@infitx/decision 1.4.2 → 1.4.4

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 (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/index.d.ts +116 -0
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.4.4](https://github.com/infitx-org/release-cd/compare/decision-v1.4.3...decision-v1.4.4) (2026-03-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * update build workflow and add allure configuration files ([169bdb8](https://github.com/infitx-org/release-cd/commit/169bdb80a48041b40dcd2a54206c76bd2fe8d900))
9
+
10
+ ## [1.4.3](https://github.com/infitx-org/release-cd/compare/decision-v1.4.2...decision-v1.4.3) (2026-03-02)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * publish definitions ([b0534e0](https://github.com/infitx-org/release-cd/commit/b0534e05cf2fa5b9f7baee07c109bb3775dd38cd))
16
+
3
17
  ## [1.4.2](https://github.com/infitx-org/release-cd/compare/decision-v1.4.1...decision-v1.4.2) (2026-02-26)
4
18
 
5
19
 
package/index.d.ts ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Configuration for the decision engine
3
+ */
4
+ export interface DecisionConfig {
5
+ /**
6
+ * Rules configuration - can be an array or object with rule names as keys
7
+ */
8
+ rules?: Rule[] | Record<string, RuleDefinition>;
9
+
10
+ /**
11
+ * Additional configuration properties
12
+ */
13
+ [key: string]: any;
14
+ }
15
+
16
+ /**
17
+ * Rule definition structure
18
+ */
19
+ export interface RuleDefinition {
20
+ /**
21
+ * Optional priority for rule evaluation (higher priority evaluated first)
22
+ */
23
+ priority?: number | string;
24
+
25
+ /**
26
+ * Condition pattern that the fact must match
27
+ */
28
+ when: any;
29
+
30
+ /**
31
+ * Result to return when condition matches (can be object or function)
32
+ */
33
+ then: Record<string, any> | ((fact: any) => Record<string, any>);
34
+ }
35
+
36
+ /**
37
+ * Normalized rule structure used internally
38
+ */
39
+ export interface Rule extends RuleDefinition {
40
+ /**
41
+ * Rule identifier
42
+ */
43
+ rule: string | number;
44
+ }
45
+
46
+ /**
47
+ * Decision result structure
48
+ */
49
+ export interface Decision {
50
+ /**
51
+ * Name/identifier of the rule that matched
52
+ */
53
+ rule: string | number;
54
+
55
+ /**
56
+ * Decision key from the 'then' clause
57
+ */
58
+ decision: string;
59
+
60
+ /**
61
+ * Additional properties from the 'then' clause value
62
+ */
63
+ [key: string]: any;
64
+ }
65
+
66
+ /**
67
+ * Decision engine instance
68
+ */
69
+ export interface DecisionEngine extends DecisionConfig {
70
+ /**
71
+ * Normalized array of rules
72
+ */
73
+ rules: Rule[];
74
+
75
+ /**
76
+ * Evaluate a fact against configured rules
77
+ *
78
+ * @param fact - The fact object to evaluate
79
+ * @param all - If true, returns all matching rules; if false, returns first match
80
+ * @returns Array of decisions (empty array if no matches when all=true, null if no match when all=false)
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const engine = decision('./rules.yaml');
85
+ * const result = engine.decide({ type: 'transfer', amount: 500 });
86
+ * // Returns: [{ rule: 'approve-small', decision: 'approved', ...}]
87
+ * ```
88
+ */
89
+ decide(fact: any, all?: boolean): Decision[] | null;
90
+ }
91
+
92
+ /**
93
+ * Create a decision engine from a configuration file or object
94
+ *
95
+ * @param config - Path to YAML config file or configuration object
96
+ * @returns Decision engine instance with rules and decide function
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // From file
101
+ * const engine = decision('./rules.yaml');
102
+ *
103
+ * // From object
104
+ * const engine = decision({
105
+ * rules: {
106
+ * 'approve-small': {
107
+ * when: { amount: { max: 1000 } },
108
+ * then: { approved: true }
109
+ * }
110
+ * }
111
+ * });
112
+ *
113
+ * const result = engine.decide({ amount: 500 });
114
+ * ```
115
+ */
116
+ export default function decision(config: string | DecisionConfig): DecisionEngine;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@infitx/decision",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Decision tables engine",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "yaml": "^2.8.2",
8
- "@infitx/match": "1.5.2"
8
+ "@infitx/match": "1.5.4"
9
9
  },
10
10
  "devDependencies": {
11
11
  "allure": "^3.2.0",