Expand description
The model the code generator shares with the orchestration layer: the
output documents (Artefacts, Document, ProjectOutput), the import
extension, the per-unit emission context (EmitProjectCtx) and the
provider-instantiation expressions the emitter splices into generated code.
Crate-hygiene D1 (#2982, PR 1): these lived in project.rs, which made the
emitter import its own orchestrator. They move here so project can leave
this crate for bynk-driver without the emitter depending on it. project
re-exports everything below at its old path until then.
Structs§
- Artefacts
- A project’s output, as a keyed set of typed documents (R7.8, #1309) —
replaces the old
ProjectOutput.files: Vec<CompiledFile>outright, not alongside it (“Done when”:CompiledFile/ProjectOutput::filesare gone, not aliased). Keyed by output path (project-root-relative), so the sibling-path lookupbynk-driver::outputneeds for.map/.bynkdbg.jsonfiles is a direct map operation instead of a linear scan, and so awrangler.tomldocument carries its real [crate::emitter:: toml_doc::TomlDocument] all the way to the write boundary instead of being stringified at construction (Decision E). - Discovered
Case - One discovered
test "<name>"case.locationpoints at the case-name literal (a run failure instead points at the failingassert), giving the editor click-through to the declaration before any run. - Discovered
Suite - v0.67: a discovered test suite — one
test <target>group (unit) ortest integration "<suite>"(integration).name+kindmirror exactly what the NDJSON runner emits atsuite-begin(kind"unit"carries the joined target name;"integration"carries the bare suite name), so the editor reconciles discovery and run documents to the same tree items. - Emit
Project Ctx - Locale
Negotiation Args - v0.15: build the TypeScript expression instantiating the provider of
capability
capdeclared inprovider_ctx, recursively wiring itsgivendependencies — local sibling providers and cross-context capability providers alike. Stateless providers, so fresh instances per use are fine. - Project
Output - Result of compiling a project.
- Remote
Skip - #2138: a
systemcase a remote test build skipped, and why. - Remote
Tests - #2138: how a remote test build treats a
systemcase it can’t run against a real runtime (CompileOptions::remote_testsin the driver). - Schema
Versions - Context passed to the emitter so it can resolve cross-file and
cross-unit references into TypeScript import statements.
The schema registry’s reconciled versions, threaded from
run_checksto each unit’s emission: events keyed<unit>.<Event>(#980), agents keyed<unit>.<Agent>(state-migrations S1, #2211). Both empty when the build has no lock. - Staged
File - One generated document, staged during
build_output/emit_unitbefore the final split intoArtefacts— seebuild_output’s own tail. - Test
Location - A project-root-relative
path:line:colsource location, structured. Line and col are 1-indexed (thebynk_syntax::span::line_colconvention). - Trace
Loc - #3580: what a traced build needs to name a call site: the file’s source text,
to turn a byte offset into
line:col, and its project-relative path. - Unit
Source - #2620: the
.bynksource of the unit being emitted and its project-relative identity path, so aunreachable(…)/todo(…)/detachlowering can name its ownpath:line:col. bynk_ts::TsExpr once per unit by the driver;NoneonEmitProjectCtx::unit_sourceis the single-file path, which has no identity. - Workers
Build - 1C.3a (#4040): the binding model of a Workers build, with what the model
is read against.
bindingsis the oneWorkerBindingsthe build’swrangler.tomlfiles were rendered from, so a reader of it sees exactly the bindings written.
Enums§
- Document
- One typed output document. No
Stringat construction for TypeScript or TOML content (R7.8) —Json/Js/SourceMap/DebugSidecarstay opaque payloads becausebynk-emitnever re-parses them itself, not because they’re an escape hatch from the rule. - Extra
Import - One import
handlers.tsneeds beyond the ones the emitter derives (#527): the driver forms them from what it knows of the build (adapter-binding modules, other Workers’ handlers, the localerender), and the emitter writes each as an import node. A small enum owned here, so the driver does not buildbynk_tsnodes itself. - Import
Ext - The extension emitted import specifiers use (
import … from "./x.<ext>"). - Provider
Namespaces - Where
instantiate_provider_ts_expr’s expression finds each unit’s provider classes: the module that constructs it imports each unit under a different namespace.
Constants§
- WASM_
MODULES_ DTS - Ambient type for the Workers loader’s
import module from "./x.wasm". - WORKER_
ASSETS_ DIR - #1883, slice 0: the name of the directory, inside a Worker’s own
workers/<dashes>/output directory, that holds its static assets — the directory the generatedwrangler.toml’s[assets] directorynames (emitter::wrangler::assets_block). Separate from the Worker’s own output so the compiled Worker and its source maps are never served as public assets.
Functions§
- bare_
singleton_ marker - #3300: how
ProviderNamespaces::BareResources’ walk records reaching one-per-Worker capabilitycapofunitin itsreferenced_units:bynk.cloudflare#Version. No unit is named with a#, so the marker never resolves to a platform, and the bareKVnamespace stays tied to reaching the unit throughKv. - called_
cross_ context_ services - v0.177 (#643, review of #658): the cross-context services a context actually
calls, as
consumed context → service names. - harness_
clock_ contexts - #2137: every context a
systemsuite’s harness stands up as a Worker (its participants and their event subscribers,test_suites::infer_harness_participants). - harness_
clock_ or - #2137:
(env as unknown as { __bynkClock?: <class> }).__bynkClock ?? <built>— the harness clock asystemtest puts on a participant’senv, else the real provider. - instantiate_
provider_ ts_ expr namespacesselects the namespace convention (ProviderNamespaces): a bodied provider’s class lives in{ns}under the bundle root,handlers_{ns}in a Worker compose and__ns_{ns}in a test module; external (binding) classes are{ns}__bindingin the first two, and a test module has none. Whenenv_identis set (workers), env-taking first-party providers receive it as a constructor argument.- is_
worker_ asset_ path - #1883, slice 0: whether
rel(output-root-relative) names a file inside some Worker’s assets directory —workers/<dashes>/<WORKER_ASSETS_DIR>/…, at any depth. The ownership rulebynk-driver::output’s reconciliation applies regardless of extension. - is_
worker_ migration_ path - P4b (#2608): whether
rel(output-root-relative) names a file in some Worker’s copied D1 migrations,workers/<dashes>/migrations/…, wherebynk-driver::output’s reconciliation prunes a.sqlthe build no longer produces. Every component must be a plain name, as foris_worker_asset_path. - new_
call_ ts_ expr new {ns}.{class}({args})as a realbynk_ts::TsExpr::Newnode.- node_
wasm_ shim - The Node form of the loader (#2321, decision B): the module’s bytes inlined
and compiled at load, so it needs no file beside the compiled output (
tsccopies only TypeScript and JSON) and no Node typings.bynk testwrites this over the Workers form atwasm_shim_path. - parse_
bare_ singleton_ marker - The
(unit, capability)abare_singleton_markernames, orNonefor a plain unit name. - sibling_
path <name>.<suffix>, matchingbynk-driver::output.rs’s own sibling-name derivation for.map/.bynkdbg.jsonfiles exactly (P7.6, #1309).- unit_
table_ uses_ emit - Events track, slice 0 (spine #936): does any handler in this unit emit?
The
UnitTable-level analogue ofemitter::commons_uses_emit, needed because compose works from the project-wideUnitTablemap, not a single unit’sTypedCommons. It isbynk_check::project_model::unit_table_uses_emit, which decides the four emission gates here (the fan-out DO, thedispatchToEventsFanoutimport, theEVENTS_FANOUTbinding and the__eventsDispatchfield) and whether a bundle has a composition root for thebynk.capability.not_providedcheck, which the editor runs too. One predicate, so the check and the emitter cannot disagree. - unit_
table_ uses_ idempotency - W30 (#2840): does any body in this unit call the first-party
Idempotency(claim,deduporremember)? A Worker that does declares the implicit database that holds its claims and remembered values. The checker resolved each call’s first-party identity (consumes bynk { Idempotency }makesIdempotencya local name for thebynkcapability), so a same-named capability from another unit does not count, as for the key scoping inscope_idempotency_key. - wasm_
shim_ path - #2321: the generated loader beside an included module, whose default export
is the compiled
WebAssembly.Module.adapters/x.wasm→adapters/x.wasm.ts. - worker_
assets_ dir - #1883, slice 0:
workers/<dashes>/<WORKER_ASSETS_DIR>, the output-root- relative directory holding one Worker’s static assets. - worker_
reaches_ wasm_ module - #2321: whether
ctx’sconsumesclosure (through adapter-to-adapterconsumestoo) reaches an adapter whose binding includes a module. - workers_
wasm_ shim - The Workers form of the loader: Wrangler compiles
./x.wasmto aWebAssembly.Moduleat deploy (CompiledWasmrule inwrangler.toml).