@regle/core 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,18 +1,15 @@
1
- import * as vue from 'vue';
2
- import { MaybeRef, Ref, ComputedRef } from 'vue';
1
+ import { MaybeRef, ComputedRef, Ref, UnwrapNestedRefs } from 'vue';
3
2
 
4
- type ArrayElement<T> = T extends Array<infer U> ? U : never;
5
- type ExcludeFromTuple<T extends readonly any[], E> = T extends [infer F, ...infer R] ? [NonNullable<F>] extends [E] ? ExcludeFromTuple<R, E> : [Exclude<F, E>, ...ExcludeFromTuple<R, E>] : [];
6
- type UnrefTuple<T extends readonly any[]> = T extends [infer F, ...infer R] ? [NonNullable<F>] extends [MaybeRef<infer U>] ? [U, ...UnrefTuple<R>] : [F, ...UnrefTuple<R>] : [];
7
-
8
- type Maybe<T> = T | null | undefined;
9
- type MaybeNull<T> = T | null;
3
+ type Maybe<T = any> = T | null | undefined;
10
4
  type DeepMaybeRef<T extends Record<string, any>> = {
11
5
  [K in keyof T]: MaybeRef<T[K]>;
12
6
  };
13
7
  type ExcludeByType<T, U> = {
14
8
  [K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K];
15
9
  };
10
+ type NonPresentKeys<TSource extends Record<string, any>, Target extends Record<string, any>> = Omit<Target, keyof TSource>;
11
+
12
+ type ArrayElement<T> = T extends Array<infer U> ? U : never;
16
13
 
17
14
  type ParamDecl<T = any> = MaybeRef<Maybe<T>> | (() => Maybe<T>);
18
15
  type CreateFn<T extends any[]> = (...args: T) => any;
@@ -51,22 +48,12 @@ declare enum InternalRuleType {
51
48
  /**
52
49
  * Returned typed of rules created with `createRule`
53
50
  * */
54
- interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition> extends RegleInternalRuleDefs<TValue, TParams, TAsync, TMetaData> {
55
- validator: RegleRuleDefinitionProcessor<TValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
56
- message: RegleRuleDefinitionWithMetadataProcessor<TValue, PossibleRegleRuleMetadataConsumer, string | string[]>;
57
- active: RegleRuleDefinitionWithMetadataProcessor<TValue, PossibleRegleRuleMetadataConsumer, boolean>;
58
- type?: string;
59
- exec: (value: Maybe<TValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
60
- }
61
- /**
62
- * @internal
63
- * */
64
- interface $InternalRegleRuleDefinition extends RegleInternalRuleDefs<any, any, any> {
65
- validator: RegleRuleDefinitionProcessor;
66
- message: RegleRuleDefinitionWithMetadataProcessor<any, any, any>;
67
- active: RegleRuleDefinitionWithMetadataProcessor<any, any, any>;
51
+ interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
52
+ validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
53
+ message: RegleRuleDefinitionWithMetadataProcessor<TFilteredValue, PossibleRegleRuleMetadataConsumer, string | string[]>;
54
+ active: RegleRuleDefinitionWithMetadataProcessor<TFilteredValue, PossibleRegleRuleMetadataConsumer, boolean>;
68
55
  type?: string;
69
- exec: (value: any) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
56
+ exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
70
57
  }
71
58
  /**
72
59
  * Rules with params created with `createRules` are callable while being customizable
@@ -74,33 +61,27 @@ interface $InternalRegleRuleDefinition extends RegleInternalRuleDefs<any, any, a
74
61
  interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> extends RegleRuleCore<TValue, TParams, TAsync, TMetadata>, RegleInternalRuleDefs<TValue, TParams, TAsync, TMetadata> {
75
62
  (...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
76
63
  }
64
+ type RegleRuleMetadataExtended = {
65
+ $valid: boolean;
66
+ [x: string]: any;
67
+ };
77
68
  /**
78
69
  * Define a rule Metadata definition
79
70
  */
80
- type RegleRuleMetadataDefinition = {
81
- $valid: boolean;
82
- [x: string]: any;
83
- } | boolean;
71
+ type RegleRuleMetadataDefinition = RegleRuleMetadataExtended | boolean;
84
72
  type DefaultMetadataProperties = Pick<ExcludeByType<RegleCommonStatus, Function>, '$invalid'>;
85
73
  /**
86
74
  * Will be used to consumme metadata on related helpers and rule status
87
75
  */
88
76
  type RegleRuleMetadataConsumer<TParams extends any[] = [], TMetadata extends RegleRuleMetadataDefinition = boolean> = DefaultMetadataProperties & (TParams extends never ? {} : {
89
77
  $params: TParams;
90
- }) & (TMetadata extends boolean ? {} : Omit<TMetadata, '$valid'>);
78
+ }) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
91
79
  /**
92
80
  * Will be used to consumme metadata on related helpers and rule status
93
81
  */
