openapi-typesafe 1.0.0-rc.3 → 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 (596) hide show
  1. package/CHANGELOG.md +1972 -0
  2. package/dist/adapters/node-file-system/file-claims.cjs +105 -0
  3. package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
  4. package/dist/adapters/node-file-system/file-claims.mjs +95 -0
  5. package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
  6. package/dist/adapters/node-file-system/file-identity.cjs +82 -0
  7. package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
  8. package/dist/adapters/node-file-system/file-identity.mjs +74 -0
  9. package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
  10. package/dist/adapters/node-file-system/node-file-system.cjs +97 -14
  11. package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
  12. package/dist/adapters/node-file-system/node-file-system.mjs +97 -14
  13. package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
  14. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
  15. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
  16. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
  17. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
  18. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +48 -0
  19. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +45 -0
  21. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
  23. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
  24. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
  25. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
  26. package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
  27. package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
  28. package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
  29. package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
  30. package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
  31. package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
  32. package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
  33. package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
  34. package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
  35. package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
  36. package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
  37. package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
  38. package/dist/adapters/redocly-loader/query-named-components.cjs +137 -0
  39. package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
  40. package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
  41. package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
  42. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +40 -29
  43. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  44. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +38 -27
  45. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  46. package/dist/adapters/redocly-loader/ref-access.cjs +45 -4
  47. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  48. package/dist/adapters/redocly-loader/ref-access.mjs +45 -4
  49. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  50. package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
  51. package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
  52. package/dist/adapters/redocly-loader/ref-holders.mjs +53 -12
  53. package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
  54. package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
  55. package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
  56. package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
  57. package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
  58. package/dist/adapters/redocly-loader/remote-fetch.cjs +40 -9
  59. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  60. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -9
  61. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  62. package/dist/adapters/redocly-loader/remote-node-limit.cjs +61 -0
  63. package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
  64. package/dist/adapters/redocly-loader/remote-node-limit.mjs +58 -0
  65. package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
  66. package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
  67. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  68. package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
  69. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  70. package/dist/adapters/redocly-loader/schema-source.cjs +18 -9
  71. package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
  72. package/dist/adapters/redocly-loader/schema-source.mjs +20 -11
  73. package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
  74. package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
  75. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  76. package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
  77. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  78. package/dist/adapters/terminal-logger/terminal-logger.cjs +10 -4
  79. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  80. package/dist/adapters/terminal-logger/terminal-logger.mjs +10 -4
  81. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  82. package/dist/api/default-ports.cjs +14 -2
  83. package/dist/api/default-ports.cjs.map +1 -1
  84. package/dist/api/default-ports.mjs +14 -2
  85. package/dist/api/default-ports.mjs.map +1 -1
  86. package/dist/api/discriminator-enum-parent.cjs +2 -2
  87. package/dist/api/discriminator-enum-parent.cjs.map +1 -1
  88. package/dist/api/discriminator-enum-parent.mjs +3 -3
  89. package/dist/api/discriminator-enum-parent.mjs.map +1 -1
  90. package/dist/api/discriminator-other-owners.cjs +5 -3
  91. package/dist/api/discriminator-other-owners.cjs.map +1 -1
  92. package/dist/api/discriminator-other-owners.mjs +5 -3
  93. package/dist/api/discriminator-other-owners.mjs.map +1 -1
  94. package/dist/api/discriminator-patch.cjs +5 -1
  95. package/dist/api/discriminator-patch.cjs.map +1 -1
  96. package/dist/api/discriminator-patch.mjs +5 -1
  97. package/dist/api/discriminator-patch.mjs.map +1 -1
  98. package/dist/api/discriminator-scan.cjs +15 -8
  99. package/dist/api/discriminator-scan.cjs.map +1 -1
  100. package/dist/api/discriminator-scan.mjs +15 -8
  101. package/dist/api/discriminator-scan.mjs.map +1 -1
  102. package/dist/api/document-refs.cjs +16 -1
  103. package/dist/api/document-refs.cjs.map +1 -1
  104. package/dist/api/document-refs.mjs +16 -1
  105. package/dist/api/document-refs.mjs.map +1 -1
  106. package/dist/api/document-run.cjs +6 -12
  107. package/dist/api/document-run.cjs.map +1 -1
  108. package/dist/api/document-run.mjs +6 -12
  109. package/dist/api/document-run.mjs.map +1 -1
  110. package/dist/api/legacy-utils.cjs.map +1 -1
  111. package/dist/api/legacy-utils.mjs.map +1 -1
  112. package/dist/api/openapi-ts.cjs +9 -6
  113. package/dist/api/openapi-ts.cjs.map +1 -1
  114. package/dist/api/openapi-ts.mjs +10 -8
  115. package/dist/api/openapi-ts.mjs.map +1 -1
  116. package/dist/api/ref-limit-options.cjs +63 -0
  117. package/dist/api/ref-limit-options.cjs.map +1 -0
  118. package/dist/api/ref-limit-options.mjs +57 -0
  119. package/dist/api/ref-limit-options.mjs.map +1 -0
  120. package/dist/api/schema-callbacks.cjs +36 -12
  121. package/dist/api/schema-callbacks.cjs.map +1 -1
  122. package/dist/api/schema-callbacks.mjs +36 -12
  123. package/dist/api/schema-callbacks.mjs.map +1 -1
  124. package/dist/api/transform-context.cjs +7 -3
  125. package/dist/api/transform-context.cjs.map +1 -1
  126. package/dist/api/transform-context.mjs +7 -3
  127. package/dist/api/transform-context.mjs.map +1 -1
  128. package/dist/api/transform-schema.cjs +47 -10
  129. package/dist/api/transform-schema.cjs.map +1 -1
  130. package/dist/api/transform-schema.mjs +48 -11
  131. package/dist/api/transform-schema.mjs.map +1 -1
  132. package/dist/application/print/text-writer.cjs +10 -3
  133. package/dist/application/print/text-writer.cjs.map +1 -1
  134. package/dist/application/print/text-writer.mjs +10 -3
  135. package/dist/application/print/text-writer.mjs.map +1 -1
  136. package/dist/application/stack-overflow.cjs +2 -1
  137. package/dist/application/stack-overflow.cjs.map +1 -1
  138. package/dist/application/stack-overflow.mjs +2 -1
  139. package/dist/application/stack-overflow.mjs.map +1 -1
  140. package/dist/application/transform/declared-value-types.cjs +36 -0
  141. package/dist/application/transform/declared-value-types.cjs.map +1 -0
  142. package/dist/application/transform/declared-value-types.mjs +34 -0
  143. package/dist/application/transform/declared-value-types.mjs.map +1 -0
  144. package/dist/application/transform/document/components.cjs +1 -1
  145. package/dist/application/transform/document/components.cjs.map +1 -1
  146. package/dist/application/transform/document/components.mjs +2 -2
  147. package/dist/application/transform/document/components.mjs.map +1 -1
  148. package/dist/application/transform/document/declared-type-names.cjs +23 -0
  149. package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
  150. package/dist/application/transform/document/declared-type-names.mjs +20 -0
  151. package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
  152. package/dist/application/transform/document/defs-root.cjs +1 -1
  153. package/dist/application/transform/document/defs-root.cjs.map +1 -1
  154. package/dist/application/transform/document/defs-root.mjs +2 -2
  155. package/dist/application/transform/document/defs-root.mjs.map +1 -1
  156. package/dist/application/transform/document/document.cjs +7 -2
  157. package/dist/application/transform/document/document.cjs.map +1 -1
  158. package/dist/application/transform/document/document.mjs +6 -3
  159. package/dist/application/transform/document/document.mjs.map +1 -1
  160. package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
  161. package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
  162. package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
  163. package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
  164. package/dist/application/transform/document/exploded-query-values.cjs +63 -0
  165. package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
  166. package/dist/application/transform/document/exploded-query-values.mjs +59 -0
  167. package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
  168. package/dist/application/transform/document/global-type-references.cjs +1 -0
  169. package/dist/application/transform/document/global-type-references.cjs.map +1 -1
  170. package/dist/application/transform/document/global-type-references.mjs +1 -1
  171. package/dist/application/transform/document/global-type-references.mjs.map +1 -1
  172. package/dist/application/transform/document/header.cjs +11 -3
  173. package/dist/application/transform/document/header.cjs.map +1 -1
  174. package/dist/application/transform/document/header.mjs +10 -2
  175. package/dist/application/transform/document/header.mjs.map +1 -1
  176. package/dist/application/transform/document/media-type.cjs +2 -2
  177. package/dist/application/transform/document/media-type.cjs.map +1 -1
  178. package/dist/application/transform/document/media-type.mjs +3 -3
  179. package/dist/application/transform/document/media-type.mjs.map +1 -1
  180. package/dist/application/transform/document/operation-keys-written.cjs +26 -0
  181. package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
  182. package/dist/application/transform/document/operation-keys-written.mjs +24 -0
  183. package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
  184. package/dist/application/transform/document/operation.cjs +1 -1
  185. package/dist/application/transform/document/operation.cjs.map +1 -1
  186. package/dist/application/transform/document/operation.mjs +2 -2
  187. package/dist/application/transform/document/operation.mjs.map +1 -1
  188. package/dist/application/transform/document/parameter-entries.cjs +34 -0
  189. package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
  190. package/dist/application/transform/document/parameter-entries.mjs +30 -0
  191. package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
  192. package/dist/application/transform/document/parameter.cjs +12 -4
  193. package/dist/application/transform/document/parameter.cjs.map +1 -1
  194. package/dist/application/transform/document/parameter.mjs +13 -5
  195. package/dist/application/transform/document/parameter.mjs.map +1 -1
  196. package/dist/application/transform/document/parameters.cjs +29 -34
  197. package/dist/application/transform/document/parameters.cjs.map +1 -1
  198. package/dist/application/transform/document/parameters.mjs +29 -34
  199. package/dist/application/transform/document/parameters.mjs.map +1 -1
  200. package/dist/application/transform/document/path-item.cjs +15 -17
  201. package/dist/application/transform/document/path-item.cjs.map +1 -1
  202. package/dist/application/transform/document/path-item.mjs +15 -19
  203. package/dist/application/transform/document/path-item.mjs.map +1 -1
  204. package/dist/application/transform/document/path-template-key.cjs +84 -0
  205. package/dist/application/transform/document/path-template-key.cjs.map +1 -0
  206. package/dist/application/transform/document/path-template-key.mjs +79 -0
  207. package/dist/application/transform/document/path-template-key.mjs.map +1 -0
  208. package/dist/application/transform/document/path-template-refs.cjs +70 -0
  209. package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
  210. package/dist/application/transform/document/path-template-refs.mjs +67 -0
  211. package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
  212. package/dist/application/transform/document/paths-enum.cjs +8 -6
  213. package/dist/application/transform/document/paths-enum.cjs.map +1 -1
  214. package/dist/application/transform/document/paths-enum.mjs +8 -7
  215. package/dist/application/transform/document/paths-enum.mjs.map +1 -1
  216. package/dist/application/transform/document/paths.cjs +43 -67
  217. package/dist/application/transform/document/paths.cjs.map +1 -1
  218. package/dist/application/transform/document/paths.mjs +42 -68
  219. package/dist/application/transform/document/paths.mjs.map +1 -1
  220. package/dist/application/transform/document/referenced-parameter.cjs +80 -0
  221. package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
  222. package/dist/application/transform/document/referenced-parameter.mjs +78 -0
  223. package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
  224. package/dist/application/transform/document/request-body.cjs +1 -1
  225. package/dist/application/transform/document/request-body.cjs.map +1 -1
  226. package/dist/application/transform/document/request-body.mjs +2 -2
  227. package/dist/application/transform/document/request-body.mjs.map +1 -1
  228. package/dist/application/transform/document/response.cjs +2 -2
  229. package/dist/application/transform/document/response.cjs.map +1 -1
  230. package/dist/application/transform/document/response.mjs +3 -3
  231. package/dist/application/transform/document/response.mjs.map +1 -1
  232. package/dist/application/transform/document/responses.cjs +1 -1
  233. package/dist/application/transform/document/responses.cjs.map +1 -1
  234. package/dist/application/transform/document/responses.mjs +2 -2
  235. package/dist/application/transform/document/responses.mjs.map +1 -1
  236. package/dist/application/transform/document/root-type-aliases.cjs +8 -23
  237. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  238. package/dist/application/transform/document/root-type-aliases.mjs +8 -24
  239. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  240. package/dist/application/transform/document/type-resolution.cjs +3 -1
  241. package/dist/application/transform/document/type-resolution.cjs.map +1 -1
  242. package/dist/application/transform/document/type-resolution.mjs +3 -1
  243. package/dist/application/transform/document/type-resolution.mjs.map +1 -1
  244. package/dist/application/transform/document/webhooks.cjs +10 -3
  245. package/dist/application/transform/document/webhooks.cjs.map +1 -1
  246. package/dist/application/transform/document/webhooks.mjs +10 -3
  247. package/dist/application/transform/document/webhooks.mjs.map +1 -1
  248. package/dist/application/transform/footer/document-footer.cjs +16 -5
  249. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  250. package/dist/application/transform/footer/document-footer.mjs +16 -5
  251. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  252. package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
  253. package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
  254. package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
  255. package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
  256. package/dist/application/transform/footer/operation-keys.cjs +23 -0
  257. package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
  258. package/dist/application/transform/footer/operation-keys.mjs +21 -0
  259. package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
  260. package/dist/application/transform/footer/type-evaluation.cjs +4 -4
  261. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
  262. package/dist/application/transform/footer/type-evaluation.mjs +4 -4
  263. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
  264. package/dist/application/transform/helper-types.cjs +3 -3
  265. package/dist/application/transform/helper-types.cjs.map +1 -1
  266. package/dist/application/transform/helper-types.mjs +3 -3
  267. package/dist/application/transform/helper-types.mjs.map +1 -1
  268. package/dist/application/transform/numbered-names.cjs +9 -0
  269. package/dist/application/transform/numbered-names.cjs.map +1 -1
  270. package/dist/application/transform/numbered-names.mjs +9 -1
  271. package/dist/application/transform/numbered-names.mjs.map +1 -1
  272. package/dist/application/transform/ref-pointer/generated-location.cjs +5 -5
  273. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
  274. package/dist/application/transform/ref-pointer/generated-location.mjs +3 -3
  275. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
  276. package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
  277. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
  278. package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
  279. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
  280. package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
  281. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
  282. package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
  283. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
  284. package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
  285. package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
  286. package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
  287. package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
  288. package/dist/application/transform/ref-pointer/original-index.cjs +68 -13
  289. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
  290. package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
  291. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
  292. package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
  293. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
  294. package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
  295. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
  296. package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
  297. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
  298. package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
  299. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
  300. package/dist/application/transform/ref-pointer/property-shape.cjs +52 -0
  301. package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
  302. package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
  303. package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
  304. package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
  305. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
  306. package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
  307. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
  308. package/dist/application/transform/ref-type.cjs +2 -1
  309. package/dist/application/transform/ref-type.cjs.map +1 -1
  310. package/dist/application/transform/ref-type.mjs +2 -1
  311. package/dist/application/transform/ref-type.mjs.map +1 -1
  312. package/dist/application/transform/schema/access-flags.cjs.map +1 -1
  313. package/dist/application/transform/schema/access-flags.mjs.map +1 -1
  314. package/dist/application/transform/schema/composition-type.cjs +1 -1
  315. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  316. package/dist/application/transform/schema/composition-type.mjs +2 -2
  317. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  318. package/dist/application/transform/schema/enum-rule.cjs +1 -1
  319. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  320. package/dist/application/transform/schema/enum-rule.mjs +2 -2
  321. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  322. package/dist/application/transform/schema/index-signature-type.cjs +21 -0
  323. package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
  324. package/dist/application/transform/schema/index-signature-type.mjs +19 -0
  325. package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
  326. package/dist/application/transform/schema/input-location.cjs +23 -0
  327. package/dist/application/transform/schema/input-location.cjs.map +1 -0
  328. package/dist/application/transform/schema/input-location.mjs +21 -0
  329. package/dist/application/transform/schema/input-location.mjs.map +1 -0
  330. package/dist/application/transform/schema/object-type.cjs +18 -8
  331. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  332. package/dist/application/transform/schema/object-type.mjs +19 -9
  333. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  334. package/dist/application/transform/schema/ref-siblings.cjs +47 -0
  335. package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
  336. package/dist/application/transform/schema/ref-siblings.mjs +45 -0
  337. package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
  338. package/dist/application/transform/schema/schema-transform.cjs +6 -3
  339. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  340. package/dist/application/transform/schema/schema-transform.mjs +6 -3
  341. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  342. package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
  343. package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
  344. package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
  345. package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
  346. package/dist/application/transform/schema-comment.cjs +5 -1
  347. package/dist/application/transform/schema-comment.cjs.map +1 -1
  348. package/dist/application/transform/schema-comment.mjs +5 -1
  349. package/dist/application/transform/schema-comment.mjs.map +1 -1
  350. package/dist/cli/api-logger.cjs +13 -0
  351. package/dist/cli/api-logger.cjs.map +1 -0
  352. package/dist/cli/api-logger.mjs +11 -0
  353. package/dist/cli/api-logger.mjs.map +1 -0
  354. package/dist/cli/api-settings.cjs +57 -9
  355. package/dist/cli/api-settings.cjs.map +1 -1
  356. package/dist/cli/api-settings.mjs +56 -11
  357. package/dist/cli/api-settings.mjs.map +1 -1
  358. package/dist/cli/api-writes.cjs +72 -0
  359. package/dist/cli/api-writes.cjs.map +1 -0
  360. package/dist/cli/api-writes.mjs +69 -0
  361. package/dist/cli/api-writes.mjs.map +1 -0
  362. package/dist/cli/cli-arguments.cjs +51 -11
  363. package/dist/cli/cli-arguments.cjs.map +1 -1
  364. package/dist/cli/cli-arguments.mjs +51 -11
  365. package/dist/cli/cli-arguments.mjs.map +1 -1
  366. package/dist/cli/cli-errors.cjs +29 -1
  367. package/dist/cli/cli-errors.cjs.map +1 -1
  368. package/dist/cli/cli-errors.mjs +29 -2
  369. package/dist/cli/cli-errors.mjs.map +1 -1
  370. package/dist/cli/cli-output.cjs +111 -4
  371. package/dist/cli/cli-output.cjs.map +1 -1
  372. package/dist/cli/cli-output.mjs +104 -5
  373. package/dist/cli/cli-output.mjs.map +1 -1
  374. package/dist/cli/main.cjs +13 -3
  375. package/dist/cli/main.cjs.map +1 -1
  376. package/dist/cli/main.mjs +14 -4
  377. package/dist/cli/main.mjs.map +1 -1
  378. package/dist/cli/redocly-apis.cjs +94 -37
  379. package/dist/cli/redocly-apis.cjs.map +1 -1
  380. package/dist/cli/redocly-apis.mjs +99 -42
  381. package/dist/cli/redocly-apis.mjs.map +1 -1
  382. package/dist/cli/ref-limits.cjs +15 -1
  383. package/dist/cli/ref-limits.cjs.map +1 -1
  384. package/dist/cli/ref-limits.mjs +15 -2
  385. package/dist/cli/ref-limits.mjs.map +1 -1
  386. package/dist/cli/run-cli.cjs +37 -14
  387. package/dist/cli/run-cli.cjs.map +1 -1
  388. package/dist/cli/run-cli.mjs +39 -16
  389. package/dist/cli/run-cli.mjs.map +1 -1
  390. package/dist/domain/append-all.cjs +10 -0
  391. package/dist/domain/append-all.cjs.map +1 -0
  392. package/dist/domain/append-all.mjs +8 -0
  393. package/dist/domain/append-all.mjs.map +1 -0
  394. package/dist/domain/cause-secrets.cjs +52 -0
  395. package/dist/domain/cause-secrets.cjs.map +1 -0
  396. package/dist/domain/cause-secrets.mjs +50 -0
  397. package/dist/domain/cause-secrets.mjs.map +1 -0
  398. package/dist/domain/errors.cjs +11 -3
  399. package/dist/domain/errors.cjs.map +1 -1
  400. package/dist/domain/errors.mjs +11 -3
  401. package/dist/domain/errors.mjs.map +1 -1
  402. package/dist/domain/ir/identifier-text.cjs.map +1 -1
  403. package/dist/domain/ir/identifier-text.mjs +1 -1
  404. package/dist/domain/ir/identifier-text.mjs.map +1 -1
  405. package/dist/domain/ir/ir-shape.cjs +187 -0
  406. package/dist/domain/ir/ir-shape.cjs.map +1 -0
  407. package/dist/domain/ir/ir-shape.mjs +184 -0
  408. package/dist/domain/ir/ir-shape.mjs.map +1 -0
  409. package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
  410. package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
  411. package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
  412. package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
  413. package/dist/domain/location-text.cjs +9 -0
  414. package/dist/domain/location-text.cjs.map +1 -0
  415. package/dist/domain/location-text.mjs +7 -0
  416. package/dist/domain/location-text.mjs.map +1 -0
  417. package/dist/domain/openapi/alias-expansion.cjs +3 -1
  418. package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
  419. package/dist/domain/openapi/alias-expansion.mjs +3 -1
  420. package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
  421. package/dist/domain/openapi/discriminated-union.cjs +3 -3
  422. package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
  423. package/dist/domain/openapi/discriminated-union.mjs +4 -4
  424. package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
  425. package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
  426. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
  427. package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
  428. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
  429. package/dist/domain/openapi/document-places.cjs +55 -0
  430. package/dist/domain/openapi/document-places.cjs.map +1 -0
  431. package/dist/domain/openapi/document-places.mjs +53 -0
  432. package/dist/domain/openapi/document-places.mjs.map +1 -0
  433. package/dist/domain/openapi/json-pointer.cjs +43 -1
  434. package/dist/domain/openapi/json-pointer.cjs.map +1 -1
  435. package/dist/domain/openapi/json-pointer.mjs +40 -2
  436. package/dist/domain/openapi/json-pointer.mjs.map +1 -1
  437. package/dist/domain/openapi/schema-dialect.cjs +15 -0
  438. package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
  439. package/dist/domain/openapi/schema-dialect.mjs +12 -0
  440. package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
  441. package/dist/domain/openapi/unsupported-features.cjs +1 -1
  442. package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
  443. package/dist/domain/openapi/unsupported-features.mjs +2 -2
  444. package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
  445. package/dist/domain/output-fixes.cjs +20 -0
  446. package/dist/domain/output-fixes.cjs.map +1 -1
  447. package/dist/domain/output-fixes.mjs +20 -0
  448. package/dist/domain/output-fixes.mjs.map +1 -1
  449. package/dist/domain/terminal-text.cjs +31 -0
  450. package/dist/domain/terminal-text.cjs.map +1 -0
  451. package/dist/domain/terminal-text.mjs +29 -0
  452. package/dist/domain/terminal-text.mjs.map +1 -0
  453. package/dist/domain/url-secrets.cjs +48 -0
  454. package/dist/domain/url-secrets.cjs.map +1 -0
  455. package/dist/domain/url-secrets.mjs +45 -0
  456. package/dist/domain/url-secrets.mjs.map +1 -0
  457. package/dist/domain/warnings.cjs +1 -0
  458. package/dist/domain/warnings.cjs.map +1 -1
  459. package/dist/domain/warnings.mjs +1 -0
  460. package/dist/domain/warnings.mjs.map +1 -1
  461. package/dist/index.d.cts +46 -20
  462. package/dist/index.d.mts +46 -20
  463. package/dist/index.d.ts +46 -20
  464. package/package.json +4 -5
  465. package/src/adapters/node-file-system/file-claims.ts +138 -0
  466. package/src/adapters/node-file-system/file-identity.ts +137 -0
  467. package/src/adapters/node-file-system/node-file-system.ts +158 -18
  468. package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
  469. package/src/adapters/redocly-loader/bundled-mapping-copies.ts +60 -0
  470. package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
  471. package/src/adapters/redocly-loader/component-schemas.ts +19 -0
  472. package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
  473. package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
  474. package/src/adapters/redocly-loader/query-named-components.ts +201 -0
  475. package/src/adapters/redocly-loader/redocly-schema-loader.ts +64 -38
  476. package/src/adapters/redocly-loader/ref-access.ts +51 -4
  477. package/src/adapters/redocly-loader/ref-holders.ts +76 -15
  478. package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
  479. package/src/adapters/redocly-loader/remote-fetch.ts +85 -13
  480. package/src/adapters/redocly-loader/remote-node-limit.ts +102 -0
  481. package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
  482. package/src/adapters/redocly-loader/schema-source.ts +35 -11
  483. package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
  484. package/src/adapters/terminal-logger/terminal-logger.ts +17 -6
  485. package/src/api/default-ports.ts +33 -4
  486. package/src/api/discriminator-enum-parent.ts +3 -3
  487. package/src/api/discriminator-other-owners.ts +5 -3
  488. package/src/api/discriminator-patch.ts +5 -1
  489. package/src/api/discriminator-scan.ts +16 -8
  490. package/src/api/document-refs.ts +29 -1
  491. package/src/api/document-run.ts +10 -19
  492. package/src/api/legacy-utils.ts +5 -1
  493. package/src/api/openapi-ts.ts +26 -8
  494. package/src/api/ref-limit-options.ts +76 -0
  495. package/src/api/run-context.ts +3 -0
  496. package/src/api/schema-callbacks.ts +60 -17
  497. package/src/api/transform-context.ts +7 -3
  498. package/src/api/transform-schema.ts +79 -12
  499. package/src/application/ports/file-system.ts +47 -0
  500. package/src/application/ports/schema-loader.ts +11 -1
  501. package/src/application/print/text-writer.ts +10 -3
  502. package/src/application/stack-overflow.ts +9 -5
  503. package/src/application/transform/declared-value-types.ts +42 -0
  504. package/src/application/transform/document/components.ts +2 -2
  505. package/src/application/transform/document/declared-type-names.ts +36 -0
  506. package/src/application/transform/document/defs-root.ts +2 -2
  507. package/src/application/transform/document/document.ts +8 -5
  508. package/src/application/transform/document/enum-names-given-back.ts +91 -0
  509. package/src/application/transform/document/exploded-query-values.ts +88 -0
  510. package/src/application/transform/document/global-type-references.ts +1 -1
  511. package/src/application/transform/document/header.ts +25 -5
  512. package/src/application/transform/document/media-type.ts +4 -3
  513. package/src/application/transform/document/operation-keys-written.ts +27 -0
  514. package/src/application/transform/document/operation.ts +2 -2
  515. package/src/application/transform/document/parameter-entries.ts +70 -0
  516. package/src/application/transform/document/parameter.ts +21 -9
  517. package/src/application/transform/document/parameters.ts +56 -66
  518. package/src/application/transform/document/path-item.ts +16 -34
  519. package/src/application/transform/document/path-template-key.ts +152 -0
  520. package/src/application/transform/document/path-template-refs.ts +106 -0
  521. package/src/application/transform/document/paths-enum.ts +24 -10
  522. package/src/application/transform/document/paths.ts +59 -125
  523. package/src/application/transform/document/referenced-parameter.ts +146 -0
  524. package/src/application/transform/document/request-body.ts +2 -2
  525. package/src/application/transform/document/response.ts +3 -3
  526. package/src/application/transform/document/responses.ts +2 -2
  527. package/src/application/transform/document/root-type-aliases.ts +17 -38
  528. package/src/application/transform/document/type-resolution.ts +2 -1
  529. package/src/application/transform/document/webhooks.ts +19 -6
  530. package/src/application/transform/footer/document-footer.ts +36 -9
  531. package/src/application/transform/footer/enum-name-claims.ts +62 -0
  532. package/src/application/transform/footer/operation-keys.ts +28 -0
  533. package/src/application/transform/footer/type-evaluation.ts +4 -4
  534. package/src/application/transform/helper-types.ts +8 -7
  535. package/src/application/transform/numbered-names.ts +15 -0
  536. package/src/application/transform/ref-pointer/generated-location.ts +3 -3
  537. package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
  538. package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
  539. package/src/application/transform/ref-pointer/located-node.ts +38 -0
  540. package/src/application/transform/ref-pointer/original-index.ts +100 -17
  541. package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
  542. package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
  543. package/src/application/transform/ref-pointer/property-shape.ts +97 -0
  544. package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
  545. package/src/application/transform/ref-type.ts +2 -1
  546. package/src/application/transform/schema/access-flags.ts +5 -2
  547. package/src/application/transform/schema/composition-type.ts +2 -2
  548. package/src/application/transform/schema/enum-rule.ts +6 -2
  549. package/src/application/transform/schema/index-signature-type.ts +31 -0
  550. package/src/application/transform/schema/input-location.ts +35 -0
  551. package/src/application/transform/schema/object-type.ts +22 -12
  552. package/src/application/transform/schema/ref-siblings.ts +76 -0
  553. package/src/application/transform/schema/schema-context.ts +3 -0
  554. package/src/application/transform/schema/schema-transform.ts +6 -3
  555. package/src/application/transform/schema/unevaluated-properties.ts +4 -44
  556. package/src/application/transform/schema-comment.ts +5 -1
  557. package/src/application/transform/transform-context.ts +5 -0
  558. package/src/cli/api-logger.ts +17 -0
  559. package/src/cli/api-settings.ts +80 -13
  560. package/src/cli/api-writes.ts +117 -0
  561. package/src/cli/cli-arguments.ts +90 -14
  562. package/src/cli/cli-dependencies.ts +26 -4
  563. package/src/cli/cli-errors.ts +42 -1
  564. package/src/cli/cli-output.ts +195 -15
  565. package/src/cli/main.ts +14 -5
  566. package/src/cli/redocly-apis.ts +177 -52
  567. package/src/cli/ref-limits.ts +21 -2
  568. package/src/cli/run-cli.ts +76 -15
  569. package/src/domain/append-all.ts +10 -0
  570. package/src/domain/cause-secrets.ts +86 -0
  571. package/src/domain/errors.ts +16 -5
  572. package/src/domain/ir/identifier-text.ts +6 -5
  573. package/src/domain/ir/ir-shape.ts +299 -0
  574. package/src/domain/ir/newer-identifier-ranges.ts +183 -30
  575. package/src/domain/location-text.ts +12 -0
  576. package/src/domain/openapi/alias-expansion.ts +4 -1
  577. package/src/domain/openapi/discriminated-union.ts +6 -4
  578. package/src/domain/openapi/discriminator-conflicts.ts +21 -7
  579. package/src/domain/openapi/document-object.ts +2 -0
  580. package/src/domain/openapi/document-places.ts +78 -0
  581. package/src/domain/openapi/json-pointer.ts +96 -7
  582. package/src/domain/openapi/schema-dialect.ts +22 -0
  583. package/src/domain/openapi/unsupported-features.ts +2 -2
  584. package/src/domain/output-fixes.ts +28 -2
  585. package/src/domain/terminal-text.ts +44 -0
  586. package/src/domain/url-secrets.ts +72 -0
  587. package/src/domain/warnings.ts +1 -0
  588. package/src/types/generator-options.ts +1 -1
  589. package/dist/cli/main.d.cts +0 -2
  590. package/dist/cli/main.d.mts +0 -2
  591. package/dist/cli/main.d.ts +0 -2
  592. package/dist/domain/url-credentials.cjs +0 -10
  593. package/dist/domain/url-credentials.cjs.map +0 -1
  594. package/dist/domain/url-credentials.mjs +0 -8
  595. package/dist/domain/url-credentials.mjs.map +0 -1
  596. package/src/domain/url-credentials.ts +0 -18
