@fbp/evaluator 0.2.0 → 1.1.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/definitions/core.js +10 -10
- package/definitions/math.js +3 -3
- package/definitions/net.js +2 -2
- package/definitions/ui.js +13 -13
- package/esm/definitions/core.js +10 -10
- package/esm/definitions/math.js +3 -3
- package/esm/definitions/net.js +2 -2
- package/esm/definitions/ui.js +13 -13
- package/esm/evaluate.js +52 -18
- package/evaluate.js +52 -18
- package/package.json +6 -6
package/definitions/core.js
CHANGED
|
@@ -18,9 +18,9 @@ exports.coreDefinitions = exports.stringConcatDef = exports.stringTemplateDef =
|
|
|
18
18
|
* - value: any (the extracted value)
|
|
19
19
|
*/
|
|
20
20
|
exports.jsonSelectDef = {
|
|
21
|
-
context: '
|
|
21
|
+
context: 'js',
|
|
22
|
+
name: 'select',
|
|
22
23
|
category: 'json',
|
|
23
|
-
type: 'core/json/select',
|
|
24
24
|
icon: 'circle',
|
|
25
25
|
inputs: [
|
|
26
26
|
{ name: 'obj', type: 'json' }
|
|
@@ -72,9 +72,9 @@ exports.jsonSelectDef = {
|
|
|
72
72
|
* - value: json (the constructed object)
|
|
73
73
|
*/
|
|
74
74
|
exports.jsonObjectDef = {
|
|
75
|
-
context: '
|
|
75
|
+
context: 'js',
|
|
76
|
+
name: 'object',
|
|
76
77
|
category: 'json',
|
|
77
|
-
type: 'core/json/object',
|
|
78
78
|
icon: 'braces',
|
|
79
79
|
inputs: [], // Dynamic inputs - any input name is valid
|
|
80
80
|
outputs: [
|
|
@@ -100,9 +100,9 @@ exports.jsonObjectDef = {
|
|
|
100
100
|
* - error: json (the error if failed)
|
|
101
101
|
*/
|
|
102
102
|
exports.flowGuardDef = {
|
|
103
|
-
context: '
|
|
103
|
+
context: 'js',
|
|
104
|
+
name: 'guard',
|
|
104
105
|
category: 'flow',
|
|
105
|
-
type: 'core/flow/guard',
|
|
106
106
|
icon: 'zap',
|
|
107
107
|
inputs: [
|
|
108
108
|
{ name: 'ok', type: 'boolean' },
|
|
@@ -146,9 +146,9 @@ exports.flowGuardDef = {
|
|
|
146
146
|
* - value: string (the resulting string)
|
|
147
147
|
*/
|
|
148
148
|
exports.stringTemplateDef = {
|
|
149
|
-
context: '
|
|
149
|
+
context: 'js',
|
|
150
|
+
name: 'template',
|
|
150
151
|
category: 'string',
|
|
151
|
-
type: 'core/string/template',
|
|
152
152
|
icon: 'quote',
|
|
153
153
|
inputs: [], // Dynamic inputs based on template placeholders
|
|
154
154
|
outputs: [
|
|
@@ -188,9 +188,9 @@ exports.stringTemplateDef = {
|
|
|
188
188
|
* - value: string (the resulting string)
|
|
189
189
|
*/
|
|
190
190
|
exports.stringConcatDef = {
|
|
191
|
-
context: '
|
|
191
|
+
context: 'js',
|
|
192
|
+
name: 'concat',
|
|
192
193
|
category: 'string',
|
|
193
|
-
type: 'core/string/concat',
|
|
194
194
|
icon: 'link',
|
|
195
195
|
inputs: [
|
|
196
196
|
{ name: 'value', type: 'string' }
|
package/definitions/math.js
CHANGED
|
@@ -6,8 +6,8 @@ exports.mathDefinitions = exports.multiplyDef = exports.addDef = exports.constNu
|
|
|
6
6
|
*/
|
|
7
7
|
exports.constNumberDef = {
|
|
8
8
|
context: 'js',
|
|
9
|
+
name: 'number',
|
|
9
10
|
category: 'const',
|
|
10
|
-
type: 'js/const/number',
|
|
11
11
|
icon: 'hash',
|
|
12
12
|
outputs: [{ name: 'value', type: 'number' }],
|
|
13
13
|
props: [{ name: 'value', type: 'number', default: 0 }],
|
|
@@ -18,8 +18,8 @@ exports.constNumberDef = {
|
|
|
18
18
|
};
|
|
19
19
|
exports.addDef = {
|
|
20
20
|
context: 'js',
|
|
21
|
+
name: 'add',
|
|
21
22
|
category: 'math',
|
|
22
|
-
type: 'js/math/add',
|
|
23
23
|
icon: 'plus',
|
|
24
24
|
inputs: [
|
|
25
25
|
{ name: 'a', type: 'number' },
|
|
@@ -33,8 +33,8 @@ exports.addDef = {
|
|
|
33
33
|
};
|
|
34
34
|
exports.multiplyDef = {
|
|
35
35
|
context: 'js',
|
|
36
|
+
name: 'multiply',
|
|
36
37
|
category: 'math',
|
|
37
|
-
type: 'js/math/multiply',
|
|
38
38
|
icon: 'x',
|
|
39
39
|
inputs: [
|
|
40
40
|
{ name: 'a', type: 'number' },
|
package/definitions/net.js
CHANGED
|
@@ -24,9 +24,9 @@ exports.netDefinitions = exports.graphqlRequestDef = void 0;
|
|
|
24
24
|
* - ok: boolean (true if request succeeded without errors)
|
|
25
25
|
*/
|
|
26
26
|
exports.graphqlRequestDef = {
|
|
27
|
-
context: '
|
|
27
|
+
context: 'js',
|
|
28
|
+
name: 'request',
|
|
28
29
|
category: 'graphql',
|
|
29
|
-
type: 'net/graphql/request',
|
|
30
30
|
icon: 'graphql',
|
|
31
31
|
inputs: [
|
|
32
32
|
{ name: 'variables', type: 'json' },
|
package/definitions/ui.js
CHANGED
|
@@ -25,8 +25,8 @@ function coerceValue(value, valueType) {
|
|
|
25
25
|
// Boundary node definitions for graph inputs/outputs
|
|
26
26
|
exports.graphInputDef = {
|
|
27
27
|
context: 'core',
|
|
28
|
+
name: 'graphInput',
|
|
28
29
|
category: 'graph',
|
|
29
|
-
type: 'core/graph/input',
|
|
30
30
|
icon: 'arrow-right',
|
|
31
31
|
inputs: [],
|
|
32
32
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -39,8 +39,8 @@ exports.graphInputDef = {
|
|
|
39
39
|
};
|
|
40
40
|
exports.graphOutputDef = {
|
|
41
41
|
context: 'core',
|
|
42
|
+
name: 'graphOutput',
|
|
42
43
|
category: 'graph',
|
|
43
|
-
type: 'core/graph/output',
|
|
44
44
|
icon: 'arrow-left',
|
|
45
45
|
inputs: [{ name: 'value', type: 'any' }],
|
|
46
46
|
outputs: [],
|
|
@@ -52,8 +52,8 @@ exports.graphOutputDef = {
|
|
|
52
52
|
};
|
|
53
53
|
exports.graphPropDef = {
|
|
54
54
|
context: 'core',
|
|
55
|
+
name: 'graphProp',
|
|
55
56
|
category: 'graph',
|
|
56
|
-
type: 'core/graph/prop',
|
|
57
57
|
icon: 'settings',
|
|
58
58
|
inputs: [],
|
|
59
59
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -65,9 +65,9 @@ exports.graphPropDef = {
|
|
|
65
65
|
impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
|
|
66
66
|
};
|
|
67
67
|
exports.pageDef = {
|
|
68
|
-
context: '
|
|
68
|
+
context: 'js',
|
|
69
|
+
name: 'Page',
|
|
69
70
|
category: 'layout',
|
|
70
|
-
type: 'ui/layout/Page',
|
|
71
71
|
icon: 'file',
|
|
72
72
|
inputs: [
|
|
73
73
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -88,9 +88,9 @@ exports.pageDef = {
|
|
|
88
88
|
})
|
|
89
89
|
};
|
|
90
90
|
exports.formDef = {
|
|
91
|
-
context: '
|
|
91
|
+
context: 'js',
|
|
92
|
+
name: 'Form',
|
|
92
93
|
category: 'form',
|
|
93
|
-
type: 'ui/form/Form',
|
|
94
94
|
icon: 'file-text',
|
|
95
95
|
inputs: [
|
|
96
96
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -111,9 +111,9 @@ exports.formDef = {
|
|
|
111
111
|
})
|
|
112
112
|
};
|
|
113
113
|
exports.inputDef = {
|
|
114
|
-
context: '
|
|
114
|
+
context: 'js',
|
|
115
|
+
name: 'Input',
|
|
115
116
|
category: 'form',
|
|
116
|
-
type: 'ui/form/Input',
|
|
117
117
|
icon: 'text-cursor',
|
|
118
118
|
inputs: [],
|
|
119
119
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -137,9 +137,9 @@ exports.inputDef = {
|
|
|
137
137
|
})
|
|
138
138
|
};
|
|
139
139
|
exports.buttonDef = {
|
|
140
|
-
context: '
|
|
140
|
+
context: 'js',
|
|
141
|
+
name: 'Button',
|
|
141
142
|
category: 'form',
|
|
142
|
-
type: 'ui/form/Button',
|
|
143
143
|
icon: 'square',
|
|
144
144
|
inputs: [],
|
|
145
145
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -161,9 +161,9 @@ exports.buttonDef = {
|
|
|
161
161
|
})
|
|
162
162
|
};
|
|
163
163
|
exports.textDef = {
|
|
164
|
-
context: '
|
|
164
|
+
context: 'js',
|
|
165
|
+
name: 'Text',
|
|
165
166
|
category: 'content',
|
|
166
|
-
type: 'ui/content/Text',
|
|
167
167
|
icon: 'type',
|
|
168
168
|
inputs: [],
|
|
169
169
|
outputs: [{ name: 'element', type: 'Element' }],
|
package/esm/definitions/core.js
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* - value: any (the extracted value)
|
|
16
16
|
*/
|
|
17
17
|
export const jsonSelectDef = {
|
|
18
|
-
context: '
|
|
18
|
+
context: 'js',
|
|
19
|
+
name: 'select',
|
|
19
20
|
category: 'json',
|
|
20
|
-
type: 'core/json/select',
|
|
21
21
|
icon: 'circle',
|
|
22
22
|
inputs: [
|
|
23
23
|
{ name: 'obj', type: 'json' }
|
|
@@ -69,9 +69,9 @@ export const jsonSelectDef = {
|
|
|
69
69
|
* - value: json (the constructed object)
|
|
70
70
|
*/
|
|
71
71
|
export const jsonObjectDef = {
|
|
72
|
-
context: '
|
|
72
|
+
context: 'js',
|
|
73
|
+
name: 'object',
|
|
73
74
|
category: 'json',
|
|
74
|
-
type: 'core/json/object',
|
|
75
75
|
icon: 'braces',
|
|
76
76
|
inputs: [], // Dynamic inputs - any input name is valid
|
|
77
77
|
outputs: [
|
|
@@ -97,9 +97,9 @@ export const jsonObjectDef = {
|
|
|
97
97
|
* - error: json (the error if failed)
|
|
98
98
|
*/
|
|
99
99
|
export const flowGuardDef = {
|
|
100
|
-
context: '
|
|
100
|
+
context: 'js',
|
|
101
|
+
name: 'guard',
|
|
101
102
|
category: 'flow',
|
|
102
|
-
type: 'core/flow/guard',
|
|
103
103
|
icon: 'zap',
|
|
104
104
|
inputs: [
|
|
105
105
|
{ name: 'ok', type: 'boolean' },
|
|
@@ -143,9 +143,9 @@ export const flowGuardDef = {
|
|
|
143
143
|
* - value: string (the resulting string)
|
|
144
144
|
*/
|
|
145
145
|
export const stringTemplateDef = {
|
|
146
|
-
context: '
|
|
146
|
+
context: 'js',
|
|
147
|
+
name: 'template',
|
|
147
148
|
category: 'string',
|
|
148
|
-
type: 'core/string/template',
|
|
149
149
|
icon: 'quote',
|
|
150
150
|
inputs: [], // Dynamic inputs based on template placeholders
|
|
151
151
|
outputs: [
|
|
@@ -185,9 +185,9 @@ export const stringTemplateDef = {
|
|
|
185
185
|
* - value: string (the resulting string)
|
|
186
186
|
*/
|
|
187
187
|
export const stringConcatDef = {
|
|
188
|
-
context: '
|
|
188
|
+
context: 'js',
|
|
189
|
+
name: 'concat',
|
|
189
190
|
category: 'string',
|
|
190
|
-
type: 'core/string/concat',
|
|
191
191
|
icon: 'link',
|
|
192
192
|
inputs: [
|
|
193
193
|
{ name: 'value', type: 'string' }
|
package/esm/definitions/math.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const constNumberDef = {
|
|
5
5
|
context: 'js',
|
|
6
|
+
name: 'number',
|
|
6
7
|
category: 'const',
|
|
7
|
-
type: 'js/const/number',
|
|
8
8
|
icon: 'hash',
|
|
9
9
|
outputs: [{ name: 'value', type: 'number' }],
|
|
10
10
|
props: [{ name: 'value', type: 'number', default: 0 }],
|
|
@@ -15,8 +15,8 @@ export const constNumberDef = {
|
|
|
15
15
|
};
|
|
16
16
|
export const addDef = {
|
|
17
17
|
context: 'js',
|
|
18
|
+
name: 'add',
|
|
18
19
|
category: 'math',
|
|
19
|
-
type: 'js/math/add',
|
|
20
20
|
icon: 'plus',
|
|
21
21
|
inputs: [
|
|
22
22
|
{ name: 'a', type: 'number' },
|
|
@@ -30,8 +30,8 @@ export const addDef = {
|
|
|
30
30
|
};
|
|
31
31
|
export const multiplyDef = {
|
|
32
32
|
context: 'js',
|
|
33
|
+
name: 'multiply',
|
|
33
34
|
category: 'math',
|
|
34
|
-
type: 'js/math/multiply',
|
|
35
35
|
icon: 'x',
|
|
36
36
|
inputs: [
|
|
37
37
|
{ name: 'a', type: 'number' },
|
package/esm/definitions/net.js
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* - ok: boolean (true if request succeeded without errors)
|
|
22
22
|
*/
|
|
23
23
|
export const graphqlRequestDef = {
|
|
24
|
-
context: '
|
|
24
|
+
context: 'js',
|
|
25
|
+
name: 'request',
|
|
25
26
|
category: 'graphql',
|
|
26
|
-
type: 'net/graphql/request',
|
|
27
27
|
icon: 'graphql',
|
|
28
28
|
inputs: [
|
|
29
29
|
{ name: 'variables', type: 'json' },
|
package/esm/definitions/ui.js
CHANGED
|
@@ -22,8 +22,8 @@ function coerceValue(value, valueType) {
|
|
|
22
22
|
// Boundary node definitions for graph inputs/outputs
|
|
23
23
|
export const graphInputDef = {
|
|
24
24
|
context: 'core',
|
|
25
|
+
name: 'graphInput',
|
|
25
26
|
category: 'graph',
|
|
26
|
-
type: 'core/graph/input',
|
|
27
27
|
icon: 'arrow-right',
|
|
28
28
|
inputs: [],
|
|
29
29
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -36,8 +36,8 @@ export const graphInputDef = {
|
|
|
36
36
|
};
|
|
37
37
|
export const graphOutputDef = {
|
|
38
38
|
context: 'core',
|
|
39
|
+
name: 'graphOutput',
|
|
39
40
|
category: 'graph',
|
|
40
|
-
type: 'core/graph/output',
|
|
41
41
|
icon: 'arrow-left',
|
|
42
42
|
inputs: [{ name: 'value', type: 'any' }],
|
|
43
43
|
outputs: [],
|
|
@@ -49,8 +49,8 @@ export const graphOutputDef = {
|
|
|
49
49
|
};
|
|
50
50
|
export const graphPropDef = {
|
|
51
51
|
context: 'core',
|
|
52
|
+
name: 'graphProp',
|
|
52
53
|
category: 'graph',
|
|
53
|
-
type: 'core/graph/prop',
|
|
54
54
|
icon: 'settings',
|
|
55
55
|
inputs: [],
|
|
56
56
|
outputs: [{ name: 'value', type: 'any' }],
|
|
@@ -62,9 +62,9 @@ export const graphPropDef = {
|
|
|
62
62
|
impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
|
|
63
63
|
};
|
|
64
64
|
export const pageDef = {
|
|
65
|
-
context: '
|
|
65
|
+
context: 'js',
|
|
66
|
+
name: 'Page',
|
|
66
67
|
category: 'layout',
|
|
67
|
-
type: 'ui/layout/Page',
|
|
68
68
|
icon: 'file',
|
|
69
69
|
inputs: [
|
|
70
70
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -85,9 +85,9 @@ export const pageDef = {
|
|
|
85
85
|
})
|
|
86
86
|
};
|
|
87
87
|
export const formDef = {
|
|
88
|
-
context: '
|
|
88
|
+
context: 'js',
|
|
89
|
+
name: 'Form',
|
|
89
90
|
category: 'form',
|
|
90
|
-
type: 'ui/form/Form',
|
|
91
91
|
icon: 'file-text',
|
|
92
92
|
inputs: [
|
|
93
93
|
{ name: 'children', type: 'Element[]', multi: true }
|
|
@@ -108,9 +108,9 @@ export const formDef = {
|
|
|
108
108
|
})
|
|
109
109
|
};
|
|
110
110
|
export const inputDef = {
|
|
111
|
-
context: '
|
|
111
|
+
context: 'js',
|
|
112
|
+
name: 'Input',
|
|
112
113
|
category: 'form',
|
|
113
|
-
type: 'ui/form/Input',
|
|
114
114
|
icon: 'text-cursor',
|
|
115
115
|
inputs: [],
|
|
116
116
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -134,9 +134,9 @@ export const inputDef = {
|
|
|
134
134
|
})
|
|
135
135
|
};
|
|
136
136
|
export const buttonDef = {
|
|
137
|
-
context: '
|
|
137
|
+
context: 'js',
|
|
138
|
+
name: 'Button',
|
|
138
139
|
category: 'form',
|
|
139
|
-
type: 'ui/form/Button',
|
|
140
140
|
icon: 'square',
|
|
141
141
|
inputs: [],
|
|
142
142
|
outputs: [{ name: 'element', type: 'Element' }],
|
|
@@ -158,9 +158,9 @@ export const buttonDef = {
|
|
|
158
158
|
})
|
|
159
159
|
};
|
|
160
160
|
export const textDef = {
|
|
161
|
-
context: '
|
|
161
|
+
context: 'js',
|
|
162
|
+
name: 'Text',
|
|
162
163
|
category: 'content',
|
|
163
|
-
type: 'ui/content/Text',
|
|
164
164
|
icon: 'type',
|
|
165
165
|
inputs: [],
|
|
166
166
|
outputs: [{ name: 'element', type: 'Element' }],
|
package/esm/evaluate.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a definition map key from context and name.
|
|
3
|
+
*/
|
|
4
|
+
function defKey(context, name) {
|
|
5
|
+
return `${context}:${name}`;
|
|
6
|
+
}
|
|
1
7
|
/**
|
|
2
8
|
* Evaluate a graph starting from the specified output node/port.
|
|
3
9
|
* Uses lazy evaluation - only evaluates nodes that are needed for the output.
|
|
@@ -16,8 +22,10 @@ export async function evaluate(graph, options) {
|
|
|
16
22
|
}
|
|
17
23
|
const defMap = new Map();
|
|
18
24
|
for (const def of definitions) {
|
|
19
|
-
defMap.set(def.
|
|
25
|
+
defMap.set(defKey(def.context, def.name), def);
|
|
20
26
|
}
|
|
27
|
+
// Graph-level context used as default for node lookups
|
|
28
|
+
const graphContext = graph.context || '';
|
|
21
29
|
// Build edge lookup: destination node -> destination port -> edges (in array order)
|
|
22
30
|
const edgesByDst = new Map();
|
|
23
31
|
for (const edge of graph.edges) {
|
|
@@ -47,8 +55,8 @@ export async function evaluate(graph, options) {
|
|
|
47
55
|
if (!node) {
|
|
48
56
|
throw new Error(`Node not found: ${nodeName}`);
|
|
49
57
|
}
|
|
50
|
-
// Handle
|
|
51
|
-
//
|
|
58
|
+
// Handle system nodes (graphInput, graphOutput, graphProp)
|
|
59
|
+
// System nodes are identified by their type name — reserved, no definition lookup needed
|
|
52
60
|
if (node.type === 'graphInput') {
|
|
53
61
|
// Get the port name from the portName property
|
|
54
62
|
const portNameProp = node.props?.find(p => p.name === 'portName');
|
|
@@ -72,8 +80,22 @@ export async function evaluate(graph, options) {
|
|
|
72
80
|
cache.set(nodeName, result);
|
|
73
81
|
return result;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
if (node.type === 'graphOutput') {
|
|
84
|
+
// graphOutput is a pass-through: evaluate its upstream 'value' input
|
|
85
|
+
const portEdges = edgesByDst.get(nodeName);
|
|
86
|
+
const edges = portEdges?.get('value') ?? [];
|
|
87
|
+
let value = undefined;
|
|
88
|
+
if (edges.length > 0) {
|
|
89
|
+
const edge = edges[0];
|
|
90
|
+
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
91
|
+
value = upstreamOutputs[edge.src.port];
|
|
92
|
+
}
|
|
93
|
+
const result = { value };
|
|
94
|
+
cache.set(nodeName, result);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
// Handle subnet nodes (type: 'subnet' with inline nodes/edges)
|
|
98
|
+
if (node.type === 'subnet' && node.nodes && node.edges) {
|
|
77
99
|
// Collect inputs for the subnet by evaluating upstream nodes
|
|
78
100
|
const subnetInputs = {};
|
|
79
101
|
const subnetPortEdges = edgesByDst.get(nodeName);
|
|
@@ -104,6 +126,7 @@ export async function evaluate(graph, options) {
|
|
|
104
126
|
// Recursively evaluate the subnet's internal graph
|
|
105
127
|
const subnetResult = await evaluate({
|
|
106
128
|
name: `${nodeName}_subnet`,
|
|
129
|
+
context: graphContext || undefined,
|
|
107
130
|
nodes: node.nodes,
|
|
108
131
|
edges: node.edges
|
|
109
132
|
}, {
|
|
@@ -118,13 +141,11 @@ export async function evaluate(graph, options) {
|
|
|
118
141
|
cache.set(nodeName, subnetOutputs);
|
|
119
142
|
return subnetOutputs;
|
|
120
143
|
}
|
|
121
|
-
// Get the definition for this node
|
|
122
|
-
const
|
|
144
|
+
// Get the definition for this node — resolve context from node override or graph default
|
|
145
|
+
const nodeContext = node.context || graphContext;
|
|
146
|
+
const definition = defMap.get(defKey(nodeContext, node.type));
|
|
123
147
|
if (!definition) {
|
|
124
|
-
throw new Error(`No definition found for node
|
|
125
|
-
}
|
|
126
|
-
if (!definition.impl) {
|
|
127
|
-
throw new Error(`No implementation found for node type: ${node.type}`);
|
|
148
|
+
throw new Error(`No definition found for node: ${nodeContext}:${node.type}`);
|
|
128
149
|
}
|
|
129
150
|
// Collect inputs by evaluating upstream nodes
|
|
130
151
|
const nodeInputs = {};
|
|
@@ -133,7 +154,6 @@ export async function evaluate(graph, options) {
|
|
|
133
154
|
for (const inputPort of definition.inputs) {
|
|
134
155
|
const edges = portEdges?.get(inputPort.name) ?? [];
|
|
135
156
|
if (inputPort.multi) {
|
|
136
|
-
// Multi-input port: collect all values in edge array order
|
|
137
157
|
const values = await Promise.all(edges.map(async (edge) => {
|
|
138
158
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
139
159
|
return upstreamOutputs[edge.src.port];
|
|
@@ -141,7 +161,6 @@ export async function evaluate(graph, options) {
|
|
|
141
161
|
nodeInputs[inputPort.name] = values;
|
|
142
162
|
}
|
|
143
163
|
else {
|
|
144
|
-
// Single input: take first edge if exists
|
|
145
164
|
if (edges.length > 0) {
|
|
146
165
|
const edge = edges[0];
|
|
147
166
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
@@ -150,24 +169,39 @@ export async function evaluate(graph, options) {
|
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
171
|
}
|
|
153
|
-
// Get props from node instance
|
|
172
|
+
// Get props from node instance (override definition defaults)
|
|
154
173
|
const nodeProps = {};
|
|
155
174
|
if (definition.props) {
|
|
156
175
|
for (const propDef of definition.props) {
|
|
157
|
-
// First check node instance props
|
|
158
176
|
const instanceProp = node.props?.find(p => p.name === propDef.name);
|
|
159
177
|
if (instanceProp !== undefined && instanceProp.value !== undefined) {
|
|
160
178
|
nodeProps[propDef.name] = instanceProp.value;
|
|
161
179
|
}
|
|
162
180
|
else if (propDef.default !== undefined) {
|
|
163
|
-
// Fall back to definition default
|
|
164
181
|
nodeProps[propDef.name] = propDef.default;
|
|
165
182
|
}
|
|
166
183
|
}
|
|
167
184
|
}
|
|
168
|
-
//
|
|
185
|
+
// Digital asset: definition has an internal graph — evaluate it recursively
|
|
186
|
+
if (definition.graph) {
|
|
187
|
+
const assetGraph = definition.graph;
|
|
188
|
+
// Find all output boundary nodes in the asset's graph
|
|
189
|
+
const assetOutputs = {};
|
|
190
|
+
const outputBoundaryNodes = assetGraph.nodes.filter(n => n.type === 'graphOutput');
|
|
191
|
+
for (const outputBoundaryNode of outputBoundaryNodes) {
|
|
192
|
+
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
|
193
|
+
const portName = portNameProp?.value || outputBoundaryNode.name;
|
|
194
|
+
const result = await evaluate({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, outputNode: outputBoundaryNode.name, outputPort: 'value', inputs: nodeInputs, props: nodeProps });
|
|
195
|
+
assetOutputs[portName] = result;
|
|
196
|
+
}
|
|
197
|
+
cache.set(nodeName, assetOutputs);
|
|
198
|
+
return assetOutputs;
|
|
199
|
+
}
|
|
200
|
+
// Leaf node: call the implementation function
|
|
201
|
+
if (!definition.impl) {
|
|
202
|
+
throw new Error(`No implementation found for node: ${nodeContext}:${node.type}`);
|
|
203
|
+
}
|
|
169
204
|
const outputs = await definition.impl(nodeInputs, nodeProps);
|
|
170
|
-
// Cache and return
|
|
171
205
|
cache.set(nodeName, outputs);
|
|
172
206
|
return outputs;
|
|
173
207
|
}
|
package/evaluate.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evaluate = evaluate;
|
|
4
|
+
/**
|
|
5
|
+
* Build a definition map key from context and name.
|
|
6
|
+
*/
|
|
7
|
+
function defKey(context, name) {
|
|
8
|
+
return `${context}:${name}`;
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* Evaluate a graph starting from the specified output node/port.
|
|
6
12
|
* Uses lazy evaluation - only evaluates nodes that are needed for the output.
|
|
@@ -19,8 +25,10 @@ async function evaluate(graph, options) {
|
|
|
19
25
|
}
|
|
20
26
|
const defMap = new Map();
|
|
21
27
|
for (const def of definitions) {
|
|
22
|
-
defMap.set(def.
|
|
28
|
+
defMap.set(defKey(def.context, def.name), def);
|
|
23
29
|
}
|
|
30
|
+
// Graph-level context used as default for node lookups
|
|
31
|
+
const graphContext = graph.context || '';
|
|
24
32
|
// Build edge lookup: destination node -> destination port -> edges (in array order)
|
|
25
33
|
const edgesByDst = new Map();
|
|
26
34
|
for (const edge of graph.edges) {
|
|
@@ -50,8 +58,8 @@ async function evaluate(graph, options) {
|
|
|
50
58
|
if (!node) {
|
|
51
59
|
throw new Error(`Node not found: ${nodeName}`);
|
|
52
60
|
}
|
|
53
|
-
// Handle
|
|
54
|
-
//
|
|
61
|
+
// Handle system nodes (graphInput, graphOutput, graphProp)
|
|
62
|
+
// System nodes are identified by their type name — reserved, no definition lookup needed
|
|
55
63
|
if (node.type === 'graphInput') {
|
|
56
64
|
// Get the port name from the portName property
|
|
57
65
|
const portNameProp = node.props?.find(p => p.name === 'portName');
|
|
@@ -75,8 +83,22 @@ async function evaluate(graph, options) {
|
|
|
75
83
|
cache.set(nodeName, result);
|
|
76
84
|
return result;
|
|
77
85
|
}
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
if (node.type === 'graphOutput') {
|
|
87
|
+
// graphOutput is a pass-through: evaluate its upstream 'value' input
|
|
88
|
+
const portEdges = edgesByDst.get(nodeName);
|
|
89
|
+
const edges = portEdges?.get('value') ?? [];
|
|
90
|
+
let value = undefined;
|
|
91
|
+
if (edges.length > 0) {
|
|
92
|
+
const edge = edges[0];
|
|
93
|
+
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
94
|
+
value = upstreamOutputs[edge.src.port];
|
|
95
|
+
}
|
|
96
|
+
const result = { value };
|
|
97
|
+
cache.set(nodeName, result);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
// Handle subnet nodes (type: 'subnet' with inline nodes/edges)
|
|
101
|
+
if (node.type === 'subnet' && node.nodes && node.edges) {
|
|
80
102
|
// Collect inputs for the subnet by evaluating upstream nodes
|
|
81
103
|
const subnetInputs = {};
|
|
82
104
|
const subnetPortEdges = edgesByDst.get(nodeName);
|
|
@@ -107,6 +129,7 @@ async function evaluate(graph, options) {
|
|
|
107
129
|
// Recursively evaluate the subnet's internal graph
|
|
108
130
|
const subnetResult = await evaluate({
|
|
109
131
|
name: `${nodeName}_subnet`,
|
|
132
|
+
context: graphContext || undefined,
|
|
110
133
|
nodes: node.nodes,
|
|
111
134
|
edges: node.edges
|
|
112
135
|
}, {
|
|
@@ -121,13 +144,11 @@ async function evaluate(graph, options) {
|
|
|
121
144
|
cache.set(nodeName, subnetOutputs);
|
|
122
145
|
return subnetOutputs;
|
|
123
146
|
}
|
|
124
|
-
// Get the definition for this node
|
|
125
|
-
const
|
|
147
|
+
// Get the definition for this node — resolve context from node override or graph default
|
|
148
|
+
const nodeContext = node.context || graphContext;
|
|
149
|
+
const definition = defMap.get(defKey(nodeContext, node.type));
|
|
126
150
|
if (!definition) {
|
|
127
|
-
throw new Error(`No definition found for node
|
|
128
|
-
}
|
|
129
|
-
if (!definition.impl) {
|
|
130
|
-
throw new Error(`No implementation found for node type: ${node.type}`);
|
|
151
|
+
throw new Error(`No definition found for node: ${nodeContext}:${node.type}`);
|
|
131
152
|
}
|
|
132
153
|
// Collect inputs by evaluating upstream nodes
|
|
133
154
|
const nodeInputs = {};
|
|
@@ -136,7 +157,6 @@ async function evaluate(graph, options) {
|
|
|
136
157
|
for (const inputPort of definition.inputs) {
|
|
137
158
|
const edges = portEdges?.get(inputPort.name) ?? [];
|
|
138
159
|
if (inputPort.multi) {
|
|
139
|
-
// Multi-input port: collect all values in edge array order
|
|
140
160
|
const values = await Promise.all(edges.map(async (edge) => {
|
|
141
161
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
142
162
|
return upstreamOutputs[edge.src.port];
|
|
@@ -144,7 +164,6 @@ async function evaluate(graph, options) {
|
|
|
144
164
|
nodeInputs[inputPort.name] = values;
|
|
145
165
|
}
|
|
146
166
|
else {
|
|
147
|
-
// Single input: take first edge if exists
|
|
148
167
|
if (edges.length > 0) {
|
|
149
168
|
const edge = edges[0];
|
|
150
169
|
const upstreamOutputs = await evaluateNode(edge.src.node);
|
|
@@ -153,24 +172,39 @@ async function evaluate(graph, options) {
|
|
|
153
172
|
}
|
|
154
173
|
}
|
|
155
174
|
}
|
|
156
|
-
// Get props from node instance
|
|
175
|
+
// Get props from node instance (override definition defaults)
|
|
157
176
|
const nodeProps = {};
|
|
158
177
|
if (definition.props) {
|
|
159
178
|
for (const propDef of definition.props) {
|
|
160
|
-
// First check node instance props
|
|
161
179
|
const instanceProp = node.props?.find(p => p.name === propDef.name);
|
|
162
180
|
if (instanceProp !== undefined && instanceProp.value !== undefined) {
|
|
163
181
|
nodeProps[propDef.name] = instanceProp.value;
|
|
164
182
|
}
|
|
165
183
|
else if (propDef.default !== undefined) {
|
|
166
|
-
// Fall back to definition default
|
|
167
184
|
nodeProps[propDef.name] = propDef.default;
|
|
168
185
|
}
|
|
169
186
|
}
|
|
170
187
|
}
|
|
171
|
-
//
|
|
188
|
+
// Digital asset: definition has an internal graph — evaluate it recursively
|
|
189
|
+
if (definition.graph) {
|
|
190
|
+
const assetGraph = definition.graph;
|
|
191
|
+
// Find all output boundary nodes in the asset's graph
|
|
192
|
+
const assetOutputs = {};
|
|
193
|
+
const outputBoundaryNodes = assetGraph.nodes.filter(n => n.type === 'graphOutput');
|
|
194
|
+
for (const outputBoundaryNode of outputBoundaryNodes) {
|
|
195
|
+
const portNameProp = outputBoundaryNode.props?.find(p => p.name === 'portName');
|
|
196
|
+
const portName = portNameProp?.value || outputBoundaryNode.name;
|
|
197
|
+
const result = await evaluate({ name: `${nodeName}_asset`, context: assetGraph.context, nodes: assetGraph.nodes, edges: assetGraph.edges }, { definitions, outputNode: outputBoundaryNode.name, outputPort: 'value', inputs: nodeInputs, props: nodeProps });
|
|
198
|
+
assetOutputs[portName] = result;
|
|
199
|
+
}
|
|
200
|
+
cache.set(nodeName, assetOutputs);
|
|
201
|
+
return assetOutputs;
|
|
202
|
+
}
|
|
203
|
+
// Leaf node: call the implementation function
|
|
204
|
+
if (!definition.impl) {
|
|
205
|
+
throw new Error(`No implementation found for node: ${nodeContext}:${node.type}`);
|
|
206
|
+
}
|
|
172
207
|
const outputs = await definition.impl(nodeInputs, nodeProps);
|
|
173
|
-
// Cache and return
|
|
174
208
|
cache.set(nodeName, outputs);
|
|
175
209
|
return outputs;
|
|
176
210
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbp/evaluator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Lazy graph evaluator for Flow-Based Programming",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
8
8
|
"types": "index.d.ts",
|
|
9
|
-
"homepage": "https://github.com/
|
|
9
|
+
"homepage": "https://github.com/flow-based-programming/spec",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/flow-based-programming/spec"
|
|
18
18
|
},
|
|
19
19
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/flow-based-programming/spec/issues"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "makage clean",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"lazy-evaluation"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fbp/types": "
|
|
38
|
+
"@fbp/types": "1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"makage": "0.1.9"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "6f0ef58d9a54f35a2a5849e84234a67fa8d8a9b5"
|
|
44
44
|
}
|