@palmares/schemas 0.1.24 → 0.1.26

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