behavior-contracts 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +246 -350
  2. package/cli-contract.yaml +49 -51
  3. package/dist/authoring.d.ts +80 -420
  4. package/dist/authoring.d.ts.map +1 -1
  5. package/dist/authoring.js +53 -1157
  6. package/dist/authoring.js.map +1 -1
  7. package/dist/behavior.d.ts +31 -15
  8. package/dist/behavior.d.ts.map +1 -1
  9. package/dist/behavior.js +55 -0
  10. package/dist/behavior.js.map +1 -1
  11. package/dist/builder.d.ts +4 -4
  12. package/dist/builder.d.ts.map +1 -1
  13. package/dist/builder.js +18 -16
  14. package/dist/builder.js.map +1 -1
  15. package/dist/cli.js +5 -5
  16. package/dist/cli.js.map +1 -1
  17. package/dist/commands/codegen.d.ts.map +1 -1
  18. package/dist/commands/codegen.js +12 -56
  19. package/dist/commands/codegen.js.map +1 -1
  20. package/dist/commands/ts-compile.d.ts +23 -0
  21. package/dist/commands/ts-compile.d.ts.map +1 -0
  22. package/dist/commands/ts-compile.js +693 -0
  23. package/dist/commands/ts-compile.js.map +1 -0
  24. package/dist/commands/ts-extract.d.ts +55 -7
  25. package/dist/commands/ts-extract.d.ts.map +1 -1
  26. package/dist/commands/ts-extract.js +177 -64
  27. package/dist/commands/ts-extract.js.map +1 -1
  28. package/dist/generated/contract.d.ts.map +1 -1
  29. package/dist/generated/contract.js +2 -2
  30. package/dist/generated/contract.js.map +1 -1
  31. package/dist/generated/program.js +4 -4
  32. package/dist/generated/program.js.map +1 -1
  33. package/dist/generator/core.d.ts +11 -1
  34. package/dist/generator/core.d.ts.map +1 -1
  35. package/dist/generator/core.js +5 -4
  36. package/dist/generator/core.js.map +1 -1
  37. package/dist/generator/emit-php.d.ts +0 -17
  38. package/dist/generator/emit-php.d.ts.map +1 -1
  39. package/dist/generator/emit-php.js +25 -1
  40. package/dist/generator/emit-php.js.map +1 -1
  41. package/dist/generator/emit-python.d.ts +0 -7
  42. package/dist/generator/emit-python.d.ts.map +1 -1
  43. package/dist/generator/emit-python.js +34 -1
  44. package/dist/generator/emit-python.js.map +1 -1
  45. package/dist/generator/emit-straightline-typed-typescript.js +1 -1
  46. package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
  47. package/dist/generator/emit-typed-native-go.d.ts +1 -1
  48. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  49. package/dist/generator/emit-typed-native-go.js +122 -112
  50. package/dist/generator/emit-typed-native-go.js.map +1 -1
  51. package/dist/generator/emit-typed-native-rust.d.ts +3 -2
  52. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  53. package/dist/generator/emit-typed-native-rust.js +61 -125
  54. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  55. package/dist/generator/emit-typescript-native.js +1 -1
  56. package/dist/generator/emit-typescript-native.js.map +1 -1
  57. package/dist/generator/emit-typescript.js +1 -1
  58. package/dist/generator/emit-typescript.js.map +1 -1
  59. package/dist/generator/typed.d.ts +5 -1
  60. package/dist/generator/typed.d.ts.map +1 -1
  61. package/dist/generator/typed.js +40 -9
  62. package/dist/generator/typed.js.map +1 -1
  63. package/dist/guard.d.ts +11 -0
  64. package/dist/guard.d.ts.map +1 -1
  65. package/dist/guard.js +35 -8
  66. package/dist/guard.js.map +1 -1
  67. package/dist/index.d.ts +20 -57
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +25 -101
  70. package/dist/index.js.map +1 -1
  71. package/dist/lowering.d.ts +251 -0
  72. package/dist/lowering.d.ts.map +1 -0
  73. package/dist/lowering.js +682 -0
  74. package/dist/lowering.js.map +1 -0
  75. package/dist/provenance.js +4 -4
  76. package/dist/provenance.js.map +1 -1
  77. package/dist/runtime.d.ts +52 -0
  78. package/dist/runtime.d.ts.map +1 -0
  79. package/dist/runtime.js +77 -0
  80. package/dist/runtime.js.map +1 -0
  81. package/dist/spec-versions.d.ts +25 -0
  82. package/dist/spec-versions.d.ts.map +1 -0
  83. package/dist/spec-versions.js +26 -0
  84. package/dist/spec-versions.js.map +1 -0
  85. package/dist/type-gate.d.ts +12 -0
  86. package/dist/type-gate.d.ts.map +1 -1
  87. package/dist/type-gate.js +79 -3
  88. package/dist/type-gate.js.map +1 -1
  89. package/package.json +5 -1
  90. package/dist/bind.d.ts +0 -88
  91. package/dist/bind.d.ts.map +0 -1
  92. package/dist/bind.js +0 -155
  93. package/dist/bind.js.map +0 -1
  94. package/dist/lower.d.ts +0 -35
  95. package/dist/lower.d.ts.map +0 -1
  96. package/dist/lower.js +0 -118
  97. package/dist/lower.js.map +0 -1
package/README.md CHANGED
@@ -1,63 +1,87 @@
1
1
  # behavior-contracts
2
2
 
