@stackables/bridge-core 0.0.1 → 1.0.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.
Files changed (54) hide show
  1. package/README.md +55 -0
  2. package/build/{ExecutionTree.d.ts → bridge-core/src/ExecutionTree.d.ts} +14 -13
  3. package/build/bridge-core/src/ExecutionTree.d.ts.map +1 -0
  4. package/build/{ExecutionTree.js → bridge-core/src/ExecutionTree.js} +155 -93
  5. package/build/{execute-bridge.d.ts → bridge-core/src/execute-bridge.d.ts} +19 -7
  6. package/build/bridge-core/src/execute-bridge.d.ts.map +1 -0
  7. package/build/{execute-bridge.js → bridge-core/src/execute-bridge.js} +13 -6
  8. package/build/{index.d.ts → bridge-core/src/index.d.ts} +4 -2
  9. package/build/bridge-core/src/index.d.ts.map +1 -0
  10. package/build/{index.js → bridge-core/src/index.js} +5 -1
  11. package/build/bridge-core/src/merge-documents.d.ts +25 -0
  12. package/build/bridge-core/src/merge-documents.d.ts.map +1 -0
  13. package/build/bridge-core/src/merge-documents.js +91 -0
  14. package/build/bridge-core/src/tools/index.d.ts.map +1 -0
  15. package/build/bridge-core/src/tools/internal.d.ts.map +1 -0
  16. package/build/{types.d.ts → bridge-core/src/types.d.ts} +28 -1
  17. package/build/bridge-core/src/types.d.ts.map +1 -0
  18. package/build/{types.js → bridge-core/src/types.js} +1 -0
  19. package/build/bridge-core/src/utils.d.ts.map +1 -0
  20. package/build/bridge-core/src/version-check.d.ts +64 -0
  21. package/build/bridge-core/src/version-check.d.ts.map +1 -0
  22. package/build/bridge-core/src/version-check.js +205 -0
  23. package/build/bridge-stdlib/src/index.d.ts +34 -0
  24. package/build/bridge-stdlib/src/index.d.ts.map +1 -0
  25. package/build/bridge-stdlib/src/index.js +40 -0
  26. package/build/bridge-stdlib/src/tools/arrays.d.ts +28 -0
  27. package/build/bridge-stdlib/src/tools/arrays.d.ts.map +1 -0
  28. package/build/bridge-stdlib/src/tools/arrays.js +50 -0
  29. package/build/bridge-stdlib/src/tools/audit.d.ts +36 -0
  30. package/build/bridge-stdlib/src/tools/audit.d.ts.map +1 -0
  31. package/build/bridge-stdlib/src/tools/audit.js +39 -0
  32. package/build/bridge-stdlib/src/tools/http-call.d.ts +35 -0
  33. package/build/bridge-stdlib/src/tools/http-call.d.ts.map +1 -0
  34. package/build/bridge-stdlib/src/tools/http-call.js +118 -0
  35. package/build/bridge-stdlib/src/tools/strings.d.ts +13 -0
  36. package/build/bridge-stdlib/src/tools/strings.d.ts.map +1 -0
  37. package/build/bridge-stdlib/src/tools/strings.js +12 -0
  38. package/build/bridge-types/src/index.d.ts +63 -0
  39. package/build/bridge-types/src/index.d.ts.map +1 -0
  40. package/build/bridge-types/src/index.js +8 -0
  41. package/package.json +6 -4
  42. package/build/ExecutionTree.d.ts.map +0 -1
  43. package/build/execute-bridge.d.ts.map +0 -1
  44. package/build/index.d.ts.map +0 -1
  45. package/build/tools/index.d.ts.map +0 -1
  46. package/build/tools/internal.d.ts.map +0 -1
  47. package/build/types.d.ts.map +0 -1
  48. package/build/utils.d.ts.map +0 -1
  49. /package/build/{tools → bridge-core/src/tools}/index.d.ts +0 -0
  50. /package/build/{tools → bridge-core/src/tools}/index.js +0 -0
  51. /package/build/{tools → bridge-core/src/tools}/internal.d.ts +0 -0
  52. /package/build/{tools → bridge-core/src/tools}/internal.js +0 -0
  53. /package/build/{utils.d.ts → bridge-core/src/utils.d.ts} +0 -0
  54. /package/build/{utils.js → bridge-core/src/utils.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { ExecutionTree, TraceCollector } from "./ExecutionTree.js";
2
2
  import { SELF_MODULE } from "./types.js";
3
- import { std } from "@stackables/bridge-stdlib";
3
+ import { std as bundledStd, STD_VERSION as BUNDLED_STD_VERSION, } from "@stackables/bridge-stdlib";
4
+ import { resolveStd, checkHandleVersions } from "./version-check.js";
4
5
  /**
5
6
  * Execute a bridge operation without GraphQL.
6
7
  *
@@ -11,12 +12,12 @@ import { std } from "@stackables/bridge-stdlib";
11
12
  *
12
13
  * @example
13
14
  * ```ts
14
- * import { parseBridgeDiagnostics, executeBridge } from "@stackables/bridge";
15
+ * import { parseBridge, executeBridge } from "@stackables/bridge";
15
16
  * import { readFileSync } from "node:fs";
16
17
  *
17
- * const { instructions } = parseBridgeDiagnostics(readFileSync("my.bridge", "utf8"));
18
+ * const document = parseBridge(readFileSync("my.bridge", "utf8"));
18
19
  * const { data } = await executeBridge({
19
- * instructions,
20
+ * document,
20
21
  * operation: "Query.myField",
21
22
  * input: { city: "Berlin" },
22
23
  * });
@@ -24,14 +25,20 @@ import { std } from "@stackables/bridge-stdlib";
24
25
  * ```
25
26
  */
26
27
  export async function executeBridge(options) {
27
- const { instructions, operation, input = {}, context = {} } = options;
28
+ const { document: doc, operation, input = {}, context = {} } = options;
28
29
  const parts = operation.split(".");
29
30
  if (parts.length !== 2 || !parts[0] || !parts[1]) {
30
31
  throw new Error(`Invalid operation "${operation}" — expected "Type.field" (e.g. "Query.myField")`);
31
32
  }
32
33
  const [type, field] = parts;
33
34
  const trunk = { module: SELF_MODULE, type, field };
34
- const tree = new ExecutionTree(trunk, instructions, { std, ...(options.tools ?? {}) }, context);
35
+ const userTools = options.tools ?? {};
36
+ // Resolve which std to use: bundled, or a versioned namespace from tools
37
+ const { namespace: activeStd, version: activeStdVersion } = resolveStd(doc.version, bundledStd, BUNDLED_STD_VERSION, userTools);
38
+ const allTools = { std: activeStd, ...userTools };
39
+ // Verify all @version-tagged handles can be satisfied
40
+ checkHandleVersions(doc.instructions, allTools, activeStdVersion);
41
+ const tree = new ExecutionTree(trunk, doc, allTools, context);
35
42
  if (options.logger)
36
43
  tree.logger = options.logger;
37
44
  if (options.signal)
@@ -8,9 +8,11 @@
8
8
  */
9
9
  export { executeBridge } from "./execute-bridge.ts";
10
10
  export type { ExecuteBridgeOptions, ExecuteBridgeResult, } from "./execute-bridge.ts";
11
- export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, } from "./ExecutionTree.ts";
11
+ export { checkStdVersion, checkHandleVersions, collectVersionedHandles, getBridgeVersion, hasVersionedToolFn, resolveStd, } from "./version-check.ts";
12
+ export { mergeBridgeDocuments } from "./merge-documents.ts";
13
+ export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, MAX_EXECUTION_DEPTH, } from "./ExecutionTree.ts";
12
14
  export type { Logger, ToolTrace, TraceLevel } from "./ExecutionTree.ts";
