@fbp/evaluator 0.2.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.
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uiDefinitions = exports.textDef = exports.buttonDef = exports.inputDef = exports.formDef = exports.pageDef = exports.graphPropDef = exports.graphOutputDef = exports.graphInputDef = void 0;
4
+ /**
5
+ * UI component node definitions with implementations for testing.
6
+ * These produce vdom JSON structures.
7
+ */
8
+ // Type coercion helper for boundary nodes
9
+ function coerceValue(value, valueType) {
10
+ if (value === undefined || value === null)
11
+ return value;
12
+ switch (valueType) {
13
+ case 'number':
14
+ return typeof value === 'number' ? value : parseFloat(String(value)) || 0;
15
+ case 'string':
16
+ return String(value);
17
+ case 'boolean':
18
+ return value === true || value === 'true' || value === 1;
19
+ case 'Element':
20
+ case 'any':
21
+ default:
22
+ return value;
23
+ }
24
+ }
25
+ // Boundary node definitions for graph inputs/outputs
26
+ exports.graphInputDef = {
27
+ context: 'core',
28
+ category: 'graph',
29
+ type: 'core/graph/input',
30
+ icon: 'arrow-right',
31
+ inputs: [],
32
+ outputs: [{ name: 'value', type: 'any' }],
33
+ props: [
34
+ { name: 'valueType', type: 'enum', default: 'any', options: ['any', 'number', 'string', 'boolean', 'Element'] },
35
+ { name: 'default', type: 'any' }
36
+ ],
37
+ description: 'Graph input boundary node',
38
+ impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
39
+ };
40
+ exports.graphOutputDef = {
41
+ context: 'core',
42
+ category: 'graph',
43
+ type: 'core/graph/output',
44
+ icon: 'arrow-left',
45
+ inputs: [{ name: 'value', type: 'any' }],
46
+ outputs: [],
47
+ props: [
48
+ { name: 'valueType', type: 'enum', default: 'any', options: ['any', 'number', 'string', 'boolean', 'Element'] }
49
+ ],
50
+ description: 'Graph output boundary node',
51
+ impl: (inputs, props) => ({ value: coerceValue(inputs.value, props?.valueType ?? 'any') })
52
+ };
53
+ exports.graphPropDef = {
54
+ context: 'core',
55
+ category: 'graph',
56
+ type: 'core/graph/prop',
57
+ icon: 'settings',
58
+ inputs: [],
59
+ outputs: [{ name: 'value', type: 'any' }],
60
+ props: [
61
+ { name: 'valueType', type: 'enum', default: 'any', options: ['any', 'number', 'string', 'boolean', 'Element'] },
62
+ { name: 'default', type: 'any' }
63
+ ],
64
+ description: 'Graph property boundary node',
65
+ impl: (_inputs, props) => ({ value: coerceValue(props?.value ?? props?.default, props?.valueType ?? 'any') })
66
+ };
67
+ exports.pageDef = {
68
+ context: 'ui',
69
+ category: 'layout',
70
+ type: 'ui/layout/Page',
71
+ icon: 'file',
72
+ inputs: [
73
+ { name: 'children', type: 'Element[]', multi: true }
74
+ ],
75
+ outputs: [{ name: 'element', type: 'Element' }],
76
+ props: [
77
+ { name: 'className', type: 'string', default: '' },
78
+ { name: 'key', type: 'string', required: true }
79
+ ],
80
+ description: 'A page container component',
81
+ impl: (inputs, props) => ({
82
+ element: {
83
+ type: 'Page',
84
+ key: props.key,
85
+ props: { className: props.className },
86
+ children: inputs.children ?? []
87
+ }
88
+ })
89
+ };
90
+ exports.formDef = {
91
+ context: 'ui',
92
+ category: 'form',
93
+ type: 'ui/form/Form',
94
+ icon: 'file-text',
95
+ inputs: [
96
+ { name: 'children', type: 'Element[]', multi: true }
97
+ ],
98
+ outputs: [{ name: 'element', type: 'Element' }],
99
+ props: [
100
+ { name: 'className', type: 'string', default: '' },
101
+ { name: 'key', type: 'string', required: true }
102
+ ],
103
+ description: 'A form container component',
104
+ impl: (inputs, props) => ({
105
+ element: {
106
+ type: 'Form',
107
+ key: props.key,
108
+ props: { className: props.className },
109
+ children: inputs.children ?? []
110
+ }
111
+ })
112
+ };
113
+ exports.inputDef = {
114
+ context: 'ui',
115
+ category: 'form',
116
+ type: 'ui/form/Input',
117
+ icon: 'text-cursor',
118
+ inputs: [],
119
+ outputs: [{ name: 'element', type: 'Element' }],
120
+ props: [
121
+ { name: 'key', type: 'string', required: true },
122
+ { name: 'name', type: 'string', required: true },
123
+ { name: 'type', type: 'string', default: 'text' },
124
+ { name: 'placeholder', type: 'string', default: '' }
125
+ ],
126
+ description: 'An input field component',
127
+ impl: (_inputs, props) => ({
128
+ element: {
129
+ type: 'Input',
130
+ key: props.key,
131
+ props: {
132
+ name: props.name,
133
+ type: props.type ?? 'text',
134
+ placeholder: props.placeholder ?? ''
135
+ }
136
+ }
137
+ })
138
+ };
139
+ exports.buttonDef = {
140
+ context: 'ui',
141
+ category: 'form',
142
+ type: 'ui/form/Button',
143
+ icon: 'square',
144
+ inputs: [],
145
+ outputs: [{ name: 'element', type: 'Element' }],
146
+ props: [
147
+ { name: 'key', type: 'string', required: true },
148
+ { name: 'type', type: 'string', default: 'button' },
149
+ { name: 'text', type: 'string', required: true }
150
+ ],
151
+ description: 'A button component',
152
+ impl: (_inputs, props) => ({
153
+ element: {
154
+ type: 'Button',
155
+ key: props.key,
156
+ props: {
157
+ type: props.type ?? 'button',
158
+ text: props.text
159
+ }
160
+ }
161
+ })
162
+ };
163
+ exports.textDef = {
164
+ context: 'ui',
165
+ category: 'content',
166
+ type: 'ui/content/Text',
167
+ icon: 'type',
168
+ inputs: [],
169
+ outputs: [{ name: 'element', type: 'Element' }],
170
+ props: [
171
+ { name: 'key', type: 'string', required: true },
172
+ { name: 'content', type: 'string', required: true }
173
+ ],
174
+ description: 'A text content component',
175
+ impl: (_inputs, props) => ({
176
+ element: {
177
+ type: 'Text',
178
+ key: props.key,
179
+ props: {
180
+ content: props.content
181
+ }
182
+ }
183
+ })
184
+ };
185
+ exports.uiDefinitions = [
186
+ exports.pageDef,
187
+ exports.formDef,
188
+ exports.inputDef,
189
+ exports.buttonDef,
190
+ exports.textDef,
191
+ exports.graphInputDef,
192
+ exports.graphOutputDef,
193
+ exports.graphPropDef
194
+ ];
@@ -0,0 +1,72 @@
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[];
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Core node definitions with implementations.
3
+ * These nodes handle JSON manipulation, flow control, and string operations.
4
+ */
5
+ /**
6
+ * core/json/select - Extract a value from JSON by path
7
+ *
8
+ * Props:
9
+ * - path: string (dot-path like "a.b.c" or "data.user.email")
10
+ *
11
+ * Inputs:
12
+ * - obj: json (the object to extract from)
13
+ *
14
+ * Outputs:
15
+ * - value: any (the extracted value)
16
+ */
17
+ export const jsonSelectDef = {
18
+ context: 'core',
19
+ category: 'json',
20
+ type: 'core/json/select',
21
+ icon: 'circle',
22
+ inputs: [
23
+ { name: 'obj', type: 'json' }
24
+ ],
25
+ outputs: [
26
+ { name: 'value', type: 'any' }
27
+ ],
28
+ props: [
29
+ { name: 'path', type: 'string', default: '' }
30
+ ],
31
+ description: 'Extract a value from JSON by dot-path',
32
+ impl: (inputs, props) => {
33
+ const { obj } = inputs;
34
+ const { path } = props;
35
+ if (!path || obj === undefined || obj === null) {
36
+ return { value: undefined };
37
+ }
38
+ const parts = path.split('.');
39
+ let current = obj;
40
+ for (const part of parts) {
41
+ if (current === undefined || current === null) {
42
+ return { value: undefined };
43
+ }
44
+ // Handle array index access like "items.0.name"
45
+ const index = parseInt(part, 10);
46
+ if (!isNaN(index) && Array.isArray(current)) {
47
+ current = current[index];
48
+ }
49
+ else if (typeof current === 'object') {
50
+ current = current[part];
51
+ }
52
+ else {
53
+ return { value: undefined };
54
+ }
55
+ }
56
+ return { value: current };
57
+ }
58
+ };
59
+ /**
60
+ * core/json/object - Build a JSON object from named inputs
61
+ *
62
+ * This node has dynamic inputs - any input wired to it becomes a key in the output object.
63
+ * The implementation receives all inputs as a Record<string, any>.
64
+ *
65
+ * Inputs:
66
+ * - (dynamic) arbitrary named inputs
67
+ *
68
+ * Outputs:
69
+ * - value: json (the constructed object)
70
+ */
71
+ export const jsonObjectDef = {
72
+ context: 'core',
73
+ category: 'json',
74
+ type: 'core/json/object',
75
+ icon: 'braces',
76
+ inputs: [], // Dynamic inputs - any input name is valid
77
+ outputs: [
78
+ { name: 'value', type: 'json' }
79
+ ],
80
+ props: [],
81
+ description: 'Build a JSON object from named inputs',
82
+ impl: (inputs) => {
83
+ // All inputs become keys in the output object
84
+ return { value: { ...inputs } };
85
+ }
86
+ };
87
+ /**
88
+ * core/flow/guard - Stop the flow if a condition fails
89
+ *
90
+ * Inputs:
91
+ * - ok: boolean (the condition to check)
92
+ * - error?: json (optional error info)
93
+ *
94
+ * Outputs:
95
+ * - pass: signal (emitted if ok is true)
96
+ * - fail: signal (emitted if ok is false)
97
+ * - error: json (the error if failed)
98
+ */
99
+ export const flowGuardDef = {
100
+ context: 'core',
101
+ category: 'flow',
102
+ type: 'core/flow/guard',
103
+ icon: 'zap',
104
+ inputs: [
105
+ { name: 'ok', type: 'boolean' },
106
+ { name: 'error', type: 'json' }
107
+ ],
108
+ outputs: [
109
+ { name: 'pass', type: 'signal' },
110
+ { name: 'fail', type: 'signal' },
111
+ { name: 'error', type: 'json' }
112
+ ],
113
+ props: [],
114
+ description: 'Stop the flow if a condition fails',
115
+ impl: (inputs) => {
116
+ const { ok, error } = inputs;
117
+ if (ok) {
118
+ return {
119
+ pass: true,
120
+ fail: false,
121
+ error: null
122
+ };
123
+ }
124
+ else {
125
+ return {
126
+ pass: false,
127
+ fail: true,
128
+ error: error || { message: 'Guard condition failed' }
129
+ };
130
+ }
131
+ }
132
+ };
133
+ /**
134
+ * core/string/template - Build a string from a template with placeholders
135
+ *
136
+ * Props:
137
+ * - template: string (template with {{placeholder}} syntax)
138
+ *
139
+ * Inputs:
140
+ * - (dynamic) values to substitute into the template
141
+ *
142
+ * Outputs:
143
+ * - value: string (the resulting string)
144
+ */
145
+ export const stringTemplateDef = {
146
+ context: 'core',
147
+ category: 'string',
148
+ type: 'core/string/template',
149
+ icon: 'quote',
150
+ inputs: [], // Dynamic inputs based on template placeholders
151
+ outputs: [
152
+ { name: 'value', type: 'string' }
153
+ ],
154
+ props: [
155
+ { name: 'template', type: 'string', default: '' }
156
+ ],
157
+ description: 'Build a string from a template with {{placeholder}} syntax',
158
+ impl: (inputs, props) => {
159
+ const { template } = props;
160
+ if (!template) {
161
+ return { value: '' };
162
+ }
163
+ // Replace {{placeholder}} with input values
164
+ const result = template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
165
+ const value = inputs[key];
166
+ if (value === undefined || value === null) {
167
+ return match; // Keep placeholder if no value
168
+ }
169
+ return String(value);
170
+ });
171
+ return { value: result };
172
+ }
173
+ };
174
+ /**
175
+ * core/string/concat - Concatenate strings with an optional separator
176
+ *
177
+ * Props:
178
+ * - prefix: string (optional prefix)
179
+ * - suffix: string (optional suffix)
180
+ *
181
+ * Inputs:
182
+ * - value: string (the main value)
183
+ *
184
+ * Outputs:
185
+ * - value: string (the resulting string)
186
+ */
187
+ export const stringConcatDef = {
188
+ context: 'core',
189
+ category: 'string',
190
+ type: 'core/string/concat',
191
+ icon: 'link',
192
+ inputs: [
193
+ { name: 'value', type: 'string' }
194
+ ],
195
+ outputs: [
196
+ { name: 'value', type: 'string' }
197
+ ],
198
+ props: [
199
+ { name: 'prefix', type: 'string', default: '' },
200
+ { name: 'suffix', type: 'string', default: '' }
201
+ ],
202
+ description: 'Concatenate strings with optional prefix/suffix',
203
+ impl: (inputs, props) => {
204
+ const { value = '' } = inputs;
205
+ const { prefix = '', suffix = '' } = props;
206
+ return { value: `${prefix}${value}${suffix}` };
207
+ }
208
+ };
209
+ export const coreDefinitions = [
210
+ jsonSelectDef,
211
+ jsonObjectDef,
212
+ flowGuardDef,
213
+ stringTemplateDef,
214
+ stringConcatDef
215
+ ];
@@ -0,0 +1,8 @@
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[];
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Math node definitions with implementations for testing.
3
+ */
4
+ export const constNumberDef = {
5
+ context: 'js',
6
+ category: 'const',
7
+ type: 'js/const/number',
8
+ icon: 'hash',
9
+ outputs: [{ name: 'value', type: 'number' }],
10
+ props: [{ name: 'value', type: 'number', default: 0 }],
11
+ description: 'Outputs a constant number value',
12
+ impl: (_inputs, props) => ({
13
+ value: props.value ?? 0
14
+ })
15
+ };
16
+ export const addDef = {
17
+ context: 'js',
18
+ category: 'math',
19
+ type: 'js/math/add',
20
+ icon: 'plus',
21
+ inputs: [
22
+ { name: 'a', type: 'number' },
23
+ { name: 'b', type: 'number' }
24
+ ],
25
+ outputs: [{ name: 'sum', type: 'number' }],
26
+ description: 'Adds two numbers',
27
+ impl: (inputs) => ({
28
+ sum: (inputs.a ?? 0) + (inputs.b ?? 0)
29
+ })
30
+ };
31
+ export const multiplyDef = {
32
+ context: 'js',
33
+ category: 'math',
34
+ type: 'js/math/multiply',
35
+ icon: 'x',
36
+ inputs: [
37
+ { name: 'a', type: 'number' },
38
+ { name: 'b', type: 'number' }
39
+ ],
40
+ outputs: [{ name: 'product', type: 'number' }],
41
+ description: 'Multiplies two numbers',
42
+ impl: (inputs) => ({
43
+ product: (inputs.a ?? 0) * (inputs.b ?? 0)
44
+ })
45
+ };
46
+ export const mathDefinitions = [
47
+ constNumberDef,
48
+ addDef,
49
+ multiplyDef
50
+ ];
@@ -0,0 +1,25 @@
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[];
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Network node definitions with implementations.
3
+ * These nodes handle GraphQL requests and related operations.
4
+ */
5
+ /**
6
+ * net/graphql/request - Execute GraphQL query or mutation
7
+ *
8
+ * Props:
9
+ * - document: string (GraphQL query/mutation document)
10
+ * - operationName?: string (optional operation name)
11
+ * - endpoint: string (GraphQL endpoint URL)
12
+ * - timeout?: number (request timeout in ms, default 30000)
13
+ *
14
+ * Inputs:
15
+ * - variables: json (GraphQL variables)
16
+ * - headers?: json (additional headers)
17
+ *
18
+ * Outputs:
19
+ * - data: json (response data)
20
+ * - error?: json (error if any)
21
+ * - ok: boolean (true if request succeeded without errors)
22
+ */
23
+ export const graphqlRequestDef = {
24
+ context: 'net',
25
+ category: 'graphql',
26
+ type: 'net/graphql/request',
27
+ icon: 'graphql',
28
+ inputs: [
29
+ { name: 'variables', type: 'json' },
30
+ { name: 'headers', type: 'json' }
31
+ ],
32
+ outputs: [
33
+ { name: 'data', type: 'json' },
34
+ { name: 'error', type: 'json' },
35
+ { name: 'ok', type: 'boolean' }
36
+ ],
37
+ props: [
38
+ { name: 'document', type: 'string', default: '' },
39
+ { name: 'operationName', type: 'string' },
40
+ { name: 'endpoint', type: 'string', default: '' },
41
+ { name: 'timeout', type: 'number', default: 30000 }
42
+ ],
43
+ description: 'Execute a GraphQL query or mutation',
44
+ impl: async (inputs, props) => {
45
+ const { variables = {}, headers = {} } = inputs;
46
+ const { document, operationName, endpoint, timeout = 30000 } = props;
47
+ if (!endpoint) {
48
+ return {
49
+ data: null,
50
+ error: { message: 'No endpoint specified' },
51
+ ok: false
52
+ };
53
+ }
54
+ if (!document) {
55
+ return {
56
+ data: null,
57
+ error: { message: 'No document specified' },
58
+ ok: false
59
+ };
60
+ }
61
+ const controller = new AbortController();
62
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
63
+ try {
64
+ const response = await fetch(endpoint, {
65
+ method: 'POST',
66
+ headers: {
67
+ 'Content-Type': 'application/json',
68
+ Accept: 'application/json',
69
+ ...headers
70
+ },
71
+ body: JSON.stringify({
72
+ query: document,
73
+ variables,
74
+ operationName: operationName || undefined
75
+ }),
76
+ signal: controller.signal
77
+ });
78
+ clearTimeout(timeoutId);
79
+ if (!response.ok) {
80
+ return {
81
+ data: null,
82
+ error: {
83
+ message: `HTTP error: ${response.status} ${response.statusText}`,
84
+ statusCode: response.status
85
+ },
86
+ ok: false
87
+ };
88
+ }
89
+ const json = await response.json();
90
+ if (json.errors && json.errors.length > 0) {
91
+ return {
92
+ data: json.data || null,
93
+ error: json.errors,
94
+ ok: false
95
+ };
96
+ }
97
+ return {
98
+ data: json.data || null,
99
+ error: null,
100
+ ok: true
101
+ };
102
+ }
103
+ catch (error) {
104
+ clearTimeout(timeoutId);
105
+ if (error instanceof Error) {
106
+ if (error.name === 'AbortError') {
107
+ return {
108
+ data: null,
109
+ error: { message: `Request timed out after ${timeout}ms` },
110
+ ok: false
111
+ };
112
+ }
113
+ return {
114
+ data: null,
115
+ error: { message: error.message },
116
+ ok: false
117
+ };
118
+ }
119
+ return {
120
+ data: null,
121
+ error: { message: String(error) },
122
+ ok: false
123
+ };
124
+ }
125
+ }
126
+ };
127
+ export const netDefinitions = [
128
+ graphqlRequestDef
129
+ ];