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
@@ -1 +1 @@
1
- {"version":3,"file":"schema-source.cjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\nconst URL_PREFIXES = [\"http://\", \"https://\", \"file://\"] as const;\n\n/** A string is a URL, JSON (starts with `{`) or YAML. */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIXES.some((prefix) => schema.startsWith(prefix))) {\n const url = new URL(schema);\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef);\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\nfunction parseYamlText(text: string, absoluteRef: string): Document {\n let document: Document;\n try {\n document = makeDocumentFromString(text, absoluteRef);\n } catch (cause) {\n throw parseFailedError(\"yaml\", absoluteRef, cause);\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n return parseSchema(await readStream(schema, options.absoluteRef), options);\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text","loadFailedError","fileURLToPath","Source","parseJson","parseFailedError","makeDocumentFromString","pathStringError","aliasExpansionFailure","YamlParseError","ResolveError","sourceInvalidError","sourceEmptyError","Readable"],"mappings":";;;;;;;;;;;;;;AAgCA,eAAe,UA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AAC5B,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,QAAA,CAAS,MAAM,GAAG,OAAO,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AACtD;;"}
1
+ {"version":3,"file":"schema-source.cjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n parseYaml,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n type TextOrigin,\n urlInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n /** Where document text came from, for the message of text that is only a string. */\n textOrigin?: TextOrigin;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\n/** A URL source string; a scheme is the same in any case (RFC 3986, section 3.1). */\nconst URL_PREFIX_RE = /^(?:https?|file):\\/\\//i;\n\n/**\n * A string is a URL, JSON (starts with `{`) or YAML. A string that starts like a URL but does not\n * parse as one fails with `SCHEMA_SOURCE_INVALID`, not the parser's `TypeError`.\n */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIX_RE.test(schema)) {\n const url = URL.parse(schema);\n if (url === null) {\n throw urlInvalidError(schema);\n }\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? \"string\");\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\n/**\n * How a parser message names document text that is no file. The document itself is named as a\n * file in the working directory, so that its relative `$ref`s resolve there, but no such file\n * exists, and a message that named it sent the user looking for it.\n */\nconst TEXT_ORIGIN_NAMES: Readonly<Record<TextOrigin, string>> = {\n string: \"the schema string\",\n stream: \"the schema stream\",\n};\n\nfunction parseYamlText(text: string, absoluteRef: string, origin: TextOrigin): Document {\n const source = new Source(absoluteRef, text);\n let document: Document;\n try {\n document = { source, parsed: parseYaml(text, { filename: TEXT_ORIGIN_NAMES[origin] }) };\n } catch (cause) {\n // As Redocly's own parse: the error keeps the first line, not the parser's code excerpt.\n throw parseFailedError(\"yaml\", absoluteRef, new YamlParseError(cause as Error, source));\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text, origin);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n const text = await readStream(schema, options.absoluteRef);\n return parseSchema(text, { ...options, textOrigin: \"stream\" });\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text","loadFailedError","urlInvalidError","fileURLToPath","Source","parseJson","parseFailedError","parseYaml","YamlParseError","pathStringError","aliasExpansionFailure","ResolveError","sourceInvalidError","sourceEmptyError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M,CAAA;AACjC;AAGA,eAAsB,WAAA,CAAY,QAAiB,OAAA,EAAgD;AACjG,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAMC,kCAAiB,+BAA0B,CAAA;AAAA,EACnD;AACA,EAAA,IAAI,kBAAkB,GAAA,EAAK;AACzB,IAAA,OAAO,iBAAiB,OAAO,CAAA;AAAA,EACjC;AACA,EAAA,IAAI,kBAAkBC,oBAAA,EAAU;AAC9B,IAAA,MAAMd,KAAAA,GAAO,MAAM,UAAA,CAAW,MAAA,EAAQ,QAAQ,WAAW,CAAA;AACzD,IAAA,OAAO,YAAYA,KAAAA,EAAM,EAAE,GAAG,OAAA,EAAS,UAAA,EAAY,UAAU,CAAA;AAAA,EAC/D;AACA,EAAA,IAAI,kBAAkB,MAAA,EAAQ;AAC5B,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,QAAA,CAAS,MAAM,GAAG,OAAO,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AACtD;;"}
@@ -1,10 +1,10 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { text } from 'node:stream/consumers';
3
3
  import { fileURLToPath } from 'node:url';
4
- import { YamlParseError, Source, ResolveError, makeDocumentFromString } from '@redocly/openapi-core';
4
+ import { YamlParseError, Source, ResolveError, parseYaml } from '@redocly/openapi-core';
5
5
  import parseJson from 'parse-json';
6
6
  import { aliasExpansionFailure } from './alias-limit.mjs';
7
- import { sourceEmptyError, loadFailedError, sourceInvalidError, parseFailedError, pathStringError } from './schema-load-errors.mjs';
7
+ import { sourceEmptyError, loadFailedError, urlInvalidError, sourceInvalidError, parseFailedError, pathStringError } from './schema-load-errors.mjs';
8
8
 
9
9
  async function readStream(stream, absoluteRef) {
10
10
  try {
@@ -13,14 +13,17 @@ async function readStream(stream, absoluteRef) {
13
13
  throw loadFailedError(absoluteRef, error);
14
14
  }
15
15
  }
16
- const URL_PREFIXES = ["http://", "https://", "file://"];
16
+ const URL_PREFIX_RE = /^(?:https?|file):\/\//i;
17
17
  function parseSchemaText(schema, options) {
18
- if (URL_PREFIXES.some((prefix) => schema.startsWith(prefix))) {
19
- const url = new URL(schema);
18
+ if (URL_PREFIX_RE.test(schema)) {
19
+ const url = URL.parse(schema);
20
+ if (url === null) {
21
+ throw urlInvalidError(schema);
22
+ }
20
23
  const absoluteRef = url.protocol === "file:" ? fileURLToPath(url) : url.href;
21
24
  return parseSchema(url, { absoluteRef, resolver: options.resolver });
22
25
  }
23
- return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef);
26
+ return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? "string");
24
27
  }
