@stackables/bridge 1.6.0 → 1.7.0

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.
@@ -97,6 +97,14 @@ export declare class ExecutionTree {
97
97
  * `??` (fallback/fallbackRef): fires when all sources reject (throw/error). */
98
98
  private resolveWires;
99
99
  response(ipath: Path, array: boolean): Promise<any>;
100
+ /**
101
+ * Find define output wires for a specific field path.
102
+ *
103
+ * Looks for whole-object define forward wires (`o <- defineHandle`)
104
+ * at path=[] for this trunk, then searches the define's output wires
105
+ * for ones matching the requested field path.
106
+ */
107
+ private findDefineFieldWires;
100
108
  }
101
109
  export {};
102
110
  //# sourceMappingURL=ExecutionTree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionTree.d.ts","sourceRoot":"","sources":["../src/ExecutionTree.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,MAAM,EAEN,WAAW,EACX,OAAO,EAGP,OAAO,EAER,MAAM,YAAY,CAAC;AAGpB,gFAAgF;AAChF,UAAU,IAAI;IACZ,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED,KAAK,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAuBhF,4BAA4B;AAC5B,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAE1C,yCAAyC;AACzC,MAAM,MAAM,SAAS,GAAG;IACtB,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,sEAAsE;IACtE,KAAK,C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AG,CAAC;IAgCzC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAI9B,6DAA6D;IAC7D,aAAa,IAAI,IAAI;IAqBrB;;oFAEgF;IAChF,OAAO,CAAC,YAAY;IA8Cd,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAsHzD;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;CA0B7B"}
@@ -1,4 +1,4 @@
1
- import { parsePath } from "./bridge-format.js";
1
+ import { parsePath } from "./utils.js";
2
2
  import { SELF_MODULE } from "./types.js";
3
3
  /** Stable string key for the state map */
4
4
  function trunkKey(ref) {
@@ -416,6 +416,18 @@ export class ExecutionTree {
416
416
  cursor = cursor.parent;
417
417
  }
418
418
  if (value === undefined) {
419
+ // ── Lazy define field resolution ────────────────────────────────
420
+ // For define trunks (__define_in_* / __define_out_*) with a specific
421
+ // field path, resolve ONLY the wire(s) targeting that field instead
422
+ // of scheduling the entire trunk. This avoids triggering unrelated
423
+ // dependency chains (e.g. requesting "city" should not fire the
424
+ // lat/lon coalesce chains that call the geo tool).
425
+ if (ref.path.length > 0 && ref.module.startsWith("__define_")) {
426
+ const fieldWires = this.bridge?.wires.filter((w) => sameTrunk(w.to, ref) && pathEquals(w.to.path, ref.path)) ?? [];
427
+ if (fieldWires.length > 0) {
428
+ return this.resolveWires(fieldWires);
429
+ }
430
+ }
419
431
  this.state[key] = this.schedule(ref);
420
432
  value = this.state[key];
421
433
  }
@@ -578,6 +590,20 @@ export class ExecutionTree {
578
590
  sameTrunk(w.to, this.trunk) &&
579
591
  pathEquals(w.to.path, cleanPath)) ?? [];
580
592
  if (matches.length > 0) {
593
+ // ── Lazy define resolution ──────────────────────────────────────
594
+ // When ALL matches at the root object level (path=[]) are
595
+ // whole-object wires sourced from define output modules, defer
596
+ // resolution to field-by-field GraphQL traversal. This avoids
597
+ // eagerly scheduling every tool inside the define block — only
598
+ // fields actually requested by the query will trigger their
599
+ // dependency chains.
600
+ if (cleanPath.length === 0 &&
601
+ !array &&
602
+ matches.every((w) => "from" in w &&
603
+ w.from.module.startsWith("__define_out_") &&
604
+ w.from.path.length === 0)) {
605
+ return this;
606
+ }
581
607
  const response = this.resolveWires(matches);
582
608
  if (!array) {
583
609
  return response;
@@ -590,6 +616,24 @@ export class ExecutionTree {
590
616
  return s;
591
617
  });
592
618
  }
619
+ // ── Resolve field from deferred define ────────────────────────────
620
+ // No direct wires for this field path — check whether a define
621
+ // forward wire exists at the root level (`o <- defineHandle`) and
622
+ // resolve only the matching field wire from the define's output.
623
+ if (cleanPath.length > 0) {
624
+ const defineFieldWires = this.findDefineFieldWires(cleanPath);
625
+ if (defineFieldWires.length > 0) {
626
+ const response = this.resolveWires(defineFieldWires);
627
+ if (!array)
628
+ return response;
629
+ const items = (await response);
630
+ return items.map((item) => {
631
+ const s = this.shadow();
632
+ s.state[trunkKey({ ...this.trunk, element: true })] = item;
633
+ return s;
634
+ });
635
+ }
636
+ }
593
637
  // Fallback: if this shadow tree has stored element data, resolve the
594
638
  // requested field directly from it. This handles passthrough arrays
595
639
  // where the bridge maps an inner array (e.g. `.stops <- j.stops`) but
@@ -617,4 +661,28 @@ export class ExecutionTree {
617
661
  // Return self to trigger downstream resolvers
618
662
  return this;
619
663
  }
664
+ /**
665
+ * Find define output wires for a specific field path.
666
+ *
667
+ * Looks for whole-object define forward wires (`o <- defineHandle`)
668
+ * at path=[] for this trunk, then searches the define's output wires
669
+ * for ones matching the requested field path.
670
+ */
671
+ findDefineFieldWires(cleanPath) {
672
+ const forwards = this.bridge?.wires.filter((w) => "from" in w &&
673
+ sameTrunk(w.to, this.trunk) &&
674
+ w.to.path.length === 0 &&
675
+ w.from.module.startsWith("__define_out_") &&
676
+ w.from.path.length === 0) ?? [];
677
+ if (forwards.length === 0)
678
+ return [];
679
+ const result = [];
680
+ for (const fw of forwards) {
681
+ const defOutTrunk = fw.from;
682
+ const fieldWires = this.bridge?.wires.filter((w) => sameTrunk(w.to, defOutTrunk) &&
683
+ pathEquals(w.to.path, cleanPath)) ?? [];
684
+ result.push(...fieldWires);
685
+ }
686
+ return result;
687
+ }
620
688
  }
@@ -1,15 +1,8 @@
1
1
  import type { Instruction } from "./types.js";
2
- export declare function parseBridge(text: string): Instruction[];
3
- /**
4
- * Parse a dot-separated path with optional array indices.
5
- *
6
- * "items[0].position.lat" → ["items", "0", "position", "lat"]
7
- * "properties[]" → ["properties"] ([] is stripped, signals array)
8
- * "x-message-id" → ["x-message-id"]
9
- */
10
- export declare function parsePath(text: string): string[];
2
+ export { parsePath } from "./utils.js";
11
3
  /**
12
- * Serialize structured instructions back to .bridge text format.
4
+ * Parse .bridge text delegates to the Chevrotain parser.
13
5
  */
6
+ export declare function parseBridge(text: string): Instruction[];
14
7
  export declare function serializeBridge(instructions: Instruction[]): string;
15
8
  //# sourceMappingURL=bridge-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-format.d.ts","sourceRoot":"","sources":["../src/bridge-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKR,WAAW,EAMd,MAAM,YAAY,CAAC;AA8CpB,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CA0FvD;AAmxCD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAchD;AAID;;GAEG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CA8BnE"}
1
+ {"version":3,"file":"bridge-format.d.ts","sourceRoot":"","sources":["../src/bridge-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIR,WAAW,EAKd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAEvD;AAMD,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CA8BnE"}