@fbp/evaluator 1.0.0 → 1.3.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/README.md +4 -84
- package/definitions/core.d.ts +60 -6
- package/definitions/core.js +432 -29
- package/definitions/math.d.ts +1 -0
- package/definitions/math.js +21 -5
- package/definitions/net.js +2 -2
- package/definitions/ui.js +13 -13
- package/esm/definitions/core.js +431 -28
- package/esm/definitions/math.js +20 -4
- package/esm/definitions/net.js +2 -2
- package/esm/definitions/ui.js +13 -13
- package/esm/evaluate.js +100 -22
- package/esm/index.js +5 -4
- package/esm/validate.js +147 -0
- package/evaluate.js +100 -22
- package/index.d.ts +7 -5
- package/index.js +31 -18
- package/package.json +20 -26
- package/validate.d.ts +54 -0
- package/validate.js +150 -0
- package/esm/definitions/core.d.ts +0 -72
- package/esm/definitions/math.d.ts +0 -8
- package/esm/definitions/net.d.ts +0 -25
- package/esm/definitions/ui.d.ts +0 -10
- package/esm/evaluate.d.ts +0 -12
- package/esm/index.d.ts +0 -6
- package/esm/types.d.ts +0 -38
package/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { evaluate } from './evaluate';
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { coreDefinitions,
|
|
6
|
-
export {
|
|
2
|
+
export type { EvaluateOptions, NodeDefinitionWithImpl, NodeImplFn, PropDefinitionWithOptions } from './types';
|
|
3
|
+
export type { GraphValidationError, GraphValidationErrorCode, ValidateGraphOptions } from './validate';
|
|
4
|
+
export { validateGraph } from './validate';
|
|
5
|
+
export { constBooleanDef, constStringDef, coreDefinitions, flowBranchDef, flowCoerceDef, flowFilterDef, flowForEachDef, flowGuardDef, flowMergeDef, flowSwitchDef, jsonMergeDef, jsonObjectDef, jsonSelectDef, jsonSplitDef, stringConcatDef, stringTemplateDef } from './definitions/core';
|
|
6
|
+
export { addDef, constNumberDef, mathDefinitions, multiplyDef, subtractDef } from './definitions/math';
|
|
7
|
+
export { graphqlRequestDef, netDefinitions } from './definitions/net';
|
|
8
|
+
export { buttonDef, formDef, graphInputDef, graphOutputDef, graphPropDef, inputDef, pageDef, textDef, uiDefinitions } from './definitions/ui';
|
package/index.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.uiDefinitions = exports.textDef = exports.pageDef = exports.inputDef = exports.graphPropDef = exports.graphOutputDef = exports.graphInputDef = exports.formDef = exports.buttonDef = exports.netDefinitions = exports.graphqlRequestDef = exports.subtractDef = exports.multiplyDef = exports.mathDefinitions = exports.constNumberDef = exports.addDef = exports.stringTemplateDef = exports.stringConcatDef = exports.jsonSplitDef = exports.jsonSelectDef = exports.jsonObjectDef = exports.jsonMergeDef = exports.flowSwitchDef = exports.flowMergeDef = exports.flowGuardDef = exports.flowForEachDef = exports.flowFilterDef = exports.flowCoerceDef = exports.flowBranchDef = exports.coreDefinitions = exports.constStringDef = exports.constBooleanDef = exports.validateGraph = exports.evaluate = void 0;
|
|
4
4
|
var evaluate_1 = require("./evaluate");
|
|
5
5
|
Object.defineProperty(exports, "evaluate", { enumerable: true, get: function () { return evaluate_1.evaluate; } });
|
|
6
|
+
var validate_1 = require("./validate");
|
|
7
|
+
Object.defineProperty(exports, "validateGraph", { enumerable: true, get: function () { return validate_1.validateGraph; } });
|
|
6
8
|
// Re-export node definitions for convenience
|
|
9
|
+
var core_1 = require("./definitions/core");
|
|
10
|
+
Object.defineProperty(exports, "constBooleanDef", { enumerable: true, get: function () { return core_1.constBooleanDef; } });
|
|
11
|
+
Object.defineProperty(exports, "constStringDef", { enumerable: true, get: function () { return core_1.constStringDef; } });
|
|
12
|
+
Object.defineProperty(exports, "coreDefinitions", { enumerable: true, get: function () { return core_1.coreDefinitions; } });
|
|
13
|
+
Object.defineProperty(exports, "flowBranchDef", { enumerable: true, get: function () { return core_1.flowBranchDef; } });
|
|
14
|
+
Object.defineProperty(exports, "flowCoerceDef", { enumerable: true, get: function () { return core_1.flowCoerceDef; } });
|
|
15
|
+
Object.defineProperty(exports, "flowFilterDef", { enumerable: true, get: function () { return core_1.flowFilterDef; } });
|
|
16
|
+
Object.defineProperty(exports, "flowForEachDef", { enumerable: true, get: function () { return core_1.flowForEachDef; } });
|
|
17
|
+
Object.defineProperty(exports, "flowGuardDef", { enumerable: true, get: function () { return core_1.flowGuardDef; } });
|
|
18
|
+
Object.defineProperty(exports, "flowMergeDef", { enumerable: true, get: function () { return core_1.flowMergeDef; } });
|
|
19
|
+
Object.defineProperty(exports, "flowSwitchDef", { enumerable: true, get: function () { return core_1.flowSwitchDef; } });
|
|
20
|
+
Object.defineProperty(exports, "jsonMergeDef", { enumerable: true, get: function () { return core_1.jsonMergeDef; } });
|
|
21
|
+
Object.defineProperty(exports, "jsonObjectDef", { enumerable: true, get: function () { return core_1.jsonObjectDef; } });
|
|
22
|
+
Object.defineProperty(exports, "jsonSelectDef", { enumerable: true, get: function () { return core_1.jsonSelectDef; } });
|
|
23
|
+
Object.defineProperty(exports, "jsonSplitDef", { enumerable: true, get: function () { return core_1.jsonSplitDef; } });
|
|
24
|
+
Object.defineProperty(exports, "stringConcatDef", { enumerable: true, get: function () { return core_1.stringConcatDef; } });
|
|
25
|
+
Object.defineProperty(exports, "stringTemplateDef", { enumerable: true, get: function () { return core_1.stringTemplateDef; } });
|
|
7
26
|
var math_1 = require("./definitions/math");
|
|
8
|
-
Object.defineProperty(exports, "mathDefinitions", { enumerable: true, get: function () { return math_1.mathDefinitions; } });
|
|
9
|
-
Object.defineProperty(exports, "constNumberDef", { enumerable: true, get: function () { return math_1.constNumberDef; } });
|
|
10
27
|
Object.defineProperty(exports, "addDef", { enumerable: true, get: function () { return math_1.addDef; } });
|
|
28
|
+
Object.defineProperty(exports, "constNumberDef", { enumerable: true, get: function () { return math_1.constNumberDef; } });
|
|
29
|
+
Object.defineProperty(exports, "mathDefinitions", { enumerable: true, get: function () { return math_1.mathDefinitions; } });
|
|
11
30
|
Object.defineProperty(exports, "multiplyDef", { enumerable: true, get: function () { return math_1.multiplyDef; } });
|
|
31
|
+
Object.defineProperty(exports, "subtractDef", { enumerable: true, get: function () { return math_1.subtractDef; } });
|
|
32
|
+
var net_1 = require("./definitions/net");
|
|
33
|
+
Object.defineProperty(exports, "graphqlRequestDef", { enumerable: true, get: function () { return net_1.graphqlRequestDef; } });
|
|
34
|
+
Object.defineProperty(exports, "netDefinitions", { enumerable: true, get: function () { return net_1.netDefinitions; } });
|
|
12
35
|
var ui_1 = require("./definitions/ui");
|
|
13
|
-
Object.defineProperty(exports, "uiDefinitions", { enumerable: true, get: function () { return ui_1.uiDefinitions; } });
|
|
14
|
-
Object.defineProperty(exports, "pageDef", { enumerable: true, get: function () { return ui_1.pageDef; } });
|
|
15
|
-
Object.defineProperty(exports, "formDef", { enumerable: true, get: function () { return ui_1.formDef; } });
|
|
16
|
-
Object.defineProperty(exports, "inputDef", { enumerable: true, get: function () { return ui_1.inputDef; } });
|
|
17
36
|
Object.defineProperty(exports, "buttonDef", { enumerable: true, get: function () { return ui_1.buttonDef; } });
|
|
18
|
-
Object.defineProperty(exports, "
|
|
37
|
+
Object.defineProperty(exports, "formDef", { enumerable: true, get: function () { return ui_1.formDef; } });
|
|
19
38
|
Object.defineProperty(exports, "graphInputDef", { enumerable: true, get: function () { return ui_1.graphInputDef; } });
|
|
20
39
|
Object.defineProperty(exports, "graphOutputDef", { enumerable: true, get: function () { return ui_1.graphOutputDef; } });
|
|
21
40
|
Object.defineProperty(exports, "graphPropDef", { enumerable: true, get: function () { return ui_1.graphPropDef; } });
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
Object.defineProperty(exports, "flowGuardDef", { enumerable: true, get: function () { return core_1.flowGuardDef; } });
|
|
27
|
-
Object.defineProperty(exports, "stringTemplateDef", { enumerable: true, get: function () { return core_1.stringTemplateDef; } });
|
|
28
|
-
Object.defineProperty(exports, "stringConcatDef", { enumerable: true, get: function () { return core_1.stringConcatDef; } });
|
|
29
|
-
var net_1 = require("./definitions/net");
|
|
30
|
-
Object.defineProperty(exports, "netDefinitions", { enumerable: true, get: function () { return net_1.netDefinitions; } });
|
|
31
|
-
Object.defineProperty(exports, "graphqlRequestDef", { enumerable: true, get: function () { return net_1.graphqlRequestDef; } });
|
|
41
|
+
Object.defineProperty(exports, "inputDef", { enumerable: true, get: function () { return ui_1.inputDef; } });
|
|
42
|
+
Object.defineProperty(exports, "pageDef", { enumerable: true, get: function () { return ui_1.pageDef; } });
|
|
43
|
+
Object.defineProperty(exports, "textDef", { enumerable: true, get: function () { return ui_1.textDef; } });
|
|
44
|
+
Object.defineProperty(exports, "uiDefinitions", { enumerable: true, get: function () { return ui_1.uiDefinitions; } });
|
package/package.json
CHANGED
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbp/evaluator",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "FBP graph evaluator — node definitions, graph evaluation and validation",
|
|
5
|
+
"author": "Constructive <developers@constructive.io>",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"main": "index.js",
|
|
7
8
|
"module": "esm/index.js",
|
|
8
9
|
"types": "index.d.ts",
|
|
9
|
-
"homepage": "https://github.com/flow-based-programming/spec",
|
|
10
|
-
"license": "MIT",
|
|
11
10
|
"publishConfig": {
|
|
12
11
|
"access": "public",
|
|
13
12
|
"directory": "dist"
|
|
14
13
|
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/flow-based-programming/spec"
|
|
18
|
-
},
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/flow-based-programming/spec/issues"
|
|
21
|
-
},
|
|
22
14
|
"scripts": {
|
|
23
|
-
"clean": "makage clean",
|
|
24
|
-
"prepack": "npm run build",
|
|
25
15
|
"build": "makage build",
|
|
26
16
|
"build:dev": "makage build --dev",
|
|
27
|
-
"
|
|
28
|
-
"test": "jest"
|
|
29
|
-
"test:watch": "jest --watch"
|
|
17
|
+
"clean": "makage clean",
|
|
18
|
+
"test": "jest --config jest.config.js"
|
|
30
19
|
},
|
|
31
|
-
"keywords": [
|
|
32
|
-
"fbp",
|
|
33
|
-
"evaluator",
|
|
34
|
-
"flow-based-programming",
|
|
35
|
-
"lazy-evaluation"
|
|
36
|
-
],
|
|
37
20
|
"dependencies": {
|
|
38
|
-
"@fbp/types": "
|
|
21
|
+
"@fbp/types": "workspace:*"
|
|
39
22
|
},
|
|
40
23
|
"devDependencies": {
|
|
41
|
-
"
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
|
+
"jest": "^30.2.0",
|
|
26
|
+
"makage": "^0.1.12",
|
|
27
|
+
"ts-jest": "^29.4.0",
|
|
28
|
+
"typescript": "^5.7.0"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/constructive-io/fbp",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/constructive-io/fbp"
|
|
42
34
|
},
|
|
43
|
-
"
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/constructive-io/fbp/issues"
|
|
37
|
+
}
|
|
44
38
|
}
|
package/validate.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Graph } from '@fbp/types';
|
|
2
|
+
import type { NodeDefinitionWithImpl } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Codes emitted by {@link validateGraph}. Kept in lock-step with the SQL
|
|
5
|
+
* `validate_function_graph` definition-aware checks so the editor pre-flight and
|
|
6
|
+
* the database gate agree on what "invalid" means.
|
|
7
|
+
*/
|
|
8
|
+
export type GraphValidationErrorCode = 'MISSING_REQUIRED_INPUT' | 'MISSING_REQUIRED_PROP';
|
|
9
|
+
export interface GraphValidationError {
|
|
10
|
+
code: GraphValidationErrorCode;
|
|
11
|
+
/** The offending node's name (qualified with the subnet/asset path). */
|
|
12
|
+
node: string;
|
|
13
|
+
/** For MISSING_REQUIRED_INPUT: the unconnected required input port. */
|
|
14
|
+
port?: string;
|
|
15
|
+
/** For MISSING_REQUIRED_PROP: the unsupplied required prop. */
|
|
16
|
+
prop?: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ValidateGraphOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Node definitions available for resolution. These are merged with any
|
|
22
|
+
* definitions embedded on the graph (`graph.definitions`) and on nested
|
|
23
|
+
* digital-asset definitions.
|
|
24
|
+
*/
|
|
25
|
+
definitions?: NodeDefinitionWithImpl[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Statically validate a flow graph before publish/execution.
|
|
29
|
+
*
|
|
30
|
+
* Heuristic (intentionally not a proof — see the caveats below) that mirrors the
|
|
31
|
+
* SQL `validate_function_graph` definition-aware pass:
|
|
32
|
+
*
|
|
33
|
+
* - For every non-boundary node whose definition resolves, each **declared**
|
|
34
|
+
* input port that is required (`optional !== true`) and non-`multi` must have
|
|
35
|
+
* at least one incoming edge, else `MISSING_REQUIRED_INPUT`.
|
|
36
|
+
* - Each definition prop that is `required` and has no `default` must be
|
|
37
|
+
* supplied by a node instance prop value, else `MISSING_REQUIRED_PROP`.
|
|
38
|
+
* - Inline `subnet` nodes are checked against their declared interface inputs
|
|
39
|
+
* and recursed into.
|
|
40
|
+
* - Digital-asset definitions (definitions carrying an internal `graph`) are
|
|
41
|
+
* recursed into.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately NOT flagged (kept consistent with the evaluator + SQL):
|
|
44
|
+
* - `graphInput` / `graphProp` boundaries — supplied at runtime.
|
|
45
|
+
* - `multi` inputs — zero-or-more, never required.
|
|
46
|
+
* - Dynamic/undeclared input ports — the evaluator accepts them, so requiredness
|
|
47
|
+
* is only enforced for declared ports.
|
|
48
|
+
* - Nodes with no resolvable definition — treated as opaque (may be a runtime
|
|
49
|
+
* handler), exactly as the SQL validator and evaluator do.
|
|
50
|
+
*
|
|
51
|
+
* @returns the list of validation errors; an empty array means the graph is
|
|
52
|
+
* statically valid. Never throws.
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateGraph(graph: Graph, options?: ValidateGraphOptions): GraphValidationError[];
|
package/validate.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateGraph = validateGraph;
|
|
4
|
+
/**
|
|
5
|
+
* Boundary node types. These are satisfied by the runtime (graphInput/graphProp
|
|
6
|
+
* receive values from the execution payload; graphOutput is a pass-through), so
|
|
7
|
+
* they are never checked for required inputs/props.
|
|
8
|
+
*/
|
|
9
|
+
const BOUNDARY_TYPES = new Set(['graphInput', 'graphOutput', 'graphProp']);
|
|
10
|
+
function defKey(context, category, name) {
|
|
11
|
+
return `${context}:${category}:${name}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse a node type (e.g., 'math:add' or 'const/string') into [category, name].
|
|
15
|
+
* Mirrors the evaluator's resolution so pre-flight and evaluation stay aligned.
|
|
16
|
+
*/
|
|
17
|
+
function parseTaskIdentifier(type) {
|
|
18
|
+
const colonIdx = type.indexOf(':');
|
|
19
|
+
if (colonIdx !== -1)
|
|
20
|
+
return [type.slice(0, colonIdx), type.slice(colonIdx + 1)];
|
|
21
|
+
const slashIdx = type.indexOf('/');
|
|
22
|
+
if (slashIdx !== -1)
|
|
23
|
+
return [type.slice(0, slashIdx), type.slice(slashIdx + 1)];
|
|
24
|
+
return ['core', type];
|
|
25
|
+
}
|
|
26
|
+
/** Build "dst node -> dst port -> has at least one incoming edge". */
|
|
27
|
+
function connectedPorts(edges) {
|
|
28
|
+
const map = new Map();
|
|
29
|
+
for (const edge of edges) {
|
|
30
|
+
let ports = map.get(edge.dst.node);
|
|
31
|
+
if (!ports) {
|
|
32
|
+
ports = new Set();
|
|
33
|
+
map.set(edge.dst.node, ports);
|
|
34
|
+
}
|
|
35
|
+
ports.add(edge.dst.port);
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
function nodeHasProp(node, propName) {
|
|
40
|
+
const p = node.props?.find(pr => pr.name === propName);
|
|
41
|
+
return p !== undefined && p.value !== undefined && p.value !== null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Statically validate a flow graph before publish/execution.
|
|
45
|
+
*
|
|
46
|
+
* Heuristic (intentionally not a proof — see the caveats below) that mirrors the
|
|
47
|
+
* SQL `validate_function_graph` definition-aware pass:
|
|
48
|
+
*
|
|
49
|
+
* - For every non-boundary node whose definition resolves, each **declared**
|
|
50
|
+
* input port that is required (`optional !== true`) and non-`multi` must have
|
|
51
|
+
* at least one incoming edge, else `MISSING_REQUIRED_INPUT`.
|
|
52
|
+
* - Each definition prop that is `required` and has no `default` must be
|
|
53
|
+
* supplied by a node instance prop value, else `MISSING_REQUIRED_PROP`.
|
|
54
|
+
* - Inline `subnet` nodes are checked against their declared interface inputs
|
|
55
|
+
* and recursed into.
|
|
56
|
+
* - Digital-asset definitions (definitions carrying an internal `graph`) are
|
|
57
|
+
* recursed into.
|
|
58
|
+
*
|
|
59
|
+
* Deliberately NOT flagged (kept consistent with the evaluator + SQL):
|
|
60
|
+
* - `graphInput` / `graphProp` boundaries — supplied at runtime.
|
|
61
|
+
* - `multi` inputs — zero-or-more, never required.
|
|
62
|
+
* - Dynamic/undeclared input ports — the evaluator accepts them, so requiredness
|
|
63
|
+
* is only enforced for declared ports.
|
|
64
|
+
* - Nodes with no resolvable definition — treated as opaque (may be a runtime
|
|
65
|
+
* handler), exactly as the SQL validator and evaluator do.
|
|
66
|
+
*
|
|
67
|
+
* @returns the list of validation errors; an empty array means the graph is
|
|
68
|
+
* statically valid. Never throws.
|
|
69
|
+
*/
|
|
70
|
+
function validateGraph(graph, options = {}) {
|
|
71
|
+
const errors = [];
|
|
72
|
+
const defMap = new Map();
|
|
73
|
+
const registerDefs = (defs) => {
|
|
74
|
+
if (!defs)
|
|
75
|
+
return;
|
|
76
|
+
for (const def of defs) {
|
|
77
|
+
const category = def.category ?? 'core';
|
|
78
|
+
defMap.set(defKey(def.context, category, def.name), def);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
registerDefs(options.definitions);
|
|
82
|
+
const visit = (g, pathPrefix) => {
|
|
83
|
+
// Definitions can be embedded per-graph (digital assets carry their own).
|
|
84
|
+
registerDefs(g.definitions);
|
|
85
|
+
const graphContext = g.context || '';
|
|
86
|
+
const connected = connectedPorts(g.edges ?? []);
|
|
87
|
+
for (const node of g.nodes ?? []) {
|
|
88
|
+
if (BOUNDARY_TYPES.has(node.type))
|
|
89
|
+
continue;
|
|
90
|
+
const qualifiedName = pathPrefix ? `${pathPrefix}/${node.name}` : node.name;
|
|
91
|
+
const nodeConnected = connected.get(node.name) ?? new Set();
|
|
92
|
+
// Inline subnet: validate against its declared interface, then recurse.
|
|
93
|
+
if (node.type === 'subnet' && node.nodes) {
|
|
94
|
+
for (const port of node.inputs ?? []) {
|
|
95
|
+
if (port.optional === true || port.multi === true)
|
|
96
|
+
continue;
|
|
97
|
+
if (!nodeConnected.has(port.name)) {
|
|
98
|
+
errors.push({
|
|
99
|
+
code: 'MISSING_REQUIRED_INPUT',
|
|
100
|
+
node: qualifiedName,
|
|
101
|
+
port: port.name,
|
|
102
|
+
message: `Required input "${port.name}" of subnet "${qualifiedName}" is not connected`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
visit({ name: `${node.name}_subnet`, context: graphContext || undefined, nodes: node.nodes, edges: node.edges ?? [] }, qualifiedName);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const nodeContext = node.context || graphContext;
|
|
110
|
+
const [category, name] = parseTaskIdentifier(node.type);
|
|
111
|
+
const definition = defMap.get(defKey(nodeContext, category, name));
|
|
112
|
+
// Unknown definition: opaque node (possibly a runtime handler). Skip —
|
|
113
|
+
// matches the SQL validator + evaluator, which do not require a definition.
|
|
114
|
+
if (!definition)
|
|
115
|
+
continue;
|
|
116
|
+
for (const port of definition.inputs ?? []) {
|
|
117
|
+
if (port.optional === true || port.multi === true)
|
|
118
|
+
continue;
|
|
119
|
+
if (!nodeConnected.has(port.name)) {
|
|
120
|
+
errors.push({
|
|
121
|
+
code: 'MISSING_REQUIRED_INPUT',
|
|
122
|
+
node: qualifiedName,
|
|
123
|
+
port: port.name,
|
|
124
|
+
message: `Required input "${port.name}" of node "${qualifiedName}" (${node.type}) is not connected`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const prop of definition.props ?? []) {
|
|
129
|
+
if (prop.required !== true)
|
|
130
|
+
continue;
|
|
131
|
+
if (prop.default !== undefined)
|
|
132
|
+
continue;
|
|
133
|
+
if (!nodeHasProp(node, prop.name)) {
|
|
134
|
+
errors.push({
|
|
135
|
+
code: 'MISSING_REQUIRED_PROP',
|
|
136
|
+
node: qualifiedName,
|
|
137
|
+
prop: prop.name,
|
|
138
|
+
message: `Required prop "${prop.name}" of node "${qualifiedName}" (${node.type}) is not set`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Digital asset: recurse into the definition's internal graph.
|
|
143
|
+
if (definition.graph) {
|
|
144
|
+
visit(definition.graph, qualifiedName);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
visit(graph, '');
|
|
149
|
+
return errors;
|
|
150
|
+
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { NodeDefinitionWithImpl } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Core node definitions with implementations.
|
|
4
|
-
* These nodes handle JSON manipulation, flow control, and string operations.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* core/json/select - Extract a value from JSON by path
|
|
8
|
-
*
|
|
9
|
-
* Props:
|
|
10
|
-
* - path: string (dot-path like "a.b.c" or "data.user.email")
|
|
11
|
-
*
|
|
12
|
-
* Inputs:
|
|
13
|
-
* - obj: json (the object to extract from)
|
|
14
|
-
*
|
|
15
|
-
* Outputs:
|
|
16
|
-
* - value: any (the extracted value)
|
|
17
|
-
*/
|
|
18
|
-
export declare const jsonSelectDef: NodeDefinitionWithImpl;
|
|
19
|
-
/**
|
|
20
|
-
* core/json/object - Build a JSON object from named inputs
|
|
21
|
-
*
|
|
22
|
-
* This node has dynamic inputs - any input wired to it becomes a key in the output object.
|
|
23
|
-
* The implementation receives all inputs as a Record<string, any>.
|
|
24
|
-
*
|
|
25
|
-
* Inputs:
|
|
26
|
-
* - (dynamic) arbitrary named inputs
|
|
27
|
-
*
|
|
28
|
-
* Outputs:
|
|
29
|
-
* - value: json (the constructed object)
|
|
30
|
-
*/
|
|
31
|
-
export declare const jsonObjectDef: NodeDefinitionWithImpl;
|
|
32
|
-
/**
|
|
33
|
-
* core/flow/guard - Stop the flow if a condition fails
|
|
34
|
-
*
|
|
35
|
-
* Inputs:
|
|
36
|
-
* - ok: boolean (the condition to check)
|
|
37
|
-
* - error?: json (optional error info)
|
|
38
|
-
*
|
|
39
|
-
* Outputs:
|
|
40
|
-
* - pass: signal (emitted if ok is true)
|
|
41
|
-
* - fail: signal (emitted if ok is false)
|
|
42
|
-
* - error: json (the error if failed)
|
|
43
|
-
*/
|
|
44
|
-
export declare const flowGuardDef: NodeDefinitionWithImpl;
|
|
45
|
-
/**
|
|
46
|
-
* core/string/template - Build a string from a template with placeholders
|
|
47
|
-
*
|
|
48
|
-
* Props:
|
|
49
|
-
* - template: string (template with {{placeholder}} syntax)
|
|
50
|
-
*
|
|
51
|
-
* Inputs:
|
|
52
|
-
* - (dynamic) values to substitute into the template
|
|
53
|
-
*
|
|
54
|
-
* Outputs:
|
|
55
|
-
* - value: string (the resulting string)
|
|
56
|
-
*/
|
|
57
|
-
export declare const stringTemplateDef: NodeDefinitionWithImpl;
|
|
58
|
-
/**
|
|
59
|
-
* core/string/concat - Concatenate strings with an optional separator
|
|
60
|
-
*
|
|
61
|
-
* Props:
|
|
62
|
-
* - prefix: string (optional prefix)
|
|
63
|
-
* - suffix: string (optional suffix)
|
|
64
|
-
*
|
|
65
|
-
* Inputs:
|
|
66
|
-
* - value: string (the main value)
|
|
67
|
-
*
|
|
68
|
-
* Outputs:
|
|
69
|
-
* - value: string (the resulting string)
|
|
70
|
-
*/
|
|
71
|
-
export declare const stringConcatDef: NodeDefinitionWithImpl;
|
|
72
|
-
export declare const coreDefinitions: NodeDefinitionWithImpl[];
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { NodeDefinitionWithImpl } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Math node definitions with implementations for testing.
|
|
4
|
-
*/
|
|
5
|
-
export declare const constNumberDef: NodeDefinitionWithImpl;
|
|
6
|
-
export declare const addDef: NodeDefinitionWithImpl;
|
|
7
|
-
export declare const multiplyDef: NodeDefinitionWithImpl;
|
|
8
|
-
export declare const mathDefinitions: NodeDefinitionWithImpl[];
|
package/esm/definitions/net.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { NodeDefinitionWithImpl } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Network node definitions with implementations.
|
|
4
|
-
* These nodes handle GraphQL requests and related operations.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* net/graphql/request - Execute GraphQL query or mutation
|
|
8
|
-
*
|
|
9
|
-
* Props:
|
|
10
|
-
* - document: string (GraphQL query/mutation document)
|
|
11
|
-
* - operationName?: string (optional operation name)
|
|
12
|
-
* - endpoint: string (GraphQL endpoint URL)
|
|
13
|
-
* - timeout?: number (request timeout in ms, default 30000)
|
|
14
|
-
*
|
|
15
|
-
* Inputs:
|
|
16
|
-
* - variables: json (GraphQL variables)
|
|
17
|
-
* - headers?: json (additional headers)
|
|
18
|
-
*
|
|
19
|
-
* Outputs:
|
|
20
|
-
* - data: json (response data)
|
|
21
|
-
* - error?: json (error if any)
|
|
22
|
-
* - ok: boolean (true if request succeeded without errors)
|
|
23
|
-
*/
|
|
24
|
-
export declare const graphqlRequestDef: NodeDefinitionWithImpl;
|
|
25
|
-
export declare const netDefinitions: NodeDefinitionWithImpl[];
|
package/esm/definitions/ui.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { NodeDefinitionWithImpl } from '../types';
|
|
2
|
-
export declare const graphInputDef: NodeDefinitionWithImpl;
|
|
3
|
-
export declare const graphOutputDef: NodeDefinitionWithImpl;
|
|
4
|
-
export declare const graphPropDef: NodeDefinitionWithImpl;
|
|
5
|
-
export declare const pageDef: NodeDefinitionWithImpl;
|
|
6
|
-
export declare const formDef: NodeDefinitionWithImpl;
|
|
7
|
-
export declare const inputDef: NodeDefinitionWithImpl;
|
|
8
|
-
export declare const buttonDef: NodeDefinitionWithImpl;
|
|
9
|
-
export declare const textDef: NodeDefinitionWithImpl;
|
|
10
|
-
export declare const uiDefinitions: NodeDefinitionWithImpl[];
|
package/esm/evaluate.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Graph } from '@fbp/types';
|
|
2
|
-
import type { EvaluateOptions } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Evaluate a graph starting from the specified output node/port.
|
|
5
|
-
* Uses lazy evaluation - only evaluates nodes that are needed for the output.
|
|
6
|
-
* Fully async to support async node implementations.
|
|
7
|
-
*
|
|
8
|
-
* @param graph - The graph to evaluate
|
|
9
|
-
* @param options - Evaluation options including definitions, output node/port, and external inputs
|
|
10
|
-
* @returns Promise resolving to the value at the specified output port
|
|
11
|
-
*/
|
|
12
|
-
export declare function evaluate(graph: Graph, options: EvaluateOptions): Promise<any>;
|
package/esm/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { evaluate } from './evaluate';
|
|
2
|
-
export type { NodeImplFn, NodeDefinitionWithImpl, EvaluateOptions, PropDefinitionWithOptions } from './types';
|
|
3
|
-
export { mathDefinitions, constNumberDef, addDef, multiplyDef } from './definitions/math';
|
|
4
|
-
export { uiDefinitions, pageDef, formDef, inputDef, buttonDef, textDef, graphInputDef, graphOutputDef, graphPropDef } from './definitions/ui';
|
|
5
|
-
export { coreDefinitions, jsonSelectDef, jsonObjectDef, flowGuardDef, stringTemplateDef, stringConcatDef } from './definitions/core';
|
|
6
|
-
export { netDefinitions, graphqlRequestDef } from './definitions/net';
|
package/esm/types.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { NodeDefinition, PropDefinition } from '@fbp/types';
|
|
2
|
-
/**
|
|
3
|
-
* A function that implements a node's computation.
|
|
4
|
-
* Takes inputs (keyed by port name) and props, returns outputs (keyed by port name).
|
|
5
|
-
* Can be sync or async - the evaluator will await the result.
|
|
6
|
-
*/
|
|
7
|
-
export type NodeImplFn = (inputs: Record<string, any>, props: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
|
|
8
|
-
/**
|
|
9
|
-
* Extended PropDefinition with runtime-only options for enum/select types.
|
|
10
|
-
* The options field is not part of the JSON schema but is used by the UI.
|
|
11
|
-
*/
|
|
12
|
-
export interface PropDefinitionWithOptions extends PropDefinition {
|
|
13
|
-
options?: string[];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A NodeDefinition extended with an optional implementation function.
|
|
17
|
-
* The impl function is not part of the JSON schema (not serializable),
|
|
18
|
-
* but is used at runtime for evaluation.
|
|
19
|
-
*/
|
|
20
|
-
export interface NodeDefinitionWithImpl extends Omit<NodeDefinition, 'props'> {
|
|
21
|
-
props?: PropDefinitionWithOptions[];
|
|
22
|
-
impl?: NodeImplFn;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Options for the evaluate function.
|
|
26
|
-
*/
|
|
27
|
-
export interface EvaluateOptions {
|
|
28
|
-
/** Node definitions with implementations */
|
|
29
|
-
definitions: NodeDefinitionWithImpl[];
|
|
30
|
-
/** The node to get output from */
|
|
31
|
-
outputNode: string;
|
|
32
|
-
/** The port to get output from */
|
|
33
|
-
outputPort: string;
|
|
34
|
-
/** External inputs to provide to graphInput nodes (keyed by portName property value) */
|
|
35
|
-
inputs?: Record<string, any>;
|
|
36
|
-
/** Props to provide to graphProp nodes (keyed by propName property value) */
|
|
37
|
-
props?: Record<string, any>;
|
|
38
|
-
}
|