@praxisui/specification 0.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/LICENSE +7 -0
- package/README.md +85 -0
- package/fesm2022/praxisui-specification.mjs +3495 -0
- package/fesm2022/praxisui-specification.mjs.map +1 -0
- package/index.d.ts +894 -0
- package/package.json +36 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
import { Specification, SpecificationMetadata } from '@praxisui/specification-core';
|
|
2
|
+
export * from '@praxisui/specification-core';
|
|
3
|
+
|
|
4
|
+
declare enum ComparisonOperator {
|
|
5
|
+
EQUALS = "eq",
|
|
6
|
+
NOT_EQUALS = "neq",
|
|
7
|
+
LESS_THAN = "lt",
|
|
8
|
+
LESS_THAN_OR_EQUAL = "lte",
|
|
9
|
+
GREATER_THAN = "gt",
|
|
10
|
+
GREATER_THAN_OR_EQUAL = "gte",
|
|
11
|
+
CONTAINS = "contains",
|
|
12
|
+
STARTS_WITH = "startsWith",
|
|
13
|
+
ENDS_WITH = "endsWith",
|
|
14
|
+
IN = "in"
|
|
15
|
+
}
|
|
16
|
+
declare const OPERATOR_SYMBOLS: Record<ComparisonOperator, string>;
|
|
17
|
+
|
|
18
|
+
declare class FieldSpecification<T extends object = any> extends Specification<T> {
|
|
19
|
+
private field;
|
|
20
|
+
private operator;
|
|
21
|
+
private value;
|
|
22
|
+
constructor(field: keyof T, operator: ComparisonOperator, value: any, metadata?: SpecificationMetadata);
|
|
23
|
+
isSatisfiedBy(obj: T): boolean;
|
|
24
|
+
toJSON(): any;
|
|
25
|
+
static fromJSON<T extends object = any>(json: any): FieldSpecification<T>;
|
|
26
|
+
clone(): FieldSpecification<T>;
|
|
27
|
+
toDSL(): string;
|
|
28
|
+
getField(): keyof T;
|
|
29
|
+
getOperator(): ComparisonOperator;
|
|
30
|
+
getValue(): any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare class AndSpecification<T extends object = any> extends Specification<T> {
|
|
34
|
+
private specifications;
|
|
35
|
+
constructor(specifications: Specification<T>[], metadata?: SpecificationMetadata);
|
|
36
|
+
isSatisfiedBy(obj: T): boolean;
|
|
37
|
+
toJSON(): any;
|
|
38
|
+
static fromJSON<T extends object = any>(json: any): AndSpecification<T>;
|
|
39
|
+
toDSL(): string;
|
|
40
|
+
getSpecifications(): Specification<T>[];
|
|
41
|
+
add(specification: Specification<T>): AndSpecification<T>;
|
|
42
|
+
clone(): AndSpecification<T>;
|
|
43
|
+
getOperatorKind(): 'and' | 'or' | 'xor' | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class OrSpecification<T extends object = any> extends Specification<T> {
|
|
47
|
+
private specifications;
|
|
48
|
+
constructor(specifications: Specification<T>[], metadata?: SpecificationMetadata);
|
|
49
|
+
isSatisfiedBy(obj: T): boolean;
|
|
50
|
+
toJSON(): any;
|
|
51
|
+
static fromJSON<T extends object = any>(json: any): OrSpecification<T>;
|
|
52
|
+
toDSL(): string;
|
|
53
|
+
getSpecifications(): Specification<T>[];
|
|
54
|
+
add(specification: Specification<T>): OrSpecification<T>;
|
|
55
|
+
clone(): OrSpecification<T>;
|
|
56
|
+
getOperatorKind(): 'and' | 'or' | 'xor' | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class NotSpecification<T extends object = any> extends Specification<T> {
|
|
60
|
+
private specification;
|
|
61
|
+
constructor(specification: Specification<T>, metadata?: SpecificationMetadata);
|
|
62
|
+
isSatisfiedBy(obj: T): boolean;
|
|
63
|
+
toJSON(): any;
|
|
64
|
+
static fromJSON<T extends object = any>(json: any): NotSpecification<T>;
|
|
65
|
+
toDSL(): string;
|
|
66
|
+
getSpecification(): Specification<T>;
|
|
67
|
+
clone(): NotSpecification<T>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare class XorSpecification<T extends object = any> extends Specification<T> {
|
|
71
|
+
private specifications;
|
|
72
|
+
constructor(specifications: Specification<T>[], metadata?: SpecificationMetadata);
|
|
73
|
+
isSatisfiedBy(obj: T): boolean;
|
|
74
|
+
toJSON(): any;
|
|
75
|
+
static fromJSON<T extends object = any>(json: any): XorSpecification<T>;
|
|
76
|
+
toDSL(): string;
|
|
77
|
+
getSpecifications(): Specification<T>[];
|
|
78
|
+
clone(): XorSpecification<T>;
|
|
79
|
+
getOperatorKind(): 'and' | 'or' | 'xor' | undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare class ImpliesSpecification<T extends object = any> extends Specification<T> {
|
|
83
|
+
private antecedent;
|
|
84
|
+
private consequent;
|
|
85
|
+
constructor(antecedent: Specification<T>, consequent: Specification<T>, metadata?: SpecificationMetadata);
|
|
86
|
+
isSatisfiedBy(obj: T): boolean;
|
|
87
|
+
toJSON(): any;
|
|
88
|
+
static fromJSON<T extends object = any>(json: any): ImpliesSpecification<T>;
|
|
89
|
+
toDSL(): string;
|
|
90
|
+
getAntecedent(): Specification<T>;
|
|
91
|
+
getConsequent(): Specification<T>;
|
|
92
|
+
clone(): ImpliesSpecification<T>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type SpecificationFunction<T> = (obj: T, ...args: any[]) => boolean;
|
|
96
|
+
declare class FunctionRegistry<T> {
|
|
97
|
+
private contextKey;
|
|
98
|
+
private static instances;
|
|
99
|
+
private functions;
|
|
100
|
+
private constructor();
|
|
101
|
+
static getInstance<T>(contextKey?: string): FunctionRegistry<T>;
|
|
102
|
+
register(name: string, fn: SpecificationFunction<T>): void;
|
|
103
|
+
unregister(name: string): boolean;
|
|
104
|
+
get(name: string): SpecificationFunction<T> | undefined;
|
|
105
|
+
has(name: string): boolean;
|
|
106
|
+
getAll(): Map<string, SpecificationFunction<T>>;
|
|
107
|
+
clear(): void;
|
|
108
|
+
execute(name: string, obj: T, ...args: any[]): boolean;
|
|
109
|
+
getContextKey(): string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare class FunctionSpecification<T extends object = any> extends Specification<T> {
|
|
113
|
+
private functionName;
|
|
114
|
+
private args;
|
|
115
|
+
private registry?;
|
|
116
|
+
constructor(functionName: string, args: any[], registry?: FunctionRegistry<T> | undefined, metadata?: SpecificationMetadata);
|
|
117
|
+
isSatisfiedBy(obj: T): boolean;
|
|
118
|
+
toJSON(): any;
|
|
119
|
+
static fromJSON<T extends object = any>(json: any, registry?: FunctionRegistry<T>): FunctionSpecification<T>;
|
|
120
|
+
toDSL(): string;
|
|
121
|
+
getFunctionName(): string;
|
|
122
|
+
getArgs(): any[];
|
|
123
|
+
getRegistry(): FunctionRegistry<T> | undefined;
|
|
124
|
+
clone(): FunctionSpecification<T>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare class AtLeastSpecification<T extends object = any> extends Specification<T> {
|
|
128
|
+
private minimum;
|
|
129
|
+
private specifications;
|
|
130
|
+
constructor(minimum: number, specifications: Specification<T>[], metadata?: SpecificationMetadata);
|
|
131
|
+
isSatisfiedBy(obj: T): boolean;
|
|
132
|
+
toJSON(): any;
|
|
133
|
+
static fromJSON<T extends object = any>(json: any): AtLeastSpecification<T>;
|
|
134
|
+
toDSL(): string;
|
|
135
|
+
getMinimum(): number;
|
|
136
|
+
getSpecifications(): Specification<T>[];
|
|
137
|
+
getSatisfiedCount(obj: T): number;
|
|
138
|
+
clone(): AtLeastSpecification<T>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
declare class ExactlySpecification<T extends object = any> extends Specification<T> {
|
|
142
|
+
private exact;
|
|
143
|
+
private specifications;
|
|
144
|
+
constructor(exact: number, specifications: Specification<T>[], metadata?: SpecificationMetadata);
|
|
145
|
+
isSatisfiedBy(obj: T): boolean;
|
|
146
|
+
toJSON(): any;
|
|
147
|
+
static fromJSON<T extends object = any>(json: any): ExactlySpecification<T>;
|
|
148
|
+
toDSL(): string;
|
|
149
|
+
getExact(): number;
|
|
150
|
+
getSpecifications(): Specification<T>[];
|
|
151
|
+
getSatisfiedCount(obj: T): number;
|
|
152
|
+
clone(): ExactlySpecification<T>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type TransformFunction = (value: any) => any;
|
|
156
|
+
declare class TransformRegistry {
|
|
157
|
+
private static instance;
|
|
158
|
+
private transforms;
|
|
159
|
+
private constructor();
|
|
160
|
+
static getInstance(): TransformRegistry;
|
|
161
|
+
private registerDefaults;
|
|
162
|
+
register(name: string, fn: TransformFunction): void;
|
|
163
|
+
unregister(name: string): boolean;
|
|
164
|
+
get(name: string): TransformFunction | undefined;
|
|
165
|
+
has(name: string): boolean;
|
|
166
|
+
getAll(): Map<string, TransformFunction>;
|
|
167
|
+
clear(): void;
|
|
168
|
+
apply(name: string, value: any): any;
|
|
169
|
+
applyChain(transforms: string[], value: any): any;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
declare class FieldToFieldSpecification<T extends object = any> extends Specification<T> {
|
|
173
|
+
private fieldA;
|
|
174
|
+
private operator;
|
|
175
|
+
private fieldB;
|
|
176
|
+
private transformA?;
|
|
177
|
+
private transformB?;
|
|
178
|
+
private transformRegistry?;
|
|
179
|
+
constructor(fieldA: keyof T, operator: ComparisonOperator, fieldB: keyof T, transformA?: string[] | undefined, transformB?: string[] | undefined, transformRegistry?: TransformRegistry | undefined, metadata?: SpecificationMetadata);
|
|
180
|
+
isSatisfiedBy(obj: T): boolean;
|
|
181
|
+
toJSON(): any;
|
|
182
|
+
static fromJSON<T extends object = any>(json: any, transformRegistry?: TransformRegistry): FieldToFieldSpecification<T>;
|
|
183
|
+
toDSL(): string;
|
|
184
|
+
getFieldA(): keyof T;
|
|
185
|
+
getFieldB(): keyof T;
|
|
186
|
+
getOperator(): ComparisonOperator;
|
|
187
|
+
getTransformA(): string[] | undefined;
|
|
188
|
+
getTransformB(): string[] | undefined;
|
|
189
|
+
clone(): FieldToFieldSpecification<T>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface ContextProvider {
|
|
193
|
+
getValue(path: string): any;
|
|
194
|
+
hasValue(path: string): boolean;
|
|
195
|
+
}
|
|
196
|
+
declare class DefaultContextProvider implements ContextProvider {
|
|
197
|
+
private context;
|
|
198
|
+
constructor(context?: Record<string, any>);
|
|
199
|
+
getValue(path: string): any;
|
|
200
|
+
hasValue(path: string): boolean;
|
|
201
|
+
private getNestedValue;
|
|
202
|
+
setContext(context: Record<string, any>): void;
|
|
203
|
+
updateContext(updates: Record<string, any>): void;
|
|
204
|
+
getContext(): Record<string, any>;
|
|
205
|
+
}
|
|
206
|
+
declare class DateContextProvider implements ContextProvider {
|
|
207
|
+
getValue(path: string): any;
|
|
208
|
+
hasValue(path: string): boolean;
|
|
209
|
+
}
|
|
210
|
+
declare class CompositeContextProvider implements ContextProvider {
|
|
211
|
+
private providers;
|
|
212
|
+
constructor(providers: ContextProvider[]);
|
|
213
|
+
getValue(path: string): any;
|
|
214
|
+
hasValue(path: string): boolean;
|
|
215
|
+
addProvider(provider: ContextProvider): void;
|
|
216
|
+
removeProvider(provider: ContextProvider): void;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class ContextualSpecification<T extends object> extends Specification<T> {
|
|
220
|
+
private template;
|
|
221
|
+
private contextProvider?;
|
|
222
|
+
private static readonly TOKEN_REGEX;
|
|
223
|
+
constructor(template: string, contextProvider?: ContextProvider | undefined, metadata?: SpecificationMetadata);
|
|
224
|
+
isSatisfiedBy(obj: T): boolean;
|
|
225
|
+
toJSON(): any;
|
|
226
|
+
static fromJSON<T extends object>(json: any, contextProvider?: ContextProvider): ContextualSpecification<T>;
|
|
227
|
+
toDSL(): string;
|
|
228
|
+
resolveTokens(template: string, obj: T): string;
|
|
229
|
+
private valueToString;
|
|
230
|
+
getTemplate(): string;
|
|
231
|
+
getContextProvider(): ContextProvider | undefined;
|
|
232
|
+
setContextProvider(provider: ContextProvider): ContextualSpecification<T>;
|
|
233
|
+
getTokens(): string[];
|
|
234
|
+
clone(): ContextualSpecification<T>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Types of conditional validation
|
|
239
|
+
*/
|
|
240
|
+
declare enum ConditionalType {
|
|
241
|
+
REQUIRED_IF = "requiredIf",
|
|
242
|
+
VISIBLE_IF = "visibleIf",
|
|
243
|
+
DISABLED_IF = "disabledIf",
|
|
244
|
+
READONLY_IF = "readonlyIf"
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Base class for conditional validators
|
|
248
|
+
*/
|
|
249
|
+
declare abstract class ConditionalSpecification<T extends object = any> extends Specification<T> {
|
|
250
|
+
protected condition: Specification<T>;
|
|
251
|
+
protected conditionalType: ConditionalType;
|
|
252
|
+
constructor(condition: Specification<T>, conditionalType: ConditionalType, metadata?: SpecificationMetadata);
|
|
253
|
+
getCondition(): Specification<T>;
|
|
254
|
+
getConditionalType(): ConditionalType;
|
|
255
|
+
abstract clone(): ConditionalSpecification<T>;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Validates that a field is required when a condition is met
|
|
259
|
+
*/
|
|
260
|
+
declare class RequiredIfSpecification<T extends object = any> extends ConditionalSpecification<T> {
|
|
261
|
+
private field;
|
|
262
|
+
constructor(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata);
|
|
263
|
+
isSatisfiedBy(obj: T): boolean;
|
|
264
|
+
toJSON(): any;
|
|
265
|
+
static fromJSON<T extends object = any>(json: any): RequiredIfSpecification<T>;
|
|
266
|
+
toDSL(): string;
|
|
267
|
+
clone(): RequiredIfSpecification<T>;
|
|
268
|
+
getField(): keyof T;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Determines if a field should be visible based on a condition
|
|
272
|
+
*/
|
|
273
|
+
declare class VisibleIfSpecification<T extends object = any> extends ConditionalSpecification<T> {
|
|
274
|
+
private field;
|
|
275
|
+
constructor(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata);
|
|
276
|
+
isSatisfiedBy(obj: T): boolean;
|
|
277
|
+
toJSON(): any;
|
|
278
|
+
static fromJSON<T extends object = any>(json: any): VisibleIfSpecification<T>;
|
|
279
|
+
toDSL(): string;
|
|
280
|
+
clone(): VisibleIfSpecification<T>;
|
|
281
|
+
getField(): keyof T;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Determines if a field should be disabled based on a condition
|
|
285
|
+
*/
|
|
286
|
+
declare class DisabledIfSpecification<T extends object = any> extends ConditionalSpecification<T> {
|
|
287
|
+
private field;
|
|
288
|
+
constructor(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata);
|
|
289
|
+
isSatisfiedBy(obj: T): boolean;
|
|
290
|
+
toJSON(): any;
|
|
291
|
+
static fromJSON<T extends object = any>(json: any): DisabledIfSpecification<T>;
|
|
292
|
+
toDSL(): string;
|
|
293
|
+
clone(): DisabledIfSpecification<T>;
|
|
294
|
+
getField(): keyof T;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Determines if a field should be readonly based on a condition
|
|
298
|
+
*/
|
|
299
|
+
declare class ReadonlyIfSpecification<T extends object = any> extends ConditionalSpecification<T> {
|
|
300
|
+
private field;
|
|
301
|
+
constructor(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata);
|
|
302
|
+
isSatisfiedBy(obj: T): boolean;
|
|
303
|
+
toJSON(): any;
|
|
304
|
+
static fromJSON<T extends object = any>(json: any): ReadonlyIfSpecification<T>;
|
|
305
|
+
toDSL(): string;
|
|
306
|
+
clone(): ReadonlyIfSpecification<T>;
|
|
307
|
+
getField(): keyof T;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Applies a specification to all elements in an array field
|
|
312
|
+
*/
|
|
313
|
+
declare class ForEachSpecification<T extends object = any, TItem extends object = any> extends Specification<T> {
|
|
314
|
+
private arrayField;
|
|
315
|
+
private itemSpecification;
|
|
316
|
+
constructor(arrayField: keyof T, itemSpecification: Specification<TItem>, metadata?: SpecificationMetadata);
|
|
317
|
+
isSatisfiedBy(obj: T): boolean;
|
|
318
|
+
toJSON(): any;
|
|
319
|
+
static fromJSON<T extends object = any>(json: any): ForEachSpecification<T>;
|
|
320
|
+
toDSL(): string;
|
|
321
|
+
clone(): ForEachSpecification<T, TItem>;
|
|
322
|
+
getArrayField(): keyof T;
|
|
323
|
+
getItemSpecification(): Specification<TItem>;
|
|
324
|
+
/**
|
|
325
|
+
* Gets items that fail the specification
|
|
326
|
+
*/
|
|
327
|
+
getFailingItems(obj: T): {
|
|
328
|
+
index: number;
|
|
329
|
+
item: any;
|
|
330
|
+
errors?: string[];
|
|
331
|
+
}[];
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Ensures all items in an array are unique based on a field or key selector
|
|
335
|
+
*/
|
|
336
|
+
declare class UniqueBySpecification<T extends object = any> extends Specification<T> {
|
|
337
|
+
private arrayField;
|
|
338
|
+
private keySelector;
|
|
339
|
+
constructor(arrayField: keyof T, keySelector: string | ((item: any) => any), metadata?: SpecificationMetadata);
|
|
340
|
+
isSatisfiedBy(obj: T): boolean;
|
|
341
|
+
toJSON(): any;
|
|
342
|
+
static fromJSON<T extends object = any>(json: any): UniqueBySpecification<T>;
|
|
343
|
+
toDSL(): string;
|
|
344
|
+
clone(): UniqueBySpecification<T>;
|
|
345
|
+
getArrayField(): keyof T;
|
|
346
|
+
getKeySelector(): string | ((item: any) => any);
|
|
347
|
+
/**
|
|
348
|
+
* Gets duplicate items found in the array
|
|
349
|
+
*/
|
|
350
|
+
getDuplicates(obj: T): {
|
|
351
|
+
key: any;
|
|
352
|
+
items: {
|
|
353
|
+
index: number;
|
|
354
|
+
item: any;
|
|
355
|
+
}[];
|
|
356
|
+
}[];
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Validates that an array has a minimum number of elements
|
|
360
|
+
*/
|
|
361
|
+
declare class MinLengthSpecification<T extends object = any> extends Specification<T> {
|
|
362
|
+
private arrayField;
|
|
363
|
+
private minLength;
|
|
364
|
+
constructor(arrayField: keyof T, minLength: number, metadata?: SpecificationMetadata);
|
|
365
|
+
isSatisfiedBy(obj: T): boolean;
|
|
366
|
+
toJSON(): any;
|
|
367
|
+
static fromJSON<T extends object = any>(json: any): MinLengthSpecification<T>;
|
|
368
|
+
toDSL(): string;
|
|
369
|
+
clone(): MinLengthSpecification<T>;
|
|
370
|
+
getArrayField(): keyof T;
|
|
371
|
+
getMinLength(): number;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Validates that an array has a maximum number of elements
|
|
375
|
+
*/
|
|
376
|
+
declare class MaxLengthSpecification<T extends object = any> extends Specification<T> {
|
|
377
|
+
private arrayField;
|
|
378
|
+
private maxLength;
|
|
379
|
+
constructor(arrayField: keyof T, maxLength: number, metadata?: SpecificationMetadata);
|
|
380
|
+
isSatisfiedBy(obj: T): boolean;
|
|
381
|
+
toJSON(): any;
|
|
382
|
+
static fromJSON<T extends object = any>(json: any): MaxLengthSpecification<T>;
|
|
383
|
+
toDSL(): string;
|
|
384
|
+
clone(): MaxLengthSpecification<T>;
|
|
385
|
+
getArrayField(): keyof T;
|
|
386
|
+
getMaxLength(): number;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Only applies the inner specification if the field is defined (not null, undefined, or empty)
|
|
391
|
+
*/
|
|
392
|
+
declare class IfDefinedSpecification<T extends object = any> extends Specification<T> {
|
|
393
|
+
private field;
|
|
394
|
+
private innerSpecification;
|
|
395
|
+
constructor(field: keyof T, innerSpecification: Specification<T>, metadata?: SpecificationMetadata);
|
|
396
|
+
isSatisfiedBy(obj: T): boolean;
|
|
397
|
+
private isUndefined;
|
|
398
|
+
toJSON(): any;
|
|
399
|
+
static fromJSON<T extends object = any>(json: any): IfDefinedSpecification<T>;
|
|
400
|
+
toDSL(): string;
|
|
401
|
+
clone(): IfDefinedSpecification<T>;
|
|
402
|
+
getField(): keyof T;
|
|
403
|
+
getInnerSpecification(): Specification<T>;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Only applies the inner specification if the field value is not null
|
|
407
|
+
*/
|
|
408
|
+
declare class IfNotNullSpecification<T extends object = any> extends Specification<T> {
|
|
409
|
+
private field;
|
|
410
|
+
private innerSpecification;
|
|
411
|
+
constructor(field: keyof T, innerSpecification: Specification<T>, metadata?: SpecificationMetadata);
|
|
412
|
+
isSatisfiedBy(obj: T): boolean;
|
|
413
|
+
toJSON(): any;
|
|
414
|
+
static fromJSON<T extends object = any>(json: any): IfNotNullSpecification<T>;
|
|
415
|
+
toDSL(): string;
|
|
416
|
+
clone(): IfNotNullSpecification<T>;
|
|
417
|
+
getField(): keyof T;
|
|
418
|
+
getInnerSpecification(): Specification<T>;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Only applies the inner specification if the field exists as a property on the object
|
|
422
|
+
*/
|
|
423
|
+
declare class IfExistsSpecification<T extends object = any> extends Specification<T> {
|
|
424
|
+
private field;
|
|
425
|
+
private innerSpecification;
|
|
426
|
+
constructor(field: keyof T, innerSpecification: Specification<T>, metadata?: SpecificationMetadata);
|
|
427
|
+
isSatisfiedBy(obj: T): boolean;
|
|
428
|
+
toJSON(): any;
|
|
429
|
+
static fromJSON<T extends object = any>(json: any): IfExistsSpecification<T>;
|
|
430
|
+
toDSL(): string;
|
|
431
|
+
clone(): IfExistsSpecification<T>;
|
|
432
|
+
getField(): keyof T;
|
|
433
|
+
getInnerSpecification(): Specification<T>;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Provides a default value for a field if it's undefined, then applies the specification
|
|
437
|
+
*/
|
|
438
|
+
declare class WithDefaultSpecification<T extends object = any> extends Specification<T> {
|
|
439
|
+
private field;
|
|
440
|
+
private defaultValue;
|
|
441
|
+
private innerSpecification;
|
|
442
|
+
constructor(field: keyof T, defaultValue: any, innerSpecification: Specification<T>, metadata?: SpecificationMetadata);
|
|
443
|
+
isSatisfiedBy(obj: T): boolean;
|
|
444
|
+
private isUndefined;
|
|
445
|
+
toJSON(): any;
|
|
446
|
+
static fromJSON<T extends object = any>(json: any): WithDefaultSpecification<T>;
|
|
447
|
+
toDSL(): string;
|
|
448
|
+
clone(): WithDefaultSpecification<T>;
|
|
449
|
+
getField(): keyof T;
|
|
450
|
+
getDefaultValue(): any;
|
|
451
|
+
getInnerSpecification(): Specification<T>;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Form validation result for a specific field
|
|
456
|
+
*/
|
|
457
|
+
interface FieldValidationResult {
|
|
458
|
+
field: string;
|
|
459
|
+
isValid: boolean;
|
|
460
|
+
errors: string[];
|
|
461
|
+
warnings: string[];
|
|
462
|
+
metadata?: SpecificationMetadata;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Complete form validation result
|
|
466
|
+
*/
|
|
467
|
+
interface FormValidationResult {
|
|
468
|
+
isValid: boolean;
|
|
469
|
+
fields: Record<string, FieldValidationResult>;
|
|
470
|
+
globalErrors: string[];
|
|
471
|
+
warnings: string[];
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Field rules configuration
|
|
475
|
+
*/
|
|
476
|
+
interface FieldRules<T extends object = any> {
|
|
477
|
+
validation?: Specification<T>[];
|
|
478
|
+
required?: boolean | Specification<T>;
|
|
479
|
+
visible?: boolean | Specification<T>;
|
|
480
|
+
disabled?: boolean | Specification<T>;
|
|
481
|
+
readonly?: boolean | Specification<T>;
|
|
482
|
+
metadata?: SpecificationMetadata;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Form specification that manages validation rules for multiple fields
|
|
486
|
+
*/
|
|
487
|
+
declare class FormSpecification<T extends object = any> extends Specification<T> {
|
|
488
|
+
private fieldRules;
|
|
489
|
+
private globalValidations;
|
|
490
|
+
constructor(metadata?: SpecificationMetadata);
|
|
491
|
+
/**
|
|
492
|
+
* Adds validation rules for a specific field
|
|
493
|
+
*/
|
|
494
|
+
addFieldRules(field: keyof T, rules: FieldRules<T>): FormSpecification<T>;
|
|
495
|
+
/**
|
|
496
|
+
* Adds a global validation rule that applies to the entire form
|
|
497
|
+
*/
|
|
498
|
+
addGlobalValidation(specification: Specification<T>): FormSpecification<T>;
|
|
499
|
+
/**
|
|
500
|
+
* Sets required condition for a field
|
|
501
|
+
*/
|
|
502
|
+
setRequired(field: keyof T, condition: boolean | Specification<T>): FormSpecification<T>;
|
|
503
|
+
/**
|
|
504
|
+
* Sets visibility condition for a field
|
|
505
|
+
*/
|
|
506
|
+
setVisible(field: keyof T, condition: boolean | Specification<T>): FormSpecification<T>;
|
|
507
|
+
/**
|
|
508
|
+
* Sets disabled condition for a field
|
|
509
|
+
*/
|
|
510
|
+
setDisabled(field: keyof T, condition: boolean | Specification<T>): FormSpecification<T>;
|
|
511
|
+
/**
|
|
512
|
+
* Sets readonly condition for a field
|
|
513
|
+
*/
|
|
514
|
+
setReadonly(field: keyof T, condition: boolean | Specification<T>): FormSpecification<T>;
|
|
515
|
+
/**
|
|
516
|
+
* Basic satisfaction check - validates all rules
|
|
517
|
+
*/
|
|
518
|
+
isSatisfiedBy(obj: T): boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Comprehensive form validation with detailed results
|
|
521
|
+
*/
|
|
522
|
+
validateForm(obj: T): FormValidationResult;
|
|
523
|
+
private validateField;
|
|
524
|
+
/**
|
|
525
|
+
* Checks if a field should be visible
|
|
526
|
+
*/
|
|
527
|
+
isFieldVisible(field: keyof T, rules: FieldRules<T> | undefined, obj: T): boolean;
|
|
528
|
+
/**
|
|
529
|
+
* Checks if a field should be disabled
|
|
530
|
+
*/
|
|
531
|
+
isFieldDisabled(field: keyof T, obj: T): boolean;
|
|
532
|
+
/**
|
|
533
|
+
* Checks if a field should be readonly
|
|
534
|
+
*/
|
|
535
|
+
isFieldReadonly(field: keyof T, obj: T): boolean;
|
|
536
|
+
/**
|
|
537
|
+
* Gets all configured fields
|
|
538
|
+
*/
|
|
539
|
+
getFields(): (keyof T)[];
|
|
540
|
+
/**
|
|
541
|
+
* Gets rules for a specific field
|
|
542
|
+
*/
|
|
543
|
+
getFieldRules(field: keyof T): FieldRules<T> | undefined;
|
|
544
|
+
toJSON(): any;
|
|
545
|
+
static fromJSON<T extends object = any>(json: any): FormSpecification<T>;
|
|
546
|
+
toDSL(): string;
|
|
547
|
+
clone(): FormSpecification<T>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
declare enum TokenType {
|
|
551
|
+
IDENTIFIER = "IDENTIFIER",
|
|
552
|
+
STRING = "STRING",
|
|
553
|
+
NUMBER = "NUMBER",
|
|
554
|
+
BOOLEAN = "BOOLEAN",
|
|
555
|
+
NULL = "NULL",
|
|
556
|
+
AND = "AND",
|
|
557
|
+
OR = "OR",
|
|
558
|
+
NOT = "NOT",
|
|
559
|
+
XOR = "XOR",
|
|
560
|
+
IMPLIES = "IMPLIES",
|
|
561
|
+
EQUALS = "EQUALS",
|
|
562
|
+
NOT_EQUALS = "NOT_EQUALS",
|
|
563
|
+
LESS_THAN = "LESS_THAN",
|
|
564
|
+
LESS_THAN_OR_EQUAL = "LESS_THAN_OR_EQUAL",
|
|
565
|
+
GREATER_THAN = "GREATER_THAN",
|
|
566
|
+
GREATER_THAN_OR_EQUAL = "GREATER_THAN_OR_EQUAL",
|
|
567
|
+
IN = "IN",
|
|
568
|
+
CONTAINS = "CONTAINS",
|
|
569
|
+
STARTS_WITH = "STARTS_WITH",
|
|
570
|
+
ENDS_WITH = "ENDS_WITH",
|
|
571
|
+
AT_LEAST = "AT_LEAST",
|
|
572
|
+
EXACTLY = "EXACTLY",
|
|
573
|
+
LEFT_PAREN = "LEFT_PAREN",
|
|
574
|
+
RIGHT_PAREN = "RIGHT_PAREN",
|
|
575
|
+
LEFT_BRACKET = "LEFT_BRACKET",
|
|
576
|
+
RIGHT_BRACKET = "RIGHT_BRACKET",
|
|
577
|
+
COMMA = "COMMA",
|
|
578
|
+
DOT = "DOT",
|
|
579
|
+
FIELD_REFERENCE = "FIELD_REFERENCE",// ${field}
|
|
580
|
+
EOF = "EOF",
|
|
581
|
+
WHITESPACE = "WHITESPACE"
|
|
582
|
+
}
|
|
583
|
+
interface Token {
|
|
584
|
+
type: TokenType;
|
|
585
|
+
value: string;
|
|
586
|
+
position: number;
|
|
587
|
+
line: number;
|
|
588
|
+
column: number;
|
|
589
|
+
}
|
|
590
|
+
declare const OPERATOR_KEYWORDS: Record<string, TokenType>;
|
|
591
|
+
declare const COMPARISON_OPERATORS: Record<string, TokenType>;
|
|
592
|
+
|
|
593
|
+
declare class DslTokenizer {
|
|
594
|
+
private input;
|
|
595
|
+
private position;
|
|
596
|
+
private line;
|
|
597
|
+
private column;
|
|
598
|
+
constructor(input: string);
|
|
599
|
+
tokenize(): Token[];
|
|
600
|
+
private nextToken;
|
|
601
|
+
private readFieldReference;
|
|
602
|
+
private readString;
|
|
603
|
+
private readNumber;
|
|
604
|
+
private readIdentifier;
|
|
605
|
+
private skipWhitespace;
|
|
606
|
+
private createToken;
|
|
607
|
+
private createTokenAndAdvance;
|
|
608
|
+
private advance;
|
|
609
|
+
private peek;
|
|
610
|
+
private isDigit;
|
|
611
|
+
private isAlpha;
|
|
612
|
+
private isAlphaNumeric;
|
|
613
|
+
private isWhitespace;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
declare class DslParser<T extends object = any> {
|
|
617
|
+
private functionRegistry?;
|
|
618
|
+
private tokens;
|
|
619
|
+
private current;
|
|
620
|
+
constructor(functionRegistry?: FunctionRegistry<T> | undefined);
|
|
621
|
+
parse(input: string): Specification<T>;
|
|
622
|
+
private parseExpression;
|
|
623
|
+
private parseImplies;
|
|
624
|
+
private parseXor;
|
|
625
|
+
private parseOr;
|
|
626
|
+
private parseAnd;
|
|
627
|
+
private parseUnary;
|
|
628
|
+
private parseComparison;
|
|
629
|
+
private parsePrimary;
|
|
630
|
+
private parseFunctionCall;
|
|
631
|
+
private parseArgument;
|
|
632
|
+
private matchComparison;
|
|
633
|
+
private tokenTypeToComparisonOperator;
|
|
634
|
+
private functionNameToOperator;
|
|
635
|
+
private extractValue;
|
|
636
|
+
private match;
|
|
637
|
+
private check;
|
|
638
|
+
private advance;
|
|
639
|
+
private isAtEnd;
|
|
640
|
+
private peek;
|
|
641
|
+
private previous;
|
|
642
|
+
private consume;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
interface ExportOptions {
|
|
646
|
+
prettyPrint?: boolean;
|
|
647
|
+
indentSize?: number;
|
|
648
|
+
maxLineLength?: number;
|
|
649
|
+
useParentheses?: 'minimal' | 'explicit' | 'auto';
|
|
650
|
+
includeMetadata?: boolean;
|
|
651
|
+
metadataPosition?: 'before' | 'after' | 'inline';
|
|
652
|
+
}
|
|
653
|
+
declare class DslExporter {
|
|
654
|
+
private options;
|
|
655
|
+
constructor(options?: ExportOptions);
|
|
656
|
+
export<T extends object = any>(specification: Specification<T>): string;
|
|
657
|
+
/**
|
|
658
|
+
* Exports specification with metadata comments
|
|
659
|
+
*/
|
|
660
|
+
exportWithMetadata<T extends object = any>(specification: Specification<T>): string;
|
|
661
|
+
private exportSpecification;
|
|
662
|
+
private getSpecificationDsl;
|
|
663
|
+
private addMetadataComments;
|
|
664
|
+
private exportFieldSpecification;
|
|
665
|
+
private exportAndSpecification;
|
|
666
|
+
private exportOrSpecification;
|
|
667
|
+
private exportNotSpecification;
|
|
668
|
+
private exportXorSpecification;
|
|
669
|
+
private exportImpliesSpecification;
|
|
670
|
+
private exportFunctionSpecification;
|
|
671
|
+
private exportAtLeastSpecification;
|
|
672
|
+
private exportExactlySpecification;
|
|
673
|
+
private exportFieldToFieldSpecification;
|
|
674
|
+
private exportContextualSpecification;
|
|
675
|
+
private needsParentheses;
|
|
676
|
+
private getOperatorPrecedence;
|
|
677
|
+
private getContextPrecedence;
|
|
678
|
+
private shouldBreakLine;
|
|
679
|
+
private formatPretty;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Types of validation issues that can be found in DSL
|
|
684
|
+
*/
|
|
685
|
+
declare enum ValidationIssueType {
|
|
686
|
+
SYNTAX_ERROR = "SyntaxError",
|
|
687
|
+
UNKNOWN_FUNCTION = "UnknownFunction",
|
|
688
|
+
UNKNOWN_OPERATOR = "UnknownOperator",
|
|
689
|
+
UNBALANCED_PARENTHESES = "UnbalancedParentheses",
|
|
690
|
+
UNBALANCED_BRACKETS = "UnbalancedBrackets",
|
|
691
|
+
INVALID_TOKEN = "InvalidToken",
|
|
692
|
+
UNEXPECTED_TOKEN = "UnexpectedToken",
|
|
693
|
+
MISSING_ARGUMENT = "MissingArgument",
|
|
694
|
+
TOO_MANY_ARGUMENTS = "TooManyArguments",
|
|
695
|
+
INVALID_FIELD_REFERENCE = "InvalidFieldReference",
|
|
696
|
+
EMPTY_EXPRESSION = "EmptyExpression",
|
|
697
|
+
UNTERMINATED_STRING = "UnterminatedString",
|
|
698
|
+
INVALID_NUMBER = "InvalidNumber",
|
|
699
|
+
DEPRECATED_SYNTAX = "DeprecatedSyntax",
|
|
700
|
+
PERFORMANCE_WARNING = "PerformanceWarning"
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Severity levels for validation issues
|
|
704
|
+
*/
|
|
705
|
+
declare enum ValidationSeverity {
|
|
706
|
+
ERROR = "error",
|
|
707
|
+
WARNING = "warning",
|
|
708
|
+
INFO = "info",
|
|
709
|
+
HINT = "hint"
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Represents a validation issue found in DSL code
|
|
713
|
+
*/
|
|
714
|
+
interface ValidationIssue {
|
|
715
|
+
/**
|
|
716
|
+
* Type of the issue
|
|
717
|
+
*/
|
|
718
|
+
type: ValidationIssueType;
|
|
719
|
+
/**
|
|
720
|
+
* Severity level
|
|
721
|
+
*/
|
|
722
|
+
severity: ValidationSeverity;
|
|
723
|
+
/**
|
|
724
|
+
* Human-readable error message
|
|
725
|
+
*/
|
|
726
|
+
message: string;
|
|
727
|
+
/**
|
|
728
|
+
* Position information
|
|
729
|
+
*/
|
|
730
|
+
position: {
|
|
731
|
+
/**
|
|
732
|
+
* Starting index in the input string
|
|
733
|
+
*/
|
|
734
|
+
start: number;
|
|
735
|
+
/**
|
|
736
|
+
* Ending index in the input string
|
|
737
|
+
*/
|
|
738
|
+
end: number;
|
|
739
|
+
/**
|
|
740
|
+
* Line number (1-based)
|
|
741
|
+
*/
|
|
742
|
+
line: number;
|
|
743
|
+
/**
|
|
744
|
+
* Column number (1-based)
|
|
745
|
+
*/
|
|
746
|
+
column: number;
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Suggested fix or correction
|
|
750
|
+
*/
|
|
751
|
+
suggestion?: string;
|
|
752
|
+
/**
|
|
753
|
+
* Additional context or help text
|
|
754
|
+
*/
|
|
755
|
+
help?: string;
|
|
756
|
+
/**
|
|
757
|
+
* Related documentation or examples
|
|
758
|
+
*/
|
|
759
|
+
documentation?: string;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Configuration for DSL validation
|
|
764
|
+
*/
|
|
765
|
+
interface DslValidatorConfig {
|
|
766
|
+
/**
|
|
767
|
+
* Available function names for validation
|
|
768
|
+
*/
|
|
769
|
+
knownFunctions?: string[];
|
|
770
|
+
/**
|
|
771
|
+
* Function registry to check against
|
|
772
|
+
*/
|
|
773
|
+
functionRegistry?: FunctionRegistry<any>;
|
|
774
|
+
/**
|
|
775
|
+
* Known field names for the target type
|
|
776
|
+
*/
|
|
777
|
+
knownFields?: string[];
|
|
778
|
+
/**
|
|
779
|
+
* Maximum expression complexity (number of operators)
|
|
780
|
+
*/
|
|
781
|
+
maxComplexity?: number;
|
|
782
|
+
/**
|
|
783
|
+
* Enable performance warnings
|
|
784
|
+
*/
|
|
785
|
+
enablePerformanceWarnings?: boolean;
|
|
786
|
+
/**
|
|
787
|
+
* Enable deprecated syntax warnings
|
|
788
|
+
*/
|
|
789
|
+
enableDeprecationWarnings?: boolean;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Validates DSL expressions and provides detailed error reporting
|
|
793
|
+
*/
|
|
794
|
+
declare class DslValidator {
|
|
795
|
+
private config;
|
|
796
|
+
private readonly BUILT_IN_FUNCTIONS;
|
|
797
|
+
constructor(config?: DslValidatorConfig);
|
|
798
|
+
/**
|
|
799
|
+
* Validates a DSL expression and returns all issues found
|
|
800
|
+
*/
|
|
801
|
+
validate(input: string): ValidationIssue[];
|
|
802
|
+
private validateBasicStructure;
|
|
803
|
+
private validateBalancedDelimiters;
|
|
804
|
+
private validateStringLiterals;
|
|
805
|
+
private validateTokens;
|
|
806
|
+
private validateSyntax;
|
|
807
|
+
private validateSemantics;
|
|
808
|
+
private validateFunctionArguments;
|
|
809
|
+
private validateComplexity;
|
|
810
|
+
private getExpectedArgumentCount;
|
|
811
|
+
private isOperatorToken;
|
|
812
|
+
private isBinaryOperatorToken;
|
|
813
|
+
private suggestSimilarField;
|
|
814
|
+
private suggestSimilarFunction;
|
|
815
|
+
private findSimilar;
|
|
816
|
+
private levenshteinDistance;
|
|
817
|
+
private getLineColumn;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
declare class SpecificationFactory {
|
|
821
|
+
static fromJSON<T extends object = any>(json: any): Specification<T>;
|
|
822
|
+
static field<T extends object = any>(field: keyof T, operator: ComparisonOperator, value: any): FieldSpecification<T>;
|
|
823
|
+
static and<T extends object = any>(...specs: Specification<T>[]): AndSpecification<T>;
|
|
824
|
+
static or<T extends object = any>(...specs: Specification<T>[]): OrSpecification<T>;
|
|
825
|
+
static not<T extends object = any>(spec: Specification<T>): NotSpecification<T>;
|
|
826
|
+
static xor<T extends object = any>(...specs: Specification<T>[]): XorSpecification<T>;
|
|
827
|
+
static implies<T extends object = any>(antecedent: Specification<T>, consequent: Specification<T>): ImpliesSpecification<T>;
|
|
828
|
+
static func<T extends object = any>(name: string, args: any[], registry?: FunctionRegistry<T>): FunctionSpecification<T>;
|
|
829
|
+
static atLeast<T extends object = any>(minimum: number, specs: Specification<T>[]): AtLeastSpecification<T>;
|
|
830
|
+
static exactly<T extends object = any>(exact: number, specs: Specification<T>[]): ExactlySpecification<T>;
|
|
831
|
+
static fieldToField<T extends object = any>(fieldA: keyof T, operator: ComparisonOperator, fieldB: keyof T, transformA?: string[], transformB?: string[], registry?: TransformRegistry): FieldToFieldSpecification<T>;
|
|
832
|
+
static contextual<T extends object = any>(template: string, provider?: ContextProvider): ContextualSpecification<T>;
|
|
833
|
+
static equals<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
834
|
+
static notEquals<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
835
|
+
static greaterThan<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
836
|
+
static lessThan<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
837
|
+
static contains<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
838
|
+
static startsWith<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
839
|
+
static endsWith<T extends object = any>(field: keyof T, value: any): FieldSpecification<T>;
|
|
840
|
+
static isIn<T extends object = any>(field: keyof T, values: any[]): FieldSpecification<T>;
|
|
841
|
+
static requiredIf<T extends object = any>(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata): RequiredIfSpecification<T>;
|
|
842
|
+
static visibleIf<T extends object = any>(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata): VisibleIfSpecification<T>;
|
|
843
|
+
static disabledIf<T extends object = any>(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata): DisabledIfSpecification<T>;
|
|
844
|
+
static readonlyIf<T extends object = any>(field: keyof T, condition: Specification<T>, metadata?: SpecificationMetadata): ReadonlyIfSpecification<T>;
|
|
845
|
+
static forEach<T extends object = any, TItem extends object = any>(arrayField: keyof T, itemSpecification: Specification<TItem>, metadata?: SpecificationMetadata): ForEachSpecification<T, TItem>;
|
|
846
|
+
static uniqueBy<T extends object = any>(arrayField: keyof T, keySelector: string | ((item: any) => any), metadata?: SpecificationMetadata): UniqueBySpecification<T>;
|
|
847
|
+
static minLength<T extends object = any>(arrayField: keyof T, minLength: number, metadata?: SpecificationMetadata): MinLengthSpecification<T>;
|
|
848
|
+
static maxLength<T extends object = any>(arrayField: keyof T, maxLength: number, metadata?: SpecificationMetadata): MaxLengthSpecification<T>;
|
|
849
|
+
static ifDefined<T extends object = any>(field: keyof T, specification: Specification<T>, metadata?: SpecificationMetadata): IfDefinedSpecification<T>;
|
|
850
|
+
static ifNotNull<T extends object = any>(field: keyof T, specification: Specification<T>, metadata?: SpecificationMetadata): IfNotNullSpecification<T>;
|
|
851
|
+
static ifExists<T extends object = any>(field: keyof T, specification: Specification<T>, metadata?: SpecificationMetadata): IfExistsSpecification<T>;
|
|
852
|
+
static withDefault<T extends object = any>(field: keyof T, defaultValue: any, specification: Specification<T>, metadata?: SpecificationMetadata): WithDefaultSpecification<T>;
|
|
853
|
+
static form<T extends object = any>(metadata?: SpecificationMetadata): FormSpecification<T>;
|
|
854
|
+
static fieldWithMetadata<T extends object = any>(field: keyof T, operator: ComparisonOperator, value: any, metadata: SpecificationMetadata): FieldSpecification<T>;
|
|
855
|
+
static equalsWithMetadata<T extends object = any>(field: keyof T, value: any, metadata: SpecificationMetadata): FieldSpecification<T>;
|
|
856
|
+
static greaterThanWithMetadata<T extends object = any>(field: keyof T, value: any, metadata: SpecificationMetadata): FieldSpecification<T>;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
declare class SpecificationUtils {
|
|
860
|
+
/**
|
|
861
|
+
* Simplifies a specification by removing redundant nesting and applying logical rules
|
|
862
|
+
*/
|
|
863
|
+
static simplify<T extends object = any>(spec: Specification<T>): Specification<T>;
|
|
864
|
+
private static simplifyAnd;
|
|
865
|
+
private static simplifyOr;
|
|
866
|
+
private static simplifyNot;
|
|
867
|
+
private static removeDuplicates;
|
|
868
|
+
/**
|
|
869
|
+
* Checks if two specifications are logically equivalent
|
|
870
|
+
*/
|
|
871
|
+
static areEquivalent<T extends object = any>(spec1: Specification<T>, spec2: Specification<T>): boolean;
|
|
872
|
+
/**
|
|
873
|
+
* Gets all field references used in a specification
|
|
874
|
+
*/
|
|
875
|
+
static getReferencedFields<T extends object = any>(spec: Specification<T>): Set<keyof T>;
|
|
876
|
+
private static collectFields;
|
|
877
|
+
/**
|
|
878
|
+
* Validates a specification for common issues
|
|
879
|
+
*/
|
|
880
|
+
static validate<T extends object = any>(spec: Specification<T>): ValidationResult;
|
|
881
|
+
private static validateSpecification;
|
|
882
|
+
/**
|
|
883
|
+
* Estimates the complexity of a specification (useful for performance analysis)
|
|
884
|
+
*/
|
|
885
|
+
static getComplexity<T extends object = any>(spec: Specification<T>): number;
|
|
886
|
+
}
|
|
887
|
+
interface ValidationResult {
|
|
888
|
+
isValid: boolean;
|
|
889
|
+
errors: string[];
|
|
890
|
+
warnings: string[];
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
export { AndSpecification, AtLeastSpecification, COMPARISON_OPERATORS, ComparisonOperator, CompositeContextProvider, ConditionalSpecification, ConditionalType, ContextualSpecification, DateContextProvider, DefaultContextProvider, DisabledIfSpecification, DslExporter, DslParser, DslTokenizer, DslValidator, ExactlySpecification, FieldSpecification, FieldToFieldSpecification, ForEachSpecification, FormSpecification, FunctionRegistry, FunctionSpecification, IfDefinedSpecification, IfExistsSpecification, IfNotNullSpecification, ImpliesSpecification, MaxLengthSpecification, MinLengthSpecification, NotSpecification, OPERATOR_KEYWORDS, OPERATOR_SYMBOLS, OrSpecification, ReadonlyIfSpecification, RequiredIfSpecification, SpecificationFactory, SpecificationUtils, TokenType, TransformRegistry, UniqueBySpecification, ValidationIssueType, ValidationSeverity, VisibleIfSpecification, WithDefaultSpecification, XorSpecification };
|
|
894
|
+
export type { ContextProvider, DslValidatorConfig, ExportOptions, FieldRules, FieldValidationResult, FormValidationResult, SpecificationFunction, Token, TransformFunction, ValidationIssue, ValidationResult };
|