@sebasoft/neuron-js 0.3.0 → 0.5.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 +84 -45
- package/dist/commonjs/Synapse.d.ts +18 -0
- package/dist/commonjs/Synapse.d.ts.map +1 -1
- package/dist/commonjs/Synapse.js +18 -0
- package/dist/commonjs/Synapse.js.map +1 -1
- package/dist/commonjs/abstracts/AbstractAction.d.ts +15 -0
- package/dist/commonjs/abstracts/AbstractAction.d.ts.map +1 -0
- package/dist/commonjs/abstracts/AbstractAction.js +25 -0
- package/dist/commonjs/abstracts/AbstractAction.js.map +1 -0
- package/dist/commonjs/abstracts/AbstractCondition.d.ts +15 -0
- package/dist/commonjs/abstracts/AbstractCondition.d.ts.map +1 -0
- package/dist/commonjs/abstracts/AbstractCondition.js +25 -0
- package/dist/commonjs/abstracts/AbstractCondition.js.map +1 -0
- package/dist/commonjs/contracts/explain.d.ts +9 -0
- package/dist/commonjs/contracts/explain.d.ts.map +1 -0
- package/dist/commonjs/contracts/explain.js +51 -0
- package/dist/commonjs/contracts/explain.js.map +1 -0
- package/dist/commonjs/contracts/validation.d.ts +40 -0
- package/dist/commonjs/contracts/validation.d.ts.map +1 -0
- package/dist/commonjs/contracts/validation.js +263 -0
- package/dist/commonjs/contracts/validation.js.map +1 -0
- package/dist/commonjs/index.d.ts +64 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +74 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/interfaces/Action.d.ts +14 -0
- package/dist/commonjs/interfaces/Action.d.ts.map +1 -1
- package/dist/commonjs/interfaces/Condition.d.ts +21 -0
- package/dist/commonjs/interfaces/Condition.d.ts.map +1 -1
- package/dist/commonjs/interfaces/Element.d.ts +16 -0
- package/dist/commonjs/interfaces/Element.d.ts.map +1 -1
- package/dist/commonjs/interfaces/HookEvents.d.ts +16 -0
- package/dist/commonjs/interfaces/HookEvents.d.ts.map +1 -1
- package/dist/commonjs/interfaces/HookEvents.js +16 -0
- package/dist/commonjs/interfaces/HookEvents.js.map +1 -1
- package/dist/commonjs/interfaces/Parameter.d.ts +16 -0
- package/dist/commonjs/interfaces/Parameter.d.ts.map +1 -1
- package/dist/commonjs/interfaces/Rule.d.ts +23 -0
- package/dist/commonjs/interfaces/Rule.d.ts.map +1 -1
- package/dist/commonjs/interfaces/Script.d.ts +10 -0
- package/dist/commonjs/interfaces/Script.d.ts.map +1 -1
- package/dist/commonjs/runtime/ActionRuntime.js +1 -1
- package/dist/commonjs/runtime/ActionRuntime.js.map +1 -1
- package/dist/commonjs/runtime/ConditionRuntime.js +3 -3
- package/dist/commonjs/runtime/ConditionRuntime.js.map +1 -1
- package/dist/commonjs/runtime/RuleRuntime.js +1 -1
- package/dist/commonjs/runtime/RuleRuntime.js.map +1 -1
- package/dist/commonjs/types/ExecutionContext.d.ts +13 -0
- package/dist/commonjs/types/ExecutionContext.d.ts.map +1 -1
- package/dist/commonjs/types/ExecutionContext.js +3 -0
- package/dist/commonjs/types/ExecutionContext.js.map +1 -1
- package/dist/commonjs/types/ExecutionResult.d.ts +14 -0
- package/dist/commonjs/types/ExecutionResult.d.ts.map +1 -1
- package/dist/commonjs/types/ExecutionResult.js +14 -0
- package/dist/commonjs/types/ExecutionResult.js.map +1 -1
- package/dist/commonjs/types/HookEmitter.d.ts +8 -1
- package/dist/commonjs/types/HookEmitter.d.ts.map +1 -1
- package/dist/esm/Synapse.d.ts +18 -0
- package/dist/esm/Synapse.d.ts.map +1 -1
- package/dist/esm/Synapse.js +18 -0
- package/dist/esm/Synapse.js.map +1 -1
- package/dist/esm/abstracts/AbstractAction.d.ts +15 -0
- package/dist/esm/abstracts/AbstractAction.d.ts.map +1 -0
- package/dist/esm/abstracts/AbstractAction.js +21 -0
- package/dist/esm/abstracts/AbstractAction.js.map +1 -0
- package/dist/esm/abstracts/AbstractCondition.d.ts +15 -0
- package/dist/esm/abstracts/AbstractCondition.d.ts.map +1 -0
- package/dist/esm/abstracts/AbstractCondition.js +21 -0
- package/dist/esm/abstracts/AbstractCondition.js.map +1 -0
- package/dist/esm/contracts/explain.d.ts +9 -0
- package/dist/esm/contracts/explain.d.ts.map +1 -0
- package/dist/esm/contracts/explain.js +48 -0
- package/dist/esm/contracts/explain.js.map +1 -0
- package/dist/esm/contracts/validation.d.ts +40 -0
- package/dist/esm/contracts/validation.d.ts.map +1 -0
- package/dist/esm/contracts/validation.js +255 -0
- package/dist/esm/contracts/validation.js.map +1 -0
- package/dist/esm/index.d.ts +64 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +50 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces/Action.d.ts +14 -0
- package/dist/esm/interfaces/Action.d.ts.map +1 -1
- package/dist/esm/interfaces/Condition.d.ts +21 -0
- package/dist/esm/interfaces/Condition.d.ts.map +1 -1
- package/dist/esm/interfaces/Element.d.ts +16 -0
- package/dist/esm/interfaces/Element.d.ts.map +1 -1
- package/dist/esm/interfaces/HookEvents.d.ts +16 -0
- package/dist/esm/interfaces/HookEvents.d.ts.map +1 -1
- package/dist/esm/interfaces/HookEvents.js +16 -0
- package/dist/esm/interfaces/HookEvents.js.map +1 -1
- package/dist/esm/interfaces/Parameter.d.ts +16 -0
- package/dist/esm/interfaces/Parameter.d.ts.map +1 -1
- package/dist/esm/interfaces/Rule.d.ts +23 -0
- package/dist/esm/interfaces/Rule.d.ts.map +1 -1
- package/dist/esm/interfaces/Script.d.ts +10 -0
- package/dist/esm/interfaces/Script.d.ts.map +1 -1
- package/dist/esm/runtime/ActionRuntime.js +1 -1
- package/dist/esm/runtime/ActionRuntime.js.map +1 -1
- package/dist/esm/runtime/ConditionRuntime.js +3 -3
- package/dist/esm/runtime/ConditionRuntime.js.map +1 -1
- package/dist/esm/runtime/RuleRuntime.js +1 -1
- package/dist/esm/runtime/RuleRuntime.js.map +1 -1
- package/dist/esm/types/ExecutionContext.d.ts +13 -0
- package/dist/esm/types/ExecutionContext.d.ts.map +1 -1
- package/dist/esm/types/ExecutionContext.js +3 -0
- package/dist/esm/types/ExecutionContext.js.map +1 -1
- package/dist/esm/types/ExecutionResult.d.ts +14 -0
- package/dist/esm/types/ExecutionResult.d.ts.map +1 -1
- package/dist/esm/types/ExecutionResult.js +14 -0
- package/dist/esm/types/ExecutionResult.js.map +1 -1
- package/dist/esm/types/HookEmitter.d.ts +8 -1
- package/dist/esm/types/HookEmitter.d.ts.map +1 -1
- package/examples/README.md +24 -0
- package/examples/eligibility-check/README.md +31 -0
- package/examples/eligibility-check/expected-output.json +7 -0
- package/examples/eligibility-check/input.json +6 -0
- package/examples/eligibility-check/rules.json +32 -0
- package/examples/eligibility-check/run.ts +128 -0
- package/examples/pricing-rules/README.md +31 -0
- package/examples/pricing-rules/expected-output.json +7 -0
- package/examples/pricing-rules/input.json +7 -0
- package/examples/pricing-rules/rules.json +32 -0
- package/examples/pricing-rules/run.ts +136 -0
- package/examples/workflow-routing/README.md +31 -0
- package/examples/workflow-routing/expected-output.json +7 -0
- package/examples/workflow-routing/input.json +6 -0
- package/examples/workflow-routing/rules.json +33 -0
- package/examples/workflow-routing/run.ts +130 -0
- package/package.json +31 -4
- package/schemas/execution-context.schema.json +23 -0
- package/schemas/execution-output.schema.json +16 -0
- package/schemas/explanation-trace.schema.json +32 -0
- package/schemas/script.schema.json +90 -0
- package/schemas/validation-error.schema.json +13 -0
- package/src/Synapse.ts +18 -0
- package/src/abstracts/AbstractAction.ts +34 -0
- package/src/abstracts/AbstractCondition.ts +34 -0
- package/src/contracts/explain.ts +66 -0
- package/src/contracts/validation.ts +348 -0
- package/src/index.ts +116 -0
- package/src/interfaces/Action.ts +14 -0
- package/src/interfaces/Condition.ts +23 -0
- package/src/interfaces/Element.ts +18 -0
- package/src/interfaces/HookEvents.ts +16 -0
- package/src/interfaces/Parameter.ts +18 -0
- package/src/interfaces/Rule.ts +24 -0
- package/src/interfaces/Script.ts +11 -0
- package/src/runtime/ActionRuntime.ts +1 -1
- package/src/runtime/ConditionRuntime.ts +3 -3
- package/src/runtime/RuleRuntime.ts +1 -1
- package/src/types/ExecutionContext.ts +13 -0
- package/src/types/ExecutionResult.ts +14 -0
- package/src/types/HookEmitter.ts +5 -0
- package/dist/commonjs/Synapse.test.d.ts +0 -2
- package/dist/commonjs/Synapse.test.d.ts.map +0 -1
- package/dist/commonjs/Synapse.test.js +0 -15
- package/dist/commonjs/Synapse.test.js.map +0 -1
- package/dist/commonjs/index.test.d.ts +0 -2
- package/dist/commonjs/index.test.d.ts.map +0 -1
- package/dist/commonjs/index.test.js +0 -132
- package/dist/commonjs/index.test.js.map +0 -1
- package/dist/commonjs/runtime/ConditionRuntime.test.d.ts +0 -2
- package/dist/commonjs/runtime/ConditionRuntime.test.d.ts.map +0 -1
- package/dist/commonjs/runtime/ConditionRuntime.test.js +0 -70
- package/dist/commonjs/runtime/ConditionRuntime.test.js.map +0 -1
- package/dist/esm/Synapse.test.d.ts +0 -2
- package/dist/esm/Synapse.test.d.ts.map +0 -1
- package/dist/esm/Synapse.test.js +0 -13
- package/dist/esm/Synapse.test.js.map +0 -1
- package/dist/esm/index.test.d.ts +0 -2
- package/dist/esm/index.test.d.ts.map +0 -1
- package/dist/esm/index.test.js +0 -130
- package/dist/esm/index.test.js.map +0 -1
- package/dist/esm/runtime/ConditionRuntime.test.d.ts +0 -2
- package/dist/esm/runtime/ConditionRuntime.test.d.ts.map +0 -1
- package/dist/esm/runtime/ConditionRuntime.test.js +0 -68
- package/dist/esm/runtime/ConditionRuntime.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,28 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/public/img/neuron-cover640.png" alt="neuron-js logo" width="640">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
5
|
# neuron-js
|
|
4
6
|
|
|
5
|
-
> **
|
|
7
|
+
> **AI-friendly TypeScript rules engine for serializable JSON business rules and deterministic workflow decisions.**
|
|
6
8
|
|
|
7
9
|
[](https://opensource.org/licenses/MIT)
|
|
8
10
|
[](https://socket.dev/npm/package/@sebasoft/neuron-js)
|
|
9
11
|
[](https://nodejs.org)
|
|
10
12
|
[](https://github.com/SebaSOFT/neuron-js/actions)
|
|
11
13
|
|
|
12
|
-
`neuron-js`
|
|
14
|
+
`neuron-js` lets teams define business rules and workflow decisions as pure JSON, execute them deterministically in Node.js or the browser, and extend the rule vocabulary with TypeScript actions, conditions, parameters, rules, and lifecycle hooks.
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Use it when hardcoded `if/else` logic is too rigid, but a heavyweight workflow or BPMN platform is too much machinery.
|
|
17
|
+
|
|
18
|
+
## Links
|
|
19
|
+
|
|
20
|
+
- Documentation: <https://sebasoft.github.io/neuron-js/>
|
|
21
|
+
- npm: <https://www.npmjs.com/package/@sebasoft/neuron-js>
|
|
22
|
+
- GitHub: <https://github.com/SebaSOFT/neuron-js>
|
|
23
|
+
- Examples: [`examples/`](examples/) with pricing, eligibility, and workflow-routing scenarios
|
|
24
|
+
- Schemas and validation docs: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
|
|
25
|
+
- AI-readable docs: planned as `NJS-GROWTH-04`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Why neuron-js?
|
|
30
|
+
|
|
31
|
+
Use `neuron-js` when:
|
|
32
|
+
|
|
33
|
+
- Business rules need to be stored, versioned, audited, or changed without redeploying code.
|
|
34
|
+
- Backend and frontend code need to share the same deterministic rule definitions.
|
|
35
|
+
- AI assistants or workflow tools generate JSON rules that still need developer-owned validation and execution boundaries.
|
|
36
|
+
- Product, pricing, eligibility, routing, or automation decisions change faster than application deployments.
|
|
37
|
+
- A full workflow platform is too heavy, but hardcoded conditional logic is too brittle.
|
|
38
|
+
|
|
39
|
+
Do not use `neuron-js` when a simple hardcoded condition is clearer and rarely changes, when arbitrary user code execution is required, or when you need a full BPMN/process orchestration platform.
|
|
15
40
|
|
|
16
41
|
---
|
|
17
42
|
|
|
18
43
|
## ✨ Features
|
|
19
44
|
|
|
20
|
-
- 🛠 **Pluggable
|
|
21
|
-
- 📦 **JSON
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
- 🌓 **Dual-
|
|
25
|
-
- 🪝 **Lifecycle Hooks**: Comprehensive hook system for monitoring and side-effect management.
|
|
45
|
+
- 🛠 **Pluggable TypeScript registry**: Register custom Actions, Conditions, Parameters, and Rules.
|
|
46
|
+
- 📦 **JSON business rules**: Store, transmit, version, and audit logic as serializable JSON.
|
|
47
|
+
- ⚡ **Deterministic execution**: Run predictable workflow and business decisions in Node.js or the browser.
|
|
48
|
+
- 🪝 **Lifecycle hooks**: Monitor script, rule, action, and error events around execution.
|
|
49
|
+
- 🌓 **Dual-module support**: Native ESM and CommonJS bundles via `tshy`.
|
|
26
50
|
|
|
27
51
|
---
|
|
28
52
|
|
|
@@ -36,43 +60,41 @@ yarn add @sebasoft/neuron-js
|
|
|
36
60
|
npm install @sebasoft/neuron-js
|
|
37
61
|
```
|
|
38
62
|
|
|
39
|
-
###
|
|
63
|
+
### Executable rule example
|
|
40
64
|
|
|
41
65
|
```typescript
|
|
42
66
|
import { Neuron, Synapse } from '@sebasoft/neuron-js';
|
|
43
67
|
|
|
44
|
-
// 1. Initialize the registry
|
|
45
68
|
const neuron = new Neuron();
|
|
46
|
-
|
|
47
|
-
// 2. Setup the executor
|
|
48
69
|
const synapse = new Synapse(neuron);
|
|
49
70
|
|
|
50
|
-
// 3. Define your logic script (JSON-serializable)
|
|
51
71
|
const script = {
|
|
52
|
-
id: '
|
|
72
|
+
id: 'pricing-decision',
|
|
53
73
|
rules: [
|
|
54
74
|
{
|
|
55
|
-
id: 'rule
|
|
75
|
+
id: 'vip-discount-rule',
|
|
56
76
|
type: 'simple_rule',
|
|
57
77
|
options: {},
|
|
58
78
|
conditions: [
|
|
59
79
|
{
|
|
60
|
-
id: '
|
|
80
|
+
id: 'minimum-order-value',
|
|
61
81
|
type: 'compare_two_numbers',
|
|
82
|
+
options: {},
|
|
62
83
|
params: [
|
|
63
|
-
{ name: 'op1', type: 'simple_number', value: '
|
|
64
|
-
{ name: 'comp', type: 'comparator', value: '>' },
|
|
65
|
-
{ name: 'op2', type: 'simple_number', value: '
|
|
84
|
+
{ id: 'order-total', name: 'op1', type: 'simple_number', value: '125', options: {} },
|
|
85
|
+
{ id: 'comparison', name: 'comp', type: 'comparator', value: '>', options: {} },
|
|
86
|
+
{ id: 'threshold', name: 'op2', type: 'simple_number', value: '100', options: {} }
|
|
66
87
|
]
|
|
67
88
|
}
|
|
68
89
|
],
|
|
69
90
|
actions: [
|
|
70
91
|
{
|
|
71
|
-
id: '
|
|
92
|
+
id: 'calculate-discount',
|
|
72
93
|
type: 'add_two_numbers',
|
|
94
|
+
options: {},
|
|
73
95
|
params: [
|
|
74
|
-
{ name: 'op1', type: 'simple_number', value: '
|
|
75
|
-
{ name: 'op2', type: 'simple_number', value: '5' }
|
|
96
|
+
{ id: 'base-discount', name: 'op1', type: 'simple_number', value: '10', options: {} },
|
|
97
|
+
{ id: 'vip-bonus', name: 'op2', type: 'simple_number', value: '5', options: {} }
|
|
76
98
|
]
|
|
77
99
|
}
|
|
78
100
|
]
|
|
@@ -80,34 +102,44 @@ const script = {
|
|
|
80
102
|
]
|
|
81
103
|
};
|
|
82
104
|
|
|
83
|
-
// 4. Execute
|
|
84
105
|
const context = { messages: [], state: {} };
|
|
85
106
|
const result = synapse.execute(script, context);
|
|
86
107
|
|
|
87
108
|
console.log(result.isSuccessful()); // true
|
|
88
|
-
console.log(result.value); // 1
|
|
109
|
+
console.log(result.value); // 1 rule executed
|
|
110
|
+
console.log(result.context.messages.map((message) => message.text)); // includes "Sum result: 15"
|
|
89
111
|
```
|
|
90
112
|
|
|
91
113
|
---
|
|
92
114
|
|
|
93
115
|
## 🧬 Core Concepts
|
|
94
116
|
|
|
95
|
-
### Neuron
|
|
96
|
-
|
|
117
|
+
### Neuron: the registry
|
|
118
|
+
|
|
119
|
+
The `Neuron` registry knows which parameter, condition, action, and rule types are available. Applications keep control of this registry so generated or stored JSON can only use developer-approved capabilities.
|
|
120
|
+
|
|
121
|
+
### Synapse: the executor
|
|
122
|
+
|
|
123
|
+
The `Synapse` engine connects a `Neuron` registry with a serializable script and an execution context. It evaluates rules, applies actions, and emits lifecycle hooks.
|
|
97
124
|
|
|
98
|
-
###
|
|
99
|
-
|
|
125
|
+
### Rule
|
|
126
|
+
|
|
127
|
+
A Rule is a logical unit containing conditions and actions.
|
|
128
|
+
|
|
129
|
+
- **No Conditions**: the rule is treated as always eligible.
|
|
130
|
+
- **No Actions**: the rule evaluates conditions but performs no operation.
|
|
100
131
|
|
|
101
132
|
### Elements
|
|
102
|
-
|
|
103
|
-
- **
|
|
104
|
-
- **
|
|
133
|
+
|
|
134
|
+
- **Action**: An operation to perform, such as writing to context, calculating a value, or triggering an approved side effect.
|
|
135
|
+
- **Condition**: A predicate that decides whether a rule should run.
|
|
136
|
+
- **Parameter**: A serializable input for actions and conditions.
|
|
105
137
|
|
|
106
138
|
---
|
|
107
139
|
|
|
108
140
|
## 💾 Execution Context & State
|
|
109
141
|
|
|
110
|
-
The `ExecutionContext` is a shared state object that persists
|
|
142
|
+
The `ExecutionContext` is a shared state object that persists through script execution. Actions and conditions can read from it, and actions can return updated context for later rules.
|
|
111
143
|
|
|
112
144
|
```typescript
|
|
113
145
|
interface ExecutionContext {
|
|
@@ -116,22 +148,27 @@ interface ExecutionContext {
|
|
|
116
148
|
}
|
|
117
149
|
```
|
|
118
150
|
|
|
119
|
-
|
|
120
|
-
Actions can read from the context and return an updated context to pass information to subsequent rules.
|
|
151
|
+
---
|
|
121
152
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
153
|
+
## Roadmap-aligned docs
|
|
154
|
+
|
|
155
|
+
The current public surface includes installation, positioning, core concepts, runtime architecture, and runnable examples.
|
|
156
|
+
|
|
157
|
+
Available adoption assets:
|
|
158
|
+
|
|
159
|
+
- Runnable examples: [`examples/`](examples/)
|
|
160
|
+
- JSON Schemas, validation, and explain output: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
|
|
161
|
+
|
|
162
|
+
Planned next adoption assets:
|
|
163
|
+
|
|
164
|
+
- `llms.txt` and AI-assistant documentation: `NJS-GROWTH-04`
|
|
165
|
+
- Comparison and migration pages: `NJS-GROWTH-05`
|
|
129
166
|
|
|
130
167
|
---
|
|
131
168
|
|
|
132
169
|
## 🛠 Development
|
|
133
170
|
|
|
134
|
-
We use a modern toolchain for high
|
|
171
|
+
We use a modern toolchain for high-signal development:
|
|
135
172
|
|
|
136
173
|
- **Linting & Formatting**: [Biome](https://biomejs.dev/)
|
|
137
174
|
- **Testing**: [Vitest](https://vitest.dev/)
|
|
@@ -142,8 +179,10 @@ We use a modern toolchain for high performance and developer ergonomics:
|
|
|
142
179
|
|
|
143
180
|
```bash
|
|
144
181
|
yarn test # Run test suite
|
|
145
|
-
yarn lint # Check
|
|
182
|
+
yarn lint # Check linting and formatting
|
|
183
|
+
yarn examples # Build and verify runnable examples
|
|
146
184
|
yarn build # Generate ESM/CJS bundles
|
|
185
|
+
yarn docs:build # Build API docs and VitePress site
|
|
147
186
|
```
|
|
148
187
|
|
|
149
188
|
---
|
|
@@ -3,10 +3,28 @@ import type { ScriptInterface } from "./interfaces/Script.js";
|
|
|
3
3
|
import type { ExecutionContext } from "./types/ExecutionContext.js";
|
|
4
4
|
import { ExecutionResult } from "./types/ExecutionResult.js";
|
|
5
5
|
import type { HookEmitter } from "./types/HookEmitter.js";
|
|
6
|
+
/**
|
|
7
|
+
* The Synapse class is the core execution engine of the rules system.
|
|
8
|
+
* It processes logic defined in scripts by coordinating between the Registry (Neuron) and the state (ExecutionContext).
|
|
9
|
+
*/
|
|
6
10
|
export declare class Synapse {
|
|
7
11
|
private readonly _neuron;
|
|
8
12
|
private readonly _hookEmitter?;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new execution engine.
|
|
15
|
+
*
|
|
16
|
+
* @param _neuron - The registry containing all element definitions.
|
|
17
|
+
* @param _hookEmitter - Optional global lifecycle hook emitter.
|
|
18
|
+
*/
|
|
9
19
|
constructor(_neuron: Neuron, _hookEmitter?: HookEmitter | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Executes a script logic against a provided context.
|
|
22
|
+
*
|
|
23
|
+
* @param script - The serializable script defining the logic rules.
|
|
24
|
+
* @param context - The shared state object to pass through the execution.
|
|
25
|
+
* @param runtimeHookEmitter - Optional one-time hook emitter for this specific execution.
|
|
26
|
+
* @returns An ExecutionResult containing the final context and the number of successfully executed rules.
|
|
27
|
+
*/
|
|
10
28
|
execute(script: ScriptInterface, context: ExecutionContext, runtimeHookEmitter?: HookEmitter): ExecutionResult<number>;
|
|
11
29
|
}
|
|
12
30
|
//# sourceMappingURL=Synapse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../../src/Synapse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,qBAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../../src/Synapse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;GAGG;AACH,qBAAa,OAAO;IAQhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IARhC;;;;;OAKG;gBAEgB,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,WAAW,YAAA;IAG7C;;;;;;;OAOG;IACH,OAAO,CACL,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,gBAAgB,EACzB,kBAAkB,CAAC,EAAE,WAAW,GAC/B,eAAe,CAAC,MAAM,CAAC;CAsB3B"}
|
package/dist/commonjs/Synapse.js
CHANGED
|
@@ -4,13 +4,31 @@ exports.Synapse = void 0;
|
|
|
4
4
|
const HookEvents_js_1 = require("./interfaces/HookEvents.js");
|
|
5
5
|
const RuleRuntime_js_1 = require("./runtime/RuleRuntime.js");
|
|
6
6
|
const ExecutionResult_js_1 = require("./types/ExecutionResult.js");
|
|
7
|
+
/**
|
|
8
|
+
* The Synapse class is the core execution engine of the rules system.
|
|
9
|
+
* It processes logic defined in scripts by coordinating between the Registry (Neuron) and the state (ExecutionContext).
|
|
10
|
+
*/
|
|
7
11
|
class Synapse {
|
|
8
12
|
_neuron;
|
|
9
13
|
_hookEmitter;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new execution engine.
|
|
16
|
+
*
|
|
17
|
+
* @param _neuron - The registry containing all element definitions.
|
|
18
|
+
* @param _hookEmitter - Optional global lifecycle hook emitter.
|
|
19
|
+
*/
|
|
10
20
|
constructor(_neuron, _hookEmitter) {
|
|
11
21
|
this._neuron = _neuron;
|
|
12
22
|
this._hookEmitter = _hookEmitter;
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes a script logic against a provided context.
|
|
26
|
+
*
|
|
27
|
+
* @param script - The serializable script defining the logic rules.
|
|
28
|
+
* @param context - The shared state object to pass through the execution.
|
|
29
|
+
* @param runtimeHookEmitter - Optional one-time hook emitter for this specific execution.
|
|
30
|
+
* @returns An ExecutionResult containing the final context and the number of successfully executed rules.
|
|
31
|
+
*/
|
|
14
32
|
execute(script, context, runtimeHookEmitter) {
|
|
15
33
|
const emitter = runtimeHookEmitter ?? this._hookEmitter;
|
|
16
34
|
if (!script?.rules || script.rules.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Synapse.js","sourceRoot":"","sources":["../../src/Synapse.ts"],"names":[],"mappings":";;;AACA,8DAAwD;AAExD,6DAAuD;AAEvD,mEAA6D;AAG7D,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"Synapse.js","sourceRoot":"","sources":["../../src/Synapse.ts"],"names":[],"mappings":";;;AACA,8DAAwD;AAExD,6DAAuD;AAEvD,mEAA6D;AAG7D;;;GAGG;AACH,MAAa,OAAO;IAQC;IACA;IARnB;;;;;OAKG;IACH,YACmB,OAAe,EACf,YAA0B;QAD1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ;;;;;;;OAOG;IACH,OAAO,CACL,MAAuB,EACvB,OAAyB,EACzB,kBAAgC;QAEhC,MAAM,OAAO,GAAG,kBAAkB,IAAI,IAAI,CAAC,YAAY,CAAC;QAExD,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChD,OAAO,EAAE,CAAC,0BAAU,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,MAAM,GAAG,IAAI,oCAAe,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;YACvE,OAAO,EAAE,CAAC,0BAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,CAAC,0BAAU,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,4BAAW,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzE,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC,0BAAU,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,OAAO,EAAE,CAAC,0BAAU,CAAC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA9CD,0BA8CC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Neuron } from "../index.js";
|
|
2
|
+
import type { ActionOptions } from "../interfaces/Action.js";
|
|
3
|
+
import type { ParameterInterface } from "../interfaces/Parameter.js";
|
|
4
|
+
import type { ExecutionContext } from "../types/ExecutionContext.js";
|
|
5
|
+
import { AbstractElement } from "./AbstractElement.js";
|
|
6
|
+
export declare abstract class AbstractAction<TOptions extends ActionOptions = ActionOptions> extends AbstractElement<TOptions> {
|
|
7
|
+
readonly rawParams: ParameterInterface[];
|
|
8
|
+
protected readonly neuron: Neuron;
|
|
9
|
+
readonly params: Map<string, {
|
|
10
|
+
getValue(context: ExecutionContext): unknown | null;
|
|
11
|
+
}>;
|
|
12
|
+
constructor(id: string, type: string, rawParams: ParameterInterface[], options: TOptions, neuron: Neuron);
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=AbstractAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractAction.d.ts","sourceRoot":"","sources":["../../../src/abstracts/AbstractAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,8BAAsB,cAAc,CAClC,QAAQ,SAAS,aAAa,GAAG,aAAa,CAC9C,SAAQ,eAAe,CAAC,QAAQ,CAAC;aASf,SAAS,EAAE,kBAAkB,EAAE;IAE/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAVnC,SAAgB,MAAM,EAAE,GAAG,CACzB,MAAM,EACN;QAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CACxD,CAAC;gBAGA,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACI,SAAS,EAAE,kBAAkB,EAAE,EAC/C,OAAO,EAAE,QAAQ,EACE,MAAM,EAAE,MAAM;IAMnC,MAAM,IAAI,MAAM;CAQjB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAction = void 0;
|
|
4
|
+
const AbstractElement_js_1 = require("./AbstractElement.js");
|
|
5
|
+
class AbstractAction extends AbstractElement_js_1.AbstractElement {
|
|
6
|
+
rawParams;
|
|
7
|
+
neuron;
|
|
8
|
+
params;
|
|
9
|
+
constructor(id, type, rawParams, options, neuron) {
|
|
10
|
+
super(id, type, options);
|
|
11
|
+
this.rawParams = rawParams;
|
|
12
|
+
this.neuron = neuron;
|
|
13
|
+
this.params = neuron.createParameterMap(rawParams);
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
return {
|
|
17
|
+
id: this.id,
|
|
18
|
+
type: this.type,
|
|
19
|
+
params: this.rawParams,
|
|
20
|
+
options: this.options,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AbstractAction = AbstractAction;
|
|
25
|
+
//# sourceMappingURL=AbstractAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractAction.js","sourceRoot":"","sources":["../../../src/abstracts/AbstractAction.ts"],"names":[],"mappings":";;;AAIA,6DAAuD;AAEvD,MAAsB,cAEpB,SAAQ,oCAAyB;IASf;IAEG;IAVL,MAAM,CAGpB;IAEF,YACE,EAAU,EACV,IAAY,EACI,SAA+B,EAC/C,OAAiB,EACE,MAAc;QAEjC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAJT,cAAS,GAAT,SAAS,CAAsB;QAE5B,WAAM,GAAN,MAAM,CAAQ;QAGjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,SAAS;YACtB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AA3BD,wCA2BC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Neuron } from "../index.js";
|
|
2
|
+
import type { ConditionOptions } from "../interfaces/Condition.js";
|
|
3
|
+
import type { ParameterInterface } from "../interfaces/Parameter.js";
|
|
4
|
+
import type { ExecutionContext } from "../types/ExecutionContext.js";
|
|
5
|
+
import { AbstractElement } from "./AbstractElement.js";
|
|
6
|
+
export declare abstract class AbstractCondition<TOptions extends ConditionOptions = ConditionOptions> extends AbstractElement<TOptions> {
|
|
7
|
+
readonly rawParams: ParameterInterface[];
|
|
8
|
+
protected readonly neuron: Neuron;
|
|
9
|
+
readonly params: Map<string, {
|
|
10
|
+
getValue(context: ExecutionContext): unknown | null;
|
|
11
|
+
}>;
|
|
12
|
+
constructor(id: string, type: string, rawParams: ParameterInterface[], options: TOptions, neuron: Neuron);
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=AbstractCondition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractCondition.d.ts","sourceRoot":"","sources":["../../../src/abstracts/AbstractCondition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,8BAAsB,iBAAiB,CACrC,QAAQ,SAAS,gBAAgB,GAAG,gBAAgB,CACpD,SAAQ,eAAe,CAAC,QAAQ,CAAC;aASf,SAAS,EAAE,kBAAkB,EAAE;IAE/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAVnC,SAAgB,MAAM,EAAE,GAAG,CACzB,MAAM,EACN;QAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CACxD,CAAC;gBAGA,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACI,SAAS,EAAE,kBAAkB,EAAE,EAC/C,OAAO,EAAE,QAAQ,EACE,MAAM,EAAE,MAAM;IAMnC,MAAM,IAAI,MAAM;CAQjB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractCondition = void 0;
|
|
4
|
+
const AbstractElement_js_1 = require("./AbstractElement.js");
|
|
5
|
+
class AbstractCondition extends AbstractElement_js_1.AbstractElement {
|
|
6
|
+
rawParams;
|
|
7
|
+
neuron;
|
|
8
|
+
params;
|
|
9
|
+
constructor(id, type, rawParams, options, neuron) {
|
|
10
|
+
super(id, type, options);
|
|
11
|
+
this.rawParams = rawParams;
|
|
12
|
+
this.neuron = neuron;
|
|
13
|
+
this.params = neuron.createParameterMap(rawParams);
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
return {
|
|
17
|
+
id: this.id,
|
|
18
|
+
type: this.type,
|
|
19
|
+
params: this.rawParams,
|
|
20
|
+
options: this.options,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AbstractCondition = AbstractCondition;
|
|
25
|
+
//# sourceMappingURL=AbstractCondition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractCondition.js","sourceRoot":"","sources":["../../../src/abstracts/AbstractCondition.ts"],"names":[],"mappings":";;;AAIA,6DAAuD;AAEvD,MAAsB,iBAEpB,SAAQ,oCAAyB;IASf;IAEG;IAVL,MAAM,CAGpB;IAEF,YACE,EAAU,EACV,IAAY,EACI,SAA+B,EAC/C,OAAiB,EACE,MAAc;QAEjC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAJT,cAAS,GAAT,SAAS,CAAsB;QAE5B,WAAM,GAAN,MAAM,CAAQ;QAGjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,SAAS;YACtB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AA3BD,8CA2BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScriptInterface } from "../interfaces/Script.js";
|
|
2
|
+
import type { ExecutionResult } from "../types/ExecutionResult.js";
|
|
3
|
+
import type { ExecutionExplanation } from "./validation.js";
|
|
4
|
+
export interface ExplainExecutionOptions {
|
|
5
|
+
script: ScriptInterface;
|
|
6
|
+
result: ExecutionResult<number>;
|
|
7
|
+
}
|
|
8
|
+
export declare function explainExecution({ script, result, }: ExplainExecutionOptions): ExecutionExplanation;
|
|
9
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../../../src/contracts/explain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EACV,oBAAoB,EAErB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,MAAM,GACP,EAAE,uBAAuB,GAAG,oBAAoB,CAkDhD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.explainExecution = explainExecution;
|
|
4
|
+
function explainExecution({ script, result, }) {
|
|
5
|
+
const trace = [
|
|
6
|
+
{
|
|
7
|
+
step: 1,
|
|
8
|
+
type: "script_received",
|
|
9
|
+
message: `Script ${script.id} contains ${script.rules.length} rule(s).`,
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
script.rules.forEach((rule, index) => {
|
|
13
|
+
trace.push({
|
|
14
|
+
step: trace.length + 1,
|
|
15
|
+
type: rule.options?.disabled ? "rule_skipped" : "rule_available",
|
|
16
|
+
ruleId: rule.id,
|
|
17
|
+
message: rule.options?.disabled
|
|
18
|
+
? `Rule ${rule.id} is disabled.`
|
|
19
|
+
: `Rule ${rule.id} has ${rule.conditions?.length ?? 0} condition(s) and ${rule.actions?.length ?? 0} action(s).`,
|
|
20
|
+
});
|
|
21
|
+
if (index === script.rules.length - 1) {
|
|
22
|
+
trace.push({
|
|
23
|
+
step: trace.length + 1,
|
|
24
|
+
type: result.isSuccessful()
|
|
25
|
+
? "execution_completed"
|
|
26
|
+
: "execution_failed",
|
|
27
|
+
ruleId: rule.id,
|
|
28
|
+
message: result.isSuccessful()
|
|
29
|
+
? `Execution completed with ${result.value ?? 0} rule(s) executed.`
|
|
30
|
+
: "Execution failed before completing all rules.",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (script.rules.length === 0) {
|
|
35
|
+
trace.push({
|
|
36
|
+
step: trace.length + 1,
|
|
37
|
+
type: "execution_completed",
|
|
38
|
+
message: "Execution completed with an empty script.",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
scriptId: script.id,
|
|
43
|
+
ok: result.isSuccessful(),
|
|
44
|
+
rulesEvaluated: script.rules.filter((rule) => !rule.options?.disabled)
|
|
45
|
+
.length,
|
|
46
|
+
rulesExecuted: typeof result.value === "number" ? result.value : null,
|
|
47
|
+
messages: result.messages,
|
|
48
|
+
trace,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../../src/contracts/explain.ts"],"names":[],"mappings":";;AAYA,4CAqDC;AArDD,SAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,MAAM,GACkB;IACxB,MAAM,KAAK,GAAgC;QACzC;YACE,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,UAAU,MAAM,CAAC,EAAE,aAAa,MAAM,CAAC,KAAK,CAAC,MAAM,WAAW;SACxE;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnC,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;YACtB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,gBAAgB;YAChE,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ;gBAC7B,CAAC,CAAC,QAAQ,IAAI,CAAC,EAAE,eAAe;gBAChC,CAAC,CAAC,QAAQ,IAAI,CAAC,EAAE,QAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,qBAAqB,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,aAAa;SACnH,CAAC,CAAC;QAEH,IAAI,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;gBACtB,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE;oBACzB,CAAC,CAAC,qBAAqB;oBACvB,CAAC,CAAC,kBAAkB;gBACtB,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE;oBAC5B,CAAC,CAAC,4BAA4B,MAAM,CAAC,KAAK,IAAI,CAAC,oBAAoB;oBACnE,CAAC,CAAC,+CAA+C;aACpD,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;YACtB,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,EAAE,EAAE,MAAM,CAAC,YAAY,EAAE;QACzB,cAAc,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;aACnE,MAAM;QACT,aAAa,EAAE,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;QACrE,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ExecutionContext } from "../types/ExecutionContext.js";
|
|
2
|
+
export interface ValidationError {
|
|
3
|
+
path: string;
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
errors: ValidationError[];
|
|
10
|
+
}
|
|
11
|
+
export declare function validateScript(script: unknown): ValidationResult;
|
|
12
|
+
export declare function validateExecutionContext(context: unknown): ValidationResult;
|
|
13
|
+
export declare function validateExecutionOutput(output: unknown): ValidationResult;
|
|
14
|
+
export declare function validateValidationErrors(value: unknown): ValidationResult;
|
|
15
|
+
export interface ExecutionExplanationEvent {
|
|
16
|
+
step: number;
|
|
17
|
+
type: string;
|
|
18
|
+
message: string;
|
|
19
|
+
ruleId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ExecutionExplanation {
|
|
22
|
+
scriptId: string;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
rulesEvaluated: number;
|
|
25
|
+
rulesExecuted: number | null;
|
|
26
|
+
messages: string[];
|
|
27
|
+
trace: ExecutionExplanationEvent[];
|
|
28
|
+
}
|
|
29
|
+
export declare function validateExecutionExplanation(value: unknown): ValidationResult;
|
|
30
|
+
export declare function summarizeExecutionOutput(result: {
|
|
31
|
+
isSuccessful(): boolean;
|
|
32
|
+
value: unknown;
|
|
33
|
+
messages: string[];
|
|
34
|
+
}): {
|
|
35
|
+
ok: boolean;
|
|
36
|
+
rulesExecuted: number | null;
|
|
37
|
+
messages: string[];
|
|
38
|
+
};
|
|
39
|
+
export type { ExecutionContext };
|
|
40
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/contracts/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AA+JD,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAShE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAqB3E;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAmCzE;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAoBzE;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,OAAO,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,yBAAyB,EAAE,CAAC;CACpC;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAsD7E;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,YAAY,IAAI,OAAO,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;;;;EAMA;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|