@tstdl/base 0.71.87 → 0.78.0-beta1

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 (373) hide show
  1. package/.eslintrc.js +2 -4
  2. package/api/client/client.js +2 -12
  3. package/api/client/client.js.map +1 -1
  4. package/api/default-error-handlers.d.ts +0 -4
  5. package/api/default-error-handlers.js +1 -6
  6. package/api/default-error-handlers.js.map +1 -1
  7. package/api/server/error-handler.js +2 -2
  8. package/api/server/error-handler.js.map +1 -1
  9. package/api/server/gateway.js +12 -18
  10. package/api/server/gateway.js.map +1 -1
  11. package/api/server/module.d.ts +0 -4
  12. package/api/server/module.js +1 -12
  13. package/api/server/module.js.map +1 -1
  14. package/api/types.d.ts +8 -32
  15. package/api/types.js.map +1 -1
  16. package/container/container.js +2 -2
  17. package/container/container.js.map +1 -1
  18. package/data-structures/index.d.ts +1 -0
  19. package/data-structures/index.js +1 -0
  20. package/data-structures/index.js.map +1 -1
  21. package/data-structures/iterable-weak-map.d.ts +29 -0
  22. package/data-structures/iterable-weak-map.js +128 -0
  23. package/data-structures/iterable-weak-map.js.map +1 -0
  24. package/data-structures/multi-key-map.d.ts +12 -1
  25. package/data-structures/multi-key-map.js +22 -11
  26. package/data-structures/multi-key-map.js.map +1 -1
  27. package/error/custom.error.d.ts +3 -1
  28. package/error/custom.error.js +16 -7
  29. package/error/custom.error.js.map +1 -1
  30. package/examples/api/basic-overview.js +16 -8
  31. package/examples/api/basic-overview.js.map +1 -1
  32. package/http/http.error.d.ts +4 -2
  33. package/http/http.error.js +6 -0
  34. package/http/http.error.js.map +1 -1
  35. package/image-service/image-service.d.ts +32 -65
  36. package/image-service/image-service.js +73 -15
  37. package/image-service/image-service.js.map +1 -1
  38. package/json-path/json-path.d.ts +8 -3
  39. package/json-path/json-path.js +24 -7
  40. package/json-path/json-path.js.map +1 -1
  41. package/logger/console/logger.js +2 -2
  42. package/logger/console/logger.js.map +1 -1
  43. package/mail/mail.service.js +2 -2
  44. package/mail/mail.service.js.map +1 -1
  45. package/module/modules/index.d.ts +0 -1
  46. package/module/modules/index.js +0 -1
  47. package/module/modules/index.js.map +1 -1
  48. package/openid-connect/oidc-configuration.service.js +7 -7
  49. package/openid-connect/oidc-configuration.service.js.map +1 -1
  50. package/openid-connect/oidc.service.js +7 -7
  51. package/openid-connect/oidc.service.js.map +1 -1
  52. package/package.json +3 -4
  53. package/process-shutdown.js +3 -2
  54. package/process-shutdown.js.map +1 -1
  55. package/reflection/decorators.js +1 -0
  56. package/reflection/decorators.js.map +1 -1
  57. package/reflection/reflection-data-map.d.ts +10 -0
  58. package/reflection/reflection-data-map.js +40 -0
  59. package/reflection/reflection-data-map.js.map +1 -0
  60. package/reflection/registry.d.ts +7 -7
  61. package/reflection/registry.js +7 -6
  62. package/reflection/registry.js.map +1 -1
  63. package/reflection/types.d.ts +1 -0
  64. package/reflection/utils.d.ts +6 -3
  65. package/reflection/utils.js +9 -35
  66. package/reflection/utils.js.map +1 -1
  67. package/schema/array-constraints/index.d.ts +2 -0
  68. package/{old-api/validation/validators → schema/array-constraints}/index.js +2 -1
  69. package/schema/array-constraints/index.js.map +1 -0
  70. package/schema/array-constraints/maximum-length.d.ts +11 -0
  71. package/schema/array-constraints/maximum-length.js +26 -0
  72. package/schema/array-constraints/maximum-length.js.map +1 -0
  73. package/schema/array-constraints/minimum-length.d.ts +11 -0
  74. package/schema/array-constraints/minimum-length.js +26 -0
  75. package/schema/array-constraints/minimum-length.js.map +1 -0
  76. package/schema/coercers/boolean.coercer.d.ts +9 -0
  77. package/schema/coercers/boolean.coercer.js +35 -0
  78. package/schema/coercers/boolean.coercer.js.map +1 -0
  79. package/schema/coercers/date.coercer.d.ts +9 -0
  80. package/schema/coercers/date.coercer.js +24 -0
  81. package/schema/coercers/date.coercer.js.map +1 -0
  82. package/schema/coercers/default-value.coercer.d.ts +9 -0
  83. package/schema/coercers/default-value.coercer.js +16 -0
  84. package/schema/coercers/default-value.coercer.js.map +1 -0
  85. package/schema/coercers/index.d.ts +7 -0
  86. package/schema/coercers/index.js +24 -0
  87. package/schema/coercers/index.js.map +1 -0
  88. package/schema/coercers/number.coercer.d.ts +9 -0
  89. package/schema/coercers/number.coercer.js +22 -0
  90. package/schema/coercers/number.coercer.js.map +1 -0
  91. package/schema/coercers/regexp.coercer.d.ts +11 -0
  92. package/schema/coercers/regexp.coercer.js +24 -0
  93. package/schema/coercers/regexp.coercer.js.map +1 -0
  94. package/schema/coercers/string.coercer.d.ts +9 -0
  95. package/schema/coercers/string.coercer.js +22 -0
  96. package/schema/coercers/string.coercer.js.map +1 -0
  97. package/schema/coercers/uint8-array.coercer.d.ts +9 -0
  98. package/schema/coercers/uint8-array.coercer.js +31 -0
  99. package/schema/coercers/uint8-array.coercer.js.map +1 -0
  100. package/schema/constraints/enumeration.d.ts +13 -0
  101. package/schema/constraints/enumeration.js +29 -0
  102. package/schema/constraints/enumeration.js.map +1 -0
  103. package/schema/constraints/generic.d.ts +22 -0
  104. package/schema/constraints/generic.js +32 -0
  105. package/schema/constraints/generic.js.map +1 -0
  106. package/schema/constraints/index.d.ts +12 -0
  107. package/schema/constraints/index.js +29 -0
  108. package/schema/constraints/index.js.map +1 -0
  109. package/schema/constraints/integer.d.ts +12 -0
  110. package/schema/constraints/integer.js +27 -0
  111. package/schema/constraints/integer.js.map +1 -0
  112. package/schema/constraints/length.d.ts +6 -0
  113. package/schema/constraints/length.js +20 -0
  114. package/schema/constraints/length.js.map +1 -0
  115. package/schema/constraints/literal.d.ts +10 -0
  116. package/schema/constraints/literal.js +26 -0
  117. package/schema/constraints/literal.js.map +1 -0
  118. package/schema/constraints/maximum-date.d.ts +12 -0
  119. package/schema/constraints/maximum-date.js +29 -0
  120. package/schema/constraints/maximum-date.js.map +1 -0
  121. package/schema/constraints/maximum-length.d.ts +12 -0
  122. package/schema/constraints/maximum-length.js +29 -0
  123. package/schema/constraints/maximum-length.js.map +1 -0
  124. package/schema/constraints/maximum.d.ts +12 -0
  125. package/schema/constraints/maximum.js +27 -0
  126. package/schema/constraints/maximum.js.map +1 -0
  127. package/schema/constraints/minimum-date.d.ts +12 -0
  128. package/schema/constraints/minimum-date.js +29 -0
  129. package/schema/constraints/minimum-date.js.map +1 -0
  130. package/schema/constraints/minimum-length.d.ts +12 -0
  131. package/schema/constraints/minimum-length.js +29 -0
  132. package/schema/constraints/minimum-length.js.map +1 -0
  133. package/schema/constraints/minimum.d.ts +12 -0
  134. package/schema/constraints/minimum.js +27 -0
  135. package/schema/constraints/minimum.js.map +1 -0
  136. package/schema/constraints/pattern.d.ts +13 -0
  137. package/schema/constraints/pattern.js +28 -0
  138. package/schema/constraints/pattern.js.map +1 -0
  139. package/schema/decorators/array.d.ts +4 -0
  140. package/schema/decorators/array.js +11 -0
  141. package/schema/decorators/array.js.map +1 -0
  142. package/schema/decorators/coerce.d.ts +2 -0
  143. package/schema/decorators/coerce.js +10 -0
  144. package/schema/decorators/coerce.js.map +1 -0
  145. package/schema/decorators/defaulted.d.ts +3 -0
  146. package/schema/decorators/defaulted.js +11 -0
  147. package/schema/decorators/defaulted.js.map +1 -0
  148. package/schema/decorators/index.d.ts +8 -0
  149. package/{old-api → schema/decorators}/index.js +8 -3
  150. package/schema/decorators/index.js.map +1 -0
  151. package/schema/decorators/nullable.d.ts +2 -0
  152. package/schema/decorators/nullable.js +10 -0
  153. package/schema/decorators/nullable.js.map +1 -0
  154. package/schema/decorators/optional.d.ts +2 -0
  155. package/schema/decorators/optional.js +10 -0
  156. package/schema/decorators/optional.js.map +1 -0
  157. package/schema/decorators/property.d.ts +6 -0
  158. package/schema/decorators/property.js +19 -0
  159. package/schema/decorators/property.js.map +1 -0
  160. package/schema/decorators/type.d.ts +3 -0
  161. package/schema/decorators/type.js +10 -0
  162. package/schema/decorators/type.js.map +1 -0
  163. package/schema/decorators/types.d.ts +18 -0
  164. package/schema/decorators/types.js +3 -0
  165. package/schema/decorators/types.js.map +1 -0
  166. package/schema/decorators/utils.d.ts +10 -0
  167. package/schema/decorators/utils.js +59 -0
  168. package/schema/decorators/utils.js.map +1 -0
  169. package/schema/index.d.ts +7 -1
  170. package/schema/index.js +7 -1
  171. package/schema/index.js.map +1 -1
  172. package/schema/schema.d.ts +19 -0
  173. package/schema/schema.error.d.ts +13 -7
  174. package/schema/schema.error.js +45 -13
  175. package/schema/schema.error.js.map +1 -1
  176. package/schema/schema.js +286 -0
  177. package/schema/schema.js.map +1 -0
  178. package/schema/schemas/any.d.ts +4 -8
  179. package/schema/schemas/any.js +9 -14
  180. package/schema/schemas/any.js.map +1 -1
  181. package/schema/schemas/array.d.ts +7 -13
  182. package/schema/schemas/array.js +14 -43
  183. package/schema/schemas/array.js.map +1 -1
  184. package/schema/schemas/assign.d.ts +8 -0
  185. package/schema/schemas/assign.js +28 -0
  186. package/schema/schemas/assign.js.map +1 -0
  187. package/schema/schemas/boolean.d.ts +5 -9
  188. package/schema/schemas/boolean.js +11 -38
  189. package/schema/schemas/boolean.js.map +1 -1
  190. package/schema/schemas/constraint.d.ts +4 -0
  191. package/schema/schemas/constraint.js +14 -0
  192. package/schema/schemas/constraint.js.map +1 -0
  193. package/schema/schemas/date.d.ts +7 -11
  194. package/schema/schemas/date.js +18 -53
  195. package/schema/schemas/date.js.map +1 -1
  196. package/schema/schemas/defaulted.d.ts +2 -15
  197. package/schema/schemas/defaulted.js +7 -23
  198. package/schema/schemas/defaulted.js.map +1 -1
  199. package/schema/schemas/enumeration.d.ts +6 -18
  200. package/schema/schemas/enumeration.js +13 -50
  201. package/schema/schemas/enumeration.js.map +1 -1
  202. package/schema/schemas/exclude.d.ts +4 -0
  203. package/schema/schemas/exclude.js +17 -0
  204. package/schema/schemas/exclude.js.map +1 -0
  205. package/schema/schemas/index.d.ts +5 -6
  206. package/schema/schemas/index.js +5 -6
  207. package/schema/schemas/index.js.map +1 -1
  208. package/schema/schemas/instance.d.ts +2 -12
  209. package/schema/schemas/instance.js +4 -20
  210. package/schema/schemas/instance.js.map +1 -1
  211. package/schema/schemas/literal.d.ts +4 -11
  212. package/schema/schemas/literal.js +13 -18
  213. package/schema/schemas/literal.js.map +1 -1
  214. package/schema/schemas/nullable.d.ts +3 -13
  215. package/schema/schemas/nullable.js +3 -26
  216. package/schema/schemas/nullable.js.map +1 -1
  217. package/schema/schemas/number.d.ts +7 -14
  218. package/schema/schemas/number.js +23 -44
  219. package/schema/schemas/number.js.map +1 -1
  220. package/schema/schemas/object.d.ts +6 -34
  221. package/schema/schemas/object.js +8 -112
  222. package/schema/schemas/object.js.map +1 -1
  223. package/schema/schemas/optional.d.ts +3 -13
  224. package/schema/schemas/optional.js +3 -26
  225. package/schema/schemas/optional.js.map +1 -1
  226. package/schema/schemas/pick.d.ts +4 -0
  227. package/schema/schemas/pick.js +17 -0
  228. package/schema/schemas/pick.js.map +1 -0
  229. package/schema/schemas/readable-stream.d.ts +4 -9
  230. package/schema/schemas/readable-stream.js +9 -15
  231. package/schema/schemas/readable-stream.js.map +1 -1
  232. package/schema/schemas/record.d.ts +4 -0
  233. package/schema/schemas/record.js +14 -0
  234. package/schema/schemas/record.js.map +1 -0
  235. package/schema/schemas/regexp.d.ts +6 -9
  236. package/schema/schemas/regexp.js +10 -27
  237. package/schema/schemas/regexp.js.map +1 -1
  238. package/schema/schemas/string.d.ts +9 -13
  239. package/schema/schemas/string.js +34 -46
  240. package/schema/schemas/string.js.map +1 -1
  241. package/schema/schemas/transform.d.ts +4 -16
  242. package/schema/schemas/transform.js +7 -36
  243. package/schema/schemas/transform.js.map +1 -1
  244. package/schema/schemas/uint8-array.d.ts +8 -11
  245. package/schema/schemas/uint8-array.js +20 -32
  246. package/schema/schemas/uint8-array.js.map +1 -1
  247. package/schema/schemas/union.d.ts +5 -17
  248. package/schema/schemas/union.js +9 -35
  249. package/schema/schemas/union.js.map +1 -1
  250. package/schema/schemas/unknown.d.ts +4 -8
  251. package/schema/schemas/unknown.js +9 -14
  252. package/schema/schemas/unknown.js.map +1 -1
  253. package/schema/transformers/generic.d.ts +13 -0
  254. package/schema/transformers/generic.js +28 -0
  255. package/schema/transformers/generic.js.map +1 -0
  256. package/schema/transformers/index.d.ts +3 -0
  257. package/{old-api/endpoints → schema/transformers}/index.js +3 -1
  258. package/schema/transformers/index.js.map +1 -0
  259. package/schema/transformers/lowercase.d.ts +9 -0
  260. package/schema/transformers/lowercase.js +22 -0
  261. package/schema/transformers/lowercase.js.map +1 -0
  262. package/schema/transformers/trim.d.ts +9 -0
  263. package/schema/transformers/trim.js +22 -0
  264. package/schema/transformers/trim.js.map +1 -0
  265. package/schema/transformers/uppercase.d.ts +9 -0
  266. package/schema/transformers/uppercase.js +22 -0
  267. package/schema/transformers/uppercase.js.map +1 -0
  268. package/schema/types.d.ts +135 -15
  269. package/schema/types.js +39 -3
  270. package/schema/types.js.map +1 -1
  271. package/schema/utils/index.d.ts +2 -0
  272. package/{old-api/validation → schema/utils}/index.js +2 -1
  273. package/schema/utils/index.js.map +1 -0
  274. package/schema/utils/schema.d.ts +12 -0
  275. package/schema/utils/schema.js +78 -0
  276. package/schema/utils/schema.js.map +1 -0
  277. package/schema/utils/value-type.d.ts +4 -0
  278. package/schema/utils/value-type.js +35 -0
  279. package/schema/utils/value-type.js.map +1 -0
  280. package/templates/providers/file-template.provider.base.d.ts +1 -1
  281. package/templates/providers/file-template.provider.base.js +3 -2
  282. package/templates/providers/file-template.provider.base.js.map +1 -1
  283. package/types.d.ts +5 -1
  284. package/utils/clone.d.ts +1 -0
  285. package/utils/clone.js +45 -0
  286. package/utils/clone.js.map +1 -0
  287. package/utils/enum.d.ts +1 -1
  288. package/utils/format-error.d.ts +20 -0
  289. package/utils/format-error.js +42 -0
  290. package/utils/format-error.js.map +1 -0
  291. package/utils/function/memoize.d.ts +6 -2
  292. package/utils/function/memoize.js +28 -20
  293. package/utils/function/memoize.js.map +1 -1
  294. package/utils/helpers.d.ts +1 -32
  295. package/utils/helpers.js +3 -158
  296. package/utils/helpers.js.map +1 -1
  297. package/utils/index.d.ts +3 -0
  298. package/utils/index.js +3 -0
  299. package/utils/index.js.map +1 -1
  300. package/utils/merge.d.ts +5 -0
  301. package/utils/merge.js +32 -0
  302. package/utils/merge.js.map +1 -0
  303. package/utils/object/decycle.d.ts +16 -0
  304. package/utils/object/decycle.js +81 -0
  305. package/utils/object/decycle.js.map +1 -0
  306. package/utils/object/dereference.js.map +1 -1
  307. package/utils/object/index.d.ts +1 -0
  308. package/utils/object/index.js +1 -0
  309. package/utils/object/index.js.map +1 -1
  310. package/utils/object/object.d.ts +4 -0
  311. package/utils/object/object.js +9 -2
  312. package/utils/object/object.js.map +1 -1
  313. package/utils/patterns.d.ts +1 -1
  314. package/utils/patterns.js +3 -3
  315. package/utils/patterns.js.map +1 -1
  316. package/utils/timing.d.ts +0 -8
  317. package/utils/timing.js.map +1 -1
  318. package/utils/type-guards.d.ts +6 -0
  319. package/utils/type-guards.js +16 -4
  320. package/utils/type-guards.js.map +1 -1
  321. package/instance-provider.d.ts +0 -17
  322. package/instance-provider.js +0 -55
  323. package/instance-provider.js.map +0 -1
  324. package/module/modules/old-web-server.module.d.ts +0 -22
  325. package/module/modules/old-web-server.module.js +0 -37
  326. package/module/modules/old-web-server.module.js.map +0 -1
  327. package/old-api/endpoint.d.ts +0 -5
  328. package/old-api/endpoint.js +0 -20
  329. package/old-api/endpoint.js.map +0 -1
  330. package/old-api/endpoints/echo.endpoint.d.ts +0 -2
  331. package/old-api/endpoints/echo.endpoint.js +0 -6
  332. package/old-api/endpoints/echo.endpoint.js.map +0 -1
  333. package/old-api/endpoints/index.d.ts +0 -1
  334. package/old-api/endpoints/index.js.map +0 -1
  335. package/old-api/http-api.d.ts +0 -63
  336. package/old-api/http-api.js +0 -269
  337. package/old-api/http-api.js.map +0 -1
  338. package/old-api/index.d.ts +0 -3
  339. package/old-api/index.js.map +0 -1
  340. package/old-api/validation/index.d.ts +0 -1
  341. package/old-api/validation/index.js.map +0 -1
  342. package/old-api/validation/types.d.ts +0 -6
  343. package/old-api/validation/types.js +0 -6
  344. package/old-api/validation/types.js.map +0 -1
  345. package/old-api/validation/validators/index.d.ts +0 -1
  346. package/old-api/validation/validators/index.js.map +0 -1
  347. package/old-api/validation/validators/noop.d.ts +0 -2
  348. package/old-api/validation/validators/noop.js +0 -8
  349. package/old-api/validation/validators/noop.js.map +0 -1
  350. package/old-api/validation/validators/superstruct.d.ts +0 -14
  351. package/old-api/validation/validators/superstruct.js +0 -66
  352. package/old-api/validation/validators/superstruct.js.map +0 -1
  353. package/old-api/validation/validators/yup.d.ts +0 -7
  354. package/old-api/validation/validators/yup.js +0 -60
  355. package/old-api/validation/validators/yup.js.map +0 -1
  356. package/schema/schema.validator.d.ts +0 -40
  357. package/schema/schema.validator.js +0 -75
  358. package/schema/schema.validator.js.map +0 -1
  359. package/schema/schemas/async-iterable.d.ts +0 -13
  360. package/schema/schemas/async-iterable.js +0 -40
  361. package/schema/schemas/async-iterable.js.map +0 -1
  362. package/schema/schemas/iterable.d.ts +0 -13
  363. package/schema/schemas/iterable.js +0 -40
  364. package/schema/schemas/iterable.js.map +0 -1
  365. package/schema/schemas/never.d.ts +0 -9
  366. package/schema/schemas/never.js +0 -22
  367. package/schema/schemas/never.js.map +0 -1
  368. package/schema/schemas/preprocess.d.ts +0 -16
  369. package/schema/schemas/preprocess.js +0 -35
  370. package/schema/schemas/preprocess.js.map +0 -1
  371. package/schema/schemas/refine.d.ts +0 -24
  372. package/schema/schemas/refine.js +0 -52
  373. package/schema/schemas/refine.js.map +0 -1
