@regle/core 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { MaybeRef, Ref, UnwrapRef, UnwrapNestedRefs, MaybeRefOrGetter } from 'vue';
1
+ import { MaybeRef, Ref, UnwrapRef, UnwrapNestedRefs, MaybeRefOrGetter, ComputedRef } from 'vue';
2
2
 
3
3
  type Prettify<T> = T extends infer R ? {
4
4
  [K in keyof R]: R[K];
@@ -78,6 +78,23 @@ Matches any primitive, `void`, `Date`, or `RegExp` value.
78
78
  */
79
79
  type BuiltIns = Primitive | void | Date | RegExp;
80
80
 
81
+ /**
82
+ Test if the given function has multiple call signatures.
83
+
84
+ Needed to handle the case of a single call signature with properties.
85
+
86
+ Multiple call signatures cannot currently be supported due to a TypeScript limitation.
87
+ @see https://github.com/microsoft/TypeScript/issues/29732
88
+ */
89
+ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
90
+ T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
91
+ ? B extends A
92
+ ? A extends B
93
+ ? false
94
+ : true
95
+ : true
96
+ : false;
97
+
81
98
  /**
82
99
  @see PartialDeep
83
100
  */
@@ -186,6 +203,83 @@ type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOpt
186
203
  [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
187
204
  };
188
205
 
206
+ type ExcludeUndefined<T> = Exclude<T, undefined>;
207
+
208
+ /**
209
+ Create a type from another type with all keys and nested keys set to required.
210
+
211
+ Use-cases:
212
+ - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
213
+ - Modeling the resulting type after a deep merge with a set of defaults.
214
+
215
+ @example
216
+ ```
217
+ import type {RequiredDeep} from 'type-fest';
218
+
219
+ type Settings = {
220
+ textEditor?: {
221
+ fontSize?: number | undefined;
222
+ fontColor?: string | undefined;
223
+ fontWeight?: number | undefined;
224
+ }
225
+ autocomplete?: boolean | undefined;
226
+ autosave?: boolean | undefined;
227
+ };
228
+
229
+ type RequiredSettings = RequiredDeep<Settings>;
230
+ // type RequiredSettings = {
231
+ // textEditor: {
232
+ // fontSize: number;
233
+ // fontColor: string;
234
+ // fontWeight: number;
235
+ // }
236
+ // autocomplete: boolean;
237
+ // autosave: boolean;
238
+ // }
239
+ ```
240
+
241
+ Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
242
+
243
+ @category Utilities
244
+ @category Object
245
+ @category Array
246
+ @category Set
247
+ @category Map
248
+ */
249
+ type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
250
+ ? E
251
+ : E extends Map<infer KeyType, infer ValueType>
252
+ ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
253
+ : E extends Set<infer ItemType>
254
+ ? Set<RequiredDeep<ItemType>>
255
+ : E extends ReadonlyMap<infer KeyType, infer ValueType>
256
+ ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
257
+ : E extends ReadonlySet<infer ItemType>
258
+ ? ReadonlySet<RequiredDeep<ItemType>>
259
+ : E extends WeakMap<infer KeyType, infer ValueType>
260
+ ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
261
+ : E extends WeakSet<infer ItemType>
262
+ ? WeakSet<RequiredDeep<ItemType>>
263
+ : E extends Promise<infer ValueType>
264
+ ? Promise<RequiredDeep<ValueType>>
265
+ : E extends (...arguments_: any[]) => unknown
266
+ ? {} extends RequiredObjectDeep<E>
267
+ ? E
268
+ : HasMultipleCallSignatures<E> extends true
269
+ ? E
270
+ : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
271
+ : E extends object
272
+ ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
273
+ ? ItemType[] extends E // Test for arrays (non-tuples) specifically
274
+ ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
275
+ : RequiredObjectDeep<E> // Tuples behave properly
276
+ : RequiredObjectDeep<E>
277
+ : unknown;
278
+
279
+ type RequiredObjectDeep<ObjectType extends object> = {
280
+ [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
281
+ };
282
+
189
283
  /**
190
284
  Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
191
285
 
@@ -231,7 +325,7 @@ type Intersection = UnionToIntersection<Union>;
231
325
 
232
326
  @category Type
233
327
  */
234
- type UnionToIntersection<Union> = (
328
+ type UnionToIntersection$1<Union> = (
235
329
  // `extends unknown` is always going to be the case and is used to convert the
236
330
  // `Union` into a [distributive conditional
237
331
  // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
@@ -289,6 +383,7 @@ interface RegleValidationGroupOutput {
289
383
  type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
290
384
  $debounce?: number;
291
385
  };
386
+ type ResolvedRegleBehaviourOptions = DeepMaybeRef<RequiredDeep<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, Record<string, any>, Record<string, any[]>>;
292
387
  type ShortcutCommonFn<T extends Record<string, any>> = {
293
388
  [x: string]: (element: OmitByType<T, Function>) => unknown;
294
389
  };
@@ -307,7 +402,7 @@ interface Regle<TState extends Record<string, any> = EmptyObject, TRules extends
307
402
  type isDeepExact<T, U> = {
308
403
  [K in keyof T]-?: CheckDeepExact<NonNullable<T[K]>, K extends keyof U ? NonNullable<U[K]> : never>;
309
404
  }[keyof T] extends true ? true : false;
310
- type CheckDeepExact<T, U> = [U] extends [never] ? false : T extends RegleCollectionRuleDecl ? U extends RegleCollectionRuleDecl ? isDeepExact<NonNullable<T['$each']>, UnionToIntersection<NonNullable<U['$each']>>> : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false;
405
+ type CheckDeepExact<T, U> = [U] extends [never] ? false : T extends RegleCollectionRuleDecl ? U extends RegleCollectionRuleDecl ? isDeepExact<NonNullable<T['$each']>, UnionToIntersection$1<NonNullable<U['$each']>>> : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false;
311
406
  type DeepReactiveState<T extends Record<string, any>> = {
312
407
  [K in keyof T]: MaybeRef<T[K]>;
313
408
  };
@@ -327,7 +422,7 @@ type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, a
327
422
  ] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
328
423
  type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? Maybe<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? Maybe<TState> : Maybe<TState> : Maybe<TState> : Maybe<TState>;
329
424
 
330
- type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> = <TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = isDeepExact<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>> extends true ? {} : never>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Unwrap<TState>, TRules, TValidationGroups>) => Regle<Unwrap<TState>, TRules, TValidationGroups, TShortcuts>;
425
+ type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> = <TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = isDeepExact<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>> extends true ? {} : MismatchInfo<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Unwrap<TState>, TRules, TValidationGroups>) => Regle<Unwrap<TState>, TRules, TValidationGroups, TShortcuts>;
331
426
  declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>>;
332
427
 
333
428
  interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
@@ -336,6 +431,17 @@ interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
336
431
  }
