@bian-womp/spark-graph 0.3.88 → 0.3.90
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 +9 -5
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/cjs/src/runtime/components/HandleResolver.d.ts.map +1 -1
- package/lib/cjs/src/runtime/components/NodeExecutor.d.ts.map +1 -1
- package/lib/esm/index.js +9 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/src/runtime/components/HandleResolver.d.ts.map +1 -1
- package/lib/esm/src/runtime/components/NodeExecutor.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 +279 -0
- package/lib/src/builder/GraphBuilder.js.map +1 -0
- package/lib/src/builder/Registry.d.ts +87 -0
- package/lib/src/builder/Registry.d.ts.map +1 -0
- package/lib/src/builder/Registry.js +390 -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 +92 -0
- package/lib/src/core/type-utils.js.map +1 -0
- package/lib/src/core/types.d.ts +95 -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 +47 -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 +1091 -0
- package/lib/src/misc/base.js.map +1 -0
- package/lib/src/misc/utils/LevelLogger.d.ts +150 -0
- package/lib/src/misc/utils/LevelLogger.d.ts.map +1 -0
- package/lib/src/misc/utils/LevelLogger.js +420 -0
- package/lib/src/misc/utils/LevelLogger.js.map +1 -0
- package/lib/src/misc/utils/LevelLogger.test.d.ts +2 -0
- package/lib/src/misc/utils/LevelLogger.test.d.ts.map +1 -0
- package/lib/src/misc/utils/LevelLogger.test.js +283 -0
- package/lib/src/misc/utils/LevelLogger.test.js.map +1 -0
- package/lib/src/misc/utils/json.d.ts +34 -0
- package/lib/src/misc/utils/json.d.ts.map +1 -0
- package/lib/src/misc/utils/json.js +471 -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 +591 -0
- package/lib/src/misc/utils/merge.js.map +1 -0
- package/lib/src/misc/utils/test-logger-output.d.ts +7 -0
- package/lib/src/misc/utils/test-logger-output.d.ts.map +1 -0
- package/lib/src/misc/utils/test-logger-output.js +48 -0
- package/lib/src/misc/utils/test-logger-output.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 +26 -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 +111 -0
- package/lib/src/runtime/GraphRuntime.d.ts.map +1 -0
- package/lib/src/runtime/GraphRuntime.js +791 -0
- package/lib/src/runtime/GraphRuntime.js.map +1 -0
- package/lib/src/runtime/LocalEngine.d.ts +41 -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 +93 -0
- package/lib/src/runtime/components/EdgePropagator.d.ts.map +1 -0
- package/lib/src/runtime/components/EdgePropagator.js +378 -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 +208 -0
- package/lib/src/runtime/components/Graph.d.ts.map +1 -0
- package/lib/src/runtime/components/Graph.js +452 -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 +229 -0
- package/lib/src/runtime/components/HandleResolver.js.map +1 -0
- package/lib/src/runtime/components/NodeExecutor.d.ts +116 -0
- package/lib/src/runtime/components/NodeExecutor.d.ts.map +1 -0
- package/lib/src/runtime/components/NodeExecutor.js +648 -0
- package/lib/src/runtime/components/NodeExecutor.js.map +1 -0
- package/lib/src/runtime/components/RunContextManager.d.ts +90 -0
- package/lib/src/runtime/components/RunContextManager.d.ts.map +1 -0
- package/lib/src/runtime/components/RunContextManager.js +329 -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 +56 -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 +300 -0
- package/lib/src/runtime/components/graph-utils.js.map +1 -0
- package/lib/src/runtime/components/interfaces.d.ts +59 -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 +57 -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 +21 -0
- package/lib/src/runtime/utils.d.ts.map +1 -0
- package/lib/src/runtime/utils.js +41 -0
- package/lib/src/runtime/utils.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
export class CategoryRegistry {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.categories = new Map();
|
|
4
|
+
}
|
|
5
|
+
register(cat) {
|
|
6
|
+
this.categories.set(cat.id, cat);
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
get(id) {
|
|
10
|
+
return this.categories.get(id);
|
|
11
|
+
}
|
|
12
|
+
has(id) {
|
|
13
|
+
return this.categories.has(id);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class Registry {
|
|
17
|
+
constructor(id) {
|
|
18
|
+
this.types = new Map();
|
|
19
|
+
this.nodes = new Map();
|
|
20
|
+
this.enums = new Map();
|
|
21
|
+
this.categories = new CategoryRegistry();
|
|
22
|
+
this.serializers = new Map();
|
|
23
|
+
this.coercions = new Map();
|
|
24
|
+
this.asyncCoercions = new Map();
|
|
25
|
+
this.resolvedCache = new Map();
|
|
26
|
+
this.id = id ?? `r${Registry.idCounter++}`;
|
|
27
|
+
}
|
|
28
|
+
registerType(desc, opts) {
|
|
29
|
+
this.types.set(desc.id, desc);
|
|
30
|
+
// Any structural change invalidates resolution cache
|
|
31
|
+
this.resolvedCache.clear();
|
|
32
|
+
if (!this.serializers.has(desc.id)) {
|
|
33
|
+
this.registerSerializer(desc.id, {
|
|
34
|
+
serialize: (v) => v,
|
|
35
|
+
deserialize: (d) => d,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (opts?.withArray) {
|
|
39
|
+
const arrayId = opts.arrayId ?? `${desc.id}[]`;
|
|
40
|
+
if (!this.types.has(arrayId)) {
|
|
41
|
+
const arrayDesc = {
|
|
42
|
+
id: arrayId,
|
|
43
|
+
validate: (v) => Array.isArray(v) &&
|
|
44
|
+
v.every((x) => {
|
|
45
|
+
try {
|
|
46
|
+
return desc.validate(x);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
this.types.set(arrayId, arrayDesc);
|
|
54
|
+
}
|
|
55
|
+
this.registerCoercion(desc.id, arrayId, (value) => (Array.isArray(value) ? value : [value]));
|
|
56
|
+
this.registerCoercion(arrayId, desc.id, (value) => {
|
|
57
|
+
if (!Array.isArray(value))
|
|
58
|
+
return value;
|
|
59
|
+
if (opts.arrayPickFirstDefined) {
|
|
60
|
+
for (const x of value)
|
|
61
|
+
if (x !== undefined)
|
|
62
|
+
return x;
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return value[0];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
registerNode(desc) {
|
|
71
|
+
this.nodes.set(desc.id, desc);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
registerSerializer(typeId, s) {
|
|
75
|
+
this.serializers.set(typeId, s);
|
|
76
|
+
// If an array variant of this type exists and doesn't have a serializer,
|
|
77
|
+
// auto-register an array serializer that maps each element using the base serializer.
|
|
78
|
+
const arrayId = `${typeId}[]`;
|
|
79
|
+
if (this.types.has(arrayId) && !this.serializers.has(arrayId)) {
|
|
80
|
+
this.serializers.set(arrayId, {
|
|
81
|
+
serialize: (value) => (Array.isArray(value) ? value.map((el) => s.serialize(el)) : value),
|
|
82
|
+
deserialize: (data) => (Array.isArray(data) ? data.map((el) => s.deserialize(el)) : data),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
// Register a type coercion from one type id to another
|
|
88
|
+
registerCoercion(fromTypeId, toTypeId, convert, opts) {
|
|
89
|
+
this.coercions.set(`${fromTypeId}->${toTypeId}`, {
|
|
90
|
+
convert,
|
|
91
|
+
nonTransitive: !!opts?.nonTransitive,
|
|
92
|
+
});
|
|
93
|
+
// If both source and target have array variants, add derived array->array coercion
|
|
94
|
+
const fromArr = fromTypeId === "base.object" ? fromTypeId : `${fromTypeId}[]`;
|
|
95
|
+
const toArr = toTypeId === "base.object" ? toTypeId : `${toTypeId}[]`;
|
|
96
|
+
const arrKey = `${fromArr}->${toArr}`;
|
|
97
|
+
if (this.types.has(fromArr) && this.types.has(toArr)) {
|
|
98
|
+
if (!this.coercions.has(arrKey) && !this.asyncCoercions.has(arrKey)) {
|
|
99
|
+
this.coercions.set(arrKey, {
|
|
100
|
+
convert: (value) => {
|
|
101
|
+
if (Array.isArray(value))
|
|
102
|
+
return value.map((v) => convert(v));
|
|
103
|
+
// Best-effort: coerce single to array-of-single
|
|
104
|
+
return [convert(value)];
|
|
105
|
+
},
|
|
106
|
+
nonTransitive: !!opts?.nonTransitive,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.resolvedCache.clear();
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
// Register an async type coercion from one type id to another
|
|
114
|
+
registerAsyncCoercion(fromTypeId, toTypeId, convertAsync, opts) {
|
|
115
|
+
this.asyncCoercions.set(`${fromTypeId}->${toTypeId}`, {
|
|
116
|
+
convertAsync,
|
|
117
|
+
nonTransitive: !!opts?.nonTransitive,
|
|
118
|
+
});
|
|
119
|
+
// If both source and target have array variants, add derived array->array async coercion
|
|
120
|
+
const fromArr = fromTypeId === "base.object" ? fromTypeId : `${fromTypeId}[]`;
|
|
121
|
+
const toArr = toTypeId === "base.object" ? toTypeId : `${toTypeId}[]`;
|
|
122
|
+
const arrKey = `${fromArr}->${toArr}`;
|
|
123
|
+
if (this.types.has(fromArr) && this.types.has(toArr)) {
|
|
124
|
+
if (!this.coercions.has(arrKey) && !this.asyncCoercions.has(arrKey)) {
|
|
125
|
+
this.asyncCoercions.set(arrKey, {
|
|
126
|
+
convertAsync: async (value, signal) => {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
const out = [];
|
|
129
|
+
for (let i = 0; i < value.length; i++) {
|
|
130
|
+
if (signal?.aborted)
|
|
131
|
+
throw signal.reason ?? new Error("aborted");
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
133
|
+
out.push(await convertAsync(value[i], signal));
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
return [await convertAsync(value, signal)];
|
|
138
|
+
},
|
|
139
|
+
nonTransitive: !!opts?.nonTransitive,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
this.resolvedCache.clear();
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
canCoerce(fromTypeId, toTypeId) {
|
|
147
|
+
if (!fromTypeId || !toTypeId)
|
|
148
|
+
return false;
|
|
149
|
+
return !!this.resolveCoercion(fromTypeId, toTypeId);
|
|
150
|
+
}
|
|
151
|
+
getCoercion(fromTypeId, toTypeId) {
|
|
152
|
+
const resolved = this.resolveCoercion(fromTypeId, toTypeId);
|
|
153
|
+
if (!resolved)
|
|
154
|
+
return undefined;
|
|
155
|
+
if (resolved.kind === "sync")
|
|
156
|
+
return resolved.convert;
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
getAsyncCoercion(fromTypeId, toTypeId) {
|
|
160
|
+
const resolved = this.resolveCoercion(fromTypeId, toTypeId);
|
|
161
|
+
if (!resolved)
|
|
162
|
+
return undefined;
|
|
163
|
+
if (resolved.kind === "async")
|
|
164
|
+
return resolved.convertAsync;
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
// Introspection for dynamic discovery
|
|
168
|
+
listCoercions() {
|
|
169
|
+
const out = [];
|
|
170
|
+
for (const [key, rec] of this.coercions.entries()) {
|
|
171
|
+
const [from, to] = key.split("->");
|
|
172
|
+
out.push({
|
|
173
|
+
from,
|
|
174
|
+
to,
|
|
175
|
+
async: false,
|
|
176
|
+
nonTransitive: rec.nonTransitive,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
for (const [key, rec] of this.asyncCoercions.entries()) {
|
|
180
|
+
const [from, to] = key.split("->");
|
|
181
|
+
out.push({ from, to, async: true, nonTransitive: rec.nonTransitive });
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
resolveCoercion(fromTypeId, toTypeId) {
|
|
186
|
+
const cacheKey = `${fromTypeId}->${toTypeId}`;
|
|
187
|
+
const cached = this.resolvedCache.get(cacheKey);
|
|
188
|
+
if (cached)
|
|
189
|
+
return cached;
|
|
190
|
+
if (fromTypeId === toTypeId) {
|
|
191
|
+
const res = {
|
|
192
|
+
kind: "sync",
|
|
193
|
+
convert: (v) => v,
|
|
194
|
+
cost: { edges: 0, async: 0 },
|
|
195
|
+
};
|
|
196
|
+
this.resolvedCache.set(cacheKey, res);
|
|
197
|
+
return res;
|
|
198
|
+
}
|
|
199
|
+
// Direct edges (regardless of nonTransitive)
|
|
200
|
+
const directSync = this.coercions.get(cacheKey);
|
|
201
|
+
if (directSync) {
|
|
202
|
+
const res = {
|
|
203
|
+
kind: "sync",
|
|
204
|
+
convert: directSync.convert,
|
|
205
|
+
cost: { edges: 1, async: 0 },
|
|
206
|
+
};
|
|
207
|
+
this.resolvedCache.set(cacheKey, res);
|
|
208
|
+
return res;
|
|
209
|
+
}
|
|
210
|
+
const directAsync = this.asyncCoercions.get(cacheKey);
|
|
211
|
+
if (directAsync) {
|
|
212
|
+
const res = {
|
|
213
|
+
kind: "async",
|
|
214
|
+
convertAsync: directAsync.convertAsync,
|
|
215
|
+
cost: { edges: 1, async: 1 },
|
|
216
|
+
};
|
|
217
|
+
this.resolvedCache.set(cacheKey, res);
|
|
218
|
+
return res;
|
|
219
|
+
}
|
|
220
|
+
// Build adjacency from transitive-allowed edges only
|
|
221
|
+
const getNeighbors = (from) => {
|
|
222
|
+
const out = [];
|
|
223
|
+
for (const [key, rec] of this.coercions.entries()) {
|
|
224
|
+
if (rec.nonTransitive)
|
|
225
|
+
continue;
|
|
226
|
+
const [src, dst] = key.split("->");
|
|
227
|
+
if (src === from)
|
|
228
|
+
out.push({ from: src, to: dst, kind: "sync", convert: rec.convert });
|
|
229
|
+
}
|
|
230
|
+
for (const [key, rec] of this.asyncCoercions.entries()) {
|
|
231
|
+
if (rec.nonTransitive)
|
|
232
|
+
continue;
|
|
233
|
+
const [src, dst] = key.split("->");
|
|
234
|
+
if (src === from)
|
|
235
|
+
out.push({
|
|
236
|
+
from: src,
|
|
237
|
+
to: dst,
|
|
238
|
+
kind: "async",
|
|
239
|
+
convertAsync: rec.convertAsync,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
};
|
|
244
|
+
const betterOf = (a, b) => {
|
|
245
|
+
if (!a)
|
|
246
|
+
return true;
|
|
247
|
+
if (b.edges !== a.edges)
|
|
248
|
+
return b.edges < a.edges;
|
|
249
|
+
return b.async < a.async;
|
|
250
|
+
};
|
|
251
|
+
const best = new Map();
|
|
252
|
+
const queue = [];
|
|
253
|
+
const push = (e) => {
|
|
254
|
+
// simple insertion to keep queue roughly ordered by cost
|
|
255
|
+
let i = 0;
|
|
256
|
+
while (i < queue.length) {
|
|
257
|
+
const q = queue[i];
|
|
258
|
+
if (e.cost.edges < q.cost.edges || (e.cost.edges === q.cost.edges && e.cost.async < q.cost.async)) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
i++;
|
|
262
|
+
}
|
|
263
|
+
queue.splice(i, 0, e);
|
|
264
|
+
};
|
|
265
|
+
push({ node: fromTypeId, cost: { edges: 0, async: 0 }, path: [] });
|
|
266
|
+
best.set(fromTypeId, { edges: 0, async: 0 });
|
|
267
|
+
while (queue.length > 0) {
|
|
268
|
+
const cur = queue.shift();
|
|
269
|
+
if (cur.node === toTypeId) {
|
|
270
|
+
// Compose
|
|
271
|
+
const cost = {
|
|
272
|
+
edges: cur.cost.edges,
|
|
273
|
+
async: cur.cost.async,
|
|
274
|
+
};
|
|
275
|
+
const hasAsync = cur.path.some((s) => s.kind === "async");
|
|
276
|
+
if (!hasAsync) {
|
|
277
|
+
const convert = (value) => {
|
|
278
|
+
let acc = value;
|
|
279
|
+
for (const step of cur.path) {
|
|
280
|
+
// all sync by construction
|
|
281
|
+
acc = step.convert(acc);
|
|
282
|
+
}
|
|
283
|
+
return acc;
|
|
284
|
+
};
|
|
285
|
+
const res = {
|
|
286
|
+
kind: "sync",
|
|
287
|
+
convert,
|
|
288
|
+
cost,
|
|
289
|
+
};
|
|
290
|
+
this.resolvedCache.set(cacheKey, res);
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
const convertAsync = async (value, signal) => {
|
|
295
|
+
let acc = value;
|
|
296
|
+
for (const step of cur.path) {
|
|
297
|
+
if (step.kind === "sync") {
|
|
298
|
+
acc = step.convert(acc);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
acc = await step.convertAsync(acc, signal);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return acc;
|
|
305
|
+
};
|
|
306
|
+
const res = {
|
|
307
|
+
kind: "async",
|
|
308
|
+
convertAsync,
|
|
309
|
+
cost,
|
|
310
|
+
};
|
|
311
|
+
this.resolvedCache.set(cacheKey, res);
|
|
312
|
+
return res;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// expand neighbors
|
|
316
|
+
for (const step of getNeighbors(cur.node)) {
|
|
317
|
+
const nextCost = {
|
|
318
|
+
edges: cur.cost.edges + 1,
|
|
319
|
+
async: cur.cost.async + (step.kind === "async" ? 1 : 0),
|
|
320
|
+
};
|
|
321
|
+
const prev = best.get(step.to);
|
|
322
|
+
if (betterOf(prev, nextCost)) {
|
|
323
|
+
best.set(step.to, nextCost);
|
|
324
|
+
push({ node: step.to, cost: nextCost, path: [...cur.path, step] });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
// Enum support
|
|
331
|
+
registerEnum(desc) {
|
|
332
|
+
const { id, displayName, options, opts, bakeTarget } = desc;
|
|
333
|
+
const labelType = opts?.labelType ?? "base.string";
|
|
334
|
+
const valueType = opts?.valueType ?? "base.float";
|
|
335
|
+
const valueToLabel = new Map();
|
|
336
|
+
const labelToValue = new Map();
|
|
337
|
+
for (const { value, label } of options) {
|
|
338
|
+
valueToLabel.set(value, label);
|
|
339
|
+
labelToValue.set(label.toLowerCase(), value);
|
|
340
|
+
}
|
|
341
|
+
this.enums.set(id, {
|
|
342
|
+
options,
|
|
343
|
+
valueToLabel,
|
|
344
|
+
labelToValue,
|
|
345
|
+
});
|
|
346
|
+
// Register type descriptor and serializer for enum (stored as number)
|
|
347
|
+
this.registerType({
|
|
348
|
+
id,
|
|
349
|
+
displayName,
|
|
350
|
+
validate: (v) => typeof v === "number" && valueToLabel.has(Number(v)),
|
|
351
|
+
bakeTarget,
|
|
352
|
+
}, opts);
|
|
353
|
+
this.registerSerializer(id, {
|
|
354
|
+
serialize: (v) => v,
|
|
355
|
+
deserialize: (d) => Number(d),
|
|
356
|
+
});
|
|
357
|
+
// Coercions: string -> enum (by label), float -> enum (by numeric value), enum -> string (label)
|
|
358
|
+
this.registerCoercion(labelType, id, (value) => {
|
|
359
|
+
const s = String(value ?? "")
|
|
360
|
+
.trim()
|
|
361
|
+
.toLowerCase();
|
|
362
|
+
const rec = this.enums.get(id);
|
|
363
|
+
if (!rec)
|
|
364
|
+
return value;
|
|
365
|
+
if (rec.labelToValue.has(s))
|
|
366
|
+
return rec.labelToValue.get(s);
|
|
367
|
+
const asNum = Number(s);
|
|
368
|
+
if (Number.isFinite(asNum) && rec.valueToLabel.has(asNum))
|
|
369
|
+
return asNum;
|
|
370
|
+
return Array.from(rec.valueToLabel.keys())[0] ?? 0;
|
|
371
|
+
});
|
|
372
|
+
this.registerCoercion(valueType, id, (value) => {
|
|
373
|
+
const n = Number(value);
|
|
374
|
+
const rec = this.enums.get(id);
|
|
375
|
+
if (!rec)
|
|
376
|
+
return value;
|
|
377
|
+
return rec.valueToLabel.has(n) ? n : (Array.from(rec.valueToLabel.keys())[0] ?? 0);
|
|
378
|
+
});
|
|
379
|
+
this.registerCoercion(id, labelType, (value) => {
|
|
380
|
+
const n = Number(value);
|
|
381
|
+
const rec = this.enums.get(id);
|
|
382
|
+
if (!rec)
|
|
383
|
+
return String(value);
|
|
384
|
+
return rec.valueToLabel.get(n) ?? String(n);
|
|
385
|
+
});
|
|
386
|
+
return this;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
Registry.idCounter = 0;
|
|
390
|
+
//# sourceMappingURL=Registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Registry.js","sourceRoot":"","sources":["../../../src/builder/Registry.ts"],"names":[],"mappings":"AAsCA,MAAM,OAAO,gBAAgB;IAA7B;QACU,eAAU,GAAG,IAAI,GAAG,EAA4C,CAAC;IAW3E,CAAC;IAVC,QAAQ,CAAc,GAAwC;QAC5D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC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I,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACxB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/B,IAAI,CAAC,GAAG;gBAAE,OAAO,KAAK,CAAC;YACvB,OAAO,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACrF,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACxB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/B,IAAI,CAAC,GAAG;gBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,OAAO,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;;AAzcc,kBAAS,GAAG,CAAC,AAAJ,CAAK"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NodeCategoryId, ExecutionPolicy } from "@bian-womp/spark-protocol";
|
|
2
|
+
import type { ExecutionContext } from "./types";
|
|
3
|
+
export interface CategoryRuntime<State = unknown> {
|
|
4
|
+
onInputsChanged?: (inputs: Record<string, unknown>, ctx: ExecutionContext<State>) => void | Promise<void>;
|
|
5
|
+
onActivated?: () => void | Promise<void>;
|
|
6
|
+
onDeactivated?: () => void | Promise<void>;
|
|
7
|
+
onExternalEvent?: (event: unknown, state: State) => void | Promise<void>;
|
|
8
|
+
onTick?: () => void;
|
|
9
|
+
dispose?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface NodeCategoryDescriptor<Impl = unknown, State = unknown> {
|
|
12
|
+
id: NodeCategoryId;
|
|
13
|
+
displayName?: string;
|
|
14
|
+
validateImpl?: (impl: Impl) => void;
|
|
15
|
+
createRuntime: (options: {
|
|
16
|
+
nodeId: string;
|
|
17
|
+
impl: Impl;
|
|
18
|
+
initialState?: Partial<State>;
|
|
19
|
+
}) => CategoryRuntime<State>;
|
|
20
|
+
policy?: Partial<ExecutionPolicy>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=categories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.d.ts","sourceRoot":"","sources":["../../../src/core/categories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,MAAM,WAAW,eAAe,CAAC,KAAK,GAAG,OAAO;IAC9C,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1G,WAAW,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,aAAa,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB,CAAC,IAAI,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IACrE,EAAE,EAAE,cAAc,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACpC,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;KAAE,KAAK,eAAe,CAAC,KAAK,CAAC,CAAC;IAClH,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.js","sourceRoot":"","sources":["../../../src/core/categories.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GraphDefinition } from "@bian-womp/spark-protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the forward-reachable subgraph from a starting node.
|
|
4
|
+
* Returns nodes in topological order, starting from the given node.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getForwardOrder(def: GraphDefinition, startId: string): string[];
|
|
7
|
+
//# sourceMappingURL=order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../../src/core/order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAiE/E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the forward-reachable subgraph from a starting node.
|
|
3
|
+
* Returns nodes in topological order, starting from the given node.
|
|
4
|
+
*/
|
|
5
|
+
export function getForwardOrder(def, startId) {
|
|
6
|
+
// Build adjacency list (forward edges only)
|
|
7
|
+
const neighbors = {};
|
|
8
|
+
const indegree = {};
|
|
9
|
+
const reachable = new Set();
|
|
10
|
+
// Initialize all nodes
|
|
11
|
+
for (const n of def.nodes) {
|
|
12
|
+
neighbors[n.nodeId] = [];
|
|
13
|
+
indegree[n.nodeId] = 0;
|
|
14
|
+
}
|
|
15
|
+
// Build forward edges
|
|
16
|
+
for (const e of def.edges) {
|
|
17
|
+
neighbors[e.source.nodeId].push(e.target.nodeId);
|
|
18
|
+
}
|
|
19
|
+
// 1. BFS to collect all forward-reachable nodes from start
|
|
20
|
+
const queue = [startId];
|
|
21
|
+
while (queue.length > 0) {
|
|
22
|
+
const id = queue.shift();
|
|
23
|
+
if (reachable.has(id))
|
|
24
|
+
continue;
|
|
25
|
+
reachable.add(id);
|
|
26
|
+
for (const nb of neighbors[id] || []) {
|
|
27
|
+
if (!reachable.has(nb)) {
|
|
28
|
+
queue.push(nb);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// 2. Compute indegree for reachable subgraph only
|
|
33
|
+
for (const e of def.edges) {
|
|
34
|
+
if (reachable.has(e.source.nodeId) && reachable.has(e.target.nodeId)) {
|
|
35
|
+
indegree[e.target.nodeId] = (indegree[e.target.nodeId] ?? 0) + 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// 3. Kahn's algorithm: topological sort of reachable subgraph
|
|
39
|
+
const q = [];
|
|
40
|
+
for (const id of reachable) {
|
|
41
|
+
if (indegree[id] === 0) {
|
|
42
|
+
q.push(id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const order = [];
|
|
46
|
+
while (q.length > 0) {
|
|
47
|
+
const id = q.shift();
|
|
48
|
+
order.push(id);
|
|
49
|
+
for (const nb of neighbors[id] || []) {
|
|
50
|
+
if (!reachable.has(nb))
|
|
51
|
+
continue;
|
|
52
|
+
indegree[nb] = (indegree[nb] ?? 0) - 1;
|
|
53
|
+
if (indegree[nb] === 0) {
|
|
54
|
+
q.push(nb);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// 4. Return only nodes from startId forward (slice from startId's position)
|
|
59
|
+
const startIdx = order.indexOf(startId);
|
|
60
|
+
if (startIdx === -1) {
|
|
61
|
+
// Start node not in order (shouldn't happen, but be safe)
|
|
62
|
+
return [startId];
|
|
63
|
+
}
|
|
64
|
+
return order.slice(startIdx);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/core/order.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,GAAoB,EAAE,OAAe;IACnE,4CAA4C;IAC5C,MAAM,SAAS,GAA6B,EAAE,CAAC;IAC/C,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpC,uBAAuB;IACvB,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAC1B,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACzB,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,sBAAsB;IACtB,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAC1B,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,2DAA2D;IAC3D,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC;IACxB,OAAO,KA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AAC,EAAE,CAAC,CAAC;QACf,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YACrC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,SAAS;YACjC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACvC,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,0DAA0D;QAC1D,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DataTypeId, HandleId, InputHandleDescriptor, HandleMetadata } from "@bian-womp/spark-protocol";
|
|
2
|
+
import type { TypedValue } from "./types";
|
|
3
|
+
export declare function typed<T = unknown>(typeId: DataTypeId, value: T): TypedValue<T>;
|
|
4
|
+
export declare function isTyped(v: unknown): v is TypedValue<unknown>;
|
|
5
|
+
export declare function unwrapTypeId(v: unknown): DataTypeId | undefined;
|
|
6
|
+
export declare function unwrapValue(v: unknown): unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Get the full declared type(s) for an input handle (supports union types)
|
|
9
|
+
* Returns the typeId as-is: string for single type, string[] for union types
|
|
10
|
+
*/
|
|
11
|
+
export declare function getInputDeclaredTypes(inputs: Record<string, InputHandleDescriptor> | undefined, handle: HandleId): DataTypeId | DataTypeId[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get the primary (first) type ID for an input handle.
|
|
14
|
+
* For union types, returns the first type in the array.
|
|
15
|
+
* This maintains backward compatibility for code that expects a single type.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getInputTypeId(inputs: Record<string, InputHandleDescriptor> | undefined, handle: HandleId): DataTypeId | undefined;
|
|
18
|
+
export declare function isInputPrivate(inputs: Record<string, InputHandleDescriptor> | undefined, handle: HandleId): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Merge two InputHandleDescriptor values, with dynamic taking precedence.
|
|
21
|
+
* If both have metadata, merge the metadata objects (dynamic overrides static).
|
|
22
|
+
* Supports union types (arrays) in both static and dynamic descriptors.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mergeInputHandleDescriptors(staticDesc: InputHandleDescriptor | undefined, dynamicDesc: InputHandleDescriptor | undefined): InputHandleDescriptor | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Extract metadata from an InputHandleDescriptor
|
|
27
|
+
*/
|
|
28
|
+
export declare function getInputHandleMetadata(inputs: Record<string, InputHandleDescriptor> | undefined, handle: HandleId): HandleMetadata | undefined;
|
|
29
|
+
//# sourceMappingURL=type-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../../../src/core/type-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC7G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAE9E;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAE5D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAG/D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAG/C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,SAAS,EACzD,MAAM,EAAE,QAAQ,GACf,UAAU,GAAG,UAAU,EAAE,GAAG,SAAS,CAOvC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,SAAS,EACzD,MAAM,EAAE,QAAQ,GACf,UAAU,GAAG,SAAS,CAIxB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAKnH;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,qBAAqB,GAAG,SAAS,EAC7C,WAAW,EAAE,qBAAqB,GAAG,SAAS,GAC7C,qBAAqB,GAAG,SAAS,CA2CnC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,SAAS,EACzD,MAAM,EAAE,QAAQ,GACf,cAAc,GAAG,SAAS,CAI5B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export function typed(typeId, value) {
|
|
2
|
+
return { __spark_type: typeId, __spark_value: value };
|
|
3
|
+
}
|
|
4
|
+
export function isTyped(v) {
|
|
5
|
+
return !!v && typeof v === "object" && Object.prototype.hasOwnProperty.call(v, "__spark_type");
|
|
6
|
+
}
|
|
7
|
+
export function unwrapTypeId(v) {
|
|
8
|
+
if (isTyped(v))
|
|
9
|
+
return String(v.__spark_type);
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
export function unwrapValue(v) {
|
|
13
|
+
if (isTyped(v))
|
|
14
|
+
return v.__spark_value;
|
|
15
|
+
return v;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the full declared type(s) for an input handle (supports union types)
|
|
19
|
+
* Returns the typeId as-is: string for single type, string[] for union types
|
|
20
|
+
*/
|
|
21
|
+
export function getInputDeclaredTypes(inputs, handle) {
|
|
22
|
+
const v = inputs ? inputs[handle] : undefined;
|
|
23
|
+
if (!v)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (typeof v === "string")
|
|
26
|
+
return v;
|
|
27
|
+
if (Array.isArray(v))
|
|
28
|
+
return v;
|
|
29
|
+
return v.typeId;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the primary (first) type ID for an input handle.
|
|
33
|
+
* For union types, returns the first type in the array.
|
|
34
|
+
* This maintains backward compatibility for code that expects a single type.
|
|
35
|
+
*/
|
|
36
|
+
export function getInputTypeId(inputs, handle) {
|
|
37
|
+
const decl = getInputDeclaredTypes(inputs, handle);
|
|
38
|
+
if (!decl)
|
|
39
|
+
return undefined;
|
|
40
|
+
return Array.isArray(decl) ? decl[0] : decl;
|
|
41
|
+
}
|
|
42
|
+
export function isInputPrivate(inputs, handle) {
|
|
43
|
+
const v = inputs ? inputs[handle] : undefined;
|
|
44
|
+
if (!v || typeof v === "string" || Array.isArray(v))
|
|
45
|
+
return false;
|
|
46
|
+
// At this point, v must be an object with optional private/metadata fields
|
|
47
|
+
return !!(typeof v === "object" && v !== null && "private" in v && v.private);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Merge two InputHandleDescriptor values, with dynamic taking precedence.
|
|
51
|
+
* If both have metadata, merge the metadata objects (dynamic overrides static).
|
|
52
|
+
* Supports union types (arrays) in both static and dynamic descriptors.
|
|
53
|
+
*/
|
|
54
|
+
export function mergeInputHandleDescriptors(staticDesc, dynamicDesc) {
|
|
55
|
+
// If only one exists, return it
|
|
56
|
+
if (!staticDesc)
|
|
57
|
+
return dynamicDesc;
|
|
58
|
+
if (!dynamicDesc)
|
|
59
|
+
return staticDesc;
|
|
60
|
+
// If both are primitive (string or array), dynamic wins
|
|
61
|
+
if ((typeof staticDesc === "string" || Array.isArray(staticDesc)) &&
|
|
62
|
+
(typeof dynamicDesc === "string" || Array.isArray(dynamicDesc))) {
|
|
63
|
+
return dynamicDesc;
|
|
64
|
+
}
|
|
65
|
+
const staticObj = typeof staticDesc === "string" || Array.isArray(staticDesc) ? { typeId: staticDesc } : staticDesc;
|
|
66
|
+
const dynamicObj = typeof dynamicDesc === "string" || Array.isArray(dynamicDesc) ? { typeId: dynamicDesc } : dynamicDesc;
|
|
67
|
+
// Merge: dynamic takes precedence, but merge metadata objects
|
|
68
|
+
const merged = {
|
|
69
|
+
typeId: dynamicObj.typeId ?? staticObj.typeId,
|
|
70
|
+
private: dynamicObj.private ?? staticObj.private,
|
|
71
|
+
defaultPolicy: dynamicObj.defaultPolicy ?? staticObj.defaultPolicy,
|
|
72
|
+
};
|
|
73
|
+
// Merge metadata if either has it
|
|
74
|
+
if (staticObj.metadata || dynamicObj.metadata) {
|
|
75
|
+
merged.metadata = {
|
|
76
|
+
...staticObj.metadata,
|
|
77
|
+
...dynamicObj.metadata, // Dynamic metadata overrides static
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Return as InputHandleDescriptor (which accepts object form)
|
|
81
|
+
return merged;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Extract metadata from an InputHandleDescriptor
|
|
85
|
+
*/
|
|
86
|
+
export function getInputHandleMetadata(inputs, handle) {
|
|
87
|
+
const v = inputs ? inputs[handle] : undefined;
|
|
88
|
+
if (!v || typeof v === "string" || Array.isArray(v))
|
|
89
|
+
return undefined;
|
|
90
|
+
return v.metadata;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=type-utils.js.map
|