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

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 (320) hide show
  1. package/CHANGELOG.md +141 -0
  2. package/dist/adapters/node-file-system/node-file-system.cjs +7 -0
  3. package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
  4. package/dist/adapters/node-file-system/node-file-system.mjs +7 -0
  5. package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
  6. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
  7. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
  8. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
  9. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
  10. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +5 -32
  11. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +6 -33
  13. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
  15. package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
  16. package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
  17. package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
  18. package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
  19. package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
  21. package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/query-named-components.cjs +137 -0
  23. package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
  25. package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +26 -14
  27. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +26 -14
  29. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/ref-access.cjs +16 -3
  31. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/ref-access.mjs +16 -3
  33. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
  35. package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/ref-holders.mjs +52 -11
  37. package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
  38. package/dist/adapters/redocly-loader/remote-fetch.cjs +5 -3
  39. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  40. package/dist/adapters/redocly-loader/remote-fetch.mjs +5 -3
  41. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  42. package/dist/adapters/redocly-loader/remote-node-limit.cjs +17 -3
  43. package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -1
  44. package/dist/adapters/redocly-loader/remote-node-limit.mjs +17 -3
  45. package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -1
  46. package/dist/adapters/redocly-loader/schema-source.cjs +7 -2
  47. package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
  48. package/dist/adapters/redocly-loader/schema-source.mjs +8 -3
  49. package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
  50. package/dist/adapters/terminal-logger/terminal-logger.cjs +7 -3
  51. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  52. package/dist/adapters/terminal-logger/terminal-logger.mjs +7 -3
  53. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  54. package/dist/api/document-refs.cjs +16 -1
  55. package/dist/api/document-refs.cjs.map +1 -1
  56. package/dist/api/document-refs.mjs +16 -1
  57. package/dist/api/document-refs.mjs.map +1 -1
  58. package/dist/api/document-run.cjs +4 -10
  59. package/dist/api/document-run.cjs.map +1 -1
  60. package/dist/api/document-run.mjs +4 -10
  61. package/dist/api/document-run.mjs.map +1 -1
  62. package/dist/api/openapi-ts.cjs +1 -2
  63. package/dist/api/openapi-ts.cjs.map +1 -1
  64. package/dist/api/openapi-ts.mjs +2 -3
  65. package/dist/api/openapi-ts.mjs.map +1 -1
  66. package/dist/api/ref-limit-options.cjs +63 -0
  67. package/dist/api/ref-limit-options.cjs.map +1 -0
  68. package/dist/api/ref-limit-options.mjs +57 -0
  69. package/dist/api/ref-limit-options.mjs.map +1 -0
  70. package/dist/api/transform-schema.cjs +12 -5
  71. package/dist/api/transform-schema.cjs.map +1 -1
  72. package/dist/api/transform-schema.mjs +12 -5
  73. package/dist/api/transform-schema.mjs.map +1 -1
  74. package/dist/application/transform/declared-value-types.cjs +36 -0
  75. package/dist/application/transform/declared-value-types.cjs.map +1 -0
  76. package/dist/application/transform/declared-value-types.mjs +34 -0
  77. package/dist/application/transform/declared-value-types.mjs.map +1 -0
  78. package/dist/application/transform/document/document.cjs +3 -1
  79. package/dist/application/transform/document/document.cjs.map +1 -1
  80. package/dist/application/transform/document/document.mjs +3 -1
  81. package/dist/application/transform/document/document.mjs.map +1 -1
  82. package/dist/application/transform/document/exploded-query-values.cjs +63 -0
  83. package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
  84. package/dist/application/transform/document/exploded-query-values.mjs +59 -0
  85. package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
  86. package/dist/application/transform/document/header.cjs +11 -3
  87. package/dist/application/transform/document/header.cjs.map +1 -1
  88. package/dist/application/transform/document/header.mjs +10 -2
  89. package/dist/application/transform/document/header.mjs.map +1 -1
  90. package/dist/application/transform/document/parameter.cjs +1 -1
  91. package/dist/application/transform/document/parameter.cjs.map +1 -1
  92. package/dist/application/transform/document/parameter.mjs +1 -1
  93. package/dist/application/transform/document/parameter.mjs.map +1 -1
  94. package/dist/application/transform/document/parameters.cjs +23 -5
  95. package/dist/application/transform/document/parameters.cjs.map +1 -1
  96. package/dist/application/transform/document/parameters.mjs +23 -5
  97. package/dist/application/transform/document/parameters.mjs.map +1 -1
  98. package/dist/application/transform/document/path-item.cjs +4 -3
  99. package/dist/application/transform/document/path-item.cjs.map +1 -1
  100. package/dist/application/transform/document/path-item.mjs +4 -4
  101. package/dist/application/transform/document/path-item.mjs.map +1 -1
  102. package/dist/application/transform/document/path-template-key.cjs +84 -0
  103. package/dist/application/transform/document/path-template-key.cjs.map +1 -0
  104. package/dist/application/transform/document/path-template-key.mjs +79 -0
  105. package/dist/application/transform/document/path-template-key.mjs.map +1 -0
  106. package/dist/application/transform/document/path-template-refs.cjs +70 -0
  107. package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
  108. package/dist/application/transform/document/path-template-refs.mjs +67 -0
  109. package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
  110. package/dist/application/transform/document/paths-enum.cjs +7 -6
  111. package/dist/application/transform/document/paths-enum.cjs.map +1 -1
  112. package/dist/application/transform/document/paths-enum.mjs +7 -6
  113. package/dist/application/transform/document/paths-enum.mjs.map +1 -1
  114. package/dist/application/transform/document/paths.cjs +38 -66
  115. package/dist/application/transform/document/paths.cjs.map +1 -1
  116. package/dist/application/transform/document/paths.mjs +36 -66
  117. package/dist/application/transform/document/paths.mjs.map +1 -1
  118. package/dist/application/transform/document/webhooks.cjs +10 -3
  119. package/dist/application/transform/document/webhooks.cjs.map +1 -1
  120. package/dist/application/transform/document/webhooks.mjs +9 -2
  121. package/dist/application/transform/document/webhooks.mjs.map +1 -1
  122. package/dist/application/transform/footer/document-footer.cjs +6 -3
  123. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  124. package/dist/application/transform/footer/document-footer.mjs +6 -3
  125. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  126. package/dist/application/transform/helper-types.cjs +3 -3
  127. package/dist/application/transform/helper-types.cjs.map +1 -1
  128. package/dist/application/transform/helper-types.mjs +3 -3
  129. package/dist/application/transform/helper-types.mjs.map +1 -1
  130. package/dist/application/transform/ref-pointer/generated-location.cjs +4 -4
  131. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
  132. package/dist/application/transform/ref-pointer/generated-location.mjs +1 -1
  133. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
  134. package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
  135. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
  136. package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
  137. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
  138. package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
  139. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
  140. package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
  141. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
  142. package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
  143. package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
  144. package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
  145. package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
  146. package/dist/application/transform/ref-pointer/original-index.cjs +68 -13
  147. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
  148. package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
  149. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
  150. package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
  151. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
  152. package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
  153. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
  154. package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
  155. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
  156. package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
  157. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
  158. package/dist/application/transform/ref-pointer/property-shape.cjs +52 -0
  159. package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
  160. package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
  161. package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
  162. package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
  163. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
  164. package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
  165. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
  166. package/dist/application/transform/schema/access-flags.cjs.map +1 -1
  167. package/dist/application/transform/schema/access-flags.mjs.map +1 -1
  168. package/dist/application/transform/schema/index-signature-type.cjs +21 -0
  169. package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
  170. package/dist/application/transform/schema/index-signature-type.mjs +19 -0
  171. package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
  172. package/dist/application/transform/schema/input-location.cjs +23 -0
  173. package/dist/application/transform/schema/input-location.cjs.map +1 -0
  174. package/dist/application/transform/schema/input-location.mjs +21 -0
  175. package/dist/application/transform/schema/input-location.mjs.map +1 -0
  176. package/dist/application/transform/schema/object-type.cjs +15 -5
  177. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  178. package/dist/application/transform/schema/object-type.mjs +15 -5
  179. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  180. package/dist/application/transform/schema/schema-transform.cjs +2 -1
  181. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  182. package/dist/application/transform/schema/schema-transform.mjs +2 -1
  183. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  184. package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
  185. package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
  186. package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
  187. package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
  188. package/dist/cli/api-logger.cjs +13 -0
  189. package/dist/cli/api-logger.cjs.map +1 -0
  190. package/dist/cli/api-logger.mjs +11 -0
  191. package/dist/cli/api-logger.mjs.map +1 -0
  192. package/dist/cli/api-settings.cjs +7 -15
  193. package/dist/cli/api-settings.cjs.map +1 -1
  194. package/dist/cli/api-settings.mjs +8 -16
  195. package/dist/cli/api-settings.mjs.map +1 -1
  196. package/dist/cli/cli-arguments.cjs +51 -11
  197. package/dist/cli/cli-arguments.cjs.map +1 -1
  198. package/dist/cli/cli-arguments.mjs +51 -11
  199. package/dist/cli/cli-arguments.mjs.map +1 -1
  200. package/dist/cli/cli-errors.cjs +17 -0
  201. package/dist/cli/cli-errors.cjs.map +1 -1
  202. package/dist/cli/cli-errors.mjs +17 -1
  203. package/dist/cli/cli-errors.mjs.map +1 -1
  204. package/dist/cli/cli-output.cjs +6 -4
  205. package/dist/cli/cli-output.cjs.map +1 -1
  206. package/dist/cli/cli-output.mjs +7 -5
  207. package/dist/cli/cli-output.mjs.map +1 -1
  208. package/dist/cli/main.cjs +10 -4
  209. package/dist/cli/main.cjs.map +1 -1
  210. package/dist/cli/main.mjs +10 -4
  211. package/dist/cli/main.mjs.map +1 -1
  212. package/dist/cli/redocly-apis.cjs +20 -9
  213. package/dist/cli/redocly-apis.cjs.map +1 -1
  214. package/dist/cli/redocly-apis.mjs +22 -11
  215. package/dist/cli/redocly-apis.mjs.map +1 -1
  216. package/dist/cli/ref-limits.cjs +15 -1
  217. package/dist/cli/ref-limits.cjs.map +1 -1
  218. package/dist/cli/ref-limits.mjs +15 -2
  219. package/dist/cli/ref-limits.mjs.map +1 -1
  220. package/dist/cli/run-cli.cjs +24 -7
  221. package/dist/cli/run-cli.cjs.map +1 -1
  222. package/dist/cli/run-cli.mjs +25 -8
  223. package/dist/cli/run-cli.mjs.map +1 -1
  224. package/dist/domain/cause-secrets.cjs +31 -16
  225. package/dist/domain/cause-secrets.cjs.map +1 -1
  226. package/dist/domain/cause-secrets.mjs +31 -16
  227. package/dist/domain/cause-secrets.mjs.map +1 -1
  228. package/dist/domain/errors.cjs +2 -0
  229. package/dist/domain/errors.cjs.map +1 -1
  230. package/dist/domain/errors.mjs +2 -0
  231. package/dist/domain/errors.mjs.map +1 -1
  232. package/dist/domain/location-text.cjs +9 -0
  233. package/dist/domain/location-text.cjs.map +1 -0
  234. package/dist/domain/location-text.mjs +7 -0
  235. package/dist/domain/location-text.mjs.map +1 -0
  236. package/dist/domain/openapi/document-places.cjs +55 -0
  237. package/dist/domain/openapi/document-places.cjs.map +1 -0
  238. package/dist/domain/openapi/document-places.mjs +53 -0
  239. package/dist/domain/openapi/document-places.mjs.map +1 -0
  240. package/dist/domain/output-fixes.cjs +8 -2
  241. package/dist/domain/output-fixes.cjs.map +1 -1
  242. package/dist/domain/output-fixes.mjs +8 -2
  243. package/dist/domain/output-fixes.mjs.map +1 -1
  244. package/dist/domain/terminal-text.cjs +31 -0
  245. package/dist/domain/terminal-text.cjs.map +1 -0
  246. package/dist/domain/terminal-text.mjs +29 -0
  247. package/dist/domain/terminal-text.mjs.map +1 -0
  248. package/dist/domain/warnings.cjs +1 -0
  249. package/dist/domain/warnings.cjs.map +1 -1
  250. package/dist/domain/warnings.mjs +1 -0
  251. package/dist/domain/warnings.mjs.map +1 -1
  252. package/dist/index.d.cts +26 -18
  253. package/dist/index.d.mts +26 -18
  254. package/dist/index.d.ts +26 -18
  255. package/package.json +1 -1
  256. package/src/adapters/node-file-system/node-file-system.ts +14 -1
  257. package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
  258. package/src/adapters/redocly-loader/bundled-mapping-copies.ts +7 -42
  259. package/src/adapters/redocly-loader/component-schemas.ts +19 -0
  260. package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
  261. package/src/adapters/redocly-loader/query-named-components.ts +201 -0
  262. package/src/adapters/redocly-loader/redocly-schema-loader.ts +46 -14
  263. package/src/adapters/redocly-loader/ref-access.ts +16 -3
  264. package/src/adapters/redocly-loader/ref-holders.ts +75 -14
  265. package/src/adapters/redocly-loader/remote-fetch.ts +11 -2
  266. package/src/adapters/redocly-loader/remote-node-limit.ts +44 -4
  267. package/src/adapters/redocly-loader/schema-source.ts +15 -3
  268. package/src/adapters/terminal-logger/terminal-logger.ts +10 -4
  269. package/src/api/document-refs.ts +29 -1
  270. package/src/api/document-run.ts +6 -16
  271. package/src/api/openapi-ts.ts +6 -3
  272. package/src/api/ref-limit-options.ts +76 -0
  273. package/src/api/transform-schema.ts +20 -5
  274. package/src/application/ports/file-system.ts +8 -0
  275. package/src/application/transform/declared-value-types.ts +42 -0
  276. package/src/application/transform/document/document.ts +4 -2
  277. package/src/application/transform/document/exploded-query-values.ts +88 -0
  278. package/src/application/transform/document/header.ts +25 -5
  279. package/src/application/transform/document/parameter.ts +4 -4
  280. package/src/application/transform/document/parameters.ts +45 -10
  281. package/src/application/transform/document/path-item.ts +3 -3
  282. package/src/application/transform/document/path-template-key.ts +152 -0
  283. package/src/application/transform/document/path-template-refs.ts +106 -0
  284. package/src/application/transform/document/paths-enum.ts +23 -9
  285. package/src/application/transform/document/paths.ts +53 -123
  286. package/src/application/transform/document/webhooks.ts +18 -5
  287. package/src/application/transform/footer/document-footer.ts +18 -8
  288. package/src/application/transform/helper-types.ts +4 -4
  289. package/src/application/transform/ref-pointer/generated-location.ts +1 -1
  290. package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
  291. package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
  292. package/src/application/transform/ref-pointer/located-node.ts +38 -0
  293. package/src/application/transform/ref-pointer/original-index.ts +100 -17
  294. package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
  295. package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
  296. package/src/application/transform/ref-pointer/property-shape.ts +97 -0
  297. package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
  298. package/src/application/transform/schema/access-flags.ts +5 -2
  299. package/src/application/transform/schema/index-signature-type.ts +31 -0
  300. package/src/application/transform/schema/input-location.ts +35 -0
  301. package/src/application/transform/schema/object-type.ts +18 -8
  302. package/src/application/transform/schema/schema-transform.ts +2 -1
  303. package/src/application/transform/schema/unevaluated-properties.ts +4 -44
  304. package/src/cli/api-logger.ts +17 -0
  305. package/src/cli/api-settings.ts +12 -20
  306. package/src/cli/cli-arguments.ts +90 -14
  307. package/src/cli/cli-dependencies.ts +7 -2
  308. package/src/cli/cli-errors.ts +22 -0
  309. package/src/cli/cli-output.ts +11 -10
  310. package/src/cli/main.ts +10 -4
  311. package/src/cli/redocly-apis.ts +37 -17
  312. package/src/cli/ref-limits.ts +21 -2
  313. package/src/cli/run-cli.ts +39 -7
  314. package/src/domain/cause-secrets.ts +59 -25
  315. package/src/domain/errors.ts +2 -0
  316. package/src/domain/location-text.ts +12 -0
  317. package/src/domain/openapi/document-places.ts +78 -0
  318. package/src/domain/output-fixes.ts +9 -2
  319. package/src/domain/terminal-text.ts +44 -0
  320. package/src/domain/warnings.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref-limit-options.cjs","sources":["../../src/api/ref-limit-options.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { RefAccess } from \"../application/ports/schema-loader.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../domain/errors.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport type { GeneratorOptions } from \"../types.js\";\n\n/**\n * The `$ref` limits of the options (threat model R1, R2, ADR-017), checked before anything loads.\n * A value of another type from JavaScript (`remoteRefHosts: \"a.com\"`, `localRefRoot: new\n * URL(\"https://…\")`) used to fail later as an error of the document.\n */\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** What a value is, for the error; a URL is named by its protocol only, as it may hold secrets. */\nfunction kindOf(value: unknown): string {\n if (value instanceof URL) {\n return `a ${value.protocol} URL`;\n }\n if (Array.isArray(value)) {\n return \"a list\";\n }\n return value === null ? \"null\" : `a ${typeof value}`;\n}\n\nfunction optionInvalid(option: string, expected: string, got: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.OPTION_INVALID,\n message: `The ${option} option must be ${expected}; got ${got}.`,\n details: { option },\n });\n}\n\nconst LOCAL_ROOT_EXPECTED = \"a directory path or a file: URL\";\n\n/**\n * A string as the CLI reads `--local-ref-root`: a URL when it has a scheme (`file:///specs/`),\n * else a path that resolves against the cwd. Undefined when it does not parse as a URL.\n */\nfunction localRootUrlOf(value: string, cwd: URL): URL | undefined {\n if (!hasUrlScheme(value)) {\n return pathToFileURL(path.resolve(fileURLToPath(cwd), value));\n }\n return URL.parse(value, cwd.href) ?? undefined;\n}\n\n/** The local root as a `file:` URL; the option is set, so it is not undefined. */\nfunction localRootOf(value: unknown, cwd: URL): URL {\n const root = typeof value === \"string\" ? localRootUrlOf(value, cwd) : value;\n if (root instanceof URL && root.protocol === FILE_PROTOCOL) {\n return root;\n }\n const got = root === undefined ? \"a string that is no valid URL\" : kindOf(root);\n throw optionInvalid(\"localRefRoot\", LOCAL_ROOT_EXPECTED, got);\n}\n\nfunction remoteHostsOf(value: unknown): readonly string[] {\n if (!Array.isArray(value)) {\n throw optionInvalid(\"remoteRefHosts\", \"a list of hosts\", kindOf(value));\n }\n const other = value.find((entry) => typeof entry !== \"string\");\n if (other !== undefined) {\n throw optionInvalid(\"remoteRefHosts\", \"a list of hosts\", `a list with ${kindOf(other)}`);\n }\n return value;\n}\n\n/** The limits of the options; fails with `OPTION_INVALID` for a value of another type. */\nexport function refAccessOf(options: GeneratorOptions, cwd: URL): RefAccess {\n const { localRefRoot, remoteRefHosts } = options;\n return {\n ...(localRefRoot === undefined ? {} : { localRoot: localRootOf(localRefRoot, cwd) }),\n ...(remoteRefHosts === undefined ? {} : { remoteHosts: remoteHostsOf(remoteRefHosts) }),\n };\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","hasUr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,YAAgB,GAAA,IAAO,IAAA,CAAK,QAAA,KAAa,aAAA,EAAe;AAC1D,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,GAAA,GAAM,IAAA,KAAS,MAAA,GAAY,+BAAA,GAAkC,OAAO,IAAI,CAAA;AAC9E,EAAA,MAAM,aAAA,CAAc,cAAA,EAAgB,mBAAA,EAAqB,GAAG,CAAA;AAC9D;AAEA,SAAS,cAAc,KAAA,EAAmC;AACxD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,aAAA,CAAc,gBAAA,EAAkB,iBAAA,EAAmB,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EACxE;AACA,EAAA,MAAM,QAAQ,KAAA,CAAM,IAAA,CAAK,CAAC,KAAA,KAAU,OAAO,UAAU,QAAQ,CAAA;AAC7D,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,MAAM,cAAc,gBAAA,EAAkB,iBAAA,EAAmB,eAAe,MAAA,CAAO,KAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EACzF;AACA,EAAA,OAAO,KAAA;AACT;AAGO,SAAS,WAAA,CAAY,SAA2B,GAAA,EAAqB;AAC1E,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,OAAA;AACzC,EAAA,OAAO;AAAA,IACL,GAAI,YAAA,KAAiB,MAAA,GAAY,EAAC,GAAI,EAAE,SAAA,EAAW,WAAA,CAAY,YAAA,EAAc,GAAG,CAAA,EAAE;AAAA,IAClF,GAAI,mBAAmB,MAAA,GAAY,KAAK,EAAE,WAAA,EAAa,aAAA,CAAc,cAAc,CAAA;AAAE,GACvF;AACF;;"}
