@regle/core 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +125 -103
- package/dist/index.js +1 -35
- package/package.json +15 -15
- package/dist/index.cjs +0 -35
- package/dist/index.d.cts +0 -435
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
1
2
|
import { MaybeRef, ComputedRef, Ref, UnwrapNestedRefs } from 'vue';
|
|
2
3
|
|
|
3
4
|
type Maybe<T = any> = T | null | undefined;
|
|
5
|
+
type MaybeGetter<T, V = any> = T | ((value: V, index: number) => T);
|
|
6
|
+
type ExtractFromGetter<T extends MaybeGetter<any, any>> = T extends MaybeGetter<infer U, any> ? U : never;
|
|
4
7
|
type DeepMaybeRef<T extends Record<string, any>> = {
|
|
5
8
|
[K in keyof T]: MaybeRef<T[K]>;
|
|
6
9
|
};
|
|
@@ -11,6 +14,106 @@ type NonPresentKeys<TSource extends Record<string, any>, Target extends Record<s
|
|
|
11
14
|
|
|
12
15
|
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
13
16
|
|
|
17
|
+
declare global {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
19
|
+
interface SymbolConstructor {
|
|
20
|
+
readonly observable: symbol;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
28
|
+
|
|
29
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
30
|
+
|
|
31
|
+
@example
|
|
32
|
+
```
|
|
33
|
+
import type {EmptyObject} from 'type-fest';
|
|
34
|
+
|
|
35
|
+
// The following illustrates the problem with `{}`.
|
|
36
|
+
const foo1: {} = {}; // Pass
|
|
37
|
+
const foo2: {} = []; // Pass
|
|
38
|
+
const foo3: {} = 42; // Pass
|
|
39
|
+
const foo4: {} = {a: 1}; // Pass
|
|
40
|
+
|
|
41
|
+
// With `EmptyObject` only the first case is valid.
|
|
42
|
+
const bar1: EmptyObject = {}; // Pass
|
|
43
|
+
const bar2: EmptyObject = 42; // Fail
|
|
44
|
+
const bar3: EmptyObject = []; // Fail
|
|
45
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
49
|
+
|
|
50
|
+
@category Object
|
|
51
|
+
*/
|
|
52
|
+
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
53
|
+
|
|
54
|
+
interface RegleBehaviourOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Only display error when calling `validateForm()`
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
lazy?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Automaticaly set the dirty set without the need of `$value` or `$touch`
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
autoDirty?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The fields will turn valid when they are, but not invalid unless calling `validateForm()`
|
|
67
|
+
* @default false
|
|
68
|
+
*
|
|
69
|
+
* @experimental report any bug
|
|
70
|
+
*/
|
|
71
|
+
rewardEarly?: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>, TExternal extends RegleExternalErrorTree<TState>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> {
|
|
74
|
+
$externalErrors?: MaybeRef<TExternal>;
|
|
75
|
+
validationGroups?: (fields: RegleStatus<TState, TRules>['$fields']) => TValidationGroups;
|
|
76
|
+
}
|
|
77
|
+
type RegleValidationGroupEntry = RegleFieldStatus<any, any, any> | RegleCollectionStatus<any, any>;
|
|
78
|
+
interface RegleValidationGroupOutput {
|
|
79
|
+
$invalid: boolean;
|
|
80
|
+
$error: boolean;
|
|
81
|
+
$pending: boolean;
|
|
82
|
+
$dirty: boolean;
|
|
83
|
+
$valid: boolean;
|
|
84
|
+
$errors: string[];
|
|
85
|
+
$silentErrors: string[];
|
|
86
|
+
}
|
|
87
|
+
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
88
|
+
$debounce?: number;
|
|
89
|
+
};
|
|
90
|
+
type AddDollarToOptions<T extends Record<string, any>> = {
|
|
91
|
+
[K in keyof T as `$${string & K}`]: T[K];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
interface Regle<TState extends Record<string, any> = EmptyObject, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree> = EmptyObject, TExternal extends RegleExternalErrorTree<TState> = never, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never> {
|
|
95
|
+
regle: RegleStatus<TState, TRules, TValidationGroups>;
|
|
96
|
+
/** Show active errors based on your behaviour options (lazy, autoDirty)
|
|
97
|
+
* It allow you to skip scouting the `regle` object
|
|
98
|
+
*/
|
|
99
|
+
errors: RegleErrorTree<TRules, TExternal>;
|
|
100
|
+
invalid: ComputedRef<boolean>;
|
|
101
|
+
resetForm: () => void;
|
|
102
|
+
validateForm: () => Promise<false | DeepSafeFormState<TState, TRules>>;
|
|
103
|
+
state: Ref<TState>;
|
|
104
|
+
}
|
|
105
|
+
type DeepReactiveState<T extends Record<string, any>> = {
|
|
106
|
+
[K in keyof T]: MaybeRef<T[K]>;
|
|
107
|
+
};
|
|
108
|
+
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>> = [unknown] extends [TState] ? object : {
|
|
109
|
+
[K in keyof TState as [SafeProperty<TState[K], TRules[K]>] extends [never] ? K : never]?: [
|
|
110
|
+
SafeProperty<TState[K], TRules[K]>
|
|
111
|
+
] extends [never] ? TState[K] : SafeProperty<TState[K], TRules[K]>;
|
|
112
|
+
} & {
|
|
113
|
+
[K in keyof TState as [SafeProperty<TState[K], TRules[K]>] extends [never] ? never : K]-?: SafeProperty<TState[K], TRules[K]>;
|
|
114
|
+
};
|
|
115
|
+
type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? TState extends Array<any> ? SafeProperty<TState[number], ExtractFromGetter<TRule['$each']>>[] : never : TRule extends ReglePartialValidationTree<any, any> ? TState extends Record<string, any> ? DeepSafeFormState<TState, TRule> : never : TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? never : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params> ? Params extends never[] ? TState : never : never : never;
|
|
116
|
+
|
|
14
117
|
type ParamDecl<T = any> = MaybeRef<Maybe<T>> | (() => Maybe<T>);
|
|
15
118
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
16
119
|
/**
|
|
@@ -95,9 +198,9 @@ type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync
|
|
|
95
198
|
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
96
199
|
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<any, any>, TReturn = any> = ((value: Maybe<TValue>, metadata: TMetadata) => TReturn) | TReturn;
|
|
97
200
|
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
98
|
-
$each: RegleFormPropertyType<ArrayElement<TValue>,
|
|
201
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
99
202
|
}) | {
|
|
100
|
-
$each: RegleFormPropertyType<ArrayElement<TValue>,
|
|
203
|
+
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
101
204
|
};
|
|
102
205
|
|
|
103
206
|
/**
|
|
@@ -153,94 +256,6 @@ type CustomRulesDeclarationTree = {
|
|
|
153
256
|
};
|
|
154
257
|
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidators;
|
|
155
258
|
|
|
156
|
-
declare global {
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
158
|
-
interface SymbolConstructor {
|
|
159
|
-
readonly observable: symbol;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
167
|
-
|
|
168
|
-
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
169
|
-
|
|
170
|
-
@example
|
|
171
|
-
```
|
|
172
|
-
import type {EmptyObject} from 'type-fest';
|
|
173
|
-
|
|
174
|
-
// The following illustrates the problem with `{}`.
|
|
175
|
-
const foo1: {} = {}; // Pass
|
|
176
|
-
const foo2: {} = []; // Pass
|
|
177
|
-
const foo3: {} = 42; // Pass
|
|
178
|
-
const foo4: {} = {a: 1}; // Pass
|
|
179
|
-
|
|
180
|
-
// With `EmptyObject` only the first case is valid.
|
|
181
|
-
const bar1: EmptyObject = {}; // Pass
|
|
182
|
-
const bar2: EmptyObject = 42; // Fail
|
|
183
|
-
const bar3: EmptyObject = []; // Fail
|
|
184
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
188
|
-
|
|
189
|
-
@category Object
|
|
190
|
-
*/
|
|
191
|
-
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
192
|
-
|
|
193
|
-
interface Regle<TState extends Record<string, any> = EmptyObject, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree> = EmptyObject, TExternal extends RegleExternalErrorTree<TState> = never> {
|
|
194
|
-
regle: RegleStatus<TState, TRules>;
|
|
195
|
-
/** Show active errors based on your behaviour options (lazy, autoDirty)
|
|
196
|
-
* It allow you to skip scouting the `regle` object
|
|
197
|
-
*/
|
|
198
|
-
errors: RegleErrorTree<TRules, TExternal>;
|
|
199
|
-
invalid: ComputedRef<boolean>;
|
|
200
|
-
resetForm: () => void;
|
|
201
|
-
validateForm: () => Promise<false | DeepSafeFormState<TState, TRules>>;
|
|
202
|
-
}
|
|
203
|
-
type DeepReactiveState<T extends Record<string, any>> = {
|
|
204
|
-
[K in keyof T]: MaybeRef<T[K]>;
|
|
205
|
-
};
|
|
206
|
-
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree>> = [unknown] extends [TState] ? {} : {
|
|
207
|
-
[K in keyof TState as [SafeProperty<TState[K], TRules[K]>] extends [never] ? K : never]?: [
|
|
208
|
-
SafeProperty<TState[K], TRules[K]>
|
|
209
|
-
] extends [never] ? TState[K] : SafeProperty<TState[K], TRules[K]>;
|
|
210
|
-
} & {
|
|
211
|
-
[K in keyof TState as [SafeProperty<TState[K], TRules[K]>] extends [never] ? never : K]-?: SafeProperty<TState[K], TRules[K]>;
|
|
212
|
-
};
|
|
213
|
-
type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? TState extends Array<any> ? SafeProperty<TState[number], TRule['$each']>[] : never : TRule extends ReglePartialValidationTree<any, any> ? TState extends Record<string, any> ? DeepSafeFormState<TState, TRule> : never : TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? never : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params> ? Params extends never[] ? TState : never : never : never;
|
|
214
|
-
|
|
215
|
-
interface RegleBehaviourOptions {
|
|
216
|
-
/**
|
|
217
|
-
* Only display error when calling `validateForm()`
|
|
218
|
-
* @default false
|
|
219
|
-
*/
|
|
220
|
-
lazy?: boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Automaticaly set the dirty set without the need of `$value` or `$touch`
|
|
223
|
-
* @default true
|
|
224
|
-
*/
|
|
225
|
-
autoDirty?: boolean;
|
|
226
|
-
/**
|
|
227
|
-
* The fields will turn valid when they are, but not invalid unless calling `validateForm()`
|
|
228
|
-
* @default false
|
|
229
|
-
*
|
|
230
|
-
* @experimental report any bug
|
|
231
|
-
*/
|
|
232
|
-
rewardEarly?: boolean;
|
|
233
|
-
}
|
|
234
|
-
interface LocalRegleBehaviourOptions<TState extends Record<string, any>, TExternal extends RegleExternalErrorTree<TState>> {
|
|
235
|
-
$externalErrors?: MaybeRef<TExternal>;
|
|
236
|
-
}
|
|
237
|
-
type FieldRegleBehaviourOptions = AddDollarToOptions<RegleBehaviourOptions> & {
|
|
238
|
-
$debounce?: number;
|
|
239
|
-
};
|
|
240
|
-
type AddDollarToOptions<T extends Record<string, any>> = {
|
|
241
|
-
[K in keyof T as `$${string & K}`]: T[K];
|
|
242
|
-
};
|
|
243
|
-
|
|
244
259
|
/**
|
|
245
260
|
* @public
|
|
246
261
|
*/
|
|
@@ -274,9 +289,9 @@ type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRul
|
|
|
274
289
|
* @public
|
|
275
290
|
*/
|
|
276
291
|
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
277
|
-
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules
|
|
292
|
+
$each?: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
278
293
|
}) | {
|
|
279
|
-
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules
|
|
294
|
+
$each?: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
280
295
|
};
|
|
281
296
|
/**
|
|
282
297
|
* @public
|
|
@@ -293,7 +308,7 @@ type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>, TExtern
|
|
|
293
308
|
} & {
|
|
294
309
|
readonly [K in keyof NonPresentKeys<TRules, TExternal>]: RegleExternalValidationErrorsReport<TExternal[K]>;
|
|
295
310
|
};
|
|
296
|
-
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never, TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<TRule['$each']
|
|
311
|
+
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never, TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<ExtractFromGetter<TRule['$each']>, TExternalError extends RegleExternalCollectionErrors ? ArrayElement<TExternalError['$each']> : never> : TRule extends RegleRuleDecl<any, any> ? string[] : TRule extends ReglePartialValidationTree<any, any> ? RegleErrorTree<TRule, TExternalError extends RegleExternalErrorTree ? TExternalError : never> : string[];
|
|
297
312
|
type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never, TExternalError extends RegleExternalValidationErrors<any> | undefined = never> = {
|
|
298
313
|
readonly $errors: string[];
|
|
299
314
|
readonly $each: RegleValidationErrors<TRule, TExternalError>[];
|
|
@@ -313,23 +328,29 @@ type RegleExternalValidationErrorsReport<TExternalError extends RegleExternalVal
|
|
|
313
328
|
/**
|
|
314
329
|
* @public
|
|
315
330
|
*/
|
|
316
|
-
|
|
331
|
+
type RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never> = RegleCommonStatus<TState> & {
|
|
317
332
|
readonly $fields: {
|
|
318
333
|
readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
|
|
319
334
|
};
|
|
320
|
-
}
|
|
335
|
+
} & ([TValidationGroups] extends [never] ? object : {
|
|
336
|
+
$groups: {
|
|
337
|
+
readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput;
|
|
338
|
+
};
|
|
339
|
+
});
|
|
321
340
|
/**
|
|
322
341
|
* @public
|
|
323
342
|
*/
|
|
324
|
-
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? NonNullable<TState[TKey]> extends Array<Record<string, any> | any> ? RegleCollectionStatus<TRule['$each']
|
|
343
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? NonNullable<TState[TKey]> extends Array<Record<string, any> | any> ? ExtractFromGetter<TRule['$each']> extends RegleRuleDecl | ReglePartialValidationTree<any> ? RegleCollectionStatus<ExtractFromGetter<TRule['$each']>, TState[TKey]> : never : RegleFieldStatus<TRule, TState, TKey> : TRule extends ReglePartialValidationTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleCommonStatus<TState[TKey]> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? RegleStatus<TState[TKey], TRule> : RegleFieldStatus<TRule, TState, TKey> : RegleFieldStatus<TRule, TState, TKey>;
|
|
325
344
|
/**
|
|
326
345
|
* @public
|
|
327
346
|
*/
|
|
328
347
|
interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus<TState> {
|
|
329
348
|
$value: UnwrapNestedRefs<TState[TKey]>;
|
|
330
349
|
readonly $externalErrors?: string[];
|
|
350
|
+
readonly $errors: string[];
|
|
351
|
+
readonly $silentErrors: string[];
|
|
331
352
|
readonly $rules: {
|
|
332
|
-
readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
|
|
353
|
+
readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : never>;
|
|
333
354
|
};
|
|
334
355
|
}
|
|
335
356
|
/**
|
|
@@ -342,7 +363,7 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
342
363
|
readonly $anyDirty: boolean;
|
|
343
364
|
readonly $pending: boolean;
|
|
344
365
|
readonly $error: boolean;
|
|
345
|
-
$id?:
|
|
366
|
+
$id?: string;
|
|
346
367
|
$value: UnwrapNestedRefs<TValue>;
|
|
347
368
|
$touch(): void;
|
|
348
369
|
$reset(): void;
|
|
@@ -354,17 +375,18 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
354
375
|
/**
|
|
355
376
|
* @public
|
|
356
377
|
*/
|
|
357
|
-
type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
|
|
378
|
+
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = never> = {
|
|
358
379
|
readonly $type: string;
|
|
359
380
|
readonly $message: string | string[];
|
|
360
381
|
readonly $active: boolean;
|
|
361
382
|
readonly $valid: boolean;
|
|
362
383
|
readonly $pending: boolean;
|
|
363
384
|
readonly $path: string;
|
|
385
|
+
readonly $metadata: TMetadata;
|
|
364
386
|
$validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
365
387
|
$validate(): Promise<boolean>;
|
|
366
388
|
$reset(): void;
|
|
367
|
-
} & ([TParams] extends [[]] ?
|
|
389
|
+
} & ([TParams] extends [[]] ? object : {
|
|
368
390
|
readonly $params: TParams;
|
|
369
391
|
});
|
|
370
392
|
/**
|
|
@@ -418,7 +440,7 @@ declare function defineType<TValue extends any = unknown, TParams extends any[]
|
|
|
418
440
|
*/
|
|
419
441
|
declare function unwrapRuleParameters<TParams extends any[]>(params: ParamDecl[]): TParams;
|
|
420
442
|
|
|
421
|
-
declare const useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations>>, TExternal extends RegleExternalErrorTree<TState>, TValid = keyof TRules extends keyof TState ? true : false>(state:
|
|
443
|
+
declare const useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations>>, TExternal extends RegleExternalErrorTree<TState>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = keyof TRules extends keyof TState ? true : false>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState, TRules, TExternal, TValidationGroups>) | undefined) => Regle<TState, TRules, TExternal, TValidationGroups>;
|
|
422
444
|
|
|
423
445
|
/**
|
|
424
446
|
* Root function that allows you to define project-wise all your custom validators or overwrite default ones
|
|
@@ -430,6 +452,6 @@ declare const useRegle: <TState extends Record<string, any>, TRules extends Regl
|
|
|
430
452
|
declare function defineRegleConfig<TCustomRules extends Partial<AllRulesDeclarations>>({ rules, options, }: {
|
|
431
453
|
rules?: () => TCustomRules;
|
|
432
454
|
options?: RegleBehaviourOptions;
|
|
433
|
-
}): <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations> & TCustomRules>, TExternal extends RegleExternalErrorTree<TState>, TValid = keyof TRules extends keyof TState ? true : false>(state:
|
|
455
|
+
}): <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, Partial<AllRulesDeclarations> & TCustomRules>, TExternal extends RegleExternalErrorTree<TState>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = keyof TRules extends keyof TState ? true : false>(state: vue.MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: TValid extends true ? TRules | vue.ComputedRef<TRules> | (() => TRules) : never, options?: (Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<TState, TRules, TExternal, TValidationGroups>) | undefined) => Regle<TState, TRules, TExternal, TValidationGroups>;
|
|
434
456
|
|
|
435
|
-
export { type DeepMaybeRef, type FormRuleDeclaration, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type ParamDecl, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type
|
|
457
|
+
export { type DeepMaybeRef, type FormRuleDeclaration, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type ParamDecl, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalValidationErrors, type RegleFieldStatus, type RegleFormPropertyType, type ReglePartialValidationTree, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleWithParamsDefinition, type RegleStatus, type RegleValidationTree, type UnwrapRegleUniversalParams, createRule, defineRegleConfig, defineType, unwrapRuleParameters, useRegle };
|