@fbp/evaluator 1.1.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 CHANGED
@@ -1,85 +1,5 @@
1
- # @fbp/evaluator
1
+ # @constructive-db/fbp-evaluator
2
2
 
3
- Lazy graph evaluator for Flow-Based Programming.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pnpm add @fbp/evaluator
9
- ```
10
-
11
- ## Usage
12
-
13
- ```typescript
14
- import { evaluate } from '@fbp/evaluator';
15
- import type { Graph } from '@fbp/types';
16
- import type { NodeDefinitionWithImpl } from '@fbp/evaluator';
17
-
18
- // Define node implementations
19
- const addDef: NodeDefinitionWithImpl = {
20
- context: 'js',
21
- category: 'math',
22
- type: 'js/math/add',
23
- inputs: [
24
- { name: 'a', type: 'number' },
25
- { name: 'b', type: 'number' }
26
- ],
27
- outputs: [{ name: 'sum', type: 'number' }],
28
- impl: (inputs) => ({
29
- sum: (inputs.a ?? 0) + (inputs.b ?? 0)
30
- })
31
- };
32
-
33
- // Create a graph
34
- const graph: Graph = {
35
- name: 'simple-add',
36
- nodes: [
37
- { name: 'num1', type: 'js/const/number', props: [{ name: 'value', type: 'number', value: 5 }] },
38
- { name: 'num2', type: 'js/const/number', props: [{ name: 'value', type: 'number', value: 3 }] },
39
- { name: 'add', type: 'js/math/add' }
40
- ],
41
- edges: [
42
- { src: { node: 'num1', port: 'value' }, dst: { node: 'add', port: 'a' } },
43
- { src: { node: 'num2', port: 'value' }, dst: { node: 'add', port: 'b' } }
44
- ]
45
- };
46
-
47
- // Evaluate the graph
48
- const result = evaluate(graph, {
49
- definitions: [constNumberDef, addDef],
50
- outputNode: 'add',
51
- outputPort: 'sum'
52
- });
53
-
54
- console.log(result); // 8
55
- ```
56
-
57
- ## Features
58
-
59
- - **Lazy evaluation**: Only evaluates nodes that are needed for the output
60
- - **Multi-input ports**: Supports ports that accept multiple incoming edges (values collected in edge array order)
61
- - **Boundary nodes**: Supports `graphInput`, `graphOutput`, and `graphProp` boundary nodes for graph inputs/outputs/props
62
-
63
- ## Boundary Node Design
64
-
65
- Boundary nodes use a **property-based approach**:
66
- - Node keys are normal identifiers (e.g., `input_a`, `output_result`, `prop_scale`)
67
- - The node's `type` property identifies it as a boundary node: `graphInput`, `graphOutput`, `graphProp`
68
- - The port/prop name is stored as a property: `{ name: 'portName', value: 'a' }` or `{ name: 'propName', value: 'scale' }`
69
-
70
- ## API
71
-
72
- ### `evaluate(graph, options)`
73
-
74
- Evaluates a graph starting from the specified output node/port.
75
-
76
- **Parameters:**
77
- - `graph: Graph` - The graph to evaluate
78
- - `options: EvaluateOptions` - Evaluation options
79
- - `definitions: NodeDefinitionWithImpl[]` - Node definitions with implementations
80
- - `outputNode: string` - The node to get output from
81
- - `outputPort: string` - The port to get output from
82
- - `inputs?: Record<string, any>` - External inputs for `graphInput` nodes (keyed by portName)
83
- - `props?: Record<string, any>` - Props for `graphProp` nodes (keyed by propName)
84
-
85
- **Returns:** The value at the specified output port
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
@@ -4,7 +4,7 @@ import type { NodeDefinitionWithImpl } from '../types';
4
4
  * These nodes handle JSON manipulation, flow control, and string operations.
5
5
  */
6
6
  /**
7
- * core/json/select - Extract a value from JSON by path
7
+ * core/json:select - Extract a value from JSON by path
8
8
  *
9
9
  * Props:
10
10
  * - path: string (dot-path like "a.b.c" or "data.user.email")
@@ -17,7 +17,7 @@ import type { NodeDefinitionWithImpl } from '../types';
17
17
  */
18
18
  export declare const jsonSelectDef: NodeDefinitionWithImpl;
19
19
  /**
20
- * core/json/object - Build a JSON object from named inputs
20
+ * core/json:object - Build a JSON object from named inputs
21
21
  *
22
22
  * This node has dynamic inputs - any input wired to it becomes a key in the output object.
23
23
  * The implementation receives all inputs as a Record<string, any>.
@@ -30,20 +30,69 @@ export declare const jsonSelectDef: NodeDefinitionWithImpl;
30
30
  */
31
31
  export declare const jsonObjectDef: NodeDefinitionWithImpl;
32
32
  /**
33
- * core/flow/guard - Stop the flow if a condition fails
33
+ * core/flow:guard - Stop the flow if a condition fails
34
34
  *
35
35
  * Inputs:
36
36
  * - ok: boolean (the condition to check)
37
37
  * - error?: json (optional error info)
38
38
  *
39
- * Outputs:
39
+ * Outputs (only the arm that was taken is emitted — a declared port absent
40
+ * from a completed output is a path not taken, and emitting both arms is what
41
+ * makes both arms run):
40
42
  * - pass: signal (emitted if ok is true)
41
43
  * - fail: signal (emitted if ok is false)
42
44
  * - error: json (the error if failed)
43
45
  */
44
46
  export declare const flowGuardDef: NodeDefinitionWithImpl;
45
47
  /**
46
- * core/string/template - Build a string from a template with placeholders
48
+ * core/flow:branch - Route a value down one of two paths
49
+ *
50
+ * Only the taken port carries a value; the other is absent rather than null, so
51
+ * a downstream node can tell "not taken" from "taken with a null value".
52
+ * `matched` always carries the verdict, for anything that wants the decision
53
+ * without sitting on an arm.
54
+ */
55
+ export declare const flowBranchDef: NodeDefinitionWithImpl;
56
+ /**
57
+ * core/flow:switch - Route a value to the first matching case, or to `default`
58
+ *
59
+ * Cases are ordered and the first match wins. Case `i` emits on `case_<i>`;
60
+ * the ports are declared up front and fixed in number, because a port a graph
61
+ * cannot name at design time is a port nothing can be wired to.
62
+ */
63
+ export declare const flowSwitchDef: NodeDefinitionWithImpl;
64
+ /**
65
+ * core/flow:merge - Rejoin two branch arms into one path
66
+ *
67
+ * The counterpart of a lazy branch: whichever arm produced a value wins, and
68
+ * `source` names it so a graph can tell which path it is now carrying. `a` wins
69
+ * a tie, which only happens when the inputs are not exclusive arms at all.
70
+ */
71
+ export declare const flowMergeDef: NodeDefinitionWithImpl;
72
+ /**
73
+ * core/flow:filter - Narrow a collection by a declared predicate
74
+ *
75
+ * Same predicate vocabulary as flow:branch, applied per element — `path`
76
+ * compares a field of each element so a list of rows can be filtered without a
77
+ * per-item node. `items`, `dropped` and `empty` are lazy ports: a survivor lane
78
+ * only runs when something survived and a rejects lane only when something was
79
+ * rejected, so the "nothing to do" case is a path rather than a length test.
80
+ */
81
+ export declare const flowFilterDef: NodeDefinitionWithImpl;
82
+ /**
83
+ * core/flow:for_each - Turn a collection into an ordered, keyed fan-out plan
84
+ *
85
+ * Each element becomes a shard descriptor `{ index, total, item, key }`. The key
86
+ * is a declared field of the element (falling back to its index) because a
87
+ * shard's identity is what lets a retry land on the same shard; duplicate or
88
+ * missing keys fail the node rather than producing an unaddressable plan, and so
89
+ * does a collection larger than `max_shards` — a truncated plan is work that
90
+ * never ran with nothing saying so. `shards` is absent for an empty collection,
91
+ * where `empty` is present instead, so a graph never fans out over nothing.
92
+ */
93
+ export declare const flowForEachDef: NodeDefinitionWithImpl;
94
+ /**
95
+ * core/string:template - Build a string from a template with placeholders
47
96
  *
48
97
  * Props:
49
98
  * - template: string (template with {{placeholder}} syntax)
@@ -56,7 +105,7 @@ export declare const flowGuardDef: NodeDefinitionWithImpl;
56
105
  */
57
106
  export declare const stringTemplateDef: NodeDefinitionWithImpl;
58
107
  /**
59
- * core/string/concat - Concatenate strings with an optional separator
108
+ * core/string:concat - Concatenate strings with an optional separator
60
109
  *
61
110
  * Props:
62
111
  * - prefix: string (optional prefix)
@@ -69,4 +118,9 @@ export declare const stringTemplateDef: NodeDefinitionWithImpl;
69
118
  * - value: string (the resulting string)
70
119
  */
71
120
  export declare const stringConcatDef: NodeDefinitionWithImpl;
121
+ export declare const constStringDef: NodeDefinitionWithImpl;
122
+ export declare const constBooleanDef: NodeDefinitionWithImpl;
123
+ export declare const jsonMergeDef: NodeDefinitionWithImpl;
124
+ export declare const jsonSplitDef: NodeDefinitionWithImpl;
125
+ export declare const flowCoerceDef: NodeDefinitionWithImpl;
72
126
  export declare const coreDefinitions: NodeDefinitionWithImpl[];