@@ -42,20 +42,59 @@ const REMOVED_FLAGS = [
42
42
  ["-it", `The -it alias has been deprecated. Use "--immutable" instead.`],
43
43
  ["--redoc", `The --redoc config flag has been renamed to "--redocly" (or -c as shorthand).`]
44
44
  ];
45
- const ROOT_TYPES_FLAGS = ["--root-types-no-schema-prefix", "--root-types-keep-casing"];
46
- function rejectRemovedFlags(argv) {
45
+ const ROOT_TYPES_FLAGS = ["rootTypesNoSchemaPrefix", "rootTypesKeepCasing"];
46
+ const OPTIONS_END = "--";
47
+ const LONG_PREFIX = "--";
48
+ const NEGATION_PREFIX = "--no-";
49
+ const VALUE_SEPARATOR = "=";
50
+ const BOOLEAN_VALUES = /* @__PURE__ */ new Set(["true", "false"]);
51
+ function writtenFlags(argv) {
52
+ const end = argv.indexOf(OPTIONS_END);
53
+ return (end === -1 ? argv : argv.slice(0, end)).filter((arg) => arg.startsWith("-") && arg !== "-").map((arg) => {
54
+ const at = arg.indexOf(VALUE_SEPARATOR);
55
+ return at === -1 ? { name: arg, value: void 0 } : { name: arg.slice(0, at), value: arg.slice(at + 1) };
56
+ });
57
+ }
58
+ function canonicalFlagName(name) {
59
+ if (!name.startsWith(LONG_PREFIX)) {
60
+ return name;
61
+ }
62
+ const bare = name.startsWith(NEGATION_PREFIX) ? name.slice(NEGATION_PREFIX.length) : name.slice(LONG_PREFIX.length);
63
+ return `${LONG_PREFIX}${kebabCase(bare)}`;
64
+ }
65
+ function rejectRemovedFlags(flags) {
66
+ const names = new Set(flags.map(({ name }) => canonicalFlagName(name)));
47
67
  for (const [flag, message] of REMOVED_FLAGS) {
48
- if (argv.includes(flag)) {
68
+ if (names.has(flag)) {
49
69
  throw cliError("CLI_FLAG_REMOVED", message);
50
70
  }
51
71
  }
52
72
  }
53
- function ineffectiveFlagNotices(argv) {
54
- if (argv.includes("--root-types")) {
73
+ const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
74
+ const BOOLEAN_ALIASES = Object.entries(ALIASES).filter(([flag]) => CAMEL_CASE_BOOLEAN_FLAGS.includes(flag)).flatMap(([, aliases]) => aliases.map((alias) => `-${alias}`));
75
+ const BOOLEAN_FLAG_NAMES = /* @__PURE__ */ new Set([
76
+ ...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),
77
+ ...BOOLEAN_ALIASES
78
+ ]);
79
+ function rejectInvalidBooleans(flags) {
80
+ for (const { name, value } of flags) {
81
+ const negated = name.startsWith(NEGATION_PREFIX) ? `${LONG_PREFIX}${name.slice(NEGATION_PREFIX.length)}` : void 0;
82
+ const isNegatedWithValue = negated !== void 0 && BOOLEAN_FLAG_NAMES.has(negated);
83
+ const isInvalid = BOOLEAN_FLAG_NAMES.has(name) && !BOOLEAN_VALUES.has(value ?? "true");
84
+ if (value !== void 0 && (isNegatedWithValue || isInvalid)) {
85
+ throw cliError(
86
+ "CLI_FLAG_INVALID",
87
+ `${name}=${value}: a boolean flag takes no value, or =true or =false.`
88
+ );
89
+ }
90
+ }
91
+ }
92
+ function ineffectiveFlagNotices(flags) {
93
+ if (flags.rootTypes === true) {
55
94
  return [];
56
95
  }
57
- return ROOT_TYPES_FLAGS.filter((flag) => argv.includes(flag)).map(
58
- (flag) => `${flag} has no effect without --root-types flag`
96
+ return ROOT_TYPES_FLAGS.filter((flag) => flags[flag] === true).map(
97
+ (flag) => `--${kebabCase(flag)} has no effect without --root-types flag`
59
98
  );
60
99
  }
61
100
  function generatorFlagsOf(parsed) {
@@ -93,7 +132,6 @@ const STRING_FLAGS = [
93
132
  "fix",
94
133
  ...["localRefRoot", "remoteRefHosts"].flatMap((flag) => [flag, kebabCase(flag)])
95
134
  ];
96
- const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
97
135
  const KNOWN_FLAGS = /* @__PURE__ */ new Set([
98
136
  ...BOOLEAN_FLAGS,
99
137
  ...STRING_FLAGS,
@@ -113,7 +151,9 @@ function writtenFlagName(key, argv) {
113
151
  return isNegated ? negated : `--${kebabCase(key)}`;
114
152
  }
115
153
  function parseCliArguments(argv) {
116
- rejectRemovedFlags(argv);
154
+ const flags = writtenFlags(argv);
155
+ rejectRemovedFlags(flags);
156
+ rejectInvalidBooleans(flags);
117
157
  const parsed = parser([...argv], {
118
158
  boolean: BOOLEAN_FLAGS,
119
159
  string: STRING_FLAGS,
@@ -121,8 +161,8 @@ function parseCliArguments(argv) {
121
161
  });
122
162
  return {
123
163
  input: optionalString(parsed._[0]),
124
- output: optionalString(parsed.output),
125
- redocly: optionalString(parsed.redocly),
164
+ output: lastString(parsed.output),
165
+ redocly: lastString(parsed.redocly),
126
166
  isCheck: parsed.check === true,
127
167
  isHelp: "help" in parsed,
128
168
  isVersion: "version" in parsed,
@@ -1 +1 @@
1
- {"version":3,"file":"cli-arguments.mjs","sources":["../../src/cli/cli-arguments.ts"],"sourcesContent":["import { kebabCase } from \"scule\";\nimport parser from \"yargs-parser\";\nimport type { OutputFixName } from \"../domain/output-fixes.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport { fixNamesOf } from \"./fix-option.js\";\n\n/** The CLI's arguments, parsed as the original CLI parsed them (yargs-parser). */\n\n/** Boolean flags that become generator options (camelCase; yargs also accepts kebab-case). */\nexport const GENERATOR_FLAGS = [\n \"additionalProperties\",\n \"alphabetize\",\n \"arrayLength\",\n \"binaryAsBlob\",\n \"conditionalEnums\",\n \"dedupeEnums\",\n \"defaultNonNullable\",\n \"emptyObjectsUnknown\",\n \"enum\",\n \"enumValues\",\n \"excludeDeprecated\",\n \"exportType\",\n \"generatePathParams\",\n \"immutable\",\n \"lint\",\n \"makePathsEnum\",\n \"pathParamsAsTypes\",\n \"propertiesRequiredByDefault\",\n \"readWriteMarkers\",\n \"rootTypes\",\n \"rootTypesKeepCasing\",\n \"rootTypesNoSchemaPrefix\",\n] as const;\n\nexport type GeneratorFlag = (typeof GENERATOR_FLAGS)[number];\n\nexport type GeneratorFlags = Readonly<Partial<Record<GeneratorFlag, boolean>>>;\n\n// `contentNever` was a boolean flag of the original CLI that no code reads; it stays in the list\n// so that `--content-never <input>` keeps parsing as a flag and an input.\nconst CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, \"check\", \"contentNever\", \"help\"];\n\n// yargs-parser matches the `boolean` list by the exact spelling of the flag: with camelCase names\n// only, `--root-types schema.yaml` took the path as the flag's value (upstream #2523). Both\n// spellings are listed.\nconst BOOLEAN_FLAGS = [\n ...CAMEL_CASE_BOOLEAN_FLAGS,\n ...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => kebabCase(flag)),\n];\n\n/** The `$ref` limits as the user wrote them; unset flags are absent. */\nexport interface CliRefLimits {\n readonly localRefRoot?: string;\n readonly remoteRefHosts?: readonly string[];\n}\n\nexport interface CliArguments {\n /** The schema path or URL; none means stdin, or the APIs of the Redocly config. */\n readonly input: string | undefined;\n readonly output: string | undefined;\n readonly redocly: string | undefined;\n readonly isCheck: boolean;\n readonly isHelp: boolean;\n readonly isVersion: boolean;\n readonly generatorFlags: GeneratorFlags;\n readonly refLimits: CliRefLimits;\n /** `--fix`, comma-separated and repeatable (ADR-021); unset when the flag is not given. */\n readonly fix: readonly OutputFixName[] | undefined;\n /** Flags the CLI does not know, as written on the command line (`--bogus`, `-x`). */\n readonly unknownFlags: readonly string[];\n}\n\n/** Flags of older versions that were removed or renamed, with the message for each. */\nconst REMOVED_FLAGS: readonly (readonly [string, string])[] = [\n [\"-ap\", `The -ap alias has been deprecated. Use \"--additional-properties\" instead.`],\n [\"--immutable-types\", `The --immutable-types flag has been renamed to \"--immutable\".`],\n [\n \"--support-array-length\",\n `The --support-array-length flag has been renamed to \"--array-length\".`,\n ],\n [\"-it\", `The -it alias has been deprecated. Use \"--immutable\" instead.`],\n [\"--redoc\", `The --redoc config flag has been renamed to \"--redocly\" (or -c as shorthand).`],\n];\n\n/** Flags that only work together with `--root-types`. */\nconst ROOT_TYPES_FLAGS = [\"--root-types-no-schema-prefix\", \"--root-types-keep-casing\"] as const;\n\nfunction rejectRemovedFlags(argv: readonly string[]): void {\n for (const [flag, message] of REMOVED_FLAGS) {\n if (argv.includes(flag)) {\n throw cliError(\"CLI_FLAG_REMOVED\", message);\n }\n }\n}\n\n/** Notices for flags that have no effect in this combination, printed before the run. */\nexport function ineffectiveFlagNotices(argv: readonly string[]): string[] {\n if (argv.includes(\"--root-types\")) {\n return [];\n }\n return ROOT_TYPES_FLAGS.filter((flag) => argv.includes(flag)).map(\n (flag) => `${flag} has no effect without --root-types flag`,\n );\n}\n\nfunction generatorFlagsOf(parsed: parser.Arguments): GeneratorFlags {\n const flags: Partial<Record<GeneratorFlag, boolean>> = {};\n for (const name of GENERATOR_FLAGS) {\n if (typeof parsed[name] === \"boolean\") {\n flags[name] = parsed[name];\n }\n }\n return flags;\n}\n\nfunction optionalString(value: unknown): string | undefined {\n return value === undefined ? undefined : String(value);\n}\n\n/** The last value of a flag that may be given more than once. */\nfunction lastString(value: unknown): string | undefined {\n return optionalString(Array.isArray(value) ? value.at(-1) : value);\n}\n\n/**\n * `--remote-ref-hosts a.example,b.example`, repeatable; an empty value allows no host. The\n * `remote-ref-hosts` setting of a `redocly.yaml` API is read the same way.\n */\nexport function hostList(value: unknown): string[] | undefined {\n if (value === undefined) {\n return undefined;\n }\n return [value]\n .flat()\n .flatMap((entry) => String(entry).split(\",\"))\n .map((host) => host.trim())\n .filter((host) => host !== \"\");\n}\n\nfunction refLimitsOf(parsed: parser.Arguments): CliRefLimits {\n const localRefRoot = lastString(parsed.localRefRoot);\n const remoteRefHosts = hostList(parsed.remoteRefHosts);\n return {\n ...(localRefRoot === undefined ? {} : { localRefRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteRefHosts }),\n };\n}\n\n/** String flags, in both spellings, so that a value such as `8080` is not read as a number. */\nconst STRING_FLAGS = [\n \"output\",\n \"redocly\",\n \"fix\",\n ...[\"localRefRoot\", \"remoteRefHosts\"].flatMap((flag) => [flag, kebabCase(flag)]),\n];\n\nconst ALIASES = { redocly: [\"c\"], exportType: [\"t\"], output: [\"o\"] };\n\n/** Every name yargs-parser can return for a flag this CLI reads. */\nconst KNOWN_FLAGS = new Set<string>([\n ...BOOLEAN_FLAGS,\n ...STRING_FLAGS,\n ...Object.values(ALIASES).flat(),\n \"version\",\n]);\n\n/**\n * Flags that no code reads. The original CLI ignored them silently, so a typo such as\n * `--alphabetise` gave other output with no hint; they still do not fail the run.\n */\nfunction unknownFlagsOf(parsed: parser.Arguments, argv: readonly string[]): string[] {\n const names = Object.keys(parsed)\n .filter((key) => key !== \"_\" && key !== \"--\" && !KNOWN_FLAGS.has(key))\n .map((key) => writtenFlagName(key, argv));\n return [...new Set(names)];\n}\n\n/** The flag as the user wrote it: yargs-parser reads `--no-x` as `x: false`. */\nfunction writtenFlagName(key: string, argv: readonly string[]): string {\n if (key.length === 1) {\n return `-${key}`;\n }\n const negated = `--no-${kebabCase(key)}`;\n const isNegated = argv.some((arg) => arg === negated || arg.startsWith(`${negated}=`));\n return isNegated ? negated : `--${kebabCase(key)}`;\n}\n\n/**\n * Parse the arguments after `node cli.js`. Fails with `CLI_FLAG_REMOVED` for an old flag and with\n * `OPTION_FIX_UNKNOWN` for an unknown `--fix` name.\n */\nexport function parseCliArguments(argv: readonly string[]): CliArguments {\n rejectRemovedFlags(argv);\n const parsed = parser([...argv], {\n boolean: BOOLEAN_FLAGS,\n string: STRING_FLAGS,\n alias: ALIASES,\n });\n return {\n input: optionalString(parsed._[0]),\n output: optionalString(parsed.output),\n redocly: optionalString(parsed.redocly),\n isCheck: parsed.check === true,\n isHelp: \"help\" in parsed,\n isVersion: \"version\" in parsed,\n generatorFlags: generatorFlagsOf(parsed),\n refLimits: refLimitsOf(parsed),\n fix: fixNamesOf(parsed.fix),\n unknownFlags: unknownFlagsOf(parsed, argv),\n };\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,eAAA,GAAkB;AAAA,EAC7B,sBAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,aAAA;AAAA,EACA,oBAAA;AAAA,EACA,qBAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,YAAA;AAAA,EACA,oBAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,mBAAA;AAAA,EACA,6BAAA;AAAA,EACA,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF;AAQA,MAAM,2BAA2B,CAAC,GAAG,eAAA,EAAiB,OAAA,EAAS,gBAAgB,MAAM,CAAA;AAKrF,MAAM,aAAA,GAAgB;AAAA,EACpB,GAAG,wBAAA;AAAA,EACH,GAAG,wBAAA,CAAyB,GAAA,CAAI,CAAC,IAAA,KAAS,S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;AAMO,SAAS,kBAAkB,IAAA,EAAuC;AACvE,EAAA,kBAAA,CAAmB,IAAI,CAAA;AACvB,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,CAAC,GAAG,IAAI,CAAA,EAAG;AAAA,IAC/B,OAAA,EAAS,aAAA;AAAA,IACT,MAAA,EAAQ,YAAA;AAAA,IACR,KAAA,EAAO;AAAA,GACR,CAAA;AACD,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,cAAA,CAAe,MAAA,CAAO,CAAA,CAAE,CAAC,CAAC,CAAA;AAAA,IACjC,MAAA,EAAQ,cAAA,CAAe,MAAA,CAAO,MAAM,CAAA;AAAA,IACpC,OAAA,EAAS,cAAA,CAAe,MAAA,CAAO,OAAO,CAAA;AAAA,IACtC,OAAA,EAAS,OAAO,KAAA,KAAU,IAAA;AAAA,IAC1B,QAAQ,MAAA,IAAU,MAAA;AAAA,IAClB,WAAW,SAAA,IAAa,MAAA;AAAA,IACxB,cAAA,EAAgB,iBAAiB,MAAM,CAAA;AAAA,IACvC,SAAA,EAAW,YAAY,MAAM,CAAA;AAAA,IAC7B,GAAA,EAAK,UAAA,CAAW,MAAA,CAAO,GAAG,CAAA;AAAA,IAC1B,YAAA,EAAc,cAAA,CAAe,MAAA,EAAQ,IAAI;AAAA,GAC3C;AACF;;"}
1
+ {"version":3,"file":"cli-arguments.mjs","sources":["../../src/cli/cli-arguments.ts"],"sourcesContent":["import { kebabCase } from \"scule\";\nimport parser from \"yargs-parser\";\nimport type { OutputFixName } from \"../domain/output-fixes.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport { fixNamesOf } from \"./fix-option.js\";\n\n/** The CLI's arguments, parsed as the original CLI parsed them (yargs-parser). */\n\n/** Boolean flags that become generator options (camelCase; yargs also accepts kebab-case). */\nexport const GENERATOR_FLAGS = [\n \"additionalProperties\",\n \"alphabetize\",\n \"arrayLength\",\n \"binaryAsBlob\",\n \"conditionalEnums\",\n \"dedupeEnums\",\n \"defaultNonNullable\",\n \"emptyObjectsUnknown\",\n \"enum\",\n \"enumValues\",\n \"excludeDeprecated\",\n \"exportType\",\n \"generatePathParams\",\n \"immutable\",\n \"lint\",\n \"makePathsEnum\",\n \"pathParamsAsTypes\",\n \"propertiesRequiredByDefault\",\n \"readWriteMarkers\",\n \"rootTypes\",\n \"rootTypesKeepCasing\",\n \"rootTypesNoSchemaPrefix\",\n] as const;\n\nexport type GeneratorFlag = (typeof GENERATOR_FLAGS)[number];\n\nexport type GeneratorFlags = Readonly<Partial<Record<GeneratorFlag, boolean>>>;\n\n// `contentNever` was a boolean flag of the original CLI that no code reads; it stays in the list\n// so that `--content-never <input>` keeps parsing as a flag and an input.\nconst CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, \"check\", \"contentNever\", \"help\"];\n\n// yargs-parser matches the `boolean` list by the exact spelling of the flag: with camelCase names\n// only, `--root-types schema.yaml` took the path as the flag's value (upstream #2523). Both\n// spellings are listed.\nconst BOOLEAN_FLAGS = [\n ...CAMEL_CASE_BOOLEAN_FLAGS,\n ...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => kebabCase(flag)),\n];\n\n/** The `$ref` limits as the user wrote them; unset flags are absent. */\nexport interface CliRefLimits {\n readonly localRefRoot?: string;\n readonly remoteRefHosts?: readonly string[];\n}\n\nexport interface CliArguments {\n /** The schema path or URL; none means stdin, or the APIs of the Redocly config. */\n readonly input: string | undefined;\n readonly output: string | undefined;\n readonly redocly: string | undefined;\n readonly isCheck: boolean;\n readonly isHelp: boolean;\n readonly isVersion: boolean;\n readonly generatorFlags: GeneratorFlags;\n readonly refLimits: CliRefLimits;\n /** `--fix`, comma-separated and repeatable (ADR-021); unset when the flag is not given. */\n readonly fix: readonly OutputFixName[] | undefined;\n /** Flags the CLI does not know, as written on the command line (`--bogus`, `-x`). */\n readonly unknownFlags: readonly string[];\n}\n\n/** Flags of older versions that were removed or renamed, with the message for each. */\nconst REMOVED_FLAGS: readonly (readonly [string, string])[] = [\n [\"-ap\", `The -ap alias has been deprecated. Use \"--additional-properties\" instead.`],\n [\"--immutable-types\", `The --immutable-types flag has been renamed to \"--immutable\".`],\n [\n \"--support-array-length\",\n `The --support-array-length flag has been renamed to \"--array-length\".`,\n ],\n [\"-it\", `The -it alias has been deprecated. Use \"--immutable\" instead.`],\n [\"--redoc\", `The --redoc config flag has been renamed to \"--redocly\" (or -c as shorthand).`],\n];\n\n/** Flags that only work together with `--root-types`. */\nconst ROOT_TYPES_FLAGS = [\"rootTypesNoSchemaPrefix\", \"rootTypesKeepCasing\"] as const;\n\nconst OPTIONS_END = \"--\";\nconst LONG_PREFIX = \"--\";\nconst NEGATION_PREFIX = \"--no-\";\nconst VALUE_SEPARATOR = \"=\";\nconst BOOLEAN_VALUES: ReadonlySet<string> = new Set([\"true\", \"false\"]);\n\n/** A flag as written before `--`: its name (`--redoc`, `-o`) and the text after `=`, if any. */\ninterface WrittenFlag {\n readonly name: string;\n readonly value: string | undefined;\n}\n\nfunction writtenFlags(argv: readonly string[]): WrittenFlag[] {\n const end = argv.indexOf(OPTIONS_END);\n return (end === -1 ? argv : argv.slice(0, end))\n .filter((arg) => arg.startsWith(\"-\") && arg !== \"-\")\n .map((arg) => {\n const at = arg.indexOf(VALUE_SEPARATOR);\n return at === -1\n ? { name: arg, value: undefined }\n : { name: arg.slice(0, at), value: arg.slice(at + 1) };\n });\n}\n\n/**\n * A long flag as yargs-parser reads it: in kebab-case and without `--no-`, so `--immutableTypes`\n * and `--no-immutable-types` are `--immutable-types`. A short flag stays as written.\n */\nfunction canonicalFlagName(name: string): string {\n if (!name.startsWith(LONG_PREFIX)) {\n return name;\n }\n const bare = name.startsWith(NEGATION_PREFIX)\n ? name.slice(NEGATION_PREFIX.length)\n : name.slice(LONG_PREFIX.length);\n return `${LONG_PREFIX}${kebabCase(bare)}`;\n}\n\n/** An old flag fails by its name in any spelling, also with a value (`--redoc=redocly.yaml`). */\nfunction rejectRemovedFlags(flags: readonly WrittenFlag[]): void {\n const names = new Set(flags.map(({ name }) => canonicalFlagName(name)));\n for (const [flag, message] of REMOVED_FLAGS) {\n if (names.has(flag)) {\n throw cliError(\"CLI_FLAG_REMOVED\", message);\n }\n }\n}\n\nconst ALIASES = { redocly: [\"c\"], exportType: [\"t\"], output: [\"o\"] };\n\n/** The short aliases of boolean flags (`-t`), which take a value the same way (`-t=true`). */\nconst BOOLEAN_ALIASES = Object.entries(ALIASES)\n .filter(([flag]) => CAMEL_CASE_BOOLEAN_FLAGS.includes(flag))\n .flatMap(([, aliases]) => aliases.map((alias) => `-${alias}`));\n\nconst BOOLEAN_FLAG_NAMES: ReadonlySet<string> = new Set([\n ...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),\n ...BOOLEAN_ALIASES,\n]);\n\n/**\n * A boolean flag takes `=true` or `=false`, and its `--no-` form takes no value. yargs-parser read\n * any other value as false (`--enum=1`, `--alphabetize=yes`), which turned the option off.\n */\nfunction rejectInvalidBooleans(flags: readonly WrittenFlag[]): void {\n for (const { name, value } of flags) {\n const negated = name.startsWith(NEGATION_PREFIX)\n ? `${LONG_PREFIX}${name.slice(NEGATION_PREFIX.length)}`\n : undefined;\n const isNegatedWithValue = negated !== undefined && BOOLEAN_FLAG_NAMES.has(negated);\n const isInvalid = BOOLEAN_FLAG_NAMES.has(name) && !BOOLEAN_VALUES.has(value ?? \"true\");\n if (value !== undefined && (isNegatedWithValue || isInvalid)) {\n throw cliError(\n \"CLI_FLAG_INVALID\",\n `${name}=${value}: a boolean flag takes no value, or =true or =false.`,\n );\n }\n }\n}\n\n/** Notices for flags that have no effect in this combination, printed before the run. */\nexport function ineffectiveFlagNotices(flags: GeneratorFlags): string[] {\n if (flags.rootTypes === true) {\n return [];\n }\n return ROOT_TYPES_FLAGS.filter((flag) => flags[flag] === true).map(\n (flag) => `--${kebabCase(flag)} has no effect without --root-types flag`,\n );\n}\n\nfunction generatorFlagsOf(parsed: parser.Arguments): GeneratorFlags {\n const flags: Partial<Record<GeneratorFlag, boolean>> = {};\n for (const name of GENERATOR_FLAGS) {\n if (typeof parsed[name] === \"boolean\") {\n flags[name] = parsed[name];\n }\n }\n return flags;\n}\n\nfunction optionalString(value: unknown): string | undefined {\n return value === undefined ? undefined : String(value);\n}\n\n/**\n * The last value of a flag that takes one value: given twice, the last one wins, as for the\n * boolean flags (yargs-parser gives a list of every value).\n */\nfunction lastString(value: unknown): string | undefined {\n return optionalString(Array.isArray(value) ? value.at(-1) : value);\n}\n\n/**\n * `--remote-ref-hosts a.example,b.example`, repeatable; an empty value allows no host. The\n * `remote-ref-hosts` setting of a `redocly.yaml` API is read the same way.\n */\nexport function hostList(value: unknown): string[] | undefined {\n if (value === undefined) {\n return undefined;\n }\n return [value]\n .flat()\n .flatMap((entry) => String(entry).split(\",\"))\n .map((host) => host.trim())\n .filter((host) => host !== \"\");\n}\n\nfunction refLimitsOf(parsed: parser.Arguments): CliRefLimits {\n const localRefRoot = lastString(parsed.localRefRoot);\n const remoteRefHosts = hostList(parsed.remoteRefHosts);\n return {\n ...(localRefRoot === undefined ? {} : { localRefRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteRefHosts }),\n };\n}\n\n/** String flags, in both spellings, so that a value such as `8080` is not read as a number. */\nconst STRING_FLAGS = [\n \"output\",\n \"redocly\",\n \"fix\",\n ...[\"localRefRoot\", \"remoteRefHosts\"].flatMap((flag) => [flag, kebabCase(flag)]),\n];\n\n/** Every name yargs-parser can return for a flag this CLI reads. */\nconst KNOWN_FLAGS = new Set<string>([\n ...BOOLEAN_FLAGS,\n ...STRING_FLAGS,\n ...Object.values(ALIASES).flat(),\n \"version\",\n]);\n\n/**\n * Flags that no code reads. The original CLI ignored them silently, so a typo such as\n * `--alphabetise` gave other output with no hint; they still do not fail the run.\n */\nfunction unknownFlagsOf(parsed: parser.Arguments, argv: readonly string[]): string[] {\n const names = Object.keys(parsed)\n .filter((key) => key !== \"_\" && key !== \"--\" && !KNOWN_FLAGS.has(key))\n .map((key) => writtenFlagName(key, argv));\n return [...new Set(names)];\n}\n\n/** The flag as the user wrote it: yargs-parser reads `--no-x` as `x: false`. */\nfunction writtenFlagName(key: string, argv: readonly string[]): string {\n if (key.length === 1) {\n return `-${key}`;\n }\n const negated = `--no-${kebabCase(key)}`;\n const isNegated = argv.some((arg) => arg === negated || arg.startsWith(`${negated}=`));\n return isNegated ? negated : `--${kebabCase(key)}`;\n}\n\n/**\n * Parse the arguments after `node cli.js`. Fails with `CLI_FLAG_REMOVED` for an old flag, with\n * `CLI_FLAG_INVALID` for a boolean flag with another value than true or false, and with\n * `OPTION_FIX_UNKNOWN` for an unknown `--fix` name.\n */\nexport function parseCliArguments(argv: readonly string[]): CliArguments {\n const flags = writtenFlags(argv);\n rejectRemovedFlags(flags);\n rejectInvalidBooleans(flags);\n const parsed = parser([...argv], {\n boolean: BOOLEAN_FLAGS,\n string: STRING_FLAGS,\n alias: ALIASES,\n });\n return {\n input: optionalString(parsed._[0]),\n output: lastString(parsed.output),\n redocly: lastString(parsed.redocly),\n isCheck: parsed.check === true,\n isHelp: \"help\" in parsed,\n isVersion: \"version\" in parsed,\n generatorFlags: generatorFlagsOf(parsed),\n refLimits: refLimitsOf(parsed),\n fix: fixNamesOf(parsed.fix),\n unknownFlags: unknownFlagsOf(parsed, argv),\n };\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,eAAA,GAAkB;AAAA,EAC7B,sBAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,aAAA;AAAA,EACA,oBAAA;AAAA,EACA,qBAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,YAAA;AAAA,EACA,oBAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,mBAAA;AAAA,EACA,6BAAA;AAAA,EACA,kBAAA;AAAA,EACA,WAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF;AAQA,MAAM,2BA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
  }
35
35
  return `${error.message}. The YAML parser reads at most ${limit} nested levels: move nested schemas to \`components\` and reference them with \`$ref\``;
36
36
  }
37
+ function sourceInvalidMessage(error) {
38
+ const { received, text } = error.details;
39
+ if (received !== "stream" || typeof text !== "string") {
40
+ return error.message;
41
+ }
42
+ return `stdin held only the YAML string "${text}", not an OpenAPI document. To read a file, pass its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts`;
43
+ }
37
44
  const CLI_ERROR_REPORTS = {
38
45
  SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
39
- SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },
46
+ SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },
40
47
  SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },
41
48
  SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },
42
49
  SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },
@@ -50,19 +57,29 @@ const CLI_ERROR_REPORTS = {
50
57
  ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
51
58
  CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },
52
59
  OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },
60
+ OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },
53
61
  TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
54
62
  CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },
63
+ CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },
55
64
  CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },
56
65
  CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
57
66
  CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },
58
67
  CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
59
68
  CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
60
69
  CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
70
+ CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },
71
+ CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },
72
+ CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },
73
+ CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },
61
74
  OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },
