@bian-womp/spark-graph 0.3.19 → 0.3.20
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 +142 -122
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/index.d.ts +1 -1
- package/lib/cjs/src/index.d.ts.map +1 -1
- package/lib/cjs/src/misc/utils/merge.d.ts +4 -28
- package/lib/cjs/src/misc/utils/merge.d.ts.map +1 -1
- package/lib/esm/index.js +142 -120
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/index.d.ts +1 -1
- package/lib/esm/src/index.d.ts.map +1 -1
- package/lib/esm/src/misc/utils/merge.d.ts +4 -28
- package/lib/esm/src/misc/utils/merge.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/src/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { createProgressGraphRegistry, createProgressGraphDef, } from "./examples
|
|
|
18
18
|
export { createValidationGraphRegistry, createValidationGraphDef, } from "./examples/validation";
|
|
19
19
|
export { installLogging } from "./examples/shared";
|
|
20
20
|
export { registerDelayNode, registerProgressNodes, generateId, BaseMathOperation, BaseCompareOperation, BaseLogicOperation, } from "./misc/base";
|
|
21
|
-
export {
|
|
21
|
+
export { mergeSnapshots, computeGraphCenter, offsetImportedPositions, mergeRuntimeState, buildValueConverter, type ConverterConfig, type ValueMappingConfig, type ValueConverter, type ValueConverterConfig, } from "./misc/utils/merge";
|
|
22
22
|
export { parseJsonPath, getValueAtPath, setValueAtPath, setValueAtPathWithCreation, findMatchingPaths, type JsonPath, type PathSegment, } from "./misc/utils/json";
|
|
23
23
|
export { LevelLogger } from "./runtime/utils";
|
|
24
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,WAAW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AAC;AAExD,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,0BAA0B,EAC1B,iBAAiB,EACjB,KAAK,QAAQ,EACb,KAAK,WAAW,GACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
import type { GraphDefinition, RuntimeSnapshotFull, RuntimeMetadata } from "@bian-womp/spark-protocol";
|
|
2
2
|
import { type JsonPath } from "./json";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration object for value conversion.
|
|
5
|
-
*/
|
|
6
3
|
export interface ValueConverterConfig {
|
|
7
4
|
nodeId: string;
|
|
8
5
|
handleId: string;
|
|
9
6
|
value: unknown;
|
|
10
|
-
type: "input" | "output" | "inputDefault"
|
|
7
|
+
type: "input" | "output" | "inputDefault";
|
|
11
8
|
nodeTypeId?: string;
|
|
12
9
|
handleDataType?: string;
|
|
13
10
|
runtimeTypeId?: string;
|
|
14
11
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Merge two graph definitions, remapping IDs to avoid conflicts.
|
|
17
|
-
* Returns the merged graph and a mapping from source node IDs to new IDs.
|
|
18
|
-
*/
|
|
19
12
|
export type ValueConverter = (config: ValueConverterConfig) => unknown;
|
|
20
|
-
export declare function mergeGraphDefinitions(target: GraphDefinition, source: GraphDefinition, converter?: ValueConverter): {
|
|
21
|
-
merged: GraphDefinition;
|
|
22
|
-
nodeIdMap: Record<string, string>;
|
|
23
|
-
};
|
|
24
13
|
/**
|
|
25
14
|
* Compute the center point of a graph based on node positions.
|
|
26
15
|
*/
|
|
@@ -48,22 +37,9 @@ export declare function offsetImportedPositions(targetPositions: Record<string,
|
|
|
48
37
|
x: number;
|
|
49
38
|
y: number;
|
|
50
39
|
}>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
export declare function mergeInputsOutputs(targetInputs: Record<string, Record<string, unknown>>, targetOutputs: Record<string, Record<string, unknown>>, sourceInputs: Record<string, Record<string, unknown>>, sourceOutputs: Record<string, Record<string, unknown>>, nodeIdMap: Record<string, string>, converter?: ValueConverter, nodeTypeMap?: Map<string, string>, handleTypeMap?: Map<string, Map<string, string>>): {
|
|
56
|
-
mergedInputs: Record<string, Record<string, unknown>>;
|
|
57
|
-
mergedOutputs: Record<string, Record<string, unknown>>;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Merge snapshot data (inputs, outputs) from source into target.
|
|
61
|
-
* Graph definition merging should be done separately using mergeGraphDefinitions.
|
|
62
|
-
* UI positions are handled separately by mergeUIState.
|
|
63
|
-
*/
|
|
64
|
-
export declare function mergeSnapshotData(targetSnapshot: RuntimeSnapshotFull, sourceSnapshot: RuntimeSnapshotFull, sourceDef: GraphDefinition, nodeIdMap: Record<string, string>, converter?: ValueConverter): {
|
|
65
|
-
mergedInputs: Record<string, Record<string, unknown>>;
|
|
66
|
-
mergedOutputs: Record<string, Record<string, unknown>>;
|
|
40
|
+
export declare function mergeSnapshots(targetSnapshot: RuntimeSnapshotFull, sourceSnapshot: RuntimeSnapshotFull, converter?: ValueConverter): {
|
|
41
|
+
merged: RuntimeSnapshotFull;
|
|
42
|
+
nodeIdMap: Record<string, string>;
|
|
67
43
|
};
|
|
68
44
|
/**
|
|
69
45
|
* Merge runtime metadata from source into target, remapping node IDs using nodeIdMap.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../../../src/misc/utils/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,mBAAmB,EACnB,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,QAAQ,CAAC;AAQhB
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../../../src/misc/utils/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,mBAAmB,EACnB,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,QAAQ,CAAC;AAQhB,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC;AAkGvE;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE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U,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,EACJ,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,GACvC,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;CAChC;AAUD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAwM3E"}
|
package/lib/esm/index.js
CHANGED
|
@@ -5421,62 +5421,42 @@ function findMatchingPaths(obj, pathSegments, currentPath = []) {
|
|
|
5421
5421
|
return results;
|
|
5422
5422
|
}
|
|
5423
5423
|
|
|
5424
|
-
function mergeGraphDefinitions(target, source
|
|
5424
|
+
function mergeGraphDefinitions(target, source) {
|
|
5425
5425
|
const existingNodeIds = new Set(target.nodes.map((n) => n.nodeId));
|
|
5426
5426
|
const existingEdgeIds = new Set(target.edges.map((e) => e.id));
|
|
5427
5427
|
const nodeIdMap = {};
|
|
5428
|
+
const targetInputDefaults = {};
|
|
5429
|
+
const sourceInputDefaults = {};
|
|
5430
|
+
for (const node of target.nodes) {
|
|
5431
|
+
if (node.resolvedHandles?.inputDefaults) {
|
|
5432
|
+
targetInputDefaults[node.nodeId] = {
|
|
5433
|
+
...node.resolvedHandles.inputDefaults,
|
|
5434
|
+
};
|
|
5435
|
+
}
|
|
5436
|
+
}
|
|
5428
5437
|
const importedNodes = source.nodes.map((n) => {
|
|
5429
5438
|
let newId = n.nodeId;
|
|
5430
|
-
|
|
5439
|
+
const isExistingNode = existingNodeIds.has(newId);
|
|
5440
|
+
if (isExistingNode) {
|
|
5431
5441
|
newId = generateId("n", existingNodeIds);
|
|
5432
5442
|
}
|
|
5433
5443
|
else {
|
|
5434
5444
|
existingNodeIds.add(newId);
|
|
5435
5445
|
}
|
|
5436
5446
|
nodeIdMap[n.nodeId] = newId;
|
|
5437
|
-
|
|
5447
|
+
if (n.resolvedHandles?.inputDefaults) {
|
|
5448
|
+
sourceInputDefaults[n.nodeId] = { ...n.resolvedHandles.inputDefaults };
|
|
5449
|
+
}
|
|
5450
|
+
return {
|
|
5438
5451
|
...n,
|
|
5439
5452
|
nodeId: newId,
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
const transformedInputDefaults = {};
|
|
5445
|
-
for (const [handleId, value] of Object.entries(transformedNode.resolvedHandles.inputDefaults)) {
|
|
5446
|
-
const handleDataType = transformedNode.resolvedHandles?.inputs?.[handleId]
|
|
5447
|
-
? typeof transformedNode.resolvedHandles.inputs[handleId] ===
|
|
5448
|
-
"string"
|
|
5449
|
-
? transformedNode.resolvedHandles.inputs[handleId]
|
|
5450
|
-
: transformedNode.resolvedHandles.inputs[handleId]?.typeId
|
|
5451
|
-
: undefined;
|
|
5452
|
-
const convertedValue = converter({
|
|
5453
|
-
nodeId: newId,
|
|
5454
|
-
handleId,
|
|
5455
|
-
value,
|
|
5456
|
-
type: "inputDefault",
|
|
5457
|
-
nodeTypeId,
|
|
5458
|
-
handleDataType,
|
|
5459
|
-
});
|
|
5460
|
-
// If converter returns null, skip this input default (delete it)
|
|
5461
|
-
if (convertedValue !== null) {
|
|
5462
|
-
transformedInputDefaults[handleId] = convertedValue;
|
|
5463
|
-
}
|
|
5453
|
+
resolvedHandles: n.resolvedHandles
|
|
5454
|
+
? {
|
|
5455
|
+
...n.resolvedHandles,
|
|
5456
|
+
inputDefaults: undefined,
|
|
5464
5457
|
}
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
transformedNode.resolvedHandles = {
|
|
5468
|
-
...transformedNode.resolvedHandles,
|
|
5469
|
-
inputDefaults: transformedInputDefaults,
|
|
5470
|
-
};
|
|
5471
|
-
}
|
|
5472
|
-
else if (transformedNode.resolvedHandles) {
|
|
5473
|
-
// Remove inputDefaults if all were deleted
|
|
5474
|
-
const { inputDefaults, ...restHandles } = transformedNode.resolvedHandles;
|
|
5475
|
-
transformedNode.resolvedHandles = restHandles;
|
|
5476
|
-
}
|
|
5477
|
-
}
|
|
5478
|
-
}
|
|
5479
|
-
return transformedNode;
|
|
5458
|
+
: undefined,
|
|
5459
|
+
};
|
|
5480
5460
|
});
|
|
5481
5461
|
const importedEdges = source.edges.map((e) => {
|
|
5482
5462
|
let newEdgeId = e.id;
|
|
@@ -5507,6 +5487,8 @@ function mergeGraphDefinitions(target, source, converter) {
|
|
|
5507
5487
|
edges: [...target.edges, ...importedEdges],
|
|
5508
5488
|
},
|
|
5509
5489
|
nodeIdMap,
|
|
5490
|
+
targetInputDefaults,
|
|
5491
|
+
sourceInputDefaults,
|
|
5510
5492
|
};
|
|
5511
5493
|
}
|
|
5512
5494
|
/**
|
|
@@ -5551,116 +5533,100 @@ function offsetImportedPositions(targetPositions, sourcePositions, sourceDef, no
|
|
|
5551
5533
|
}
|
|
5552
5534
|
return newPositions;
|
|
5553
5535
|
}
|
|
5554
|
-
|
|
5555
|
-
* Merge inputs and outputs from source into target, remapping node IDs.
|
|
5556
|
-
* Source values override target when merging.
|
|
5557
|
-
*/
|
|
5558
|
-
function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOutputs, nodeIdMap, converter, nodeTypeMap, handleTypeMap) {
|
|
5559
|
-
// Deep copy target inputs/outputs to avoid mutating the original
|
|
5536
|
+
function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOutputs, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap, handleTypeMap) {
|
|
5560
5537
|
const mergedInputs = {};
|
|
5561
5538
|
const mergedOutputs = {};
|
|
5562
|
-
|
|
5539
|
+
const mergedInputDefaults = {};
|
|
5540
|
+
const inputsToConvert = [];
|
|
5541
|
+
const outputsToConvert = [];
|
|
5542
|
+
const inputDefaultsToConvert = [];
|
|
5563
5543
|
for (const [nodeId, inputs] of Object.entries(targetInputs)) {
|
|
5564
5544
|
mergedInputs[nodeId] = { ...inputs };
|
|
5565
5545
|
}
|
|
5566
5546
|
for (const [nodeId, outputs] of Object.entries(targetOutputs)) {
|
|
5567
5547
|
mergedOutputs[nodeId] = { ...outputs };
|
|
5568
5548
|
}
|
|
5549
|
+
for (const [nodeId, defaults] of Object.entries(targetInputDefaults)) {
|
|
5550
|
+
mergedInputDefaults[nodeId] = { ...defaults };
|
|
5551
|
+
}
|
|
5569
5552
|
for (const [oldId, inputs] of Object.entries(sourceInputs)) {
|
|
5570
5553
|
const newId = nodeIdMap[oldId];
|
|
5571
5554
|
if (newId) {
|
|
5572
|
-
const transformedInputs = {};
|
|
5573
|
-
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5574
|
-
// Ensure mergedInputs[newId] exists
|
|
5575
5555
|
if (!mergedInputs[newId]) {
|
|
5576
5556
|
mergedInputs[newId] = {};
|
|
5577
5557
|
}
|
|
5558
|
+
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5578
5559
|
for (const [handleId, value] of Object.entries(inputs)) {
|
|
5579
5560
|
const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
: value;
|
|
5590
|
-
// If converter returns null, delete this input
|
|
5591
|
-
if (convertedValue === null) {
|
|
5592
|
-
delete mergedInputs[newId][handleId];
|
|
5593
|
-
}
|
|
5594
|
-
else {
|
|
5595
|
-
// Otherwise, set the converted value
|
|
5596
|
-
transformedInputs[handleId] = convertedValue;
|
|
5597
|
-
}
|
|
5598
|
-
}
|
|
5599
|
-
// Merge transformed inputs
|
|
5600
|
-
if (Object.keys(transformedInputs).length > 0) {
|
|
5601
|
-
mergedInputs[newId] = { ...mergedInputs[newId], ...transformedInputs };
|
|
5602
|
-
}
|
|
5603
|
-
// Clean up empty node input objects
|
|
5604
|
-
if (Object.keys(mergedInputs[newId]).length === 0) {
|
|
5605
|
-
delete mergedInputs[newId];
|
|
5561
|
+
inputsToConvert.push({
|
|
5562
|
+
nodeId: newId,
|
|
5563
|
+
originalNodeId: oldId,
|
|
5564
|
+
handleId,
|
|
5565
|
+
value,
|
|
5566
|
+
nodeTypeId,
|
|
5567
|
+
handleDataType,
|
|
5568
|
+
});
|
|
5569
|
+
mergedInputs[newId][handleId] = value;
|
|
5606
5570
|
}
|
|
5607
5571
|
}
|
|
5608
5572
|
}
|
|
5609
5573
|
for (const [oldId, outputs] of Object.entries(sourceOutputs)) {
|
|
5610
5574
|
const newId = nodeIdMap[oldId];
|
|
5611
5575
|
if (newId) {
|
|
5612
|
-
const transformedOutputs = {};
|
|
5613
|
-
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5614
|
-
// Ensure mergedOutputs[newId] exists
|
|
5615
5576
|
if (!mergedOutputs[newId]) {
|
|
5616
5577
|
mergedOutputs[newId] = {};
|
|
5617
5578
|
}
|
|
5579
|
+
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5618
5580
|
for (const [handleId, value] of Object.entries(outputs)) {
|
|
5619
5581
|
const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
|
|
5620
5582
|
const runtimeTypeId = isTypedOutput(value)
|
|
5621
5583
|
? getTypedOutputTypeId(value)
|
|
5622
5584
|
: undefined;
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
: value;
|
|
5634
|
-
// If converter returns null, delete this output
|
|
5635
|
-
if (convertedValue === null) {
|
|
5636
|
-
delete mergedOutputs[newId][handleId];
|
|
5637
|
-
}
|
|
5638
|
-
else {
|
|
5639
|
-
// Otherwise, set the converted value
|
|
5640
|
-
transformedOutputs[handleId] = convertedValue;
|
|
5641
|
-
}
|
|
5585
|
+
outputsToConvert.push({
|
|
5586
|
+
nodeId: newId,
|
|
5587
|
+
originalNodeId: oldId,
|
|
5588
|
+
handleId,
|
|
5589
|
+
value,
|
|
5590
|
+
nodeTypeId,
|
|
5591
|
+
handleDataType,
|
|
5592
|
+
runtimeTypeId,
|
|
5593
|
+
});
|
|
5594
|
+
mergedOutputs[newId][handleId] = value;
|
|
5642
5595
|
}
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5596
|
+
}
|
|
5597
|
+
}
|
|
5598
|
+
for (const [oldId, defaults] of Object.entries(sourceInputDefaults)) {
|
|
5599
|
+
const newId = nodeIdMap[oldId];
|
|
5600
|
+
if (newId) {
|
|
5601
|
+
if (!mergedInputDefaults[newId]) {
|
|
5602
|
+
mergedInputDefaults[newId] = {};
|
|
5649
5603
|
}
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5604
|
+
const nodeTypeId = nodeTypeMap?.get(oldId);
|
|
5605
|
+
for (const [handleId, value] of Object.entries(defaults)) {
|
|
5606
|
+
const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
|
|
5607
|
+
inputDefaultsToConvert.push({
|
|
5608
|
+
nodeId: newId,
|
|
5609
|
+
originalNodeId: oldId,
|
|
5610
|
+
handleId,
|
|
5611
|
+
value,
|
|
5612
|
+
nodeTypeId,
|
|
5613
|
+
handleDataType,
|
|
5614
|
+
});
|
|
5615
|
+
mergedInputDefaults[newId][handleId] = value;
|
|
5653
5616
|
}
|
|
5654
5617
|
}
|
|
5655
5618
|
}
|
|
5656
|
-
return {
|
|
5619
|
+
return {
|
|
5620
|
+
mergedInputs,
|
|
5621
|
+
mergedOutputs,
|
|
5622
|
+
mergedInputDefaults,
|
|
5623
|
+
inputsToConvert,
|
|
5624
|
+
outputsToConvert,
|
|
5625
|
+
inputDefaultsToConvert,
|
|
5626
|
+
};
|
|
5657
5627
|
}
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
* Graph definition merging should be done separately using mergeGraphDefinitions.
|
|
5661
|
-
* UI positions are handled separately by mergeUIState.
|
|
5662
|
-
*/
|
|
5663
|
-
function mergeSnapshotData(targetSnapshot, sourceSnapshot, sourceDef, nodeIdMap, converter) {
|
|
5628
|
+
function mergeSnapshotData(targetSnapshot, sourceSnapshot, targetInputDefaults, sourceInputDefaults, nodeIdMap) {
|
|
5629
|
+
const sourceDef = sourceSnapshot.def ?? { nodes: []};
|
|
5664
5630
|
const nodeTypeMap = new Map();
|
|
5665
5631
|
const handleTypeMap = new Map();
|
|
5666
5632
|
for (const node of sourceDef.nodes) {
|
|
@@ -5690,10 +5656,66 @@ function mergeSnapshotData(targetSnapshot, sourceSnapshot, sourceDef, nodeIdMap,
|
|
|
5690
5656
|
handleTypeMap.set(node.nodeId, nodeHandleTypes);
|
|
5691
5657
|
}
|
|
5692
5658
|
}
|
|
5693
|
-
|
|
5659
|
+
return mergeInputsOutputs(targetSnapshot.inputs ?? {}, targetSnapshot.outputs ?? {}, sourceSnapshot.inputs ?? {}, sourceSnapshot.outputs ?? {}, targetInputDefaults, sourceInputDefaults, nodeIdMap, nodeTypeMap, handleTypeMap);
|
|
5660
|
+
}
|
|
5661
|
+
function mergeSnapshots(targetSnapshot, sourceSnapshot, converter) {
|
|
5662
|
+
const targetDef = targetSnapshot.def ?? { nodes: [], edges: [] };
|
|
5663
|
+
const sourceDef = sourceSnapshot.def ?? { nodes: [], edges: [] };
|
|
5664
|
+
const { merged, nodeIdMap, targetInputDefaults, sourceInputDefaults } = mergeGraphDefinitions(targetDef, sourceDef);
|
|
5665
|
+
const { mergedInputs, mergedOutputs, mergedInputDefaults, inputsToConvert, outputsToConvert, inputDefaultsToConvert, } = mergeSnapshotData(targetSnapshot, sourceSnapshot, targetInputDefaults, sourceInputDefaults, nodeIdMap);
|
|
5666
|
+
if (converter) {
|
|
5667
|
+
const applyConversion = (items, values, type) => {
|
|
5668
|
+
for (const item of items) {
|
|
5669
|
+
const convertedValue = converter({
|
|
5670
|
+
nodeId: item.nodeId,
|
|
5671
|
+
handleId: item.handleId,
|
|
5672
|
+
value: item.value,
|
|
5673
|
+
type,
|
|
5674
|
+
nodeTypeId: item.nodeTypeId,
|
|
5675
|
+
handleDataType: item.handleDataType,
|
|
5676
|
+
runtimeTypeId: item.runtimeTypeId,
|
|
5677
|
+
});
|
|
5678
|
+
if (convertedValue === null) {
|
|
5679
|
+
delete values[item.nodeId]?.[item.handleId];
|
|
5680
|
+
if (values[item.nodeId] &&
|
|
5681
|
+
Object.keys(values[item.nodeId]).length === 0) {
|
|
5682
|
+
delete values[item.nodeId];
|
|
5683
|
+
}
|
|
5684
|
+
}
|
|
5685
|
+
else {
|
|
5686
|
+
if (!values[item.nodeId]) {
|
|
5687
|
+
values[item.nodeId] = {};
|
|
5688
|
+
}
|
|
5689
|
+
values[item.nodeId][item.handleId] = convertedValue;
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
};
|
|
5693
|
+
applyConversion(inputDefaultsToConvert, mergedInputDefaults, "inputDefault");
|
|
5694
|
+
applyConversion(inputsToConvert, mergedInputs, "input");
|
|
5695
|
+
applyConversion(outputsToConvert, mergedOutputs, "output");
|
|
5696
|
+
}
|
|
5697
|
+
const nodeMap = new Map(merged.nodes.map((n) => [n.nodeId, n]));
|
|
5698
|
+
for (const nodeId in mergedInputDefaults) {
|
|
5699
|
+
const node = nodeMap.get(nodeId);
|
|
5700
|
+
if (node && Object.keys(mergedInputDefaults[nodeId]).length > 0) {
|
|
5701
|
+
if (!node.resolvedHandles) {
|
|
5702
|
+
node.resolvedHandles = {};
|
|
5703
|
+
}
|
|
5704
|
+
node.resolvedHandles.inputDefaults = mergedInputDefaults[nodeId];
|
|
5705
|
+
}
|
|
5706
|
+
}
|
|
5694
5707
|
return {
|
|
5695
|
-
|
|
5696
|
-
|
|
5708
|
+
merged: {
|
|
5709
|
+
def: merged,
|
|
5710
|
+
inputs: mergedInputs,
|
|
5711
|
+
outputs: mergedOutputs,
|
|
5712
|
+
environment: {
|
|
5713
|
+
...targetSnapshot.environment,
|
|
5714
|
+
...sourceSnapshot.environment,
|
|
5715
|
+
},
|
|
5716
|
+
extData: { ...targetSnapshot.extData, ...sourceSnapshot.extData },
|
|
5717
|
+
},
|
|
5718
|
+
nodeIdMap,
|
|
5697
5719
|
};
|
|
5698
5720
|
}
|
|
5699
5721
|
/**
|
|
@@ -5895,5 +5917,5 @@ function buildValueConverter(config) {
|
|
|
5895
5917
|
};
|
|
5896
5918
|
}
|
|
5897
5919
|
|
|
5898
|
-
export { BaseCompareOperation, BaseLogicOperation, BaseMathOperation, CompositeCategory, ComputeCategory, GraphBuilder, GraphRuntime, LevelLogger, LocalEngine, Registry, buildValueConverter, computeGraphCenter, createAsyncGraphDef, createAsyncGraphRegistry, createProgressGraphDef, createProgressGraphRegistry, createSimpleGraphDef, createSimpleGraphRegistry, createValidationGraphDef, createValidationGraphRegistry, findMatchingPaths, generateId, getInputHandleMetadata, getInputTypeId, getTypedOutputTypeId, getTypedOutputValue, getValueAtPath, installLogging, isInputPrivate, isTypedOutput,
|
|
5920
|
+
export { BaseCompareOperation, BaseLogicOperation, BaseMathOperation, CompositeCategory, ComputeCategory, GraphBuilder, GraphRuntime, LevelLogger, LocalEngine, Registry, buildValueConverter, computeGraphCenter, createAsyncGraphDef, createAsyncGraphRegistry, createProgressGraphDef, createProgressGraphRegistry, createSimpleGraphDef, createSimpleGraphRegistry, createValidationGraphDef, createValidationGraphRegistry, findMatchingPaths, generateId, getInputHandleMetadata, getInputTypeId, getTypedOutputTypeId, getTypedOutputValue, getValueAtPath, installLogging, isInputPrivate, isTypedOutput, mergeInputHandleDescriptors, mergeRuntimeState, mergeSnapshots, offsetImportedPositions, parseJsonPath, registerDelayNode, registerProgressNodes, setValueAtPath, setValueAtPathWithCreation, typed };
|
|
5899
5921
|
//# sourceMappingURL=index.js.map
|