@regle/core 0.0.8 → 0.0.10

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.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import * as vue from 'vue';
2
2
  import { MaybeRef, Ref, ComputedRef } from 'vue';
3
- import { DeepMaybeRef as DeepMaybeRef$1 } from 'types/utils';
4
- import { DeepReactiveState as DeepReactiveState$1 } from 'types/core/useRegle.types';
5
3
 
6
4
  type ArrayElement<T> = T extends Array<infer U> ? U : never;
7
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>] : [];
@@ -38,8 +36,8 @@ type UnwrapRegleUniversalParams<T extends ParamDecl[] = [], F = CreateFn<T>> = [
38
36
  */
39
37
  interface RegleInternalRuleDefs<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
40
38
  _validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
41
- _message: string | string[] | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => string | string[]);
42
- _active?: boolean | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => boolean);
39
+ _message: string | string[] | ((value: Maybe<TValue>, metadata: PossibleRegleRuleMetadataConsumer) => string | string[]);
40
+ _active?: boolean | ((value: Maybe<TValue>, metadata: PossibleRegleRuleMetadataConsumer) => boolean);
43
41
  _type?: string;
44
42
  _patched: boolean;
45
43
  _params?: RegleUniversalParams<TParams>;
@@ -53,10 +51,10 @@ declare enum InternalRuleType {
53
51
  /**
54
52
  * Returned typed of rules created with `createRule`
55
53
  * */
56
- interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> extends RegleInternalRuleDefs<TValue, TParams, TAsync, TMetaData> {
54
+ interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition> extends RegleInternalRuleDefs<TValue, TParams, TAsync, TMetaData> {
57
55
  validator: RegleRuleDefinitionProcessor<TValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
58
- message: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TParams, TMetaData>, string | string[]>;
59
- active: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TParams, TMetaData>, boolean>;
56
+ message: RegleRuleDefinitionWithMetadataProcessor<TValue, PossibleRegleRuleMetadataConsumer, string | string[]>;
57
+ active: RegleRuleDefinitionWithMetadataProcessor<TValue, PossibleRegleRuleMetadataConsumer, boolean>;
60
58
  type?: string;
61
59
  exec: (value: Maybe<TValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
62
60
  }
@@ -90,6 +88,12 @@ type DefaultMetadataProperties = Pick<ExcludeByType<RegleCommonStatus, Function>
90
88
  type RegleRuleMetadataConsumer<TParams extends any[] = [], TMetadata extends RegleRuleMetadataDefinition = boolean> = DefaultMetadataProperties & (TParams extends never ? {} : {
91
89
  $params: TParams;
92
90
  }) & (TMetadata extends boolean ? {} : Omit<TMetadata, '$valid'>);
91
+ /**
92
+ * Will be used to consumme metadata on related helpers and rule status
93
+ */
94
+ type PossibleRegleRuleMetadataConsumer = DefaultMetadataProperties & {
95
+ $params?: any[];
96
+ };
93
97
  /**
94
98
  * @internal
95
99
  */
@@ -152,8 +156,6 @@ interface $InternalRegleRuleInit {
152
156
  type DefaultValidators = {
153
157
  maxLength: RegleRuleWithParamsDefinition<string, [count: number]>;
154
158
  required: RegleRuleDefinition<unknown, []>;
155
- requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
156
- requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
157
159
  alpha: RegleRuleDefinition<string>;
158
160
  alphaNum: RegleRuleDefinition<string | number>;
159
161
  between: RegleRuleWithParamsDefinition<number, [min: number, max: number]>;
@@ -180,215 +182,6 @@ type CustomRulesDeclarationTree = {
180
182
  };
181
183
  type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidators;
182
184
 
183
- /**
184
- * @public
185
- */
186
- type ReglePartialValidationTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
187
- [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
188
- };
189
- /**
190
- * @public
191
- */
192
- type RegleValidationTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
193
- [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules>;
194
- };
195
- /**
196
- * @internal
197
- * @reference {@link ReglePartialValidationTree}
198
- */
199
- type $InternalReglePartialValidationTree = {
200
- [x: string]: $InternalFormPropertyTypes;
201
- };
202
- /**
203
- * @public
204
- */
205
- 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>;
206
- /**
207
- * @internal
208
- * @reference {@link RegleFormPropertyType}
209
- */
210
- type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialValidationTree;
211
- /**
212
- * @public
213
- * Rule tree for a form property
214
- */
215
- type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
216
- [TKey in keyof TCustomRules]?: TCustomRules[TKey] extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, TParams> : FormRuleDeclaration<TValue, any, any, any>;
217
- };
218
- /**
219
- * @internal
220
- * @reference {@link RegleRuleDecl}
221
- */
222
- type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any, any, any>>;
223
- /**
224
- * @public
225
- */
226
- type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
227
- $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
228
- }) | {
229
- $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
230
- };
231
- /**
232
- * @internal
233
- * @reference {@link RegleCollectionRuleDecl}
234
- *
235
- */
236
- type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
237
- $each?: $InternalFormPropertyTypes;
238
- };
239
- /**
240
- * @public
241
- */
242
- type InlineRuleDeclaration<TValue extends any, TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition, TAsync extends boolean = TReturn extends Promise<any> ? true : false> = (value: Maybe<TValue>, ...args: any[]) => TReturn;
243
- /**
244
- * @public
245
- * Regroup inline and registered rules
246
- * */
247
- type FormRuleDeclaration<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, TAsync extends boolean = TReturn extends Promise<any> ? true : false> = InlineRuleDeclaration<TValue, TReturn, TMetadata, TAsync> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
248
-
249
- type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
250
- readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
251
- };
252
- 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[];
253
- type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = {
254
- readonly $errors: string[];
255
- readonly $each: RegleValidationErrors<TRule>[];
256
- };
257
- /**
258
- * @internal
259
- */
260
- type $InternalRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
261
- type RegleExternalErrorTree<TState extends Record<string, any> = Record<string, any>> = {
262
- [K in keyof TState]?: RegleExternalValidationErrors<TState[K]>;
263
- };
264
- type RegleExternalValidationErrors<TValue extends any> = [NonNullable<TValue>] extends [
265
- never
266
- ] ? string[] : TValue extends Array<infer U> ? RegleExternalCollectionErrors<U> : NonNullable<TValue> extends Date ? string[] : NonNullable<TValue> extends File ? string[] : TValue extends Record<string, any> ? RegleExternalErrorTree<TValue> : string[];
267
- type RegleExternalCollectionErrors<TValue extends any = any> = {
268
- $errors?: string[];
269
- $each?: RegleExternalValidationErrors<TValue>[];
270
- };
271
- type $InternalExternalRegleErrors = RegleExternalCollectionErrors<any> | string[] | RegleExternalErrorTree<any>;
272
- type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
273
-
274
- /**
275
- * @public
276
- */
277
- interface RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>> extends RegleCommonStatus<TState> {
278
- readonly $fields: {
279
- readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
280
- };
281
- }
282
- /**
283
- * @internal
284
- * @reference {@link RegleStatus}
285
- */
286
- interface $InternalRegleStatus extends RegleCommonStatus {
287
- $fields: {
288
- [x: string]: $InternalRegleStatusType;
289
- };
290
- }
291
- /**
292
- * @public
293
- */
294
- 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>;
295
- /**
296
- * @internal
297
- * @reference {@link InferRegleStatusType}
298
- */
299
- type $InternalRegleStatusType = $InternalRegleCollectionStatus | RegleCommonStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
300
- /**
301
- * @public
302
- */
303
- interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus<TState> {
304
- $value: TState[TKey];
305
- readonly $externalErrors?: string[];
306
- readonly $rules: {
307
- readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
308
- };
309
- }
310
- /**
311
- * @internal
312
- * @reference {@link RegleFieldStatus}
313
- */
314
- interface $InternalRegleFieldStatus extends RegleCommonStatus {
315
- $value: any;
316
- $rules: Record<string, $InternalRegleRuleStatus>;
317
- $externalErrors?: string[];
318
- }
319
- /**
320
- * @public
321
- */
322
- interface RegleCommonStatus<TValue = any> {
323
- readonly $valid: boolean;
324
- readonly $invalid: boolean;
325
- readonly $dirty: boolean;
326
- readonly $anyDirty: boolean;
327
- readonly $pending: boolean;
328
- readonly $error: boolean;
329
- $id?: string;
330
- $value: TValue;
331
- $touch(): void;
332
- $reset(): void;
333
- $validate(): Promise<boolean>;
334
- $unwatch(): void;
335
- $watch(): void;
336
- $clearExternalErrors(): void;
337
- }
338
- /**
339
- * @public
340
- */
341
- type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
342
- readonly $type: string;
343
- readonly $message: string | string[];
344
- readonly $active: boolean;
345
- readonly $valid: boolean;
346
- readonly $pending: boolean;
347
- readonly $path: string;
348
- $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
349
- $validate(): Promise<boolean>;
350
- } & ([TParams] extends [[]] ? {} : {
351
- readonly $params: TParams;
352
- });
353
- /**
354
- * @internal
355
- * @reference {@link RegleRuleStatus}
356
- */
357
- interface $InternalRegleRuleStatus {
358
- $type: string;
359
- $message: string | string[];
360
- $active: boolean;
361
- $valid: boolean;
362
- $pending: boolean;
363
- $path: string;
364
- $externalErrors?: string[];
365
- $params?: any[];
366
- $validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
367
- $validate(): Promise<boolean>;
368
- $unwatch(): void;
369
- $watch(): void;
370
- }
371
- /**
372
- * @public
373
- */
374
- interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
375
- readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
376
- }
377
- /**
378
- * @internal
379
- * @reference {@link RegleCollectionStatus}
380
- */
381
- interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields'> {
382
- $each: Array<$InternalRegleStatusType>;
383
- $rules?: Record<string, $InternalRegleRuleStatus>;
384
- /** Track each array state */
385
- $unwatch(): void;
386
- $watch(): void;
387
- $fields?: {
388
- [x: string]: $InternalRegleStatusType;
389
- };
390
- }
391
-
392
185
  /**
393
186
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
394
187
 
@@ -653,13 +446,236 @@ interface RegleBehaviourOptions {
653
446
  /**
654
447
  * The fields will turn valid when they are, but not invalid unless calling `validateForm()`
655
448
  * @default false
449
+ *
450
+ * @experimental report any bug
656
451
  */
