@bian-womp/spark-graph 0.1.16 → 0.1.17

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
@@ -378,8 +378,7 @@ function typed(typeId, value) {
378
378
  function isTypedOutput(v) {
379
379
  return (!!v &&
380
380
  typeof v === "object" &&
381
- Object.prototype.hasOwnProperty.call(v, "__spark_type") &&
382
- Object.prototype.hasOwnProperty.call(v, "__spark_value"));
381
+ Object.prototype.hasOwnProperty.call(v, "__spark_type"));
383
382
  }
384
383
 
385
384
  class GraphRuntime {
@@ -1250,15 +1249,30 @@ class GraphBuilder {
1250
1249
  message: `Edge ${e.id} target node missing`,
1251
1250
  data: { edgeId: e.id },
1252
1251
  });
1253
- // infer edge type from source output if missing
1252
+ // Infer edge type when missing. For union sources, prefer target input type if available.
1254
1253
  let effectiveTypeId = e.typeId;
1255
- if (!effectiveTypeId && srcNode) {
1254
+ let _srcDeclared;
1255
+ let _dstDeclared;
1256
+ if (srcNode) {
1256
1257
  const srcType = this.registry.nodes.get(srcNode.typeId);
1257
- if (srcType) {
1258
- const declared = srcType.outputs[e.source.handle];
1259
- effectiveTypeId = Array.isArray(declared)
1260
- ? declared[0]
1261
- : declared;
1258
+ if (srcType)
1259
+ _srcDeclared = srcType.outputs[e.source.handle];
1260
+ }
1261
+ if (dstNode) {
1262
+ const dstType = this.registry.nodes.get(dstNode.typeId);
1263
+ if (dstType)
1264
+ _dstDeclared = dstType.inputs[e.target.handle];
1265
+ }
1266
+ if (!effectiveTypeId) {
1267
+ if (Array.isArray(_srcDeclared) && _dstDeclared) {
1268
+ // When source is a union and target input type is known, adopt the input type
1269
+ // so validation checks are performed against the target, not an arbitrary variant.
1270
+ effectiveTypeId = _dstDeclared;
1271
+ }
1272
+ else if (_srcDeclared) {
1273
+ effectiveTypeId = Array.isArray(_srcDeclared)
1274
+ ? _srcDeclared[0]
1275
+ : _srcDeclared;
1262
1276
  }
1263
1277
  }
1264
1278
  const type = effectiveTypeId
@@ -1295,7 +1309,8 @@ class GraphBuilder {
1295
1309
  : [];
1296
1310
  if (declaredArr.length > 0 && effectiveTypeId) {
1297
1311
  for (const s of declaredArr) {
1298
- if (s !== effectiveTypeId && !this.registry.canCoerce(s, effectiveTypeId)) {
1312
+ if (s !== effectiveTypeId &&
1313
+ !this.registry.canCoerce(s, effectiveTypeId)) {
1299
1314
  issues.push({
1300
1315
  level: "error",
1301
1316
  code: "TYPE_MISMATCH_OUTPUT",
@@ -1342,7 +1357,8 @@ class GraphBuilder {
1342
1357
  ? [effectiveTypeId]
1343
1358
  : [];
1344
1359
  for (const s of srcArr) {
1345
- if (s !== declaredIn && !this.registry.canCoerce(s, declaredIn)) {
1360
+ if (s !== declaredIn &&
1361
+ !this.registry.canCoerce(s, declaredIn)) {
1346
1362
  issues.push({
1347
1363
  level: "error",
1348
1364
  code: "TYPE_MISMATCH_INPUT",
@@ -1358,7 +1374,8 @@ class GraphBuilder {
1358
1374
  }
1359
1375
  }
1360
1376
  }
1361
- else if (declaredIn !== effectiveTypeId && !this.registry.canCoerce(effectiveTypeId, declaredIn)) {
1377
+ else if (declaredIn !== effectiveTypeId &&
1378
+ !this.registry.canCoerce(effectiveTypeId, declaredIn)) {
1362
1379
  issues.push({
1363
1380
  level: "error",
1364
1381
  code: "TYPE_MISMATCH_INPUT",