25
28
  function parseJsonText(text2, absoluteRef) {
26
29
  try {
@@ -29,15 +32,20 @@ function parseJsonText(text2, absoluteRef) {
29
32
  throw parseFailedError("json", absoluteRef, cause);
30
33
  }
31
34
  }
32
- function parseYamlText(text2, absoluteRef) {
35
+ const TEXT_ORIGIN_NAMES = {
36
+ string: "the schema string",
37
+ stream: "the schema stream"
38
+ };
39
+ function parseYamlText(text2, absoluteRef, origin) {
40
+ const source = new Source(absoluteRef, text2);
33
41
  let document;
34
42
  try {
35
- document = makeDocumentFromString(text2, absoluteRef);
43
+ document = { source, parsed: parseYaml(text2, { filename: TEXT_ORIGIN_NAMES[origin] }) };
36
44
  } catch (cause) {
37
- throw parseFailedError("yaml", absoluteRef, cause);
45
+ throw parseFailedError("yaml", absoluteRef, new YamlParseError(cause, source));
38
46
  }
39
47
  if (typeof document.parsed === "string") {
40
- throw pathStringError(text2);
48
+ throw pathStringError(text2, origin);
41
49
  }
42
50
  const failure = aliasExpansionFailure(document.parsed);
43
51
  if (failure !== void 0) {
@@ -83,7 +91,8 @@ async function parseSchema(schema, options) {
83
91
  return resolveSchemaURL(options);
84
92
  }
85
93
  if (schema instanceof Readable) {
86
- return parseSchema(await readStream(schema, options.absoluteRef), options);
94
+ const text2 = await readStream(schema, options.absoluteRef);
95
+ return parseSchema(text2, { ...options, textOrigin: "stream" });
87
96
  }
88
97
  if (schema instanceof Buffer) {
89
98
  return parseSchema(schema.toString("utf8"), options);
@@ -1 +1 @@
1
- {"version":3,"file":"schema-source.mjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\nconst URL_PREFIXES = [\"http://\", \"https://\", \"file://\"] as const;\n\n/** A string is a URL, JSON (starts with `{`) or YAML. */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIXES.some((prefix) => schema.startsWith(prefix))) {\n const url = new URL(schema);\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef);\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\nfunction parseYamlText(text: string, absoluteRef: string): Document {\n let document: Document;\n try {\n document = makeDocumentFromString(text, absoluteRef);\n } catch (cause) {\n throw parseFailedError(\"yaml\", absoluteRef, cause);\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n return parseSchema(await readStream(schema, options.absoluteRef), options);\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text"],"mappings":";;;;;;;;AAgCA,eAAe,UAAA,CAAW,QAAkB,WAAA,EAAsC;AAChF,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,MAAM,CAAA,EAAG,IAAA,EAAK;AAAA,EACnC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,eAAA,CAAgB,aAAa,KAAK,CAAA;AAAA,EAC1C;AACF;AAEA,MAAM,YAAA,GAAe,CAAC,SAAA,EAAW,UAAA,EAAY,SAAS,CAAA;AAGtD,SAAS,eAAA,CACP,QACA,OAAA,EAC8B;AAC9B,EAAA,IAAI,YAAA,CAAa,KAAK,CAAC,MAAA,KAAW,OAAO,UAAA,CAAW,MAAM,CAAC,CAAA,EAAG;AAC5D,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAC1B,IAAA,MAAM,cAAc,GAAA,CAAI,QAAA,KAAa,UAAU,aAAA,CAAc,GAAG,IAAI,GAAA,CAAI,IAAA;AACxE,IAAA,OAAO,YAAY,GAAA,EAAK,EAAE,aA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Q,IAAI,MAAA,CAAO,WAAA,EAAa,KAAK,SAAA,CAAU,MAAM,GAAG,kBAAkB,CAAA;AAAA,MAC1E,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACA,EAAA,MAAM,mBAAmB,MAAM,CAAA;AACjC;AAGA,eAAsB,WAAA,CAAY,QAAiB,OAAA,EAAgD;AACjG,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,iBAAiB,+BAA0B,CAAA;AAAA,EACnD;AACA,EAAA,IAAI,kBAAkB,GAAA,EAAK;AACzB,IAAA,OAAO,iBAAiB,OAAO,CAAA;AAAA,EACjC;AACA,EAAA,IAAI,kBAAkB,QAAA,EAAU;AAC9B,IAAA,OAAO,YAAY,MAAM,UAAA,CAAW,QAAQ,OAAA,CAAQ,WAAW,GAAG,OAAO,CAAA;AAAA,EAC3E;AACA,EAAA,IAAI,kBAAkB,MAAA,EAAQ;AAC5B,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,QAAA,CAAS,MAAM,GAAG,OAAO,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AACtD;;"}
1
+ {"version":3,"file":"schema-source.mjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n parseYaml,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n type TextOrigin,\n urlInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n /** Where document text came from, for the message of text that is only a string. */\n textOrigin?: TextOrigin;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\n/** A URL source string; a scheme is the same in any case (RFC 3986, section 3.1). */\nconst URL_PREFIX_RE = /^(?:https?|file):\\/\\//i;\n\n/**\n * A string is a URL, JSON (starts with `{`) or YAML. A string that starts like a URL but does not\n * parse as one fails with `SCHEMA_SOURCE_INVALID`, not the parser's `TypeError`.\n */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIX_RE.test(schema)) {\n const url = URL.parse(schema);\n if (url === null) {\n throw urlInvalidError(schema);\n }\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? \"string\");\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\n/**\n * How a parser message names document text that is no file. The document itself is named as a\n * file in the working directory, so that its relative `$ref`s resolve there, but no such file\n * exists, and a message that named it sent the user looking for it.\n */\nconst TEXT_ORIGIN_NAMES: Readonly<Record<TextOrigin, string>> = {\n string: \"the schema string\",\n stream: \"the schema stream\",\n};\n\nfunction parseYamlText(text: string, absoluteRef: string, origin: TextOrigin): Document {\n const source = new Source(absoluteRef, text);\n let document: Document;\n try {\n document = { source, parsed: parseYaml(text, { filename: TEXT_ORIGIN_NAMES[origin] }) };\n } catch (cause) {\n // As Redocly's own parse: the error keeps the first line, not the parser's code excerpt.\n throw parseFailedError(\"yaml\", absoluteRef, new YamlParseError(cause as Error, source));\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text, origin);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n const text = await readStream(schema, options.absoluteRef);\n return parseSchema(text, { ...options, textOrigin: \"stream\" });\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text"],"mappings":";;;;;;;;AAoCA,eAAe,UAAA,CAAW,QAAkB,WAAA,EAAsC;AAChF,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,MAAM,CAAA,EAAG,IAAA,EAAK;AAAA,EACnC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,eAAA,CAAgB,aAAa,KAAK,CAAA;AAAA,EAC1C;AACF;AAGA,MAAM,aAAA,GAAgB,wBAAA;AAMtB,SAAS,eAAA,CACP,QACA,OAAA,EAC8B;AAC9B,EAAA,IAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA,EAAG;AAC9B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,MAAM,CAAA;AAC5B,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,gBAAgB,MAAM,CAAA;AAAA,IAC9B;AACA,IAAA,MAAM,cAAc,GAAA,CAAI,QAAA,KAAa,UAAU,aAAA,CAAc,GAAG,IAAI,GAAA,CAAI,IAAA;AACxE,IAAA,OAAO,YAAY,GAAA,EAAK,EAAE,aAAa,QAAA,EAAU,OAAA,CAAQ,UAAU,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,MAAA,CAAO,CAAC,CA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../../domain/errors.cjs');
4
+ const jsonPointer = require('../../domain/openapi/json-pointer.cjs');
4
5
 
5
6
  const UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
6
7
  "hasOwnProperty",
@@ -22,9 +23,6 @@ function isUnsupportedEntry(key, value) {
22
23
  return key === CONSTRUCTOR_KEY && typeof value === "object" && typeof name === "string";
23
24
  }
24
25
  const KEYS_IN_MESSAGE = 5;
25
- function escapePointerSegment(segment) {
26
- return segment.replaceAll("~", "~0").replaceAll("/", "~1");
27
- }
28
26
  function unsupportedKeysOf(document) {
29
27
  const found = [];
30
28
  const visited = /* @__PURE__ */ new WeakSet();
@@ -35,10 +33,10 @@ function unsupportedKeysOf(document) {
35
33
  pending.push({ value, pointer });
36
34
  }
37
35
  };
38
- enqueue(document.parsed, "#");
36
+ enqueue(document.parsed, jsonPointer.ROOT_POINTER);
39
37
  for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
40
38
  for (const [key, child] of Object.entries(node.value)) {
41
- const pointer = `${node.pointer}/${escapePointerSegment(key)}`;
39
+ const pointer = jsonPointer.childPointer(node.pointer, key);
42
40
  if (isUnsupportedEntry(key, child)) {
43
41
  found.push({ key, pointer, source: document.source });
44
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unsupported-keys.cjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/** RFC 6901: `~` becomes `~0` and `/` becomes `~1`. */\nfunction escapePointerSegment(segment: string): string {\n return segment.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, \"#\");\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = `${node.pointer}/${escapePointerSegment(key)}`;\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES"],"mappings":";;;;AAWO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAC;AAOD,MAAM,eAAA,GAAkB,aAAA;AAExB,SAAS,kBAAA,CAAmB,KAAa,KAAA,EAAyB;AAChE,EAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAQ,KAAA,EAAiD,IAAA;AAC/D,EAAA,OAAO,QAAQ,eAAA,IAAmB,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,IAAA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AQ,OAAO,OAAO,CAAA;AAAA,IACxB;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAGO,SAAS,oBAAoB,SAAA,EAAwD;AAC1F,EAAA,OAAO,SAAA,CAAU,QAAQ,iBAAiB,CAAA;AAC5C;AAEA,SAAS,YAAY,KAAA,EAA+B;AAClD,EAAA,OAAO,CAAA,CAAA,EAAI,MAAM,GAAG,CAAA,KAAA,EAAQ,MAAM,OAAO,CAAA,IAAA,EAAO,MAAM,MAAM,CAAA,CAAA;AAC9D;AAGO,SAAS,oBAAA,CACd,MACA,KAAA,EACsB;AACtB,EAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAG,eAAe,CAAA,CAAE,IAAI,WAAW,CAAA;AAC7D,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,eAAA,GAAkB,QAAQ,IAAA,CAAK,MAAA,GAAS,eAAe,CAAA,KAAA,CAAA,GAAU,EAAA;AAC5F,EAAA,OAAO,IAAIA,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,sBAAA;AAAA,IAClB,SACE,CAAA,gGAAA,EACc,MAAA,CAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,IACxC,OAAA,EAAS,EAAE,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,MAAW,EAAE,GAAG,KAAA,EAAM,CAAE,CAAA,EAAE;AAAA,IACrD;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"unsupported-keys.cjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { childPointer, ROOT_POINTER } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, ROOT_POINTER);\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = childPointer(node.pointer, key);\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":["ROOT_POINTER","childPointer","OpenAPITypesafeError","ERROR_CODES"],"mappings":";;;;;AAYO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAC;AAOD,MAAM,eAAA,GAAkB,aAAA;AAExB,SAAS,kBAAA,CAAmB,KAAa,KAAA,EAAyB;AAChE,EAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MA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AAO,KAAA;AACT;AAGO,SAAS,oBAAoB,SAAA,EAAwD;AAC1F,EAAA,OAAO,SAAA,CAAU,QAAQ,iBAAiB,CAAA;AAC5C;AAEA,SAAS,YAAY,KAAA,EAA+B;AAClD,EAAA,OAAO,CAAA,CAAA,EAAI,MAAM,GAAG,CAAA,KAAA,EAAQ,MAAM,OAAO,CAAA,IAAA,EAAO,MAAM,MAAM,CAAA,CAAA;AAC9D;AAGO,SAAS,oBAAA,CACd,MACA,KAAA,EACsB;AACtB,EAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAG,eAAe,CAAA,CAAE,IAAI,WAAW,CAAA;AAC7D,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,eAAA,GAAkB,QAAQ,IAAA,CAAK,MAAA,GAAS,eAAe,CAAA,KAAA,CAAA,GAAU,EAAA;AAC5F,EAAA,OAAO,IAAIC,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,sBAAA;AAAA,IAClB,SACE,CAAA,gGAAA,EACc,MAAA,CAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,IACxC,OAAA,EAAS,EAAE,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,MAAW,EAAE,GAAG,KAAA,EAAM,CAAE,CAAA,EAAE;AAAA,IACrD;AAAA,GACD,CAAA;AACH;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { OpenAPITypesafeError, ERROR_CODES } from '../../domain/errors.mjs';
2
+ import { childPointer, ROOT_POINTER } from '../../domain/openapi/json-pointer.mjs';
2
3
 
3
4
  const UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
4
5
  "hasOwnProperty",
@@ -20,9 +21,6 @@ function isUnsupportedEntry(key, value) {
20
21
  return key === CONSTRUCTOR_KEY && typeof value === "object" && typeof name === "string";
21
22
  }
22
23
  const KEYS_IN_MESSAGE = 5;
23
- function escapePointerSegment(segment) {
24
- return segment.replaceAll("~", "~0").replaceAll("/", "~1");
25
- }
26
24
  function unsupportedKeysOf(document) {
27
25
  const found = [];
28
26
  const visited = /* @__PURE__ */ new WeakSet();
@@ -33,10 +31,10 @@ function unsupportedKeysOf(document) {
33
31
  pending.push({ value, pointer });
34
32
  }
35
33
  };
36
- enqueue(document.parsed, "#");
34
+ enqueue(document.parsed, ROOT_POINTER);
37
35
  for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
38
36
  for (const [key, child] of Object.entries(node.value)) {
39
- const pointer = `${node.pointer}/${escapePointerSegment(key)}`;
37
+ const pointer = childPointer(node.pointer, key);
40
38
  if (isUnsupportedEntry(key, child)) {
41
39
  found.push({ key, pointer, source: document.source });
42
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unsupported-keys.mjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/** RFC 6901: `~` becomes `~0` and `/` becomes `~1`. */\nfunction escapePointerSegment(segment: string): string {\n return segment.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, \"#\");\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = `${node.pointer}/${escapePointerSegment(key)}`;\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":[],"mappings":";;AAWO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAC;AAOD,MAAM,eAAA,GAAkB,aAAA;AAExB,SAAS,kBAAA,CAAmB,KAAa,KAAA,EAAyB;AAChE,EAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAQ,KAAA,EAAiD,IAAA;AAC/D,EAAA,OAAO,QAAQ,eAAA,IAAmB,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,IAAA,KAAS,QAAA;AACjF;AAGA,MAAM,eAAA,GAAkB,CAAA;AAqBxB,SAAS,qBAAqB,OAAA,EAAyB;AACrD,EAAA,OAAO,QAAQ,UAAA,CAAW,GAAA,EAAK,IAAI,CAAA,CAAE,UAAA,CAAW,KAAK,IAAI,CAAA;AAC3D;AAOA,SAAS,kBAAkB,QAAA,EAA4C;AACrE,EAAA,MAAM,QAA0B,EAAC;AACjC,EAAA,MAAM,OAAA,uBAAc,OAAA,EAAgB;AACpC,EAAA,MAAM,UAAyB,EAAC;AACh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AS,oBAAA,CACd,MACA,KAAA,EACsB;AACtB,EAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAG,eAAe,CAAA,CAAE,IAAI,WAAW,CAAA;AAC7D,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,eAAA,GAAkB,QAAQ,IAAA,CAAK,MAAA,GAAS,eAAe,CAAA,KAAA,CAAA,GAAU,EAAA;AAC5F,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,sBAAA;AAAA,IAClB,SACE,CAAA,gGAAA,EACc,MAAA,CAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,IACxC,OAAA,EAAS,EAAE,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,MAAW,EAAE,GAAG,KAAA,EAAM,CAAE,CAAA,EAAE;AAAA,IACrD;AAAA,GACD,CAAA;AACH;;"}
1
+ {"version":3,"file":"unsupported-keys.mjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { childPointer, ROOT_POINTER } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, ROOT_POINTER);\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = childPointer(node.pointer, key);\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAC;AAOD,MAAM,eAAA,GAAkB,aAAA;AAExB,SAAS,kBAAA,CAAmB,KAAa,KAAA,EAAyB;AAChE,EAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAQ,KAAA,EAAiD,IAAA;AAC/D,EAAA,OAAO,QAAQ,eAAA,IAAmB,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,IAAA,KAAS,QAAA;AACjF;AAGA,MAAM,eAAA,GAAkB,CAAA;AAyBxB,SAAS,kBAAkB,QAAA,EAA4C;AACrE,EAAA,MAAM,QAA0B,EAAC;AACjC,EAAA,MAAM,OAAA,uBAAc,OAAA,EAAgB;AACpC,EAAA,MAAM,UAAyB,EAAC;AAChC,EAAA,MAAM,OAAA,GAAU,CAAC,KAAA,EAAgB,OAAA,KAA0B;AACzD,IAAA,IAAI,OA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AW,CAAA;AAC7D,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,eAAA,GAAkB,QAAQ,IAAA,CAAK,MAAA,GAAS,eAAe,CAAA,KAAA,CAAA,GAAU,EAAA;AAC5F,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,sBAAA;AAAA,IAClB,SACE,CAAA,gGAAA,EACc,MAAA,CAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,IACxC,OAAA,EAAS,EAAE,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,MAAW,EAAE,GAAG,KAAA,EAAM,CAAE,CAAA,EAAE;AAAA,IACrD;AAAA,GACD,CAAA;AACH;;"}
@@ -1,12 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const colors = require('ansi-colors');
4
- const urlCredentials = require('../../domain/url-credentials.cjs');
4
+ const terminalText = require('../../domain/terminal-text.cjs');
5
+ const urlSecrets = require('../../domain/url-secrets.cjs');
5
6
 
6
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
8
 
8
9
  const colors__default = /*#__PURE__*/_interopDefaultCompat(colors);
9
10
 
11
+ function shownText(message) {
12
+ return terminalText.terminalSafeText(urlSecrets.redactUrlSecrets(message));
13
+ }
10
14
  const MILLISECONDS_PER_SECOND = 1e3;
11
15
  const MILLISECONDS_PER_MINUTE = 6e4;
12
16
  function formatDuration(milliseconds) {
@@ -47,16 +51,18 @@ class TerminalLogger {
47
51
  }
48
52
  const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? "info"}`);
49
53
  const time = durationMs === void 0 ? " " : this.#palette.green(` ${formatDuration(durationMs)} `);
50
- const text = urlCredentials.redactUrlCredentials(message);
54
+ const text = shownText(message);
51
55
  this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);
52
56
  }
53
57
  warn(message) {
54
58
  if (!this.#options.silent) {
55
- this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${urlCredentials.redactUrlCredentials(message)}`));
59
+ this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${shownText(message)}`));
56
60
  }
57
61
  }
58
62
  error(message) {
59
- this.#options.sink.error(this.#palette.red(` \u2718 ${urlCredentials.redactUrlCredentials(message)}`));
63
+ if (!this.#options.silent) {
64
+ this.#options.sink.error(this.#palette.red(` \u2718 ${shownText(message)}`));
65
+ }
60
66
  }
61
67
  }
62
68
  function createTerminalLogger(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-logger.cjs","sources":["../../../src/adapters/terminal-logger/terminal-logger.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport type { DebugGroup, Logger } from \"../../application/ports/logger.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The Logger port on a terminal, with the original output format: ` ⚠ ` warnings, ` ✘ `\n * errors, and `openapi-ts:<group>` debug lines filtered by `DEBUG` (ENGINEERING_PLAN 4.5). No\n * line shows the user info of a URL.\n */\n\n/** Where the lines go: `console` in production, a recording sink in tests. */\nexport interface TerminalSink {\n debug(line: string): void;\n warn(line: string): void;\n error(line: string): void;\n}\n\nexport interface TerminalLoggerOptions {\n /** Drop warnings (errors and debug lines are still written). */\n readonly silent: boolean;\n /** The value of `DEBUG`: `*`, `openapi-ts:*` or `openapi-ts:<group>` turn debug lines on. */\n readonly debugFilter: string | undefined;\n readonly useColors: boolean;\n readonly sink: TerminalSink;\n}\n\ntype Colors = ReturnType<typeof colors.create>;\n\nconst MILLISECONDS_PER_SECOND = 1000;\nconst MILLISECONDS_PER_MINUTE = 60_000;\n\n/** A duration as the original prints it: one decimal, in ms, s or m. */\nexport function formatDuration(milliseconds: number): string {\n if (milliseconds < MILLISECONDS_PER_SECOND) {\n return `${Math.round(10 * milliseconds) / 10}ms`;\n }\n if (milliseconds < MILLISECONDS_PER_MINUTE) {\n return `${Math.round(milliseconds / 100) / 10}s`;\n }\n return `${Math.round(milliseconds / 6000) / 10}m`;\n}\n\nfunction groupColor(palette: Colors, group: DebugGroup | undefined): (text: string) => string {\n const byGroup: Readonly<Partial<Record<DebugGroup, (text: string) => string>>> = {\n redoc: palette.cyanBright,\n lint: palette.yellowBright,\n bundle: palette.magentaBright,\n ts: palette.blueBright,\n };\n return (group && byGroup[group]) || palette.whiteBright;\n}\n\n/** Whether `DEBUG` asks for this group (the original check, case-insensitive for the group). */\nexport function isDebugEnabled(filter: string | undefined, group: DebugGroup | undefined): boolean {\n if (!filter) {\n return false;\n }\n return (\n !group ||\n filter === \"*\" ||\n filter === \"openapi-ts:*\" ||\n filter.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`\n );\n}\n\nclass TerminalLogger implements Logger {\n readonly #options: TerminalLoggerOptions;\n readonly #palette: Colors;\n\n constructor(options: TerminalLoggerOptions) {\n this.#options = options;\n this.#palette = colors.create();\n this.#palette.enabled = options.useColors;\n }\n\n debug(message: string, group?: DebugGroup, durationMs?: number): void {\n if (!isDebugEnabled(this.#options.debugFilter, group)) {\n return;\n }\n const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? \"info\"}`);\n // The original wrote no space without a duration (`openapi-ts:lintIgnored …`).\n const time =\n durationMs === undefined ? \" \" : this.#palette.green(` ${formatDuration(durationMs)} `);\n const text = redactUrlCredentials(message);\n this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);\n }\n\n warn(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.warn(this.#palette.yellow(` ⚠ ${redactUrlCredentials(message)}`));\n }\n }\n\n error(message: string): void {\n this.#options.sink.error(this.#palette.red(` ✘ ${redactUrlCredentials(message)}`));\n }\n}\n\n/** A Logger that writes to a terminal sink. */\nexport function createTerminalLogger(options: TerminalLoggerOptions): Logger {\n return new TerminalLogger(options);\n}\n"],"names":["colors","redactUrlCredentials"],"mappings":";;;;;;;;;AA4BA,MAAM,uBAAA,GAA0B,GAAA;AAChC,MAAM,uBAAA,GAA0B,GA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CAAA,CAAqB,OAAO,CAAC,CAAA,CAAE,CAAC,CAAA;AAAA,EACpF;AACF;AAGO,SAAS,qBAAqB,OAAA,EAAwC;AAC3E,EAAA,OAAO,IAAI,eAAe,OAAO,CAAA;AACnC;;;;"}
1
+ {"version":3,"file":"terminal-logger.cjs","sources":["../../../src/adapters/terminal-logger/terminal-logger.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport type { DebugGroup, Logger } from \"../../application/ports/logger.js\";\nimport { terminalSafeText } from \"../../domain/terminal-text.js\";\nimport { redactUrlSecrets } from \"../../domain/url-secrets.js\";\n\n/**\n * The Logger port on a terminal, with the original output format: ` ⚠ ` warnings, ` ✘ `\n * errors, and `openapi-ts:<group>` debug lines filtered by `DEBUG` (ENGINEERING_PLAN 4.5). No\n * line shows the secrets of a URL, and each message prints as one line: a message quotes the\n * document, whose control characters could forge CI commands (terminal-text.ts).\n */\n\nfunction shownText(message: string): string {\n return terminalSafeText(redactUrlSecrets(message));\n}\n\n/** Where the lines go: `console` in production, a recording sink in tests. */\nexport interface TerminalSink {\n debug(line: string): void;\n warn(line: string): void;\n error(line: string): void;\n}\n\nexport interface TerminalLoggerOptions {\n /**\n * Drop warnings and error lines; debug lines, which `DEBUG` asks for, are still written. The\n * error lines are the problems of a document that fails to load, which the thrown error lists.\n */\n readonly silent: boolean;\n /** The value of `DEBUG`: `*`, `openapi-ts:*` or `openapi-ts:<group>` turn debug lines on. */\n readonly debugFilter: string | undefined;\n readonly useColors: boolean;\n readonly sink: TerminalSink;\n}\n\ntype Colors = ReturnType<typeof colors.create>;\n\nconst MILLISECONDS_PER_SECOND = 1000;\nconst MILLISECONDS_PER_MINUTE = 60_000;\n\n/** A duration as the original prints it: one decimal, in ms, s or m. */\nexport function formatDuration(milliseconds: number): string {\n if (milliseconds < MILLISECONDS_PER_SECOND) {\n return `${Math.round(10 * milliseconds) / 10}ms`;\n }\n if (milliseconds < MILLISECONDS_PER_MINUTE) {\n return `${Math.round(milliseconds / 100) / 10}s`;\n }\n return `${Math.round(milliseconds / 6000) / 10}m`;\n}\n\nfunction groupColor(palette: Colors, group: DebugGroup | undefined): (text: string) => string {\n const byGroup: Readonly<Partial<Record<DebugGroup, (text: string) => string>>> = {\n redoc: palette.cyanBright,\n lint: palette.yellowBright,\n bundle: palette.magentaBright,\n ts: palette.blueBright,\n };\n return (group && byGroup[group]) || palette.whiteBright;\n}\n\n/** Whether `DEBUG` asks for this group (the original check, case-insensitive for the group). */\nexport function isDebugEnabled(filter: string | undefined, group: DebugGroup | undefined): boolean {\n if (!filter) {\n return false;\n }\n return (\n !group ||\n filter === \"*\" ||\n filter === \"openapi-ts:*\" ||\n filter.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`\n );\n}\n\nclass TerminalLogger implements Logger {\n readonly #options: TerminalLoggerOptions;\n readonly #palette: Colors;\n\n constructor(options: TerminalLoggerOptions) {\n this.#options = options;\n this.#palette = colors.create();\n this.#palette.enabled = options.useColors;\n }\n\n debug(message: string, group?: DebugGroup, durationMs?: number): void {\n if (!isDebugEnabled(this.#options.debugFilter, group)) {\n return;\n }\n const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? \"info\"}`);\n // The original wrote no space without a duration (`openapi-ts:lintIgnored …`).\n const time =\n durationMs === undefined ? \" \" : this.#palette.green(` ${formatDuration(durationMs)} `);\n const text = shownText(message);\n this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);\n }\n\n warn(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.warn(this.#palette.yellow(` ⚠ ${shownText(message)}`));\n }\n }\n\n error(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.error(this.#palette.red(` ✘ ${shownText(message)}`));\n }\n }\n}\n\n/** A Logger that writes to a terminal sink. */\nexport function createTerminalLogger(options: TerminalLoggerOptions): Logger {\n return new TerminalLogger(options);\n}\n"],"names":["terminalSafeText","redactUrlSecrets","colors"],"mappings":";;;;;;;;;;AAYA,SAAS,UAAU,OAAA,EAAyB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M,OAAA,EAAuB;AAC3B,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,MAAA,EAAQ;AACzB,MAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,CAAA,SAAA,EAAO,SAAA,CAAU,OAAO,CAAC,CAAA,CAAE,CAAC,CAAA;AAAA,IACzE;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,OAAA,EAAwC;AAC3E,EAAA,OAAO,IAAI,eAAe,OAAO,CAAA;AACnC;;;;"}
@@ -1,6 +1,10 @@
1
1
  import colors from 'ansi-colors';
2
- import { redactUrlCredentials } from '../../domain/url-credentials.mjs';
2
+ import { terminalSafeText } from '../../domain/terminal-text.mjs';
3
+ import { redactUrlSecrets } from '../../domain/url-secrets.mjs';
3
4
 
5
+ function shownText(message) {
6
+ return terminalSafeText(redactUrlSecrets(message));
7
+ }
4
8
  const MILLISECONDS_PER_SECOND = 1e3;
5
9
  const MILLISECONDS_PER_MINUTE = 6e4;
6
10
  function formatDuration(milliseconds) {
@@ -41,16 +45,18 @@ class TerminalLogger {
41
45
  }
42
46
  const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? "info"}`);
43
47
  const time = durationMs === void 0 ? " " : this.#palette.green(` ${formatDuration(durationMs)} `);
44
- const text = redactUrlCredentials(message);
48
+ const text = shownText(message);
45
49
  this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);
46
50
  }
47
51
  warn(message) {
48
52
  if (!this.#options.silent) {
49
- this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${redactUrlCredentials(message)}`));
53
+ this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${shownText(message)}`));
50
54
  }
51
55
  }
52
56
  error(message) {
53
- this.#options.sink.error(this.#palette.red(` \u2718 ${redactUrlCredentials(message)}`));
57
+ if (!this.#options.silent) {
58
+ this.#options.sink.error(this.#palette.red(` \u2718 ${shownText(message)}`));
59
+ }
54
60
  }
55
61
  }
56
62
  function createTerminalLogger(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-logger.mjs","sources":["../../../src/adapters/terminal-logger/terminal-logger.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport type { DebugGroup, Logger } from \"../../application/ports/logger.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The Logger port on a terminal, with the original output format: ` ⚠ ` warnings, ` ✘ `\n * errors, and `openapi-ts:<group>` debug lines filtered by `DEBUG` (ENGINEERING_PLAN 4.5). No\n * line shows the user info of a URL.\n */\n\n/** Where the lines go: `console` in production, a recording sink in tests. */\nexport interface TerminalSink {\n debug(line: string): void;\n warn(line: string): void;\n error(line: string): void;\n}\n\nexport interface TerminalLoggerOptions {\n /** Drop warnings (errors and debug lines are still written). */\n readonly silent: boolean;\n /** The value of `DEBUG`: `*`, `openapi-ts:*` or `openapi-ts:<group>` turn debug lines on. */\n readonly debugFilter: string | undefined;\n readonly useColors: boolean;\n readonly sink: TerminalSink;\n}\n\ntype Colors = ReturnType<typeof colors.create>;\n\nconst MILLISECONDS_PER_SECOND = 1000;\nconst MILLISECONDS_PER_MINUTE = 60_000;\n\n/** A duration as the original prints it: one decimal, in ms, s or m. */\nexport function formatDuration(milliseconds: number): string {\n if (milliseconds < MILLISECONDS_PER_SECOND) {\n return `${Math.round(10 * milliseconds) / 10}ms`;\n }\n if (milliseconds < MILLISECONDS_PER_MINUTE) {\n return `${Math.round(milliseconds / 100) / 10}s`;\n }\n return `${Math.round(milliseconds / 6000) / 10}m`;\n}\n\nfunction groupColor(palette: Colors, group: DebugGroup | undefined): (text: string) => string {\n const byGroup: Readonly<Partial<Record<DebugGroup, (text: string) => string>>> = {\n redoc: palette.cyanBright,\n lint: palette.yellowBright,\n bundle: palette.magentaBright,\n ts: palette.blueBright,\n };\n return (group && byGroup[group]) || palette.whiteBright;\n}\n\n/** Whether `DEBUG` asks for this group (the original check, case-insensitive for the group). */\nexport function isDebugEnabled(filter: string | undefined, group: DebugGroup | undefined): boolean {\n if (!filter) {\n return false;\n }\n return (\n !group ||\n filter === \"*\" ||\n filter === \"openapi-ts:*\" ||\n filter.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`\n );\n}\n\nclass TerminalLogger implements Logger {\n readonly #options: TerminalLoggerOptions;\n readonly #palette: Colors;\n\n constructor(options: TerminalLoggerOptions) {\n this.#options = options;\n this.#palette = colors.create();\n this.#palette.enabled = options.useColors;\n }\n\n debug(message: string, group?: DebugGroup, durationMs?: number): void {\n if (!isDebugEnabled(this.#options.debugFilter, group)) {\n return;\n }\n const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? \"info\"}`);\n // The original wrote no space without a duration (`openapi-ts:lintIgnored …`).\n const time =\n durationMs === undefined ? \" \" : this.#palette.green(` ${formatDuration(durationMs)} `);\n const text = redactUrlCredentials(message);\n this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);\n }\n\n warn(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.warn(this.#palette.yellow(` ⚠ ${redactUrlCredentials(message)}`));\n }\n }\n\n error(message: string): void {\n this.#options.sink.error(this.#palette.red(` ✘ ${redactUrlCredentials(message)}`));\n }\n}\n\n/** A Logger that writes to a terminal sink. */\nexport function createTerminalLogger(options: TerminalLoggerOptions): Logger {\n return new TerminalLogger(options);\n}\n"],"names":[],"mappings":";;;AA4BA,MAAM,uBAAA,GAA0B,GAAA;AAChC,MAAM,uBAAA,GAA0B,GAAA;AAGzB,SAAS,eAAe,YAAA,EAA8B;AAC3D,EAAA,IAAI,eAAe,uBAAA,EAAyB;AAC1C,IAAA,OAAO,GAAG,IAAA,CAAK,KAAA,CAAM,EAAA,GAAK,YAAY,IAAI,EAAE,CAAA,EAAA,CAAA;AAAA,EAC9C;AACA,EAAA,IAAI,eAAe,uBAAA,EAAyB;AAC1C,IAAA,OAAO,GAAG,IAAA,CAAK,KAAA,CAAM,YAAA,GAAe,GAAG,IAAI,EAAE,C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,EAAU,KAAK,CAAA,CAAE,CAAA,WAAA,EAAc,KAAA,IAAS,MAAM,CAAA,CAAE,CAAA;AAE7E,IAAA,MAAM,IAAA,GACJ,UAAA,KAAe,MAAA,GAAY,GAAA,GAAM,IAAA,CAAK,QAAA,CAAS,KAAA,CAAM,CAAA,CAAA,EAAI,cAAA,CAAe,UAAU,CAAC,CAAA,CAAA,CAAG,CAAA;AACxF,IAAA,MAAM,IAAA,GAAO,qBAAqB,OAAO,CAAA;AACzC,IAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,CAAA,EAAA,EAAK,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,IAAI,CAAC,CAAA,EAAG,IAAI,CAAA,EAAG,IAAI,CAAA,CAAE,CAAA;AAAA,EACxE;AAAA,EAEA,KAAK,OAAA,EAAuB;AAC1B,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,MAAA,EAAQ;AACzB,MAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,CAAA,SAAA,EAAO,oBAAA,CAAqB,OAAO,CAAC,CAAA,CAAE,CAAC,CAAA;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,MAAM,OAAA,EAAuB;AAC3B,IAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,CAAA,SAAA,EAAO,oBAAA,CAAqB,OAAO,CAAC,CAAA,CAAE,CAAC,CAAA;AAAA,EACpF;AACF;AAGO,SAAS,qBAAqB,OAAA,EAAwC;AAC3E,EAAA,OAAO,IAAI,eAAe,OAAO,CAAA;AACnC;;"}
1
+ {"version":3,"file":"terminal-logger.mjs","sources":["../../../src/adapters/terminal-logger/terminal-logger.ts"],"sourcesContent":["import colors from \"ansi-colors\";\nimport type { DebugGroup, Logger } from \"../../application/ports/logger.js\";\nimport { terminalSafeText } from \"../../domain/terminal-text.js\";\nimport { redactUrlSecrets } from \"../../domain/url-secrets.js\";\n\n/**\n * The Logger port on a terminal, with the original output format: ` ⚠ ` warnings, ` ✘ `\n * errors, and `openapi-ts:<group>` debug lines filtered by `DEBUG` (ENGINEERING_PLAN 4.5). No\n * line shows the secrets of a URL, and each message prints as one line: a message quotes the\n * document, whose control characters could forge CI commands (terminal-text.ts).\n */\n\nfunction shownText(message: string): string {\n return terminalSafeText(redactUrlSecrets(message));\n}\n\n/** Where the lines go: `console` in production, a recording sink in tests. */\nexport interface TerminalSink {\n debug(line: string): void;\n warn(line: string): void;\n error(line: string): void;\n}\n\nexport interface TerminalLoggerOptions {\n /**\n * Drop warnings and error lines; debug lines, which `DEBUG` asks for, are still written. The\n * error lines are the problems of a document that fails to load, which the thrown error lists.\n */\n readonly silent: boolean;\n /** The value of `DEBUG`: `*`, `openapi-ts:*` or `openapi-ts:<group>` turn debug lines on. */\n readonly debugFilter: string | undefined;\n readonly useColors: boolean;\n readonly sink: TerminalSink;\n}\n\ntype Colors = ReturnType<typeof colors.create>;\n\nconst MILLISECONDS_PER_SECOND = 1000;\nconst MILLISECONDS_PER_MINUTE = 60_000;\n\n/** A duration as the original prints it: one decimal, in ms, s or m. */\nexport function formatDuration(milliseconds: number): string {\n if (milliseconds < MILLISECONDS_PER_SECOND) {\n return `${Math.round(10 * milliseconds) / 10}ms`;\n }\n if (milliseconds < MILLISECONDS_PER_MINUTE) {\n return `${Math.round(milliseconds / 100) / 10}s`;\n }\n return `${Math.round(milliseconds / 6000) / 10}m`;\n}\n\nfunction groupColor(palette: Colors, group: DebugGroup | undefined): (text: string) => string {\n const byGroup: Readonly<Partial<Record<DebugGroup, (text: string) => string>>> = {\n redoc: palette.cyanBright,\n lint: palette.yellowBright,\n bundle: palette.magentaBright,\n ts: palette.blueBright,\n };\n return (group && byGroup[group]) || palette.whiteBright;\n}\n\n/** Whether `DEBUG` asks for this group (the original check, case-insensitive for the group). */\nexport function isDebugEnabled(filter: string | undefined, group: DebugGroup | undefined): boolean {\n if (!filter) {\n return false;\n }\n return (\n !group ||\n filter === \"*\" ||\n filter === \"openapi-ts:*\" ||\n filter.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`\n );\n}\n\nclass TerminalLogger implements Logger {\n readonly #options: TerminalLoggerOptions;\n readonly #palette: Colors;\n\n constructor(options: TerminalLoggerOptions) {\n this.#options = options;\n this.#palette = colors.create();\n this.#palette.enabled = options.useColors;\n }\n\n debug(message: string, group?: DebugGroup, durationMs?: number): void {\n if (!isDebugEnabled(this.#options.debugFilter, group)) {\n return;\n }\n const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? \"info\"}`);\n // The original wrote no space without a duration (`openapi-ts:lintIgnored …`).\n const time =\n durationMs === undefined ? \" \" : this.#palette.green(` ${formatDuration(durationMs)} `);\n const text = shownText(message);\n this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);\n }\n\n warn(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.warn(this.#palette.yellow(` ⚠ ${shownText(message)}`));\n }\n }\n\n error(message: string): void {\n if (!this.#options.silent) {\n this.#options.sink.error(this.#palette.red(` ✘ ${shownText(message)}`));\n }\n }\n}\n\n/** A Logger that writes to a terminal sink. */\nexport function createTerminalLogger(options: TerminalLoggerOptions): Logger {\n return new TerminalLogger(options);\n}\n"],"names":[],"mappings":";;;;AAYA,SAAS,UAAU,OAAA,EAAyB;AAC1C,EAAA,OAAO,gBAAA,CAAiB,gBAAA,CAAiB,OAAO,CAAC,CAAA;AACnD;AAuBA,MAAM,uBAAA,GAA0B,GAAA;AAChC,MAAM,uBAAA,GAA0B,GAAA;AAGzB,SAAS,eAAe,YAAA,EAA8B;AAC3D,EAAA,IAAI,eAAe,uBAAA,EAAyB;AAC1C,IAAA,OAAO,GAAG,IAAA,CAAK,KAAA,CAAM,EAAA,GAAK,YAAY,IAAI,EAAE,CAAA,EAAA,CAAA;AAAA,EAC9C;AACA,EAAA,IAAI,eAAe,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;;"}
@@ -14,21 +14,33 @@ function terminalSupportsColor() {
14
14
  const stdout = supportsColor__default.stdout;
15
15
  return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;
16
16
  }
17
+ const STDERR_SINK = {
18
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
19
+ debug: (line) => console.error(line),
20
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
21
+ warn: (line) => console.warn(line),
22
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
23
+ error: (line) => console.error(line)
24
+ };
17
25
  function defaultLogger(silent) {
18
26
  return terminalLogger.createTerminalLogger({
19
27
  silent,
20
28
  debugFilter: process.env.DEBUG,
21
29
  useColors: terminalSupportsColor(),
22
- sink: console
30
+ sink: STDERR_SINK
23
31
  });
24
32
  }
25
33
  function defaultDeprecationReporter() {
26
34
  return nodeDeprecations.createNodeDeprecationReporter();
27
35
  }
28
36
  const REMOTE_REF_TIMEOUT_MS = 6e4;
37
+ const MEBIBYTE = 1024 * 1024;
29
38
  const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
30
39
  maxDocuments: 1e4,
31
- maxParallelFetches: 16
40
+ maxParallelFetches: 16,
41
+ maxDocumentBytes: 128 * MEBIBYTE,
42
+ maxTotalBytes: 256 * MEBIBYTE,
43
+ maxNodes: 8e6
32
44
  };
