@regle/core 1.18.0-beta.4 → 1.18.0
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 +248 -298
- package/dist/regle-core.js +109 -109
- package/dist/regle-core.min.js +2 -2
- package/package.json +6 -6
package/dist/regle-core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/core v1.18.0
|
|
2
|
+
* @regle/core v1.18.0
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -15,13 +15,13 @@ type RegleStaticImpl<T> = Raw<T & {
|
|
|
15
15
|
type IsRegleStatic<T> = T extends RegleStaticImpl<T> ? true : false;
|
|
16
16
|
type UnwrapStatic<T> = IsUnknown<T> extends true ? any : NonNullable<T> extends RegleStaticImpl<infer U> ? Raw<U> : UnwrapStaticSimple<T>;
|
|
17
17
|
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;
|
|
18
|
-
interface GlobalConfigOverrides<TValue
|
|
18
|
+
interface GlobalConfigOverrides<TValue extends unknown = unknown> {
|
|
19
19
|
/**
|
|
20
20
|
* Override the default $edited handler.
|
|
21
21
|
*/
|
|
22
|
-
isEdited?: isEditedHandlerFn<TValue
|
|
22
|
+
isEdited?: isEditedHandlerFn<TValue>;
|
|
23
23
|
}
|
|
24
|
-
type isEditedHandlerFn<TValue
|
|
24
|
+
type isEditedHandlerFn<TValue extends unknown = unknown> = (currentValue: MaybeInput<TValue>, initialValue: MaybeInput<TValue>, defaultHandlerFn: (currentValue: unknown, initialValue: unknown) => boolean) => boolean;
|
|
25
25
|
interface RegleBehaviourOptions {
|
|
26
26
|
/**
|
|
27
27
|
* Does not run rules until the field is dirty.
|
|
@@ -62,7 +62,7 @@ interface RegleBehaviourOptions {
|
|
|
62
62
|
*/
|
|
63
63
|
immediateDirty?: boolean | undefined;
|
|
64
64
|
}
|
|
65
|
-
interface LocalRegleBehaviourOptions<TState
|
|
65
|
+
interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
|
|
66
66
|
/**
|
|
67
67
|
* A dictionary of external errors to be injected into the field statuses.
|
|
68
68
|
*
|
|
@@ -71,7 +71,7 @@ interface LocalRegleBehaviourOptions<TState$1 extends Record<string, any>, TRule
|
|
|
71
71
|
*
|
|
72
72
|
* More details: https://reglejs.dev/advanced-usage/external-errors
|
|
73
73
|
*/
|
|
74
|
-
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState
|
|
74
|
+
externalErrors?: Ref<RegleExternalErrorTree<Unwrap<TState>> | Record<string, string[]>>;
|
|
75
75
|
/**
|
|
76
76
|
* Allows you to group fields for custom collective validation logic.
|
|
77
77
|
*
|
|
@@ -83,7 +83,7 @@ interface LocalRegleBehaviourOptions<TState$1 extends Record<string, any>, TRule
|
|
|
83
83
|
*
|
|
84
84
|
* More details: https://reglejs.dev/core-concepts/modifiers#validationgroups
|
|
85
85
|
*/
|
|
86
|
-
validationGroups?: (fields: RegleStatus<TState
|
|
86
|
+
validationGroups?: (fields: RegleStatus<TState, TRules>['$fields']) => TValidationGroups;
|
|
87
87
|
/**
|
|
88
88
|
* A unique identifier for the Regle instance in the devtools.
|
|
89
89
|
* @default undefined
|
|
@@ -107,7 +107,7 @@ interface RegleValidationGroupOutput {
|
|
|
107
107
|
/** Collection of all error messages from fields in the group, regardless of $dirty state. */
|
|
108
108
|
$silentErrors: string[];
|
|
109
109
|
}
|
|
110
|
-
type FieldRegleBehaviourOptions<TValue
|
|
110
|
+
type FieldRegleBehaviourOptions<TValue extends unknown = unknown> = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
111
111
|
/**
|
|
112
112
|
* Let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.
|
|
113
113
|
*/
|
|
@@ -115,9 +115,9 @@ type FieldRegleBehaviourOptions<TValue$1 extends unknown = unknown> = AddDollarT
|
|
|
115
115
|
/**
|
|
116
116
|
* Override the default `$edited` handler.
|
|
117
117
|
*/
|
|
118
|
-
$isEdited?: isEditedHandlerFn<TValue
|
|
118
|
+
$isEdited?: isEditedHandlerFn<TValue>;
|
|
119
119
|
};
|
|
120
|
-
type CollectionRegleBehaviourOptions<TValue
|
|
120
|
+
type CollectionRegleBehaviourOptions<TValue extends unknown = unknown> = FieldRegleBehaviourOptions<TValue> & {
|
|
121
121
|
/**
|
|
122
122
|
* Allow deep compare of array children to compute the `$edited` property
|
|
123
123
|
*
|
|
@@ -156,13 +156,13 @@ type AddDollarToOptions<T extends Record<string, any>> = { [K in keyof T as `$${
|
|
|
156
156
|
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
157
157
|
*
|
|
158
158
|
*/
|
|
159
|
-
type Regle<TState
|
|
159
|
+
type Regle<TState extends Record<string, any> = EmptyObject, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> = EmptyObject, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
160
160
|
/**
|
|
161
161
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
162
162
|
*
|
|
163
163
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
164
164
|
*/
|
|
165
|
-
r$: Raw<RegleRoot<TState
|
|
165
|
+
r$: Raw<RegleRoot<TState, TRules, TValidationGroups, TShortcuts>>;
|
|
166
166
|
} & TAdditionalReturnProperties;
|
|
167
167
|
/**
|
|
168
168
|
* The type for a single field validation instance.
|
|
@@ -172,17 +172,17 @@ type Regle<TState$1 extends Record<string, any> = EmptyObject, TRules$1 extends
|
|
|
172
172
|
* @template TShortcuts - Custom shortcut definitions for common validation patterns
|
|
173
173
|
* @template TAdditionalReturnProperties - Additional properties to extend the return type
|
|
174
174
|
*/
|
|
175
|
-
type RegleSingleField<TState
|
|
175
|
+
type RegleSingleField<TState extends Maybe<PrimitiveTypes> = any, TRules extends RegleRuleDecl<NonNullable<TState>> = EmptyObject, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
176
176
|
/**
|
|
177
177
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
178
178
|
*
|
|
179
179
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
180
180
|
*/
|
|
181
|
-
r$: Raw<RegleFieldStatus<TState
|
|
181
|
+
r$: Raw<RegleFieldStatus<TState, TRules, TShortcuts>>;
|
|
182
182
|
} & TAdditionalReturnProperties;
|
|
183
183
|
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
|
|
184
|
-
type InferDeepReactiveState<TState
|
|
185
|
-
type ResetOptions<TState
|
|
184
|
+
type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState> extends Date | File ? MaybeRef<TState> : NonNullable<TState> extends Record<string, any> ? DeepReactiveState<TState> : MaybeRef<TState>;
|
|
185
|
+
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
186
186
|
/**
|
|
187
187
|
* Reset validation status and reset form state to its initial state.
|
|
188
188
|
*
|
|
@@ -203,7 +203,7 @@ type ResetOptions<TState$1 extends unknown> = RequireOneOrNone<{
|
|
|
203
203
|
* Reset validation status and reset form state to the given state
|
|
204
204
|
* Also set the new state as the initial state.
|
|
205
205
|
*/
|
|
206
|
-
toState?: TState
|
|
206
|
+
toState?: TState | (() => TState);
|
|
207
207
|
/**
|
|
208
208
|
* Clears the $externalErrors state back to an empty object.
|
|
209
209
|
*
|
|
@@ -222,18 +222,16 @@ type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleR
|
|
|
222
222
|
'~~global': Record<string, SuperCompatibleRegleRoot>;
|
|
223
223
|
};
|
|
224
224
|
type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
|
|
225
|
-
type PartialFormState<TState
|
|
226
|
-
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules
|
|
227
|
-
/** The result of the validation */
|
|
228
|
-
|
|
229
|
-
/** Output data, filter the result by checking the `valid` property */
|
|
230
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : IsEmptyObject<TRules$1> extends true ? MaybeOutput<Data> : 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;
|
|
225
|
+
type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{ [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: MaybeOutput<TState[K]> } & { [K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? K : TState[K] extends Array<any> ? K : never]: NonNullable<TState[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState[K]> }>;
|
|
226
|
+
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
|
|
227
|
+
/** The result of the validation */valid: false; /** Output data, filter the result by checking the `valid` property */
|
|
228
|
+
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : IsEmptyObject<TRules> extends true ? MaybeOutput<Data> : 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;
|
|
231
229
|
/**
|
|
232
230
|
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
233
231
|
*
|
|
234
232
|
* Only contains errors from properties where $dirty equals true.
|
|
235
233
|
* */
|
|
236
|
-
issues: DataTypeRegleIssues<Data, TRules
|
|
234
|
+
issues: DataTypeRegleIssues<Data, TRules>;
|
|
237
235
|
/**
|
|
238
236
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
239
237
|
*
|
|
@@ -242,13 +240,13 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 ex
|
|
|
242
240
|
errors: DataTypeRegleErrors<Data>;
|
|
243
241
|
} | {
|
|
244
242
|
valid: true;
|
|
245
|
-
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : IsEmptyObject<TRules
|
|
243
|
+
data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : IsEmptyObject<TRules> extends true ? MaybeOutput<Data> : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules extends ReglePartialRuleTree<any> ? TRules : {}>[] : NonNullable<Data> extends Date | File ? SafeFieldProperty<Raw<NonNullable<Data>>, TRules extends ReglePartialRuleTree<any> ? TRules : {}> : NonNullable<Data> extends Record<string, any> ? DeepSafeFormState<NonNullable<Data>, TRules extends ReglePartialRuleTree<any> ? TRules : {}> : SafeFieldProperty<Data, TRules extends ReglePartialRuleTree<any> ? TRules : {}> : unknown;
|
|
246
244
|
issues: EmptyObject;
|
|
247
245
|
errors: EmptyObject;
|
|
248
246
|
};
|
|
249
|
-
type DataTypeRegleIssues<TData extends Record<string, any> | any[] | unknown, TRules
|
|
247
|
+
type DataTypeRegleIssues<TData extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any> = never> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? RegleFieldIssue<TRules>[] : RegleCollectionErrors<TData, true> : isRecordLiteral<TData> extends true ? RegleIssuesTree<TData> : RegleFieldIssue<TRules>[] : RegleFieldIssue | RegleCollectionErrors<TData, true> | RegleIssuesTree<TData>;
|
|
250
248
|
type DataTypeRegleErrors<TData extends Record<string, any> | any[] | unknown> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? string[] : RegleCollectionErrors<TData> : isRecordLiteral<TData> extends true ? RegleErrorTree<TData> : string[] : string[] | RegleErrorTree<TData> | RegleCollectionErrors<TData>;
|
|
251
|
-
type RegleCollectionResult<Data extends any[], TRules
|
|
249
|
+
type RegleCollectionResult<Data extends any[], TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
|
|
252
250
|
valid: false;
|
|
253
251
|
issues: RegleCollectionErrors<Data, true>;
|
|
254
252
|
errors: RegleCollectionErrors<Data>;
|
|
@@ -257,9 +255,9 @@ type RegleCollectionResult<Data extends any[], TRules$1 extends ReglePartialRule
|
|
|
257
255
|
issues: EmptyObject;
|
|
258
256
|
errors: EmptyObject;
|
|
259
257
|
});
|
|
260
|
-
type RegleFieldResult<Data extends any, TRules
|
|
258
|
+
type RegleFieldResult<Data extends any, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
|
|
261
259
|
valid: false;
|
|
262
|
-
issues: RegleFieldIssue<TRules
|
|
260
|
+
issues: RegleFieldIssue<TRules>[];
|
|
263
261
|
errors: string[];
|
|
264
262
|
} | {
|
|
265
263
|
valid: true;
|
|
@@ -272,15 +270,15 @@ type $InternalRegleResult = {
|
|
|
272
270
|
errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
|
|
273
271
|
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
274
272
|
};
|
|
275
|
-
type DeepSafeFormState<TState
|
|
273
|
+
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]> } & { [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>> }> : TState;
|
|
276
274
|
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRefOrComputedRef<RegleRuleDecl<any, any>> ? { [K in keyof UnwrapRef<TRule>]-?: UnwrapRef<TRule>[K] extends RegleRuleDefinition<unknown, any, any[], any, any, any, any, true> ? true : false }[keyof UnwrapRef<TRule>] extends false ? false : true : false;
|
|
277
|
-
type ObjectHaveAtLeastOneRequiredField<TState
|
|
278
|
-
$self: IsPropertyOutputRequired<string, TRules
|
|
279
|
-
})[keyof TState
|
|
280
|
-
type ArrayHaveAtLeastOneRequiredField<TState
|
|
281
|
-
type SafeProperty<TState
|
|
282
|
-
type IsPropertyOutputRequired<TState
|
|
283
|
-
type SafeFieldProperty<TState
|
|
275
|
+
type ObjectHaveAtLeastOneRequiredField<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, any>> = TState extends Maybe<TState> ? ({ [K in keyof NonNullable<TState>]-?: IsPropertyOutputRequired<NonNullable<TState>[K], TRules[K] extends RegleFormPropertyType<any, any> ? TRules[K] : {}> } & {
|
|
276
|
+
$self: IsPropertyOutputRequired<string, TRules['$self']>;
|
|
277
|
+
})[keyof TState | '$self'] extends false ? false : true : true;
|
|
278
|
+
type ArrayHaveAtLeastOneRequiredField<TState extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState>> = TState extends Maybe<TState> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends MaybeRef<RegleRuleDecl> ? Omit<UnwrapRef<TRule>, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
|
|
279
|
+
type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? DeepSafeFormState<NonNullable<TState> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState>> : {}, TRule> : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends true ? TState : MaybeOutput<TState> : TState : TState;
|
|
280
|
+
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule extends ReglePartialRuleTree<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, any> ? TRule : {}> extends false ? false : true : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends false ? false : true : false : false;
|
|
281
|
+
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState> : MaybeOutput<TState>;
|
|
284
282
|
/** Types to be augmented by @regle/schemas */
|
|
285
283
|
interface NarrowVariantExtracts {}
|
|
286
284
|
interface NarrowVariantFieldExtracts<T extends unknown> {}
|
|
@@ -290,31 +288,31 @@ type NarrowVariant<TRoot extends {
|
|
|
290
288
|
[x: string]: unknown;
|
|
291
289
|
};
|
|
292
290
|
$value: unknown;
|
|
293
|
-
}, TKey
|
|
291
|
+
}, TKey extends keyof TRoot, TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
|
|
294
292
|
$value: infer V;
|
|
295
|
-
} ? V : unknown)> = Extract<TRoot, { [K in TKey
|
|
296
|
-
$fields: Extract<TRoot['$fields'], { [K in TKey
|
|
297
|
-
$value: TValue
|
|
293
|
+
} ? V : unknown)> = Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue>[keyof NarrowVariantFieldExtracts<TValue>]) }> & {
|
|
294
|
+
$fields: Extract<TRoot['$fields'], { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue>[keyof NarrowVariantFieldExtracts<TValue>]) }> & { [K in TKey]: TRoot[K] & {
|
|
295
|
+
$value: TValue;
|
|
298
296
|
} };
|
|
299
297
|
} & {
|
|
300
|
-
$value: Omit<TRoot['$value'], TKey
|
|
301
|
-
} & { [K in TKey
|
|
302
|
-
$value: TValue
|
|
298
|
+
$value: Omit<TRoot['$value'], TKey> & { [K in TKey]: TValue };
|
|
299
|
+
} & { [K in TKey]: TRoot[K] & {
|
|
300
|
+
$value: TValue;
|
|
303
301
|
} };
|
|
304
|
-
type MaybeVariantStatus<TState
|
|
305
|
-
$fields: ProcessChildrenFields<TState
|
|
306
|
-
} & (HasNamedKeys<TState
|
|
307
|
-
type ProcessChildrenFields<TState
|
|
308
|
-
type FindCorrespondingVariant<TState
|
|
309
|
-
type PossibleLiteralTypes<T extends Record<string, any>, TKey
|
|
310
|
-
[x: string]: { [K in TKey
|
|
302
|
+
type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? IsUnion<TRules> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields'> & {
|
|
303
|
+
$fields: ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>];
|
|
304
|
+
} & (HasNamedKeys<TState> extends true ? ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>] : {}) : RegleStatus<JoinDiscriminatedUnions<TState>, TRules extends ReglePartialRuleTree<NonNullable<JoinDiscriminatedUnions<TState>>> ? TRules : EmptyObject, TShortcuts> : RegleStatus<TState, TRules, TShortcuts>;
|
|
305
|
+
type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
306
|
+
type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
|
|
307
|
+
type PossibleLiteralTypes<T extends Record<string, any>, TKey extends keyof T> = unknown extends T[TKey] ? {
|
|
308
|
+
[x: string]: { [K in TKey]-?: Omit<RegleRuleDecl<any, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
311
309
|
literal?: RegleRuleDefinition<'literal', any, [literal: any], false, boolean, any, string | number, true>;
|
|
312
310
|
} };
|
|
313
|
-
} : { [TVal in NonNullable<T[TKey
|
|
311
|
+
} : { [TVal in NonNullable<T[TKey]>]: { [K in TKey]-?: Omit<RegleRuleDecl<TVal, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
|
|
314
312
|
literal?: RegleRuleDefinition<'literal', MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number, true>;
|
|
315
313
|
} } };
|
|
316
|
-
type RequiredForm<T extends Record<string, any>, TKey
|
|
317
|
-
type VariantTuple<T extends Record<string, any>, TKey
|
|
314
|
+
type RequiredForm<T extends Record<string, any>, TKey extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey> & PossibleLiteralTypes<T, TKey>[keyof PossibleLiteralTypes<T, TKey>];
|
|
315
|
+
type VariantTuple<T extends Record<string, any>, TKey extends keyof T> = [RequiredForm<T, TKey>, ...RequiredForm<T, TKey>[]];
|
|
318
316
|
/**
|
|
319
317
|
* Combine all members of a union type, merging types for each key, and keeping loose types
|
|
320
318
|
*/
|
|
@@ -325,8 +323,8 @@ type ResolveKeys<TUnion extends unknown> = Partial<UnionToIntersection<RemoveCom
|
|
|
325
323
|
*/
|
|
326
324
|
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;
|
|
327
325
|
type DumbJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<TUnion>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
|
|
328
|
-
type RemoveCommonKey<T extends readonly any[], K
|
|
329
|
-
type HasCommonKey<T extends readonly any[], K
|
|
326
|
+
type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
|
|
327
|
+
type HasCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? K extends keyof F ? true : HasCommonKey<R, K> : false;
|
|
330
328
|
/**
|
|
331
329
|
* Transforms a union and apply undefined values to non-present keys to support intersection
|
|
332
330
|
*/
|
|
@@ -342,7 +340,7 @@ type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F,
|
|
|
342
340
|
/**
|
|
343
341
|
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
344
342
|
*/
|
|
345
|
-
type GetMaybeObjectValue<O extends Record<string, any>, K
|
|
343
|
+
type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K extends keyof O ? O[K] : undefined;
|
|
346
344
|
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K] };
|
|
347
345
|
/**
|
|
348
346
|
* Merge every boolean property into a single boolean.
|
|
@@ -374,18 +372,18 @@ type MaybeReadonly<T> = T | Readonly<T>;
|
|
|
374
372
|
type NonUndefined<T> = Exclude<T, undefined>;
|
|
375
373
|
type MaybeNullable<T> = Or<IsNullable<T>, IsOptional<T>>;
|
|
376
374
|
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
377
|
-
type MaybeGetter<T, V
|
|
375
|
+
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}, TSelf extends Record<string, any> = {}> = (T & TSelf) | ((value: Ref<V>, index: number) => T & TAdd & TSelf);
|
|
378
376
|
type MaybeComputedOrGetter<T> = MaybeRefOrComputedRef<T> | ((...args: any[]) => T);
|
|
379
377
|
type Unwrap<T extends MaybeRef<unknown>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
380
378
|
type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends MaybeComputedOrGetter<infer U> ? U : T extends Ref<infer U> ? U : T extends ((...args: any[]) => infer U) ? U : T;
|
|
381
379
|
type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
|
|
382
380
|
type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
383
|
-
type OmitByType<T extends Record<string, any>, U
|
|
381
|
+
type OmitByType<T extends Record<string, any>, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] };
|
|
384
382
|
type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
|
|
385
|
-
type ExcludeByType<T, U
|
|
383
|
+
type ExcludeByType<T, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] extends U ? never : T[K] };
|
|
386
384
|
type PrimitiveTypes = string | number | boolean | bigint | Date | File;
|
|
387
385
|
type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
|
|
388
|
-
type NoInferLegacy<A
|
|
386
|
+
type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
|
|
389
387
|
/**
|
|
390
388
|
* Extract the element type from an array.
|
|
391
389
|
*
|
|
@@ -400,7 +398,7 @@ type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
|
400
398
|
*/
|
|
401
399
|
type NonEmptyTuple<T> = [T, ...T[]] | T[];
|
|
402
400
|
interface inferRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>> {
|
|
403
|
-
<TState
|
|
401
|
+
<TState extends MaybeRef<Record<string, any> | MaybeInput<PrimitiveTypes>>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<DefaultValidatorsTree> & TCustomRules>, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<DefaultValidatorsTree> & TCustomRules>>(state: Maybe<TState> | DeepReactiveState<TState>, rulesFactory: Unwrap<TState> extends MaybeInput<PrimitiveTypes> ? TDecl : Unwrap<TState> extends Record<string, any> ? TRules : {}): NonNullable<Unwrap<TState>> extends PrimitiveTypes ? TDecl : TRules;
|
|
404
402
|
}
|
|
405
403
|
/**
|
|
406
404
|
* Type helper to provide autocomplete and type-checking for your form rules.
|
|
@@ -568,9 +566,9 @@ declare function extendRegleConfig<TRootCustomRules extends Partial<ExtendedRule
|
|
|
568
566
|
useRegle: useRegleFn<Merge<TRootCustomRules, TCustomRules>, TRootShortcuts & TShortcuts>;
|
|
569
567
|
inferRules: inferRulesFn<Merge<TRootCustomRules, TCustomRules>>;
|
|
570
568
|
};
|
|
571
|
-
type useRegleFnOptions<TState
|
|
569
|
+
type useRegleFnOptions<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<NonNullable<JoinDiscriminatedUnions<TState>>, Partial<ExtendedRulesDeclarations>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState extends Record<string, any> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState>, TRules, TValidationGroups> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions;
|
|
572
570
|
interface useRegleFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
573
|
-
<TState
|
|
571
|
+
<TState extends MaybeRef<Record<string, any> | MaybeInput<PrimitiveTypes>>, TRules extends ReglePartialRuleTree<JoinDiscriminatedUnions<Unwrap<TState>>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<Unwrap<TState>>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<TState> | DeepReactiveState<TState>, rulesFactory: Unwrap<TState> extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : Unwrap<TState> extends Record<string, any> ? MaybeComputedOrGetter<TRules> : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<Unwrap<TState>, TRules, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<Unwrap<TState>, TRules, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<Unwrap<TState>, TRules, TAdditionalOptions, TValidationGroups>])]): NonNullable<Unwrap<TState>> extends PrimitiveTypes ? RegleSingleField<NonNullable<Unwrap<TState>>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<Unwrap<TState> extends Record<string, any> ? Unwrap<TState> : {}, UnwrapSimple<TRules> extends Record<string, any> ? UnwrapSimple<TRules> : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
574
572
|
__config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
|
|
575
573
|
}
|
|
576
574
|
/**
|
|
@@ -752,9 +750,9 @@ declare function getErrors<TRegle extends SuperCompatibleRegleRoot | SuperCompat
|
|
|
752
750
|
* @see {@link https://reglejs.dev/core-concepts/displaying-errors#get-issues-by-path Documentation}
|
|
753
751
|
*/
|
|
754
752
|
declare function getIssues<TRegle extends SuperCompatibleRegleRoot | SuperCompatibleRegleStatus, TPath extends Paths<TRegle['$issues']>>(r$: MaybeRef<TRegle>, path: TPath | (string & {})): IsStringLiteral<TPath> extends true ? Get<TRegle['$issues'], TPath & string> : RegleFieldIssue[] | undefined;
|
|
755
|
-
type useRulesFnOptions<TRules
|
|
753
|
+
type useRulesFnOptions<TRules extends RegleUnknownRulesTree | RegleRuleDecl, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState = InferInput<TRules>> = Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? (TRules extends Record<string, any> ? TRules : {}) : {}, TValidationGroups>;
|
|
756
754
|
interface useRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
757
|
-
<TRules
|
|
755
|
+
<TRules extends RegleUnknownRulesTree | RegleRuleDecl, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<ExtendedRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState extends Record<string, any> = InferInput<TRules>>(rulesFactory: TState extends Record<string, any> ? MaybeRef<TRules> | ((...args: any[]) => TRules) : {}, options?: useRulesFnOptions<TRules, TValidationGroups, TState>): NonNullable<TState> extends PrimitiveTypes ? Raw<RegleFieldStatus<NonNullable<TState>, TDecl, TShortcuts>> & StandardSchemaV1<TState> : Raw<RegleRoot<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules extends Record<string, any> ? TRules : {}, TValidationGroups, TShortcuts>> & StandardSchemaV1<TState>;
|
|
758
756
|
__config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
|
|
759
757
|
}
|
|
760
758
|
/**
|
|
@@ -814,16 +812,16 @@ type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<
|
|
|
814
812
|
/**
|
|
815
813
|
* Extract a set rules and setting them as required
|
|
816
814
|
*/
|
|
817
|
-
type RegleEnforceRequiredRules<TRules
|
|
815
|
+
type RegleEnforceRequiredRules<TRules extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules> & { [K in TRules]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
|
|
818
816
|
/**
|
|
819
817
|
* Extract a set of custom rules from a global configuration and setting them as required
|
|
820
818
|
|
|
821
819
|
*/
|
|
822
|
-
type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules
|
|
820
|
+
type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules extends keyof InferRegleRules<T>> = Omit<Partial<DefaultValidatorsTree>, TRules> & { [K in TRules]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
|
|
823
821
|
/**
|
|
824
822
|
* Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
|
|
825
823
|
*/
|
|
826
|
-
type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState
|
|
824
|
+
type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState extends unknown = any, TRules extends keyof InferRegleRules<T> = never> = RegleFieldStatus<TState, [TRules] extends [never] ? Partial<InferRegleRules<T>> : RegleEnforceCustomRequiredRules<T, TRules>, InferRegleShortcuts<T>>;
|
|
827
825
|
/**
|
|
828
826
|
* Infer safe output type from a rules object and it's original state type
|
|
829
827
|
*
|
|
@@ -831,7 +829,7 @@ type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState$1 extends unk
|
|
|
831
829
|
* type FormRequest = InferOutput<typeof rules, typeof formState>;
|
|
832
830
|
* ```
|
|
833
831
|
*/
|
|
834
|
-
type InferOutput<TRules
|
|
832
|
+
type InferOutput<TRules extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TState extends MaybeRef<unknown> = InferInput<TRules>> = isRecordLiteral<TState> extends true ? TRules extends MaybeRef<StandardSchemaV1<infer State>> ? State : DeepSafeFormState<JoinDiscriminatedUnions<Unwrap<NonNullable<TState>>>, TRules extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> ? UnwrapRef<TRules> : {}> : TState extends any[] ? TState[] : TState;
|
|
835
833
|
/**
|
|
836
834
|
* Infer input type from a rules object
|
|
837
835
|
*
|
|
@@ -839,15 +837,15 @@ type InferOutput<TRules$1 extends MaybeRef<ReglePartialRuleTree<Record<string, a
|
|
|
839
837
|
* type FormRequest = InferInput<typeof rules>;
|
|
840
838
|
* ```
|
|
841
839
|
*/
|
|
842
|
-
type InferInput<TRules
|
|
840
|
+
type InferInput<TRules extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TMarkMaybe extends boolean = true> = TRules extends MaybeRef<StandardSchemaV1<infer State>> ? State : IsUnion<UnwrapSimple<TRules>> extends true ? InferTupleUnionInput<UnionToTuple<UnwrapSimple<TRules>>>[number] : TMarkMaybe extends true ? Prettify<{ [K in keyof UnwrapSimple<TRules> as UnwrapSimple<TRules>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? K : never]?: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe> } & { [K in keyof UnwrapSimple<TRules> as UnwrapSimple<TRules>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? never : K]: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe> }> : Prettify<{ [K in keyof UnwrapSimple<TRules>]: ProcessInputChildren<UnwrapSimple<TRules>[K], TMarkMaybe> }>;
|
|
843
841
|
type ProcessInputChildren<TRule extends unknown, TMarkMaybe extends boolean> = TRule extends {
|
|
844
842
|
$each: RegleCollectionEachRules<any, any>;
|
|
845
843
|
} ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any, any> ? InferInput<ExtractFromGetter<TRule['$each']>, TMarkMaybe>[] : any[] : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? [ExtractTypeFromRules<UnwrapRef<TRule>>] extends [never] ? unknown : ExtractTypeFromRules<UnwrapRef<TRule>> : TRule extends ReglePartialRuleTree<any, any> ? InferInput<TRule, TMarkMaybe> : string;
|
|
846
|
-
type ExtractTypeFromRules<TRules
|
|
844
|
+
type ExtractTypeFromRules<TRules extends RegleRuleDecl<any, any>> = FilterRulesWithInput<TRules> extends {
|
|
847
845
|
type: infer Input;
|
|
848
|
-
} ? Input : [FilterRulesWithSingleType<TRules
|
|
849
|
-
type FilterRulesWithInput<TRules
|
|
850
|
-
type FilterRulesWithSingleType<TRules
|
|
846
|
+
} ? Input : [FilterRulesWithSingleType<TRules>[keyof FilterRulesWithSingleType<TRules>]] extends [never] ? FilterRulesWithInput<TRules>[keyof FilterRulesWithInput<TRules>] : FilterRulesWithSingleType<TRules>[keyof FilterRulesWithSingleType<TRules>];
|
|
847
|
+
type FilterRulesWithInput<TRules extends RegleRuleDecl<any, any>> = { [K in keyof TRules as TRules[K] extends RegleRuleDefinition<unknown, any, any, any, any, infer Input> ? unknown extends Input ? never : K : never]: TRules[K] extends RegleRuleDefinition<unknown, any, any, any, any, infer Input> ? Input : unknown };
|
|
848
|
+
type FilterRulesWithSingleType<TRules extends RegleRuleDecl<any, any>> = { [K in keyof TRules as TRules[K] extends RegleRuleDefinition<unknown, any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion<NonNullable<Input>> extends true ? never : K : never]: TRules[K] extends RegleRuleDefinition<unknown, any, any, any, any, infer Input> ? IsUnion<NonNullable<Input>> extends true ? unknown : Input : unknown };
|
|
851
849
|
type InferTupleUnionInput<T extends any[]> = T extends [infer F extends ReglePartialRuleTree, ...infer R] ? [InferInput<F, true>, ...InferTupleUnionInput<R>] : [];
|
|
852
850
|
/**
|
|
853
851
|
* Infer safe output from any `r$` instance
|
|
@@ -905,21 +903,21 @@ type CreateFn<T extends any[]> = (...args: T) => any;
|
|
|
905
903
|
*
|
|
906
904
|
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
907
905
|
*/
|
|
908
|
-
type RegleUniversalParams<T extends any[] = [], F
|
|
909
|
-
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F
|
|
906
|
+
type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>> }) => any : never>;
|
|
907
|
+
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends ((...args: infer Args) => any) ? (...args: { [K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K] }) => any : never>;
|
|
910
908
|
/**
|
|
911
909
|
* Internal definition of the rule, this can be used to reset or patch the rule
|
|
912
910
|
*/
|
|
913
|
-
type RegleInternalRuleDefs<TValue
|
|
914
|
-
_validator: (value: Maybe<TValue
|
|
915
|
-
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue
|
|
916
|
-
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue
|
|
917
|
-
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue
|
|
911
|
+
type RegleInternalRuleDefs<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> = Raw<{
|
|
912
|
+
_validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
913
|
+
_message: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
914
|
+
_active?: boolean | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => boolean);
|
|
915
|
+
_tooltip?: string | string[] | ((metadata: PossibleRegleRuleMetadataConsumer<TValue>) => string | string[]);
|
|
918
916
|
_type?: string;
|
|
919
917
|
_message_patched: boolean;
|
|
920
918
|
_tooltip_patched: boolean;
|
|
921
|
-
_params?: RegleUniversalParams<TParams
|
|
922
|
-
_async: TAsync
|
|
919
|
+
_params?: RegleUniversalParams<TParams>;
|
|
920
|
+
_async: TAsync;
|
|
923
921
|
readonly _brand: symbol;
|
|
924
922
|
}>;
|
|
925
923
|
declare const InternalRuleType: {
|
|
@@ -931,26 +929,26 @@ type IsLiteral<T> = string extends T ? false : true;
|
|
|
931
929
|
/**
|
|
932
930
|
* Returned typed of rules created with `createRule`
|
|
933
931
|
* */
|
|
934
|
-
interface RegleRuleDefinition<TType
|
|
935
|
-
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams
|
|
932
|
+
interface RegleRuleDefinition<TType extends string | unknown = unknown, TValue extends unknown = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, _TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & (infer M) ? M : TValue), TNonEmpty extends boolean = boolean> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
|
|
933
|
+
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
|
|
936
934
|
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
937
935
|
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
938
936
|
tooltip: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
939
|
-
type?: TType
|
|
940
|
-
_value?: IsLiteral<TValue
|
|
941
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync
|
|
937
|
+
type?: TType;
|
|
938
|
+
_value?: IsLiteral<TValue> extends true ? TValue : any;
|
|
939
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
|
|
942
940
|
required: TNonEmpty;
|
|
943
941
|
}
|
|
944
942
|
/**
|
|
945
943
|
* Rules with params created with `createRules` are callable while being customizable
|
|
946
944
|
*/
|
|
947
|
-
type RegleRuleWithParamsDefinition<TType
|
|
948
|
-
(...params: RegleUniversalParams<TParams
|
|
949
|
-
} & (TParams
|
|
950
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync
|
|
945
|
+
type RegleRuleWithParamsDefinition<TType extends string | unknown = unknown, TValue extends unknown = unknown, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & (infer M) ? M : TValue)> = RegleRuleCore<TType, TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & {
|
|
946
|
+
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TType, TFilteredValue, TParams, TAsync, TMetadata, TInput>;
|
|
947
|
+
} & (TParams extends [param?: any, ...any[]] ? {
|
|
948
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
951
949
|
} : {});
|
|
952
|
-
type RegleRuleWithParamsDefinitionInput<TType
|
|
953
|
-
exec: (value: Maybe<TFilteredValue>) => TAsync
|
|
950
|
+
type RegleRuleWithParamsDefinitionInput<TType extends string | unknown = unknown, TValue extends any = any, TParams extends any[] = never, TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = (TValue extends Date & File & (infer M) ? M : TValue)> = RegleRuleCore<TType, TFilteredValue, TParams, TAsync, TMetadata> & RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> & (TParams extends [param?: any, ...any[]] ? {
|
|
951
|
+
exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
954
952
|
} : {});
|
|
955
953
|
type RegleRuleMetadataExtended = {
|
|
956
954
|
$valid: boolean;
|
|
@@ -971,24 +969,24 @@ type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
|
971
969
|
/**
|
|
972
970
|
* Will be used to consume metadata on related helpers and rule status
|
|
973
971
|
*/
|
|
974
|
-
type RegleRuleMetadataConsumer<TValue
|
|
975
|
-
$value: Maybe<TValue
|
|
976
|
-
} & DefaultMetadataProperties & (TParams
|
|
977
|
-
$params: [...TParams
|
|
978
|
-
}) & (Exclude<TMetadata
|
|
972
|
+
type RegleRuleMetadataConsumer<TValue extends any, TParams extends [...any[]] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
973
|
+
$value: Maybe<TValue>;
|
|
974
|
+
} & DefaultMetadataProperties & (TParams extends never ? {} : {
|
|
975
|
+
$params: [...TParams];
|
|
976
|
+
}) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
|
|
979
977
|
/**
|
|
980
978
|
* Will be used to consume metadata on related helpers and rule status
|
|
981
979
|
*/
|
|
982
|
-
type PossibleRegleRuleMetadataConsumer<TValue
|
|
983
|
-
$value: Maybe<TValue
|
|
980
|
+
type PossibleRegleRuleMetadataConsumer<TValue> = {
|
|
981
|
+
$value: Maybe<TValue>;
|
|
984
982
|
} & DefaultMetadataProperties & {
|
|
985
983
|
$params?: [...any[]];
|
|
986
984
|
};
|
|
987
985
|
/**
|
|
988
986
|
* Generic types for a created RegleRule
|
|
989
987
|
*/
|
|
990
|
-
type RegleRuleRaw<TType
|
|
991
|
-
type RegleRuleRawInput<TValue
|
|
988
|
+
type RegleRuleRaw<TType extends string | unknown = unknown, TValue extends any = any, TParams extends [...any[]] = [...any[]], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetaData> | RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetaData>;
|
|
989
|
+
type RegleRuleRawInput<TValue extends any = any, TParams extends [...any[]] = [...any[]], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = boolean> = Omit<RegleRuleDefinition<unknown, TValue, TParams, TAsync, TMetaData> | RegleRuleWithParamsDefinition<unknown, TValue, TParams, TAsync, TMetaData>, 'message' | 'tooltip' | 'active'> & {
|
|
992
990
|
message: any;
|
|
993
991
|
active?: any;
|
|
994
992
|
tooltip?: any;
|
|
@@ -998,43 +996,43 @@ type RegleRuleRawInput<TValue$1 extends any = any, TParams$1 extends [...any[]]
|
|
|
998
996
|
* For a rule with params it will return a function
|
|
999
997
|
* Otherwise it will return the rule definition
|
|
1000
998
|
*/
|
|
1001
|
-
type InferRegleRule<TType
|
|
1002
|
-
type RegleRuleDefinitionProcessor<TValue
|
|
1003
|
-
type RegleRuleDefinitionWithMetadataProcessor<TValue
|
|
1004
|
-
type RegleCollectionRuleDefinition<TValue
|
|
1005
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue
|
|
999
|
+
type InferRegleRule<TType extends string | unknown, TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean, TNonEmpty extends boolean = false> = [TParams] extends [[]] ? RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetaData, TValue, TValue, TNonEmpty> : RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetaData, TNonEmpty>;
|
|
1000
|
+
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
1001
|
+
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any[]>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
1002
|
+
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions> & {
|
|
1003
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
1006
1004
|
}) | ({
|
|
1007
|
-
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue
|
|
1005
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
1008
1006
|
} & CollectionRegleBehaviourOptions);
|
|
1009
|
-
type RegleInitPropertyGetter<TValue
|
|
1007
|
+
type RegleInitPropertyGetter<TValue, TReturn, TParams extends [...any[]], TMetadata extends RegleRuleMetadataDefinition> = TReturn | ((metadata: RegleRuleMetadataConsumer<TValue, TParams, TMetadata>) => TReturn);
|
|
1010
1008
|
/**
|
|
1011
1009
|
* @argument
|
|
1012
1010
|
* createRule arguments options
|
|
1013
1011
|
*/
|
|
1014
|
-
interface RegleRuleInit<TType
|
|
1015
|
-
validator: (value: Maybe<TValue
|
|
1016
|
-
message: RegleInitPropertyGetter<TValue
|
|
1017
|
-
active?: RegleInitPropertyGetter<TValue
|
|
1018
|
-
tooltip?: RegleInitPropertyGetter<TValue
|
|
1019
|
-
type?: TType
|
|
1020
|
-
async?: TAsync
|
|
1012
|
+
interface RegleRuleInit<TType extends string | unknown = unknown, TValue extends unknown = unknown, TParams extends [...any[]] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean, TMetadata extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TAsync extends boolean = (TReturn extends Promise<any> ? true : false), TNonEmpty extends boolean = false> {
|
|
1013
|
+
validator: (value: Maybe<TValue>, ...args: TParams) => TReturn;
|
|
1014
|
+
message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1015
|
+
active?: RegleInitPropertyGetter<TValue, boolean, TParams, TMetadata>;
|
|
1016
|
+
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1017
|
+
type?: TType;
|
|
1018
|
+
async?: TAsync;
|
|
1021
1019
|
required?: TNonEmpty;
|
|
1022
1020
|
}
|
|
1023
1021
|
/**
|
|
1024
1022
|
* @argument
|
|
1025
1023
|
* Rule core
|
|
1026
1024
|
*/
|
|
1027
|
-
interface RegleRuleCore<TType
|
|
1028
|
-
validator: (value: Maybe<TValue
|
|
1029
|
-
message: RegleInitPropertyGetter<TValue
|
|
1030
|
-
active?: RegleInitPropertyGetter<TValue
|
|
1031
|
-
tooltip?: RegleInitPropertyGetter<TValue
|
|
1032
|
-
type?: TType
|
|
1025
|
+
interface RegleRuleCore<TType extends string | unknown, TValue extends any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> {
|
|
1026
|
+
validator: (value: Maybe<TValue>, ...args: TParams) => TAsync extends false ? TMetadata : Promise<TMetadata>;
|
|
1027
|
+
message: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1028
|
+
active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1029
|
+
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1030
|
+
type?: TType;
|
|
1033
1031
|
async?: boolean;
|
|
1034
1032
|
}
|
|
1035
|
-
type RegleRuleTypeReturn<TValue
|
|
1036
|
-
value: TValue
|
|
1037
|
-
params: [...TParams
|
|
1033
|
+
type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
|
|
1034
|
+
value: TValue;
|
|
1035
|
+
params: [...TParams];
|
|
1038
1036
|
};
|
|
1039
1037
|
interface CommonComparisonOptions {
|
|
1040
1038
|
/**
|
|
@@ -1114,40 +1112,35 @@ type AllRulesDeclarations = ExtendedRulesDeclarations;
|
|
|
1114
1112
|
/**
|
|
1115
1113
|
* @public
|
|
1116
1114
|
*/
|
|
1117
|
-
type RegleRoot<TState
|
|
1115
|
+
type RegleRoot<TState extends object | Record<string, unknown> = {}, TRules extends ReglePartialRuleTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> = MaybeVariantStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
1118
1116
|
/**
|
|
1119
1117
|
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
1120
1118
|
*/
|
|
1121
1119
|
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
1122
1120
|
});
|
|
1123
|
-
type ProcessNestedFields<TState
|
|
1121
|
+
type ProcessNestedFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}, TIsFields extends boolean = false> = Or<HasNamedKeys<TState>, TIsFields> extends true ? { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } : {};
|
|
1124
1122
|
/**
|
|
1125
1123
|
* @public
|
|
1126
1124
|
*/
|
|
1127
|
-
type RegleStatus<TState
|
|
1128
|
-
/** 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. */
|
|
1129
|
-
readonly $fields: ProcessNestedFields<TState$1, TRules$1, TShortcuts, true>;
|
|
1125
|
+
type RegleStatus<TState extends object | Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState, TRules> & {
|
|
1126
|
+
/** 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. */readonly $fields: ProcessNestedFields<TState, TRules, TShortcuts, true>;
|
|
1130
1127
|
/**
|
|
1131
1128
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
1132
1129
|
*
|
|
1133
1130
|
* Only contains issues from properties where $dirty equals true.
|
|
1134
1131
|
*/
|
|
1135
|
-
readonly $issues: RegleIssuesTree<TState
|
|
1132
|
+
readonly $issues: RegleIssuesTree<TState, false, TRules>;
|
|
1136
1133
|
/**
|
|
1137
1134
|
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
1138
1135
|
*
|
|
1139
1136
|
* Only contains errors from properties where $dirty equals true.
|
|
1140
1137
|
* */
|
|
1141
|
-
readonly $errors: RegleErrorTree<TState
|
|
1142
|
-
/**
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
/**
|
|
1147
|
-
$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<RegleResult<JoinDiscriminatedUnions<TState$1>, TRules$1>>;
|
|
1148
|
-
} & ProcessNestedFields<TState$1, TRules$1, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> }) & (TRules$1['$self'] extends RegleRuleDecl ? {
|
|
1149
|
-
/** Represents the status of the parent object. Status only concern the object itself and not its children */
|
|
1150
|
-
readonly $self: RegleFieldStatus<NonNullable<TRules$1['$self']>, NonNullable<TRules$1['$self']>, TShortcuts>;
|
|
1138
|
+
readonly $errors: RegleErrorTree<TState, false>; /** Collection of all the error messages, collected for all children properties. */
|
|
1139
|
+
readonly $silentErrors: RegleErrorTree<TState>; /** 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). */
|
|
1140
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState>; /** 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). */
|
|
1141
|
+
$validate: (forceValues?: JoinDiscriminatedUnions<TState> extends EmptyObject ? any : HasNamedKeys<JoinDiscriminatedUnions<TState>> extends true ? IsUnknown<JoinDiscriminatedUnions<TState>> extends true ? any : JoinDiscriminatedUnions<TState> : any) => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
|
|
1142
|
+
} & ProcessNestedFields<TState, TRules, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> }) & (TRules['$self'] extends RegleRuleDecl ? {
|
|
1143
|
+
/** Represents the status of the parent object. Status only concern the object itself and not its children */readonly $self: RegleFieldStatus<NonNullable<TRules['$self']>, NonNullable<TRules['$self']>, TShortcuts>;
|
|
1151
1144
|
} : {});
|
|
1152
1145
|
/**
|
|
1153
1146
|
* @internal
|
|
@@ -1169,7 +1162,7 @@ interface $InternalRegleStatus extends $InternalRegleCommonStatus {
|
|
|
1169
1162
|
/**
|
|
1170
1163
|
* @public
|
|
1171
1164
|
*/
|
|
1172
|
-
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState
|
|
1165
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TState> extends true ? [TState[TKey]] extends [undefined | null] ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Array<unknown> ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState[TKey], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCollectionStatus<TState[TKey], {}, TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<Raw<TState[TKey]>, TRule, TShortcuts> : unknown extends TState[TKey] ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? NonNullable<TState[TKey]> extends RegleStaticImpl<infer U> ? RegleFieldStatus<Raw<U>, TRule, TShortcuts> : TRule extends ReglePartialRuleTree<TState[TKey]> ? MaybeVariantStatus<TState[TKey], TRule, TShortcuts> : MaybeVariantStatus<TState[TKey], {}, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<Raw<NonNullable<TState[TKey]>>, TRule, TShortcuts> : unknown extends TState[TKey] ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? NonNullable<TState[TKey]> extends RegleStaticImpl<infer U> ? RegleFieldStatus<Raw<U>, TRule, TShortcuts> : MaybeVariantStatus<TState[TKey], ReglePartialRuleTree<TState[TKey]>, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCommonStatus<unknown>;
|
|
1173
1166
|
/**
|
|
1174
1167
|
* @internal
|
|
1175
1168
|
* @reference {@link InferRegleStatusType}
|
|
@@ -1178,46 +1171,37 @@ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleS
|
|
|
1178
1171
|
/**
|
|
1179
1172
|
* @public
|
|
1180
1173
|
*/
|
|
1181
|
-
type RegleFieldStatus<TState
|
|
1182
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model
|
|
1183
|
-
$
|
|
1184
|
-
/** $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. */
|
|
1185
|
-
$silentValue: MaybeOutput<UnwrapNestedRefs<TState$1>>;
|
|
1174
|
+
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<ExtendedRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState, TRules>, '$value' | '$silentValue' | '$initialValue' | '$originalValue'> & {
|
|
1175
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/$value: MaybeOutput<UnwrapNestedRefs<TState>>; /** $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. */
|
|
1176
|
+
$silentValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
1186
1177
|
/**
|
|
1187
1178
|
* This value reflect the current initial value of the field.
|
|
1188
1179
|
* The initial value is different than the original value as the initial value can be mutated when using `$reset`.
|
|
1189
1180
|
*/
|
|
1190
|
-
readonly $initialValue: MaybeOutput<UnwrapNestedRefs<TState
|
|
1181
|
+
readonly $initialValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
1191
1182
|
/**
|
|
1192
1183
|
* This value reflect the original value of the field at original call. This can't be mutated
|
|
1193
1184
|
*/
|
|
1194
|
-
readonly $originalValue: MaybeOutput<UnwrapNestedRefs<TState
|
|
1185
|
+
readonly $originalValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
1195
1186
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1196
1187
|
*
|
|
1197
1188
|
* Only contains errors from properties where $dirty equals true. */
|
|
1198
|
-
readonly $errors: string[];
|
|
1199
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1189
|
+
readonly $errors: string[]; /** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1200
1190
|
readonly $silentErrors: string[];
|
|
1201
1191
|
/**
|
|
1202
1192
|
* Collect all metadata of validators, Only contains metadata from properties where $dirty equals true.
|
|
1203
1193
|
*/
|
|
1204
|
-
readonly $issues: RegleFieldIssue<TRules
|
|
1194
|
+
readonly $issues: RegleFieldIssue<TRules>[];
|
|
1205
1195
|
/**
|
|
1206
1196
|
* Collect all metadata of validators, including the error message.
|
|
1207
1197
|
*/
|
|
1208
|
-
readonly $silentIssues: RegleFieldIssue<TRules
|
|
1209
|
-
/** Stores
|
|
1210
|
-
readonly $
|
|
1211
|
-
/**
|
|
1212
|
-
|
|
1213
|
-
/**
|
|
1214
|
-
readonly $
|
|
1215
|
-
/** 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). */
|
|
1216
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState$1>;
|
|
1217
|
-
/** 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). */
|
|
1218
|
-
$validate: (forceValues?: IsUnknown<TState$1> extends true ? any : TState$1) => Promise<RegleFieldResult<TState$1, TRules$1>>;
|
|
1219
|
-
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1220
|
-
readonly $rules: ComputeFieldRules<TState$1, TRules$1>;
|
|
1198
|
+
readonly $silentIssues: RegleFieldIssue<TRules>[]; /** Stores external errors of the current field */
|
|
1199
|
+
readonly $externalErrors: string[]; /** Stores active tooltips messages of the current field */
|
|
1200
|
+
readonly $tooltips: string[]; /** Represents the inactive status. Is true when this state have empty rules */
|
|
1201
|
+
readonly $inactive: boolean; /** 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). */
|
|
1202
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>; /** 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). */
|
|
1203
|
+
$validate: (forceValues?: IsUnknown<TState> extends true ? any : TState) => Promise<RegleFieldResult<TState, TRules>>; /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1204
|
+
readonly $rules: ComputeFieldRules<TState, TRules>;
|
|
1221
1205
|
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
1222
1206
|
/**
|
|
1223
1207
|
* @internal
|
|
@@ -1242,7 +1226,7 @@ interface $InternalRegleFieldStatus extends $InternalRegleCommonStatus {
|
|
|
1242
1226
|
/**
|
|
1243
1227
|
* @public
|
|
1244
1228
|
*/
|
|
1245
|
-
interface RegleCommonStatus<TValue
|
|
1229
|
+
interface RegleCommonStatus<TValue = any, TRules extends Record<string, any> = never> extends StandardSchemaV1<TValue, [TRules] extends [never] ? TValue : InferOutput<TRules, TValue>> {
|
|
1246
1230
|
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
1247
1231
|
readonly $invalid: boolean;
|
|
1248
1232
|
/**
|
|
@@ -1278,20 +1262,20 @@ interface RegleCommonStatus<TValue$1 = any, TRules$1 extends Record<string, any>
|
|
|
1278
1262
|
/** Id used to track collections items */
|
|
1279
1263
|
$id?: string;
|
|
1280
1264
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1281
|
-
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue
|
|
1265
|
+
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1282
1266
|
/**
|
|
1283
1267
|
* `$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.
|
|
1284
1268
|
* */
|
|
1285
|
-
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue
|
|
1269
|
+
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1286
1270
|
/**
|
|
1287
1271
|
* This value reflect the current initial value of the field.
|
|
1288
1272
|
* The initial value is different than the original value as the initial value can be mutated when using `$reset`.
|
|
1289
1273
|
*/
|
|
1290
|
-
readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue
|
|
1274
|
+
readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1291
1275
|
/**
|
|
1292
1276
|
* This value reflect the original value of the field at original call. This can't be mutated
|
|
1293
1277
|
*/
|
|
1294
|
-
readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue
|
|
1278
|
+
readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1295
1279
|
/** Marks the field and all nested properties as $dirty. */
|
|
1296
1280
|
$touch(): void;
|
|
1297
1281
|
/**
|
|
@@ -1300,7 +1284,7 @@ interface RegleCommonStatus<TValue$1 = any, TRules$1 extends Record<string, any>
|
|
|
1300
1284
|
* Rerun rules if `$lazy` is false
|
|
1301
1285
|
*/
|
|
1302
1286
|
$reset(): void;
|
|
1303
|
-
$reset(options?: ResetOptions<TValue
|
|
1287
|
+
$reset(options?: ResetOptions<TValue>): void;
|
|
1304
1288
|
/** Clears the $externalErrors state back to an empty object. */
|
|
1305
1289
|
$clearExternalErrors(): void;
|
|
1306
1290
|
}
|
|
@@ -1314,35 +1298,22 @@ interface $InternalRegleCommonStatus extends Omit<RegleCommonStatus, '$touch' |
|
|
|
1314
1298
|
/**
|
|
1315
1299
|
* @public
|
|
1316
1300
|
*/
|
|
1317
|
-
type RegleRuleStatus<TValue
|
|
1318
|
-
/** The name of the rule type. */
|
|
1319
|
-
readonly $
|
|
1320
|
-
|
|
1321
|
-
readonly $
|
|
1322
|
-
/**
|
|
1323
|
-
readonly $
|
|
1324
|
-
|
|
1325
|
-
readonly $
|
|
1326
|
-
/**
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
/**
|
|
1331
|
-
readonly $path: string;
|
|
1332
|
-
/** Contains the metadata returned by the validator function. */
|
|
1333
|
-
readonly $metadata: TMetadata$1 extends boolean ? TMetadata$1 : Omit<TMetadata$1, '$valid'>;
|
|
1334
|
-
/** Run the rule validator and compute its properties like $message and $active */
|
|
1335
|
-
$parse(): Promise<boolean>;
|
|
1336
|
-
/** Reset the $valid, $metadata and $pending states */
|
|
1337
|
-
$reset(): void;
|
|
1338
|
-
/** Returns the original rule validator function. */
|
|
1339
|
-
$validator: ((value: IsUnknown<TValue$1> extends true ? any : MaybeInput<TValue$1>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: IsUnknown<TValue$1> extends true ? any : TValue$1, ...args: [TParams$1] extends [never[]] ? [] : [unknown[]] extends [TParams$1] ? any[] : TParams$1) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
1340
|
-
} & ([TParams$1] extends [never[]] ? {} : [unknown[]] extends [TParams$1] ? {
|
|
1341
|
-
/** Contains the rule parameters when the rule accepts arguments. */
|
|
1342
|
-
readonly $params?: any[];
|
|
1301
|
+
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
1302
|
+
/** The name of the rule type. */readonly $type: string; /** Returns the computed error message or messages for the current rule. */
|
|
1303
|
+
readonly $message: string | string[]; /** Stores the current rule tooltip or tooltips */
|
|
1304
|
+
readonly $tooltip: string | string[]; /** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
1305
|
+
readonly $active: boolean; /** Indicates the state of validation for this validator. */
|
|
1306
|
+
readonly $valid: boolean; /** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
1307
|
+
readonly $pending: boolean; /** Returns the current path of the rule (used internally for tracking) */
|
|
1308
|
+
readonly $path: string; /** Contains the metadata returned by the validator function. */
|
|
1309
|
+
readonly $metadata: TMetadata extends boolean ? TMetadata : Omit<TMetadata, '$valid'>; /** Run the rule validator and compute its properties like $message and $active */
|
|
1310
|
+
$parse(): Promise<boolean>; /** Reset the $valid, $metadata and $pending states */
|
|
1311
|
+
$reset(): void; /** Returns the original rule validator function. */
|
|
1312
|
+
$validator: ((value: IsUnknown<TValue> extends true ? any : MaybeInput<TValue>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: IsUnknown<TValue> extends true ? any : TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
1313
|
+
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
1314
|
+
/** Contains the rule parameters when the rule accepts arguments. */readonly $params?: any[];
|
|
1343
1315
|
} : {
|
|
1344
|
-
/** Contains the rule parameters when the rule accepts arguments. */
|
|
1345
|
-
readonly $params: [...TParams$1];
|
|
1316
|
+
/** Contains the rule parameters when the rule accepts arguments. */readonly $params: [...TParams];
|
|
1346
1317
|
});
|
|
1347
1318
|
/**
|
|
1348
1319
|
* @internal
|
|
@@ -1376,31 +1347,24 @@ interface $InternalRegleRuleStatus {
|
|
|
1376
1347
|
/**
|
|
1377
1348
|
* @public
|
|
1378
1349
|
*/
|
|
1379
|
-
type RegleCollectionStatus<TState
|
|
1380
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model
|
|
1381
|
-
$
|
|
1382
|
-
|
|
1383
|
-
$
|
|
1384
|
-
/** Collection of status of every item in your collection. Each item will be a field you can access, or map on it to display your elements. */
|
|
1385
|
-
readonly $each: Array<InferRegleStatusType<NonNullable<TRules$1>, NonNullable<TState$1>, number, TShortcuts>>;
|
|
1386
|
-
/** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
|
|
1387
|
-
readonly $self: RegleFieldStatus<TState$1, TFieldRule, TShortcuts>;
|
|
1350
|
+
type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePartialRuleTree<Record<string, any>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState, TRules>, '$value'> & {
|
|
1351
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/$value: MaybeOutput<TState>; /** $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. */
|
|
1352
|
+
$silentValue: MaybeOutput<TState>; /** Collection of status of every item in your collection. Each item will be a field you can access, or map on it to display your elements. */
|
|
1353
|
+
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>; /** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
|
|
1354
|
+
readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
1388
1355
|
/**
|
|
1389
1356
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
1390
1357
|
*
|
|
1391
1358
|
* Only contains issues from properties where $dirty equals true.
|
|
1392
1359
|
*/
|
|
1393
|
-
readonly $issues: RegleCollectionErrors<TState
|
|
1360
|
+
readonly $issues: RegleCollectionErrors<TState, true>;
|
|
1394
1361
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1395
1362
|
*
|
|
1396
1363
|
* Only contains errors from properties where $dirty equals true. */
|
|
1397
|
-
readonly $errors: RegleCollectionErrors<TState
|
|
1398
|
-
/**
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState$1>;
|
|
1402
|
-
/** 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). */
|
|
1403
|
-
$validate: (value?: JoinDiscriminatedUnions<TState$1>) => Promise<RegleCollectionResult<TState$1, JoinDiscriminatedUnions<TRules$1>>>;
|
|
1364
|
+
readonly $errors: RegleCollectionErrors<TState>; /** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1365
|
+
readonly $silentErrors: RegleCollectionErrors<TState>; /** 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). */
|
|
1366
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TState>; /** 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). */
|
|
1367
|
+
$validate: (value?: JoinDiscriminatedUnions<TState>) => Promise<RegleCollectionResult<TState, JoinDiscriminatedUnions<TRules>>>;
|
|
1404
1368
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
1405
1369
|
/**
|
|
1406
1370
|
* @internal
|
|
@@ -1438,7 +1402,7 @@ type RegleUnknownRulesTree = {
|
|
|
1438
1402
|
/**
|
|
1439
1403
|
* @public
|
|
1440
1404
|
*/
|
|
1441
|
-
type RegleComputedRules<TForm extends MaybeRefOrComputedRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<ExtendedRulesDeclarations> | Regle<any, any> | useRegleFn<any> = Partial<ExtendedRulesDeclarations>, TState
|
|
1405
|
+
type RegleComputedRules<TForm extends MaybeRefOrComputedRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<ExtendedRulesDeclarations> | Regle<any, any> | useRegleFn<any> = Partial<ExtendedRulesDeclarations>, TState = 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>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState>[TKey], Omit<Partial<ExtendedRulesDeclarations>, keyof TCustom> & Partial<TCustom>> };
|
|
1442
1406
|
/**
|
|
1443
1407
|
* @internal
|
|
1444
1408
|
* @reference {@link ReglePartialRuleTree}
|
|
@@ -1451,7 +1415,7 @@ type $InternalReglePartialRuleTree = {
|
|
|
1451
1415
|
/**
|
|
1452
1416
|
* @public
|
|
1453
1417
|
*/
|
|
1454
|
-
type RegleFormPropertyType<TValue
|
|
1418
|
+
type RegleFormPropertyType<TValue = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = [NonNullable<TValue>] extends [never] ? MaybeRefOrComputedRef<RegleRuleDecl<TValue, TCustomRules>> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue>, TCustomRules>> : NonNullable<TValue> extends File ? MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue>, TCustomRules>> : NonNullable<TValue> extends Ref<infer V> ? RegleFormPropertyType<V, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? NonNullable<TValue> extends RegleStatic<infer U> ? MaybeRefOrComputedRef<RegleRuleDecl<Raw<U>, TCustomRules>> : ReglePartialRuleTree<NonNullable<TValue>, TCustomRules> : MaybeRefOrComputedRef<RegleRuleDecl<NonNullable<TValue>, TCustomRules>>;
|
|
1455
1419
|
/**
|
|
1456
1420
|
* @internal
|
|
1457
1421
|
* @reference {@link RegleFormPropertyType}
|
|
@@ -1461,8 +1425,8 @@ type $InternalFormPropertyTypes = MaybeRefOrComputedRef<$InternalRegleRuleDecl>
|
|
|
1461
1425
|
* @public
|
|
1462
1426
|
* Rule tree for a form property
|
|
1463
1427
|
*/
|
|
1464
|
-
type RegleRuleDecl<TValue
|
|
1465
|
-
[x: string]: FormRuleDeclaration<TValue
|
|
1428
|
+
type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<DefaultValidatorsTree>, TOptions extends Record<string, unknown> = FieldRegleBehaviourOptions<TValue>> = TOptions & { [TKey in keyof RemoveIndexSignature<TCustomRules>]?: FormRuleDeclaration<TValue, any[]> } & {
|
|
1429
|
+
[x: string]: FormRuleDeclaration<TValue, any[]> | boolean | number | undefined;
|
|
1466
1430
|
};
|
|
1467
1431
|
/**
|
|
1468
1432
|
* @internal
|
|
@@ -1475,9 +1439,9 @@ type $InternalRegleRuleDecl = FieldRegleBehaviourOptions & CollectionRegleBehavi
|
|
|
1475
1439
|
type RegleCollectionRuleDeclKeyProperty = {
|
|
1476
1440
|
$key?: PropertyKey;
|
|
1477
1441
|
};
|
|
1478
|
-
type CollectionEachRuleDecl<TValue
|
|
1479
|
-
$each?: RegleCollectionEachRules<TValue
|
|
1480
|
-
} : MaybeNullable<TValue
|
|
1442
|
+
type CollectionEachRuleDecl<TValue = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = IsAny<TValue> extends true ? {
|
|
1443
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
1444
|
+
} : MaybeNullable<TValue> extends true ? {
|
|
1481
1445
|
/**
|
|
1482
1446
|
* Rules for each item in the collection
|
|
1483
1447
|
*
|
|
@@ -1485,19 +1449,19 @@ type CollectionEachRuleDecl<TValue$1 = any[], TCustomRules extends Partial<Exten
|
|
|
1485
1449
|
* Regle can't guess the type of the array if it's undefined.
|
|
1486
1450
|
* Having an empty `$each: {}` is the only way to tell Regle that the array is a collection.
|
|
1487
1451
|
*/
|
|
1488
|
-
$each: RegleCollectionEachRules<TValue
|
|
1452
|
+
$each: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
1489
1453
|
} : {
|
|
1490
1454
|
/**
|
|
1491
1455
|
* Rules for each item in the collection
|
|
1492
1456
|
*/
|
|
1493
|
-
$each?: RegleCollectionEachRules<TValue
|
|
1457
|
+
$each?: RegleCollectionEachRules<TValue, TCustomRules>;
|
|
1494
1458
|
};
|
|
1495
1459
|
/**
|
|
1496
1460
|
* @public
|
|
1497
1461
|
*/
|
|
1498
|
-
type RegleCollectionRuleDecl<TValue
|
|
1462
|
+
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = (CollectionEachRuleDecl<TValue, TCustomRules> & RegleRuleDecl<NonNullable<TValue>, TCustomRules, CollectionRegleBehaviourOptions>) | (CollectionEachRuleDecl<TValue, TCustomRules> & CollectionRegleBehaviourOptions);
|
|
1499
1463
|
/** @public */
|
|
1500
|
-
type RegleCollectionEachRules<TValue
|
|
1464
|
+
type RegleCollectionEachRules<TValue = any[], TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>> = MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>, RegleCollectionRuleDeclKeyProperty, RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>>;
|
|
1501
1465
|
/**
|
|
1502
1466
|
* @internal
|
|
1503
1467
|
* @reference {@link RegleCollectionRuleDecl}
|
|
@@ -1510,31 +1474,31 @@ type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
|
|
|
1510
1474
|
/**
|
|
1511
1475
|
* @public
|
|
1512
1476
|
*/
|
|
1513
|
-
type InlineRuleDeclaration<TValue
|
|
1477
|
+
type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
|
|
1514
1478
|
/**
|
|
1515
1479
|
* @public
|
|
1516
1480
|
* Regroup inline and registered rules
|
|
1517
1481
|
* */
|
|
1518
|
-
type FormRuleDeclaration<TValue
|
|
1519
|
-
type RegleErrorTree<TState
|
|
1482
|
+
type FormRuleDeclaration<TValue extends any = unknown, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync extends boolean = boolean> = InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<unknown, TValue, TParams, TAsync, TMetadata, any, any, boolean> | RegleRuleWithParamsDefinitionInput<unknown, TValue, [param?: any], TAsync, TMetadata> | RegleRuleWithParamsDefinitionInput<unknown, TValue, [param?: any, ...any[]], TAsync, TMetadata>;
|
|
1483
|
+
type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>, TIssue extends boolean = false, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false, TIssue, TSchema> } & {
|
|
1520
1484
|
readonly $self?: string[];
|
|
1521
1485
|
};
|
|
1522
|
-
type RegleIssuesTree<TState
|
|
1486
|
+
type RegleIssuesTree<TState = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false, true, TSchema, K extends keyof TRules ? TRules[K] extends RegleFormPropertyType<Record<string, any>> ? TRules[K] : EmptyObject : EmptyObject> } & {
|
|
1523
1487
|
readonly $self?: RegleFieldIssue[];
|
|
1524
1488
|
};
|
|
1525
|
-
type RegleExternalErrorTree<TState
|
|
1489
|
+
type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true, TSchema> } & {
|
|
1526
1490
|
readonly $self?: RegleFieldIssue[];
|
|
1527
1491
|
};
|
|
1528
|
-
type RegleExternalSchemaErrorTree<TState
|
|
1529
|
-
type ErrorMessageOrIssue<TIssue extends boolean, TRules
|
|
1530
|
-
type RegleValidationErrors<TState
|
|
1531
|
-
type RegleFieldIssue<TRules
|
|
1492
|
+
type RegleExternalSchemaErrorTree<TState = MaybeRef<Record<string, any> | any[]>, TSchema extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true, true, TSchema> };
|
|
1493
|
+
type ErrorMessageOrIssue<TIssue extends boolean, TRules extends RegleFormPropertyType<Record<string, any>> = EmptyObject> = TIssue extends true ? RegleFieldIssue<TRules>[] : string[];
|
|
1494
|
+
type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false, TSchema extends boolean = false, TRules extends RegleFormPropertyType<Record<string, any>> = EmptyObject> = HasNamedKeys<TState> extends true ? IsAny<TState> extends true ? any : NonNullable<TState> extends Array<infer U> ? TSchema extends false ? TExternal extends false ? RegleCollectionErrors<U, TIssue, TSchema> : RegleExternalCollectionErrors<U, TIssue, TSchema> : RegleCollectionErrors<U, TIssue, TSchema> : NonNullable<TState> extends Date | File ? ErrorMessageOrIssue<TIssue, TRules> : NonNullable<TState> extends Record<string, any> ? IsRegleStatic<NonNullable<TState>> extends true ? ErrorMessageOrIssue<TIssue, TRules> : TExternal extends false ? RegleErrorTree<TState, TIssue, TSchema> : RegleExternalErrorTree<TState, TSchema> : ErrorMessageOrIssue<TIssue, TRules> : any;
|
|
1495
|
+
type RegleFieldIssue<TRules extends RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>> = EmptyObject> = {
|
|
1532
1496
|
readonly $property: string;
|
|
1533
1497
|
readonly $type?: string;
|
|
1534
1498
|
readonly $message: string;
|
|
1535
|
-
} & (IsEmptyObject<TRules
|
|
1499
|
+
} & (IsEmptyObject<TRules> extends true ? {
|
|
1536
1500
|
readonly $rule: string;
|
|
1537
|
-
} : { [K in keyof ComputeFieldRules<any, TRules
|
|
1501
|
+
} : { [K in keyof ComputeFieldRules<any, TRules>]: ComputeFieldRules<any, TRules>[K] extends {
|
|
1538
1502
|
$metadata: infer TMetadata;
|
|
1539
1503
|
} ? K extends string ? {
|
|
1540
1504
|
readonly $rule: K;
|
|
@@ -1544,17 +1508,17 @@ type RegleFieldIssue<TRules$1 extends RegleFormPropertyType<unknown, Partial<Ext
|
|
|
1544
1508
|
readonly $rule: string;
|
|
1545
1509
|
} : {
|
|
1546
1510
|
readonly $rule: string;
|
|
1547
|
-
} }[keyof ComputeFieldRules<any, TRules
|
|
1548
|
-
type ComputeFieldRules<TState
|
|
1549
|
-
readonly [x: string]: RegleRuleStatus<TState
|
|
1550
|
-
} : { readonly [TRuleKey in keyof Omit<UnwrapRef<TRules
|
|
1551
|
-
type RegleCollectionErrors<TState
|
|
1511
|
+
} }[keyof ComputeFieldRules<any, TRules>]);
|
|
1512
|
+
type ComputeFieldRules<TState extends any, TRules extends MaybeRef<RegleFormPropertyType<unknown, Partial<ExtendedRulesDeclarations>>>> = IsEmptyObject<UnwrapRef<TRules>> extends true ? {
|
|
1513
|
+
readonly [x: string]: RegleRuleStatus<TState, any[], any>;
|
|
1514
|
+
} : { readonly [TRuleKey in keyof Omit<UnwrapRef<TRules>, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, UnwrapRef<TRules>[TRuleKey] extends RegleRuleDefinition<unknown, any, infer TParams, any> ? TParams : [], UnwrapRef<TRules>[TRuleKey] extends RegleRuleDefinition<unknown, any, any, any, infer TMetadata> ? TMetadata : UnwrapRef<TRules>[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
|
|
1515
|
+
type RegleCollectionErrors<TState extends any, TIssue extends boolean = false, TSchema extends boolean = false> = {
|
|
1552
1516
|
readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
1553
|
-
readonly $each: RegleValidationErrors<TState
|
|
1517
|
+
readonly $each: RegleValidationErrors<TState, false, TIssue, TSchema>[];
|
|
1554
1518
|
};
|
|
1555
|
-
type RegleExternalCollectionErrors<TState
|
|
1519
|
+
type RegleExternalCollectionErrors<TState extends unknown, TIssue extends boolean = false, TSchema extends boolean = false> = {
|
|
1556
1520
|
readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
1557
|
-
readonly $each?: RegleValidationErrors<TState
|
|
1521
|
+
readonly $each?: RegleValidationErrors<TState, true, TIssue, TSchema>[];
|
|
1558
1522
|
};
|
|
1559
1523
|
/** @internal */
|
|
1560
1524
|
type $InternalRegleCollectionErrors = {
|
|
@@ -1573,8 +1537,8 @@ type $InternalRegleCollectionIssues = {
|
|
|
1573
1537
|
readonly $self?: RegleFieldIssue[];
|
|
1574
1538
|
readonly $each?: $InternalRegleIssues[];
|
|
1575
1539
|
};
|
|
1576
|
-
type RegleLike<TState
|
|
1577
|
-
$value: TState
|
|
1540
|
+
type RegleLike<TState extends Record<string, any>> = {
|
|
1541
|
+
$value: TState;
|
|
1578
1542
|
$validate: (...args: any[]) => Promise<SuperCompatibleRegleResult>;
|
|
1579
1543
|
};
|
|
1580
1544
|
interface SuperCompatibleRegle {
|
|
@@ -1683,51 +1647,37 @@ type SuperCompatibleRegleCollectionIssues = $InternalRegleCollectionIssues;
|
|
|
1683
1647
|
*
|
|
1684
1648
|
* @see {@link https://reglejs.dev/core-concepts/rules/reusable-rules Documentation}
|
|
1685
1649
|
*/
|
|
1686
|
-
declare function createRule<const TType
|
|
1650
|
+
declare function createRule<const TType extends string | unknown, TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync extends boolean = (TReturn extends Promise<any> ? true : false), TNonEmpty extends boolean = false>(definition: RegleRuleInit<TType, TValue, TParams, TReturn, TMetadata, TAsync, TNonEmpty>): InferRegleRule<TType, TValue, TParams, TAsync, TMetadata, TNonEmpty>;
|
|
1687
1651
|
/**
|
|
1688
1652
|
* Returns a clean list of parameters
|
|
1689
1653
|
* Removing Ref and executing function to return the unwrapped value
|
|
1690
1654
|
*/
|
|
1691
|
-
declare function unwrapRuleParameters<TParams
|
|
1692
|
-
type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue
|
|
1693
|
-
/** Map of merged Regle instances and their properties */
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
$value: TValue$1;
|
|
1697
|
-
/** $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. */
|
|
1698
|
-
$silentValue: TValue$1;
|
|
1655
|
+
declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
|
|
1656
|
+
type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TValue = { [K in keyof TRegles]: TRegles[K]['$value'] }> = Omit<RegleCommonStatus, '$value' | '$silentValue' | '$errors' | '$silentErrors' | '$name' | '$unwatch' | '$watch' | '$extractDirtyFields'> & {
|
|
1657
|
+
/** Map of merged Regle instances and their properties */readonly $instances: { [K in keyof TRegles]: TRegles[K] }; /** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1658
|
+
$value: TValue; /** $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. */
|
|
1659
|
+
$silentValue: TValue;
|
|
1699
1660
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1700
1661
|
*
|
|
1701
1662
|
* Only contains errors from properties where $dirty equals true. */
|
|
1702
|
-
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
1703
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
1663
|
+
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] }; /** Collection of all the error messages, collected for all children properties. */
|
|
1704
1664
|
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
1705
1665
|
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
1706
|
-
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
1707
|
-
|
|
1708
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>[];
|
|
1709
|
-
/** 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). */
|
|
1666
|
+
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] }; /** 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). */
|
|
1667
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue>[]; /** 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). */
|
|
1710
1668
|
$validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
|
|
1711
1669
|
} & (HasNamedKeys<TRegles> extends true ? { [K in keyof TRegles]: TRegles[K] } : {});
|
|
1712
|
-
type MergedScopedRegles<TValue
|
|
1713
|
-
/** Array of scoped Regles instances */
|
|
1714
|
-
readonly $
|
|
1715
|
-
/** Collection of all registered Regles instances
|
|
1716
|
-
readonly $
|
|
1717
|
-
/** Collection of all registered Regles instances
|
|
1718
|
-
readonly $
|
|
1719
|
-
/**
|
|
1720
|
-
|
|
1721
|
-
/** Collection of all registered Regles instances issues */
|
|
1722
|
-
readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
1723
|
-
/** Collection of all registered Regles instances silent issues */
|
|
1724
|
-
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
1725
|
-
/** 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). */
|
|
1726
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue$1>;
|
|
1727
|
-
/** 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). */
|
|
1728
|
-
$validate: (forceValues?: TValue$1) => Promise<{
|
|
1670
|
+
type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate' | '$extractDirtyFields'> & {
|
|
1671
|
+
/** Array of scoped Regles instances */readonly $instances: SuperCompatibleRegleRoot[]; /** Collection of all registered Regles instances values */
|
|
1672
|
+
readonly $value: TValue; /** Collection of all registered Regles instances errors */
|
|
1673
|
+
readonly $errors: RegleValidationErrors<Record<string, unknown>>[]; /** Collection of all registered Regles instances silent errors */
|
|
1674
|
+
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[]; /** Collection of all registered Regles instances issues */
|
|
1675
|
+
readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[]; /** Collection of all registered Regles instances silent issues */
|
|
1676
|
+
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[]; /** 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). */
|
|
1677
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TValue>; /** 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). */
|
|
1678
|
+
$validate: (forceValues?: TValue) => Promise<{
|
|
1729
1679
|
valid: boolean;
|
|
1730
|
-
data: TValue
|
|
1680
|
+
data: TValue;
|
|
1731
1681
|
errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
1732
1682
|
issues: RegleValidationErrors<Record<string, unknown>>[];
|
|
1733
1683
|
}>;
|
|
@@ -1786,10 +1736,10 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
|
|
|
1786
1736
|
* @see {@link https://reglejs.dev/advanced-usage/merge-regles Documentation}
|
|
1787
1737
|
*/
|
|
1788
1738
|
declare function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TScoped extends boolean = false>(regles: TRegles, _scoped?: TScoped): TScoped extends false ? MergedRegles<TRegles> : MergedScopedRegles;
|
|
1789
|
-
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue
|
|
1790
|
-
r$: MergedRegles<{ [K in keyof TValue
|
|
1791
|
-
} : <TValue
|
|
1792
|
-
r$: MergedScopedRegles<TValue
|
|
1739
|
+
type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string | string[]>) => {
|
|
1740
|
+
r$: MergedRegles<{ [K in keyof TValue]: RegleRoot<TValue[K]> & SuperCompatibleRegleRoot }>;
|
|
1741
|
+
} : <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string | string[]>) => {
|
|
1742
|
+
r$: MergedScopedRegles<TValue>;
|
|
1793
1743
|
};
|
|
1794
1744
|
type UseScopedRegleOptions<TAsRecord extends boolean> = {
|
|
1795
1745
|
namespace?: MaybeRefOrGetter<string>;
|
|
@@ -1882,8 +1832,8 @@ declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any>
|
|
|
1882
1832
|
*
|
|
1883
1833
|
* @see {@link https://reglejs.dev/advanced-usage/scoped-validation Documentation}
|
|
1884
1834
|
*/
|
|
1885
|
-
declare const useCollectScope: <TValue
|
|
1886
|
-
r$: MergedScopedRegles<TValue
|
|
1835
|
+
declare const useCollectScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string | string[]>) => {
|
|
1836
|
+
r$: MergedScopedRegles<TValue>;
|
|
1887
1837
|
};
|
|
1888
1838
|
/**
|
|
1889
1839
|
* Clone of `useRegle` that automatically registers its instance for collection by `useCollectScope`.
|
|
@@ -1983,9 +1933,9 @@ declare function narrowVariant<TRoot extends {
|
|
|
1983
1933
|
[x: string]: unknown;
|
|
1984
1934
|
};
|
|
1985
1935
|
$value: unknown;
|
|
1986
|
-
}, const TKey
|
|
1936
|
+
}, const TKey extends keyof TRoot, const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
|
|
1987
1937
|
$value: infer V;
|
|
1988
|
-
} ? V : unknown)>(root: TRoot | undefined, discriminantKey: TKey
|
|
1938
|
+
} ? V : unknown)>(root: TRoot | undefined, discriminantKey: TKey, discriminantValue: TValue): root is NarrowVariant<TRoot, TKey, TValue>;
|
|
1989
1939
|
/**
|
|
1990
1940
|
* Create a reactive reference to a narrowed variant.
|
|
1991
1941
|
* Useful in templates or when you need a stable ref to the narrowed type.
|
|
@@ -2010,17 +1960,17 @@ declare function narrowVariant<TRoot extends {
|
|
|
2010
1960
|
*
|
|
2011
1961
|
* @see {@link https://reglejs.dev/advanced-usage/variants Documentation}
|
|
2012
1962
|
*/
|
|
2013
|
-
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey
|
|
1963
|
+
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey extends keyof TRoot['$fields'], const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
|
|
2014
1964
|
$value: infer V;
|
|
2015
|
-
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey
|
|
1965
|
+
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue, options: {
|
|
2016
1966
|
/**
|
|
2017
1967
|
* Assert that the variant is always defined, use with caution
|
|
2018
1968
|
*/
|
|
2019
1969
|
unsafeAssertion: true;
|
|
2020
|
-
}): Ref<NarrowVariant<TRoot, TKey
|
|
2021
|
-
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey
|
|
1970
|
+
}): Ref<NarrowVariant<TRoot, TKey, TValue>>;
|
|
1971
|
+
declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey extends keyof TRoot['$fields'], const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
|
|
2022
1972
|
$value: infer V;
|
|
2023
|
-
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey
|
|
1973
|
+
} ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue): Ref<NarrowVariant<TRoot, TKey, TValue> | undefined>;
|
|
2024
1974
|
/**
|
|
2025
1975
|
* Helper method to wrap a raw rules object with type inference.
|
|
2026
1976
|
* Provides autocomplete and type-checking without processing.
|
|
@@ -2042,7 +1992,7 @@ declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKe
|
|
|
2042
1992
|
*
|
|
2043
1993
|
* @see {@link https://reglejs.dev/common-usage/standard-schema Documentation}
|
|
2044
1994
|
*/
|
|
2045
|
-
declare function defineRules<TRules
|
|
1995
|
+
declare function defineRules<TRules extends RegleUnknownRulesTree>(rules: TRules): TRules;
|
|
2046
1996
|
/**
|
|
2047
1997
|
* Refine a rules object to add rules that depend on the state values.
|
|
2048
1998
|
* Inspired by Zod's `refine`, this allows writing dynamic rules while maintaining type safety.
|
|
@@ -2072,7 +2022,7 @@ declare function defineRules<TRules$1 extends RegleUnknownRulesTree>(rules: TRul
|
|
|
2072
2022
|
*
|
|
2073
2023
|
* @see {@link https://reglejs.dev/common-usage/standard-schema#refinerules Documentation}
|
|
2074
2024
|
*/
|
|
2075
|
-
declare function refineRules<TRules
|
|
2025
|
+
declare function refineRules<TRules extends RegleUnknownRulesTree, TRefinement extends ReglePartialRuleTree<InferInput<TRules>> & RegleUnknownRulesTree>(rules: TRules, refinement: (state: Ref<InferInput<TRules>>) => TRefinement): (state: Ref<InferInput<TRules>>) => Merge<TRules, TRefinement>;
|
|
2076
2026
|
/**
|
|
2077
2027
|
* Vue plugin to enable Regle devtools integration with Vue Devtools.
|
|
2078
2028
|
* Provides debugging capabilities for inspecting validation trees, states, and actions.
|