@regle/core 1.12.2 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/regle-core.d.ts +316 -236
- package/dist/regle-core.js +27 -28
- package/dist/regle-core.min.js +1 -1
- package/package.json +1 -1
package/dist/regle-core.d.ts
CHANGED
|
@@ -1,7 +1,198 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
|
-
import { MaybeRef, MaybeRefOrGetter, Plugin, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
3
|
-
import { EmptyObject, IsAny, IsEmptyObject, IsUnion, IsUnknown, Merge, Or,
|
|
2
|
+
import { ComputedRef, MaybeRef, MaybeRefOrGetter, Plugin, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
3
|
+
import { EmptyObject, IsAny, IsEmptyObject, IsUnion, IsUnknown, Merge, Or, RequireAtLeastOne, RequireOneOrNone, RequiredDeep, UnionToIntersection, UnionToTuple } from "type-fest";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
+
declare const RegleStaticSymbol: unique symbol;
|
|
6
|
+
type RegleStatic<T> = T extends (new (...args: infer Args) => infer U) ? RegleStaticImpl<new (...args: Args) => RegleStaticImpl<U>> : RegleStaticImpl<T>;
|
|
7
|
+
type RegleStaticImpl<T> = Raw<T & {
|
|
8
|
+
[RegleStaticSymbol]: true;
|
|
9
|
+
}>;
|
|
10
|
+
type IsRegleStatic<T> = T extends RegleStaticImpl<T> ? true : false;
|
|
11
|
+
type UnwrapStatic<T> = IsUnknown<T> extends true ? any : NonNullable<T> extends RegleStaticImpl<infer U> ? Raw<U> : UnwrapStaticSimple<T>;
|
|
12
|
+
type UnwrapStaticSimple<T> = NonNullable<T> extends Array<infer U> ? Array<UnwrapStatic<U>> : isRecordLiteral<NonNullable<T>> extends true ? { [K in keyof T]: UnwrapStatic<T[K]> } : T;
|
|
13
|
+
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
14
|
+
type Maybe<T = any> = T | null | undefined;
|
|
15
|
+
type MaybeInput<T = any> = T | null | undefined;
|
|
16
|
+
type MaybeOutput<T = any> = T | undefined;
|
|
17
|
+
type MaybeReadonly<T> = T | Readonly<T>;
|
|
18
|
+
type NonUndefined<T> = Exclude<T, undefined>;
|
|
19
|
+
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
20
|
+
type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
|
|
21
|
+
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
22
|
+
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends ((...args: any[]) => infer U) ? U : T;
|
|
23
|
+
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
24
|
+
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
25
|
+
type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
|
|
26
|
+
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
27
|
+
type ExcludeByType<T, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] extends U$1 ? never : T[K] };
|
|
28
|
+
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
29
|
+
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
30
|
+
type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
|
|
31
|
+
/**
|
|
32
|
+
* Extract the element type from an array.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* type Element = ArrayElement<[1, 2, 3]>; // number
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
40
|
+
/**
|
|
41
|
+
* Declares a tuple that must have at least one element
|
|
42
|
+
*/
|
|
43
|
+
type NonEmptyTuple<T> = [T, ...T[]] | T[];
|
|
44
|
+
type useRegleFnOptions<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<ExtendedRulesDeclarations>>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState$1 extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups> & TAdditionalOptions;
|
|
45
|
+
interface useRegleFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
46
|
+
<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<MaybeRef<TState$1> | DeepReactiveState<TState$1>>, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState$1 extends Record<string, any> ? MaybeRefOrComputedRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState$1> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState$1>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
47
|
+
__config?: {
|
|
48
|
+
rules?: () => CustomRulesDeclarationTree;
|
|
49
|
+
modifiers?: RegleBehaviourOptions;
|
|
50
|
+
shortcuts?: TShortcuts;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* useRegle serves as the foundation for validation logic.
|
|
55
|
+
*
|
|
56
|
+
* It accepts the following inputs:
|
|
57
|
+
*
|
|
58
|
+
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
59
|
+
* @param rules - These should align with the structure of your state.
|
|
60
|
+
* @param modifiers - Customize regle behaviour
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { useRegle } from '@regle/core';
|
|
64
|
+
import { required } from '@regle/rules';
|
|
65
|
+
|
|
66
|
+
const { r$ } = useRegle({ email: '' }, {
|
|
67
|
+
email: { required }
|
|
68
|
+
})
|
|
69
|
+
* ```
|
|
70
|
+
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
71
|
+
*/
|
|
72
|
+
declare const useRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
73
|
+
interface inferRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>> {
|
|
74
|
+
<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<DefaultValidatorsTree> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<DefaultValidatorsTree> & TCustomRules>>(state: MaybeRef<TState$1> | DeepReactiveState<TState$1> | undefined, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? TDecl : TState$1 extends Record<string, any> ? TRules$1 : {}): NonNullable<TState$1> extends PrimitiveTypes ? TDecl : TRules$1;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
78
|
+
* It will just return the rules without any processing.
|
|
79
|
+
*
|
|
80
|
+
* @param state - The state reference
|
|
81
|
+
* @param rules - Your rule tree
|
|
82
|
+
*/
|
|
83
|
+
declare const inferRules: inferRulesFn<Partial<ExtendedRulesDeclarations>>;
|
|
84
|
+
declare function useRootStorage({
|
|
85
|
+
initialState,
|
|
86
|
+
originalState,
|
|
87
|
+
options,
|
|
88
|
+
scopeRules,
|
|
89
|
+
state,
|
|
90
|
+
customRules,
|
|
91
|
+
shortcuts,
|
|
92
|
+
schemaErrors,
|
|
93
|
+
schemaMode,
|
|
94
|
+
onValidate
|
|
95
|
+
}: {
|
|
96
|
+
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
97
|
+
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
98
|
+
options: ResolvedRegleBehaviourOptions;
|
|
99
|
+
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
100
|
+
originalState: Record<string, any> | PrimitiveTypes;
|
|
101
|
+
customRules?: () => CustomRulesDeclarationTree;
|
|
102
|
+
shortcuts: RegleShortcutDefinition | undefined;
|
|
103
|
+
schemaErrors?: Ref<any | undefined>;
|
|
104
|
+
schemaMode?: boolean;
|
|
105
|
+
onValidate?: () => Promise<$InternalRegleResult>;
|
|
106
|
+
}): {
|
|
107
|
+
regle: $InternalRegleStatusType | undefined;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Converts a nested $errors object to a flat array of string errors
|
|
111
|
+
*
|
|
112
|
+
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
113
|
+
*/
|
|
114
|
+
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
115
|
+
includePath: true;
|
|
116
|
+
}): StandardSchemaV1.Issue[];
|
|
117
|
+
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
118
|
+
includePath?: false;
|
|
119
|
+
}): string[];
|
|
120
|
+
type useRulesFnOptions<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 = InferInput<TRules$1>> = Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups>;
|
|
121
|
+
interface useRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
122
|
+
<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<ExtendedRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 extends Record<string, any> = InferInput<TRules$1>>(rulesFactory: TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, options?: useRulesFnOptions<TRules$1, TValidationGroups, TState$1>): NonNullable<TState$1> extends PrimitiveTypes ? Raw<RegleFieldStatus<NonNullable<TState$1>, TDecl, TShortcuts>> & StandardSchemaV1<TState$1> : Raw<RegleRoot<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts>> & StandardSchemaV1<TState$1>;
|
|
123
|
+
__config?: {
|
|
124
|
+
rules?: () => CustomRulesDeclarationTree;
|
|
125
|
+
modifiers?: RegleBehaviourOptions;
|
|
126
|
+
shortcuts?: TShortcuts;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* useRules is a clone of useRegle, without the need to provide a state.
|
|
131
|
+
*
|
|
132
|
+
* It accepts the following inputs:
|
|
133
|
+
*
|
|
134
|
+
* @param rules - Your rules object
|
|
135
|
+
* @param modifiers - Customize regle behaviour
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { useRules } from '@regle/core';
|
|
139
|
+
import { required } from '@regle/rules';
|
|
140
|
+
|
|
141
|
+
const { r$ } = useRules({
|
|
142
|
+
email: { required }
|
|
143
|
+
})
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare const useRules: useRulesFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>>;
|
|
147
|
+
/**
|
|
148
|
+
* Marks a value as static and treats the constructor as a regular raw Field.
|
|
149
|
+
* @param value - The value to mark as static.
|
|
150
|
+
* @returns The marked value.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const StaticDecimal = markStatic(Decimal);
|
|
154
|
+
* const StaticBigWrapper = markStatic(BigWrapper);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
|
|
158
|
+
/**
|
|
159
|
+
* Infer type of the `r$` of any function returning a regle instance
|
|
160
|
+
*/
|
|
161
|
+
type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
|
|
162
|
+
/**
|
|
163
|
+
* Infer custom rules declared in a global configuration
|
|
164
|
+
*/
|
|
165
|
+
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
|
|
166
|
+
/**
|
|
167
|
+
* Infer custom shortcuts declared in a global configuration
|
|
168
|
+
*/
|
|
169
|
+
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
170
|
+
/**
|
|
171
|
+
* Extract a set rules and setting them as required
|
|
172
|
+
*/
|
|
173
|
+
type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
174
|
+
/**
|
|
175
|
+
* Extract a set of custom rules from a global configuration and setting them as required
|
|
176
|
+
|
|
177
|
+
*/
|
|
178
|
+
type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules$1 extends keyof InferRegleRules<T>> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
|
|
179
|
+
/**
|
|
180
|
+
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
181
|
+
*/
|
|
182
|
+
type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState$1 extends unknown = any, TRules$1 extends keyof InferRegleRules<T> = never> = RegleFieldStatus<TState$1, [TRules$1] extends [never] ? Partial<InferRegleRules<T>> : RegleEnforceCustomRequiredRules<T, TRules$1>, InferRegleShortcuts<T>>;
|
|
183
|
+
/**
|
|
184
|
+
/**
|
|
185
|
+
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
186
|
+
* exactly matches the structure of type T, including all nested properties.
|
|
187
|
+
*
|
|
188
|
+
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
189
|
+
*/
|
|
190
|
+
type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
|
|
191
|
+
type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
|
|
192
|
+
type TypeError<Msg> = {
|
|
193
|
+
[' TypeError']: Msg;
|
|
194
|
+
};
|
|
195
|
+
type Coerce<T> = `${T & string}`;
|
|
5
196
|
interface RegleBehaviourOptions {
|
|
6
197
|
/**
|
|
7
198
|
* Only display error when calling `r$.$validate()`
|
|
@@ -189,10 +380,10 @@ type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
|
189
380
|
type PartialFormState<TState$1 extends Record<string, any>> = [unknown] extends [TState$1] ? {} : Prettify<{ [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? never : TState$1[K] extends Array<any> ? never : K]?: MaybeOutput<TState$1[K]> } & { [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? K : TState$1[K] extends Array<any> ? K : never]: NonNullable<TState$1[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState$1[K]> }>;
|
|
190
381
|
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
|
|
191
382
|
valid: false;
|
|
192
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Date | File ? MaybeOutput<Data
|
|
383
|
+
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Date | File ? MaybeOutput<Raw<Data>> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data> : unknown;
|
|
193
384
|
} | {
|
|
194
385
|
valid: true;
|
|
195
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules$1>[] : Data extends Date | File ? SafeFieldProperty<Data
|
|
386
|
+
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules$1>[] : NonNullable<Data> extends Date | File ? SafeFieldProperty<Raw<NonNullable<Data>>, TRules$1> : NonNullable<Data> extends Record<string, any> ? DeepSafeFormState<NonNullable<Data>, TRules$1> : SafeFieldProperty<Data, TRules$1> : unknown;
|
|
196
387
|
};
|
|
197
388
|
type RegleNestedResult<Data extends Record<string, any> | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
198
389
|
/**
|
|
@@ -237,14 +428,6 @@ type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<an
|
|
|
237
428
|
issues: [];
|
|
238
429
|
errors: [];
|
|
239
430
|
});
|
|
240
|
-
/**
|
|
241
|
-
* Infer safe output from any `r$` instance
|
|
242
|
-
*
|
|
243
|
-
* ```ts
|
|
244
|
-
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
type InferSafeOutput<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = UnwrapRef<TRegle> extends Raw<RegleRoot<infer TState extends Record<string, any>, infer TRules, any, any>> ? DeepSafeFormState<JoinDiscriminatedUnions<TState>, TRules> : UnwrapRef<TRegle> extends RegleFieldStatus<infer TState, infer TRules> ? SafeFieldProperty<TState, TRules> : UnwrapRef<TRegle> extends RegleLike<infer TState extends Record<string, any>> ? TState : never;
|
|
248
431
|
type $InternalRegleResult = {
|
|
249
432
|
valid: boolean;
|
|
250
433
|
data: any;
|
|
@@ -252,7 +435,7 @@ type $InternalRegleResult = {
|
|
|
252
435
|
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
253
436
|
};
|
|
254
437
|
type DeepSafeFormState<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? {} : TRules$1 extends undefined ? TState$1 : TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? K : never]?: SafeProperty<TState$1[K], TRules$1[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState$1[K], TRules$1[K]> } & { [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState$1[K], TRules$1[K]> ? unknown : NonNullable<SafeProperty<TState$1[K], TRules$1[K]>> }> : TState$1;
|
|
255
|
-
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends
|
|
438
|
+
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRefOrComputedRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
|
|
256
439
|
type ObjectHaveAtLeastOneRequiredField<TState$1 extends Record<string, any>, TRule extends ReglePartialRuleTree<TState$1, any>> = TState$1 extends Maybe<TState$1> ? { [K in keyof NonNullable<TState$1>]-?: IsPropertyOutputRequired<NonNullable<TState$1>[K], TRule[K]> }[keyof TState$1] extends false ? false : true : true;
|
|
257
440
|
type ArrayHaveAtLeastOneRequiredField<TState$1 extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState$1>> = TState$1 extends Maybe<TState$1> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends MaybeRef<RegleRuleDecl> ? Omit<UnwrapRef<TRule>, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState$1>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
|
|
258
441
|
type SafeProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState$1 ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState$1 extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState$1 : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? DeepSafeFormState<NonNullable<TState$1> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState$1>> : {}, TRule> : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends true ? TState$1 : MaybeOutput<TState$1> : TState$1 : TState$1;
|
|
@@ -284,28 +467,27 @@ type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Recor
|
|
|
284
467
|
type ProcessChildrenFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState$1>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
285
468
|
type FindCorrespondingVariant<TState$1 extends Record<string, any>, TRules$1 extends any[]> = TRules$1 extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState$1> ? [F] : FindCorrespondingVariant<TState$1, R> : [];
|
|
286
469
|
type PossibleLiteralTypes<T extends Record<string, any>, TKey$1 extends keyof T> = unknown extends T[TKey$1] ? {
|
|
287
|
-
[x: string]: { [K in TKey$1]-?: Omit<RegleRuleDecl<any, Partial<
|
|
470
|
+
[x: string]: { [K in TKey$1]-?: Omit<RegleRuleDecl<any, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
288
471
|
literal?: RegleRuleDefinition<any, [literal: any], false, boolean, any, string | number>;
|
|
289
472
|
} };
|
|
290
|
-
} : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<
|
|
473
|
+
} : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
291
474
|
literal?: RegleRuleDefinition<MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number>;
|
|
292
475
|
} } };
|
|
293
476
|
type RequiredForm<T extends Record<string, any>, TKey$1 extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey$1> & PossibleLiteralTypes<T, TKey$1>[keyof PossibleLiteralTypes<T, TKey$1>];
|
|
294
477
|
type VariantTuple<T extends Record<string, any>, TKey$1 extends keyof T> = [RequiredForm<T, TKey$1>, ...RequiredForm<T, TKey$1>[]];
|
|
295
|
-
type RemoveCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
|
|
296
478
|
/**
|
|
297
|
-
*
|
|
479
|
+
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
298
480
|
*/
|
|
299
|
-
|
|
300
|
-
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
481
|
+
type JoinDiscriminatedUnions<TUnion extends unknown> = HasNamedKeys<TUnion> extends true ? isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : TUnion : TUnion;
|
|
301
482
|
/**
|
|
302
|
-
*
|
|
483
|
+
* Combine all members of a union type on one level and not nested.
|
|
303
484
|
*/
|
|
304
|
-
type
|
|
485
|
+
type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
|
|
486
|
+
type RemoveCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
|
|
305
487
|
/**
|
|
306
|
-
*
|
|
488
|
+
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
307
489
|
*/
|
|
308
|
-
type
|
|
490
|
+
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
|
|
309
491
|
/**
|
|
310
492
|
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
311
493
|
*/
|
|
@@ -315,203 +497,47 @@ type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string>
|
|
|
315
497
|
*/
|
|
316
498
|
type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
317
499
|
/**
|
|
318
|
-
*
|
|
500
|
+
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
319
501
|
*/
|
|
320
|
-
type
|
|
502
|
+
type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
|
|
503
|
+
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K] };
|
|
321
504
|
/**
|
|
322
|
-
*
|
|
505
|
+
* Merge every boolean property into a single boolean.
|
|
323
506
|
*/
|
|
324
|
-
type
|
|
325
|
-
|
|
507
|
+
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
508
|
+
/**
|
|
509
|
+
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
510
|
+
*/
|
|
511
|
+
type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
|
|
512
|
+
type EnumType<T extends Record<string, unknown>> = T[keyof T];
|
|
326
513
|
type EnumLike = {
|
|
327
514
|
[k: string]: string | number;
|
|
328
515
|
[nu: number]: string;
|
|
329
516
|
};
|
|
330
|
-
type
|
|
517
|
+
type MaybeRefOrComputedRef<T extends any> = MaybeRef<T> | ComputedRef<T>;
|
|
331
518
|
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
332
|
-
type UnwrapStatic<T> = IsUnknown<T> extends true ? any : NonNullable<T> extends RegleStaticImpl<infer U> ? Raw<U> : UnwrapStaticSimple<T>;
|
|
333
|
-
type UnwrapStaticSimple<T> = NonNullable<T> extends Array<infer U> ? Array<UnwrapStatic<U>> : isRecordLiteral<NonNullable<T>> extends true ? { [K in keyof T]: UnwrapStatic<T[K]> } : T;
|
|
334
519
|
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
335
520
|
type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
|
|
336
521
|
type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
|
|
337
|
-
declare const RegleStaticSymbol: unique symbol;
|
|
338
|
-
type RegleStatic<T> = T extends (new (...args: infer Args) => infer U) ? RegleStaticImpl<new (...args: Args) => RegleStaticImpl<U>> : RegleStaticImpl<T>;
|
|
339
|
-
type RegleStaticImpl<T> = Raw<T & {
|
|
340
|
-
[RegleStaticSymbol]: true;
|
|
341
|
-
}>;
|
|
342
|
-
type IsRegleStatic<T> = T extends RegleStaticImpl<T> ? true : false;
|
|
343
|
-
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
344
|
-
type Maybe<T = any> = T | null | undefined;
|
|
345
|
-
type MaybeInput<T = any> = T | null | undefined;
|
|
346
|
-
type MaybeOutput<T = any> = T | undefined;
|
|
347
|
-
type MaybeReadonly<T> = T | Readonly<T>;
|
|
348
|
-
type NonUndefined<T> = Exclude<T, undefined>;
|
|
349
|
-
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
350
|
-
type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
|
|
351
|
-
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
352
|
-
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends ((...args: any[]) => infer U) ? U : T;
|
|
353
|
-
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
354
|
-
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
355
|
-
type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
|
|
356
|
-
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
357
|
-
type ExcludeByType<T, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] extends U$1 ? never : T[K] };
|
|
358
|
-
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
359
|
-
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
360
|
-
type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
|
|
361
|
-
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
362
|
-
type NonEmptyTuple<T> = [T, ...T[]] | T[];
|
|
363
|
-
type useRegleFnOptions<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<AllRulesDeclarations>>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState$1 extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups> & TAdditionalOptions;
|
|
364
|
-
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
365
|
-
<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<AllRulesDeclarations> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<MaybeRef<TState$1> | DeepReactiveState<TState$1>>, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState$1> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState$1>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
366
|
-
__config?: {
|
|
367
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
368
|
-
modifiers?: RegleBehaviourOptions;
|
|
369
|
-
shortcuts?: TShortcuts;
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* useRegle serves as the foundation for validation logic.
|
|
374
|
-
*
|
|
375
|
-
* It accepts the following inputs:
|
|
376
|
-
*
|
|
377
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
378
|
-
* @param rules - These should align with the structure of your state.
|
|
379
|
-
* @param modifiers - Customize regle behaviour
|
|
380
|
-
*
|
|
381
|
-
* ```ts
|
|
382
|
-
* import { useRegle } from '@regle/core';
|
|
383
|
-
import { required } from '@regle/rules';
|
|
384
|
-
|
|
385
|
-
const { r$ } = useRegle({ email: '' }, {
|
|
386
|
-
email: { required }
|
|
387
|
-
})
|
|
388
|
-
* ```
|
|
389
|
-
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
390
|
-
*/
|
|
391
|
-
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
392
|
-
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
393
|
-
<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<AllRulesDeclarations> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<AllRulesDeclarations> & TCustomRules>>(state: MaybeRef<TState$1> | DeepReactiveState<TState$1>, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? TDecl : TState$1 extends Record<string, any> ? TRules$1 : {}): NonNullable<TState$1> extends PrimitiveTypes ? TDecl : TRules$1;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
397
|
-
* It will just return the rules without any processing.
|
|
398
|
-
*
|
|
399
|
-
* @param state - The state reference
|
|
400
|
-
* @param rules - Your rule tree
|
|
401
|
-
*/
|
|
402
|
-
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
403
|
-
declare function useRootStorage({
|
|
404
|
-
initialState,
|
|
405
|
-
originalState,
|
|
406
|
-
options,
|
|
407
|
-
scopeRules,
|
|
408
|
-
state,
|
|
409
|
-
customRules,
|
|
410
|
-
shortcuts,
|
|
411
|
-
schemaErrors,
|
|
412
|
-
schemaMode,
|
|
413
|
-
onValidate
|
|
414
|
-
}: {
|
|
415
|
-
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
416
|
-
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
417
|
-
options: ResolvedRegleBehaviourOptions;
|
|
418
|
-
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
419
|
-
originalState: Record<string, any> | PrimitiveTypes;
|
|
420
|
-
customRules?: () => CustomRulesDeclarationTree;
|
|
421
|
-
shortcuts: RegleShortcutDefinition | undefined;
|
|
422
|
-
schemaErrors?: Ref<any | undefined>;
|
|
423
|
-
schemaMode?: boolean;
|
|
424
|
-
onValidate?: () => Promise<$InternalRegleResult>;
|
|
425
|
-
}): {
|
|
426
|
-
regle: $InternalRegleStatusType | undefined;
|
|
427
|
-
};
|
|
428
522
|
/**
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
523
|
+
* Convert a nested object to a deeply nested partial object.
|
|
432
524
|
*/
|
|
433
|
-
|
|
434
|
-
includePath: true;
|
|
435
|
-
}): StandardSchemaV1.Issue[];
|
|
436
|
-
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
437
|
-
includePath?: false;
|
|
438
|
-
}): string[];
|
|
439
|
-
type useRulesFnOptions<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 = InferInput<TRules$1>> = Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups>;
|
|
440
|
-
interface useRulesFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
441
|
-
<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 extends Record<string, any> = InferInput<TRules$1>>(rulesFactory: TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, options?: useRulesFnOptions<TRules$1, TValidationGroups, TState$1>): NonNullable<TState$1> extends PrimitiveTypes ? Raw<RegleFieldStatus<NonNullable<TState$1>, TDecl, TShortcuts>> & StandardSchemaV1<TState$1> : Raw<RegleRoot<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts>> & StandardSchemaV1<TState$1>;
|
|
442
|
-
__config?: {
|
|
443
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
444
|
-
modifiers?: RegleBehaviourOptions;
|
|
445
|
-
shortcuts?: TShortcuts;
|
|
446
|
-
};
|
|
447
|
-
}
|
|
525
|
+
type DeepPartial<T> = T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Date | File | RegleStaticImpl<unknown> ? T : T extends Record<string, any> ? { [K in keyof T]?: DeepPartial<T[K]> | undefined } : T | undefined;
|
|
448
526
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* It accepts the following inputs:
|
|
452
|
-
*
|
|
453
|
-
* @param rules - Your rules object
|
|
454
|
-
* @param modifiers - Customize regle behaviour
|
|
527
|
+
* Infer safe output type from a rules object and it's original state type
|
|
455
528
|
*
|
|
456
529
|
* ```ts
|
|
457
|
-
*
|
|
458
|
-
import { required } from '@regle/rules';
|
|
459
|
-
|
|
460
|
-
const { r$ } = useRules({
|
|
461
|
-
email: { required }
|
|
462
|
-
})
|
|
530
|
+
* type FormRequest = InferOutput<typeof rules, typeof formState>;
|
|
463
531
|
* ```
|
|
464
532
|
*/
|
|
465
|
-
|
|
533
|
+
type InferOutput<TRules$1 extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TState$1 extends MaybeRef<unknown> = InferInput<TRules$1>> = isRecordLiteral<TState$1> extends true ? DeepSafeFormState<JoinDiscriminatedUnions<Unwrap<NonNullable<TState$1>>>, TRules$1> : TState$1 extends any[] ? TState$1[] : TState$1;
|
|
466
534
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
* @returns The marked value.
|
|
470
|
-
* @example
|
|
535
|
+
* Infer input type from a rules object
|
|
536
|
+
*
|
|
471
537
|
* ```ts
|
|
472
|
-
*
|
|
473
|
-
* const StaticBigWrapper = markStatic(BigWrapper);
|
|
538
|
+
* type FormRequest = InferInput<typeof rules>;
|
|
474
539
|
* ```
|
|
475
540
|
*/
|
|
476
|
-
declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
|
|
477
|
-
/**
|
|
478
|
-
* Infer type of the `r$` of any function returning a regle instance
|
|
479
|
-
*/
|
|
480
|
-
type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
|
|
481
|
-
/**
|
|
482
|
-
* Infer custom rules declared in a global configuration
|
|
483
|
-
*/
|
|
484
|
-
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
|
|
485
|
-
/**
|
|
486
|
-
* Infer custom shortcuts declared in a global configuration
|
|
487
|
-
*/
|
|
488
|
-
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
489
|
-
/**
|
|
490
|
-
* Extract a set rules and setting them as required
|
|
491
|
-
*/
|
|
492
|
-
type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
493
|
-
/**
|
|
494
|
-
* Extract a set of custom rules from a global configuration and setting them as required
|
|
495
|
-
|
|
496
|
-
*/
|
|
497
|
-
type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules$1 extends keyof InferRegleRules<T>> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
|
|
498
|
-
/**
|
|
499
|
-
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
500
|
-
*/
|
|
501
|
-
type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState$1 extends unknown = any, TRules$1 extends keyof InferRegleRules<T> = never> = RegleFieldStatus<TState$1, [TRules$1] extends [never] ? Partial<InferRegleRules<T>> : RegleEnforceCustomRequiredRules<T, TRules$1>, InferRegleShortcuts<T>>;
|
|
502
|
-
/**
|
|
503
|
-
/**
|
|
504
|
-
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
505
|
-
* exactly matches the structure of type T, including all nested properties.
|
|
506
|
-
*
|
|
507
|
-
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
508
|
-
*/
|
|
509
|
-
type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
|
|
510
|
-
type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
|
|
511
|
-
type TypeError<Msg> = {
|
|
512
|
-
[' TypeError']: Msg;
|
|
513
|
-
};
|
|
514
|
-
type Coerce<T> = `${T & string}`;
|
|
515
541
|
type InferInput<TRules$1 extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TMarkMaybe extends boolean = true> = TRules$1 extends MaybeRef<StandardSchemaV1<infer State>> ? State : IsUnion<UnwrapSimple<TRules$1>> extends true ? InferTupleUnionInput<UnionToTuple<UnwrapSimple<TRules$1>>>[number] : TMarkMaybe extends true ? Prettify<{ [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? K : never]?: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> } & { [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? never : K]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }> : Prettify<{ [K in keyof UnwrapSimple<TRules$1>]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }>;
|
|
516
542
|
type ProcessInputChildren<TRule extends unknown, TMarkMaybe extends boolean> = TRule extends {
|
|
517
543
|
$each: RegleCollectionEachRules<any, any>;
|
|
@@ -522,6 +548,56 @@ type ExtractTypeFromRules<TRules$1 extends RegleRuleDecl<any, any>> = FilterRule
|
|
|
522
548
|
type FilterRulesWithInput<TRules$1 extends RegleRuleDecl<any, any>> = { [K in keyof TRules$1 as TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : K : never]: TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? Input : unknown };
|
|
523
549
|
type FilterRulesWithSingleType<TRules$1 extends RegleRuleDecl<any, any>> = { [K in keyof TRules$1 as TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion<NonNullable<Input>> extends true ? never : K : never]: TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? IsUnion<NonNullable<Input>> extends true ? unknown : Input : unknown };
|
|
524
550
|
type InferTupleUnionInput<T extends any[]> = T extends [infer F extends ReglePartialRuleTree, ...infer R] ? [InferInput<F, true>, ...InferTupleUnionInput<R>] : [];
|
|
551
|
+
/**
|
|
552
|
+
* Infer safe output from any `r$` instance
|
|
553
|
+
*
|
|
554
|
+
* ```ts
|
|
555
|
+
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
556
|
+
* ```
|
|
557
|
+
*
|
|
558
|
+
* @deprecated Use {@link InferValidOutput} instead
|
|
559
|
+
*/
|
|
560
|
+
type InferSafeOutput<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = UnwrapRef<TRegle> extends Raw<RegleRoot<infer TState extends Record<string, any>, infer TRules, any, any>> ? DeepSafeFormState<JoinDiscriminatedUnions<TState>, TRules> : UnwrapRef<TRegle> extends RegleFieldStatus<infer TState, infer TRules> ? SafeFieldProperty<TState, TRules> : UnwrapRef<TRegle> extends RegleLike<infer TState extends Record<string, any>> ? TState : never;
|
|
561
|
+
/**
|
|
562
|
+
* Infer safe output from any `r$` instance
|
|
563
|
+
*
|
|
564
|
+
* ```ts
|
|
565
|
+
* type FormRequest = InferValidOutput<typeof r$>;
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
type InferValidOutput<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = InferSafeOutput<TRegle>;
|
|
569
|
+
/**
|
|
570
|
+
* Infer complete validation result from any `r$` instance
|
|
571
|
+
*/
|
|
572
|
+
type InferRegleValidationResult<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = InferRegleSettings<TRegle> extends {
|
|
573
|
+
state: infer TState;
|
|
574
|
+
rules: infer TRules extends Record<string, any>;
|
|
575
|
+
} ? RegleNestedResult<TState, TRules> : InferRegleSettings<TRegle> extends {
|
|
576
|
+
state: infer TState;
|
|
577
|
+
rules: never;
|
|
578
|
+
} ? ({
|
|
579
|
+
valid: true;
|
|
580
|
+
data: TState;
|
|
581
|
+
} | {
|
|
582
|
+
valid: false;
|
|
583
|
+
data: TState;
|
|
584
|
+
}) & {
|
|
585
|
+
errors: RegleErrorTree<TState>[];
|
|
586
|
+
issues: RegleIssuesTree<TState>;
|
|
587
|
+
} : never;
|
|
588
|
+
/**
|
|
589
|
+
* Infer State and Rules from any `r$` instance
|
|
590
|
+
*/
|
|
591
|
+
type InferRegleSettings<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = UnwrapRef<TRegle> extends Raw<RegleRoot<infer TState extends Record<string, any>, infer TRules extends Record<string, any>, any, any>> ? {
|
|
592
|
+
state: TState;
|
|
593
|
+
rules: TRules;
|
|
594
|
+
} : UnwrapRef<TRegle> extends RegleFieldStatus<infer TState, infer TRules extends Record<string, any>> ? {
|
|
595
|
+
state: TState;
|
|
596
|
+
rules: TRules;
|
|
597
|
+
} : UnwrapRef<TRegle> extends RegleLike<infer TState extends Record<string, any>> ? {
|
|
598
|
+
state: TState;
|
|
599
|
+
rules: never;
|
|
600
|
+
} : never;
|
|
525
601
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
526
602
|
/**
|
|
527
603
|
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
@@ -549,7 +625,7 @@ declare const InternalRuleType: {
|
|
|
549
625
|
readonly Inline: "__inline";
|
|
550
626
|
readonly Async: "__async";
|
|
551
627
|
};
|
|
552
|
-
type InternalRuleType =
|
|
628
|
+
type InternalRuleType = EnumType<typeof InternalRuleType>;
|
|
553
629
|
type IsLiteral<T> = string extends T ? false : true;
|
|
554
630
|
/**
|
|
555
631
|
* Returned typed of rules created with `createRule`
|
|
@@ -623,7 +699,7 @@ type RegleRuleRawInput<TValue$1 extends any = any, TParams$1 extends [...any[]]
|
|
|
623
699
|
type InferRegleRule<TValue$1 extends any = any, TParams$1 extends any[] = [], TAsync$1 extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> = [TParams$1] extends [[]] ? RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetaData> : RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetaData>;
|
|
624
700
|
type RegleRuleDefinitionProcessor<TValue$1 extends any = any, TParams$1 extends any[] = [], TReturn = any> = (value: Maybe<TValue$1>, ...params: TParams$1) => TReturn;
|
|
625
701
|
type RegleRuleDefinitionWithMetadataProcessor<TValue$1 extends any, TMetadata$1 extends RegleRuleMetadataConsumer<TValue$1, any[]>, TReturn = any> = ((metadata: TMetadata$1) => TReturn) | TReturn;
|
|
626
|
-
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<
|
|
702
|
+
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
627
703
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
628
704
|
}) | ({
|
|
629
705
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
@@ -713,7 +789,7 @@ type DefaultValidators = {
|
|
|
713
789
|
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
714
790
|
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
715
791
|
regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
|
|
716
|
-
required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
|
|
792
|
+
required: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
717
793
|
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
718
794
|
string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
|
|
719
795
|
type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
|
|
@@ -724,15 +800,17 @@ type CustomRulesDeclarationTree = {
|
|
|
724
800
|
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
725
801
|
};
|
|
726
802
|
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
727
|
-
type
|
|
803
|
+
type ExtendedRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
804
|
+
/** @deprecated Use {@link ExtendedRulesDeclarations} instead */
|
|
805
|
+
type AllRulesDeclarations = ExtendedRulesDeclarations;
|
|
728
806
|
/**
|
|
729
807
|
* @public
|
|
730
808
|
*/
|
|
731
|
-
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<
|
|
809
|
+
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
732
810
|
/**
|
|
733
811
|
* @public
|
|
734
812
|
*/
|
|
735
|
-
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<
|
|
813
|
+
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = { [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
736
814
|
/**
|
|
737
815
|
* @public
|
|
738
816
|
*/
|
|
@@ -742,7 +820,7 @@ type RegleUnknownRulesTree = {
|
|
|
742
820
|
/**
|
|
743
821
|
* @public
|
|
744
822
|
*/
|
|
745
|
-
type RegleComputedRules<TForm extends
|
|
823
|
+
type RegleComputedRules<TForm extends MaybeRefOrComputedRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<ExtendedRulesDeclarations> | Regle<any, any> | useRegleFn<any> = Partial<ExtendedRulesDeclarations>, TState$1 = Unwrap<UnwrapMaybeRef<TForm>>, TCustom = (TCustomRules extends Regle<any, infer R> ? R extends ReglePartialRuleTree<any, infer C> ? C : Partial<ExtendedRulesDeclarations> : TCustomRules extends useRegleFn<infer Rules, any> ? Rules : {})> = { [TKey in keyof JoinDiscriminatedUnions<TState$1>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState$1>[TKey], Omit<Partial<ExtendedRulesDeclarations>, keyof TCustom> & Partial<TCustom>> };
|
|
746
824
|
/**
|
|
747
825
|
* @internal
|
|
748
826
|
* @reference {@link ReglePartialRuleTree}
|
|
@@ -753,17 +831,19 @@ type $InternalReglePartialRuleTree = {
|
|
|
753
831
|
/**
|
|
754
832
|
* @public
|
|
755
833
|
*/
|
|
756
|
-
type RegleFormPropertyType<TValue$1 = any, TCustomRules extends Partial<
|
|
834
|
+
type RegleFormPropertyType<TValue$1 = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = [NonNullable<TValue$1>] extends [never] ? MaybeRefOrComputedRef<RegleRuleDecl<TValue$1, TCustomRules>> : NonNullable<TValue$1> extends Array<any> ? RegleCollectionRuleDecl<TValue$1, TCustomRules> : NonNullable<TValue$1> extends Date ? MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>> : NonNullable<TValue$1> extends File ? MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>> : NonNullable<TValue$1> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue$1> extends Record<string, any> ? NonNullable<TValue$1> extends RegleStatic<infer U> ? MaybeRefOrComputedRef<RegleRuleDecl<Raw<U>, TCustomRules>> : ReglePartialRuleTree<NonNullable<TValue$1>, TCustomRules> : MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue$1>, TCustomRules>>;
|
|
757
835
|
/**
|
|
758
836
|
* @internal
|
|
759
837
|
* @reference {@link RegleFormPropertyType}
|
|
760
838
|
*/
|
|
761
|
-
type $InternalFormPropertyTypes =
|
|
839
|
+
type $InternalFormPropertyTypes = MaybeRefOrComputedRef<$InternalRegleRuleDecl> | $InternalRegleCollectionRuleDecl | $InternalReglePartialRuleTree | FieldRegleBehaviourOptions;
|
|
762
840
|
/**
|
|
763
841
|
* @public
|
|
764
842
|
* Rule tree for a form property
|
|
765
843
|
*/
|
|
766
|
-
type RegleRuleDecl<TValue$1 extends any = any, TCustomRules extends Partial<
|
|
844
|
+
type RegleRuleDecl<TValue$1 extends any = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<DefaultValidatorsTree>, TOptions extends Record<string, unknown> = FieldRegleBehaviourOptions> = TOptions & { [TKey in keyof RemoveIndexSignature<TCustomRules>]?: FormRuleDeclaration<TValue$1, any[]> } & {
|
|
845
|
+
[x: string]: FormRuleDeclaration<TValue$1, any[]> | boolean | number | undefined;
|
|
846
|
+
};
|
|
767
847
|
/**
|
|
768
848
|
* @internal
|
|
769
849
|
* @reference {@link RegleRuleDecl}
|
|
@@ -778,13 +858,13 @@ type RegleCollectionRuleDeclKeyProperty = {
|
|
|
778
858
|
/**
|
|
779
859
|
* @public
|
|
780
860
|
*/
|
|
781
|
-
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<
|
|
861
|
+
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = ({
|
|
782
862
|
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
783
863
|
} & RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
784
864
|
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
785
865
|
} & CollectionRegleBehaviourOptions);
|
|
786
866
|
/** @public */
|
|
787
|
-
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<
|
|
867
|
+
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>, RegleCollectionRuleDeclKeyProperty>;
|
|
788
868
|
/**
|
|
789
869
|
* @internal
|
|
790
870
|
* @reference {@link RegleCollectionRuleDecl}
|
|
@@ -814,7 +894,7 @@ type ProcessNestedFields<TState$1 extends Record<string, any> | undefined, TRule
|
|
|
814
894
|
/**
|
|
815
895
|
* @public
|
|
816
896
|
*/
|
|
817
|
-
type RegleStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState$1> & {
|
|
897
|
+
type RegleStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState$1, TRules$1> & {
|
|
818
898
|
/** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
|
|
819
899
|
readonly $fields: ProcessNestedFields<TState$1, TRules$1, TShortcuts, true>;
|
|
820
900
|
/**
|
|
@@ -832,7 +912,7 @@ type RegleStatus<TState$1 extends Record<string, any> | undefined = Record<strin
|
|
|
832
912
|
/** Collection of all the error messages, collected for all children properties. */
|
|
833
913
|
readonly $silentErrors: RegleErrorTree<TState$1>;
|
|
834
914
|
/** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
835
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
915
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState$1>;
|
|
836
916
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
|
|
837
917
|
$validate: (forceValues?: JoinDiscriminatedUnions<TState$1> extends EmptyObject ? any : HasNamedKeys<JoinDiscriminatedUnions<TState$1>> extends true ? IsUnknown<JoinDiscriminatedUnions<TState$1>> extends true ? any : JoinDiscriminatedUnions<TState$1> : any) => Promise<RegleNestedResult<JoinDiscriminatedUnions<TState$1>, TRules$1>>;
|
|
838
918
|
} & ProcessNestedFields<TState$1, TRules$1, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
@@ -855,13 +935,13 @@ interface $InternalRegleStatus extends $InternalRegleCommonStatus {
|
|
|
855
935
|
/**
|
|
856
936
|
* @public
|
|
857
937
|
*/
|
|
858
|
-
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState$1 extends Record<PropertyKey, any> = any, TKey$1 extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TState$1> extends true ? [TState$1[TKey$1]] extends [undefined | null] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState$1[TKey$1], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleCollectionStatus<TState$1[TKey$1], {}, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState$1[TKey$1]> extends Array<any> ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Date | File ? RegleFieldStatus<TState$1[TKey$1]
|
|
938
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState$1 extends Record<PropertyKey, any> = any, TKey$1 extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TState$1> extends true ? [TState$1[TKey$1]] extends [undefined | null] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState$1[TKey$1], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleCollectionStatus<TState$1[TKey$1], {}, TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState$1[TKey$1]> extends Array<any> ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Date | File ? RegleFieldStatus<Raw<TState$1[TKey$1]>, TRule, TShortcuts> : unknown extends TState$1[TKey$1] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Record<PropertyKey, any> ? NonNullable<TState$1[TKey$1]> extends RegleStaticImpl<infer U> ? RegleFieldStatus<Raw<U>, TRule, TShortcuts> : MaybeVariantStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Date | File ? RegleFieldStatus<Raw<NonNullable<TState$1[TKey$1]>>, TRule, TShortcuts> : unknown extends TState$1[TKey$1] ? RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : NonNullable<TState$1[TKey$1]> extends Record<PropertyKey, any> ? NonNullable<TState$1[TKey$1]> extends RegleStaticImpl<infer U> ? RegleFieldStatus<Raw<U>, TRule, TShortcuts> : MaybeVariantStatus<TState$1[TKey$1], ReglePartialRuleTree<TState$1[TKey$1]>, TShortcuts> : RegleFieldStatus<TState$1[TKey$1], TRule, TShortcuts> : RegleCommonStatus<unknown>;
|
|
859
939
|
/**
|
|
860
940
|
* @internal
|
|
861
941
|
* @reference {@link InferRegleStatusType}
|
|
862
942
|
*/
|
|
863
943
|
type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
|
|
864
|
-
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<
|
|
944
|
+
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>> = EmptyObject> = {
|
|
865
945
|
readonly $property: string;
|
|
866
946
|
readonly $type?: string;
|
|
867
947
|
readonly $message: string;
|
|
@@ -878,13 +958,13 @@ type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<All
|
|
|
878
958
|
} : {
|
|
879
959
|
readonly $rule: string;
|
|
880
960
|
} }[keyof ComputeFieldRules<any, TRules$1>]);
|
|
881
|
-
type ComputeFieldRules<TState$1 extends any, TRules$1 extends MaybeRef<RegleFormPropertyType<unknown, Partial<
|
|
961
|
+
type ComputeFieldRules<TState$1 extends any, TRules$1 extends MaybeRef<RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>>>> = IsEmptyObject<UnwrapRef<TRules$1>> extends true ? {
|
|
882
962
|
readonly [x: string]: RegleRuleStatus<TState$1, any[], any>;
|
|
883
963
|
} : { readonly [TRuleKey in keyof Omit<UnwrapRef<TRules$1>, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState$1, UnwrapRef<TRules$1>[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], UnwrapRef<TRules$1>[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : UnwrapRef<TRules$1>[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
|
|
884
964
|
/**
|
|
885
965
|
* @public
|
|
886
966
|
*/
|
|
887
|
-
type RegleFieldStatus<TState$1 extends any = any, TRules$1 extends RegleFormPropertyType<unknown, Partial<
|
|
967
|
+
type RegleFieldStatus<TState$1 extends any = any, TRules$1 extends RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState$1, TRules$1>, '$value' | '$silentValue' | '$initialValue' | '$originalValue'> & {
|
|
888
968
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
889
969
|
$value: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
890
970
|
/** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
|
|
@@ -948,7 +1028,7 @@ interface $InternalRegleFieldStatus extends $InternalRegleCommonStatus {
|
|
|
948
1028
|
/**
|
|
949
1029
|
* @public
|
|
950
1030
|
*/
|
|
951
|
-
interface RegleCommonStatus<TValue$1 = any> extends StandardSchemaV1<TValue$1
|
|
1031
|
+
interface RegleCommonStatus<TValue$1 = any, TRules$1 extends Record<string, any> = never> extends StandardSchemaV1<TValue$1, [TRules$1] extends [never] ? TValue$1 : InferOutput<TRules$1, TValue$1>> {
|
|
952
1032
|
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
953
1033
|
readonly $invalid: boolean;
|
|
954
1034
|
/**
|
|
@@ -1080,7 +1160,7 @@ interface $InternalRegleRuleStatus {
|
|
|
1080
1160
|
/**
|
|
1081
1161
|
* @public
|
|
1082
1162
|
*/
|
|
1083
|
-
type RegleCollectionStatus<TState$1 extends any[] = any[], TRules$1 extends ReglePartialRuleTree<ArrayElement<TState$1>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState$1>, '$value'> & {
|
|
1163
|
+
type RegleCollectionStatus<TState$1 extends any[] = any[], TRules$1 extends ReglePartialRuleTree<ArrayElement<TState$1>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState$1, TRules$1>, '$value'> & {
|
|
1084
1164
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1085
1165
|
$value: MaybeOutput<TState$1>;
|
|
1086
1166
|
/** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
|
|
@@ -1102,7 +1182,7 @@ type RegleCollectionStatus<TState$1 extends any[] = any[], TRules$1 extends Regl
|
|
|
1102
1182
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1103
1183
|
readonly $silentErrors: RegleCollectionErrors<TState$1>;
|
|
1104
1184
|
/** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
1105
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1185
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState$1>;
|
|
1106
1186
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
|
|
1107
1187
|
$validate: (value?: JoinDiscriminatedUnions<TState$1>) => Promise<RegleCollectionResult<TState$1, JoinDiscriminatedUnions<TRules$1>>>;
|
|
1108
1188
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
@@ -1121,19 +1201,19 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1121
1201
|
$extractDirtyFields: (filterNullishValues?: boolean) => any[];
|
|
1122
1202
|
$validate: (forceValues?: any) => Promise<$InternalRegleResult>;
|
|
1123
1203
|
}
|
|
1124
|
-
type RegleErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TIssue extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], false, TIssue> };
|
|
1125
|
-
type RegleIssuesTree<TState$1 = MaybeRef<Record<string, any> | any[]
|
|
1126
|
-
type RegleExternalErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]
|
|
1127
|
-
type RegleExternalSchemaErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]
|
|
1204
|
+
type RegleErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TIssue extends boolean = false, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], false, TIssue, TSchema> };
|
|
1205
|
+
type RegleIssuesTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], false, true, TSchema> };
|
|
1206
|
+
type RegleExternalErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], true, TSchema> };
|
|
1207
|
+
type RegleExternalSchemaErrorTree<TState$1 = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState$1>>[K], true, true, TSchema> };
|
|
1128
1208
|
type ErrorMessageOrIssue<TIssue extends boolean> = TIssue extends true ? RegleFieldIssue[] : string[];
|
|
1129
|
-
type RegleValidationErrors<TState$1 extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false> = HasNamedKeys<TState$1> extends true ? IsAny<TState$1> extends true ? any : NonNullable<TState$1> extends Array<infer U> ? U extends Record<string, any> ? TExternal extends false ? ExtendOnlyRealRecord<U> extends true ? RegleCollectionErrors<U, TIssue> : ErrorMessageOrIssue<TIssue> : RegleExternalCollectionErrors<U, TIssue> : ErrorMessageOrIssue<TIssue> : NonNullable<TState$1> extends Date | File ? ErrorMessageOrIssue<TIssue> : NonNullable<TState$1> extends Record<string, any> ? IsRegleStatic<NonNullable<TState$1>> extends true ? ErrorMessageOrIssue<TIssue> : TExternal extends false ? RegleErrorTree<TState$1, TIssue> : RegleExternalErrorTree<TState$1> : ErrorMessageOrIssue<TIssue> : any;
|
|
1130
|
-
type RegleCollectionErrors<TState$1 extends
|
|
1209
|
+
type RegleValidationErrors<TState$1 extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false, TSchema extends boolean = false> = HasNamedKeys<TState$1> extends true ? IsAny<TState$1> extends true ? any : NonNullable<TState$1> extends Array<infer U> ? TSchema extends false ? U extends Record<string, any> ? TExternal extends false ? ExtendOnlyRealRecord<U> extends true ? RegleCollectionErrors<U, TIssue, TSchema> : ErrorMessageOrIssue<TIssue> : RegleExternalCollectionErrors<U, TIssue, TSchema> : ErrorMessageOrIssue<TIssue> : RegleCollectionErrors<U, TIssue, TSchema> : NonNullable<TState$1> extends Date | File ? ErrorMessageOrIssue<TIssue> : NonNullable<TState$1> extends Record<string, any> ? IsRegleStatic<NonNullable<TState$1>> extends true ? ErrorMessageOrIssue<TIssue> : TExternal extends false ? RegleErrorTree<TState$1, TIssue, TSchema> : RegleExternalErrorTree<TState$1, TSchema> : ErrorMessageOrIssue<TIssue> : any;
|
|
1210
|
+
type RegleCollectionErrors<TState$1 extends any, TIssue extends boolean = false, TSchema extends boolean = false> = {
|
|
1131
1211
|
readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
1132
|
-
readonly $each: RegleValidationErrors<TState$1, false, TIssue>[];
|
|
1212
|
+
readonly $each: RegleValidationErrors<TState$1, false, TIssue, TSchema>[];
|
|
1133
1213
|
};
|
|
1134
|
-
type RegleExternalCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false> = {
|
|
1214
|
+
type RegleExternalCollectionErrors<TState$1 extends Record<string, any>, TIssue extends boolean = false, TSchema extends boolean = false> = {
|
|
1135
1215
|
readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
1136
|
-
readonly $each?: RegleValidationErrors<TState$1, true, TIssue>[];
|
|
1216
|
+
readonly $each?: RegleValidationErrors<TState$1, true, TIssue, TSchema>[];
|
|
1137
1217
|
};
|
|
1138
1218
|
/** @internal */
|
|
1139
1219
|
type $InternalRegleCollectionErrors = {
|
|
@@ -1258,7 +1338,7 @@ declare function unwrapRuleParameters<TParams$1 extends any[]>(params: MaybeRefO
|
|
|
1258
1338
|
* - a `useRegle` composable that can typecheck your custom rules
|
|
1259
1339
|
* - an `inferRules` helper that can typecheck your custom rules
|
|
1260
1340
|
*/
|
|
1261
|
-
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<
|
|
1341
|
+
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<ExtendedRulesDeclarations>>({
|
|
1262
1342
|
rules,
|
|
1263
1343
|
modifiers,
|
|
1264
1344
|
shortcuts
|
|
@@ -1279,7 +1359,7 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
|
|
|
1279
1359
|
* - a `useRegle` composable that can typecheck your custom rules
|
|
1280
1360
|
* - an `inferRules` helper that can typecheck your custom rules
|
|
1281
1361
|
*/
|
|
1282
|
-
declare function extendRegleConfig<TRootCustomRules extends Partial<
|
|
1362
|
+
declare function extendRegleConfig<TRootCustomRules extends Partial<ExtendedRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<ExtendedRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
|
|
1283
1363
|
rules,
|
|
1284
1364
|
modifiers,
|
|
1285
1365
|
shortcuts
|
|
@@ -1307,7 +1387,7 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
|
|
|
1307
1387
|
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
1308
1388
|
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
1309
1389
|
/** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
1310
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1390
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>[];
|
|
1311
1391
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
|
|
1312
1392
|
$validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
|
|
1313
1393
|
} & (HasNamedKeys<TRegles> extends true ? { [K in keyof TRegles]: TRegles[K] } : {});
|
|
@@ -1325,7 +1405,7 @@ type MergedScopedRegles<TValue$1 extends Record<string, unknown>[] = Record<stri
|
|
|
1325
1405
|
/** Collection of all registered Regles instances silent issues */
|
|
1326
1406
|
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
1327
1407
|
/** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
1328
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1408
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>;
|
|
1329
1409
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
|
|
1330
1410
|
$validate: (forceValues?: TValue$1) => Promise<{
|
|
1331
1411
|
valid: boolean;
|
|
@@ -1380,10 +1460,10 @@ type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsR
|
|
|
1380
1460
|
*/
|
|
1381
1461
|
asRecord?: TAsRecord;
|
|
1382
1462
|
};
|
|
1383
|
-
declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<
|
|
1463
|
+
declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<ExtendedRulesDeclarations>>, TAsRecord extends boolean = false, TReturnedRegle extends useRegleFn<any, any, any, any> = (TCustomRegle extends useRegleFn<infer A, infer B> ? useRegleFn<A, B, {
|
|
1384
1464
|
dispose: () => void;
|
|
1385
1465
|
register: () => void;
|
|
1386
|
-
}, UseScopedRegleOptions<TAsRecord>> : useRegleFn<Partial<
|
|
1466
|
+
}, UseScopedRegleOptions<TAsRecord>> : useRegleFn<Partial<ExtendedRulesDeclarations>, any, {
|
|
1387
1467
|
dispose: () => void;
|
|
1388
1468
|
register: () => void;
|
|
1389
1469
|
}, UseScopedRegleOptions<TAsRecord>>)>(options?: CreateScopedUseRegleOptions<TCustomRegle, TAsRecord>): {
|
|
@@ -1392,7 +1472,7 @@ declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any>
|
|
|
1392
1472
|
};
|
|
1393
1473
|
declare const useCollectScope: <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string | string[]>) => {
|
|
1394
1474
|
r$: MergedScopedRegles<TValue$1>;
|
|
1395
|
-
}, useScopedRegle: useRegleFn<Partial<
|
|
1475
|
+
}, useScopedRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, never, {
|
|
1396
1476
|
dispose: () => void;
|
|
1397
1477
|
register: () => void;
|
|
1398
1478
|
}, {
|
|
@@ -1484,4 +1564,4 @@ declare function defineRules<TRules$1 extends RegleUnknownRulesTree>(rules: TRul
|
|
|
1484
1564
|
*/
|
|
1485
1565
|
declare function refineRules<TRules$1 extends RegleUnknownRulesTree, TRefinement extends ReglePartialRuleTree<InferInput<TRules$1>> & RegleUnknownRulesTree>(rules: TRules$1, refinement: (state: Ref<InferInput<TRules$1>>) => TRefinement): (state: Ref<InferInput<TRules$1>>) => Merge<TRules$1, TRefinement>;
|
|
1486
1566
|
declare const RegleVuePlugin: Plugin;
|
|
1487
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type ArrayElement, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepReactiveState, type DefaultValidatorsTree, type FormRuleDeclaration, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InferSafeOutput, type InlineRuleDeclaration, InternalRuleType, type IsRegleStatic, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NarrowVariantExtracts, type NarrowVariantFieldExtracts, type NoInferLegacy, type NonEmptyTuple, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, 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 RegleSingleField, type RegleStatic, type RegleStaticImpl, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, RegleVuePlugin, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type TupleToPlainObj, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UnwrapStatic, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, markStatic, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useRules, type useRulesFn, useScopedRegle, variantToRef };
|
|
1567
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type ArrayElement, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepPartial, type DeepReactiveState, type DefaultValidatorsTree, type ExtendedRulesDeclarations, type FormRuleDeclaration, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferOutput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleSettings, type InferRegleShortcuts, type InferRegleStatusType, type InferRegleValidationResult, type InferSafeOutput, type InferValidOutput, type InlineRuleDeclaration, InternalRuleType, type IsRegleStatic, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NarrowVariantExtracts, type NarrowVariantFieldExtracts, type NoInferLegacy, type NonEmptyTuple, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, type RegleLike, type RegleNestedResult, 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 RegleRuleWithParamsDefinitionInput, type RegleShortcutDefinition, type RegleSingleField, type RegleStatic, type RegleStaticImpl, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, RegleVuePlugin, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type TupleToPlainObj, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UnwrapStatic, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, markStatic, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useRules, type useRulesFn, useScopedRegle, variantToRef };
|