@bian-womp/spark-graph 0.2.35 → 0.2.37
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
CHANGED
|
@@ -521,10 +521,43 @@ class GraphRuntime {
|
|
|
521
521
|
const hasInbound = this.edges.some((e) => e.target.nodeId === nodeId && e.target.handle === handle);
|
|
522
522
|
if (hasInbound)
|
|
523
523
|
continue;
|
|
524
|
+
// Validate input value against declared type
|
|
525
|
+
if (value !== undefined && this.registry) {
|
|
526
|
+
const desc = this.registry.nodes.get(node.typeId);
|
|
527
|
+
const resolved = this.resolvedByNode.get(nodeId);
|
|
528
|
+
// Get typeId from resolved handles first, then registry statics
|
|
529
|
+
const typeId = resolved
|
|
530
|
+
? getInputTypeId(resolved.inputs, handle)
|
|
531
|
+
: desc
|
|
532
|
+
? getInputTypeId(desc.inputs, handle)
|
|
533
|
+
: undefined;
|
|
534
|
+
if (typeId) {
|
|
535
|
+
const typeDesc = this.registry.types.get(typeId);
|
|
536
|
+
if (typeDesc?.validate && !typeDesc.validate(value)) {
|
|
537
|
+
// Emit error event for invalid input value and reject it
|
|
538
|
+
const errorMessage = `Invalid value for input ${nodeId}.${handle} (type ${typeId}): ${JSON.stringify(value)}`;
|
|
539
|
+
this.emit("error", {
|
|
540
|
+
kind: "input-validation",
|
|
541
|
+
nodeId,
|
|
542
|
+
handle,
|
|
543
|
+
typeId,
|
|
544
|
+
value,
|
|
545
|
+
message: errorMessage,
|
|
546
|
+
});
|
|
547
|
+
// Skip storing invalid value
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
524
552
|
const prev = node.inputs[handle];
|
|
525
553
|
const same = this.valuesEqual(prev, value);
|
|
526
554
|
if (!same) {
|
|
527
|
-
|
|
555
|
+
if (value === undefined) {
|
|
556
|
+
delete node.inputs[handle];
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
node.inputs[handle] = value;
|
|
560
|
+
}
|
|
528
561
|
// Emit value event for input updates
|
|
529
562
|
this.emit("value", { nodeId, handle, value, io: "input" });
|
|
530
563
|
anyChanged = true;
|