behavior-contracts 0.8.11 → 0.8.13
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 +22 -16
- package/cli-contract.yaml +46 -44
- package/dist/behavior.d.ts +10 -1
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +5 -0
- package/dist/behavior.js.map +1 -1
- package/dist/cli.js +16 -14
- package/dist/cli.js.map +1 -1
- package/dist/commands/codegen.d.ts +4 -3
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +8 -5
- package/dist/commands/codegen.js.map +1 -1
- package/dist/generated/commands.d.ts.map +1 -1
- package/dist/generated/commands.js +12 -16
- package/dist/generated/commands.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.d.ts +6 -8
- package/dist/generated/program.d.ts.map +1 -1
- package/dist/generated/program.js +6 -8
- package/dist/generated/program.js.map +1 -1
- package/dist/generated/types.d.ts +6 -8
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generator/core.d.ts +9 -24
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +1 -1
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-shared-debox.d.ts.map +1 -1
- package/dist/generator/emit-shared-debox.js +2 -0
- package/dist/generator/emit-shared-debox.js.map +1 -1
- package/dist/generator/emit-shared-go-typed.d.ts +2 -0
- package/dist/generator/emit-shared-go-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-go-typed.js +31 -0
- package/dist/generator/emit-shared-go-typed.js.map +1 -1
- package/dist/generator/emit-shared-rust-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-rust-typed.js +13 -0
- package/dist/generator/emit-shared-rust-typed.js.map +1 -1
- package/dist/generator/emit-shared-typescript-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript-typed.js +4 -0
- package/dist/generator/emit-shared-typescript-typed.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +10 -0
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +360 -204
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +217 -224
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/typed.d.ts +9 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +37 -0
- package/dist/generator/typed.js.map +1 -1
- package/dist/guard.d.ts +7 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +9 -2
- package/dist/guard.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { GeneratorFailure } from "./core.js";
|
|
|
2
2
|
import { isControlGate } from "../behavior.js";
|
|
3
3
|
import { rustStraightlineInternals } from "./emit-shared-rust.js";
|
|
4
4
|
import { rustTypedInternals } from "./emit-shared-rust-typed.js";
|
|
5
|
-
import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
|
|
5
|
+
import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef, typeRefContainsValue } from "./typed.js";
|
|
6
6
|
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr } from "./straightline.js";
|
|
7
7
|
import { NativeExprCompiler } from "./native-expr.js";
|
|
8
8
|
import { buildAsyncPlans } from "./async-plan.js";
|
|
@@ -214,14 +214,22 @@ function inStructName(compName) {
|
|
|
214
214
|
// required/optional, present/absent, error assembly, fail-closed. The seam stays native: Probe/NumProbe
|
|
215
215
|
// are concrete enums and WireRow/WireList are monomorphized via mutual associated types (Row/List), so no
|
|
216
216
|
// boxed Value / dyn / Box crosses the boundary.
|
|
217
|
-
/** emitRustProbeWireTypes — the once-per-module probe enums +
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
|
|
217
|
+
/** emitRustProbeWireTypes — the once-per-module probe enums + the BC-OWNED concrete wire types + their
|
|
218
|
+
* classification. bc GENERATES the whole seam: `WireValue` is a self-contained (runtime-free) generic
|
|
219
|
+
* result the consumer's SINGLE op-agnostic transport builds and returns; the consumer implements NOTHING
|
|
220
|
+
* over it (no trait, no probe protocol). The generated inline de-box reads it via these inherent methods —
|
|
221
|
+
* static typed extraction lowers the generic result to the covered plane's typed values immediately, so no
|
|
222
|
+
* dynamic value crosses the covered/hot plane (bc#87). Numbers ride as raw text so BC owns overflow. */
|
|
223
|
+
function emitRustProbeWireTypes(clone) {
|
|
224
|
+
// bc#156: WireValue is a port field (Vec<WireValue>) when a `value` input port exists — the ports struct
|
|
225
|
+
// derives Clone (bc#87 parallel dispatch) and the port init clones the input, so WireValue/WireRow/WireList
|
|
226
|
+
// must be Clone THEN. A value-free module never clones the wire (return-only), so the derive is omitted to
|
|
227
|
+
// keep those generated modules byte-identical to pre-#156.
|
|
228
|
+
const cloneDerive = clone ? "#[derive(Clone)]\n" : "";
|
|
221
229
|
return `// Probe<T> / NumProbe — the outcome of classifying one wire attribute against a declared type. Got carries
|
|
222
230
|
// the matched value (a NumProbe's raw numeric text, which the de-box parses + range-checks so overflow is
|
|
223
|
-
// BC's to detect); actual_wire_type is the producer's own wire tag (
|
|
224
|
-
//
|
|
231
|
+
// BC's to detect); actual_wire_type is the producer's own wire tag (S/N/BOOL/M/L/NULL); raw_value is the
|
|
232
|
+
// offending value stringified. Concrete enums — no boxed runtime value.
|
|
225
233
|
pub enum Probe<T> {
|
|
226
234
|
Got(T),
|
|
227
235
|
Wrong { actual_wire_type: String, raw_value: String },
|
|
@@ -236,46 +244,166 @@ pub enum NumProbe {
|
|
|
236
244
|
Absent,
|
|
237
245
|
}
|
|
238
246
|
|
|
239
|
-
// WireValue —
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
pub
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
// WireValue — the BC-OWNED, BC-GENERATED, self-contained (runtime-free) generic result the consumer's
|
|
248
|
+
// single op-agnostic transport returns. The consumer BUILDS it as it reads the producer (the raw I/O act)
|
|
249
|
+
// — WireValue::Str/Num/Bool/Null/Row/List, or the int()/float() constructors — and implements NOTHING over
|
|
250
|
+
// it. Numbers carry raw text (BC parses + range-checks → overflow is BC's to detect). A composite is a
|
|
251
|
+
// nested WireRow / WireList. NO trait, NO consumer classification protocol.
|
|
252
|
+
${cloneDerive}pub enum WireValue {
|
|
253
|
+
Str(String),
|
|
254
|
+
Num(String),
|
|
255
|
+
Bool(bool),
|
|
256
|
+
Null,
|
|
257
|
+
Row(WireRow),
|
|
258
|
+
List(WireList),
|
|
251
259
|
}
|
|
252
260
|
|
|
253
|
-
// WireRow / WireList —
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
pub
|
|
258
|
-
|
|
259
|
-
// the attribute keys present (the entries of a wire map / DynamoDB "M") — iterated to decode a map(V).
|
|
260
|
-
fn keys(&self) -> Vec<String>;
|
|
261
|
-
fn probe_string(&self, field: &str) -> Probe<String>;
|
|
262
|
-
fn probe_number(&self, field: &str) -> NumProbe;
|
|
263
|
-
fn probe_bool(&self, field: &str) -> Probe<bool>;
|
|
264
|
-
fn probe_row(&self, field: &str) -> Probe<Self>;
|
|
265
|
-
fn probe_list(&self, field: &str) -> Probe<Self::List>;
|
|
261
|
+
// WireRow / WireList — a wire map (a DynamoDB "M") / wire array (an "L"). Native Vec-backed; the generated
|
|
262
|
+
// de-box probes them by declared field / element and owns strictness (required/optional, present/absent,
|
|
263
|
+
// error assembly). row/list probes return a BORROW (Probe<&WireRow>/Probe<&WireList>) so nested decode is
|
|
264
|
+
// zero-copy — only leaf scalars are cloned into the covered typed struct.
|
|
265
|
+
${cloneDerive}pub struct WireRow {
|
|
266
|
+
pub entries: Vec<(String, WireValue)>,
|
|
266
267
|
}
|
|
267
268
|
|
|
268
|
-
pub
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
fn
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
fn
|
|
278
|
-
|
|
269
|
+
${cloneDerive}pub struct WireList {
|
|
270
|
+
pub items: Vec<WireValue>,
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
impl WireValue {
|
|
274
|
+
// constructors the consumer's transport uses to build numeric results (numbers ride as raw text).
|
|
275
|
+
pub fn int(n: i64) -> Self {
|
|
276
|
+
WireValue::Num(n.to_string())
|
|
277
|
+
}
|
|
278
|
+
pub fn float(n: f64) -> Self {
|
|
279
|
+
WireValue::Num(n.to_string())
|
|
280
|
+
}
|
|
281
|
+
// the top result is always present (Some(self)); the field/elem probes share the same classifiers.
|
|
282
|
+
pub fn as_string(&self) -> Probe<String> {
|
|
283
|
+
probe_string_at(Some(self))
|
|
284
|
+
}
|
|
285
|
+
pub fn as_number(&self) -> NumProbe {
|
|
286
|
+
probe_number_at(Some(self))
|
|
287
|
+
}
|
|
288
|
+
pub fn as_bool(&self) -> Probe<bool> {
|
|
289
|
+
probe_bool_at(Some(self))
|
|
290
|
+
}
|
|
291
|
+
pub fn as_row(&self) -> Probe<&WireRow> {
|
|
292
|
+
probe_row_at(Some(self))
|
|
293
|
+
}
|
|
294
|
+
pub fn as_list(&self) -> Probe<&WireList> {
|
|
295
|
+
probe_list_at(Some(self))
|
|
296
|
+
}
|
|
297
|
+
fn tag(&self) -> &'static str {
|
|
298
|
+
match self {
|
|
299
|
+
WireValue::Str(_) => "S",
|
|
300
|
+
WireValue::Num(_) => "N",
|
|
301
|
+
WireValue::Bool(_) => "BOOL",
|
|
302
|
+
WireValue::Null => "NULL",
|
|
303
|
+
WireValue::Row(_) => "M",
|
|
304
|
+
WireValue::List(_) => "L",
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
fn raw(&self) -> String {
|
|
308
|
+
match self {
|
|
309
|
+
WireValue::Str(s) => s.clone(),
|
|
310
|
+
WireValue::Num(s) => s.clone(),
|
|
311
|
+
WireValue::Bool(b) => b.to_string(),
|
|
312
|
+
WireValue::Null => "null".to_string(),
|
|
313
|
+
WireValue::Row(_) | WireValue::List(_) => "[composite]".to_string(),
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
impl WireRow {
|
|
319
|
+
fn get(&self, field: &str) -> Option<&WireValue> {
|
|
320
|
+
self.entries.iter().find(|(k, _)| k.as_str() == field).map(|(_, v)| v)
|
|
321
|
+
}
|
|
322
|
+
pub fn keys(&self) -> Vec<String> {
|
|
323
|
+
self.entries.iter().map(|(k, _)| k.clone()).collect()
|
|
324
|
+
}
|
|
325
|
+
pub fn probe_string(&self, field: &str) -> Probe<String> {
|
|
326
|
+
probe_string_at(self.get(field))
|
|
327
|
+
}
|
|
328
|
+
pub fn probe_number(&self, field: &str) -> NumProbe {
|
|
329
|
+
probe_number_at(self.get(field))
|
|
330
|
+
}
|
|
331
|
+
pub fn probe_bool(&self, field: &str) -> Probe<bool> {
|
|
332
|
+
probe_bool_at(self.get(field))
|
|
333
|
+
}
|
|
334
|
+
pub fn probe_row(&self, field: &str) -> Probe<&WireRow> {
|
|
335
|
+
probe_row_at(self.get(field))
|
|
336
|
+
}
|
|
337
|
+
pub fn probe_list(&self, field: &str) -> Probe<&WireList> {
|
|
338
|
+
probe_list_at(self.get(field))
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
impl WireList {
|
|
343
|
+
pub fn len(&self) -> usize {
|
|
344
|
+
self.items.len()
|
|
345
|
+
}
|
|
346
|
+
pub fn is_empty(&self) -> bool {
|
|
347
|
+
self.items.is_empty()
|
|
348
|
+
}
|
|
349
|
+
pub fn elem_string(&self, i: usize) -> Probe<String> {
|
|
350
|
+
probe_string_at(self.items.get(i))
|
|
351
|
+
}
|
|
352
|
+
pub fn elem_number(&self, i: usize) -> NumProbe {
|
|
353
|
+
probe_number_at(self.items.get(i))
|
|
354
|
+
}
|
|
355
|
+
pub fn elem_bool(&self, i: usize) -> Probe<bool> {
|
|
356
|
+
probe_bool_at(self.items.get(i))
|
|
357
|
+
}
|
|
358
|
+
pub fn elem_row(&self, i: usize) -> Probe<&WireRow> {
|
|
359
|
+
probe_row_at(self.items.get(i))
|
|
360
|
+
}
|
|
361
|
+
pub fn elem_list(&self, i: usize) -> Probe<&WireList> {
|
|
362
|
+
probe_list_at(self.items.get(i))
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// the ONE classifier per kind, over an Option<&WireValue> (None = absent attribute/element). The BC-owned
|
|
367
|
+
// WireValue variant IS the wire tag — no consumer classification.
|
|
368
|
+
fn probe_string_at(v: Option<&WireValue>) -> Probe<String> {
|
|
369
|
+
match v {
|
|
370
|
+
None => Probe::Absent,
|
|
371
|
+
Some(WireValue::Str(s)) => Probe::Got(s.clone()),
|
|
372
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
373
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
fn probe_number_at(v: Option<&WireValue>) -> NumProbe {
|
|
377
|
+
match v {
|
|
378
|
+
None => NumProbe::Absent,
|
|
379
|
+
Some(WireValue::Num(s)) => NumProbe::Got { raw: s.clone(), actual_wire_type: "N".to_string() },
|
|
380
|
+
Some(WireValue::Null) => NumProbe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
381
|
+
Some(o) => NumProbe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
fn probe_bool_at(v: Option<&WireValue>) -> Probe<bool> {
|
|
385
|
+
match v {
|
|
386
|
+
None => Probe::Absent,
|
|
387
|
+
Some(WireValue::Bool(b)) => Probe::Got(*b),
|
|
388
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
389
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
fn probe_row_at(v: Option<&WireValue>) -> Probe<&WireRow> {
|
|
393
|
+
match v {
|
|
394
|
+
None => Probe::Absent,
|
|
395
|
+
Some(WireValue::Row(r)) => Probe::Got(r),
|
|
396
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
397
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
fn probe_list_at(v: Option<&WireValue>) -> Probe<&WireList> {
|
|
401
|
+
match v {
|
|
402
|
+
None => Probe::Absent,
|
|
403
|
+
Some(WireValue::List(l)) => Probe::Got(l),
|
|
404
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
405
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
406
|
+
}
|
|
279
407
|
}`;
|
|
280
408
|
}
|
|
281
409
|
/**
|
|
@@ -2166,6 +2294,13 @@ ${emitStructSurface([])}
|
|
|
2166
2294
|
// every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
|
|
2167
2295
|
// WireValue/WireRow/WireList traits) is emitted once whenever any handler node exists.
|
|
2168
2296
|
const anyWire = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
2297
|
+
// bc#156: WireValue becomes a port field (Vec<WireValue>) iff some input port carries a `value` — then the
|
|
2298
|
+
// Clone-deriving ports struct + the cloning port init require the wire types to be Clone (see
|
|
2299
|
+
// emitRustProbeWireTypes). SSoT detection via the inputPortTypeRef → typeRefContainsValue walk.
|
|
2300
|
+
const hasValuePort = native.some((c) => Object.values(c.inputPorts ?? {}).some((s) => {
|
|
2301
|
+
const r = inputPortTypeRef(s, plan);
|
|
2302
|
+
return r !== undefined && typeRefContainsValue(r, plan);
|
|
2303
|
+
}));
|
|
2169
2304
|
for (const c of native) {
|
|
2170
2305
|
const typedNodes = new Map();
|
|
2171
2306
|
// build the full typed-node map FIRST so a map's over-element resolution can see every node.
|
|
@@ -2241,7 +2376,7 @@ use std::cell::RefCell;`;
|
|
|
2241
2376
|
: undefined,
|
|
2242
2377
|
`// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
|
|
2243
2378
|
anyWire
|
|
2244
|
-
? `// strict de-box wire seam — the
|
|
2379
|
+
? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList): the\n// consumer's single transport builds + returns it, implements NOTHING over it. The generated INLINE de-box\n// classifies it against the STATICALLY declared type and owns strictness (required/optional, present/absent,\n// error assembly, fail-closed). Self-contained concrete types — no trait, no boxed runtime value.\n${emitRustProbeWireTypes(hasValuePort)}`
|
|
2245
2380
|
: undefined,
|
|
2246
2381
|
elemMaterializers.length
|
|
2247
2382
|
? `// map augmented-element copiers (pure struct field assignment — no dynamic value read).\n${elemMaterializers.join("\n\n")}`
|
|
@@ -2278,174 +2413,25 @@ export function rustTypedNativeObserve(ir, ioModel = "sync", leaf) {
|
|
|
2278
2413
|
// every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
|
|
2279
2414
|
// needed whenever any component has a handler node.
|
|
2280
2415
|
const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
2281
|
-
//
|
|
2282
|
-
//
|
|
2283
|
-
//
|
|
2284
|
-
//
|
|
2285
|
-
//
|
|
2416
|
+
// value_to_wire (TEST glue): builds the covered module's BC-OWNED concrete `WireValue` from a scripted bc
|
|
2417
|
+
// `Value` — the test-harness analog of the consumer's real transport (which builds `WireValue` as it reads
|
|
2418
|
+
// the producer). Numbers ride as raw text (WireValue::Num), matching how the de-box parses + range-checks;
|
|
2419
|
+
// the wire tags + classification live ONCE in the covered module's WireValue (probe_*_at), so this only
|
|
2420
|
+
// CONSTRUCTS — a scripted wrong-variant value maps to the corresponding WireValue variant and the covered
|
|
2421
|
+
// de-box classifies it (TYPE_MISMATCH ≡ run_behavior), no separate scripted classifier.
|
|
2286
2422
|
const wireAdapter = anyDeBox
|
|
2287
|
-
? `// ──
|
|
2288
|
-
fn
|
|
2423
|
+
? `// ── value_to_wire (TEST glue): scripted bc Value -> the covered module's BC-owned WireValue ──
|
|
2424
|
+
fn value_to_wire(v: &Value) -> WireValue {
|
|
2289
2425
|
match v {
|
|
2290
|
-
Value::Null =>
|
|
2291
|
-
Value::Bool(
|
|
2292
|
-
Value::Int(
|
|
2293
|
-
Value::
|
|
2294
|
-
Value::
|
|
2295
|
-
Value::
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
fn scripted_wire_raw(v: &Value) -> String {
|
|
2301
|
-
match v {
|
|
2302
|
-
Value::Null => "null".to_string(),
|
|
2303
|
-
Value::Bool(b) => b.to_string(),
|
|
2304
|
-
Value::Int(n) => n.to_string(),
|
|
2305
|
-
Value::Float(f) => f.to_string(),
|
|
2306
|
-
Value::Str(s) => s.clone(),
|
|
2307
|
-
Value::Arr(_) | Value::Obj(_) => "[composite]".to_string(),
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
fn probe_string_val(v: Option<&Value>) -> Probe<String> {
|
|
2312
|
-
match v {
|
|
2313
|
-
None => Probe::Absent,
|
|
2314
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2315
|
-
Some(Value::Str(s)) => Probe::Got(s.clone()),
|
|
2316
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
fn probe_number_val(v: Option<&Value>) -> NumProbe {
|
|
2321
|
-
match v {
|
|
2322
|
-
None => NumProbe::Absent,
|
|
2323
|
-
Some(Value::Null) => NumProbe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2324
|
-
Some(Value::Int(n)) => NumProbe::Got { raw: n.to_string(), actual_wire_type: "N".to_string() },
|
|
2325
|
-
Some(Value::Float(f)) => NumProbe::Got { raw: f.to_string(), actual_wire_type: "N".to_string() },
|
|
2326
|
-
Some(other) => NumProbe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
fn probe_bool_val(v: Option<&Value>) -> Probe<bool> {
|
|
2331
|
-
match v {
|
|
2332
|
-
None => Probe::Absent,
|
|
2333
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2334
|
-
Some(Value::Bool(b)) => Probe::Got(*b),
|
|
2335
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
fn probe_row_val(v: Option<&Value>) -> Probe<ScriptedWireRow> {
|
|
2340
|
-
match v {
|
|
2341
|
-
None => Probe::Absent,
|
|
2342
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2343
|
-
Some(Value::Obj(pairs)) => Probe::Got(ScriptedWireRow { obj: pairs.clone() }),
|
|
2344
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
|
|
2348
|
-
fn probe_list_val(v: Option<&Value>) -> Probe<ScriptedWireList> {
|
|
2349
|
-
match v {
|
|
2350
|
-
None => Probe::Absent,
|
|
2351
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2352
|
-
Some(Value::Arr(items)) => Probe::Got(ScriptedWireList { items: items.clone() }),
|
|
2353
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2354
|
-
}
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
pub struct ScriptedWireRow {
|
|
2358
|
-
obj: Vec<(String, Value)>,
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
impl ScriptedWireRow {
|
|
2362
|
-
pub fn new(v: Value) -> Self {
|
|
2363
|
-
match v {
|
|
2364
|
-
Value::Obj(pairs) => ScriptedWireRow { obj: pairs },
|
|
2365
|
-
_ => ScriptedWireRow { obj: Vec::new() },
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
fn get(&self, field: &str) -> Option<&Value> {
|
|
2369
|
-
self.obj.iter().find(|(k, _)| k.as_str() == field).map(|(_, v)| v)
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
pub struct ScriptedWireList {
|
|
2374
|
-
items: Vec<Value>,
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
// ScriptedWireValue — a scripted node result wrapped as the uniform WireValue: a top value is always
|
|
2378
|
-
// present (Some), so as_* never observes Absent; a scripted null is Value::Null → Probe::Null.
|
|
2379
|
-
pub struct ScriptedWireValue {
|
|
2380
|
-
v: Value,
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
impl ScriptedWireValue {
|
|
2384
|
-
pub fn new(v: Value) -> Self {
|
|
2385
|
-
ScriptedWireValue { v }
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
impl WireValue for ScriptedWireValue {
|
|
2390
|
-
type Row = ScriptedWireRow;
|
|
2391
|
-
fn as_string(&self) -> Probe<String> {
|
|
2392
|
-
probe_string_val(Some(&self.v))
|
|
2393
|
-
}
|
|
2394
|
-
fn as_number(&self) -> NumProbe {
|
|
2395
|
-
probe_number_val(Some(&self.v))
|
|
2396
|
-
}
|
|
2397
|
-
fn as_bool(&self) -> Probe<bool> {
|
|
2398
|
-
probe_bool_val(Some(&self.v))
|
|
2399
|
-
}
|
|
2400
|
-
fn as_row(&self) -> Probe<ScriptedWireRow> {
|
|
2401
|
-
probe_row_val(Some(&self.v))
|
|
2402
|
-
}
|
|
2403
|
-
fn as_list(&self) -> Probe<ScriptedWireList> {
|
|
2404
|
-
probe_list_val(Some(&self.v))
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
impl WireRow for ScriptedWireRow {
|
|
2409
|
-
type List = ScriptedWireList;
|
|
2410
|
-
fn keys(&self) -> Vec<String> {
|
|
2411
|
-
self.obj.iter().map(|(k, _)| k.clone()).collect()
|
|
2412
|
-
}
|
|
2413
|
-
fn probe_string(&self, field: &str) -> Probe<String> {
|
|
2414
|
-
probe_string_val(self.get(field))
|
|
2415
|
-
}
|
|
2416
|
-
fn probe_number(&self, field: &str) -> NumProbe {
|
|
2417
|
-
probe_number_val(self.get(field))
|
|
2418
|
-
}
|
|
2419
|
-
fn probe_bool(&self, field: &str) -> Probe<bool> {
|
|
2420
|
-
probe_bool_val(self.get(field))
|
|
2421
|
-
}
|
|
2422
|
-
fn probe_row(&self, field: &str) -> Probe<Self> {
|
|
2423
|
-
probe_row_val(self.get(field))
|
|
2424
|
-
}
|
|
2425
|
-
fn probe_list(&self, field: &str) -> Probe<Self::List> {
|
|
2426
|
-
probe_list_val(self.get(field))
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
|
|
2430
|
-
impl WireList for ScriptedWireList {
|
|
2431
|
-
type Row = ScriptedWireRow;
|
|
2432
|
-
fn len(&self) -> usize {
|
|
2433
|
-
self.items.len()
|
|
2434
|
-
}
|
|
2435
|
-
fn elem_string(&self, i: usize) -> Probe<String> {
|
|
2436
|
-
probe_string_val(self.items.get(i))
|
|
2437
|
-
}
|
|
2438
|
-
fn elem_number(&self, i: usize) -> NumProbe {
|
|
2439
|
-
probe_number_val(self.items.get(i))
|
|
2440
|
-
}
|
|
2441
|
-
fn elem_bool(&self, i: usize) -> Probe<bool> {
|
|
2442
|
-
probe_bool_val(self.items.get(i))
|
|
2443
|
-
}
|
|
2444
|
-
fn elem_row(&self, i: usize) -> Probe<Self::Row> {
|
|
2445
|
-
probe_row_val(self.items.get(i))
|
|
2446
|
-
}
|
|
2447
|
-
fn elem_list(&self, i: usize) -> Probe<Self> {
|
|
2448
|
-
probe_list_val(self.items.get(i))
|
|
2426
|
+
Value::Null => WireValue::Null,
|
|
2427
|
+
Value::Bool(b) => WireValue::Bool(*b),
|
|
2428
|
+
Value::Int(n) => WireValue::Num(n.to_string()),
|
|
2429
|
+
Value::Float(f) => WireValue::Num(f.to_string()),
|
|
2430
|
+
Value::Str(s) => WireValue::Str(s.clone()),
|
|
2431
|
+
Value::Arr(items) => WireValue::List(WireList { items: items.iter().map(value_to_wire).collect() }),
|
|
2432
|
+
Value::Obj(pairs) => WireValue::Row(WireRow {
|
|
2433
|
+
entries: pairs.iter().map(|(k, vv)| (k.clone(), value_to_wire(vv))).collect(),
|
|
2434
|
+
}),
|
|
2449
2435
|
}
|
|
2450
2436
|
}`
|
|
2451
2437
|
: "";
|
|
@@ -2476,17 +2462,17 @@ impl WireList for ScriptedWireList {
|
|
|
2476
2462
|
// async iff this catalog leaf's terminal handler is async (consistent per catalog component).
|
|
2477
2463
|
const fnKw = ap.nodeIsAsync(n.id) ? "pub async fn" : "pub fn";
|
|
2478
2464
|
if ("fanout" in n) {
|
|
2479
|
-
// fanout: return the aligned per-id element WIRES (Vec<Option<
|
|
2465
|
+
// fanout: return the aligned per-id element WIRES (Vec<Option<WireValue>>); a null aligned
|
|
2480
2466
|
// body is a DANGLING id → None (the covered runner maps it to the zero element).
|
|
2481
2467
|
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2482
|
-
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<Option<
|
|
2468
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<Option<WireValue>>, BehaviorError> {
|
|
2483
2469
|
${drainStmt(catalog, "_echo")}
|
|
2484
2470
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2485
2471
|
let wires = arr
|
|
2486
2472
|
.into_iter()
|
|
2487
2473
|
.map(|ev| match ev {
|
|
2488
2474
|
Value::Null => None,
|
|
2489
|
-
_ => Some(
|
|
2475
|
+
_ => Some(value_to_wire(&ev)),
|
|
2490
2476
|
})
|
|
2491
2477
|
.collect();
|
|
2492
2478
|
Ok(wires)
|
|
@@ -2494,23 +2480,23 @@ impl WireList for ScriptedWireList {
|
|
|
2494
2480
|
continue;
|
|
2495
2481
|
}
|
|
2496
2482
|
if ("map" in n) {
|
|
2497
|
-
// map: batched → one WIRE per element (Vec<
|
|
2483
|
+
// map: batched → one WIRE per element (Vec<WireValue>); non-batched → one element WIRE.
|
|
2498
2484
|
const m = n.map;
|
|
2499
2485
|
if (m.batched === true) {
|
|
2500
2486
|
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2501
|
-
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<
|
|
2487
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<WireValue>, BehaviorError> {
|
|
2502
2488
|
${drainStmt(catalog, "_echo")}
|
|
2503
2489
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2504
|
-
let wires = arr.
|
|
2490
|
+
let wires = arr.iter().map(value_to_wire).collect();
|
|
2505
2491
|
Ok(wires)
|
|
2506
2492
|
}`);
|
|
2507
2493
|
}
|
|
2508
2494
|
else {
|
|
2509
2495
|
const { elemRef: overElemRef } = mapOverElemInfo(c, n, typedNodes, plan);
|
|
2510
2496
|
const params = spreadParams(portFieldSpread(m.ports, c, plan, typedNodes, { name: m.as, ref: overElemRef, plan }));
|
|
2511
|
-
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<
|
|
2497
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2512
2498
|
${drainStmt(catalog, "_echo")}
|
|
2513
|
-
Ok(
|
|
2499
|
+
Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2514
2500
|
}`);
|
|
2515
2501
|
}
|
|
2516
2502
|
continue;
|
|
@@ -2535,12 +2521,12 @@ impl WireList for ScriptedWireList {
|
|
|
2535
2521
|
if (portRust === recordRust) {
|
|
2536
2522
|
// the port IS the whole record → echo it DIRECTLY (matching run_behavior's plain echo:port).
|
|
2537
2523
|
const own = typeRefIsCopy(ref) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2538
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2524
|
+
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(value_to_wire(&${serializeTyped("tv", ref, plan)}));\n }`);
|
|
2539
2525
|
}
|
|
2540
2526
|
else if (fieldRust !== null && field !== undefined && portRust === fieldRust) {
|
|
2541
2527
|
// a scalar port wraps into the record's single field ({v: ports.X}).
|
|
2542
2528
|
const own = typeRefIsCopy(field.type) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2543
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2529
|
+
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(value_to_wire(&Value::Obj(vec![(${rustStrLit(field.name)}.to_string(), ${serializeTyped("tv", field.type, plan)})])));\n }`);
|
|
2544
2530
|
}
|
|
2545
2531
|
}
|
|
2546
2532
|
}
|
|
@@ -2548,14 +2534,14 @@ impl WireList for ScriptedWireList {
|
|
|
2548
2534
|
// #129: an arr node with an `items` port echoes the NATIVE port array (serialized element-by-element
|
|
2549
2535
|
// into a Value::Arr) so the node→leaf array dataflow test is non-vacuous.
|
|
2550
2536
|
const elemRef = ref.elem;
|
|
2551
|
-
echoBranches.push(` if echo == "items" {\n let tv = Value::Arr(${portFieldName("items")}.iter().map(|e| { let ev = e.clone(); ${serializeTyped("ev", elemRef, plan)} }).collect());\n return Ok(
|
|
2537
|
+
echoBranches.push(` if echo == "items" {\n let tv = Value::Arr(${portFieldName("items")}.iter().map(|e| { let ev = e.clone(); ${serializeTyped("ev", elemRef, plan)} }).collect());\n return Ok(value_to_wire(&tv));\n }`);
|
|
2552
2538
|
}
|
|
2553
2539
|
const canEcho = echoBranches.length > 0;
|
|
2554
2540
|
const params = spreadParams(portFieldSpread(node.ports, c, plan, typedNodes));
|
|
2555
2541
|
const echoBlock = canEcho ? `${echoBranches.join("\n")}\n` : "";
|
|
2556
|
-
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<
|
|
2542
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2557
2543
|
${drainStmt(catalog, canEcho ? "echo" : "_echo")}
|
|
2558
|
-
${echoBlock} Ok(
|
|
2544
|
+
${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2559
2545
|
}`);
|
|
2560
2546
|
}
|
|
2561
2547
|
}
|
|
@@ -2757,9 +2743,12 @@ function emitInDecoder(comp, plan) {
|
|
|
2757
2743
|
lines.push(`${head} k == ${rustStrLit(p)} {`);
|
|
2758
2744
|
if ((schema?.type === "array" || schema?.type === "arr") && et !== undefined) {
|
|
2759
2745
|
// #108: decode the boxed Value::Arr into the native Vec<ElemT> (test glue — materialize each elem).
|
|
2746
|
+
// bc#156: a `value[]` element is BC's opaque wire — decode it with the BC-owned value_to_wire
|
|
2747
|
+
// constructor (the SAME wire the output de-box uses), NOT the typed materializer (WireValue is not a
|
|
2748
|
+
// de-box target). This is the generic bound-value list built from a heterogeneous / empty input array.
|
|
2760
2749
|
const elemRef = deriveTypeRef(et, plan);
|
|
2761
2750
|
const elemTy = renderTypeRef(elemRef);
|
|
2762
|
-
const mat = materializeExpr("ev", elemRef, plan);
|
|
2751
|
+
const mat = elemRef.kind === "value" ? "value_to_wire(ev)" : materializeExpr("ev", elemRef, plan);
|
|
2763
2752
|
lines.push(` match v {`);
|
|
2764
2753
|
lines.push(` Value::Arr(a) => {`);
|
|
2765
2754
|
lines.push(` let mut dec: Vec<${elemTy}> = Vec::with_capacity(a.len());`);
|
|
@@ -2769,6 +2758,10 @@ function emitInDecoder(comp, plan) {
|
|
|
2769
2758
|
lines.push(` other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected array, got `)}, other.type_name())),`);
|
|
2770
2759
|
lines.push(` }`);
|
|
2771
2760
|
}
|
|
2761
|
+
else if (schema?.type === "value") {
|
|
2762
|
+
// bc#156: a scalar `value` port — the raw bound value as BC's opaque wire (value_to_wire).
|
|
2763
|
+
lines.push(` in_.${field} = value_to_wire(v);`);
|
|
2764
|
+
}
|
|
2772
2765
|
else if (schema?.type === "map" && et !== undefined) {
|
|
2773
2766
|
// #108-map: decode the boxed Value::Obj into the native BTreeMap<String, V> (test glue — the input
|
|
2774
2767
|
// map port carries a declared elemType). materializeExpr covers the map de-box (obj → BTreeMap).
|