@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.
Files changed (174) hide show
  1. package/.turbo/turbo-build$colon$watch.log +12 -410
  2. package/CHANGELOG.md +17 -0
  3. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
  4. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
  5. package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
  6. package/__tests__/.drizzle/schema.ts +35 -0
  7. package/__tests__/drizzle.config.ts +11 -0
  8. package/__tests__/eslint.config.js +10 -0
  9. package/__tests__/manage.ts +5 -0
  10. package/__tests__/node_modules/.bin/drizzle-kit +17 -0
  11. package/__tests__/node_modules/.bin/esbuild +14 -0
  12. package/__tests__/node_modules/.bin/tsc +17 -0
  13. package/__tests__/node_modules/.bin/tsserver +17 -0
  14. package/__tests__/node_modules/.bin/tsx +17 -0
  15. package/__tests__/package.json +36 -0
  16. package/__tests__/sqlite.db +0 -0
  17. package/__tests__/src/core/array.test.ts +130 -0
  18. package/__tests__/src/core/boolean.test.ts +66 -0
  19. package/__tests__/src/core/datetime.test.ts +102 -0
  20. package/__tests__/src/core/index.ts +35 -0
  21. package/__tests__/src/core/model.test.ts +260 -0
  22. package/__tests__/src/core/models.ts +50 -0
  23. package/__tests__/src/core/numbers.test.ts +177 -0
  24. package/__tests__/src/core/object.test.ts +198 -0
  25. package/__tests__/src/core/string.test.ts +222 -0
  26. package/__tests__/src/core/test.test.ts +59 -0
  27. package/__tests__/src/core/types.test.ts +97 -0
  28. package/__tests__/src/core/union.test.ts +99 -0
  29. package/__tests__/src/settings.ts +71 -0
  30. package/__tests__/tsconfig.json +11 -0
  31. package/dist/cjs/src/adapter/fields/index.js +2 -2
  32. package/dist/cjs/src/adapter/fields/object.js +9 -0
  33. package/dist/cjs/src/adapter/index.js +1 -0
  34. package/dist/cjs/src/constants.js +1 -7
  35. package/dist/cjs/src/domain.js +146 -1
  36. package/dist/cjs/src/index.js +69 -74
  37. package/dist/cjs/src/model.js +206 -206
  38. package/dist/cjs/src/schema/array.js +185 -58
  39. package/dist/cjs/src/schema/boolean.js +105 -44
  40. package/dist/cjs/src/schema/datetime.js +104 -38
  41. package/dist/cjs/src/schema/number.js +134 -114
  42. package/dist/cjs/src/schema/object.js +106 -43
  43. package/dist/cjs/src/schema/schema.js +123 -75
  44. package/dist/cjs/src/schema/string.js +152 -58
  45. package/dist/cjs/src/schema/union.js +412 -290
  46. package/dist/cjs/src/utils.js +42 -15
  47. package/dist/cjs/src/validators/array.js +6 -1
  48. package/dist/cjs/src/validators/boolean.js +2 -0
  49. package/dist/cjs/src/validators/datetime.js +4 -0
  50. package/dist/cjs/src/validators/number.js +12 -40
  51. package/dist/cjs/src/validators/object.js +1 -0
  52. package/dist/cjs/src/validators/schema.js +5 -1
  53. package/dist/cjs/src/validators/string.js +30 -2
  54. package/dist/cjs/src/validators/union.js +5 -4
  55. package/dist/cjs/src/validators/utils.js +99 -27
  56. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
  57. package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
  58. package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
  59. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
  60. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
  61. package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
  62. package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
  63. package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
  64. package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
  65. package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
  66. package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
  67. package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
  68. package/dist/cjs/types/adapter/index.d.ts +1 -0
  69. package/dist/cjs/types/adapter/index.d.ts.map +1 -1
  70. package/dist/cjs/types/adapter/types.d.ts +28 -18
  71. package/dist/cjs/types/adapter/types.d.ts.map +1 -1
  72. package/dist/cjs/types/constants.d.ts +0 -1
  73. package/dist/cjs/types/constants.d.ts.map +1 -1
  74. package/dist/cjs/types/domain.d.ts +5 -4
  75. package/dist/cjs/types/domain.d.ts.map +1 -1
  76. package/dist/cjs/types/index.d.ts +78 -55
  77. package/dist/cjs/types/index.d.ts.map +1 -1
  78. package/dist/cjs/types/model.d.ts +17 -17
  79. package/dist/cjs/types/model.d.ts.map +1 -1
  80. package/dist/cjs/types/schema/array.d.ts +168 -47
  81. package/dist/cjs/types/schema/array.d.ts.map +1 -1
  82. package/dist/cjs/types/schema/boolean.d.ts +103 -44
  83. package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
  84. package/dist/cjs/types/schema/datetime.d.ts +90 -30
  85. package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
  86. package/dist/cjs/types/schema/number.d.ts +133 -125
  87. package/dist/cjs/types/schema/number.d.ts.map +1 -1
  88. package/dist/cjs/types/schema/object.d.ts +104 -35
  89. package/dist/cjs/types/schema/object.d.ts.map +1 -1
  90. package/dist/cjs/types/schema/schema.d.ts +62 -44
  91. package/dist/cjs/types/schema/schema.d.ts.map +1 -1
  92. package/dist/cjs/types/schema/string.d.ts +152 -65
  93. package/dist/cjs/types/schema/string.d.ts.map +1 -1
  94. package/dist/cjs/types/schema/types.d.ts +11 -2
  95. package/dist/cjs/types/schema/types.d.ts.map +1 -1
  96. package/dist/cjs/types/schema/union.d.ts +133 -40
  97. package/dist/cjs/types/schema/union.d.ts.map +1 -1
  98. package/dist/cjs/types/types.d.ts +35 -0
  99. package/dist/cjs/types/types.d.ts.map +1 -1
  100. package/dist/cjs/types/utils.d.ts +41 -27
  101. package/dist/cjs/types/utils.d.ts.map +1 -1
  102. package/dist/cjs/types/validators/array.d.ts.map +1 -1
  103. package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
  104. package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
  105. package/dist/cjs/types/validators/number.d.ts +5 -6
  106. package/dist/cjs/types/validators/number.d.ts.map +1 -1
  107. package/dist/cjs/types/validators/object.d.ts.map +1 -1
  108. package/dist/cjs/types/validators/schema.d.ts +2 -2
  109. package/dist/cjs/types/validators/schema.d.ts.map +1 -1
  110. package/dist/cjs/types/validators/string.d.ts +9 -9
  111. package/dist/cjs/types/validators/string.d.ts.map +1 -1
  112. package/dist/cjs/types/validators/utils.d.ts +44 -27
  113. package/dist/cjs/types/validators/utils.d.ts.map +1 -1
  114. package/dist/esm/src/adapter/fields/index.js +2 -2
  115. package/dist/esm/src/adapter/fields/object.js +6 -0
  116. package/dist/esm/src/adapter/index.js +1 -0
  117. package/dist/esm/src/constants.js +1 -2
  118. package/dist/esm/src/domain.js +11 -1
  119. package/dist/esm/src/index.js +38 -73
  120. package/dist/esm/src/model.js +83 -78
  121. package/dist/esm/src/schema/array.js +136 -54
  122. package/dist/esm/src/schema/boolean.js +98 -44
  123. package/dist/esm/src/schema/datetime.js +91 -38
  124. package/dist/esm/src/schema/number.js +127 -110
  125. package/dist/esm/src/schema/object.js +98 -43
  126. package/dist/esm/src/schema/schema.js +102 -67
  127. package/dist/esm/src/schema/string.js +147 -59
  128. package/dist/esm/src/schema/union.js +119 -40
  129. package/dist/esm/src/types.js +14 -1
  130. package/dist/esm/src/utils.js +56 -27
  131. package/dist/esm/src/validators/array.js +6 -1
  132. package/dist/esm/src/validators/boolean.js +2 -0
  133. package/dist/esm/src/validators/datetime.js +4 -0
  134. package/dist/esm/src/validators/number.js +9 -23
  135. package/dist/esm/src/validators/object.js +1 -0
  136. package/dist/esm/src/validators/schema.js +5 -1
  137. package/dist/esm/src/validators/string.js +30 -2
  138. package/dist/esm/src/validators/union.js +5 -4
  139. package/dist/esm/src/validators/utils.js +62 -36
  140. package/package.json +3 -3
  141. package/src/adapter/fields/array.ts +2 -2
  142. package/src/adapter/fields/boolean.ts +3 -8
  143. package/src/adapter/fields/datetime.ts +3 -9
  144. package/src/adapter/fields/index.ts +11 -11
  145. package/src/adapter/fields/number.ts +3 -9
  146. package/src/adapter/fields/object.ts +13 -10
  147. package/src/adapter/fields/string.ts +3 -9
  148. package/src/adapter/fields/union.ts +3 -9
  149. package/src/adapter/index.ts +1 -0
  150. package/src/adapter/types.ts +60 -45
  151. package/src/constants.ts +1 -3
  152. package/src/domain.ts +15 -1
  153. package/src/index.ts +189 -211
  154. package/src/model.ts +119 -115
  155. package/src/schema/array.ts +274 -90
  156. package/src/schema/boolean.ts +145 -60
  157. package/src/schema/datetime.ts +133 -49
  158. package/src/schema/number.ts +210 -173
  159. package/src/schema/object.ts +167 -74
  160. package/src/schema/schema.ts +205 -126
  161. package/src/schema/string.ts +221 -94
  162. package/src/schema/types.ts +44 -16
  163. package/src/schema/union.ts +193 -68
  164. package/src/types.ts +53 -0
  165. package/src/utils.ts +115 -57
  166. package/src/validators/array.ts +46 -27
  167. package/src/validators/boolean.ts +13 -7
  168. package/src/validators/datetime.ts +24 -16
  169. package/src/validators/number.ts +53 -63
  170. package/src/validators/object.ts +6 -5
  171. package/src/validators/schema.ts +33 -25
  172. package/src/validators/string.ts +122 -59
  173. package/src/validators/union.ts +8 -8
  174. package/src/validators/utils.ts +67 -42