62
75
  OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },
63
76
  OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT }
64
77
  };
65
78
  function describeCliFailure(error) {
79
+ if (error instanceof ApiFailure) {
80
+ const failure = describeCliFailure(error.cause);
81
+ return { ...failure, message: `API ${error.apiName}: ${failure.message}` };
82
+ }
66
83
  if (!errors.isOpenAPITypesafeError(error)) {
67
84
  const text = error instanceof Error ? error.stack ?? error.message : String(error);
68
85
  return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };
@@ -71,10 +88,21 @@ function describeCliFailure(error) {
71
88
  const message = report.message?.(error) ?? error.message;
72
89
  return { exitCode: report.exitCode, message: `${message} (${error.code})` };
73
90
  }
91
+ class ApiFailure extends Error {
92
+ name = "ApiFailure";
93
+ cause;
94
+ apiName;
95
+ constructor(apiName, cause) {
96
+ super(`API ${apiName} failed`, { cause });
97
+ this.apiName = apiName;
98
+ this.cause = cause;
99
+ }
100
+ }
74
101
  function cliError(code, message, cause) {
75
102
  return new errors.OpenAPITypesafeError({ code: errors.ERROR_CODES[code], message, cause });
76
103
  }
77
104
 
105
+ exports.ApiFailure = ApiFailure;
78
106
  exports.EXIT_CODES = EXIT_CODES;
79
107
  exports.cliError = cliError;
80
108
  exports.describeCliFailure = describeCliFailure;
@@ -1 +1 @@
1
- {"version":3,"file":"cli-errors.cjs","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\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },\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 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":["isOpenAPITypesafeError","OpenAPITypesafeError","ERROR_CODES"],"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,MAA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ACtB,EAAA,OAAO,IAAIC,4BAAqB,EAAE,IAAA,EAAMC,mBAAY,IAAI,CAAA,EAAG,OAAA,EAAS,KAAA,EAAO,CAAA;AAC7E;;;;"}
1
+ {"version":3,"file":"cli-errors.cjs","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 OpenAPITypesafeError({ code: ERROR_CODES[code], message, cause });\n}\n"],"names":["isOpenAPITypesafeError","OpenAPITypesafeError","ERROR_CODES"],"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,qBAAqB,KAAA,EAAqC;AACjE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,GAA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Message(error) {
32
32
  }
