@bian-womp/spark-graph 0.2.54 → 0.2.55

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/esm/index.js CHANGED
@@ -3258,6 +3258,20 @@ function registerProgressNodes(registry) {
3258
3258
  },
3259
3259
  });
3260
3260
  }
3261
+ function generateId(prefix, used = new Set()) {
3262
+ let id;
3263
+ let attempts = 0;
3264
+ do {
3265
+ id = `${prefix}${Math.random().toString(36).slice(2, 8)}`;
3266
+ attempts++;
3267
+ if (attempts > 1000) {
3268
+ id = `${prefix}${Date.now().toString(36)}${Math.random()
3269
+ .toString(36)
3270
+ .slice(2, 4)}`;
3271
+ }
3272
+ } while (used.has(id));
3273
+ return id;
3274
+ }
3261
3275
 
3262
3276
  function installLogging(engine) {
3263
3277
  engine.on("value", (e) => {
@@ -3473,5 +3487,561 @@ function createValidationGraphRegistry() {
3473
3487
  return registry;
3474
3488
  }
3475
3489
 
3476
- export { BatchedEngine, CompositeCategory, ComputeCategory, GraphBuilder, GraphRuntime, HybridEngine, PullEngine, PushEngine, Registry, StepEngine, createAsyncGraphDef, createAsyncGraphRegistry, createEngine, createProgressGraphDef, createProgressGraphRegistry, createSimpleGraphDef, createSimpleGraphRegistry, createValidationGraphDef, createValidationGraphRegistry, getInputTypeId, getTypedOutputTypeId, getTypedOutputValue, installLogging, isInputPrivate, isTypedOutput, registerDelayNode, registerProgressNodes, typed };
3490
+ function parseJsonPath(path) {
3491
+ if (typeof path === "string") {
3492
+ return path.split(".").flatMap((segment) => {
3493
+ const arrayMatch = segment.match(/^(.+)\[(\d+)\]$/);
3494
+ if (arrayMatch) {
3495
+ const index = parseInt(arrayMatch[2], 10);
3496
+ return arrayMatch[1] ? [arrayMatch[1], index] : [index];
3497
+ }
3498
+ return [segment];
3499
+ });
3500
+ }
3501
+ return path;
3502
+ }
3503
+ function getValueAtPath(obj, pathSegments) {
3504
+ if (pathSegments.length === 0) {
3505
+ return { value: obj, parent: null, key: "" };
3506
+ }
3507
+ let current = obj;
3508
+ for (let i = 0; i < pathSegments.length - 1; i++) {
3509
+ const segment = pathSegments[i];
3510
+ if (current === null ||
3511
+ current === undefined ||
3512
+ typeof current !== "object") {
3513
+ return null;
3514
+ }
3515
+ if (typeof segment === "string") {
3516
+ if (Array.isArray(current)) {
3517
+ const index = parseInt(segment, 10);
3518
+ if (isNaN(index))
3519
+ return null;
3520
+ current = current[index];
3521
+ }
3522
+ else {
3523
+ current = current[segment];
3524
+ }
3525
+ }
3526
+ else if (typeof segment === "number") {
3527
+ if (Array.isArray(current)) {
3528
+ if (segment >= 0 && segment < current.length) {
3529
+ current = current[segment];
3530
+ }
3531
+ else {
3532
+ return null;
3533
+ }
3534
+ }
3535
+ else {
3536
+ return null;
3537
+ }
3538
+ }
3539
+ else if (segment instanceof RegExp) {
3540
+ if (Array.isArray(current)) {
3541
+ return null;
3542
+ }
3543
+ const obj = current;
3544
+ const matchingKey = Object.keys(obj).find((key) => segment.test(key));
3545
+ if (!matchingKey)
3546
+ return null;
3547
+ current = obj[matchingKey];
3548
+ }
3549
+ else {
3550
+ return null;
3551
+ }
3552
+ }
3553
+ const lastSegment = pathSegments[pathSegments.length - 1];
3554
+ if (typeof lastSegment === "string") {
3555
+ if (Array.isArray(current)) {
3556
+ const index = parseInt(lastSegment, 10);
3557
+ if (isNaN(index))
3558
+ return null;
3559
+ return { value: current[index], parent: current, key: index };
3560
+ }
3561
+ else if (current !== null &&
3562
+ current !== undefined &&
3563
+ typeof current === "object") {
3564
+ return {
3565
+ value: current[lastSegment],
3566
+ parent: current,
3567
+ key: lastSegment,
3568
+ };
3569
+ }
3570
+ }
3571
+ else if (typeof lastSegment === "number") {
3572
+ if (Array.isArray(current)) {
3573
+ if (lastSegment >= 0 && lastSegment < current.length) {
3574
+ return {
3575
+ value: current[lastSegment],
3576
+ parent: current,
3577
+ key: lastSegment,
3578
+ };
3579
+ }
3580
+ }
3581
+ return null;
3582
+ }
3583
+ else if (lastSegment instanceof RegExp) {
3584
+ if (Array.isArray(current)) {
3585
+ return null;
3586
+ }
3587
+ const obj = current;
3588
+ const matchingKey = Object.keys(obj).find((key) => lastSegment.test(key));
3589
+ if (!matchingKey)
3590
+ return null;
3591
+ return { value: obj[matchingKey], parent: current, key: matchingKey };
3592
+ }
3593
+ return null;
3594
+ }
3595
+ function setValueAtPath(obj, pathSegments, newValue) {
3596
+ const result = getValueAtPath(obj, pathSegments);
3597
+ if (!result || result.parent === null)
3598
+ return false;
3599
+ if (Array.isArray(result.parent)) {
3600
+ result.parent[result.key] = newValue;
3601
+ }
3602
+ else {
3603
+ result.parent[result.key] = newValue;
3604
+ }
3605
+ return true;
3606
+ }
3607
+ function findMatchingPaths(obj, pathSegments, currentPath = []) {
3608
+ if (pathSegments.length === 0) {
3609
+ return [{ path: currentPath, value: obj }];
3610
+ }
3611
+ const [currentSegment, ...remainingSegments] = pathSegments;
3612
+ const results = [];
3613
+ if (currentSegment === undefined) {
3614
+ return results;
3615
+ }
3616
+ if (typeof currentSegment === "string") {
3617
+ if (Array.isArray(obj)) {
3618
+ const index = parseInt(currentSegment, 10);
3619
+ if (!isNaN(index) && index >= 0 && index < obj.length) {
3620
+ results.push(...findMatchingPaths(obj[index], remainingSegments, [
3621
+ ...currentPath,
3622
+ index,
3623
+ ]));
3624
+ }
3625
+ }
3626
+ else if (obj !== null && obj !== undefined && typeof obj === "object") {
3627
+ const objRecord = obj;
3628
+ if (currentSegment in objRecord) {
3629
+ results.push(...findMatchingPaths(objRecord[currentSegment], remainingSegments, [
3630
+ ...currentPath,
3631
+ currentSegment,
3632
+ ]));
3633
+ }
3634
+ }
3635
+ }
3636
+ else if (typeof currentSegment === "number") {
3637
+ if (Array.isArray(obj)) {
3638
+ if (currentSegment >= 0 && currentSegment < obj.length) {
3639
+ results.push(...findMatchingPaths(obj[currentSegment], remainingSegments, [
3640
+ ...currentPath,
3641
+ currentSegment,
3642
+ ]));
3643
+ }
3644
+ }
3645
+ }
3646
+ else if (currentSegment instanceof RegExp) {
3647
+ if (Array.isArray(obj)) {
3648
+ for (let i = 0; i < obj.length; i++) {
3649
+ results.push(...findMatchingPaths(obj[i], remainingSegments, [...currentPath, i]));
3650
+ }
3651
+ }
3652
+ else if (obj !== null && obj !== undefined && typeof obj === "object") {
3653
+ const objRecord = obj;
3654
+ for (const key of Object.keys(objRecord)) {
3655
+ if (currentSegment.test(key)) {
3656
+ results.push(...findMatchingPaths(objRecord[key], remainingSegments, [
3657
+ ...currentPath,
3658
+ key,
3659
+ ]));
3660
+ }
3661
+ }
3662
+ }
3663
+ }
3664
+ return results;
3665
+ }
3666
+
3667
+ function mergeGraphDefinitions(target, source, converter) {
3668
+ const existingNodeIds = new Set(target.nodes.map((n) => n.nodeId));
3669
+ const existingEdgeIds = new Set(target.edges.map((e) => e.id));
3670
+ const nodeIdMap = {};
3671
+ const importedNodes = source.nodes.map((n) => {
3672
+ let newId = n.nodeId;
3673
+ if (existingNodeIds.has(newId)) {
3674
+ newId = generateId("n", existingNodeIds);
3675
+ }
3676
+ else {
3677
+ existingNodeIds.add(newId);
3678
+ }
3679
+ nodeIdMap[n.nodeId] = newId;
3680
+ const transformedNode = {
3681
+ ...n,
3682
+ nodeId: newId,
3683
+ };
3684
+ if (converter) {
3685
+ const nodeTypeId = transformedNode.typeId;
3686
+ if (transformedNode.initialInputs) {
3687
+ const transformedInitialInputs = {};
3688
+ for (const [handleId, value] of Object.entries(transformedNode.initialInputs)) {
3689
+ const handleDataType = transformedNode.resolvedHandles?.inputs?.[handleId]
3690
+ ? typeof transformedNode.resolvedHandles.inputs[handleId] ===
3691
+ "string"
3692
+ ? transformedNode.resolvedHandles.inputs[handleId]
3693
+ : transformedNode.resolvedHandles.inputs[handleId]?.typeId
3694
+ : undefined;
3695
+ transformedInitialInputs[handleId] = converter(newId, handleId, value, "initialInput", nodeTypeId, handleDataType);
3696
+ }
3697
+ transformedNode.initialInputs = transformedInitialInputs;
3698
+ }
3699
+ if (transformedNode.resolvedHandles?.inputDefaults) {
3700
+ const transformedInputDefaults = {};
3701
+ for (const [handleId, value] of Object.entries(transformedNode.resolvedHandles.inputDefaults)) {
3702
+ const handleDataType = transformedNode.resolvedHandles?.inputs?.[handleId]
3703
+ ? typeof transformedNode.resolvedHandles.inputs[handleId] ===
3704
+ "string"
3705
+ ? transformedNode.resolvedHandles.inputs[handleId]
3706
+ : transformedNode.resolvedHandles.inputs[handleId]?.typeId
3707
+ : undefined;
3708
+ transformedInputDefaults[handleId] = converter(newId, handleId, value, "inputDefault", nodeTypeId, handleDataType);
3709
+ }
3710
+ transformedNode.resolvedHandles = {
3711
+ ...transformedNode.resolvedHandles,
3712
+ inputDefaults: transformedInputDefaults,
3713
+ };
3714
+ }
3715
+ }
3716
+ return transformedNode;
3717
+ });
3718
+ const importedEdges = source.edges.map((e) => {
3719
+ let newEdgeId = e.id;
3720
+ if (existingEdgeIds.has(newEdgeId)) {
3721
+ newEdgeId = generateId("e", existingEdgeIds);
3722
+ }
3723
+ else {
3724
+ existingEdgeIds.add(newEdgeId);
3725
+ }
3726
+ const sourceNodeId = nodeIdMap[e.source.nodeId] ?? e.source.nodeId;
3727
+ const targetNodeId = nodeIdMap[e.target.nodeId] ?? e.target.nodeId;
3728
+ return {
3729
+ ...e,
3730
+ id: newEdgeId,
3731
+ source: {
3732
+ ...e.source,
3733
+ nodeId: sourceNodeId,
3734
+ },
3735
+ target: {
3736
+ ...e.target,
3737
+ nodeId: targetNodeId,
3738
+ },
3739
+ };
3740
+ });
3741
+ return {
3742
+ merged: {
3743
+ nodes: [...target.nodes, ...importedNodes],
3744
+ edges: [...target.edges, ...importedEdges],
3745
+ },
3746
+ nodeIdMap,
3747
+ };
3748
+ }
3749
+ /**
3750
+ * Compute the center point of a graph based on node positions.
3751
+ */
3752
+ function computeGraphCenter(positions, nodeIds) {
3753
+ const validPositions = nodeIds
3754
+ .map((id) => positions[id])
3755
+ .filter((pos) => pos !== undefined);
3756
+ if (validPositions.length === 0) {
3757
+ return { x: 0, y: 0 };
3758
+ }
3759
+ const minX = Math.min(...validPositions.map((p) => p.x));
3760
+ const maxX = Math.max(...validPositions.map((p) => p.x));
3761
+ const minY = Math.min(...validPositions.map((p) => p.y));
3762
+ const maxY = Math.max(...validPositions.map((p) => p.y));
3763
+ return {
3764
+ x: (minX + maxX) / 2,
3765
+ y: (minY + maxY) / 2,
3766
+ };
3767
+ }
3768
+ /**
3769
+ * Offset positions of imported nodes based on an anchor point.
3770
+ * Preserves relative layout of imported nodes while positioning them at the anchor.
3771
+ */
3772
+ function offsetImportedPositions(targetPositions, sourcePositions, sourceDef, nodeIdMap, anchorPos) {
3773
+ const sourceNodeIds = sourceDef.nodes.map((n) => n.nodeId);
3774
+ const sourceCenter = computeGraphCenter(sourcePositions, sourceNodeIds);
3775
+ const dx = anchorPos.x - sourceCenter.x;
3776
+ const dy = anchorPos.y - sourceCenter.y;
3777
+ const newPositions = {
3778
+ ...targetPositions,
3779
+ };
3780
+ for (const node of sourceDef.nodes) {
3781
+ const oldId = node.nodeId;
3782
+ const newId = nodeIdMap[oldId];
3783
+ const srcPos = sourcePositions[oldId] ?? { x: 0, y: 0 };
3784
+ newPositions[newId] = {
3785
+ x: srcPos.x + dx,
3786
+ y: srcPos.y + dy,
3787
+ };
3788
+ }
3789
+ return newPositions;
3790
+ }
3791
+ /**
3792
+ * Merge inputs and outputs from source into target, remapping node IDs.
3793
+ * Source values override target when merging.
3794
+ */
3795
+ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOutputs, nodeIdMap, converter, nodeTypeMap, handleTypeMap) {
3796
+ const mergedInputs = { ...targetInputs };
3797
+ const mergedOutputs = { ...targetOutputs };
3798
+ for (const [oldId, inputs] of Object.entries(sourceInputs)) {
3799
+ const newId = nodeIdMap[oldId];
3800
+ if (newId) {
3801
+ const transformedInputs = {};
3802
+ const nodeTypeId = nodeTypeMap?.get(oldId);
3803
+ for (const [handleId, value] of Object.entries(inputs)) {
3804
+ const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
3805
+ transformedInputs[handleId] = converter
3806
+ ? converter(newId, handleId, value, "input", nodeTypeId, handleDataType)
3807
+ : value;
3808
+ }
3809
+ mergedInputs[newId] = mergedInputs[newId]
3810
+ ? { ...mergedInputs[newId], ...transformedInputs }
3811
+ : transformedInputs;
3812
+ }
3813
+ }
3814
+ for (const [oldId, outputs] of Object.entries(sourceOutputs)) {
3815
+ const newId = nodeIdMap[oldId];
3816
+ if (newId) {
3817
+ const transformedOutputs = {};
3818
+ const nodeTypeId = nodeTypeMap?.get(oldId);
3819
+ for (const [handleId, value] of Object.entries(outputs)) {
3820
+ const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
3821
+ const runtimeTypeId = isTypedOutput(value)
3822
+ ? getTypedOutputTypeId(value)
3823
+ : undefined;
3824
+ transformedOutputs[handleId] = converter
3825
+ ? converter(newId, handleId, value, "output", nodeTypeId, handleDataType, runtimeTypeId)
3826
+ : value;
3827
+ }
3828
+ mergedOutputs[newId] = mergedOutputs[newId]
3829
+ ? { ...mergedOutputs[newId], ...transformedOutputs }
3830
+ : transformedOutputs;
3831
+ }
3832
+ }
3833
+ return { mergedInputs, mergedOutputs };
3834
+ }
3835
+ /**
3836
+ * Merge snapshot data (inputs, outputs, UI positions) from source into target.
3837
+ * Graph definition merging should be done separately using mergeGraphDefinitions.
3838
+ */
3839
+ function mergeSnapshotData(targetSnapshot, sourceSnapshot, sourceDef, nodeIdMap, anchorPos, converter) {
3840
+ const nodeTypeMap = new Map();
3841
+ const handleTypeMap = new Map();
3842
+ for (const node of sourceDef.nodes) {
3843
+ nodeTypeMap.set(node.nodeId, node.typeId);
3844
+ const nodeHandleTypes = new Map();
3845
+ if (node.resolvedHandles?.inputs) {
3846
+ for (const [handleId, handleDesc] of Object.entries(node.resolvedHandles.inputs)) {
3847
+ const typeId = typeof handleDesc === "string"
3848
+ ? handleDesc
3849
+ : handleDesc?.typeId;
3850
+ if (typeId)
3851
+ nodeHandleTypes.set(handleId, typeId);
3852
+ }
3853
+ }
3854
+ if (node.resolvedHandles?.outputs) {
3855
+ for (const [handleId, handleDesc] of Object.entries(node.resolvedHandles.outputs)) {
3856
+ const typeId = typeof handleDesc === "string"
3857
+ ? handleDesc
3858
+ : Array.isArray(handleDesc)
3859
+ ? handleDesc[0]
3860
+ : undefined;
3861
+ if (typeId)
3862
+ nodeHandleTypes.set(handleId, typeId);
3863
+ }
3864
+ }
3865
+ if (nodeHandleTypes.size > 0) {
3866
+ handleTypeMap.set(node.nodeId, nodeHandleTypes);
3867
+ }
3868
+ }
3869
+ const { mergedInputs, mergedOutputs } = mergeInputsOutputs(targetSnapshot.inputs ?? {}, targetSnapshot.outputs ?? {}, sourceSnapshot.inputs ?? {}, sourceSnapshot.outputs ?? {}, nodeIdMap, converter, nodeTypeMap, handleTypeMap);
3870
+ const targetUI = targetSnapshot.extData?.ui || {};
3871
+ const sourceUI = sourceSnapshot.extData?.ui || {};
3872
+ const mergedPositions = offsetImportedPositions(targetUI.positions ?? {}, sourceUI.positions ?? {}, sourceDef, nodeIdMap, anchorPos);
3873
+ return {
3874
+ mergedInputs,
3875
+ mergedOutputs,
3876
+ mergedPositions,
3877
+ };
3878
+ }
3879
+ function matchesPattern(value, pattern) {
3880
+ if (!pattern)
3881
+ return true;
3882
+ if (typeof pattern === "string") {
3883
+ return value === pattern;
3884
+ }
3885
+ return pattern.test(value);
3886
+ }
3887
+ /**
3888
+ * Build a converter function from a configuration that maps values based on handle/node matching.
3889
+ * The converter will replace values when:
3890
+ * - handleId matches (if specified)
3891
+ * - nodeId matches (if specified)
3892
+ * - nodeTypeId matches (if specified)
3893
+ * - handleDataType matches (if specified)
3894
+ * - runtimeTypeId matches (if specified, for typed outputs)
3895
+ * - value exists in valueMap
3896
+ */
3897
+ function buildValueConverter(config) {
3898
+ return (nodeId, handleId, value, type, nodeTypeId, handleDataType, runtimeTypeId) => {
3899
+ const isTyped = isTypedOutput(value);
3900
+ for (const mapping of config.mappings) {
3901
+ if (!matchesPattern(handleId, mapping.handleId))
3902
+ continue;
3903
+ if (!matchesPattern(nodeId, mapping.nodeId))
3904
+ continue;
3905
+ if (mapping.nodeTypeId && nodeTypeId) {
3906
+ if (!matchesPattern(nodeTypeId, mapping.nodeTypeId))
3907
+ continue;
3908
+ }
3909
+ if (mapping.handleDataType && handleDataType) {
3910
+ if (!matchesPattern(handleDataType, mapping.handleDataType))
3911
+ continue;
3912
+ }
3913
+ if (mapping.runtimeTypeId && runtimeTypeId) {
3914
+ if (!matchesPattern(runtimeTypeId, mapping.runtimeTypeId))
3915
+ continue;
3916
+ }
3917
+ if (mapping.transformTypedValue && isTyped) {
3918
+ const innerValue = getTypedOutputValue(value);
3919
+ const typedTypeId = getTypedOutputTypeId(value);
3920
+ if (!typedTypeId)
3921
+ continue;
3922
+ if (mapping.path !== undefined) {
3923
+ const pathSegments = parseJsonPath(mapping.path);
3924
+ const matches = findMatchingPaths(innerValue, pathSegments);
3925
+ if (matches.length > 0) {
3926
+ const transformedInner = JSON.parse(JSON.stringify(innerValue));
3927
+ let changed = false;
3928
+ for (const match of matches) {
3929
+ const matchValue = match.value;
3930
+ if (matchValue !== null && matchValue !== undefined) {
3931
+ let newValue = matchValue;
3932
+ if (mapping.valueMap instanceof Map) {
3933
+ if (mapping.valueMap.has(matchValue)) {
3934
+ newValue = mapping.valueMap.get(matchValue);
3935
+ changed = true;
3936
+ }
3937
+ }
3938
+ else {
3939
+ if (typeof matchValue === "string" ||
3940
+ typeof matchValue === "number") {
3941
+ if (matchValue in mapping.valueMap) {
3942
+ newValue = mapping.valueMap[matchValue];
3943
+ changed = true;
3944
+ }
3945
+ }
3946
+ }
3947
+ if (changed && newValue !== matchValue) {
3948
+ setValueAtPath(transformedInner, match.path, newValue);
3949
+ }
3950
+ }
3951
+ }
3952
+ return changed ? typed(typedTypeId, transformedInner) : value;
3953
+ }
3954
+ }
3955
+ else {
3956
+ if (innerValue !== null && innerValue !== undefined) {
3957
+ let newValue = innerValue;
3958
+ if (mapping.valueMap instanceof Map) {
3959
+ if (mapping.valueMap.has(innerValue)) {
3960
+ newValue = mapping.valueMap.get(innerValue);
3961
+ return typed(typedTypeId, newValue);
3962
+ }
3963
+ }
3964
+ else {
3965
+ if (typeof innerValue === "string" ||
3966
+ typeof innerValue === "number") {
3967
+ if (innerValue in mapping.valueMap) {
3968
+ newValue = mapping.valueMap[innerValue];
3969
+ return typed(typedTypeId, newValue);
3970
+ }
3971
+ }
3972
+ }
3973
+ }
3974
+ }
3975
+ continue;
3976
+ }
3977
+ if (mapping.path !== undefined) {
3978
+ let pathSegments = parseJsonPath(mapping.path);
3979
+ if (isTyped) {
3980
+ const typedTypeId = getTypedOutputTypeId(value);
3981
+ if (typedTypeId) {
3982
+ const firstSegment = pathSegments[0];
3983
+ const firstSegmentStr = typeof firstSegment === "string"
3984
+ ? firstSegment
3985
+ : firstSegment instanceof RegExp
3986
+ ? null
3987
+ : String(firstSegment);
3988
+ if (firstSegmentStr !== "__spark_value" &&
3989
+ firstSegmentStr !== "__spark_type") {
3990
+ pathSegments = ["__spark_value", ...pathSegments];
3991
+ }
3992
+ }
3993
+ }
3994
+ const matches = findMatchingPaths(value, pathSegments);
3995
+ if (matches.length > 0) {
3996
+ const transformedValue = JSON.parse(JSON.stringify(value));
3997
+ let changed = false;
3998
+ for (const match of matches) {
3999
+ const matchValue = match.value;
4000
+ if (matchValue !== null && matchValue !== undefined) {
4001
+ let newValue = matchValue;
4002
+ if (mapping.valueMap instanceof Map) {
4003
+ if (mapping.valueMap.has(matchValue)) {
4004
+ newValue = mapping.valueMap.get(matchValue);
4005
+ changed = true;
4006
+ }
4007
+ }
4008
+ else {
4009
+ if (typeof matchValue === "string" ||
4010
+ typeof matchValue === "number") {
4011
+ if (matchValue in mapping.valueMap) {
4012
+ newValue = mapping.valueMap[matchValue];
4013
+ changed = true;
4014
+ }
4015
+ }
4016
+ }
4017
+ if (changed && newValue !== matchValue) {
4018
+ setValueAtPath(transformedValue, match.path, newValue);
4019
+ }
4020
+ }
4021
+ }
4022
+ return changed ? transformedValue : value;
4023
+ }
4024
+ }
4025
+ else {
4026
+ if (value !== null && value !== undefined) {
4027
+ if (mapping.valueMap instanceof Map) {
4028
+ if (mapping.valueMap.has(value)) {
4029
+ return mapping.valueMap.get(value);
4030
+ }
4031
+ }
4032
+ else {
4033
+ if (typeof value === "string" || typeof value === "number") {
4034
+ if (value in mapping.valueMap) {
4035
+ return mapping.valueMap[value];
4036
+ }
4037
+ }
4038
+ }
4039
+ }
4040
+ }
4041
+ }
4042
+ return value;
4043
+ };
4044
+ }
4045
+
4046
+ export { BatchedEngine, CompositeCategory, ComputeCategory, GraphBuilder, GraphRuntime, HybridEngine, PullEngine, PushEngine, Registry, StepEngine, buildValueConverter, computeGraphCenter, createAsyncGraphDef, createAsyncGraphRegistry, createEngine, createProgressGraphDef, createProgressGraphRegistry, createSimpleGraphDef, createSimpleGraphRegistry, createValidationGraphDef, createValidationGraphRegistry, findMatchingPaths, generateId, getInputTypeId, getTypedOutputTypeId, getTypedOutputValue, getValueAtPath, installLogging, isInputPrivate, isTypedOutput, mergeGraphDefinitions, mergeInputsOutputs, mergeSnapshotData, offsetImportedPositions, parseJsonPath, registerDelayNode, registerProgressNodes, setValueAtPath, typed };
3477
4047
  //# sourceMappingURL=index.js.map