behavior-contracts 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/behavior.d.ts.map +1 -1
  2. package/dist/behavior.js +18 -10
  3. package/dist/behavior.js.map +1 -1
  4. package/dist/generator/emit-shared-go.d.ts.map +1 -1
  5. package/dist/generator/emit-shared-go.js +40 -19
  6. package/dist/generator/emit-shared-go.js.map +1 -1
  7. package/dist/generator/emit-shared-rust.d.ts.map +1 -1
  8. package/dist/generator/emit-shared-rust.js +50 -30
  9. package/dist/generator/emit-shared-rust.js.map +1 -1
  10. package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
  11. package/dist/generator/emit-shared-typescript.js +26 -4
  12. package/dist/generator/emit-shared-typescript.js.map +1 -1
  13. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  14. package/dist/generator/emit-typed-native-go.js +50 -18
  15. package/dist/generator/emit-typed-native-go.js.map +1 -1
  16. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  17. package/dist/generator/emit-typed-native-rust.js +43 -13
  18. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  19. package/dist/generator/native-expr.d.ts +7 -0
  20. package/dist/generator/native-expr.d.ts.map +1 -1
  21. package/dist/generator/native-expr.js +11 -0
  22. package/dist/generator/native-expr.js.map +1 -1
  23. package/dist/generator/straightline.d.ts +5 -0
  24. package/dist/generator/straightline.d.ts.map +1 -1
  25. package/dist/generator/straightline.js +1 -0
  26. package/dist/generator/straightline.js.map +1 -1
  27. package/dist/generator/typed.d.ts +17 -11
  28. package/dist/generator/typed.d.ts.map +1 -1
  29. package/dist/generator/typed.js +19 -12
  30. package/dist/generator/typed.js.map +1 -1
  31. package/dist/plan.d.ts +7 -0
  32. package/dist/plan.d.ts.map +1 -1
  33. package/dist/plan.js +7 -2
  34. package/dist/plan.js.map +1 -1
  35. package/dist/primitives.d.ts +4 -3
  36. package/dist/primitives.d.ts.map +1 -1
  37. package/dist/primitives.js +8 -7
  38. package/dist/primitives.js.map +1 -1
  39. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { GeneratorFailure } from "./core.js";
2
2
  import { isControlGate, nodeWirePassthrough } 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, guardedMapIntoIsOpt, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
5
+ import { buildTypePlan, deriveTypeRef, findDecl, guardedMapIntoIsCoverable, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
6
6
  import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, nodeNarrowedPaths } from "./straightline.js";
7
7
  import { NativeExprCompiler } from "./native-expr.js";
8
8
  import { buildAsyncPlans } from "./async-plan.js";
@@ -591,8 +591,18 @@ function renderRustWireBox(plan, srcExpr, depth = 0) {
591
591
  const e = `e${depth}`;
592
592
  return `WireValue::List(WireList { items: ${srcExpr}.into_iter().map(|${e}| ${renderRustWireBox(plan.elem, e, depth + 1)}).collect() })`;
593
593
  }
594
+ if (plan.k === "map") {
595
+ // bc#181: typed map<V> → wire map, represented as a dynamic-keyed WireRow (there is NO WireMap type; a
596
+ // declared map<V> is the dynamic-keyed twin of a record — the READ side de-boxes a WireRow INTO map<V>
597
+ // the SAME way, emit-shared-debox `mapval`). Box EACH entry's VALUE recursively (box-once, no round-trip);
598
+ // keys carried as dynamic strings. BTreeMap<String,_> iterates in ascending key order, so the WireRow is
599
+ // deterministic (matching the rust typed map's canonical key order).
600
+ const k = `k${depth}`;
601
+ const v = `v${depth}`;
602
+ return `WireValue::Row(WireRow { entries: ${srcExpr}.into_iter().map(|(${k}, ${v})| (${k}, ${renderRustWireBox(plan.value, v, depth + 1)})).collect() })`;
603
+ }
594
604
  }
595
- throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust wire box: a value[] element of type '${plan.expectedType}' is not native-covered by the typed→wire box (an opt-wrapped or map element boxes ambiguously — fail-closed rather than risk a run_behavior divergence)`);
605
+ throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust wire box: a value[] element of type '${plan.expectedType}' is not native-covered by the typed→wire box (an OPT-wrapped element boxes ambiguously — opt present-vs-null on the wire is not statically pinned to run_behavior's Value pass-through — so it stays fail-closed rather than risk a divergence)`);
596
606
  }
