@regle/core 1.1.0-beta.2 → 1.1.0-beta.3

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.
@@ -1,2536 +0,0 @@
1
- import { Ref, MaybeRef, UnwrapRef, UnwrapNestedRefs, Raw, MaybeRefOrGetter } from 'vue';
2
-
3
- type Prettify<T> = T extends infer R ? {
4
- [K in keyof R]: R[K];
5
- } & {} : never;
6
- type Maybe<T = any> = T | null | undefined;
7
- type MaybeInput<T = any> = T | null | undefined;
8
- type MaybeOutput<T = any> = T | undefined;
9
- type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
10
- type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
11
- type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
12
- type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
13
- type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date ? false : NonNullable<T> extends Record<string, any> ? true : false;
14
- type OmitByType<T extends Record<string, any>, U> = {
15
- [K in keyof T as T[K] extends U ? never : K]: T[K];
16
- };
17
- type DeepMaybeRef<T extends Record<string, any>> = {
18
- [K in keyof T]: MaybeRef<T[K]>;
19
- };
20
- type ExcludeByType<T, U> = {
21
- [K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K];
22
- };
23
- type PrimitiveTypes = string | number | boolean | bigint | Date | File;
24
- type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File ? false : NonNullable<T> extends Record<string, any> ? true : false;
25
- type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
26
-
27
- type ArrayElement<T> = T extends Array<infer U> ? U : never;
28
-
29
- /**
30
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
31
-
32
- @category Type
33
- */
34
- type Primitive =
35
- | null
36
- | undefined
37
- | string
38
- | number
39
- | boolean
40
- | symbol
41
- | bigint;
42
-
43
- declare global {
44
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
45
- interface SymbolConstructor {
46
- readonly observable: symbol;
47
- }
48
- }
49
-
50
- /**
51
- Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
52
-
53
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
54
-
55
- @example
56
- ```
57
- import type {UnionToIntersection} from 'type-fest';
58
-
59
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
60
-
61
- type Intersection = UnionToIntersection<Union>;
62
- //=> {the(): void; great(arg: string): void; escape: boolean};
63
- ```
64
-
65
- A more applicable example which could make its way into your library code follows.
66
-
67
- @example
68
- ```
69
- import type {UnionToIntersection} from 'type-fest';
70
-
71
- class CommandOne {
72
- commands: {
73
- a1: () => undefined,
74
- b1: () => undefined,
75
- }
76
- }
77
-
78
- class CommandTwo {
79
- commands: {
80
- a2: (argA: string) => undefined,
81
- b2: (argB: string) => undefined,
82
- }
83
- }
84
-
85
- const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
86
- type Union = typeof union;
87
- //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
88
-
89
- type Intersection = UnionToIntersection<Union>;
90
- //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
91
- ```
92
-
93
- @category Type
94
- */
95
- type UnionToIntersection$1<Union> = (
96
- // `extends unknown` is always going to be the case and is used to convert the
97
- // `Union` into a [distributive conditional
98
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
99
- Union extends unknown
100
- // The union type is used as the only argument to a function since the union
101
- // of function arguments is an intersection.
102
- ? (distributedUnion: Union) => void
103
- // This won't happen.
104
- : never
105
- // Infer the `Intersection` type since TypeScript represents the positional
106
- // arguments of unions of functions as an intersection of the union.
107
- ) extends ((mergedIntersection: infer Intersection) => void)
108
- // The `& Union` is to allow indexing by the resulting type
109
- ? Intersection & Union
110
- : never;
111
-
112
- declare const emptyObjectSymbol: unique symbol;
113
-
114
- /**
115
- Represents a strictly empty plain object, the `{}` value.
116
-
117
- When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
118
-
119
- @example
120
- ```
121
- import type {EmptyObject} from 'type-fest';
122
-
123
- // The following illustrates the problem with `{}`.
124
- const foo1: {} = {}; // Pass
125
- const foo2: {} = []; // Pass
126
- const foo3: {} = 42; // Pass
127
- const foo4: {} = {a: 1}; // Pass
128
-
129
- // With `EmptyObject` only the first case is valid.
130
- const bar1: EmptyObject = {}; // Pass
131
- const bar2: EmptyObject = 42; // Fail
132
- const bar3: EmptyObject = []; // Fail
133
- const bar4: EmptyObject = {a: 1}; // Fail
134
- ```
135
-
136
- Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
137
-
138
- @category Object
139
- */
140
- type EmptyObject = {[emptyObjectSymbol]?: never};
141
-
142
- /**
143
- Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
144
-
145
- @example
146
- ```
147
- import type {IsEmptyObject} from 'type-fest';
148
-
149
- type Pass = IsEmptyObject<{}>; //=> true
150
- type Fail = IsEmptyObject<[]>; //=> false
151
- type Fail = IsEmptyObject<null>; //=> false
152
- ```
153
-
154
- @see EmptyObject
155
- @category Object
156
- */
157
- type IsEmptyObject<T> = T extends EmptyObject ? true : false;
158
-
159
- /**
160
- Extract all required keys from the given type.
161
-
162
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
163
-
164
- @example
165
- ```
166
- import type {RequiredKeysOf} from 'type-fest';
167
-
168
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
169
-
170
- interface User {
171
- name: string;
172
- surname: string;
173
-
174
- luckyNumber?: number;
175
- }
176
-
177
- const validator1 = createValidation<User>('name', value => value.length < 25);
178
- const validator2 = createValidation<User>('surname', value => value.length < 25);
179
- ```
180
-
181
- @category Utilities
182
- */
183
- type RequiredKeysOf<BaseType extends object> = Exclude<{
184
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
185
- ? Key
186
- : never
187
- }[keyof BaseType], undefined>;
188
-
189
- /**
190
- Returns a boolean for whether the given type is `never`.
191
-
192
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
193
- @link https://stackoverflow.com/a/53984913/10292952
194
- @link https://www.zhenghao.io/posts/ts-never
195
-
196
- Useful in type utilities, such as checking if something does not occur.
197
-
198
- @example
199
- ```
200
- import type {IsNever, And} from 'type-fest';
201
-
202
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
203
- type AreStringsEqual<A extends string, B extends string> =
204
- And<
205
- IsNever<Exclude<A, B>> extends true ? true : false,
206
- IsNever<Exclude<B, A>> extends true ? true : false
207
- >;
208
-
209
- type EndIfEqual<I extends string, O extends string> =
210
- AreStringsEqual<I, O> extends true
211
- ? never
212
- : void;
213
-
214
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
215
- if (input === output) {
216
- process.exit(0);
217
- }
218
- }
219
-
220
- endIfEqual('abc', 'abc');
221
- //=> never
222
-
223
- endIfEqual('abc', '123');
224
- //=> void
225
- ```
226
-
227
- @category Type Guard
228
- @category Utilities
229
- */
230
- type IsNever$1<T> = [T] extends [never] ? true : false;
231
-
232
- /**
233
- An if-else-like type that resolves depending on whether the given type is `never`.
234
-
235
- @see {@link IsNever}
236
-
237
- @example
238
- ```
239
- import type {IfNever} from 'type-fest';
240
-
241
- type ShouldBeTrue = IfNever<never>;
242
- //=> true
243
-
244
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
245
- //=> 'bar'
246
- ```
247
-
248
- @category Type Guard
249
- @category Utilities
250
- */
251
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
252
- IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever
253
- );
254
-
255
- // Can eventually be replaced with the built-in once this library supports
256
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
257
- type NoInfer<T> = T extends infer U ? U : never;
258
-
259
- /**
260
- Returns a boolean for whether the given type is `any`.
261
-
262
- @link https://stackoverflow.com/a/49928360/1490091
263
-
264
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
265
-
266
- @example
267
- ```
268
- import type {IsAny} from 'type-fest';
269
-
270
- const typedObject = {a: 1, b: 2} as const;
271
- const anyObject: any = {a: 1, b: 2};
272
-
273
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
274
- return obj[key];
275
- }
276
-
277
- const typedA = get(typedObject, 'a');
278
- //=> 1
279
-
280
- const anyA = get(anyObject, 'a');
281
- //=> any
282
- ```
283
-
284
- @category Type Guard
285
- @category Utilities
286
- */
287
- type IsAny$1<T> = 0 extends 1 & NoInfer<T> ? true : false;
288
-
289
- /**
290
- Disallows any of the given keys.
291
- */
292
- type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
293
-
294
- /**
295
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
296
-
297
- @example
298
- ```
299
- import type {Simplify} from 'type-fest';
300
-
301
- type PositionProps = {
302
- top: number;
303
- left: number;
304
- };
305
-
306
- type SizeProps = {
307
- width: number;
308
- height: number;
309
- };
310
-
311
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
312
- type Props = Simplify<PositionProps & SizeProps>;
313
- ```
314
-
315
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
316
-
317
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
318
-
319
- @example
320
- ```
321
- import type {Simplify} from 'type-fest';
322
-
323
- interface SomeInterface {
324
- foo: number;
325
- bar?: string;
326
- baz: number | undefined;
327
- }
328
-
329
- type SomeType = {
330
- foo: number;
331
- bar?: string;
332
- baz: number | undefined;
333
- };
334
-
335
- const literal = {foo: 123, bar: 'hello', baz: 456};
336
- const someType: SomeType = literal;
337
- const someInterface: SomeInterface = literal;
338
-
339
- function fn(object: Record<string, unknown>): void {}
340
-
341
- fn(literal); // Good: literal object type is sealed
342
- fn(someType); // Good: type is sealed
343
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
344
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
345
- ```
346
-
347
- @link https://github.com/microsoft/TypeScript/issues/15300
348
- @see SimplifyDeep
349
- @category Object
350
- */
351
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
352
-
353
- /**
354
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
355
-
356
- This is the counterpart of `PickIndexSignature`.
357
-
358
- Use-cases:
359
- - Remove overly permissive signatures from third-party types.
360
-
361
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
362
-
363
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
364
-
365
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
366
-
367
- ```
368
- const indexed: Record<string, unknown> = {}; // Allowed
369
-
370
- const keyed: Record<'foo', unknown> = {}; // Error
371
- // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
372
- ```
373
-
374
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
375
-
376
- ```
377
- type Indexed = {} extends Record<string, unknown>
378
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
379
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
380
- // => '✅ `{}` is assignable to `Record<string, unknown>`'
381
-
382
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
383
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
384
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
385
- // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
386
- ```
387
-
388
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
389
-
390
- ```
391
- import type {OmitIndexSignature} from 'type-fest';
392
-
393
- type OmitIndexSignature<ObjectType> = {
394
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
395
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
396
- };
397
- ```
398
-
399
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
400
-
401
- ```
402
- import type {OmitIndexSignature} from 'type-fest';
403
-
404
- type OmitIndexSignature<ObjectType> = {
405
- [KeyType in keyof ObjectType
406
- // Is `{}` assignable to `Record<KeyType, unknown>`?
407
- as {} extends Record<KeyType, unknown>
408
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
409
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
410
- ]: ObjectType[KeyType];
411
- };
412
- ```
413
-
414
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
415
-
416
- @example
417
- ```
418
- import type {OmitIndexSignature} from 'type-fest';
419
-
420
- interface Example {
421
- // These index signatures will be removed.
422
- [x: string]: any
423
- [x: number]: any
424
- [x: symbol]: any
425
- [x: `head-${string}`]: string
426
- [x: `${string}-tail`]: string
427
- [x: `head-${string}-tail`]: string
428
- [x: `${bigint}`]: string
429
- [x: `embedded-${number}`]: string
430
-
431
- // These explicitly defined keys will remain.
432
- foo: 'bar';
433
- qux?: 'baz';
434
- }
435
-
436
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
437
- // => { foo: 'bar'; qux?: 'baz' | undefined; }
438
- ```
439
-
440
- @see PickIndexSignature
441
- @category Object
442
- */
443
- type OmitIndexSignature<ObjectType> = {
444
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
445
- ? never
446
- : KeyType]: ObjectType[KeyType];
447
- };
448
-
449
- /**
450
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
451
-
452
- This is the counterpart of `OmitIndexSignature`.
453
-
454
- @example
455
- ```
456
- import type {PickIndexSignature} from 'type-fest';
457
-
458
- declare const symbolKey: unique symbol;
459
-
460
- type Example = {
461
- // These index signatures will remain.
462
- [x: string]: unknown;
463
- [x: number]: unknown;
464
- [x: symbol]: unknown;
465
- [x: `head-${string}`]: string;
466
- [x: `${string}-tail`]: string;
467
- [x: `head-${string}-tail`]: string;
468
- [x: `${bigint}`]: string;
469
- [x: `embedded-${number}`]: string;
470
-
471
- // These explicitly defined keys will be removed.
472
- ['kebab-case-key']: string;
473
- [symbolKey]: string;
474
- foo: 'bar';
475
- qux?: 'baz';
476
- };
477
-
478
- type ExampleIndexSignature = PickIndexSignature<Example>;
479
- // {
480
- // [x: string]: unknown;
481
- // [x: number]: unknown;
482
- // [x: symbol]: unknown;
483
- // [x: `head-${string}`]: string;
484
- // [x: `${string}-tail`]: string;
485
- // [x: `head-${string}-tail`]: string;
486
- // [x: `${bigint}`]: string;
487
- // [x: `embedded-${number}`]: string;
488
- // }
489
- ```
490
-
491
- @see OmitIndexSignature
492
- @category Object
493
- */
494
- type PickIndexSignature<ObjectType> = {
495
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
496
- ? KeyType
497
- : never]: ObjectType[KeyType];
498
- };
499
-
500
- // Merges two objects without worrying about index signatures.
501
- type SimpleMerge<Destination, Source> = {
502
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
503
- } & Source;
504
-
505
- /**
506
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
507
-
508
- @example
509
- ```
510
- import type {Merge} from 'type-fest';
511
-
512
- interface Foo {
513
- [x: string]: unknown;
514
- [x: number]: unknown;
515
- foo: string;
516
- bar: symbol;
517
- }
518
-
519
- type Bar = {
520
- [x: number]: number;
521
- [x: symbol]: unknown;
522
- bar: Date;
523
- baz: boolean;
524
- };
525
-
526
- export type FooBar = Merge<Foo, Bar>;
527
- // => {
528
- // [x: string]: unknown;
529
- // [x: number]: number;
530
- // [x: symbol]: unknown;
531
- // foo: string;
532
- // bar: Date;
533
- // baz: boolean;
534
- // }
535
- ```
536
-
537
- @category Object
538
- */
539
- type Merge<Destination, Source> =
540
- Simplify<
541
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
542
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
543
- >;
544
-
545
- /**
546
- An if-else-like type that resolves depending on whether the given type is `any`.
547
-
548
- @see {@link IsAny}
549
-
550
- @example
551
- ```
552
- import type {IfAny} from 'type-fest';
553
-
554
- type ShouldBeTrue = IfAny<any>;
555
- //=> true
556
-
557
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
558
- //=> 'bar'
559
- ```
560
-
561
- @category Type Guard
562
- @category Utilities
563
- */
564
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
565
- IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny
566
- );
567
-
568
- /**
569
- Extract all optional keys from the given type.
570
-
571
- This is useful when you want to create a new type that contains different type values for the optional keys only.
572
-
573
- @example
574
- ```
575
- import type {OptionalKeysOf, Except} from 'type-fest';
576
-
577
- interface User {
578
- name: string;
579
- surname: string;
580
-
581
- luckyNumber?: number;
582
- }
583
-
584
- const REMOVE_FIELD = Symbol('remove field symbol');
585
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
586
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
587
- };
588
-
589
- const update1: UpdateOperation<User> = {
590
- name: 'Alice'
591
- };
592
-
593
- const update2: UpdateOperation<User> = {
594
- name: 'Bob',
595
- luckyNumber: REMOVE_FIELD
596
- };
597
- ```
598
-
599
- @category Utilities
600
- */
601
- type OptionalKeysOf<BaseType extends object> = Exclude<{
602
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
603
- ? never
604
- : Key
605
- }[keyof BaseType], undefined>;
606
-
607
- /**
608
- Matches any primitive, `void`, `Date`, or `RegExp` value.
609
- */
610
- type BuiltIns = Primitive | void | Date | RegExp;
611
-
612
- /**
613
- Test if the given function has multiple call signatures.
614
-
615
- Needed to handle the case of a single call signature with properties.
616
-
617
- Multiple call signatures cannot currently be supported due to a TypeScript limitation.
618
- @see https://github.com/microsoft/TypeScript/issues/29732
619
- */
620
- type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
621
- T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
622
- ? B extends A
623
- ? A extends B
624
- ? false
625
- : true
626
- : true
627
- : false;
628
-
629
- /**
630
- Merges user specified options with default options.
631
-
632
- @example
633
- ```
634
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
635
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
636
- type SpecifiedOptions = {leavesOnly: true};
637
-
638
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
639
- //=> {maxRecursionDepth: 10; leavesOnly: true}
640
- ```
641
-
642
- @example
643
- ```
644
- // Complains if default values are not provided for optional options
645
-
646
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
647
- type DefaultPathsOptions = {maxRecursionDepth: 10};
648
- type SpecifiedOptions = {};
649
-
650
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
651
- // ~~~~~~~~~~~~~~~~~~~
652
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
653
- ```
654
-
655
- @example
656
- ```
657
- // Complains if an option's default type does not conform to the expected type
658
-
659
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
660
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
661
- type SpecifiedOptions = {};
662
-
663
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
664
- // ~~~~~~~~~~~~~~~~~~~
665
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
666
- ```
667
-
668
- @example
669
- ```
670
- // Complains if an option's specified type does not conform to the expected type
671
-
672
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
673
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
674
- type SpecifiedOptions = {leavesOnly: 'yes'};
675
-
676
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
677
- // ~~~~~~~~~~~~~~~~
678
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
679
- ```
680
- */
681
- type ApplyDefaultOptions<
682
- Options extends object,
683
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
684
- SpecifiedOptions extends Options,
685
- > =
686
- IfAny<SpecifiedOptions, Defaults,
687
- IfNever<SpecifiedOptions, Defaults,
688
- Simplify<Merge<Defaults, {
689
- [Key in keyof SpecifiedOptions
690
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
691
- ]: SpecifiedOptions[Key]
692
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
693
- >>;
694
-
695
- /**
696
- Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
697
-
698
- Use-cases:
699
- - Creating interfaces for components that only need one of the keys to display properly.
700
- - Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
701
-
702
- The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
703
-
704
- @example
705
- ```
706
- import type {RequireExactlyOne} from 'type-fest';
707
-
708
- type Responder = {
709
- text: () => string;
710
- json: () => string;
711
- secure: boolean;
712
- };
713
-
714
- const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
715
- // Adding a `text` key here would cause a compile error.
716
-
717
- json: () => '{"message": "ok"}',
718
- secure: true
719
- };
720
- ```
721
-
722
- @category Object
723
- */
724
- type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
725
- {[Key in KeysType]: (
726
- Required<Pick<ObjectType, Key>> &
727
- Partial<Record<Exclude<KeysType, Key>, never>>
728
- )}[KeysType] & Omit<ObjectType, KeysType>;
729
-
730
- /**
731
- Create a type that requires exactly one of the given keys and disallows more, or none of the given keys. The remaining keys are kept as is.
732
-
733
- @example
734
- ```
735
- import type {RequireOneOrNone} from 'type-fest';
736
-
737
- type Responder = RequireOneOrNone<{
738
- text: () => string;
739
- json: () => string;
740
- secure: boolean;
741
- }, 'text' | 'json'>;
742
-
743
- const responder1: Responder = {
744
- secure: true
745
- };
746
-
747
- const responder2: Responder = {
748
- text: () => '{"message": "hi"}',
749
- secure: true
750
- };
751
-
752
- const responder3: Responder = {
753
- json: () => '{"message": "ok"}',
754
- secure: true
755
- };
756
- ```
757
-
758
- @category Object
759
- */
760
- type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (
761
- | RequireExactlyOne<ObjectType, KeysType>
762
- | RequireNone<KeysType>
763
- ) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
764
-
765
- /**
766
- @see {@link PartialDeep}
767
- */
768
- type PartialDeepOptions = {
769
- /**
770
- Whether to affect the individual elements of arrays and tuples.
771
-
772
- @default false
773
- */
774
- readonly recurseIntoArrays?: boolean;
775
-
776
- /**
777
- Allows `undefined` values in non-tuple arrays.
778
-
779
- - When set to `true`, elements of non-tuple arrays can be `undefined`.
780
- - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
781
-
782
- @default true
783
-
784
- @example
785
- You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
786
-
787
- ```
788
- import type {PartialDeep} from 'type-fest';
789
-
790
- type Settings = {
791
- languages: string[];
792
- };
793
-
794
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
795
-
796
- partialSettings.languages = [undefined]; // Error
797
- partialSettings.languages = []; // Ok
798
- ```
799
- */
800
- readonly allowUndefinedInNonTupleArrays?: boolean;
801
- };
802
-
803
- type DefaultPartialDeepOptions = {
804
- recurseIntoArrays: false;
805
- allowUndefinedInNonTupleArrays: true;
806
- };
807
-
808
- /**
809
- Create a type from another type with all keys and nested keys set to optional.
810
-
811
- Use-cases:
812
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
813
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
814
-
815
- @example
816
- ```
817
- import type {PartialDeep} from 'type-fest';
818
-
819
- const settings: Settings = {
820
- textEditor: {
821
- fontSize: 14,
822
- fontColor: '#000000',
823
- fontWeight: 400
824
- },
825
- autocomplete: false,
826
- autosave: true
827
- };
828
-
829
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
830
- return {...settings, ...savedSettings};
831
- }
832
-
833
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
834
- ```
835
-
836
- By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
837
-
838
- ```
839
- import type {PartialDeep} from 'type-fest';
840
-
841
- type Settings = {
842
- languages: string[];
843
- }
844
-
845
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
846
- languages: [undefined]
847
- };
848
- ```
849
-
850
- @see {@link PartialDeepOptions}
851
-
852
- @category Object
853
- @category Array
854
- @category Set
855
- @category Map
856
- */
857
- type PartialDeep<T, Options extends PartialDeepOptions = {}> =
858
- _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
859
-
860
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
861
- ? T
862
- : T extends Map<infer KeyType, infer ValueType>
863
- ? PartialMapDeep<KeyType, ValueType, Options>
864
- : T extends Set<infer ItemType>
865
- ? PartialSetDeep<ItemType, Options>
866
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
867
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
868
- : T extends ReadonlySet<infer ItemType>
869
- ? PartialReadonlySetDeep<ItemType, Options>
870
- : T extends object
871
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
872
- ? Options['recurseIntoArrays'] extends true
873
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
874
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
875
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
876
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
877
- : PartialObjectDeep<T, Options> // Tuples behave properly
878
- : T // If they don't opt into array testing, just use the original type
879
- : PartialObjectDeep<T, Options>
880
- : unknown;
881
-
882
- /**
883
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
884
- */
885
- type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
886
-
887
- /**
888
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
889
- */
890
- type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
891
-
892
- /**
893
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
894
- */
895
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
896
-
897
- /**
898
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
899
- */
900
- type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
901
-
902
- /**
903
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
904
- */
905
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
906
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
907
- };
908
-
909
- type ExcludeUndefined<T> = Exclude<T, undefined>;
910
-
911
- /**
912
- Create a type from another type with all keys and nested keys set to required.
913
-
914
- Use-cases:
915
- - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
916
- - Modeling the resulting type after a deep merge with a set of defaults.
917
-
918
- @example
919
- ```
920
- import type {RequiredDeep} from 'type-fest';
921
-
922
- type Settings = {
923
- textEditor?: {
924
- fontSize?: number | undefined;
925
- fontColor?: string | undefined;
926
- fontWeight?: number | undefined;
927
- }
928
- autocomplete?: boolean | undefined;
929
- autosave?: boolean | undefined;
930
- };
931
-
932
- type RequiredSettings = RequiredDeep<Settings>;
933
- // type RequiredSettings = {
934
- // textEditor: {
935
- // fontSize: number;
936
- // fontColor: string;
937
- // fontWeight: number;
938
- // }
939
- // autocomplete: boolean;
940
- // autosave: boolean;
941
- // }
942
- ```
943
-
944
- Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
945
-
946
- @category Utilities
947
- @category Object
948
- @category Array
949
- @category Set
950
- @category Map
951
- */
952
- type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
953
- ? E
954
- : E extends Map<infer KeyType, infer ValueType>
955
- ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
956
- : E extends Set<infer ItemType>
957
- ? Set<RequiredDeep<ItemType>>
958
- : E extends ReadonlyMap<infer KeyType, infer ValueType>
959
- ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
960
- : E extends ReadonlySet<infer ItemType>
961
- ? ReadonlySet<RequiredDeep<ItemType>>
962
- : E extends WeakMap<infer KeyType, infer ValueType>
963
- ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
964
- : E extends WeakSet<infer ItemType>
965
- ? WeakSet<RequiredDeep<ItemType>>
966
- : E extends Promise<infer ValueType>
967
- ? Promise<RequiredDeep<ValueType>>
968
- : E extends (...arguments_: any[]) => unknown
969
- ? {} extends RequiredObjectDeep<E>
970
- ? E
971
- : HasMultipleCallSignatures<E> extends true
972
- ? E
973
- : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
974
- : E extends object
975
- ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
976
- ? ItemType[] extends E // Test for arrays (non-tuples) specifically
977
- ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
978
- : RequiredObjectDeep<E> // Tuples behave properly
979
- : RequiredObjectDeep<E>
980
- : unknown;
981
-
982
- type RequiredObjectDeep<ObjectType extends object> = {
983
- [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
984
- };
985
-
986
- /**
987
- Returns the last element of a union type.
988
-
989
- @example
990
- ```
991
- type Last = LastOfUnion<1 | 2 | 3>;
992
- //=> 3
993
- ```
994
- */
995
- type LastOfUnion<T> =
996
- UnionToIntersection$1<T extends any ? () => T : never> extends () => (infer R)
997
- ? R
998
- : never;
999
-
1000
- /**
1001
- Convert a union type into an unordered tuple type of its elements.
1002
-
1003
- "Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
1004
-
1005
- This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
1006
-
1007
- @example
1008
- ```
1009
- import type {UnionToTuple} from 'type-fest';
1010
-
1011
- type Numbers = 1 | 2 | 3;
1012
- type NumbersTuple = UnionToTuple<Numbers>;
1013
- //=> [1, 2, 3]
1014
- ```
1015
-
1016
- @example
1017
- ```
1018
- import type {UnionToTuple} from 'type-fest';
1019
-
1020
- const pets = {
1021
- dog: '🐶',
1022
- cat: '🐱',
1023
- snake: '🐍',
1024
- };
1025
-
1026
- type Pet = keyof typeof pets;
1027
- //=> 'dog' | 'cat' | 'snake'
1028
-
1029
- const petList = Object.keys(pets) as UnionToTuple<Pet>;
1030
- //=> ['dog', 'cat', 'snake']
1031
- ```
1032
-
1033
- @category Array
1034
- */
1035
- type UnionToTuple$1<T, L = LastOfUnion<T>> =
1036
- IsNever$1<T> extends false
1037
- ? [...UnionToTuple$1<Exclude<T, L>>, L]
1038
- : [];
1039
-
1040
- interface RegleBehaviourOptions {
1041
- /**
1042
- * Only display error when calling `r$.$validate()`
1043
- * @default false
1044
- */
1045
- lazy?: boolean | undefined;
1046
- /**
1047
- * Automaticaly set the dirty set without the need of `$value` or `$touch`
1048
- * @default true
1049
- *
1050
- * @default false if rewardEarly is true
1051
-
1052
- */
1053
- autoDirty?: boolean | undefined;
1054
- /**
1055
- * The fields will turn valid when they are, but not invalid unless calling `r$.$validate()`
1056
- * @default false
1057
- */
1058
- rewardEarly?: boolean | undefined;
1059
- /**
1060
- * Define wether or not the external errors should be cleared when updating a field
1061
- * @default true
1062
- *
1063
- */
1064
- clearExternalErrorsOnChange?: boolean | undefined;
1065
- }
1066
- interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
1067
- externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState>>>;
1068
- validationGroups?: (fields: RegleStatus<TState, TRules>['$fields']) => TValidationGroups;
1069
- }
1070
- type RegleValidationGroupEntry = RegleFieldStatus<any, any>;
1071
- interface RegleValidationGroupOutput {
1072
- $invalid: boolean;
1073
- $error: boolean;
1074
- $pending: boolean;
1075
- $dirty: boolean;
1076
- $correct: boolean;
1077
- $errors: string[];
1078
- $silentErrors: string[];
1079
- }
1080
- type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
1081
- /**
1082
- * Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
1083
- */
1084
- $debounce?: number;
1085
- };
1086
- type ResolvedRegleBehaviourOptions = DeepMaybeRef<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, Record<string, any>, Record<string, any[]>>;
1087
- type ShortcutCommonFn<T extends Record<string, any>> = {
1088
- [x: string]: (element: OmitByType<T, Function>) => unknown;
1089
- };
1090
- type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
1091
- /**
1092
- * Allow you to customize the properties of every single field
1093
- */
1094
- fields?: ShortcutCommonFn<RegleFieldStatus<any, Partial<TCustomRules> & Partial<DefaultValidators>>>;
1095
- /**
1096
- * Allow you to customize the properties of every parent of a nested object
1097
- */
1098
- nested?: ShortcutCommonFn<RegleStatus<Record<string, any>, ReglePartialRuleTree<any, Partial<TCustomRules> & Partial<DefaultValidators>>>>;
1099
- /**
1100
- * Allow you to customize the properties of every parent of a collection
1101
- */
1102
- collections?: ShortcutCommonFn<RegleCollectionStatus<any[], Partial<TCustomRules> & Partial<DefaultValidators>>>;
1103
- };
1104
- type AddDollarToOptions<T extends Record<string, any>> = {
1105
- [K in keyof T as `$${string & K}`]: T[K];
1106
- };
1107
-
1108
- type Regle<TState extends Record<string, any> = EmptyObject, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> = EmptyObject, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
1109
- /**
1110
- * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
1111
- *
1112
- * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
1113
- */
1114
- r$: Raw<RegleRoot<TState, TRules, TValidationGroups, TShortcuts>>;
1115
- } & TAdditionalReturnProperties;
1116
- type RegleSingleField<TState extends Maybe<PrimitiveTypes> = any, TRules extends RegleRuleDecl<NonNullable<TState>> = EmptyObject, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
1117
- /**
1118
- * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
1119
- *
1120
- * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
1121
- */
1122
- r$: Raw<RegleFieldStatus<TState, TRules, TShortcuts>>;
1123
- } & TAdditionalReturnProperties;
1124
- type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? {
1125
- [K in keyof T]: InferDeepReactiveState<T[K]>;
1126
- } : never;
1127
- type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState> extends Date | File ? MaybeRef<TState> : TState extends Record<string, any> | undefined ? DeepReactiveState<TState> : MaybeRef<TState>;
1128
- type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{
1129
- [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]>;
1130
- } & {
1131
- [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: NonNullable<SafeProperty<TState[K], TRules[K]>>;
1132
- }> : TState;
1133
- type FieldHaveRequiredRule<TRule extends RegleRuleDecl> = unknown extends TRule['required'] ? false : TRule['required'] extends undefined ? false : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? true : false : false;
1134
- type ObjectHaveAtLeastOneRequiredField<TState extends Record<string, any>, TRule extends ReglePartialRuleTree<TState, any>> = TState extends Maybe<TState> ? {
1135
- [K in keyof NonNullable<TState>]-?: IsPropertyOutputRequired<NonNullable<TState>[K], TRule[K]>;
1136
- }[keyof TState] extends false ? false : true : true;
1137
- type ArrayHaveAtLeastOneRequiredField<TState extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState>> = TState extends Maybe<TState> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends RegleRuleDecl ? Omit<TRule, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
1138
- type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState] ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? DeepSafeFormState<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends true ? TState : Maybe<TState> : TState : TState;
1139
- type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [
1140
- unknown
1141
- ] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
1142
- type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? MaybeOutput<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? NonNullable<TState> : MaybeOutput<TState> : MaybeOutput<TState> : MaybeOutput<TState>;
1143
-
1144
- type ResetOptions<TState extends unknown> = RequireOneOrNone<{
1145
- /**
1146
- * Reset validation status and reset form state to its initial state
1147
- *
1148
- * ⚠️ This doesn't work if the state is a `reactive` object.
1149
- */
1150
- toInitialState?: boolean;
1151
- /**
1152
- * Reset validation status and reset form state to the given state
1153
- * Also set the new state as new initial state.
1154
- */
1155
- toState?: TState | (() => TState);
1156
- /**
1157
- * Clears the $externalErrors state back to an empty object.
1158
- */
1159
- clearExternalErrors?: boolean;
1160
- }, 'toInitialState' | 'toState'>;
1161
-
1162
- /**
1163
- * Negates a boolean type.
1164
- */
1165
- type Not<T extends boolean> = T extends true ? false : true;
1166
- /**
1167
- * Checks if all the boolean types in the {@linkcode Types} array are `true`.
1168
- */
1169
- type And<Types extends boolean[]> = Types[number] extends true ? true : false;
1170
- /**
1171
- * @internal
1172
- */
1173
- declare const secret: unique symbol;
1174
- /**
1175
- * @internal
1176
- */
1177
- type Secret = typeof secret;
1178
- /**
1179
- * Checks if the given type is `never`.
1180
- */
1181
- type IsNever<T> = [T] extends [never] ? true : false;
1182
- /**
1183
- * Checks if the given type is `any`.
1184
- */
1185
- type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
1186
- /**
1187
- * Determines if the given type is `unknown`.
1188
- */
1189
- type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
1190
- /**
1191
- * Subjective "useful" keys from a type. For objects it's just `keyof` but for
1192
- * tuples/arrays it's the number keys.
1193
- *
1194
- * @example
1195
- * ```ts
1196
- * UsefulKeys<{ a: 1; b: 2 }> // 'a' | 'b'
1197
- *
1198
- * UsefulKeys<['a', 'b']> // '0' | '1'
1199
- *
1200
- * UsefulKeys<string[]> // number
1201
- * ```
1202
- */
1203
- type UsefulKeys<T> = T extends any[] ? {
1204
- [K in keyof T]: K;
1205
- }[number] : keyof T;
1206
- /**
1207
- * Extracts the keys from a type that are required (not optional).
1208
- */
1209
- type RequiredKeys<T> = Extract<{
1210
- [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
1211
- }[keyof T], keyof T>;
1212
- /**
1213
- * Gets the keys of an object type that are optional.
1214
- */
1215
- type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
1216
- /**
1217
- * Extracts the keys from a type that are not `readonly`.
1218
- */
1219
- type ReadonlyKeys<T> = Extract<{
1220
- [K in keyof T]-?: ReadonlyEquivalent<{
1221
- [_K in K]: T[K];
1222
- }, {
1223
- -readonly [_K in K]: T[K];
1224
- }> extends true ? never : K;
1225
- }[keyof T], keyof T>;
1226
- /**
1227
- * Determines if two types, are equivalent in a `readonly` manner.
1228
- *
1229
- * @internal
1230
- */
1231
- type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
1232
- /**
1233
- * Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
1234
- * 1. If either type is `never`, the result is `true` iff the other type is also `never`.
1235
- * 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
1236
- */
1237
- type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
1238
- /**
1239
- * Checks if two types are strictly equal using
1240
- * the TypeScript internal identical-to operator.
1241
- *
1242
- * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
1243
- */
1244
- type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends <T>() => T extends (R & T) | T ? true : false ? IsNever<L> extends IsNever<R> ? true : false : false;
1245
- /**
1246
- * Checks that {@linkcode Left} and {@linkcode Right} extend each other.
1247
- * Not quite the same as an equality check since `any` can make it resolve
1248
- * to `true`. So should only be used when {@linkcode Left} and
1249
- * {@linkcode Right} are known to avoid `any`.
1250
- */
1251
- type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
1252
- /**
1253
- * Convert a union to an intersection.
1254
- * `A | B | C` -\> `A & B & C`
1255
- */
1256
- type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
1257
- /**
1258
- * Get the last element of a union.
1259
- * First, converts to a union of `() => T` functions,
1260
- * then uses {@linkcode UnionToIntersection} to get the last one.
1261
- */
1262
- type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends () => infer R ? R : never;
1263
- /**
1264
- * Intermediate type for {@linkcode UnionToTuple} which pushes the
1265
- * "last" union member to the end of a tuple, and recursively prepends
1266
- * the remainder of the union.
1267
- */
1268
- type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
1269
- /**
1270
- * Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
1271
- */
1272
- type UnionToTuple<Union> = TuplifyUnion<Union>;
1273
- type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
1274
-
1275
- /**
1276
- * The simple(ish) way to get overload info from a function
1277
- * {@linkcode FunctionType}. Recent versions of TypeScript will match any
1278
- * function against a generic 10-overload type, filling in slots with
1279
- * duplicates of the function. So, we can just match against a single type
1280
- * and get all the overloads.
1281
- *
1282
- * For older versions of TypeScript, we'll need to painstakingly do
1283
- * ten separate matches.
1284
- */
1285
- type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
1286
- (...args: infer A1): infer R1;
1287
- (...args: infer A2): infer R2;
1288
- (...args: infer A3): infer R3;
1289
- (...args: infer A4): infer R4;
1290
- (...args: infer A5): infer R5;
1291
- (...args: infer A6): infer R6;
1292
- (...args: infer A7): infer R7;
1293
- (...args: infer A8): infer R8;
1294
- (...args: infer A9): infer R9;
1295
- (...args: infer A10): infer R10;
1296
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : never;
1297
- /**
1298
- * A function with `unknown` parameters and return type.
1299
- */
1300
- type UnknownFunction = (...args: unknown[]) => unknown;
1301
- /**
1302
- * `true` iff {@linkcode FunctionType} is
1303
- * equivalent to `(...args: unknown[]) => unknown`,
1304
- * which is what an overload variant looks like for a non-existent overload.
1305
- * This is useful because older versions of TypeScript end up with
1306
- * 9 "useless" overloads and one real one for parameterless/generic functions.
1307
- *
1308
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1309
- */
1310
- type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownFunction>;
1311
- /**
1312
- * Old versions of TypeScript can sometimes seem to refuse to separate out
1313
- * union members unless you put them each in a pointless tuple and add an
1314
- * extra `infer X` expression. There may be a better way to work around this
1315
- * problem, but since it's not a problem in newer versions of TypeScript,
1316
- * it's not a priority right now.
1317
- */
1318
- type Tuplify<Union> = Union extends infer X ? [X] : never;
1319
- /**
1320
- * For older versions of TypeScript, we need two separate workarounds
1321
- * to get overload info. First, we need need to use
1322
- * {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
1323
- * functions with 1-10 overloads. Then, we need to filter out the
1324
- * "useless" overloads that are present in older versions of TypeScript,
1325
- * for parameterless functions. To do this we use
1326
- * {@linkcode IsUselessOverloadInfo} to remove useless overloads.
1327
- *
1328
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1329
- */
1330
- type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup ? Tup extends [infer Fn] ? IsUselessOverloadInfo<Fn> extends true ? never : Fn : never : never;
1331
- /**
1332
- * For versions of TypeScript below 5.3, we need to check for 10 overloads,
1333
- * then 9, then 8, etc., to get a union of the overload variants.
1334
- */
1335
- type DecreasingOverloadsInfoUnion<F> = F extends {
1336
- (...args: infer A1): infer R1;
1337
- (...args: infer A2): infer R2;
1338
- (...args: infer A3): infer R3;
1339
- (...args: infer A4): infer R4;
1340
- (...args: infer A5): infer R5;
1341
- (...args: infer A6): infer R6;
1342
- (...args: infer A7): infer R7;
1343
- (...args: infer A8): infer R8;
1344
- (...args: infer A9): infer R9;
1345
- (...args: infer A10): infer R10;
1346
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : F extends {
1347
- (...args: infer A1): infer R1;
1348
- (...args: infer A2): infer R2;
1349
- (...args: infer A3): infer R3;
1350
- (...args: infer A4): infer R4;
1351
- (...args: infer A5): infer R5;
1352
- (...args: infer A6): infer R6;
1353
- (...args: infer A7): infer R7;
1354
- (...args: infer A8): infer R8;
1355
- (...args: infer A9): infer R9;
1356
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) : F extends {
1357
- (...args: infer A1): infer R1;
1358
- (...args: infer A2): infer R2;
1359
- (...args: infer A3): infer R3;
1360
- (...args: infer A4): infer R4;
1361
- (...args: infer A5): infer R5;
1362
- (...args: infer A6): infer R6;
1363
- (...args: infer A7): infer R7;
1364
- (...args: infer A8): infer R8;
1365
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) : F extends {
1366
- (...args: infer A1): infer R1;
1367
- (...args: infer A2): infer R2;
1368
- (...args: infer A3): infer R3;
1369
- (...args: infer A4): infer R4;
1370
- (...args: infer A5): infer R5;
1371
- (...args: infer A6): infer R6;
1372
- (...args: infer A7): infer R7;
1373
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
1374
- (...args: infer A1): infer R1;
1375
- (...args: infer A2): infer R2;
1376
- (...args: infer A3): infer R3;
1377
- (...args: infer A4): infer R4;
1378
- (...args: infer A5): infer R5;
1379
- (...args: infer A6): infer R6;
1380
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
1381
- (...args: infer A1): infer R1;
1382
- (...args: infer A2): infer R2;
1383
- (...args: infer A3): infer R3;
1384
- (...args: infer A4): infer R4;
1385
- (...args: infer A5): infer R5;
1386
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
1387
- (...args: infer A1): infer R1;
1388
- (...args: infer A2): infer R2;
1389
- (...args: infer A3): infer R3;
1390
- (...args: infer A4): infer R4;
1391
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
1392
- (...args: infer A1): infer R1;
1393
- (...args: infer A2): infer R2;
1394
- (...args: infer A3): infer R3;
1395
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
1396
- (...args: infer A1): infer R1;
1397
- (...args: infer A2): infer R2;
1398
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends (...args: infer A1) => infer R1 ? ((...p: A1) => R1) : never;
1399
- /**
1400
- * Get a union of overload variants for a function {@linkcode FunctionType}.
1401
- * Does a check for whether we can do the one-shot
1402
- * 10-overload matcher (which works for ts\>5.3), and if not,
1403
- * falls back to the more complicated utility.
1404
- */
1405
- type OverloadsInfoUnion<FunctionType> = IsNever<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
1406
- /**
1407
- * The simple(ish) way to get overload info from a constructor
1408
- * {@linkcode ConstructorType}. Recent versions of TypeScript will match any
1409
- * constructor against a generic 10-overload type, filling in slots with
1410
- * duplicates of the constructor. So, we can just match against a single type
1411
- * and get all the overloads.
1412
- *
1413
- * For older versions of TypeScript,
1414
- * we'll need to painstakingly do ten separate matches.
1415
- */
1416
- type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
1417
- new (...args: infer A1): infer R1;
1418
- new (...args: infer A2): infer R2;
1419
- new (...args: infer A3): infer R3;
1420
- new (...args: infer A4): infer R4;
1421
- new (...args: infer A5): infer R5;
1422
- new (...args: infer A6): infer R6;
1423
- new (...args: infer A7): infer R7;
1424
- new (...args: infer A8): infer R8;
1425
- new (...args: infer A9): infer R9;
1426
- new (...args: infer A10): infer R10;
1427
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : never;
1428
- /**
1429
- * A constructor function with `unknown` parameters and return type.
1430
- */
1431
- type UnknownConstructor = new (...args: unknown[]) => unknown;
1432
- /**
1433
- * Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
1434
- */
1435
- type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownConstructor>;
1436
- /**
1437
- * For older versions of TypeScript, we need two separate workarounds to
1438
- * get constructor overload info. First, we need need to use
1439
- * {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
1440
- * info for constructors with 1-10 overloads. Then, we need to filter out the
1441
- * "useless" overloads that are present in older versions of TypeScript,
1442
- * for parameterless constructors. To do this we use
1443
- * {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
1444
- *
1445
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1446
- */
1447
- type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup ? Tup extends [infer Ctor] ? IsUselessConstructorOverloadInfo<Ctor> extends true ? never : Ctor : never : never;
1448
- /**
1449
- * For versions of TypeScript below 5.3, we need to check for 10 overloads,
1450
- * then 9, then 8, etc., to get a union of the overload variants.
1451
- */
1452
- type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
1453
- new (...args: infer A1): infer R1;
1454
- new (...args: infer A2): infer R2;
1455
- new (...args: infer A3): infer R3;
1456
- new (...args: infer A4): infer R4;
1457
- new (...args: infer A5): infer R5;
1458
- new (...args: infer A6): infer R6;
1459
- new (...args: infer A7): infer R7;
1460
- new (...args: infer A8): infer R8;
1461
- new (...args: infer A9): infer R9;
1462
- new (...args: infer A10): infer R10;
1463
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : ConstructorType extends {
1464
- new (...args: infer A1): infer R1;
1465
- new (...args: infer A2): infer R2;
1466
- new (...args: infer A3): infer R3;
1467
- new (...args: infer A4): infer R4;
1468
- new (...args: infer A5): infer R5;
1469
- new (...args: infer A6): infer R6;
1470
- new (...args: infer A7): infer R7;
1471
- new (...args: infer A8): infer R8;
1472
- new (...args: infer A9): infer R9;
1473
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) : ConstructorType extends {
1474
- new (...args: infer A1): infer R1;
1475
- new (...args: infer A2): infer R2;
1476
- new (...args: infer A3): infer R3;
1477
- new (...args: infer A4): infer R4;
1478
- new (...args: infer A5): infer R5;
1479
- new (...args: infer A6): infer R6;
1480
- new (...args: infer A7): infer R7;
1481
- new (...args: infer A8): infer R8;
1482
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) : ConstructorType extends {
1483
- new (...args: infer A1): infer R1;
1484
- new (...args: infer A2): infer R2;
1485
- new (...args: infer A3): infer R3;
1486
- new (...args: infer A4): infer R4;
1487
- new (...args: infer A5): infer R5;
1488
- new (...args: infer A6): infer R6;
1489
- new (...args: infer A7): infer R7;
1490
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) : ConstructorType extends {
1491
- new (...args: infer A1): infer R1;
1492
- new (...args: infer A2): infer R2;
1493
- new (...args: infer A3): infer R3;
1494
- new (...args: infer A4): infer R4;
1495
- new (...args: infer A5): infer R5;
1496
- new (...args: infer A6): infer R6;
1497
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) : ConstructorType extends {
1498
- new (...args: infer A1): infer R1;
1499
- new (...args: infer A2): infer R2;
1500
- new (...args: infer A3): infer R3;
1501
- new (...args: infer A4): infer R4;
1502
- new (...args: infer A5): infer R5;
1503
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
1504
- new (...args: infer A1): infer R1;
1505
- new (...args: infer A2): infer R2;
1506
- new (...args: infer A3): infer R3;
1507
- new (...args: infer A4): infer R4;
1508
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
1509
- new (...args: infer A1): infer R1;
1510
- new (...args: infer A2): infer R2;
1511
- new (...args: infer A3): infer R3;
1512
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
1513
- new (...args: infer A1): infer R1;
1514
- new (...args: infer A2): infer R2;
1515
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends new (...args: infer A1) => infer R1 ? (new (...p: A1) => R1) : never;
1516
- /**
1517
- * Get a union of overload variants for a constructor
1518
- * {@linkcode ConstructorType}. Does a check for whether we can do the
1519
- * one-shot 10-overload matcher (which works for ts\>5.3), and if not,
1520
- * falls back to the more complicated utility.
1521
- */
1522
- type ConstructorOverloadsUnion<ConstructorType> = IsNever<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType> : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
1523
- /**
1524
- * Allows inferring any constructor using the `infer` keyword.
1525
- */
1526
- type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
1527
- /**
1528
- * A union type of the parameters allowed for any overload
1529
- * of constructor {@linkcode ConstructorType}.
1530
- */
1531
- type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
1532
- /**
1533
- * Calculates the number of overloads for a given function type.
1534
- */
1535
- type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>['length'];
1536
-
1537
- /**
1538
- * Represents a deeply branded type.
1539
- *
1540
- * Recursively walk a type and replace it with a branded type related to the
1541
- * original. This is useful for equality-checking stricter than
1542
- * `A extends B ? B extends A ? true : false : false`, because it detects the
1543
- * difference between a few edge-case types that vanilla TypeScript
1544
- * doesn't by default:
1545
- * - `any` vs `unknown`
1546
- * - `{ readonly a: string }` vs `{ a: string }`
1547
- * - `{ a?: string }` vs `{ a: string | undefined }`
1548
- *
1549
- * __Note__: not very performant for complex types - this should only be used
1550
- * when you know you need it. If doing an equality check, it's almost always
1551
- * better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
1552
- */
1553
- type DeepBrand<T> = IsNever<T> extends true ? {
1554
- type: 'never';
1555
- } : IsAny<T> extends true ? {
1556
- type: 'any';
1557
- } : IsUnknown<T> extends true ? {
1558
- type: 'unknown';
1559
- } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
1560
- type: 'primitive';
1561
- value: T;
1562
- } : T extends new (...args: any[]) => any ? {
1563
- type: 'constructor';
1564
- params: ConstructorOverloadParameters<T>;
1565
- instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
1566
- } : T extends (...args: infer P) => infer R ? NumOverloads<T> extends 1 ? {
1567
- type: 'function';
1568
- params: DeepBrand<P>;
1569
- return: DeepBrand<R>;
1570
- this: DeepBrand<ThisParameterType<T>>;
1571
- props: DeepBrand<Omit<T, keyof Function>>;
1572
- } : UnionToTuple<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
1573
- type: 'overloads';
1574
- overloads: {
1575
- [K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]>;
1576
- };
1577
- } : never : T extends any[] ? {
1578
- type: 'array';
1579
- items: {
1580
- [K in keyof T]: T[K];
1581
- };
1582
- } : {
1583
- type: 'object';
1584
- properties: {
1585
- [K in keyof T]: DeepBrand<T[K]>;
1586
- };
1587
- readonly: ReadonlyKeys<T>;
1588
- required: RequiredKeys<T>;
1589
- optional: OptionalKeys<T>;
1590
- constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
1591
- };
1592
- /**
1593
- * Checks if two types are strictly equal using branding.
1594
- */
1595
- type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
1596
-
1597
- type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields'> & {
1598
- $fields: {
1599
- [TIndex in keyof TupleToPlainObj<UnionToTuple$1<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? {
1600
- [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as TKey extends keyof JoinDiscriminatedUnions<TRules> ? TKey : never]-?: InferRegleStatusType<NonNullable<TKey extends keyof JoinDiscriminatedUnions<TRules> ? JoinDiscriminatedUnions<TRules>[TKey] : {}>, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
1601
- } & {
1602
- [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as TKey extends keyof JoinDiscriminatedUnions<TRules> ? never : TKey]: InferRegleStatusType<{}, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
1603
- } : {};
1604
- }[keyof TupleToPlainObj<UnionToTuple$1<TState>>];
1605
- } : RegleStatus<TState, TRules, TShortcuts>;
1606
-
1607
- interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
1608
- <TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRefOrGetter<TRules> : {}, options?: TState extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? TRules : {}, TValidationGroups> & TAdditionalOptions): TState extends MaybeInput<PrimitiveTypes> ? RegleSingleField<TState, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
1609
- }
1610
- /**
1611
- * useRegle serves as the foundation for validation logic.
1612
- *
1613
- * It accepts the following inputs:
1614
- *
1615
- * @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
1616
- * @param rules - These should align with the structure of your state.
1617
- * @param modifiers - Customize regle behaviour
1618
- *
1619
- * ```ts
1620
- * import { useRegle } from '@regle/core';
1621
- import { required } from '@regle/rules';
1622
-
1623
- const { r$ } = useRegle({ email: '' }, {
1624
- email: { required }
1625
- })
1626
- * ```
1627
- * Docs: {@link https://reglejs.dev/core-concepts/}
1628
- */
1629
- declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
1630
-
1631
- interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
1632
- <TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends TState extends MaybeInput<PrimitiveTypes> ? RegleRuleDecl<NonNullable<TState>, TCustomRules> : TState extends Record<string, any> ? ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> : {}>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: TRules): NoInferLegacy<TRules>;
1633
- }
1634
- /**
1635
- * Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
1636
- * It will just return the rules without any processing.
1637
- *
1638
- * @param state - The state reference
1639
- * @param rules - Your rule tree
1640
- */
1641
- declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
1642
-
1643
- declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, schemaErrors, schemaMode, onValidate, }: {
1644
- scopeRules: Ref<$InternalReglePartialRuleTree>;
1645
- state: Ref<Record<string, any> | PrimitiveTypes>;
1646
- options: ResolvedRegleBehaviourOptions;
1647
- initialState: Ref<Record<string, any> | PrimitiveTypes>;
1648
- customRules?: () => CustomRulesDeclarationTree;
1649
- shortcuts: RegleShortcutDefinition | undefined;
1650
- schemaErrors?: Ref<any | undefined>;
1651
- schemaMode?: boolean;
1652
- onValidate?: () => Promise<$InternalRegleResult>;
1653
- }): {
1654
- regle: $InternalRegleStatusType | undefined;
1655
- };
1656
-
1657
- /**
1658
- * Converts an nested $errors object to a flat array of string errors
1659
- *
1660
- * Can also flatten to an array containing the path of each error with the options.includePath
1661
- */
1662
- declare function flatErrors(errors: $InternalRegleErrors, options: {
1663
- includePath: true;
1664
- }): {
1665
- error: string;
1666
- path: string;
1667
- }[];
1668
- declare function flatErrors(errors: $InternalRegleErrors, options?: {
1669
- includePath?: false;
1670
- }): string[];
1671
-
1672
- type InferRegleRoot<T extends (...args: any[]) => Regle<any, any, any, any>> = T extends (...args: any[]) => infer U ? U extends Regle<any, any, any, any> ? Prettify<U['r$']> : never : never;
1673
- type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<U> & Partial<DefaultValidators>> : {};
1674
- type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
1675
- type RegleEnforceRequiredRules<TRules extends keyof DefaultValidators> = {
1676
- [K in TRules]-?: UnwrapRuleWithParams<DefaultValidators[K]>;
1677
- };
1678
- type RegleEnforceCustomRequiredRules<T extends Partial<AllRulesDeclarations> | useRegleFn<any>, TRules extends T extends useRegleFn<any> ? keyof InferRegleRules<T> : keyof T> = {
1679
- [K in TRules]-?: T extends useRegleFn<any> ? K extends keyof InferRegleRules<T> ? UnwrapRuleWithParams<InferRegleRules<T>[K]> : never : K extends keyof T ? NonNullable<T[K]> : never;
1680
- };
1681
-
1682
- /**
1683
- * Borrowed from vitest
1684
- */
1685
- type PrintType<T> = IsUnknown<T> extends true ? 'unknown' : IsNever<T> extends true ? 'never' : IsAny<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : bigint extends T ? 'bigint' : T extends bigint ? `literal bigint: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...';
1686
- /**
1687
- * Borrowed from vitest
1688
- */
1689
- type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : {
1690
- [K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
1691
- } : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `[Regle error] The parent property does not match the form schema`;
1692
-
1693
- type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
1694
- /**
1695
- * Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
1696
- */
1697
- type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K extends keyof O ? O[K] : undefined;
1698
- /**
1699
- * Combine all unions values to be able to get even the normally "never" values, act as an intersection type
1700
- */
1701
- type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [
1702
- infer F extends Record<string, any>,
1703
- ...infer R
1704
- ] ? [
1705
- {
1706
- [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K>;
1707
- } & {
1708
- [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K>;
1709
- },
1710
- ...RetrieveUnionUnknownValues<R, TKeys>
1711
- ] : [];
1712
- /**
1713
- * Get all possible keys from an union, even the ones present only on one union
1714
- */
1715
- type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
1716
- /**
1717
- * Transforms an union and apply undefined values to non-present keys to support intersection
1718
- */
1719
- type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple$1<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple$1<TUnion>>>[number]>[number];
1720
- /**
1721
- * Combine all members of an union type, merging types for each keys, and keeping loose types
1722
- */
1723
- type JoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<TUnion>, keyof NormalizeUnion<TUnion>>[number]>> & Pick<NormalizeUnion<TUnion>, keyof NormalizeUnion<TUnion>>> : TUnion;
1724
- type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
1725
- type EnumLike = {
1726
- [k: string]: string | number;
1727
- [nu: number]: string;
1728
- };
1729
- type enumType<T extends Record<string, unknown>> = T[keyof T];
1730
- type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
1731
- type TupleToPlainObj<T> = {
1732
- [I in keyof T & `${number}`]: T[I];
1733
- };
1734
-
1735
- type CreateFn<T extends any[]> = (...args: T) => any;
1736
- /**
1737
- * Transform normal parameters tuple declaration to a rich tuple declaration
1738
- *
1739
- * [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
1740
- */
1741
- type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
1742
- [K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>>;
1743
- }) => any : never>;
1744
- type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
1745
- [K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K];
1746
- }) => any : never>;
1747
-
1748
- /**
1749
- * Internal definition of the rule, can be used to reset or patch the rule
1750
- */
1751
- interface RegleInternalRuleDefs<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
1752
- _validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
1753
- _message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
1754
- _active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => boolean);
1755
- _tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
1756
- _type?: string;
1757
- _message_patched: boolean;
1758
- _tooltip_patched: boolean;
1759
- _params?: RegleUniversalParams<TParams>;
1760
- _async: TAsync;
1761
- readonly _brand: symbol;
1762
- }
1763
- declare const InternalRuleType: {
1764
- readonly Inline: "__inline";
1765
- readonly Async: "__async";
1766
- };
1767
- type InternalRuleType = enumType<typeof InternalRuleType>;
1768
-
1769
- /**
1770
- * Returned typed of rules created with `createRule`
1771
- * */
1772
- interface RegleRuleDefinition<TValue extends any = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
1773
- validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
1774
- message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
1775
- active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
1776
- tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
1777
- type?: string;
1778
- exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
1779
- }
1780
- /**
1781
- * Rules with params created with `createRules` are callable while being customizable
1782
- */
1783
- interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata>, RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> {
1784
- (...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TFilteredValue, TParams, TAsync, TMetadata>;
1785
- }
1786
- type RegleRuleMetadataExtended = {
1787
- $valid: boolean;
1788
- [x: string]: any;
1789
- };
1790
- type UnwrapRuleTree<T extends {
1791
- [x: string]: RegleRuleRaw<any> | undefined;
1792
- }> = {
1793
- [K in keyof T]: UnwrapRuleWithParams<T[K]>;
1794
- };
1795
- type UnwrapRuleWithParams<T extends RegleRuleRaw<any, any, any, any> | undefined> = T extends RegleRuleWithParamsDefinition<infer TValue, infer TParams, infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> : T;
1796
- /**
1797
- * Define a rule Metadata definition
1798
- */
1799
- type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
1800
- type DefaultMetadataPropertiesCommon = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid' | '$dirty' | '$pending' | '$correct' | '$error'>;
1801
- type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
1802
- $rule: Pick<$InternalRegleRuleStatus, '$valid' | '$pending'>;
1803
- };
1804
- /**
1805
- * Will be used to consumme metadata on related helpers and rule status
1806
- */
1807
- type RegleRuleMetadataConsumer<TValue extends any, TParams extends any[] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
1808
- $value: Maybe<TValue>;
1809
- } & DefaultMetadataProperties & (TParams extends never ? {} : {
1810
- $params: [...TParams];
1811
- }) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
1812
- /**
1813
- * Will be used to consumme metadata on related helpers and rule status
1814
- */
1815
- type PossibleRegleRuleMetadataConsumer<TValue> = {
1816
- $value: Maybe<TValue>;
1817
- } & DefaultMetadataProperties & {
1818
- $params?: any[];
1819
- };
1820
- /**
1821
- * Generic types for a created RegleRule
1822
- */
1823
- type RegleRuleRaw<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> | RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
1824
- /**
1825
- * Process the type of a created rule with `createRule`.
1826
- * For a rule with params it will return a function
1827
- * Otherwise it will return the rule definition
1828
- */
1829
- type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> = [TParams] extends [[]] ? RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> : RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
1830
- type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
1831
- type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any[]>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
1832
- type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
1833
- $each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
1834
- }) | ({
1835
- $each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
1836
- } & FieldRegleBehaviourOptions);
1837
-
1838
- type RegleInitPropertyGetter<TValue, TReturn, TParams extends [...any[]], TMetadata extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue, TParams, TMetadata>) => TReturn);
1839
- /**
1840
- * @argument
1841
- * createRule arguments options
1842
- */
1843
- interface RegleRuleInit<TValue extends any, TParams extends [...any[]] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean, TMetadata extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TAsync extends boolean = TReturn extends Promise<any> ? true : false> {
1844
- validator: (value: Maybe<TValue>, ...args: TParams) => TReturn;
1845
- message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1846
- active?: RegleInitPropertyGetter<TValue, boolean, TParams, TMetadata>;
1847
- tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1848
- type?: string;
1849
- async?: TAsync;
1850
- }
1851
- /**
1852
- * @argument
1853
- * Rule core
1854
- */
1855
- interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
1856
- validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
1857
- message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1858
- active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1859
- tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1860
- type?: string;
1861
- }
1862
- type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
1863
- value: TValue;
1864
- params: [...TParams];
1865
- };
1866
-
1867
- interface CommonComparationOptions {
1868
- /**
1869
- * Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
1870
- * @default true
1871
- */
1872
- allowEqual?: boolean;
1873
- }
1874
- type DefaultValidators = {
1875
- alpha: RegleRuleDefinition<string>;
1876
- alphaNum: RegleRuleDefinition<string | number>;
1877
- between: RegleRuleWithParamsDefinition<number, [min: Maybe<number>, max: Maybe<number>]>;
1878
- checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
1879
- contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
1880
- dateAfter: RegleRuleWithParamsDefinition<string | Date, [
1881
- after: Maybe<string | Date>
1882
- ], false, true | {
1883
- $valid: false;
1884
- error: 'date-not-after';
1885
- } | {
1886
- $valid: false;
1887
- error: 'value-or-paramater-not-a-date';
1888
- }>;
1889
- dateBefore: RegleRuleWithParamsDefinition<string | Date, [
1890
- before: Maybe<string | Date>
1891
- ], false, true | {
1892
- $valid: false;
1893
- error: 'date-not-before';
1894
- } | {
1895
- $valid: false;
1896
- error: 'value-or-paramater-not-a-date';
1897
- }>;
1898
- dateBetween: RegleRuleWithParamsDefinition<string | Date, [
1899
- before: Maybe<string | Date>,
1900
- after: Maybe<string | Date>
1901
- ], false, boolean>;
1902
- decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
1903
- email: RegleRuleDefinition<string, [], false, boolean, string>;
1904
- endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
1905
- exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
1906
- count: number
1907
- ], false, boolean>;
1908
- exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
1909
- integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
1910
- ipAddress: RegleRuleDefinition<string, [], false, boolean, string>;
1911
- literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
1912
- macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
1913
- maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
1914
- count: number,
1915
- options?: CommonComparationOptions
1916
- ], false, boolean>;
1917
- maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparationOptions], false, boolean>;
1918
- minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
1919
- count: number,
1920
- options?: CommonComparationOptions
1921
- ], false, boolean>;
1922
- minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparationOptions], false, boolean>;
1923
- nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
1924
- numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
1925
- oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
1926
- regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
1927
- required: RegleRuleDefinition<unknown, []>;
1928
- sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
1929
- startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
1930
- url: RegleRuleDefinition<string, [], false, boolean, string>;
1931
- };
1932
-
1933
- type CustomRulesDeclarationTree = {
1934
- [x: string]: RegleRuleRaw<any, any, boolean, any> | undefined;
1935
- };
1936
- type AllRulesDeclarations = CustomRulesDeclarationTree & {
1937
- [K in keyof DefaultValidators]: RegleRuleRaw<any, any, boolean, any> | undefined;
1938
- };
1939
-
1940
- /**
1941
- * @public
1942
- */
1943
- type ReglePartialRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
1944
- [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
1945
- };
1946
- /**
1947
- * @public
1948
- */
1949
- type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
1950
- [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules>;
1951
- };
1952
- /**
1953
- * @public
1954
- */
1955
- type RegleComputedRules<TForm extends MaybeRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<AllRulesDeclarations> | Regle<any, any> = Partial<AllRulesDeclarations>, TState = Unwrap<TForm>, TCustom = TCustomRules extends Regle<any, infer R> ? R extends ReglePartialRuleTree<any, infer C> ? C : Partial<AllRulesDeclarations> : TCustomRules> = {
1956
- [TKey in keyof JoinDiscriminatedUnions<TState>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState>[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
1957
- };
1958
- /**
1959
- * @internal
1960
- * @reference {@link ReglePartialRuleTree}
1961
- */
1962
- type $InternalReglePartialRuleTree = {
1963
- [x: string]: $InternalFormPropertyTypes;
1964
- };
1965
- /**
1966
- * @public
1967
- */
1968
- type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends File ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? ReglePartialRuleTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
1969
- /**
1970
- * @internal
1971
- * @reference {@link RegleFormPropertyType}
1972
- */
1973
- type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialRuleTree | FieldRegleBehaviourOptions;
1974
- /**
1975
- * @public
1976
- * Rule tree for a form property
1977
- */
1978
- type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = FieldRegleBehaviourOptions & {
1979
- [TKey in keyof TCustomRules]?: NonNullable<TCustomRules[TKey]> extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, [...TParams, ...args: [...any[]]], boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any[], any, any> ? FormRuleDeclaration<TValue, any[]> : FormRuleDeclaration<TValue, any[]> | FieldRegleBehaviourOptions[keyof FieldRegleBehaviourOptions];
1980
- };
1981
- /**
1982
- * @internal
1983
- * @reference {@link RegleRuleDecl}
1984
- */
1985
- type $InternalRegleRuleDecl = FieldRegleBehaviourOptions & Record<string, FormRuleDeclaration<any, any>>;
1986
- /**
1987
- * @public
1988
- */
1989
- type RegleCollectionRuleDeclKeyProperty = {
1990
- $key?: PropertyKey;
1991
- };
1992
- /**
1993
- * @public
1994
- */
1995
- type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = ({
1996
- $each?: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>, RegleCollectionRuleDeclKeyProperty>;
1997
- } & RegleRuleDecl<NonNullable<TValue>, TCustomRules>) | ({
1998
- $each?: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>, RegleCollectionRuleDeclKeyProperty>;
1999
- } & FieldRegleBehaviourOptions);
2000
- /**
2001
- * @internal
2002
- * @reference {@link RegleCollectionRuleDecl}
2003
- */
2004
- type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
2005
- $each?: MaybeGetter<$InternalFormPropertyTypes & RegleCollectionRuleDeclKeyProperty, any>;
2006
- };
2007
- /**
2008
- * @public
2009
- */
2010
- type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
2011
- /**
2012
- * @public
2013
- * Regroup inline and registered rules
2014
- * */
2015
- type FormRuleDeclaration<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = boolean> = InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
2016
-
2017
- type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = {
2018
- readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false>;
2019
- };
2020
- type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = {
2021
- readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true>;
2022
- };
2023
- type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U> : RegleExternalCollectionErrors<U> : string[] : NonNullable<TState> extends Date | File ? string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState> : RegleExternalErrorTree<TState> : string[];
2024
- type RegleCollectionErrors<TState extends Record<string, any>> = {
2025
- readonly $self: string[];
2026
- readonly $each: RegleValidationErrors<TState, false>[];
2027
- };
2028
- type RegleExternalCollectionErrors<TState extends Record<string, any>> = {
2029
- readonly $self?: string[];
2030
- readonly $each?: RegleValidationErrors<TState, true>[];
2031
- };
2032
- /** @internal */
2033
- type $InternalRegleCollectionErrors = {
2034
- readonly $self?: string[];
2035
- readonly $each?: $InternalRegleErrors[];
2036
- };
2037
- type $InternalRegleErrorTree = {
2038
- [x: string]: $InternalRegleErrors;
2039
- };
2040
- /**
2041
- * @internal
2042
- */
2043
- type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
2044
- type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{
2045
- [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: MaybeOutput<TState[K]>;
2046
- } & {
2047
- [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? K : TState[K] extends Array<any> ? K : never]: NonNullable<TState[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState[K]>;
2048
- }>;
2049
- type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any>> = {
2050
- valid: false;
2051
- data: NonNullable<Data> extends Date | File ? MaybeOutput<Data> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data>;
2052
- } | {
2053
- valid: true;
2054
- data: Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules>;
2055
- };
2056
- type $InternalRegleResult = {
2057
- valid: boolean;
2058
- data: any;
2059
- };
2060
-
2061
- /**
2062
- * @public
2063
- */
2064
- type RegleRoot<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialRuleTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> = MaybeVariantStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
2065
- /**
2066
- * Collection of validation groups used declared with the `validationGroups` modifier
2067
- */
2068
- $groups: {
2069
- readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput;
2070
- };
2071
- });
2072
- /** Supports both core Regle and schemas Regle for Zod/Valibot */
2073
- type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
2074
- $groups?: {
2075
- [x: string]: RegleValidationGroupOutput;
2076
- };
2077
- $validate: () => Promise<SuperCompatibleRegleResult>;
2078
- };
2079
- type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
2080
- '~~global': Record<string, SuperCompatibleRegleRoot>;
2081
- };
2082
- type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
2083
- type SuperCompatibleRegleResult = $InternalRegleResult;
2084
- interface SuperCompatibleRegleStatus extends SuperCompatibleRegleCommonStatus {
2085
- $fields: {
2086
- [x: string]: unknown;
2087
- };
2088
- readonly $errors: Record<string, RegleValidationErrors<any, false>>;
2089
- readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
2090
- $extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
2091
- $validate?: () => Promise<SuperCompatibleRegleResult>;
2092
- }
2093
- type SuperCompatibleRegleRuleStatus = Omit<$InternalRegleRuleStatus, '$haveAsync' | '$validating' | '$fieldDirty' | '$fieldInvalid' | '$fieldPending' | '$fieldCorrect' | '$fieldError' | '$unwatch' | '$watch'>;
2094
- type SuperCompatibleRegleCommonStatus = Omit<RegleCommonStatus, '$pending'> & {
2095
- $pending?: boolean;
2096
- };
2097
- interface SuperCompatibleRegleFieldStatus extends SuperCompatibleRegleCommonStatus {
2098
- $value: any;
2099
- $silentValue: any;
2100
- readonly $rules: Record<string, SuperCompatibleRegleRuleStatus>;
2101
- readonly $externalErrors?: string[];
2102
- readonly $errors: string[];
2103
- readonly $inactive: boolean;
2104
- readonly $silentErrors: string[];
2105
- $extractDirtyFields: (filterNullishValues?: boolean) => any;
2106
- $validate?: () => Promise<SuperCompatibleRegleResult>;
2107
- }
2108
- interface SuperCompatibleRegleCollectionStatus extends Omit<SuperCompatibleRegleStatus, '$fields' | '$errors' | '$silentErrors'> {
2109
- readonly $self: SuperCompatibleRegleFieldStatus;
2110
- readonly $each: Array<SuperCompatibleRegleStatus | SuperCompatibleRegleFieldStatus>;
2111
- readonly $errors: SuperCompatibleRegleCollectionErrors;
2112
- readonly $silentErrors: SuperCompatibleRegleCollectionErrors;
2113
- readonly $externalErrors?: string[];
2114
- $extractDirtyFields: (filterNullishValues?: boolean) => any[];
2115
- $validate?: () => Promise<SuperCompatibleRegleResult>;
2116
- }
2117
- type SuperCompatibleRegleCollectionErrors = $InternalRegleCollectionErrors;
2118
- /**
2119
- * @public
2120
- */
2121
- type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
2122
- /** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
2123
- readonly $fields: {
2124
- readonly [TKey in keyof TState as IsEmptyObject<TRules[TKey]> extends true ? never : TKey]: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
2125
- } & {
2126
- readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject<TRules[TKey]> extends true ? TKey : never : never : never]-?: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
2127
- };
2128
- /**
2129
- * Collection of all the error messages, collected for all children properties and nested forms.
2130
- *
2131
- * Only contains errors from properties where $dirty equals true. */
2132
- readonly $errors: RegleErrorTree<TState>;
2133
- /** Collection of all the error messages, collected for all children properties. */
2134
- readonly $silentErrors: RegleErrorTree<TState>;
2135
- /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
2136
- $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
2137
- /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
2138
- $validate: () => Promise<RegleResult<TState, TRules>>;
2139
- } & ([TShortcuts['nested']] extends [never] ? {} : {
2140
- [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>;
2141
- });
2142
- /**
2143
- * @internal
2144
- * @reference {@link RegleStatus}
2145
- */
2146
- interface $InternalRegleStatus extends $InternalRegleCommonStatus {
2147
- $fields: {
2148
- [x: string]: $InternalRegleStatusType;
2149
- };
2150
- readonly $errors: Record<string, $InternalRegleErrors>;
2151
- readonly $silentErrors: Record<string, $InternalRegleErrors>;
2152
- $extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
2153
- $validate: () => Promise<$InternalRegleResult>;
2154
- }
2155
- /**
2156
- * @public
2157
- */
2158
- type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState[TKey]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState[TKey], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCollectionStatus<TState[TKey], {}, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState[TKey], TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState[TKey], ReglePartialRuleTree<TState[TKey]>, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts>;
2159
- /**
2160
- * @internal
2161
- * @reference {@link InferRegleStatusType}
2162
- */
2163
- type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
2164
- /**
2165
- * @public
2166
- */
2167
- type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value'> & {
2168
- /** A reference to the original validated model. It can be used to bind your form with v-model.*/
2169
- $value: MaybeOutput<UnwrapNestedRefs<TState>>;
2170
- /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
2171
- $silentValue: MaybeOutput<UnwrapNestedRefs<TState>>;
2172
- /** Collection of all the error messages, collected for all children properties and nested forms.
2173
- *
2174
- * Only contains errors from properties where $dirty equals true. */
2175
- readonly $errors: string[];
2176
- /** Collection of all the error messages, collected for all children properties and nested forms. */
2177
- readonly $silentErrors: string[];
2178
- /** Stores external errors of the current field */
2179
- readonly $externalErrors: string[];
2180
- /** Stores active tooltips messages of the current field */
2181
- readonly $tooltips: string[];
2182
- /** Represents the inactive status. Is true when this state have empty rules */
2183
- readonly $inactive: boolean;
2184
- /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
2185
- $extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
2186
- /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
2187
- $validate: () => Promise<RegleResult<TState, TRules>>;
2188
- /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
2189
- readonly $rules: {
2190
- readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : any>;
2191
- };
2192
- } & ([TShortcuts['fields']] extends [never] ? {} : {
2193
- [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>;
2194
- });
2195
- /**
2196
- * @internal
2197
- * @reference {@link RegleFieldStatus}
2198
- */
2199
- interface $InternalRegleFieldStatus extends $InternalRegleCommonStatus {
2200
- $value: any;
2201
- $silentValue: any;
2202
- readonly $rules: Record<string, $InternalRegleRuleStatus>;
2203
- readonly $externalErrors?: string[];
2204
- readonly $errors: string[];
2205
- readonly $tooltips: string[];
2206
- readonly $inactive: boolean;
2207
- readonly $silentErrors: string[];
2208
- $extractDirtyFields: (filterNullishValues?: boolean) => any;
2209
- $validate: () => Promise<$InternalRegleResult>;
2210
- }
2211
- /**
2212
- * @public
2213
- */
2214
- interface RegleCommonStatus<TValue = any> {
2215
- readonly $invalid: boolean;
2216
- /**
2217
- * This is not the opposite of `$invalid`. Correct is meant to display UI validation report.
2218
- *
2219
- * This will be `true` only if:
2220
- * - The field have at least one active rule
2221
- * - Is dirty and not empty
2222
- * - Passes validation
2223
- */
2224
- readonly $correct: boolean;
2225
- readonly $dirty: boolean;
2226
- readonly $anyDirty: boolean;
2227
- readonly $edited: boolean;
2228
- readonly $anyEdited: boolean;
2229
- /** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
2230
- readonly $pending: boolean;
2231
- /** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
2232
- readonly $error: boolean;
2233
- /** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
2234
- readonly $ready: boolean;
2235
- /** Return the current key name of the field. */
2236
- readonly $name: string;
2237
- /** Id used to track collections items */
2238
- $id?: string;
2239
- /** A reference to the original validated model. It can be used to bind your form with v-model.*/
2240
- $value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
2241
- /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
2242
- $silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
2243
- /** Marks the field and all nested properties as $dirty. */
2244
- $touch(): void;
2245
- /**
2246
- * Reset the validation status to a pristine state while keeping the current form state.
2247
- * Resets the `$dirty` state on all nested properties of a form.
2248
- * Rerun rules if `$lazy` is false
2249
- */
2250
- $reset(): void;
2251
- $reset(options?: ResetOptions<TValue>): void;
2252
- /** Clears the $externalErrors state back to an empty object. */
2253
- $clearExternalErrors(): void;
2254
- }
2255
- interface $InternalRegleCommonStatus extends Omit<RegleCommonStatus, '$touch' | '$reset'> {
2256
- $touch(runCommit?: boolean, withConditions?: boolean): void;
2257
- $unwatch(): void;
2258
- $watch(): void;
2259
- $reset(options?: ResetOptions<any>, fromParent?: boolean): void;
2260
- }
2261
- /**
2262
- * @public
2263
- */
2264
- type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = any> = {
2265
- /** The name of the rule type. */
2266
- readonly $type: string;
2267
- /** Returns the computed error message or messages for the current rule. */
2268
- readonly $message: string | string[];
2269
- /** Stores the current rule tooltip or tooltips */
2270
- readonly $tooltip: string | string[];
2271
- /** Indicates whether or not the rule is enabled (for rules like requiredIf) */
2272
- readonly $active: boolean;
2273
- /** Indicates the state of validation for this validator. */
2274
- readonly $valid: boolean;
2275
- /** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
2276
- readonly $pending: boolean;
2277
- /** Returns the current path of the rule (used internally for tracking) */
2278
- readonly $path: string;
2279
- /** Contains the metadata returned by the validator function. */
2280
- readonly $metadata: TMetadata;
2281
- /** Run the rule validator and compute its properties like $message and $active */
2282
- $parse(): Promise<boolean>;
2283
- /** Reset the $valid, $metadata and $pending states */
2284
- $reset(): void;
2285
- /** Returns the original rule validator function. */
2286
- $validator: ((value: MaybeInput<TValue>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
2287
- } & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
2288
- readonly $params?: any[];
2289
- } : {
2290
- readonly $params: [...TParams];
2291
- });
2292
- /**
2293
- * @internal
2294
- * @reference {@link RegleRuleStatus}
2295
- */
2296
- interface $InternalRegleRuleStatus {
2297
- $type: string;
2298
- $message: string | string[];
2299
- $tooltip: string | string[];
2300
- $active: boolean;
2301
- $valid: boolean;
2302
- $pending: boolean;
2303
- $path: string;
2304
- $externalErrors?: string[];
2305
- $params?: any[];
2306
- $metadata: any;
2307
- $haveAsync: boolean;
2308
- $validating: boolean;
2309
- $fieldDirty: boolean;
2310
- $fieldInvalid: boolean;
2311
- $fieldPending: boolean;
2312
- $fieldCorrect: boolean;
2313
- $fieldError: boolean;
2314
- $validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
2315
- $parse(): Promise<boolean>;
2316
- $reset(): void;
2317
- $unwatch(): void;
2318
- $watch(): void;
2319
- }
2320
- /**
2321
- * @public
2322
- */
2323
- type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePartialRuleTree<ArrayElement<TState>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$value'> & {
2324
- /** A reference to the original validated model. It can be used to bind your form with v-model.*/
2325
- $value: MaybeOutput<TState>;
2326
- /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
2327
- $silentValue: MaybeOutput<TState>;
2328
- /** Collection of status of every item in your collection. Each item will be a field you can access, or map on it to display your elements. */
2329
- readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
2330
- /** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
2331
- readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
2332
- /** Collection of all the error messages, collected for all children properties and nested forms.
2333
- *
2334
- * Only contains errors from properties where $dirty equals true. */
2335
- readonly $errors: RegleCollectionErrors<TState>;
2336
- /** Collection of all the error messages, collected for all children properties and nested forms. */
2337
- readonly $silentErrors: RegleCollectionErrors<TState>;
2338
- /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
2339
- $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
2340
- /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
2341
- $validate: () => Promise<RegleResult<TState, TRules>>;
2342
- } & ([TShortcuts['collections']] extends [never] ? {} : {
2343
- [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
2344
- });
2345
- /**
2346
- * @internal
2347
- * @reference {@link RegleCollectionStatus}
2348
- */
2349
- interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields' | '$errors' | '$silentErrors'> {
2350
- readonly $self: $InternalRegleFieldStatus;
2351
- readonly $each: Array<$InternalRegleStatusType>;
2352
- readonly $errors: $InternalRegleCollectionErrors;
2353
- readonly $silentErrors: $InternalRegleCollectionErrors;
2354
- readonly $externalErrors?: string[];
2355
- $extractDirtyFields: (filterNullishValues?: boolean) => any[];
2356
- $validate: () => Promise<$InternalRegleResult>;
2357
- }
2358
-
2359
- /**
2360
- * Create a typed custom rule that can be used like default rules.
2361
- * It can also be declared in the global options
2362
- *
2363
- * It will automatically detect if the rule is async
2364
- *
2365
- * @typeParam TValue - The input value the rule should receive
2366
- * @typeParam TParams - Tuple declaration of the rule parameters (if any)
2367
- *
2368
- *
2369
- * @param definition - The rule processors object
2370
- *
2371
- * @returns A rule definition that can be callable depending on params presence
2372
- *
2373
- * @exemple
2374
- *
2375
- * ```ts
2376
- * // Create a simple rule with no params
2377
- * import {isFilled} from '@regle/rules';
2378
- *
2379
- * export const isFoo = createRule({
2380
- * validator(value: Maybe<string>) {
2381
- * if (isFilled(value)) {
2382
- * return value === 'foo';
2383
- * }
2384
- * return true
2385
- * },
2386
- * message: "The value should be 'foo'"
2387
- * })
2388
- *
2389
- * ```
2390
- *
2391
- * Docs: {@link https://reglejs.dev/core-concepts/rules/reusable-rules}
2392
- */
2393
- declare function createRule<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(definition: RegleRuleInit<TValue, TParams, TReturn, TMetadata, TAsync>): InferRegleRule<TValue, TParams, TAsync, TMetadata>;
2394
-
2395
- /**
2396
- * Returns a clean list of parameters
2397
- * Removing Ref and executing function to return the unwraped value
2398
- */
2399
- declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
2400
-
2401
- /**
2402
- * Define a global regle configuration, where you can:
2403
- * - Customize buil-in rules messages
2404
- * - Add your custom rules
2405
- * - Define global modifiers
2406
- * - Define shortcuts
2407
- *
2408
- * It will return:
2409
- *
2410
- * - a `useRegle` composable that can typecheck your custom rules
2411
- * - an `inferRules` helper that can typecheck your custom rules
2412
- */
2413
- declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations>>({ rules, modifiers, shortcuts, }: {
2414
- rules?: () => TCustomRules;
2415
- modifiers?: RegleBehaviourOptions;
2416
- shortcuts?: TShortcuts;
2417
- }): {
2418
- useRegle: useRegleFn<TCustomRules, TShortcuts>;
2419
- inferRules: inferRulesFn<TCustomRules>;
2420
- };
2421
-
2422
- type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue = {
2423
- [K in keyof TRegles]: TRegles[K]['$value'];
2424
- }> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch'> & {
2425
- /** Dictionnay of merged Regle instances and their properties */
2426
- readonly $instances: {
2427
- [K in keyof TRegles]: TRegles[K];
2428
- };
2429
- /** A reference to the original validated model. It can be used to bind your form with v-model.*/
2430
- $value: TValue;
2431
- /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
2432
- $silentValue: TValue;
2433
- /** Collection of all the error messages, collected for all children properties and nested forms.
2434
- *
2435
- * Only contains errors from properties where $dirty equals true. */
2436
- readonly $errors: {
2437
- [K in keyof TRegles]: TRegles[K]['$errors'];
2438
- };
2439
- /** Collection of all the error messages, collected for all children properties. */
2440
- readonly $silentErrors: {
2441
- [K in keyof TRegles]: TRegles[K]['$silentErrors'];
2442
- };
2443
- /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
2444
- $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TValue>;
2445
- /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
2446
- $validate: () => Promise<MergedReglesResult<TRegles>>;
2447
- };
2448
- type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
2449
- /** Array of scoped Regles instances */
2450
- readonly $instances: SuperCompatibleRegleRoot[];
2451
- /** Collection of all registered Regles instances values */
2452
- readonly $value: TValue;
2453
- /** Collection of all registered Regles instances errors */
2454
- readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
2455
- /** Collection of all registered Regles instances silent errors */
2456
- readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
2457
- /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
2458
- $validate: () => Promise<{
2459
- valid: boolean;
2460
- data: TValue;
2461
- }>;
2462
- };
2463
- type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
2464
- valid: false;
2465
- data: {
2466
- [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2467
- valid: false;
2468
- }>['data'];
2469
- };
2470
- } | {
2471
- valid: true;
2472
- data: {
2473
- [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2474
- valid: true;
2475
- }>['data'];
2476
- };
2477
- };
2478
- declare function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TScoped extends boolean = false>(regles: TRegles, _scoped?: TScoped): TScoped extends false ? MergedRegles<TRegles> : MergedScopedRegles;
2479
-
2480
- declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<AllRulesDeclarations>>, TReturnedRegle extends useRegleFn<any, any> = TCustomRegle extends useRegleFn<infer A, infer B> ? useRegleFn<A, B, {
2481
- dispose: () => void;
2482
- register: () => void;
2483
- }, {
2484
- namespace?: MaybeRefOrGetter<string>;
2485
- }> : useRegleFn<Partial<AllRulesDeclarations>>>(options?: {
2486
- customUseRegle?: TCustomRegle;
2487
- customStore?: Ref<ScopedInstancesRecordLike>;
2488
- }): {
2489
- useScopedRegle: TReturnedRegle;
2490
- useCollectScope<TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>): {
2491
- r$: MergedScopedRegles<TValue>;
2492
- };
2493
- };
2494
- declare const useCollectScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
2495
- r$: MergedScopedRegles<TValue>;
2496
- };
2497
- declare const useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
2498
- dispose: () => void;
2499
- register: () => void;
2500
- }, {
2501
- namespace?: MaybeRefOrGetter<string>;
2502
- }>;
2503
-
2504
- type PossibleLiteralTypes<T extends Record<string, any>, TKey extends keyof T> = {
2505
- [TVal in NonNullable<T[TKey]>]: {
2506
- [K in TKey]-?: Omit<RegleRuleDecl<TVal, Partial<AllRulesDeclarations>>, 'literal'> & {
2507
- literal?: RegleRuleDefinition<TVal, [literal: TVal], false, boolean, string | number>;
2508
- };
2509
- };
2510
- };
2511
- type RequiredForm<T extends Record<string, any>, TKey extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey> & PossibleLiteralTypes<T, TKey>[keyof PossibleLiteralTypes<T, TKey>];
2512
- type Variant1<T extends Record<string, any>, TKey extends keyof T> = [
2513
- RequiredForm<T, TKey>,
2514
- ...RequiredForm<T, TKey>[]
2515
- ];
2516
- /**
2517
- *
2518
- * Autocomplete may not work here because of https://github.com/microsoft/TypeScript/issues/49547
2519
- */
2520
- declare function createVariant<const TForm extends Record<string, any>, const TDiscriminant extends keyof JoinDiscriminatedUnions<TForm>, const TVariants extends Variant1<JoinDiscriminatedUnions<TForm>, TDiscriminant>>(root: MaybeRefOrGetter<TForm> | DeepReactiveState<TForm>, disciminantKey: TDiscriminant, variants: [...TVariants]): Ref<TVariants[number]>;
2521
- declare function discriminateVariant<TRoot extends {
2522
- [x: string]: unknown;
2523
- }, TKey extends keyof TRoot, const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
2524
- $value: infer V;
2525
- } ? V : unknown>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, {
2526
- [K in TKey]: RegleFieldStatus<TValue, any, any>;
2527
- }>;
2528
- declare function inferVariantToRef<TRoot extends {
2529
- [x: string]: unknown;
2530
- }, TKey extends keyof TRoot, const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
2531
- $value: infer V;
2532
- } ? V : unknown>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): Ref<Extract<TRoot, {
2533
- [K in TKey]: RegleFieldStatus<TValue, any, any>;
2534
- }>> | undefined;
2535
-
2536
- export { type $InternalRegleStatus, type AllRulesDeclarations, type CommonComparationOptions, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeVariantStatus, type MergedRegles, type MismatchInfo, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleSingleField, type RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, createVariant, defineRegleConfig, discriminateVariant, flatErrors, inferRules, inferVariantToRef, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };