@regle/schemas 1.11.0-beta.1 → 1.11.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/regle-schemas.d.ts +37 -4496
- package/dist/regle-schemas.js +2 -24
- package/package.json +11 -16
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,4472 +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 {
|
|
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$1> = T$1 extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
8
|
-
type Maybe<T$1 = any> = T$1 | null | undefined;
|
|
9
|
-
type MaybeInput<T$1 = any> = T$1 | null | undefined;
|
|
10
|
-
type MaybeOutput<T$1 = any> = T$1 | undefined;
|
|
11
|
-
type NonUndefined<T$1> = Exclude<T$1, undefined>;
|
|
12
|
-
type PromiseReturn<T$1> = T$1 extends Promise<infer U> ? U : T$1;
|
|
13
|
-
type MaybeGetter<T$1, V$1 = any, TAdd extends Record<string, any> = {}> = T$1 | ((value: Ref<V$1>, index: number) => T$1 & TAdd);
|
|
14
|
-
type Unwrap<T$1 extends MaybeRef<Record<string, any>>> = T$1 extends Ref ? UnwrapRef<T$1> : UnwrapNestedRefs<T$1>;
|
|
15
|
-
type ExtractFromGetter<T$1 extends MaybeGetter<any, any, any>> = T$1 extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T$1;
|
|
16
|
-
type ExtendOnlyRealRecord<T$1 extends unknown> = NonNullable<T$1> extends File | Date ? false : NonNullable<T$1> extends Record<string, any> ? true : false;
|
|
17
|
-
type OmitByType<T$1 extends Record<string, any>, U$1> = { [K in keyof T$1 as T$1[K] extends U$1 ? never : K]: T$1[K] };
|
|
18
|
-
type DeepMaybeRef<T$1 extends Record<string, any>> = { [K in keyof T$1]: MaybeRef<T$1[K]> };
|
|
19
|
-
type ExcludeByType<T$1, U$1> = { [K in keyof T$1 as T$1[K] extends U$1 ? never : K]: T$1[K] extends U$1 ? never : T$1[K] };
|
|
20
|
-
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
21
|
-
type isRecordLiteral<T$1 extends unknown> = NonNullable<T$1> extends Date | File ? false : NonNullable<T$1> 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$1> = T$1 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$1> = T$1 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$1> = 0 extends 1 & NoInfer<T$1> ? 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$1> = [T$1] 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$1 extends (...arguments_: any[]) => unknown> = T$1 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$1, IfNotAnyOrNever$1, IfAny = any, IfNever = never> = If$1<IsAny$1<T$1>, IfAny, If$1<IsNever$1<T$1>, 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$1> = [T$1] 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$1> = (unknown extends T$1 // `T` can be `unknown` or `any`
|
|
555
|
-
? IsNull<T$1> 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$1> = { [KeyType in keyof T$1]: T$1[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$1, Options extends PartialDeepOptions$1 = {}> = _PartialDeep$1<T$1, ApplyDefaultOptions$1<PartialDeepOptions$1, DefaultPartialDeepOptions$1, Options>>;
|
|
1113
|
-
type _PartialDeep$1<T$1, Options extends Required<PartialDeepOptions$1>> = T$1 extends BuiltIns$1 | ((new (...arguments_: any[]) => unknown)) ? T$1 : T$1 extends Map<infer KeyType, infer ValueType> ? PartialMapDeep$1<KeyType, ValueType, Options> : T$1 extends Set<infer ItemType> ? PartialSetDeep$1<ItemType, Options> : T$1 extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep$1<KeyType, ValueType, Options> : T$1 extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep$1<ItemType, Options> : T$1 extends ((...arguments_: any[]) => unknown) ? IsNever$1<keyof T$1> extends true ? T$1 // For functions with no properties
|
|
1114
|
-
: HasMultipleCallSignatures$1<T$1> extends true ? T$1 : ((...arguments_: Parameters<T$1>) => ReturnType<T$1>) & PartialObjectDeep$1<T$1, Options> : T$1 extends object ? T$1 extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
1115
|
-
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T$1 // Test for arrays (non-tuples) specifically
|
|
1116
|
-
? readonly ItemType[] extends T$1 // 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$1, Options> // Tuples behave properly
|
|
1118
|
-
: T$1 // If they don't opt into array testing, just use the original type
|
|
1119
|
-
: PartialObjectDeep$1<T$1, 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$1, Options extends Required<PartialDeepOptions$1>> = {} & Set<_PartialDeep$1<T$1, 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$1, Options extends Required<PartialDeepOptions$1>> = {} & ReadonlySet<_PartialDeep$1<T$1, 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$1> = UnionToIntersection<T$1 extends any ? () => T$1 : 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$1, L = LastOfUnion<T$1>> = IsNever$1<T$1> extends false ? [...UnionToTuple<Exclude<T$1, 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
|
-
* A unique identifier for the Regle instance in the devtools.
|
|
1277
|
-
* @default undefined
|
|
1278
|
-
*/
|
|
1279
|
-
id?: string | undefined;
|
|
1280
|
-
}
|
|
1281
|
-
interface LocalRegleBehaviourOptions<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
|
|
1282
|
-
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState$1>> | Record<string, string[]>>;
|
|
1283
|
-
validationGroups?: (fields: RegleStatus<TState$1, TRules$1>['$fields']) => TValidationGroups;
|
|
1284
|
-
}
|
|
1285
|
-
type RegleValidationGroupEntry = RegleFieldStatus<any, any> | undefined;
|
|
1286
|
-
interface RegleValidationGroupOutput {
|
|
1287
|
-
$invalid: boolean;
|
|
1288
|
-
$error: boolean;
|
|
1289
|
-
$pending: boolean;
|
|
1290
|
-
$dirty: boolean;
|
|
1291
|
-
$correct: boolean;
|
|
1292
|
-
$errors: string[];
|
|
1293
|
-
$silentErrors: string[];
|
|
1294
|
-
}
|
|
1295
|
-
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
1296
|
-
/**
|
|
1297
|
-
* Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
|
|
1298
|
-
*/
|
|
1299
|
-
$debounce?: number;
|
|
1300
|
-
};
|
|
1301
|
-
type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
|
|
1302
|
-
/**
|
|
1303
|
-
* Allow deep compare of array children to compute the `$edited` property
|
|
1304
|
-
*
|
|
1305
|
-
* Disabled by default for performance
|
|
1306
|
-
*
|
|
1307
|
-
* @default false
|
|
1308
|
-
* */
|
|
1309
|
-
$deepCompare?: boolean;
|
|
1310
|
-
};
|
|
1311
|
-
type ShortcutCommonFn<T$1 extends Record<string, any>> = {
|
|
1312
|
-
[x: string]: (element: Omit<OmitByType<T$1, Function>, '~standard'>) => unknown;
|
|
1313
|
-
};
|
|
1314
|
-
type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
|
|
1315
|
-
/**
|
|
1316
|
-
* Allow you to customize the properties for every field
|
|
1317
|
-
*/
|
|
1318
|
-
fields?: ShortcutCommonFn<RegleFieldStatus<any, Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1319
|
-
/**
|
|
1320
|
-
* Allow you to customize the properties for every parent of a nested object
|
|
1321
|
-
*/
|
|
1322
|
-
nested?: ShortcutCommonFn<RegleStatus<Record<string, any>, ReglePartialRuleTree<any, Partial<TCustomRules> & Partial<DefaultValidators>>>>;
|
|
1323
|
-
/**
|
|
1324
|
-
* Allow you to customize the properties for every parent of a collection
|
|
1325
|
-
*/
|
|
1326
|
-
collections?: ShortcutCommonFn<RegleCollectionStatus<any[], Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1327
|
-
};
|
|
1328
|
-
type AddDollarToOptions<T$1 extends Record<string, any>> = { [K in keyof T$1 as `$${string & K}`]: T$1[K] };
|
|
1329
|
-
//#endregion
|
|
1330
|
-
//#region src/types/core/useRegle.types.d.ts
|
|
1331
|
-
/**
|
|
1332
|
-
* The main Regle type that represents a complete validation instance.
|
|
1333
|
-
*
|
|
1334
|
-
* @template TState - The shape of the state object being validated
|
|
1335
|
-
* @template TRules - The validation rules tree for the state
|
|
1336
|
-
* @template TValidationGroups - Groups of validation rules that can be run together
|
|
1337
|
-
* @template TShortcuts - Custom shortcut definitions for common validation patterns
|
|
1338
|
-
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
1339
|
-
*
|
|
1340
|
-
*/
|
|
1341
|
-
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> = {}> = {
|
|
1342
|
-
/**
|
|
1343
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1344
|
-
*
|
|
1345
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1346
|
-
*/
|
|
1347
|
-
r$: Raw<RegleRoot<TState$1, TRules$1, TValidationGroups, TShortcuts>>;
|
|
1348
|
-
} & TAdditionalReturnProperties;
|
|
1349
|
-
/**
|
|
1350
|
-
* The type for a single field validation instance.
|
|
1351
|
-
*
|
|
1352
|
-
* @template TState - The type of the state value being validated
|
|
1353
|
-
* @template TRules - The validation rules for the field
|
|
1354
|
-
* @template TShortcuts - Custom shortcut definitions for common validation patterns
|
|
1355
|
-
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
1356
|
-
*/
|
|
1357
|
-
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> = {}> = {
|
|
1358
|
-
/**
|
|
1359
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1360
|
-
*
|
|
1361
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1362
|
-
*/
|
|
1363
|
-
r$: Raw<RegleFieldStatus<TState$1, TRules$1, TShortcuts>>;
|
|
1364
|
-
} & TAdditionalReturnProperties;
|
|
1365
|
-
type DeepReactiveState<T$1 extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T$1> extends true ? { [K in keyof T$1]: InferDeepReactiveState<T$1[K]> } : never;
|
|
1366
|
-
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>;
|
|
1367
|
-
//#endregion
|
|
1368
|
-
//#region src/types/core/reset.types.d.ts
|
|
1369
|
-
type ResetOptions<TState$1 extends unknown> = RequireOneOrNone<{
|
|
1370
|
-
/**
|
|
1371
|
-
* Reset validation status and reset form state to its initial state.
|
|
1372
|
-
*
|
|
1373
|
-
* Initial state is different than the original state as the initial state can be mutated when using `$reset`.
|
|
1374
|
-
*
|
|
1375
|
-
* This serve as the base comparison state for `$edited` property.
|
|
1376
|
-
*
|
|
1377
|
-
* ⚠️ This doesn't work if the state is a `reactive` object.
|
|
1378
|
-
*/
|
|
1379
|
-
toInitialState?: boolean;
|
|
1380
|
-
/**
|
|
1381
|
-
* Reset validation status and reset form state to its original state.
|
|
1382
|
-
*
|
|
1383
|
-
* Original state is the unmutated state that was passed to the form when it was initialized.
|
|
1384
|
-
*/
|
|
1385
|
-
toOriginalState?: boolean;
|
|
1386
|
-
/**
|
|
1387
|
-
* Reset validation status and reset form state to the given state
|
|
1388
|
-
* Also set the new state as the initial state.
|
|
1389
|
-
*/
|
|
1390
|
-
toState?: TState$1 | (() => TState$1);
|
|
1391
|
-
/**
|
|
1392
|
-
* Clears the $externalErrors state back to an empty object.
|
|
1393
|
-
*
|
|
1394
|
-
* @default false
|
|
1395
|
-
*/
|
|
1396
|
-
clearExternalErrors?: boolean;
|
|
1397
|
-
/**
|
|
1398
|
-
* Keep the validation state of the form ($dirty, $invalid, $pending etc..)
|
|
1399
|
-
* Only useful if you only want to reset the form state.
|
|
1400
|
-
*
|
|
1401
|
-
* @default false
|
|
1402
|
-
*/
|
|
1403
|
-
keepValidationState?: boolean;
|
|
1404
|
-
}, 'toInitialState' | 'toState'>;
|
|
1405
|
-
//#endregion
|
|
1406
|
-
//#region src/types/core/scopedRegle.types.d.ts
|
|
1407
|
-
type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
|
|
1408
|
-
'~~global': Record<string, SuperCompatibleRegleRoot>;
|
|
1409
|
-
};
|
|
1410
|
-
type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
1411
|
-
//#endregion
|
|
1412
|
-
//#region src/types/core/results.types.d.ts
|
|
1413
|
-
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]> }>;
|
|
1414
|
-
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
|
|
1415
|
-
valid: false;
|
|
1416
|
-
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;
|
|
1417
|
-
} | {
|
|
1418
|
-
valid: true;
|
|
1419
|
-
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;
|
|
1420
|
-
};
|
|
1421
|
-
type RegleNestedResult<Data extends Record<string, any> | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
1422
|
-
valid: false;
|
|
1423
|
-
issues: RegleIssuesTree<Data>;
|
|
1424
|
-
errors: RegleErrorTree<Data>;
|
|
1425
|
-
} | {
|
|
1426
|
-
valid: true;
|
|
1427
|
-
issues: EmptyObject$1;
|
|
1428
|
-
errors: EmptyObject$1;
|
|
1429
|
-
});
|
|
1430
|
-
type RegleCollectionResult<Data extends any[], TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
1431
|
-
valid: false;
|
|
1432
|
-
issues: RegleCollectionErrors<Data, true>;
|
|
1433
|
-
errors: RegleCollectionErrors<Data>;
|
|
1434
|
-
} | {
|
|
1435
|
-
valid: true;
|
|
1436
|
-
issues: EmptyObject$1;
|
|
1437
|
-
errors: EmptyObject$1;
|
|
1438
|
-
});
|
|
1439
|
-
type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & {
|
|
1440
|
-
issues: RegleFieldIssue<TRules$1>[];
|
|
1441
|
-
errors: string[];
|
|
1442
|
-
};
|
|
1443
|
-
/**
|
|
1444
|
-
* Infer safe output from any `r$` instance
|
|
1445
|
-
*
|
|
1446
|
-
* ```ts
|
|
1447
|
-
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
1448
|
-
* ```
|
|
1449
|
-
*/
|
|
1450
|
-
|
|
1451
|
-
type $InternalRegleResult = {
|
|
1452
|
-
valid: boolean;
|
|
1453
|
-
data: any;
|
|
1454
|
-
errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
|
|
1455
|
-
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
1456
|
-
};
|
|
1457
|
-
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;
|
|
1458
|
-
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;
|
|
1459
|
-
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;
|
|
1460
|
-
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;
|
|
1461
|
-
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;
|
|
1462
|
-
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;
|
|
1463
|
-
type SafeFieldProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState$1> : MaybeOutput<TState$1>;
|
|
1464
|
-
//#endregion
|
|
1465
|
-
//#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/utils.d.ts
|
|
1466
|
-
/**
|
|
1467
|
-
* Negates a boolean type.
|
|
1468
|
-
*/
|
|
1469
|
-
type Not<T$1 extends boolean> = T$1 extends true ? false : true;
|
|
1470
|
-
/**
|
|
1471
|
-
* Checks if the given type is `never`.
|
|
1472
|
-
*/
|
|
1473
|
-
type IsNever$2<T$1> = [T$1] extends [never] ? true : false;
|
|
1474
|
-
/**
|
|
1475
|
-
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
|
|
1476
|
-
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
|
|
1477
|
-
* 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`.
|
|
1478
|
-
*/
|
|
1479
|
-
type Extends<Left, Right> = IsNever$2<Left> extends true ? IsNever$2<Right> : [Left] extends [Right] ? true : false;
|
|
1480
|
-
/**
|
|
1481
|
-
* Convert a union to an intersection.
|
|
1482
|
-
* `A | B | C` -\> `A & B & C`
|
|
1483
|
-
*/
|
|
1484
|
-
type UnionToIntersection$1<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection : never;
|
|
1485
|
-
/**
|
|
1486
|
-
* Get the last element of a union.
|
|
1487
|
-
* First, converts to a union of `() => T` functions,
|
|
1488
|
-
* then uses {@linkcode UnionToIntersection} to get the last one.
|
|
1489
|
-
*/
|
|
1490
|
-
type LastOf<Union> = UnionToIntersection$1<Union extends any ? () => Union : never> extends (() => infer R) ? R : never;
|
|
1491
|
-
/**
|
|
1492
|
-
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
|
1493
|
-
* "last" union member to the end of a tuple, and recursively prepends
|
|
1494
|
-
* the remainder of the union.
|
|
1495
|
-
*/
|
|
1496
|
-
type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever$2<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
|
|
1497
|
-
/**
|
|
1498
|
-
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
|
1499
|
-
*/
|
|
1500
|
-
type UnionToTuple$1<Union> = TuplifyUnion<Union>;
|
|
1501
|
-
type IsUnion<T$1> = Not<Extends<UnionToTuple$1<T$1>['length'], 1>>;
|
|
1502
|
-
//#endregion
|
|
1503
|
-
//#region src/types/core/variants.types.d.ts
|
|
1504
|
-
|
|
1505
|
-
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'> & {
|
|
1506
|
-
$fields: ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>];
|
|
1507
|
-
} & (HasNamedKeys<TState$1> extends true ? ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>] : {}) : RegleStatus<TState$1, TRules$1, TShortcuts>;
|
|
1508
|
-
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> } : {} };
|
|
1509
|
-
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> : [];
|
|
1510
|
-
//#endregion
|
|
1511
|
-
//#region src/core/useRegle/useRegle.d.ts
|
|
1512
|
-
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;
|
|
1513
|
-
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1514
|
-
<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>;
|
|
1515
|
-
__config?: {
|
|
1516
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
1517
|
-
modifiers?: RegleBehaviourOptions;
|
|
1518
|
-
shortcuts?: TShortcuts;
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* useRegle serves as the foundation for validation logic.
|
|
1523
|
-
*
|
|
1524
|
-
* It accepts the following inputs:
|
|
1525
|
-
*
|
|
1526
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
1527
|
-
* @param rules - These should align with the structure of your state.
|
|
1528
|
-
* @param modifiers - Customize regle behaviour
|
|
1529
|
-
*
|
|
1530
|
-
* ```ts
|
|
1531
|
-
* import { useRegle } from '@regle/core';
|
|
1532
|
-
import { required } from '@regle/rules';
|
|
1533
|
-
|
|
1534
|
-
const { r$ } = useRegle({ email: '' }, {
|
|
1535
|
-
email: { required }
|
|
1536
|
-
})
|
|
1537
|
-
* ```
|
|
1538
|
-
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1539
|
-
*/
|
|
1540
|
-
|
|
1541
|
-
//#endregion
|
|
1542
|
-
//#region src/types/utils/mismatch.types.d.ts
|
|
1543
|
-
/**
|
|
1544
|
-
/**
|
|
1545
|
-
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
1546
|
-
* exactly matches the structure of type T, including all nested properties.
|
|
1547
|
-
*
|
|
1548
|
-
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
1549
|
-
*/
|
|
1550
|
-
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>}>`> };
|
|
1551
|
-
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] };
|
|
1552
|
-
type TypeError<Msg> = {
|
|
1553
|
-
[' TypeError']: Msg;
|
|
1554
|
-
};
|
|
1555
|
-
type Coerce<T$1> = `${T$1 & string}`;
|
|
1556
|
-
//#endregion
|
|
1557
|
-
//#region src/types/utils/object.types.d.ts
|
|
1558
|
-
type RemoveCommonKey<T$1 extends readonly any[], K$1 extends PropertyKey> = T$1 extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
|
|
1559
|
-
/**
|
|
1560
|
-
* Restore the optional properties (with ?) of a generated mapped object type
|
|
1561
|
-
*/
|
|
1562
|
-
|
|
1563
|
-
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
1564
|
-
/**
|
|
1565
|
-
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
1566
|
-
*/
|
|
1567
|
-
type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
|
|
1568
|
-
/**
|
|
1569
|
-
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
1570
|
-
*/
|
|
1571
|
-
type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
|
|
1572
|
-
/**
|
|
1573
|
-
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
1574
|
-
*/
|
|
1575
|
-
type RetrieveUnionUnknownValues<T$1 extends readonly any[], TKeys extends string> = T$1 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>] : [];
|
|
1576
|
-
/**
|
|
1577
|
-
* Get all possible keys from a union, even the ones present only on one union
|
|
1578
|
-
*/
|
|
1579
|
-
type RetrieveUnionUnknownKeysOf<T$1 extends readonly any[]> = T$1 extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
1580
|
-
/**
|
|
1581
|
-
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
1582
|
-
*/
|
|
1583
|
-
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
|
|
1584
|
-
/**
|
|
1585
|
-
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
1586
|
-
*/
|
|
1587
|
-
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;
|
|
1588
|
-
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;
|
|
1589
|
-
type EnumLike = {
|
|
1590
|
-
[k: string]: string | number;
|
|
1591
|
-
[nu: number]: string;
|
|
1592
|
-
};
|
|
1593
|
-
type UnwrapMaybeRef<T$1 extends MaybeRef<any> | DeepReactiveState<any>> = T$1 extends Ref<any> ? UnwrapRef<T$1> : UnwrapNestedRefs<T$1>;
|
|
1594
|
-
type TupleToPlainObj<T$1> = { [I in keyof T$1 & `${number}`]: T$1[I] };
|
|
1595
|
-
type HasNamedKeys<T$1> = IsUnion<T$1> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T$1>> : ProcessHasNamedKeys<T$1>;
|
|
1596
|
-
type ProcessHasNamedKeys<T$1> = { [K in keyof NonNullable<T$1>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T$1>] extends never ? false : true;
|
|
1597
|
-
//#endregion
|
|
1598
|
-
//#region src/types/utils/infer.types.d.ts
|
|
1599
|
-
|
|
1600
|
-
//#endregion
|
|
1601
|
-
//#region src/types/rules/rule.params.types.d.ts
|
|
1602
|
-
type CreateFn<T$1 extends any[]> = (...args: T$1) => any;
|
|
1603
|
-
/**
|
|
1604
|
-
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
1605
|
-
*
|
|
1606
|
-
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
1607
|
-
*/
|
|
1608
|
-
type RegleUniversalParams<T$1 extends any[] = [], F$1 = CreateFn<T$1>> = [T$1] extends [[]] ? [] : Parameters<F$1 extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>> }) => any : never>;
|
|
1609
|
-
type UnwrapRegleUniversalParams<T$1 extends MaybeRefOrGetter[] = [], F$1 = CreateFn<T$1>> = [T$1] 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>;
|
|
1610
|
-
//#endregion
|
|
1611
|
-
//#region src/types/rules/rule.internal.types.d.ts
|
|
1612
|
-
/**
|
|
1613
|
-
* Internal definition of the rule, this can be used to reset or patch the rule
|
|
1614
|
-
*/
|
|
1615
|
-
type RegleInternalRuleDefs<TValue$1 extends any = any, TParams$1 extends any[] = [], TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = Raw<{
|
|
1616
|
-
_validator: (value: Maybe<TValue$1>, ...args: TParams$1) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1617
|
-
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => string | string[]);
|
|
1618
|
-
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => boolean);
|
|
1619
|
-
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue$1>) => string | string[]);
|
|
1620
|
-
_type?: string;
|
|
1621
|
-
_message_patched: boolean;
|
|
1622
|
-
_tooltip_patched: boolean;
|
|
1623
|
-
_params?: RegleUniversalParams<TParams$1>;
|
|
1624
|
-
_async: TAsync$1;
|
|
1625
|
-
readonly _brand: symbol;
|
|
1626
|
-
}>;
|
|
1627
|
-
//#endregion
|
|
1628
|
-
//#region src/types/rules/rule.definition.type.d.ts
|
|
1629
|
-
type IsLiteral<T$1> = string extends T$1 ? false : true;
|
|
1630
|
-
/**
|
|
1631
|
-
* Returned typed of rules created with `createRule`
|
|
1632
|
-
* */
|
|
1633
|
-
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> {
|
|
1634
|
-
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams$1, TAsync$1 extends false ? TMetaData : Promise<TMetaData>>;
|
|
1635
|
-
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1636
|
-
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
1637
|
-
tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1638
|
-
type?: string;
|
|
1639
|
-
_value?: IsLiteral<TValue$1> extends true ? TValue$1 : any;
|
|
1640
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetaData : Promise<TMetaData>;
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Rules with params created with `createRules` are callable while being customizable
|
|
1644
|
-
*/
|
|
1645
|
-
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> & {
|
|
1646
|
-
(...params: RegleUniversalParams<TParams$1>): RegleRuleDefinition<TFilteredValue, TParams$1, TAsync$1, TMetadata$1, TInput>;
|
|
1647
|
-
} & (TParams$1 extends [param?: any, ...any[]] ? {
|
|
1648
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1649
|
-
} : {});
|
|
1650
|
-
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[]] ? {
|
|
1651
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1652
|
-
} : {});
|
|
1653
|
-
type RegleRuleMetadataExtended = {
|
|
1654
|
-
$valid: boolean;
|
|
1655
|
-
[x: string]: any;
|
|
1656
|
-
};
|
|
1657
|
-
/**
|
|
1658
|
-
* Define a rule Metadata definition
|
|
1659
|
-
*/
|
|
1660
|
-
type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
|
|
1661
|
-
type DefaultMetadataPropertiesCommon = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid' | '$dirty' | '$pending' | '$correct' | '$error'>;
|
|
1662
|
-
type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
1663
|
-
$rule: Pick<$InternalRegleRuleStatus, '$valid' | '$pending'>;
|
|
1664
|
-
};
|
|
1665
|
-
/**
|
|
1666
|
-
* Will be used to consume metadata on related helpers and rule status
|
|
1667
|
-
*/
|
|
1668
|
-
type RegleRuleMetadataConsumer<TValue$1 extends any, TParams$1 extends [...any[]] = never, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = {
|
|
1669
|
-
$value: Maybe<TValue$1>;
|
|
1670
|
-
} & DefaultMetadataProperties & (TParams$1 extends never ? {} : {
|
|
1671
|
-
$params: [...TParams$1];
|
|
1672
|
-
}) & (Exclude<TMetadata$1, boolean> extends RegleRuleMetadataExtended ? TMetadata$1 extends boolean ? Partial<Omit<Exclude<TMetadata$1, boolean>, '$valid'>> : Omit<Exclude<TMetadata$1, boolean>, '$valid'> : {});
|
|
1673
|
-
/**
|
|
1674
|
-
* Will be used to consume metadata on related helpers and rule status
|
|
1675
|
-
*/
|
|
1676
|
-
type PossibleRegleRuleMetadataConsumer<TValue$1> = {
|
|
1677
|
-
$value: Maybe<TValue$1>;
|
|
1678
|
-
} & DefaultMetadataProperties & {
|
|
1679
|
-
$params?: [...any[]];
|
|
1680
|
-
};
|
|
1681
|
-
/**
|
|
1682
|
-
* Generic types for a created RegleRule
|
|
1683
|
-
*/
|
|
1684
|
-
|
|
1685
|
-
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'> & {
|
|
1686
|
-
message: any;
|
|
1687
|
-
active?: any;
|
|
1688
|
-
tooltip?: any;
|
|
1689
|
-
};
|
|
1690
|
-
/**
|
|
1691
|
-
* Process the type of created rule with `createRule`.
|
|
1692
|
-
* For a rule with params it will return a function
|
|
1693
|
-
* Otherwise it will return the rule definition
|
|
1694
|
-
*/
|
|
1695
|
-
|
|
1696
|
-
type RegleRuleDefinitionProcessor<TValue$1 extends any = any, TParams$1 extends any[] = [], TReturn = any> = (value: Maybe<TValue$1>, ...params: TParams$1) => TReturn;
|
|
1697
|
-
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
1698
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
1699
|
-
}) | ({
|
|
1700
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
1701
|
-
} & CollectionRegleBehaviourOptions);
|
|
1702
|
-
//#endregion
|
|
1703
|
-
//#region src/types/rules/rule.init.types.d.ts
|
|
1704
|
-
type RegleInitPropertyGetter<TValue$1, TReturn, TParams$1 extends [...any[]], TMetadata$1 extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>) => TReturn);
|
|
1705
|
-
/**
|
|
1706
|
-
* @argument
|
|
1707
|
-
* createRule arguments options
|
|
1708
|
-
*/
|
|
1709
|
-
|
|
1710
|
-
/**
|
|
1711
|
-
* @argument
|
|
1712
|
-
* Rule core
|
|
1713
|
-
*/
|
|
1714
|
-
interface RegleRuleCore<TValue$1 extends any, TParams$1 extends any[] = [], TAsync$1 extends boolean = false, TMetadata$1 extends RegleRuleMetadataDefinition = boolean> {
|
|
1715
|
-
validator: (value: Maybe<TValue$1>, ...args: TParams$1) => TAsync$1 extends false ? TMetadata$1 : Promise<TMetadata$1>;
|
|
1716
|
-
message: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1717
|
-
active?: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1718
|
-
tooltip?: RegleInitPropertyGetter<TValue$1, string | string[], TParams$1, TMetadata$1>;
|
|
1719
|
-
type?: string;
|
|
1720
|
-
async?: boolean;
|
|
1721
|
-
}
|
|
1722
|
-
//#endregion
|
|
1723
|
-
//#region src/core/defaultValidators.d.ts
|
|
1724
|
-
interface CommonComparisonOptions {
|
|
1725
|
-
/**
|
|
1726
|
-
* Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
|
|
1727
|
-
* @default true
|
|
1728
|
-
*/
|
|
1729
|
-
allowEqual?: boolean;
|
|
1730
|
-
}
|
|
1731
|
-
interface CommonAlphaOptions {
|
|
1732
|
-
/**
|
|
1733
|
-
* Allow symbols in alphabetical-like rules (like "_")
|
|
1734
|
-
* @default true
|
|
1735
|
-
*/
|
|
1736
|
-
allowSymbols?: boolean;
|
|
1737
|
-
}
|
|
1738
|
-
type DefaultValidators = {
|
|
1739
|
-
alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined]>;
|
|
1740
|
-
alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined]>;
|
|
1741
|
-
between: RegleRuleWithParamsDefinition<number, [min: Maybe<number>, max: Maybe<number>]>;
|
|
1742
|
-
boolean: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1743
|
-
checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
|
|
1744
|
-
contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1745
|
-
date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
1746
|
-
dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1747
|
-
$valid: false;
|
|
1748
|
-
error: 'date-not-after';
|
|
1749
|
-
} | {
|
|
1750
|
-
$valid: false;
|
|
1751
|
-
error: 'value-or-parameter-not-a-date';
|
|
1752
|
-
}>;
|
|
1753
|
-
dateBefore: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1754
|
-
$valid: false;
|
|
1755
|
-
error: 'date-not-before';
|
|
1756
|
-
} | {
|
|
1757
|
-
$valid: false;
|
|
1758
|
-
error: 'value-or-parameter-not-a-date';
|
|
1759
|
-
}>;
|
|
1760
|
-
dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, after: Maybe<string | Date>, options?: CommonComparisonOptions], false, boolean>;
|
|
1761
|
-
decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1762
|
-
email: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1763
|
-
endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1764
|
-
exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
|
|
1765
|
-
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
1766
|
-
hexadecimal: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1767
|
-
integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1768
|
-
ipv4Address: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1769
|
-
literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
|
|
1770
|
-
macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
|
|
1771
|
-
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1772
|
-
maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1773
|
-
minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1774
|
-
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1775
|
-
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
1776
|
-
number: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1777
|
-
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1778
|
-
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
1779
|
-
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
1780
|
-
required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
|
|
1781
|
-
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
1782
|
-
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1783
|
-
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
1784
|
-
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1785
|
-
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1786
|
-
};
|
|
1787
|
-
//#endregion
|
|
1788
|
-
//#region src/types/rules/rule.custom.types.d.ts
|
|
1789
|
-
type CustomRulesDeclarationTree = {
|
|
1790
|
-
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
1791
|
-
};
|
|
1792
|
-
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
1793
|
-
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
1794
|
-
//#endregion
|
|
1795
|
-
//#region src/types/rules/rule.declaration.types.d.ts
|
|
1796
|
-
/**
|
|
1797
|
-
* @public
|
|
1798
|
-
*/
|
|
1799
|
-
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
1800
|
-
/**
|
|
1801
|
-
* @public
|
|
1802
|
-
*/
|
|
1803
|
-
|
|
1804
|
-
/**
|
|
1805
|
-
* @public
|
|
1806
|
-
*/
|
|
1807
|
-
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>>;
|
|
1808
|
-
/**
|
|
1809
|
-
* @internal
|
|
1810
|
-
* @reference {@link RegleFormPropertyType}
|
|
1811
|
-
*/
|
|
1812
|
-
|
|
1813
|
-
/**
|
|
1814
|
-
* @public
|
|
1815
|
-
* Rule tree for a form property
|
|
1816
|
-
*/
|
|
1817
|
-
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] };
|
|
1818
|
-
/**
|
|
1819
|
-
* @internal
|
|
1820
|
-
* @reference {@link RegleRuleDecl}
|
|
1821
|
-
*/
|
|
1822
|
-
|
|
1823
|
-
/**
|
|
1824
|
-
* @public
|
|
1825
|
-
*/
|
|
1826
|
-
type RegleCollectionRuleDeclKeyProperty = {
|
|
1827
|
-
$key?: PropertyKey;
|
|
1828
|
-
};
|
|
1829
|
-
/**
|
|
1830
|
-
* @public
|
|
1831
|
-
*/
|
|
1832
|
-
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = ({
|
|
1833
|
-
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
1834
|
-
} & RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
1835
|
-
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
1836
|
-
} & CollectionRegleBehaviourOptions);
|
|
1837
|
-
/** @public */
|
|
1838
|
-
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>, RegleCollectionRuleDeclKeyProperty>;
|
|
1839
|
-
/**
|
|
1840
|
-
* @internal
|
|
1841
|
-
* @reference {@link RegleCollectionRuleDecl}
|
|
1842
|
-
*/
|
|
1843
|
-
|
|
1844
|
-
/**
|
|
1845
|
-
* @public
|
|
1846
|
-
*/
|
|
1847
|
-
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;
|
|
1848
|
-
/**
|
|
1849
|
-
* @public
|
|
1850
|
-
* Regroup inline and registered rules
|
|
1851
|
-
* */
|
|
1852
|
-
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>;
|
|
1853
|
-
//#endregion
|
|
1854
|
-
//#region src/types/rules/rule.status.types.d.ts
|
|
1855
|
-
/**
|
|
1856
|
-
* @public
|
|
1857
|
-
*/
|
|
1858
|
-
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] ? {} : {
|
|
1859
|
-
/**
|
|
1860
|
-
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
1861
|
-
*/
|
|
1862
|
-
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
1863
|
-
});
|
|
1864
|
-
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> } : {};
|
|
1865
|
-
/**
|
|
1866
|
-
* @public
|
|
1867
|
-
*/
|
|
1868
|
-
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> & {
|
|
1869
|
-
/** 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. */
|
|
1870
|
-
readonly $fields: ProcessNestedFields$1<TState$1, TRules$1, TShortcuts, true>;
|
|
1871
|
-
/**
|
|
1872
|
-
* Collection of all the issues, collected for all children properties and nested forms.
|
|
1873
|
-
*
|
|
1874
|
-
* Only contains issues from properties where $dirty equals true.
|
|
1875
|
-
*/
|
|
1876
|
-
readonly $issues: RegleIssuesTree<TState$1>;
|
|
1877
|
-
/**
|
|
1878
|
-
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
1879
|
-
*
|
|
1880
|
-
* Only contains errors from properties where $dirty equals true.
|
|
1881
|
-
* */
|
|
1882
|
-
readonly $errors: RegleErrorTree<TState$1>;
|
|
1883
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
1884
|
-
readonly $silentErrors: RegleErrorTree<TState$1>;
|
|
1885
|
-
/** 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). */
|
|
1886
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState$1>;
|
|
1887
|
-
/** 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). */
|
|
1888
|
-
$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>>;
|
|
1889
|
-
} & ProcessNestedFields$1<TState$1, TRules$1, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
1890
|
-
/**
|
|
1891
|
-
* @internal
|
|
1892
|
-
* @reference {@link RegleStatus}
|
|
1893
|
-
*/
|
|
1894
|
-
|
|
1895
|
-
/**
|
|
1896
|
-
* @public
|
|
1897
|
-
*/
|
|
1898
|
-
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>;
|
|
1899
|
-
/**
|
|
1900
|
-
* @internal
|
|
1901
|
-
* @reference {@link InferRegleStatusType}
|
|
1902
|
-
*/
|
|
1903
|
-
|
|
1904
|
-
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = EmptyObject$1> = {
|
|
1905
|
-
readonly $property: string;
|
|
1906
|
-
readonly $type?: string;
|
|
1907
|
-
readonly $message: string;
|
|
1908
|
-
} & (IsEmptyObject<TRules$1> extends true ? {
|
|
1909
|
-
readonly $rule: string;
|
|
1910
|
-
} : { [K in keyof ComputeFieldRules<any, TRules$1>]: ComputeFieldRules<any, TRules$1>[K] extends {
|
|
1911
|
-
$metadata: infer TMetadata;
|
|
1912
|
-
} ? K extends string ? {
|
|
1913
|
-
readonly $rule: K;
|
|
1914
|
-
} & (TMetadata extends boolean ? {
|
|
1915
|
-
readonly $rule: string;
|
|
1916
|
-
} : TMetadata) : {
|
|
1917
|
-
readonly $rule: string;
|
|
1918
|
-
} : {
|
|
1919
|
-
readonly $rule: string;
|
|
1920
|
-
} }[keyof ComputeFieldRules<any, TRules$1>]);
|
|
1921
|
-
type ComputeFieldRules<TState$1 extends any, TRules$1 extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>>> = IsEmptyObject<TRules$1> extends true ? {
|
|
1922
|
-
readonly [x: string]: RegleRuleStatus<TState$1, any[], any>;
|
|
1923
|
-
} : { 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> };
|
|
1924
|
-
/**
|
|
1925
|
-
* @public
|
|
1926
|
-
*/
|
|
1927
|
-
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'> & {
|
|
1928
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1929
|
-
$value: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
1930
|
-
/** $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. */
|
|
1931
|
-
$silentValue: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
1932
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1933
|
-
*
|
|
1934
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
1935
|
-
readonly $errors: string[];
|
|
1936
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1937
|
-
readonly $silentErrors: string[];
|
|
1938
|
-
/**
|
|
1939
|
-
* Collect all metadata of validators, Only contains metadata from properties where $dirty equals true.
|
|
1940
|
-
*/
|
|
1941
|
-
readonly $issues: RegleFieldIssue<TRules$1>[];
|
|
1942
|
-
/**
|
|
1943
|
-
* Collect all metadata of validators, including the error message.
|
|
1944
|
-
*/
|
|
1945
|
-
readonly $silentIssues: RegleFieldIssue<TRules$1>[];
|
|
1946
|
-
/** Stores external errors of the current field */
|
|
1947
|
-
readonly $externalErrors: string[];
|
|
1948
|
-
/** Stores active tooltips messages of the current field */
|
|
1949
|
-
readonly $tooltips: string[];
|
|
1950
|
-
/** Represents the inactive status. Is true when this state have empty rules */
|
|
1951
|
-
readonly $inactive: boolean;
|
|
1952
|
-
/** 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). */
|
|
1953
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState$1>;
|
|
1954
|
-
/** 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). */
|
|
1955
|
-
$validate: (forceValues?: IsUnknown<TState$1> extends true ? any : TState$1) => Promise<RegleFieldResult<TState$1, TRules$1>>;
|
|
1956
|
-
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1957
|
-
readonly $rules: ComputeFieldRules<TState$1, TRules$1>;
|
|
1958
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
1959
|
-
/**
|
|
1960
|
-
* @internal
|
|
1961
|
-
* @reference {@link RegleFieldStatus}
|
|
1962
|
-
*/
|
|
1963
|
-
|
|
1964
|
-
/**
|
|
1965
|
-
* @public
|
|
1966
|
-
*/
|
|
1967
|
-
interface RegleCommonStatus<TValue$1 = any> extends StandardSchemaV1<TValue$1> {
|
|
1968
|
-
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
1969
|
-
readonly $invalid: boolean;
|
|
1970
|
-
/**
|
|
1971
|
-
* This is not the opposite of `$invalid`. Correct is meant to display UI validation report.
|
|
1972
|
-
*
|
|
1973
|
-
* This will be `true` only if:
|
|
1974
|
-
* - The field have at least one active rule
|
|
1975
|
-
* - Is dirty and not empty
|
|
1976
|
-
* - Passes validation
|
|
1977
|
-
*/
|
|
1978
|
-
readonly $correct: boolean;
|
|
1979
|
-
/** 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.*/
|
|
1980
|
-
readonly $dirty: boolean;
|
|
1981
|
-
/** 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. */
|
|
1982
|
-
readonly $anyDirty: boolean;
|
|
1983
|
-
/** Indicates whether a field has been touched and if the value is different than the initial one.
|
|
1984
|
-
* On nested elements and collections, it's true only if all its children are also `$edited`.
|
|
1985
|
-
* Use `$anyEdited` to check for any edited children
|
|
1986
|
-
*/
|
|
1987
|
-
readonly $edited: boolean;
|
|
1988
|
-
/** 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. */
|
|
1989
|
-
readonly $anyEdited: boolean;
|
|
1990
|
-
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
1991
|
-
readonly $pending: boolean;
|
|
1992
|
-
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
1993
|
-
readonly $error: boolean;
|
|
1994
|
-
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
1995
|
-
readonly $ready: boolean;
|
|
1996
|
-
/** Return the current key name of the field. */
|
|
1997
|
-
readonly $name: string;
|
|
1998
|
-
/** Returns the current path of the rule (used internally for tracking) */
|
|
1999
|
-
readonly $path: string;
|
|
2000
|
-
/** Id used to track collections items */
|
|
2001
|
-
$id?: string;
|
|
2002
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2003
|
-
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2004
|
-
/**
|
|
2005
|
-
* This value reflect the current initial value of the field.
|
|
2006
|
-
* The initial value is different than the original value as the initial value can be mutated when using `$reset`.
|
|
2007
|
-
*/
|
|
2008
|
-
readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2009
|
-
/**
|
|
2010
|
-
* This value reflect the original value of the field at original call. This can't be mutated
|
|
2011
|
-
*/
|
|
2012
|
-
readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2013
|
-
/**
|
|
2014
|
-
* `$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.
|
|
2015
|
-
* */
|
|
2016
|
-
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue$1>>;
|
|
2017
|
-
/** Marks the field and all nested properties as $dirty. */
|
|
2018
|
-
$touch(): void;
|
|
2019
|
-
/**
|
|
2020
|
-
* Reset the validation status to a pristine state while keeping the current form state.
|
|
2021
|
-
* Resets the `$dirty` state on all nested properties of a form.
|
|
2022
|
-
* Rerun rules if `$lazy` is false
|
|
2023
|
-
*/
|
|
2024
|
-
$reset(): void;
|
|
2025
|
-
$reset(options?: ResetOptions<TValue$1>): void;
|
|
2026
|
-
/** Clears the $externalErrors state back to an empty object. */
|
|
2027
|
-
$clearExternalErrors(): void;
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* @public
|
|
2031
|
-
*/
|
|
2032
|
-
type RegleRuleStatus<TValue$1 = any, TParams$1 extends any[] = any[], TMetadata$1 extends RegleRuleMetadataDefinition = boolean> = {
|
|
2033
|
-
/** The name of the rule type. */
|
|
2034
|
-
readonly $type: string;
|
|
2035
|
-
/** Returns the computed error message or messages for the current rule. */
|
|
2036
|
-
readonly $message: string | string[];
|
|
2037
|
-
/** Stores the current rule tooltip or tooltips */
|
|
2038
|
-
readonly $tooltip: string | string[];
|
|
2039
|
-
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
2040
|
-
readonly $active: boolean;
|
|
2041
|
-
/** Indicates the state of validation for this validator. */
|
|
2042
|
-
readonly $valid: boolean;
|
|
2043
|
-
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
2044
|
-
readonly $pending: boolean;
|
|
2045
|
-
/** Returns the current path of the rule (used internally for tracking) */
|
|
2046
|
-
readonly $path: string;
|
|
2047
|
-
/** Contains the metadata returned by the validator function. */
|
|
2048
|
-
readonly $metadata: TMetadata$1 extends boolean ? TMetadata$1 : Omit<TMetadata$1, '$valid'>;
|
|
2049
|
-
/** Run the rule validator and compute its properties like $message and $active */
|
|
2050
|
-
$parse(): Promise<boolean>;
|
|
2051
|
-
/** Reset the $valid, $metadata and $pending states */
|
|
2052
|
-
$reset(): void;
|
|
2053
|
-
/** Returns the original rule validator function. */
|
|
2054
|
-
$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>);
|
|
2055
|
-
} & ([TParams$1] extends [never[]] ? {} : [unknown[]] extends [TParams$1] ? {
|
|
2056
|
-
readonly $params?: any[];
|
|
2057
|
-
} : {
|
|
2058
|
-
readonly $params: [...TParams$1];
|
|
2059
|
-
});
|
|
2060
|
-
/**
|
|
2061
|
-
* @internal
|
|
2062
|
-
* @reference {@link RegleRuleStatus}
|
|
2063
|
-
*/
|
|
2064
|
-
interface $InternalRegleRuleStatus {
|
|
2065
|
-
$type?: string;
|
|
2066
|
-
$message: string | string[];
|
|
2067
|
-
$tooltip: string | string[];
|
|
2068
|
-
$active: boolean;
|
|
2069
|
-
$valid: boolean;
|
|
2070
|
-
$pending: boolean;
|
|
2071
|
-
$path: string;
|
|
2072
|
-
$externalErrors?: string[];
|
|
2073
|
-
$params?: any[];
|
|
2074
|
-
$metadata: any;
|
|
2075
|
-
$haveAsync: boolean;
|
|
2076
|
-
$validating: boolean;
|
|
2077
|
-
$fieldDirty: boolean;
|
|
2078
|
-
$fieldInvalid: boolean;
|
|
2079
|
-
$fieldPending: boolean;
|
|
2080
|
-
$fieldCorrect: boolean;
|
|
2081
|
-
$fieldError: boolean;
|
|
2082
|
-
$maybePending: boolean;
|
|
2083
|
-
$validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
|
|
2084
|
-
$parse(): Promise<boolean>;
|
|
2085
|
-
$reset(): void;
|
|
2086
|
-
$unwatch(): void;
|
|
2087
|
-
$watch(): void;
|
|
2088
|
-
}
|
|
2089
|
-
/**
|
|
2090
|
-
* @public
|
|
2091
|
-
*/
|
|
2092
|
-
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'> & {
|
|
2093
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2094
|
-
$value: MaybeOutput<TState$1>;
|
|
2095
|
-
/** $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. */
|
|
2096
|
-
$silentValue: MaybeOutput<TState$1>;
|
|
2097
|
-
/** 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. */
|
|
2098
|
-
readonly $each: Array<InferRegleStatusType<NonNullable<TRules$1>, NonNullable<TState$1>, number, TShortcuts>>;
|
|
2099
|
-
/** 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. */
|
|
2100
|
-
readonly $self: RegleFieldStatus<TState$1, TFieldRule, TShortcuts>;
|
|
2101
|
-
/**
|
|
2102
|
-
* Collection of all the issues, collected for all children properties and nested forms.
|
|
2103
|
-
*
|
|
2104
|
-
* Only contains issues from properties where $dirty equals true.
|
|
2105
|
-
*/
|
|
2106
|
-
readonly $issues: RegleCollectionErrors<TState$1, true>;
|
|
2107
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2108
|
-
*
|
|
2109
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
2110
|
-
readonly $errors: RegleCollectionErrors<TState$1>;
|
|
2111
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2112
|
-
readonly $silentErrors: RegleCollectionErrors<TState$1>;
|
|
2113
|
-
/** 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). */
|
|
2114
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState$1>;
|
|
2115
|
-
/** 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). */
|
|
2116
|
-
$validate: (value?: JoinDiscriminatedUnions<TState$1>) => Promise<RegleCollectionResult<TState$1, JoinDiscriminatedUnions<TRules$1>>>;
|
|
2117
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
2118
|
-
/**
|
|
2119
|
-
* @internal
|
|
2120
|
-
* @reference {@link RegleCollectionStatus}
|
|
2121
|
-
*/
|
|
2122
|
-
|
|
2123
|
-
//#endregion
|
|
2124
|
-
//#region src/types/rules/rule.errors.types.d.ts
|
|
2125
|
-
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> };
|
|
2126
|
-
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> };
|
|
2127
|
-
type RegleExternalErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], true> };
|
|
2128
|
-
type ErrorMessageOrIssue<TIssue extends boolean> = TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2129
|
-
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;
|
|
2130
|
-
type RegleCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2131
|
-
readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2132
|
-
readonly $each: RegleValidationErrors<TState$1, false, TIssue>[];
|
|
2133
|
-
};
|
|
2134
|
-
type RegleExternalCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2135
|
-
readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2136
|
-
readonly $each?: RegleValidationErrors<TState$1, true, TIssue>[];
|
|
2137
|
-
};
|
|
2138
|
-
/** @internal */
|
|
2139
|
-
type $InternalRegleCollectionErrors = {
|
|
2140
|
-
readonly $self?: string[];
|
|
2141
|
-
readonly $each?: $InternalRegleErrors[];
|
|
2142
|
-
};
|
|
2143
|
-
type $InternalRegleErrorTree = {
|
|
2144
|
-
[x: string]: $InternalRegleErrors;
|
|
2145
|
-
};
|
|
2146
|
-
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
2147
|
-
type $InternalRegleIssuesTree = {
|
|
2148
|
-
[x: string]: $InternalRegleIssues;
|
|
2149
|
-
};
|
|
2150
|
-
type $InternalRegleIssues = $InternalRegleCollectionIssues | RegleFieldIssue[] | $InternalRegleIssuesTree;
|
|
2151
|
-
type $InternalRegleCollectionIssues = {
|
|
2152
|
-
readonly $self?: RegleFieldIssue[];
|
|
2153
|
-
readonly $each?: $InternalRegleIssues[];
|
|
2154
|
-
};
|
|
2155
|
-
//#endregion
|
|
2156
|
-
//#region src/types/rules/compatibility.rules.d.ts
|
|
2157
|
-
|
|
2158
|
-
/** Supports both core Regle and schemas Regle for Zod/Valibot */
|
|
2159
|
-
type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
|
|
2160
|
-
$groups?: {
|
|
2161
|
-
[x: string]: RegleValidationGroupOutput;
|
|
2162
|
-
};
|
|
2163
|
-
$validate: (...args: any[]) => Promise<SuperCompatibleRegleResult>;
|
|
2164
|
-
};
|
|
2165
|
-
type SuperCompatibleRegleResult = $InternalRegleResult;
|
|
2166
|
-
type SuperCompatibleRegleStatus = {
|
|
2167
|
-
readonly $fields: {
|
|
2168
|
-
[x: string]: any;
|
|
2169
|
-
};
|
|
2170
|
-
readonly $issues: Record<string, RegleValidationErrors<any, false, true>>;
|
|
2171
|
-
readonly $errors: Record<string, RegleValidationErrors<any, false>>;
|
|
2172
|
-
readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
|
|
2173
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
|
|
2174
|
-
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2175
|
-
$reset: (options?: ResetOptions<unknown>) => void;
|
|
2176
|
-
[x: string]: any;
|
|
2177
|
-
};
|
|
2178
|
-
//#endregion
|
|
2179
|
-
//#region src/core/mergeRegles.d.ts
|
|
2180
|
-
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'> & {
|
|
2181
|
-
/** Map of merged Regle instances and their properties */
|
|
2182
|
-
readonly $instances: { [K in keyof TRegles]: TRegles[K] };
|
|
2183
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2184
|
-
$value: TValue$1;
|
|
2185
|
-
/** $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. */
|
|
2186
|
-
$silentValue: TValue$1;
|
|
2187
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2188
|
-
*
|
|
2189
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
2190
|
-
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2191
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
2192
|
-
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
2193
|
-
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2194
|
-
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
2195
|
-
/** 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). */
|
|
2196
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue$1>;
|
|
2197
|
-
/** 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). */
|
|
2198
|
-
$validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
|
|
2199
|
-
};
|
|
2200
|
-
type MergedScopedRegles<TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue$1>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
|
|
2201
|
-
/** Array of scoped Regles instances */
|
|
2202
|
-
readonly $instances: SuperCompatibleRegleRoot[];
|
|
2203
|
-
/** Collection of all registered Regles instances values */
|
|
2204
|
-
readonly $value: TValue$1;
|
|
2205
|
-
/** Collection of all registered Regles instances errors */
|
|
2206
|
-
readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2207
|
-
/** Collection of all registered Regles instances silent errors */
|
|
2208
|
-
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2209
|
-
/** Collection of all registered Regles instances issues */
|
|
2210
|
-
readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2211
|
-
/** Collection of all registered Regles instances silent issues */
|
|
2212
|
-
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2213
|
-
/** 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). */
|
|
2214
|
-
$validate: (forceValues?: TValue$1) => Promise<{
|
|
2215
|
-
valid: boolean;
|
|
2216
|
-
data: TValue$1;
|
|
2217
|
-
errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2218
|
-
issues: RegleValidationErrors<Record<string, unknown>>[];
|
|
2219
|
-
}>;
|
|
2220
|
-
};
|
|
2221
|
-
type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
|
|
2222
|
-
valid: false;
|
|
2223
|
-
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2224
|
-
valid: false;
|
|
2225
|
-
}>['data'] };
|
|
2226
|
-
errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2227
|
-
issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2228
|
-
} | {
|
|
2229
|
-
valid: true;
|
|
2230
|
-
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2231
|
-
valid: true;
|
|
2232
|
-
}>['data'] };
|
|
2233
|
-
errors: EmptyObject$1;
|
|
2234
|
-
issues: EmptyObject$1;
|
|
2235
|
-
};
|
|
2236
|
-
//#endregion
|
|
2237
|
-
//#region src/core/createScopedUseRegle/useCollectScope.d.ts
|
|
2238
|
-
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue$1 extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2239
|
-
r$: MergedRegles<{ [K in keyof TValue$1]: RegleRoot<TValue$1[K]> & SuperCompatibleRegleRoot }>;
|
|
2240
|
-
} : <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2241
|
-
r$: MergedScopedRegles<TValue$1>;
|
|
2242
|
-
};
|
|
2243
|
-
//#endregion
|
|
2244
|
-
//#region src/core/createScopedUseRegle/useScopedRegle.d.ts
|
|
2245
|
-
type UseScopedRegleOptions<TAsRecord extends boolean> = {
|
|
2246
|
-
namespace?: MaybeRefOrGetter<string>;
|
|
2247
|
-
} & (TAsRecord extends true ? {
|
|
2248
|
-
scopeKey: string;
|
|
2249
|
-
} : {});
|
|
2250
|
-
//#endregion
|
|
2251
|
-
//#region src/core/createScopedUseRegle/createScopedUseRegle.d.ts
|
|
2252
|
-
type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsRecord extends boolean> = {
|
|
2253
|
-
/**
|
|
2254
|
-
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
2255
|
-
*/
|
|
2256
|
-
customUseRegle?: TCustomRegle;
|
|
2257
|
-
/**
|
|
2258
|
-
* Store the collected instances externally
|
|
2259
|
-
*/
|
|
2260
|
-
customStore?: Ref<ScopedInstancesRecordLike>;
|
|
2261
|
-
/**
|
|
2262
|
-
* Collect instances in a Record instead of an array
|
|
2263
|
-
*
|
|
2264
|
-
* ⚠️ Each nested `useScopedRegle` must provide a parameter `scopeKey` to be collected.
|
|
2265
|
-
*/
|
|
2266
|
-
asRecord?: TAsRecord;
|
|
2267
|
-
};
|
|
2268
|
-
//#endregion
|
|
2269
|
-
//#region ../../node_modules/.pnpm/vue-router@4.6.3_vue@3.5.22_typescript@5.9.3_/node_modules/vue-router/dist/router-BbqN7H95.d.mts
|
|
2270
|
-
//#region src/query.d.ts
|
|
2271
|
-
|
|
2272
|
-
/**
|
|
2273
|
-
* Possible values in normalized {@link LocationQuery}. `null` renders the query
|
|
2274
|
-
* param but without an `=`.
|
|
2275
|
-
*
|
|
2276
|
-
* @example
|
|
2277
|
-
* ```
|
|
2278
|
-
* ?isNull&isEmpty=&other=other
|
|
2279
|
-
* gives
|
|
2280
|
-
* `{ isNull: null, isEmpty: '', other: 'other' }`.
|
|
2281
|
-
* ```
|
|
2282
|
-
*
|
|
2283
|
-
* @internal
|
|
2284
|
-
*/
|
|
2285
|
-
type LocationQueryValue = string | null;
|
|
2286
|
-
/**
|
|
2287
|
-
* Possible values when defining a query. `undefined` allows to remove a value.
|
|
2288
|
-
*
|
|
2289
|
-
* @internal
|
|
2290
|
-
*/
|
|
2291
|
-
type LocationQueryValueRaw = LocationQueryValue | number | undefined;
|
|
2292
|
-
/**
|
|
2293
|
-
* Normalized query object that appears in {@link RouteLocationNormalized}
|
|
2294
|
-
*
|
|
2295
|
-
* @public
|
|
2296
|
-
*/
|
|
2297
|
-
type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>;
|
|
2298
|
-
/**
|
|
2299
|
-
* Loose {@link LocationQuery} object that can be passed to functions like
|
|
2300
|
-
* {@link Router.push} and {@link Router.replace} or anywhere when creating a
|
|
2301
|
-
* {@link RouteLocationRaw}
|
|
2302
|
-
*
|
|
2303
|
-
* @public
|
|
2304
|
-
*/
|
|
2305
|
-
type LocationQueryRaw = Record<string | number, LocationQueryValueRaw | LocationQueryValueRaw[]>;
|
|
2306
|
-
/**
|
|
2307
|
-
* Transforms a queryString into a {@link LocationQuery} object. Accept both, a
|
|
2308
|
-
* version with the leading `?` and without Should work as URLSearchParams
|
|
2309
|
-
|
|
2310
|
-
* @internal
|
|
2311
|
-
*
|
|
2312
|
-
* @param search - search string to parse
|
|
2313
|
-
* @returns a query object
|
|
2314
|
-
*/
|
|
2315
|
-
declare function parseQuery(search: string): LocationQuery;
|
|
2316
|
-
/**
|
|
2317
|
-
* Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
|
|
2318
|
-
* doesn't prepend a `?`
|
|
2319
|
-
*
|
|
2320
|
-
* @internal
|
|
2321
|
-
*
|
|
2322
|
-
* @param query - query object to stringify
|
|
2323
|
-
* @returns string version of the query without the leading `?`
|
|
2324
|
-
*/
|
|
2325
|
-
declare function stringifyQuery(query: LocationQueryRaw | undefined): string;
|
|
2326
|
-
//#endregion
|
|
2327
|
-
//#region src/config.d.ts
|
|
2328
|
-
/**
|
|
2329
|
-
* Allows customizing existing types of the router that are used globally like `$router`, `<RouterLink>`, etc. **ONLY FOR INTERNAL USAGE**.
|
|
2330
|
-
*
|
|
2331
|
-
* - `$router` - the router instance
|
|
2332
|
-
* - `$route` - the current route location
|
|
2333
|
-
* - `beforeRouteEnter` - Page component option
|
|
2334
|
-
* - `beforeRouteUpdate` - Page component option
|
|
2335
|
-
* - `beforeRouteLeave` - Page component option
|
|
2336
|
-
* - `RouterLink` - RouterLink Component
|
|
2337
|
-
* - `RouterView` - RouterView Component
|
|
2338
|
-
*
|
|
2339
|
-
* @internal
|
|
2340
|
-
*/
|
|
2341
|
-
interface TypesConfig {}
|
|
2342
|
-
//#endregion
|
|
2343
|
-
//#region src/typed-routes/route-map.d.ts
|
|
2344
|
-
/**
|
|
2345
|
-
* Helper type to define a Typed `RouteRecord`
|
|
2346
|
-
* @see {@link RouteRecord}
|
|
2347
|
-
*/
|
|
2348
|
-
interface RouteRecordInfo<Name extends string | symbol = string, Path extends string = string, ParamsRaw extends RouteParamsRawGeneric = RouteParamsRawGeneric, Params$1 extends RouteParamsGeneric = RouteParamsGeneric, ChildrenNames extends string | symbol = never> {
|
|
2349
|
-
name: Name;
|
|
2350
|
-
path: Path;
|
|
2351
|
-
paramsRaw: ParamsRaw;
|
|
2352
|
-
params: Params$1;
|
|
2353
|
-
childrenNames: ChildrenNames;
|
|
2354
|
-
}
|
|
2355
|
-
type RouteRecordInfoGeneric = RouteRecordInfo<string | symbol, string, RouteParamsRawGeneric, RouteParamsGeneric, string | symbol>;
|
|
2356
|
-
/**
|
|
2357
|
-
* Convenience type to get the typed RouteMap or a generic one if not provided. It is extracted from the {@link TypesConfig} if it exists, it becomes {@link RouteMapGeneric} otherwise.
|
|
2358
|
-
*/
|
|
2359
|
-
type RouteMap = TypesConfig extends Record<'RouteNamedMap', infer RouteNamedMap> ? RouteNamedMap : RouteMapGeneric;
|
|
2360
|
-
/**
|
|
2361
|
-
* Generic version of the `RouteMap`.
|
|
2362
|
-
*/
|
|
2363
|
-
type RouteMapGeneric = Record<string | symbol, RouteRecordInfoGeneric>;
|
|
2364
|
-
//#endregion
|
|
2365
|
-
//#region src/types/utils.d.ts
|
|
2366
|
-
/**
|
|
2367
|
-
* Creates a union type that still allows autocompletion for strings.
|
|
2368
|
-
* @internal
|
|
2369
|
-
*/
|
|
2370
|
-
type _LiteralUnion<LiteralType, BaseType extends string = string> = LiteralType | (BaseType & Record<never, never>);
|
|
2371
|
-
/**
|
|
2372
|
-
* Maybe a promise maybe not
|
|
2373
|
-
* @internal
|
|
2374
|
-
*/
|
|
2375
|
-
type _Awaitable<T$1> = T$1 | PromiseLike<T$1>;
|
|
2376
|
-
/**
|
|
2377
|
-
* @internal
|
|
2378
|
-
*/
|
|
2379
|
-
|
|
2380
|
-
//#endregion
|
|
2381
|
-
//#region src/typed-routes/route-records.d.ts
|
|
2382
|
-
/**
|
|
2383
|
-
* @internal
|
|
2384
|
-
*/
|
|
2385
|
-
type RouteRecordRedirectOption = RouteLocationRaw | ((to: RouteLocation, from: RouteLocationNormalizedLoaded) => RouteLocationRaw);
|
|
2386
|
-
/**
|
|
2387
|
-
* Generic version of {@link RouteRecordName}.
|
|
2388
|
-
*/
|
|
2389
|
-
type RouteRecordNameGeneric = string | symbol | undefined;
|
|
2390
|
-
/**
|
|
2391
|
-
* Possible values for a route record **after normalization**
|
|
2392
|
-
*
|
|
2393
|
-
* NOTE: since `RouteRecordName` is a type, it evaluates too early and it's often the generic version {@link RouteRecordNameGeneric}. If you need a typed version of all of the names of routes, use {@link RouteMap | `keyof RouteMap`}
|
|
2394
|
-
*/
|
|
2395
|
-
|
|
2396
|
-
/**
|
|
2397
|
-
* @internal
|
|
2398
|
-
*/
|
|
2399
|
-
type _RouteRecordProps<Name extends keyof RouteMap = keyof RouteMap> = boolean | Record<string, any> | ((to: RouteLocationNormalized<Name>) => Record<string, any>);
|
|
2400
|
-
//#endregion
|
|
2401
|
-
//#region src/typed-routes/route-location.d.ts
|
|
2402
|
-
/**
|
|
2403
|
-
* Generic version of {@link RouteLocation}. It is used when no {@link RouteMap} is provided.
|
|
2404
|
-
*/
|
|
2405
|
-
interface RouteLocationGeneric extends _RouteLocationBase, RouteLocationOptions {
|
|
2406
|
-
/**
|
|
2407
|
-
* Array of {@link RouteRecord} containing components as they were
|
|
2408
|
-
* passed when adding records. It can also contain redirect records. This
|
|
2409
|
-
* can't be used directly. **This property is non-enumerable**.
|
|
2410
|
-
*/
|
|
2411
|
-
matched: RouteRecord[];
|
|
2412
|
-
}
|
|
2413
|
-
/**
|
|
2414
|
-
* Helper to generate a type safe version of the {@link RouteLocation} type.
|
|
2415
|
-
*/
|
|
2416
|
-
interface RouteLocationTyped<RouteMap$1 extends RouteMapGeneric, Name extends keyof RouteMap$1> extends RouteLocationGeneric {
|
|
2417
|
-
name: Extract<Name, string | symbol>;
|
|
2418
|
-
params: RouteMap$1[Name]['params'];
|
|
2419
|
-
}
|
|
2420
|
-
/**
|
|
2421
|
-
* List of all possible {@link RouteLocation} indexed by the route name.
|
|
2422
|
-
* @internal
|
|
2423
|
-
*/
|
|
2424
|
-
type RouteLocationTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationTyped<RouteMap$1, N> };
|
|
2425
|
-
/**
|
|
2426
|
-
* Generic version of {@link RouteLocationNormalized} that is used when no {@link RouteMap} is provided.
|
|
2427
|
-
*/
|
|
2428
|
-
interface RouteLocationNormalizedGeneric extends _RouteLocationBase {
|
|
2429
|
-
name: RouteRecordNameGeneric;
|
|
2430
|
-
/**
|
|
2431
|
-
* Array of {@link RouteRecordNormalized}
|
|
2432
|
-
*/
|
|
2433
|
-
matched: RouteRecordNormalized[];
|
|
2434
|
-
}
|
|
2435
|
-
/**
|
|
2436
|
-
* Helper to generate a type safe version of the {@link RouteLocationNormalized} type.
|
|
2437
|
-
*/
|
|
2438
|
-
interface RouteLocationNormalizedTyped<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap$1 = keyof RouteMap$1> extends RouteLocationNormalizedGeneric {
|
|
2439
|
-
name: Extract<Name, string | symbol>;
|
|
2440
|
-
params: RouteMap$1[Name]['params'];
|
|
2441
|
-
/**
|
|
2442
|
-
* Array of {@link RouteRecordNormalized}
|
|
2443
|
-
*/
|
|
2444
|
-
matched: RouteRecordNormalized[];
|
|
2445
|
-
}
|
|
2446
|
-
/**
|
|
2447
|
-
* List of all possible {@link RouteLocationNormalized} indexed by the route name.
|
|
2448
|
-
* @internal
|
|
2449
|
-
*/
|
|
2450
|
-
type RouteLocationNormalizedTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationNormalizedTyped<RouteMap$1, N> };
|
|
2451
|
-
/**
|
|
2452
|
-
* Generic version of {@link RouteLocationNormalizedLoaded} that is used when no {@link RouteMap} is provided.
|
|
2453
|
-
*/
|
|
2454
|
-
interface RouteLocationNormalizedLoadedGeneric extends RouteLocationNormalizedGeneric {
|
|
2455
|
-
/**
|
|
2456
|
-
* Array of {@link RouteLocationMatched} containing only plain components (any
|
|
2457
|
-
* lazy-loaded components have been loaded and were replaced inside the
|
|
2458
|
-
* `components` object) so it can be directly used to display routes. It
|
|
2459
|
-
* cannot contain redirect records either. **This property is non-enumerable**.
|
|
2460
|
-
*/
|
|
2461
|
-
matched: RouteLocationMatched[];
|
|
2462
|
-
}
|
|
2463
|
-
/**
|
|
2464
|
-
* Helper to generate a type safe version of the {@link RouteLocationNormalizedLoaded} type.
|
|
2465
|
-
*/
|
|
2466
|
-
interface RouteLocationNormalizedLoadedTyped<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap$1 = keyof RouteMap$1> extends RouteLocationNormalizedLoadedGeneric {
|
|
2467
|
-
name: Extract<Name, string | symbol>;
|
|
2468
|
-
params: RouteMap$1[Name]['params'];
|
|
2469
|
-
}
|
|
2470
|
-
/**
|
|
2471
|
-
* List of all possible {@link RouteLocationNormalizedLoaded} indexed by the route name.
|
|
2472
|
-
* @internal
|
|
2473
|
-
*/
|
|
2474
|
-
type RouteLocationNormalizedLoadedTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationNormalizedLoadedTyped<RouteMap$1, N> };
|
|
2475
|
-
/**
|
|
2476
|
-
* Generic version of {@link RouteLocationAsRelative}. It is used when no {@link RouteMap} is provided.
|
|
2477
|
-
*/
|
|
2478
|
-
interface RouteLocationAsRelativeGeneric extends RouteQueryAndHash, RouteLocationOptions {
|
|
2479
|
-
name?: RouteRecordNameGeneric;
|
|
2480
|
-
params?: RouteParamsRawGeneric;
|
|
2481
|
-
/**
|
|
2482
|
-
* A relative path to the current location. This property should be removed
|
|
2483
|
-
*/
|
|
2484
|
-
path?: undefined;
|
|
2485
|
-
}
|
|
2486
|
-
/**
|
|
2487
|
-
* Helper to generate a type safe version of the {@link RouteLocationAsRelative} type.
|
|
2488
|
-
*/
|
|
2489
|
-
interface RouteLocationAsRelativeTyped<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap$1 = keyof RouteMap$1> extends RouteLocationAsRelativeGeneric {
|
|
2490
|
-
name?: Extract<Name, string | symbol>;
|
|
2491
|
-
params?: RouteMap$1[Name]['paramsRaw'];
|
|
2492
|
-
}
|
|
2493
|
-
/**
|
|
2494
|
-
* List of all possible {@link RouteLocationAsRelative} indexed by the route name.
|
|
2495
|
-
* @internal
|
|
2496
|
-
*/
|
|
2497
|
-
type RouteLocationAsRelativeTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationAsRelativeTyped<RouteMap$1, N> };
|
|
2498
|
-
/**
|
|
2499
|
-
* Generic version of {@link RouteLocationAsPath}. It is used when no {@link RouteMap} is provided.
|
|
2500
|
-
*/
|
|
2501
|
-
interface RouteLocationAsPathGeneric extends RouteQueryAndHash, RouteLocationOptions {
|
|
2502
|
-
/**
|
|
2503
|
-
* Percentage encoded pathname section of the URL.
|
|
2504
|
-
*/
|
|
2505
|
-
path: string;
|
|
2506
|
-
}
|
|
2507
|
-
/**
|
|
2508
|
-
* Helper to generate a type safe version of the {@link RouteLocationAsPath} type.
|
|
2509
|
-
*/
|
|
2510
|
-
interface RouteLocationAsPathTyped<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap$1 = keyof RouteMap$1> extends RouteLocationAsPathGeneric {
|
|
2511
|
-
path: _LiteralUnion<RouteMap$1[Name]['path']>;
|
|
2512
|
-
}
|
|
2513
|
-
/**
|
|
2514
|
-
* List of all possible {@link RouteLocationAsPath} indexed by the route name.
|
|
2515
|
-
* @internal
|
|
2516
|
-
*/
|
|
2517
|
-
type RouteLocationAsPathTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationAsPathTyped<RouteMap$1, N> };
|
|
2518
|
-
/**
|
|
2519
|
-
* Helper to generate a type safe version of the {@link RouteLocationAsString} type.
|
|
2520
|
-
*/
|
|
2521
|
-
type RouteLocationAsStringTyped<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap$1 = keyof RouteMap$1> = RouteMap$1[Name]['path'];
|
|
2522
|
-
/**
|
|
2523
|
-
* List of all possible {@link RouteLocationAsString} indexed by the route name.
|
|
2524
|
-
* @internal
|
|
2525
|
-
*/
|
|
2526
|
-
type RouteLocationAsStringTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationAsStringTyped<RouteMap$1, N> };
|
|
2527
|
-
/**
|
|
2528
|
-
* Generic version of {@link RouteLocationResolved}. It is used when no {@link RouteMap} is provided.
|
|
2529
|
-
*/
|
|
2530
|
-
interface RouteLocationResolvedGeneric extends RouteLocationGeneric {
|
|
2531
|
-
/**
|
|
2532
|
-
* Resolved `href` for the route location that will be set on the `<a href="...">`.
|
|
2533
|
-
*/
|
|
2534
|
-
href: string;
|
|
2535
|
-
}
|
|
2536
|
-
/**
|
|
2537
|
-
* Helper to generate a type safe version of the {@link RouteLocationResolved} type.
|
|
2538
|
-
*/
|
|
2539
|
-
interface RouteLocationResolvedTyped<RouteMap$1 extends RouteMapGeneric, Name extends keyof RouteMap$1> extends RouteLocationTyped<RouteMap$1, Name> {
|
|
2540
|
-
/**
|
|
2541
|
-
* Resolved `href` for the route location that will be set on the `<a href="...">`.
|
|
2542
|
-
*/
|
|
2543
|
-
href: string;
|
|
2544
|
-
}
|
|
2545
|
-
/**
|
|
2546
|
-
* List of all possible {@link RouteLocationResolved} indexed by the route name.
|
|
2547
|
-
* @internal
|
|
2548
|
-
*/
|
|
2549
|
-
type RouteLocationResolvedTypedList<RouteMap$1 extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap$1]: RouteLocationResolvedTyped<RouteMap$1, N> };
|
|
2550
|
-
/**
|
|
2551
|
-
* Type safe versions of types that are exposed by vue-router. We have to use a generic check to allow for names to be `undefined` when no `RouteMap` is provided.
|
|
2552
|
-
*/
|
|
2553
|
-
/**
|
|
2554
|
-
* {@link RouteLocationRaw} resolved using the matcher
|
|
2555
|
-
*/
|
|
2556
|
-
type RouteLocation<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationGeneric : RouteLocationTypedList<RouteMap>[Name];
|
|
2557
|
-
/**
|
|
2558
|
-
* Similar to {@link RouteLocation} but its
|
|
2559
|
-
* {@link RouteLocationNormalizedTyped.matched | `matched` property} cannot contain redirect records
|
|
2560
|
-
*/
|
|
2561
|
-
type RouteLocationNormalized<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationNormalizedGeneric : RouteLocationNormalizedTypedList<RouteMap>[Name];
|
|
2562
|
-
/**
|
|
2563
|
-
* Similar to {@link RouteLocationNormalized} but its `components` do not contain any function to lazy load components.
|
|
2564
|
-
* In other words, it's ready to be rendered by `<RouterView>`.
|
|
2565
|
-
*/
|
|
2566
|
-
type RouteLocationNormalizedLoaded<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationNormalizedLoadedGeneric : RouteLocationNormalizedLoadedTypedList<RouteMap>[Name];
|
|
2567
|
-
/**
|
|
2568
|
-
* Route location relative to the current location. It accepts other properties than `path` like `params`, `query` and
|
|
2569
|
-
* `hash` to conveniently change them.
|
|
2570
|
-
*/
|
|
2571
|
-
type RouteLocationAsRelative<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsRelativeGeneric : RouteLocationAsRelativeTypedList<RouteMap>[Name];
|
|
2572
|
-
/**
|
|
2573
|
-
* Route location resolved with {@link Router | `router.resolve()`}.
|
|
2574
|
-
*/
|
|
2575
|
-
type RouteLocationResolved<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationResolvedGeneric : RouteLocationResolvedTypedList<RouteMap>[Name];
|
|
2576
|
-
/**
|
|
2577
|
-
* Same as {@link RouteLocationAsPath} but as a string literal.
|
|
2578
|
-
*/
|
|
2579
|
-
type RouteLocationAsString<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? string : _LiteralUnion<RouteLocationAsStringTypedList<RouteMap>[Name], string>;
|
|
2580
|
-
/**
|
|
2581
|
-
* Route location as an object with a `path` property.
|
|
2582
|
-
*/
|
|
2583
|
-
type RouteLocationAsPath<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsPathGeneric : RouteLocationAsPathTypedList<RouteMap>[Name];
|
|
2584
|
-
/**
|
|
2585
|
-
* Route location that can be passed to `router.push()` and other user-facing APIs.
|
|
2586
|
-
*/
|
|
2587
|
-
type RouteLocationRaw<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsString | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric : _LiteralUnion<RouteLocationAsStringTypedList<RouteMap>[Name], string> | RouteLocationAsRelativeTypedList<RouteMap>[Name] | RouteLocationAsPathTypedList<RouteMap>[Name];
|
|
2588
|
-
//#endregion
|
|
2589
|
-
//#region src/typed-routes/navigation-guards.d.ts
|
|
2590
|
-
/**
|
|
2591
|
-
* Return types for a Navigation Guard. Based on `TypesConfig`
|
|
2592
|
-
*
|
|
2593
|
-
* @see {@link TypesConfig}
|
|
2594
|
-
*/
|
|
2595
|
-
type NavigationGuardReturn = void | Error | boolean | RouteLocationRaw;
|
|
2596
|
-
/**
|
|
2597
|
-
* Navigation Guard with a type parameter for `this`.
|
|
2598
|
-
* @see {@link TypesConfig}
|
|
2599
|
-
*/
|
|
2600
|
-
interface NavigationGuardWithThis<T$1> {
|
|
2601
|
-
(this: T$1, to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, next: NavigationGuardNext): _Awaitable<NavigationGuardReturn>;
|
|
2602
|
-
}
|
|
2603
|
-
/**
|
|
2604
|
-
* Navigation Guard.
|
|
2605
|
-
*/
|
|
2606
|
-
interface NavigationGuard {
|
|
2607
|
-
(to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, next: NavigationGuardNext): _Awaitable<NavigationGuardReturn>;
|
|
2608
|
-
}
|
|
2609
|
-
/**
|
|
2610
|
-
* Navigation hook triggered after a navigation is settled.
|
|
2611
|
-
*/
|
|
2612
|
-
interface NavigationHookAfter {
|
|
2613
|
-
(to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, failure?: NavigationFailure | void): unknown;
|
|
2614
|
-
}
|
|
2615
|
-
/**
|
|
2616
|
-
* `next()` callback passed to navigation guards.
|
|
2617
|
-
*/
|
|
2618
|
-
interface NavigationGuardNext {
|
|
2619
|
-
(): void;
|
|
2620
|
-
(error: Error): void;
|
|
2621
|
-
(location: RouteLocationRaw): void;
|
|
2622
|
-
(valid: boolean | undefined): void;
|
|
2623
|
-
(cb: NavigationGuardNextCallback): void;
|
|
2624
|
-
}
|
|
2625
|
-
/**
|
|
2626
|
-
* Callback that can be passed to `next()` in `beforeRouteEnter()` guards.
|
|
2627
|
-
*/
|
|
2628
|
-
type NavigationGuardNextCallback = (vm: ComponentPublicInstance) => unknown;
|
|
2629
|
-
//#endregion
|
|
2630
|
-
//#region src/matcher/types.d.ts
|
|
2631
|
-
/**
|
|
2632
|
-
* Normalized version of a {@link RouteRecord | route record}.
|
|
2633
|
-
*/
|
|
2634
|
-
interface RouteRecordNormalized {
|
|
2635
|
-
/**
|
|
2636
|
-
* {@inheritDoc _RouteRecordBase.path}
|
|
2637
|
-
*/
|
|
2638
|
-
path: _RouteRecordBase['path'];
|
|
2639
|
-
/**
|
|
2640
|
-
* {@inheritDoc _RouteRecordBase.redirect}
|
|
2641
|
-
*/
|
|
2642
|
-
redirect: _RouteRecordBase['redirect'] | undefined;
|
|
2643
|
-
/**
|
|
2644
|
-
* {@inheritDoc _RouteRecordBase.name}
|
|
2645
|
-
*/
|
|
2646
|
-
name: _RouteRecordBase['name'];
|
|
2647
|
-
/**
|
|
2648
|
-
* {@inheritDoc RouteRecordMultipleViews.components}
|
|
2649
|
-
*/
|
|
2650
|
-
components: RouteRecordMultipleViews['components'] | null | undefined;
|
|
2651
|
-
/**
|
|
2652
|
-
* Contains the original modules for lazy loaded components.
|
|
2653
|
-
* @internal
|
|
2654
|
-
*/
|
|
2655
|
-
mods: Record<string, unknown>;
|
|
2656
|
-
/**
|
|
2657
|
-
* Nested route records.
|
|
2658
|
-
*/
|
|
2659
|
-
children: RouteRecordRaw[];
|
|
2660
|
-
/**
|
|
2661
|
-
* {@inheritDoc _RouteRecordBase.meta}
|
|
2662
|
-
*/
|
|
2663
|
-
meta: Exclude<_RouteRecordBase['meta'], void>;
|
|
2664
|
-
/**
|
|
2665
|
-
* {@inheritDoc RouteRecordMultipleViews.props}
|
|
2666
|
-
*/
|
|
2667
|
-
props: Record<string, _RouteRecordProps>;
|
|
2668
|
-
/**
|
|
2669
|
-
* Registered beforeEnter guards
|
|
2670
|
-
*/
|
|
2671
|
-
beforeEnter: _RouteRecordBase['beforeEnter'];
|
|
2672
|
-
/**
|
|
2673
|
-
* Registered leave guards
|
|
2674
|
-
*
|
|
2675
|
-
* @internal
|
|
2676
|
-
*/
|
|
2677
|
-
leaveGuards: Set<NavigationGuard>;
|
|
2678
|
-
/**
|
|
2679
|
-
* Registered update guards
|
|
2680
|
-
*
|
|
2681
|
-
* @internal
|
|
2682
|
-
*/
|
|
2683
|
-
updateGuards: Set<NavigationGuard>;
|
|
2684
|
-
/**
|
|
2685
|
-
* Registered beforeRouteEnter callbacks passed to `next` or returned in guards
|
|
2686
|
-
*
|
|
2687
|
-
* @internal
|
|
2688
|
-
*/
|
|
2689
|
-
enterCallbacks: Record<string, NavigationGuardNextCallback[]>;
|
|
2690
|
-
/**
|
|
2691
|
-
* Mounted route component instances
|
|
2692
|
-
* Having the instances on the record mean beforeRouteUpdate and
|
|
2693
|
-
* beforeRouteLeave guards can only be invoked with the latest mounted app
|
|
2694
|
-
* instance if there are multiple application instances rendering the same
|
|
2695
|
-
* view, basically duplicating the content on the page, which shouldn't happen
|
|
2696
|
-
* in practice. It will work if multiple apps are rendering different named
|
|
2697
|
-
* views.
|
|
2698
|
-
*/
|
|
2699
|
-
instances: Record<string, ComponentPublicInstance | undefined | null>;
|
|
2700
|
-
/**
|
|
2701
|
-
* Defines if this record is the alias of another one. This property is
|
|
2702
|
-
* `undefined` if the record is the original one.
|
|
2703
|
-
*/
|
|
2704
|
-
aliasOf: RouteRecordNormalized | undefined;
|
|
2705
|
-
}
|
|
2706
|
-
/**
|
|
2707
|
-
* {@inheritDoc RouteRecordNormalized}
|
|
2708
|
-
*/
|
|
2709
|
-
type RouteRecord = RouteRecordNormalized;
|
|
2710
|
-
//#endregion
|
|
2711
|
-
//#region src/matcher/pathParserRanker.d.ts
|
|
2712
|
-
|
|
2713
|
-
/**
|
|
2714
|
-
* @internal
|
|
2715
|
-
*/
|
|
2716
|
-
interface _PathParserOptions {
|
|
2717
|
-
/**
|
|
2718
|
-
* Makes the RegExp case-sensitive.
|
|
2719
|
-
*
|
|
2720
|
-
* @defaultValue `false`
|
|
2721
|
-
*/
|
|
2722
|
-
sensitive?: boolean;
|
|
2723
|
-
/**
|
|
2724
|
-
* Whether to disallow a trailing slash or not.
|
|
2725
|
-
*
|
|
2726
|
-
* @defaultValue `false`
|
|
2727
|
-
*/
|
|
2728
|
-
strict?: boolean;
|
|
2729
|
-
/**
|
|
2730
|
-
* Should the RegExp match from the beginning by prepending a `^` to it.
|
|
2731
|
-
* @internal
|
|
2732
|
-
*
|
|
2733
|
-
* @defaultValue `true`
|
|
2734
|
-
*/
|
|
2735
|
-
start?: boolean;
|
|
2736
|
-
/**
|
|
2737
|
-
* Should the RegExp match until the end by appending a `$` to it.
|
|
2738
|
-
*
|
|
2739
|
-
* @deprecated this option will alsways be `true` in the future. Open a discussion in vuejs/router if you need this to be `false`
|
|
2740
|
-
*
|
|
2741
|
-
* @defaultValue `true`
|
|
2742
|
-
*/
|
|
2743
|
-
end?: boolean;
|
|
2744
|
-
}
|
|
2745
|
-
type PathParserOptions = Pick<_PathParserOptions, 'end' | 'sensitive' | 'strict'>;
|
|
2746
|
-
//#endregion
|
|
2747
|
-
//#region src/matcher/pathMatcher.d.ts
|
|
2748
|
-
|
|
2749
|
-
//#endregion
|
|
2750
|
-
//#region src/history/common.d.ts
|
|
2751
|
-
type HistoryLocation = string;
|
|
2752
|
-
/**
|
|
2753
|
-
* Allowed variables in HTML5 history state. Note that pushState clones the state
|
|
2754
|
-
* passed and does not accept everything: e.g.: it doesn't accept symbols, nor
|
|
2755
|
-
* functions as values. It also ignores Symbols as keys.
|
|
2756
|
-
*
|
|
2757
|
-
* @internal
|
|
2758
|
-
*/
|
|
2759
|
-
type HistoryStateValue = string | number | boolean | null | undefined | HistoryState | HistoryStateArray;
|
|
2760
|
-
/**
|
|
2761
|
-
* Allowed HTML history.state
|
|
2762
|
-
*/
|
|
2763
|
-
interface HistoryState {
|
|
2764
|
-
[x: number]: HistoryStateValue;
|
|
2765
|
-
[x: string]: HistoryStateValue;
|
|
2766
|
-
}
|
|
2767
|
-
/**
|
|
2768
|
-
* Allowed arrays for history.state.
|
|
2769
|
-
*
|
|
2770
|
-
* @internal
|
|
2771
|
-
*/
|
|
2772
|
-
interface HistoryStateArray extends Array<HistoryStateValue> {}
|
|
2773
|
-
declare enum NavigationType {
|
|
2774
|
-
pop = "pop",
|
|
2775
|
-
push = "push",
|
|
2776
|
-
}
|
|
2777
|
-
declare enum NavigationDirection {
|
|
2778
|
-
back = "back",
|
|
2779
|
-
forward = "forward",
|
|
2780
|
-
unknown = "",
|
|
2781
|
-
}
|
|
2782
|
-
interface NavigationInformation {
|
|
2783
|
-
type: NavigationType;
|
|
2784
|
-
direction: NavigationDirection;
|
|
2785
|
-
delta: number;
|
|
2786
|
-
}
|
|
2787
|
-
interface NavigationCallback {
|
|
2788
|
-
(to: HistoryLocation, from: HistoryLocation, information: NavigationInformation): void;
|
|
2789
|
-
}
|
|
2790
|
-
/**
|
|
2791
|
-
* Interface implemented by History implementations that can be passed to the
|
|
2792
|
-
* router as {@link Router.history}
|
|
2793
|
-
*
|
|
2794
|
-
* @alpha
|
|
2795
|
-
*/
|
|
2796
|
-
interface RouterHistory {
|
|
2797
|
-
/**
|
|
2798
|
-
* Base path that is prepended to every url. This allows hosting an SPA at a
|
|
2799
|
-
* sub-folder of a domain like `example.com/sub-folder` by having a `base` of
|
|
2800
|
-
* `/sub-folder`
|
|
2801
|
-
*/
|
|
2802
|
-
readonly base: string;
|
|
2803
|
-
/**
|
|
2804
|
-
* Current History location
|
|
2805
|
-
*/
|
|
2806
|
-
readonly location: HistoryLocation;
|
|
2807
|
-
/**
|
|
2808
|
-
* Current History state
|
|
2809
|
-
*/
|
|
2810
|
-
readonly state: HistoryState;
|
|
2811
|
-
/**
|
|
2812
|
-
* Navigates to a location. In the case of an HTML5 History implementation,
|
|
2813
|
-
* this will call `history.pushState` to effectively change the URL.
|
|
2814
|
-
*
|
|
2815
|
-
* @param to - location to push
|
|
2816
|
-
* @param data - optional {@link HistoryState} to be associated with the
|
|
2817
|
-
* navigation entry
|
|
2818
|
-
*/
|
|
2819
|
-
push(to: HistoryLocation, data?: HistoryState): void;
|
|
2820
|
-
/**
|
|
2821
|
-
* Same as {@link RouterHistory.push} but performs a `history.replaceState`
|
|
2822
|
-
* instead of `history.pushState`
|
|
2823
|
-
*
|
|
2824
|
-
* @param to - location to set
|
|
2825
|
-
* @param data - optional {@link HistoryState} to be associated with the
|
|
2826
|
-
* navigation entry
|
|
2827
|
-
*/
|
|
2828
|
-
replace(to: HistoryLocation, data?: HistoryState): void;
|
|
2829
|
-
/**
|
|
2830
|
-
* Traverses history in a given direction.
|
|
2831
|
-
*
|
|
2832
|
-
* @example
|
|
2833
|
-
* ```js
|
|
2834
|
-
* myHistory.go(-1) // equivalent to window.history.back()
|
|
2835
|
-
* myHistory.go(1) // equivalent to window.history.forward()
|
|
2836
|
-
* ```
|
|
2837
|
-
*
|
|
2838
|
-
* @param delta - distance to travel. If delta is \< 0, it will go back,
|
|
2839
|
-
* if it's \> 0, it will go forward by that amount of entries.
|
|
2840
|
-
* @param triggerListeners - whether this should trigger listeners attached to
|
|
2841
|
-
* the history
|
|
2842
|
-
*/
|
|
2843
|
-
go(delta: number, triggerListeners?: boolean): void;
|
|
2844
|
-
/**
|
|
2845
|
-
* Attach a listener to the History implementation that is triggered when the
|
|
2846
|
-
* navigation is triggered from outside (like the Browser back and forward
|
|
2847
|
-
* buttons) or when passing `true` to {@link RouterHistory.back} and
|
|
2848
|
-
* {@link RouterHistory.forward}
|
|
2849
|
-
*
|
|
2850
|
-
* @param callback - listener to attach
|
|
2851
|
-
* @returns a callback to remove the listener
|
|
2852
|
-
*/
|
|
2853
|
-
listen(callback: NavigationCallback): () => void;
|
|
2854
|
-
/**
|
|
2855
|
-
* Generates the corresponding href to be used in an anchor tag.
|
|
2856
|
-
*
|
|
2857
|
-
* @param location - history location that should create an href
|
|
2858
|
-
*/
|
|
2859
|
-
createHref(location: HistoryLocation): string;
|
|
2860
|
-
/**
|
|
2861
|
-
* Clears any event listener attached by the history implementation.
|
|
2862
|
-
*/
|
|
2863
|
-
destroy(): void;
|
|
2864
|
-
}
|
|
2865
|
-
//#endregion
|
|
2866
|
-
//#region src/types/index.d.ts
|
|
2867
|
-
type Lazy<T$1> = () => Promise<T$1>;
|
|
2868
|
-
/**
|
|
2869
|
-
* @internal
|
|
2870
|
-
*/
|
|
2871
|
-
type RouteParamValue = string;
|
|
2872
|
-
/**
|
|
2873
|
-
* @internal
|
|
2874
|
-
*/
|
|
2875
|
-
type RouteParamValueRaw = RouteParamValue | number | null | undefined;
|
|
2876
|
-
type RouteParamsGeneric = Record<string, RouteParamValue | RouteParamValue[]>;
|
|
2877
|
-
type RouteParamsRawGeneric = Record<string, RouteParamValueRaw | Exclude<RouteParamValueRaw, null | undefined>[]>;
|
|
2878
|
-
/**
|
|
2879
|
-
* @internal
|
|
2880
|
-
*/
|
|
2881
|
-
interface RouteQueryAndHash {
|
|
2882
|
-
query?: LocationQueryRaw;
|
|
2883
|
-
hash?: string;
|
|
2884
|
-
}
|
|
2885
|
-
/**
|
|
2886
|
-
* @internal
|
|
2887
|
-
*/
|
|
2888
|
-
|
|
2889
|
-
/**
|
|
2890
|
-
* Common options for all navigation methods.
|
|
2891
|
-
*/
|
|
2892
|
-
interface RouteLocationOptions {
|
|
2893
|
-
/**
|
|
2894
|
-
* Replace the entry in the history instead of pushing a new entry
|
|
2895
|
-
*/
|
|
2896
|
-
replace?: boolean;
|
|
2897
|
-
/**
|
|
2898
|
-
* Triggers the navigation even if the location is the same as the current one.
|
|
2899
|
-
* Note this will also add a new entry to the history unless `replace: true`
|
|
2900
|
-
* is passed.
|
|
2901
|
-
*/
|
|
2902
|
-
force?: boolean;
|
|
2903
|
-
/**
|
|
2904
|
-
* State to save using the History API. This cannot contain any reactive
|
|
2905
|
-
* values and some primitives like Symbols are forbidden. More info at
|
|
2906
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/History/state
|
|
2907
|
-
*/
|
|
2908
|
-
state?: HistoryState;
|
|
2909
|
-
}
|
|
2910
|
-
/**
|
|
2911
|
-
* Route Location that can infer the necessary params based on the name.
|
|
2912
|
-
*
|
|
2913
|
-
* @internal
|
|
2914
|
-
*/
|
|
2915
|
-
|
|
2916
|
-
interface RouteLocationMatched extends RouteRecordNormalized {
|
|
2917
|
-
components: Record<string, RouteComponent> | null | undefined;
|
|
2918
|
-
}
|
|
2919
|
-
/**
|
|
2920
|
-
* Base properties for a normalized route location.
|
|
2921
|
-
*
|
|
2922
|
-
* @internal
|
|
2923
|
-
*/
|
|
2924
|
-
interface _RouteLocationBase extends Pick<MatcherLocation, 'name' | 'path' | 'params' | 'meta'> {
|
|
2925
|
-
/**
|
|
2926
|
-
* The whole location including the `search` and `hash`. This string is
|
|
2927
|
-
* percentage encoded.
|
|
2928
|
-
*/
|
|
2929
|
-
fullPath: string;
|
|
2930
|
-
/**
|
|
2931
|
-
* Object representation of the `search` property of the current location.
|
|
2932
|
-
*/
|
|
2933
|
-
query: LocationQuery;
|
|
2934
|
-
/**
|
|
2935
|
-
* Hash of the current location. If present, starts with a `#`.
|
|
2936
|
-
*/
|
|
2937
|
-
hash: string;
|
|
2938
|
-
/**
|
|
2939
|
-
* Contains the location we were initially trying to access before ending up
|
|
2940
|
-
* on the current location.
|
|
2941
|
-
*/
|
|
2942
|
-
redirectedFrom: RouteLocation | undefined;
|
|
2943
|
-
}
|
|
2944
|
-
/**
|
|
2945
|
-
* Allowed Component in {@link RouteLocationMatched}
|
|
2946
|
-
*/
|
|
2947
|
-
type RouteComponent = Component$1 | DefineComponent;
|
|
2948
|
-
/**
|
|
2949
|
-
* Allowed Component definitions in route records provided by the user
|
|
2950
|
-
*/
|
|
2951
|
-
type RawRouteComponent = RouteComponent | Lazy<RouteComponent>;
|
|
2952
|
-
/**
|
|
2953
|
-
* Internal type for common properties among all kind of {@link RouteRecordRaw}.
|
|
2954
|
-
*/
|
|
2955
|
-
interface _RouteRecordBase extends PathParserOptions {
|
|
2956
|
-
/**
|
|
2957
|
-
* Path of the record. Should start with `/` unless the record is the child of
|
|
2958
|
-
* another record.
|
|
2959
|
-
*
|
|
2960
|
-
* @example `/users/:id` matches `/users/1` as well as `/users/posva`.
|
|
2961
|
-
*/
|
|
2962
|
-
path: string;
|
|
2963
|
-
/**
|
|
2964
|
-
* Where to redirect if the route is directly matched. The redirection happens
|
|
2965
|
-
* before any navigation guard and triggers a new navigation with the new
|
|
2966
|
-
* target location.
|
|
2967
|
-
*/
|
|
2968
|
-
redirect?: RouteRecordRedirectOption;
|
|
2969
|
-
/**
|
|
2970
|
-
* Aliases for the record. Allows defining extra paths that will behave like a
|
|
2971
|
-
* copy of the record. Allows having paths shorthands like `/users/:id` and
|
|
2972
|
-
* `/u/:id`. All `alias` and `path` values must share the same params.
|
|
2973
|
-
*/
|
|
2974
|
-
alias?: string | string[];
|
|
2975
|
-
/**
|
|
2976
|
-
* Name for the route record. Must be unique.
|
|
2977
|
-
*/
|
|
2978
|
-
name?: RouteRecordNameGeneric;
|
|
2979
|
-
/**
|
|
2980
|
-
* Before Enter guard specific to this record. Note `beforeEnter` has no
|
|
2981
|
-
* effect if the record has a `redirect` property.
|
|
2982
|
-
*/
|
|
2983
|
-
beforeEnter?: NavigationGuardWithThis<undefined> | NavigationGuardWithThis<undefined>[];
|
|
2984
|
-
/**
|
|
2985
|
-
* Arbitrary data attached to the record.
|
|
2986
|
-
*/
|
|
2987
|
-
meta?: RouteMeta;
|
|
2988
|
-
/**
|
|
2989
|
-
* Array of nested routes.
|
|
2990
|
-
*/
|
|
2991
|
-
children?: RouteRecordRaw[];
|
|
2992
|
-
/**
|
|
2993
|
-
* Allow passing down params as props to the component rendered by `router-view`.
|
|
2994
|
-
*/
|
|
2995
|
-
props?: _RouteRecordProps | Record<string, _RouteRecordProps>;
|
|
2996
|
-
}
|
|
2997
|
-
/**
|
|
2998
|
-
* Interface to type `meta` fields in route records.
|
|
2999
|
-
*
|
|
3000
|
-
* @example
|
|
3001
|
-
*
|
|
3002
|
-
* ```ts
|
|
3003
|
-
* // typings.d.ts or router.ts
|
|
3004
|
-
* import 'vue-router';
|
|
3005
|
-
*
|
|
3006
|
-
* declare module 'vue-router' {
|
|
3007
|
-
* interface RouteMeta {
|
|
3008
|
-
* requiresAuth?: boolean
|
|
3009
|
-
* }
|
|
3010
|
-
* }
|
|
3011
|
-
* ```
|
|
3012
|
-
*/
|
|
3013
|
-
interface RouteMeta extends Record<PropertyKey, unknown> {}
|
|
3014
|
-
/**
|
|
3015
|
-
* Route Record defining one single component with the `component` option.
|
|
3016
|
-
*/
|
|
3017
|
-
interface RouteRecordSingleView extends _RouteRecordBase {
|
|
3018
|
-
/**
|
|
3019
|
-
* Component to display when the URL matches this route.
|
|
3020
|
-
*/
|
|
3021
|
-
component: RawRouteComponent;
|
|
3022
|
-
components?: never;
|
|
3023
|
-
children?: never;
|
|
3024
|
-
redirect?: never;
|
|
3025
|
-
/**
|
|
3026
|
-
* Allow passing down params as props to the component rendered by `router-view`.
|
|
3027
|
-
*/
|
|
3028
|
-
props?: _RouteRecordProps;
|
|
3029
|
-
}
|
|
3030
|
-
/**
|
|
3031
|
-
* Route Record defining one single component with a nested view. Differently
|
|
3032
|
-
* from {@link RouteRecordSingleView}, this record has children and allows a
|
|
3033
|
-
* `redirect` option.
|
|
3034
|
-
*/
|
|
3035
|
-
interface RouteRecordSingleViewWithChildren extends _RouteRecordBase {
|
|
3036
|
-
/**
|
|
3037
|
-
* Component to display when the URL matches this route.
|
|
3038
|
-
*/
|
|
3039
|
-
component?: RawRouteComponent | null | undefined;
|
|
3040
|
-
components?: never;
|
|
3041
|
-
children: RouteRecordRaw[];
|
|
3042
|
-
/**
|
|
3043
|
-
* Allow passing down params as props to the component rendered by `router-view`.
|
|
3044
|
-
*/
|
|
3045
|
-
props?: _RouteRecordProps;
|
|
3046
|
-
}
|
|
3047
|
-
/**
|
|
3048
|
-
* Route Record defining multiple named components with the `components` option.
|
|
3049
|
-
*/
|
|
3050
|
-
interface RouteRecordMultipleViews extends _RouteRecordBase {
|
|
3051
|
-
/**
|
|
3052
|
-
* Components to display when the URL matches this route. Allow using named views.
|
|
3053
|
-
*/
|
|
3054
|
-
components: Record<string, RawRouteComponent>;
|
|
3055
|
-
component?: never;
|
|
3056
|
-
children?: never;
|
|
3057
|
-
redirect?: never;
|
|
3058
|
-
/**
|
|
3059
|
-
* Allow passing down params as props to the component rendered by
|
|
3060
|
-
* `router-view`. Should be an object with the same keys as `components` or a
|
|
3061
|
-
* boolean to be applied to every component.
|
|
3062
|
-
*/
|
|
3063
|
-
props?: Record<string, _RouteRecordProps> | boolean;
|
|
3064
|
-
}
|
|
3065
|
-
/**
|
|
3066
|
-
* Route Record defining multiple named components with the `components` option and children.
|
|
3067
|
-
*/
|
|
3068
|
-
interface RouteRecordMultipleViewsWithChildren extends _RouteRecordBase {
|
|
3069
|
-
/**
|
|
3070
|
-
* Components to display when the URL matches this route. Allow using named views.
|
|
3071
|
-
*/
|
|
3072
|
-
components?: Record<string, RawRouteComponent> | null | undefined;
|
|
3073
|
-
component?: never;
|
|
3074
|
-
children: RouteRecordRaw[];
|
|
3075
|
-
/**
|
|
3076
|
-
* Allow passing down params as props to the component rendered by
|
|
3077
|
-
* `router-view`. Should be an object with the same keys as `components` or a
|
|
3078
|
-
* boolean to be applied to every component.
|
|
3079
|
-
*/
|
|
3080
|
-
props?: Record<string, _RouteRecordProps> | boolean;
|
|
3081
|
-
}
|
|
3082
|
-
/**
|
|
3083
|
-
* Route Record that defines a redirect. Cannot have `component` or `components`
|
|
3084
|
-
* as it is never rendered.
|
|
3085
|
-
*/
|
|
3086
|
-
interface RouteRecordRedirect extends _RouteRecordBase {
|
|
3087
|
-
redirect: RouteRecordRedirectOption;
|
|
3088
|
-
component?: never;
|
|
3089
|
-
components?: never;
|
|
3090
|
-
props?: never;
|
|
3091
|
-
}
|
|
3092
|
-
type RouteRecordRaw = RouteRecordSingleView | RouteRecordSingleViewWithChildren | RouteRecordMultipleViews | RouteRecordMultipleViewsWithChildren | RouteRecordRedirect;
|
|
3093
|
-
/**
|
|
3094
|
-
* Route location that can be passed to the matcher.
|
|
3095
|
-
*/
|
|
3096
|
-
|
|
3097
|
-
/**
|
|
3098
|
-
* Normalized/resolved Route location that returned by the matcher.
|
|
3099
|
-
*/
|
|
3100
|
-
interface MatcherLocation {
|
|
3101
|
-
/**
|
|
3102
|
-
* Name of the matched record
|
|
3103
|
-
*/
|
|
3104
|
-
name: RouteRecordNameGeneric | null | undefined;
|
|
3105
|
-
/**
|
|
3106
|
-
* Percentage encoded pathname section of the URL.
|
|
3107
|
-
*/
|
|
3108
|
-
path: string;
|
|
3109
|
-
/**
|
|
3110
|
-
* Object of decoded params extracted from the `path`.
|
|
3111
|
-
*/
|
|
3112
|
-
params: RouteParamsGeneric;
|
|
3113
|
-
/**
|
|
3114
|
-
* Merged `meta` properties from all the matched route records.
|
|
3115
|
-
*/
|
|
3116
|
-
meta: RouteMeta;
|
|
3117
|
-
/**
|
|
3118
|
-
* Array of {@link RouteRecord} containing components as they were
|
|
3119
|
-
* passed when adding records. It can also contain redirect records. This
|
|
3120
|
-
* can't be used directly
|
|
3121
|
-
*/
|
|
3122
|
-
matched: RouteRecord[];
|
|
3123
|
-
}
|
|
3124
|
-
//#endregion
|
|
3125
|
-
//#region src/errors.d.ts
|
|
3126
|
-
/**
|
|
3127
|
-
* Flags so we can combine them when checking for multiple errors. This is the internal version of
|
|
3128
|
-
* {@link NavigationFailureType}.
|
|
3129
|
-
*
|
|
3130
|
-
* @internal
|
|
3131
|
-
*/
|
|
3132
|
-
declare const enum ErrorTypes {
|
|
3133
|
-
MATCHER_NOT_FOUND = 1,
|
|
3134
|
-
NAVIGATION_GUARD_REDIRECT = 2,
|
|
3135
|
-
NAVIGATION_ABORTED = 4,
|
|
3136
|
-
NAVIGATION_CANCELLED = 8,
|
|
3137
|
-
NAVIGATION_DUPLICATED = 16,
|
|
3138
|
-
}
|
|
3139
|
-
/**
|
|
3140
|
-
* Enumeration with all possible types for navigation failures. Can be passed to
|
|
3141
|
-
* {@link isNavigationFailure} to check for specific failures.
|
|
3142
|
-
*/
|
|
3143
|
-
|
|
3144
|
-
/**
|
|
3145
|
-
* Extended Error that contains extra information regarding a failed navigation.
|
|
3146
|
-
*/
|
|
3147
|
-
interface NavigationFailure extends Error {
|
|
3148
|
-
/**
|
|
3149
|
-
* Type of the navigation. One of {@link NavigationFailureType}
|
|
3150
|
-
*/
|
|
3151
|
-
type: ErrorTypes.NAVIGATION_CANCELLED | ErrorTypes.NAVIGATION_ABORTED | ErrorTypes.NAVIGATION_DUPLICATED;
|
|
3152
|
-
/**
|
|
3153
|
-
* Route location we were navigating from
|
|
3154
|
-
*/
|
|
3155
|
-
from: RouteLocationNormalized;
|
|
3156
|
-
/**
|
|
3157
|
-
* Route location we were navigating to
|
|
3158
|
-
*/
|
|
3159
|
-
to: RouteLocationNormalized;
|
|
3160
|
-
}
|
|
3161
|
-
/**
|
|
3162
|
-
* Internal error used to detect a redirection.
|
|
3163
|
-
*
|
|
3164
|
-
* @internal
|
|
3165
|
-
*/
|
|
3166
|
-
|
|
3167
|
-
/**
|
|
3168
|
-
* Internal type to define an ErrorHandler
|
|
3169
|
-
*
|
|
3170
|
-
* @param error - error thrown
|
|
3171
|
-
* @param to - location we were navigating to when the error happened
|
|
3172
|
-
* @param from - location we were navigating from when the error happened
|
|
3173
|
-
* @internal
|
|
3174
|
-
*/
|
|
3175
|
-
interface _ErrorListener {
|
|
3176
|
-
(error: any, to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded): any;
|
|
3177
|
-
}
|
|
3178
|
-
//#endregion
|
|
3179
|
-
//#region src/scrollBehavior.d.ts
|
|
3180
|
-
/**
|
|
3181
|
-
* Scroll position similar to
|
|
3182
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions | `ScrollToOptions`}.
|
|
3183
|
-
* Note that not all browsers support `behavior`.
|
|
3184
|
-
*/
|
|
3185
|
-
type ScrollPositionCoordinates = {
|
|
3186
|
-
behavior?: ScrollOptions['behavior'];
|
|
3187
|
-
left?: number;
|
|
3188
|
-
top?: number;
|
|
3189
|
-
};
|
|
3190
|
-
/**
|
|
3191
|
-
* Internal normalized version of {@link ScrollPositionCoordinates} that always
|
|
3192
|
-
* has `left` and `top` coordinates. Must be a type to be assignable to HistoryStateValue.
|
|
3193
|
-
*
|
|
3194
|
-
* @internal
|
|
3195
|
-
*/
|
|
3196
|
-
type _ScrollPositionNormalized = {
|
|
3197
|
-
behavior?: ScrollOptions['behavior'];
|
|
3198
|
-
left: number;
|
|
3199
|
-
top: number;
|
|
3200
|
-
};
|
|
3201
|
-
/**
|
|
3202
|
-
* Type of the `scrollBehavior` option that can be passed to `createRouter`.
|
|
3203
|
-
*/
|
|
3204
|
-
interface RouterScrollBehavior {
|
|
3205
|
-
/**
|
|
3206
|
-
* @param to - Route location where we are navigating to
|
|
3207
|
-
* @param from - Route location where we are navigating from
|
|
3208
|
-
* @param savedPosition - saved position if it exists, `null` otherwise
|
|
3209
|
-
*/
|
|
3210
|
-
(to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, savedPosition: _ScrollPositionNormalized | null): Awaitable<ScrollPosition | false | void>;
|
|
3211
|
-
}
|
|
3212
|
-
interface ScrollPositionElement extends ScrollToOptions {
|
|
3213
|
-
/**
|
|
3214
|
-
* A valid CSS selector. Note some characters must be escaped in id selectors (https://mathiasbynens.be/notes/css-escapes).
|
|
3215
|
-
* @example
|
|
3216
|
-
* Here are a few examples:
|
|
3217
|
-
*
|
|
3218
|
-
* - `.title`
|
|
3219
|
-
* - `.content:first-child`
|
|
3220
|
-
* - `#marker`
|
|
3221
|
-
* - `#marker\~with\~symbols`
|
|
3222
|
-
* - `#marker.with.dot`: selects `class="with dot" id="marker"`, not `id="marker.with.dot"`
|
|
3223
|
-
*
|
|
3224
|
-
*/
|
|
3225
|
-
el: string | Element;
|
|
3226
|
-
}
|
|
3227
|
-
type ScrollPosition = ScrollPositionCoordinates | ScrollPositionElement;
|
|
3228
|
-
type Awaitable<T$1> = T$1 | PromiseLike<T$1>;
|
|
3229
|
-
//#endregion
|
|
3230
|
-
//#region src/experimental/route-resolver/matchers/param-parsers/types.d.ts
|
|
3231
|
-
/**
|
|
3232
|
-
* Defines a parser that can read a param from the url (string-based) and
|
|
3233
|
-
* transform it into a more complex type, or vice versa.
|
|
3234
|
-
*
|
|
3235
|
-
* @see MatcherPattern
|
|
3236
|
-
*/
|
|
3237
|
-
|
|
3238
|
-
//#endregion
|
|
3239
|
-
//#region src/experimental/router.d.ts
|
|
3240
|
-
/**
|
|
3241
|
-
* Options to initialize a {@link Router} instance.
|
|
3242
|
-
*/
|
|
3243
|
-
interface EXPERIMENTAL_RouterOptions_Base extends PathParserOptions {
|
|
3244
|
-
/**
|
|
3245
|
-
* History implementation used by the router. Most web applications should use
|
|
3246
|
-
* `createWebHistory` but it requires the server to be properly configured.
|
|
3247
|
-
* You can also use a _hash_ based history with `createWebHashHistory` that
|
|
3248
|
-
* does not require any configuration on the server but isn't handled at all
|
|
3249
|
-
* by search engines and does poorly on SEO.
|
|
3250
|
-
*
|
|
3251
|
-
* @example
|
|
3252
|
-
* ```js
|
|
3253
|
-
* createRouter({
|
|
3254
|
-
* history: createWebHistory(),
|
|
3255
|
-
* // other options...
|
|
3256
|
-
* })
|
|
3257
|
-
* ```
|
|
3258
|
-
*/
|
|
3259
|
-
history: RouterHistory;
|
|
3260
|
-
/**
|
|
3261
|
-
* Function to control scrolling when navigating between pages. Can return a
|
|
3262
|
-
* Promise to delay scrolling.
|
|
3263
|
-
*
|
|
3264
|
-
* @see {@link RouterScrollBehavior}.
|
|
3265
|
-
*
|
|
3266
|
-
* @example
|
|
3267
|
-
* ```js
|
|
3268
|
-
* function scrollBehavior(to, from, savedPosition) {
|
|
3269
|
-
* // `to` and `from` are both route locations
|
|
3270
|
-
* // `savedPosition` can be null if there isn't one
|
|
3271
|
-
* }
|
|
3272
|
-
* ```
|
|
3273
|
-
*/
|
|
3274
|
-
scrollBehavior?: RouterScrollBehavior;
|
|
3275
|
-
/**
|
|
3276
|
-
* Custom implementation to parse a query. See its counterpart,
|
|
3277
|
-
* {@link EXPERIMENTAL_RouterOptions_Base.stringifyQuery}.
|
|
3278
|
-
*
|
|
3279
|
-
* @example
|
|
3280
|
-
* Let's say you want to use the [qs package](https://github.com/ljharb/qs)
|
|
3281
|
-
* to parse queries, you can provide both `parseQuery` and `stringifyQuery`:
|
|
3282
|
-
* ```js
|
|
3283
|
-
* import qs from 'qs'
|
|
3284
|
-
*
|
|
3285
|
-
* createRouter({
|
|
3286
|
-
* // other options...
|
|
3287
|
-
* parseQuery: qs.parse,
|
|
3288
|
-
* stringifyQuery: qs.stringify,
|
|
3289
|
-
* })
|
|
3290
|
-
* ```
|
|
3291
|
-
*/
|
|
3292
|
-
parseQuery?: typeof parseQuery;
|
|
3293
|
-
/**
|
|
3294
|
-
* Custom implementation to stringify a query object. Should not prepend a leading `?`.
|
|
3295
|
-
* {@link parseQuery} counterpart to handle query parsing.
|
|
3296
|
-
*/
|
|
3297
|
-
stringifyQuery?: typeof stringifyQuery;
|
|
3298
|
-
/**
|
|
3299
|
-
* Default class applied to active {@link RouterLink}. If none is provided,
|
|
3300
|
-
* `router-link-active` will be applied.
|
|
3301
|
-
*/
|
|
3302
|
-
linkActiveClass?: string;
|
|
3303
|
-
/**
|
|
3304
|
-
* Default class applied to exact active {@link RouterLink}. If none is provided,
|
|
3305
|
-
* `router-link-exact-active` will be applied.
|
|
3306
|
-
*/
|
|
3307
|
-
linkExactActiveClass?: string;
|
|
3308
|
-
}
|
|
3309
|
-
/**
|
|
3310
|
-
* Internal type for common properties among all kind of {@link RouteRecordRaw}.
|
|
3311
|
-
*/
|
|
3312
|
-
|
|
3313
|
-
/**
|
|
3314
|
-
* Router base instance.
|
|
3315
|
-
*
|
|
3316
|
-
* @experimental This version is not stable, it's meant to replace {@link Router} in the future.
|
|
3317
|
-
*/
|
|
3318
|
-
interface EXPERIMENTAL_Router_Base<TRecord> {
|
|
3319
|
-
/**
|
|
3320
|
-
* Current {@link RouteLocationNormalized}
|
|
3321
|
-
*/
|
|
3322
|
-
readonly currentRoute: ShallowRef<RouteLocationNormalizedLoaded>;
|
|
3323
|
-
/**
|
|
3324
|
-
* Allows turning off the listening of history events. This is a low level api for micro-frontend.
|
|
3325
|
-
*/
|
|
3326
|
-
listening: boolean;
|
|
3327
|
-
/**
|
|
3328
|
-
* Checks if a route with a given name exists
|
|
3329
|
-
*
|
|
3330
|
-
* @param name - Name of the route to check
|
|
3331
|
-
*/
|
|
3332
|
-
hasRoute(name: NonNullable<RouteRecordNameGeneric>): boolean;
|
|
3333
|
-
/**
|
|
3334
|
-
* Get a full list of all the {@link RouteRecord | route records}.
|
|
3335
|
-
*/
|
|
3336
|
-
getRoutes(): TRecord[];
|
|
3337
|
-
/**
|
|
3338
|
-
* Returns the {@link RouteLocation | normalized version} of a
|
|
3339
|
-
* {@link RouteLocationRaw | route location}. Also includes an `href` property
|
|
3340
|
-
* that includes any existing `base`. By default, the `currentLocation` used is
|
|
3341
|
-
* `router.currentRoute` and should only be overridden in advanced use cases.
|
|
3342
|
-
*
|
|
3343
|
-
* @param to - Raw route location to resolve
|
|
3344
|
-
* @param currentLocation - Optional current location to resolve against
|
|
3345
|
-
*/
|
|
3346
|
-
resolve<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsRelativeTyped<RouteMap, Name>, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolved<Name>;
|
|
3347
|
-
resolve(to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolved;
|
|
3348
|
-
/**
|
|
3349
|
-
* Programmatically navigate to a new URL by pushing an entry in the history
|
|
3350
|
-
* stack.
|
|
3351
|
-
*
|
|
3352
|
-
* @param to - Route location to navigate to
|
|
3353
|
-
*/
|
|
3354
|
-
push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
|
|
3355
|
-
/**
|
|
3356
|
-
* Programmatically navigate to a new URL by replacing the current entry in
|
|
3357
|
-
* the history stack.
|
|
3358
|
-
*
|
|
3359
|
-
* @param to - Route location to navigate to
|
|
3360
|
-
*/
|
|
3361
|
-
replace(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
|
|
3362
|
-
/**
|
|
3363
|
-
* Go back in history if possible by calling `history.back()`. Equivalent to
|
|
3364
|
-
* `router.go(-1)`.
|
|
3365
|
-
*/
|
|
3366
|
-
back(): void;
|
|
3367
|
-
/**
|
|
3368
|
-
* Go forward in history if possible by calling `history.forward()`.
|
|
3369
|
-
* Equivalent to `router.go(1)`.
|
|
3370
|
-
*/
|
|
3371
|
-
forward(): void;
|
|
3372
|
-
/**
|
|
3373
|
-
* Allows you to move forward or backward through the history. Calls
|
|
3374
|
-
* `history.go()`.
|
|
3375
|
-
*
|
|
3376
|
-
* @param delta - The position in the history to which you want to move,
|
|
3377
|
-
* relative to the current page
|
|
3378
|
-
*/
|
|
3379
|
-
go(delta: number): void;
|
|
3380
|
-
/**
|
|
3381
|
-
* Add a navigation guard that executes before any navigation. Returns a
|
|
3382
|
-
* function that removes the registered guard.
|
|
3383
|
-
*
|
|
3384
|
-
* @param guard - navigation guard to add
|
|
3385
|
-
*/
|
|
3386
|
-
beforeEach(guard: NavigationGuardWithThis<undefined>): () => void;
|
|
3387
|
-
/**
|
|
3388
|
-
* Add a navigation guard that executes before navigation is about to be
|
|
3389
|
-
* resolved. At this state all component have been fetched and other
|
|
3390
|
-
* navigation guards have been successful. Returns a function that removes the
|
|
3391
|
-
* registered guard.
|
|
3392
|
-
*
|
|
3393
|
-
* @param guard - navigation guard to add
|
|
3394
|
-
* @returns a function that removes the registered guard
|
|
3395
|
-
*
|
|
3396
|
-
* @example
|
|
3397
|
-
* ```js
|
|
3398
|
-
* router.beforeResolve(to => {
|
|
3399
|
-
* if (to.meta.requiresAuth && !isAuthenticated) return false
|
|
3400
|
-
* })
|
|
3401
|
-
* ```
|
|
3402
|
-
*
|
|
3403
|
-
*/
|
|
3404
|
-
beforeResolve(guard: NavigationGuardWithThis<undefined>): () => void;
|
|
3405
|
-
/**
|
|
3406
|
-
* Add a navigation hook that is executed after every navigation. Returns a
|
|
3407
|
-
* function that removes the registered hook.
|
|
3408
|
-
*
|
|
3409
|
-
* @param guard - navigation hook to add
|
|
3410
|
-
* @returns a function that removes the registered hook
|
|
3411
|
-
*
|
|
3412
|
-
* @example
|
|
3413
|
-
* ```js
|
|
3414
|
-
* router.afterEach((to, from, failure) => {
|
|
3415
|
-
* if (isNavigationFailure(failure)) {
|
|
3416
|
-
* console.log('failed navigation', failure)
|
|
3417
|
-
* }
|
|
3418
|
-
* })
|
|
3419
|
-
* ```
|
|
3420
|
-
*/
|
|
3421
|
-
afterEach(guard: NavigationHookAfter): () => void;
|
|
3422
|
-
/**
|
|
3423
|
-
* Adds an error handler that is called every time a non caught error happens
|
|
3424
|
-
* during navigation. This includes errors thrown synchronously and
|
|
3425
|
-
* asynchronously, errors returned or passed to `next` in any navigation
|
|
3426
|
-
* guard, and errors occurred when trying to resolve an async component that
|
|
3427
|
-
* is required to render a route.
|
|
3428
|
-
*
|
|
3429
|
-
* @param handler - error handler to register
|
|
3430
|
-
*/
|
|
3431
|
-
onError(handler: _ErrorListener): () => void;
|
|
3432
|
-
/**
|
|
3433
|
-
* Returns a Promise that resolves when the router has completed the initial
|
|
3434
|
-
* navigation, which means it has resolved all async enter hooks and async
|
|
3435
|
-
* components that are associated with the initial route. If the initial
|
|
3436
|
-
* navigation already happened, the promise resolves immediately.
|
|
3437
|
-
*
|
|
3438
|
-
* This is useful in server-side rendering to ensure consistent output on both
|
|
3439
|
-
* the server and the client. Note that on server side, you need to manually
|
|
3440
|
-
* push the initial location while on client side, the router automatically
|
|
3441
|
-
* picks it up from the URL.
|
|
3442
|
-
*/
|
|
3443
|
-
isReady(): Promise<void>;
|
|
3444
|
-
/**
|
|
3445
|
-
* Called automatically by `app.use(router)`. Should not be called manually by
|
|
3446
|
-
* the user. This will trigger the initial navigation when on client side.
|
|
3447
|
-
*
|
|
3448
|
-
* @internal
|
|
3449
|
-
* @param app - Application that uses the router
|
|
3450
|
-
*/
|
|
3451
|
-
install(app: App): void;
|
|
3452
|
-
}
|
|
3453
|
-
//#endregion
|
|
3454
|
-
//#region ../../node_modules/.pnpm/vue-router@4.6.3_vue@3.5.22_typescript@5.9.3_/node_modules/vue-router/dist/vue-router.d.mts
|
|
3455
|
-
//#endregion
|
|
3456
|
-
//#region src/router.d.ts
|
|
3457
|
-
/**
|
|
3458
|
-
* Options to initialize a {@link Router} instance.
|
|
3459
|
-
*/
|
|
3460
|
-
interface RouterOptions extends EXPERIMENTAL_RouterOptions_Base {
|
|
3461
|
-
/**
|
|
3462
|
-
* Initial list of routes that should be added to the router.
|
|
3463
|
-
*/
|
|
3464
|
-
routes: Readonly<RouteRecordRaw[]>;
|
|
3465
|
-
}
|
|
3466
|
-
/**
|
|
3467
|
-
* Router instance.
|
|
3468
|
-
*/
|
|
3469
|
-
interface Router extends EXPERIMENTAL_Router_Base<RouteRecordNormalized> {
|
|
3470
|
-
/**
|
|
3471
|
-
* Original options object passed to create the Router
|
|
3472
|
-
*/
|
|
3473
|
-
readonly options: RouterOptions;
|
|
3474
|
-
/**
|
|
3475
|
-
* Add a new {@link RouteRecordRaw | route record} as the child of an existing route.
|
|
3476
|
-
*
|
|
3477
|
-
* @param parentName - Parent Route Record where `route` should be appended at
|
|
3478
|
-
* @param route - Route Record to add
|
|
3479
|
-
*/
|
|
3480
|
-
addRoute(parentName: NonNullable<RouteRecordNameGeneric>, route: RouteRecordRaw): () => void;
|
|
3481
|
-
/**
|
|
3482
|
-
* Add a new {@link RouteRecordRaw | route record} to the router.
|
|
3483
|
-
*
|
|
3484
|
-
* @param route - Route Record to add
|
|
3485
|
-
*/
|
|
3486
|
-
addRoute(route: RouteRecordRaw): () => void;
|
|
3487
|
-
/**
|
|
3488
|
-
* Remove an existing route by its name.
|
|
3489
|
-
*
|
|
3490
|
-
* @param name - Name of the route to remove
|
|
3491
|
-
*/
|
|
3492
|
-
removeRoute(name: NonNullable<RouteRecordNameGeneric>): void;
|
|
3493
|
-
/**
|
|
3494
|
-
* Delete all routes from the router.
|
|
3495
|
-
*/
|
|
3496
|
-
clearRoutes(): void;
|
|
3497
|
-
}
|
|
3498
|
-
/**
|
|
3499
|
-
* Creates a Router instance that can be used by a Vue app.
|
|
3500
|
-
*
|
|
3501
|
-
* @param options - {@link RouterOptions}
|
|
3502
|
-
*/
|
|
3503
|
-
|
|
3504
|
-
//#endregion
|
|
3505
|
-
//#region src/RouterLink.d.ts
|
|
3506
|
-
interface RouterLinkOptions {
|
|
3507
|
-
/**
|
|
3508
|
-
* Route Location the link should navigate to when clicked on.
|
|
3509
|
-
*/
|
|
3510
|
-
to: RouteLocationRaw;
|
|
3511
|
-
/**
|
|
3512
|
-
* Calls `router.replace` instead of `router.push`.
|
|
3513
|
-
*/
|
|
3514
|
-
replace?: boolean;
|
|
3515
|
-
}
|
|
3516
|
-
interface RouterLinkProps extends RouterLinkOptions {
|
|
3517
|
-
/**
|
|
3518
|
-
* Whether RouterLink should not wrap its content in an `a` tag. Useful when
|
|
3519
|
-
* using `v-slot` to create a custom RouterLink
|
|
3520
|
-
*/
|
|
3521
|
-
custom?: boolean;
|
|
3522
|
-
/**
|
|
3523
|
-
* Class to apply when the link is active
|
|
3524
|
-
*/
|
|
3525
|
-
activeClass?: string;
|
|
3526
|
-
/**
|
|
3527
|
-
* Class to apply when the link is exact active
|
|
3528
|
-
*/
|
|
3529
|
-
exactActiveClass?: string;
|
|
3530
|
-
/**
|
|
3531
|
-
* Value passed to the attribute `aria-current` when the link is exact active.
|
|
3532
|
-
*
|
|
3533
|
-
* @defaultValue `'page'`
|
|
3534
|
-
*/
|
|
3535
|
-
ariaCurrentValue?: 'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false';
|
|
3536
|
-
/**
|
|
3537
|
-
* Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
|
|
3538
|
-
*/
|
|
3539
|
-
viewTransition?: boolean;
|
|
3540
|
-
}
|
|
3541
|
-
/**
|
|
3542
|
-
* Options passed to {@link useLink}.
|
|
3543
|
-
*/
|
|
3544
|
-
interface UseLinkOptions<Name extends keyof RouteMap = keyof RouteMap> {
|
|
3545
|
-
to: MaybeRef<RouteLocationAsString | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPath | RouteLocationRaw>;
|
|
3546
|
-
replace?: MaybeRef<boolean | undefined>;
|
|
3547
|
-
/**
|
|
3548
|
-
* Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
|
|
3549
|
-
*/
|
|
3550
|
-
viewTransition?: boolean;
|
|
3551
|
-
}
|
|
3552
|
-
/**
|
|
3553
|
-
* Return type of {@link useLink}.
|
|
3554
|
-
* @internal
|
|
3555
|
-
*/
|
|
3556
|
-
interface UseLinkReturn<Name extends keyof RouteMap = keyof RouteMap> {
|
|
3557
|
-
route: ComputedRef<RouteLocationResolved<Name>>;
|
|
3558
|
-
href: ComputedRef<string>;
|
|
3559
|
-
isActive: ComputedRef<boolean>;
|
|
3560
|
-
isExactActive: ComputedRef<boolean>;
|
|
3561
|
-
navigate(e?: MouseEvent): Promise<void | NavigationFailure>;
|
|
3562
|
-
}
|
|
3563
|
-
/**
|
|
3564
|
-
* Returns the internal behavior of a {@link RouterLink} without the rendering part.
|
|
3565
|
-
*
|
|
3566
|
-
* @param props - a `to` location and an optional `replace` flag
|
|
3567
|
-
*/
|
|
3568
|
-
declare function useLink<Name extends keyof RouteMap = keyof RouteMap>(props: UseLinkOptions<Name>): UseLinkReturn<Name>;
|
|
3569
|
-
/**
|
|
3570
|
-
* Component to render a link that triggers a navigation on click.
|
|
3571
|
-
*/
|
|
3572
|
-
declare const RouterLink: _RouterLinkI;
|
|
3573
|
-
/**
|
|
3574
|
-
* @internal
|
|
3575
|
-
*/
|
|
3576
|
-
type _RouterLinkPropsTypedBase = AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterLinkProps;
|
|
3577
|
-
/**
|
|
3578
|
-
* @internal
|
|
3579
|
-
*/
|
|
3580
|
-
type RouterLinkPropsTyped<Custom extends boolean | undefined> = Custom extends true ? _RouterLinkPropsTypedBase & {
|
|
3581
|
-
custom: true;
|
|
3582
|
-
} : _RouterLinkPropsTypedBase & {
|
|
3583
|
-
custom?: false | undefined;
|
|
3584
|
-
} & Omit<AnchorHTMLAttributes, 'href'>;
|
|
3585
|
-
/**
|
|
3586
|
-
* Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
|
|
3587
|
-
* automatically for JSX.
|
|
3588
|
-
*
|
|
3589
|
-
* @internal
|
|
3590
|
-
*/
|
|
3591
|
-
interface _RouterLinkI {
|
|
3592
|
-
new <Custom extends boolean | undefined = boolean | undefined>(): {
|
|
3593
|
-
$props: RouterLinkPropsTyped<Custom>;
|
|
3594
|
-
$slots: {
|
|
3595
|
-
default?: ({
|
|
3596
|
-
route,
|
|
3597
|
-
href,
|
|
3598
|
-
isActive,
|
|
3599
|
-
isExactActive,
|
|
3600
|
-
navigate
|
|
3601
|
-
}: UnwrapRef<UseLinkReturn>) => VNode[];
|
|
3602
|
-
};
|
|
3603
|
-
};
|
|
3604
|
-
/**
|
|
3605
|
-
* Access to `useLink()` without depending on using vue-router
|
|
3606
|
-
*
|
|
3607
|
-
* @internal
|
|
3608
|
-
*/
|
|
3609
|
-
useLink: typeof useLink;
|
|
3610
|
-
}
|
|
3611
|
-
//#endregion
|
|
3612
|
-
//#region src/RouterView.d.ts
|
|
3613
|
-
interface RouterViewProps {
|
|
3614
|
-
name?: string;
|
|
3615
|
-
route?: RouteLocationNormalized;
|
|
3616
|
-
}
|
|
3617
|
-
/**
|
|
3618
|
-
* Component to display the current route the user is at.
|
|
3619
|
-
*/
|
|
3620
|
-
declare const RouterView: {
|
|
3621
|
-
new (): {
|
|
3622
|
-
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterViewProps;
|
|
3623
|
-
$slots: {
|
|
3624
|
-
default?: ({
|
|
3625
|
-
Component,
|
|
3626
|
-
route
|
|
3627
|
-
}: {
|
|
3628
|
-
Component: VNode;
|
|
3629
|
-
route: RouteLocationNormalizedLoaded;
|
|
3630
|
-
}) => VNode[];
|
|
3631
|
-
};
|
|
3632
|
-
};
|
|
3633
|
-
};
|
|
3634
|
-
//#endregion
|
|
3635
|
-
//#region src/useApi.d.ts
|
|
3636
|
-
/**
|
|
3637
|
-
* Returns the router instance. Equivalent to using `$router` inside
|
|
3638
|
-
* templates.
|
|
3639
|
-
*/
|
|
3640
|
-
|
|
3641
|
-
//#endregion
|
|
3642
|
-
//#region src/index.d.ts
|
|
3643
|
-
declare module 'vue' {
|
|
3644
|
-
interface ComponentCustomOptions {
|
|
3645
|
-
/**
|
|
3646
|
-
* Guard called when the router is navigating to the route that is rendering
|
|
3647
|
-
* this component from a different route. Differently from `beforeRouteUpdate`
|
|
3648
|
-
* and `beforeRouteLeave`, `beforeRouteEnter` does not have access to the
|
|
3649
|
-
* component instance through `this` because it triggers before the component
|
|
3650
|
-
* is even mounted.
|
|
3651
|
-
*
|
|
3652
|
-
* @param to - RouteLocationRaw we are navigating to
|
|
3653
|
-
* @param from - RouteLocationRaw we are navigating from
|
|
3654
|
-
* @param next - function to validate, cancel or modify (by redirecting) the
|
|
3655
|
-
* navigation
|
|
3656
|
-
*/
|
|
3657
|
-
beforeRouteEnter?: TypesConfig extends Record<'beforeRouteEnter', infer T> ? T : NavigationGuardWithThis<undefined>;
|
|
3658
|
-
/**
|
|
3659
|
-
* Guard called whenever the route that renders this component has changed, but
|
|
3660
|
-
* it is reused for the new route. This allows you to guard for changes in
|
|
3661
|
-
* params, the query or the hash.
|
|
3662
|
-
*
|
|
3663
|
-
* @param to - RouteLocationRaw we are navigating to
|
|
3664
|
-
* @param from - RouteLocationRaw we are navigating from
|
|
3665
|
-
* @param next - function to validate, cancel or modify (by redirecting) the
|
|
3666
|
-
* navigation
|
|
3667
|
-
*/
|
|
3668
|
-
beforeRouteUpdate?: TypesConfig extends Record<'beforeRouteUpdate', infer T> ? T : NavigationGuard;
|
|
3669
|
-
/**
|
|
3670
|
-
* Guard called when the router is navigating away from the current route that
|
|
3671
|
-
* is rendering this component.
|
|
3672
|
-
*
|
|
3673
|
-
* @param to - RouteLocationRaw we are navigating to
|
|
3674
|
-
* @param from - RouteLocationRaw we are navigating from
|
|
3675
|
-
* @param next - function to validate, cancel or modify (by redirecting) the
|
|
3676
|
-
* navigation
|
|
3677
|
-
*/
|
|
3678
|
-
beforeRouteLeave?: TypesConfig extends Record<'beforeRouteLeave', infer T> ? T : NavigationGuard;
|
|
3679
|
-
}
|
|
3680
|
-
interface ComponentCustomProperties {
|
|
3681
|
-
/**
|
|
3682
|
-
* Normalized current location. See {@link RouteLocationNormalizedLoaded}.
|
|
3683
|
-
*/
|
|
3684
|
-
$route: TypesConfig extends Record<'$route', infer T> ? T : RouteLocationNormalizedLoaded;
|
|
3685
|
-
/**
|
|
3686
|
-
* {@link Router} instance used by the application.
|
|
3687
|
-
*/
|
|
3688
|
-
$router: TypesConfig extends Record<'$router', infer T> ? T : Router;
|
|
3689
|
-
}
|
|
3690
|
-
interface GlobalComponents {
|
|
3691
|
-
RouterView: TypesConfig extends Record<'RouterView', infer T> ? T : typeof RouterView;
|
|
3692
|
-
RouterLink: TypesConfig extends Record<'RouterLink', infer T> ? T : typeof RouterLink;
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
//#endregion
|
|
3696
|
-
//#endregion
|
|
3697
|
-
//#region src/devtools/registry.d.ts
|
|
3698
|
-
//#endregion
|
|
3699
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/primitive.d.ts
|
|
3700
|
-
/**
|
|
3701
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
3702
|
-
|
|
3703
|
-
@category Type
|
|
3704
|
-
*/
|
|
3705
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
3706
|
-
//#endregion
|
|
3707
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/empty-object.d.ts
|
|
3708
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
3709
|
-
|
|
3710
|
-
/**
|
|
3711
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
3712
|
-
|
|
3713
|
-
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)).
|
|
3714
|
-
|
|
3715
|
-
@example
|
|
3716
|
-
```
|
|
3717
|
-
import type {EmptyObject} from 'type-fest';
|
|
3718
|
-
|
|
3719
|
-
// The following illustrates the problem with `{}`.
|
|
3720
|
-
const foo1: {} = {}; // Pass
|
|
3721
|
-
const foo2: {} = []; // Pass
|
|
3722
|
-
const foo3: {} = 42; // Pass
|
|
3723
|
-
const foo4: {} = {a: 1}; // Pass
|
|
3724
|
-
|
|
3725
|
-
// With `EmptyObject` only the first case is valid.
|
|
3726
|
-
const bar1: EmptyObject = {}; // Pass
|
|
3727
|
-
const bar2: EmptyObject = 42; // Fail
|
|
3728
|
-
const bar3: EmptyObject = []; // Fail
|
|
3729
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
3730
|
-
```
|
|
3731
|
-
|
|
3732
|
-
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}.
|
|
3733
|
-
|
|
3734
|
-
@category Object
|
|
3735
|
-
*/
|
|
3736
|
-
type EmptyObject = {
|
|
3737
|
-
[emptyObjectSymbol]?: never;
|
|
3738
|
-
};
|
|
3739
|
-
//#endregion
|
|
3740
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-any.d.ts
|
|
3741
|
-
/**
|
|
3742
|
-
Returns a boolean for whether the given type is `any`.
|
|
3743
|
-
|
|
3744
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
3745
|
-
|
|
3746
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
3747
|
-
|
|
3748
|
-
@example
|
|
3749
|
-
```
|
|
3750
|
-
import type {IsAny} from 'type-fest';
|
|
3751
|
-
|
|
3752
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
3753
|
-
const anyObject: any = {a: 1, b: 2};
|
|
3754
|
-
|
|
3755
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
3756
|
-
return obj[key];
|
|
3757
|
-
}
|
|
3758
|
-
|
|
3759
|
-
const typedA = get(typedObject, 'a');
|
|
3760
|
-
//=> 1
|
|
3761
|
-
|
|
3762
|
-
const anyA = get(anyObject, 'a');
|
|
3763
|
-
//=> any
|
|
3764
|
-
```
|
|
3765
|
-
|
|
3766
|
-
@category Type Guard
|
|
3767
|
-
@category Utilities
|
|
3768
|
-
*/
|
|
3769
|
-
type IsAny<T$1> = 0 extends 1 & NoInfer<T$1> ? true : false;
|
|
3770
|
-
//#endregion
|
|
3771
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
3772
|
-
/**
|
|
3773
|
-
Returns a boolean for whether the given key is an optional key of type.
|
|
3774
|
-
|
|
3775
|
-
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
3776
|
-
|
|
3777
|
-
@example
|
|
3778
|
-
```
|
|
3779
|
-
import type {IsOptionalKeyOf} from 'type-fest';
|
|
3780
|
-
|
|
3781
|
-
interface User {
|
|
3782
|
-
name: string;
|
|
3783
|
-
surname: string;
|
|
3784
|
-
|
|
3785
|
-
luckyNumber?: number;
|
|
3786
|
-
}
|
|
3787
|
-
|
|
3788
|
-
interface Admin {
|
|
3789
|
-
name: string;
|
|
3790
|
-
surname?: string;
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
3794
|
-
//=> true
|
|
3795
|
-
|
|
3796
|
-
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
3797
|
-
//=> false
|
|
3798
|
-
|
|
3799
|
-
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
3800
|
-
//=> boolean
|
|
3801
|
-
|
|
3802
|
-
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
3803
|
-
//=> false
|
|
3804
|
-
|
|
3805
|
-
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
3806
|
-
//=> boolean
|
|
3807
|
-
```
|
|
3808
|
-
|
|
3809
|
-
@category Type Guard
|
|
3810
|
-
@category Utilities
|
|
3811
|
-
*/
|
|
3812
|
-
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;
|
|
3813
|
-
//#endregion
|
|
3814
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
3815
|
-
/**
|
|
3816
|
-
Extract all optional keys from the given type.
|
|
3817
|
-
|
|
3818
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
3819
|
-
|
|
3820
|
-
@example
|
|
3821
|
-
```
|
|
3822
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
3823
|
-
|
|
3824
|
-
interface User {
|
|
3825
|
-
name: string;
|
|
3826
|
-
surname: string;
|
|
3827
|
-
|
|
3828
|
-
luckyNumber?: number;
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
3832
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
3833
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
3834
|
-
};
|
|
3835
|
-
|
|
3836
|
-
const update1: UpdateOperation<User> = {
|
|
3837
|
-
name: 'Alice'
|
|
3838
|
-
};
|
|
3839
|
-
|
|
3840
|
-
const update2: UpdateOperation<User> = {
|
|
3841
|
-
name: 'Bob',
|
|
3842
|
-
luckyNumber: REMOVE_FIELD
|
|
3843
|
-
};
|
|
3844
|
-
```
|
|
3845
|
-
|
|
3846
|
-
@category Utilities
|
|
3847
|
-
*/
|
|
3848
|
-
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
3849
|
-
? (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`
|
|
3850
|
-
: never;
|
|
3851
|
-
//#endregion
|
|
3852
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
3853
|
-
/**
|
|
3854
|
-
Extract all required keys from the given type.
|
|
3855
|
-
|
|
3856
|
-
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...
|
|
3857
|
-
|
|
3858
|
-
@example
|
|
3859
|
-
```
|
|
3860
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
3861
|
-
|
|
3862
|
-
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
3863
|
-
|
|
3864
|
-
interface User {
|
|
3865
|
-
name: string;
|
|
3866
|
-
surname: string;
|
|
3867
|
-
|
|
3868
|
-
luckyNumber?: number;
|
|
3869
|
-
}
|
|
3870
|
-
|
|
3871
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
3872
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
3873
|
-
```
|
|
3874
|
-
|
|
3875
|
-
@category Utilities
|
|
3876
|
-
*/
|
|
3877
|
-
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
3878
|
-
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
3879
|
-
//#endregion
|
|
3880
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-never.d.ts
|
|
3881
|
-
/**
|
|
3882
|
-
Returns a boolean for whether the given type is `never`.
|
|
3883
|
-
|
|
3884
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
3885
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
3886
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
3887
|
-
|
|
3888
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
3889
|
-
|
|
3890
|
-
@example
|
|
3891
|
-
```
|
|
3892
|
-
import type {IsNever, And} from 'type-fest';
|
|
3893
|
-
|
|
3894
|
-
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
3895
|
-
type AreStringsEqual<A extends string, B extends string> =
|
|
3896
|
-
And<
|
|
3897
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
3898
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
3899
|
-
>;
|
|
3900
|
-
|
|
3901
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
3902
|
-
AreStringsEqual<I, O> extends true
|
|
3903
|
-
? never
|
|
3904
|
-
: void;
|
|
3905
|
-
|
|
3906
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
3907
|
-
if (input === output) {
|
|
3908
|
-
process.exit(0);
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
endIfEqual('abc', 'abc');
|
|
3913
|
-
//=> never
|
|
3914
|
-
|
|
3915
|
-
endIfEqual('abc', '123');
|
|
3916
|
-
//=> void
|
|
3917
|
-
```
|
|
3918
|
-
|
|
3919
|
-
@category Type Guard
|
|
3920
|
-
@category Utilities
|
|
3921
|
-
*/
|
|
3922
|
-
type IsNever<T$1> = [T$1] extends [never] ? true : false;
|
|
3923
|
-
//#endregion
|
|
3924
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/if.d.ts
|
|
3925
|
-
/**
|
|
3926
|
-
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
3927
|
-
|
|
3928
|
-
Use-cases:
|
|
3929
|
-
- 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'>`.
|
|
3930
|
-
|
|
3931
|
-
Note:
|
|
3932
|
-
- 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'`.
|
|
3933
|
-
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
3934
|
-
|
|
3935
|
-
@example
|
|
3936
|
-
```
|
|
3937
|
-
import {If} from 'type-fest';
|
|
3938
|
-
|
|
3939
|
-
type A = If<true, 'yes', 'no'>;
|
|
3940
|
-
//=> 'yes'
|
|
3941
|
-
|
|
3942
|
-
type B = If<false, 'yes', 'no'>;
|
|
3943
|
-
//=> 'no'
|
|
3944
|
-
|
|
3945
|
-
type C = If<boolean, 'yes', 'no'>;
|
|
3946
|
-
//=> 'yes' | 'no'
|
|
3947
|
-
|
|
3948
|
-
type D = If<any, 'yes', 'no'>;
|
|
3949
|
-
//=> 'yes' | 'no'
|
|
3950
|
-
|
|
3951
|
-
type E = If<never, 'yes', 'no'>;
|
|
3952
|
-
//=> 'no'
|
|
3953
|
-
```
|
|
3954
|
-
|
|
3955
|
-
@example
|
|
3956
|
-
```
|
|
3957
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
3958
|
-
|
|
3959
|
-
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
3960
|
-
//=> 'not any'
|
|
3961
|
-
|
|
3962
|
-
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
3963
|
-
//=> 'is never'
|
|
3964
|
-
```
|
|
3965
|
-
|
|
3966
|
-
@example
|
|
3967
|
-
```
|
|
3968
|
-
import {If, IsEqual} from 'type-fest';
|
|
3969
|
-
|
|
3970
|
-
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
3971
|
-
|
|
3972
|
-
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
3973
|
-
//=> 'equal'
|
|
3974
|
-
|
|
3975
|
-
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
3976
|
-
//=> 'not equal'
|
|
3977
|
-
```
|
|
3978
|
-
|
|
3979
|
-
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:
|
|
3980
|
-
|
|
3981
|
-
@example
|
|
3982
|
-
```
|
|
3983
|
-
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
3984
|
-
|
|
3985
|
-
type HundredZeroes = StringRepeat<'0', 100>;
|
|
3986
|
-
|
|
3987
|
-
// The following implementation is not tail recursive
|
|
3988
|
-
type Includes<S extends string, Char extends string> =
|
|
3989
|
-
S extends `${infer First}${infer Rest}`
|
|
3990
|
-
? If<IsEqual<First, Char>,
|
|
3991
|
-
'found',
|
|
3992
|
-
Includes<Rest, Char>>
|
|
3993
|
-
: 'not found';
|
|
3994
|
-
|
|
3995
|
-
// Hence, instantiations with long strings will fail
|
|
3996
|
-
// @ts-expect-error
|
|
3997
|
-
type Fails = Includes<HundredZeroes, '1'>;
|
|
3998
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
3999
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
4000
|
-
|
|
4001
|
-
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
4002
|
-
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
4003
|
-
S extends `${infer First}${infer Rest}`
|
|
4004
|
-
? IsEqual<First, Char> extends true
|
|
4005
|
-
? 'found'
|
|
4006
|
-
: IncludesWithoutIf<Rest, Char>
|
|
4007
|
-
: 'not found';
|
|
4008
|
-
|
|
4009
|
-
// Now, instantiations with long strings will work
|
|
4010
|
-
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
4011
|
-
//=> 'not found'
|
|
4012
|
-
```
|
|
4013
|
-
|
|
4014
|
-
@category Type Guard
|
|
4015
|
-
@category Utilities
|
|
4016
|
-
*/
|
|
4017
|
-
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
4018
|
-
//#endregion
|
|
4019
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/type.d.ts
|
|
4020
|
-
/**
|
|
4021
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
4022
|
-
*/
|
|
4023
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
4024
|
-
/**
|
|
4025
|
-
Test if the given function has multiple call signatures.
|
|
4026
|
-
|
|
4027
|
-
Needed to handle the case of a single call signature with properties.
|
|
4028
|
-
|
|
4029
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
4030
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
4031
|
-
*/
|
|
4032
|
-
type HasMultipleCallSignatures<T$1 extends (...arguments_: any[]) => unknown> = T$1 extends {
|
|
4033
|
-
(...arguments_: infer A): unknown;
|
|
4034
|
-
(...arguments_: infer B): unknown;
|
|
4035
|
-
} ? B extends A ? A extends B ? false : true : true : false;
|
|
4036
|
-
//#endregion
|
|
4037
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/simplify.d.ts
|
|
4038
|
-
/**
|
|
4039
|
-
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.
|
|
4040
|
-
|
|
4041
|
-
@example
|
|
4042
|
-
```
|
|
4043
|
-
import type {Simplify} from 'type-fest';
|
|
4044
|
-
|
|
4045
|
-
type PositionProps = {
|
|
4046
|
-
top: number;
|
|
4047
|
-
left: number;
|
|
4048
|
-
};
|
|
4049
|
-
|
|
4050
|
-
type SizeProps = {
|
|
4051
|
-
width: number;
|
|
4052
|
-
height: number;
|
|
4053
|
-
};
|
|
4054
|
-
|
|
4055
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
4056
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
4057
|
-
```
|
|
4058
|
-
|
|
4059
|
-
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.
|
|
4060
|
-
|
|
4061
|
-
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`.
|
|
4062
|
-
|
|
4063
|
-
@example
|
|
4064
|
-
```
|
|
4065
|
-
import type {Simplify} from 'type-fest';
|
|
4066
|
-
|
|
4067
|
-
interface SomeInterface {
|
|
4068
|
-
foo: number;
|
|
4069
|
-
bar?: string;
|
|
4070
|
-
baz: number | undefined;
|
|
4071
|
-
}
|
|
4072
|
-
|
|
4073
|
-
type SomeType = {
|
|
4074
|
-
foo: number;
|
|
4075
|
-
bar?: string;
|
|
4076
|
-
baz: number | undefined;
|
|
4077
|
-
};
|
|
4078
|
-
|
|
4079
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
4080
|
-
const someType: SomeType = literal;
|
|
4081
|
-
const someInterface: SomeInterface = literal;
|
|
4082
|
-
|
|
4083
|
-
function fn(object: Record<string, unknown>): void {}
|
|
4084
|
-
|
|
4085
|
-
fn(literal); // Good: literal object type is sealed
|
|
4086
|
-
fn(someType); // Good: type is sealed
|
|
4087
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
4088
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
4089
|
-
```
|
|
4090
|
-
|
|
4091
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
4092
|
-
@see {@link SimplifyDeep}
|
|
4093
|
-
@category Object
|
|
4094
|
-
*/
|
|
4095
|
-
type Simplify<T$1> = { [KeyType in keyof T$1]: T$1[KeyType] } & {};
|
|
4096
|
-
//#endregion
|
|
4097
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
4098
|
-
/**
|
|
4099
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
4100
|
-
|
|
4101
|
-
This is the counterpart of `PickIndexSignature`.
|
|
4102
|
-
|
|
4103
|
-
Use-cases:
|
|
4104
|
-
- Remove overly permissive signatures from third-party types.
|
|
4105
|
-
|
|
4106
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
4107
|
-
|
|
4108
|
-
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>`.
|
|
4109
|
-
|
|
4110
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
4111
|
-
|
|
4112
|
-
```
|
|
4113
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
4114
|
-
|
|
4115
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
4116
|
-
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
4117
|
-
```
|
|
4118
|
-
|
|
4119
|
-
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:
|
|
4120
|
-
|
|
4121
|
-
```
|
|
4122
|
-
type Indexed = {} extends Record<string, unknown>
|
|
4123
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
4124
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
4125
|
-
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
4126
|
-
|
|
4127
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
4128
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
4129
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
4130
|
-
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
4131
|
-
```
|
|
4132
|
-
|
|
4133
|
-
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`...
|
|
4134
|
-
|
|
4135
|
-
```
|
|
4136
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
4137
|
-
|
|
4138
|
-
type OmitIndexSignature<ObjectType> = {
|
|
4139
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
4140
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
4141
|
-
};
|
|
4142
|
-
```
|
|
4143
|
-
|
|
4144
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
4145
|
-
|
|
4146
|
-
```
|
|
4147
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
4148
|
-
|
|
4149
|
-
type OmitIndexSignature<ObjectType> = {
|
|
4150
|
-
[KeyType in keyof ObjectType
|
|
4151
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
4152
|
-
as {} extends Record<KeyType, unknown>
|
|
4153
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
4154
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
4155
|
-
]: ObjectType[KeyType];
|
|
4156
|
-
};
|
|
4157
|
-
```
|
|
4158
|
-
|
|
4159
|
-
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.
|
|
4160
|
-
|
|
4161
|
-
@example
|
|
4162
|
-
```
|
|
4163
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
4164
|
-
|
|
4165
|
-
interface Example {
|
|
4166
|
-
// These index signatures will be removed.
|
|
4167
|
-
[x: string]: any
|
|
4168
|
-
[x: number]: any
|
|
4169
|
-
[x: symbol]: any
|
|
4170
|
-
[x: `head-${string}`]: string
|
|
4171
|
-
[x: `${string}-tail`]: string
|
|
4172
|
-
[x: `head-${string}-tail`]: string
|
|
4173
|
-
[x: `${bigint}`]: string
|
|
4174
|
-
[x: `embedded-${number}`]: string
|
|
4175
|
-
|
|
4176
|
-
// These explicitly defined keys will remain.
|
|
4177
|
-
foo: 'bar';
|
|
4178
|
-
qux?: 'baz';
|
|
4179
|
-
}
|
|
4180
|
-
|
|
4181
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
4182
|
-
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
4183
|
-
```
|
|
4184
|
-
|
|
4185
|
-
@see {@link PickIndexSignature}
|
|
4186
|
-
@category Object
|
|
4187
|
-
*/
|
|
4188
|
-
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
4189
|
-
//#endregion
|
|
4190
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
4191
|
-
/**
|
|
4192
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
4193
|
-
|
|
4194
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
4195
|
-
|
|
4196
|
-
@example
|
|
4197
|
-
```
|
|
4198
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
4199
|
-
|
|
4200
|
-
declare const symbolKey: unique symbol;
|
|
4201
|
-
|
|
4202
|
-
type Example = {
|
|
4203
|
-
// These index signatures will remain.
|
|
4204
|
-
[x: string]: unknown;
|
|
4205
|
-
[x: number]: unknown;
|
|
4206
|
-
[x: symbol]: unknown;
|
|
4207
|
-
[x: `head-${string}`]: string;
|
|
4208
|
-
[x: `${string}-tail`]: string;
|
|
4209
|
-
[x: `head-${string}-tail`]: string;
|
|
4210
|
-
[x: `${bigint}`]: string;
|
|
4211
|
-
[x: `embedded-${number}`]: string;
|
|
4212
|
-
|
|
4213
|
-
// These explicitly defined keys will be removed.
|
|
4214
|
-
['kebab-case-key']: string;
|
|
4215
|
-
[symbolKey]: string;
|
|
4216
|
-
foo: 'bar';
|
|
4217
|
-
qux?: 'baz';
|
|
4218
|
-
};
|
|
4219
|
-
|
|
4220
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
4221
|
-
// {
|
|
4222
|
-
// [x: string]: unknown;
|
|
4223
|
-
// [x: number]: unknown;
|
|
4224
|
-
// [x: symbol]: unknown;
|
|
4225
|
-
// [x: `head-${string}`]: string;
|
|
4226
|
-
// [x: `${string}-tail`]: string;
|
|
4227
|
-
// [x: `head-${string}-tail`]: string;
|
|
4228
|
-
// [x: `${bigint}`]: string;
|
|
4229
|
-
// [x: `embedded-${number}`]: string;
|
|
4230
|
-
// }
|
|
4231
|
-
```
|
|
4232
|
-
|
|
4233
|
-
@see {@link OmitIndexSignature}
|
|
4234
|
-
@category Object
|
|
4235
|
-
*/
|
|
4236
|
-
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
4237
|
-
//#endregion
|
|
4238
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/merge.d.ts
|
|
4239
|
-
// Merges two objects without worrying about index signatures.
|
|
4240
|
-
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
4241
|
-
|
|
4242
|
-
/**
|
|
4243
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
4244
|
-
|
|
4245
|
-
@example
|
|
4246
|
-
```
|
|
4247
|
-
import type {Merge} from 'type-fest';
|
|
4248
|
-
|
|
4249
|
-
interface Foo {
|
|
4250
|
-
[x: string]: unknown;
|
|
4251
|
-
[x: number]: unknown;
|
|
4252
|
-
foo: string;
|
|
4253
|
-
bar: symbol;
|
|
4254
|
-
}
|
|
4255
|
-
|
|
4256
|
-
type Bar = {
|
|
4257
|
-
[x: number]: number;
|
|
4258
|
-
[x: symbol]: unknown;
|
|
4259
|
-
bar: Date;
|
|
4260
|
-
baz: boolean;
|
|
4261
|
-
};
|
|
4262
|
-
|
|
4263
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
4264
|
-
// => {
|
|
4265
|
-
// [x: string]: unknown;
|
|
4266
|
-
// [x: number]: number;
|
|
4267
|
-
// [x: symbol]: unknown;
|
|
4268
|
-
// foo: string;
|
|
4269
|
-
// bar: Date;
|
|
4270
|
-
// baz: boolean;
|
|
4271
|
-
// }
|
|
4272
|
-
```
|
|
4273
|
-
|
|
4274
|
-
@category Object
|
|
4275
|
-
*/
|
|
4276
|
-
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
4277
|
-
//#endregion
|
|
4278
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/object.d.ts
|
|
4279
|
-
/**
|
|
4280
|
-
Merges user specified options with default options.
|
|
4281
|
-
|
|
4282
|
-
@example
|
|
4283
|
-
```
|
|
4284
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
4285
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
4286
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
4287
|
-
|
|
4288
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
4289
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
4290
|
-
```
|
|
4291
|
-
|
|
4292
|
-
@example
|
|
4293
|
-
```
|
|
4294
|
-
// Complains if default values are not provided for optional options
|
|
4295
|
-
|
|
4296
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
4297
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
4298
|
-
type SpecifiedOptions = {};
|
|
4299
|
-
|
|
4300
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
4301
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
4302
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
4303
|
-
```
|
|
4304
|
-
|
|
4305
|
-
@example
|
|
4306
|
-
```
|
|
4307
|
-
// Complains if an option's default type does not conform to the expected type
|
|
4308
|
-
|
|
4309
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
4310
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
4311
|
-
type SpecifiedOptions = {};
|
|
4312
|
-
|
|
4313
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
4314
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
4315
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
4316
|
-
```
|
|
4317
|
-
|
|
4318
|
-
@example
|
|
4319
|
-
```
|
|
4320
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
4321
|
-
|
|
4322
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
4323
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
4324
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
4325
|
-
|
|
4326
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
4327
|
-
// ~~~~~~~~~~~~~~~~
|
|
4328
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
4329
|
-
```
|
|
4330
|
-
*/
|
|
4331
|
-
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>>>>;
|
|
4332
|
-
//#endregion
|
|
4333
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/partial-deep.d.ts
|
|
4334
|
-
/**
|
|
4335
|
-
@see {@link PartialDeep}
|
|
4336
|
-
*/
|
|
4337
|
-
type PartialDeepOptions = {
|
|
4338
|
-
/**
|
|
4339
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
4340
|
-
@default false
|
|
4341
|
-
*/
|
|
4342
|
-
readonly recurseIntoArrays?: boolean;
|
|
4343
|
-
|
|
4344
|
-
/**
|
|
4345
|
-
Allows `undefined` values in non-tuple arrays.
|
|
4346
|
-
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
4347
|
-
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
4348
|
-
@default false
|
|
4349
|
-
@example
|
|
4350
|
-
You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
|
|
4351
|
-
```
|
|
4352
|
-
import type {PartialDeep} from 'type-fest';
|
|
4353
|
-
type Settings = {
|
|
4354
|
-
languages: string[];
|
|
4355
|
-
};
|
|
4356
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
|
|
4357
|
-
partialSettings.languages = [undefined]; // OK
|
|
4358
|
-
```
|
|
4359
|
-
*/
|
|
4360
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
4361
|
-
};
|
|
4362
|
-
type DefaultPartialDeepOptions = {
|
|
4363
|
-
recurseIntoArrays: false;
|
|
4364
|
-
allowUndefinedInNonTupleArrays: false;
|
|
4365
|
-
};
|
|
4366
|
-
|
|
4367
|
-
/**
|
|
4368
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
4369
|
-
|
|
4370
|
-
Use-cases:
|
|
4371
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
4372
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
4373
|
-
|
|
4374
|
-
@example
|
|
4375
|
-
```
|
|
4376
|
-
import type {PartialDeep} from 'type-fest';
|
|
4377
|
-
|
|
4378
|
-
let settings = {
|
|
4379
|
-
textEditor: {
|
|
4380
|
-
fontSize: 14,
|
|
4381
|
-
fontColor: '#000000',
|
|
4382
|
-
fontWeight: 400,
|
|
4383
|
-
},
|
|
4384
|
-
autocomplete: false,
|
|
4385
|
-
autosave: true,
|
|
4386
|
-
};
|
|
4387
|
-
|
|
4388
|
-
const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
|
|
4389
|
-
{...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
|
|
4390
|
-
);
|
|
4391
|
-
|
|
4392
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
4393
|
-
```
|
|
4394
|
-
|
|
4395
|
-
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:
|
|
4396
|
-
|
|
4397
|
-
```
|
|
4398
|
-
import type {PartialDeep} from 'type-fest';
|
|
4399
|
-
|
|
4400
|
-
type Shape = {
|
|
4401
|
-
dimensions: [number, number];
|
|
4402
|
-
};
|
|
4403
|
-
|
|
4404
|
-
const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
|
|
4405
|
-
dimensions: [], // OK
|
|
4406
|
-
};
|
|
4407
|
-
|
|
4408
|
-
partialShape.dimensions = [15]; // OK
|
|
4409
|
-
```
|
|
4410
|
-
|
|
4411
|
-
@see {@link PartialDeepOptions}
|
|
4412
|
-
|
|
4413
|
-
@category Object
|
|
4414
|
-
@category Array
|
|
4415
|
-
@category Set
|
|
4416
|
-
@category Map
|
|
4417
|
-
*/
|
|
4418
|
-
type PartialDeep<T$1, Options extends PartialDeepOptions = {}> = _PartialDeep<T$1, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
4419
|
-
type _PartialDeep<T$1, Options extends Required<PartialDeepOptions>> = T$1 extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T$1 : T$1 extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T$1 extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T$1 extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T$1 extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T$1 extends ((...arguments_: any[]) => unknown) ? IsNever<keyof T$1> extends true ? T$1 // For functions with no properties
|
|
4420
|
-
: HasMultipleCallSignatures<T$1> extends true ? T$1 : ((...arguments_: Parameters<T$1>) => ReturnType<T$1>) & PartialObjectDeep<T$1, Options> : T$1 extends object ? T$1 extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
4421
|
-
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T$1 // Test for arrays (non-tuples) specifically
|
|
4422
|
-
? readonly ItemType[] extends T$1 // Differentiate readonly and mutable arrays
|
|
4423
|
-
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T$1, Options> // Tuples behave properly
|
|
4424
|
-
: T$1 // If they don't opt into array testing, just use the original type
|
|
4425
|
-
: PartialObjectDeep<T$1, Options> : unknown;
|
|
4426
|
-
|
|
4427
|
-
/**
|
|
4428
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
4429
|
-
*/
|
|
4430
|
-
type PartialMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
4431
|
-
|
|
4432
|
-
/**
|
|
4433
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
4434
|
-
*/
|
|
4435
|
-
type PartialSetDeep<T$1, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T$1, Options>>;
|
|
4436
|
-
|
|
4437
|
-
/**
|
|
4438
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
4439
|
-
*/
|
|
4440
|
-
type PartialReadonlyMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
4441
|
-
|
|
4442
|
-
/**
|
|
4443
|
-
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
4444
|
-
*/
|
|
4445
|
-
type PartialReadonlySetDeep<T$1, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T$1, Options>>;
|
|
4446
|
-
|
|
4447
|
-
/**
|
|
4448
|
-
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
4449
|
-
*/
|
|
4450
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = { [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> };
|
|
4451
|
-
//#endregion
|
|
4452
|
-
//#region src/types/core.types.d.ts
|
|
4453
|
-
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> = {}> = {
|
|
4454
8
|
/**
|
|
4455
9
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
4456
10
|
*
|
|
4457
11
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
4458
12
|
*/
|
|
4459
|
-
r$: Raw<RegleSchemaStatus<TState
|
|
13
|
+
r$: Raw<RegleSchemaStatus<TState, TShortcuts, true>>;
|
|
4460
14
|
} & TAdditionalReturnProperties;
|
|
4461
|
-
type RegleSingleFieldSchema<TState
|
|
15
|
+
type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
4462
16
|
/**
|
|
4463
17
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
4464
18
|
*
|
|
4465
19
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
4466
20
|
*/
|
|
4467
|
-
r$: Raw<RegleSchemaFieldStatus<TState
|
|
21
|
+
r$: Raw<RegleSchemaFieldStatus<TState, TShortcuts> & {
|
|
4468
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). */
|
|
4469
|
-
$validate: (forceValues?: TState
|
|
23
|
+
$validate: (forceValues?: TState extends EmptyObject ? any : HasNamedKeys<TState> extends true ? TState : any) => Promise<RegleSchemaResult<TState>>;
|
|
4470
24
|
}>;
|
|
4471
25
|
} & TAdditionalReturnProperties;
|
|
4472
26
|
type RegleSchemaResult<TSchema extends unknown> = {
|
|
@@ -4480,37 +34,37 @@ type RegleSchemaResult<TSchema extends unknown> = {
|
|
|
4480
34
|
issues: EmptyObject;
|
|
4481
35
|
errors: EmptyObject;
|
|
4482
36
|
};
|
|
4483
|
-
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 } : {};
|
|
4484
38
|
/**
|
|
4485
39
|
* @public
|
|
4486
40
|
*/
|
|
4487
|
-
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' : ''> & {
|
|
4488
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. */
|
|
4489
|
-
readonly $fields: ProcessNestedFields<TState
|
|
43
|
+
readonly $fields: ProcessNestedFields<TState, TShortcuts>;
|
|
4490
44
|
/** Collection of all issues, collected for all children properties and nested forms.
|
|
4491
45
|
*
|
|
4492
46
|
* Only contains errors from properties where $dirty equals true. */
|
|
4493
|
-
readonly $issues: RegleIssuesTree<TState
|
|
47
|
+
readonly $issues: RegleIssuesTree<TState>;
|
|
4494
48
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
4495
49
|
*
|
|
4496
50
|
* Only contains errors from properties where $dirty equals true. */
|
|
4497
|
-
readonly $errors: RegleErrorTree<TState
|
|
51
|
+
readonly $errors: RegleErrorTree<TState>;
|
|
4498
52
|
/** Collection of all the error messages, collected for all children properties. */
|
|
4499
|
-
readonly $silentErrors: RegleErrorTree<TState
|
|
53
|
+
readonly $silentErrors: RegleErrorTree<TState>;
|
|
4500
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). */
|
|
4501
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
4502
|
-
} & ProcessNestedFields<TState
|
|
55
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
56
|
+
} & ProcessNestedFields<TState, TShortcuts> & (IsRoot extends true ? {
|
|
4503
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). */
|
|
4504
|
-
$validate: (forceValues?: TState
|
|
58
|
+
$validate: (forceValues?: TState extends EmptyObject ? (HasNamedKeys<TState> extends true ? TState : any) : TState) => Promise<RegleSchemaResult<TState>>;
|
|
4505
59
|
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
4506
60
|
/**
|
|
4507
61
|
* @public
|
|
4508
62
|
*/
|
|
4509
|
-
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>;
|
|
4510
64
|
/**
|
|
4511
65
|
* @public
|
|
4512
66
|
*/
|
|
4513
|
-
type RegleSchemaFieldStatus<TState
|
|
67
|
+
type RegleSchemaFieldStatus<TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
|
|
4514
68
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
4515
69
|
*
|
|
4516
70
|
* Only contains errors from properties where $dirty equals true. */
|
|
@@ -4531,36 +85,34 @@ type RegleSchemaFieldStatus<TState$1 = any, TShortcuts extends RegleShortcutDefi
|
|
|
4531
85
|
readonly $inactive: boolean;
|
|
4532
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 */
|
|
4533
87
|
readonly $rules: {
|
|
4534
|
-
[`~validator`]: RegleRuleStatus<TState
|
|
88
|
+
[`~validator`]: RegleRuleStatus<TState, []>;
|
|
4535
89
|
};
|
|
4536
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). */
|
|
4537
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
91
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
4538
92
|
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
4539
93
|
/**
|
|
4540
94
|
* @public
|
|
4541
95
|
*/
|
|
4542
|
-
type RegleSchemaCollectionStatus<TState
|
|
96
|
+
type RegleSchemaCollectionStatus<TState extends any[], TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TState, TShortcuts>, '$errors' | '$silentErrors' | '$validate'> & {
|
|
4543
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. */
|
|
4544
|
-
readonly $each: Array<InferRegleSchemaStatusType<ArrayElement<TState
|
|
98
|
+
readonly $each: Array<InferRegleSchemaStatusType<ArrayElement<TState>, TShortcuts>>;
|
|
4545
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. */
|
|
4546
|
-
readonly $self: RegleSchemaFieldStatus<TState
|
|
100
|
+
readonly $self: RegleSchemaFieldStatus<TState, TShortcuts>;
|
|
4547
101
|
/**
|
|
4548
102
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
4549
103
|
*
|
|
4550
104
|
* Only contains issues from properties where $dirty equals true.
|
|
4551
105
|
*/
|
|
4552
|
-
readonly $issues: RegleCollectionErrors<TState
|
|
106
|
+
readonly $issues: RegleCollectionErrors<TState, true>;
|
|
4553
107
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
4554
108
|
*
|
|
4555
109
|
* Only contains errors from properties where $dirty equals true. */
|
|
4556
|
-
readonly $errors: RegleCollectionErrors<TState
|
|
110
|
+
readonly $errors: RegleCollectionErrors<TState>;
|
|
4557
111
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
4558
|
-
readonly $silentErrors: RegleCollectionErrors<TState
|
|
112
|
+
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
4559
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). */
|
|
4560
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState
|
|
114
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
4561
115
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
4562
|
-
//#endregion
|
|
4563
|
-
//#region src/types/options.types.d.ts
|
|
4564
116
|
type RegleSchemaBehaviourOptions = {
|
|
4565
117
|
/**
|
|
4566
118
|
* Settings for applying transforms and default to the current state
|
|
@@ -4576,15 +128,13 @@ type RegleSchemaBehaviourOptions = {
|
|
|
4576
128
|
onValidate?: boolean;
|
|
4577
129
|
};
|
|
4578
130
|
};
|
|
4579
|
-
//#endregion
|
|
4580
|
-
//#region src/core/useRegleSchema.d.ts
|
|
4581
131
|
type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
|
|
4582
132
|
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
4583
|
-
<TSchema extends StandardSchemaV1, TState
|
|
133
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<NoInferLegacy<TState>, {
|
|
4584
134
|
recurseIntoArrays: true;
|
|
4585
|
-
}>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState
|
|
135
|
+
}>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState>, {
|
|
4586
136
|
recurseIntoArrays: true;
|
|
4587
|
-
}>>, 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>;
|
|
4588
138
|
}
|
|
4589
139
|
/**
|
|
4590
140
|
* useRegle serves as the foundation for validation logic.
|
|
@@ -4606,8 +156,6 @@ interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = nev
|
|
|
4606
156
|
* Docs: {@link https://reglejs.dev/integrations/schemas-libraries}
|
|
4607
157
|
*/
|
|
4608
158
|
declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
4609
|
-
//#endregion
|
|
4610
|
-
//#region src/core/withDeps.d.ts
|
|
4611
159
|
/**
|
|
4612
160
|
*
|
|
4613
161
|
* Force dependency on any RPC schema
|
|
@@ -4624,13 +172,11 @@ declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {},
|
|
|
4624
172
|
* useRegleSchema({name: ''}, schema)
|
|
4625
173
|
* ```
|
|
4626
174
|
*/
|
|
4627
|
-
declare function withDeps<TSchema extends StandardSchemaV1, TParams
|
|
4628
|
-
//#endregion
|
|
4629
|
-
//#region src/core/inferSchema.d.ts
|
|
175
|
+
declare function withDeps<TSchema extends StandardSchemaV1, TParams extends unknown[] = []>(schema: TSchema, _depsArray: [...TParams]): TSchema;
|
|
4630
176
|
interface inferSchemaFn {
|
|
4631
|
-
<TSchema extends StandardSchemaV1, TState
|
|
177
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(state: MaybeRef<PartialDeep<TState, {
|
|
4632
178
|
recurseIntoArrays: true;
|
|
4633
|
-
}>> | DeepReactiveState<PartialDeep<TState
|
|
179
|
+
}>> | DeepReactiveState<PartialDeep<TState, {
|
|
4634
180
|
recurseIntoArrays: true;
|
|
4635
181
|
}>>, rulesFactory: MaybeRef<TSchema>): NoInferLegacy<TSchema>;
|
|
4636
182
|
}
|
|
@@ -4642,8 +188,6 @@ interface inferSchemaFn {
|
|
|
4642
188
|
* @param schema - Your schema
|
|
4643
189
|
*/
|
|
4644
190
|
declare const inferSchema: inferSchemaFn;
|
|
4645
|
-
//#endregion
|
|
4646
|
-
//#region src/core/defineRegleSchemaConfig.d.ts
|
|
4647
191
|
/**
|
|
4648
192
|
* Define a global regle configuration, where you can:
|
|
4649
193
|
* - Define global modifiers
|
|
@@ -4664,8 +208,6 @@ declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinit
|
|
|
4664
208
|
useRegleSchema: useRegleSchemaFn<TShortcuts>;
|
|
4665
209
|
inferSchema: inferSchemaFn;
|
|
4666
210
|
};
|
|
4667
|
-
//#endregion
|
|
4668
|
-
//#region src/core/createScopedUseRegleSchema.d.ts
|
|
4669
211
|
type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any, any>, TAsRecord extends boolean> = Omit<CreateScopedUseRegleOptions<any, TAsRecord>, 'customUseRegle'> & {
|
|
4670
212
|
/**
|
|
4671
213
|
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
@@ -4673,8 +215,8 @@ type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any
|
|
|
4673
215
|
customUseRegle?: TCustomRegle;
|
|
4674
216
|
};
|
|
4675
217
|
declare const useCollectSchemaScope: <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string>) => {
|
|
4676
|
-
r$: MergedScopedRegles<TValue$1>;
|
|
4677
|
-
}, useScopedRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
218
|
+
r$: _regle_core0.MergedScopedRegles<TValue$1>;
|
|
219
|
+
}, useScopedRegleSchema: useRegleSchemaFn<_regle_core0.RegleShortcutDefinition<any>, {}, {}>;
|
|
4678
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, {
|
|
4679
221
|
dispose: () => void;
|
|
4680
222
|
register: () => void;
|
|
@@ -4685,5 +227,4 @@ declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn
|
|
|
4685
227
|
useScopedRegle: TReturnedRegle;
|
|
4686
228
|
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
4687
229
|
};
|
|
4688
|
-
//#endregion
|
|
4689
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 };
|