https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • d

    DanTheGoodman

    03/09/2023, 12:42 PM
    gotcha thanks!
  • h

    HardAtWork

    03/09/2023, 12:46 PM
    Note too that just because you run deleteAll doesn’t mean that the DO itself is deleted. It(and its ID) will continue to exist(without any storage) for about a minute or two
  • d

    DanTheGoodman

    03/09/2023, 12:47 PM
    thanks for the heads up!
  • j

    johtso

    03/09/2023, 1:57 PM
    Is there an easy way to achieve self destructive ephemeral DOs? I'd love to have my user sessions backed by a DO but have it destroyed if no requests are made for a certain period of time
  • d

    DanTheGoodman

    03/09/2023, 1:58 PM
    Set an alarm for some time after every request (say
    new Date().getTime() + 5000
    for a 5 second delay) and in the alarm handler just call
    .deleteAll()
  • j

    johtso

    03/09/2023, 1:59 PM
    And I guess replace the previous alarm each time
  • d

    DanTheGoodman

    03/09/2023, 1:59 PM
    SetAlarm will upsert it
  • d

    DanTheGoodman

    03/09/2023, 1:59 PM
    so it will replace if it already exists, or set if it does not
  • j

    johtso

    03/09/2023, 2:00 PM
    Another question, what's the go to way to get a type safe interface between my DO and my worker? Something like trpc?
  • j

    johtso

    03/09/2023, 2:17 PM
    Does itty router help with this?
  • j

    johtso

    03/09/2023, 2:40 PM
    Does anyone know if itty-durable gives type safety?
  • l

    Larry

    03/09/2023, 2:43 PM
    There might be a way to use native TypeScript types that I don't know of, but I use vanilla JavaScript so I've settled on @cfworker/json-schema
  • j

    johtso

    03/09/2023, 2:56 PM
    @Kevin W - Itty does itty-durable "just work" when it comes to types?
  • a

    andheller

    03/09/2023, 3:13 PM
    That would be great! Would try/catch work if it runs out of memory?
  • d

    DanTheGoodman

    03/09/2023, 3:23 PM
    they are bound together, and can share types in the codebase
  • d

    DanTheGoodman

    03/09/2023, 3:23 PM
    Do you mean runtime-safe? It's better to validate inputs and assume they are as expected once they enter the system rather than checking everywhere
  • d

    DanTheGoodman

    03/09/2023, 3:24 PM
    If you need runtime type checking you can use something like zod
  • d

    DanTheGoodman

    03/09/2023, 3:24 PM
    Hono has better typing across the board, I've used both itty-router and hono. I prefer to stay away from itty-durable but that would have better typing. I stay away because I don't like how differnet it is from making normal DOs
  • j

    johtso

    03/09/2023, 3:25 PM
    @DanTheGoodman this looks promising https://www.npmjs.com/package/trpc-durable-objects
  • j

    johtso

    03/09/2023, 3:25 PM
    Just looking to reduce boilerplate
  • d

    DanTheGoodman

    03/09/2023, 3:25 PM
    Are you just trying to get strong type checking?
  • d

    DanTheGoodman

    03/09/2023, 3:26 PM
    just type check when requests come it, then you can assume they are safe once they are in the system
  • d

    DanTheGoodman

    03/09/2023, 3:26 PM
    so at the worker type check everything before passing to a DO
  • d

    DanTheGoodman

    03/09/2023, 3:26 PM
    many many packages for that
  • j

    johtso

    03/09/2023, 3:26 PM
    I want to be able to call a method of my DO from my worker as if it was a local function, and have the correct types, and have the response validated
  • d

    DanTheGoodman

    03/09/2023, 3:28 PM
    Ultimately you will be at the mercy of that package, it's not really worth it in my experience of making many production systems on workers and DOs. Keep with the request/response semantics because that is what's actually happening, and that decouples you from dumb decisions or lack of updates from third party packages
  • d

    DanTheGoodman

    03/09/2023, 3:28 PM
    but that's very much an opinion... personally I'd never use a small package like that in production, I'm not about to maintain someone else's code when I need changes if that makes sense
  • d

    DanTheGoodman

    03/09/2023, 3:29 PM
    going from 5 lines per function to 2 is not worth all that hoop jumping IMO
  • d

    DanTheGoodman

    03/09/2023, 3:29 PM
    premature optimization is the common terminology here
  • k

    Kevin W - Itty

    03/09/2023, 3:31 PM
    Currently itty-durable itself (the invisible code) is not typed at all, but you can easily type your objects as you define them, then use those types throughout your worker code.
1...511512513...567Latest