@regle/schemas 1.2.2 → 1.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/dist/regle-schemas.d.ts +2606 -254
- package/dist/regle-schemas.js +290 -0
- package/dist/regle-schemas.min.js +1 -0
- package/package.json +16 -16
- package/dist/regle-schemas.min.mjs +0 -1
- package/dist/regle-schemas.mjs +0 -289
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,29 +1,2386 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { MaybeRef, MaybeRefOrGetter, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region ../core/dist/regle-core.d.ts
|
|
5
|
+
//#region src/types/utils/misc.types.d.ts
|
|
6
|
+
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
7
|
+
type Maybe<T = any> = T | null | undefined;
|
|
8
|
+
type MaybeInput<T = any> = T | null | undefined;
|
|
9
|
+
type MaybeOutput<T = any> = T | undefined;
|
|
10
|
+
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
11
|
+
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
|
|
12
|
+
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
13
|
+
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
14
|
+
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
15
|
+
type OmitByType<T extends Record<string, any>, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] };
|
|
16
|
+
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
17
|
+
type ExcludeByType<T, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K] };
|
|
18
|
+
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
19
|
+
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
20
|
+
type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/utils/Array.types.d.ts
|
|
24
|
+
type ArrayElement$1<T> = T extends Array<infer U> ? U : never;
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/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
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/observable-like.d.ts
|
|
37
|
+
declare global {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
39
|
+
interface SymbolConstructor {
|
|
40
|
+
readonly observable: symbol;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
46
|
+
/**
|
|
47
|
+
@remarks
|
|
48
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
49
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
50
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
51
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
52
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
53
|
+
|
|
54
|
+
@category Observable
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
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).
|
|
59
|
+
|
|
60
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
61
|
+
|
|
62
|
+
@example
|
|
63
|
+
```
|
|
64
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
65
|
+
|
|
66
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
67
|
+
|
|
68
|
+
type Intersection = UnionToIntersection<Union>;
|
|
69
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A more applicable example which could make its way into your library code follows.
|
|
73
|
+
|
|
74
|
+
@example
|
|
75
|
+
```
|
|
76
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
77
|
+
|
|
78
|
+
class CommandOne {
|
|
79
|
+
commands: {
|
|
80
|
+
a1: () => undefined,
|
|
81
|
+
b1: () => undefined,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class CommandTwo {
|
|
86
|
+
commands: {
|
|
87
|
+
a2: (argA: string) => undefined,
|
|
88
|
+
b2: (argB: string) => undefined,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
93
|
+
type Union = typeof union;
|
|
94
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
95
|
+
|
|
96
|
+
type Intersection = UnionToIntersection<Union>;
|
|
97
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
@category Type
|
|
101
|
+
*/
|
|
102
|
+
type UnionToIntersection$1<Union> = (
|
|
103
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
104
|
+
// `Union` into a [distributive conditional
|
|
105
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
106
|
+
Union extends unknown
|
|
107
|
+
// The union type is used as the only argument to a function since the union
|
|
108
|
+
// of function arguments is an intersection.
|
|
109
|
+
? (distributedUnion: Union) => void
|
|
110
|
+
// This won't happen.
|
|
111
|
+
: never
|
|
112
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
113
|
+
// arguments of unions of functions as an intersection of the union.
|
|
114
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
115
|
+
// The `& Union` is to allow indexing by the resulting type
|
|
116
|
+
? Intersection & Union : never;
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/empty-object.d.ts
|
|
120
|
+
declare const emptyObjectSymbol$1: unique symbol;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
124
|
+
|
|
125
|
+
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)).
|
|
126
|
+
|
|
127
|
+
@example
|
|
128
|
+
```
|
|
129
|
+
import type {EmptyObject} from 'type-fest';
|
|
130
|
+
|
|
131
|
+
// The following illustrates the problem with `{}`.
|
|
132
|
+
const foo1: {} = {}; // Pass
|
|
133
|
+
const foo2: {} = []; // Pass
|
|
134
|
+
const foo3: {} = 42; // Pass
|
|
135
|
+
const foo4: {} = {a: 1}; // Pass
|
|
136
|
+
|
|
137
|
+
// With `EmptyObject` only the first case is valid.
|
|
138
|
+
const bar1: EmptyObject = {}; // Pass
|
|
139
|
+
const bar2: EmptyObject = 42; // Fail
|
|
140
|
+
const bar3: EmptyObject = []; // Fail
|
|
141
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
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}.
|
|
145
|
+
|
|
146
|
+
@category Object
|
|
147
|
+
*/
|
|
148
|
+
type EmptyObject$1 = {
|
|
149
|
+
[emptyObjectSymbol$1]?: never;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
154
|
+
|
|
155
|
+
@example
|
|
156
|
+
```
|
|
157
|
+
import type {IsEmptyObject} from 'type-fest';
|
|
158
|
+
|
|
159
|
+
type Pass = IsEmptyObject<{}>; //=> true
|
|
160
|
+
type Fail = IsEmptyObject<[]>; //=> false
|
|
161
|
+
type Fail = IsEmptyObject<null>; //=> false
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
@see EmptyObject
|
|
165
|
+
@category Object
|
|
166
|
+
*/
|
|
167
|
+
type IsEmptyObject<T> = T extends EmptyObject$1 ? true : false;
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
171
|
+
/**
|
|
172
|
+
Extract all optional keys from the given type.
|
|
173
|
+
|
|
174
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
175
|
+
|
|
176
|
+
@example
|
|
177
|
+
```
|
|
178
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
179
|
+
|
|
180
|
+
interface User {
|
|
181
|
+
name: string;
|
|
182
|
+
surname: string;
|
|
183
|
+
|
|
184
|
+
luckyNumber?: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
188
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
189
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const update1: UpdateOperation<User> = {
|
|
193
|
+
name: 'Alice'
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const update2: UpdateOperation<User> = {
|
|
197
|
+
name: 'Bob',
|
|
198
|
+
luckyNumber: REMOVE_FIELD
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
@category Utilities
|
|
203
|
+
*/
|
|
204
|
+
type OptionalKeysOf$1<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
205
|
+
? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
206
|
+
: never;
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
210
|
+
// Should never happen
|
|
211
|
+
/**
|
|
212
|
+
Extract all required keys from the given type.
|
|
213
|
+
|
|
214
|
+
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...
|
|
215
|
+
|
|
216
|
+
@example
|
|
217
|
+
```
|
|
218
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
219
|
+
|
|
220
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
221
|
+
|
|
222
|
+
interface User {
|
|
223
|
+
name: string;
|
|
224
|
+
surname: string;
|
|
225
|
+
|
|
226
|
+
luckyNumber?: number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
230
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
@category Utilities
|
|
234
|
+
*/
|
|
235
|
+
type RequiredKeysOf$1<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
236
|
+
? Exclude<keyof BaseType, OptionalKeysOf$1<BaseType>> : never;
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-never.d.ts
|
|
240
|
+
// Should never happen
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
Returns a boolean for whether the given type is `never`.
|
|
244
|
+
|
|
245
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
246
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
247
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
248
|
+
|
|
249
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
250
|
+
|
|
251
|
+
@example
|
|
252
|
+
```
|
|
253
|
+
import type {IsNever, And} from 'type-fest';
|
|
254
|
+
|
|
255
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
256
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
257
|
+
And<
|
|
258
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
259
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
260
|
+
>;
|
|
261
|
+
|
|
262
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
263
|
+
AreStringsEqual<I, O> extends true
|
|
264
|
+
? never
|
|
265
|
+
: void;
|
|
266
|
+
|
|
267
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
268
|
+
if (input === output) {
|
|
269
|
+
process.exit(0);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
endIfEqual('abc', 'abc');
|
|
274
|
+
//=> never
|
|
275
|
+
|
|
276
|
+
endIfEqual('abc', '123');
|
|
277
|
+
//=> void
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
@category Type Guard
|
|
281
|
+
@category Utilities
|
|
282
|
+
*/
|
|
283
|
+
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
284
|
+
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-never.d.ts
|
|
287
|
+
/**
|
|
288
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
289
|
+
|
|
290
|
+
@see {@link IsNever}
|
|
291
|
+
|
|
292
|
+
@example
|
|
293
|
+
```
|
|
294
|
+
import type {IfNever} from 'type-fest';
|
|
295
|
+
|
|
296
|
+
type ShouldBeTrue = IfNever<never>;
|
|
297
|
+
//=> true
|
|
298
|
+
|
|
299
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
300
|
+
//=> 'bar'
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
@category Type Guard
|
|
304
|
+
@category Utilities
|
|
305
|
+
*/
|
|
306
|
+
type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
307
|
+
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-any.d.ts
|
|
310
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
311
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
312
|
+
type NoInfer$1<T> = T extends infer U ? U : never;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
Returns a boolean for whether the given type is `any`.
|
|
316
|
+
|
|
317
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
318
|
+
|
|
319
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
320
|
+
|
|
321
|
+
@example
|
|
322
|
+
```
|
|
323
|
+
import type {IsAny} from 'type-fest';
|
|
324
|
+
|
|
325
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
326
|
+
const anyObject: any = {a: 1, b: 2};
|
|
327
|
+
|
|
328
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
329
|
+
return obj[key];
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const typedA = get(typedObject, 'a');
|
|
333
|
+
//=> 1
|
|
334
|
+
|
|
335
|
+
const anyA = get(anyObject, 'a');
|
|
336
|
+
//=> any
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
@category Type Guard
|
|
340
|
+
@category Utilities
|
|
341
|
+
*/
|
|
342
|
+
type IsAny$1<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
|
|
343
|
+
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/keys.d.ts
|
|
346
|
+
/**
|
|
347
|
+
Disallows any of the given keys.
|
|
348
|
+
*/
|
|
349
|
+
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
350
|
+
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/simplify.d.ts
|
|
353
|
+
/**
|
|
354
|
+
Utility type to retrieve only literal keys from type.
|
|
355
|
+
*/
|
|
356
|
+
/**
|
|
357
|
+
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.
|
|
358
|
+
|
|
359
|
+
@example
|
|
360
|
+
```
|
|
361
|
+
import type {Simplify} from 'type-fest';
|
|
362
|
+
|
|
363
|
+
type PositionProps = {
|
|
364
|
+
top: number;
|
|
365
|
+
left: number;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
type SizeProps = {
|
|
369
|
+
width: number;
|
|
370
|
+
height: number;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
374
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
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.
|
|
378
|
+
|
|
379
|
+
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`.
|
|
380
|
+
|
|
381
|
+
@example
|
|
382
|
+
```
|
|
383
|
+
import type {Simplify} from 'type-fest';
|
|
384
|
+
|
|
385
|
+
interface SomeInterface {
|
|
386
|
+
foo: number;
|
|
387
|
+
bar?: string;
|
|
388
|
+
baz: number | undefined;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
type SomeType = {
|
|
392
|
+
foo: number;
|
|
393
|
+
bar?: string;
|
|
394
|
+
baz: number | undefined;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
398
|
+
const someType: SomeType = literal;
|
|
399
|
+
const someInterface: SomeInterface = literal;
|
|
400
|
+
|
|
401
|
+
function fn(object: Record<string, unknown>): void {}
|
|
402
|
+
|
|
403
|
+
fn(literal); // Good: literal object type is sealed
|
|
404
|
+
fn(someType); // Good: type is sealed
|
|
405
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
406
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
410
|
+
@see SimplifyDeep
|
|
411
|
+
@category Object
|
|
412
|
+
*/
|
|
413
|
+
type Simplify$1<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
417
|
+
/**
|
|
418
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
419
|
+
|
|
420
|
+
This is the counterpart of `PickIndexSignature`.
|
|
421
|
+
|
|
422
|
+
Use-cases:
|
|
423
|
+
- Remove overly permissive signatures from third-party types.
|
|
424
|
+
|
|
425
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
426
|
+
|
|
427
|
+
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>`.
|
|
428
|
+
|
|
429
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
430
|
+
|
|
431
|
+
```
|
|
432
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
433
|
+
|
|
434
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
435
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
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:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
type Indexed = {} extends Record<string, unknown>
|
|
442
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
443
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
444
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
445
|
+
|
|
446
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
447
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
448
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
449
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
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`...
|
|
453
|
+
|
|
454
|
+
```
|
|
455
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
456
|
+
|
|
457
|
+
type OmitIndexSignature<ObjectType> = {
|
|
458
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
459
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
460
|
+
};
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
464
|
+
|
|
465
|
+
```
|
|
466
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
467
|
+
|
|
468
|
+
type OmitIndexSignature<ObjectType> = {
|
|
469
|
+
[KeyType in keyof ObjectType
|
|
470
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
471
|
+
as {} extends Record<KeyType, unknown>
|
|
472
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
473
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
474
|
+
]: ObjectType[KeyType];
|
|
475
|
+
};
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
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.
|
|
479
|
+
|
|
480
|
+
@example
|
|
481
|
+
```
|
|
482
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
483
|
+
|
|
484
|
+
interface Example {
|
|
485
|
+
// These index signatures will be removed.
|
|
486
|
+
[x: string]: any
|
|
487
|
+
[x: number]: any
|
|
488
|
+
[x: symbol]: any
|
|
489
|
+
[x: `head-${string}`]: string
|
|
490
|
+
[x: `${string}-tail`]: string
|
|
491
|
+
[x: `head-${string}-tail`]: string
|
|
492
|
+
[x: `${bigint}`]: string
|
|
493
|
+
[x: `embedded-${number}`]: string
|
|
494
|
+
|
|
495
|
+
// These explicitly defined keys will remain.
|
|
496
|
+
foo: 'bar';
|
|
497
|
+
qux?: 'baz';
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
501
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
@see PickIndexSignature
|
|
505
|
+
@category Object
|
|
506
|
+
*/
|
|
507
|
+
type OmitIndexSignature$1<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
508
|
+
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
511
|
+
/**
|
|
512
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
513
|
+
|
|
514
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
515
|
+
|
|
516
|
+
@example
|
|
517
|
+
```
|
|
518
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
519
|
+
|
|
520
|
+
declare const symbolKey: unique symbol;
|
|
521
|
+
|
|
522
|
+
type Example = {
|
|
523
|
+
// These index signatures will remain.
|
|
524
|
+
[x: string]: unknown;
|
|
525
|
+
[x: number]: unknown;
|
|
526
|
+
[x: symbol]: unknown;
|
|
527
|
+
[x: `head-${string}`]: string;
|
|
528
|
+
[x: `${string}-tail`]: string;
|
|
529
|
+
[x: `head-${string}-tail`]: string;
|
|
530
|
+
[x: `${bigint}`]: string;
|
|
531
|
+
[x: `embedded-${number}`]: string;
|
|
532
|
+
|
|
533
|
+
// These explicitly defined keys will be removed.
|
|
534
|
+
['kebab-case-key']: string;
|
|
535
|
+
[symbolKey]: string;
|
|
536
|
+
foo: 'bar';
|
|
537
|
+
qux?: 'baz';
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
541
|
+
// {
|
|
542
|
+
// [x: string]: unknown;
|
|
543
|
+
// [x: number]: unknown;
|
|
544
|
+
// [x: symbol]: unknown;
|
|
545
|
+
// [x: `head-${string}`]: string;
|
|
546
|
+
// [x: `${string}-tail`]: string;
|
|
547
|
+
// [x: `head-${string}-tail`]: string;
|
|
548
|
+
// [x: `${bigint}`]: string;
|
|
549
|
+
// [x: `embedded-${number}`]: string;
|
|
550
|
+
// }
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
@see OmitIndexSignature
|
|
554
|
+
@category Object
|
|
555
|
+
*/
|
|
556
|
+
type PickIndexSignature$1<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
557
|
+
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/merge.d.ts
|
|
560
|
+
// Merges two objects without worrying about index signatures.
|
|
561
|
+
type SimpleMerge$1<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
565
|
+
|
|
566
|
+
@example
|
|
567
|
+
```
|
|
568
|
+
import type {Merge} from 'type-fest';
|
|
569
|
+
|
|
570
|
+
interface Foo {
|
|
571
|
+
[x: string]: unknown;
|
|
572
|
+
[x: number]: unknown;
|
|
573
|
+
foo: string;
|
|
574
|
+
bar: symbol;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
type Bar = {
|
|
578
|
+
[x: number]: number;
|
|
579
|
+
[x: symbol]: unknown;
|
|
580
|
+
bar: Date;
|
|
581
|
+
baz: boolean;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
585
|
+
// => {
|
|
586
|
+
// [x: string]: unknown;
|
|
587
|
+
// [x: number]: number;
|
|
588
|
+
// [x: symbol]: unknown;
|
|
589
|
+
// foo: string;
|
|
590
|
+
// bar: Date;
|
|
591
|
+
// baz: boolean;
|
|
592
|
+
// }
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
@category Object
|
|
596
|
+
*/
|
|
597
|
+
type Merge$1<Destination, Source> = Simplify$1<SimpleMerge$1<PickIndexSignature$1<Destination>, PickIndexSignature$1<Source>> & SimpleMerge$1<OmitIndexSignature$1<Destination>, OmitIndexSignature$1<Source>>>;
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-any.d.ts
|
|
601
|
+
/**
|
|
602
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
603
|
+
|
|
604
|
+
@see {@link IsAny}
|
|
605
|
+
|
|
606
|
+
@example
|
|
607
|
+
```
|
|
608
|
+
import type {IfAny} from 'type-fest';
|
|
609
|
+
|
|
610
|
+
type ShouldBeTrue = IfAny<any>;
|
|
611
|
+
//=> true
|
|
612
|
+
|
|
613
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
614
|
+
//=> 'bar'
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
@category Type Guard
|
|
618
|
+
@category Utilities
|
|
619
|
+
*/
|
|
620
|
+
type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
621
|
+
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/type.d.ts
|
|
624
|
+
/**
|
|
625
|
+
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
626
|
+
*/
|
|
627
|
+
type BuiltIns$1 = Primitive$1 | void | Date | RegExp;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
Matches non-recursive types.
|
|
631
|
+
*/
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
Test if the given function has multiple call signatures.
|
|
635
|
+
|
|
636
|
+
Needed to handle the case of a single call signature with properties.
|
|
637
|
+
|
|
638
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
639
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/object.d.ts
|
|
644
|
+
// Should never happen
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
Merges user specified options with default options.
|
|
648
|
+
|
|
649
|
+
@example
|
|
650
|
+
```
|
|
651
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
652
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
653
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
654
|
+
|
|
655
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
656
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
@example
|
|
660
|
+
```
|
|
661
|
+
// Complains if default values are not provided for optional options
|
|
662
|
+
|
|
663
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
664
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
665
|
+
type SpecifiedOptions = {};
|
|
666
|
+
|
|
667
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
668
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
669
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
@example
|
|
673
|
+
```
|
|
674
|
+
// Complains if an option's default type does not conform to the expected type
|
|
675
|
+
|
|
676
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
677
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
678
|
+
type SpecifiedOptions = {};
|
|
679
|
+
|
|
680
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
681
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
682
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
@example
|
|
686
|
+
```
|
|
687
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
688
|
+
|
|
689
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
690
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
691
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
692
|
+
|
|
693
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
694
|
+
// ~~~~~~~~~~~~~~~~
|
|
695
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
696
|
+
```
|
|
697
|
+
*/
|
|
698
|
+
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> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify$1<Merge$1<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf$1<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
699
|
+
>>;
|
|
700
|
+
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/require-exactly-one.d.ts
|
|
703
|
+
/**
|
|
704
|
+
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
705
|
+
|
|
706
|
+
Use-cases:
|
|
707
|
+
- Creating interfaces for components that only need one of the keys to display properly.
|
|
708
|
+
- Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
|
|
709
|
+
|
|
710
|
+
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.
|
|
711
|
+
|
|
712
|
+
@example
|
|
713
|
+
```
|
|
714
|
+
import type {RequireExactlyOne} from 'type-fest';
|
|
715
|
+
|
|
716
|
+
type Responder = {
|
|
717
|
+
text: () => string;
|
|
718
|
+
json: () => string;
|
|
719
|
+
secure: boolean;
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
|
|
723
|
+
// Adding a `text` key here would cause a compile error.
|
|
724
|
+
|
|
725
|
+
json: () => '{"message": "ok"}',
|
|
726
|
+
secure: true
|
|
727
|
+
};
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
@category Object
|
|
731
|
+
*/
|
|
732
|
+
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = { [Key in KeysType]: (Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>) }[KeysType] & Omit<ObjectType, KeysType>;
|
|
733
|
+
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/require-one-or-none.d.ts
|
|
736
|
+
/**
|
|
737
|
+
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.
|
|
738
|
+
|
|
739
|
+
@example
|
|
740
|
+
```
|
|
741
|
+
import type {RequireOneOrNone} from 'type-fest';
|
|
742
|
+
|
|
743
|
+
type Responder = RequireOneOrNone<{
|
|
744
|
+
text: () => string;
|
|
745
|
+
json: () => string;
|
|
746
|
+
secure: boolean;
|
|
747
|
+
}, 'text' | 'json'>;
|
|
748
|
+
|
|
749
|
+
const responder1: Responder = {
|
|
750
|
+
secure: true
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const responder2: Responder = {
|
|
754
|
+
text: () => '{"message": "hi"}',
|
|
755
|
+
secure: true
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
const responder3: Responder = {
|
|
759
|
+
json: () => '{"message": "ok"}',
|
|
760
|
+
secure: true
|
|
761
|
+
};
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
@category Object
|
|
765
|
+
*/
|
|
766
|
+
type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>;
|
|
767
|
+
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/partial-deep.d.ts
|
|
770
|
+
// Ignore unspecified keys.
|
|
771
|
+
/**
|
|
772
|
+
@see {@link PartialDeep}
|
|
773
|
+
*/
|
|
774
|
+
type PartialDeepOptions$1 = {
|
|
775
|
+
/**
|
|
776
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
777
|
+
@default false
|
|
778
|
+
*/
|
|
779
|
+
readonly recurseIntoArrays?: boolean;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
Allows `undefined` values in non-tuple arrays.
|
|
783
|
+
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
784
|
+
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
785
|
+
@default true
|
|
786
|
+
@example
|
|
787
|
+
You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
|
|
788
|
+
```
|
|
789
|
+
import type {PartialDeep} from 'type-fest';
|
|
790
|
+
type Settings = {
|
|
791
|
+
languages: string[];
|
|
792
|
+
};
|
|
793
|
+
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
794
|
+
partialSettings.languages = [undefined]; // Error
|
|
795
|
+
partialSettings.languages = []; // Ok
|
|
796
|
+
```
|
|
797
|
+
*/
|
|
798
|
+
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
799
|
+
};
|
|
800
|
+
type DefaultPartialDeepOptions$1 = {
|
|
801
|
+
recurseIntoArrays: false;
|
|
802
|
+
allowUndefinedInNonTupleArrays: true;
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
Create a type from another type with all keys and nested keys set to optional.
|
|
807
|
+
|
|
808
|
+
Use-cases:
|
|
809
|
+
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
810
|
+
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
811
|
+
|
|
812
|
+
@example
|
|
813
|
+
```
|
|
814
|
+
import type {PartialDeep} from 'type-fest';
|
|
815
|
+
|
|
816
|
+
const settings: Settings = {
|
|
817
|
+
textEditor: {
|
|
818
|
+
fontSize: 14,
|
|
819
|
+
fontColor: '#000000',
|
|
820
|
+
fontWeight: 400
|
|
821
|
+
},
|
|
822
|
+
autocomplete: false,
|
|
823
|
+
autosave: true
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
827
|
+
return {...settings, ...savedSettings};
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
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:
|
|
834
|
+
|
|
835
|
+
```
|
|
836
|
+
import type {PartialDeep} from 'type-fest';
|
|
837
|
+
|
|
838
|
+
type Settings = {
|
|
839
|
+
languages: string[];
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
843
|
+
languages: [undefined]
|
|
844
|
+
};
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
@see {@link PartialDeepOptions}
|
|
848
|
+
|
|
849
|
+
@category Object
|
|
850
|
+
@category Array
|
|
851
|
+
@category Set
|
|
852
|
+
@category Map
|
|
853
|
+
*/
|
|
854
|
+
type PartialDeep$1<T, Options extends PartialDeepOptions$1 = {}> = _PartialDeep$1<T, ApplyDefaultOptions$1<PartialDeepOptions$1, DefaultPartialDeepOptions$1, Options>>;
|
|
855
|
+
type _PartialDeep$1<T, Options extends Required<PartialDeepOptions$1>> = T extends BuiltIns$1 | ((new (...arguments_: any[]) => unknown)) ? T : IsNever$1<keyof T> extends true // For functions with no properties
|
|
856
|
+
? 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 object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
857
|
+
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
858
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
859
|
+
? 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
|
|
860
|
+
: T // If they don't opt into array testing, just use the original type
|
|
861
|
+
: PartialObjectDeep$1<T, Options> : unknown;
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
865
|
+
*/
|
|
866
|
+
type PartialMapDeep$1<KeyType, ValueType, Options extends Required<PartialDeepOptions$1>> = {} & Map<_PartialDeep$1<KeyType, Options>, _PartialDeep$1<ValueType, Options>>;
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
870
|
+
*/
|
|
871
|
+
type PartialSetDeep$1<T, Options extends Required<PartialDeepOptions$1>> = {} & Set<_PartialDeep$1<T, Options>>;
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
875
|
+
*/
|
|
876
|
+
type PartialReadonlyMapDeep$1<KeyType, ValueType, Options extends Required<PartialDeepOptions$1>> = {} & ReadonlyMap<_PartialDeep$1<KeyType, Options>, _PartialDeep$1<ValueType, Options>>;
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
880
|
+
*/
|
|
881
|
+
type PartialReadonlySetDeep$1<T, Options extends Required<PartialDeepOptions$1>> = {} & ReadonlySet<_PartialDeep$1<T, Options>>;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
885
|
+
*/
|
|
886
|
+
type PartialObjectDeep$1<ObjectType extends object, Options extends Required<PartialDeepOptions$1>> = (ObjectType extends ((...arguments_: any) => unknown) ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType> : {}) & ({ [KeyType in keyof ObjectType]?: _PartialDeep$1<ObjectType[KeyType], Options> });
|
|
887
|
+
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/required-deep.d.ts
|
|
890
|
+
|
|
891
|
+
//#endregion
|
|
892
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
893
|
+
/**
|
|
894
|
+
Returns the last element of a union type.
|
|
895
|
+
|
|
896
|
+
@example
|
|
897
|
+
```
|
|
898
|
+
type Last = LastOfUnion<1 | 2 | 3>;
|
|
899
|
+
//=> 3
|
|
900
|
+
```
|
|
901
|
+
*/
|
|
902
|
+
type LastOfUnion<T> = UnionToIntersection$1<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
906
|
+
|
|
907
|
+
"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.
|
|
908
|
+
|
|
909
|
+
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.
|
|
910
|
+
|
|
911
|
+
@example
|
|
912
|
+
```
|
|
913
|
+
import type {UnionToTuple} from 'type-fest';
|
|
914
|
+
|
|
915
|
+
type Numbers = 1 | 2 | 3;
|
|
916
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
917
|
+
//=> [1, 2, 3]
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
@example
|
|
921
|
+
```
|
|
922
|
+
import type {UnionToTuple} from 'type-fest';
|
|
923
|
+
|
|
924
|
+
const pets = {
|
|
925
|
+
dog: '🐶',
|
|
926
|
+
cat: '🐱',
|
|
927
|
+
snake: '🐍',
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
type Pet = keyof typeof pets;
|
|
931
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
932
|
+
|
|
933
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
934
|
+
//=> ['dog', 'cat', 'snake']
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
@category Array
|
|
938
|
+
*/
|
|
939
|
+
type UnionToTuple$1<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple$1<Exclude<T, L>>, L] : [];
|
|
940
|
+
|
|
941
|
+
//#endregion
|
|
942
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-null.d.ts
|
|
943
|
+
/**
|
|
944
|
+
Returns a boolean for whether the given type is `null`.
|
|
945
|
+
|
|
946
|
+
@example
|
|
947
|
+
```
|
|
948
|
+
import type {IsNull} from 'type-fest';
|
|
949
|
+
|
|
950
|
+
type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
|
|
951
|
+
|
|
952
|
+
type Example1 = NonNullFallback<null, string>;
|
|
953
|
+
//=> string
|
|
954
|
+
|
|
955
|
+
type Example2 = NonNullFallback<number, string>;
|
|
956
|
+
//=? number
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
@category Type Guard
|
|
960
|
+
@category Utilities
|
|
961
|
+
*/
|
|
962
|
+
type IsNull<T> = [T] extends [null] ? true : false;
|
|
963
|
+
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-unknown.d.ts
|
|
966
|
+
/**
|
|
967
|
+
Returns a boolean for whether the given type is `unknown`.
|
|
968
|
+
|
|
969
|
+
@link https://github.com/dsherret/conditional-type-checks/pull/16
|
|
970
|
+
|
|
971
|
+
Useful in type utilities, such as when dealing with unknown data from API calls.
|
|
972
|
+
|
|
973
|
+
@example
|
|
974
|
+
```
|
|
975
|
+
import type {IsUnknown} from 'type-fest';
|
|
976
|
+
|
|
977
|
+
// https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
|
|
978
|
+
type Action<TState, TPayload = void> =
|
|
979
|
+
IsUnknown<TPayload> extends true
|
|
980
|
+
? (state: TState) => TState,
|
|
981
|
+
: (state: TState, payload: TPayload) => TState;
|
|
982
|
+
|
|
983
|
+
class Store<TState> {
|
|
984
|
+
constructor(private state: TState) {}
|
|
985
|
+
|
|
986
|
+
execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
|
|
987
|
+
this.state = action(this.state, payload);
|
|
988
|
+
return this.state;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// ... other methods
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const store = new Store({value: 1});
|
|
995
|
+
declare const someExternalData: unknown;
|
|
996
|
+
|
|
997
|
+
store.execute(state => ({value: state.value + 1}));
|
|
998
|
+
//=> `TPayload` is `void`
|
|
999
|
+
|
|
1000
|
+
store.execute((state, payload) => ({value: state.value + payload}), 5);
|
|
1001
|
+
//=> `TPayload` is `5`
|
|
1002
|
+
|
|
1003
|
+
store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
|
|
1004
|
+
//=> Errors: `action` is `(state: TState) => TState`
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
@category Utilities
|
|
1008
|
+
*/
|
|
1009
|
+
type IsUnknown$1<T> = (unknown extends T // `T` can be `unknown` or `any`
|
|
1010
|
+
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
|
1011
|
+
? true : false : false);
|
|
1012
|
+
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/types/core/modifiers.types.d.ts
|
|
1015
|
+
interface RegleBehaviourOptions {
|
|
1016
|
+
/**
|
|
1017
|
+
* Only display error when calling `r$.$validate()`
|
|
1018
|
+
* @default false
|
|
1019
|
+
*/
|
|
1020
|
+
lazy?: boolean | undefined;
|
|
1021
|
+
/**
|
|
1022
|
+
* Automatically set the dirty set without the need of `$value` or `$touch`.
|
|
1023
|
+
* @default true
|
|
1024
|
+
*
|
|
1025
|
+
*/
|
|
1026
|
+
autoDirty?: boolean | undefined;
|
|
1027
|
+
/**
|
|
1028
|
+
* Only update error status when calling `$validate`.
|
|
1029
|
+
* Will not display errors as you type
|
|
1030
|
+
* @default false
|
|
1031
|
+
*
|
|
1032
|
+
* @default true if rewardEarly is true
|
|
1033
|
+
*
|
|
1034
|
+
*/
|
|
1035
|
+
silent?: boolean | undefined;
|
|
1036
|
+
/**
|
|
1037
|
+
* The fields will turn valid when they are, but not invalid unless calling `r$.$validate()`
|
|
1038
|
+
* @default false
|
|
1039
|
+
*/
|
|
1040
|
+
rewardEarly?: boolean | undefined;
|
|
1041
|
+
/**
|
|
1042
|
+
* Define whether the external errors should be cleared when updating a field
|
|
1043
|
+
*
|
|
1044
|
+
* Default to `false` if `$silent` is set to `true`
|
|
1045
|
+
* @default true
|
|
1046
|
+
*
|
|
1047
|
+
*
|
|
1048
|
+
*/
|
|
1049
|
+
clearExternalErrorsOnChange?: boolean | undefined;
|
|
1050
|
+
}
|
|
1051
|
+
interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
|
|
1052
|
+
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState>>>;
|
|
1053
|
+
validationGroups?: (fields: RegleStatus<TState, TRules>['$fields']) => TValidationGroups;
|
|
1054
|
+
}
|
|
1055
|
+
type RegleValidationGroupEntry = RegleFieldStatus<any, any>;
|
|
1056
|
+
interface RegleValidationGroupOutput {
|
|
1057
|
+
$invalid: boolean;
|
|
1058
|
+
$error: boolean;
|
|
1059
|
+
$pending: boolean;
|
|
1060
|
+
$dirty: boolean;
|
|
1061
|
+
$correct: boolean;
|
|
1062
|
+
$errors: string[];
|
|
1063
|
+
$silentErrors: string[];
|
|
1064
|
+
}
|
|
1065
|
+
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
1066
|
+
/**
|
|
1067
|
+
* Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
|
|
1068
|
+
*/
|
|
1069
|
+
$debounce?: number;
|
|
1070
|
+
};
|
|
1071
|
+
type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
|
|
1072
|
+
/**
|
|
1073
|
+
* Allow deep compare of array children to compute the `$edited` property
|
|
1074
|
+
*
|
|
1075
|
+
* Disabled by default for performance
|
|
1076
|
+
*
|
|
1077
|
+
* @default false
|
|
1078
|
+
* */
|
|
1079
|
+
$deepCompare?: boolean;
|
|
1080
|
+
};
|
|
1081
|
+
type ShortcutCommonFn<T extends Record<string, any>> = {
|
|
1082
|
+
[x: string]: (element: OmitByType<T, Function>) => unknown;
|
|
1083
|
+
};
|
|
1084
|
+
type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
|
|
1085
|
+
/**
|
|
1086
|
+
* Allow you to customize the properties for every field
|
|
1087
|
+
*/
|
|
1088
|
+
fields?: ShortcutCommonFn<RegleFieldStatus<any, Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1089
|
+
/**
|
|
1090
|
+
* Allow you to customize the properties for every parent of a nested object
|
|
1091
|
+
*/
|
|
1092
|
+
nested?: ShortcutCommonFn<RegleStatus<Record<string, any>, ReglePartialRuleTree<any, Partial<TCustomRules> & Partial<DefaultValidators>>>>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Allow you to customize the properties for every parent of a collection
|
|
1095
|
+
*/
|
|
1096
|
+
collections?: ShortcutCommonFn<RegleCollectionStatus<any[], Partial<TCustomRules> & Partial<DefaultValidators>>>;
|
|
1097
|
+
};
|
|
1098
|
+
type AddDollarToOptions<T extends Record<string, any>> = { [K in keyof T as `$${string & K}`]: T[K] };
|
|
1099
|
+
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/types/core/useRegle.types.d.ts
|
|
1102
|
+
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> = {}> = {
|
|
1103
|
+
/**
|
|
1104
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1105
|
+
*
|
|
1106
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1107
|
+
*/
|
|
1108
|
+
r$: Raw<RegleRoot<TState, TRules, TValidationGroups, TShortcuts>>;
|
|
1109
|
+
} & TAdditionalReturnProperties;
|
|
1110
|
+
type RegleSingleField<TState extends Maybe<PrimitiveTypes> = any, TRules extends RegleRuleDecl<NonNullable<TState>> = EmptyObject$1, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
1111
|
+
/**
|
|
1112
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
1113
|
+
*
|
|
1114
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
1115
|
+
*/
|
|
1116
|
+
r$: Raw<RegleFieldStatus<TState, TRules, TShortcuts>>;
|
|
1117
|
+
} & TAdditionalReturnProperties;
|
|
1118
|
+
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
|
|
1119
|
+
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>;
|
|
1120
|
+
|
|
1121
|
+
//#endregion
|
|
1122
|
+
//#region src/types/core/reset.types.d.ts
|
|
1123
|
+
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
1124
|
+
/**
|
|
1125
|
+
* Reset validation status and reset form state to its initial state
|
|
1126
|
+
*
|
|
1127
|
+
* ⚠️ This doesn't work if the state is a `reactive` object.
|
|
1128
|
+
*/
|
|
1129
|
+
toInitialState?: boolean;
|
|
1130
|
+
/**
|
|
1131
|
+
* Reset validation status and reset form state to the given state
|
|
1132
|
+
* Also set the new state as the initial state.
|
|
1133
|
+
*/
|
|
1134
|
+
toState?: TState | (() => TState);
|
|
1135
|
+
/**
|
|
1136
|
+
* Clears the $externalErrors state back to an empty object.
|
|
1137
|
+
*/
|
|
1138
|
+
clearExternalErrors?: boolean;
|
|
1139
|
+
}, 'toInitialState' | 'toState'>;
|
|
1140
|
+
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/types/core/scopedRegle.types.d.ts
|
|
1143
|
+
type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
|
|
1144
|
+
'~~global': Record<string, SuperCompatibleRegleRoot>;
|
|
1145
|
+
};
|
|
1146
|
+
type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
1147
|
+
|
|
1148
|
+
//#endregion
|
|
1149
|
+
//#region src/types/core/results.types.d.ts
|
|
1150
|
+
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]> }>;
|
|
1151
|
+
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any>> = {
|
|
1152
|
+
valid: false;
|
|
1153
|
+
data: IsUnknown$1<Data> extends true ? unknown : NonNullable<Data> extends Date | File ? MaybeOutput<Data> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data>;
|
|
1154
|
+
} | {
|
|
1155
|
+
valid: true;
|
|
1156
|
+
data: IsUnknown$1<Data> extends true ? unknown : Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules>;
|
|
1157
|
+
};
|
|
1158
|
+
/**
|
|
1159
|
+
* Infer safe output from any `r$` instance
|
|
1160
|
+
*
|
|
1161
|
+
* ```ts
|
|
1162
|
+
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
|
|
1166
|
+
type $InternalRegleResult = {
|
|
1167
|
+
valid: boolean;
|
|
1168
|
+
data: any;
|
|
1169
|
+
};
|
|
1170
|
+
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]> } & { [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>> }> : TState;
|
|
1171
|
+
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? [unknown] extends TRule['required'] ? NonNullable<TRule['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<TRule['required']> extends TRule['required'] ? TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
|
|
1172
|
+
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;
|
|
1173
|
+
type ArrayHaveAtLeastOneRequiredField<TState extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState>> = TState extends Maybe<TState> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends RegleRuleDecl ? Omit<TRule, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement$1<NonNullable<TState>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
|
|
1174
|
+
type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? DeepSafeFormState<NonNullable<TState> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState>> : {}, TRule> : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends true ? TState : MaybeOutput<TState> : TState : TState;
|
|
1175
|
+
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
|
|
1176
|
+
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState> : MaybeOutput<TState>;
|
|
1177
|
+
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/utils.d.ts
|
|
1180
|
+
/**
|
|
1181
|
+
* Negates a boolean type.
|
|
1182
|
+
*/
|
|
1183
|
+
type Not<T extends boolean> = T extends true ? false : true;
|
|
1184
|
+
/**
|
|
1185
|
+
* Returns `true` if at least one of the types in the
|
|
1186
|
+
* {@linkcode Types} array is `true`, otherwise returns `false`.
|
|
1187
|
+
*/
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* Checks if all the boolean types in the {@linkcode Types} array are `true`.
|
|
1191
|
+
*/
|
|
1192
|
+
type And<Types extends boolean[]> = Types[number] extends true ? true : false;
|
|
1193
|
+
/**
|
|
1194
|
+
* Represents an equality type that returns {@linkcode Right} if
|
|
1195
|
+
* {@linkcode Left} is `true`,
|
|
1196
|
+
* otherwise returns the negation of {@linkcode Right}.
|
|
1197
|
+
*/
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* @internal
|
|
1201
|
+
*/
|
|
1202
|
+
declare const secret: unique symbol;
|
|
1203
|
+
/**
|
|
1204
|
+
* @internal
|
|
1205
|
+
*/
|
|
1206
|
+
type Secret = typeof secret;
|
|
1207
|
+
/**
|
|
1208
|
+
* Checks if the given type is `never`.
|
|
1209
|
+
*/
|
|
1210
|
+
type IsNever$2<T> = [T] extends [never] ? true : false;
|
|
1211
|
+
/**
|
|
1212
|
+
* Checks if the given type is `any`.
|
|
1213
|
+
*/
|
|
1214
|
+
type IsAny$2<T> = [T] extends [Secret] ? Not<IsNever$2<T>> : false;
|
|
1215
|
+
/**
|
|
1216
|
+
* Determines if the given type is `unknown`.
|
|
1217
|
+
*/
|
|
1218
|
+
type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny$2<T>> : false;
|
|
1219
|
+
/**
|
|
1220
|
+
* Determines if a type is either `never` or `any`.
|
|
1221
|
+
*/
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Subjective "useful" keys from a type. For objects it's just `keyof` but for
|
|
1225
|
+
* tuples/arrays it's the number keys.
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* UsefulKeys<{ a: 1; b: 2 }> // 'a' | 'b'
|
|
1230
|
+
*
|
|
1231
|
+
* UsefulKeys<['a', 'b']> // '0' | '1'
|
|
1232
|
+
*
|
|
1233
|
+
* UsefulKeys<string[]> // number
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
type UsefulKeys<T> = T extends any[] ? { [K in keyof T]: K }[number] : keyof T;
|
|
1237
|
+
/**
|
|
1238
|
+
* Extracts the keys from a type that are required (not optional).
|
|
1239
|
+
*/
|
|
1240
|
+
type RequiredKeys<T> = Extract<{ [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T], keyof T>;
|
|
1241
|
+
/**
|
|
1242
|
+
* Gets the keys of an object type that are optional.
|
|
1243
|
+
*/
|
|
1244
|
+
type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
|
|
1245
|
+
/**
|
|
1246
|
+
* Extracts the keys from a type that are not `readonly`.
|
|
1247
|
+
*/
|
|
1248
|
+
type ReadonlyKeys<T> = Extract<{ [K in keyof T]-?: ReadonlyEquivalent<{ [_K in K]: T[K] }, { -readonly [_K in K]: T[K] }> extends true ? never : K }[keyof T], keyof T>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Determines if two types, are equivalent in a `readonly` manner.
|
|
1251
|
+
*
|
|
1252
|
+
* @internal
|
|
1253
|
+
*/
|
|
1254
|
+
type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
|
|
1257
|
+
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
|
|
1258
|
+
* 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`.
|
|
1259
|
+
*/
|
|
1260
|
+
type Extends<Left, Right> = IsNever$2<Left> extends true ? IsNever$2<Right> : [Left] extends [Right] ? true : false;
|
|
1261
|
+
/**
|
|
1262
|
+
* Checks if the {@linkcode Left} type extends the {@linkcode Right} type,
|
|
1263
|
+
* excluding `any` or `never`.
|
|
1264
|
+
*/
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* Checks if two types are strictly equal using
|
|
1268
|
+
* the TypeScript internal identical-to operator.
|
|
1269
|
+
*
|
|
1270
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
|
|
1271
|
+
*/
|
|
1272
|
+
type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends (<T>() => T extends (R & T) | T ? true : false) ? IsNever$2<L> extends IsNever$2<R> ? true : false : false;
|
|
1273
|
+
/**
|
|
1274
|
+
* Checks that {@linkcode Left} and {@linkcode Right} extend each other.
|
|
1275
|
+
* Not quite the same as an equality check since `any` can make it resolve
|
|
1276
|
+
* to `true`. So should only be used when {@linkcode Left} and
|
|
1277
|
+
* {@linkcode Right} are known to avoid `any`.
|
|
1278
|
+
*/
|
|
1279
|
+
type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
|
|
1280
|
+
/**
|
|
1281
|
+
* @internal
|
|
1282
|
+
*/
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Convert a union to an intersection.
|
|
1286
|
+
* `A | B | C` -\> `A & B & C`
|
|
1287
|
+
*/
|
|
1288
|
+
type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection : never;
|
|
1289
|
+
/**
|
|
1290
|
+
* Get the last element of a union.
|
|
1291
|
+
* First, converts to a union of `() => T` functions,
|
|
1292
|
+
* then uses {@linkcode UnionToIntersection} to get the last one.
|
|
1293
|
+
*/
|
|
1294
|
+
type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends (() => infer R) ? R : never;
|
|
1295
|
+
/**
|
|
1296
|
+
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
|
1297
|
+
* "last" union member to the end of a tuple, and recursively prepends
|
|
1298
|
+
* the remainder of the union.
|
|
1299
|
+
*/
|
|
1300
|
+
type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever$2<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
|
|
1301
|
+
/**
|
|
1302
|
+
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
|
1303
|
+
*/
|
|
1304
|
+
type UnionToTuple<Union> = TuplifyUnion<Union>;
|
|
1305
|
+
type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
|
|
1306
|
+
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/overloads.d.ts
|
|
1309
|
+
/**
|
|
1310
|
+
* A recursive version of `Pick` that selects properties from the left type that are present in the right type.
|
|
1311
|
+
* The "leaf" types from `Left` are used - only the keys of `Right` are considered.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* const user = {email: 'a@b.com', name: 'John Doe', address: {street: '123 2nd St', city: 'New York', zip: '10001', state: 'NY', country: 'USA'}}
|
|
1316
|
+
*
|
|
1317
|
+
* type Result = DeepPickMatchingProps<typeof user, {name: unknown; address: {city: unknown}}> // {name: string, address: {city: string}}
|
|
1318
|
+
* ```
|
|
1319
|
+
*/
|
|
1320
|
+
/**
|
|
1321
|
+
* The simple(ish) way to get overload info from a function
|
|
1322
|
+
* {@linkcode FunctionType}. Recent versions of TypeScript will match any
|
|
1323
|
+
* function against a generic 10-overload type, filling in slots with
|
|
1324
|
+
* duplicates of the function. So, we can just match against a single type
|
|
1325
|
+
* and get all the overloads.
|
|
1326
|
+
*
|
|
1327
|
+
* For older versions of TypeScript, we'll need to painstakingly do
|
|
1328
|
+
* ten separate matches.
|
|
1329
|
+
*/
|
|
1330
|
+
type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
|
|
1331
|
+
(...args: infer A1): infer R1;
|
|
1332
|
+
(...args: infer A2): infer R2;
|
|
1333
|
+
(...args: infer A3): infer R3;
|
|
1334
|
+
(...args: infer A4): infer R4;
|
|
1335
|
+
(...args: infer A5): infer R5;
|
|
1336
|
+
(...args: infer A6): infer R6;
|
|
1337
|
+
(...args: infer A7): infer R7;
|
|
1338
|
+
(...args: infer A8): infer R8;
|
|
1339
|
+
(...args: infer A9): infer R9;
|
|
1340
|
+
(...args: infer A10): infer R10;
|
|
1341
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : never;
|
|
1342
|
+
/**
|
|
1343
|
+
* A function with `unknown` parameters and return type.
|
|
1344
|
+
*/
|
|
1345
|
+
type UnknownFunction = (...args: unknown[]) => unknown;
|
|
1346
|
+
/**
|
|
1347
|
+
* `true` iff {@linkcode FunctionType} is
|
|
1348
|
+
* equivalent to `(...args: unknown[]) => unknown`,
|
|
1349
|
+
* which is what an overload variant looks like for a non-existent overload.
|
|
1350
|
+
* This is useful because older versions of TypeScript end up with
|
|
1351
|
+
* 9 "useless" overloads and one real one for parameterless/generic functions.
|
|
1352
|
+
*
|
|
1353
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
|
1354
|
+
*/
|
|
1355
|
+
type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownFunction>;
|
|
1356
|
+
/**
|
|
1357
|
+
* Old versions of TypeScript can sometimes seem to refuse to separate out
|
|
1358
|
+
* union members unless you put them each in a pointless tuple and add an
|
|
1359
|
+
* extra `infer X` expression. There may be a better way to work around this
|
|
1360
|
+
* problem, but since it's not a problem in newer versions of TypeScript,
|
|
1361
|
+
* it's not a priority right now.
|
|
1362
|
+
*/
|
|
1363
|
+
type Tuplify<Union> = Union extends infer X ? [X] : never;
|
|
1364
|
+
/**
|
|
1365
|
+
* For older versions of TypeScript, we need two separate workarounds
|
|
1366
|
+
* to get overload info. First, we need need to use
|
|
1367
|
+
* {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
|
|
1368
|
+
* functions with 1-10 overloads. Then, we need to filter out the
|
|
1369
|
+
* "useless" overloads that are present in older versions of TypeScript,
|
|
1370
|
+
* for parameterless functions. To do this we use
|
|
1371
|
+
* {@linkcode IsUselessOverloadInfo} to remove useless overloads.
|
|
1372
|
+
*
|
|
1373
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
|
1374
|
+
*/
|
|
1375
|
+
type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup ? Tup extends [infer Fn] ? IsUselessOverloadInfo<Fn> extends true ? never : Fn : never : never;
|
|
1376
|
+
/**
|
|
1377
|
+
* For versions of TypeScript below 5.3, we need to check for 10 overloads,
|
|
1378
|
+
* then 9, then 8, etc., to get a union of the overload variants.
|
|
1379
|
+
*/
|
|
1380
|
+
type DecreasingOverloadsInfoUnion<F> = F extends {
|
|
1381
|
+
(...args: infer A1): infer R1;
|
|
1382
|
+
(...args: infer A2): infer R2;
|
|
1383
|
+
(...args: infer A3): infer R3;
|
|
1384
|
+
(...args: infer A4): infer R4;
|
|
1385
|
+
(...args: infer A5): infer R5;
|
|
1386
|
+
(...args: infer A6): infer R6;
|
|
1387
|
+
(...args: infer A7): infer R7;
|
|
1388
|
+
(...args: infer A8): infer R8;
|
|
1389
|
+
(...args: infer A9): infer R9;
|
|
1390
|
+
(...args: infer A10): infer R10;
|
|
1391
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : F extends {
|
|
1392
|
+
(...args: infer A1): infer R1;
|
|
1393
|
+
(...args: infer A2): infer R2;
|
|
1394
|
+
(...args: infer A3): infer R3;
|
|
1395
|
+
(...args: infer A4): infer R4;
|
|
1396
|
+
(...args: infer A5): infer R5;
|
|
1397
|
+
(...args: infer A6): infer R6;
|
|
1398
|
+
(...args: infer A7): infer R7;
|
|
1399
|
+
(...args: infer A8): infer R8;
|
|
1400
|
+
(...args: infer A9): infer R9;
|
|
1401
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) : F extends {
|
|
1402
|
+
(...args: infer A1): infer R1;
|
|
1403
|
+
(...args: infer A2): infer R2;
|
|
1404
|
+
(...args: infer A3): infer R3;
|
|
1405
|
+
(...args: infer A4): infer R4;
|
|
1406
|
+
(...args: infer A5): infer R5;
|
|
1407
|
+
(...args: infer A6): infer R6;
|
|
1408
|
+
(...args: infer A7): infer R7;
|
|
1409
|
+
(...args: infer A8): infer R8;
|
|
1410
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) : F extends {
|
|
1411
|
+
(...args: infer A1): infer R1;
|
|
1412
|
+
(...args: infer A2): infer R2;
|
|
1413
|
+
(...args: infer A3): infer R3;
|
|
1414
|
+
(...args: infer A4): infer R4;
|
|
1415
|
+
(...args: infer A5): infer R5;
|
|
1416
|
+
(...args: infer A6): infer R6;
|
|
1417
|
+
(...args: infer A7): infer R7;
|
|
1418
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
|
|
1419
|
+
(...args: infer A1): infer R1;
|
|
1420
|
+
(...args: infer A2): infer R2;
|
|
1421
|
+
(...args: infer A3): infer R3;
|
|
1422
|
+
(...args: infer A4): infer R4;
|
|
1423
|
+
(...args: infer A5): infer R5;
|
|
1424
|
+
(...args: infer A6): infer R6;
|
|
1425
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
|
|
1426
|
+
(...args: infer A1): infer R1;
|
|
1427
|
+
(...args: infer A2): infer R2;
|
|
1428
|
+
(...args: infer A3): infer R3;
|
|
1429
|
+
(...args: infer A4): infer R4;
|
|
1430
|
+
(...args: infer A5): infer R5;
|
|
1431
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
|
|
1432
|
+
(...args: infer A1): infer R1;
|
|
1433
|
+
(...args: infer A2): infer R2;
|
|
1434
|
+
(...args: infer A3): infer R3;
|
|
1435
|
+
(...args: infer A4): infer R4;
|
|
1436
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
|
|
1437
|
+
(...args: infer A1): infer R1;
|
|
1438
|
+
(...args: infer A2): infer R2;
|
|
1439
|
+
(...args: infer A3): infer R3;
|
|
1440
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
|
|
1441
|
+
(...args: infer A1): infer R1;
|
|
1442
|
+
(...args: infer A2): infer R2;
|
|
1443
|
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends ((...args: infer A1) => infer R1) ? ((...p: A1) => R1) : never;
|
|
1444
|
+
/**
|
|
1445
|
+
* Get a union of overload variants for a function {@linkcode FunctionType}.
|
|
1446
|
+
* Does a check for whether we can do the one-shot
|
|
1447
|
+
* 10-overload matcher (which works for ts\>5.3), and if not,
|
|
1448
|
+
* falls back to the more complicated utility.
|
|
1449
|
+
*/
|
|
1450
|
+
type OverloadsInfoUnion<FunctionType> = IsNever$2<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
|
|
1451
|
+
/**
|
|
1452
|
+
* Allows inferring any function using the `infer` keyword.
|
|
1453
|
+
*/
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* The simple(ish) way to get overload info from a constructor
|
|
1457
|
+
* {@linkcode ConstructorType}. Recent versions of TypeScript will match any
|
|
1458
|
+
* constructor against a generic 10-overload type, filling in slots with
|
|
1459
|
+
* duplicates of the constructor. So, we can just match against a single type
|
|
1460
|
+
* and get all the overloads.
|
|
1461
|
+
*
|
|
1462
|
+
* For older versions of TypeScript,
|
|
1463
|
+
* we'll need to painstakingly do ten separate matches.
|
|
1464
|
+
*/
|
|
1465
|
+
type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
|
1466
|
+
new (...args: infer A1): infer R1;
|
|
1467
|
+
new (...args: infer A2): infer R2;
|
|
1468
|
+
new (...args: infer A3): infer R3;
|
|
1469
|
+
new (...args: infer A4): infer R4;
|
|
1470
|
+
new (...args: infer A5): infer R5;
|
|
1471
|
+
new (...args: infer A6): infer R6;
|
|
1472
|
+
new (...args: infer A7): infer R7;
|
|
1473
|
+
new (...args: infer A8): infer R8;
|
|
1474
|
+
new (...args: infer A9): infer R9;
|
|
1475
|
+
new (...args: infer A10): infer R10;
|
|
1476
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : never;
|
|
1477
|
+
/**
|
|
1478
|
+
* A constructor function with `unknown` parameters and return type.
|
|
1479
|
+
*/
|
|
1480
|
+
type UnknownConstructor = new (...args: unknown[]) => unknown;
|
|
1481
|
+
/**
|
|
1482
|
+
* Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
|
|
1483
|
+
*/
|
|
1484
|
+
type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownConstructor>;
|
|
1485
|
+
/**
|
|
1486
|
+
* For older versions of TypeScript, we need two separate workarounds to
|
|
1487
|
+
* get constructor overload info. First, we need need to use
|
|
1488
|
+
* {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
|
|
1489
|
+
* info for constructors with 1-10 overloads. Then, we need to filter out the
|
|
1490
|
+
* "useless" overloads that are present in older versions of TypeScript,
|
|
1491
|
+
* for parameterless constructors. To do this we use
|
|
1492
|
+
* {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
|
|
1493
|
+
*
|
|
1494
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
|
1495
|
+
*/
|
|
1496
|
+
type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup ? Tup extends [infer Ctor] ? IsUselessConstructorOverloadInfo<Ctor> extends true ? never : Ctor : never : never;
|
|
1497
|
+
/**
|
|
1498
|
+
* For versions of TypeScript below 5.3, we need to check for 10 overloads,
|
|
1499
|
+
* then 9, then 8, etc., to get a union of the overload variants.
|
|
1500
|
+
*/
|
|
1501
|
+
type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
|
1502
|
+
new (...args: infer A1): infer R1;
|
|
1503
|
+
new (...args: infer A2): infer R2;
|
|
1504
|
+
new (...args: infer A3): infer R3;
|
|
1505
|
+
new (...args: infer A4): infer R4;
|
|
1506
|
+
new (...args: infer A5): infer R5;
|
|
1507
|
+
new (...args: infer A6): infer R6;
|
|
1508
|
+
new (...args: infer A7): infer R7;
|
|
1509
|
+
new (...args: infer A8): infer R8;
|
|
1510
|
+
new (...args: infer A9): infer R9;
|
|
1511
|
+
new (...args: infer A10): infer R10;
|
|
1512
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : ConstructorType extends {
|
|
1513
|
+
new (...args: infer A1): infer R1;
|
|
1514
|
+
new (...args: infer A2): infer R2;
|
|
1515
|
+
new (...args: infer A3): infer R3;
|
|
1516
|
+
new (...args: infer A4): infer R4;
|
|
1517
|
+
new (...args: infer A5): infer R5;
|
|
1518
|
+
new (...args: infer A6): infer R6;
|
|
1519
|
+
new (...args: infer A7): infer R7;
|
|
1520
|
+
new (...args: infer A8): infer R8;
|
|
1521
|
+
new (...args: infer A9): infer R9;
|
|
1522
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) : ConstructorType extends {
|
|
1523
|
+
new (...args: infer A1): infer R1;
|
|
1524
|
+
new (...args: infer A2): infer R2;
|
|
1525
|
+
new (...args: infer A3): infer R3;
|
|
1526
|
+
new (...args: infer A4): infer R4;
|
|
1527
|
+
new (...args: infer A5): infer R5;
|
|
1528
|
+
new (...args: infer A6): infer R6;
|
|
1529
|
+
new (...args: infer A7): infer R7;
|
|
1530
|
+
new (...args: infer A8): infer R8;
|
|
1531
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) : ConstructorType extends {
|
|
1532
|
+
new (...args: infer A1): infer R1;
|
|
1533
|
+
new (...args: infer A2): infer R2;
|
|
1534
|
+
new (...args: infer A3): infer R3;
|
|
1535
|
+
new (...args: infer A4): infer R4;
|
|
1536
|
+
new (...args: infer A5): infer R5;
|
|
1537
|
+
new (...args: infer A6): infer R6;
|
|
1538
|
+
new (...args: infer A7): infer R7;
|
|
1539
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) : ConstructorType extends {
|
|
1540
|
+
new (...args: infer A1): infer R1;
|
|
1541
|
+
new (...args: infer A2): infer R2;
|
|
1542
|
+
new (...args: infer A3): infer R3;
|
|
1543
|
+
new (...args: infer A4): infer R4;
|
|
1544
|
+
new (...args: infer A5): infer R5;
|
|
1545
|
+
new (...args: infer A6): infer R6;
|
|
1546
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) : ConstructorType extends {
|
|
1547
|
+
new (...args: infer A1): infer R1;
|
|
1548
|
+
new (...args: infer A2): infer R2;
|
|
1549
|
+
new (...args: infer A3): infer R3;
|
|
1550
|
+
new (...args: infer A4): infer R4;
|
|
1551
|
+
new (...args: infer A5): infer R5;
|
|
1552
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
|
|
1553
|
+
new (...args: infer A1): infer R1;
|
|
1554
|
+
new (...args: infer A2): infer R2;
|
|
1555
|
+
new (...args: infer A3): infer R3;
|
|
1556
|
+
new (...args: infer A4): infer R4;
|
|
1557
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
|
|
1558
|
+
new (...args: infer A1): infer R1;
|
|
1559
|
+
new (...args: infer A2): infer R2;
|
|
1560
|
+
new (...args: infer A3): infer R3;
|
|
1561
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
|
|
1562
|
+
new (...args: infer A1): infer R1;
|
|
1563
|
+
new (...args: infer A2): infer R2;
|
|
1564
|
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends (new (...args: infer A1) => infer R1) ? (new (...p: A1) => R1) : never;
|
|
1565
|
+
/**
|
|
1566
|
+
* Get a union of overload variants for a constructor
|
|
1567
|
+
* {@linkcode ConstructorType}. Does a check for whether we can do the
|
|
1568
|
+
* one-shot 10-overload matcher (which works for ts\>5.3), and if not,
|
|
1569
|
+
* falls back to the more complicated utility.
|
|
1570
|
+
*/
|
|
1571
|
+
type ConstructorOverloadsUnion<ConstructorType> = IsNever$2<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType> : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
|
|
1572
|
+
/**
|
|
1573
|
+
* Allows inferring any constructor using the `infer` keyword.
|
|
1574
|
+
*/
|
|
1575
|
+
type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
|
|
1576
|
+
/**
|
|
1577
|
+
* A union type of the parameters allowed for any overload
|
|
1578
|
+
* of constructor {@linkcode ConstructorType}.
|
|
1579
|
+
*/
|
|
1580
|
+
type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
|
|
1581
|
+
/**
|
|
1582
|
+
* Calculates the number of overloads for a given function type.
|
|
1583
|
+
*/
|
|
1584
|
+
type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>['length'];
|
|
1585
|
+
|
|
1586
|
+
//#endregion
|
|
1587
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/branding.d.ts
|
|
1588
|
+
/**
|
|
1589
|
+
* Represents a deeply branded type.
|
|
1590
|
+
*
|
|
1591
|
+
* Recursively walk a type and replace it with a branded type related to the
|
|
1592
|
+
* original. This is useful for equality-checking stricter than
|
|
1593
|
+
* `A extends B ? B extends A ? true : false : false`, because it detects the
|
|
1594
|
+
* difference between a few edge-case types that vanilla TypeScript
|
|
1595
|
+
* doesn't by default:
|
|
1596
|
+
* - `any` vs `unknown`
|
|
1597
|
+
* - `{ readonly a: string }` vs `{ a: string }`
|
|
1598
|
+
* - `{ a?: string }` vs `{ a: string | undefined }`
|
|
1599
|
+
*
|
|
1600
|
+
* __Note__: not very performant for complex types - this should only be used
|
|
1601
|
+
* when you know you need it. If doing an equality check, it's almost always
|
|
1602
|
+
* better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
|
|
1603
|
+
*/
|
|
1604
|
+
type DeepBrand<T> = IsNever$2<T> extends true ? {
|
|
1605
|
+
type: 'never';
|
|
1606
|
+
} : IsAny$2<T> extends true ? {
|
|
1607
|
+
type: 'any';
|
|
1608
|
+
} : IsUnknown<T> extends true ? {
|
|
1609
|
+
type: 'unknown';
|
|
1610
|
+
} : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
|
|
1611
|
+
type: 'primitive';
|
|
1612
|
+
value: T;
|
|
1613
|
+
} : T extends (new (...args: any[]) => any) ? {
|
|
1614
|
+
type: 'constructor';
|
|
1615
|
+
params: ConstructorOverloadParameters<T>;
|
|
1616
|
+
instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
|
|
1617
|
+
} : T extends ((...args: infer P) => infer R) ? NumOverloads<T> extends 1 ? {
|
|
1618
|
+
type: 'function';
|
|
1619
|
+
params: DeepBrand<P>;
|
|
1620
|
+
return: DeepBrand<R>;
|
|
1621
|
+
this: DeepBrand<ThisParameterType<T>>;
|
|
1622
|
+
props: DeepBrand<Omit<T, keyof Function>>;
|
|
1623
|
+
} : UnionToTuple<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
|
|
1624
|
+
type: 'overloads';
|
|
1625
|
+
overloads: { [K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]> };
|
|
1626
|
+
} : never : T extends any[] ? {
|
|
1627
|
+
type: 'array';
|
|
1628
|
+
items: { [K in keyof T]: T[K] };
|
|
1629
|
+
} : {
|
|
1630
|
+
type: 'object';
|
|
1631
|
+
properties: { [K in keyof T]: DeepBrand<T[K]> };
|
|
1632
|
+
readonly: ReadonlyKeys<T>;
|
|
1633
|
+
required: RequiredKeys<T>;
|
|
1634
|
+
optional: OptionalKeys<T>;
|
|
1635
|
+
constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
|
|
1636
|
+
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Checks if two types are strictly equal using branding.
|
|
1639
|
+
*/
|
|
1640
|
+
type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
|
|
1641
|
+
|
|
1642
|
+
//#endregion
|
|
1643
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.1/node_modules/expect-type/dist/messages.d.ts
|
|
1644
|
+
/**
|
|
1645
|
+
* Determines the printable type representation for a given type.
|
|
1646
|
+
*/
|
|
1647
|
+
type PrintType<T> = IsUnknown<T> extends true ? 'unknown' : IsNever$2<T> extends true ? 'never' : IsAny$2<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : bigint extends T ? 'bigint' : T extends bigint ? `literal bigint: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends ((...args: any[]) => any) ? 'function' : '...';
|
|
1648
|
+
/**
|
|
1649
|
+
* Helper for showing end-user a hint why their type assertion is failing.
|
|
1650
|
+
* This swaps "leaf" types with a literal message about what the actual and
|
|
1651
|
+
* expected types are. Needs to check for `Not<IsAny<Actual>>` because
|
|
1652
|
+
* otherwise `LeafTypeOf<Actual>` returns `never`, which extends everything 🤔
|
|
1653
|
+
*/
|
|
1654
|
+
type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny$2<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : { [K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never> } : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
|
|
1655
|
+
|
|
1656
|
+
//#endregion
|
|
1657
|
+
//#region src/types/core/variants.types.d.ts
|
|
1658
|
+
/**
|
|
1659
|
+
* @internal
|
|
1660
|
+
*/
|
|
1661
|
+
|
|
1662
|
+
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'> & {
|
|
1663
|
+
$fields: ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>];
|
|
1664
|
+
} : RegleStatus<TState, TRules, TShortcuts>;
|
|
1665
|
+
type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple$1<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple$1<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple$1<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple$1<TState>[TIndexInt] : never, UnionToTuple$1<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
1666
|
+
type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region src/core/useRegle/useRegle.d.ts
|
|
1669
|
+
type useRegleFnOptions<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? TRules : {}, TValidationGroups> & TAdditionalOptions;
|
|
1670
|
+
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1671
|
+
<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = (isDeepExact<NoInferLegacy<TRules>, Unwrap<TState extends Record<string, any> ? TState : {}>> extends true ? {} : MismatchInfo<RegleRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>, NoInferLegacy<TRules>>)>(...params: [state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRef<TRules> | ((...args: any[]) => TRules) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
1672
|
+
__config?: {
|
|
1673
|
+
rules?: () => CustomRulesDeclarationTree;
|
|
1674
|
+
modifiers?: RegleBehaviourOptions;
|
|
1675
|
+
shortcuts?: TShortcuts;
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* useRegle serves as the foundation for validation logic.
|
|
1680
|
+
*
|
|
1681
|
+
* It accepts the following inputs:
|
|
1682
|
+
*
|
|
1683
|
+
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
1684
|
+
* @param rules - These should align with the structure of your state.
|
|
1685
|
+
* @param modifiers - Customize regle behaviour
|
|
1686
|
+
*
|
|
1687
|
+
* ```ts
|
|
1688
|
+
* import { useRegle } from '@regle/core';
|
|
1689
|
+
import { required } from '@regle/rules';
|
|
1690
|
+
|
|
1691
|
+
const { r$ } = useRegle({ email: '' }, {
|
|
1692
|
+
email: { required }
|
|
1693
|
+
})
|
|
1694
|
+
* ```
|
|
1695
|
+
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1696
|
+
*/
|
|
1697
|
+
|
|
1698
|
+
//#endregion
|
|
1699
|
+
//#region src/types/utils/object.types.d.ts
|
|
1700
|
+
type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
|
|
1701
|
+
/**
|
|
1702
|
+
* Restore the optional properties (with ?) of a generated mapped object type
|
|
1703
|
+
*/
|
|
1704
|
+
|
|
1705
|
+
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
1706
|
+
/**
|
|
1707
|
+
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
1708
|
+
*/
|
|
1709
|
+
type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
|
|
1710
|
+
/**
|
|
1711
|
+
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
1712
|
+
*/
|
|
1713
|
+
type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K extends keyof O ? O[K] : undefined;
|
|
1714
|
+
/**
|
|
1715
|
+
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
1716
|
+
*/
|
|
1717
|
+
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
|
|
1718
|
+
/**
|
|
1719
|
+
* Get all possible keys from a union, even the ones present only on one union
|
|
1720
|
+
*/
|
|
1721
|
+
type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
1722
|
+
/**
|
|
1723
|
+
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
1724
|
+
*/
|
|
1725
|
+
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple$1<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple$1<TUnion>>>[number]>[number];
|
|
1726
|
+
/**
|
|
1727
|
+
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
1728
|
+
*/
|
|
1729
|
+
type JoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : TUnion;
|
|
1730
|
+
type EnumLike = {
|
|
1731
|
+
[k: string]: string | number;
|
|
1732
|
+
[nu: number]: string;
|
|
1733
|
+
};
|
|
1734
|
+
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
1735
|
+
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
1736
|
+
|
|
1737
|
+
//#endregion
|
|
1738
|
+
//#region src/types/utils/mismatch.types.d.ts
|
|
1739
|
+
type isDeepExact<TRules, TTree> = { [K in keyof TRules]-?: CheckDeepExact<NonNullable<TRules[K]>, K extends keyof JoinDiscriminatedUnions<TTree> ? NonNullable<JoinDiscriminatedUnions<TTree>[K]> : never> }[keyof TRules] extends true ? true : false;
|
|
1740
|
+
type CheckDeepExact<TRules, TTree> = [TTree] extends [never] ? false : TRules extends RegleCollectionRuleDecl ? TTree extends Array<any> ? isDeepExact<NonNullable<TRules['$each']>, JoinDiscriminatedUnions<NonNullable<ArrayElement$1<TTree>>>> : TRules extends RegleRuleDecl ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<TRules, TTree> : false : TRules extends RegleRuleDecl ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<TRules, TTree> : false;
|
|
1741
|
+
|
|
1742
|
+
//#endregion
|
|
1743
|
+
//#region src/types/utils/infer.types.d.ts
|
|
1744
|
+
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region src/types/rules/rule.params.types.d.ts
|
|
1747
|
+
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
1748
|
+
/**
|
|
1749
|
+
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
1750
|
+
*
|
|
1751
|
+
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
1752
|
+
*/
|
|
1753
|
+
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>;
|
|
1754
|
+
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>;
|
|
1755
|
+
|
|
1756
|
+
//#endregion
|
|
1757
|
+
//#region src/types/rules/rule.internal.types.d.ts
|
|
1758
|
+
/**
|
|
1759
|
+
* Internal definition of the rule, this can be used to reset or patch the rule
|
|
1760
|
+
*/
|
|
1761
|
+
type RegleInternalRuleDefs<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> = Raw<{
|
|
1762
|
+
_validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1763
|
+
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
1764
|
+
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => boolean);
|
|
1765
|
+
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
1766
|
+
_type?: string;
|
|
1767
|
+
_message_patched: boolean;
|
|
1768
|
+
_tooltip_patched: boolean;
|
|
1769
|
+
_params?: RegleUniversalParams<TParams>;
|
|
1770
|
+
_async: TAsync;
|
|
1771
|
+
readonly _brand: symbol;
|
|
1772
|
+
}>;
|
|
1773
|
+
//#endregion
|
|
1774
|
+
//#region src/types/rules/rule.definition.type.d.ts
|
|
1775
|
+
type IsLiteral<T> = string extends T ? false : true;
|
|
1776
|
+
/**
|
|
1777
|
+
* Returned typed of rules created with `createRule`
|
|
1778
|
+
* */
|
|
1779
|
+
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> {
|
|
1780
|
+
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
|
|
1781
|
+
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1782
|
+
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
1783
|
+
tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1784
|
+
type?: string;
|
|
1785
|
+
_value?: IsLiteral<TValue> extends true ? TValue : any;
|
|
1786
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* @internal
|
|
1790
|
+
* */
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Rules with params created with `createRules` are callable while being customizable
|
|
1794
|
+
*/
|
|
1795
|
+
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> & {
|
|
1796
|
+
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TFilteredValue, TParams, TAsync, TMetadata, TInput>;
|
|
1797
|
+
} & (TParams extends [param?: any, ...any[]] ? {
|
|
1798
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1799
|
+
} : {});
|
|
1800
|
+
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[]] ? {
|
|
1801
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1802
|
+
} : {});
|
|
1803
|
+
type RegleRuleMetadataExtended = {
|
|
1804
|
+
$valid: boolean;
|
|
1805
|
+
[x: string]: any;
|
|
1806
|
+
};
|
|
1807
|
+
/**
|
|
1808
|
+
* Define a rule Metadata definition
|
|
1809
|
+
*/
|
|
1810
|
+
type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
|
|
1811
|
+
type DefaultMetadataPropertiesCommon = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid' | '$dirty' | '$pending' | '$correct' | '$error'>;
|
|
1812
|
+
type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
1813
|
+
$rule: Pick<$InternalRegleRuleStatus, '$valid' | '$pending'>;
|
|
1814
|
+
};
|
|
1815
|
+
/**
|
|
1816
|
+
* Will be used to consume metadata on related helpers and rule status
|
|
1817
|
+
*/
|
|
1818
|
+
type RegleRuleMetadataConsumer<TValue extends any, TParams extends [...any[]] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
1819
|
+
$value: Maybe<TValue>;
|
|
1820
|
+
} & DefaultMetadataProperties & (TParams extends never ? {} : {
|
|
1821
|
+
$params: [...TParams];
|
|
1822
|
+
}) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
|
|
1823
|
+
/**
|
|
1824
|
+
* Will be used to consume metadata on related helpers and rule status
|
|
1825
|
+
*/
|
|
1826
|
+
type PossibleRegleRuleMetadataConsumer<TValue> = {
|
|
1827
|
+
$value: Maybe<TValue>;
|
|
1828
|
+
} & DefaultMetadataProperties & {
|
|
1829
|
+
$params?: [...any[]];
|
|
1830
|
+
};
|
|
1831
|
+
/**
|
|
1832
|
+
* @internal
|
|
1833
|
+
*/
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Generic types for a created RegleRule
|
|
1837
|
+
*/
|
|
1838
|
+
|
|
1839
|
+
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'> & {
|
|
1840
|
+
message: any;
|
|
1841
|
+
active?: any;
|
|
1842
|
+
tooltip?: any;
|
|
1843
|
+
};
|
|
1844
|
+
/**
|
|
1845
|
+
* Process the type of created rule with `createRule`.
|
|
1846
|
+
* For a rule with params it will return a function
|
|
1847
|
+
* Otherwise it will return the rule definition
|
|
1848
|
+
*/
|
|
1849
|
+
|
|
1850
|
+
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
1851
|
+
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
1852
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement$1<NonNullable<TValue>>, TCustomRules>, ArrayElement$1<TValue>>;
|
|
1853
|
+
}) | ({
|
|
1854
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement$1<NonNullable<TValue>>, TCustomRules>, ArrayElement$1<TValue>>;
|
|
1855
|
+
} & CollectionRegleBehaviourOptions);
|
|
1856
|
+
|
|
1857
|
+
//#endregion
|
|
1858
|
+
//#region src/types/rules/rule.init.types.d.ts
|
|
1859
|
+
type RegleInitPropertyGetter<TValue, TReturn, TParams extends [...any[]], TMetadata extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue, TParams, TMetadata>) => TReturn);
|
|
1860
|
+
/**
|
|
1861
|
+
* @argument
|
|
1862
|
+
* createRule arguments options
|
|
1863
|
+
*/
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* @argument
|
|
1867
|
+
* Rule core
|
|
1868
|
+
*/
|
|
1869
|
+
interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
|
|
1870
|
+
validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1871
|
+
message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1872
|
+
active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1873
|
+
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1874
|
+
type?: string;
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* @internal
|
|
1878
|
+
* createRule arguments options
|
|
1879
|
+
*/
|
|
1880
|
+
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region src/core/defaultValidators.d.ts
|
|
1883
|
+
interface CommonComparisonOptions {
|
|
1884
|
+
/**
|
|
1885
|
+
* Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
|
|
1886
|
+
* @default true
|
|
1887
|
+
*/
|
|
1888
|
+
allowEqual?: boolean;
|
|
1889
|
+
}
|
|
1890
|
+
interface CommonAlphaOptions {
|
|
1891
|
+
/**
|
|
1892
|
+
* Allow symbols in alphabetical-like rules (like "_")
|
|
1893
|
+
* @default true
|
|
1894
|
+
*/
|
|
1895
|
+
allowSymbols?: boolean;
|
|
1896
|
+
}
|
|
1897
|
+
type DefaultValidators = {
|
|
1898
|
+
alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined]>;
|
|
1899
|
+
alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined]>;
|
|
1900
|
+
between: RegleRuleWithParamsDefinition<number, [min: Maybe<number>, max: Maybe<number>]>;
|
|
1901
|
+
boolean: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1902
|
+
checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
|
|
1903
|
+
contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1904
|
+
date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
1905
|
+
dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1906
|
+
$valid: false;
|
|
1907
|
+
error: 'date-not-after';
|
|
1908
|
+
} | {
|
|
1909
|
+
$valid: false;
|
|
1910
|
+
error: 'value-or-parameter-not-a-date';
|
|
1911
|
+
}>;
|
|
1912
|
+
dateBefore: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, options?: CommonComparisonOptions], false, true | {
|
|
1913
|
+
$valid: false;
|
|
1914
|
+
error: 'date-not-before';
|
|
1915
|
+
} | {
|
|
1916
|
+
$valid: false;
|
|
1917
|
+
error: 'value-or-parameter-not-a-date';
|
|
1918
|
+
}>;
|
|
1919
|
+
dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: Maybe<string | Date>, after: Maybe<string | Date>, options?: CommonComparisonOptions], false, boolean>;
|
|
1920
|
+
decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1921
|
+
email: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1922
|
+
endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1923
|
+
exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
|
|
1924
|
+
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
1925
|
+
hexadecimal: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1926
|
+
integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1927
|
+
ipv4Address: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1928
|
+
literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
|
|
1929
|
+
macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
|
|
1930
|
+
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1931
|
+
maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1932
|
+
minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1933
|
+
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
1934
|
+
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
1935
|
+
number: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1936
|
+
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1937
|
+
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
1938
|
+
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
1939
|
+
required: RegleRuleDefinition<unknown, []>;
|
|
1940
|
+
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
1941
|
+
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
1942
|
+
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
1943
|
+
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1944
|
+
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
//#endregion
|
|
1948
|
+
//#region src/types/rules/rule.custom.types.d.ts
|
|
1949
|
+
type CustomRulesDeclarationTree = {
|
|
1950
|
+
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
1951
|
+
};
|
|
1952
|
+
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
1953
|
+
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
1954
|
+
|
|
1955
|
+
//#endregion
|
|
1956
|
+
//#region src/types/rules/rule.declaration.types.d.ts
|
|
1957
|
+
/**
|
|
1958
|
+
* @public
|
|
1959
|
+
*/
|
|
1960
|
+
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
1961
|
+
/**
|
|
1962
|
+
* @public
|
|
1963
|
+
*/
|
|
1964
|
+
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
1965
|
+
/**
|
|
1966
|
+
* @public
|
|
1967
|
+
*/
|
|
1968
|
+
|
|
1969
|
+
/**
|
|
1970
|
+
* @public
|
|
1971
|
+
*/
|
|
1972
|
+
type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends File ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? ReglePartialRuleTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
|
|
1973
|
+
/**
|
|
1974
|
+
* @internal
|
|
1975
|
+
* @reference {@link RegleFormPropertyType}
|
|
1976
|
+
*/
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* @public
|
|
1980
|
+
* Rule tree for a form property
|
|
1981
|
+
*/
|
|
1982
|
+
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] };
|
|
1983
|
+
/**
|
|
1984
|
+
* @internal
|
|
1985
|
+
* @reference {@link RegleRuleDecl}
|
|
1986
|
+
*/
|
|
1987
|
+
|
|
1988
|
+
/**
|
|
1989
|
+
* @public
|
|
1990
|
+
*/
|
|
1991
|
+
type RegleCollectionRuleDeclKeyProperty = {
|
|
1992
|
+
$key?: PropertyKey;
|
|
1993
|
+
};
|
|
1994
|
+
/**
|
|
1995
|
+
* @public
|
|
1996
|
+
*/
|
|
1997
|
+
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = ({
|
|
1998
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
1999
|
+
} & RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
2000
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
2001
|
+
} & CollectionRegleBehaviourOptions);
|
|
2002
|
+
/** @public */
|
|
2003
|
+
type RegleCollectionEachRules<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement$1<NonNullable<TValue>>, TCustomRules>, ArrayElement$1<TValue>, RegleCollectionRuleDeclKeyProperty>;
|
|
2004
|
+
/**
|
|
2005
|
+
* @internal
|
|
2006
|
+
* @reference {@link RegleCollectionRuleDecl}
|
|
2007
|
+
*/
|
|
2008
|
+
|
|
2009
|
+
/**
|
|
2010
|
+
* @public
|
|
2011
|
+
*/
|
|
2012
|
+
type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
|
|
2013
|
+
/**
|
|
2014
|
+
* @internal
|
|
2015
|
+
*/
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* @public
|
|
2019
|
+
* Regroup inline and registered rules
|
|
2020
|
+
* */
|
|
2021
|
+
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>;
|
|
2022
|
+
|
|
2023
|
+
//#endregion
|
|
2024
|
+
//#region src/types/rules/rule.errors.types.d.ts
|
|
2025
|
+
type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false> };
|
|
2026
|
+
type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true> };
|
|
2027
|
+
type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U> : RegleExternalCollectionErrors<U> : string[] : NonNullable<TState> extends Date | File ? string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState> : RegleExternalErrorTree<TState> : string[];
|
|
2028
|
+
type RegleCollectionErrors<TState extends Record<string, any>> = {
|
|
2029
|
+
readonly $self: string[];
|
|
2030
|
+
readonly $each: RegleValidationErrors<TState, false>[];
|
|
2031
|
+
};
|
|
2032
|
+
type RegleExternalCollectionErrors<TState extends Record<string, any>> = {
|
|
2033
|
+
readonly $self?: string[];
|
|
2034
|
+
readonly $each?: RegleValidationErrors<TState, true>[];
|
|
2035
|
+
};
|
|
2036
|
+
/** @internal */
|
|
2037
|
+
|
|
2038
|
+
//#endregion
|
|
2039
|
+
//#region src/types/rules/rule.status.types.d.ts
|
|
2040
|
+
/**
|
|
2041
|
+
* @public
|
|
2042
|
+
*/
|
|
2043
|
+
type RegleRoot<TState extends Record<string, any> = {}, TRules extends ReglePartialRuleTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> = MaybeVariantStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
2044
|
+
/**
|
|
2045
|
+
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
2046
|
+
*/
|
|
2047
|
+
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
2048
|
+
});
|
|
2049
|
+
/**
|
|
2050
|
+
* @public
|
|
2051
|
+
*/
|
|
2052
|
+
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
2053
|
+
/** 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. */
|
|
2054
|
+
readonly $fields: { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject<TRules[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> };
|
|
2055
|
+
/**
|
|
2056
|
+
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
2057
|
+
*
|
|
2058
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2059
|
+
readonly $errors: RegleErrorTree<TState>;
|
|
2060
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
2061
|
+
readonly $silentErrors: RegleErrorTree<TState>;
|
|
2062
|
+
/** 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). */
|
|
2063
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
|
|
2064
|
+
/** 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). */
|
|
2065
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
|
|
2066
|
+
} & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
2067
|
+
/**
|
|
2068
|
+
* @internal
|
|
2069
|
+
* @reference {@link RegleStatus}
|
|
2070
|
+
*/
|
|
2071
|
+
|
|
2072
|
+
/**
|
|
2073
|
+
* @public
|
|
2074
|
+
*/
|
|
2075
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = [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>;
|
|
2076
|
+
/**
|
|
2077
|
+
* @internal
|
|
2078
|
+
* @reference {@link InferRegleStatusType}
|
|
2079
|
+
*/
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* @public
|
|
2083
|
+
*/
|
|
2084
|
+
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value' | '$silentValue'> & {
|
|
2085
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2086
|
+
$value: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2087
|
+
/** $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. */
|
|
2088
|
+
$silentValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2089
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2090
|
+
*
|
|
2091
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2092
|
+
readonly $errors: string[];
|
|
2093
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2094
|
+
readonly $silentErrors: string[];
|
|
2095
|
+
/** Stores external errors of the current field */
|
|
2096
|
+
readonly $externalErrors: string[];
|
|
2097
|
+
/** Stores active tooltips messages of the current field */
|
|
2098
|
+
readonly $tooltips: string[];
|
|
2099
|
+
/** Represents the inactive status. Is true when this state have empty rules */
|
|
2100
|
+
readonly $inactive: boolean;
|
|
2101
|
+
/** 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). */
|
|
2102
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
|
|
2103
|
+
/** 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). */
|
|
2104
|
+
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
2105
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
2106
|
+
readonly $rules: IsEmptyObject<TRules> extends true ? {
|
|
2107
|
+
readonly [x: string]: RegleRuleStatus<TState, any[], any>;
|
|
2108
|
+
} : { readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : any> };
|
|
2109
|
+
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
2110
|
+
/**
|
|
2111
|
+
* @internal
|
|
2112
|
+
* @reference {@link RegleFieldStatus}
|
|
2113
|
+
*/
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* @public
|
|
2117
|
+
*/
|
|
2118
|
+
interface RegleCommonStatus<TValue = any> {
|
|
2119
|
+
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
2120
|
+
readonly $invalid: boolean;
|
|
2121
|
+
/**
|
|
2122
|
+
* This is not the opposite of `$invalid`. Correct is meant to display UI validation report.
|
|
2123
|
+
*
|
|
2124
|
+
* This will be `true` only if:
|
|
2125
|
+
* - The field have at least one active rule
|
|
2126
|
+
* - Is dirty and not empty
|
|
2127
|
+
* - Passes validation
|
|
2128
|
+
*/
|
|
2129
|
+
readonly $correct: boolean;
|
|
2130
|
+
/** 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.*/
|
|
2131
|
+
readonly $dirty: boolean;
|
|
2132
|
+
/** 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. */
|
|
2133
|
+
readonly $anyDirty: boolean;
|
|
2134
|
+
/** Indicates whether a field has been touched and if the value is different than the initial one.
|
|
2135
|
+
* On nested elements and collections, it's true only if all its children are also `$edited`.
|
|
2136
|
+
* Use `$anyEdited` to check for any edited children
|
|
2137
|
+
*/
|
|
2138
|
+
readonly $edited: boolean;
|
|
2139
|
+
/** 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. */
|
|
2140
|
+
readonly $anyEdited: boolean;
|
|
2141
|
+
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
2142
|
+
readonly $pending: boolean;
|
|
2143
|
+
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
2144
|
+
readonly $error: boolean;
|
|
2145
|
+
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
2146
|
+
readonly $ready: boolean;
|
|
2147
|
+
/** Return the current key name of the field. */
|
|
2148
|
+
readonly $name: string;
|
|
2149
|
+
/** Id used to track collections items */
|
|
2150
|
+
$id?: string;
|
|
2151
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2152
|
+
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
2153
|
+
/** $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. */
|
|
2154
|
+
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
2155
|
+
/** Marks the field and all nested properties as $dirty. */
|
|
2156
|
+
$touch(): void;
|
|
2157
|
+
/**
|
|
2158
|
+
* Reset the validation status to a pristine state while keeping the current form state.
|
|
2159
|
+
* Resets the `$dirty` state on all nested properties of a form.
|
|
2160
|
+
* Rerun rules if `$lazy` is false
|
|
2161
|
+
*/
|
|
2162
|
+
$reset(): void;
|
|
2163
|
+
$reset(options?: ResetOptions<TValue>): void;
|
|
2164
|
+
/** Clears the $externalErrors state back to an empty object. */
|
|
2165
|
+
$clearExternalErrors(): void;
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* @public
|
|
2169
|
+
*/
|
|
2170
|
+
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
2171
|
+
/** The name of the rule type. */
|
|
2172
|
+
readonly $type: string;
|
|
2173
|
+
/** Returns the computed error message or messages for the current rule. */
|
|
2174
|
+
readonly $message: string | string[];
|
|
2175
|
+
/** Stores the current rule tooltip or tooltips */
|
|
2176
|
+
readonly $tooltip: string | string[];
|
|
2177
|
+
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
2178
|
+
readonly $active: boolean;
|
|
2179
|
+
/** Indicates the state of validation for this validator. */
|
|
2180
|
+
readonly $valid: boolean;
|
|
2181
|
+
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
2182
|
+
readonly $pending: boolean;
|
|
2183
|
+
/** Returns the current path of the rule (used internally for tracking) */
|
|
2184
|
+
readonly $path: string;
|
|
2185
|
+
/** Contains the metadata returned by the validator function. */
|
|
2186
|
+
readonly $metadata: TMetadata extends boolean ? TMetadata : Omit<TMetadata, '$valid'>;
|
|
2187
|
+
/** Run the rule validator and compute its properties like $message and $active */
|
|
2188
|
+
$parse(): Promise<boolean>;
|
|
2189
|
+
/** Reset the $valid, $metadata and $pending states */
|
|
2190
|
+
$reset(): void;
|
|
2191
|
+
/** Returns the original rule validator function. */
|
|
2192
|
+
$validator: ((value: IsUnknown$1<TValue> extends true ? any : MaybeInput<TValue>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: IsUnknown$1<TValue> extends true ? any : TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
2193
|
+
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
2194
|
+
readonly $params?: any[];
|
|
2195
|
+
} : {
|
|
2196
|
+
readonly $params: [...TParams];
|
|
2197
|
+
});
|
|
2198
|
+
/**
|
|
2199
|
+
* @internal
|
|
2200
|
+
* @reference {@link RegleRuleStatus}
|
|
2201
|
+
*/
|
|
2202
|
+
interface $InternalRegleRuleStatus {
|
|
2203
|
+
$type: string;
|
|
2204
|
+
$message: string | string[];
|
|
2205
|
+
$tooltip: string | string[];
|
|
2206
|
+
$active: boolean;
|
|
2207
|
+
$valid: boolean;
|
|
2208
|
+
$pending: boolean;
|
|
2209
|
+
$path: string;
|
|
2210
|
+
$externalErrors?: string[];
|
|
2211
|
+
$params?: any[];
|
|
2212
|
+
$metadata: any;
|
|
2213
|
+
$haveAsync: boolean;
|
|
2214
|
+
$validating: boolean;
|
|
2215
|
+
$fieldDirty: boolean;
|
|
2216
|
+
$fieldInvalid: boolean;
|
|
2217
|
+
$fieldPending: boolean;
|
|
2218
|
+
$fieldCorrect: boolean;
|
|
2219
|
+
$fieldError: boolean;
|
|
2220
|
+
$maybePending: boolean;
|
|
2221
|
+
$validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
|
|
2222
|
+
$parse(): Promise<boolean>;
|
|
2223
|
+
$reset(): void;
|
|
2224
|
+
$unwatch(): void;
|
|
2225
|
+
$watch(): void;
|
|
2226
|
+
}
|
|
2227
|
+
/**
|
|
2228
|
+
* @public
|
|
2229
|
+
*/
|
|
2230
|
+
type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePartialRuleTree<ArrayElement$1<TState>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$value'> & {
|
|
2231
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2232
|
+
$value: MaybeOutput<TState>;
|
|
2233
|
+
/** $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. */
|
|
2234
|
+
$silentValue: MaybeOutput<TState>;
|
|
2235
|
+
/** 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. */
|
|
2236
|
+
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
2237
|
+
/** 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. */
|
|
2238
|
+
readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
2239
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2240
|
+
*
|
|
2241
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2242
|
+
readonly $errors: RegleCollectionErrors<TState>;
|
|
2243
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2244
|
+
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
2245
|
+
/** 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). */
|
|
2246
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
|
|
2247
|
+
/** 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). */
|
|
2248
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, JoinDiscriminatedUnions<TRules>>>;
|
|
2249
|
+
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
2250
|
+
/**
|
|
2251
|
+
* @internal
|
|
2252
|
+
* @reference {@link RegleCollectionStatus}
|
|
2253
|
+
*/
|
|
2254
|
+
|
|
2255
|
+
/** Supports both core Regle and schemas Regle for Zod/Valibot */
|
|
2256
|
+
type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
|
|
2257
|
+
$groups?: {
|
|
2258
|
+
[x: string]: RegleValidationGroupOutput;
|
|
2259
|
+
};
|
|
2260
|
+
$validate: () => Promise<SuperCompatibleRegleResult>;
|
|
2261
|
+
};
|
|
2262
|
+
type SuperCompatibleRegleResult = $InternalRegleResult;
|
|
2263
|
+
interface SuperCompatibleRegleStatus extends SuperCompatibleRegleCommonStatus {
|
|
2264
|
+
$fields: {
|
|
2265
|
+
[x: string]: unknown;
|
|
2266
|
+
};
|
|
2267
|
+
readonly $errors: Record<string, RegleValidationErrors<any, false>>;
|
|
2268
|
+
readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
|
|
2269
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
|
|
2270
|
+
$validate?: () => Promise<SuperCompatibleRegleResult>;
|
|
2271
|
+
}
|
|
2272
|
+
type SuperCompatibleRegleCommonStatus = Omit<RegleCommonStatus, '$pending'> & {
|
|
2273
|
+
$pending?: boolean;
|
|
2274
|
+
};
|
|
2275
|
+
//#endregion
|
|
2276
|
+
//#region src/core/mergeRegles.d.ts
|
|
2277
|
+
type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue = { [K in keyof TRegles]: TRegles[K]['$value'] }> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch'> & {
|
|
2278
|
+
/** Map of merged Regle instances and their properties */
|
|
2279
|
+
readonly $instances: { [K in keyof TRegles]: TRegles[K] };
|
|
2280
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2281
|
+
$value: TValue;
|
|
2282
|
+
/** $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. */
|
|
2283
|
+
$silentValue: TValue;
|
|
2284
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2285
|
+
*
|
|
2286
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
2287
|
+
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2288
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
2289
|
+
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
2290
|
+
/** 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). */
|
|
2291
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue>;
|
|
2292
|
+
/** 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). */
|
|
2293
|
+
$validate: () => Promise<MergedReglesResult<TRegles>>;
|
|
2294
|
+
};
|
|
2295
|
+
type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
|
|
2296
|
+
/** Array of scoped Regles instances */
|
|
2297
|
+
readonly $instances: SuperCompatibleRegleRoot[];
|
|
2298
|
+
/** Collection of all registered Regles instances values */
|
|
2299
|
+
readonly $value: TValue;
|
|
2300
|
+
/** Collection of all registered Regles instances errors */
|
|
2301
|
+
readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2302
|
+
/** Collection of all registered Regles instances silent errors */
|
|
2303
|
+
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2304
|
+
/** 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). */
|
|
2305
|
+
$validate: () => Promise<{
|
|
2306
|
+
valid: boolean;
|
|
2307
|
+
data: TValue;
|
|
2308
|
+
}>;
|
|
2309
|
+
};
|
|
2310
|
+
type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
|
|
2311
|
+
valid: false;
|
|
2312
|
+
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2313
|
+
valid: false;
|
|
2314
|
+
}>['data'] };
|
|
2315
|
+
} | {
|
|
2316
|
+
valid: true;
|
|
2317
|
+
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2318
|
+
valid: true;
|
|
2319
|
+
}>['data'] };
|
|
2320
|
+
};
|
|
2321
|
+
//#endregion
|
|
2322
|
+
//#region src/core/createScopedUseRegle/useCollectScope.d.ts
|
|
2323
|
+
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2324
|
+
r$: MergedRegles<{ [K in keyof TValue]: RegleRoot<TValue[K]> }>;
|
|
2325
|
+
} : <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
2326
|
+
r$: MergedScopedRegles<TValue>;
|
|
2327
|
+
};
|
|
5
2328
|
|
|
2329
|
+
//#endregion
|
|
2330
|
+
//#region src/core/createScopedUseRegle/useScopedRegle.d.ts
|
|
2331
|
+
type UseScopedRegleOptions<TAsRecord extends boolean> = {
|
|
2332
|
+
namespace?: MaybeRefOrGetter<string>;
|
|
2333
|
+
} & (TAsRecord extends true ? {
|
|
2334
|
+
scopeKey: string;
|
|
2335
|
+
} : {});
|
|
2336
|
+
|
|
2337
|
+
//#endregion
|
|
2338
|
+
//#region src/core/createScopedUseRegle/createScopedUseRegle.d.ts
|
|
2339
|
+
type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsRecord extends boolean> = {
|
|
2340
|
+
/**
|
|
2341
|
+
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
2342
|
+
*/
|
|
2343
|
+
customUseRegle?: TCustomRegle;
|
|
2344
|
+
/**
|
|
2345
|
+
* Store the collected instances externally
|
|
2346
|
+
*/
|
|
2347
|
+
customStore?: Ref<ScopedInstancesRecordLike>;
|
|
2348
|
+
/**
|
|
2349
|
+
* Set the
|
|
2350
|
+
*/
|
|
2351
|
+
asRecord?: TAsRecord;
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2354
|
+
//#endregion
|
|
2355
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/primitive.d.ts
|
|
6
2356
|
/**
|
|
7
2357
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
8
2358
|
|
|
9
2359
|
@category Type
|
|
10
2360
|
*/
|
|
11
|
-
type Primitive =
|
|
12
|
-
| null
|
|
13
|
-
| undefined
|
|
14
|
-
| string
|
|
15
|
-
| number
|
|
16
|
-
| boolean
|
|
17
|
-
| symbol
|
|
18
|
-
| bigint;
|
|
2361
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
19
2362
|
|
|
2363
|
+
//#endregion
|
|
2364
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/observable-like.d.ts
|
|
20
2365
|
declare global {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2366
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
2367
|
+
interface SymbolConstructor {
|
|
2368
|
+
readonly observable: symbol;
|
|
2369
|
+
}
|
|
25
2370
|
}
|
|
26
2371
|
|
|
2372
|
+
//#endregion
|
|
2373
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/empty-object.d.ts
|
|
2374
|
+
/**
|
|
2375
|
+
@remarks
|
|
2376
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
2377
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
2378
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
2379
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
2380
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
2381
|
+
|
|
2382
|
+
@category Observable
|
|
2383
|
+
*/
|
|
27
2384
|
declare const emptyObjectSymbol: unique symbol;
|
|
28
2385
|
|
|
29
2386
|
/**
|
|
@@ -52,8 +2409,27 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
52
2409
|
|
|
53
2410
|
@category Object
|
|
54
2411
|
*/
|
|
55
|
-
type EmptyObject = {
|
|
2412
|
+
type EmptyObject = {
|
|
2413
|
+
[emptyObjectSymbol]?: never;
|
|
2414
|
+
};
|
|
2415
|
+
|
|
2416
|
+
//#endregion
|
|
2417
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
2418
|
+
/**
|
|
2419
|
+
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
2420
|
+
|
|
2421
|
+
@example
|
|
2422
|
+
```
|
|
2423
|
+
import type {IsEmptyObject} from 'type-fest';
|
|
2424
|
+
|
|
2425
|
+
type Pass = IsEmptyObject<{}>; //=> true
|
|
2426
|
+
type Fail = IsEmptyObject<[]>; //=> false
|
|
2427
|
+
type Fail = IsEmptyObject<null>; //=> false
|
|
2428
|
+
```
|
|
56
2429
|
|
|
2430
|
+
@see EmptyObject
|
|
2431
|
+
@category Object
|
|
2432
|
+
*/
|
|
57
2433
|
/**
|
|
58
2434
|
Extract all optional keys from the given type.
|
|
59
2435
|
|
|
@@ -87,13 +2463,13 @@ const update2: UpdateOperation<User> = {
|
|
|
87
2463
|
|
|
88
2464
|
@category Utilities
|
|
89
2465
|
*/
|
|
90
|
-
type OptionalKeysOf<BaseType extends object> =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
94
|
-
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
95
|
-
: never; // Should never happen
|
|
2466
|
+
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
2467
|
+
? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
2468
|
+
: never;
|
|
96
2469
|
|
|
2470
|
+
//#endregion
|
|
2471
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
2472
|
+
// Should never happen
|
|
97
2473
|
/**
|
|
98
2474
|
Extract all required keys from the given type.
|
|
99
2475
|
|
|
@@ -118,10 +2494,12 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
|
|
|
118
2494
|
|
|
119
2495
|
@category Utilities
|
|
120
2496
|
*/
|
|
121
|
-
type RequiredKeysOf<BaseType extends object> =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
2497
|
+
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
2498
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
2499
|
+
|
|
2500
|
+
//#endregion
|
|
2501
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-never.d.ts
|
|
2502
|
+
// Should never happen
|
|
125
2503
|
|
|
126
2504
|
/**
|
|
127
2505
|
Returns a boolean for whether the given type is `never`.
|
|
@@ -166,6 +2544,8 @@ endIfEqual('abc', '123');
|
|
|
166
2544
|
*/
|
|
167
2545
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
168
2546
|
|
|
2547
|
+
//#endregion
|
|
2548
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-never.d.ts
|
|
169
2549
|
/**
|
|
170
2550
|
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
171
2551
|
|
|
@@ -185,10 +2565,10 @@ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
|
185
2565
|
@category Type Guard
|
|
186
2566
|
@category Utilities
|
|
187
2567
|
*/
|
|
188
|
-
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
189
|
-
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
190
|
-
);
|
|
2568
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
191
2569
|
|
|
2570
|
+
//#endregion
|
|
2571
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/array.d.ts
|
|
192
2572
|
/**
|
|
193
2573
|
Extract the element of an array that also works for array union.
|
|
194
2574
|
|
|
@@ -198,6 +2578,18 @@ It creates a type-safe way to access the element type of `unknown` type.
|
|
|
198
2578
|
*/
|
|
199
2579
|
type ArrayElement<T> = T extends readonly unknown[] ? T[0] : never;
|
|
200
2580
|
|
|
2581
|
+
//#endregion
|
|
2582
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/is-any.d.ts
|
|
2583
|
+
/**
|
|
2584
|
+
Returns the static, fixed-length portion of the given array, excluding variable-length parts.
|
|
2585
|
+
|
|
2586
|
+
@example
|
|
2587
|
+
```
|
|
2588
|
+
type A = [string, number, boolean, ...string[]];
|
|
2589
|
+
type B = StaticPartOfArray<A>;
|
|
2590
|
+
//=> [string, number, boolean]
|
|
2591
|
+
```
|
|
2592
|
+
*/
|
|
201
2593
|
// Can eventually be replaced with the built-in once this library supports
|
|
202
2594
|
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
203
2595
|
type NoInfer<T> = T extends infer U ? U : never;
|
|
@@ -232,6 +2624,8 @@ const anyA = get(anyObject, 'a');
|
|
|
232
2624
|
*/
|
|
233
2625
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
234
2626
|
|
|
2627
|
+
//#endregion
|
|
2628
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/simplify.d.ts
|
|
235
2629
|
/**
|
|
236
2630
|
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.
|
|
237
2631
|
|
|
@@ -289,8 +2683,10 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
289
2683
|
@see SimplifyDeep
|
|
290
2684
|
@category Object
|
|
291
2685
|
*/
|
|
292
|
-
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
2686
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
293
2687
|
|
|
2688
|
+
//#endregion
|
|
2689
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
294
2690
|
/**
|
|
295
2691
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
296
2692
|
|
|
@@ -381,12 +2777,10 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
381
2777
|
@see PickIndexSignature
|
|
382
2778
|
@category Object
|
|
383
2779
|
*/
|
|
384
|
-
type OmitIndexSignature<ObjectType> = {
|
|
385
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
386
|
-
? never
|
|
387
|
-
: KeyType]: ObjectType[KeyType];
|
|
388
|
-
};
|
|
2780
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
389
2781
|
|
|
2782
|
+
//#endregion
|
|
2783
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
390
2784
|
/**
|
|
391
2785
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
392
2786
|
|
|
@@ -432,16 +2826,12 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
432
2826
|
@see OmitIndexSignature
|
|
433
2827
|
@category Object
|
|
434
2828
|
*/
|
|
435
|
-
type PickIndexSignature<ObjectType> = {
|
|
436
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
437
|
-
? KeyType
|
|
438
|
-
: never]: ObjectType[KeyType];
|
|
439
|
-
};
|
|
2829
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
440
2830
|
|
|
2831
|
+
//#endregion
|
|
2832
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/merge.d.ts
|
|
441
2833
|
// Merges two objects without worrying about index signatures.
|
|
442
|
-
type SimpleMerge<Destination, Source> = {
|
|
443
|
-
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
444
|
-
} & Source;
|
|
2834
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
445
2835
|
|
|
446
2836
|
/**
|
|
447
2837
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
@@ -477,12 +2867,10 @@ export type FooBar = Merge<Foo, Bar>;
|
|
|
477
2867
|
|
|
478
2868
|
@category Object
|
|
479
2869
|
*/
|
|
480
|
-
type Merge<Destination, Source> =
|
|
481
|
-
Simplify<
|
|
482
|
-
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
483
|
-
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
484
|
-
>;
|
|
2870
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
485
2871
|
|
|
2872
|
+
//#endregion
|
|
2873
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/if-any.d.ts
|
|
486
2874
|
/**
|
|
487
2875
|
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
488
2876
|
|
|
@@ -502,15 +2890,21 @@ type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
|
502
2890
|
@category Type Guard
|
|
503
2891
|
@category Utilities
|
|
504
2892
|
*/
|
|
505
|
-
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
506
|
-
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
507
|
-
);
|
|
2893
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
508
2894
|
|
|
2895
|
+
//#endregion
|
|
2896
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/type.d.ts
|
|
509
2897
|
/**
|
|
510
2898
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
511
2899
|
*/
|
|
512
2900
|
type BuiltIns = Primitive | void | Date | RegExp;
|
|
513
2901
|
|
|
2902
|
+
//#endregion
|
|
2903
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/internal/object.d.ts
|
|
2904
|
+
/**
|
|
2905
|
+
Matches non-recursive types.
|
|
2906
|
+
*/
|
|
2907
|
+
|
|
514
2908
|
/**
|
|
515
2909
|
Merges user specified options with default options.
|
|
516
2910
|
|
|
@@ -563,65 +2957,43 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
563
2957
|
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
564
2958
|
```
|
|
565
2959
|
*/
|
|
566
|
-
type ApplyDefaultOptions<
|
|
567
|
-
|
|
568
|
-
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
569
|
-
SpecifiedOptions extends Options,
|
|
570
|
-
> =
|
|
571
|
-
IfAny<SpecifiedOptions, Defaults,
|
|
572
|
-
IfNever<SpecifiedOptions, Defaults,
|
|
573
|
-
Simplify<Merge<Defaults, {
|
|
574
|
-
[Key in keyof SpecifiedOptions
|
|
575
|
-
as Key extends OptionalKeysOf<Options>
|
|
576
|
-
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
577
|
-
? Key
|
|
578
|
-
: never
|
|
579
|
-
: Key
|
|
580
|
-
]: SpecifiedOptions[Key]
|
|
581
|
-
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
582
|
-
>>;
|
|
2960
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny<SpecifiedOptions, Defaults, IfNever<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
2961
|
+
>>;
|
|
583
2962
|
|
|
2963
|
+
//#endregion
|
|
2964
|
+
//#region ../../node_modules/.pnpm/type-fest@4.40.1/node_modules/type-fest/source/partial-deep.d.ts
|
|
584
2965
|
/**
|
|
585
2966
|
@see {@link PartialDeep}
|
|
586
2967
|
*/
|
|
587
2968
|
type PartialDeepOptions = {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
614
|
-
|
|
615
|
-
partialSettings.languages = [undefined]; // Error
|
|
616
|
-
partialSettings.languages = []; // Ok
|
|
617
|
-
```
|
|
618
|
-
*/
|
|
619
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
2969
|
+
/**
|
|
2970
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
2971
|
+
@default false
|
|
2972
|
+
*/
|
|
2973
|
+
readonly recurseIntoArrays?: boolean;
|
|
2974
|
+
|
|
2975
|
+
/**
|
|
2976
|
+
Allows `undefined` values in non-tuple arrays.
|
|
2977
|
+
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
2978
|
+
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
2979
|
+
@default true
|
|
2980
|
+
@example
|
|
2981
|
+
You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
|
|
2982
|
+
```
|
|
2983
|
+
import type {PartialDeep} from 'type-fest';
|
|
2984
|
+
type Settings = {
|
|
2985
|
+
languages: string[];
|
|
2986
|
+
};
|
|
2987
|
+
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
2988
|
+
partialSettings.languages = [undefined]; // Error
|
|
2989
|
+
partialSettings.languages = []; // Ok
|
|
2990
|
+
```
|
|
2991
|
+
*/
|
|
2992
|
+
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
620
2993
|
};
|
|
621
|
-
|
|
622
2994
|
type DefaultPartialDeepOptions = {
|
|
623
|
-
|
|
624
|
-
|
|
2995
|
+
recurseIntoArrays: false;
|
|
2996
|
+
allowUndefinedInNonTupleArrays: true;
|
|
625
2997
|
};
|
|
626
2998
|
|
|
627
2999
|
/**
|
|
@@ -673,32 +3045,14 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
|
673
3045
|
@category Set
|
|
674
3046
|
@category Map
|
|
675
3047
|
*/
|
|
676
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
? PartialMapDeep<KeyType, ValueType, Options>
|
|
685
|
-
: T extends Set<infer ItemType>
|
|
686
|
-
? PartialSetDeep<ItemType, Options>
|
|
687
|
-
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
688
|
-
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
689
|
-
: T extends ReadonlySet<infer ItemType>
|
|
690
|
-
? PartialReadonlySetDeep<ItemType, Options>
|
|
691
|
-
: T extends object
|
|
692
|
-
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
693
|
-
? Options['recurseIntoArrays'] extends true
|
|
694
|
-
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
695
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
696
|
-
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
697
|
-
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
698
|
-
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
699
|
-
: T // If they don't opt into array testing, just use the original type
|
|
700
|
-
: PartialObjectDeep<T, Options>
|
|
701
|
-
: unknown;
|
|
3048
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
3049
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T : IsNever<keyof T> extends true // For functions with no properties
|
|
3050
|
+
? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
3051
|
+
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
3052
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
3053
|
+
? 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
|
|
3054
|
+
: T // If they don't opt into array testing, just use the original type
|
|
3055
|
+
: PartialObjectDeep<T, Options> : unknown;
|
|
702
3056
|
|
|
703
3057
|
/**
|
|
704
3058
|
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
@@ -723,63 +3077,54 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
|
|
|
723
3077
|
/**
|
|
724
3078
|
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
725
3079
|
*/
|
|
726
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
|
|
727
|
-
(ObjectType extends (...arguments_: any) => unknown
|
|
728
|
-
? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
|
|
729
|
-
: {}) & ({
|
|
730
|
-
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
731
|
-
});
|
|
3080
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = (ObjectType extends ((...arguments_: any) => unknown) ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType> : {}) & ({ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> });
|
|
732
3081
|
|
|
3082
|
+
//#endregion
|
|
3083
|
+
//#region src/types/core.types.d.ts
|
|
733
3084
|
type RegleSchema<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
3085
|
+
/**
|
|
3086
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
3087
|
+
*
|
|
3088
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
3089
|
+
*/
|
|
3090
|
+
r$: Raw<RegleSchemaStatus<TState, TSchema, TShortcuts, true>>;
|
|
740
3091
|
} & TAdditionalReturnProperties;
|
|
741
3092
|
type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extends unknown, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
3093
|
+
/**
|
|
3094
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
3095
|
+
*
|
|
3096
|
+
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
3097
|
+
*/
|
|
3098
|
+
r$: Raw<RegleSchemaFieldStatus<TState, TSchema, TShortcuts> & {
|
|
3099
|
+
/** 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). */
|
|
3100
|
+
$validate: () => Promise<RegleSchemaResult<TSchema>>;
|
|
3101
|
+
}>;
|
|
751
3102
|
} & TAdditionalReturnProperties;
|
|
752
3103
|
type RegleSchemaResult<TSchema extends unknown> = {
|
|
753
|
-
|
|
754
|
-
|
|
3104
|
+
valid: false;
|
|
3105
|
+
data: PartialDeep<TSchema>;
|
|
755
3106
|
} | {
|
|
756
|
-
|
|
757
|
-
|
|
3107
|
+
valid: true;
|
|
3108
|
+
data: TSchema;
|
|
758
3109
|
};
|
|
759
3110
|
/**
|
|
760
3111
|
* @public
|
|
761
3112
|
*/
|
|
762
3113
|
type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>, TSchema extends Record<string, any> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
774
|
-
readonly $silentErrors: RegleErrorTree<TState>;
|
|
775
|
-
/** 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). */
|
|
776
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3114
|
+
/** 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. */
|
|
3115
|
+
readonly $fields: { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TSchema> ? JoinDiscriminatedUnions<TSchema>[TKey] extends NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never };
|
|
3116
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3117
|
+
*
|
|
3118
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
3119
|
+
readonly $errors: RegleErrorTree<TState>;
|
|
3120
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
3121
|
+
readonly $silentErrors: RegleErrorTree<TState>;
|
|
3122
|
+
/** 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). */
|
|
3123
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
777
3124
|
} & (IsRoot extends true ? {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : {
|
|
781
|
-
[K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>;
|
|
782
|
-
});
|
|
3125
|
+
/** 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). */
|
|
3126
|
+
$validate: () => Promise<RegleSchemaResult<TSchema>>;
|
|
3127
|
+
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
783
3128
|
/**
|
|
784
3129
|
* @public
|
|
785
3130
|
*/
|
|
@@ -788,72 +3133,68 @@ type InferRegleSchemaStatusType<TSchema extends unknown, TState extends unknown,
|
|
|
788
3133
|
* @public
|
|
789
3134
|
*/
|
|
790
3135
|
type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : {
|
|
808
|
-
[K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>;
|
|
809
|
-
});
|
|
3136
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3137
|
+
*
|
|
3138
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
3139
|
+
readonly $errors: string[];
|
|
3140
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
3141
|
+
readonly $silentErrors: string[];
|
|
3142
|
+
/** 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). */
|
|
3143
|
+
readonly $externalErrors?: string[];
|
|
3144
|
+
/** Represents the inactive status. Is true when this state have empty rules */
|
|
3145
|
+
readonly $inactive: boolean;
|
|
3146
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
3147
|
+
readonly $rules: {
|
|
3148
|
+
[`~validator`]: RegleRuleStatus<TState, []>;
|
|
3149
|
+
};
|
|
3150
|
+
/** 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). */
|
|
3151
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3152
|
+
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
810
3153
|
/**
|
|
811
3154
|
* @public
|
|
812
3155
|
*/
|
|
813
3156
|
type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState extends any[], TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TSchema, TState, TShortcuts>, '$errors' | '$silentErrors' | '$validate'> & {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
3157
|
+
/** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */
|
|
3158
|
+
readonly $each: Array<InferRegleSchemaStatusType<NonNullable<TSchema>, ArrayElement<TState>, TShortcuts>>;
|
|
3159
|
+
/** 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. */
|
|
3160
|
+
readonly $self: RegleSchemaFieldStatus<TSchema, TState, TShortcuts>;
|
|
3161
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
3162
|
+
*
|
|
3163
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
3164
|
+
readonly $errors: RegleCollectionErrors<TSchema>;
|
|
3165
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
3166
|
+
readonly $silentErrors: RegleCollectionErrors<TSchema>;
|
|
3167
|
+
/** 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). */
|
|
3168
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3169
|
+
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
3170
|
+
|
|
3171
|
+
//#endregion
|
|
3172
|
+
//#region src/types/options.types.d.ts
|
|
830
3173
|
type RegleSchemaBehaviourOptions = {
|
|
3174
|
+
/**
|
|
3175
|
+
* Settings for applying transforms and default to the current state
|
|
3176
|
+
*/
|
|
3177
|
+
syncState?: {
|
|
3178
|
+
/**
|
|
3179
|
+
* Applies every transform on every update to the state
|
|
3180
|
+
*/
|
|
3181
|
+
onUpdate?: boolean;
|
|
831
3182
|
/**
|
|
832
|
-
*
|
|
3183
|
+
* Applies every transform only when calling `$validate`
|
|
833
3184
|
*/
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
* Applies every transform on every update to the state
|
|
837
|
-
*/
|
|
838
|
-
onUpdate?: boolean;
|
|
839
|
-
/**
|
|
840
|
-
* Applies every transform only when calling `$validate`
|
|
841
|
-
*/
|
|
842
|
-
onValidate?: boolean;
|
|
843
|
-
};
|
|
3185
|
+
onValidate?: boolean;
|
|
3186
|
+
};
|
|
844
3187
|
};
|
|
845
3188
|
|
|
3189
|
+
//#endregion
|
|
3190
|
+
//#region src/core/useRegleSchema.d.ts
|
|
846
3191
|
type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly' | 'silent'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
|
|
847
3192
|
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}>>,
|
|
854
|
-
rulesFactory: MaybeRef<TSchema>,
|
|
855
|
-
...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])
|
|
856
|
-
]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, UnwrapNestedRefs<NonNullable<StandardSchemaV1.InferInput<TSchema>>>, TShortcuts, TAdditionalReturnProperties>;
|
|
3193
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<TState, {
|
|
3194
|
+
recurseIntoArrays: true;
|
|
3195
|
+
}>> | DeepReactiveState<PartialDeep<TState, {
|
|
3196
|
+
recurseIntoArrays: true;
|
|
3197
|
+
}>>, rulesFactory: MaybeRef<TSchema>, ...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, UnwrapNestedRefs<NonNullable<StandardSchemaV1.InferInput<TSchema>>>, TShortcuts, TAdditionalReturnProperties>;
|
|
857
3198
|
}
|
|
858
3199
|
/**
|
|
859
3200
|
* useRegle serves as the foundation for validation logic.
|
|
@@ -876,6 +3217,8 @@ interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = nev
|
|
|
876
3217
|
*/
|
|
877
3218
|
declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
878
3219
|
|
|
3220
|
+
//#endregion
|
|
3221
|
+
//#region src/core/withDeps.d.ts
|
|
879
3222
|
/**
|
|
880
3223
|
*
|
|
881
3224
|
* Force dependency on any RPC schema
|
|
@@ -894,12 +3237,14 @@ declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {},
|
|
|
894
3237
|
*/
|
|
895
3238
|
declare function withDeps<TSchema extends StandardSchemaV1, TParams extends unknown[] = []>(schema: TSchema, depsArray: [...TParams]): TSchema;
|
|
896
3239
|
|
|
3240
|
+
//#endregion
|
|
3241
|
+
//#region src/core/inferSchema.d.ts
|
|
897
3242
|
interface inferSchemaFn {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
3243
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(state: MaybeRef<PartialDeep<TState, {
|
|
3244
|
+
recurseIntoArrays: true;
|
|
3245
|
+
}>> | DeepReactiveState<PartialDeep<TState, {
|
|
3246
|
+
recurseIntoArrays: true;
|
|
3247
|
+
}>>, rulesFactory: MaybeRef<TSchema>): NoInferLegacy<TSchema>;
|
|
903
3248
|
}
|
|
904
3249
|
/**
|
|
905
3250
|
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
@@ -910,6 +3255,8 @@ interface inferSchemaFn {
|
|
|
910
3255
|
*/
|
|
911
3256
|
declare const inferSchema: inferSchemaFn;
|
|
912
3257
|
|
|
3258
|
+
//#endregion
|
|
3259
|
+
//#region src/core/defineRegleSchemaConfig.d.ts
|
|
913
3260
|
/**
|
|
914
3261
|
* Define a global regle configuration, where you can:
|
|
915
3262
|
* - Define global modifiers
|
|
@@ -920,33 +3267,38 @@ declare const inferSchema: inferSchemaFn;
|
|
|
920
3267
|
* - a `useRegleSchema` composable that can typecheck your custom rules
|
|
921
3268
|
* - an `inferSchema` helper that can typecheck your custom rules
|
|
922
3269
|
*/
|
|
923
|
-
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({
|
|
924
|
-
|
|
925
|
-
|
|
3270
|
+
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({
|
|
3271
|
+
modifiers,
|
|
3272
|
+
shortcuts
|
|
3273
|
+
}: {
|
|
3274
|
+
modifiers?: RegleBehaviourOptions;
|
|
3275
|
+
shortcuts?: TShortcuts;
|
|
926
3276
|
}): {
|
|
927
|
-
|
|
928
|
-
|
|
3277
|
+
useRegleSchema: useRegleSchemaFn<TShortcuts>;
|
|
3278
|
+
inferSchema: inferSchemaFn;
|
|
929
3279
|
};
|
|
930
3280
|
|
|
3281
|
+
//#endregion
|
|
3282
|
+
//#region src/core/createScopedUseRegleSchema.d.ts
|
|
931
3283
|
type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any, any>, TAsRecord extends boolean> = Omit<CreateScopedUseRegleOptions<any, TAsRecord>, 'customUseRegle'> & {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
3284
|
+
/**
|
|
3285
|
+
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
3286
|
+
*/
|
|
3287
|
+
customUseRegle?: TCustomRegle;
|
|
936
3288
|
};
|
|
937
3289
|
declare const useCollectSchemaScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
938
3290
|
r$: MergedScopedRegles<TValue>;
|
|
939
|
-
}
|
|
940
|
-
declare const
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
register: () => void;
|
|
3291
|
+
}, useScopedRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
|
|
3292
|
+
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TAsRecord extends boolean = false, TReturnedRegle extends useRegleSchemaFn<any, any, any> = (TCustomRegle extends useRegleSchemaFn<infer S> ? useRegleSchemaFn<S, {
|
|
3293
|
+
dispose: () => void;
|
|
3294
|
+
register: () => void;
|
|
944
3295
|
}, UseScopedRegleOptions<TAsRecord>> : useRegleSchemaFn<any, {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
}, UseScopedRegleOptions<TAsRecord
|
|
948
|
-
|
|
949
|
-
|
|
3296
|
+
dispose: () => void;
|
|
3297
|
+
register: () => void;
|
|
3298
|
+
}, UseScopedRegleOptions<TAsRecord>>)>(options?: CreateScopedUseRegleSchemaOptions<TCustomRegle, TAsRecord>) => {
|
|
3299
|
+
useScopedRegle: TReturnedRegle;
|
|
3300
|
+
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
950
3301
|
};
|
|
951
3302
|
|
|
952
|
-
|
|
3303
|
+
//#endregion
|
|
3304
|
+
export { InferRegleSchemaStatusType, RegleSchema, RegleSchemaBehaviourOptions, RegleSchemaCollectionStatus, RegleSchemaFieldStatus, RegleSchemaResult, RegleSchemaStatus, RegleSingleFieldSchema, createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
|