behavior-contracts 0.8.11 → 0.8.12
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/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-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 +340 -202
- 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 +195 -221
- 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/package.json +1 -1
|
@@ -214,14 +214,17 @@ 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
|
-
*
|
|
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. */
|
|
220
223
|
function emitRustProbeWireTypes() {
|
|
221
224
|
return `// Probe<T> / NumProbe — the outcome of classifying one wire attribute against a declared type. Got carries
|
|
222
225
|
// 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
|
-
//
|
|
226
|
+
// BC's to detect); actual_wire_type is the producer's own wire tag (S/N/BOOL/M/L/NULL); raw_value is the
|
|
227
|
+
// offending value stringified. Concrete enums — no boxed runtime value.
|
|
225
228
|
pub enum Probe<T> {
|
|
226
229
|
Got(T),
|
|
227
230
|
Wrong { actual_wire_type: String, raw_value: String },
|
|
@@ -236,46 +239,166 @@ pub enum NumProbe {
|
|
|
236
239
|
Absent,
|
|
237
240
|
}
|
|
238
241
|
|
|
239
|
-
// WireValue —
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
pub
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
242
|
+
// WireValue — the BC-OWNED, BC-GENERATED, self-contained (runtime-free) generic result the consumer's
|
|
243
|
+
// single op-agnostic transport returns. The consumer BUILDS it as it reads the producer (the raw I/O act)
|
|
244
|
+
// — WireValue::Str/Num/Bool/Null/Row/List, or the int()/float() constructors — and implements NOTHING over
|
|
245
|
+
// it. Numbers carry raw text (BC parses + range-checks → overflow is BC's to detect). A composite is a
|
|
246
|
+
// nested WireRow / WireList. NO trait, NO consumer classification protocol.
|
|
247
|
+
pub enum WireValue {
|
|
248
|
+
Str(String),
|
|
249
|
+
Num(String),
|
|
250
|
+
Bool(bool),
|
|
251
|
+
Null,
|
|
252
|
+
Row(WireRow),
|
|
253
|
+
List(WireList),
|
|
251
254
|
}
|
|
252
255
|
|
|
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>;
|
|
256
|
+
// WireRow / WireList — a wire map (a DynamoDB "M") / wire array (an "L"). Native Vec-backed; the generated
|
|
257
|
+
// de-box probes them by declared field / element and owns strictness (required/optional, present/absent,
|
|
258
|
+
// error assembly). row/list probes return a BORROW (Probe<&WireRow>/Probe<&WireList>) so nested decode is
|
|
259
|
+
// zero-copy — only leaf scalars are cloned into the covered typed struct.
|
|
260
|
+
pub struct WireRow {
|
|
261
|
+
pub entries: Vec<(String, WireValue)>,
|
|
266
262
|
}
|
|
267
263
|
|
|
268
|
-
pub
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
fn
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
fn
|
|
278
|
-
|
|
264
|
+
pub struct WireList {
|
|
265
|
+
pub items: Vec<WireValue>,
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
impl WireValue {
|
|
269
|
+
// constructors the consumer's transport uses to build numeric results (numbers ride as raw text).
|
|
270
|
+
pub fn int(n: i64) -> Self {
|
|
271
|
+
WireValue::Num(n.to_string())
|
|
272
|
+
}
|
|
273
|
+
pub fn float(n: f64) -> Self {
|
|
274
|
+
WireValue::Num(n.to_string())
|
|
275
|
+
}
|
|
276
|
+
// the top result is always present (Some(self)); the field/elem probes share the same classifiers.
|
|
277
|
+
pub fn as_string(&self) -> Probe<String> {
|
|
278
|
+
probe_string_at(Some(self))
|
|
279
|
+
}
|
|
280
|
+
pub fn as_number(&self) -> NumProbe {
|
|
281
|
+
probe_number_at(Some(self))
|
|
282
|
+
}
|
|
283
|
+
pub fn as_bool(&self) -> Probe<bool> {
|
|
284
|
+
probe_bool_at(Some(self))
|
|
285
|
+
}
|
|
286
|
+
pub fn as_row(&self) -> Probe<&WireRow> {
|
|
287
|
+
probe_row_at(Some(self))
|
|
288
|
+
}
|
|
289
|
+
pub fn as_list(&self) -> Probe<&WireList> {
|
|
290
|
+
probe_list_at(Some(self))
|
|
291
|
+
}
|
|
292
|
+
fn tag(&self) -> &'static str {
|
|
293
|
+
match self {
|
|
294
|
+
WireValue::Str(_) => "S",
|
|
295
|
+
WireValue::Num(_) => "N",
|
|
296
|
+
WireValue::Bool(_) => "BOOL",
|
|
297
|
+
WireValue::Null => "NULL",
|
|
298
|
+
WireValue::Row(_) => "M",
|
|
299
|
+
WireValue::List(_) => "L",
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
fn raw(&self) -> String {
|
|
303
|
+
match self {
|
|
304
|
+
WireValue::Str(s) => s.clone(),
|
|
305
|
+
WireValue::Num(s) => s.clone(),
|
|
306
|
+
WireValue::Bool(b) => b.to_string(),
|
|
307
|
+
WireValue::Null => "null".to_string(),
|
|
308
|
+
WireValue::Row(_) | WireValue::List(_) => "[composite]".to_string(),
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
impl WireRow {
|
|
314
|
+
fn get(&self, field: &str) -> Option<&WireValue> {
|
|
315
|
+
self.entries.iter().find(|(k, _)| k.as_str() == field).map(|(_, v)| v)
|
|
316
|
+
}
|
|
317
|
+
pub fn keys(&self) -> Vec<String> {
|
|
318
|
+
self.entries.iter().map(|(k, _)| k.clone()).collect()
|
|
319
|
+
}
|
|
320
|
+
pub fn probe_string(&self, field: &str) -> Probe<String> {
|
|
321
|
+
probe_string_at(self.get(field))
|
|
322
|
+
}
|
|
323
|
+
pub fn probe_number(&self, field: &str) -> NumProbe {
|
|
324
|
+
probe_number_at(self.get(field))
|
|
325
|
+
}
|
|
326
|
+
pub fn probe_bool(&self, field: &str) -> Probe<bool> {
|
|
327
|
+
probe_bool_at(self.get(field))
|
|
328
|
+
}
|
|
329
|
+
pub fn probe_row(&self, field: &str) -> Probe<&WireRow> {
|
|
330
|
+
probe_row_at(self.get(field))
|
|
331
|
+
}
|
|
332
|
+
pub fn probe_list(&self, field: &str) -> Probe<&WireList> {
|
|
333
|
+
probe_list_at(self.get(field))
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
impl WireList {
|
|
338
|
+
pub fn len(&self) -> usize {
|
|
339
|
+
self.items.len()
|
|
340
|
+
}
|
|
341
|
+
pub fn is_empty(&self) -> bool {
|
|
342
|
+
self.items.is_empty()
|
|
343
|
+
}
|
|
344
|
+
pub fn elem_string(&self, i: usize) -> Probe<String> {
|
|
345
|
+
probe_string_at(self.items.get(i))
|
|
346
|
+
}
|
|
347
|
+
pub fn elem_number(&self, i: usize) -> NumProbe {
|
|
348
|
+
probe_number_at(self.items.get(i))
|
|
349
|
+
}
|
|
350
|
+
pub fn elem_bool(&self, i: usize) -> Probe<bool> {
|
|
351
|
+
probe_bool_at(self.items.get(i))
|
|
352
|
+
}
|
|
353
|
+
pub fn elem_row(&self, i: usize) -> Probe<&WireRow> {
|
|
354
|
+
probe_row_at(self.items.get(i))
|
|
355
|
+
}
|
|
356
|
+
pub fn elem_list(&self, i: usize) -> Probe<&WireList> {
|
|
357
|
+
probe_list_at(self.items.get(i))
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// the ONE classifier per kind, over an Option<&WireValue> (None = absent attribute/element). The BC-owned
|
|
362
|
+
// WireValue variant IS the wire tag — no consumer classification.
|
|
363
|
+
fn probe_string_at(v: Option<&WireValue>) -> Probe<String> {
|
|
364
|
+
match v {
|
|
365
|
+
None => Probe::Absent,
|
|
366
|
+
Some(WireValue::Str(s)) => Probe::Got(s.clone()),
|
|
367
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
368
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
fn probe_number_at(v: Option<&WireValue>) -> NumProbe {
|
|
372
|
+
match v {
|
|
373
|
+
None => NumProbe::Absent,
|
|
374
|
+
Some(WireValue::Num(s)) => NumProbe::Got { raw: s.clone(), actual_wire_type: "N".to_string() },
|
|
375
|
+
Some(WireValue::Null) => NumProbe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
376
|
+
Some(o) => NumProbe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
fn probe_bool_at(v: Option<&WireValue>) -> Probe<bool> {
|
|
380
|
+
match v {
|
|
381
|
+
None => Probe::Absent,
|
|
382
|
+
Some(WireValue::Bool(b)) => Probe::Got(*b),
|
|
383
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
384
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
fn probe_row_at(v: Option<&WireValue>) -> Probe<&WireRow> {
|
|
388
|
+
match v {
|
|
389
|
+
None => Probe::Absent,
|
|
390
|
+
Some(WireValue::Row(r)) => Probe::Got(r),
|
|
391
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
392
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
fn probe_list_at(v: Option<&WireValue>) -> Probe<&WireList> {
|
|
396
|
+
match v {
|
|
397
|
+
None => Probe::Absent,
|
|
398
|
+
Some(WireValue::List(l)) => Probe::Got(l),
|
|
399
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
400
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
401
|
+
}
|
|
279
402
|
}`;
|
|
280
403
|
}
|
|
281
404
|
/**
|
|
@@ -2241,7 +2364,7 @@ use std::cell::RefCell;`;
|
|
|
2241
2364
|
: undefined,
|
|
2242
2365
|
`// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
|
|
2243
2366
|
anyWire
|
|
2244
|
-
? `// strict de-box wire seam — the
|
|
2367
|
+
? `// 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()}`
|
|
2245
2368
|
: undefined,
|
|
2246
2369
|
elemMaterializers.length
|
|
2247
2370
|
? `// map augmented-element copiers (pure struct field assignment — no dynamic value read).\n${elemMaterializers.join("\n\n")}`
|
|
@@ -2278,174 +2401,25 @@ export function rustTypedNativeObserve(ir, ioModel = "sync", leaf) {
|
|
|
2278
2401
|
// every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
|
|
2279
2402
|
// needed whenever any component has a handler node.
|
|
2280
2403
|
const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
2281
|
-
//
|
|
2282
|
-
//
|
|
2283
|
-
//
|
|
2284
|
-
//
|
|
2285
|
-
//
|
|
2404
|
+
// value_to_wire (TEST glue): builds the covered module's BC-OWNED concrete `WireValue` from a scripted bc
|
|
2405
|
+
// `Value` — the test-harness analog of the consumer's real transport (which builds `WireValue` as it reads
|
|
2406
|
+
// the producer). Numbers ride as raw text (WireValue::Num), matching how the de-box parses + range-checks;
|
|
2407
|
+
// the wire tags + classification live ONCE in the covered module's WireValue (probe_*_at), so this only
|
|
2408
|
+
// CONSTRUCTS — a scripted wrong-variant value maps to the corresponding WireValue variant and the covered
|
|
2409
|
+
// de-box classifies it (TYPE_MISMATCH ≡ run_behavior), no separate scripted classifier.
|
|
2286
2410
|
const wireAdapter = anyDeBox
|
|
2287
|
-
? `// ──
|
|
2288
|
-
fn
|
|
2289
|
-
match v {
|
|
2290
|
-
Value::Null => "NULL",
|
|
2291
|
-
Value::Bool(_) => "BOOL",
|
|
2292
|
-
Value::Int(_) | Value::Float(_) => "N",
|
|
2293
|
-
Value::Str(_) => "S",
|
|
2294
|
-
Value::Arr(_) => "L",
|
|
2295
|
-
Value::Obj(_) => "M",
|
|
2296
|
-
}
|
|
2297
|
-
.to_string()
|
|
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> {
|
|
2411
|
+
? `// ── value_to_wire (TEST glue): scripted bc Value -> the covered module's BC-owned WireValue ──
|
|
2412
|
+
fn value_to_wire(v: &Value) -> WireValue {
|
|
2331
2413
|
match v {
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
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))
|
|
2414
|
+
Value::Null => WireValue::Null,
|
|
2415
|
+
Value::Bool(b) => WireValue::Bool(*b),
|
|
2416
|
+
Value::Int(n) => WireValue::Num(n.to_string()),
|
|
2417
|
+
Value::Float(f) => WireValue::Num(f.to_string()),
|
|
2418
|
+
Value::Str(s) => WireValue::Str(s.clone()),
|
|
2419
|
+
Value::Arr(items) => WireValue::List(WireList { items: items.iter().map(value_to_wire).collect() }),
|
|
2420
|
+
Value::Obj(pairs) => WireValue::Row(WireRow {
|
|
2421
|
+
entries: pairs.iter().map(|(k, vv)| (k.clone(), value_to_wire(vv))).collect(),
|
|
2422
|
+
}),
|
|
2449
2423
|
}
|
|
2450
2424
|
}`
|
|
2451
2425
|
: "";
|
|
@@ -2476,17 +2450,17 @@ impl WireList for ScriptedWireList {
|
|
|
2476
2450
|
// async iff this catalog leaf's terminal handler is async (consistent per catalog component).
|
|
2477
2451
|
const fnKw = ap.nodeIsAsync(n.id) ? "pub async fn" : "pub fn";
|
|
2478
2452
|
if ("fanout" in n) {
|
|
2479
|
-
// fanout: return the aligned per-id element WIRES (Vec<Option<
|
|
2453
|
+
// fanout: return the aligned per-id element WIRES (Vec<Option<WireValue>>); a null aligned
|
|
2480
2454
|
// body is a DANGLING id → None (the covered runner maps it to the zero element).
|
|
2481
2455
|
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2482
|
-
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<Option<
|
|
2456
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<Option<WireValue>>, BehaviorError> {
|
|
2483
2457
|
${drainStmt(catalog, "_echo")}
|
|
2484
2458
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2485
2459
|
let wires = arr
|
|
2486
2460
|
.into_iter()
|
|
2487
2461
|
.map(|ev| match ev {
|
|
2488
2462
|
Value::Null => None,
|
|
2489
|
-
_ => Some(
|
|
2463
|
+
_ => Some(value_to_wire(&ev)),
|
|
2490
2464
|
})
|
|
2491
2465
|
.collect();
|
|
2492
2466
|
Ok(wires)
|
|
@@ -2494,23 +2468,23 @@ impl WireList for ScriptedWireList {
|
|
|
2494
2468
|
continue;
|
|
2495
2469
|
}
|
|
2496
2470
|
if ("map" in n) {
|
|
2497
|
-
// map: batched → one WIRE per element (Vec<
|
|
2471
|
+
// map: batched → one WIRE per element (Vec<WireValue>); non-batched → one element WIRE.
|
|
2498
2472
|
const m = n.map;
|
|
2499
2473
|
if (m.batched === true) {
|
|
2500
2474
|
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2501
|
-
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<
|
|
2475
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<WireValue>, BehaviorError> {
|
|
2502
2476
|
${drainStmt(catalog, "_echo")}
|
|
2503
2477
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2504
|
-
let wires = arr.
|
|
2478
|
+
let wires = arr.iter().map(value_to_wire).collect();
|
|
2505
2479
|
Ok(wires)
|
|
2506
2480
|
}`);
|
|
2507
2481
|
}
|
|
2508
2482
|
else {
|
|
2509
2483
|
const { elemRef: overElemRef } = mapOverElemInfo(c, n, typedNodes, plan);
|
|
2510
2484
|
const params = spreadParams(portFieldSpread(m.ports, c, plan, typedNodes, { name: m.as, ref: overElemRef, plan }));
|
|
2511
|
-
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<
|
|
2485
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2512
2486
|
${drainStmt(catalog, "_echo")}
|
|
2513
|
-
Ok(
|
|
2487
|
+
Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2514
2488
|
}`);
|
|
2515
2489
|
}
|
|
2516
2490
|
continue;
|
|
@@ -2535,12 +2509,12 @@ impl WireList for ScriptedWireList {
|
|
|
2535
2509
|
if (portRust === recordRust) {
|
|
2536
2510
|
// the port IS the whole record → echo it DIRECTLY (matching run_behavior's plain echo:port).
|
|
2537
2511
|
const own = typeRefIsCopy(ref) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2538
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2512
|
+
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(value_to_wire(&${serializeTyped("tv", ref, plan)}));\n }`);
|
|
2539
2513
|
}
|
|
2540
2514
|
else if (fieldRust !== null && field !== undefined && portRust === fieldRust) {
|
|
2541
2515
|
// a scalar port wraps into the record's single field ({v: ports.X}).
|
|
2542
2516
|
const own = typeRefIsCopy(field.type) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2543
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2517
|
+
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
2518
|
}
|
|
2545
2519
|
}
|
|
2546
2520
|
}
|
|
@@ -2548,14 +2522,14 @@ impl WireList for ScriptedWireList {
|
|
|
2548
2522
|
// #129: an arr node with an `items` port echoes the NATIVE port array (serialized element-by-element
|
|
2549
2523
|
// into a Value::Arr) so the node→leaf array dataflow test is non-vacuous.
|
|
2550
2524
|
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(
|
|
2525
|
+
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
2526
|
}
|
|
2553
2527
|
const canEcho = echoBranches.length > 0;
|
|
2554
2528
|
const params = spreadParams(portFieldSpread(node.ports, c, plan, typedNodes));
|
|
2555
2529
|
const echoBlock = canEcho ? `${echoBranches.join("\n")}\n` : "";
|
|
2556
|
-
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<
|
|
2530
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2557
2531
|
${drainStmt(catalog, canEcho ? "echo" : "_echo")}
|
|
2558
|
-
${echoBlock} Ok(
|
|
2532
|
+
${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2559
2533
|
}`);
|
|
2560
2534
|
}
|
|
2561
2535
|
}
|