Cloudflare - v1.3.0
    Preparing search index...

    Class DurableObjectBinding<E>

    Accessor for the Durable Object namespace binding (durable_objects in wrangler.json).

    const counters = new DurableObjectBinding() // binding name from the configuration layer
    const stub = counters.stubByName(ctx.env, `room:${roomId}`)
    const response = await stub.fetch('https://durable-object/increment')

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Hierarchy (View Summary)

    • Binding<DurableObjectNamespace, E>
      • DurableObjectBinding
    Index
    locationHint?: DurableObjectLocationHint

    Default location hint applied when creating stubs.

    settings: () => DurableObjectSettings

    This accessor’s settings, resolved on first read.

    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • Derives the object id for a name without creating a stub.

      Parameters

      • env: E

        The Worker environment.

      • name: string

        The name to derive the object id from.

      Returns DurableObjectId

      The derived object id.

    • Checks whether the binding is available on the given environment.

      Use this to degrade gracefully when a binding is optional.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Resolves the binding, failing fast when it is not configured.

      Parameters

      • env: E

        The Worker environment.

      Returns DurableObjectNamespace

      The resolved binding.

      MissingBindingError When the binding is absent from the environment.

    • Returns the stub for an existing object id.

      Parameters

      • env: E

        The Worker environment.

      • id: string | DurableObjectId

        The object id, either as an id or its string form.

      Returns DurableObjectStub

      The stub for that object.

    • Returns the stub for the object derived from a name.

      The same name always maps to the same object, which is what makes this the usual way to shard state by tenant, room, or user.

      Parameters

      • env: E

        The Worker environment.

      • name: string

        The name to derive the object id from.

      Returns DurableObjectStub

      The stub for that object.

      MissingBindingError When the Durable Object binding is absent.

    • Creates a brand new object and returns its stub.

      Parameters

      • env: E

        The Worker environment.

      Returns DurableObjectStub

      The stub for the newly created object.

    • Builds the stub options carrying the configured location hint.

      Returns DurableObjectNamespaceGetDurableObjectOptions

      The stub options, or undefined when no hint is configured.

    • Resolves the binding without throwing.

      Parameters

      • env: E

        The Worker environment.

      Returns DurableObjectNamespace<undefined>

      The resolved binding, or null when it is not configured.