Skip to main content

Module emit

Module emit 

Source
Expand description

Per-declaration emission — the functions emit_project drives to render each top-level Bynk declaration into TypeScript. Split out of emitter.rs (ADR 0060), then into one file per declaration kind (back-half paydown 2.1, #4086). This file only declares those files and re-exports them, so every emitter::emit::X and emitter::X path still resolves; each child imports what it uses explicitly. The one glob import below is not for this file: moved function bodies spell parent paths through it, such as super::tco::plan, super::commons_alias, super::serialisation::… and super::ty_to_type_ref.

  • types: type, refined, record and sum declarations and their checks;
  • functions: attached methods, free functions, constants and contract guards;
  • suite: the declarations a test suite makes, which testgen calls;
  • handlers: handler method names and labels, and the handler-body items services, agents and free functions share;
  • messages: messages bundles and ICU placeholders;
  • capability: capabilities, derived capabilities and providers;
  • service: services, contexts, the make surface and the actor-sum types;
  • websocket: the Durable Object methods and fetch upgrade branch of a from websocket service;
  • agent: emit_agent, the agent class’s constructor, its state record and its zero entries;
  • agent_store: an agent’s store layout, lazy-read specs, and key and wire codecs;
  • agent_state: the loadState and commitState functions, hydration and the persistence guards;
  • agent_migrate: the migrate from N step functions and their dispatcher;
  • agent_dispatch: an agent’s handler methods, Workers fetch dispatch and factory;
  • agent_history: the history-property driver.

Functions§

any_service_binds_caller
v0.54 (#655): whether any of services declares an on call … by c: Caller handler, whose emitted deps carries the calling context’s qualified name as its CallerId identity (ADR 0092). This is the single predicate both bundle caller-identity seams consult — emit_make_surface (which adds the __caller parameter) and the compose root (which passes the name) — so the two can never disagree on which providers thread a caller. caller_binder_for self-guards HandlerKind::Call, so no kind filter is needed or wanted here.
collect_handler_labels
Slice 3 (semantic-debugging track, ADR 0105): the debug-metadata sidecar’s { fn → label } map — each emitted handler function paired with its Bynk operation label, so the debugger can name a stack frame GET "/" rather than http_GET. bynk_ts::TsExpr by re-walking the unit’s handlers with the same naming functions the emitter uses (so the keys match the emitted function names); serialised as a JSON object (manual, like the source map — no serde). Returns None when the unit declares no handlers.
context_pascal
The PascalCase name a context uses for its generated Deps interface: shortener.links → ShortenerLinks.
cron_handler_method_name
Synthesise a TypeScript-safe method name for an on cron handler (v0.10a): cron_<service>_<index>, where index is the handler’s position among the service’s cron handlers in declaration order. The same key is computed at each emission site (the handlers method, the compose surface wrapper, and the scheduled dispatcher) by walking handlers in the same order, so it is collision-free and stable without encoding the schedule expression.
emit_suite_decls
#3066: a suite’s own type and const declarations, as TypeScript for the body of one test runner: the types (an interface and its companion object, or a union), their JSON codecs (so select[T], Json.encode/decode and the boundary paths find __serialise_T / __deserialise_T in scope), and the constants (cached-function declarations, like a unit’s). They are declared local to the runner, so another suite declaring the same name cannot collide and nothing here reaches the deployable. typed is the suite’s view with the suite’s types and constants already merged in; qual qualifies a target type a suite type’s codec mentions, as the module-level codecs do.
emit_suite_fn
#2834: a suite-local helper fn — emit_free_fn without the export, since it is declared inside a test runner and called from its body.
emit_suite_late_codecs
#3111: the codecs a runner’s body reached for beyond the always-present ones (emit_suite_decls): a suite type under another generic (Result, a user generic, nested containers) at a Json boundary. reached is what the runner’s lowering noted; only roots that name a suite type are served here (the module-level closure serves the rest). Returns the function declarations, with export dropped, to be spliced ahead of the body; empty when the body reached nothing new.
http_handler_method_name_ir
Synthesise a TypeScript-safe method name for an on http METHOD path handler. The result is used both as the key on the service object and as the identifier the Worker fetch handler invokes. Path parameter segments (:name) become Param_name to remain distinct from literal segments. (v0.9 §5.3)
queue_handler_method_name
Method name for an on queue handler (v0.10b): queue_<service>_<index>, by the handler’s position among the service’s queue handlers. Computed identically at the handlers method, the compose surface wrapper, and the queue dispatcher (queue names are unique context-wide, but the index keeps the key identifier-safe without sanitising the name).
test_scaffold_ns
#1759: the identifier a generated test module imports a unit as (import * as __ns_greet from …). A test module destructures a unit’s values out of this namespace (const { greet } = __ns_greet;), so the namespace can’t take qualified_to_ns’s bare name: a context greet declaring fn greet would shadow its own import and read greet in its temporal dead zone. The reserved __ns_ prefix can’t be a user identifier. Every test-module namespace reference goes through this, in tests_emit and in lowering that runs in_test_scaffold().