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.
- package/README.md +246 -350
- package/cli-contract.yaml +49 -51
- package/dist/authoring.d.ts +80 -420
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +53 -1157
- package/dist/authoring.js.map +1 -1
- package/dist/behavior.d.ts +31 -15
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +55 -0
- package/dist/behavior.js.map +1 -1
- package/dist/builder.d.ts +4 -4
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +18 -16
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +12 -56
- package/dist/commands/codegen.js.map +1 -1
- package/dist/commands/ts-compile.d.ts +23 -0
- package/dist/commands/ts-compile.d.ts.map +1 -0
- package/dist/commands/ts-compile.js +693 -0
- package/dist/commands/ts-compile.js.map +1 -0
- package/dist/commands/ts-extract.d.ts +55 -7
- package/dist/commands/ts-extract.d.ts.map +1 -1
- package/dist/commands/ts-extract.js +177 -64
- package/dist/commands/ts-extract.js.map +1 -1
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +2 -2
- package/dist/generated/contract.js.map +1 -1
- package/dist/generated/program.js +4 -4
- package/dist/generated/program.js.map +1 -1
- package/dist/generator/core.d.ts +11 -1
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +5 -4
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-php.d.ts +0 -17
- package/dist/generator/emit-php.d.ts.map +1 -1
- package/dist/generator/emit-php.js +25 -1
- package/dist/generator/emit-php.js.map +1 -1
- package/dist/generator/emit-python.d.ts +0 -7
- package/dist/generator/emit-python.d.ts.map +1 -1
- package/dist/generator/emit-python.js +34 -1
- package/dist/generator/emit-python.js.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +122 -112
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +3 -2
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +61 -125
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/emit-typescript-native.js +1 -1
- package/dist/generator/emit-typescript-native.js.map +1 -1
- package/dist/generator/emit-typescript.js +1 -1
- package/dist/generator/emit-typescript.js.map +1 -1
- package/dist/generator/typed.d.ts +5 -1
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +40 -9
- package/dist/generator/typed.js.map +1 -1
- package/dist/guard.d.ts +11 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +35 -8
- package/dist/guard.js.map +1 -1
- package/dist/index.d.ts +20 -57
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -101
- package/dist/index.js.map +1 -1
- package/dist/lowering.d.ts +251 -0
- package/dist/lowering.d.ts.map +1 -0
- package/dist/lowering.js +682 -0
- package/dist/lowering.js.map +1 -0
- package/dist/provenance.js +4 -4
- package/dist/provenance.js.map +1 -1
- package/dist/runtime.d.ts +52 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +77 -0
- package/dist/runtime.js.map +1 -0
- package/dist/spec-versions.d.ts +25 -0
- package/dist/spec-versions.d.ts.map +1 -0
- package/dist/spec-versions.js +26 -0
- package/dist/spec-versions.js.map +1 -0
- package/dist/type-gate.d.ts +12 -0
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +79 -3
- package/dist/type-gate.js.map +1 -1
- package/package.json +5 -1
- package/dist/bind.d.ts +0 -88
- package/dist/bind.d.ts.map +0 -1
- package/dist/bind.js +0 -155
- package/dist/bind.js.map +0 -1
- package/dist/lower.d.ts +0 -35
- package/dist/lower.d.ts.map +0 -1
- package/dist/lower.js +0 -118
- package/dist/lower.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,63 +1,87 @@
|
|
|
1
1
|
# behavior-contracts
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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["
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ML["
|
|
27
|
-
LEAF["leaf
|
|
28
|
-
|
|
29
|
-
TS
|
|
30
|
-
|
|
31
|
-
IR
|
|
32
|
-
LEAF -.
|
|
33
|
-
LEAF -.
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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
|
|
49
|
-
|
|
50
|
-
per-language leaf transports** (Go / Rust / …). This is the audience that writes
|
|
51
|
-
`
|
|
52
|
-
|
|
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
|
|
56
|
-
**TypeScript**
|
|
57
|
-
|
|
58
|
-
run directly) linked to the library's shipped leaf transports, then a call to the
|
|
59
|
-
entry point. They write **no
|
|
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
|
|
81
|
-
- **
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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,
|
|
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**
|
|
92
|
-
|
|
93
|
-
|
|
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`
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
your users only declare a model and run it (Section B).
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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)
|
|
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("
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
244
|
-
**codegen** is CLI-only
|
|
245
|
-
|
|
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
|
-
| `
|
|
258
|
-
| `
|
|
259
|
-
| `
|
|
260
|
-
| `
|
|
261
|
-
| `
|
|
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
|
|
483
|
-
|
|
484
|
-
|
|
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.
|
|
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.
|
|
490
|
-
|
|
491
|
-
|
|
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 —
|
|
390
|
+
## 2a. Run it in TypeScript — just call it
|
|
494
391
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
|
504
|
-
|
|
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
|
-
|
|
509
|
-
|
|
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>`
|
|
515
|
-
type-
|
|
516
|
-
native (Go / Rust) or a shared-runtime
|
|
517
|
-
|
|
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
|
|
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
|
|
559
|
-
file) embeds the compiled IR
|
|
560
|
-
|
|
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
|
|
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
|
|
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` /
|
|
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).
|