@bian-womp/spark-graph 0.1.20 → 0.1.21
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 +39 -29
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/core/types.d.ts +2 -0
- package/lib/cjs/src/core/types.d.ts.map +1 -1
- package/lib/cjs/src/index.d.ts +2 -4
- package/lib/cjs/src/index.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/index.js +38 -30
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/core/types.d.ts +2 -0
- package/lib/esm/src/core/types.d.ts.map +1 -1
- package/lib/esm/src/index.d.ts +2 -4
- package/lib/esm/src/index.d.ts.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/index.cjs
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
function typed(typeId, value) {
|
|
4
|
+
return { __spark_type: typeId, __spark_value: value };
|
|
5
|
+
}
|
|
6
|
+
function isTypedOutput(v) {
|
|
7
|
+
return (!!v &&
|
|
8
|
+
typeof v === "object" &&
|
|
9
|
+
Object.prototype.hasOwnProperty.call(v, "__spark_type"));
|
|
10
|
+
}
|
|
11
|
+
function getTypedOutputTypeId(v) {
|
|
12
|
+
if (isTypedOutput(v))
|
|
13
|
+
return String(v.__spark_type);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function getTypedOutputValue(v) {
|
|
17
|
+
if (isTypedOutput(v))
|
|
18
|
+
return v.__spark_value;
|
|
19
|
+
return v;
|
|
20
|
+
}
|
|
21
|
+
function getInputTypeId(inputs, handle) {
|
|
22
|
+
const v = inputs ? inputs[handle] : undefined;
|
|
23
|
+
if (!v)
|
|
24
|
+
return undefined;
|
|
25
|
+
return typeof v === "string" ? v : v.typeId;
|
|
26
|
+
}
|
|
27
|
+
function isInputPrivate(inputs, handle) {
|
|
28
|
+
const v = inputs ? inputs[handle] : undefined;
|
|
29
|
+
return !!(v && typeof v === "object" && v.private);
|
|
30
|
+
}
|
|
31
|
+
|
|
3
32
|
class CategoryRegistry {
|
|
4
33
|
constructor() {
|
|
5
34
|
this.categories = new Map();
|
|
@@ -372,25 +401,6 @@ class Registry {
|
|
|
372
401
|
}
|
|
373
402
|
}
|
|
374
403
|
|
|
375
|
-
function typed(typeId, value) {
|
|
376
|
-
return { __spark_type: typeId, __spark_value: value };
|
|
377
|
-
}
|
|
378
|
-
function isTypedOutput(v) {
|
|
379
|
-
return (!!v &&
|
|
380
|
-
typeof v === "object" &&
|
|
381
|
-
Object.prototype.hasOwnProperty.call(v, "__spark_type"));
|
|
382
|
-
}
|
|
383
|
-
function getInputTypeId(inputs, handle) {
|
|
384
|
-
const v = inputs ? inputs[handle] : undefined;
|
|
385
|
-
if (!v)
|
|
386
|
-
return undefined;
|
|
387
|
-
return typeof v === "string" ? v : v.typeId;
|
|
388
|
-
}
|
|
389
|
-
function isInputPrivate(inputs, handle) {
|
|
390
|
-
const v = inputs ? inputs[handle] : undefined;
|
|
391
|
-
return !!(v && typeof v === "object" && v.private);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
404
|
class GraphRuntime {
|
|
395
405
|
constructor() {
|
|
396
406
|
this.nodes = new Map();
|
|
@@ -565,12 +575,12 @@ class GraphRuntime {
|
|
|
565
575
|
});
|
|
566
576
|
if (anyAsync) {
|
|
567
577
|
convertAsync = async (v, signal) => {
|
|
568
|
-
|
|
578
|
+
const typeId = getTypedOutputTypeId(v);
|
|
579
|
+
if (!typeId)
|
|
569
580
|
throw new Error(`Typed output required for union source; allowed: ${srcTypes.join("|")}`);
|
|
570
|
-
const typeId = String(v.__spark_type);
|
|
571
581
|
if (!srcTypes.includes(typeId))
|
|
572
582
|
throw new Error(`Invalid typed output ${typeId}; allowed: ${srcTypes.join("|")}`);
|
|
573
|
-
const payload =
|
|
583
|
+
const payload = typeId;
|
|
574
584
|
const res = registry.resolveCoercion(typeId, dstDeclared);
|
|
575
585
|
if (!res)
|
|
576
586
|
return payload;
|
|
@@ -581,12 +591,12 @@ class GraphRuntime {
|
|
|
581
591
|
}
|
|
582
592
|
else {
|
|
583
593
|
convert = (v) => {
|
|
584
|
-
|
|
594
|
+
const typeId = getTypedOutputTypeId(v);
|
|
595
|
+
if (!typeId)
|
|
585
596
|
throw new Error(`Typed output required for union source; allowed: ${srcTypes.join("|")}`);
|
|
586
|
-
const typeId = String(v.__spark_type);
|
|
587
597
|
if (!srcTypes.includes(typeId))
|
|
588
598
|
throw new Error(`Invalid typed output ${typeId}; allowed: ${srcTypes.join("|")}`);
|
|
589
|
-
const payload =
|
|
599
|
+
const payload = typeId;
|
|
590
600
|
const res = registry.resolveCoercion(typeId, dstDeclared);
|
|
591
601
|
if (!res)
|
|
592
602
|
return payload;
|
|
@@ -777,9 +787,7 @@ class GraphRuntime {
|
|
|
777
787
|
handle: srcHandle,
|
|
778
788
|
value,
|
|
779
789
|
io: "output",
|
|
780
|
-
runtimeTypeId:
|
|
781
|
-
? String(value.__spark_type)
|
|
782
|
-
: undefined,
|
|
790
|
+
runtimeTypeId: getTypedOutputTypeId(value),
|
|
783
791
|
});
|
|
784
792
|
// fan-out along all edges from this output
|
|
785
793
|
const outEdges = this.edges.filter((e) => e.source.nodeId === srcNodeId && e.source.handle === srcHandle);
|
|
@@ -811,7 +819,7 @@ class GraphRuntime {
|
|
|
811
819
|
handle: e.target.handle,
|
|
812
820
|
value: v,
|
|
813
821
|
io: "input",
|
|
814
|
-
runtimeTypeId:
|
|
822
|
+
runtimeTypeId: getTypedOutputTypeId(v),
|
|
815
823
|
});
|
|
816
824
|
if (!this.paused && this.allInboundHaveValue(e.target.nodeId))
|
|
817
825
|
this.scheduleInputsChanged(e.target.nodeId);
|
|
@@ -2487,6 +2495,8 @@ exports.createSimpleGraphRegistry = createSimpleGraphRegistry;
|
|
|
2487
2495
|
exports.createValidationGraphDef = createValidationGraphDef;
|
|
2488
2496
|
exports.createValidationGraphRegistry = createValidationGraphRegistry;
|
|
2489
2497
|
exports.getInputTypeId = getInputTypeId;
|
|
2498
|
+
exports.getTypedOutputTypeId = getTypedOutputTypeId;
|
|
2499
|
+
exports.getTypedOutputValue = getTypedOutputValue;
|
|
2490
2500
|
exports.isInputPrivate = isInputPrivate;
|
|
2491
2501
|
exports.isTypedOutput = isTypedOutput;
|
|
2492
2502
|
exports.registerDelayNode = registerDelayNode;
|