@ddd-ts-kit/http 0.12.0 → 0.14.0

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 (471) hide show
  1. package/README.md +373 -11
  2. package/dist/controller/controller-routes.d.ts.map +1 -1
  3. package/dist/controller/controller-routes.js +8 -0
  4. package/dist/controller/controller-routes.js.map +1 -1
  5. package/dist/controller/controller-spec.d.ts +7 -0
  6. package/dist/controller/controller-spec.d.ts.map +1 -1
  7. package/dist/error/default-error-mapping.d.ts.map +1 -1
  8. package/dist/error/default-error-mapping.js +1 -0
  9. package/dist/error/default-error-mapping.js.map +1 -1
  10. package/dist/express/mount-express.d.ts +4 -2
  11. package/dist/express/mount-express.d.ts.map +1 -1
  12. package/dist/express/mount-express.js +25 -11
  13. package/dist/express/mount-express.js.map +1 -1
  14. package/dist/fastify/mount-fastify.d.ts +2 -1
  15. package/dist/fastify/mount-fastify.d.ts.map +1 -1
  16. package/dist/fastify/mount-fastify.js +23 -4
  17. package/dist/fastify/mount-fastify.js.map +1 -1
  18. package/dist/field-access/assert-writable.d.ts +8 -0
  19. package/dist/field-access/assert-writable.d.ts.map +1 -0
  20. package/dist/field-access/assert-writable.js +29 -0
  21. package/dist/field-access/assert-writable.js.map +1 -0
  22. package/dist/field-access/field-access-entry.d.ts +7 -0
  23. package/dist/field-access/field-access-entry.d.ts.map +1 -0
  24. package/dist/field-access/field-access-entry.js +2 -0
  25. package/dist/field-access/field-access-entry.js.map +1 -0
  26. package/dist/field-access/field-access.d.ts +13 -0
  27. package/dist/field-access/field-access.d.ts.map +1 -0
  28. package/dist/field-access/field-access.js +41 -0
  29. package/dist/field-access/field-access.js.map +1 -0
  30. package/dist/field-access/field-decider-of.d.ts +37 -0
  31. package/dist/field-access/field-decider-of.d.ts.map +1 -0
  32. package/dist/field-access/field-decider-of.js +30 -0
  33. package/dist/field-access/field-decider-of.js.map +1 -0
  34. package/dist/field-access/field-decider.d.ts +4 -0
  35. package/dist/field-access/field-decider.d.ts.map +1 -0
  36. package/dist/field-access/field-decider.js +2 -0
  37. package/dist/field-access/field-decider.js.map +1 -0
  38. package/dist/field-access/field-judge.d.ts +33 -0
  39. package/dist/field-access/field-judge.d.ts.map +1 -0
  40. package/dist/field-access/field-judge.js +81 -0
  41. package/dist/field-access/field-judge.js.map +1 -0
  42. package/dist/field-access/field-policy.d.ts +15 -0
  43. package/dist/field-access/field-policy.d.ts.map +1 -0
  44. package/dist/field-access/field-policy.js +2 -0
  45. package/dist/field-access/field-policy.js.map +1 -0
  46. package/dist/field-access/field-question.d.ts +18 -0
  47. package/dist/field-access/field-question.d.ts.map +1 -0
  48. package/dist/field-access/field-question.js +2 -0
  49. package/dist/field-access/field-question.js.map +1 -0
  50. package/dist/field-access/field-requirement.d.ts +13 -0
  51. package/dist/field-access/field-requirement.d.ts.map +1 -0
  52. package/dist/field-access/field-requirement.js +2 -0
  53. package/dist/field-access/field-requirement.js.map +1 -0
  54. package/dist/field-access/field-rule.d.ts +11 -0
  55. package/dist/field-access/field-rule.d.ts.map +1 -0
  56. package/dist/field-access/field-rule.js +2 -0
  57. package/dist/field-access/field-rule.js.map +1 -0
  58. package/dist/field-access/field-rules.d.ts +6 -0
  59. package/dist/field-access/field-rules.d.ts.map +1 -0
  60. package/dist/field-access/field-rules.js +2 -0
  61. package/dist/field-access/field-rules.js.map +1 -0
  62. package/dist/field-access/field-tree.d.ts +16 -0
  63. package/dist/field-access/field-tree.d.ts.map +1 -0
  64. package/dist/field-access/field-tree.js +28 -0
  65. package/dist/field-access/field-tree.js.map +1 -0
  66. package/dist/field-access/visible-body.d.ts +9 -0
  67. package/dist/field-access/visible-body.d.ts.map +1 -0
  68. package/dist/field-access/visible-body.js +42 -0
  69. package/dist/field-access/visible-body.js.map +1 -0
  70. package/dist/field-access/with-field-access.d.ts +17 -0
  71. package/dist/field-access/with-field-access.d.ts.map +1 -0
  72. package/dist/field-access/with-field-access.js +63 -0
  73. package/dist/field-access/with-field-access.js.map +1 -0
  74. package/dist/forms/assert-hints.d.ts +12 -0
  75. package/dist/forms/assert-hints.d.ts.map +1 -0
  76. package/dist/forms/assert-hints.js +32 -0
  77. package/dist/forms/assert-hints.js.map +1 -0
  78. package/dist/forms/assert-opens.d.ts +16 -0
  79. package/dist/forms/assert-opens.d.ts.map +1 -0
  80. package/dist/forms/assert-opens.js +24 -0
  81. package/dist/forms/assert-opens.js.map +1 -0
  82. package/dist/forms/constraints-of.d.ts +4 -0
  83. package/dist/forms/constraints-of.d.ts.map +1 -0
  84. package/dist/forms/constraints-of.js +24 -0
  85. package/dist/forms/constraints-of.js.map +1 -0
  86. package/dist/forms/define-form.d.ts +20 -0
  87. package/dist/forms/define-form.d.ts.map +1 -0
  88. package/dist/forms/define-form.js +8 -0
  89. package/dist/forms/define-form.js.map +1 -0
  90. package/dist/forms/field-block.d.ts +33 -0
  91. package/dist/forms/field-block.d.ts.map +1 -0
  92. package/dist/forms/field-block.js +2 -0
  93. package/dist/forms/field-block.js.map +1 -0
  94. package/dist/forms/field-hint.d.ts +18 -0
  95. package/dist/forms/field-hint.d.ts.map +1 -0
  96. package/dist/forms/field-hint.js +2 -0
  97. package/dist/forms/field-hint.js.map +1 -0
  98. package/dist/forms/field-lookup.d.ts +7 -0
  99. package/dist/forms/field-lookup.d.ts.map +1 -0
  100. package/dist/forms/field-lookup.js +2 -0
  101. package/dist/forms/field-lookup.js.map +1 -0
  102. package/dist/forms/form-block.d.ts +5 -0
  103. package/dist/forms/form-block.d.ts.map +1 -0
  104. package/dist/forms/form-block.js +2 -0
  105. package/dist/forms/form-block.js.map +1 -0
  106. package/dist/forms/form-condition.d.ts +9 -0
  107. package/dist/forms/form-condition.d.ts.map +1 -0
  108. package/dist/forms/form-condition.js +2 -0
  109. package/dist/forms/form-condition.js.map +1 -0
  110. package/dist/forms/form-describer.d.ts +35 -0
  111. package/dist/forms/form-describer.d.ts.map +1 -0
  112. package/dist/forms/form-describer.js +132 -0
  113. package/dist/forms/form-describer.js.map +1 -0
  114. package/dist/forms/form-description.d.ts +17 -0
  115. package/dist/forms/form-description.d.ts.map +1 -0
  116. package/dist/forms/form-description.js +2 -0
  117. package/dist/forms/form-description.js.map +1 -0
  118. package/dist/forms/form-document.d.ts +9 -0
  119. package/dist/forms/form-document.d.ts.map +1 -0
  120. package/dist/forms/form-document.js +2 -0
  121. package/dist/forms/form-document.js.map +1 -0
  122. package/dist/forms/form-documents-of.d.ts +10 -0
  123. package/dist/forms/form-documents-of.d.ts.map +1 -0
  124. package/dist/forms/form-documents-of.js +22 -0
  125. package/dist/forms/form-documents-of.js.map +1 -0
  126. package/dist/forms/form-format.d.ts +7 -0
  127. package/dist/forms/form-format.d.ts.map +1 -0
  128. package/dist/forms/form-format.js +3 -0
  129. package/dist/forms/form-format.js.map +1 -0
  130. package/dist/forms/form-group-hint.d.ts +8 -0
  131. package/dist/forms/form-group-hint.d.ts.map +1 -0
  132. package/dist/forms/form-group-hint.js +2 -0
  133. package/dist/forms/form-group-hint.js.map +1 -0
  134. package/dist/forms/form-hints.d.ts +16 -0
  135. package/dist/forms/form-hints.d.ts.map +1 -0
  136. package/dist/forms/form-hints.js +2 -0
  137. package/dist/forms/form-hints.js.map +1 -0
  138. package/dist/forms/form-of-route.d.ts +17 -0
  139. package/dist/forms/form-of-route.d.ts.map +1 -0
  140. package/dist/forms/form-of-route.js +47 -0
  141. package/dist/forms/form-of-route.js.map +1 -0
  142. package/dist/forms/form-query-schema.d.ts +10 -0
  143. package/dist/forms/form-query-schema.d.ts.map +1 -0
  144. package/dist/forms/form-query-schema.js +58 -0
  145. package/dist/forms/form-query-schema.js.map +1 -0
  146. package/dist/forms/form-query.d.ts +7 -0
  147. package/dist/forms/form-query.d.ts.map +1 -0
  148. package/dist/forms/form-query.js +2 -0
  149. package/dist/forms/form-query.js.map +1 -0
  150. package/dist/forms/form-requirement.d.ts +18 -0
  151. package/dist/forms/form-requirement.d.ts.map +1 -0
  152. package/dist/forms/form-requirement.js +2 -0
  153. package/dist/forms/form-requirement.js.map +1 -0
  154. package/dist/forms/form-routes.d.ts +19 -0
  155. package/dist/forms/form-routes.d.ts.map +1 -0
  156. package/dist/forms/form-routes.js +67 -0
  157. package/dist/forms/form-routes.js.map +1 -0
  158. package/dist/forms/form-schema.d.ts +4 -0
  159. package/dist/forms/form-schema.d.ts.map +1 -0
  160. package/dist/forms/form-schema.js +52 -0
  161. package/dist/forms/form-schema.js.map +1 -0
  162. package/dist/forms/group-block.d.ts +9 -0
  163. package/dist/forms/group-block.d.ts.map +1 -0
  164. package/dist/forms/group-block.js +2 -0
  165. package/dist/forms/group-block.js.map +1 -0
  166. package/dist/forms/json-form.d.ts +8 -0
  167. package/dist/forms/json-form.d.ts.map +1 -0
  168. package/dist/forms/json-form.js +2 -0
  169. package/dist/forms/json-form.js.map +1 -0
  170. package/dist/forms/json-forms-of.d.ts +12 -0
  171. package/dist/forms/json-forms-of.d.ts.map +1 -0
  172. package/dist/forms/json-forms-of.js +129 -0
  173. package/dist/forms/json-forms-of.js.map +1 -0
  174. package/dist/forms/lookups-of.d.ts +5 -0
  175. package/dist/forms/lookups-of.d.ts.map +1 -0
  176. package/dist/forms/lookups-of.js +7 -0
  177. package/dist/forms/lookups-of.js.map +1 -0
  178. package/dist/forms/widget-of.d.ts +5 -0
  179. package/dist/forms/widget-of.d.ts.map +1 -0
  180. package/dist/forms/widget-of.js +25 -0
  181. package/dist/forms/widget-of.js.map +1 -0
  182. package/dist/forms/widget.d.ts +3 -0
  183. package/dist/forms/widget.d.ts.map +1 -0
  184. package/dist/forms/widget.js +2 -0
  185. package/dist/forms/widget.js.map +1 -0
  186. package/dist/hono/edge-problem.d.ts +11 -0
  187. package/dist/hono/edge-problem.d.ts.map +1 -0
  188. package/dist/hono/edge-problem.js +15 -0
  189. package/dist/hono/edge-problem.js.map +1 -0
  190. package/dist/hono/hono-mount-options.d.ts +10 -0
  191. package/dist/hono/hono-mount-options.d.ts.map +1 -0
  192. package/dist/hono/hono-mount-options.js +2 -0
  193. package/dist/hono/hono-mount-options.js.map +1 -0
  194. package/dist/hono/hono-raw.d.ts +11 -0
  195. package/dist/hono/hono-raw.d.ts.map +1 -0
  196. package/dist/hono/hono-raw.js +2 -0
  197. package/dist/hono/hono-raw.js.map +1 -0
  198. package/dist/hono/mount-hono.d.ts +13 -0
  199. package/dist/hono/mount-hono.d.ts.map +1 -0
  200. package/dist/hono/mount-hono.js +77 -0
  201. package/dist/hono/mount-hono.js.map +1 -0
  202. package/dist/hono/read-body.d.ts +16 -0
  203. package/dist/hono/read-body.d.ts.map +1 -0
  204. package/dist/hono/read-body.js +65 -0
  205. package/dist/hono/read-body.js.map +1 -0
  206. package/dist/hono.d.ts +4 -0
  207. package/dist/hono.d.ts.map +1 -0
  208. package/dist/hono.js +2 -0
  209. package/dist/hono.js.map +1 -0
  210. package/dist/index.d.ts +43 -0
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +20 -0
  213. package/dist/index.js.map +1 -1
  214. package/dist/openapi/cache-response-headers.d.ts +5 -2
  215. package/dist/openapi/cache-response-headers.d.ts.map +1 -1
  216. package/dist/openapi/cache-response-headers.js +10 -5
  217. package/dist/openapi/cache-response-headers.js.map +1 -1
  218. package/dist/openapi/definitions.d.ts +6 -1
  219. package/dist/openapi/definitions.d.ts.map +1 -1
  220. package/dist/openapi/definitions.js +12 -1
  221. package/dist/openapi/definitions.js.map +1 -1
  222. package/dist/openapi/documenting.d.ts +11 -0
  223. package/dist/openapi/documenting.d.ts.map +1 -0
  224. package/dist/openapi/documenting.js +2 -0
  225. package/dist/openapi/documenting.js.map +1 -0
  226. package/dist/openapi/generate-open-api.d.ts +7 -0
  227. package/dist/openapi/generate-open-api.d.ts.map +1 -1
  228. package/dist/openapi/generate-open-api.js +5 -1
  229. package/dist/openapi/generate-open-api.js.map +1 -1
  230. package/dist/openapi/path-items.d.ts +2 -3
  231. package/dist/openapi/path-items.d.ts.map +1 -1
  232. package/dist/openapi/path-items.js +8 -7
  233. package/dist/openapi/path-items.js.map +1 -1
  234. package/dist/openapi/request-body.d.ts +6 -3
  235. package/dist/openapi/request-body.d.ts.map +1 -1
  236. package/dist/openapi/request-body.js +13 -3
  237. package/dist/openapi/request-body.js.map +1 -1
  238. package/dist/openapi/responses.d.ts +2 -3
  239. package/dist/openapi/responses.d.ts.map +1 -1
  240. package/dist/openapi/responses.js +40 -12
  241. package/dist/openapi/responses.js.map +1 -1
  242. package/dist/openapi/schema-parameters.js +1 -1
  243. package/dist/openapi/schema-parameters.js.map +1 -1
  244. package/dist/pagination/every-page.d.ts +15 -0
  245. package/dist/pagination/every-page.d.ts.map +1 -0
  246. package/dist/pagination/every-page.js +21 -0
  247. package/dist/pagination/every-page.js.map +1 -0
  248. package/dist/pagination/page-schema-of.d.ts +3 -1
  249. package/dist/pagination/page-schema-of.d.ts.map +1 -1
  250. package/dist/pagination/page-schema-of.js +11 -3
  251. package/dist/pagination/page-schema-of.js.map +1 -1
  252. package/dist/pipeline/assert-cached-routes.d.ts +4 -2
  253. package/dist/pipeline/assert-cached-routes.d.ts.map +1 -1
  254. package/dist/pipeline/assert-cached-routes.js +46 -8
  255. package/dist/pipeline/assert-cached-routes.js.map +1 -1
  256. package/dist/pipeline/conditional-answer.d.ts +7 -2
  257. package/dist/pipeline/conditional-answer.d.ts.map +1 -1
  258. package/dist/pipeline/conditional-answer.js +10 -6
  259. package/dist/pipeline/conditional-answer.js.map +1 -1
  260. package/dist/pipeline/entity-tag-of.d.ts +3 -3
  261. package/dist/pipeline/entity-tag-of.d.ts.map +1 -1
  262. package/dist/pipeline/entity-tag-of.js +4 -4
  263. package/dist/pipeline/entity-tag-of.js.map +1 -1
  264. package/dist/pipeline/error-context.d.ts +6 -1
  265. package/dist/pipeline/error-context.d.ts.map +1 -1
  266. package/dist/pipeline/execute-options.d.ts +17 -0
  267. package/dist/pipeline/execute-options.d.ts.map +1 -1
  268. package/dist/pipeline/execute-route.d.ts.map +1 -1
  269. package/dist/pipeline/execute-route.js +121 -35
  270. package/dist/pipeline/execute-route.js.map +1 -1
  271. package/dist/pipeline/iterated-within.d.ts +9 -0
  272. package/dist/pipeline/iterated-within.d.ts.map +1 -0
  273. package/dist/pipeline/iterated-within.js +17 -0
  274. package/dist/pipeline/iterated-within.js.map +1 -0
  275. package/dist/pipeline/negotiated-vary.d.ts +6 -0
  276. package/dist/pipeline/negotiated-vary.d.ts.map +1 -0
  277. package/dist/pipeline/negotiated-vary.js +15 -0
  278. package/dist/pipeline/negotiated-vary.js.map +1 -0
  279. package/dist/pipeline/negotiation.d.ts +19 -0
  280. package/dist/pipeline/negotiation.d.ts.map +1 -0
  281. package/dist/pipeline/negotiation.js +19 -0
  282. package/dist/pipeline/negotiation.js.map +1 -0
  283. package/dist/pipeline/primed.d.ts +6 -0
  284. package/dist/pipeline/primed.d.ts.map +1 -0
  285. package/dist/pipeline/primed.js +20 -0
  286. package/dist/pipeline/primed.js.map +1 -0
  287. package/dist/pipeline/read-body.d.ts +10 -0
  288. package/dist/pipeline/read-body.d.ts.map +1 -0
  289. package/dist/pipeline/read-body.js +33 -0
  290. package/dist/pipeline/read-body.js.map +1 -0
  291. package/dist/pipeline/reported-stream.d.ts +6 -0
  292. package/dist/pipeline/reported-stream.d.ts.map +1 -0
  293. package/dist/pipeline/reported-stream.js +14 -0
  294. package/dist/pipeline/reported-stream.js.map +1 -0
  295. package/dist/pipeline/represented-answer.d.ts +7 -0
  296. package/dist/pipeline/represented-answer.d.ts.map +1 -0
  297. package/dist/pipeline/represented-answer.js +2 -0
  298. package/dist/pipeline/represented-answer.js.map +1 -0
  299. package/dist/pipeline/represented.d.ts +7 -0
  300. package/dist/pipeline/represented.d.ts.map +1 -0
  301. package/dist/pipeline/represented.js +19 -0
  302. package/dist/pipeline/represented.js.map +1 -0
  303. package/dist/pipeline/route-response.d.ts +2 -0
  304. package/dist/pipeline/route-response.d.ts.map +1 -1
  305. package/dist/pipeline/tagged-answer.d.ts +5 -2
  306. package/dist/pipeline/tagged-answer.d.ts.map +1 -1
  307. package/dist/pipeline/tagged-answer.js +1 -1
  308. package/dist/pipeline/tagged-answer.js.map +1 -1
  309. package/dist/pipeline/write-stream.d.ts +8 -0
  310. package/dist/pipeline/write-stream.d.ts.map +1 -0
  311. package/dist/pipeline/write-stream.js +23 -0
  312. package/dist/pipeline/write-stream.js.map +1 -0
  313. package/dist/pipeline/written-in.d.ts +10 -0
  314. package/dist/pipeline/written-in.d.ts.map +1 -0
  315. package/dist/pipeline/written-in.js +17 -0
  316. package/dist/pipeline/written-in.js.map +1 -0
  317. package/dist/representation/assert-served.d.ts +10 -0
  318. package/dist/representation/assert-served.d.ts.map +1 -0
  319. package/dist/representation/assert-served.js +18 -0
  320. package/dist/representation/assert-served.js.map +1 -0
  321. package/dist/representation/body-shape.d.ts +9 -0
  322. package/dist/representation/body-shape.d.ts.map +1 -0
  323. package/dist/representation/body-shape.js +2 -0
  324. package/dist/representation/body-shape.js.map +1 -0
  325. package/dist/representation/csv/csv-cell.d.ts +8 -0
  326. package/dist/representation/csv/csv-cell.d.ts.map +1 -0
  327. package/dist/representation/csv/csv-cell.js +19 -0
  328. package/dist/representation/csv/csv-cell.js.map +1 -0
  329. package/dist/representation/csv/csv-representation.d.ts +16 -0
  330. package/dist/representation/csv/csv-representation.d.ts.map +1 -0
  331. package/dist/representation/csv/csv-representation.js +54 -0
  332. package/dist/representation/csv/csv-representation.js.map +1 -0
  333. package/dist/representation/is-json-media-type.d.ts +3 -0
  334. package/dist/representation/is-json-media-type.d.ts.map +1 -0
  335. package/dist/representation/is-json-media-type.js +5 -0
  336. package/dist/representation/is-json-media-type.js.map +1 -0
  337. package/dist/representation/json-representation.d.ts +14 -0
  338. package/dist/representation/json-representation.d.ts.map +1 -0
  339. package/dist/representation/json-representation.js +40 -0
  340. package/dist/representation/json-representation.js.map +1 -0
  341. package/dist/representation/malformed-body.d.ts +4 -0
  342. package/dist/representation/malformed-body.d.ts.map +1 -0
  343. package/dist/representation/malformed-body.js +6 -0
  344. package/dist/representation/malformed-body.js.map +1 -0
  345. package/dist/representation/media-type-of.d.ts +3 -0
  346. package/dist/representation/media-type-of.d.ts.map +1 -0
  347. package/dist/representation/media-type-of.js +7 -0
  348. package/dist/representation/media-type-of.js.map +1 -0
  349. package/dist/representation/negotiate.d.ts +8 -0
  350. package/dist/representation/negotiate.d.ts.map +1 -0
  351. package/dist/representation/negotiate.js +55 -0
  352. package/dist/representation/negotiate.js.map +1 -0
  353. package/dist/representation/not-acceptable-error.d.ts +7 -0
  354. package/dist/representation/not-acceptable-error.d.ts.map +1 -0
  355. package/dist/representation/not-acceptable-error.js +7 -0
  356. package/dist/representation/not-acceptable-error.js.map +1 -0
  357. package/dist/representation/problem-shape.d.ts +4 -0
  358. package/dist/representation/problem-shape.d.ts.map +1 -0
  359. package/dist/representation/problem-shape.js +7 -0
  360. package/dist/representation/problem-shape.js.map +1 -0
  361. package/dist/representation/representation.d.ts +20 -0
  362. package/dist/representation/representation.d.ts.map +1 -0
  363. package/dist/representation/representation.js +9 -0
  364. package/dist/representation/representation.js.map +1 -0
  365. package/dist/representation/representations.d.ts +33 -0
  366. package/dist/representation/representations.d.ts.map +1 -0
  367. package/dist/representation/representations.js +85 -0
  368. package/dist/representation/representations.js.map +1 -0
  369. package/dist/representation/represented-body.d.ts +3 -0
  370. package/dist/representation/represented-body.d.ts.map +1 -0
  371. package/dist/representation/represented-body.js +2 -0
  372. package/dist/representation/represented-body.js.map +1 -0
  373. package/dist/representation/stream-schema-of.d.ts +10 -0
  374. package/dist/representation/stream-schema-of.d.ts.map +1 -0
  375. package/dist/representation/stream-schema-of.js +31 -0
  376. package/dist/representation/stream-schema-of.js.map +1 -0
  377. package/dist/representation/unsupported-media-type-error.d.ts +7 -0
  378. package/dist/representation/unsupported-media-type-error.d.ts.map +1 -0
  379. package/dist/representation/unsupported-media-type-error.js +7 -0
  380. package/dist/representation/unsupported-media-type-error.js.map +1 -0
  381. package/dist/representation/wire-text.d.ts +7 -0
  382. package/dist/representation/wire-text.d.ts.map +1 -0
  383. package/dist/representation/wire-text.js +21 -0
  384. package/dist/representation/wire-text.js.map +1 -0
  385. package/dist/representation/xml/decode-entities.d.ts +3 -0
  386. package/dist/representation/xml/decode-entities.d.ts.map +1 -0
  387. package/dist/representation/xml/decode-entities.js +38 -0
  388. package/dist/representation/xml/decode-entities.js.map +1 -0
  389. package/dist/representation/xml/is-xml-name.d.ts +3 -0
  390. package/dist/representation/xml/is-xml-name.d.ts.map +1 -0
  391. package/dist/representation/xml/is-xml-name.js +6 -0
  392. package/dist/representation/xml/is-xml-name.js.map +1 -0
  393. package/dist/representation/xml/xml-convention.d.ts +10 -0
  394. package/dist/representation/xml/xml-convention.d.ts.map +1 -0
  395. package/dist/representation/xml/xml-convention.js +10 -0
  396. package/dist/representation/xml/xml-convention.js.map +1 -0
  397. package/dist/representation/xml/xml-element-writer.d.ts +16 -0
  398. package/dist/representation/xml/xml-element-writer.d.ts.map +1 -0
  399. package/dist/representation/xml/xml-element-writer.js +71 -0
  400. package/dist/representation/xml/xml-element-writer.js.map +1 -0
  401. package/dist/representation/xml/xml-element.d.ts +9 -0
  402. package/dist/representation/xml/xml-element.d.ts.map +1 -0
  403. package/dist/representation/xml/xml-element.js +2 -0
  404. package/dist/representation/xml/xml-element.js.map +1 -0
  405. package/dist/representation/xml/xml-parser.d.ts +27 -0
  406. package/dist/representation/xml/xml-parser.d.ts.map +1 -0
  407. package/dist/representation/xml/xml-parser.js +154 -0
  408. package/dist/representation/xml/xml-parser.js.map +1 -0
  409. package/dist/representation/xml/xml-representation.d.ts +20 -0
  410. package/dist/representation/xml/xml-representation.d.ts.map +1 -0
  411. package/dist/representation/xml/xml-representation.js +52 -0
  412. package/dist/representation/xml/xml-representation.js.map +1 -0
  413. package/dist/representation/xml/xml-syntax-error.d.ts +5 -0
  414. package/dist/representation/xml/xml-syntax-error.d.ts.map +1 -0
  415. package/dist/representation/xml/xml-syntax-error.js +8 -0
  416. package/dist/representation/xml/xml-syntax-error.js.map +1 -0
  417. package/dist/representation/xml/xml-text.d.ts +7 -0
  418. package/dist/representation/xml/xml-text.d.ts.map +1 -0
  419. package/dist/representation/xml/xml-text.js +30 -0
  420. package/dist/representation/xml/xml-text.js.map +1 -0
  421. package/dist/representation/xml/xml-value-reader.d.ts +15 -0
  422. package/dist/representation/xml/xml-value-reader.d.ts.map +1 -0
  423. package/dist/representation/xml/xml-value-reader.js +101 -0
  424. package/dist/representation/xml/xml-value-reader.js.map +1 -0
  425. package/dist/route/answers-with-schema.d.ts +7 -0
  426. package/dist/route/answers-with-schema.d.ts.map +1 -0
  427. package/dist/route/answers-with-schema.js +10 -0
  428. package/dist/route/answers-with-schema.js.map +1 -0
  429. package/dist/route/route-spec.d.ts +11 -0
  430. package/dist/route/route-spec.d.ts.map +1 -1
  431. package/dist/schema/json-schema-of.d.ts +7 -0
  432. package/dist/schema/json-schema-of.d.ts.map +1 -0
  433. package/dist/schema/json-schema-of.js +15 -0
  434. package/dist/schema/json-schema-of.js.map +1 -0
  435. package/dist/schema/schema-node.d.ts +25 -0
  436. package/dist/schema/schema-node.d.ts.map +1 -0
  437. package/dist/schema/schema-node.js +92 -0
  438. package/dist/schema/schema-node.js.map +1 -0
  439. package/dist/schema/schema-type.d.ts +3 -0
  440. package/dist/schema/schema-type.d.ts.map +1 -0
  441. package/dist/schema/schema-type.js +2 -0
  442. package/dist/schema/schema-type.js.map +1 -0
  443. package/dist/schema/xml-hints.d.ts +9 -0
  444. package/dist/schema/xml-hints.d.ts.map +1 -0
  445. package/dist/schema/xml-hints.js +2 -0
  446. package/dist/schema/xml-hints.js.map +1 -0
  447. package/dist/schemas/accepted-schema.d.ts +8 -0
  448. package/dist/schemas/accepted-schema.d.ts.map +1 -0
  449. package/dist/schemas/accepted-schema.js +20 -0
  450. package/dist/schemas/accepted-schema.js.map +1 -0
  451. package/dist/schemas/accepted.d.ts +5 -0
  452. package/dist/schemas/accepted.d.ts.map +1 -0
  453. package/dist/schemas/accepted.js +2 -0
  454. package/dist/schemas/accepted.js.map +1 -0
  455. package/dist/serialization/decimal-text.d.ts +6 -0
  456. package/dist/serialization/decimal-text.d.ts.map +1 -0
  457. package/dist/serialization/decimal-text.js +13 -0
  458. package/dist/serialization/decimal-text.js.map +1 -0
  459. package/dist/serialization/money-body.d.ts +6 -0
  460. package/dist/serialization/money-body.d.ts.map +1 -0
  461. package/dist/serialization/money-body.js +2 -0
  462. package/dist/serialization/money-body.js.map +1 -0
  463. package/dist/serialization/money.d.ts +4 -0
  464. package/dist/serialization/money.d.ts.map +1 -0
  465. package/dist/serialization/money.js +10 -0
  466. package/dist/serialization/money.js.map +1 -0
  467. package/dist/support/is-async-iterable.d.ts +3 -0
  468. package/dist/support/is-async-iterable.d.ts.map +1 -0
  469. package/dist/support/is-async-iterable.js +5 -0
  470. package/dist/support/is-async-iterable.js.map +1 -0
  471. package/package.json +15 -5