3
- `behavior-contracts` (**bc**) is the SCP→native substrate. A behavior is authored once in
4
- TypeScript with the **SCP authoring API**; that single definition is both a spec and an
5
- executable function. In TypeScript it **runs directly** — `lowerBehaviors` lowers it in memory to
6
- a native-JS-speed direct-call closure (no interpreter, no explicit codegen step, zero runtime
7
- deps). For every other language the `bc` CLI compiles it — in one pass — either to
8
- **genuinely-native per-language code** (Go and Rust) that runs at hand-written-SDK-floor parity,
9
- or to a module driven by a small shared runtime (Python / PHP). Compilation is deterministic and
10
- canonically-serialized, so the same authored behavior produces byte-identical output across every
11
- language.
12
-
13
- You author in **SCP** (TypeScript). The IR is bc's own internal intermediate, produced by the
14
- public `compileBehaviors` seam and never hand-written or hand-handled. Running an authored behavior
15
- is `lowerBehaviors` in TypeScript and `bc generate` for every other language; the only native code
16
- hand-written downstream is one op-agnostic **leaf transport** per leaf, and the library that owns
17
- the behaviors ships those.
18
-
19
- ## How it fits together
3
+ **`behavior-contracts` (bc) is a DSL for declaring what a piece of behavior *means*.**
4
+
5
+ In most codebases, business logic, persistence, transactions, external calls, error handling and
6
+ execution order all end up tangled inside one function in one language. Responsibility boundaries
7
+ blur, the implementation and the documentation drift apart, and the order of execution gets baked
8
+ into the code.
9
+
10
+ bc separates the two questions. You declare **what the behavior means** — which components
11
+ compose into which result — as a contract. You do **not** write how it is orchestrated: execution
12
+ order is derived from the data dependencies, not written by hand. The declaration is ordinary
13
+ TypeScript, so it is simultaneously the specification *and* the running code.
14
+
15
+ ```ts
16
+ import { behavior, type Int } from "behavior-contracts";
17
+
18
+ class UserQueries {
19
+ @behavior
20
+ static findByEmail(email: string): User[] {
21
+ return Db.query(`SELECT id, email FROM users WHERE email = ?`, [email]);
22
+ }
23
+ }
24
+ ```
25
+
26
+ That method *is* the contract. `@behavior` is a marker: at runtime it does nothing — the method
27
+ runs as plain TypeScript — and at build time it marks the entry point bc reads.
28
+
29
+ ## Because the meaning is implementation-independent, it can target any language
30
+
31
+ A declaration says what the behavior means, not how one language happens to implement it. That
32
+ independence is what makes the rest possible: **one declaration compiles to Go, Rust, Python and
33
+ PHP** — Go and Rust as genuinely native code running at hand-written-SDK-floor parity, Python and
34
+ PHP as modules driven by a small shared runtime. Compilation is deterministic and canonically
35
+ serialized, so the same declaration produces byte-identical results in every language.
36
+
37
+ Multi-language codegen is a *consequence* of the design, not the point of it.
20
38
 
21
39
  ```mermaid
22
40
  flowchart TD
23
- TS["TS code — SCP behavior<br/>(a spec AND an executable function)"]
24
- IR["codegen-internal IR"]
25
- TSN["TS-native code<br/>(JS closure · runs at native speed)"]
26
- ML["multi-language code<br/>(Go · Rust · Python · PHP)"]
27
- LEAF["leaf nodes"]
28
-
29
- TS -->|compileBehaviors| IR
30
- IR -->|"in-memory · no explicit codegen"| TSN
31
- IR -->|bc generate| ML
32
- LEAF -. bound to per-language functions .-> TSN
33
- LEAF -. bound to per-language functions .-> ML
41
+ TS["Declaration — ordinary TypeScript<br/>(the contract AND the running code)"]
42
+ RUN["runs directly in TypeScript"]
43
+ IR["bc-internal IR"]
44
+ ML["Go · Rust · Python · PHP"]
45
+ LEAF["leaf — the one hand-written<br/>I/O function per language"]
46
+
47
+ TS --> RUN
48
+ TS -->|"bc generate (build time)"| IR
49
+ IR --> ML
50
+ LEAF -. called by .-> RUN
51
+ LEAF -. called by .-> ML
34
52
  ```
35
53
 
36
- One TS behavior definition is **both the spec and an executable function**: it runs directly
37
- in TypeScript (lowered in-memory to a JS closure — no explicit codegen) and generates the
38
- native code for every other language. Leaf nodes bind to a per-language function (the leaf
39
- transport).
54
+ The IR is bc's own internal intermediate — never hand-written or hand-handled. The only code
55
+ hand-written per language is one op-agnostic **leaf transport** per leaf (the actual I/O), and the
56
+ library that owns the behaviors ships those.
57
+
58
+ > The declaration style bc implements is **Semantic Contract Programming (SCP)** — "contract the
59
+ > meaning itself as components, and build larger meaning by combining them". The full paradigm is
60
+ > specified in [`docs/semantic-contract-programming.md`](../docs/semantic-contract-programming.md);
61
+ > you do not need to read it to use bc.
62
+
63
+ > This is the README bundled with the published npm package. It mirrors the monorepo root
64
+ > README; the repository also holds the specs, conformance vectors and examples it links to.
40
65
 
41
66
  ## Who this is for
42
67
 
43
68
  bc sits under a stack of three levels; the two audiences below are levels 2 and 3.
44
69
 
45
- 1. **behavior-contracts (bc)** — this package: the SCP→native codegen substrate.
70
+ 1. **behavior-contracts (bc)** — this package: the declaration substrate and its native codegen.
46
71
  2. **A library built on bc** — a *bc consumer* (e.g. litedbmodel or graphddb), the
47
72
  **library author**. Its job is to express its own domain surface (e.g. litedbmodel's
48
- decorators) as bc behaviors: its own decorators are metadata-only collectors, an adapter
49
- lowers that metadata to bc SCP via the authoring API + `compileBehaviors`, and it **ships the
50
- per-language leaf transports** (Go / Rust / …). This is the audience that writes
51
- `SemanticBehavior` / `@behavior` classes, `defineLeaf`, `In<T>`, and the expression builders,
52
- and hand-writes each leaf transport once per language. It provides everything except the end
53
- user's model. → **Section A**.
73
+ decorators) as bc declarations: its own decorators stay metadata-only collectors, and its
74
+ lowering step produces the declaration-limited TypeScript that bc reads. It also **ships the
75
+ per-language leaf transports** (Go / Rust / …). This is the audience that writes `@behavior` /
76
+ `@leaf` methods and hand-writes each leaf transport once per language. It provides everything
77
+ except the end user's model. → **Section A**.
54
78
  3. **A user of such a library** — the **end user** (the library's consumer, e.g. a
55
- litedbmodel user). They define their model with the *library's* own surface and run it. In
56
- **TypeScript** that is `lowerBehaviors(Model)` → call the returned closure directly (native
57
- speed, no `bc generate`). For **Go / Rust / Python / PHP** it is `bc generate` (the `bc` CLI,
58
- run directly) linked to the library's shipped leaf transports, then a call to the generated
59
- entry point. They write **no SCP, no leaf transport, no IR** — just the model and the run
60
- call. → **Section B**.
79
+ litedbmodel user). They declare their model with the *library's* own surface and run it. In
80
+ **TypeScript** they simply **call the method** — the markers are no-ops at runtime, so the
81
+ declaration is just TypeScript that runs. For **Go / Rust / Python / PHP** it is `bc generate`
82
+ (the `bc` CLI, run directly) linked to the library's shipped leaf transports, then a call to the
83
+ generated entry point. They write **no declarations for bc, no leaf transport, no IR** — just the
84
+ model and the run call. → **Section B**.
61
85
 
