@palmares/schemas 0.0.1 → 0.1.1

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 (175) hide show
  1. package/.turbo/turbo-build$colon$watch.log +12 -410
  2. package/.turbo/turbo-build.log +13 -4
  3. package/CHANGELOG.md +26 -0
  4. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
  5. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
  6. package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
  7. package/__tests__/.drizzle/schema.ts +35 -0
  8. package/__tests__/drizzle.config.ts +11 -0
  9. package/__tests__/eslint.config.js +10 -0
  10. package/__tests__/manage.ts +5 -0
  11. package/__tests__/node_modules/.bin/drizzle-kit +17 -0
  12. package/__tests__/node_modules/.bin/esbuild +14 -0
  13. package/__tests__/node_modules/.bin/tsc +17 -0
  14. package/__tests__/node_modules/.bin/tsserver +17 -0
  15. package/__tests__/node_modules/.bin/tsx +17 -0
  16. package/__tests__/package.json +36 -0
  17. package/__tests__/sqlite.db +0 -0
  18. package/__tests__/src/core/array.test.ts +130 -0
  19. package/__tests__/src/core/boolean.test.ts +66 -0
  20. package/__tests__/src/core/datetime.test.ts +102 -0
  21. package/__tests__/src/core/index.ts +35 -0
  22. package/__tests__/src/core/model.test.ts +260 -0
  23. package/__tests__/src/core/models.ts +50 -0
  24. package/__tests__/src/core/numbers.test.ts +177 -0
  25. package/__tests__/src/core/object.test.ts +198 -0
  26. package/__tests__/src/core/string.test.ts +222 -0
  27. package/__tests__/src/core/test.test.ts +59 -0
  28. package/__tests__/src/core/types.test.ts +97 -0
  29. package/__tests__/src/core/union.test.ts +99 -0
  30. package/__tests__/src/settings.ts +71 -0
  31. package/__tests__/tsconfig.json +11 -0
  32. package/dist/cjs/src/adapter/fields/index.js +2 -2
  33. package/dist/cjs/src/adapter/fields/object.js +9 -0
  34. package/dist/cjs/src/adapter/index.js +1 -0
  35. package/dist/cjs/src/constants.js +1 -7
  36. package/dist/cjs/src/domain.js +146 -1
  37. package/dist/cjs/src/index.js +69 -74
  38. package/dist/cjs/src/model.js +206 -206
  39. package/dist/cjs/src/schema/array.js +185 -58
  40. package/dist/cjs/src/schema/boolean.js +105 -44
  41. package/dist/cjs/src/schema/datetime.js +104 -38
  42. package/dist/cjs/src/schema/number.js +134 -114
  43. package/dist/cjs/src/schema/object.js +106 -43
  44. package/dist/cjs/src/schema/schema.js +123 -75
  45. package/dist/cjs/src/schema/string.js +152 -58
  46. package/dist/cjs/src/schema/union.js +412 -290
  47. package/dist/cjs/src/utils.js +42 -15
  48. package/dist/cjs/src/validators/array.js +6 -1
  49. package/dist/cjs/src/validators/boolean.js +2 -0
  50. package/dist/cjs/src/validators/datetime.js +4 -0
  51. package/dist/cjs/src/validators/number.js +12 -40
  52. package/dist/cjs/src/validators/object.js +1 -0
  53. package/dist/cjs/src/validators/schema.js +5 -1
  54. package/dist/cjs/src/validators/string.js +30 -2
  55. package/dist/cjs/src/validators/union.js +5 -4
  56. package/dist/cjs/src/validators/utils.js +99 -27
  57. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
  58. package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
  59. package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
  60. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
  61. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
  62. package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
  63. package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
  64. package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
  65. package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
  66. package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
  67. package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
  68. package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
  69. package/dist/cjs/types/adapter/index.d.ts +1 -0
  70. package/dist/cjs/types/adapter/index.d.ts.map +1 -1
  71. package/dist/cjs/types/adapter/types.d.ts +28 -18
  72. package/dist/cjs/types/adapter/types.d.ts.map +1 -1
  73. package/dist/cjs/types/constants.d.ts +0 -1
  74. package/dist/cjs/types/constants.d.ts.map +1 -1
  75. package/dist/cjs/types/domain.d.ts +5 -4
  76. package/dist/cjs/types/domain.d.ts.map +1 -1
  77. package/dist/cjs/types/index.d.ts +78 -55
  78. package/dist/cjs/types/index.d.ts.map +1 -1
  79. package/dist/cjs/types/model.d.ts +17 -17
  80. package/dist/cjs/types/model.d.ts.map +1 -1
  81. package/dist/cjs/types/schema/array.d.ts +168 -47
  82. package/dist/cjs/types/schema/array.d.ts.map +1 -1
  83. package/dist/cjs/types/schema/boolean.d.ts +103 -44
  84. package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
  85. package/dist/cjs/types/schema/datetime.d.ts +90 -30
  86. package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
  87. package/dist/cjs/types/schema/number.d.ts +133 -125
  88. package/dist/cjs/types/schema/number.d.ts.map +1 -1
  89. package/dist/cjs/types/schema/object.d.ts +104 -35
  90. package/dist/cjs/types/schema/object.d.ts.map +1 -1
  91. package/dist/cjs/types/schema/schema.d.ts +62 -44
  92. package/dist/cjs/types/schema/schema.d.ts.map +1 -1
  93. package/dist/cjs/types/schema/string.d.ts +152 -65
  94. package/dist/cjs/types/schema/string.d.ts.map +1 -1
  95. package/dist/cjs/types/schema/types.d.ts +11 -2
  96. package/dist/cjs/types/schema/types.d.ts.map +1 -1
  97. package/dist/cjs/types/schema/union.d.ts +133 -40
  98. package/dist/cjs/types/schema/union.d.ts.map +1 -1
  99. package/dist/cjs/types/types.d.ts +35 -0
  100. package/dist/cjs/types/types.d.ts.map +1 -1
  101. package/dist/cjs/types/utils.d.ts +41 -27
  102. package/dist/cjs/types/utils.d.ts.map +1 -1
  103. package/dist/cjs/types/validators/array.d.ts.map +1 -1
  104. package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
  105. package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
  106. package/dist/cjs/types/validators/number.d.ts +5 -6
  107. package/dist/cjs/types/validators/number.d.ts.map +1 -1
  108. package/dist/cjs/types/validators/object.d.ts.map +1 -1
  109. package/dist/cjs/types/validators/schema.d.ts +2 -2
  110. package/dist/cjs/types/validators/schema.d.ts.map +1 -1
  111. package/dist/cjs/types/validators/string.d.ts +9 -9
  112. package/dist/cjs/types/validators/string.d.ts.map +1 -1
  113. package/dist/cjs/types/validators/utils.d.ts +44 -27
  114. package/dist/cjs/types/validators/utils.d.ts.map +1 -1
  115. package/dist/esm/src/adapter/fields/index.js +2 -2
  116. package/dist/esm/src/adapter/fields/object.js +6 -0
  117. package/dist/esm/src/adapter/index.js +1 -0
  118. package/dist/esm/src/constants.js +1 -2
  119. package/dist/esm/src/domain.js +11 -1
  120. package/dist/esm/src/index.js +38 -73
  121. package/dist/esm/src/model.js +83 -78
  122. package/dist/esm/src/schema/array.js +136 -54
  123. package/dist/esm/src/schema/boolean.js +98 -44
  124. package/dist/esm/src/schema/datetime.js +91 -38
  125. package/dist/esm/src/schema/number.js +127 -110
  126. package/dist/esm/src/schema/object.js +98 -43
  127. package/dist/esm/src/schema/schema.js +102 -67
  128. package/dist/esm/src/schema/string.js +147 -59
  129. package/dist/esm/src/schema/union.js +119 -40
  130. package/dist/esm/src/types.js +14 -1
  131. package/dist/esm/src/utils.js +56 -27
  132. package/dist/esm/src/validators/array.js +6 -1
  133. package/dist/esm/src/validators/boolean.js +2 -0
  134. package/dist/esm/src/validators/datetime.js +4 -0
  135. package/dist/esm/src/validators/number.js +9 -23
  136. package/dist/esm/src/validators/object.js +1 -0
  137. package/dist/esm/src/validators/schema.js +5 -1
  138. package/dist/esm/src/validators/string.js +30 -2
  139. package/dist/esm/src/validators/union.js +5 -4
  140. package/dist/esm/src/validators/utils.js +62 -36
  141. package/package.json +3 -3
  142. package/src/adapter/fields/array.ts +2 -2
  143. package/src/adapter/fields/boolean.ts +3 -8
  144. package/src/adapter/fields/datetime.ts +3 -9
  145. package/src/adapter/fields/index.ts +11 -11
  146. package/src/adapter/fields/number.ts +3 -9
  147. package/src/adapter/fields/object.ts +13 -10
  148. package/src/adapter/fields/string.ts +3 -9
  149. package/src/adapter/fields/union.ts +3 -9
  150. package/src/adapter/index.ts +1 -0
  151. package/src/adapter/types.ts +60 -45
  152. package/src/constants.ts +1 -3
  153. package/src/domain.ts +15 -1
  154. package/src/index.ts +189 -211
  155. package/src/model.ts +119 -115
  156. package/src/schema/array.ts +274 -90
  157. package/src/schema/boolean.ts +145 -60
  158. package/src/schema/datetime.ts +133 -49
  159. package/src/schema/number.ts +210 -173
  160. package/src/schema/object.ts +167 -74
  161. package/src/schema/schema.ts +205 -126
  162. package/src/schema/string.ts +221 -94
  163. package/src/schema/types.ts +44 -16
  164. package/src/schema/union.ts +193 -68
  165. package/src/types.ts +53 -0
  166. package/src/utils.ts +115 -57
  167. package/src/validators/array.ts +46 -27
  168. package/src/validators/boolean.ts +13 -7
  169. package/src/validators/datetime.ts +24 -16
  170. package/src/validators/number.ts +53 -63
  171. package/src/validators/object.ts +6 -5
  172. package/src/validators/schema.ts +33 -25
  173. package/src/validators/string.ts +122 -59
  174. package/src/validators/union.ts +8 -8
  175. package/src/validators/utils.ts +67 -42
