@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.
Files changed (178) hide show
  1. package/README.md +84 -45
  2. package/dist/commonjs/Synapse.d.ts +18 -0
  3. package/dist/commonjs/Synapse.d.ts.map +1 -1
  4. package/dist/commonjs/Synapse.js +18 -0
  5. package/dist/commonjs/Synapse.js.map +1 -1
  6. package/dist/commonjs/abstracts/AbstractAction.d.ts +15 -0
  7. package/dist/commonjs/abstracts/AbstractAction.d.ts.map +1 -0
  8. package/dist/commonjs/abstracts/AbstractAction.js +25 -0
  9. package/dist/commonjs/abstracts/AbstractAction.js.map +1 -0
  10. package/dist/commonjs/abstracts/AbstractCondition.d.ts +15 -0
  11. package/dist/commonjs/abstracts/AbstractCondition.d.ts.map +1 -0
  12. package/dist/commonjs/abstracts/AbstractCondition.js +25 -0
  13. package/dist/commonjs/abstracts/AbstractCondition.js.map +1 -0
  14. package/dist/commonjs/contracts/explain.d.ts +9 -0
  15. package/dist/commonjs/contracts/explain.d.ts.map +1 -0
  16. package/dist/commonjs/contracts/explain.js +51 -0
  17. package/dist/commonjs/contracts/explain.js.map +1 -0
  18. package/dist/commonjs/contracts/validation.d.ts +40 -0
  19. package/dist/commonjs/contracts/validation.d.ts.map +1 -0
  20. package/dist/commonjs/contracts/validation.js +263 -0
  21. package/dist/commonjs/contracts/validation.js.map +1 -0
  22. package/dist/commonjs/index.d.ts +64 -0
  23. package/dist/commonjs/index.d.ts.map +1 -1
  24. package/dist/commonjs/index.js +74 -1
  25. package/dist/commonjs/index.js.map +1 -1
  26. package/dist/commonjs/interfaces/Action.d.ts +14 -0
  27. package/dist/commonjs/interfaces/Action.d.ts.map +1 -1
  28. package/dist/commonjs/interfaces/Condition.d.ts +21 -0
  29. package/dist/commonjs/interfaces/Condition.d.ts.map +1 -1
  30. package/dist/commonjs/interfaces/Element.d.ts +16 -0
  31. package/dist/commonjs/interfaces/Element.d.ts.map +1 -1
  32. package/dist/commonjs/interfaces/HookEvents.d.ts +16 -0
  33. package/dist/commonjs/interfaces/HookEvents.d.ts.map +1 -1
  34. package/dist/commonjs/interfaces/HookEvents.js +16 -0
  35. package/dist/commonjs/interfaces/HookEvents.js.map +1 -1
  36. package/dist/commonjs/interfaces/Parameter.d.ts +16 -0
  37. package/dist/commonjs/interfaces/Parameter.d.ts.map +1 -1
  38. package/dist/commonjs/interfaces/Rule.d.ts +23 -0
  39. package/dist/commonjs/interfaces/Rule.d.ts.map +1 -1
  40. package/dist/commonjs/interfaces/Script.d.ts +10 -0
  41. package/dist/commonjs/interfaces/Script.d.ts.map +1 -1
  42. package/dist/commonjs/runtime/ActionRuntime.js +1 -1
  43. package/dist/commonjs/runtime/ActionRuntime.js.map +1 -1
  44. package/dist/commonjs/runtime/ConditionRuntime.js +3 -3
  45. package/dist/commonjs/runtime/ConditionRuntime.js.map +1 -1
  46. package/dist/commonjs/runtime/RuleRuntime.js +1 -1
  47. package/dist/commonjs/runtime/RuleRuntime.js.map +1 -1
  48. package/dist/commonjs/types/ExecutionContext.d.ts +13 -0
  49. package/dist/commonjs/types/ExecutionContext.d.ts.map +1 -1
  50. package/dist/commonjs/types/ExecutionContext.js +3 -0
  51. package/dist/commonjs/types/ExecutionContext.js.map +1 -1
  52. package/dist/commonjs/types/ExecutionResult.d.ts +14 -0
  53. package/dist/commonjs/types/ExecutionResult.d.ts.map +1 -1
  54. package/dist/commonjs/types/ExecutionResult.js +14 -0
  55. package/dist/commonjs/types/ExecutionResult.js.map +1 -1
  56. package/dist/commonjs/types/HookEmitter.d.ts +8 -1
  57. package/dist/commonjs/types/HookEmitter.d.ts.map +1 -1
  58. package/dist/esm/Synapse.d.ts +18 -0
  59. package/dist/esm/Synapse.d.ts.map +1 -1
  60. package/dist/esm/Synapse.js +18 -0
  61. package/dist/esm/Synapse.js.map +1 -1
  62. package/dist/esm/abstracts/AbstractAction.d.ts +15 -0
  63. package/dist/esm/abstracts/AbstractAction.d.ts.map +1 -0
  64. package/dist/esm/abstracts/AbstractAction.js +21 -0
  65. package/dist/esm/abstracts/AbstractAction.js.map +1 -0
  66. package/dist/esm/abstracts/AbstractCondition.d.ts +15 -0
  67. package/dist/esm/abstracts/AbstractCondition.d.ts.map +1 -0
  68. package/dist/esm/abstracts/AbstractCondition.js +21 -0
  69. package/dist/esm/abstracts/AbstractCondition.js.map +1 -0
  70. package/dist/esm/contracts/explain.d.ts +9 -0
  71. package/dist/esm/contracts/explain.d.ts.map +1 -0
  72. package/dist/esm/contracts/explain.js +48 -0
  73. package/dist/esm/contracts/explain.js.map +1 -0
  74. package/dist/esm/contracts/validation.d.ts +40 -0
  75. package/dist/esm/contracts/validation.d.ts.map +1 -0
  76. package/dist/esm/contracts/validation.js +255 -0
  77. package/dist/esm/contracts/validation.js.map +1 -0
  78. package/dist/esm/index.d.ts +64 -0
  79. package/dist/esm/index.d.ts.map +1 -1
  80. package/dist/esm/index.js +50 -0
  81. package/dist/esm/index.js.map +1 -1
  82. package/dist/esm/interfaces/Action.d.ts +14 -0
  83. package/dist/esm/interfaces/Action.d.ts.map +1 -1
  84. package/dist/esm/interfaces/Condition.d.ts +21 -0
  85. package/dist/esm/interfaces/Condition.d.ts.map +1 -1
  86. package/dist/esm/interfaces/Element.d.ts +16 -0
  87. package/dist/esm/interfaces/Element.d.ts.map +1 -1
  88. package/dist/esm/interfaces/HookEvents.d.ts +16 -0
  89. package/dist/esm/interfaces/HookEvents.d.ts.map +1 -1
  90. package/dist/esm/interfaces/HookEvents.js +16 -0
  91. package/dist/esm/interfaces/HookEvents.js.map +1 -1
  92. package/dist/esm/interfaces/Parameter.d.ts +16 -0
  93. package/dist/esm/interfaces/Parameter.d.ts.map +1 -1
  94. package/dist/esm/interfaces/Rule.d.ts +23 -0
  95. package/dist/esm/interfaces/Rule.d.ts.map +1 -1
  96. package/dist/esm/interfaces/Script.d.ts +10 -0
  97. package/dist/esm/interfaces/Script.d.ts.map +1 -1
  98. package/dist/esm/runtime/ActionRuntime.js +1 -1
  99. package/dist/esm/runtime/ActionRuntime.js.map +1 -1
  100. package/dist/esm/runtime/ConditionRuntime.js +3 -3
  101. package/dist/esm/runtime/ConditionRuntime.js.map +1 -1
  102. package/dist/esm/runtime/RuleRuntime.js +1 -1
  103. package/dist/esm/runtime/RuleRuntime.js.map +1 -1
  104. package/dist/esm/types/ExecutionContext.d.ts +13 -0
  105. package/dist/esm/types/ExecutionContext.d.ts.map +1 -1
  106. package/dist/esm/types/ExecutionContext.js +3 -0
  107. package/dist/esm/types/ExecutionContext.js.map +1 -1
  108. package/dist/esm/types/ExecutionResult.d.ts +14 -0
  109. package/dist/esm/types/ExecutionResult.d.ts.map +1 -1
  110. package/dist/esm/types/ExecutionResult.js +14 -0
  111. package/dist/esm/types/ExecutionResult.js.map +1 -1
  112. package/dist/esm/types/HookEmitter.d.ts +8 -1
  113. package/dist/esm/types/HookEmitter.d.ts.map +1 -1
  114. package/examples/README.md +24 -0
  115. package/examples/eligibility-check/README.md +31 -0
  116. package/examples/eligibility-check/expected-output.json +7 -0
  117. package/examples/eligibility-check/input.json +6 -0
  118. package/examples/eligibility-check/rules.json +32 -0
  119. package/examples/eligibility-check/run.ts +128 -0
  120. package/examples/pricing-rules/README.md +31 -0
  121. package/examples/pricing-rules/expected-output.json +7 -0
  122. package/examples/pricing-rules/input.json +7 -0
  123. package/examples/pricing-rules/rules.json +32 -0
  124. package/examples/pricing-rules/run.ts +136 -0
  125. package/examples/workflow-routing/README.md +31 -0
  126. package/examples/workflow-routing/expected-output.json +7 -0
  127. package/examples/workflow-routing/input.json +6 -0
  128. package/examples/workflow-routing/rules.json +33 -0
  129. package/examples/workflow-routing/run.ts +130 -0
  130. package/package.json +31 -4
  131. package/schemas/execution-context.schema.json +23 -0
  132. package/schemas/execution-output.schema.json +16 -0
  133. package/schemas/explanation-trace.schema.json +32 -0
  134. package/schemas/script.schema.json +90 -0
  135. package/schemas/validation-error.schema.json +13 -0
  136. package/src/Synapse.ts +18 -0
  137. package/src/abstracts/AbstractAction.ts +34 -0
  138. package/src/abstracts/AbstractCondition.ts +34 -0
  139. package/src/contracts/explain.ts +66 -0
  140. package/src/contracts/validation.ts +348 -0
  141. package/src/index.ts +116 -0
  142. package/src/interfaces/Action.ts +14 -0
  143. package/src/interfaces/Condition.ts +23 -0
  144. package/src/interfaces/Element.ts +18 -0
  145. package/src/interfaces/HookEvents.ts +16 -0
  146. package/src/interfaces/Parameter.ts +18 -0
  147. package/src/interfaces/Rule.ts +24 -0
  148. package/src/interfaces/Script.ts +11 -0
  149. package/src/runtime/ActionRuntime.ts +1 -1
  150. package/src/runtime/ConditionRuntime.ts +3 -3
  151. package/src/runtime/RuleRuntime.ts +1 -1
  152. package/src/types/ExecutionContext.ts +13 -0
  153. package/src/types/ExecutionResult.ts +14 -0
  154. package/src/types/HookEmitter.ts +5 -0
  155. package/dist/commonjs/Synapse.test.d.ts +0 -2
  156. package/dist/commonjs/Synapse.test.d.ts.map +0 -1
  157. package/dist/commonjs/Synapse.test.js +0 -15
  158. package/dist/commonjs/Synapse.test.js.map +0 -1
  159. package/dist/commonjs/index.test.d.ts +0 -2
  160. package/dist/commonjs/index.test.d.ts.map +0 -1
  161. package/dist/commonjs/index.test.js +0 -132
  162. package/dist/commonjs/index.test.js.map +0 -1
  163. package/dist/commonjs/runtime/ConditionRuntime.test.d.ts +0 -2
  164. package/dist/commonjs/runtime/ConditionRuntime.test.d.ts.map +0 -1
  165. package/dist/commonjs/runtime/ConditionRuntime.test.js +0 -70
  166. package/dist/commonjs/runtime/ConditionRuntime.test.js.map +0 -1
  167. package/dist/esm/Synapse.test.d.ts +0 -2
  168. package/dist/esm/Synapse.test.d.ts.map +0 -1
  169. package/dist/esm/Synapse.test.js +0 -13
  170. package/dist/esm/Synapse.test.js.map +0 -1
  171. package/dist/esm/index.test.d.ts +0 -2
  172. package/dist/esm/index.test.d.ts.map +0 -1
  173. package/dist/esm/index.test.js +0 -130
  174. package/dist/esm/index.test.js.map +0 -1
  175. package/dist/esm/runtime/ConditionRuntime.test.d.ts +0 -2
  176. package/dist/esm/runtime/ConditionRuntime.test.d.ts.map +0 -1
  177. package/dist/esm/runtime/ConditionRuntime.test.js +0 -68
  178. package/dist/esm/runtime/ConditionRuntime.test.js.map +0 -1