62
86
  If you are **building** a library on top of bc, read **Section A**. If you are **using** a
63
87
  library that was built on bc, read **Section B**.
@@ -77,20 +101,78 @@ library that was built on bc, read **Section B**.
77
101
  payload and returns a `WireValue` — no trait, no probe protocol, no per-role signature.
78
102
  - **Fail-closed, never silently boxed.** Shapes not yet natively coverable are rejected at
79
103
  generation time rather than falling back to a boxed/interpreted path labelled as native.
80
- An ambiguous or non-canonical type is rejected **loudly at authoring**.
81
- - **Native-speed TypeScript, in memory.** `lowerBehaviors` lowers an authored behavior to a
82
- directly-callable JS closure at native JS speed — no interpreter, no explicit codegen step, no
83
- generated file, zero runtime deps — so a TS-defined behavior runs directly in TS.
84
- - **Shared interpreter for Python and PHP.** The same authored behavior emits an interpreter
104
+ An ambiguous or non-canonical type is rejected **loudly at build time**.
105
+ - **In TypeScript the declaration just runs.** `@behavior` / `@leaf` are no-op markers at
106
+ runtime, so a declared method is an ordinary static method: calling it executes the leaf
107
+ implementations directly at native JS speed — no interpreter, no lowering call, no generated
108
+ file, zero runtime deps.
109
+ - **Shared interpreter for Python and PHP.** The same declaration emits an interpreter
85
110
  module that runs on the shared runtime with identical semantics (a TypeScript interpreter module
86
- is available too, as an alternative to in-memory lowering).
111
+ is available too, when you want an emitted file rather than a direct call).
87
112
  - **Deterministic, canonical serialization.** Key-sorted, typed-value encoding with a
88
113
  canonical decimal float representation — the same behavior always serializes to the same
89
114
  bytes, which is what makes cross-language conformance verifiable.
90
115
 
91
- Native de-box codegen is for **Go and Rust**. **TypeScript** runs in-memory at native JS speed via
92
- `lowerBehaviors` (or an emitted interpreter module); Python and PHP consume the compiled behavior
93
- through the shared interpreter.
116
+ Native de-box codegen is for **Go and Rust**. **TypeScript** needs no codegen at all — the
117
+ declaration runs as-is; Python and PHP consume the compiled behavior through the shared
118
+ interpreter.
119
+
120
+ ## What you can write in a declaration
121
+
122
+ A declaration body is ordinary TypeScript, but only the subset below carries meaning across
123
+ languages. Everything in it is written as **native TypeScript syntax** — bc reads the syntax and
124
+ derives the contract. Anything outside this subset is **rejected loudly at build time** (never
125
+ silently reinterpreted).
126
+
127
+ **Values and references**
128
+
129
+ | You write | Meaning |
130
+ |---|---|
131
+ | `email` (a parameter) | an input port |
132
+ | `row.title` | a field reference |
133
+ | `row?.title` | an optional reference (missing is a value, not an error) |
134
+ | `` `A#${id}` `` / `"a" + id` | string concatenation |
135
+ | `1`, `"x"`, `true`, `null`, `[…]`, `{…}` | literals (`Int` / `Float` distinguish integer from float) |
136
+
137
+ **Operators**
138
+
139
+ | You write | Meaning |
140
+ |---|---|
141
+ | `+` `-` `*` `/` `%` `-x` | arithmetic (`add` `sub` `mul` `div` `mod` `neg`) |
142
+ | `===` `!==` `<` `<=` `>` `>=` | comparison |
143
+ | `&&` `\|\|` `!` | boolean logic (operands must be `bool` — no truthiness) |
144
+ | `??` | default when null (`coalesce`) |
145
+ | `xs.length` | length of an array |
146
+
147
+ Loose equality (`==` / `!=`) and truthy conditions are rejected — the meaning must be unambiguous
148
+ in every target language.
149
+
150
+ **Control flow**
151
+
152
+ | You write | Meaning |
153
+ |---|---|
154
+ | `cond ? a : b` | choose a value, or choose which component runs |
155
+ | `if (cond) { … }` | run a component only when the condition holds (otherwise it is skipped) |
156
+ | `xs.map(x => …)` | run a component once per element |
157
+
158
+ Execution order is **not** written: bc derives it from the data dependencies, and independent work
159
+ is scheduled concurrently.
160
+
161
+ **Components (the units of meaning)**
162
+
163
+ | You write | Meaning |
164
+ |---|---|
165
+ | `@behavior static m(a: T): R` | a declared behavior — arguments are input ports, the return type is the output |
166
+ | `@leaf static f(a: T): R` | a leaf — the boundary where real I/O happens (one hand-written transport per language) |
167
+ | `Db.query(sql, params)` | calling a leaf = one component in the graph |
168
+ | `const x: T = …` | pins the result type of a node |
169
+ | `opt(x)` | make a reference optional |
170
+ | `xs.map(f, { into, batched })` | map options: zip the result into each element / batch the calls |
171
+ | `refsConnection(…, { dedupeKey, drop, implicitSource })` | fan out over references, de-duplicating them |
172
+
173
+ `@behavior` and `@leaf` are **markers**: at runtime they do nothing, so the method is an ordinary
174
+ static method that just runs. `opt` and `refsConnection` are the only two helpers with no native
175
+ TypeScript equivalent.
94
176
 
95
177
  ## Install
96
178
 
@@ -101,66 +183,67 @@ npm install behavior-contracts
101
183
  - ESM-only library; TypeScript type declarations are included.
102
184
  - Requires Node.js **22+**.
103
185
  - No runtime dependencies. (`typescript` is a build-time-only optional peer, needed by the
104
- CLI to codegen from a `.ts` authoring module.)
186
+ CLI to codegen from a `.ts` declaration module.)
187
+ - If you **run a generated TypeScript module**, keep `behavior-contracts` as a dependency of the
188
+ project that runs it — the generated module pulls what it needs from this package itself.
105
189
 
106
190
  ---
107
191
 
108
192
  # Section A — For library authors (building a library on bc)
109
193
 
