Skip to main content

Module emit_model

Module emit_model 

Source
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::files are gone, not aliased). Keyed by output path (project-root-relative), so the sibling-path lookup bynk-driver::output needs for .map/ .bynkdbg.json files is a direct map operation instead of a linear scan, and so a wrangler.toml document carries its real [crate::emitter:: toml_doc::TomlDocument] all the way to the write boundary instead of being stringified at construction (Decision E).
DiscoveredCase
One discovered test "<name>" case. location points at the case-name literal (a run failure instead points at the failing assert), giving the editor click-through to the declaration before any run.
DiscoveredSuite
v0.67: a discovered test suite — one test <target> group (unit) or test integration "<suite>" (integration). name + kind mirror exactly what the NDJSON runner emits at suite-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.
EmitProjectCtx
LocaleNegotiationArgs
v0.15: build the TypeScript expression instantiating the provider of capability cap declared in provider_ctx, recursively wiring its given dependencies — local sibling providers and cross-context capability providers alike. Stateless providers, so fresh instances per use are fine.
ProjectOutput
Result of compiling a project.
RemoteSkip
#2138: a system case a remote test build skipped, and why.
RemoteTests
#2138: how a remote test build treats a system case it can’t run against a real runtime (CompileOptions::remote_tests in the driver).
SchemaVersions
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_checks to 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.
StagedFile
One generated document, staged during build_output/emit_unit before the final split into Artefacts — see build_output’s own tail.
TestLocation
A project-root-relative path:line:col source location, structured. Line and col are 1-indexed (the bynk_syntax::span::line_col convention).
TraceLoc
#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.
UnitSource
#2620: the .bynk source of the unit being emitted and its project-relative identity path, so a unreachable(…) / todo(…) / detach lowering can name its own path:line:col. bynk_ts::TsExpr once per unit by the driver; None on EmitProjectCtx::unit_source is the single-file path, which has no identity.
WorkersBuild
1C.3a (#4040): the binding model of a Workers build, with what the model is read against. bindings is the one WorkerBindings the build’s wrangler.toml files were rendered from, so a reader of it sees exactly the bindings written.

Enums§

Document
One typed output document. No String at construction for TypeScript or TOML content (R7.8) — Json/Js/SourceMap/DebugSidecar stay opaque payloads because bynk-emit never re-parses them itself, not because they’re an escape hatch from the rule.
ExtraImport
One import handlers.ts needs 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 locale render), and the emitter writes each as an import node. A small enum owned here, so the driver does not build bynk_ts nodes itself.
ImportExt
The extension emitted import specifiers use (import … from "./x.<ext>").
ProviderNamespaces
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 generated wrangler.toml’s [assets] directory names (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 capability cap of unit in its referenced_units: bynk.cloudflare#Version. No unit is named with a #, so the marker never resolves to a platform, and the bare KV namespace stays tied to reaching the unit through Kv.
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 system suite’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 a system test puts on a participant’s env, else the real provider.
instantiate_provider_ts_expr
namespaces selects 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}__binding in the first two, and a test module has none. When env_ident is 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 rule bynk-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/…, where bynk-driver::output’s reconciliation prunes a .sql the build no longer produces. Every component must be a plain name, as for is_worker_asset_path.
new_call_ts_expr
new {ns}.{class}({args}) as a real bynk_ts::TsExpr::New node.
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 (tsc copies only TypeScript and JSON) and no Node typings. bynk test writes this over the Workers form at wasm_shim_path.
parse_bare_singleton_marker
The (unit, capability) a bare_singleton_marker names, or None for a plain unit name.
sibling_path
<name>.<suffix>, matching bynk-driver::output.rs’s own sibling-name derivation for .map/.bynkdbg.json files 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 of emitter::commons_uses_emit, needed because compose works from the project-wide UnitTable map, not a single unit’s TypedCommons. It is bynk_check::project_model::unit_table_uses_emit, which decides the four emission gates here (the fan-out DO, the dispatchToEventsFanout import, the EVENTS_FANOUT binding and the __eventsDispatch field) and whether a bundle has a composition root for the bynk.capability.not_provided check, 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, dedup or remember)? 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 } makes Idempotency a local name for the bynk capability), so a same-named capability from another unit does not count, as for the key scoping in scope_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’s consumes closure (through adapter-to-adapter consumes too) reaches an adapter whose binding includes a module.
workers_wasm_shim
The Workers form of the loader: Wrangler compiles ./x.wasm to a WebAssembly.Module at deploy (CompiledWasm rule in wrangler.toml).