Skip to main content

Crate bynk_emit

Crate bynk_emit 

Source
Expand description

Bynk’s TypeScript emission, plus the per-unit build sequencing that drives it — the layer above bynk-project (discovery, the dependency graph), bynk-check (all semantic checking, R3.5), and (since the P7.12 crate carve) bynk-ir/bynk-lower (the typed IR and its &CheckedProgram → Ir lowering pass).

project owns compile_project/run_checks: the two-pass sequence over a project’s units — discover and parse (bynk-project), then resolve, type-check (bynk-check) and emit each unit with full visibility of what it uses/consumes. emitter lowers a checked program to TypeScript. Input: a project tree (or an in-memory overlay). Output: TypeScript files plus diagnostics — this crate originates none of its own (P5.5, design/tracks/semantics-in-the-checker.md §3.5, R10.1).

testgen generates the test harness: each suite’s test module, the test entry and the discovery manifest, with the test-runtime fragments they embed. The driver calls it, and keeps orchestration, file I/O and process spawning (1B.2a, #4028).

Extracted from bynkc as slice 4 of the crate-decomposition track over bynk-syntax + bynk-check. Behaviour is unchanged; bynk depends on this crate and re-exports its modules so its public API (compile_project, ProjectOutput, …) and the binary are untouched.

Re-exports§

pub use emitter::wrangler::COMPATIBILITY_DATE;
pub use emitter::wrangler::DEFAULT_COMPATIBILITY_FLAGS;
pub use emitter::wrangler::WRANGLER_MIN;
pub use emitter::wrangler::compatibility_flags;

Modules§

emit_model
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.
emitter
TypeScript emission (spec §7, v0.1 §6, v0.2 §6).
testgen
Test-harness generation: suite/test integration processing, the test entry (tests/main.ts), the discovery manifest and the embedded test-runtime fragments. The fragments are authored as modules under bynk-emit/runtime/src/testing/ and reach the harness only through runtime_splice (1B.3a, #4047).
wire_format
State-migrations S4 (#2259): the call signature and the sweep route’s names, for bynk migrate sweep, which signs as the runtime verifies. #1969: the cross-context wire format, version 1, as a published surface.

Structs§

Compiled
A single-file compile that also returns the non-failing warnings produced on success — what a CLI prints (v0.89, ADR 0117). compile is the warning-discarding convenience over this.

Constants§

AGENTS_MANIFEST
#3562 (G5): the file every Worker that hosts an agent stages beside its entry, naming each context and the agent classes it owns, which bynk deploy reads to guard a move.
CONTAINERS_UNAVAILABLE_VAR
#3477 (slice C3): the wrangler dev --var that tells a generated container class its containers are off (bynk dev without Docker), so a call faults naming Docker. The runtime’s own copy is CONTAINERS_UNAVAILABLE_VAR (container.ts); xtask/tests/env_protocol.rs keeps the two equal (#4003). The wrangler dev --var that tells a generated container class its containers are off (bynk dev without Docker).
EDGE_FROM_PREFIX
I2 (#1971): the edge keys’ names, for the driver (bynk dev, bynk deploy), which sees the compiler only through this crate. The prefix of the secret a callee holds for the edge from one caller, followed by the caller’s edge suffix.
EDGE_TO_PREFIX
I2 (#1971): the edge keys’ names, for the driver (bynk dev, bynk deploy), which sees the compiler only through this crate. The prefix of the secret a caller holds for the edge to one callee, followed by the callee’s edge suffix.
INSPECT_CALLER
#3581 (the dev agent-inspection track): the caller name bynk dev inspect signs its requests as, and the variable under which bynk dev gives every served Worker the local key for it (BYNK_CALL_FROM_ plus the caller’s edge suffix). The runtime’s INSPECT_CALLER is the same name.
INSPECT_CALLER_KEY_VAR
The edge key from bynk dev inspect’s caller, bynk.dev: the CALL_FROM_PREFIX family’s one fixed member.
INSPECT_MEMBERS_FILE
#3562 (G6): the file a bynk dev group build stages beside its entry, naming each member that hosts an agent and its classes, so bynk dev inspect can sign a request for the member that answers it.
LOCAL_CALL_KEY
I2 (#1971): the value of every edge key off the deployed path. bynk dev passes it for each edge a Worker is on (BYNK_CALL_TO_<callee>, BYNK_CALL_FROM_<caller>, named by bynk_check::wire_format), and the generated test harnesses put it in every participant’s env. Fixed rather than random so two bynk dev --context sessions run side by side still admit each other’s calls. It guards nothing, so it must never reach a deployed Worker: bynk deploy mints one key per edge, and none is ever written into a generated wrangler.toml.
NODE_FLOOR
The Node floor as (major, minor): what bynk doctor compares against.
NODE_MAJOR_FLOOR
Minimum supported Node.js major version for the node platform binding and for running Bynk’s emitted TypeScript.
NODE_MINOR_FLOOR
The minor version within NODE_MAJOR_FLOOR the floor sits at: 22.13, the first 22.x whose built-in node:sqlite loads without --experimental-sqlite (standard-library P4a, #2602: the D1 test double runs on it). CI’s floor job installs exactly this version.
STORAGE_LAYOUT
The storage layout this emitter writes an agent’s state in (#3189, the retired per-entry-storage track in design/archive/retired-tracks.md): 1 is the wholesale layout, with every collection inline in the one "state" record, and 2 is the per-entry layout, with each Map/Set/Cache/Log entry and index posting under its own key. bynk deploy records it in each version’s facts so that bynk deploy revert can refuse a rollback to a build that writes an older layout over stored data. The slice that changes the layout raises this together with the emitter’s writer.
TYPESCRIPT_MAJOR_TESTED
The TypeScript major the emitted output is verified against, and the only one Bynk supports (#3420): the one users get from npm install -g typescript. Every CI leg installs it and type-checks every positive fixture under it, the npx fallbacks provision it, and bynk doctor warns on a tsc below it and reports one newer than it as untested. (There was a lower floor, 5, until #3420: tsc 5 cost about 4x tsc 7 per bynk test, and the shape of the generated code is meant to be independent of the tooling.)

Functions§

check_with_warnings
Check a single-file commons without building it: the same diagnostics as compile_with_warnings, minus the build-only ones, and no emission. Returns the non-failing warnings on success. The single-file half of bynk check (bynk_driver::run_check); a directory goes through the project pipeline in Mode::Check instead.
compile
Compile a single Bynk source string to a TypeScript string.
compile_with_warnings
The warning-preserving single-file compile behind compile. See Compiled.
edge_key_from
I2 (#1971): the edge keys’ names, for the driver (bynk dev, bynk deploy), which sees the compiler only through this crate. I2 (#1971): the secret the callee holds for calls from caller (BYNK_CALL_FROM_SHOP__ORDERS). The callee picks it by the request’s CALLER_HEADER, so an undeclared caller finds no key and is refused.
edge_key_to
I2 (#1971): the edge keys’ names, for the driver (bynk dev, bynk deploy), which sees the compiler only through this crate. I2 (#1971): the secret the caller holds for calls to callee (BYNK_CALL_TO_SHOP__PAYMENT). Same value as the callee’s edge_key_from for the same edge.