@tstdl/base 0.78.0-beta4 → 0.78.0-beta40

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 (386) hide show
  1. package/api/client/client.d.ts +2 -1
  2. package/api/client/client.js +6 -13
  3. package/api/client/client.js.map +1 -1
  4. package/api/response.js.map +1 -1
  5. package/api/server/gateway.js +7 -5
  6. package/api/server/gateway.js.map +1 -1
  7. package/api/types.d.ts +22 -9
  8. package/api/types.js +1 -2
  9. package/api/types.js.map +1 -1
  10. package/api/utils.d.ts +9 -0
  11. package/api/utils.js +15 -0
  12. package/api/utils.js.map +1 -0
  13. package/application/application.js.map +1 -1
  14. package/container/container.js.map +1 -1
  15. package/container/decorators.d.ts +1 -1
  16. package/container/decorators.js.map +1 -1
  17. package/css/theme/theme.service.js.map +1 -1
  18. package/data-structures/iterable-weak-map.js +1 -1
  19. package/data-structures/iterable-weak-map.js.map +1 -1
  20. package/data-structures/linked-list.js.map +1 -1
  21. package/data-structures/sorted-array-list.js.map +1 -1
  22. package/database/mongo/classes.js.map +1 -1
  23. package/database/mongo/mongo-entity-repository.js +2 -2
  24. package/database/mongo/mongo-entity-repository.js.map +1 -1
  25. package/distributed-loop/distributed-loop.js.map +1 -1
  26. package/distributed-loop/provider.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 +1 -1
  35. package/error/custom.error.js +8 -6
  36. package/error/custom.error.js.map +1 -1
  37. package/examples/api/basic-overview.js +0 -1
  38. package/examples/api/basic-overview.js.map +1 -1
  39. package/examples/mail/basic.js +12 -7
  40. package/examples/mail/basic.js.map +1 -1
  41. package/examples/mail/templates/hello-name.d.ts +2 -0
  42. package/examples/mail/templates/hello-name.js +11 -0
  43. package/examples/mail/templates/hello-name.js.map +1 -0
  44. package/examples/pdf/basic.js +6 -3
  45. package/examples/pdf/basic.js.map +1 -1
  46. package/examples/pdf/templates/hello-name.d.ts +1 -4
  47. package/examples/pdf/templates/hello-name.js +16 -4
  48. package/examples/pdf/templates/hello-name.js.map +1 -1
  49. package/examples/reflection/basic.js +1 -1
  50. package/examples/reflection/basic.js.map +1 -1
  51. package/http/client/adapters/got-http-client.adapter.js.map +1 -1
  52. package/http/client/adapters/undici-http-client.adapter.js.map +1 -1
  53. package/http/client/adapters/utils.js +20 -8
  54. package/http/client/adapters/utils.js.map +1 -1
  55. package/http/client/http-client-request.d.ts +13 -3
  56. package/http/client/http-client-request.js +4 -0
  57. package/http/client/http-client-request.js.map +1 -1
  58. package/http/client/http-client.js +29 -12
  59. package/http/client/http-client.js.map +1 -1
  60. package/http/http-headers.d.ts +2 -0
  61. package/http/http-headers.js +6 -0
  62. package/http/http-headers.js.map +1 -1
  63. package/http/server/node/node-http-server.js.map +1 -1
  64. package/image-service/image-service.js.map +1 -1
  65. package/image-service/imgproxy/imgproxy-image-service.js.map +1 -1
  66. package/key-value-store/mongo/mongo-key-value-store.provider.js.map +1 -1
  67. package/key-value-store/mongo/mongo-key-value.repository.js.map +1 -1
  68. package/key-value-store/mongo/mongo-key-value.store.js.map +1 -1
  69. package/lock/mongo/lock.js.map +1 -1
  70. package/lock/mongo/mongo-lock-repository.js.map +1 -1
  71. package/lock/mongo/provider.js.map +1 -1
  72. package/logger/console/logger.js.map +1 -1
  73. package/mail/clients/nodemailer.mail-client.js.map +1 -1
  74. package/mail/index.d.ts +0 -3
  75. package/mail/index.js +0 -3
  76. package/mail/index.js.map +1 -1
  77. package/mail/mail.service.d.ts +3 -5
  78. package/mail/mail.service.js +8 -14
  79. package/mail/mail.service.js.map +1 -1
  80. package/mail/models/mail-template.model.d.ts +11 -10
  81. package/mail/models/mail-template.model.js +7 -0
  82. package/mail/models/mail-template.model.js.map +1 -1
  83. package/mail/module.d.ts +1 -5
  84. package/mail/module.js +2 -11
  85. package/mail/module.js.map +1 -1
  86. package/mail/repositories/mongo-mail-log.repository.js.map +1 -1
  87. package/mail/tokens.d.ts +0 -3
  88. package/mail/tokens.js +1 -2
  89. package/mail/tokens.js.map +1 -1
  90. package/message-bus/local/local-message-bus-provider.js.map +1 -1
  91. package/message-bus/local/local-message-bus.js.map +1 -1
  92. package/migration/migrator.js.map +1 -1
  93. package/migration/mongo/migration-state-repository.js.map +1 -1
  94. package/module/modules/web-server.module.js.map +1 -1
  95. package/object-storage/s3/s3.object-storage-provider.js.map +1 -1
  96. package/object-storage/s3/s3.object-storage.js.map +1 -1
  97. package/openid-connect/cached-oidc-configuration.service.js.map +1 -1
  98. package/openid-connect/mongo-oidc-state.repository.js.map +1 -1
  99. package/openid-connect/oidc-configuration.service.d.ts +2 -1
  100. package/openid-connect/oidc-configuration.service.js +5 -3
  101. package/openid-connect/oidc-configuration.service.js.map +1 -1
  102. package/openid-connect/oidc.service-model.d.ts +11 -3
  103. package/openid-connect/oidc.service.d.ts +4 -3
  104. package/openid-connect/oidc.service.js +66 -21
  105. package/openid-connect/oidc.service.js.map +1 -1
  106. package/package.json +7 -8
  107. package/pdf/pdf.service.d.ts +48 -10
  108. package/pdf/pdf.service.js +114 -4
  109. package/pdf/pdf.service.js.map +1 -1
  110. package/promise/deferred-promise.d.ts +2 -15
  111. package/promise/deferred-promise.js +5 -10
  112. package/promise/deferred-promise.js.map +1 -1
  113. package/promise/index.d.ts +1 -0
  114. package/promise/index.js +1 -0
  115. package/promise/index.js.map +1 -1
  116. package/promise/lazy-promise.d.ts +11 -0
  117. package/promise/lazy-promise.js +31 -0
  118. package/promise/lazy-promise.js.map +1 -0
  119. package/queue/mongo/mongo-job.repository.js.map +1 -1
  120. package/queue/mongo/queue.js.map +1 -1
  121. package/queue/mongo/queue.provider.js.map +1 -1
  122. package/reflection/decorator-data.js +1 -1
  123. package/reflection/decorator-data.js.map +1 -1
  124. package/reflection/decorators.d.ts +2 -2
  125. package/reflection/decorators.js +7 -7
  126. package/reflection/decorators.js.map +1 -1
  127. package/reflection/registry.d.ts +8 -8
  128. package/reflection/registry.js +1 -1
  129. package/reflection/registry.js.map +1 -1
  130. package/reflection/types.d.ts +3 -2
  131. package/reflection/utils.d.ts +7 -2
  132. package/reflection/utils.js +38 -12
  133. package/reflection/utils.js.map +1 -1
  134. package/schema/array-constraints/maximum-length.js +2 -2
  135. package/schema/array-constraints/maximum-length.js.map +1 -1
  136. package/schema/array-constraints/minimum-length.js +2 -2
  137. package/schema/array-constraints/minimum-length.js.map +1 -1
  138. package/schema/coercers/default-value.coercer.d.ts +1 -1
  139. package/schema/coercers/default-value.coercer.js +1 -1
  140. package/schema/coercers/default-value.coercer.js.map +1 -1
  141. package/schema/coercers/uint8-array.coercer.js +4 -3
  142. package/schema/coercers/uint8-array.coercer.js.map +1 -1
  143. package/schema/constraints/enumeration.js +2 -2
  144. package/schema/constraints/enumeration.js.map +1 -1
  145. package/schema/constraints/generic.js +2 -2
  146. package/schema/constraints/generic.js.map +1 -1
  147. package/schema/constraints/integer.js +3 -3
  148. package/schema/constraints/integer.js.map +1 -1
  149. package/schema/constraints/literal.js +2 -2
  150. package/schema/constraints/literal.js.map +1 -1
  151. package/schema/constraints/maximum-date.js +3 -3
  152. package/schema/constraints/maximum-date.js.map +1 -1
  153. package/schema/constraints/maximum-length.js +2 -2
  154. package/schema/constraints/maximum-length.js.map +1 -1
  155. package/schema/constraints/maximum.js +3 -3
  156. package/schema/constraints/maximum.js.map +1 -1
  157. package/schema/constraints/minimum-date.js +3 -3
  158. package/schema/constraints/minimum-date.js.map +1 -1
  159. package/schema/constraints/minimum-length.js +2 -2
  160. package/schema/constraints/minimum-length.js.map +1 -1
  161. package/schema/constraints/minimum.js +3 -3
  162. package/schema/constraints/minimum.js.map +1 -1
  163. package/schema/constraints/pattern.js +3 -3
  164. package/schema/constraints/pattern.js.map +1 -1
  165. package/schema/decorators/array.d.ts +2 -2
  166. package/schema/decorators/array.js +1 -1
  167. package/schema/decorators/array.js.map +1 -1
  168. package/schema/decorators/defaulted.d.ts +2 -2
  169. package/schema/decorators/defaulted.js +1 -1
  170. package/schema/decorators/defaulted.js.map +1 -1
  171. package/schema/decorators/optional.d.ts +3 -1
  172. package/schema/decorators/optional.js +2 -2
  173. package/schema/decorators/optional.js.map +1 -1
  174. package/schema/decorators/property.d.ts +1 -1
  175. package/schema/decorators/property.js +3 -1
  176. package/schema/decorators/property.js.map +1 -1
  177. package/schema/decorators/types.d.ts +4 -4
  178. package/schema/decorators/utils.d.ts +3 -2
  179. package/schema/decorators/utils.js +4 -8
  180. package/schema/decorators/utils.js.map +1 -1
  181. package/schema/schema.d.ts +8 -10
  182. package/schema/schema.error.d.ts +1 -0
  183. package/schema/schema.error.js +1 -1
  184. package/schema/schema.error.js.map +1 -1
  185. package/schema/schema.js +131 -164
  186. package/schema/schema.js.map +1 -1
  187. package/schema/schemas/any.d.ts +2 -2
  188. package/schema/schemas/any.js +2 -2
  189. package/schema/schemas/any.js.map +1 -1
  190. package/schema/schemas/array.d.ts +2 -1
  191. package/schema/schemas/array.js +1 -1
  192. package/schema/schemas/array.js.map +1 -1
  193. package/schema/schemas/assign.d.ts +5 -5
  194. package/schema/schemas/boolean.js +2 -2
  195. package/schema/schemas/boolean.js.map +1 -1
  196. package/schema/schemas/date.js +2 -2
  197. package/schema/schemas/date.js.map +1 -1
  198. package/schema/schemas/defaulted.d.ts +3 -2
  199. package/schema/schemas/defaulted.js.map +1 -1
  200. package/schema/schemas/enumeration.js +2 -2
  201. package/schema/schemas/enumeration.js.map +1 -1
  202. package/schema/schemas/exclude.d.ts +4 -1
  203. package/schema/schemas/exclude.js +6 -11
  204. package/schema/schemas/exclude.js.map +1 -1
  205. package/schema/schemas/index.d.ts +2 -0
  206. package/schema/schemas/index.js +2 -0
  207. package/schema/schemas/index.js.map +1 -1
  208. package/schema/schemas/instance.d.ts +2 -2
  209. package/schema/schemas/instance.js +1 -1
  210. package/schema/schemas/instance.js.map +1 -1
  211. package/schema/schemas/literal.js +2 -2
  212. package/schema/schemas/literal.js.map +1 -1
  213. package/schema/schemas/nullable.d.ts +3 -2
  214. package/schema/schemas/nullable.js.map +1 -1
  215. package/schema/schemas/number.d.ts +1 -1
  216. package/schema/schemas/number.js +2 -2
  217. package/schema/schemas/number.js.map +1 -1
  218. package/schema/schemas/object.d.ts +2 -3
  219. package/schema/schemas/object.js.map +1 -1
  220. package/schema/schemas/omit.d.ts +4 -0
  221. package/schema/schemas/omit.js +17 -0
  222. package/schema/schemas/omit.js.map +1 -0
  223. package/schema/schemas/readable-stream.d.ts +2 -2
  224. package/schema/schemas/readable-stream.js +2 -2
  225. package/schema/schemas/readable-stream.js.map +1 -1
  226. package/schema/schemas/record.d.ts +3 -2
  227. package/schema/schemas/record.js.map +1 -1
  228. package/schema/schemas/regexp.js +2 -2
  229. package/schema/schemas/regexp.js.map +1 -1
  230. package/schema/schemas/string.js +2 -2
  231. package/schema/schemas/string.js.map +1 -1
  232. package/schema/schemas/transform.d.ts +3 -2
  233. package/schema/schemas/transform.js.map +1 -1
  234. package/schema/schemas/uint8-array.d.ts +2 -3
  235. package/schema/schemas/uint8-array.js +3 -3
  236. package/schema/schemas/uint8-array.js.map +1 -1
  237. package/schema/schemas/union.d.ts +9 -8
  238. package/schema/schemas/union.js +1 -1
  239. package/schema/schemas/union.js.map +1 -1
  240. package/schema/schemas/unknown.d.ts +2 -2
  241. package/schema/schemas/unknown.js +2 -2
  242. package/schema/schemas/unknown.js.map +1 -1
  243. package/schema/transformers/generic.d.ts +4 -4
  244. package/schema/transformers/generic.js.map +1 -1
  245. package/schema/transformers/lowercase.js +1 -1
  246. package/schema/transformers/lowercase.js.map +1 -1
  247. package/schema/transformers/trim.js +1 -1
  248. package/schema/transformers/trim.js.map +1 -1
  249. package/schema/transformers/uppercase.js +1 -1
  250. package/schema/transformers/uppercase.js.map +1 -1
  251. package/schema/types.d.ts +53 -39
  252. package/schema/types.js +49 -34
  253. package/schema/types.js.map +1 -1
  254. package/schema/utils/schema.d.ts +13 -5
  255. package/schema/utils/schema.js +86 -26
  256. package/schema/utils/schema.js.map +1 -1
  257. package/schema/utils/value-type.d.ts +3 -1
  258. package/schema/utils/value-type.js +32 -2
  259. package/schema/utils/value-type.js.map +1 -1
  260. package/search-index/elastic/config.js.map +1 -1
  261. package/search-index/elastic/model/index-mapping.d.ts +2 -1
  262. package/search-index/elastic/model/index-mapping.js.map +1 -1
  263. package/search-index/elastic/search-index.js +1 -1
  264. package/search-index/elastic/search-index.js.map +1 -1
  265. package/serializer/serializable.d.ts +4 -4
  266. package/serializer/serializable.js.map +1 -1
  267. package/templates/index.d.ts +2 -0
  268. package/templates/index.js +2 -0
  269. package/templates/index.js.map +1 -1
  270. package/templates/module.d.ts +3 -1
  271. package/templates/module.js +31 -8
  272. package/templates/module.js.map +1 -1
  273. package/templates/providers/file.provider-template.d.ts +16 -0
  274. package/templates/providers/{file-template.provider.js → file.provider-template.js} +22 -15
  275. package/templates/providers/file.provider-template.js.map +1 -0
  276. package/templates/providers/memory.template-provider.d.ts +8 -0
  277. package/templates/providers/{memory-template.provider.base.js → memory.template-provider.js} +8 -6
  278. package/templates/providers/memory.template-provider.js.map +1 -0
  279. package/templates/renderers/handlebars.template-renderer.d.ts +38 -6
  280. package/templates/renderers/handlebars.template-renderer.js +47 -3
  281. package/templates/renderers/handlebars.template-renderer.js.map +1 -1
  282. package/templates/renderers/mjml.template-renderer.d.ts +6 -6
  283. package/templates/renderers/mjml.template-renderer.js +8 -9
  284. package/templates/renderers/mjml.template-renderer.js.map +1 -1
  285. package/templates/renderers/string.template-renderer.d.ts +8 -0
  286. package/{mail/template-providers/memory-mail-template.provider.js → templates/renderers/string.template-renderer.js} +13 -7
  287. package/templates/renderers/string.template-renderer.js.map +1 -0
  288. package/templates/resolvers/file.template-resolver.d.ts +23 -0
  289. package/templates/resolvers/file.template-resolver.js +63 -0
  290. package/templates/resolvers/file.template-resolver.js.map +1 -0
  291. package/templates/resolvers/string.template-resolver.d.ts +13 -0
  292. package/templates/resolvers/string.template-resolver.js +44 -0
  293. package/templates/resolvers/string.template-resolver.js.map +1 -0
  294. package/templates/template-renderer.provider.js +7 -19
  295. package/templates/template-renderer.provider.js.map +1 -1
  296. package/templates/template-resolver.provider.d.ts +8 -0
  297. package/templates/template-resolver.provider.js +48 -0
  298. package/templates/template-resolver.provider.js.map +1 -0
  299. package/templates/template.model.d.ts +14 -4
  300. package/templates/template.model.js +42 -0
  301. package/templates/template.model.js.map +1 -1
  302. package/templates/template.renderer.d.ts +14 -3
  303. package/templates/template.renderer.js +3 -0
  304. package/templates/template.renderer.js.map +1 -1
  305. package/templates/template.resolver.d.ts +5 -0
  306. package/templates/template.resolver.js +7 -0
  307. package/templates/template.resolver.js.map +1 -0
  308. package/templates/template.service.d.ts +10 -4
  309. package/templates/template.service.js +19 -6
  310. package/templates/template.service.js.map +1 -1
  311. package/templates/tokens.d.ts +3 -2
  312. package/templates/tokens.js +2 -1
  313. package/templates/tokens.js.map +1 -1
  314. package/types.d.ts +6 -4
  315. package/utils/array/array.d.ts +1 -2
  316. package/utils/array/array.js.map +1 -1
  317. package/utils/async-iterable-helpers/includes.d.ts +2 -0
  318. package/utils/async-iterable-helpers/includes.js +13 -0
  319. package/utils/async-iterable-helpers/includes.js.map +1 -0
  320. package/utils/async-iterable-helpers/index.d.ts +1 -0
  321. package/utils/async-iterable-helpers/index.js +1 -0
  322. package/utils/async-iterable-helpers/index.js.map +1 -1
  323. package/utils/clone.js +4 -0
  324. package/utils/clone.js.map +1 -1
  325. package/utils/compression.d.ts +13 -13
  326. package/utils/compression.js +10 -9
  327. package/utils/compression.js.map +1 -1
  328. package/utils/encoding.js +1 -1
  329. package/utils/encoding.js.map +1 -1
  330. package/utils/enum.js +3 -3
  331. package/utils/enum.js.map +1 -1
  332. package/utils/function/memoize.d.ts +1 -0
  333. package/utils/function/memoize.js +7 -4
  334. package/utils/function/memoize.js.map +1 -1
  335. package/utils/helpers.d.ts +0 -2
  336. package/utils/helpers.js +1 -12
  337. package/utils/helpers.js.map +1 -1
  338. package/utils/index.d.ts +1 -0
  339. package/utils/index.js +1 -0
  340. package/utils/index.js.map +1 -1
  341. package/utils/iterable-helpers/includes.d.ts +1 -0
  342. package/utils/iterable-helpers/includes.js +9 -0
  343. package/utils/iterable-helpers/includes.js.map +1 -0
  344. package/utils/iterable-helpers/index.d.ts +1 -0
  345. package/utils/iterable-helpers/index.js +1 -0
  346. package/utils/iterable-helpers/index.js.map +1 -1
  347. package/utils/object/property-name.d.ts +2 -2
  348. package/utils/throw.d.ts +2 -0
  349. package/utils/throw.js +15 -0
  350. package/utils/throw.js.map +1 -0
  351. package/utils/type-guards.d.ts +13 -1
  352. package/utils/type-guards.js +29 -5
  353. package/utils/type-guards.js.map +1 -1
  354. package/web-types.d.ts +28 -0
  355. package/web-types.js +3 -0
  356. package/web-types.js.map +1 -0
  357. package/mail/mail-template-renderer.provider.d.ts +0 -8
  358. package/mail/mail-template-renderer.provider.js +0 -60
  359. package/mail/mail-template-renderer.provider.js.map +0 -1
  360. package/mail/mail-template.provider.d.ts +0 -4
  361. package/mail/mail-template.provider.js +0 -7
  362. package/mail/mail-template.provider.js.map +0 -1
  363. package/mail/mail-template.renderer.d.ts +0 -10
  364. package/mail/mail-template.renderer.js +0 -7
  365. package/mail/mail-template.renderer.js.map +0 -1
  366. package/mail/template-providers/file-mail-template.provider.d.ts +0 -24
  367. package/mail/template-providers/file-mail-template.provider.js +0 -51
  368. package/mail/template-providers/file-mail-template.provider.js.map +0 -1
  369. package/mail/template-providers/memory-mail-template.provider.d.ts +0 -6
  370. package/mail/template-providers/memory-mail-template.provider.js.map +0 -1
  371. package/mail/template-renderers/handlebars.mail-template-renderer.d.ts +0 -13
  372. package/mail/template-renderers/handlebars.mail-template-renderer.js +0 -49
  373. package/mail/template-renderers/handlebars.mail-template-renderer.js.map +0 -1
  374. package/mail/template-renderers/mjml.mail-template-renderer.d.ts +0 -14
  375. package/mail/template-renderers/mjml.mail-template-renderer.js +0 -63
  376. package/mail/template-renderers/mjml.mail-template-renderer.js.map +0 -1
  377. package/templates/providers/file-template.provider.base.d.ts +0 -12
  378. package/templates/providers/file-template.provider.base.js +0 -50
  379. package/templates/providers/file-template.provider.base.js.map +0 -1
  380. package/templates/providers/file-template.provider.d.ts +0 -22
  381. package/templates/providers/file-template.provider.js.map +0 -1
  382. package/templates/providers/memory-template.provider.base.d.ts +0 -9
  383. package/templates/providers/memory-template.provider.base.js.map +0 -1
  384. package/templates/providers/memory-template.provider.d.ts +0 -4
  385. package/templates/providers/memory-template.provider.js +0 -18
  386. package/templates/providers/memory-template.provider.js.map +0 -1
