payid-types 0.1.7 → 0.1.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/rule.ts +51 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payid-types",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/rule.ts CHANGED
@@ -1,17 +1,66 @@
1
+ // ─── Primitive condition (shared across all rule formats) ───────────────────
2
+
1
3
  export interface RuleCondition {
2
4
  field: string;
3
5
  op: string;
6
+ /** Literal value OR cross-field reference prefixed with "$" (e.g. "$state.dailyLimit") */
4
7
  value: any;
5
8
  }
6
9
 
7
- export interface Rule {
10
+ // ─── Format A: single-condition rule ────────────────────────────────────────
11
+
12
+ export interface SimpleRule {
8
13
  id: string;
9
14
  if: RuleCondition;
15
+ message?: string;
16
+ }
17
+
18
+ // ─── Format B: multi-condition rule (AND / OR over conditions[]) ─────────────
19
+
20
+ export interface MultiConditionRule {
21
+ id: string;
22
+ logic: "AND" | "OR";
23
+ conditions: RuleCondition[];
24
+ message?: string;
25
+ }
26
+
27
+ // ─── Format C: nested rule (AND / OR over child rules) ──────────────────────
28
+
29
+ export interface NestedRule {
30
+ id: string;
31
+ logic: "AND" | "OR";
32
+ rules: AnyRule[];
33
+ message?: string;
34
+ }
35
+
36
+ /** Union of all supported rule formats */
37
+ export type AnyRule = SimpleRule | MultiConditionRule | NestedRule;
38
+
39
+ // ─── Type guards ─────────────────────────────────────────────────────────────
40
+
41
+ export function isSimpleRule(rule: AnyRule): rule is SimpleRule {
42
+ return "if" in rule;
10
43
  }
11
44
 
45
+ export function isMultiConditionRule(rule: AnyRule): rule is MultiConditionRule {
46
+ return "conditions" in rule;
47
+ }
48
+
49
+ export function isNestedRule(rule: AnyRule): rule is NestedRule {
50
+ return "rules" in rule;
51
+ }
52
+
53
+ // ─── Root rule config ────────────────────────────────────────────────────────
54
+
12
55
  export interface RuleConfig {
13
56
  version?: string;
14
57
  logic: "AND" | "OR";
15
- rules: Rule[];
58
+ rules: AnyRule[];
59
+ /** Optional list of required context namespaces (e.g. ["oracle", "risk"]) */
16
60
  requires?: string[];
61
+ message?: string;
17
62
  }
63
+
64
+ // ─── Backwards-compat alias (Rule was previously SimpleRule only) ────────────
65
+ /** @deprecated Use AnyRule instead */
66
+ export type Rule = AnyRule;