A POC for using trpc for cloudflares durable objects - GitHub - markusahlstrand/trpc-durable-objects: A POC for using trpc for cloudflares durable objects
Haha yeah… see, that’s the part that I didn’t want to have to think about when making DOs. I only want to care about the business logic… in the case of a counter for instance, just the value and the increment. All the rest of the native DO code was noise IMO… the storage bits, fetch, internal routing, even building a request from the Worker.
Obviously the definition isn't as minimal because you write the method input shape using a zod scheme instead of just method arguments, but that gets you type safety
I think just writing your DO a in full TS and casting the stub as you grab it in the Worker should still get you that… I’ll do some tests to confirm this
If you think of a DO as a stateful object, I don’t think validation there makes much sense personally… as the real point of contact between an external source and any form of input is really at the Worker level. I’d put validation there.
yeah, for sure… migrating DOs is no joke sometimes. I usually write a temporary self-transform method, then run it across the DOs to sync them w new structure
A small amount of DOs being frequently accessed seems pretty safe… the danger I’ve found is when you’re creating a LOT of DOs.
For instance, on itty.sh, I originally spun up a DO a for every entry created, just for a setAlarm to destroy it at expiration. That worked like a dream, but was gonna eat my lunch in the bill for every 128MB DO spun up. Instead, I had to create a a series of expiration managers, basically load balanced expiration DOs, each handling potentially many expirations.
I couldn't find any mention of receiving SSE responses within a worker or DO, using the fetch api instead of EventSource. Eventually I found https://github.com/julienmachon/sse-client which works pretty well. It'd be nice if the docs just mentioned receiving SSE is possible in a DO.