@palmares/schemas 0.0.1 → 0.1.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/.turbo/turbo-build$colon$watch.log +12 -410
- package/CHANGELOG.md +17 -0
- package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
- package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
- package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
- package/__tests__/.drizzle/schema.ts +35 -0
- package/__tests__/drizzle.config.ts +11 -0
- package/__tests__/eslint.config.js +10 -0
- package/__tests__/manage.ts +5 -0
- package/__tests__/node_modules/.bin/drizzle-kit +17 -0
- package/__tests__/node_modules/.bin/esbuild +14 -0
- package/__tests__/node_modules/.bin/tsc +17 -0
- package/__tests__/node_modules/.bin/tsserver +17 -0
- package/__tests__/node_modules/.bin/tsx +17 -0
- package/__tests__/package.json +36 -0
- package/__tests__/sqlite.db +0 -0
- package/__tests__/src/core/array.test.ts +130 -0
- package/__tests__/src/core/boolean.test.ts +66 -0
- package/__tests__/src/core/datetime.test.ts +102 -0
- package/__tests__/src/core/index.ts +35 -0
- package/__tests__/src/core/model.test.ts +260 -0
- package/__tests__/src/core/models.ts +50 -0
- package/__tests__/src/core/numbers.test.ts +177 -0
- package/__tests__/src/core/object.test.ts +198 -0
- package/__tests__/src/core/string.test.ts +222 -0
- package/__tests__/src/core/test.test.ts +59 -0
- package/__tests__/src/core/types.test.ts +97 -0
- package/__tests__/src/core/union.test.ts +99 -0
- package/__tests__/src/settings.ts +71 -0
- package/__tests__/tsconfig.json +11 -0
- package/dist/cjs/src/adapter/fields/index.js +2 -2
- package/dist/cjs/src/adapter/fields/object.js +9 -0
- package/dist/cjs/src/adapter/index.js +1 -0
- package/dist/cjs/src/constants.js +1 -7
- package/dist/cjs/src/domain.js +146 -1
- package/dist/cjs/src/index.js +69 -74
- package/dist/cjs/src/model.js +206 -206
- package/dist/cjs/src/schema/array.js +185 -58
- package/dist/cjs/src/schema/boolean.js +105 -44
- package/dist/cjs/src/schema/datetime.js +104 -38
- package/dist/cjs/src/schema/number.js +134 -114
- package/dist/cjs/src/schema/object.js +106 -43
- package/dist/cjs/src/schema/schema.js +123 -75
- package/dist/cjs/src/schema/string.js +152 -58
- package/dist/cjs/src/schema/union.js +412 -290
- package/dist/cjs/src/utils.js +42 -15
- package/dist/cjs/src/validators/array.js +6 -1
- package/dist/cjs/src/validators/boolean.js +2 -0
- package/dist/cjs/src/validators/datetime.js +4 -0
- package/dist/cjs/src/validators/number.js +12 -40
- package/dist/cjs/src/validators/object.js +1 -0
- package/dist/cjs/src/validators/schema.js +5 -1
- package/dist/cjs/src/validators/string.js +30 -2
- package/dist/cjs/src/validators/union.js +5 -4
- package/dist/cjs/src/validators/utils.js +99 -27
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
- package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
- package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
- package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
- package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
- package/dist/cjs/types/adapter/index.d.ts +1 -0
- package/dist/cjs/types/adapter/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/types.d.ts +28 -18
- package/dist/cjs/types/adapter/types.d.ts.map +1 -1
- package/dist/cjs/types/constants.d.ts +0 -1
- package/dist/cjs/types/constants.d.ts.map +1 -1
- package/dist/cjs/types/domain.d.ts +5 -4
- package/dist/cjs/types/domain.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +78 -55
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/model.d.ts +17 -17
- package/dist/cjs/types/model.d.ts.map +1 -1
- package/dist/cjs/types/schema/array.d.ts +168 -47
- package/dist/cjs/types/schema/array.d.ts.map +1 -1
- package/dist/cjs/types/schema/boolean.d.ts +103 -44
- package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
- package/dist/cjs/types/schema/datetime.d.ts +90 -30
- package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
- package/dist/cjs/types/schema/number.d.ts +133 -125
- package/dist/cjs/types/schema/number.d.ts.map +1 -1
- package/dist/cjs/types/schema/object.d.ts +104 -35
- package/dist/cjs/types/schema/object.d.ts.map +1 -1
- package/dist/cjs/types/schema/schema.d.ts +62 -44
- package/dist/cjs/types/schema/schema.d.ts.map +1 -1
- package/dist/cjs/types/schema/string.d.ts +152 -65
- package/dist/cjs/types/schema/string.d.ts.map +1 -1
- package/dist/cjs/types/schema/types.d.ts +11 -2
- package/dist/cjs/types/schema/types.d.ts.map +1 -1
- package/dist/cjs/types/schema/union.d.ts +133 -40
- package/dist/cjs/types/schema/union.d.ts.map +1 -1
- package/dist/cjs/types/types.d.ts +35 -0
- package/dist/cjs/types/types.d.ts.map +1 -1
- package/dist/cjs/types/utils.d.ts +41 -27
- package/dist/cjs/types/utils.d.ts.map +1 -1
- package/dist/cjs/types/validators/array.d.ts.map +1 -1
- package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
- package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
- package/dist/cjs/types/validators/number.d.ts +5 -6
- package/dist/cjs/types/validators/number.d.ts.map +1 -1
- package/dist/cjs/types/validators/object.d.ts.map +1 -1
- package/dist/cjs/types/validators/schema.d.ts +2 -2
- package/dist/cjs/types/validators/schema.d.ts.map +1 -1
- package/dist/cjs/types/validators/string.d.ts +9 -9
- package/dist/cjs/types/validators/string.d.ts.map +1 -1
- package/dist/cjs/types/validators/utils.d.ts +44 -27
- package/dist/cjs/types/validators/utils.d.ts.map +1 -1
- package/dist/esm/src/adapter/fields/index.js +2 -2
- package/dist/esm/src/adapter/fields/object.js +6 -0
- package/dist/esm/src/adapter/index.js +1 -0
- package/dist/esm/src/constants.js +1 -2
- package/dist/esm/src/domain.js +11 -1
- package/dist/esm/src/index.js +38 -73
- package/dist/esm/src/model.js +83 -78
- package/dist/esm/src/schema/array.js +136 -54
- package/dist/esm/src/schema/boolean.js +98 -44
- package/dist/esm/src/schema/datetime.js +91 -38
- package/dist/esm/src/schema/number.js +127 -110
- package/dist/esm/src/schema/object.js +98 -43
- package/dist/esm/src/schema/schema.js +102 -67
- package/dist/esm/src/schema/string.js +147 -59
- package/dist/esm/src/schema/union.js +119 -40
- package/dist/esm/src/types.js +14 -1
- package/dist/esm/src/utils.js +56 -27
- package/dist/esm/src/validators/array.js +6 -1
- package/dist/esm/src/validators/boolean.js +2 -0
- package/dist/esm/src/validators/datetime.js +4 -0
- package/dist/esm/src/validators/number.js +9 -23
- package/dist/esm/src/validators/object.js +1 -0
- package/dist/esm/src/validators/schema.js +5 -1
- package/dist/esm/src/validators/string.js +30 -2
- package/dist/esm/src/validators/union.js +5 -4
- package/dist/esm/src/validators/utils.js +62 -36
- package/package.json +3 -3
- package/src/adapter/fields/array.ts +2 -2
- package/src/adapter/fields/boolean.ts +3 -8
- package/src/adapter/fields/datetime.ts +3 -9
- package/src/adapter/fields/index.ts +11 -11
- package/src/adapter/fields/number.ts +3 -9
- package/src/adapter/fields/object.ts +13 -10
- package/src/adapter/fields/string.ts +3 -9
- package/src/adapter/fields/union.ts +3 -9
- package/src/adapter/index.ts +1 -0
- package/src/adapter/types.ts +60 -45
- package/src/constants.ts +1 -3
- package/src/domain.ts +15 -1
- package/src/index.ts +189 -211
- package/src/model.ts +119 -115
- package/src/schema/array.ts +274 -90
- package/src/schema/boolean.ts +145 -60
- package/src/schema/datetime.ts +133 -49
- package/src/schema/number.ts +210 -173
- package/src/schema/object.ts +167 -74
- package/src/schema/schema.ts +205 -126
- package/src/schema/string.ts +221 -94
- package/src/schema/types.ts +44 -16
- package/src/schema/union.ts +193 -68
- package/src/types.ts +53 -0
- package/src/utils.ts +115 -57
- package/src/validators/array.ts +46 -27
- package/src/validators/boolean.ts +13 -7
- package/src/validators/datetime.ts +24 -16
- package/src/validators/number.ts +53 -63
- package/src/validators/object.ts +6 -5
- package/src/validators/schema.ts +33 -25
- package/src/validators/string.ts +122 -59
- package/src/validators/union.ts +8 -8
- package/src/validators/utils.ts +67 -42
package/src/validators/number.ts
CHANGED
@@ -4,9 +4,14 @@ import type { ValidationFallbackReturnType } from '../schema/types';
|
|
4
4
|
|
5
5
|
export function numberValidation(): ValidationFallbackReturnType {
|
6
6
|
return {
|
7
|
+
name: 'number',
|
7
8
|
type: 'medium',
|
8
9
|
// eslint-disable-next-line ts/require-await
|
9
|
-
callback: async (
|
10
|
+
callback: async (
|
11
|
+
value: any,
|
12
|
+
path: (string | number)[],
|
13
|
+
_options: Parameters<Schema['__transformToAdapter']>[0]
|
14
|
+
) => {
|
10
15
|
return {
|
11
16
|
parsed: value,
|
12
17
|
errors: [
|
@@ -15,19 +20,24 @@ export function numberValidation(): ValidationFallbackReturnType {
|
|
15
20
|
code: 'number',
|
16
21
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
17
22
|
path: path || [],
|
18
|
-
message: 'The value must be a number. Received: ' + typeof value
|
19
|
-
}
|
20
|
-
]
|
23
|
+
message: 'The value must be a number. Received: ' + typeof value
|
24
|
+
}
|
25
|
+
]
|
21
26
|
};
|
22
|
-
}
|
27
|
+
}
|
23
28
|
};
|
24
29
|
}
|
25
30
|
|
26
|
-
export function max(args: NumberSchema['__max']): ValidationFallbackReturnType {
|
31
|
+
export function max(args: NonNullable<NumberSchema['__max']>): ValidationFallbackReturnType {
|
27
32
|
return {
|
33
|
+
name: 'max',
|
28
34
|
type: 'low',
|
29
35
|
// eslint-disable-next-line ts/require-await
|
30
|
-
callback: async (
|
36
|
+
callback: async (
|
37
|
+
value: any,
|
38
|
+
path: (string | number)[],
|
39
|
+
_options: Parameters<Schema['__transformToAdapter']>[0]
|
40
|
+
) => {
|
31
41
|
if (args.inclusive)
|
32
42
|
return {
|
33
43
|
parsed: value,
|
@@ -37,9 +47,9 @@ export function max(args: NumberSchema['__max']): ValidationFallbackReturnType {
|
|
37
47
|
code: 'max',
|
38
48
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
39
49
|
path: path || [],
|
40
|
-
message: args.message
|
41
|
-
}
|
42
|
-
]
|
50
|
+
message: args.message
|
51
|
+
}
|
52
|
+
]
|
43
53
|
};
|
44
54
|
|
45
55
|
return {
|
@@ -50,16 +60,17 @@ export function max(args: NumberSchema['__max']): ValidationFallbackReturnType {
|
|
50
60
|
code: 'max',
|
51
61
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
52
62
|
path: path || [],
|
53
|
-
message: args.message
|
54
|
-
}
|
55
|
-
]
|
63
|
+
message: args.message
|
64
|
+
}
|
65
|
+
]
|
56
66
|
};
|
57
|
-
}
|
67
|
+
}
|
58
68
|
};
|
59
69
|
}
|
60
70
|
|
61
|
-
export function min(args: NumberSchema['__min']): ValidationFallbackReturnType {
|
71
|
+
export function min(args: NonNullable<NumberSchema['__min']>): ValidationFallbackReturnType {
|
62
72
|
return {
|
73
|
+
name: 'min',
|
63
74
|
type: 'low',
|
64
75
|
// eslint-disable-next-line ts/require-await
|
65
76
|
callback: async (value: any, path?: (string | number)[]) => {
|
@@ -71,9 +82,9 @@ export function min(args: NumberSchema['__min']): ValidationFallbackReturnType {
|
|
71
82
|
isValid: value >= args.value,
|
72
83
|
message: args.message,
|
73
84
|
code: 'min',
|
74
|
-
path: path || []
|
75
|
-
}
|
76
|
-
]
|
85
|
+
path: path || []
|
86
|
+
}
|
87
|
+
]
|
77
88
|
};
|
78
89
|
|
79
90
|
return {
|
@@ -83,44 +94,21 @@ export function min(args: NumberSchema['__min']): ValidationFallbackReturnType {
|
|
83
94
|
isValid: value > args.value,
|
84
95
|
message: args.message,
|
85
96
|
code: 'min',
|
86
|
-
path: path || []
|
87
|
-
}
|
88
|
-
]
|
89
|
-
};
|
90
|
-
},
|
91
|
-
};
|
92
|
-
}
|
93
|
-
|
94
|
-
export function negative(args: NumberSchema['__allowNegative']): ValidationFallbackReturnType {
|
95
|
-
return {
|
96
|
-
type: 'low',
|
97
|
-
// eslint-disable-next-line ts/require-await
|
98
|
-
callback: async (value: any, path?: (string | number)[]) => {
|
99
|
-
const isValid = args.allowZero ? value < 0 : value <= 0;
|
100
|
-
|
101
|
-
return {
|
102
|
-
parsed: value,
|
103
|
-
errors: isValid
|
104
|
-
? []
|
105
|
-
: [
|
106
|
-
{
|
107
|
-
isValid: isValid,
|
108
|
-
message: args.message,
|
109
|
-
code: 'negative',
|
110
|
-
path: path || [],
|
111
|
-
},
|
112
|
-
],
|
97
|
+
path: path || []
|
98
|
+
}
|
99
|
+
]
|
113
100
|
};
|
114
|
-
}
|
101
|
+
}
|
115
102
|
};
|
116
103
|
}
|
117
104
|
|
118
|
-
export function
|
105
|
+
export function integer(args: NonNullable<NumberSchema['__integer']>): ValidationFallbackReturnType {
|
119
106
|
return {
|
107
|
+
name: 'integer',
|
120
108
|
type: 'low',
|
121
109
|
// eslint-disable-next-line ts/require-await
|
122
110
|
callback: async (value: any, path?: (string | number)[]) => {
|
123
|
-
const isValid =
|
111
|
+
const isValid = Number.isInteger(value);
|
124
112
|
|
125
113
|
return {
|
126
114
|
parsed: value,
|
@@ -130,17 +118,18 @@ export function positive(args: NumberSchema['__allowPositive']): ValidationFallb
|
|
130
118
|
{
|
131
119
|
isValid: isValid,
|
132
120
|
message: args.message,
|
133
|
-
code: '
|
134
|
-
path: path || []
|
135
|
-
}
|
136
|
-
]
|
121
|
+
code: 'integer',
|
122
|
+
path: path || []
|
123
|
+
}
|
124
|
+
]
|
137
125
|
};
|
138
|
-
}
|
126
|
+
}
|
139
127
|
};
|
140
128
|
}
|
141
129
|
|
142
|
-
export function maxDigits(args: NumberSchema['__maxDigits']): ValidationFallbackReturnType {
|
130
|
+
export function maxDigits(args: NonNullable<NumberSchema['__maxDigits']>): ValidationFallbackReturnType {
|
143
131
|
return {
|
132
|
+
name: 'maxDigits',
|
144
133
|
type: 'low',
|
145
134
|
// eslint-disable-next-line ts/require-await
|
146
135
|
callback: async (value: any, path?: (string | number)[]) => {
|
@@ -155,16 +144,17 @@ export function maxDigits(args: NumberSchema['__maxDigits']): ValidationFallback
|
|
155
144
|
isValid: isValid,
|
156
145
|
message: args.message,
|
157
146
|
code: 'maxDigits',
|
158
|
-
path: path || []
|
159
|
-
}
|
160
|
-
]
|
147
|
+
path: path || []
|
148
|
+
}
|
149
|
+
]
|
161
150
|
};
|
162
|
-
}
|
151
|
+
}
|
163
152
|
};
|
164
153
|
}
|
165
154
|
|
166
|
-
export function decimalPlaces(args: NumberSchema['__decimalPlaces']): ValidationFallbackReturnType {
|
155
|
+
export function decimalPlaces(args: NonNullable<NumberSchema['__decimalPlaces']>): ValidationFallbackReturnType {
|
167
156
|
return {
|
157
|
+
name: 'decimalPlaces',
|
168
158
|
type: 'low',
|
169
159
|
// eslint-disable-next-line ts/require-await
|
170
160
|
callback: async (value: any, path?: (string | number)[]) => {
|
@@ -179,10 +169,10 @@ export function decimalPlaces(args: NumberSchema['__decimalPlaces']): Validation
|
|
179
169
|
isValid: isValid,
|
180
170
|
message: args.message,
|
181
171
|
code: 'decimalPlaces',
|
182
|
-
path: path || []
|
183
|
-
}
|
184
|
-
]
|
172
|
+
path: path || []
|
173
|
+
}
|
174
|
+
]
|
185
175
|
};
|
186
|
-
}
|
176
|
+
}
|
187
177
|
};
|
188
178
|
}
|
package/src/validators/object.ts
CHANGED
@@ -3,6 +3,7 @@ import type { ValidationFallbackCallbackReturnType, ValidationFallbackReturnType
|
|
3
3
|
|
4
4
|
export function objectValidation(keysToFallback: { [key: string]: Schema }): ValidationFallbackReturnType {
|
5
5
|
return {
|
6
|
+
name: 'object',
|
6
7
|
type: 'low',
|
7
8
|
callback: async (value: any, path: (string | number)[], options: Parameters<Schema['__transformToAdapter']>[0]) => {
|
8
9
|
const isNotAnObject = typeof value !== 'object' && Array.isArray(value) === false && value !== null;
|
@@ -17,9 +18,9 @@ export function objectValidation(keysToFallback: { [key: string]: Schema }): Val
|
|
17
18
|
code: 'object',
|
18
19
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
19
20
|
path: path || [],
|
20
|
-
message: 'The value must be an object. Received: ' + typeof value
|
21
|
-
}
|
22
|
-
]
|
21
|
+
message: 'The value must be an object. Received: ' + typeof value
|
22
|
+
}
|
23
|
+
]
|
23
24
|
};
|
24
25
|
|
25
26
|
const errors: { [key: string]: ValidationFallbackCallbackReturnType['errors'] } = {};
|
@@ -48,8 +49,8 @@ export function objectValidation(keysToFallback: { [key: string]: Schema }): Val
|
|
48
49
|
|
49
50
|
return {
|
50
51
|
parsed: value,
|
51
|
-
errors: Object.values(errors).flat()
|
52
|
+
errors: Object.values(errors).flat()
|
52
53
|
};
|
53
|
-
}
|
54
|
+
}
|
54
55
|
};
|
55
56
|
}
|
package/src/validators/schema.ts
CHANGED
@@ -7,6 +7,7 @@ import type { ValidationFallbackReturnType } from '../schema/types';
|
|
7
7
|
|
8
8
|
export function optional(args: Schema['__optional']): ValidationFallbackReturnType {
|
9
9
|
return {
|
10
|
+
name: 'optional',
|
10
11
|
type: 'high',
|
11
12
|
// eslint-disable-next-line ts/require-await
|
12
13
|
callback: async (value: any, path: (string | number)[]) => {
|
@@ -15,7 +16,7 @@ export function optional(args: Schema['__optional']): ValidationFallbackReturnTy
|
|
15
16
|
return {
|
16
17
|
parsed: value,
|
17
18
|
errors: [],
|
18
|
-
preventChildValidation: true
|
19
|
+
preventChildValidation: true
|
19
20
|
};
|
20
21
|
return {
|
21
22
|
parsed: value,
|
@@ -25,24 +26,25 @@ export function optional(args: Schema['__optional']): ValidationFallbackReturnTy
|
|
25
26
|
message: args.message,
|
26
27
|
code: 'required' as ErrorCodes,
|
27
28
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
28
|
-
path: path || []
|
29
|
-
}
|
29
|
+
path: path || []
|
30
|
+
}
|
30
31
|
],
|
31
|
-
preventChildValidation: true
|
32
|
+
preventChildValidation: true
|
32
33
|
};
|
33
34
|
}
|
34
35
|
|
35
36
|
return {
|
36
37
|
parsed: value,
|
37
38
|
errors: [],
|
38
|
-
preventChildValidation: false
|
39
|
+
preventChildValidation: false
|
39
40
|
};
|
40
|
-
}
|
41
|
+
}
|
41
42
|
};
|
42
43
|
}
|
43
44
|
|
44
45
|
export function nullable(args: Schema['__nullable']): ValidationFallbackReturnType {
|
45
46
|
return {
|
47
|
+
name: 'nullable',
|
46
48
|
type: 'high',
|
47
49
|
// eslint-disable-next-line ts/require-await
|
48
50
|
callback: async (value: any, path: (string | number)[]) => {
|
@@ -51,7 +53,7 @@ export function nullable(args: Schema['__nullable']): ValidationFallbackReturnTy
|
|
51
53
|
return {
|
52
54
|
parsed: value,
|
53
55
|
errors: [],
|
54
|
-
preventChildValidation: true
|
56
|
+
preventChildValidation: true
|
55
57
|
};
|
56
58
|
return {
|
57
59
|
parsed: value,
|
@@ -59,26 +61,27 @@ export function nullable(args: Schema['__nullable']): ValidationFallbackReturnTy
|
|
59
61
|
{
|
60
62
|
isValid: false,
|
61
63
|
message: args.message,
|
62
|
-
code: '
|
64
|
+
code: 'null',
|
63
65
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
64
|
-
path: path || []
|
65
|
-
}
|
66
|
+
path: path || []
|
67
|
+
}
|
66
68
|
],
|
67
|
-
preventChildValidation: true
|
69
|
+
preventChildValidation: true
|
68
70
|
};
|
69
71
|
}
|
70
72
|
|
71
73
|
return {
|
72
74
|
parsed: value,
|
73
75
|
errors: [],
|
74
|
-
preventChildValidation: false
|
76
|
+
preventChildValidation: false
|
75
77
|
};
|
76
|
-
}
|
78
|
+
}
|
77
79
|
};
|
78
80
|
}
|
79
81
|
|
80
|
-
export function checkType(args: Schema['__type']): ValidationFallbackReturnType {
|
82
|
+
export function checkType(args: NonNullable<Schema['__type']>): ValidationFallbackReturnType {
|
81
83
|
return {
|
84
|
+
name: 'checkType',
|
82
85
|
type: 'medium',
|
83
86
|
// eslint-disable-next-line ts/require-await
|
84
87
|
callback: async (value: any, path: (string | number)[]) => {
|
@@ -86,7 +89,7 @@ export function checkType(args: Schema['__type']): ValidationFallbackReturnType
|
|
86
89
|
return {
|
87
90
|
parsed: value,
|
88
91
|
errors: [],
|
89
|
-
preventChildValidation: false
|
92
|
+
preventChildValidation: false
|
90
93
|
};
|
91
94
|
|
92
95
|
return {
|
@@ -97,22 +100,27 @@ export function checkType(args: Schema['__type']): ValidationFallbackReturnType
|
|
97
100
|
message: args.message,
|
98
101
|
code: 'invalid_type' as ErrorCodes,
|
99
102
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
100
|
-
path: path || []
|
101
|
-
}
|
103
|
+
path: path || []
|
104
|
+
}
|
102
105
|
],
|
103
|
-
preventChildValidation: true
|
106
|
+
preventChildValidation: true
|
104
107
|
};
|
105
|
-
}
|
108
|
+
}
|
106
109
|
};
|
107
110
|
}
|
108
111
|
|
109
112
|
export function is(
|
110
|
-
args: BooleanSchema['__is'] | NumberSchema['__is'] | StringSchema['__is']
|
113
|
+
args: NonNullable<BooleanSchema['__is']> | NonNullable<NumberSchema['__is']> | NonNullable<StringSchema['__is']>
|
111
114
|
): ValidationFallbackReturnType {
|
112
115
|
return {
|
116
|
+
name: 'is',
|
113
117
|
type: 'medium',
|
114
118
|
// eslint-disable-next-line ts/require-await
|
115
|
-
callback: async (
|
119
|
+
callback: async (
|
120
|
+
value: any,
|
121
|
+
path: (string | number)[],
|
122
|
+
_options: Parameters<Schema['__transformToAdapter']>[0]
|
123
|
+
) => {
|
116
124
|
const isValid = Array.isArray(args.value) ? args.value.includes(value as never) : value === args.value;
|
117
125
|
return {
|
118
126
|
parsed: value,
|
@@ -124,11 +132,11 @@ export function is(
|
|
124
132
|
code: 'is',
|
125
133
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
126
134
|
path: path || [],
|
127
|
-
message: 'Value is not a boolean'
|
128
|
-
}
|
135
|
+
message: 'Value is not a boolean'
|
136
|
+
}
|
129
137
|
],
|
130
|
-
preventChildValidation: true
|
138
|
+
preventChildValidation: true
|
131
139
|
};
|
132
|
-
}
|
140
|
+
}
|
133
141
|
};
|
134
142
|
}
|