@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/schema/datetime.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import Schema from './schema';
|
2
|
-
import { getDefaultAdapter } from '../conf';
|
3
2
|
import { defaultTransform, defaultTransformToAdapter } from '../utils';
|
4
3
|
import { above, allowStringParser, below, datetimeValidation } from '../validators/datetime';
|
5
4
|
import { nullable, optional } from '../validators/schema';
|
@@ -20,7 +19,7 @@ export default class DatetimeSchema<
|
|
20
19
|
representation: string;
|
21
20
|
validate: Date;
|
22
21
|
},
|
23
|
-
TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType
|
22
|
+
TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType
|
24
23
|
> extends Schema<TType, TDefinitions> {
|
25
24
|
protected __allowString!: boolean;
|
26
25
|
|
@@ -35,6 +34,21 @@ export default class DatetimeSchema<
|
|
35
34
|
message: string;
|
36
35
|
};
|
37
36
|
|
37
|
+
protected __type: {
|
38
|
+
message: string;
|
39
|
+
check: (value: TType['input']) => boolean;
|
40
|
+
} = {
|
41
|
+
message: 'Invalid type',
|
42
|
+
check: (value: any) => {
|
43
|
+
if (typeof value === 'string') {
|
44
|
+
const valueAsDate = new Date(value);
|
45
|
+
if (isNaN(valueAsDate.getTime())) return false;
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
return value instanceof Date;
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
38
52
|
protected async __transformToAdapter(options: Parameters<Schema['__transformToAdapter']>[0]): Promise<any> {
|
39
53
|
return defaultTransformToAdapter(
|
40
54
|
async (adapter) => {
|
@@ -49,9 +63,10 @@ export default class DatetimeSchema<
|
|
49
63
|
above: this.__above,
|
50
64
|
nullable: this.__nullable,
|
51
65
|
optional: this.__optional,
|
66
|
+
type: this.__type,
|
52
67
|
parsers: {
|
53
68
|
nullable: this.__nullable.allow,
|
54
|
-
optional: this.__optional.allow
|
69
|
+
optional: this.__optional.allow
|
55
70
|
}
|
56
71
|
}),
|
57
72
|
{
|
@@ -59,16 +74,17 @@ export default class DatetimeSchema<
|
|
59
74
|
nullable,
|
60
75
|
allowString: allowStringParser,
|
61
76
|
above,
|
62
|
-
below
|
77
|
+
below
|
63
78
|
},
|
64
79
|
{
|
65
80
|
validatorsIfFallbackOrNotSupported: datetimeValidation(),
|
66
81
|
shouldAddStringVersion: options.shouldAddStringVersion,
|
67
82
|
// eslint-disable-next-line ts/require-await
|
68
|
-
fallbackIfNotSupported: async () => []
|
83
|
+
fallbackIfNotSupported: async () => []
|
69
84
|
}
|
70
85
|
);
|
71
86
|
},
|
87
|
+
this,
|
72
88
|
this.__transformedSchemas,
|
73
89
|
options,
|
74
90
|
'datetime'
|
@@ -76,7 +92,8 @@ export default class DatetimeSchema<
|
|
76
92
|
}
|
77
93
|
|
78
94
|
/**
|
79
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something
|
95
|
+
* This let's you refine the schema with custom validations. This is useful when you want to validate something
|
96
|
+
* that is not supported by default by the schema adapter.
|
80
97
|
*
|
81
98
|
* @example
|
82
99
|
* ```typescript
|
@@ -88,7 +105,8 @@ export default class DatetimeSchema<
|
|
88
105
|
*
|
89
106
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
90
107
|
*
|
91
|
-
*
|
108
|
+
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
109
|
+
* console.log(errors);
|
92
110
|
* ```
|
93
111
|
*
|
94
112
|
* @param refinementCallback - The callback that will be called to validate the value.
|
@@ -98,7 +116,13 @@ export default class DatetimeSchema<
|
|
98
116
|
* @returns The schema.
|
99
117
|
*/
|
100
118
|
refine(
|
101
|
-
refinementCallback: (
|
119
|
+
refinementCallback: (
|
120
|
+
value: TType['input']
|
121
|
+
) =>
|
122
|
+
| Promise<void | undefined | { code: string; message: string }>
|
123
|
+
| void
|
124
|
+
| undefined
|
125
|
+
| { code: string; message: string }
|
102
126
|
) {
|
103
127
|
return super.refine(refinementCallback) as unknown as DatetimeSchema<
|
104
128
|
{
|
@@ -107,7 +131,8 @@ export default class DatetimeSchema<
|
|
107
131
|
internal: TType['internal'];
|
108
132
|
output: TType['output'];
|
109
133
|
representation: TType['representation'];
|
110
|
-
},
|
134
|
+
},
|
135
|
+
TDefinitions
|
111
136
|
>;
|
112
137
|
}
|
113
138
|
|
@@ -149,8 +174,36 @@ export default class DatetimeSchema<
|
|
149
174
|
}
|
150
175
|
|
151
176
|
/**
|
152
|
-
*
|
153
|
-
*
|
177
|
+
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
178
|
+
*
|
179
|
+
* ```typescript
|
180
|
+
* p.datetime().optional({ message: 'This value should be defined', allow: false })
|
181
|
+
* ```
|
182
|
+
*
|
183
|
+
* @param options - The options of nonOptional function
|
184
|
+
* @param options.message - A custom message if the value is undefined.
|
185
|
+
*
|
186
|
+
* @returns - The schema.
|
187
|
+
*/
|
188
|
+
nonOptional(options?: { message: string }) {
|
189
|
+
return super.optional({
|
190
|
+
message: options?.message,
|
191
|
+
allow: false
|
192
|
+
}) as unknown as DatetimeSchema<
|
193
|
+
{
|
194
|
+
input: TType['input'];
|
195
|
+
validate: TType['validate'];
|
196
|
+
internal: TType['internal'];
|
197
|
+
output: TType['output'];
|
198
|
+
representation: TType['representation'];
|
199
|
+
},
|
200
|
+
TDefinitions
|
201
|
+
>;
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
206
|
+
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
154
207
|
*
|
155
208
|
* @example
|
156
209
|
* ```typescript
|
@@ -187,14 +240,43 @@ export default class DatetimeSchema<
|
|
187
240
|
}
|
188
241
|
|
189
242
|
/**
|
190
|
-
*
|
191
|
-
*
|
243
|
+
* Just adds a message when the value is null. It's just a syntax sugar for
|
244
|
+
*
|
245
|
+
* ```typescript
|
246
|
+
* p.datetime().nullable({ message: 'This value cannot be null', allow: false })
|
247
|
+
* ```
|
248
|
+
*
|
249
|
+
* @param options - The options of nonNullable function
|
250
|
+
* @param options.message - A custom message if the value is null.
|
251
|
+
*
|
252
|
+
* @returns - The schema.
|
253
|
+
*/
|
254
|
+
nonNullable(options?: { message: string }) {
|
255
|
+
return super.nullable({
|
256
|
+
message: options?.message || '',
|
257
|
+
allow: false
|
258
|
+
}) as unknown as DatetimeSchema<
|
259
|
+
{
|
260
|
+
input: TType['input'];
|
261
|
+
validate: TType['validate'];
|
262
|
+
internal: TType['internal'];
|
263
|
+
output: TType['output'];
|
264
|
+
representation: TType['representation'];
|
265
|
+
},
|
266
|
+
TDefinitions
|
267
|
+
>;
|
268
|
+
}
|
269
|
+
|
270
|
+
/**
|
271
|
+
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
272
|
+
* that way otherwise it will set the value to undefined after it's validated.
|
192
273
|
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
193
274
|
* function. This will remove the value from the representation of the schema.
|
194
275
|
*
|
195
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
196
|
-
* But if you want to remove the value from the internal representation, you can pass the argument
|
197
|
-
* Then if you still want to remove the value from the representation, you will need to pass
|
276
|
+
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
277
|
+
* function.But if you want to remove the value from the internal representation, you can pass the argument
|
278
|
+
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
279
|
+
* the argument `toRepresentation` as true as well.
|
198
280
|
*
|
199
281
|
* @example
|
200
282
|
* ```typescript
|
@@ -216,16 +298,18 @@ export default class DatetimeSchema<
|
|
216
298
|
* ```
|
217
299
|
*
|
218
300
|
*
|
219
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
220
|
-
*
|
221
|
-
*
|
301
|
+
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
302
|
+
* the {@link data} function.
|
303
|
+
* But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as
|
304
|
+
* true. Then if you still want to remove the value from the representation, you will need to pass the argument
|
305
|
+
* `toRepresentation` as true as well.
|
222
306
|
*
|
223
307
|
* @returns The schema.
|
224
308
|
*/
|
225
309
|
omit<
|
226
310
|
TToInternal extends boolean,
|
227
311
|
TToRepresentation extends boolean = boolean extends TToInternal ? true : false
|
228
|
-
>(args?: { toInternal?: TToInternal
|
312
|
+
>(args?: { toInternal?: TToInternal; toRepresentation?: TToRepresentation }) {
|
229
313
|
return super.omit(args) as unknown as DatetimeSchema<
|
230
314
|
{
|
231
315
|
input: TToInternal extends true ? TType['input'] | undefined : TType['input'];
|
@@ -239,9 +323,9 @@ export default class DatetimeSchema<
|
|
239
323
|
}
|
240
324
|
|
241
325
|
/**
|
242
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
243
|
-
* like a database. You should always return the schema after you save the value, that way we will always have
|
244
|
-
* of the schema after the save operation.
|
326
|
+
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
327
|
+
* source like a database. You should always return the schema after you save the value, that way we will always have
|
328
|
+
* the correct type of the schema after the save operation.
|
245
329
|
*
|
246
330
|
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
247
331
|
*
|
@@ -295,9 +379,9 @@ export default class DatetimeSchema<
|
|
295
379
|
>;
|
296
380
|
}
|
297
381
|
|
298
|
-
|
299
382
|
/**
|
300
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
383
|
+
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
384
|
+
* value will be used.
|
301
385
|
*
|
302
386
|
* @example
|
303
387
|
* ```typescript
|
@@ -326,8 +410,9 @@ export default class DatetimeSchema<
|
|
326
410
|
}
|
327
411
|
|
328
412
|
/**
|
329
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
330
|
-
* the custom schema your own way. Our API does not support passthrough?
|
413
|
+
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
414
|
+
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
415
|
+
* No problem, you can use this function to customize the zod schema.
|
331
416
|
*
|
332
417
|
* @example
|
333
418
|
* ```typescript
|
@@ -339,12 +424,13 @@ export default class DatetimeSchema<
|
|
339
424
|
*
|
340
425
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
341
426
|
*
|
342
|
-
*
|
427
|
+
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
428
|
+
* console.log(errors);
|
343
429
|
* ```
|
344
430
|
*
|
345
431
|
* @param callback - The callback that will be called to customize the schema.
|
346
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
347
|
-
* to a string so you can save it for future runs.
|
432
|
+
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
433
|
+
* compile the underlying schema to a string so you can save it for future runs.
|
348
434
|
*
|
349
435
|
* @returns The schema.
|
350
436
|
*/
|
@@ -358,8 +444,9 @@ export default class DatetimeSchema<
|
|
358
444
|
}
|
359
445
|
|
360
446
|
/**
|
361
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
362
|
-
* control to add data cleaning for example, transforming the data and
|
447
|
+
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
448
|
+
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
449
|
+
* whatever. Another use case is when you want to return deeply nested recursive data.
|
363
450
|
* The schema maps to itself.
|
364
451
|
*
|
365
452
|
* @example
|
@@ -416,8 +503,9 @@ export default class DatetimeSchema<
|
|
416
503
|
}
|
417
504
|
|
418
505
|
/**
|
419
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
420
|
-
* to a type that the schema adapter can understand. For example, you might want to
|
506
|
+
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
507
|
+
* want to transform the value to a type that the schema adapter can understand. For example, you might want to
|
508
|
+
* transform a string to a date. This is the function you use.
|
421
509
|
*
|
422
510
|
* @example
|
423
511
|
* ```typescript
|
@@ -461,8 +549,9 @@ export default class DatetimeSchema<
|
|
461
549
|
}
|
462
550
|
|
463
551
|
/**
|
464
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
465
|
-
* here BEFORE the validation. This pretty much transforms the value to a type
|
552
|
+
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
553
|
+
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
|
554
|
+
* that the schema adapter can understand.
|
466
555
|
*
|
467
556
|
* @example
|
468
557
|
* ```
|
@@ -494,7 +583,8 @@ export default class DatetimeSchema<
|
|
494
583
|
}
|
495
584
|
|
496
585
|
/**
|
497
|
-
* This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
|
586
|
+
* This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
|
587
|
+
* result to be a string as well.
|
498
588
|
*
|
499
589
|
* @example
|
500
590
|
* ```typescript
|
@@ -536,7 +626,8 @@ export default class DatetimeSchema<
|
|
536
626
|
*
|
537
627
|
* @param value - The value that we are comparing against.
|
538
628
|
* @param options - The options that we are passing to the validator.
|
539
|
-
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to
|
629
|
+
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to
|
630
|
+
* the specified date.
|
540
631
|
* @param options.message - The message that we are returning if the value is not above the specified date.
|
541
632
|
*
|
542
633
|
* @returns - The schema instance
|
@@ -548,7 +639,7 @@ export default class DatetimeSchema<
|
|
548
639
|
this.__above = {
|
549
640
|
value,
|
550
641
|
inclusive,
|
551
|
-
message
|
642
|
+
message
|
552
643
|
};
|
553
644
|
return this;
|
554
645
|
}
|
@@ -569,7 +660,8 @@ export default class DatetimeSchema<
|
|
569
660
|
*
|
570
661
|
* @param value - The value that we are comparing against.
|
571
662
|
* @param options - The options that we are passing to the validator.
|
572
|
-
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the
|
663
|
+
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the
|
664
|
+
* specified date.
|
573
665
|
* @param options.message - The message that we are returning if the value is not above the specified date.
|
574
666
|
*
|
575
667
|
* @returns - The schema instance
|
@@ -581,7 +673,7 @@ export default class DatetimeSchema<
|
|
581
673
|
this.__below = {
|
582
674
|
value,
|
583
675
|
inclusive,
|
584
|
-
message
|
676
|
+
message
|
585
677
|
};
|
586
678
|
return this;
|
587
679
|
}
|
@@ -598,14 +690,6 @@ export default class DatetimeSchema<
|
|
598
690
|
TDefinitions
|
599
691
|
>();
|
600
692
|
|
601
|
-
const adapterInstance = getDefaultAdapter();
|
602
|
-
|
603
|
-
returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
|
604
|
-
transformed: false,
|
605
|
-
adapter: adapterInstance,
|
606
|
-
schemas: [],
|
607
|
-
};
|
608
|
-
|
609
693
|
return returnValue;
|
610
694
|
}
|
611
695
|
}
|