@@ -17,10 +17,11 @@ _export(exports, {
17
17
  }
18
18
  });
19
19
  var _schema = /*#__PURE__*/ _interop_require_default(require("./schema"));
20
- var _conf = require("../conf");
21
20
  var _constants = require("../constants");
21
+ var _parsers = require("../parsers");
22
22
  var _utils = require("../utils");
23
23
  var _number = require("../validators/number");
24
+ var _schema1 = require("../validators/schema");
24
25
  function _assert_this_initialized(self) {
25
26
  if (self === void 0) {
26
27
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -279,14 +280,21 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
279
280
  _class_call_check(this, NumberSchema);
280
281
  var _this;
281
282
  _this = _super.apply(this, arguments);
283
+ _define_property(_assert_this_initialized(_this), "__allowString", void 0);
282
284
  _define_property(_assert_this_initialized(_this), "__is", void 0);
283
285
  _define_property(_assert_this_initialized(_this), "__integer", void 0);
284
286
  _define_property(_assert_this_initialized(_this), "__maxDigits", void 0);
285
287
  _define_property(_assert_this_initialized(_this), "__decimalPlaces", void 0);
286
288
  _define_property(_assert_this_initialized(_this), "__max", void 0);
287
289
  _define_property(_assert_this_initialized(_this), "__min", void 0);
288
- _define_property(_assert_this_initialized(_this), "__allowNegative", void 0);
289
- _define_property(_assert_this_initialized(_this), "__allowPositive", void 0);
290
+ _define_property(_assert_this_initialized(_this), "__type", {
291
+ message: 'Invalid type',
292
+ check: function(value) {
293
+ var isNumber = new RegExp('^-?\\d*(\\.\\d+)?$').test(value);
294
+ if (typeof value === 'string' && _this.__allowString && isNumber) return true;
295
+ return typeof value === 'number';
296
+ }
297
+ });
290
298
  return _this;
291
299
  }
292
300
  _create_class(NumberSchema, [
@@ -307,22 +315,28 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
307
315
  return {
308
316
  is: _this.__is,
309
317
  min: _this.__min,
310
- allowNegative: _this.__allowNegative,
311
- allowPositive: _this.__allowPositive,
312
318
  max: _this.__max,
313
319
  integer: _this.__integer,
314
320
  optional: _this.__optional,
315
321
  nullable: _this.__nullable,
316
322
  maxDigits: _this.__maxDigits,
317
323
  decimalPlaces: _this.__decimalPlaces,
324
+ type: _this.__type,
318
325
  parsers: {
326
+ allowString: _this.__allowString,
319
327
  nullable: _this.__nullable.allow,
320
328
  optional: _this.__optional.allow
321
329
  }
322
330
  };
323
331
  }, {
324
332
  max: _number.max,
325
- min: _number.min
333
+ min: _number.min,
334
+ maxDigits: _number.maxDigits,
335
+ is: _schema1.is,
336
+ optional: _schema1.optional,
337
+ nullable: _schema1.nullable,
338
+ decimalPlaces: _number.decimalPlaces,
339
+ integer: _number.integer
326
340
  }, {
327
341
  validatorsIfFallbackOrNotSupported: (0, _number.numberValidation)(),
328
342
  shouldAddStringVersion: options.shouldAddStringVersion,
@@ -342,7 +356,7 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
342
356
  return function(adapter) {
343
357
  return _ref.apply(this, arguments);
344
358
  };
345
- }(), _this.__transformedSchemas, options, 'number')
359
+ }(), _this, _this.__transformedSchemas, options, 'number')
346
360
  ];
