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