33
45
  function processCwd() {
34
46
  return process.cwd();
@@ -1 +1 @@
1
- {"version":3,"file":"default-ports.cjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":["supportsColor","createTerminalLogger","createNodeDeprecationReporter","performance","createConfig"],"mappings":";;;;;;;;;;;;AAeO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAASA,sBAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAOC,mCAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAOC,8CAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAO9B,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB;AACtB;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAOC,4BAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAOC,wBAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;;;;;;;;"}
1
+ {"version":3,"file":"default-ports.cjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport {\n createTerminalLogger,\n type TerminalSink,\n} from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/**\n * Every line of the logger goes to stderr: the CLI writes the types to stdout, and `console.debug`\n * writes there too, so debug lines would end up inside the generated file.\n */\nconst STDERR_SINK: TerminalSink = {\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n debug: (line) => console.error(line),\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n warn: (line) => console.warn(line),\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n error: (line) => console.error(line),\n};\n\n/** The terminal logger with `DEBUG` from the environment, writing to stderr. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: STDERR_SINK,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\nconst MEBIBYTE = 1024 * 1024;\n\n/**\n * Bounds on the remote documents of one schema (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n *\n * The size limits count decoded bytes and parsed nodes (threat model T2, ADR-033 decision 6).\n * The largest document of the 1,820-entry compatibility corpus is Microsoft Graph beta: 71 MiB,\n * 2.65 million nodes (keys and values), 1.6 GB peak memory when loaded from a URL. A remote body\n * took about 7 bytes of memory per byte of text and 110 per node in our measurements, so 128 MiB\n * per document (1.8 times Graph beta), 256 MiB per schema (a split document may be twice as\n * large) and 8 million nodes per schema (3 times Graph beta) let crafted documents finish within\n * a heap of 2 GB; with the default heap of 4 GB they peak at about 1.2 to 2.3 GB.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n maxDocumentBytes: 128 * MEBIBYTE,\n maxTotalBytes: 256 * MEBIBYTE,\n maxNodes: 8_000_000,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":["supportsColor","createTerminalLogger","createNodeDeprecationReporter","performance","createConfig"],"mappings":";;;;;;;;;;;;AAkBO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAASA,sBAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAMA,MAAM,WAAA,GAA4B;AAAA;AAAA,EAEhC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA;AAAA,EAEnC,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA;AAAA,EAEjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI;AACrC,CAAA;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAOC,mCAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAOC,8CAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAErC,MAAM,WAAW,IAAA,GAAO,IAAA;AAejB,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB,EAAA;AAAA,EACpB,kBAAkB,GAAA,GAAM,QAAA;AAAA,EACxB,eAAe,GAAA,GAAM,QAAA;AAAA,EACrB,QAAA,EAAU;AACZ;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAOC,4BAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAOC,wBAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;;;;;;;;"}
@@ -8,21 +8,33 @@ function terminalSupportsColor() {
8
8
  const stdout = supportsColor.stdout;
9
9
  return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;
10
10
  }
11
+ const STDERR_SINK = {
12
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
13
+ debug: (line) => console.error(line),
14
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
15
+ warn: (line) => console.warn(line),
16
+ // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel
17
+ error: (line) => console.error(line)
18
+ };
11
19
  function defaultLogger(silent) {
12
20
  return createTerminalLogger({
13
21
  silent,
14
22
  debugFilter: process.env.DEBUG,
15
23
  useColors: terminalSupportsColor(),
16
- sink: console
24
+ sink: STDERR_SINK
17
25
  });
18
26
  }
19
27
  function defaultDeprecationReporter() {
20
28
  return createNodeDeprecationReporter();
21
29
  }
22
30
  const REMOTE_REF_TIMEOUT_MS = 6e4;
31
+ const MEBIBYTE = 1024 * 1024;
23
32
  const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
24
33
  maxDocuments: 1e4,
25
- maxParallelFetches: 16
34
+ maxParallelFetches: 16,
35
+ maxDocumentBytes: 128 * MEBIBYTE,
36
+ maxTotalBytes: 256 * MEBIBYTE,
37
+ maxNodes: 8e6
26
38
  };