597
607
  /** returnErrFail — the default de-box mismatch control flow: propagate the structured Error Value out of
598
608
  * the enclosing runner (fail/retry componentRef results + map/fanout element de-box, which fails closed
@@ -811,6 +821,9 @@ function makeRustExprBackend(resolveHead, plan) {
811
821
  wireType: () => renderTypeRef({ kind: "value" }),
812
822
  // bc#156/#160: box a value[] element into the opaque BC wire via the ONE box SSoT (owned element expr).
813
823
  wireBox: (item) => renderRustWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr),
824
+ // bc#178: box EACH element of the owned typed Vec into an arr<value> (Vec<WireValue>) — the same
825
+ // per-element box renderer as wireBox's list case, applied over the referenced array (box-once/element).
826
+ wireBoxEachElem: (srcExpr, elemRef) => `${srcExpr}.into_iter().map(|__be| ${renderRustWireBox(buildWirePlan(elemRef, { from: "elem" }, { model: "port", field: "port", plan }, "in"), "__be")}).collect::<Vec<${renderTypeRef({ kind: "value" })}>>()`,
814
827
  scalarType: (s) => rustScalar(s),
815
828
  strLit: (s) => `${rustStrLit(s)}.to_string()`,
816
829
  boolLit: (b) => (b ? "true" : "false"),
@@ -1272,13 +1285,14 @@ function coveredMapNode(n, bodyIds, comp) {
1272
1285
  if (n === null || typeof n !== "object" || !("map" in n))
1273
1286
  return false;
1274
1287
  const m = n.map;
1275
- // #108 (rust twin of the go predicate): a guarded map (`when`) IS covered with NO `into`. #177: a
1276
- // guarded map WITH `into` is covered ONLY when the into field is OPT (keep-with-null — kept element →
1277
- // present into, guard-skipped element → into=None), byte-equal to run_behavior applyInto pass-through +
1278
- // opt-into null. A REQUIRED into field → run_behavior FAILS MISSING_PROP on a skipped element, so
1279
- // fail-close is byte-equal. over element type must be statically resolvable: prior-node arr field, or
1280
- // an input array port carrying `elemType` (BC does not infer — consumer-interface C3).
1281
- if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsOpt(n, comp))
1288
+ // #108 (rust twin of the go predicate): a guarded map (`when`) IS covered with NO `into`. #177/#182: a
1289
+ // guarded map WITH `into` is covered when the guard-skipped element has a well-defined skip value — the
1290
+ // into field is OPT (skip → None, #177) OR relationKind:connection (skip → the empty connection
1291
+ // {items:[],cursor:null}, #182). Byte-equal to run_behavior applyInto (opt-into → null / connection-into
1292
+ // → unproducedValue("connection")). A REQUIRED non-connection into → run_behavior FAILS MISSING_PROP on a
1293
+ // skipped element, so fail-close is byte-equal. over element type must be statically resolvable: prior-node
1294
+ // arr field, or an input array port carrying `elemType` (BC does not infer — consumer-interface C3).
1295
+ if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
1282
1296
  return false;
1283
1297
  if (m.policy !== undefined && m.policy !== "fail")
1284
1298
  return false;
@@ -2033,6 +2047,21 @@ isAsync = false) {
2033
2047
  // mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType throw).
2034
2048
  const elemDeBoxRef = mapElemRowRef(node, elemArrRef, plan);
2035
2049
  const renderElemDeBox = (il) => renderResultDeBox(elemDeBoxRef, `er_${s}`, node.id, plan, il, returnErrFail, nodeWirePassthrough(node));
2050
+ // #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
2051
+ // NOT by opt-ness (matching run_behavior applyInto, which fills a connection into with the empty
2052
+ // connection UNCONDITIONALLY on relationKind==="connection"):
2053
+ // - connection into → the connection-zero in the field's typed rep (same shape emitProducedAwareValue
2054
+ // uses for a skipped connection node): a required `Conn` field → `Conn::default()`, an OPT
2055
+ // `Option<Conn>` field → `Some(Conn::default())` (empty connection, NOT None). `Conn::default()`'s
2056
+ // derived Default serializes to {items:[],cursor:null} (#182).
2057
+ // - non-connection into → opt → None = null (#177 keep-with-null; unchanged).
2058
+ const intoSkipDefault = m.relationKind === "connection"
2059
+ ? elemDeBoxRef.kind === "opt"
2060
+ ? `Some(${renderTypeRef(elemDeBoxRef.inner)}::default())`
2061
+ : `${renderTypeRef(elemDeBoxRef)}::default()`
2062
+ : elemDeBoxRef.kind === "opt"
2063
+ ? "None"
2064
+ : `${renderTypeRef(elemDeBoxRef)}::default()`;
2036
2065
  // build the per-element CONCRETE native ports struct. `il` = indent inside the element loop.
2037
2066
  const buildPorts = (il) => {
2038
2067
  const out = [];
@@ -2125,7 +2154,7 @@ isAsync = false) {
2125
2154
  lines.push(`${indent} let dec_${s} = decs_iter_${s}.next().expect("aligned kept row");`);
2126
2155
  lines.push(`${indent} built_${s}.push(${elemMat}(oel_${s}, dec_${s}));`);
2127
2156
  lines.push(`${indent} } else {`);
2128
- lines.push(`${indent} built_${s}.push(${elemMat}(oel_${s}, None));`);
2157
+ lines.push(`${indent} built_${s}.push(${elemMat}(oel_${s}, ${intoSkipDefault}));`);
2129
2158
  lines.push(`${indent} }`);
2130
2159
  lines.push(`${indent}}`);
2131
2160
  }
@@ -2178,9 +2207,10 @@ isAsync = false) {
2178
2207
  else {
2179
2208
  // #93 shape 2 / #108: NON-batched map — dispatch ONCE PER KEPT ELEMENT.
2180
2209
  lines.push(`${indent}for oel_${s} in over_${s}.iter() {`);
2181
- // #177 keep-with-null: a guard-skipped element is KEPT with into=None instead of dropped — byte-equal
2182
- // to run_behavior's applyInto pass-through + opt-into null.
2183
- const nonBatchedSkip = keepWithNull ? `built_${s}.push(${elemMat}(oel_${s}, None)); continue;` : "continue;";
2210
+ // #177/#182 keep-with-skip-value: a guard-skipped element is KEPT with into=intoSkipDefault (None /
2211
+ // Conn::default()) instead of dropped — byte-equal to run_behavior's applyInto (opt-into → null /
2212
+ // connection-into → empty connection).
2213
+ const nonBatchedSkip = keepWithNull ? `built_${s}.push(${elemMat}(oel_${s}, ${intoSkipDefault})); continue;` : "continue;";
2184
2214
  for (const l of emitGuard(indent + " ", nonBatchedSkip))
2185
2215
  lines.push(l);
2186
2216
  for (const l of buildPorts(indent + " "))