openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.4

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 (448) hide show
  1. package/CHANGELOG.md +1831 -0
  2. package/dist/adapters/node-file-system/file-claims.cjs +105 -0
  3. package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
  4. package/dist/adapters/node-file-system/file-claims.mjs +95 -0
  5. package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
  6. package/dist/adapters/node-file-system/file-identity.cjs +82 -0
  7. package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
  8. package/dist/adapters/node-file-system/file-identity.mjs +74 -0
  9. package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
  10. package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
  11. package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
  12. package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
  13. package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
  15. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
  16. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
  17. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
  18. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
  19. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
  20. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
  21. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
  22. package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
  23. package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
  25. package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
  27. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
  29. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
  31. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
  33. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
  35. package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
  37. package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
  38. package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
  39. package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
  40. package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
  41. package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
  42. package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
  43. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  44. package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
  45. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  46. package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
  47. package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
  48. package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
  49. package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
  50. package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
  51. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  52. package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
  53. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  54. package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
  55. package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
  56. package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
  57. package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
  58. package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
  59. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  60. package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
  61. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  62. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  63. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  64. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  65. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  66. package/dist/api/default-ports.cjs +14 -2
  67. package/dist/api/default-ports.cjs.map +1 -1
  68. package/dist/api/default-ports.mjs +14 -2
  69. package/dist/api/default-ports.mjs.map +1 -1
  70. package/dist/api/discriminator-enum-parent.cjs +2 -2
  71. package/dist/api/discriminator-enum-parent.cjs.map +1 -1
  72. package/dist/api/discriminator-enum-parent.mjs +3 -3
  73. package/dist/api/discriminator-enum-parent.mjs.map +1 -1
  74. package/dist/api/discriminator-other-owners.cjs +5 -3
  75. package/dist/api/discriminator-other-owners.cjs.map +1 -1
  76. package/dist/api/discriminator-other-owners.mjs +5 -3
  77. package/dist/api/discriminator-other-owners.mjs.map +1 -1
  78. package/dist/api/discriminator-patch.cjs +5 -1
  79. package/dist/api/discriminator-patch.cjs.map +1 -1
  80. package/dist/api/discriminator-patch.mjs +5 -1
  81. package/dist/api/discriminator-patch.mjs.map +1 -1
  82. package/dist/api/discriminator-scan.cjs +15 -8
  83. package/dist/api/discriminator-scan.cjs.map +1 -1
  84. package/dist/api/discriminator-scan.mjs +15 -8
  85. package/dist/api/discriminator-scan.mjs.map +1 -1
  86. package/dist/api/document-run.cjs +2 -2
  87. package/dist/api/document-run.cjs.map +1 -1
  88. package/dist/api/document-run.mjs +2 -2
  89. package/dist/api/document-run.mjs.map +1 -1
  90. package/dist/api/legacy-utils.cjs.map +1 -1
  91. package/dist/api/legacy-utils.mjs.map +1 -1
  92. package/dist/api/openapi-ts.cjs +8 -4
  93. package/dist/api/openapi-ts.cjs.map +1 -1
  94. package/dist/api/openapi-ts.mjs +8 -5
  95. package/dist/api/openapi-ts.mjs.map +1 -1
  96. package/dist/api/schema-callbacks.cjs +36 -12
  97. package/dist/api/schema-callbacks.cjs.map +1 -1
  98. package/dist/api/schema-callbacks.mjs +36 -12
  99. package/dist/api/schema-callbacks.mjs.map +1 -1
  100. package/dist/api/transform-context.cjs +7 -3
  101. package/dist/api/transform-context.cjs.map +1 -1
  102. package/dist/api/transform-context.mjs +7 -3
  103. package/dist/api/transform-context.mjs.map +1 -1
  104. package/dist/api/transform-schema.cjs +40 -10
  105. package/dist/api/transform-schema.cjs.map +1 -1
  106. package/dist/api/transform-schema.mjs +41 -11
  107. package/dist/api/transform-schema.mjs.map +1 -1
  108. package/dist/application/print/text-writer.cjs +10 -3
  109. package/dist/application/print/text-writer.cjs.map +1 -1
  110. package/dist/application/print/text-writer.mjs +10 -3
  111. package/dist/application/print/text-writer.mjs.map +1 -1
  112. package/dist/application/stack-overflow.cjs +2 -1
  113. package/dist/application/stack-overflow.cjs.map +1 -1
  114. package/dist/application/stack-overflow.mjs +2 -1
  115. package/dist/application/stack-overflow.mjs.map +1 -1
  116. package/dist/application/transform/document/components.cjs +1 -1
  117. package/dist/application/transform/document/components.cjs.map +1 -1
  118. package/dist/application/transform/document/components.mjs +2 -2
  119. package/dist/application/transform/document/components.mjs.map +1 -1
  120. package/dist/application/transform/document/declared-type-names.cjs +23 -0
  121. package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
  122. package/dist/application/transform/document/declared-type-names.mjs +20 -0
  123. package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
  124. package/dist/application/transform/document/defs-root.cjs +1 -1
  125. package/dist/application/transform/document/defs-root.cjs.map +1 -1
  126. package/dist/application/transform/document/defs-root.mjs +2 -2
  127. package/dist/application/transform/document/defs-root.mjs.map +1 -1
  128. package/dist/application/transform/document/document.cjs +4 -1
  129. package/dist/application/transform/document/document.cjs.map +1 -1
  130. package/dist/application/transform/document/document.mjs +3 -2
  131. package/dist/application/transform/document/document.mjs.map +1 -1
  132. package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
  133. package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
  134. package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
  135. package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
  136. package/dist/application/transform/document/global-type-references.cjs +1 -0
  137. package/dist/application/transform/document/global-type-references.cjs.map +1 -1
  138. package/dist/application/transform/document/global-type-references.mjs +1 -1
  139. package/dist/application/transform/document/global-type-references.mjs.map +1 -1
  140. package/dist/application/transform/document/media-type.cjs +2 -2
  141. package/dist/application/transform/document/media-type.cjs.map +1 -1
  142. package/dist/application/transform/document/media-type.mjs +3 -3
  143. package/dist/application/transform/document/media-type.mjs.map +1 -1
  144. package/dist/application/transform/document/operation-keys-written.cjs +26 -0
  145. package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
  146. package/dist/application/transform/document/operation-keys-written.mjs +24 -0
  147. package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
  148. package/dist/application/transform/document/operation.cjs +1 -1
  149. package/dist/application/transform/document/operation.cjs.map +1 -1
  150. package/dist/application/transform/document/operation.mjs +2 -2
  151. package/dist/application/transform/document/operation.mjs.map +1 -1
  152. package/dist/application/transform/document/parameter-entries.cjs +34 -0
  153. package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
  154. package/dist/application/transform/document/parameter-entries.mjs +30 -0
  155. package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
  156. package/dist/application/transform/document/parameter.cjs +12 -4
  157. package/dist/application/transform/document/parameter.cjs.map +1 -1
  158. package/dist/application/transform/document/parameter.mjs +13 -5
  159. package/dist/application/transform/document/parameter.mjs.map +1 -1
  160. package/dist/application/transform/document/parameters.cjs +6 -29
  161. package/dist/application/transform/document/parameters.cjs.map +1 -1
  162. package/dist/application/transform/document/parameters.mjs +6 -29
  163. package/dist/application/transform/document/parameters.mjs.map +1 -1
  164. package/dist/application/transform/document/path-item.cjs +11 -14
  165. package/dist/application/transform/document/path-item.cjs.map +1 -1
  166. package/dist/application/transform/document/path-item.mjs +12 -16
  167. package/dist/application/transform/document/path-item.mjs.map +1 -1
  168. package/dist/application/transform/document/paths-enum.cjs +1 -0
  169. package/dist/application/transform/document/paths-enum.cjs.map +1 -1
  170. package/dist/application/transform/document/paths-enum.mjs +1 -1
  171. package/dist/application/transform/document/paths-enum.mjs.map +1 -1
  172. package/dist/application/transform/document/paths.cjs +5 -1
  173. package/dist/application/transform/document/paths.cjs.map +1 -1
  174. package/dist/application/transform/document/paths.mjs +6 -2
  175. package/dist/application/transform/document/paths.mjs.map +1 -1
  176. package/dist/application/transform/document/referenced-parameter.cjs +80 -0
  177. package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
  178. package/dist/application/transform/document/referenced-parameter.mjs +78 -0
  179. package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
  180. package/dist/application/transform/document/request-body.cjs +1 -1
  181. package/dist/application/transform/document/request-body.cjs.map +1 -1
  182. package/dist/application/transform/document/request-body.mjs +2 -2
  183. package/dist/application/transform/document/request-body.mjs.map +1 -1
  184. package/dist/application/transform/document/response.cjs +2 -2
  185. package/dist/application/transform/document/response.cjs.map +1 -1
  186. package/dist/application/transform/document/response.mjs +3 -3
  187. package/dist/application/transform/document/response.mjs.map +1 -1
  188. package/dist/application/transform/document/responses.cjs +1 -1
  189. package/dist/application/transform/document/responses.cjs.map +1 -1
  190. package/dist/application/transform/document/responses.mjs +2 -2
  191. package/dist/application/transform/document/responses.mjs.map +1 -1
  192. package/dist/application/transform/document/root-type-aliases.cjs +8 -23
  193. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  194. package/dist/application/transform/document/root-type-aliases.mjs +8 -24
  195. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  196. package/dist/application/transform/document/type-resolution.cjs +3 -1
  197. package/dist/application/transform/document/type-resolution.cjs.map +1 -1
  198. package/dist/application/transform/document/type-resolution.mjs +3 -1
  199. package/dist/application/transform/document/type-resolution.mjs.map +1 -1
  200. package/dist/application/transform/document/webhooks.cjs +1 -1
  201. package/dist/application/transform/document/webhooks.cjs.map +1 -1
  202. package/dist/application/transform/document/webhooks.mjs +2 -2
  203. package/dist/application/transform/document/webhooks.mjs.map +1 -1
  204. package/dist/application/transform/footer/document-footer.cjs +10 -2
  205. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  206. package/dist/application/transform/footer/document-footer.mjs +10 -2
  207. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  208. package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
  209. package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
  210. package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
  211. package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
  212. package/dist/application/transform/footer/operation-keys.cjs +23 -0
  213. package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
  214. package/dist/application/transform/footer/operation-keys.mjs +21 -0
  215. package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
  216. package/dist/application/transform/footer/type-evaluation.cjs +4 -4
  217. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
  218. package/dist/application/transform/footer/type-evaluation.mjs +4 -4
  219. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
  220. package/dist/application/transform/helper-types.cjs +1 -1
  221. package/dist/application/transform/helper-types.cjs.map +1 -1
  222. package/dist/application/transform/helper-types.mjs +1 -1
  223. package/dist/application/transform/helper-types.mjs.map +1 -1
  224. package/dist/application/transform/numbered-names.cjs +9 -0
  225. package/dist/application/transform/numbered-names.cjs.map +1 -1
  226. package/dist/application/transform/numbered-names.mjs +9 -1
  227. package/dist/application/transform/numbered-names.mjs.map +1 -1
  228. package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
  229. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
  230. package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
  231. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
  232. package/dist/application/transform/ref-type.cjs +2 -1
  233. package/dist/application/transform/ref-type.cjs.map +1 -1
  234. package/dist/application/transform/ref-type.mjs +2 -1
  235. package/dist/application/transform/ref-type.mjs.map +1 -1
  236. package/dist/application/transform/schema/composition-type.cjs +1 -1
  237. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  238. package/dist/application/transform/schema/composition-type.mjs +2 -2
  239. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  240. package/dist/application/transform/schema/enum-rule.cjs +1 -1
  241. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  242. package/dist/application/transform/schema/enum-rule.mjs +2 -2
  243. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  244. package/dist/application/transform/schema/object-type.cjs +3 -3
  245. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  246. package/dist/application/transform/schema/object-type.mjs +4 -4
  247. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  248. package/dist/application/transform/schema/ref-siblings.cjs +47 -0
  249. package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
  250. package/dist/application/transform/schema/ref-siblings.mjs +45 -0
  251. package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
  252. package/dist/application/transform/schema/schema-transform.cjs +4 -2
  253. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  254. package/dist/application/transform/schema/schema-transform.mjs +4 -2
  255. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  256. package/dist/application/transform/schema-comment.cjs +5 -1
  257. package/dist/application/transform/schema-comment.cjs.map +1 -1
  258. package/dist/application/transform/schema-comment.mjs +5 -1
  259. package/dist/application/transform/schema-comment.mjs.map +1 -1
  260. package/dist/cli/api-settings.cjs +62 -6
  261. package/dist/cli/api-settings.cjs.map +1 -1
  262. package/dist/cli/api-settings.mjs +60 -7
  263. package/dist/cli/api-settings.mjs.map +1 -1
  264. package/dist/cli/api-writes.cjs +72 -0
  265. package/dist/cli/api-writes.cjs.map +1 -0
  266. package/dist/cli/api-writes.mjs +69 -0
  267. package/dist/cli/api-writes.mjs.map +1 -0
  268. package/dist/cli/cli-errors.cjs +12 -1
  269. package/dist/cli/cli-errors.cjs.map +1 -1
  270. package/dist/cli/cli-errors.mjs +12 -1
  271. package/dist/cli/cli-errors.mjs.map +1 -1
  272. package/dist/cli/cli-output.cjs +106 -1
  273. package/dist/cli/cli-output.cjs.map +1 -1
  274. package/dist/cli/cli-output.mjs +99 -2
  275. package/dist/cli/cli-output.mjs.map +1 -1
  276. package/dist/cli/main.cjs +5 -1
  277. package/dist/cli/main.cjs.map +1 -1
  278. package/dist/cli/main.mjs +6 -2
  279. package/dist/cli/main.mjs.map +1 -1
  280. package/dist/cli/redocly-apis.cjs +82 -36
  281. package/dist/cli/redocly-apis.cjs.map +1 -1
  282. package/dist/cli/redocly-apis.mjs +85 -39
  283. package/dist/cli/redocly-apis.mjs.map +1 -1
  284. package/dist/cli/run-cli.cjs +13 -7
  285. package/dist/cli/run-cli.cjs.map +1 -1
  286. package/dist/cli/run-cli.mjs +14 -8
  287. package/dist/cli/run-cli.mjs.map +1 -1
  288. package/dist/domain/append-all.cjs +10 -0
  289. package/dist/domain/append-all.cjs.map +1 -0
  290. package/dist/domain/append-all.mjs +8 -0
  291. package/dist/domain/append-all.mjs.map +1 -0
  292. package/dist/domain/cause-secrets.cjs +37 -0
  293. package/dist/domain/cause-secrets.cjs.map +1 -0
  294. package/dist/domain/cause-secrets.mjs +35 -0
  295. package/dist/domain/cause-secrets.mjs.map +1 -0
  296. package/dist/domain/errors.cjs +9 -3
  297. package/dist/domain/errors.cjs.map +1 -1
  298. package/dist/domain/errors.mjs +9 -3
  299. package/dist/domain/errors.mjs.map +1 -1
  300. package/dist/domain/ir/identifier-text.cjs.map +1 -1
  301. package/dist/domain/ir/identifier-text.mjs +1 -1
  302. package/dist/domain/ir/identifier-text.mjs.map +1 -1
  303. package/dist/domain/ir/ir-shape.cjs +187 -0
  304. package/dist/domain/ir/ir-shape.cjs.map +1 -0
  305. package/dist/domain/ir/ir-shape.mjs +184 -0
  306. package/dist/domain/ir/ir-shape.mjs.map +1 -0
  307. package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
  308. package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
  309. package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
  310. package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
  311. package/dist/domain/openapi/alias-expansion.cjs +3 -1
  312. package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
  313. package/dist/domain/openapi/alias-expansion.mjs +3 -1
  314. package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
  315. package/dist/domain/openapi/discriminated-union.cjs +3 -3
  316. package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
  317. package/dist/domain/openapi/discriminated-union.mjs +4 -4
  318. package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
  319. package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
  320. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
  321. package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
  322. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
  323. package/dist/domain/openapi/json-pointer.cjs +43 -1
  324. package/dist/domain/openapi/json-pointer.cjs.map +1 -1
  325. package/dist/domain/openapi/json-pointer.mjs +40 -2
  326. package/dist/domain/openapi/json-pointer.mjs.map +1 -1
  327. package/dist/domain/openapi/schema-dialect.cjs +15 -0
  328. package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
  329. package/dist/domain/openapi/schema-dialect.mjs +12 -0
  330. package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
  331. package/dist/domain/openapi/unsupported-features.cjs +1 -1
  332. package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
  333. package/dist/domain/openapi/unsupported-features.mjs +2 -2
  334. package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
  335. package/dist/domain/output-fixes.cjs +14 -0
  336. package/dist/domain/output-fixes.cjs.map +1 -1
  337. package/dist/domain/output-fixes.mjs +14 -0
  338. package/dist/domain/output-fixes.mjs.map +1 -1
  339. package/dist/domain/url-secrets.cjs +48 -0
  340. package/dist/domain/url-secrets.cjs.map +1 -0
  341. package/dist/domain/url-secrets.mjs +45 -0
  342. package/dist/domain/url-secrets.mjs.map +1 -0
  343. package/dist/index.d.cts +22 -4
  344. package/dist/index.d.mts +22 -4
  345. package/dist/index.d.ts +22 -4
  346. package/package.json +4 -5
  347. package/src/adapters/node-file-system/file-claims.ts +138 -0
  348. package/src/adapters/node-file-system/file-identity.ts +137 -0
  349. package/src/adapters/node-file-system/node-file-system.ts +145 -18
  350. package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
  351. package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
  352. package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
  353. package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
  354. package/src/adapters/redocly-loader/ref-access.ts +37 -3
  355. package/src/adapters/redocly-loader/ref-holders.ts +3 -3
  356. package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
  357. package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
  358. package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
  359. package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
  360. package/src/adapters/redocly-loader/schema-source.ts +20 -8
  361. package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
  362. package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
  363. package/src/api/default-ports.ts +33 -4
  364. package/src/api/discriminator-enum-parent.ts +3 -3
  365. package/src/api/discriminator-other-owners.ts +5 -3
  366. package/src/api/discriminator-patch.ts +5 -1
  367. package/src/api/discriminator-scan.ts +16 -8
  368. package/src/api/document-run.ts +4 -3
  369. package/src/api/legacy-utils.ts +5 -1
  370. package/src/api/openapi-ts.ts +20 -5
  371. package/src/api/run-context.ts +3 -0
  372. package/src/api/schema-callbacks.ts +60 -17
  373. package/src/api/transform-context.ts +7 -3
  374. package/src/api/transform-schema.ts +64 -12
  375. package/src/application/ports/file-system.ts +39 -0
  376. package/src/application/ports/schema-loader.ts +11 -1
  377. package/src/application/print/text-writer.ts +10 -3
  378. package/src/application/stack-overflow.ts +9 -5
  379. package/src/application/transform/document/components.ts +2 -2
  380. package/src/application/transform/document/declared-type-names.ts +36 -0
  381. package/src/application/transform/document/defs-root.ts +2 -2
  382. package/src/application/transform/document/document.ts +4 -3
  383. package/src/application/transform/document/enum-names-given-back.ts +91 -0
  384. package/src/application/transform/document/global-type-references.ts +1 -1
  385. package/src/application/transform/document/media-type.ts +4 -3
  386. package/src/application/transform/document/operation-keys-written.ts +27 -0
  387. package/src/application/transform/document/operation.ts +2 -2
  388. package/src/application/transform/document/parameter-entries.ts +70 -0
  389. package/src/application/transform/document/parameter.ts +21 -9
  390. package/src/application/transform/document/parameters.ts +11 -56
  391. package/src/application/transform/document/path-item.ts +13 -31
  392. package/src/application/transform/document/paths-enum.ts +1 -1
  393. package/src/application/transform/document/paths.ts +6 -2
  394. package/src/application/transform/document/referenced-parameter.ts +146 -0
  395. package/src/application/transform/document/request-body.ts +2 -2
  396. package/src/application/transform/document/response.ts +3 -3
  397. package/src/application/transform/document/responses.ts +2 -2
  398. package/src/application/transform/document/root-type-aliases.ts +17 -38
  399. package/src/application/transform/document/type-resolution.ts +2 -1
  400. package/src/application/transform/document/webhooks.ts +2 -2
  401. package/src/application/transform/footer/document-footer.ts +18 -1
  402. package/src/application/transform/footer/enum-name-claims.ts +62 -0
  403. package/src/application/transform/footer/operation-keys.ts +28 -0
  404. package/src/application/transform/footer/type-evaluation.ts +4 -4
  405. package/src/application/transform/helper-types.ts +6 -5
  406. package/src/application/transform/numbered-names.ts +15 -0
  407. package/src/application/transform/ref-pointer/generated-location.ts +2 -2
  408. package/src/application/transform/ref-type.ts +2 -1
  409. package/src/application/transform/schema/composition-type.ts +2 -2
  410. package/src/application/transform/schema/enum-rule.ts +6 -2
  411. package/src/application/transform/schema/object-type.ts +4 -4
  412. package/src/application/transform/schema/ref-siblings.ts +76 -0
  413. package/src/application/transform/schema/schema-context.ts +3 -0
  414. package/src/application/transform/schema/schema-transform.ts +4 -2
  415. package/src/application/transform/schema-comment.ts +5 -1
  416. package/src/application/transform/transform-context.ts +5 -0
  417. package/src/cli/api-settings.ts +82 -7
  418. package/src/cli/api-writes.ts +117 -0
  419. package/src/cli/cli-dependencies.ts +21 -4
  420. package/src/cli/cli-errors.ts +20 -1
  421. package/src/cli/cli-output.ts +186 -7
  422. package/src/cli/main.ts +6 -3
  423. package/src/cli/redocly-apis.ts +153 -48
  424. package/src/cli/run-cli.ts +37 -8
  425. package/src/domain/append-all.ts +10 -0
  426. package/src/domain/cause-secrets.ts +52 -0
  427. package/src/domain/errors.ts +14 -5
  428. package/src/domain/ir/identifier-text.ts +6 -5
  429. package/src/domain/ir/ir-shape.ts +299 -0
  430. package/src/domain/ir/newer-identifier-ranges.ts +183 -30
  431. package/src/domain/openapi/alias-expansion.ts +4 -1
  432. package/src/domain/openapi/discriminated-union.ts +6 -4
  433. package/src/domain/openapi/discriminator-conflicts.ts +21 -7
  434. package/src/domain/openapi/document-object.ts +2 -0
  435. package/src/domain/openapi/json-pointer.ts +96 -7
  436. package/src/domain/openapi/schema-dialect.ts +22 -0
  437. package/src/domain/openapi/unsupported-features.ts +2 -2
  438. package/src/domain/output-fixes.ts +21 -2
  439. package/src/domain/url-secrets.ts +72 -0
  440. package/src/types/generator-options.ts +1 -1
  441. package/dist/cli/main.d.cts +0 -2
  442. package/dist/cli/main.d.mts +0 -2
  443. package/dist/cli/main.d.ts +0 -2
  444. package/dist/domain/url-credentials.cjs +0 -10
  445. package/dist/domain/url-credentials.cjs.map +0 -1
  446. package/dist/domain/url-credentials.mjs +0 -8
  447. package/dist/domain/url-credentials.mjs.map +0 -1
  448. package/src/domain/url-credentials.ts +0 -18
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const RAW_TYPE_DECLARATION_RE = /^(?:export\s+)?(?:declare\s+)?(?:type|interface|enum|const\s+enum|class)\s+([A-Za-z_$][\w$]*)/gm;
4
+ function typeNamesInText(text) {
5
+ return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? "");
6
+ }
7
+ function typeNamesOf(declaration) {
8
+ switch (declaration.kind) {
9
+ case "rawDeclaration":
10
+ return declaration.name === void 0 ? typeNamesInText(declaration.text) : [declaration.name];
11
+ case "constArray":
12
+ return [];
13
+ default:
14
+ return [declaration.name];
15
+ }
16
+ }
17
+ function typeNamesDeclaredBy(declarations) {
18
+ return new Set(declarations.flatMap(typeNamesOf));
19
+ }
20
+
21
+ exports.typeNamesDeclaredBy = typeNamesDeclaredBy;
22
+ exports.typeNamesInText = typeNamesInText;
23
+ //# sourceMappingURL=declared-type-names.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-type-names.cjs","sources":["../../../../src/application/transform/document/declared-type-names.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The type names that declarations of the output take. Two declarations of one type name do not\n * compile (TS2300, TS2567), or merge into one type without an error (two enums, two interfaces).\n */\n\n/**\n * A declaration at the start of a line of raw text: the helper types, the `--read-write-markers`\n * types, `inject` text and footer nodes from user code. A `const` lives in the value namespace.\n */\nconst RAW_TYPE_DECLARATION_RE =\n /^(?:export\\s+)?(?:declare\\s+)?(?:type|interface|enum|const\\s+enum|class)\\s+([A-Za-z_$][\\w$]*)/gm;\n\n/** The type names that raw declaration text declares. */\nexport function typeNamesInText(text: string): string[] {\n return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? \"\");\n}\n\nfunction typeNamesOf(declaration: IrDeclaration): readonly string[] {\n switch (declaration.kind) {\n case \"rawDeclaration\":\n return declaration.name === undefined\n ? typeNamesInText(declaration.text)\n : [declaration.name];\n case \"constArray\":\n return [];\n default:\n return [declaration.name];\n }\n}\n\n/** Every type name the declarations take; `--enum-values` arrays are values, so they take none. */\nexport function typeNamesDeclaredBy(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(declarations.flatMap(typeNamesOf));\n}\n"],"names":[],"mappings":";;AAWA,MAAM,uBAAA,GACJ,iGAAA;AAGK,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,uBAAuB,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,KAAA,KAAU,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAClF;AAEA,SAAS,YAAY,WAAA,EAA+C;AAClE,EAAA,QAAQ,YAAY,IAAA;AAAM,IACxB,KAAK,gBAAA;AACH,MAAA,OAAO,WAAA,CAAY,SAAS,MAAA,GACxB,eAAA,CAAgB,YAAY,IAAI,CAAA,GAChC,CAAC,WAAA,CAAY,IAAI,CAAA;AAAA,IACvB,KAAK,YAAA;AACH,MAAA,OAAO,EAAC;AAAA,IACV;AACE,MAAA,OAAO,CAAC,YAAY,IAAI,CAAA;AAAA;AAE9B;AAGO,SAAS,oBAAoB,YAAA,EAAqD;AACvF,EAAA,OAAO,IAAI,GAAA,CAAI,YAAA,CAAa,OAAA,CAAQ,WAAW,CAAC,CAAA;AAClD;;;"}
@@ -0,0 +1,20 @@
1
+ const RAW_TYPE_DECLARATION_RE = /^(?:export\s+)?(?:declare\s+)?(?:type|interface|enum|const\s+enum|class)\s+([A-Za-z_$][\w$]*)/gm;
2
+ function typeNamesInText(text) {
3
+ return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? "");
4
+ }
5
+ function typeNamesOf(declaration) {
6
+ switch (declaration.kind) {
7
+ case "rawDeclaration":
8
+ return declaration.name === void 0 ? typeNamesInText(declaration.text) : [declaration.name];
9
+ case "constArray":
10
+ return [];
11
+ default:
12
+ return [declaration.name];
13
+ }
14
+ }
15
+ function typeNamesDeclaredBy(declarations) {
16
+ return new Set(declarations.flatMap(typeNamesOf));
17
+ }
18
+
19
+ export { typeNamesDeclaredBy, typeNamesInText };
20
+ //# sourceMappingURL=declared-type-names.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-type-names.mjs","sources":["../../../../src/application/transform/document/declared-type-names.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The type names that declarations of the output take. Two declarations of one type name do not\n * compile (TS2300, TS2567), or merge into one type without an error (two enums, two interfaces).\n */\n\n/**\n * A declaration at the start of a line of raw text: the helper types, the `--read-write-markers`\n * types, `inject` text and footer nodes from user code. A `const` lives in the value namespace.\n */\nconst RAW_TYPE_DECLARATION_RE =\n /^(?:export\\s+)?(?:declare\\s+)?(?:type|interface|enum|const\\s+enum|class)\\s+([A-Za-z_$][\\w$]*)/gm;\n\n/** The type names that raw declaration text declares. */\nexport function typeNamesInText(text: string): string[] {\n return [...text.matchAll(RAW_TYPE_DECLARATION_RE)].map((match) => match[1] ?? \"\");\n}\n\nfunction typeNamesOf(declaration: IrDeclaration): readonly string[] {\n switch (declaration.kind) {\n case \"rawDeclaration\":\n return declaration.name === undefined\n ? typeNamesInText(declaration.text)\n : [declaration.name];\n case \"constArray\":\n return [];\n default:\n return [declaration.name];\n }\n}\n\n/** Every type name the declarations take; `--enum-values` arrays are values, so they take none. */\nexport function typeNamesDeclaredBy(declarations: readonly IrDeclaration[]): Set<string> {\n return new Set(declarations.flatMap(typeNamesOf));\n}\n"],"names":[],"mappings":"AAWA,MAAM,uBAAA,GACJ,iGAAA;AAGK,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,uBAAuB,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,KAAA,KAAU,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAClF;AAEA,SAAS,YAAY,WAAA,EAA+C;AAClE,EAAA,QAAQ,YAAY,IAAA;AAAM,IACxB,KAAK,gBAAA;AACH,MAAA,OAAO,WAAA,CAAY,SAAS,MAAA,GACxB,eAAA,CAAgB,YAAY,IAAI,CAAA,GAChC,CAAC,WAAA,CAAY,IAAI,CAAA;AAAA,IACvB,KAAK,YAAA;AACH,MAAA,OAAO,EAAC;AAAA,IACV;AACE,MAAA,OAAO,CAAC,YAAY,IAAI,CAAA;AAAA;AAE9B;AAGO,SAAS,oBAAoB,YAAA,EAAqD;AACvF,EAAA,OAAO,IAAI,GAAA,CAAI,YAAA,CAAa,OAAA,CAAQ,WAAW,CAAC,CAAA;AAClD;;"}
@@ -7,7 +7,7 @@ const schemaTransform = require('../schema/schema-transform.cjs');
7
7
 