27
39
  function processCwd() {
28
40
  return process.cwd();
@@ -1 +1 @@
1
- {"version":3,"file":"default-ports.mjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/** The terminal logger with `DEBUG` from the environment, writing to the console. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: console,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\n/**\n * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":[],"mappings":";;;;;;AAeO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAAS,aAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAO,oBAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAO,6BAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAO9B,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB;AACtB;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAO,YAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAO,YAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;"}
1
+ {"version":3,"file":"default-ports.mjs","sources":["../../src/api/default-ports.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport { createConfig, type Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport supportsColor from \"supports-color\";\nimport { createNodeDeprecationReporter } from \"../adapters/node-deprecations/node-deprecations.js\";\nimport type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport {\n createTerminalLogger,\n type TerminalSink,\n} from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { DeprecationReporter } from \"../application/ports/deprecation-reporter.js\";\nimport type { Logger } from \"../application/ports/logger.js\";\n\n/**\n * The default adapters of the Node API (ENGINEERING_PLAN 4.5): this module and the CLI's\n * composition root are where the process environment is read.\n */\n\n/** Colors when the terminal supports them, as the original decided. */\nexport function terminalSupportsColor(): boolean {\n const stdout = supportsColor.stdout;\n return Boolean(stdout) && stdout !== false && stdout.hasBasic !== false;\n}\n\n/**\n * Every line of the logger goes to stderr: the CLI writes the types to stdout, and `console.debug`\n * writes there too, so debug lines would end up inside the generated file.\n */\nconst STDERR_SINK: TerminalSink = {\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n debug: (line) => console.error(line),\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n warn: (line) => console.warn(line),\n // biome-ignore lint/suspicious/noConsole: the terminal logger's own channel\n error: (line) => console.error(line),\n};\n\n/** The terminal logger with `DEBUG` from the environment, writing to stderr. */\nexport function defaultLogger(silent: boolean): Logger {\n return createTerminalLogger({\n silent,\n debugFilter: process.env.DEBUG,\n useColors: terminalSupportsColor(),\n sink: STDERR_SINK,\n });\n}\n\n/** Deprecations as Node.js `DeprecationWarning`s, each code once per process. */\nexport function defaultDeprecationReporter(): DeprecationReporter {\n return createNodeDeprecationReporter();\n}\n\n/**\n * How long one remote `$ref` (or a remote source) may take to load. Large documents (the 27 MB\n * Cloudflare spec) download in seconds; a minute covers slow hosts, while Node's own fetch would\n * wait five minutes for a server that never answers (ENGINEERING_PLAN 8.5).\n */\nexport const REMOTE_REF_TIMEOUT_MS = 60_000;\n\nconst MEBIBYTE = 1024 * 1024;\n\n/**\n * Bounds on the remote documents of one schema (ADR-033). Large split documents have a few thousand\n * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a\n * multi-file document fast without exhausting local ports.\n *\n * The size limits count decoded bytes and parsed nodes (threat model T2, ADR-033 decision 6).\n * The largest document of the 1,820-entry compatibility corpus is Microsoft Graph beta: 71 MiB,\n * 2.65 million nodes (keys and values), 1.6 GB peak memory when loaded from a URL. A remote body\n * took about 7 bytes of memory per byte of text and 110 per node in our measurements, so 128 MiB\n * per document (1.8 times Graph beta), 256 MiB per schema (a split document may be twice as\n * large) and 8 million nodes per schema (3 times Graph beta) let crafted documents finish within\n * a heap of 2 GB; with the default heap of 4 GB they peak at about 1.2 to 2.3 GB.\n */\nexport const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {\n maxDocuments: 10_000,\n maxParallelFetches: 16,\n maxDocumentBytes: 128 * MEBIBYTE,\n maxTotalBytes: 256 * MEBIBYTE,\n maxNodes: 8_000_000,\n};\n\n/** The working directory of the process: the default `cwd` of an inline source. */\nexport function processCwd(): string {\n return process.cwd();\n}\n\n/** A monotonic clock in milliseconds, for debug durations. */\nexport function monotonicNow(): number {\n return performance.now();\n}\n\n/** The default Redocly config: minimal rules, and duplicate operation IDs are an error. */\nexport function defaultRedoclyConfig(): Promise<RedoclyConfig> {\n const rules = { \"operation-operationId-unique\": { severity: \"error\" as const } };\n return createConfig({ rules }, { extends: [\"minimal\"] });\n}\n"],"names":[],"mappings":";;;;;;AAkBO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,MAAM,SAAS,aAAA,CAAc,MAAA;AAC7B,EAAA,OAAO,QAAQ,MAAM,CAAA,IAAK,MAAA,KAAW,KAAA,IAAS,OAAO,QAAA,KAAa,KAAA;AACpE;AAMA,MAAM,WAAA,GAA4B;AAAA;AAAA,EAEhC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA;AAAA,EAEnC,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA;AAAA,EAEjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI;AACrC,CAAA;AAGO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,OAAO,oBAAA,CAAqB;AAAA,IAC1B,MAAA;AAAA,IACA,WAAA,EAAa,QAAQ,GAAA,CAAI,KAAA;AAAA,IACzB,WAAW,qBAAA,EAAsB;AAAA,IACjC,IAAA,EAAM;AAAA,GACP,CAAA;AACH;AAGO,SAAS,0BAAA,GAAkD;AAChE,EAAA,OAAO,6BAAA,EAA8B;AACvC;AAOO,MAAM,qBAAA,GAAwB;AAErC,MAAM,WAAW,IAAA,GAAO,IAAA;AAejB,MAAM,8BAAA,GAAuD;AAAA,EAClE,YAAA,EAAc,GAAA;AAAA,EACd,kBAAA,EAAoB,EAAA;AAAA,EACpB,kBAAkB,GAAA,GAAM,QAAA;AAAA,EACxB,eAAe,GAAA,GAAM,QAAA;AAAA,EACrB,QAAA,EAAU;AACZ;AAGO,SAAS,UAAA,GAAqB;AACnC,EAAA,OAAO,QAAQ,GAAA,EAAI;AACrB;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAO,YAAY,GAAA,EAAI;AACzB;AAGO,SAAS,oBAAA,GAA+C;AAC7D,EAAA,MAAM,QAAQ,EAAE,8BAAA,EAAgC,EAAE,QAAA,EAAU,SAAiB,EAAE;AAC/E,EAAA,OAAO,YAAA,CAAa,EAAE,KAAA,EAAM,EAAG,EAAE,OAAA,EAAS,CAAC,SAAS,CAAA,EAAG,CAAA;AACzD;;"}
@@ -7,14 +7,14 @@ const ROOT_SEGMENTS = 3;
7
7
  function typedAt(ref) {
8
8
  const segments = jsonPointer.parseRefPointer(ref);
9
9
  const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
10
- return jsonPointer.createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
10
+ return jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, [...segments.slice(0, ROOT_SEGMENTS), ...nested]);
11
11
  }
12
12
  function isSchemaObject(value) {
13
13
  return typeof value === "object" && value !== null && !Array.isArray(value);
14
14
  }
15
15
  function ownProperty(item, ref, name) {
16
16
  const property = ("properties" in item ? item.properties : void 0)?.[name];
17
- return property === void 0 ? void 0 : { property, path: jsonPointer.createRef([ref, name]) };
17
+ return property === void 0 ? void 0 : { property, path: jsonPointer.appendPointer(ref, [name]) };
18
18
  }
19
19
  function declaredProperty(ref, name, resolve, visited) {
20
20
  const schema = resolve(ref);