33
33
  return `${error.message}. The YAML parser reads at most ${limit} nested levels: move nested schemas to \`components\` and reference them with \`$ref\``;
34
34
  }
35
+ function sourceInvalidMessage(error) {
36
+ const { received, text } = error.details;
37
+ if (received !== "stream" || typeof text !== "string") {
38
+ return error.message;
39
+ }
40
+ return `stdin held only the YAML string "${text}", not an OpenAPI document. To read a file, pass its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts`;
41
+ }
35
42
  const CLI_ERROR_REPORTS = {
36
43
  SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
37
- SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },
44
+ SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },
38
45
  SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },
39
46
  SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },
40
47
  SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },
@@ -48,19 +55,29 @@ const CLI_ERROR_REPORTS = {
48
55
  ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
49
56
  CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },
50
57
  OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },
58
+ OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },
51
59
  TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
52
60
  CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },
61
+ CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },
53
62
  CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },
54
63
  CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
55
64
  CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },
56
65
  CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
57
66
  CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
58
67
  CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
68
+ CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },
69
+ CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },
70
+ CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },
71
+ CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },
59
72
  OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },
60
73
  OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },
61
74
  OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT }
62
75
  };
63
76
  function describeCliFailure(error) {
77
+ if (error instanceof ApiFailure) {
78
+ const failure = describeCliFailure(error.cause);
79
+ return { ...failure, message: `API ${error.apiName}: ${failure.message}` };
80
+ }
64
81
  if (!isOpenAPITypesafeError(error)) {
65
82
  const text = error instanceof Error ? error.stack ?? error.message : String(error);
66
83
  return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };
@@ -69,9 +86,19 @@ function describeCliFailure(error) {
69
86
  const message = report.message?.(error) ?? error.message;
70
87
  return { exitCode: report.exitCode, message: `${message} (${error.code})` };
71
88
  }
89
+ class ApiFailure extends Error {
90
+ name = "ApiFailure";
91
+ cause;
92
+ apiName;
93
+ constructor(apiName, cause) {
94
+ super(`API ${apiName} failed`, { cause });
95
+ this.apiName = apiName;
96
+ this.cause = cause;
97
+ }
98
+ }
72
99
  function cliError(code, message, cause) {
73
100
  return new OpenAPITypesafeError({ code: ERROR_CODES[code], message, cause });
74
101
  }
75
102
 
76
- export { EXIT_CODES, cliError, describeCliFailure };
103
+ export { ApiFailure, EXIT_CODES, cliError, describeCliFailure };
77
104
  //# sourceMappingURL=cli-errors.mjs.map
@@ -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\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },\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 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,EAA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,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 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,qBAAqB,KAAA,EAAqC;AACjE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,GAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,MAAA,GAAS,CAAA;AACtF,EAAA,OAAO,4BAA4B,KAAK,C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,EAC3E;AACA,EAAA,IAAI,CAAC,sBAAA,CAAuB,KAAK,CAAA,EAAG;AAClC,IAAA,MAAM,IAAA,GAAO,iBAAiB,KAAA,GAAS,KAAA,CAAM,SAAS,KAAA,CAAM,OAAA,GAAW,OAAO,KAAK,CAAA;AACnF,IAAA,OAAO,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;AAMO,MAAM,mBAAmB,KAAA,CAAM;AAAA,EAClB,IAAA,GAAO,YAAA;AAAA,EACP,KAAA;AAAA,EACT,OAAA;AAAA,EAET,WAAA,CAAY,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,23 +3,118 @@
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');
8
+ const urlSecrets = require('../domain/url-secrets.cjs');
6
9
  const cliErrors = require('./cli-errors.cjs');
