@regle/core 0.0.3 → 0.0.4-beta.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/index.cjs +633 -277
- package/dist/index.d.cts +128 -26
- package/dist/index.d.ts +128 -26
- package/dist/index.js +641 -279
- package/package.json +5 -3
package/dist/index.d.cts
CHANGED
|
@@ -9,11 +9,11 @@ type Maybe<T> = T | null | undefined;
|
|
|
9
9
|
* @argument
|
|
10
10
|
* createRule arguments options
|
|
11
11
|
*/
|
|
12
|
-
interface RegleRuleInit<TValue extends any, TParams extends any[] = []> {
|
|
12
|
+
interface RegleRuleInit<TValue extends any, TParams extends any[] = [], TType extends string = string> {
|
|
13
13
|
validator: (value: Maybe<TValue>, ...args: TParams) => boolean | Promise<boolean>;
|
|
14
14
|
message: string | ((value: Maybe<TValue>, ...args: TParams) => string);
|
|
15
15
|
active?: boolean | ((value: Maybe<TValue>, ...args: TParams) => boolean);
|
|
16
|
-
type:
|
|
16
|
+
type: TType;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type DefaultValidators = {
|
|
@@ -92,26 +92,62 @@ type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends AllRules
|
|
|
92
92
|
type CustomRulesDeclarationTree = Record<string, RegleRuleRaw<any, any>>;
|
|
93
93
|
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidators;
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
95
98
|
type ReglePartialValidationTree<TForm extends Record<string, any>, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = {
|
|
96
99
|
[TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
|
|
97
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
* @reference {@link ReglePartialValidationTree}
|
|
104
|
+
*/
|
|
105
|
+
type $InternalReglePartialValidationTree = {
|
|
106
|
+
[x: string]: $InternalFormPropertyTypes;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
98
111
|
type RegleFormPropertyType<TValue = any, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<unknown, TCustomRules> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends File ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? ReglePartialValidationTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
|
|
99
112
|
/**
|
|
113
|
+
* @internal
|
|
114
|
+
* @reference {@link RegleFormPropertyType}
|
|
115
|
+
*/
|
|
116
|
+
type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialValidationTree;
|
|
117
|
+
/**
|
|
118
|
+
* @public
|
|
100
119
|
* Rule tree for a form property
|
|
101
120
|
*/
|
|
102
121
|
type RegleRuleDecl<TValue extends any = any, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = {
|
|
103
122
|
[TKey in keyof TCustomRules]?: TCustomRules[TKey] extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, TParams> : FormRuleDeclaration<TValue, any>;
|
|
104
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* @internal
|
|
126
|
+
* @reference {@link RegleRuleDecl}
|
|
127
|
+
*/
|
|
128
|
+
type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any>>;
|
|
129
|
+
/**
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
105
132
|
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
106
133
|
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
|
|
107
134
|
}) | {
|
|
108
135
|
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
|
|
109
136
|
};
|
|
110
137
|
/**
|
|
111
|
-
*
|
|
138
|
+
* @internal
|
|
139
|
+
* @reference {@link RegleCollectionRuleDecl}
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
|
|
143
|
+
$each?: $InternalFormPropertyTypes;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* @public
|
|
112
147
|
*/
|
|
113
|
-
type InlineRuleDeclaration<TValue extends any> = (value: Maybe<TValue>, ...args: any[]) => boolean | Promise<boolean>;
|
|
148
|
+
type InlineRuleDeclaration<TValue extends any = any> = (value: Maybe<TValue>, ...args: any[]) => boolean | Promise<boolean>;
|
|
114
149
|
/**
|
|
150
|
+
* @public
|
|
115
151
|
* Regroup inline and registered rules
|
|
116
152
|
* */
|
|
117
153
|
type FormRuleDeclaration<TValue extends any, TParams extends any[] = []> = InlineRuleDeclaration<TValue> | RegleRuleDefinition<TValue, TParams>;
|
|
@@ -119,7 +155,7 @@ type FormRuleDeclaration<TValue extends any, TParams extends any[] = []> = Inlin
|
|
|
119
155
|
type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
|
|
120
156
|
readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
|
|
121
157
|
};
|
|
122
|
-
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends
|
|
158
|
+
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<TRule['$each']> : TRule extends ReglePartialValidationTree<any, any> ? RegleErrorTree<TRule> : TRule extends RegleRuleDecl<any, any> ? string[] : string[];
|
|
123
159
|
type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = {
|
|
124
160
|
readonly $errors: string[];
|
|
125
161
|
readonly $each: RegleValidationErrors<TRule>[];
|
|
@@ -127,54 +163,118 @@ type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undef
|
|
|
127
163
|
type PossibleRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
|
|
128
164
|
type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
|
|
129
165
|
|
|
130
|
-
|
|
166
|
+
/**
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
interface RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>> extends RegleCommonStatus {
|
|
131
170
|
readonly $fields: {
|
|
132
171
|
readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
|
|
133
172
|
};
|
|
134
173
|
}
|
|
135
|
-
|
|
136
|
-
|
|
174
|
+
/**
|
|
175
|
+
* @internal
|
|
176
|
+
* @reference {@link RegleStatus}
|
|
177
|
+
*/
|
|
178
|
+
interface $InternalRegleStatus extends RegleCommonStatus {
|
|
179
|
+
$fields: {
|
|
180
|
+
[x: string]: $InternalRegleStatusType;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? RegleCollectionStatus<TRule['$each'], TState[TKey]> : TRule extends ReglePartialValidationTree<any> ? TState[TKey] extends Array<any> ? RegleCommonStatus : RegleStatus<TState[TKey], TRule> : RegleFieldStatus<TRule, TState, TKey>;
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
* @reference {@link InferRegleStatusType}
|
|
190
|
+
*/
|
|
191
|
+
type $InternalRegleStatusType = $InternalRegleCollectionStatus | RegleCommonStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
|
|
192
|
+
/**
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, AllRulesDeclarations> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus {
|
|
196
|
+
$value: TState[TKey];
|
|
137
197
|
readonly $rules: {
|
|
138
198
|
readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
|
|
139
199
|
};
|
|
140
200
|
}
|
|
141
|
-
|
|
201
|
+
/**
|
|
202
|
+
* @internal
|
|
203
|
+
* @reference {@link RegleFieldStatus}
|
|
204
|
+
*/
|
|
205
|
+
interface $InternalRegleFieldStatus extends RegleCommonStatus {
|
|
206
|
+
$value: any;
|
|
207
|
+
$rules: Record<string, $InternalRegleRuleStatus>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
interface RegleCommonStatus {
|
|
142
213
|
readonly $valid: boolean;
|
|
143
214
|
readonly $invalid: boolean;
|
|
144
215
|
readonly $dirty: boolean;
|
|
145
216
|
readonly $anyDirty: boolean;
|
|
146
217
|
readonly $pending: boolean;
|
|
147
|
-
$value: TValue;
|
|
148
218
|
readonly $error: boolean;
|
|
149
|
-
$touch
|
|
150
|
-
$reset
|
|
219
|
+
$touch(): void;
|
|
220
|
+
$reset(): void;
|
|
221
|
+
$validate(): Promise<boolean>;
|
|
222
|
+
$unwatch(): void;
|
|
223
|
+
$watch(): void;
|
|
151
224
|
}
|
|
152
|
-
|
|
225
|
+
/**
|
|
226
|
+
* @public
|
|
227
|
+
*/
|
|
228
|
+
type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
|
|
153
229
|
readonly $type: string;
|
|
154
230
|
readonly $message: string;
|
|
155
|
-
readonly $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
156
231
|
readonly $active: boolean;
|
|
157
232
|
readonly $valid: boolean;
|
|
158
233
|
readonly $pending: boolean;
|
|
159
|
-
readonly $
|
|
160
|
-
|
|
161
|
-
|
|
234
|
+
readonly $path: string;
|
|
235
|
+
$validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
236
|
+
$validate(): Promise<boolean>;
|
|
237
|
+
} & ([TParams] extends [[]] ? {} : {
|
|
238
|
+
readonly $params: TParams;
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* @internal
|
|
242
|
+
* @reference {@link RegleRuleStatus}
|
|
243
|
+
*/
|
|
244
|
+
interface $InternalRegleRuleStatus {
|
|
162
245
|
readonly $type: string;
|
|
163
246
|
readonly $message: string;
|
|
164
|
-
readonly $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
165
247
|
readonly $active: boolean;
|
|
166
248
|
readonly $valid: boolean;
|
|
167
249
|
readonly $pending: boolean;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
250
|
+
readonly $path: string;
|
|
251
|
+
$validator(value: any, ...args: any[]): boolean | Promise<boolean>;
|
|
252
|
+
$validate(): Promise<boolean>;
|
|
253
|
+
$unwatch(): void;
|
|
254
|
+
$watch(): void;
|
|
255
|
+
readonly $params?: any[];
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
171
260
|
interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
|
|
172
261
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
|
|
173
262
|
}
|
|
174
|
-
|
|
175
|
-
|
|
263
|
+
/**
|
|
264
|
+
* @internal
|
|
265
|
+
* @reference {@link RegleCollectionStatus}
|
|
266
|
+
*/
|
|
267
|
+
interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields'> {
|
|
268
|
+
$each: Array<$InternalRegleStatusType>;
|
|
269
|
+
$rules?: Record<string, $InternalRegleRuleStatus>;
|
|
270
|
+
$unwatch(): void;
|
|
271
|
+
$watch(): void;
|
|
272
|
+
$fields?: {
|
|
273
|
+
[x: string]: $InternalRegleStatusType;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
176
276
|
|
|
177
|
-
declare function createRule<TValue extends any, TParams extends any[] = []>(definition: RegleRuleInit<TValue, TParams>): InferRegleRule<TValue, TParams>;
|
|
277
|
+
declare function createRule<TValue extends any, TParams extends any[] = [], TType extends string = string>(definition: RegleRuleInit<TValue, TParams, TType>): InferRegleRule<TValue, TParams>;
|
|
178
278
|
|
|
179
279
|
/**
|
|
180
280
|
* Root function that allows you to define project-wise all your custom validators or overwrite default ones
|
|
@@ -186,9 +286,11 @@ declare function createRule<TValue extends any, TParams extends any[] = []>(defi
|
|
|
186
286
|
declare function defineCustomValidators<TCustomRules extends Partial<AllRulesDeclarations>>(customRules: () => TCustomRules): {
|
|
187
287
|
useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree & DefaultValidators & TCustomRules>>(state: vue.Ref<TState>, rulesFactory: vue.ComputedRef<TRules> | (() => TRules)) => {
|
|
188
288
|
state: vue.Ref<TState>;
|
|
189
|
-
$regle:
|
|
289
|
+
$regle: RegleStatus<TState, TRules>;
|
|
190
290
|
errors: RegleErrorTree<TRules>;
|
|
291
|
+
resetForm: () => void;
|
|
292
|
+
validateForm: () => Promise<boolean>;
|
|
191
293
|
};
|
|
192
294
|
};
|
|
193
295
|
|
|
194
|
-
export { AllRulesDeclarations, CustomRulesDeclarationTree, DataType, FormRuleDeclaration, InferRegleRule, InferRegleStatusType, InlineRuleDeclaration, InternalRuleType, ParamDecl, PossibleRegleErrors,
|
|
296
|
+
export { $InternalFormPropertyTypes, $InternalRegleCollectionRuleDecl, $InternalRegleCollectionStatus, $InternalRegleFieldStatus, $InternalReglePartialValidationTree, $InternalRegleRuleDecl, $InternalRegleRuleStatus, $InternalRegleStatus, $InternalRegleStatusType, AllRulesDeclarations, CustomRulesDeclarationTree, DataType, FormRuleDeclaration, InferRegleRule, InferRegleStatusType, InlineRuleDeclaration, InternalRuleType, ParamDecl, PossibleRegleErrors, RegleCollectionErrors, RegleCollectionRuleDecl, RegleCollectionRuleDefinition, RegleCollectionStatus, RegleCommonStatus, RegleErrorTree, RegleFieldStatus, RegleFormPropertyType, RegleInternalRuleDefs, ReglePartialValidationTree, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionProcessor, RegleRuleInit, RegleRuleRaw, RegleRuleStatus, RegleRuleWithParamsDefinition, RegleStatus, RegleUniversalParams, RegleValidationErrors, UnwrapRegleUniversalParams, createRule, defineCustomValidators };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ type Maybe<T> = T | null | undefined;
|
|
|
9
9
|
* @argument
|
|
10
10
|
* createRule arguments options
|
|
11
11
|
*/
|
|
12
|
-
interface RegleRuleInit<TValue extends any, TParams extends any[] = []> {
|
|
12
|
+
interface RegleRuleInit<TValue extends any, TParams extends any[] = [], TType extends string = string> {
|
|
13
13
|
validator: (value: Maybe<TValue>, ...args: TParams) => boolean | Promise<boolean>;
|
|
14
14
|
message: string | ((value: Maybe<TValue>, ...args: TParams) => string);
|
|
15
15
|
active?: boolean | ((value: Maybe<TValue>, ...args: TParams) => boolean);
|
|
16
|
-
type:
|
|
16
|
+
type: TType;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type DefaultValidators = {
|
|
@@ -92,26 +92,62 @@ type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends AllRules
|
|
|
92
92
|
type CustomRulesDeclarationTree = Record<string, RegleRuleRaw<any, any>>;
|
|
93
93
|
type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidators;
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
95
98
|
type ReglePartialValidationTree<TForm extends Record<string, any>, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = {
|
|
96
99
|
[TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules>;
|
|
97
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
* @reference {@link ReglePartialValidationTree}
|
|
104
|
+
*/
|
|
105
|
+
type $InternalReglePartialValidationTree = {
|
|
106
|
+
[x: string]: $InternalFormPropertyTypes;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
98
111
|
type RegleFormPropertyType<TValue = any, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = [NonNullable<TValue>] extends [never] ? RegleRuleDecl<unknown, TCustomRules> : NonNullable<TValue> extends Array<any> ? RegleCollectionRuleDecl<TValue, TCustomRules> : NonNullable<TValue> extends Date ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends File ? RegleRuleDecl<NonNullable<TValue>, TCustomRules> : NonNullable<TValue> extends Record<string, any> ? ReglePartialValidationTree<NonNullable<TValue>, TCustomRules> : RegleRuleDecl<NonNullable<TValue>, TCustomRules>;
|
|
99
112
|
/**
|
|
113
|
+
* @internal
|
|
114
|
+
* @reference {@link RegleFormPropertyType}
|
|
115
|
+
*/
|
|
116
|
+
type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollectionRuleDecl | $InternalReglePartialValidationTree;
|
|
117
|
+
/**
|
|
118
|
+
* @public
|
|
100
119
|
* Rule tree for a form property
|
|
101
120
|
*/
|
|
102
121
|
type RegleRuleDecl<TValue extends any = any, TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = {
|
|
103
122
|
[TKey in keyof TCustomRules]?: TCustomRules[TKey] extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, TParams> : FormRuleDeclaration<TValue, any>;
|
|
104
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* @internal
|
|
126
|
+
* @reference {@link RegleRuleDecl}
|
|
127
|
+
*/
|
|
128
|
+
type $InternalRegleRuleDecl = Record<string, FormRuleDeclaration<any, any>>;
|
|
129
|
+
/**
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
105
132
|
type RegleCollectionRuleDecl<TValue = any[], TCustomRules extends AllRulesDeclarations = AllRulesDeclarations> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
106
133
|
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
|
|
107
134
|
}) | {
|
|
108
135
|
$each?: RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>;
|
|
109
136
|
};
|
|
110
137
|
/**
|
|
111
|
-
*
|
|
138
|
+
* @internal
|
|
139
|
+
* @reference {@link RegleCollectionRuleDecl}
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
|
|
143
|
+
$each?: $InternalFormPropertyTypes;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* @public
|
|
112
147
|
*/
|
|
113
|
-
type InlineRuleDeclaration<TValue extends any> = (value: Maybe<TValue>, ...args: any[]) => boolean | Promise<boolean>;
|
|
148
|
+
type InlineRuleDeclaration<TValue extends any = any> = (value: Maybe<TValue>, ...args: any[]) => boolean | Promise<boolean>;
|
|
114
149
|
/**
|
|
150
|
+
* @public
|
|
115
151
|
* Regroup inline and registered rules
|
|
116
152
|
* */
|
|
117
153
|
type FormRuleDeclaration<TValue extends any, TParams extends any[] = []> = InlineRuleDeclaration<TValue> | RegleRuleDefinition<TValue, TParams>;
|
|
@@ -119,7 +155,7 @@ type FormRuleDeclaration<TValue extends any, TParams extends any[] = []> = Inlin
|
|
|
119
155
|
type RegleErrorTree<TRules extends ReglePartialValidationTree<any, any>> = {
|
|
120
156
|
readonly [K in keyof TRules]: RegleValidationErrors<TRules[K]>;
|
|
121
157
|
};
|
|
122
|
-
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends
|
|
158
|
+
type RegleValidationErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleCollectionRuleDefinition ? RegleCollectionErrors<TRule['$each']> : TRule extends ReglePartialValidationTree<any, any> ? RegleErrorTree<TRule> : TRule extends RegleRuleDecl<any, any> ? string[] : string[];
|
|
123
159
|
type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undefined = never> = {
|
|
124
160
|
readonly $errors: string[];
|
|
125
161
|
readonly $each: RegleValidationErrors<TRule>[];
|
|
@@ -127,54 +163,118 @@ type RegleCollectionErrors<TRule extends RegleFormPropertyType<any, any> | undef
|
|
|
127
163
|
type PossibleRegleErrors = RegleCollectionErrors<any> | string[] | RegleErrorTree<any>;
|
|
128
164
|
type DataType = string | number | Record<string, any> | File | Array<any> | Date | null | undefined;
|
|
129
165
|
|
|
130
|
-
|
|
166
|
+
/**
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
interface RegleStatus<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialValidationTree<TState> = Record<string, any>> extends RegleCommonStatus {
|
|
131
170
|
readonly $fields: {
|
|
132
171
|
readonly [TKey in keyof TRules]: InferRegleStatusType<NonNullable<TRules[TKey]>, TState, TKey>;
|
|
133
172
|
};
|
|
134
173
|
}
|
|
135
|
-
|
|
136
|
-
|
|
174
|
+
/**
|
|
175
|
+
* @internal
|
|
176
|
+
* @reference {@link RegleStatus}
|
|
177
|
+
*/
|
|
178
|
+
interface $InternalRegleStatus extends RegleCommonStatus {
|
|
179
|
+
$fields: {
|
|
180
|
+
[x: string]: $InternalRegleStatusType;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialValidationTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> = TRule extends RegleCollectionRuleDefinition<any, any> ? RegleCollectionStatus<TRule['$each'], TState[TKey]> : TRule extends ReglePartialValidationTree<any> ? TState[TKey] extends Array<any> ? RegleCommonStatus : RegleStatus<TState[TKey], TRule> : RegleFieldStatus<TRule, TState, TKey>;
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
* @reference {@link InferRegleStatusType}
|
|
190
|
+
*/
|
|
191
|
+
type $InternalRegleStatusType = $InternalRegleCollectionStatus | RegleCommonStatus | $InternalRegleStatus | $InternalRegleFieldStatus;
|
|
192
|
+
/**
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
interface RegleFieldStatus<TRules extends RegleFormPropertyType<any, AllRulesDeclarations> = Record<string, any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string> extends RegleCommonStatus {
|
|
196
|
+
$value: TState[TKey];
|
|
137
197
|
readonly $rules: {
|
|
138
198
|
readonly [TRuleKey in keyof TRules]: RegleRuleStatus<TState[TKey], TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams> ? TParams : []>;
|
|
139
199
|
};
|
|
140
200
|
}
|
|
141
|
-
|
|
201
|
+
/**
|
|
202
|
+
* @internal
|
|
203
|
+
* @reference {@link RegleFieldStatus}
|
|
204
|
+
*/
|
|
205
|
+
interface $InternalRegleFieldStatus extends RegleCommonStatus {
|
|
206
|
+
$value: any;
|
|
207
|
+
$rules: Record<string, $InternalRegleRuleStatus>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
interface RegleCommonStatus {
|
|
142
213
|
readonly $valid: boolean;
|
|
143
214
|
readonly $invalid: boolean;
|
|
144
215
|
readonly $dirty: boolean;
|
|
145
216
|
readonly $anyDirty: boolean;
|
|
146
217
|
readonly $pending: boolean;
|
|
147
|
-
$value: TValue;
|
|
148
218
|
readonly $error: boolean;
|
|
149
|
-
$touch
|
|
150
|
-
$reset
|
|
219
|
+
$touch(): void;
|
|
220
|
+
$reset(): void;
|
|
221
|
+
$validate(): Promise<boolean>;
|
|
222
|
+
$unwatch(): void;
|
|
223
|
+
$watch(): void;
|
|
151
224
|
}
|
|
152
|
-
|
|
225
|
+
/**
|
|
226
|
+
* @public
|
|
227
|
+
*/
|
|
228
|
+
type RegleRuleStatus<TValue = any, TParams extends any[] = any[]> = {
|
|
153
229
|
readonly $type: string;
|
|
154
230
|
readonly $message: string;
|
|
155
|
-
readonly $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
156
231
|
readonly $active: boolean;
|
|
157
232
|
readonly $valid: boolean;
|
|
158
233
|
readonly $pending: boolean;
|
|
159
|
-
readonly $
|
|
160
|
-
|
|
161
|
-
|
|
234
|
+
readonly $path: string;
|
|
235
|
+
$validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
236
|
+
$validate(): Promise<boolean>;
|
|
237
|
+
} & ([TParams] extends [[]] ? {} : {
|
|
238
|
+
readonly $params: TParams;
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* @internal
|
|
242
|
+
* @reference {@link RegleRuleStatus}
|
|
243
|
+
*/
|
|
244
|
+
interface $InternalRegleRuleStatus {
|
|
162
245
|
readonly $type: string;
|
|
163
246
|
readonly $message: string;
|
|
164
|
-
readonly $validator: (value: TValue, ...args: TParams) => boolean | Promise<boolean>;
|
|
165
247
|
readonly $active: boolean;
|
|
166
248
|
readonly $valid: boolean;
|
|
167
249
|
readonly $pending: boolean;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
250
|
+
readonly $path: string;
|
|
251
|
+
$validator(value: any, ...args: any[]): boolean | Promise<boolean>;
|
|
252
|
+
$validate(): Promise<boolean>;
|
|
253
|
+
$unwatch(): void;
|
|
254
|
+
$watch(): void;
|
|
255
|
+
readonly $params?: any[];
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
171
260
|
interface RegleCollectionStatus<TRules extends RegleRuleDecl | ReglePartialValidationTree<any>, TState extends any[]> extends RegleFieldStatus<TRules, TState> {
|
|
172
261
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, TState, number>>;
|
|
173
262
|
}
|
|
174
|
-
|
|
175
|
-
|
|
263
|
+
/**
|
|
264
|
+
* @internal
|
|
265
|
+
* @reference {@link RegleCollectionStatus}
|
|
266
|
+
*/
|
|
267
|
+
interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fields'> {
|
|
268
|
+
$each: Array<$InternalRegleStatusType>;
|
|
269
|
+
$rules?: Record<string, $InternalRegleRuleStatus>;
|
|
270
|
+
$unwatch(): void;
|
|
271
|
+
$watch(): void;
|
|
272
|
+
$fields?: {
|
|
273
|
+
[x: string]: $InternalRegleStatusType;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
176
276
|
|
|
177
|
-
declare function createRule<TValue extends any, TParams extends any[] = []>(definition: RegleRuleInit<TValue, TParams>): InferRegleRule<TValue, TParams>;
|
|
277
|
+
declare function createRule<TValue extends any, TParams extends any[] = [], TType extends string = string>(definition: RegleRuleInit<TValue, TParams, TType>): InferRegleRule<TValue, TParams>;
|
|
178
278
|
|
|
179
279
|
/**
|
|
180
280
|
* Root function that allows you to define project-wise all your custom validators or overwrite default ones
|
|
@@ -186,9 +286,11 @@ declare function createRule<TValue extends any, TParams extends any[] = []>(defi
|
|
|
186
286
|
declare function defineCustomValidators<TCustomRules extends Partial<AllRulesDeclarations>>(customRules: () => TCustomRules): {
|
|
187
287
|
useRegle: <TState extends Record<string, any>, TRules extends ReglePartialValidationTree<TState, CustomRulesDeclarationTree & DefaultValidators & TCustomRules>>(state: vue.Ref<TState>, rulesFactory: vue.ComputedRef<TRules> | (() => TRules)) => {
|
|
188
288
|
state: vue.Ref<TState>;
|
|
189
|
-
$regle:
|
|
289
|
+
$regle: RegleStatus<TState, TRules>;
|
|
190
290
|
errors: RegleErrorTree<TRules>;
|
|
291
|
+
resetForm: () => void;
|
|
292
|
+
validateForm: () => Promise<boolean>;
|
|
191
293
|
};
|
|
192
294
|
};
|
|
193
295
|
|
|
194
|
-
export { AllRulesDeclarations, CustomRulesDeclarationTree, DataType, FormRuleDeclaration, InferRegleRule, InferRegleStatusType, InlineRuleDeclaration, InternalRuleType, ParamDecl, PossibleRegleErrors,
|
|
296
|
+
export { $InternalFormPropertyTypes, $InternalRegleCollectionRuleDecl, $InternalRegleCollectionStatus, $InternalRegleFieldStatus, $InternalReglePartialValidationTree, $InternalRegleRuleDecl, $InternalRegleRuleStatus, $InternalRegleStatus, $InternalRegleStatusType, AllRulesDeclarations, CustomRulesDeclarationTree, DataType, FormRuleDeclaration, InferRegleRule, InferRegleStatusType, InlineRuleDeclaration, InternalRuleType, ParamDecl, PossibleRegleErrors, RegleCollectionErrors, RegleCollectionRuleDecl, RegleCollectionRuleDefinition, RegleCollectionStatus, RegleCommonStatus, RegleErrorTree, RegleFieldStatus, RegleFormPropertyType, RegleInternalRuleDefs, ReglePartialValidationTree, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionProcessor, RegleRuleInit, RegleRuleRaw, RegleRuleStatus, RegleRuleWithParamsDefinition, RegleStatus, RegleUniversalParams, RegleValidationErrors, UnwrapRegleUniversalParams, createRule, defineCustomValidators };
|