347
361
  });
348
362
  })();
@@ -350,7 +364,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
350
364
  },
351
365
  {
352
366
  /**
353
- * 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.
367
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something
368
+ * that is not supported by default by the schema adapter.
354
369
  *
355
370
  * @example
356
371
  * ```typescript
@@ -362,7 +377,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
362
377
  *
363
378
  * const { errors, parsed } = await numberSchema.parse(-1);
364
379
  *
365
- * console.log(errors); // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
380
+ * console.log(errors);
381
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
366
382
  * ```
367
383
  *
368
384
  * @param refinementCallback - The callback that will be called to validate the value.
@@ -406,8 +422,28 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
406
422
  },
407
423
  {
408
424
  /**
409
- * 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
410
- * the { message: 'Your custom message', allow: false } on the options.
425
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
426
+ *
427
+ * ```typescript
428
+ * p.string().optional({ message: 'This value cannot be null', allow: false })
429
+ * ```
430
+ *
431
+ * @param options - The options of nonOptional function
432
+ * @param options.message - A custom message if the value is undefined.
433
+ *
434
+ * @returns - The schema.
435
+ */ key: "nonOptional",
436
+ value: function nonOptional(options) {
437
+ return _get(_get_prototype_of(NumberSchema.prototype), "optional", this).call(this, {
438
+ message: options === null || options === void 0 ? void 0 : options.message,
439
+ allow: false
440
+ });
441
+ }
442
+ },
443
+ {
444
+ /**
445
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
446
+ * is NULL by setting the { message: 'Your custom message', allow: false } on the options.
411
447
  *
412
448
  * @example
413
449
  * ```typescript
@@ -436,14 +472,36 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
436
472
  },
437
473
  {
438
474
  /**
439
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep that way
440
- * otherwise it will set the value to undefined after it's validated.
475
+ * Just adds a message when the value is null. It's just a syntax sugar for
476
+ *
477
+ * ```typescript
478
+ * p.string().nullable({ message: 'This value cannot be null', allow: false })
479
+ * ```
480
+ *
481
+ * @param options - The options of nonNullable function
482
+ * @param options.message - A custom message if the value is null.
483
+ *
484
+ * @returns - The schema.
485
+ */ key: "nonNullable",
486
+ value: function nonNullable(options) {
487
+ return _get(_get_prototype_of(NumberSchema.prototype), "nullable", this).call(this, {
488
+ message: (options === null || options === void 0 ? void 0 : options.message) || '',
489
+ allow: false
490
+ });
491
+ }
492
+ },
493
+ {
494
+ /**
495
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
496
+ * that way otherwise it will set the value to undefined after it's validated.
441
497
  * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
442
498
  * function. This will remove the value from the representation of the schema.
443
499
  *
444
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
445
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
446
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
500
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
501
+ * function.
502
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
503
+ * as true. Then if you still want to remove the value from the representation, you will need to pass the argument
504
+ * `toRepresentation` as true as well.
447
505
  *
448
506
  * @example
449
507
  * ```typescript
@@ -465,9 +523,11 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
465
523
  * ```
466
524
  *
467
525
  *
468
- * @param args - By default, the value will be removed just from the representation, in other words, when you call the {@link data} function.
469
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as true.
470
- * Then if you still want to remove the value from the representation, you will need to pass the argument `toRepresentation` as true as well.
526
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
527
+ * the {@link data} function.
528
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
529
+ * as true. Then if you still want to remove the value from the representation, you will need to pass the argument
530
+ * `toRepresentation` as true as well.
471
531
  *
472
532
  * @returns The schema.
473
533
  */ key: "omit",
@@ -477,9 +537,32 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
477
537
  },