@@ -1,9 +1,8 @@
1
1
  import Schema from './schema';
2
- import { getDefaultAdapter } from '../conf';
3
2
  import {
4
3
  defaultTransform,
5
4
  defaultTransformToAdapter,
6
- transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas,
5
+ transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas
7
6
  } from '../utils';
8
7
  import { objectValidation } from '../validators/object';
9
8
  import Validator from '../validators/utils';
@@ -26,11 +25,19 @@ export default class ObjectSchema<
26
25
  representation: Record<any, any>;
27
26
  },
28
27
  TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType,
29
- TData extends Record<any, any> = Record<any, any>,
28
+ TData extends Record<any, any> = Record<any, any>
30
29
  > extends Schema<TType, TDefinitions> {
31
30
  protected __data: Record<any, Schema>;
32
31
  protected __cachedDataAsEntries!: [string, Schema][];
33
32
 
33
+ protected __type: {
34
+ message: string;
35
+ check: (value: TType['input']) => boolean;
36
+ } = {
37
+ message: 'Invalid type',
38
+ check: (value) => typeof value === 'object' && value !== null
39
+ };
40
+
34
41
  constructor(data: TData) {
35
42
  super();
36
43
  this.__data = data;
@@ -39,7 +46,7 @@ export default class ObjectSchema<
39
46
  protected __retrieveDataAsEntriesAndCache(): [string, Schema][] {
40
47
  const dataAsEntries = Array.isArray(this.__cachedDataAsEntries)
41
48
  ? this.__cachedDataAsEntries
42
- : (Object.entries(this.__data));
49
+ : Object.entries(this.__data);
43
50
  this.__cachedDataAsEntries = dataAsEntries;
44
51
  return this.__cachedDataAsEntries;
45
52
  }
@@ -57,10 +64,10 @@ export default class ObjectSchema<
57
64
  // This is needed because we will create other objects based this one by reference
58
65
  const transformedDataByKeys = {
59
66
  transformed: {},
60
- asString: {},
67
+ asString: {}
61
68
  } as { transformed: Record<any, any>; asString: Record<any, string> };
62
69
  const transformedDataByKeysArray: { transformed: Record<any, any>; asString: Record<any, string> }[] = [
63
- transformedDataByKeys,
70
+ transformedDataByKeys
64
71
  ];
65
72
 
66
73
  let shouldValidateWithFallback = false;
@@ -90,7 +97,7 @@ export default class ObjectSchema<
90
97
  if (transformedDataByKeysArray[indexOnTransformedDataByKeys] === undefined)
91
98
  transformedDataByKeysArray[indexOnTransformedDataByKeys] = {
92
99
  transformed: { ...transformedDataByKeys.transformed },
93
- asString: { ...transformedDataByKeys.asString },
100
+ asString: { ...transformedDataByKeys.asString }
94
101
  };
95
102
  transformedDataByKeysArray[indexOnTransformedDataByKeys].transformed[key] =
96
103
  transformedDataAndString[transformedDataIndex].transformed;
@@ -121,20 +128,22 @@ export default class ObjectSchema<
121
128
  data: isStringVersion ? asString : transformed,
122
129
  nullable: this.__nullable,
123
130
  optional: this.__optional,
131
+ type: this.__type,
124
132
  parsers: {
125
133
  nullable: this.__nullable.allow,
126
- optional: this.__optional.allow,
134
+ optional: this.__optional.allow
127
135
  }
128
136
  }),