@@ -14,7 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("../api/default-error-handlers"), exports);
18
- __exportStar(require("../api/response"), exports);
19
- __exportStar(require("./endpoint"), exports);
17
+ __exportStar(require("./array"), exports);
18
+ __exportStar(require("./coerce"), exports);
19
+ __exportStar(require("./nullable"), exports);
20
+ __exportStar(require("./optional"), exports);
21
+ __exportStar(require("./property"), exports);
22
+ __exportStar(require("./type"), exports);
23
+ __exportStar(require("./types"), exports);
24
+ __exportStar(require("./utils"), exports);
20
25
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/schema/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB"}
@@ -0,0 +1,2 @@
1
+ import type { Decorator } from "../../reflection";
2
+ export declare function Nullable(): Decorator<'property' | 'accessor'>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Nullable = void 0;
5
+ const utils_1 = require("./utils");
6
+ function Nullable() {
7
+ return (0, utils_1.createSchemaPropertyDecorator)({ nullable: true });
8
+ }
9
+ exports.Nullable = Nullable;
10
+ //# sourceMappingURL=nullable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../source/schema/decorators/nullable.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,mCAAwD;AAExD,SAAgB,QAAQ;IACtB,OAAO,IAAA,qCAA6B,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,2 @@
1
+ import type { Decorator } from "../../reflection";
2
+ export declare function Optional(): Decorator<'property' | 'accessor'>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Optional = void 0;
5
+ const utils_1 = require("./utils");
6
+ function Optional() {
7
+ return (0, utils_1.createSchemaPropertyDecorator)({ optional: true });
8
+ }
9
+ exports.Optional = Optional;
10
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/decorators/optional.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,mCAAwD;AAExD,SAAgB,QAAQ;IACtB,OAAO,IAAA,qCAA6B,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,6 @@
1
+ import type { Decorator } from "../../reflection";
2
+ import type { TypedOmit } from "../../types";
3
+ import type { ValueTypes } from '../types';
4
+ import type { PropertyOptions } from './types';
5
+ export declare function Property(options?: PropertyOptions): Decorator<'property' | 'accessor'>;
6
+ export declare function Property(types?: () => ValueTypes, options?: TypedOmit<PropertyOptions, 'type'>): Decorator<'property' | 'accessor'>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Property = void 0;
5
+ const array_1 = require("../../utils/array/array");
6
+ const type_guards_1 = require("../../utils/type-guards");
7
+ const utils_1 = require("./utils");
8
+ function Property(optionsOrTypes = {}, optionsOrNothing) {
9
+ const options = (0, type_guards_1.isFunction)(optionsOrTypes) ? { type: { deferred: optionsOrTypes }, ...optionsOrNothing } : optionsOrTypes;
10
+ return (0, utils_1.createSchemaPropertyDecorator)({
11
+ ...options,
12
+ coercers: (0, type_guards_1.isDefined)(options.coercers) ? (0, array_1.toArray)(options.coercers) : undefined,
13
+ transformers: (0, type_guards_1.isDefined)(options.transformers) ? (0, array_1.toArray)(options.transformers) : undefined,
14
+ arrayConstraints: (0, type_guards_1.isDefined)(options.arrayConstraints) ? (0, array_1.toArray)(options.arrayConstraints) : undefined,
15
+ valueConstraints: (0, type_guards_1.isDefined)(options.valueConstraints) ? (0, array_1.toArray)(options.valueConstraints) : undefined
16
+ });
17
+ }
18
+ exports.Property = Property;
19
+ //# sourceMappingURL=property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.js","sourceRoot":"","sources":["../../../source/schema/decorators/property.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,mDAA8C;AAC9C,yDAA4D;AAG5D,mCAAwD;AAIxD,SAAgB,QAAQ,CAAC,iBAAuD,EAAE,EAAE,gBAAkC;IACpH,MAAM,OAAO,GAAoB,IAAA,wBAAU,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;IAE3I,OAAO,IAAA,qCAA6B,EAAC;QACnC,GAAG,OAAO;QACV,QAAQ,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QAC7E,YAAY,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;QACzF,gBAAgB,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS;QACrG,gBAAgB,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS;KACtG,CAAC,CAAC;AACL,CAAC;AAVD,4BAUC"}
@@ -0,0 +1,3 @@
1
+ import type { Decorator } from "../../reflection";
2
+ import type { SchemaTypeReflectionData } from './types';
3
+ export declare function Type(options?: SchemaTypeReflectionData): Decorator<'class'>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Type = void 0;
5
+ const reflection_1 = require("../../reflection");
6
+ function Type(options = {}) {
7
+ return (0, reflection_1.createClassDecorator)({ data: { schema: options }, mergeData: true });
8
+ }
9
+ exports.Type = Type;
10
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/schema/decorators/type.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,iDAAoD;AAGpD,SAAgB,IAAI,CAAC,UAAoC,EAAE;IACzD,OAAO,IAAA,iCAAoB,EAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9E,CAAC;AAFD,oBAEC"}
@@ -0,0 +1,18 @@
1
+ import type { OneOrMany } from "../../types";
2
+ import type { MaybeDeferredValueTypes, ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueSchema, ValueType } from '../types';
3
+ export declare type SchemaTypeReflectionData = Partial<Pick<ObjectSchema, 'mask' | 'allowUnknownProperties'>> & {
4
+ factory?: SchemaFactoryFunction<any>;
5
+ };
6
+ export declare type TypesProvider = () => OneOrMany<ValueType>;
7
+ export declare type SchemaPropertyReflectionData = {
8
+ type?: MaybeDeferredValueTypes;
9
+ array?: boolean;
10
+ optional?: boolean;
11
+ nullable?: boolean;
12
+ coerce?: boolean;
13
+ coercers?: readonly SchemaValueCoercer[];
14
+ transformers?: readonly SchemaValueTransformer[];
15
+ arrayConstraints?: readonly SchemaArrayConstraint[];
16
+ valueConstraints?: readonly SchemaValueConstraint[];
17
+ };
18
+ export declare type PropertyOptions = Partial<ValueSchema>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../source/schema/decorators/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { Decorator } from "../../reflection";
2
+ import type { OneOrMany } from "../../types";
3
+ import type { SchemaArrayConstraint, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueType } from '../types';
4
+ import type { PropertyOptions } from './types';
5
+ export declare function createSchemaPropertyDecorator(options: PropertyOptions): Decorator<'property' | 'accessor'>;
6
+ export declare function createSchemaPropertyDecoratorFromValueType(valueType: ValueType): Decorator<'property' | 'accessor'>;
7
+ export declare function createSchemaValueCoercerDecorator(coercer: SchemaValueCoercer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
8
+ export declare function createSchemaValueTransformerDecorator(transformer: SchemaValueTransformer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
9
+ export declare function createSchemaArrayConstraintDecorator(constraint: SchemaArrayConstraint, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
10
+ export declare function createSchemaValueConstraintDecorator(constraints: OneOrMany<SchemaValueConstraint>, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createSchemaValueConstraintDecorator = exports.createSchemaArrayConstraintDecorator = exports.createSchemaValueTransformerDecorator = exports.createSchemaValueCoercerDecorator = exports.createSchemaPropertyDecoratorFromValueType = exports.createSchemaPropertyDecorator = void 0;
5
+ const reflection_1 = require("../../reflection");
6
+ const array_1 = require("../../utils/array/array");
7
+ const merge_1 = require("../../utils/merge");
8
+ const object_1 = require("../../utils/object");
9
+ const type_guards_1 = require("../../utils/type-guards");
10
+ const types_1 = require("../types");
11
+ function createSchemaPropertyDecorator(options) {
12
+ return (0, reflection_1.createPropertyOrAccessorDecorator)({
13
+ handler(_, metadata) {
14
+ const schemaData = getSchemaPropertyReflectionData(metadata);
15
+ const newSchemaData = {
16
+ ...options,
17
+ coercers: ((0, type_guards_1.isDefined)(options.coercers) && (!(0, type_guards_1.isArray)(options.coercers) || options.coercers.length > 0)) ? (0, merge_1.merge)((0, array_1.toArray)(options.coercers), schemaData.coercers) : undefined,
18
+ transformers: ((0, type_guards_1.isDefined)(options.transformers) && (!(0, type_guards_1.isArray)(options.transformers) || options.transformers.length > 0)) ? (0, merge_1.merge)((0, array_1.toArray)(options.transformers), schemaData.transformers) : undefined,
19
+ arrayConstraints: ((0, type_guards_1.isDefined)(options.arrayConstraints) && (!(0, type_guards_1.isArray)(options.arrayConstraints) || options.arrayConstraints.length > 0)) ? (0, merge_1.merge)((0, array_1.toArray)(options.arrayConstraints), schemaData.arrayConstraints) : undefined,
20
+ valueConstraints: ((0, type_guards_1.isDefined)(options.valueConstraints) && (!(0, type_guards_1.isArray)(options.valueConstraints) || options.valueConstraints.length > 0)) ? (0, merge_1.merge)((0, array_1.toArray)(options.valueConstraints), schemaData.valueConstraints) : undefined
21
+ };
22
+ metadata.data.set('schema', (0, object_1.filterObject)(newSchemaData, type_guards_1.isDefined), true);
23
+ }
24
+ });
25
+ }
26
+ exports.createSchemaPropertyDecorator = createSchemaPropertyDecorator;
27
+ function createSchemaPropertyDecoratorFromValueType(valueType) {
28
+ const schema = (0, types_1.isValueSchema)(valueType) ? valueType : (0, types_1.valueSchema)({ type: valueType });
29
+ return createSchemaPropertyDecorator({
30
+ ...schema,
31
+ type: schema.type
32
+ });
33
+ }
34
+ exports.createSchemaPropertyDecoratorFromValueType = createSchemaPropertyDecoratorFromValueType;
35
+ function createSchemaValueCoercerDecorator(coercer, options) {
36
+ return createSchemaPropertyDecorator({ ...options, coercers: coercer });
37
+ }
38
+ exports.createSchemaValueCoercerDecorator = createSchemaValueCoercerDecorator;
39
+ function createSchemaValueTransformerDecorator(transformer, options) {
40
+ return createSchemaPropertyDecorator({ ...options, transformers: transformer });
41
+ }
42
+ exports.createSchemaValueTransformerDecorator = createSchemaValueTransformerDecorator;
43
+ function createSchemaArrayConstraintDecorator(constraint, options) {
44
+ return createSchemaPropertyDecorator({ ...options, arrayConstraints: constraint });
45
+ }
46
+ exports.createSchemaArrayConstraintDecorator = createSchemaArrayConstraintDecorator;
47
+ function createSchemaValueConstraintDecorator(constraints, options) {
48
+ return createSchemaPropertyDecorator({ ...options, valueConstraints: constraints });
49
+ }
50
+ exports.createSchemaValueConstraintDecorator = createSchemaValueConstraintDecorator;
51
+ function getSchemaPropertyReflectionData(metadata) {
52
+ let schemaData = metadata.data.tryGet('schema');
53
+ if ((0, type_guards_1.isUndefined)(schemaData)) {
54
+ schemaData = {};
55
+ metadata.data.set('schema', schemaData);
56
+ }
57
+ return schemaData;
58
+ }
59
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../source/schema/decorators/utils.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,iDAAiE;AAEjE,mDAA8C;AAC9C,6CAAsC;AACtC,+CAA8C;AAC9C,yDAAsE;AAEtE,oCAAsD;AAGtD,SAAgB,6BAA6B,CAAC,OAAwB;IACpE,OAAO,IAAA,8CAAiC,EAAC;QACvC,OAAO,CAAC,CAAC,EAAE,QAAQ;YACjB,MAAM,UAAU,GAAG,+BAA+B,CAAC,QAAQ,CAAC,CAAC;YAE7D,MAAM,aAAa,GAAiC;gBAClD,GAAG,OAAO;gBACV,QAAQ,EAAE,CAAC,IAAA,uBAAS,EAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAA,qBAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,aAAK,EAAC,IAAA,eAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,E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U,CAAC,CAAC;KACzC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
package/schema/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
+ export * from './array-constraints';
2
+ export * from './coercers';
3
+ export * from './constraints';
4
+ export * from './decorators';
5
+ export * from './schema';
1
6
  export * from './schema.error';
2
- export * from './schema.validator';
3
7
  export * from './schemas';
8
+ export * from './transformers';
4
9
  export * from './types';
10
+ export * from './utils';
package/schema/index.js CHANGED
@@ -14,8 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./array-constraints"), exports);
18
+ __exportStar(require("./coercers"), exports);
19
+ __exportStar(require("./constraints"), exports);
20
+ __exportStar(require("./decorators"), exports);
21
+ __exportStar(require("./schema"), exports);
17
22
  __exportStar(require("./schema.error"), exports);
18
- __exportStar(require("./schema.validator"), exports);
19
23
  __exportStar(require("./schemas"), exports);
24
+ __exportStar(require("./transformers"), exports);
20
25
  __exportStar(require("./types"), exports);
26
+ __exportStar(require("./utils"), exports);
21
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/schema/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,qDAAmC;AACnC,4CAA0B;AAC1B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/schema/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,6CAA2B;AAC3B,gDAA8B;AAC9B,+CAA6B;AAC7B,2CAAyB;AACzB,iDAA+B;AAC/B,4CAA0B;AAC1B,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB"}
@@ -0,0 +1,19 @@
1
+ import { JsonPath } from "../json-path";
2
+ import type { Type } from "../types";
3
+ import type { ObjectSchema, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, ValueSchema } from './types';
4
+ export declare type Schema<T = any> = ObjectSchema<T> | ValueSchema<T>;
5
+ export declare const getSchemaFromReflection: typeof _getObjectSchemaFromReflection;
6
+ export declare type SchemaTestable<T = any> = Schema<T> | Type<T>;
7
+ export declare const Schema: {
8
+ registerDefaultCoercer(coercer: SchemaValueCoercer): void;
9
+ test<T>(schema: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
10
+ validate<T_1>(schema: SchemaTestable<T_1>, value: unknown, options?: SchemaTestOptions): boolean;
11
+ parse<T_2>(schema: SchemaTestable<T_2>, value: unknown, options?: SchemaTestOptions): T_2;
12
+ /**
13
+ * disables stack traces for errors
14
+ * @deprecated for internal use only
15
+ */
16
+ testWithFastError<T_3>(schema: SchemaTestable<T_3>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T_3>;
17
+ };
18
+ declare function _getObjectSchemaFromReflection<T>(type: Type<T>): ObjectSchema<T> | null;
19
+ export {};
@@ -1,15 +1,21 @@
1
+ import type { CustomErrorOptions } from "../error";
1
2
  import { CustomError } from "../error";
2
3
  import type { JsonPath } from "../json-path";
3
- export declare type SchemaErrorOptions = {
4
+ import type { OneOrMany, TypedOmit, UndefinableJson } from "../types";
5
+ import type { ErrorExtraInfo } from "../utils/format-error";
6
+ import type { ValueType } from './types';
7
+ export declare type SchemaErrorOptions = Pick<CustomErrorOptions, 'fast'> & {
4
8
  path: string | JsonPath;
5
- details?: any;
9
+ inner?: OneOrMany<SchemaError>;
10
+ details?: UndefinableJson;
6
11
  };
7
- export declare class SchemaError extends CustomError {
12
+ export declare class SchemaError extends CustomError implements ErrorExtraInfo {
8
13
  static readonly errorName = "SchemaError";
9
14
  readonly path: string;
10
- readonly details: any;
15
+ readonly inner?: SchemaError[];
16
+ readonly details?: UndefinableJson;
11
17
  constructor(message: string, options: SchemaErrorOptions, cause?: any);
12
- static expectedButGot(expected: string, got: string, path: string | JsonPath): SchemaError;
13
- static couldNotCoerce(expected: string, got: string, message: string, path: string | JsonPath): SchemaError;
18
+ static expectedButGot(expected: OneOrMany<string | ValueType>, got: string | ValueType, path: string | JsonPath, options?: TypedOmit<SchemaErrorOptions, 'path'>): SchemaError;
19
+ static couldNotCoerce(expected: OneOrMany<string | ValueType>, got: string | ValueType, path: string | JsonPath, customMessage?: string | undefined, options?: TypedOmit<SchemaErrorOptions, 'path'>): SchemaError;
20
+ getExtraInfo(includeMessage?: boolean): UndefinableJson | undefined;
14
21
  }
15
- export declare function schemaError(message: string, path: string | JsonPath): SchemaError;
@@ -1,29 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schemaError = exports.SchemaError = void 0;
3
+ exports.SchemaError = void 0;
4
4
  const error_1 = require("../error");
5
+ const array_1 = require("../utils/array/array");
5
6
  const type_guards_1 = require("../utils/type-guards");
7
+ const utils_1 = require("./utils");
6
8
  class SchemaError extends error_1.CustomError {
7
9
  constructor(message, options, cause) {
8
- super({ message, cause });
10
+ super({ message, cause, fast: options.fast ?? true });
9
11
  this.path = (0, type_guards_1.isString)(options.path) ? options.path : options.path.path;
10
- if ((0, type_guards_1.isNotNullOrUndefined)(this.details)) {
12
+ if ((0, type_guards_1.isDefined)(options.inner)) {
13
+ const errors = (0, array_1.toArray)(options.inner);
14
+ if (errors.length > 0) {
15
+ this.inner = errors;
16
+ }
17
+ }
18
+ if ((0, type_guards_1.isNotNullOrUndefined)(options.details)) {
11
19
  this.details = options.details;
12
20
  }
13
21
  }
14
- static expectedButGot(expected, got, path) {
15
- const message = `expected ${expected} but got ${got}`;
16
- return new SchemaError(message, { path });
22
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
23
+ static expectedButGot(expected, got, path, options) {
24
+ const expectedNames = (0, array_1.toArray)(expected).map((exp) => ((0, type_guards_1.isString)(exp) ? exp : (0, utils_1.getValueTypeName)(exp)));
25
+ const gotName = (0, type_guards_1.isString)(got) ? got : (0, utils_1.getValueTypeName)(got);
26
+ const expectedString = expectedNames.length == 1
27
+ ? expectedNames[0]
28
+ : `[${expectedNames.join(', ')}]`;
29
+ const message = `Expected ${expectedString} but got ${gotName}.`;
30
+ return new SchemaError(message, { path, ...options });
17
31
  }
18
- static couldNotCoerce(expected, got, message, path) {
19
- const errorMessage = `could not coerce ${got} to ${expected}: ${message}`;
20
- return new SchemaError(errorMessage, { path });
32
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
33
+ static couldNotCoerce(expected, got, path, customMessage, options) {
34
+ const expectedNames = (0, array_1.toArray)(expected).map((exp) => ((0, type_guards_1.isString)(exp) ? exp : (0, utils_1.getValueTypeName)(exp)));
35
+ const gotText = (0, type_guards_1.isString)(got) ? got : (0, utils_1.getValueTypeName)(got);
36
+ const expectedString = expectedNames.length == 1
37
+ ? expectedNames[0]
38
+ : `[${expectedNames.join(', ')}]`;
39
+ const customMessageString = (0, type_guards_1.isDefined)(customMessage) ? `: ${customMessage}` : '.';
40
+ const errorMessage = `Could not coerce ${gotText} to ${expectedString}${customMessageString}`;
41
+ return new SchemaError(errorMessage, { path, ...options });
42
+ }
43
+ getExtraInfo(includeMessage = false) {
44
+ const obj = {
45
+ path: this.path
46
+ };
47
+ if (includeMessage) {
48
+ obj['message'] = this.message;
49
+ }
50
+ if ((0, type_guards_1.isDefined)(this.inner) && (this.inner.length > 0)) {
51
+ obj['inner'] = this.inner.map((error) => error.getExtraInfo(true));
52
+ }
53
+ if ((0, type_guards_1.isNotNullOrUndefined)(this.details)) {
54
+ obj['details'] = this.details;
55
+ }
56
+ return obj;
21
57
  }
22
58
  }
23
59
  exports.SchemaError = SchemaError;
24
60
  SchemaError.errorName = 'SchemaError';
25
- function schemaError(message, path) {
26
- return new SchemaError(message, { path });
27
- }
28
- exports.schemaError = schemaError;
29
61
  //# sourceMappingURL=schema.error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AAAA,oCAAsC;AAEtC,sDAAqE;AAOrE,MAAa,WAAY,SAAQ,mBAAW;IAM1C,YAAY,OAAe,EAAE,OAA2B,EAAE,KAAW;QACnE,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAQ,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAEtE,IAAI,IAAA,kCAAoB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;SAChC;IACH,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,GAAW,EAAE,IAAuB;QAC1E,MAAM,OAAO,GAAG,YAAY,QAAQ,YAAY,GAAG,EAAE,CAAC;QACtD,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,GAAW,EAAE,OAAe,EAAE,IAAuB;QAC3F,MAAM,YAAY,GAAG,oBAAoB,GAAG,OAAO,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC1E,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;;AAxBH,kCAyBC;AAxBiB,qBAAS,GAAG,aAAa,CAAC;AA0B5C,SAAgB,WAAW,CAAC,OAAe,EAAE,IAAuB;IAClE,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC;AAFD,kCAEC"}
1
+ {"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema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