@regle/schemas 1.9.7 → 1.10.0-beta.1

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