@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
@@ -0,0 +1,1737 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/schema/union.ts
22
+ var union_exports = {};
23
+ __export(union_exports, {
24
+ UnionSchema: () => UnionSchema,
25
+ union: () => union
26
+ });
27
+ module.exports = __toCommonJS(union_exports);
28
+
29
+ // src/exceptions.ts
30
+ var NoAdapterFoundError = class extends Error {
31
+ static {
32
+ __name(this, "NoAdapterFoundError");
33
+ }
34
+ constructor() {
35
+ super("No adapter found, please define an adapter using setDefaultAdapter() before using any schema.");
36
+ }
37
+ };
38
+
39
+ // src/conf.ts
40
+ function getDefaultAdapter() {
41
+ if (!globalThis.$PSchemasAdapter) throw new NoAdapterFoundError();
42
+ return globalThis.$PSchemasAdapter;
43
+ }
44
+ __name(getDefaultAdapter, "getDefaultAdapter");
45
+
46
+ // src/validators/schema.ts
47
+ function optional(args) {
48
+ return {
49
+ name: "optional",
50
+ type: "high",
51
+ // eslint-disable-next-line ts/require-await
52
+ callback: /* @__PURE__ */ __name(async (value, path) => {
53
+ if (value === void 0) {
54
+ if (args.allow === true) return {
55
+ parsed: value,
56
+ errors: [],
57
+ preventChildValidation: true
58
+ };
59
+ return {
60
+ parsed: value,
61
+ errors: [
62
+ {
63
+ isValid: false,
64
+ message: args.message,
65
+ code: "required",
66
+ // eslint-disable-next-line ts/no-unnecessary-condition
67
+ path: path || []
68
+ }
69
+ ],
70
+ preventChildValidation: true
71
+ };
72
+ }
73
+ return {
74
+ parsed: value,
75
+ errors: [],
76
+ preventChildValidation: false
77
+ };
78
+ }, "callback")
79
+ };
80
+ }
81
+ __name(optional, "optional");
82
+ function nullable(args) {
83
+ return {
84
+ name: "nullable",
85
+ type: "high",
86
+ // eslint-disable-next-line ts/require-await
87
+ callback: /* @__PURE__ */ __name(async (value, path) => {
88
+ if (value === null) {
89
+ if (args.allow === true) return {
90
+ parsed: value,
91
+ errors: [],
92
+ preventChildValidation: true
93
+ };
94
+ return {
95
+ parsed: value,
96
+ errors: [
97
+ {
98
+ isValid: false,
99
+ message: args.message,
100
+ code: "null",
101
+ // eslint-disable-next-line ts/no-unnecessary-condition
102
+ path: path || []
103
+ }
104
+ ],
105
+ preventChildValidation: true
106
+ };
107
+ }
108
+ return {
109
+ parsed: value,
110
+ errors: [],
111
+ preventChildValidation: false
112
+ };
113
+ }, "callback")
114
+ };
115
+ }
116
+ __name(nullable, "nullable");
117
+ function checkType(args) {
118
+ return {
119
+ name: "checkType",
120
+ type: "medium",
121
+ // eslint-disable-next-line ts/require-await
122
+ callback: /* @__PURE__ */ __name(async (value, path) => {
123
+ if (args.check(value)) return {
124
+ parsed: value,
125
+ errors: [],
126
+ preventChildValidation: false
127
+ };
128
+ return {
129
+ parsed: value,
130
+ errors: [
131
+ {
132
+ isValid: false,
133
+ message: args.message,
134
+ code: "invalid_type",
135
+ // eslint-disable-next-line ts/no-unnecessary-condition
136
+ path: path || []
137
+ }
138
+ ],
139
+ preventChildValidation: true
140
+ };
141
+ }, "callback")
142
+ };
143
+ }
144
+ __name(checkType, "checkType");
145
+
146
+ // src/validators/utils.ts
147
+ var priorityByType = {
148
+ low: 0,
149
+ medium: 1,
150
+ high: 2
151
+ };
152
+ var typeByPriority = Object.entries(priorityByType).reduce((acc, [key, value]) => {
153
+ acc[value] = key;
154
+ return acc;
155
+ }, {});
156
+ var Validator = class _Validator {
157
+ static {
158
+ __name(this, "Validator");
159
+ }
160
+ $$type = "$PValidator";
161
+ child;
162
+ parent;
163
+ fallbackNamesAdded = /* @__PURE__ */ new Set();
164
+ priority;
165
+ fallbacks = [];
166
+ constructor(type) {
167
+ this.fallbackNamesAdded = /* @__PURE__ */ new Set();
168
+ this.fallbacks = [];
169
+ this.priority = priorityByType[type];
170
+ }
171
+ /**
172
+ * We create all of the validators on the schema in order, i actually didn't want to go on that route but i
173
+ * found it easier to do so.
174
+ *
175
+ * The logic here is simple, if it's not the same priority we will walk on the linked list until we find
176
+ * a validator that matches the priority we are expecting. If we can't walk anymore, we create the next
177
+ * priority validator and append it to the linked list. Be aware that it's a double linked list, so we
178
+ * can walk both ways, from the end to the start and from the start to the end.
179
+ * So you don't really need to start from the root, the linked list can start from anywhere and it will
180
+ * find it's way through.
181
+ *
182
+ * I know there are better ways to do this instead of walking through the linked list, but like i explained
183
+ * before, this is enough for now.
184
+ *
185
+ * If the priority is higher than the current priority saved on the schema, we should substitute the
186
+ * rootValidator on the schema with the new one.
187
+ *
188
+ * @param schema - The schema that we are working on right now, all fallbacks are tied to that specific schema.
189
+ * @param type - The type of the fallback that we are adding.
190
+ * @param fallback - The fallback function that we are adding.
191
+ * @param childOrParent - If we are adding a fallback to the child or to the parent.
192
+ * @param options - The options that we are passing to the fallback.
193
+ */
194
+ checkAppendOrCreate(schema2, type, fallbackName, fallback, childOrParent, options) {
195
+ const schemaWithProtected = schema2;
196
+ if (this[childOrParent]) this[childOrParent].addFallback(schemaWithProtected, type, fallbackName, fallback, options);
197
+ else {
198
+ const nextPriority = childOrParent === "child" ? this.priority - 1 : this.priority + 1;
199
+ if (Object.keys(typeByPriority).includes(String(nextPriority))) {
200
+ const nextType = typeByPriority[nextPriority];
201
+ const validatorInstance = new _Validator(nextType);
202
+ this[childOrParent] = validatorInstance;
203
+ this[childOrParent][childOrParent === "parent" ? "child" : "parent"] = this;
204
+ this[childOrParent].addFallback(schemaWithProtected, type, fallbackName, fallback, options);
205
+ if (nextPriority > schemaWithProtected.__rootFallbacksValidator.priority) schemaWithProtected.__rootFallbacksValidator = validatorInstance;
206
+ }
207
+ }
208
+ }
209
+ addFallback(schema2, type, fallbackName, fallback, options) {
210
+ if (this.fallbackNamesAdded.has(fallbackName) && options?.removeCurrent !== true) return;
211
+ this.fallbackNamesAdded.add(fallbackName);
212
+ const priority = priorityByType[type];
213
+ if (this.priority === priority) {
214
+ if (typeof options?.at === "number") this.fallbacks.splice(options.at, options.removeCurrent === true ? 1 : 0, fallback);
215
+ else this.fallbacks.push(fallback);
216
+ } else if (priority > this.priority) this.checkAppendOrCreate(schema2, type, fallbackName, fallback, "parent", options);
217
+ else if (priority < this.priority) this.checkAppendOrCreate(schema2, type, fallbackName, fallback, "child", options);
218
+ }
219
+ /**
220
+ * Validates the value against all of the fallbacks, the fallbacks are executed in order, from the highest
221
+ * priority to the lowest priority. A validator can stop the execution of the other validators if it feels
222
+ * like so. Like on the example of a value being null or undefined.
223
+ *
224
+ * @param errorsAsHashedSet - This is a set that contains all of the errors that we already found, this is
225
+ * used to avoid duplicated errors.
226
+ * @param path - The path that we are validating right now.
227
+ * @param parseResult - The result of the parsing, it contains the parsed value and the errors that we found.
228
+ * @param options - The options that we are passing to the fallback.
229
+ */
230
+ async validate(errorsAsHashedSet, path, parseResult, options) {
231
+ let doesItShouldPreventChildValidation = false;
232
+ for (const fallback of this.fallbacks) {
233
+ const { parsed, errors, preventChildValidation } = await fallback(parseResult.parsed, path, options);
234
+ parseResult.parsed = parsed;
235
+ for (const error of errors) {
236
+ if (error.isValid === false) {
237
+ const sortedError = Object.fromEntries(Object.entries(error).sort(([a], [b]) => a.localeCompare(b)));
238
+ const hashedError = JSON.stringify(sortedError);
239
+ if (errorsAsHashedSet.has(hashedError)) continue;
240
+ errorsAsHashedSet.add(hashedError);
241
+ if (!Array.isArray(parseResult.errors)) parseResult.errors = [];
242
+ parseResult.errors.push({
243
+ ...error,
244
+ received: parseResult.parsed
245
+ });
246
+ }
247
+ }
248
+ doesItShouldPreventChildValidation = doesItShouldPreventChildValidation || preventChildValidation || false;
249
+ }
250
+ if (this.child && doesItShouldPreventChildValidation === false) return await this.child.validate(errorsAsHashedSet, path, parseResult, options);
251
+ return parseResult;
252
+ }
253
+ /**
254
+ * This static method takes care of everything for you. This means that you should only call this method
255
+ * for appending new fallbacks, it takes care of creating the root validator and making sure that the
256
+ * rootValidator on the schema is the highest priority one.
257
+ *
258
+ * @param schema - The schema that we are working on right now, all fallbacks are tied to that specific
259
+ * schema. We automatically define the rootValidator on the schema so you don't need to worry about that.
260
+ * @param fallback - The fallback that we are adding. This is an object that contains the type of the
261
+ * fallback and the callback that we are adding.
262
+ * @param options - The options that we are passing to the fallback. Options like `at` and `removeCurrent`
263
+ * are passed to the `addFallback` method.
264
+ */
265
+ static createAndAppendFallback(schema2, fallback, options) {
266
+ const schemaWithProtected = schema2;
267
+ let validatorInstance = schemaWithProtected.__rootFallbacksValidator;
268
+ if (schemaWithProtected.__rootFallbacksValidator === void 0) {
269
+ validatorInstance = new _Validator(fallback.type);
270
+ schemaWithProtected.__rootFallbacksValidator = validatorInstance;
271
+ }
272
+ validatorInstance.addFallback(schema2, fallback.type, fallback.name, fallback.callback, options);
273
+ return validatorInstance;
274
+ }
275
+ toString(ident = 0) {
276
+ return `Priority: ${this.priority}
277
+ Fallbacks: ${this.fallbacks.length}
278
+ ${this.child ? `Children:
279
+ ${this.child.toString(ident + 2)}` : ""}`;
280
+ }
281
+ };
282
+
283
+ // src/utils.ts
284
+ var WithFallback = class {
285
+ static {
286
+ __name(this, "WithFallback");
287
+ }
288
+ $$type = "$PWithFallback";
289
+ fallbackFor;
290
+ transformedSchema;
291
+ adapterType;
292
+ constructor(adapterType, fallbackFor, transformedSchema) {
293
+ this.adapterType = adapterType;
294
+ this.fallbackFor = new Set(fallbackFor);
295
+ this.transformedSchema = transformedSchema;
296
+ }
297
+ };
298
+ function withFallbackFactory(adapterType) {
299
+ return (fallbackFor, transformedSchema) => new WithFallback(adapterType, fallbackFor, transformedSchema);
300
+ }
301
+ __name(withFallbackFactory, "withFallbackFactory");
302
+ async function defaultTransform(type, schema2, adapter, fieldAdapter, getValidationData, fallbackFunctions, options) {
303
+ const validationData = await Promise.resolve(getValidationData(false));
304
+ const validationDataForStringVersion = options.shouldAddStringVersion ? await Promise.resolve(getValidationData(true)) : void 0;
305
+ const schemaWithPrivateFields = schema2;
306
+ const checkIfShouldUseParserAndAppend = /* @__PURE__ */ __name((parser) => {
307
+ const isValidationDataAParser = validationData.parsers?.[parser] !== void 0;
308
+ if (isValidationDataAParser) schema2.__parsers._fallbacks.add(parser);
309
+ }, "checkIfShouldUseParserAndAppend");
310
+ const getExtendedOrNotSchemaAndString = /* @__PURE__ */ __name((schema3, toStringVersion) => {
311
+ const extendedOrNotSchema2 = typeof schemaWithPrivateFields.__extends?.callback === "function" ? schemaWithPrivateFields.__extends.callback(schema3) : schema3;
312
+ const extendedOrNotSchemaString2 = typeof schemaWithPrivateFields.__extends?.toStringCallback === "function" ? schemaWithPrivateFields.__extends.toStringCallback(toStringVersion) : toStringVersion;
313
+ return [
314
+ extendedOrNotSchema2,
315
+ extendedOrNotSchemaString2
316
+ ];
317
+ }, "getExtendedOrNotSchemaAndString");
318
+ const checkIfShouldAppendFallbackAndAppend = /* @__PURE__ */ __name((fallback) => {
319
+ const wereArgumentsForThatFallbackDefinedAndFallbackFunctionDefined = validationData[fallback] !== void 0 && fallbackFunctions[fallback] !== void 0;
320
+ if (wereArgumentsForThatFallbackDefinedAndFallbackFunctionDefined) {
321
+ const fallbackReturnType = fallbackFunctions[fallback](validationData[fallback]);
322
+ Validator.createAndAppendFallback(schema2, fallbackReturnType);
323
+ }
324
+ }, "checkIfShouldAppendFallbackAndAppend");
325
+ const appendRootFallback = /* @__PURE__ */ __name(() => {
326
+ if (options.validatorsIfFallbackOrNotSupported) {
327
+ const validatorsIfFallbackOrNotSupported = Array.isArray(options.validatorsIfFallbackOrNotSupported) ? options.validatorsIfFallbackOrNotSupported : [
328
+ options.validatorsIfFallbackOrNotSupported
329
+ ];
330
+ for (const fallback of validatorsIfFallbackOrNotSupported) Validator.createAndAppendFallback(schema2, fallback);
331
+ }
332
+ }, "appendRootFallback");
333
+ const appendRequiredFallbacks = /* @__PURE__ */ __name(() => {
334
+ const hasFallbacks = schemaWithPrivateFields.__rootFallbacksValidator?.["$$type"] === "$PValidator";
335
+ if (hasFallbacks) {
336
+ Validator.createAndAppendFallback(schema2, optional(schemaWithPrivateFields.__optional));
337
+ Validator.createAndAppendFallback(schema2, nullable(schemaWithPrivateFields.__nullable));
338
+ Validator.createAndAppendFallback(schema2, checkType(schemaWithPrivateFields.__type));
339
+ }
340
+ }, "appendRequiredFallbacks");
341
+ const isFieldAdapterNotSupportedForThatFieldType = fieldAdapter === void 0;
342
+ if (options.fallbackIfNotSupported !== void 0 && isFieldAdapterNotSupportedForThatFieldType) {
343
+ const existingFallbacks = Object.keys(fallbackFunctions);
344
+ const allParsers = Object.keys(validationData["parsers"]);
345
+ appendRootFallback();
346
+ for (const fallback of existingFallbacks) checkIfShouldAppendFallbackAndAppend(fallback);
347
+ for (const parser of allParsers) checkIfShouldUseParserAndAppend(parser);
348
+ appendRequiredFallbacks();
349
+ return options.fallbackIfNotSupported();
350
+ }
351
+ if (!fieldAdapter) throw new Error("The field adapter is not supported and no fallback was provided.");
352
+ const translatedSchemaOrWithFallback = await Promise.resolve(fieldAdapter.translate(adapter.field, {
353
+ withFallback: withFallbackFactory(type),
354
+ ...validationData
355
+ }));
356
+ let stringVersion = "";
357
+ if (options.shouldAddStringVersion) stringVersion = await fieldAdapter.toString(adapter, adapter.field, validationDataForStringVersion);
358
+ if (translatedSchemaOrWithFallback?.["$$type"] === "$PWithFallback") {
359
+ appendRootFallback();
360
+ for (const fallback of translatedSchemaOrWithFallback.fallbackFor) {
361
+ checkIfShouldAppendFallbackAndAppend(fallback);
362
+ checkIfShouldUseParserAndAppend(fallback);
363
+ }
364
+ const [extendedOrNotSchema2, extendedOrNotSchemaString2] = getExtendedOrNotSchemaAndString(translatedSchemaOrWithFallback.transformedSchema, stringVersion);
365
+ appendRequiredFallbacks();
366
+ return [
367
+ {
368
+ transformed: extendedOrNotSchema2,
369
+ asString: extendedOrNotSchemaString2
370
+ }
371
+ ];
372
+ }
373
+ const [extendedOrNotSchema, extendedOrNotSchemaString] = getExtendedOrNotSchemaAndString(translatedSchemaOrWithFallback, stringVersion);
374
+ return [
375
+ {
376
+ transformed: extendedOrNotSchema,
377
+ asString: extendedOrNotSchemaString
378
+ }
379
+ ];
380
+ }
381
+ __name(defaultTransform, "defaultTransform");
382
+ async function defaultTransformToAdapter(callback, schema2, transformedSchemas, options, type) {
383
+ const isTransformedSchemasEmpty = Object.keys(transformedSchemas).length <= 0;
384
+ if (isTransformedSchemasEmpty) {
385
+ const adapterInstanceToUse = (
386
+ // eslint-disable-next-line ts/no-unnecessary-condition
387
+ options.schemaAdapter?.["$$type"] === "$PSchemaAdapter" ? options.schemaAdapter : getDefaultAdapter()
388
+ );
389
+ schema2["__transformedSchemas"][adapterInstanceToUse.name] = {
390
+ transformed: false,
391
+ adapter: adapterInstanceToUse,
392
+ schemas: []
393
+ };
394
+ }
395
+ const schemaAdapterNameToUse = options.schemaAdapter?.name || Object.keys(transformedSchemas)[0];
396
+ const isACustomSchemaAdapterAndNotYetDefined = (
397
+ // eslint-disable-next-line ts/no-unnecessary-condition
398
+ transformedSchemas[schemaAdapterNameToUse] === void 0 && options.schemaAdapter !== void 0
399
+ );
400
+ if (isACustomSchemaAdapterAndNotYetDefined) transformedSchemas[schemaAdapterNameToUse] = {
401
+ transformed: false,
402
+ adapter: options.schemaAdapter,
403
+ schemas: []
404
+ };
405
+ const shouldTranslate = transformedSchemas[schemaAdapterNameToUse].transformed === false || options.force === true;
406
+ if (shouldTranslate) {
407
+ const translatedSchemas = await callback(transformedSchemas[schemaAdapterNameToUse].adapter);
408
+ transformedSchemas[schemaAdapterNameToUse].schemas = translatedSchemas;
409
+ transformedSchemas[schemaAdapterNameToUse].transformed = true;
410
+ }
411
+ transformedSchemas[schemaAdapterNameToUse].transformed = true;
412
+ return transformedSchemas[schemaAdapterNameToUse].schemas;
413
+ }
414
+ __name(defaultTransformToAdapter, "defaultTransformToAdapter");
415
+ async function formatErrorFromParseMethod(adapter, fieldAdapter, error, received, schema2, path, errorsAsHashedSet) {
416
+ const formattedError = await fieldAdapter.formatError(adapter, adapter.field, schema2, error);
417
+ formattedError.path = Array.isArray(formattedError.path) ? [
418
+ ...path,
419
+ ...formattedError.path
420
+ ] : path;
421
+ const formattedErrorAsParseResultError = formattedError;
422
+ formattedErrorAsParseResultError.isValid = false;
423
+ const sortedError = Object.fromEntries(Object.entries(formattedErrorAsParseResultError).sort(([a], [b]) => a.localeCompare(b)));
424
+ const hashedError = JSON.stringify(sortedError);
425
+ errorsAsHashedSet.add(JSON.stringify(sortedError));
426
+ formattedErrorAsParseResultError.received = received;
427
+ return formattedErrorAsParseResultError;
428
+ }
429
+ __name(formatErrorFromParseMethod, "formatErrorFromParseMethod");
430
+ async function transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas(schema2, options) {
431
+ const schemaWithProtected = schema2;
432
+ const transformedData = await schemaWithProtected.__transformToAdapter(options);
433
+ const doesKeyHaveFallback = schemaWithProtected.__rootFallbacksValidator !== void 0;
434
+ const doesKeyHaveToInternal = typeof schemaWithProtected.__toInternal === "function";
435
+ const doesKeyHaveToValidate = typeof schemaWithProtected.__toValidate === "function";
436
+ const doesKeyHaveToDefault = typeof schemaWithProtected.__defaultFunction === "function";
437
+ const doesKeyHaveRunBeforeParseAndData = typeof schemaWithProtected.__runBeforeParseAndData === "function";
438
+ const doesKeyHaveParserFallback = schemaWithProtected.__parsers._fallbacks.size > 0;
439
+ const shouldAddFallbackValidation = doesKeyHaveFallback || doesKeyHaveToInternal || doesKeyHaveToValidate || doesKeyHaveToDefault || doesKeyHaveParserFallback || doesKeyHaveRunBeforeParseAndData || // eslint-disable-next-line ts/no-unnecessary-condition
440
+ transformedData === void 0;
441
+ return [
442
+ transformedData,
443
+ shouldAddFallbackValidation
444
+ ];
445
+ }
446
+ __name(transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas, "transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas");
447
+
448
+ // src/schema/schema.ts
449
+ var Schema = class _Schema {
450
+ static {
451
+ __name(this, "Schema");
452
+ }
453
+ $$type = "$PSchema";
454
+ fieldType = "schema";
455
+ // Those functions will assume control of the validation process on adapters, instead of the schema.
456
+ // Why this is used? The idea is that the Schema has NO idea
457
+ // that one of it's children might be an UnionSchema for example. The adapter might not support unions,
458
+ // so then we give control to the union. The parent schema will already have an array of translated
459
+ // adapter schemas. This means for a union with Number and String it'll generate two schemas, one for number
460
+ // and one for the value as String. Of course this gets multiplied. So if we have a union with Number and String.
461
+ // We should take those two schemas from the array and validate them individually. This logic is
462
+ // handled by the union schema. If we have an intersection type for example, instead of validating
463
+ // One schema OR the other, we validate one schema AND the other. This will be handled
464
+ // by the schema that contains that intersection logic.
465
+ __beforeValidationCallbacks = /* @__PURE__ */ new Map();
466
+ __cachedGetParent;
467
+ set __getParent(value) {
468
+ this.__cachedGetParent = value;
469
+ }
470
+ get __getParent() {
471
+ return this.__cachedGetParent;
472
+ }
473
+ __alreadyAppliedModel;
474
+ __runBeforeParseAndData;
475
+ __rootFallbacksValidator;
476
+ __saveCallback;
477
+ __modelOmitCallback;
478
+ __parsers = {
479
+ high: /* @__PURE__ */ new Map(),
480
+ medium: /* @__PURE__ */ new Map(),
481
+ low: /* @__PURE__ */ new Map(),
482
+ _fallbacks: /* @__PURE__ */ new Set()
483
+ };
484
+ __refinements = [];
485
+ __nullable = {
486
+ message: "Cannot be null",
487
+ allow: false
488
+ };
489
+ __optional = {
490
+ message: "Required",
491
+ allow: false
492
+ };
493
+ __extends = void 0;
494
+ __transformedSchemas = {};
495
+ __defaultFunction = void 0;
496
+ __toRepresentation = void 0;
497
+ __toValidate = void 0;
498
+ __toInternal = void 0;
499
+ __type = {
500
+ message: "Invalid type",
501
+ check: /* @__PURE__ */ __name(() => true, "check")
502
+ };
503
+ __getDefaultTransformedSchemas() {
504
+ const adapterInstance = getDefaultAdapter();
505
+ if (this.__transformedSchemas[adapterInstance.constructor.name] === void 0) this.__transformedSchemas[adapterInstance.constructor.name] = {
506
+ transformed: false,
507
+ adapter: adapterInstance,
508
+ schemas: []
509
+ };
510
+ }
511
+ /**
512
+ * This will validate the data with the fallbacks, so internally, without relaying on the schema adapter.
513
+ * This is nice because we can support things that the schema adapter is not able to support by default.
514
+ *
515
+ * @param errorsAsHashedSet - The errors as a hashed set. This is used to prevent duplicate errors.
516
+ * @param path - The path of the error.
517
+ * @param parseResult - The result of the parse method.
518
+ */
519
+ async __validateByFallbacks(path, parseResult, options) {
520
+ if (this.__rootFallbacksValidator) return this.__rootFallbacksValidator.validate(options.errorsAsHashedSet, path, parseResult, options);
521
+ return parseResult;
522
+ }
523
+ /**
524
+ * This will validate by the adapter. In other words, we send the data to the schema adapter and then we validate
525
+ * that data.
526
+ * So understand that, first we send the data to the adapter, the adapter validates it, then, after we validate
527
+ * from the adapter we validate with the fallbacks so we can do all of the extra validations not handled by
528
+ * the adapter.
529
+ *
530
+ * @param value - The value to be validated.
531
+ * @param errorsAsHashedSet - The errors as a hashed set. This is used to prevent duplicate errors on the validator.
532
+ * @param path - The path of the error so we can construct an object with the nested paths of the error.
533
+ * @param parseResult - The result of the parse method.
534
+ *
535
+ * @returns The result and the errors of the parse method.
536
+ */
537
+ async __validateByAdapter(adapter, fieldAdapter, schema2, value, path, options) {
538
+ const parseResult = {
539
+ errors: [],
540
+ parsed: value
541
+ };
542
+ parseResult.errors = [];
543
+ parseResult.parsed = value;
544
+ if (fieldAdapter === void 0 || typeof fieldAdapter.parse !== "function") return parseResult;
545
+ const adapterParseResult = await fieldAdapter.parse(adapter, adapter.field, schema2.transformed, value, options.args);
546
+ parseResult.parsed = adapterParseResult.parsed;
547
+ if (adapterParseResult.errors) {
548
+ if (Array.isArray(adapterParseResult.errors)) parseResult.errors = await Promise.all(adapterParseResult.errors.map(async (error) => formatErrorFromParseMethod(adapter, fieldAdapter, error, value, schema2.transformed, path, options.errorsAsHashedSet || /* @__PURE__ */ new Set())));
549
+ else parseResult.errors = [
550
+ await formatErrorFromParseMethod(adapter, fieldAdapter, parseResult.errors, value, schema2.transformed, path, options.errorsAsHashedSet || /* @__PURE__ */ new Set())
551
+ ];
552
+ }
553
+ parseResult.errors = parseResult.errors.filter((error) => typeof error !== "undefined");
554
+ return parseResult;
555
+ }
556
+ // eslint-disable-next-line ts/require-await
557
+ async __transformToAdapter(_options) {
558
+ throw new Error("Not implemented");
559
+ }
560
+ /** */
561
+ async __parsersToTransformValue(value, parsersToUse) {
562
+ let shouldStop = false;
563
+ for (const [parserName, parser] of this.__parsers.high.entries()) {
564
+ if (parsersToUse instanceof Set === false || parsersToUse.has(parserName)) {
565
+ const result = await Promise.resolve(parser(value));
566
+ if (result.preventNextParsers) shouldStop = true;
567
+ value = result.value;
568
+ } else continue;
569
+ }
570
+ if (shouldStop === false) {
571
+ for (const [parserName, parser] of this.__parsers.medium.entries()) {
572
+ if (parsersToUse instanceof Set === false || parsersToUse.has(parserName)) {
573
+ const result = await Promise.resolve(parser(value));
574
+ if (result.preventNextParsers) shouldStop = true;
575
+ value = result.value;
576
+ } else continue;
577
+ }
578
+ }
579
+ if (shouldStop === false) {
580
+ for (const [parserName, parser] of this.__parsers.low.entries()) {
581
+ if (parsersToUse instanceof Set === false || parsersToUse.has(parserName)) {
582
+ const result = await Promise.resolve(parser(value));
583
+ if (result.preventNextParsers) shouldStop = true;
584
+ value = result.value;
585
+ } else continue;
586
+ }
587
+ }
588
+ return value;
589
+ }
590
+ async __parse(value, path = [], options) {
591
+ this.__getDefaultTransformedSchemas();
592
+ if (typeof this.__runBeforeParseAndData === "function") await this.__runBeforeParseAndData(this);
593
+ const shouldRunToInternalToBubbleUp = options.toInternalToBubbleUp === void 0;
594
+ if (shouldRunToInternalToBubbleUp) options.toInternalToBubbleUp = [];
595
+ if (options.errorsAsHashedSet instanceof Set === false) options.errorsAsHashedSet = /* @__PURE__ */ new Set();
596
+ const shouldCallDefaultFunction = value === void 0 && typeof this.__defaultFunction === "function";
597
+ const shouldCallToValidateCallback = typeof this.__toValidate === "function";
598
+ const schemaAdapterFieldType = this.fieldType;
599
+ if (shouldCallDefaultFunction) value = await this.__defaultFunction();
600
+ if (shouldCallToValidateCallback) value = await Promise.resolve(this.__toValidate(value));
601
+ const parseResult = {
602
+ errors: [],
603
+ parsed: value
604
+ };
605
+ value = await this.__parsersToTransformValue(value, this.__parsers._fallbacks);
606
+ if (options.appendFallbacksBeforeAdapterValidation === void 0) options.appendFallbacksBeforeAdapterValidation = (schema2, name, callback) => {
607
+ if (this !== schema2) this.__beforeValidationCallbacks.set(name, callback);
608
+ };
609
+ if (this.__transformedSchemas[options.schemaAdapter?.constructor.name || getDefaultAdapter().constructor.name].transformed === false) await this.__transformToAdapter(options);
610
+ const adapterToUse = options.schemaAdapter ? options.schemaAdapter : Object.values(this.__transformedSchemas)[0].adapter;
611
+ const parsedResultsAfterFallbacks = await this.__validateByFallbacks(path, {
612
+ errors: parseResult.errors,
613
+ parsed: value
614
+ }, options);
615
+ parseResult.parsed = parsedResultsAfterFallbacks.parsed;
616
+ parseResult.errors = (parseResult.errors || []).concat(parsedResultsAfterFallbacks.errors || []);
617
+ if (this.__beforeValidationCallbacks.size > 0) {
618
+ for (const callback of this.__beforeValidationCallbacks.values()) {
619
+ const parsedValuesAfterValidationCallbacks = await callback(adapterToUse, adapterToUse[schemaAdapterFieldType], this, this.__transformedSchemas[adapterToUse.constructor.name].schemas, value, path, options);
620
+ parseResult.parsed = parsedValuesAfterValidationCallbacks.parsed;
621
+ parseResult.errors = Array.isArray(parseResult.errors) && Array.isArray(parsedValuesAfterValidationCallbacks.errors) ? [
622
+ ...parseResult.errors,
623
+ ...parsedValuesAfterValidationCallbacks.errors
624
+ ] : Array.isArray(parseResult.errors) ? parseResult.errors : parsedValuesAfterValidationCallbacks.errors;
625
+ }
626
+ } else {
627
+ const parsedValuesAfterValidatingByAdapter = await this.__validateByAdapter(adapterToUse, adapterToUse[schemaAdapterFieldType], this.__transformedSchemas[adapterToUse.constructor.name].schemas[0], value, path, options);
628
+ parseResult.parsed = parsedValuesAfterValidatingByAdapter.parsed;
629
+ parseResult.errors = (parseResult.errors || []).concat(parsedValuesAfterValidatingByAdapter.errors);
630
+ }
631
+ const hasToInternalCallback = typeof this.__toInternal === "function";
632
+ const shouldCallToInternalDuringParse = hasToInternalCallback && (options.toInternalToBubbleUp?.length === 0 || Array.isArray(options.toInternalToBubbleUp) === false);
633
+ const hasNoErrors = parseResult.errors === void 0 || (parseResult.errors || []).length === 0;
634
+ await Promise.all(this.__refinements.map(async (refinement) => {
635
+ const errorOrNothing = await Promise.resolve(refinement(parseResult.parsed));
636
+ if (typeof errorOrNothing === "undefined") return;
637
+ parseResult.errors.push({
638
+ isValid: false,
639
+ code: errorOrNothing.code,
640
+ message: errorOrNothing.message,
641
+ received: parseResult.parsed,
642
+ path
643
+ });
644
+ }));
645
+ if (shouldCallToInternalDuringParse && hasNoErrors) parseResult.parsed = await this.__toInternal(value);
646
+ if (shouldRunToInternalToBubbleUp && hasNoErrors) for (const functionToModifyResult of options.toInternalToBubbleUp || []) await functionToModifyResult();
647
+ return parseResult;
648
+ }
649
+ /**
650
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something
651
+ * that is not supported by default by the schema adapter.
652
+ *
653
+ * @example
654
+ * ```typescript
655
+ * import * as p from '@palmares/schemas';
656
+ *
657
+ * const numberSchema = p.number().refine((value) => {
658
+ * if (value < 0) return { code: 'invalid_number', message: 'The number should be greater than 0' };
659
+ * });
660
+ *
661
+ * const { errors, parsed } = await numberSchema.parse(-1);
662
+ *
663
+ * console.log(errors);
664
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
665
+ * ```
666
+ *
667
+ * @param refinementCallback - The callback that will be called to validate the value.
668
+ * @param options - Options for the refinement.
669
+ * @param options.isAsync - Whether the callback is async or not. Defaults to true.
670
+ */
671
+ refine(refinementCallback) {
672
+ this.__refinements.push(refinementCallback);
673
+ return this;
674
+ }
675
+ /**
676
+ * Allows the value to be either undefined or null.
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * import * as p from '@palmares/schemas';
681
+ *
682
+ * const numberSchema = p.number().optional();
683
+ *
684
+ * const { errors, parsed } = await numberSchema.parse(undefined);
685
+ *
686
+ * console.log(parsed); // undefined
687
+ *
688
+ * const { errors, parsed } = await numberSchema.parse(null);
689
+ *
690
+ * console.log(parsed); // null
691
+ *
692
+ * const { errors, parsed } = await numberSchema.parse(1);
693
+ *
694
+ * console.log(parsed); // 1
695
+ * ```
696
+ *
697
+ * @returns - The schema we are working with.
698
+ */
699
+ optional(options) {
700
+ this.__optional = {
701
+ message: typeof options?.message === "string" ? options.message : "Required",
702
+ allow: typeof options?.allow === "boolean" ? options.allow : true
703
+ };
704
+ return this;
705
+ }
706
+ /**
707
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when
708
+ * the value is NULL by setting the { message: 'Your custom message', allow: false } on the options.
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * import * as p from '@palmares/schemas';
713
+ *
714
+ * const numberSchema = p.number().nullable();
715
+ *
716
+ * const { errors, parsed } = await numberSchema.parse(null);
717
+ *
718
+ * console.log(parsed); // null
719
+ *
720
+ * const { errors, parsed } = await numberSchema.parse(undefined);
721
+ *
722
+ * console.log(errors); // [{ isValid: false, code: 'invalid_type', message: 'Invalid type', path: [] }]
723
+ * ```
724
+ *
725
+ * @param options - The options for the nullable function.
726
+ * @param options.message - The message to be shown when the value is not null. Defaults to 'Cannot be null'.
727
+ * @param options.allow - Whether the value can be null or not. Defaults to true.
728
+ *
729
+ * @returns The schema.
730
+ */
731
+ nullable(options) {
732
+ this.__nullable = {
733
+ message: typeof options?.message === "string" ? options.message : "Cannot be null",
734
+ allow: typeof options?.allow === "boolean" ? options.allow : true
735
+ };
736
+ return this;
737
+ }
738
+ /**
739
+ * Appends a custom schema to the schema, this way it will bypass the creation of the schema in runtime.
740
+ *
741
+ * By default when validating, on the first validation we create the schema. Just during the first validation.
742
+ * With this function, you bypass that, so you can speed up the validation process.
743
+ *
744
+ * @example
745
+ * ```typescript
746
+ * import * as p from '@palmares/schemas';
747
+ * import * as z from 'zod';
748
+ *
749
+ * const numberSchema = p.number().appendSchema(z.number());
750
+ *
751
+ * const { errors, parsed } = await numberSchema.parse(1);
752
+ * ```
753
+ *
754
+ * @param schema - The schema to be appended.
755
+ * @param args - The arguments for the schema.
756
+ * @param args.adapter - The adapter to be used. If not provided, the default adapter will be used.
757
+ *
758
+ * @returns The same schema again.
759
+ */
760
+ appendSchema(schema2, args) {
761
+ const adapter = args?.adapter || getDefaultAdapter();
762
+ this.__transformedSchemas[adapter.constructor.name] = {
763
+ transformed: true,
764
+ adapter,
765
+ schemas: [
766
+ schema2
767
+ ]
768
+ };
769
+ return this;
770
+ }
771
+ /**
772
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
773
+ * that way otherwise it will set the value to undefined after it's validated.
774
+ * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
775
+ * function. This will remove the value from the representation of the schema.
776
+ *
777
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
778
+ * function. But if you want to remove the value from the internal representation, you can pass the argument
779
+ * `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
780
+ * the argument `toRepresentation` as true as well.
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * import * as p from '@palmares/schemas';
785
+ *
786
+ * const userSchema = p.object({
787
+ * id: p.number().optional(),
788
+ * name: p.string(),
789
+ * password: p.string().omit()
790
+ * });
791
+ *
792
+ * const user = await userSchema.data({
793
+ * id: 1,
794
+ * name: 'John Doe',
795
+ * password: '123456'
796
+ * });
797
+ *
798
+ * console.log(user); // { id: 1, name: 'John Doe' }
799
+ * ```
800
+ *
801
+ *
802
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
803
+ * the {@link data} function.
804
+ * But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
805
+ * as true. Then if you still want to remove the value from the representation, you will need to pass the
806
+ * argument `toRepresentation` as true as well.
807
+ *
808
+ * @returns The schema.
809
+ */
810
+ omit(args) {
811
+ const toRepresentation = typeof args?.toRepresentation === "boolean" ? args.toRepresentation : typeof args?.toInternal !== "boolean";
812
+ const toInternal = typeof args?.toInternal === "boolean" ? args.toInternal : false;
813
+ if (toInternal) {
814
+ if (this.__toInternal) {
815
+ const toInternal2 = this.__toInternal;
816
+ this.__toInternal = async (value) => {
817
+ await toInternal2(value);
818
+ return void 0;
819
+ };
820
+ } else this.__toInternal = async () => void 0;
821
+ } else if (toRepresentation) {
822
+ if (this.__toRepresentation) {
823
+ const toRepresentation2 = this.__toRepresentation;
824
+ this.__toRepresentation = async (value) => {
825
+ await toRepresentation2(value);
826
+ return void 0;
827
+ };
828
+ } else this.__toRepresentation = async () => void 0;
829
+ }
830
+ return this;
831
+ }
832
+ /**
833
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
834
+ * source like a database. You should always return the schema after you save the value, that way we will always have
835
+ * the correct type of the schema after the save operation.
836
+ *
837
+ * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
838
+ *
839
+ * @example
840
+ * ```typescript
841
+ * import * as p from '@palmares/schemas';
842
+ *
843
+ * import { User } from './models';
844
+ *
845
+ * const userSchema = p.object({
846
+ * id: p.number().optional(),
847
+ * name: p.string(),
848
+ * email: p.string().email(),
849
+ * }).onSave(async (value) => {
850
+ * // Create or update the user on the database using palmares models or any other library of your choice.
851
+ * if (value.id)
852
+ * await User.default.set(value, { search: { id: value.id } });
853
+ * else
854
+ * await User.default.set(value);
855
+ *
856
+ * return value;
857
+ * });
858
+ *
859
+ *
860
+ * // Then, on your controller, do something like this:
861
+ * const { isValid, save, errors } = await userSchema.validate(req.body);
862
+ * if (isValid) {
863
+ * const savedValue = await save();
864
+ * return Response.json(savedValue, { status: 201 });
865
+ * }
866
+ *
867
+ * return Response.json({ errors }, { status: 400 });
868
+ * ```
869
+ *
870
+ * @param callback - The callback that will be called to save the value on an external source.
871
+ *
872
+ * @returns The schema.
873
+ */
874
+ onSave(callback) {
875
+ this.__saveCallback = callback;
876
+ return this;
877
+ }
878
+ /**
879
+ * This function is used to validate the schema and save the value to the database. It is used in
880
+ * conjunction with the {@link onSave} function.
881
+ *
882
+ * Different from other validation libraries, palmares schemas is aware that you want to save. On your
883
+ * routes/functions we recommend to ALWAYS use this function instead of {@link parse} directly. This is because
884
+ * this function by default will return an object with the property `save` or the `errors`. If the errors are present,
885
+ * you can return the errors to the user. If the save property is present, you can use to save the value to an
886
+ * external source. e.g. a database.
887
+ *
888
+ * @example
889
+ * ```typescript
890
+ * import * as p from '@palmares/schemas';
891
+ *
892
+ * import { User } from './models';
893
+ *
894
+ * const userSchema = p.object({
895
+ * id: p.number().optional(),
896
+ * name: p.string(),
897
+ * email: p.string().email(),
898
+ * }).onSave(async (value) => {
899
+ * // Create or update the user on the database using palmares models or any other library of your choice.
900
+ * if (value.id)
901
+ * await User.default.set(value, { search: { id: value.id } });
902
+ * else
903
+ * await User.default.set(value);
904
+ *
905
+ * return value;
906
+ * });
907
+ *
908
+ *
909
+ * // Then, on your controller, do something like this:
910
+ * const { isValid, save, errors } = await userSchema.validate(req.body);
911
+ * if (isValid) {
912
+ * const savedValue = await save();
913
+ * return Response.json(savedValue, { status: 201 });
914
+ * }
915
+ *
916
+ * return Response.json({ errors }, { status: 400 });
917
+ * ```
918
+ *
919
+ * @param value - The value to be validated.
920
+ *
921
+ * @returns An object with the property isValid, if the value is valid, the function `save` will be present.
922
+ * If the value is invalid, the property errors will be present.
923
+ */
924
+ async validate(value, context) {
925
+ const { errors, parsed } = await this.__parse(value, [], {
926
+ context
927
+ });
928
+ if ((errors || []).length > 0) return {
929
+ isValid: false,
930
+ errors
931
+ };
932
+ return {
933
+ isValid: true,
934
+ save: /* @__PURE__ */ __name(async () => this._save.bind(this)(parsed, context), "save")
935
+ };
936
+ }
937
+ /**
938
+ * Internal function, when we call the {@link validate} function it's this function that gets called
939
+ * when the user uses the `save` function returned by the {@link validate} function if the value is valid.
940
+ *
941
+ * @param value - The value to be saved.
942
+ *
943
+ * @returns The value to representation.
944
+ */
945
+ async _save(value, context) {
946
+ if (this.__saveCallback) {
947
+ const result = await this.__saveCallback(value, context);
948
+ return this.data(result);
949
+ }
950
+ return this.data(value);
951
+ }
952
+ /**
953
+ * This function is used to validate and parse the value to the internal representation of the schema.
954
+ *
955
+ * @example
956
+ * ```typescript
957
+ * import * as p from '@palmares/schemas';
958
+ *
959
+ * const numberSchema = p.number().allowString();
960
+ *
961
+ * const { errors, parsed } = await numberSchema.parse('123');
962
+ *
963
+ * console.log(parsed); // 123
964
+ * ```
965
+ *
966
+ * @param value - The value to be parsed.
967
+ *
968
+ * @returns The parsed value.
969
+ */
970
+ async parse(value) {
971
+ return this.__parse(value, [], {});
972
+ }
973
+ /**
974
+ * This function is used to transform the value to the representation without validating it.
975
+ * This is useful when you want to return a data from a query directly to the user. But for example
976
+ * you are returning the data of a user, you can clean the password or any other sensitive data.
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * import * as p from '@palmares/schemas';
981
+ *
982
+ * const userSchema = p.object({
983
+ * id: p.number().optional(),
984
+ * name: p.string(),
985
+ * email: p.string().email(),
986
+ * password: p.string().optional()
987
+ * }).toRepresentation(async (value) => {
988
+ * return {
989
+ * id: value.id,
990
+ * name: value.name,
991
+ * email: value.email
992
+ * }
993
+ * });
994
+ *
995
+ * const user = await userSchema.data({
996
+ * id: 1,
997
+ * name: 'John Doe',
998
+ * email: 'john@gmail.com',
999
+ * password: '123456'
1000
+ * });
1001
+ * ```
1002
+ */
1003
+ async data(value) {
1004
+ this.__getDefaultTransformedSchemas();
1005
+ if (typeof this.__runBeforeParseAndData === "function") await this.__runBeforeParseAndData(this);
1006
+ value = await this.__parsersToTransformValue(value);
1007
+ if (this.__toRepresentation) value = await Promise.resolve(this.__toRepresentation(value));
1008
+ if (this.__defaultFunction && value === void 0) value = await Promise.resolve(this.__defaultFunction());
1009
+ return value;
1010
+ }
1011
+ instanceOf(args) {
1012
+ this.__type.check = typeof args.check === "function" ? args.check : this.__type.check;
1013
+ this.__type.message = typeof args.message === "string" ? args.message : this.__type.message;
1014
+ return this;
1015
+ }
1016
+ /**
1017
+ * This function is used to add a default value to the schema. If the value is either undefined or null,
1018
+ * the default value will be used.
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * import * as p from '@palmares/schemas';
1023
+ *
1024
+ * const numberSchema = p.number().default(0);
1025
+ *
1026
+ * const { errors, parsed } = await numberSchema.parse(undefined);
1027
+ *
1028
+ * console.log(parsed); // 0
1029
+ * ```
1030
+ */
1031
+ default(defaultValueOrFunction) {
1032
+ const isFunction = typeof defaultValueOrFunction === "function";
1033
+ if (isFunction) this.__defaultFunction = defaultValueOrFunction;
1034
+ else this.__defaultFunction = async () => defaultValueOrFunction;
1035
+ return this;
1036
+ }
1037
+ /**
1038
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
1039
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
1040
+ * No problem, you can use this function to customize the zod schema.
1041
+ *
1042
+ * @example
1043
+ * ```typescript
1044
+ * import * as p from '@palmares/schemas';
1045
+ *
1046
+ * const numberSchema = p.number().extends((schema) => {
1047
+ * return schema.nonnegative();
1048
+ * });
1049
+ *
1050
+ * const { errors, parsed } = await numberSchema.parse(-1);
1051
+ *
1052
+ * console.log(errors);
1053
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
1054
+ * ```
1055
+ *
1056
+ * @param callback - The callback that will be called to customize the schema.
1057
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want
1058
+ * to compile the underlying schema to a string so you can save it for future runs.
1059
+ *
1060
+ * @returns The schema.
1061
+ */
1062
+ extends(callback, toStringCallback) {
1063
+ this.__extends = {
1064
+ callback,
1065
+ toStringCallback
1066
+ };
1067
+ return this;
1068
+ }
1069
+ /**
1070
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
1071
+ * function. With this function you have full control to add data cleaning for example, transforming the data
1072
+ * and whatever. Another use case is when you want to return deeply nested recursive data.
1073
+ * The schema maps to itself.
1074
+ *
1075
+ * @example
1076
+ * ```typescript
1077
+ * import * as p from '@palmares/schemas';
1078
+ *
1079
+ * const recursiveSchema = p.object({
1080
+ * id: p.number().optional(),
1081
+ * name: p.string(),
1082
+ * }).toRepresentation(async (value) => {
1083
+ * return {
1084
+ * id: value.id,
1085
+ * name: value.name,
1086
+ * children: await Promise.all(value.children.map(async (child) => await recursiveSchema.data(child)))
1087
+ * }
1088
+ * });
1089
+ *
1090
+ * const data = await recursiveSchema.data({
1091
+ * id: 1,
1092
+ * name: 'John Doe',
1093
+ * });
1094
+ * ```
1095
+ *
1096
+ * @example
1097
+ * ```
1098
+ * import * as p from '@palmares/schemas';
1099
+ *
1100
+ * const colorToRGBSchema = p.string().toRepresentation(async (value) => {
1101
+ * switch (value) {
1102
+ * case 'red': return { r: 255, g: 0, b: 0 };
1103
+ * case 'green': return { r: 0, g: 255, b: 0 };
1104
+ * case 'blue': return { r: 0, g: 0, b: 255 };
1105
+ * default: return { r: 0, g: 0, b: 0 };
1106
+ * }
1107
+ * });
1108
+ * ```
1109
+ * @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
1110
+ * @param options - Options for the toRepresentation function.
1111
+ * @param options.after - Whether the toRepresentationCallback should be called after the existing
1112
+ * toRepresentationCallback. Defaults to true.
1113
+ * @param options.before - Whether the toRepresentationCallback should be called before the existing
1114
+ * toRepresentationCallback. Defaults to true.
1115
+ *
1116
+ * @returns The schema with a new return type
1117
+ */
1118
+ toRepresentation(toRepresentationCallback, options) {
1119
+ if (this.__toRepresentation) {
1120
+ const before = typeof options?.before === "boolean" ? options.before : typeof options?.after === "boolean" ? !options.after : true;
1121
+ const existingToRepresentation = this.__toRepresentation;
1122
+ this.__toRepresentation = async (value) => {
1123
+ if (before) return toRepresentationCallback(await existingToRepresentation(value));
1124
+ else return existingToRepresentation(await toRepresentationCallback(value));
1125
+ };
1126
+ } else this.__toRepresentation = toRepresentationCallback;
1127
+ return this;
1128
+ }
1129
+ /**
1130
+ * This function is used to transform the value to the internal representation of the schema. This is useful
1131
+ * when you want to transform the value to a type that the schema adapter can understand. For example, you
1132
+ * might want to transform a string to a date. This is the function you use.
1133
+ *
1134
+ * @example
1135
+ * ```typescript
1136
+ * import * as p from '@palmares/schemas';
1137
+ *
1138
+ * const dateSchema = p.string().toInternal((value) => {
1139
+ * return new Date(value);
1140
+ * });
1141
+ *
1142
+ * const date = await dateSchema.parse('2021-01-01');
1143
+ *
1144
+ * console.log(date); // Date object
1145
+ *
1146
+ * const rgbToColorSchema = p.object({
1147
+ * r: p.number().min(0).max(255),
1148
+ * g: p.number().min(0).max(255),
1149
+ * b: p.number().min(0).max(255),
1150
+ * }).toInternal(async (value) => {
1151
+ * if (value.r === 255 && value.g === 0 && value.b === 0) return 'red';
1152
+ * if (value.r === 0 && value.g === 255 && value.b === 0) return 'green';
1153
+ * if (value.r === 0 && value.g === 0 && value.b === 255) return 'blue';
1154
+ * return `rgb(${value.r}, ${value.g}, ${value.b})`;
1155
+ * });
1156
+ * ```
1157
+ *
1158
+ * @param toInternalCallback - The callback that will be called to transform the value to the internal representation.
1159
+ *
1160
+ * @returns The schema with a new return type.
1161
+ */
1162
+ toInternal(toInternalCallback) {
1163
+ if (this.__toInternal) {
1164
+ const toInternal = this.__toInternal;
1165
+ this.__toInternal = async (value) => {
1166
+ const newValue = await toInternal(value);
1167
+ return toInternalCallback(newValue);
1168
+ };
1169
+ } else this.__toInternal = toInternalCallback;
1170
+ return this;
1171
+ }
1172
+ /**
1173
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a
1174
+ * string, you can convert that string to a date here BEFORE the validation. This pretty much transforms the value
1175
+ * to a type that the schema adapter can understand.
1176
+ *
1177
+ * @example
1178
+ * ```
1179
+ * import * as p from '@palmares/schemas';
1180
+ * import * as z from 'zod';
1181
+ *
1182
+ * const customRecordToMapSchema = p.schema().appendSchema(z.map()).toValidate(async (value) => {
1183
+ * return new Map(value); // Before validating we transform the value to a map.
1184
+ * });
1185
+ *
1186
+ * const { errors, parsed } = await customRecordToMapSchema.parse({ key: 'value' });
1187
+ * ```
1188
+ *
1189
+ * @param toValidateCallback - The callback that will be called to validate the value.
1190
+ *
1191
+ * @returns The schema with a new return type.
1192
+ */
1193
+ toValidate(toValidateCallback) {
1194
+ this.__toValidate = toValidateCallback;
1195
+ return this;
1196
+ }
1197
+ /**
1198
+ * Used to transform the given schema on a stringfied version of the adapter.
1199
+ */
1200
+ async compile(adapter) {
1201
+ const data = await this.__transformToAdapter({
1202
+ shouldAddStringVersion: true,
1203
+ force: true
1204
+ });
1205
+ const stringVersions = data.map((value) => value.asString);
1206
+ return stringVersions;
1207
+ }
1208
+ static new(..._args) {
1209
+ const result = new _Schema();
1210
+ return result;
1211
+ }
1212
+ };
1213
+ var schema = Schema.new;
1214
+
1215
+ // src/validators/union.ts
1216
+ function unionValidation(schemas) {
1217
+ return {
1218
+ name: "union",
1219
+ type: "medium",
1220
+ callback: /* @__PURE__ */ __name(async (value, path, options) => {
1221
+ const parsedValues = {
1222
+ parsed: value,
1223
+ errors: []
1224
+ };
1225
+ const startingToInternalBubbleUpLength = options.toInternalToBubbleUp?.length || 0;
1226
+ for (let i = 0; i < schemas.length; i++) {
1227
+ const schemaWithProtected = schemas[i];
1228
+ const parsedData = await schemaWithProtected.__parse(value, path, options);
1229
+ parsedValues.parsed = parsedData.parsed;
1230
+ if (Array.isArray(parsedData.errors)) if (Array.isArray(parsedValues.errors)) parsedValues.errors.push(...parsedData.errors);
1231
+ else parsedValues.errors = parsedData.errors;
1232
+ const hasNoErrorsSoItsAValidSchemaAndShouldResetOldErrors = (
1233
+ // eslint-disable-next-line ts/no-unnecessary-condition
1234
+ parsedData.errors === void 0 || (parsedData.errors || []).length === 0
1235
+ );
1236
+ if (hasNoErrorsSoItsAValidSchemaAndShouldResetOldErrors) {
1237
+ return {
1238
+ parsed: parsedValues.parsed,
1239
+ errors: []
1240
+ };
1241
+ } else if (startingToInternalBubbleUpLength < (options.toInternalToBubbleUp?.length || 0)) {
1242
+ const numberOfElementsToRemove = (options.toInternalToBubbleUp?.length || 0) - startingToInternalBubbleUpLength;
1243
+ options.toInternalToBubbleUp?.splice(startingToInternalBubbleUpLength, numberOfElementsToRemove);
1244
+ }
1245
+ }
1246
+ return {
1247
+ parsed: parsedValues.parsed,
1248
+ // eslint-disable-next-line ts/no-unnecessary-condition
1249
+ errors: Array.isArray(parsedValues.errors) ? parsedValues.errors : []
1250
+ };
1251
+ }, "callback")
1252
+ };
1253
+ }
1254
+ __name(unionValidation, "unionValidation");
1255
+
1256
+ // src/schema/union.ts
1257
+ var UnionSchema = class _UnionSchema extends Schema {
1258
+ static {
1259
+ __name(this, "UnionSchema");
1260
+ }
1261
+ fieldType = "union";
1262
+ __type = {
1263
+ message: "Invalid type",
1264
+ check: /* @__PURE__ */ __name((value) => Array.from(this.__schemas).some((schema2) => schema2["__type"].check(value)), "check")
1265
+ };
1266
+ __schemas = /* @__PURE__ */ new Set();
1267
+ constructor(schemas) {
1268
+ super();
1269
+ this.__schemas = new Set(schemas);
1270
+ }
1271
+ async __transformToAdapter(options) {
1272
+ return defaultTransformToAdapter(async (adapter) => {
1273
+ const promises = [];
1274
+ const shouldBeHighPriorityFallback = adapter.union === void 0;
1275
+ const transformedSchemasAsString = [];
1276
+ const transformedSchemas = [];
1277
+ let shouldBeHandledByFallback = shouldBeHighPriorityFallback;
1278
+ for (const schemaToTransform of this.__schemas.values()) {
1279
+ const awaitableTransformer = /* @__PURE__ */ __name(async () => {
1280
+ const [transformedData, shouldAddFallbackValidationForThisKey] = await transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas(schemaToTransform, options);
1281
+ if (shouldAddFallbackValidationForThisKey) shouldBeHandledByFallback = true;
1282
+ for (const transformedSchema of transformedData) {
1283
+ transformedSchemasAsString.push(transformedSchema.asString);
1284
+ transformedSchemas.push(transformedSchema.transformed);
1285
+ }
1286
+ }, "awaitableTransformer");
1287
+ promises.push(awaitableTransformer());
1288
+ }
1289
+ if (shouldBeHandledByFallback) {
1290
+ Validator.createAndAppendFallback(this, unionValidation(Array.from(this.__schemas)), {
1291
+ at: 0,
1292
+ removeCurrent: true
1293
+ });
1294
+ }
1295
+ await Promise.all(promises);
1296
+ return defaultTransform("union", this, adapter, adapter.union, (isStringVersion) => ({
1297
+ nullable: this.__nullable,
1298
+ type: this.__type,
1299
+ optional: this.__optional,
1300
+ schemas: isStringVersion ? transformedSchemasAsString : transformedSchemas,
1301
+ parsers: {
1302
+ nullable: this.__nullable.allow,
1303
+ optional: this.__optional.allow
1304
+ }
1305
+ }), {}, {
1306
+ shouldAddStringVersion: options.shouldAddStringVersion,
1307
+ fallbackIfNotSupported: /* @__PURE__ */ __name(async () => {
1308
+ if (options.appendFallbacksBeforeAdapterValidation) options.appendFallbacksBeforeAdapterValidation(this, "union", async (adapter2, fieldAdapter, schema2, translatedSchemas, value, path, options2) => {
1309
+ const parsedValues = {
1310
+ parsed: value,
1311
+ errors: []
1312
+ };
1313
+ for (const translatedSchema of translatedSchemas) {
1314
+ const { parsed, errors } = await schema2.__validateByAdapter(adapter2, fieldAdapter, translatedSchema, value, path, options2);
1315
+ if ((errors || []).length <= 0) return {
1316
+ parsed,
1317
+ errors
1318
+ };
1319
+ else {
1320
+ parsedValues.parsed = parsed;
1321
+ parsedValues.errors = (parsedValues.errors || []).concat(errors || []);
1322
+ }
1323
+ }
1324
+ return parsedValues;
1325
+ });
1326
+ const transformedSchemasAsPromises = [];
1327
+ for (const schema2 of this.__schemas) transformedSchemasAsPromises.push(schema2.__transformToAdapter(options));
1328
+ return (await Promise.all(transformedSchemasAsPromises)).flat();
1329
+ }, "fallbackIfNotSupported")
1330
+ });
1331
+ }, this, this.__transformedSchemas, options, "union");
1332
+ }
1333
+ /**
1334
+ * This let's you refine the schema with custom validations. This is useful when you want to validate something that
1335
+ * is not supported by default by the schema adapter.
1336
+ *
1337
+ * @example
1338
+ * ```typescript
1339
+ * import * as p from '@palmares/schemas';
1340
+ *
1341
+ * const numberSchema = p.number().refine((value) => {
1342
+ * if (value < 0) return { code: 'invalid_number', message: 'The number should be greater than 0' };
1343
+ * });
1344
+ *
1345
+ * const { errors, parsed } = await numberSchema.parse(-1);
1346
+ *
1347
+ * // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
1348
+ * console.log(errors);
1349
+ * ```
1350
+ *
1351
+ * @param refinementCallback - The callback that will be called to validate the value.
1352
+ * @param options - Options for the refinement.
1353
+ * @param options.isAsync - Whether the callback is async or not. Defaults to true.
1354
+ */
1355
+ refine(refinementCallback) {
1356
+ return super.refine(refinementCallback);
1357
+ }
1358
+ /**
1359
+ * Allows the value to be either undefined or null.
1360
+ *
1361
+ * @example
1362
+ * ```typescript
1363
+ * import * as p from '@palmares/schemas';
1364
+ *
1365
+ * const numberSchema = p.number().optional();
1366
+ *
1367
+ * const { errors, parsed } = await numberSchema.parse(undefined);
1368
+ *
1369
+ * console.log(parsed); // undefined
1370
+ *
1371
+ * const { errors, parsed } = await numberSchema.parse(null);
1372
+ *
1373
+ * console.log(parsed); // null
1374
+ *
1375
+ * const { errors, parsed } = await numberSchema.parse(1);
1376
+ *
1377
+ * console.log(parsed); // 1
1378
+ * ```
1379
+ *
1380
+ * @returns - The schema we are working with.
1381
+ */
1382
+ optional(options) {
1383
+ return super.optional(options);
1384
+ }
1385
+ /**
1386
+ * Just adds a message when the value is undefined. It's just a syntax sugar for
1387
+ *
1388
+ * ```typescript
1389
+ * p.string().optional({ message: 'This value cannot be null', allow: false })
1390
+ * ```
1391
+ *
1392
+ * @param options - The options of nonOptional function
1393
+ * @param options.message - A custom message if the value is undefined.
1394
+ *
1395
+ * @returns - The schema.
1396
+ */
1397
+ nonOptional(options) {
1398
+ return super.optional({
1399
+ message: options?.message,
1400
+ allow: false
1401
+ });
1402
+ }
1403
+ /**
1404
+ * Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
1405
+ * is NULL by setting the { message: 'Your custom message', allow: false } on the options.
1406
+ *
1407
+ * @example
1408
+ * ```typescript
1409
+ * import * as p from '@palmares/schemas';
1410
+ *
1411
+ * const numberSchema = p.number().nullable();
1412
+ *
1413
+ * const { errors, parsed } = await numberSchema.parse(null);
1414
+ *
1415
+ * console.log(parsed); // null
1416
+ *
1417
+ * const { errors, parsed } = await numberSchema.parse(undefined);
1418
+ *
1419
+ * console.log(errors); // [{ isValid: false, code: 'invalid_type', message: 'Invalid type', path: [] }]
1420
+ * ```
1421
+ *
1422
+ * @param options - The options for the nullable function.
1423
+ * @param options.message - The message to be shown when the value is not null. Defaults to 'Cannot be null'.
1424
+ * @param options.allow - Whether the value can be null or not. Defaults to true.
1425
+ *
1426
+ * @returns The schema.
1427
+ */
1428
+ nullable(options) {
1429
+ return super.nullable(options);
1430
+ }
1431
+ /**
1432
+ * Just adds a message when the value is null. It's just a syntax sugar for
1433
+ *
1434
+ * ```typescript
1435
+ * p.string().nullable({ message: 'This value cannot be null', allow: false })
1436
+ * ```
1437
+ *
1438
+ * @param options - The options of nonNullable function
1439
+ * @param options.message - A custom message if the value is null.
1440
+ *
1441
+ * @returns - The schema.
1442
+ */
1443
+ nonNullable(options) {
1444
+ return super.nullable({
1445
+ message: options?.message || "",
1446
+ allow: false
1447
+ });
1448
+ }
1449
+ /**
1450
+ * This method will remove the value from the representation of the schema. If the value is undefined it will keep
1451
+ * that way
1452
+ * otherwise it will set the value to undefined after it's validated.
1453
+ * This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
1454
+ * function. This will remove the value from the representation of the schema.
1455
+ *
1456
+ * By default, the value will be removed just from the representation, in other words, when you call the {@link data}
1457
+ * function. But if you want to remove the value from the internal representation, you can pass the argument
1458
+ * `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
1459
+ * the argument `toRepresentation` as true as well.
1460
+ *
1461
+ * @example
1462
+ * ```typescript
1463
+ * import * as p from '@palmares/schemas';
1464
+ *
1465
+ * const userSchema = p.object({
1466
+ * id: p.number().optional(),
1467
+ * name: p.string(),
1468
+ * password: p.string().omit()
1469
+ * });
1470
+ *
1471
+ * const user = await userSchema.data({
1472
+ * id: 1,
1473
+ * name: 'John Doe',
1474
+ * password: '123456'
1475
+ * });
1476
+ *
1477
+ * console.log(user); // { id: 1, name: 'John Doe' }
1478
+ * ```
1479
+ *
1480
+ *
1481
+ * @param args - By default, the value will be removed just from the representation, in other words, when you call
1482
+ * the {@link data} function. But if you want to remove the value from the internal representation, you can pass
1483
+ * the argument `toInternal` as true. Then if you still want to remove the value from the representation, you
1484
+ * will need to pass the argument `toRepresentation` as true as well.
1485
+ *
1486
+ * @returns The schema.
1487
+ */
1488
+ omit(args) {
1489
+ return super.omit(args);
1490
+ }
1491
+ /**
1492
+ * This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
1493
+ * source like a database. You should always return the schema after you save the value, that way we will always
1494
+ * have the correct type of the schema after the save operation.
1495
+ *
1496
+ * You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
1497
+ *
1498
+ * @example
1499
+ * ```typescript
1500
+ * import * as p from '@palmares/schemas';
1501
+ *
1502
+ * import { User } from './models';
1503
+ *
1504
+ * const userSchema = p.object({
1505
+ * id: p.number().optional(),
1506
+ * name: p.string(),
1507
+ * email: p.string().email(),
1508
+ * }).onSave(async (value) => {
1509
+ * // Create or update the user on the database using palmares models or any other library of your choice.
1510
+ * if (value.id)
1511
+ * await User.default.set(value, { search: { id: value.id } });
1512
+ * else
1513
+ * await User.default.set(value);
1514
+ *
1515
+ * return value;
1516
+ * });
1517
+ *
1518
+ *
1519
+ * // Then, on your controller, do something like this:
1520
+ * const { isValid, save, errors } = await userSchema.validate(req.body);
1521
+ * if (isValid) {
1522
+ * const savedValue = await save();
1523
+ * return Response.json(savedValue, { status: 201 });
1524
+ * }
1525
+ *
1526
+ * return Response.json({ errors }, { status: 400 });
1527
+ * ```
1528
+ *
1529
+ * @param callback - The callback that will be called to save the value on an external source.
1530
+ *
1531
+ * @returns The schema.
1532
+ */
1533
+ onSave(callback) {
1534
+ return super.onSave(callback);
1535
+ }
1536
+ /**
1537
+ * This function is used to add a default value to the schema. If the value is either undefined or null, the default
1538
+ * value will be used.
1539
+ *
1540
+ * @example
1541
+ * ```typescript
1542
+ * import * as p from '@palmares/schemas';
1543
+ *
1544
+ * const numberSchema = p.number().default(0);
1545
+ *
1546
+ * const { errors, parsed } = await numberSchema.parse(undefined);
1547
+ *
1548
+ * console.log(parsed); // 0
1549
+ * ```
1550
+ */
1551
+ default(defaultValueOrFunction) {
1552
+ return super.default(defaultValueOrFunction);
1553
+ }
1554
+ /**
1555
+ * This function is used to transform the value to the representation without validating it.
1556
+ * This is useful when you want to return a data from a query directly to the user. But for example
1557
+ * you are returning the data of a user, you can clean the password or any other sensitive data.
1558
+ *
1559
+ * @example
1560
+ * ```typescript
1561
+ * import * as p from '@palmares/schemas';
1562
+ *
1563
+ * const userSchema = p.object({
1564
+ * id: p.number().optional(),
1565
+ * name: p.string(),
1566
+ * email: p.string().email(),
1567
+ * password: p.string().optional()
1568
+ * }).toRepresentation(async (value) => {
1569
+ * return {
1570
+ * id: value.id,
1571
+ * name: value.name,
1572
+ * email: value.email
1573
+ * }
1574
+ * });
1575
+ *
1576
+ * const user = await userSchema.data({
1577
+ * id: 1,
1578
+ * name: 'John Doe',
1579
+ * email: 'john@gmail.com',
1580
+ * password: '123456'
1581
+ * });
1582
+ * ```
1583
+ */
1584
+ async data(value) {
1585
+ const parsedValue = await super.data(value);
1586
+ for (const schema2 of Array.from(this.__schemas)) {
1587
+ if (schema2["__optional"].allow && value === void 0) return schema2.data(parsedValue);
1588
+ if (schema2["__nullable"].allow && value === null) return schema2.data(parsedValue);
1589
+ if (schema2["__type"].check(parsedValue)) return schema2.data(parsedValue);
1590
+ }
1591
+ return parsedValue;
1592
+ }
1593
+ /**
1594
+ * This function let's you customize the schema your own way. After we translate the schema on the adapter we call
1595
+ * this function to let you customize the custom schema your own way. Our API does not support passthrough?
1596
+ * No problem, you can use this function to customize the zod schema.
1597
+ *
1598
+ * @example
1599
+ * ```typescript
1600
+ * import * as p from '@palmares/schemas';
1601
+ *
1602
+ * const numberSchema = p.number().extends((schema) => {
1603
+ * return schema.nonnegative();
1604
+ * });
1605
+ *
1606
+ * const { errors, parsed } = await numberSchema.parse(-1);
1607
+ *
1608
+ * // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
1609
+ * console.log(errors);
1610
+ * ```
1611
+ *
1612
+ * @param callback - The callback that will be called to customize the schema.
1613
+ * @param toStringCallback - The callback that will be called to transform the schema to a string when you want
1614
+ * to compile the underlying schema to a string so you can save it for future runs.
1615
+ *
1616
+ * @returns The schema.
1617
+ */
1618
+ extends(callback, toStringCallback) {
1619
+ return super.extends(callback, toStringCallback);
1620
+ }
1621
+ /**
1622
+ * This function is used to transform the value to the representation of the schema. When using the {@link data}
1623
+ * function. With this function you have full control to add data cleaning for example, transforming the data and
1624
+ * whatever. Another use case is when you want to return deeply nested recursive data. The schema maps to itself.
1625
+ *
1626
+ * @example
1627
+ * ```typescript
1628
+ * import * as p from '@palmares/schemas';
1629
+ *
1630
+ * const recursiveSchema = p.object({
1631
+ * id: p.number().optional(),
1632
+ * name: p.string(),
1633
+ * }).toRepresentation(async (value) => {
1634
+ * return {
1635
+ * id: value.id,
1636
+ * name: value.name,
1637
+ * children: await Promise.all(value.children.map(async (child) => await recursiveSchema.data(child)))
1638
+ * }
1639
+ * });
1640
+ *
1641
+ * const data = await recursiveSchema.data({
1642
+ * id: 1,
1643
+ * name: 'John Doe',
1644
+ * });
1645
+ * ```
1646
+ *
1647
+ * @example
1648
+ * ```
1649
+ * import * as p from '@palmares/schemas';
1650
+ *
1651
+ * const colorToRGBSchema = p.string().toRepresentation(async (value) => {
1652
+ * switch (value) {
1653
+ * case 'red': return { r: 255, g: 0, b: 0 };
1654
+ * case 'green': return { r: 0, g: 255, b: 0 };
1655
+ * case 'blue': return { r: 0, g: 0, b: 255 };
1656
+ * default: return { r: 0, g: 0, b: 0 };
1657
+ * }
1658
+ * });
1659
+ * ```
1660
+ * @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
1661
+ *
1662
+ * @returns The schema with a new return type
1663
+ */
1664
+ toRepresentation(toRepresentationCallback) {
1665
+ return super.toRepresentation(toRepresentationCallback);
1666
+ }
1667
+ /**
1668
+ * This function is used to transform the value to the internal representation of the schema. This is useful when you
1669
+ * want to transform the value to a type that the schema adapter can understand. For example, you might want to
1670
+ * transform a string to a date. This is the function you use.
1671
+ *
1672
+ * @example
1673
+ * ```typescript
1674
+ * import * as p from '@palmares/schemas';
1675
+ *
1676
+ * const dateSchema = p.string().toInternal((value) => {
1677
+ * return new Date(value);
1678
+ * });
1679
+ *
1680
+ * const date = await dateSchema.parse('2021-01-01');
1681
+ *
1682
+ * console.log(date); // Date object
1683
+ *
1684
+ * const rgbToColorSchema = p.object({
1685
+ * r: p.number().min(0).max(255),
1686
+ * g: p.number().min(0).max(255),
1687
+ * b: p.number().min(0).max(255),
1688
+ * }).toInternal(async (value) => {
1689
+ * if (value.r === 255 && value.g === 0 && value.b === 0) return 'red';
1690
+ * if (value.r === 0 && value.g === 255 && value.b === 0) return 'green';
1691
+ * if (value.r === 0 && value.g === 0 && value.b === 255) return 'blue';
1692
+ * return `rgb(${value.r}, ${value.g}, ${value.b})`;
1693
+ * });
1694
+ * ```
1695
+ *
1696
+ * @param toInternalCallback - The callback that will be called to transform the value to the internal representation.
1697
+ *
1698
+ * @returns The schema with a new return type.
1699
+ */
1700
+ toInternal(toInternalCallback) {
1701
+ return super.toInternal(toInternalCallback);
1702
+ }
1703
+ /**
1704
+ * Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
1705
+ * you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
1706
+ * that the schema adapter can understand.
1707
+ *
1708
+ * @example
1709
+ * ```
1710
+ * import * as p from '@palmares/schemas';
1711
+ * import * as z from 'zod';
1712
+ *
1713
+ * const customRecordToMapSchema = p.schema().appendSchema(z.map()).toValidate(async (value) => {
1714
+ * return new Map(value); // Before validating we transform the value to a map.
1715
+ * });
1716
+ *
1717
+ * const { errors, parsed } = await customRecordToMapSchema.parse({ key: 'value' });
1718
+ * ```
1719
+ *
1720
+ * @param toValidateCallback - The callback that will be called to validate the value.
1721
+ *
1722
+ * @returns The schema with a new return type.
1723
+ */
1724
+ toValidate(toValidateCallback) {
1725
+ return super.toValidate(toValidateCallback);
1726
+ }
1727
+ static new(schemas) {
1728
+ const returnValue = new _UnionSchema(schemas);
1729
+ return returnValue;
1730
+ }
1731
+ };
1732
+ var union = UnionSchema.new;
1733
+ // Annotate the CommonJS export names for ESM import in node:
1734
+ 0 && (module.exports = {
1735
+ UnionSchema,
1736
+ union
1737
+ });