129
137
  {},
130
138
  {
131
- shouldAddStringVersion: options.shouldAddStringVersion,
139
+ shouldAddStringVersion: options.shouldAddStringVersion
132
140
  }
133
141
  )
134
142
  )
135
143
  )
136
144
  ).flat();
137
145
  },
146
+ this,
138
147
  this.__transformedSchemas,
139
148
  options,
140
149
  'object'
@@ -142,8 +151,10 @@ export default class ObjectSchema<
142
151
  }
143
152
 
144
153
  /**
145
- * Transform the data to the representation without validating it. This is useful when you want to return a data from a query directly to the user. The core idea of this is that you can join the data
146
- * from the database "by hand". In other words, you can do the joins by yourself directly on code. For more complex cases, this can be really helpful.
154
+ * Transform the data to the representation without validating it. This is useful when you want to return a data
155
+ * from a query directly to the user. The core idea of this is that you can join the data from the database "by hand".
156
+ * In other words, you can do the joins by yourself directly on code. For more complex cases, this can be really
157
+ * helpful.
147
158
  *
148
159
  * @param value - The value to be transformed.
149
160
  *
@@ -173,7 +184,8 @@ export default class ObjectSchema<
173
184
  }
174
185
 
175
186
  /**
176
- * This let's you refine the schema with custom validations. This is useful when you want to validate something that is not supported by default by the schema adapter.
187
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something
188
+ * that is not supported by default by the schema adapter.
177
189
  *
178
190
  * @example
179
191
  * ```typescript
@@ -185,7 +197,8 @@ export default class ObjectSchema<
185
197
  *
186
198
  * const { errors, parsed } = await numberSchema.parse(-1);
187
199
  *
188
- * console.log(errors); // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
200
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
201
+ * console.log(errors);
189
202
  * ```
190
203
  *
191
204
  * @param refinementCallback - The callback that will be called to validate the value.
@@ -193,7 +206,13 @@ export default class ObjectSchema<
193
206
  * @param options.isAsync - Whether the callback is async or not. Defaults to true.
194
207
  */
