@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,11 +1,19 @@
1
-
2
1
  import Schema from './schema';
3
- import { getDefaultAdapter } from '../conf';
4
2
  import { defaultTransform, defaultTransformToAdapter } from '../utils';
5
- import { endsWith, includes, maxLength, minLength, regex, startsWith, stringValidation } from '../validators/string';
3
+ import { is, nullable, optional } from '../validators/schema';
4
+ import {
5
+ email,
6
+ endsWith,
7
+ includes,
8
+ maxLength,
9
+ minLength,
10
+ regex,
11
+ startsWith,
12
+ stringValidation,
13
+ uuid
14
+ } from '../validators/string';
6
15
 
7
16
  import type { DefinitionsOfSchemaType } from './types';
8
- import type { Narrow } from '@palmares/core';
9
17
 
10
18
  export default class StringSchema<
11
19
  TType extends {
@@ -21,53 +29,59 @@ export default class StringSchema<
21
29
  representation: string;
22
30
  validate: string;
23
31
  },
24
- TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType,
32
+ TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType
25
33
  > extends Schema<TType, TDefinitions> {
26
- protected __is!: {
27
- value: Narrow<TType['input'] | TType['input'][]>;
34
+ protected __is?: {
35
+ value: TType['input'] | TType['input'][];
28
36
  message: string;
29
37
  };
30
38
 
31
- protected __email!: {
39
+ protected __email?: {
32
40
  message: string;
33
41
  };
34
42
 
35
-
36
- protected __uuid!: {
43
+ protected __uuid?: {
37
44
  message: string;
38
45
  };
39
46
 
40
- protected __minLength!: {
47
+ protected __minLength?: {
41
48
  value: number;
42
- inclusive: boolean;
43
49
  message: string;
44
50
  };
45
51
 
46
- protected __maxLength!: {
52
+ protected __maxLength?: {
47
53
  value: number;
48
- inclusive: boolean;
49
54
  message: string;
50
55
  };
51
56
 
52
- protected __regex!: {
57
+ protected __regex?: {
53
58
  value: RegExp;
54
59
  message: string;
55
60
  };
56
- protected __endsWith!: {
61
+ protected __endsWith?: {
57
62
  value: string;
58
63
  message: string;
59
64
  };
60
65
 
61
- protected __startsWith!: {
66
+ protected __startsWith?: {
62
67
  value: string;
63
68
  message: string;
64
69
  };
65
70
 
66
- protected __includes!: {
71
+ protected __includes?: {
67
72
  value: string;
68
73
  message: string;
69
74
  };
70
75
 
76
+ protected __type: {
77
+ message: string;
78
+ check: (value: TType['input']) => boolean;
79
+ } = {
80
+ message: 'Invalid type',
81
+ check: (value: any) => {
82
+ return typeof value === 'string';
83
+ }
84
+ };
71
85
  protected async __transformToAdapter(options: Parameters<Schema['__transformToAdapter']>[0]): Promise<any> {
72
86
  return defaultTransformToAdapter(
73
87
  async (adapter) => {
@@ -77,6 +91,10 @@ export default class StringSchema<
77
91
  adapter,
78
92
  adapter.string,
79
93
  () => ({
94
+ type: this.__type,
95
+ is: this.__is,
96
+ email: this.__email,
97
+ uuid: this.__uuid,
80
98
  minLength: this.__minLength,
81
99
  maxLength: this.__maxLength,
82
100
  regex: this.__regex,
@@ -87,7 +105,7 @@ export default class StringSchema<
87
105
  optional: this.__optional,
88
106
  parsers: {
89
107
  nullable: this.__nullable.allow,
90
- optional: this.__optional.allow,
108
+ optional: this.__optional.allow
91
109
  }
92
110
  }),
93
111
  {
@@ -95,8 +113,13 @@ export default class StringSchema<
95
113
  minLength,
96
114
  endsWith,
97
115
  startsWith,
116
+ email,
117
+ uuid,
118
+ is,
98
119
  regex,
99
120
  includes,
121
+ nullable,
122
+ optional
100
123
  },
101
124
  {
102
125
  validatorsIfFallbackOrNotSupported: stringValidation(),
@@ -104,10 +127,11 @@ export default class StringSchema<
104
127
  // eslint-disable-next-line ts/require-await
105
128
  fallbackIfNotSupported: async () => {
106
129
  return [];
107
- },
130
+ }
108
131
  }
109
132
  );
110
133
  },
134
+ this,
111
135
  this.__transformedSchemas,
112
136
  options,
113
137
  'number'
@@ -115,7 +139,8 @@ export default class StringSchema<
115
139
  }
116
140
 
117
141
  /**
118
- * 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.
142
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something that
143
+ * is not supported by default by the schema adapter.
119
144
  *
120
145
  * @example
121
146
  * ```typescript
@@ -127,7 +152,8 @@ export default class StringSchema<
127
152
  *
128
153
  * const { errors, parsed } = await numberSchema.parse(-1);
129
154
  *
130
- * console.log(errors); // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
155
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
156
+ * console.log(errors);
131
157
  * ```
132
158
  *
133
159
  * @param refinementCallback - The callback that will be called to validate the value.
@@ -135,7 +161,13 @@ export default class StringSchema<
135
161
  * @param options.isAsync - Whether the callback is async or not. Defaults to true.
136
162
  */
137
163
  refine(
138
- refinementCallback: (value: TType['input']) => Promise<void | undefined | { code: string; message: string }> | void | undefined | { code: string; message: string }
164
+ refinementCallback: (
165
+ value: TType['input']
166
+ ) =>
167
+ | Promise<void | undefined | { code: string; message: string }>
168
+ | void
169
+ | undefined
170
+ | { code: string; message: string }
139
171
  ) {
140
172
  return super.refine(refinementCallback) as unknown as StringSchema<
141
173
  {
@@ -144,7 +176,8 @@ export default class StringSchema<
144
176
  internal: TType['internal'];
145
177
  output: TType['output'];
146
178
  representation: TType['representation'];
147
- }, TDefinitions
179
+ },
180
+ TDefinitions
148
181
  >;
149
182
  }
150
183
 
@@ -172,8 +205,8 @@ export default class StringSchema<
172
205
  *
173
206
  * @returns - The schema we are working with.
174
207
  */
175
- optional(options?: { message: string; allow: false }) {
176
- return super.optional(options) as unknown as StringSchema<
208
+ optional() {
209
+ return super.optional() as unknown as StringSchema<
177
210
  {
178
211
  input: TType['input'] | undefined | null;
179
212
  validate: TType['validate'] | undefined | null;
@@ -186,8 +219,36 @@ export default class StringSchema<
186
219
  }
187
220
 
188
221
  /**
189
- * 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
190
- * the { message: 'Your custom message', allow: false } on the options.
222
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
223
+ *
224
+ * ```typescript
225
+ * p.string().optional({ message: 'This value cannot be null', allow: false })
226
+ * ```
227
+ *
228
+ * @param options - The options of nonOptional function
229
+ * @param options.message - A custom message if the value is undefined.
230
+ *
231
+ * @returns - The schema.
232
+ */
233
+ nonOptional(options?: { message: string }) {
234
+ return super.optional({
235
+ message: options?.message,
236
+ allow: false
237
+ }) as unknown as StringSchema<
238
+ {
239
+ input: TType['input'];
240
+ validate: TType['validate'];
241
+ internal: TType['internal'];
242
+ output: TType['output'];
243
+ representation: TType['representation'];
244
+ },
245
+ TDefinitions
246
+ >;
247
+ }
248
+
249
+ /**
250
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
251
+ * is NULL by setting the { message: 'Your custom message', allow: false } on the options.
191
252
  *
192
253
  * @example
193
254
  * ```typescript
@@ -224,14 +285,43 @@ export default class StringSchema<
224
285
  }
225
286
 
226
287
  /**
227
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep that way
228
- * otherwise it will set the value to undefined after it's validated.
288
+ * Just adds a message when the value is null. It's just a syntax sugar for
289
+ *
290
+ * ```typescript
291
+ * p.string().nullable({ message: 'This value cannot be null', allow: false })
292
+ * ```
293
+ *
294
+ * @param options - The options of nonNullable function
295
+ * @param options.message - A custom message if the value is null.
296
+ *
297
+ * @returns - The schema.
298
+ */
299
+ nonNullable(options?: { message: string }) {
300
+ return super.nullable({
301
+ message: options?.message || '',
302
+ allow: false
303
+ }) as unknown as StringSchema<
304
+ {
305
+ input: TType['input'];
306
+ validate: TType['validate'];
307
+ internal: TType['internal'];
308
+ output: TType['output'];
309
+ representation: TType['representation'];
310
+ },
311
+ TDefinitions
312
+ >;
313
+ }
314
+
315
+ /**
316
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
317
+ * that way otherwise it will set the value to undefined after it's validated.
229
318
  * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
230
319
  * function. This will remove the value from the representation of the schema.
231
320
  *
232
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
233
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
234
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
321
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
322
+ * function. But if you want to remove the value from the internal representation, you can pass the argument
323
+ * `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
324
+ * the argument `toRepresentation` as true as well.
235
325
  *
236
326
  * @example
237
327
  * ```typescript
@@ -253,16 +343,17 @@ export default class StringSchema<
253
343
  * ```
254
344
  *
255
345
  *
256
- * @param args - By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
257
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
258
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
346
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
347
+ * the {@link data} function. But if you want to remove the value from the internal representation, you can pass the
348
+ * argument `toInternal` as true. Then if you still want to remove the value from the representation, you will need
349
+ * to pass the argument `toRepresentation` as true as well.
259
350
  *
260
351
  * @returns The schema.
261
352
  */
262
353
  omit<
263
354
  TToInternal extends boolean,
264
355
  TToRepresentation extends boolean = boolean extends TToInternal ? true : false
265
- >(args?: { toInternal?: TToInternal, toRepresentation?: TToRepresentation }) {
356
+ >(args?: { toInternal?: TToInternal; toRepresentation?: TToRepresentation }) {
266
357
  return super.omit(args) as unknown as StringSchema<
267
358
  {
268
359
  input: TToInternal extends true ? TType['input'] | undefined : TType['input'];
@@ -276,9 +367,9 @@ export default class StringSchema<
276
367
  }
277
368
 
278
369
  /**
279
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external source
280
- * like a database. You should always return the schema after you save the value, that way we will always have the correct type
281
- * of the schema after the save operation.
370
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
371
+ * source like a database. You should always return the schema after you save the value, that way we will always have
372
+ * the correct type of the schema after the save operation.
282
373
  *
283
374
  * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
284
375
  *
@@ -332,9 +423,9 @@ export default class StringSchema<
332
423
  >;
333
424
  }
334
425
 
335
-
336
426
  /**
337
- * 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.
427
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
428
+ * value will be used.
338
429
  *
339
430
  * @example
340
431
  * ```typescript
@@ -363,8 +454,9 @@ export default class StringSchema<
363
454
  }
364
455
 
365
456
  /**
366
- * 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
367
- * the custom schema your own way. Our API does not support passthrough? No problem, you can use this function to customize the zod schema.
457
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
458
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
459
+ * No problem, you can use this function to customize the zod schema.
368
460
  *
369
461
  * @example
370
462
  * ```typescript
@@ -375,13 +467,13 @@ export default class StringSchema<
375
467
  * });
376
468
  *
377
469
  * const { errors, parsed } = await numberSchema.parse(-1);
378
- *
379
- * console.log(errors); // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
470
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
471
+ * console.log(errors);
380
472
  * ```
381
473
  *
382
474
  * @param callback - The callback that will be called to customize the schema.
383
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to compile the underlying schema
384
- * to a string so you can save it for future runs.
475
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
476
+ * compile the underlying schema to a string so you can save it for future runs.
385
477
  *
386
478
  * @returns The schema.
387
479
  */
@@ -395,8 +487,9 @@ export default class StringSchema<
395
487
  }
396
488
 
397
489
  /**
398
- * 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
399
- * 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.
490
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
491
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
492
+ * whatever. Another use case is when you want to return deeply nested recursive data.
400
493
  * The schema maps to itself.
401
494
  *
402
495
  * @example
@@ -453,8 +546,9 @@ export default class StringSchema<
453
546
  }
454
547
 
455
548
  /**
456
- * 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
457
- * 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.
549
+ * This function is used to transform the value to the internal representation of the schema. This is useful when
550
+ * you want to transform the value to a type that the schema adapter can understand. For example, you might want
551
+ * to transform a string to a date. This is the function you use.
458
552
  *
459
553
  * @example
460
554
  * ```typescript
@@ -498,8 +592,9 @@ export default class StringSchema<
498
592
  }
499
593
 
500
594
  /**
501
- * 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
502
- * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
595
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
596
+ * you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a
597
+ * type that the schema adapter can understand.
503
598
  *
504
599
  * @example
505
600
  * ```typescript
@@ -531,7 +626,8 @@ export default class StringSchema<
531
626
  }
532
627
 
533
628
  /**
534
- * Defines a list of strings that are allowed, it's useful when you want to restrict the values that are allowed. Like a selector or a Choice field.
629
+ * Defines a list of strings that are allowed, it's useful when you want to restrict the values that are allowed.
630
+ * Like a selector or a Choice field.
535
631
  *
536
632
  * @example
537
633
  * ```typescript
@@ -540,17 +636,25 @@ export default class StringSchema<
540
636
  * const schema = p.string().is(['Argentina', 'Brazil', 'Chile']);
541
637
  *
542
638
  * schema.parse('Argentina'); // { errors: [], parsed: 'Argentina' }
543
- * schema.parse('Uruguay'); // { errors: [{ code: 'invalid_value', message: 'The value should be equal to Argentina, Brazil, Chile', path: [] }], parsed: 'Uruguay' }
639
+ * // { errors: [{
640
+ * // code: 'invalid_value',
641
+ * // message: 'The value should be equal to Argentina, Brazil, Chile',
642
+ * // path: [] }], parsed: 'Uruguay' }
643
+ * schema.parse('Uruguay');
544
644
  * ```
545
645
  *
546
646
  * @param value - The list of numbers that are allowed
547
647
  *
548
648
  * @returns - The schema instance
549
649
  */
550
- is<const TValue extends TType['input'][]>(value: TValue) {
650
+ is<const TValue extends TType['input'][]>(
651
+ value: TValue,
652
+ options?: Partial<Omit<NonNullable<StringSchema['__is']>, 'value'>>
653
+ ) {
551
654
  this.__is = {
552
655
  value,
553
- message: `The value should be equal to ${value.join(', ')}`,
656
+ message:
657
+ typeof options?.message === 'string' ? options.message : `The value should be equal to ${value.join(', ')}`
554
658
  };
555
659
 
556
660
  return this as any as Schema<
@@ -575,7 +679,9 @@ export default class StringSchema<
575
679
  * const schema = p.string().endsWith('.com');
576
680
  *
577
681
  * schema.parse('example.com'); // { errors: [], parsed: 'example.com' }
578
- * schema.parse('example.org'); // { errors: [{ code: 'endsWith', message: 'The value should end with .com', path: [] }], parsed: 'example.org' }
682
+ *
683
+ * // { errors: [{ code: 'endsWith', message: 'The value should end with .com', path: [] }], parsed: 'example.org' }
684
+ * schema.parse('example.org');
579
685
  * ```
580
686
  *
581
687
  * @param value - The value that the string should end with.
@@ -584,10 +690,10 @@ export default class StringSchema<
584
690
  *
585
691
  * @returns - The schema instance.
586
692
  */
587
- endsWith(value: string, options?: Partial<Omit<StringSchema['__endsWith'], 'value'>>) {
693
+ endsWith(value: string, options?: Partial<Omit<NonNullable<StringSchema['__endsWith']>, 'value'>>) {
588
694
  this.__endsWith = {
589
695
  value,
590
- message: options?.message || `The value should end with ${value}`,
696
+ message: options?.message || `The value should end with ${value}`
591
697
  };
592
698
  return this;
593
699
  }
@@ -602,7 +708,11 @@ export default class StringSchema<
602
708
  * const schema = p.string().startsWith('https://');
603
709
  *
604
710
  * schema.parse('https://example.com'); // { errors: [], parsed: 'https://example.com' }
605
- * schema.parse('http://example.com'); // { errors: [{ code: 'startsWith', message: 'The value should start with https://', path: [] }], parsed: 'http://example.com' }
711
+ * // {
712
+ * // errors: [{ code: 'startsWith', message: 'The value should start with https://', path: [] }],
713
+ * // parsed: 'http://example.com'
714
+ * // }
715
+ * schema.parse('http://example.com');
606
716
  * ```
607
717
  *
608
718
  * @param value - The value that the string should start with.
@@ -611,10 +721,10 @@ export default class StringSchema<
611
721
  *
612
722
  * @returns - The schema instance.
613
723
  */
614
- startsWith(value: string , options?: Partial<Omit<StringSchema['__startsWith'], 'value'>>) {
724
+ startsWith(value: string, options?: Partial<Omit<NonNullable<StringSchema['__startsWith']>, 'value'>>) {
615
725
  this.__startsWith = {
616
726
  value,
617
- message: options?.message || `The value should start with ${value}`,
727
+ message: options?.message || `The value should start with ${value}`
618
728
  };
619
729
  return this;
620
730
  }
@@ -629,7 +739,13 @@ export default class StringSchema<
629
739
  * const schema = p.string().includes('for babies');
630
740
  *
631
741
  * schema.parse('Computer graphics for babies'); // { errors: [], parsed: 'Computer graphics for babies' }
632
- * schema.parse('Learn javascript as you were 5'); // { errors: [{ code: 'includes', message: 'The string value should include the following substring 'for babies', path: [] }], parsed: 'example.org' }
742
+ * // {
743
+ * // errors: [{
744
+ * // code: 'includes',
745
+ * // message: 'The string value should include the following substring 'for babies',
746
+ * // path: []
747
+ * // }], parsed: 'example.org' }
748
+ * schema.parse('Learn javascript as you were 5');
633
749
  * ```
634
750
  *
635
751
  * @param value - The value that the string should include.
@@ -638,10 +754,10 @@ export default class StringSchema<
638
754
  *
639
755
  * @returns - The schema instance.
640
756
  */
641
- includes(value: string, options?: Partial<Omit<StringSchema['__includes'], 'value'>>) {
757
+ includes(value: string, options?: Partial<Omit<NonNullable<StringSchema['__includes']>, 'value'>>) {
642
758
  this.__includes = {
643
759
  value,
644
- message: options?.message || `The string value should include the following substring '${value}'`,
760
+ message: options?.message || `The string value should include the following substring '${value}'`
645
761
  };
646
762
  return this;
647
763
  }
@@ -656,7 +772,15 @@ export default class StringSchema<
656
772
  * const schema = p.string().regex(/^[a-z]+$/);
657
773
  *
658
774
  * schema.parse('abc'); // { errors: [], parsed: 'abc' }
659
- * schema.parse('123'); // { errors: [{ code: 'regex', message: 'The value should match the following regex /^[a-z]+$/', path: [] }], parsed: '123' }
775
+ * // {
776
+ * // errors: [{
777
+ * // code: 'regex',
778
+ * // message: 'The value should match the following regex /^[a-z]+$/',
779
+ * // path: []
780
+ * // }],
781
+ * // parsed: '123'
782
+ * // }
783
+ * schema.parse('123');
660
784
  * ```
661
785
  *
662
786
  * @param value - The regex that the string should match.
@@ -665,16 +789,17 @@ export default class StringSchema<
665
789
  *
666
790
  * @returns - The schema instance.
667
791
  */
668
- regex(value: RegExp, options?: Partial<Omit<StringSchema['__regex'], 'value'>>) {
792
+ regex(value: RegExp, options?: Partial<Omit<NonNullable<StringSchema['__regex']>, 'value'>>) {
669
793
  this.__regex = {
670
794
  value,
671
- message: options?.message || `The value should match the following regex '${value.toString()}'`,
795
+ message: options?.message || `The value should match the following regex '${value.toString()}'`
672
796
  };
673
797
  return this;
674
798
  }
675
799
 
676
800
  /**
677
- * Validates if the string has a maximum length. Use { inclusive: true } to allow the value to have the same length as the maximum length.
801
+ * Validates if the string has a maximum length. Use { inclusive: true } to allow the value to have the same length
802
+ * as the maximum length.
678
803
  *
679
804
  * @example
680
805
  * ```typescript
@@ -683,7 +808,11 @@ export default class StringSchema<
683
808
  * const schema = p.string().maxLength(5);
684
809
  *
685
810
  * schema.parse('12345'); // { errors: [], parsed: '12345' }
686
- * schema.parse('123456'); // { errors: [{ code: 'maxLength', message: 'The value should have a maximum length of 5', path: [] }], parsed: '123
811
+ * // {
812
+ * // errors: [{ code: 'maxLength', message: 'The value should have a maximum length of 5', path: [] }],
813
+ * // parsed: '123
814
+ * // }
815
+ * schema.parse('123456');
687
816
  * ```
688
817
  *
689
818
  * @param value - The maximum length that the string should have.
@@ -693,17 +822,17 @@ export default class StringSchema<
693
822
  *
694
823
  * @returns - The schema instance.
695
824
  */
696
- maxLength(value: number, options?: Partial<Omit<StringSchema['__maxLength'], 'value'>>) {
825
+ maxLength(value: number, options?: Partial<Omit<NonNullable<StringSchema['__maxLength']>, 'value'>>) {
697
826
  this.__maxLength = {
698
827
  value,
699
- message: options?.message || `The value should have a maximum length of ${value}`,
700
- inclusive: typeof options?.inclusive === 'boolean' ? options.inclusive : false,
828
+ message: options?.message || `The value should have a maximum length of ${value}`
701
829
  };
702
830
  return this;
703
831
  }
704
832
 
705
833
  /**
706
- * Validates if the string has a minimum length. Use { inclusive: true } to allow the value to have the same length as the minimum length.
834
+ * Validates if the string has a minimum length. Use { inclusive: true } to allow the value to have the same length
835
+ * as the minimum length.
707
836
  *
708
837
  * @example
709
838
  * ```typescript
@@ -712,7 +841,11 @@ export default class StringSchema<
712
841
  * const schema = p.string().minLength(5);
713
842
  *
714
843
  * schema.parse('12345'); // { errors: [], parsed: '12345' }
715
- * schema.parse('1234'); // { errors: [{ code: 'minLength', message: 'The value should have a minimum length of 5', path: [] }], parsed: '1234' }
844
+ * // {
845
+ * // errors: [{ code: 'minLength', message: 'The value should have a minimum length of 5', path: [] }],
846
+ * // parsed: '1234'
847
+ * // }
848
+ * schema.parse('1234');
716
849
  * ```
717
850
  *
718
851
  * @param value - The minimum length that the string should have.
@@ -722,11 +855,10 @@ export default class StringSchema<
722
855
  *
723
856
  * @returns - The schema instance.
724
857
  */
725
- minLength(value: number, options?: Partial<Omit<StringSchema['__minLength'], 'value'>>) {
858
+ minLength(value: number, options?: Partial<Omit<NonNullable<StringSchema['__minLength']>, 'value'>>) {
726
859
  this.__minLength = {
727
860
  value,
728
- message: options?.message || `The value should have a minimum length of ${value}`,
729
- inclusive: typeof options?.inclusive === 'boolean' ? options.inclusive : false,
861
+ message: options?.message || `The value should have a minimum length of ${value}`
730
862
  };
731
863
  return this;
732
864
  }
@@ -740,22 +872,23 @@ export default class StringSchema<
740
872
  *
741
873
  * const schema = p.string().uuid();
742
874
  *
743
- * schema.parse('550e8400-e29b-41d4-a716-446655440000'); // { errors: [], parsed: '550e8400-e29b-41d4-a716-446655440000' }
875
+ * // { errors: [], parsed: '550e8400-e29b-41d4-a716-446655440000' }
876
+ * schema.parse('550e8400-e29b-41d4-a716-446655440000');
744
877
  * ```
745
878
  *
746
879
  * @param options - The options for the uuid function.
747
- * @param options.message - The message to be shown when the value is not a valid UUID. Defaults to 'The value should be a valid UUID'.
880
+ * @param options.message - The message to be shown when the value is not a valid UUID. Defaults to
881
+ * 'The value should be a valid UUID'.
748
882
  *
749
883
  * @returns - The schema instance.
750
884
  */
751
885
  uuid(options?: StringSchema['__uuid']) {
752
886
  this.__uuid = {
753
- message: options?.message || 'The value should be a valid UUID',
887
+ message: options?.message || 'The value should be a valid UUID'
754
888
  };
755
889
  return this;
756
890
  }
757
891
 
758
-
759
892
  /**
760
893
  * Validates if the string is a valid email or not
761
894
  *
@@ -770,14 +903,15 @@ export default class StringSchema<
770
903
  * ```
771
904
  *
772
905
  * @param options - The options for the email function.
773
- * @param options.message - The message to be shown when the value is not a valid email. Defaults to 'The value should be a valid email'.
906
+ * @param options.message - The message to be shown when the value is not a valid email.
907
+ * Defaults to 'The value should be a valid email'.
774
908
  *
775
909
  * @returns - The schema instance.
776
910
  */
777
911
  email(options?: StringSchema['__email']) {
778
912
  this.__email = {
779
- message: options?.message || 'The value should be a valid email',
780
- }
913
+ message: options?.message || 'The value should be a valid email'
914
+ };
781
915
  return this;
782
916
  }
783
917
 
@@ -792,13 +926,6 @@ export default class StringSchema<
792
926
  },
793
927
  TDefinitions
794
928
  >();
795
- const adapterInstance = getDefaultAdapter();
796
-
797
- returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
798
- transformed: false,
799
- adapter: adapterInstance,
800
- schemas: [],
801
- };
802
929
 
803
930
  return returnValue;
804
931
  }