@tstdl/base 0.71.87 → 0.78.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/.eslintrc.js +2 -4
  2. package/api/client/client.js +2 -12
  3. package/api/client/client.js.map +1 -1
  4. package/api/default-error-handlers.d.ts +0 -4
  5. package/api/default-error-handlers.js +1 -6
  6. package/api/default-error-handlers.js.map +1 -1
  7. package/api/server/error-handler.js +2 -2
  8. package/api/server/error-handler.js.map +1 -1
  9. package/api/server/gateway.js +12 -18
  10. package/api/server/gateway.js.map +1 -1
  11. package/api/server/module.d.ts +0 -4
  12. package/api/server/module.js +1 -12
  13. package/api/server/module.js.map +1 -1
  14. package/api/types.d.ts +8 -32
  15. package/api/types.js.map +1 -1
  16. package/container/container.js +2 -2
  17. package/container/container.js.map +1 -1
  18. package/data-structures/index.d.ts +1 -0
  19. package/data-structures/index.js +1 -0
  20. package/data-structures/index.js.map +1 -1
  21. package/data-structures/iterable-weak-map.d.ts +29 -0
  22. package/data-structures/iterable-weak-map.js +128 -0
  23. package/data-structures/iterable-weak-map.js.map +1 -0
  24. package/data-structures/multi-key-map.d.ts +12 -1
  25. package/data-structures/multi-key-map.js +22 -11
  26. package/data-structures/multi-key-map.js.map +1 -1
  27. package/error/custom.error.d.ts +3 -1
  28. package/error/custom.error.js +16 -7
  29. package/error/custom.error.js.map +1 -1
  30. package/examples/api/basic-overview.js +16 -8
  31. package/examples/api/basic-overview.js.map +1 -1
  32. package/http/http.error.d.ts +4 -2
  33. package/http/http.error.js +6 -0
  34. package/http/http.error.js.map +1 -1
  35. package/image-service/image-service.d.ts +32 -65
  36. package/image-service/image-service.js +73 -15
  37. package/image-service/image-service.js.map +1 -1
  38. package/json-path/json-path.d.ts +8 -3
  39. package/json-path/json-path.js +24 -7
  40. package/json-path/json-path.js.map +1 -1
  41. package/logger/console/logger.js +2 -2
  42. package/logger/console/logger.js.map +1 -1
  43. package/mail/mail.service.js +2 -2
  44. package/mail/mail.service.js.map +1 -1
  45. package/module/modules/index.d.ts +0 -1
  46. package/module/modules/index.js +0 -1
  47. package/module/modules/index.js.map +1 -1
  48. package/openid-connect/oidc-configuration.service.js +7 -7
  49. package/openid-connect/oidc-configuration.service.js.map +1 -1
  50. package/openid-connect/oidc.service.js +7 -7
  51. package/openid-connect/oidc.service.js.map +1 -1
  52. package/package.json +3 -4
  53. package/process-shutdown.js +3 -2
  54. package/process-shutdown.js.map +1 -1
  55. package/reflection/decorators.js +1 -0
  56. package/reflection/decorators.js.map +1 -1
  57. package/reflection/reflection-data-map.d.ts +10 -0
  58. package/reflection/reflection-data-map.js +40 -0
  59. package/reflection/reflection-data-map.js.map +1 -0
  60. package/reflection/registry.d.ts +7 -7
  61. package/reflection/registry.js +7 -6
  62. package/reflection/registry.js.map +1 -1
  63. package/reflection/types.d.ts +1 -0
  64. package/reflection/utils.d.ts +6 -3
  65. package/reflection/utils.js +9 -35
  66. package/reflection/utils.js.map +1 -1
  67. package/schema/array-constraints/index.d.ts +2 -0
  68. package/{old-api/validation/validators → schema/array-constraints}/index.js +2 -1
  69. package/schema/array-constraints/index.js.map +1 -0
  70. package/schema/array-constraints/maximum-length.d.ts +11 -0
  71. package/schema/array-constraints/maximum-length.js +26 -0
  72. package/schema/array-constraints/maximum-length.js.map +1 -0
  73. package/schema/array-constraints/minimum-length.d.ts +11 -0
  74. package/schema/array-constraints/minimum-length.js +26 -0
  75. package/schema/array-constraints/minimum-length.js.map +1 -0
  76. package/schema/coercers/boolean.coercer.d.ts +9 -0
  77. package/schema/coercers/boolean.coercer.js +35 -0
  78. package/schema/coercers/boolean.coercer.js.map +1 -0
  79. package/schema/coercers/date.coercer.d.ts +9 -0
  80. package/schema/coercers/date.coercer.js +24 -0
  81. package/schema/coercers/date.coercer.js.map +1 -0
  82. package/schema/coercers/default-value.coercer.d.ts +9 -0
  83. package/schema/coercers/default-value.coercer.js +16 -0
  84. package/schema/coercers/default-value.coercer.js.map +1 -0
  85. package/schema/coercers/index.d.ts +7 -0
  86. package/schema/coercers/index.js +24 -0
  87. package/schema/coercers/index.js.map +1 -0
  88. package/schema/coercers/number.coercer.d.ts +9 -0
  89. package/schema/coercers/number.coercer.js +22 -0
  90. package/schema/coercers/number.coercer.js.map +1 -0
  91. package/schema/coercers/regexp.coercer.d.ts +11 -0
  92. package/schema/coercers/regexp.coercer.js +24 -0
  93. package/schema/coercers/regexp.coercer.js.map +1 -0
  94. package/schema/coercers/string.coercer.d.ts +9 -0
  95. package/schema/coercers/string.coercer.js +22 -0
  96. package/schema/coercers/string.coercer.js.map +1 -0
  97. package/schema/coercers/uint8-array.coercer.d.ts +9 -0
  98. package/schema/coercers/uint8-array.coercer.js +31 -0
  99. package/schema/coercers/uint8-array.coercer.js.map +1 -0
  100. package/schema/constraints/enumeration.d.ts +13 -0
  101. package/schema/constraints/enumeration.js +29 -0
  102. package/schema/constraints/enumeration.js.map +1 -0
  103. package/schema/constraints/generic.d.ts +22 -0
  104. package/schema/constraints/generic.js +32 -0
  105. package/schema/constraints/generic.js.map +1 -0
  106. package/schema/constraints/index.d.ts +12 -0
  107. package/schema/constraints/index.js +29 -0
  108. package/schema/constraints/index.js.map +1 -0
  109. package/schema/constraints/integer.d.ts +12 -0
  110. package/schema/constraints/integer.js +27 -0
  111. package/schema/constraints/integer.js.map +1 -0
  112. package/schema/constraints/length.d.ts +6 -0
  113. package/schema/constraints/length.js +20 -0
  114. package/schema/constraints/length.js.map +1 -0
  115. package/schema/constraints/literal.d.ts +10 -0
  116. package/schema/constraints/literal.js +26 -0
  117. package/schema/constraints/literal.js.map +1 -0
  118. package/schema/constraints/maximum-date.d.ts +12 -0
  119. package/schema/constraints/maximum-date.js +29 -0
  120. package/schema/constraints/maximum-date.js.map +1 -0
  121. package/schema/constraints/maximum-length.d.ts +12 -0
  122. package/schema/constraints/maximum-length.js +29 -0
  123. package/schema/constraints/maximum-length.js.map +1 -0
  124. package/schema/constraints/maximum.d.ts +12 -0
  125. package/schema/constraints/maximum.js +27 -0
  126. package/schema/constraints/maximum.js.map +1 -0
  127. package/schema/constraints/minimum-date.d.ts +12 -0
  128. package/schema/constraints/minimum-date.js +29 -0
  129. package/schema/constraints/minimum-date.js.map +1 -0
  130. package/schema/constraints/minimum-length.d.ts +12 -0
  131. package/schema/constraints/minimum-length.js +29 -0
  132. package/schema/constraints/minimum-length.js.map +1 -0
  133. package/schema/constraints/minimum.d.ts +12 -0
  134. package/schema/constraints/minimum.js +27 -0
  135. package/schema/constraints/minimum.js.map +1 -0
  136. package/schema/constraints/pattern.d.ts +13 -0
  137. package/schema/constraints/pattern.js +28 -0
  138. package/schema/constraints/pattern.js.map +1 -0
  139. package/schema/decorators/array.d.ts +4 -0
  140. package/schema/decorators/array.js +11 -0
  141. package/schema/decorators/array.js.map +1 -0
  142. package/schema/decorators/coerce.d.ts +2 -0
  143. package/schema/decorators/coerce.js +10 -0
  144. package/schema/decorators/coerce.js.map +1 -0
  145. package/schema/decorators/defaulted.d.ts +3 -0
  146. package/schema/decorators/defaulted.js +11 -0
  147. package/schema/decorators/defaulted.js.map +1 -0
  148. package/schema/decorators/index.d.ts +8 -0
  149. package/{old-api → schema/decorators}/index.js +8 -3
  150. package/schema/decorators/index.js.map +1 -0
  151. package/schema/decorators/nullable.d.ts +2 -0
  152. package/schema/decorators/nullable.js +10 -0
  153. package/schema/decorators/nullable.js.map +1 -0
  154. package/schema/decorators/optional.d.ts +2 -0
  155. package/schema/decorators/optional.js +10 -0
  156. package/schema/decorators/optional.js.map +1 -0
  157. package/schema/decorators/property.d.ts +6 -0
  158. package/schema/decorators/property.js +19 -0
  159. package/schema/decorators/property.js.map +1 -0
  160. package/schema/decorators/type.d.ts +3 -0
  161. package/schema/decorators/type.js +10 -0
  162. package/schema/decorators/type.js.map +1 -0
  163. package/schema/decorators/types.d.ts +18 -0
  164. package/schema/decorators/types.js +3 -0
  165. package/schema/decorators/types.js.map +1 -0
  166. package/schema/decorators/utils.d.ts +10 -0
  167. package/schema/decorators/utils.js +59 -0
  168. package/schema/decorators/utils.js.map +1 -0
  169. package/schema/index.d.ts +7 -1
  170. package/schema/index.js +7 -1
  171. package/schema/index.js.map +1 -1
  172. package/schema/schema.d.ts +19 -0
  173. package/schema/schema.error.d.ts +13 -7
  174. package/schema/schema.error.js +45 -13
  175. package/schema/schema.error.js.map +1 -1
  176. package/schema/schema.js +286 -0
  177. package/schema/schema.js.map +1 -0
  178. package/schema/schemas/any.d.ts +4 -8
  179. package/schema/schemas/any.js +9 -14
  180. package/schema/schemas/any.js.map +1 -1
  181. package/schema/schemas/array.d.ts +7 -13
  182. package/schema/schemas/array.js +14 -43
  183. package/schema/schemas/array.js.map +1 -1
  184. package/schema/schemas/assign.d.ts +8 -0
  185. package/schema/schemas/assign.js +28 -0
  186. package/schema/schemas/assign.js.map +1 -0
  187. package/schema/schemas/boolean.d.ts +5 -9
  188. package/schema/schemas/boolean.js +11 -38
  189. package/schema/schemas/boolean.js.map +1 -1
  190. package/schema/schemas/constraint.d.ts +4 -0
  191. package/schema/schemas/constraint.js +14 -0
  192. package/schema/schemas/constraint.js.map +1 -0
  193. package/schema/schemas/date.d.ts +7 -11
  194. package/schema/schemas/date.js +18 -53
  195. package/schema/schemas/date.js.map +1 -1
  196. package/schema/schemas/defaulted.d.ts +2 -15
  197. package/schema/schemas/defaulted.js +7 -23
  198. package/schema/schemas/defaulted.js.map +1 -1
  199. package/schema/schemas/enumeration.d.ts +6 -18
  200. package/schema/schemas/enumeration.js +13 -50
  201. package/schema/schemas/enumeration.js.map +1 -1
  202. package/schema/schemas/exclude.d.ts +4 -0
  203. package/schema/schemas/exclude.js +17 -0
  204. package/schema/schemas/exclude.js.map +1 -0
  205. package/schema/schemas/index.d.ts +5 -6
  206. package/schema/schemas/index.js +5 -6
  207. package/schema/schemas/index.js.map +1 -1
  208. package/schema/schemas/instance.d.ts +2 -12
  209. package/schema/schemas/instance.js +4 -20
  210. package/schema/schemas/instance.js.map +1 -1
  211. package/schema/schemas/literal.d.ts +4 -11
  212. package/schema/schemas/literal.js +13 -18
  213. package/schema/schemas/literal.js.map +1 -1
  214. package/schema/schemas/nullable.d.ts +3 -13
  215. package/schema/schemas/nullable.js +3 -26
  216. package/schema/schemas/nullable.js.map +1 -1
  217. package/schema/schemas/number.d.ts +7 -14
  218. package/schema/schemas/number.js +23 -44
  219. package/schema/schemas/number.js.map +1 -1
  220. package/schema/schemas/object.d.ts +6 -34
  221. package/schema/schemas/object.js +8 -112
  222. package/schema/schemas/object.js.map +1 -1
  223. package/schema/schemas/optional.d.ts +3 -13
  224. package/schema/schemas/optional.js +3 -26
  225. package/schema/schemas/optional.js.map +1 -1
  226. package/schema/schemas/pick.d.ts +4 -0
  227. package/schema/schemas/pick.js +17 -0
  228. package/schema/schemas/pick.js.map +1 -0
  229. package/schema/schemas/readable-stream.d.ts +4 -9
  230. package/schema/schemas/readable-stream.js +9 -15
  231. package/schema/schemas/readable-stream.js.map +1 -1
  232. package/schema/schemas/record.d.ts +4 -0
  233. package/schema/schemas/record.js +14 -0
  234. package/schema/schemas/record.js.map +1 -0
  235. package/schema/schemas/regexp.d.ts +6 -9
  236. package/schema/schemas/regexp.js +10 -27
  237. package/schema/schemas/regexp.js.map +1 -1
  238. package/schema/schemas/string.d.ts +9 -13
  239. package/schema/schemas/string.js +34 -46
  240. package/schema/schemas/string.js.map +1 -1
  241. package/schema/schemas/transform.d.ts +4 -16
  242. package/schema/schemas/transform.js +7 -36
  243. package/schema/schemas/transform.js.map +1 -1
  244. package/schema/schemas/uint8-array.d.ts +8 -11
  245. package/schema/schemas/uint8-array.js +20 -32
  246. package/schema/schemas/uint8-array.js.map +1 -1
  247. package/schema/schemas/union.d.ts +5 -17
  248. package/schema/schemas/union.js +9 -35
  249. package/schema/schemas/union.js.map +1 -1
  250. package/schema/schemas/unknown.d.ts +4 -8
  251. package/schema/schemas/unknown.js +9 -14
  252. package/schema/schemas/unknown.js.map +1 -1
  253. package/schema/transformers/generic.d.ts +13 -0
  254. package/schema/transformers/generic.js +28 -0
  255. package/schema/transformers/generic.js.map +1 -0
  256. package/schema/transformers/index.d.ts +3 -0
  257. package/{old-api/endpoints → schema/transformers}/index.js +3 -1
  258. package/schema/transformers/index.js.map +1 -0
  259. package/schema/transformers/lowercase.d.ts +9 -0
  260. package/schema/transformers/lowercase.js +22 -0
  261. package/schema/transformers/lowercase.js.map +1 -0
  262. package/schema/transformers/trim.d.ts +9 -0
  263. package/schema/transformers/trim.js +22 -0
  264. package/schema/transformers/trim.js.map +1 -0
  265. package/schema/transformers/uppercase.d.ts +9 -0
  266. package/schema/transformers/uppercase.js +22 -0
  267. package/schema/transformers/uppercase.js.map +1 -0
  268. package/schema/types.d.ts +135 -15
  269. package/schema/types.js +39 -3
  270. package/schema/types.js.map +1 -1
  271. package/schema/utils/index.d.ts +2 -0
  272. package/{old-api/validation → schema/utils}/index.js +2 -1
  273. package/schema/utils/index.js.map +1 -0
  274. package/schema/utils/schema.d.ts +12 -0
  275. package/schema/utils/schema.js +78 -0
  276. package/schema/utils/schema.js.map +1 -0
  277. package/schema/utils/value-type.d.ts +4 -0
  278. package/schema/utils/value-type.js +35 -0
  279. package/schema/utils/value-type.js.map +1 -0
  280. package/templates/providers/file-template.provider.base.d.ts +1 -1
  281. package/templates/providers/file-template.provider.base.js +3 -2
  282. package/templates/providers/file-template.provider.base.js.map +1 -1
  283. package/types.d.ts +5 -1
  284. package/utils/clone.d.ts +1 -0
  285. package/utils/clone.js +45 -0
  286. package/utils/clone.js.map +1 -0
  287. package/utils/enum.d.ts +1 -1
  288. package/utils/format-error.d.ts +20 -0
  289. package/utils/format-error.js +42 -0
  290. package/utils/format-error.js.map +1 -0
  291. package/utils/function/memoize.d.ts +6 -2
  292. package/utils/function/memoize.js +28 -20
  293. package/utils/function/memoize.js.map +1 -1
  294. package/utils/helpers.d.ts +1 -32
  295. package/utils/helpers.js +3 -158
  296. package/utils/helpers.js.map +1 -1
  297. package/utils/index.d.ts +3 -0
  298. package/utils/index.js +3 -0
  299. package/utils/index.js.map +1 -1
  300. package/utils/merge.d.ts +5 -0
  301. package/utils/merge.js +32 -0
  302. package/utils/merge.js.map +1 -0
  303. package/utils/object/decycle.d.ts +16 -0
  304. package/utils/object/decycle.js +81 -0
  305. package/utils/object/decycle.js.map +1 -0
  306. package/utils/object/dereference.js.map +1 -1
  307. package/utils/object/index.d.ts +1 -0
  308. package/utils/object/index.js +1 -0
  309. package/utils/object/index.js.map +1 -1
  310. package/utils/object/object.d.ts +4 -0
  311. package/utils/object/object.js +9 -2
  312. package/utils/object/object.js.map +1 -1
  313. package/utils/patterns.d.ts +1 -1
  314. package/utils/patterns.js +3 -3
  315. package/utils/patterns.js.map +1 -1
  316. package/utils/timing.d.ts +0 -8
  317. package/utils/timing.js.map +1 -1
  318. package/utils/type-guards.d.ts +6 -0
  319. package/utils/type-guards.js +16 -4
  320. package/utils/type-guards.js.map +1 -1
  321. package/instance-provider.d.ts +0 -17
  322. package/instance-provider.js +0 -55
  323. package/instance-provider.js.map +0 -1
  324. package/module/modules/old-web-server.module.d.ts +0 -22
  325. package/module/modules/old-web-server.module.js +0 -37
  326. package/module/modules/old-web-server.module.js.map +0 -1
  327. package/old-api/endpoint.d.ts +0 -5
  328. package/old-api/endpoint.js +0 -20
  329. package/old-api/endpoint.js.map +0 -1
  330. package/old-api/endpoints/echo.endpoint.d.ts +0 -2
  331. package/old-api/endpoints/echo.endpoint.js +0 -6
  332. package/old-api/endpoints/echo.endpoint.js.map +0 -1
  333. package/old-api/endpoints/index.d.ts +0 -1
  334. package/old-api/endpoints/index.js.map +0 -1
  335. package/old-api/http-api.d.ts +0 -63
  336. package/old-api/http-api.js +0 -269
  337. package/old-api/http-api.js.map +0 -1
  338. package/old-api/index.d.ts +0 -3
  339. package/old-api/index.js.map +0 -1
  340. package/old-api/validation/index.d.ts +0 -1
  341. package/old-api/validation/index.js.map +0 -1
  342. package/old-api/validation/types.d.ts +0 -6
  343. package/old-api/validation/types.js +0 -6
  344. package/old-api/validation/types.js.map +0 -1
  345. package/old-api/validation/validators/index.d.ts +0 -1
  346. package/old-api/validation/validators/index.js.map +0 -1
  347. package/old-api/validation/validators/noop.d.ts +0 -2
  348. package/old-api/validation/validators/noop.js +0 -8
  349. package/old-api/validation/validators/noop.js.map +0 -1
  350. package/old-api/validation/validators/superstruct.d.ts +0 -14
  351. package/old-api/validation/validators/superstruct.js +0 -66
  352. package/old-api/validation/validators/superstruct.js.map +0 -1
  353. package/old-api/validation/validators/yup.d.ts +0 -7
  354. package/old-api/validation/validators/yup.js +0 -60
  355. package/old-api/validation/validators/yup.js.map +0 -1
  356. package/schema/schema.validator.d.ts +0 -40
  357. package/schema/schema.validator.js +0 -75
  358. package/schema/schema.validator.js.map +0 -1
  359. package/schema/schemas/async-iterable.d.ts +0 -13
  360. package/schema/schemas/async-iterable.js +0 -40
  361. package/schema/schemas/async-iterable.js.map +0 -1
  362. package/schema/schemas/iterable.d.ts +0 -13
  363. package/schema/schemas/iterable.js +0 -40
  364. package/schema/schemas/iterable.js.map +0 -1
  365. package/schema/schemas/never.d.ts +0 -9
  366. package/schema/schemas/never.js +0 -22
  367. package/schema/schemas/never.js.map +0 -1
  368. package/schema/schemas/preprocess.d.ts +0 -16
  369. package/schema/schemas/preprocess.js +0 -35
  370. package/schema/schemas/preprocess.js.map +0 -1
  371. package/schema/schemas/refine.d.ts +0 -24
  372. package/schema/schemas/refine.js +0 -52
  373. package/schema/schemas/refine.js.map +0 -1
