Setu-TS
    Preparing search index...

    Interface ICloudflareBindings

    Typed access to a Cloudflare Worker's platform bindings.

    Resolve it from the service registry under CAPABILITIES.CLOUDFLARE.

    Every accessor throws CloudflareBindingMissingError for a name the Worker does not carry, rather than returning undefined: a missing binding is a deployment error, and failing with the requested name plus the names that are present says what to fix. Use has when absence is an expected case.

    Binding methods may only be called inside a request. The Workers platform prohibits I/O in top-level scope, so holding a binding at registration time is fine while reading through it there is not.

    const cf = ctx.services.get<ICloudflareBindings>(CAPABILITIES.CLOUDFLARE);
    const value = await cf.kv('SETTINGS').get('theme');
    cf.waitUntil(reportUsage(value));

    0.2.0

    interface ICloudflareBindings {
        d1(name: string): ID1Database;
        durableObject(name: string): IDurableObjectNamespace;
        get<T>(name: string): T;
        has(name: string): boolean;
        kv(name: string): IKvNamespace;
        names(): readonly string[];
        queue(name: string): IQueueProducer;
        r2(name: string): IR2Bucket;
        service(name: string): IServiceBinding;
        vars(): Readonly<Record<string, string>>;
        waitUntil(promise: Promise<unknown>): void;
    }
    Index
    • A binding of a type this package has no facade for — Hyperdrive, Vectorize, Workers AI, Analytics Engine, and anything Cloudflare ships next.

      Type Parameters

      • T

        The caller's own type for the binding

      Parameters

      • name: string

        The binding name

      Returns T

      The binding

      When the binding is absent

    • The Worker's string variables and secrets.

      The same values reach runtime.env when the application passes env to RuntimePlugin; this accessor exists so a consumer holding only the bindings service does not need the runtime as well.

      Returns Readonly<Record<string, string>>

      The string entries of the Worker's env

    • Keeps the invocation alive until the promise settles, so work can outlive the response.

      Cloudflare allows up to 30 seconds after the invocation ends, shared across every call in one request. A rejection is logged rather than left unhandled. Off Cloudflare Workers — with no host injected — the promise simply runs, because no runtime there cuts work off at the response.

      Parameters

      • promise: Promise<unknown>

        The background work

      Returns void