@palmares/schemas 0.1.25 → 0.2.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 (305) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/src/adapter/fields/array.cjs +96 -0
  3. package/dist/src/adapter/fields/array.d.ts.map +1 -0
  4. package/dist/src/adapter/fields/array.js +70 -0
  5. package/dist/src/adapter/fields/boolean.cjs +102 -0
  6. package/dist/src/adapter/fields/boolean.d.ts.map +1 -0
  7. package/dist/src/adapter/fields/boolean.js +76 -0
  8. package/dist/src/adapter/fields/datetime.cjs +102 -0
  9. package/dist/src/adapter/fields/datetime.d.ts.map +1 -0
  10. package/dist/src/adapter/fields/datetime.js +76 -0
  11. package/dist/src/adapter/fields/index.cjs +87 -0
  12. package/dist/src/adapter/fields/index.d.ts.map +1 -0
  13. package/dist/src/adapter/fields/index.js +61 -0
  14. package/dist/src/adapter/fields/number.cjs +102 -0
  15. package/dist/src/adapter/fields/number.d.ts.map +1 -0
  16. package/dist/src/adapter/fields/number.js +76 -0
  17. package/dist/src/adapter/fields/object.cjs +108 -0
  18. package/dist/src/adapter/fields/object.d.ts.map +1 -0
  19. package/dist/src/adapter/fields/object.js +82 -0
  20. package/dist/src/adapter/fields/string.cjs +102 -0
  21. package/dist/src/adapter/fields/string.d.ts.map +1 -0
  22. package/dist/src/adapter/fields/string.js +76 -0
  23. package/dist/src/adapter/fields/union.cjs +102 -0
  24. package/dist/src/adapter/fields/union.d.ts.map +1 -0
  25. package/dist/src/adapter/fields/union.js +76 -0
  26. package/dist/src/adapter/index.cjs +65 -0
  27. package/dist/src/adapter/index.d.ts.map +1 -0
  28. package/dist/src/adapter/index.js +40 -0
  29. package/dist/src/adapter/types.cjs +18 -0
  30. package/dist/src/adapter/types.d.ts.map +1 -0
  31. package/dist/src/adapter/types.js +0 -0
  32. package/dist/src/compile.cjs +59 -0
  33. package/dist/src/compile.d.ts.map +1 -0
  34. package/dist/src/compile.js +36 -0
  35. package/dist/src/conf.cjs +53 -0
  36. package/dist/src/conf.d.ts.map +1 -0
  37. package/dist/src/conf.js +27 -0
  38. package/dist/src/constants.cjs +40 -0
  39. package/dist/src/constants.d.ts.map +1 -0
  40. package/dist/src/constants.js +14 -0
  41. package/dist/src/domain.cjs +63 -0
  42. package/dist/src/domain.d.ts.map +1 -0
  43. package/dist/src/domain.js +40 -0
  44. package/dist/src/exceptions.cjs +48 -0
  45. package/dist/{cjs/types → src}/exceptions.d.ts +0 -3
  46. package/dist/src/exceptions.d.ts.map +1 -0
  47. package/dist/src/exceptions.js +24 -0
  48. package/dist/src/index.cjs +6509 -0
  49. package/dist/src/index.d.ts.map +1 -0
  50. package/dist/src/index.js +6445 -0
  51. package/dist/src/middleware.cjs +58 -0
  52. package/dist/src/middleware.d.ts.map +1 -0
  53. package/dist/src/middleware.js +35 -0
  54. package/dist/src/model.cjs +5992 -0
  55. package/dist/src/model.d.ts.map +1 -0
  56. package/dist/src/model.js +5967 -0
  57. package/dist/src/parsers/convert-from-number.cjs +34 -0
  58. package/dist/src/parsers/convert-from-number.d.ts.map +1 -0
  59. package/dist/src/parsers/convert-from-number.js +11 -0
  60. package/dist/src/parsers/convert-from-string.cjs +40 -0
  61. package/dist/src/parsers/convert-from-string.d.ts.map +1 -0
  62. package/dist/src/parsers/convert-from-string.js +17 -0
  63. package/dist/src/parsers/index.cjs +50 -0
  64. package/dist/src/parsers/index.d.ts.map +1 -0
  65. package/dist/src/parsers/index.js +24 -0
  66. package/dist/src/schema/array.cjs +1863 -0
  67. package/dist/src/schema/array.d.ts.map +1 -0
  68. package/dist/src/schema/array.js +1837 -0
  69. package/dist/src/schema/boolean.cjs +1800 -0
  70. package/dist/src/schema/boolean.d.ts.map +1 -0
  71. package/dist/src/schema/boolean.js +1774 -0
  72. package/dist/src/schema/datetime.cjs +1789 -0
  73. package/dist/src/schema/datetime.d.ts.map +1 -0
  74. package/dist/src/schema/datetime.js +1763 -0
  75. package/dist/src/schema/index.cjs +2026 -0
  76. package/dist/src/schema/index.d.ts.map +1 -0
  77. package/dist/src/schema/index.js +2001 -0
  78. package/dist/src/schema/number.cjs +2026 -0
  79. package/dist/src/schema/number.d.ts.map +1 -0
  80. package/dist/src/schema/number.js +2000 -0
  81. package/dist/src/schema/object.cjs +1795 -0
  82. package/dist/src/schema/object.d.ts.map +1 -0
  83. package/dist/src/schema/object.js +1769 -0
  84. package/dist/src/schema/schema.cjs +844 -0
  85. package/dist/src/schema/schema.d.ts.map +1 -0
  86. package/dist/src/schema/schema.js +818 -0
  87. package/dist/src/schema/string.cjs +2126 -0
  88. package/dist/src/schema/string.d.ts.map +1 -0
  89. package/dist/src/schema/string.js +2100 -0
  90. package/dist/src/schema/types.cjs +18 -0
  91. package/dist/src/schema/types.d.ts.map +1 -0
  92. package/dist/src/schema/types.js +0 -0
  93. package/dist/src/schema/union.cjs +1737 -0
  94. package/dist/src/schema/union.d.ts.map +1 -0
  95. package/dist/src/schema/union.js +1711 -0
  96. package/dist/src/types.cjs +18 -0
  97. package/dist/src/types.d.ts.map +1 -0
  98. package/dist/src/types.js +0 -0
  99. package/dist/src/utils.cjs +477 -0
  100. package/dist/src/utils.d.ts.map +1 -0
  101. package/dist/src/utils.js +445 -0
  102. package/dist/src/validators/array.cjs +176 -0
  103. package/dist/src/validators/array.d.ts.map +1 -0
  104. package/dist/src/validators/array.js +150 -0
  105. package/dist/src/validators/boolean.cjs +71 -0
  106. package/dist/src/validators/boolean.d.ts.map +1 -0
  107. package/dist/src/validators/boolean.js +47 -0
  108. package/dist/src/validators/datetime.cjs +129 -0
  109. package/dist/src/validators/datetime.d.ts.map +1 -0
  110. package/dist/src/validators/datetime.js +103 -0
  111. package/dist/src/validators/number.cjs +194 -0
  112. package/dist/src/validators/number.d.ts.map +1 -0
  113. package/dist/src/validators/number.js +166 -0
  114. package/dist/src/validators/object.cjs +69 -0
  115. package/dist/src/validators/object.d.ts.map +1 -0
  116. package/dist/src/validators/object.js +46 -0
  117. package/dist/src/validators/schema.cjs +158 -0
  118. package/dist/src/validators/schema.d.ts.map +1 -0
  119. package/dist/src/validators/schema.js +132 -0
  120. package/dist/src/validators/string.cjs +255 -0
  121. package/dist/src/validators/string.d.ts.map +1 -0
  122. package/dist/src/validators/string.js +224 -0
  123. package/dist/src/validators/types.cjs +18 -0
  124. package/dist/src/validators/types.d.ts.map +1 -0
  125. package/dist/src/validators/types.js +0 -0
  126. package/dist/src/validators/union.cjs +69 -0
  127. package/dist/src/validators/union.d.ts.map +1 -0
  128. package/dist/src/validators/union.js +46 -0
  129. package/dist/src/validators/utils.cjs +165 -0
  130. package/dist/src/validators/utils.d.ts.map +1 -0
  131. package/dist/src/validators/utils.js +142 -0
  132. package/dist/tsconfig.types.tsbuildinfo +1 -0
  133. package/package.json +15 -23
  134. package/dist/cjs/src/adapter/fields/array.js +0 -152
  135. package/dist/cjs/src/adapter/fields/boolean.js +0 -162
  136. package/dist/cjs/src/adapter/fields/datetime.js +0 -162
  137. package/dist/cjs/src/adapter/fields/index.js +0 -311
  138. package/dist/cjs/src/adapter/fields/number.js +0 -162
  139. package/dist/cjs/src/adapter/fields/object.js +0 -171
  140. package/dist/cjs/src/adapter/fields/string.js +0 -162
  141. package/dist/cjs/src/adapter/fields/union.js +0 -162
  142. package/dist/cjs/src/adapter/index.js +0 -201
  143. package/dist/cjs/src/adapter/types.js +0 -4
  144. package/dist/cjs/src/compile.js +0 -262
  145. package/dist/cjs/src/conf.js +0 -26
  146. package/dist/cjs/src/constants.js +0 -36
  147. package/dist/cjs/src/domain.js +0 -156
  148. package/dist/cjs/src/exceptions.js +0 -168
  149. package/dist/cjs/src/index.js +0 -317
  150. package/dist/cjs/src/middleware.js +0 -213
  151. package/dist/cjs/src/model.js +0 -628
  152. package/dist/cjs/src/parsers/convert-from-number.js +0 -15
  153. package/dist/cjs/src/parsers/convert-from-string.js +0 -19
  154. package/dist/cjs/src/parsers/index.js +0 -20
  155. package/dist/cjs/src/schema/array.js +0 -1014
  156. package/dist/cjs/src/schema/boolean.js +0 -883
  157. package/dist/cjs/src/schema/datetime.js +0 -840
  158. package/dist/cjs/src/schema/index.js +0 -12
  159. package/dist/cjs/src/schema/number.js +0 -976
  160. package/dist/cjs/src/schema/object.js +0 -1052
  161. package/dist/cjs/src/schema/schema.js +0 -1840
  162. package/dist/cjs/src/schema/string.js +0 -1038
  163. package/dist/cjs/src/schema/types.js +0 -4
  164. package/dist/cjs/src/schema/union.js +0 -1070
  165. package/dist/cjs/src/types.js +0 -4
  166. package/dist/cjs/src/utils.js +0 -647
  167. package/dist/cjs/src/validators/array.js +0 -462
  168. package/dist/cjs/src/validators/boolean.js +0 -201
  169. package/dist/cjs/src/validators/datetime.js +0 -291
  170. package/dist/cjs/src/validators/number.js +0 -375
  171. package/dist/cjs/src/validators/object.js +0 -291
  172. package/dist/cjs/src/validators/schema.js +0 -322
  173. package/dist/cjs/src/validators/string.js +0 -467
  174. package/dist/cjs/src/validators/types.js +0 -4
  175. package/dist/cjs/src/validators/union.js +0 -233
  176. package/dist/cjs/src/validators/utils.js +0 -499
  177. package/dist/cjs/tsconfig.types.tsbuildinfo +0 -1
  178. package/dist/cjs/types/adapter/fields/array.d.ts.map +0 -1
  179. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +0 -1
  180. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +0 -1
  181. package/dist/cjs/types/adapter/fields/index.d.ts.map +0 -1
  182. package/dist/cjs/types/adapter/fields/number.d.ts.map +0 -1
  183. package/dist/cjs/types/adapter/fields/object.d.ts.map +0 -1
  184. package/dist/cjs/types/adapter/fields/string.d.ts.map +0 -1
  185. package/dist/cjs/types/adapter/fields/union.d.ts.map +0 -1
  186. package/dist/cjs/types/adapter/index.d.ts.map +0 -1
  187. package/dist/cjs/types/adapter/types.d.ts.map +0 -1
  188. package/dist/cjs/types/compile.d.ts.map +0 -1
  189. package/dist/cjs/types/conf.d.ts.map +0 -1
  190. package/dist/cjs/types/constants.d.ts.map +0 -1
  191. package/dist/cjs/types/domain.d.ts.map +0 -1
  192. package/dist/cjs/types/exceptions.d.ts.map +0 -1
  193. package/dist/cjs/types/index.d.ts.map +0 -1
  194. package/dist/cjs/types/middleware.d.ts.map +0 -1
  195. package/dist/cjs/types/model.d.ts.map +0 -1
  196. package/dist/cjs/types/parsers/convert-from-number.d.ts.map +0 -1
  197. package/dist/cjs/types/parsers/convert-from-string.d.ts.map +0 -1
  198. package/dist/cjs/types/parsers/index.d.ts.map +0 -1
  199. package/dist/cjs/types/schema/array.d.ts.map +0 -1
  200. package/dist/cjs/types/schema/boolean.d.ts.map +0 -1
  201. package/dist/cjs/types/schema/datetime.d.ts.map +0 -1
  202. package/dist/cjs/types/schema/index.d.ts.map +0 -1
  203. package/dist/cjs/types/schema/number.d.ts.map +0 -1
  204. package/dist/cjs/types/schema/object.d.ts.map +0 -1
  205. package/dist/cjs/types/schema/schema.d.ts.map +0 -1
  206. package/dist/cjs/types/schema/string.d.ts.map +0 -1
  207. package/dist/cjs/types/schema/types.d.ts.map +0 -1
  208. package/dist/cjs/types/schema/union.d.ts.map +0 -1
  209. package/dist/cjs/types/types.d.ts.map +0 -1
  210. package/dist/cjs/types/utils.d.ts.map +0 -1
  211. package/dist/cjs/types/validators/array.d.ts.map +0 -1
  212. package/dist/cjs/types/validators/boolean.d.ts.map +0 -1
  213. package/dist/cjs/types/validators/datetime.d.ts.map +0 -1
  214. package/dist/cjs/types/validators/number.d.ts.map +0 -1
  215. package/dist/cjs/types/validators/object.d.ts.map +0 -1
  216. package/dist/cjs/types/validators/schema.d.ts.map +0 -1
  217. package/dist/cjs/types/validators/string.d.ts.map +0 -1
  218. package/dist/cjs/types/validators/types.d.ts.map +0 -1
  219. package/dist/cjs/types/validators/union.d.ts.map +0 -1
  220. package/dist/cjs/types/validators/utils.d.ts.map +0 -1
  221. package/dist/esm/src/adapter/fields/array.js +0 -13
  222. package/dist/esm/src/adapter/fields/boolean.js +0 -20
  223. package/dist/esm/src/adapter/fields/datetime.js +0 -20
  224. package/dist/esm/src/adapter/fields/index.js +0 -37
  225. package/dist/esm/src/adapter/fields/number.js +0 -20
  226. package/dist/esm/src/adapter/fields/object.js +0 -26
  227. package/dist/esm/src/adapter/fields/string.js +0 -20
  228. package/dist/esm/src/adapter/fields/union.js +0 -20
  229. package/dist/esm/src/adapter/index.js +0 -21
  230. package/dist/esm/src/adapter/types.js +0 -1
  231. package/dist/esm/src/compile.js +0 -10
  232. package/dist/esm/src/conf.js +0 -18
  233. package/dist/esm/src/constants.js +0 -4
  234. package/dist/esm/src/domain.js +0 -11
  235. package/dist/esm/src/exceptions.js +0 -15
  236. package/dist/esm/src/index.js +0 -126
  237. package/dist/esm/src/middleware.js +0 -29
  238. package/dist/esm/src/model.js +0 -264
  239. package/dist/esm/src/parsers/convert-from-number.js +0 -8
  240. package/dist/esm/src/parsers/convert-from-string.js +0 -14
  241. package/dist/esm/src/parsers/index.js +0 -2
  242. package/dist/esm/src/schema/array.js +0 -487
  243. package/dist/esm/src/schema/boolean.js +0 -520
  244. package/dist/esm/src/schema/datetime.js +0 -477
  245. package/dist/esm/src/schema/index.js +0 -3
  246. package/dist/esm/src/schema/number.js +0 -610
  247. package/dist/esm/src/schema/object.js +0 -521
  248. package/dist/esm/src/schema/schema.js +0 -767
  249. package/dist/esm/src/schema/string.js +0 -668
  250. package/dist/esm/src/schema/types.js +0 -1
  251. package/dist/esm/src/schema/union.js +0 -468
  252. package/dist/esm/src/types.js +0 -14
  253. package/dist/esm/src/utils.js +0 -207
  254. package/dist/esm/src/validators/array.js +0 -140
  255. package/dist/esm/src/validators/boolean.js +0 -37
  256. package/dist/esm/src/validators/datetime.js +0 -89
  257. package/dist/esm/src/validators/number.js +0 -148
  258. package/dist/esm/src/validators/object.js +0 -39
  259. package/dist/esm/src/validators/schema.js +0 -118
  260. package/dist/esm/src/validators/string.js +0 -202
  261. package/dist/esm/src/validators/types.js +0 -1
  262. package/dist/esm/src/validators/union.js +0 -39
  263. package/dist/esm/src/validators/utils.js +0 -147
  264. /package/dist/{cjs/types → src}/adapter/fields/array.d.ts +0 -0
  265. /package/dist/{cjs/types → src}/adapter/fields/boolean.d.ts +0 -0
  266. /package/dist/{cjs/types → src}/adapter/fields/datetime.d.ts +0 -0
  267. /package/dist/{cjs/types → src}/adapter/fields/index.d.ts +0 -0
  268. /package/dist/{cjs/types → src}/adapter/fields/number.d.ts +0 -0
  269. /package/dist/{cjs/types → src}/adapter/fields/object.d.ts +0 -0
  270. /package/dist/{cjs/types → src}/adapter/fields/string.d.ts +0 -0
  271. /package/dist/{cjs/types → src}/adapter/fields/union.d.ts +0 -0
  272. /package/dist/{cjs/types → src}/adapter/index.d.ts +0 -0
  273. /package/dist/{cjs/types → src}/adapter/types.d.ts +0 -0
  274. /package/dist/{cjs/types → src}/compile.d.ts +0 -0
  275. /package/dist/{cjs/types → src}/conf.d.ts +0 -0
  276. /package/dist/{cjs/types → src}/constants.d.ts +0 -0
  277. /package/dist/{cjs/types → src}/domain.d.ts +0 -0
  278. /package/dist/{cjs/types → src}/index.d.ts +0 -0
  279. /package/dist/{cjs/types → src}/middleware.d.ts +0 -0
  280. /package/dist/{cjs/types → src}/model.d.ts +0 -0
  281. /package/dist/{cjs/types → src}/parsers/convert-from-number.d.ts +0 -0
  282. /package/dist/{cjs/types → src}/parsers/convert-from-string.d.ts +0 -0
  283. /package/dist/{cjs/types → src}/parsers/index.d.ts +0 -0
  284. /package/dist/{cjs/types → src}/schema/array.d.ts +0 -0
  285. /package/dist/{cjs/types → src}/schema/boolean.d.ts +0 -0
  286. /package/dist/{cjs/types → src}/schema/datetime.d.ts +0 -0
  287. /package/dist/{cjs/types → src}/schema/index.d.ts +0 -0
  288. /package/dist/{cjs/types → src}/schema/number.d.ts +0 -0
  289. /package/dist/{cjs/types → src}/schema/object.d.ts +0 -0
  290. /package/dist/{cjs/types → src}/schema/schema.d.ts +0 -0
  291. /package/dist/{cjs/types → src}/schema/string.d.ts +0 -0
  292. /package/dist/{cjs/types → src}/schema/types.d.ts +0 -0
  293. /package/dist/{cjs/types → src}/schema/union.d.ts +0 -0
  294. /package/dist/{cjs/types → src}/types.d.ts +0 -0
  295. /package/dist/{cjs/types → src}/utils.d.ts +0 -0
  296. /package/dist/{cjs/types → src}/validators/array.d.ts +0 -0
  297. /package/dist/{cjs/types → src}/validators/boolean.d.ts +0 -0
  298. /package/dist/{cjs/types → src}/validators/datetime.d.ts +0 -0
  299. /package/dist/{cjs/types → src}/validators/number.d.ts +0 -0
  300. /package/dist/{cjs/types → src}/validators/object.d.ts +0 -0
  301. /package/dist/{cjs/types → src}/validators/schema.d.ts +0 -0
  302. /package/dist/{cjs/types → src}/validators/string.d.ts +0 -0
  303. /package/dist/{cjs/types → src}/validators/types.d.ts +0 -0
  304. /package/dist/{cjs/types → src}/validators/union.d.ts +0 -0
  305. /package/dist/{cjs/types → src}/validators/utils.d.ts +0 -0