110
- You are writing the layer that maps your library's own DSL/decorators onto bc. Your decorators
111
- stay metadata-only collectors; an adapter reads that metadata and lowers each domain operation to
112
- a bc **behavior** with the SCP authoring API below, and `compileBehaviors` turns those behaviors
113
- into bc's internal IR. You also **ship one op-agnostic leaf transport per leaf, per language** — so
114
- your users only declare a model and run it (Section B). Everything in this section is exported from
115
- the package root (`behavior-contracts`).
116
-
117
- ## Author in TypeScript
118
-
119
- Behaviors are `@behavior` classes (or classes extending `SemanticBehavior`); each public
120
- method is a root behavior. The input-port bag is the method's `$: In<T>` parameter, and `T`
121
- is a plain TS type. Numeric precision uses the `Int` / `Float` branded aliases — plain TS
122
- `number` is **rejected** because it is ambiguous between a 64-bit int and a 64-bit float and
123
- BC does not infer. Leaves are declared once with `defineLeaf`; its meta carries the leaf's
124
- **transport symbol name** (the contract name the end user implements). Types are given as TS
125
- types and canonical PortableType notation only — there is **no `inputPorts` type-struct to
126
- hand-write**, and a non-canonical notation (e.g. an angle-bracket string like
127
- `"arr<obj<...>>"`) is rejected loudly at authoring.
194
+ You are writing the layer that maps your library's own DSL/decorators onto bc. Your decorators stay
195
+ metadata-only collectors; your lowering step turns that metadata into **declaration-limited
196
+ TypeScript** — the `@behavior` / `@leaf` methods below — and `bc generate --from` reads that source
197
+ **statically** (it parses the AST; it never executes your module). You also **ship one op-agnostic
198
+ leaf transport per leaf, per language** — so your users only declare a model and run it (Section B).
199
+
200
+ Because the lowering step produces source, one of your decorators can expand into **several** leaves
201
+ or a composed behavior: the structure you emit is your choice, and bc reads whatever declaration
202
+ comes out.
203
+
204
+ ## Declare in TypeScript
205
+
206
+ A behavior is a `@behavior static` method. Its **parameters are the inputs** (natural positional
207
+ arguments — no bag object), and its **return type is the output**. A leaf is a `@leaf static`
208
+ method whose **signature is the contract** bc reads: parameters become the leaf's input ports and
209
+ the return type its output (a `T[]` return means the leaf yields many). Numeric precision uses the
210
+ `Int` / `Float` branded aliases — plain TS `number` is **rejected** because it is ambiguous between
211
+ a 64-bit int and a 64-bit float and bc does not infer.
128
212
 
129
213
  ```ts
130
- import { behavior, defineLeaf, behaviorComponents, SemanticBehavior, type In } from "behavior-contracts";
131
-
132
- // A leaf is a typed static function. `ports`/`output` are canonical PortableType notation;
133
- // `transport` fixes the op-agnostic symbol name the leaf transport uses (default: Leaf_<name> /
134
- // leaf_<name>). The impl body is never touched by `bc generate` — it is the TS run path
135
- // (interpreter and `lowerBehaviors`); the native languages call the transport of that name.
136
- const Select = defineLeaf(
137
- "Select",
138
- {
139
- cardinality: "many",
140
- ports: { sql: "string", email: "string" },
141
- output: { obj: { id: "int", email: "string" } },
142
- transport: "Leaf_Select",
143
- },
144
- (p, ctx) => runYourQuery(p.sql, p.email),
145
- );
146
-
147
- const C = behaviorComponents({ Select });
148
-
149
- @behavior
150
- export class UserRepo extends SemanticBehavior {
151
- findByEmail($: In<{ email: string }>) {
152
- return C.Select({ sql: "SELECT id, email FROM users WHERE email = ?", email: $.email })
153
- .as<{ arr: { obj: { id: "int"; email: "string" } } }>({ arr: { obj: { id: "int", email: "string" } } });
214
+ import { behavior, leaf, type Int } from "behavior-contracts";
215
+
216
+ export interface User {
217
+ id: Int;
218
+ email: string;
219
+ }
220
+
221
+ // A leaf is a typed static method. Its SIGNATURE is what bc reads (input ports `sql` / `key`,
222
+ // output `User[]`). The BODY is the TypeScript run path — it is never touched by `bc generate`;
223
+ // the native languages call the leaf transport of the corresponding name instead.
224
+ export class Db {
225
+ @leaf static Select(sql: string, key: string): User[] {
226
+ return runYourQuery(sql, key);
227
+ }
228
+ }
229
+
230
+ export class UserRepo {
231
+ @behavior static findByEmail(email: string) {
232
+ return Db.Select("SELECT id, email FROM users WHERE email = ?", email);
154
233
  }
155
234
  }
156
235
  ```
157
236
 
158
- This authored module is what your library ships (or generates from its own decorator surface); it
159
- is the `--from <authoring.ts> --behavior <Class>` the `bc` CLI compiles for Go / Rust / Python /
160
- PHP, and the class `lowerBehaviors` runs directly in TypeScript (Section B). Expression logic inside
161
- a behavior is built with the closed operator vocabulary
162
- (`when` / `concat` / `add` / … / `opt` / `coalesce` / `len`); `add` and its siblings are the
163
- authoring IR builders (distinct from the `codegenPrimitives` the generated code calls).
237
+ That module is what your library ships (or generates from its own decorator surface); it is the
238
+ `--from <model.ts> --behavior <Class>` the `bc` CLI compiles for Go / Rust / Python / PHP, and in
239
+ TypeScript it is simply called (Section B).
240
+
241
+ Bodies are ordinary TypeScript, restricted to what carries a portable meaning: `+` / `?:` / `&&` /
242
+ `if` / `.map` / `?.` / template literals / comparisons all lower to the portable expression and
243
+ control vocabulary. Two helpers exist because native syntax cannot express them: `opt(x)` (an
244
+ optional reference — `opt(x).field`) and `refsConnection(list, cb, opts)` (a de-duplicated fan-out).
245
+ Anything outside the portable vocabulary is rejected loudly at build time rather than silently
246
+ mis-lowered.
164
247
 
165
248
  ## Ship the per-language leaf transports
166
249
 
@@ -178,7 +261,7 @@ The **same one transport** serves a leaf across **all** its roles and cardinalit
178
261
  (base / GSI / limited / batched / fanout) — divergent port sets are just different payload fields,
179
262
  and there is no per-role signature. The generated native hot path stays fully typed; only the leaf
180
263
  boundary is wire (de-box once). The default symbol name is `Leaf_<comp>` (Go) / `leaf_<comp>`
