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
@@ -1 +1 @@
1
- {"version":3,"file":"cli-errors.mjs","sources":["../../src/cli/cli-errors.ts"],"sourcesContent":["import {\n ERROR_CODES,\n type ErrorCode,\n isOpenAPITypesafeError,\n OpenAPITypesafeError,\n} from \"../domain/errors.js\";\n\n/**\n * How the CLI reports a failure (ENGINEERING_PLAN 4.6, ADR-011): each error code maps to a process\n * exit code and the line printed for it. The table is exhaustive, so a new error code does not\n * compile until the CLI handles it.\n */\n\n/** Process exit codes of the CLI, documented in docs/cli.md. */\nexport const EXIT_CODES = {\n SUCCESS: 0,\n /** `--check` found output that differs from the generated types (as in the original CLI). */\n OUTPUT_STALE: 1,\n /** A flag, the Redocly config, the environment or a callback is wrong. */\n USAGE: 2,\n /** The OpenAPI document cannot be read, is invalid, or cannot be converted. */\n SCHEMA: 3,\n /** An output file cannot be read or written. */\n OUTPUT: 4,\n /** An unexpected failure: a bug in the generator (sysexits `EX_SOFTWARE`). */\n INTERNAL: 70,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\ninterface CliErrorReport {\n readonly exitCode: ExitCode;\n /** The printed text; the error's own message when absent. */\n readonly message?: (error: OpenAPITypesafeError) => string;\n}\n\n/** Problems are printed one by one while linting, so the summary only counts them. */\nfunction schemaInvalidMessage(error: OpenAPITypesafeError): string {\n const count = Array.isArray(error.details.problems) ? error.details.problems.length : 1;\n return `The OpenAPI document has ${count} ${count === 1 ? \"error\" : \"errors\"} (see above)`;\n}\n\n/**\n * Node's `fetch` fails with only \"fetch failed\"; the network reason (refused, DNS, TLS) is the\n * cause of that error. The Node API keeps the original message, so only the CLI adds it.\n */\nfunction loadFailedMessage(error: OpenAPITypesafeError): string {\n const reason = error.cause instanceof Error ? error.cause.cause : undefined;\n if (!(reason instanceof Error)) {\n return error.message;\n }\n // `loadFailedError`, the only source of this code, always sets the source.\n return `${error.message}: ${reason.message} (${String(error.details.source)})`;\n}\n\n/** The message js-yaml throws at its nesting limit (docs/security/threat-model.md T2). */\nconst YAML_DEPTH_LIMIT_MESSAGE = /nesting exceeded maxDepth \\((\\d+)\\)/;\n\n/** The parser's message says the limit, not how to stay under it. */\nfunction parseFailedMessage(error: OpenAPITypesafeError): string {\n const limit = YAML_DEPTH_LIMIT_MESSAGE.exec(error.message)?.[1];\n if (limit === undefined) {\n return error.message;\n }\n return (\n `${error.message}. The YAML parser reads at most ${limit} nested levels: ` +\n \"move nested schemas to `components` and reference them with `$ref`\"\n );\n}\n\n/**\n * Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the\n * CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).\n */\nfunction sourceInvalidMessage(error: OpenAPITypesafeError): string {\n const { received, text } = error.details;\n if (received !== \"stream\" || typeof text !== \"string\") {\n return error.message;\n }\n return (\n `stdin held only the YAML string \"${text}\", not an OpenAPI document. To read a file, pass ` +\n \"its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts\"\n );\n}\n\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },\n SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },\n SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },\n SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: schemaInvalidMessage },\n SCHEMA_REF_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_REF_FORBIDDEN: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_OBJECT_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_PROPERTY_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_TOO_DEEP: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_KEY_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },\n OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },\n TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },\n CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },\n OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },\n OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n};\n\n/** What the CLI prints and returns for a thrown value. */\nexport interface CliFailure {\n readonly exitCode: ExitCode;\n readonly message: string;\n}\n\n/**\n * Map a thrown value to the CLI's output. A typed error prints one line with its code; anything\n * else is a bug and prints its stack, so it can be reported.\n */\nexport function describeCliFailure(error: unknown): CliFailure {\n if (!isOpenAPITypesafeError(error)) {\n const text = error instanceof Error ? (error.stack ?? error.message) : String(error);\n return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };\n }\n const report = CLI_ERROR_REPORTS[error.code];\n const message = report.message?.(error) ?? error.message;\n return { exitCode: report.exitCode, message: `${message} (${error.code})` };\n}\n\n/** Errors of the CLI itself; its messages are the original CLI's messages. */\nexport function cliError(\n code: Extract<ErrorCode, `CLI_${string}` | `OUTPUT_${string}`>,\n message: string,\n cause?: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES[code], message, cause });\n}\n"],"names":[],"mappings":";;AAcO,MAAM,UAAA,GAAa;AAAA,EACxB,OAAA,EAAS,CAAA;AAAA;AAAA,EAET,YAAA,EAAc,CAAA;AAAA;AAAA,EAEd,KAAA,EAAO,CAAA;AAAA;AAAA,EAEP,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,QAAA,EAAU;AACZ;AAWA,SAAS,qBAA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EAAE,QAAA,EAAU,UAAA,CAAW,UAAU,OAAA,EAAS,CAAA,kBAAA,EAAqB,IAAI,CAAA,CAAA,EAAG;AAAA,EAC/E;AACA,EAAA,MAAM,MAAA,GAAS,iBAAA,CAAkB,KAAA,CAAM,IAAI,CAAA;AAC3C,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,GAAU,KAAK,KAAK,KAAA,CAAM,OAAA;AACjD,EAAA,OAAO,EAAE,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,OAAA,EAAS,GAAG,OAAO,CAAA,EAAA,EAAK,KAAA,CAAM,IAAI,CAAA,CAAA,CAAA,EAAI;AAC5E;AAGO,SAAS,QAAA,CACd,IAAA,EACA,OAAA,EACA,KAAA,EACsB;AACtB,EAAA,OAAO,IAAI,qBAAqB,EAAE,IAAA,EAAM,YAAY,IAAI,CAAA,EAAG,OAAA,EAAS,KAAA,EAAO,CAAA;AAC7E;;"}
1
+ {"version":3,"file":"cli-errors.mjs","sources":["../../src/cli/cli-errors.ts"],"sourcesContent":["import {\n ERROR_CODES,\n type ErrorCode,\n isOpenAPITypesafeError,\n OpenAPITypesafeError,\n} from \"../domain/errors.js\";\n\n/**\n * How the CLI reports a failure (ENGINEERING_PLAN 4.6, ADR-011): each error code maps to a process\n * exit code and the line printed for it. The table is exhaustive, so a new error code does not\n * compile until the CLI handles it.\n */\n\n/** Process exit codes of the CLI, documented in docs/cli.md. */\nexport const EXIT_CODES = {\n SUCCESS: 0,\n /** `--check` found output that differs from the generated types (as in the original CLI). */\n OUTPUT_STALE: 1,\n /** A flag, the Redocly config, the environment or a callback is wrong. */\n USAGE: 2,\n /** The OpenAPI document cannot be read, is invalid, or cannot be converted. */\n SCHEMA: 3,\n /** An output file cannot be read or written. */\n OUTPUT: 4,\n /** An unexpected failure: a bug in the generator (sysexits `EX_SOFTWARE`). */\n INTERNAL: 70,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\ninterface CliErrorReport {\n readonly exitCode: ExitCode;\n /** The printed text; the error's own message when absent. */\n readonly message?: (error: OpenAPITypesafeError) => string;\n}\n\n/** Problems are printed one by one while linting, so the summary only counts them. */\nfunction schemaInvalidMessage(error: OpenAPITypesafeError): string {\n const count = Array.isArray(error.details.problems) ? error.details.problems.length : 1;\n return `The OpenAPI document has ${count} ${count === 1 ? \"error\" : \"errors\"} (see above)`;\n}\n\n/**\n * Node's `fetch` fails with only \"fetch failed\"; the network reason (refused, DNS, TLS) is the\n * cause of that error. The Node API keeps the original message, so only the CLI adds it.\n */\nfunction loadFailedMessage(error: OpenAPITypesafeError): string {\n const reason = error.cause instanceof Error ? error.cause.cause : undefined;\n if (!(reason instanceof Error)) {\n return error.message;\n }\n // `loadFailedError`, the only source of this code, always sets the source.\n return `${error.message}: ${reason.message} (${String(error.details.source)})`;\n}\n\n/** The message js-yaml throws at its nesting limit (docs/security/threat-model.md T2). */\nconst YAML_DEPTH_LIMIT_MESSAGE = /nesting exceeded maxDepth \\((\\d+)\\)/;\n\n/** The parser's message says the limit, not how to stay under it. */\nfunction parseFailedMessage(error: OpenAPITypesafeError): string {\n const limit = YAML_DEPTH_LIMIT_MESSAGE.exec(error.message)?.[1];\n if (limit === undefined) {\n return error.message;\n }\n return (\n `${error.message}. The YAML parser reads at most ${limit} nested levels: ` +\n \"move nested schemas to `components` and reference them with `$ref`\"\n );\n}\n\n/**\n * Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the\n * CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).\n */\nfunction sourceInvalidMessage(error: OpenAPITypesafeError): string {\n const { received, text } = error.details;\n if (received !== \"stream\" || typeof text !== \"string\") {\n return error.message;\n }\n return (\n `stdin held only the YAML string \"${text}\", not an OpenAPI document. To read a file, pass ` +\n \"its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts\"\n );\n}\n\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },\n SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },\n SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },\n SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: schemaInvalidMessage },\n SCHEMA_REF_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_REF_FORBIDDEN: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_OBJECT_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_PROPERTY_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_TOO_DEEP: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_KEY_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },\n OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },\n OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },\n TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },\n OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },\n OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n};\n\n/** What the CLI prints and returns for a thrown value. */\nexport interface CliFailure {\n readonly exitCode: ExitCode;\n readonly message: string;\n}\n\n/**\n * Map a thrown value to the CLI's output. A typed error prints one line with its code; anything\n * else is a bug and prints its stack, so it can be reported.\n */\nexport function describeCliFailure(error: unknown): CliFailure {\n if (error instanceof ApiFailure) {\n const failure = describeCliFailure(error.cause);\n return { ...failure, message: `API ${error.apiName}: ${failure.message}` };\n }\n if (!isOpenAPITypesafeError(error)) {\n const text = error instanceof Error ? (error.stack ?? error.message) : String(error);\n return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };\n }\n const report = CLI_ERROR_REPORTS[error.code];\n const message = report.message?.(error) ?? error.message;\n return { exitCode: report.exitCode, message: `${message} (${error.code})` };\n}\n\n/**\n * A failure of one API of a Redocly config. The CLI reports its cause with the API named first,\n * as the config errors of an API are; the cause keeps its code and so its exit code.\n */\nexport class ApiFailure extends Error {\n override readonly name = \"ApiFailure\";\n override readonly cause: unknown;\n readonly apiName: string;\n\n constructor(apiName: string, cause: unknown) {\n super(`API ${apiName} failed`, { cause });\n this.apiName = apiName;\n this.cause = cause;\n }\n}\n\n/** Errors of the CLI itself; its messages are the original CLI's messages. */\nexport function cliError(\n code: Extract<ErrorCode, `CLI_${string}` | `OUTPUT_${string}`>,\n message: string,\n cause?: unknown,\n): OpenAPITypesafeError {\n return new OpenAPIT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SAAiB,KAAA,EAAgB;AAC3C,IAAA,KAAA,CAAM,CAAA,IAAA,EAAO,OAAO,CAAA,OAAA,CAAA,EAAW,EAAE,OAAO,CAAA;AACxC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF;AAGO,SAAS,QAAA,CACd,IAAA,EACA,OAAA,EACA,KAAA,EACsB;AACtB,EAAA,OAAO,IAAI,qBAAqB,EAAE,IAAA,EAAM,YAAY,IAAI,CAAA,EAAG,OAAA,EAAS,KAAA,EAAO,CAAA;AAC7E;;"}
@@ -3,6 +3,8 @@
3
3
  const path = require('node:path');
4
4
  const node_url = require('node:url');
5
5
  const terminalLogger = require('../adapters/terminal-logger/terminal-logger.cjs');
6
+ const locationText = require('../domain/location-text.cjs');
7
+ const terminalText = require('../domain/terminal-text.cjs');
6
8
  const urlSecrets = require('../domain/url-secrets.cjs');
7
9
  const cliErrors = require('./cli-errors.cjs');
8
10
 
@@ -10,9 +12,8 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
10
12
 
11
13
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
12
14
 
13
- const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
14
15
  function resolveLocationUrl(location, base) {
15
- if (URL_SCHEME.test(location)) {
16
+ if (locationText.hasUrlScheme(location)) {
16
17
  const url = URL.parse(location, base.href);
17
18
  if (url === null) {
18
19
  const shown = urlSecrets.redactUnparsedUrl(location);
@@ -105,14 +106,15 @@ function duplicateOutputError(output, others) {
105
106
  );
106
107
  }
107
108
  function parseLocationUrl(location, base) {
108
- if (URL_SCHEME.test(location)) {
109
+ if (locationText.hasUrlScheme(location)) {
109
110
  return URL.parse(location, base.href) ?? void 0;
110
111
  }
111
112
  return resolveLocationUrl(location, base);
112
113
  }
113
114
  function printDone(run, output) {
114
115
  const { style, now } = run.deps;
115
- const target = style.green(`${output.source} \u2192 ${style.bold(output.output)}`);
116
+ const source = terminalText.terminalSafeText(urlSecrets.redactUrlSecrets(output.source));
117
+ const target = style.green(`${source} \u2192 ${style.bold(terminalText.terminalSafeText(output.output))}`);
116
118
  const duration = style.dim(`[${terminalLogger.formatDuration(now() - run.startedAt)}]`);
117
119
  run.deps.console.info(`\u{1F680} ${target} ${duration}`);
118
120
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cli-output.cjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { redactUnparsedUrl } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * A scheme of two or more characters (`https:`, `file:`). One letter is a Windows drive (`C:`), so\n * `C:\\\\specs\\\\api.yaml` stays a path.\n */\nconst URL_SCHEME = /^[a-z][a-z\\d+.-]+:/i;\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (URL_SCHEME.test(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (URL_SCHEME.test(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const target = style.green(`${output.source} → ${style.bold(output.output)}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":["redactUnparsedUrl","cliError","fileURLToPath","pathToFileURL","path","formatDuration"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,UAAA,GAAa,qBAAA;AASZ,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,UAAA,CAAW,IAAA,CAAK,QAAQ,CAAA,EAAG;AAC7B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQA,6BAAkB,QAAQ,CAAA;AACxC,MAAA,MAAMC,kBAAA,CAAS,sBAAA,EAAwB,CAAA,aAAA,EAAgB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,gBAAgBC,sBAAA,CAAc,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAC,CAAA;AACtD,EAAA,OAAOC,sBAAA,CAAcC,aAAA,CAAK,OAAA,CAAQ,aAAA,EAAe,QAAQ,CAAC,CAAA;AAC5D;AAEA,MAAM,aAAA,GAAgB,OAAA;AAGtB,MAAM,qCAA0C,IAAI,GAAA,CAAI,CAAC,GAAA,EAAK,IAAI,CAAC,CAAA;AAOnE,SAAS,cAAA,CAAe,UAAkB,IAAA,EAAoB;AAC5D,EAAA,MAAM,WAAA,GAAc,QAAA,CACjB,KAAA,CAAMA,aAAA,CAAK,GAAG,CAAA,CACd,OAAA,CAAQ,CAAC,IAAA,KAAS,KAAK,KAAA,CAAM,GAAG,CAAC,CAA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S,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,MAAA,CAAO,MAAM,CAAA,QAAA,EAAM,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAA,CAAE,CAAA;AAC5E,EAAA,MAAM,QAAA,GAAW,KAAA,CAAM,GAAA,CAAI,CAAA,CAAA,EAAII,6BAAA,CAAe,KAAI,GAAI,GAAA,CAAI,SAAS,CAAC,CAAA,CAAA,CAAG,CAAA;AACvE,EAAA,GAAA,CAAI,KAAK,OAAA,CAAQ,IAAA,CAAK,aAAM,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAA;AAClD;AAMO,SAAS,UAAA,CAAW,GAAA,EAAa,MAAA,EAAoB,QAAA,EAAwB;AAClF,EAAA,IAAI,GAAA,CAAI,KAAK,OAAA,EAAS;AACpB,IAAA,IAAI,IAAI,IAAA,CAAK,KAAA,CAAM,SAAS,MAAA,CAAO,IAAI,MAAM,QAAA,EAAU;AAErD,MAAA,MAAMJ,kBAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;;;;;;;;;;"}
1
+ {"version":3,"file":"cli-output.cjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":["hasUrlScheme","redactUnparsedUrl","cliError","fileURLToPath","pathToFileURL","path","terminalSafeText","redactUrlSecrets","formatD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A,EAAIE,6BAAA,CAAe,KAAI,GAAI,GAAA,CAAI,SAAS,CAAC,CAAA,CAAA,CAAG,CAAA;AACvE,EAAA,GAAA,CAAI,KAAK,OAAA,CAAQ,IAAA,CAAK,aAAM,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAA;AAClD;AAMO,SAAS,UAAA,CAAW,GAAA,EAAa,MAAA,EAAoB,QAAA,EAAwB;AAClF,EAAA,IAAI,GAAA,CAAI,KAAK,OAAA,EAAS;AACpB,IAAA,IAAI,IAAI,IAAA,CAAK,KAAA,CAAM,SAAS,MAAA,CAAO,IAAI,MAAM,QAAA,EAAU;AAErD,MAAA,MAAMN,kBAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;;;;;;;;;;"}
@@ -1,12 +1,13 @@
1
1
  import path from 'node:path';
2
2
  import { fileURLToPath, pathToFileURL } from 'node:url';
3
3
  import { formatDuration } from '../adapters/terminal-logger/terminal-logger.mjs';
4
- import { redactUnparsedUrl } from '../domain/url-secrets.mjs';
4
+ import { hasUrlScheme } from '../domain/location-text.mjs';
5
+ import { terminalSafeText } from '../domain/terminal-text.mjs';
6
+ import { redactUnparsedUrl, redactUrlSecrets } from '../domain/url-secrets.mjs';
5
7
  import { cliError } from './cli-errors.mjs';
6
8
 
7
- const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
8
9
  function resolveLocationUrl(location, base) {
9
- if (URL_SCHEME.test(location)) {
10
+ if (hasUrlScheme(location)) {
10
11
  const url = URL.parse(location, base.href);
11
12
  if (url === null) {
12
13
  const shown = redactUnparsedUrl(location);
@@ -99,14 +100,15 @@ function duplicateOutputError(output, others) {
99
100
  );
100
101
  }
101
102
  function parseLocationUrl(location, base) {
102
- if (URL_SCHEME.test(location)) {
103
+ if (hasUrlScheme(location)) {
103
104
  return URL.parse(location, base.href) ?? void 0;
104
105
  }
105
106
  return resolveLocationUrl(location, base);
106
107
  }
107
108
  function printDone(run, output) {
108
109
  const { style, now } = run.deps;
109
- const target = style.green(`${output.source} \u2192 ${style.bold(output.output)}`);
110
+ const source = terminalSafeText(redactUrlSecrets(output.source));
111
+ const target = style.green(`${source} \u2192 ${style.bold(terminalSafeText(output.output))}`);
110
112
  const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);
111
113
  run.deps.console.info(`\u{1F680} ${target} ${duration}`);
112
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { redactUnparsedUrl } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * A scheme of two or more characters (`https:`, `file:`). One letter is a Windows drive (`C:`), so\n * `C:\\\\specs\\\\api.yaml` stays a path.\n */\nconst URL_SCHEME = /^[a-z][a-z\\d+.-]+:/i;\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (URL_SCHEME.test(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (URL_SCHEME.test(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const target = style.green(`${output.source} → ${style.bold(output.output)}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":[],"mappings":";;;;;;AAiCA,MAAM,UAAA,GAAa,qBAAA;AASZ,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,UAAA,CAAW,IAAA,CAAK,QAAQ,CAAA,EAAG;AAC7B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQ,kBAAkB,QAAQ,CAAA;AACxC,MAAA,MAAM,QAAA,CAAS,sBAAA,EAAwB,CAAA,aAAA,EAAgB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,gBAAgB,aAAA,CAAc,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAC,CAAA;AACtD,EAAA,OAAO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,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;"}
1
+ {"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":[],"mappings":";;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,YAAA,CAAa,QAAQ,CAAA,EAAG;AAC1B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQ,kBAAkB,QAAQ,CAAA;AACxC,MAAA,MAAM,QAAA,CAAS,sBAAA,EAAwB,CAAA,aAAA,EAAgB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,gBAAgB,aAAA,CAAc,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAC,CAAA;AACtD,EAAA,OAAO,aAAA,CAAc,IAAA,CAAK,OAAA,CAAQ,aAAA,EAAe,QAAQ,CAAC,CAAA;AAC5D;AAEA,MAAM,aAAA,GAAgB,OAAA;AAGtB,MAAM,qCAA0C,IAAI,GAAA,CAAI,CAAC,GAAA,EAAK,IAAI,CAAC,CAAA;AAOnE,SAAS,cAAA,CAAe,UAAkB,IAAA,EAAoB;AAC5D,EAAA,MAAM,WAAA,GAAc,QAAA,CACjB,KAAA,CAAM,IAAA,CAAK,GAAG,CAAA,CACd,OAAA,CAAQ,CAAC,IAAA,KAAS,KAAK,KAAA,CAAM,GAAG,CAAC,CAAA,CACjC,GAAG,EAAE,CAAA;AACR,EAAA,OACE,WAA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A,MAAM,MAAA,GAAS,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,MAAM,CAAA,QAAA,EAAM,KAAA,CAAM,IAAA,CAAK,gBAAA,CAAiB,MAAA,CAAO,MAAM,CAAC,CAAC,CAAA,CAAE,CAAA;AACvF,EAAA,MAAM,QAAA,GAAW,KAAA,CAAM,GAAA,CAAI,CAAA,CAAA,EAAI,cAAA,CAAe,KAAI,GAAI,GAAA,CAAI,SAAS,CAAC,CAAA,CAAA,CAAG,CAAA;AACvE,EAAA,GAAA,CAAI,KAAK,OAAA,CAAQ,IAAA,CAAK,aAAM,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAA;AAClD;AAMO,SAAS,UAAA,CAAW,GAAA,EAAa,MAAA,EAAoB,QAAA,EAAwB;AAClF,EAAA,IAAI,GAAA,CAAI,KAAK,OAAA,EAAS;AACpB,IAAA,IAAI,IAAI,IAAA,CAAK,KAAA,CAAM,SAAS,MAAA,CAAO,IAAI,MAAM,QAAA,EAAU;AAErD,MAAA,MAAM,QAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;"}
package/dist/cli/main.cjs CHANGED
@@ -5,11 +5,14 @@ const node_tty = require('node:tty');
5
5
  const node_url = require('node:url');
6
6
  const colors = require('ansi-colors');
7
7
  const nodeFileSystem = require('../adapters/node-file-system/node-file-system.cjs');
8
+ const pipeSafeWriter = require('../adapters/pipe-safe-writer/pipe-safe-writer.cjs');
8
9
  const redoclyConfigSource = require('../adapters/redocly-loader/redocly-config-source.cjs');
9
10
  const astToString = require('../api/ast-to-string.cjs');
10
11
  const commentHeader = require('../api/comment-header.cjs');
11
12
  const defaultPorts = require('../api/default-ports.cjs');
12
13
  const openapiTs = require('../api/openapi-ts.cjs');
14
+ const terminalText = require('../domain/terminal-text.cjs');
15
+ const apiLogger = require('./api-logger.cjs');
13
16
  const runCli = require('./run-cli.cjs');
14
17
 
15
18
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -33,8 +36,10 @@ function terminalStyle() {
33
36
  };
34
37
  }
35
38
  const STDIN_DESCRIPTOR = 0;
36
- const generateTypes = async (source, options) => {
37
- const ports = await openapiTs.defaultGeneratorPorts(options);
39
+ const generateTypes = async (source, options, apiName) => {
40
+ const terminalLogger = defaultPorts.defaultLogger(options.silent ?? false);
41
+ const logger = apiName === void 0 ? terminalLogger : apiLogger.apiLogger(terminalLogger, apiName);
42
+ const ports = await openapiTs.defaultGeneratorPorts(options, logger);
38
43
  const { declarations, localFiles } = await openapiTs.generateDocument(source, options, ports);
39
44
  return { contents: `${commentHeader.COMMENT_HEADER}${astToString.astToString(declarations)}`, localFiles };
40
45
  };
@@ -42,8 +47,9 @@ function terminalConsole() {
42
47
  return {
43
48
  // biome-ignore lint/suspicious/noConsole: the CLI's own output lines
44
49
  info: (text) => console.info(text),
50
+ // A notice names flags and API names as written, so it is shown as one plain line.
45
51
  // biome-ignore lint/suspicious/noConsole: the CLI's own notices
46
- notice: (text) => console.warn(text)
52
+ notice: (text) => console.warn(terminalText.terminalSafeText(text))
47
53
  };
48
54
  }
49
55
  function processDependencies() {
@@ -53,7 +59,7 @@ function processDependencies() {
53
59
  version: readVersion(),
54
60
  logger: defaultPorts.defaultLogger(false),
55
61
  console: terminalConsole(),
56
- writeStdout: (text) => process.stdout.write(text),
62
+ writeStdout: pipeSafeWriter.createPipeSafeWriter(process.stdout),
57
63
  stdin: () => process.stdin,
58
64
  // `isatty` reads the descriptor without opening `process.stdin`, which would keep the
59
65
  // process alive.
@@ -1 +1 @@
1
- {"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options) => {\n const ports = await defaultGeneratorPorts(options);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(text),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: (text) => process.stdout.write(text),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":["fs","colors","terminalSupportsColor","defaultGeneratorPorts","generateDocument","COMMENT_HEADER","astToString","pathToFileURL","defaultLogger","isatty","createNodeFileSystem","createRedoclyConfigSource","monotonicNow","runCli"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,8PAAe,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAMA,YAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAEA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAUC,gBAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,UAAUC,kCAAA,EAAsB;AACxC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK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IAC7C,QAAA,EAAU,aAAA;AAAA,IACV,GAAA,EAAKC,yBAAA;AAAA,IACL,OAAO,aAAA;AAAc,GACvB;AACF;AAEAC,aAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
1
+ {"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":["fs","colors","terminalSupportsColor","defaultLogger","apiLogger","defaultGeneratorPorts","generateDocument","COMMENT_HEADER","astToString","terminalSafeText","pathToFileURL","createPipeSafeWriter","isatty","createNodeFileSystem","createRedoclyConfigSource","monotonicNow","runCli"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,8PAAe,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,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A,KAAS,QAAQ,IAAA,CAAKC,6BAAA,CAAiB,IAAI,CAAC;AAAA,GACvD;AACF;AAEA,SAAS,mBAAA,GAAuC;AAC9C,EAAA,MAAM,GAAA,GAAM,QAAQ,GAAA,EAAI;AACxB,EAAA,OAAO;AAAA,IACL,GAAA,EAAKC,sBAAA,CAAc,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG,CAAA;AAAA,IAC5B,SAAS,WAAA,EAAY;AAAA,IACrB,MAAA,EAAQP,2BAAc,KAAK,CAAA;AAAA,IAC3B,SAAS,eAAA,EAAgB;AAAA,IACzB,WAAA,EAAaQ,mCAAA,CAAqB,OAAA,CAAQ,MAAM,CAAA;AAAA,IAChD,KAAA,EAAO,MAAM,OAAA,CAAQ,KAAA;AAAA;AAAA;AAAA,IAGrB,eAAA,EAAiB,MAAMC,eAAA,CAAO,gBAAgB,CAAA;AAAA,IAC9C,OAAOC,mCAAA,EAAqB;AAAA,IAC5B,cAAA,EAAgBC,8CAA0B,GAAG,CAAA;AAAA,IAC7C,QAAA,EAAU,aAAA;AAAA,IACV,GAAA,EAAKC,yBAAA;AAAA,IACL,OAAO,aAAA;AAAc,GACvB;AACF;AAEAC,aAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
package/dist/cli/main.mjs CHANGED
@@ -3,11 +3,14 @@ import { isatty } from 'node:tty';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import colors from 'ansi-colors';
5
5
  import { createNodeFileSystem } from '../adapters/node-file-system/node-file-system.mjs';
6
+ import { createPipeSafeWriter } from '../adapters/pipe-safe-writer/pipe-safe-writer.mjs';
6
7
  import { createRedoclyConfigSource } from '../adapters/redocly-loader/redocly-config-source.mjs';
7
8
  import { astToString } from '../api/ast-to-string.mjs';
8
9
  import { COMMENT_HEADER } from '../api/comment-header.mjs';
9
10
  import { monotonicNow, defaultLogger, terminalSupportsColor } from '../api/default-ports.mjs';
10
11
  import { defaultGeneratorPorts, generateDocument } from '../api/openapi-ts.mjs';
12
+ import { terminalSafeText } from '../domain/terminal-text.mjs';
13
+ import { apiLogger } from './api-logger.mjs';
11
14
  import { runCli } from './run-cli.mjs';
12
15
 
13
16
  const PACKAGE_JSON = new URL("../../package.json", import.meta.url);
@@ -25,8 +28,10 @@ function terminalStyle() {
25
28
  };
26
29
  }
27
30
  const STDIN_DESCRIPTOR = 0;
28
- const generateTypes = async (source, options) => {
29
- const ports = await defaultGeneratorPorts(options);
31
+ const generateTypes = async (source, options, apiName) => {
32
+ const terminalLogger = defaultLogger(options.silent ?? false);
33
+ const logger = apiName === void 0 ? terminalLogger : apiLogger(terminalLogger, apiName);
34
+ const ports = await defaultGeneratorPorts(options, logger);
30
35
  const { declarations, localFiles } = await generateDocument(source, options, ports);
31
36
  return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };
32
37
  };
@@ -34,8 +39,9 @@ function terminalConsole() {
34
39
  return {
35
40
  // biome-ignore lint/suspicious/noConsole: the CLI's own output lines
36
41
  info: (text) => console.info(text),
42
+ // A notice names flags and API names as written, so it is shown as one plain line.
37
43
  // biome-ignore lint/suspicious/noConsole: the CLI's own notices
38
- notice: (text) => console.warn(text)
44
+ notice: (text) => console.warn(terminalSafeText(text))
39
45
  };
40
46
  }
41
47
  function processDependencies() {
@@ -45,7 +51,7 @@ function processDependencies() {
45
51
  version: readVersion(),
46
52
  logger: defaultLogger(false),
47
53
  console: terminalConsole(),
48
- writeStdout: (text) => process.stdout.write(text),
54
+ writeStdout: createPipeSafeWriter(process.stdout),
49
55
  stdin: () => process.stdin,
50
56
  // `isatty` reads the descriptor without opening `process.stdin`, which would keep the
51
57
  // process alive.
@@ -1 +1 @@
1
- {"version":3,"file":"main.mjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options) => {\n const ports = await defaultGeneratorPorts(options);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(text),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: (text) => process.stdout.write(text),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":[],"mappings":";;;;;;;;;;;;AAmBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,YAAY,GAAG,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAM,GAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAEA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,UAAU,qBAAA,EAAsB;AACxC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,IAAI;AAAA,GACjC;AACF;AAEA,MAAM,gBAAA,GAAmB,CAAA;AAEzB,MAAM,aAAA,GAA+B,OAAO,MAAA,EAAQ,OAAA,KAAY;AAC9D,EAAA,MAAM,KAAA,GAAQ,MAAM,qBAAA,CAAsB,OAAO,CAAA;AACjD,EAAA,MAAM,EAAE,cAAc,UAAA,EAAW,GAAI,MAAM,gBAAA,CAAiB,MAAA,EAAQ,SAAS,KAAK,CAAA;AAClF,EAAA,OAAO,EAAE,UAAU,CAA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"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,YAAY,GAAG,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAM,GAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAEA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,UAAU,qBAAA,EAAsB;AACxC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,IAAI;AAAA,GACjC;AACF;AAEA,MAAM,gBAAA,GAAmB,CAAA;AAEzB,MAAM,aA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AC9C,OAAO,oBAAA,EAAqB;AAAA,IAC5B,cAAA,EAAgB,0BAA0B,GAAG,CAAA;AAAA,IAC7C,QAAA,EAAU,aAAA;AAAA,IACV,GAAA,EAAK,YAAA;AAAA,IACL,OAAO,aAAA;AAAc,GACvB;AACF;AAEA,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
@@ -2,6 +2,7 @@
2
2
 
3
3
  const apiSettings = require('./api-settings.cjs');
4
4
  const apiWrites = require('./api-writes.cjs');
5
+ const cliArguments = require('./cli-arguments.cjs');
5
6
  const cliErrors = require('./cli-errors.cjs');
6
7
  const cliOutput = require('./cli-output.cjs');
7
8
  const docsLinks = require('./docs-links.cjs');
@@ -43,21 +44,25 @@ function apiTarget(api, configRoot) {
43
44
  }
44
45
  return { name, root, settings, configRoot };
45
46
  }
46
- function apiOptions(run, redocly, target) {
47
+ function apiOptions(run, apiRun, target) {
47
48
  const { name, settings, configRoot } = target;
49
+ const flags = { ...run.args.generatorFlags, ...apiSettings.apiFlags(name, settings) };
50
+ for (const notice of cliArguments.ineffectiveFlagNotices(flags)) {
51
+ run.deps.console.notice(`API ${name}: ${notice}`);
52
+ }
48
53
  return {
49
- ...run.args.generatorFlags,
50
- ...apiSettings.apiFlags(name, settings),
51
- ...refLimits.refLimitOptions(run.args, run.deps.cwd),
54
+ ...flags,
55
+ ...apiRun.refLimits,
52
56
  ...apiSettings.apiRefLimitOptions(name, settings, configRoot),
53
57
  ...fixOption.fixOption(apiSettings.apiFixNames(name, settings) ?? run.args.fix),
54
- redocly
58
+ redocly: apiRun.redocly
55
59
  };
56
60
  }
57
61
  function otherOutputs(files, apiName) {
58
62
  return [...files.outputs].filter(([name]) => name !== apiName).map(([name, location]) => ({ name: `API ${name}`, location }));
59
63
  }
60
- async function generateApi(run, redocly, target, files) {
64
+ async function generateApi(run, apiRun, target) {
65
+ const { files } = apiRun;
61
66
  for (const warning of apiSettings.unknownSettingWarnings(target.name, target.settings)) {
62
67
  run.deps.logger.warn(warning);
63
68
  }
@@ -66,8 +71,13 @@ async function generateApi(run, redocly, target, files) {
66
71
  cliOutput.ensureOutputIsNotSchema(run, outputFile, files.schemas);
67
72
  cliOutput.ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));
68
73
  const source = cliOutput.resolveLocationUrl(target.root, target.configRoot);
69
- const types = await run.deps.generate(source, apiOptions(run, redocly, target));
70
- return { name: target.name, outputFile, types };
74
+ const options = apiOptions(run, apiRun, target);
75
+ try {
76
+ const types = await run.deps.generate(source, options, target.name);
77
+ return { name: target.name, outputFile, types };
78
+ } catch (error) {
79
+ throw new cliErrors.ApiFailure(target.name, error);
80
+ }
71
81
  }
72
82
  function configFilesOf(run, redocly, apis) {
73
83
  const configRoot = configRootOf(redocly, run.deps.cwd);
@@ -100,9 +110,10 @@ async function settledInTurn(items, task) {
100
110
  async function generateRedoclyApis(run, redocly) {
101
111
  const apis = redoclyApisOf(redocly);
102
112
  const { configRoot, files } = configFilesOf(run, redocly, apis);
113
+ const apiRun = { redocly, files, refLimits: refLimits.refLimitOptions(run.args, run.deps.cwd) };
103
114
  const results = await settledInTurn(
104
115
  apis,
105
- (api) => generateApi(run, redocly, apiTarget(api, configRoot), files)
116
+ (api) => generateApi(run, apiRun, apiTarget(api, configRoot))
106
117
  );
107
118
  const generated = results.flatMap(
108
119
  (result) => result.status === "fulfilled" ? [result.value] : []
@@ -1 +1 @@
1
- {"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/** The generator options of one API: its own settings win over the CLI's flags. */\nfunction apiOptions(run: CliRun, redocly: RedoclyConfig, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n return {\n ...run.args.generatorFlags,\n ...apiFlags(name, settings),\n ...refLimitOptions(run.args, run.deps.cwd),\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly,\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(\n run: CliRun,\n redocly: RedoclyConfig,\n target: ApiTarget,\n files: ConfigFiles,\n): Promise<GeneratedApi> {\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, outputFile, files.schemas);\n ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));\n const source = resolveLocationUrl(target.root, target.configRoot);\n const types = await run.deps.generate(source, apiOptions(run, redocly, target));\n return { name: target.name, outputFile, types };\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, redocly, apiTarget(api, configRoot), files),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":["resolveLocationUrl","cliError","OUTPUT_SETTING","MULTIPLE_SCHEMAS_DOCS_URL","apiFlags","refLimitOptions","apiRefLimitOptions","fixOption","apiFixNames","unknownSettingWarnings","apiOutputOf","outputFileOf","ensureOutputIsNotSchema","ensureOutputIsOwn","parseLocationUrl","redoclyConfigFiles","filesReadBy","writeGeneratedApis"],"mappings":";;;;;;;;;;AA+BA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,MAAA,GAAS,GAAA;AACf,IAAA,OAAO,EAAE,MAAM,IAAA,EAAM,MAAA,CAAO,MAAM,QAAA,EAAU,MAAA,CAAO,kBAAkB,CAAA,EAAE;AAAA,EACzE,CAAC,CAAA;AACH;AAEO,SAAS,eAAe,OAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAE,EAAE,MAAA,GAAS,CAAA;AAClD;AAGA,S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GACpD;AACA,EAAA,MAAM,SAAA,GAAY,SAAA,CAAU,OAAA,CAAQ,CAAC,EAAE,IAAA,EAAM,KAAA,EAAM,KAAMC,qBAAA,CAAY,GAAA,EAAK,KAAA,EAAO,CAAA,IAAA,EAAO,IAAI,EAAE,CAAC,CAAA;AAC/F,EAAA,MAAM,aAAA,GAAgBC,4BAAA,CAAmB,GAAA,EAAK,SAAA,EAAW,SAAS,CAAA;AAClE,EAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,MAAA,KACtB,MAAA,CAAO,MAAA,KAAW,aAAa,CAAC,MAAA,CAAO,MAAM,CAAA,GAAK,cAAc,GAAA,CAAI,MAAA,CAAO,KAAA,CAAM,IAAI,KAAK;AAAC,GAC7F;AACF;;;"}
1
+ {"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { ineffectiveFlagNotices } from \"./cli-arguments.js\";\nimport { ApiFailure, cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { type RefLimitOptions, refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/**\n * What every API of a run shares: the config, the files of all APIs, and the reference limits of\n * the command line, which are checked once before any API, so an invalid flag fails the run once.\n */\ninterface ApiRun {\n readonly redocly: RedoclyConfig;\n readonly files: ConfigFiles;\n readonly refLimits: RefLimitOptions;\n}\n\n/**\n * The generator options of one API: its own settings win over the CLI's flags. A flag that has\n * no effect with the merged flags is named for this API, since its settings may turn on the flag\n * that the command line lacks, or set one that has no effect themselves.\n */\nfunction apiOptions(run: CliRun, apiRun: ApiRun, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n const flags = { ...run.args.generatorFlags, ...apiFlags(name, settings) };\n for (const notice of ineffectiveFlagNotices(flags)) {\n run.deps.console.notice(`API ${name}: ${notice}`);\n }\n return {\n ...flags,\n ...apiRun.refLimits,\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly: apiRun.redocly,\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(run: CliRun, apiRun: ApiRun, target: ApiTarget): Promise<GeneratedApi> {\n const { files } = apiRun;\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, outputFile, files.schemas);\n ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));\n const source = resolveLocationUrl(target.root, target.configRoot);\n const options = apiOptions(run, apiRun, target);\n try {\n const types = await run.deps.generate(source, options, target.name);\n return { name: target.name, outputFile, types };\n } catch (error) {\n throw new ApiFailure(target.name, error);\n }\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const apiRun = { redocly, files, refLimits: refLimitOptions(run.args, run.deps.cwd) };\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, apiRun, apiTarget(api, configRoot)),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":["resolveLocationUrl","cliError","OUTPUT_SETTING","MULTIPLE_SCHEMAS_DOCS_URL","apiFlags","ineffectiveFlagNotices","apiRefLimitOptions","fixOption","apiFixNames","unknownSettingWarnings","apiOutputOf","outputFileOf","ensureOutputIsNotSchema","ensureOutputIsOwn","ApiFailure","parseLocationUrl","redoclyConfigFiles","refLimitOptions","filesReadBy","writeGeneratedApis"],"mappings":";;;;;;;;;;;AAgCA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,MAAA,GAAS,GAAA;AACf,IAAA,OAAO,EAAE,MAAM,IAAA,EAAM,MAAA,CAAO,MAAM,QAAA,EAAU,MAAA,CAAO,kBAAkB,CAAA,EAAE;AAAA,EACzE,CAAC,CAAA;AACH;AAEO,SAAS,eAAe,OAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAE,EAAE,MAAA,GAAS,CAAA;AAClD;AAGA,SAAS,YAAA,CAAa,SAAwB,GAAA,EAAe;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