@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
@@ -12,8 +12,12 @@ export default class ArraySchema<TType extends {
|
|
12
12
|
internal: any[];
|
13
13
|
representation: any[];
|
14
14
|
validate: any[];
|
15
|
-
}, TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType, TSchemas extends readonly [Schema, ...Schema[]] | [Schema
|
16
|
-
protected __schemas: readonly [Schema, ...Schema[]] | [Schema
|
15
|
+
}, TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType, TSchemas extends readonly [Schema, ...Schema[]] | [[Schema]] = [[Schema]]> extends Schema<TType, TDefinitions> {
|
16
|
+
protected __schemas: readonly [Schema, ...Schema[]] | [[Schema]];
|
17
|
+
protected __type: {
|
18
|
+
message: string;
|
19
|
+
check: (value: TType['input']) => boolean;
|
20
|
+
};
|
17
21
|
protected __minLength: {
|
18
22
|
value: number;
|
19
23
|
inclusive: boolean;
|
@@ -30,7 +34,8 @@ export default class ArraySchema<TType extends {
|
|
30
34
|
constructor(...schemas: TSchemas);
|
31
35
|
protected __transformToAdapter(options: Parameters<Schema['__transformToAdapter']>[0]): Promise<any>;
|
32
36
|
/**
|
33
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
37
|
+
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
38
|
+
* is not supported by default by the schema adapter.
|
34
39
|
*
|
35
40
|
* @example
|
36
41
|
* ```typescript
|
@@ -42,7 +47,8 @@ export default class ArraySchema<TType extends {
|
|
42
47
|
*
|
43
48
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
44
49
|
*
|
45
|
-
*
|
50
|
+
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
51
|
+
* console.log(errors);
|
46
52
|
* ```
|
47
53
|
*
|
48
54
|
* @param refinementCallback - The callback that will be called to validate the value.
|
@@ -63,9 +69,10 @@ export default class ArraySchema<TType extends {
|
|
63
69
|
representation: TType["representation"];
|
64
70
|
}, TDefinitions, TSchemas>;
|
65
71
|
/**
|
66
|
-
* Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can
|
67
|
-
*
|
68
|
-
* This
|
72
|
+
* Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can
|
73
|
+
* pass `outputOnly` as `true` to this method.
|
74
|
+
* This will allow you to pass `null` or `undefined` as a value on the {@link Schema.data} method, but it will not
|
75
|
+
* allow the value to be `null` or `undefined`. This is useful for typing purposes.
|
69
76
|
*
|
70
77
|
* @example
|
71
78
|
* ```typescript
|
@@ -92,8 +99,10 @@ export default class ArraySchema<TType extends {
|
|
92
99
|
* company: companySchema.optional({ outputOnly: true })
|
93
100
|
* });
|
94
101
|
*
|
95
|
-
*
|
96
|
-
* const
|
102
|
+
* // Will not allow the company to be null or undefined on a typing level.
|
103
|
+
* const { errors, parsed } = await userSchema.data({ id: 1, name: 'John Doe' });
|
104
|
+
* // Will allow the company to be null or undefined on a typing level
|
105
|
+
* const value = await userSchema.data({ id: 1, name: 'John Doe' });
|
97
106
|
* ```
|
98
107
|
*
|
99
108
|
* @returns - The schema we are working with.
|
@@ -102,7 +111,7 @@ export default class ArraySchema<TType extends {
|
|
102
111
|
message?: string;
|
103
112
|
allow?: false;
|
104
113
|
outputOnly?: TOutputOnly;
|
105
|
-
}): ArraySchema<
|
114
|
+
}): ArraySchema<TOutputOnly extends true ? {
|
106
115
|
input: TType["input"];
|
107
116
|
validate: TType["validate"];
|
108
117
|
internal: TType["internal"];
|
@@ -114,10 +123,31 @@ export default class ArraySchema<TType extends {
|
|
114
123
|
internal: TType["internal"] | undefined | null;
|
115
124
|
output: TType["output"] | undefined | null;
|
116
125
|
representation: TType["representation"] | undefined | null;
|
117
|
-
}
|
126
|
+
}, TDefinitions, TSchemas>;
|
127
|
+
/**
|
128
|
+
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
129
|
+
*
|
130
|
+
* ```typescript
|
131
|
+
* p.datetime().optional({ message: 'This value should be defined', allow: false })
|
132
|
+
* ```
|
133
|
+
*
|
134
|
+
* @param options - The options of nonOptional function
|
135
|
+
* @param options.message - A custom message if the value is undefined.
|
136
|
+
*
|
137
|
+
* @returns - The schema.
|
138
|
+
*/
|
139
|
+
nonOptional(options?: {
|
140
|
+
message: string;
|
141
|
+
}): ArraySchema<{
|
142
|
+
input: TType["input"];
|
143
|
+
validate: TType["validate"];
|
144
|
+
internal: TType["internal"];
|
145
|
+
output: TType["output"];
|
146
|
+
representation: TType["representation"];
|
147
|
+
}, TDefinitions>;
|
118
148
|
/**
|
119
|
-
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
120
|
-
* the { message: 'Your custom message', allow: false } on the options.
|
149
|
+
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
150
|
+
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
121
151
|
*
|
122
152
|
* @example
|
123
153
|
* ```typescript
|
@@ -151,14 +181,36 @@ export default class ArraySchema<TType extends {
|
|
151
181
|
representation: TType["representation"] | null;
|
152
182
|
}, TDefinitions, TSchemas>;
|
153
183
|
/**
|
154
|
-
*
|
155
|
-
*
|
184
|
+
* Just adds a message when the value is null. It's just a syntax sugar for
|
185
|
+
*
|
186
|
+
* ```typescript
|
187
|
+
* p.datetime().nullable({ message: 'This value cannot be null', allow: false })
|
188
|
+
* ```
|
189
|
+
*
|
190
|
+
* @param options - The options of nonNullable function
|
191
|
+
* @param options.message - A custom message if the value is null.
|
192
|
+
*
|
193
|
+
* @returns - The schema.
|
194
|
+
*/
|
195
|
+
nonNullable(options?: {
|
196
|
+
message: string;
|
197
|
+
}): ArraySchema<{
|
198
|
+
input: TType["input"];
|
199
|
+
validate: TType["validate"];
|
200
|
+
internal: TType["internal"];
|
201
|
+
output: TType["output"];
|
202
|
+
representation: TType["representation"];
|
203
|
+
}, TDefinitions>;
|
204
|
+
/**
|
205
|
+
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
206
|
+
* that way otherwise it will set the value to undefined after it's validated.
|
156
207
|
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
157
208
|
* function. This will remove the value from the representation of the schema.
|
158
209
|
*
|
159
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
160
|
-
* But if you want to remove the value from the internal representation, you can pass the argument
|
161
|
-
* Then if you still want to remove the value from the representation, you will need to pass
|
210
|
+
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
211
|
+
* function. But if you want to remove the value from the internal representation, you can pass the argument
|
212
|
+
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
213
|
+
* the argument `toRepresentation` as true as well.
|
162
214
|
*
|
163
215
|
* @example
|
164
216
|
* ```typescript
|
@@ -180,9 +232,12 @@ export default class ArraySchema<TType extends {
|
|
180
232
|
* ```
|
181
233
|
*
|
182
234
|
*
|
183
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
184
|
-
*
|
185
|
-
*
|
235
|
+
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
236
|
+
* the {@link data} function.
|
237
|
+
* But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
|
238
|
+
* as true.
|
239
|
+
* Then if you still want to remove the value from the representation, you will need to pass the argument
|
240
|
+
* `toRepresentation` as true as well.
|
186
241
|
*
|
187
242
|
* @returns The schema.
|
188
243
|
*/
|
@@ -197,9 +252,9 @@ export default class ArraySchema<TType extends {
|
|
197
252
|
representation: TToRepresentation extends true ? undefined : TType["representation"];
|
198
253
|
}, TDefinitions, TSchemas>;
|
199
254
|
/**
|
200
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
201
|
-
* like a database. You should always return the schema after you save the value, that way we will always have
|
202
|
-
* of the schema after the save operation.
|
255
|
+
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
256
|
+
* source like a database. You should always return the schema after you save the value, that way we will always have
|
257
|
+
* the correct type of the schema after the save operation.
|
203
258
|
*
|
204
259
|
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
205
260
|
*
|
@@ -248,7 +303,8 @@ export default class ArraySchema<TType extends {
|
|
248
303
|
hasSave: true;
|
249
304
|
}, TSchemas>;
|
250
305
|
/**
|
251
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
306
|
+
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
307
|
+
* value will be used.
|
252
308
|
*
|
253
309
|
* @example
|
254
310
|
* ```typescript
|
@@ -269,8 +325,40 @@ export default class ArraySchema<TType extends {
|
|
269
325
|
representation: TType["representation"];
|
270
326
|
}, TDefinitions, TSchemas>;
|
271
327
|
/**
|
272
|
-
* This function
|
273
|
-
*
|
328
|
+
* This function is used to transform the value to the representation without validating it.
|
329
|
+
* This is useful when you want to return a data from a query directly to the user. But for example
|
330
|
+
* you are returning the data of a user, you can clean the password or any other sensitive data.
|
331
|
+
*
|
332
|
+
* @example
|
333
|
+
* ```typescript
|
334
|
+
* import * as p from '@palmares/schemas';
|
335
|
+
*
|
336
|
+
* const userSchema = p.object({
|
337
|
+
* id: p.number().optional(),
|
338
|
+
* name: p.string(),
|
339
|
+
* email: p.string().email(),
|
340
|
+
* password: p.string().optional()
|
341
|
+
* }).toRepresentation(async (value) => {
|
342
|
+
* return {
|
343
|
+
* id: value.id,
|
344
|
+
* name: value.name,
|
345
|
+
* email: value.email
|
346
|
+
* }
|
347
|
+
* });
|
348
|
+
*
|
349
|
+
* const user = await userSchema.data({
|
350
|
+
* id: 1,
|
351
|
+
* name: 'John Doe',
|
352
|
+
* email: 'john@gmail.com',
|
353
|
+
* password: '123456'
|
354
|
+
* });
|
355
|
+
* ```
|
356
|
+
*/
|
357
|
+
data(value: TType['output']): Promise<TType['representation']>;
|
358
|
+
/**
|
359
|
+
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
360
|
+
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
361
|
+
* No problem, you can use this function to customize the zod schema.
|
274
362
|
*
|
275
363
|
* @example
|
276
364
|
* ```typescript
|
@@ -282,19 +370,21 @@ export default class ArraySchema<TType extends {
|
|
282
370
|
*
|
283
371
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
284
372
|
*
|
285
|
-
*
|
373
|
+
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
374
|
+
* console.log(errors);
|
286
375
|
* ```
|
287
376
|
*
|
288
377
|
* @param callback - The callback that will be called to customize the schema.
|
289
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
290
|
-
* to a string so you can save it for future runs.
|
378
|
+
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
379
|
+
* compile the underlying schema to a string so you can save it for future runs.
|
291
380
|
*
|
292
381
|
* @returns The schema.
|
293
382
|
*/
|
294
383
|
extends(callback: (schema: Awaited<ReturnType<NonNullable<TDefinitions['schemaAdapter']['object']>['translate']>>) => Awaited<ReturnType<NonNullable<TDefinitions['schemaAdapter']['field']>['translate']>> | any, toStringCallback?: (schemaAsString: string) => string): this;
|
295
384
|
/**
|
296
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
297
|
-
* control to add data cleaning for example, transforming the data and
|
385
|
+
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
386
|
+
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
387
|
+
* whatever. Another use case is when you want to return deeply nested recursive data.
|
298
388
|
* The schema maps to itself.
|
299
389
|
*
|
300
390
|
* @example
|
@@ -343,8 +433,9 @@ export default class ArraySchema<TType extends {
|
|
343
433
|
representation: TRepresentation;
|
344
434
|
}, TDefinitions, TSchemas>;
|
345
435
|
/**
|
346
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
347
|
-
* to a type that the schema adapter can understand. For example, you might want to
|
436
|
+
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
437
|
+
* want to transform the value to a type that the schema adapter can understand. For example, you might want to
|
438
|
+
* transform a string to a date. This is the function you use.
|
348
439
|
*
|
349
440
|
* @example
|
350
441
|
* ```typescript
|
@@ -382,8 +473,9 @@ export default class ArraySchema<TType extends {
|
|
382
473
|
representation: TType["representation"];
|
383
474
|
}, TDefinitions, TSchemas>;
|
384
475
|
/**
|
385
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
386
|
-
* here BEFORE the validation. This pretty much transforms the value to a type
|
476
|
+
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
477
|
+
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
|
478
|
+
* that the schema adapter can understand.
|
387
479
|
*
|
388
480
|
* @example
|
389
481
|
* ```
|
@@ -408,22 +500,51 @@ export default class ArraySchema<TType extends {
|
|
408
500
|
output: TType["output"];
|
409
501
|
representation: TType["representation"];
|
410
502
|
}, TDefinitions, TSchemas>;
|
411
|
-
minLength(value: number,
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
internal: ExtractTypeFromArrayOfSchemas<TSchemas, "internal">;
|
418
|
-
output: ExtractTypeFromArrayOfSchemas<TSchemas, "output">;
|
419
|
-
representation: ExtractTypeFromArrayOfSchemas<TSchemas, "representation">;
|
503
|
+
minLength(value: number, options?: Omit<ArraySchema['__minLength'], 'value'>): ArraySchema<{
|
504
|
+
input: [TType["input"][number], ...TType["input"][number][]];
|
505
|
+
validate: [TType["validate"][number], ...TType["validate"][number][]];
|
506
|
+
internal: [TType["internal"][number], ...TType["internal"][number][]];
|
507
|
+
output: [TType["output"][number], ...TType["output"][number][]];
|
508
|
+
representation: [TType["representation"][number], ...TType["representation"][number][]];
|
420
509
|
}, TDefinitions, TSchemas>;
|
510
|
+
maxLength(value: number, options?: Omit<ArraySchema['__maxLength'], 'value'>): this;
|
511
|
+
static new<TSchemas extends readonly [Schema, ...Schema[]] | [[Schema]], TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType>(...schemas: TSchemas): TSchemas extends [[Schema]] ? ArraySchema<{
|
512
|
+
input: ExtractTypeFromArrayOfSchemas<TSchemas, 'input'>;
|
513
|
+
validate: ExtractTypeFromArrayOfSchemas<TSchemas, 'validate'>;
|
514
|
+
internal: ExtractTypeFromArrayOfSchemas<TSchemas, 'internal'>;
|
515
|
+
output: ExtractTypeFromArrayOfSchemas<TSchemas, 'output'>;
|
516
|
+
representation: ExtractTypeFromArrayOfSchemas<TSchemas, 'representation'>;
|
517
|
+
}, TDefinitions, TSchemas> : ArraySchema<{
|
518
|
+
input: ExtractTypeFromArrayOfSchemas<TSchemas, 'input'>;
|
519
|
+
validate: ExtractTypeFromArrayOfSchemas<TSchemas, 'validate'>;
|
520
|
+
internal: ExtractTypeFromArrayOfSchemas<TSchemas, 'internal'>;
|
521
|
+
output: ExtractTypeFromArrayOfSchemas<TSchemas, 'output'>;
|
522
|
+
representation: ExtractTypeFromArrayOfSchemas<TSchemas, 'representation'>;
|
523
|
+
}, TDefinitions, TSchemas> & {
|
524
|
+
maxLength: never;
|
525
|
+
minLength: never;
|
526
|
+
};
|
421
527
|
}
|
422
|
-
export declare const array: <TSchemas extends readonly [Schema, ...Schema[]] | [Schema
|
528
|
+
export declare const array: <TSchemas extends readonly [Schema, ...Schema[]] | [[Schema]], TDefinitions extends DefinitionsOfSchemaType>(...schemas: TSchemas) => TSchemas extends [[Schema<{
|
529
|
+
input: any;
|
530
|
+
validate: any;
|
531
|
+
internal: any;
|
532
|
+
output: any;
|
533
|
+
representation: any;
|
534
|
+
}, DefinitionsOfSchemaType>]] ? ArraySchema<{
|
535
|
+
input: ExtractTypeFromArrayOfSchemas<TSchemas, "input", []>;
|
536
|
+
validate: ExtractTypeFromArrayOfSchemas<TSchemas, "validate", []>;
|
537
|
+
internal: ExtractTypeFromArrayOfSchemas<TSchemas, "internal", []>;
|
538
|
+
output: ExtractTypeFromArrayOfSchemas<TSchemas, "output", []>;
|
539
|
+
representation: ExtractTypeFromArrayOfSchemas<TSchemas, "representation", []>;
|
540
|
+
}, TDefinitions, TSchemas> : ArraySchema<{
|
423
541
|
input: ExtractTypeFromArrayOfSchemas<TSchemas, "input", []>;
|
424
542
|
validate: ExtractTypeFromArrayOfSchemas<TSchemas, "validate", []>;
|
425
543
|
internal: ExtractTypeFromArrayOfSchemas<TSchemas, "internal", []>;
|
426
544
|
output: ExtractTypeFromArrayOfSchemas<TSchemas, "output", []>;
|
427
545
|
representation: ExtractTypeFromArrayOfSchemas<TSchemas, "representation", []>;
|
428
|
-
}, TDefinitions, TSchemas
|
546
|
+
}, TDefinitions, TSchemas> & {
|
547
|
+
maxLength: never;
|
548
|
+
minLength: never;
|
549
|
+
};
|
429
550
|
//# sourceMappingURL=array.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../../src/schema/array.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAW9B,OAAO,KAAK,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAEtF,MAAM,CAAC,OAAO,OAAO,WAAW,CAC9B,KAAK,SAAS;IACZ,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,cAAc,EAAE,GAAG,CAAC;CACrB,GAAG;IACF,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,cAAc,EAAE,GAAG,E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U,CAAC,CAAC;QAC9D,QAAQ,EAAE,6BAA6B,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC9D,MAAM,EAAE,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1D,cAAc,EAAE,6BAA6B,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;KAC3E,EACD,YAAY,EACZ,QAAQ,CACT,GACD,WAAW,CACT;QACE,KAAK,EAAE,6BAA6B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACxD,QAAQ,EAAE,6BAA6B,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC9D,QAAQ,EAAE,6BAA6B,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC9D,MAAM,EAAE,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1D,cAAc,EAAE,6BAA6B,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;KAC3E,EACD,YAAY,EACZ,QAAQ,CACT,GAAG;QACF,SAAS,EAAE,KAAK,CAAC;QACjB,SAAS,EAAE,KAAK,CAAC;KAClB;CAwCN;AAED,eAAO,MAAM,KAAK,GAChB,QAAQ,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAC5D,YAAY,SAAS,uBAAuB,cAEhC,QAAQ;;;;;;;;;;;;;;;;;;;eAhDH,KAAK;eACL,KAAK;CAgDgC,CAAC"}
|
@@ -21,9 +21,14 @@ export default class BooleanSchema<TType extends {
|
|
21
21
|
value: boolean;
|
22
22
|
message: string;
|
23
23
|
};
|
24
|
+
protected __type: {
|
25
|
+
message: string;
|
26
|
+
check: (value: TType['input']) => boolean;
|
27
|
+
};
|
24
28
|
protected __transformToAdapter(options: Parameters<Schema['__transformToAdapter']>[0]): Promise<any>;
|
25
29
|
/**
|
26
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
30
|
+
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
31
|
+
* is not supported by default by the schema adapter.
|
27
32
|
*
|
28
33
|
* @example
|
29
34
|
* ```typescript
|
@@ -35,7 +40,8 @@ export default class BooleanSchema<TType extends {
|
|
35
40
|
*
|
36
41
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
37
42
|
*
|
38
|
-
*
|
43
|
+
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
44
|
+
* console.log(errors);
|
39
45
|
* ```
|
40
46
|
*
|
41
47
|
* @param refinementCallback - The callback that will be called to validate the value.
|
@@ -92,8 +98,29 @@ export default class BooleanSchema<TType extends {
|
|
92
98
|
representation: TType["representation"] | undefined | null;
|
93
99
|
}, TDefinitions>;
|
94
100
|
/**
|
95
|
-
*
|
96
|
-
*
|
101
|
+
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
102
|
+
*
|
103
|
+
* ```typescript
|
104
|
+
* p.string().optional({ message: 'This value cannot be null', allow: false })
|
105
|
+
* ```
|
106
|
+
*
|
107
|
+
* @param options - The options of nonOptional function
|
108
|
+
* @param options.message - A custom message if the value is undefined.
|
109
|
+
*
|
110
|
+
* @returns - The schema.
|
111
|
+
*/
|
112
|
+
nonOptional(options?: {
|
113
|
+
message: string;
|
114
|
+
}): BooleanSchema<{
|
115
|
+
input: TType["input"];
|
116
|
+
validate: TType["validate"];
|
117
|
+
internal: TType["internal"];
|
118
|
+
output: TType["output"];
|
119
|
+
representation: TType["representation"];
|
120
|
+
}, TDefinitions>;
|
121
|
+
/**
|
122
|
+
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value is
|
123
|
+
* NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
97
124
|
*
|
98
125
|
* @example
|
99
126
|
* ```typescript
|
@@ -127,14 +154,36 @@ export default class BooleanSchema<TType extends {
|
|
127
154
|
representation: TType["representation"] | null;
|
128
155
|
}, TDefinitions>;
|
129
156
|
/**
|
130
|
-
*
|
131
|
-
*
|
157
|
+
* Just adds a message when the value is null. It's just a syntax sugar for
|
158
|
+
*
|
159
|
+
* ```typescript
|
160
|
+
* p.string().nullable({ message: 'This value cannot be null', allow: false })
|
161
|
+
* ```
|
162
|
+
*
|
163
|
+
* @param options - The options of nonNullable function
|
164
|
+
* @param options.message - A custom message if the value is null.
|
165
|
+
*
|
166
|
+
* @returns - The schema.
|
167
|
+
*/
|
168
|
+
nonNullable(options?: {
|
169
|
+
message: string;
|
170
|
+
}): BooleanSchema<{
|
171
|
+
input: TType["input"];
|
172
|
+
validate: TType["validate"];
|
173
|
+
internal: TType["internal"];
|
174
|
+
output: TType["output"];
|
175
|
+
representation: TType["representation"];
|
176
|
+
}, TDefinitions>;
|
177
|
+
/**
|
178
|
+
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
179
|
+
* that way otherwise it will set the value to undefined after it's validated.
|
132
180
|
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
133
181
|
* function. This will remove the value from the representation of the schema.
|
134
182
|
*
|
135
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
136
|
-
* But if you want to remove the value from the internal representation, you can pass the argument
|
137
|
-
* Then if you still want to remove the value from the representation, you will need to pass
|
183
|
+
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
184
|
+
* function.But if you want to remove the value from the internal representation, you can pass the argument
|
185
|
+
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
186
|
+
* the argument `toRepresentation` as true as well.
|
138
187
|
*
|
139
188
|
* @example
|
140
189
|
* ```typescript
|
@@ -156,9 +205,11 @@ export default class BooleanSchema<TType extends {
|
|
156
205
|
* ```
|
157
206
|
*
|
158
207
|
*
|
159
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
160
|
-
* But if you want to remove the value from the internal representation, you can pass the
|
161
|
-
*
|
208
|
+
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
209
|
+
* the {@link data} function. But if you want to remove the value from the internal representation, you can pass the
|
210
|
+
* argument `toInternal` as true.
|
211
|
+
* Then if you still want to remove the value from the representation, you will need to pass the argument
|
212
|
+
* `toRepresentation` as true as well.
|
162
213
|
*
|
163
214
|
* @returns The schema.
|
164
215
|
*/
|
@@ -173,9 +224,9 @@ export default class BooleanSchema<TType extends {
|
|
173
224
|
representation: TToRepresentation extends true ? undefined : TType["representation"];
|
174
225
|
}, TDefinitions>;
|
175
226
|
/**
|
176
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
177
|
-
* like a database. You should always return the schema after you save the value, that way we will always have
|
178
|
-
* of the schema after the save operation.
|
227
|
+
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
228
|
+
* source like a database. You should always return the schema after you save the value, that way we will always have
|
229
|
+
* the correct type of the schema after the save operation.
|
179
230
|
*
|
180
231
|
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
181
232
|
*
|
@@ -224,7 +275,8 @@ export default class BooleanSchema<TType extends {
|
|
224
275
|
hasSave: true;
|
225
276
|
}>;
|
226
277
|
/**
|
227
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
278
|
+
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
279
|
+
* value will be used.
|
228
280
|
*
|
229
281
|
* @example
|
230
282
|
* ```typescript
|
@@ -245,8 +297,9 @@ export default class BooleanSchema<TType extends {
|
|
245
297
|
representation: TType["representation"];
|
246
298
|
}, TDefinitions>;
|
247
299
|
/**
|
248
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
249
|
-
* the custom schema your own way. Our API does not support passthrough?
|
300
|
+
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
301
|
+
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
302
|
+
* No problem, you can use this function to customize the zod schema.
|
250
303
|
*
|
251
304
|
* @example
|
252
305
|
* ```typescript
|
@@ -257,21 +310,21 @@ export default class BooleanSchema<TType extends {
|
|
257
310
|
* });
|
258
311
|
*
|
259
312
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
260
|
-
*
|
261
|
-
* console.log(errors);
|
313
|
+
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
314
|
+
* console.log(errors);
|
262
315
|
* ```
|
263
316
|
*
|
264
317
|
* @param callback - The callback that will be called to customize the schema.
|
265
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
266
|
-
* to a string so you can save it for future runs.
|
318
|
+
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
319
|
+
* compile the underlying schema to a string so you can save it for future runs.
|
267
320
|
*
|
268
321
|
* @returns The schema.
|
269
322
|
*/
|
270
323
|
extends(callback: (schema: Awaited<ReturnType<NonNullable<TDefinitions['schemaAdapter']['datetime']>['translate']>>) => Awaited<ReturnType<NonNullable<TDefinitions['schemaAdapter']['field']>['translate']>> | any, toStringCallback?: (schemaAsString: string) => string): this;
|
271
324
|
/**
|
272
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
273
|
-
* control to add data cleaning for example, transforming the data and
|
274
|
-
* The schema maps to itself.
|
325
|
+
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
326
|
+
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
327
|
+
* whatever. Another use case is when you want to return deeply nested recursive data. The schema maps to itself.
|
275
328
|
*
|
276
329
|
* @example
|
277
330
|
* ```typescript
|
@@ -319,8 +372,9 @@ export default class BooleanSchema<TType extends {
|
|
319
372
|
representation: TRepresentation;
|
320
373
|
}, TDefinitions>;
|
321
374
|
/**
|
322
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when
|
323
|
-
* to a type that the schema adapter can understand. For example, you might want
|
375
|
+
* This function is used to transform the value to the internal representation of the schema. This is useful when
|
376
|
+
* you want to transform the value to a type that the schema adapter can understand. For example, you might want
|
377
|
+
* to transform a string to a date. This is the function you use.
|
324
378
|
*
|
325
379
|
* @example
|
326
380
|
* ```typescript
|
@@ -358,8 +412,9 @@ export default class BooleanSchema<TType extends {
|
|
358
412
|
representation: TType["representation"];
|
359
413
|
}, TDefinitions>;
|
360
414
|
/**
|
361
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
362
|
-
* here BEFORE the validation. This pretty much transforms the value to a type
|
415
|
+
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
416
|
+
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
|
417
|
+
* that the schema adapter can understand.
|
363
418
|
*
|
364
419
|
* @example
|
365
420
|
* ```
|
@@ -385,7 +440,8 @@ export default class BooleanSchema<TType extends {
|
|
385
440
|
representation: TType["representation"];
|
386
441
|
}, TDefinitions>;
|
387
442
|
/**
|
388
|
-
* This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
|
443
|
+
* This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
|
444
|
+
* result to be a string as well.
|
389
445
|
*
|
390
446
|
* @example
|
391
447
|
* ```ts
|
@@ -402,7 +458,8 @@ export default class BooleanSchema<TType extends {
|
|
402
458
|
validate: string | TType["validate"];
|
403
459
|
}, TDefinitions>;
|
404
460
|
/**
|
405
|
-
* Allows you to set the values that will be considered as true. This is useful when you have a string that can be
|
461
|
+
* Allows you to set the values that will be considered as true. This is useful when you have a string that can be
|
462
|
+
* 'T' or 'F' for example.
|
406
463
|
*
|
407
464
|
* @example
|
408
465
|
* ```ts
|
@@ -422,18 +479,19 @@ export default class BooleanSchema<TType extends {
|
|
422
479
|
validate: TValues[number] | TType["validate"];
|
423
480
|
}, TDefinitions>;
|
424
481
|
/**
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
482
|
+
* Allows you to set the values that will be considered as false. This is useful when you have a string that can
|
483
|
+
* be 'N' or 0 for example.
|
484
|
+
*
|
485
|
+
* @example
|
486
|
+
* ```ts
|
487
|
+
* boolean().falseValues(['F', 'N', 0]).parse('F') // works and parses to false
|
488
|
+
* boolean().falseValues(['F', 'N', 0]).parse('Y') // fails and returns the value as is
|
489
|
+
* ```
|
490
|
+
*
|
491
|
+
* @param values - The values on an array that will be considered as true.
|
492
|
+
*
|
493
|
+
* @returns - The schema instance
|
494
|
+
*/
|
437
495
|
falseValues<const TValues extends any[]>(values: TValues): BooleanSchema<{
|
438
496
|
input: TValues[number] | TType["input"];
|
439
497
|
output: TValues[number] | TType["output"];
|
@@ -442,7 +500,8 @@ export default class BooleanSchema<TType extends {
|
|
442
500
|
validate: TValues[number] | TType["validate"];
|
443
501
|
}, TDefinitions>;
|
444
502
|
/**
|
445
|
-
* This will allow the value to be a number, it does not validate, it just parses inputs as number and allows the
|
503
|
+
* This will allow the value to be a number, it does not validate, it just parses inputs as number and allows the
|
504
|
+
* result to be a string as well.
|
446
505
|
*
|
447
506
|
* @example
|
448
507
|
* ```ts
|