@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/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: 'ui',
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: 'ui',
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: 'ui',
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: 'ui',
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: 'ui',
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' }],
@@ -3,7 +3,7 @@
3
3
  * These nodes handle JSON manipulation, flow control, and string operations.
4
4
  */
5
5
  /**
6
- * core/json/select - Extract a value from JSON by path
6
+ * core/json:select - Extract a value from JSON by path
7
7
  *
8
8
  * Props:
9
9
  * - path: string (dot-path like "a.b.c" or "data.user.email")
@@ -15,9 +15,9 @@
15
15
  * - value: any (the extracted value)
16
16
  */
17
17
  export const jsonSelectDef = {
18
- context: 'core',
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' }
@@ -57,7 +57,7 @@ export const jsonSelectDef = {
57
57
  }
58
58
  };
59
59
  /**
60
- * core/json/object - Build a JSON object from named inputs
60
+ * core/json:object - Build a JSON object from named inputs
61
61
  *
62
62
  * This node has dynamic inputs - any input wired to it becomes a key in the output object.
63
63
  * The implementation receives all inputs as a Record<string, any>.
@@ -69,9 +69,9 @@ export const jsonSelectDef = {
69
69
  * - value: json (the constructed object)
70
70
  */
71
71
  export const jsonObjectDef = {
72
- context: 'core',
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: [
@@ -85,21 +85,23 @@ export const jsonObjectDef = {
85
85
  }
86
86
  };
87
87
  /**
88
- * core/flow/guard - Stop the flow if a condition fails
88
+ * core/flow:guard - Stop the flow if a condition fails
89
89
  *
90
90
  * Inputs:
91
91
  * - ok: boolean (the condition to check)
92
92
  * - error?: json (optional error info)
93
93
  *
94
- * Outputs:
94
+ * Outputs (only the arm that was taken is emitted — a declared port absent
95
+ * from a completed output is a path not taken, and emitting both arms is what
96
+ * makes both arms run):
95
97
  * - pass: signal (emitted if ok is true)
96
98
  * - fail: signal (emitted if ok is false)
97
99
  * - error: json (the error if failed)
98
100
  */
99
101
  export const flowGuardDef = {
100
- context: 'core',
102
+ context: 'js',
103
+ name: 'guard',
101
104
  category: 'flow',
102
- type: 'core/flow/guard',
103
105
  icon: 'zap',
104
106
  inputs: [
105
107
  { name: 'ok', type: 'boolean' },
@@ -115,23 +117,316 @@ export const flowGuardDef = {
115
117
  impl: (inputs) => {
116
118
  const { ok, error } = inputs;
117
119
  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
- };
120
+ return { pass: true };
130
121
  }
122
+ return {
123
+ fail: true,
124
+ error: error || { message: 'Guard condition failed' }
125
+ };
131
126
  }
132
127
  };
128
+ const COMPARISONS = ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'truthy', 'empty', 'contains'];
133
129
  /**
134
- * core/string/template - Build a string from a template with placeholders
130
+ * The predicate flow:branch and flow:switch share: an operator plus an expected
131
+ * value, never an expression to evaluate — a graph definition is data, and data
132
+ * that gets executed is a remote-code-execution surface.
133
+ *
134
+ * Kept in step with the worker-side implementation in `@fbp/flow`, which is the
135
+ * same predicate for the same node types: the editor's local preview and a
136
+ * server run must agree on which arm a graph takes.
137
+ */
138
+ const compare = (value, operator, expected) => {
139
+ switch (operator) {
140
+ case 'eq': return value === expected;
141
+ case 'neq': return value !== expected;
142
+ case 'gt': return Number(value) > Number(expected);
143
+ case 'gte': return Number(value) >= Number(expected);
144
+ case 'lt': return Number(value) < Number(expected);
145
+ case 'lte': return Number(value) <= Number(expected);
146
+ case 'truthy': return Boolean(value);
147
+ case 'empty':
148
+ if (value === null || value === undefined)
149
+ return true;
150
+ if (Array.isArray(value) || typeof value === 'string')
151
+ return value.length === 0;
152
+ if (typeof value === 'object')
153
+ return Object.keys(value).length === 0;
154
+ return false;
155
+ case 'contains':
156
+ if (Array.isArray(value))
157
+ return value.includes(expected);
158
+ return String(value ?? '').includes(String(expected ?? ''));
159
+ }
160
+ };
161
+ /**
162
+ * core/flow:branch - Route a value down one of two paths
163
+ *
164
+ * Only the taken port carries a value; the other is absent rather than null, so
165
+ * a downstream node can tell "not taken" from "taken with a null value".
166
+ * `matched` always carries the verdict, for anything that wants the decision
167
+ * without sitting on an arm.
168
+ */
169
+ export const flowBranchDef = {
170
+ context: 'js',
171
+ name: 'branch',
172
+ category: 'flow',
173
+ icon: 'git-branch',
174
+ inputs: [
175
+ { name: 'value', type: 'any' },
176
+ // Wired only when the comparison value comes from the graph rather than the prop.
177
+ { name: 'expected', type: 'any', optional: true }
178
+ ],
179
+ outputs: [
180
+ { name: 'matched', type: 'boolean' },
181
+ { name: 'true', type: 'any' },
182
+ { name: 'false', type: 'any' }
183
+ ],
184
+ props: [
185
+ { name: 'operator', type: 'string', default: 'truthy' },
186
+ { name: 'expected', type: 'any' }
187
+ ],
188
+ description: 'Route a value down one of two paths by a declared predicate',
189
+ impl: (inputs, props) => {
190
+ const operator = String(props.operator ?? 'truthy');
191
+ if (!COMPARISONS.includes(operator)) {
192
+ throw new Error(`flow:branch: unknown operator "${operator}" (expected one of ${COMPARISONS.join(', ')})`);
193
+ }
194
+ const expected = 'expected' in inputs ? inputs.expected : props.expected;
195
+ const matched = compare(inputs.value, operator, expected);
196
+ return matched
197
+ ? { matched, true: inputs.value }
198
+ : { matched, false: inputs.value };
199
+ }
200
+ };
201
+ /** The number of case ports flow:switch declares. */
202
+ const SWITCH_CASE_PORTS = 6;
203
+ /**
204
+ * core/flow:switch - Route a value to the first matching case, or to `default`
205
+ *
206
+ * Cases are ordered and the first match wins. Case `i` emits on `case_<i>`;
207
+ * the ports are declared up front and fixed in number, because a port a graph
208
+ * cannot name at design time is a port nothing can be wired to.
209
+ */
210
+ export const flowSwitchDef = {
211
+ context: 'js',
212
+ name: 'switch',
213
+ category: 'flow',
214
+ icon: 'git-fork',
215
+ inputs: [
216
+ { name: 'value', type: 'any' }
217
+ ],
218
+ outputs: [
219
+ { name: 'matched_case', type: 'string' },
220
+ ...Array.from({ length: SWITCH_CASE_PORTS }, (_, i) => ({ name: `case_${i}`, type: 'any' })),
221
+ { name: 'default', type: 'any' }
222
+ ],
223
+ props: [
224
+ { name: 'cases', type: 'json', default: [] },
225
+ { name: 'operator', type: 'string', default: 'eq' }
226
+ ],
227
+ description: 'Route a value to the first matching case, or to default',
228
+ impl: (inputs, props) => {
229
+ const rawCases = props.cases ?? [];
230
+ if (!Array.isArray(rawCases)) {
231
+ throw new Error('flow:switch: props.cases must be an array of { operator, expected }');
232
+ }
233
+ if (rawCases.length > SWITCH_CASE_PORTS) {
234
+ throw new Error(`flow:switch: ${rawCases.length} cases exceeds the ${SWITCH_CASE_PORTS} declared case ports`);
235
+ }
236
+ const fallbackOperator = String(props.operator ?? 'eq');
237
+ for (let i = 0; i < rawCases.length; i++) {
238
+ const branchCase = rawCases[i];
239
+ if (branchCase === null || typeof branchCase !== 'object') {
240
+ throw new Error(`flow:switch: case ${i} must be an object of { operator, expected }`);
241
+ }
242
+ const operator = String(branchCase.operator ?? fallbackOperator);
243
+ if (!COMPARISONS.includes(operator)) {
244
+ throw new Error(`flow:switch: case ${i} has unknown operator "${operator}" (expected one of ${COMPARISONS.join(', ')})`);
245
+ }
246
+ if (compare(inputs.value, operator, branchCase.expected)) {
247
+ return { matched_case: String(i), [`case_${i}`]: inputs.value };
248
+ }
249
+ }
250
+ return { matched_case: 'default', default: inputs.value };
251
+ }
252
+ };
253
+ /**
254
+ * core/flow:merge - Rejoin two branch arms into one path
255
+ *
256
+ * The counterpart of a lazy branch: whichever arm produced a value wins, and
257
+ * `source` names it so a graph can tell which path it is now carrying. `a` wins
258
+ * a tie, which only happens when the inputs are not exclusive arms at all.
259
+ */
260
+ export const flowMergeDef = {
261
+ context: 'js',
262
+ name: 'merge',
263
+ category: 'flow',
264
+ icon: 'git-merge',
265
+ inputs: [
266
+ // Optional on purpose: a merge runs on whichever arm arrived, and a branch
267
+ // arm that was not taken never produces one.
268
+ { name: 'a', type: 'any', optional: true },
269
+ { name: 'b', type: 'any', optional: true }
270
+ ],
271
+ outputs: [
272
+ { name: 'value', type: 'any' },
273
+ { name: 'source', type: 'string' }
274
+ ],
275
+ props: [],
276
+ description: 'Rejoin two branch arms into one path',
277
+ impl: (inputs) => {
278
+ if (inputs.a !== undefined) {
279
+ return { value: inputs.a, source: 'a' };
280
+ }
281
+ if (inputs.b !== undefined) {
282
+ return { value: inputs.b, source: 'b' };
283
+ }
284
+ throw new Error('flow:merge: neither input arrived — nothing to merge');
285
+ }
286
+ };
287
+ /** Read a dot-path out of one collection element, for the nodes that key on a field. */
288
+ const selectPath = (item, path) => {
289
+ if (path === '')
290
+ return item;
291
+ return path.split('.').reduce((acc, segment) => {
292
+ if (acc === null || typeof acc !== 'object')
293
+ return undefined;
294
+ return acc[segment];
295
+ }, item);
296
+ };
297
+ const requireArray = (node, items) => {
298
+ if (!Array.isArray(items)) {
299
+ throw new Error(`${node}: items must be an array (received ${items === null ? 'null' : typeof items})`);
300
+ }
301
+ return items;
302
+ };
303
+ /**
304
+ * core/flow:filter - Narrow a collection by a declared predicate
305
+ *
306
+ * Same predicate vocabulary as flow:branch, applied per element — `path`
307
+ * compares a field of each element so a list of rows can be filtered without a
308
+ * per-item node. `items`, `dropped` and `empty` are lazy ports: a survivor lane
309
+ * only runs when something survived and a rejects lane only when something was
310
+ * rejected, so the "nothing to do" case is a path rather than a length test.
311
+ */
312
+ export const flowFilterDef = {
313
+ context: 'js',
314
+ name: 'filter',
315
+ category: 'flow',
316
+ icon: 'filter',
317
+ inputs: [
318
+ { name: 'items', type: 'json' },
319
+ // Wired only when the comparison value comes from the graph rather than the prop.
320
+ { name: 'expected', type: 'any', optional: true }
321
+ ],
322
+ outputs: [
323
+ { name: 'items', type: 'json' },
324
+ { name: 'dropped', type: 'json' },
325
+ { name: 'empty', type: 'boolean' },
326
+ { name: 'kept_count', type: 'number' },
327
+ { name: 'dropped_count', type: 'number' }
328
+ ],
329
+ props: [
330
+ { name: 'operator', type: 'string', default: 'truthy' },
331
+ { name: 'expected', type: 'any' },
332
+ { name: 'path', type: 'string', default: '' }
333
+ ],
334
+ description: 'Narrow a collection by a declared predicate',
335
+ impl: (inputs, props) => {
336
+ const operator = String(props.operator ?? 'truthy');
337
+ if (!COMPARISONS.includes(operator)) {
338
+ throw new Error(`flow:filter: unknown operator "${operator}" (expected one of ${COMPARISONS.join(', ')})`);
339
+ }
340
+ const items = requireArray('flow:filter', inputs.items);
341
+ const path = String(props.path ?? '');
342
+ const expected = 'expected' in inputs ? inputs.expected : props.expected;
343
+ const kept = [];
344
+ const dropped = [];
345
+ for (const item of items) {
346
+ if (compare(selectPath(item, path), operator, expected)) {
347
+ kept.push(item);
348
+ }
349
+ else {
350
+ dropped.push(item);
351
+ }
352
+ }
353
+ const outputs = {
354
+ kept_count: kept.length,
355
+ dropped_count: dropped.length
356
+ };
357
+ if (kept.length > 0)
358
+ outputs.items = kept;
359
+ else
360
+ outputs.empty = true;
361
+ if (dropped.length > 0)
362
+ outputs.dropped = dropped;
363
+ return outputs;
364
+ }
365
+ };
366
+ /** The ceiling flow:for_each refuses to plan beyond unless a graph raises it. */
367
+ const DEFAULT_MAX_SHARDS = 64;
368
+ /**
369
+ * core/flow:for_each - Turn a collection into an ordered, keyed fan-out plan
370
+ *
371
+ * Each element becomes a shard descriptor `{ index, total, item, key }`. The key
372
+ * is a declared field of the element (falling back to its index) because a
373
+ * shard's identity is what lets a retry land on the same shard; duplicate or
374
+ * missing keys fail the node rather than producing an unaddressable plan, and so
375
+ * does a collection larger than `max_shards` — a truncated plan is work that
376
+ * never ran with nothing saying so. `shards` is absent for an empty collection,
377
+ * where `empty` is present instead, so a graph never fans out over nothing.
378
+ */
379
+ export const flowForEachDef = {
380
+ context: 'js',
381
+ name: 'for_each',
382
+ category: 'flow',
383
+ icon: 'list-ordered',
384
+ inputs: [
385
+ { name: 'items', type: 'json' }
386
+ ],
387
+ outputs: [
388
+ { name: 'shards', type: 'json' },
389
+ { name: 'empty', type: 'boolean' },
390
+ { name: 'total', type: 'number' }
391
+ ],
392
+ props: [
393
+ { name: 'key', type: 'string', default: '' },
394
+ { name: 'max_shards', type: 'number', default: DEFAULT_MAX_SHARDS }
395
+ ],
396
+ description: 'Turn a collection into an ordered, keyed fan-out plan',
397
+ impl: (inputs, props) => {
398
+ const items = requireArray('flow:for_each', inputs.items);
399
+ const maxShards = Number(props.max_shards ?? DEFAULT_MAX_SHARDS);
400
+ if (!Number.isFinite(maxShards) || maxShards < 1) {
401
+ throw new Error(`flow:for_each: max_shards must be a positive number (received ${String(props.max_shards)})`);
402
+ }
403
+ if (items.length > maxShards) {
404
+ throw new Error(`flow:for_each: ${items.length} items exceeds max_shards ${maxShards} — raise the ceiling or filter the collection first`);
405
+ }
406
+ const keyPath = String(props.key ?? '');
407
+ const total = items.length;
408
+ const shards = items.map((item, index) => {
409
+ if (keyPath === '') {
410
+ return { index, total, item, key: String(index) };
411
+ }
412
+ const keyValue = selectPath(item, keyPath);
413
+ if (keyValue === null || keyValue === undefined || keyValue === '') {
414
+ throw new Error(`flow:for_each: item ${index} has no value at key path "${keyPath}" — a shard without a stable key cannot be retried`);
415
+ }
416
+ return { index, total, item, key: String(keyValue) };
417
+ });
418
+ const keys = shards.map((shard) => shard.key);
419
+ const duplicate = keys.find((key, index) => keys.indexOf(key) !== index);
420
+ if (duplicate !== undefined) {
421
+ throw new Error(`flow:for_each: key "${duplicate}" appears more than once at key path "${keyPath}" — shard keys must be unique`);
422
+ }
423
+ return total === 0
424
+ ? { total, empty: true }
425
+ : { total, shards };
426
+ }
427
+ };
428
+ /**
429
+ * core/string:template - Build a string from a template with placeholders
135
430
  *
136
431
  * Props:
137
432
  * - template: string (template with {{placeholder}} syntax)
@@ -143,9 +438,9 @@ export const flowGuardDef = {
143
438
  * - value: string (the resulting string)
144
439
  */
