@fbp/evaluator 1.7.0 → 1.8.0
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/esm/evaluate.js +23 -5
- package/esm/validate.js +1 -1
- package/evaluate.js +23 -5
- package/package.json +3 -3
- package/validate.js +1 -1
package/esm/evaluate.js
CHANGED
|
@@ -68,7 +68,12 @@ export function refEdges(nodes, scopePath = []) {
|
|
|
68
68
|
* recursing forever.
|
|
69
69
|
*/
|
|
70
70
|
function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
71
|
-
const {
|
|
71
|
+
const { inputs = {}, props = {}, absent } = options;
|
|
72
|
+
// Definitions stored in the graph (converted subnets) join the ones passed in, for this graph and everything inside it.
|
|
73
|
+
// A stored definition with no graph only describes a node, so it never replaces one that can run.
|
|
74
|
+
const supplied = new Set(options.definitions.map(d => defKey(d.context, d.category ?? 'core', d.name)));
|
|
75
|
+
const stored = (graph.definitions ?? []).filter(d => d.graph || !supplied.has(defKey(d.context, d.category ?? 'core', d.name)));
|
|
76
|
+
const definitions = stored.length ? [...options.definitions, ...stored] : options.definitions;
|
|
72
77
|
// Reject cycles up front, as the validator and the SQL gate do: pulling
|
|
73
78
|
// through a loop would otherwise recurse until the stack overflows.
|
|
74
79
|
const cycle = findCycle(graph.nodes.map(n => n.name), [...graph.edges, ...refEdges(graph.nodes, scopePath)]);
|
|
@@ -82,7 +87,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
82
87
|
}
|
|
83
88
|
const defMap = new Map();
|
|
84
89
|
for (const def of definitions) {
|
|
85
|
-
defMap.set(defKey(def.context, def.category, def.name), def);
|
|
90
|
+
defMap.set(defKey(def.context, def.category ?? 'core', def.name), def);
|
|
86
91
|
}
|
|
87
92
|
// Graph-level context used as default for node lookups
|
|
88
93
|
const graphContext = graph.context || '';
|
|
@@ -236,7 +241,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
236
241
|
}
|
|
237
242
|
}
|
|
238
243
|
// One evaluation of the inner graph serves every output port.
|
|
239
|
-
const pull = openGraph({ name: `${nodeName}_subnet`, context: graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, { definitions, inputs: subnetInputs, props: subnetProps, absent: absentInputs }, assetPath, [...scopePath, nodeName], scope);
|
|
244
|
+
const pull = openGraph({ name: `${nodeName}_subnet`, context: node.context || graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, { definitions, inputs: subnetInputs, props: subnetProps, absent: absentInputs }, assetPath, [...scopePath, nodeName], scope);
|
|
240
245
|
const subnetOutputs = {};
|
|
241
246
|
for (const outputPort of outputPorts) {
|
|
242
247
|
const outputBoundaryNode = node.nodes.find(n => n.type === 'graphOutput' && n.props?.find(p => p.name === 'portName')?.value === outputPort.name);
|
|
@@ -273,6 +278,8 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
273
278
|
*/
|
|
274
279
|
const notTaken = (outputs, port) => !(port in outputs);
|
|
275
280
|
const skipped = {};
|
|
281
|
+
// A digital asset is a subnet stored once: its unwired arms stay dark inside it, as in an inline subnet.
|
|
282
|
+
const absentInputs = new Set();
|
|
276
283
|
const declaredPortNames = new Set();
|
|
277
284
|
if (definition.inputs) {
|
|
278
285
|
for (const inputPort of definition.inputs) {
|
|
@@ -286,6 +293,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
286
293
|
: { value: upstreamOutputs[edge.src.port] };
|
|
287
294
|
}));
|
|
288
295
|
const values = arrived.filter((slot) => slot !== undefined);
|
|
296
|
+
if (edges.length > 0 && values.length === 0 && definition.graph && !inputPort.optional) {
|
|
297
|
+
absentInputs.add(inputPort.name);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
289
300
|
if (edges.length > 0 && values.length === 0 && !inputPort.optional) {
|
|
290
301
|
cache.set(nodeName, skipped);
|
|
291
302
|
return skipped;
|
|
@@ -297,7 +308,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
297
308
|
const edge = edges[0];
|
|
298
309
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
299
310
|
if (notTaken(upstreamOutputs, edge.src.port)) {
|
|
300
|
-
if (
|
|
311
|
+
if (definition.graph) {
|
|
312
|
+
absentInputs.add(inputPort.name);
|
|
313
|
+
}
|
|
314
|
+
else if (!inputPort.optional) {
|
|
301
315
|
cache.set(nodeName, skipped);
|
|
302
316
|
return skipped;
|
|
303
317
|
}
|
|
@@ -316,6 +330,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
316
330
|
const edge = edges[0];
|
|
317
331
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
318
332
|
if (notTaken(upstreamOutputs, edge.src.port)) {
|
|
333
|
+
if (definition.graph) {
|
|
334
|
+
absentInputs.add(portName);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
319
337
|
cache.set(nodeName, skipped);
|
|
320
338
|
return skipped;
|
|
321
339
|
}
|
|
@@ -343,7 +361,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
343
361
|
}
|
|
344
362
|
const assetGraph = definition.graph;
|
|
345
363
|
// One evaluation of the asset's graph serves every output port.
|
|
346
|
-
const pull = openGraph({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, inputs: nodeInputs, props: nodeProps }, [...assetPath, key]);
|
|
364
|
+
const pull = openGraph({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges, definitions: assetGraph.definitions }, { definitions, inputs: nodeInputs, props: nodeProps, absent: absentInputs }, [...assetPath, key]);
|
|
347
365
|
const assetOutputs = {};
|
|
348
366
|
for (const outputBoundaryNode of assetGraph.nodes.filter(n => n.type === 'graphOutput')) {
|
|
349
367
|
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
package/esm/validate.js
CHANGED
|
@@ -136,7 +136,7 @@ export function validateGraph(graph, options = {}) {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
visit({ name: `${node.name}_subnet`, context: graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, qualifiedName, [...scope, node.name]);
|
|
139
|
+
visit({ name: `${node.name}_subnet`, context: node.context || graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, qualifiedName, [...scope, node.name]);
|
|
140
140
|
continue;
|
|
141
141
|
}
|
|
142
142
|
const nodeContext = node.context || graphContext;
|
package/evaluate.js
CHANGED
|
@@ -72,7 +72,12 @@ function refEdges(nodes, scopePath = []) {
|
|
|
72
72
|
* recursing forever.
|
|
73
73
|
*/
|
|
74
74
|
function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
75
|
-
const {
|
|
75
|
+
const { inputs = {}, props = {}, absent } = options;
|
|
76
|
+
// Definitions stored in the graph (converted subnets) join the ones passed in, for this graph and everything inside it.
|
|
77
|
+
// A stored definition with no graph only describes a node, so it never replaces one that can run.
|
|
78
|
+
const supplied = new Set(options.definitions.map(d => defKey(d.context, d.category ?? 'core', d.name)));
|
|
79
|
+
const stored = (graph.definitions ?? []).filter(d => d.graph || !supplied.has(defKey(d.context, d.category ?? 'core', d.name)));
|
|
80
|
+
const definitions = stored.length ? [...options.definitions, ...stored] : options.definitions;
|
|
76
81
|
// Reject cycles up front, as the validator and the SQL gate do: pulling
|
|
77
82
|
// through a loop would otherwise recurse until the stack overflows.
|
|
78
83
|
const cycle = (0, cycles_1.findCycle)(graph.nodes.map(n => n.name), [...graph.edges, ...refEdges(graph.nodes, scopePath)]);
|
|
@@ -86,7 +91,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
86
91
|
}
|
|
87
92
|
const defMap = new Map();
|
|
88
93
|
for (const def of definitions) {
|
|
89
|
-
defMap.set(defKey(def.context, def.category, def.name), def);
|
|
94
|
+
defMap.set(defKey(def.context, def.category ?? 'core', def.name), def);
|
|
90
95
|
}
|
|
91
96
|
// Graph-level context used as default for node lookups
|
|
92
97
|
const graphContext = graph.context || '';
|
|
@@ -240,7 +245,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
240
245
|
}
|
|
241
246
|
}
|
|
242
247
|
// One evaluation of the inner graph serves every output port.
|
|
243
|
-
const pull = openGraph({ name: `${nodeName}_subnet`, context: graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, { definitions, inputs: subnetInputs, props: subnetProps, absent: absentInputs }, assetPath, [...scopePath, nodeName], scope);
|
|
248
|
+
const pull = openGraph({ name: `${nodeName}_subnet`, context: node.context || graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, { definitions, inputs: subnetInputs, props: subnetProps, absent: absentInputs }, assetPath, [...scopePath, nodeName], scope);
|
|
244
249
|
const subnetOutputs = {};
|
|
245
250
|
for (const outputPort of outputPorts) {
|
|
246
251
|
const outputBoundaryNode = node.nodes.find(n => n.type === 'graphOutput' && n.props?.find(p => p.name === 'portName')?.value === outputPort.name);
|
|
@@ -277,6 +282,8 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
277
282
|
*/
|
|
278
283
|
const notTaken = (outputs, port) => !(port in outputs);
|
|
279
284
|
const skipped = {};
|
|
285
|
+
// A digital asset is a subnet stored once: its unwired arms stay dark inside it, as in an inline subnet.
|
|
286
|
+
const absentInputs = new Set();
|
|
280
287
|
const declaredPortNames = new Set();
|
|
281
288
|
if (definition.inputs) {
|
|
282
289
|
for (const inputPort of definition.inputs) {
|
|
@@ -290,6 +297,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
290
297
|
: { value: upstreamOutputs[edge.src.port] };
|
|
291
298
|
}));
|
|
292
299
|
const values = arrived.filter((slot) => slot !== undefined);
|
|
300
|
+
if (edges.length > 0 && values.length === 0 && definition.graph && !inputPort.optional) {
|
|
301
|
+
absentInputs.add(inputPort.name);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
293
304
|
if (edges.length > 0 && values.length === 0 && !inputPort.optional) {
|
|
294
305
|
cache.set(nodeName, skipped);
|
|
295
306
|
return skipped;
|
|
@@ -301,7 +312,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
301
312
|
const edge = edges[0];
|
|
302
313
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
303
314
|
if (notTaken(upstreamOutputs, edge.src.port)) {
|
|
304
|
-
if (
|
|
315
|
+
if (definition.graph) {
|
|
316
|
+
absentInputs.add(inputPort.name);
|
|
317
|
+
}
|
|
318
|
+
else if (!inputPort.optional) {
|
|
305
319
|
cache.set(nodeName, skipped);
|
|
306
320
|
return skipped;
|
|
307
321
|
}
|
|
@@ -320,6 +334,10 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
320
334
|
const edge = edges[0];
|
|
321
335
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
322
336
|
if (notTaken(upstreamOutputs, edge.src.port)) {
|
|
337
|
+
if (definition.graph) {
|
|
338
|
+
absentInputs.add(portName);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
323
341
|
cache.set(nodeName, skipped);
|
|
324
342
|
return skipped;
|
|
325
343
|
}
|
|
@@ -347,7 +365,7 @@ function openGraph(graph, options, assetPath, scopePath = [], parentScope) {
|
|
|
347
365
|
}
|
|
348
366
|
const assetGraph = definition.graph;
|
|
349
367
|
// One evaluation of the asset's graph serves every output port.
|
|
350
|
-
const pull = openGraph({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, inputs: nodeInputs, props: nodeProps }, [...assetPath, key]);
|
|
368
|
+
const pull = openGraph({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges, definitions: assetGraph.definitions }, { definitions, inputs: nodeInputs, props: nodeProps, absent: absentInputs }, [...assetPath, key]);
|
|
351
369
|
const assetOutputs = {};
|
|
352
370
|
for (const outputBoundaryNode of assetGraph.nodes.filter(n => n.type === 'graphOutput')) {
|
|
353
371
|
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbp/evaluator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "FBP graph evaluator — node definitions, graph evaluation and validation",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"directory": "dist"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fbp/
|
|
16
|
-
"@fbp/
|
|
15
|
+
"@fbp/types": "1.5.0",
|
|
16
|
+
"@fbp/spec": "1.5.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/jest": "^30.0.0",
|
package/validate.js
CHANGED
|
@@ -139,7 +139,7 @@ function validateGraph(graph, options = {}) {
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
visit({ name: `${node.name}_subnet`, context: graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, qualifiedName, [...scope, node.name]);
|
|
142
|
+
visit({ name: `${node.name}_subnet`, context: node.context || graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, qualifiedName, [...scope, node.name]);
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
const nodeContext = node.context || graphContext;
|