657
452
  rewardEarly?: boolean;
658
453
  }
659
454
  interface LocalRegleBehaviourOptions<TState extends Record<string, any>> {
660
455
  $externalErrors?: MaybeRef<RegleExternalErrorTree<TState>>;
661
456
  }
662
- type ResolvedRegleBehaviourOptions = DeepMaybeRef$1<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>>;
457
+ type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
458
+ $debounce?: number;
459
+ };
460
+ type ResolvedRegleBehaviourOptions = DeepMaybeRef<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>>;
461
+ type AddDollarToOptions<T extends Record<string, any>> = {
462
+ [K in keyof T as `$${string & K}`]: T[K];
463
+ };
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
+
471
+ /**
472
+ * @public
473
+ */
474
+ type ReglePartialValidationTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
475
+ [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
476
+ };
477
+ /**
478
+ * @public
479
+ */
480
+ type RegleValidationTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
481
+ [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules>;
482
+ };
483
+ /**
484
+ * @internal
485
+ * @reference {@link ReglePartialValidationTree}
486
+ */
487
+ type $InternalReglePartialValidationTree = {
488
+ [x: string]: $InternalFormPropertyTypes;
489
+ };
490
+ /**
491
+ * @public
492
+ */
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;
499
+ /**
500
+ * @public
501
+ * Rule tree for a form property
502
+ */
503
+ type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = FieldRegleBehaviourOptions & {
504
+ [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
+ };
506
+ /**
507
+ * @internal
508
+ * @reference {@link RegleRuleDecl}
509
+ */
510
+ type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any>>;
511
+ /**
512
+ * @public
513
+ */
514
+ type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
515
+ $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
516
+ }) | {
517
+ $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
518
+ };
519
+ /**
520
+ * @internal
521
+ * @reference {@link RegleCollectionRuleDecl}
522
+ *
523
+ */
524
+ type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
525
+ $each?: $InternalFormPropertyTypes;
526
+ };
527
+ /**
528
+ * @public
529
+ */
530
+ type InlineRuleDeclaration<TValue extends any, TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>> = (value: Maybe<TValue>, ...args: any[]) => TReturn;
531
+ /**
532
+ * @public
533
+ * Regroup inline and registered rules
534
+ * */
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>;
536
+
537
+ type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
538
+ readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
539
+ };
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> = {
542
+ readonly $errors: string[];
543
+ readonly $each: RegleValidationErrors<TRule>[];
544
+ };
545
+ /**
546
+ * @internal
547
+ */
548
+ type $InternalRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
549
+ type RegleExternalErrorTree<TState extends Record<string, any> = Record<string, any>> = {
550
+ [K in keyof TState]?: RegleExternalValidationErrors<TState[K]>;
551
+ };
552
+ type RegleExternalValidationErrors<TValue extends any> = [NonNullable<TValue>] extends [
553
+ never
554
+ ] ? string[] : TValue extends Array<infer U> ? RegleExternalCollectionErrors<U> : NonNullable<TValue> extends Date ? string[] : NonNullable<TValue> extends File ? string[] : TValue extends Record<string, any> ? RegleExternalErrorTree<TValue> : string[];
555
+ type RegleExternalCollectionErrors<TValue extends any = any> = {
556
+ $errors?: string[];
557
+ $each?: RegleExternalValidationErrors<TValue>[];
558
+ };
559
+ type $InternalExternalRegleErrors = RegleExternalCollectionErrors<any> | string[] | RegleExternalErrorTree<any>;
560
+ type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
561
+
562
+ /**
563
+ * @public
564
+ */
565
+ interface RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>> extends RegleCommonStatus<TState> {
566
+ readonly $fields: {
567
+ readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
568
+ };
569
+ }
570
+ /**
571
+ * @internal
572
+ * @reference {@link RegleStatus}
573
+ */
574
+ interface $InternalRegleStatus extends RegleCommonStatus {
575
+ $fields: {
576
+ [x: string]: $InternalRegleStatusType;
577
+ };
578
+ }
579
+ /**
580
+ * @public
581
+ */
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;
588
+ /**
589
+ * @public
590
+ */
591
+ 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];
593
+ readonly $externalErrors?: string[];
594
+ readonly $rules: {
595
+ readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
596
+ };
597
+ }
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
+ /**
608
+ * @public
609
+ */
610
+ interface RegleCommonStatus<TValue = any> {
611
+ readonly $valid: boolean;
612
+ readonly $invalid: boolean;
613
+ readonly $dirty: boolean;
614
+ readonly $anyDirty: boolean;
615
+ readonly $pending: boolean;
616
+ readonly $error: boolean;
617
+ $id?: string;
618
+ $value: TValue;
619
+ $touch(): void;
620
+ $reset(): void;
621
+ $validate(): Promise<boolean>;
622
+ $unwatch(): void;
623
+ $watch(): void;
624
+ $clearExternalErrors(): void;
625
+ }
626
+ /**
627
+ * @public
628
+ */
629
+ type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
630
+ readonly $type: string;
631
+ readonly $message: string | string[];
632
+ readonly $active: boolean;
633
+ readonly $valid: boolean;
634
+ readonly $pending: boolean;
635
+ readonly $path: string;
636
+ $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
637
+ $validate(): Promise<boolean>;
638
+ } & ([TParams] extends [[]] ? {} : {
639
+ readonly $params: TParams;
640
+ });
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
+ /**
660
+ * @public
661
+ */
662
+ interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
663
+ readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
664
+ }
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
+ }
663
679
 