13
15
  export { SELF_MODULE } from "./types.ts";
14
- export type { Bridge, CacheStore, ConstDef, ControlFlowInstruction, DefineDef, HandleBinding, Instruction, NodeRef, ToolCallFn, ToolContext, ToolDef, ToolDep, ToolMap, ToolWire, Wire, } from "./types.ts";
16
+ export type { Bridge, BridgeDocument, CacheStore, ConstDef, ControlFlowInstruction, DefineDef, HandleBinding, Instruction, NodeRef, ToolCallFn, ToolContext, ToolDef, ToolDep, ToolMap, ToolWire, VersionDecl, Wire, } from "./types.ts";
15
17
  export { parsePath } from "./utils.ts";
16
18
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAI5D,OAAO,EACL,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIxE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EACV,MAAM,EACN,cAAc,EACd,UAAU,EACV,QAAQ,EACR,sBAAsB,EACtB,SAAS,EACT,aAAa,EACb,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,WAAW,EACX,IAAI,GACL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
@@ -8,8 +8,12 @@
8
8
  */
9
9
  // ── Runtime engine ──────────────────────────────────────────────────────────
10
10
  export { executeBridge } from "./execute-bridge.js";
11
+ // ── Version check ───────────────────────────────────────────────────────────
12
+ export { checkStdVersion, checkHandleVersions, collectVersionedHandles, getBridgeVersion, hasVersionedToolFn, resolveStd, } from "./version-check.js";
13
+ // ── Document utilities ──────────────────────────────────────────────────────
14
+ export { mergeBridgeDocuments } from "./merge-documents.js";
11
15
  // ── Execution tree (advanced) ───────────────────────────────────────────────
