@bernierllc/nevar-types 0.0.1 → 0.1.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/.eslintrc.js +29 -0
- package/LICENSE +5 -0
- package/README.md +128 -43
- package/__tests__/errors.test.ts +189 -0
- package/__tests__/type-guards.test.ts +152 -0
- package/dist/actions.d.ts +71 -0
- package/dist/actions.js +9 -0
- package/dist/conditions.d.ts +24 -0
- package/dist/conditions.js +35 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +9 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +9 -0
- package/dist/errors.d.ts +59 -0
- package/dist/errors.js +95 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +23 -0
- package/dist/models.d.ts +56 -0
- package/dist/models.js +9 -0
- package/dist/operators.d.ts +24 -0
- package/dist/operators.js +9 -0
- package/dist/results.d.ts +79 -0
- package/dist/results.js +9 -0
- package/dist/storage.d.ts +100 -0
- package/dist/storage.js +9 -0
- package/dist/triggers.d.ts +11 -0
- package/dist/triggers.js +9 -0
- package/jest.config.cjs +29 -0
- package/package.json +35 -7
- package/proof-coverage.json +41 -0
- package/src/actions.ts +91 -0
- package/src/conditions.ts +55 -0
- package/src/config.ts +78 -0
- package/src/context.ts +16 -0
- package/src/errors.ts +102 -0
- package/src/index.ts +79 -0
- package/src/models.ts +68 -0
- package/src/operators.ts +33 -0
- package/src/results.ts +91 -0
- package/src/storage.ts +118 -0
- package/src/triggers.ts +19 -0
- package/tsconfig.json +22 -0
package/src/results.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Rule, EvaluationTrace } from './models';
|
|
10
|
+
import { ActionResult, ActionIntent } from './actions';
|
|
11
|
+
import { ExecutionLogEntry } from './storage';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The result of evaluating a single rule's conditions against a payload.
|
|
15
|
+
*/
|
|
16
|
+
export interface EvaluationResult {
|
|
17
|
+
matched: boolean;
|
|
18
|
+
trace: EvaluationTrace[];
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The result of emitting a trigger and executing matched rules.
|
|
24
|
+
*/
|
|
25
|
+
export interface EmitResult {
|
|
26
|
+
status: 'executed' | 'no_match' | 'loop_blocked' | 'circuit_tripped';
|
|
27
|
+
triggerKey: string;
|
|
28
|
+
groupId: string | null;
|
|
29
|
+
rulesEvaluated: number;
|
|
30
|
+
rulesMatched: number;
|
|
31
|
+
actionsExecuted: number;
|
|
32
|
+
actionResults: ActionResult[];
|
|
33
|
+
durationMs: number;
|
|
34
|
+
logs: ExecutionLogEntry[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The result of previewing a trigger without executing actions.
|
|
39
|
+
*/
|
|
40
|
+
export interface PreviewResult {
|
|
41
|
+
status: 'previewed' | 'no_match';
|
|
42
|
+
triggerKey: string;
|
|
43
|
+
groupId: string | null;
|
|
44
|
+
rulesEvaluated: number;
|
|
45
|
+
rulesMatched: number;
|
|
46
|
+
intents: ActionIntent[];
|
|
47
|
+
evaluationTraces: Array<{ rule: Rule; trace: EvaluationTrace[] }>;
|
|
48
|
+
durationMs: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A rule that matched during evaluation, along with its evaluation result.
|
|
53
|
+
*/
|
|
54
|
+
export interface MatchedRule {
|
|
55
|
+
rule: Rule;
|
|
56
|
+
evaluationResult: EvaluationResult;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A handle to a running evaluation loop (e.g., polling or streaming).
|
|
61
|
+
*/
|
|
62
|
+
export interface LoopHandle {
|
|
63
|
+
id: string;
|
|
64
|
+
stop?: () => void;
|
|
65
|
+
isRunning?: () => boolean;
|
|
66
|
+
triggerKey?: string;
|
|
67
|
+
status?: 'running' | 'paused' | 'killed' | 'completed' | string;
|
|
68
|
+
iterations?: number;
|
|
69
|
+
startedAt?: Date;
|
|
70
|
+
lastHeartbeat?: Date;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Analysis of a detected evaluation loop.
|
|
75
|
+
*/
|
|
76
|
+
export interface LoopAnalysis {
|
|
77
|
+
detected?: boolean;
|
|
78
|
+
hasLoops?: boolean;
|
|
79
|
+
loops: DetectedLoop[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A single detected loop in the evaluation chain.
|
|
84
|
+
*/
|
|
85
|
+
export interface DetectedLoop {
|
|
86
|
+
triggerKey?: string;
|
|
87
|
+
ruleIds: string[];
|
|
88
|
+
depth?: number;
|
|
89
|
+
chain?: string[];
|
|
90
|
+
allOptedIn?: boolean;
|
|
91
|
+
}
|
package/src/storage.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Rule, RuleGroup, LogLevel } from './models';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Filters for querying rule groups.
|
|
13
|
+
*/
|
|
14
|
+
export interface GroupFilters {
|
|
15
|
+
name?: string;
|
|
16
|
+
isActive?: boolean;
|
|
17
|
+
isDefault?: boolean;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Filters for querying rules.
|
|
23
|
+
*/
|
|
24
|
+
export interface RuleFilters {
|
|
25
|
+
groupId?: string;
|
|
26
|
+
triggerType?: string;
|
|
27
|
+
isActive?: boolean;
|
|
28
|
+
name?: string;
|
|
29
|
+
slug?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Filters for querying execution logs.
|
|
34
|
+
*/
|
|
35
|
+
export interface LogFilters {
|
|
36
|
+
triggerKey?: string;
|
|
37
|
+
groupId?: string;
|
|
38
|
+
ruleId?: string;
|
|
39
|
+
status?: string;
|
|
40
|
+
fromDate?: Date;
|
|
41
|
+
toDate?: Date;
|
|
42
|
+
from?: Date;
|
|
43
|
+
to?: Date;
|
|
44
|
+
page?: number;
|
|
45
|
+
pageSize?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A paginated result set.
|
|
50
|
+
*/
|
|
51
|
+
export interface PaginatedResult<T> {
|
|
52
|
+
items?: T[];
|
|
53
|
+
data?: T[];
|
|
54
|
+
total: number;
|
|
55
|
+
page: number;
|
|
56
|
+
pageSize: number;
|
|
57
|
+
totalPages?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A log entry recording the execution of a trigger.
|
|
62
|
+
*/
|
|
63
|
+
export interface ExecutionLogEntry {
|
|
64
|
+
id: string;
|
|
65
|
+
triggerKey: string;
|
|
66
|
+
triggerPayload?: Record<string, unknown>;
|
|
67
|
+
groupId: string | null;
|
|
68
|
+
ruleId: string | null;
|
|
69
|
+
ruleName?: string;
|
|
70
|
+
status: string;
|
|
71
|
+
logLevel?: LogLevel;
|
|
72
|
+
message?: string;
|
|
73
|
+
data?: Record<string, unknown>;
|
|
74
|
+
conditionsEvaluated?: Array<{
|
|
75
|
+
field?: string;
|
|
76
|
+
op?: string;
|
|
77
|
+
expected?: unknown;
|
|
78
|
+
actual?: unknown;
|
|
79
|
+
matched?: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
actionsExecuted?: import('./actions').ActionResult[];
|
|
82
|
+
errorMessage?: string;
|
|
83
|
+
durationMs: number;
|
|
84
|
+
timestamp: Date;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The storage adapter interface that all persistence backends must implement.
|
|
89
|
+
*/
|
|
90
|
+
export interface NevarStorageAdapter {
|
|
91
|
+
// Group operations
|
|
92
|
+
createGroup(group: Omit<RuleGroup, 'id'>): Promise<RuleGroup>;
|
|
93
|
+
updateGroup(id: string, patch: Partial<RuleGroup>): Promise<RuleGroup>;
|
|
94
|
+
deleteGroup(id: string): Promise<void>;
|
|
95
|
+
findGroup(id: string): Promise<RuleGroup | null>;
|
|
96
|
+
findDefaultGroup(): Promise<RuleGroup | null>;
|
|
97
|
+
findGroupForContext(metadata: Record<string, unknown>): Promise<RuleGroup | null>;
|
|
98
|
+
listGroups(filters?: GroupFilters): Promise<RuleGroup[]>;
|
|
99
|
+
|
|
100
|
+
// Rule operations
|
|
101
|
+
createRule(rule: Omit<Rule, 'id'>): Promise<Rule>;
|
|
102
|
+
updateRule(id: string, patch: Partial<Rule>): Promise<Rule>;
|
|
103
|
+
deleteRule(id: string): Promise<void>;
|
|
104
|
+
findRule(id: string): Promise<Rule | null>;
|
|
105
|
+
findActiveRules(groupId: string, triggerKey: string): Promise<Rule[]>;
|
|
106
|
+
listRules(filters?: RuleFilters): Promise<Rule[]>;
|
|
107
|
+
|
|
108
|
+
// Log operations
|
|
109
|
+
writeLog(entry: ExecutionLogEntry): Promise<void>;
|
|
110
|
+
queryLogs(filters: LogFilters): Promise<PaginatedResult<ExecutionLogEntry>>;
|
|
111
|
+
purgeLogs(olderThan: Date): Promise<number>;
|
|
112
|
+
|
|
113
|
+
// Bulk operations
|
|
114
|
+
transformRules(
|
|
115
|
+
filter: RuleFilters,
|
|
116
|
+
transform: (rule: Rule) => Rule
|
|
117
|
+
): Promise<{ updated: number; failed: Array<{ ruleId: string; error: string }> }>;
|
|
118
|
+
}
|
package/src/triggers.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Defines a trigger type that the engine listens for.
|
|
11
|
+
*/
|
|
12
|
+
export interface TriggerDefinition {
|
|
13
|
+
key: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
payloadSchema?: unknown;
|
|
17
|
+
schema?: Record<string, unknown>;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*"],
|
|
21
|
+
"exclude": ["node_modules", "dist", "__tests__"]
|
|
22
|
+
}
|