@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
@@ -17,7 +17,6 @@ _export(exports, {
17
17
  }
18
18
  });
19
19
  var _schema = /*#__PURE__*/ _interop_require_default(require("./schema"));
20
- var _conf = require("../conf");
21
20
  var _convertfromstring = /*#__PURE__*/ _interop_require_default(require("../parsers/convert-from-string"));
22
21
  var _utils = require("../utils");
23
22
  var _boolean = require("../validators/boolean");
@@ -285,6 +284,16 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
285
284
  _define_property(_assert_this_initialized(_this), "__trueValues", void 0);
286
285
  _define_property(_assert_this_initialized(_this), "__falseValues", void 0);
287
286
  _define_property(_assert_this_initialized(_this), "__is", void 0);
287
+ _define_property(_assert_this_initialized(_this), "__type", {
288
+ message: 'Invalid type',
289
+ check: function(value) {
290
+ if (typeof value === 'string' && _this.__allowString) return true;
291
+ if (typeof value === 'number' && _this.__allowNumber) return true;
292
+ if (Array.isArray(_this.__trueValues) && _this.__trueValues.includes(value)) return true;
293
+ if (Array.isArray(_this.__falseValues) && _this.__falseValues.includes(value)) return true;
294
+ return typeof value === 'boolean';
295
+ }
296
+ });
288
297
  return _this;
289
298
  }
290
299
  _create_class(BooleanSchema, [
@@ -302,16 +311,19 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
302
311
  return [
303
312
  2,
304
313
  (0, _utils.defaultTransform)('boolean', _this, adapter, adapter.boolean, function() {
314
+ var _this___is;
305
315
  return {
306
316
  parsers: {
307
317
  allowString: _this.__allowString,
308
318
  allowNumber: _this.__allowNumber,
309
- is: _this.__is.value,
319
+ // eslint-disable-next-line ts/no-unnecessary-condition
320
+ is: (_this___is = _this.__is) === null || _this___is === void 0 ? void 0 : _this___is.value,
310
321
  trueValues: _this.__trueValues,
311
322
  falseValues: _this.__falseValues,
312
323
  nullable: _this.__nullable.allow,
313
324
  optional: _this.__optional.allow
314
325
  },
326
+ type: _this.__type,
315
327
  is: _this.__is,
316
328
  nullable: _this.__nullable,
317
329
  optional: _this.__optional
@@ -339,7 +351,7 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
339
351
  return function(adapter) {
340
352
  return _ref.apply(this, arguments);
341
353
  };
342
- }(), _this.__transformedSchemas, options, 'boolean')
354
+ }(), _this, _this.__transformedSchemas, options, 'boolean')
343
355
  ];
344
356
  });
345
357
  })();
@@ -347,7 +359,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
347
359
  },