@@ -1,2 +1,4 @@
1
1
  import type { Decorator } from "../../reflection";
2
- export declare function Optional(): Decorator<'property' | 'accessor'>;
2
+ import type { OneOrMany } from "../../types";
3
+ import type { SchemaTestable } from '../schema';
4
+ export declare function Optional(schema?: OneOrMany<SchemaTestable>): Decorator<'property' | 'accessor'>;
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Optional = void 0;
5
5
  const utils_1 = require("./utils");
6
- function Optional() {
7
- return (0, utils_1.createSchemaPropertyDecorator)({ optional: true });
6
+ function Optional(schema) {
7
+ return (0, utils_1.createSchemaPropertyDecorator)({ schema, optional: true });
8
8
  }
9
9
  exports.Optional = Optional;
10
10
  //# sourceMappingURL=optional.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/decorators/optional.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAKzD,mCAAwD;AAExD,SAAgB,QAAQ,CAAC,MAAkC;IACzD,OAAO,IAAA,qCAA6B,EAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC;AAFD,4BAEC"}
@@ -3,4 +3,4 @@ import type { OneOrMany, TypedOmit } from "../../types";
3
3
  import type { ValueType } from '../types';
4
4
  import type { PropertyOptions } from './types';
5
5
  export declare function Property(options?: PropertyOptions): Decorator<'property' | 'accessor'>;
6
- export declare function Property(types?: () => OneOrMany<ValueType>, options?: TypedOmit<PropertyOptions, 'type'>): Decorator<'property' | 'accessor'>;
6
+ export declare function Property(schema?: OneOrMany<ValueType>, options?: TypedOmit<PropertyOptions, 'schema'>): Decorator<'property' | 'accessor'>;
@@ -7,8 +7,10 @@ const type_guards_1 = require("../../utils/type-guards");
7
7
  const types_1 = require("../types");
8
8
  const utils_1 = require("./utils");
9
9
  function Property(optionsOrTypes = {}, optionsOrNothing) {
10
- const options = (0, type_guards_1.isFunction)(optionsOrTypes) ? { type: { deferred: () => (0, types_1.valueTypesToSchema)(optionsOrTypes()) }, ...optionsOrNothing } : optionsOrTypes;
10
+ const schema = ((0, type_guards_1.isFunction)(optionsOrTypes) || (0, type_guards_1.isString)(optionsOrTypes)) ? (0, types_1.typeSchema)(optionsOrTypes) : undefined;
11
+ const options = (0, type_guards_1.isUndefined)(schema) ? optionsOrTypes : optionsOrNothing ?? {};
11
12
  return (0, utils_1.createSchemaPropertyDecorator)({
13
+ schema,
12
14
  ...options,
13
15
  coercers: (0, type_guards_1.isDefined)(options.coercers) ? (0, array_1.toArray)(options.coercers) : undefined,
14
16
  transformers: (0, type_guards_1.isDefined)(options.transformers) ? (0, array_1.toArray)(options.transformers) : undefined,
@@ -1 +1 @@
1
- {"version":3,"file":"property.js","sourceRoot":"","sources":["../../../source/schema/decorators/property.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,mDAA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AE,gBAAkC;IACtH,MAAM,MAAM,GAAG,CAAC,IAAA,wBAAU,EAAC,cAAc,CAAC,IAAI,IAAA,sBAAQ,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAU,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjH,MAAM,OAAO,GAAG,IAAA,yBAAW,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,cAAkC,CAAC,CAAC,CAAC,gBAAgB,IAAK,EAAsB,CAAC;IAExH,OAAO,IAAA,qCAA6B,EAAC;QACnC,MAAM;QACN,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;AAZD,4BAYC"}
@@ -1,11 +1,11 @@
1
1
  import type { OneOrMany } from "../../types";
2
- import type { ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueSchema, ValueType } from '../types';
2
+ import type { SchemaTestable } from '../schema';
3
+ import type { ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueSchema } from '../types';
3
4
  export declare type SchemaTypeReflectionData = Partial<Pick<ObjectSchema, 'mask' | 'allowUnknownProperties'>> & {
4
5
  factory?: SchemaFactoryFunction<any>;
5
6
  };
6
- export declare type TypesProvider = () => OneOrMany<ValueType>;
7
7
  export declare type SchemaPropertyReflectionData = {
8
- type?: OneOrMany<ValueType>;
8
+ schema?: OneOrMany<SchemaTestable>;
9
9
  array?: boolean;
10
10
  optional?: boolean;
11
11
  nullable?: boolean;
@@ -15,4 +15,4 @@ export declare type SchemaPropertyReflectionData = {
15
15
  arrayConstraints?: readonly SchemaArrayConstraint[];
16
16
  valueConstraints?: readonly SchemaValueConstraint[];
17
17
  };
18
- export declare type PropertyOptions = Partial<ValueSchema>;
18
+ export declare type PropertyOptions = Partial<ValueSchema<any>>;
@@ -1,9 +1,10 @@
1
1
  import type { Decorator } from "../../reflection";
2
2
  import type { OneOrMany } from "../../types";
3
- import type { SchemaArrayConstraint, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueType } from '../types';
3
+ import type { Schema } from '../schema';
4
+ import type { SchemaArrayConstraint, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer } from '../types';
4
5
  import type { PropertyOptions } from './types';
5
6
  export declare function createSchemaPropertyDecorator(options: PropertyOptions): Decorator<'property' | 'accessor'>;
6
- export declare function createSchemaPropertyDecoratorFromValueType(valueType: ValueType): Decorator<'property' | 'accessor'>;
7
+ export declare function createSchemaPropertyDecoratorFromSchema(schema: Schema): Decorator<'property' | 'accessor'>;
7
8
  export declare function createSchemaValueCoercerDecorator(coercer: SchemaValueCoercer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
8
9
  export declare function createSchemaValueTransformerDecorator(transformer: SchemaValueTransformer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
9
10
  export declare function createSchemaArrayConstraintDecorator(constraint: SchemaArrayConstraint, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/naming-convention */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createSchemaValueConstraintDecorator = exports.createSchemaArrayConstraintDecorator = exports.createSchemaValueTransformerDecorator = exports.createSchemaValueCoercerDecorator = exports.createSchemaPropertyDecoratorFromValueType = exports.createSchemaPropertyDecorator = void 0;
4
+ exports.createSchemaValueConstraintDecorator = exports.createSchemaArrayConstraintDecorator = exports.createSchemaValueTransformerDecorator = exports.createSchemaValueCoercerDecorator = exports.createSchemaPropertyDecoratorFromSchema = exports.createSchemaPropertyDecorator = void 0;
5
5
  const reflection_1 = require("../../reflection");
6
6
  const array_1 = require("../../utils/array/array");
7
7
  const merge_1 = require("../../utils/merge");
@@ -24,14 +24,10 @@ function createSchemaPropertyDecorator(options) {
24
24
  });
25
25
  }
26
26
  exports.createSchemaPropertyDecorator = createSchemaPropertyDecorator;
27
- function createSchemaPropertyDecoratorFromValueType(valueType) {
28
- const schema = (0, types_1.isValueSchema)(valueType) ? valueType : (0, types_1.valueSchema)(valueType);
29
- return createSchemaPropertyDecorator({
30
- ...schema,
31
- type: schema.type
32
- });
27
+ function createSchemaPropertyDecoratorFromSchema(schema) {
28
+ return createSchemaPropertyDecorator((0, types_1.isValueSchema)(schema) ? schema : (0, types_1.valueSchema)(schema));
33
29
  }
34
- exports.createSchemaPropertyDecoratorFromValueType = createSchemaPropertyDecoratorFromValueType;
30
+ exports.createSchemaPropertyDecoratorFromSchema = createSchemaPropertyDecoratorFromSchema;
35
31
  function createSchemaValueCoercerDecorator(coercer, options) {
36
32
  return createSchemaPropertyDecorator({ ...options, coercers: coercer });
37
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../source/schema/decorators/utils.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,iDAAiE;AAEjE,mDAA8C;AAC9C,6CA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{ ObjectSchema, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, TypeSchema, ValueSchema } from './types';
3
- export declare type Schema<T = any, O = T> = ObjectSchema<T, O> | ValueSchema<T, O>;
4
- export declare const getSchemaFromReflection: typeof _getObjectSchemaFromReflection;
5
- export declare type SchemaTestable<T = any, O = T> = Schema<T, O> | TypeSchema<T, O>;
2
+ import type { NormalizedObjectSchema, NormalizedTypeSchema, NormalizedValueSchema, ObjectSchema, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, TypeSchema, ValueSchema, ValueType } from './types';
3
+ export declare type Schema<T = any, O = T> = ObjectSchema<T, O> | ValueSchema<T, O> | TypeSchema<O>;
4
+ export declare type SchemaTestable<T = any, O = T> = Schema<T, O> | ValueType<O>;
5
+ export declare type NormalizedSchema<T = any, O = T> = NormalizedObjectSchema<T, O> | NormalizedValueSchema<T, O> | NormalizedTypeSchema<O>;
6
6
  export declare const Schema: {
7
7
  registerDefaultCoercer(coercer: SchemaValueCoercer): void;
8
- test<T, O>(schema: SchemaTestable<T, O>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O>;
9
- validate<T_1, O_1 = T_1>(schema: SchemaTestable<T_1, O_1>, value: unknown, options?: SchemaTestOptions): boolean;
10
- parse<T_2, O_2 = T_2>(schema: SchemaTestable<T_2, O_2>, value: unknown, options?: SchemaTestOptions): O_2;
8
+ test<T, O>(schemaOrValueType: SchemaTestable<T, O>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O>;
9
+ validate<T_1, O_1 = T_1>(schemaOrValueType: SchemaTestable<T_1, O_1>, value: unknown, options?: SchemaTestOptions): boolean;
10
+ parse<T_2, O_2 = T_2>(schemaOrValueType: SchemaTestable<T_2, O_2>, value: unknown, options?: SchemaTestOptions): O_2;
11
11
  /**
12
12
  * disables stack traces for errors
13
13
  * @deprecated for internal use only
14
14
  */
15
- testWithFastError<T_3, O_3 = T_3>(schema: SchemaTestable<T_3, O_3>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O_3>;
15
+ testWithFastError<T_3, O_3 = T_3>(schema: Schema<T_3, O_3>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O_3>;
16
16
  };
17
- declare function _getObjectSchemaFromReflection<T, O>(type: TypeSchema<T, O>): ObjectSchema<T> | null;
18
- export {};
@@ -8,6 +8,7 @@ export declare type SchemaErrorOptions = Pick<CustomErrorOptions, 'fast'> & {
8
8
  path: string | JsonPath;
9
9
  inner?: OneOrMany<SchemaError>;
10
10
  details?: UndefinableJson;
11
+ cause?: any;
11
12
  };
12
13
  export declare class SchemaError extends CustomError implements ErrorExtraInfo {
13
14
  static readonly errorName = "SchemaError";
@@ -7,7 +7,7 @@ const type_guards_1 = require("../utils/type-guards");
7
7
  const utils_1 = require("./utils");
8
8
  class SchemaError extends error_1.CustomError {
9
9
  constructor(message, options, cause) {
10
- super({ message, cause, fast: options.fast ?? true });
10
+ super({ message, cause: cause ?? options.cause, fast: options.fast ?? true });
11
11
  this.path = (0, type_guards_1.isString)(options.path) ? options.path : options.path.path;
12
12
  if ((0, type_guards_1.isDefined)(options.inner)) {
13
13
  const errors = (0, array_1.toArray)(options.inner);
@@ -1 +1 @@
1
- {"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAGtC,gDAA8C;AAE9C,sDAAgF;AAEhF,mCAA2C;AAQ3C,MAAa,WAAY,SAAQ,mBAAW;IAO1C,YAAY,OAAe,EAAE,OAA2B,EAAE,KAAW;QACnE,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAI,GAAG,IAAA,sBAAQ,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC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S,GAAG,aAAa,CAAC"}
package/schema/schema.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Schema = exports.getSchemaFromReflection = void 0;
3
+ exports.Schema = void 0;
4
4
  const json_path_1 = require("../json-path");
5
- const reflection_1 = require("../reflection");
6
5
  const array_1 = require("../utils/array/array");
7
- const function_1 = require("../utils/function");
8
6
  const noop_1 = require("../utils/noop");
9
7
  const object_1 = require("../utils/object/object");
10
8
  const set_1 = require("../utils/set");
@@ -18,7 +16,6 @@ const uint8_array_coercer_1 = require("./coercers/uint8-array.coercer");
18
16
  const schema_error_1 = require("./schema.error");
19
17
  const types_1 = require("./types");
20
18
  const utils_1 = require("./utils");
21
- exports.getSchemaFromReflection = (0, function_1.memoizeSingle)(_getObjectSchemaFromReflection);
22
19
  const defaultCoercers = new Map();
23
20
  let initialize = () => {
24
21
  exports.Schema.registerDefaultCoercer(number_coercer_1.numberCoercer);
@@ -39,20 +36,23 @@ exports.Schema = {
39
36
  defaultCoercers.get(sourceType).push(coercer);
40
37
  }
41
38
  },
42
- test(schema, value, options, path = json_path_1.JsonPath.ROOT) {
39
+ test(schemaOrValueType, value, options, path = json_path_1.JsonPath.ROOT) {
40
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
43
41
  const result = this.testWithFastError(schema, value, options, path);
44
- if (result.success) {
42
+ if (result.valid) {
45
43
  return result;
46
44
  }
47
- return { success: false, error: new schema_error_1.SchemaError(result.error.message, { ...result.error, fast: false }, result.error.cause) };
45
+ return { valid: false, error: new schema_error_1.SchemaError(result.error.message, { ...result.error, fast: false }) };
48
46
  },
49
- validate(schema, value, options) {
47
+ validate(schemaOrValueType, value, options) {
48
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
50
49
  const result = this.test(schema, value, options);
51
- return result.success;
50
+ return result.valid;
52
51
  },
53
- parse(schema, value, options) {
52
+ parse(schemaOrValueType, value, options) {
53
+ const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
54
54
  const result = this.test(schema, value, options);
55
- if (result.success) {
55
+ if (result.valid) {
56
56
  return result.value;
57
57
  }
58
58
  throw result.error;
@@ -66,222 +66,189 @@ exports.Schema = {
66
66
  if ((0, types_1.isValueSchema)(schema)) {
67
67
  return testValue(schema, value, options, path);
68
68
  }
69
- return testObject(schema, value, options, path);
69
+ if ((0, types_1.isTypeSchema)(schema)) {
70
+ return testType(schema, value, options, path);
71
+ }
72
+ if ((0, types_1.isObjectSchema)(schema)) {
73
+ return testObject(schema, value, options, path);
74
+ }
75
+ throw new Error('Unsupported schema');
70
76
  }
71
77
  };
72
- // eslint-disable-next-line complexity
73
- function testObject(schemaOrType, value, options = {}, path = json_path_1.JsonPath.ROOT) {
74
- if ((0, type_guards_1.isFunction)(schemaOrType) && (value instanceof schemaOrType)) {
75
- return { success: true, value: value };
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) || ((0, utils_1.getValueType)(value) == resolvedValueType)) {
85
+ return { valid: true, value: value };
86
+ }
87
+ const objectSchema = (0, utils_1.getSchemaFromReflection)(resolvedValueType);
88
+ if ((0, type_guards_1.isNotNull)(objectSchema)) {
89
+ return testObject(objectSchema, value, options, path);
90
+ }
76
91
  }
77
- if (!(value instanceof Object) && !(0, type_guards_1.isObject)(value)) {
78
- const expected = (0, type_guards_1.isFunction)(schemaOrType) ? schemaOrType : Object;
79
- return { success: false, error: schema_error_1.SchemaError.expectedButGot(expected, (0, utils_1.getValueType)(value), path) };
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 };
80
94
  }
81
- const unnormalizedSchema = (0, type_guards_1.isFunction)(schemaOrType) ? (0, exports.getSchemaFromReflection)(schemaOrType) : schemaOrType;
82
- if ((0, type_guards_1.isNull)(unnormalizedSchema)) {
83
- return { success: false, error: schema_error_1.SchemaError.expectedButGot(schemaOrType, (0, utils_1.getValueType)(value), path) };
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) };
84
101
  }
85
- const schema = (0, utils_1.normalizeSchema)(unnormalizedSchema);
102
+ const schema = (0, utils_1.normalizeObjectSchema)(objectSchema);
86
103
  const mask = schema.mask ?? options.mask ?? false;
87
104
  const resultValue = (0, type_guards_1.isDefined)(schema.factory?.type) ? new schema.factory.type() : {};
88
105
  const schemaPropertyKeys = (0, object_1.objectKeys)(schema.properties);
89
106
  const valuePropertyKeys = (0, object_1.objectKeys)(value);
90
107
  const unknownValuePropertyKeys = (0, set_1.differenceSets)(new Set(valuePropertyKeys), new Set(schemaPropertyKeys));
91
108
  if ((unknownValuePropertyKeys.length > 0) && !(mask || (schema.allowUnknownProperties.size > 0))) {
92
- return { success: false, error: new schema_error_1.SchemaError('Unknown property', { path: path.add(unknownValuePropertyKeys[0]) }) };
109
+ return { valid: false, error: new schema_error_1.SchemaError('Unknown property', { path: path.add(unknownValuePropertyKeys[0]) }) };
93
110
  }
94
111
  for (const key of schemaPropertyKeys) {
95
112
  const propertyResult = exports.Schema.testWithFastError(schema.properties[key], value[key], options, path.add(key));
96
- if (!propertyResult.success) {
113
+ if (!propertyResult.valid) {
97
114
  return propertyResult;
98
115
  }
99
116
  resultValue[key] = propertyResult.value;
100
117
  }
101
118
  if (schema.allowUnknownProperties.size > 0) {
102
119
  for (const key of unknownValuePropertyKeys) {
103
- const errors = [];
104
- for (const allowedSchema of schema.allowUnknownProperties) {
105
- const propertyResult = exports.Schema.testWithFastError(allowedSchema, value[key], options, path.add(key));
106
- if (!propertyResult.success && !mask) {
107
- errors.push(propertyResult.error);
108
- continue;
109
- }
110
- resultValue[key] = propertyResult.value;
111
- break;
112
- }
113
- if (errors.length > 0) {
114
- return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match any allowed schemas.', { inner: errors, path }) };
120
+ const propertyResult = exports.Schema.testWithFastError((0, types_1.valueSchema)([...schema.allowUnknownProperties]), value[key], options, path.add(key));
121
+ if (!propertyResult.valid && !mask) {
122
+ return propertyResult;
115
123
  }
124
+ resultValue[key] = propertyResult.value;
116
125
  }
117
126
  }
118
127
  const testResultValue = (0, type_guards_1.isUndefined)(schema.factory) ? resultValue : (0, type_guards_1.isDefined)(schema.factory.type) ? resultValue : schema.factory.builder(resultValue);
119
- return { success: true, value: testResultValue };
128
+ return { valid: true, value: testResultValue };
120
129
  }
121
130
  // eslint-disable-next-line max-lines-per-function, max-statements, complexity
122
131
  function testValue(schema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
123
- const valueSchema = (0, utils_1.normalizeValueSchema)(schema);
124
- if (valueSchema.optional && (0, type_guards_1.isUndefined)(value)) {
125
- return { success: true, value: value };
132
+ const normalizedValueSchema = (0, utils_1.normalizeValueSchema)(schema);
133
+ if (normalizedValueSchema.optional && (0, type_guards_1.isUndefined)(value)) {
134
+ return { valid: true, value: value };
126
135
  }
127
- if (valueSchema.nullable && (0, type_guards_1.isNull)(value)) {
128
- return { success: true, value: value };
136
+ if (normalizedValueSchema.nullable && (0, type_guards_1.isNull)(value)) {
137
+ return { valid: true, value: value };
129
138
  }
130
139
  const context = {
131
- schema: valueSchema,
140
+ schema: normalizedValueSchema,
132
141
  options
133
142
  };
134
143
  /** handle arrays */
135
- if (valueSchema.array) {
144
+ if (normalizedValueSchema.array) {
136
145
  if (!(0, type_guards_1.isArray)(value)) {
137
146
  throw schema_error_1.SchemaError.expectedButGot(Array, (0, utils_1.getValueType)(value), path);
138
147
  }
139
- for (const arrayConstraint of valueSchema.arrayConstraints) {
148
+ for (const arrayConstraint of normalizedValueSchema.arrayConstraints) {
140
149
  const result = arrayConstraint.validate(value, path, context);
141
- if (!result.success) {
142
- return { success: false, error: result.error };
150
+ if (!result.valid) {
151
+ return { valid: false, error: result.error };
143
152
  }
144
153
  }
145
154
  const itemSchema = (0, utils_1.getArrayItemSchema)(schema);
146
155
  const validatedItems = [];
147
156
  for (let i = 0; i < value.length; i++) {
148
157
  const result = testValue(itemSchema, value[i], options, path.add(i));
149
- if (!result.success) {
158
+ if (!result.valid) {
150
159
  return result;
151
160
  }
152
161
  validatedItems.push(result.value);
153
162
  }
154
- return { success: true, value: validatedItems };
155
- }
156
- let valueType = (0, utils_1.getValueType)(value);
157
- let validType = isValidType(valueSchema, valueType);
158
- let resultValue = value;
159
- /** try to coerce with custom coercers */
160
- if (!validType) {
161
- const coercers = valueSchema.coercers.get(valueType);
162
- if ((0, type_guards_1.isDefined)(coercers)) {
163
- const errors = [];
164
- for (const coercer of coercers) {
165
- const coerceResult = coercer.coerce(resultValue, path, context);
166
- if (!coerceResult.success) {
167
- errors.push(coerceResult.error);
168
- continue;
169
- }
170
- resultValue = coerceResult.value;
171
- valueType = (0, utils_1.getValueType)(resultValue);
172
- validType = isValidType(valueSchema, valueType);
173
- break;
174
- }
175
- if ((errors.length > 0)) {
176
- return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
177
- }
178
- }
179
- }
180
- /** try to coerce with default coercers if enabled */
181
- if (!validType && (valueSchema.coerce || options.coerce == true)) {
182
- const coercers = defaultCoercers.get(valueType);
183
- if ((0, type_guards_1.isDefined)(coercers)) {
184
- const errors = [];
185
- for (const coercer of coercers) {
186
- const coerceResult = coercer.coerce(resultValue, path, context);
187
- if (!coerceResult.success) {
188
- errors.push(coerceResult.error);
189
- continue;
190
- }
191
- resultValue = coerceResult.value;
192
- valueType = (0, utils_1.getValueType)(resultValue);
193
- validType = isValidType(valueSchema, valueType);
194
- break;
195
- }
196
- if ((errors.length > 0)) {
197
- return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
198
- }
199
- }
200
- }
201
- /** check for sub-schemas */
202
- if (!validType) {
163
+ return { valid: true, value: validatedItems };
164
+ }
165
+ let valueType;
166
+ let valueTestResult;
167
+ let resultValue;
168
+ function updateCurrentState(newValue) {
169
+ resultValue = newValue;
170
+ valueType = (0, utils_1.getValueType)(newValue);
171
+ valueTestResult = isValidValue(normalizedValueSchema.schema, newValue, options, path);
172
+ }
173
+ updateCurrentState(value);
174
+ /** try to coerce */
175
+ if (!valueTestResult.valid) {
176
+ const coercers = [
177
+ ...(normalizedValueSchema.coercers.get(valueType) ?? []),
178
+ ...((normalizedValueSchema.coerce || options.coerce == true) ? (defaultCoercers.get(valueType) ?? []) : [])
179
+ ];
203
180
  const errors = [];
204
- for (const type of valueSchema.type) {
205
- if (types_1.primitiveValueTypesSet.has(type)) {
206
- continue;
207
- }
208
- const typeSchema = (0, types_1.valueTypesToSchema)(type);
209
- const result = exports.Schema.testWithFastError(typeSchema, resultValue, options, path);
210
- if (!result.success) {
211
- errors.push(result.error);
181
+ let success = false;
182
+ for (const coercer of coercers) {
183
+ const coerceResult = coercer.coerce(resultValue, path, context);
184
+ if (!coerceResult.success) {
185
+ errors.push(coerceResult.error);
212
186
  continue;
213
187
  }
214
- resultValue = result.value;
215
- validType = true;
188
+ success = true;
189
+ updateCurrentState(coerceResult.value);
216
190
  break;
217
191
  }
218
- if (!validType && (errors.length > 0)) {
219
- return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match any allowed schemas.', { inner: errors, path }) };
192
+ if (!success && (errors.length > 0)) {
193
+ return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
220
194
  }
221
195
  }
222
- if (!validType) {
223
- const expectedNames = [...valueSchema.type].map((exp) => ((0, type_guards_1.isString)(exp) ? exp : (0, utils_1.getValueTypeName)(exp)));
224
- const expectedTypeString = expectedNames.length == 1
225
- ? expectedNames[0]
226
- : `[${expectedNames.join(', ')}]`;
227
- const expects = valueSchema.valueConstraints.map((constraint) => constraint.expects);
228
- const expectsString = expects.length > 0 ? ` (${expects.join(', ')})` : '';
229
- return { success: false, error: schema_error_1.SchemaError.expectedButGot(`${expectedTypeString}${expectsString}`, (0, utils_1.getValueType)(resultValue), path) };
196
+ if (!valueTestResult.valid) {
197
+ const expectsString = getExpectString(schema);
198
+ return { valid: false, error: schema_error_1.SchemaError.expectedButGot(expectsString, valueType, path) };
230
199
  }
231
- if (valueSchema.transformers.length > 0) {
232
- for (const transformer of valueSchema.transformers) {
233
- resultValue = transformer.transform(resultValue, path, context);
200
+ if (normalizedValueSchema.transformers.length > 0) {
201
+ let transformedValue = resultValue;
202
+ for (const transformer of normalizedValueSchema.transformers) {
203
+ const transformResult = transformer.transform(transformedValue, path, context);
204
+ if (!transformResult.success) {
205
+ return { valid: false, error: transformResult.error };
206
+ }
207
+ transformedValue = transformResult.value;
234
208
  }
235
- valueType = (0, utils_1.getValueType)(resultValue);
236
- validType = isValidType(valueSchema, valueType);
237
- if (!validType) {
238
- const typeString = (0, type_guards_1.isFunction)(valueType) ? valueType.name : valueType;
209
+ updateCurrentState(transformedValue);
210
+ if (!valueTestResult.valid) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
211
+ const typeString = (0, utils_1.getValueTypeName)(valueType);
239
212
  throw new Error(`Transformers resulted in invalid type (${typeString}).`);
240
213
  }
241
214
  }
242
- for (const constraint of valueSchema.valueConstraints) {
243
- const result = constraint.validate(resultValue, path, context);
244
- if (!result.success) {
245
- return { success: false, error: result.error };
215
+ {
216
+ const errors = [];
217
+ for (const constraint of normalizedValueSchema.valueConstraints) {
218
+ const result = constraint.validate(resultValue, path, context);
219
+ if (!result.valid) {
220
+ errors.push(result.error);
221
+ }
222
+ }
223
+ if (errors.length > 0) {
224
+ 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
225
  }
247
226
  }
248
- return { success: true, value: resultValue };
227
+ return { valid: true, value: resultValue };
249
228
  }
250
- function isValidType(valueSchema, valueType) {
251
- return valueSchema.type.has(valueType) || valueSchema.type.has('any');
252
- }
253
- function _getObjectSchemaFromReflection(type) {
254
- const metadata = reflection_1.reflectionRegistry.getMetadata(type);
255
- if (!metadata.registered) {
256
- return null;
257
- }
258
- const typeData = metadata.data.tryGet('schema');
259
- const properties = {};
260
- for (const [key, propertyMetadata] of metadata.properties) {
261
- const reflectionData = propertyMetadata.data.tryGet('schema');
262
- const itemType = (0, type_guards_1.isDefined)(reflectionData?.type) ? (0, types_1.deferrableValueTypesToValueTypes)(reflectionData.type) : undefined;
263
- const array = ((propertyMetadata.type == Array) && (itemType != Array)) || (reflectionData?.array == true);
264
- if (array && ((0, type_guards_1.isUndefined)(itemType) || ((0, type_guards_1.isArray)(itemType) && (itemType.length == 0)))) {
265
- throw new Error(`Item type missing on type ${type.name} at property "${String(key)}"`);
229
+ function isValidValue(validSchemas, value, options, path) {
230
+ const errors = [];
231
+ for (const schema of validSchemas) {
232
+ const result = exports.Schema.testWithFastError(schema, value, options, path);
233
+ if (result.valid) {
234
+ return result;
266
235
  }
267
- properties[key] = {
268
- type: (itemType ?? propertyMetadata.type),
269
- array,
270
- optional: reflectionData?.optional,
271
- nullable: reflectionData?.nullable,
272
- coerce: reflectionData?.coerce,
273
- coercers: reflectionData?.coercers,
274
- transformers: reflectionData?.transformers,
275
- arrayConstraints: reflectionData?.arrayConstraints,
276
- valueConstraints: reflectionData?.valueConstraints
277
- };
236
+ errors.push(result.error);
278
237
  }
279
- const objectSchema = {
280
- factory: (0, type_guards_1.isDefined)(typeData?.factory) ? { builder: typeData.factory } : { type: type },
281
- properties,
282
- mask: typeData?.mask,
283
- allowUnknownProperties: typeData?.allowUnknownProperties
284
- };
285
- return objectSchema;
238
+ const expectStrings = [];
239
+ for (const schema of validSchemas) {
240
+ getExpectString(schema);
241
+ }
242
+ const expectString = expectStrings.join('\n');
243
+ return { valid: false, error: schema_error_1.SchemaError.expectedButGot(expectString, (0, utils_1.getValueType)(value), path) };
244
+ }
245
+ function getExpectString(schema) {
246
+ const expectedNames = (0, utils_1.getSchemaTypeNames)(schema);
247
+ const expectedTypeString = (expectedNames.length == 1)
248
+ ? expectedNames[0]
249
+ : `[${expectedNames.join(', ')}]`;
250
+ const expects = (0, types_1.isValueSchema)(schema) ? (0, array_1.toArray)(schema.valueConstraints ?? []).map((constraint) => constraint.expects) : [];
251
+ const expectsString = (expects.length > 0) ? ` (${expects.join(', ')})` : '';
252
+ return `${expectedTypeString}${expectsString}`;
286
253
  }
287
254
  //# sourceMappingURL=schema.js.map