181
- (Rust); `defineLeaf`'s `transport` fixes it, and `--leaf-transport <leaf>=<sym>` can override it.
264
+ (Rust), and `--leaf-transport <leaf>=<sym>` overrides it per leaf.
182
265
 
183
266
  ```go
184
267
  package tx
@@ -188,7 +271,7 @@ import "example.com/app/wire"
188
271
  // One op-agnostic function per leaf. Reads its inputs from the payload by name, does the raw
189
272
  // I/O, and builds the BC-owned WireValue. The covered module owns all classification/de-box.
190
273
  func Leaf_Select(payload wire.WireRow) (wire.WireValue, error) {
191
- email := payload.ProbeString("email").Got // the port the covered module bound
274
+ email := payload.ProbeString("key").Got // the port the covered module bound
192
275
  _ = email
193
276
  return wire.WireListOf([]wire.WireValue{
194
277
  wire.WireRowOf([]wire.WireField{
@@ -218,13 +301,13 @@ result:
218
301
 
219
302
  ```bash
220
303
  # Go cross-package — emit ONLY the shared wire package (no --out ⇒ no covered module here):
221
- bc generate --lang go-typed-native --from behaviors.ts --behavior UserRepo \
304
+ bc generate --lang go-typed-native --from model.ts --behavior UserRepo \
222
305
  --shared-types-out wire/wire.go \
223
306
  --shared-types-import example.com/app/wire \
224
307
  --leaf-transport-import example.com/app/tx
225
308
 
226
309
  # Rust cross-crate:
227
- bc generate --lang rust-typed-native --from behaviors.ts --behavior UserRepo \
310
+ bc generate --lang rust-typed-native --from model.ts --behavior UserRepo \
228
311
  --shared-types-out wire/src/lib.rs \
229
312
  --shared-types-import bcwire \
230
313
  --leaf-transport-import bctx
@@ -232,7 +315,10 @@ bc generate --lang rust-typed-native --from behaviors.ts --behavior UserRepo \
232
315
 
233
316
  Runnable end-to-end samples of the library side + a shared wire seam:
234
317
  [`examples/building-a-library-on-bc/`](../examples/building-a-library-on-bc/) (custom decorators →
235
- SCP + Go/Rust transports), plus the standalone cross-layout samples
318
+ declarations + Go/Rust transports) and
319
+ [`examples/library-lowering-patterns/`](../examples/library-lowering-patterns/) (metadata → **emitted**
320
+ declaration source, one relation declaration expanding into several leaf calls, and CQRS derived by
321
+ the library), plus the standalone cross-layout samples
236
322
  [`examples/go-cross-package/`](../examples/go-cross-package/) (Go, separate transport package),
237
323
  [`examples/rust-cross-crate/`](../examples/rust-cross-crate/) (Rust, separate transport crate), and
238
324
  [`examples/rust-cross-module/`](../examples/rust-cross-module/) (Rust, intra-crate — no shared crate
@@ -240,223 +326,19 @@ needed).
240
326
 
241
327
  ## Public API reference
242
328
 
243
- Everything below is exported from the package root (`behavior-contracts`). Cross-language
244
- **codegen** is CLI-only — the `bc` binary is the sole public codegen entry, so no emitter appears
245
- here — but the **compile seam** (`compileBehaviors`, SCP→IR) and the **TS lowering** entry
246
- (`lowerBehaviors`) are public functions and do appear below.
247
-
248
- ### Authoring surface
249
-
250
- The effect-agnostic authoring API. A `@behavior` / `SemanticBehavior` class lowers each
251
- public method to one component-graph root behavior; leaves are declared with `defineLeaf`;
252
- port and result types are given as TS types (with the `Int` / `Float` branded aliases and
253
- canonical PortableType notation).
329
+ Everything you import from `behavior-contracts` when declaring behaviors — this is the whole list.
330
+ Cross-language **codegen** is CLI-only: the `bc` binary is the sole public codegen entry, so no
331
+ emitter and no compile function appears here.
254
332
 
255
333
  | Export | Kind | Purpose |
256
334
  |---|---|---|
257
- | `SemanticBehavior` | class | Base class a behavior class extends; each public method is a root behavior. |
258
- | `behavior` | decorator | Marks a class as a behavior module (alternative to extending `SemanticBehavior`). |
259
- | `defineLeaf` | fn | Declares a leaf: ports/output types, cardinality, and the transport symbol name the end user implements. |
260
- | `behaviorComponents` | fn | Bundles declared leaves/components into a callable component map used inside behavior bodies. |
261
- | `catalogComponents` | fn | Builds the component catalog consumed by the runtime/binder from declared components. |
262
- | `catalogEntryFromLeaf` | fn | Derives a single catalog entry from a leaf definition. |
263
- | `deriveCatalog` | fn | Derives the full catalog from a set of authored behaviors/leaves. |
264
- | `referencedComponents` | fn | Lists the components a lowered behavior references (library-side CQRS derivation). |
265
- | `classifyBehaviorEffect` | fn | Classifies a behavior's effect (read/write) from its lowered graph. |
266
- | `AuthoringFailure` | error | Thrown for invalid authoring (e.g. non-canonical type, ambiguous `number`). |
267
- | `when` | builder | Conditional/guard expression builder. |
268
- | `concat` | builder | String concatenation expression builder. |
269
- | `add` `sub` `mul` `div` `mod` `neg` | builder | Arithmetic expression builders. |
270
- | `eq` `ne` `lt` `le` `gt` `ge` | builder | Comparison expression builders. |
271
- | `and` `or` `not` | builder | Boolean expression builders. |
272
- | `coalesce` | builder | Null-coalescing expression builder. |
273
- | `len` | builder | Length expression builder. |
274
- | `opt` | builder | Marks a port/value as optional (key-omittable) in the type. |
275
- | `In` | type | Wrapper type for a behavior method's input-port bag (`$: In<T>`). |
335
+ | `behavior` | decorator | Marks a `static` method as one root behavior. No-op at runtime; the entry point bc reads at build time. |
336
+ | `leaf` | decorator | Marks a `static` method as one leaf. Its signature is the contract (parameters → input ports, return type → output); its body is the TypeScript run path. |
337
+ | `opt` | fn | Optional reference — `opt(x).field` lowers to an absence-tolerant read. Identity at runtime. |
338
+ | `refsConnection` | fn | De-duplicated fan-out over a list (`dedupeKey`, optional `implicitSource`), returning `{ items, cursor }`. |
339
+ | `AuthoringFailure` | error | Thrown for an invalid declaration (e.g. a non-portable body, ambiguous `number`). |
276
340
  | `Int` / `Float` | type | Branded numeric aliases that disambiguate 64-bit int vs. float (plain `number` is rejected). |
