@regle/core 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/dist/regle-core.d.ts +1130 -1165
- package/dist/regle-core.js +2555 -0
- package/dist/regle-core.min.js +1 -0
- package/package.json +12 -12
- package/dist/regle-core.min.mjs +0 -2
- package/dist/regle-core.mjs +0 -2877
package/dist/regle-core.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as vue0 from "vue";
|
|
2
|
+
import { MaybeRef, MaybeRefOrGetter, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} & {} : never;
|
|
4
|
+
//#region src/types/utils/misc.types.d.ts
|
|
5
|
+
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
7
6
|
type Maybe<T = any> = T | null | undefined;
|
|
8
7
|
type MaybeInput<T = any> = T | null | undefined;
|
|
9
8
|
type MaybeOutput<T = any> = T | undefined;
|
|
@@ -11,45 +10,51 @@ type MaybeReadonly<T> = T | Readonly<T>;
|
|
|
11
10
|
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
12
11
|
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
|
|
13
12
|
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
14
|
-
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends (...args: any[]) => infer U ? U : T;
|
|
13
|
+
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends ((...args: any[]) => infer U) ? U : T;
|
|
15
14
|
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
16
15
|
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
17
|
-
type OmitByType<T extends Record<string, any>, U> = {
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
type DeepMaybeRef<T extends Record<string, any>> = {
|
|
21
|
-
[K in keyof T]: MaybeRef<T[K]>;
|
|
22
|
-
};
|
|
23
|
-
type ExcludeByType<T, U> = {
|
|
24
|
-
[K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K];
|
|
25
|
-
};
|
|
16
|
+
type OmitByType<T extends Record<string, any>, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] };
|
|
17
|
+
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
18
|
+
type ExcludeByType<T, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K] };
|
|
26
19
|
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
27
20
|
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
28
21
|
type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
|
|
29
22
|
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/types/utils/Array.types.d.ts
|
|
30
25
|
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
31
26
|
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/primitive.d.ts
|
|
32
29
|
/**
|
|
33
30
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
34
31
|
|
|
35
32
|
@category Type
|
|
36
33
|
*/
|
|
37
|
-
type Primitive =
|
|
38
|
-
| null
|
|
39
|
-
| undefined
|
|
40
|
-
| string
|
|
41
|
-
| number
|
|
42
|
-
| boolean
|
|
43
|
-
| symbol
|
|
44
|
-
| bigint;
|
|
34
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
45
35
|
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/observable-like.d.ts
|
|
46
38
|
declare global {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
40
|
+
interface SymbolConstructor {
|
|
41
|
+
readonly observable: symbol;
|
|
42
|
+
}
|
|
51
43
|
}
|
|
52
44
|
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
47
|
+
/**
|
|
48
|
+
@remarks
|
|
49
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
50
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
51
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
52
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
53
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
54
|
+
|
|
55
|
+
@category Observable
|
|
56
|
+
*/
|
|
57
|
+
|
|
53
58
|
/**
|
|
54
59
|
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).
|
|
55
60
|
|
|
@@ -96,22 +101,23 @@ type Intersection = UnionToIntersection<Union>;
|
|
|
96
101
|
@category Type
|
|
97
102
|
*/
|
|
98
103
|
type UnionToIntersection$1<Union> = (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
105
|
+
// `Union` into a [distributive conditional
|
|
106
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
107
|
+
Union extends unknown
|
|
108
|
+
// The union type is used as the only argument to a function since the union
|
|
109
|
+
// of function arguments is an intersection.
|
|
110
|
+
? (distributedUnion: Union) => void
|
|
111
|
+
// This won't happen.
|
|
112
|
+
: never
|
|
113
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
114
|
+
// arguments of unions of functions as an intersection of the union.
|
|
110
115
|
) extends ((mergedIntersection: infer Intersection) => void)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
: never;
|
|
116
|
+
// The `& Union` is to allow indexing by the resulting type
|
|
117
|
+
? Intersection & Union : never;
|
|
114
118
|
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/empty-object.d.ts
|
|
115
121
|
declare const emptyObjectSymbol: unique symbol;
|
|
116
122
|
|
|
117
123
|
/**
|
|
@@ -140,7 +146,9 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
140
146
|
|
|
141
147
|
@category Object
|
|
142
148
|
*/
|
|
143
|
-
type EmptyObject = {
|
|
149
|
+
type EmptyObject = {
|
|
150
|
+
[emptyObjectSymbol]?: never;
|
|
151
|
+
};
|
|
144
152
|
|
|
145
153
|
/**
|
|
146
154
|
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
@@ -159,6 +167,8 @@ type Fail = IsEmptyObject<null>; //=> false
|
|
|
159
167
|
*/
|
|
160
168
|
type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
161
169
|
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
162
172
|
/**
|
|
163
173
|
Extract all optional keys from the given type.
|
|
164
174
|
|
|
@@ -192,13 +202,13 @@ const update2: UpdateOperation<User> = {
|
|
|
192
202
|
|
|
193
203
|
@category Utilities
|
|
194
204
|
*/
|
|
195
|
-
type OptionalKeysOf<BaseType extends object> =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
199
|
-
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
200
|
-
: never; // Should never happen
|
|
205
|
+
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
206
|
+
? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
207
|
+
: never;
|
|
201
208
|
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
211
|
+
// Should never happen
|
|
202
212
|
/**
|
|
203
213
|
Extract all required keys from the given type.
|
|
204
214
|
|
|
@@ -223,10 +233,12 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
|
|
|
223
233
|
|
|
224
234
|
@category Utilities
|
|
225
235
|
*/
|
|
226
|
-
type RequiredKeysOf<BaseType extends object> =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
236
|
+
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
237
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-never.d.ts
|
|
241
|
+
// Should never happen
|
|
230
242
|
|
|
231
243
|
/**
|
|
232
244
|
Returns a boolean for whether the given type is `never`.
|
|
@@ -271,6 +283,8 @@ endIfEqual('abc', '123');
|
|
|
271
283
|
*/
|
|
272
284
|
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
273
285
|
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-never.d.ts
|
|
274
288
|
/**
|
|
275
289
|
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
276
290
|
|
|
@@ -290,10 +304,10 @@ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
|
290
304
|
@category Type Guard
|
|
291
305
|
@category Utilities
|
|
292
306
|
*/
|
|
293
|
-
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
294
|
-
IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
295
|
-
);
|
|
307
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
296
308
|
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-any.d.ts
|
|
297
311
|
// Can eventually be replaced with the built-in once this library supports
|
|
298
312
|
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
299
313
|
type NoInfer<T> = T extends infer U ? U : never;
|
|
@@ -328,11 +342,18 @@ const anyA = get(anyObject, 'a');
|
|
|
328
342
|
*/
|
|
329
343
|
type IsAny$1<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
330
344
|
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/keys.d.ts
|
|
331
347
|
/**
|
|
332
348
|
Disallows any of the given keys.
|
|
333
349
|
*/
|
|
334
350
|
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
335
351
|
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/simplify.d.ts
|
|
354
|
+
/**
|
|
355
|
+
Utility type to retrieve only literal keys from type.
|
|
356
|
+
*/
|
|
336
357
|
/**
|
|
337
358
|
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.
|
|
338
359
|
|
|
@@ -390,8 +411,10 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
390
411
|
@see SimplifyDeep
|
|
391
412
|
@category Object
|
|
392
413
|
*/
|
|
393
|
-
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
414
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
394
415
|
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
395
418
|
/**
|
|
396
419
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
397
420
|
|
|
@@ -482,12 +505,10 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
482
505
|
@see PickIndexSignature
|
|
483
506
|
@category Object
|
|
484
507
|
*/
|
|
485
|
-
type OmitIndexSignature<ObjectType> = {
|
|
486
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
487
|
-
? never
|
|
488
|
-
: KeyType]: ObjectType[KeyType];
|
|
489
|
-
};
|
|
508
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
490
509
|
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
491
512
|
/**
|
|
492
513
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
493
514
|
|
|
@@ -533,16 +554,12 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
533
554
|
@see OmitIndexSignature
|
|
534
555
|
@category Object
|
|
535
556
|
*/
|
|
536
|
-
type PickIndexSignature<ObjectType> = {
|
|
537
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
538
|
-
? KeyType
|
|
539
|
-
: never]: ObjectType[KeyType];
|
|
540
|
-
};
|
|
557
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
541
558
|
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/merge.d.ts
|
|
542
561
|
// Merges two objects without worrying about index signatures.
|
|
543
|
-
type SimpleMerge<Destination, Source> = {
|
|
544
|
-
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
545
|
-
} & Source;
|
|
562
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
546
563
|
|
|
547
564
|
/**
|
|
548
565
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
@@ -578,12 +595,10 @@ export type FooBar = Merge<Foo, Bar>;
|
|
|
578
595
|
|
|
579
596
|
@category Object
|
|
580
597
|
*/
|
|
581
|
-
type Merge<Destination, Source> =
|
|
582
|
-
Simplify<
|
|
583
|
-
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
584
|
-
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
585
|
-
>;
|
|
598
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
586
599
|
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-any.d.ts
|
|
587
602
|
/**
|
|
588
603
|
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
589
604
|
|
|
@@ -603,15 +618,19 @@ type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
|
603
618
|
@category Type Guard
|
|
604
619
|
@category Utilities
|
|
605
620
|
*/
|
|
606
|
-
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
607
|
-
IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
608
|
-
);
|
|
621
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
609
622
|
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/type.d.ts
|
|
610
625
|
/**
|
|
611
626
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
612
627
|
*/
|
|
613
628
|
type BuiltIns = Primitive | void | Date | RegExp;
|
|
614
629
|
|
|
630
|
+
/**
|
|
631
|
+
Matches non-recursive types.
|
|
632
|
+
*/
|
|
633
|
+
|
|
615
634
|
/**
|
|
616
635
|
Test if the given function has multiple call signatures.
|
|
617
636
|
|
|
@@ -620,14 +639,14 @@ Needed to handle the case of a single call signature with properties.
|
|
|
620
639
|
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
621
640
|
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
622
641
|
*/
|
|
623
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
642
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
643
|
+
(...arguments_: infer A): unknown;
|
|
644
|
+
(...arguments_: infer B): unknown;
|
|
645
|
+
} ? B extends A ? A extends B ? false : true : true : false;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
Returns a boolean for whether the given `boolean` is not `false`.
|
|
649
|
+
*/
|
|
631
650
|
|
|
632
651
|
/**
|
|
633
652
|
Returns a boolean for whether the given type is a union type.
|
|
@@ -646,23 +665,17 @@ type IsUnion$1<T> = InternalIsUnion<T>;
|
|
|
646
665
|
/**
|
|
647
666
|
The actual implementation of `IsUnion`.
|
|
648
667
|
*/
|
|
649
|
-
type InternalIsUnion<T, U = T> =
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
// In some cases `Result` will return `false | true` which is `boolean`,
|
|
661
|
-
// that means `T` has at least two types and it's a union type,
|
|
662
|
-
// so we will return `true` instead of `boolean`.
|
|
663
|
-
? boolean extends Result ? true
|
|
664
|
-
: Result
|
|
665
|
-
: never; // Should never happen
|
|
668
|
+
type InternalIsUnion<T, U = T> = (
|
|
669
|
+
// @link https://ghaiklor.github.io/type-challenges-solutions/en/medium-isunion.html
|
|
670
|
+
IsNever$1<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result
|
|
671
|
+
// In some cases `Result` will return `false | true` which is `boolean`,
|
|
672
|
+
// that means `T` has at least two types and it's a union type,
|
|
673
|
+
// so we will return `true` instead of `boolean`.
|
|
674
|
+
? boolean extends Result ? true : Result : never;
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/object.d.ts
|
|
678
|
+
// Should never happen
|
|
666
679
|
|
|
667
680
|
/**
|
|
668
681
|
Merges user specified options with default options.
|
|
@@ -716,24 +729,11 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
716
729
|
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
717
730
|
```
|
|
718
731
|
*/
|
|
719
|
-
type ApplyDefaultOptions<
|
|
720
|
-
|
|
721
|
-
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
722
|
-
SpecifiedOptions extends Options,
|
|
723
|
-
> =
|
|
724
|
-
IfAny<SpecifiedOptions, Defaults,
|
|
725
|
-
IfNever<SpecifiedOptions, Defaults,
|
|
726
|
-
Simplify<Merge<Defaults, {
|
|
727
|
-
[Key in keyof SpecifiedOptions
|
|
728
|
-
as Key extends OptionalKeysOf<Options>
|
|
729
|
-
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
730
|
-
? Key
|
|
731
|
-
: never
|
|
732
|
-
: Key
|
|
733
|
-
]: SpecifiedOptions[Key]
|
|
734
|
-
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
735
|
-
>>;
|
|
732
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny<SpecifiedOptions, Defaults, IfNever<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
733
|
+
>>;
|
|
736
734
|
|
|
735
|
+
//#endregion
|
|
736
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/require-exactly-one.d.ts
|
|
737
737
|
/**
|
|
738
738
|
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
739
739
|
|
|
@@ -763,12 +763,10 @@ const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
|
|
|
763
763
|
|
|
764
764
|
@category Object
|
|
765
765
|
*/
|
|
766
|
-
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
|
767
|
-
{[Key in KeysType]: (
|
|
768
|
-
Required<Pick<ObjectType, Key>> &
|
|
769
|
-
Partial<Record<Exclude<KeysType, Key>, never>>
|
|
770
|
-
)}[KeysType] & Omit<ObjectType, KeysType>;
|
|
766
|
+
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = { [Key in KeysType]: (Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>) }[KeysType] & Omit<ObjectType, KeysType>;
|
|
771
767
|
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/require-one-or-none.d.ts
|
|
772
770
|
/**
|
|
773
771
|
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.
|
|
774
772
|
|
|
@@ -799,52 +797,43 @@ const responder3: Responder = {
|
|
|
799
797
|
|
|
800
798
|
@category Object
|
|
801
799
|
*/
|
|
802
|
-
type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (
|
|
803
|
-
| RequireExactlyOne<ObjectType, KeysType>
|
|
804
|
-
| RequireNone<KeysType>
|
|
805
|
-
) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
|
|
800
|
+
type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>;
|
|
806
801
|
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/partial-deep.d.ts
|
|
804
|
+
// Ignore unspecified keys.
|
|
807
805
|
/**
|
|
808
806
|
@see {@link PartialDeep}
|
|
809
807
|
*/
|
|
810
808
|
type PartialDeepOptions = {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
837
|
-
|
|
838
|
-
partialSettings.languages = [undefined]; // Error
|
|
839
|
-
partialSettings.languages = []; // Ok
|
|
840
|
-
```
|
|
841
|
-
*/
|
|
842
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
809
|
+
/**
|
|
810
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
811
|
+
@default false
|
|
812
|
+
*/
|
|
813
|
+
readonly recurseIntoArrays?: boolean;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
Allows `undefined` values in non-tuple arrays.
|
|
817
|
+
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
818
|
+
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
819
|
+
@default true
|
|
820
|
+
@example
|
|
821
|
+
You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
|
|
822
|
+
```
|
|
823
|
+
import type {PartialDeep} from 'type-fest';
|
|
824
|
+
type Settings = {
|
|
825
|
+
languages: string[];
|
|
826
|
+
};
|
|
827
|
+
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
828
|
+
partialSettings.languages = [undefined]; // Error
|
|
829
|
+
partialSettings.languages = []; // Ok
|
|
830
|
+
```
|
|
831
|
+
*/
|
|
832
|
+
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
843
833
|
};
|
|
844
|
-
|
|
845
834
|
type DefaultPartialDeepOptions = {
|
|
846
|
-
|
|
847
|
-
|
|
835
|
+
recurseIntoArrays: false;
|
|
836
|
+
allowUndefinedInNonTupleArrays: true;
|
|
848
837
|
};
|
|
849
838
|
|
|
850
839
|
/**
|
|
@@ -896,32 +885,14 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
|
896
885
|
@category Set
|
|
897
886
|
@category Map
|
|
898
887
|
*/
|
|
899
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
? PartialMapDeep<KeyType, ValueType, Options>
|
|
908
|
-
: T extends Set<infer ItemType>
|
|
909
|
-
? PartialSetDeep<ItemType, Options>
|
|
910
|
-
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
911
|
-
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
912
|
-
: T extends ReadonlySet<infer ItemType>
|
|
913
|
-
? PartialReadonlySetDeep<ItemType, Options>
|
|
914
|
-
: T extends object
|
|
915
|
-
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
916
|
-
? Options['recurseIntoArrays'] extends true
|
|
917
|
-
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
918
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
919
|
-
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
920
|
-
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
921
|
-
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
922
|
-
: T // If they don't opt into array testing, just use the original type
|
|
923
|
-
: PartialObjectDeep<T, Options>
|
|
924
|
-
: unknown;
|
|
888
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
889
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T : IsNever$1<keyof T> extends true // For functions with no properties
|
|
890
|
+
? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
891
|
+
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
892
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
893
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T, Options> // Tuples behave properly
|
|
894
|
+
: T // If they don't opt into array testing, just use the original type
|
|
895
|
+
: PartialObjectDeep<T, Options> : unknown;
|
|
925
896
|
|
|
926
897
|
/**
|
|
927
898
|
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
@@ -946,13 +917,10 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
|
|
|
946
917
|
/**
|
|
947
918
|
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
948
919
|
*/
|
|
949
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
|
|
950
|
-
(ObjectType extends (...arguments_: any) => unknown
|
|
951
|
-
? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
|
|
952
|
-
: {}) & ({
|
|
953
|
-
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
954
|
-
});
|
|
920
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = (ObjectType extends ((...arguments_: any) => unknown) ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType> : {}) & ({ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> });
|
|
955
921
|
|
|
922
|
+
//#endregion
|
|
923
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/required-deep.d.ts
|
|
956
924
|
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
957
925
|
|
|
958
926
|
/**
|
|
@@ -996,40 +964,15 @@ Note that types containing overloaded functions are not made deeply required due
|
|
|
996
964
|
@category Set
|
|
997
965
|
@category Map
|
|
998
966
|
*/
|
|
999
|
-
type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
: E extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
1006
|
-
? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
|
|
1007
|
-
: E extends ReadonlySet<infer ItemType>
|
|
1008
|
-
? ReadonlySet<RequiredDeep<ItemType>>
|
|
1009
|
-
: E extends WeakMap<infer KeyType, infer ValueType>
|
|
1010
|
-
? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
|
|
1011
|
-
: E extends WeakSet<infer ItemType>
|
|
1012
|
-
? WeakSet<RequiredDeep<ItemType>>
|
|
1013
|
-
: E extends Promise<infer ValueType>
|
|
1014
|
-
? Promise<RequiredDeep<ValueType>>
|
|
1015
|
-
: E extends (...arguments_: any[]) => unknown
|
|
1016
|
-
? {} extends RequiredObjectDeep<E>
|
|
1017
|
-
? E
|
|
1018
|
-
: HasMultipleCallSignatures<E> extends true
|
|
1019
|
-
? E
|
|
1020
|
-
: ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
|
|
1021
|
-
: E extends object
|
|
1022
|
-
? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
1023
|
-
? ItemType[] extends E // Test for arrays (non-tuples) specifically
|
|
1024
|
-
? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
|
|
1025
|
-
: RequiredObjectDeep<E> // Tuples behave properly
|
|
1026
|
-
: RequiredObjectDeep<E>
|
|
1027
|
-
: unknown;
|
|
1028
|
-
|
|
1029
|
-
type RequiredObjectDeep<ObjectType extends object> = {
|
|
1030
|
-
[KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
|
|
1031
|
-
};
|
|
967
|
+
type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns ? E : E extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : E extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : E extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : E extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : E extends ((...arguments_: any[]) => unknown) ? {} extends RequiredObjectDeep<E> ? E : HasMultipleCallSignatures<E> extends true ? E : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E> : E extends object ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
968
|
+
? ItemType[] extends E // Test for arrays (non-tuples) specifically
|
|
969
|
+
? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
|
|
970
|
+
: RequiredObjectDeep<E> // Tuples behave properly
|
|
971
|
+
: RequiredObjectDeep<E> : unknown;
|
|
972
|
+
type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
|
|
1032
973
|
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
1033
976
|
/**
|
|
1034
977
|
Returns the last element of a union type.
|
|
1035
978
|
|
|
@@ -1039,10 +982,7 @@ type Last = LastOfUnion<1 | 2 | 3>;
|
|
|
1039
982
|
//=> 3
|
|
1040
983
|
```
|
|
1041
984
|
*/
|
|
1042
|
-
type LastOfUnion<T> =
|
|
1043
|
-
UnionToIntersection$1<T extends any ? () => T : never> extends () => (infer R)
|
|
1044
|
-
? R
|
|
1045
|
-
: never;
|
|
985
|
+
type LastOfUnion<T> = UnionToIntersection$1<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
1046
986
|
|
|
1047
987
|
/**
|
|
1048
988
|
Convert a union type into an unordered tuple type of its elements.
|
|
@@ -1079,11 +1019,10 @@ const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
|
1079
1019
|
|
|
1080
1020
|
@category Array
|
|
1081
1021
|
*/
|
|
1082
|
-
type UnionToTuple$1<T, L = LastOfUnion<T>> =
|
|
1083
|
-
IsNever$1<T> extends false
|
|
1084
|
-
? [...UnionToTuple$1<Exclude<T, L>>, L]
|
|
1085
|
-
: [];
|
|
1022
|
+
type UnionToTuple$1<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple$1<Exclude<T, L>>, L] : [];
|
|
1086
1023
|
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-null.d.ts
|
|
1087
1026
|
/**
|
|
1088
1027
|
Returns a boolean for whether the given type is `null`.
|
|
1089
1028
|
|
|
@@ -1105,6 +1044,8 @@ type Example2 = NonNullFallback<number, string>;
|
|
|
1105
1044
|
*/
|
|
1106
1045
|
type IsNull<T> = [T] extends [null] ? true : false;
|
|
1107
1046
|
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-unknown.d.ts
|
|
1108
1049
|
/**
|
|
1109
1050
|
Returns a boolean for whether the given type is `unknown`.
|
|
1110
1051
|
|
|
@@ -1148,158 +1089,155 @@ store.execute((state, payload) => ({value: state.value + payload}), someExternal
|
|
|
1148
1089
|
|
|
1149
1090
|
@category Utilities
|
|
1150
1091
|
*/
|
|
1151
|
-
type IsUnknown$1<T> = (
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
? true
|
|
1155
|
-
: false
|
|
1156
|
-
: false
|
|
1157
|
-
);
|
|
1092
|
+
type IsUnknown$1<T> = (unknown extends T // `T` can be `unknown` or `any`
|
|
1093
|
+
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
|
1094
|
+
? true : false : false);
|
|
1158
1095
|
|
|
1096
|
+
//#endregion
|
|
1097
|
+
//#region src/types/core/modifiers.types.d.ts
|
|
1159
1098
|
interface RegleBehaviourOptions {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
clearExternalErrorsOnChange?: boolean | undefined;
|
|
1099
|
+
/**
|
|
1100
|
+
* Only display error when calling `r$.$validate()`
|
|
1101
|
+
* @default false
|
|
1102
|
+
*/
|
|
1103
|
+
lazy?: boolean | undefined;
|
|
1104
|
+
/**
|
|
1105
|
+
* Automatically set the dirty set without the need of `$value` or `$touch`.
|
|
1106
|
+
* @default true
|
|
1107
|
+
*
|
|
1108
|
+
*/
|
|
1109
|
+
autoDirty?: boolean | undefined;
|
|
1110
|
+
/**
|
|
1111
|
+
* Only update error status when calling `$validate`.
|
|
1112
|
+
* Will not display errors as you type
|
|
1113
|
+
* @default false
|
|
1114
|
+
*
|
|
1115
|
+
* @default true if rewardEarly is true
|
|
1116
|
+
*
|
|
1117
|
+
*/
|
|
1118
|
+
silent?: boolean | undefined;
|
|
1119
|
+
/**
|
|
1120
|
+
* The fields will turn valid when they are, but not invalid unless calling `r$.$validate()`
|
|
1121
|
+
* @default false
|
|
1122
|
+
*/
|
|
1123
|
+
rewardEarly?: boolean | undefined;
|
|
1124
|
+
/**
|
|
1125
|
+
* Define whether the external errors should be cleared when updating a field
|
|
1126
|
+
*
|
|
1127
|
+
* Default to `false` if `$silent` is set to `true`
|
|
1128
|
+
* @default true
|
|
1129
|
+
*
|
|
1130
|
+
*
|
|
1131
|
+
*/
|
|
1132
|
+
clearExternalErrorsOnChange?: boolean | undefined;
|
|
1195
1133
|
}
|
|
1196
1134
|
interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
|
|
1197
|
-
|
|
1198
|
-
|
|
1135
|
+
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState>>>;
|
|
1136
|
+
validationGroups?: (fields: RegleStatus<TState, TRules>['$fields']) => TValidationGroups;
|
|
1199
1137
|
}
|
|
1200
1138
|
type RegleValidationGroupEntry = RegleFieldStatus<any, any>;
|
|
1201
1139
|
interface RegleValidationGroupOutput {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1140
|
+
$invalid: boolean;
|
|
1141
|
+
$error: boolean;
|
|
1142
|
+
$pending: boolean;
|
|
1143
|
+
$dirty: boolean;
|
|
1144
|
+
$correct: boolean;
|
|
1145
|
+
$errors: string[];
|
|
1146
|
+
$silentErrors: string[];
|
|
1209
1147
|
}
|
|
1210
1148
|
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1149
|
+
/**
|
|
1150
|
+
* Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
|
|
1151
|
+
*/
|
|
1152
|
+
$debounce?: number;
|
|
1215
1153
|
};
|
|
1216
1154
|
type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1155
|
+
/**
|
|
1156
|
+
* Allow deep compare of array children to compute the `$edited` property
|
|
1157
|
+
*
|
|
1158
|
+
* Disabled by default for performance
|
|
1159
|
+
*
|
|
1160
|
+
* @default false
|
|
1161
|
+
* */
|
|
1162
|
+
$deepCompare?: boolean;
|
|
1225
1163
|
};
|
|
1226
1164
|
type ResolvedRegleBehaviourOptions = DeepMaybeRef<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, Record<string, any>, Record<string, any[]>>;
|
|
1227
1165
|
type ShortcutCommonFn<T extends Record<string, any>> = {
|
|
1228
|
-
|
|
1166
|
+
[x: string]: (element: OmitByType<T, Function>) => unknown;
|
|
1229
1167
|
};
|
|
1230
1168
|
type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
};
|
|
1244
|
-
type AddDollarToOptions<T extends Record<string, any>> = {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1169
|
+
/**
|
|
1170
|
+
* Allow you to customize the properties for every field
|
|
1171
|
+
*/
|
|
1172
|
+
fields?: ShortcutCommonFn<RegleFieldStatus<any, Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1173
|
+
/**
|
|
1174
|
+
* Allow you to customize the properties for every parent of a nested object
|
|
1175
|
+
*/
|
|
1176
|
+
nested?: ShortcutCommonFn<RegleStatus<Record<string, any>, ReglePartialRuleTree<any, Partial<TCustomRules> & Partial<DefaultValidators>>>>;
|
|
1177
|
+
/**
|
|
1178
|
+
* Allow you to customize the properties for every parent of a collection
|
|
1179
|
+
*/
|
|
1180
|
+
collections?: ShortcutCommonFn<RegleCollectionStatus<any[], Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1181
|
+
};
|
|
1182
|
+
type AddDollarToOptions<T extends Record<string, any>> = { [K in keyof T as `$${string & K}`]: T[K] };
|
|
1183
|
+
|
|
1184
|
+
//#endregion
|
|
1185
|
+
//#region src/types/core/useRegle.types.d.ts
|
|
1248
1186
|
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> = {}> = {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1187
|
+
/**
|
|
1188
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1189
|
+
*
|
|
1190
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1191
|
+
*/
|
|
1192
|
+
r$: Raw<RegleRoot<TState, TRules, TValidationGroups, TShortcuts>>;
|
|
1255
1193
|
} & TAdditionalReturnProperties;
|
|
1256
1194
|
type RegleSingleField<TState extends Maybe<PrimitiveTypes> = any, TRules extends RegleRuleDecl<NonNullable<TState>> = EmptyObject, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1195
|
+
/**
|
|
1196
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1197
|
+
*
|
|
1198
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1199
|
+
*/
|
|
1200
|
+
r$: Raw<RegleFieldStatus<TState, TRules, TShortcuts>>;
|
|
1263
1201
|
} & TAdditionalReturnProperties;
|
|
1264
|
-
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? {
|
|
1265
|
-
[K in keyof T]: InferDeepReactiveState<T[K]>;
|
|
1266
|
-
} : never;
|
|
1202
|
+
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
|
|
1267
1203
|
type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState> extends Date | File ? MaybeRef<TState> : NonNullable<TState> extends Record<string, any> ? DeepReactiveState<TState> : MaybeRef<TState>;
|
|
1268
1204
|
|
|
1205
|
+
//#endregion
|
|
1206
|
+
//#region src/types/core/reset.types.d.ts
|
|
1269
1207
|
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1208
|
+
/**
|
|
1209
|
+
* Reset validation status and reset form state to its initial state
|
|
1210
|
+
*
|
|
1211
|
+
* ⚠️ This doesn't work if the state is a `reactive` object.
|
|
1212
|
+
*/
|
|
1213
|
+
toInitialState?: boolean;
|
|
1214
|
+
/**
|
|
1215
|
+
* Reset validation status and reset form state to the given state
|
|
1216
|
+
* Also set the new state as the initial state.
|
|
1217
|
+
*/
|
|
1218
|
+
toState?: TState | (() => TState);
|
|
1219
|
+
/**
|
|
1220
|
+
* Clears the $externalErrors state back to an empty object.
|
|
1221
|
+
*/
|
|
1222
|
+
clearExternalErrors?: boolean;
|
|
1285
1223
|
}, 'toInitialState' | 'toState'>;
|
|
1286
1224
|
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/types/core/scopedRegle.types.d.ts
|
|
1287
1227
|
type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
|
|
1288
|
-
|
|
1228
|
+
'~~global': Record<string, SuperCompatibleRegleRoot>;
|
|
1289
1229
|
};
|
|
1290
1230
|
type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
1291
1231
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
} & {
|
|
1295
|
-
[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]>;
|
|
1296
|
-
}>;
|
|
1232
|
+
//#endregion
|
|
1233
|
+
//#region src/types/core/results.types.d.ts
|
|
1234
|
+
type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{ [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: MaybeOutput<TState[K]> } & { [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]> }>;
|
|
1297
1235
|
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any>> = {
|
|
1298
|
-
|
|
1299
|
-
|
|
1236
|
+
valid: false;
|
|
1237
|
+
data: IsUnknown$1<Data> extends true ? unknown : 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>;
|
|
1300
1238
|
} | {
|
|
1301
|
-
|
|
1302
|
-
|
|
1239
|
+
valid: true;
|
|
1240
|
+
data: IsUnknown$1<Data> extends true ? unknown : 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>;
|
|
1303
1241
|
};
|
|
1304
1242
|
/**
|
|
1305
1243
|
* Infer safe output from any `r$` instance
|
|
@@ -1310,33 +1248,38 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
|
|
|
1310
1248
|
*/
|
|
1311
1249
|
type InferSafeOutput<TRegle extends MaybeRef<RegleRoot<{}, any, any, any>> | MaybeRef<RegleFieldStatus<any, any, any>>> = UnwrapRef<TRegle> extends Raw<RegleRoot<infer TState extends Record<string, any>, infer TRules, any, any>> ? DeepSafeFormState<JoinDiscriminatedUnions<TState>, TRules> : UnwrapRef<TRegle> extends RegleFieldStatus<infer TState, infer TRules> ? SafeFieldProperty<TState, TRules> : never;
|
|
1312
1250
|
type $InternalRegleResult = {
|
|
1313
|
-
|
|
1314
|
-
|
|
1251
|
+
valid: boolean;
|
|
1252
|
+
data: any;
|
|
1315
1253
|
};
|
|
1316
|
-
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{
|
|
1317
|
-
[K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]>;
|
|
1318
|
-
} & {
|
|
1319
|
-
[K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>>;
|
|
1320
|
-
}> : TState;
|
|
1254
|
+
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]> } & { [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>> }> : TState;
|
|
1321
1255
|
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? [unknown] extends TRule['required'] ? NonNullable<TRule['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<TRule['required']> extends TRule['required'] ? TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
|
|
1322
|
-
type ObjectHaveAtLeastOneRequiredField<TState extends Record<string, any>, TRule extends ReglePartialRuleTree<TState, any>> = TState extends Maybe<TState> ? {
|
|
1323
|
-
[K in keyof NonNullable<TState>]-?: IsPropertyOutputRequired<NonNullable<TState>[K], TRule[K]>;
|
|
1324
|
-
}[keyof TState] extends false ? false : true : true;
|
|
1256
|
+
type ObjectHaveAtLeastOneRequiredField<TState extends Record<string, any>, TRule extends ReglePartialRuleTree<TState, any>> = TState extends Maybe<TState> ? { [K in keyof NonNullable<TState>]-?: IsPropertyOutputRequired<NonNullable<TState>[K], TRule[K]> }[keyof TState] extends false ? false : true : true;
|
|
1325
1257
|
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;
|
|
1326
1258
|
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> ? JoinDiscriminatedUnions<NonNullable<TState>> : {}, TRule> : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends true ? TState : MaybeOutput<TState> : TState : TState;
|
|
1327
|
-
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [
|
|
1328
|
-
unknown
|
|
1329
|
-
] 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;
|
|
1259
|
+
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] 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;
|
|
1330
1260
|
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState> : MaybeOutput<TState>;
|
|
1331
1261
|
|
|
1262
|
+
//#endregion
|
|
1263
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/utils.d.ts
|
|
1332
1264
|
/**
|
|
1333
1265
|
* Negates a boolean type.
|
|
1334
1266
|
*/
|
|
1335
1267
|
type Not<T extends boolean> = T extends true ? false : true;
|
|
1268
|
+
/**
|
|
1269
|
+
* Returns `true` if at least one of the types in the
|
|
1270
|
+
* {@linkcode Types} array is `true`, otherwise returns `false`.
|
|
1271
|
+
*/
|
|
1272
|
+
|
|
1336
1273
|
/**
|
|
1337
1274
|
* Checks if all the boolean types in the {@linkcode Types} array are `true`.
|
|
1338
1275
|
*/
|
|
1339
1276
|
type And<Types extends boolean[]> = Types[number] extends true ? true : false;
|
|
1277
|
+
/**
|
|
1278
|
+
* Represents an equality type that returns {@linkcode Right} if
|
|
1279
|
+
* {@linkcode Left} is `true`,
|
|
1280
|
+
* otherwise returns the negation of {@linkcode Right}.
|
|
1281
|
+
*/
|
|
1282
|
+
|
|
1340
1283
|
/**
|
|
1341
1284
|
* @internal
|
|
1342
1285
|
*/
|
|
@@ -1357,6 +1300,10 @@ type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
|
|
|
1357
1300
|
* Determines if the given type is `unknown`.
|
|
1358
1301
|
*/
|
|
1359
1302
|
type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
|
|
1303
|
+
/**
|
|
1304
|
+
* Determines if a type is either `never` or `any`.
|
|
1305
|
+
*/
|
|
1306
|
+
|
|
1360
1307
|
/**
|
|
1361
1308
|
* Subjective "useful" keys from a type. For objects it's just `keyof` but for
|
|
1362
1309
|
* tuples/arrays it's the number keys.
|
|
@@ -1370,15 +1317,11 @@ type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
|
|
|
1370
1317
|
* UsefulKeys<string[]> // number
|
|
1371
1318
|
* ```
|
|
1372
1319
|
*/
|
|
1373
|
-
type UsefulKeys<T> = T extends any[] ? {
|
|
1374
|
-
[K in keyof T]: K;
|
|
1375
|
-
}[number] : keyof T;
|
|
1320
|
+
type UsefulKeys<T> = T extends any[] ? { [K in keyof T]: K }[number] : keyof T;
|
|
1376
1321
|
/**
|
|
1377
1322
|
* Extracts the keys from a type that are required (not optional).
|
|
1378
1323
|
*/
|
|
1379
|
-
type RequiredKeys<T> = Extract<{
|
|
1380
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
1381
|
-
}[keyof T], keyof T>;
|
|
1324
|
+
type RequiredKeys<T> = Extract<{ [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T], keyof T>;
|
|
1382
1325
|
/**
|
|
1383
1326
|
* Gets the keys of an object type that are optional.
|
|
1384
1327
|
*/
|
|
@@ -1386,13 +1329,7 @@ type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
|
|
|
1386
1329
|
/**
|
|
1387
1330
|
* Extracts the keys from a type that are not `readonly`.
|
|
1388
1331
|
*/
|
|
1389
|
-
type ReadonlyKeys<T> = Extract<{
|
|
1390
|
-
[K in keyof T]-?: ReadonlyEquivalent<{
|
|
1391
|
-
[_K in K]: T[K];
|
|
1392
|
-
}, {
|
|
1393
|
-
-readonly [_K in K]: T[K];
|
|
1394
|
-
}> extends true ? never : K;
|
|
1395
|
-
}[keyof T], keyof T>;
|
|
1332
|
+
type ReadonlyKeys<T> = Extract<{ [K in keyof T]-?: ReadonlyEquivalent<{ [_K in K]: T[K] }, { -readonly [_K in K]: T[K] }> extends true ? never : K }[keyof T], keyof T>;
|
|
1396
1333
|
/**
|
|
1397
1334
|
* Determines if two types, are equivalent in a `readonly` manner.
|
|
1398
1335
|
*
|
|
@@ -1405,13 +1342,18 @@ type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (
|
|
|
1405
1342
|
* 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`.
|
|
1406
1343
|
*/
|
|
1407
1344
|
type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
|
|
1345
|
+
/**
|
|
1346
|
+
* Checks if the {@linkcode Left} type extends the {@linkcode Right} type,
|
|
1347
|
+
* excluding `any` or `never`.
|
|
1348
|
+
*/
|
|
1349
|
+
|
|
1408
1350
|
/**
|
|
1409
1351
|
* Checks if two types are strictly equal using
|
|
1410
1352
|
* the TypeScript internal identical-to operator.
|
|
1411
1353
|
*
|
|
1412
1354
|
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
|
|
1413
1355
|
*/
|
|
1414
|
-
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;
|
|
1356
|
+
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;
|
|
1415
1357
|
/**
|
|
1416
1358
|
* Checks that {@linkcode Left} and {@linkcode Right} extend each other.
|
|
1417
1359
|
* Not quite the same as an equality check since `any` can make it resolve
|
|
@@ -1419,17 +1361,21 @@ type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (
|
|
|
1419
1361
|
* {@linkcode Right} are known to avoid `any`.
|
|
1420
1362
|
*/
|
|
1421
1363
|
type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
|
|
1364
|
+
/**
|
|
1365
|
+
* @internal
|
|
1366
|
+
*/
|
|
1367
|
+
|
|
1422
1368
|
/**
|
|
1423
1369
|
* Convert a union to an intersection.
|
|
1424
1370
|
* `A | B | C` -\> `A & B & C`
|
|
1425
1371
|
*/
|
|
1426
|
-
type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
|
|
1372
|
+
type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection : never;
|
|
1427
1373
|
/**
|
|
1428
1374
|
* Get the last element of a union.
|
|
1429
1375
|
* First, converts to a union of `() => T` functions,
|
|
1430
1376
|
* then uses {@linkcode UnionToIntersection} to get the last one.
|
|
1431
1377
|
*/
|
|
1432
|
-
type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends () => infer R ? R : never;
|
|
1378
|
+
type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends (() => infer R) ? R : never;
|
|
1433
1379
|
/**
|
|
1434
1380
|
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
|
1435
1381
|
* "last" union member to the end of a tuple, and recursively prepends
|
|
@@ -1442,6 +1388,19 @@ type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends t
|
|
|
1442
1388
|
type UnionToTuple<Union> = TuplifyUnion<Union>;
|
|
1443
1389
|
type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
|
|
1444
1390
|
|
|
1391
|
+
//#endregion
|
|
1392
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/overloads.d.ts
|
|
1393
|
+
/**
|
|
1394
|
+
* A recursive version of `Pick` that selects properties from the left type that are present in the right type.
|
|
1395
|
+
* The "leaf" types from `Left` are used - only the keys of `Right` are considered.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```ts
|
|
1399
|
+
* const user = {email: 'a@b.com', name: 'John Doe', address: {street: '123 2nd St', city: 'New York', zip: '10001', state: 'NY', country: 'USA'}}
|
|
1400
|
+
*
|
|
1401
|
+
* type Result = DeepPickMatchingProps<typeof user, {name: unknown; address: {city: unknown}}> // {name: string, address: {city: string}}
|
|
1402
|
+
* ```
|
|
1403
|
+
*/
|
|
1445
1404
|
/**
|
|
1446
1405
|
* The simple(ish) way to get overload info from a function
|
|
1447
1406
|
* {@linkcode FunctionType}. Recent versions of TypeScript will match any
|
|
@@ -1453,16 +1412,16 @@ type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
|
|
|
1453
1412
|
* ten separate matches.
|
|
1454
1413
|
*/
|
|
1455
1414
|
type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1415
|
+
(...args: infer A1): infer R1;
|
|
1416
|
+
(...args: infer A2): infer R2;
|
|
1417
|
+
(...args: infer A3): infer R3;
|
|
1418
|
+
(...args: infer A4): infer R4;
|
|
1419
|
+
(...args: infer A5): infer R5;
|
|
1420
|
+
(...args: infer A6): infer R6;
|
|
1421
|
+
(...args: infer A7): infer R7;
|
|
1422
|
+
(...args: infer A8): infer R8;
|
|
1423
|
+
(...args: infer A9): infer R9;
|
|
1424
|
+
(...args: infer A10): infer R10;
|
|
1466
1425
|
} ? ((...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;
|
|
1467
1426
|
/**
|
|
1468
1427
|
* A function with `unknown` parameters and return type.
|
|
@@ -1503,69 +1462,69 @@ type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUn
|
|
|
1503
1462
|
* then 9, then 8, etc., to get a union of the overload variants.
|
|
1504
1463
|
*/
|
|
1505
1464
|
type DecreasingOverloadsInfoUnion<F> = F extends {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1465
|
+
(...args: infer A1): infer R1;
|
|
1466
|
+
(...args: infer A2): infer R2;
|
|
1467
|
+
(...args: infer A3): infer R3;
|
|
1468
|
+
(...args: infer A4): infer R4;
|
|
1469
|
+
(...args: infer A5): infer R5;
|
|
1470
|
+
(...args: infer A6): infer R6;
|
|
1471
|
+
(...args: infer A7): infer R7;
|
|
1472
|
+
(...args: infer A8): infer R8;
|
|
1473
|
+
(...args: infer A9): infer R9;
|
|
1474
|
+
(...args: infer A10): infer R10;
|
|
1516
1475
|
} ? ((...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 {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1476
|
+
(...args: infer A1): infer R1;
|
|
1477
|
+
(...args: infer A2): infer R2;
|
|
1478
|
+
(...args: infer A3): infer R3;
|
|
1479
|
+
(...args: infer A4): infer R4;
|
|
1480
|
+
(...args: infer A5): infer R5;
|
|
1481
|
+
(...args: infer A6): infer R6;
|
|
1482
|
+
(...args: infer A7): infer R7;
|
|
1483
|
+
(...args: infer A8): infer R8;
|
|
1484
|
+
(...args: infer A9): infer R9;
|
|
1526
1485
|
} ? ((...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 {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1486
|
+
(...args: infer A1): infer R1;
|
|
1487
|
+
(...args: infer A2): infer R2;
|
|
1488
|
+
(...args: infer A3): infer R3;
|
|
1489
|
+
(...args: infer A4): infer R4;
|
|
1490
|
+
(...args: infer A5): infer R5;
|
|
1491
|
+
(...args: infer A6): infer R6;
|
|
1492
|
+
(...args: infer A7): infer R7;
|
|
1493
|
+
(...args: infer A8): infer R8;
|
|
1535
1494
|
} ? ((...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 {
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1495
|
+
(...args: infer A1): infer R1;
|
|
1496
|
+
(...args: infer A2): infer R2;
|
|
1497
|
+
(...args: infer A3): infer R3;
|
|
1498
|
+
(...args: infer A4): infer R4;
|
|
1499
|
+
(...args: infer A5): infer R5;
|
|
1500
|
+
(...args: infer A6): infer R6;
|
|
1501
|
+
(...args: infer A7): infer R7;
|
|
1543
1502
|
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1503
|
+
(...args: infer A1): infer R1;
|
|
1504
|
+
(...args: infer A2): infer R2;
|
|
1505
|
+
(...args: infer A3): infer R3;
|
|
1506
|
+
(...args: infer A4): infer R4;
|
|
1507
|
+
(...args: infer A5): infer R5;
|
|
1508
|
+
(...args: infer A6): infer R6;
|
|
1550
1509
|
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1510
|
+
(...args: infer A1): infer R1;
|
|
1511
|
+
(...args: infer A2): infer R2;
|
|
1512
|
+
(...args: infer A3): infer R3;
|
|
1513
|
+
(...args: infer A4): infer R4;
|
|
1514
|
+
(...args: infer A5): infer R5;
|
|
1556
1515
|
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1516
|
+
(...args: infer A1): infer R1;
|
|
1517
|
+
(...args: infer A2): infer R2;
|
|
1518
|
+
(...args: infer A3): infer R3;
|
|
1519
|
+
(...args: infer A4): infer R4;
|
|
1561
1520
|
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1521
|
+
(...args: infer A1): infer R1;
|
|
1522
|
+
(...args: infer A2): infer R2;
|
|
1523
|
+
(...args: infer A3): infer R3;
|
|
1565
1524
|
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
} ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends (...args: infer A1) => infer R1 ? ((...p: A1) => R1) : never;
|
|
1525
|
+
(...args: infer A1): infer R1;
|
|
1526
|
+
(...args: infer A2): infer R2;
|
|
1527
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends ((...args: infer A1) => infer R1) ? ((...p: A1) => R1) : never;
|
|
1569
1528
|
/**
|
|
1570
1529
|
* Get a union of overload variants for a function {@linkcode FunctionType}.
|
|
1571
1530
|
* Does a check for whether we can do the one-shot
|
|
@@ -1573,6 +1532,10 @@ type DecreasingOverloadsInfoUnion<F> = F extends {
|
|
|
1573
1532
|
* falls back to the more complicated utility.
|
|
1574
1533
|
*/
|
|
1575
1534
|
type OverloadsInfoUnion<FunctionType> = IsNever<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
|
|
1535
|
+
/**
|
|
1536
|
+
* Allows inferring any function using the `infer` keyword.
|
|
1537
|
+
*/
|
|
1538
|
+
|
|
1576
1539
|
/**
|
|
1577
1540
|
* The simple(ish) way to get overload info from a constructor
|
|
1578
1541
|
* {@linkcode ConstructorType}. Recent versions of TypeScript will match any
|
|
@@ -1584,16 +1547,16 @@ type OverloadsInfoUnion<FunctionType> = IsNever<TSPost53OverloadsInfoUnion<(a: 1
|
|
|
1584
1547
|
* we'll need to painstakingly do ten separate matches.
|
|
1585
1548
|
*/
|
|
1586
1549
|
type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1550
|
+
new (...args: infer A1): infer R1;
|
|
1551
|
+
new (...args: infer A2): infer R2;
|
|
1552
|
+
new (...args: infer A3): infer R3;
|
|
1553
|
+
new (...args: infer A4): infer R4;
|
|
1554
|
+
new (...args: infer A5): infer R5;
|
|
1555
|
+
new (...args: infer A6): infer R6;
|
|
1556
|
+
new (...args: infer A7): infer R7;
|
|
1557
|
+
new (...args: infer A8): infer R8;
|
|
1558
|
+
new (...args: infer A9): infer R9;
|
|
1559
|
+
new (...args: infer A10): infer R10;
|
|
1597
1560
|
} ? (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;
|
|
1598
1561
|
/**
|
|
1599
1562
|
* A constructor function with `unknown` parameters and return type.
|
|
@@ -1620,69 +1583,69 @@ type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingC
|
|
|
1620
1583
|
* then 9, then 8, etc., to get a union of the overload variants.
|
|
1621
1584
|
*/
|
|
1622
1585
|
type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1586
|
+
new (...args: infer A1): infer R1;
|
|
1587
|
+
new (...args: infer A2): infer R2;
|
|
1588
|
+
new (...args: infer A3): infer R3;
|
|
1589
|
+
new (...args: infer A4): infer R4;
|
|
1590
|
+
new (...args: infer A5): infer R5;
|
|
1591
|
+
new (...args: infer A6): infer R6;
|
|
1592
|
+
new (...args: infer A7): infer R7;
|
|
1593
|
+
new (...args: infer A8): infer R8;
|
|
1594
|
+
new (...args: infer A9): infer R9;
|
|
1595
|
+
new (...args: infer A10): infer R10;
|
|
1633
1596
|
} ? (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 {
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1597
|
+
new (...args: infer A1): infer R1;
|
|
1598
|
+
new (...args: infer A2): infer R2;
|
|
1599
|
+
new (...args: infer A3): infer R3;
|
|
1600
|
+
new (...args: infer A4): infer R4;
|
|
1601
|
+
new (...args: infer A5): infer R5;
|
|
1602
|
+
new (...args: infer A6): infer R6;
|
|
1603
|
+
new (...args: infer A7): infer R7;
|
|
1604
|
+
new (...args: infer A8): infer R8;
|
|
1605
|
+
new (...args: infer A9): infer R9;
|
|
1643
1606
|
} ? (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 {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1607
|
+
new (...args: infer A1): infer R1;
|
|
1608
|
+
new (...args: infer A2): infer R2;
|
|
1609
|
+
new (...args: infer A3): infer R3;
|
|
1610
|
+
new (...args: infer A4): infer R4;
|
|
1611
|
+
new (...args: infer A5): infer R5;
|
|
1612
|
+
new (...args: infer A6): infer R6;
|
|
1613
|
+
new (...args: infer A7): infer R7;
|
|
1614
|
+
new (...args: infer A8): infer R8;
|
|
1652
1615
|
} ? (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 {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1616
|
+
new (...args: infer A1): infer R1;
|
|
1617
|
+
new (...args: infer A2): infer R2;
|
|
1618
|
+
new (...args: infer A3): infer R3;
|
|
1619
|
+
new (...args: infer A4): infer R4;
|
|
1620
|
+
new (...args: infer A5): infer R5;
|
|
1621
|
+
new (...args: infer A6): infer R6;
|
|
1622
|
+
new (...args: infer A7): infer R7;
|
|
1660
1623
|
} ? (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 {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1624
|
+
new (...args: infer A1): infer R1;
|
|
1625
|
+
new (...args: infer A2): infer R2;
|
|
1626
|
+
new (...args: infer A3): infer R3;
|
|
1627
|
+
new (...args: infer A4): infer R4;
|
|
1628
|
+
new (...args: infer A5): infer R5;
|
|
1629
|
+
new (...args: infer A6): infer R6;
|
|
1667
1630
|
} ? (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 {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1631
|
+
new (...args: infer A1): infer R1;
|
|
1632
|
+
new (...args: infer A2): infer R2;
|
|
1633
|
+
new (...args: infer A3): infer R3;
|
|
1634
|
+
new (...args: infer A4): infer R4;
|
|
1635
|
+
new (...args: infer A5): infer R5;
|
|
1673
1636
|
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1637
|
+
new (...args: infer A1): infer R1;
|
|
1638
|
+
new (...args: infer A2): infer R2;
|
|
1639
|
+
new (...args: infer A3): infer R3;
|
|
1640
|
+
new (...args: infer A4): infer R4;
|
|
1678
1641
|
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1642
|
+
new (...args: infer A1): infer R1;
|
|
1643
|
+
new (...args: infer A2): infer R2;
|
|
1644
|
+
new (...args: infer A3): infer R3;
|
|
1682
1645
|
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends new (...args: infer A1) => infer R1 ? (new (...p: A1) => R1) : never;
|
|
1646
|
+
new (...args: infer A1): infer R1;
|
|
1647
|
+
new (...args: infer A2): infer R2;
|
|
1648
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends (new (...args: infer A1) => infer R1) ? (new (...p: A1) => R1) : never;
|
|
1686
1649
|
/**
|
|
1687
1650
|
* Get a union of overload variants for a constructor
|
|
1688
1651
|
* {@linkcode ConstructorType}. Does a check for whether we can do the
|
|
@@ -1704,6 +1667,8 @@ type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<
|
|
|
1704
1667
|
*/
|
|
1705
1668
|
type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>['length'];
|
|
1706
1669
|
|
|
1670
|
+
//#endregion
|
|
1671
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/branding.d.ts
|
|
1707
1672
|
/**
|
|
1708
1673
|
* Represents a deeply branded type.
|
|
1709
1674
|
*
|
|
@@ -1721,117 +1686,92 @@ type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>
|
|
|
1721
1686
|
* better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
|
|
1722
1687
|
*/
|
|
1723
1688
|
type DeepBrand<T> = IsNever<T> extends true ? {
|
|
1724
|
-
|
|
1689
|
+
type: 'never';
|
|
1725
1690
|
} : IsAny<T> extends true ? {
|
|
1726
|
-
|
|
1691
|
+
type: 'any';
|
|
1727
1692
|
} : IsUnknown<T> extends true ? {
|
|
1728
|
-
|
|
1693
|
+
type: 'unknown';
|
|
1729
1694
|
} : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
} : T extends new (...args: any[]) => any ? {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
} : T extends (...args: infer P) => infer R ? NumOverloads<T> extends 1 ? {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1695
|
+
type: 'primitive';
|
|
1696
|
+
value: T;
|
|
1697
|
+
} : T extends (new (...args: any[]) => any) ? {
|
|
1698
|
+
type: 'constructor';
|
|
1699
|
+
params: ConstructorOverloadParameters<T>;
|
|
1700
|
+
instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
|
|
1701
|
+
} : T extends ((...args: infer P) => infer R) ? NumOverloads<T> extends 1 ? {
|
|
1702
|
+
type: 'function';
|
|
1703
|
+
params: DeepBrand<P>;
|
|
1704
|
+
return: DeepBrand<R>;
|
|
1705
|
+
this: DeepBrand<ThisParameterType<T>>;
|
|
1706
|
+
props: DeepBrand<Omit<T, keyof Function>>;
|
|
1742
1707
|
} : UnionToTuple<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
[K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]>;
|
|
1746
|
-
};
|
|
1708
|
+
type: 'overloads';
|
|
1709
|
+
overloads: { [K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]> };
|
|
1747
1710
|
} : never : T extends any[] ? {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
[K in keyof T]: T[K];
|
|
1751
|
-
};
|
|
1711
|
+
type: 'array';
|
|
1712
|
+
items: { [K in keyof T]: T[K] };
|
|
1752
1713
|
} : {
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
optional: OptionalKeys<T>;
|
|
1760
|
-
constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
|
|
1714
|
+
type: 'object';
|
|
1715
|
+
properties: { [K in keyof T]: DeepBrand<T[K]> };
|
|
1716
|
+
readonly: ReadonlyKeys<T>;
|
|
1717
|
+
required: RequiredKeys<T>;
|
|
1718
|
+
optional: OptionalKeys<T>;
|
|
1719
|
+
constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
|
|
1761
1720
|
};
|
|
1762
1721
|
/**
|
|
1763
1722
|
* Checks if two types are strictly equal using branding.
|
|
1764
1723
|
*/
|
|
1765
1724
|
type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
|
|
1766
1725
|
|
|
1726
|
+
//#endregion
|
|
1727
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/messages.d.ts
|
|
1767
1728
|
/**
|
|
1768
1729
|
* Determines the printable type representation for a given type.
|
|
1769
1730
|
*/
|
|
1770
|
-
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' : '...';
|
|
1731
|
+
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' : '...';
|
|
1771
1732
|
/**
|
|
1772
1733
|
* Helper for showing end-user a hint why their type assertion is failing.
|
|
1773
1734
|
* This swaps "leaf" types with a literal message about what the actual and
|
|
1774
1735
|
* expected types are. Needs to check for `Not<IsAny<Actual>>` because
|
|
1775
1736
|
* otherwise `LeafTypeOf<Actual>` returns `never`, which extends everything 🤔
|
|
1776
1737
|
*/
|
|
1777
|
-
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]>> : {
|
|
1778
|
-
[K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
|
|
1779
|
-
} : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
|
|
1738
|
+
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]>> : { [K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never> } : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
|
|
1780
1739
|
|
|
1740
|
+
//#endregion
|
|
1741
|
+
//#region src/types/core/variants.types.d.ts
|
|
1742
|
+
/**
|
|
1743
|
+
* @internal
|
|
1744
|
+
*/
|
|
1781
1745
|
type NarrowVariant<TRoot extends {
|
|
1782
|
-
|
|
1783
|
-
}, TKey extends keyof TRoot, TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
1784
|
-
|
|
1785
|
-
} ? V : unknown> = Extract<TRoot, {
|
|
1786
|
-
[K in TKey]: RegleFieldStatus<TValue, any, any>;
|
|
1787
|
-
}>;
|
|
1746
|
+
[x: string]: unknown;
|
|
1747
|
+
}, TKey extends keyof TRoot, TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
1748
|
+
$value: infer V;
|
|
1749
|
+
} ? V : unknown)> = Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> }>;
|
|
1788
1750
|
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'> & {
|
|
1789
|
-
|
|
1751
|
+
$fields: ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>];
|
|
1790
1752
|
} : RegleStatus<TState, TRules, TShortcuts>;
|
|
1791
|
-
type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}> = {
|
|
1792
|
-
|
|
1793
|
-
[TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
|
|
1794
|
-
} & {
|
|
1795
|
-
[TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
|
|
1796
|
-
} : {};
|
|
1797
|
-
};
|
|
1798
|
-
type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [
|
|
1799
|
-
infer F,
|
|
1800
|
-
...infer R
|
|
1801
|
-
] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
|
|
1753
|
+
type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple$1<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
1754
|
+
type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
|
|
1802
1755
|
type PossibleLiteralTypes<T extends Record<string, any>, TKey extends keyof T> = unknown extends T[TKey] ? {
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
}
|
|
1809
|
-
[TVal in NonNullable<T[TKey]>]: {
|
|
1810
|
-
[K in TKey]-?: Omit<RegleRuleDecl<TVal, Partial<AllRulesDeclarations>>, 'literal'> & {
|
|
1811
|
-
literal?: RegleRuleDefinition<MaybeInput<TVal>, [
|
|
1812
|
-
literal: TVal
|
|
1813
|
-
], false, boolean, MaybeInput<TVal>, string | number>;
|
|
1814
|
-
};
|
|
1815
|
-
};
|
|
1816
|
-
};
|
|
1756
|
+
[x: string]: { [K in TKey]-?: Omit<RegleRuleDecl<any, Partial<AllRulesDeclarations>>, 'literal'> & {
|
|
1757
|
+
literal?: RegleRuleDefinition<any, [literal: any], false, boolean, any, string | number>;
|
|
1758
|
+
} };
|
|
1759
|
+
} : { [TVal in NonNullable<T[TKey]>]: { [K in TKey]-?: Omit<RegleRuleDecl<TVal, Partial<AllRulesDeclarations>>, 'literal'> & {
|
|
1760
|
+
literal?: RegleRuleDefinition<MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number>;
|
|
1761
|
+
} } };
|
|
1817
1762
|
type RequiredForm<T extends Record<string, any>, TKey extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey> & PossibleLiteralTypes<T, TKey>[keyof PossibleLiteralTypes<T, TKey>];
|
|
1818
|
-
type VariantTuple<T extends Record<string, any>, TKey extends keyof T> = [
|
|
1819
|
-
RequiredForm<T, TKey>,
|
|
1820
|
-
...RequiredForm<T, TKey>[]
|
|
1821
|
-
];
|
|
1763
|
+
type VariantTuple<T extends Record<string, any>, TKey extends keyof T> = [RequiredForm<T, TKey>, ...RequiredForm<T, TKey>[]];
|
|
1822
1764
|
|
|
1765
|
+
//#endregion
|
|
1766
|
+
//#region src/core/useRegle/useRegle.d.ts
|
|
1823
1767
|
type useRegleFnOptions<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = 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;
|
|
1824
1768
|
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
1832
|
-
modifiers?: RegleBehaviourOptions;
|
|
1833
|
-
shortcuts?: TShortcuts;
|
|
1834
|
-
};
|
|
1769
|
+
<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = (isDeepExact<NoInferLegacy<TRules>, Unwrap<TState extends Record<string, any> ? TState : {}>> extends true ? {} : MismatchInfo<RegleRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>, NoInferLegacy<TRules>>)>(...params: [state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRef<TRules> | ((...args: any[]) => TRules) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
1770
|
+
__config?: {
|
|
1771
|
+
rules?: () => CustomRulesDeclarationTree;
|
|
1772
|
+
modifiers?: RegleBehaviourOptions;
|
|
1773
|
+
shortcuts?: TShortcuts;
|
|
1774
|
+
};
|
|
1835
1775
|
}
|
|
1836
1776
|
/**
|
|
1837
1777
|
* useRegle serves as the foundation for validation logic.
|
|
@@ -1854,8 +1794,10 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
|
|
|
1854
1794
|
*/
|
|
1855
1795
|
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
1856
1796
|
|
|
1797
|
+
//#endregion
|
|
1798
|
+
//#region src/core/useRegle/inferRules.d.ts
|
|
1857
1799
|
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
1858
|
-
|
|
1800
|
+
<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValid = (isDeepExact<NoInferLegacy<TRules>, Unwrap<TState extends Record<string, any> ? TState : {}>> extends true ? {} : MismatchInfo<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>>)>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? TDecl : TState extends Record<string, any> ? TRules : {}): NonNullable<TState> extends PrimitiveTypes ? TDecl : TRules;
|
|
1859
1801
|
}
|
|
1860
1802
|
/**
|
|
1861
1803
|
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
@@ -1866,49 +1808,93 @@ interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
|
1866
1808
|
*/
|
|
1867
1809
|
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
1868
1810
|
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1811
|
+
//#endregion
|
|
1812
|
+
//#region src/core/useRegle/root/useRootStorage.d.ts
|
|
1813
|
+
declare function useRootStorage({
|
|
1814
|
+
initialState,
|
|
1815
|
+
options,
|
|
1816
|
+
scopeRules,
|
|
1817
|
+
state,
|
|
1818
|
+
customRules,
|
|
1819
|
+
shortcuts,
|
|
1820
|
+
schemaErrors,
|
|
1821
|
+
schemaMode,
|
|
1822
|
+
onValidate
|
|
1823
|
+
}: {
|
|
1824
|
+
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
1825
|
+
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1826
|
+
options: ResolvedRegleBehaviourOptions;
|
|
1827
|
+
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1828
|
+
customRules?: () => CustomRulesDeclarationTree;
|
|
1829
|
+
shortcuts: RegleShortcutDefinition | undefined;
|
|
1830
|
+
schemaErrors?: Ref<any | undefined>;
|
|
1831
|
+
schemaMode?: boolean;
|
|
1832
|
+
onValidate?: () => Promise<$InternalRegleResult>;
|
|
1879
1833
|
}): {
|
|
1880
|
-
|
|
1834
|
+
regle: $InternalRegleStatusType | undefined;
|
|
1881
1835
|
};
|
|
1882
1836
|
|
|
1837
|
+
//#endregion
|
|
1838
|
+
//#region src/core/useRegle/useErrors.d.ts
|
|
1883
1839
|
/**
|
|
1884
1840
|
* Converts a nested $errors object to a flat array of string errors
|
|
1885
1841
|
*
|
|
1886
1842
|
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
1887
1843
|
*/
|
|
1888
1844
|
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
1889
|
-
|
|
1845
|
+
includePath: true;
|
|
1890
1846
|
}): {
|
|
1891
|
-
|
|
1892
|
-
|
|
1847
|
+
error: string;
|
|
1848
|
+
path: string;
|
|
1893
1849
|
}[];
|
|
1894
1850
|
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
1895
|
-
|
|
1851
|
+
includePath?: false;
|
|
1896
1852
|
}): string[];
|
|
1897
1853
|
|
|
1898
|
-
|
|
1854
|
+
//#endregion
|
|
1855
|
+
//#region src/types/utils/props.types.d.ts
|
|
1856
|
+
/**
|
|
1857
|
+
* Infer type of the `r$` of any function returning a regle instance
|
|
1858
|
+
*/
|
|
1859
|
+
type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
|
|
1860
|
+
/**
|
|
1861
|
+
* Infer custom rules declared in a global configuration
|
|
1862
|
+
*/
|
|
1899
1863
|
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<U> & Partial<DefaultValidators>> : {};
|
|
1864
|
+
/**
|
|
1865
|
+
* Infer custom shortcuts declared in a global configuration
|
|
1866
|
+
*/
|
|
1900
1867
|
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
type
|
|
1905
|
-
|
|
1906
|
-
|
|
1868
|
+
/**
|
|
1869
|
+
* Extract a set rules and setting them as required
|
|
1870
|
+
*/
|
|
1871
|
+
type RegleEnforceRequiredRules<TRules extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules> & { [K in TRules]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
1872
|
+
/**
|
|
1873
|
+
* Extract a set of custom rules from a global configuration and setting them as required
|
|
1874
|
+
|
|
1875
|
+
*/
|
|
1876
|
+
type RegleEnforceCustomRequiredRules<T extends Partial<AllRulesDeclarations> | useRegleFn<any, any>, TRules extends (T extends useRegleFn<any, any> ? keyof InferRegleRules<T> : keyof T)> = Omit<Partial<DefaultValidatorsTree>, TRules> & { [K in TRules]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
|
|
1877
|
+
/**
|
|
1878
|
+
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
1879
|
+
*/
|
|
1880
|
+
type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState extends unknown = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = InferRegleRules<T>> = RegleFieldStatus<TState, TRules, InferRegleShortcuts<T>>;
|
|
1881
|
+
/**
|
|
1882
|
+
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
1883
|
+
*/
|
|
1884
|
+
type RegleCustomStatus<T extends useRegleFn<any, any>, TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = InferRegleRules<T>> = RegleStatus<TState, TRules, InferRegleShortcuts<T>>;
|
|
1885
|
+
/**
|
|
1886
|
+
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
1887
|
+
*/
|
|
1888
|
+
type RegleCustomCollectionStatus<T extends useRegleFn<any, any>, TState extends any[] = any[], TRules extends ReglePartialRuleTree<ArrayElement<TState>> = InferRegleRules<T>> = RegleCollectionStatus<TState, TRules, InferRegleShortcuts<T>>;
|
|
1907
1889
|
|
|
1890
|
+
//#endregion
|
|
1891
|
+
//#region src/types/utils/object.types.d.ts
|
|
1908
1892
|
type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1893
|
+
/**
|
|
1894
|
+
* Restore the optional properties (with ?) of a generated mapped object type
|
|
1895
|
+
*/
|
|
1896
|
+
|
|
1897
|
+
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
1912
1898
|
/**
|
|
1913
1899
|
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
1914
1900
|
*/
|
|
@@ -1920,17 +1906,7 @@ type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K ex
|
|
|
1920
1906
|
/**
|
|
1921
1907
|
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
1922
1908
|
*/
|
|
1923
|
-
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [
|
|
1924
|
-
infer F extends Record<string, any>,
|
|
1925
|
-
...infer R
|
|
1926
|
-
] ? [
|
|
1927
|
-
{
|
|
1928
|
-
[K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K>;
|
|
1929
|
-
} & {
|
|
1930
|
-
[K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K>;
|
|
1931
|
-
},
|
|
1932
|
-
...RetrieveUnionUnknownValues<R, TKeys>
|
|
1933
|
-
] : [];
|
|
1909
|
+
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
|
|
1934
1910
|
/**
|
|
1935
1911
|
* Get all possible keys from a union, even the ones present only on one union
|
|
1936
1912
|
*/
|
|
@@ -1945,106 +1921,102 @@ type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTupl
|
|
|
1945
1921
|
type JoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : TUnion;
|
|
1946
1922
|
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;
|
|
1947
1923
|
type EnumLike = {
|
|
1948
|
-
|
|
1949
|
-
|
|
1924
|
+
[k: string]: string | number;
|
|
1925
|
+
[nu: number]: string;
|
|
1950
1926
|
};
|
|
1951
1927
|
type enumType<T extends Record<string, unknown>> = T[keyof T];
|
|
1952
1928
|
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
1953
|
-
type TupleToPlainObj<T> = {
|
|
1954
|
-
[I in keyof T & `${number}`]: T[I];
|
|
1955
|
-
};
|
|
1929
|
+
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
1956
1930
|
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
}[keyof TRules] extends true ? true : false;
|
|
1931
|
+
//#endregion
|
|
1932
|
+
//#region src/types/utils/mismatch.types.d.ts
|
|
1933
|
+
type isDeepExact<TRules, TTree> = { [K in keyof TRules]-?: CheckDeepExact<NonNullable<TRules[K]>, K extends keyof JoinDiscriminatedUnions<TTree> ? NonNullable<JoinDiscriminatedUnions<TTree>[K]> : never> }[keyof TRules] extends true ? true : false;
|
|
1960
1934
|
type CheckDeepExact<TRules, TTree> = [TTree] extends [never] ? false : TRules extends RegleCollectionRuleDecl ? TTree extends Array<any> ? isDeepExact<NonNullable<TRules['$each']>, JoinDiscriminatedUnions<NonNullable<ArrayElement<TTree>>>> : TRules extends RegleRuleDecl ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<TRules, TTree> : false : TRules extends RegleRuleDecl ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<TRules, TTree> : false;
|
|
1961
1935
|
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
}> : Prettify<{
|
|
1965
|
-
[K in keyof UnwrapSimple<TRules>]: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe>;
|
|
1966
|
-
}>;
|
|
1936
|
+
//#endregion
|
|
1937
|
+
//#region src/types/utils/infer.types.d.ts
|
|
1938
|
+
type InferInput<TRules extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>), TMarkMaybe extends boolean = true> = IsUnion$1<UnwrapSimple<TRules>> extends true ? InferTupleUnionInput<UnionToTuple$1<UnwrapSimple<TRules>>>[number] : TMarkMaybe extends true ? Prettify<{ [K in keyof UnwrapSimple<TRules>]?: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe> }> : Prettify<{ [K in keyof UnwrapSimple<TRules>]: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe> }>;
|
|
1967
1939
|
type ProcessInputChildren<TRule extends unknown, TMarkMaybe extends boolean> = TRule extends {
|
|
1968
|
-
|
|
1940
|
+
$each: RegleCollectionEachRules<any, any>;
|
|
1969
1941
|
} ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any, any> ? InferInput<ExtractFromGetter<TRule['$each']>, TMarkMaybe>[] : any[] : TRule extends RegleRuleDecl<any, any> ? [ExtractTypeFromRules<TRule>] extends [never] ? unknown : ExtractTypeFromRules<TRule> : TRule extends ReglePartialRuleTree<any, any> ? InferInput<TRule, TMarkMaybe> : string;
|
|
1970
1942
|
type ExtractTypeFromRules<TRules extends RegleRuleDecl<any, any>> = FilterRulesWithInput<TRules> extends {
|
|
1971
|
-
|
|
1943
|
+
type: infer Input;
|
|
1972
1944
|
} ? Input : [FilterRulesWithSingleType<TRules>[keyof FilterRulesWithSingleType<TRules>]] extends [never] ? FilterRulesWithInput<TRules>[keyof FilterRulesWithInput<TRules>] : FilterRulesWithSingleType<TRules>[keyof FilterRulesWithSingleType<TRules>];
|
|
1973
|
-
type FilterRulesWithInput<TRules extends RegleRuleDecl<any, any>> = {
|
|
1974
|
-
|
|
1975
|
-
};
|
|
1976
|
-
type FilterRulesWithSingleType<TRules extends RegleRuleDecl<any, any>> = {
|
|
1977
|
-
[K in keyof TRules as TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion$1<NonNullable<Input>> extends true ? never : K : never]: TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? IsUnion$1<NonNullable<Input>> extends true ? unknown : Input : unknown;
|
|
1978
|
-
};
|
|
1945
|
+
type FilterRulesWithInput<TRules extends RegleRuleDecl<any, any>> = { [K in keyof TRules as TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : K : never]: TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? Input : unknown };
|
|
1946
|
+
type FilterRulesWithSingleType<TRules extends RegleRuleDecl<any, any>> = { [K in keyof TRules as TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion$1<NonNullable<Input>> extends true ? never : K : never]: TRules[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? IsUnion$1<NonNullable<Input>> extends true ? unknown : Input : unknown };
|
|
1979
1947
|
type InferTupleUnionInput<T extends any[]> = T extends [infer F extends ReglePartialRuleTree, ...infer R] ? [InferInput<F, true>, ...InferTupleUnionInput<R>] : [];
|
|
1980
1948
|
|
|
1949
|
+
//#endregion
|
|
1950
|
+
//#region src/types/rules/rule.params.types.d.ts
|
|
1981
1951
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
1982
1952
|
/**
|
|
1983
1953
|
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
1984
1954
|
*
|
|
1985
1955
|
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
1986
1956
|
*/
|
|
1987
|
-
type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
1988
|
-
|
|
1989
|
-
}) => any : never>;
|
|
1990
|
-
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
1991
|
-
[K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K];
|
|
1992
|
-
}) => any : never>;
|
|
1957
|
+
type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>> }) => any : never>;
|
|
1958
|
+
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K] }) => any : never>;
|
|
1993
1959
|
|
|
1960
|
+
//#endregion
|
|
1961
|
+
//#region src/types/rules/rule.internal.types.d.ts
|
|
1994
1962
|
/**
|
|
1995
1963
|
* Internal definition of the rule, this can be used to reset or patch the rule
|
|
1996
1964
|
*/
|
|
1997
1965
|
type RegleInternalRuleDefs<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> = Raw<{
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1966
|
+
_validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1967
|
+
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
1968
|
+
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => boolean);
|
|
1969
|
+
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
1970
|
+
_type?: string;
|
|
1971
|
+
_message_patched: boolean;
|
|
1972
|
+
_tooltip_patched: boolean;
|
|
1973
|
+
_params?: RegleUniversalParams<TParams>;
|
|
1974
|
+
_async: TAsync;
|
|
1975
|
+
readonly _brand: symbol;
|
|
2008
1976
|
}>;
|
|
2009
1977
|
declare const InternalRuleType: {
|
|
2010
|
-
|
|
2011
|
-
|
|
1978
|
+
readonly Inline: "__inline";
|
|
1979
|
+
readonly Async: "__async";
|
|
2012
1980
|
};
|
|
2013
1981
|
type InternalRuleType = enumType<typeof InternalRuleType>;
|
|
2014
1982
|
|
|
1983
|
+
//#endregion
|
|
1984
|
+
//#region src/types/rules/rule.definition.type.d.ts
|
|
2015
1985
|
type IsLiteral<T> = string extends T ? false : true;
|
|
2016
1986
|
/**
|
|
2017
1987
|
* Returned typed of rules created with `createRule`
|
|
2018
1988
|
* */
|
|
2019
|
-
interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TInput = unknown, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1989
|
+
interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & infer M ? M : TValue)> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
|
|
1990
|
+
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
|
|
1991
|
+
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1992
|
+
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
1993
|
+
tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1994
|
+
type?: string;
|
|
1995
|
+
_value?: IsLiteral<TValue> extends true ? TValue : any;
|
|
1996
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
|
|
2027
1997
|
}
|
|
1998
|
+
/**
|
|
1999
|
+
* @internal
|
|
2000
|
+
* */
|
|
2001
|
+
|
|
2028
2002
|
/**
|
|
2029
2003
|
* Rules with params created with `createRules` are callable while being customizable
|
|
2030
2004
|
*/
|
|
2031
|
-
type RegleRuleWithParamsDefinition<TValue extends unknown = unknown, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TInput = unknown, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> = RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & {
|
|
2032
|
-
|
|
2005
|
+
type RegleRuleWithParamsDefinition<TValue extends unknown = unknown, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & infer M ? M : TValue)> = RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & {
|
|
2006
|
+
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TFilteredValue, TParams, TAsync, TMetadata, TInput>;
|
|
2033
2007
|
} & (TParams extends [param?: any, ...any[]] ? {
|
|
2034
|
-
|
|
2008
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
2035
2009
|
} : {});
|
|
2036
|
-
type RegleRuleWithParamsDefinitionInput<TValue extends any = any, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> = RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & (TParams extends [param?: any, ...any[]] ? {
|
|
2037
|
-
|
|
2010
|
+
type RegleRuleWithParamsDefinitionInput<TValue extends any = any, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = (TValue extends Date & File & infer M ? M : TValue)> = RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & (TParams extends [param?: any, ...any[]] ? {
|
|
2011
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
2038
2012
|
} : {});
|
|
2039
2013
|
type RegleRuleMetadataExtended = {
|
|
2040
|
-
|
|
2041
|
-
|
|
2014
|
+
$valid: boolean;
|
|
2015
|
+
[x: string]: any;
|
|
2042
2016
|
};
|
|
2043
2017
|
type UnwrapRuleTree<T extends {
|
|
2044
|
-
|
|
2045
|
-
}> = {
|
|
2046
|
-
[K in keyof T]: UnwrapRuleWithParams<T[K]>;
|
|
2047
|
-
};
|
|
2018
|
+
[x: string]: RegleRuleRawInput<any, any[], any, any> | undefined;
|
|
2019
|
+
}> = { [K in keyof T]: UnwrapRuleWithParams<T[K]> };
|
|
2048
2020
|
type UnwrapRuleWithParams<T extends RegleRuleRawInput<any, any[], any, any> | undefined> = T extends RegleRuleWithParamsDefinition<infer TValue, infer TParams, infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> : T;
|
|
2049
2021
|
/**
|
|
2050
2022
|
* Define a rule Metadata definition
|
|
@@ -2052,32 +2024,36 @@ type UnwrapRuleWithParams<T extends RegleRuleRawInput<any, any[], any, any> | un
|
|
|
2052
2024
|
type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
|
|
2053
2025
|
type DefaultMetadataPropertiesCommon = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid' | '$dirty' | '$pending' | '$correct' | '$error'>;
|
|
2054
2026
|
type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
2055
|
-
|
|
2027
|
+
$rule: Pick<$InternalRegleRuleStatus, '$valid' | '$pending'>;
|
|
2056
2028
|
};
|
|
2057
2029
|
/**
|
|
2058
2030
|
* Will be used to consume metadata on related helpers and rule status
|
|
2059
2031
|
*/
|
|
2060
2032
|
type RegleRuleMetadataConsumer<TValue extends any, TParams extends [...any[]] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
2061
|
-
|
|
2033
|
+
$value: Maybe<TValue>;
|
|
2062
2034
|
} & DefaultMetadataProperties & (TParams extends never ? {} : {
|
|
2063
|
-
|
|
2035
|
+
$params: [...TParams];
|
|
2064
2036
|
}) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
|
|
2065
2037
|
/**
|
|
2066
2038
|
* Will be used to consume metadata on related helpers and rule status
|
|
2067
2039
|
*/
|
|
2068
2040
|
type PossibleRegleRuleMetadataConsumer<TValue> = {
|
|
2069
|
-
|
|
2041
|
+
$value: Maybe<TValue>;
|
|
2070
2042
|
} & DefaultMetadataProperties & {
|
|
2071
|
-
|
|
2043
|
+
$params?: [...any[]];
|
|
2072
2044
|
};
|
|
2045
|
+
/**
|
|
2046
|
+
* @internal
|
|
2047
|
+
*/
|
|
2048
|
+
|
|
2073
2049
|
/**
|
|
2074
2050
|
* Generic types for a created RegleRule
|
|
2075
2051
|
*/
|
|
2076
2052
|
type RegleRuleRaw<TValue extends any = any, TParams extends [...any[]] = [...any[]], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> | RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
|
|
2077
2053
|
type RegleRuleRawInput<TValue extends any = any, TParams extends [...any[]] = [...any[]], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = Omit<RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> | RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>, 'message' | 'tooltip' | 'active'> & {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2054
|
+
message: any;
|
|
2055
|
+
active?: any;
|
|
2056
|
+
tooltip?: any;
|
|
2081
2057
|
};
|
|
2082
2058
|
/**
|
|
2083
2059
|
* Process the type of created rule with `createRule`.
|
|
@@ -2088,160 +2064,147 @@ type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync
|
|
|
2088
2064
|
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
2089
2065
|
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any[]>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
2090
2066
|
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
2091
|
-
|
|
2067
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
2092
2068
|
}) | ({
|
|
2093
|
-
|
|
2069
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
2094
2070
|
} & CollectionRegleBehaviourOptions);
|
|
2095
2071
|
|
|
2072
|
+
//#endregion
|
|
2073
|
+
//#region src/types/rules/rule.init.types.d.ts
|
|
2096
2074
|
type RegleInitPropertyGetter<TValue, TReturn, TParams extends [...any[]], TMetadata extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue, TParams, TMetadata>) => TReturn);
|
|
2097
2075
|
/**
|
|
2098
2076
|
* @argument
|
|
2099
2077
|
* createRule arguments options
|
|
2100
2078
|
*/
|
|
2101
|
-
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> {
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2079
|
+
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)> {
|
|
2080
|
+
validator: (value: Maybe<TValue>, ...args: TParams) => TReturn;
|
|
2081
|
+
message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
2082
|
+
active?: RegleInitPropertyGetter<TValue, boolean, TParams, TMetadata>;
|
|
2083
|
+
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
2084
|
+
type?: string;
|
|
2085
|
+
async?: TAsync;
|
|
2108
2086
|
}
|
|
2109
2087
|
/**
|
|
2110
2088
|
* @argument
|
|
2111
2089
|
* Rule core
|
|
2112
2090
|
*/
|
|
2113
2091
|
interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2092
|
+
validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
2093
|
+
message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
2094
|
+
active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
2095
|
+
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
2096
|
+
type?: string;
|
|
2119
2097
|
}
|
|
2098
|
+
/**
|
|
2099
|
+
* @internal
|
|
2100
|
+
* createRule arguments options
|
|
2101
|
+
*/
|
|
2102
|
+
|
|
2120
2103
|
type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
|
|
2121
|
-
|
|
2122
|
-
|
|
2104
|
+
value: TValue;
|
|
2105
|
+
params: [...TParams];
|
|
2123
2106
|
};
|
|
2124
2107
|
|
|
2108
|
+
//#endregion
|
|
2109
|
+
//#region src/core/defaultValidators.d.ts
|
|
2125
2110
|
interface CommonComparisonOptions {
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2111
|
+
/**
|
|
2112
|
+
* Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
|
|
2113
|
+
* @default true
|
|
2114
|
+
*/
|
|
2115
|
+
allowEqual?: boolean;
|
|
2131
2116
|
}
|
|
2132
2117
|
interface CommonAlphaOptions {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2118
|
+
/**
|
|
2119
|
+
* Allow symbols in alphabetical-like rules (like "_")
|
|
2120
|
+
* @default true
|
|
2121
|
+
*/
|
|
2122
|
+
allowSymbols?: boolean;
|
|
2138
2123
|
}
|
|
2139
2124
|
type DefaultValidators = {
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
options?: CommonComparisonOptions
|
|
2192
|
-
], false, boolean>;
|
|
2193
|
-
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
2194
|
-
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
2195
|
-
number: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
2196
|
-
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
2197
|
-
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
2198
|
-
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
2199
|
-
required: RegleRuleDefinition<unknown, []>;
|
|
2200
|
-
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
2201
|
-
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
2202
|
-
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
2203
|
-
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
2204
|
-
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
2205
|
-
};
|
|
2206
|
-
|
|
2125
|
+
alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined]>;
|
|
2126
|
+
alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined]>;
|
|
2127
|
+
between: RegleRuleWithParamsDefinition<number, [min: Maybe<number>, max: Maybe<number>]>;
|
|
2128
|
+
boolean: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
2129
|
+
checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
|
|
2130
|
+
contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
2131
|
+
date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
2132
|
+
dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
2133
|
+
$valid: false;
|
|
2134
|
+
error: 'date-not-after';
|
|
2135
|
+
} | {
|
|
2136
|
+
$valid: false;
|
|
2137
|
+
error: 'value-or-parameter-not-a-date';
|
|
2138
|
+
}>;
|
|
2139
|
+
dateBefore: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
2140
|
+
$valid: false;
|
|
2141
|
+
error: 'date-not-before';
|
|
2142
|
+
} | {
|
|
2143
|
+
$valid: false;
|
|
2144
|
+
error: 'value-or-parameter-not-a-date';
|
|
2145
|
+
}>;
|
|
2146
|
+
dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, after: Maybe<string | Date>, options?: CommonComparisonOptions], false, boolean>;
|
|
2147
|
+
decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
2148
|
+
email: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
2149
|
+
endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
2150
|
+
exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
|
|
2151
|
+
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
2152
|
+
hexadecimal: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
2153
|
+
integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
2154
|
+
ipv4Address: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
2155
|
+
literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
|
|
2156
|
+
macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
|
|
2157
|
+
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
2158
|
+
maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
2159
|
+
minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
2160
|
+
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
2161
|
+
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
2162
|
+
number: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
2163
|
+
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
2164
|
+
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
2165
|
+
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
2166
|
+
required: RegleRuleDefinition<unknown, []>;
|
|
2167
|
+
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
2168
|
+
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
2169
|
+
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
2170
|
+
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
2171
|
+
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
//#endregion
|
|
2175
|
+
//#region src/types/rules/rule.custom.types.d.ts
|
|
2207
2176
|
type CustomRulesDeclarationTree = {
|
|
2208
|
-
|
|
2209
|
-
};
|
|
2210
|
-
type DefaultValidatorsTree = {
|
|
2211
|
-
[K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
2177
|
+
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
2212
2178
|
};
|
|
2179
|
+
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
2213
2180
|
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
2214
2181
|
|
|
2182
|
+
//#endregion
|
|
2183
|
+
//#region src/types/rules/rule.declaration.types.d.ts
|
|
2215
2184
|
/**
|
|
2216
2185
|
* @public
|
|
2217
2186
|
*/
|
|
2218
|
-
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
|
|
2219
|
-
[TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
|
|
2220
|
-
};
|
|
2187
|
+
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
2221
2188
|
/**
|
|
2222
2189
|
* @public
|
|
2223
2190
|
*/
|
|
2224
|
-
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
|
|
2225
|
-
[TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules>;
|
|
2226
|
-
};
|
|
2191
|
+
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
2227
2192
|
/**
|
|
2228
2193
|
* @public
|
|
2229
2194
|
*/
|
|
2230
2195
|
type RegleUnknownRulesTree = {
|
|
2231
|
-
|
|
2196
|
+
[x: string]: RegleRuleDecl | RegleCollectionRuleDecl | RegleUnknownRulesTree;
|
|
2232
2197
|
};
|
|
2233
2198
|
/**
|
|
2234
2199
|
* @public
|
|
2235
2200
|
*/
|
|
2236
|
-
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> = {
|
|
2237
|
-
[TKey in keyof JoinDiscriminatedUnions<TState>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState>[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
|
|
2238
|
-
};
|
|
2201
|
+
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)> = { [TKey in keyof JoinDiscriminatedUnions<TState>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState>[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}> };
|
|
2239
2202
|
/**
|
|
2240
2203
|
* @internal
|
|
2241
2204
|
* @reference {@link ReglePartialRuleTree}
|
|
2242
2205
|
*/
|
|
2243
2206
|
type $InternalReglePartialRuleTree = {
|
|
2244
|
-
|
|
2207
|
+
[x: string]: $InternalFormPropertyTypes;
|
|
2245
2208
|
};
|
|
2246
2209
|
/**
|
|
2247
2210
|
* @public
|
|
@@ -2256,9 +2219,7 @@ type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollect
|
|
|
2256
2219
|
* @public
|
|
2257
2220
|
* Rule tree for a form property
|
|
2258
2221
|
*/
|
|
2259
|
-
type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>, TOptions extends Record<string, unknown> = FieldRegleBehaviourOptions> = TOptions & {
|
|
2260
|
-
[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[]> | TOptions[keyof TOptions];
|
|
2261
|
-
};
|
|
2222
|
+
type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>, TOptions extends Record<string, unknown> = FieldRegleBehaviourOptions> = TOptions & { [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[]> | TOptions[keyof TOptions] };
|
|
2262
2223
|
/**
|
|
2263
2224
|
* @internal
|
|
2264
2225
|
* @reference {@link RegleRuleDecl}
|
|
@@ -2268,15 +2229,15 @@ type $InternalRegleRuleDecl = FieldRegleBehaviourOptions & CollectionRegleBehavi
|
|
|
2268
2229
|
* @public
|
|
2269
2230
|
*/
|
|
2270
2231
|
type RegleCollectionRuleDeclKeyProperty = {
|
|
2271
|
-
|
|
2232
|
+
$key?: PropertyKey;
|
|
2272
2233
|
};
|
|
2273
2234
|
/**
|
|
2274
2235
|
* @public
|
|
2275
2236
|
*/
|
|
2276
2237
|
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = ({
|
|
2277
|
-
|
|
2238
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
2278
2239
|
} & RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
2279
|
-
|
|
2240
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
2280
2241
|
} & CollectionRegleBehaviourOptions);
|
|
2281
2242
|
/** @public */
|
|
2282
2243
|
type RegleCollectionEachRules<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>, RegleCollectionRuleDeclKeyProperty>;
|
|
@@ -2285,93 +2246,89 @@ type RegleCollectionEachRules<TValue = any[], TCustomRules extends Partial<AllRu
|
|
|
2285
2246
|
* @reference {@link RegleCollectionRuleDecl}
|
|
2286
2247
|
*/
|
|
2287
2248
|
type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
|
|
2288
|
-
|
|
2249
|
+
$each?: MaybeGetter<$InternalFormPropertyTypes & RegleCollectionRuleDeclKeyProperty, any>;
|
|
2289
2250
|
};
|
|
2290
2251
|
/**
|
|
2291
2252
|
* @public
|
|
2292
2253
|
*/
|
|
2293
2254
|
type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
|
|
2255
|
+
/**
|
|
2256
|
+
* @internal
|
|
2257
|
+
*/
|
|
2258
|
+
|
|
2294
2259
|
/**
|
|
2295
2260
|
* @public
|
|
2296
2261
|
* Regroup inline and registered rules
|
|
2297
2262
|
* */
|
|
2298
|
-
type FormRuleDeclaration<TValue extends any = unknown, TParams extends any[] = 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> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any], TAsync, TMetadata> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any, ...any[]], TAsync, TMetadata>;
|
|
2263
|
+
type FormRuleDeclaration<TValue extends any = unknown, TParams extends any[] = 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> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any], TAsync, TMetadata> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any, ...any[]], TAsync, TMetadata>;
|
|
2299
2264
|
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
};
|
|
2303
|
-
type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = {
|
|
2304
|
-
readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true>;
|
|
2305
|
-
};
|
|
2265
|
+
//#endregion
|
|
2266
|
+
//#region src/types/rules/rule.errors.types.d.ts
|
|
2267
|
+
type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false> };
|
|
2268
|
+
type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true> };
|
|
2306
2269
|
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[];
|
|
2307
2270
|
type RegleCollectionErrors<TState extends Record<string, any>> = {
|
|
2308
|
-
|
|
2309
|
-
|
|
2271
|
+
readonly $self: string[];
|
|
2272
|
+
readonly $each: RegleValidationErrors<TState, false>[];
|
|
2310
2273
|
};
|
|
2311
2274
|
type RegleExternalCollectionErrors<TState extends Record<string, any>> = {
|
|
2312
|
-
|
|
2313
|
-
|
|
2275
|
+
readonly $self?: string[];
|
|
2276
|
+
readonly $each?: RegleValidationErrors<TState, true>[];
|
|
2314
2277
|
};
|
|
2315
2278
|
/** @internal */
|
|
2316
2279
|
type $InternalRegleCollectionErrors = {
|
|
2317
|
-
|
|
2318
|
-
|
|
2280
|
+
readonly $self?: string[];
|
|
2281
|
+
readonly $each?: $InternalRegleErrors[];
|
|
2319
2282
|
};
|
|
2320
2283
|
type $InternalRegleErrorTree = {
|
|
2321
|
-
|
|
2284
|
+
[x: string]: $InternalRegleErrors;
|
|
2322
2285
|
};
|
|
2323
2286
|
/**
|
|
2324
2287
|
* @internal
|
|
2325
2288
|
*/
|
|
2326
2289
|
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
2327
2290
|
|
|
2291
|
+
//#endregion
|
|
2292
|
+
//#region src/types/rules/rule.status.types.d.ts
|
|
2328
2293
|
/**
|
|
2329
2294
|
* @public
|
|
2330
2295
|
*/
|
|
2331
2296
|
type RegleRoot<TState extends 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] ? {} : {
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput;
|
|
2337
|
-
};
|
|
2297
|
+
/**
|
|
2298
|
+
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
2299
|
+
*/
|
|
2300
|
+
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
2338
2301
|
});
|
|
2339
2302
|
/**
|
|
2340
2303
|
* @public
|
|
2341
2304
|
*/
|
|
2342
2305
|
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
2358
|
-
/** 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). */
|
|
2359
|
-
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
|
|
2360
|
-
} & ([TShortcuts['nested']] extends [never] ? {} : {
|
|
2361
|
-
[K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>;
|
|
2362
|
-
});
|
|
2306
|
+
/** 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. */
|
|
2307
|
+
readonly $fields: { 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 : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> };
|
|
2308
|
+
/**
|
|
2309
|
+
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
2310
|
+
*
|
|
2311
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2312
|
+
readonly $errors: RegleErrorTree<TState>;
|
|
2313
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
2314
|
+
readonly $silentErrors: RegleErrorTree<TState>;
|
|
2315
|
+
/** 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). */
|
|
2316
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
2317
|
+
/** 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). */
|
|
2318
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
|
|
2319
|
+
} & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
2363
2320
|
/**
|
|
2364
2321
|
* @internal
|
|
2365
2322
|
* @reference {@link RegleStatus}
|
|
2366
2323
|
*/
|
|
2367
2324
|
interface $InternalRegleStatus extends $InternalRegleCommonStatus {
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2325
|
+
$fields: {
|
|
2326
|
+
[x: string]: $InternalRegleStatusType;
|
|
2327
|
+
};
|
|
2328
|
+
readonly $errors: Record<string, $InternalRegleErrors>;
|
|
2329
|
+
readonly $silentErrors: Record<string, $InternalRegleErrors>;
|
|
2330
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
|
|
2331
|
+
$validate: () => Promise<$InternalRegleResult>;
|
|
2375
2332
|
}
|
|
2376
2333
|
/**
|
|
2377
2334
|
* @public
|
|
@@ -2386,254 +2343,252 @@ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleS
|
|
|
2386
2343
|
* @public
|
|
2387
2344
|
*/
|
|
2388
2345
|
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value' | '$silentValue'> & {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
};
|
|
2415
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : {
|
|
2416
|
-
[K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>;
|
|
2417
|
-
});
|
|
2346
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2347
|
+
$value: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2348
|
+
/** $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. */
|
|
2349
|
+
$silentValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2350
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2351
|
+
*
|
|
2352
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2353
|
+
readonly $errors: string[];
|
|
2354
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2355
|
+
readonly $silentErrors: string[];
|
|
2356
|
+
/** Stores external errors of the current field */
|
|
2357
|
+
readonly $externalErrors: string[];
|
|
2358
|
+
/** Stores active tooltips messages of the current field */
|
|
2359
|
+
readonly $tooltips: string[];
|
|
2360
|
+
/** Represents the inactive status. Is true when this state have empty rules */
|
|
2361
|
+
readonly $inactive: boolean;
|
|
2362
|
+
/** 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). */
|
|
2363
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
|
|
2364
|
+
/** 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). */
|
|
2365
|
+
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
2366
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
2367
|
+
readonly $rules: IsEmptyObject<TRules> extends true ? {
|
|
2368
|
+
readonly [x: string]: RegleRuleStatus<TState, any[], any>;
|
|
2369
|
+
} : { 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> };
|
|
2370
|
+
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
2418
2371
|
/**
|
|
2419
2372
|
* @internal
|
|
2420
2373
|
* @reference {@link RegleFieldStatus}
|
|
2421
2374
|
*/
|
|
2422
2375
|
interface $InternalRegleFieldStatus extends $InternalRegleCommonStatus {
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2376
|
+
$value: any;
|
|
2377
|
+
$silentValue: any;
|
|
2378
|
+
readonly $rules: Record<string, $InternalRegleRuleStatus>;
|
|
2379
|
+
readonly $externalErrors?: string[];
|
|
2380
|
+
readonly $errors: string[];
|
|
2381
|
+
readonly $tooltips: string[];
|
|
2382
|
+
readonly $inactive: boolean;
|
|
2383
|
+
readonly $silentErrors: string[];
|
|
2384
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => any;
|
|
2385
|
+
$validate: () => Promise<$InternalRegleResult>;
|
|
2433
2386
|
}
|
|
2434
2387
|
/**
|
|
2435
2388
|
* @public
|
|
2436
2389
|
*/
|
|
2437
2390
|
interface RegleCommonStatus<TValue = any> {
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2391
|
+
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
2392
|
+
readonly $invalid: boolean;
|
|
2393
|
+
/**
|
|
2394
|
+
* This is not the opposite of `$invalid`. Correct is meant to display UI validation report.
|
|
2395
|
+
*
|
|
2396
|
+
* This will be `true` only if:
|
|
2397
|
+
* - The field have at least one active rule
|
|
2398
|
+
* - Is dirty and not empty
|
|
2399
|
+
* - Passes validation
|
|
2400
|
+
*/
|
|
2401
|
+
readonly $correct: boolean;
|
|
2402
|
+
/** Indicates whether a field has been validated or interacted with by the user at least once. It's typically used to determine if a message should be displayed to the user. You can change this flag manually using the $touch and $reset methods. The $dirty flag is considered true if the current model has been touched or if all its children are dirty.*/
|
|
2403
|
+
readonly $dirty: boolean;
|
|
2404
|
+
/** Similar to $dirty, with one exception. The $anyDirty flag is considered true if given model was touched or any of its children are $anyDirty which means at least one descendant is $dirty. */
|
|
2405
|
+
readonly $anyDirty: boolean;
|
|
2406
|
+
/** Indicates whether a field has been touched and if the value is different than the initial one.
|
|
2407
|
+
* On nested elements and collections, it's true only if all its children are also `$edited`.
|
|
2408
|
+
* Use `$anyEdited` to check for any edited children
|
|
2409
|
+
*/
|
|
2410
|
+
readonly $edited: boolean;
|
|
2411
|
+
/** Similar to $edited, with one exception. The $anyEdited flag is considered true if given model was edited or any of its children are $anyEdited which means at least one descendant is $edited. */
|
|
2412
|
+
readonly $anyEdited: boolean;
|
|
2413
|
+
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
2414
|
+
readonly $pending: boolean;
|
|
2415
|
+
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
2416
|
+
readonly $error: boolean;
|
|
2417
|
+
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
2418
|
+
readonly $ready: boolean;
|
|
2419
|
+
/** Return the current key name of the field. */
|
|
2420
|
+
readonly $name: string;
|
|
2421
|
+
/** Id used to track collections items */
|
|
2422
|
+
$id?: string;
|
|
2423
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2424
|
+
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
2425
|
+
/** $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. */
|
|
2426
|
+
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
2427
|
+
/** Marks the field and all nested properties as $dirty. */
|
|
2428
|
+
$touch(): void;
|
|
2429
|
+
/**
|
|
2430
|
+
* Reset the validation status to a pristine state while keeping the current form state.
|
|
2431
|
+
* Resets the `$dirty` state on all nested properties of a form.
|
|
2432
|
+
* Rerun rules if `$lazy` is false
|
|
2433
|
+
*/
|
|
2434
|
+
$reset(): void;
|
|
2435
|
+
$reset(options?: ResetOptions<TValue>): void;
|
|
2436
|
+
/** Clears the $externalErrors state back to an empty object. */
|
|
2437
|
+
$clearExternalErrors(): void;
|
|
2485
2438
|
}
|
|
2486
2439
|
interface $InternalRegleCommonStatus extends Omit<RegleCommonStatus, '$touch' | '$reset'> {
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2440
|
+
$touch(runCommit?: boolean, withConditions?: boolean): void;
|
|
2441
|
+
$unwatch(): void;
|
|
2442
|
+
$watch(): void;
|
|
2443
|
+
$reset(options?: ResetOptions<any>, fromParent?: boolean): void;
|
|
2491
2444
|
}
|
|
2492
2445
|
/**
|
|
2493
2446
|
* @public
|
|
2494
2447
|
*/
|
|
2495
2448
|
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2449
|
+
/** The name of the rule type. */
|
|
2450
|
+
readonly $type: string;
|
|
2451
|
+
/** Returns the computed error message or messages for the current rule. */
|
|
2452
|
+
readonly $message: string | string[];
|
|
2453
|
+
/** Stores the current rule tooltip or tooltips */
|
|
2454
|
+
readonly $tooltip: string | string[];
|
|
2455
|
+
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
2456
|
+
readonly $active: boolean;
|
|
2457
|
+
/** Indicates the state of validation for this validator. */
|
|
2458
|
+
readonly $valid: boolean;
|
|
2459
|
+
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
2460
|
+
readonly $pending: boolean;
|
|
2461
|
+
/** Returns the current path of the rule (used internally for tracking) */
|
|
2462
|
+
readonly $path: string;
|
|
2463
|
+
/** Contains the metadata returned by the validator function. */
|
|
2464
|
+
readonly $metadata: TMetadata extends boolean ? TMetadata : Omit<TMetadata, '$valid'>;
|
|
2465
|
+
/** Run the rule validator and compute its properties like $message and $active */
|
|
2466
|
+
$parse(): Promise<boolean>;
|
|
2467
|
+
/** Reset the $valid, $metadata and $pending states */
|
|
2468
|
+
$reset(): void;
|
|
2469
|
+
/** Returns the original rule validator function. */
|
|
2470
|
+
$validator: ((value: IsUnknown$1<TValue> extends true ? any : MaybeInput<TValue>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: IsUnknown$1<TValue> extends true ? any : TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
2518
2471
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
2519
|
-
|
|
2472
|
+
readonly $params?: any[];
|
|
2520
2473
|
} : {
|
|
2521
|
-
|
|
2474
|
+
readonly $params: [...TParams];
|
|
2522
2475
|
});
|
|
2523
2476
|
/**
|
|
2524
2477
|
* @internal
|
|
2525
2478
|
* @reference {@link RegleRuleStatus}
|
|
2526
2479
|
*/
|
|
2527
2480
|
interface $InternalRegleRuleStatus {
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2481
|
+
$type: string;
|
|
2482
|
+
$message: string | string[];
|
|
2483
|
+
$tooltip: string | string[];
|
|
2484
|
+
$active: boolean;
|
|
2485
|
+
$valid: boolean;
|
|
2486
|
+
$pending: boolean;
|
|
2487
|
+
$path: string;
|
|
2488
|
+
$externalErrors?: string[];
|
|
2489
|
+
$params?: any[];
|
|
2490
|
+
$metadata: any;
|
|
2491
|
+
$haveAsync: boolean;
|
|
2492
|
+
$validating: boolean;
|
|
2493
|
+
$fieldDirty: boolean;
|
|
2494
|
+
$fieldInvalid: boolean;
|
|
2495
|
+
$fieldPending: boolean;
|
|
2496
|
+
$fieldCorrect: boolean;
|
|
2497
|
+
$fieldError: boolean;
|
|
2498
|
+
$maybePending: boolean;
|
|
2499
|
+
$validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
|
|
2500
|
+
$parse(): Promise<boolean>;
|
|
2501
|
+
$reset(): void;
|
|
2502
|
+
$unwatch(): void;
|
|
2503
|
+
$watch(): void;
|
|
2551
2504
|
}
|
|
2552
2505
|
/**
|
|
2553
2506
|
* @public
|
|
2554
2507
|
*/
|
|
2555
2508
|
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'> & {
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
2575
|
-
[K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
|
|
2576
|
-
});
|
|
2509
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2510
|
+
$value: MaybeOutput<TState>;
|
|
2511
|
+
/** $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. */
|
|
2512
|
+
$silentValue: MaybeOutput<TState>;
|
|
2513
|
+
/** 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. */
|
|
2514
|
+
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
2515
|
+
/** 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. */
|
|
2516
|
+
readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
2517
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2518
|
+
*
|
|
2519
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2520
|
+
readonly $errors: RegleCollectionErrors<TState>;
|
|
2521
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2522
|
+
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
2523
|
+
/** 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). */
|
|
2524
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
2525
|
+
/** 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). */
|
|
2526
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, JoinDiscriminatedUnions<TRules>>>;
|
|
2527
|
+
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
2577
2528
|
/**
|
|
2578
2529
|
* @internal
|
|
2579
2530
|
* @reference {@link RegleCollectionStatus}
|
|
2580
2531
|
*/
|
|
2581
2532
|
interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields' | '$errors' | '$silentErrors'> {
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2533
|
+
readonly $self: $InternalRegleFieldStatus;
|
|
2534
|
+
readonly $each: Array<$InternalRegleStatusType>;
|
|
2535
|
+
readonly $errors: $InternalRegleCollectionErrors;
|
|
2536
|
+
readonly $silentErrors: $InternalRegleCollectionErrors;
|
|
2537
|
+
readonly $externalErrors?: string[];
|
|
2538
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => any[];
|
|
2539
|
+
$validate: () => Promise<$InternalRegleResult>;
|
|
2589
2540
|
}
|
|
2590
2541
|
|
|
2542
|
+
//#endregion
|
|
2543
|
+
//#region src/types/rules/compatibility.rules.d.ts
|
|
2591
2544
|
interface SuperCompatibleRegle {
|
|
2592
|
-
|
|
2545
|
+
r$: SuperCompatibleRegleRoot;
|
|
2593
2546
|
}
|
|
2594
2547
|
/** Supports both core Regle and schemas Regle for Zod/Valibot */
|
|
2595
2548
|
type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2549
|
+
$groups?: {
|
|
2550
|
+
[x: string]: RegleValidationGroupOutput;
|
|
2551
|
+
};
|
|
2552
|
+
$validate: () => Promise<SuperCompatibleRegleResult>;
|
|
2600
2553
|
};
|
|
2601
2554
|
type SuperCompatibleRegleResult = $InternalRegleResult;
|
|
2602
2555
|
interface SuperCompatibleRegleStatus extends SuperCompatibleRegleCommonStatus {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2556
|
+
$fields: {
|
|
2557
|
+
[x: string]: unknown;
|
|
2558
|
+
};
|
|
2559
|
+
readonly $errors: Record<string, RegleValidationErrors<any, false>>;
|
|
2560
|
+
readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
|
|
2561
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
|
|
2562
|
+
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2610
2563
|
}
|
|
2611
2564
|
type SuperCompatibleRegleRuleStatus = Omit<$InternalRegleRuleStatus, '$haveAsync' | '$validating' | '$fieldDirty' | '$fieldInvalid' | '$fieldPending' | '$fieldCorrect' | '$fieldError' | '$unwatch' | '$watch' | '$maybePending'>;
|
|
2612
2565
|
type SuperCompatibleRegleCommonStatus = Omit<RegleCommonStatus, '$pending'> & {
|
|
2613
|
-
|
|
2566
|
+
$pending?: boolean;
|
|
2614
2567
|
};
|
|
2615
2568
|
interface SuperCompatibleRegleFieldStatus extends SuperCompatibleRegleCommonStatus {
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2569
|
+
$value: any;
|
|
2570
|
+
$silentValue: any;
|
|
2571
|
+
readonly $rules: Record<string, SuperCompatibleRegleRuleStatus>;
|
|
2572
|
+
readonly $externalErrors?: string[];
|
|
2573
|
+
readonly $errors: string[];
|
|
2574
|
+
readonly $inactive: boolean;
|
|
2575
|
+
readonly $silentErrors: string[];
|
|
2576
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => any;
|
|
2577
|
+
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2625
2578
|
}
|
|
2626
2579
|
interface SuperCompatibleRegleCollectionStatus extends Omit<SuperCompatibleRegleStatus, '$fields' | '$errors' | '$silentErrors'> {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2580
|
+
readonly $self: SuperCompatibleRegleFieldStatus;
|
|
2581
|
+
readonly $each: Array<SuperCompatibleRegleStatus | SuperCompatibleRegleFieldStatus>;
|
|
2582
|
+
readonly $errors: SuperCompatibleRegleCollectionErrors;
|
|
2583
|
+
readonly $silentErrors: SuperCompatibleRegleCollectionErrors;
|
|
2584
|
+
readonly $externalErrors?: string[];
|
|
2585
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => any[];
|
|
2586
|
+
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2634
2587
|
}
|
|
2635
2588
|
type SuperCompatibleRegleCollectionErrors = $InternalRegleCollectionErrors;
|
|
2636
2589
|
|
|
2590
|
+
//#endregion
|
|
2591
|
+
//#region src/core/createRule/createRule.d.ts
|
|
2637
2592
|
/**
|
|
2638
2593
|
* Create a typed custom rule that can be used like default rules.
|
|
2639
2594
|
* It can also be declared in the global options
|
|
@@ -2665,14 +2620,23 @@ type SuperCompatibleRegleCollectionErrors = $InternalRegleCollectionErrors;
|
|
|
2665
2620
|
*
|
|
2666
2621
|
* Docs: {@link https://reglejs.dev/core-concepts/rules/reusable-rules}
|
|
2667
2622
|
*/
|
|
2668
|
-
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>;
|
|
2623
|
+
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>;
|
|
2669
2624
|
|
|
2625
|
+
//#endregion
|
|
2626
|
+
//#region src/core/createRule/unwrapRuleParameters.d.ts
|
|
2670
2627
|
/**
|
|
2671
2628
|
* Returns a clean list of parameters
|
|
2672
2629
|
* Removing Ref and executing function to return the unwrapped value
|
|
2673
2630
|
*/
|
|
2674
2631
|
declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
|
|
2675
2632
|
|
|
2633
|
+
//#endregion
|
|
2634
|
+
//#region src/core/defineRegleConfig.d.ts
|
|
2635
|
+
/**
|
|
2636
|
+
* Returns a clean list of parameters
|
|
2637
|
+
* Removing Ref and executing function to return the unwrapped value
|
|
2638
|
+
*/
|
|
2639
|
+
|
|
2676
2640
|
/**
|
|
2677
2641
|
* Define a global regle configuration, where you can:
|
|
2678
2642
|
* - Customize built-in rules messages
|
|
@@ -2685,13 +2649,17 @@ declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrG
|
|
|
2685
2649
|
* - a `useRegle` composable that can typecheck your custom rules
|
|
2686
2650
|
* - an `inferRules` helper that can typecheck your custom rules
|
|
2687
2651
|
*/
|
|
2688
|
-
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations>>({
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2652
|
+
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations>>({
|
|
2653
|
+
rules,
|
|
2654
|
+
modifiers,
|
|
2655
|
+
shortcuts
|
|
2656
|
+
}: {
|
|
2657
|
+
rules?: () => TCustomRules;
|
|
2658
|
+
modifiers?: RegleBehaviourOptions;
|
|
2659
|
+
shortcuts?: TShortcuts;
|
|
2692
2660
|
}): {
|
|
2693
|
-
|
|
2694
|
-
|
|
2661
|
+
useRegle: useRegleFn<TCustomRules, TShortcuts>;
|
|
2662
|
+
inferRules: inferRulesFn<TCustomRules>;
|
|
2695
2663
|
};
|
|
2696
2664
|
/**
|
|
2697
2665
|
* Extend an already created custom `useRegle` (as the first parameter)
|
|
@@ -2701,121 +2669,119 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
|
|
|
2701
2669
|
* - a `useRegle` composable that can typecheck your custom rules
|
|
2702
2670
|
* - an `inferRules` helper that can typecheck your custom rules
|
|
2703
2671
|
*/
|
|
2704
|
-
declare function extendRegleConfig<TRootCustomRules extends Partial<AllRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<AllRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2672
|
+
declare function extendRegleConfig<TRootCustomRules extends Partial<AllRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<AllRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
|
|
2673
|
+
rules,
|
|
2674
|
+
modifiers,
|
|
2675
|
+
shortcuts
|
|
2676
|
+
}: {
|
|
2677
|
+
rules?: () => TCustomRules;
|
|
2678
|
+
modifiers?: RegleBehaviourOptions;
|
|
2679
|
+
shortcuts?: TShortcuts;
|
|
2708
2680
|
}): {
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
};
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
}> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch'> & {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
[K in keyof TRegles]: TRegles[K]['$silentErrors'];
|
|
2733
|
-
};
|
|
2734
|
-
/** 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). */
|
|
2735
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TValue>;
|
|
2736
|
-
/** 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). */
|
|
2737
|
-
$validate: () => Promise<MergedReglesResult<TRegles>>;
|
|
2681
|
+
useRegle: useRegleFn<Merge<TRootCustomRules, TCustomRules>, TRootShortcuts & TShortcuts>;
|
|
2682
|
+
inferRules: inferRulesFn<Merge<TRootCustomRules, TCustomRules>>;
|
|
2683
|
+
};
|
|
2684
|
+
|
|
2685
|
+
//#endregion
|
|
2686
|
+
//#region src/core/mergeRegles.d.ts
|
|
2687
|
+
type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue = { [K in keyof TRegles]: TRegles[K]['$value'] }> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch'> & {
|
|
2688
|
+
/** Map of merged Regle instances and their properties */
|
|
2689
|
+
readonly $instances: { [K in keyof TRegles]: TRegles[K] };
|
|
2690
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2691
|
+
$value: TValue;
|
|
2692
|
+
/** $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. */
|
|
2693
|
+
$silentValue: TValue;
|
|
2694
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2695
|
+
*
|
|
2696
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2697
|
+
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2698
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
2699
|
+
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
2700
|
+
/** 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). */
|
|
2701
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TValue>;
|
|
2702
|
+
/** 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). */
|
|
2703
|
+
$validate: () => Promise<MergedReglesResult<TRegles>>;
|
|
2738
2704
|
};
|
|
2739
2705
|
type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2706
|
+
/** Array of scoped Regles instances */
|
|
2707
|
+
readonly $instances: SuperCompatibleRegleRoot[];
|
|
2708
|
+
/** Collection of all registered Regles instances values */
|
|
2709
|
+
readonly $value: TValue;
|
|
2710
|
+
/** Collection of all registered Regles instances errors */
|
|
2711
|
+
readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2712
|
+
/** Collection of all registered Regles instances silent errors */
|
|
2713
|
+
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2714
|
+
/** 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). */
|
|
2715
|
+
$validate: () => Promise<{
|
|
2716
|
+
valid: boolean;
|
|
2717
|
+
data: TValue;
|
|
2718
|
+
}>;
|
|
2753
2719
|
};
|
|
2754
2720
|
type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
|
|
2721
|
+
valid: false;
|
|
2722
|
+
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2755
2723
|
valid: false;
|
|
2756
|
-
|
|
2757
|
-
[K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2758
|
-
valid: false;
|
|
2759
|
-
}>['data'];
|
|
2760
|
-
};
|
|
2724
|
+
}>['data'] };
|
|
2761
2725
|
} | {
|
|
2726
|
+
valid: true;
|
|
2727
|
+
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2762
2728
|
valid: true;
|
|
2763
|
-
|
|
2764
|
-
[K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2765
|
-
valid: true;
|
|
2766
|
-
}>['data'];
|
|
2767
|
-
};
|
|
2729
|
+
}>['data'] };
|
|
2768
2730
|
};
|
|
2769
2731
|
declare function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TScoped extends boolean = false>(regles: TRegles, _scoped?: TScoped): TScoped extends false ? MergedRegles<TRegles> : MergedScopedRegles;
|
|
2770
2732
|
|
|
2733
|
+
//#endregion
|
|
2734
|
+
//#region src/core/createScopedUseRegle/useCollectScope.d.ts
|
|
2771
2735
|
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2772
|
-
|
|
2773
|
-
[K in keyof TValue]: RegleRoot<TValue[K]>;
|
|
2774
|
-
}>;
|
|
2736
|
+
r$: MergedRegles<{ [K in keyof TValue]: RegleRoot<TValue[K]> }>;
|
|
2775
2737
|
} : <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2776
|
-
|
|
2738
|
+
r$: MergedScopedRegles<TValue>;
|
|
2777
2739
|
};
|
|
2778
2740
|
|
|
2741
|
+
//#endregion
|
|
2742
|
+
//#region src/core/createScopedUseRegle/useScopedRegle.d.ts
|
|
2779
2743
|
type UseScopedRegleOptions<TAsRecord extends boolean> = {
|
|
2780
|
-
|
|
2744
|
+
namespace?: MaybeRefOrGetter<string>;
|
|
2781
2745
|
} & (TAsRecord extends true ? {
|
|
2782
|
-
|
|
2746
|
+
scopeKey: string;
|
|
2783
2747
|
} : {});
|
|
2784
2748
|
|
|
2749
|
+
//#endregion
|
|
2750
|
+
//#region src/core/createScopedUseRegle/createScopedUseRegle.d.ts
|
|
2785
2751
|
type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsRecord extends boolean> = {
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
};
|
|
2799
|
-
declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<AllRulesDeclarations>>, TAsRecord extends boolean = false, TReturnedRegle extends useRegleFn<any, any, any, any> = TCustomRegle extends useRegleFn<infer A, infer B> ? useRegleFn<A, B, {
|
|
2800
|
-
|
|
2801
|
-
|
|
2752
|
+
/**
|
|
2753
|
+
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
2754
|
+
*/
|
|
2755
|
+
customUseRegle?: TCustomRegle;
|
|
2756
|
+
/**
|
|
2757
|
+
* Store the collected instances externally
|
|
2758
|
+
*/
|
|
2759
|
+
customStore?: Ref<ScopedInstancesRecordLike>;
|
|
2760
|
+
/**
|
|
2761
|
+
* Set the
|
|
2762
|
+
*/
|
|
2763
|
+
asRecord?: TAsRecord;
|
|
2764
|
+
};
|
|
2765
|
+
declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<AllRulesDeclarations>>, TAsRecord extends boolean = false, TReturnedRegle extends useRegleFn<any, any, any, any> = (TCustomRegle extends useRegleFn<infer A, infer B> ? useRegleFn<A, B, {
|
|
2766
|
+
dispose: () => void;
|
|
2767
|
+
register: () => void;
|
|
2802
2768
|
}, UseScopedRegleOptions<TAsRecord>> : useRegleFn<Partial<AllRulesDeclarations>, any, {
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
}, UseScopedRegleOptions<TAsRecord
|
|
2806
|
-
|
|
2807
|
-
|
|
2769
|
+
dispose: () => void;
|
|
2770
|
+
register: () => void;
|
|
2771
|
+
}, UseScopedRegleOptions<TAsRecord>>)>(options?: CreateScopedUseRegleOptions<TCustomRegle, TAsRecord>): {
|
|
2772
|
+
useScopedRegle: TReturnedRegle;
|
|
2773
|
+
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
2808
2774
|
};
|
|
2809
|
-
declare const useCollectScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?:
|
|
2775
|
+
declare const useCollectScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string>) => {
|
|
2810
2776
|
r$: MergedScopedRegles<TValue>;
|
|
2811
|
-
}
|
|
2812
|
-
declare const useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
|
|
2777
|
+
}, useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
|
|
2813
2778
|
dispose: () => void;
|
|
2814
2779
|
register: () => void;
|
|
2815
|
-
}, {
|
|
2816
|
-
namespace?:
|
|
2817
|
-
}>;
|
|
2818
|
-
|
|
2780
|
+
}, {
|
|
2781
|
+
namespace?: vue0.MaybeRefOrGetter<string>;
|
|
2782
|
+
}>;
|
|
2783
|
+
//#endregion
|
|
2784
|
+
//#region src/core/createVariant.d.ts
|
|
2819
2785
|
/**
|
|
2820
2786
|
* Declare variations of state that depends on one value
|
|
2821
2787
|
*
|
|
@@ -2847,12 +2813,10 @@ declare function createVariant<TForm extends Record<string, any>, TDiscriminant
|
|
|
2847
2813
|
* ```
|
|
2848
2814
|
*/
|
|
2849
2815
|
declare function narrowVariant<TRoot extends {
|
|
2850
|
-
|
|
2851
|
-
}, const TKey extends keyof TRoot, const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2852
|
-
|
|
2853
|
-
} ? V : unknown>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, {
|
|
2854
|
-
[K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any>;
|
|
2855
|
-
}>;
|
|
2816
|
+
[x: string]: unknown;
|
|
2817
|
+
}, const TKey extends keyof TRoot, const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2818
|
+
$value: infer V;
|
|
2819
|
+
} ? V : unknown)>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }>;
|
|
2856
2820
|
/**
|
|
2857
2821
|
* Narrow a nested variant root to a reactive reference
|
|
2858
2822
|
*
|
|
@@ -2862,12 +2826,12 @@ declare function narrowVariant<TRoot extends {
|
|
|
2862
2826
|
* </script>
|
|
2863
2827
|
* ```
|
|
2864
2828
|
*/
|
|
2865
|
-
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey extends keyof TRoot['$fields'], const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2866
|
-
|
|
2867
|
-
} ? V : unknown>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue): Ref<Extract<TRoot['$fields'], {
|
|
2868
|
-
[K in TKey]: RegleFieldStatus<TValue, any, any>;
|
|
2869
|
-
}> | undefined>;
|
|
2829
|
+
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey extends keyof TRoot['$fields'], const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2830
|
+
$value: infer V;
|
|
2831
|
+
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue): Ref<Extract<TRoot['$fields'], { [K in TKey]: RegleFieldStatus<TValue, any, any> }> | undefined>;
|
|
2870
2832
|
|
|
2833
|
+
//#endregion
|
|
2834
|
+
//#region src/core/refineRules.d.ts
|
|
2871
2835
|
/**
|
|
2872
2836
|
* Helper method to wrap an raw rules object
|
|
2873
2837
|
*
|
|
@@ -2895,4 +2859,5 @@ declare function defineRules<TRules extends RegleUnknownRulesTree>(rules: TRules
|
|
|
2895
2859
|
*/
|
|
2896
2860
|
declare function refineRules<TRules extends RegleUnknownRulesTree, TRefinement extends ReglePartialRuleTree<InferInput<TRules>> & RegleUnknownRulesTree>(rules: TRules, refinement: (state: Ref<InferInput<TRules>>) => TRefinement): (state: Ref<InferInput<TRules>>) => Merge<TRules, TRefinement>;
|
|
2897
2861
|
|
|
2898
|
-
|
|
2862
|
+
//#endregion
|
|
2863
|
+
export { $InternalRegleStatus, AllRulesDeclarations, CommonAlphaOptions, CommonComparisonOptions, CreateScopedUseRegleOptions, DeepMaybeRef, DeepReactiveState, DefaultValidatorsTree, FormRuleDeclaration, HaveAnyRequiredProps, InferInput, InferRegleRoot, InferRegleRule, InferRegleRules, InferRegleShortcuts, InferRegleStatusType, InferSafeOutput, InlineRuleDeclaration, InternalRuleType, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeInput, MaybeOutput, MaybeReadonly, MaybeVariantStatus, MergedRegles, MergedScopedRegles, NarrowVariant, NoInferLegacy, PrimitiveTypes, Regle, RegleBehaviourOptions, RegleCollectionErrors, RegleCollectionRuleDecl, RegleCollectionRuleDefinition, RegleCollectionStatus, RegleCommonStatus, RegleComputedRules, RegleCustomCollectionStatus, RegleCustomFieldStatus, RegleCustomStatus, RegleEnforceCustomRequiredRules, RegleEnforceRequiredRules, RegleErrorTree, RegleExternalCollectionErrors, RegleExternalErrorTree, RegleFieldStatus, RegleFormPropertyType, RegleInternalRuleDefs, ReglePartialRuleTree, RegleResult, RegleRoot, RegleRuleCore, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionProcessor, RegleRuleDefinitionWithMetadataProcessor, RegleRuleInit, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleMetadataExtended, RegleRuleRaw, RegleRuleStatus, RegleRuleTypeReturn, RegleRuleWithParamsDefinition, RegleShortcutDefinition, RegleSingleField, RegleStatus, RegleUniversalParams, RegleUnknownRulesTree, RegleValidationErrors, RegleValidationGroupEntry, RegleValidationGroupOutput, RegleRuleTree as RegleValidationTree, ResolvedRegleBehaviourOptions, ScopedInstancesRecord, ScopedInstancesRecordLike, SuperCompatibleRegle, SuperCompatibleRegleCollectionErrors, SuperCompatibleRegleCollectionStatus, SuperCompatibleRegleFieldStatus, SuperCompatibleRegleResult, SuperCompatibleRegleRoot, SuperCompatibleRegleRuleStatus, SuperCompatibleRegleStatus, Unwrap, UnwrapRegleUniversalParams, UnwrapRuleWithParams, UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, inferRulesFn, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, useCollectScopeFn, useRegle, useRegleFn, useRootStorage, useScopedRegle, variantToRef };
|