@regle/core 0.0.7 → 0.0.9

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 | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => 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>;
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
  */
@@ -108,7 +112,7 @@ type RegleRuleRaw<TValue extends any = any, TParams extends any[] = [], TAsync e
108
112
  */
109
113
  type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> = [TParams] extends [[]] ? RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> : RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
110
114
  type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
111
- type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<any, any>, TReturn = any> = (value: Maybe<TValue>, metadata: TMetadata) => TReturn;
115
+ type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<any, any>, TReturn = any> = ((value: Maybe<TValue>, metadata: TMetadata) => TReturn) | TReturn;
112
116
  type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
113
117
  $each: RegleFormPropertyType<ArrayElement<TValue>, TCustomRules>;
114
118
  }) | {
@@ -125,7 +129,7 @@ interface RegleRuleInit<TValue extends any, TParams extends any[], TReturn exten
125
129
  params: TParams;
126
130
  };
127
131
  validator: (value: Maybe<TValue>, ...args: TParams) => TReturn;
128
- message: string | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => string);
132
+ message: string | string[] | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => string | string[]);
129
133
  active?: boolean | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => boolean);
130
134
  }
131
135
  /**
@@ -134,7 +138,7 @@ interface RegleRuleInit<TValue extends any, TParams extends any[], TReturn exten
134
138
  */
135
139
  interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
136
140
  validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
137
- message: string | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => string);
141
+ message: string | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => string | string[]);
138
142
  active?: boolean | ((value: Maybe<TValue>, metadata: RegleRuleMetadataConsumer<TParams, TMetadata>) => boolean);
139
143
  type?: string;
140
144
  }
@@ -144,7 +148,7 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
144
148
  */
145
149
  interface $InternalRegleRuleInit {
146
150
  validator: (value: any, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
147
- message: string | ((value: any, metadata: $InternalRegleRuleMetadataConsumer) => string);
151
+ message: string | ((value: any, metadata: $InternalRegleRuleMetadataConsumer) => string | string[]);
148
152
  active?: boolean | ((value: any, metadata: $InternalRegleRuleMetadataConsumer) => boolean);
149
153
  type?: string;
150
154
  }
@@ -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,213 +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
- * @internal
191
- * @reference {@link ReglePartialValidationTree}
192
- */
193
- type $InternalReglePartialValidationTree = {
194
- [x: string]: $InternalFormPropertyTypes;
195
- };
196
- /**
197
- * @public
198
- */
199
- type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<unknown, 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>;
200
- /**
201
- * @internal
202
- * @reference {@link RegleFormPropertyType}
203
- */
204
- type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialValidationTree;
205
- /**
206
- * @public
207
- * Rule tree for a form property
208
- */
209
- type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = {
210
- [TKey in keyof TCustomRules]?: TCustomRules[TKey] extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, TParams> : FormRuleDeclaration<TValue, any>;
211
- };
212
- /**
213
- * @internal
214
- * @reference {@link RegleRuleDecl}
215
- */
216
- type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any>>;
217
- /**
218
- * @public
219
- */
220
- type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
221
- $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
222
- }) | {
223
- $each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
224
- };
225
- /**
226
- * @internal
227
- * @reference {@link RegleCollectionRuleDecl}
228
- *
229
- */
230
- type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
231
- $each?: $InternalFormPropertyTypes;
232
- };
233
- /**
234
- * @public
235
- */
236
- type InlineRuleDeclaration<TValue extends any = any, TMetadata extends RegleRuleMetadataDefinition = boolean, TReturn extends TMetadata | Promise<TMetadata> = TMetadata, TAsync extends boolean = TReturn extends Promise<any> ? true : false> = (value: Maybe<TValue>, ...args: any[]) => TReturn;
237
- /**
238
- * @public
239
- */
240
- type InlinePromiseRuleDeclaration<TValue extends any = any, TMetadata extends RegleRuleMetadataDefinition = boolean> = (value: Maybe<TValue>, ...args: any[]) => Promise<TMetadata>;
241
- /**
242
- * @public
243
- * Regroup inline and registered rules
244
- * */
245
- type FormRuleDeclaration<TValue extends any, TParams extends any[] = [], TMetadata extends RegleRuleMetadataDefinition = boolean> = InlineRuleDeclaration<TValue, TMetadata> | RegleRuleDefinition<TValue, TParams, boolean, TMetadata>;
246
-
247
- type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
248
- readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
249
- };
250
- 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[];
251
- type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = {
252
- readonly $errors: string[];
253
- readonly $each: RegleValidationErrors<TRule>[];
254
- };
255
- /**
256
- * @internal
257
- */
258
- type $InternalRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
259
- type RegleExternalErrorTree<TState extends Record<string, any> = Record<string, any>> = {
260
- [K in keyof TState]?: RegleExternalValidationErrors<TState[K]>;
261
- };
262
- type RegleExternalValidationErrors<TValue extends any> = [NonNullable<TValue>] extends [
263
- never
264
- ] ? 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[];
265
- type RegleExternalCollectionErrors<TValue extends any = any> = {
266
- $errors?: string[];
267
- $each?: RegleExternalValidationErrors<TValue>[];
268
- };
269
- type $InternalExternalRegleErrors = RegleExternalCollectionErrors<any> | string[] | RegleExternalErrorTree<any>;
270
- type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
271
-
272
- /**
273
- * @public
274
- */
275
- interface RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>> extends RegleCommonStatus<TState> {
276
- readonly $fields: {
277
- readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
278
- };
279
- }
280
- /**
281
- * @internal
282
- * @reference {@link RegleStatus}
283
- */
284
- interface $InternalRegleStatus extends RegleCommonStatus {
285
- $fields: {
286
- [x: string]: $InternalRegleStatusType;
287
- };
288
- }
289
- /**
290
- * @public
291
- */
292
- 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>;
293
- /**
294
- * @internal
295
- * @reference {@link InferRegleStatusType}
296
- */
297
- type $InternalRegleStatusType = $InternalRegleCollectionStatus | RegleCommonStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
298
- /**
299
- * @public
300
- */
301
- interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus<TState> {
302
- $value: TState[TKey];
303
- readonly $externalErrors?: string[];
304
- readonly $rules: {
305
- readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
306
- };
307
- }
308
- /**
309
- * @internal
310
- * @reference {@link RegleFieldStatus}
311
- */
312
- interface $InternalRegleFieldStatus extends RegleCommonStatus {
313
- $value: any;
314
- $rules: Record<string, $InternalRegleRuleStatus>;
315
- $externalErrors?: string[];
316
- }
317
- /**
318
- * @public
319
- */
320
- interface RegleCommonStatus<TValue = any> {
321
- readonly $valid: boolean;
322
- readonly $invalid: boolean;
323
- readonly $dirty: boolean;
324
- readonly $anyDirty: boolean;
325
- readonly $pending: boolean;
326
- readonly $error: boolean;
327
- $id?: string;
328
- $value: TValue;
329
- $touch(): void;
330
- $reset(): void;
331
- $validate(): Promise<boolean>;
332
- $unwatch(): void;
333
- $watch(): void;
334
- $clearExternalErrors(): void;
335
- }
336
- /**
337
- * @public
338
- */
339
- type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
340
- readonly $type: string;
341
- readonly $message: string;
342
- readonly $active: boolean;
343
- readonly $valid: boolean;
344
- readonly $pending: boolean;
345
- readonly $path: string;
346
- $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
347
- $validate(): Promise<boolean>;
348
- } & ([TParams] extends [[]] ? {} : {
349
- readonly $params: TParams;
350
- });
351
- /**
352
- * @internal
353
- * @reference {@link RegleRuleStatus}
354
- */
355
- interface $InternalRegleRuleStatus {
356
- $type: string;
357
- $message: string;
358
- $active: boolean;
359
- $valid: boolean;
360
- $pending: boolean;
361
- $path: string;
362
- $externalErrors?: string[];
363
- $params?: any[];
364
- $validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
365
- $validate(): Promise<boolean>;
366
- $unwatch(): void;
367
- $watch(): void;
368
- }
369
- /**
370
- * @public
371
- */
372
- interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
373
- readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
374
- }
375
- /**
376
- * @internal
377
- * @reference {@link RegleCollectionStatus}
378
- */
379
- interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields'> {
380
- $each: Array<$InternalRegleStatusType>;
381
- $rules?: Record<string, $InternalRegleRuleStatus>;
382
- /** Track each array state */
383
- $unwatch(): void;
384
- $watch(): void;
385
- $fields?: {
386
- [x: string]: $InternalRegleStatusType;
387
- };
388
- }
389
-
390
185
  /**
391
186
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
392
187
 
@@ -651,13 +446,236 @@ interface RegleBehaviourOptions {
651
446
  /**
652
447
  * The fields will turn valid when they are, but not invalid unless calling `validateForm()`
653
448
  * @default false
449
+ *
450
+ * @experimental report any bug
654
451
  */
