@regle/core 1.13.0 → 1.14.0-beta.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 +612 -280
- package/dist/regle-core.js +377 -104
- package/dist/regle-core.min.js +1 -1
- package/package.json +1 -1
package/dist/regle-core.d.ts
CHANGED
|
@@ -1,7 +1,245 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
2
|
import { ComputedRef, MaybeRef, MaybeRefOrGetter, Plugin, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
3
|
-
import { EmptyObject, IsAny, IsEmptyObject, IsUnion, IsUnknown, Merge, Or,
|
|
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
|
+
* It transforms your data and validation rules into a powerful, reactive validation system.
|
|
56
|
+
*
|
|
57
|
+
* @param state - Your form data (plain object, ref, reactive object, or structure with nested refs)
|
|
58
|
+
* @param rules - Validation rules that should align with the structure of your state
|
|
59
|
+
* @param modifiers - Optional configuration to customize regle behavior
|
|
60
|
+
* @returns An object containing `r$` - the reactive validation state
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { useRegle } from '@regle/core';
|
|
65
|
+
* import { required, email, minLength } from '@regle/rules';
|
|
66
|
+
*
|
|
67
|
+
* const { r$ } = useRegle(
|
|
68
|
+
* { name: '', email: '' },
|
|
69
|
+
* {
|
|
70
|
+
* name: { required, minLength: minLength(2) },
|
|
71
|
+
* email: { required, email }
|
|
72
|
+
* }
|
|
73
|
+
* );
|
|
74
|
+
*
|
|
75
|
+
* // Access validation state
|
|
76
|
+
* r$.$valid // Whether all validations pass
|
|
77
|
+
* r$.$value // The current form values
|
|
78
|
+
* r$.name.$errors // Errors for the name field
|
|
79
|
+
*
|
|
80
|
+
* // Trigger validation
|
|
81
|
+
* const result = await r$.$validate();
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://reglejs.dev/core-concepts/ Documentation}
|
|
85
|
+
*/
|
|
86
|
+
declare const useRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
87
|
+
interface inferRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>> {
|
|
88
|
+
<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;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type helper to provide autocomplete and type-checking for your form rules.
|
|
92
|
+
* It returns the rules without any processing - useful with computed rules.
|
|
93
|
+
*
|
|
94
|
+
* @param state - The state reference
|
|
95
|
+
* @param rules - Your rule tree
|
|
96
|
+
* @returns The rules object (passthrough)
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { inferRules, useRegle } from '@regle/core';
|
|
101
|
+
* import { required, minLength } from '@regle/rules';
|
|
102
|
+
*
|
|
103
|
+
* const state = ref({ name: '' });
|
|
104
|
+
*
|
|
105
|
+
* // inferRules preserves TypeScript autocompletion
|
|
106
|
+
* const rules = computed(() => {
|
|
107
|
+
* return inferRules(state, {
|
|
108
|
+
* name: { required, minLength: minLength(2) }
|
|
109
|
+
* })
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* const { r$ } = useRegle(state, rules);
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @see {@link https://reglejs.dev/core-concepts/#dynamic-rules-object Documentation}
|
|
116
|
+
*/
|
|
117
|
+
declare const inferRules: inferRulesFn<Partial<ExtendedRulesDeclarations>>;
|
|
118
|
+
declare function useRootStorage({
|
|
119
|
+
initialState,
|
|
120
|
+
originalState,
|
|
121
|
+
options,
|
|
122
|
+
scopeRules,
|
|
123
|
+
state,
|
|
124
|
+
customRules,
|
|
125
|
+
shortcuts,
|
|
126
|
+
schemaErrors,
|
|
127
|
+
schemaMode,
|
|
128
|
+
onValidate
|
|
129
|
+
}: {
|
|
130
|
+
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
131
|
+
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
132
|
+
options: ResolvedRegleBehaviourOptions;
|
|
133
|
+
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
134
|
+
originalState: Record<string, any> | PrimitiveTypes;
|
|
135
|
+
customRules?: () => CustomRulesDeclarationTree;
|
|
136
|
+
shortcuts: RegleShortcutDefinition | undefined;
|
|
137
|
+
schemaErrors?: Ref<any | undefined>;
|
|
138
|
+
schemaMode?: boolean;
|
|
139
|
+
onValidate?: () => Promise<$InternalRegleResult>;
|
|
140
|
+
}): {
|
|
141
|
+
regle: $InternalRegleStatusType | undefined;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Converts a nested $errors object to a flat array of string errors
|
|
145
|
+
*
|
|
146
|
+
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
147
|
+
*/
|
|
148
|
+
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
149
|
+
includePath: true;
|
|
150
|
+
}): StandardSchemaV1.Issue[];
|
|
151
|
+
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
152
|
+
includePath?: false;
|
|
153
|
+
}): string[];
|
|
154
|
+
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>;
|
|
155
|
+
interface useRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
156
|
+
<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>;
|
|
157
|
+
__config?: {
|
|
158
|
+
rules?: () => CustomRulesDeclarationTree;
|
|
159
|
+
modifiers?: RegleBehaviourOptions;
|
|
160
|
+
shortcuts?: TShortcuts;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* `useRules` is a variant of `useRegle` that doesn't require you to provide initial state.
|
|
165
|
+
* It creates an empty state based on your rules structure and implements the Standard Schema spec.
|
|
166
|
+
*
|
|
167
|
+
* This is useful when you want to define validation rules first and infer the state type from them.
|
|
168
|
+
*
|
|
169
|
+
* @param rules - Your validation rules object
|
|
170
|
+
* @param modifiers - Optional configuration to customize regle behavior
|
|
171
|
+
* @returns The reactive validation state (implements StandardSchemaV1)
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { useRules, type InferInput } from '@regle/core';
|
|
176
|
+
* import { required, string, email } from '@regle/rules';
|
|
177
|
+
*
|
|
178
|
+
* const r$ = useRules({
|
|
179
|
+
* name: { required, string },
|
|
180
|
+
* email: { required, email }
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* // State is automatically created and typed
|
|
184
|
+
* r$.$value.name // string | null
|
|
185
|
+
* r$.$value.email // string | null
|
|
186
|
+
*
|
|
187
|
+
* // Can be used with Standard Schema compatible libraries
|
|
188
|
+
* const result = await r$['~standard'].validate({ name: '', email: '' });
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @see {@link https://reglejs.dev/common-usage/standard-schema#userules Documentation}
|
|
192
|
+
*/
|
|
193
|
+
declare const useRules: useRulesFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>>;
|
|
194
|
+
/**
|
|
195
|
+
* Marks a value as static and treats the constructor as a regular raw Field.
|
|
196
|
+
* @param value - The value to mark as static.
|
|
197
|
+
* @returns The marked value.
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const StaticDecimal = markStatic(Decimal);
|
|
201
|
+
* const StaticBigWrapper = markStatic(BigWrapper);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
|
|
205
|
+
/**
|
|
206
|
+
* Infer type of the `r$` of any function returning a regle instance
|
|
207
|
+
*/
|
|
208
|
+
type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
|
|
209
|
+
/**
|
|
210
|
+
* Infer custom rules declared in a global configuration
|
|
211
|
+
*/
|
|
212
|
+
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
|
|
213
|
+
/**
|
|
214
|
+
* Infer custom shortcuts declared in a global configuration
|
|
215
|
+
*/
|
|
216
|
+
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
217
|
+
/**
|
|
218
|
+
* Extract a set rules and setting them as required
|
|
219
|
+
*/
|
|
220
|
+
type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
221
|
+
/**
|
|
222
|
+
* Extract a set of custom rules from a global configuration and setting them as required
|
|
223
|
+
|
|
224
|
+
*/
|
|
225
|
+
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 };
|
|
226
|
+
/**
|
|
227
|
+
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
228
|
+
*/
|
|
229
|
+
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>>;
|
|
230
|
+
/**
|
|
231
|
+
/**
|
|
232
|
+
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
233
|
+
* exactly matches the structure of type T, including all nested properties.
|
|
234
|
+
*
|
|
235
|
+
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
236
|
+
*/
|
|
237
|
+
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>}>`> };
|
|
238
|
+
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] };
|
|
239
|
+
type TypeError<Msg> = {
|
|
240
|
+
[' TypeError']: Msg;
|
|
241
|
+
};
|
|
242
|
+
type Coerce<T> = `${T & string}`;
|
|
5
243
|
interface RegleBehaviourOptions {
|
|
6
244
|
/**
|
|
7
245
|
* Only display error when calling `r$.$validate()`
|
|
@@ -189,10 +427,10 @@ type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
|
189
427
|
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
428
|
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
|
|
191
429
|
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
|
|
430
|
+
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
431
|
} | {
|
|
194
432
|
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
|
|
433
|
+
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
434
|
};
|
|
197
435
|
type RegleNestedResult<Data extends Record<string, any> | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
|
|
198
436
|
/**
|
|
@@ -237,14 +475,6 @@ type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<an
|
|
|
237
475
|
issues: [];
|
|
238
476
|
errors: [];
|
|
239
477
|
});
|
|
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
478
|
type $InternalRegleResult = {
|
|
249
479
|
valid: boolean;
|
|
250
480
|
data: any;
|
|
@@ -252,7 +482,7 @@ type $InternalRegleResult = {
|
|
|
252
482
|
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
253
483
|
};
|
|
254
484
|
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
|
|
485
|
+
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
486
|
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
487
|
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
488
|
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 +514,27 @@ type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Recor
|
|
|
284
514
|
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
515
|
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
516
|
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<
|
|
517
|
+
[x: string]: { [K in TKey$1]-?: Omit<RegleRuleDecl<any, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
288
518
|
literal?: RegleRuleDefinition<any, [literal: any], false, boolean, any, string | number>;
|
|
289
519
|
} };
|
|
290
|
-
} : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<
|
|
520
|
+
} : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
291
521
|
literal?: RegleRuleDefinition<MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number>;
|
|
292
522
|
} } };
|
|
293
523
|
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
524
|
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
525
|
/**
|
|
297
|
-
*
|
|
526
|
+
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
298
527
|
*/
|
|
299
|
-
|
|
300
|
-
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
528
|
+
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
529
|
/**
|
|
302
|
-
*
|
|
530
|
+
* Combine all members of a union type on one level and not nested.
|
|
303
531
|
*/
|
|
304
|
-
type
|
|
532
|
+
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;
|
|
533
|
+
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
534
|
/**
|
|
306
|
-
*
|
|
535
|
+
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
307
536
|
*/
|
|
308
|
-
type
|
|
537
|
+
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
|
|
309
538
|
/**
|
|
310
539
|
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
311
540
|
*/
|
|
@@ -315,204 +544,47 @@ type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string>
|
|
|
315
544
|
*/
|
|
316
545
|
type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
317
546
|
/**
|
|
318
|
-
*
|
|
547
|
+
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
319
548
|
*/
|
|
320
|
-
type
|
|
549
|
+
type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
|
|
550
|
+
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K] };
|
|
321
551
|
/**
|
|
322
|
-
*
|
|
552
|
+
* Merge every boolean property into a single boolean.
|
|
323
553
|
*/
|
|
324
|
-
type
|
|
325
|
-
|
|
554
|
+
type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
|
|
555
|
+
/**
|
|
556
|
+
* Ensure that if at least one prop is required, the "prop" object will be required too
|
|
557
|
+
*/
|
|
558
|
+
type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
|
|
559
|
+
type EnumType<T extends Record<string, unknown>> = T[keyof T];
|
|
326
560
|
type EnumLike = {
|
|
327
561
|
[k: string]: string | number;
|
|
328
562
|
[nu: number]: string;
|
|
329
563
|
};
|
|
330
|
-
type enumType<T extends Record<string, unknown>> = T[keyof T];
|
|
331
564
|
type MaybeRefOrComputedRef<T extends any> = MaybeRef<T> | ComputedRef<T>;
|
|
332
565
|
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
333
|
-
type UnwrapStatic<T> = IsUnknown<T> extends true ? any : NonNullable<T> extends RegleStaticImpl<infer U> ? Raw<U> : UnwrapStaticSimple<T>;
|
|
334
|
-
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;
|
|
335
566
|
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
336
567
|
type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
|
|
337
568
|
type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
|
|
338
|
-
declare const RegleStaticSymbol: unique symbol;
|
|
339
|
-
type RegleStatic<T> = T extends (new (...args: infer Args) => infer U) ? RegleStaticImpl<new (...args: Args) => RegleStaticImpl<U>> : RegleStaticImpl<T>;
|
|
340
|
-
type RegleStaticImpl<T> = Raw<T & {
|
|
341
|
-
[RegleStaticSymbol]: true;
|
|
342
|
-
}>;
|
|
343
|
-
type IsRegleStatic<T> = T extends RegleStaticImpl<T> ? true : false;
|
|
344
|
-
type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
345
|
-
type Maybe<T = any> = T | null | undefined;
|
|
346
|
-
type MaybeInput<T = any> = T | null | undefined;
|
|
347
|
-
type MaybeOutput<T = any> = T | undefined;
|
|
348
|
-
type MaybeReadonly<T> = T | Readonly<T>;
|
|
349
|
-
type NonUndefined<T> = Exclude<T, undefined>;
|
|
350
|
-
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
351
|
-
type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
|
|
352
|
-
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
353
|
-
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends ((...args: any[]) => infer U) ? U : T;
|
|
354
|
-
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
355
|
-
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
356
|
-
type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
|
|
357
|
-
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
358
|
-
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] };
|
|
359
|
-
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
360
|
-
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
361
|
-
type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
|
|
362
|
-
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
363
|
-
type NonEmptyTuple<T> = [T, ...T[]] | T[];
|
|
364
|
-
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;
|
|
365
|
-
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
366
|
-
<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> & Partial<TCustomRules>>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<AllRulesDeclarations> & 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>;
|
|
367
|
-
__config?: {
|
|
368
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
369
|
-
modifiers?: RegleBehaviourOptions;
|
|
370
|
-
shortcuts?: TShortcuts;
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
569
|
/**
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* It accepts the following inputs:
|
|
377
|
-
*
|
|
378
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
379
|
-
* @param rules - These should align with the structure of your state.
|
|
380
|
-
* @param modifiers - Customize regle behaviour
|
|
381
|
-
*
|
|
382
|
-
* ```ts
|
|
383
|
-
* import { useRegle } from '@regle/core';
|
|
384
|
-
import { required } from '@regle/rules';
|
|
385
|
-
|
|
386
|
-
const { r$ } = useRegle({ email: '' }, {
|
|
387
|
-
email: { required }
|
|
388
|
-
})
|
|
389
|
-
* ```
|
|
390
|
-
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
570
|
+
* Convert a nested object to a deeply nested partial object.
|
|
391
571
|
*/
|
|
392
|
-
|
|
393
|
-
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
394
|
-
<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> | undefined, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? TDecl : TState$1 extends Record<string, any> ? TRules$1 : {}): NonNullable<TState$1> extends PrimitiveTypes ? TDecl : TRules$1;
|
|
395
|
-
}
|
|
572
|
+
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;
|
|
396
573
|
/**
|
|
397
|
-
*
|
|
398
|
-
* It will just return the rules without any processing.
|
|
399
|
-
*
|
|
400
|
-
* @param state - The state reference
|
|
401
|
-
* @param rules - Your rule tree
|
|
402
|
-
*/
|
|
403
|
-
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
404
|
-
declare function useRootStorage({
|
|
405
|
-
initialState,
|
|
406
|
-
originalState,
|
|
407
|
-
options,
|
|
408
|
-
scopeRules,
|
|
409
|
-
state,
|
|
410
|
-
customRules,
|
|
411
|
-
shortcuts,
|
|
412
|
-
schemaErrors,
|
|
413
|
-
schemaMode,
|
|
414
|
-
onValidate
|
|
415
|
-
}: {
|
|
416
|
-
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
417
|
-
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
418
|
-
options: ResolvedRegleBehaviourOptions;
|
|
419
|
-
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
420
|
-
originalState: Record<string, any> | PrimitiveTypes;
|
|
421
|
-
customRules?: () => CustomRulesDeclarationTree;
|
|
422
|
-
shortcuts: RegleShortcutDefinition | undefined;
|
|
423
|
-
schemaErrors?: Ref<any | undefined>;
|
|
424
|
-
schemaMode?: boolean;
|
|
425
|
-
onValidate?: () => Promise<$InternalRegleResult>;
|
|
426
|
-
}): {
|
|
427
|
-
regle: $InternalRegleStatusType | undefined;
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* Converts a nested $errors object to a flat array of string errors
|
|
431
|
-
*
|
|
432
|
-
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
433
|
-
*/
|
|
434
|
-
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
435
|
-
includePath: true;
|
|
436
|
-
}): StandardSchemaV1.Issue[];
|
|
437
|
-
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
438
|
-
includePath?: false;
|
|
439
|
-
}): string[];
|
|
440
|
-
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>;
|
|
441
|
-
interface useRulesFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
442
|
-
<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>;
|
|
443
|
-
__config?: {
|
|
444
|
-
rules?: () => CustomRulesDeclarationTree;
|
|
445
|
-
modifiers?: RegleBehaviourOptions;
|
|
446
|
-
shortcuts?: TShortcuts;
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* useRules is a clone of useRegle, without the need to provide a state.
|
|
451
|
-
*
|
|
452
|
-
* It accepts the following inputs:
|
|
453
|
-
*
|
|
454
|
-
* @param rules - Your rules object
|
|
455
|
-
* @param modifiers - Customize regle behaviour
|
|
574
|
+
* Infer safe output type from a rules object and it's original state type
|
|
456
575
|
*
|
|
457
576
|
* ```ts
|
|
458
|
-
*
|
|
459
|
-
import { required } from '@regle/rules';
|
|
460
|
-
|
|
461
|
-
const { r$ } = useRules({
|
|
462
|
-
email: { required }
|
|
463
|
-
})
|
|
577
|
+
* type FormRequest = InferOutput<typeof rules, typeof formState>;
|
|
464
578
|
* ```
|
|
465
579
|
*/
|
|
466
|
-
|
|
580
|
+
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;
|
|
467
581
|
/**
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
* @returns The marked value.
|
|
471
|
-
* @example
|
|
582
|
+
* Infer input type from a rules object
|
|
583
|
+
*
|
|
472
584
|
* ```ts
|
|
473
|
-
*
|
|
474
|
-
* const StaticBigWrapper = markStatic(BigWrapper);
|
|
585
|
+
* type FormRequest = InferInput<typeof rules>;
|
|
475
586
|
* ```
|
|
476
587
|
*/
|
|
477
|
-
declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
|
|
478
|
-
/**
|
|
479
|
-
* Infer type of the `r$` of any function returning a regle instance
|
|
480
|
-
*/
|
|
481
|
-
type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
|
|
482
|
-
/**
|
|
483
|
-
* Infer custom rules declared in a global configuration
|
|
484
|
-
*/
|
|
485
|
-
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
|
|
486
|
-
/**
|
|
487
|
-
* Infer custom shortcuts declared in a global configuration
|
|
488
|
-
*/
|
|
489
|
-
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
490
|
-
/**
|
|
491
|
-
* Extract a set rules and setting them as required
|
|
492
|
-
*/
|
|
493
|
-
type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
494
|
-
/**
|
|
495
|
-
* Extract a set of custom rules from a global configuration and setting them as required
|
|
496
|
-
|
|
497
|
-
*/
|
|
498
|
-
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 };
|
|
499
|
-
/**
|
|
500
|
-
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
501
|
-
*/
|
|
502
|
-
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>>;
|
|
503
|
-
/**
|
|
504
|
-
/**
|
|
505
|
-
* DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
|
|
506
|
-
* exactly matches the structure of type T, including all nested properties.
|
|
507
|
-
*
|
|
508
|
-
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
509
|
-
*/
|
|
510
|
-
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>}>`> };
|
|
511
|
-
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] };
|
|
512
|
-
type TypeError<Msg> = {
|
|
513
|
-
[' TypeError']: Msg;
|
|
514
|
-
};
|
|
515
|
-
type Coerce<T> = `${T & string}`;
|
|
516
588
|
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> }>;
|
|
517
589
|
type ProcessInputChildren<TRule extends unknown, TMarkMaybe extends boolean> = TRule extends {
|
|
518
590
|
$each: RegleCollectionEachRules<any, any>;
|
|
@@ -523,6 +595,56 @@ type ExtractTypeFromRules<TRules$1 extends RegleRuleDecl<any, any>> = FilterRule
|
|
|
523
595
|
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 };
|
|
524
596
|
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 };
|
|
525
597
|
type InferTupleUnionInput<T extends any[]> = T extends [infer F extends ReglePartialRuleTree, ...infer R] ? [InferInput<F, true>, ...InferTupleUnionInput<R>] : [];
|
|
598
|
+
/**
|
|
599
|
+
* Infer safe output from any `r$` instance
|
|
600
|
+
*
|
|
601
|
+
* ```ts
|
|
602
|
+
* type FormRequest = InferSafeOutput<typeof r$>;
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* @deprecated Use {@link InferValidOutput} instead
|
|
606
|
+
*/
|
|
607
|
+
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;
|
|
608
|
+
/**
|
|
609
|
+
* Infer safe output from any `r$` instance
|
|
610
|
+
*
|
|
611
|
+
* ```ts
|
|
612
|
+
* type FormRequest = InferValidOutput<typeof r$>;
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
type InferValidOutput<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = InferSafeOutput<TRegle>;
|
|
616
|
+
/**
|
|
617
|
+
* Infer complete validation result from any `r$` instance
|
|
618
|
+
*/
|
|
619
|
+
type InferRegleValidationResult<TRegle extends MaybeRef<SuperCompatibleRegleRoot | SuperCompatibleRegleFieldStatus>> = InferRegleSettings<TRegle> extends {
|
|
620
|
+
state: infer TState;
|
|
621
|
+
rules: infer TRules extends Record<string, any>;
|
|
622
|
+
} ? RegleNestedResult<TState, TRules> : InferRegleSettings<TRegle> extends {
|
|
623
|
+
state: infer TState;
|
|
624
|
+
rules: never;
|
|
625
|
+
} ? ({
|
|
626
|
+
valid: true;
|
|
627
|
+
data: TState;
|
|
628
|
+
} | {
|
|
629
|
+
valid: false;
|
|
630
|
+
data: TState;
|
|
631
|
+
}) & {
|
|
632
|
+
errors: RegleErrorTree<TState>[];
|
|
633
|
+
issues: RegleIssuesTree<TState>;
|
|
634
|
+
} : never;
|
|
635
|
+
/**
|
|
636
|
+
* Infer State and Rules from any `r$` instance
|
|
637
|
+
*/
|
|
638
|
+
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>> ? {
|
|
639
|
+
state: TState;
|
|
640
|
+
rules: TRules;
|
|
641
|
+
} : UnwrapRef<TRegle> extends RegleFieldStatus<infer TState, infer TRules extends Record<string, any>> ? {
|
|
642
|
+
state: TState;
|
|
643
|
+
rules: TRules;
|
|
644
|
+
} : UnwrapRef<TRegle> extends RegleLike<infer TState extends Record<string, any>> ? {
|
|
645
|
+
state: TState;
|
|
646
|
+
rules: never;
|
|
647
|
+
} : never;
|
|
526
648
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
527
649
|
/**
|
|
528
650
|
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
@@ -550,7 +672,7 @@ declare const InternalRuleType: {
|
|
|
550
672
|
readonly Inline: "__inline";
|
|
551
673
|
readonly Async: "__async";
|
|
552
674
|
};
|
|
553
|
-
type InternalRuleType =
|
|
675
|
+
type InternalRuleType = EnumType<typeof InternalRuleType>;
|
|
554
676
|
type IsLiteral<T> = string extends T ? false : true;
|
|
555
677
|
/**
|
|
556
678
|
* Returned typed of rules created with `createRule`
|
|
@@ -624,7 +746,7 @@ type RegleRuleRawInput<TValue$1 extends any = any, TParams$1 extends [...any[]]
|
|
|
624
746
|
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>;
|
|
625
747
|
type RegleRuleDefinitionProcessor<TValue$1 extends any = any, TParams$1 extends any[] = [], TReturn = any> = (value: Maybe<TValue$1>, ...params: TParams$1) => TReturn;
|
|
626
748
|
type RegleRuleDefinitionWithMetadataProcessor<TValue$1 extends any, TMetadata$1 extends RegleRuleMetadataConsumer<TValue$1, any[]>, TReturn = any> = ((metadata: TMetadata$1) => TReturn) | TReturn;
|
|
627
|
-
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<
|
|
749
|
+
type RegleCollectionRuleDefinition<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
628
750
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
629
751
|
}) | ({
|
|
630
752
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>>;
|
|
@@ -725,15 +847,17 @@ type CustomRulesDeclarationTree = {
|
|
|
725
847
|
[x: string]: RegleRuleRawInput<any, any[], boolean, any> | undefined;
|
|
726
848
|
};
|
|
727
849
|
type DefaultValidatorsTree = { [K in keyof DefaultValidators]: RegleRuleRawInput<any, any[], boolean, any> | undefined };
|
|
728
|
-
type
|
|
850
|
+
type ExtendedRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
|
|
851
|
+
/** @deprecated Use {@link ExtendedRulesDeclarations} instead */
|
|
852
|
+
type AllRulesDeclarations = ExtendedRulesDeclarations;
|
|
729
853
|
/**
|
|
730
854
|
* @public
|
|
731
855
|
*/
|
|
732
|
-
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<
|
|
856
|
+
type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
733
857
|
/**
|
|
734
858
|
* @public
|
|
735
859
|
*/
|
|
736
|
-
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<
|
|
860
|
+
type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = { [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules> };
|
|
737
861
|
/**
|
|
738
862
|
* @public
|
|
739
863
|
*/
|
|
@@ -743,7 +867,7 @@ type RegleUnknownRulesTree = {
|
|
|
743
867
|
/**
|
|
744
868
|
* @public
|
|
745
869
|
*/
|
|
746
|
-
type RegleComputedRules<TForm extends MaybeRefOrComputedRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<
|
|
870
|
+
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>> };
|
|
747
871
|
/**
|
|
748
872
|
* @internal
|
|
749
873
|
* @reference {@link ReglePartialRuleTree}
|
|
@@ -754,7 +878,7 @@ type $InternalReglePartialRuleTree = {
|
|
|
754
878
|
/**
|
|
755
879
|
* @public
|
|
756
880
|
*/
|
|
757
|
-
type RegleFormPropertyType<TValue$1 = any, TCustomRules extends Partial<
|
|
881
|
+
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>>;
|
|
758
882
|
/**
|
|
759
883
|
* @internal
|
|
760
884
|
* @reference {@link RegleFormPropertyType}
|
|
@@ -764,7 +888,9 @@ type $InternalFormPropertyTypes = MaybeRefOrComputedRef<$InternalRegleRuleDecl>
|
|
|
764
888
|
* @public
|
|
765
889
|
* Rule tree for a form property
|
|
766
890
|
*/
|
|
767
|
-
type RegleRuleDecl<TValue$1 extends any = any, TCustomRules extends Partial<
|
|
891
|
+
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[]> } & {
|
|
892
|
+
[x: string]: FormRuleDeclaration<TValue$1, any[]> | boolean | number | undefined;
|
|
893
|
+
};
|
|
768
894
|
/**
|
|
769
895
|
* @internal
|
|
770
896
|
* @reference {@link RegleRuleDecl}
|
|
@@ -779,13 +905,13 @@ type RegleCollectionRuleDeclKeyProperty = {
|
|
|
779
905
|
/**
|
|
780
906
|
* @public
|
|
781
907
|
*/
|
|
782
|
-
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<
|
|
908
|
+
type RegleCollectionRuleDecl<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = ({
|
|
783
909
|
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
784
910
|
} & RegleRuleDecl<NonNullable<TValue$1>, TCustomRules, CollectionRegleBehaviourOptions>) | ({
|
|
785
911
|
$each?: RegleCollectionEachRules<TValue$1, TCustomRules>;
|
|
786
912
|
} & CollectionRegleBehaviourOptions);
|
|
787
913
|
/** @public */
|
|
788
|
-
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<
|
|
914
|
+
type RegleCollectionEachRules<TValue$1 = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue$1>>, TCustomRules>, ArrayElement<TValue$1>, RegleCollectionRuleDeclKeyProperty>;
|
|
789
915
|
/**
|
|
790
916
|
* @internal
|
|
791
917
|
* @reference {@link RegleCollectionRuleDecl}
|
|
@@ -815,7 +941,7 @@ type ProcessNestedFields<TState$1 extends Record<string, any> | undefined, TRule
|
|
|
815
941
|
/**
|
|
816
942
|
* @public
|
|
817
943
|
*/
|
|
818
|
-
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> & {
|
|
944
|
+
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> & {
|
|
819
945
|
/** 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. */
|
|
820
946
|
readonly $fields: ProcessNestedFields<TState$1, TRules$1, TShortcuts, true>;
|
|
821
947
|
/**
|
|
@@ -833,7 +959,7 @@ type RegleStatus<TState$1 extends Record<string, any> | undefined = Record<strin
|
|
|
833
959
|
/** Collection of all the error messages, collected for all children properties. */
|
|
834
960
|
readonly $silentErrors: RegleErrorTree<TState$1>;
|
|
835
961
|
/** 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). */
|
|
836
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
962
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState$1>;
|
|
837
963
|
/** 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). */
|
|
838
964
|
$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>>;
|
|
839
965
|
} & ProcessNestedFields<TState$1, TRules$1, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
@@ -856,13 +982,13 @@ interface $InternalRegleStatus extends $InternalRegleCommonStatus {
|
|
|
856
982
|
/**
|
|
857
983
|
* @public
|
|
858
984
|
*/
|
|
859
|
-
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]
|
|
985
|
+
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>;
|
|
860
986
|
/**
|
|
861
987
|
* @internal
|
|
862
988
|
* @reference {@link InferRegleStatusType}
|
|
863
989
|
*/
|
|
864
990
|
type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
|
|
865
|
-
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<
|
|
991
|
+
type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>> = EmptyObject> = {
|
|
866
992
|
readonly $property: string;
|
|
867
993
|
readonly $type?: string;
|
|
868
994
|
readonly $message: string;
|
|
@@ -879,13 +1005,13 @@ type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<All
|
|
|
879
1005
|
} : {
|
|
880
1006
|
readonly $rule: string;
|
|
881
1007
|
} }[keyof ComputeFieldRules<any, TRules$1>]);
|
|
882
|
-
type ComputeFieldRules<TState$1 extends any, TRules$1 extends MaybeRef<RegleFormPropertyType<unknown, Partial<
|
|
1008
|
+
type ComputeFieldRules<TState$1 extends any, TRules$1 extends MaybeRef<RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>>>> = IsEmptyObject<UnwrapRef<TRules$1>> extends true ? {
|
|
883
1009
|
readonly [x: string]: RegleRuleStatus<TState$1, any[], any>;
|
|
884
1010
|
} : { 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> };
|
|
885
1011
|
/**
|
|
886
1012
|
* @public
|
|
887
1013
|
*/
|
|
888
|
-
type RegleFieldStatus<TState$1 extends any = any, TRules$1 extends RegleFormPropertyType<unknown, Partial<
|
|
1014
|
+
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'> & {
|
|
889
1015
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
890
1016
|
$value: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
891
1017
|
/** $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. */
|
|
@@ -949,7 +1075,7 @@ interface $InternalRegleFieldStatus extends $InternalRegleCommonStatus {
|
|
|
949
1075
|
/**
|
|
950
1076
|
* @public
|
|
951
1077
|
*/
|
|
952
|
-
interface RegleCommonStatus<TValue$1 = any> extends StandardSchemaV1<TValue$1
|
|
1078
|
+
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>> {
|
|
953
1079
|
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
954
1080
|
readonly $invalid: boolean;
|
|
955
1081
|
/**
|
|
@@ -1081,7 +1207,7 @@ interface $InternalRegleRuleStatus {
|
|
|
1081
1207
|
/**
|
|
1082
1208
|
* @public
|
|
1083
1209
|
*/
|
|
1084
|
-
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'> & {
|
|
1210
|
+
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'> & {
|
|
1085
1211
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1086
1212
|
$value: MaybeOutput<TState$1>;
|
|
1087
1213
|
/** $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. */
|
|
@@ -1103,7 +1229,7 @@ type RegleCollectionStatus<TState$1 extends any[] = any[], TRules$1 extends Regl
|
|
|
1103
1229
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1104
1230
|
readonly $silentErrors: RegleCollectionErrors<TState$1>;
|
|
1105
1231
|
/** 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). */
|
|
1106
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1232
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState$1>;
|
|
1107
1233
|
/** 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). */
|
|
1108
1234
|
$validate: (value?: JoinDiscriminatedUnions<TState$1>) => Promise<RegleCollectionResult<TState$1, JoinDiscriminatedUnions<TRules$1>>>;
|
|
1109
1235
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
@@ -1211,35 +1337,57 @@ interface SuperCompatibleRegleCollectionStatus extends Omit<SuperCompatibleRegle
|
|
|
1211
1337
|
type SuperCompatibleRegleCollectionErrors = $InternalRegleCollectionErrors;
|
|
1212
1338
|
type SuperCompatibleRegleCollectionIssues = $InternalRegleCollectionIssues;
|
|
1213
1339
|
/**
|
|
1214
|
-
* Create a typed custom rule that can be used like
|
|
1215
|
-
*
|
|
1340
|
+
* Create a typed custom rule that can be used like built-in rules.
|
|
1341
|
+
* The created rule can be declared in global options or used directly.
|
|
1216
1342
|
*
|
|
1217
|
-
*
|
|
1343
|
+
* Features:
|
|
1344
|
+
* - Automatically detects if the rule is async
|
|
1345
|
+
* - Supports parameters for configurable rules
|
|
1346
|
+
* - Full TypeScript type inference
|
|
1347
|
+
* - Custom metadata support
|
|
1218
1348
|
*
|
|
1349
|
+
* @param definition - The rule definition object containing:
|
|
1350
|
+
* - `validator`: The validation function
|
|
1351
|
+
* - `message`: Error message (string or function)
|
|
1352
|
+
* - `type`: Optional rule type identifier
|
|
1353
|
+
* - `active`: Optional function to conditionally activate the rule
|
|
1354
|
+
* - `tooltip`: Optional tooltip message
|
|
1219
1355
|
*
|
|
1220
|
-
* @
|
|
1221
|
-
*
|
|
1222
|
-
* @returns A rule definition that can be callable depending on params presence
|
|
1223
|
-
*
|
|
1224
|
-
* @exemple
|
|
1356
|
+
* @returns A rule definition that is callable if it accepts parameters
|
|
1225
1357
|
*
|
|
1358
|
+
* @example
|
|
1226
1359
|
* ```ts
|
|
1227
|
-
*
|
|
1228
|
-
* import {isFilled} from '@regle/rules';
|
|
1360
|
+
* import { createRule } from '@regle/core';
|
|
1361
|
+
* import { isFilled } from '@regle/rules';
|
|
1229
1362
|
*
|
|
1363
|
+
* // Simple rule without params
|
|
1230
1364
|
* export const isFoo = createRule({
|
|
1231
1365
|
* validator(value: Maybe<string>) {
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1366
|
+
* if (isFilled(value)) {
|
|
1367
|
+
* return value === 'foo';
|
|
1368
|
+
* }
|
|
1369
|
+
* return true;
|
|
1236
1370
|
* },
|
|
1237
1371
|
* message: "The value should be 'foo'"
|
|
1238
|
-
* })
|
|
1372
|
+
* });
|
|
1239
1373
|
*
|
|
1374
|
+
* // Rule with parameters
|
|
1375
|
+
* export const minCustom = createRule({
|
|
1376
|
+
* validator(value: Maybe<number>, min: number) {
|
|
1377
|
+
* if (isFilled(value)) {
|
|
1378
|
+
* return value >= min;
|
|
1379
|
+
* }
|
|
1380
|
+
* return true;
|
|
1381
|
+
* },
|
|
1382
|
+
* message: ({ $params: [min] }) => `Value must be at least ${min}`
|
|
1383
|
+
* });
|
|
1384
|
+
*
|
|
1385
|
+
* // Usage
|
|
1386
|
+
* useRegle({ name: '' }, { name: { isFoo } });
|
|
1387
|
+
* useRegle({ count: 0 }, { count: { minCustom: minCustom(5) } });
|
|
1240
1388
|
* ```
|
|
1241
1389
|
*
|
|
1242
|
-
*
|
|
1390
|
+
* @see {@link https://reglejs.dev/core-concepts/rules/reusable-rules Documentation}
|
|
1243
1391
|
*/
|
|
1244
1392
|
declare function createRule<TValue$1 extends any, TParams$1 extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync$1 extends boolean = (TReturn extends Promise<any> ? true : false)>(definition: RegleRuleInit<TValue$1, TParams$1, TReturn, TMetadata$1, TAsync$1>): InferRegleRule<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
|
|
1245
1393
|
/**
|
|
@@ -1248,18 +1396,45 @@ declare function createRule<TValue$1 extends any, TParams$1 extends any[], TRetu
|
|
|
1248
1396
|
*/
|
|
1249
1397
|
declare function unwrapRuleParameters<TParams$1 extends any[]>(params: MaybeRefOrGetter[]): TParams$1;
|
|
1250
1398
|
/**
|
|
1251
|
-
* Define a global
|
|
1399
|
+
* Define a global Regle configuration to customize the validation behavior across your application.
|
|
1400
|
+
*
|
|
1401
|
+
* Features:
|
|
1252
1402
|
* - Customize built-in rules messages
|
|
1253
|
-
* - Add your custom rules
|
|
1254
|
-
* - Define global modifiers
|
|
1255
|
-
* - Define shortcuts
|
|
1403
|
+
* - Add your custom rules with full type inference
|
|
1404
|
+
* - Define global modifiers (lazy, rewardEarly, etc.)
|
|
1405
|
+
* - Define shortcuts for common validation patterns
|
|
1406
|
+
*
|
|
1407
|
+
* @param options - Configuration options
|
|
1408
|
+
* @param options.rules - Factory function returning custom rules
|
|
1409
|
+
* @param options.modifiers - Global behavior modifiers
|
|
1410
|
+
* @param options.shortcuts - Reusable validation shortcuts
|
|
1411
|
+
* @returns Object containing typed `useRegle`, `inferRules`, and `useRules` functions
|
|
1412
|
+
*
|
|
1413
|
+
* @example
|
|
1414
|
+
* ```ts
|
|
1415
|
+
* import { defineRegleConfig } from '@regle/core';
|
|
1416
|
+
* import { required, withMessage } from '@regle/rules';
|
|
1256
1417
|
*
|
|
1257
|
-
*
|
|
1418
|
+
* export const { useRegle, inferRules, useRules } = defineRegleConfig({
|
|
1419
|
+
* rules: () => ({
|
|
1420
|
+
* // Override default required message
|
|
1421
|
+
* required: withMessage(required, 'This field cannot be empty'),
|
|
1422
|
+
* // Add custom rule
|
|
1423
|
+
* myCustomRule: createRule({
|
|
1424
|
+
* validator: (value) => value === 'valid',
|
|
1425
|
+
* message: 'Invalid value'
|
|
1426
|
+
* })
|
|
1427
|
+
* }),
|
|
1428
|
+
* modifiers: {
|
|
1429
|
+
* lazy: true,
|
|
1430
|
+
* rewardEarly: true
|
|
1431
|
+
* }
|
|
1432
|
+
* });
|
|
1433
|
+
* ```
|
|
1258
1434
|
*
|
|
1259
|
-
*
|
|
1260
|
-
* - an `inferRules` helper that can typecheck your custom rules
|
|
1435
|
+
* @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
|
|
1261
1436
|
*/
|
|
1262
|
-
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<
|
|
1437
|
+
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<ExtendedRulesDeclarations>>({
|
|
1263
1438
|
rules,
|
|
1264
1439
|
modifiers,
|
|
1265
1440
|
shortcuts
|
|
@@ -1273,14 +1448,33 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
|
|
|
1273
1448
|
useRules: useRulesFn<TCustomRules, TShortcuts>;
|
|
1274
1449
|
};
|
|
1275
1450
|
/**
|
|
1276
|
-
* Extend an already created custom `useRegle`
|
|
1451
|
+
* Extend an already created custom `useRegle` configuration with additional rules, modifiers, or shortcuts.
|
|
1277
1452
|
*
|
|
1278
|
-
*
|
|
1453
|
+
* @param regle - The existing useRegle function to extend
|
|
1454
|
+
* @param options - Additional configuration to merge
|
|
1455
|
+
* @param options.rules - Additional custom rules
|
|
1456
|
+
* @param options.modifiers - Additional modifiers to merge
|
|
1457
|
+
* @param options.shortcuts - Additional shortcuts to merge
|
|
1458
|
+
* @returns Object containing the extended `useRegle` and `inferRules` functions
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* ```ts
|
|
1462
|
+
* import { extendRegleConfig } from '@regle/core';
|
|
1463
|
+
* import { baseUseRegle } from './base-config';
|
|
1464
|
+
*
|
|
1465
|
+
* export const { useRegle, inferRules } = extendRegleConfig(baseUseRegle, {
|
|
1466
|
+
* rules: () => ({
|
|
1467
|
+
* additionalRule: myNewRule
|
|
1468
|
+
* }),
|
|
1469
|
+
* modifiers: {
|
|
1470
|
+
* rewardEarly: true
|
|
1471
|
+
* }
|
|
1472
|
+
* });
|
|
1473
|
+
* ```
|
|
1279
1474
|
*
|
|
1280
|
-
*
|
|
1281
|
-
* - an `inferRules` helper that can typecheck your custom rules
|
|
1475
|
+
* @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
|
|
1282
1476
|
*/
|
|
1283
|
-
declare function extendRegleConfig<TRootCustomRules extends Partial<
|
|
1477
|
+
declare function extendRegleConfig<TRootCustomRules extends Partial<ExtendedRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<ExtendedRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
|
|
1284
1478
|
rules,
|
|
1285
1479
|
modifiers,
|
|
1286
1480
|
shortcuts
|
|
@@ -1308,7 +1502,7 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
|
|
|
1308
1502
|
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
1309
1503
|
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
1310
1504
|
/** 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). */
|
|
1311
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1505
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>[];
|
|
1312
1506
|
/** 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). */
|
|
1313
1507
|
$validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
|
|
1314
1508
|
} & (HasNamedKeys<TRegles> extends true ? { [K in keyof TRegles]: TRegles[K] } : {});
|
|
@@ -1326,7 +1520,7 @@ type MergedScopedRegles<TValue$1 extends Record<string, unknown>[] = Record<stri
|
|
|
1326
1520
|
/** Collection of all registered Regles instances silent issues */
|
|
1327
1521
|
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
1328
1522
|
/** 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). */
|
|
1329
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
1523
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>;
|
|
1330
1524
|
/** 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). */
|
|
1331
1525
|
$validate: (forceValues?: TValue$1) => Promise<{
|
|
1332
1526
|
valid: boolean;
|
|
@@ -1350,6 +1544,44 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
|
|
|
1350
1544
|
errors: EmptyObject;
|
|
1351
1545
|
issues: EmptyObject;
|
|
1352
1546
|
};
|
|
1547
|
+
/**
|
|
1548
|
+
* Merge multiple Regle instances into a single validation state.
|
|
1549
|
+
* Useful for combining multiple forms or validation scopes.
|
|
1550
|
+
*
|
|
1551
|
+
* @param regles - An object containing named Regle instances to merge
|
|
1552
|
+
* @param _scoped - Internal flag for scoped validation (default: false)
|
|
1553
|
+
* @returns A merged validation state with all instances' properties combined
|
|
1554
|
+
*
|
|
1555
|
+
* @example
|
|
1556
|
+
* ```ts
|
|
1557
|
+
* import { useRegle, mergeRegles } from '@regle/core';
|
|
1558
|
+
* import { required } from '@regle/rules';
|
|
1559
|
+
*
|
|
1560
|
+
* // Create separate validation instances
|
|
1561
|
+
* const { r$: personalInfo } = useRegle(
|
|
1562
|
+
* { name: '', email: '' },
|
|
1563
|
+
* { name: { required }, email: { required } }
|
|
1564
|
+
* );
|
|
1565
|
+
*
|
|
1566
|
+
* const { r$: address } = useRegle(
|
|
1567
|
+
* { street: '', city: '' },
|
|
1568
|
+
* { street: { required }, city: { required } }
|
|
1569
|
+
* );
|
|
1570
|
+
*
|
|
1571
|
+
* // Merge them together
|
|
1572
|
+
* const merged$ = mergeRegles({
|
|
1573
|
+
* personalInfo,
|
|
1574
|
+
* address
|
|
1575
|
+
* });
|
|
1576
|
+
*
|
|
1577
|
+
* // Access combined state
|
|
1578
|
+
* merged$.$valid // true when ALL forms are valid
|
|
1579
|
+
* merged$.$errors // { personalInfo: {...}, address: {...} }
|
|
1580
|
+
* await merged$.$validate() // Validates all forms
|
|
1581
|
+
* ```
|
|
1582
|
+
*
|
|
1583
|
+
* @see {@link https://reglejs.dev/advanced-usage/merge-regles Documentation}
|
|
1584
|
+
*/
|
|
1353
1585
|
declare function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TScoped extends boolean = false>(regles: TRegles, _scoped?: TScoped): TScoped extends false ? MergedRegles<TRegles> : MergedScopedRegles;
|
|
1354
1586
|
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue$1 extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string | string[]>) => {
|
|
1355
1587
|
r$: MergedRegles<{ [K in keyof TValue$1]: RegleRoot<TValue$1[K]> & SuperCompatibleRegleRoot }>;
|
|
@@ -1381,10 +1613,39 @@ type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsR
|
|
|
1381
1613
|
*/
|
|
1382
1614
|
asRecord?: TAsRecord;
|
|
1383
1615
|
};
|
|
1384
|
-
|
|
1616
|
+
/**
|
|
1617
|
+
* Create a scoped validation system for collecting and validating multiple form instances.
|
|
1618
|
+
* Useful for dynamic forms, multi-step wizards, or component-based form architectures.
|
|
1619
|
+
*
|
|
1620
|
+
* @param options - Configuration options
|
|
1621
|
+
* @param options.customUseRegle - Custom useRegle instance with your global config
|
|
1622
|
+
* @param options.customStore - External ref to store collected instances
|
|
1623
|
+
* @param options.asRecord - If true, collect instances in a Record (requires `id` param in useScopedRegle)
|
|
1624
|
+
* @returns Object containing `useScopedRegle` and `useCollectScope` functions
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* // scoped-config.ts
|
|
1629
|
+
* import { createScopedUseRegle } from '@regle/core';
|
|
1630
|
+
*
|
|
1631
|
+
* export const { useScopedRegle, useCollectScope } = createScopedUseRegle();
|
|
1632
|
+
*
|
|
1633
|
+
* // ChildComponent.vue
|
|
1634
|
+
* const { r$ } = useScopedRegle(state, rules, {
|
|
1635
|
+
* namespace: 'myForm'
|
|
1636
|
+
* });
|
|
1637
|
+
*
|
|
1638
|
+
* // ParentComponent.vue
|
|
1639
|
+
* const { r$: collectedR$ } = useCollectScope('myForm');
|
|
1640
|
+
* await collectedR$.$validate(); // Validates all child forms
|
|
1641
|
+
* ```
|
|
1642
|
+
*
|
|
1643
|
+
* @see {@link https://reglejs.dev/advanced-usage/scoped-validation Documentation}
|
|
1644
|
+
*/
|
|
1645
|
+
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, {
|
|
1385
1646
|
dispose: () => void;
|
|
1386
1647
|
register: () => void;
|
|
1387
|
-
}, UseScopedRegleOptions<TAsRecord>> : useRegleFn<Partial<
|
|
1648
|
+
}, UseScopedRegleOptions<TAsRecord>> : useRegleFn<Partial<ExtendedRulesDeclarations>, any, {
|
|
1388
1649
|
dispose: () => void;
|
|
1389
1650
|
register: () => void;
|
|
1390
1651
|
}, UseScopedRegleOptions<TAsRecord>>)>(options?: CreateScopedUseRegleOptions<TCustomRegle, TAsRecord>): {
|
|
@@ -1393,41 +1654,71 @@ declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any>
|
|
|
1393
1654
|
};
|
|
1394
1655
|
declare const useCollectScope: <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string | string[]>) => {
|
|
1395
1656
|
r$: MergedScopedRegles<TValue$1>;
|
|
1396
|
-
}, useScopedRegle: useRegleFn<Partial<
|
|
1657
|
+
}, useScopedRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, never, {
|
|
1397
1658
|
dispose: () => void;
|
|
1398
1659
|
register: () => void;
|
|
1399
1660
|
}, {
|
|
1400
1661
|
namespace?: vue0.MaybeRefOrGetter<string>;
|
|
1401
1662
|
}>;
|
|
1402
1663
|
/**
|
|
1403
|
-
*
|
|
1664
|
+
* Create variant-based validation rules that depend on a discriminant field value.
|
|
1665
|
+
* Useful for union types where different fields are required based on a type discriminant.
|
|
1666
|
+
*
|
|
1667
|
+
* Note: Autocomplete may not fully work due to TypeScript limitations.
|
|
1404
1668
|
*
|
|
1405
|
-
*
|
|
1669
|
+
* @param root - The reactive state object
|
|
1670
|
+
* @param discriminantKey - The key used to discriminate between variants
|
|
1671
|
+
* @param variants - Array of variant rule definitions using `literal` for type matching
|
|
1672
|
+
* @returns A computed ref containing the currently active variant rules
|
|
1406
1673
|
*
|
|
1674
|
+
* @example
|
|
1407
1675
|
* ```ts
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
1411
|
-
*
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1415
|
-
*
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
1418
|
-
*
|
|
1419
|
-
*
|
|
1676
|
+
* import { useRegle, createVariant } from '@regle/core';
|
|
1677
|
+
* import { required, email, literal } from '@regle/rules';
|
|
1678
|
+
*
|
|
1679
|
+
* const state = ref({
|
|
1680
|
+
* type: 'EMAIL' as 'EMAIL' | 'GITHUB',
|
|
1681
|
+
* email: '',
|
|
1682
|
+
* username: ''
|
|
1683
|
+
* });
|
|
1684
|
+
*
|
|
1685
|
+
* // ⚠️ Use getter syntax for your rules
|
|
1686
|
+
* const { r$ } = useRegle(state, () => {
|
|
1687
|
+
* const variant = createVariant(state, 'type', [
|
|
1688
|
+
* { type: { literal: literal('EMAIL') }, email: { required, email } },
|
|
1689
|
+
* { type: { literal: literal('GITHUB') }, username: { required } },
|
|
1690
|
+
* { type: { required } }, // Default case
|
|
1691
|
+
* ]);
|
|
1692
|
+
*
|
|
1693
|
+
* return {
|
|
1694
|
+
* ...variant.value,
|
|
1695
|
+
* };
|
|
1696
|
+
* });
|
|
1420
1697
|
* ```
|
|
1698
|
+
*
|
|
1699
|
+
* @see {@link https://reglejs.dev/advanced-usage/variants Documentation}
|
|
1421
1700
|
*/
|
|
1422
1701
|
declare function createVariant<TForm extends Record<string, any>, TDiscriminant extends keyof JoinDiscriminatedUnions<TForm>, TVariants extends VariantTuple<JoinDiscriminatedUnions<TForm>, TDiscriminant>>(root: MaybeRefOrGetter<TForm> | DeepReactiveState<TForm>, discriminantKey: TDiscriminant, variants: [...TVariants]): Ref<TVariants[number]>;
|
|
1423
1702
|
/**
|
|
1424
|
-
*
|
|
1703
|
+
* Type guard to narrow a variant field to a specific discriminated value.
|
|
1704
|
+
* Enables type-safe access to variant-specific fields.
|
|
1705
|
+
*
|
|
1706
|
+
* @param root - The Regle status object
|
|
1707
|
+
* @param discriminantKey - The key used to discriminate between variants
|
|
1708
|
+
* @param discriminantValue - The specific value to narrow to
|
|
1709
|
+
* @returns `true` if the discriminant matches, with TypeScript narrowing the type
|
|
1425
1710
|
*
|
|
1711
|
+
* @example
|
|
1426
1712
|
* ```ts
|
|
1713
|
+
* import { narrowVariant } from '@regle/core';
|
|
1714
|
+
*
|
|
1427
1715
|
* if (narrowVariant(r$, 'type', 'EMAIL')) {
|
|
1428
|
-
*
|
|
1716
|
+
* // TypeScript knows r$.email exists here
|
|
1717
|
+
* r$.email.$value = 'user@example.com';
|
|
1429
1718
|
* }
|
|
1430
1719
|
* ```
|
|
1720
|
+
*
|
|
1721
|
+
* @see {@link https://reglejs.dev/advanced-usage/variants Documentation}
|
|
1431
1722
|
*/
|
|
1432
1723
|
declare function narrowVariant<TRoot extends {
|
|
1433
1724
|
[x: string]: unknown;
|
|
@@ -1439,13 +1730,28 @@ declare function narrowVariant<TRoot extends {
|
|
|
1439
1730
|
$value: infer V;
|
|
1440
1731
|
} ? V : unknown)>(root: TRoot | undefined, discriminantKey: TKey$1, discriminantValue: TValue$1): root is NarrowVariant<TRoot, TKey$1, TValue$1>;
|
|
1441
1732
|
/**
|
|
1442
|
-
*
|
|
1733
|
+
* Create a reactive reference to a narrowed variant.
|
|
1734
|
+
* Useful in templates or when you need a stable ref to the narrowed type.
|
|
1443
1735
|
*
|
|
1736
|
+
* @param root - The Regle status object (can be a ref)
|
|
1737
|
+
* @param discriminantKey - The key used to discriminate between variants
|
|
1738
|
+
* @param discriminantValue - The specific value to narrow to
|
|
1739
|
+
* @param options - Optional `{ unsafeAssertion: true }` to assert the variant always exists
|
|
1740
|
+
* @returns A ref containing the narrowed variant (or undefined if not matching)
|
|
1741
|
+
*
|
|
1742
|
+
* @example
|
|
1444
1743
|
* ```vue
|
|
1445
1744
|
* <script setup lang="ts">
|
|
1446
|
-
*
|
|
1745
|
+
* import { variantToRef } from '@regle/core';
|
|
1746
|
+
*
|
|
1747
|
+
* const emailR$ = variantToRef(r$, 'type', 'EMAIL');
|
|
1748
|
+
*
|
|
1749
|
+
* // In template:
|
|
1750
|
+
* // <input v-if="emailR$" v-model="emailR$.$value.email" />
|
|
1447
1751
|
* </script>
|
|
1448
1752
|
* ```
|
|
1753
|
+
*
|
|
1754
|
+
* @see {@link https://reglejs.dev/advanced-usage/variants Documentation}
|
|
1449
1755
|
*/
|
|
1450
1756
|
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey$1 extends keyof TRoot['$fields'], const TValue$1 extends (LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey$1], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
|
|
1451
1757
|
$value: infer V;
|
|
@@ -1459,30 +1765,56 @@ declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKe
|
|
|
1459
1765
|
$value: infer V;
|
|
1460
1766
|
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey$1, discriminantValue: TValue$1): Ref<NarrowVariant<TRoot, TKey$1, TValue$1> | undefined>;
|
|
1461
1767
|
/**
|
|
1462
|
-
* Helper method to wrap
|
|
1768
|
+
* Helper method to wrap a raw rules object with type inference.
|
|
1769
|
+
* Provides autocomplete and type-checking without processing.
|
|
1463
1770
|
*
|
|
1464
|
-
*
|
|
1771
|
+
* @param rules - The rules object to wrap
|
|
1772
|
+
* @returns The same rules object (passthrough)
|
|
1465
1773
|
*
|
|
1774
|
+
* @example
|
|
1466
1775
|
* ```ts
|
|
1467
|
-
*
|
|
1776
|
+
* import { defineRules } from '@regle/core';
|
|
1777
|
+
* import { required, string } from '@regle/rules';
|
|
1778
|
+
*
|
|
1779
|
+
* // defineRules helps catch structure errors
|
|
1780
|
+
* const rules = defineRules({
|
|
1781
|
+
* firstName: { required, string },
|
|
1782
|
+
* lastName: { required, string }
|
|
1783
|
+
* });
|
|
1468
1784
|
* ```
|
|
1785
|
+
*
|
|
1786
|
+
* @see {@link https://reglejs.dev/common-usage/standard-schema Documentation}
|
|
1469
1787
|
*/
|
|
1470
1788
|
declare function defineRules<TRules$1 extends RegleUnknownRulesTree>(rules: TRules$1): TRules$1;
|
|
1471
1789
|
/**
|
|
1472
|
-
* Refine a
|
|
1790
|
+
* Refine a rules object to add rules that depend on the state values.
|
|
1791
|
+
* Inspired by Zod's `refine`, this allows writing dynamic rules while maintaining type safety.
|
|
1473
1792
|
*
|
|
1474
|
-
* @
|
|
1793
|
+
* @param rules - The base rules object
|
|
1794
|
+
* @param refinement - A function that receives the typed state and returns additional rules
|
|
1795
|
+
* @returns A function that, given the state ref, returns the merged rules
|
|
1475
1796
|
*
|
|
1797
|
+
* @example
|
|
1476
1798
|
* ```ts
|
|
1799
|
+
* import { refineRules, type InferInput } from '@regle/core';
|
|
1800
|
+
* import { required, string, sameAs } from '@regle/rules';
|
|
1801
|
+
*
|
|
1477
1802
|
* const rules = refineRules({
|
|
1478
|
-
*
|
|
1479
|
-
* }, (state) => {
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1803
|
+
* password: { required, string },
|
|
1804
|
+
* }, (state) => ({
|
|
1805
|
+
* // state is typed based on the base rules
|
|
1806
|
+
* confirmPassword: {
|
|
1807
|
+
* required,
|
|
1808
|
+
* sameAs: sameAs(() => state.value.password)
|
|
1809
|
+
* }
|
|
1810
|
+
* }));
|
|
1811
|
+
*
|
|
1812
|
+
* type State = InferInput<typeof rules>;
|
|
1813
|
+
* // { password: string; confirmPassword: string }
|
|
1484
1814
|
* ```
|
|
1815
|
+
*
|
|
1816
|
+
* @see {@link https://reglejs.dev/common-usage/standard-schema#refinerules Documentation}
|
|
1485
1817
|
*/
|
|
1486
1818
|
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>;
|
|
1487
1819
|
declare const RegleVuePlugin: Plugin;
|
|
1488
|
-
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 };
|
|
1820
|
+
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 };
|