277
- | `Recorded` | type | Marks a recorded (persisted) value in a behavior signature. |
278
- | `BehaviorClass` | type | Type of a class usable as a behavior module. |
279
- | `CompileBehaviorsOptions` | type | Options accepted by the compile seam the CLI drives. |
280
- | `BehaviorEffect` | type | Effect classification result (read/write). |
281
341
  | `AuthoringFailureCode` | type | Discriminant codes for `AuthoringFailure`. |
282
- | `LeafDefinition` | type | The shape returned by `defineLeaf`. |
283
- | `LeafMeta` | type | A leaf's declared meta (ports, output, cardinality, transport). |
284
- | `PortableTypeToTs` / `PortsToTs` | type | Type-level maps from canonical PortableType notation to TS types. |
285
-
286
- ### Compile & lower
287
-
288
- The public compile seam (SCP → bc's internal IR) and the TypeScript lowering entry (compile → run
289
- in memory at native JS speed).
290
-
291
- | Export | Kind | Purpose |
292
- |---|---|---|
293
- | `compileBehaviors` | fn | Compiles a `@behavior` / `SemanticBehavior` class (SCP closures only) to bc's internal component-graph IR — the single canonical IR producer, shared by the interpreter, `lowerBehaviors`, and the `bc generate --from` CLI. Rejects raw IR / a non-behavior input (`NOT_A_BEHAVIOR_CLASS`). |
294
- | `lowerBehaviors` | fn (async) | Lowers a behavior class in memory to directly-callable, native-JS-speed closures — no interpreter, no explicit codegen step, zero runtime deps. Leaf impls link automatically from `defineLeaf`; the only injection is `ctx`. Returns a `LoweredBehaviors`. |
295
- | `LoweredBehaviors` | type | The result of `lowerBehaviors`: `{ sync, async }`, each a `{ method: (input) => output }` map of lowered direct-call closures (the `async` twin awaits async leaf impls). |
296
-
297
- ### Interpreter runtime
298
-
299
- The shared runtime that walks a compiled behavior (the TS/Python/PHP path).
300
-
301
- | Export | Kind | Purpose |
302
- |---|---|---|
303
- | `runBehavior` | fn | Executes a compiled component-graph behavior with injected boundary handlers. |
304
- | `runBehaviorAsync` | fn | Async variant of `runBehavior`. |
305
- | `BehaviorFailure` | error | Thrown for a runtime behavior failure (carries structured detail). |
306
- | `fanoutDedupDrop` | fn | Fan-out dedup/drop helper for fan-out result shaping. |
307
- | `portableTypeNotation` | fn | Canonicalizes/serializes a type into portable notation. |
308
- | `conformResultToOutType` | fn | Conforms a handler result to the declared output type. |
309
- | `FanoutDedupDropSpec` | type | Spec for `fanoutDedupDrop`. |
310
- | `PortSchema` | type | Declared schema of a component's ports. |
311
- | `PortableType` / `PortableScalarType` | type | The portable type model (composite and scalar). |
312
- | `CatalogEntry` / `CatalogOutput` / `Catalog` | type | Component catalog types consumed by the runtime. |
313
- | `Handler` / `AsyncHandler` | type | A boundary handler (sync/async) for a component. |
314
- | `Handlers` / `AsyncHandlers` | type | A map of handlers keyed by component. |
315
- | `HandlerCtx` | type | The environment/context passed to a handler. |
316
- | `BehaviorFailureCode` | type | Discriminant codes for `BehaviorFailure`. |
317
-
318
- ### Bind
319
-
320
- | Export | Kind | Purpose |
321
- |---|---|---|
322
- | `bindBehaviors` | fn | Binds registered leaf impls to a compiled catalog after a completeness gate, yielding a dispatchable set. |
323
- | `BindFailure` | error | Thrown when binding is incomplete/invalid. |
324
- | `BoundBehaviors` | type | The dispatchable result of `bindBehaviors`. |
325
- | `BindFailureCode` | type | Discriminant codes for `BindFailure`. |
326
-
327
- ### Provenance & IR handle
328
-
329
- The runtime-side provenance gate and the branded IR handle types used by generated
330
- interpreter modules.
331
-
332
- | Export | Kind | Purpose |
333
- |---|---|---|
334
- | `assertCompiled` | fn | Asserts a value carries a valid compile-provenance token (fail-closed on tampered/stale). |
335
- | `loadCompiledIR` | fn | Adopts a serialized `ComponentGraphIRDoc` into a branded `ComponentGraphIR` handle (used by generated `--lang typescript` modules at load). |
336
- | `fingerprintComponentGraph` | fn | Provenance-gated canonical fingerprint of a component graph. |
337
- | `ProvenanceError` | error | Thrown on a provenance/fingerprint mismatch. |
338
- | `ComponentGraphIR` | type | Branded root handle for a compiled component graph. |
339
- | `ComponentGraphIRDoc` | type | Serialized document form of a compiled component graph (embedded literal in generated interpreter modules). |
340
-
341
- ### Plan
342
-
343
- The portable execution-plan runtime (stage grouping, concurrency, skip propagation, error
344
- policy).
345
-
346
- | Export | Kind | Purpose |
347
- |---|---|---|
348
- | `runPlan` | fn | Executes a portable execution-plan IR. |
349
- | `runPlanAsync` | fn | Async variant of `runPlan`. |
350
- | `finalTree` | fn | Builds the final result tree from a plan run. |
351
- | `PlanFailure` | error | Thrown for a plan execution failure. |
352
- | `POLICY_KINDS` | const | Closed set of policy kinds. |
353
- | `RELATION_KINDS` | const | Closed set of relation kinds. |
354
- | `ELEMENT_POLICY_KINDS` | const | Closed set of per-element error-policy kinds (`error` / `skip`). |
355
- | `ERROR_KINDS` | const | Closed set of error kinds. |
356
- | `ExecutionPlanSpec` / `OpSpec` | type | The plan and per-op spec shapes. |
357
- | `Exec` / `AsyncExec` | type | The executor callback types. |
358
- | `ExecOutcome` / `RunResult` | type | Per-op outcome and overall run result. |
359
- | `PolicyKind` / `RelationKind` / `ElementPolicyKind` / `ErrorKind` | type | Element types of the corresponding `*_KINDS` sets. |
360
- | `ErrorDetail` | type | Structured error detail carried by a failure. |
361
- | `PlanFailureCode` | type | Discriminant codes for `PlanFailure`. |
362
-
363
- ### Type gate
364
-
365
- | Export | Kind | Purpose |
366
- |---|---|---|
367
- | `UntypedNodeError` | error | Thrown when a node/output type is not uniquely determined (fail-closed; guarantees end-to-end typed-flat codegen). |
368
-
369
- ### Guard / portability
370
-
371
- | Export | Kind | Purpose |
372
- |---|---|---|
373
- | `assertPortable` | fn | Fail-closed structural validation that a value is portable IR. |
374
- | `assertPortableComponentGraph` | fn | Portability guard specialized for a component graph. |
375
- | `assertPortableTypeNotation` | fn | Validates a type notation is canonical/portable. |
376
- | `PORTABLE_EXPR_OPERATORS` | const | The closed set of portable expression operators. |
377
- | `PORTABLE_SCALAR_TYPES` | const | The closed set of portable scalar types. |
378
- | `PortabilityError` | error | Thrown on a portability violation. |
379
-
380
- ### Operator type signatures
381
-
382
- The SSoT for the closed expression vocabulary's input/output types (read by the type gate,
383
- never re-derived ad hoc).
384
-
385
- | Export | Kind | Purpose |
386
- |---|---|---|
387
- | `OPERATOR_TYPE_SIGNATURES` | const | The declared input/output type signatures for every operator. |
388
- | `operatorSignature` | fn | Looks up the signature for an operator. |
389
- | `resolveOperatorResult` | fn | Resolves an operator's result type from its operand types. |
390
- | `isValueOperator` | fn | Whether an operator produces a value (vs. a predicate). |
391
- | `OperatorSignature` / `OperatorResultRule` / `OperandConstraint` | type | The signature model types. |
392
-
393
- ### Expression evaluation
394
-
395
- | Export | Kind | Purpose |
396
- |---|---|---|
397
- | `evaluateExpression` | fn | Evaluates the portable expression IR (regnant semantics). |
398
- | `encodeValue` | fn | Encodes a value for the expression evaluator. |
399
- | `cmpCodePoints` | fn | Deterministic code-point string comparison. |
400
- | `ExprFailure` | error | Thrown for an expression evaluation failure. |
401
- | `FORBIDDEN_OBJECT_KEY` | const | The object key forbidden in values (prototype-pollution guard). |
402
- | `Value` / `Scope` | type | The value model and evaluation scope. |
403
- | `ExprFailureCode` | type | Discriminant codes for `ExprFailure`. |
404
-
405
- ### Template rendering
406
-
407
- | Export | Kind | Purpose |
408
- |---|---|---|
409
- | `renderTemplate` | fn | Pure strict `{param}` string substitution. |
410
- | `resolvePartial` | fn | Resolves a partial/nested template reference. |
411
- | `TemplateFailure` | error | Thrown for a template rendering failure. |
412
- | `TemplateFailureCode` | type | Discriminant codes for `TemplateFailure`. |
413
-
414
- ### Canonical serialization
415
-
416
- | Export | Kind | Purpose |
417
- |---|---|---|
418
- | `canonicalValue` | fn | Deterministic canonical value normalization (sorted keys, typed values). |
419
- | `canonicalJson` | fn | Canonical JSON serialization (compact, canonical floats). |
420
- | `pyFloatRepr` | fn | Canonical decimal float representation (Python-compatible). |
421
- | `CanonicalFailure` | error | Thrown for a canonicalization failure. |
422
- | `CanonicalFailureCode` | type | Discriminant codes for `CanonicalFailure`. |
423
-
424
- ### Envelope
425
-
426
- | Export | Kind | Purpose |
427
- |---|---|---|
428
- | `validateEnvelope` | fn | Fail-closed spec-version validation of an envelope (loud-rejects unknown versions). |
429
- | `EnvelopeFailure` | error | Thrown for an envelope validation failure. |
430
- | `EnvelopeFailureCode` | type | Discriminant codes for `EnvelopeFailure`. |
431
-
432
- ### Codec (conformance adapter)
433
-
434
- | Export | Kind | Purpose |
435
- |---|---|---|
436
- | `decodeValue` | fn | Decodes an encoded value (conformance runner adapter). |
437
- | `deepEquals` | fn | Deterministic deep equality (conformance runner adapter). |
438
-
439
- ### Codegen primitives (called by generated code)
440
-
441
- The stable primitive surface generated code calls directly. Individual expression operators
442
- are bundled in the `codegenPrimitives` namespace (thin wrappers delegating to
443
- `evaluateExpression`) to avoid colliding with the same-named authoring IR builders.
444
-
445
- | Export | Kind | Purpose |
446
- |---|---|---|
447
- | `codegenPrimitives` | namespace | The bundled per-operator primitive functions generated code calls. |
448
- | `mapWithConcurrency` | fn | Bounded-concurrency map helper used by generated plans. |
449
- | `unproducedValue` | fn | Sentinel for an unproduced value. |
450
- | `skipSingle` / `skipConnection` | fn | Skip sentinels for single / connection results. |
451
- | `hydrateInto` | fn | Hydration helper used by generated code. |
452
- | `Expr` | type | The expression node type accepted by the primitives. |
453
-
454
- ### Constants
455
-
456
- | Export | Kind | Purpose |
457
- |---|---|---|
458
- | `SPEC_VERSIONS` | const | The IR/vector spec versions this package supports (independent of the library semver). |
459
- | `ENVELOPE_SPEC_VERSION` | const | The default supported envelope spec version (`"<major>.<minor>"`). |
460
342
 