195
208
  refine(
196
- refinementCallback: (value: TType['input']) => Promise<void | undefined | { code: string; message: string }> | void | undefined | { code: string; message: string }
209
+ refinementCallback: (
210
+ value: TType['input']
211
+ ) =>
212
+ | Promise<void | undefined | { code: string; message: string }>
213
+ | void
214
+ | undefined
215
+ | { code: string; message: string }
197
216
  ) {
198
217
  return super.refine(refinementCallback) as unknown as ObjectSchema<
199
218
  {
@@ -202,14 +221,17 @@ export default class ObjectSchema<
202
221
  internal: TType['internal'];
203
222
  output: TType['output'];
204
223
  representation: TType['representation'];
205
- }, TDefinitions, TData
224
+ },
225
+ TDefinitions,
226
+ TData
206
227
  >;
207
228
  }
208
229
 
209
230
  /**
210
- * Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can pass `outputOnly` as `true` to this method.
211
- * This will allow you to pass `null` or `undefined` as a value on the {@link Schema.data} method, but it will not allow the value to be `null` or `undefined`.
212
- * This is useful for typing purposes
231
+ * Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can
232
+ * pass `outputOnly` as `true` to this method. This will allow you to pass `null` or `undefined` as a value on the
233
+ * {@link Schema.data} method, but it will not allow the value to be `null` or `undefined`. This is useful for
234
+ * typing purposes
213
235
  *
214
236
  * @example
215
237
  * ```typescript
@@ -237,35 +259,72 @@ export default class ObjectSchema<
237
259
  * company: companySchema.optional({ outputOnly: true })
238
260
  * });
239
261
  *
240
- * const { errors, parsed } = await userSchema.data({ id: 1, name: 'John Doe' }); // Will not allow the company to be null or undefined on a typing level.
241
- * const value = await userSchema.data({ id: 1, name: 'John Doe' }); // Will allow the company to be null or undefined on a typing level
262
+ * // Will not allow the company to be null or undefined on a typing level.
263
+ * const { errors, parsed } = await userSchema.data({ id: 1, name: 'John Doe' });
264
+ *
265
+ * // Will allow the company to be null or undefined on a typing level
266
+ * const value = await userSchema.data({ id: 1, name: 'John Doe' });
242
267
  * ```
243
268
  *
244
269
  * @returns - The schema we are working with.
245
270
  */
