Skip to content

Emission

Bynk compiles to TypeScript. This page summarises what each construct emits. The output is deterministic and headed // Generated by bynkc — do not edit by hand.

TargetFlagLayoutCross-context calls
Bundle--target bundle (default)flat .ts tree mirroring sourcedirect in-process calls
Workers--target workersone Worker dir per contextJSON over Service Bindings, validated at the boundary

See Target Cloudflare Workers.

Bynk source

commons → plain TS types and functions

target: bundle

target: workers

flat .ts tree mirroring source; StateRegistry for agents

per context: index.ts (router + validation), handlers.ts, compose.ts, wrangler.toml

agent → Durable Object: loadState / commitState

record → serialise_ / deserialise_ boundary helpers

One construct, deterministic output — and what that output is depends on the target.

Text equivalent: a commons emits plain TypeScript types and functions on either target. On bundle, the output is a flat .ts tree mirroring the source, with a StateRegistry backing agents. On workers, each context emits index.ts (router and boundary validation), handlers.ts (logic), compose.ts (wiring), and wrangler.toml; each agent emits a Durable Object class with loadState / commitState; and records gain serialise_* / deserialise_* helpers for the boundary.

BynkTypeScript
type Id = Int (alias)branded number + Id.of/Id.unsafe
refined typebranded base + .of (runtime predicate check) + .unsafe
opaque typebranded base + constructors; no structural access
recordinterface with readonly fields; object literal construction
sumdiscriminated union on tag + a constructor namespace
type Status = | Pending | Shipped(tracking: String)
export type Status =
{ readonly tag: "Pending" }
| { readonly tag: "Shipped"; readonly tracking: string };
export const Status = {
Pending: { tag: "Pending" } as Status,
Shipped: (tracking: string): Status => ({ tag: "Shipped", tracking }),
};
BynkTypeScript
if … else …conditional expression / if
matchswitch on .tag, payloads bound as const
admitted literalT.unsafe(literal)
?early-return on Err
<-await

A state interface, a zero-value factory, and a class with loadState / commitState. On bundle, a StateRegistry; on workers, a Durable Object.

function __zeroOfCounterState(): CounterState { return { count: 0 }; }
// loadState(): return stored ?? __zeroOfCounterState();

Each context with HTTP handlers emits handlers.ts (logic), index.ts (router + boundary validation), compose.ts (wiring), and wrangler.toml. Records gain serialise_* / deserialise_* helpers for the boundary.

A per-target test module plus an aggregating tests/main.ts runner; bynkc test compiles, type-checks with tsc, and runs it with Node.