Cloudflare - v1.3.0
    Preparing search index...

    Class Binding<TBinding, E>Abstract

    Base class for every Cloudflare binding accessor.

    Cloudflare exposes bindings on the per-request E object rather than on a module-level singleton, so an instance never holds the binding itself — it holds the name of the binding and resolves it from the E passed to each call. That keeps instances safe to create once at module scope and reuse across requests.

    The name arrives already resolved: subclasses take their settings from resolve, so neither this class nor its callers know whether a value was defaulted or overridden.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Hierarchy (View Summary)

    Index
    • Constructs a binding accessor.

      Type Parameters

      Parameters

      • binding: string | (() => string)

        Binding name as declared in wrangler.json, or a function producing it when first needed.

      Returns Binding<TBinding, E>

      The name may arrive as a function, and every subclass passes one. Accessors are created at module scope so a single instance is reused across requests, and module scope runs while a consumer's imports are still being hoisted, before it can call configure(). A thunk moves the lookup to first use, which is inside a request.

    settle: () => string

    Produces the binding name, on first read.

    settled: string = null

    The name once settled, so it is produced only once.

    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • 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.