@@ -0,0 +1,57 @@
1
+ import path from 'node:path';
2
+ import { pathToFileURL, fileURLToPath } from 'node:url';
3
+ import { OpenAPITypesafeError, ERROR_CODES } from '../domain/errors.mjs';
4
+ import { hasUrlScheme } from '../domain/location-text.mjs';
5
+
6
+ const FILE_PROTOCOL = "file:";
7
+ function kindOf(value) {
8
+ if (value instanceof URL) {
9
+ return `a ${value.protocol} URL`;
10
+ }
11
+ if (Array.isArray(value)) {
12
+ return "a list";
13
+ }
14
+ return value === null ? "null" : `a ${typeof value}`;
15
+ }
16
+ function optionInvalid(option, expected, got) {
17
+ return new OpenAPITypesafeError({
18
+ code: ERROR_CODES.OPTION_INVALID,
19
+ message: `The ${option} option must be ${expected}; got ${got}.`,
20
+ details: { option }
21
+ });
22
+ }
23
+ const LOCAL_ROOT_EXPECTED = "a directory path or a file: URL";
24
+ function localRootUrlOf(value, cwd) {
25
+ if (!hasUrlScheme(value)) {
26
+ return pathToFileURL(path.resolve(fileURLToPath(cwd), value));
27
+ }
28
+ return URL.parse(value, cwd.href) ?? void 0;
29
+ }
30
+ function localRootOf(value, cwd) {
31
+ const root = typeof value === "string" ? localRootUrlOf(value, cwd) : value;
32
+ if (root instanceof URL && root.protocol === FILE_PROTOCOL) {
33
+ return root;
34
+ }
35
+ const got = root === void 0 ? "a string that is no valid URL" : kindOf(root);
36
+ throw optionInvalid("localRefRoot", LOCAL_ROOT_EXPECTED, got);
37
+ }
38
+ function remoteHostsOf(value) {
39
+ if (!Array.isArray(value)) {
40
+ throw optionInvalid("remoteRefHosts", "a list of hosts", kindOf(value));
41
+ }
42
+ const other = value.find((entry) => typeof entry !== "string");
43
+ if (other !== void 0) {
44
+ throw optionInvalid("remoteRefHosts", "a list of hosts", `a list with ${kindOf(other)}`);
45
+ }
46
+ return value;
47
+ }
48
+ function refAccessOf(options, cwd) {
49
+ const { localRefRoot, remoteRefHosts } = options;
50
+ return {
51
+ ...localRefRoot === void 0 ? {} : { localRoot: localRootOf(localRefRoot, cwd) },
52
+ ...remoteRefHosts === void 0 ? {} : { remoteHosts: remoteHostsOf(remoteRefHosts) }
53
+ };
54
+ }
55
+
56
+ export { refAccessOf };
57
+ //# sourceMappingURL=ref-limit-options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref-limit-options.mjs","sources":["../../src/api/ref-limit-options.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { RefAccess } from \"../application/ports/schema-loader.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../domain/errors.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport type { GeneratorOptions } from \"../types.js\";\n\n/**\n * The `$ref` limits of the options (threat model R1, R2, ADR-017), checked before anything loads.\n * A value of another type from JavaScript (`remoteRefHosts: \"a.com\"`, `localRefRoot: new\n * URL(\"https://…\")`) used to fail later as an error of the document.\n */\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** What a value is, for the error; a URL is named by its protocol only, as it may hold secrets. */\nfunction kindOf(value: unknown): string {\n if (value instanceof URL) {\n return `a ${value.protocol} URL`;\n }\n if (Array.isArray(value)) {\n return \"a list\";\n }\n return value === null ? \"null\" : `a ${typeof value}`;\n}\n\nfunction optionInvalid(option: string, expected: string, got: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.OPTION_INVALID,\n message: `The ${option} option must be ${expected}; got ${got}.`,\n details: { option },\n });\n}\n\nconst LOCAL_ROOT_EXPECTED = \"a directory path or a file: URL\";\n\n/**\n * A string as the CLI reads `--local-ref-root`: a URL when it has a scheme (`file:///specs/`),\n * else a path that resolves against the cwd. Undefined when it does not parse as a URL.\n */\nfunction localRootUrlOf(value: string, cwd: URL): URL | undefined {\n if (!hasUrlScheme(value)) {\n return pathToFileURL(path.resolve(fileURLToPath(cwd), value));\n }\n return URL.parse(value, cwd.href) ?? undefined;\n}\n\n/** The local root as a `file:` URL; the option is set, so it is not undefined. */\nfunction localRootOf(value: unknown, cwd: URL): URL {\n const root = typeof value === \"string\" ? localRootUrlOf(value, cwd) : value;\n if (root instanceof URL && root.protocol === FILE_PROTOCOL) {\n return root;\n }\n const got = root === undefined ? \"a string that is no valid URL\" : kindOf(root);\n throw optionInvalid(\"localRefRoot\", LOCAL_ROOT_EXPECTED, got);\n}\n\nfunction remoteHostsOf(value: unknown): readonly string[] {\n if (!Array.isArray(value)) {\n throw optionInvalid(\"remoteRefHosts\", \"a list of hosts\", kindOf(value));\n }\n const other = value.find((entry) => typeof entry !== \"string\");\n if (other !== undefined) {\n throw optionInvalid(\"remoteRefHosts\", \"a list of hosts\", `a list with ${kindOf(other)}`);\n }\n return value;\n}\n\n/** The limits of the options; fails with `OPTION_INVALID` for a value of another type. */\nexport function refAccessOf(options: GeneratorOptions, cwd: URL): RefAccess {\n const { localRefRoot, remoteRefHosts } = options;\n return {\n ...(localRefRoot === undefined ? {} : { localRoot: localRootOf(localRefRoot, cwd) }),\n ...(remoteRefHosts === undefined ? {} : { remoteHosts: remoteHostsOf(remoteRefHosts) }),\n };\n}\n"],"names":[],"mappings":";;;;;AAaA,MAAM,aAAA,GAAgB,OAAA;AAGtB,SAAS,OAAO,KAAA,EAAwB;AACtC,EAAA,IAAI,iBAAiB,GAAA,EAAK;AACxB,IAAA,OAAO,CAAA,EAAA,EAAK,MAAM,QAAQ,CAAA,IAAA,CAAA;AAAA,EAC5B;AACA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,KAAU,IAAA,GAAO,MAAA,GAAS,CAAA,EAAA,EAAK,OAAO,KAAK,CAAA,CAAA;AACpD;AAEA,SAAS,aAAA,CAAc,MAAA,EAAgB,QAAA,EAAkB,GAAA,EAAmC;AAC1F,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,cAAA;AAAA,IAClB,SAAS,CAAA,IAAA,EAAO,MAAM,CAAA,gBAAA,EAAmB,QAAQ,SAAS,GAAG,CAAA,CAAA,CAAA;AAAA,IAC7D,OAAA,EAAS,EAAE,MAAA;AAAO,GACnB,CAAA;AACH;AAEA,MAAM,mBAAA,GAAsB,iCAAA;A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C1E,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,OAAA;AACzC,EAAA,OAAO;AAAA,IACL,GAAI,YAAA,KAAiB,MAAA,GAAY,EAAC,GAAI,EAAE,SAAA,EAAW,WAAA,CAAY,YAAA,EAAc,GAAG,CAAA,EAAE;AAAA,IAClF,GAAI,mBAAmB,MAAA,GAAY,KAAK,EAAE,WAAA,EAAa,aAAA,CAAc,cAAc,CAAA;AAAE,GACvF;AACF;;"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const document = require('../application/transform/document/document.cjs');
6
6
  const enumNamesGivenBack = require('../application/transform/document/enum-names-given-back.cjs');
