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