@bian-womp/spark-graph 0.2.57 → 0.2.59
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 +110 -8
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/core/categories.d.ts +2 -2
- package/lib/cjs/src/core/categories.d.ts.map +1 -1
- package/lib/cjs/src/core/types.d.ts +4 -2
- package/lib/cjs/src/core/types.d.ts.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 +13 -1
- package/lib/cjs/src/misc/utils/merge.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/index.js +110 -8
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/core/categories.d.ts +2 -2
- package/lib/esm/src/core/categories.d.ts.map +1 -1
- package/lib/esm/src/core/types.d.ts +4 -2
- package/lib/esm/src/core/types.d.ts.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 +13 -1
- package/lib/esm/src/misc/utils/merge.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
|
@@ -402,6 +402,14 @@ class Registry {
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
+
const LOG_LEVEL_VALUES = {
|
|
406
|
+
debug: 0,
|
|
407
|
+
info: 1,
|
|
408
|
+
warn: 2,
|
|
409
|
+
error: 3,
|
|
410
|
+
silent: 4,
|
|
411
|
+
};
|
|
412
|
+
|
|
405
413
|
// Helper: typed promise detection and unwrapping for T | Promise<T>
|
|
406
414
|
function isPromise(value) {
|
|
407
415
|
return !!value && typeof value.then === "function";
|
|
@@ -476,6 +484,7 @@ class GraphRuntime {
|
|
|
476
484
|
...desc.policy,
|
|
477
485
|
...n.params?.policy,
|
|
478
486
|
},
|
|
487
|
+
logLevel: desc.logLevel,
|
|
479
488
|
runSeq: 0,
|
|
480
489
|
activeControllers: new Set(),
|
|
481
490
|
queue: [],
|
|
@@ -643,6 +652,36 @@ class GraphRuntime {
|
|
|
643
652
|
((p) => {
|
|
644
653
|
node.stats.progress = Math.max(0, Math.min(1, Number(p) || 0));
|
|
645
654
|
});
|
|
655
|
+
// Create log function that respects node's logLevel
|
|
656
|
+
const log = (level, message, context) => {
|
|
657
|
+
const nodeLogLevel = node.logLevel ?? "info"; // Default to "info" if not set
|
|
658
|
+
const nodeLogValue = LOG_LEVEL_VALUES[nodeLogLevel] ?? 1;
|
|
659
|
+
const requestedValue = LOG_LEVEL_VALUES[level] ?? 1;
|
|
660
|
+
// Only log if requested level >= node's logLevel
|
|
661
|
+
if (requestedValue >= nodeLogValue && nodeLogLevel !== "silent") {
|
|
662
|
+
const contextStr = context
|
|
663
|
+
? ` ${Object.entries(context)
|
|
664
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
665
|
+
.join(" ")}`
|
|
666
|
+
: "";
|
|
667
|
+
const fullMessage = `[node:${runId || nodeId}:${node.typeId}] ${message}${contextStr}`;
|
|
668
|
+
// For other levels, use appropriate console method
|
|
669
|
+
switch (level) {
|
|
670
|
+
case "debug":
|
|
671
|
+
console.info(fullMessage);
|
|
672
|
+
break;
|
|
673
|
+
case "info":
|
|
674
|
+
console.info(fullMessage);
|
|
675
|
+
break;
|
|
676
|
+
case "warn":
|
|
677
|
+
console.warn(fullMessage);
|
|
678
|
+
break;
|
|
679
|
+
case "error":
|
|
680
|
+
console.error(fullMessage);
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
646
685
|
return {
|
|
647
686
|
state: node.state,
|
|
648
687
|
setState: (next) => Object.assign(node.state, next),
|
|
@@ -658,6 +697,7 @@ class GraphRuntime {
|
|
|
658
697
|
runId,
|
|
659
698
|
abortSignal,
|
|
660
699
|
reportProgress,
|
|
700
|
+
log,
|
|
661
701
|
};
|
|
662
702
|
}
|
|
663
703
|
scheduleInputsChangedInternal(nodeId) {
|
|
@@ -722,7 +762,11 @@ class GraphRuntime {
|
|
|
722
762
|
const exec = async (attempt) => {
|
|
723
763
|
let hadError = false;
|
|
724
764
|
try {
|
|
725
|
-
node.lifecycle?.prepare
|
|
765
|
+
if (node.lifecycle?.prepare) {
|
|
766
|
+
ctx.log("debug", "prepare-start");
|
|
767
|
+
node.lifecycle.prepare(node.params ?? {}, ctx);
|
|
768
|
+
ctx.log("debug", "prepare-done");
|
|
769
|
+
}
|
|
726
770
|
await node.runtime.onInputsChanged?.(capturedInputs, ctx);
|
|
727
771
|
}
|
|
728
772
|
catch (err) {
|
|
@@ -763,12 +807,17 @@ class GraphRuntime {
|
|
|
763
807
|
runId,
|
|
764
808
|
durationMs: node.stats.lastDurationMs,
|
|
765
809
|
});
|
|
810
|
+
ctx.log("debug", "node-done", {
|
|
811
|
+
durationMs: node.stats.lastDurationMs,
|
|
812
|
+
hadError,
|
|
813
|
+
});
|
|
766
814
|
if (onDone)
|
|
767
815
|
onDone();
|
|
768
816
|
}
|
|
769
817
|
};
|
|
770
818
|
// fire node-start event
|
|
771
819
|
this.emit("stats", { kind: "node-start", nodeId, runId });
|
|
820
|
+
ctx.log("debug", "node-start");
|
|
772
821
|
exec(0);
|
|
773
822
|
};
|
|
774
823
|
const mode = policy.asyncConcurrency ?? "switch";
|
|
@@ -1167,7 +1216,11 @@ class GraphRuntime {
|
|
|
1167
1216
|
const effectiveInputs = this.getEffectiveInputs(node.nodeId);
|
|
1168
1217
|
const ctrl = new AbortController();
|
|
1169
1218
|
const ctx = this.createExecutionContext(node.nodeId, node, effectiveInputs, `${node.nodeId}:init`, ctrl.signal);
|
|
1170
|
-
node.lifecycle?.prepare
|
|
1219
|
+
if (node.lifecycle?.prepare) {
|
|
1220
|
+
ctx.log("debug", "prepare-start");
|
|
1221
|
+
node.lifecycle.prepare(node.params ?? {}, ctx);
|
|
1222
|
+
ctx.log("debug", "prepare-done");
|
|
1223
|
+
}
|
|
1171
1224
|
node.runtime.onActivated?.();
|
|
1172
1225
|
}
|
|
1173
1226
|
if (invalidate) {
|
|
@@ -1413,7 +1466,11 @@ class GraphRuntime {
|
|
|
1413
1466
|
const effectiveInputs = this.getEffectiveInputs(rn.nodeId);
|
|
1414
1467
|
const ctrl = new AbortController();
|
|
1415
1468
|
const ctx = this.createExecutionContext(rn.nodeId, rn, effectiveInputs, `${rn.nodeId}:init`, ctrl.signal);
|
|
1416
|
-
rn.lifecycle?.prepare
|
|
1469
|
+
if (rn.lifecycle?.prepare) {
|
|
1470
|
+
ctx.log("debug", "prepare-start");
|
|
1471
|
+
rn.lifecycle.prepare(rn.params ?? {}, ctx);
|
|
1472
|
+
ctx.log("debug", "prepare-done");
|
|
1473
|
+
}
|
|
1417
1474
|
rn.runtime.onActivated?.();
|
|
1418
1475
|
}
|
|
1419
1476
|
else {
|
|
@@ -1601,6 +1658,13 @@ class GraphRuntime {
|
|
|
1601
1658
|
return;
|
|
1602
1659
|
const token = (this.recomputeTokenByNode.get(nodeId) ?? 0) + 1;
|
|
1603
1660
|
this.recomputeTokenByNode.set(nodeId, token);
|
|
1661
|
+
// Log resolveHandles-start
|
|
1662
|
+
const nodeLogLevel = node.logLevel ?? "info";
|
|
1663
|
+
const nodeLogValue = LOG_LEVEL_VALUES[nodeLogLevel] ?? 1;
|
|
1664
|
+
const shouldLog = nodeLogValue <= LOG_LEVEL_VALUES.debug && nodeLogLevel !== "silent";
|
|
1665
|
+
if (shouldLog) {
|
|
1666
|
+
console.info(`[node:${nodeId}:${node.typeId}] resolveHandles-start`);
|
|
1667
|
+
}
|
|
1604
1668
|
let r;
|
|
1605
1669
|
try {
|
|
1606
1670
|
const res = resolveHandles({
|
|
@@ -1611,8 +1675,16 @@ class GraphRuntime {
|
|
|
1611
1675
|
r = await unwrapMaybePromise(res);
|
|
1612
1676
|
}
|
|
1613
1677
|
catch {
|
|
1678
|
+
// Log resolveHandles-done even on error
|
|
1679
|
+
if (shouldLog) {
|
|
1680
|
+
console.info(`[node:${nodeId}:${node.typeId}] resolveHandles-done (error)`);
|
|
1681
|
+
}
|
|
1614
1682
|
return;
|
|
1615
1683
|
}
|
|
1684
|
+
// Log resolveHandles-done
|
|
1685
|
+
if (shouldLog) {
|
|
1686
|
+
console.info(`[node:${nodeId}:${node.typeId}] resolveHandles-done`);
|
|
1687
|
+
}
|
|
1616
1688
|
// If a newer recompute was scheduled, drop this result
|
|
1617
1689
|
if ((this.recomputeTokenByNode.get(nodeId) ?? 0) !== token)
|
|
1618
1690
|
return;
|
|
@@ -3694,7 +3766,14 @@ function mergeGraphDefinitions(target, source, converter) {
|
|
|
3694
3766
|
? transformedNode.resolvedHandles.inputs[handleId]
|
|
3695
3767
|
: transformedNode.resolvedHandles.inputs[handleId]?.typeId
|
|
3696
3768
|
: undefined;
|
|
3697
|
-
transformedInitialInputs[handleId] = converter(
|
|
3769
|
+
transformedInitialInputs[handleId] = converter({
|
|
3770
|
+
nodeId: newId,
|
|
3771
|
+
handleId,
|
|
3772
|
+
value,
|
|
3773
|
+
type: "initialInput",
|
|
3774
|
+
nodeTypeId,
|
|
3775
|
+
handleDataType,
|
|
3776
|
+
});
|
|
3698
3777
|
}
|
|
3699
3778
|
transformedNode.initialInputs = transformedInitialInputs;
|
|
3700
3779
|
}
|
|
@@ -3707,7 +3786,14 @@ function mergeGraphDefinitions(target, source, converter) {
|
|
|
3707
3786
|
? transformedNode.resolvedHandles.inputs[handleId]
|
|
3708
3787
|
: transformedNode.resolvedHandles.inputs[handleId]?.typeId
|
|
3709
3788
|
: undefined;
|
|
3710
|
-
transformedInputDefaults[handleId] = converter(
|
|
3789
|
+
transformedInputDefaults[handleId] = converter({
|
|
3790
|
+
nodeId: newId,
|
|
3791
|
+
handleId,
|
|
3792
|
+
value,
|
|
3793
|
+
type: "inputDefault",
|
|
3794
|
+
nodeTypeId,
|
|
3795
|
+
handleDataType,
|
|
3796
|
+
});
|
|
3711
3797
|
}
|
|
3712
3798
|
transformedNode.resolvedHandles = {
|
|
3713
3799
|
...transformedNode.resolvedHandles,
|
|
@@ -3805,7 +3891,14 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
3805
3891
|
for (const [handleId, value] of Object.entries(inputs)) {
|
|
3806
3892
|
const handleDataType = handleTypeMap?.get(oldId)?.get(handleId);
|
|
3807
3893
|
transformedInputs[handleId] = converter
|
|
3808
|
-
? converter(
|
|
3894
|
+
? converter({
|
|
3895
|
+
nodeId: newId,
|
|
3896
|
+
handleId,
|
|
3897
|
+
value,
|
|
3898
|
+
type: "input",
|
|
3899
|
+
nodeTypeId,
|
|
3900
|
+
handleDataType,
|
|
3901
|
+
})
|
|
3809
3902
|
: value;
|
|
3810
3903
|
}
|
|
3811
3904
|
mergedInputs[newId] = mergedInputs[newId]
|
|
@@ -3824,7 +3917,15 @@ function mergeInputsOutputs(targetInputs, targetOutputs, sourceInputs, sourceOut
|
|
|
3824
3917
|
? getTypedOutputTypeId(value)
|
|
3825
3918
|
: undefined;
|
|
3826
3919
|
transformedOutputs[handleId] = converter
|
|
3827
|
-
? converter(
|
|
3920
|
+
? converter({
|
|
3921
|
+
nodeId: newId,
|
|
3922
|
+
handleId,
|
|
3923
|
+
value,
|
|
3924
|
+
type: "output",
|
|
3925
|
+
nodeTypeId,
|
|
3926
|
+
handleDataType,
|
|
3927
|
+
runtimeTypeId,
|
|
3928
|
+
})
|
|
3828
3929
|
: value;
|
|
3829
3930
|
}
|
|
3830
3931
|
mergedOutputs[newId] = mergedOutputs[newId]
|
|
@@ -3897,7 +3998,8 @@ function matchesPattern(value, pattern) {
|
|
|
3897
3998
|
* - value exists in valueMap
|
|
3898
3999
|
*/
|
|
3899
4000
|
function buildValueConverter(config) {
|
|
3900
|
-
return (
|
|
4001
|
+
return (converterConfig) => {
|
|
4002
|
+
const { nodeId, handleId, value, type, nodeTypeId, handleDataType, runtimeTypeId, } = converterConfig;
|
|
3901
4003
|
const isTyped = isTypedOutput(value);
|
|
3902
4004
|
for (const mapping of config.mappings) {
|
|
3903
4005
|
if (!matchesPattern(handleId, mapping.handleId))
|