package/README.md CHANGED
@@ -1,28 +1,52 @@
1
- ![neuron-cover640.png](docs/assets/neuron-cover640.png)
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
- > **A pluggable, serializable rules engine for functional programming rulesets.**
7
+ > **AI-friendly TypeScript rules engine for serializable JSON business rules and deterministic workflow decisions.**
6
8
 
7
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
10
  [![Socket Badge](https://badge.socket.dev/npm/package/@sebasoft/neuron-js)](https://socket.dev/npm/package/@sebasoft/neuron-js)
9
11
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D24.0.0-blue.svg)](https://nodejs.org)
10
12
  [![Build Status](https://github.com/SebaSOFT/neuron-js/actions/workflows/ci.yml/badge.svg)](https://github.com/SebaSOFT/neuron-js/actions)
11
13
 
12
- `neuron-js` is a lightweight, extensible rules engine designed to execute functional programming logic for other applications in a strictly serializable format. By modeling execution after biological systems—using **Neurons** as registries and **Synapses** as executors—it allows you to build, store, and run complex functional rulesets that remain pure JSON.
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
- Perfect for dynamic business rules, automation workflows, and cross-application decision logic.
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 Architecture**: Easily register custom Actions, Conditions, and Parameters.
21
- - 📦 **JSON Serializable**: Logic scripts are pure JSON, perfect for database storage or remote transmission.
22
- - 🧬 **Biological Analogy**: Intuitive execution model based on neurons, synapses, and rules.
23
- - **Modern Toolchain**: Built with Node 24, TypeScript, Biome, and Vitest.
24
- - 🌓 **Dual-Module Support**: Native ESM and CommonJS support via `tshy`.
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
- ### Basic Usage
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: 'hello-script',
72
+ id: 'pricing-decision',
53
73
  rules: [
54
74
  {
55
- id: 'rule-1',
75
+ id: 'vip-discount-rule',
56
76
  type: 'simple_rule',
57
77
  options: {},
58
78
  conditions: [
59
79
  {
60
- id: 'is-positive',
80
+ id: 'minimum-order-value',
61
81
  type: 'compare_two_numbers',
82
+ options: {},
62
83
  params: [
63
- { name: 'op1', type: 'simple_number', value: '10' },
64
- { name: 'comp', type: 'comparator', value: '>' },
65
- { name: 'op2', type: 'simple_number', value: '0' }
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: 'add-log',
92
+ id: 'calculate-discount',
72
93
  type: 'add_two_numbers',
94
+ options: {},
73
95
  params: [
74
- { name: 'op1', type: 'simple_number', value: '5' },
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 (number of rules executed)
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 (The Registry)
96
- The `Neuron` acts as the central hub where all element types (Actions, Conditions, Parameters, Rules) are registered. It ensures the runtime knows how to instantiate any element defined in your scripts.
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
- ### Synapse (The Executor)
99
- The `Synapse` is the engine that connects a `Neuron` registry to an `ExecutionScript`. It traverses the logic and manages the flow of the `ExecutionContext`.
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
- - **Action**: An operation to perform (e.g., "SendEmail", "UpdateDatabase").
103
- - **Condition**: A logical predicate (e.g., "UserIsAdmin", "ValueIsGreaterThanX").
104
- - **Parameter**: Configurable inputs for elements, enabling reusable logic templates.
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 throughout the entire execution of a script. It allows Actions and Conditions to communicate and share data.
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
- ### Using State in Actions
120
- Actions can read from the context and return an updated context to pass information to subsequent rules.
151
+ ---
121
152
 
122
- ```typescript
123
- // Example: An action that stores a value in the state
124
- execute(context: ExecutionContext): ExecutionResult {
125
- const newState = { ...context.state, lastCalculation: 42 };
126
- return new ExecutionResult(true, { ...context, state: newState });
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 performance and developer ergonomics:
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 for linting issues
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;IAEhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBADb,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,WAAW,YAAA;IAG7C,OAAO,CACL,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,gBAAgB,EACzB,kBAAkB,CAAC,EAAE,WAAW,GAC/B,eAAe,CAAC,MAAM,CAAC;CAsB3B"}
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"}
@@ -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;IAEC;IACA;IAFnB,YACmB,OAAe,EACf,YAA0B;QAD1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ,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,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AC,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,WA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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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