478
538
  {
479
539
  /**
480
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external source
481
- * like a database. You should always return the schema after you save the value, that way we will always have the correct type
482
- * of the schema after the save operation.
540
+ * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
541
+ * result to be a string as well.
542
+ *
543
+ * @example
544
+ * ```ts
545
+ * number().allowString().parse('true') // true
546
+ * ```
547
+ *
548
+ * @returns - The schema instance
549
+ */ key: "allowString",
550
+ value: function allowString() {
551
+ this.__allowString = true;
552
+ this.__parsers.low.set('allowString', (0, _parsers.convertFromStringBuilder)(function(value) {
553
+ return {
554
+ value: Number(value),
555
+ preventNextParsers: false
556
+ };
557
+ }));
558
+ return this;
559
+ }
560
+ },
561
+ {
562
+ /**
563
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
564
+ * source like a database. You should always return the schema after you save the value, that way we will always
565
+ * have the correct type of the schema after the save operation.
483
566
  *
484
567
  * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
485
568
  *
@@ -524,7 +607,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
524
607
  },
525
608
  {
526
609
  /**
527
- * 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.
610
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
611
+ * value will be used.
528
612
  *
529
613
  * @example
530
614
  * ```typescript
@@ -543,8 +627,9 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
543
627
  },
544
628
  {
545
629
  /**
546
- * 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
547
- * the custom schema your own way. Our API does not support passthrough? No problem, you can use this function to customize the zod schema.
630
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
631
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
632
+ * No problem, you can use this function to customize the zod schema.
548
633
  *
549
634
  * @example
550
635
  * ```typescript
@@ -556,12 +641,13 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
556
641
  *
557
642
  * const { errors, parsed } = await numberSchema.parse(-1);
558
643
  *
559
- * console.log(errors); // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
644
+ * console.log(errors);
645
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
560
646
  * ```
561
647
  *
562
648
  * @param callback - The callback that will be called to customize the schema.
563
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you want to compile the underlying schema
564
- * to a string so you can save it for future runs.
649
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you
650
+ * want to compile the underlying schema to a string so you can save it for future runs.
565
651
  *
566
652
  * @returns The schema.
567
653
  */ key: "extends",
@@ -571,8 +657,9 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
571
657
  },
