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