-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
55 lines (47 loc) · 1.38 KB
/
index.d.ts
File metadata and controls
55 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
ValidationOptions,
ObjectSchema,
NullableType,
ValidationErrorItem,
} from "joi"
type Type$ExplictFields<FieldTypes> = Partial<{
[key in keyof FieldTypes]: boolean
}>
type Type$DataState<FieldTypes> = {
[key in keyof FieldTypes]: {
$dirty: boolean
}
}
type Type$Errors<FieldTypes> = {
[key in keyof FieldTypes]: {
$property: keyof FieldTypes
$message: ValidationErrorItem["message"]
}[]
}
export type TypeUseValidatorConfig<FieldTypes> = {
initialData: NullableType<FieldTypes>
schema: ObjectSchema<FieldTypes>
explicitCheck?: Type$ExplictFields<FieldTypes>
validationOptions?: Pick<ValidationOptions, "abortEarly">
}
export type TypeUseValidatorState<FieldTypes> = {
$data: NullableType<FieldTypes>
$dirty: boolean
$explict_fields: Type$ExplictFields<FieldTypes>
$data_state: Type$DataState<FieldTypes>
$source_errors: Type$Errors<FieldTypes>
$errors: Type$Errors<FieldTypes>
$all_source_errors: Type$Errors<FieldTypes>
$all_errors: Type$Errors<FieldTypes>
$invalid: boolean
$auto_invalid: boolean
$validation_success: boolean
$validated: boolean
}
export interface TypeUseValidator<FieldTypes> {
state: TypeUseValidatorState<FieldTypes>
}
export const useValidator: <T>(
options: TypeUseValidatorConfig<T>
) => TypeUseValidator<T>
export default useValidator