@bian-womp/spark-graph 0.1.16 → 0.1.18
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 +46 -12
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/builder/GraphBuilder.d.ts.map +1 -1
- package/lib/cjs/src/core/types.d.ts.map +1 -1
- package/lib/cjs/src/misc/base.d.ts.map +1 -1
- package/lib/esm/index.js +46 -12
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/builder/GraphBuilder.d.ts.map +1 -1
- package/lib/esm/src/core/types.d.ts.map +1 -1
- package/lib/esm/src/misc/base.d.ts.map +1 -1
- package/package.json +1 -1
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
|
-
//
|
|
1252
|
+
// Infer edge type when missing. For union sources, prefer target input type if available.
|
|
1254
1253
|
let effectiveTypeId = e.typeId;
|
|
1255
|
-
|
|
1254
|
+
let _srcDeclared;
|
|
1255
|
+
let _dstDeclared;
|
|
1256
|
+
if (srcNode) {
|
|
1256
1257
|
const srcType = this.registry.nodes.get(srcNode.typeId);
|
|
1257
|
-
if (srcType)
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
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 &&
|
|
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 &&
|
|
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 &&
|
|
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",
|
|
@@ -1876,6 +1893,23 @@ function setupBasicGraphRegistry() {
|
|
|
1876
1893
|
Result: Math.trunc(Number(ins.Value)),
|
|
1877
1894
|
}),
|
|
1878
1895
|
});
|
|
1896
|
+
// JSON parser node: base.stringToObject
|
|
1897
|
+
registry.registerNode({
|
|
1898
|
+
id: "base.stringToObject",
|
|
1899
|
+
categoryId: "compute",
|
|
1900
|
+
inputs: { Text: "base.string" },
|
|
1901
|
+
outputs: { Object: "base.object" },
|
|
1902
|
+
impl: (ins) => {
|
|
1903
|
+
const t = ins.Text ?? "";
|
|
1904
|
+
try {
|
|
1905
|
+
const obj = JSON.parse(t);
|
|
1906
|
+
return { Object: obj };
|
|
1907
|
+
}
|
|
1908
|
+
catch {
|
|
1909
|
+
return { Object: undefined };
|
|
1910
|
+
}
|
|
1911
|
+
},
|
|
1912
|
+
});
|
|
1879
1913
|
// Number to String
|
|
1880
1914
|
registry.registerNode({
|
|
1881
1915
|
id: "base.numberToString",
|