94
82
  type PossibleRegleRuleMetadataConsumer = DefaultMetadataProperties & {
95
83
  $params?: any[];
96
84
  };
97
- /**
98
- * @internal
99
- */
100
- type $InternalRegleRuleMetadataConsumer = DefaultMetadataProperties & {
101
- $params?: any[];
102
- [x: string]: any;
103
- };
104
85
  /**
105
86
  * Generic types for a created RegleRule
106
87
  */
@@ -142,16 +123,6 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
142
123
  active?: boolean | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => boolean);
143
124
  type?: string;
144
125
  }
145
- /**
146
- * @internal
147
- * createRule arguments options
148
- */
149
- interface $InternalRegleRuleInit {
150
- validator: (value: any, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
151
- message: string | ((value: any, metadata: $InternalRegleRuleMetadataConsumer) => string | string[]);
152
- active?: boolean | ((value: any, metadata: $InternalRegleRuleMetadataConsumer) => boolean);
153
- type?: string;
154
- }
155
126
 
156
127
  type DefaultValidators = {
157
128
  maxLength: RegleRuleWithParamsDefinition<string, [count: number]>;
@@ -182,20 +153,6 @@ type CustomRulesDeclarationTree = {
182
153
  };
183
154
  type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidators;
184
155
 
185
- /**
186
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
187
-
188
- @category Type
189
- */
190
- type Primitive =
191
- | null
192
- | undefined
193
- | string
194
- | number
195
- | boolean
196
- | symbol
197
- | bigint;
198
-
199
156
  declare global {
200
157
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
201
158
  interface SymbolConstructor {
@@ -203,227 +160,50 @@ declare global {
203
160
  }
204
161
  }
205
162
 
206
- /**
207
- Matches any primitive, `void`, `Date`, or `RegExp` value.
208
- */
209
- type BuiltIns = Primitive | void | Date | RegExp;
210
-
211
- /**
212
- Test if the given function has multiple call signatures.
213
-
214
- Needed to handle the case of a single call signature with properties.
215
-
216
- Multiple call signatures cannot currently be supported due to a TypeScript limitation.
217
- @see https://github.com/microsoft/TypeScript/issues/29732
218
- */
219
- type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
220
- T extends {(...arguments_: infer A): unknown; (...arguments_: any[]): unknown}
221
- ? unknown[] extends A
222
- ? false
223
- : true
224
- : false;
225
-
226
- /**
227
- @see PartialDeep
228
- */
229
- type PartialDeepOptions = {
230
- /**
231
- Whether to affect the individual elements of arrays and tuples.
232
-
233
- @default false
234
- */
235
- readonly recurseIntoArrays?: boolean;
236
- };
237
-
238
- /**
239
- Create a type from another type with all keys and nested keys set to optional.
240
-
241
- Use-cases:
242
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
243
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
244
-
245
- @example
246
- ```
247
- import type {PartialDeep} from 'type-fest';
248
-
249
- const settings: Settings = {
250
- textEditor: {
251
- fontSize: 14;
252
- fontColor: '#000000';
253
- fontWeight: 400;
254
- }
255
- autocomplete: false;
256
- autosave: true;
257
- };
258
-
259
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
260
- return {...settings, ...savedSettings};
261
- }
262
-
263
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
264
- ```
265
-
266
- 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:
267
-
268
- ```
269
- import type {PartialDeep} from 'type-fest';
270
-
271
- interface Settings {
272
- languages: string[];
273
- }
274
-
275
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
276
- languages: [undefined]
277
- };
278
- ```
279
-
280
- @category Object
281
- @category Array
282
- @category Set
283
- @category Map
284
- */
285
- type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
286
- ? T
287
- : T extends Map<infer KeyType, infer ValueType>
288
- ? PartialMapDeep<KeyType, ValueType, Options>
289
- : T extends Set<infer ItemType>
290
- ? PartialSetDeep<ItemType, Options>
291
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
292
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
293
- : T extends ReadonlySet<infer ItemType>
294
- ? PartialReadonlySetDeep<ItemType, Options>
295
- : T extends object
296
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
297
- ? Options['recurseIntoArrays'] extends true
298
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
299
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
300
- ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
301
- : Array<PartialDeep<ItemType | undefined, Options>>
302
- : PartialObjectDeep<T, Options> // Tuples behave properly
303
- : T // If they don't opt into array testing, just use the original type
304
- : PartialObjectDeep<T, Options>
305
- : unknown;
306
-
307
- /**
308
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
309
- */
310
- type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
311
-
312
- /**
313
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
314
- */
315
- type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
316
-
317
- /**
318
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
319
- */
320
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
321
-
322
- /**
323
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
324
- */
325
- type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
163
+ declare const emptyObjectSymbol: unique symbol;
326
164
 
327
165
  /**
328
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
329
- */
330
- type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
331
- [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
332
- };
166
+ Represents a strictly empty plain object, the `{}` value.
333
167
 
334
- type ExcludeUndefined<T> = Exclude<T, undefined>;
335
-
336
- /**
337
- Create a type from another type with all keys and nested keys set to required.
338
-
339
- Use-cases:
340
- - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
341
- - Modeling the resulting type after a deep merge with a set of defaults.
168
+ 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)).
342
169
 
343
170
  @example
344
171
  ```
345
- import type {RequiredDeep} from 'type-fest';
346
-
347
- type Settings = {
348
- textEditor?: {
349
- fontSize?: number | undefined;
350
- fontColor?: string | undefined;
351
- fontWeight?: number | undefined;
352
- }
353
- autocomplete?: boolean | undefined;
354
- autosave?: boolean | undefined;
355
- };
356
-
357
- type RequiredSettings = RequiredDeep<Settings>;
358
- // type RequiredSettings = {
359
- // textEditor: {
360
- // fontSize: number;
361
- // fontColor: string;
362
- // fontWeight: number;
363
- // }
364
- // autocomplete: boolean;
365
- // autosave: boolean;
366
- // }
172
+ import type {EmptyObject} from 'type-fest';
173
+
174
+ // The following illustrates the problem with `{}`.
175
+ const foo1: {} = {}; // Pass
176
+ const foo2: {} = []; // Pass
177
+ const foo3: {} = 42; // Pass
178
+ const foo4: {} = {a: 1}; // Pass
179
+
180
+ // With `EmptyObject` only the first case is valid.
181
+ const bar1: EmptyObject = {}; // Pass
182
+ const bar2: EmptyObject = 42; // Fail
183
+ const bar3: EmptyObject = []; // Fail
184
+ const bar4: EmptyObject = {a: 1}; // Fail
367
185
  ```
368
186
 
369
- Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
187
+ 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}.
370
188
 
371
- @category Utilities
372
189
  @category Object
373
- @category Array
374
- @category Set
375
- @category Map
376
190
  */
377
- type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
378
- ? E
379
- : E extends Map<infer KeyType, infer ValueType>
380
- ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
381
- : E extends Set<infer ItemType>
382
- ? Set<RequiredDeep<ItemType>>
383
- : E extends ReadonlyMap<infer KeyType, infer ValueType>
384
- ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
385
- : E extends ReadonlySet<infer ItemType>
386
- ? ReadonlySet<RequiredDeep<ItemType>>
387
- : E extends WeakMap<infer KeyType, infer ValueType>
388
- ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
389
- : E extends WeakSet<infer ItemType>
390
- ? WeakSet<RequiredDeep<ItemType>>
391
- : E extends Promise<infer ValueType>
392
- ? Promise<RequiredDeep<ValueType>>
393
- : E extends (...arguments_: any[]) => unknown
394
- ? {} extends RequiredObjectDeep<E>
395
- ? E
396
- : HasMultipleCallSignatures<E> extends true
397
- ? E
398
- : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
399
- : E extends object
400
- ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
401
- ? ItemType[] extends E // Test for arrays (non-tuples) specifically
402
- ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
403
- : RequiredObjectDeep<E> // Tuples behave properly
404
- : RequiredObjectDeep<E>
405
- : unknown;
406
-
407
- type RequiredObjectDeep<ObjectType extends object> = {
408
- [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
409
- };
191
+ type EmptyObject = {[emptyObjectSymbol]?: never};
410
192
 
411
- interface Regle<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>> {
412
- $state: Ref<PartialDeep<TState>>;
413
- $regle: RegleStatus<TState, TRules>;
193
+ interface Regle<TState extends Record<string, any> = EmptyObject, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree> = EmptyObject, TExternal extends RegleExternalErrorTree<TState> = never> {
194
+ regle: RegleStatus<TState, TRules>;
414
195
  /** Show active errors based on your behaviour options (lazy, autoDirty)
415
- * It allow you to skip scouting the `$regle` object
196
+ * It allow you to skip scouting the `regle` object
416
197
  */
417
- $errors: RegleErrorTree<TRules>;
418
- $valid: ComputedRef<boolean>;
419
- $invalid: ComputedRef<boolean>;
198
+ errors: RegleErrorTree<TRules, TExternal>;
199
+ invalid: ComputedRef<boolean>;
420
200
  resetForm: () => void;
421
201
  validateForm: () => Promise<false | DeepSafeFormState<TState, TRules>>;
422
202
  }
423
203
  type DeepReactiveState<T extends Record<string, any>> = {
424
204
  [K in keyof T]: MaybeRef<T[K]>;
425
205
  };
426
- type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>> = {
206
+ type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>> = [unknown] extends [TState] ? {} : {
427
207
  [K in keyof TState as [SafeProperty<TState[K], TRules[K]>] extends [never] ? K : never]?: [
428
208
  SafeProperty<TState[K], TRules[K]>
429
209
  ] extends [never] ? TState[K] : SafeProperty<TState[K], TRules[K]>;
@@ -451,22 +231,15 @@ interface RegleBehaviourOptions {
451
231
  */
452
232
  rewardEarly?: boolean;
453
233
  }
454
- interface LocalRegleBehaviourOptions<TState extends Record<string, any>> {
455
- $externalErrors?: MaybeRef<RegleExternalErrorTree<TState>>;
234
+ interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TExternal extends RegleExternalErrorTree<TState>> {
235
+ $externalErrors?: MaybeRef<TExternal>;
456
236
  }
457
237
  type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
458
238
  $debounce?: number;
459
239
  };
460
- type ResolvedRegleBehaviourOptions = DeepMaybeRef<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>>;
461
240
  type AddDollarToOptions<T extends Record<string, any>> = {
462
241
  [K in keyof T as `$${string & K}`]: T[K];
463
242
  };
464
- type FilterDollarProperties<T extends Record<string, any>> = {
465
- [K in keyof T as K extends `$${string}` ? never : K]: T[K];
466
- };
467
- type PickDollarProperties<T extends Record<string, any>> = {
468
- [K in keyof T as K extends `$${string}` ? K : never]: T[K];
469
- };
470
243
 
471
244
  /**
472
245
  * @public
@@ -481,21 +254,15 @@ type RegleValidationTree<TForm extends Record<string, any>, TCustomRules extends
481
254
  [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules>;
482
255
  };
483
256
  /**
484
- * @internal
485
- * @reference {@link ReglePartialValidationTree}
257
+ * @public
486
258
  */
487
- type $InternalReglePartialValidationTree = {
488
- [x: string]: $InternalFormPropertyTypes;
259
+ type RegleComputedRules<TForm extends MaybeRef<Record<string, any>>, TCustomRules extends Partial<AllRulesDeclarations> | Regle<any, any> = Partial<AllRulesDeclarations>, TState = TForm extends Ref<infer R> ? R : TForm, TCustom = TCustomRules extends Regle<any, infer R> ? R extends ReglePartialValidationTree<any, infer C> ? C : Partial<AllRulesDeclarations> : TCustomRules> = {
260
+ [TKey in keyof TState]?: RegleFormPropertyType<TState[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
489
261
  };
490
262
  /**
491
263
  * @public
492
264
  */
493
- 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 Record<string, any> ? ReglePartialValidationTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
494
- /**
495
- * @internal
496
- * @reference {@link RegleFormPropertyType}
497
- */
498
- type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialValidationTree;
265
+ 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> ? ReglePartialValidationTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
499
266
  /**
500
267
  * @public
501
268
  * Rule tree for a form property
@@ -503,11 +270,6 @@ type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollect
503
270
  type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = FieldRegleBehaviourOptions & {
504
271
  [TKey in keyof TCustomRules]?: NonNullable<TCustomRules[TKey]> extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, TParams, boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any, any, any> ? FormRuleDeclaration<TValue, any> : FormRuleDeclaration<TValue, any> | FieldRegleBehaviourOptions[keyof FieldRegleBehaviourOptions];
505
272
  };
506
- /**
507
- * @internal
508
- * @reference {@link RegleRuleDecl}
509
- */
510
- type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any>>;
511
273
  /**
512
274
  * @public
513
275
  */
@@ -516,36 +278,26 @@ type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRul
516
278
  }) | {
517
279
  $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
518
280
  };
519
- /**
520
- * @internal
521
- * @reference {@link RegleCollectionRuleDecl}
522
- *
523
- */
524
- type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
525
- $each?: $InternalFormPropertyTypes;
526
- };
527
281
  /**
528
282
  * @public
529
283
  */
530
- type InlineRuleDeclaration<TValue extends any, TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>> = (value: Maybe<TValue>, ...args: any[]) => TReturn;
284
+ type InlineRuleDeclaration<TValue extends any = any, TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>> = (value: Maybe<TValue>, ...args: any[]) => TReturn;
531
285
  /**
532
286
  * @public
533
287
  * Regroup inline and registered rules
534
288
  * */
535
- type FormRuleDeclaration<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = boolean> = InlineRuleDeclaration<TValue, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
289
+ type FormRuleDeclaration<TValue extends any, TParams extends 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, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
536
290
 
537
- type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
538
- readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
291
+ type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>, TExternal extends RegleExternalErrorTree<Record<string, unknown>> = never> = {
292
+ readonly [K in keyof TRules]: RegleValidationErrors<TRules[K], K extends keyof TExternal ? TExternal[K] : never>;
293
+ } & {
294
+ readonly [K in keyof NonPresentKeys<TRules, TExternal>]: RegleExternalValidationErrorsReport<TExternal[K]>;
539
295
  };
540
- type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<TRule['$each']> : TRule extends ReglePartialValidationTree<any, any> ? RegleErrorTree<TRule> : TRule extends RegleRuleDecl<any, any> ? string[] : string[];
541
- type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = {
296
+ type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never, TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<TRule['$each'], TExternalError extends RegleExternalCollectionErrors ? ArrayElement<TExternalError['$each']> : never> : TRule extends RegleRuleDecl<any, any> ? string[] : TRule extends ReglePartialValidationTree<any, any> ? RegleErrorTree<TRule, TExternalError extends RegleExternalErrorTree ? TExternalError : never> : string[];
297
+ type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never, TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = {
542
298
  readonly $errors: string[];
543
- readonly $each: RegleValidationErrors<TRule>[];
299
+ readonly $each: RegleValidationErrors<TRule, TExternalError>[];
544
300
  };
545
- /**
546
- * @internal
547
- */
548
- type $InternalRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
549
301
  type RegleExternalErrorTree<TState extends Record<string, any> = Record<string, any>> = {
550
302
  [K in keyof TState]?: RegleExternalValidationErrors<TState[K]>;
551
303
  };
@@ -556,8 +308,7 @@ type RegleExternalCollectionErrors<TValue extends any = any> = {
556
308
  $errors?: string[];
557
309
  $each?: RegleExternalValidationErrors<TValue>[];
558
310
  };
559
- type $InternalExternalRegleErrors = RegleExternalCollectionErrors<any> | string[] | RegleExternalErrorTree<any>;
560
- type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
311
+ type RegleExternalValidationErrorsReport<TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = TExternalError extends RegleExternalCollectionErrors ? RegleCollectionErrors<TExternalError['$each']> : TExternalError extends string[] ? string[] : TExternalError extends RegleExternalErrorTree<any> ? RegleErrorTree<TExternalError> : string[];
561
312
 
562
313
  /**
563
314
  * @public
@@ -567,43 +318,20 @@ interface RegleStatus<TState extends Record<string, any> = Record<string, any>,
567
318
  readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
568
319
  };
569
320
  }
570
- /**
571
- * @internal
572
- * @reference {@link RegleStatus}
573
- */
574
- interface $InternalRegleStatus extends RegleCommonStatus {
575
- $fields: {
576
- [x: string]: $InternalRegleStatusType;
577
- };
578
- }
579
321
  /**
580
322
  * @public
581
323
  */
582
- type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? RegleCollectionStatus<TRule['$each'], TState[TKey]> : TRule extends ReglePartialValidationTree<any> ? TState[TKey] extends Array<any> ? RegleCommonStatus<TState[TKey]> : RegleStatus<TState[TKey], TRule> : RegleFieldStatus<TRule, TState, TKey>;
583
- /**
584
- * @internal
585
- * @reference {@link InferRegleStatusType}
586
- */
587
- type $InternalRegleStatusType = $InternalRegleCollectionStatus | RegleCommonStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
324
+ type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? NonNullable<TState[TKey]> extends Array<Record<string, any> | any> ? RegleCollectionStatus<TRule['$each'], TState[TKey]> : RegleFieldStatus<TRule, TState, TKey> : TRule extends ReglePartialValidationTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleCommonStatus<TState[TKey]> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? RegleStatus<TState[TKey], TRule> : RegleFieldStatus<TRule, TState, TKey> : RegleFieldStatus<TRule, TState, TKey>;
588
325
  /**
589
326
  * @public
590
327
  */
591
328
  interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus<TState> {
592
- $value: TState[TKey];
329
+ $value: UnwrapNestedRefs<TState[TKey]>;
593
330
  readonly $externalErrors?: string[];
594
331
  readonly $rules: {
595
332
  readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
596
333
  };
597
334
  }
598
- /**
599
- * @internal
600
- * @reference {@link RegleFieldStatus}
601
- */
602
- interface $InternalRegleFieldStatus extends RegleCommonStatus {
603
- $value: any;
604
- $rules: Record<string, $InternalRegleRuleStatus>;
605
- $externalErrors?: string[];
606
- }
607
335
  /**
608
336
  * @public
609
337
  */
@@ -614,8 +342,8 @@ interface RegleCommonStatus<TValue = any> {
614
342
  readonly $anyDirty: boolean;
615
343
  readonly $pending: boolean;
616
344
  readonly $error: boolean;
617
- $id?: string;
618
- $value: TValue;
345
+ $id?: number;
346
+ $value: UnwrapNestedRefs<TValue>;
619
347
  $touch(): void;
620
348
  $reset(): void;
621
349
  $validate(): Promise<boolean>;
@@ -635,47 +363,16 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
635
363
  readonly $path: string;
636
364
  $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
637
365
  $validate(): Promise<boolean>;
366
+ $reset(): void;
638
367
  } & ([TParams] extends [[]] ? {} : {
639
368
  readonly $params: TParams;
640
369
  });
641
- /**
642
- * @internal
643
- * @reference {@link RegleRuleStatus}
644
- */
645
- interface $InternalRegleRuleStatus {
646
- $type: string;
647
- $message: string | string[];
648
- $active: boolean;
649
- $valid: boolean;
650
- $pending: boolean;
651
- $path: string;
652
- $externalErrors?: string[];
653
- $params?: any[];
654
- $validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
655
- $validate(): Promise<boolean>;
656
- $unwatch(): void;
657
- $watch(): void;
658
- }
659
370
  /**
660
371
  * @public
661
372
  */
662
373
  interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
663
374
  readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
664
375
  }
665
- /**
666
- * @internal
667
- * @reference {@link RegleCollectionStatus}
668
- */
669
- interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields'> {
670
- $each: Array<$InternalRegleStatusType>;
671
- $rules?: Record<string, $InternalRegleRuleStatus>;
672
- /** Track each array state */
673
- $unwatch(): void;
674
- $watch(): void;
675
- $fields?: {
676
- [x: string]: $InternalRegleStatusType;
677
- };
678
- }
679
376
 
680
377
  /**
681
378
  * @description
@@ -697,7 +394,8 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
697
394
  * // Create a simple rule with no params
698
395
  * import {ruleHelpers} from '@regle/validators';
699
396
  *
700
- * export const isFoo = createRule<string>({
397
+ * export const isFoo = createRule({
398
+ * type: defineType<string>('foo'),
701
399
  * validator(value) {
702
400
  * if (ruleHelpers.isFilled(value)) {
703
401
  * return value === 'foo';
@@ -720,7 +418,7 @@ declare function defineType<TValue extends any = unknown, TParams extends any[]
720
418
  */
721
419
  declare function unwrapRuleParameters<TParams extends any[]>(params: ParamDecl[]): TParams;
722
420
 
723
- declare const useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations>>, TValid = keyof TRules extends keyof TState ? true : false>(state: Ref<TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState>) | undefined) => Regle<TState, TRules>;
421
+ declare const useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations>>, TExternal extends RegleExternalErrorTree<TState>, TValid = keyof TRules extends keyof TState ? true : false>(state: Ref<TState, TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState, TExternal>) | undefined) => Regle<TState, TRules, TExternal>;
724
422
 
725
423
  /**
726
424
  * Root function that allows you to define project-wise all your custom validators or overwrite default ones
@@ -732,6 +430,6 @@ declare const useRegle: <TState extends Record<string, any>, TRules extends Regl
732
430
  declare function defineRegleConfig<TCustomRules extends Partial<AllRulesDeclarations>>({ rules, options, }: {
733
431
  rules?: () => TCustomRules;
734
432
  options?: RegleBehaviourOptions;
735
- }): <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations> & TCustomRules>, TValid = keyof TRules extends keyof TState ? true : false>(state: vue.Ref<TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | vue.ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState>) | undefined) => Regle<TState, TRules>;
433
+ }): <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations> & TCustomRules>, TExternal extends RegleExternalErrorTree<TState>, TValid = keyof TRules extends keyof TState ? true : false>(state: Ref<TState, TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState, TExternal>) | undefined) => Regle<TState, TRules, TExternal>;
736
434
 
737
- export { type $InternalExternalRegleErrors, type $InternalFormPropertyTypes, type $InternalRegleCollectionRuleDecl, type $InternalRegleCollectionStatus, type $InternalRegleErrors, type $InternalRegleFieldStatus, type $InternalReglePartialValidationTree, type $InternalRegleRuleDecl, type $InternalRegleRuleDefinition, type $InternalRegleRuleInit, type $InternalRegleRuleMetadataConsumer, type $InternalRegleRuleStatus, type $InternalRegleStatus, type $InternalRegleStatusType, type AddDollarToOptions, type AllRulesDeclarations, type ArrayElement, type CustomRulesDeclarationTree, type DataType, type DeepMaybeRef, type DeepReactiveState, type DeepSafeFormState, type ExcludeByType, type ExcludeFromTuple, type FieldRegleBehaviourOptions, type FilterDollarProperties, type FormRuleDeclaration, type InferRegleRule, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type MaybeNull, type ParamDecl, type PickDollarProperties, type PossibleRegleRuleMetadataConsumer, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalValidationErrors, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialValidationTree, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleWithParamsDefinition, type RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationTree, type ResolvedRegleBehaviourOptions, type SafeProperty, type UnrefTuple, type UnwrapRegleUniversalParams, createRule, defineRegleConfig, defineType, unwrapRuleParameters, useRegle };
435
+ export { type DeepMaybeRef, type FormRuleDeclaration, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type ParamDecl, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalValidationErrors, type RegleFieldStatus, type RegleFormPropertyType, type ReglePartialValidationTree, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleWithParamsDefinition, type RegleStatus, type RegleValidationTree, type UnwrapRegleUniversalParams, createRule, defineRegleConfig, defineType, unwrapRuleParameters, useRegle };