@tstdl/base 0.71.89 → 0.78.0-beta10

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 (385) 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/gateway.js +15 -18
  8. package/api/server/gateway.js.map +1 -1
  9. package/api/server/module.d.ts +0 -4
  10. package/api/server/module.js +1 -12
  11. package/api/server/module.js.map +1 -1
  12. package/api/types.d.ts +15 -36
  13. package/api/types.js.map +1 -1
  14. package/container/container.js +2 -2
  15. package/container/container.js.map +1 -1
  16. package/container/resolve-chain.d.ts +5 -5
  17. package/container/resolve-chain.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/enumerable/async-enumerable.d.ts +2 -1
  28. package/enumerable/async-enumerable.js +3 -0
  29. package/enumerable/async-enumerable.js.map +1 -1
  30. package/enumerable/enumerable-methods.d.ts +1 -0
  31. package/enumerable/enumerable.d.ts +1 -0
  32. package/enumerable/enumerable.js +12 -18
  33. package/enumerable/enumerable.js.map +1 -1
  34. package/error/custom.error.d.ts +3 -1
  35. package/error/custom.error.js +16 -7
  36. package/error/custom.error.js.map +1 -1
  37. package/examples/api/basic-overview.js +16 -8
  38. package/examples/api/basic-overview.js.map +1 -1
  39. package/http/client/adapters/utils.js.map +1 -1
  40. package/image-service/image-service.d.ts +32 -65
  41. package/image-service/image-service.js +73 -15
  42. package/image-service/image-service.js.map +1 -1
  43. package/json-path/json-path.d.ts +8 -3
  44. package/json-path/json-path.js +24 -7
  45. package/json-path/json-path.js.map +1 -1
  46. package/mail/template-providers/file-mail-template.provider.js +2 -2
  47. package/mail/template-providers/file-mail-template.provider.js.map +1 -1
  48. package/module/modules/index.d.ts +0 -1
  49. package/module/modules/index.js +0 -1
  50. package/module/modules/index.js.map +1 -1
  51. package/openid-connect/oidc-configuration.service.js +7 -7
  52. package/openid-connect/oidc-configuration.service.js.map +1 -1
  53. package/openid-connect/oidc.service.js +7 -7
  54. package/openid-connect/oidc.service.js.map +1 -1
  55. package/package.json +2 -4
  56. package/process-shutdown.js +3 -2
  57. package/process-shutdown.js.map +1 -1
  58. package/promise/deferred-promise.d.ts +2 -15
  59. package/promise/deferred-promise.js +5 -10
  60. package/promise/deferred-promise.js.map +1 -1
  61. package/promise/lazy-promise.d.ts +11 -0
  62. package/promise/lazy-promise.js +31 -0
  63. package/promise/lazy-promise.js.map +1 -0
  64. package/reflection/decorators.js +1 -0
  65. package/reflection/decorators.js.map +1 -1
  66. package/reflection/reflection-data-map.d.ts +10 -0
  67. package/reflection/reflection-data-map.js +40 -0
  68. package/reflection/reflection-data-map.js.map +1 -0
  69. package/reflection/registry.d.ts +15 -15
  70. package/reflection/registry.js +7 -6
  71. package/reflection/registry.js.map +1 -1
  72. package/reflection/types.d.ts +1 -0
  73. package/reflection/utils.d.ts +6 -3
  74. package/reflection/utils.js +9 -35
  75. package/reflection/utils.js.map +1 -1
  76. package/schema/array-constraints/index.d.ts +2 -0
  77. package/{old-api/validation/validators → schema/array-constraints}/index.js +2 -1
  78. package/schema/array-constraints/index.js.map +1 -0
  79. package/schema/array-constraints/maximum-length.d.ts +11 -0
  80. package/schema/array-constraints/maximum-length.js +26 -0
  81. package/schema/array-constraints/maximum-length.js.map +1 -0
  82. package/schema/array-constraints/minimum-length.d.ts +11 -0
  83. package/schema/array-constraints/minimum-length.js +26 -0
  84. package/schema/array-constraints/minimum-length.js.map +1 -0
  85. package/schema/coercers/boolean.coercer.d.ts +9 -0
  86. package/schema/coercers/boolean.coercer.js +35 -0
  87. package/schema/coercers/boolean.coercer.js.map +1 -0
  88. package/schema/coercers/date.coercer.d.ts +9 -0
  89. package/schema/coercers/date.coercer.js +24 -0
  90. package/schema/coercers/date.coercer.js.map +1 -0
  91. package/schema/coercers/default-value.coercer.d.ts +9 -0
  92. package/schema/coercers/default-value.coercer.js +16 -0
  93. package/schema/coercers/default-value.coercer.js.map +1 -0
  94. package/schema/coercers/index.d.ts +7 -0
  95. package/schema/coercers/index.js +24 -0
  96. package/schema/coercers/index.js.map +1 -0
  97. package/schema/coercers/number.coercer.d.ts +9 -0
  98. package/schema/coercers/number.coercer.js +22 -0
  99. package/schema/coercers/number.coercer.js.map +1 -0
  100. package/schema/coercers/regexp.coercer.d.ts +11 -0
  101. package/schema/coercers/regexp.coercer.js +24 -0
  102. package/schema/coercers/regexp.coercer.js.map +1 -0
  103. package/schema/coercers/string.coercer.d.ts +9 -0
  104. package/schema/coercers/string.coercer.js +22 -0
  105. package/schema/coercers/string.coercer.js.map +1 -0
  106. package/schema/coercers/uint8-array.coercer.d.ts +9 -0
  107. package/schema/coercers/uint8-array.coercer.js +26 -0
  108. package/schema/coercers/uint8-array.coercer.js.map +1 -0
  109. package/schema/constraints/enumeration.d.ts +13 -0
  110. package/schema/constraints/enumeration.js +29 -0
  111. package/schema/constraints/enumeration.js.map +1 -0
  112. package/schema/constraints/generic.d.ts +22 -0
  113. package/schema/constraints/generic.js +32 -0
  114. package/schema/constraints/generic.js.map +1 -0
  115. package/schema/constraints/index.d.ts +12 -0
  116. package/schema/constraints/index.js +29 -0
  117. package/schema/constraints/index.js.map +1 -0
  118. package/schema/constraints/integer.d.ts +12 -0
  119. package/schema/constraints/integer.js +27 -0
  120. package/schema/constraints/integer.js.map +1 -0
  121. package/schema/constraints/length.d.ts +6 -0
  122. package/schema/constraints/length.js +20 -0
  123. package/schema/constraints/length.js.map +1 -0
  124. package/schema/constraints/literal.d.ts +10 -0
  125. package/schema/constraints/literal.js +26 -0
  126. package/schema/constraints/literal.js.map +1 -0
  127. package/schema/constraints/maximum-date.d.ts +12 -0
  128. package/schema/constraints/maximum-date.js +29 -0
  129. package/schema/constraints/maximum-date.js.map +1 -0
  130. package/schema/constraints/maximum-length.d.ts +12 -0
  131. package/schema/constraints/maximum-length.js +29 -0
  132. package/schema/constraints/maximum-length.js.map +1 -0
  133. package/schema/constraints/maximum.d.ts +12 -0
  134. package/schema/constraints/maximum.js +27 -0
  135. package/schema/constraints/maximum.js.map +1 -0
  136. package/schema/constraints/minimum-date.d.ts +12 -0
  137. package/schema/constraints/minimum-date.js +29 -0
  138. package/schema/constraints/minimum-date.js.map +1 -0
  139. package/schema/constraints/minimum-length.d.ts +12 -0
  140. package/schema/constraints/minimum-length.js +29 -0
  141. package/schema/constraints/minimum-length.js.map +1 -0
  142. package/schema/constraints/minimum.d.ts +12 -0
  143. package/schema/constraints/minimum.js +27 -0
  144. package/schema/constraints/minimum.js.map +1 -0
  145. package/schema/constraints/pattern.d.ts +13 -0
  146. package/schema/constraints/pattern.js +28 -0
  147. package/schema/constraints/pattern.js.map +1 -0
  148. package/schema/decorators/array.d.ts +5 -0
  149. package/schema/decorators/array.js +11 -0
  150. package/schema/decorators/array.js.map +1 -0
  151. package/schema/decorators/coerce.d.ts +2 -0
  152. package/schema/decorators/coerce.js +10 -0
  153. package/schema/decorators/coerce.js.map +1 -0
  154. package/schema/decorators/defaulted.d.ts +4 -0
  155. package/schema/decorators/defaulted.js +11 -0
  156. package/schema/decorators/defaulted.js.map +1 -0
  157. package/schema/decorators/index.d.ts +8 -0
  158. package/{old-api → schema/decorators}/index.js +8 -3
  159. package/schema/decorators/index.js.map +1 -0
  160. package/schema/decorators/nullable.d.ts +2 -0
  161. package/schema/decorators/nullable.js +10 -0
  162. package/schema/decorators/nullable.js.map +1 -0
  163. package/schema/decorators/optional.d.ts +2 -0
  164. package/schema/decorators/optional.js +10 -0
  165. package/schema/decorators/optional.js.map +1 -0
  166. package/schema/decorators/property.d.ts +6 -0
  167. package/schema/decorators/property.js +22 -0
  168. package/schema/decorators/property.js.map +1 -0
  169. package/schema/decorators/type.d.ts +3 -0
  170. package/schema/decorators/type.js +10 -0
  171. package/schema/decorators/type.js.map +1 -0
  172. package/schema/decorators/types.d.ts +18 -0
  173. package/schema/decorators/types.js +3 -0
  174. package/schema/decorators/types.js.map +1 -0
  175. package/schema/decorators/utils.d.ts +11 -0
  176. package/schema/decorators/utils.js +55 -0
  177. package/schema/decorators/utils.js.map +1 -0
  178. package/schema/index.d.ts +7 -1
  179. package/schema/index.js +7 -1
  180. package/schema/index.js.map +1 -1
  181. package/schema/schema.d.ts +20 -0
  182. package/schema/schema.error.d.ts +13 -7
  183. package/schema/schema.error.js +45 -13
  184. package/schema/schema.error.js.map +1 -1
  185. package/schema/schema.js +282 -0
  186. package/schema/schema.js.map +1 -0
  187. package/schema/schemas/any.d.ts +4 -8
  188. package/schema/schemas/any.js +9 -14
  189. package/schema/schemas/any.js.map +1 -1
  190. package/schema/schemas/array.d.ts +9 -13
  191. package/schema/schemas/array.js +13 -43
  192. package/schema/schemas/array.js.map +1 -1
  193. package/schema/schemas/assign.d.ts +8 -0
  194. package/schema/schemas/assign.js +27 -0
  195. package/schema/schemas/assign.js.map +1 -0
  196. package/schema/schemas/boolean.d.ts +5 -9
  197. package/schema/schemas/boolean.js +10 -38
  198. package/schema/schemas/boolean.js.map +1 -1
  199. package/schema/schemas/constraint.d.ts +4 -0
  200. package/schema/schemas/constraint.js +13 -0
  201. package/schema/schemas/constraint.js.map +1 -0
  202. package/schema/schemas/date.d.ts +7 -11
  203. package/schema/schemas/date.js +17 -53
  204. package/schema/schemas/date.js.map +1 -1
  205. package/schema/schemas/defaulted.d.ts +4 -15
  206. package/schema/schemas/defaulted.js +6 -23
  207. package/schema/schemas/defaulted.js.map +1 -1
  208. package/schema/schemas/enumeration.d.ts +6 -18
  209. package/schema/schemas/enumeration.js +12 -50
  210. package/schema/schemas/enumeration.js.map +1 -1
  211. package/schema/schemas/exclude.d.ts +4 -0
  212. package/schema/schemas/exclude.js +17 -0
  213. package/schema/schemas/exclude.js.map +1 -0
  214. package/schema/schemas/index.d.ts +5 -5
  215. package/schema/schemas/index.js +5 -5
  216. package/schema/schemas/index.js.map +1 -1
  217. package/schema/schemas/instance.d.ts +2 -12
  218. package/schema/schemas/instance.js +4 -20
  219. package/schema/schemas/instance.js.map +1 -1
  220. package/schema/schemas/literal.d.ts +4 -11
  221. package/schema/schemas/literal.js +12 -18
  222. package/schema/schemas/literal.js.map +1 -1
  223. package/schema/schemas/nullable.d.ts +3 -13
  224. package/schema/schemas/nullable.js +3 -26
  225. package/schema/schemas/nullable.js.map +1 -1
  226. package/schema/schemas/number.d.ts +7 -14
  227. package/schema/schemas/number.js +25 -44
  228. package/schema/schemas/number.js.map +1 -1
  229. package/schema/schemas/object.d.ts +5 -34
  230. package/schema/schemas/object.js +8 -112
  231. package/schema/schemas/object.js.map +1 -1
  232. package/schema/schemas/optional.d.ts +3 -13
  233. package/schema/schemas/optional.js +3 -26
  234. package/schema/schemas/optional.js.map +1 -1
  235. package/schema/schemas/pick.d.ts +4 -0
  236. package/schema/schemas/pick.js +17 -0
  237. package/schema/schemas/pick.js.map +1 -0
  238. package/schema/schemas/readable-stream.d.ts +4 -9
  239. package/schema/schemas/readable-stream.js +9 -16
  240. package/schema/schemas/readable-stream.js.map +1 -1
  241. package/schema/schemas/record.d.ts +5 -0
  242. package/schema/schemas/record.js +14 -0
  243. package/schema/schemas/record.js.map +1 -0
  244. package/schema/schemas/regexp.d.ts +6 -9
  245. package/schema/schemas/regexp.js +10 -27
  246. package/schema/schemas/regexp.js.map +1 -1
  247. package/schema/schemas/string.d.ts +9 -13
  248. package/schema/schemas/string.js +33 -46
  249. package/schema/schemas/string.js.map +1 -1
  250. package/schema/schemas/transform.d.ts +5 -16
  251. package/schema/schemas/transform.js +5 -36
  252. package/schema/schemas/transform.js.map +1 -1
  253. package/schema/schemas/uint8-array.d.ts +7 -11
  254. package/schema/schemas/uint8-array.js +20 -32
  255. package/schema/schemas/uint8-array.js.map +1 -1
  256. package/schema/schemas/union.d.ts +10 -17
  257. package/schema/schemas/union.js +11 -36
  258. package/schema/schemas/union.js.map +1 -1
  259. package/schema/schemas/unknown.d.ts +4 -8
  260. package/schema/schemas/unknown.js +9 -14
  261. package/schema/schemas/unknown.js.map +1 -1
  262. package/schema/transformers/generic.d.ts +13 -0
  263. package/schema/transformers/generic.js +28 -0
  264. package/schema/transformers/generic.js.map +1 -0
  265. package/schema/transformers/index.d.ts +3 -0
  266. package/{old-api/endpoints → schema/transformers}/index.js +3 -1
  267. package/schema/transformers/index.js.map +1 -0
  268. package/schema/transformers/lowercase.d.ts +9 -0
  269. package/schema/transformers/lowercase.js +22 -0
  270. package/schema/transformers/lowercase.js.map +1 -0
  271. package/schema/transformers/trim.d.ts +9 -0
  272. package/schema/transformers/trim.js +22 -0
  273. package/schema/transformers/trim.js.map +1 -0
  274. package/schema/transformers/uppercase.d.ts +9 -0
  275. package/schema/transformers/uppercase.js +22 -0
  276. package/schema/transformers/uppercase.js.map +1 -0
  277. package/schema/types.d.ts +155 -17
  278. package/schema/types.js +74 -3
  279. package/schema/types.js.map +1 -1
  280. package/schema/utils/index.d.ts +2 -0
  281. package/{old-api/validation → schema/utils}/index.js +2 -1
  282. package/schema/utils/index.js.map +1 -0
  283. package/schema/utils/schema.d.ts +13 -0
  284. package/schema/utils/schema.js +74 -0
  285. package/schema/utils/schema.js.map +1 -0
  286. package/schema/utils/value-type.d.ts +5 -0
  287. package/schema/utils/value-type.js +39 -0
  288. package/schema/utils/value-type.js.map +1 -0
  289. package/templates/providers/file-template.provider.base.d.ts +1 -1
  290. package/templates/providers/file-template.provider.base.js +3 -2
  291. package/templates/providers/file-template.provider.base.js.map +1 -1
  292. package/templates/providers/file-template.provider.js.map +1 -1
  293. package/types.d.ts +8 -4
  294. package/utils/async-iterable-helpers/includes.d.ts +2 -0
  295. package/utils/async-iterable-helpers/includes.js +13 -0
  296. package/utils/async-iterable-helpers/includes.js.map +1 -0
  297. package/utils/async-iterable-helpers/index.d.ts +1 -0
  298. package/utils/async-iterable-helpers/index.js +1 -0
  299. package/utils/async-iterable-helpers/index.js.map +1 -1
  300. package/utils/compression.d.ts +13 -13
  301. package/utils/compression.js +2 -1
  302. package/utils/compression.js.map +1 -1
  303. package/utils/encoding.js +1 -1
  304. package/utils/encoding.js.map +1 -1
  305. package/utils/enum.d.ts +1 -1
  306. package/utils/function/memoize.d.ts +6 -2
  307. package/utils/function/memoize.js +28 -20
  308. package/utils/function/memoize.js.map +1 -1
  309. package/utils/index.d.ts +1 -0
  310. package/utils/index.js +1 -0
  311. package/utils/index.js.map +1 -1
  312. package/utils/iterable-helpers/includes.d.ts +1 -0
  313. package/utils/iterable-helpers/includes.js +9 -0
  314. package/utils/iterable-helpers/includes.js.map +1 -0
  315. package/utils/iterable-helpers/index.d.ts +1 -0
  316. package/utils/iterable-helpers/index.js +1 -0
  317. package/utils/iterable-helpers/index.js.map +1 -1
  318. package/utils/merge.d.ts +5 -0
  319. package/utils/merge.js +32 -0
  320. package/utils/merge.js.map +1 -0
  321. package/utils/object/dereference.js.map +1 -1
  322. package/utils/object/object.d.ts +4 -0
  323. package/utils/object/object.js +9 -2
  324. package/utils/object/object.js.map +1 -1
  325. package/utils/patterns.d.ts +1 -1
  326. package/utils/patterns.js +3 -3
  327. package/utils/patterns.js.map +1 -1
  328. package/utils/timing.d.ts +0 -8
  329. package/utils/timing.js.map +1 -1
  330. package/utils/type-guards.d.ts +6 -0
  331. package/utils/type-guards.js +16 -4
  332. package/utils/type-guards.js.map +1 -1
  333. package/instance-provider.d.ts +0 -17
  334. package/instance-provider.js +0 -55
  335. package/instance-provider.js.map +0 -1
  336. package/module/modules/old-web-server.module.d.ts +0 -22
  337. package/module/modules/old-web-server.module.js +0 -37
  338. package/module/modules/old-web-server.module.js.map +0 -1
  339. package/old-api/endpoint.d.ts +0 -5
  340. package/old-api/endpoint.js +0 -20
  341. package/old-api/endpoint.js.map +0 -1
  342. package/old-api/endpoints/echo.endpoint.d.ts +0 -2
  343. package/old-api/endpoints/echo.endpoint.js +0 -6
  344. package/old-api/endpoints/echo.endpoint.js.map +0 -1
  345. package/old-api/endpoints/index.d.ts +0 -1
  346. package/old-api/endpoints/index.js.map +0 -1
  347. package/old-api/http-api.d.ts +0 -63
  348. package/old-api/http-api.js +0 -269
  349. package/old-api/http-api.js.map +0 -1
  350. package/old-api/index.d.ts +0 -3
  351. package/old-api/index.js.map +0 -1
  352. package/old-api/validation/index.d.ts +0 -1
  353. package/old-api/validation/index.js.map +0 -1
  354. package/old-api/validation/types.d.ts +0 -6
  355. package/old-api/validation/types.js +0 -6
  356. package/old-api/validation/types.js.map +0 -1
  357. package/old-api/validation/validators/index.d.ts +0 -1
  358. package/old-api/validation/validators/index.js.map +0 -1
  359. package/old-api/validation/validators/noop.d.ts +0 -2
  360. package/old-api/validation/validators/noop.js +0 -8
  361. package/old-api/validation/validators/noop.js.map +0 -1
  362. package/old-api/validation/validators/superstruct.d.ts +0 -14
  363. package/old-api/validation/validators/superstruct.js +0 -66
  364. package/old-api/validation/validators/superstruct.js.map +0 -1
  365. package/old-api/validation/validators/yup.d.ts +0 -7
  366. package/old-api/validation/validators/yup.js +0 -60
  367. package/old-api/validation/validators/yup.js.map +0 -1
  368. package/schema/schema.validator.d.ts +0 -40
  369. package/schema/schema.validator.js +0 -75
  370. package/schema/schema.validator.js.map +0 -1
  371. package/schema/schemas/async-iterable.d.ts +0 -13
  372. package/schema/schemas/async-iterable.js +0 -40
  373. package/schema/schemas/async-iterable.js.map +0 -1
  374. package/schema/schemas/iterable.d.ts +0 -13
  375. package/schema/schemas/iterable.js +0 -40
  376. package/schema/schemas/iterable.js.map +0 -1
  377. package/schema/schemas/never.d.ts +0 -9
  378. package/schema/schemas/never.js +0 -22
  379. package/schema/schemas/never.js.map +0 -1
  380. package/schema/schemas/preprocess.d.ts +0 -16
  381. package/schema/schemas/preprocess.js +0 -35
  382. package/schema/schemas/preprocess.js.map +0 -1
  383. package/schema/schemas/refine.d.ts +0 -24
  384. package/schema/schemas/refine.js +0 -52
  385. package/schema/schemas/refine.js.map +0 -1