461
343
  ## Spec versions
462
344
 
@@ -479,42 +361,56 @@ library (semver) version:
479
361
 
480
362
  # Section B — For users of a library built on bc
481
363
 
482
- You are using a library (e.g. litedbmodel or graphddb) that was built on bc. You never write bc
483
- `@behavior` classes, leaf transports, or IR — the library already did all of that (Section A). You
484
- **declare a model** with the library's surface, then **run it**.
364
+ You are using a library (e.g. litedbmodel or graphddb) that was built on bc. You never write leaf
365
+ transports or IR — the library already did all of that (Section A). You **declare a model** with the
366
+ library's surface, name your operations, then **run it**.
485
367
 
486
- ## 1. Define your model with the library's surface
368
+ ## 1. Declare your model with the library's surface
487
369
 
488
370
  You describe your model with the **library's own surface** — its decorators, its schema DSL, whatever
489
- it exposes. bc does **not** dictate this; the library does. The library's authoring (Section A)
490
- already turned its surface into bc behaviors, so declaring a model and naming an operation in one
491
- behavior method is your whole domain-level job.
371
+ it exposes. bc does **not** dictate this; the library does. An endpoint is a `@behavior static`
372
+ method whose body calls the library's leaf:
373
+
374
+ ```ts
375
+ import { entity, field, behavior, Db } from "your-library";
376
+
377
+ @entity("users")
378
+ class User {
379
+ @field.int id!: number;
380
+ @field.string email!: string;
381
+ }
382
+
383
+ export class UserRepo {
384
+ @behavior static findByEmail(email: string) {
385
+ return Db.Select("SELECT id, email FROM users WHERE email = ?", email);
386
+ }
387
+ }
388
+ ```
492
389
 
