@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
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the base interface for all elements within the rules engine.
|
|
3
|
+
* Elements are the building blocks of scripts, pulses, actions, conditions, and parameters.
|
|
4
|
+
*
|
|
5
|
+
* @template TOptions - The type of configuration options for this element.
|
|
6
|
+
*/
|
|
1
7
|
export interface ElementInterface<TOptions = any> {
|
|
8
|
+
/**
|
|
9
|
+
* Unique identifier for the element instance.
|
|
10
|
+
*/
|
|
2
11
|
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* The registered type name of the element.
|
|
14
|
+
* This type is used by the Registry (Neuron) to look up the correct implementation.
|
|
15
|
+
*/
|
|
3
16
|
type: string;
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options specific to this element instance.
|
|
19
|
+
*/
|
|
4
20
|
options: TOptions;
|
|
5
21
|
}
|
|
6
22
|
//# sourceMappingURL=Element.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Element.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Element.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,GAAG;IAC9C,EAAE,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Element.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Element.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,GAAG;IAC9C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;CACnB"}
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of all lifecycle events emitted during script execution.
|
|
3
|
+
* These can be used with a HookEmitter to monitor performance, log data, or handle side effects.
|
|
4
|
+
*/
|
|
1
5
|
export declare enum HookEvents {
|
|
6
|
+
/** Emitted when the execution of a script starts. */
|
|
2
7
|
ON_SCRIPT_START = "on_script_start",
|
|
8
|
+
/** Emitted when a specific rule begins evaluation. */
|
|
3
9
|
ON_RULE_START = "on_rule_start",
|
|
10
|
+
/** Emitted before a condition starts evaluation. */
|
|
4
11
|
ON_CONDITION_START = "pre_condition_start",
|
|
12
|
+
/** Emitted before an action starts execution. */
|
|
5
13
|
ON_ACTION_START = "pre_action_start",
|
|
14
|
+
/** Emitted when a script successfully completes all rules. */
|
|
6
15
|
ON_SCRIPT_END = "pre_script_end",
|
|
16
|
+
/** Emitted when a rule finishes evaluation (regardless of outcome). */
|
|
7
17
|
ON_RULE_END = "on_rule_end",
|
|
18
|
+
/** Emitted after a condition evaluation completes. */
|
|
8
19
|
ON_CONDITION_END = "pre_condition_end",
|
|
20
|
+
/** Emitted after an action execution completes. */
|
|
9
21
|
ON_ACTION_END = "pre_action_end",
|
|
22
|
+
/** Emitted if an unhandled error occurs during script execution. */
|
|
10
23
|
ON_SCRIPT_ERROR = "on_script_error",
|
|
24
|
+
/** Emitted if an error occurs while evaluating a specific rule. */
|
|
11
25
|
ON_RULE_ERROR = "on_rule_error",
|
|
26
|
+
/** Emitted if an error occurs during condition evaluation. */
|
|
12
27
|
ON_CONDITION_ERROR = "on_condition_error",
|
|
28
|
+
/** Emitted if an error occurs during action execution. */
|
|
13
29
|
ON_ACTION_ERROR = "on_action_error"
|
|
14
30
|
}
|
|
15
31
|
//# sourceMappingURL=HookEvents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HookEvents.d.ts","sourceRoot":"","sources":["../../../src/interfaces/HookEvents.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAC/B,kBAAkB,wBAAwB;IAC1C,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,WAAW,gBAAgB;IAC3B,gBAAgB,sBAAsB;IACtC,aAAa,mBAAmB;IAChC,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;CACpC"}
|
|
1
|
+
{"version":3,"file":"HookEvents.d.ts","sourceRoot":"","sources":["../../../src/interfaces/HookEvents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,UAAU;IACpB,qDAAqD;IACrD,eAAe,oBAAoB;IACnC,sDAAsD;IACtD,aAAa,kBAAkB;IAC/B,oDAAoD;IACpD,kBAAkB,wBAAwB;IAC1C,iDAAiD;IACjD,eAAe,qBAAqB;IACpC,8DAA8D;IAC9D,aAAa,mBAAmB;IAChC,uEAAuE;IACvE,WAAW,gBAAgB;IAC3B,sDAAsD;IACtD,gBAAgB,sBAAsB;IACtC,mDAAmD;IACnD,aAAa,mBAAmB;IAChC,oEAAoE;IACpE,eAAe,oBAAoB;IACnC,mEAAmE;IACnE,aAAa,kBAAkB;IAC/B,8DAA8D;IAC9D,kBAAkB,uBAAuB;IACzC,0DAA0D;IAC1D,eAAe,oBAAoB;CACpC"}
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of all lifecycle events emitted during script execution.
|
|
3
|
+
* These can be used with a HookEmitter to monitor performance, log data, or handle side effects.
|
|
4
|
+
*/
|
|
1
5
|
export var HookEvents;
|
|
2
6
|
(function (HookEvents) {
|
|
7
|
+
/** Emitted when the execution of a script starts. */
|
|
3
8
|
HookEvents["ON_SCRIPT_START"] = "on_script_start";
|
|
9
|
+
/** Emitted when a specific rule begins evaluation. */
|
|
4
10
|
HookEvents["ON_RULE_START"] = "on_rule_start";
|
|
11
|
+
/** Emitted before a condition starts evaluation. */
|
|
5
12
|
HookEvents["ON_CONDITION_START"] = "pre_condition_start";
|
|
13
|
+
/** Emitted before an action starts execution. */
|
|
6
14
|
HookEvents["ON_ACTION_START"] = "pre_action_start";
|
|
15
|
+
/** Emitted when a script successfully completes all rules. */
|
|
7
16
|
HookEvents["ON_SCRIPT_END"] = "pre_script_end";
|
|
17
|
+
/** Emitted when a rule finishes evaluation (regardless of outcome). */
|
|
8
18
|
HookEvents["ON_RULE_END"] = "on_rule_end";
|
|
19
|
+
/** Emitted after a condition evaluation completes. */
|
|
9
20
|
HookEvents["ON_CONDITION_END"] = "pre_condition_end";
|
|
21
|
+
/** Emitted after an action execution completes. */
|
|
10
22
|
HookEvents["ON_ACTION_END"] = "pre_action_end";
|
|
23
|
+
/** Emitted if an unhandled error occurs during script execution. */
|
|
11
24
|
HookEvents["ON_SCRIPT_ERROR"] = "on_script_error";
|
|
25
|
+
/** Emitted if an error occurs while evaluating a specific rule. */
|
|
12
26
|
HookEvents["ON_RULE_ERROR"] = "on_rule_error";
|
|
27
|
+
/** Emitted if an error occurs during condition evaluation. */
|
|
13
28
|
HookEvents["ON_CONDITION_ERROR"] = "on_condition_error";
|
|
29
|
+
/** Emitted if an error occurs during action execution. */
|
|
14
30
|
HookEvents["ON_ACTION_ERROR"] = "on_action_error";
|
|
15
31
|
})(HookEvents || (HookEvents = {}));
|
|
16
32
|
//# sourceMappingURL=HookEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HookEvents.js","sourceRoot":"","sources":["../../../src/interfaces/HookEvents.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"HookEvents.js","sourceRoot":"","sources":["../../../src/interfaces/HookEvents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAN,IAAY,UAyBX;AAzBD,WAAY,UAAU;IACpB,qDAAqD;IACrD,iDAAmC,CAAA;IACnC,sDAAsD;IACtD,6CAA+B,CAAA;IAC/B,oDAAoD;IACpD,wDAA0C,CAAA;IAC1C,iDAAiD;IACjD,kDAAoC,CAAA;IACpC,8DAA8D;IAC9D,8CAAgC,CAAA;IAChC,uEAAuE;IACvE,yCAA2B,CAAA;IAC3B,sDAAsD;IACtD,oDAAsC,CAAA;IACtC,mDAAmD;IACnD,8CAAgC,CAAA;IAChC,oEAAoE;IACpE,iDAAmC,CAAA;IACnC,mEAAmE;IACnE,6CAA+B,CAAA;IAC/B,8DAA8D;IAC9D,uDAAyC,CAAA;IACzC,0DAA0D;IAC1D,iDAAmC,CAAA;AACrC,CAAC,EAzBW,UAAU,KAAV,UAAU,QAyBrB"}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import type { ElementInterface } from "./Element.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a configurable input value for Actions and Conditions.
|
|
4
|
+
* Parameters allow for reusable logic templates by decoupling the implementation from the values.
|
|
5
|
+
*
|
|
6
|
+
* @template TValue - The primitive or complex type of the parameter's value.
|
|
7
|
+
* @template TOptions - The type of configuration options for this parameter.
|
|
8
|
+
*/
|
|
2
9
|
export interface ParameterInterface<TValue = any, TOptions = any> extends ElementInterface<TOptions> {
|
|
10
|
+
/**
|
|
11
|
+
* The semantic name of the parameter (e.g., "recipient", "threshold").
|
|
12
|
+
*/
|
|
3
13
|
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The actual value assigned to the parameter.
|
|
16
|
+
*/
|
|
4
17
|
value: TValue | null;
|
|
18
|
+
/**
|
|
19
|
+
* An optional fallback value if the primary value is missing or null.
|
|
20
|
+
*/
|
|
5
21
|
defaultValue?: TValue;
|
|
6
22
|
}
|
|
7
23
|
//# sourceMappingURL=Parameter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parameter.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Parameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,kBAAkB,CAAC,MAAM,GAAG,GAAG,EAAE,QAAQ,GAAG,GAAG,CAC9D,SAAQ,gBAAgB,CAAC,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Parameter.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Parameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB,CAAC,MAAM,GAAG,GAAG,EAAE,QAAQ,GAAG,GAAG,CAC9D,SAAQ,gBAAgB,CAAC,QAAQ,CAAC;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import type { ActionInterface } from "./Action.js";
|
|
2
2
|
import type { ConditionInterface } from "./Condition.js";
|
|
3
3
|
import type { ElementInterface } from "./Element.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for a Rule.
|
|
6
|
+
*/
|
|
4
7
|
export interface RuleOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the rule is disabled and should be skipped.
|
|
10
|
+
*/
|
|
5
11
|
disabled?: boolean;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a logical unit containing conditions and actions.
|
|
15
|
+
* A Rule executes its actions only if its conditions evaluate to true.
|
|
16
|
+
*
|
|
17
|
+
* - **Empty Conditions**: The rule is considered "Always" and will automatically execute actions.
|
|
18
|
+
* - **Empty Actions**: The rule will "Do Nothing" (no side effects).
|
|
19
|
+
*
|
|
20
|
+
* @template TOptions - The type of configuration options for this rule.
|
|
21
|
+
*/
|
|
7
22
|
export interface RuleInterface<TOptions extends RuleOptions = RuleOptions> extends ElementInterface<TOptions> {
|
|
23
|
+
/**
|
|
24
|
+
* List of conditions that must be satisfied for the actions to execute.
|
|
25
|
+
* If empty, actions are always executed.
|
|
26
|
+
*/
|
|
8
27
|
conditions: ConditionInterface[];
|
|
28
|
+
/**
|
|
29
|
+
* List of actions to perform if the conditions are met.
|
|
30
|
+
* If empty, the rule has no side effects.
|
|
31
|
+
*/
|
|
9
32
|
actions: ActionInterface[];
|
|
10
33
|
}
|
|
11
34
|
//# sourceMappingURL=Rule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rule.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,gBAAgB,CAAC,QAAQ,CAAC;IAClC,UAAU,EAAE,kBAAkB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Rule.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,gBAAgB,CAAC,QAAQ,CAAC;IAClC;;;OAGG;IACH,UAAU,EAAE,kBAAkB,EAAE,CAAC;IAEjC;;;OAGG;IACH,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B"}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import type { RuleInterface } from "./Rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a complete set of rules to be executed by the engine.
|
|
4
|
+
* The script is the top-level serializable container for all logic.
|
|
5
|
+
*/
|
|
2
6
|
export interface ScriptInterface {
|
|
7
|
+
/**
|
|
8
|
+
* Unique identifier for the script.
|
|
9
|
+
*/
|
|
3
10
|
id: string;
|
|
11
|
+
/**
|
|
12
|
+
* The ordered list of rules that comprise the script's logic.
|
|
13
|
+
*/
|
|
4
14
|
rules: RuleInterface[];
|
|
5
15
|
}
|
|
6
16
|
//# sourceMappingURL=Script.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Script.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Script.d.ts","sourceRoot":"","sources":["../../../src/interfaces/Script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB"}
|
|
@@ -14,7 +14,7 @@ export class ActionRuntime {
|
|
|
14
14
|
let currentContext = context;
|
|
15
15
|
let actionsExecuted = 0;
|
|
16
16
|
for (const actionItem of this._actions) {
|
|
17
|
-
if (actionItem.options
|
|
17
|
+
if (actionItem.options?.disabled) {
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
this._hookEmitter?.(HookEvents.ON_ACTION_START, currentContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRuntime.js","sourceRoot":"","sources":["../../../src/runtime/ActionRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,MAAM,OAAO,aAAa;IAEL;IACA;IACA;IAHnB,YACmB,QAA2B,EAC3B,OAAe,EACf,YAA0B;QAF1B,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,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AAC,UAAU,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;gBAChE,OAAO,IAAI,eAAe,CACxB,KAAK,EACL,cAAc,EACd,eAAe,EACf,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,MAAM,cAAc,GAAG,IAAI,UAAU,CACnC,UAAU,CAAC,EAAE,EACb,UAAU,CAAC,IAAI,EACf,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,OAAO,EAClB,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;YAC5D,WAAW,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YAE3C,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,EAAE,CAAC;gBACjC,IAAI,CAAC,YAAY,EAAE,CAAC,UAAU,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;gBAChE,OAAO,IAAI,eAAe,CACxB,KAAK,EACL,cAAc,EACd,eAAe,EACf,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC;YACtC,eAAe,EAAE,CAAC;YAClB,WAAW,CAAC,IAAI,CAAC,iBAAiB,UAAU,CAAC,EAAE,yBAAyB,CAAC,CAAC;YAC1E,IAAI,CAAC,YAAY,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,IAAI,eAAe,CACxB,IAAI,EACJ,cAAc,EACd,eAAe,EACf,WAAW,CACZ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -17,11 +17,11 @@ export class ConditionRuntime {
|
|
|
17
17
|
const orGroups = [[]];
|
|
18
18
|
let groupIndex = 0;
|
|
19
19
|
for (const conditionItem of this._conditions) {
|
|
20
|
-
if (conditionItem.options
|
|
20
|
+
if (conditionItem.options?.disabled) {
|
|
21
21
|
continue;
|
|
22
22
|
}
|
|
23
23
|
this._hookEmitter?.(HookEvents.ON_CONDITION_START, context);
|
|
24
|
-
if (conditionItem.options
|
|
24
|
+
if (conditionItem.options?.orCondition &&
|
|
25
25
|
orGroups[groupIndex].length > 0) {
|
|
26
26
|
groupIndex++;
|
|
27
27
|
orGroups[groupIndex] = [];
|
|
@@ -39,7 +39,7 @@ export class ConditionRuntime {
|
|
|
39
39
|
this._hookEmitter?.(HookEvents.ON_CONDITION_ERROR, context);
|
|
40
40
|
return new ExecutionResult(false, context, false, messageList);
|
|
41
41
|
}
|
|
42
|
-
const verdict = conditionItem.options
|
|
42
|
+
const verdict = conditionItem.options?.inverted
|
|
43
43
|
? !conditionResult.value
|
|
44
44
|
: !!conditionResult.value;
|
|
45
45
|
orGroups[groupIndex].push(verdict);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionRuntime.js","sourceRoot":"","sources":["../../../src/runtime/ConditionRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,MAAM,OAAO,gBAAgB;IAER;IACA;IACA;IAHnB,YACmB,WAAiC,EACjC,OAAe,EACf,YAA0B;QAF1B,gBAAW,GAAX,WAAW,CAAsB;QACjC,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ,OAAO,CAAC,OAAyB;QAC/B,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,MAAM,QAAQ,GAAgB,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,aAAa,IAAI,IAAI,CAAC,WAAW,EAAE,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,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CACrD,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -16,7 +16,7 @@ export class RuleRuntime {
|
|
|
16
16
|
let currentContext = context;
|
|
17
17
|
let rulesExecuted = 0;
|
|
18
18
|
for (const ruleItem of this._rules) {
|
|
19
|
-
if (ruleItem.options
|
|
19
|
+
if (ruleItem.options?.disabled) {
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
22
|
const RuleCtor = this._neuron.getRule(ruleItem.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleRuntime.js","sourceRoot":"","sources":["../../../src/runtime/RuleRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,OAAO,WAAW;IAEH;IACA;IACA;IAHnB,YACmB,MAAuB,EACvB,OAAe,EACf,YAA0B;QAF1B,WAAM,GAAN,MAAM,CAAiB;QACvB,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ,OAAO,CAAC,OAAyB;QAC/B,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,IAAI,cAAc,GAAG,OAAO,CAAC;QAC7B,IAAI,aAAa,GAAG,CAAC,CAAC;QAEtB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,QAAQ,CAAC,OAAO,
|
|
1
|
+
{"version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AAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,IAAI,eAAe,CACxB,IAAI,EACJ,cAAc,EACd,aAAa,EACb,WAAW,CACZ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity levels for execution messages.
|
|
3
|
+
*/
|
|
1
4
|
export declare enum MessageType {
|
|
2
5
|
DEBUG = "debug",
|
|
3
6
|
INFO = "info",
|
|
4
7
|
WARN = "warn",
|
|
5
8
|
ERROR = "error"
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Represents a log message or audit entry generated during execution.
|
|
12
|
+
*/
|
|
7
13
|
export interface ExecutionMessage {
|
|
14
|
+
/** The severity level of the message. */
|
|
8
15
|
type: MessageType;
|
|
16
|
+
/** The descriptive text of the message. */
|
|
9
17
|
text: string;
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The shared state container that travels through the execution engine.
|
|
21
|
+
*/
|
|
11
22
|
export interface ExecutionContext {
|
|
23
|
+
/** Accumulation of all messages generated during the current script run. */
|
|
12
24
|
messages: ExecutionMessage[];
|
|
25
|
+
/** The primary data object being processed and mutated by actions. */
|
|
13
26
|
state: Record<string, any>;
|
|
14
27
|
}
|
|
15
28
|
//# sourceMappingURL=ExecutionContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/types/ExecutionContext.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B"}
|
|
1
|
+
{"version":3,"file":"ExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/types/ExecutionContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,IAAI,EAAE,WAAW,CAAC;IAClB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionContext.js","sourceRoot":"","sources":["../../../src/types/ExecutionContext.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,4BAAa,CAAA;IACb,4BAAa,CAAA;IACb,8BAAe,CAAA;AACjB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB"}
|
|
1
|
+
{"version":3,"file":"ExecutionContext.js","sourceRoot":"","sources":["../../../src/types/ExecutionContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,4BAAa,CAAA;IACb,4BAAa,CAAA;IACb,8BAAe,CAAA;AACjB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import type { ExecutionContext } from "./ExecutionContext.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the outcome of an execution unit (Script, Rule, Action, or Condition).
|
|
4
|
+
*
|
|
5
|
+
* @template TValue - The type of the value produced by the execution (e.g., number of rules for a Script, boolean for a Condition).
|
|
6
|
+
*/
|
|
2
7
|
export declare class ExecutionResult<TValue = any> {
|
|
3
8
|
readonly success: boolean;
|
|
4
9
|
readonly context: ExecutionContext;
|
|
5
10
|
readonly value: TValue | null;
|
|
6
11
|
readonly messages: string[];
|
|
12
|
+
/**
|
|
13
|
+
* @param success - Whether the execution completed without errors.
|
|
14
|
+
* @param context - The state of the ExecutionContext after the run.
|
|
15
|
+
* @param value - The primary output of the execution.
|
|
16
|
+
* @param messages - Any informational or error messages generated.
|
|
17
|
+
*/
|
|
7
18
|
constructor(success: boolean, context: ExecutionContext, value?: TValue | null, messages?: string[]);
|
|
19
|
+
/**
|
|
20
|
+
* Helper to check if the execution was successful.
|
|
21
|
+
*/
|
|
8
22
|
isSuccessful(): boolean;
|
|
9
23
|
}
|
|
10
24
|
//# sourceMappingURL=ExecutionResult.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionResult.d.ts","sourceRoot":"","sources":["../../../src/types/ExecutionResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,qBAAa,eAAe,CAAC,MAAM,GAAG,GAAG;
|
|
1
|
+
{"version":3,"file":"ExecutionResult.d.ts","sourceRoot":"","sources":["../../../src/types/ExecutionResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;GAIG;AACH,qBAAa,eAAe,CAAC,MAAM,GAAG,GAAG;aAQrB,OAAO,EAAE,OAAO;aAChB,OAAO,EAAE,gBAAgB;aACzB,KAAK,EAAE,MAAM,GAAG,IAAI;aACpB,QAAQ,EAAE,MAAM,EAAE;IAVpC;;;;;OAKG;gBAEe,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,gBAAgB,EACzB,KAAK,GAAE,MAAM,GAAG,IAAW,EAC3B,QAAQ,GAAE,MAAM,EAAO;IAGzC;;OAEG;IACH,YAAY,IAAI,OAAO;CAGxB"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the outcome of an execution unit (Script, Rule, Action, or Condition).
|
|
3
|
+
*
|
|
4
|
+
* @template TValue - The type of the value produced by the execution (e.g., number of rules for a Script, boolean for a Condition).
|
|
5
|
+
*/
|
|
1
6
|
export class ExecutionResult {
|
|
2
7
|
success;
|
|
3
8
|
context;
|
|
4
9
|
value;
|
|
5
10
|
messages;
|
|
11
|
+
/**
|
|
12
|
+
* @param success - Whether the execution completed without errors.
|
|
13
|
+
* @param context - The state of the ExecutionContext after the run.
|
|
14
|
+
* @param value - The primary output of the execution.
|
|
15
|
+
* @param messages - Any informational or error messages generated.
|
|
16
|
+
*/
|
|
6
17
|
constructor(success, context, value = null, messages = []) {
|
|
7
18
|
this.success = success;
|
|
8
19
|
this.context = context;
|
|
9
20
|
this.value = value;
|
|
10
21
|
this.messages = messages;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Helper to check if the execution was successful.
|
|
25
|
+
*/
|
|
12
26
|
isSuccessful() {
|
|
13
27
|
return this.success;
|
|
14
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionResult.js","sourceRoot":"","sources":["../../../src/types/ExecutionResult.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"ExecutionResult.js","sourceRoot":"","sources":["../../../src/types/ExecutionResult.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAQR;IACA;IACA;IACA;IAVlB;;;;;OAKG;IACH,YACkB,OAAgB,EAChB,OAAyB,EACzB,QAAuB,IAAI,EAC3B,WAAqB,EAAE;QAHvB,YAAO,GAAP,OAAO,CAAS;QAChB,YAAO,GAAP,OAAO,CAAkB;QACzB,UAAK,GAAL,KAAK,CAAsB;QAC3B,aAAQ,GAAR,QAAQ,CAAe;IACtC,CAAC;IAEJ;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { HookEvents } from "../interfaces/HookEvents.js";
|
|
2
2
|
import type { ExecutionContext } from "../types/ExecutionContext.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Functional type for lifecycle hook callbacks.
|
|
5
|
+
*/
|
|
6
|
+
export type HookEmitter = (
|
|
7
|
+
/** The lifecycle event being triggered. */
|
|
8
|
+
event: HookEvents,
|
|
9
|
+
/** The current state of the execution context. */
|
|
10
|
+
context: ExecutionContext) => void;
|
|
4
11
|
//# sourceMappingURL=HookEmitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HookEmitter.d.ts","sourceRoot":"","sources":["../../../src/types/HookEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"HookEmitter.d.ts","sourceRoot":"","sources":["../../../src/types/HookEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;AACxB,2CAA2C;AAC3C,KAAK,EAAE,UAAU;AACjB,kDAAkD;AAClD,OAAO,EAAE,gBAAgB,KACtB,IAAI,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Runnable Examples
|
|
2
|
+
|
|
3
|
+
These examples are copy-paste friendly Neuron-JS scenarios. Each folder contains a serializable `rules.json`, an `input.json` execution context, an `expected-output.json` contract, and a `run.ts` file that executes and verifies the scenario.
|
|
4
|
+
|
|
5
|
+
## Available examples
|
|
6
|
+
|
|
7
|
+
- [Pricing rules](pricing-rules/) — apply a VIP discount when a cart meets a subtotal threshold.
|
|
8
|
+
- [Eligibility check](eligibility-check/) — approve an applicant when a score crosses a threshold.
|
|
9
|
+
- [Workflow routing](workflow-routing/) — route a high-priority support ticket to an escalation lane.
|
|
10
|
+
|
|
11
|
+
## Run all examples
|
|
12
|
+
|
|
13
|
+
From the repository root:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn examples
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or run one example directly after building:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn build
|
|
23
|
+
node examples/pricing-rules/run.ts
|
|
24
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Eligibility Check Example
|
|
2
|
+
|
|
3
|
+
Run an eligibility decision from JSON. The rule checks whether an applicant score passes the required threshold, then writes the approved status into the execution context.
|
|
4
|
+
|
|
5
|
+
## Run
|
|
6
|
+
|
|
7
|
+
From the repository root:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn build
|
|
11
|
+
node examples/eligibility-check/run.ts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Expected summary:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"ok": true,
|
|
19
|
+
"rulesExecuted": 1,
|
|
20
|
+
"eligible": true,
|
|
21
|
+
"decision": "approved",
|
|
22
|
+
"messages": ["Eligibility decision: approved"]
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Files
|
|
27
|
+
|
|
28
|
+
- `rules.json` — the serializable Neuron-JS script.
|
|
29
|
+
- `input.json` — the execution context used by the script.
|
|
30
|
+
- `expected-output.json` — the checked output summary.
|
|
31
|
+
- `run.ts` — registers the example vocabulary, executes the script, and fails if output differs.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "eligibility-check-demo",
|
|
3
|
+
"rules": [
|
|
4
|
+
{
|
|
5
|
+
"id": "approve-qualified-applicant",
|
|
6
|
+
"type": "simple_rule",
|
|
7
|
+
"options": {},
|
|
8
|
+
"conditions": [
|
|
9
|
+
{
|
|
10
|
+
"id": "score-threshold",
|
|
11
|
+
"type": "compare_two_numbers",
|
|
12
|
+
"options": {},
|
|
13
|
+
"params": [
|
|
14
|
+
{ "id": "applicant-score", "name": "op1", "type": "state_number", "value": "applicant.score", "options": {} },
|
|
15
|
+
{ "id": "comparison", "name": "comp", "type": "comparator", "value": ">=", "options": {} },
|
|
16
|
+
{ "id": "required-score", "name": "op2", "type": "simple_number", "value": "700", "options": {} }
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"actions": [
|
|
21
|
+
{
|
|
22
|
+
"id": "mark-approved",
|
|
23
|
+
"type": "set_decision",
|
|
24
|
+
"options": {},
|
|
25
|
+
"params": [
|
|
26
|
+
{ "id": "decision-value", "name": "decision", "type": "simple_string", "value": "approved", "options": {} }
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|