@@ -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,CAA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AC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;SACpE;QAED,IAAI,IAAA,kCAAoB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACtC,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;SAC/B;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAtEH,kCAuEC;AAtEiB,qBAAS,GAAG,aAAa,CAAC"}
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Schema = exports.getSchemaFromReflection = void 0;
4
+ const json_path_1 = require("../json-path");
5
+ const reflection_1 = require("../reflection");
6
+ const array_1 = require("../utils/array/array");
7
+ const function_1 = require("../utils/function");
8
+ const noop_1 = require("../utils/noop");
9
+ const object_1 = require("../utils/object/object");
10
+ const set_1 = require("../utils/set");
11
+ const type_guards_1 = require("../utils/type-guards");
12
+ const boolean_coercer_1 = require("./coercers/boolean.coercer");
13
+ const date_coercer_1 = require("./coercers/date.coercer");
14
+ const number_coercer_1 = require("./coercers/number.coercer");
15
+ const regexp_coercer_1 = require("./coercers/regexp.coercer");
16
+ const string_coercer_1 = require("./coercers/string.coercer");
17
+ const uint8_array_coercer_1 = require("./coercers/uint8-array.coercer");
18
+ const schema_error_1 = require("./schema.error");
19
+ const types_1 = require("./types");
20
+ const utils_1 = require("./utils");
21
+ exports.getSchemaFromReflection = (0, function_1.memoizeSingle)(_getObjectSchemaFromReflection);
22
+ const defaultCoercers = new Map();
23
+ let initialize = () => {
24
+ exports.Schema.registerDefaultCoercer(number_coercer_1.numberCoercer);
25
+ exports.Schema.registerDefaultCoercer(string_coercer_1.stringCoercer);
26
+ exports.Schema.registerDefaultCoercer(boolean_coercer_1.booleanCoercer);
27
+ exports.Schema.registerDefaultCoercer(date_coercer_1.dateCoercer);
28
+ exports.Schema.registerDefaultCoercer(regexp_coercer_1.regExpCoercer);
29
+ exports.Schema.registerDefaultCoercer(uint8_array_coercer_1.uint8ArrayCoercer);
30
+ initialize = noop_1.noop;
31
+ };
32
+ // eslint-disable-next-line @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention
33
+ exports.Schema = {
34
+ registerDefaultCoercer(coercer) {
35
+ for (const sourceType of (0, array_1.toArray)(coercer.sourceType)) {
36
+ if (!defaultCoercers.has(sourceType)) {
37
+ defaultCoercers.set(sourceType, []);
38
+ }
39
+ defaultCoercers.get(sourceType).push(coercer);
40
+ }
41
+ },
42
+ test(schemaOrValueType, value, options, path = json_path_1.JsonPath.ROOT) {
43
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
44
+ const result = this.testWithFastError(schema, value, options, path);
45
+ if (result.valid) {
46
+ return result;
47
+ }
48
+ return { valid: false, error: new schema_error_1.SchemaError(result.error.message, { ...result.error, fast: false }, result.error.cause) };
49
+ },
50
+ validate(schemaOrValueType, value, options) {
51
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
52
+ const result = this.test(schema, value, options);
53
+ return result.valid;
54
+ },
55
+ parse(schemaOrValueType, value, options) {
56
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
57
+ const result = this.test(schema, value, options);
58
+ if (result.valid) {
59
+ return result.value;
60
+ }
61
+ throw result.error;
62
+ },
63
+ /**
64
+ * disables stack traces for errors
65
+ * @deprecated for internal use only
66
+ */
67
+ testWithFastError(schema, value, options, path = json_path_1.JsonPath.ROOT) {
68
+ initialize();
69
+ if ((0, types_1.isValueSchema)(schema)) {
70
+ return testValue(schema, value, options, path);
71
+ }
72
+ if ((0, types_1.isTypeSchema)(schema)) {
73
+ return testType(schema, value, options, path);
74
+ }
75
+ return testObject(schema, value, options, path);
76
+ }
77
+ };
78
+ function testType(schema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
79
+ const resolvedValueType = (0, types_1.resolveValueType)(schema.type);
80
+ if (resolvedValueType == 'any') {
81
+ return { valid: true, value: value };
82
+ }
83
+ else if ((0, type_guards_1.isFunction)(resolvedValueType)) {
84
+ if (value instanceof resolvedValueType) {
85
+ return { valid: true, value };
86
+ }
87
+ const objectSchema = (0, exports.getSchemaFromReflection)(resolvedValueType);
88
+ if ((0, type_guards_1.isNotNull)(objectSchema)) {
89
+ return testObject(objectSchema, value, options, path);
90
+ }
91
+ }
92
+ else if ((resolvedValueType == 'null' && (0, type_guards_1.isNull)(value)) || (resolvedValueType == 'undefined' && (0, type_guards_1.isUndefined)(value)) || (resolvedValueType == 'any')) {
93
+ return { valid: true, value: value };
94
+ }
95
+ return { valid: false, error: schema_error_1.SchemaError.expectedButGot(resolvedValueType, (0, utils_1.getValueType)(value), path) };
96
+ }
97
+ // eslint-disable-next-line complexity
98
+ function testObject(objectSchema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
99
+ if (!(value instanceof Object)) {
100
+ return { valid: false, error: schema_error_1.SchemaError.expectedButGot(objectSchema.sourceType ?? 'object', (0, utils_1.getValueType)(value), path) };
101
+ }
102
+ const schema = (0, utils_1.normalizeObjectSchema)(objectSchema);
103
+ const mask = schema.mask ?? options.mask ?? false;
104
+ const resultValue = (0, type_guards_1.isDefined)(schema.factory?.type) ? new schema.factory.type() : {};
105
+ const schemaPropertyKeys = (0, object_1.objectKeys)(schema.properties);
106
+ const valuePropertyKeys = (0, object_1.objectKeys)(value);
107
+ const unknownValuePropertyKeys = (0, set_1.differenceSets)(new Set(valuePropertyKeys), new Set(schemaPropertyKeys));
108
+ if ((unknownValuePropertyKeys.length > 0) && !(mask || (schema.allowUnknownProperties.size > 0))) {
109
+ return { valid: false, error: new schema_error_1.SchemaError('Unknown property', { path: path.add(unknownValuePropertyKeys[0]) }) };
110
+ }
111
+ for (const key of schemaPropertyKeys) {
112
+ const propertyResult = exports.Schema.testWithFastError(schema.properties[key], value[key], options, path.add(key));
113
+ if (!propertyResult.valid) {
114
+ return propertyResult;
115
+ }
116
+ resultValue[key] = propertyResult.value;
117
+ }
118
+ if (schema.allowUnknownProperties.size > 0) {
119
+ for (const key of unknownValuePropertyKeys) {
120
+ const errors = [];
121
+ for (const allowedSchema of schema.allowUnknownProperties) {
122
+ const propertyResult = exports.Schema.testWithFastError(allowedSchema, value[key], options, path.add(key));
123
+ if (!propertyResult.valid && !mask) {
124
+ errors.push(propertyResult.error);
125
+ continue;
126
+ }
127
+ resultValue[key] = propertyResult.value;
128
+ break;
129
+ }
130
+ if (errors.length > 0) {
131
+ return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match any allowed schemas.', { inner: errors, path }) };
132
+ }
133
+ }
134
+ }
135
+ const testResultValue = (0, type_guards_1.isUndefined)(schema.factory) ? resultValue : (0, type_guards_1.isDefined)(schema.factory.type) ? resultValue : schema.factory.builder(resultValue);
136
+ return { valid: true, value: testResultValue };
137
+ }
138
+ // eslint-disable-next-line max-lines-per-function, max-statements, complexity
139
+ function testValue(schema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
140
+ const valueSchema = (0, utils_1.normalizeValueSchema)(schema);
141
+ if (valueSchema.optional && (0, type_guards_1.isUndefined)(value)) {
142
+ return { valid: true, value: value };
143
+ }
144
+ if (valueSchema.nullable && (0, type_guards_1.isNull)(value)) {
145
+ return { valid: true, value: value };
146
+ }
147
+ const context = {
148
+ schema: valueSchema,
149
+ options
150
+ };
151
+ /** handle arrays */
152
+ if (valueSchema.array) {
153
+ if (!(0, type_guards_1.isArray)(value)) {
154
+ throw schema_error_1.SchemaError.expectedButGot(Array, (0, utils_1.getValueType)(value), path);
155
+ }
156
+ for (const arrayConstraint of valueSchema.arrayConstraints) {
157
+ const result = arrayConstraint.validate(value, path, context);
158
+ if (!result.valid) {
159
+ return { valid: false, error: result.error };
160
+ }
161
+ }
162
+ const itemSchema = (0, utils_1.getArrayItemSchema)(schema);
163
+ const validatedItems = [];
164
+ for (let i = 0; i < value.length; i++) {
165
+ const result = testValue(itemSchema, value[i], options, path.add(i));
166
+ if (!result.valid) {
167
+ return result;
168
+ }
169
+ validatedItems.push(result.value);
170
+ }
171
+ return { valid: true, value: validatedItems };
172
+ }
173
+ let valueType;
174
+ let valueTestResult;
175
+ let resultValue;
176
+ function updateCurrentState(newValue) {
177
+ resultValue = newValue;
178
+ valueType = (0, utils_1.getValueType)(newValue);
179
+ valueTestResult = isValidValue(valueSchema.schema, newValue, options, path);
180
+ }
181
+ updateCurrentState(value);
182
+ /** try to coerce */
183
+ if (!valueTestResult.valid) {
184
+ const coercers = [
185
+ ...(valueSchema.coercers.get(valueType) ?? []),
186
+ ...((valueSchema.coerce || options.coerce == true) ? (defaultCoercers.get(valueType) ?? []) : [])
187
+ ];
188
+ const errors = [];
189
+ for (const coercer of coercers) {
190
+ const coerceResult = coercer.coerce(resultValue, path, context);
191
+ if (!coerceResult.success) {
192
+ errors.push(coerceResult.error);
193
+ continue;
194
+ }
195
+ updateCurrentState(coerceResult.value);
196
+ break;
197
+ }
198
+ if (errors.length > 0) {
199
+ return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
200
+ }
201
+ }
202
+ if (!valueTestResult.valid) {
203
+ const expectedNames = (0, utils_1.getSchemaTypeNames)(schema);
204
+ const expectedTypeString = (expectedNames.length == 1)
205
+ ? expectedNames[0]
206
+ : `[${expectedNames.join(', ')}]`;
207
+ const expects = valueSchema.valueConstraints.map((constraint) => constraint.expects);
208
+ const expectsString = (expects.length > 0) ? ` (${expects.join(', ')})` : '';
209
+ return { valid: false, error: schema_error_1.SchemaError.expectedButGot(`${expectedTypeString}${expectsString}`, valueType, path) };
210
+ }
211
+ if (valueSchema.transformers.length > 0) {
212
+ let transformedValue = resultValue;
213
+ for (const transformer of valueSchema.transformers) {
214
+ transformedValue = transformer.transform(transformedValue, path, context);
215
+ }
216
+ updateCurrentState(transformedValue);
217
+ if (!valueTestResult.valid) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
218
+ const typeString = (0, utils_1.getValueTypeName)(valueType);
219
+ throw new Error(`Transformers resulted in invalid type (${typeString}).`);
220
+ }
221
+ }
222
+ {
223
+ const errors = [];
224
+ for (const constraint of valueSchema.valueConstraints) {
225
+ const result = constraint.validate(resultValue, path, context);
226
+ if (!result.valid) {
227
+ errors.push(result.error);
228
+ }
229
+ }
230
+ if (errors.length > 0) {
231
+ return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match schema.', { path, fast: true, inner: errors }) };
232
+ }
233
+ }
234
+ return { valid: true, value: resultValue };
235
+ }
236
+ function isValidValue(validSchemas, value, options, path) {
237
+ const errors = [];
238
+ for (const schema of validSchemas) {
239
+ const result = exports.Schema.testWithFastError(schema, value, options, path);
240
+ if (result.valid) {
241
+ return result;
242
+ }
243
+ errors.push(result.error);
244
+ }
245
+ return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match schema.', { path, fast: true, inner: errors }) };
246
+ }
247
+ function _getObjectSchemaFromReflection(type) {
248
+ const metadata = reflection_1.reflectionRegistry.getMetadata(type);
249
+ if (!metadata.registered) {
250
+ return null;
251
+ }
252
+ const typeData = metadata.data.tryGet('schema');
253
+ const properties = {};
254
+ for (const [key, propertyMetadata] of metadata.properties) {
255
+ const reflectionData = propertyMetadata.data.tryGet('schema');
256
+ const itemType = ((0, type_guards_1.isDefined)(reflectionData) && (0, type_guards_1.isDefined)(reflectionData.type)) ? reflectionData.type : undefined;
257
+ const array = reflectionData?.array == true;
258
+ if (array && ((0, type_guards_1.isUndefined)(itemType) || ((0, type_guards_1.isArray)(itemType) && (itemType.length == 0)))) {
259
+ throw new Error(`Item type missing on type ${type.name} at property "${String(key)}"`);
260
+ }
261
+ properties[key] = {
262
+ schema: (0, types_1.valueTypesOrSchemasToSchemas)(itemType ?? propertyMetadata.type),
263
+ array,
264
+ optional: reflectionData?.optional,
265
+ nullable: reflectionData?.nullable,
266
+ coerce: reflectionData?.coerce,
267
+ coercers: reflectionData?.coercers,
268
+ transformers: reflectionData?.transformers,
269
+ arrayConstraints: reflectionData?.arrayConstraints,
270
+ valueConstraints: reflectionData?.valueConstraints
271
+ };
272
+ }
273
+ const objectSchema = {
274
+ sourceType: type,
275
+ factory: (0, type_guards_1.isDefined)(typeData?.factory) ? { builder: typeData.factory } : { type: type },
276
+ properties,
277
+ mask: typeData?.mask,
278
+ allowUnknownProperties: typeData?.allowUnknownProperties
279
+ };
280
+ return objectSchema;
281
+ }
282
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../source/schema/schema.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AACvC,8CAAkD;AAElD,gDAA8C;AAC9C,gDAAiD;AACjD,wCAAoC;AACpC,mDAAmD;AACnD,sCAA6C;AAC7C,sDAAqG;AACrG,gEAA4D;AAC5D,0DAAsD;AACtD,8DAA0D;AAC1D,8DAA0D;AAC1D,8DAA0D;AAC1D,wEAAmE;AAEnE,iDAA6C;AAE7C,mCAAiI;AACjI,mCAA8I;AAMjI,QAAA,uBAAuB,GAAG,IAAA,wBAAa,EAAC,8BAA8B,CAAC,CAAC;AAErF,MAAM,eAAe,GAAG,IAAI,GAAG,EAAmC,CAAC;AAEnE,IAAI,UAAU,GAAG,GAAS,EAAE;IAC1B,cAAM,CAAC,sBAAsB,CAAC,8BAAa,CAAC,CAAC;IAC7C,cAAM,CAAC,sBAAsB,CAAC,8BAAa,CAAC,CAAC;IAC7C,cAAM,CAAC,sBAAsB,CAAC,gCAAc,CAAC,CAAC;IAC9C,cAAM,CAAC,sBAAsB,CAAC,0BAAW,CAAC,CAAC;IAC3C,cAAM,CAAC,sBAAsB,CAAC,8BAAa,CAAC,CAAC;IAC7C,cAAM,CAAC,sBAAsB,CAAC,uCAAiB,CAAC,CAAC;IAEjD,UAAU,GAAG,WAAI,CAAC;AACpB,CAAC,CAAC;AAEF,iGAAiG;AACpF,QAAA,MAAM,GAAG;IACpB,sBAAsB,CAAC,OAA2B;QAChD,KAAK,MAAM,UAAU,IA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A,qBAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACrF,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,IAAI,iBAAiB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACxF;QAED,UAAU,CAAC,GAAG,CAAC,GAAG;YAChB,MAAM,EAAE,IAAA,oCAA4B,EAAC,QAAQ,IAAI,gBAAgB,CAAC,IAAI,CAAC;YACvE,KAAK;YACL,QAAQ,EAAE,cAAc,EAAE,QAAQ;YAClC,QAAQ,EAAE,cAAc,EAAE,QAAQ;YAClC,MAAM,EAAE,cAAc,EAAE,MAAM;YAC9B,QAAQ,EAAE,cAAc,EAAE,QAAQ;YAClC,YAAY,EAAE,cAAc,EAAE,YAAY;YAC1C,gBAAgB,EAAE,cAAc,EAAE,gBAAgB;YAClD,gBAAgB,EAAE,cAAc,EAAE,gBAAgB;SACnD,CAAC;KACH;IAED,MAAM,YAAY,GAAiB;QACjC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,IAAA,uBAAS,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAS,CAAC,OAAmC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAY,EAAE;QAC3H,UAAU;QACV,IAAI,EAAE,QAAQ,EAAE,IAAI;QACpB,sBAAsB,EAAE,QAAQ,EAAE,sBAAsB;KACzD,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -1,8 +1,4 @@
1
- import type { ValidationTestResult } from '../schema.validator';
2
- import { SchemaValidator, test } from '../schema.validator';
3
- import type { SchemaDefinition, SchemaOptions } from '../types';
4
- export declare type AnySchemaDefinition = SchemaDefinition<'any', any, any>;
5
- export declare class AnySchemaValidator extends SchemaValidator<AnySchemaDefinition> {
6
- [test](value: any): ValidationTestResult<any>;
7
- }
8
- export declare function any(options?: SchemaOptions<AnySchemaDefinition>): AnySchemaValidator;
1
+ import type { Decorator } from "../../reflection";
2
+ import type { TypeSchema } from '../types';
3
+ export declare function any(): TypeSchema<any>;
4
+ export declare function Any(): Decorator<'property' | 'accessor'>;
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.any = exports.AnySchemaValidator = void 0;
4
- const schema_validator_1 = require("../schema.validator");
4
+ exports.Any = exports.any = void 0;
5
+ const decorators_1 = require("../decorators");
5
6
  const types_1 = require("../types");
