@bian-womp/spark-graph 0.3.23 → 0.3.25
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 +77 -24
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/builder/GraphBuilder.d.ts +1 -0
- package/lib/cjs/src/builder/GraphBuilder.d.ts.map +1 -1
- package/lib/cjs/src/misc/base.d.ts +3 -1
- package/lib/cjs/src/misc/base.d.ts.map +1 -1
- package/lib/cjs/src/misc/utils/merge.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphLifecycleApi.d.ts +1 -0
- package/lib/cjs/src/runtime/GraphLifecycleApi.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts +2 -0
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/index.js +77 -24
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/builder/GraphBuilder.d.ts +1 -0
- package/lib/esm/src/builder/GraphBuilder.d.ts.map +1 -1
- package/lib/esm/src/misc/base.d.ts +3 -1
- package/lib/esm/src/misc/base.d.ts.map +1 -1
- package/lib/esm/src/misc/utils/merge.d.ts.map +1 -1
- package/lib/esm/src/runtime/GraphLifecycleApi.d.ts +1 -0
- package/lib/esm/src/runtime/GraphLifecycleApi.d.ts.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts +2 -0
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/index.cjs
CHANGED
|
@@ -2778,6 +2778,8 @@ class GraphRuntime {
|
|
|
2778
2778
|
}
|
|
2779
2779
|
static create(def, registry, opts) {
|
|
2780
2780
|
const gr = new GraphRuntime();
|
|
2781
|
+
if (opts?.startPaused)
|
|
2782
|
+
gr.pause();
|
|
2781
2783
|
gr.environment = opts?.environment ?? {};
|
|
2782
2784
|
// Set registry and environment on components
|
|
2783
2785
|
gr.graph.setRegistry(registry);
|
|
@@ -2785,7 +2787,15 @@ class GraphRuntime {
|
|
|
2785
2787
|
gr.handleResolver.setEnvironment(gr.environment);
|
|
2786
2788
|
gr.nodeExecutor.setEnvironment(gr.environment);
|
|
2787
2789
|
// Precompute per-node resolved handles (use def-provided overrides; do not compute dynamically here)
|
|
2788
|
-
const initial =
|
|
2790
|
+
const initial = gr.pauseRefCount
|
|
2791
|
+
? {
|
|
2792
|
+
resolved: new Map(),
|
|
2793
|
+
pending: new Set(),
|
|
2794
|
+
}
|
|
2795
|
+
: tryHandleResolving(def, registry, gr.environment);
|
|
2796
|
+
if (gr.pauseRefCount) {
|
|
2797
|
+
gr.handleResolvingSkippedRef = def;
|
|
2798
|
+
}
|
|
2789
2799
|
for (const [nodeId, handles] of initial.resolved) {
|
|
2790
2800
|
gr.graph.setResolvedHandles(nodeId, handles);
|
|
2791
2801
|
}
|
|
@@ -3089,6 +3099,20 @@ class GraphRuntime {
|
|
|
3089
3099
|
if (this.persistentPauseToken) {
|
|
3090
3100
|
this.persistentPauseToken();
|
|
3091
3101
|
this.persistentPauseToken = null;
|
|
3102
|
+
// If handle resolving was skipped, trigger it now
|
|
3103
|
+
if (this.handleResolvingSkippedRef) {
|
|
3104
|
+
const registry = this.graph.getRegistry();
|
|
3105
|
+
if (registry) {
|
|
3106
|
+
const result = tryHandleResolving(this.handleResolvingSkippedRef, registry, this.environment);
|
|
3107
|
+
for (const [nodeId, handles] of result.resolved) {
|
|
3108
|
+
this.graph.setResolvedHandles(nodeId, handles);
|
|
3109
|
+
}
|
|
3110
|
+
for (const nodeId of result.pending) {
|
|
3111
|
+
this.handleResolver.scheduleRecomputeHandles(nodeId);
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
this.handleResolvingSkippedRef = undefined;
|
|
3115
|
+
}
|
|
3092
3116
|
}
|
|
3093
3117
|
}
|
|
3094
3118
|
copyOutputs(fromNodeId, toNodeId, options) {
|
|
@@ -3276,7 +3300,15 @@ class GraphRuntime {
|
|
|
3276
3300
|
});
|
|
3277
3301
|
{
|
|
3278
3302
|
// Update handles and edges
|
|
3279
|
-
const result =
|
|
3303
|
+
const result = this.pauseRefCount
|
|
3304
|
+
? {
|
|
3305
|
+
resolved: new Map(),
|
|
3306
|
+
pending: new Set(),
|
|
3307
|
+
}
|
|
3308
|
+
: tryHandleResolving(def, registry, this.environment);
|
|
3309
|
+
if (this.pauseRefCount) {
|
|
3310
|
+
this.handleResolvingSkippedRef = def;
|
|
3311
|
+
}
|
|
3280
3312
|
const changedHandles = {};
|
|
3281
3313
|
for (const [nodeId, newHandles] of result.resolved) {
|
|
3282
3314
|
const oldHandles = this.graph.getResolvedHandles(nodeId);
|
|
@@ -5552,17 +5584,19 @@ function offsetImportedPositions(targetPositions, sourcePositions, sourceDef, no
|
|
|
5552
5584
|
}
|
|
5553
5585
|
function buildTypeMaps(def) {
|
|
5554
5586
|
const nodeTypeMap = new Map();
|
|
5555
|
-
const
|
|
5587
|
+
const inputHandleTypeMap = new Map();
|
|
5588
|
+
const outputHandleTypeMap = new Map();
|
|
5556
5589
|
for (const node of def.nodes) {
|
|
5557
5590
|
nodeTypeMap.set(node.nodeId, node.typeId);
|
|
5558
|
-
const
|
|
5591
|
+
const nodeInputTypes = new Map();
|
|
5592
|
+
const nodeOutputTypes = new Map();
|
|
5559
5593
|
if (node.resolvedHandles?.inputs) {
|
|
5560
5594
|
for (const [handleId, handleDesc] of Object.entries(node.resolvedHandles.inputs)) {
|
|
5561
5595
|
const typeId = typeof handleDesc === "string"
|
|
5562
5596
|
? handleDesc
|
|
5563
5597
|
: handleDesc?.typeId;
|
|
5564
5598
|
if (typeId)
|
|
5565
|
-
|
|
5599
|
+
nodeInputTypes.set(handleId, typeId);
|
|
5566
5600
|
}
|
|
5567
5601
|
}
|
|
5568
5602
|
if (node.resolvedHandles?.outputs) {
|
|
@@ -5573,14 +5607,33 @@ function buildTypeMaps(def) {
|
|
|
5573
5607
|
? handleDesc[0]
|
|
5574
5608
|
: undefined;
|
|
5575
5609
|
if (typeId)
|
|
5576
|
-
|
|
5610
|
+
nodeOutputTypes.set(handleId, typeId);
|
|
5577
5611
|
}
|
|
5578
5612
|
}
|
|
5579
|
-
|
|
5580
|
-
|
|
5613
|
+
// Also include handles from inputDefaults - they share handle IDs with inputs
|
|
5614
|
+
if (node.resolvedHandles?.inputDefaults) {
|
|
5615
|
+
for (const handleId of Object.keys(node.resolvedHandles.inputDefaults)) {
|
|
5616
|
+
// If not already in map, try to get type from input handles
|
|
5617
|
+
if (!nodeInputTypes.has(handleId) && node.resolvedHandles?.inputs) {
|
|
5618
|
+
const inputDesc = node.resolvedHandles.inputs[handleId];
|
|
5619
|
+
if (inputDesc) {
|
|
5620
|
+
const typeId = typeof inputDesc === "string"
|
|
5621
|
+
? inputDesc
|
|
5622
|
+
: inputDesc?.typeId;
|
|
5623
|
+
if (typeId)
|
|
5624
|
+
nodeInputTypes.set(handleId, typeId);
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
if (nodeInputTypes.size > 0) {
|
|
5630
|
+
inputHandleTypeMap.set(node.nodeId, nodeInputTypes);
|
|
5631
|
+
}
|
|
5632
|
+
if (nodeOutputTypes.size > 0) {
|
|
5633
|
+
outputHandleTypeMap.set(node.nodeId, nodeOutputTypes);
|
|
5581
5634
|
}
|
|
5582
5635
|
}
|
|
5583
|
-
return { nodeTypeMap,
|
|
5636
|
+
return { nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap };
|
|
5584
5637
|
}
|
|
5585
5638
|
function applyConversion(items, values, converter, type) {
|
|
5586
5639
|
for (const item of items) {
|
|
@@ -5608,21 +5661,21 @@ function applyConversion(items, values, converter, type) {
|
|
|
5608
5661
|
}
|
|
5609
5662
|
}
|
|
5610
5663
|
}
|
|
5611
|
-
function collectValuesToConvert(values, nodeTypeMap,
|
|
5664
|
+
function collectValuesToConvert(values, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap, type) {
|
|
5612
5665
|
const converted = {};
|
|
5613
5666
|
const toConvert = [];
|
|
5667
|
+
const handleTypeMap = type === "output" ? outputHandleTypeMap : inputHandleTypeMap;
|
|
5614
5668
|
for (const [nodeId, nodeValues] of Object.entries(values)) {
|
|
5615
5669
|
converted[nodeId] = { ...nodeValues };
|
|
5616
|
-
const
|
|
5617
|
-
const nodeTypeId = nodeTypeMap.get(originalNodeId);
|
|
5670
|
+
const nodeTypeId = nodeTypeMap.get(nodeId);
|
|
5618
5671
|
for (const [handleId, value] of Object.entries(nodeValues)) {
|
|
5619
|
-
const handleDataType = handleTypeMap.get(
|
|
5672
|
+
const handleDataType = handleTypeMap.get(nodeId)?.get(handleId);
|
|
5620
5673
|
const runtimeTypeId = isTypedOutput(value)
|
|
5621
5674
|
? getTypedOutputTypeId(value)
|
|
5622
5675
|
: undefined;
|
|
5623
5676
|
toConvert.push({
|
|
5624
5677
|
nodeId,
|
|
5625
|
-
originalNodeId,
|
|
5678
|
+
originalNodeId: nodeId,
|
|
5626
5679
|
handleId,
|
|
5627
5680
|
value,
|
|
5628
5681
|
nodeTypeId,
|
|
@@ -5635,16 +5688,16 @@ function collectValuesToConvert(values, nodeTypeMap, handleTypeMap, originalNode
|
|
|
5635
5688
|
}
|
|
5636
5689
|
function convertSnapshot(snapshot, converter) {
|
|
5637
5690
|
const def = snapshot.def ?? { nodes: [], edges: [] };
|
|
5638
|
-
const { nodeTypeMap,
|
|
5691
|
+
const { nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap } = buildTypeMaps(def);
|
|
5639
5692
|
const inputDefaults = {};
|
|
5640
5693
|
for (const node of def.nodes) {
|
|
5641
5694
|
if (node.resolvedHandles?.inputDefaults) {
|
|
5642
5695
|
inputDefaults[node.nodeId] = { ...node.resolvedHandles.inputDefaults };
|
|
5643
5696
|
}
|
|
5644
5697
|
}
|
|
5645
|
-
const { converted: convertedInputs, toConvert: inputsToConvert } = collectValuesToConvert(snapshot.inputs ?? {}, nodeTypeMap,
|
|
5646
|
-
const { converted: convertedOutputs, toConvert: outputsToConvert } = collectValuesToConvert(snapshot.outputs ?? {}, nodeTypeMap,
|
|
5647
|
-
const { converted: convertedInputDefaults, toConvert: inputDefaultsToConvert, } = collectValuesToConvert(inputDefaults, nodeTypeMap,
|
|
5698
|
+
const { converted: convertedInputs, toConvert: inputsToConvert } = collectValuesToConvert(snapshot.inputs ?? {}, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap, "input");
|
|
5699
|
+
const { converted: convertedOutputs, toConvert: outputsToConvert } = collectValuesToConvert(snapshot.outputs ?? {}, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap, "output");
|
|
5700
|
+
const { converted: convertedInputDefaults, toConvert: inputDefaultsToConvert, } = collectValuesToConvert(inputDefaults, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap, "inputDefault");
|
|
5648
5701
|
applyConversion(inputsToConvert, convertedInputs, converter, "input");
|
|
5649
5702
|
applyConversion(outputsToConvert, convertedOutputs, converter, "output");
|
|
5650
5703
|
applyConversion(inputDefaultsToConvert, convertedInputDefaults, converter, "inputDefault");
|
|
@@ -5675,7 +5728,7 @@ function convertSnapshot(snapshot, converter) {
|
|
|
5675
5728
|
outputs: convertedOutputs,
|
|
5676
5729
|
};
|
|
5677
5730
|
}
|
|
5678
|
-
function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOutputs, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap,
|
|
5731
|
+
function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOutputs, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap) {
|
|
5679
5732
|
const mergedInputs = { ...targetInputs };
|
|
5680
5733
|
const mergedOutputs = { ...targetOutputs };
|
|
5681
5734
|
const mergedInputDefaults = { ...targetInputDefaults };
|
|
@@ -5690,7 +5743,7 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
5690
5743
|
}
|
|
5691
5744
|
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5692
5745
|
for (const [handleId, value] of Object.entries(inputs)) {
|
|
5693
|
-
const handleDataType =
|
|
5746
|
+
const handleDataType = inputHandleTypeMap?.get(oldId)?.get(handleId);
|
|
5694
5747
|
inputsToConvert.push({
|
|
5695
5748
|
nodeId: newId,
|
|
5696
5749
|
originalNodeId: oldId,
|
|
@@ -5711,7 +5764,7 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
5711
5764
|
}
|
|
5712
5765
|
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5713
5766
|
for (const [handleId, value] of Object.entries(outputs)) {
|
|
5714
|
-
const handleDataType =
|
|
5767
|
+
const handleDataType = outputHandleTypeMap?.get(oldId)?.get(handleId);
|
|
5715
5768
|
const runtimeTypeId = isTypedOutput(value)
|
|
5716
5769
|
? getTypedOutputTypeId(value)
|
|
5717
5770
|
: undefined;
|
|
@@ -5736,7 +5789,7 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
5736
5789
|
}
|
|
5737
5790
|
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5738
5791
|
for (const [handleId, value] of Object.entries(defaults)) {
|
|
5739
|
-
const handleDataType =
|
|
5792
|
+
const handleDataType = inputHandleTypeMap?.get(oldId)?.get(handleId);
|
|
5740
5793
|
inputDefaultsToConvert.push({
|
|
5741
5794
|
nodeId: newId,
|
|
5742
5795
|
originalNodeId: oldId,
|
|
@@ -5760,8 +5813,8 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
5760
5813
|
}
|
|
5761
5814
|
function mergeSnapshotData(targetSnapshot, sourceSnapshot, targetInputDefaults, sourceInputDefaults, nodeIdMap) {
|
|
5762
5815
|
const sourceDef = sourceSnapshot.def ?? { nodes: []};
|
|
5763
|
-
const { nodeTypeMap,
|
|
5764
|
-
return mergeInputsOutputs(targetSnapshot.inputs ?? {}, targetSnapshot.outputs ?? {}, sourceSnapshot.inputs ?? {}, sourceSnapshot.outputs ?? {}, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap,
|
|
5816
|
+
const { nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap } = buildTypeMaps(sourceDef);
|
|
5817
|
+
return mergeInputsOutputs(targetSnapshot.inputs ?? {}, targetSnapshot.outputs ?? {}, sourceSnapshot.inputs ?? {}, sourceSnapshot.outputs ?? {}, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap, inputHandleTypeMap, outputHandleTypeMap);
|
|
5765
5818
|
}
|
|
5766
5819
|
function mergeSnapshots(targetSnapshot, sourceSnapshot, converter) {
|
|
5767
5820
|
const targetDef = targetSnapshot.def ?? { nodes: [], edges: [] };
|