Skip to main content

Module emitter

Module emitter 

Source
Expand description

TypeScript emission (spec §7, v0.1 §6, v0.2 §6).

Walks the typed AST and writes a single TypeScript module.

v0.2 lowering rules:

  • Refined-base types: branded type alias + constructor object with of/unsafe (+ any user-declared methods).
  • Record types: TypeScript interface + namespace object with methods.
  • Sum types: discriminated-union type alias + namespace object with variant constructors and methods.
  • Field access lowers to property access.
  • Method calls lower to Type.method(receiver, args) (UFCS).
  • match lowers to a switch on .tag; in tail position it inlines, otherwise it becomes an IIFE.
  • is lowers to a tag check; bindings become const declarations on the truthy side of if/&&.

Re-exports§

pub use toml_doc::print_toml_document;

Modules§

client
I4 (#1970): the typed TypeScript client for a context’s foreign callers, workers/<context>/bynk-client.ts (design/archive/retired-tracks.md, interop track D3).
contracts
bynk-contracts.json generation per Worker (v0.177, #643).
secrets
bynk-secrets.json generation per Worker (v0.172, ADR 0195).
toml_doc
P7.3 (#1303): a minimal typed TOML tree and printer — the one piece of R7.8 (Artefacts is a keyed set of typed documents, never a String at construction) landable ahead of bynk-ts (Arc B, P7.5+), since wrangler.toml is the one document bynk-emit produces that isn’t TypeScript. Not a general TOML library: TomlValue represents exactly what emitter::wrangler::emit_wrangler_toml needs to build a wrangler.toml today, no more.
wrangler
wrangler.toml generation per Worker (v0.8 §4.4 / §4.5).

Structs§

SystemHttpClaims
#2019: what a system-tier call needs to sign the claims a refinement actor’s predicate checks (actor Admin = User where hasClaim("admin")). A route guarded by a refinement has drivers that take a trailing claims object, signed into the JWT next to sub; a call acting as a refinement actor passes that actor’s witness claims, and any other call passes {}, so the Worker’s seam answers 403 exactly as it would a real token lacking the claim.
SystemJobServices
#2136: the cron and queue services a system-tier case drives through the participant Worker’s real scheduled and queue entry points. A svc.schedule("<expr>", …) address on a cron service here lowers to __sysdrive_schedule_<svc>_<index>(…), and q.message(m) on a queue service to __sysdrive_message_<q>(m) (tests_emit::emit_system_job_support).

Functions§

emit_runtime_module
Emit the contents of out/runtime.ts. This module ships with every project so the per-context / per-test emissions can import { Ok, Err, Some, None, ... } from a single source. It includes:
emit_tsconfig
Emit the contents of out/tsconfig.json. The CLI uses tsc -p against this when running bynkc test; users can also drive tsc against it directly to produce JS for deployment.
emit_tsconfig_with_source_maps
The bynkc test --coverage variant (#854): the same config with sourceMap enabled, so tsc emits the .js.maps the coverage remap consumes (hop 1, .js → emitted .ts). Kept coverage-only rather than folded into the default so a normal bynkc test / deployment tsc run ships no .js.maps. The runner overwrites the default out/tsconfig.json with this before tsc.