348
360
  {
349
361
  /**
350
- * 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.
362
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something that
363
+ * is not supported by default by the schema adapter.
351
364
  *
352
365
  * @example
353
366
  * ```typescript
@@ -359,7 +372,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
359
372
  *
360
373
  * const { errors, parsed } = await numberSchema.parse(-1);
361
374
  *
362
- * console.log(errors); // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
375
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
376
+ * console.log(errors);
363
377
  * ```
364
378
  *
365
379
  * @param refinementCallback - The callback that will be called to validate the value.
@@ -403,8 +417,28 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
403
417
  },
404
418
  {
405
419
  /**
406
- * 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
407
- * the { message: 'Your custom message', allow: false } on the options.
420
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
421
+ *
422
+ * ```typescript
423
+ * p.string().optional({ message: 'This value cannot be null', allow: false })
424
+ * ```
425
+ *
426
+ * @param options - The options of nonOptional function
427
+ * @param options.message - A custom message if the value is undefined.
428
+ *
429
+ * @returns - The schema.
430
+ */ key: "nonOptional",
431
+ value: function nonOptional(options) {
432
+ return _get(_get_prototype_of(BooleanSchema.prototype), "optional", this).call(this, {
433
+ message: options === null || options === void 0 ? void 0 : options.message,
434
+ allow: false
435
+ });
436
+ }
437
+ },
438
+ {
439
+ /**
440
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value is
441
+ * NULL by setting the { message: 'Your custom message', allow: false } on the options.
408
442
  *
409
443
  * @example
410
444
  * ```typescript
@@ -433,14 +467,35 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
433
467
  },
434
468
  {
435
469
  /**
436
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep that way
437
- * otherwise it will set the value to undefined after it's validated.
470
+ * Just adds a message when the value is null. It's just a syntax sugar for
471
+ *
472
+ * ```typescript
473
+ * p.string().nullable({ message: 'This value cannot be null', allow: false })
474
+ * ```
475
+ *
476
+ * @param options - The options of nonNullable function
477
+ * @param options.message - A custom message if the value is null.
478
+ *
479
+ * @returns - The schema.
480
+ */ key: "nonNullable",
481
+ value: function nonNullable(options) {
482
+ return _get(_get_prototype_of(BooleanSchema.prototype), "nullable", this).call(this, {
483
+ message: (options === null || options === void 0 ? void 0 : options.message) || '',
484
+ allow: false
485
+ });
486
+ }
487
+ },
488
+ {
489
+ /**
490
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
491
+ * that way otherwise it will set the value to undefined after it's validated.
438
492
  * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
439
493
  * function. This will remove the value from the representation of the schema.
440
494
  *
441
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
442
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
443
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
495
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
496
+ * function.But if you want to remove the value from the internal representation, you can pass the argument
497
+ * `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
498
+ * the argument `toRepresentation` as true as well.
444
499
  *
445
500
  * @example
446
501
  * ```typescript
@@ -462,9 +517,11 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
462
517
  * ```
463
518
  *
464
519
  *
465
- * @param args - By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
466
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
467
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
520
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
521
+ * the {@link data} function. But if you want to remove the value from the internal representation, you can pass the
522
+ * argument `toInternal` as true.
523
+ * Then if you still want to remove the value from the representation, you will need to pass the argument
524
+ * `toRepresentation` as true as well.
468
525
  *
469
526
  * @returns The schema.
470
527
  */ key: "omit",
@@ -474,9 +531,9 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
474
531
  },
475
532
  {
476
533
  /**
477
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external source
478
- * like a database. You should always return the schema after you save the value, that way we will always have the correct type
479
- * of the schema after the save operation.
534
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
535
+ * source like a database. You should always return the schema after you save the value, that way we will always have
536
+ * the correct type of the schema after the save operation.
480
537
  *
481
538
  * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
482
539
  *
@@ -521,7 +578,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
521
578
  },
522
579
  {
523
580
  /**
524
- * 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.
581
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
582
+ * value will be used.
525
583
  *
526
584
  * @example
527
585
  * ```typescript
@@ -540,8 +598,9 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
540
598
  },
541
599
  {
542
600
  /**
543
- * 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
544
- * the custom schema your own way. Our API does not support passthrough? No problem, you can use this function to customize the zod schema.
601
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
602
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
603
+ * No problem, you can use this function to customize the zod schema.
545
604
  *
546
605
  * @example
547
606
  * ```typescript
@@ -552,13 +611,13 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
552
611
  * });
553
612
  *
554
613
  * const { errors, parsed } = await numberSchema.parse(-1);
555
- *
556
- * console.log(errors); // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
614
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
615
+ * console.log(errors);
557
616
  * ```
558
617
  *
559
618
  * @param callback - The callback that will be called to customize the schema.
560
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to compile the underlying schema
561
- * to a string so you can save it for future runs.
619
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
620
+ * compile the underlying schema to a string so you can save it for future runs.
562
621
  *
563
622
  * @returns The schema.
564
623
  */ key: "extends",
@@ -568,9 +627,9 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
568
627
  },