145
440
  export const stringTemplateDef = {
146
- context: 'core',
441
+ context: 'js',
442
+ name: 'template',
147
443
  category: 'string',
148
- type: 'core/string/template',
149
444
  icon: 'quote',
150
445
  inputs: [], // Dynamic inputs based on template placeholders
151
446
  outputs: [
@@ -172,7 +467,7 @@ export const stringTemplateDef = {
172
467
  }
173
468
  };
174
469
  /**
175
- * core/string/concat - Concatenate strings with an optional separator
470
+ * core/string:concat - Concatenate strings with an optional separator
176
471
  *
177
472
  * Props:
178
473
  * - prefix: string (optional prefix)
@@ -185,9 +480,9 @@ export const stringTemplateDef = {
185
480
  * - value: string (the resulting string)
186
481
  */
187
482
  export const stringConcatDef = {
188
- context: 'core',
483
+ context: 'js',
484
+ name: 'concat',
189
485
  category: 'string',
190
- type: 'core/string/concat',
191
486
  icon: 'link',
192
487
  inputs: [
193
488
  { name: 'value', type: 'string' }
@@ -206,10 +501,118 @@ export const stringConcatDef = {
206
501
  return { value: `${prefix}${value}${suffix}` };
207
502
  }
208
503
  };
504
+ export const constStringDef = {
505
+ context: 'js',
506
+ name: 'string',
507
+ category: 'const',
508
+ icon: 'type',
509
+ outputs: [{ name: 'value', type: 'string' }],
510
+ props: [{ name: 'value', type: 'string', default: '' }],
511
+ description: 'Outputs a constant string value',
512
+ impl: (_inputs, props) => ({
513
+ value: props.value ?? ''
514
+ })
515
+ };
516
+ export const constBooleanDef = {
517
+ context: 'js',
518
+ name: 'boolean',
519
+ category: 'const',
520
+ icon: 'toggle',
521
+ outputs: [{ name: 'value', type: 'boolean' }],
522
+ props: [{ name: 'value', type: 'boolean', default: false }],
523
+ description: 'Outputs a constant boolean value',
524
+ impl: (_inputs, props) => ({
525
+ value: props.value ?? false
526
+ })
527
+ };
528
+ export const jsonMergeDef = {
529
+ context: 'js',
530
+ name: 'merge',
531
+ category: 'json',
532
+ icon: 'git-merge',
533
+ inputs: [
534
+ { name: 'a', type: 'json' },
535
+ { name: 'b', type: 'json' }
536
+ ],
537
+ outputs: [
538
+ { name: 'value', type: 'json' }
539
+ ],
540
+ description: 'Merge two JSON objects',
541
+ impl: (inputs) => ({
542
+ value: { ...(inputs.a || {}), ...(inputs.b || {}) }
543
+ })
544
+ };
545
+ export const jsonSplitDef = {
546
+ context: 'js',
547
+ name: 'split',
548
+ category: 'json',
549
+ icon: 'scissors',
550
+ inputs: [
551
+ { name: 'obj', type: 'json' }
552
+ ],
553
+ outputs: [
554
+ { name: 'selected', type: 'json' },
555
+ { name: 'rest', type: 'json' }
556
+ ],
557
+ props: [
558
+ { name: 'keys', type: 'string', default: '' }
559
+ ],
560
+ description: 'Split a JSON object by key list',
561
+ impl: (inputs, props) => {
562
+ const obj = inputs.obj || {};
563
+ const keyList = (props.keys || '').split(',').map((k) => k.trim()).filter(Boolean);
564
+ const keySet = new Set(keyList);
565
+ const selected = {};
566
+ const rest = {};
567
+ for (const [k, v] of Object.entries(obj)) {
568
+ if (keySet.has(k))
569
+ selected[k] = v;
570
+ else
571
+ rest[k] = v;
572
+ }
573
+ return { selected, rest };
574
+ }
575
+ };
576
+ export const flowCoerceDef = {
577
+ context: 'js',
578
+ name: 'coerce',
579
+ category: 'flow',
580
+ icon: 'repeat',
581
+ inputs: [
582
+ { name: 'value', type: 'any' }
583
+ ],
584
+ outputs: [
585
+ { name: 'value', type: 'any' }
586
+ ],
587
+ props: [
588
+ { name: 'type', type: 'string', default: 'string' }
589
+ ],
590
+ description: 'Convert a value to a different type',
591
+ impl: (inputs, props) => {
592
+ const { value } = inputs;
593
+ switch (props.type) {
594
+ case 'number': return { value: Number(value) || 0 };
595
+ case 'string': return { value: String(value ?? '') };
596
+ case 'boolean': return { value: Boolean(value) };
597
+ case 'json': return { value: typeof value === 'string' ? JSON.parse(value) : value };
598
+ default: return { value };
599
+ }
600
+ }
601
+ };
209
602
  export const coreDefinitions = [
603
+ constStringDef,
604
+ constBooleanDef,
210
605
  jsonSelectDef,
211
606
  jsonObjectDef,
607
+ jsonMergeDef,
608
+ jsonSplitDef,
212
609
  flowGuardDef,
610
+ flowBranchDef,
611
+ flowSwitchDef,
612
+ flowMergeDef,
613
+ flowFilterDef,
614
+ flowForEachDef,
615
+ flowCoerceDef,
213
616
  stringTemplateDef,
214
617
  stringConcatDef
215
618
  ];
@@ -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' },
@@ -43,8 +43,24 @@ export const multiplyDef = {
43
43
  product: (inputs.a ?? 0) * (inputs.b ?? 0)
44
44
  })
45
45
  };
46
+ export const subtractDef = {
47
+ context: 'js',
48
+ name: 'subtract',
49
+ category: 'math',
50
+ icon: 'minus',
51
+ inputs: [
52
+ { name: 'a', type: 'number' },
53
+ { name: 'b', type: 'number' }
54
+ ],
55
+ outputs: [{ name: 'difference', type: 'number' }],
56
+ description: 'Subtracts b from a',
57
+ impl: (inputs) => ({
58
+ difference: (inputs.a ?? 0) - (inputs.b ?? 0)
59
+ })
60
+ };
46
61
  export const mathDefinitions = [
47
62
  constNumberDef,
48
63
  addDef,
49
- multiplyDef
64
+ multiplyDef,
65
+ subtractDef
50
66
  ];