@ddd-ts-kit/http 0.0.0-stage → 0.1.1

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 (394) hide show
  1. package/README.md +388 -2
  2. package/dist/criteria/coerce-value.d.ts +8 -0
  3. package/dist/criteria/coerce-value.d.ts.map +1 -0
  4. package/dist/criteria/coerce-value.js +29 -0
  5. package/dist/criteria/coerce-value.js.map +1 -0
  6. package/dist/criteria/criteria-from.d.ts +11 -0
  7. package/dist/criteria/criteria-from.d.ts.map +1 -0
  8. package/dist/criteria/criteria-from.js +17 -0
  9. package/dist/criteria/criteria-from.js.map +1 -0
  10. package/dist/criteria/criteria-parameters.d.ts +10 -0
  11. package/dist/criteria/criteria-parameters.d.ts.map +1 -0
  12. package/dist/criteria/criteria-parameters.js +45 -0
  13. package/dist/criteria/criteria-parameters.js.map +1 -0
  14. package/dist/criteria/criteria-query-options.d.ts +6 -0
  15. package/dist/criteria/criteria-query-options.d.ts.map +1 -0
  16. package/dist/criteria/criteria-query-options.js +2 -0
  17. package/dist/criteria/criteria-query-options.js.map +1 -0
  18. package/dist/criteria/criteria-query-schema.d.ts +10 -0
  19. package/dist/criteria/criteria-query-schema.d.ts.map +1 -0
  20. package/dist/criteria/criteria-query-schema.js +12 -0
  21. package/dist/criteria/criteria-query-schema.js.map +1 -0
  22. package/dist/criteria/filter-entries.d.ts +9 -0
  23. package/dist/criteria/filter-entries.d.ts.map +1 -0
  24. package/dist/criteria/filter-entries.js +28 -0
  25. package/dist/criteria/filter-entries.js.map +1 -0
  26. package/dist/criteria/filter-entry.d.ts +6 -0
  27. package/dist/criteria/filter-entry.d.ts.map +1 -0
  28. package/dist/criteria/filter-entry.js +2 -0
  29. package/dist/criteria/filter-entry.js.map +1 -0
  30. package/dist/criteria/parse-condition.d.ts +7 -0
  31. package/dist/criteria/parse-condition.d.ts.map +1 -0
  32. package/dist/criteria/parse-condition.js +52 -0
  33. package/dist/criteria/parse-condition.js.map +1 -0
  34. package/dist/criteria/parse-criteria-query.d.ts +5 -0
  35. package/dist/criteria/parse-criteria-query.d.ts.map +1 -0
  36. package/dist/criteria/parse-criteria-query.js +31 -0
  37. package/dist/criteria/parse-criteria-query.js.map +1 -0
  38. package/dist/criteria/parse-filters.d.ts +15 -0
  39. package/dist/criteria/parse-filters.d.ts.map +1 -0
  40. package/dist/criteria/parse-filters.js +52 -0
  41. package/dist/criteria/parse-filters.js.map +1 -0
  42. package/dist/criteria/sortable-fields.d.ts +4 -0
  43. package/dist/criteria/sortable-fields.d.ts.map +1 -0
  44. package/dist/criteria/sortable-fields.js +6 -0
  45. package/dist/criteria/sortable-fields.js.map +1 -0
  46. package/dist/criteria/split-list.d.ts +3 -0
  47. package/dist/criteria/split-list.d.ts.map +1 -0
  48. package/dist/criteria/split-list.js +19 -0
  49. package/dist/criteria/split-list.js.map +1 -0
  50. package/dist/docs/docs-page.d.ts +11 -0
  51. package/dist/docs/docs-page.d.ts.map +1 -0
  52. package/dist/docs/docs-page.js +18 -0
  53. package/dist/docs/docs-page.js.map +1 -0
  54. package/dist/docs/docs-ui.d.ts +2 -0
  55. package/dist/docs/docs-ui.d.ts.map +1 -0
  56. package/dist/docs/docs-ui.js +2 -0
  57. package/dist/docs/docs-ui.js.map +1 -0
  58. package/dist/docs/open-api-docs-routes.d.ts +22 -0
  59. package/dist/docs/open-api-docs-routes.d.ts.map +1 -0
  60. package/dist/docs/open-api-docs-routes.js +54 -0
  61. package/dist/docs/open-api-docs-routes.js.map +1 -0
  62. package/dist/docs.d.ts +3 -0
  63. package/dist/docs.d.ts.map +1 -0
  64. package/dist/docs.js +2 -0
  65. package/dist/docs.js.map +1 -0
  66. package/dist/error/create-error-mapper.d.ts +10 -0
  67. package/dist/error/create-error-mapper.d.ts.map +1 -0
  68. package/dist/error/create-error-mapper.js +12 -0
  69. package/dist/error/create-error-mapper.js.map +1 -0
  70. package/dist/error/default-error-mapping.d.ts +3 -0
  71. package/dist/error/default-error-mapping.d.ts.map +1 -0
  72. package/dist/error/default-error-mapping.js +9 -0
  73. package/dist/error/default-error-mapping.js.map +1 -0
  74. package/dist/error/error-mapper.d.ts +12 -0
  75. package/dist/error/error-mapper.d.ts.map +1 -0
  76. package/dist/error/error-mapper.js +8 -0
  77. package/dist/error/error-mapper.js.map +1 -0
  78. package/dist/error/error-mapping.d.ts +3 -0
  79. package/dist/error/error-mapping.d.ts.map +1 -0
  80. package/dist/error/error-mapping.js +2 -0
  81. package/dist/error/error-mapping.js.map +1 -0
  82. package/dist/error/forbidden-error.d.ts +5 -0
  83. package/dist/error/forbidden-error.d.ts.map +1 -0
  84. package/dist/error/forbidden-error.js +5 -0
  85. package/dist/error/forbidden-error.js.map +1 -0
  86. package/dist/error/internal-error-code.d.ts +2 -0
  87. package/dist/error/internal-error-code.d.ts.map +1 -0
  88. package/dist/error/internal-error-code.js +2 -0
  89. package/dist/error/internal-error-code.js.map +1 -0
  90. package/dist/error/problem.d.ts +11 -0
  91. package/dist/error/problem.d.ts.map +1 -0
  92. package/dist/error/problem.js +2 -0
  93. package/dist/error/problem.js.map +1 -0
  94. package/dist/error/response-contract-error.d.ts +7 -0
  95. package/dist/error/response-contract-error.d.ts.map +1 -0
  96. package/dist/error/response-contract-error.js +10 -0
  97. package/dist/error/response-contract-error.js.map +1 -0
  98. package/dist/error/status-title.d.ts +2 -0
  99. package/dist/error/status-title.d.ts.map +1 -0
  100. package/dist/error/status-title.js +28 -0
  101. package/dist/error/status-title.js.map +1 -0
  102. package/dist/error/to-problem.d.ts +4 -0
  103. package/dist/error/to-problem.d.ts.map +1 -0
  104. package/dist/error/to-problem.js +34 -0
  105. package/dist/error/to-problem.js.map +1 -0
  106. package/dist/error/unauthorized-error.d.ts +5 -0
  107. package/dist/error/unauthorized-error.d.ts.map +1 -0
  108. package/dist/error/unauthorized-error.js +5 -0
  109. package/dist/error/unauthorized-error.js.map +1 -0
  110. package/dist/express/mount-express.d.ts +10 -0
  111. package/dist/express/mount-express.d.ts.map +1 -0
  112. package/dist/express/mount-express.js +38 -0
  113. package/dist/express/mount-express.js.map +1 -0
  114. package/dist/express.d.ts +2 -0
  115. package/dist/express.d.ts.map +1 -0
  116. package/dist/express.js +2 -0
  117. package/dist/express.js.map +1 -0
  118. package/dist/fastify/fastify-mount-options.d.ts +3 -0
  119. package/dist/fastify/fastify-mount-options.d.ts.map +1 -0
  120. package/dist/fastify/fastify-mount-options.js +2 -0
  121. package/dist/fastify/fastify-mount-options.js.map +1 -0
  122. package/dist/fastify/fastify-routes.d.ts +6 -0
  123. package/dist/fastify/fastify-routes.d.ts.map +1 -0
  124. package/dist/fastify/fastify-routes.js +10 -0
  125. package/dist/fastify/fastify-routes.js.map +1 -0
  126. package/dist/fastify/mount-fastify.d.ts +6 -0
  127. package/dist/fastify/mount-fastify.d.ts.map +1 -0
  128. package/dist/fastify/mount-fastify.js +19 -0
  129. package/dist/fastify/mount-fastify.js.map +1 -0
  130. package/dist/fastify.d.ts +4 -0
  131. package/dist/fastify.d.ts.map +1 -0
  132. package/dist/fastify.js +3 -0
  133. package/dist/fastify.js.map +1 -0
  134. package/dist/index.d.ts +50 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +27 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/nest/create-routes-module.d.ts +15 -0
  139. package/dist/nest/create-routes-module.d.ts.map +1 -0
  140. package/dist/nest/create-routes-module.js +54 -0
  141. package/dist/nest/create-routes-module.js.map +1 -0
  142. package/dist/nest/routes-factory.d.ts +8 -0
  143. package/dist/nest/routes-factory.d.ts.map +1 -0
  144. package/dist/nest/routes-factory.js +2 -0
  145. package/dist/nest/routes-factory.js.map +1 -0
  146. package/dist/nest/routes-mounter.d.ts +9 -0
  147. package/dist/nest/routes-mounter.d.ts.map +1 -0
  148. package/dist/nest/routes-mounter.js +8 -0
  149. package/dist/nest/routes-mounter.js.map +1 -0
  150. package/dist/nest.d.ts +4 -0
  151. package/dist/nest.d.ts.map +1 -0
  152. package/dist/nest.js +3 -0
  153. package/dist/nest.js.map +1 -0
  154. package/dist/openapi/check-open-api-drift.d.ts +6 -0
  155. package/dist/openapi/check-open-api-drift.d.ts.map +1 -0
  156. package/dist/openapi/check-open-api-drift.js +6 -0
  157. package/dist/openapi/check-open-api-drift.js.map +1 -0
  158. package/dist/openapi/compare.d.ts +3 -0
  159. package/dist/openapi/compare.d.ts.map +1 -0
  160. package/dist/openapi/compare.js +5 -0
  161. package/dist/openapi/compare.js.map +1 -0
  162. package/dist/openapi/definitions.d.ts +14 -0
  163. package/dist/openapi/definitions.d.ts.map +1 -0
  164. package/dist/openapi/definitions.js +61 -0
  165. package/dist/openapi/definitions.js.map +1 -0
  166. package/dist/openapi/generate-open-api.d.ts +21 -0
  167. package/dist/openapi/generate-open-api.d.ts.map +1 -0
  168. package/dist/openapi/generate-open-api.js +43 -0
  169. package/dist/openapi/generate-open-api.js.map +1 -0
  170. package/dist/openapi/open-api-document.d.ts +18 -0
  171. package/dist/openapi/open-api-document.d.ts.map +1 -0
  172. package/dist/openapi/open-api-document.js +2 -0
  173. package/dist/openapi/open-api-document.js.map +1 -0
  174. package/dist/openapi/open-api-info.d.ts +6 -0
  175. package/dist/openapi/open-api-info.d.ts.map +1 -0
  176. package/dist/openapi/open-api-info.js +2 -0
  177. package/dist/openapi/open-api-info.js.map +1 -0
  178. package/dist/openapi/open-api-path.d.ts +2 -0
  179. package/dist/openapi/open-api-path.d.ts.map +1 -0
  180. package/dist/openapi/open-api-path.js +4 -0
  181. package/dist/openapi/open-api-path.js.map +1 -0
  182. package/dist/openapi/open-api-server.d.ts +5 -0
  183. package/dist/openapi/open-api-server.d.ts.map +1 -0
  184. package/dist/openapi/open-api-server.js +2 -0
  185. package/dist/openapi/open-api-server.js.map +1 -0
  186. package/dist/openapi/path-items.d.ts +7 -0
  187. package/dist/openapi/path-items.d.ts.map +1 -0
  188. package/dist/openapi/path-items.js +43 -0
  189. package/dist/openapi/path-items.js.map +1 -0
  190. package/dist/openapi/path-parameters.d.ts +4 -0
  191. package/dist/openapi/path-parameters.d.ts.map +1 -0
  192. package/dist/openapi/path-parameters.js +13 -0
  193. package/dist/openapi/path-parameters.js.map +1 -0
  194. package/dist/openapi/problem-schema.d.ts +3 -0
  195. package/dist/openapi/problem-schema.d.ts.map +1 -0
  196. package/dist/openapi/problem-schema.js +27 -0
  197. package/dist/openapi/problem-schema.js.map +1 -0
  198. package/dist/openapi/requirement.d.ts +3 -0
  199. package/dist/openapi/requirement.d.ts.map +1 -0
  200. package/dist/openapi/requirement.js +5 -0
  201. package/dist/openapi/requirement.js.map +1 -0
  202. package/dist/openapi/responses.d.ts +7 -0
  203. package/dist/openapi/responses.d.ts.map +1 -0
  204. package/dist/openapi/responses.js +50 -0
  205. package/dist/openapi/responses.js.map +1 -0
  206. package/dist/openapi/schema-parameters.d.ts +5 -0
  207. package/dist/openapi/schema-parameters.d.ts.map +1 -0
  208. package/dist/openapi/schema-parameters.js +24 -0
  209. package/dist/openapi/schema-parameters.js.map +1 -0
  210. package/dist/openapi/stringify-open-api.d.ts +4 -0
  211. package/dist/openapi/stringify-open-api.d.ts.map +1 -0
  212. package/dist/openapi/stringify-open-api.js +5 -0
  213. package/dist/openapi/stringify-open-api.js.map +1 -0
  214. package/dist/openapi.d.ts +7 -0
  215. package/dist/openapi.d.ts.map +1 -0
  216. package/dist/openapi.js +4 -0
  217. package/dist/openapi.js.map +1 -0
  218. package/dist/pagination/issue.d.ts +3 -0
  219. package/dist/pagination/issue.d.ts.map +1 -0
  220. package/dist/pagination/issue.js +4 -0
  221. package/dist/pagination/issue.js.map +1 -0
  222. package/dist/pagination/limits-of.d.ts +3 -0
  223. package/dist/pagination/limits-of.d.ts.map +1 -0
  224. package/dist/pagination/limits-of.js +8 -0
  225. package/dist/pagination/limits-of.js.map +1 -0
  226. package/dist/pagination/page-body.d.ts +7 -0
  227. package/dist/pagination/page-body.d.ts.map +1 -0
  228. package/dist/pagination/page-body.js +2 -0
  229. package/dist/pagination/page-body.js.map +1 -0
  230. package/dist/pagination/page-query-options.d.ts +8 -0
  231. package/dist/pagination/page-query-options.d.ts.map +1 -0
  232. package/dist/pagination/page-query-options.js +2 -0
  233. package/dist/pagination/page-query-options.js.map +1 -0
  234. package/dist/pagination/page-query-schema.d.ts +6 -0
  235. package/dist/pagination/page-query-schema.d.ts.map +1 -0
  236. package/dist/pagination/page-query-schema.js +8 -0
  237. package/dist/pagination/page-query-schema.js.map +1 -0
  238. package/dist/pagination/page-request-from.d.ts +9 -0
  239. package/dist/pagination/page-request-from.d.ts.map +1 -0
  240. package/dist/pagination/page-request-from.js +16 -0
  241. package/dist/pagination/page-request-from.js.map +1 -0
  242. package/dist/pagination/page-request-parameters.d.ts +9 -0
  243. package/dist/pagination/page-request-parameters.d.ts.map +1 -0
  244. package/dist/pagination/page-request-parameters.js +30 -0
  245. package/dist/pagination/page-request-parameters.js.map +1 -0
  246. package/dist/pagination/page-response.d.ts +5 -0
  247. package/dist/pagination/page-response.d.ts.map +1 -0
  248. package/dist/pagination/page-response.js +9 -0
  249. package/dist/pagination/page-response.js.map +1 -0
  250. package/dist/pagination/page-schema-of.d.ts +9 -0
  251. package/dist/pagination/page-schema-of.d.ts.map +1 -0
  252. package/dist/pagination/page-schema-of.js +60 -0
  253. package/dist/pagination/page-schema-of.js.map +1 -0
  254. package/dist/pagination/parse-page-query.d.ts +5 -0
  255. package/dist/pagination/parse-page-query.d.ts.map +1 -0
  256. package/dist/pagination/parse-page-query.js +108 -0
  257. package/dist/pagination/parse-page-query.js.map +1 -0
  258. package/dist/pipeline/assert-declared-response.d.ts +4 -0
  259. package/dist/pipeline/assert-declared-response.d.ts.map +1 -0
  260. package/dist/pipeline/assert-declared-response.js +18 -0
  261. package/dist/pipeline/assert-declared-response.js.map +1 -0
  262. package/dist/pipeline/correlation-header.d.ts +2 -0
  263. package/dist/pipeline/correlation-header.d.ts.map +1 -0
  264. package/dist/pipeline/correlation-header.js +2 -0
  265. package/dist/pipeline/correlation-header.js.map +1 -0
  266. package/dist/pipeline/correlation-id-of.d.ts +4 -0
  267. package/dist/pipeline/correlation-id-of.d.ts.map +1 -0
  268. package/dist/pipeline/correlation-id-of.js +7 -0
  269. package/dist/pipeline/correlation-id-of.js.map +1 -0
  270. package/dist/pipeline/error-context.d.ts +15 -0
  271. package/dist/pipeline/error-context.d.ts.map +1 -0
  272. package/dist/pipeline/error-context.js +2 -0
  273. package/dist/pipeline/error-context.js.map +1 -0
  274. package/dist/pipeline/execute-options.d.ts +40 -0
  275. package/dist/pipeline/execute-options.d.ts.map +1 -0
  276. package/dist/pipeline/execute-options.js +2 -0
  277. package/dist/pipeline/execute-options.js.map +1 -0
  278. package/dist/pipeline/execute-route.d.ts +6 -0
  279. package/dist/pipeline/execute-route.d.ts.map +1 -0
  280. package/dist/pipeline/execute-route.js +108 -0
  281. package/dist/pipeline/execute-route.js.map +1 -0
  282. package/dist/pipeline/execution-of-request.d.ts +16 -0
  283. package/dist/pipeline/execution-of-request.d.ts.map +1 -0
  284. package/dist/pipeline/execution-of-request.js +44 -0
  285. package/dist/pipeline/execution-of-request.js.map +1 -0
  286. package/dist/pipeline/raw-request.d.ts +10 -0
  287. package/dist/pipeline/raw-request.d.ts.map +1 -0
  288. package/dist/pipeline/raw-request.js +2 -0
  289. package/dist/pipeline/raw-request.js.map +1 -0
  290. package/dist/pipeline/report-http-errors.d.ts +11 -0
  291. package/dist/pipeline/report-http-errors.d.ts.map +1 -0
  292. package/dist/pipeline/report-http-errors.js +17 -0
  293. package/dist/pipeline/report-http-errors.js.map +1 -0
  294. package/dist/pipeline/route-around.d.ts +5 -0
  295. package/dist/pipeline/route-around.d.ts.map +1 -0
  296. package/dist/pipeline/route-around.js +2 -0
  297. package/dist/pipeline/route-around.js.map +1 -0
  298. package/dist/pipeline/route-response.d.ts +7 -0
  299. package/dist/pipeline/route-response.d.ts.map +1 -0
  300. package/dist/pipeline/route-response.js +2 -0
  301. package/dist/pipeline/route-response.js.map +1 -0
  302. package/dist/pipeline/serialize-body.d.ts +7 -0
  303. package/dist/pipeline/serialize-body.d.ts.map +1 -0
  304. package/dist/pipeline/serialize-body.js +16 -0
  305. package/dist/pipeline/serialize-body.js.map +1 -0
  306. package/dist/pipeline/validate-request.d.ts +8 -0
  307. package/dist/pipeline/validate-request.d.ts.map +1 -0
  308. package/dist/pipeline/validate-request.js +30 -0
  309. package/dist/pipeline/validate-request.js.map +1 -0
  310. package/dist/pipeline/well-formed-identifier.d.ts +3 -0
  311. package/dist/pipeline/well-formed-identifier.d.ts.map +1 -0
  312. package/dist/pipeline/well-formed-identifier.js +6 -0
  313. package/dist/pipeline/well-formed-identifier.js.map +1 -0
  314. package/dist/route/assert-unique-routes.d.ts +3 -0
  315. package/dist/route/assert-unique-routes.d.ts.map +1 -0
  316. package/dist/route/assert-unique-routes.js +22 -0
  317. package/dist/route/assert-unique-routes.js.map +1 -0
  318. package/dist/route/define-route.d.ts +7 -0
  319. package/dist/route/define-route.d.ts.map +1 -0
  320. package/dist/route/define-route.js +17 -0
  321. package/dist/route/define-route.js.map +1 -0
  322. package/dist/route/define-routes.d.ts +4 -0
  323. package/dist/route/define-routes.d.ts.map +1 -0
  324. package/dist/route/define-routes.js +11 -0
  325. package/dist/route/define-routes.js.map +1 -0
  326. package/dist/route/duplicate-route-error.d.ts +4 -0
  327. package/dist/route/duplicate-route-error.d.ts.map +1 -0
  328. package/dist/route/duplicate-route-error.js +7 -0
  329. package/dist/route/duplicate-route-error.js.map +1 -0
  330. package/dist/route/handler-input.d.ts +23 -0
  331. package/dist/route/handler-input.d.ts.map +1 -0
  332. package/dist/route/handler-input.js +2 -0
  333. package/dist/route/handler-input.js.map +1 -0
  334. package/dist/route/handler-result.d.ts +20 -0
  335. package/dist/route/handler-result.d.ts.map +1 -0
  336. package/dist/route/handler-result.js +2 -0
  337. package/dist/route/handler-result.js.map +1 -0
  338. package/dist/route/http-method.d.ts +2 -0
  339. package/dist/route/http-method.d.ts.map +1 -0
  340. package/dist/route/http-method.js +2 -0
  341. package/dist/route/http-method.js.map +1 -0
  342. package/dist/route/prefix-routes.d.ts +4 -0
  343. package/dist/route/prefix-routes.d.ts.map +1 -0
  344. package/dist/route/prefix-routes.js +10 -0
  345. package/dist/route/prefix-routes.js.map +1 -0
  346. package/dist/route/raw-headers.d.ts +2 -0
  347. package/dist/route/raw-headers.d.ts.map +1 -0
  348. package/dist/route/raw-headers.js +2 -0
  349. package/dist/route/raw-headers.js.map +1 -0
  350. package/dist/route/request-context.d.ts +13 -0
  351. package/dist/route/request-context.d.ts.map +1 -0
  352. package/dist/route/request-context.js +2 -0
  353. package/dist/route/request-context.js.map +1 -0
  354. package/dist/route/request-schemas.d.ts +8 -0
  355. package/dist/route/request-schemas.d.ts.map +1 -0
  356. package/dist/route/request-schemas.js +2 -0
  357. package/dist/route/request-schemas.js.map +1 -0
  358. package/dist/route/response-spec.d.ts +6 -0
  359. package/dist/route/response-spec.d.ts.map +1 -0
  360. package/dist/route/response-spec.js +2 -0
  361. package/dist/route/response-spec.js.map +1 -0
  362. package/dist/route/responses-spec.d.ts +5 -0
  363. package/dist/route/responses-spec.d.ts.map +1 -0
  364. package/dist/route/responses-spec.js +2 -0
  365. package/dist/route/responses-spec.js.map +1 -0
  366. package/dist/route/route-handler.d.ts +6 -0
  367. package/dist/route/route-handler.d.ts.map +1 -0
  368. package/dist/route/route-handler.js +2 -0
  369. package/dist/route/route-handler.js.map +1 -0
  370. package/dist/route/route-input.d.ts +10 -0
  371. package/dist/route/route-input.d.ts.map +1 -0
  372. package/dist/route/route-input.js +2 -0
  373. package/dist/route/route-input.js.map +1 -0
  374. package/dist/route/route-output.d.ts +6 -0
  375. package/dist/route/route-output.d.ts.map +1 -0
  376. package/dist/route/route-output.js +2 -0
  377. package/dist/route/route-output.js.map +1 -0
  378. package/dist/route/route-spec.d.ts +23 -0
  379. package/dist/route/route-spec.d.ts.map +1 -0
  380. package/dist/route/route-spec.js +2 -0
  381. package/dist/route/route-spec.js.map +1 -0
  382. package/dist/route/route.d.ts +11 -0
  383. package/dist/route/route.d.ts.map +1 -0
  384. package/dist/route/route.js +2 -0
  385. package/dist/route/route.js.map +1 -0
  386. package/dist/route/without-trailing-slashes.d.ts +3 -0
  387. package/dist/route/without-trailing-slashes.d.ts.map +1 -0
  388. package/dist/route/without-trailing-slashes.js +9 -0
  389. package/dist/route/without-trailing-slashes.js.map +1 -0
  390. package/dist/support/is-record.d.ts +2 -0
  391. package/dist/support/is-record.d.ts.map +1 -0
  392. package/dist/support/is-record.js +4 -0
  393. package/dist/support/is-record.js.map +1 -0
  394. package/package.json +82 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.js","sourceRoot":"","sources":["../../src/pagination/issue.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,IAAY,EAAE,OAAe;IAC/D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type PageLimits } from '@ddd-ts-kit/kernel';
