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

    Loren

    04/01/2021, 1:44 PM
    Hey all, are there any docs on the API changes for uploading DO's / new workers with module syntax without wrangler? Or is reading through the wrangler source the best way to figure it out? Thanks!
  • r

    Rawn

    04/01/2021, 1:58 PM
    Anyone have a successful way of using DOs with Typescript yet? I.e. how do i work with DOs as Typescript classes?
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:04 PM
    Yes! https://github.com/cloudflare/workers-types should have the typings you need to get started 😊
  • a

    AlexRobinson

    04/01/2021, 2:06 PM
    That sounds like your wrangler.toml is still trying to bind to the class you're deleting. I'd suggest deleting the binding and trying again. We should also document that better, it's admittedly not super obvious
  • r

    Rawn

    04/01/2021, 2:06 PM
    @User Yep, I have been using that for my normal ts workers, but can't get it to work with DOs now.
  • r

    Rawn

    04/01/2021, 2:07 PM
    When i call
    wrangler publish --new-class Counter
    it answers with:
    Cannot create binding for class Counter that does not currently implements durable objects. Did you mean to apply a --new-class migration to it?"
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:09 PM
    Just got to say that the class implements the `interface DurableObjectNamespace`: https://github.com/cloudflare/workers-types/blob/c18cf034f92ee007dabbaed1eec9e58da8cb04bc/index.d.ts#L694
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:10 PM
    That's not a TypeScript problem. Have you had a look at the instructions here? https://github.com/cloudflare/wrangler/releases
  • r

    Rawn

    04/01/2021, 2:12 PM
    I'll check it out first.
  • a

    AlexRobinson

    04/01/2021, 2:13 PM
    @User what version of wrangler are you running?
  • a

    AlexRobinson

    04/01/2021, 2:14 PM
    I'm not positive about whether the new flags like
    --new-class
    are supported when doing a typescript build, but they're definitely not supported if you're on a build prior to v1.15.0-custom-builds-rc.1 (and you should really grab v1.15.0-custom-builds-rc.2 while you're at it)
  • r

    Rawn

    04/01/2021, 2:16 PM
    @User Im using
    wrangler 1.15.0-custom-builds-rc.2
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:16 PM
    Ah, sorry, I confess I haven't actually tried TypeScript with the newest wrangler release yet. I was just relying on however I had it setup when I was beta testing before the RCs.
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:17 PM
    If you take away the TypeScript stuff, are you able to get
    --new-class
    working?
  • a

    AlexRobinson

    04/01/2021, 2:17 PM
    thanks, it is possible then that the new migration flags don't work with the typescript build yet. I'll check into that for you
  • r

    Rawn

    04/01/2021, 2:20 PM
    Awesome thanks!
  • r

    Rawn

    04/01/2021, 2:22 PM
    Another thing, while on the topic: The constructor in a typescript DO class has the signature something like this:
    constructor(state: DurableObjectState, env: any)
    , but as you can see, I didn't find the type for
    env
    in the
    @cloudflare/workers-types/index.d.ts
    ?
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:25 PM
    You need to define that yourself really, since it's just the other namespaces you have implemented in your project.
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:25 PM
    Got an example somewhere, two seconds...
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:25 PM
    https://github.com/cloudflare/workers-types/issues/76
  • m

    matt

    04/01/2021, 2:27 PM
    You likely still have the binding declared in
    wrangler.toml
    under the
    [durable_objects]
    section, you need to remove the binding if you are deleting the class it binds to (whoops, looks like alex answered already)
  • r

    Rawn

    04/01/2021, 2:29 PM
    Of course! you are right... 🤦‍♂️
  • m

    matt

    04/01/2021, 2:30 PM
    @User Are you still using custom builds with
    type = "javascript"
    and a
    [build]
    section like the provided templates have with your typescript setup?
  • r

    Rawn

    04/01/2021, 2:31 PM
    @User ah, no, im still using a project generated from the old typescript template, so it is webpack type
  • m

    matt

    04/01/2021, 2:31 PM
    durable objects must be implemented as exported classes, which requires using modules, which requires using custom builds (migrations are gated in the same way)
  • r

    Rawn

    04/01/2021, 2:32 PM
    Right, and TS classes just compiles to functions i suppose..
  • k

    Kat

    04/01/2021, 2:32 PM
    Will we have the ability to list/delete DO's via the UI at some point?
  • r

    Rawn

    04/01/2021, 2:33 PM
    @User I assume I should be able to create an *.mjs shim perhaps?
  • g

    Greg Brimble | Cloudflare Pages

    04/01/2021, 2:33 PM
    It's a WIP 😊
  • m

    matt

    04/01/2021, 2:36 PM
    @User yeah, you'll need to. the shim is required with webpack at the moment as webpack currently only supports outputting a commonjs module (there are plugins that allow it to output an es6 module, but I had poor luck with them). CommonJS modules only support a single default export, which makes them unsuitable for use as the root module (the module the runtime looks at to find your fetch handler and DO classes) as the runtime expects DO classes to be named exports
1...363738...567Latest