@stackables/bridge-core 0.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.
@@ -0,0 +1,57 @@
1
+ import type { Logger, ToolTrace, TraceLevel } from "./ExecutionTree.ts";
2
+ import type { Instruction, ToolMap } from "./types.ts";
3
+ export type ExecuteBridgeOptions = {
4
+ /** Parsed bridge instructions (from `parseBridgeDiagnostics`). */
5
+ instructions: Instruction[];
6
+ /**
7
+ * Which bridge to execute, as `"Type.field"`.
8
+ * Mirrors the `bridge Type.field { ... }` declaration.
9
+ * Example: `"Query.searchTrains"` or `"Mutation.sendEmail"`.
10
+ */
11
+ operation: string;
12
+ /** Input arguments — equivalent to GraphQL field arguments. */
13
+ input?: Record<string, unknown>;
14
+ /** Additional tools to merge with the built-in `std` namespace. */
15
+ tools?: ToolMap;
16
+ /** Context available via `with context as ctx` inside the bridge. */
17
+ context?: Record<string, unknown>;
18
+ /**
19
+ * Enable tool-call tracing.
20
+ * - `"off"` (default) — no collection, zero overhead
21
+ * - `"basic"` — tool, fn, timing, errors; no input/output
22
+ * - `"full"` — everything including input and output
23
+ */
24
+ trace?: TraceLevel;
25
+ /** Structured logger for engine events. */
26
+ logger?: Logger;
27
+ /** External abort signal — cancels execution when triggered. */
28
+ signal?: AbortSignal;
29
+ };
30
+ export type ExecuteBridgeResult<T = unknown> = {
31
+ data: T;
32
+ traces: ToolTrace[];
33
+ };
34
+ /**
35
+ * Execute a bridge operation without GraphQL.
36
+ *
37
+ * Runs a bridge file's data-wiring logic standalone — no schema, no server,
38
+ * no HTTP layer required. Useful for CLI tools, background jobs, tests, and
39
+ * any context where you want Bridge's declarative data-fetching outside of
40
+ * a GraphQL server.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { parseBridgeDiagnostics, executeBridge } from "@stackables/bridge";
45
+ * import { readFileSync } from "node:fs";
46
+ *
47
+ * const { instructions } = parseBridgeDiagnostics(readFileSync("my.bridge", "utf8"));
48
+ * const { data } = await executeBridge({
49
+ * instructions,
50
+ * operation: "Query.myField",
51
+ * input: { city: "Berlin" },
52
+ * });
53
+ * console.log(data);
54
+ * ```
55
+ */
56
+ export declare function executeBridge<T = unknown>(options: ExecuteBridgeOptions): Promise<ExecuteBridgeResult<T>>;
57
+ //# sourceMappingURL=execute-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-bridge.d.ts","sourceRoot":"","sources":["../src/execute-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,kEAAkE;IAClE,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC7C,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CAAC,CAAC,GAAG,OAAO,EAC7C,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CA+BjC"}
@@ -0,0 +1,45 @@
1
+ import { ExecutionTree, TraceCollector } from "./ExecutionTree.js";
2
+ import { SELF_MODULE } from "./types.js";
3
+ import { std } from "@stackables/bridge-stdlib";
4
+ /**
5
+ * Execute a bridge operation without GraphQL.
6
+ *
7
+ * Runs a bridge file's data-wiring logic standalone — no schema, no server,
8
+ * no HTTP layer required. Useful for CLI tools, background jobs, tests, and
9
+ * any context where you want Bridge's declarative data-fetching outside of
10
+ * a GraphQL server.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { parseBridgeDiagnostics, executeBridge } from "@stackables/bridge";
15
+ * import { readFileSync } from "node:fs";
16
+ *
17
+ * const { instructions } = parseBridgeDiagnostics(readFileSync("my.bridge", "utf8"));
18
+ * const { data } = await executeBridge({
19
+ * instructions,
20
+ * operation: "Query.myField",
21
+ * input: { city: "Berlin" },
22
+ * });
23
+ * console.log(data);
24
+ * ```
25
+ */
26
+ export async function executeBridge(options) {
27
+ const { instructions, operation, input = {}, context = {} } = options;
28
+ const parts = operation.split(".");
29
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
30
+ throw new Error(`Invalid operation "${operation}" — expected "Type.field" (e.g. "Query.myField")`);
31
+ }
32
+ const [type, field] = parts;
33
+ const trunk = { module: SELF_MODULE, type, field };
34
+ const tree = new ExecutionTree(trunk, instructions, { std, ...(options.tools ?? {}) }, context);
35
+ if (options.logger)
36
+ tree.logger = options.logger;
37
+ if (options.signal)
38
+ tree.signal = options.signal;
39
+ const traceLevel = options.trace ?? "off";
40
+ if (traceLevel !== "off") {
41
+ tree.tracer = new TraceCollector(traceLevel);
42
+ }
43
+ const data = await tree.run(input);
44
+ return { data: data, traces: tree.getTraces() };
45
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @stackables/bridge-core — The Bridge runtime engine.
3
+ *
4
+ * Contains the execution engine, type system, internal tools (math, logic,
5
+ * string concat), and utilities. Given pre-parsed `Instruction[]` (JSON AST),
6
+ * you can execute a bridge without pulling in the parser (Chevrotain) or
7
+ * GraphQL dependencies.
8
+ */
9
+ export { executeBridge } from "./execute-bridge.ts";
10
+ export type { ExecuteBridgeOptions, ExecuteBridgeResult, } from "./execute-bridge.ts";
11
+ export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, } from "./ExecutionTree.ts";
12
+ export type { Logger, ToolTrace, TraceLevel } from "./ExecutionTree.ts";
13
+ 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";
15
+ export { parsePath } from "./utils.ts";
16
+ //# 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,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GACjB,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,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,IAAI,GACL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @stackables/bridge-core — The Bridge runtime engine.
3
+ *
4
+ * Contains the execution engine, type system, internal tools (math, logic,
5
+ * string concat), and utilities. Given pre-parsed `Instruction[]` (JSON AST),
6
+ * you can execute a bridge without pulling in the parser (Chevrotain) or
7
+ * GraphQL dependencies.
8
+ */
9
+ // ── Runtime engine ──────────────────────────────────────────────────────────
10
+ export { executeBridge } from "./execute-bridge.js";
11
+ // ── Execution tree (advanced) ───────────────────────────────────────────────
12
+ export { ExecutionTree, TraceCollector, BridgeAbortError, BridgePanicError, } from "./ExecutionTree.js";
13
+ // ── Types ───────────────────────────────────────────────────────────────────
14
+ export { SELF_MODULE } from "./types.js";
15
+ // ── Utilities ───────────────────────────────────────────────────────────────
16
+ export { parsePath } from "./utils.js";
@@ -0,0 +1,2 @@
1
+ export * as internal from "./internal.ts";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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
+ export * as internal from "./internal.js";
@@ -0,0 +1,71 @@
1
+ /** Add two numbers. Returns `a + b`. */
2
+ export declare function add(opts: {
3
+ a: number;
4
+ b: number;
5
+ }): number;
6
+ /** Subtract two numbers. Returns `a - b`. */
7
+ export declare function subtract(opts: {
8
+ a: number;
9
+ b: number;
10
+ }): number;
11
+ /** Multiply two numbers. Returns `a * b`. */
12
+ export declare function multiply(opts: {
13
+ a: number;
14
+ b: number;
15
+ }): number;
16
+ /** Divide two numbers. Returns `a / b`. */
17
+ export declare function divide(opts: {
18
+ a: number;
19
+ b: number;
20
+ }): number;
21
+ /** Strict equality. Returns `true` if `a === b`, `false` otherwise. */
22
+ export declare function eq(opts: {
23
+ a: any;
24
+ b: any;
25
+ }): boolean;
26
+ /** Strict inequality. Returns `true` if `a !== b`, `false` otherwise. */
27
+ export declare function neq(opts: {
28
+ a: any;
29
+ b: any;
30
+ }): boolean;
31
+ /** Greater than. Returns `true` if `a > b`, `false` otherwise. */
32
+ export declare function gt(opts: {
33
+ a: number;
34
+ b: number;
35
+ }): boolean;
36
+ /** Greater than or equal. Returns `true` if `a >= b`, `false` otherwise. */
37
+ export declare function gte(opts: {
38
+ a: number;
39
+ b: number;
40
+ }): boolean;
41
+ /** Less than. Returns `true` if `a < b`, `false` otherwise. */
42
+ export declare function lt(opts: {
43
+ a: number;
44
+ b: number;
45
+ }): boolean;
46
+ /** Less than or equal. Returns `true` if `a <= b`, `false` otherwise. */
47
+ export declare function lte(opts: {
48
+ a: number;
49
+ b: number;
50
+ }): boolean;
51
+ /** Logical NOT. Returns `true` if `a` is falsy. */
52
+ export declare function not(opts: {
53
+ a: any;
54
+ }): boolean;
55
+ /** Logical AND. Returns `true` if both `a` and `b` are truthy. */
56
+ export declare function and(opts: {
57
+ a: any;
58
+ b: any;
59
+ }): boolean;
60
+ /** Logical OR. Returns `true` if either `a` or `b` is truthy. */
61
+ export declare function or(opts: {
62
+ a: any;
63
+ b: any;
64
+ }): boolean;
65
+ /** String concatenation. Joins all parts into a single string. */
66
+ export declare function concat(opts: {
67
+ parts: unknown[];
68
+ }): {
69
+ value: string;
70
+ };
71
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/tools/internal.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,wBAAgB,GAAG,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE1D;AACD,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE/D;AACD,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAA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,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"}
@@ -0,0 +1,59 @@
1
+ /** Add two numbers. Returns `a + b`. */
2
+ export function add(opts) {
3
+ return Number(opts.a) + Number(opts.b);
4
+ }
5
+ /** Subtract two numbers. Returns `a - b`. */
6
+ export function subtract(opts) {
7
+ return Number(opts.a) - Number(opts.b);
8
+ }
9
+ /** Multiply two numbers. Returns `a * b`. */
10
+ export function multiply(opts) {
11
+ return Number(opts.a) * Number(opts.b);
12
+ }
13
+ /** Divide two numbers. Returns `a / b`. */
14
+ export function divide(opts) {
15
+ return Number(opts.a) / Number(opts.b);
16
+ }
17
+ /** Strict equality. Returns `true` if `a === b`, `false` otherwise. */
18
+ export function eq(opts) {
19
+ return opts.a === opts.b;
20
+ }
21
+ /** Strict inequality. Returns `true` if `a !== b`, `false` otherwise. */
22
+ export function neq(opts) {
23
+ return opts.a !== opts.b;
24
+ }
25
+ /** Greater than. Returns `true` if `a > b`, `false` otherwise. */
26
+ export function gt(opts) {
27
+ return Number(opts.a) > Number(opts.b);
28
+ }
29
+ /** Greater than or equal. Returns `true` if `a >= b`, `false` otherwise. */
30
+ export function gte(opts) {
31
+ return Number(opts.a) >= Number(opts.b);
32
+ }
33
+ /** Less than. Returns `true` if `a < b`, `false` otherwise. */
34
+ export function lt(opts) {
35
+ return Number(opts.a) < Number(opts.b);
36
+ }
37
+ /** Less than or equal. Returns `true` if `a <= b`, `false` otherwise. */
38
+ export function lte(opts) {
39
+ return Number(opts.a) <= Number(opts.b);
40
+ }
41
+ /** Logical NOT. Returns `true` if `a` is falsy. */
42
+ export function not(opts) {
43
+ return !opts.a;
44
+ }
45
+ /** Logical AND. Returns `true` if both `a` and `b` are truthy. */
46
+ export function and(opts) {
47
+ return Boolean(opts.a) && Boolean(opts.b);
48
+ }
49
+ /** Logical OR. Returns `true` if either `a` or `b` is truthy. */
50
+ export function or(opts) {
51
+ return Boolean(opts.a) || Boolean(opts.b);
52
+ }
53
+ /** String concatenation. Joins all parts into a single string. */
54
+ export function concat(opts) {
55
+ const result = (opts.parts ?? [])
56
+ .map((v) => (v == null ? "" : String(v)))
57
+ .join("");
58
+ return { value: result };
59
+ }
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Structured node reference — identifies a specific data point in the execution graph.
3
+ *
4
+ * Every wire has a "from" and "to", each described by a NodeRef.
5
+ * The trunk (module + type + field + instance) identifies the node,
6
+ * while path drills into its data.
7
+ */
8
+ export type NodeRef = {
9
+ /** Module identifier: "hereapi", "sendgrid", "zillow", or SELF_MODULE */
10
+ module: string;
11
+ /** GraphQL type ("Query" | "Mutation") or "Tools" for tool functions */
12
+ type: string;
13
+ /** Field or function name: "geocode", "search", "centsToUsd" */
14
+ field: string;
15
+ /** Instance number for tool calls (1, 2, ...) */
16
+ instance?: number;
17
+ /** References the current array element in a shadow tree (for per-element mapping) */
18
+ element?: boolean;
19
+ /** Path into the data: ["items", "0", "position", "lat"] */
20
+ path: string[];
21
+ /** True when the first `?.` is right after the root (e.g., `api?.data`) */
22
+ rootSafe?: boolean;
23
+ /** Per-segment safety flags (same length as `path`); true = `?.` before that segment */
24
+ pathSafe?: boolean[];
25
+ };
26
+ /**
27
+ * A wire connects a data source (from) to a data sink (to).
28
+ * Execution is pull-based: when "to" is demanded, "from" is resolved.
29
+ *
30
+ * Constant wires (`=`) set a fixed value on the target.
31
+ * Pull wires (`<-`) resolve the source at runtime.
32
+ * Pipe wires (`pipe: true`) are generated by the `<- h1:h2:source` shorthand
33
+ * and route data through declared tool handles; the serializer collapses them
34
+ * back to pipe notation.
35
+ */
36
+ export type Wire = {
37
+ from: NodeRef;
38
+ to: NodeRef;
39
+ pipe?: true;
40
+ safe?: true;
41
+ falsyFallbackRefs?: NodeRef[];
42
+ falsyFallback?: string;
43
+ falsyControl?: ControlFlowInstruction;
44
+ nullishFallback?: string;
45
+ nullishFallbackRef?: NodeRef;
46
+ nullishControl?: ControlFlowInstruction;
47
+ catchFallback?: string;
48
+ catchFallbackRef?: NodeRef;
49
+ catchControl?: ControlFlowInstruction;
50
+ } | {
51
+ value: string;
52
+ to: NodeRef;
53
+ } | {
54
+ cond: NodeRef;
55
+ thenRef?: NodeRef;
56
+ thenValue?: string;
57
+ elseRef?: NodeRef;
58
+ elseValue?: string;
59
+ to: NodeRef;
60
+ falsyFallbackRefs?: NodeRef[];
61
+ falsyFallback?: string;
62
+ falsyControl?: ControlFlowInstruction;
63
+ nullishFallback?: string;
64
+ nullishFallbackRef?: NodeRef;
65
+ nullishControl?: ControlFlowInstruction;
66
+ catchFallback?: string;
67
+ catchFallbackRef?: NodeRef;
68
+ catchControl?: ControlFlowInstruction;
69
+ } | {
70
+ /** Short-circuit logical AND: evaluate left first, only evaluate right if left is truthy */
71
+ condAnd: {
72
+ leftRef: NodeRef;
73
+ rightRef?: NodeRef;
74
+ rightValue?: string;
75
+ safe?: true;
76
+ rightSafe?: true;
77
+ };
78
+ to: NodeRef;
79
+ falsyFallbackRefs?: NodeRef[];
80
+ falsyFallback?: string;
81
+ falsyControl?: ControlFlowInstruction;
82
+ nullishFallback?: string;
83
+ nullishFallbackRef?: NodeRef;
84
+ nullishControl?: ControlFlowInstruction;
85
+ catchFallback?: string;
86
+ catchFallbackRef?: NodeRef;
87
+ catchControl?: ControlFlowInstruction;
88
+ } | {
89
+ /** Short-circuit logical OR: evaluate left first, only evaluate right if left is falsy */
90
+ condOr: {
91
+ leftRef: NodeRef;
92
+ rightRef?: NodeRef;
93
+ rightValue?: string;
94
+ safe?: true;
95
+ rightSafe?: true;
96
+ };
97
+ to: NodeRef;
98
+ falsyFallbackRefs?: NodeRef[];
99
+ falsyFallback?: string;
100
+ falsyControl?: ControlFlowInstruction;
101
+ nullishFallback?: string;
102
+ nullishFallbackRef?: NodeRef;
103
+ nullishControl?: ControlFlowInstruction;
104
+ catchFallback?: string;
105
+ catchFallbackRef?: NodeRef;
106
+ catchControl?: ControlFlowInstruction;
107
+ };
108
+ /**
109
+ * Bridge definition — wires one GraphQL field to its data sources.
110
+ */
111
+ export type Bridge = {
112
+ kind: "bridge";
113
+ /** GraphQL type: "Query" | "Mutation" */
114
+ type: string;
115
+ /** GraphQL field name */
116
+ field: string;
117
+ /** Declared data sources and their wire handles */
118
+ handles: HandleBinding[];
119
+ /** Connection wires */
120
+ wires: Wire[];
121
+ /**
122
+ * When set, this bridge was declared with the passthrough shorthand:
123
+ * `bridge Type.field with <name>`. The value is the define/tool name.
124
+ */
125
+ passthrough?: string;
126
+ /** Handles to eagerly evaluate (e.g. side-effect tools).
127
+ * Critical by default — a forced handle that throws aborts the bridge.
128
+ * Add `catchError: true` (written as `force <handle> ?? null`) to
129
+ * swallow the error for fire-and-forget side-effects. */
130
+ forces?: Array<{
131
+ handle: string;
132
+ module: string;
133
+ type: string;
134
+ field: string;
135
+ instance?: number;
136
+ /** When true, errors from this forced handle are silently caught (`?? null`). */
137
+ catchError?: true;
138
+ }>;
139
+ arrayIterators?: Record<string, string>;
140
+ pipeHandles?: Array<{
141
+ key: string;
142
+ handle: string;
143
+ baseTrunk: {
144
+ module: string;
145
+ type: string;
146
+ field: string;
147
+ instance?: number;
148
+ };
149
+ }>;
150
+ };
151
+ /**
152
+ * A handle binding — declares a named data source available in a bridge.
153
+ *
154
+ * Every wire reference in the bridge body must trace back to one of these.
155
+ */
156
+ export type HandleBinding = {
157
+ handle: string;
158
+ kind: "tool";
159
+ name: string;
160
+ } | {
161
+ handle: string;
162
+ kind: "input";
163
+ } | {
164
+ handle: string;
165
+ kind: "output";
166
+ } | {
167
+ handle: string;
168
+ kind: "context";
169
+ } | {
170
+ handle: string;
171
+ kind: "const";
172
+ } | {
173
+ handle: string;
174
+ kind: "define";
175
+ name: string;
176
+ };
177
+ /** Internal module identifier for the bridge's own trunk (input args + output fields) */
178
+ export declare const SELF_MODULE = "_";
179
+ /**
180
+ * Tool definition — a declared tool with wires, dependencies, and optional inheritance.
181
+ *
182
+ * Tool blocks define reusable, composable API call configurations:
183
+ * tool hereapi httpCall — root tool with function name
184
+ * tool hereapi.geocode extends hereapi — child inherits parent wires
185
+ *
186
+ * The engine resolves extends chains, merges wires, and calls the
187
+ * registered tool function with the fully-built input object.
188
+ */
189
+ export type ToolDef = {
190
+ kind: "tool";
191
+ /** Tool name: "hereapi", "sendgrid.send", "authService" */
192
+ name: string;
193
+ /** Function name — looked up in the tools map. Omitted when extends is used. */
194
+ fn?: string;
195
+ /** Parent tool name — inherits fn, deps, and wires */
196
+ extends?: string;
197
+ /** Dependencies declared via `with` inside the tool block */
198
+ deps: ToolDep[];
199
+ /** Wires: constants (`=`) and pulls (`<-`) defining the tool's input */
200
+ wires: ToolWire[];
201
+ };
202
+ /**
203
+ * A dependency declared inside a tool block.
204
+ *
205
+ * with context — brings the full GraphQL context into scope
206
+ * with authService as auth — brings another tool's output into scope
207
+ */
208
+ export type ToolDep = {
209
+ kind: "context";
210
+ handle: string;
211
+ } | {
212
+ kind: "tool";
213
+ handle: string;
214
+ tool: string;
215
+ } | {
216
+ kind: "const";
217
+ handle: string;
218
+ };
219
+ /**
220
+ * A wire in a tool block — either a constant value, a pull from a dependency,
221
+ * or an error fallback.
222
+ *
223
+ * Examples:
224
+ * baseUrl = "https://api.sendgrid.com/v3" → constant
225
+ * method = POST → constant (unquoted)
226
+ * headers.Authorization <- ctx.sendgrid.token → pull from context
227
+ * headers.Authorization <- auth.access_token → pull from tool dep
228
+ * on error = { "lat": 0, "lon": 0 } → constant fallback
229
+ * on error <- ctx.fallbacks.geo → pull fallback from context
230
+ */
231
+ export type ToolWire = {
232
+ target: string;
233
+ kind: "constant";
234
+ value: string;
235
+ } | {
236
+ target: string;
237
+ kind: "pull";
238
+ source: string;
239
+ } | {
240
+ kind: "onError";
241
+ value: string;
242
+ } | {
243
+ kind: "onError";
244
+ source: string;
245
+ };
246
+ /**
247
+ * Context passed to every tool function as the second argument.
248
+ *
249
+ * Provides access to engine services (logger, etc.) without polluting the
250
+ * input object. Tools that don't need it simply ignore the second arg.
251
+ */
252
+ export type { ToolContext, ToolCallFn, ToolMap, CacheStore, } from "@stackables/bridge-types";
253
+ /**
254
+ * Explicit control flow instruction — used on the right side of fallback
255
+ * gates (`||`, `??`, `catch`) to influence execution.
256
+ *
257
+ * - `throw` — raises a standard Error with the given message
258
+ * - `panic` — raises a BridgePanicError that bypasses all error boundaries
259
+ * - `continue` — skips the current array element (sentinel value)
260
+ * - `break` — halts array iteration (sentinel value)
261
+ */
262
+ export type ControlFlowInstruction = {
263
+ kind: "throw";
264
+ message: string;
265
+ } | {
266
+ kind: "panic";
267
+ message: string;
268
+ } | {
269
+ kind: "continue";
270
+ } | {
271
+ kind: "break";
272
+ };
273
+ /**
274
+ * Named constant definition — a reusable value defined in the bridge file.
275
+ *
276
+ * Constants are available in bridge blocks via `with const as c` and in tool
277
+ * blocks via `with const`. The engine collects all ConstDef instructions into
278
+ * a single namespace object keyed by name.
279
+ *
280
+ * Examples:
281
+ * const fallbackGeo = { "lat": 0, "lon": 0 }
282
+ * const defaultCurrency = "EUR"
283
+ */
284
+ export type ConstDef = {
285
+ kind: "const";
286
+ /** Constant name — used as the key in the const namespace */
287
+ name: string;
288
+ /** Raw JSON string — parsed at runtime when accessed */
289
+ value: string;
290
+ };
291
+ /** Union of all instruction types */
292
+ export type Instruction = Bridge | ToolDef | ConstDef | DefineDef;
293
+ /**
294
+ * Define block — a reusable named subgraph (pipeline / macro).
295
+ *
296
+ * At parse time a define is stored as a template. When a bridge declares
297
+ * `with <define> as <handle>`, the define's handles and wires are inlined
298
+ * into the bridge with namespaced identifiers for isolation.
299
+ *
300
+ * Example:
301
+ * define secureProfile {
302
+ * with userApi as api
303
+ * with input as i
304
+ * with output as o
305
+ * api.id <- i.userId
306
+ * o.name <- api.login
307
+ * }
308
+ */
309
+ export type DefineDef = {
310
+ kind: "define";
311
+ /** Define name — referenced in bridge `with` declarations */
312
+ name: string;
313
+ /** Declared handles (tools, input, output, etc.) */
314
+ handles: HandleBinding[];
315
+ /** Connection wires (same format as Bridge wires) */
316
+ wires: Wire[];
317
+ /** Array iterators (same as Bridge) */
318
+ arrayIterators?: Record<string, string>;
319
+ /** Pipe fork registry (same as Bridge) */
320
+ pipeHandles?: Bridge["pipeHandles"];
321
+ };
322
+ //# sourceMappingURL=types.d.ts.map
@@ -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,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,sBAAsB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CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qCAAqC;AACrC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,qDAAqD;IACrD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,uCAAuC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;CACrC,CAAC"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ /** Internal module identifier for the bridge's own trunk (input args + output fields) */
2
+ export const SELF_MODULE = "_";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared utilities for the Bridge runtime.
3
+ */
4
+ /**
5
+ * Split a dotted path string into path segments, expanding array indices.
6
+ * e.g. "items[0].name" → ["items", "0", "name"]
7
+ */
8
+ export declare function parsePath(text: string): string[];
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -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"}
package/build/utils.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Shared utilities for the Bridge runtime.
3
+ */
4
+ /**
5
+ * Split a dotted path string into path segments, expanding array indices.
6
+ * e.g. "items[0].name" → ["items", "0", "name"]
7
+ */
8
+ export function parsePath(text) {
9
+ const parts = [];
10
+ for (const segment of text.split(".")) {
11
+ const match = segment.match(/^([^[]+)(?:\[(\d*)\])?$/);
12
+ if (match) {
13
+ parts.push(match[1]);
14
+ if (match[2] !== undefined && match[2] !== "") {
15
+ parts.push(match[2]);
16
+ }
17
+ }
18
+ else {
19
+ parts.push(segment);
20
+ }
21
+ }
22
+ return parts;
23
+ }