493
- ## 2a. Run it in TypeScript — `lowerBehaviors`, directly
390
+ ## 2a. Run it in TypeScript — just call it
494
391
 
495
- In TypeScript the model runs **in-process** at native JS speed. `lowerBehaviors(Model)` compiles the
496
- behavior and lowers it in memory to directly-callable closures — no interpreter, no `bc generate`
497
- step, no generated file, zero runtime deps. The library's leaf impls link automatically:
392
+ `@behavior` / `@leaf` are no-op markers at runtime, so the declaration is ordinary TypeScript:
393
+ calling the method runs the library's leaf implementation directly, at native JS speed. There is no
394
+ lowering call, no interpreter, no `bc generate`, and no generated file:
498
395
 
499
396
  ```ts
500
- import { lowerBehaviors } from "behavior-contracts";
501
397
  import { UserRepo } from "./model.ts"; // your model, declared with the library's decorators
502
398
 
503
- const repo = await lowerBehaviors(UserRepo); // lower once
504
- const rows = repo.sync.findByEmail({ email: "a@b.c" }); // call the returned closure directly
505
- // rows === [{ id: 1n, email: "a@b.c" }] (int is a bigint in bc's value model)
399
+ const rows = UserRepo.findByEmail("a@b.c"); // a plain static-method call
400
+ // rows === [{ id: 1n, email: "a@b.c" }] (int is a bigint in bc's value model)
506
401
  ```
507
402
 
508
- `lowerBehaviors` returns `{ sync, async }` — the `async` twin awaits async leaf impls. Runnable
509
- sample: [`examples/using-a-bc-library/run-ts.mjs`](../examples/using-a-bc-library/run-ts.mjs).
403
+ Runnable sample:
404
+ [`examples/using-a-bc-library/run-ts.mjs`](../examples/using-a-bc-library/run-ts.mjs).
510
405
 
511
406
  ## 2b. Run it in Go / Rust / Python / PHP — `bc generate`
512
407
 
513
408
  For the other languages the `behavior-contracts` package installs a `bc` binary you run **yourself**
514
- (not through the library). `bc generate --from <model.ts> --behavior <Class>` imports the module,
515
- type-extracts each method's `$: In<T>` type via the TypeScript compiler, and compiles ts → ir →
516
- native (Go / Rust) or a shared-runtime interpreter module (Python / PHP) in **one pass**. You wire it
517
- to the library's shipped leaf transports + BC-owned wire types with `--leaf-transport-import` /
409
+ (not through the library). `bc generate --from <model.ts> --behavior <Class>` reads your TypeScript
410
+ **source** with the TypeScript compiler — type-extracting each method's parameter and return types
411
+ and lowering its body's AST — and compiles source → ir → native (Go / Rust) or a shared-runtime
412
+ interpreter module (Python / PHP) in **one pass**. Your module is never executed. You wire it to the
413
+ library's shipped leaf transports + BC-owned wire types with `--leaf-transport-import` /
518
414
  `--shared-types-import` — you write neither; the library ships them (Section A):
519
415
 
520
416
  ```bash
@@ -535,8 +431,8 @@ bc check --lang go-typed-native --from model.ts --behavior UserRepo --out go/beh
535
431
  ```
536
432
 
537
433
  Full flag reference: `bc generate --help` (also generated at
538
- [`docs/cli-reference.md`](./docs/cli-reference.md)). `--in <ir-doc.json>` is an internal/advanced
539
- input; the consumer surface is `--from`.
434
+ [`docs/cli-reference.md`](./docs/cli-reference.md)). `--in <ir-doc.json>` is an
435
+ internal/advanced input; the consumer surface is `--from`.
540
436
 
541
437
  ## 3. Call the generated entry point
542
438
 
@@ -555,11 +451,11 @@ let rows = run_native_raw_struct_findByEmail(InNRFindByEmail { email: "a@b.c".to
555
451
  ```
556
452
 
557
453
  A `--lang python` / `--lang php` module runs on the shared runtime with the IR embedded. A
558
- `--lang typescript` interpreter module (an alternative to `lowerBehaviors` when you want an emitted
559
- file) embeds the compiled IR as a `ComponentGraphIRDoc` literal and adopts it at load with
560
- `loadCompiledIR`, then `runBehavior` walks it.
454
+ `--lang typescript` interpreter module (an alternative to calling the declaration directly, when you
455
+ want an emitted file) embeds the compiled IR and walks it at run time — it wires itself up, so
456
+ there is nothing to import by hand.
561
457
 
562
- The complete, runnable end-user example — one model, with the TypeScript `lowerBehaviors` run and the
458
+ The complete, runnable end-user example — one model, with the direct TypeScript run and the
563
459
  Go / Rust `bc generate` runs all printing the same row — is
564
460
  [`examples/using-a-bc-library/`](../examples/using-a-bc-library/).
565
461
 
@@ -567,10 +463,10 @@ Go / Rust `bc generate` runs all printing the same row — is
567
463
 
568
464
  ## Documentation
569
465
 
570
- Deeper design and specification documents live alongside the package in the repository:
466
+ Deeper design and specification documents live alongside the package:
571
467
 
572
- - [`docs/cli-reference.md`](./docs/cli-reference.md) — the full `bc generate` / `bc check`
573
- option reference.
468
+ - [`docs/cli-reference.md`](./docs/cli-reference.md) — the full `bc generate` /
469
+ `bc check` option reference.
574
470
  - [`docs/strict-typing-and-debox.md`](../docs/strict-typing-and-debox.md) — mandatory typing,
575
471
  the strict de-box, the BC-owned wire type, and the leaf transport (the full contract for the
576
472
  above).