6
- class AnySchemaValidator extends schema_validator_1.SchemaValidator {
7
- [schema_validator_1.test](value) {
8
- return { valid: true, value };
9
- }
10
- }
11
- exports.AnySchemaValidator = AnySchemaValidator;
12
- function any(options) {
13
- const schema = (0, types_1.schemaHelper)({
14
- type: 'any',
15
- ...options
16
- });
17
- return new AnySchemaValidator(schema);
7
+ function any() {
8
+ return (0, types_1.typeSchema)('any');
18
9
  }
19
10
  exports.any = any;
11
+ function Any() {
12
+ return (0, decorators_1.createSchemaPropertyDecoratorFromSchema)(any());
13
+ }
14
+ exports.Any = Any;
20
15
  //# sourceMappingURL=any.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"any.js","sourceRoot":"","sources":["../../../source/schema/schemas/any.ts"],"names":[],"mappings":";;;AACA,0DAA4D;AAE5D,oCAAwC;AAIxC,MAAa,kBAAmB,SAAQ,kCAAoC;IAC1E,CAAC,uBAAI,CAAC,CAAC,KAAU;QACf,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACF;AAJD,gDAIC;AAED,SAAgB,GAAG,CAAC,OAA4C;IAC9D,MAAM,MAAM,GAAG,IAAA,oBAAY,EAAsB;QAC/C,IAAI,EAAE,KAAK;QACX,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAPD,kBAOC"}
1
+ {"version":3,"file":"any.js","sourceRoot":"","sources":["../../../source/schema/schemas/any.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAwE;AAExE,oCAAsC;AAEtC,SAAgB,GAAG;IACjB,OAAO,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAFD,kBAEC;AAED,SAAgB,GAAG;IACjB,OAAO,IAAA,oDAAuC,EAAC,GAAG,EAAE,CAAC,CAAC;AACxD,CAAC;AAFD,kBAEC"}
@@ -1,14 +1,10 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
3
- import { SchemaValidator, test, testAsync } from '../schema.validator';
4
- import type { SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
5
- export declare type ArraySchemaDefinition<T extends SchemaDefinition = SchemaDefinition> = SchemaDefinition<'array', unknown, SchemaOutput<T>[]> & {
6
- schema: T;
1
+ import type { OneOrMany } from "../../types";
2
+ import type { Schema } from '../schema';
3
+ import type { Coercible, ValueSchema, ValueType } from '../types';
4
+ export declare type ArrayOptions = Coercible & {
5
+ /** minimum length */
6
+ minimumLength?: number;
7
+ /** maximum length */
8
+ maximumLength?: number;
7
9
  };
8
- export declare class ArraySchemaValidator<T extends SchemaDefinition> extends SchemaValidator<ArraySchemaDefinition<T>> {
9
- private readonly innerValidator;
10
- constructor(innerValidator: SchemaValidator<T>, schema: ArraySchemaDefinition<T>);
11
- [test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<ArraySchemaDefinition<T>>>;
12
- [testAsync](value: unknown, options: DefinedValidationOptions, path: JsonPath): Promise<ValidationTestResult<SchemaOutput<ArraySchemaDefinition<T>>>>;
13
- }
14
- export declare function array<T extends SchemaDefinition>(innerValidator: SchemaValidator<T>, options?: SchemaOptions<ArraySchemaDefinition<T>, 'schema'>): ArraySchemaValidator<T>;
10
+ export declare function array<T, O = T>(innerValues: OneOrMany<Schema<T, O> | ValueType>, options?: ArrayOptions): ValueSchema<T, O[]>;
@@ -1,53 +1,23 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.array = exports.ArraySchemaValidator = void 0;
4
+ exports.array = void 0;
4
5
  const type_guards_1 = require("../../utils/type-guards");
5
- const type_of_1 = require("../../utils/type-of");
6
- const schema_error_1 = require("../schema.error");
7
- const schema_validator_1 = require("../schema.validator");
6
+ const array_constraints_1 = require("../array-constraints");
8
7
  const types_1 = require("../types");
9
- class ArraySchemaValidator extends schema_validator_1.SchemaValidator {
10
- constructor(innerValidator, schema) {
11
- super(schema);
12
- this.innerValidator = innerValidator;
8
+ function array(innerValues, options = {}) {
9
+ const arrayConstraints = [];
10
+ if ((0, type_guards_1.isDefined)(options.minimumLength)) {
11
+ arrayConstraints.push(new array_constraints_1.ArrayMaximumLengthConstraint(options.minimumLength));
13
12
  }
14
- [schema_validator_1.test](value, options, path) {
15
- if (!(0, type_guards_1.isArray)(value)) {
16
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot('array', (0, type_of_1.typeOf)(value), path) };
17
- }
18
- const validatedArray = [];
19
- for (let i = 0; i < value.length; i++) {
20
- const innerTestResult = this.innerValidator[schema_validator_1.test](value[i], options, path.add(i));
21
- if (!innerTestResult.valid) {
22
- return innerTestResult;
23
- }
24
- validatedArray.push(innerTestResult.value);
25
- }
26
- return { valid: true, value: validatedArray };
13
+ if ((0, type_guards_1.isDefined)(options.maximumLength)) {
14
+ arrayConstraints.push(new array_constraints_1.ArrayMaximumLengthConstraint(options.maximumLength));
27
15
  }
28
- async [schema_validator_1.testAsync](value, options, path) {
29
- if (!(0, type_guards_1.isArray)(value)) {
30
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot('array', (0, type_of_1.typeOf)(value), path) };
31
- }
32
- const validatedArray = [];
33
- for (let i = 0; i < value.length; i++) {
34
- const innerTestResult = await this.innerValidator[schema_validator_1.testAsync](value[i], options, path.add(i));
35
- if (!innerTestResult.valid) {
36
- return innerTestResult;
37
- }
38
- validatedArray.push(innerTestResult.value);
39
- }
40
- return { valid: true, value: validatedArray };
41
- }
42
- }
43
- exports.ArraySchemaValidator = ArraySchemaValidator;
44
- function array(innerValidator, options) {
45
- const schema = (0, types_1.schemaHelper)({
46
- type: 'array',
47
- schema: innerValidator.schema,
48
- ...options
16
+ return (0, types_1.valueSchema)((0, types_1.valueTypesOrSchemasToSchemas)(innerValues), {
17
+ array: true,
18
+ coerce: options.coerce,
19
+ arrayConstraints
49
20
  });
50
- return new ArraySchemaValidator(innerValidator, schema);
51
21
  }
52
22
  exports.array = array;
53
23
  //# sourceMappingURL=array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../source/schema/schemas/array.ts"],"names":[],"mappings":";;;AACA,yDAA8C;AAC9C,iDAAyC;AACzC,kDAA8C;AAE9C,0DAAuE;AAEvE,oCAAwC;AAMxC,MAAa,oBAAiD,SAAQ,kCAAyC;IAG7G,YAAY,cAAkC,EAAE,MAAgC;QAC9E,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,CAAC,uBAAI,CAAC,CAAC,KAAc,EAAE,OAAiC,EAAE,IAAc;QACtE,IAAI,CAAC,IAAA,qBAAO,EAAC,KAAK,CAAC,EAAE;YACnB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0BAAW,CAAC,cAAc,CAAC,OAAO,EAAE,IAAA,gBAAM,EAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;SAC1F;QAED,MAAM,cAAc,GAAsB,EAAE,CAAC;QAE7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,MAAM,eAAe,GAAG,IAAI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;IAC/I,MAAM,MAAM,GAAG,IAAA,oBAAY,EAA2B;QACpD,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,cAAc,CAAC,MAAM;QAC7B,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,IAAI,oBAAoB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC;AARD,sBAQC"}
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../source/schema/schemas/array.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,yDAAgD;AAChD,4DAAoE;AAGpE,oCAAqE;AAUrE,SAAgB,KAAK,CAAW,WAAgD,EAAE,UAAwB,EAAE;IAC1G,MAAM,gBAAgB,GAA4B,EAAE,CAAC;IAErD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,gBAAgB,CAAC,IAAI,CAAC,IAAI,gDAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KAChF;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,gBAAgB,CAAC,IAAI,CAAC,IAAI,gDAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KAChF;IAED,OAAO,IAAA,mBAAW,EAAM,IAAA,oCAA4B,EAAC,WAAW,CAAC,EAAE;QACjE,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAhBD,sBAgBC"}
@@ -0,0 +1,8 @@
1
+ import type { Record } from "../../types";
2
+ import type { Merge } from 'type-fest';
3
+ import type { ObjectSchema } from '../types';
4
+ export declare function assign<T1 extends Record, O1 extends Record, T2 extends Record, O2 extends Record>(schema1: ObjectSchema<T1, O1>, schema2: ObjectSchema<T2, O2>): ObjectSchema<Merge<T1, T2>, Merge<O1, O2>>;
5
+ export declare function assign<T1 extends Record, O1 extends Record, T2 extends Record, O2 extends Record, T3 extends Record, O3 extends Record>(schema1: ObjectSchema<T1, O1>, schema2: ObjectSchema<T2, O2>, schema3: ObjectSchema<T3, O3>): ObjectSchema<Merge<Merge<T1, T2>, T3>, Merge<Merge<O1, O2>, O3>>;
6
+ export declare function assign<T1 extends Record, O1 extends Record, T2 extends Record, O2 extends Record, T3 extends Record, O3 extends Record, T4 extends Record, O4 extends Record>(schema1: ObjectSchema<T1, O1>, schema2: ObjectSchema<T2, O2>, schema3: ObjectSchema<T3, O3>, schema4: ObjectSchema<T4, O4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>, Merge<Merge<Merge<O1, O2>, O3>, O4>>;
7
+ export declare function assign<T1 extends Record, O1 extends Record, T2 extends Record, O2 extends Record, T3 extends Record, O3 extends Record, T4 extends Record, O4 extends Record, T6 extends Record, O6 extends Record>(schema1: ObjectSchema<T1, O1>, schema2: ObjectSchema<T2, O2>, schema3: ObjectSchema<T3, O3>, schema4: ObjectSchema<T4, O4>, schema5: ObjectSchema<T6, O6>): ObjectSchema<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T6>, Merge<Merge<Merge<Merge<O1, O2>, O3>, O4>, O6>>;
8
+ export declare function assign<T1 extends Record, O1 extends Record, T2 extends Record, O2 extends Record, T3 extends Record, O3 extends Record, T4 extends Record, O4 extends Record, T6 extends Record, O6 extends Record, T7 extends Record, O7 extends Record>(schema1: ObjectSchema<T1, O1>, schema2: ObjectSchema<T2, O2>, schema3: ObjectSchema<T3, O3>, schema4: ObjectSchema<T4, O4>, schema5: ObjectSchema<T6, O6>, schema6: ObjectSchema<T7, O7>): ObjectSchema<Merge<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T6>, T7>, Merge<Merge<Merge<Merge<Merge<O1, O2>, O3>, O4>, O6>, O7>>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assign = void 0;
4
+ const array_1 = require("../../utils/array/array");
5
+ const type_guards_1 = require("../../utils/type-guards");
6
+ function assign(...schemas) {
7
+ (0, type_guards_1.assert)(schemas.length >= 2, 'Assign requires at least 2 schemas.');
8
+ let result = schemas[0];
9
+ for (let i = 1; i < schemas.length; i++) {
10
+ result = {
11
+ ...result,
12
+ ...schemas[i],
13
+ properties: {
14
+ ...result.properties,
15
+ ...schemas[i].properties
16
+ },
17
+ allowUnknownProperties: [...(0, array_1.toArray)(result.allowUnknownProperties ?? []), ...(0, array_1.toArray)(schemas[i].allowUnknownProperties ?? [])]
18
+ };
19
+ }
20
+ if (result.allowUnknownProperties.length == 0) {
21
+ const { allowUnknownProperties: _, ...rest } = result;
22
+ result = rest;
23
+ }
24
+ return result;
25
+ }
26
+ exports.assign = assign;
27
+ //# sourceMappingURL=assign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assign.js","sourceRoot":"","sources":["../../../source/schema/schemas/assign.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAC9C,yDAA6C;AAU7C,SAAgB,MAAM,CAAC,GAAG,OAAuB;IAC/C,IAAA,oBAAM,EAAC,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;IAEnE,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;IAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,GAAG;YACP,GAAG,MAAM;YACT,GAAG,OAAO,CAAC,CAAC,CAAE;YACd,UAAU,EAAE;gBACV,GAAG,MAAM,CAAC,UAAU;gBACpB,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,UAAU;aAC1B;YACD,sBAAsB,EAAE,CAAC,GAAG,IAAA,eAAO,EAAC,MAAM,CAAC,sBAAsB,IAAI,EAAE,CAAC,EAAE,GAAG,IAAA,eAAO,EAAC,OAAO,CAAC,CAAC,CAAE,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;SAChI,CAAC;KACH;IAED,IAAK,MAAM,CAAC,sBAAgC,CAAC,MAAM,IAAI,CAAC,EAAE;QACxD,MAAM,EAAE,sBAAsB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QACtD,MAAM,GAAG,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAvBD,wBAuBC"}