8
8
  function defsRootType(defs, context) {
9
9
  const members = Object.entries(defs).map(([name, schema]) => {
10
- const location = { path: jsonPointer.createRef(["$defs", name]), schema };
10
+ const location = { path: jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, ["$defs", name]), schema };
11
11
  const type = schemaTransform.transformSchema(schema, location, context);
12
12
  return constructors.irProperty(propertyName.toPropertyName(name), type, { isReadonly: context.options.immutable });
13
13
  });
@@ -1 +1 @@
1
- {"version":3,"file":"defs-root.cjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: createRef([\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":["createRef","transformSchema","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMA,qBAAA,CAAU,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC5D,IAAA,MAAM,IAAA,GAAOC,+BAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,IAAA,OAAOC,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;;"}
1
+ {"version":3,"file":"defs-root.cjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":["appendPointer","ROOT_POINTER","transformSchema","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMA,yBAAA,CAAcC,wBAAA,EAAc,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC9E,IAAA,MAAM,IAAA,GAAOC,+BAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,IAAA,OAAOC,uBAAA,CAAWC,2BAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;;"}
@@ -1,11 +1,11 @@
1
1
  import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
2
2
  import { toPropertyName } from '../../../domain/ir/property-name.mjs';
3
- import { createRef } from '../../../domain/openapi/json-pointer.mjs';
3
+ import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
4
4
  import { transformSchema } from '../schema/schema-transform.mjs';
5
5
 
6
6
  function defsRootType(defs, context) {
7
7
  const members = Object.entries(defs).map(([name, schema]) => {
8
- const location = { path: createRef(["$defs", name]), schema };
8
+ const location = { path: appendPointer(ROOT_POINTER, ["$defs", name]), schema };
9
9
  const type = transformSchema(schema, location, context);
10
10
  return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
11
11
  });
@@ -1 +1 @@
1
- {"version":3,"file":"defs-root.mjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: createRef([\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,SAAA,CAAU,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC5D,IAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,IAAA,OAAO,UAAA,CAAW,cAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;;"}
1
+ {"version":3,"file":"defs-root.mjs","sources":["../../../../src/application/transform/document/defs-root.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrObjectType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/**\n * The root `$defs` type: one required member per named subschema, so `#/$defs/<name>` refs\n * (`$defs[\"<name>\"]`) resolve. The original transformed the whole `$defs` map as one schema,\n * which gave `Record<string, never>` and made every such ref `never` (research/legacy-bugs.md,\n * item 18).\n */\nexport function defsRootType(\n defs: Readonly<Record<string, Schema>>,\n context: TransformContext,\n): IrObjectType {\n const members = Object.entries(defs).map(([name, schema]) => {\n const location = { path: appendPointer(ROOT_POINTER, [\"$defs\", name]), schema };\n const type = transformSchema(schema, location, context);\n return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,YAAA,CACd,MACA,OAAA,EACc;AACd,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,KAAM;AAC3D,IAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,aAAA,CAAc,YAAA,EAAc,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA,EAAG,MAAA,EAAO;AAC9E,IAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AACtD,IAAA,OAAO,UAAA,CAAW,cAAA,CAAe,IAAI,CAAA,EAAG,IAAA,EAAM,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EACzF,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;;"}
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const appendAll = require('../../../domain/append-all.cjs');
3
4
  const constructors = require('../../../domain/ir/constructors.cjs');
4
5
  const helperTypes = require('../helper-types.cjs');
5
6
  const components = require('./components.cjs');
@@ -90,7 +91,7 @@ function documentBody(document, context, footer = NO_FOOTER) {
90
91
  if (inject !== "") {
91
92
  declarations.push({ kind: "rawDeclaration", text: inject });
92
93
  }
93
- declarations.push(...rootsDeclarations(document, context, footer));
94
+ appendAll.appendAll(declarations, rootsDeclarations(document, context, footer));
94
95
  return declarations;
95
96
  }
96
97
  function documentClosing(document, context, hasOperations) {
@@ -104,6 +105,8 @@ function documentClosing(document, context, hasOperations) {
104
105
  return declarations;
105
106
  }
106
107
 
108
+ exports.OPERATIONS_NAME = OPERATIONS_NAME;
109
+ exports.ROOT_KEYS = ROOT_KEYS;
107
110
  exports.documentBody = documentBody;
108
111
  exports.documentClosing = documentClosing;
109
112
  //# sourceMappingURL=document.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.cjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nconst ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nconst OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n declarations.push(...rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeLookup","READ_WRITE_MARKER_TYPES","apiPathsEnumDeclaration"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU,CAAA;AAGrF,MAAM,eAAA,GAAkB,YAAA;AAExB,MAAM,kBAAkBA,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAGA,sBAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnBC,yCAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAUC,iBAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,O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../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeLookup","READ_WRITE_MARKER_TYPES","appendAll","apiPathsEnumDeclaration"],"mappings":";;;;;;;;;;;;;AAuBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkBA,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAGA,sBAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnBC,yCAAA,CAAyB,U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AI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;;;;"}
@@ -1,3 +1,4 @@
1
+ import { appendAll } from '../../../domain/append-all.mjs';
1
2
  import { irRecord, irObject, irKeyword } from '../../../domain/ir/constructors.mjs';
2
3
  import { READ_WRITE_MARKER_TYPES } from '../helper-types.mjs';
3
4
  import { componentsType } from './components.mjs';
@@ -88,7 +89,7 @@ function documentBody(document, context, footer = NO_FOOTER) {
88
89
  if (inject !== "") {
89
90
  declarations.push({ kind: "rawDeclaration", text: inject });
90
91
  }
91
- declarations.push(...rootsDeclarations(document, context, footer));
92
+ appendAll(declarations, rootsDeclarations(document, context, footer));
92
93
  return declarations;
93
94
  }
94
95
  function documentClosing(document, context, hasOperations) {
@@ -102,5 +103,5 @@ function documentClosing(document, context, hasOperations) {
102
103
  return declarations;
103
104
  }
104
105
 
105
- export { documentBody, documentClosing };
106
+ export { OPERATIONS_NAME, ROOT_KEYS, documentBody, documentClosing };
106
107
  //# sourceMappingURL=document.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nconst ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nconst OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n declarations.push(...rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAsBA,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU,CAAA;AAGrF,MAAM,eAAA,GAAkB,YAAA;AAExB,MAAM,kBAAkB,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,SAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnB,wBAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAAS,EAAC;AAAA,MACV,iBAAA,EAAmB,CAAC,MAAA,KAAW,eAAA,CAAgB,SAAS,MAAM;AAAA,KAChE;AAAA,EACF,CAAA;AAAA,EACA,QAAA,EAAU,CAAC,IAAA,EAAM,OAAA,MAAa,EAAE,IAAA,EAAM,YAAA,CAAa,IAAA,EAAqB,OAAO,CAAA,EAAG,OAAA,EAAS,EAA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EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,yBAAyB,CAAA;AAAA,EAC7E;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAA,CAAQ,UAAU,EAAE,CAAA;AACnE,EAAA,IAAI,WAAW,EAAA,EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,YAAA,CAAa,KAAK,GAAG,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACjE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAK,uBAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;"}
1
+ {"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAuBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkB,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,SAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnB,wBAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAAS,EAAC;AAAA,MACV,iBAAA,EAAmB,CAAC,MAAA,KAAW,eAAA,CAAgB,SAAS,MAAM;AAAA,KAChE;AAAA,EACF,CAAA;AAAA,EACA,QAAA,EAAU,CAAC,IAAA,EAAM,OAAA,MAAa,EAAE,I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AAI,OAAA,CAAQ,QAAQ,gBAAA,EAAkB;AACpC,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,yBAAyB,CAAA;AAAA,EAC7E;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAA,CAAQ,UAAU,EAAE,CAAA;AACnE,EAAA,IAAI,WAAW,EAAA,EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,SAAA,CAAU,YAAA,EAAc,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAK,uBAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;"}
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const helperTypes = require('../helper-types.cjs');
4
+ const declaredTypeNames = require('./declared-type-names.cjs');
5
+ const document = require('./document.cjs');
6
+ const globalTypeReferences = require('./global-type-references.cjs');
7
+ const pathsEnum = require('./paths-enum.cjs');
8
+ const rootTypeAliases = require('./root-type-aliases.cjs');
9
+
10
+ const NAMES_THE_OUTPUT_MAY_NEED = /* @__PURE__ */ new Set([
11
+ ...globalTypeReferences.GLOBAL_TYPE_NAMES,
12
+ ...Object.values(helperTypes.HELPER_TYPES).map(({ name }) => name),
13
+ ...declaredTypeNames.typeNamesInText(helperTypes.READ_WRITE_MARKER_TYPES),
14
+ pathsEnum.API_PATHS_NAME,
15
+ ...document.ROOT_KEYS,
16
+ document.OPERATIONS_NAME
17
+ ]);
18
+ function namesTheOutputNeeds({ body, footer, closing }) {
19
+ const others = [
20
+ ...body.filter((declaration) => !rootTypeAliases.isRootTypeAlias(declaration)),
21
+ ...footer.filter((declaration) => declaration.kind !== "enum"),
22
+ ...closing
23
+ ];
24
+ return /* @__PURE__ */ new Set([
25
+ ...globalTypeReferences.globalTypeReferences([...body, ...footer, ...closing]),
26
+ ...declaredTypeNames.typeNamesDeclaredBy(others)
27
+ ]);
28
+ }
29
+ const SKIPPED_KEYS = /* @__PURE__ */ new Set(["origin"]);
30
+ const ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\..*)?$/s;
31
+ function renamedReference(name, renames) {
32
+ const match = ENUM_REFERENCE_RE.exec(name);
33
+ const renamed = match === null ? void 0 : renames.get(match[2] ?? "");
34
+ return renamed === void 0 ? name : `${match?.[1] ?? ""}${renamed}${match?.[3] ?? ""}`;
35
+ }
36
+ function isNode(value) {
37
+ return typeof value === "object" && value !== null;
38
+ }
39
+ function renamedNode(value, renames) {
40
+ if (Array.isArray(value)) {
41
+ return value.map((item) => renamedNode(item, renames));
42
+ }
43
+ if (!isNode(value)) {
44
+ return value;
45
+ }
46
+ const node = Object.fromEntries(
47
+ Object.entries(value).map(([key, child]) => [
48
+ key,
49
+ SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames)
50
+ ])
51
+ );
52
+ const isNamed = (node.kind === "reference" || node.kind === "enum") && typeof node.name === "string";
53
+ return isNamed ? { ...node, name: renamedReference(node.name, renames) } : node;
54
+ }
55
+ function withEnumsRenamed(declarations, renames) {
56
+ return renames.size === 0 ? [...declarations] : renamedNode(declarations, renames);
57
+ }
58
+
59
+ exports.NAMES_THE_OUTPUT_MAY_NEED = NAMES_THE_OUTPUT_MAY_NEED;
60
+ exports.namesTheOutputNeeds = namesTheOutputNeeds;
61
+ exports.withEnumsRenamed = withEnumsRenamed;
62
+ //# sourceMappingURL=enum-names-given-back.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-names-given-back.cjs","sources":["../../../../src/application/transform/document/enum-names-given-back.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport { typeNamesDeclaredBy, typeNamesInText } from \"./declared-type-names.js\";\nimport { OPERATIONS_NAME, ROOT_KEYS } from \"./document.js\";\nimport { GLOBAL_TYPE_NAMES, globalTypeReferences } from \"./global-type-references.js\";\nimport { API_PATHS_NAME } from \"./paths-enum.js\";\nimport { isRootTypeAlias } from \"./root-type-aliases.js\";\n\n/**\n * The second step of naming `--enum` declarations (`EnumNameClaims`): once the output is known,\n * an enum that gave way to a name the output turned out not to need gets that name back.\n */\n\n/**\n * The type names the output of a document may need, besides its enums: the global types it may\n * refer to and the names the generator declares itself. An enum avoids them until the end.\n */\nexport const NAMES_THE_OUTPUT_MAY_NEED: ReadonlySet<string> = new Set([\n ...GLOBAL_TYPE_NAMES,\n ...Object.values(HELPER_TYPES).map(({ name }) => name),\n ...typeNamesInText(READ_WRITE_MARKER_TYPES),\n API_PATHS_NAME,\n ...ROOT_KEYS,\n OPERATIONS_NAME,\n]);\n\n/** The parts of a transformed document; the footer holds only IR declarations here. */\nexport interface DocumentParts {\n readonly body: readonly IrDeclaration[];\n readonly footer: readonly IrDeclaration[];\n readonly closing: readonly IrDeclaration[];\n}\n\n/**\n * The type names the output needs besides its enums: the globals it refers to, and the names of\n * its other declarations. Root aliases give way to enums (`renameTakenAliases`), so they count\n * for nothing.\n */\nexport function namesTheOutputNeeds({ body, footer, closing }: DocumentParts): Set<string> {\n const others = [\n ...body.filter((declaration) => !isRootTypeAlias(declaration)),\n ...footer.filter((declaration) => declaration.kind !== \"enum\"),\n ...closing,\n ];\n return new Set([\n ...globalTypeReferences([...body, ...footer, ...closing]),\n ...typeNamesDeclaredBy(others),\n ]);\n}\n\n/** `origin` holds the compiler node a raw type was printed from; it is not IR. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\"]);\n\n/** The enum references the generator writes: `Name`, `Name.member` and `typeof Name`. */\nconst ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\\..*)?$/s;\n\nfunction renamedReference(name: string, renames: ReadonlyMap<string, string>): string {\n const match = ENUM_REFERENCE_RE.exec(name);\n const renamed = match === null ? undefined : renames.get(match[2] ?? \"\");\n return renamed === undefined ? name : `${match?.[1] ?? \"\"}${renamed}${match?.[3] ?? \"\"}`;\n}\n\nfunction isNode(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction renamedNode(value: unknown, renames: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => renamedNode(item, renames));\n }\n if (!isNode(value)) {\n return value;\n }\n const node = Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames),\n ]),\n );\n const isNamed =\n (node.kind === \"reference\" || node.kind === \"enum\") && typeof node.name === \"string\";\n return isNamed ? { ...node, name: renamedReference(node.name as string, renames) } : node;\n}\n\n/** The declarations with each enum in `renames` (old name to new) renamed, references too. */\nexport function withEnumsRenamed<T extends IrDeclaration>(\n declarations: readonly T[],\n renames: ReadonlyMap<string, string>,\n): T[] {\n return renames.size === 0 ? [...declarations] : (renamedNode(declarations, renames) as T[]);\n}\n"],"names":["GLOBAL_TYPE_NAMES","HELPER_TYPES","typeNamesInText","READ_WRITE_MARKER_TYPES","API_PATHS_NAME","ROOT_KEYS","OPERATIONS_NAME","isRootTypeAlias","globalTypeReferences","typeNamesDeclaredBy"],"mappings":";;;;;;;;;AAiBO,MAAM,yBAAA,uBAAqD,GAAA,CAAI;AAAA,EACpE,GAA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+ import { ROOT_KEYS, OPERATIONS_NAME } from './document.mjs';
4
+ import { GLOBAL_TYPE_NAMES, globalTypeReferences } from './global-type-references.mjs';
5
+ import { API_PATHS_NAME } from './paths-enum.mjs';
6
+ import { isRootTypeAlias } from './root-type-aliases.mjs';
7
+
8
+ const NAMES_THE_OUTPUT_MAY_NEED = /* @__PURE__ */ new Set([
9
+ ...GLOBAL_TYPE_NAMES,
10
+ ...Object.values(HELPER_TYPES).map(({ name }) => name),
11
+ ...typeNamesInText(READ_WRITE_MARKER_TYPES),
12
+ API_PATHS_NAME,
13
+ ...ROOT_KEYS,
14
+ OPERATIONS_NAME
15
+ ]);
16
+ function namesTheOutputNeeds({ body, footer, closing }) {
17
+ const others = [
18
+ ...body.filter((declaration) => !isRootTypeAlias(declaration)),
19
+ ...footer.filter((declaration) => declaration.kind !== "enum"),
20
+ ...closing
21
+ ];
22
+ return /* @__PURE__ */ new Set([
23
+ ...globalTypeReferences([...body, ...footer, ...closing]),
24
+ ...typeNamesDeclaredBy(others)
25
+ ]);
26
+ }
27
+ const SKIPPED_KEYS = /* @__PURE__ */ new Set(["origin"]);
28
+ const ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\..*)?$/s;
29
+ function renamedReference(name, renames) {
30
+ const match = ENUM_REFERENCE_RE.exec(name);
31
+ const renamed = match === null ? void 0 : renames.get(match[2] ?? "");
32
+ return renamed === void 0 ? name : `${match?.[1] ?? ""}${renamed}${match?.[3] ?? ""}`;
33
+ }
34
+ function isNode(value) {
35
+ return typeof value === "object" && value !== null;
36
+ }
37
+ function renamedNode(value, renames) {
38
+ if (Array.isArray(value)) {
39
+ return value.map((item) => renamedNode(item, renames));
40
+ }
41
+ if (!isNode(value)) {
42
+ return value;
43
+ }
44
+ const node = Object.fromEntries(
45
+ Object.entries(value).map(([key, child]) => [
46
+ key,
47
+ SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames)
48
+ ])
49
+ );
50
+ const isNamed = (node.kind === "reference" || node.kind === "enum") && typeof node.name === "string";
51
+ return isNamed ? { ...node, name: renamedReference(node.name, renames) } : node;
52
+ }
53
+ function withEnumsRenamed(declarations, renames) {
54
+ return renames.size === 0 ? [...declarations] : renamedNode(declarations, renames);
55
+ }
56
+
57
+ export { NAMES_THE_OUTPUT_MAY_NEED, namesTheOutputNeeds, withEnumsRenamed };
58
+ //# sourceMappingURL=enum-names-given-back.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-names-given-back.mjs","sources":["../../../../src/application/transform/document/enum-names-given-back.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\nimport { HELPER_TYPES, READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport { typeNamesDeclaredBy, typeNamesInText } from \"./declared-type-names.js\";\nimport { OPERATIONS_NAME, ROOT_KEYS } from \"./document.js\";\nimport { GLOBAL_TYPE_NAMES, globalTypeReferences } from \"./global-type-references.js\";\nimport { API_PATHS_NAME } from \"./paths-enum.js\";\nimport { isRootTypeAlias } from \"./root-type-aliases.js\";\n\n/**\n * The second step of naming `--enum` declarations (`EnumNameClaims`): once the output is known,\n * an enum that gave way to a name the output turned out not to need gets that name back.\n */\n\n/**\n * The type names the output of a document may need, besides its enums: the global types it may\n * refer to and the names the generator declares itself. An enum avoids them until the end.\n */\nexport const NAMES_THE_OUTPUT_MAY_NEED: ReadonlySet<string> = new Set([\n ...GLOBAL_TYPE_NAMES,\n ...Object.values(HELPER_TYPES).map(({ name }) => name),\n ...typeNamesInText(READ_WRITE_MARKER_TYPES),\n API_PATHS_NAME,\n ...ROOT_KEYS,\n OPERATIONS_NAME,\n]);\n\n/** The parts of a transformed document; the footer holds only IR declarations here. */\nexport interface DocumentParts {\n readonly body: readonly IrDeclaration[];\n readonly footer: readonly IrDeclaration[];\n readonly closing: readonly IrDeclaration[];\n}\n\n/**\n * The type names the output needs besides its enums: the globals it refers to, and the names of\n * its other declarations. Root aliases give way to enums (`renameTakenAliases`), so they count\n * for nothing.\n */\nexport function namesTheOutputNeeds({ body, footer, closing }: DocumentParts): Set<string> {\n const others = [\n ...body.filter((declaration) => !isRootTypeAlias(declaration)),\n ...footer.filter((declaration) => declaration.kind !== \"enum\"),\n ...closing,\n ];\n return new Set([\n ...globalTypeReferences([...body, ...footer, ...closing]),\n ...typeNamesDeclaredBy(others),\n ]);\n}\n\n/** `origin` holds the compiler node a raw type was printed from; it is not IR. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\"]);\n\n/** The enum references the generator writes: `Name`, `Name.member` and `typeof Name`. */\nconst ENUM_REFERENCE_RE = /^(typeof )?([^.]+)(\\..*)?$/s;\n\nfunction renamedReference(name: string, renames: ReadonlyMap<string, string>): string {\n const match = ENUM_REFERENCE_RE.exec(name);\n const renamed = match === null ? undefined : renames.get(match[2] ?? \"\");\n return renamed === undefined ? name : `${match?.[1] ?? \"\"}${renamed}${match?.[3] ?? \"\"}`;\n}\n\nfunction isNode(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction renamedNode(value: unknown, renames: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => renamedNode(item, renames));\n }\n if (!isNode(value)) {\n return value;\n }\n const node = Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n SKIPPED_KEYS.has(key) ? child : renamedNode(child, renames),\n ]),\n );\n const isNamed =\n (node.kind === \"reference\" || node.kind === \"enum\") && typeof node.name === \"string\";\n return isNamed ? { ...node, name: renamedReference(node.name as string, renames) } : node;\n}\n\n/** The declarations with each enum in `renames` (old name to new) renamed, references too. */\nexport function withEnumsRenamed<T extends IrDeclaration>(\n declarations: readonly T[],\n renames: ReadonlyMap<string, string>,\n): T[] {\n return renames.size === 0 ? [...declarations] : (renamedNode(declarations, renames) as T[]);\n}\n"],"names":[],"mappings":";;;;;;;AAiBO,MAAM,yBAAA,uBAAqD,GAAA,CAAI;AAAA,EACpE,GAAG,iBAAA;AAAA,EACH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AA4D;AAC1E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,WAAA,CAAY,OAAgB,OAAA,EAA+C;AAClF,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,MAAM,GAAA,CAAI,CAAC,SAAS,WAAA,CAAY,IAAA,EAAM,OAAO,CAAC,CAAA;AAAA,EACvD;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,KAAK,CAAA,EAAG;AAClB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAO,MAAA,CAAO,WAAA;AAAA,IAClB,MAAA,CAAO,QAAQ,KAAK,CAAA,CAAE,IAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM;AAAA,MAC1C,GAAA;AAAA,MACA,aAAa,GAAA,CAAI,GAAG,IAAI,KAAA,GAAQ,WAAA,CAAY,OAAO,OAAO;AAAA,KAC3D;AAAA,GACH;AACA,EAAA,MAAM,OAAA,GAAA,CACH,KAAK,IAAA,KAAS,WAAA,IAAe,KAAK,IAAA,KAAS,MAAA,KAAW,OAAO,IAAA,CAAK,IAAA,KAAS,QAAA;AAC9E,EAAA,OAAO,OAAA,GAAU,EAAE,GAAG,IAAA,EAAM,IAAA,EAAM,iBAAiB,IAAA,CAAK,IAAA,EAAgB,OAAO,CAAA,EAAE,GAAI,IAAA;AACvF;AAGO,SAAS,gBAAA,CACd,cACA,OAAA,EACK;AACL,EAAA,OAAO,OAAA,CAAQ,SAAS,CAAA,GAAI,CAAC,GAAG,YAAY,CAAA,GAAK,WAAA,CAAY,YAAA,EAAc,OAAO,CAAA;AACpF;;"}
@@ -59,5 +59,6 @@ function globalTypeReferences(declarations) {
59
59
  return used;
60
60
  }
61
61
 
62
+ exports.GLOBAL_TYPE_NAMES = GLOBAL_TYPE_NAMES;
62
63
  exports.globalTypeReferences = globalTypeReferences;
63
64
  //# sourceMappingURL=global-type-references.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"global-type-references.cjs","sources":["../../../../src/application/transform/document/global-type-references.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The TypeScript global types that generated code can refer to: in references (`Record<string,\n * never>`, `Omit<…>`, the `Blob` of `--binary-as-blob`) and in the text of footer helpers\n * (`Exclude<…>`, `Readonly<…>`). A module declaration of the same name shadows the global: every\n * use of it then fails to compile, or silently names the module's type (`Blob`).\n */\nconst GLOBAL_TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Array\",\n \"Blob\",\n \"Exclude\",\n \"Extract\",\n \"NonNullable\",\n \"Omit\",\n \"Partial\",\n \"Pick\",\n \"Readonly\",\n \"ReadonlyArray\",\n \"Record\",\n \"Required\",\n]);\n\nconst GENERIC_USE = /\\b([A-Z][A-Za-z]*)\\s*</g;\n\n/** `origin` holds the outside node a raw type was printed from; it is not part of the output. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\", \"comments\"]);\n\nfunction isObject(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction addTextUses(text: string, used: Set<string>): void {\n for (const match of text.matchAll(GENERIC_USE)) {\n const name = match[1] ?? \"\";\n if (GLOBAL_TYPE_NAMES.has(name)) {\n used.add(name);\n }\n }\n}\n\nfunction addNodeUses(node: Readonly<Record<string, unknown>>, used: Set<string>): void {\n if (node.kind === \"reference\" && typeof node.name === \"string\") {\n if (GLOBAL_TYPE_NAMES.has(node.name)) {\n used.add(node.name);\n }\n } else if (\n (node.kind === \"raw\" || node.kind === \"rawDeclaration\") &&\n typeof node.text === \"string\"\n ) {\n addTextUses(node.text, used);\n }\n}\n\nfunction visit(value: unknown, used: Set<string>): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n visit(item, used);\n }\n return;\n }\n if (!isObject(value)) {\n return;\n }\n addNodeUses(value, used);\n for (const [key, child] of Object.entries(value)) {\n if (!SKIPPED_KEYS.has(key)) {\n visit(child, used);\n }\n }\n}\n\n/** The TypeScript global type names that the declarations refer to. */\nexport function globalTypeReferences(declarations: readonly IrDeclaration[]): Set<string> {\n const used = new Set<string>();\n visit(declarations, used);\n return used;\n}\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,uBAA6C,GAAA,CAAI;AAAA,EACrD,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,WAAA,GAAc,yBAAA;AAGpB,MAAM,+BAAoC,IAAI,GAAA,CAAI,CAAC,QAAA,EAAU,UAAU,CAAC,CAAA;AAExE,SAAS,SAAS,KAAA,EAA4D;AAC5E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,WAAA,CAAY,MAAc,IAAA,EAAyB;AAC1D,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,CAAS,WAAW,CAAA,EAAG;AAC9C,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,CAAC,CAAA,IAAK,EAAA;AACzB,IAAA,IAAI,iBAAA,CAAkB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC/B,MAAA,IAAA,CAAK,IAAI,IAAI,CAAA;AAAA,IACf;AAAA,EACF;AACF;AAEA,SAAS,WAAA,CAAY,MAAyC,IAAA,EAAyB;AACrF,EAAA,IAAI,KAAK,IAAA,KAAS,WAAA,IAAe,OAAO,IAAA,CAAK,SAAS,QAAA,EAAU;AAC9D,IAAA,IAAI,iBAAA,CAAkB,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA,EAAG;AACpC,MAAA,IAAA,CAAK,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA,IACpB;AAAA,EACF,CAAA,MAAA,IAAA,CACG,IAAA,CAAK,IAAA,KAAS,KAAA,IAAS,IAAA,CAAK,SAAS,gBAAA,KACtC,OAAO,IAAA,CAAK,IAAA,KAAS,QAAA,EACrB;AACA,IAAA,WAAA,CAAY,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,EAC7B;AACF;AAEA,SAAS,KAAA,CAAM,OAAgB,IAAA,EAAyB;AACtD,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,IAClB;AACA,IAAA;AAAA,EACF;AACA,EAAA,IAAI,CAAC,QAAA,CAAS,KAAK,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AACA,EAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AACvB,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,CAAC,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA,EAAG;AAC1B,MAAA,KAAA,CAAM,OAAO,IAAI,CAAA;AAAA,IACnB;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,YAAA,EAAqD;AACxF,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,KAAA,CAAM,cAAc,IAAI,CAAA;AACxB,EAAA,OAAO,IAAA;AACT;;"}
1
+ {"version":3,"file":"global-type-references.cjs","sources":["../../../../src/application/transform/document/global-type-references.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The TypeScript global types that generated code can refer to: in references (`Record<string,\n * never>`, `Omit<…>`, the `Blob` of `--binary-as-blob`) and in the text of footer helpers\n * (`Exclude<…>`, `Readonly<…>`). A module declaration of the same name shadows the global: every\n * use of it then fails to compile, or silently names the module's type (`Blob`).\n */\nexport const GLOBAL_TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Array\",\n \"Blob\",\n \"Exclude\",\n \"Extract\",\n \"NonNullable\",\n \"Omit\",\n \"Partial\",\n \"Pick\",\n \"Readonly\",\n \"ReadonlyArray\",\n \"Record\",\n \"Required\",\n]);\n\nconst GENERIC_USE = /\\b([A-Z][A-Za-z]*)\\s*</g;\n\n/** `origin` holds the outside node a raw type was printed from; it is not part of the output. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\", \"comments\"]);\n\nfunction isObject(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction addTextUses(text: string, used: Set<string>): void {\n for (const match of text.matchAll(GENERIC_USE)) {\n const name = match[1] ?? \"\";\n if (GLOBAL_TYPE_NAMES.has(name)) {\n used.add(name);\n }\n }\n}\n\nfunction addNodeUses(node: Readonly<Record<string, unknown>>, used: Set<string>): void {\n if (node.kind === \"reference\" && typeof node.name === \"string\") {\n if (GLOBAL_TYPE_NAMES.has(node.name)) {\n used.add(node.name);\n }\n } else if (\n (node.kind === \"raw\" || node.kind === \"rawDeclaration\") &&\n typeof node.text === \"string\"\n ) {\n addTextUses(node.text, used);\n }\n}\n\nfunction visit(value: unknown, used: Set<string>): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n visit(item, used);\n }\n return;\n }\n if (!isObject(value)) {\n return;\n }\n addNodeUses(value, used);\n for (const [key, child] of Object.entries(value)) {\n if (!SKIPPED_KEYS.has(key)) {\n visit(child, used);\n }\n }\n}\n\n/** The TypeScript global type names that the declarations refer to. */\nexport function globalTypeReferences(declarations: readonly IrDeclaration[]): Set<string> {\n const used = new Set<string>();\n visit(declarations, used);\n return used;\n}\n"],"names":[],"mappings":";;AAQO,MAAM,iBAAA,uBAA6C,GAAA,CAAI;AAAA,EAC5D,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,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A,EAAG;AACxB,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,IAClB;AACA,IAAA;AAAA,EACF;AACA,EAAA,IAAI,CAAC,QAAA,CAAS,KAAK,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AACA,EAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AACvB,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,CAAC,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA,EAAG;AAC1B,MAAA,KAAA,CAAM,OAAO,IAAI,CAAA;AAAA,IACnB;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,YAAA,EAAqD;AACxF,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,KAAA,CAAM,cAAc,IAAI,CAAA;AACxB,EAAA,OAAO,IAAA;AACT;;;"}
@@ -57,5 +57,5 @@ function globalTypeReferences(declarations) {
57
57
  return used;
58
58
  }
59
59
 
60
- export { globalTypeReferences };
60
+ export { GLOBAL_TYPE_NAMES, globalTypeReferences };
61
61
  //# sourceMappingURL=global-type-references.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"global-type-references.mjs","sources":["../../../../src/application/transform/document/global-type-references.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The TypeScript global types that generated code can refer to: in references (`Record<string,\n * never>`, `Omit<…>`, the `Blob` of `--binary-as-blob`) and in the text of footer helpers\n * (`Exclude<…>`, `Readonly<…>`). A module declaration of the same name shadows the global: every\n * use of it then fails to compile, or silently names the module's type (`Blob`).\n */\nconst GLOBAL_TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Array\",\n \"Blob\",\n \"Exclude\",\n \"Extract\",\n \"NonNullable\",\n \"Omit\",\n \"Partial\",\n \"Pick\",\n \"Readonly\",\n \"ReadonlyArray\",\n \"Record\",\n \"Required\",\n]);\n\nconst GENERIC_USE = /\\b([A-Z][A-Za-z]*)\\s*</g;\n\n/** `origin` holds the outside node a raw type was printed from; it is not part of the output. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\", \"comments\"]);\n\nfunction isObject(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction addTextUses(text: string, used: Set<string>): void {\n for (const match of text.matchAll(GENERIC_USE)) {\n const name = match[1] ?? \"\";\n if (GLOBAL_TYPE_NAMES.has(name)) {\n used.add(name);\n }\n }\n}\n\nfunction addNodeUses(node: Readonly<Record<string, unknown>>, used: Set<string>): void {\n if (node.kind === \"reference\" && typeof node.name === \"string\") {\n if (GLOBAL_TYPE_NAMES.has(node.name)) {\n used.add(node.name);\n }\n } else if (\n (node.kind === \"raw\" || node.kind === \"rawDeclaration\") &&\n typeof node.text === \"string\"\n ) {\n addTextUses(node.text, used);\n }\n}\n\nfunction visit(value: unknown, used: Set<string>): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n visit(item, used);\n }\n return;\n }\n if (!isObject(value)) {\n return;\n }\n addNodeUses(value, used);\n for (const [key, child] of Object.entries(value)) {\n if (!SKIPPED_KEYS.has(key)) {\n visit(child, used);\n }\n }\n}\n\n/** The TypeScript global type names that the declarations refer to. */\nexport function globalTypeReferences(declarations: readonly IrDeclaration[]): Set<string> {\n const used = new Set<string>();\n visit(declarations, used);\n return used;\n}\n"],"names":[],"mappings":"AAQA,MAAM,iBAAA,uBAA6C,GAAA,CAAI;AAAA,EACrD,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,WAAA,GAAc,yBA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,CAAC,QAAA,CAAS,KAAK,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AACA,EAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AACvB,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,CAAC,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA,EAAG;AAC1B,MAAA,KAAA,CAAM,OAAO,IAAI,CAAA;AAAA,IACnB;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,YAAA,EAAqD;AACxF,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,KAAA,CAAM,cAAc,IAAI,CAAA;AACxB,EAAA,OAAO,IAAA;AACT;;"}
1
+ {"version":3,"file":"global-type-references.mjs","sources":["../../../../src/application/transform/document/global-type-references.ts"],"sourcesContent":["import type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The TypeScript global types that generated code can refer to: in references (`Record<string,\n * never>`, `Omit<…>`, the `Blob` of `--binary-as-blob`) and in the text of footer helpers\n * (`Exclude<…>`, `Readonly<…>`). A module declaration of the same name shadows the global: every\n * use of it then fails to compile, or silently names the module's type (`Blob`).\n */\nexport const GLOBAL_TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Array\",\n \"Blob\",\n \"Exclude\",\n \"Extract\",\n \"NonNullable\",\n \"Omit\",\n \"Partial\",\n \"Pick\",\n \"Readonly\",\n \"ReadonlyArray\",\n \"Record\",\n \"Required\",\n]);\n\nconst GENERIC_USE = /\\b([A-Z][A-Za-z]*)\\s*</g;\n\n/** `origin` holds the outside node a raw type was printed from; it is not part of the output. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\"origin\", \"comments\"]);\n\nfunction isObject(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction addTextUses(text: string, used: Set<string>): void {\n for (const match of text.matchAll(GENERIC_USE)) {\n const name = match[1] ?? \"\";\n if (GLOBAL_TYPE_NAMES.has(name)) {\n used.add(name);\n }\n }\n}\n\nfunction addNodeUses(node: Readonly<Record<string, unknown>>, used: Set<string>): void {\n if (node.kind === \"reference\" && typeof node.name === \"string\") {\n if (GLOBAL_TYPE_NAMES.has(node.name)) {\n used.add(node.name);\n }\n } else if (\n (node.kind === \"raw\" || node.kind === \"rawDeclaration\") &&\n typeof node.text === \"string\"\n ) {\n addTextUses(node.text, used);\n }\n}\n\nfunction visit(value: unknown, used: Set<string>): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n visit(item, used);\n }\n return;\n }\n if (!isObject(value)) {\n return;\n }\n addNodeUses(value, used);\n for (const [key, child] of Object.entries(value)) {\n if (!SKIPPED_KEYS.has(key)) {\n visit(child, used);\n }\n }\n}\n\n/** The TypeScript global type names that the declarations refer to. */\nexport function globalTypeReferences(declarations: readonly IrDeclaration[]): Set<string> {\n const used = new Set<string>();\n visit(declarations, used);\n return used;\n}\n"],"names":[],"mappings":"AAQO,MAAM,iBAAA,uBAA6C,GAAA,CAAI;AAAA,EAC5D,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC;AAED,MAAM,WAAA,GAAc,yBAAA;AAGpB,MAAM,+BAAoC,IAAI,GAAA,CAAI,CAAC,QAAA,EAAU,UAAU,CAAC,CAAA;AAExE,SAAS,SAAS,KAAA,EAA4D;AAC5E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,WAAA,CAAY,MAAc,IAAA,EAAyB;AAC1D,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,CAAS,WAAW,CAAA,EAAG;AAC9C,IAA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B;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,YAAA,EAAqD;AACxF,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,KAAA,CAAM,cAAc,IAAI,CAAA;AACxB,EAAA,OAAO,IAAA;AACT;;"}
@@ -21,11 +21,11 @@ function itemSchemaAt(entry, path, context) {
21
21
  const resolved = mediaTypeObject.isMediaTypeComponentRef(entry.$ref) ? context.refs.resolve(entry.$ref) : void 0;
22
22
  return { schema: resolved?.itemSchema, path: jsonPointer.createRef([entry.$ref, "itemSchema"]) };
23
23
  }
24
- return { schema: entry.itemSchema, path: jsonPointer.createRef([path, "itemSchema"]) };
24
+ return { schema: entry.itemSchema, path: jsonPointer.appendPointer(path, ["itemSchema"]) };
25
25
  }
26
26
  function itemContentMember(content, location, context, flags) {
27
27
  const members = documentEntries.documentEntries(content, context.options).flatMap(([mediaType, entry]) => {
28
- const contentPath = jsonPointer.createRef([location.path, "content", mediaType]);
28
+ const contentPath = jsonPointer.appendPointer(location.path, ["content", mediaType]);
29
29
  const item = itemSchemaAt(entry, contentPath, context);
30
30
  if (item.schema === void 0) {
31
31
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"media-type.cjs","sources":["../../../../src/application/transform/document/media-type.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ContentMap,\n isMediaTypeComponentRef,\n type MediaTypeObject,\n} from \"../../../domain/openapi/media-type-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\n\n/** The sibling of `content` that holds item types (ADR-020). */\nconst ITEM_CONTENT_KEY = \"itemContent\";\n\n/** A media type's schema, or `unknown` when it has none (OpenAPI 3.1 §4.8.14). */\nexport function mediaTypeType(\n mediaType: MediaTypeObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n return mediaType.schema ? transformSchema(mediaType.schema, location, context) : UNKNOWN_TYPE;\n}\n\n/** A `content` entry: a `$ref` is transformed like a schema `$ref`, the rest as a media type. */\nexport function contentEntryType(\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // `in` throws for a null entry, as in the original.\n return \"$ref\" in entry\n ? transformSchema(entry, location, context)\n : mediaTypeType(entry, location, context);\n}\n\n/** The `itemSchema` of a `content` entry and where it is, following a `$ref` to a component. */\nfunction itemSchemaAt(\n entry: ContentMap[string],\n path: string,\n context: SchemaContext,\n): { readonly schema: MediaTypeObject[\"itemSchema\"]; readonly path: string } {\n if (\"$ref\" in entry) {\n // Other `$ref`s in `content` keep their pre-3.2 output, so only media type components count.\n const resolved = isMediaTypeComponentRef(entry.$ref)\n ? (context.refs.resolve(entry.$ref) as MediaTypeObject | undefined)\n : undefined;\n return { schema: resolved?.itemSchema, path: createRef([entry.$ref, \"itemSchema\"]) };\n }\n return { schema: entry.itemSchema, path: createRef([path, \"itemSchema\"]) };\n}\n\n/**\n * `itemContent`: the type of one item of each media type with an `itemSchema` (OpenAPI 3.2), next\n * to `content`, which keeps the type of the complete body. Null when no media type has one.\n */\nexport function itemContentMember(\n content: ContentMap,\n location: SchemaLocation,\n context: SchemaContext,\n flags: { readonly isReadonly: boolean },\n): IrPropertySignature | null {\n const members = documentEntries(content, context.options).flatMap(([mediaType, entry]) => {\n const contentPath = createRef([location.path, \"content\", mediaType]);\n const item = itemSchemaAt(entry, contentPath, context);\n if (item.schema === undefined) {\n return [];\n }\n const type = transformSchema(item.schema, { ...location, path: item.path }, context);\n return [documentMember(mediaType, type, entry, { isReadonly: context.options.immutable })];\n });\n return members.length > 0\n ? irProperty(toPropertyName(ITEM_CONTENT_KEY), irObject(members), flags)\n : null;\n}\n"],"names":["transformSchema","UNKNOWN_TYPE","isMediaTypeComponentRef","createRef","documentEntries","documentMember","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;;;;;AAgBA,MAAM,gBAAA,GAAmB,aAAA;AAGlB,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,OAAO,UAAU,MAAA,GAASA,+BAAA,CAAgB,UAAU,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA,GAAIC,wBAAA;AACnF;AAGO,SAAS,gBAAA,CACd,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,OAAO,MAAA,IAAU,KAAA,GACbD,+BAAA,CAAgB,KAAA,EAAO,QAAA,EAAU,OAAO,CAAA,GACxC,aAAA,CAAc,KAAA,EAAO,QAAA,EAAU,OAAO,CAAA;AAC5C;AAGA,SAAS,YAAA,CACP,KAAA,EACA,IAAA,EACA,OAAA,EAC2E;AAC3E,EAAA,IAAI,UAAU,KAAA,EAAO;AAEnB,IAAA,MAAM,QAAA,GAAWE,uCAAA,CAAwB,KAAA,CAAM,IAAI,CAAA,GAC9C,QAAQ,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,GAChC,MAAA;AACJ,IAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,UAAA,EAAY,IAAA,EAAMC,qBAAA,CAAU,CAAC,KAAA,CAAM,IAAA,EAAM,YAAY,CAAC,CAAA,EAAE;AAAA,EACrF;AACA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,CAAM,UAAA,EAAY,IAAA,EAAMA,sBAAU,CAAC,IAAA,EAAM,YAAY,CAAC,CAAA,EAAE;AAC3E;AAMO,SAAS,iBAAA,CACd,OAAA,EACA,QAAA,EACA,OAAA,EACA,KAAA,EAC4B;AAC5B,EAAA,MAAM,OAAA,GAAUC,+BAAA,CAAgB,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,SAAA,EAAW,KAAK,CAAA,KAAM;AACxF,IAAA,MAAM,cAAcD,qBAAA,CAAU,CAAC,SAAS,IAAA,EAAM,SAAA,EAAW,SAAS,CAAC,CAAA;AACnE,IAAA,MAAM,IAAA,GAAO,YAAA,CAAa,KAAA,EAAO,WAAA,EAAa,OAAO,CAAA;AACrD,IAAA,IAAI,IAAA,CAAK,WAAW,MAAA,EAAW;AAC7B,MAAA,OAAO,EAAC;AAAA,IACV;AACA,IAAA,MAAM,IAAA,GAAOH,+BAAA,CAAgB,IAAA,CAAK,MAAA,EAAQ,EAAE,GAAG,QAAA,EAAU,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK,EAAG,OAAO,CAAA;AACnF,IAAA,OAAO,CAACK,6BAAA,CAAe,SAAA,EAAW,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAC,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GACpBC,uBAAA,CAAWC,2BAAA,CAAe,gBAAgB,CAAA,EAAGC,qBAAA,CAAS,OAAO,CAAA,EAAG,KAAK,CAAA,GACrE,IAAA;AACN;;;;"}
1
+ {"version":3,"file":"media-type.cjs","sources":["../../../../src/application/transform/document/media-type.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ContentMap,\n isMediaTypeComponentRef,\n type MediaTypeObject,\n} from \"../../../domain/openapi/media-type-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\n\n/** The sibling of `content` that holds item types (ADR-020). */\nconst ITEM_CONTENT_KEY = \"itemContent\";\n\n/** A media type's schema, or `unknown` when it has none (OpenAPI 3.1 §4.8.14). */\nexport function mediaTypeType(\n mediaType: MediaTypeObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n return mediaType.schema ? transformSchema(mediaType.schema, location, context) : UNKNOWN_TYPE;\n}\n\n/** A `content` entry: a `$ref` is transformed like a schema `$ref`, the rest as a media type. */\nexport function contentEntryType(\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // `in` throws for a null entry, as in the original.\n return \"$ref\" in entry\n ? transformSchema(entry, location, context)\n : mediaTypeType(entry, location, context);\n}\n\n/** The `itemSchema` of a `content` entry and where it is, following a `$ref` to a component. */\nfunction itemSchemaAt(\n entry: ContentMap[string],\n path: string,\n context: SchemaContext,\n): { readonly schema: MediaTypeObject[\"itemSchema\"]; readonly path: string } {\n if (\"$ref\" in entry) {\n // Other `$ref`s in `content` keep their pre-3.2 output, so only media type components count.\n const resolved = isMediaTypeComponentRef(entry.$ref)\n ? (context.refs.resolve(entry.$ref) as MediaTypeObject | undefined)\n : undefined;\n // `createRef` reads the `$ref` itself as a pointer; only the constant segment is appended.\n return { schema: resolved?.itemSchema, path: createRef([entry.$ref, \"itemSchema\"]) };\n }\n return { schema: entry.itemSchema, path: appendPointer(path, [\"itemSchema\"]) };\n}\n\n/**\n * `itemContent`: the type of one item of each media type with an `itemSchema` (OpenAPI 3.2), next\n * to `content`, which keeps the type of the complete body. Null when no media type has one.\n */\nexport function itemContentMember(\n content: ContentMap,\n location: SchemaLocation,\n context: SchemaContext,\n flags: { readonly isReadonly: boolean },\n): IrPropertySignature | null {\n const members = documentEntries(content, context.options).flatMap(([mediaType, entry]) => {\n const contentPath = appendPointer(location.path, [\"content\", mediaType]);\n const item = itemSchemaAt(entry, contentPath, context);\n if (item.schema === undefined) {\n return [];\n }\n const type = transformSchema(item.schema, { ...location, path: item.path }, context);\n return [documentMember(mediaType, type, entry, { isReadonly: context.options.immutable })];\n });\n return members.length > 0\n ? irProperty(toPropertyName(ITEM_CONTENT_KEY), irObject(members), flags)\n : null;\n}\n"],"names":["transformSchema","UNKNOWN_TYPE","isMediaTypeComponentRef","createRef","appendPointer","documentEntries","documentMember","irProperty","toPropertyName","irObject"],"mappings":";;;;;;;;;;;AAgBA,MAAM,gBAAA,GAAmB,aAAA;AAGlB,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,OAAO,UAAU,MAAA,GAASA,+BAAA,CAAgB,UAAU,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA,GAAIC,wBAAA;AACnF;AAGO,SAAS,gBAAA,CACd,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,OAAO,MAAA,IAAU,KAAA,GACbD,+BAAA,CAAgB,KAAA,EAAO,QAAA,EAAU,OAAO,CAAA,GACxC,aAAA,CAAc,KAAA,EAAO,QAAA,EAAU,OAAO,CAAA;AAC5C;AAGA,SAAS,YAAA,CACP,KAAA,EACA,IAAA,EACA,OAAA,EAC2E;AAC3E,EAAA,IAAI,UAAU,KAAA,EAAO;AAEnB,IAAA,MAAM,QAAA,GAAWE,uCAAA,CAAwB,KAAA,CAAM,IAAI,CAAA,GAC9C,QAAQ,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,GAChC,MAAA;AAEJ,IAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,UAAA,EAAY,IAAA,EAAMC,qBAAA,CAAU,CAAC,KAAA,CAAM,IAAA,EAAM,YAAY,CAAC,CAAA,EAAE;AAAA,EACrF;AACA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,CAAM,UAAA,EAAY,IAAA,EAAMC,0BAAc,IAAA,EAAM,CAAC,YAAY,CAAC,CAAA,EAAE;AAC/E;AAMO,SAAS,iBAAA,CACd,OAAA,EACA,QAAA,EACA,OAAA,EACA,KAAA,EAC4B;AAC5B,EAAA,MAAM,OAAA,GAAUC,+BAAA,CAAgB,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,SAAA,EAAW,KAAK,CAAA,KAAM;AACxF,IAAA,MAAM,cAAcD,yBAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,SAAS,CAAC,CAAA;AACvE,IAAA,MAAM,IAAA,GAAO,YAAA,CAAa,KAAA,EAAO,WAAA,EAAa,OAAO,CAAA;AACrD,IAAA,IAAI,IAAA,CAAK,WAAW,MAAA,EAAW;AAC7B,MAAA,OAAO,EAAC;AAAA,IACV;AACA,IAAA,MAAM,IAAA,GAAOJ,+BAAA,CAAgB,IAAA,CAAK,MAAA,EAAQ,EAAE,GAAG,QAAA,EAAU,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK,EAAG,OAAO,CAAA;AACnF,IAAA,OAAO,CAACM,6BAAA,CAAe,SAAA,EAAW,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAC,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GACpBC,uBAAA,CAAWC,2BAAA,CAAe,gBAAgB,CAAA,EAAGC,qBAAA,CAAS,OAAO,CAAA,EAAG,KAAK,CAAA,GACrE,IAAA;AACN;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
2
2
  import { toPropertyName } from '../../../domain/ir/property-name.mjs';
3
- import { createRef } from '../../../domain/openapi/json-pointer.mjs';
3
+ import { appendPointer, createRef } from '../../../domain/openapi/json-pointer.mjs';
4
4
  import { isMediaTypeComponentRef } from '../../../domain/openapi/media-type-object.mjs';
5
5
  import { documentEntries } from '../document-entries.mjs';
6
6
  import { transformSchema } from '../schema/schema-transform.mjs';
@@ -19,11 +19,11 @@ function itemSchemaAt(entry, path, context) {
19
19
  const resolved = isMediaTypeComponentRef(entry.$ref) ? context.refs.resolve(entry.$ref) : void 0;
20
20
  return { schema: resolved?.itemSchema, path: createRef([entry.$ref, "itemSchema"]) };
21
21
  }
22
- return { schema: entry.itemSchema, path: createRef([path, "itemSchema"]) };
22
+ return { schema: entry.itemSchema, path: appendPointer(path, ["itemSchema"]) };
23
23
  }
24
24
  function itemContentMember(content, location, context, flags) {
25
25
  const members = documentEntries(content, context.options).flatMap(([mediaType, entry]) => {
26
- const contentPath = createRef([location.path, "content", mediaType]);
26
+ const contentPath = appendPointer(location.path, ["content", mediaType]);
27
27
  const item = itemSchemaAt(entry, contentPath, context);
28
28
  if (item.schema === void 0) {
29
29
  return [];