@bian-womp/spark-graph 0.1.17 → 0.1.19

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
@@ -380,6 +380,16 @@ function isTypedOutput(v) {
380
380
  typeof v === "object" &&
381
381
  Object.prototype.hasOwnProperty.call(v, "__spark_type"));
382
382
  }
383
+ function getInputTypeId(inputs, handle) {
384
+ const v = inputs ? inputs[handle] : undefined;
385
+ if (!v)
386
+ return undefined;
387
+ return typeof v === "string" ? v : v.typeId;
388
+ }
389
+ function isInputPrivate(inputs, handle) {
390
+ const v = inputs ? inputs[handle] : undefined;
391
+ return !!(v && typeof v === "object" && v.private);
392
+ }
383
393
 
384
394
  class GraphRuntime {
385
395
  constructor() {
@@ -452,7 +462,7 @@ class GraphRuntime {
452
462
  if (dstNode) {
453
463
  const dstDesc = registry.nodes.get(dstNode.typeId);
454
464
  if (dstDesc) {
455
- dstDeclared = dstDesc.inputs[e.target.handle];
465
+ dstDeclared = getInputTypeId(dstDesc.inputs, e.target.handle);
456
466
  }
457
467
  }
458
468
  // Attach dynamic convert/convertAsync aware of union sources and typed outputs
@@ -1105,7 +1115,7 @@ class GraphRuntime {
1105
1115
  if (dstNode) {
1106
1116
  const dstDesc = registry.nodes.get(dstNode.typeId);
1107
1117
  if (dstDesc) {
1108
- dstDeclared = dstDesc.inputs[e.target.handle];
1118
+ dstDeclared = getInputTypeId(dstDesc.inputs, e.target.handle);
1109
1119
  }
1110
1120
  }
1111
1121
  const { convert, convertAsync } = GraphRuntime.buildEdgeConverters(srcDeclared, dstDeclared, registry);
@@ -1343,7 +1353,20 @@ class GraphBuilder {
1343
1353
  });
1344
1354
  }
1345
1355
  if (dstType) {
1346
- const declaredIn = dstType.inputs[e.target.handle];
1356
+ // Private inputs should not accept edges
1357
+ if (isInputPrivate(dstType.inputs, e.target.handle)) {
1358
+ issues.push({
1359
+ level: "error",
1360
+ code: "INPUT_PRIVATE",
1361
+ message: `Edge ${e.id} targets private input ${dstNode.typeId}.${e.target.handle}`,
1362
+ data: {
1363
+ edgeId: e.id,
1364
+ nodeId: dstNode.nodeId,
1365
+ input: e.target.handle,
1366
+ },
1367
+ });
1368
+ }
1369
+ const declaredIn = getInputTypeId(dstType.inputs, e.target.handle);
1347
1370
  if (declaredIn && effectiveTypeId) {
1348
1371
  // If source is a union, ensure each variant can reach declaredIn
1349
1372
  if (srcNode) {
@@ -1421,7 +1444,8 @@ class GraphBuilder {
1421
1444
  ? this.registry.nodes.get(innerNode.typeId)
1422
1445
  : undefined;
1423
1446
  const typeId = innerDesc ? innerDesc.inputs[map.handle] : undefined;
1424
- inputTypes[outerIn] = typeId ?? "untyped";
1447
+ inputTypes[outerIn] =
1448
+ typeof typeId === "string" ? typeId : typeId?.typeId ?? "untyped";
1425
1449
  }
1426
1450
  for (const [outerOut, map] of Object.entries(exposure.outputs)) {
1427
1451
  const innerNode = def.nodes.find((n) => n.nodeId === map.nodeId);
@@ -1893,6 +1917,23 @@ function setupBasicGraphRegistry() {
1893
1917
  Result: Math.trunc(Number(ins.Value)),
1894
1918
  }),
1895
1919
  });
1920
+ // JSON parser node: base.stringToObject
1921
+ registry.registerNode({
1922
+ id: "base.stringToObject",
1923
+ categoryId: "compute",
1924
+ inputs: { Text: "base.string" },
1925
+ outputs: { Object: "base.object" },
1926
+ impl: (ins) => {
1927
+ const t = ins.Text ?? "";
1928
+ try {
1929
+ const obj = JSON.parse(t);
1930
+ return { Object: obj };
1931
+ }
1932
+ catch {
1933
+ return { Object: undefined };
1934
+ }
1935
+ },
1936
+ });
1896
1937
  // Number to String
1897
1938
  registry.registerNode({
1898
1939
  id: "base.numberToString",
@@ -2394,6 +2435,8 @@ exports.createSimpleGraphDef = createSimpleGraphDef;
2394
2435
  exports.createSimpleGraphRegistry = createSimpleGraphRegistry;
2395
2436
  exports.createValidationGraphDef = createValidationGraphDef;
2396
2437
  exports.createValidationGraphRegistry = createValidationGraphRegistry;
2438
+ exports.getInputTypeId = getInputTypeId;
2439
+ exports.isInputPrivate = isInputPrivate;
2397
2440
  exports.isTypedOutput = isTypedOutput;
2398
2441
  exports.registerDelayNode = registerDelayNode;
2399
2442
  exports.registerProgressNodes = registerProgressNodes;