7
7
  const operationKeysWritten = require('../application/transform/document/operation-keys-written.cjs');
8
+ const pathTemplateRefs = require('../application/transform/document/path-template-refs.cjs');
8
9
  const rootTypeAliases = require('../application/transform/document/root-type-aliases.cjs');
9
10
  const documentFooter = require('../application/transform/footer/document-footer.cjs');
10
11
  const enumNameClaims = require('../application/transform/footer/enum-name-claims.cjs');
@@ -81,6 +82,15 @@ function enumValuesChecked(body, footer, ctx) {
81
82
  }
82
83
  return checked.footer;
83
84
  }
85
+ function withTemplateRefs({ body, footer, closing }, keys) {
86
+ return {
87
+ body: pathTemplateRefs.withTemplatePathRefs(body, keys),
88
+ footer: footer.map(
89
+ (entry) => footerEntry.isIrDeclaration(entry) ? pathTemplateRefs.withTemplatePathRefs([entry], keys)[0] ?? entry : entry
90
+ ),
91
+ closing: pathTemplateRefs.withTemplatePathRefs(closing, keys)
92
+ };
93
+ }
84
94
  function transformDocument(schema, ctx) {
85
95
  const document$1 = schema;
86
96
  ctx.schemaDialect = schemaDialect.schemaDialectOf(document$1.openapi);
@@ -95,11 +105,8 @@ function transformDocument(schema, ctx) {
95
105
  const rawClosing = document.documentClosing(document$1, context, rawFooter.some(isOperations));
96
106
  const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };
97
107
  const { body, footer, closing } = withEnumNamesGivenBack(parts, names);
98
- return {
99
- body: rootTypeAliases.renameTakenAliases(body, footer.filter(footerEntry.isIrDeclaration), closing),
100
- footer,
101
- closing
102
- };
108
+ const named = { body: rootTypeAliases.renameTakenAliases(body, footer.filter(footerEntry.isIrDeclaration), closing), footer };
109
+ return withTemplateRefs({ ...named, closing }, pathTemplateRefs.unmatchedTemplateKeys(document$1.paths, context));
103
110
  }
