@regle/schemas 1.10.1 → 1.11.0-beta.2
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/dist/regle-schemas.d.ts +37 -3060
- package/dist/regle-schemas.js +0 -20
- package/package.json +7 -12
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,3036 +1,26 @@
|
|
|
1
|
+
import * as _regle_core0 from "@regle/core";
|
|
2
|
+
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepReactiveState, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
1
3
|
import * as vue0 from "vue";
|
|
2
|
-
import { MaybeRef,
|
|
4
|
+
import { MaybeRef, Raw, UnwrapNestedRefs } from "vue";
|
|
3
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//#region src/types/utils/misc.types.d.ts
|
|
7
|
-
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
8
|
-
type Maybe<T = any> = T | null | undefined;
|
|
9
|
-
type MaybeInput<T = any> = T | null | undefined;
|
|
10
|
-
type MaybeOutput<T = any> = T | undefined;
|
|
11
|
-
type NonUndefined<T> = Exclude<T, undefined>;
|
|
12
|
-
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
13
|
-
type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
|
|
14
|
-
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
15
|
-
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
16
|
-
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
17
|
-
type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
|
|
18
|
-
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
19
|
-
type ExcludeByType<T, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] extends U$1 ? never : T[K] };
|
|
20
|
-
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
21
|
-
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
22
|
-
type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/types/utils/Array.types.d.ts
|
|
25
|
-
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/primitive.d.ts
|
|
28
|
-
/**
|
|
29
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
30
|
-
|
|
31
|
-
@category Type
|
|
32
|
-
*/
|
|
33
|
-
type Primitive$1 = null | undefined | string | number | boolean | symbol | bigint;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
36
|
-
/**
|
|
37
|
-
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).
|
|
38
|
-
|
|
39
|
-
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
40
|
-
|
|
41
|
-
@example
|
|
42
|
-
```
|
|
43
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
44
|
-
|
|
45
|
-
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
46
|
-
|
|
47
|
-
type Intersection = UnionToIntersection<Union>;
|
|
48
|
-
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
A more applicable example which could make its way into your library code follows.
|
|
52
|
-
|
|
53
|
-
@example
|
|
54
|
-
```
|
|
55
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
56
|
-
|
|
57
|
-
class CommandOne {
|
|
58
|
-
commands: {
|
|
59
|
-
a1: () => undefined,
|
|
60
|
-
b1: () => undefined,
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class CommandTwo {
|
|
65
|
-
commands: {
|
|
66
|
-
a2: (argA: string) => undefined,
|
|
67
|
-
b2: (argB: string) => undefined,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
72
|
-
type Union = typeof union;
|
|
73
|
-
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
74
|
-
|
|
75
|
-
type Intersection = UnionToIntersection<Union>;
|
|
76
|
-
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
@category Type
|
|
80
|
-
*/
|
|
81
|
-
type UnionToIntersection<Union> = (
|
|
82
|
-
// `extends unknown` is always going to be the case and is used to convert the
|
|
83
|
-
// `Union` into a [distributive conditional
|
|
84
|
-
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
85
|
-
Union extends unknown
|
|
86
|
-
// The union type is used as the only argument to a function since the union
|
|
87
|
-
// of function arguments is an intersection.
|
|
88
|
-
? (distributedUnion: Union) => void
|
|
89
|
-
// This won't happen.
|
|
90
|
-
: never
|
|
91
|
-
// Infer the `Intersection` type since TypeScript represents the positional
|
|
92
|
-
// arguments of unions of functions as an intersection of the union.
|
|
93
|
-
) extends ((mergedIntersection: infer Intersection) => void)
|
|
94
|
-
// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
95
|
-
? Intersection & Union : never;
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/empty-object.d.ts
|
|
98
|
-
declare const emptyObjectSymbol$1: unique symbol;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
102
|
-
|
|
103
|
-
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
104
|
-
|
|
105
|
-
@example
|
|
106
|
-
```
|
|
107
|
-
import type {EmptyObject} from 'type-fest';
|
|
108
|
-
|
|
109
|
-
// The following illustrates the problem with `{}`.
|
|
110
|
-
const foo1: {} = {}; // Pass
|
|
111
|
-
const foo2: {} = []; // Pass
|
|
112
|
-
const foo3: {} = 42; // Pass
|
|
113
|
-
const foo4: {} = {a: 1}; // Pass
|
|
114
|
-
|
|
115
|
-
// With `EmptyObject` only the first case is valid.
|
|
116
|
-
const bar1: EmptyObject = {}; // Pass
|
|
117
|
-
const bar2: EmptyObject = 42; // Fail
|
|
118
|
-
const bar3: EmptyObject = []; // Fail
|
|
119
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
123
|
-
|
|
124
|
-
@category Object
|
|
125
|
-
*/
|
|
126
|
-
type EmptyObject$1 = {
|
|
127
|
-
[emptyObjectSymbol$1]?: never;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
131
|
-
|
|
132
|
-
@example
|
|
133
|
-
```
|
|
134
|
-
import type {IsEmptyObject} from 'type-fest';
|
|
135
|
-
|
|
136
|
-
type Pass = IsEmptyObject<{}>; //=> true
|
|
137
|
-
type Fail = IsEmptyObject<[]>; //=> false
|
|
138
|
-
type Fail = IsEmptyObject<null>; //=> false
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
@see {@link EmptyObject}
|
|
142
|
-
@category Object
|
|
143
|
-
*/
|
|
144
|
-
type IsEmptyObject<T> = T extends EmptyObject$1 ? true : false;
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-any.d.ts
|
|
147
|
-
/**
|
|
148
|
-
Returns a boolean for whether the given type is `any`.
|
|
149
|
-
|
|
150
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
151
|
-
|
|
152
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
153
|
-
|
|
154
|
-
@example
|
|
155
|
-
```
|
|
156
|
-
import type {IsAny} from 'type-fest';
|
|
157
|
-
|
|
158
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
159
|
-
const anyObject: any = {a: 1, b: 2};
|
|
160
|
-
|
|
161
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
162
|
-
return obj[key];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const typedA = get(typedObject, 'a');
|
|
166
|
-
//=> 1
|
|
167
|
-
|
|
168
|
-
const anyA = get(anyObject, 'a');
|
|
169
|
-
//=> any
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
@category Type Guard
|
|
173
|
-
@category Utilities
|
|
174
|
-
*/
|
|
175
|
-
type IsAny$1<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
178
|
-
/**
|
|
179
|
-
Returns a boolean for whether the given key is an optional key of type.
|
|
180
|
-
|
|
181
|
-
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
182
|
-
|
|
183
|
-
@example
|
|
184
|
-
```
|
|
185
|
-
import type {IsOptionalKeyOf} from 'type-fest';
|
|
186
|
-
|
|
187
|
-
interface User {
|
|
188
|
-
name: string;
|
|
189
|
-
surname: string;
|
|
190
|
-
|
|
191
|
-
luckyNumber?: number;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
interface Admin {
|
|
195
|
-
name: string;
|
|
196
|
-
surname?: string;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
200
|
-
//=> true
|
|
201
|
-
|
|
202
|
-
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
203
|
-
//=> false
|
|
204
|
-
|
|
205
|
-
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
206
|
-
//=> boolean
|
|
207
|
-
|
|
208
|
-
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
209
|
-
//=> false
|
|
210
|
-
|
|
211
|
-
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
212
|
-
//=> boolean
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
@category Type Guard
|
|
216
|
-
@category Utilities
|
|
217
|
-
*/
|
|
218
|
-
type IsOptionalKeyOf$1<Type extends object, Key$1 extends keyof Type> = IsAny$1<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
219
|
-
//#endregion
|
|
220
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
221
|
-
/**
|
|
222
|
-
Extract all optional keys from the given type.
|
|
223
|
-
|
|
224
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
225
|
-
|
|
226
|
-
@example
|
|
227
|
-
```
|
|
228
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
229
|
-
|
|
230
|
-
interface User {
|
|
231
|
-
name: string;
|
|
232
|
-
surname: string;
|
|
233
|
-
|
|
234
|
-
luckyNumber?: number;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
238
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
239
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const update1: UpdateOperation<User> = {
|
|
243
|
-
name: 'Alice'
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const update2: UpdateOperation<User> = {
|
|
247
|
-
name: 'Bob',
|
|
248
|
-
luckyNumber: REMOVE_FIELD
|
|
249
|
-
};
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
@category Utilities
|
|
253
|
-
*/
|
|
254
|
-
type OptionalKeysOf$1<Type extends object> = Type extends unknown // For distributing `Type`
|
|
255
|
-
? (keyof { [Key in keyof Type as IsOptionalKeyOf$1<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
256
|
-
: never;
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
259
|
-
/**
|
|
260
|
-
Extract all required keys from the given type.
|
|
261
|
-
|
|
262
|
-
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
263
|
-
|
|
264
|
-
@example
|
|
265
|
-
```
|
|
266
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
267
|
-
|
|
268
|
-
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
269
|
-
|
|
270
|
-
interface User {
|
|
271
|
-
name: string;
|
|
272
|
-
surname: string;
|
|
273
|
-
|
|
274
|
-
luckyNumber?: number;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
278
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
@category Utilities
|
|
282
|
-
*/
|
|
283
|
-
type RequiredKeysOf$1<Type extends object> = Type extends unknown // For distributing `Type`
|
|
284
|
-
? Exclude<keyof Type, OptionalKeysOf$1<Type>> : never;
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-never.d.ts
|
|
287
|
-
/**
|
|
288
|
-
Returns a boolean for whether the given type is `never`.
|
|
289
|
-
|
|
290
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
291
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
292
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
293
|
-
|
|
294
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
295
|
-
|
|
296
|
-
@example
|
|
297
|
-
```
|
|
298
|
-
import type {IsNever, And} from 'type-fest';
|
|
299
|
-
|
|
300
|
-
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
301
|
-
type AreStringsEqual<A extends string, B extends string> =
|
|
302
|
-
And<
|
|
303
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
304
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
305
|
-
>;
|
|
306
|
-
|
|
307
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
308
|
-
AreStringsEqual<I, O> extends true
|
|
309
|
-
? never
|
|
310
|
-
: void;
|
|
311
|
-
|
|
312
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
313
|
-
if (input === output) {
|
|
314
|
-
process.exit(0);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
endIfEqual('abc', 'abc');
|
|
319
|
-
//=> never
|
|
320
|
-
|
|
321
|
-
endIfEqual('abc', '123');
|
|
322
|
-
//=> void
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
@category Type Guard
|
|
326
|
-
@category Utilities
|
|
327
|
-
*/
|
|
328
|
-
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
329
|
-
//#endregion
|
|
330
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/if.d.ts
|
|
331
|
-
/**
|
|
332
|
-
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
333
|
-
|
|
334
|
-
Use-cases:
|
|
335
|
-
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
336
|
-
|
|
337
|
-
Note:
|
|
338
|
-
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
339
|
-
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
340
|
-
|
|
341
|
-
@example
|
|
342
|
-
```
|
|
343
|
-
import {If} from 'type-fest';
|
|
344
|
-
|
|
345
|
-
type A = If<true, 'yes', 'no'>;
|
|
346
|
-
//=> 'yes'
|
|
347
|
-
|
|
348
|
-
type B = If<false, 'yes', 'no'>;
|
|
349
|
-
//=> 'no'
|
|
350
|
-
|
|
351
|
-
type C = If<boolean, 'yes', 'no'>;
|
|
352
|
-
//=> 'yes' | 'no'
|
|
353
|
-
|
|
354
|
-
type D = If<any, 'yes', 'no'>;
|
|
355
|
-
//=> 'yes' | 'no'
|
|
356
|
-
|
|
357
|
-
type E = If<never, 'yes', 'no'>;
|
|
358
|
-
//=> 'no'
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
@example
|
|
362
|
-
```
|
|
363
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
364
|
-
|
|
365
|
-
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
366
|
-
//=> 'not any'
|
|
367
|
-
|
|
368
|
-
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
369
|
-
//=> 'is never'
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
@example
|
|
373
|
-
```
|
|
374
|
-
import {If, IsEqual} from 'type-fest';
|
|
375
|
-
|
|
376
|
-
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
377
|
-
|
|
378
|
-
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
379
|
-
//=> 'equal'
|
|
380
|
-
|
|
381
|
-
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
382
|
-
//=> 'not equal'
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
386
|
-
|
|
387
|
-
@example
|
|
388
|
-
```
|
|
389
|
-
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
390
|
-
|
|
391
|
-
type HundredZeroes = StringRepeat<'0', 100>;
|
|
392
|
-
|
|
393
|
-
// The following implementation is not tail recursive
|
|
394
|
-
type Includes<S extends string, Char extends string> =
|
|
395
|
-
S extends `${infer First}${infer Rest}`
|
|
396
|
-
? If<IsEqual<First, Char>,
|
|
397
|
-
'found',
|
|
398
|
-
Includes<Rest, Char>>
|
|
399
|
-
: 'not found';
|
|
400
|
-
|
|
401
|
-
// Hence, instantiations with long strings will fail
|
|
402
|
-
// @ts-expect-error
|
|
403
|
-
type Fails = Includes<HundredZeroes, '1'>;
|
|
404
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
405
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
406
|
-
|
|
407
|
-
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
408
|
-
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
409
|
-
S extends `${infer First}${infer Rest}`
|
|
410
|
-
? IsEqual<First, Char> extends true
|
|
411
|
-
? 'found'
|
|
412
|
-
: IncludesWithoutIf<Rest, Char>
|
|
413
|
-
: 'not found';
|
|
414
|
-
|
|
415
|
-
// Now, instantiations with long strings will work
|
|
416
|
-
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
417
|
-
//=> 'not found'
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
@category Type Guard
|
|
421
|
-
@category Utilities
|
|
422
|
-
*/
|
|
423
|
-
type If$1<Type extends boolean, IfBranch, ElseBranch> = IsNever$1<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
424
|
-
//#endregion
|
|
425
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/type.d.ts
|
|
426
|
-
/**
|
|
427
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
428
|
-
*/
|
|
429
|
-
type BuiltIns$1 = Primitive$1 | void | Date | RegExp;
|
|
430
|
-
/**
|
|
431
|
-
Test if the given function has multiple call signatures.
|
|
432
|
-
|
|
433
|
-
Needed to handle the case of a single call signature with properties.
|
|
434
|
-
|
|
435
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
436
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
437
|
-
*/
|
|
438
|
-
type HasMultipleCallSignatures$1<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
439
|
-
(...arguments_: infer A): unknown;
|
|
440
|
-
(...arguments_: infer B): unknown;
|
|
441
|
-
} ? B extends A ? A extends B ? false : true : true : false;
|
|
442
|
-
/**
|
|
443
|
-
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
444
|
-
|
|
445
|
-
@example
|
|
446
|
-
```
|
|
447
|
-
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
448
|
-
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
449
|
-
//=> 'VALID'
|
|
450
|
-
|
|
451
|
-
// When `T` is `any` => Returns `IfAny` branch
|
|
452
|
-
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
453
|
-
//=> 'IS_ANY'
|
|
454
|
-
|
|
455
|
-
// When `T` is `never` => Returns `IfNever` branch
|
|
456
|
-
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
457
|
-
//=> 'IS_NEVER'
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
|
|
461
|
-
|
|
462
|
-
@example
|
|
463
|
-
```ts
|
|
464
|
-
import type {StringRepeat} from 'type-fest';
|
|
465
|
-
|
|
466
|
-
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
467
|
-
|
|
468
|
-
// The following implementation is not tail recursive
|
|
469
|
-
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
470
|
-
|
|
471
|
-
// Hence, instantiations with long strings will fail
|
|
472
|
-
// @ts-expect-error
|
|
473
|
-
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
474
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
475
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
476
|
-
|
|
477
|
-
// To fix this, move the recursion into a helper type
|
|
478
|
-
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
479
|
-
|
|
480
|
-
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
481
|
-
|
|
482
|
-
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
483
|
-
//=> ''
|
|
484
|
-
```
|
|
485
|
-
*/
|
|
486
|
-
type IfNotAnyOrNever<T, IfNotAnyOrNever$1, IfAny = any, IfNever = never> = If$1<IsAny$1<T>, IfAny, If$1<IsNever$1<T>, IfNever, IfNotAnyOrNever$1>>;
|
|
487
|
-
//#endregion
|
|
488
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-null.d.ts
|
|
489
|
-
/**
|
|
490
|
-
Returns a boolean for whether the given type is `null`.
|
|
491
|
-
|
|
492
|
-
@example
|
|
493
|
-
```
|
|
494
|
-
import type {IsNull} from 'type-fest';
|
|
495
|
-
|
|
496
|
-
type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
|
|
497
|
-
|
|
498
|
-
type Example1 = NonNullFallback<null, string>;
|
|
499
|
-
//=> string
|
|
500
|
-
|
|
501
|
-
type Example2 = NonNullFallback<number, string>;
|
|
502
|
-
//=? number
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
@category Type Guard
|
|
506
|
-
@category Utilities
|
|
507
|
-
*/
|
|
508
|
-
type IsNull<T> = [T] extends [null] ? true : false;
|
|
509
|
-
//#endregion
|
|
510
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-unknown.d.ts
|
|
511
|
-
/**
|
|
512
|
-
Returns a boolean for whether the given type is `unknown`.
|
|
513
|
-
|
|
514
|
-
@link https://github.com/dsherret/conditional-type-checks/pull/16
|
|
515
|
-
|
|
516
|
-
Useful in type utilities, such as when dealing with unknown data from API calls.
|
|
517
|
-
|
|
518
|
-
@example
|
|
519
|
-
```
|
|
520
|
-
import type {IsUnknown} from 'type-fest';
|
|
521
|
-
|
|
522
|
-
// https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
|
|
523
|
-
type Action<TState, TPayload = void> =
|
|
524
|
-
IsUnknown<TPayload> extends true
|
|
525
|
-
? (state: TState) => TState,
|
|
526
|
-
: (state: TState, payload: TPayload) => TState;
|
|
527
|
-
|
|
528
|
-
class Store<TState> {
|
|
529
|
-
constructor(private state: TState) {}
|
|
530
|
-
|
|
531
|
-
execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
|
|
532
|
-
this.state = action(this.state, payload);
|
|
533
|
-
return this.state;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// ... other methods
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const store = new Store({value: 1});
|
|
540
|
-
declare const someExternalData: unknown;
|
|
541
|
-
|
|
542
|
-
store.execute(state => ({value: state.value + 1}));
|
|
543
|
-
//=> `TPayload` is `void`
|
|
544
|
-
|
|
545
|
-
store.execute((state, payload) => ({value: state.value + payload}), 5);
|
|
546
|
-
//=> `TPayload` is `5`
|
|
547
|
-
|
|
548
|
-
store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
|
|
549
|
-
//=> Errors: `action` is `(state: TState) => TState`
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
@category Utilities
|
|
553
|
-
*/
|
|
554
|
-
type IsUnknown<T> = (unknown extends T // `T` can be `unknown` or `any`
|
|
555
|
-
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
|
556
|
-
? true : false : false);
|
|
557
|
-
//#endregion
|
|
558
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/keys.d.ts
|
|
559
|
-
/**
|
|
560
|
-
Disallows any of the given keys.
|
|
561
|
-
*/
|
|
562
|
-
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/simplify.d.ts
|
|
565
|
-
/**
|
|
566
|
-
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.
|
|
567
|
-
|
|
568
|
-
@example
|
|
569
|
-
```
|
|
570
|
-
import type {Simplify} from 'type-fest';
|
|
571
|
-
|
|
572
|
-
type PositionProps = {
|
|
573
|
-
top: number;
|
|
574
|
-
left: number;
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
type SizeProps = {
|
|
578
|
-
width: number;
|
|
579
|
-
height: number;
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
583
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
584
|
-
```
|
|
585
|
-
|
|
586
|
-
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
587
|
-
|
|
588
|
-
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
589
|
-
|
|
590
|
-
@example
|
|
591
|
-
```
|
|
592
|
-
import type {Simplify} from 'type-fest';
|
|
593
|
-
|
|
594
|
-
interface SomeInterface {
|
|
595
|
-
foo: number;
|
|
596
|
-
bar?: string;
|
|
597
|
-
baz: number | undefined;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
type SomeType = {
|
|
601
|
-
foo: number;
|
|
602
|
-
bar?: string;
|
|
603
|
-
baz: number | undefined;
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
607
|
-
const someType: SomeType = literal;
|
|
608
|
-
const someInterface: SomeInterface = literal;
|
|
609
|
-
|
|
610
|
-
function fn(object: Record<string, unknown>): void {}
|
|
611
|
-
|
|
612
|
-
fn(literal); // Good: literal object type is sealed
|
|
613
|
-
fn(someType); // Good: type is sealed
|
|
614
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
615
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
619
|
-
@see {@link SimplifyDeep}
|
|
620
|
-
@category Object
|
|
621
|
-
*/
|
|
622
|
-
type Simplify$1<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
623
|
-
//#endregion
|
|
624
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
625
|
-
/**
|
|
626
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
627
|
-
|
|
628
|
-
This is the counterpart of `PickIndexSignature`.
|
|
629
|
-
|
|
630
|
-
Use-cases:
|
|
631
|
-
- Remove overly permissive signatures from third-party types.
|
|
632
|
-
|
|
633
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
634
|
-
|
|
635
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
636
|
-
|
|
637
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
638
|
-
|
|
639
|
-
```
|
|
640
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
641
|
-
|
|
642
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
643
|
-
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
644
|
-
```
|
|
645
|
-
|
|
646
|
-
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
647
|
-
|
|
648
|
-
```
|
|
649
|
-
type Indexed = {} extends Record<string, unknown>
|
|
650
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
651
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
652
|
-
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
653
|
-
|
|
654
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
655
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
656
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
657
|
-
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
661
|
-
|
|
662
|
-
```
|
|
663
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
664
|
-
|
|
665
|
-
type OmitIndexSignature<ObjectType> = {
|
|
666
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
667
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
668
|
-
};
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
672
|
-
|
|
673
|
-
```
|
|
674
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
675
|
-
|
|
676
|
-
type OmitIndexSignature<ObjectType> = {
|
|
677
|
-
[KeyType in keyof ObjectType
|
|
678
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
679
|
-
as {} extends Record<KeyType, unknown>
|
|
680
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
681
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
682
|
-
]: ObjectType[KeyType];
|
|
683
|
-
};
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
687
|
-
|
|
688
|
-
@example
|
|
689
|
-
```
|
|
690
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
691
|
-
|
|
692
|
-
interface Example {
|
|
693
|
-
// These index signatures will be removed.
|
|
694
|
-
[x: string]: any
|
|
695
|
-
[x: number]: any
|
|
696
|
-
[x: symbol]: any
|
|
697
|
-
[x: `head-${string}`]: string
|
|
698
|
-
[x: `${string}-tail`]: string
|
|
699
|
-
[x: `head-${string}-tail`]: string
|
|
700
|
-
[x: `${bigint}`]: string
|
|
701
|
-
[x: `embedded-${number}`]: string
|
|
702
|
-
|
|
703
|
-
// These explicitly defined keys will remain.
|
|
704
|
-
foo: 'bar';
|
|
705
|
-
qux?: 'baz';
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
709
|
-
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
@see {@link PickIndexSignature}
|
|
713
|
-
@category Object
|
|
714
|
-
*/
|
|
715
|
-
type OmitIndexSignature$1<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
718
|
-
/**
|
|
719
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
720
|
-
|
|
721
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
722
|
-
|
|
723
|
-
@example
|
|
724
|
-
```
|
|
725
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
726
|
-
|
|
727
|
-
declare const symbolKey: unique symbol;
|
|
728
|
-
|
|
729
|
-
type Example = {
|
|
730
|
-
// These index signatures will remain.
|
|
731
|
-
[x: string]: unknown;
|
|
732
|
-
[x: number]: unknown;
|
|
733
|
-
[x: symbol]: unknown;
|
|
734
|
-
[x: `head-${string}`]: string;
|
|
735
|
-
[x: `${string}-tail`]: string;
|
|
736
|
-
[x: `head-${string}-tail`]: string;
|
|
737
|
-
[x: `${bigint}`]: string;
|
|
738
|
-
[x: `embedded-${number}`]: string;
|
|
739
|
-
|
|
740
|
-
// These explicitly defined keys will be removed.
|
|
741
|
-
['kebab-case-key']: string;
|
|
742
|
-
[symbolKey]: string;
|
|
743
|
-
foo: 'bar';
|
|
744
|
-
qux?: 'baz';
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
748
|
-
// {
|
|
749
|
-
// [x: string]: unknown;
|
|
750
|
-
// [x: number]: unknown;
|
|
751
|
-
// [x: symbol]: unknown;
|
|
752
|
-
// [x: `head-${string}`]: string;
|
|
753
|
-
// [x: `${string}-tail`]: string;
|
|
754
|
-
// [x: `head-${string}-tail`]: string;
|
|
755
|
-
// [x: `${bigint}`]: string;
|
|
756
|
-
// [x: `embedded-${number}`]: string;
|
|
757
|
-
// }
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
@see {@link OmitIndexSignature}
|
|
761
|
-
@category Object
|
|
762
|
-
*/
|
|
763
|
-
type PickIndexSignature$1<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
764
|
-
//#endregion
|
|
765
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/merge.d.ts
|
|
766
|
-
// Merges two objects without worrying about index signatures.
|
|
767
|
-
type SimpleMerge$1<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
771
|
-
|
|
772
|
-
@example
|
|
773
|
-
```
|
|
774
|
-
import type {Merge} from 'type-fest';
|
|
775
|
-
|
|
776
|
-
interface Foo {
|
|
777
|
-
[x: string]: unknown;
|
|
778
|
-
[x: number]: unknown;
|
|
779
|
-
foo: string;
|
|
780
|
-
bar: symbol;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
type Bar = {
|
|
784
|
-
[x: number]: number;
|
|
785
|
-
[x: symbol]: unknown;
|
|
786
|
-
bar: Date;
|
|
787
|
-
baz: boolean;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
791
|
-
// => {
|
|
792
|
-
// [x: string]: unknown;
|
|
793
|
-
// [x: number]: number;
|
|
794
|
-
// [x: symbol]: unknown;
|
|
795
|
-
// foo: string;
|
|
796
|
-
// bar: Date;
|
|
797
|
-
// baz: boolean;
|
|
798
|
-
// }
|
|
799
|
-
```
|
|
800
|
-
|
|
801
|
-
@category Object
|
|
802
|
-
*/
|
|
803
|
-
type Merge$1<Destination, Source> = Simplify$1<SimpleMerge$1<PickIndexSignature$1<Destination>, PickIndexSignature$1<Source>> & SimpleMerge$1<OmitIndexSignature$1<Destination>, OmitIndexSignature$1<Source>>>;
|
|
804
|
-
//#endregion
|
|
805
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/object.d.ts
|
|
806
|
-
/**
|
|
807
|
-
Merges user specified options with default options.
|
|
808
|
-
|
|
809
|
-
@example
|
|
810
|
-
```
|
|
811
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
812
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
813
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
814
|
-
|
|
815
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
816
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
@example
|
|
820
|
-
```
|
|
821
|
-
// Complains if default values are not provided for optional options
|
|
822
|
-
|
|
823
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
824
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
825
|
-
type SpecifiedOptions = {};
|
|
826
|
-
|
|
827
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
828
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
829
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
@example
|
|
833
|
-
```
|
|
834
|
-
// Complains if an option's default type does not conform to the expected type
|
|
835
|
-
|
|
836
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
837
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
838
|
-
type SpecifiedOptions = {};
|
|
839
|
-
|
|
840
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
841
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
842
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
843
|
-
```
|
|
844
|
-
|
|
845
|
-
@example
|
|
846
|
-
```
|
|
847
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
848
|
-
|
|
849
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
850
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
851
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
852
|
-
|
|
853
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
854
|
-
// ~~~~~~~~~~~~~~~~
|
|
855
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
856
|
-
```
|
|
857
|
-
*/
|
|
858
|
-
type ApplyDefaultOptions$1<Options extends object, Defaults extends Simplify$1<Omit<Required<Options>, RequiredKeysOf$1<Options>> & Partial<Record<RequiredKeysOf$1<Options>, never>>>, SpecifiedOptions extends Options> = If$1<IsAny$1<SpecifiedOptions>, Defaults, If$1<IsNever$1<SpecifiedOptions>, Defaults, Simplify$1<Merge$1<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf$1<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
859
|
-
//#endregion
|
|
860
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/or.d.ts
|
|
861
|
-
/**
|
|
862
|
-
Returns a boolean for whether either of two given types is true.
|
|
863
|
-
|
|
864
|
-
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
865
|
-
|
|
866
|
-
@example
|
|
867
|
-
```
|
|
868
|
-
import type {Or} from 'type-fest';
|
|
869
|
-
|
|
870
|
-
type TT = Or<true, true>;
|
|
871
|
-
//=> true
|
|
872
|
-
|
|
873
|
-
type TF = Or<true, false>;
|
|
874
|
-
//=> true
|
|
875
|
-
|
|
876
|
-
type FT = Or<false, true>;
|
|
877
|
-
//=> true
|
|
878
|
-
|
|
879
|
-
type FF = Or<false, false>;
|
|
880
|
-
//=> false
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
884
|
-
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
885
|
-
|
|
886
|
-
@example
|
|
887
|
-
```
|
|
888
|
-
import type {Or} from 'type-fest';
|
|
889
|
-
|
|
890
|
-
type A = Or<false, boolean>;
|
|
891
|
-
//=> boolean
|
|
892
|
-
|
|
893
|
-
type B = Or<boolean, false>;
|
|
894
|
-
//=> boolean
|
|
895
|
-
|
|
896
|
-
type C = Or<true, boolean>;
|
|
897
|
-
//=> true
|
|
898
|
-
|
|
899
|
-
type D = Or<boolean, true>;
|
|
900
|
-
//=> true
|
|
901
|
-
|
|
902
|
-
type E = Or<boolean, boolean>;
|
|
903
|
-
//=> boolean
|
|
904
|
-
```
|
|
905
|
-
|
|
906
|
-
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
907
|
-
|
|
908
|
-
@example
|
|
909
|
-
```
|
|
910
|
-
import type {Or} from 'type-fest';
|
|
911
|
-
|
|
912
|
-
type A = Or<true, never>;
|
|
913
|
-
//=> true
|
|
914
|
-
|
|
915
|
-
type B = Or<never, true>;
|
|
916
|
-
//=> true
|
|
917
|
-
|
|
918
|
-
type C = Or<false, never>;
|
|
919
|
-
//=> false
|
|
920
|
-
|
|
921
|
-
type D = Or<never, false>;
|
|
922
|
-
//=> false
|
|
923
|
-
|
|
924
|
-
type E = Or<boolean, never>;
|
|
925
|
-
//=> boolean
|
|
926
|
-
|
|
927
|
-
type F = Or<never, boolean>;
|
|
928
|
-
//=> boolean
|
|
929
|
-
|
|
930
|
-
type G = Or<never, never>;
|
|
931
|
-
//=> false
|
|
932
|
-
```
|
|
933
|
-
|
|
934
|
-
@see {@link And}
|
|
935
|
-
@see {@link Xor}
|
|
936
|
-
*/
|
|
937
|
-
type Or<A$1 extends boolean, B$1 extends boolean> = _Or<If$1<IsNever$1<A$1>, false, A$1>, If$1<IsNever$1<B$1>, false, B$1>>;
|
|
938
|
-
// `never` is treated as `false`
|
|
939
|
-
|
|
940
|
-
type _Or<A$1 extends boolean, B$1 extends boolean> = A$1 extends true ? true : B$1 extends true ? true : false;
|
|
941
|
-
//#endregion
|
|
942
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/require-exactly-one.d.ts
|
|
943
|
-
/**
|
|
944
|
-
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
945
|
-
|
|
946
|
-
Use-cases:
|
|
947
|
-
- Creating interfaces for components that only need one of the keys to display properly.
|
|
948
|
-
- Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
|
|
949
|
-
|
|
950
|
-
The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
|
|
951
|
-
|
|
952
|
-
@example
|
|
953
|
-
```
|
|
954
|
-
import type {RequireExactlyOne} from 'type-fest';
|
|
955
|
-
|
|
956
|
-
type Responder = {
|
|
957
|
-
text: () => string;
|
|
958
|
-
json: () => string;
|
|
959
|
-
secure: boolean;
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
|
|
963
|
-
// Adding a `text` key here would cause a compile error.
|
|
964
|
-
|
|
965
|
-
json: () => '{"message": "ok"}',
|
|
966
|
-
secure: true
|
|
967
|
-
};
|
|
968
|
-
```
|
|
969
|
-
|
|
970
|
-
@category Object
|
|
971
|
-
*/
|
|
972
|
-
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If$1<IsNever$1<KeysType>, never, _RequireExactlyOne<ObjectType, If$1<IsAny$1<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
973
|
-
type _RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]: (Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>) }[KeysType] & Omit<ObjectType, KeysType>;
|
|
974
|
-
//#endregion
|
|
975
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/require-one-or-none.d.ts
|
|
976
|
-
/**
|
|
977
|
-
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.
|
|
978
|
-
|
|
979
|
-
@example
|
|
980
|
-
```
|
|
981
|
-
import type {RequireOneOrNone} from 'type-fest';
|
|
982
|
-
|
|
983
|
-
type Responder = RequireOneOrNone<{
|
|
984
|
-
text: () => string;
|
|
985
|
-
json: () => string;
|
|
986
|
-
secure: boolean;
|
|
987
|
-
}, 'text' | 'json'>;
|
|
988
|
-
|
|
989
|
-
const responder1: Responder = {
|
|
990
|
-
secure: true
|
|
991
|
-
};
|
|
992
|
-
|
|
993
|
-
const responder2: Responder = {
|
|
994
|
-
text: () => '{"message": "hi"}',
|
|
995
|
-
secure: true
|
|
996
|
-
};
|
|
997
|
-
|
|
998
|
-
const responder3: Responder = {
|
|
999
|
-
json: () => '{"message": "ok"}',
|
|
1000
|
-
secure: true
|
|
1001
|
-
};
|
|
1002
|
-
```
|
|
1003
|
-
|
|
1004
|
-
@category Object
|
|
1005
|
-
*/
|
|
1006
|
-
type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If$1<IsNever$1<KeysType>, ObjectType, _RequireOneOrNone<ObjectType, If$1<IsAny$1<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
1007
|
-
type _RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
|
|
1008
|
-
//#endregion
|
|
1009
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-union.d.ts
|
|
1010
|
-
/**
|
|
1011
|
-
Returns a boolean for whether the given type is a union.
|
|
1012
|
-
|
|
1013
|
-
@example
|
|
1014
|
-
```
|
|
1015
|
-
import type {IsUnion} from 'type-fest';
|
|
1016
|
-
|
|
1017
|
-
type A = IsUnion<string | number>;
|
|
1018
|
-
//=> true
|
|
1019
|
-
|
|
1020
|
-
type B = IsUnion<string>;
|
|
1021
|
-
//=> false
|
|
1022
|
-
```
|
|
1023
|
-
*/
|
|
1024
|
-
|
|
1025
|
-
// Should never happen
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/partial-deep.d.ts
|
|
1028
|
-
/**
|
|
1029
|
-
@see {@link PartialDeep}
|
|
1030
|
-
*/
|
|
1031
|
-
type PartialDeepOptions$1 = {
|
|
1032
|
-
/**
|
|
1033
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
1034
|
-
@default false
|
|
1035
|
-
*/
|
|
1036
|
-
readonly recurseIntoArrays?: boolean;
|
|
1037
|
-
|
|
1038
|
-
/**
|
|
1039
|
-
Allows `undefined` values in non-tuple arrays.
|
|
1040
|
-
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
1041
|
-
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
1042
|
-
@default false
|
|
1043
|
-
@example
|
|
1044
|
-
You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
|
|
1045
|
-
```
|
|
1046
|
-
import type {PartialDeep} from 'type-fest';
|
|
1047
|
-
type Settings = {
|
|
1048
|
-
languages: string[];
|
|
1049
|
-
};
|
|
1050
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
|
|
1051
|
-
partialSettings.languages = [undefined]; // OK
|
|
1052
|
-
```
|
|
1053
|
-
*/
|
|
1054
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
1055
|
-
};
|
|
1056
|
-
type DefaultPartialDeepOptions$1 = {
|
|
1057
|
-
recurseIntoArrays: false;
|
|
1058
|
-
allowUndefinedInNonTupleArrays: false;
|
|
1059
|
-
};
|
|
1060
|
-
|
|
1061
|
-
/**
|
|
1062
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
1063
|
-
|
|
1064
|
-
Use-cases:
|
|
1065
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
1066
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
1067
|
-
|
|
1068
|
-
@example
|
|
1069
|
-
```
|
|
1070
|
-
import type {PartialDeep} from 'type-fest';
|
|
1071
|
-
|
|
1072
|
-
let settings = {
|
|
1073
|
-
textEditor: {
|
|
1074
|
-
fontSize: 14,
|
|
1075
|
-
fontColor: '#000000',
|
|
1076
|
-
fontWeight: 400,
|
|
1077
|
-
},
|
|
1078
|
-
autocomplete: false,
|
|
1079
|
-
autosave: true,
|
|
1080
|
-
};
|
|
1081
|
-
|
|
1082
|
-
const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
|
|
1083
|
-
{...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
|
|
1084
|
-
);
|
|
1085
|
-
|
|
1086
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
1087
|
-
```
|
|
1088
|
-
|
|
1089
|
-
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
1090
|
-
|
|
1091
|
-
```
|
|
1092
|
-
import type {PartialDeep} from 'type-fest';
|
|
1093
|
-
|
|
1094
|
-
type Shape = {
|
|
1095
|
-
dimensions: [number, number];
|
|
1096
|
-
};
|
|
1097
|
-
|
|
1098
|
-
const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
|
|
1099
|
-
dimensions: [], // OK
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
|
-
partialShape.dimensions = [15]; // OK
|
|
1103
|
-
```
|
|
1104
|
-
|
|
1105
|
-
@see {@link PartialDeepOptions}
|
|
1106
|
-
|
|
1107
|
-
@category Object
|
|
1108
|
-
@category Array
|
|
1109
|
-
@category Set
|
|
1110
|
-
@category Map
|
|
1111
|
-
*/
|
|
1112
|
-
type PartialDeep$1<T, Options extends PartialDeepOptions$1 = {}> = _PartialDeep$1<T, ApplyDefaultOptions$1<PartialDeepOptions$1, DefaultPartialDeepOptions$1, Options>>;
|
|
1113
|
-
type _PartialDeep$1<T, Options extends Required<PartialDeepOptions$1>> = T extends BuiltIns$1 | ((new (...arguments_: any[]) => unknown)) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep$1<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep$1<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep$1<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep$1<ItemType, Options> : T extends ((...arguments_: any[]) => unknown) ? IsNever$1<keyof T> extends true ? T // For functions with no properties
|
|
1114
|
-
: HasMultipleCallSignatures$1<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep$1<T, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
1115
|
-
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
1116
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
1117
|
-
? ReadonlyArray<_PartialDeep$1<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep$1<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep$1<T, Options> // Tuples behave properly
|
|
1118
|
-
: T // If they don't opt into array testing, just use the original type
|
|
1119
|
-
: PartialObjectDeep$1<T, Options> : unknown;
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
1123
|
-
*/
|
|
1124
|
-
type PartialMapDeep$1<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions$1>> = {} & Map<_PartialDeep$1<KeyType$1, Options>, _PartialDeep$1<ValueType$1, Options>>;
|
|
1125
|
-
|
|
1126
|
-
/**
|
|
1127
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
1128
|
-
*/
|
|
1129
|
-
type PartialSetDeep$1<T, Options extends Required<PartialDeepOptions$1>> = {} & Set<_PartialDeep$1<T, Options>>;
|
|
1130
|
-
|
|
1131
|
-
/**
|
|
1132
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
1133
|
-
*/
|
|
1134
|
-
type PartialReadonlyMapDeep$1<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions$1>> = {} & ReadonlyMap<_PartialDeep$1<KeyType$1, Options>, _PartialDeep$1<ValueType$1, Options>>;
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
1138
|
-
*/
|
|
1139
|
-
type PartialReadonlySetDeep$1<T, Options extends Required<PartialDeepOptions$1>> = {} & ReadonlySet<_PartialDeep$1<T, Options>>;
|
|
1140
|
-
|
|
1141
|
-
/**
|
|
1142
|
-
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
1143
|
-
*/
|
|
1144
|
-
type PartialObjectDeep$1<ObjectType extends object, Options extends Required<PartialDeepOptions$1>> = { [KeyType in keyof ObjectType]?: _PartialDeep$1<ObjectType[KeyType], Options> };
|
|
1145
|
-
//#endregion
|
|
1146
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-deep.d.ts
|
|
1147
|
-
/**
|
|
1148
|
-
Create a type from another type with all keys and nested keys set to required.
|
|
1149
|
-
|
|
1150
|
-
Use-cases:
|
|
1151
|
-
- Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
|
|
1152
|
-
- Modeling the resulting type after a deep merge with a set of defaults.
|
|
1153
|
-
|
|
1154
|
-
@example
|
|
1155
|
-
```
|
|
1156
|
-
import type {RequiredDeep} from 'type-fest';
|
|
1157
|
-
|
|
1158
|
-
type Settings = {
|
|
1159
|
-
textEditor?: {
|
|
1160
|
-
fontSize?: number;
|
|
1161
|
-
fontColor?: string;
|
|
1162
|
-
fontWeight?: number | undefined;
|
|
1163
|
-
};
|
|
1164
|
-
autocomplete?: boolean;
|
|
1165
|
-
autosave?: boolean | undefined;
|
|
1166
|
-
};
|
|
1167
|
-
|
|
1168
|
-
type RequiredSettings = RequiredDeep<Settings>;
|
|
1169
|
-
//=> {
|
|
1170
|
-
// textEditor: {
|
|
1171
|
-
// fontSize: number;
|
|
1172
|
-
// fontColor: string;
|
|
1173
|
-
// fontWeight: number | undefined;
|
|
1174
|
-
// };
|
|
1175
|
-
// autocomplete: boolean;
|
|
1176
|
-
// autosave: boolean | undefined;
|
|
1177
|
-
// }
|
|
1178
|
-
```
|
|
1179
|
-
|
|
1180
|
-
Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
1181
|
-
|
|
1182
|
-
@category Utilities
|
|
1183
|
-
@category Object
|
|
1184
|
-
@category Array
|
|
1185
|
-
@category Set
|
|
1186
|
-
@category Map
|
|
1187
|
-
*/
|
|
1188
|
-
|
|
1189
|
-
//#endregion
|
|
1190
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
1191
|
-
/**
|
|
1192
|
-
Returns the last element of a union type.
|
|
1193
|
-
|
|
1194
|
-
@example
|
|
1195
|
-
```
|
|
1196
|
-
type Last = LastOfUnion<1 | 2 | 3>;
|
|
1197
|
-
//=> 3
|
|
1198
|
-
```
|
|
1199
|
-
*/
|
|
1200
|
-
type LastOfUnion<T> = UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
1201
|
-
|
|
1202
|
-
/**
|
|
1203
|
-
Convert a union type into an unordered tuple type of its elements.
|
|
1204
|
-
|
|
1205
|
-
"Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
|
|
1206
|
-
|
|
1207
|
-
This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
|
|
1208
|
-
|
|
1209
|
-
@example
|
|
1210
|
-
```
|
|
1211
|
-
import type {UnionToTuple} from 'type-fest';
|
|
1212
|
-
|
|
1213
|
-
type Numbers = 1 | 2 | 3;
|
|
1214
|
-
type NumbersTuple = UnionToTuple<Numbers>;
|
|
1215
|
-
//=> [1, 2, 3]
|
|
1216
|
-
```
|
|
1217
|
-
|
|
1218
|
-
@example
|
|
1219
|
-
```
|
|
1220
|
-
import type {UnionToTuple} from 'type-fest';
|
|
1221
|
-
|
|
1222
|
-
const pets = {
|
|
1223
|
-
dog: '🐶',
|
|
1224
|
-
cat: '🐱',
|
|
1225
|
-
snake: '🐍',
|
|
1226
|
-
};
|
|
1227
|
-
|
|
1228
|
-
type Pet = keyof typeof pets;
|
|
1229
|
-
//=> 'dog' | 'cat' | 'snake'
|
|
1230
|
-
|
|
1231
|
-
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
1232
|
-
//=> ['dog', 'cat', 'snake']
|
|
1233
|
-
```
|
|
1234
|
-
|
|
1235
|
-
@category Array
|
|
1236
|
-
*/
|
|
1237
|
-
type UnionToTuple<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
|
|
1238
|
-
//#endregion
|
|
1239
|
-
//#region src/types/core/modifiers.types.d.ts
|
|
1240
|
-
interface RegleBehaviourOptions {
|
|
1241
|
-
/**
|
|
1242
|
-
* Only display error when calling `r$.$validate()`
|
|
1243
|
-
* @default false
|
|
1244
|
-
*/
|
|
1245
|
-
lazy?: boolean | undefined;
|
|
1246
|
-
/**
|
|
1247
|
-
* Automatically set the dirty set without the need of `$value` or `$touch`.
|
|
1248
|
-
* @default true
|
|
1249
|
-
*
|
|
1250
|
-
*/
|
|
1251
|
-
autoDirty?: boolean | undefined;
|
|
1252
|
-
/**
|
|
1253
|
-
* Only update error status when calling `$validate`.
|
|
1254
|
-
* Will not display errors as you type
|
|
1255
|
-
* @default false
|
|
1256
|
-
*
|
|
1257
|
-
* @default true if rewardEarly is true
|
|
1258
|
-
*
|
|
1259
|
-
*/
|
|
1260
|
-
silent?: boolean | undefined;
|
|
1261
|
-
/**
|
|
1262
|
-
* The fields will turn valid when they are, but not invalid unless calling `r$.$validate()`
|
|
1263
|
-
* @default false
|
|
1264
|
-
*/
|
|
1265
|
-
rewardEarly?: boolean | undefined;
|
|
1266
|
-
/**
|
|
1267
|
-
* Define whether the external errors should be cleared when updating a field
|
|
1268
|
-
*
|
|
1269
|
-
* Default to `false` if `$silent` is set to `true`
|
|
1270
|
-
* @default true
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*/
|
|
1274
|
-
clearExternalErrorsOnChange?: boolean | undefined;
|
|
1275
|
-
}
|
|
1276
|
-
interface LocalRegleBehaviourOptions<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
|
|
1277
|
-
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState$1>> | Record<string, string[]>>;
|
|
1278
|
-
validationGroups?: (fields: RegleStatus<TState$1, TRules$1>['$fields']) => TValidationGroups;
|
|
1279
|
-
}
|
|
1280
|
-
type RegleValidationGroupEntry = RegleFieldStatus<any, any> | undefined;
|
|
1281
|
-
interface RegleValidationGroupOutput {
|
|
1282
|
-
$invalid: boolean;
|
|
1283
|
-
$error: boolean;
|
|
1284
|
-
$pending: boolean;
|
|
1285
|
-
$dirty: boolean;
|
|
1286
|
-
$correct: boolean;
|
|
1287
|
-
$errors: string[];
|
|
1288
|
-
$silentErrors: string[];
|
|
1289
|
-
}
|
|
1290
|
-
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
1291
|
-
/**
|
|
1292
|
-
* Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
|
|
1293
|
-
*/
|
|
1294
|
-
$debounce?: number;
|
|
1295
|
-
};
|
|
1296
|
-
type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
|
|
1297
|
-
/**
|
|
1298
|
-
* Allow deep compare of array children to compute the `$edited` property
|
|
1299
|
-
*
|
|
1300
|
-
* Disabled by default for performance
|
|
1301
|
-
*
|
|
1302
|
-
* @default false
|
|
1303
|
-
* */
|
|
1304
|
-
$deepCompare?: boolean;
|
|
1305
|
-
};
|
|
1306
|
-
type ShortcutCommonFn<T extends Record<string, any>> = {
|
|
1307
|
-
[x: string]: (element: Omit<OmitByType<T, Function>, '~standard'>) => unknown;
|
|
1308
|
-
};
|
|
1309
|
-
type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
|
|
1310
|
-
/**
|
|
1311
|
-
* Allow you to customize the properties for every field
|
|
1312
|
-
*/
|
|
1313
|
-
fields?: ShortcutCommonFn<RegleFieldStatus<any, Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1314
|
-
/**
|
|
1315
|
-
* Allow you to customize the properties for every parent of a nested object
|
|
1316
|
-
*/
|
|
1317
|
-
nested?: ShortcutCommonFn<RegleStatus<Record<string, any>, ReglePartialRuleTree<any, Partial<TCustomRules> & Partial<DefaultValidators>>>>;
|
|
1318
|
-
/**
|
|
1319
|
-
* Allow you to customize the properties for every parent of a collection
|
|
1320
|
-
*/
|
|
1321
|
-
collections?: ShortcutCommonFn<RegleCollectionStatus<any[], Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1322
|
-
};
|
|
1323
|
-
type AddDollarToOptions<T extends Record<string, any>> = { [K in keyof T as `$${string & K}`]: T[K] };
|
|
1324
|
-
//#endregion
|
|
1325
|
-
//#region src/types/core/useRegle.types.d.ts
|
|
1326
|
-
/**
|
|
1327
|
-
* The main Regle type that represents a complete validation instance.
|
|
1328
|
-
*
|
|
1329
|
-
* @template TState - The shape of the state object being validated
|
|
1330
|
-
* @template TRules - The validation rules tree for the state
|
|
1331
|
-
* @template TValidationGroups - Groups of validation rules that can be run together
|
|
1332
|
-
* @template TShortcuts - Custom shortcut definitions for common validation patterns
|
|
1333
|
-
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
1334
|
-
*
|
|
1335
|
-
*/
|
|
1336
|
-
type Regle<TState$1 extends Record<string, any> = EmptyObject$1, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> = EmptyObject$1, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
1337
|
-
/**
|
|
1338
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1339
|
-
*
|
|
1340
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1341
|
-
*/
|
|
1342
|
-
r$: Raw<RegleRoot<TState$1, TRules$1, TValidationGroups, TShortcuts>>;
|
|
1343
|
-
} & TAdditionalReturnProperties;
|
|
1344
|
-
/**
|
|
1345
|
-
* The type for a single field validation instance.
|
|
1346
|
-
*
|
|
1347
|
-
* @template TState - The type of the state value being validated
|
|
1348
|
-
* @template TRules - The validation rules for the field
|
|
1349
|
-
* @template TShortcuts - Custom shortcut definitions for common validation patterns
|
|
1350
|
-
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
1351
|
-
*/
|
|
1352
|
-
type RegleSingleField<TState$1 extends Maybe<PrimitiveTypes> = any, TRules$1 extends RegleRuleDecl<NonNullable<TState$1>> = EmptyObject$1, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
1353
|
-
/**
|
|
1354
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1355
|
-
*
|
|
1356
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1357
|
-
*/
|
|
1358
|
-
r$: Raw<RegleFieldStatus<TState$1, TRules$1, TShortcuts>>;
|
|
1359
|
-
} & TAdditionalReturnProperties;
|
|
1360
|
-
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
|
|
1361
|
-
type InferDeepReactiveState<TState$1> = NonNullable<TState$1> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState$1> extends Date | File ? MaybeRef<TState$1> : NonNullable<TState$1> extends Record<string, any> ? DeepReactiveState<TState$1> : MaybeRef<TState$1>;
|
|
1362
|
-
//#endregion
|
|
1363
|
-
//#region src/types/core/reset.types.d.ts
|
|
1364
|
-
type ResetOptions<TState$1 extends unknown> = RequireOneOrNone<{
|
|
1365
|
-
/**
|
|
1366
|
-
* Reset validation status and reset form state to its initial state.
|
|
1367
|
-
*
|
|
1368
|
-
* Initial state is different than the original state as the initial state can be mutated when using `$reset`.
|
|
1369
|
-
*
|
|
1370
|
-
* This serve as the base comparison state for `$edited` property.
|
|
1371
|
-
*
|
|
1372
|
-
* ⚠️ This doesn't work if the state is a `reactive` object.
|
|
1373
|
-
*/
|
|
1374
|
-
toInitialState?: boolean;
|
|
1375
|
-
/**
|
|
1376
|
-
* Reset validation status and reset form state to its original state.
|
|
1377
|
-
*
|
|
1378
|
-
* Original state is the unmutated state that was passed to the form when it was initialized.
|
|
1379
|
-
*/
|
|
1380
|
-
toOriginalState?: boolean;
|
|
1381
|
-
/**
|
|
1382
|
-
* Reset validation status and reset form state to the given state
|
|
1383
|
-
* Also set the new state as the initial state.
|
|
1384
|
-
*/
|
|
1385
|
-
toState?: TState$1 | (() => TState$1);
|
|
1386
|
-
/**
|
|
1387
|
-
* Clears the $externalErrors state back to an empty object.
|
|
1388
|
-
*
|
|
1389
|
-
* @default false
|
|
1390
|
-
*/
|
|
1391
|
-
clearExternalErrors?: boolean;
|
|
1392
|
-
/**
|
|
1393
|
-
* Keep the validation state of the form ($dirty, $invalid, $pending etc..)
|
|
1394
|
-
* Only useful if you only want to reset the form state.
|
|
1395
|
-
*
|
|
1396
|
-
* @default false
|
|
1397
|
-
*/
|
|
1398
|
-
keepValidationState?: boolean;
|
|
1399
|
-
}, 'toInitialState' | 'toState'>;
|
|
1400
|
-
//#endregion
|
|
1401
|
-
//#region src/types/core/scopedRegle.types.d.ts
|
|
1402
|
-
type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
|
|
1403
|
-
'~~global': Record<string, SuperCompatibleRegleRoot>;
|
|
1404
|
-
};
|
|
1405
|
-
type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
1406
|
-
//#endregion
|
|
1407
|
-
//#region src/types/core/results.types.d.ts
|
|
1408
|
-
type PartialFormState<TState$1 extends Record<string, any>> = [unknown] extends [TState$1] ? {} : Prettify<{ [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? never : TState$1[K] extends Array<any> ? never : K]?: MaybeOutput<TState$1[K]> } & { [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? K : TState$1[K] extends Array<any> ? K : never]: NonNullable<TState$1[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState$1[K]> }>;
|
|
1409
|
-
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
|
|
1410
|
-
valid: false;
|
|
1411
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny$1<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? 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> : unknown;
|
|
1412
|
-
} | {
|
|
1413
|
-
valid: true;
|
|
1414
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny$1<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules$1>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules$1> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules$1> : SafeFieldProperty<Data, TRules$1> : unknown;
|
|
1415
|
-
};
|
|
1416
|
-
type RegleNestedResult<Data extends Record<string, any> | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
1417
|
-
valid: false;
|
|
1418
|
-
issues: RegleIssuesTree<Data>;
|
|
1419
|
-
errors: RegleErrorTree<Data>;
|
|
1420
|
-
} | {
|
|
1421
|
-
valid: true;
|
|
1422
|
-
issues: EmptyObject$1;
|
|
1423
|
-
errors: EmptyObject$1;
|
|
1424
|
-
});
|
|
1425
|
-
type RegleCollectionResult<Data extends any[], TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
1426
|
-
valid: false;
|
|
1427
|
-
issues: RegleCollectionErrors<Data, true>;
|
|
1428
|
-
errors: RegleCollectionErrors<Data>;
|
|
1429
|
-
} | {
|
|
1430
|
-
valid: true;
|
|
1431
|
-
issues: EmptyObject$1;
|
|
1432
|
-
errors: EmptyObject$1;
|
|
1433
|
-
});
|
|
1434
|
-
type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & {
|
|
1435
|
-
issues: RegleFieldIssue<TRules$1>[];
|
|
1436
|
-
errors: string[];
|
|
1437
|
-
};
|
|
1438
|
-
/**
|
|
1439
|
-
* Infer safe output from any `r$` instance
|
|
1440
|
-
*
|
|
1441
|
-
* ```ts
|
|
1442
|
-
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
1443
|
-
* ```
|
|
1444
|
-
*/
|
|
1445
|
-
|
|
1446
|
-
type $InternalRegleResult = {
|
|
1447
|
-
valid: boolean;
|
|
1448
|
-
data: any;
|
|
1449
|
-
errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
|
|
1450
|
-
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
1451
|
-
};
|
|
1452
|
-
type DeepSafeFormState<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? {} : TRules$1 extends undefined ? TState$1 : TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? K : never]?: SafeProperty<TState$1[K], TRules$1[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState$1[K], TRules$1[K]> } & { [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState$1[K], TRules$1[K]> ? unknown : NonNullable<SafeProperty<TState$1[K], TRules$1[K]>> }> : TState$1;
|
|
1453
|
-
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
|
|
1454
|
-
type ObjectHaveAtLeastOneRequiredField<TState$1 extends Record<string, any>, TRule extends ReglePartialRuleTree<TState$1, any>> = TState$1 extends Maybe<TState$1> ? { [K in keyof NonNullable<TState$1>]-?: IsPropertyOutputRequired<NonNullable<TState$1>[K], TRule[K]> }[keyof TState$1] extends false ? false : true : true;
|
|
1455
|
-
type ArrayHaveAtLeastOneRequiredField<TState$1 extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState$1>> = TState$1 extends Maybe<TState$1> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends MaybeRef<RegleRuleDecl> ? Omit<UnwrapRef<TRule>, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState$1>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
|
|
1456
|
-
type SafeProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState$1 ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState$1 extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState$1 : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? DeepSafeFormState<NonNullable<TState$1> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState$1>> : {}, TRule> : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends true ? TState$1 : MaybeOutput<TState$1> : TState$1 : TState$1;
|
|
1457
|
-
type IsPropertyOutputRequired<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? unknown : NonNullable<TState$1> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState$1>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState$1> extends Record<string, any> ? NonNullable<TState$1> : {}, TRule> extends false ? false : true : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends false ? false : true : false : false;
|
|
1458
|
-
type SafeFieldProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState$1> : MaybeOutput<TState$1>;
|
|
1459
|
-
//#endregion
|
|
1460
|
-
//#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/utils.d.ts
|
|
1461
|
-
/**
|
|
1462
|
-
* Negates a boolean type.
|
|
1463
|
-
*/
|
|
1464
|
-
type Not<T extends boolean> = T extends true ? false : true;
|
|
1465
|
-
/**
|
|
1466
|
-
* Checks if the given type is `never`.
|
|
1467
|
-
*/
|
|
1468
|
-
type IsNever$2<T> = [T] extends [never] ? true : false;
|
|
1469
|
-
/**
|
|
1470
|
-
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
|
|
1471
|
-
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
|
|
1472
|
-
* 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`.
|
|
1473
|
-
*/
|
|
1474
|
-
type Extends<Left, Right> = IsNever$2<Left> extends true ? IsNever$2<Right> : [Left] extends [Right] ? true : false;
|
|
1475
|
-
/**
|
|
1476
|
-
* Convert a union to an intersection.
|
|
1477
|
-
* `A | B | C` -\> `A & B & C`
|
|
1478
|
-
*/
|
|
1479
|
-
type UnionToIntersection$1<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection : never;
|
|
1480
|
-
/**
|
|
1481
|
-
* Get the last element of a union.
|
|
1482
|
-
* First, converts to a union of `() => T` functions,
|
|
1483
|
-
* then uses {@linkcode UnionToIntersection} to get the last one.
|
|
1484
|
-
*/
|
|
1485
|
-
type LastOf<Union> = UnionToIntersection$1<Union extends any ? () => Union : never> extends (() => infer R) ? R : never;
|
|
1486
|
-
/**
|
|
1487
|
-
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
|
1488
|
-
* "last" union member to the end of a tuple, and recursively prepends
|
|
1489
|
-
* the remainder of the union.
|
|
1490
|
-
*/
|
|
1491
|
-
type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever$2<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
|
|
1492
|
-
/**
|
|
1493
|
-
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
|
1494
|
-
*/
|
|
1495
|
-
type UnionToTuple$1<Union> = TuplifyUnion<Union>;
|
|
1496
|
-
type IsUnion<T> = Not<Extends<UnionToTuple$1<T>['length'], 1>>;
|
|
1497
|
-
//#endregion
|
|
1498
|
-
//#region src/types/core/variants.types.d.ts
|
|
1499
|
-
|
|
1500
|
-
type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState$1>> extends true ? Omit<RegleStatus<TState$1, TRules$1, TShortcuts>, '$fields'> & {
|
|
1501
|
-
$fields: ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>];
|
|
1502
|
-
} & (HasNamedKeys<TState$1> extends true ? ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>] : {}) : RegleStatus<TState$1, TRules$1, TShortcuts>;
|
|
1503
|
-
type ProcessChildrenFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState$1>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
1504
|
-
type FindCorrespondingVariant<TState$1 extends Record<string, any>, TRules$1 extends any[]> = TRules$1 extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState$1> ? [F] : FindCorrespondingVariant<TState$1, R> : [];
|
|
1505
|
-
//#endregion
|
|
1506
|
-
//#region src/core/useRegle/useRegle.d.ts
|
|
1507
|
-
type useRegleFnOptions<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<AllRulesDeclarations>>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState$1 extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups> & TAdditionalOptions;
|
|
1508
|
-
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1509
|
-
<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<AllRulesDeclarations> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<MaybeRef<TState$1> | DeepReactiveState<TState$1>>, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState$1> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState$1>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
1510
|
-
__config?: {
|
|
1511
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
1512
|
-
modifiers?: RegleBehaviourOptions;
|
|
1513
|
-
shortcuts?: TShortcuts;
|
|
1514
|
-
};
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* useRegle serves as the foundation for validation logic.
|
|
1518
|
-
*
|
|
1519
|
-
* It accepts the following inputs:
|
|
1520
|
-
*
|
|
1521
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
1522
|
-
* @param rules - These should align with the structure of your state.
|
|
1523
|
-
* @param modifiers - Customize regle behaviour
|
|
1524
|
-
*
|
|
1525
|
-
* ```ts
|
|
1526
|
-
* import { useRegle } from '@regle/core';
|
|
1527
|
-
import { required } from '@regle/rules';
|
|
1528
|
-
|
|
1529
|
-
const { r$ } = useRegle({ email: '' }, {
|
|
1530
|
-
email: { required }
|
|
1531
|
-
})
|
|
1532
|
-
* ```
|
|
1533
|
-
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1534
|
-
*/
|
|
1535
|
-
|
|
1536
|
-
//#endregion
|
|
1537
|
-
//#region src/types/utils/mismatch.types.d.ts
|
|
1538
|
-
/**
|
|
1539
|
-
/**
|
|
1540
|
-
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
1541
|
-
* exactly matches the structure of type T, including all nested properties.
|
|
1542
|
-
*
|
|
1543
|
-
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
1544
|
-
*/
|
|
1545
|
-
type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
|
|
1546
|
-
type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
|
|
1547
|
-
type TypeError<Msg> = {
|
|
1548
|
-
[' TypeError']: Msg;
|
|
1549
|
-
};
|
|
1550
|
-
type Coerce<T> = `${T & string}`;
|
|
1551
|
-
//#endregion
|
|
1552
|
-
//#region src/types/utils/object.types.d.ts
|
|
1553
|
-
type RemoveCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
|
|
1554
|
-
/**
|
|
1555
|
-
* Restore the optional properties (with ?) of a generated mapped object type
|
|
1556
|
-
*/
|
|
1557
|
-
|
|
1558
|
-
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
1559
|
-
/**
|
|
1560
|
-
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
1561
|
-
*/
|
|
1562
|
-
type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
|
|
1563
|
-
/**
|
|
1564
|
-
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
1565
|
-
*/
|
|
1566
|
-
type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
|
|
1567
|
-
/**
|
|
1568
|
-
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
1569
|
-
*/
|
|
1570
|
-
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 NonUndefined<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
|
|
1571
|
-
/**
|
|
1572
|
-
* Get all possible keys from a union, even the ones present only on one union
|
|
1573
|
-
*/
|
|
1574
|
-
type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
1575
|
-
/**
|
|
1576
|
-
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
1577
|
-
*/
|
|
1578
|
-
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
|
|
1579
|
-
/**
|
|
1580
|
-
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
1581
|
-
*/
|
|
1582
|
-
type JoinDiscriminatedUnions<TUnion extends unknown> = HasNamedKeys<TUnion> extends true ? isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : TUnion : TUnion;
|
|
1583
|
-
type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
|
|
1584
|
-
type EnumLike = {
|
|
1585
|
-
[k: string]: string | number;
|
|
1586
|
-
[nu: number]: string;
|
|
1587
|
-
};
|
|
1588
|
-
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
1589
|
-
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
1590
|
-
type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
|
|
1591
|
-
type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
|
|
1592
|
-
//#endregion
|
|
1593
|
-
//#region src/types/utils/infer.types.d.ts
|
|
1594
|
-
|
|
1595
|
-
//#endregion
|
|
1596
|
-
//#region src/types/rules/rule.params.types.d.ts
|
|
1597
|
-
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
1598
|
-
/**
|
|
1599
|
-
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
1600
|
-
*
|
|
1601
|
-
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
1602
|
-
*/
|
|
1603
|
-
type RegleUniversalParams<T extends any[] = [], F$1 = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F$1 extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>> }) => any : never>;
|
|
1604
|
-
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F$1 = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F$1 extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K] }) => any : never>;
|
|
1605
|
-
//#endregion
|
|
1606
|
-
//#region src/types/rules/rule.internal.types.d.ts
|
|
1607
|
-
/**
|
|
1608
|
-
* Internal definition of the rule, this can be used to reset or patch the rule
|
|
1609
|
-
*/
|
|
1610
|
-
type RegleInternalRuleDefs<TValue$1 extends any = any, TParams$1 extends any[] = [], TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = Raw<{
|
|
1611
|
-
_validator: (value: Maybe<TValue$1>, ...args: TParams$1) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1612
|
-
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => string | string[]);
|
|
1613
|
-
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => boolean);
|
|
1614
|
-
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => string | string[]);
|
|
1615
|
-
_type?: string;
|
|
1616
|
-
_message_patched: boolean;
|
|
1617
|
-
_tooltip_patched: boolean;
|
|
1618
|
-
_params?: RegleUniversalParams<TParams$1>;
|
|
1619
|
-
_async: TAsync$1;
|
|
1620
|
-
readonly _brand: symbol;
|
|
1621
|
-
}>;
|
|
1622
|
-
//#endregion
|
|
1623
|
-
//#region src/types/rules/rule.definition.type.d.ts
|
|
1624
|
-
type IsLiteral<T> = string extends T ? false : true;
|
|
1625
|
-
/**
|
|
1626
|
-
* Returned typed of rules created with `createRule`
|
|
1627
|
-
* */
|
|
1628
|
-
interface RegleRuleDefinition<TValue$1 extends unknown = unknown, TParams$1 extends any[] = [], TAsync$1 extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, _TInput = unknown, TFilteredValue extends any = (TValue$1 extends Date & File & infer M ? M : TValue$1)> extends RegleInternalRuleDefs<TFilteredValue, TParams$1, TAsync$1, TMetaData> {
|
|
1629
|
-
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams$1, TAsync$1 extends false ? TMetaData : Promise<TMetaData>>;
|
|
1630
|
-
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1631
|
-
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
1632
|
-
tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1633
|
-
type?: string;
|
|
1634
|
-
_value?: IsLiteral<TValue$1> extends true ? TValue$1 : any;
|
|
1635
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetaData : Promise<TMetaData>;
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* Rules with params created with `createRules` are callable while being customizable
|
|
1639
|
-
*/
|
|
1640
|
-
type RegleRuleWithParamsDefinition<TValue$1 extends unknown = unknown, TParams$1 extends any[] = never, TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean, TInput = unknown, TFilteredValue extends any = (TValue$1 extends Date & File & infer M ? M : TValue$1)> = RegleRuleCore<TFilteredValue, TParams$1, TAsync$1, TMetadata$1> & RegleInternalRuleDefs<TFilteredValue, TParams$1, TAsync$1, TMetadata$1> & {
|
|
1641
|
-
(...params: RegleUniversalParams<TParams$1>): RegleRuleDefinition<TFilteredValue, TParams$1, TAsync$1, TMetadata$1, TInput>;
|
|
1642
|
-
} & (TParams$1 extends [param?: any, ...any[]] ? {
|
|
1643
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1644
|
-
} : {});
|
|
1645
|
-
type RegleRuleWithParamsDefinitionInput<TValue$1 extends any = any, TParams$1 extends any[] = never, TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = (TValue$1 extends Date & File & infer M ? M : TValue$1)> = RegleRuleCore<TFilteredValue, TParams$1, TAsync$1, TMetadata$1> & RegleInternalRuleDefs<TFilteredValue, TParams$1, TAsync$1, TMetadata$1> & (TParams$1 extends [param?: any, ...any[]] ? {
|
|
1646
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1647
|
-
} : {});
|
|
1648
|
-
type RegleRuleMetadataExtended = {
|
|
1649
|
-
$valid: boolean;
|
|
1650
|
-
[x: string]: any;
|
|
1651
|
-
};
|
|
1652
|
-
/**
|
|
1653
|
-
* Define a rule Metadata definition
|
|
1654
|
-
*/
|
|
1655
|
-
type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
|
|
1656
|
-
type DefaultMetadataPropertiesCommon = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid' | '$dirty' | '$pending' | '$correct' | '$error'>;
|
|
1657
|
-
type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
1658
|
-
$rule: Pick<$InternalRegleRuleStatus, '$valid' | '$pending'>;
|
|
1659
|
-
};
|
|
1660
|
-
/**
|
|
1661
|
-
* Will be used to consume metadata on related helpers and rule status
|
|
1662
|
-
*/
|
|
1663
|
-
type RegleRuleMetadataConsumer<TValue$1 extends any, TParams$1 extends [...any[]] = never, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = {
|
|
1664
|
-
$value: Maybe<TValue$1>;
|
|
1665
|
-
} & DefaultMetadataProperties & (TParams$1 extends never ? {} : {
|
|
1666
|
-
$params: [...TParams$1];
|
|
1667
|
-
}) & (Exclude<TMetadata$1, boolean> extends RegleRuleMetadataExtended ? TMetadata$1 extends boolean ? Partial<Omit<Exclude<TMetadata$1, boolean>, '$valid'>> : Omit<Exclude<TMetadata$1, boolean>, '$valid'> : {});
|
|
1668
|
-
/**
|
|
1669
|
-
* Will be used to consume metadata on related helpers and rule status
|
|
1670
|
-
*/
|
|
1671
|
-
type PossibleRegleRuleMetadataConsumer<TValue$1> = {
|
|
1672
|
-
$value: Maybe<TValue$1>;
|
|
1673
|
-
} & DefaultMetadataProperties & {
|
|
1674
|
-
$params?: [...any[]];
|
|
1675
|
-
};
|
|
1676
|
-
/**
|
|
1677
|
-
* Generic types for a created RegleRule
|
|
1678
|
-
*/
|
|
1679
|
-
|
|
1680
|
-
type RegleRuleRawInput<TValue$1 extends any = any, TParams$1 extends [...any[]] = [...any[]], TAsync$1 extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = Omit<RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetaData> | RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetaData>, 'message' | 'tooltip' | 'active'> & {
|
|
1681
|
-
message: any;
|
|
1682
|
-
active?: any;
|
|
1683
|
-
tooltip?: any;
|
|
1684
|
-
};
|
|
1685
|
-
/**
|
|
1686
|
-
* Process the type of created rule with `createRule`.
|
|
1687
|
-
* For a rule with params it will return a function
|
|
1688
|
-
* Otherwise it will return the rule definition
|
|
1689
|
-
*/
|
|
1690
|
-
|
|
1691
|
-
type RegleRuleDefinitionProcessor<TValue$1 extends any = any, TParams$1 extends any[] = [], TReturn = any> = (value: Maybe<TValue$1>, ...params: TParams$1) => TReturn;
|
|
1692
|
-
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
1693
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
1694
|
-
}) | ({
|
|
1695
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
1696
|
-
} & CollectionRegleBehaviourOptions);
|
|
1697
|
-
//#endregion
|
|
1698
|
-
//#region src/types/rules/rule.init.types.d.ts
|
|
1699
|
-
type RegleInitPropertyGetter<TValue$1, TReturn, TParams$1 extends [...any[]], TMetadata$1 extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>) => TReturn);
|
|
1700
|
-
/**
|
|
1701
|
-
* @argument
|
|
1702
|
-
* createRule arguments options
|
|
1703
|
-
*/
|
|
1704
|
-
|
|
1705
|
-
/**
|
|
1706
|
-
* @argument
|
|
1707
|
-
* Rule core
|
|
1708
|
-
*/
|
|
1709
|
-
interface RegleRuleCore<TValue$1 extends any, TParams$1 extends any[] = [], TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> {
|
|
1710
|
-
validator: (value: Maybe<TValue$1>, ...args: TParams$1) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1711
|
-
message: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1712
|
-
active?: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1713
|
-
tooltip?: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1714
|
-
type?: string;
|
|
1715
|
-
async?: boolean;
|
|
1716
|
-
}
|
|
1717
|
-
//#endregion
|
|
1718
|
-
//#region src/core/defaultValidators.d.ts
|
|
1719
|
-
interface CommonComparisonOptions {
|
|
1720
|
-
/**
|
|
1721
|
-
* Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
|
|
1722
|
-
* @default true
|
|
1723
|
-
*/
|
|
1724
|
-
allowEqual?: boolean;
|
|
1725
|
-
}
|
|
1726
|
-
interface CommonAlphaOptions {
|
|
1727
|
-
/**
|
|
1728
|
-
* Allow symbols in alphabetical-like rules (like "_")
|
|
1729
|
-
* @default true
|
|
1730
|
-
*/
|
|
1731
|
-
allowSymbols?: boolean;
|
|
1732
|
-
}
|
|
1733
|
-
type DefaultValidators = {
|
|
1734
|
-
alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined]>;
|
|
1735
|
-
alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined]>;
|
|
1736
|
-
between: RegleRuleWithParamsDefinition<number, [min: Maybe<number>, max: Maybe<number>]>;
|
|
1737
|
-
boolean: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1738
|
-
checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
|
|
1739
|
-
contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1740
|
-
date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
1741
|
-
dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1742
|
-
$valid: false;
|
|
1743
|
-
error: 'date-not-after';
|
|
1744
|
-
} | {
|
|
1745
|
-
$valid: false;
|
|
1746
|
-
error: 'value-or-parameter-not-a-date';
|
|
1747
|
-
}>;
|
|
1748
|
-
dateBefore: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1749
|
-
$valid: false;
|
|
1750
|
-
error: 'date-not-before';
|
|
1751
|
-
} | {
|
|
1752
|
-
$valid: false;
|
|
1753
|
-
error: 'value-or-parameter-not-a-date';
|
|
1754
|
-
}>;
|
|
1755
|
-
dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, after: Maybe<string | Date>, options?: CommonComparisonOptions], false, boolean>;
|
|
1756
|
-
decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1757
|
-
email: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1758
|
-
endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1759
|
-
exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
|
|
1760
|
-
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
1761
|
-
hexadecimal: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1762
|
-
integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1763
|
-
ipv4Address: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1764
|
-
literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
|
|
1765
|
-
macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
|
|
1766
|
-
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1767
|
-
maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1768
|
-
minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1769
|
-
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1770
|
-
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
1771
|
-
number: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1772
|
-
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1773
|
-
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
1774
|
-
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
1775
|
-
required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
|
|
1776
|
-
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
1777
|
-
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1778
|
-
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
1779
|
-
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1780
|
-
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1781
|
-
};
|
|
1782
|
-
//#endregion
|
|
1783
|
-
//#region src/types/rules/rule.custom.types.d.ts
|
|
1784
|
-
type CustomRulesDeclarationTree = {
|
|
1785
|
-
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
1786
|
-
};
|
|
1787
|
-
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
1788
|
-
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
1789
|
-
//#endregion
|
|
1790
|
-
//#region src/types/rules/rule.declaration.types.d.ts
|
|
1791
|
-
/**
|
|
1792
|
-
* @public
|
|
1793
|
-
*/
|
|
1794
|
-
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
1795
|
-
/**
|
|
1796
|
-
* @public
|
|
1797
|
-
*/
|
|
1798
|
-
|
|
1799
|
-
/**
|
|
1800
|
-
* @public
|
|
1801
|
-
*/
|
|
1802
|
-
type RegleFormPropertyType<TValue$1 = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = [NonNullable<TValue$1>] extends [never] ? MaybeRef<RegleRuleDecl<TValue$1, TCustomRules>> : NonNullable<TValue$1> extends Array<any> ? RegleCollectionRuleDecl<TValue$1, TCustomRules> : NonNullable<TValue$1> extends Date ? MaybeRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>> : NonNullable<TValue$1> extends File ? MaybeRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>> : NonNullable<TValue$1> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue$1> extends Record<string, any> ? ReglePartialRuleTree<NonNullable<TValue$1>, TCustomRules> : MaybeRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>>;
|
|
1803
|
-
/**
|
|
1804
|
-
* @internal
|
|
1805
|
-
* @reference {@link RegleFormPropertyType}
|
|
1806
|
-
*/
|
|
1807
|
-
|
|
1808
|
-
/**
|
|
1809
|
-
* @public
|
|
1810
|
-
* Rule tree for a form property
|
|
1811
|
-
*/
|
|
1812
|
-
type RegleRuleDecl<TValue$1 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$1, [...TParams, ...args: [...any[]]], boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any[], any, any> ? FormRuleDeclaration<TValue$1, any[]> : FormRuleDeclaration<TValue$1, any[]> | TOptions[keyof TOptions] };
|
|
1813
|
-
/**
|
|
1814
|
-
* @internal
|
|
1815
|
-
* @reference {@link RegleRuleDecl}
|
|
1816
|
-
*/
|
|
1817
|
-
|
|
1818
|
-
/**
|
|
1819
|
-
* @public
|
|
1820
|
-
*/
|
|
1821
|
-
type RegleCollectionRuleDeclKeyProperty = {
|
|
1822
|
-
$key?: PropertyKey;
|
|
1823
|
-
};
|
|
1824
|
-
/**
|
|
1825
|
-
* @public
|
|
1826
|
-
*/
|
|
1827
|
-
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = ({
|
|
1828
|
-
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
1829
|
-
} & RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
1830
|
-
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
1831
|
-
} & CollectionRegleBehaviourOptions);
|
|
1832
|
-
/** @public */
|
|
1833
|
-
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>, RegleCollectionRuleDeclKeyProperty>;
|
|
1834
|
-
/**
|
|
1835
|
-
* @internal
|
|
1836
|
-
* @reference {@link RegleCollectionRuleDecl}
|
|
1837
|
-
*/
|
|
1838
|
-
|
|
1839
|
-
/**
|
|
1840
|
-
* @public
|
|
1841
|
-
*/
|
|
1842
|
-
type InlineRuleDeclaration<TValue$1 extends any = any, TParams$1 extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue$1>, ...args: UnwrapRegleUniversalParams<TParams$1>) => TReturn;
|
|
1843
|
-
/**
|
|
1844
|
-
* @public
|
|
1845
|
-
* Regroup inline and registered rules
|
|
1846
|
-
* */
|
|
1847
|
-
type FormRuleDeclaration<TValue$1 extends any = unknown, TParams$1 extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync$1 extends boolean = boolean> = InlineRuleDeclaration<TValue$1, TParams$1, TReturn> | RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1> | RegleRuleWithParamsDefinitionInput<TValue$1, [param?: any], TAsync$1, TMetadata$1> | RegleRuleWithParamsDefinitionInput<TValue$1, [param?: any, ...any[]], TAsync$1, TMetadata$1>;
|
|
1848
|
-
//#endregion
|
|
1849
|
-
//#region src/types/rules/rule.status.types.d.ts
|
|
1850
|
-
/**
|
|
1851
|
-
* @public
|
|
1852
|
-
*/
|
|
1853
|
-
type RegleRoot<TState$1 extends Record<string, unknown> = {}, TRules$1 extends ReglePartialRuleTree<TState$1> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> = MaybeVariantStatus<TState$1, TRules$1, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
1854
|
-
/**
|
|
1855
|
-
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
1856
|
-
*/
|
|
1857
|
-
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
1858
|
-
});
|
|
1859
|
-
type ProcessNestedFields$1<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}, TIsFields extends boolean = false> = Or<HasNamedKeys<TState$1>, TIsFields> extends true ? { readonly [TKey in keyof TState$1 as TRules$1[TKey] extends NonNullable<TRules$1[TKey]> ? NonNullable<TRules$1[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules$1[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules$1[TKey]>> extends true ? ExtendOnlyRealRecord<TState$1[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState$1>[TKey], NonNullable<TRules$1[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> } & { readonly [TKey in keyof TState$1 as TRules$1[TKey] extends NonNullable<TRules$1[TKey]> ? NonNullable<TRules$1[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules$1[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules$1[TKey]>> extends true ? ExtendOnlyRealRecord<TState$1[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState$1>[TKey], NonNullable<TRules$1[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> } : {};
|
|
1860
|
-
/**
|
|
1861
|
-
* @public
|
|
1862
|
-
*/
|
|
1863
|
-
type RegleStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState$1> & {
|
|
1864
|
-
/** 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. */
|
|
1865
|
-
readonly $fields: ProcessNestedFields$1<TState$1, TRules$1, TShortcuts, true>;
|
|
1866
|
-
/**
|
|
1867
|
-
* Collection of all the issues, collected for all children properties and nested forms.
|
|
1868
|
-
*
|
|
1869
|
-
* Only contains issues from properties where $dirty equals true.
|
|
1870
|
-
*/
|
|
1871
|
-
readonly $issues: RegleIssuesTree<TState$1>;
|
|
1872
|
-
/**
|
|
1873
|
-
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
1874
|
-
*
|
|
1875
|
-
* Only contains errors from properties where $dirty equals true.
|
|
1876
|
-
* */
|
|
1877
|
-
readonly $errors: RegleErrorTree<TState$1>;
|
|
1878
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
1879
|
-
readonly $silentErrors: RegleErrorTree<TState$1>;
|
|
1880
|
-
/** 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). */
|
|
1881
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState$1>;
|
|
1882
|
-
/** 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). */
|
|
1883
|
-
$validate: (forceValues?: JoinDiscriminatedUnions<TState$1> extends EmptyObject$1 ? any : HasNamedKeys<JoinDiscriminatedUnions<TState$1>> extends true ? IsUnknown<JoinDiscriminatedUnions<TState$1>> extends true ? any : JoinDiscriminatedUnions<TState$1> : any) => Promise<RegleNestedResult<JoinDiscriminatedUnions<TState$1>, TRules$1>>;
|
|
1884
|
-
} & ProcessNestedFields$1<TState$1, TRules$1, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
1885
|
-
/**
|
|
1886
|
-
* @internal
|
|
1887
|
-
* @reference {@link RegleStatus}
|
|
1888
|
-
*/
|
|
1889
|
-
|
|
1890
|
-
/**
|
|
1891
|
-
* @public
|
|
1892
|
-
*/
|
|
1893
|
-
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState$1 extends Record<PropertyKey, any> = any, TKey$1 extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TState$1> extends true ? [TState$1[TKey$1]] extends [undefined | null] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState$1[TKey$1], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleCollectionStatus<TState$1[TKey$1], {}, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState$1[TKey$1]> extends Array<any> ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Date | File ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : unknown extends TState$1[TKey$1] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Date | File ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : unknown extends TState$1[TKey$1] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState$1[TKey$1], ReglePartialRuleTree<TState$1[TKey$1]>, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleCommonStatus<unknown>;
|
|
1894
|
-
/**
|
|
1895
|
-
* @internal
|
|
1896
|
-
* @reference {@link InferRegleStatusType}
|
|
1897
|
-
*/
|
|
1898
|
-
|
|
1899
|
-
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = EmptyObject$1> = {
|
|
1900
|
-
readonly $property: string;
|
|
1901
|
-
readonly $type?: string;
|
|
1902
|
-
readonly $message: string;
|
|
1903
|
-
} & (IsEmptyObject<TRules$1> extends true ? {
|
|
1904
|
-
readonly $rule: string;
|
|
1905
|
-
} : { [K in keyof ComputeFieldRules<any, TRules$1>]: ComputeFieldRules<any, TRules$1>[K] extends {
|
|
1906
|
-
$metadata: infer TMetadata;
|
|
1907
|
-
} ? K extends string ? {
|
|
1908
|
-
readonly $rule: K;
|
|
1909
|
-
} & (TMetadata extends boolean ? {
|
|
1910
|
-
readonly $rule: string;
|
|
1911
|
-
} : TMetadata) : {
|
|
1912
|
-
readonly $rule: string;
|
|
1913
|
-
} : {
|
|
1914
|
-
readonly $rule: string;
|
|
1915
|
-
} }[keyof ComputeFieldRules<any, TRules$1>]);
|
|
1916
|
-
type ComputeFieldRules<TState$1 extends any, TRules$1 extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>>> = IsEmptyObject<TRules$1> extends true ? {
|
|
1917
|
-
readonly [x: string]: RegleRuleStatus<TState$1, any[], any>;
|
|
1918
|
-
} : { readonly [TRuleKey in keyof Omit<TRules$1, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState$1, TRules$1[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules$1[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules$1[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
|
|
1919
|
-
/**
|
|
1920
|
-
* @public
|
|
1921
|
-
*/
|
|
1922
|
-
type RegleFieldStatus<TState$1 extends any = any, TRules$1 extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState$1>, '$value' | '$silentValue'> & {
|
|
1923
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1924
|
-
$value: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
1925
|
-
/** $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. */
|
|
1926
|
-
$silentValue: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
1927
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1928
|
-
*
|
|
1929
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
1930
|
-
readonly $errors: string[];
|
|
1931
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1932
|
-
readonly $silentErrors: string[];
|
|
1933
|
-
/**
|
|
1934
|
-
* Collect all metadata of validators, Only contains metadata from properties where $dirty equals true.
|
|
1935
|
-
*/
|
|
1936
|
-
readonly $issues: RegleFieldIssue<TRules$1>[];
|
|
1937
|
-
/**
|
|
1938
|
-
* Collect all metadata of validators, including the error message.
|
|
1939
|
-
*/
|
|
1940
|
-
readonly $silentIssues: RegleFieldIssue<TRules$1>[];
|
|
1941
|
-
/** Stores external errors of the current field */
|
|
1942
|
-
readonly $externalErrors: string[];
|
|
1943
|
-
/** Stores active tooltips messages of the current field */
|
|
1944
|
-
readonly $tooltips: string[];
|
|
1945
|
-
/** Represents the inactive status. Is true when this state have empty rules */
|
|
1946
|
-
readonly $inactive: boolean;
|
|
1947
|
-
/** 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). */
|
|
1948
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState$1>;
|
|
1949
|
-
/** 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). */
|
|
1950
|
-
$validate: (forceValues?: IsUnknown<TState$1> extends true ? any : TState$1) => Promise<RegleFieldResult<TState$1, TRules$1>>;
|
|
1951
|
-
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1952
|
-
readonly $rules: ComputeFieldRules<TState$1, TRules$1>;
|
|
1953
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
1954
|
-
/**
|
|
1955
|
-
* @internal
|
|
1956
|
-
* @reference {@link RegleFieldStatus}
|
|
1957
|
-
*/
|
|
1958
|
-
|
|
1959
|
-
/**
|
|
1960
|
-
* @public
|
|
1961
|
-
*/
|
|
1962
|
-
interface RegleCommonStatus<TValue$1 = any> extends StandardSchemaV1<TValue$1> {
|
|
1963
|
-
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
1964
|
-
readonly $invalid: boolean;
|
|
1965
|
-
/**
|
|
1966
|
-
* This is not the opposite of `$invalid`. Correct is meant to display UI validation report.
|
|
1967
|
-
*
|
|
1968
|
-
* This will be `true` only if:
|
|
1969
|
-
* - The field have at least one active rule
|
|
1970
|
-
* - Is dirty and not empty
|
|
1971
|
-
* - Passes validation
|
|
1972
|
-
*/
|
|
1973
|
-
readonly $correct: boolean;
|
|
1974
|
-
/** 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.*/
|
|
1975
|
-
readonly $dirty: boolean;
|
|
1976
|
-
/** 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. */
|
|
1977
|
-
readonly $anyDirty: boolean;
|
|
1978
|
-
/** Indicates whether a field has been touched and if the value is different than the initial one.
|
|
1979
|
-
* On nested elements and collections, it's true only if all its children are also `$edited`.
|
|
1980
|
-
* Use `$anyEdited` to check for any edited children
|
|
1981
|
-
*/
|
|
1982
|
-
readonly $edited: boolean;
|
|
1983
|
-
/** 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. */
|
|
1984
|
-
readonly $anyEdited: boolean;
|
|
1985
|
-
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
1986
|
-
readonly $pending: boolean;
|
|
1987
|
-
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
1988
|
-
readonly $error: boolean;
|
|
1989
|
-
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
1990
|
-
readonly $ready: boolean;
|
|
1991
|
-
/** Return the current key name of the field. */
|
|
1992
|
-
readonly $name: string;
|
|
1993
|
-
/** Returns the current path of the rule (used internally for tracking) */
|
|
1994
|
-
readonly $path: string;
|
|
1995
|
-
/** Id used to track collections items */
|
|
1996
|
-
$id?: string;
|
|
1997
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1998
|
-
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
1999
|
-
/**
|
|
2000
|
-
* This value reflect the current initial value of the field.
|
|
2001
|
-
* The initial value is different than the original value as the initial value can be mutated when using `$reset`.
|
|
2002
|
-
*/
|
|
2003
|
-
readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2004
|
-
/**
|
|
2005
|
-
* This value reflect the original value of the field at original call. This can't be mutated
|
|
2006
|
-
*/
|
|
2007
|
-
readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2008
|
-
/**
|
|
2009
|
-
* `$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.
|
|
2010
|
-
* */
|
|
2011
|
-
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2012
|
-
/** Marks the field and all nested properties as $dirty. */
|
|
2013
|
-
$touch(): void;
|
|
2014
|
-
/**
|
|
2015
|
-
* Reset the validation status to a pristine state while keeping the current form state.
|
|
2016
|
-
* Resets the `$dirty` state on all nested properties of a form.
|
|
2017
|
-
* Rerun rules if `$lazy` is false
|
|
2018
|
-
*/
|
|
2019
|
-
$reset(): void;
|
|
2020
|
-
$reset(options?: ResetOptions<TValue$1>): void;
|
|
2021
|
-
/** Clears the $externalErrors state back to an empty object. */
|
|
2022
|
-
$clearExternalErrors(): void;
|
|
2023
|
-
}
|
|
2024
|
-
/**
|
|
2025
|
-
* @public
|
|
2026
|
-
*/
|
|
2027
|
-
type RegleRuleStatus<TValue$1 = any, TParams$1 extends any[] = any[], TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = {
|
|
2028
|
-
/** The name of the rule type. */
|
|
2029
|
-
readonly $type: string;
|
|
2030
|
-
/** Returns the computed error message or messages for the current rule. */
|
|
2031
|
-
readonly $message: string | string[];
|
|
2032
|
-
/** Stores the current rule tooltip or tooltips */
|
|
2033
|
-
readonly $tooltip: string | string[];
|
|
2034
|
-
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
2035
|
-
readonly $active: boolean;
|
|
2036
|
-
/** Indicates the state of validation for this validator. */
|
|
2037
|
-
readonly $valid: boolean;
|
|
2038
|
-
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
2039
|
-
readonly $pending: boolean;
|
|
2040
|
-
/** Returns the current path of the rule (used internally for tracking) */
|
|
2041
|
-
readonly $path: string;
|
|
2042
|
-
/** Contains the metadata returned by the validator function. */
|
|
2043
|
-
readonly $metadata: TMetadata$1 extends boolean ? TMetadata$1 : Omit<TMetadata$1, '$valid'>;
|
|
2044
|
-
/** Run the rule validator and compute its properties like $message and $active */
|
|
2045
|
-
$parse(): Promise<boolean>;
|
|
2046
|
-
/** Reset the $valid, $metadata and $pending states */
|
|
2047
|
-
$reset(): void;
|
|
2048
|
-
/** Returns the original rule validator function. */
|
|
2049
|
-
$validator: ((value: IsUnknown<TValue$1> extends true ? any : MaybeInput<TValue$1>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: IsUnknown<TValue$1> extends true ? any : TValue$1, ...args: [TParams$1] extends [never[]] ? [] : [unknown[]] extends [TParams$1] ? any[] : TParams$1) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
2050
|
-
} & ([TParams$1] extends [never[]] ? {} : [unknown[]] extends [TParams$1] ? {
|
|
2051
|
-
readonly $params?: any[];
|
|
2052
|
-
} : {
|
|
2053
|
-
readonly $params: [...TParams$1];
|
|
2054
|
-
});
|
|
2055
|
-
/**
|
|
2056
|
-
* @internal
|
|
2057
|
-
* @reference {@link RegleRuleStatus}
|
|
2058
|
-
*/
|
|
2059
|
-
interface $InternalRegleRuleStatus {
|
|
2060
|
-
$type?: string;
|
|
2061
|
-
$message: string | string[];
|
|
2062
|
-
$tooltip: string | string[];
|
|
2063
|
-
$active: boolean;
|
|
2064
|
-
$valid: boolean;
|
|
2065
|
-
$pending: boolean;
|
|
2066
|
-
$path: string;
|
|
2067
|
-
$externalErrors?: string[];
|
|
2068
|
-
$params?: any[];
|
|
2069
|
-
$metadata: any;
|
|
2070
|
-
$haveAsync: boolean;
|
|
2071
|
-
$validating: boolean;
|
|
2072
|
-
$fieldDirty: boolean;
|
|
2073
|
-
$fieldInvalid: boolean;
|
|
2074
|
-
$fieldPending: boolean;
|
|
2075
|
-
$fieldCorrect: boolean;
|
|
2076
|
-
$fieldError: boolean;
|
|
2077
|
-
$maybePending: boolean;
|
|
2078
|
-
$validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
|
|
2079
|
-
$parse(): Promise<boolean>;
|
|
2080
|
-
$reset(): void;
|
|
2081
|
-
$unwatch(): void;
|
|
2082
|
-
$watch(): void;
|
|
2083
|
-
}
|
|
2084
|
-
/**
|
|
2085
|
-
* @public
|
|
2086
|
-
*/
|
|
2087
|
-
type RegleCollectionStatus<TState$1 extends any[] = any[], TRules$1 extends ReglePartialRuleTree<ArrayElement<TState$1>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState$1>, '$value'> & {
|
|
2088
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2089
|
-
$value: MaybeOutput<TState$1>;
|
|
2090
|
-
/** $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. */
|
|
2091
|
-
$silentValue: MaybeOutput<TState$1>;
|
|
2092
|
-
/** 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. */
|
|
2093
|
-
readonly $each: Array<InferRegleStatusType<NonNullable<TRules$1>, NonNullable<TState$1>, number, TShortcuts>>;
|
|
2094
|
-
/** 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. */
|
|
2095
|
-
readonly $self: RegleFieldStatus<TState$1, TFieldRule, TShortcuts>;
|
|
2096
|
-
/**
|
|
2097
|
-
* Collection of all the issues, collected for all children properties and nested forms.
|
|
2098
|
-
*
|
|
2099
|
-
* Only contains issues from properties where $dirty equals true.
|
|
2100
|
-
*/
|
|
2101
|
-
readonly $issues: RegleCollectionErrors<TState$1, true>;
|
|
2102
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2103
|
-
*
|
|
2104
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
2105
|
-
readonly $errors: RegleCollectionErrors<TState$1>;
|
|
2106
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2107
|
-
readonly $silentErrors: RegleCollectionErrors<TState$1>;
|
|
2108
|
-
/** 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). */
|
|
2109
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState$1>;
|
|
2110
|
-
/** 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). */
|
|
2111
|
-
$validate: (value?: JoinDiscriminatedUnions<TState$1>) => Promise<RegleCollectionResult<TState$1, JoinDiscriminatedUnions<TRules$1>>>;
|
|
2112
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
2113
|
-
/**
|
|
2114
|
-
* @internal
|
|
2115
|
-
* @reference {@link RegleCollectionStatus}
|
|
2116
|
-
*/
|
|
2117
|
-
|
|
2118
|
-
//#endregion
|
|
2119
|
-
//#region src/types/rules/rule.errors.types.d.ts
|
|
2120
|
-
type RegleErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TIssue extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], false, TIssue> };
|
|
2121
|
-
type RegleIssuesTree<TState$1 = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], false, true> };
|
|
2122
|
-
type RegleExternalErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], true> };
|
|
2123
|
-
type ErrorMessageOrIssue<TIssue extends boolean> = TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2124
|
-
type RegleValidationErrors<TState$1 extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false> = HasNamedKeys<TState$1> extends true ? IsAny$1<TState$1> extends true ? any : NonNullable<TState$1> extends Array<infer U> ? U extends Record<string, any> ? TExternal extends false ? ExtendOnlyRealRecord<U> extends true ? RegleCollectionErrors<U, TIssue> : ErrorMessageOrIssue<TIssue> : RegleExternalCollectionErrors<U, TIssue> : ErrorMessageOrIssue<TIssue> : NonNullable<TState$1> extends Date | File ? ErrorMessageOrIssue<TIssue> : NonNullable<TState$1> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState$1, TIssue> : RegleExternalErrorTree<TState$1> : ErrorMessageOrIssue<TIssue> : any;
|
|
2125
|
-
type RegleCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2126
|
-
readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2127
|
-
readonly $each: RegleValidationErrors<TState$1, false, TIssue>[];
|
|
2128
|
-
};
|
|
2129
|
-
type RegleExternalCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2130
|
-
readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2131
|
-
readonly $each?: RegleValidationErrors<TState$1, true, TIssue>[];
|
|
2132
|
-
};
|
|
2133
|
-
/** @internal */
|
|
2134
|
-
type $InternalRegleCollectionErrors = {
|
|
2135
|
-
readonly $self?: string[];
|
|
2136
|
-
readonly $each?: $InternalRegleErrors[];
|
|
2137
|
-
};
|
|
2138
|
-
type $InternalRegleErrorTree = {
|
|
2139
|
-
[x: string]: $InternalRegleErrors;
|
|
2140
|
-
};
|
|
2141
|
-
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
2142
|
-
type $InternalRegleIssuesTree = {
|
|
2143
|
-
[x: string]: $InternalRegleIssues;
|
|
2144
|
-
};
|
|
2145
|
-
type $InternalRegleIssues = $InternalRegleCollectionIssues | RegleFieldIssue[] | $InternalRegleIssuesTree;
|
|
2146
|
-
type $InternalRegleCollectionIssues = {
|
|
2147
|
-
readonly $self?: RegleFieldIssue[];
|
|
2148
|
-
readonly $each?: $InternalRegleIssues[];
|
|
2149
|
-
};
|
|
2150
|
-
//#endregion
|
|
2151
|
-
//#region src/types/rules/compatibility.rules.d.ts
|
|
2152
|
-
|
|
2153
|
-
/** Supports both core Regle and schemas Regle for Zod/Valibot */
|
|
2154
|
-
type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
|
|
2155
|
-
$groups?: {
|
|
2156
|
-
[x: string]: RegleValidationGroupOutput;
|
|
2157
|
-
};
|
|
2158
|
-
$validate: (...args: any[]) => Promise<SuperCompatibleRegleResult>;
|
|
2159
|
-
};
|
|
2160
|
-
type SuperCompatibleRegleResult = $InternalRegleResult;
|
|
2161
|
-
type SuperCompatibleRegleStatus = {
|
|
2162
|
-
readonly $fields: {
|
|
2163
|
-
[x: string]: any;
|
|
2164
|
-
};
|
|
2165
|
-
readonly $issues: Record<string, RegleValidationErrors<any, false, true>>;
|
|
2166
|
-
readonly $errors: Record<string, RegleValidationErrors<any, false>>;
|
|
2167
|
-
readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
|
|
2168
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
|
|
2169
|
-
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2170
|
-
[x: string]: any;
|
|
2171
|
-
};
|
|
2172
|
-
//#endregion
|
|
2173
|
-
//#region src/core/mergeRegles.d.ts
|
|
2174
|
-
type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue$1 = { [K in keyof TRegles]: TRegles[K]['$value'] }> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch'> & {
|
|
2175
|
-
/** Map of merged Regle instances and their properties */
|
|
2176
|
-
readonly $instances: { [K in keyof TRegles]: TRegles[K] };
|
|
2177
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2178
|
-
$value: TValue$1;
|
|
2179
|
-
/** $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. */
|
|
2180
|
-
$silentValue: TValue$1;
|
|
2181
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2182
|
-
*
|
|
2183
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
2184
|
-
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2185
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
2186
|
-
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
2187
|
-
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2188
|
-
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
2189
|
-
/** 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). */
|
|
2190
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue$1>;
|
|
2191
|
-
/** 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). */
|
|
2192
|
-
$validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
|
|
2193
|
-
};
|
|
2194
|
-
type MergedScopedRegles<TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue$1>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
|
|
2195
|
-
/** Array of scoped Regles instances */
|
|
2196
|
-
readonly $instances: SuperCompatibleRegleRoot[];
|
|
2197
|
-
/** Collection of all registered Regles instances values */
|
|
2198
|
-
readonly $value: TValue$1;
|
|
2199
|
-
/** Collection of all registered Regles instances errors */
|
|
2200
|
-
readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2201
|
-
/** Collection of all registered Regles instances silent errors */
|
|
2202
|
-
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2203
|
-
/** Collection of all registered Regles instances issues */
|
|
2204
|
-
readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2205
|
-
/** Collection of all registered Regles instances silent issues */
|
|
2206
|
-
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2207
|
-
/** 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). */
|
|
2208
|
-
$validate: (forceValues?: TValue$1) => Promise<{
|
|
2209
|
-
valid: boolean;
|
|
2210
|
-
data: TValue$1;
|
|
2211
|
-
errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2212
|
-
issues: RegleValidationErrors<Record<string, unknown>>[];
|
|
2213
|
-
}>;
|
|
2214
|
-
};
|
|
2215
|
-
type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
|
|
2216
|
-
valid: false;
|
|
2217
|
-
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2218
|
-
valid: false;
|
|
2219
|
-
}>['data'] };
|
|
2220
|
-
errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2221
|
-
issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2222
|
-
} | {
|
|
2223
|
-
valid: true;
|
|
2224
|
-
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2225
|
-
valid: true;
|
|
2226
|
-
}>['data'] };
|
|
2227
|
-
errors: EmptyObject$1;
|
|
2228
|
-
issues: EmptyObject$1;
|
|
2229
|
-
};
|
|
2230
|
-
//#endregion
|
|
2231
|
-
//#region src/core/createScopedUseRegle/useCollectScope.d.ts
|
|
2232
|
-
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue$1 extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2233
|
-
r$: MergedRegles<{ [K in keyof TValue$1]: RegleRoot<TValue$1[K]> & SuperCompatibleRegleRoot }>;
|
|
2234
|
-
} : <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2235
|
-
r$: MergedScopedRegles<TValue$1>;
|
|
2236
|
-
};
|
|
2237
|
-
//#endregion
|
|
2238
|
-
//#region src/core/createScopedUseRegle/useScopedRegle.d.ts
|
|
2239
|
-
type UseScopedRegleOptions<TAsRecord extends boolean> = {
|
|
2240
|
-
namespace?: MaybeRefOrGetter<string>;
|
|
2241
|
-
} & (TAsRecord extends true ? {
|
|
2242
|
-
scopeKey: string;
|
|
2243
|
-
} : {});
|
|
2244
|
-
//#endregion
|
|
2245
|
-
//#region src/core/createScopedUseRegle/createScopedUseRegle.d.ts
|
|
2246
|
-
type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsRecord extends boolean> = {
|
|
2247
|
-
/**
|
|
2248
|
-
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
2249
|
-
*/
|
|
2250
|
-
customUseRegle?: TCustomRegle;
|
|
2251
|
-
/**
|
|
2252
|
-
* Store the collected instances externally
|
|
2253
|
-
*/
|
|
2254
|
-
customStore?: Ref<ScopedInstancesRecordLike>;
|
|
2255
|
-
/**
|
|
2256
|
-
* Collect instances in a Record instead of an array
|
|
2257
|
-
*
|
|
2258
|
-
* ⚠️ Each nested `useScopedRegle` must provide a parameter `scopeKey` to be collected.
|
|
2259
|
-
*/
|
|
2260
|
-
asRecord?: TAsRecord;
|
|
2261
|
-
};
|
|
2262
|
-
//#endregion
|
|
2263
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/primitive.d.ts
|
|
2264
|
-
/**
|
|
2265
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
2266
|
-
|
|
2267
|
-
@category Type
|
|
2268
|
-
*/
|
|
2269
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
2270
|
-
//#endregion
|
|
2271
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/empty-object.d.ts
|
|
2272
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
2273
|
-
|
|
2274
|
-
/**
|
|
2275
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
2276
|
-
|
|
2277
|
-
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
2278
|
-
|
|
2279
|
-
@example
|
|
2280
|
-
```
|
|
2281
|
-
import type {EmptyObject} from 'type-fest';
|
|
2282
|
-
|
|
2283
|
-
// The following illustrates the problem with `{}`.
|
|
2284
|
-
const foo1: {} = {}; // Pass
|
|
2285
|
-
const foo2: {} = []; // Pass
|
|
2286
|
-
const foo3: {} = 42; // Pass
|
|
2287
|
-
const foo4: {} = {a: 1}; // Pass
|
|
2288
|
-
|
|
2289
|
-
// With `EmptyObject` only the first case is valid.
|
|
2290
|
-
const bar1: EmptyObject = {}; // Pass
|
|
2291
|
-
const bar2: EmptyObject = 42; // Fail
|
|
2292
|
-
const bar3: EmptyObject = []; // Fail
|
|
2293
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
2294
|
-
```
|
|
2295
|
-
|
|
2296
|
-
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
2297
|
-
|
|
2298
|
-
@category Object
|
|
2299
|
-
*/
|
|
2300
|
-
type EmptyObject = {
|
|
2301
|
-
[emptyObjectSymbol]?: never;
|
|
2302
|
-
};
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-any.d.ts
|
|
2305
|
-
/**
|
|
2306
|
-
Returns a boolean for whether the given type is `any`.
|
|
2307
|
-
|
|
2308
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
2309
|
-
|
|
2310
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
2311
|
-
|
|
2312
|
-
@example
|
|
2313
|
-
```
|
|
2314
|
-
import type {IsAny} from 'type-fest';
|
|
2315
|
-
|
|
2316
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
2317
|
-
const anyObject: any = {a: 1, b: 2};
|
|
2318
|
-
|
|
2319
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
2320
|
-
return obj[key];
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
const typedA = get(typedObject, 'a');
|
|
2324
|
-
//=> 1
|
|
2325
|
-
|
|
2326
|
-
const anyA = get(anyObject, 'a');
|
|
2327
|
-
//=> any
|
|
2328
|
-
```
|
|
2329
|
-
|
|
2330
|
-
@category Type Guard
|
|
2331
|
-
@category Utilities
|
|
2332
|
-
*/
|
|
2333
|
-
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
2334
|
-
//#endregion
|
|
2335
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
2336
|
-
/**
|
|
2337
|
-
Returns a boolean for whether the given key is an optional key of type.
|
|
2338
|
-
|
|
2339
|
-
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
2340
|
-
|
|
2341
|
-
@example
|
|
2342
|
-
```
|
|
2343
|
-
import type {IsOptionalKeyOf} from 'type-fest';
|
|
2344
|
-
|
|
2345
|
-
interface User {
|
|
2346
|
-
name: string;
|
|
2347
|
-
surname: string;
|
|
2348
|
-
|
|
2349
|
-
luckyNumber?: number;
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
|
-
interface Admin {
|
|
2353
|
-
name: string;
|
|
2354
|
-
surname?: string;
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
2358
|
-
//=> true
|
|
2359
|
-
|
|
2360
|
-
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
2361
|
-
//=> false
|
|
2362
|
-
|
|
2363
|
-
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
2364
|
-
//=> boolean
|
|
2365
|
-
|
|
2366
|
-
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
2367
|
-
//=> false
|
|
2368
|
-
|
|
2369
|
-
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
2370
|
-
//=> boolean
|
|
2371
|
-
```
|
|
2372
|
-
|
|
2373
|
-
@category Type Guard
|
|
2374
|
-
@category Utilities
|
|
2375
|
-
*/
|
|
2376
|
-
type IsOptionalKeyOf<Type extends object, Key$1 extends keyof Type> = IsAny<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
2377
|
-
//#endregion
|
|
2378
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
2379
|
-
/**
|
|
2380
|
-
Extract all optional keys from the given type.
|
|
2381
|
-
|
|
2382
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
2383
|
-
|
|
2384
|
-
@example
|
|
2385
|
-
```
|
|
2386
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
2387
|
-
|
|
2388
|
-
interface User {
|
|
2389
|
-
name: string;
|
|
2390
|
-
surname: string;
|
|
2391
|
-
|
|
2392
|
-
luckyNumber?: number;
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
2396
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
2397
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
2398
|
-
};
|
|
2399
|
-
|
|
2400
|
-
const update1: UpdateOperation<User> = {
|
|
2401
|
-
name: 'Alice'
|
|
2402
|
-
};
|
|
2403
|
-
|
|
2404
|
-
const update2: UpdateOperation<User> = {
|
|
2405
|
-
name: 'Bob',
|
|
2406
|
-
luckyNumber: REMOVE_FIELD
|
|
2407
|
-
};
|
|
2408
|
-
```
|
|
2409
|
-
|
|
2410
|
-
@category Utilities
|
|
2411
|
-
*/
|
|
2412
|
-
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
2413
|
-
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
2414
|
-
: never;
|
|
2415
|
-
//#endregion
|
|
2416
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
2417
|
-
/**
|
|
2418
|
-
Extract all required keys from the given type.
|
|
2419
|
-
|
|
2420
|
-
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
2421
|
-
|
|
2422
|
-
@example
|
|
2423
|
-
```
|
|
2424
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
2425
|
-
|
|
2426
|
-
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
2427
|
-
|
|
2428
|
-
interface User {
|
|
2429
|
-
name: string;
|
|
2430
|
-
surname: string;
|
|
2431
|
-
|
|
2432
|
-
luckyNumber?: number;
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
2436
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
2437
|
-
```
|
|
2438
|
-
|
|
2439
|
-
@category Utilities
|
|
2440
|
-
*/
|
|
2441
|
-
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
2442
|
-
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
2443
|
-
//#endregion
|
|
2444
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-never.d.ts
|
|
2445
|
-
/**
|
|
2446
|
-
Returns a boolean for whether the given type is `never`.
|
|
2447
|
-
|
|
2448
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
2449
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
2450
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
2451
|
-
|
|
2452
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
2453
|
-
|
|
2454
|
-
@example
|
|
2455
|
-
```
|
|
2456
|
-
import type {IsNever, And} from 'type-fest';
|
|
2457
|
-
|
|
2458
|
-
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
2459
|
-
type AreStringsEqual<A extends string, B extends string> =
|
|
2460
|
-
And<
|
|
2461
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
2462
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
2463
|
-
>;
|
|
2464
|
-
|
|
2465
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
2466
|
-
AreStringsEqual<I, O> extends true
|
|
2467
|
-
? never
|
|
2468
|
-
: void;
|
|
2469
|
-
|
|
2470
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
2471
|
-
if (input === output) {
|
|
2472
|
-
process.exit(0);
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
endIfEqual('abc', 'abc');
|
|
2477
|
-
//=> never
|
|
2478
|
-
|
|
2479
|
-
endIfEqual('abc', '123');
|
|
2480
|
-
//=> void
|
|
2481
|
-
```
|
|
2482
|
-
|
|
2483
|
-
@category Type Guard
|
|
2484
|
-
@category Utilities
|
|
2485
|
-
*/
|
|
2486
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
2487
|
-
//#endregion
|
|
2488
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/if.d.ts
|
|
2489
|
-
/**
|
|
2490
|
-
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
2491
|
-
|
|
2492
|
-
Use-cases:
|
|
2493
|
-
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
2494
|
-
|
|
2495
|
-
Note:
|
|
2496
|
-
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
2497
|
-
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
2498
|
-
|
|
2499
|
-
@example
|
|
2500
|
-
```
|
|
2501
|
-
import {If} from 'type-fest';
|
|
2502
|
-
|
|
2503
|
-
type A = If<true, 'yes', 'no'>;
|
|
2504
|
-
//=> 'yes'
|
|
2505
|
-
|
|
2506
|
-
type B = If<false, 'yes', 'no'>;
|
|
2507
|
-
//=> 'no'
|
|
2508
|
-
|
|
2509
|
-
type C = If<boolean, 'yes', 'no'>;
|
|
2510
|
-
//=> 'yes' | 'no'
|
|
2511
|
-
|
|
2512
|
-
type D = If<any, 'yes', 'no'>;
|
|
2513
|
-
//=> 'yes' | 'no'
|
|
2514
|
-
|
|
2515
|
-
type E = If<never, 'yes', 'no'>;
|
|
2516
|
-
//=> 'no'
|
|
2517
|
-
```
|
|
2518
|
-
|
|
2519
|
-
@example
|
|
2520
|
-
```
|
|
2521
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
2522
|
-
|
|
2523
|
-
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
2524
|
-
//=> 'not any'
|
|
2525
|
-
|
|
2526
|
-
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
2527
|
-
//=> 'is never'
|
|
2528
|
-
```
|
|
2529
|
-
|
|
2530
|
-
@example
|
|
2531
|
-
```
|
|
2532
|
-
import {If, IsEqual} from 'type-fest';
|
|
2533
|
-
|
|
2534
|
-
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
2535
|
-
|
|
2536
|
-
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
2537
|
-
//=> 'equal'
|
|
2538
|
-
|
|
2539
|
-
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
2540
|
-
//=> 'not equal'
|
|
2541
|
-
```
|
|
2542
|
-
|
|
2543
|
-
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
2544
|
-
|
|
2545
|
-
@example
|
|
2546
|
-
```
|
|
2547
|
-
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
2548
|
-
|
|
2549
|
-
type HundredZeroes = StringRepeat<'0', 100>;
|
|
2550
|
-
|
|
2551
|
-
// The following implementation is not tail recursive
|
|
2552
|
-
type Includes<S extends string, Char extends string> =
|
|
2553
|
-
S extends `${infer First}${infer Rest}`
|
|
2554
|
-
? If<IsEqual<First, Char>,
|
|
2555
|
-
'found',
|
|
2556
|
-
Includes<Rest, Char>>
|
|
2557
|
-
: 'not found';
|
|
2558
|
-
|
|
2559
|
-
// Hence, instantiations with long strings will fail
|
|
2560
|
-
// @ts-expect-error
|
|
2561
|
-
type Fails = Includes<HundredZeroes, '1'>;
|
|
2562
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
2563
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
2564
|
-
|
|
2565
|
-
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
2566
|
-
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
2567
|
-
S extends `${infer First}${infer Rest}`
|
|
2568
|
-
? IsEqual<First, Char> extends true
|
|
2569
|
-
? 'found'
|
|
2570
|
-
: IncludesWithoutIf<Rest, Char>
|
|
2571
|
-
: 'not found';
|
|
2572
|
-
|
|
2573
|
-
// Now, instantiations with long strings will work
|
|
2574
|
-
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
2575
|
-
//=> 'not found'
|
|
2576
|
-
```
|
|
2577
|
-
|
|
2578
|
-
@category Type Guard
|
|
2579
|
-
@category Utilities
|
|
2580
|
-
*/
|
|
2581
|
-
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
2582
|
-
//#endregion
|
|
2583
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/type.d.ts
|
|
2584
|
-
/**
|
|
2585
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
2586
|
-
*/
|
|
2587
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
2588
|
-
/**
|
|
2589
|
-
Test if the given function has multiple call signatures.
|
|
2590
|
-
|
|
2591
|
-
Needed to handle the case of a single call signature with properties.
|
|
2592
|
-
|
|
2593
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
2594
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
2595
|
-
*/
|
|
2596
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
2597
|
-
(...arguments_: infer A): unknown;
|
|
2598
|
-
(...arguments_: infer B): unknown;
|
|
2599
|
-
} ? B extends A ? A extends B ? false : true : true : false;
|
|
2600
|
-
//#endregion
|
|
2601
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/simplify.d.ts
|
|
2602
|
-
/**
|
|
2603
|
-
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.
|
|
2604
|
-
|
|
2605
|
-
@example
|
|
2606
|
-
```
|
|
2607
|
-
import type {Simplify} from 'type-fest';
|
|
2608
|
-
|
|
2609
|
-
type PositionProps = {
|
|
2610
|
-
top: number;
|
|
2611
|
-
left: number;
|
|
2612
|
-
};
|
|
2613
|
-
|
|
2614
|
-
type SizeProps = {
|
|
2615
|
-
width: number;
|
|
2616
|
-
height: number;
|
|
2617
|
-
};
|
|
2618
|
-
|
|
2619
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
2620
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
2621
|
-
```
|
|
2622
|
-
|
|
2623
|
-
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
2624
|
-
|
|
2625
|
-
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
2626
|
-
|
|
2627
|
-
@example
|
|
2628
|
-
```
|
|
2629
|
-
import type {Simplify} from 'type-fest';
|
|
2630
|
-
|
|
2631
|
-
interface SomeInterface {
|
|
2632
|
-
foo: number;
|
|
2633
|
-
bar?: string;
|
|
2634
|
-
baz: number | undefined;
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
type SomeType = {
|
|
2638
|
-
foo: number;
|
|
2639
|
-
bar?: string;
|
|
2640
|
-
baz: number | undefined;
|
|
2641
|
-
};
|
|
2642
|
-
|
|
2643
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
2644
|
-
const someType: SomeType = literal;
|
|
2645
|
-
const someInterface: SomeInterface = literal;
|
|
2646
|
-
|
|
2647
|
-
function fn(object: Record<string, unknown>): void {}
|
|
2648
|
-
|
|
2649
|
-
fn(literal); // Good: literal object type is sealed
|
|
2650
|
-
fn(someType); // Good: type is sealed
|
|
2651
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
2652
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
2653
|
-
```
|
|
2654
|
-
|
|
2655
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
2656
|
-
@see {@link SimplifyDeep}
|
|
2657
|
-
@category Object
|
|
2658
|
-
*/
|
|
2659
|
-
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
2660
|
-
//#endregion
|
|
2661
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
2662
|
-
/**
|
|
2663
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
2664
|
-
|
|
2665
|
-
This is the counterpart of `PickIndexSignature`.
|
|
2666
|
-
|
|
2667
|
-
Use-cases:
|
|
2668
|
-
- Remove overly permissive signatures from third-party types.
|
|
2669
|
-
|
|
2670
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
2671
|
-
|
|
2672
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
2673
|
-
|
|
2674
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
2675
|
-
|
|
2676
|
-
```
|
|
2677
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
2678
|
-
|
|
2679
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
2680
|
-
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
2681
|
-
```
|
|
2682
|
-
|
|
2683
|
-
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
2684
|
-
|
|
2685
|
-
```
|
|
2686
|
-
type Indexed = {} extends Record<string, unknown>
|
|
2687
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
2688
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
2689
|
-
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
2690
|
-
|
|
2691
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
2692
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
2693
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
2694
|
-
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
2695
|
-
```
|
|
2696
|
-
|
|
2697
|
-
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
2698
|
-
|
|
2699
|
-
```
|
|
2700
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
2701
|
-
|
|
2702
|
-
type OmitIndexSignature<ObjectType> = {
|
|
2703
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
2704
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
2705
|
-
};
|
|
2706
|
-
```
|
|
2707
|
-
|
|
2708
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
2709
|
-
|
|
2710
|
-
```
|
|
2711
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
2712
|
-
|
|
2713
|
-
type OmitIndexSignature<ObjectType> = {
|
|
2714
|
-
[KeyType in keyof ObjectType
|
|
2715
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
2716
|
-
as {} extends Record<KeyType, unknown>
|
|
2717
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
2718
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
2719
|
-
]: ObjectType[KeyType];
|
|
2720
|
-
};
|
|
2721
|
-
```
|
|
2722
|
-
|
|
2723
|
-
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
2724
|
-
|
|
2725
|
-
@example
|
|
2726
|
-
```
|
|
2727
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
2728
|
-
|
|
2729
|
-
interface Example {
|
|
2730
|
-
// These index signatures will be removed.
|
|
2731
|
-
[x: string]: any
|
|
2732
|
-
[x: number]: any
|
|
2733
|
-
[x: symbol]: any
|
|
2734
|
-
[x: `head-${string}`]: string
|
|
2735
|
-
[x: `${string}-tail`]: string
|
|
2736
|
-
[x: `head-${string}-tail`]: string
|
|
2737
|
-
[x: `${bigint}`]: string
|
|
2738
|
-
[x: `embedded-${number}`]: string
|
|
2739
|
-
|
|
2740
|
-
// These explicitly defined keys will remain.
|
|
2741
|
-
foo: 'bar';
|
|
2742
|
-
qux?: 'baz';
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
2746
|
-
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
2747
|
-
```
|
|
2748
|
-
|
|
2749
|
-
@see {@link PickIndexSignature}
|
|
2750
|
-
@category Object
|
|
2751
|
-
*/
|
|
2752
|
-
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
2753
|
-
//#endregion
|
|
2754
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
2755
|
-
/**
|
|
2756
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
2757
|
-
|
|
2758
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
2759
|
-
|
|
2760
|
-
@example
|
|
2761
|
-
```
|
|
2762
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
2763
|
-
|
|
2764
|
-
declare const symbolKey: unique symbol;
|
|
2765
|
-
|
|
2766
|
-
type Example = {
|
|
2767
|
-
// These index signatures will remain.
|
|
2768
|
-
[x: string]: unknown;
|
|
2769
|
-
[x: number]: unknown;
|
|
2770
|
-
[x: symbol]: unknown;
|
|
2771
|
-
[x: `head-${string}`]: string;
|
|
2772
|
-
[x: `${string}-tail`]: string;
|
|
2773
|
-
[x: `head-${string}-tail`]: string;
|
|
2774
|
-
[x: `${bigint}`]: string;
|
|
2775
|
-
[x: `embedded-${number}`]: string;
|
|
2776
|
-
|
|
2777
|
-
// These explicitly defined keys will be removed.
|
|
2778
|
-
['kebab-case-key']: string;
|
|
2779
|
-
[symbolKey]: string;
|
|
2780
|
-
foo: 'bar';
|
|
2781
|
-
qux?: 'baz';
|
|
2782
|
-
};
|
|
2783
|
-
|
|
2784
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
2785
|
-
// {
|
|
2786
|
-
// [x: string]: unknown;
|
|
2787
|
-
// [x: number]: unknown;
|
|
2788
|
-
// [x: symbol]: unknown;
|
|
2789
|
-
// [x: `head-${string}`]: string;
|
|
2790
|
-
// [x: `${string}-tail`]: string;
|
|
2791
|
-
// [x: `head-${string}-tail`]: string;
|
|
2792
|
-
// [x: `${bigint}`]: string;
|
|
2793
|
-
// [x: `embedded-${number}`]: string;
|
|
2794
|
-
// }
|
|
2795
|
-
```
|
|
2796
|
-
|
|
2797
|
-
@see {@link OmitIndexSignature}
|
|
2798
|
-
@category Object
|
|
2799
|
-
*/
|
|
2800
|
-
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
2801
|
-
//#endregion
|
|
2802
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/merge.d.ts
|
|
2803
|
-
// Merges two objects without worrying about index signatures.
|
|
2804
|
-
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
2805
|
-
|
|
2806
|
-
/**
|
|
2807
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
2808
|
-
|
|
2809
|
-
@example
|
|
2810
|
-
```
|
|
2811
|
-
import type {Merge} from 'type-fest';
|
|
2812
|
-
|
|
2813
|
-
interface Foo {
|
|
2814
|
-
[x: string]: unknown;
|
|
2815
|
-
[x: number]: unknown;
|
|
2816
|
-
foo: string;
|
|
2817
|
-
bar: symbol;
|
|
2818
|
-
}
|
|
2819
|
-
|
|
2820
|
-
type Bar = {
|
|
2821
|
-
[x: number]: number;
|
|
2822
|
-
[x: symbol]: unknown;
|
|
2823
|
-
bar: Date;
|
|
2824
|
-
baz: boolean;
|
|
2825
|
-
};
|
|
2826
|
-
|
|
2827
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
2828
|
-
// => {
|
|
2829
|
-
// [x: string]: unknown;
|
|
2830
|
-
// [x: number]: number;
|
|
2831
|
-
// [x: symbol]: unknown;
|
|
2832
|
-
// foo: string;
|
|
2833
|
-
// bar: Date;
|
|
2834
|
-
// baz: boolean;
|
|
2835
|
-
// }
|
|
2836
|
-
```
|
|
2837
|
-
|
|
2838
|
-
@category Object
|
|
2839
|
-
*/
|
|
2840
|
-
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
2841
|
-
//#endregion
|
|
2842
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/object.d.ts
|
|
2843
|
-
/**
|
|
2844
|
-
Merges user specified options with default options.
|
|
2845
|
-
|
|
2846
|
-
@example
|
|
2847
|
-
```
|
|
2848
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
2849
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
2850
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
2851
|
-
|
|
2852
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
2853
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
2854
|
-
```
|
|
2855
|
-
|
|
2856
|
-
@example
|
|
2857
|
-
```
|
|
2858
|
-
// Complains if default values are not provided for optional options
|
|
2859
|
-
|
|
2860
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
2861
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
2862
|
-
type SpecifiedOptions = {};
|
|
2863
|
-
|
|
2864
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
2865
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
2866
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
2867
|
-
```
|
|
2868
|
-
|
|
2869
|
-
@example
|
|
2870
|
-
```
|
|
2871
|
-
// Complains if an option's default type does not conform to the expected type
|
|
2872
|
-
|
|
2873
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
2874
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
2875
|
-
type SpecifiedOptions = {};
|
|
2876
|
-
|
|
2877
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
2878
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
2879
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
2880
|
-
```
|
|
2881
|
-
|
|
2882
|
-
@example
|
|
2883
|
-
```
|
|
2884
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
2885
|
-
|
|
2886
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
2887
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
2888
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
2889
|
-
|
|
2890
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
2891
|
-
// ~~~~~~~~~~~~~~~~
|
|
2892
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
2893
|
-
```
|
|
2894
|
-
*/
|
|
2895
|
-
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
2896
|
-
//#endregion
|
|
2897
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/partial-deep.d.ts
|
|
2898
|
-
/**
|
|
2899
|
-
@see {@link PartialDeep}
|
|
2900
|
-
*/
|
|
2901
|
-
type PartialDeepOptions = {
|
|
2902
|
-
/**
|
|
2903
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
2904
|
-
@default false
|
|
2905
|
-
*/
|
|
2906
|
-
readonly recurseIntoArrays?: boolean;
|
|
2907
|
-
|
|
2908
|
-
/**
|
|
2909
|
-
Allows `undefined` values in non-tuple arrays.
|
|
2910
|
-
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
2911
|
-
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
2912
|
-
@default false
|
|
2913
|
-
@example
|
|
2914
|
-
You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
|
|
2915
|
-
```
|
|
2916
|
-
import type {PartialDeep} from 'type-fest';
|
|
2917
|
-
type Settings = {
|
|
2918
|
-
languages: string[];
|
|
2919
|
-
};
|
|
2920
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
|
|
2921
|
-
partialSettings.languages = [undefined]; // OK
|
|
2922
|
-
```
|
|
2923
|
-
*/
|
|
2924
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
2925
|
-
};
|
|
2926
|
-
type DefaultPartialDeepOptions = {
|
|
2927
|
-
recurseIntoArrays: false;
|
|
2928
|
-
allowUndefinedInNonTupleArrays: false;
|
|
2929
|
-
};
|
|
2930
|
-
|
|
2931
|
-
/**
|
|
2932
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
2933
|
-
|
|
2934
|
-
Use-cases:
|
|
2935
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
2936
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
2937
|
-
|
|
2938
|
-
@example
|
|
2939
|
-
```
|
|
2940
|
-
import type {PartialDeep} from 'type-fest';
|
|
2941
|
-
|
|
2942
|
-
let settings = {
|
|
2943
|
-
textEditor: {
|
|
2944
|
-
fontSize: 14,
|
|
2945
|
-
fontColor: '#000000',
|
|
2946
|
-
fontWeight: 400,
|
|
2947
|
-
},
|
|
2948
|
-
autocomplete: false,
|
|
2949
|
-
autosave: true,
|
|
2950
|
-
};
|
|
2951
|
-
|
|
2952
|
-
const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
|
|
2953
|
-
{...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
|
|
2954
|
-
);
|
|
2955
|
-
|
|
2956
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
2957
|
-
```
|
|
2958
|
-
|
|
2959
|
-
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
2960
|
-
|
|
2961
|
-
```
|
|
2962
|
-
import type {PartialDeep} from 'type-fest';
|
|
2963
|
-
|
|
2964
|
-
type Shape = {
|
|
2965
|
-
dimensions: [number, number];
|
|
2966
|
-
};
|
|
2967
|
-
|
|
2968
|
-
const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
|
|
2969
|
-
dimensions: [], // OK
|
|
2970
|
-
};
|
|
2971
|
-
|
|
2972
|
-
partialShape.dimensions = [15]; // OK
|
|
2973
|
-
```
|
|
2974
|
-
|
|
2975
|
-
@see {@link PartialDeepOptions}
|
|
2976
|
-
|
|
2977
|
-
@category Object
|
|
2978
|
-
@category Array
|
|
2979
|
-
@category Set
|
|
2980
|
-
@category Map
|
|
2981
|
-
*/
|
|
2982
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
2983
|
-
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? 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 ((...arguments_: any[]) => unknown) ? IsNever<keyof T> extends true ? T // For functions with no properties
|
|
2984
|
-
: HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
2985
|
-
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
2986
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
2987
|
-
? 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
|
|
2988
|
-
: T // If they don't opt into array testing, just use the original type
|
|
2989
|
-
: PartialObjectDeep<T, Options> : unknown;
|
|
2990
|
-
|
|
2991
|
-
/**
|
|
2992
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
2993
|
-
*/
|
|
2994
|
-
type PartialMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
2995
|
-
|
|
2996
|
-
/**
|
|
2997
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
2998
|
-
*/
|
|
2999
|
-
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
3000
|
-
|
|
3001
|
-
/**
|
|
3002
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
3003
|
-
*/
|
|
3004
|
-
type PartialReadonlyMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
3008
|
-
*/
|
|
3009
|
-
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
3010
|
-
|
|
3011
|
-
/**
|
|
3012
|
-
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
3013
|
-
*/
|
|
3014
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = { [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> };
|
|
3015
|
-
//#endregion
|
|
3016
|
-
//#region src/types/core.types.d.ts
|
|
3017
|
-
type RegleSchema<TState$1 extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
6
|
+
import { EmptyObject, PartialDeep } from "type-fest";
|
|
7
|
+
type RegleSchema<TState extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
3018
8
|
/**
|
|
3019
9
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
3020
10
|
*
|
|
3021
11
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
3022
12
|
*/
|
|
3023
|
-
r$: Raw<RegleSchemaStatus<TState
|
|
13
|
+
r$: Raw<RegleSchemaStatus<TState, TShortcuts, true>>;
|
|
3024
14
|
} & TAdditionalReturnProperties;
|
|
3025
|
-
type RegleSingleFieldSchema<TState
|
|
15
|
+
type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
3026
16
|
/**
|
|
3027
17
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
3028
18
|
*
|
|
3029
19
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
3030
20
|
*/
|
|
3031
|
-
r$: Raw<RegleSchemaFieldStatus<TState
|
|
21
|
+
r$: Raw<RegleSchemaFieldStatus<TState, TShortcuts> & {
|
|
3032
22
|
/** 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). */
|
|
3033
|
-
$validate: (forceValues?: TState
|
|
23
|
+
$validate: (forceValues?: TState extends EmptyObject ? any : HasNamedKeys<TState> extends true ? TState : any) => Promise<RegleSchemaResult<TState>>;
|
|
3034
24
|
}>;
|
|
3035
25
|
} & TAdditionalReturnProperties;
|
|
3036
26
|
type RegleSchemaResult<TSchema extends unknown> = {
|
|
@@ -3044,37 +34,37 @@ type RegleSchemaResult<TSchema extends unknown> = {
|
|
|
3044
34
|
issues: EmptyObject;
|
|
3045
35
|
errors: EmptyObject;
|
|
3046
36
|
};
|
|
3047
|
-
type ProcessNestedFields<TState
|
|
37
|
+
type ProcessNestedFields<TState extends Record<string, any>, TShortcuts extends RegleShortcutDefinition> = HasNamedKeys<TState> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TState> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TState>[TKey]>, TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TState> ? JoinDiscriminatedUnions<TState>[TKey] extends NonNullable<JoinDiscriminatedUnions<TState>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TState> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TState>[TKey]>, TShortcuts> : never } : {};
|
|
3048
38
|
/**
|
|
3049
39
|
* @public
|
|
3050
40
|
*/
|
|
3051
|
-
type RegleSchemaStatus<TState
|
|
41
|
+
type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
|
|
3052
42
|
/** 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. */
|
|
3053
|
-
readonly $fields: ProcessNestedFields<TState
|
|
43
|
+
readonly $fields: ProcessNestedFields<TState, TShortcuts>;
|
|
3054
44
|
/** Collection of all issues, collected for all children properties and nested forms.
|
|
3055
45
|
*
|
|
3056
46
|
* Only contains errors from properties where $dirty equals true. */
|
|
3057
|
-
readonly $issues: RegleIssuesTree<TState
|
|
47
|
+
readonly $issues: RegleIssuesTree<TState>;
|
|
3058
48
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3059
49
|
*
|
|
3060
50
|
* Only contains errors from properties where $dirty equals true. */
|
|
3061
|
-
readonly $errors: RegleErrorTree<TState
|
|
51
|
+
readonly $errors: RegleErrorTree<TState>;
|
|
3062
52
|
/** Collection of all the error messages, collected for all children properties. */
|
|
3063
|
-
readonly $silentErrors: RegleErrorTree<TState
|
|
53
|
+
readonly $silentErrors: RegleErrorTree<TState>;
|
|
3064
54
|
/** 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). */
|
|
3065
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
3066
|
-
} & ProcessNestedFields<TState
|
|
55
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
56
|
+
} & ProcessNestedFields<TState, TShortcuts> & (IsRoot extends true ? {
|
|
3067
57
|
/** 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). */
|
|
3068
|
-
$validate: (forceValues?: TState
|
|
58
|
+
$validate: (forceValues?: TState extends EmptyObject ? (HasNamedKeys<TState> extends true ? TState : any) : TState) => Promise<RegleSchemaResult<TState>>;
|
|
3069
59
|
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
3070
60
|
/**
|
|
3071
61
|
* @public
|
|
3072
62
|
*/
|
|
3073
|
-
type InferRegleSchemaStatusType<TState
|
|
63
|
+
type InferRegleSchemaStatusType<TState extends unknown, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState> extends Array<infer A> ? A extends Record<string, any> ? RegleSchemaCollectionStatus<NonNullable<TState>, TShortcuts> : RegleSchemaFieldStatus<TState, TShortcuts> : NonNullable<TState> extends Date | File ? RegleSchemaFieldStatus<TState, TShortcuts> : unknown extends TState ? RegleSchemaFieldStatus<TState extends EmptyObject ? unknown : TState, TShortcuts> : NonNullable<TState> extends Record<string, any> ? RegleSchemaStatus<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TShortcuts> : RegleSchemaFieldStatus<TState, TShortcuts>;
|
|
3074
64
|
/**
|
|
3075
65
|
* @public
|
|
3076
66
|
*/
|
|
3077
|
-
type RegleSchemaFieldStatus<TState
|
|
67
|
+
type RegleSchemaFieldStatus<TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
|
|
3078
68
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3079
69
|
*
|
|
3080
70
|
* Only contains errors from properties where $dirty equals true. */
|
|
@@ -3095,36 +85,34 @@ type RegleSchemaFieldStatus<TState$1 = any, TShortcuts extends RegleShortcutDefi
|
|
|
3095
85
|
readonly $inactive: boolean;
|
|
3096
86
|
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
3097
87
|
readonly $rules: {
|
|
3098
|
-
[`~validator`]: RegleRuleStatus<TState
|
|
88
|
+
[`~validator`]: RegleRuleStatus<TState, []>;
|
|
3099
89
|
};
|
|
3100
90
|
/** 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). */
|
|
3101
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
91
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3102
92
|
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
3103
93
|
/**
|
|
3104
94
|
* @public
|
|
3105
95
|
*/
|
|
3106
|
-
type RegleSchemaCollectionStatus<TState
|
|
96
|
+
type RegleSchemaCollectionStatus<TState extends any[], TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TState, TShortcuts>, '$errors' | '$silentErrors' | '$validate'> & {
|
|
3107
97
|
/** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */
|
|
3108
|
-
readonly $each: Array<InferRegleSchemaStatusType<ArrayElement<TState
|
|
98
|
+
readonly $each: Array<InferRegleSchemaStatusType<ArrayElement<TState>, TShortcuts>>;
|
|
3109
99
|
/** 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. */
|
|
3110
|
-
readonly $self: RegleSchemaFieldStatus<TState
|
|
100
|
+
readonly $self: RegleSchemaFieldStatus<TState, TShortcuts>;
|
|
3111
101
|
/**
|
|
3112
102
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
3113
103
|
*
|
|
3114
104
|
* Only contains issues from properties where $dirty equals true.
|
|
3115
105
|
*/
|
|
3116
|
-
readonly $issues: RegleCollectionErrors<TState
|
|
106
|
+
readonly $issues: RegleCollectionErrors<TState, true>;
|
|
3117
107
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3118
108
|
*
|
|
3119
109
|
* Only contains errors from properties where $dirty equals true. */
|
|
3120
|
-
readonly $errors: RegleCollectionErrors<TState
|
|
110
|
+
readonly $errors: RegleCollectionErrors<TState>;
|
|
3121
111
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
3122
|
-
readonly $silentErrors: RegleCollectionErrors<TState
|
|
112
|
+
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
3123
113
|
/** 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). */
|
|
3124
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
114
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3125
115
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
3126
|
-
//#endregion
|
|
3127
|
-
//#region src/types/options.types.d.ts
|
|
3128
116
|
type RegleSchemaBehaviourOptions = {
|
|
3129
117
|
/**
|
|
3130
118
|
* Settings for applying transforms and default to the current state
|
|
@@ -3140,15 +128,13 @@ type RegleSchemaBehaviourOptions = {
|
|
|
3140
128
|
onValidate?: boolean;
|
|
3141
129
|
};
|
|
3142
130
|
};
|
|
3143
|
-
//#endregion
|
|
3144
|
-
//#region src/core/useRegleSchema.d.ts
|
|
3145
131
|
type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
|
|
3146
132
|
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
3147
|
-
<TSchema extends StandardSchemaV1, TState
|
|
133
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<NoInferLegacy<TState>, {
|
|
3148
134
|
recurseIntoArrays: true;
|
|
3149
|
-
}>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState
|
|
135
|
+
}>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState>, {
|
|
3150
136
|
recurseIntoArrays: true;
|
|
3151
|
-
}>>, rulesFactory: MaybeRef<TSchema>, ...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])]): NonNullable<TState
|
|
137
|
+
}>>, rulesFactory: MaybeRef<TSchema>, ...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, TShortcuts, TAdditionalReturnProperties>;
|
|
3152
138
|
}
|
|
3153
139
|
/**
|
|
3154
140
|
* useRegle serves as the foundation for validation logic.
|
|
@@ -3170,8 +156,6 @@ interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = nev
|
|
|
3170
156
|
* Docs: {@link https://reglejs.dev/integrations/schemas-libraries}
|
|
3171
157
|
*/
|
|
3172
158
|
declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
3173
|
-
//#endregion
|
|
3174
|
-
//#region src/core/withDeps.d.ts
|
|
3175
159
|
/**
|
|
3176
160
|
*
|
|
3177
161
|
* Force dependency on any RPC schema
|
|
@@ -3188,13 +172,11 @@ declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {},
|
|
|
3188
172
|
* useRegleSchema({name: ''}, schema)
|
|
3189
173
|
* ```
|
|
3190
174
|
*/
|
|
3191
|
-
declare function withDeps<TSchema extends StandardSchemaV1, TParams
|
|
3192
|
-
//#endregion
|
|
3193
|
-
//#region src/core/inferSchema.d.ts
|
|
175
|
+
declare function withDeps<TSchema extends StandardSchemaV1, TParams extends unknown[] = []>(schema: TSchema, _depsArray: [...TParams]): TSchema;
|
|
3194
176
|
interface inferSchemaFn {
|
|
3195
|
-
<TSchema extends StandardSchemaV1, TState
|
|
177
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(state: MaybeRef<PartialDeep<TState, {
|
|
3196
178
|
recurseIntoArrays: true;
|
|
3197
|
-
}>> | DeepReactiveState<PartialDeep<TState
|
|
179
|
+
}>> | DeepReactiveState<PartialDeep<TState, {
|
|
3198
180
|
recurseIntoArrays: true;
|
|
3199
181
|
}>>, rulesFactory: MaybeRef<TSchema>): NoInferLegacy<TSchema>;
|
|
3200
182
|
}
|
|
@@ -3206,8 +188,6 @@ interface inferSchemaFn {
|
|
|
3206
188
|
* @param schema - Your schema
|
|
3207
189
|
*/
|
|
3208
190
|
declare const inferSchema: inferSchemaFn;
|
|
3209
|
-
//#endregion
|
|
3210
|
-
//#region src/core/defineRegleSchemaConfig.d.ts
|
|
3211
191
|
/**
|
|
3212
192
|
* Define a global regle configuration, where you can:
|
|
3213
193
|
* - Define global modifiers
|
|
@@ -3228,8 +208,6 @@ declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinit
|
|
|
3228
208
|
useRegleSchema: useRegleSchemaFn<TShortcuts>;
|
|
3229
209
|
inferSchema: inferSchemaFn;
|
|
3230
210
|
};
|
|
3231
|
-
//#endregion
|
|
3232
|
-
//#region src/core/createScopedUseRegleSchema.d.ts
|
|
3233
211
|
type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any, any>, TAsRecord extends boolean> = Omit<CreateScopedUseRegleOptions<any, TAsRecord>, 'customUseRegle'> & {
|
|
3234
212
|
/**
|
|
3235
213
|
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
@@ -3237,8 +215,8 @@ type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any
|
|
|
3237
215
|
customUseRegle?: TCustomRegle;
|
|
3238
216
|
};
|
|
3239
217
|
declare const useCollectSchemaScope: <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string>) => {
|
|
3240
|
-
r$: MergedScopedRegles<TValue$1>;
|
|
3241
|
-
}, useScopedRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
218
|
+
r$: _regle_core0.MergedScopedRegles<TValue$1>;
|
|
219
|
+
}, useScopedRegleSchema: useRegleSchemaFn<_regle_core0.RegleShortcutDefinition<any>, {}, {}>;
|
|
3242
220
|
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TAsRecord extends boolean = false, TReturnedRegle extends useRegleSchemaFn<any, any, any> = (TCustomRegle extends useRegleSchemaFn<infer S> ? useRegleSchemaFn<S, {
|
|
3243
221
|
dispose: () => void;
|
|
3244
222
|
register: () => void;
|
|
@@ -3249,5 +227,4 @@ declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn
|
|
|
3249
227
|
useScopedRegle: TReturnedRegle;
|
|
3250
228
|
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
3251
229
|
};
|
|
3252
|
-
//#endregion
|
|
3253
230
|
export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaBehaviourOptions, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
|