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.

Functions§

duplicate_bindings
The bindings in bindings whose name an earlier one already took, each paired with that earlier one, in list order.
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.
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).