Skip to main content

Module worker_bindings

Module worker_bindings 

Source
Expand description

A Worker’s binding names must be unique (bynk.context.duplicate_binding).

A Worker’s bindings come from derivations that know nothing of each other: the KV namespace’s fixed crate::firstparty::KV_BINDING_NAME, a consumed context’s name (a.b → A_B), an agent’s class name (OrderEntity → ORDER_ENTITY) and a derived capability’s (Billing → SERVICE_BILLING). Two of them can meet: an agent Kv in a context that consumes bynk.cloudflare { Kv } is KV twice, and an agent ServiceBilling and a capability Billing = Service are both SERVICE_BILLING. Wrangler takes such a config without complaint and one binding hides the other, so the clash is a compile error. The names themselves are never adjusted to avoid it, because deployed Workers depend on them.

The names are the emitter’s (bynk_emit::emitter::wrangler:: worker_bindings, the list wrangler.toml is written from); this module owns the check over them and the diagnostic.

Structs§

WorkerBinding
One binding a Worker declares: the name its env field and its wrangler.toml entry share, and where that name came from.

Enums§

BindingSource
What put a binding into a Worker’s wrangler.toml: the source a bynk.context.duplicate_binding diagnostic names.

Constants§

IMPLICIT_IDEMPOTENCY_CAPABILITY
W30 (#2840): the capability of the D1Database source of a Worker’s implicit idempotency database. Not an identifier, so no project’s own derived D1 capability can carry it: whether a binding is the implicit one is decided by its source, never by its name (a project’s capability Idempotency = D1 is bound as D1_IDEMPOTENCY too).

Functions§

duplicate_bindings
The bindings in bindings whose name an earlier one already took, each paired with that earlier one, in list order.
idempotency_binding
W30 (#2840): the binding of a Worker’s implicit idempotency database, named IDEMPOTENCY_BINDING.
instance_binding_name
S4a (#1966): the Worker binding name of a derived capability, the kind’s prefix then the capability name in screaming_snake case (Sessions → KV_SESSIONS, PriceCache → KV_PRICE_CACHE).
phase_duplicate_bindings
bynk.context.duplicate_binding: each context’s Worker declares every binding name once. bindings holds each context’s bindings as its wrangler.toml would list them. One error per clash, at the declaration that brought in the second binding (an agent, or a consumes clause), preferring one the author wrote over consumes bynk.cloudflare, naming both sources. A clash between two sources with no declaration of their own (Service Bindings added for event subscribers) is reported at the context’s name.
phase_group_binding_collisions
bynk.deploy.binding_collision (#3562): the members of a Worker group share one wrangler.toml and one env, so a binding name two members both declare is one binding when their declarations are identical (the same kind and options, so the point of co-location is shared state) and an error when they differ. bindings holds each context’s bindings (phase_duplicate_bindings reports a name one context repeats). One error per clash, at the later member’s declaration, naming both members and both sources.
screaming_snake
A declaration’s name in screaming snake case (OrderEntity → ORDER_ENTITY): the casing of an agent’s binding and of a derived capability’s. One function, so the two kinds of name the duplicate check compares cannot drift apart (review of #1968).