104
111
  function transformSchema(schema, ctx) {
105
112
  return documentDeclarations.documentDeclarations(transformDocument(schema, ctx));
@@ -1 +1 @@
1
- {"version":3,"file":"transform-schema.cjs","sources":["../../src/api/transform-schema.ts"],"sourcesContent":["import type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport { documentBody, documentClosing } from \"../application/transform/document/document.js\";\nimport {\n NAMES_THE_OUTPUT_MAY_NEED,\n namesTheOutputNeeds,\n withEnumsRenamed,\n} from \"../application/transform/document/enum-names-given-back.js\";\nimport { operationKeysWritten } from \"../application/transform/document/operation-keys-written.js\";\nimport { renameTakenAliases } from \"../application/transform/document/root-type-aliases.js\";\nimport { RunFooter, type RunFooterNames } from \"../application/transform/footer/document-footer.js\";\nimport { EnumNameClaims } from \"../application/transform/footer/enum-name-claims.js\";\nimport { checkedEnumValues } from \"../application/transform/footer/enum-values-check.js\";\nimport { OperationKeys } from \"../application/transform/footer/operation-keys.js\";\nimport {\n FIRST_SCHEMA_NAMES,\n SharedEnumNameRecorder,\n type SharedEnumNames,\n} from \"../application/transform/footer/shared-enum-names.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { DocumentObject } from \"../domain/openapi/document-object.js\";\nimport { schemaDialectOf } from \"../domain/openapi/schema-dialect.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type { GlobalContext, OpenAPI3 } from \"../types.js\";\nimport { FirstSchemaNameRecorder } from \"./discriminator-enum-names.js\";\nimport { documentDeclarations, type TransformedDocument } from \"./document-declarations.js\";\nimport { excludedValuesWarning } from \"./enum-values-warnings.js\";\nimport { type FooterEntry, isIrDeclaration } from \"./footer-entry.js\";\nimport { ContextFooterSink } from \"./footer-sink.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { createTransformContext } from \"./transform-context.js\";\n\nconst OPERATIONS_NAME = \"operations\";\n\n/** Whether a footer entry is named `operations` (any declaration kind, as in the original). */\nfunction isOperations(entry: FooterEntry): boolean {\n const name = isIrDeclaration(entry)\n ? (entry as { name?: string }).name\n : (entry as Partial<ts.InterfaceDeclaration>).name?.escapedText;\n return name === OPERATIONS_NAME;\n}\n\n/** Drops a message: the first pass must not repeat the run's warnings or debug lines. */\nconst dropMessage = (): void => undefined;\nconst DROPPED_MESSAGES = { debug: dropMessage, warn: dropMessage, error: dropMessage };\n\n/** A shared enum name recorder of a first pass, and the names it gives the second. */\ninterface EnumNameRecorder extends SharedEnumNames {\n chosenNames(): SharedEnumNames;\n}\n\n/**\n * The names of shared enums, known only at the end: a first pass transforms the document into a\n * scratch footer that `recorder` watches; its output is dropped. User callbacks run in both\n * passes. The `dedupe-enum-names` fix (ADR-021, upstream #1683) names an enum by all of its\n * schemas; `discriminator-values` keeps the first declaring schema's name\n * (`FirstSchemaNameRecorder`).\n */\nfunction sharedEnumNamesOf(\n document: DocumentObject,\n ctx: RunContext,\n recorder: EnumNameRecorder,\n): SharedEnumNames {\n const injectFooter: FooterEntry[] = [];\n const scratch: RunContext = {\n ...ctx,\n injectFooter,\n runFooter: new RunFooter(new ContextFooterSink(injectFooter), true, recorder),\n logger: DROPPED_MESSAGES,\n legacyCallbackWarnings: new Set(),\n };\n const scratchContext = createTransformContext(scratch);\n documentBody(document, scratchContext, () => injectFooter.filter(isIrDeclaration));\n return recorder.chosenNames();\n}\n\n/** The recorder of the run's fixes, or null where the first schema's name needs no first pass. */\nfunction enumNameRecorderOf(ctx: GlobalContext): EnumNameRecorder | null {\n if (ctx.fix?.includes(FIX.DEDUPE_ENUM_NAMES)) {\n return new SharedEnumNameRecorder();\n }\n return ctx.fix?.includes(FIX.DISCRIMINATOR_VALUES) ? new FirstSchemaNameRecorder() : null;\n}\n\n/**\n * The run's footer: with a naming fix, `--enum` and `--dedupe-enums` it names shared enums. A\n * footer that a call before created on the context is kept.\n */\nfunction withRunFooter(document: DocumentObject, ctx: RunContext, names: RunFooterNames): void {\n if (ctx.runFooter !== undefined) {\n return;\n }\n const recorder = enumNameRecorderOf(ctx);\n const shared =\n recorder === null || !ctx.enum || !ctx.dedupeEnums\n ? null\n : sharedEnumNamesOf(document, ctx, recorder);\n const sink = new ContextFooterSink(ctx.injectFooter);\n ctx.runFooter =\n shared === null\n ? new RunFooter(sink, ctx.dedupeEnums, FIRST_SCHEMA_NAMES, names)\n : new RunFooter(sink, true, shared, names);\n}\n\n/**\n * The document with the enums renamed that gave way to a name the output turned out not to need\n * (`EnumNameClaims`): they get that name back, as before.\n */\nfunction withEnumNamesGivenBack(\n parts: TransformedDocument,\n names: RunFooterNames,\n): TransformedDocument {\n const footer = parts.footer.filter(isIrDeclaration);\n const renames = names.enums.givenBack(namesTheOutputNeeds({ ...parts, footer }));\n if (renames.size === 0) {\n return parts;\n }\n return {\n body: withEnumsRenamed(parts.body, renames),\n footer: parts.footer.map((entry) =>\n isIrDeclaration(entry) ? (withEnumsRenamed([entry], renames)[0] ?? entry) : entry,\n ),\n closing: withEnumsRenamed(parts.closing, renames),\n };\n}\n\n/**\n * With `--enum-values`, arrays whose location type does not hold their values are typed by their\n * values (ADR-027); a location that excludes listed values is a contradiction of the document.\n */\nfunction enumValuesChecked(\n body: readonly IrDeclaration[],\n footer: FooterEntry[],\n ctx: RunContext,\n): FooterEntry[] {\n if (!ctx.enumValues) {\n return footer;\n }\n const checked = checkedEnumValues(footer, body, isIrDeclaration);\n for (const retype of checked.retyped) {\n if (retype.kind === \"excluded\") {\n ctx.logger?.warn(excludedValuesWarning(retype.name, retype.excluded));\n }\n }\n return checked.footer;\n}\n\n/** @internal Root types, the footer, then the closing declarations (Phase 5, step 6). */\nexport function transformDocument(schema: OpenAPI3, ctx: RunContext): TransformedDocument {\n const document = schema as DocumentObject;\n ctx.schemaDialect = schemaDialectOf(document.openapi);\n const names: RunFooterNames = {\n enums: new EnumNameClaims(NAMES_THE_OUTPUT_MAY_NEED),\n operations: new OperationKeys(operationKeysWritten(document)),\n };\n withRunFooter(document, ctx, names);\n const context = createTransformContext(ctx);\n // documentBody registers the enums in the footer, so the footer is read after it.\n const rawBody = documentBody(document, context, () => ctx.injectFooter.filter(isIrDeclaration));\n const rawFooter = enumValuesChecked(rawBody, [...ctx.injectFooter], ctx);\n const rawClosing = documentClosing(document, context, rawFooter.some(isOperations));\n const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };\n const { body, footer, closing } = withEnumNamesGivenBack(parts, names);\n return {\n body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing),\n footer,\n closing,\n };\n}\n\n/**\n * The whole document as IR declarations (ENGINEERING_PLAN 6.1–6.2); `openapiTS` returns the same\n * for a loaded document.\n */\nexport default function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclaration[] {\n return documentDeclarations(transformDocument(schema, ctx));\n}\n"],"names":["isIrDeclaration","document","RunFooter","ContextFooterSink","createTransformContext","documentBody","FIX","SharedEnumNameRecorder","FirstSchemaNameRecorder","FIRST_SCHEMA_NAMES","namesTheOutputNeeds","withEnumsRenamed","checkedEnumValues","excludedValuesWarning","schemaDialectOf","EnumNameClaims","NAMES_THE_OUTPUT_MAY_NEED","OperationKeys","operationKeysWritten","documentClosing","renameTakenAliases","documentDeclarations"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,eAAA,GAAkB,YAAA;AAGxB,SAAS,aAAa,KAAA,EAA6B;AACjD,EAAA,MAAM,OAAOA,2BAAA,CAAgB,KAAK,IAC7B,KAAA,CAA4B,IAAA,GAC5B,MAA2C,IAAA,EAAM,WAAA;AACtD,EAAA,OAAO,IAAA,KAAS,eAAA;AAClB;AAGA,MAAM,cAAc,MAAY,MAAA;AAChC,MAAM,mBAAmB,EAAE,KAAA,E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AA;AACrE,EAAA,OAAO;AAAA,IACL,MAAMmB,kCAAA,CAAmB,IAAA,EAAM,OAAO,MAAA,CAAOpB,2BAAe,GAAG,OAAO,CAAA;AAAA,IACtE,MAAA;AAAA,IACA;AAAA,GACF;AACF;AAMA,SAAwB,eAAA,CAAgB,QAAkB,GAAA,EAAqC;AAC7F,EAAA,OAAOqB,yCAAA,CAAqB,iBAAA,CAAkB,MAAA,EAAQ,GAAG,CAAC,CAAA;AAC5D;;;"}
1
+ {"version":3,"file":"transform-schema.cjs","sources":["../../src/api/transform-schema.ts"],"sourcesContent":["import type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport { documentBody, documentClosing } from \"../application/transform/document/document.js\";\nimport {\n NAMES_THE_OUTPUT_MAY_NEED,\n namesTheOutputNeeds,\n withEnumsRenamed,\n} from \"../application/transform/document/enum-names-given-back.js\";\nimport { operationKeysWritten } from \"../application/transform/document/operation-keys-written.js\";\nimport {\n unmatchedTemplateKeys,\n withTemplatePathRefs,\n} from \"../application/transform/document/path-template-refs.js\";\nimport { renameTakenAliases } from \"../application/transform/document/root-type-aliases.js\";\nimport { RunFooter, type RunFooterNames } from \"../application/transform/footer/document-footer.js\";\nimport { EnumNameClaims } from \"../application/transform/footer/enum-name-claims.js\";\nimport { checkedEnumValues } from \"../application/transform/footer/enum-values-check.js\";\nimport { OperationKeys } from \"../application/transform/footer/operation-keys.js\";\nimport {\n FIRST_SCHEMA_NAMES,\n SharedEnumNameRecorder,\n type SharedEnumNames,\n} from \"../application/transform/footer/shared-enum-names.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { DocumentObject } from \"../domain/openapi/document-object.js\";\nimport { schemaDialectOf } from \"../domain/openapi/schema-dialect.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type { GlobalContext, OpenAPI3 } from \"../types.js\";\nimport { FirstSchemaNameRecorder } from \"./discriminator-enum-names.js\";\nimport { documentDeclarations, type TransformedDocument } from \"./document-declarations.js\";\nimport { excludedValuesWarning } from \"./enum-values-warnings.js\";\nimport { type FooterEntry, isIrDeclaration } from \"./footer-entry.js\";\nimport { ContextFooterSink } from \"./footer-sink.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { createTransformContext } from \"./transform-context.js\";\n\nconst OPERATIONS_NAME = \"operations\";\n\n/** Whether a footer entry is named `operations` (any declaration kind, as in the original). */\nfunction isOperations(entry: FooterEntry): boolean {\n const name = isIrDeclaration(entry)\n ? (entry as { name?: string }).name\n : (entry as Partial<ts.InterfaceDeclaration>).name?.escapedText;\n return name === OPERATIONS_NAME;\n}\n\n/** Drops a message: the first pass must not repeat the run's warnings or debug lines. */\nconst dropMessage = (): void => undefined;\nconst DROPPED_MESSAGES = { debug: dropMessage, warn: dropMessage, error: dropMessage };\n\n/** A shared enum name recorder of a first pass, and the names it gives the second. */\ninterface EnumNameRecorder extends SharedEnumNames {\n chosenNames(): SharedEnumNames;\n}\n\n/**\n * The names of shared enums, known only at the end: a first pass transforms the document into a\n * scratch footer that `recorder` watches; its output is dropped. User callbacks run in both\n * passes. The `dedupe-enum-names` fix (ADR-021, upstream #1683) names an enum by all of its\n * schemas; `discriminator-values` keeps the first declaring schema's name\n * (`FirstSchemaNameRecorder`).\n */\nfunction sharedEnumNamesOf(\n document: DocumentObject,\n ctx: RunContext,\n recorder: EnumNameRecorder,\n): SharedEnumNames {\n const injectFooter: FooterEntry[] = [];\n const scratch: RunContext = {\n ...ctx,\n injectFooter,\n runFooter: new RunFooter(new ContextFooterSink(injectFooter), true, recorder),\n logger: DROPPED_MESSAGES,\n legacyCallbackWarnings: new Set(),\n };\n const scratchContext = createTransformContext(scratch);\n documentBody(document, scratchContext, () => injectFooter.filter(isIrDeclaration));\n return recorder.chosenNames();\n}\n\n/** The recorder of the run's fixes, or null where the first schema's name needs no first pass. */\nfunction enumNameRecorderOf(ctx: GlobalContext): EnumNameRecorder | null {\n if (ctx.fix?.includes(FIX.DEDUPE_ENUM_NAMES)) {\n return new SharedEnumNameRecorder();\n }\n return ctx.fix?.includes(FIX.DISCRIMINATOR_VALUES) ? new FirstSchemaNameRecorder() : null;\n}\n\n/**\n * The run's footer: with a naming fix, `--enum` and `--dedupe-enums` it names shared enums. A\n * footer that a call before created on the context is kept.\n */\nfunction withRunFooter(document: DocumentObject, ctx: RunContext, names: RunFooterNames): void {\n if (ctx.runFooter !== undefined) {\n return;\n }\n const recorder = enumNameRecorderOf(ctx);\n const shared =\n recorder === null || !ctx.enum || !ctx.dedupeEnums\n ? null\n : sharedEnumNamesOf(document, ctx, recorder);\n const sink = new ContextFooterSink(ctx.injectFooter);\n ctx.runFooter =\n shared === null\n ? new RunFooter(sink, ctx.dedupeEnums, FIRST_SCHEMA_NAMES, names)\n : new RunFooter(sink, true, shared, names);\n}\n\n/**\n * The document with the enums renamed that gave way to a name the output turned out not to need\n * (`EnumNameClaims`): they get that name back, as before.\n */\nfunction withEnumNamesGivenBack(\n parts: TransformedDocument,\n names: RunFooterNames,\n): TransformedDocument {\n const footer = parts.footer.filter(isIrDeclaration);\n const renames = names.enums.givenBack(namesTheOutputNeeds({ ...parts, footer }));\n if (renames.size === 0) {\n return parts;\n }\n return {\n body: withEnumsRenamed(parts.body, renames),\n footer: parts.footer.map((entry) =>\n isIrDeclaration(entry) ? (withEnumsRenamed([entry], renames)[0] ?? entry) : entry,\n ),\n closing: withEnumsRenamed(parts.closing, renames),\n };\n}\n\n/**\n * With `--enum-values`, arrays whose location type does not hold their values are typed by their\n * values (ADR-027); a location that excludes listed values is a contradiction of the document.\n */\nfunction enumValuesChecked(\n body: readonly IrDeclaration[],\n footer: FooterEntry[],\n ctx: RunContext,\n): FooterEntry[] {\n if (!ctx.enumValues) {\n return footer;\n }\n const checked = checkedEnumValues(footer, body, isIrDeclaration);\n for (const retype of checked.retyped) {\n if (retype.kind === \"excluded\") {\n ctx.logger?.warn(excludedValuesWarning(retype.name, retype.excluded));\n }\n }\n return checked.footer;\n}\n\n/** The document with its references into templated paths indexed by their templates. */\nfunction withTemplateRefs(\n { body, footer, closing }: TransformedDocument,\n keys: ReadonlyMap<string, string>,\n): TransformedDocument {\n return {\n body: withTemplatePathRefs(body, keys),\n footer: footer.map((entry) =>\n isIrDeclaration(entry) ? (withTemplatePathRefs([entry], keys)[0] ?? entry) : entry,\n ),\n closing: withTemplatePathRefs(closing, keys),\n };\n}\n\n/** @internal Root types, the footer, then the closing declarations (Phase 5, step 6). */\nexport function transformDocument(schema: OpenAPI3, ctx: RunContext): TransformedDocument {\n const document = schema as DocumentObject;\n ctx.schemaDialect = schemaDialectOf(document.openapi);\n const names: RunFooterNames = {\n enums: new EnumNameClaims(NAMES_THE_OUTPUT_MAY_NEED),\n operations: new OperationKeys(operationKeysWritten(document)),\n };\n withRunFooter(document, ctx, names);\n const context = createTransformContext(ctx);\n // documentBody registers the enums in the footer, so the footer is read after it.\n const rawBody = documentBody(document, context, () => ctx.injectFooter.filter(isIrDeclaration));\n const rawFooter = enumValuesChecked(rawBody, [...ctx.injectFooter], ctx);\n const rawClosing = documentClosing(document, context, rawFooter.some(isOperations));\n const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };\n const { body, footer, closing } = withEnumNamesGivenBack(parts, names);\n const named = { body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing), footer };\n return withTemplateRefs({ ...named, closing }, unmatchedTemplateKeys(document.paths, context));\n}\n\n/**\n * The whole document as IR declarations (ENGINEERING_PLAN 6.1–6.2); `openapiTS` returns the same\n * for a loaded document.\n */\nexport default function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclaration[] {\n return documentDeclarations(transformDocument(schema, ctx));\n}\n"],"names":["isIrDeclaration","document","RunFooter","ContextFooterSink","createTransformContext","documentBody","FIX","SharedEnumNameRecorder","FirstSchemaNameRecorder","FIRST_SCHEMA_NAMES","namesTheOutputNeeds","withEnumsRenamed","checkedEnumValues","excludedValuesWarning","withTemplatePathRefs","schemaDialectOf","EnumNameClaims","NAMES_THE_OUTPUT_MAY_NEED","OperationKeys","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6 +1,7 @@
1
1
  import { documentBody, documentClosing } from '../application/transform/document/document.mjs';
2
2
  import { NAMES_THE_OUTPUT_MAY_NEED, namesTheOutputNeeds, withEnumsRenamed } from '../application/transform/document/enum-names-given-back.mjs';
3
3
  import { operationKeysWritten } from '../application/transform/document/operation-keys-written.mjs';
4
+ import { unmatchedTemplateKeys, withTemplatePathRefs } from '../application/transform/document/path-template-refs.mjs';
4
5
  import { renameTakenAliases } from '../application/transform/document/root-type-aliases.mjs';
5
6
  import { RunFooter } from '../application/transform/footer/document-footer.mjs';
6
7
  import { EnumNameClaims } from '../application/transform/footer/enum-name-claims.mjs';
@@ -77,6 +78,15 @@ function enumValuesChecked(body, footer, ctx) {
77
78
  }
78
79
  return checked.footer;
79
80
  }
81
+ function withTemplateRefs({ body, footer, closing }, keys) {
82
+ return {
83
+ body: withTemplatePathRefs(body, keys),
84
+ footer: footer.map(
85
+ (entry) => isIrDeclaration(entry) ? withTemplatePathRefs([entry], keys)[0] ?? entry : entry
86
+ ),
87
+ closing: withTemplatePathRefs(closing, keys)
88
+ };
89
+ }
80
90
  function transformDocument(schema, ctx) {
81
91
  const document = schema;
82
92
  ctx.schemaDialect = schemaDialectOf(document.openapi);
@@ -91,11 +101,8 @@ function transformDocument(schema, ctx) {
91
101
  const rawClosing = documentClosing(document, context, rawFooter.some(isOperations));
92
102
  const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };
93
103
  const { body, footer, closing } = withEnumNamesGivenBack(parts, names);
94
- return {
95
- body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing),
96
- footer,
97
- closing
98
- };
104
+ const named = { body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing), footer };
105
+ return withTemplateRefs({ ...named, closing }, unmatchedTemplateKeys(document.paths, context));
99
106
  }
100
107
  function transformSchema(schema, ctx) {
101
108
  return documentDeclarations(transformDocument(schema, ctx));
@@ -1 +1 @@
1
- {"version":3,"file":"transform-schema.mjs","sources":["../../src/api/transform-schema.ts"],"sourcesContent":["import type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport { documentBody, documentClosing } from \"../application/transform/document/document.js\";\nimport {\n NAMES_THE_OUTPUT_MAY_NEED,\n namesTheOutputNeeds,\n withEnumsRenamed,\n} from \"../application/transform/document/enum-names-given-back.js\";\nimport { operationKeysWritten } from \"../application/transform/document/operation-keys-written.js\";\nimport { renameTakenAliases } from \"../application/transform/document/root-type-aliases.js\";\nimport { RunFooter, type RunFooterNames } from \"../application/transform/footer/document-footer.js\";\nimport { EnumNameClaims } from \"../application/transform/footer/enum-name-claims.js\";\nimport { checkedEnumValues } from \"../application/transform/footer/enum-values-check.js\";\nimport { OperationKeys } from \"../application/transform/footer/operation-keys.js\";\nimport {\n FIRST_SCHEMA_NAMES,\n SharedEnumNameRecorder,\n type SharedEnumNames,\n} from \"../application/transform/footer/shared-enum-names.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { DocumentObject } from \"../domain/openapi/document-object.js\";\nimport { schemaDialectOf } from \"../domain/openapi/schema-dialect.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type { GlobalContext, OpenAPI3 } from \"../types.js\";\nimport { FirstSchemaNameRecorder } from \"./discriminator-enum-names.js\";\nimport { documentDeclarations, type TransformedDocument } from \"./document-declarations.js\";\nimport { excludedValuesWarning } from \"./enum-values-warnings.js\";\nimport { type FooterEntry, isIrDeclaration } from \"./footer-entry.js\";\nimport { ContextFooterSink } from \"./footer-sink.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { createTransformContext } from \"./transform-context.js\";\n\nconst OPERATIONS_NAME = \"operations\";\n\n/** Whether a footer entry is named `operations` (any declaration kind, as in the original). */\nfunction isOperations(entry: FooterEntry): boolean {\n const name = isIrDeclaration(entry)\n ? (entry as { name?: string }).name\n : (entry as Partial<ts.InterfaceDeclaration>).name?.escapedText;\n return name === OPERATIONS_NAME;\n}\n\n/** Drops a message: the first pass must not repeat the run's warnings or debug lines. */\nconst dropMessage = (): void => undefined;\nconst DROPPED_MESSAGES = { debug: dropMessage, warn: dropMessage, error: dropMessage };\n\n/** A shared enum name recorder of a first pass, and the names it gives the second. */\ninterface EnumNameRecorder extends SharedEnumNames {\n chosenNames(): SharedEnumNames;\n}\n\n/**\n * The names of shared enums, known only at the end: a first pass transforms the document into a\n * scratch footer that `recorder` watches; its output is dropped. User callbacks run in both\n * passes. The `dedupe-enum-names` fix (ADR-021, upstream #1683) names an enum by all of its\n * schemas; `discriminator-values` keeps the first declaring schema's name\n * (`FirstSchemaNameRecorder`).\n */\nfunction sharedEnumNamesOf(\n document: DocumentObject,\n ctx: RunContext,\n recorder: EnumNameRecorder,\n): SharedEnumNames {\n const injectFooter: FooterEntry[] = [];\n const scratch: RunContext = {\n ...ctx,\n injectFooter,\n runFooter: new RunFooter(new ContextFooterSink(injectFooter), true, recorder),\n logger: DROPPED_MESSAGES,\n legacyCallbackWarnings: new Set(),\n };\n const scratchContext = createTransformContext(scratch);\n documentBody(document, scratchContext, () => injectFooter.filter(isIrDeclaration));\n return recorder.chosenNames();\n}\n\n/** The recorder of the run's fixes, or null where the first schema's name needs no first pass. */\nfunction enumNameRecorderOf(ctx: GlobalContext): EnumNameRecorder | null {\n if (ctx.fix?.includes(FIX.DEDUPE_ENUM_NAMES)) {\n return new SharedEnumNameRecorder();\n }\n return ctx.fix?.includes(FIX.DISCRIMINATOR_VALUES) ? new FirstSchemaNameRecorder() : null;\n}\n\n/**\n * The run's footer: with a naming fix, `--enum` and `--dedupe-enums` it names shared enums. A\n * footer that a call before created on the context is kept.\n */\nfunction withRunFooter(document: DocumentObject, ctx: RunContext, names: RunFooterNames): void {\n if (ctx.runFooter !== undefined) {\n return;\n }\n const recorder = enumNameRecorderOf(ctx);\n const shared =\n recorder === null || !ctx.enum || !ctx.dedupeEnums\n ? null\n : sharedEnumNamesOf(document, ctx, recorder);\n const sink = new ContextFooterSink(ctx.injectFooter);\n ctx.runFooter =\n shared === null\n ? new RunFooter(sink, ctx.dedupeEnums, FIRST_SCHEMA_NAMES, names)\n : new RunFooter(sink, true, shared, names);\n}\n\n/**\n * The document with the enums renamed that gave way to a name the output turned out not to need\n * (`EnumNameClaims`): they get that name back, as before.\n */\nfunction withEnumNamesGivenBack(\n parts: TransformedDocument,\n names: RunFooterNames,\n): TransformedDocument {\n const footer = parts.footer.filter(isIrDeclaration);\n const renames = names.enums.givenBack(namesTheOutputNeeds({ ...parts, footer }));\n if (renames.size === 0) {\n return parts;\n }\n return {\n body: withEnumsRenamed(parts.body, renames),\n footer: parts.footer.map((entry) =>\n isIrDeclaration(entry) ? (withEnumsRenamed([entry], renames)[0] ?? entry) : entry,\n ),\n closing: withEnumsRenamed(parts.closing, renames),\n };\n}\n\n/**\n * With `--enum-values`, arrays whose location type does not hold their values are typed by their\n * values (ADR-027); a location that excludes listed values is a contradiction of the document.\n */\nfunction enumValuesChecked(\n body: readonly IrDeclaration[],\n footer: FooterEntry[],\n ctx: RunContext,\n): FooterEntry[] {\n if (!ctx.enumValues) {\n return footer;\n }\n const checked = checkedEnumValues(footer, body, isIrDeclaration);\n for (const retype of checked.retyped) {\n if (retype.kind === \"excluded\") {\n ctx.logger?.warn(excludedValuesWarning(retype.name, retype.excluded));\n }\n }\n return checked.footer;\n}\n\n/** @internal Root types, the footer, then the closing declarations (Phase 5, step 6). */\nexport function transformDocument(schema: OpenAPI3, ctx: RunContext): TransformedDocument {\n const document = schema as DocumentObject;\n ctx.schemaDialect = schemaDialectOf(document.openapi);\n const names: RunFooterNames = {\n enums: new EnumNameClaims(NAMES_THE_OUTPUT_MAY_NEED),\n operations: new OperationKeys(operationKeysWritten(document)),\n };\n withRunFooter(document, ctx, names);\n const context = createTransformContext(ctx);\n // documentBody registers the enums in the footer, so the footer is read after it.\n const rawBody = documentBody(document, context, () => ctx.injectFooter.filter(isIrDeclaration));\n const rawFooter = enumValuesChecked(rawBody, [...ctx.injectFooter], ctx);\n const rawClosing = documentClosing(document, context, rawFooter.some(isOperations));\n const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };\n const { body, footer, closing } = withEnumNamesGivenBack(parts, names);\n return {\n body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing),\n footer,\n closing,\n };\n}\n\n/**\n * The whole document as IR declarations (ENGINEERING_PLAN 6.1–6.2); `openapiTS` returns the same\n * for a loaded document.\n */\nexport default function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclaration[] {\n return documentDeclarations(transformDocument(schema, ctx));\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAM,eAAA,GAAkB,YAAA;AAGxB,SAAS,aAAa,KAAA,EAA6B;AACjD,EAAA,MAAM,OAAO,eAAA,CAAgB,KAAK,IAC7B,KAAA,CAA4B,IAAA,GAC5B,MAA2C,IAAA,EAAM,WAAA;AACtD,EAAA,OAAO,IAAA,KAAS,eAAA;AAClB;AAGA,MAAM,cAAc,MAAY,MAAA;AAChC,MAAM,mBAAmB,EAAE,KAAA,EAAO,aAAa,IAAA,EAAM,WAAA,EAAa,OAAO,WAAA,EAAY;AAcrF,SAAS,iBAAA,CACP,QAAA,EACA,GAAA,EACA,QAAA,EACiB;AACjB,EAAA,MAAM,eAA8B,EAAC;AACrC,EAAA,MAAM,OAAA,GAAsB;AAAA,IAC1B,GAAG,GAAA;AAAA,IACH,YAAA;AAAA,IACA,SAAA,EAAW,IAAI,SAAA,CAAU,IAAI,kBAAkB,YAAY,CAAA,EAAG,MAAM,QAAQ,CAAA;AAAA,IAC5E,MAAA,EAAQ,gBAAA;AAAA,IACR,sBAAA,sBAA4B,GAAA;AAAI,GAClC;AACA,EAAA,MAAM,cAAA,GAAiB,uBAAuB,OAAO,CAAA;AACrD,EAAA,YAAA,CAAa,UAAU,cAAA,EAAgB,MAAM,YAAA,CAAa,MAAA,CAAO,eAAe,CAAC,CAAA;AACjF,EAAA,OAAO,SAAS,WAAA,EAAY;AAC9B;AAGA,SAAS,mBAAmB,GAAA,EAA6C;AACvE,EAAA,IAAI,GAAA,CAAI,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GAAU,uBAAuB,GAAG,CAAA;AAE1C,EAAA,MAAM,OAAA,GAAU,aAAa,QAAA,EAAU,OAAA,EAAS,MAAM,GAAA,CAAI,YAAA,CAAa,MAAA,CAAO,eAAe,CAAC,CAAA;AAC9F,EAAA,MAAM,SAAA,GAAY,kBAAkB,OAAA,EAAS,CAAC,GAAG,GAAA,CAAI,YAAY,GAAG,GAAG,CAAA;AACvE,EAAA,MAAM,aAAa,eAAA,CAAgB,QAAA,EAAU,SAAS,SAAA,CAAU,IAAA,CAAK,YAAY,CAAC,CAAA;AAClF,EAAA,MAAM,QAAQ,EAAE,IAAA,EAAM,SAAS,MAAA,EAAQ,SAAA,EAAW,SAAS,UAAA,EAAW;AACtE,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAQ,GAAI,sBAAA,CAAuB,OAAO,KAAK,CAAA;AACrE,EAAA,OAAO;AAAA,IACL,MAAM,kBAAA,CAAmB,IAAA,EAAM,OAAO,MAAA,CAAO,eAAe,GAAG,OAAO,CAAA;AAAA,IACtE,MAAA;AAAA,IACA;AAAA,GACF;AACF;AAMA,SAAwB,eAAA,CAAgB,QAAkB,GAAA,EAAqC;AAC7F,EAAA,OAAO,oBAAA,CAAqB,iBAAA,CAAkB,MAAA,EAAQ,GAAG,CAAC,CAAA;AAC5D;;"}
1
+ {"version":3,"file":"transform-schema.mjs","sources":["../../src/api/transform-schema.ts"],"sourcesContent":["import type { ts } from \"../adapters/type-ast-bridge/typescript-types.js\";\nimport { documentBody, documentClosing } from \"../application/transform/document/document.js\";\nimport {\n NAMES_THE_OUTPUT_MAY_NEED,\n namesTheOutputNeeds,\n withEnumsRenamed,\n} from \"../application/transform/document/enum-names-given-back.js\";\nimport { operationKeysWritten } from \"../application/transform/document/operation-keys-written.js\";\nimport {\n unmatchedTemplateKeys,\n withTemplatePathRefs,\n} from \"../application/transform/document/path-template-refs.js\";\nimport { renameTakenAliases } from \"../application/transform/document/root-type-aliases.js\";\nimport { RunFooter, type RunFooterNames } from \"../application/transform/footer/document-footer.js\";\nimport { EnumNameClaims } from \"../application/transform/footer/enum-name-claims.js\";\nimport { checkedEnumValues } from \"../application/transform/footer/enum-values-check.js\";\nimport { OperationKeys } from \"../application/transform/footer/operation-keys.js\";\nimport {\n FIRST_SCHEMA_NAMES,\n SharedEnumNameRecorder,\n type SharedEnumNames,\n} from \"../application/transform/footer/shared-enum-names.js\";\nimport type { IrDeclaration } from \"../domain/ir/nodes.js\";\nimport type { DocumentObject } from \"../domain/openapi/document-object.js\";\nimport { schemaDialectOf } from \"../domain/openapi/schema-dialect.js\";\nimport { FIX } from \"../domain/output-fixes.js\";\nimport type { GlobalContext, OpenAPI3 } from \"../types.js\";\nimport { FirstSchemaNameRecorder } from \"./discriminator-enum-names.js\";\nimport { documentDeclarations, type TransformedDocument } from \"./document-declarations.js\";\nimport { excludedValuesWarning } from \"./enum-values-warnings.js\";\nimport { type FooterEntry, isIrDeclaration } from \"./footer-entry.js\";\nimport { ContextFooterSink } from \"./footer-sink.js\";\nimport type { RunContext } from \"./run-context.js\";\nimport { createTransformContext } from \"./transform-context.js\";\n\nconst OPERATIONS_NAME = \"operations\";\n\n/** Whether a footer entry is named `operations` (any declaration kind, as in the original). */\nfunction isOperations(entry: FooterEntry): boolean {\n const name = isIrDeclaration(entry)\n ? (entry as { name?: string }).name\n : (entry as Partial<ts.InterfaceDeclaration>).name?.escapedText;\n return name === OPERATIONS_NAME;\n}\n\n/** Drops a message: the first pass must not repeat the run's warnings or debug lines. */\nconst dropMessage = (): void => undefined;\nconst DROPPED_MESSAGES = { debug: dropMessage, warn: dropMessage, error: dropMessage };\n\n/** A shared enum name recorder of a first pass, and the names it gives the second. */\ninterface EnumNameRecorder extends SharedEnumNames {\n chosenNames(): SharedEnumNames;\n}\n\n/**\n * The names of shared enums, known only at the end: a first pass transforms the document into a\n * scratch footer that `recorder` watches; its output is dropped. User callbacks run in both\n * passes. The `dedupe-enum-names` fix (ADR-021, upstream #1683) names an enum by all of its\n * schemas; `discriminator-values` keeps the first declaring schema's name\n * (`FirstSchemaNameRecorder`).\n */\nfunction sharedEnumNamesOf(\n document: DocumentObject,\n ctx: RunContext,\n recorder: EnumNameRecorder,\n): SharedEnumNames {\n const injectFooter: FooterEntry[] = [];\n const scratch: RunContext = {\n ...ctx,\n injectFooter,\n runFooter: new RunFooter(new ContextFooterSink(injectFooter), true, recorder),\n logger: DROPPED_MESSAGES,\n legacyCallbackWarnings: new Set(),\n };\n const scratchContext = createTransformContext(scratch);\n documentBody(document, scratchContext, () => injectFooter.filter(isIrDeclaration));\n return recorder.chosenNames();\n}\n\n/** The recorder of the run's fixes, or null where the first schema's name needs no first pass. */\nfunction enumNameRecorderOf(ctx: GlobalContext): EnumNameRecorder | null {\n if (ctx.fix?.includes(FIX.DEDUPE_ENUM_NAMES)) {\n return new SharedEnumNameRecorder();\n }\n return ctx.fix?.includes(FIX.DISCRIMINATOR_VALUES) ? new FirstSchemaNameRecorder() : null;\n}\n\n/**\n * The run's footer: with a naming fix, `--enum` and `--dedupe-enums` it names shared enums. A\n * footer that a call before created on the context is kept.\n */\nfunction withRunFooter(document: DocumentObject, ctx: RunContext, names: RunFooterNames): void {\n if (ctx.runFooter !== undefined) {\n return;\n }\n const recorder = enumNameRecorderOf(ctx);\n const shared =\n recorder === null || !ctx.enum || !ctx.dedupeEnums\n ? null\n : sharedEnumNamesOf(document, ctx, recorder);\n const sink = new ContextFooterSink(ctx.injectFooter);\n ctx.runFooter =\n shared === null\n ? new RunFooter(sink, ctx.dedupeEnums, FIRST_SCHEMA_NAMES, names)\n : new RunFooter(sink, true, shared, names);\n}\n\n/**\n * The document with the enums renamed that gave way to a name the output turned out not to need\n * (`EnumNameClaims`): they get that name back, as before.\n */\nfunction withEnumNamesGivenBack(\n parts: TransformedDocument,\n names: RunFooterNames,\n): TransformedDocument {\n const footer = parts.footer.filter(isIrDeclaration);\n const renames = names.enums.givenBack(namesTheOutputNeeds({ ...parts, footer }));\n if (renames.size === 0) {\n return parts;\n }\n return {\n body: withEnumsRenamed(parts.body, renames),\n footer: parts.footer.map((entry) =>\n isIrDeclaration(entry) ? (withEnumsRenamed([entry], renames)[0] ?? entry) : entry,\n ),\n closing: withEnumsRenamed(parts.closing, renames),\n };\n}\n\n/**\n * With `--enum-values`, arrays whose location type does not hold their values are typed by their\n * values (ADR-027); a location that excludes listed values is a contradiction of the document.\n */\nfunction enumValuesChecked(\n body: readonly IrDeclaration[],\n footer: FooterEntry[],\n ctx: RunContext,\n): FooterEntry[] {\n if (!ctx.enumValues) {\n return footer;\n }\n const checked = checkedEnumValues(footer, body, isIrDeclaration);\n for (const retype of checked.retyped) {\n if (retype.kind === \"excluded\") {\n ctx.logger?.warn(excludedValuesWarning(retype.name, retype.excluded));\n }\n }\n return checked.footer;\n}\n\n/** The document with its references into templated paths indexed by their templates. */\nfunction withTemplateRefs(\n { body, footer, closing }: TransformedDocument,\n keys: ReadonlyMap<string, string>,\n): TransformedDocument {\n return {\n body: withTemplatePathRefs(body, keys),\n footer: footer.map((entry) =>\n isIrDeclaration(entry) ? (withTemplatePathRefs([entry], keys)[0] ?? entry) : entry,\n ),\n closing: withTemplatePathRefs(closing, keys),\n };\n}\n\n/** @internal Root types, the footer, then the closing declarations (Phase 5, step 6). */\nexport function transformDocument(schema: OpenAPI3, ctx: RunContext): TransformedDocument {\n const document = schema as DocumentObject;\n ctx.schemaDialect = schemaDialectOf(document.openapi);\n const names: RunFooterNames = {\n enums: new EnumNameClaims(NAMES_THE_OUTPUT_MAY_NEED),\n operations: new OperationKeys(operationKeysWritten(document)),\n };\n withRunFooter(document, ctx, names);\n const context = createTransformContext(ctx);\n // documentBody registers the enums in the footer, so the footer is read after it.\n const rawBody = documentBody(document, context, () => ctx.injectFooter.filter(isIrDeclaration));\n const rawFooter = enumValuesChecked(rawBody, [...ctx.injectFooter], ctx);\n const rawClosing = documentClosing(document, context, rawFooter.some(isOperations));\n const parts = { body: rawBody, footer: rawFooter, closing: rawClosing };\n const { body, footer, closing } = withEnumNamesGivenBack(parts, names);\n const named = { body: renameTakenAliases(body, footer.filter(isIrDeclaration), closing), footer };\n return withTemplateRefs({ ...named, closing }, unmatchedTemplateKeys(document.paths, context));\n}\n\n/**\n * The whole document as IR declarations (ENGINEERING_PLAN 6.1–6.2); `openapiTS` returns the same\n * for a loaded document.\n */\nexport default function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclaration[] {\n return documentDeclarations(transformDocument(schema, ctx));\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,MAAM,eAAA,GAAkB,YAAA;AAGxB,SAAS,aAAa,KAAA,EAA6B;AACjD,EAAA,MAAM,OAAO,eAAA,CAAgB,KAAK,IAC7B,KAAA,CAA4B,IAAA,GAC5B,MAA2C,IAAA,EAAM,WAAA;AACtD,EAAA,OAAO,IAAA,KAAS,eAAA;AAClB;AAGA,MAAM,cAAc,MAAY,MAAA;AAChC,MAAM,mBAAmB,EAAE,KAAA,EAAO,aAAa,IAAA,EAAM,WAAA,EAAa,OAAO,WAAA,EAAY;AAcrF,SAAS,iBAAA,CACP,QAAA,EACA,GAAA,EACA,QAAA,EACiB;AACjB,EAAA,MAAM,eAA8B,EAAC;AACrC,EAAA,MAAM,OAAA,GAAsB;AAAA,IAC1B,GAAG,GAAA;AAAA,IACH,YAAA;AAAA,IACA,SAAA,EAAW,IAAI,SAAA,CAAU,IAAI,kBAAkB,YAAY,CAAA,EAAG,MAAM,QAAQ,CAAA;AAAA,IAC5E,MAAA,EAAQ,gBAAA;AAAA,IACR,sBAAA,sBAA4B,GAAA;AAAI,GAClC;AACA,EAAA,MAAM,cAAA,GAAiB,uBAAuB,OAAO,CAAA;AACrD,EAAA,YAAA,CAAa,UAAU,cAAA,EAAgB,MAAM,YAAA,CAAa,MAAA,CAAO,eAAe,CAAC,CAAA;AACjF,EAAA,OAAO,SAAS,WAAA,EAAY;AAC9B;AAGA,SAAS,mBAAmB,GAAA,EAA6C;AACvE,EAAA,IAAI,GAAA,CA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/F;AAMA,SAAwB,eAAA,CAAgB,QAAkB,GAAA,EAAqC;AAC7F,EAAA,OAAO,oBAAA,CAAqB,iBAAA,CAAkB,MAAA,EAAQ,GAAG,CAAC,CAAA;AAC5D;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const constructors = require('../../domain/ir/constructors.cjs');
4
+ const helperTypes = require('./helper-types.cjs');
5
+
6
+ function memberValueTypes(member) {
7
+ if (member.kind === "indexSignature") {
8
+ return [member.type];
9
+ }
10
+ return member.isOptional ? [member.type, constructors.irKeyword("undefined")] : [member.type];
11
+ }
12
+ function declaredValueTypes(type, footer) {
13
+ switch (type.kind) {
14
+ case "object":
15
+ return type.members.flatMap(memberValueTypes);
16
+ case "union":
17
+ case "intersection":
18
+ return type.types.flatMap((member) => declaredValueTypes(member, footer));
19
+ case "reference":
20
+ case "indexedAccess":
21
+ case "raw":
22
+ footer.requirePropertyValues();
23
+ return [constructors.irReference(helperTypes.HELPER_TYPES.propertyValues.name, [type])];
24
+ case "keyword":
25
+ case "stringLiteral":
26
+ case "numberLiteral":
27
+ case "booleanLiteral":
28
+ case "array":
29
+ case "tuple":
30
+ case "readonly":
31
+ return [];
32
+ }
33
+ }
34
+
35
+ exports.declaredValueTypes = declaredValueTypes;
36
+ //# sourceMappingURL=declared-value-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-value-types.cjs","sources":["../../../src/application/transform/declared-value-types.ts"],"sourcesContent":["import { irKeyword, irReference } from \"../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../domain/ir/nodes.js\";\nimport { HELPER_TYPES } from \"./helper-types.js\";\nimport type { FooterDeclarations } from \"./schema/schema-context.js\";\n\n/** The footer part that declares the `PropertyValues` helper type. */\nexport type PropertyValuesFooter = Pick<FooterDeclarations, \"requirePropertyValues\">;\n\nfunction memberValueTypes(member: IrMember): IrType[] {\n if (member.kind === \"indexSignature\") {\n return [member.type];\n }\n return member.isOptional ? [member.type, irKeyword(\"undefined\")] : [member.type];\n}\n\n/**\n * The value types a key of the type can have, read from its IR: the members of object types,\n * through unions and intersections. A reference (a `$ref`, `Omit`, `WithRequired`) or a raw\n * type is read with `PropertyValues`. Primitives, literals and arrays declare no keys.\n */\nexport function declaredValueTypes(type: IrType, footer: PropertyValuesFooter): IrType[] {\n switch (type.kind) {\n case \"object\":\n return type.members.flatMap(memberValueTypes);\n case \"union\":\n case \"intersection\":\n return type.types.flatMap((member) => declaredValueTypes(member, footer));\n case \"reference\":\n case \"indexedAccess\":\n case \"raw\":\n footer.requirePropertyValues();\n return [irReference(HELPER_TYPES.propertyValues.name, [type])];\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"array\":\n case \"tuple\":\n case \"readonly\":\n return [];\n }\n}\n"],"names":["irKeyword","irReference","HELPER_TYPES"],"mappings":";;;;;AAQA,SAAS,iBAAiB,MAAA,EAA4B;AACpD,EAAA,IAAI,MAAA,CAAO,SAAS,gBAAA,EAAkB;AACpC,IAAA,OAAO,CAAC,OAAO,IAAI,CAAA;AAAA,EACrB;AACA,EAAA,OAAO,MAAA,CAAO,UAAA,GAAa,CAAC,MAAA,CAAO,IAAA,EAAMA,sBAAA,CAAU,WAAW,CAAC,CAAA,GAAI,CAAC,MAAA,CAAO,IAAI,CAAA;AACjF;AAOO,SAAS,kBAAA,CAAmB,MAAc,MAAA,EAAwC;AACvF,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,gBAAgB,CAAA;AAAA,IAC9C,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,IAAA,CAAK,MAAM,OAAA,CAAQ,CAAC,WAAW,kBAAA,CAAmB,MAAA,EAAQ,MAAM,CAAC,CAAA;AAAA,IAC1E,KAAK,WAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,KAAA;AACH,MAAA,MAAA,CAAO,qBAAA,EAAsB;AAC7B,MAAA,OAAO,CAACC,yBAAYC,wBAAA,CAAa,cAAA,CAAe,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AAAA,IAC/D,KAAK,SAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,gBAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,EAAC;AAAA;AAEd;;"}
@@ -0,0 +1,34 @@
1
+ import { irReference, irKeyword } from '../../domain/ir/constructors.mjs';
2
+ import { HELPER_TYPES } from './helper-types.mjs';
3
+
4
+ function memberValueTypes(member) {
5
+ if (member.kind === "indexSignature") {
6
+ return [member.type];
7
+ }
8
+ return member.isOptional ? [member.type, irKeyword("undefined")] : [member.type];
9
+ }
10
+ function declaredValueTypes(type, footer) {
11
+ switch (type.kind) {
12
+ case "object":
13
+ return type.members.flatMap(memberValueTypes);
14
+ case "union":
15
+ case "intersection":
16
+ return type.types.flatMap((member) => declaredValueTypes(member, footer));
17
+ case "reference":
18
+ case "indexedAccess":
19
+ case "raw":
20
+ footer.requirePropertyValues();
21
+ return [irReference(HELPER_TYPES.propertyValues.name, [type])];
22
+ case "keyword":
23
+ case "stringLiteral":
24
+ case "numberLiteral":
25
+ case "booleanLiteral":
26
+ case "array":
27
+ case "tuple":
28
+ case "readonly":
29
+ return [];
30
+ }
31
+ }
32
+
33
+ export { declaredValueTypes };
34
+ //# sourceMappingURL=declared-value-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-value-types.mjs","sources":["../../../src/application/transform/declared-value-types.ts"],"sourcesContent":["import { irKeyword, irReference } from \"../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../domain/ir/nodes.js\";\nimport { HELPER_TYPES } from \"./helper-types.js\";\nimport type { FooterDeclarations } from \"./schema/schema-context.js\";\n\n/** The footer part that declares the `PropertyValues` helper type. */\nexport type PropertyValuesFooter = Pick<FooterDeclarations, \"requirePropertyValues\">;\n\nfunction memberValueTypes(member: IrMember): IrType[] {\n if (member.kind === \"indexSignature\") {\n return [member.type];\n }\n return member.isOptional ? [member.type, irKeyword(\"undefined\")] : [member.type];\n}\n\n/**\n * The value types a key of the type can have, read from its IR: the members of object types,\n * through unions and intersections. A reference (a `$ref`, `Omit`, `WithRequired`) or a raw\n * type is read with `PropertyValues`. Primitives, literals and arrays declare no keys.\n */\nexport function declaredValueTypes(type: IrType, footer: PropertyValuesFooter): IrType[] {\n switch (type.kind) {\n case \"object\":\n return type.members.flatMap(memberValueTypes);\n case \"union\":\n case \"intersection\":\n return type.types.flatMap((member) => declaredValueTypes(member, footer));\n case \"reference\":\n case \"indexedAccess\":\n case \"raw\":\n footer.requirePropertyValues();\n return [irReference(HELPER_TYPES.propertyValues.name, [type])];\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"array\":\n case \"tuple\":\n case \"readonly\":\n return [];\n }\n}\n"],"names":[],"mappings":";;;AAQA,SAAS,iBAAiB,MAAA,EAA4B;AACpD,EAAA,IAAI,MAAA,CAAO,SAAS,gBAAA,EAAkB;AACpC,IAAA,OAAO,CAAC,OAAO,IAAI,CAAA;AAAA,EACrB;AACA,EAAA,OAAO,MAAA,CAAO,UAAA,GAAa,CAAC,MAAA,CAAO,IAAA,EAAM,SAAA,CAAU,WAAW,CAAC,CAAA,GAAI,CAAC,MAAA,CAAO,IAAI,CAAA;AACjF;AAOO,SAAS,kBAAA,CAAmB,MAAc,MAAA,EAAwC;AACvF,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,gBAAgB,CAAA;AAAA,IAC9C,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,IAAA,CAAK,MAAM,OAAA,CAAQ,CAAC,WAAW,kBAAA,CAAmB,MAAA,EAAQ,MAAM,CAAC,CAAA;AAAA,IAC1E,KAAK,WAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,KAAA;AACH,MAAA,MAAA,CAAO,qBAAA,EAAsB;AAC7B,MAAA,OAAO,CAAC,YAAY,YAAA,CAAa,cAAA,CAAe,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AAAA,IAC/D,KAAK,SAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,gBAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,EAAC;AAAA;AAEd;;"}
@@ -7,6 +7,7 @@ const components = require('./components.cjs');
7
7
  const declaredTypes = require('./declared-types.cjs');
8
8
  const defsRoot = require('./defs-root.cjs');
9
9
  const keptDeprecated$1 = require('./kept-deprecated.cjs');
10
+ const pathItem = require('./path-item.cjs');
10
11
  const paths = require('./paths.cjs');
11
12
  const pathsEnum = require('./paths-enum.cjs');
12
13
  const webhooks = require('./webhooks.cjs');
@@ -100,7 +101,8 @@ function documentClosing(document, context, hasOperations) {
100
101
  declarations.push(emptyAlias(OPERATIONS_NAME));
101
102
  }
102
103
  if (context.options.makePathsEnum && document.paths) {
103
- declarations.push(pathsEnum.apiPathsEnumDeclaration(document.paths));
104
+ const isIncluded = (operation) => pathItem.isIncludedOperation(operation, context);
105
+ declarations.push(pathsEnum.apiPathsEnumDeclaration(document.paths, isIncluded));
104
106
  }
105
107
  return declarations;
106
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"document.cjs","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":["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,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,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"version":3,"file":"document.cjs","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 { OperationEntry, 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 { isIncludedOperation } from \"./path-item.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 const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeLookup","READ_WRITE_MARKER_TYPES","appendAll","isIncludedOperation","apiPathsEnumDeclaration"],"mappings":";;;;;;;;;;;;;;AAwBO,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,CAA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,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,MAAM,UAAA,GAAa,CAAC,SAAA,KAA8BC,4BAAA,CAAoB,WAAW,OAAO,CAAA;AACxF,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,YAAA;AACT;;;;;"}
@@ -5,6 +5,7 @@ import { componentsType } from './components.mjs';
5
5
  import { declaredTypeLookup } from './declared-types.mjs';
6
6
  import { defsRootType } from './defs-root.mjs';
7
7
  import { keptDeprecatedComponents } from './kept-deprecated.mjs';
8
+ import { isIncludedOperation } from './path-item.mjs';
8
9
  import { pathMembers, pathsObjectType } from './paths.mjs';
9
10
  import { apiPathsEnumDeclaration } from './paths-enum.mjs';
10
11
  import { webhooksType } from './webhooks.mjs';
@@ -98,7 +99,8 @@ function documentClosing(document, context, hasOperations) {
98
99
  declarations.push(emptyAlias(OPERATIONS_NAME));
99
100
  }
100
101
  if (context.options.makePathsEnum && document.paths) {
101
- declarations.push(apiPathsEnumDeclaration(document.paths));
102
+ const isIncluded = (operation) => isIncludedOperation(operation, context);
103
+ declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));
102
104
  }
103
105
  return declarations;
104
106
  }
@@ -1 +1 @@
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,M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GA,MAAM,SAAA,GAAY,MAAgC,EAAC;AAO5C,SAAS,YAAA,CACd,QAAA,EACA,OAAA,EACA,MAAA,GAAyC,SAAA,EACxB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,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;;"}
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 { OperationEntry, 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 { isIncludedOperation } from \"./path-item.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 const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwBO,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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