@@ -1,269 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpApi = exports.noopRequestDataTransformer = exports.getDefaultRequestDataTransformer = exports.getSimpleRouteHandler = exports.getStreamRouteHandler = exports.getBufferRouteHandler = exports.getJsonRouteHandler = exports.getTextRouteHandler = exports.route = exports.simpleRoute = void 0;
4
- const response_1 = require("../api/response");
5
- const error_1 = require("../error");
6
- const http_1 = require("../http");
7
- const array_1 = require("../utils/array");
8
- const encoding_1 = require("../utils/encoding");
9
- const math_1 = require("../utils/math");
10
- const stream_reader_1 = require("../utils/stream/stream-reader");
11
- const timer_1 = require("../utils/timer");
12
- const type_guards_1 = require("../utils/type-guards");
13
- const KoaRouter = require("@koa/router");
14
- const Koa = require("koa");
15
- const server_1 = require("../http/server");
16
- function simpleRoute({ method, path, bodyType, maxRequestBodyBytes, endpoint }) {
17
- return route({
18
- method,
19
- path,
20
- bodyType,
21
- maxRequestBodyBytes,
22
- handler: getJsonRouteHandler(),
23
- requestDataTransformer: getDefaultRequestDataTransformer(),
24
- endpoint
25
- });
26
- }
27
- exports.simpleRoute = simpleRoute;
28
- // eslint-disable-next-line @typescript-eslint/no-shadow
29
- function route(route) {
30
- return route;
31
- }
32
- exports.route = route;
33
- function getTextRouteHandler() {
34
- return getSimpleRouteHandler((result) => server_1.HttpServerResponse.fromObject({ body: { text: result } }));
35
- }
36
- exports.getTextRouteHandler = getTextRouteHandler;
37
- function getJsonRouteHandler() {
38
- return getSimpleRouteHandler((result) => server_1.HttpServerResponse.fromObject({ body: { json: result } }));
39
- }
40
- exports.getJsonRouteHandler = getJsonRouteHandler;
41
- function getBufferRouteHandler() {
42
- return getSimpleRouteHandler((result) => server_1.HttpServerResponse.fromObject({ body: { buffer: result } }));
43
- }
44
- exports.getBufferRouteHandler = getBufferRouteHandler;
45
- function getStreamRouteHandler() {
46
- return getSimpleRouteHandler((result) => server_1.HttpServerResponse.fromObject({ body: { stream: result } }));
47
- }
48
- exports.getStreamRouteHandler = getStreamRouteHandler;
49
- function getSimpleRouteHandler(handler) {
50
- async function routeHandler(request, parameters, endpoint) {
51
- const result = await endpoint(parameters, request);
52
- return handler(result);
53
- }
54
- return routeHandler;
55
- }
56
- exports.getSimpleRouteHandler = getSimpleRouteHandler;
57
- function getDefaultRequestDataTransformer() {
58
- function defaultRequestDataTransformer(data, bodyType, context) {
59
- let transformed = { ...data.parameters };
60
- const requestBodyType = contentTypeToBodyType(context.request.type);
61
- if ((bodyType == 'json' && (0, type_guards_1.isObject)(data.body) && !Array.isArray(data.body)) || (bodyType == 'auto' && requestBodyType == 'json')) {
62
- transformed = { ...transformed, ...data.body };
63
- }
64
- else if (bodyType != 'none' && (0, type_guards_1.isDefined)(data.body)) {
65
- transformed = { ...transformed, body: data.body };
66
- }
67
- return transformed;
68
- }
69
- return defaultRequestDataTransformer;
70
- }
71
- exports.getDefaultRequestDataTransformer = getDefaultRequestDataTransformer;
72
- function noopRequestDataTransformer(data) {
73
- return data;
74
- }
75
- exports.noopRequestDataTransformer = noopRequestDataTransformer;
76
- class HttpApi {
77
- constructor({ prefix, logger, behindProxy = false }) {
78
- this.logger = logger;
79
- this.koa = new Koa();
80
- this.router = new KoaRouter();
81
- this.supressedErrors = new Set();
82
- this.requestHandler = this.koa.callback();
83
- this.koa.proxy = behindProxy;
84
- if (prefix != undefined) {
85
- this.router.prefix(prefix);
86
- }
87
- this.koa.use(responseTimeMiddleware);
88
- this.koa.use(errorCatchMiddleware(logger, this.supressedErrors));
89
- this.koa.use(this.router.routes());
90
- this.koa.use(this.router.allowedMethods());
91
- }
92
- handleRequest(request, response) {
93
- this.requestHandler(request, response);
94
- }
95
- supressErrorLog(...errorConstructors) {
96
- for (const errorConstructor of errorConstructors) {
97
- this.supressedErrors.add(errorConstructor);
98
- }
99
- }
100
- registerRoutes(...routes) {
101
- // eslint-disable-next-line @typescript-eslint/no-shadow
102
- for (const route of routes) {
103
- const methods = (0, array_1.toArray)(route.method);
104
- for (const method of methods) {
105
- switch (method) {
106
- case 'GET':
107
- this.registerRoute(method, route.path, 'none', route.maxRequestBodyBytes ?? 10e6, route.requestDataTransformer, route.endpoint, route.handler);
108
- break;
109
- case 'POST':
110
- case 'PATCH':
111
- case 'PUT':
112
- case 'DELETE':
113
- this.registerRoute(method, route.path, route.bodyType ?? 'auto', route.maxRequestBodyBytes ?? 10e6, route.requestDataTransformer, route.endpoint, route.handler);
114
- break;
115
- default:
116
- throw new Error('unknown route method');
117
- }
118
- }
119
- }
120
- }
121
- registerRoute(method, path, bodyType, maxBytes, requestDataTransformer, endpoint, handler) {
122
- this.router.register(path, [method], async (context, next) => {
123
- await this.handle(context, bodyType, maxBytes, requestDataTransformer, endpoint, handler);
124
- return next();
125
- });
126
- }
127
- // eslint-disable-next-line max-lines-per-function, max-statements, class-methods-use-this
128
- async handle(context, bodyType, maxBytes, requestDataTransformer, endpoint, handler) {
129
- const { request, response, params } = context;
130
- const { query: { ...query } } = request;
131
- const requestParameters = { ...params, ...query };
132
- let body;
133
- try {
134
- body = await getBody(request, bodyType, maxBytes);
135
- }
136
- catch (error) {
137
- response.status = (0, response_1.getErrorStatusCode)(error, 400);
138
- response.body = (0, response_1.createErrorResponse)(error);
139
- return;
140
- }
141
- const requestData = { parameters: requestParameters, body };
142
- const handlerParameters = requestDataTransformer(requestData, bodyType, { request });
143
- const httpRequest = new server_1.HttpServerRequest({
144
- url: context.URL,
145
- method: context.request.method,
146
- headers: new http_1.HttpHeaders(context.req.headers),
147
- query: new http_1.HttpQuery(query),
148
- ip: context.request.ip,
149
- body: request.req
150
- });
151
- const httpResponse = await handler(httpRequest, handlerParameters, endpoint);
152
- applyResponse(response, httpResponse);
153
- }
154
- }
155
- exports.HttpApi = HttpApi;
156
- function applyResponse(response, responseResult) {
157
- if (responseResult.body?.json != undefined) {
158
- response.set('Content-Type', 'application/json; charset=utf-8');
159
- response.body = JSON.stringify(responseResult.body.json);
160
- }
161
- else if (responseResult.body?.text != undefined) {
162
- response.body = responseResult.body.text;
163
- }
164
- else if (responseResult.body?.stream != undefined) {
165
- response.body = responseResult.body.stream;
166
- }
167
- else if (responseResult.body?.buffer != undefined) {
168
- response.body = responseResult.body.buffer;
169
- }
170
- for (const [field, value] of responseResult.headers.normalizedEntries()) {
171
- response.remove(field);
172
- for (const val of (0, array_1.toArray)(value)) {
173
- response.append(field, val);
174
- }
175
- }
176
- if (responseResult.statusCode != undefined) {
177
- response.status = responseResult.statusCode;
178
- }
179
- if (responseResult.statusMessage != undefined) {
180
- response.message = responseResult.statusMessage;
181
- }
182
- }
183
- async function getBody(request, bodyType, maxBytes = 10e6) {
184
- switch (bodyType) {
185
- case 'none':
186
- return undefined;
187
- case 'text':
188
- return readBody(request, maxBytes);
189
- case 'json':
190
- return readJsonBody(request, maxBytes);
191
- case 'stream':
192
- return request.req;
193
- case 'buffer':
194
- return readRawBody(request, maxBytes);
195
- case 'auto':
196
- const requestBodyType = contentTypeToBodyType(request.type);
197
- return getBody(request, requestBodyType, maxBytes);
198
- default:
199
- throw new Error('unknown HttpBodyType');
200
- }
201
- }
202
- async function readJsonBody(request, maxBytes) {
203
- const body = await readBody(request, maxBytes);
204
- try {
205
- const json = JSON.parse(body);
206
- return json;
207
- }
208
- catch (error) {
209
- throw new error_1.UnsupportedMediaTypeError('expected application/json');
210
- }
211
- }
212
- async function readBody(request, maxBytes) {
213
- const rawBody = await readRawBody(request, maxBytes);
214
- const encoding = ((0, type_guards_1.isDefined)(request.charset) && (request.charset.length > 0)) ? request.charset : undefined;
215
- const body = (0, encoding_1.decodeText)(rawBody, encoding);
216
- return body;
217
- }
218
- async function readRawBody(request, maxBytes) {
219
- if (request.length > maxBytes) {
220
- throw new error_1.MaxBytesExceededError(`maximum content-length of ${maxBytes} bytes exceeded`);
221
- }
222
- const buffer = await (0, stream_reader_1.readBinaryStream)(request.req, request.length, maxBytes);
223
- return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
224
- }
225
- function errorCatchMiddleware(logger, supressedErrors) {
226
- // eslint-disable-next-line @typescript-eslint/no-shadow
227
- return async function errorCatchMiddleware({ response }, next) {
228
- try {
229
- // eslint-disable-next-line callback-return
230
- await next();
231
- }
232
- catch (error) {
233
- const errorConstructor = error.constructor;
234
- const supressed = supressedErrors.has(errorConstructor);
235
- if (!supressed) {
236
- logger.error(error);
237
- }
238
- if ((0, response_1.hasErrorHandler)(errorConstructor)) {
239
- response.status = (0, response_1.getErrorStatusCode)(error);
240
- response.body = (0, response_1.createErrorResponse)(error);
241
- }
242
- else {
243
- response.status = 500;
244
- response.body = (0, response_1.createErrorResponse)('500', 'Internal Server Error');
245
- }
246
- }
247
- };
248
- }
249
- async function responseTimeMiddleware(context, next) {
250
- const milliseconds = await timer_1.Timer.measureAsync(next);
251
- const roundedMilliseconds = (0, math_1.round)(milliseconds, 2);
252
- context.response.set('X-Response-Time', `${roundedMilliseconds}ms`);
253
- }
254
- function contentTypeToBodyType(contentType) {
255
- switch (contentType) {
256
- case 'text/plain':
257
- return 'text';
258
- case 'application/json':
259
- return 'json';
260
- case 'application/octet-stream':
261
- return 'buffer';
262
- case '':
263
- case undefined:
264
- return 'none';
265
- default:
266
- throw new error_1.BadRequestError('unsupported Content-Type');
267
- }
268
- }
269
- //# sourceMappingURL=http-api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-api.js","sourceRoot":"","sources":["../../source/old-api/http-api.ts"],"names":[],"mappings":";;;AACA,8CAA0F;AAE1F,oCAA4F;AAE5F,kCAAgD;AAIhD,0CAAwC;AACxC,gDAA8C;AAC9C,wCAAqC;AAErC,iEAAgE;AAEhE,0CAAsC;AACtC,sDAA0D;AAC1D,yCAAyC;AAGzC,2BAA2B;AAE3B,2CAAuE;AAyBvE,SAAgB,WAAW,CACzB,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAA2L;IAElP,OAAO,KAAK,CACV;QACE,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,mBAAmB;QACnB,OAAO,EAAE,mBAAmB,EAAE;QAC9B,sBAAsB,EAAE,gCAAgC,EAAE;QAC1D,QAAQ;KACT,CACF,CAAC;AACJ,CAAC;AAdD,kCAcC;AAED,wDAAwD;AACxD,SAAgB,KAAK,CAA0H,KAA6F;IAC1O,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,sBAEC;AAQD,SAAgB,mBAAmB;IACjC,OAAO,qBAAqB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,2BAAkB,CAAC,UAAU,CAAC,EAAE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Q,WAAW,EAAE;QACnB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;QAEhB,KAAK,kBAAkB;YACrB,OAAO,MAAM,CAAC;QAEhB,KAAK,0BAA0B;YAC7B,OAAO,QAAQ,CAAC;QAElB,KAAK,EAAE,CAAC;QACR,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAEhB;YACE,MAAM,IAAI,uBAAe,CAAC,0BAA0B,CAAC,CAAC;KACzD;AACH,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from "../api/default-error-handlers";
2
- export * from "../api/response";
3
- export * from './endpoint';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/old-api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAC7C,kDAA+B;AAC/B,6CAA2B"}
@@ -1 +0,0 @@
1
- export * from './types';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/old-api/validation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
@@ -1,6 +0,0 @@
1
- import { ValidationError } from "../../error";
2
- export { ValidationError };
3
- export declare type SyncEndpointParametersValidator<Input, Output> = (object: Input) => ValidationResult<Output>;
4
- export declare type AsyncEndpointParametersValidator<Input, Output> = (object: Input) => Promise<ValidationResult<Output>>;
5
- export declare type EndpointParametersValidator<Input, Output> = SyncEndpointParametersValidator<Input, Output> | AsyncEndpointParametersValidator<Input, Output>;
6
- export declare type ValidationResult<Output> = Output;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationError = void 0;
4
- const error_1 = require("../../error");
5
- Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return error_1.ValidationError; } });
6
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../source/old-api/validation/types.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AACjC,gGADA,uBAAe,OACA"}
@@ -1 +0,0 @@
1
- export * from './noop';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../source/old-api/validation/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
@@ -1,2 +0,0 @@
1
- import type { ValidationResult } from '../types';
2
- export declare function noopValidator<T>(value: T): ValidationResult<T>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noopValidator = void 0;
4
- function noopValidator(value) {
5
- return value;
6
- }
7
- exports.noopValidator = noopValidator;
8
- //# sourceMappingURL=noop.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noop.js","sourceRoot":"","sources":["../../../../source/old-api/validation/validators/noop.ts"],"names":[],"mappings":";;;AAEA,SAAgB,aAAa,CAAI,KAAQ;IACvC,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,sCAEC"}
@@ -1,14 +0,0 @@
1
- import type { Struct } from 'superstruct';
2
- import type { SyncEndpointParametersValidator, ValidationResult } from '../types';
3
- export declare type SuperstructOptions = {
4
- coerce?: boolean;
5
- mask?: boolean;
6
- };
7
- export declare function setDefaultSuperstructOptions(options: SuperstructOptions): void;
8
- export declare const email: () => Struct<string, null>;
9
- export declare const coerceNumber: (struct?: Struct<number, null>) => Struct<number, null>;
10
- export declare const coerceBoolean: () => Struct<boolean, null>;
11
- export declare const lowercased: <T, S>(struct: Struct<T, S>) => Struct<T, S>;
12
- export declare const nulledStructSchema: <T>(struct: Struct<T, any>) => Struct<T, null>;
13
- export declare function validator<T>(struct: Struct<T>, options?: SuperstructOptions): SyncEndpointParametersValidator<unknown, T>;
14
- export declare function validate<T, U>(struct: Struct<T>, value: U, options?: SuperstructOptions): ValidationResult<T>;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validate = exports.validator = exports.nulledStructSchema = exports.lowercased = exports.coerceBoolean = exports.coerceNumber = exports.email = exports.setDefaultSuperstructOptions = void 0;
4
- const patterns_1 = require("../../../utils/patterns");
5
- const type_guards_1 = require("../../../utils/type-guards");
6
- const superstruct_1 = require("superstruct");
7
- const types_1 = require("../types");
8
- let defaultOptions = {
9
- coerce: true,
10
- mask: false
11
- };
12
- function setDefaultSuperstructOptions(options) {
13
- defaultOptions = options;
14
- }
15
- exports.setDefaultSuperstructOptions = setDefaultSuperstructOptions;
16
- const coerceBooleanLiteralsStruct = (0, superstruct_1.union)([(0, superstruct_1.literal)(true), (0, superstruct_1.literal)(false), (0, superstruct_1.literal)(1), (0, superstruct_1.literal)(0), (0, superstruct_1.literal)('true'), (0, superstruct_1.literal)('false'), (0, superstruct_1.literal)('1'), (0, superstruct_1.literal)('0'), (0, superstruct_1.literal)('yes'), (0, superstruct_1.literal)('no')]);
17
- const coerceBooleanTrueLiterals = [true, 1, 'true', '1', 'yes'];
18
- const numberStruct = (0, superstruct_1.number)();
19
- const numberStringStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^[+-]?(?:\d*\.)?\d+$/u);
20
- const email = () => (0, superstruct_1.pattern)((0, superstruct_1.string)(), patterns_1.emailPattern);
21
- exports.email = email;
22
- const coerceNumber = (struct = numberStruct) => (0, superstruct_1.coerce)(struct, numberStringStruct, (value) => parseFloat(value));
23
- exports.coerceNumber = coerceNumber;
24
- const coerceBoolean = () => (0, superstruct_1.coerce)((0, superstruct_1.boolean)(), coerceBooleanLiteralsStruct, (value) => coerceBooleanTrueLiterals.includes(value));
25
- exports.coerceBoolean = coerceBoolean;
26
- const lowercased = (struct) => (0, superstruct_1.coerce)(struct, (0, superstruct_1.string)(), (x) => x.toLowerCase());
27
- exports.lowercased = lowercased;
28
- const nulledStructSchema = (struct) => struct;
29
- exports.nulledStructSchema = nulledStructSchema;
30
- function validator(struct, options = defaultOptions) {
31
- return (value) => validate(struct, value, options);
32
- }
33
- exports.validator = validator;
34
- function validate(struct, value, options = defaultOptions) {
35
- let result;
36
- let error;
37
- if (options.mask == true) {
38
- try {
39
- result = struct.mask(value);
40
- }
41
- catch (_error) {
42
- error = _error;
43
- }
44
- }
45
- else {
46
- [error, result] = struct.validate(value, { coerce: options.coerce });
47
- }
48
- if ((0, type_guards_1.isDefined)(error)) {
49
- throw convertError(error);
50
- }
51
- return result;
52
- }
53
- exports.validate = validate;
54
- function convertError(error) {
55
- const failures = error.failures().map((failure) => convertFailure(failure));
56
- const inner = (failures.length > 0) ? failures : undefined;
57
- return convertFailure(error, inner);
58
- }
59
- function convertFailure(failure, inner) {
60
- const details = {
61
- path: failure.path,
62
- type: failure.type
63
- };
64
- return new types_1.ValidationError(failure.message, { details, inner });
65
- }
66
- //# sourceMappingURL=superstruct.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../../../../source/old-api/validation/validators/superstruct.ts"],"names":[],"mappings":";;;AAAA,sDAAgD;AAChD,4DAAgD;AAEhD,6CAAuF;AAEvF,oCAA2C;AAO3C,IAAI,cAAc,GAAuB;IACvC,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF,SAAgB,4BAA4B,CAAC,OAA2B;IACtE,cAAc,GAAG,OAAO,CAAC;AAC3B,CAAC;AAFD,oEAEC;AAED,MAAM,2BAA2B,GAAG,IAAA,mBAAK,EAAC,CAAC,IAAA,qBAAO,EAAC,IAAI,CAAC,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC,EAAE,IAAA,qBAAO,EAAC,CAAC,CAAC,EAAE,IAAA,qBAAO,EAAC,CAAC,CAAC,EAAE,IAAA,qBAAO,EAAC,MAAM,CAAC,EAAE,IAAA,qBAAO,EAAC,OAAO,CAAC,EAAE,IAAA,qBAAO,EAAC,GAAG,CAAC,EAAE,IAAA,qBAAO,EAAC,GAAG,CAAC,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC,EAAE,IAAA,qBAAO,EAAC,IAAI,C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,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAClE,CAAC"}
@@ -1,7 +0,0 @@
1
- import * as yup from 'yup';
2
- import type { EndpointParametersValidator, ValidationResult } from '../types';
3
- export declare function setDefaultYupValidationOptions(options: yup.ValidateOptions): void;
4
- export declare function stripNullFromSchema<T>(schema: yup.MixedSchema<T>): yup.MixedSchema<Exclude<T, null>>;
5
- export declare function oneOfSchemas<T>(schemas: yup.Schema<T>[], message?: string): yup.Schema<T>;
6
- export declare function validator<T>(schema: yup.Schema<T>, options?: yup.ValidateOptions): EndpointParametersValidator<unknown, T>;
7
- export declare function validate<T, U>(schema: yup.Schema<T>, value: U, options?: yup.ValidateOptions): ValidationResult<T>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validate = exports.validator = exports.oneOfSchemas = exports.stripNullFromSchema = exports.setDefaultYupValidationOptions = void 0;
4
- const yup = require("yup");
5
- const types_1 = require("../types");
6
- let defaultOptions = {
7
- abortEarly: false,
8
- stripUnknown: false
9
- };
10
- function setDefaultYupValidationOptions(options) {
11
- defaultOptions = options;
12
- }
13
- exports.setDefaultYupValidationOptions = setDefaultYupValidationOptions;
14
- function stripNullFromSchema(schema) {
15
- return schema;
16
- }
17
- exports.stripNullFromSchema = stripNullFromSchema;
18
- function oneOfSchemas(schemas, message = 'value did not match any of the allowed schemas') {
19
- return yup.mixed().test({
20
- name: 'one-of-schemas',
21
- message,
22
- test(value) {
23
- const errors = [];
24
- for (const schema of schemas) {
25
- try {
26
- schema.validateSync(value, this.options);
27
- return true;
28
- }
29
- catch (error) {
30
- errors.push(error);
31
- }
32
- }
33
- const error = new yup.ValidationError('none of the provided schemas validated successfully', value, this.path);
34
- error.inner = errors;
35
- return error;
36
- }
37
- });
38
- }
39
- exports.oneOfSchemas = oneOfSchemas;
40
- function validator(schema, options) {
41
- return (value) => validate(schema, value, options);
42
- }
43
- exports.validator = validator;
44
- function validate(schema, value, options = defaultOptions) {
45
- try {
46
- return schema.validateSync(value, options);
47
- }
48
- catch (error) {
49
- throw convertError(error);
50
- }
51
- }
52
- exports.validate = validate;
53
- function convertError(error) {
54
- const details = {
55
- path: error.path
56
- };
57
- const inner = (error.inner.length > 0) ? error.inner.map(convertError) : undefined;
58
- return new types_1.ValidationError(error.message, { details, inner });
59
- }
60
- //# sourceMappingURL=yup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yup.js","sourceRoot":"","sources":["../../../../source/old-api/validation/validators/yup.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAE3B,oCAA2C;AAE3C,IAAI,cAAc,GAAwB;IACxC,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,KAAK;CACpB,CAAC;AAEF,SAAgB,8BAA8B,CAAC,OAA4B;IACzE,cAAc,GAAG,OAAO,CAAC;AAC3B,CAAC;AAFD,wEAEC;AAED,SAAgB,mBAAmB,CAAI,MAA0B;IAC/D,OAAO,MAA2C,CAAC;AACrD,CAAC;AAFD,kDAEC;AAED,SAAgB,YAAY,CAAI,OAAwB,EAAE,UAAkB,gDAAgD;IAC1H,OAAO,GAAG,CAAC,KAAK,EAAK,CAAC,IAAI,CAAC;QACzB,IAAI,EAAE,gBAAgB;QACtB,OAAO;QACP,IAAI,CAAC,KAAU;YACb,MAAM,MAAM,GAA0B,EAAE,CAAC;YAEzC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,IAAI;oBACF,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;oBACzC,OAAO,IAAI,CAAC;iBACb;gBACD,OAAO,KAAc,EAAE;oBACrB,MAAM,CAAC,IAAI,CAAC,KAA4B,CAAC,CAAC;iBAC3C;aACF;YAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,qDAAqD,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/G,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;YAErB,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAvBD,oCAuBC;AAED,SAAgB,SAAS,CAAI,MAAqB,EAAE,OAA6B;IAC/E,OAAO,CAAC,KAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAFD,8BAEC;AAED,SAAgB,QAAQ,CAAO,MAAqB,EAAE,KAAQ,EAAE,UAA+B,cAAc;IAC3G,IAAI;QACF,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAC5C;IACD,OAAO,KAAc,EAAE;QACrB,MAAM,YAAY,CAAC,KAA4B,CAAC,CAAC;KAClD;AACH,CAAC;AAPD,4BAOC;AAED,SAAS,YAAY,CAAC,KAA0B;IAC9C,MAAM,OAAO,GAAG;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;IAEF,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnF,OAAO,IAAI,uBAAe,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE,CAAC"}
@@ -1,40 +0,0 @@
1
- import { JsonPath } from "../json-path";
2
- import type { PrimitiveType, PrimitiveTypeString, Type } from "../types";
3
- import { SchemaError } from './schema.error';
4
- import type { Coercible, Maskable, SchemaDefinition, SchemaInput, SchemaOutput } from './types';
5
- export declare const test: unique symbol;
6
- export declare const testAsync: unique symbol;
7
- export declare type CoercerFunction<P extends PrimitiveTypeString, T> = (value: PrimitiveType<P>, path: string | JsonPath) => ValidationTestResult<T>;
8
- export declare type CoercerMap<T> = {
9
- [P in PrimitiveTypeString]?: CoercerFunction<P, T>;
10
- };
11
- export declare type ValidationOptions = Coercible & Maskable;
12
- export declare type DefinedValidationOptions = Required<ValidationOptions>;
13
- export declare type ValidationTestResult<T> = {
14
- valid: true;
15
- value: T;
16
- error?: undefined;
17
- } | {
18
- valid: false;
19
- value?: undefined;
20
- error: SchemaError;
21
- };
22
- export declare type EnsureTypeOptions = Coercible;
23
- export declare abstract class SchemaValidator<S extends SchemaDefinition = SchemaDefinition> {
24
- readonly schema: S;
25
- /** used for type inference only */
26
- readonly inputType: SchemaInput<S>;
27
- /** used for type inference only */
28
- readonly outputType: SchemaOutput<S>;
29
- constructor(schema: S);
30
- is(value: any, options?: ValidationOptions): value is SchemaOutput<S>;
31
- isAsync(value: SchemaInput<S>, options?: ValidationOptions): Promise<boolean>;
32
- parse(value: SchemaInput<S>, options?: ValidationOptions): SchemaOutput<S>;
33
- parseAsync(value: SchemaInput<S>, options?: ValidationOptions): Promise<SchemaOutput<S>>;
34
- test(value: SchemaInput<S>, options?: ValidationOptions): ValidationTestResult<SchemaOutput<S>>;
35
- testAsync(value: SchemaInput<S>, options?: ValidationOptions): Promise<ValidationTestResult<SchemaOutput<S>>>;
36
- protected ensureType<U extends PrimitiveType>(type: PrimitiveTypeString<U>, value: unknown, path: JsonPath, options?: EnsureTypeOptions, coercers?: CoercerMap<U>): ValidationTestResult<U>;
37
- protected ensureInstance<U extends PrimitiveType>(type: Type, value: unknown, path: JsonPath, options?: EnsureTypeOptions, coercers?: CoercerMap<U>): ValidationTestResult<U>;
38
- protected [testAsync](value: SchemaInput<S>, options: DefinedValidationOptions, path: JsonPath): Promise<ValidationTestResult<SchemaOutput<S>>>;
39
- protected abstract [test](value: SchemaInput<S>, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<S>>;
40
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaValidator = exports.testAsync = exports.test = void 0;
4
- const json_path_1 = require("../json-path");
5
- const type_guards_1 = require("../utils/type-guards");
6
- const type_of_1 = require("../utils/type-of");
7
- const schema_error_1 = require("./schema.error");
8
- exports.test = Symbol('test');
9
- exports.testAsync = Symbol('testAsync');
10
- class SchemaValidator {
11
- constructor(schema) {
12
- this.schema = schema;
13
- }
14
- is(value, options) {
15
- const result = this.test(value, options);
16
- return result.valid;
17
- }
18
- async isAsync(value, options) {
19
- const result = await this.testAsync(value, options);
20
- return result.valid;
21
- }
22
- parse(value, options) {
23
- const result = this.test(value, options);
24
- if (result.valid) {
25
- return result.value;
26
- }
27
- throw result.error;
28
- }
29
- async parseAsync(value, options) {
30
- const result = await this.testAsync(value, options);
31
- if (result.valid) {
32
- return result.value;
33
- }
34
- throw result.error;
35
- }
36
- test(value, options) {
37
- return this[exports.test](value, convertOptions(options), new json_path_1.JsonPath());
38
- }
39
- async testAsync(value, options) {
40
- return this[exports.testAsync](value, convertOptions(options), new json_path_1.JsonPath());
41
- }
42
- ensureType(type, value, path, options, coercers) {
43
- const valueType = typeof value;
44
- if (valueType == type) {
45
- return { valid: true, value: value };
46
- }
47
- const coercer = (options?.coerce ?? false) ? coercers?.[valueType] : undefined;
48
- if ((0, type_guards_1.isUndefined)(coercer)) {
49
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot(type, (0, type_of_1.typeOf)(value), path) };
50
- }
51
- return coercer(value, path);
52
- }
53
- ensureInstance(type, value, path, options, coercers) {
54
- if (value instanceof type) {
55
- return { valid: true, value: value };
56
- }
57
- const coercer = (options?.coerce ?? false) ? coercers?.[typeof value] : undefined;
58
- if ((0, type_guards_1.isUndefined)(coercer)) {
59
- return { valid: false, error: schema_error_1.SchemaError.expectedButGot(type.name, (0, type_of_1.typeOf)(value), path) };
60
- }
61
- return coercer(value, path);
62
- }
63
- // eslint-disable-next-line @typescript-eslint/adjacent-overload-signatures, @typescript-eslint/require-await
64
- async [exports.testAsync](value, options, path) {
65
- return this[exports.test](value, options, path);
66
- }
67
- }
68
- exports.SchemaValidator = SchemaValidator;
69
- function convertOptions(options) {
70
- return {
71
- coerce: options?.coerce ?? false,
72
- mask: options?.mask ?? false
73
- };
74
- }
75
- //# sourceMappingURL=schema.validator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.validator.js","sourceRoot":"","sources":["../../source/schema/schema.validator.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AAEvC,sDAAkD;AAClD,8CAAyC;AACzC,iDAA6C;AAGhC,QAAA,IAAI,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC;AACrC,QAAA,SAAS,GAAkB,MAAM,CAAC,WAAW,CAAC,CAAC;AAgB5D,MAAsB,eAAe;IASnC,YAAY,MAAS;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,EAAE,CAAC,KAAU,EAAE,OAA2B;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAuB,EAAE,OAAO,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAqB,EAAE,OAA2B;QAC9D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAqB,EAAE,OAA2B;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEzC,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,OAAO,MAAM,CAAC,KAAK,CAAC;SACrB;QAED,MAAM,MAAM,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAqB,EAAE,OAA2B;QACjE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEpD,IAAI,MAAM,CAAC,KAAK,EAAE;Y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