2
+ export declare function limitsOf(options: Partial<PageLimits>): PageLimits;
3
+ //# sourceMappingURL=limits-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits-of.d.ts","sourceRoot":"","sources":["../../src/pagination/limits-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAKjE"}
@@ -0,0 +1,8 @@
1
+ import { DEFAULT_PAGE_LIMITS } from '@ddd-ts-kit/kernel';
2
+ export function limitsOf(options) {
3
+ return {
4
+ defaultSize: options.defaultSize ?? DEFAULT_PAGE_LIMITS.defaultSize,
5
+ maxSize: options.maxSize ?? DEFAULT_PAGE_LIMITS.maxSize,
6
+ };
7
+ }
8
+ //# sourceMappingURL=limits-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits-of.js","sourceRoot":"","sources":["../../src/pagination/limits-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,oBAAoB,CAAC;AAE1E,MAAM,UAAU,QAAQ,CAAC,OAA4B;IACnD,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAAC,WAAW;QACnE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAAC,OAAO;KACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** A page as a JSON body: the kernel `Page`, with a mutable list as schemas infer it. */
2
+ export interface PageBody<T> {
3
+ items: T[];
4
+ total?: number;
5
+ nextCursor?: string;
6
+ }
7
+ //# sourceMappingURL=page-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-body.d.ts","sourceRoot":"","sources":["../../src/pagination/page-body.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=page-body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-body.js","sourceRoot":"","sources":["../../src/pagination/page-body.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { PageLimits, PageRequest } from '@ddd-ts-kit/kernel';
2
+ export interface PageQueryOptions<Field extends string = never> extends Partial<PageLimits> {
3
+ /** The closed list of fields a client may sort by. Without it, a `sort` parameter is refused. */
4
+ readonly sortable?: readonly Field[];
5
+ /** The variant of a query that names neither `offset` nor `cursor`. Default `offset`. */
6
+ readonly kind?: PageRequest['kind'];
7
+ }
8
+ //# sourceMappingURL=page-query-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query-options.d.ts","sourceRoot":"","sources":["../../src/pagination/page-query-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,CAAE,SAAQ,OAAO,CAAC,UAAU,CAAC;IACzF,iGAAiG;IACjG,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IACrC,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=page-query-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query-options.js","sourceRoot":"","sources":["../../src/pagination/page-query-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { PageRequest } from '@ddd-ts-kit/kernel';
2
+ import { type Schema } from '@ddd-ts-kit/validation';
3
+ import type { PageQueryOptions } from './page-query-options.js';
4
+ /** The same reading as a `Schema`, for a route whose whole query is the page: `request: { query }`. */
5
+ export declare function pageQuerySchema<Field extends string = never>(options?: PageQueryOptions<Field>): Schema<PageRequest<Field>>;
6
+ //# sourceMappingURL=page-query-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query-schema.d.ts","sourceRoot":"","sources":["../../src/pagination/page-query-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,EAC1D,OAAO,GAAE,gBAAgB,CAAC,KAAK,CAAM,GACpC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAE5B"}
@@ -0,0 +1,8 @@
1
+ import { customSchema } from '@ddd-ts-kit/validation';
2
+ import { pageRequestParameters } from './page-request-parameters.js';
3
+ import { parsePageQuery } from './parse-page-query.js';
4
+ /** The same reading as a `Schema`, for a route whose whole query is the page: `request: { query }`. */
5
+ export function pageQuerySchema(options = {}) {
6
+ return customSchema((query) => parsePageQuery(query, options), pageRequestParameters(options));
7
+ }
8
+ //# sourceMappingURL=page-query-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query-schema.js","sourceRoot":"","sources":["../../src/pagination/page-query-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,uGAAuG;AACvG,MAAM,UAAU,eAAe,CAC7B,OAAO,GAA4B,EAAE;IAErC,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { PageRequest } from '@ddd-ts-kit/kernel';
2
+ import type { PageQueryOptions } from './page-query-options.js';
3
+ /**
4
+ * Reads `limit`, `offset`, `cursor` and `sort` (`placedAt,-total`: a leading `-` is
5
+ * descending) from a query, as strings or already coerced. Throws the `ValidationError` of the
6
+ * pipeline, so a wrong parameter is answered 422 with one issue per parameter.
7
+ */
8
+ export declare function pageRequestFrom<Field extends string = never>(query: unknown, options?: PageQueryOptions<Field>): PageRequest<Field>;
9
+ //# sourceMappingURL=page-request-from.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-request-from.d.ts","sourceRoot":"","sources":["../../src/pagination/page-request-from.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,EAC1D,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,gBAAgB,CAAC,KAAK,CAAM,GACpC,WAAW,CAAC,KAAK,CAAC,CAUpB"}
@@ -0,0 +1,16 @@
1
+ import { ValidationError } from '@ddd-ts-kit/validation';
2
+ import { parsePageQuery } from './parse-page-query.js';
3
+ /**
4
+ * Reads `limit`, `offset`, `cursor` and `sort` (`placedAt,-total`: a leading `-` is
5
+ * descending) from a query, as strings or already coerced. Throws the `ValidationError` of the
6
+ * pipeline, so a wrong parameter is answered 422 with one issue per parameter.
7
+ */
8
+ export function pageRequestFrom(query, options = {}) {
9
+ const parsed = parsePageQuery(query, options);
10
+ if (parsed.ok) {
11
+ return parsed.value;
12
+ }
13
+ const issues = parsed.error.map((issue) => ({ ...issue, path: `query.${issue.path}` }));
14
+ throw new ValidationError(issues, 'The request is not valid.');
15
+ }
16
+ //# sourceMappingURL=page-request-from.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-request-from.js","sourceRoot":"","sources":["../../src/pagination/page-request-from.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,OAAO,GAA4B,EAAE;IAErC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAE9C,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAExF,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { JsonSchema } from '@ddd-ts-kit/validation';
2
+ import type { PageQueryOptions } from './page-query-options.js';
3
+ /**
4
+ * The query parameters of a page as a JSON Schema object: one OpenAPI parameter per property
5
+ * once it is the `toJsonSchema()` of a query schema. Merge `properties` into a wider schema
6
+ * when the route has filters too.
7
+ */
8
+ export declare function pageRequestParameters(options?: PageQueryOptions<string>): JsonSchema;
9
+ //# sourceMappingURL=page-request-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-request-parameters.d.ts","sourceRoot":"","sources":["../../src/pagination/page-request-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,gBAAgB,CAAC,MAAM,CAAM,GAAG,UAAU,CAiBxF"}
@@ -0,0 +1,30 @@
1
+ import { limitsOf } from './limits-of.js';
2
+ /**
3
+ * The query parameters of a page as a JSON Schema object: one OpenAPI parameter per property
4
+ * once it is the `toJsonSchema()` of a query schema. Merge `properties` into a wider schema
5
+ * when the route has filters too.
6
+ */
7
+ export function pageRequestParameters(options = {}) {
8
+ const { defaultSize, maxSize } = limitsOf(options);
9
+ const sortable = options.sortable ?? [];
10
+ return {
11
+ type: 'object',
12
+ properties: {
13
+ limit: { type: 'integer', minimum: 1, maximum: maxSize, default: defaultSize, description: 'Size of the page.' },
14
+ offset: { type: 'integer', minimum: 0, description: 'Items to skip. Not with `cursor`.' },
15
+ cursor: {
16
+ type: 'string',
17
+ minLength: 1,
18
+ description: 'The `nextCursor` of the previous page. Not with `offset`.',
19
+ },
20
+ ...(sortable.length === 0 ? {} : { sort: sortParameter(sortable) }),
21
+ },
22
+ };
23
+ }
24
+ function sortParameter(sortable) {
25
+ return {
26
+ type: 'string',
27
+ description: `Comma-separated fields, a leading "-" for descending. Sortable: ${sortable.join(', ')}.`,
28
+ };
29
+ }
30
+ //# sourceMappingURL=page-request-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-request-parameters.js","sourceRoot":"","sources":["../../src/pagination/page-request-parameters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAO,GAA6B,EAAE;IAC1E,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE;YAChH,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE;YACzF,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,CAAC;gBACZ,WAAW,EAAE,2DAA2D;aACzE;YACD,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;SACpE;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,QAA2B;IAChD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,mEAAmE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;KACvG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Page } from '@ddd-ts-kit/kernel';
2
+ import type { PageBody } from './page-body.js';
3
+ /** The body of a search answer: the items through `map`, `total` and `nextCursor` when the page has them. */
4
+ export declare function pageResponse<T, U>(page: Page<T>, map: (item: T) => U): PageBody<U>;
5
+ //# sourceMappingURL=page-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-response.d.ts","sourceRoot":"","sources":["../../src/pagination/page-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,6GAA6G;AAC7G,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAMlF"}
@@ -0,0 +1,9 @@
1
+ /** The body of a search answer: the items through `map`, `total` and `nextCursor` when the page has them. */
2
+ export function pageResponse(page, map) {
3
+ return {
4
+ items: page.items.map(map),
5
+ ...(page.total === undefined ? {} : { total: page.total }),
6
+ ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
7
+ };
8
+ }
9
+ //# sourceMappingURL=page-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-response.js","sourceRoot":"","sources":["../../src/pagination/page-response.ts"],"names":[],"mappings":"AAGA,6GAA6G;AAC7G,MAAM,UAAU,YAAY,CAAO,IAAa,EAAE,GAAmB;IACnE,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;QAC1B,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1D,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type Schema } from '@ddd-ts-kit/validation';
2
+ import type { PageBody } from './page-body.js';
3
+ /**
4
+ * The schema of a page of items, from the schema of one item: validates the envelope and each
5
+ * item, and describes both in the contract. Local `$defs` of the item schema move to the top,
6
+ * where the OpenAPI generator collects them.
7
+ */
8
+ export declare function pageSchemaOf<T>(item: Schema<T>): Schema<PageBody<T>>;
9
+ //# sourceMappingURL=page-schema-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-schema-of.d.ts","sourceRoot":"","sources":["../../src/pagination/page-schema-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,MAAM,EAAwB,MAAM,wBAAwB,CAAC;AAG1G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEpE"}
@@ -0,0 +1,60 @@
1
+ import { err, ok } from '@ddd-ts-kit/kernel';
2
+ import { customSchema } from '@ddd-ts-kit/validation';
3
+ import { isRecord } from '../support/is-record.js';
4
+ import { issue } from './issue.js';
5
+ /**
6
+ * The schema of a page of items, from the schema of one item: validates the envelope and each
7
+ * item, and describes both in the contract. Local `$defs` of the item schema move to the top,
8
+ * where the OpenAPI generator collects them.
9
+ */
10
+ export function pageSchemaOf(item) {
11
+ return customSchema((input) => parsePageBody(input, item), pageJsonSchema(item.toJsonSchema()));
12
+ }
13
+ function parsePageBody(input, item) {
14
+ if (!isRecord(input) || !Array.isArray(input['items'])) {
15
+ return err([issue('items', 'invalid_page', 'A page has a list of items.')]);
16
+ }
17
+ const issues = [];
18
+ const items = itemsOf(input['items'], item, issues);
19
+ const more = moreOf(input, issues);
20
+ return issues.length > 0 ? err(issues) : ok({ items, ...more });
21
+ }
22
+ function itemsOf(inputs, item, issues) {
23
+ return inputs.flatMap((input, index) => {
24
+ const parsed = item.parse(input);
25
+ if (parsed.ok) {
26
+ return [parsed.value];
27
+ }
28
+ for (const found of parsed.error) {
29
+ const path = found.path === '' ? `items.${String(index)}` : `items.${String(index)}.${found.path}`;
30
+ issues.push({ ...found, path });
31
+ }
32
+ return [];
33
+ });
34
+ }
35
+ function moreOf(input, issues) {
36
+ const { total, nextCursor } = input;
37
+ const counted = typeof total === 'number' && Number.isSafeInteger(total) && total >= 0;
38
+ if (total !== undefined && !counted) {
39
+ issues.push(issue('total', 'invalid_page', 'Must be a non-negative integer.'));
40
+ }
41
+ if (nextCursor !== undefined && typeof nextCursor !== 'string') {
42
+ issues.push(issue('nextCursor', 'invalid_page', 'Must be a string.'));
43
+ }
44
+ return { ...(counted ? { total } : {}), ...(typeof nextCursor === 'string' ? { nextCursor } : {}) };
45
+ }
46
+ function pageJsonSchema(itemSchema) {
47
+ const { $schema: _dialect, $defs, definitions, ...item } = itemSchema;
48
+ return {
49
+ type: 'object',
50
+ required: ['items'],
51
+ properties: {
52
+ items: { type: 'array', items: item },
53
+ total: { type: 'integer', minimum: 0, description: 'Present when it is cheap to count.' },
54
+ nextCursor: { type: 'string', description: 'Present when more items follow.' },
55
+ },
56
+ ...($defs === undefined ? {} : { $defs }),
57
+ ...(definitions === undefined ? {} : { definitions }),
58
+ };
59
+ }
60
+ //# sourceMappingURL=page-schema-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-schema-of.js","sourceRoot":"","sources":["../../src/p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,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACtG,CAAC;AAED,SAAS,cAAc,CAAC,UAAsB;IAC5C,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,UAAU,CAAC;IAEtE,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,OAAO,CAAC;QACnB,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;YACrC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE;YACzF,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iCAAiC,EAAE;SAC/E;QACD,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QACzC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type PageRequest, type Result } from '@ddd-ts-kit/kernel';
2
+ import type { ValidationIssue } from '@ddd-ts-kit/validation';
3
+ import type { PageQueryOptions } from './page-query-options.js';
4
+ export declare function parsePageQuery<Field extends string>(input: unknown, options: PageQueryOptions<Field>): Result<PageRequest<Field>, ValidationIssue[]>;
5
+ //# sourceMappingURL=parse-page-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-page-query.d.ts","sourceRoot":"","sources":["../../src/pagination/parse-page-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAgBhE,wBAAgB,cAAc,CAAC,KAAK,SAAS,MAAM,EACjD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC/B,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC,CAoB/C"}
@@ -0,0 +1,108 @@
1
+ import { cursorPage, err, offsetPage, ok, } from '@ddd-ts-kit/kernel';
2
+ import { isRecord } from '../support/is-record.js';
3
+ import { issue } from './issue.js';
4
+ import { limitsOf } from './limits-of.js';
5
+ export function parsePageQuery(input, options) {
6
+ const reading = { query: isRecord(input) ? input : {}, issues: [] };
7
+ const limits = limitsOf(options);
8
+ const asked = {
9
+ limit: limitOf(reading, limits),
10
+ offset: offsetOf(reading),
11
+ cursor: cursorOf(reading),
12
+ sort: sortOf(reading, options.sortable ?? []),
13
+ };
14
+ if (asked.offset !== undefined && asked.cursor !== undefined) {
15
+ reading.issues.push(issue('cursor', 'offset_with_cursor', 'A page is asked by offset or by cursor, not both.'));
16
+ }
17
+ if (reading.issues.length > 0) {
18
+ return err(reading.issues);
19
+ }
20
+ return ok(options.kind === 'cursor' ? cursorFirst(asked, limits) : offsetFirst(asked, limits));
21
+ }
22
+ function limitOf({ query, issues }, limits) {
23
+ if (query['limit'] === undefined) {
24
+ return limits.defaultSize;
25
+ }
26
+ const limit = integerOf(query['limit']);
27
+ if (limit !== undefined && limit >= 1 && limit <= limits.maxSize) {
28
+ return limit;
29
+ }
30
+ issues.push(issue('limit', 'invalid_limit', `Must be an integer between 1 and ${String(limits.maxSize)}.`));
31
+ return limits.defaultSize;
32
+ }
33
+ function integerOf(value) {
34
+ const text = typeof value === 'number' ? String(value) : value;
35
+ if (typeof text !== 'string' || !/^\d{1,15}$/.test(text)) {
36
+ return undefined;
37
+ }
38
+ return Number(text);
39
+ }
40
+ function offsetOf({ query, issues }) {
41
+ if (query['offset'] === undefined) {
42
+ return undefined;
43
+ }
44
+ const offset = integerOf(query['offset']);
45
+ if (offset !== undefined && offset >= 0) {
46
+ return offset;
47
+ }
48
+ issues.push(issue('offset', 'invalid_offset', 'Must be a non-negative integer.'));
49
+ return undefined;
50
+ }
51
+ function cursorOf({ query, issues }) {
52
+ const cursor = query['cursor'];
53
+ if (cursor === undefined) {
54
+ return undefined;
55
+ }
56
+ if (typeof cursor === 'string' && cursor !== '') {
57
+ return cursor;
58
+ }
59
+ issues.push(issue('cursor', 'invalid_cursor', 'Must be the nextCursor of a previous page.'));
60
+ return undefined;
61
+ }
62
+ function sortOf({ query, issues }, sortable) {
63
+ const terms = sortTermsOf(query['sort']);
64
+ if (terms === undefined) {
65
+ issues.push(issue('sort', 'invalid_sort', 'Must be a comma-separated list of fields.'));
66
+ return [];
67
+ }
68
+ return terms.flatMap((term) => {
69
+ const descending = term.startsWith('-');
70
+ const field = sortable.find((allowed) => allowed === (descending ? term.slice(1) : term));
71
+ if (field !== undefined) {
72
+ return [{ field, direction: descending ? 'desc' : 'asc' }];
73
+ }
74
+ issues.push(issue('sort', 'unsortable_field', `Sortable fields: ${sortable.join(', ') || 'none'}.`));
75
+ return [];
76
+ });
77
+ }
78
+ /** `sort=a,-b` and a repeated `sort=a&sort=-b` read the same. `undefined` for anything else. */
79
+ function sortTermsOf(sort) {
80
+ if (sort === undefined) {
81
+ return [];
82
+ }
83
+ const values = Array.isArray(sort) ? sort : [sort];
84
+ if (!values.every((value) => typeof value === 'string')) {
85
+ return undefined;
86
+ }
87
+ return values
88
+ .flatMap((value) => value.split(','))
89
+ .map((term) => term.trim())
90
+ .filter((term) => term !== '');
91
+ }
92
+ /** A cursor page unless the query names an offset. */
93
+ function cursorFirst(asked, limits) {
94
+ const { limit, sort, offset, cursor } = asked;
95
+ if (offset !== undefined) {
96
+ return offsetPage({ limit, sort, offset }, limits);
97
+ }
98
+ return cursorPage({ limit, sort, ...(cursor === undefined ? {} : { cursor }) }, limits);
99
+ }
100
+ /** An offset page unless the query names a cursor. */
101
+ function offsetFirst(asked, limits) {
102
+ const { limit, sort, offset, cursor } = asked;
103
+ if (cursor !== undefined) {
104
+ return cursorPage({ limit, sort, cursor }, limits);
105
+ }
106
+ return offsetPage({ limit, sort, ...(offset === undefined ? {} : { offset }) }, limits);
107
+ }
108
+ //# sourceMappingURL=parse-page-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-page-query.js","sourceRoot":"","sources":["../../src/pagination/parse-page-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,GAAG,EACH,UAAU,EACV,EAAE,GAKH,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAiB1C,MAAM,UAAU,cAAc,CAC5B,KAAc,EACd,OAAgC;IAEhC,MAAM,OAAO,GAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7E,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEjC,MAAM,KAAK,GAAiB;QAC1B,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;QAC/B,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;QACzB,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;KAC9C,CAAC;IAEF,IAAI,KAAK,CAAC,MAAM,KAAK,SAA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CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RouteOutput } from '../route/route-output.js';
2
+ import type { Route } from '../route/route.js';
3
+ export declare function assertDeclaredResponse(route: Route, { status, body }: RouteOutput): void;
4
+ //# sourceMappingURL=assert-declared-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-declared-response.d.ts","sourceRoot":"","sources":["../../src/pipeline/assert-declared-response.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,IAAI,CAyBxF"}
@@ -0,0 +1,18 @@
1
+ import { ResponseContractError } from '../error/response-contract-error.js';
2
+ export function assertDeclaredResponse(route, { status, body }) {
3
+ const declared = route.responses[status];
4
+ if (declared === undefined) {
5
+ throw new ResponseContractError(`Route "${route.operationId}" answered ${status}, which it does not declare.`);
6
+ }
7
+ if (declared.body === undefined) {
8
+ if (body !== undefined) {
9
+ throw new ResponseContractError(`Route "${route.operationId}" answered ${status} with a body, but declares none.`);
10
+ }
11
+ return;
12
+ }
13
+ const result = declared.body.parse(body);
14
+ if (!result.ok) {
15
+ throw new ResponseContractError(`Route "${route.operationId}" answered ${status} with a body that does not match its schema.`, result.error);
16
+ }
17
+ }
18
+ //# sourceMappingURL=assert-declared-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-declared-response.js","sourceRoot":"","sources":["../../src/pipeline/assert-declared-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAI5E,MAAM,UAAU,sBAAsB,CAAC,KAAY,EAAE,EAAE,MAAM,EAAE,IAAI,EAAe;IAChF,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,qBAAqB,CAAC,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,8BAA8B,CAAC,CAAC;IACjH,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,qBAAqB,CAC7B,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,kCAAkC,CAClF,CAAC;QACJ,CAAC;QAED,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,qBAAqB,CAC7B,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,8CAA8C,EAC7F,MAAM,CAAC,KAAK,CACb,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const CORRELATION_HEADER = "x-correlation-id";
2
+ //# sourceMappingURL=correlation-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlation-header.d.ts","sourceRoot":"","sources":["../../src/pipeline/correlation-header.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const CORRELATION_HEADER = 'x-correlation-id';
2
+ //# sourceMappingURL=correlation-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlation-header.js","sourceRoot":"","sources":["../../src/pipeline/correlation-header.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RawHeaders } from '../route/raw-headers.js';
2
+ /** The incoming `x-correlation-id` when it is well formed; otherwise the request starts the chain. */
3
+ export declare function correlationIdOf(headers: Readonly<RawHeaders>, requestId: string): string;
4
+ //# sourceMappingURL=correlation-id-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlation-id-of.d.ts","sourceRoot":"","sources":["../../src/pipeline/correlation-id-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAExF"}
@@ -0,0 +1,7 @@
1
+ import { CORRELATION_HEADER } from './correlation-header.js';
2
+ import { wellFormedIdentifier } from './well-formed-identifier.js';
3
+ /** The incoming `x-correlation-id` when it is well formed; otherwise the request starts the chain. */
4
+ export function correlationIdOf(headers, requestId) {
5
+ return wellFormedIdentifier(headers[CORRELATION_HEADER]) ?? requestId;
6
+ }
7
+ //# sourceMappingURL=correlation-id-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlation-id-of.js","sourceRoot":"","sources":["../../src/pipeline/correlation-id-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,sGAAsG;AACtG,MAAM,UAAU,eAAe,CAAC,OAA6B,EAAE,SAAiB;IAC9E,OAAO,oBAAoB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,SAAS,CAAC;AACxE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ExecutionContext } from '@ddd-ts-kit/kernel';
2
+ import type { Problem } from '../error/problem.js';
3
+ import type { HttpMethod } from '../route/http-method.js';
4
+ export interface ErrorContext {
5
+ readonly requestId: string;
6
+ readonly correlationId: string;
7
+ readonly operationId: string;
8
+ readonly method: HttpMethod;
9
+ readonly path: string;
10
+ /** The response the client receives for this error. */
11
+ readonly problem: Problem;
12
+ /** The execution context of the request, when the failure happened after it was built: not for a refused credential or an invalid request. */
13
+ readonly execution?: ExecutionContext;
14
+ }
15
+ //# sourceMappingURL=error-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-context.d.ts","sourceRoot":"","sources":["../../src/pipeline/error-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,8IAA8I;IAC9I,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=error-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-context.js","sourceRoot":"","sources":["../../src/pipeline/error-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import type { Clock, ExecutionScope } from '@ddd-ts-kit/kernel';
2
+ import type { ErrorMapper } from '../error/error-mapper.js';
3
+ import type { ErrorContext } from './error-context.js';
4
+ import type { RawRequest } from './raw-request.js';
5
+ import type { RouteAround } from './route-around.js';
6
+ export interface ExecuteOptions {
7
+ readonly errorMapper?: ErrorMapper;
8
+ /** Authenticates the request; throw `UnauthorizedError` to refuse it. */
9
+ readonly resolvePrincipal?: (raw: unknown) => unknown;
10
+ /**
11
+ * Runs every handler inside a scope that knows the principal, typically an ambient actor
12
+ * context, so that no route can forget to open it.
13
+ */
14
+ readonly withPrincipal?: <T>(principal: unknown, work: () => Promise<T>) => Promise<T>;
15
+ /** Called for every error answered as a problem, expected or not. Meant for logging. */
16
+ readonly onError?: (error: unknown, context: ErrorContext) => void;
17
+ /** Checks each response against the route declaration. Meant for tests. */
18
+ readonly validateResponses?: boolean;
19
+ /** Defaults to the incoming `x-request-id` header when it is well formed, else a UUID. */
20
+ readonly requestId?: (request: RawRequest) => string;
21
+ /**
22
+ * Runs every handler inside `scope.run(execution, ...)`, so loggers, audit columns and tenant
23
+ * scoping read the execution context of the request. Opened outside of `withPrincipal`.
24
+ */
25
+ readonly executionScope?: ExecutionScope;
26
+ /**
27
+ * Gives every request a `deadline` in its execution context, this many milliseconds after it
28
+ * arrived. The pipeline does not interrupt a handler: what honours the deadline reads it.
29
+ */
30
+ readonly requestTimeoutMs?: number;
31
+ /** The instant a request arrived at, for `requestTimeoutMs`. Defaults to the system clock. */
32
+ readonly clock?: Clock;
33
+ /**
34
+ * Wraps the whole handling of each request, from authentication to the answer, refusals
35
+ * included. This is where a tracer names the request after its route: `tracedRoutes()` of
36
+ * `@ddd-ts-kit/tracing` fits as it is.
37
+ */
38
+ readonly around?: RouteAround;
39
+ }
40
+ //# sourceMappingURL=execute-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-options.d.ts","sourceRoot":"","sources":["../../src/pipeline/execute-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACvF,wFAAwF;IACxF,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IACnE,2EAA2E;IAC3E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,0FAA0F;IAC1F,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAC;IACrD;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=execute-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-options.js","sourceRoot":"","sources":["../../src/pipeline/execute-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Route } from '../route/route.js';
2
+ import type { ExecuteOptions } from './execute-options.js';
3
+ import type { RawRequest } from './raw-request.js';
4
+ import type { RouteResponse } from './route-response.js';
5
+ export declare function executeRoute(route: Route, request: RawRequest, options?: ExecuteOptions): Promise<RouteResponse>;
6
+ //# sourceMappingURL=execute-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-route.d.ts","sourceRoot":"","sources":["../../src/pipeline/execute-route.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAkBzD,wBAAsB,YAAY,CAChC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAOxB"}