569
628
  {
570
629
  /**
571
- * 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
572
- * 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.
573
- * The schema maps to itself.
630
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
631
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
632
+ * whatever. Another use case is when you want to return deeply nested recursive data. The schema maps to itself.
574
633
  *
575
634
  * @example
576
635
  * ```typescript
@@ -616,8 +675,9 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
616
675
  },
617
676
  {
618
677
  /**
619
- * 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
620
- * 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.
678
+ * This function is used to transform the value to the internal representation of the schema. This is useful when
679
+ * you want to transform the value to a type that the schema adapter can understand. For example, you might want
680
+ * to transform a string to a date. This is the function you use.
621
681
  *
622
682
  * @example
623
683
  * ```typescript
@@ -653,8 +713,9 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
653
713
  },
654
714
  {
655
715
  /**
656
- * 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
657
- * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
716
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
717
+ * you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
718
+ * that the schema adapter can understand.
658
719
  *
659
720
  * @example
660
721
  * ```
@@ -678,7 +739,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
678
739
  },
679
740
  {
680
741
  /**
681
- * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the result to be a string as well.
742
+ * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
743
+ * result to be a string as well.
682
744
  *
683
745
  * @example
684
746
  * ```ts
@@ -700,7 +762,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
700
762
  },
701
763
  {
702
764
  /**
703
- * Allows you to set the values that will be considered as true. This is useful when you have a string that can be 'T' or 'F' for example.
765
+ * Allows you to set the values that will be considered as true. This is useful when you have a string that can be
766
+ * 'T' or 'F' for example.
704
767
  *
705
768
  * @example
706
769
  * ```ts
@@ -716,9 +779,10 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
716
779
  this.__trueValues = values;
717
780
  this.__parsers.medium.set('trueValues', function(value) {
718
781
  var valueExistsInList = values.includes(value);
782
+ console.log('trueValues', valueExistsInList);
719
783
  return {
720
784
  preventNextParsers: valueExistsInList,
721
- value: valueExistsInList
785
+ value: valueExistsInList ? true : value
722
786
  };
723
787
  });
724
788
  return this;
@@ -726,7 +790,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
726
790
  },
727
791
  {
728
792
  /**
729
- * Allows you to set the values that will be considered as false. This is useful when you have a string that can be 'N' or 0 for example.
793
+ * Allows you to set the values that will be considered as false. This is useful when you have a string that can
794
+ * be 'N' or 0 for example.
730
795
  *
731
796
  * @example
732
797
  * ```ts
@@ -742,9 +807,10 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
742
807
  this.__falseValues = values;
743
808
  this.__parsers.medium.set('falseValues', function(value) {
744
809
  var valueExistsInList = values.includes(value);
810
+ console.log('falseValues', valueExistsInList);
745
811
  return {
746
812
  preventNextParsers: valueExistsInList,
747
- value: !valueExistsInList
813
+ value: valueExistsInList ? false : value
748
814
  };
749
815
  });
750
816
  return this;
@@ -752,7 +818,8 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
752
818
  },
753
819
  {
754
820
  /**
755
- * This will allow the value to be a number, it does not validate, it just parses inputs as number and allows the result to be a string as well.
821
+ * This will allow the value to be a number, it does not validate, it just parses inputs as number and allows the
822
+ * result to be a string as well.
756
823
  *
757
824
  * @example
758
825
  * ```ts
@@ -809,12 +876,6 @@ var BooleanSchema = /*#__PURE__*/ function(Schema) {
809
876
  key: "new",
810
877
  value: function _new() {
811
878
  var returnValue = new BooleanSchema();
812
- var adapterInstance = (0, _conf.getDefaultAdapter)();
813
- returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
814
- transformed: false,
815
- adapter: adapterInstance,
816
- schemas: []
817
- };
818
879
  return returnValue;
819
880
  }
820
881
  }
@@ -17,7 +17,6 @@ _export(exports, {
17
17
  }
18
18
  });
19
19
  var _schema = /*#__PURE__*/ _interop_require_default(require("./schema"));
20
- var _conf = require("../conf");
21
20
  var _utils = require("../utils");
22
21
  var _datetime = require("../validators/datetime");
23
22
  var _schema1 = require("../validators/schema");
@@ -123,6 +122,13 @@ function _inherits(subClass, superClass) {
123
122
  });
124
123
  if (superClass) _set_prototype_of(subClass, superClass);
125
124
  }
