@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,9 +1,5 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
3
- import { SchemaValidator, test } from '../schema.validator';
4
- import type { Coercible, SchemaDefinition, SchemaOptions } from '../types';
5
- export declare type BooleanSchemaDefinition = SchemaDefinition<'boolean', unknown, boolean> & Coercible;
6
- export declare class BooleanSchemaValidator extends SchemaValidator<BooleanSchemaDefinition> {
7
- [test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<boolean>;
8
- }
9
- export declare function boolean(options?: SchemaOptions<BooleanSchemaDefinition>): BooleanSchemaValidator;
1
+ import type { Decorator } from "../../reflection";
2
+ import type { Coercible, ValueSchema } from '../types';
3
+ export declare type BooleanOptions = Coercible;
4
+ export declare function boolean(options?: BooleanOptions): ValueSchema<boolean>;
5
+ export declare function Boolean(options?: BooleanOptions): Decorator<'property' | 'accessor'>;
@@ -1,45 +1,17 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.boolean = exports.BooleanSchemaValidator = void 0;
4
- const schema_error_1 = require("../schema.error");
5
- const schema_validator_1 = require("../schema.validator");
4
+ exports.Boolean = exports.boolean = void 0;
5
+ const decorators_1 = require("../decorators");
6
6
  const types_1 = require("../types");
7
- const coercerMap = {
8
- string: (string, path) => {
9
- const lowered = string.toLowerCase();
10
- switch (lowered) {
11
- case 'true':
12
- case '1':
13
- case 'yes':
14
- return { valid: true, value: true };
15
- case 'false':
16
- case '0':
17
- case 'no':
18
- return { valid: true, value: false };
19
- default:
20
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot('boolean', 'string', path) };
21
- }
22
- },
23
- number: (number, path) => ((number == 1) ? { valid: true, value: true }
24
- : (number == 0) ? { valid: true, value: false }
25
- : { valid: false, error: schema_error_1.SchemaError.expectedButGot('boolean', 'number', path) })
26
- };
27
- class BooleanSchemaValidator extends schema_validator_1.SchemaValidator {
28
- [schema_validator_1.test](value, options, path) {
29
- const result = super.ensureType('boolean', value, path, { coerce: this.schema.coerce ?? options.coerce }, coercerMap);
30
- if (!result.valid) {
31
- return result;
32
- }
33
- return { valid: true, value: result.value };
34
- }
35
- }
36
- exports.BooleanSchemaValidator = BooleanSchemaValidator;
37
- function boolean(options) {
38
- const schema = (0, types_1.schemaHelper)({
39
- type: 'boolean',
40
- ...options
7
+ function boolean(options = {}) {
8
+ return (0, types_1.valueSchema)((0, types_1.typeSchema)(globalThis.Boolean), {
9
+ coerce: options.coerce
41
10
  });
42
- return new BooleanSchemaValidator(schema);
43
11
  }
44
12
  exports.boolean = boolean;
13
+ function Boolean(options) {
14
+ return (0, decorators_1.createSchemaPropertyDecoratorFromSchema)(boolean(options));
15
+ }
16
+ exports.Boolean = Boolean;
45
17
  //# sourceMappingURL=boolean.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../source/schema/schemas/boolean.ts"],"names":[],"mappings":";;;AACA,kDAA8C;AAE9C,0DAA4D;AAE5D,oCAAwC;AAExC,MAAM,UAAU,GAAwB;IACtC,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACvB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QAErC,QAAQ,OAAO,EAAE;YACf,KAAK,MAAM,CAAC;YACZ,KAAK,GAAG,CAAC;YACT,KAAK,KAAK;gBACR,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAEtC,KAAK,OAAO,CAAC;YACb,KAAK,GAAG,CAAC;YACT,KAAK,IAAI;gBACP,OAAO,EAAE,KAAK,EAAE,IAA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IAEH,OAAO,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAPD,0BAOC"}
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../source/schema/schemas/boolean.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAwE;AAExE,oCAAmD;AAInD,SAAgB,OAAO,CAAC,UAA0B,EAAE;IAClD,OAAO,IAAA,mBAAW,EAAU,IAAA,kBAAU,EAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC1D,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AAJD,0BAIC;AAED,SAAgB,OAAO,CAAC,OAAwB;IAC9C,OAAO,IAAA,oDAAuC,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC;AAFD,0BAEC"}
@@ -0,0 +1,4 @@
1
+ import type { OneOrMany } from "../../types";
2
+ import type { GenericConstraintFunction } from '../constraints/generic';
3
+ import type { Schema } from '../schema';
4
+ export declare function constraint<T, O>(schema: Schema<T, O>, constraintFunction: GenericConstraintFunction<T>, expects?: OneOrMany<string>): Schema<T, O>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constraint = void 0;
4
+ const generic_1 = require("../constraints/generic");
5
+ const types_1 = require("../types");
6
+ function constraint(schema, constraintFunction, expects) {
7
+ return (0, types_1.valueSchema)(schema, {
8
+ valueConstraints: new generic_1.GenericConstraint(constraintFunction, expects)
9
+ });
10
+ }
11
+ exports.constraint = constraint;
12
+ /* decorator is in file of GenericConstraint */
13
+ //# sourceMappingURL=constraint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constraint.js","sourceRoot":"","sources":["../../../source/schema/schemas/constraint.ts"],"names":[],"mappings":";;;AAEA,oDAA2D;AAE3D,oCAAuC;AAEvC,SAAgB,UAAU,CAAO,MAAoB,EAAE,kBAAgD,EAAE,OAA2B;IAClI,OAAO,IAAA,mBAAW,EAAC,MAAM,EAAE;QACzB,gBAAgB,EAAE,IAAI,2BAAiB,CAAC,kBAAkB,EAAE,OAAO,CAAC;KACrE,CAAC,CAAC;AACL,CAAC;AAJD,gCAIC;AAED,+CAA+C"}
@@ -1,12 +1,8 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
3
- import { SchemaValidator, test } from '../schema.validator';
4
- import type { Coercible, SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
5
- export declare type DateSchemaDefinition = SchemaDefinition<'uint8-array', unknown, Date> & Coercible & {
6
- min?: Date;
7
- max?: Date;
1
+ import type { Decorator } from "../../reflection";
2
+ import type { Coercible, ValueSchema } from '../types';
3
+ export declare type DateOptions = Coercible & {
4
+ minimum?: Date | number;
5
+ maximum?: Date | number;
8
6
  };
9
- export declare class DateSchemaValidator extends SchemaValidator<DateSchemaDefinition> {
10
- [test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<DateSchemaDefinition>>;
11
- }
12
- export declare function date(options?: SchemaOptions<DateSchemaDefinition>): DateSchemaValidator;
7
+ export declare function date(options?: DateOptions): ValueSchema<Date>;
8
+ export declare function Date(options?: DateOptions): Decorator<'property' | 'accessor'>;
@@ -1,63 +1,27 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.date = exports.DateSchemaValidator = void 0;
4
+ exports.Date = exports.date = void 0;
4
5
  const type_guards_1 = require("../../utils/type-guards");
5
- const schema_error_1 = require("../schema.error");
6
- const schema_validator_1 = require("../schema.validator");
6
+ const constraints_1 = require("../constraints");
7
+ const decorators_1 = require("../decorators");
7
8
  const types_1 = require("../types");
8
- const instance_1 = require("./instance");
9
- const dateInstanceSchema = (0, instance_1.instance)(Date);
10
- const coercerMap = {
11
- string: (string, path) => {
12
- const dateValue = new Date(string);
13
- if (Number.isNaN(dateValue.getTime())) {
14
- return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid format', path) };
15
- }
16
- return { valid: true, value: dateValue };
17
- },
18
- number: (number, path) => {
19
- const dateValue = new Date(number);
20
- if (Number.isNaN(dateValue.getTime())) {
21
- return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid timestamp', path) };
22
- }
23
- return { valid: true, value: dateValue };
24
- },
25
- bigint: (bigint, path) => {
26
- const numberValue = Number(bigint);
27
- const dateValue = new Date(numberValue);
28
- if (Number.isNaN(dateValue.getTime())) {
29
- return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid timestamp', path) };
30
- }
31
- return { valid: true, value: dateValue };
9
+ function date(options = {}) {
10
+ const constraints = [];
11
+ if ((0, type_guards_1.isDefined)(options.minimum)) {
12
+ constraints.push(new constraints_1.MinimumDateConstraint(options.minimum));
32
13
  }
33
- };
34
- class DateSchemaValidator extends schema_validator_1.SchemaValidator {
35
- [schema_validator_1.test](value, options, path) {
36
- const result = super.ensureInstance(Date, value, path, { coerce: this.schema.coerce ?? options.coerce }, coercerMap);
37
- if (!result.valid) {
38
- return result;
39
- }
40
- const instanceTestResult = dateInstanceSchema[schema_validator_1.test](result.value, options, path);
41
- if (!instanceTestResult.valid) {
42
- return instanceTestResult;
43
- }
44
- const dateValue = instanceTestResult.value;
45
- if ((0, type_guards_1.isDefined)(this.schema.min) && (dateValue < this.schema.min)) {
46
- return { valid: false, error: (0, schema_error_1.schemaError)(`minimum date is ${this.schema.min.toISOString()}`, path) };
47
- }
48
- if ((0, type_guards_1.isDefined)(this.schema.max) && (dateValue > this.schema.max)) {
49
- return { valid: false, error: (0, schema_error_1.schemaError)(`maximum date is ${this.schema.max.toISOString()}`, path) };
50
- }
51
- return { valid: true, value: dateValue };
14
+ if ((0, type_guards_1.isDefined)(options.maximum)) {
15
+ constraints.push(new constraints_1.MaximumDateConstraint(options.maximum));
52
16
  }
53
- }
54
- exports.DateSchemaValidator = DateSchemaValidator;
55
- function date(options) {
56
- const schema = (0, types_1.schemaHelper)({
57
- type: 'uint8-array',
58
- ...options
17
+ return (0, types_1.valueSchema)((0, types_1.typeSchema)(globalThis.Date), {
18
+ coerce: options.coerce,
19
+ valueConstraints: constraints
59
20
  });
60
- return new DateSchemaValidator(schema);
61
21
  }
62
22
  exports.date = date;
23
+ function Date(options) {
24
+ return (0, decorators_1.createSchemaPropertyDecoratorFromSchema)(date(options));
25
+ }
26
+ exports.Date = Date;
63
27
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../../../source/schema/schemas/date.ts"],"names":[],"mappings":";;;AACA,yDAAgD;AAChD,kDAA2D;AAE3D,0DAA4D;AAE5D,oCAAwC;AACxC,yCAAsC;AAOtC,MAAM,kBAAkB,GAAG,IAAA,mBAAQ,EAAC,IAAI,CAAC,CAAC;AAE1C,MAAM,UAAU,GAAqB;IACnC,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACvB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE;YACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0BAAW,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC;SACxG;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC3C,CAAC;IACD,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACvB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE;YACrC,OAAO,EAA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;IAEhD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,mCAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC9D;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,mCAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC9D;IAED,OAAO,IAAA,mBAAW,EAAC,IAAA,kBAAU,EAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC9C,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AAfD,oBAeC;AAED,SAAgB,IAAI,CAAC,OAAqB;IACxC,OAAO,IAAA,oDAAuC,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC;AAFD,oBAEC"}
@@ -1,15 +1,4 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { NonNullOrUndefinable } from "../../types";
3
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
4
- import { SchemaValidator, test } from '../schema.validator';
5
- import type { SchemaDefinition, SchemaInput, SchemaOptions, SchemaOutput } from '../types';
6
- export declare type DefaultedSchemaDefinition<T extends SchemaDefinition = SchemaDefinition, U = unknown> = SchemaDefinition<'defaulted', SchemaInput<T> | undefined | null, NonNullOrUndefinable<SchemaOutput<T>> | U> & {
7
- schema: T;
8
- defaultValue: U;
9
- };
10
- export declare class DefaultedSchemaValidator<T extends SchemaDefinition, U> extends SchemaValidator<DefaultedSchemaDefinition<T, U>> {
11
- private readonly innerValidator;
12
- constructor(innerValidator: SchemaValidator<T>, schema: DefaultedSchemaDefinition<T, U>);
13
- [test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<DefaultedSchemaDefinition<T, U>>>;
14
- }
15
- export declare function defaulted<T extends SchemaDefinition, U>(innerValidator: SchemaValidator<T>, defaultValue: U, options?: SchemaOptions<DefaultedSchemaDefinition<T, U>, 'schema' | 'defaultValue'>): DefaultedSchemaValidator<T, U>;
1
+ import type { OneOrMany } from "../../types";
2
+ import type { Schema } from '../schema';
3
+ import type { ValueSchema } from '../types';
4
+ export declare function defaulted<T, O, Default>(type: OneOrMany<Schema<T, O>>, defaultValue: Default): ValueSchema<T, O | Default>;
@@ -1,30 +1,13 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaulted = exports.DefaultedSchemaValidator = void 0;
4
- const type_guards_1 = require("../../utils/type-guards");
5
- const schema_validator_1 = require("../schema.validator");
4
+ exports.defaulted = void 0;
5
+ const coercers_1 = require("../coercers");
6
6
  const types_1 = require("../types");
7
- class DefaultedSchemaValidator extends schema_validator_1.SchemaValidator {
8
- constructor(innerValidator, schema) {
9
- super(schema);
10
- this.innerValidator = innerValidator;
11
- }
12
- [schema_validator_1.test](value, options, path) {
13
- if ((0, type_guards_1.isNullOrUndefined)(value)) {
14
- return { valid: true, value: this.schema.defaultValue };
15
- }
16
- return this.innerValidator[schema_validator_1.test](value, options, path);
17
- }
18
- }
19
- exports.DefaultedSchemaValidator = DefaultedSchemaValidator;
20
- function defaulted(innerValidator, defaultValue, options) {
21
- const schema = (0, types_1.schemaHelper)({
22
- type: 'defaulted',
23
- schema: innerValidator.schema,
24
- defaultValue,
25
- ...options
7
+ function defaulted(type, defaultValue) {
8
+ return (0, types_1.valueSchema)(type, {
9
+ coercers: new coercers_1.DefaultValueCoercer(defaultValue)
26
10
  });
27
- return new DefaultedSchemaValidator(innerValidator, schema);
28
11
  }
29
12
  exports.defaulted = defaulted;
30
13
  //# sourceMappingURL=defaulted.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaulted.js","sourceRoot":"","sources":["../../../source/schema/schemas/defaulted.ts"],"names":[],"mappings":";;;AAEA,yDAAwD;AAExD,0DAA4D;AAE5D,oCAAwC;AAOxC,MAAa,wBAAwD,SAAQ,kCAAgD;IAG3H,YAAY,cAAkC,EAAE,MAAuC;QACrF,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,IAAA,+BAAiB,EAAC,KAAK,CAAC,EAAE;YAC5B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;SACzD;QAED,OAAO,IAAI,CAAC,cAAc,CAAC,uBAAI,CAAC,CAAC,KAAuB,EAAE,OAAO,EAAE,IAAI,CAAwE,CAAC;IAClJ,CAAC;CACF;AAhBD,4DAgBC;AAED,SAAgB,SAAS,CAAgC,cAAkC,EAAE,YAAe,EAAE,OAAmF;IAC/L,MAAM,MAAM,GAAG,IAAA,oBAAY,EAAkC;QAC3D,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,cAAc,CAAC,MAAM;QAC7B,YAAY;QACZ,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,IAAI,wBAAwB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AATD,8BASC"}
1
+ {"version":3,"file":"defaulted.js","sourceRoot":"","sources":["../../../source/schema/schemas/defaulted.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,0CAAkD;AAGlD,oCAAuC;AAEvC,SAAgB,SAAS,CAAgB,IAA6B,EAAE,YAAqB;IAC3F,OAAO,IAAA,mBAAW,EAAC,IAAI,EAAE;QACvB,QAAQ,EAAE,IAAI,8BAAmB,CAAC,YAAY,CAAC;KAChD,CAAC,CAAC;AACL,CAAC;AAJD,8BAIC"}
@@ -1,18 +1,6 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { Enumeration, EnumerationArray } from "../../types";
3
- import type { EnumValue } from "../../utils/enum";
4
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
5
- import { SchemaValidator, test } from '../schema.validator';
6
- import type { Coercible, SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
7
- export declare type EnumerationSchemaOutput<T extends Enumeration> = T extends EnumerationArray ? T[number] : EnumValue<T>;
8
- export declare type EnumerationSchemaDefinition<T extends Enumeration = Enumeration> = SchemaDefinition<'enumeration', unknown, EnumerationSchemaOutput<T>> & Coercible & {
9
- values: T;
10
- };
11
- export declare class EnumerationSchemaValidator<T extends Enumeration> extends SchemaValidator<EnumerationSchemaDefinition<T>> {
12
- private readonly values;
13
- private readonly valuesSet;
14
- readonly valuesCommaSeparated: string;
15
- constructor(valuesOrEnum: T, schema: EnumerationSchemaDefinition<T>);
16
- [test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<EnumerationSchemaDefinition<T>>>;
17
- }
18
- export declare function enumeration<T extends Enumeration>(values: T, options?: SchemaOptions<EnumerationSchemaDefinition, 'values'>): EnumerationSchemaValidator<T>;
1
+ import type { Decorator } from "../../reflection";
2
+ import type { Enumeration as EnumerationType, EnumerationValue } from "../../types";
3
+ import type { Coercible, ValueSchema } from '../types';
4
+ export declare type EnumerationOptions = Coercible;
5
+ export declare function enumeration<T extends EnumerationType>(enumerationValue: T, options?: EnumerationOptions): ValueSchema<EnumerationValue<T>>;
6
+ export declare function Enumeration(enumerationValue: EnumerationType, options?: EnumerationOptions): Decorator<'property' | 'accessor'>;
@@ -1,58 +1,20 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enumeration = exports.EnumerationSchemaValidator = void 0;
4
- const enum_1 = require("../../utils/enum");
5
- const lazy_property_1 = require("../../utils/object/lazy-property");
6
- const patterns_1 = require("../../utils/patterns");
7
- const type_guards_1 = require("../../utils/type-guards");
8
- const type_of_1 = require("../../utils/type-of");
9
- const schema_error_1 = require("../schema.error");
10
- const schema_validator_1 = require("../schema.validator");
4
+ exports.Enumeration = exports.enumeration = void 0;
5
+ const constraints_1 = require("../constraints");
6
+ const decorators_1 = require("../decorators");
11
7
  const types_1 = require("../types");
12
- class EnumerationSchemaValidator extends schema_validator_1.SchemaValidator {
13
- constructor(valuesOrEnum, schema) {
14
- super(schema);
15
- this.values = (0, type_guards_1.isArray)(valuesOrEnum) ? valuesOrEnum : (0, enum_1.enumValues)(valuesOrEnum);
16
- this.valuesSet = new Set(this.values);
17
- (0, lazy_property_1.lazyProperty)(this, 'valuesCommaSeparated', () => this.values.map((value) => (stringifyEnumerationValue(value))).join(', '));
18
- }
19
- [schema_validator_1.test](value, options, path) {
20
- if (this.valuesSet.has(value)) {
21
- return { valid: true, value: value };
22
- }
23
- if (this.schema.coerce ?? options.coerce) {
24
- let coercedValue;
25
- switch (typeof value) {
26
- case 'number':
27
- coercedValue = value.toString();
28
- break;
29
- case 'string':
30
- coercedValue = patterns_1.numberPattern.test(value) ? Number(value) : undefined;
31
- break;
32
- default:
33
- coercedValue = undefined;
34
- break;
35
- }
36
- if (this.valuesSet.has(coercedValue)) {
37
- return { valid: true, value: coercedValue };
38
- }
39
- }
40
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot(`one of [${this.valuesCommaSeparated}]`, stringifyEnumerationValue(value), path) };
41
- }
42
- }
43
- exports.EnumerationSchemaValidator = EnumerationSchemaValidator;
44
- function enumeration(values, options) {
45
- const schema = (0, types_1.schemaHelper)({
46
- type: 'enumeration',
47
- values,
48
- ...options
8
+ function enumeration(enumerationValue, options = {}) {
9
+ const enumerationConstraint = new constraints_1.EnumerationConstraint(enumerationValue);
10
+ return (0, types_1.valueSchema)((0, types_1.valueTypesOrSchemasToSchemas)(enumerationConstraint.suitableTypes), {
11
+ coerce: options.coerce,
12
+ valueConstraints: enumerationConstraint
49
13
  });
50
- return new EnumerationSchemaValidator(values, schema);
51
14
  }
52
15
  exports.enumeration = enumeration;
53
- function stringifyEnumerationValue(value) {
54
- return (0, type_guards_1.isString)(value) ? `"${value}"`
55
- : (0, type_guards_1.isNumber)(value) ? value.toString()
56
- : (0, type_of_1.typeOf)(value);
16
+ function Enumeration(enumerationValue, options = {}) {
17
+ return (0, decorators_1.createSchemaPropertyDecoratorFromSchema)(enumeration(enumerationValue, options));
57
18
  }
19
+ exports.Enumeration = Enumeration;
58
20
  //# sourceMappingURL=enumeration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"enumeration.js","sourceRoot":"","sources":["../../../source/schema/schemas/enumeration.ts"],"names":[],"mappings":";;;AAGA,2CAA0C;AAC1C,oEAA4D;AAC5D,mDAAiD;AACjD,yDAAkE;AAClE,iDAAyC;AACzC,kDAA8C;AAE9C,0DAA4D;AAE5D,oCAAwC;AAQxC,MAAa,0BAAkD,SAAQ,kCAA+C;IAMpH,YAAY,YAAe,EAAE,MAAsC;QACjE,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,MAAM,GAAG,IAAA,qBAAO,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAgC,CAAC,CAAC,CAAC,IAAA,iBAAU,EAAC,YAAY,CAAC,CAAC;QAClG,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEtC,IAAA,4BAAY,EAAC,IAAqC,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/J,CAAC;IAED,CAAC,uBAAI,CAAC,CAAC,KAAc,EAAE,OAAiC,EAAE,IAAc;QACtE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAwB,CAAC,EAAE;YAChD,OAA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,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE;YAClC,CAAC,CAAC,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC;AACtB,CAAC"}
1
+ {"version":3,"file":"enumeration.js","sourceRoot":"","sources":["../../../source/schema/schemas/enumeration.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,gDAAuD;AACvD,8CAAwE;AAExE,oCAAqE;AAIrE,SAAgB,WAAW,CAA4B,gBAAmB,EAAE,UAA8B,EAAE;IAC1G,MAAM,qBAAqB,GAAG,IAAI,mCAAqB,CAAC,gBAAgB,CAAC,CAAC;IAE1E,OAAO,IAAA,mBAAW,EAAC,IAAA,oCAA4B,EAAC,qBAAqB,CAAC,aAAa,CAAC,EAAE;QACpF,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,qBAAqB;KACxC,CAAC,CAAC;AACL,CAAC;AAPD,kCAOC;AAED,SAAgB,WAAW,CAAC,gBAAiC,EAAE,UAA8B,EAAE;IAC7F,OAAO,IAAA,oDAAuC,EAAC,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC;AACzF,CAAC;AAFD,kCAEC"}
@@ -0,0 +1,4 @@
1
+ import type { OneOrMany, Record } from "../../types";
2
+ import type { Simplify } from 'type-fest';
3
+ import type { ObjectSchema } from '../types';
4
+ export declare function exclude<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, key: OneOrMany<K>): ObjectSchema<Simplify<Omit<T, K>>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exclude = void 0;
4
+ const array_1 = require("../../utils/array/array");
5
+ const types_1 = require("../types");
6
+ function exclude(schema, key) {
7
+ const keys = (0, array_1.toArray)(key);
8
+ const entries = Object.entries(schema.properties);
9
+ const pickedEntries = entries.filter(([propertyKey]) => !keys.includes(propertyKey));
10
+ const pickedSchema = (0, types_1.objectSchema)({
11
+ ...schema,
12
+ properties: Object.fromEntries(pickedEntries)
13
+ });
14
+ return pickedSchema;
15
+ }
16
+ exports.exclude = exclude;
17
+ //# sourceMappingURL=exclude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exclude.js","sourceRoot":"","sources":["../../../source/schema/schemas/exclude.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAG9C,oCAAwC;AAExC,SAAgB,OAAO,CAAsC,MAAuB,EAAE,GAAiB;IACrG,MAAM,IAAI,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;IAE1B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAgB,CAAC,CAAC,CAAC;IAE1F,MAAM,YAAY,GAAG,IAAA,oBAAY,EAAC;QAChC,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAA8B;KAC3E,CAAC,CAAC;IAEH,OAAO,YAAmD,CAAC;AAC7D,CAAC;AAZD,0BAYC"}
@@ -1,21 +1,21 @@
1
1
  export * from './any';
2
2
  export * from './array';
3
- export * from './async-iterable';
3
+ export * from './assign';
4
4
  export * from './boolean';
5
+ export * from './constraint';
5
6
  export * from './date';
6
7
  export * from './defaulted';
7
8
  export * from './enumeration';
9
+ export * from './exclude';
8
10
  export * from './instance';
9
- export * from './iterable';
10
11
  export * from './literal';
11
- export * from './never';
12
12
  export * from './nullable';
13
13
  export * from './number';
14
14
  export * from './object';
15
15
  export * from './optional';
16
- export * from './preprocess';
16
+ export * from './pick';
17
17
  export * from './readable-stream';
18
- export * from './refine';
18
+ export * from './record';
19
19
  export * from './regexp';
20
20
  export * from './string';
21
21
  export * from './transform';
@@ -16,22 +16,22 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./any"), exports);
18
18
  __exportStar(require("./array"), exports);
19
- __exportStar(require("./async-iterable"), exports);
19
+ __exportStar(require("./assign"), exports);
20
20
  __exportStar(require("./boolean"), exports);
21
+ __exportStar(require("./constraint"), exports);
21
22
  __exportStar(require("./date"), exports);
22
23
  __exportStar(require("./defaulted"), exports);
23
24
  __exportStar(require("./enumeration"), exports);
25
+ __exportStar(require("./exclude"), exports);
24
26
  __exportStar(require("./instance"), exports);
25
- __exportStar(require("./iterable"), exports);
26
27
  __exportStar(require("./literal"), exports);
27
- __exportStar(require("./never"), exports);
28
28
  __exportStar(require("./nullable"), exports);
29
29
  __exportStar(require("./number"), exports);
30
30
  __exportStar(require("./object"), exports);
31
31
  __exportStar(require("./optional"), exports);
32
- __exportStar(require("./preprocess"), exports);
32
+ __exportStar(require("./pick"), exports);
33
33
  __exportStar(require("./readable-stream"), exports);
34
- __exportStar(require("./refine"), exports);
34
+ __exportStar(require("./record"), exports);
35
35
  __exportStar(require("./regexp"), exports);
36
36
  __exportStar(require("./string"), exports);
37
37
  __exportStar(require("./transform"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/schema/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,0CAAwB;AACxB,mDAAiC;AACjC,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,gDAA8B;AAC9B,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,+CAA6B;AAC7B,oDAAkC;AAClC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/schema/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,yCAAuB;AACvB,8CAA4B;AAC5B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,yCAAuB;AACvB,oDAAkC;AAClC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B"}
@@ -1,12 +1,2 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { Type } from "../../types";
3
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
4
- import { SchemaValidator, test } from '../schema.validator';
5
- import type { SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
6
- export declare type InstanceSchemaDefinition<T = unknown> = SchemaDefinition<'instance', T, T> & {
7
- constructor: Type<T>;
8
- };
9
- export declare class InstanceSchemaValidator<T> extends SchemaValidator<InstanceSchemaDefinition<T>> {
10
- [test](value: unknown, _options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<InstanceSchemaDefinition<T>>>;
11
- }
12
- export declare function instance<T>(constructor: Type<T>, options?: SchemaOptions<InstanceSchemaDefinition<T>, 'constructor'>): InstanceSchemaValidator<T>;
1
+ import type { NormalizeValueType, TypeSchema, ValueType } from '../types';
2
+ export declare function instance<T>(type: ValueType<T>): TypeSchema<NormalizeValueType<T>>;
@@ -1,26 +1,10 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/ban-types */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instance = exports.InstanceSchemaValidator = void 0;
4
- const type_of_1 = require("../../utils/type-of");
5
- const schema_error_1 = require("../schema.error");
6
- const schema_validator_1 = require("../schema.validator");
4
+ exports.instance = void 0;
7
5
  const types_1 = require("../types");
8
- class InstanceSchemaValidator extends schema_validator_1.SchemaValidator {
9
- [schema_validator_1.test](value, _options, path) {
10
- if (value instanceof this.schema.constructor) {
11
- return { valid: true, value: value };
12
- }
13
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot(`instance of ${this.schema.constructor.name}`, (0, type_of_1.typeOf)(value), path) };
14
- }
15
- }
16
- exports.InstanceSchemaValidator = InstanceSchemaValidator;
17
- function instance(constructor, options) {
18
- const schema = (0, types_1.schemaHelper)({
19
- type: 'instance',
20
- constructor,
21
- ...options
22
- });
23
- return new InstanceSchemaValidator(schema);
6
+ function instance(type) {
7
+ return (0, types_1.typeSchema)(type);
24
8
  }
25
9
  exports.instance = instance;
26
10
  //# sourceMappingURL=instance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../source/schema/schemas/instance.ts"],"names":[],"mappings":";;;AAEA,iDAAyC;AACzC,kDAA8C;AAE9C,0DAA4D;AAE5D,oCAAwC;AAMxC,MAAa,uBAA2B,SAAQ,kCAA4C;IAC1F,CAAC,uBAAI,CAAC,CAAC,KAAc,EAAE,QAAkC,EAAE,IAAc;QACvE,IAAI,KAAK,YAAY,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAC5C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAU,EAAE,CAAC;SAC3C;QAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0BAAW,CAAC,cAAc,CAAC,eAAe,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,IAAA,gBAAM,EAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;IACjI,CAAC;CACF;AARD,0DAQC;AAED,SAAgB,QAAQ,CAAI,WAAoB,EAAE,OAAmE;IACnH,MAAM,MAAM,GAAG,IAAA,oBAAY,EAA8B;QACvD,IAAI,EAAE,UAAU;QAChB,WAAW;QACX,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AARD,4BAQC"}
1
+ {"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../source/schema/schemas/instance.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAGjD,oCAAsC;AAEtC,SAAgB,QAAQ,CAAI,IAAkB;IAC5C,OAAO,IAAA,kBAAU,EAAI,IAAI,CAAC,CAAC;AAC7B,CAAC;AAFD,4BAEC"}
@@ -1,11 +1,4 @@
1
- import type { JsonPath } from "../../json-path";
2
- import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
3
- import { SchemaValidator, test } from '../schema.validator';
4
- import type { SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
5
- export declare type LiteralSchemaDefinition<T> = SchemaDefinition<'literal', T, T> & {
6
- value: T;
7
- };
8
- export declare class LiteralSchemaValidator<T> extends SchemaValidator<LiteralSchemaDefinition<T>> {
9
- [test](value: unknown, _options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<LiteralSchemaDefinition<T>>>;
10
- }
11
- export declare function literal<T>(value: T, options?: SchemaOptions<LiteralSchemaDefinition<T>, 'value'>): LiteralSchemaValidator<T>;
1
+ import type { Decorator } from "../../reflection";
2
+ import type { ValueSchema } from '../types';
3
+ export declare function literal<T>(value: T): ValueSchema<T>;
4
+ export declare function Literal(value: any): Decorator<'property' | 'accessor'>;
@@ -1,25 +1,19 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.literal = exports.LiteralSchemaValidator = void 0;
4
- const schema_error_1 = require("../schema.error");
5
- const schema_validator_1 = require("../schema.validator");
4
+ exports.Literal = exports.literal = void 0;
5
+ const constraints_1 = require("../constraints");
6
+ const decorators_1 = require("../decorators");
6
7
  const types_1 = require("../types");
7
- class LiteralSchemaValidator extends schema_validator_1.SchemaValidator {
8
- [schema_validator_1.test](value, _options, path) {
9
- if (value === this.schema.value) {
10
- return { valid: true, value: value };
11
- }
12
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot(String(this.schema.value), String(value), path) };
13
- }
14
- }
15
- exports.LiteralSchemaValidator = LiteralSchemaValidator;
16
- function literal(value, options) {
17
- const schema = (0, types_1.schemaHelper)({
18
- type: 'literal',
19
- value,
20
- ...options
8
+ const utils_1 = require("../utils");
9
+ function literal(value) {
10
+ return (0, types_1.valueSchema)((0, types_1.typeSchema)((0, utils_1.getValueType)(value)), {
11
+ valueConstraints: new constraints_1.LiteralConstraint(value)
21
12
  });
22
- return new LiteralSchemaValidator(schema);
23
13
  }
24
14
  exports.literal = literal;
15
+ function Literal(value) {
16
+ return (0, decorators_1.createSchemaPropertyDecoratorFromSchema)(literal(value));
17
+ }
18
+ exports.Literal = Literal;
25
19
  //# sourceMappingURL=literal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../source/schema/schemas/literal.ts"],"names":[],"mappings":";;;AACA,kDAA8C;AAE9C,0DAA4D;AAE5D,oCAAwC;AAMxC,MAAa,sBAA0B,SAAQ,kCAA2C;IACxF,CAAC,uBAAI,CAAC,CAAC,KAAc,EAAE,QAAkC,EAAE,IAAc;QACvE,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YAC/B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAU,EAAE,CAAC;SAC3C;QAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0BAAW,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;IAC7G,CAAC;CACF;AARD,wDAQC;AAED,SAAgB,OAAO,CAAI,KAAQ,EAAE,OAA4D;IAC/F,MAAM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