@f-o-t/rules-engine 2.0.2 → 3.0.1

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/dist/index.d.cts DELETED
@@ -1,1173 +0,0 @@
1
- import { ArrayCondition, ArrayOperator, BooleanCondition, BooleanOperator, Condition as Condition2, ConditionGroup as ConditionGroup6, CustomCondition, DateCondition, DateOperator, EvaluationResult, GroupEvaluationResult as GroupEvaluationResult2, LogicalOperator, NumberCondition, NumberOperator, StringCondition, StringOperator } from "@f-o-t/condition-evaluator";
2
- import { ConditionGroup as ConditionGroup7, isConditionGroup } from "@f-o-t/condition-evaluator";
3
- import { z } from "zod";
4
- type ConsequenceDefinitions = Record<string, z.ZodType>;
5
- type DefaultConsequences = Record<string, z.ZodType>;
6
- type InferConsequenceType<T extends ConsequenceDefinitions> = keyof T;
7
- type InferConsequencePayload<
8
- T extends ConsequenceDefinitions,
9
- K extends keyof T
10
- > = z.infer<T[K]>;
11
- type Consequence<
12
- TConsequences extends ConsequenceDefinitions = DefaultConsequences,
13
- TType extends keyof TConsequences = keyof TConsequences
14
- > = {
15
- readonly type: TType;
16
- readonly payload: z.infer<TConsequences[TType]>;
17
- };
18
- type ConsequenceInput<
19
- TConsequences extends ConsequenceDefinitions = DefaultConsequences,
20
- TType extends keyof TConsequences = keyof TConsequences
21
- > = {
22
- type: TType;
23
- payload: z.infer<TConsequences[TType]>;
24
- };
25
- type AggregatedConsequence<TConsequences extends ConsequenceDefinitions = DefaultConsequences> = {
26
- readonly type: keyof TConsequences;
27
- readonly payload: unknown;
28
- readonly ruleId: string;
29
- readonly ruleName?: string;
30
- readonly priority: number;
31
- };
32
- import { ConditionGroup } from "@f-o-t/condition-evaluator";
33
- import { z as z2 } from "zod";
34
- type Rule<
35
- _TContext = unknown,
36
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
37
- > = {
38
- readonly id: string;
39
- readonly name: string;
40
- readonly description?: string;
41
- readonly conditions: ConditionGroup;
42
- readonly consequences: ReadonlyArray<Consequence<TConsequences>>;
43
- readonly priority: number;
44
- readonly enabled: boolean;
45
- readonly stopOnMatch: boolean;
46
- readonly tags: ReadonlyArray<string>;
47
- readonly category?: string;
48
- readonly metadata?: Readonly<Record<string, unknown>>;
49
- readonly createdAt: Date;
50
- readonly updatedAt: Date;
51
- };
52
- type RuleInput<
53
- _TContext = unknown,
54
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
55
- > = {
56
- id?: string;
57
- name: string;
58
- description?: string;
59
- conditions: ConditionGroup;
60
- consequences: Array<{
61
- type: keyof TConsequences;
62
- payload: z2.infer<TConsequences[keyof TConsequences]>;
63
- }>;
64
- priority?: number;
65
- enabled?: boolean;
66
- stopOnMatch?: boolean;
67
- tags?: string[];
68
- category?: string;
69
- metadata?: Record<string, unknown>;
70
- };
71
- type RuleSet = {
72
- readonly id: string;
73
- readonly name: string;
74
- readonly description?: string;
75
- readonly ruleIds: ReadonlyArray<string>;
76
- readonly enabled: boolean;
77
- readonly metadata?: Readonly<Record<string, unknown>>;
78
- };
79
- type RuleSetInput = {
80
- id?: string;
81
- name: string;
82
- description?: string;
83
- ruleIds: string[];
84
- enabled?: boolean;
85
- metadata?: Record<string, unknown>;
86
- };
87
- type RuleFilters = {
88
- readonly enabled?: boolean;
89
- readonly tags?: ReadonlyArray<string>;
90
- readonly category?: string;
91
- readonly ruleSetId?: string;
92
- readonly ids?: ReadonlyArray<string>;
93
- };
94
- declare const RuleSchema: any;
95
- declare const RuleSetSchema: any;
96
- type RuleSchemaType = z2.infer<typeof RuleSchema>;
97
- type RuleSetSchemaType = z2.infer<typeof RuleSetSchema>;
98
- type RuleComplexity = {
99
- readonly ruleId: string;
100
- readonly ruleName: string;
101
- readonly totalConditions: number;
102
- readonly maxDepth: number;
103
- readonly groupCount: number;
104
- readonly uniqueFields: number;
105
- readonly uniqueOperators: number;
106
- readonly consequenceCount: number;
107
- readonly complexityScore: number;
108
- };
109
- type RuleSetAnalysis = {
110
- readonly ruleCount: number;
111
- readonly enabledCount: number;
112
- readonly disabledCount: number;
113
- readonly totalConditions: number;
114
- readonly totalConsequences: number;
115
- readonly uniqueFields: ReadonlyArray<string>;
116
- readonly uniqueOperators: ReadonlyArray<string>;
117
- readonly uniqueConsequenceTypes: ReadonlyArray<string>;
118
- readonly uniqueCategories: ReadonlyArray<string>;
119
- readonly uniqueTags: ReadonlyArray<string>;
120
- readonly priorityRange: {
121
- min: number;
122
- max: number;
123
- };
124
- readonly averageComplexity: number;
125
- readonly complexityDistribution: {
126
- readonly low: number;
127
- readonly medium: number;
128
- readonly high: number;
129
- };
130
- readonly ruleComplexities: ReadonlyArray<RuleComplexity>;
131
- };
132
- type FieldUsage = {
133
- readonly field: string;
134
- readonly count: number;
135
- readonly types: ReadonlyArray<string>;
136
- readonly operators: ReadonlyArray<string>;
137
- readonly rules: ReadonlyArray<{
138
- id: string;
139
- name: string;
140
- }>;
141
- };
142
- type OperatorUsage = {
143
- readonly operator: string;
144
- readonly type: string;
145
- readonly count: number;
146
- readonly rules: ReadonlyArray<{
147
- id: string;
148
- name: string;
149
- }>;
150
- };
151
- type ConsequenceUsage = {
152
- readonly type: string;
153
- readonly count: number;
154
- readonly rules: ReadonlyArray<{
155
- id: string;
156
- name: string;
157
- }>;
158
- };
159
- declare const analyzeRuleComplexity: <
160
- TContext = unknown,
161
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
162
- >(rule: Rule<TContext, TConsequences>) => RuleComplexity;
163
- declare const analyzeRuleSet: <
164
- TContext = unknown,
165
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
166
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => RuleSetAnalysis;
167
- declare const analyzeFieldUsage: <
168
- TContext = unknown,
169
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
170
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<FieldUsage>;
171
- declare const analyzeOperatorUsage: <
172
- TContext = unknown,
173
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
174
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<OperatorUsage>;
175
- declare const analyzeConsequenceUsage: <
176
- TContext = unknown,
177
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
178
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<ConsequenceUsage>;
179
- declare const findMostComplexRules: <
180
- TContext = unknown,
181
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
182
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, limit?: number) => ReadonlyArray<RuleComplexity>;
183
- declare const findLeastUsedFields: <
184
- TContext = unknown,
185
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
186
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, limit?: number) => ReadonlyArray<FieldUsage>;
187
- declare const formatRuleSetAnalysis: (analysis: RuleSetAnalysis) => string;
188
- import { Condition, ConditionGroup as ConditionGroup2 } from "@f-o-t/condition-evaluator";
189
- type ConditionBuilderState = {
190
- readonly conditions: (Condition | ConditionGroup2)[];
191
- };
192
- type ConditionBuilder = {
193
- readonly number: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq", value: number) => ConditionBuilder;
194
- readonly string: (field: string, operator: "eq" | "neq" | "contains" | "not_contains" | "starts_with" | "ends_with" | "in" | "not_in" | "like" | "not_like" | "ilike" | "not_ilike" | "regex" | "not_regex", value: string | string[]) => ConditionBuilder;
195
- readonly boolean: (field: string, operator: "eq" | "neq", value: boolean) => ConditionBuilder;
196
- readonly date: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq" | "between", value: string | Date | [string | Date, string | Date]) => ConditionBuilder;
197
- readonly array: (field: string, operator: "contains" | "not_contains" | "contains_all" | "contains_any" | "is_empty" | "is_not_empty" | "length_eq" | "length_gt" | "length_lt", value: unknown) => ConditionBuilder;
198
- readonly ref: (field: string, operator: string, valueRef: string) => ConditionBuilder;
199
- readonly and: (builder: (cb: ConditionBuilder) => ConditionBuilder) => ConditionBuilder;
200
- readonly or: (builder: (cb: ConditionBuilder) => ConditionBuilder) => ConditionBuilder;
201
- readonly raw: (condition: Condition | ConditionGroup2) => ConditionBuilder;
202
- readonly build: () => ConditionGroup2;
203
- readonly getConditions: () => ReadonlyArray<Condition | ConditionGroup2>;
204
- };
205
- declare const resetBuilderIds: () => void;
206
- declare const conditions: () => ConditionBuilder;
207
- declare const and: (builderFn: (cb: ConditionBuilder) => ConditionBuilder) => ConditionGroup2;
208
- declare const or: (builderFn: (cb: ConditionBuilder) => ConditionBuilder) => ConditionGroup2;
209
- declare const all: (...items: (Condition | ConditionGroup2)[]) => ConditionGroup2;
210
- declare const any: (...items: (Condition | ConditionGroup2)[]) => ConditionGroup2;
211
- declare const num: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq", value: number) => Condition;
212
- declare const str: (field: string, operator: "eq" | "neq" | "contains" | "not_contains" | "starts_with" | "ends_with" | "in" | "not_in" | "like" | "not_like" | "ilike" | "not_ilike" | "regex" | "not_regex", value: string | string[]) => Condition;
213
- declare const bool: (field: string, operator: "eq" | "neq", value: boolean) => Condition;
214
- declare const date: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq" | "between", value: string | Date | [string | Date, string | Date]) => Condition;
215
- declare const arr: (field: string, operator: "contains" | "not_contains" | "contains_all" | "contains_any" | "is_empty" | "is_not_empty" | "length_eq" | "length_gt" | "length_lt", value?: unknown) => Condition;
216
- import { ConditionGroup as ConditionGroup3 } from "@f-o-t/condition-evaluator";
217
- import { z as z3 } from "zod";
218
- type RuleBuilderState<
219
- _TContext = unknown,
220
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
221
- > = {
222
- readonly id?: string;
223
- readonly name?: string;
224
- readonly description?: string;
225
- readonly conditions?: ConditionGroup3;
226
- readonly consequences: Array<{
227
- type: keyof TConsequences;
228
- payload: z3.infer<TConsequences[keyof TConsequences]>;
229
- }>;
230
- readonly priority: number;
231
- readonly enabled: boolean;
232
- readonly stopOnMatch: boolean;
233
- readonly tags: string[];
234
- readonly category?: string;
235
- readonly metadata?: Record<string, unknown>;
236
- };
237
- type RuleBuilder<
238
- TContext = unknown,
239
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
240
- > = {
241
- readonly id: (id: string) => RuleBuilder<TContext, TConsequences>;
242
- readonly named: (name: string) => RuleBuilder<TContext, TConsequences>;
243
- readonly describedAs: (description: string) => RuleBuilder<TContext, TConsequences>;
244
- readonly when: (conditions: ConditionGroup3 | ((cb: ConditionBuilder) => ConditionBuilder)) => RuleBuilder<TContext, TConsequences>;
245
- readonly then: <K extends keyof TConsequences>(type: K, payload: z3.infer<TConsequences[K]>) => RuleBuilder<TContext, TConsequences>;
246
- readonly withPriority: (priority: number) => RuleBuilder<TContext, TConsequences>;
247
- readonly enabled: (enabled?: boolean) => RuleBuilder<TContext, TConsequences>;
248
- readonly disabled: () => RuleBuilder<TContext, TConsequences>;
249
- readonly stopOnMatch: (stop?: boolean) => RuleBuilder<TContext, TConsequences>;
250
- readonly tagged: (...tags: string[]) => RuleBuilder<TContext, TConsequences>;
251
- readonly inCategory: (category: string) => RuleBuilder<TContext, TConsequences>;
252
- readonly withMetadata: (metadata: Record<string, unknown>) => RuleBuilder<TContext, TConsequences>;
253
- readonly build: () => RuleInput<TContext, TConsequences>;
254
- readonly getState: () => RuleBuilderState<TContext, TConsequences>;
255
- };
256
- declare const rule: <
257
- TContext = unknown,
258
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
259
- >() => RuleBuilder<TContext, TConsequences>;
260
- declare const createRule: <
261
- TContext = unknown,
262
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
263
- >(builderFn: (rb: RuleBuilder<TContext, TConsequences>) => RuleBuilder<TContext, TConsequences>) => RuleInput<TContext, TConsequences>;
264
- import { z as z4 } from "zod";
265
- declare const RuleStatsSchema: any;
266
- type RuleStats = z4.infer<typeof RuleStatsSchema>;
267
- declare const CacheStatsSchema: any;
268
- type CacheStats = z4.infer<typeof CacheStatsSchema>;
269
- declare const EngineStatsSchema: any;
270
- type EngineStats = z4.infer<typeof EngineStatsSchema>;
271
- type EngineState<
272
- TContext = unknown,
273
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
274
- > = {
275
- readonly rules: ReadonlyMap<string, Rule<TContext, TConsequences>>;
276
- readonly ruleSets: ReadonlyMap<string, RuleSet>;
277
- readonly ruleOrder: ReadonlyArray<string>;
278
- };
279
- type MutableEngineState<
280
- TContext = unknown,
281
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
282
- > = {
283
- rules: Map<string, Rule<TContext, TConsequences>>;
284
- ruleSets: Map<string, RuleSet>;
285
- ruleOrder: string[];
286
- };
287
- type MutableRuleStats = {
288
- evaluations: number;
289
- matches: number;
290
- errors: number;
291
- totalTimeMs: number;
292
- avgTimeMs: number;
293
- lastEvaluated?: Date;
294
- };
295
- type OptimizerState = {
296
- readonly ruleStats: ReadonlyMap<string, RuleStats>;
297
- readonly lastOptimized?: Date;
298
- };
299
- type MutableOptimizerState = {
300
- ruleStats: Map<string, MutableRuleStats>;
301
- lastOptimized?: Date;
302
- };
303
- declare const createInitialState: <
304
- TContext = unknown,
305
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
306
- >() => MutableEngineState<TContext, TConsequences>;
307
- declare const createInitialOptimizerState: () => MutableOptimizerState;
308
- declare const createInitialRuleStats: () => MutableRuleStats;
309
- type CacheEntry<T> = {
310
- value: T;
311
- expiresAt: number;
312
- createdAt: number;
313
- };
314
- type Cache<T> = {
315
- readonly get: (key: string) => T | undefined;
316
- readonly set: (key: string, value: T) => void;
317
- readonly has: (key: string) => boolean;
318
- readonly delete: (key: string) => boolean;
319
- readonly clear: () => void;
320
- readonly getStats: () => CacheStats;
321
- };
322
- type CacheOptions = {
323
- readonly ttl: number;
324
- readonly maxSize: number;
325
- readonly onEvict?: (key: string, value: unknown) => void;
326
- };
327
- declare const createCache: <T>(options: CacheOptions) => Cache<T>;
328
- declare const createNoopCache: <T>() => Cache<T>;
329
- import { GroupEvaluationResult } from "@f-o-t/condition-evaluator";
330
- import { z as z5 } from "zod";
331
- declare const ConflictResolutionStrategySchema: any;
332
- type ConflictResolutionStrategy = z5.infer<typeof ConflictResolutionStrategySchema>;
333
- declare const EvaluateOptionsSchema: any;
334
- type EvaluateOptions = z5.infer<typeof EvaluateOptionsSchema>;
335
- declare const EvaluateConfigSchema: any;
336
- type EvaluateConfig = z5.infer<typeof EvaluateConfigSchema>;
337
- type EvaluationContext<TContext = unknown> = {
338
- readonly data: TContext;
339
- readonly timestamp: Date;
340
- readonly correlationId?: string;
341
- readonly metadata?: Readonly<Record<string, unknown>>;
342
- };
343
- type RuleEvaluationResult<
344
- _TContext = unknown,
345
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
346
- > = {
347
- readonly ruleId: string;
348
- readonly ruleName: string;
349
- readonly matched: boolean;
350
- readonly conditionResult: GroupEvaluationResult;
351
- readonly consequences: ReadonlyArray<AggregatedConsequence<TConsequences>>;
352
- readonly evaluationTimeMs: number;
353
- readonly skipped: boolean;
354
- readonly skipReason?: string;
355
- readonly error?: Error;
356
- };
357
- type EngineExecutionResult<
358
- TContext = unknown,
359
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
360
- > = {
361
- readonly context: EvaluationContext<TContext>;
362
- readonly results: ReadonlyArray<RuleEvaluationResult<TContext, TConsequences>>;
363
- readonly matchedRules: ReadonlyArray<Rule<TContext, TConsequences>>;
364
- readonly consequences: ReadonlyArray<AggregatedConsequence<TConsequences>>;
365
- readonly totalRulesEvaluated: number;
366
- readonly totalRulesMatched: number;
367
- readonly totalRulesSkipped: number;
368
- readonly totalRulesErrored: number;
369
- readonly executionTimeMs: number;
370
- readonly stoppedEarly: boolean;
371
- readonly stoppedByRuleId?: string;
372
- readonly cacheHit: boolean;
373
- };
374
- type EvaluateRuleOptions = {
375
- readonly skipDisabled?: boolean;
376
- };
377
- declare const evaluateRule: <
378
- TContext = unknown,
379
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
380
- >(rule: Rule<TContext, TConsequences>, context: EvaluationContext<TContext>, options?: EvaluateRuleOptions) => RuleEvaluationResult<TContext, TConsequences>;
381
- type EvaluateRulesOptions<
382
- TContext = unknown,
383
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
384
- > = {
385
- readonly config?: Partial<EvaluateConfig>;
386
- readonly onRuleEvaluated?: (result: RuleEvaluationResult<TContext, TConsequences>) => void;
387
- };
388
- type EvaluateRulesResult<
389
- TContext = unknown,
390
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
391
- > = {
392
- readonly results: ReadonlyArray<RuleEvaluationResult<TContext, TConsequences>>;
393
- readonly matchedRules: ReadonlyArray<Rule<TContext, TConsequences>>;
394
- readonly consequences: ReadonlyArray<AggregatedConsequence<TConsequences>>;
395
- readonly stoppedEarly: boolean;
396
- readonly stoppedByRuleId?: string;
397
- };
398
- declare const evaluateRules: <
399
- TContext = unknown,
400
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
401
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, context: EvaluationContext<TContext>, options?: EvaluateRulesOptions<TContext, TConsequences>) => EvaluateRulesResult<TContext, TConsequences>;
402
- declare const filterRules: <
403
- TContext = unknown,
404
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
405
- >(filters: RuleFilters) => (rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<Rule<TContext, TConsequences>>;
406
- declare const filterByEnabled: <
407
- TContext = unknown,
408
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
409
- >(enabled: boolean) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
410
- declare const filterByTags: <
411
- TContext = unknown,
412
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
413
- >(tags: ReadonlyArray<string>) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
414
- declare const filterByCategory: <
415
- TContext = unknown,
416
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
417
- >(category: string) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
418
- declare const filterByIds: <
419
- TContext = unknown,
420
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
421
- >(ids: ReadonlyArray<string>) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
422
- type GroupByField = "category" | "priority" | "enabled";
423
- type GroupedRules<
424
- TContext = unknown,
425
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
426
- > = ReadonlyMap<string | number | boolean, ReadonlyArray<Rule<TContext, TConsequences>>>;
427
- declare const groupRules: <
428
- TContext = unknown,
429
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
430
- >(field: GroupByField) => (rules: ReadonlyArray<Rule<TContext, TConsequences>>) => GroupedRules<TContext, TConsequences>;
431
- declare const groupByCategory: <
432
- TContext = unknown,
433
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
434
- >() => (rules: readonly Rule<TContext, TConsequences>[]) => GroupedRules<TContext, TConsequences>;
435
- declare const groupByPriority: <
436
- TContext = unknown,
437
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
438
- >() => (rules: readonly Rule<TContext, TConsequences>[]) => GroupedRules<TContext, TConsequences>;
439
- declare const groupByEnabled: <
440
- TContext = unknown,
441
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
442
- >() => (rules: readonly Rule<TContext, TConsequences>[]) => GroupedRules<TContext, TConsequences>;
443
- declare const groupByCustom: <
444
- TContext = unknown,
445
- TConsequences extends ConsequenceDefinitions = DefaultConsequences,
446
- TKey extends string | number | boolean = string
447
- >(keyFn: (rule: Rule<TContext, TConsequences>) => TKey) => (rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyMap<TKey, ReadonlyArray<Rule<TContext, TConsequences>>>;
448
- type SortField = "priority" | "name" | "createdAt" | "updatedAt";
449
- type SortDirection = "asc" | "desc";
450
- type SortOptions = {
451
- readonly field: SortField;
452
- readonly direction?: SortDirection;
453
- };
454
- declare const sortRules: <
455
- TContext = unknown,
456
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
457
- >(options: SortField | SortOptions) => (rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<Rule<TContext, TConsequences>>;
458
- declare const sortByPriority: <
459
- TContext = unknown,
460
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
461
- >(direction?: SortDirection) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
462
- declare const sortByName: <
463
- TContext = unknown,
464
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
465
- >(direction?: SortDirection) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
466
- declare const sortByCreatedAt: <
467
- TContext = unknown,
468
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
469
- >(direction?: SortDirection) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
470
- declare const sortByUpdatedAt: <
471
- TContext = unknown,
472
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
473
- >(direction?: SortDirection) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
474
- import { z as z6 } from "zod";
475
- declare const LogLevelSchema: any;
476
- type LogLevel = z6.infer<typeof LogLevelSchema>;
477
- declare const CacheConfigSchema: any;
478
- type CacheConfig = z6.infer<typeof CacheConfigSchema>;
479
- declare const ValidationConfigSchema: any;
480
- type ValidationConfig = z6.infer<typeof ValidationConfigSchema>;
481
- declare const VersioningConfigSchema: any;
482
- type VersioningConfig = z6.infer<typeof VersioningConfigSchema>;
483
- type Logger = {
484
- readonly error: (...args: unknown[]) => void;
485
- readonly warn: (...args: unknown[]) => void;
486
- readonly info: (...args: unknown[]) => void;
487
- readonly debug: (...args: unknown[]) => void;
488
- };
489
- type EngineHooks<
490
- TContext = unknown,
491
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
492
- > = {
493
- readonly beforeEvaluation?: (context: EvaluationContext<TContext>, rules: ReadonlyArray<Rule<TContext, TConsequences>>) => void | Promise<void>;
494
- readonly afterEvaluation?: (result: EngineExecutionResult<TContext, TConsequences>) => void | Promise<void>;
495
- readonly beforeRuleEvaluation?: (rule: Rule<TContext, TConsequences>, context: EvaluationContext<TContext>) => void | Promise<void>;
496
- readonly afterRuleEvaluation?: (rule: Rule<TContext, TConsequences>, result: RuleEvaluationResult<TContext, TConsequences>) => void | Promise<void>;
497
- readonly onRuleMatch?: (rule: Rule<TContext, TConsequences>, context: EvaluationContext<TContext>) => void | Promise<void>;
498
- readonly onRuleSkip?: (rule: Rule<TContext, TConsequences>, reason: string) => void | Promise<void>;
499
- readonly onRuleError?: (rule: Rule<TContext, TConsequences>, error: Error) => void | Promise<void>;
500
- readonly onConsequenceCollected?: (rule: Rule<TContext, TConsequences>, consequence: AggregatedConsequence<TConsequences>) => void | Promise<void>;
501
- readonly onCacheHit?: (key: string, result: EngineExecutionResult<TContext, TConsequences>) => void | Promise<void>;
502
- readonly onCacheMiss?: (key: string) => void | Promise<void>;
503
- readonly onSlowRule?: (rule: Rule<TContext, TConsequences>, timeMs: number, threshold: number) => void | Promise<void>;
504
- readonly onHookError?: (hookName: string, error: Error) => void;
505
- };
506
- type EngineConfig<
507
- TContext = unknown,
508
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
509
- > = {
510
- readonly consequences?: TConsequences;
511
- readonly conflictResolution?: ConflictResolutionStrategy;
512
- readonly cache?: Partial<CacheConfig>;
513
- readonly validation?: Partial<ValidationConfig>;
514
- readonly versioning?: Partial<VersioningConfig>;
515
- readonly hooks?: EngineHooks<TContext, TConsequences>;
516
- readonly logLevel?: LogLevel;
517
- readonly logger?: Logger;
518
- readonly continueOnError?: boolean;
519
- readonly slowRuleThresholdMs?: number;
520
- readonly hookTimeoutMs?: number;
521
- };
522
- type ResolvedEngineConfig<
523
- TContext = unknown,
524
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
525
- > = {
526
- readonly consequences: TConsequences | undefined;
527
- readonly conflictResolution: ConflictResolutionStrategy;
528
- readonly cache: CacheConfig;
529
- readonly validation: ValidationConfig;
530
- readonly versioning: VersioningConfig;
531
- readonly hooks: EngineHooks<TContext, TConsequences>;
532
- readonly logLevel: LogLevel;
533
- readonly logger: Logger;
534
- readonly continueOnError: boolean;
535
- readonly slowRuleThresholdMs: number;
536
- readonly hookTimeoutMs: number | undefined;
537
- };
538
- declare const parseCacheConfig: (input?: Partial<CacheConfig>) => CacheConfig;
539
- declare const parseValidationConfig: (input?: Partial<ValidationConfig>) => ValidationConfig;
540
- declare const parseVersioningConfig: (input?: Partial<VersioningConfig>) => VersioningConfig;
541
- declare const getDefaultCacheConfig: () => CacheConfig;
542
- declare const getDefaultValidationConfig: () => ValidationConfig;
543
- declare const getDefaultVersioningConfig: () => VersioningConfig;
544
- declare const getDefaultLogLevel: () => LogLevel;
545
- declare const getDefaultConflictResolution: () => ConflictResolutionStrategy;
546
- type Engine<
547
- TContext = unknown,
548
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
549
- > = {
550
- readonly addRule: (input: RuleInput<TContext, TConsequences>) => Rule<TContext, TConsequences>;
551
- readonly addRules: (inputs: RuleInput<TContext, TConsequences>[]) => Rule<TContext, TConsequences>[];
552
- readonly removeRule: (ruleId: string) => boolean;
553
- readonly updateRule: (ruleId: string, updates: Partial<RuleInput<TContext, TConsequences>>) => Rule<TContext, TConsequences> | undefined;
554
- readonly getRule: (ruleId: string) => Rule<TContext, TConsequences> | undefined;
555
- readonly getRules: (filters?: RuleFilters) => ReadonlyArray<Rule<TContext, TConsequences>>;
556
- readonly enableRule: (ruleId: string) => boolean;
557
- readonly disableRule: (ruleId: string) => boolean;
558
- readonly clearRules: () => void;
559
- readonly addRuleSet: (input: RuleSetInput) => RuleSet;
560
- readonly getRuleSet: (ruleSetId: string) => RuleSet | undefined;
561
- readonly getRuleSets: () => ReadonlyArray<RuleSet>;
562
- readonly removeRuleSet: (ruleSetId: string) => boolean;
563
- readonly evaluate: (context: TContext, options?: EvaluateOptions) => Promise<EngineExecutionResult<TContext, TConsequences>>;
564
- readonly clearCache: () => void;
565
- readonly getCacheStats: () => CacheStats;
566
- readonly getState: () => Readonly<EngineState<TContext, TConsequences>>;
567
- readonly getStats: () => EngineStats;
568
- };
569
- declare const createEngine: <
570
- TContext = unknown,
571
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
572
- >(config?: EngineConfig<TContext, TConsequences>) => Engine<TContext, TConsequences>;
573
- declare const addRule2: <
574
- TContext = unknown,
575
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
576
- >(state: MutableEngineState<TContext, TConsequences>, input: RuleInput<TContext, TConsequences>) => Rule<TContext, TConsequences>;
577
- declare const addRules2: <
578
- TContext = unknown,
579
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
580
- >(state: MutableEngineState<TContext, TConsequences>, inputs: RuleInput<TContext, TConsequences>[]) => Rule<TContext, TConsequences>[];
581
- declare const removeRule2: <
582
- TContext = unknown,
583
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
584
- >(state: MutableEngineState<TContext, TConsequences>, ruleId: string) => boolean;
585
- declare const updateRule2: <
586
- TContext = unknown,
587
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
588
- >(state: MutableEngineState<TContext, TConsequences>, ruleId: string, updates: Partial<RuleInput<TContext, TConsequences>>) => Rule<TContext, TConsequences> | undefined;
589
- declare const getRule2: <
590
- TContext = unknown,
591
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
592
- >(state: MutableEngineState<TContext, TConsequences>, ruleId: string) => Rule<TContext, TConsequences> | undefined;
593
- declare const getRules2: <
594
- TContext = unknown,
595
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
596
- >(state: MutableEngineState<TContext, TConsequences>, filters?: RuleFilters) => ReadonlyArray<Rule<TContext, TConsequences>>;
597
- declare const enableRule2: <
598
- TContext = unknown,
599
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
600
- >(state: MutableEngineState<TContext, TConsequences>, ruleId: string) => boolean;
601
- declare const disableRule2: <
602
- TContext = unknown,
603
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
604
- >(state: MutableEngineState<TContext, TConsequences>, ruleId: string) => boolean;
605
- declare const clearRules2: <
606
- TContext = unknown,
607
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
608
- >(state: MutableEngineState<TContext, TConsequences>) => void;
609
- declare const addRuleSet2: <
610
- TContext = unknown,
611
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
612
- >(state: MutableEngineState<TContext, TConsequences>, input: RuleSetInput) => RuleSet;
613
- declare const getRuleSet2: <
614
- TContext = unknown,
615
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
616
- >(state: MutableEngineState<TContext, TConsequences>, ruleSetId: string) => RuleSet | undefined;
617
- declare const getRuleSets2: <
618
- TContext = unknown,
619
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
620
- >(state: MutableEngineState<TContext, TConsequences>) => ReadonlyArray<RuleSet>;
621
- declare const removeRuleSet2: <
622
- TContext = unknown,
623
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
624
- >(state: MutableEngineState<TContext, TConsequences>, ruleSetId: string) => boolean;
625
- declare const getRulesInSet: <
626
- TContext = unknown,
627
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
628
- >(state: MutableEngineState<TContext, TConsequences>, ruleSetId: string) => ReadonlyArray<Rule<TContext, TConsequences>>;
629
- declare const cloneState: <
630
- TContext = unknown,
631
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
632
- >(state: MutableEngineState<TContext, TConsequences>) => MutableEngineState<TContext, TConsequences>;
633
- type FieldIndex<
634
- TContext = unknown,
635
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
636
- > = Map<string, ReadonlyArray<Rule<TContext, TConsequences>>>;
637
- type TagIndex<
638
- TContext = unknown,
639
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
640
- > = Map<string, ReadonlyArray<Rule<TContext, TConsequences>>>;
641
- type CategoryIndex<
642
- TContext = unknown,
643
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
644
- > = Map<string, ReadonlyArray<Rule<TContext, TConsequences>>>;
645
- type PriorityIndex<
646
- TContext = unknown,
647
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
648
- > = Map<number, ReadonlyArray<Rule<TContext, TConsequences>>>;
649
- type RuleIndex<
650
- TContext = unknown,
651
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
652
- > = {
653
- readonly byField: FieldIndex<TContext, TConsequences>;
654
- readonly byTag: TagIndex<TContext, TConsequences>;
655
- readonly byCategory: CategoryIndex<TContext, TConsequences>;
656
- readonly byPriority: PriorityIndex<TContext, TConsequences>;
657
- readonly byId: Map<string, Rule<TContext, TConsequences>>;
658
- readonly sortedByPriority: ReadonlyArray<Rule<TContext, TConsequences>>;
659
- };
660
- type IndexOptions = {
661
- readonly indexByField?: boolean;
662
- readonly indexByTag?: boolean;
663
- readonly indexByCategory?: boolean;
664
- readonly indexByPriority?: boolean;
665
- };
666
- declare const buildIndex: <
667
- TContext = unknown,
668
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
669
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, options?: IndexOptions) => RuleIndex<TContext, TConsequences>;
670
- declare const getRulesByField: <
671
- TContext = unknown,
672
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
673
- >(index: RuleIndex<TContext, TConsequences>, field: string) => ReadonlyArray<Rule<TContext, TConsequences>>;
674
- declare const getRulesByFields: <
675
- TContext = unknown,
676
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
677
- >(index: RuleIndex<TContext, TConsequences>, fields: ReadonlyArray<string>, mode?: "any" | "all") => ReadonlyArray<Rule<TContext, TConsequences>>;
678
- declare const getRulesByTag: <
679
- TContext = unknown,
680
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
681
- >(index: RuleIndex<TContext, TConsequences>, tag: string) => ReadonlyArray<Rule<TContext, TConsequences>>;
682
- declare const getRulesByTags: <
683
- TContext = unknown,
684
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
685
- >(index: RuleIndex<TContext, TConsequences>, tags: ReadonlyArray<string>, mode?: "any" | "all") => ReadonlyArray<Rule<TContext, TConsequences>>;
686
- declare const getRulesByCategory: <
687
- TContext = unknown,
688
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
689
- >(index: RuleIndex<TContext, TConsequences>, category: string) => ReadonlyArray<Rule<TContext, TConsequences>>;
690
- declare const getRulesByPriority: <
691
- TContext = unknown,
692
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
693
- >(index: RuleIndex<TContext, TConsequences>, priority: number) => ReadonlyArray<Rule<TContext, TConsequences>>;
694
- declare const getRulesByPriorityRange: <
695
- TContext = unknown,
696
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
697
- >(index: RuleIndex<TContext, TConsequences>, minPriority: number, maxPriority: number) => ReadonlyArray<Rule<TContext, TConsequences>>;
698
- declare const getRuleById: <
699
- TContext = unknown,
700
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
701
- >(index: RuleIndex<TContext, TConsequences>, id: string) => Rule<TContext, TConsequences> | undefined;
702
- declare const filterRulesForContext: <
703
- TContext = unknown,
704
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
705
- >(index: RuleIndex<TContext, TConsequences>, contextFields: ReadonlyArray<string>) => ReadonlyArray<Rule<TContext, TConsequences>>;
706
- type OptimizationSuggestion = {
707
- readonly type: "INDEX" | "CACHE" | "MERGE" | "SIMPLIFY" | "REORDER";
708
- readonly severity: "high" | "medium" | "low";
709
- readonly message: string;
710
- readonly ruleIds?: ReadonlyArray<string>;
711
- readonly details?: Readonly<Record<string, unknown>>;
712
- };
713
- declare const analyzeOptimizations: <
714
- TContext = unknown,
715
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
716
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<OptimizationSuggestion>;
717
- declare const getIndexStats: <
718
- TContext = unknown,
719
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
720
- >(index: RuleIndex<TContext, TConsequences>) => {
721
- totalRules: number;
722
- uniqueFields: number;
723
- uniqueTags: number;
724
- uniqueCategories: number;
725
- uniquePriorities: number;
726
- averageRulesPerField: number;
727
- averageRulesPerTag: number;
728
- };
729
- import { ConditionGroup as ConditionGroup4 } from "@f-o-t/condition-evaluator";
730
- type SerializedRule = {
731
- readonly id: string;
732
- readonly name: string;
733
- readonly description?: string;
734
- readonly conditions: ConditionGroup4;
735
- readonly consequences: ReadonlyArray<{
736
- type: string;
737
- payload: unknown;
738
- }>;
739
- readonly priority: number;
740
- readonly enabled: boolean;
741
- readonly stopOnMatch: boolean;
742
- readonly tags: ReadonlyArray<string>;
743
- readonly category?: string;
744
- readonly metadata?: Readonly<Record<string, unknown>>;
745
- readonly createdAt: string;
746
- readonly updatedAt: string;
747
- };
748
- type SerializedRuleSet = {
749
- readonly id: string;
750
- readonly name: string;
751
- readonly description?: string;
752
- readonly ruleIds: ReadonlyArray<string>;
753
- readonly enabled: boolean;
754
- readonly metadata?: Readonly<Record<string, unknown>>;
755
- };
756
- type ExportFormat = {
757
- readonly version: string;
758
- readonly exportedAt: string;
759
- readonly rules: ReadonlyArray<SerializedRule>;
760
- readonly ruleSets?: ReadonlyArray<SerializedRuleSet>;
761
- readonly metadata?: Readonly<Record<string, unknown>>;
762
- };
763
- type ImportOptions = {
764
- readonly generateNewIds?: boolean;
765
- readonly idPrefix?: string;
766
- readonly preserveDates?: boolean;
767
- readonly validateSchema?: boolean;
768
- };
769
- type OrphanedReference = {
770
- readonly ruleSetId: string;
771
- readonly ruleSetName: string;
772
- readonly missingRuleIds: ReadonlyArray<string>;
773
- };
774
- type ImportResult<
775
- TContext = unknown,
776
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
777
- > = {
778
- readonly success: boolean;
779
- readonly rules: ReadonlyArray<Rule<TContext, TConsequences>>;
780
- readonly ruleSets: ReadonlyArray<RuleSet>;
781
- readonly errors: ReadonlyArray<{
782
- index: number;
783
- type: "rule" | "ruleSet";
784
- message: string;
785
- }>;
786
- readonly idMapping: ReadonlyMap<string, string>;
787
- readonly orphanedReferences: ReadonlyArray<OrphanedReference>;
788
- };
789
- declare const serializeRule: <
790
- TContext = unknown,
791
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
792
- >(rule: Rule<TContext, TConsequences>) => SerializedRule;
793
- declare const deserializeRule: <
794
- TContext = unknown,
795
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
796
- >(serialized: SerializedRule, options?: ImportOptions) => Rule<TContext, TConsequences>;
797
- declare const serializeRuleSet: (ruleSet: RuleSet) => SerializedRuleSet;
798
- declare const deserializeRuleSet: (serialized: SerializedRuleSet, idMapping: Map<string, string>, options?: ImportOptions) => RuleSet;
799
- declare const exportRules: <
800
- TContext = unknown,
801
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
802
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, ruleSets?: ReadonlyArray<RuleSet>, metadata?: Record<string, unknown>) => ExportFormat;
803
- declare const exportToJson: <
804
- TContext = unknown,
805
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
806
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, ruleSets?: ReadonlyArray<RuleSet>, metadata?: Record<string, unknown>) => string;
807
- declare const importRules: <
808
- TContext = unknown,
809
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
810
- >(data: ExportFormat, options?: ImportOptions) => ImportResult<TContext, TConsequences>;
811
- declare const importFromJson: <
812
- TContext = unknown,
813
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
814
- >(json: string, options?: ImportOptions) => ImportResult<TContext, TConsequences>;
815
- declare const cloneRule: <
816
- TContext = unknown,
817
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
818
- >(rule: Rule<TContext, TConsequences>, newId?: string, newName?: string) => Rule<TContext, TConsequences>;
819
- declare const mergeRuleSets: <
820
- TContext = unknown,
821
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
822
- >(baseRules: ReadonlyArray<Rule<TContext, TConsequences>>, incomingRules: ReadonlyArray<Rule<TContext, TConsequences>>, strategy?: "replace" | "skip" | "merge") => ReadonlyArray<Rule<TContext, TConsequences>>;
823
- declare const diffRuleSets: <
824
- TContext = unknown,
825
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
826
- >(oldRules: ReadonlyArray<Rule<TContext, TConsequences>>, newRules: ReadonlyArray<Rule<TContext, TConsequences>>) => {
827
- added: ReadonlyArray<Rule<TContext, TConsequences>>;
828
- removed: ReadonlyArray<Rule<TContext, TConsequences>>;
829
- modified: ReadonlyArray<{
830
- old: Rule<TContext, TConsequences>;
831
- new: Rule<TContext, TConsequences>;
832
- }>;
833
- unchanged: ReadonlyArray<Rule<TContext, TConsequences>>;
834
- };
835
- type SimulationContext<TContext = unknown> = {
836
- readonly data: TContext;
837
- readonly metadata?: Record<string, unknown>;
838
- };
839
- type SimulationResult<
840
- TContext = unknown,
841
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
842
- > = {
843
- readonly context: SimulationContext<TContext>;
844
- readonly matchedRules: ReadonlyArray<RuleEvaluationResult<TContext, TConsequences>>;
845
- readonly unmatchedRules: ReadonlyArray<{
846
- ruleId: string;
847
- ruleName: string;
848
- reason: string;
849
- }>;
850
- readonly consequences: ReadonlyArray<{
851
- type: keyof TConsequences;
852
- payload: unknown;
853
- ruleId: string;
854
- ruleName: string;
855
- }>;
856
- readonly executionTimeMs: number;
857
- };
858
- type WhatIfResult<
859
- TContext = unknown,
860
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
861
- > = {
862
- readonly original: SimulationResult<TContext, TConsequences>;
863
- readonly modified: SimulationResult<TContext, TConsequences>;
864
- readonly differences: {
865
- readonly newMatches: ReadonlyArray<string>;
866
- readonly lostMatches: ReadonlyArray<string>;
867
- readonly consequenceChanges: ReadonlyArray<{
868
- type: "added" | "removed" | "modified";
869
- consequenceType: string;
870
- ruleId: string;
871
- }>;
872
- };
873
- };
874
- type BatchSimulationResult<
875
- TContext = unknown,
876
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
877
- > = {
878
- readonly results: ReadonlyArray<SimulationResult<TContext, TConsequences>>;
879
- readonly summary: {
880
- readonly totalContexts: number;
881
- readonly averageMatchedRules: number;
882
- readonly ruleMatchFrequency: ReadonlyMap<string, number>;
883
- readonly consequenceFrequency: ReadonlyMap<string, number>;
884
- readonly averageExecutionTimeMs: number;
885
- };
886
- };
887
- declare const simulate: <
888
- TContext = unknown,
889
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
890
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, context: SimulationContext<TContext>) => SimulationResult<TContext, TConsequences>;
891
- declare const simulateSingleRule: <
892
- TContext = unknown,
893
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
894
- >(rule: Rule<TContext, TConsequences>, context: SimulationContext<TContext>) => {
895
- matched: boolean;
896
- conditionResult: unknown;
897
- consequences: ReadonlyArray<{
898
- type: keyof TConsequences;
899
- payload: unknown;
900
- }>;
901
- };
902
- declare const whatIf: <
903
- TContext = unknown,
904
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
905
- >(originalRules: ReadonlyArray<Rule<TContext, TConsequences>>, modifiedRules: ReadonlyArray<Rule<TContext, TConsequences>>, context: SimulationContext<TContext>) => WhatIfResult<TContext, TConsequences>;
906
- declare const batchSimulate: <
907
- TContext = unknown,
908
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
909
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, contexts: ReadonlyArray<SimulationContext<TContext>>) => BatchSimulationResult<TContext, TConsequences>;
910
- declare const findRulesAffectedByContextChange: <
911
- TContext = unknown,
912
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
913
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, originalContext: SimulationContext<TContext>, modifiedContext: SimulationContext<TContext>) => {
914
- becameTrue: ReadonlyArray<Rule<TContext, TConsequences>>;
915
- becameFalse: ReadonlyArray<Rule<TContext, TConsequences>>;
916
- unchanged: ReadonlyArray<Rule<TContext, TConsequences>>;
917
- };
918
- declare const formatSimulationResult: <
919
- TContext = unknown,
920
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
921
- >(result: SimulationResult<TContext, TConsequences>) => string;
922
- declare const hashContext: (context: unknown) => string;
923
- declare const hashRules: (ruleIds: ReadonlyArray<string>) => string;
924
- declare const generateId: () => string;
925
- type TimingResult<T> = {
926
- readonly result: T;
927
- readonly durationMs: number;
928
- };
929
- declare const measureTime: <T>(fn: () => T) => TimingResult<T>;
930
- declare const measureTimeAsync: <T>(fn: () => Promise<T>) => Promise<TimingResult<T>>;
931
- declare const withTimeout: <T>(promise: Promise<T>, timeoutMs: number, errorMessage?: string) => Promise<T>;
932
- type ConflictType = "DUPLICATE_ID" | "DUPLICATE_CONDITIONS" | "OVERLAPPING_CONDITIONS" | "CONTRADICTORY_CONSEQUENCES" | "PRIORITY_COLLISION" | "UNREACHABLE_RULE";
933
- type Conflict<
934
- TContext = unknown,
935
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
936
- > = {
937
- readonly type: ConflictType;
938
- readonly severity: "error" | "warning" | "info";
939
- readonly message: string;
940
- readonly ruleIds: ReadonlyArray<string>;
941
- readonly rules: ReadonlyArray<Rule<TContext, TConsequences>>;
942
- readonly details?: Readonly<Record<string, unknown>>;
943
- };
944
- type ConflictDetectionOptions = {
945
- readonly checkDuplicateIds?: boolean;
946
- readonly checkDuplicateConditions?: boolean;
947
- readonly checkOverlappingConditions?: boolean;
948
- readonly checkPriorityCollisions?: boolean;
949
- readonly checkUnreachableRules?: boolean;
950
- };
951
- declare const detectConflicts: <
952
- TContext = unknown,
953
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
954
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, options?: ConflictDetectionOptions) => ReadonlyArray<Conflict<TContext, TConsequences>>;
955
- declare const hasConflicts: <
956
- TContext = unknown,
957
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
958
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, options?: ConflictDetectionOptions) => boolean;
959
- declare const hasErrors: <
960
- TContext = unknown,
961
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
962
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, options?: ConflictDetectionOptions) => boolean;
963
- declare const getConflictsByType: <
964
- TContext = unknown,
965
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
966
- >(conflicts: ReadonlyArray<Conflict<TContext, TConsequences>>, type: ConflictType) => ReadonlyArray<Conflict<TContext, TConsequences>>;
967
- declare const getConflictsBySeverity: <
968
- TContext = unknown,
969
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
970
- >(conflicts: ReadonlyArray<Conflict<TContext, TConsequences>>, severity: "error" | "warning" | "info") => ReadonlyArray<Conflict<TContext, TConsequences>>;
971
- declare const formatConflicts: <
972
- TContext = unknown,
973
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
974
- >(conflicts: ReadonlyArray<Conflict<TContext, TConsequences>>) => string;
975
- type IntegrityIssue = {
976
- readonly code: string;
977
- readonly message: string;
978
- readonly severity: "error" | "warning" | "info";
979
- readonly path?: string;
980
- readonly ruleId?: string;
981
- readonly details?: Readonly<Record<string, unknown>>;
982
- };
983
- type IntegrityCheckResult = {
984
- readonly valid: boolean;
985
- readonly issues: ReadonlyArray<IntegrityIssue>;
986
- };
987
- type IntegrityCheckOptions = {
988
- readonly checkCircularReferences?: boolean;
989
- readonly checkOrphanedRuleSets?: boolean;
990
- readonly checkMissingReferences?: boolean;
991
- readonly checkFieldConsistency?: boolean;
992
- readonly requiredFields?: ReadonlyArray<string>;
993
- readonly allowedCategories?: ReadonlyArray<string>;
994
- readonly allowedTags?: ReadonlyArray<string>;
995
- };
996
- declare const checkIntegrity: <
997
- TContext = unknown,
998
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
999
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, ruleSets?: ReadonlyArray<RuleSet>, options?: IntegrityCheckOptions) => IntegrityCheckResult;
1000
- declare const checkRuleFieldCoverage: <
1001
- TContext = unknown,
1002
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1003
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>, expectedFields: ReadonlyArray<string>) => {
1004
- coveredFields: ReadonlyArray<string>;
1005
- uncoveredFields: ReadonlyArray<string>;
1006
- extraFields: ReadonlyArray<string>;
1007
- coveragePercentage: number;
1008
- };
1009
- declare const getUsedFields: <
1010
- TContext = unknown,
1011
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1012
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<string>;
1013
- declare const getUsedOperators: <
1014
- TContext = unknown,
1015
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1016
- >(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => ReadonlyArray<{
1017
- field: string;
1018
- operator: string;
1019
- type: string;
1020
- }>;
1021
- declare const formatIntegrityResult: (result: IntegrityCheckResult) => string;
1022
- import { ConditionGroup as ConditionGroup5 } from "@f-o-t/condition-evaluator";
1023
- import { z as z7 } from "zod";
1024
- declare const ValidationErrorSchema: any;
1025
- type ValidationError = z7.infer<typeof ValidationErrorSchema>;
1026
- declare const ValidationResultSchema: any;
1027
- type ValidationResult = z7.infer<typeof ValidationResultSchema>;
1028
- declare const ValidationOptionsSchema: any;
1029
- type ValidationOptions = z7.infer<typeof ValidationOptionsSchema>;
1030
- type ResolvedValidationOptions = {
1031
- validateConditions: boolean;
1032
- validateConsequences: boolean;
1033
- strictMode: boolean;
1034
- };
1035
- declare const validateRule: <
1036
- TContext = unknown,
1037
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1038
- >(rule: unknown, options?: ValidationOptions & {
1039
- consequenceSchemas?: TConsequences;
1040
- }) => ValidationResult;
1041
- declare const validateRules: <
1042
- TContext = unknown,
1043
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1044
- >(rules: ReadonlyArray<unknown>, options?: ValidationOptions & {
1045
- consequenceSchemas?: TConsequences;
1046
- }) => ValidationResult;
1047
- declare const validateRuleSet: (ruleSet: unknown) => ValidationResult;
1048
- declare const validateConditions: (conditions: ConditionGroup5) => ValidationResult;
1049
- declare const parseRule: <
1050
- TContext = unknown,
1051
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1052
- >(rule: unknown, options?: ValidationOptions & {
1053
- consequenceSchemas?: TConsequences;
1054
- }) => Rule<TContext, TConsequences>;
1055
- declare const safeParseRule: <
1056
- TContext = unknown,
1057
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1058
- >(rule: unknown, options?: ValidationOptions & {
1059
- consequenceSchemas?: TConsequences;
1060
- }) => {
1061
- success: true;
1062
- data: Rule<TContext, TConsequences>;
1063
- } | {
1064
- success: false;
1065
- errors: ReadonlyArray<ValidationError>;
1066
- };
1067
- declare const createRuleValidator: <
1068
- TContext = unknown,
1069
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1070
- >(consequenceSchemas: TConsequences, defaultOptions?: ValidationOptions) => {
1071
- validate: (rule: unknown, options?: ValidationOptions) => z7.infer<any>;
1072
- parse: (rule: unknown, options?: ValidationOptions) => Rule<TContext, TConsequences>;
1073
- safeParse: (rule: unknown, options?: ValidationOptions) => {
1074
- success: false;
1075
- errors: ReadonlyArray<ValidationError>;
1076
- } | {
1077
- success: true;
1078
- data: Rule<TContext, TConsequences>;
1079
- };
1080
- };
1081
- type RuleVersion<
1082
- TContext = unknown,
1083
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1084
- > = {
1085
- readonly versionId: string;
1086
- readonly ruleId: string;
1087
- readonly version: number;
1088
- readonly rule: Rule<TContext, TConsequences>;
1089
- readonly createdAt: Date;
1090
- readonly createdBy?: string;
1091
- readonly comment?: string;
1092
- readonly changeType: "create" | "update" | "delete" | "enable" | "disable";
1093
- };
1094
- type VersionHistory<
1095
- TContext = unknown,
1096
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1097
- > = {
1098
- readonly ruleId: string;
1099
- readonly currentVersion: number;
1100
- readonly versions: ReadonlyArray<RuleVersion<TContext, TConsequences>>;
1101
- };
1102
- type VersionStore<
1103
- TContext = unknown,
1104
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1105
- > = {
1106
- readonly histories: ReadonlyMap<string, VersionHistory<TContext, TConsequences>>;
1107
- };
1108
- declare const createVersionStore: <
1109
- TContext = unknown,
1110
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1111
- >() => VersionStore<TContext, TConsequences>;
1112
- declare const addVersion: <
1113
- TContext = unknown,
1114
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1115
- >(store: VersionStore<TContext, TConsequences>, rule: Rule<TContext, TConsequences>, changeType: RuleVersion<TContext, TConsequences>["changeType"], options?: {
1116
- createdBy?: string;
1117
- comment?: string;
1118
- }) => VersionStore<TContext, TConsequences>;
1119
- declare const getHistory: <
1120
- TContext = unknown,
1121
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1122
- >(store: VersionStore<TContext, TConsequences>, ruleId: string) => VersionHistory<TContext, TConsequences> | undefined;
1123
- declare const getVersion: <
1124
- TContext = unknown,
1125
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1126
- >(store: VersionStore<TContext, TConsequences>, ruleId: string, version: number) => RuleVersion<TContext, TConsequences> | undefined;
1127
- declare const getLatestVersion: <
1128
- TContext = unknown,
1129
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1130
- >(store: VersionStore<TContext, TConsequences>, ruleId: string) => RuleVersion<TContext, TConsequences> | undefined;
1131
- declare const getAllVersions: <
1132
- TContext = unknown,
1133
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1134
- >(store: VersionStore<TContext, TConsequences>, ruleId: string) => ReadonlyArray<RuleVersion<TContext, TConsequences>>;
1135
- declare const rollbackToVersion: <
1136
- TContext = unknown,
1137
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1138
- >(store: VersionStore<TContext, TConsequences>, ruleId: string, targetVersion: number, options?: {
1139
- createdBy?: string;
1140
- comment?: string;
1141
- }) => {
1142
- store: VersionStore<TContext, TConsequences>;
1143
- rule: Rule<TContext, TConsequences> | undefined;
1144
- };
1145
- declare const compareVersions: <
1146
- TContext = unknown,
1147
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1148
- >(store: VersionStore<TContext, TConsequences>, ruleId: string, version1: number, version2: number) => {
1149
- version1: RuleVersion<TContext, TConsequences> | undefined;
1150
- version2: RuleVersion<TContext, TConsequences> | undefined;
1151
- differences: ReadonlyArray<{
1152
- field: string;
1153
- oldValue: unknown;
1154
- newValue: unknown;
1155
- }>;
1156
- } | null;
1157
- declare const getVersionsByDateRange: <
1158
- TContext = unknown,
1159
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1160
- >(store: VersionStore<TContext, TConsequences>, startDate: Date, endDate: Date) => ReadonlyArray<RuleVersion<TContext, TConsequences>>;
1161
- declare const getVersionsByChangeType: <
1162
- TContext = unknown,
1163
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1164
- >(store: VersionStore<TContext, TConsequences>, changeType: RuleVersion<TContext, TConsequences>["changeType"]) => ReadonlyArray<RuleVersion<TContext, TConsequences>>;
1165
- declare const pruneOldVersions: <
1166
- TContext = unknown,
1167
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1168
- >(store: VersionStore<TContext, TConsequences>, keepCount: number) => VersionStore<TContext, TConsequences>;
1169
- declare const formatVersionHistory: <
1170
- TContext = unknown,
1171
- TConsequences extends ConsequenceDefinitions = DefaultConsequences
1172
- >(history: VersionHistory<TContext, TConsequences>) => string;
1173
- export { withTimeout, whatIf, validateRules, validateRuleSet, validateRule, validateConditions, updateRule2 as updateRule, str, sortRules, sortByUpdatedAt, sortByPriority, sortByName, sortByCreatedAt, simulateSingleRule, simulate, serializeRuleSet, serializeRule, safeParseRule, rule, rollbackToVersion, resetBuilderIds, removeRuleSet2 as removeRuleSet, removeRule2 as removeRule, pruneOldVersions, parseVersioningConfig, parseValidationConfig, parseRule, parseCacheConfig, or, num, mergeRuleSets, measureTimeAsync, measureTime, isConditionGroup, importRules, importFromJson, hashRules, hashContext, hasErrors, hasConflicts, groupRules, groupByPriority, groupByEnabled, groupByCustom, groupByCategory, getVersionsByDateRange, getVersionsByChangeType, getVersion, getUsedOperators, getUsedFields, getRulesInSet, getRulesByTags, getRulesByTag, getRulesByPriorityRange, getRulesByPriority, getRulesByFields, getRulesByField, getRulesByCategory, getRules2 as getRules, getRuleSets2 as getRuleSets, getRuleSet2 as getRuleSet, getRuleById, getRule2 as getRule, getLatestVersion, getIndexStats, getHistory, getDefaultVersioningConfig, getDefaultValidationConfig, getDefaultLogLevel, getDefaultConflictResolution, getDefaultCacheConfig, getConflictsByType, getConflictsBySeverity, getAllVersions, generateId, formatVersionHistory, formatSimulationResult, formatRuleSetAnalysis, formatIntegrityResult, formatConflicts, findRulesAffectedByContextChange, findMostComplexRules, findLeastUsedFields, filterRulesForContext, filterRules, filterByTags, filterByIds, filterByEnabled, filterByCategory, exportToJson, exportRules, evaluateRules, evaluateRule, enableRule2 as enableRule, disableRule2 as disableRule, diffRuleSets, detectConflicts, deserializeRuleSet, deserializeRule, date, createVersionStore, createRuleValidator, createRule, createNoopCache, createInitialState, createInitialRuleStats, createInitialOptimizerState, createEngine, createCache, conditions, compareVersions, cloneState, cloneRule, clearRules2 as clearRules, checkRuleFieldCoverage, checkIntegrity, buildIndex, bool, batchSimulate, arr, any, and, analyzeRuleSet, analyzeRuleComplexity, analyzeOptimizations, analyzeOperatorUsage, analyzeFieldUsage, analyzeConsequenceUsage, all, addVersion, addRules2 as addRules, addRuleSet2 as addRuleSet, addRule2 as addRule, WhatIfResult, VersioningConfigSchema, VersioningConfig, VersionStore, VersionHistory, ValidationResultSchema, ValidationResult, ValidationOptionsSchema, ValidationOptions, ValidationErrorSchema, ValidationError, ValidationConfigSchema, ValidationConfig, TimingResult, TagIndex, StringOperator, StringCondition, SortOptions, SortField, SortDirection, SimulationResult, SimulationContext, SerializedRuleSet, SerializedRule, RuleVersion, RuleStatsSchema, RuleStats, RuleSetSchemaType, RuleSetSchema, RuleSetInput, RuleSetAnalysis, RuleSet, RuleSchemaType, RuleSchema, RuleInput, RuleIndex, RuleFilters, RuleEvaluationResult, RuleComplexity, RuleBuilderState, RuleBuilder, Rule, ResolvedValidationOptions, ResolvedEngineConfig, PriorityIndex, OrphanedReference, OptimizerState, OptimizationSuggestion, OperatorUsage, NumberOperator, NumberCondition, LogicalOperator, Logger, LogLevelSchema, LogLevel, IntegrityIssue, IntegrityCheckResult, IntegrityCheckOptions, InferConsequenceType, InferConsequencePayload, IndexOptions, ImportResult, ImportOptions, GroupedRules, GroupEvaluationResult2 as GroupEvaluationResult, GroupByField, FieldUsage, FieldIndex, ExportFormat, EvaluationResult, EvaluationContext, EvaluateRulesResult, EvaluateRulesOptions, EvaluateRuleOptions, EvaluateOptionsSchema, EvaluateOptions, EvaluateConfigSchema, EvaluateConfig, EngineStatsSchema, EngineStats, EngineState, EngineHooks, EngineExecutionResult, EngineConfig, Engine, DefaultConsequences, DateOperator, DateCondition, CustomCondition, ConsequenceUsage, ConsequenceInput, ConsequenceDefinitions, Consequence, ConflictType, ConflictResolutionStrategySchema, ConflictResolutionStrategy, ConflictDetectionOptions, Conflict, ConditionGroup7 as ConditionGroupSchema, ConditionGroup6 as ConditionGroup, ConditionBuilderState, ConditionBuilder, Condition2 as Condition, CategoryIndex, CacheStatsSchema, CacheStats, CacheOptions, CacheEntry, CacheConfigSchema, CacheConfig, Cache, BooleanOperator, BooleanCondition, BatchSimulationResult, ArrayOperator, ArrayCondition, AggregatedConsequence };