125
+ function _instanceof(left, right) {
126
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
127
+ return !!right[Symbol.hasInstance](left);
128
+ } else {
129
+ return left instanceof right;
130
+ }
131
+ }
126
132
  function _interop_require_default(obj) {
127
133
  return obj && obj.__esModule ? obj : {
128
134
  default: obj
@@ -282,6 +288,17 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
282
288
  _define_property(_assert_this_initialized(_this), "__allowString", void 0);
283
289
  _define_property(_assert_this_initialized(_this), "__above", void 0);
284
290
  _define_property(_assert_this_initialized(_this), "__below", void 0);
291
+ _define_property(_assert_this_initialized(_this), "__type", {
292
+ message: 'Invalid type',
293
+ check: function(value) {
294
+ if (typeof value === 'string') {
295
+ var valueAsDate = new Date(value);
296
+ if (isNaN(valueAsDate.getTime())) return false;
297
+ return true;
298
+ }
299
+ return _instanceof(value, Date);
300
+ }
301
+ });
285
302
  return _this;
286
303
  }
287
304
  _create_class(DatetimeSchema, [
@@ -305,6 +322,7 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
305
322
  above: _this.__above,
306
323
  nullable: _this.__nullable,
307
324
  optional: _this.__optional,
325
+ type: _this.__type,
308
326
  parsers: {
309
327
  nullable: _this.__nullable.allow,
310
328
  optional: _this.__optional.allow
@@ -335,7 +353,7 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
335
353
  return function(adapter) {
336
354
  return _ref.apply(this, arguments);
337
355
  };
338
- }(), _this.__transformedSchemas, options, 'datetime')
356
+ }(), _this, _this.__transformedSchemas, options, 'datetime')
339
357
  ];
340
358
  });
341
359
  })();
@@ -343,7 +361,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
343
361
  },
344
362
  {
345
363
  /**
346
- * 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.
364
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something
365
+ * that is not supported by default by the schema adapter.
347
366
  *
348
367
  * @example
349
368
  * ```typescript
@@ -355,7 +374,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
355
374
  *
356
375
  * const { errors, parsed } = await numberSchema.parse(-1);
357
376
  *
358
- * console.log(errors); // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
377
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
378
+ * console.log(errors);
359
379
  * ```
360
380
  *
361
381
  * @param refinementCallback - The callback that will be called to validate the value.
@@ -399,8 +419,28 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
399
419
  },
400
420
  {
401
421
  /**
402
- * 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
403
- * the { message: 'Your custom message', allow: false } on the options.
422
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
423
+ *
424
+ * ```typescript
425
+ * p.datetime().optional({ message: 'This value should be defined', allow: false })
426
+ * ```
427
+ *
428
+ * @param options - The options of nonOptional function
429
+ * @param options.message - A custom message if the value is undefined.
430
+ *
431
+ * @returns - The schema.
432
+ */ key: "nonOptional",
433
+ value: function nonOptional(options) {
434
+ return _get(_get_prototype_of(DatetimeSchema.prototype), "optional", this).call(this, {
435
+ message: options === null || options === void 0 ? void 0 : options.message,
436
+ allow: false
437
+ });
438
+ }
439
+ },
440
+ {
441
+ /**
442
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
443
+ * is NULL by setting the { message: 'Your custom message', allow: false } on the options.
404
444
  *
405
445
  * @example
406
446
  * ```typescript
@@ -429,14 +469,35 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
429
469
  },
430
470
  {
431
471
  /**
432
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep that way
433
- * otherwise it will set the value to undefined after it's validated.
472
+ * Just adds a message when the value is null. It's just a syntax sugar for
473
+ *
474
+ * ```typescript
475
+ * p.datetime().nullable({ message: 'This value cannot be null', allow: false })
476
+ * ```
477
+ *
478
+ * @param options - The options of nonNullable function
479
+ * @param options.message - A custom message if the value is null.
480
+ *
481
+ * @returns - The schema.
482
+ */ key: "nonNullable",
483
+ value: function nonNullable(options) {
484
+ return _get(_get_prototype_of(DatetimeSchema.prototype), "nullable", this).call(this, {
485
+ message: (options === null || options === void 0 ? void 0 : options.message) || '',
486
+ allow: false
487
+ });
488
+ }
489
+ },
490
+ {
491
+ /**
492
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
493
+ * that way otherwise it will set the value to undefined after it's validated.
434
494
  * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
435
495
  * function. This will remove the value from the representation of the schema.
436
496
  *
437
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
438
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
439
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
497
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
498
+ * function.But if you want to remove the value from the internal representation, you can pass the argument
499
+ * `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
500
+ * the argument `toRepresentation` as true as well.
440
501
  *
441
502
  * @example
442
503
  * ```typescript
@@ -458,9 +519,11 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
458
519
  * ```
459
520
  *
460
521
  *
461
- * @param args - By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
462
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
463
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
522
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
523
+ * the {@link data} function.
524
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as
525
+ * true. Then if you still want to remove the value from the representation, you will need to pass the argument
526
+ * `toRepresentation` as true as well.
464
527
  *
465
528
  * @returns The schema.
466
529
  */ key: "omit",
@@ -470,9 +533,9 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
470
533
  },