655
452
  rewardEarly?: boolean;
656
453
  }
657
454
  interface LocalRegleBehaviourOptions<TState extends Record<string, any>> {
658
455
  $externalErrors?: MaybeRef<RegleExternalErrorTree<TState>>;
659
456
  }
660
- 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
+ }
661
679
 
662
680
  /**
663
681
  * @description
@@ -690,7 +708,7 @@ type ResolvedRegleBehaviourOptions = DeepMaybeRef$1<RequiredDeep<RegleBehaviourO
690
708
  * })
691
709
  * ```
692
710
  */
693
- declare function createRule<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetaData extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(definition: RegleRuleInit<TValue, TParams, TReturn, TMetaData, TAsync>): InferRegleRule<TValue, TParams, TAsync, TMetaData>;
711
+ declare function createRule<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(definition: RegleRuleInit<TValue, TParams, TReturn, TMetadata, TAsync>): InferRegleRule<TValue, TParams, TAsync, TMetadata>;
694
712
  declare function defineType<TValue extends any = unknown, TParams extends any[] = []>(ruleName: string): {
695
713
  value: TValue;
696
714
  params: TParams;
@@ -702,7 +720,7 @@ declare function defineType<TValue extends any = unknown, TParams extends any[]
702
720
  */
703
721
  declare function unwrapRuleParameters<TParams extends any[]>(params: ParamDecl[]): TParams;
704
722
 
705
- 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>;
706
724
 
707
725
  /**
708
726
  * Root function that allows you to define project-wise all your custom validators or overwrite default ones
@@ -714,6 +732,6 @@ declare const useRegle: <TState extends Record<string, any>, TRules extends Regl
714
732
  declare function defineRegleConfig<TCustomRules extends Partial<AllRulesDeclarations>>({ rules, options, }: {
715
733
  rules?: () => TCustomRules;
716
734
  options?: RegleBehaviourOptions;
717
- }): <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>;
718
736
 
719
- 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 InlinePromiseRuleDeclaration, 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 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 };