664
680
  /**
665
681
  * @description
@@ -704,7 +720,7 @@ declare function defineType<TValue extends any = unknown, TParams extends any[]
704
720
  */
705
721
  declare function unwrapRuleParameters<TParams extends any[]>(params: ParamDecl[]): TParams;
706
722
 
707
- declare const useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations>>>(state: Ref<TState> | DeepReactiveState$1<TState>, rulesFactory: ComputedRef<TRules> | (() => TRules), options?: (Partial<DeepMaybeRef$1<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState>) | undefined) => Regle<TState, TRules>;
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>;
708
724
 
709
725
  /**
710
726
  * Root function that allows you to define project-wise all your custom validators or overwrite default ones
@@ -716,6 +732,6 @@ declare const useRegle: <TState extends Record<string, any>, TRules extends Regl
716
732
  declare function defineRegleConfig<TCustomRules extends Partial<AllRulesDeclarations>>({ rules, options, }: {
717
733
  rules?: () => TCustomRules;
718
734
  options?: RegleBehaviourOptions;
719
- }): <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations> & TCustomRules>>(state: vue.Ref<TState> | DeepReactiveState<TState>, rulesFactory: vue.ComputedRef<TRules> | (() => TRules), options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState>) | undefined) => Regle<TState, TRules>;
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>;
720
736
 
721
- 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 AllRulesDeclarations, type ArrayElement, type CustomRulesDeclarationTree, type DataType, type DeepMaybeRef, type ExcludeByType, type ExcludeFromTuple, type FormRuleDeclaration, type InferRegleRule, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type MaybeNull, type ParamDecl, 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 UnrefTuple, type UnwrapRegleUniversalParams, createRule, defineRegleConfig, defineType, unwrapRuleParameters, useRegle };
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 };