@@ -0,0 +1,67 @@
1
+ import { isAnonymous, ok } from '@ddd-ts-kit/kernel';
2
+ import { customSchema, parseOrThrow } from '@ddd-ts-kit/validation';
3
+ import { UnauthorizedError } from '../error/unauthorized-error.js';
4
+ import { FieldJudge } from '../field-access/field-judge.js';
5
+ import { withoutTrailingSlashes } from '../route/without-trailing-slashes.js';
6
+ import { isRecord } from '../support/is-record.js';
7
+ import { assertOpens } from './assert-opens.js';
8
+ import { FORM_SCHEMA } from './form-schema.js';
9
+ import { FormFormat } from './form-format.js';
10
+ import { FormOfRoute } from './form-of-route.js';
11
+ import { formQuerySchema } from './form-query-schema.js';
12
+ import { jsonFormsOf } from './json-forms-of.js';
13
+ import { lookupsOf } from './lookups-of.js';
14
+ const FORM_RESPONSE = customSchema((input) => ok(input), FORM_SCHEMA);
15
+ /**
16
+ * One route per route that declares a `form`: `GET /forms/<operationId>` answers its form for
17
+ * the caller, in JSON Forms or as a tree of blocks (`?format=blocks`). It is guarded as the
18
+ * route it describes is documented: a form of a route that is not public refuses the
19
+ * anonymous caller, and one that `requires` the permission of its use case refuses with 403 the
20
+ * caller who may not run it. Mounted and documented like any route:
21
+ *
22
+ * const routes = defineRoutes(appRoutes, formRoutes(appRoutes, { fieldAccess }));
23
+ */
24
+ export function formRoutes(routes, options = {}) {
25
+ const lookups = lookupsOf(routes);
26
+ const prefix = withoutTrailingSlashes(options.prefix ?? '/forms');
27
+ return routes
28
+ .filter((route) => route.form !== undefined)
29
+ .map((route) => formRoute(route, FormOfRoute.of(route, lookups), { ...options, prefix }));
30
+ }
31
+ function formRoute(route, form, options) {
32
+ const query = formQuerySchema(form.body);
33
+ return {
34
+ method: 'GET',
35
+ path: `${options.prefix}/${route.operationId}`,
36
+ operationId: `${route.operationId}Form`,
37
+ summary: `Form: ${route.summary}`,
38
+ description: `The form of ${route.method} ${route.path}, for the caller: a field they may not see is absent, one they may not set is read-only.`,
39
+ ...(route.tags === undefined ? {} : { tags: route.tags }),
40
+ ...(route.groups === undefined ? {} : { groups: route.groups }),
41
+ request: { query },
42
+ responses: { 200: { description: 'The form, for the caller.', body: FORM_RESPONSE } },
43
+ errors: [
44
+ ...(route.security === false ? [] : ['UNAUTHORIZED']),
45
+ ...(route.form?.requires === undefined ? [] : ['FORBIDDEN']),
46
+ ],
47
+ security: route.security,
48
+ async handle(input) {
49
+ const { actor } = input.context.execution;
50
+ if (route.security !== false && isAnonymous(actor)) {
51
+ throw new UnauthorizedError('Authentication is required');
52
+ }
53
+ // The pipeline read the query through its schema before the handler: what it hands over is a FormQuery.
54
+ const asked = isFormQuery(input.query) ? input.query : parseOrThrow(query, input.query);
55
+ await assertOpens(route.form?.requires, { actor, decide: options.fieldAccess, values: asked.values });
56
+ return { status: 200, body: await answer(form, new FieldJudge(actor, options.fieldAccess), asked) };
57
+ },
58
+ };
59
+ }
60
+ async function answer(form, judge, { format, values }) {
61
+ const description = await form.describe(judge, values);
62
+ return format === FormFormat.blocks ? description : jsonFormsOf(description, form.body, values);
63
+ }
64
+ function isFormQuery(value) {
65
+ return isRecord(value) && typeof value['format'] === 'string' && isRecord(value['values']);
66
+ }
67
+ //# sourceMappingURL=form-routes.js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S,WAAW,CAAC,KAAc;IACjC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC7F,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { JsonSchema } from '@ddd-ts-kit/validation';
2
+ /** What the contract says of a form: JSON Forms, or the neutral tree of blocks. */
3
+ export declare const FORM_SCHEMA: JsonSchema;
4
+ //# sourceMappingURL=form-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-schema.d.ts","sourceRoot":"","sources":["../../src/forms/form-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,mFAAmF;AACnF,eAAO,MAAM,WAAW,EAAE,UAiDzB,CAAC"}
@@ -0,0 +1,52 @@
1
+ const BLOCK = { $ref: '#/$defs/FormBlock' };
2
+ /** What the contract says of a form: JSON Forms, or the neutral tree of blocks. */
3
+ export const FORM_SCHEMA = {
4
+ oneOf: [
5
+ {
6
+ type: 'object',
7
+ description: 'JSON Forms: give the three to a renderer for React, Angular or Vue.',
8
+ required: ['schema', 'uischema', 'data'],
9
+ properties: { schema: { type: 'object' }, uischema: { type: 'object' }, data: { type: 'object' } },
10
+ },
11
+ {
12
+ type: 'object',
13
+ description: 'The neutral tree of blocks, for a front end with its own rendering engine.',
14
+ required: ['type', 'operation', 'method', 'path', 'label', 'blocks'],
15
+ properties: {
16
+ type: { const: 'form' },
17
+ operation: { type: 'string' },
18
+ method: { type: 'string' },
19
+ path: { type: 'string' },
20
+ label: { type: 'string', description: 'A translation key.' },
21
+ blocks: { type: 'array', items: BLOCK },
22
+ },
23
+ },
24
+ ],
25
+ $defs: {
26
+ FormBlock: {
27
+ type: 'object',
28
+ description: 'A group (`type: group`, `blocks`) or a field (`type: field`, `widget`, `required`, `readOnly`, `constraints`, `options`, `lookup`, `visibleWhen`, `requiredWhen`, `value`). Labels are translation keys.',
29
+ required: ['type', 'name', 'label'],
30
+ properties: {
31
+ type: { enum: ['group', 'field'] },
32
+ name: { type: 'string' },
33
+ label: { type: 'string' },
34
+ widget: { type: 'string' },
35
+ required: { type: 'boolean' },
36
+ readOnly: { type: 'boolean' },
37
+ constraints: { type: 'object' },
38
+ options: { type: 'array', items: { type: 'object', properties: { value: {}, label: { type: 'string' } } } },
39
+ multiple: { type: 'boolean' },
40
+ lookup: {
41
+ type: 'object',
42
+ properties: { operation: { type: 'string' }, method: { type: 'string' }, path: { type: 'string' } },
43
+ },
44
+ visibleWhen: { type: 'object' },
45
+ requiredWhen: { type: 'object' },
46
+ value: {},
47
+ blocks: { type: 'array', items: BLOCK },
48
+ },
49
+ },
50
+ },
51
+ };
52
+ //# sourceMappingURL=form-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-schema.js","sourceRoot":"","sources":["../../src/forms/form-schema.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;AAE5C,mFAAmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC,KAAK,EAAE;QACL;YACE,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,qEAAqE;YAClF,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC;YACxC,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SACnG;QACD;YACE,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4EAA4E;YACzF,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;YACpE,UAAU,EAAE;gBACV,IAAI,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AE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;iBACpG;gBACD,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC/B,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;aACxC;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** A group of blocks of a form, which may hold groups of its own: `Block` is a `FormBlock`. */
2
+ export interface GroupBlock<Block = unknown> {
3
+ readonly type: 'group';
4
+ readonly name: string;
5
+ /** A translation key: `<operationId>.<group>`. */
6
+ readonly label: string;
7
+ readonly blocks: readonly Block[];
8
+ }
9
+ //# sourceMappingURL=group-block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-block.d.ts","sourceRoot":"","sources":["../../src/forms/group-block.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,MAAM,WAAW,UAAU,CAAC,KAAK,GAAG,OAAO;IACzC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;CACnC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=group-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-block.js","sourceRoot":"","sources":["../../src/forms/group-block.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { JsonSchema } from '@ddd-ts-kit/validation';
2
+ /** A form in JSON Forms: what its renderers take as `schema`, `uischema` and `data`. */
3
+ export interface JsonForm {
4
+ readonly schema: JsonSchema;
5
+ readonly uischema: JsonSchema;
6
+ readonly data: Readonly<Record<string, unknown>>;
7
+ }
8
+ //# sourceMappingURL=json-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-form.d.ts","sourceRoot":"","sources":["../../src/forms/json-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-form.js","sourceRoot":"","sources":["../../src/forms/json-form.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { SchemaNode } from '../schema/schema-node.js';
2
+ import type { FormDescription } from './form-description.js';
3
+ import type { JsonForm } from './json-form.js';
4
+ /**
5
+ * The form in JSON Forms, the recommended default: a JSON Schema of what the caller may see
6
+ * (read-only where they may not set), a UI schema of groups and controls whose labels are
7
+ * translation keys (`i18n`), rules for conditional visibility, `if`/`then` for a field required
8
+ * by a condition, and the values the request gave as `data`. Every renderer of JSON Forms
9
+ * (React, Angular, Vue) takes the three as they are.
10
+ */
11
+ export declare function jsonFormsOf(description: FormDescription, body: SchemaNode, data: Readonly<Record<string, unknown>>): JsonForm;
12
+ //# sourceMappingURL=json-forms-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-forms-of.d.ts","sourceRoot":"","sources":["../../src/forms/json-forms-of.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAK3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO/C;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACtC,QAAQ,CAMV"}
@@ -0,0 +1,129 @@
1
+ import { isRecord } from '../support/is-record.js';
2
+ const MAX_DEPTH = 16;
3
+ const WIDGET_FORMATS = { datetime: 'date-time', date: 'date', time: 'time' };
4
+ /** What a schema says of itself and of other documents, which a self-contained form schema does not need. */
5
+ const LEFT_OUT = new Set(['$ref', '$defs', 'definitions', '$schema', '$id', 'x-field-access']);
6
+ /**
7
+ * The form in JSON Forms, the recommended default: a JSON Schema of what the caller may see
8
+ * (read-only where they may not set), a UI schema of groups and controls whose labels are
9
+ * translation keys (`i18n`), rules for conditional visibility, `if`/`then` for a field required
10
+ * by a condition, and the values the request gave as `data`. Every renderer of JSON Forms
11
+ * (React, Angular, Vue) takes the three as they are.
12
+ */
13
+ export function jsonFormsOf(description, body, data) {
14
+ return {
15
+ schema: objectSchema(description.blocks, body),
16
+ uischema: { type: 'VerticalLayout', elements: elementsOf(description.blocks, '#') },
17
+ data: visibleData(description.blocks, data),
18
+ };
19
+ }
20
+ /** The values the request gave, for the fields the caller sees only: a hidden field is not echoed back. */
21
+ function visibleData(blocks, data) {
22
+ return Object.fromEntries(fieldsOf(blocks).flatMap((field) => {
23
+ const name = lastSegment(field.name);
24
+ const value = data[name];
25
+ if (value === undefined) {
26
+ return [];
27
+ }
28
+ return [[name, field.widget === 'group' && isRecord(value) ? visibleData(field.blocks ?? [], value) : value]];
29
+ }));
30
+ }
31
+ /** The schema of one object of the form, its properties in the order of the request schema whatever the layout. */
32
+ function objectSchema(blocks, node) {
33
+ const children = new Map(node.properties());
34
+ const order = [...children.keys()];
35
+ const fields = fieldsOf(blocks).sort((a, b) => order.indexOf(lastSegment(a.name)) - order.indexOf(lastSegment(b.name)));
36
+ const conditional = fields.flatMap((field) => field.requiredWhen === undefined ? [] : [requiredWhen(field, field.requiredWhen)]);
37
+ return {
38
+ type: 'object',
39
+ properties: Object.fromEntries(fields.map((field) => [lastSegment(field.name), propertySchema(field, children.get(lastSegment(field.name)))])),
40
+ required: fields.filter((field) => field.required).map((field) => lastSegment(field.name)),
41
+ ...(conditional.length === 0 ? {} : { allOf: conditional }),
42
+ };
43
+ }
44
+ function propertySchema(field, node) {
45
+ if (node === undefined) {
46
+ return {};
47
+ }
48
+ if (field.widget === 'group') {
49
+ return { ...objectSchema(field.blocks ?? [], node), ...(field.readOnly === true ? { readOnly: true } : {}) };
50
+ }
51
+ const own = inlined(node, 0);
52
+ return {
53
+ ...own,
54
+ ...(field.readOnly === true ? { readOnly: true } : {}),
55
+ ...(field.options !== undefined && own['enum'] === undefined && field.multiple !== true
56
+ ? { enum: field.options.map(({ value }) => value) }
57
+ : {}),
58
+ ...formatOf(field),
59
+ };
60
+ }
61
+ /** A widget of an instant says the format a renderer picks its control by, whatever format the schema library wrote. */
62
+ function formatOf({ widget }) {
63
+ const format = WIDGET_FORMATS[widget];
64
+ return format === undefined ? {} : { format };
65
+ }
66
+ /** The node with every reference followed, so the form schema holds itself. */
67
+ function inlined(node, depth) {
68
+ const own = Object.fromEntries(Object.entries(node.node).filter(([key]) => !LEFT_OUT.has(key)));
69
+ if (depth >= MAX_DEPTH) {
70
+ return own;
71
+ }
72
+ const properties = node.properties();
73
+ return {
74
+ ...own,
75
+ ...(properties.length === 0
76
+ ? {}
77
+ : { properties: Object.fromEntries(properties.map(([name, child]) => [name, inlined(child, depth + 1)])) }),
78
+ ...(isRecord(node.node['items']) ? { items: inlined(node.items(), depth + 1) } : {}),
79
+ };
80
+ }
81
+ function elementsOf(blocks, scope) {
82
+ return blocks.map((block) => {
83
+ if (block.type === 'group') {
84
+ return { type: 'Group', label: block.label, i18n: block.label, elements: elementsOf(block.blocks, scope) };
85
+ }
86
+ const own = `${scope}/properties/${lastSegment(block.name)}`;
87
+ if (block.widget === 'group') {
88
+ return { type: 'Group', label: block.label, i18n: block.label, elements: elementsOf(block.blocks ?? [], own) };
89
+ }
90
+ return control(block, own);
91
+ });
92
+ }
93
+ function control(field, scope) {
94
+ const options = {
95
+ ...(field.widget === 'textarea' ? { multi: true } : {}),
96
+ ...(field.widget === 'radio' ? { format: 'radio' } : {}),
97
+ ...(field.readOnly === true ? { readonly: true } : {}),
98
+ ...(field.lookup === undefined ? {} : { lookup: field.lookup }),
99
+ };
100
+ return {
101
+ type: 'Control',
102
+ scope,
103
+ i18n: field.label,
104
+ ...(Object.keys(options).length === 0 ? {} : { options }),
105
+ ...(field.visibleWhen === undefined ? {} : { rule: { effect: 'SHOW', condition: conditionOf(field.visibleWhen) } }),
106
+ };
107
+ }
108
+ function conditionOf(condition) {
109
+ return {
110
+ scope: scopeOf(condition.field),
111
+ schema: 'equals' in condition ? { const: condition.equals } : { enum: [...condition.in] },
112
+ };
113
+ }
114
+ function requiredWhen(field, condition) {
115
+ const name = lastSegment(condition.field);
116
+ const matching = 'equals' in condition ? { const: condition.equals } : { enum: [...condition.in] };
117
+ return { if: { properties: { [name]: matching }, required: [name] }, then: { required: [lastSegment(field.name)] } };
118
+ }
119
+ /** The fields of one level of the body, whatever group of the layout holds them. */
120
+ function fieldsOf(blocks) {
121
+ return blocks.flatMap((block) => (block.type === 'group' ? fieldsOf(block.blocks) : [block]));
122
+ }
123
+ function scopeOf(path) {
124
+ return `#/properties/${path.split('.').join('/properties/')}`;
125
+ }
126
+ function lastSegment(path) {
127
+ return path.slice(path.lastIndexOf('.') + 1);
128
+ }
129
+ //# sourceMappingURL=json-forms-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-forms-of.js","sourceRoot":"","sources":["../../src/forms/json-forms-of.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,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EAAE,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;AACvH,CAAC;AAED,oFAAoF;AACpF,SAAS,QAAQ,CAAC,MAA4B;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,gBAAgB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;AAChE,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Route } from '../route/route.js';
2
+ import type { FieldLookup } from './field-lookup.js';
3
+ /** The `GET` routes a field may take its options from, by operation id. */
4
+ export declare function lookupsOf(routes: readonly Route[]): ReadonlyMap<string, FieldLookup>;
5
+ //# sourceMappingURL=lookups-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookups-of.d.ts","sourceRoot":"","sources":["../../src/forms/lookups-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAMpF"}
@@ -0,0 +1,7 @@
1
+ /** The `GET` routes a field may take its options from, by operation id. */
2
+ export function lookupsOf(routes) {
3
+ return new Map(routes
4
+ .filter((route) => route.method === 'GET')
5
+ .map((route) => [route.operationId, { operation: route.operationId, method: 'GET', path: route.path }]));
6
+ }
7
+ //# sourceMappingURL=lookups-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookups-of.js","sourceRoot":"","sources":["../../src/forms/lookups-of.ts"],"names":[],"mappings":"AAGA,2EAA2E;AAC3E,MAAM,UAAU,SAAS,CAAC,MAAwB;IAChD,OAAO,IAAI,GAAG,CACZ,MAAM;SACH,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC;SACzC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAC1G,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { SchemaNode } from '../schema/schema-node.js';
2
+ import type { Widget } from './widget.js';
3
+ /** The widget a field gets when its hint names none, from its schema. */
4
+ export declare function widgetOf(node: SchemaNode): Widget;
5
+ //# sourceMappingURL=widget-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-of.d.ts","sourceRoot":"","sources":["../../src/forms/widget-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAS1C,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAsBjD"}
@@ -0,0 +1,25 @@
1
+ const BY_FORMAT = {
2
+ 'date-time': 'datetime',
3
+ date: 'date',
4
+ time: 'time',
5
+ email: 'email',
6
+ };
7
+ /** The widget a field gets when its hint names none, from its schema. */
8
+ export function widgetOf(node) {
9
+ if (node.node['enum'] !== undefined) {
10
+ return 'select';
11
+ }
12
+ const type = node.type();
13
+ if (type === 'boolean') {
14
+ return 'checkbox';
15
+ }
16
+ if (type === 'number' || type === 'integer') {
17
+ return 'number';
18
+ }
19
+ if (type === 'array') {
20
+ return 'list';
21
+ }
22
+ const format = node.node['format'];
23
+ return (typeof format === 'string' ? BY_FORMAT[format] : undefined) ?? 'text';
24
+ }
25
+ //# sourceMappingURL=widget-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-of.js","sourceRoot":"","sources":["../../src/forms/widget-of.ts"],"names":[],"mappings":"AAGA,MAAM,SAAS,GAAqC;IAClD,WAAW,EAAE,UAAU;IACvB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,yEAAyE;AACzE,MAAM,UAAU,QAAQ,CAAC,IAAgB;IACvC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAEzB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;AAChF,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** How a field is entered: what a block of the form says, and what a renderer maps to a control of its own. */
2
+ export type Widget = 'text' | 'textarea' | 'number' | 'checkbox' | 'select' | 'radio' | 'date' | 'datetime' | 'time' | 'email' | 'password' | 'group' | 'list';
3
+ //# sourceMappingURL=widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/forms/widget.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,MAAM,MAAM,MAAM,GACd,MAAM,GACN,UAAU,GACV,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,OAAO,GACP,MAAM,GACN,UAAU,GACV,MAAM,GACN,OAAO,GACP,UAAU,GACV,OAAO,GACP,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=widget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../src/forms/widget.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { RawHeaders } from '../route/raw-headers.js';
2
+ /** A request the adapter refuses before the pipeline runs: its status, its code and what is wrong. */
3
+ export interface EdgeRefusal {
4
+ readonly status: number;
5
+ readonly title: string;
6
+ readonly code: string;
7
+ readonly detail: string;
8
+ }
9
+ /** The answer to a request refused at the edge: a problem document, as every other refusal. */
10
+ export declare function edgeProblem(headers: RawHeaders, refusal: EdgeRefusal): Response;
11
+ //# sourceMappingURL=edge-problem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-problem.d.ts","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,sGAAsG;AACtG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,CAW/E"}
@@ -0,0 +1,15 @@
1
+ import { CORRELATION_HEADER } from '../pipeline/correlation-header.js';
2
+ import { wellFormedIdentifier } from '../pipeline/well-formed-identifier.js';
3
+ /** The answer to a request refused at the edge: a problem document, as every other refusal. */
4
+ export function edgeProblem(headers, refusal) {
5
+ const requestId = wellFormedIdentifier(headers['x-request-id']) ?? globalThis.crypto.randomUUID();
6
+ const problem = { type: 'about:blank', ...refusal, requestId };
7
+ return new Response(JSON.stringify(problem), {
8
+ status: refusal.status,
9
+ headers: {
10
+ 'content-type': 'application/problem+json',
11
+ [CORRELATION_HEADER]: wellFormedIdentifier(headers[CORRELATION_HEADER]) ?? requestId,
12
+ },
13
+ });
14
+ }
15
+ //# sourceMappingURL=edge-problem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-problem.js","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAW7E,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,OAAmB,EAAE,OAAoB;IACnE,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClG,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC;IAE/D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC3C,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE;YACP,cAAc,EAAE,0BAA0B;YAC1C,CAAC,kBAAkB,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,SAAS;SACrF;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ExecuteOptions } from '../pipeline/execute-options.js';
2
+ export interface HonoMountOptions extends ExecuteOptions {
3
+ /**
4
+ * The largest JSON body read, in bytes: a larger one is answered 413 as a problem
5
+ * (`BODY_TOO_LARGE`) before the pipeline runs, without being held in memory. 1 MiB by default,
6
+ * the limit of Fastify; Express answers beyond 100 kB. An upload has the limit its route declares.
7
+ */
8
+ readonly bodyLimit?: number;
9
+ }
10
+ //# sourceMappingURL=hono-mount-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-mount-options.d.ts","sourceRoot":"","sources":["../../src/hono/hono-mount-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hono-mount-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-mount-options.js","sourceRoot":"","sources":["../../src/hono/hono-mount-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { Context } from 'hono';
2
+ import type { RawHeaders } from '../route/raw-headers.js';
3
+ /**
4
+ * What `resolvePrincipal` and the hooks receive as the request on Hono: the headers as a plain
5
+ * record, which the authenticators of the kit read, and the context of Hono for the rest.
6
+ */
7
+ export interface HonoRaw {
8
+ readonly headers: RawHeaders;
9
+ readonly context: Context;
10
+ }
11
+ //# sourceMappingURL=hono-raw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-raw.d.ts","sourceRoot":"","sources":["../../src/hono/hono-raw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hono-raw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-raw.js","sourceRoot":"","sources":["../../src/hono/hono-raw.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { Hono } from 'hono';
2
+ import type { Route } from '../route/route.js';
3
+ import type { HonoMountOptions } from './hono-mount-options.js';
4
+ /**
5
+ * Registers the routes on a Hono application. The adapter reads the JSON body itself, up to
6
+ * `bodyLimit` (1 MiB by default): a larger body is answered 413 and a body that is not JSON 400,
7
+ * both as problems, before the pipeline runs. A body in a media type the route consumes
8
+ * (`consumes`) is read as text under the same limit, for its representation. An upload and a raw
9
+ * body are read from the request stream; a body that is a stream, or a streamed list, is
10
+ * streamed to the response.
11
+ */
12
+ export declare function mountHono(app: Pick<Hono, 'on'>, routes: readonly Route[], options?: HonoMountOptions): void;
13
+ //# sourceMappingURL=mount-hono.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount-hono.d.ts","sourceRoot":"","sources":["../../src/hono/mount-hono.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAQ1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAShE;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,OAAO,GAAE,gBAAqB,GAAG,IAAI,CAQ/G"}
@@ -0,0 +1,77 @@
1
+ import { Readable } from 'node:stream';
2
+ import { assertCachedRoutes } from '../pipeline/assert-cached-routes.js';
3
+ import { executeRoute } from '../pipeline/execute-route.js';
4
+ import { serializeBody } from '../pipeline/serialize-body.js';
5
+ import { assertServed } from '../representation/assert-served.js';
6
+ import { assertUniqueRoutes } from '../route/assert-unique-routes.js';
7
+ import { edgeProblem } from './edge-problem.js';
8
+ import { readBody } from './read-body.js';
9
+ /** What Fastify reads at most by default: the same bound on every adapter that sets its own. */
10
+ const ONE_MEBIBYTE = 1_048_576;
11
+ /**
12
+ * Registers the routes on a Hono application. The adapter reads the JSON body itself, up to
13
+ * `bodyLimit` (1 MiB by default): a larger body is answered 413 and a body that is not JSON 400,
14
+ * both as problems, before the pipeline runs. A body in a media type the route consumes
15
+ * (`consumes`) is read as text under the same limit, for its representation. An upload and a raw
16
+ * body are read from the request stream; a body that is a stream, or a streamed list, is
17
+ * streamed to the response.
18
+ */
19
+ export function mountHono(app, routes, options = {}) {
20
+ assertUniqueRoutes(routes);
21
+ assertServed(routes, options.representations);
22
+ assertCachedRoutes(routes, options);
23
+ for (const route of routes) {
24
+ app.on(route.method, route.path, handlerOf(route, options));
25
+ }
26
+ }
27
+ function handlerOf(route, options) {
28
+ const { bodyLimit = ONE_MEBIBYTE, ...execute } = options;
29
+ return async (context) => {
30
+ const request = streamed(route) ? streamRequest(context) : await bodyRequest(context, route, bodyLimit);
31
+ if (request instanceof Response) {
32
+ return request;
33
+ }
34
+ return responseOf(await executeRoute(route, request, execute));
35
+ };
36
+ }
37
+ function streamed(route) {
38
+ return route.upload !== undefined || route.rawBody === true;
39
+ }
40
+ function streamRequest(context) {
41
+ const { body } = context.req.raw;
42
+ return {
43
+ ...common(context),
44
+ body: undefined,
45
+ ...(body === null ? {} : { stream: Readable.fromWeb(body) }),
46
+ };
47
+ }
48
+ async function bodyRequest(context, route, limit) {
49
+ const body = await readBody(context, limit, route.consumes);
50
+ if (!body.read) {
51
+ return edgeProblem(context.req.header(), body.refusal);
52
+ }
53
+ return { ...common(context), body: body.value };
54
+ }
55
+ function common(context) {
56
+ const headers = context.req.header();
57
+ const raw = { headers, context };
58
+ return { params: context.req.param(), query: queryOf(context), headers, raw };
59
+ }
60
+ function responseOf(result) {
61
+ return new Response(sentOf(result), { status: result.status, headers: result.headers });
62
+ }
63
+ /** A file as it is, a streamed list as a stream of its chunks, anything else serialized. */
64
+ function sentOf(result) {
65
+ if (result.body instanceof Readable) {
66
+ return Readable.toWeb(result.body);
67
+ }
68
+ return result.stream === undefined ? (serializeBody(result) ?? null) : Readable.toWeb(Readable.from(result.stream));
69
+ }
70
+ /** A repeated key keeps its values as a list, a single one is a string: what Express and Fastify answer. */
71
+ function queryOf(context) {
72
+ return Object.fromEntries(Object.entries(context.req.queries()).map(([name, values]) => [
73
+ name,
74
+ values.length === 1 ? (values[0] ?? '') : values,
75
+ ]));
76
+ }
77
+ //# sourceMappingURL=mount-hono.js.map