@bian-womp/spark-graph 0.3.45 → 0.3.47
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/lib/cjs/index.cjs +14 -15
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/core/types.d.ts +2 -1
- package/lib/cjs/src/core/types.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/cjs/src/runtime/components/NodeExecutor.d.ts.map +1 -1
- package/lib/cjs/src/runtime/components/RunContextManager.d.ts +2 -1
- package/lib/cjs/src/runtime/components/RunContextManager.d.ts.map +1 -1
- package/lib/esm/index.js +14 -15
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/core/types.d.ts +2 -1
- package/lib/esm/src/core/types.d.ts.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/src/runtime/components/NodeExecutor.d.ts.map +1 -1
- package/lib/esm/src/runtime/components/RunContextManager.d.ts +2 -1
- package/lib/esm/src/runtime/components/RunContextManager.d.ts.map +1 -1
- package/lib/src/builder/GraphBuilder.d.ts +43 -0
- package/lib/src/builder/GraphBuilder.d.ts.map +1 -0
- package/lib/src/builder/GraphBuilder.js +284 -0
- package/lib/src/builder/GraphBuilder.js.map +1 -0
- package/lib/src/builder/Registry.d.ts +93 -0
- package/lib/src/builder/Registry.d.ts.map +1 -0
- package/lib/src/builder/Registry.js +393 -0
- package/lib/src/builder/Registry.js.map +1 -0
- package/lib/src/core/categories.d.ts +22 -0
- package/lib/src/core/categories.d.ts.map +1 -0
- package/lib/src/core/categories.js +2 -0
- package/lib/src/core/categories.js.map +1 -0
- package/lib/src/core/order.d.ts +7 -0
- package/lib/src/core/order.d.ts.map +1 -0
- package/lib/src/core/order.js +66 -0
- package/lib/src/core/order.js.map +1 -0
- package/lib/src/core/type-utils.d.ts +29 -0
- package/lib/src/core/type-utils.d.ts.map +1 -0
- package/lib/src/core/type-utils.js +97 -0
- package/lib/src/core/type-utils.js.map +1 -0
- package/lib/src/core/types.d.ts +92 -0
- package/lib/src/core/types.d.ts.map +1 -0
- package/lib/src/core/types.js +2 -0
- package/lib/src/core/types.js.map +1 -0
- package/lib/src/examples/arrays.d.ts +5 -0
- package/lib/src/examples/arrays.d.ts.map +1 -0
- package/lib/src/examples/arrays.js +49 -0
- package/lib/src/examples/arrays.js.map +1 -0
- package/lib/src/examples/async.d.ts +5 -0
- package/lib/src/examples/async.d.ts.map +1 -0
- package/lib/src/examples/async.js +91 -0
- package/lib/src/examples/async.js.map +1 -0
- package/lib/src/examples/progress.d.ts +5 -0
- package/lib/src/examples/progress.d.ts.map +1 -0
- package/lib/src/examples/progress.js +51 -0
- package/lib/src/examples/progress.js.map +1 -0
- package/lib/src/examples/run.d.ts +2 -0
- package/lib/src/examples/run.d.ts.map +1 -0
- package/lib/src/examples/run.js +32 -0
- package/lib/src/examples/run.js.map +1 -0
- package/lib/src/examples/runMode.d.ts +2 -0
- package/lib/src/examples/runMode.d.ts.map +1 -0
- package/lib/src/examples/runMode.js +223 -0
- package/lib/src/examples/runMode.js.map +1 -0
- package/lib/src/examples/shared.d.ts +5 -0
- package/lib/src/examples/shared.d.ts.map +1 -0
- package/lib/src/examples/shared.js +49 -0
- package/lib/src/examples/shared.js.map +1 -0
- package/lib/src/examples/simple.d.ts +5 -0
- package/lib/src/examples/simple.d.ts.map +1 -0
- package/lib/src/examples/simple.js +79 -0
- package/lib/src/examples/simple.js.map +1 -0
- package/lib/src/examples/snapshot.d.ts +4 -0
- package/lib/src/examples/snapshot.d.ts.map +1 -0
- package/lib/src/examples/snapshot.js +58 -0
- package/lib/src/examples/snapshot.js.map +1 -0
- package/lib/src/examples/validation.d.ts +5 -0
- package/lib/src/examples/validation.d.ts.map +1 -0
- package/lib/src/examples/validation.js +105 -0
- package/lib/src/examples/validation.js.map +1 -0
- package/lib/src/index.d.ts +27 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +19 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/misc/base.d.ts +51 -0
- package/lib/src/misc/base.d.ts.map +1 -0
- package/lib/src/misc/base.js +1122 -0
- package/lib/src/misc/base.js.map +1 -0
- package/lib/src/misc/utils/json.d.ts +22 -0
- package/lib/src/misc/utils/json.d.ts.map +1 -0
- package/lib/src/misc/utils/json.js +239 -0
- package/lib/src/misc/utils/json.js.map +1 -0
- package/lib/src/misc/utils/merge.d.ts +51 -0
- package/lib/src/misc/utils/merge.d.ts.map +1 -0
- package/lib/src/misc/utils/merge.js +600 -0
- package/lib/src/misc/utils/merge.js.map +1 -0
- package/lib/src/plugins/composite.d.ts +22 -0
- package/lib/src/plugins/composite.d.ts.map +1 -0
- package/lib/src/plugins/composite.js +59 -0
- package/lib/src/plugins/composite.js.map +1 -0
- package/lib/src/plugins/compute.d.ts +5 -0
- package/lib/src/plugins/compute.d.ts.map +1 -0
- package/lib/src/plugins/compute.js +39 -0
- package/lib/src/plugins/compute.js.map +1 -0
- package/lib/src/runtime/Engine.d.ts +28 -0
- package/lib/src/runtime/Engine.d.ts.map +1 -0
- package/lib/src/runtime/Engine.js +2 -0
- package/lib/src/runtime/Engine.js.map +1 -0
- package/lib/src/runtime/GraphLifecycleApi.d.ts +46 -0
- package/lib/src/runtime/GraphLifecycleApi.d.ts.map +1 -0
- package/lib/src/runtime/GraphLifecycleApi.js +2 -0
- package/lib/src/runtime/GraphLifecycleApi.js.map +1 -0
- package/lib/src/runtime/GraphRuntime.d.ts +94 -0
- package/lib/src/runtime/GraphRuntime.d.ts.map +1 -0
- package/lib/src/runtime/GraphRuntime.js +729 -0
- package/lib/src/runtime/GraphRuntime.js.map +1 -0
- package/lib/src/runtime/LocalEngine.d.ts +45 -0
- package/lib/src/runtime/LocalEngine.d.ts.map +1 -0
- package/lib/src/runtime/LocalEngine.js +89 -0
- package/lib/src/runtime/LocalEngine.js.map +1 -0
- package/lib/src/runtime/components/EdgePropagator.d.ts +101 -0
- package/lib/src/runtime/components/EdgePropagator.d.ts.map +1 -0
- package/lib/src/runtime/components/EdgePropagator.js +372 -0
- package/lib/src/runtime/components/EdgePropagator.js.map +1 -0
- package/lib/src/runtime/components/EventEmitter.d.ts +12 -0
- package/lib/src/runtime/components/EventEmitter.d.ts.map +1 -0
- package/lib/src/runtime/components/EventEmitter.js +33 -0
- package/lib/src/runtime/components/EventEmitter.js.map +1 -0
- package/lib/src/runtime/components/Graph.d.ts +211 -0
- package/lib/src/runtime/components/Graph.d.ts.map +1 -0
- package/lib/src/runtime/components/Graph.js +468 -0
- package/lib/src/runtime/components/Graph.js.map +1 -0
- package/lib/src/runtime/components/HandleResolver.d.ts +36 -0
- package/lib/src/runtime/components/HandleResolver.d.ts.map +1 -0
- package/lib/src/runtime/components/HandleResolver.js +231 -0
- package/lib/src/runtime/components/HandleResolver.js.map +1 -0
- package/lib/src/runtime/components/NodeExecutor.d.ts +110 -0
- package/lib/src/runtime/components/NodeExecutor.d.ts.map +1 -0
- package/lib/src/runtime/components/NodeExecutor.js +659 -0
- package/lib/src/runtime/components/NodeExecutor.js.map +1 -0
- package/lib/src/runtime/components/RunContextManager.d.ts +86 -0
- package/lib/src/runtime/components/RunContextManager.d.ts.map +1 -0
- package/lib/src/runtime/components/RunContextManager.js +302 -0
- package/lib/src/runtime/components/RunContextManager.js.map +1 -0
- package/lib/src/runtime/components/RuntimeValidatorManager.d.ts +31 -0
- package/lib/src/runtime/components/RuntimeValidatorManager.d.ts.map +1 -0
- package/lib/src/runtime/components/RuntimeValidatorManager.js +55 -0
- package/lib/src/runtime/components/RuntimeValidatorManager.js.map +1 -0
- package/lib/src/runtime/components/graph-utils.d.ts +33 -0
- package/lib/src/runtime/components/graph-utils.d.ts.map +1 -0
- package/lib/src/runtime/components/graph-utils.js +292 -0
- package/lib/src/runtime/components/graph-utils.js.map +1 -0
- package/lib/src/runtime/components/interfaces.d.ts +54 -0
- package/lib/src/runtime/components/interfaces.d.ts.map +1 -0
- package/lib/src/runtime/components/interfaces.js +2 -0
- package/lib/src/runtime/components/interfaces.js.map +1 -0
- package/lib/src/runtime/components/types.d.ts +55 -0
- package/lib/src/runtime/components/types.d.ts.map +1 -0
- package/lib/src/runtime/components/types.js +2 -0
- package/lib/src/runtime/components/types.js.map +1 -0
- package/lib/src/runtime/utils.d.ts +67 -0
- package/lib/src/runtime/utils.d.ts.map +1 -0
- package/lib/src/runtime/utils.js +137 -0
- package/lib/src/runtime/utils.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { getInputDeclaredTypes, unwrapTypeId, unwrapValue, mergeInputHandleDescriptors, typed, } from "../../core/type-utils";
|
|
2
|
+
import { isPromise } from "../utils";
|
|
3
|
+
export function tryHandleResolving(def, registry, environment) {
|
|
4
|
+
const out = new Map();
|
|
5
|
+
const pending = new Set();
|
|
6
|
+
for (const n of def.nodes) {
|
|
7
|
+
const desc = registry.nodes.get(n.typeId);
|
|
8
|
+
if (!desc)
|
|
9
|
+
continue;
|
|
10
|
+
const overrideInputs = n.resolvedHandles?.inputs;
|
|
11
|
+
const overrideOutputs = n.resolvedHandles?.outputs;
|
|
12
|
+
const overrideDefaults = n.resolvedHandles?.inputDefaults;
|
|
13
|
+
// Resolve dynamic handles if available (initial pass: inputs may be undefined)
|
|
14
|
+
let dyn = {};
|
|
15
|
+
try {
|
|
16
|
+
if (typeof desc.resolveHandles === "function") {
|
|
17
|
+
const maybe = desc.resolveHandles({
|
|
18
|
+
nodeId: n.nodeId,
|
|
19
|
+
environment: environment || {},
|
|
20
|
+
params: n.params,
|
|
21
|
+
inputs: undefined,
|
|
22
|
+
});
|
|
23
|
+
// Only use sync results here; async results are applied via recompute later
|
|
24
|
+
if (isPromise(maybe)) {
|
|
25
|
+
// mark node as pending async recompute
|
|
26
|
+
pending.add(n.nodeId);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
dyn = maybe || {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// ignore dynamic resolution errors at this stage
|
|
35
|
+
}
|
|
36
|
+
// Merge base with dynamic and overrides (allow partial resolvedHandles)
|
|
37
|
+
// Merge inputs properly, handling metadata
|
|
38
|
+
const inputs = {};
|
|
39
|
+
// First, add all static handles
|
|
40
|
+
if (desc.inputs) {
|
|
41
|
+
for (const [handle, staticDesc] of Object.entries(desc.inputs)) {
|
|
42
|
+
inputs[handle] = staticDesc;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Then, merge dynamic handles
|
|
46
|
+
if (dyn.inputs) {
|
|
47
|
+
for (const [handle, dynamicDesc] of Object.entries(dyn.inputs)) {
|
|
48
|
+
const staticDesc = desc.inputs?.[handle];
|
|
49
|
+
const merged = mergeInputHandleDescriptors(staticDesc, dynamicDesc);
|
|
50
|
+
if (merged) {
|
|
51
|
+
inputs[handle] = merged;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Finally, merge overrides
|
|
56
|
+
if (overrideInputs) {
|
|
57
|
+
for (const [handle, overrideDesc] of Object.entries(overrideInputs)) {
|
|
58
|
+
const existingDesc = inputs[handle];
|
|
59
|
+
const merged = mergeInputHandleDescriptors(existingDesc, overrideDesc);
|
|
60
|
+
if (merged) {
|
|
61
|
+
inputs[handle] = merged;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const outputs = {
|
|
66
|
+
...desc.outputs,
|
|
67
|
+
...dyn.outputs,
|
|
68
|
+
...overrideOutputs,
|
|
69
|
+
};
|
|
70
|
+
const inputDefaults = {
|
|
71
|
+
...desc.inputDefaults,
|
|
72
|
+
...dyn.inputDefaults,
|
|
73
|
+
...overrideDefaults,
|
|
74
|
+
};
|
|
75
|
+
out.set(n.nodeId, { inputs, outputs, inputDefaults });
|
|
76
|
+
}
|
|
77
|
+
return { resolved: out, pending };
|
|
78
|
+
}
|
|
79
|
+
export function buildEdges(def, registry, resolvedByNode) {
|
|
80
|
+
return def.edges.map((e) => {
|
|
81
|
+
const srcNode = def.nodes.find((n) => n.nodeId === e.source.nodeId);
|
|
82
|
+
const dstNode = def.nodes.find((n) => n.nodeId === e.target.nodeId);
|
|
83
|
+
const { srcDeclared, dstDeclared } = extractEdgeTypes(e.source.nodeId, e.source.handle, e.target.nodeId, e.target.handle, resolvedByNode);
|
|
84
|
+
const { convert, convertAsync } = buildEdgeConverters(srcDeclared, dstDeclared, registry, `buildEdges: ${srcNode?.typeId || ""}.${e.source.nodeId}.${e.source.handle} -> ${dstNode?.typeId || ""}.${e.target.nodeId}.${e.target.handle}`);
|
|
85
|
+
return {
|
|
86
|
+
id: e.id,
|
|
87
|
+
source: { ...e.source },
|
|
88
|
+
target: { ...e.target },
|
|
89
|
+
typeId: e.typeId, // Preserve original (may be undefined)
|
|
90
|
+
convert,
|
|
91
|
+
convertAsync,
|
|
92
|
+
srcUnionTypes: Array.isArray(srcDeclared) ? [...srcDeclared] : undefined,
|
|
93
|
+
dstDeclared,
|
|
94
|
+
stats: { runs: 0, inFlight: false, progress: 0 },
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Extract edge type information from resolved handles
|
|
100
|
+
* Used by both buildEdges and updateNodeHandles to avoid duplication
|
|
101
|
+
* Now supports union types on both source (output) and destination (input) handles
|
|
102
|
+
*/
|
|
103
|
+
export function extractEdgeTypes(sourceNodeId, sourceHandle, targetNodeId, targetHandle, resolvedByNode) {
|
|
104
|
+
const srcResolved = resolvedByNode.get(sourceNodeId);
|
|
105
|
+
const dstResolved = resolvedByNode.get(targetNodeId);
|
|
106
|
+
const srcDeclared = srcResolved
|
|
107
|
+
? srcResolved.outputs[sourceHandle]
|
|
108
|
+
: undefined;
|
|
109
|
+
const dstDeclared = dstResolved
|
|
110
|
+
? getInputDeclaredTypes(dstResolved.inputs, targetHandle)
|
|
111
|
+
: undefined;
|
|
112
|
+
return {
|
|
113
|
+
srcDeclared,
|
|
114
|
+
dstDeclared,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Static helper: build edge converters for type coercion
|
|
118
|
+
// Now supports union types on both source (output) and destination (input) handles
|
|
119
|
+
export function buildEdgeConverters(srcDeclared, dstDeclared, registry, edgeLabel) {
|
|
120
|
+
if (!dstDeclared || !srcDeclared) {
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
const isSrcUnion = Array.isArray(srcDeclared);
|
|
124
|
+
const srcTypes = isSrcUnion ? srcDeclared : [srcDeclared];
|
|
125
|
+
const isDstUnion = Array.isArray(dstDeclared);
|
|
126
|
+
const dstTypes = isDstUnion ? dstDeclared : [dstDeclared];
|
|
127
|
+
// Helper to compare coercion costs (sync preferred, then fewer steps)
|
|
128
|
+
const compareCost = (a, b) => {
|
|
129
|
+
// Prefer sync over async
|
|
130
|
+
if (a.kind === "sync" && b.kind === "async")
|
|
131
|
+
return -1;
|
|
132
|
+
if (a.kind === "async" && b.kind === "sync")
|
|
133
|
+
return 1;
|
|
134
|
+
// If same kind, prefer fewer edges
|
|
135
|
+
if (a.cost.edges !== b.cost.edges)
|
|
136
|
+
return a.cost.edges - b.cost.edges;
|
|
137
|
+
// If same edges, prefer fewer async steps
|
|
138
|
+
return a.cost.async - b.cost.async;
|
|
139
|
+
};
|
|
140
|
+
// Helper to find the best coercion from a source type to any destination type
|
|
141
|
+
const getCoercion = (srcTypeId) => {
|
|
142
|
+
const candidates = [];
|
|
143
|
+
// Try all destination types and collect valid coercions
|
|
144
|
+
for (const dstTypeId of dstTypes) {
|
|
145
|
+
const coercion = registry.resolveCoercion(srcTypeId, dstTypeId);
|
|
146
|
+
if (coercion) {
|
|
147
|
+
candidates.push({
|
|
148
|
+
dstType: dstTypeId,
|
|
149
|
+
coercion,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (candidates.length === 0)
|
|
154
|
+
return null;
|
|
155
|
+
// Select best by cost: sync preferred, then fewer edges, then fewer async steps
|
|
156
|
+
const best = candidates.reduce((best, cur) => {
|
|
157
|
+
return compareCost(cur.coercion, best.coercion) < 0 ? cur : best;
|
|
158
|
+
});
|
|
159
|
+
if (best.coercion.kind === "sync") {
|
|
160
|
+
return {
|
|
161
|
+
kind: "sync",
|
|
162
|
+
convert: best.coercion.convert,
|
|
163
|
+
dstType: best.dstType,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return {
|
|
168
|
+
kind: "async",
|
|
169
|
+
convert: (v) => v, // placeholder, not used for async
|
|
170
|
+
convertAsync: best.coercion.convertAsync,
|
|
171
|
+
dstType: best.dstType,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
// Resolve coercions for all source types
|
|
176
|
+
const coercions = srcTypes.map(getCoercion);
|
|
177
|
+
const hasAsync = coercions.some((r) => r?.kind === "async");
|
|
178
|
+
// Helper to extract and validate typed output for unions
|
|
179
|
+
const extractPayload = (v) => {
|
|
180
|
+
const typeId = unwrapTypeId(v);
|
|
181
|
+
const payload = unwrapValue(v);
|
|
182
|
+
if (isSrcUnion) {
|
|
183
|
+
if (!typeId) {
|
|
184
|
+
throw new Error(`Typed output required for union source (${edgeLabel}); allowed: ${srcTypes.join("|")}`);
|
|
185
|
+
}
|
|
186
|
+
if (!srcTypes.includes(typeId)) {
|
|
187
|
+
throw new Error(`Invalid typed output ${typeId} (${edgeLabel}); allowed: ${srcTypes.join("|")}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (typeId) {
|
|
191
|
+
// Warn if typed output is used for non-union source
|
|
192
|
+
console.warn(`Typed output ${typeId} is fed even though source is not union (${edgeLabel}): ${srcDeclared} -> ${dstDeclared}`);
|
|
193
|
+
}
|
|
194
|
+
return { typeId: typeId || srcTypes[0], payload };
|
|
195
|
+
};
|
|
196
|
+
const wrapIfDstUnion = (dstType, val) => {
|
|
197
|
+
if (!isDstUnion || !dstType)
|
|
198
|
+
return val;
|
|
199
|
+
return typed(dstType, val);
|
|
200
|
+
};
|
|
201
|
+
if (hasAsync) {
|
|
202
|
+
return {
|
|
203
|
+
convertAsync: async (v, signal) => {
|
|
204
|
+
const { typeId, payload } = extractPayload(v);
|
|
205
|
+
const res = getCoercion(typeId);
|
|
206
|
+
if (!res) {
|
|
207
|
+
const fallbackType = isDstUnion && typeId && dstTypes.includes(typeId)
|
|
208
|
+
? typeId
|
|
209
|
+
: undefined;
|
|
210
|
+
return wrapIfDstUnion(fallbackType, payload);
|
|
211
|
+
}
|
|
212
|
+
if (res.kind === "async" && res.convertAsync) {
|
|
213
|
+
const converted = await res.convertAsync(payload, signal);
|
|
214
|
+
return wrapIfDstUnion(res.dstType, converted);
|
|
215
|
+
}
|
|
216
|
+
return wrapIfDstUnion(res.dstType, res.convert(payload));
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Sync path
|
|
221
|
+
const firstCoercion = coercions.find((r) => r?.kind === "sync");
|
|
222
|
+
if (!firstCoercion) {
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
convert: (v) => {
|
|
227
|
+
const { typeId, payload } = extractPayload(v);
|
|
228
|
+
const res = getCoercion(typeId);
|
|
229
|
+
if (!res) {
|
|
230
|
+
const fallbackType = isDstUnion && typeId && dstTypes.includes(typeId)
|
|
231
|
+
? typeId
|
|
232
|
+
: undefined;
|
|
233
|
+
return wrapIfDstUnion(fallbackType, payload);
|
|
234
|
+
}
|
|
235
|
+
if (res.kind === "async") {
|
|
236
|
+
throw new Error(`Async coercion required but convert used (${edgeLabel})`);
|
|
237
|
+
}
|
|
238
|
+
const converted = res.convert(payload);
|
|
239
|
+
return wrapIfDstUnion(res.dstType, converted);
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Compute effective inputs for a node by merging real inputs with defaults.
|
|
245
|
+
* This is a shared utility used by both NodeExecutor and runtime validators.
|
|
246
|
+
*
|
|
247
|
+
* @param nodeId - The node ID to compute effective inputs for
|
|
248
|
+
* @param graph - Graph component to access node and handle information
|
|
249
|
+
* @param registry - Registry to access node type descriptors and defaults
|
|
250
|
+
* @returns Record of effective input values (real inputs merged with defaults)
|
|
251
|
+
*/
|
|
252
|
+
export function getEffectiveInputs(nodeId, graph, registry) {
|
|
253
|
+
const node = graph.getNode(nodeId);
|
|
254
|
+
if (!node)
|
|
255
|
+
return {};
|
|
256
|
+
const desc = registry.nodes.get(node.typeId);
|
|
257
|
+
if (!desc)
|
|
258
|
+
return {};
|
|
259
|
+
const resolved = graph.getResolvedHandles(nodeId);
|
|
260
|
+
const regDefaults = desc.inputDefaults ?? {};
|
|
261
|
+
const dynDefaults = resolved?.inputDefaults ?? {};
|
|
262
|
+
// Identify which handles are dynamically resolved (not in registry statics)
|
|
263
|
+
const staticHandles = new Set(Object.keys(desc.inputs ?? {}));
|
|
264
|
+
const dynamicHandles = new Set(Object.keys(resolved?.inputs ?? {}).filter((h) => !staticHandles.has(h)));
|
|
265
|
+
// Precedence: dynamic > registry
|
|
266
|
+
const mergedDefaults = {
|
|
267
|
+
...regDefaults,
|
|
268
|
+
...dynDefaults,
|
|
269
|
+
};
|
|
270
|
+
// Start with real inputs only (no defaults)
|
|
271
|
+
const effective = { ...node.inputs };
|
|
272
|
+
// Build set of inbound handles (wired inputs)
|
|
273
|
+
const inboundEdges = graph.getInboundEdges(nodeId);
|
|
274
|
+
const inbound = new Set(inboundEdges.map((e) => e.target.handle));
|
|
275
|
+
// Apply defaults only for:
|
|
276
|
+
// 1. Unbound handles that have no explicit value
|
|
277
|
+
// 2. Static handles (not dynamically resolved)
|
|
278
|
+
for (const [handle, defaultValue] of Object.entries(mergedDefaults)) {
|
|
279
|
+
if (defaultValue === undefined)
|
|
280
|
+
continue;
|
|
281
|
+
if (inbound.has(handle))
|
|
282
|
+
continue; // Don't override wired inputs
|
|
283
|
+
if (effective[handle] !== undefined)
|
|
284
|
+
continue; // Already has value
|
|
285
|
+
if (dynamicHandles.has(handle))
|
|
286
|
+
continue; // Skip defaults for dynamic handles
|
|
287
|
+
// Clone to avoid shared references
|
|
288
|
+
effective[handle] = structuredClone(defaultValue);
|
|
289
|
+
}
|
|
290
|
+
return effective;
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=graph-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-utils.js","sourceRoot":"","sources":["../../../../src/runtime/components/graph-utils.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,2BAA2B,EAC3B,KAAK,GACN,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,UAAU,kBAAkB,CAChC,GAAoB,EACpB,QAAkB,EAClB,WAAqC;IAErC,MAAM,GAAG,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,cAAc,GAAG,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC;QACjD,MAAM,eAAe,GAAG,CAAC,CAAC,eAAe,EAAE,OAAO,CAAC;QACnD,MAAM,gBAAgB,GAAG,CAAC,CAAC,eAAe,EAAE,aAAa,CAAC;QAC1D,+EAA+E;QAC/E,IAAI,GAAG,GAA6B,EAAE,CAAC;QACvC,IAAI,CAAC;YACH,IAAI,OAAO,IAAI,CAAC,cAAc,KAAK,UAAU,EA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AC,MAAM,CAAC;YAAE,SAAS,CAAC,oCAAoC;QAE9E,mCAAmC;QACnC,SAAS,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RunMode } from "@bian-womp/spark-protocol";
|
|
2
|
+
import type { RunContextId } from "./types";
|
|
3
|
+
import type { Graph } from "./Graph";
|
|
4
|
+
import type { Registry } from "../../builder/Registry";
|
|
5
|
+
/**
|
|
6
|
+
* Interface for edge propagation operations
|
|
7
|
+
*/
|
|
8
|
+
export interface IEdgePropagator {
|
|
9
|
+
propagate(srcNodeId: string, srcHandle: string, value: unknown, runContextIds?: Set<RunContextId>): void;
|
|
10
|
+
invalidateDownstream(nodeId: string): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Interface for node execution operations
|
|
14
|
+
*/
|
|
15
|
+
export interface INodeExecutor {
|
|
16
|
+
execute(nodeId: string, runContextIds?: Set<RunContextId>, resolveHandles?: boolean): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Interface for handle resolution operations
|
|
20
|
+
*/
|
|
21
|
+
export interface IHandleResolver {
|
|
22
|
+
scheduleRecomputeHandles(nodeId: string): void;
|
|
23
|
+
getPendingResolution(nodeId: string): Promise<void> | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error details returned by a runtime validator when execution should be blocked
|
|
27
|
+
*/
|
|
28
|
+
export interface RuntimeValidationError {
|
|
29
|
+
message: string;
|
|
30
|
+
code?: string;
|
|
31
|
+
details?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runtime validator function that checks current runtime state before node execution.
|
|
35
|
+
* Returns false to allow execution, or RuntimeValidationError to block execution with details.
|
|
36
|
+
*
|
|
37
|
+
* @param nodeId - The node about to execute
|
|
38
|
+
* @param graph - Graph component to access all nodes and their current state
|
|
39
|
+
* @param registry - Registry to access node type information
|
|
40
|
+
* @returns false to allow execution, or RuntimeValidationError to block with details
|
|
41
|
+
*/
|
|
42
|
+
export type RuntimeValidator = (nodeId: string, graph: Graph, registry: Registry) => false | RuntimeValidationError;
|
|
43
|
+
export interface IRuntimeValidator {
|
|
44
|
+
hasRuntimeValidationBlock(nodeId: string): RuntimeValidationError | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Interface for runtime coordination operations
|
|
48
|
+
* Implemented by GraphRuntime to coordinate cross-component operations
|
|
49
|
+
*/
|
|
50
|
+
export interface IRuntime extends IRuntimeValidator {
|
|
51
|
+
isPaused(): boolean;
|
|
52
|
+
getRunMode(): RunMode | null;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CACP,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,EACd,aAAa,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,GAChC,IAAI,CAAC;IACR,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5F;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,KACf,KAAK,GAAG,sBAAsB,CAAC;AAEpC,MAAM,WAAW,iBAAiB;IAChC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAAC;CAC1E;AAED;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,iBAAiB;IACjD,QAAQ,IAAI,OAAO,CAAC;IACpB,UAAU,IAAI,OAAO,GAAG,IAAI,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/runtime/components/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { GraphNodeDefinition, GraphEdgeDefinition, ExecutionPolicy, LogLevel } from "@bian-womp/spark-protocol";
|
|
2
|
+
import type { NodeTypeDescriptor, RuntimeEdgeStats, RuntimeNodeStats } from "../../core/types";
|
|
3
|
+
import type { CategoryRuntime } from "../../core/categories";
|
|
4
|
+
export interface RuntimeNode<State = any> extends GraphNodeDefinition {
|
|
5
|
+
inputs: Record<string, unknown>;
|
|
6
|
+
outputs: Record<string, unknown>;
|
|
7
|
+
state: State;
|
|
8
|
+
runtime: CategoryRuntime<State>;
|
|
9
|
+
lifecycle: NodeTypeDescriptor<Record<string, string>, Record<string, string>, State, any>["lifecycle"];
|
|
10
|
+
policy?: Partial<ExecutionPolicy>;
|
|
11
|
+
logLevel?: LogLevel;
|
|
12
|
+
latestRunId?: string;
|
|
13
|
+
runSeq: number;
|
|
14
|
+
activeControllers: Set<AbortController>;
|
|
15
|
+
controllerRunIds: Map<AbortController, string>;
|
|
16
|
+
snapshotCancelledRunIds?: Set<string>;
|
|
17
|
+
queue: ExecutionPlan[];
|
|
18
|
+
stats: RuntimeNodeStats;
|
|
19
|
+
activeRunContextIds: Set<string>;
|
|
20
|
+
lastScheduledAt?: number;
|
|
21
|
+
lastInputAt?: Record<string, number>;
|
|
22
|
+
lastSuccessAt?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Readonly version of RuntimeNode for external access.
|
|
26
|
+
* Prevents accidental modifications from outside Graph class.
|
|
27
|
+
*/
|
|
28
|
+
export type ReadonlyRuntimeNode<State = any> = Readonly<Omit<RuntimeNode<State>, "inputs" | "outputs" | "state" | "stats" | "lastInputAt">> & {
|
|
29
|
+
readonly inputs: Readonly<Record<string, unknown>>;
|
|
30
|
+
readonly outputs: Readonly<Record<string, unknown>>;
|
|
31
|
+
readonly state: Readonly<State>;
|
|
32
|
+
readonly stats: Readonly<RuntimeNodeStats>;
|
|
33
|
+
readonly lastInputAt?: Readonly<Record<string, number>>;
|
|
34
|
+
};
|
|
35
|
+
export interface RuntimeEdge extends GraphEdgeDefinition {
|
|
36
|
+
convert?: (value: unknown) => unknown;
|
|
37
|
+
convertAsync?: (value: unknown, signal: AbortSignal) => Promise<unknown>;
|
|
38
|
+
stats: RuntimeEdgeStats;
|
|
39
|
+
srcUnionTypes?: string[];
|
|
40
|
+
dstDeclared?: string | string[];
|
|
41
|
+
}
|
|
42
|
+
export type RunContextId = string;
|
|
43
|
+
/**
|
|
44
|
+
* Execution plan containing all information needed to start a node execution.
|
|
45
|
+
* Captures a snapshot of the node's policy at scheduling time so later
|
|
46
|
+
* mutations to `node.policy` don't affect an in-flight run.
|
|
47
|
+
*/
|
|
48
|
+
export interface ExecutionPlan {
|
|
49
|
+
runId: string;
|
|
50
|
+
effectiveInputs: Record<string, unknown>;
|
|
51
|
+
runContextIdsForRun?: Set<RunContextId>;
|
|
52
|
+
timestamp: number;
|
|
53
|
+
policy: RuntimeNode["policy"];
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,QAAQ,EACT,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,WAAW,WAAW,CAAC,KAAK,GAAG,GAAG,CAAE,SAAQ,mBAAmB;IACnE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IAChC,SAAS,EAAE,kBAAkB,CAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,KAAK,EACL,GAAG,CACJ,CAAC,WAAW,CAAC,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,WAAW,C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EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzE,KAAK,EAAE,gBAAgB,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACjC;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,mBAAmB,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/runtime/components/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { LogLevel } from "@bian-womp/spark-protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Shared utility functions for runtime components
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a value is a Promise
|
|
7
|
+
*/
|
|
8
|
+
export declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Unwrap a value that might be a Promise
|
|
11
|
+
*/
|
|
12
|
+
export declare function unwrapMaybePromise<T>(value: T | Promise<T>): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Shallow/deep-ish equality check to avoid unnecessary runs on identical values
|
|
15
|
+
*/
|
|
16
|
+
export declare function valuesEqual(a: unknown, b: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A reusable logger class that supports configurable log levels and prefixes.
|
|
19
|
+
* Can be instantiated with a default log level and optionally override per call.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LevelLogger {
|
|
22
|
+
private defaultLevel;
|
|
23
|
+
private prefix;
|
|
24
|
+
/**
|
|
25
|
+
* Maps log levels to numeric values for comparison
|
|
26
|
+
*/
|
|
27
|
+
static readonly levelValues: Record<LogLevel, number>;
|
|
28
|
+
constructor(defaultLevel?: LogLevel, prefix?: string);
|
|
29
|
+
/**
|
|
30
|
+
* Sets the prefix for log messages
|
|
31
|
+
*/
|
|
32
|
+
setPrefix(prefix: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the current prefix
|
|
35
|
+
*/
|
|
36
|
+
getPrefix(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Sets the default log level for this logger instance
|
|
39
|
+
*/
|
|
40
|
+
setLevel(level: LogLevel): void;
|
|
41
|
+
/**
|
|
42
|
+
* Gets the current default log level
|
|
43
|
+
*/
|
|
44
|
+
getLevel(): LogLevel;
|
|
45
|
+
getLevelValue(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Logs a debug message
|
|
48
|
+
*/
|
|
49
|
+
debug(message: string, context?: Record<string, unknown>, overrideLevel?: LogLevel): void;
|
|
50
|
+
/**
|
|
51
|
+
* Logs an info message
|
|
52
|
+
*/
|
|
53
|
+
info(message: string, context?: Record<string, unknown>, overrideLevel?: LogLevel): void;
|
|
54
|
+
/**
|
|
55
|
+
* Logs a warning message
|
|
56
|
+
*/
|
|
57
|
+
warn(message: string, context?: Record<string, unknown>, overrideLevel?: LogLevel): void;
|
|
58
|
+
/**
|
|
59
|
+
* Logs an error message
|
|
60
|
+
*/
|
|
61
|
+
error(message: string, context?: Record<string, unknown>, overrideLevel?: LogLevel): void;
|
|
62
|
+
/**
|
|
63
|
+
* Core logging method that respects the log level and applies prefix
|
|
64
|
+
*/
|
|
65
|
+
private log;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRo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IAIP;;OAEG;IACH,IAAI,CACF,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,OAAO,CAAC,GAAG;CA0CZ"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { LOG_LEVEL_VALUES } from "@bian-womp/spark-protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Shared utility functions for runtime components
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a value is a Promise
|
|
7
|
+
*/
|
|
8
|
+
export function isPromise(value) {
|
|
9
|
+
return !!value && typeof value.then === "function";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Unwrap a value that might be a Promise
|
|
13
|
+
*/
|
|
14
|
+
export async function unwrapMaybePromise(value) {
|
|
15
|
+
return isPromise(value) ? await value : value;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Shallow/deep-ish equality check to avoid unnecessary runs on identical values
|
|
19
|
+
*/
|
|
20
|
+
export function valuesEqual(a, b) {
|
|
21
|
+
if (a === b)
|
|
22
|
+
return true;
|
|
23
|
+
if (typeof a !== typeof b)
|
|
24
|
+
return false;
|
|
25
|
+
if (a && b && typeof a === "object") {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A reusable logger class that supports configurable log levels and prefixes.
|
|
37
|
+
* Can be instantiated with a default log level and optionally override per call.
|
|
38
|
+
*/
|
|
39
|
+
export class LevelLogger {
|
|
40
|
+
constructor(defaultLevel = "info", prefix = "") {
|
|
41
|
+
this.defaultLevel = defaultLevel;
|
|
42
|
+
this.prefix = prefix;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sets the prefix for log messages
|
|
46
|
+
*/
|
|
47
|
+
setPrefix(prefix) {
|
|
48
|
+
this.prefix = prefix;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the current prefix
|
|
52
|
+
*/
|
|
53
|
+
getPrefix() {
|
|
54
|
+
return this.prefix;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sets the default log level for this logger instance
|
|
58
|
+
*/
|
|
59
|
+
setLevel(level) {
|
|
60
|
+
this.defaultLevel = level;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the current default log level
|
|
64
|
+
*/
|
|
65
|
+
getLevel() {
|
|
66
|
+
return this.defaultLevel;
|
|
67
|
+
}
|
|
68
|
+
getLevelValue() {
|
|
69
|
+
return LevelLogger.levelValues[this.defaultLevel];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Logs a debug message
|
|
73
|
+
*/
|
|
74
|
+
debug(message, context, overrideLevel) {
|
|
75
|
+
this.log("debug", message, context, overrideLevel);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Logs an info message
|
|
79
|
+
*/
|
|
80
|
+
info(message, context, overrideLevel) {
|
|
81
|
+
this.log("info", message, context, overrideLevel);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Logs a warning message
|
|
85
|
+
*/
|
|
86
|
+
warn(message, context, overrideLevel) {
|
|
87
|
+
this.log("warn", message, context, overrideLevel);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Logs an error message
|
|
91
|
+
*/
|
|
92
|
+
error(message, context, overrideLevel) {
|
|
93
|
+
this.log("error", message, context, overrideLevel);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Core logging method that respects the log level and applies prefix
|
|
97
|
+
*/
|
|
98
|
+
log(requestedLevel, message, context, overrideLevel) {
|
|
99
|
+
const effectiveLevel = overrideLevel ?? this.defaultLevel;
|
|
100
|
+
// Silent level suppresses all logs
|
|
101
|
+
if (effectiveLevel === "silent") {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const requestedValue = LevelLogger.levelValues[requestedLevel] ?? 1;
|
|
105
|
+
const effectiveValue = LevelLogger.levelValues[effectiveLevel] ?? 1;
|
|
106
|
+
// Only log if the requested level is >= effective level
|
|
107
|
+
if (requestedValue >= effectiveValue) {
|
|
108
|
+
const contextStr = context
|
|
109
|
+
? ` ${Object.entries(context)
|
|
110
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
111
|
+
.join(" ")}`
|
|
112
|
+
: "";
|
|
113
|
+
const prefixedMessage = this.prefix
|
|
114
|
+
? `${this.prefix} ${message}${contextStr}`
|
|
115
|
+
: `${message}${contextStr}`;
|
|
116
|
+
switch (requestedLevel) {
|
|
117
|
+
case "debug":
|
|
118
|
+
console.info(prefixedMessage);
|
|
119
|
+
break;
|
|
120
|
+
case "info":
|
|
121
|
+
console.info(prefixedMessage);
|
|
122
|
+
break;
|
|
123
|
+
case "warn":
|
|
124
|
+
console.warn(prefixedMessage);
|
|
125
|
+
break;
|
|
126
|
+
case "error":
|
|
127
|
+
console.error(prefixedMessage);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Maps log levels to numeric values for comparison
|
|
135
|
+
*/
|
|
136
|
+
LevelLogger.levelValues = LOG_LEVEL_VALUES;
|
|
137
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/runtime/utils.ts"],"names":[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