337
432
  declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
338
433
 
434
+ declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, }: {
435
+ scopeRules: ComputedRef<$InternalReglePartialRuleTree>;
436
+ state: Ref<Record<string, any>>;
437
+ options: ResolvedRegleBehaviourOptions;
438
+ initialState: Record<string, any>;
439
+ customRules?: () => CustomRulesDeclarationTree;
440
+ shortcuts: RegleShortcutDefinition | undefined;
441
+ }): {
442
+ regle: $InternalRegleStatus | undefined;
443
+ };
444
+
339
445
  type InferRegleRoot<T extends (...args: any[]) => Regle<any, any, any, any>> = T extends (...args: any[]) => infer U ? U extends Regle<any, any, any, any> ? Prettify<U['r$']> : never : never;
340
446
  type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<U> & Partial<DefaultValidators>> : {};
341
447
  type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
@@ -346,6 +452,451 @@ type RegleEnforceCustomRequiredRules<T extends Partial<AllRulesDeclarations> | u
346
452
  [K in TRules]-?: T extends useRegleFn<any> ? K extends keyof InferRegleRules<T> ? NonNullable<InferRegleRules<T>[K]> : never : K extends keyof T ? NonNullable<T[K]> : never;
347
453
  };
348
454
 
455
+ /**
456
+ * Negates a boolean type.
457
+ */
458
+ type Not<T extends boolean> = T extends true ? false : true;
459
+ /**
460
+ * Checks if all the boolean types in the {@linkcode Types} array are `true`.
461
+ */
462
+ type And<Types extends boolean[]> = Types[number] extends true ? true : false;
463
+ /**
464
+ * @internal
465
+ */
466
+ declare const secret: unique symbol;
467
+ /**
468
+ * @internal
469
+ */
470
+ type Secret = typeof secret;
471
+ /**
472
+ * Checks if the given type is `never`.
473
+ */
474
+ type IsNever<T> = [T] extends [never] ? true : false;
475
+ /**
476
+ * Checks if the given type is `any`.
477
+ */
478
+ type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
479
+ /**
480
+ * Determines if the given type is `unknown`.
481
+ */
482
+ type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
483
+ /**
484
+ * Subjective "useful" keys from a type. For objects it's just `keyof` but for
485
+ * tuples/arrays it's the number keys.
486
+ *
487
+ * @example
488
+ * ```ts
489
+ * UsefulKeys<{ a: 1; b: 2 }> // 'a' | 'b'
490
+ *
491
+ * UsefulKeys<['a', 'b']> // '0' | '1'
492
+ *
493
+ * UsefulKeys<string[]> // number
494
+ * ```
495
+ */
496
+ type UsefulKeys<T> = T extends any[] ? {
497
+ [K in keyof T]: K;
498
+ }[number] : keyof T;
499
+ /**
500
+ * Extracts the keys from a type that are required (not optional).
501
+ */
502
+ type RequiredKeys<T> = Extract<{
503
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
504
+ }[keyof T], keyof T>;
505
+ /**
506
+ * Gets the keys of an object type that are optional.
507
+ */
508
+ type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
509
+ /**
510
+ * Extracts the keys from a type that are not `readonly`.
511
+ */
512
+ type ReadonlyKeys<T> = Extract<{
513
+ [K in keyof T]-?: ReadonlyEquivalent<{
514
+ [_K in K]: T[K];
515
+ }, {
516
+ -readonly [_K in K]: T[K];
517
+ }> extends true ? never : K;
518
+ }[keyof T], keyof T>;
519
+ /**
520
+ * Determines if two types, are equivalent in a `readonly` manner.
521
+ *
522
+ * @internal
523
+ */
524
+ type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
525
+ /**
526
+ * Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
527
+ * 1. If either type is `never`, the result is `true` iff the other type is also `never`.
528
+ * 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
529
+ */
530
+ type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
531
+ /**
532
+ * Checks if two types are strictly equal using
533
+ * the TypeScript internal identical-to operator.
534
+ *
535
+ * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
536
+ */
537
+ type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends <T>() => T extends (R & T) | T ? true : false ? IsNever<L> extends IsNever<R> ? true : false : false;
538
+ /**
539
+ * Checks that {@linkcode Left} and {@linkcode Right} extend each other.
540
+ * Not quite the same as an equality check since `any` can make it resolve
541
+ * to `true`. So should only be used when {@linkcode Left} and
542
+ * {@linkcode Right} are known to avoid `any`.
543
+ */
544
+ type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
545
+ /**
546
+ * Convert a union to an intersection.
547
+ * `A | B | C` -\> `A & B & C`
548
+ */
549
+ type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
550
+ /**
551
+ * Get the last element of a union.
552
+ * First, converts to a union of `() => T` functions,
553
+ * then uses {@linkcode UnionToIntersection} to get the last one.
554
+ */
555
+ type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends () => infer R ? R : never;
556
+ /**
557
+ * Intermediate type for {@linkcode UnionToTuple} which pushes the
558
+ * "last" union member to the end of a tuple, and recursively prepends
559
+ * the remainder of the union.
560
+ */
561
+ type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
562
+ /**
563
+ * Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
564
+ */
565
+ type UnionToTuple<Union> = TuplifyUnion<Union>;
566
+
567
+ /**
568
+ * The simple(ish) way to get overload info from a function
569
+ * {@linkcode FunctionType}. Recent versions of TypeScript will match any
570
+ * function against a generic 10-overload type, filling in slots with
571
+ * duplicates of the function. So, we can just match against a single type
572
+ * and get all the overloads.
573
+ *
574
+ * For older versions of TypeScript, we'll need to painstakingly do
575
+ * ten separate matches.
576
+ */
577
+ type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
578
+ (...args: infer A1): infer R1;
579
+ (...args: infer A2): infer R2;
580
+ (...args: infer A3): infer R3;
581
+ (...args: infer A4): infer R4;
582
+ (...args: infer A5): infer R5;
583
+ (...args: infer A6): infer R6;
584
+ (...args: infer A7): infer R7;
585
+ (...args: infer A8): infer R8;
586
+ (...args: infer A9): infer R9;
587
+ (...args: infer A10): infer R10;
588
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : never;
589
+ /**
590
+ * A function with `unknown` parameters and return type.
591
+ */
592
+ type UnknownFunction = (...args: unknown[]) => unknown;
593
+ /**
594
+ * `true` iff {@linkcode FunctionType} is
595
+ * equivalent to `(...args: unknown[]) => unknown`,
596
+ * which is what an overload variant looks like for a non-existent overload.
597
+ * This is useful because older versions of TypeScript end up with
598
+ * 9 "useless" overloads and one real one for parameterless/generic functions.
599
+ *
600
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
601
+ */
602
+ type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownFunction>;
603
+ /**
604
+ * Old versions of TypeScript can sometimes seem to refuse to separate out
605
+ * union members unless you put them each in a pointless tuple and add an
606
+ * extra `infer X` expression. There may be a better way to work around this
607
+ * problem, but since it's not a problem in newer versions of TypeScript,
608
+ * it's not a priority right now.
609
+ */
610
+ type Tuplify<Union> = Union extends infer X ? [X] : never;
611
+ /**
612
+ * For older versions of TypeScript, we need two separate workarounds
613
+ * to get overload info. First, we need need to use
614
+ * {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
615
+ * functions with 1-10 overloads. Then, we need to filter out the
616
+ * "useless" overloads that are present in older versions of TypeScript,
617
+ * for parameterless functions. To do this we use
618
+ * {@linkcode IsUselessOverloadInfo} to remove useless overloads.
619
+ *
620
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
621
+ */
622
+ type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup ? Tup extends [infer Fn] ? IsUselessOverloadInfo<Fn> extends true ? never : Fn : never : never;
623
+ /**
624
+ * For versions of TypeScript below 5.3, we need to check for 10 overloads,
625
+ * then 9, then 8, etc., to get a union of the overload variants.
626
+ */
627
+ type DecreasingOverloadsInfoUnion<F> = F extends {
628
+ (...args: infer A1): infer R1;
629
+ (...args: infer A2): infer R2;
630
+ (...args: infer A3): infer R3;
631
+ (...args: infer A4): infer R4;
632
+ (...args: infer A5): infer R5;
633
+ (...args: infer A6): infer R6;
634
+ (...args: infer A7): infer R7;
635
+ (...args: infer A8): infer R8;
636
+ (...args: infer A9): infer R9;
637
+ (...args: infer A10): infer R10;
638
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : F extends {
639
+ (...args: infer A1): infer R1;
640
+ (...args: infer A2): infer R2;
641
+ (...args: infer A3): infer R3;
642
+ (...args: infer A4): infer R4;
643
+ (...args: infer A5): infer R5;
644
+ (...args: infer A6): infer R6;
645
+ (...args: infer A7): infer R7;
646
+ (...args: infer A8): infer R8;
647
+ (...args: infer A9): infer R9;
648
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) : F extends {
649
+ (...args: infer A1): infer R1;
650
+ (...args: infer A2): infer R2;
651
+ (...args: infer A3): infer R3;
652
+ (...args: infer A4): infer R4;
653
+ (...args: infer A5): infer R5;
654
+ (...args: infer A6): infer R6;
655
+ (...args: infer A7): infer R7;
656
+ (...args: infer A8): infer R8;
657
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) : F extends {
658
+ (...args: infer A1): infer R1;
659
+ (...args: infer A2): infer R2;
660
+ (...args: infer A3): infer R3;
661
+ (...args: infer A4): infer R4;
662
+ (...args: infer A5): infer R5;
663
+ (...args: infer A6): infer R6;
664
+ (...args: infer A7): infer R7;
665
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
666
+ (...args: infer A1): infer R1;
667
+ (...args: infer A2): infer R2;
668
+ (...args: infer A3): infer R3;
669
+ (...args: infer A4): infer R4;
670
+ (...args: infer A5): infer R5;
671
+ (...args: infer A6): infer R6;
672
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
673
+ (...args: infer A1): infer R1;
674
+ (...args: infer A2): infer R2;
675
+ (...args: infer A3): infer R3;
676
+ (...args: infer A4): infer R4;
677
+ (...args: infer A5): infer R5;
678
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
679
+ (...args: infer A1): infer R1;
680
+ (...args: infer A2): infer R2;
681
+ (...args: infer A3): infer R3;
682
+ (...args: infer A4): infer R4;
683
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
684
+ (...args: infer A1): infer R1;
685
+ (...args: infer A2): infer R2;
686
+ (...args: infer A3): infer R3;
687
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
688
+ (...args: infer A1): infer R1;
689
+ (...args: infer A2): infer R2;
690
+ } ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends (...args: infer A1) => infer R1 ? ((...p: A1) => R1) : never;
691
+ /**
692
+ * Get a union of overload variants for a function {@linkcode FunctionType}.
693
+ * Does a check for whether we can do the one-shot
694
+ * 10-overload matcher (which works for ts\>5.3), and if not,
695
+ * falls back to the more complicated utility.
696
+ */
697
+ type OverloadsInfoUnion<FunctionType> = IsNever<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
698
+ /**
699
+ * The simple(ish) way to get overload info from a constructor
700
+ * {@linkcode ConstructorType}. Recent versions of TypeScript will match any
701
+ * constructor against a generic 10-overload type, filling in slots with
702
+ * duplicates of the constructor. So, we can just match against a single type
703
+ * and get all the overloads.
704
+ *
705
+ * For older versions of TypeScript,
706
+ * we'll need to painstakingly do ten separate matches.
707
+ */
708
+ type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
709
+ new (...args: infer A1): infer R1;
710
+ new (...args: infer A2): infer R2;
711
+ new (...args: infer A3): infer R3;
712
+ new (...args: infer A4): infer R4;
713
+ new (...args: infer A5): infer R5;
714
+ new (...args: infer A6): infer R6;
715
+ new (...args: infer A7): infer R7;
716
+ new (...args: infer A8): infer R8;
717
+ new (...args: infer A9): infer R9;
718
+ new (...args: infer A10): infer R10;
719
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : never;
720
+ /**
721
+ * A constructor function with `unknown` parameters and return type.
722
+ */
723
+ type UnknownConstructor = new (...args: unknown[]) => unknown;
724
+ /**
725
+ * Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
726
+ */
727
+ type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownConstructor>;
728
+ /**
729
+ * For older versions of TypeScript, we need two separate workarounds to
730
+ * get constructor overload info. First, we need need to use
731
+ * {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
732
+ * info for constructors with 1-10 overloads. Then, we need to filter out the
733
+ * "useless" overloads that are present in older versions of TypeScript,
734
+ * for parameterless constructors. To do this we use
735
+ * {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
736
+ *
737
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
738
+ */
739
+ type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup ? Tup extends [infer Ctor] ? IsUselessConstructorOverloadInfo<Ctor> extends true ? never : Ctor : never : never;
740
+ /**
741
+ * For versions of TypeScript below 5.3, we need to check for 10 overloads,
742
+ * then 9, then 8, etc., to get a union of the overload variants.
743
+ */
744
+ type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
745
+ new (...args: infer A1): infer R1;
746
+ new (...args: infer A2): infer R2;
747
+ new (...args: infer A3): infer R3;
748
+ new (...args: infer A4): infer R4;
749
+ new (...args: infer A5): infer R5;
750
+ new (...args: infer A6): infer R6;
751
+ new (...args: infer A7): infer R7;
752
+ new (...args: infer A8): infer R8;
753
+ new (...args: infer A9): infer R9;
754
+ new (...args: infer A10): infer R10;
755
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : ConstructorType extends {
756
+ new (...args: infer A1): infer R1;
757
+ new (...args: infer A2): infer R2;
758
+ new (...args: infer A3): infer R3;
759
+ new (...args: infer A4): infer R4;
760
+ new (...args: infer A5): infer R5;
761
+ new (...args: infer A6): infer R6;
762
+ new (...args: infer A7): infer R7;
763
+ new (...args: infer A8): infer R8;
764
+ new (...args: infer A9): infer R9;
765
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) : ConstructorType extends {
766
+ new (...args: infer A1): infer R1;
767
+ new (...args: infer A2): infer R2;
768
+ new (...args: infer A3): infer R3;
769
+ new (...args: infer A4): infer R4;
770
+ new (...args: infer A5): infer R5;
771
+ new (...args: infer A6): infer R6;
772
+ new (...args: infer A7): infer R7;
773
+ new (...args: infer A8): infer R8;
774
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) : ConstructorType extends {
775
+ new (...args: infer A1): infer R1;
776
+ new (...args: infer A2): infer R2;
777
+ new (...args: infer A3): infer R3;
778
+ new (...args: infer A4): infer R4;
779
+ new (...args: infer A5): infer R5;
780
+ new (...args: infer A6): infer R6;
781
+ new (...args: infer A7): infer R7;
782
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) : ConstructorType extends {
783
+ new (...args: infer A1): infer R1;
784
+ new (...args: infer A2): infer R2;
785
+ new (...args: infer A3): infer R3;
786
+ new (...args: infer A4): infer R4;
787
+ new (...args: infer A5): infer R5;
788
+ new (...args: infer A6): infer R6;
789
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) : ConstructorType extends {
790
+ new (...args: infer A1): infer R1;
791
+ new (...args: infer A2): infer R2;
792
+ new (...args: infer A3): infer R3;
793
+ new (...args: infer A4): infer R4;
794
+ new (...args: infer A5): infer R5;
795
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
796
+ new (...args: infer A1): infer R1;
797
+ new (...args: infer A2): infer R2;
798
+ new (...args: infer A3): infer R3;
799
+ new (...args: infer A4): infer R4;
800
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
801
+ new (...args: infer A1): infer R1;
802
+ new (...args: infer A2): infer R2;
803
+ new (...args: infer A3): infer R3;
804
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
805
+ new (...args: infer A1): infer R1;
806
+ new (...args: infer A2): infer R2;
807
+ } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends new (...args: infer A1) => infer R1 ? (new (...p: A1) => R1) : never;
808
+ /**
809
+ * Get a union of overload variants for a constructor
810
+ * {@linkcode ConstructorType}. Does a check for whether we can do the
811
+ * one-shot 10-overload matcher (which works for ts\>5.3), and if not,
812
+ * falls back to the more complicated utility.
813
+ */
814
+ type ConstructorOverloadsUnion<ConstructorType> = IsNever<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType> : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
815
+ /**
816
+ * Allows inferring any constructor using the `infer` keyword.
817
+ */
818
+ type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
819
+ /**
820
+ * A union type of the parameters allowed for any overload
821
+ * of constructor {@linkcode ConstructorType}.
822
+ */
823
+ type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
824
+ /**
825
+ * Calculates the number of overloads for a given function type.
826
+ */
827
+ type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>['length'];
828
+
829
+ /**
830
+ * Represents a deeply branded type.
831
+ *
832
+ * Recursively walk a type and replace it with a branded type related to the
833
+ * original. This is useful for equality-checking stricter than
834
+ * `A extends B ? B extends A ? true : false : false`, because it detects the
835
+ * difference between a few edge-case types that vanilla TypeScript
836
+ * doesn't by default:
837
+ * - `any` vs `unknown`
838
+ * - `{ readonly a: string }` vs `{ a: string }`
839
+ * - `{ a?: string }` vs `{ a: string | undefined }`
840
+ *
841
+ * __Note__: not very performant for complex types - this should only be used
842
+ * when you know you need it. If doing an equality check, it's almost always
843
+ * better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
844
+ */
845
+ type DeepBrand<T> = IsNever<T> extends true ? {
846
+ type: 'never';
847
+ } : IsAny<T> extends true ? {
848
+ type: 'any';
849
+ } : IsUnknown<T> extends true ? {
850
+ type: 'unknown';
851
+ } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
852
+ type: 'primitive';
853
+ value: T;
854
+ } : T extends new (...args: any[]) => any ? {
855
+ type: 'constructor';
856
+ params: ConstructorOverloadParameters<T>;
857
+ instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
858
+ } : T extends (...args: infer P) => infer R ? NumOverloads<T> extends 1 ? {
859
+ type: 'function';
860
+ params: DeepBrand<P>;
861
+ return: DeepBrand<R>;
862
+ this: DeepBrand<ThisParameterType<T>>;
863
+ props: DeepBrand<Omit<T, keyof Function>>;
864
+ } : UnionToTuple<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
865
+ type: 'overloads';
866
+ overloads: {
867
+ [K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]>;
868
+ };
869
+ } : never : T extends any[] ? {
870
+ type: 'array';
871
+ items: {
872
+ [K in keyof T]: T[K];
873
+ };
874
+ } : {
875
+ type: 'object';
876
+ properties: {
877
+ [K in keyof T]: DeepBrand<T[K]>;
878
+ };
879
+ readonly: ReadonlyKeys<T>;
880
+ required: RequiredKeys<T>;
881
+ optional: OptionalKeys<T>;
882
+ constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
883
+ };
884
+ /**
885
+ * Checks if two types are strictly equal using branding.
886
+ */
887
+ type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
888
+
889
+ /**
890
+ * Borrowed from vitest
891
+ */
892
+ type PrintType<T> = IsUnknown<T> extends true ? 'unknown' : IsNever<T> extends true ? 'never' : IsAny<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : bigint extends T ? 'bigint' : T extends bigint ? `literal bigint: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...';
893
+ /**
894
+ * Borrowed from vitest
895
+ */
896
+ type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : {
897
+ [K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
898
+ } : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `[Regle error] The parent property does not match the form schema`;
899
+
349
900
  type ParamDecl<T = any> = MaybeRef<Maybe<T>> | (() => Maybe<T>);
350
901
  type CreateFn<T extends any[]> = (...args: T) => any;
351
902
  /**
@@ -373,6 +924,7 @@ interface RegleInternalRuleDefs<TValue extends any = any, TParams extends any[]
373
924
  _tooltip_patched: boolean;
374
925
  _params?: RegleUniversalParams<TParams>;
375
926
  _async: TAsync;
927
+ readonly _brand: symbol;
376
928
  }
377
929
  declare enum InternalRuleType {
378
930
  Inline = "__inline",
@@ -471,6 +1023,10 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
471
1023
  tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
472
1024
  type?: string;
473
1025
  }
1026
+ type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
1027
+ value: TValue;
1028
+ params: [...TParams];
1029
+ };
474
1030
 
475
1031
  type DefaultValidators = {
476
1032
  alpha: RegleRuleDefinition<string>;
@@ -546,10 +1102,22 @@ type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Parti
546
1102
  type RegleComputedRules<TForm extends MaybeRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<AllRulesDeclarations> | Regle<any, any> = Partial<AllRulesDeclarations>, TState = Unwrap<TForm>, TCustom = TCustomRules extends Regle<any, infer R> ? R extends ReglePartialRuleTree<any, infer C> ? C : Partial<AllRulesDeclarations> : TCustomRules> = {
547
1103
  [TKey in keyof TState]?: RegleFormPropertyType<TState[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
548
1104
  };
1105
+ /**
1106
+ * @internal
1107
+ * @reference {@link ReglePartialRuleTree}
1108
+ */
1109
+ type $InternalReglePartialRuleTree = {
1110
+ [x: string]: $InternalFormPropertyTypes;
1111
+ };
549
1112
  /**
550
1113
  * @public
551
1114
  */
552
1115
  type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends File ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? ReglePartialRuleTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
1116
+ /**
1117
+ * @internal
1118
+ * @reference {@link RegleFormPropertyType}
1119
+ */
1120
+ type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialRuleTree | FieldRegleBehaviourOptions;
553
1121
  /**
554
1122
  * @public
555
1123
  * Rule tree for a form property
@@ -557,6 +1125,11 @@ type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<AllRulesDe
557
1125
  type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = FieldRegleBehaviourOptions & {
558
1126
  [TKey in keyof TCustomRules]?: NonNullable<TCustomRules[TKey]> extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, [...TParams, ...args: [...any[]]], boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any, any, any> ? FormRuleDeclaration<TValue, any> : FormRuleDeclaration<TValue, any> | FieldRegleBehaviourOptions[keyof FieldRegleBehaviourOptions];
559
1127
  };
1128
+ /**
1129
+ * @internal
1130
+ * @reference {@link RegleRuleDecl}
1131
+ */
1132
+ type $InternalRegleRuleDecl = FieldRegleBehaviourOptions & Record<string, FormRuleDeclaration<any, any>>;
560
1133
  /**
561
1134
  * @public
562
1135
  */
@@ -571,6 +1144,13 @@ type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRul
571
1144
  } & RegleRuleDecl<NonNullable<TValue>, TCustomRules>) | ({
572
1145
  $each?: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>, RegleCollectionRuleDeclKeyProperty>;
573
1146
  } & FieldRegleBehaviourOptions);
1147
+ /**
1148
+ * @internal
1149
+ * @reference {@link RegleCollectionRuleDecl}
1150
+ */
1151
+ type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
1152
+ $each?: MaybeGetter<$InternalFormPropertyTypes & RegleCollectionRuleDeclKeyProperty, any>;
1153
+ };
574
1154
  /**
575
1155
  * @public
576
1156
  */
@@ -596,6 +1176,18 @@ type RegleExternalCollectionErrors<TState extends Record<string, any>> = {
596
1176
  readonly $self?: string[];
597
1177
  readonly $each?: RegleValidationErrors<TState, true>[];
598
1178
  };
1179
+ /** @internal */
1180
+ type $InternalRegleCollectionErrors = {
1181
+ readonly $self?: string[];
1182
+ readonly $each?: $InternalRegleErrors[];
1183
+ };
1184
+ type $InternalRegleErrorTree = {
1185
+ [x: string]: $InternalRegleErrors;
1186
+ };
1187
+ /**
1188
+ * @internal
1189
+ */
1190
+ type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
599
1191
  type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{
600
1192
  [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: Maybe<TState[K]>;
601
1193
  } & {
@@ -608,6 +1200,10 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
608
1200
  result: true;
609
1201
  data: Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules>;
610
1202
  };
1203
+ type $InternalRegleResult = {
1204
+ result: boolean;
1205
+ data: any;
1206
+ };
611
1207
 
612
1208
  /**
613
1209
  * @public
@@ -633,10 +1229,28 @@ type RegleStatus<TState extends Record<string, any> | undefined = Record<string,
633
1229
  } & ([TShortcuts['nested']] extends [never] ? {} : {
634
1230
  [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>;
635
1231
  });
1232
+ /**
1233
+ * @internal
1234
+ * @reference {@link RegleStatus}
1235
+ */
1236
+ interface $InternalRegleStatus extends RegleCommonStatus {
1237
+ $fields: {
1238
+ [x: string]: $InternalRegleStatusType;
1239
+ };
1240
+ readonly $errors: Record<string, $InternalRegleErrors>;
1241
+ readonly $silentErrors: Record<string, $InternalRegleErrors>;
1242
+ $extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
1243
+ $validate: () => Promise<$InternalRegleResult>;
1244
+ }
636
1245
  /**
637
1246
  * @public
638
1247
  */
639
1248
  type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState[TKey]> extends Array<Record<string, any> | any> ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState[TKey], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCollectionStatus<TState[TKey], {}, TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleCommonStatus<TState[TKey]> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? RegleStatus<TState[TKey], TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? RegleStatus<TState[TKey], ReglePartialRuleTree<TState[TKey]>, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts>;
1249
+ /**
1250
+ * @internal
1251
+ * @reference {@link InferRegleStatusType}
1252
+ */
1253
+ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
640
1254
  /**
641
1255
  * @public
642
1256
  */
@@ -655,6 +1269,20 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
655
1269
  } & ([TShortcuts['fields']] extends [never] ? {} : {
656
1270
  [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>;
657
1271
  });
1272
+ /**
1273
+ * @internal
1274
+ * @reference {@link RegleFieldStatus}
1275
+ */
1276
+ interface $InternalRegleFieldStatus extends RegleCommonStatus {
1277
+ $value: any;
1278
+ $silentValue: any;
1279
+ readonly $rules: Record<string, $InternalRegleRuleStatus>;
1280
+ readonly $externalErrors?: string[];
1281
+ readonly $errors: string[];
1282
+ readonly $silentErrors: string[];
1283
+ $extractDirtyFields: (filterNullishValues?: boolean) => any;
1284
+ $validate: () => Promise<$InternalRegleResult>;
1285
+ }
658
1286
  /**
659
1287
  * @public
660
1288
  */
@@ -697,6 +1325,29 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata exte
697
1325
  } : {
698
1326
  readonly $params: TParams;
699
1327
  });
1328
+ /**
1329
+ * @internal
1330
+ * @reference {@link RegleRuleStatus}
1331
+ */
1332
+ interface $InternalRegleRuleStatus {
1333
+ $type: string;
1334
+ $message: string | string[];
1335
+ $tooltip: string | string[];
1336
+ $active: boolean;
1337
+ $valid: boolean;
1338
+ $pending: boolean;
1339
+ $path: string;
1340
+ $externalErrors?: string[];
1341
+ $params?: any[];
1342
+ $metadata: any;
1343
+ $haveAsync: boolean;
1344
+ $validating: boolean;
1345
+ $validator(value: any, ...args: any[]): RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>;
1346
+ $validate(): Promise<boolean>;
1347
+ $unwatch(): void;
1348
+ $watch(): void;
1349
+ $reset(): void;
1350
+ }
700
1351
  /**
701
1352
  * @public
702
1353
  */
@@ -712,6 +1363,22 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
712
1363
  } & ([TShortcuts['collections']] extends [never] ? {} : {
713
1364
  [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
714
1365
  });
1366
+ /**
1367
+ * @internal
1368
+ * @reference {@link RegleCollectionStatus}
1369
+ */
1370
+ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields' | '$errors' | '$silentErrors'> {
1371
+ readonly $field: $InternalRegleFieldStatus;
1372
+ readonly $each: Array<$InternalRegleStatusType>;
1373
+ readonly $errors: $InternalRegleCollectionErrors;
1374
+ readonly $silentErrors: $InternalRegleCollectionErrors;
1375
+ readonly $externalErrors?: string[];
1376
+ $extractDirtyFields: (filterNullishValues?: boolean) => any[];
1377
+ $validate: () => Promise<$InternalRegleResult>;
1378
+ /** Track each array state */
1379
+ $unwatch(): void;
1380
+ $watch(): void;
1381
+ }
715
1382
 
716
1383
  /**
717
1384
  * @description
@@ -731,11 +1398,11 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
731
1398
  *
732
1399
  * ```ts
733
1400
  * // Create a simple rule with no params
734
- * import {ruleHelpers} from '@regle/rules';
1401
+ * import {isFilled} from '@regle/rules';
735
1402
  *
736
1403
  * export const isFoo = createRule({
737
1404
  * validator(value: string) {
738
- * if (ruleHelpers.isFilled(value)) {
1405
+ * if (isFilled(value)) {
739
1406
  * return value === 'foo';
740
1407
  * }
741
1408
  * return true
@@ -761,4 +1428,4 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
761
1428
  inferRules: inferRulesFn<TCustomRules>;
762
1429
  };
763
1430
 
764
- export { type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, 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 RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialRuleTree, type RegleResult, type RegleRoot, 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 RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, defineRegleConfig, inferRules, unwrapRuleParameters, useRegle };
1431
+ export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type NoInferLegacy, type ParamDecl, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, defineRegleConfig, inferRules, unwrapRuleParameters, useRegle, useRootStorage };