7
10
 
8
11
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
12
 
10
13
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
11
14
 
12
- const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
13
15
  function resolveLocationUrl(location, base) {
14
- if (URL_SCHEME.test(location)) {
15
- return new URL(location);
16
+ if (locationText.hasUrlScheme(location)) {
17
+ const url = URL.parse(location, base.href);
18
+ if (url === null) {
19
+ const shown = urlSecrets.redactUnparsedUrl(location);
20
+ throw cliErrors.cliError("CLI_LOCATION_INVALID", `The location ${shown} is not a valid URL`);
21
+ }
22
+ return url;
16
23
  }
17
24
  const baseDirectory = node_url.fileURLToPath(new URL(".", base));
18
25
  return node_url.pathToFileURL(path__default.resolve(baseDirectory, location));
19
26
  }
27
+ const FILE_PROTOCOL = "file:";
28
+ const DIRECTORY_SEGMENTS = /* @__PURE__ */ new Set([".", ".."]);
29
+ function namesDirectory(location, file) {
30
+ const lastSegment = location.split(path__default.sep).flatMap((part) => part.split("/")).at(-1);
31
+ return lastSegment === "" || DIRECTORY_SEGMENTS.has(lastSegment ?? "") || file.pathname.endsWith("/");
32
+ }
33
+ function invalidOutput(output, reason) {
34
+ return cliErrors.cliError("CLI_OUTPUT_INVALID", `The output ${output} ${reason}`);
35
+ }
36
+ function outputUrlOf(run, output, base) {
37
+ const file = parseLocationUrl(output, base);
38
+ if (file?.protocol !== FILE_PROTOCOL) {
39
+ throw invalidOutput(
40
+ output,
41
+ "is not a local file. Write the types to a file path or a file: URL."
42
+ );
43
+ }
44
+ if (!isLocalFile(file)) {
45
+ throw invalidOutput(output, "names no file on this computer. Use a file path instead.");
46
+ }
47
+ if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {
48
+ throw invalidOutput(output, "is a directory. Name the file to write the types to in it.");
49
+ }
50
+ return file;
51
+ }
52
+ function isLocalFile(file) {
53
+ try {
54
+ node_url.fileURLToPath(file);
55
+ return true;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+ function outputFileOf(run, named, base) {
61
+ return { ...named, file: outputUrlOf(run, named.output, base) };
62
+ }
63
+ function filesAtOutput(run, output, files) {
64
+ return files.filter(
65
+ ({ location }) => location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file)
66
+ );
67
+ }
68
+ function displayPathOf(run, location) {
69
+ return path__default.relative(node_url.fileURLToPath(run.deps.cwd), node_url.fileURLToPath(location)) || ".";
70
+ }
71
+ function redoclyConfigFiles(run, redocly) {
72
+ if (!redocly.configFile) {
73
+ return [];
74
+ }
75
+ const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);
76
+ return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];
77
+ }
78
+ function filesReadBy(run, types, owner) {
79
+ return types.localFiles.map((location) => ({
80
+ name: `schema ${displayPathOf(run, location)} that ${owner} reads`,
81
+ location
82
+ }));
83
+ }
84
+ function ensureOutputIsNotSchema(run, output, schemas) {
85
+ const [schema] = filesAtOutput(run, output, schemas);
86
+ if (schema) {
87
+ throw cliErrors.cliError(
88
+ "CLI_OUTPUT_IS_INPUT",
89
+ `The output ${output.output} is the ${schema.name}: writing the types would overwrite it. Choose another output file.`
90
+ );
91
+ }
92
+ }
93
+ function ensureOutputIsOwn(run, output, otherOutputs) {
94
+ const clashes = filesAtOutput(run, output, otherOutputs);
95
+ if (clashes.length > 0) {
96
+ throw duplicateOutputError(
97
+ output,
98
+ clashes.map(({ name }) => name)
99
+ );
100
+ }
101
+ }
102
+ function duplicateOutputError(output, others) {
103
+ return cliErrors.cliError(
104
+ "CLI_OUTPUT_DUPLICATE",
105
+ `The output ${output.output} of API ${output.source} is also the output of ${others.join(", ")}: they would overwrite each other. Give each API its own output file.`
106
+ );
107
+ }
108
+ function parseLocationUrl(location, base) {
109
+ if (locationText.hasUrlScheme(location)) {
110
+ return URL.parse(location, base.href) ?? void 0;
111
+ }
112
+ return resolveLocationUrl(location, base);
113
+ }
20
114
  function printDone(run, output) {
21
115
  const { style, now } = run.deps;
22
- 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))}`);
23
118
  const duration = style.dim(`[${terminalLogger.formatDuration(now() - run.startedAt)}]`);
24
119
  run.deps.console.info(`\u{1F680} ${target} ${duration}`);
25
120
  }
@@ -36,7 +131,19 @@ function emitOutput(run, output, contents) {
36
131
  run.deps.files.writeText(output.file, contents);
37
132
  printDone(run, output);
38
133
  }
134
+ function writeOutput(run, output, types, readFiles) {
135
+ ensureOutputIsNotSchema(run, output, readFiles);
136
+ emitOutput(run, output, types.contents);
137
+ }
39
138
 
139
+ exports.duplicateOutputError = duplicateOutputError;
40
140
  exports.emitOutput = emitOutput;
141
+ exports.ensureOutputIsNotSchema = ensureOutputIsNotSchema;
142
+ exports.ensureOutputIsOwn = ensureOutputIsOwn;
143
+ exports.filesReadBy = filesReadBy;
144
+ exports.outputFileOf = outputFileOf;
145
+ exports.parseLocationUrl = parseLocationUrl;
146
+ exports.redoclyConfigFiles = redoclyConfigFiles;
41
147
  exports.resolveLocationUrl = resolveLocationUrl;
148
+ exports.writeOutput = writeOutput;
42
149
  //# sourceMappingURL=cli-output.cjs.map
@@ -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 { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies } 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/** A generated file: `source` names the schema and `output` is the path as the user wrote it. */\nexport interface OutputFile {\n readonly source: string;\n readonly output: string;\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 as it is, else a file path, absolute or relative to\n * the directory of `base` (a directory or file URL). A path is not parsed as a URL, so `#`, `?` and\n * `%` are part of the file name.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (URL_SCHEME.test(location)) {\n return new URL(location);\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\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"],"names":["fileURLToPath","pathToFileURL","path","formatDuration","cliError"],"mappings":";;;;;;;;;;;AA2BA,MAAM,UAAA,GAAa,qBAAA;AAOZ,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,UAAA,CAAW,IA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CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;;;"}
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","formatDuration"],"mappings":";;;;;;;;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAIA,yBAAA,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,GAAQC,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,CAAA,CACjC,GAAG,EAAE,CAAA;AACR,EAAA,OACE,WAAA,KAAgB,EAAA,IAAM,kBAAA,CAAmB,GAAA,CAAI,W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