572
658
  {
573
659
  /**
574
- * 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
575
- * 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.
660
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
661
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
662
+ * whatever. Another use case is when you want to return deeply nested recursive data.
576
663
  * The schema maps to itself.
577
664
  *
578
665
  * @example
@@ -619,8 +706,9 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
619
706
  },
620
707
  {
621
708
  /**
622
- * 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
623
- * 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.
709
+ * This function is used to transform the value to the internal representation of the schema. This is useful when
710
+ * you want to transform the value to a type that the schema adapter can understand. For example, you might want
711
+ * to transform a string to a date. This is the function you use.
624
712
  *
625
713
  * @example
626
714
  * ```typescript
@@ -656,7 +744,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
656
744
  },
657
745
  {
658
746
  /**
659
- * 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
747
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
748
+ * you can convert that string to a date
660
749
  * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
661
750
  *
662
751
  * @example
@@ -700,17 +789,18 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
700
789
  *
701
790
  * @returns - The schema instance
702
791
  */ key: "is",
703
- value: function is(value) {
792
+ value: function is(value, options) {
704
793
  this.__is = {
705
794
  value: value,
706
- message: "The value should be equal to ".concat(value.join(','))
795
+ message: typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The value should be equal to ".concat(value.join(','))
707
796
  };
708
797
  return this;
709
798
  }
710
799
  },
711
800
  {
712
801
  /**
713
- * Allows only numbers that are less than the value passed. If you want to allow the number to be equal to the value, you can pass the option `inclusive` as `true`.
802
+ * Allows only numbers that are less than the value passed. If you want to allow the number to be equal to the value,
803
+ * you can pass the option `inclusive` as `true`.
714
804
  * Otherwise, it will only allow numbers less than the value.
715
805
  *
716
806
  * @example
@@ -747,7 +837,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
747
837
  },
748
838
  {
749
839
  /**
750
- * This method will validate if the number is greater than the value passed. If you want to allow the number to be equal to the value, you can pass the option `inclusive` as `true`.
840
+ * This method will validate if the number is greater than the value passed. If you want to allow the number to be
841
+ * equal to the value, you can pass the option `inclusive` as `true`.
751
842
  * Otherwise, it will only allow numbers greater than the value.
752
843
  *
753
844
  * @example
@@ -784,74 +875,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
784
875
  },
785
876
  {
786
877
  /**
787
- * Allows only negative numbers. If you want to allow zero, you can pass the option `allowZero` as `true`. Otherwise, it will only allow negative numbers.
788
- *
789
- * @example
790
- * ```typescript
791
- * import * as p from '@palmares/schema';
792
- *
793
- * const schema = p.number().negative();
794
- *
795
- * schema.parse(-10); // { errors: [], parsed: -10 }
796
- * schema.parse(0); // { errors: [{ code: 'negative', message: 'The number should be negative' }], parsed: 0 }
797
- *
798
- * const schema = p.number().negative({ allowZero: true });
799
- *
800
- * schema.parse(0); // { errors: [], parsed: 0 }
801
- * ```
802
- *
803
- * @param options - The options to be passed to the validation
804
- * @param options.allowZero - If you want to allow zero, you can pass this option as `true`. Otherwise, it will only allow negative numbers.
805
- * @param options.message - The message to be returned if the validation fails
806
- *
807
- * @returns - The schema instance
808
- */ key: "negative",
809
- value: function negative(options) {
810
- var allowZero = typeof (options === null || options === void 0 ? void 0 : options.allowZero) === 'boolean' ? options.allowZero : true;
811
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : (0, _constants.DEFAULT_NUMBER_NEGATIVE_EXCEPTION)(allowZero);
812
- this.__allowNegative = {
813
- allowZero: allowZero,
814
- message: message
815
- };
816
- return this;
817
- }
818
- },
819
- {
820
- /**
821
- * Allows only positive numbers. If you want to allow zero, you can pass the option `allowZero` as `true`. Otherwise, it will only allow positive numbers greater than zero.
822
- *
823
- * @example
824
- * ```typescript
825
- * import * as p from '@palmares/schema';
826
- *
827
- * const schema = p.number().positive();
828
- *
829
- * schema.parse(10); // { errors: [], parsed: 10 }
830
- * schema.parse(0); // { errors: [{ code: 'positive', message: 'The number should be positive' }], parsed: 0 }
831
- *
832
- * const schema = p.number().positive({ allowZero: true });
833
- * schema.parse(0); // { errors: [], parsed: 0 }
834
- * ```
835
- *
836
- * @param options - The options to be passed to the validation
837
- * @param options.allowZero - If you want to allow zero, you can pass this option as `true`. Otherwise, it will only allow positive numbers greater than zero.
838
- * @param options.message - The message to be returned if the validation fails
839
- *
840
- * @returns - The schema instance
841
- */ key: "positive",
842
- value: function positive(options) {
843
- var allowZero = typeof (options === null || options === void 0 ? void 0 : options.allowZero) === 'boolean' ? options.allowZero : true;
844
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : (0, _constants.DEFAULT_NUMBER_NEGATIVE_EXCEPTION)(allowZero);
845
- this.__allowPositive = {
846
- allowZero: allowZero,
847
- message: message
848
- };
849
- return this;
850
- }
851
- },
852
- {
853
- /**
854
- * This method will validate the number to have the exact number of decimal places. It's usually useful for decimal numbers like currencies.
878
+ * This method will validate the number to have the exact number of decimal places. It's usually useful for decimal
879
+ * numbers like currencies.
855
880
  *
856
881
  * @example
857
882
  * ```
@@ -859,7 +884,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
859
884
  *
860
885
  * schema.parse(10.00); // { errors: [], parsed: 10.00}
861
886
  *
862
- * schema.parse(10.000); // { errors: [{ code: 'decimal_places', message: 'The number should have 2 decimal places' }], parsed: 10.000}
887
+ * schema.parse(10.000);
888
+ * // { errors: [{ code: 'decimal_places', message: 'The number should have 2 decimal places' }], parsed: 10.000}
863
889
  * ```
864
890
  *
865
891
  * @param value - The number of decimal places.
@@ -879,8 +905,8 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
879
905
  },
880
906
  {
881
907
  /**
882
- * This method will validate the number to have at most the number of digits specified. If used in conjunction with {@link decimalPlaces}, this number should be bigger than the
883
- * value of the decimal places.
908
+ * This method will validate the number to have at most the number of digits specified. If used in conjunction with
909
+ * {@link decimalPlaces}, this number should be bigger than the value of the decimal places.
884
910
  *
885
911
  * Think about that
886
912
  *
@@ -943,12 +969,6 @@ var NumberSchema = /*#__PURE__*/ function(Schema) {
943
969
  key: "new",
944
970
  value: function _new() {
945
971
  var returnValue = new NumberSchema();
946
- var adapterInstance = (0, _conf.getDefaultAdapter)();
947
- returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
948
- transformed: false,
949
- adapter: adapterInstance,
950
- schemas: []
951
- };
952
972
  return returnValue;
953
973
  }
954
974
  }