@f-o-t/rules-engine 1.0.0 → 2.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/README.md +78 -20
- package/dist/index.cjs +286 -218
- package/dist/index.d.cts +191 -186
- package/dist/index.d.ts +191 -186
- package/dist/index.js +291 -218
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ArrayCondition, BooleanCondition, Condition as
|
|
1
|
+
import { ArrayCondition, ArrayOperator, BooleanCondition, BooleanOperator, Condition as Condition3, 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";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
type ConsequenceDefinitions = Record<string, z.ZodType>;
|
|
4
5
|
type DefaultConsequences = Record<string, z.ZodType>;
|
|
@@ -94,7 +95,35 @@ declare const RuleSchema: z2.ZodObject<{
|
|
|
94
95
|
id: z2.ZodString;
|
|
95
96
|
name: z2.ZodString;
|
|
96
97
|
description: z2.ZodOptional<z2.ZodString>;
|
|
97
|
-
conditions: z2.ZodCustom<
|
|
98
|
+
conditions: z2.ZodCustom<{
|
|
99
|
+
id: string;
|
|
100
|
+
operator: "AND" | "OR";
|
|
101
|
+
scoringMode?: "binary" | "weighted" | undefined;
|
|
102
|
+
threshold?: number | undefined;
|
|
103
|
+
weight?: number | undefined;
|
|
104
|
+
} & {
|
|
105
|
+
conditions: (import("@f-o-t/condition-evaluator").Condition | ({
|
|
106
|
+
id: string;
|
|
107
|
+
operator: "AND" | "OR";
|
|
108
|
+
scoringMode?: "binary" | "weighted" | undefined;
|
|
109
|
+
threshold?: number | undefined;
|
|
110
|
+
weight?: number | undefined;
|
|
111
|
+
} & any))[];
|
|
112
|
+
}, {
|
|
113
|
+
id: string;
|
|
114
|
+
operator: "AND" | "OR";
|
|
115
|
+
scoringMode?: "binary" | "weighted" | undefined;
|
|
116
|
+
threshold?: number | undefined;
|
|
117
|
+
weight?: number | undefined;
|
|
118
|
+
} & {
|
|
119
|
+
conditions: (import("@f-o-t/condition-evaluator").Condition | ({
|
|
120
|
+
id: string;
|
|
121
|
+
operator: "AND" | "OR";
|
|
122
|
+
scoringMode?: "binary" | "weighted" | undefined;
|
|
123
|
+
threshold?: number | undefined;
|
|
124
|
+
weight?: number | undefined;
|
|
125
|
+
} & any))[];
|
|
126
|
+
}>;
|
|
98
127
|
consequences: z2.ZodArray<z2.ZodObject<{
|
|
99
128
|
type: z2.ZodString;
|
|
100
129
|
payload: z2.ZodUnknown;
|
|
@@ -129,10 +158,7 @@ type RuleComplexity = {
|
|
|
129
158
|
readonly consequenceCount: number;
|
|
130
159
|
readonly complexityScore: number;
|
|
131
160
|
};
|
|
132
|
-
type RuleSetAnalysis
|
|
133
|
-
TContext = unknown,
|
|
134
|
-
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
135
|
-
> = {
|
|
161
|
+
type RuleSetAnalysis = {
|
|
136
162
|
readonly ruleCount: number;
|
|
137
163
|
readonly enabledCount: number;
|
|
138
164
|
readonly disabledCount: number;
|
|
@@ -189,7 +215,7 @@ declare const analyzeRuleComplexity: <
|
|
|
189
215
|
declare const analyzeRuleSet: <
|
|
190
216
|
TContext = unknown,
|
|
191
217
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
192
|
-
>(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => RuleSetAnalysis
|
|
218
|
+
>(rules: ReadonlyArray<Rule<TContext, TConsequences>>) => RuleSetAnalysis;
|
|
193
219
|
declare const analyzeFieldUsage: <
|
|
194
220
|
TContext = unknown,
|
|
195
221
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -210,13 +236,10 @@ declare const findLeastUsedFields: <
|
|
|
210
236
|
TContext = unknown,
|
|
211
237
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
212
238
|
>(rules: ReadonlyArray<Rule<TContext, TConsequences>>, limit?: number) => ReadonlyArray<FieldUsage>;
|
|
213
|
-
declare const formatRuleSetAnalysis:
|
|
214
|
-
|
|
215
|
-
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
216
|
-
>(analysis: RuleSetAnalysis<TContext, TConsequences>) => string;
|
|
217
|
-
import { Condition, ConditionGroup as ConditionGroup2 } from "@f-o-t/condition-evaluator";
|
|
239
|
+
declare const formatRuleSetAnalysis: (analysis: RuleSetAnalysis) => string;
|
|
240
|
+
import { Condition as Condition2, ConditionGroup as ConditionGroup2 } from "@f-o-t/condition-evaluator";
|
|
218
241
|
type ConditionBuilderState = {
|
|
219
|
-
readonly conditions: (
|
|
242
|
+
readonly conditions: (Condition2 | ConditionGroup2)[];
|
|
220
243
|
};
|
|
221
244
|
type ConditionBuilder = {
|
|
222
245
|
readonly number: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq", value: number) => ConditionBuilder;
|
|
@@ -227,21 +250,21 @@ type ConditionBuilder = {
|
|
|
227
250
|
readonly ref: (field: string, operator: string, valueRef: string) => ConditionBuilder;
|
|
228
251
|
readonly and: (builder: (cb: ConditionBuilder) => ConditionBuilder) => ConditionBuilder;
|
|
229
252
|
readonly or: (builder: (cb: ConditionBuilder) => ConditionBuilder) => ConditionBuilder;
|
|
230
|
-
readonly raw: (condition:
|
|
253
|
+
readonly raw: (condition: Condition2 | ConditionGroup2) => ConditionBuilder;
|
|
231
254
|
readonly build: () => ConditionGroup2;
|
|
232
|
-
readonly getConditions: () => ReadonlyArray<
|
|
255
|
+
readonly getConditions: () => ReadonlyArray<Condition2 | ConditionGroup2>;
|
|
233
256
|
};
|
|
234
257
|
declare const resetBuilderIds: () => void;
|
|
235
258
|
declare const conditions: () => ConditionBuilder;
|
|
236
259
|
declare const and: (builderFn: (cb: ConditionBuilder) => ConditionBuilder) => ConditionGroup2;
|
|
237
260
|
declare const or: (builderFn: (cb: ConditionBuilder) => ConditionBuilder) => ConditionGroup2;
|
|
238
|
-
declare const all: (...items: (
|
|
239
|
-
declare const any: (...items: (
|
|
240
|
-
declare const num: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq", value: number) =>
|
|
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[]) =>
|
|
242
|
-
declare const bool: (field: string, operator: "eq" | "neq", value: boolean) =>
|
|
243
|
-
declare const date: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq" | "between", value: string | Date | [string | Date, string | Date]) =>
|
|
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) =>
|
|
261
|
+
declare const all: (...items: (Condition2 | ConditionGroup2)[]) => ConditionGroup2;
|
|
262
|
+
declare const any: (...items: (Condition2 | ConditionGroup2)[]) => ConditionGroup2;
|
|
263
|
+
declare const num: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq", value: number) => Condition2;
|
|
264
|
+
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[]) => Condition2;
|
|
265
|
+
declare const bool: (field: string, operator: "eq" | "neq", value: boolean) => Condition2;
|
|
266
|
+
declare const date: (field: string, operator: "gt" | "gte" | "lt" | "lte" | "eq" | "neq" | "between", value: string | Date | [string | Date, string | Date]) => Condition2;
|
|
267
|
+
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) => Condition2;
|
|
245
268
|
import { ConditionGroup as ConditionGroup3 } from "@f-o-t/condition-evaluator";
|
|
246
269
|
import { z as z3 } from "zod";
|
|
247
270
|
type RuleBuilderState<
|
|
@@ -290,6 +313,39 @@ declare const createRule: <
|
|
|
290
313
|
TContext = unknown,
|
|
291
314
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
292
315
|
>(builderFn: (rb: RuleBuilder<TContext, TConsequences>) => RuleBuilder<TContext, TConsequences>) => RuleInput<TContext, TConsequences>;
|
|
316
|
+
import { z as z4 } from "zod";
|
|
317
|
+
declare const RuleStatsSchema: z4.ZodObject<{
|
|
318
|
+
evaluations: z4.ZodNumber;
|
|
319
|
+
matches: z4.ZodNumber;
|
|
320
|
+
errors: z4.ZodNumber;
|
|
321
|
+
totalTimeMs: z4.ZodNumber;
|
|
322
|
+
avgTimeMs: z4.ZodNumber;
|
|
323
|
+
lastEvaluated: z4.ZodOptional<z4.ZodDate>;
|
|
324
|
+
}, z4.core.$strip>;
|
|
325
|
+
type RuleStats = z4.infer<typeof RuleStatsSchema>;
|
|
326
|
+
declare const CacheStatsSchema: z4.ZodObject<{
|
|
327
|
+
size: z4.ZodNumber;
|
|
328
|
+
maxSize: z4.ZodNumber;
|
|
329
|
+
hits: z4.ZodNumber;
|
|
330
|
+
misses: z4.ZodNumber;
|
|
331
|
+
hitRate: z4.ZodNumber;
|
|
332
|
+
evictions: z4.ZodNumber;
|
|
333
|
+
}, z4.core.$strip>;
|
|
334
|
+
type CacheStats = z4.infer<typeof CacheStatsSchema>;
|
|
335
|
+
declare const EngineStatsSchema: z4.ZodObject<{
|
|
336
|
+
totalRules: z4.ZodNumber;
|
|
337
|
+
enabledRules: z4.ZodNumber;
|
|
338
|
+
disabledRules: z4.ZodNumber;
|
|
339
|
+
totalRuleSets: z4.ZodNumber;
|
|
340
|
+
totalEvaluations: z4.ZodNumber;
|
|
341
|
+
totalMatches: z4.ZodNumber;
|
|
342
|
+
totalErrors: z4.ZodNumber;
|
|
343
|
+
avgEvaluationTimeMs: z4.ZodNumber;
|
|
344
|
+
cacheHits: z4.ZodNumber;
|
|
345
|
+
cacheMisses: z4.ZodNumber;
|
|
346
|
+
cacheHitRate: z4.ZodNumber;
|
|
347
|
+
}, z4.core.$strip>;
|
|
348
|
+
type EngineStats = z4.infer<typeof EngineStatsSchema>;
|
|
293
349
|
type EngineState<
|
|
294
350
|
TContext = unknown,
|
|
295
351
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -306,14 +362,6 @@ type MutableEngineState<
|
|
|
306
362
|
ruleSets: Map<string, RuleSet>;
|
|
307
363
|
ruleOrder: string[];
|
|
308
364
|
};
|
|
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
365
|
type MutableRuleStats = {
|
|
318
366
|
evaluations: number;
|
|
319
367
|
matches: number;
|
|
@@ -330,27 +378,6 @@ type MutableOptimizerState = {
|
|
|
330
378
|
ruleStats: Map<string, MutableRuleStats>;
|
|
331
379
|
lastOptimized?: Date;
|
|
332
380
|
};
|
|
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
381
|
declare const createInitialState: <
|
|
355
382
|
TContext = unknown,
|
|
356
383
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -378,6 +405,41 @@ type CacheOptions = {
|
|
|
378
405
|
declare const createCache: <T>(options: CacheOptions) => Cache<T>;
|
|
379
406
|
declare const createNoopCache: <T>() => Cache<T>;
|
|
380
407
|
import { GroupEvaluationResult } from "@f-o-t/condition-evaluator";
|
|
408
|
+
import { z as z5 } from "zod";
|
|
409
|
+
declare const ConflictResolutionStrategySchema: z5.ZodEnum<{
|
|
410
|
+
priority: "priority";
|
|
411
|
+
"first-match": "first-match";
|
|
412
|
+
all: "all";
|
|
413
|
+
"most-specific": "most-specific";
|
|
414
|
+
}>;
|
|
415
|
+
type ConflictResolutionStrategy = z5.infer<typeof ConflictResolutionStrategySchema>;
|
|
416
|
+
declare const EvaluateOptionsSchema: z5.ZodObject<{
|
|
417
|
+
conflictResolution: z5.ZodOptional<z5.ZodEnum<{
|
|
418
|
+
priority: "priority";
|
|
419
|
+
"first-match": "first-match";
|
|
420
|
+
all: "all";
|
|
421
|
+
"most-specific": "most-specific";
|
|
422
|
+
}>>;
|
|
423
|
+
maxRules: z5.ZodOptional<z5.ZodNumber>;
|
|
424
|
+
timeout: z5.ZodOptional<z5.ZodNumber>;
|
|
425
|
+
skipDisabled: z5.ZodOptional<z5.ZodBoolean>;
|
|
426
|
+
tags: z5.ZodOptional<z5.ZodArray<z5.ZodString>>;
|
|
427
|
+
category: z5.ZodOptional<z5.ZodString>;
|
|
428
|
+
ruleSetId: z5.ZodOptional<z5.ZodString>;
|
|
429
|
+
bypassCache: z5.ZodOptional<z5.ZodBoolean>;
|
|
430
|
+
}, z5.core.$strip>;
|
|
431
|
+
type EvaluateOptions = z5.infer<typeof EvaluateOptionsSchema>;
|
|
432
|
+
declare const EvaluateConfigSchema: z5.ZodObject<{
|
|
433
|
+
conflictResolution: z5.ZodEnum<{
|
|
434
|
+
priority: "priority";
|
|
435
|
+
"first-match": "first-match";
|
|
436
|
+
all: "all";
|
|
437
|
+
"most-specific": "most-specific";
|
|
438
|
+
}>;
|
|
439
|
+
continueOnError: z5.ZodBoolean;
|
|
440
|
+
collectAllConsequences: z5.ZodBoolean;
|
|
441
|
+
}, z5.core.$strip>;
|
|
442
|
+
type EvaluateConfig = z5.infer<typeof EvaluateConfigSchema>;
|
|
381
443
|
type EvaluationContext<TContext = unknown> = {
|
|
382
444
|
readonly data: TContext;
|
|
383
445
|
readonly timestamp: Date;
|
|
@@ -415,22 +477,6 @@ type EngineExecutionResult<
|
|
|
415
477
|
readonly stoppedByRuleId?: string;
|
|
416
478
|
readonly cacheHit: boolean;
|
|
417
479
|
};
|
|
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
480
|
type EvaluateRuleOptions = {
|
|
435
481
|
readonly skipDisabled?: boolean;
|
|
436
482
|
};
|
|
@@ -531,26 +577,37 @@ declare const sortByUpdatedAt: <
|
|
|
531
577
|
TContext = unknown,
|
|
532
578
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
533
579
|
>(direction?: SortDirection) => (rules: readonly Rule<TContext, TConsequences>[]) => readonly Rule<TContext, TConsequences>[];
|
|
534
|
-
|
|
580
|
+
import { z as z6 } from "zod";
|
|
581
|
+
declare const LogLevelSchema: z6.ZodEnum<{
|
|
582
|
+
error: "error";
|
|
583
|
+
none: "none";
|
|
584
|
+
warn: "warn";
|
|
585
|
+
info: "info";
|
|
586
|
+
debug: "debug";
|
|
587
|
+
}>;
|
|
588
|
+
type LogLevel = z6.infer<typeof LogLevelSchema>;
|
|
589
|
+
declare const CacheConfigSchema: z6.ZodObject<{
|
|
590
|
+
enabled: z6.ZodDefault<z6.ZodBoolean>;
|
|
591
|
+
ttl: z6.ZodDefault<z6.ZodNumber>;
|
|
592
|
+
maxSize: z6.ZodDefault<z6.ZodNumber>;
|
|
593
|
+
}, z6.core.$strip>;
|
|
594
|
+
type CacheConfig = z6.infer<typeof CacheConfigSchema>;
|
|
595
|
+
declare const ValidationConfigSchema: z6.ZodObject<{
|
|
596
|
+
enabled: z6.ZodDefault<z6.ZodBoolean>;
|
|
597
|
+
strict: z6.ZodDefault<z6.ZodBoolean>;
|
|
598
|
+
}, z6.core.$strip>;
|
|
599
|
+
type ValidationConfig = z6.infer<typeof ValidationConfigSchema>;
|
|
600
|
+
declare const VersioningConfigSchema: z6.ZodObject<{
|
|
601
|
+
enabled: z6.ZodDefault<z6.ZodBoolean>;
|
|
602
|
+
maxVersions: z6.ZodDefault<z6.ZodNumber>;
|
|
603
|
+
}, z6.core.$strip>;
|
|
604
|
+
type VersioningConfig = z6.infer<typeof VersioningConfigSchema>;
|
|
535
605
|
type Logger = {
|
|
536
606
|
readonly error: (...args: unknown[]) => void;
|
|
537
607
|
readonly warn: (...args: unknown[]) => void;
|
|
538
608
|
readonly info: (...args: unknown[]) => void;
|
|
539
609
|
readonly debug: (...args: unknown[]) => void;
|
|
540
610
|
};
|
|
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
611
|
type EngineHooks<
|
|
555
612
|
TContext = unknown,
|
|
556
613
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -566,6 +623,7 @@ type EngineHooks<
|
|
|
566
623
|
readonly onCacheHit?: (key: string, result: EngineExecutionResult<TContext, TConsequences>) => void | Promise<void>;
|
|
567
624
|
readonly onCacheMiss?: (key: string) => void | Promise<void>;
|
|
568
625
|
readonly onSlowRule?: (rule: Rule<TContext, TConsequences>, timeMs: number, threshold: number) => void | Promise<void>;
|
|
626
|
+
readonly onHookError?: (hookName: string, error: Error) => void;
|
|
569
627
|
};
|
|
570
628
|
type EngineConfig<
|
|
571
629
|
TContext = unknown,
|
|
@@ -581,6 +639,7 @@ type EngineConfig<
|
|
|
581
639
|
readonly logger?: Logger;
|
|
582
640
|
readonly continueOnError?: boolean;
|
|
583
641
|
readonly slowRuleThresholdMs?: number;
|
|
642
|
+
readonly hookTimeoutMs?: number;
|
|
584
643
|
};
|
|
585
644
|
type ResolvedEngineConfig<
|
|
586
645
|
TContext = unknown,
|
|
@@ -596,19 +655,16 @@ type ResolvedEngineConfig<
|
|
|
596
655
|
readonly logger: Logger;
|
|
597
656
|
readonly continueOnError: boolean;
|
|
598
657
|
readonly slowRuleThresholdMs: number;
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
declare const
|
|
602
|
-
declare const
|
|
603
|
-
declare const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
continueOnError: boolean;
|
|
610
|
-
slowRuleThresholdMs: number;
|
|
611
|
-
};
|
|
658
|
+
readonly hookTimeoutMs: number | undefined;
|
|
659
|
+
};
|
|
660
|
+
declare const parseCacheConfig: (input?: Partial<CacheConfig>) => CacheConfig;
|
|
661
|
+
declare const parseValidationConfig: (input?: Partial<ValidationConfig>) => ValidationConfig;
|
|
662
|
+
declare const parseVersioningConfig: (input?: Partial<VersioningConfig>) => VersioningConfig;
|
|
663
|
+
declare const getDefaultCacheConfig: () => CacheConfig;
|
|
664
|
+
declare const getDefaultValidationConfig: () => ValidationConfig;
|
|
665
|
+
declare const getDefaultVersioningConfig: () => VersioningConfig;
|
|
666
|
+
declare const getDefaultLogLevel: () => LogLevel;
|
|
667
|
+
declare const getDefaultConflictResolution: () => ConflictResolutionStrategy;
|
|
612
668
|
type Engine<
|
|
613
669
|
TContext = unknown,
|
|
614
670
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -832,6 +888,11 @@ type ImportOptions = {
|
|
|
832
888
|
readonly preserveDates?: boolean;
|
|
833
889
|
readonly validateSchema?: boolean;
|
|
834
890
|
};
|
|
891
|
+
type OrphanedReference = {
|
|
892
|
+
readonly ruleSetId: string;
|
|
893
|
+
readonly ruleSetName: string;
|
|
894
|
+
readonly missingRuleIds: ReadonlyArray<string>;
|
|
895
|
+
};
|
|
835
896
|
type ImportResult<
|
|
836
897
|
TContext = unknown,
|
|
837
898
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
@@ -845,6 +906,7 @@ type ImportResult<
|
|
|
845
906
|
message: string;
|
|
846
907
|
}>;
|
|
847
908
|
readonly idMapping: ReadonlyMap<string, string>;
|
|
909
|
+
readonly orphanedReferences: ReadonlyArray<OrphanedReference>;
|
|
848
910
|
};
|
|
849
911
|
declare const serializeRule: <
|
|
850
912
|
TContext = unknown,
|
|
@@ -982,82 +1044,6 @@ declare const formatSimulationResult: <
|
|
|
982
1044
|
declare const hashContext: (context: unknown) => string;
|
|
983
1045
|
declare const hashRules: (ruleIds: ReadonlyArray<string>) => string;
|
|
984
1046
|
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
1047
|
type TimingResult<T> = {
|
|
1062
1048
|
readonly result: T;
|
|
1063
1049
|
readonly durationMs: number;
|
|
@@ -1065,7 +1051,6 @@ type TimingResult<T> = {
|
|
|
1065
1051
|
declare const measureTime: <T>(fn: () => T) => TimingResult<T>;
|
|
1066
1052
|
declare const measureTimeAsync: <T>(fn: () => Promise<T>) => Promise<TimingResult<T>>;
|
|
1067
1053
|
declare const withTimeout: <T>(promise: Promise<T>, timeoutMs: number, errorMessage?: string) => Promise<T>;
|
|
1068
|
-
declare const delay: (ms: number) => Promise<void>;
|
|
1069
1054
|
type ConflictType = "DUPLICATE_ID" | "DUPLICATE_CONDITIONS" | "OVERLAPPING_CONDITIONS" | "CONTRADICTORY_CONSEQUENCES" | "PRIORITY_COLLISION" | "UNREACHABLE_RULE";
|
|
1070
1055
|
type Conflict<
|
|
1071
1056
|
TContext = unknown,
|
|
@@ -1157,19 +1142,32 @@ declare const getUsedOperators: <
|
|
|
1157
1142
|
}>;
|
|
1158
1143
|
declare const formatIntegrityResult: (result: IntegrityCheckResult) => string;
|
|
1159
1144
|
import { ConditionGroup as ConditionGroup5 } from "@f-o-t/condition-evaluator";
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1145
|
+
import { z as z7 } from "zod";
|
|
1146
|
+
declare const ValidationErrorSchema: z7.ZodObject<{
|
|
1147
|
+
path: z7.ZodString;
|
|
1148
|
+
message: z7.ZodString;
|
|
1149
|
+
code: z7.ZodString;
|
|
1150
|
+
}, z7.core.$strip>;
|
|
1151
|
+
type ValidationError = z7.infer<typeof ValidationErrorSchema>;
|
|
1152
|
+
declare const ValidationResultSchema: z7.ZodObject<{
|
|
1153
|
+
valid: z7.ZodBoolean;
|
|
1154
|
+
errors: z7.ZodArray<z7.ZodObject<{
|
|
1155
|
+
path: z7.ZodString;
|
|
1156
|
+
message: z7.ZodString;
|
|
1157
|
+
code: z7.ZodString;
|
|
1158
|
+
}, z7.core.$strip>>;
|
|
1159
|
+
}, z7.core.$strip>;
|
|
1160
|
+
type ValidationResult = z7.infer<typeof ValidationResultSchema>;
|
|
1161
|
+
declare const ValidationOptionsSchema: z7.ZodObject<{
|
|
1162
|
+
validateConditions: z7.ZodOptional<z7.ZodBoolean>;
|
|
1163
|
+
validateConsequences: z7.ZodOptional<z7.ZodBoolean>;
|
|
1164
|
+
strictMode: z7.ZodOptional<z7.ZodBoolean>;
|
|
1165
|
+
}, z7.core.$strip>;
|
|
1166
|
+
type ValidationOptions = z7.infer<typeof ValidationOptionsSchema>;
|
|
1167
|
+
type ResolvedValidationOptions = {
|
|
1168
|
+
validateConditions: boolean;
|
|
1169
|
+
validateConsequences: boolean;
|
|
1170
|
+
strictMode: boolean;
|
|
1173
1171
|
};
|
|
1174
1172
|
declare const validateRule: <
|
|
1175
1173
|
TContext = unknown,
|
|
@@ -1207,7 +1205,14 @@ declare const createRuleValidator: <
|
|
|
1207
1205
|
TContext = unknown,
|
|
1208
1206
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
1209
1207
|
>(consequenceSchemas: TConsequences, defaultOptions?: ValidationOptions) => {
|
|
1210
|
-
validate: (rule: unknown, options?: ValidationOptions) =>
|
|
1208
|
+
validate: (rule: unknown, options?: ValidationOptions) => {
|
|
1209
|
+
valid: boolean;
|
|
1210
|
+
errors: {
|
|
1211
|
+
path: string;
|
|
1212
|
+
message: string;
|
|
1213
|
+
code: string;
|
|
1214
|
+
}[];
|
|
1215
|
+
};
|
|
1211
1216
|
parse: (rule: unknown, options?: ValidationOptions) => Rule<TContext, TConsequences>;
|
|
1212
1217
|
safeParse: (rule: unknown, options?: ValidationOptions) => {
|
|
1213
1218
|
success: false;
|
|
@@ -1309,4 +1314,4 @@ declare const formatVersionHistory: <
|
|
|
1309
1314
|
TContext = unknown,
|
|
1310
1315
|
TConsequences extends ConsequenceDefinitions = DefaultConsequences
|
|
1311
1316
|
>(history: VersionHistory<TContext, TConsequences>) => string;
|
|
1312
|
-
export { withTimeout, whatIf, validateRules, validateRuleSet, validateRule, validateConditions, updateRule2 as updateRule,
|
|
1317
|
+
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, Condition3 as Condition, CategoryIndex, CacheStatsSchema, CacheStats, CacheOptions, CacheEntry, CacheConfigSchema, CacheConfig, Cache, BooleanOperator, BooleanCondition, BatchSimulationResult, ArrayOperator, ArrayCondition, AggregatedConsequence };
|