471
534
  {
472
535
  /**
473
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external source
474
- * like a database. You should always return the schema after you save the value, that way we will always have the correct type
475
- * of the schema after the save operation.
536
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
537
+ * source like a database. You should always return the schema after you save the value, that way we will always have
538
+ * the correct type of the schema after the save operation.
476
539
  *
477
540
  * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
478
541
  *
@@ -517,7 +580,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
517
580
  },
518
581
  {
519
582
  /**
520
- * 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.
583
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
584
+ * value will be used.
521
585
  *
522
586
  * @example
523
587
  * ```typescript
@@ -536,8 +600,9 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
536
600
  },
537
601
  {
538
602
  /**
539
- * 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
540
- * the custom schema your own way. Our API does not support passthrough? No problem, you can use this function to customize the zod schema.
603
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
604
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
605
+ * No problem, you can use this function to customize the zod schema.
541
606
  *
542
607
  * @example
543
608
  * ```typescript
@@ -549,12 +614,13 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
549
614
  *
550
615
  * const { errors, parsed } = await numberSchema.parse(-1);
551
616
  *
552
- * console.log(errors); // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
617
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
618
+ * console.log(errors);
553
619
  * ```
554
620
  *
555
621
  * @param callback - The callback that will be called to customize the schema.
556
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to compile the underlying schema
557
- * to a string so you can save it for future runs.
622
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
623
+ * compile the underlying schema to a string so you can save it for future runs.
558
624
  *
559
625
  * @returns The schema.
560
626
  */ key: "extends",
@@ -564,8 +630,9 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
564
630
  },
565
631
  {
566
632
  /**
567
- * 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
568
- * 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.
633
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
634
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
635
+ * whatever. Another use case is when you want to return deeply nested recursive data.
569
636
  * The schema maps to itself.
570
637
  *
571
638
  * @example
@@ -612,8 +679,9 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
612
679
  },
613
680
  {
614
681
  /**
615
- * 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
616
- * 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.
682
+ * This function is used to transform the value to the internal representation of the schema. This is useful when you
683
+ * want to transform the value to a type that the schema adapter can understand. For example, you might want to
684
+ * transform a string to a date. This is the function you use.
617
685
  *
618
686
  * @example
619
687
  * ```typescript
@@ -649,8 +717,9 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
649
717
  },
650
718
  {
651
719
  /**
652
- * 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
653
- * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
720
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
721
+ * you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
722
+ * that the schema adapter can understand.
654
723
  *
655
724
  * @example
656
725
  * ```
@@ -674,7 +743,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
674
743
  },
675
744
  {
676
745
  /**
677
- * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the result to be a string as well.
746
+ * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
747
+ * result to be a string as well.
678
748
  *
679
749
  * @example
680
750
  * ```typescript
@@ -707,7 +777,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
707
777
  *
708
778
  * @param value - The value that we are comparing against.
709
779
  * @param options - The options that we are passing to the validator.
710
- * @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the specified date.
780
+ * @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to
781
+ * the specified date.
711
782
  * @param options.message - The message that we are returning if the value is not above the specified date.
712
783
  *
713
784
  * @returns - The schema instance
@@ -740,7 +811,8 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
740
811
  *
741
812
  * @param value - The value that we are comparing against.
742
813
  * @param options - The options that we are passing to the validator.
743
- * @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the specified date.
814
+ * @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the
815
+ * specified date.
744
816
  * @param options.message - The message that we are returning if the value is not above the specified date.
745
817
  *
746
818
  * @returns - The schema instance
@@ -761,12 +833,6 @@ var DatetimeSchema = /*#__PURE__*/ function(Schema) {
761
833
  key: "new",
762
834
  value: function _new() {
763
835
  var returnValue = new DatetimeSchema();
764
- var adapterInstance = (0, _conf.getDefaultAdapter)();
765
- returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
766
- transformed: false,
767
- adapter: adapterInstance,
768
- schemas: []
769
- };
770
836
  return returnValue;
771
837
  }
772
838
  }