-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
86 lines (67 loc) · 1.79 KB
/
index.d.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
AnySchema
} from 'yup';
import {
Schema
} from './schema.d.js';
export type DateFormat = 'yyyy-mm-dd';
// What's returned from `yup` type constructors:
// * `number()`
// * `string().when()`
// * `lazy()`
// * etc
type YupType = AnySchema;
interface TypeConstructorParameters {
schemaEntry: PropertyDescriptor<Schema>;
}
// Simply adds `.required()` or `.nullable()`.
type FromYupType = (yupType: YupType) => YupType;
type TypeConstructor = (fromYupType: FromYupType, parameters: TypeConstructorParameters) => YupType;
export type TypeDefinition = YupType | TypeConstructor;
export type Types = Record<string, TypeDefinition>;
export function useCustomTypes(types: Types): void;
export interface SchemaError {
message: string;
path: string;
}
export type ValidationErrorType =
'required' |
'unknown' |
'ambiguous' |
'unsupported';
export interface SchemaValidationError {
message: string;
errors?: string[];
type?: ValidationErrorType;
path?: string;
value: any;
}
interface CreateValidationErrorArgs {
message: string;
errors: string[];
type?: ValidationErrorType;
path?: string;
value: any;
}
export type CreateValidationError = (CreateValidationErrorArgs) => SchemaValidationError;
type Schemas = {
[name: string]: Schema;
}
export interface SchemaValidationOptions {
schemas: Schemas;
allowEmptyStrings?: boolean;
allowEmptyArrays?: boolean;
returnAllErrors?: boolean;
convertDates?: boolean;
dateStrings?: boolean;
dateFormat?: DateFormat;
customTypes?: Types;
createValidationError?: CreateValidationError;
// context?: object;
}
export type ValidationFunction = (data: object) => object;
declare function schemaValidation(
schema: Schema,
options?: SchemaValidationOptions
): ValidationFunction;
export default schemaValidation;