246
- optional<TOutputOnly extends boolean = false>(options?: { message?: string; allow?: false, outputOnly?: TOutputOnly}) {
247
- return (options?.outputOnly ? this : super.optional(options)) as unknown as ObjectSchema<TOutputOnly extends true ?
271
+ optional<TOutputOnly extends boolean = false>(options?: {
272
+ message?: string;
273
+ allow?: false;
274
+ outputOnly?: TOutputOnly;
275
+ }) {
276
+ return (options?.outputOnly ? this : super.optional(options)) as unknown as ObjectSchema<
277
+ TOutputOnly extends true
278
+ ? {
279
+ input: TType['input'];
280
+ validate: TType['validate'];
281
+ internal: TType['internal'];
282
+ output: TType['output'] | undefined | null;
283
+ representation: TType['representation'];
284
+ }
285
+ : {
286
+ input: TType['input'] | undefined | null;
287
+ validate: TType['validate'] | undefined | null;
288
+ internal: TType['internal'] | undefined | null;
289
+ output: TType['output'] | undefined | null;
290
+ representation: TType['representation'] | undefined | null;
291
+ },
292
+ TDefinitions,
293
+ TData
294
+ >;
295
+ }
296
+
297
+ /**
298
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
299
+ *
300
+ * ```typescript
301
+ * p.datetime().optional({ message: 'This value should be defined', allow: false })
302
+ * ```
303
+ *
304
+ * @param options - The options of nonOptional function
305
+ * @param options.message - A custom message if the value is undefined.
306
+ *
307
+ * @returns - The schema.
308
+ */
309
+ nonOptional(options?: { message: string }) {
310
+ return super.optional({
311
+ message: options?.message,
312
+ allow: false
313
+ }) as unknown as ObjectSchema<
248
314
  {
249
315
  input: TType['input'];
250
316
  validate: TType['validate'];
251
317
  internal: TType['internal'];
252
- output: TType['output'] | undefined | null;
318
+ output: TType['output'];
253
319
  representation: TType['representation'];
254
- } :
255
- {
256
- input: TType['input'] | undefined | null;
257
- validate: TType['validate'] | undefined | null;
258
- internal: TType['internal'] | undefined | null;
259
- output: TType['output'] | undefined | null;
260
- representation: TType['representation'] | undefined | null;
261
320
  },
262
- TDefinitions,
263
- TData
321
+ TDefinitions
264
322
  >;
265
323
  }
266
324
 
267
325
  /**
268
- * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value is NULL by setting
326
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
327
+ * is NULL by setting
269
328
  * the { message: 'Your custom message', allow: false } on the options.
270
329
  *
271
330
  * @example
@@ -304,14 +363,45 @@ export default class ObjectSchema<
304
363
  }
305
364
 
306
365
  /**
307
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep that way
308
- * otherwise it will set the value to undefined after it's validated.
366
+ * Just adds a message when the value is null. It's just a syntax sugar for
367
+ *
368
+ * ```typescript
369
+ * p.datetime().nullable({ message: 'This value cannot be null', allow: false })
370
+ * ```
371
+ *
372
+ * @param options - The options of nonNullable function
373
+ * @param options.message - A custom message if the value is null.
374
+ *
375
+ * @returns - The schema.
376
+ */
377
+ nonNullable(options?: { message: string }) {
378
+ return super.nullable({
379
+ message: options?.message || '',
380
+ allow: false
381
+ }) as unknown as ObjectSchema<
382
+ {
383
+ input: TType['input'];
384
+ validate: TType['validate'];
385
+ internal: TType['internal'];
386
+ output: TType['output'];
387
+ representation: TType['representation'];
388
+ },
389
+ TDefinitions
390
+ >;
391
+ }
392
+
393
+ /**
394
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
395
+ * that way otherwise it will set the value to undefined after it's validated.
309
396
  * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
310
397
  * function. This will remove the value from the representation of the schema.
311
398
  *
312
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
313
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
314
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
399
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
400
+ * function.
401
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
402
+ * as true.
403
+ * Then if you still want to remove the value from the representation, you will need to pass the argument
404
+ * `toRepresentation` as true as well.
315
405
  *
316
406
  * @example
317
407
  * ```typescript
@@ -333,16 +423,19 @@ export default class ObjectSchema<
333
423
  * ```
334
424
  *
335
425
  *
336
- * @param args - By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
337
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
338
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
426
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
427
+ * the {@link data} function.
428
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
429
+ * as true.
430
+ * Then if you still want to remove the value from the representation, you will need to pass the argument
431
+ * `toRepresentation` as true as well.
339
432
  *
340
433
  * @returns The schema.
341
434
  */
342
435
  omit<
343
436
  TToInternal extends boolean,
344
437
  TToRepresentation extends boolean = boolean extends TToInternal ? true : false
345
- >(args?: { toInternal?: TToInternal, toRepresentation?: TToRepresentation }) {
438
+ >(args?: { toInternal?: TToInternal; toRepresentation?: TToRepresentation }) {
346
439
  return super.omit(args) as unknown as ObjectSchema<
347
440
  {
348
441
  input: TToInternal extends true ? TType['input'] | undefined : TType['input'];
@@ -357,9 +450,9 @@ export default class ObjectSchema<
357
450
  }
358
451
 
359
452
  /**
360
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external source
361
- * like a database. You should always return the schema after you save the value, that way we will always have the correct type
362
- * of the schema after the save operation.
453
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
454
+ * source like a database. You should always return the schema after you save the value, that way we will always have
455
+ * the correct type of the schema after the save operation.
363
456
  *
364
457
  * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
365
458
  *
@@ -414,9 +507,9 @@ export default class ObjectSchema<
414
507
  >;
415
508
  }
416
509
 
417
-
418
510
  /**
419
- * This function is used to add a default value to the schema. If the value is either undefined or null, the default value will be used.
511
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
512
+ * value will be used.
420
513
  *
421
514
  * @example
422
515
  * ```typescript
@@ -446,8 +539,9 @@ export default class ObjectSchema<
446
539
  }
447
540
 
448
541
  /**
449
- * This function let's you customize the schema your own way. After we translate the schema on the adapter we call this function to let you customize
450
- * the custom schema your own way. Our API does not support passthrough? No problem, you can use this function to customize the zod schema.
542
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
543
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
544
+ * No problem, you can use this function to customize the zod schema.
451
545
  *
452
546
  * @example
453
547
  * ```typescript
@@ -459,12 +553,13 @@ export default class ObjectSchema<
459
553
  *
460
554
  * const { errors, parsed } = await numberSchema.parse(-1);
461
555
  *
462
- * console.log(errors); // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
556
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
557
+ * console.log(errors);
463
558
  * ```
464
559
  *
465
560
  * @param callback - The callback that will be called to customize the schema.
466
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to compile the underlying schema
467
- * to a string so you can save it for future runs.
561
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
562
+ * compile the underlying schema to a string so you can save it for future runs.
468
563
  *
469
564
  * @returns The schema.
470
565
  */
@@ -478,8 +573,9 @@ export default class ObjectSchema<
478
573
  }
479
574
 
480
575
  /**
481
- * This function is used to transform the value to the representation of the schema. When using the {@link data} function. With this function you have full
482
- * control to add data cleaning for example, transforming the data and whatever. Another use case is when you want to return deeply nested recursive data.
576
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
577
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
578
+ * whatever. Another use case is when you want to return deeply nested recursive data.
483
579
  * The schema maps to itself.
484
580
  *
485
581
  * @example
@@ -518,8 +614,10 @@ export default class ObjectSchema<
518
614
  * ```
519
615
  * @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
520
616
  * @param options - Options for the toRepresentation function.
521
- * @param options.after - Whether the toRepresentationCallback should be called after the existing toRepresentationCallback. Defaults to true.
522
- * @param options.before - Whether the toRepresentationCallback should be called before the existing toRepresentationCallback. Defaults to true.
617
+ * @param options.after - Whether the toRepresentationCallback should be called after the existing
618
+ * toRepresentationCallback. Defaults to true.
619
+ * @param options.before - Whether the toRepresentationCallback should be called before the existing
620
+ * toRepresentationCallback. Defaults to true.
523
621
  *
524
622
  * @returns The schema with a new return type
525
623
  */
@@ -544,8 +642,9 @@ export default class ObjectSchema<
544
642
  }
545
643
 
546
644
  /**
547
- * This function is used to transform the value to the internal representation of the schema. This is useful when you want to transform the value
548
- * to a type that the schema adapter can understand. For example, you might want to transform a string to a date. This is the function you use.
645
+ * This function is used to transform the value to the internal representation of the schema. This is useful when
646
+ * you want to transform the value to a type that the schema adapter can understand. For example, you might want
647
+ * to transform a string to a date. This is the function you use.
549
648
  *
550
649
  * @example
551
650
  * ```typescript
@@ -590,8 +689,9 @@ export default class ObjectSchema<
590
689
  }
591
690
 
592
691
  /**
593
- * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string, you can convert that string to a date
594
- * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
692
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
693
+ * you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
694
+ * that the schema adapter can understand.
595
695
  *
596
696
  * @example
597
697
  * ```
@@ -648,10 +748,11 @@ export default class ObjectSchema<
648
748
  */
649
749
  removeExtraneous() {
650
750
  this.__parsers.medium.set('removeExtraneous', (value) => {
651
- if (typeof value !== 'object' || value === null) return {
652
- value,
653
- preventNextParsers: false,
654
- };
751
+ if (typeof value !== 'object' || value === null)
752
+ return {
753
+ value,
754
+ preventNextParsers: false
755
+ };
655
756
 
656
757
  const valueKeys = Object.keys(value);
657
758
  for (const key of valueKeys) {
@@ -661,7 +762,7 @@ export default class ObjectSchema<
661
762
 
662
763
  return {
663
764
  value,
664
- preventNextParsers: false,
765
+ preventNextParsers: false
665
766
  };
666
767
  });
667
768
 
@@ -670,7 +771,7 @@ export default class ObjectSchema<
670
771
 
671
772
  static new<
672
773
  TData extends Record<any, Schema<any, TDefinitions>>,
673
- TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType,
774
+ TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType
674
775
  >(data: TData) {
675
776
  const returnValue = new ObjectSchema<
676
777
  {
@@ -684,14 +785,6 @@ export default class ObjectSchema<
684
785
  TData
685
786
  >(data);
686
787
 
687
- const adapterInstance = getDefaultAdapter();
688
-
689
- returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
690
- transformed: false,
691
- adapter: adapterInstance,
692
- schemas: [],
693
- };
694
-
695
788
  return returnValue;
696
789
  }
697
790
  }