@@ -1,976 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- NumberSchema: function() {
13
- return NumberSchema;
14
- },
15
- number: function() {
16
- return number;
17
- }
18
- });
19
- var _schema = require("./schema");
20
- var _constants = require("../constants");
21
- var _parsers = require("../parsers");
22
- var _utils = require("../utils");
23
- var _number = require("../validators/number");
24
- var _schema1 = require("../validators/schema");
25
- function _assert_this_initialized(self) {
26
- if (self === void 0) {
27
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
28
- }
29
- return self;
30
- }
31
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
32
- try {
33
- var info = gen[key](arg);
34
- var value = info.value;
35
- } catch (error) {
36
- reject(error);
37
- return;
38
- }
39
- if (info.done) {
40
- resolve(value);
41
- } else {
42
- Promise.resolve(value).then(_next, _throw);
43
- }
44
- }
45
- function _async_to_generator(fn) {
46
- return function() {
47
- var self = this, args = arguments;
48
- return new Promise(function(resolve, reject) {
49
- var gen = fn.apply(self, args);
50
- function _next(value) {
51
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
52
- }
53
- function _throw(err) {
54
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
55
- }
56
- _next(undefined);
57
- });
58
- };
59
- }
60
- function _class_call_check(instance, Constructor) {
61
- if (!(instance instanceof Constructor)) {
62
- throw new TypeError("Cannot call a class as a function");
63
- }
64
- }
65
- function _defineProperties(target, props) {
66
- for(var i = 0; i < props.length; i++){
67
- var descriptor = props[i];
68
- descriptor.enumerable = descriptor.enumerable || false;
69
- descriptor.configurable = true;
70
- if ("value" in descriptor) descriptor.writable = true;
71
- Object.defineProperty(target, descriptor.key, descriptor);
72
- }
73
- }
74
- function _create_class(Constructor, protoProps, staticProps) {
75
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
76
- if (staticProps) _defineProperties(Constructor, staticProps);
77
- return Constructor;
78
- }
79
- function _define_property(obj, key, value) {
80
- if (key in obj) {
81
- Object.defineProperty(obj, key, {
82
- value: value,
83
- enumerable: true,
84
- configurable: true,
85
- writable: true
86
- });
87
- } else {
88
- obj[key] = value;
89
- }
90
- return obj;
91
- }
92
- function _get(target, property, receiver) {
93
- if (typeof Reflect !== "undefined" && Reflect.get) {
94
- _get = Reflect.get;
95
- } else {
96
- _get = function get(target, property, receiver) {
97
- var base = _super_prop_base(target, property);
98
- if (!base) return;
99
- var desc = Object.getOwnPropertyDescriptor(base, property);
100
- if (desc.get) {
101
- return desc.get.call(receiver || target);
102
- }
103
- return desc.value;
104
- };
105
- }
106
- return _get(target, property, receiver || target);
107
- }
108
- function _get_prototype_of(o) {
109
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
110
- return o.__proto__ || Object.getPrototypeOf(o);
111
- };
112
- return _get_prototype_of(o);
113
- }
114
- function _inherits(subClass, superClass) {
115
- if (typeof superClass !== "function" && superClass !== null) {
116
- throw new TypeError("Super expression must either be null or a function");
117
- }
118
- subClass.prototype = Object.create(superClass && superClass.prototype, {
119
- constructor: {
120
- value: subClass,
121
- writable: true,
122
- configurable: true
123
- }
124
- });
125
- if (superClass) _set_prototype_of(subClass, superClass);
126
- }
127
- function _possible_constructor_return(self, call) {
128
- if (call && (_type_of(call) === "object" || typeof call === "function")) {
129
- return call;
130
- }
131
- return _assert_this_initialized(self);
132
- }
133
- function _set_prototype_of(o, p) {
134
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
135
- o.__proto__ = p;
136
- return o;
137
- };
138
- return _set_prototype_of(o, p);
139
- }
140
- function _super_prop_base(object, property) {
141
- while(!Object.prototype.hasOwnProperty.call(object, property)){
142
- object = _get_prototype_of(object);
143
- if (object === null) break;
144
- }
145
- return object;
146
- }
147
- function _type_of(obj) {
148
- "@swc/helpers - typeof";
149
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
150
- }
151
- function _is_native_reflect_construct() {
152
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
153
- if (Reflect.construct.sham) return false;
154
- if (typeof Proxy === "function") return true;
155
- try {
156
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
157
- return true;
158
- } catch (e) {
159
- return false;
160
- }
161
- }
162
- function _create_super(Derived) {
163
- var hasNativeReflectConstruct = _is_native_reflect_construct();
164
- return function _createSuperInternal() {
165
- var Super = _get_prototype_of(Derived), result;
166
- if (hasNativeReflectConstruct) {
167
- var NewTarget = _get_prototype_of(this).constructor;
168
- result = Reflect.construct(Super, arguments, NewTarget);
169
- } else {
170
- result = Super.apply(this, arguments);
171
- }
172
- return _possible_constructor_return(this, result);
173
- };
174
- }
175
- function _ts_generator(thisArg, body) {
176
- var f, y, t, g, _ = {
177
- label: 0,
178
- sent: function() {
179
- if (t[0] & 1) throw t[1];
180
- return t[1];
181
- },
182
- trys: [],
183
- ops: []
184
- };
185
- return g = {
186
- next: verb(0),
187
- "throw": verb(1),
188
- "return": verb(2)
189
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
190
- return this;
191
- }), g;
192
- function verb(n) {
193
- return function(v) {
194
- return step([
195
- n,
196
- v
197
- ]);
198
- };
199
- }
200
- function step(op) {
201
- if (f) throw new TypeError("Generator is already executing.");
202
- while(_)try {
203
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
204
- if (y = 0, t) op = [
205
- op[0] & 2,
206
- t.value
207
- ];
208
- switch(op[0]){
209
- case 0:
210
- case 1:
211
- t = op;
212
- break;
213
- case 4:
214
- _.label++;
215
- return {
216
- value: op[1],
217
- done: false
218
- };
219
- case 5:
220
- _.label++;
221
- y = op[1];
222
- op = [
223
- 0
224
- ];
225
- continue;
226
- case 7:
227
- op = _.ops.pop();
228
- _.trys.pop();
229
- continue;
230
- default:
231
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
232
- _ = 0;
233
- continue;
234
- }
235
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
236
- _.label = op[1];
237
- break;
238
- }
239
- if (op[0] === 6 && _.label < t[1]) {
240
- _.label = t[1];
241
- t = op;
242
- break;
243
- }
244
- if (t && _.label < t[2]) {
245
- _.label = t[2];
246
- _.ops.push(op);
247
- break;
248
- }
249
- if (t[2]) _.ops.pop();
250
- _.trys.pop();
251
- continue;
252
- }
253
- op = body.call(thisArg, _);
254
- } catch (e) {
255
- op = [
256
- 6,
257
- e
258
- ];
259
- y = 0;
260
- } finally{
261
- f = t = 0;
262
- }
263
- if (op[0] & 5) throw op[1];
264
- return {
265
- value: op[0] ? op[1] : void 0,
266
- done: true
267
- };
268
- }
269
- }
270
- var NumberSchema = /*#__PURE__*/ function(Schema) {
271
- "use strict";
272
- _inherits(NumberSchema, Schema);
273
- var _super = _create_super(NumberSchema);
274
- function NumberSchema() {
275
- _class_call_check(this, NumberSchema);
276
- var _this;
277
- _this = _super.apply(this, arguments);
278
- _define_property(_assert_this_initialized(_this), "fieldType", 'number');
279
- _define_property(_assert_this_initialized(_this), "__allowString", void 0);
280
- _define_property(_assert_this_initialized(_this), "__is", void 0);
281
- _define_property(_assert_this_initialized(_this), "__integer", void 0);
282
- _define_property(_assert_this_initialized(_this), "__maxDigits", void 0);
283
- _define_property(_assert_this_initialized(_this), "__decimalPlaces", void 0);
284
- _define_property(_assert_this_initialized(_this), "__max", void 0);
285
- _define_property(_assert_this_initialized(_this), "__min", void 0);
286
- _define_property(_assert_this_initialized(_this), "__type", {
287
- message: 'Invalid type',
288
- check: function(value) {
289
- var isNumber = new RegExp('^-?\\d*(\\.\\d+)?$').test(value);
290
- if (typeof value === 'string' && _this.__allowString && isNumber) return true;
291
- return typeof value === 'number';
292
- }
293
- });
294
- return _this;
295
- }
296
- _create_class(NumberSchema, [
297
- {
298
- key: "__transformToAdapter",
299
- value: function __transformToAdapter(options) {
300
- var _this = this;
301
- return _async_to_generator(function() {
302
- return _ts_generator(this, function(_state) {
303
- return [
304
- 2,
305
- (0, _utils.defaultTransformToAdapter)(function() {
306
- var _ref = _async_to_generator(function(adapter) {
307
- return _ts_generator(this, function(_state) {
308
- return [
309
- 2,
310
- (0, _utils.defaultTransform)('number', _this, adapter, adapter.number, function() {
311
- return {
312
- is: _this.__is,
313
- min: _this.__min,
314
- max: _this.__max,
315
- integer: _this.__integer,
316
- optional: _this.__optional,
317
- nullable: _this.__nullable,
318
- maxDigits: _this.__maxDigits,
319
- decimalPlaces: _this.__decimalPlaces,
320
- type: _this.__type,
321
- parsers: {
322
- allowString: _this.__allowString,
323
- nullable: _this.__nullable.allow,
324
- optional: _this.__optional.allow
325
- }
326
- };
327
- }, {
328
- max: _number.max,
329
- min: _number.min,
330
- maxDigits: _number.maxDigits,
331
- is: _schema1.is,
332
- optional: _schema1.optional,
333
- nullable: _schema1.nullable,
334
- decimalPlaces: _number.decimalPlaces,
335
- integer: _number.integer
336
- }, {
337
- validatorsIfFallbackOrNotSupported: (0, _number.numberValidation)(),
338
- shouldAddStringVersion: options.shouldAddStringVersion,
339
- // eslint-disable-next-line ts/require-await
340
- fallbackIfNotSupported: /*#__PURE__*/ _async_to_generator(function() {
341
- return _ts_generator(this, function(_state) {
342
- return [
343
- 2,
344
- []
345
- ];
346
- });
347
- })
348
- })
349
- ];
350
- });
351
- });
352
- return function(adapter) {
353
- return _ref.apply(this, arguments);
354
- };
355
- }(), _this, _this.__transformedSchemas, options, 'number')
356
- ];
357
- });
358
- })();
359
- }
360
- },
361
- {
362
- /**
363
- * This let's you refine the schema with custom validations. This is useful when you want to validate something
364
- * that is not supported by default by the schema adapter.
365
- *
366
- * @example
367
- * ```typescript
368
- * import * as p from '@palmares/schemas';
369
- *
370
- * const numberSchema = p.number().refine((value) => {
371
- * if (value < 0) return { code: 'invalid_number', message: 'The number should be greater than 0' };
372
- * });
373
- *
374
- * const { errors, parsed } = await numberSchema.parse(-1);
375
- *
376
- * console.log(errors);
377
- * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
378
- * ```
379
- *
380
- * @param refinementCallback - The callback that will be called to validate the value.
381
- * @param options - Options for the refinement.
382
- * @param options.isAsync - Whether the callback is async or not. Defaults to true.
383
- *
384
- * @returns The schema.
385
- */ key: "refine",
386
- value: function refine(refinementCallback) {
387
- return _get(_get_prototype_of(NumberSchema.prototype), "refine", this).call(this, refinementCallback);
388
- }
389
- },
390
- {
391
- /**
392
- * Allows the value to be either undefined or null.
393
- *
394
- * @example
395
- * ```typescript
396
- * import * as p from '@palmares/schemas';
397
- *
398
- * const numberSchema = p.number().optional();
399
- *
400
- * const { errors, parsed } = await numberSchema.parse(undefined);
401
- *
402
- * console.log(parsed); // undefined
403
- *
404
- * const { errors, parsed } = await numberSchema.parse(null);
405
- *
406
- * console.log(parsed); // null
407
- *
408
- * const { errors, parsed } = await numberSchema.parse(1);
409
- *
410
- * console.log(parsed); // 1
411
- * ```
412
- *
413
- * @returns - The schema we are working with.
414
- */ key: "optional",
415
- value: function optional(options) {
416
- return _get(_get_prototype_of(NumberSchema.prototype), "optional", this).call(this, options);
417
- }
418
- },
419
- {
420
- /**
421
- * Just adds a message when the value is undefined. It's just a syntax sugar for
422
- *
423
- * ```typescript
424
- * p.string().optional({ message: 'This value cannot be null', allow: false })
425
- * ```
426
- *
427
- * @param options - The options of nonOptional function
428
- * @param options.message - A custom message if the value is undefined.
429
- *
430
- * @returns - The schema.
431
- */ key: "nonOptional",
432
- value: function nonOptional(options) {
433
- return _get(_get_prototype_of(NumberSchema.prototype), "optional", this).call(this, {
434
- message: options === null || options === void 0 ? void 0 : options.message,
435
- allow: false
436
- });
437
- }
438
- },
439
- {
440
- /**
441
- * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
442
- * is NULL by setting the { message: 'Your custom message', allow: false } on the options.
443
- *
444
- * @example
445
- * ```typescript
446
- * import * as p from '@palmares/schemas';
447
- *
448
- * const numberSchema = p.number().nullable();
449
- *
450
- * const { errors, parsed } = await numberSchema.parse(null);
451
- *
452
- * console.log(parsed); // null
453
- *
454
- * const { errors, parsed } = await numberSchema.parse(undefined);
455
- *
456
- * console.log(errors); // [{ isValid: false, code: 'invalid_type', message: 'Invalid type', path: [] }]
457
- * ```
458
- *
459
- * @param options - The options for the nullable function.
460
- * @param options.message - The message to be shown when the value is not null. Defaults to 'Cannot be null'.
461
- * @param options.allow - Whether the value can be null or not. Defaults to true.
462
- *
463
- * @returns The schema.
464
- */ key: "nullable",
465
- value: function nullable(options) {
466
- return _get(_get_prototype_of(NumberSchema.prototype), "nullable", this).call(this, options);
467
- }
468
- },
469
- {
470
- /**
471
- * Just adds a message when the value is null. It's just a syntax sugar for
472
- *
473
- * ```typescript
474
- * p.string().nullable({ message: 'This value cannot be null', allow: false })
475
- * ```
476
- *
477
- * @param options - The options of nonNullable function
478
- * @param options.message - A custom message if the value is null.
479
- *
480
- * @returns - The schema.
481
- */ key: "nonNullable",
482
- value: function nonNullable(options) {
483
- return _get(_get_prototype_of(NumberSchema.prototype), "nullable", this).call(this, {
484
- message: (options === null || options === void 0 ? void 0 : options.message) || '',
485
- allow: false
486
- });
487
- }
488
- },
489
- {
490
- /**
491
- * This method will remove the value from the representation of the schema. If the value is undefined it will keep
492
- * that way otherwise it will set the value to undefined after it's validated.
493
- * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
494
- * function. This will remove the value from the representation of the schema.
495
- *
496
- * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
497
- * function.
498
- * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
499
- * as true. Then if you still want to remove the value from the representation, you will need to pass the argument
500
- * `toRepresentation` as true as well.
501
- *
502
- * @example
503
- * ```typescript
504
- * import * as p from '@palmares/schemas';
505
- *
506
- * const userSchema = p.object({
507
- * id: p.number().optional(),
508
- * name: p.string(),
509
- * password: p.string().omit()
510
- * });
511
- *
512
- * const user = await userSchema.data({
513
- * id: 1,
514
- * name: 'John Doe',
515
- * password: '123456'
516
- * });
517
- *
518
- * console.log(user); // { id: 1, name: 'John Doe' }
519
- * ```
520
- *
521
- *
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`
525
- * as 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.
527
- *
528
- * @returns The schema.
529
- */ key: "omit",
530
- value: function omit(args) {
531
- return _get(_get_prototype_of(NumberSchema.prototype), "omit", this).call(this, args);
532
- }
533
- },
534
- {
535
- /**
536
- * This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
537
- * result to be a string as well.
538
- *
539
- * @example
540
- * ```ts
541
- * number().allowString().parse('true') // true
542
- * ```
543
- *
544
- * @returns - The schema instance
545
- */ key: "allowString",
546
- value: function allowString() {
547
- this.__allowString = true;
548
- this.__parsers.low.set('allowString', (0, _parsers.convertFromStringBuilder)(function(value) {
549
- return {
550
- value: Number(value),
551
- preventNextParsers: false
552
- };
553
- }));
554
- return this;
555
- }
556
- },
557
- {
558
- /**
559
- * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
560
- * source like a database. You should always return the schema after you save the value, that way we will always
561
- * have the correct type of the schema after the save operation.
562
- *
563
- * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
564
- *
565
- * @example
566
- * ```typescript
567
- * import * as p from '@palmares/schemas';
568
- *
569
- * import { User } from './models';
570
- *
571
- * const userSchema = p.object({
572
- * id: p.number().optional(),
573
- * name: p.string(),
574
- * email: p.string().email(),
575
- * }).onSave(async (value) => {
576
- * // Create or update the user on the database using palmares models or any other library of your choice.
577
- * if (value.id)
578
- * await User.default.set(value, { search: { id: value.id } });
579
- * else
580
- * await User.default.set(value);
581
- *
582
- * return value;
583
- * });
584
- *
585
- *
586
- * // Then, on your controller, do something like this:
587
- * const { isValid, save, errors } = await userSchema.validate(req.body);
588
- * if (isValid) {
589
- * const savedValue = await save();
590
- * return Response.json(savedValue, { status: 201 });
591
- * }
592
- *
593
- * return Response.json({ errors }, { status: 400 });
594
- * ```
595
- *
596
- * @param callback - The callback that will be called to save the value on an external source.
597
- *
598
- * @returns The schema.
599
- */ key: "onSave",
600
- value: function onSave(callback) {
601
- return _get(_get_prototype_of(NumberSchema.prototype), "onSave", this).call(this, callback);
602
- }
603
- },
604
- {
605
- /**
606
- * This function is used to add a default value to the schema. If the value is either undefined or null, the default
607
- * value will be used.
608
- *
609
- * @example
610
- * ```typescript
611
- * import * as p from '@palmares/schemas';
612
- *
613
- * const numberSchema = p.number().default(0);
614
- *
615
- * const { errors, parsed } = await numberSchema.parse(undefined);
616
- *
617
- * console.log(parsed); // 0
618
- * ```
619
- */ key: "default",
620
- value: function _default(defaultValueOrFunction) {
621
- return _get(_get_prototype_of(NumberSchema.prototype), "default", this).call(this, defaultValueOrFunction);
622
- }
623
- },
624
- {
625
- /**
626
- * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
627
- * this function to let you customize the custom schema your own way. Our API does not support passthrough?
628
- * No problem, you can use this function to customize the zod schema.
629
- *
630
- * @example
631
- * ```typescript
632
- * import * as p from '@palmares/schemas';
633
- *
634
- * const numberSchema = p.number().extends((schema) => {
635
- * return schema.nonnegative();
636
- * });
637
- *
638
- * const { errors, parsed } = await numberSchema.parse(-1);
639
- *
640
- * console.log(errors);
641
- * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
642
- * ```
643
- *
644
- * @param callback - The callback that will be called to customize the schema.
645
- * @param toStringCallback - The callback that will be called to transform the schema to a string when you
646
- * want to compile the underlying schema to a string so you can save it for future runs.
647
- *
648
- * @returns The schema.
649
- */ key: "extends",
650
- value: function _extends(callback, toStringCallback) {
651
- return _get(_get_prototype_of(NumberSchema.prototype), "extends", this).call(this, callback, toStringCallback);
652
- }
653
- },
654
- {
655
- /**
656
- * This function is used to transform the value to the representation of the schema. When using the {@link data}
657
- * function. With this function you have full control to add data cleaning for example, transforming the data and
658
- * whatever. Another use case is when you want to return deeply nested recursive data.
659
- * The schema maps to itself.
660
- *
661
- * @example
662
- * ```typescript
663
- * import * as p from '@palmares/schemas';
664
- *
665
- * const recursiveSchema = p.object({
666
- * id: p.number().optional(),
667
- * name: p.string(),
668
- * }).toRepresentation(async (value) => {
669
- * return {
670
- * id: value.id,
671
- * name: value.name,
672
- * children: await Promise.all(value.children.map(async (child) => await recursiveSchema.data(child)))
673
- * }
674
- * });
675
- *
676
- * const data = await recursiveSchema.data({
677
- * id: 1,
678
- * name: 'John Doe',
679
- * });
680
- * ```
681
- *
682
- * @example
683
- * ```
684
- * import * as p from '@palmares/schemas';
685
- *
686
- * const colorToRGBSchema = p.string().toRepresentation(async (value) => {
687
- * switch (value) {
688
- * case 'red': return { r: 255, g: 0, b: 0 };
689
- * case 'green': return { r: 0, g: 255, b: 0 };
690
- * case 'blue': return { r: 0, g: 0, b: 255 };
691
- * default: return { r: 0, g: 0, b: 0 };
692
- * }
693
- * });
694
- * ```
695
- * @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
696
- *
697
- * @returns The schema with a new return type
698
- */ key: "toRepresentation",
699
- value: function toRepresentation(toRepresentationCallback) {
700
- return _get(_get_prototype_of(NumberSchema.prototype), "toRepresentation", this).call(this, toRepresentationCallback);
701
- }
702
- },
703
- {
704
- /**
705
- * This function is used to transform the value to the internal representation of the schema. This is useful when
706
- * you want to transform the value to a type that the schema adapter can understand. For example, you might want
707
- * to transform a string to a date. This is the function you use.
708
- *
709
- * @example
710
- * ```typescript
711
- * import * as p from '@palmares/schemas';
712
- *
713
- * const dateSchema = p.string().toInternal((value) => {
714
- * return new Date(value);
715
- * });
716
- *
717
- * const date = await dateSchema.parse('2021-01-01');
718
- *
719
- * console.log(date); // Date object
720
- *
721
- * const rgbToColorSchema = p.object({
722
- * r: p.number().min(0).max(255),
723
- * g: p.number().min(0).max(255),
724
- * b: p.number().min(0).max(255),
725
- * }).toInternal(async (value) => {
726
- * if (value.r === 255 && value.g === 0 && value.b === 0) return 'red';
727
- * if (value.r === 0 && value.g === 255 && value.b === 0) return 'green';
728
- * if (value.r === 0 && value.g === 0 && value.b === 255) return 'blue';
729
- * return `rgb(${value.r}, ${value.g}, ${value.b})`;
730
- * });
731
- * ```
732
- *
733
- * @param toInternalCallback - The callback that will be called to transform the value to the internal representation.
734
- *
735
- * @returns The schema with a new return type.
736
- */ key: "toInternal",
737
- value: function toInternal(toInternalCallback) {
738
- return _get(_get_prototype_of(NumberSchema.prototype), "toInternal", this).call(this, toInternalCallback);
739
- }
740
- },
741
- {
742
- /**
743
- * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
744
- * you can convert that string to a date
745
- * here BEFORE the validation. This pretty much transforms the value to a type that the schema adapter can understand.
746
- *
747
- * @example
748
- * ```
749
- * import * as p from '@palmares/schemas';
750
- * import * as z from 'zod';
751
- *
752
- * const customRecordToMapSchema = p.schema().appendSchema(z.map()).toValidate(async (value) => {
753
- * return new Map(value); // Before validating we transform the value to a map.
754
- * });
755
- *
756
- * const { errors, parsed } = await customRecordToMapSchema.parse({ key: 'value' });
757
- * ```
758
- *
759
- * @param toValidateCallback - The callback that will be called to validate the value.
760
- *
761
- * @returns The schema with a new return type.
762
- */ key: "toValidate",
763
- value: function toValidate(toValidateCallback) {
764
- return _get(_get_prototype_of(NumberSchema.prototype), "toValidate", this).call(this, toValidateCallback);
765
- }
766
- },
767
- {
768
- /**
769
- * Defines a list of numbers that are allowed, it's not a range but the actual numbers that are allowed, it's useful
770
- * when you want to allow only specific set of numbers.
771
- *
772
- * @example
773
- * ```typescript
774
- * import * as p from '@palmares/schema';
775
- *
776
- * const schema = p.number().is([1, 2, 3]);
777
- *
778
- * schema.parse(1); // { errors: [], parsed: 1 }
779
- * schema.parse(2); // { errors: [], parsed: 2 }
780
- * schema.parse(3); // { errors: [], parsed: 3 }
781
- * schema.parse(4); // { errors: [{ code: 'is', message: 'The value should be equal to 1,2,3' }], parsed: 4 }
782
- * ```
783
- *
784
- * @param value - The list of numbers that are allowed
785
- *
786
- * @returns - The schema instance
787
- */ key: "is",
788
- value: function is(value, options) {
789
- this.__is = {
790
- value: value,
791
- message: typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The value should be equal to ".concat(value.join(','))
792
- };
793
- return this;
794
- }
795
- },
796
- {
797
- /**
798
- * Allows only numbers that are less than the value passed. If you want to allow the number to be equal to the value,
799
- * you can pass the option `inclusive` as `true`.
800
- * Otherwise, it will only allow numbers less than the value.
801
- *
802
- * @example
803
- * ```typescript
804
- * import * as p from '@palmares/schema';
805
- *
806
- * const schema = p.number().max(10);
807
- *
808
- * schema.parse(10); // { errors: [{ code: 'max', message: 'The number should be less than 10' }], parsed: 10 }
809
- * schema.parse(9); // { errors: [], parsed: 9 }
810
- *
811
- * const schema = p.number().max(10, { inclusive: true });
812
- *
813
- * schema.parse(10); // { errors: [], parsed: 10 }
814
- * ```
815
- *
816
- * @param value - The value to compare with the number
817
- * @param options - The options to be passed to the validation
818
- * @param options.inclusive - If you want to allow the number to be equal to the value, you can pass this option
819
- * @param options.message - The message to be returned if the validation fails
820
- *
821
- * @returns - The schema instance
822
- */ key: "max",
823
- value: function max(value, options) {
824
- var inclusive = typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false;
825
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : (0, _constants.DEFAULT_NUMBER_MAX_EXCEPTION)(value, inclusive);
826
- this.__max = {
827
- value: value,
828
- inclusive: inclusive,
829
- message: message
830
- };
831
- return this;
832
- }
833
- },
834
- {
835
- /**
836
- * This method will validate if the number is greater than the value passed. If you want to allow the number to be
837
- * equal to the value, you can pass the option `inclusive` as `true`.
838
- * Otherwise, it will only allow numbers greater than the value.
839
- *
840
- * @example
841
- * ```typescript
842
- * import * as p from '@palmares/schema';
843
- *
844
- * const schema = p.number().min(10);
845
- *
846
- * schema.parse(10); // { errors: [], parsed: 10 }
847
- * schema.parse(9); // { errors: [{ code: 'min', message: 'The number should be greater than 10' }], parsed: 9 }
848
- *
849
- * const schema = p.number().min(10, { inclusive: true });
850
- *
851
- * schema.parse(10); // { errors: [], parsed: 10 }
852
- * ```
853
- *
854
- * @param value - The value to compare with the number
855
- * @param options - The options to be passed to the validation
856
- * @param options.inclusive - If you want to allow the number to be equal to the value, you can pass this option
857
- * @param options.message - The message to be returned if the validation fails
858
- *
859
- * @returns - The schema instance
860
- */ key: "min",
861
- value: function min(value, options) {
862
- var inclusive = typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false;
863
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : (0, _constants.DEFAULT_NUMBER_MIN_EXCEPTION)(value, inclusive);
864
- this.__min = {
865
- value: value,
866
- inclusive: inclusive,
867
- message: message
868
- };
869
- return this;
870
- }
871
- },
872
- {
873
- /**
874
- * This method will validate the number to have the exact number of decimal places. It's usually useful for decimal
875
- * numbers like currencies.
876
- *
877
- * @example
878
- * ```
879
- * const schema = number().decimalPlaces(2);
880
- *
881
- * schema.parse(10.00); // { errors: [], parsed: 10.00}
882
- *
883
- * schema.parse(10.000);
884
- * // { errors: [{ code: 'decimal_places', message: 'The number should have 2 decimal places' }], parsed: 10.000}
885
- * ```
886
- *
887
- * @param value - The number of decimal places.
888
- * @param options - The options.
889
- * @param options.message - The message to show if the validation fails.
890
- *
891
- * @returns The schema so you can chain other methods.
892
- */ key: "decimalPlaces",
893
- value: function decimalPlaces(value, options) {
894
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The number should have ".concat(value, " decimal places");
895
- this.__decimalPlaces = {
896
- value: value,
897
- message: message
898
- };
899
- return this;
900
- }
901
- },
902
- {
903
- /**
904
- * This method will validate the number to have at most the number of digits specified. If used in conjunction with
905
- * {@link decimalPlaces}, this number should be bigger than the value of the decimal places.
906
- *
907
- * Think about that
908
- *
909
- * - If you have a number with 2 decimal places, the number 10.00 has 4 digits and 2 decimal places.
910
- * - The number 10.000 has 5 digits and 3 decimal places.
911
- *
912
- * @example
913
- * ```
914
- * const schema = number().maxDigits(4);
915
- *
916
- * schema.parse(10); // { errors: [], parsed: 10}
917
- * schema.parse(100); // { errors: [], parsed: 100}
918
- * schema.parse(1000); // { errors: [], parsed: 1000}
919
- * ```
920
- *
921
- * @param value - The maximum number of digits, counting the digits before and after the decimal point.
922
- * @param options - Custom options for the validation.
923
- * @param options.message - The message to show if the validation fails.
924
- *
925
- * @returns - The schema so you can chain other methods.
926
- */ key: "maxDigits",
927
- value: function maxDigits(value, options) {
928
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The number should have at most ".concat(value, " digits");
929
- this.__maxDigits = {
930
- value: value,
931
- message: message
932
- };
933
- return this;
934
- }
935
- },
936
- {
937
- /**
938
- * With this method we will validate if the number is an integer. If it's not, we will return an error.
939
- *
940
- * @example
941
- * ```typescript
942
- * import * as p from '@palmares/schema';
943
- *
944
- * const schema = p.number().integer();
945
- *
946
- * schema.parse(10); // { errors: [], parsed: 10 }
947
- * schema.parse(10.1); // { errors: [{ code: 'integer', message: 'The number should be an integer' }], parsed: 10.1 }
948
- * ```
949
- *
950
- * @param options - The options to be passed to the validation
951
- * @param options.message - The message to be returned if the validation fails
952
- *
953
- * @returns - The schema instance
954
- */ key: "integer",
955
- value: function integer(options) {
956
- var message = typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : (0, _constants.DEFAULT_NUMBER_INTEGER_EXCEPTION)();
957
- this.__integer = {
958
- message: message
959
- };
960
- return this;
961
- }
962
- }
963
- ], [
964
- {
965
- key: "new",
966
- value: function _new() {
967
- var returnValue = new NumberSchema();
968
- return returnValue;
969
- }
970
- }
971
- ]);
972
- return NumberSchema;
973
- }(_schema.Schema);
974
- var number = function() {
975
- return NumberSchema.new();
976
- };