12
- export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, } from "./ExecutionTree.js";
16
+ export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, MAX_EXECUTION_DEPTH, } from "./ExecutionTree.js";
13
17
  // ── Types ───────────────────────────────────────────────────────────────────
14
18
  export { SELF_MODULE } from "./types.js";
15
19
  // ── Utilities ───────────────────────────────────────────────────────────────
@@ -0,0 +1,25 @@
1
+ import type { BridgeDocument } from "./types.ts";
2
+ /**
3
+ * Merge multiple `BridgeDocument`s into one.
4
+ *
5
+ * Instructions are concatenated in order. For the version field, the
6
+ * **highest** declared version wins — this preserves the strictest
7
+ * compatibility requirement across all source documents. Documents
8
+ * without a version are silently skipped during version resolution.
9
+ *
10
+ * Top-level names (bridges, tools, constants, defines) must be globally
11
+ * unique across all merged documents. Duplicates cause an immediate error
12
+ * rather than silently shadowing one another.
13
+ *
14
+ * @throws Error when documents declare different **major** versions
15
+ * (e.g. merging a `1.x` and `2.x` document is not allowed).
16
+ * @throws Error when documents define duplicate top-level names.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const merged = mergeBridgeDocuments(weatherDoc, quotesDoc, authDoc);
21
+ * const schema = bridgeTransform(baseSchema, merged, { tools });
22
+ * ```
23
+ */
24
+ export declare function mergeBridgeDocuments(...docs: BridgeDocument[]): BridgeDocument;
25
+ //# sourceMappingURL=merge-documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-documents.d.ts","sourceRoot":"","sources":["../../../src/merge-documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,IAAI,EAAE,cAAc,EAAE,GACxB,cAAc,CA8BhB"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Merge multiple `BridgeDocument`s into one.
3
+ *
4
+ * Instructions are concatenated in order. For the version field, the
5
+ * **highest** declared version wins — this preserves the strictest
6
+ * compatibility requirement across all source documents. Documents
7
+ * without a version are silently skipped during version resolution.
8
+ *
9
+ * Top-level names (bridges, tools, constants, defines) must be globally
10
+ * unique across all merged documents. Duplicates cause an immediate error
11
+ * rather than silently shadowing one another.
12
+ *
13
+ * @throws Error when documents declare different **major** versions
14
+ * (e.g. merging a `1.x` and `2.x` document is not allowed).
15
+ * @throws Error when documents define duplicate top-level names.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const merged = mergeBridgeDocuments(weatherDoc, quotesDoc, authDoc);
20
+ * const schema = bridgeTransform(baseSchema, merged, { tools });
21
+ * ```
22
+ */
23
+ export function mergeBridgeDocuments(...docs) {
24
+ if (docs.length === 0) {
25
+ return { instructions: [] };
26
+ }
27
+ if (docs.length === 1) {
28
+ return docs[0];
29
+ }
30
+ const version = resolveVersion(docs);
31
+ const instructions = [];
32
+ // Track global namespaces to prevent collisions across merged files
33
+ const seenDefs = new Set();
34
+ for (const doc of docs) {
35
+ for (const inst of doc.instructions) {
36
+ const key = instructionKey(inst);
37
+ if (key) {
38
+ if (seenDefs.has(key)) {
39
+ throw new Error(`Merge conflict: duplicate ${key.replace(":", " '")}' across bridge documents.`);
40
+ }
41
+ seenDefs.add(key);
42
+ }
43
+ instructions.push(inst);
44
+ }
45
+ }
46
+ return { version, instructions };
47
+ }
48
+ // ── Internal ────────────────────────────────────────────────────────────────
49
+ /** Unique key for a top-level instruction, used for collision detection. */
50
+ function instructionKey(inst) {
51
+ switch (inst.kind) {
52
+ case "const":
53
+ return `const:${inst.name}`;
54
+ case "tool":
55
+ return `tool:${inst.name}`;
56
+ case "define":
57
+ return `define:${inst.name}`;
58
+ case "bridge":
59
+ return `bridge:${inst.type}.${inst.field}`;
60
+ }
61
+ }
62
+ /**
63
+ * Pick the highest declared version, ensuring all documents share the same
64
+ * major. Returns `undefined` when no document declares a version.
65
+ */
66
+ function resolveVersion(docs) {
67
+ let best;
68
+ let bestMajor = -1;
69
+ let bestMinor = -1;
70
+ let bestPatch = -1;
71
+ for (const doc of docs) {
72
+ if (!doc.version)
73
+ continue;
74
+ const parts = doc.version.split(".").map(Number);
75
+ const [major = 0, minor = 0, patch = 0] = parts;
76
+ if (best !== undefined && major !== bestMajor) {
77
+ throw new Error(`Cannot merge bridge documents with different major versions: ` +
78
+ `${best} vs ${doc.version}. ` +
79
+ `Split them into separate bridgeTransform calls instead.`);
80
+ }
81
+ if (major > bestMajor ||
82
+ (major === bestMajor && minor > bestMinor) ||
83
+ (major === bestMajor && minor === bestMinor && patch > bestPatch)) {
84
+ best = doc.version;
85
+ bestMajor = major;
86
+ bestMinor = minor;
87
+ bestPatch = patch;
88
+ }
89
+ }
90
+ return best;
91
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"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AAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE1D;AACD,yEAAyE;AACzE,wBAAgB,GAAG,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE3D;AACD,mDAAmD;AACnD,wBAAgB,GAAG,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,OAAO,CAE7C;AACD,kEAAkE;AAClE,wBAAgB,GAAG,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,OAAO,CAErD;AACD,iEAAiE;AACjE,wBAAgB,EAAE,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,OAAO,CAEpD;AACD,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAKpE"}
@@ -157,6 +157,7 @@ export type HandleBinding = {
157
157
  handle: string;
158
158
  kind: "tool";
159
159
  name: string;
160
+ version?: string;
160
161
  } | {
161
162
  handle: string;
162
163
  kind: "input";
@@ -212,6 +213,7 @@ export type ToolDep = {
212
213
  kind: "tool";
213
214
  handle: string;
214
215
  tool: string;
216
+ version?: string;
215
217
  } | {
216
218
  kind: "const";
217
219
  handle: string;
@@ -288,8 +290,33 @@ export type ConstDef = {
288
290
  /** Raw JSON string — parsed at runtime when accessed */
289
291
  value: string;
290
292
  };
291
- /** Union of all instruction types */
293
+ /**
294
+ * Version declaration — records the bridge file's declared language version.
295
+ *
296
+ * Emitted by the parser as the first instruction. Used at runtime to verify
297
+ * that the standard library satisfies the bridge's minimum version requirement.
298
+ *
299
+ * Example: `version 1.5` → `{ kind: "version", version: "1.5" }`
300
+ */
301
+ export type VersionDecl = {
302
+ kind: "version";
303
+ /** Declared version string, e.g. "1.5" */
304
+ version: string;
305
+ };
306
+ /** Union of all instruction types (excludes VersionDecl — version lives on BridgeDocument) */
292
307
  export type Instruction = Bridge | ToolDef | ConstDef | DefineDef;
308
+ /**
309
+ * Parsed bridge document — the structured output of the compiler.
310
+ *
311
+ * Wraps the instruction array with document-level metadata (version) and
312
+ * provides a natural home for future pre-computed optimisations.
313
+ */
314
+ export interface BridgeDocument {
315
+ /** Declared language version (from `version X.Y` header). */
316
+ version?: string;
317
+ /** All instructions: bridge, tool, const, and define blocks. */
318
+ instructions: Instruction[];
319
+ }
293
320
  /**
294
321
  * Define block — a reusable named subgraph (pipeline / macro).
295
322
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,IAAI,GACZ;IACE,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,iBAAiB,CAAC,EAAE,OAAO,EAAE,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/** Internal module identifier for the bridge's own trunk (input args + output fields) */
2
2
  export const SELF_MODULE = "_";
3
+ /* c8 ignore stop */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAchD"}
@@ -0,0 +1,64 @@
1
+ import type { BridgeDocument, Instruction, ToolMap } from "./types.ts";
2
+ /**
3
+ * Extract the declared bridge version from a document.
4
+ * Returns `undefined` if no version was declared.
5
+ */
6
+ export declare function getBridgeVersion(doc: BridgeDocument): string | undefined;
7
+ /**
8
+ * Verify that the standard library satisfies the bridge file's declared version.
9
+ *
10
+ * The bridge `version X.Y` header acts as a minimum-version constraint:
11
+ * - Same major → compatible (only major bumps introduce breaking changes)
12
+ * - Bridge minor ≤ std minor → OK (std is same or newer)
13
+ * - Bridge minor > std minor → ERROR (bridge needs features not in this std)
14
+ * - Different major → ERROR (user must provide a compatible std explicitly)
15
+ *
16
+ * @throws Error with an actionable message when the std is incompatible.
17
+ */
18
+ export declare function checkStdVersion(version: string | undefined, stdVersion: string): void;
19
+ /**
20
+ * Resolve the standard library namespace and version to use.
21
+ *
22
+ * Checks the bundled std first. When the bridge file targets a different
23
+ * major version (e.g. `version 1.5` vs bundled `2.0.0`), scans the
24
+ * user-provided tools map for a versioned namespace key like `"std@1.5"`.
25
+ *
26
+ * @returns The resolved std namespace and its version string.
27
+ * @throws Error with an actionable message when no compatible std is found.
28
+ */
29
+ export declare function resolveStd(version: string | undefined, bundledStd: ToolMap, bundledStdVersion: string, userTools?: ToolMap): {
30
+ namespace: ToolMap;
31
+ version: string;
32
+ };
33
+ /**
34
+ * Collect every tool reference that carries an `@version` tag from handles
35
+ * (bridge/define blocks) and deps (tool blocks).
36
+ */
37
+ export declare function collectVersionedHandles(instructions: Instruction[]): Array<{
38
+ name: string;
39
+ version: string;
40
+ }>;
41
+ /**
42
+ * Check whether a versioned dotted tool name can be resolved.
43
+ *
44
+ * In addition to the standard checks (namespace traversal, flat key),
45
+ * this also checks **versioned namespace keys** in the tool map:
46
+ * - `"std.str.toLowerCase@999.1"` as a flat key
47
+ * - `"std.str@999.1"` as a namespace key containing `toLowerCase`
48
+ * - `"std@999.1"` as a namespace key, traversing to `str.toLowerCase`
49
+ */
50
+ export declare function hasVersionedToolFn(toolFns: ToolMap, name: string, version: string): boolean;
51
+ /**
52
+ * Validate that all versioned tool handles can be satisfied at runtime.
53
+ *
54
+ * For each handle with `@version`:
55
+ * 1. A versioned key or versioned namespace in the tool map → satisfied
56
+ * 2. A `std.*` tool whose STD_VERSION ≥ the requested version → satisfied
57
+ * 3. Otherwise → throws with an actionable error message
58
+ *
59
+ * Call this **before** constructing the ExecutionTree to fail early.
60
+ *
61
+ * @throws Error when a versioned tool cannot be satisfied.
62
+ */
63
+ export declare function checkHandleVersions(instructions: Instruction[], toolFns: ToolMap, stdVersion: string): void;
64
+ //# sourceMappingURL=version-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-check.d.ts","sourceRoot":"","sources":["../../../src/version-check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EAEd,WAAW,EAEX,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAExE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,UAAU,EAAE,MAAM,GACjB,IAAI,CAuBN;AAID;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,UAAU,EAAE,OAAO,EACnB,iBAAiB,EAAE,MAAM,EACzB,SAAS,GAAE,OAAY,GACtB;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA4CzC;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,WAAW,EAAE,GAC1B,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAmB1C;AAwBD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CA8BT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,WAAW,EAAE,EAC3B,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,GACjB,IAAI,CA6BN"}
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Extract the declared bridge version from a document.
3
+ * Returns `undefined` if no version was declared.
4
+ */
5
+ export function getBridgeVersion(doc) {
6
+ return doc.version;
7
+ }
8
+ /**
9
+ * Verify that the standard library satisfies the bridge file's declared version.
10
+ *
11
+ * The bridge `version X.Y` header acts as a minimum-version constraint:
12
+ * - Same major → compatible (only major bumps introduce breaking changes)
13
+ * - Bridge minor ≤ std minor → OK (std is same or newer)
14
+ * - Bridge minor > std minor → ERROR (bridge needs features not in this std)
15
+ * - Different major → ERROR (user must provide a compatible std explicitly)
16
+ *
17
+ * @throws Error with an actionable message when the std is incompatible.
18
+ */
19
+ export function checkStdVersion(version, stdVersion) {
20
+ if (!version)
21
+ return; // no version declared — nothing to check
22
+ const bParts = version.split(".").map(Number);
23
+ const sParts = stdVersion.split(".").map(Number);
24
+ const [bMajor = 0, bMinor = 0] = bParts;
25
+ const [sMajor = 0, sMinor = 0] = sParts;
26
+ if (bMajor !== sMajor) {
27
+ throw new Error(`Bridge version ${version} requires a ${bMajor}.x standard library, ` +
28
+ `but the provided std is ${stdVersion} (major version ${sMajor}). ` +
29
+ `Provide a compatible std as "std@${version}" in the tools map.`);
30
+ }
31
+ if (bMinor > sMinor) {
32
+ throw new Error(`Bridge version ${version} requires standard library ≥ ${bMajor}.${bMinor}, ` +
33
+ `but the installed @stackables/bridge-stdlib is ${stdVersion}. ` +
34
+ `Update @stackables/bridge-stdlib to ${bMajor}.${bMinor}.0 or later.`);
35
+ }
36
+ }
37
+ // ── Std resolution from tools map ───────────────────────────────────────────
38
+ /**
39
+ * Resolve the standard library namespace and version to use.
40
+ *
41
+ * Checks the bundled std first. When the bridge file targets a different
42
+ * major version (e.g. `version 1.5` vs bundled `2.0.0`), scans the
43
+ * user-provided tools map for a versioned namespace key like `"std@1.5"`.
44
+ *
45
+ * @returns The resolved std namespace and its version string.
46
+ * @throws Error with an actionable message when no compatible std is found.
47
+ */
48
+ export function resolveStd(version, bundledStd, bundledStdVersion, userTools = {}) {
49
+ if (!version) {
50
+ return { namespace: bundledStd, version: bundledStdVersion };
51
+ }
52
+ const [bMajor = 0, bMinor = 0] = version.split(".").map(Number);
53
+ const [sMajor = 0, sMinor = 0] = bundledStdVersion.split(".").map(Number);
54
+ // Bundled std satisfies the bridge version
55
+ if (bMajor === sMajor && sMinor >= bMinor) {
56
+ return { namespace: bundledStd, version: bundledStdVersion };
57
+ }
58
+ // Scan tools for a versioned std namespace key (e.g. "std@1.5")
59
+ for (const key of Object.keys(userTools)) {
60
+ const match = key.match(/^std@(.+)$/);
61
+ if (match) {
62
+ const ver = match[1];
63
+ const parts = ver.split(".").map(Number);
64
+ const [vMajor = 0, vMinor = 0] = parts;
65
+ if (vMajor === bMajor && vMinor >= bMinor) {
66
+ const ns = userTools[key];
67
+ if (ns != null && typeof ns === "object" && !Array.isArray(ns)) {
68
+ const fullVersion = parts.length <= 2 ? `${ver}.0` : ver;
69
+ return { namespace: ns, version: fullVersion };
70
+ }
71
+ }
72
+ }
73
+ }
74
+ // No compatible std found — produce actionable error
75
+ if (bMajor !== sMajor) {
76
+ throw new Error(`Bridge version ${version} requires a ${bMajor}.x standard library, ` +
77
+ `but the bundled std is ${bundledStdVersion} (major version ${sMajor}). ` +
78
+ `Provide a compatible std as "std@${version}" in the tools map.`);
79
+ }
80
+ throw new Error(`Bridge version ${version} requires standard library ≥ ${bMajor}.${bMinor}, ` +
81
+ `but the installed @stackables/bridge-stdlib is ${bundledStdVersion}. ` +
82
+ `Update @stackables/bridge-stdlib to ${bMajor}.${bMinor}.0 or later.`);
83
+ }
84
+ // ── Versioned handle validation ─────────────────────────────────────────────
85
+ /**
86
+ * Collect every tool reference that carries an `@version` tag from handles
87
+ * (bridge/define blocks) and deps (tool blocks).
88
+ */
89
+ export function collectVersionedHandles(instructions) {
90
+ const result = [];
91
+ for (const inst of instructions) {
92
+ if (inst.kind === "bridge" || inst.kind === "define") {
93
+ for (const h of inst.handles) {
94
+ if (h.kind === "tool" && h.version) {
95
+ result.push({ name: h.name, version: h.version });
96
+ }
97
+ }
98
+ }
99
+ if (inst.kind === "tool") {
100
+ for (const dep of inst.deps) {
101
+ if (dep.kind === "tool" && dep.version) {
102
+ result.push({ name: dep.tool, version: dep.version });
103
+ }
104
+ }
105
+ }
106
+ }
107
+ return result;
108
+ }
109
+ /**
110
+ * Check whether a dotted tool name resolves to a function in the tool map.
111
+ * Supports both namespace traversal (std.str.toUpperCase) and flat keys.
112
+ */
113
+ function hasToolFn(toolFns, name) {
114
+ if (name.includes(".")) {
115
+ const parts = name.split(".");
116
+ let current = toolFns;
117
+ for (const part of parts) {
118
+ if (current == null || typeof current !== "object") {
119
+ current = undefined;
120
+ break;
121
+ }
122
+ current = current[part];
123
+ }
124
+ if (typeof current === "function")
125
+ return true;
126
+ // flat key fallback
127
+ return typeof toolFns[name] === "function";
128
+ }
129
+ return typeof toolFns[name] === "function";
130
+ }
131
+ /**
132
+ * Check whether a versioned dotted tool name can be resolved.
133
+ *
134
+ * In addition to the standard checks (namespace traversal, flat key),
135
+ * this also checks **versioned namespace keys** in the tool map:
136
+ * - `"std.str.toLowerCase@999.1"` as a flat key
137
+ * - `"std.str@999.1"` as a namespace key containing `toLowerCase`
138
+ * - `"std@999.1"` as a namespace key, traversing to `str.toLowerCase`
139
+ */
140
+ export function hasVersionedToolFn(toolFns, name, version) {
141
+ const versionedKey = `${name}@${version}`;
142
+ // 1. Flat key or direct namespace traversal
143
+ if (hasToolFn(toolFns, versionedKey))
144
+ return true;
145
+ // 2. Versioned namespace key lookup
146
+ // For "std.str.toLowerCase" @ "999.1", try:
147
+ // toolFns["std.str@999.1"]?.toLowerCase
148
+ // toolFns["std@999.1"]?.str?.toLowerCase
149
+ if (name.includes(".")) {
150
+ const parts = name.split(".");
151
+ for (let i = parts.length - 1; i >= 1; i--) {
152
+ const nsKey = parts.slice(0, i).join(".") + "@" + version;
153
+ const remainder = parts.slice(i);
154
+ let ns = toolFns[nsKey];
155
+ if (ns != null && typeof ns === "object") {
156
+ for (const part of remainder) {
157
+ if (ns == null || typeof ns !== "object") {
158
+ ns = undefined;
159
+ break;
160
+ }
161
+ ns = ns[part];
162
+ }
163
+ if (typeof ns === "function")
164
+ return true;
165
+ }
166
+ }
167
+ }
168
+ return false;
169
+ }
170
+ /**
171
+ * Validate that all versioned tool handles can be satisfied at runtime.
172
+ *
173
+ * For each handle with `@version`:
174
+ * 1. A versioned key or versioned namespace in the tool map → satisfied
175
+ * 2. A `std.*` tool whose STD_VERSION ≥ the requested version → satisfied
176
+ * 3. Otherwise → throws with an actionable error message
177
+ *
178
+ * Call this **before** constructing the ExecutionTree to fail early.
179
+ *
180
+ * @throws Error when a versioned tool cannot be satisfied.
181
+ */
182
+ export function checkHandleVersions(instructions, toolFns, stdVersion) {
183
+ const versioned = collectVersionedHandles(instructions);
184
+ for (const { name, version } of versioned) {
185
+ // 1. Flat key, namespace traversal, or versioned namespace key
186
+ if (hasVersionedToolFn(toolFns, name, version))
187
+ continue;
188
+ // 2. For std.* tools, check if the active std satisfies the version
189
+ if (name.startsWith("std.")) {
190
+ const sParts = stdVersion.split(".").map(Number);
191
+ const vParts = version.split(".").map(Number);
192
+ const [sMajor = 0, sMinor = 0] = sParts;
193
+ const [vMajor = 0, vMinor = 0] = vParts;
194
+ if (sMajor === vMajor && sMinor >= vMinor)
195
+ continue;
196
+ throw new Error(`Tool "${name}@${version}" requires standard library ≥ ${vMajor}.${vMinor}, ` +
197
+ `but the installed @stackables/bridge-stdlib is ${stdVersion}. ` +
198
+ `Either update the stdlib or provide the tool as ` +
199
+ `"${name}@${version}" in the tools map.`);
200
+ }
201
+ // 3. Non-std tool — must be provided with a versioned key or namespace
202
+ throw new Error(`Tool "${name}@${version}" is not available. ` +
203
+ `Provide it as "${name}@${version}" in the tools map.`);
204
+ }
205
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @stackables/bridge-stdlib — Bridge standard library tools.
3
+ *
4
+ * Contains the `std` namespace tools (httpCall, string helpers, array helpers,
5
+ * audit) that ship with Bridge. Referenced in `.bridge` files as
6
+ * `std.httpCall`, `std.str.toUpperCase`, etc.
7
+ *
8
+ * Separated from core so it can be versioned independently.
9
+ */
10
+ import { audit } from "./tools/audit.ts";
11
+ import * as arrays from "./tools/arrays.ts";
12
+ import * as strings from "./tools/strings.ts";
13
+ /**
14
+ * Standard library version.
15
+ *
16
+ * The bridge `version X.Y` header declares the minimum compatible std version.
17
+ * At runtime the engine compares this constant against the bridge's declared
18
+ * version to verify compatibility (same major, equal-or-higher minor).
19
+ */
20
+ export declare const STD_VERSION = "1.5.0";
21
+ export declare const std: {
22
+ readonly str: typeof strings;
23
+ readonly arr: typeof arrays;
24
+ readonly audit: typeof audit;
25
+ readonly httpCall: import("@stackables/bridge-types").ToolCallFn;
26
+ };
27
+ /**
28
+ * All known built-in tool names as "namespace.tool" strings.
29
+ *
30
+ * Useful for LSP/IDE autocomplete and diagnostics.
31
+ */
32
+ export declare const builtinToolNames: readonly string[];
33
+ export { createHttpCall } from "./tools/http-call.ts";
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../bridge-stdlib/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AASnC,eAAO,MAAM,GAAG;;;;;CAKN,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAE7C,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @stackables/bridge-stdlib — Bridge standard library tools.
3
+ *
4
+ * Contains the `std` namespace tools (httpCall, string helpers, array helpers,
5
+ * audit) that ship with Bridge. Referenced in `.bridge` files as
6
+ * `std.httpCall`, `std.str.toUpperCase`, etc.
7
+ *
8
+ * Separated from core so it can be versioned independently.
9
+ */
10
+ import { audit } from "./tools/audit.js";
11
+ import { createHttpCall } from "./tools/http-call.js";
12
+ import * as arrays from "./tools/arrays.js";
13
+ import * as strings from "./tools/strings.js";
14
+ /**
15
+ * Standard library version.
16
+ *
17
+ * The bridge `version X.Y` header declares the minimum compatible std version.
18
+ * At runtime the engine compares this constant against the bridge's declared
19
+ * version to verify compatibility (same major, equal-or-higher minor).
20
+ */
21
+ export const STD_VERSION = "1.5.0";
22
+ /**
23
+ * Standard built-in tools — available under the `std` namespace.
24
+ *
25
+ * Referenced in `.bridge` files as `std.str.toUpperCase`, `std.arr.first`, etc.
26
+ */
27
+ const httpCallFn = createHttpCall();
28
+ export const std = {
29
+ str: strings,
30
+ arr: arrays,
31
+ audit,
32
+ httpCall: httpCallFn,
33
+ };
34
+ /**
35
+ * All known built-in tool names as "namespace.tool" strings.
36
+ *
37
+ * Useful for LSP/IDE autocomplete and diagnostics.
38
+ */
39
+ export const builtinToolNames = Object.keys(std).map((k) => `std.${k}`);
40
+ export { createHttpCall } from "./tools/http-call.js";