openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.2

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 (513) hide show
  1. package/README.md +12 -5
  2. package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
  3. package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
  4. package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
  5. package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
  6. package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
  7. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  8. package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
  9. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  10. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +34 -11
  11. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +33 -10
  13. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
  15. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  16. package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
  17. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
  19. package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
  21. package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
  23. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
  25. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
  27. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
  29. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
  31. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
  33. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
  35. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
  37. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  38. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  39. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  40. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  41. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  42. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +5 -1
  43. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  44. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +5 -1
  45. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  46. package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
  47. package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
  48. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
  49. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
  50. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
  51. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
  52. package/dist/api/default-ports.cjs +9 -0
  53. package/dist/api/default-ports.cjs.map +1 -1
  54. package/dist/api/default-ports.mjs +8 -1
  55. package/dist/api/default-ports.mjs.map +1 -1
  56. package/dist/api/discriminator-conflict-warnings.cjs +25 -0
  57. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
  58. package/dist/api/discriminator-conflict-warnings.mjs +23 -0
  59. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
  60. package/dist/api/discriminator-enum-names.cjs +19 -0
  61. package/dist/api/discriminator-enum-names.cjs.map +1 -0
  62. package/dist/api/discriminator-enum-names.mjs +17 -0
  63. package/dist/api/discriminator-enum-names.mjs.map +1 -0
  64. package/dist/api/discriminator-enum-parent.cjs +59 -0
  65. package/dist/api/discriminator-enum-parent.cjs.map +1 -0
  66. package/dist/api/discriminator-enum-parent.mjs +57 -0
  67. package/dist/api/discriminator-enum-parent.mjs.map +1 -0
  68. package/dist/api/discriminator-enum.cjs +25 -0
  69. package/dist/api/discriminator-enum.cjs.map +1 -1
  70. package/dist/api/discriminator-enum.mjs +25 -1
  71. package/dist/api/discriminator-enum.mjs.map +1 -1
  72. package/dist/api/discriminator-other-owners.cjs +67 -0
  73. package/dist/api/discriminator-other-owners.cjs.map +1 -0
  74. package/dist/api/discriminator-other-owners.mjs +64 -0
  75. package/dist/api/discriminator-other-owners.mjs.map +1 -0
  76. package/dist/api/discriminator-patch.cjs +92 -0
  77. package/dist/api/discriminator-patch.cjs.map +1 -0
  78. package/dist/api/discriminator-patch.mjs +86 -0
  79. package/dist/api/discriminator-patch.mjs.map +1 -0
  80. package/dist/api/discriminator-scan.cjs +50 -65
  81. package/dist/api/discriminator-scan.cjs.map +1 -1
  82. package/dist/api/discriminator-scan.mjs +44 -59
  83. package/dist/api/discriminator-scan.mjs.map +1 -1
  84. package/dist/api/document-refs.cjs +15 -12
  85. package/dist/api/document-refs.cjs.map +1 -1
  86. package/dist/api/document-refs.mjs +15 -12
  87. package/dist/api/document-refs.mjs.map +1 -1
  88. package/dist/api/document-run.cjs +21 -4
  89. package/dist/api/document-run.cjs.map +1 -1
  90. package/dist/api/document-run.mjs +22 -5
  91. package/dist/api/document-run.mjs.map +1 -1
  92. package/dist/api/enum-values-warnings.cjs +16 -0
  93. package/dist/api/enum-values-warnings.cjs.map +1 -0
  94. package/dist/api/enum-values-warnings.mjs +14 -0
  95. package/dist/api/enum-values-warnings.mjs.map +1 -0
  96. package/dist/api/footer-sink.cjs +25 -2
  97. package/dist/api/footer-sink.cjs.map +1 -1
  98. package/dist/api/footer-sink.mjs +25 -2
  99. package/dist/api/footer-sink.mjs.map +1 -1
  100. package/dist/api/legacy-callback-warning.cjs +4 -1
  101. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  102. package/dist/api/legacy-callback-warning.mjs +4 -1
  103. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  104. package/dist/api/legacy-ts-helpers.cjs.map +1 -1
  105. package/dist/api/legacy-ts-helpers.mjs.map +1 -1
  106. package/dist/api/legacy-utils.cjs.map +1 -1
  107. package/dist/api/legacy-utils.mjs.map +1 -1
  108. package/dist/api/openapi-ts.cjs +2 -1
  109. package/dist/api/openapi-ts.cjs.map +1 -1
  110. package/dist/api/openapi-ts.mjs +3 -2
  111. package/dist/api/openapi-ts.mjs.map +1 -1
  112. package/dist/api/path-template-warnings.cjs +21 -0
  113. package/dist/api/path-template-warnings.cjs.map +1 -0
  114. package/dist/api/path-template-warnings.mjs +19 -0
  115. package/dist/api/path-template-warnings.mjs.map +1 -0
  116. package/dist/api/transform-context.cjs +4 -2
  117. package/dist/api/transform-context.cjs.map +1 -1
  118. package/dist/api/transform-context.mjs +4 -2
  119. package/dist/api/transform-context.mjs.map +1 -1
  120. package/dist/api/transform-schema.cjs +52 -3
  121. package/dist/api/transform-schema.cjs.map +1 -1
  122. package/dist/api/transform-schema.mjs +53 -4
  123. package/dist/api/transform-schema.mjs.map +1 -1
  124. package/dist/api/unsupported-feature-warnings.cjs +6 -1
  125. package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
  126. package/dist/api/unsupported-feature-warnings.mjs +6 -1
  127. package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
  128. package/dist/application/print/type-printer.cjs +7 -1
  129. package/dist/application/print/type-printer.cjs.map +1 -1
  130. package/dist/application/print/type-printer.mjs +7 -1
  131. package/dist/application/print/type-printer.mjs.map +1 -1
  132. package/dist/application/transform/document/assignability.cjs +144 -0
  133. package/dist/application/transform/document/assignability.cjs.map +1 -0
  134. package/dist/application/transform/document/assignability.mjs +138 -0
  135. package/dist/application/transform/document/assignability.mjs.map +1 -0
  136. package/dist/application/transform/document/components.cjs +2 -2
  137. package/dist/application/transform/document/components.cjs.map +1 -1
  138. package/dist/application/transform/document/components.mjs +4 -4
  139. package/dist/application/transform/document/components.mjs.map +1 -1
  140. package/dist/application/transform/document/declared-types.cjs +66 -0
  141. package/dist/application/transform/document/declared-types.cjs.map +1 -0
  142. package/dist/application/transform/document/declared-types.mjs +63 -0
  143. package/dist/application/transform/document/declared-types.mjs.map +1 -0
  144. package/dist/application/transform/document/document.cjs +32 -9
  145. package/dist/application/transform/document/document.cjs.map +1 -1
  146. package/dist/application/transform/document/document.mjs +34 -11
  147. package/dist/application/transform/document/document.mjs.map +1 -1
  148. package/dist/application/transform/document/exploded-query.cjs +46 -0
  149. package/dist/application/transform/document/exploded-query.cjs.map +1 -0
  150. package/dist/application/transform/document/exploded-query.mjs +43 -0
  151. package/dist/application/transform/document/exploded-query.mjs.map +1 -0
  152. package/dist/application/transform/document/global-type-references.cjs +63 -0
  153. package/dist/application/transform/document/global-type-references.cjs.map +1 -0
  154. package/dist/application/transform/document/global-type-references.mjs +61 -0
  155. package/dist/application/transform/document/global-type-references.mjs.map +1 -0
  156. package/dist/application/transform/document/list-assignability.cjs +54 -0
  157. package/dist/application/transform/document/list-assignability.cjs.map +1 -0
  158. package/dist/application/transform/document/list-assignability.mjs +52 -0
  159. package/dist/application/transform/document/list-assignability.mjs.map +1 -0
  160. package/dist/application/transform/document/parameters.cjs +41 -9
  161. package/dist/application/transform/document/parameters.cjs.map +1 -1
  162. package/dist/application/transform/document/parameters.mjs +42 -10
  163. package/dist/application/transform/document/parameters.mjs.map +1 -1
  164. package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
  165. package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
  166. package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
  167. package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
  168. package/dist/application/transform/document/path-template-replace.cjs +48 -0
  169. package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
  170. package/dist/application/transform/document/path-template-replace.mjs +45 -0
  171. package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
  172. package/dist/application/transform/document/paths.cjs +55 -29
  173. package/dist/application/transform/document/paths.cjs.map +1 -1
  174. package/dist/application/transform/document/paths.mjs +54 -30
  175. package/dist/application/transform/document/paths.mjs.map +1 -1
  176. package/dist/application/transform/document/root-type-aliases.cjs +15 -14
  177. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  178. package/dist/application/transform/document/root-type-aliases.mjs +15 -13
  179. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  180. package/dist/application/transform/document/template-key-match.cjs +128 -0
  181. package/dist/application/transform/document/template-key-match.cjs.map +1 -0
  182. package/dist/application/transform/document/template-key-match.mjs +125 -0
  183. package/dist/application/transform/document/template-key-match.mjs.map +1 -0
  184. package/dist/application/transform/document/type-assignability.cjs +192 -0
  185. package/dist/application/transform/document/type-assignability.cjs.map +1 -0
  186. package/dist/application/transform/document/type-assignability.mjs +190 -0
  187. package/dist/application/transform/document/type-assignability.mjs.map +1 -0
  188. package/dist/application/transform/document/type-key.cjs +70 -0
  189. package/dist/application/transform/document/type-key.cjs.map +1 -0
  190. package/dist/application/transform/document/type-key.mjs +68 -0
  191. package/dist/application/transform/document/type-key.mjs.map +1 -0
  192. package/dist/application/transform/document/type-resolution.cjs +131 -0
  193. package/dist/application/transform/document/type-resolution.cjs.map +1 -0
  194. package/dist/application/transform/document/type-resolution.mjs +125 -0
  195. package/dist/application/transform/document/type-resolution.mjs.map +1 -0
  196. package/dist/application/transform/footer/document-footer.cjs +66 -4
  197. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  198. package/dist/application/transform/footer/document-footer.mjs +67 -5
  199. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  200. package/dist/application/transform/footer/enum-naming.cjs +17 -0
  201. package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
  202. package/dist/application/transform/footer/enum-naming.mjs +17 -1
  203. package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
  204. package/dist/application/transform/footer/enum-values-check.cjs +129 -0
  205. package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
  206. package/dist/application/transform/footer/enum-values-check.mjs +127 -0
  207. package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
  208. package/dist/application/transform/footer/evaluation.cjs +42 -0
  209. package/dist/application/transform/footer/evaluation.cjs.map +1 -0
  210. package/dist/application/transform/footer/evaluation.mjs +33 -0
  211. package/dist/application/transform/footer/evaluation.mjs.map +1 -0
  212. package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
  213. package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
  214. package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
  215. package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
  216. package/dist/application/transform/footer/type-evaluation.cjs +138 -0
  217. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
  218. package/dist/application/transform/footer/type-evaluation.mjs +136 -0
  219. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
  220. package/dist/application/transform/footer/type-indexing.cjs +107 -0
  221. package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
  222. package/dist/application/transform/footer/type-indexing.mjs +105 -0
  223. package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
  224. package/dist/application/transform/footer/type-rules.cjs +172 -0
  225. package/dist/application/transform/footer/type-rules.cjs.map +1 -0
  226. package/dist/application/transform/footer/type-rules.mjs +166 -0
  227. package/dist/application/transform/footer/type-rules.mjs.map +1 -0
  228. package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
  229. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
  230. package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
  231. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
  232. package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
  233. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
  234. package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
  235. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
  236. package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
  237. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
  238. package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
  239. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
  240. package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
  241. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
  242. package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
  243. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
  244. package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
  245. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
  246. package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
  247. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
  248. package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
  249. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
  250. package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
  251. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
  252. package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
  253. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
  254. package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
  255. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
  256. package/dist/application/transform/ref-type.cjs +7 -2
  257. package/dist/application/transform/ref-type.cjs.map +1 -1
  258. package/dist/application/transform/ref-type.mjs +3 -2
  259. package/dist/application/transform/ref-type.mjs.map +1 -1
  260. package/dist/application/transform/schema/access-flags.cjs +38 -0
  261. package/dist/application/transform/schema/access-flags.cjs.map +1 -0
  262. package/dist/application/transform/schema/access-flags.mjs +36 -0
  263. package/dist/application/transform/schema/access-flags.mjs.map +1 -0
  264. package/dist/application/transform/schema/array-type.cjs +32 -1
  265. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  266. package/dist/application/transform/schema/array-type.mjs +33 -2
  267. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  268. package/dist/application/transform/schema/composition-type.cjs +50 -15
  269. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  270. package/dist/application/transform/schema/composition-type.mjs +50 -15
  271. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  272. package/dist/application/transform/schema/core-type.cjs +3 -1
  273. package/dist/application/transform/schema/core-type.cjs.map +1 -1
  274. package/dist/application/transform/schema/core-type.mjs +3 -1
  275. package/dist/application/transform/schema/core-type.mjs.map +1 -1
  276. package/dist/application/transform/schema/discriminated-union.cjs +30 -0
  277. package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
  278. package/dist/application/transform/schema/discriminated-union.mjs +27 -0
  279. package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
  280. package/dist/application/transform/schema/discriminator-property.cjs +3 -2
  281. package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
  282. package/dist/application/transform/schema/discriminator-property.mjs +3 -2
  283. package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
  284. package/dist/application/transform/schema/enum-rule.cjs +66 -10
  285. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  286. package/dist/application/transform/schema/enum-rule.mjs +67 -12
  287. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  288. package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
  289. package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
  290. package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
  291. package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
  292. package/dist/application/transform/schema/object-type.cjs +38 -25
  293. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  294. package/dist/application/transform/schema/object-type.mjs +39 -27
  295. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  296. package/dist/application/transform/schema/required-variants.cjs +45 -0
  297. package/dist/application/transform/schema/required-variants.cjs.map +1 -0
  298. package/dist/application/transform/schema/required-variants.mjs +42 -0
  299. package/dist/application/transform/schema/required-variants.mjs.map +1 -0
  300. package/dist/application/transform/schema/schema-transform.cjs +2 -2
  301. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  302. package/dist/application/transform/schema/schema-transform.mjs +2 -2
  303. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  304. package/dist/application/transform/schema-comment.cjs +51 -5
  305. package/dist/application/transform/schema-comment.cjs.map +1 -1
  306. package/dist/application/transform/schema-comment.mjs +50 -6
  307. package/dist/application/transform/schema-comment.mjs.map +1 -1
  308. package/dist/application/transform/type-combinators.mjs +1 -1
  309. package/dist/cli/api-settings.cjs +78 -0
  310. package/dist/cli/api-settings.cjs.map +1 -0
  311. package/dist/cli/api-settings.mjs +73 -0
  312. package/dist/cli/api-settings.mjs.map +1 -0
  313. package/dist/cli/cli-arguments.cjs +12 -3
  314. package/dist/cli/cli-arguments.cjs.map +1 -1
  315. package/dist/cli/cli-arguments.mjs +12 -4
  316. package/dist/cli/cli-arguments.mjs.map +1 -1
  317. package/dist/cli/cli-errors.cjs +3 -2
  318. package/dist/cli/cli-errors.cjs.map +1 -1
  319. package/dist/cli/cli-errors.mjs +3 -2
  320. package/dist/cli/cli-errors.mjs.map +1 -1
  321. package/dist/cli/cli-output.cjs +8 -3
  322. package/dist/cli/cli-output.cjs.map +1 -1
  323. package/dist/cli/cli-output.mjs +9 -4
  324. package/dist/cli/cli-output.mjs.map +1 -1
  325. package/dist/cli/help-text.cjs +3 -3
  326. package/dist/cli/help-text.cjs.map +1 -1
  327. package/dist/cli/help-text.mjs +3 -3
  328. package/dist/cli/help-text.mjs.map +1 -1
  329. package/dist/cli/main.cjs +5 -0
  330. package/dist/cli/main.cjs.map +1 -1
  331. package/dist/cli/main.mjs +5 -0
  332. package/dist/cli/main.mjs.map +1 -1
  333. package/dist/cli/redocly-apis.cjs +15 -7
  334. package/dist/cli/redocly-apis.cjs.map +1 -1
  335. package/dist/cli/redocly-apis.mjs +15 -7
  336. package/dist/cli/redocly-apis.mjs.map +1 -1
  337. package/dist/cli/ref-limits.cjs +1 -1
  338. package/dist/cli/ref-limits.cjs.map +1 -1
  339. package/dist/cli/ref-limits.mjs +2 -2
  340. package/dist/cli/ref-limits.mjs.map +1 -1
  341. package/dist/cli/run-cli.cjs +20 -3
  342. package/dist/cli/run-cli.cjs.map +1 -1
  343. package/dist/cli/run-cli.mjs +21 -4
  344. package/dist/cli/run-cli.mjs.map +1 -1
  345. package/dist/domain/errors.cjs +6 -1
  346. package/dist/domain/errors.cjs.map +1 -1
  347. package/dist/domain/errors.mjs +6 -1
  348. package/dist/domain/errors.mjs.map +1 -1
  349. package/dist/domain/ir/constructors.cjs +7 -1
  350. package/dist/domain/ir/constructors.cjs.map +1 -1
  351. package/dist/domain/ir/constructors.mjs +6 -2
  352. package/dist/domain/ir/constructors.mjs.map +1 -1
  353. package/dist/domain/openapi/admitted-values.cjs +75 -0
  354. package/dist/domain/openapi/admitted-values.cjs.map +1 -0
  355. package/dist/domain/openapi/admitted-values.mjs +72 -0
  356. package/dist/domain/openapi/admitted-values.mjs.map +1 -0
  357. package/dist/domain/openapi/discriminated-union.cjs +68 -0
  358. package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
  359. package/dist/domain/openapi/discriminated-union.mjs +62 -0
  360. package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
  361. package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
  362. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
  363. package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
  364. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
  365. package/dist/domain/openapi/parameter-object.cjs.map +1 -1
  366. package/dist/domain/openapi/parameter-object.mjs.map +1 -1
  367. package/dist/domain/openapi/path-templates.cjs +23 -0
  368. package/dist/domain/openapi/path-templates.cjs.map +1 -0
  369. package/dist/domain/openapi/path-templates.mjs +21 -0
  370. package/dist/domain/openapi/path-templates.mjs.map +1 -0
  371. package/dist/domain/output-fixes.cjs +36 -1
  372. package/dist/domain/output-fixes.cjs.map +1 -1
  373. package/dist/domain/output-fixes.mjs +36 -1
  374. package/dist/domain/output-fixes.mjs.map +1 -1
  375. package/dist/domain/url-credentials.cjs +10 -0
  376. package/dist/domain/url-credentials.cjs.map +1 -0
  377. package/dist/domain/url-credentials.mjs +8 -0
  378. package/dist/domain/url-credentials.mjs.map +1 -0
  379. package/dist/domain/warnings.cjs +23 -0
  380. package/dist/domain/warnings.cjs.map +1 -0
  381. package/dist/domain/warnings.mjs +20 -0
  382. package/dist/domain/warnings.mjs.map +1 -0
  383. package/dist/index.cjs +2 -0
  384. package/dist/index.cjs.map +1 -1
  385. package/dist/index.d.cts +1182 -46
  386. package/dist/index.d.mts +1182 -46
  387. package/dist/index.d.ts +1182 -46
  388. package/dist/index.mjs +1 -0
  389. package/dist/index.mjs.map +1 -1
  390. package/dist/transform/components-object.cjs +2 -1
  391. package/dist/transform/components-object.cjs.map +1 -1
  392. package/dist/transform/components-object.mjs +2 -1
  393. package/dist/transform/components-object.mjs.map +1 -1
  394. package/dist/transform/path-item-object.cjs.map +1 -1
  395. package/dist/transform/path-item-object.mjs.map +1 -1
  396. package/package.json +6 -5
  397. package/src/adapters/redocly-loader/configured-headers.ts +65 -0
  398. package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
  399. package/src/adapters/redocly-loader/redocly-schema-loader.ts +44 -13
  400. package/src/adapters/redocly-loader/ref-access.ts +60 -5
  401. package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
  402. package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
  403. package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
  404. package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
  405. package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
  406. package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
  407. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +5 -1
  408. package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
  409. package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
  410. package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
  411. package/src/api/default-ports.ts +16 -0
  412. package/src/api/discriminator-conflict-warnings.ts +43 -0
  413. package/src/api/discriminator-enum-names.ts +26 -0
  414. package/src/api/discriminator-enum-parent.ts +129 -0
  415. package/src/api/discriminator-enum.ts +39 -0
  416. package/src/api/discriminator-other-owners.ts +97 -0
  417. package/src/api/discriminator-patch.ts +152 -0
  418. package/src/api/discriminator-scan.ts +78 -90
  419. package/src/api/document-refs.ts +19 -15
  420. package/src/api/document-run.ts +32 -11
  421. package/src/api/enum-values-warnings.ts +21 -0
  422. package/src/api/footer-sink.ts +34 -2
  423. package/src/api/legacy-callback-warning.ts +7 -3
  424. package/src/api/legacy-ts-helpers.ts +7 -5
  425. package/src/api/legacy-utils.ts +1 -1
  426. package/src/api/openapi-ts.ts +2 -0
  427. package/src/api/path-template-warnings.ts +27 -0
  428. package/src/api/run-context.ts +34 -0
  429. package/src/api/transform-context.ts +17 -9
  430. package/src/api/transform-schema.ts +90 -5
  431. package/src/api/unsupported-feature-warnings.ts +8 -1
  432. package/src/application/ports/redocly-config-source.ts +5 -1
  433. package/src/application/print/type-printer.ts +8 -1
  434. package/src/application/transform/document/assignability.ts +203 -0
  435. package/src/application/transform/document/components.ts +6 -6
  436. package/src/application/transform/document/declared-types.ts +93 -0
  437. package/src/application/transform/document/document.ts +71 -13
  438. package/src/application/transform/document/exploded-query.ts +91 -0
  439. package/src/application/transform/document/global-type-references.ts +78 -0
  440. package/src/application/transform/document/list-assignability.ts +87 -0
  441. package/src/application/transform/document/parameters.ts +78 -12
  442. package/src/application/transform/document/path-key-overlaps.ts +148 -59
  443. package/src/application/transform/document/path-template-replace.ts +90 -0
  444. package/src/application/transform/document/paths.ts +101 -38
  445. package/src/application/transform/document/root-type-aliases.ts +29 -28
  446. package/src/application/transform/document/template-key-match.ts +183 -0
  447. package/src/application/transform/document/type-assignability.ts +268 -0
  448. package/src/application/transform/document/type-key.ts +80 -0
  449. package/src/application/transform/document/type-resolution.ts +163 -0
  450. package/src/application/transform/footer/document-footer.ts +91 -6
  451. package/src/application/transform/footer/enum-naming.ts +29 -0
  452. package/src/application/transform/footer/enum-values-check.ts +171 -0
  453. package/src/application/transform/footer/evaluation.ts +57 -0
  454. package/src/application/transform/footer/shared-enum-names.ts +86 -0
  455. package/src/application/transform/footer/type-evaluation.ts +167 -0
  456. package/src/application/transform/footer/type-indexing.ts +152 -0
  457. package/src/application/transform/footer/type-rules.ts +269 -0
  458. package/src/application/transform/ref-pointer/generated-location.ts +211 -0
  459. package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
  460. package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
  461. package/src/application/transform/ref-pointer/original-index.ts +95 -0
  462. package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
  463. package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
  464. package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
  465. package/src/application/transform/ref-type.ts +11 -6
  466. package/src/application/transform/schema/access-flags.ts +63 -0
  467. package/src/application/transform/schema/array-type.ts +66 -5
  468. package/src/application/transform/schema/composition-type.ts +96 -24
  469. package/src/application/transform/schema/core-type.ts +8 -4
  470. package/src/application/transform/schema/discriminated-union.ts +58 -0
  471. package/src/application/transform/schema/discriminator-property.ts +8 -3
  472. package/src/application/transform/schema/enum-rule.ts +136 -13
  473. package/src/application/transform/schema/inherited-discriminator.ts +54 -0
  474. package/src/application/transform/schema/object-type.ts +51 -33
  475. package/src/application/transform/schema/required-variants.ts +88 -0
  476. package/src/application/transform/schema/schema-context.ts +26 -0
  477. package/src/application/transform/schema/schema-transform.ts +2 -2
  478. package/src/application/transform/schema-comment.ts +84 -4
  479. package/src/cli/api-settings.ts +109 -0
  480. package/src/cli/cli-arguments.ts +18 -5
  481. package/src/cli/cli-dependencies.ts +5 -0
  482. package/src/cli/cli-errors.ts +4 -2
  483. package/src/cli/cli-output.ts +18 -4
  484. package/src/cli/help-text.ts +4 -4
  485. package/src/cli/main.ts +6 -0
  486. package/src/cli/redocly-apis.ts +21 -11
  487. package/src/cli/ref-limits.ts +2 -2
  488. package/src/cli/run-cli.ts +25 -4
  489. package/src/domain/errors.ts +10 -2
  490. package/src/domain/ir/constructors.ts +9 -1
  491. package/src/domain/ir/nodes.ts +11 -7
  492. package/src/domain/openapi/admitted-values.ts +113 -0
  493. package/src/domain/openapi/discriminated-union.ts +109 -0
  494. package/src/domain/openapi/discriminator-conflicts.ts +251 -0
  495. package/src/domain/openapi/parameter-object.ts +4 -0
  496. package/src/domain/openapi/path-templates.ts +32 -0
  497. package/src/domain/openapi/schema-object.ts +2 -0
  498. package/src/domain/output-fixes.ts +43 -2
  499. package/src/domain/url-credentials.ts +18 -0
  500. package/src/domain/warnings.ts +28 -0
  501. package/src/index.ts +1 -0
  502. package/src/transform/components-object.ts +3 -1
  503. package/src/transform/path-item-object.ts +6 -2
  504. package/src/types/generator-options.ts +12 -21
  505. package/src/types/openapi-common.ts +1 -0
  506. package/src/types/openapi-request.ts +3 -0
  507. package/src/types/openapi-schema.ts +2 -0
  508. package/src/types/openapi-security.ts +1 -0
  509. package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
  510. package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
  511. package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
  512. package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
  513. package/src/application/transform/document/path-item-conflicts.ts +0 -79
@@ -1 +1 @@
1
- {"version":3,"file":"ir-to-typescript.cjs","sources":["../../../src/adapters/type-ast-bridge/ir-to-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { assertNever } from \"../../domain/assert-never.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/**\n * Convert IR to TypeScript AST nodes with the same factory calls the original generator makes.\n * Printing the result with the TypeScript printer gives the original output, which is how the\n * printer parity tests (ENGINEERING_PLAN 4.3) define \"byte-identical\". Every function takes the\n * TypeScript module to build with (ADR-004, decision 4): the nodes must come from the same module\n * that later reads or prints them.\n */\n\ntype KeywordName = Exclude<IrKeyword, \"null\">;\n\nfunction keywordKind(ts: TypeScriptModule, keyword: KeywordName): ts.KeywordTypeSyntaxKind {\n const kinds: Readonly<Record<KeywordName, ts.KeywordTypeSyntaxKind>> = {\n string: ts.SyntaxKind.StringKeyword,\n number: ts.SyntaxKind.NumberKeyword,\n boolean: ts.SyntaxKind.BooleanKeyword,\n undefined: ts.SyntaxKind.UndefinedKeyword,\n unknown: ts.SyntaxKind.UnknownKeyword,\n never: ts.SyntaxKind.NeverKeyword,\n };\n return kinds[keyword];\n}\n\nfunction toKeywordType(ts: TypeScriptModule, keyword: IrKeyword): ts.TypeNode {\n return keyword === \"null\"\n ? ts.factory.createLiteralTypeNode(ts.factory.createNull())\n : ts.factory.createKeywordTypeNode(keywordKind(ts, keyword));\n}\n\n/**\n * Numbers as the original writes them: a negative value is a prefix minus on its absolute value.\n */\nfunction toNumberExpression(\n ts: TypeScriptModule,\n value: number,\n): ts.PrefixUnaryExpression | ts.NumericLiteral {\n return value < 0\n ? ts.factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n ts.factory.createNumericLiteral(Math.abs(value)),\n )\n : ts.factory.createNumericLiteral(value);\n}\n\n/** An enum member or array element value, written as the original writes it. */\nexport function toValueExpression(ts: TypeScriptModule, value: string | number): ts.Expression {\n return typeof value === \"number\"\n ? toNumberExpression(ts, value)\n : ts.factory.createStringLiteral(value);\n}\n\n/** The original writes JSON-encoded literal types as identifiers to keep UTF-8 readable. */\nfunction toStringLiteralType(\n ts: TypeScriptModule,\n value: string,\n encoding: \"json\" | \"escaped\",\n): ts.TypeNode {\n return encoding === \"json\"\n ? (ts.factory.createIdentifier(JSON.stringify(value)) as unknown as ts.TypeNode)\n : ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value));\n}\n\nfunction toTupleElement(ts: TypeScriptModule, element: IrTupleElement): ts.TypeNode {\n const type = toTypeNode(ts, element.type);\n return element.isRest ? ts.factory.createRestTypeNode(type) : type;\n}\n\ntype LeafType = Extract<\n IrType,\n { kind: \"keyword\" | \"stringLiteral\" | \"numberLiteral\" | \"booleanLiteral\" | \"raw\" }\n>;\n\nfunction toLeafTypeNode(ts: TypeScriptModule, type: LeafType): ts.TypeNode {\n switch (type.kind) {\n case \"keyword\":\n return toKeywordType(ts, type.keyword);\n case \"stringLiteral\":\n return toStringLiteralType(ts, type.value, type.encoding);\n case \"numberLiteral\":\n return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));\n case \"booleanLiteral\":\n return ts.factory.createLiteralTypeNode(\n type.value ? ts.factory.createTrue() : ts.factory.createFalse(),\n );\n case \"raw\":\n // A node read from TypeScript goes back as it was, so the TypeScript printer indents it.\n return (\n (type.origin as ts.TypeNode | undefined) ??\n (ts.factory.createIdentifier(type.text) as unknown as ts.TypeNode)\n );\n default:\n return assertNever(type);\n }\n}\n\nfunction toReferenceNode(\n ts: TypeScriptModule,\n type: Extract<IrType, { kind: \"reference\" }>,\n): ts.TypeNode {\n const typeArguments =\n type.typeArguments.length > 0\n ? type.typeArguments.map((argument) => toTypeNode(ts, argument))\n : undefined;\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(type.name), typeArguments);\n}\n\n/** Convert one IR type. */\nexport function toTypeNode(ts: TypeScriptModule, type: IrType): ts.TypeNode {\n const convert = (inner: IrType) => toTypeNode(ts, inner);\n const { factory } = ts;\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"raw\":\n return toLeafTypeNode(ts, type);\n case \"reference\":\n return toReferenceNode(ts, type);\n case \"array\":\n return factory.createArrayTypeNode(convert(type.element));\n case \"tuple\":\n return factory.createTupleTypeNode(\n type.elements.map((element) => toTupleElement(ts, element)),\n );\n case \"union\":\n return factory.createUnionTypeNode(type.types.map(convert));\n case \"intersection\":\n return factory.createIntersectionTypeNode(type.types.map(convert));\n case \"object\":\n return factory.createTypeLiteralNode(type.members.map((member) => toTypeElement(ts, member)));\n case \"indexedAccess\":\n return factory.createIndexedAccessTypeNode(convert(type.object), convert(type.index));\n case \"readonly\":\n return factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, convert(type.type));\n default:\n return assertNever(type);\n }\n}\n\n/** Attach IR comments to a node as synthetic leading comments, as the original does. */\nexport function withComments<T extends ts.Node>(\n ts: TypeScriptModule,\n node: T,\n comments: readonly IrComment[],\n): T {\n for (const comment of comments) {\n const kind =\n comment.kind === \"block\"\n ? ts.SyntaxKind.MultiLineCommentTrivia\n : ts.SyntaxKind.SingleLineCommentTrivia;\n ts.addSyntheticLeadingComment(node, kind, comment.text, true);\n }\n return node;\n}\n\nfunction toPropertyName(ts: TypeScriptModule, name: IrPropertyName): ts.PropertyName {\n switch (name.kind) {\n case \"identifier\":\n return ts.factory.createIdentifier(name.text);\n case \"string\":\n return ts.factory.createStringLiteral(name.value);\n case \"number\":\n return ts.factory.createNumericLiteral(name.text);\n default:\n return assertNever(name);\n }\n}\n\nfunction readonlyModifiers(ts: TypeScriptModule, isReadonly: boolean): ts.Modifier[] | undefined {\n return isReadonly ? [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)] : undefined;\n}\n\n/** Convert one property signature (for callbacks that receive a `ts.PropertySignature`). */\nexport function toPropertySignature(\n ts: TypeScriptModule,\n property: IrPropertySignature,\n): ts.PropertySignature {\n const questionToken = property.isOptional\n ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)\n : undefined;\n const signature = ts.factory.createPropertySignature(\n readonlyModifiers(ts, property.isReadonly),\n toPropertyName(ts, property.name),\n questionToken,\n toTypeNode(ts, property.type),\n );\n return withComments(ts, signature, property.comments);\n}\n\nexport function toTypeElement(ts: TypeScriptModule, member: IrMember): ts.TypeElement {\n if (member.kind === \"property\") {\n return toPropertySignature(ts, member);\n }\n const parameter = ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n member.parameterName,\n undefined,\n toTypeNode(ts, member.parameterType),\n );\n const signature = ts.factory.createIndexSignature(\n readonlyModifiers(ts, member.isReadonly),\n [parameter],\n toTypeNode(ts, member.type),\n );\n return withComments(ts, signature, member.comments);\n}\n"],"names":["assertNever"],"mappings":";;;;AAuBA,SAAS,WAAA,CAAY,IAAsB,OAAA,EAAgD;AACzF,EAAA,MAAM,KAAA,GAAiE;AAAA,IACrE,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,SAAA,EAAW,GAAG,UAAA,CAAW,gBAAA;AAAA,IACzB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,KAAA,EAAO,GAAG,UAAA,CAAW;AAAA,GACvB;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB;AAEA,SAAS,aAAA,CAAc,IAAsB,OAAA,EAAiC;AAC5E,EAAA,OAAO,YAAY,MAAA,GACf,EAAA,CAAG,OAAA,CAAQ,qBAAA,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AC3B,iBAAA,CAAkB,EAAA,EAAI,QAAA,CAAS,UAAU,CAAA;AAAA,IACzC,cAAA,CAAe,EAAA,EAAI,QAAA,CAAS,IAAI,CAAA;AAAA,IAChC,aAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,QAAA,CAAS,IAAI;AAAA,GAC9B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,QAAA,CAAS,QAAQ,CAAA;AACtD;AAEO,SAAS,aAAA,CAAc,IAAsB,MAAA,EAAkC;AACpF,EAAA,IAAI,MAAA,CAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,OAAO,mBAAA,CAAoB,IAAI,MAAM,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,CAAO,aAAA;AAAA,IACP,MAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,aAAa;AAAA,GACrC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,oBAAA;AAAA,IAC3B,iBAAA,CAAkB,EAAA,EAAI,MAAA,CAAO,UAAU,CAAA;AAAA,IACvC,CAAC,SAAS,CAAA;AAAA,IACV,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,IAAI;AAAA,GAC5B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,MAAA,CAAO,QAAQ,CAAA;AACpD;;;;;;"}
1
+ {"version":3,"file":"ir-to-typescript.cjs","sources":["../../../src/adapters/type-ast-bridge/ir-to-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { assertNever } from \"../../domain/assert-never.js\";\nimport { DEFAULT_STRING_ENCODING } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/**\n * Convert IR to TypeScript AST nodes with the same factory calls the original generator makes.\n * Printing the result with the TypeScript printer gives the original output, which is how the\n * printer parity tests (ENGINEERING_PLAN 4.3) define \"byte-identical\". Every function takes the\n * TypeScript module to build with (ADR-004, decision 4): the nodes must come from the same module\n * that later reads or prints them.\n */\n\ntype KeywordName = Exclude<IrKeyword, \"null\">;\n\nfunction keywordKind(ts: TypeScriptModule, keyword: KeywordName): ts.KeywordTypeSyntaxKind {\n const kinds: Readonly<Record<KeywordName, ts.KeywordTypeSyntaxKind>> = {\n string: ts.SyntaxKind.StringKeyword,\n number: ts.SyntaxKind.NumberKeyword,\n boolean: ts.SyntaxKind.BooleanKeyword,\n undefined: ts.SyntaxKind.UndefinedKeyword,\n unknown: ts.SyntaxKind.UnknownKeyword,\n never: ts.SyntaxKind.NeverKeyword,\n };\n return kinds[keyword];\n}\n\nfunction toKeywordType(ts: TypeScriptModule, keyword: IrKeyword): ts.TypeNode {\n return keyword === \"null\"\n ? ts.factory.createLiteralTypeNode(ts.factory.createNull())\n : ts.factory.createKeywordTypeNode(keywordKind(ts, keyword));\n}\n\n/**\n * Numbers as the original writes them: a negative value is a prefix minus on its absolute value.\n */\nfunction toNumberExpression(\n ts: TypeScriptModule,\n value: number,\n): ts.PrefixUnaryExpression | ts.NumericLiteral {\n return value < 0\n ? ts.factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n ts.factory.createNumericLiteral(Math.abs(value)),\n )\n : ts.factory.createNumericLiteral(value);\n}\n\n/** An enum member or array element value, written as the original writes it. */\nexport function toValueExpression(ts: TypeScriptModule, value: string | number): ts.Expression {\n return typeof value === \"number\"\n ? toNumberExpression(ts, value)\n : ts.factory.createStringLiteral(value);\n}\n\n/** The original writes JSON-encoded literal types as identifiers to keep UTF-8 readable. */\nfunction toStringLiteralType(\n ts: TypeScriptModule,\n value: string,\n encoding: \"json\" | \"escaped\",\n): ts.TypeNode {\n return encoding === \"json\"\n ? (ts.factory.createIdentifier(JSON.stringify(value)) as unknown as ts.TypeNode)\n : ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value));\n}\n\nfunction toTupleElement(ts: TypeScriptModule, element: IrTupleElement): ts.TypeNode {\n const type = toTypeNode(ts, element.type);\n if (element.isOptional) {\n return ts.factory.createOptionalTypeNode(type);\n }\n return element.isRest ? ts.factory.createRestTypeNode(type) : type;\n}\n\ntype LeafType = Extract<\n IrType,\n { kind: \"keyword\" | \"stringLiteral\" | \"numberLiteral\" | \"booleanLiteral\" | \"raw\" }\n>;\n\nfunction toLeafTypeNode(ts: TypeScriptModule, type: LeafType): ts.TypeNode {\n switch (type.kind) {\n case \"keyword\":\n return toKeywordType(ts, type.keyword);\n case \"stringLiteral\":\n return toStringLiteralType(ts, type.value, type.encoding ?? DEFAULT_STRING_ENCODING);\n case \"numberLiteral\":\n return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));\n case \"booleanLiteral\":\n return ts.factory.createLiteralTypeNode(\n type.value ? ts.factory.createTrue() : ts.factory.createFalse(),\n );\n case \"raw\":\n // A node read from TypeScript goes back as it was, so the TypeScript printer indents it.\n return (\n (type.origin as ts.TypeNode | undefined) ??\n (ts.factory.createIdentifier(type.text) as unknown as ts.TypeNode)\n );\n default:\n return assertNever(type);\n }\n}\n\nfunction toReferenceNode(\n ts: TypeScriptModule,\n type: Extract<IrType, { kind: \"reference\" }>,\n): ts.TypeNode {\n const typeArguments =\n type.typeArguments.length > 0\n ? type.typeArguments.map((argument) => toTypeNode(ts, argument))\n : undefined;\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(type.name), typeArguments);\n}\n\n/** Convert one IR type. */\nexport function toTypeNode(ts: TypeScriptModule, type: IrType): ts.TypeNode {\n const convert = (inner: IrType) => toTypeNode(ts, inner);\n const { factory } = ts;\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"raw\":\n return toLeafTypeNode(ts, type);\n case \"reference\":\n return toReferenceNode(ts, type);\n case \"array\":\n return factory.createArrayTypeNode(convert(type.element));\n case \"tuple\":\n return factory.createTupleTypeNode(\n type.elements.map((element) => toTupleElement(ts, element)),\n );\n case \"union\":\n return factory.createUnionTypeNode(type.types.map(convert));\n case \"intersection\":\n return factory.createIntersectionTypeNode(type.types.map(convert));\n case \"object\":\n return factory.createTypeLiteralNode(type.members.map((member) => toTypeElement(ts, member)));\n case \"indexedAccess\":\n return factory.createIndexedAccessTypeNode(convert(type.object), convert(type.index));\n case \"readonly\":\n return factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, convert(type.type));\n default:\n return assertNever(type);\n }\n}\n\n/** Attach IR comments to a node as synthetic leading comments, as the original does. */\nexport function withComments<T extends ts.Node>(\n ts: TypeScriptModule,\n node: T,\n comments: readonly IrComment[],\n): T {\n for (const comment of comments) {\n const kind =\n comment.kind === \"block\"\n ? ts.SyntaxKind.MultiLineCommentTrivia\n : ts.SyntaxKind.SingleLineCommentTrivia;\n ts.addSyntheticLeadingComment(node, kind, comment.text, true);\n }\n return node;\n}\n\nfunction toPropertyName(ts: TypeScriptModule, name: IrPropertyName): ts.PropertyName {\n switch (name.kind) {\n case \"identifier\":\n return ts.factory.createIdentifier(name.text);\n case \"string\":\n return ts.factory.createStringLiteral(name.value);\n case \"number\":\n return ts.factory.createNumericLiteral(name.text);\n default:\n return assertNever(name);\n }\n}\n\nfunction readonlyModifiers(ts: TypeScriptModule, isReadonly: boolean): ts.Modifier[] | undefined {\n return isReadonly ? [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)] : undefined;\n}\n\n/** Convert one property signature (for callbacks that receive a `ts.PropertySignature`). */\nexport function toPropertySignature(\n ts: TypeScriptModule,\n property: IrPropertySignature,\n): ts.PropertySignature {\n const questionToken = property.isOptional\n ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)\n : undefined;\n const signature = ts.factory.createPropertySignature(\n readonlyModifiers(ts, property.isReadonly),\n toPropertyName(ts, property.name),\n questionToken,\n toTypeNode(ts, property.type),\n );\n return withComments(ts, signature, property.comments);\n}\n\nexport function toTypeElement(ts: TypeScriptModule, member: IrMember): ts.TypeElement {\n if (member.kind === \"property\") {\n return toPropertySignature(ts, member);\n }\n const parameter = ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n member.parameterName,\n undefined,\n toTypeNode(ts, member.parameterType),\n );\n const signature = ts.factory.createIndexSignature(\n readonlyModifiers(ts, member.isReadonly),\n [parameter],\n toTypeNode(ts, member.type),\n );\n return withComments(ts, signature, member.comments);\n}\n"],"names":["DEFAULT_STRING_ENCODING","assertNever"],"mappings":";;;;;AAwBA,SAAS,WAAA,CAAY,IAAsB,OAAA,EAAgD;AACzF,EAAA,MAAM,KAAA,GAAiE;AAAA,IACrE,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,SAAA,EAAW,GAAG,UAAA,CAAW,gBAAA;AAAA,IACzB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,KAAA,EAAO,GAAG,UAAA,CAAW;AAAA,GACvB;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB;AAEA,SAAS,aAAA,CAAc,IAAsB,OAAA,EAAiC;AAC5E,EAAA,OAAO,YAAY,MAAA,GACf,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,GAAG,OAAA,CAAQ,UAAA,EAAY,CAAA,GACxD,GAAG,OAAA,CAAQ,qBAAA,CAAsB,WAAA,CAAY,EAAA,EAAI,OAAO,CAAC,CAAA;AAC/D;AAKA,SAAS,kBAAA,CACP,IACA,KAAA,EAC8C;AAC9C,EAAA,OAAO,KAAA,GAAQ,CAAA,GACX,EAAA,CAAG,OAAA,CAAQ,2BAAA;AAAA,IACT,GAAG,UAA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UAAA,CAAW,EAAA,EAAI,QAAA,CAAS,IAAI;AAAA,GAC9B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,QAAA,CAAS,QAAQ,CAAA;AACtD;AAEO,SAAS,aAAA,CAAc,IAAsB,MAAA,EAAkC;AACpF,EAAA,IAAI,MAAA,CAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,OAAO,mBAAA,CAAoB,IAAI,MAAM,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,CAAO,aAAA;AAAA,IACP,MAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,aAAa;AAAA,GACrC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,oBAAA;AAAA,IAC3B,iBAAA,CAAkB,EAAA,EAAI,MAAA,CAAO,UAAU,CAAA;AAAA,IACvC,CAAC,SAAS,CAAA;AAAA,IACV,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,IAAI;AAAA,GAC5B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,MAAA,CAAO,QAAQ,CAAA;AACpD;;;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { assertNever } from '../../domain/assert-never.mjs';
2
+ import { DEFAULT_STRING_ENCODING } from '../../domain/ir/constructors.mjs';
2
3
 
3
4
  function keywordKind(ts, keyword) {
4
5
  const kinds = {
@@ -28,6 +29,9 @@ function toStringLiteralType(ts, value, encoding) {
28
29
  }
29
30
  function toTupleElement(ts, element) {
30
31
  const type = toTypeNode(ts, element.type);
32
+ if (element.isOptional) {
33
+ return ts.factory.createOptionalTypeNode(type);
34
+ }
31
35
  return element.isRest ? ts.factory.createRestTypeNode(type) : type;
32
36
  }
33
37
  function toLeafTypeNode(ts, type) {
@@ -35,7 +39,7 @@ function toLeafTypeNode(ts, type) {
35
39
  case "keyword":
36
40
  return toKeywordType(ts, type.keyword);
37
41
  case "stringLiteral":
38
- return toStringLiteralType(ts, type.value, type.encoding);
42
+ return toStringLiteralType(ts, type.value, type.encoding ?? DEFAULT_STRING_ENCODING);
39
43
  case "numberLiteral":
40
44
  return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));
41
45
  case "booleanLiteral":
@@ -1 +1 @@
1
- {"version":3,"file":"ir-to-typescript.mjs","sources":["../../../src/adapters/type-ast-bridge/ir-to-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { assertNever } from \"../../domain/assert-never.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/**\n * Convert IR to TypeScript AST nodes with the same factory calls the original generator makes.\n * Printing the result with the TypeScript printer gives the original output, which is how the\n * printer parity tests (ENGINEERING_PLAN 4.3) define \"byte-identical\". Every function takes the\n * TypeScript module to build with (ADR-004, decision 4): the nodes must come from the same module\n * that later reads or prints them.\n */\n\ntype KeywordName = Exclude<IrKeyword, \"null\">;\n\nfunction keywordKind(ts: TypeScriptModule, keyword: KeywordName): ts.KeywordTypeSyntaxKind {\n const kinds: Readonly<Record<KeywordName, ts.KeywordTypeSyntaxKind>> = {\n string: ts.SyntaxKind.StringKeyword,\n number: ts.SyntaxKind.NumberKeyword,\n boolean: ts.SyntaxKind.BooleanKeyword,\n undefined: ts.SyntaxKind.UndefinedKeyword,\n unknown: ts.SyntaxKind.UnknownKeyword,\n never: ts.SyntaxKind.NeverKeyword,\n };\n return kinds[keyword];\n}\n\nfunction toKeywordType(ts: TypeScriptModule, keyword: IrKeyword): ts.TypeNode {\n return keyword === \"null\"\n ? ts.factory.createLiteralTypeNode(ts.factory.createNull())\n : ts.factory.createKeywordTypeNode(keywordKind(ts, keyword));\n}\n\n/**\n * Numbers as the original writes them: a negative value is a prefix minus on its absolute value.\n */\nfunction toNumberExpression(\n ts: TypeScriptModule,\n value: number,\n): ts.PrefixUnaryExpression | ts.NumericLiteral {\n return value < 0\n ? ts.factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n ts.factory.createNumericLiteral(Math.abs(value)),\n )\n : ts.factory.createNumericLiteral(value);\n}\n\n/** An enum member or array element value, written as the original writes it. */\nexport function toValueExpression(ts: TypeScriptModule, value: string | number): ts.Expression {\n return typeof value === \"number\"\n ? toNumberExpression(ts, value)\n : ts.factory.createStringLiteral(value);\n}\n\n/** The original writes JSON-encoded literal types as identifiers to keep UTF-8 readable. */\nfunction toStringLiteralType(\n ts: TypeScriptModule,\n value: string,\n encoding: \"json\" | \"escaped\",\n): ts.TypeNode {\n return encoding === \"json\"\n ? (ts.factory.createIdentifier(JSON.stringify(value)) as unknown as ts.TypeNode)\n : ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value));\n}\n\nfunction toTupleElement(ts: TypeScriptModule, element: IrTupleElement): ts.TypeNode {\n const type = toTypeNode(ts, element.type);\n return element.isRest ? ts.factory.createRestTypeNode(type) : type;\n}\n\ntype LeafType = Extract<\n IrType,\n { kind: \"keyword\" | \"stringLiteral\" | \"numberLiteral\" | \"booleanLiteral\" | \"raw\" }\n>;\n\nfunction toLeafTypeNode(ts: TypeScriptModule, type: LeafType): ts.TypeNode {\n switch (type.kind) {\n case \"keyword\":\n return toKeywordType(ts, type.keyword);\n case \"stringLiteral\":\n return toStringLiteralType(ts, type.value, type.encoding);\n case \"numberLiteral\":\n return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));\n case \"booleanLiteral\":\n return ts.factory.createLiteralTypeNode(\n type.value ? ts.factory.createTrue() : ts.factory.createFalse(),\n );\n case \"raw\":\n // A node read from TypeScript goes back as it was, so the TypeScript printer indents it.\n return (\n (type.origin as ts.TypeNode | undefined) ??\n (ts.factory.createIdentifier(type.text) as unknown as ts.TypeNode)\n );\n default:\n return assertNever(type);\n }\n}\n\nfunction toReferenceNode(\n ts: TypeScriptModule,\n type: Extract<IrType, { kind: \"reference\" }>,\n): ts.TypeNode {\n const typeArguments =\n type.typeArguments.length > 0\n ? type.typeArguments.map((argument) => toTypeNode(ts, argument))\n : undefined;\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(type.name), typeArguments);\n}\n\n/** Convert one IR type. */\nexport function toTypeNode(ts: TypeScriptModule, type: IrType): ts.TypeNode {\n const convert = (inner: IrType) => toTypeNode(ts, inner);\n const { factory } = ts;\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"raw\":\n return toLeafTypeNode(ts, type);\n case \"reference\":\n return toReferenceNode(ts, type);\n case \"array\":\n return factory.createArrayTypeNode(convert(type.element));\n case \"tuple\":\n return factory.createTupleTypeNode(\n type.elements.map((element) => toTupleElement(ts, element)),\n );\n case \"union\":\n return factory.createUnionTypeNode(type.types.map(convert));\n case \"intersection\":\n return factory.createIntersectionTypeNode(type.types.map(convert));\n case \"object\":\n return factory.createTypeLiteralNode(type.members.map((member) => toTypeElement(ts, member)));\n case \"indexedAccess\":\n return factory.createIndexedAccessTypeNode(convert(type.object), convert(type.index));\n case \"readonly\":\n return factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, convert(type.type));\n default:\n return assertNever(type);\n }\n}\n\n/** Attach IR comments to a node as synthetic leading comments, as the original does. */\nexport function withComments<T extends ts.Node>(\n ts: TypeScriptModule,\n node: T,\n comments: readonly IrComment[],\n): T {\n for (const comment of comments) {\n const kind =\n comment.kind === \"block\"\n ? ts.SyntaxKind.MultiLineCommentTrivia\n : ts.SyntaxKind.SingleLineCommentTrivia;\n ts.addSyntheticLeadingComment(node, kind, comment.text, true);\n }\n return node;\n}\n\nfunction toPropertyName(ts: TypeScriptModule, name: IrPropertyName): ts.PropertyName {\n switch (name.kind) {\n case \"identifier\":\n return ts.factory.createIdentifier(name.text);\n case \"string\":\n return ts.factory.createStringLiteral(name.value);\n case \"number\":\n return ts.factory.createNumericLiteral(name.text);\n default:\n return assertNever(name);\n }\n}\n\nfunction readonlyModifiers(ts: TypeScriptModule, isReadonly: boolean): ts.Modifier[] | undefined {\n return isReadonly ? [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)] : undefined;\n}\n\n/** Convert one property signature (for callbacks that receive a `ts.PropertySignature`). */\nexport function toPropertySignature(\n ts: TypeScriptModule,\n property: IrPropertySignature,\n): ts.PropertySignature {\n const questionToken = property.isOptional\n ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)\n : undefined;\n const signature = ts.factory.createPropertySignature(\n readonlyModifiers(ts, property.isReadonly),\n toPropertyName(ts, property.name),\n questionToken,\n toTypeNode(ts, property.type),\n );\n return withComments(ts, signature, property.comments);\n}\n\nexport function toTypeElement(ts: TypeScriptModule, member: IrMember): ts.TypeElement {\n if (member.kind === \"property\") {\n return toPropertySignature(ts, member);\n }\n const parameter = ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n member.parameterName,\n undefined,\n toTypeNode(ts, member.parameterType),\n );\n const signature = ts.factory.createIndexSignature(\n readonlyModifiers(ts, member.isReadonly),\n [parameter],\n toTypeNode(ts, member.type),\n );\n return withComments(ts, signature, member.comments);\n}\n"],"names":[],"mappings":";;AAuBA,SAAS,WAAA,CAAY,IAAsB,OAAA,EAAgD;AACzF,EAAA,MAAM,KAAA,GAAiE;AAAA,IACrE,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,SAAA,EAAW,GAAG,UAAA,CAAW,gBAAA;AAAA,IACzB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,KAAA,EAAO,GAAG,UAAA,CAAW;AAAA,GACvB;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB;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CAAG,UAAA,CAAW,aAAa,CAAA,GAClD,MAAA;AACJ,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,uBAAA;AAAA,IAC3B,iBAAA,CAAkB,EAAA,EAAI,QAAA,CAAS,UAAU,CAAA;AAAA,IACzC,cAAA,CAAe,EAAA,EAAI,QAAA,CAAS,IAAI,CAAA;AAAA,IAChC,aAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,QAAA,CAAS,IAAI;AAAA,GAC9B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,QAAA,CAAS,QAAQ,CAAA;AACtD;AAEO,SAAS,aAAA,CAAc,IAAsB,MAAA,EAAkC;AACpF,EAAA,IAAI,MAAA,CAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,OAAO,mBAAA,CAAoB,IAAI,MAAM,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,CAAO,aAAA;AAAA,IACP,MAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,aAAa;AAAA,GACrC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,oBAAA;AAAA,IAC3B,iBAAA,CAAkB,EAAA,EAAI,MAAA,CAAO,UAAU,CAAA;AAAA,IACvC,CAAC,SAAS,CAAA;AAAA,IACV,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,IAAI;AAAA,GAC5B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,MAAA,CAAO,QAAQ,CAAA;AACpD;;"}
1
+ {"version":3,"file":"ir-to-typescript.mjs","sources":["../../../src/adapters/type-ast-bridge/ir-to-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { assertNever } from \"../../domain/assert-never.js\";\nimport { DEFAULT_STRING_ENCODING } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/**\n * Convert IR to TypeScript AST nodes with the same factory calls the original generator makes.\n * Printing the result with the TypeScript printer gives the original output, which is how the\n * printer parity tests (ENGINEERING_PLAN 4.3) define \"byte-identical\". Every function takes the\n * TypeScript module to build with (ADR-004, decision 4): the nodes must come from the same module\n * that later reads or prints them.\n */\n\ntype KeywordName = Exclude<IrKeyword, \"null\">;\n\nfunction keywordKind(ts: TypeScriptModule, keyword: KeywordName): ts.KeywordTypeSyntaxKind {\n const kinds: Readonly<Record<KeywordName, ts.KeywordTypeSyntaxKind>> = {\n string: ts.SyntaxKind.StringKeyword,\n number: ts.SyntaxKind.NumberKeyword,\n boolean: ts.SyntaxKind.BooleanKeyword,\n undefined: ts.SyntaxKind.UndefinedKeyword,\n unknown: ts.SyntaxKind.UnknownKeyword,\n never: ts.SyntaxKind.NeverKeyword,\n };\n return kinds[keyword];\n}\n\nfunction toKeywordType(ts: TypeScriptModule, keyword: IrKeyword): ts.TypeNode {\n return keyword === \"null\"\n ? ts.factory.createLiteralTypeNode(ts.factory.createNull())\n : ts.factory.createKeywordTypeNode(keywordKind(ts, keyword));\n}\n\n/**\n * Numbers as the original writes them: a negative value is a prefix minus on its absolute value.\n */\nfunction toNumberExpression(\n ts: TypeScriptModule,\n value: number,\n): ts.PrefixUnaryExpression | ts.NumericLiteral {\n return value < 0\n ? ts.factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n ts.factory.createNumericLiteral(Math.abs(value)),\n )\n : ts.factory.createNumericLiteral(value);\n}\n\n/** An enum member or array element value, written as the original writes it. */\nexport function toValueExpression(ts: TypeScriptModule, value: string | number): ts.Expression {\n return typeof value === \"number\"\n ? toNumberExpression(ts, value)\n : ts.factory.createStringLiteral(value);\n}\n\n/** The original writes JSON-encoded literal types as identifiers to keep UTF-8 readable. */\nfunction toStringLiteralType(\n ts: TypeScriptModule,\n value: string,\n encoding: \"json\" | \"escaped\",\n): ts.TypeNode {\n return encoding === \"json\"\n ? (ts.factory.createIdentifier(JSON.stringify(value)) as unknown as ts.TypeNode)\n : ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value));\n}\n\nfunction toTupleElement(ts: TypeScriptModule, element: IrTupleElement): ts.TypeNode {\n const type = toTypeNode(ts, element.type);\n if (element.isOptional) {\n return ts.factory.createOptionalTypeNode(type);\n }\n return element.isRest ? ts.factory.createRestTypeNode(type) : type;\n}\n\ntype LeafType = Extract<\n IrType,\n { kind: \"keyword\" | \"stringLiteral\" | \"numberLiteral\" | \"booleanLiteral\" | \"raw\" }\n>;\n\nfunction toLeafTypeNode(ts: TypeScriptModule, type: LeafType): ts.TypeNode {\n switch (type.kind) {\n case \"keyword\":\n return toKeywordType(ts, type.keyword);\n case \"stringLiteral\":\n return toStringLiteralType(ts, type.value, type.encoding ?? DEFAULT_STRING_ENCODING);\n case \"numberLiteral\":\n return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));\n case \"booleanLiteral\":\n return ts.factory.createLiteralTypeNode(\n type.value ? ts.factory.createTrue() : ts.factory.createFalse(),\n );\n case \"raw\":\n // A node read from TypeScript goes back as it was, so the TypeScript printer indents it.\n return (\n (type.origin as ts.TypeNode | undefined) ??\n (ts.factory.createIdentifier(type.text) as unknown as ts.TypeNode)\n );\n default:\n return assertNever(type);\n }\n}\n\nfunction toReferenceNode(\n ts: TypeScriptModule,\n type: Extract<IrType, { kind: \"reference\" }>,\n): ts.TypeNode {\n const typeArguments =\n type.typeArguments.length > 0\n ? type.typeArguments.map((argument) => toTypeNode(ts, argument))\n : undefined;\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(type.name), typeArguments);\n}\n\n/** Convert one IR type. */\nexport function toTypeNode(ts: TypeScriptModule, type: IrType): ts.TypeNode {\n const convert = (inner: IrType) => toTypeNode(ts, inner);\n const { factory } = ts;\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"raw\":\n return toLeafTypeNode(ts, type);\n case \"reference\":\n return toReferenceNode(ts, type);\n case \"array\":\n return factory.createArrayTypeNode(convert(type.element));\n case \"tuple\":\n return factory.createTupleTypeNode(\n type.elements.map((element) => toTupleElement(ts, element)),\n );\n case \"union\":\n return factory.createUnionTypeNode(type.types.map(convert));\n case \"intersection\":\n return factory.createIntersectionTypeNode(type.types.map(convert));\n case \"object\":\n return factory.createTypeLiteralNode(type.members.map((member) => toTypeElement(ts, member)));\n case \"indexedAccess\":\n return factory.createIndexedAccessTypeNode(convert(type.object), convert(type.index));\n case \"readonly\":\n return factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, convert(type.type));\n default:\n return assertNever(type);\n }\n}\n\n/** Attach IR comments to a node as synthetic leading comments, as the original does. */\nexport function withComments<T extends ts.Node>(\n ts: TypeScriptModule,\n node: T,\n comments: readonly IrComment[],\n): T {\n for (const comment of comments) {\n const kind =\n comment.kind === \"block\"\n ? ts.SyntaxKind.MultiLineCommentTrivia\n : ts.SyntaxKind.SingleLineCommentTrivia;\n ts.addSyntheticLeadingComment(node, kind, comment.text, true);\n }\n return node;\n}\n\nfunction toPropertyName(ts: TypeScriptModule, name: IrPropertyName): ts.PropertyName {\n switch (name.kind) {\n case \"identifier\":\n return ts.factory.createIdentifier(name.text);\n case \"string\":\n return ts.factory.createStringLiteral(name.value);\n case \"number\":\n return ts.factory.createNumericLiteral(name.text);\n default:\n return assertNever(name);\n }\n}\n\nfunction readonlyModifiers(ts: TypeScriptModule, isReadonly: boolean): ts.Modifier[] | undefined {\n return isReadonly ? [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)] : undefined;\n}\n\n/** Convert one property signature (for callbacks that receive a `ts.PropertySignature`). */\nexport function toPropertySignature(\n ts: TypeScriptModule,\n property: IrPropertySignature,\n): ts.PropertySignature {\n const questionToken = property.isOptional\n ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)\n : undefined;\n const signature = ts.factory.createPropertySignature(\n readonlyModifiers(ts, property.isReadonly),\n toPropertyName(ts, property.name),\n questionToken,\n toTypeNode(ts, property.type),\n );\n return withComments(ts, signature, property.comments);\n}\n\nexport function toTypeElement(ts: TypeScriptModule, member: IrMember): ts.TypeElement {\n if (member.kind === \"property\") {\n return toPropertySignature(ts, member);\n }\n const parameter = ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n member.parameterName,\n undefined,\n toTypeNode(ts, member.parameterType),\n );\n const signature = ts.factory.createIndexSignature(\n readonlyModifiers(ts, member.isReadonly),\n [parameter],\n toTypeNode(ts, member.type),\n );\n return withComments(ts, signature, member.comments);\n}\n"],"names":[],"mappings":";;;AAwBA,SAAS,WAAA,CAAY,IAAsB,OAAA,EAAgD;AACzF,EAAA,MAAM,KAAA,GAAiE;AAAA,IACrE,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,MAAA,EAAQ,GAAG,UAAA,CAAW,aAAA;AAAA,IACtB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,SAAA,EAAW,GAAG,UAAA,CAAW,gBAAA;AAAA,IACzB,OAAA,EAAS,GAAG,UAAA,CAAW,cAAA;AAAA,IACvB,KAAA,EAAO,GAAG,UAAA,CAAW;AAAA,GACvB;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB;AAEA,SAAS,aAAA,CAAc,IAAsB,OAAA,EAAiC;AAC5E,EAAA,OAAO,YAAY,MAAA,GACf,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,GAAG,OAAA,CAAQ,UAAA,EAAY,CAAA,GACxD,GAAG,OAAA,CAAQ,qBAAA,CAAsB,WAAA,CAAY,EAAA,EAAI,OAAO,CAAC,CAAA;AAC/D;AAKA,SAAS,kBAAA,CACP,IACA,KAAA,EAC8C;AAC9C,EAAA,OAAO,KAAA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AAA,EAAI,QAAA,CAAS,IAAI,CAAA;AAAA,IAChC,aAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,QAAA,CAAS,IAAI;AAAA,GAC9B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,QAAA,CAAS,QAAQ,CAAA;AACtD;AAEO,SAAS,aAAA,CAAc,IAAsB,MAAA,EAAkC;AACpF,EAAA,IAAI,MAAA,CAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,OAAO,mBAAA,CAAoB,IAAI,MAAM,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,CAAO,aAAA;AAAA,IACP,MAAA;AAAA,IACA,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,aAAa;AAAA,GACrC;AACA,EAAA,MAAM,SAAA,GAAY,GAAG,OAAA,CAAQ,oBAAA;AAAA,IAC3B,iBAAA,CAAkB,EAAA,EAAI,MAAA,CAAO,UAAU,CAAA;AAAA,IACvC,CAAC,SAAS,CAAA;AAAA,IACV,UAAA,CAAW,EAAA,EAAI,MAAA,CAAO,IAAI;AAAA,GAC5B;AACA,EAAA,OAAO,YAAA,CAAa,EAAA,EAAI,SAAA,EAAW,MAAA,CAAO,QAAQ,CAAA;AACpD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"print-typescript.cjs","sources":["../../../src/adapters/type-ast-bridge/print-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/** Options of `astToString` for the TypeScript printer, as in the original. */\nexport interface AstToStringOptions {\n fileName?: string;\n sourceText?: string;\n formatOptions?: ts.PrinterOptions;\n}\n\n/** Print TypeScript nodes as the original `astToString` did. */\nexport function printWithTypeScript(\n ts: TypeScriptModule,\n nodes: readonly ts.Node[],\n options?: AstToStringOptions,\n): string {\n const sourceFile = ts.createSourceFile(\n options?.fileName ?? \"openapi-ts.ts\",\n options?.sourceText ?? \"\",\n ts.ScriptTarget.ESNext,\n false,\n ts.ScriptKind.TS,\n );\n // The source file is new and not shared, so its statements can be set once.\n (sourceFile as { statements: ts.NodeArray<ts.Statement> }).statements =\n ts.factory.createNodeArray(nodes as readonly ts.Statement[]);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n ...options?.formatOptions,\n });\n return printer.printFile(sourceFile);\n}\n"],"names":[],"mappings":";;AAWO,SAAS,mBAAA,CACd,EAAA,EACA,KAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,aAAa,EAAA,CAAG,gBAAA;AAAA,IACpB,SAAS,QAAA,IAAY,eAAA;AAAA,IACrB,SAAS,UAAA,IAAc,EAAA;AAAA,IACvB,GAAG,YAAA,CAAa,MAAA;AAAA,IAChB,KAAA;AAAA,IACA,GAAG,UAAA,CAAW;AAAA,GAChB;AAEA,EAAC,UAAA,CAA0D,UAAA,GACzD,EAAA,CAAG,OAAA,CAAQ,gBAAgB,KAAgC,CAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,GAAG,aAAA,CAAc;AAAA,IAC/B,OAAA,EAAS,GAAG,WAAA,CAAY,QAAA;AAAA,IACxB,cAAA,EAAgB,KAAA;AAAA,IAChB,GAAG,OAAA,EAAS;AAAA,GACb,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,UAAU,UAAU,CAAA;AACrC;;"}
1
+ {"version":3,"file":"print-typescript.cjs","sources":["../../../src/adapters/type-ast-bridge/print-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport type { ts as CompilerTypes } from \"./typescript-types.js\";\n\n/** Options of `astToString` for the TypeScript printer, as in the original. */\nexport interface AstToStringOptions {\n fileName?: string;\n sourceText?: string;\n /** The installed compiler's printer options (ADR-032: named without `ts.PrinterOptions`). */\n formatOptions?: CompilerTypes.PrinterOptions;\n}\n\n/** Print TypeScript nodes as the original `astToString` did. */\nexport function printWithTypeScript(\n ts: TypeScriptModule,\n nodes: readonly ts.Node[],\n options?: AstToStringOptions,\n): string {\n const sourceFile = ts.createSourceFile(\n options?.fileName ?? \"openapi-ts.ts\",\n options?.sourceText ?? \"\",\n ts.ScriptTarget.ESNext,\n false,\n ts.ScriptKind.TS,\n );\n // The source file is new and not shared, so its statements can be set once.\n (sourceFile as { statements: ts.NodeArray<ts.Statement> }).statements =\n ts.factory.createNodeArray(nodes as readonly ts.Statement[]);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n ...options?.formatOptions,\n });\n return printer.printFile(sourceFile);\n}\n"],"names":[],"mappings":";;AAaO,SAAS,mBAAA,CACd,EAAA,EACA,KAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,aAAa,EAAA,CAAG,gBAAA;AAAA,IACpB,SAAS,QAAA,IAAY,eAAA;AAAA,IACrB,SAAS,UAAA,IAAc,EAAA;AAAA,IACvB,GAAG,YAAA,CAAa,MAAA;AAAA,IAChB,KAAA;AAAA,IACA,GAAG,UAAA,CAAW;AAAA,GAChB;AAEA,EAAC,UAAA,CAA0D,UAAA,GACzD,EAAA,CAAG,OAAA,CAAQ,gBAAgB,KAAgC,CAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,GAAG,aAAA,CAAc;AAAA,IAC/B,OAAA,EAAS,GAAG,WAAA,CAAY,QAAA;AAAA,IACxB,cAAA,EAAgB,KAAA;AAAA,IAChB,GAAG,OAAA,EAAS;AAAA,GACb,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,UAAU,UAAU,CAAA;AACrC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"print-typescript.mjs","sources":["../../../src/adapters/type-ast-bridge/print-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\n\n/** Options of `astToString` for the TypeScript printer, as in the original. */\nexport interface AstToStringOptions {\n fileName?: string;\n sourceText?: string;\n formatOptions?: ts.PrinterOptions;\n}\n\n/** Print TypeScript nodes as the original `astToString` did. */\nexport function printWithTypeScript(\n ts: TypeScriptModule,\n nodes: readonly ts.Node[],\n options?: AstToStringOptions,\n): string {\n const sourceFile = ts.createSourceFile(\n options?.fileName ?? \"openapi-ts.ts\",\n options?.sourceText ?? \"\",\n ts.ScriptTarget.ESNext,\n false,\n ts.ScriptKind.TS,\n );\n // The source file is new and not shared, so its statements can be set once.\n (sourceFile as { statements: ts.NodeArray<ts.Statement> }).statements =\n ts.factory.createNodeArray(nodes as readonly ts.Statement[]);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n ...options?.formatOptions,\n });\n return printer.printFile(sourceFile);\n}\n"],"names":[],"mappings":"AAWO,SAAS,mBAAA,CACd,EAAA,EACA,KAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,aAAa,EAAA,CAAG,gBAAA;AAAA,IACpB,SAAS,QAAA,IAAY,eAAA;AAAA,IACrB,SAAS,UAAA,IAAc,EAAA;AAAA,IACvB,GAAG,YAAA,CAAa,MAAA;AAAA,IAChB,KAAA;AAAA,IACA,GAAG,UAAA,CAAW;AAAA,GAChB;AAEA,EAAC,UAAA,CAA0D,UAAA,GACzD,EAAA,CAAG,OAAA,CAAQ,gBAAgB,KAAgC,CAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,GAAG,aAAA,CAAc;AAAA,IAC/B,OAAA,EAAS,GAAG,WAAA,CAAY,QAAA;AAAA,IACxB,cAAA,EAAgB,KAAA;AAAA,IAChB,GAAG,OAAA,EAAS;AAAA,GACb,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,UAAU,UAAU,CAAA;AACrC;;"}
1
+ {"version":3,"file":"print-typescript.mjs","sources":["../../../src/adapters/type-ast-bridge/print-typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport type { ts as CompilerTypes } from \"./typescript-types.js\";\n\n/** Options of `astToString` for the TypeScript printer, as in the original. */\nexport interface AstToStringOptions {\n fileName?: string;\n sourceText?: string;\n /** The installed compiler's printer options (ADR-032: named without `ts.PrinterOptions`). */\n formatOptions?: CompilerTypes.PrinterOptions;\n}\n\n/** Print TypeScript nodes as the original `astToString` did. */\nexport function printWithTypeScript(\n ts: TypeScriptModule,\n nodes: readonly ts.Node[],\n options?: AstToStringOptions,\n): string {\n const sourceFile = ts.createSourceFile(\n options?.fileName ?? \"openapi-ts.ts\",\n options?.sourceText ?? \"\",\n ts.ScriptTarget.ESNext,\n false,\n ts.ScriptKind.TS,\n );\n // The source file is new and not shared, so its statements can be set once.\n (sourceFile as { statements: ts.NodeArray<ts.Statement> }).statements =\n ts.factory.createNodeArray(nodes as readonly ts.Statement[]);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n ...options?.formatOptions,\n });\n return printer.printFile(sourceFile);\n}\n"],"names":[],"mappings":"AAaO,SAAS,mBAAA,CACd,EAAA,EACA,KAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,aAAa,EAAA,CAAG,gBAAA;AAAA,IACpB,SAAS,QAAA,IAAY,eAAA;AAAA,IACrB,SAAS,UAAA,IAAc,EAAA;AAAA,IACvB,GAAG,YAAA,CAAa,MAAA;AAAA,IAChB,KAAA;AAAA,IACA,GAAG,UAAA,CAAW;AAAA,GAChB;AAEA,EAAC,UAAA,CAA0D,UAAA,GACzD,EAAA,CAAG,OAAA,CAAQ,gBAAgB,KAAgC,CAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,GAAG,aAAA,CAAc;AAAA,IAC/B,OAAA,EAAS,GAAG,WAAA,CAAY,QAAA;AAAA,IACxB,cAAA,EAAgB,KAAA;AAAA,IAChB,GAAG,OAAA,EAAS;AAAA,GACb,CAAA;AACD,EAAA,OAAO,OAAA,CAAQ,UAAU,UAAU,CAAA;AACrC;;"}
@@ -48,18 +48,24 @@ function fromReference(ts, node) {
48
48
  const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));
49
49
  return { kind: "reference", name: ts.idText(node.typeName), typeArguments };
50
50
  }
51
+ function fromTupleElement(ts, element, convert) {
52
+ if (ts.isRestTypeNode(element)) {
53
+ return { type: convert(element.type), isRest: true, isOptional: false };
54
+ }
55
+ if (ts.isOptionalTypeNode(element)) {
56
+ return { type: fromTypeNode(ts, element.type, element), isRest: false, isOptional: true };
57
+ }
58
+ return { type: convert(element), isRest: false, isOptional: false };
59
+ }
51
60
  function fromTuple(ts, node) {
52
- const isPlain = node.elements.every(
53
- (element) => !ts.isNamedTupleMember(element) && !ts.isOptionalTypeNode(element)
54
- );
55
- if (!isPlain) {
61
+ if (node.elements.some((element) => ts.isNamedTupleMember(element))) {
56
62
  return null;
57
63
  }
58
64
  const convert = childrenOf(ts, node);
59
- const elements = node.elements.map(
60
- (element) => ts.isRestTypeNode(element) ? { type: convert(element.type), isRest: true } : { type: convert(element), isRest: false }
61
- );
62
- return { kind: "tuple", elements };
65
+ return {
66
+ kind: "tuple",
67
+ elements: node.elements.map((element) => fromTupleElement(ts, element, convert))
68
+ };
63
69
  }
64
70
  function fromComments(ts, node) {
65
71
  const comments = ts.getSyntheticLeadingComments(node) ?? [];
@@ -179,7 +185,7 @@ function isFactoryParenthesis(ts, inner, parent) {
179
185
  return false;
180
186
  }
181
187
  const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);
182
- const isPostfixOrReadonlyParent = ts.isArrayTypeNode(parent) || ts.isIndexedAccessTypeNode(parent) || ts.isTypeOperatorNode(parent);
188
+ const isPostfixOrReadonlyParent = ts.isArrayTypeNode(parent) || ts.isIndexedAccessTypeNode(parent) || ts.isOptionalTypeNode(parent) || ts.isTypeOperatorNode(parent);
183
189
  if (isPostfixOrReadonlyParent) {
184
190
  return isComposite || ts.isTypeOperatorNode(inner);
185
191
  }
@@ -1 +1 @@
1
- {"version":3,"file":"typescript-to-ir.cjs","sources":["../../../src/adapters/type-ast-bridge/typescript-to-ir.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { irRaw } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport { asRaw, isIrNode, needsPrintedText } from \"./typescript-raw-text.js\";\n\n/**\n * Read TypeScript type nodes from user callbacks into IR (ADR-004, decision 3). Synthesized nodes\n * are mapped by structure. Anything the IR cannot express exactly is printed with the TypeScript\n * printer, the way the original output it, and kept as a `raw` node: parsed nodes, nodes with\n * comments, explicit parentheses, single-quoted strings, numbers not in canonical form, and syntax\n * the IR does not model. Every function takes the user's TypeScript module (ADR-004, decision 4):\n * `SyntaxKind` numbers differ between versions, so a node is read with the module that made it.\n */\n\nfunction keywordOf(ts: TypeScriptModule, kind: ts.SyntaxKind): IrKeyword | undefined {\n const keywords: ReadonlyMap<ts.SyntaxKind, IrKeyword> = new Map([\n [ts.SyntaxKind.StringKeyword, \"string\"],\n [ts.SyntaxKind.NumberKeyword, \"number\"],\n [ts.SyntaxKind.BooleanKeyword, \"boolean\"],\n [ts.SyntaxKind.UndefinedKeyword, \"undefined\"],\n [ts.SyntaxKind.UnknownKeyword, \"unknown\"],\n [ts.SyntaxKind.NeverKeyword, \"never\"],\n ]);\n return keywords.get(kind);\n}\n\nfunction isCanonicalNumber(text: string): boolean {\n return String(Number(text)) === text;\n}\n\nfunction fromNumber(ts: TypeScriptModule, literal: ts.Expression): IrType | null {\n if (ts.isNumericLiteral(literal)) {\n return isCanonicalNumber(literal.text)\n ? { kind: \"numberLiteral\", value: Number(literal.text) }\n : null;\n }\n const isNegative =\n ts.isPrefixUnaryExpression(literal) &&\n literal.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(literal.operand) &&\n isCanonicalNumber(literal.operand.text) &&\n Number(literal.operand.text) !== 0;\n return isNegative\n ? { kind: \"numberLiteral\", value: -Number((literal.operand as ts.NumericLiteral).text) }\n : null;\n}\n\nfunction fromLiteral(ts: TypeScriptModule, node: ts.LiteralTypeNode): IrType | null {\n const { literal } = node;\n if (ts.isStringLiteral(literal)) {\n const isSingleQuoted = (literal as { singleQuote?: boolean }).singleQuote === true;\n return isSingleQuoted\n ? null\n : { kind: \"stringLiteral\", value: literal.text, encoding: \"escaped\" };\n }\n if (literal.kind === ts.SyntaxKind.NullKeyword) {\n return { kind: \"keyword\", keyword: \"null\" };\n }\n if (literal.kind === ts.SyntaxKind.TrueKeyword || literal.kind === ts.SyntaxKind.FalseKeyword) {\n return { kind: \"booleanLiteral\", value: literal.kind === ts.SyntaxKind.TrueKeyword };\n }\n return fromNumber(ts, literal);\n}\n\n/** Converts the children of one node, which becomes their parent. */\nfunction childrenOf(ts: TypeScriptModule, parent: ts.Node): (child: ts.TypeNode) => IrType {\n return (child) => fromTypeNode(ts, child, parent);\n}\n\nfunction fromReference(ts: TypeScriptModule, node: ts.TypeReferenceNode): IrType | null {\n if (!ts.isIdentifier(node.typeName)) {\n return null;\n }\n const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));\n return { kind: \"reference\", name: ts.idText(node.typeName), typeArguments };\n}\n\nfunction fromTuple(ts: TypeScriptModule, node: ts.TupleTypeNode): IrType | null {\n const isPlain = node.elements.every(\n (element) => !ts.isNamedTupleMember(element) && !ts.isOptionalTypeNode(element),\n );\n if (!isPlain) {\n return null;\n }\n const convert = childrenOf(ts, node);\n const elements = node.elements.map((element) =>\n ts.isRestTypeNode(element)\n ? { type: convert(element.type), isRest: true }\n : { type: convert(element), isRest: false },\n );\n return { kind: \"tuple\", elements };\n}\n\n/**\n * Leading comments in order, or null when the IR cannot hold them: trailing comments, or a\n * comment without a line break after it (the IR always writes one).\n */\nfunction fromComments(ts: TypeScriptModule, node: ts.Node): IrComment[] | null {\n const comments = ts.getSyntheticLeadingComments(node) ?? [];\n const hasTrailing = (ts.getSyntheticTrailingComments(node)?.length ?? 0) > 0;\n if (hasTrailing || comments.some((comment) => !comment.hasTrailingNewLine)) {\n return null;\n }\n return comments.map((comment) => ({\n kind: comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? \"block\" : \"line\",\n text: comment.text,\n }));\n}\n\nfunction fromPropertyName(ts: TypeScriptModule, name: ts.PropertyName): IrPropertyName | null {\n if (ts.isIdentifier(name)) {\n return { kind: \"identifier\", text: ts.idText(name) };\n }\n if (ts.isStringLiteral(name) && (name as { singleQuote?: boolean }).singleQuote !== true) {\n return { kind: \"string\", value: name.text };\n }\n return ts.isNumericLiteral(name) ? { kind: \"number\", text: name.text } : null;\n}\n\n/** Only `readonly` is modeled; any other modifier makes the member unreadable as IR. */\nfunction readonlyFlag(ts: TypeScriptModule, node: ts.TypeElement): boolean | null {\n const modifiers = ts.canHaveModifiers(node) ? (ts.getModifiers(node) ?? []) : [];\n const isOnlyReadonly = modifiers.every(\n (modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword,\n );\n return isOnlyReadonly ? modifiers.length > 0 : null;\n}\n\n/** A property signature as IR, or null when it uses syntax the IR does not model. */\nexport function fromPropertySignature(\n ts: TypeScriptModule,\n node: ts.PropertySignature,\n): IrPropertySignature | null {\n const name = fromPropertyName(ts, node.name);\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n if (name === null || comments === null || isReadonly === null || node.type === undefined) {\n return null;\n }\n return {\n kind: \"property\",\n name,\n type: fromTypeNode(ts, node.type, node),\n isOptional: node.questionToken !== undefined,\n isReadonly,\n comments,\n };\n}\n\nfunction fromIndexSignature(\n ts: TypeScriptModule,\n node: ts.IndexSignatureDeclaration,\n): IrMember | null {\n const [parameter, ...others] = node.parameters;\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n const isPlain =\n parameter?.type !== undefined && ts.isIdentifier(parameter.name) && others.length === 0;\n if (!isPlain || comments === null || isReadonly === null) {\n return null;\n }\n return {\n kind: \"indexSignature\",\n parameterName: ts.idText(parameter.name as ts.Identifier),\n parameterType: fromTypeNode(ts, parameter.type as ts.TypeNode, node),\n type: fromTypeNode(ts, node.type, node),\n isReadonly,\n comments,\n };\n}\n\nfunction fromMember(ts: TypeScriptModule, member: ts.TypeElement): IrMember | null {\n if (member.pos >= 0) {\n return null;\n }\n if (ts.isPropertySignature(member)) {\n return fromPropertySignature(ts, member);\n }\n return ts.isIndexSignatureDeclaration(member) ? fromIndexSignature(ts, member) : null;\n}\n\nfunction fromTypeLiteral(ts: TypeScriptModule, node: ts.TypeLiteralNode): IrType | null {\n const members = node.members.map((member) => fromMember(ts, member));\n const isReadable = members.every((member) => member !== null);\n return isReadable ? { kind: \"object\", members: members as IrMember[] } : null;\n}\n\nfunction fromComposite(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const convert = childrenOf(ts, node);\n if (ts.isArrayTypeNode(node)) {\n return { kind: \"array\", element: convert(node.elementType) };\n }\n if (ts.isUnionTypeNode(node)) {\n return { kind: \"union\", types: node.types.map(convert) };\n }\n if (ts.isIntersectionTypeNode(node)) {\n return { kind: \"intersection\", types: node.types.map(convert) };\n }\n if (ts.isIndexedAccessTypeNode(node)) {\n return {\n kind: \"indexedAccess\",\n object: convert(node.objectType),\n index: convert(node.indexType),\n };\n }\n if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) {\n return { kind: \"readonly\", type: convert(node.type) };\n }\n return ts.isTypeLiteralNode(node) ? fromTypeLiteral(ts, node) : null;\n}\n\nfunction fromStructure(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const keyword = keywordOf(ts, node.kind);\n if (keyword !== undefined) {\n return { kind: \"keyword\", keyword };\n }\n if (ts.isIdentifier(node)) {\n // The original writes JSON string literals and some references as bare identifiers.\n return irRaw(ts.idText(node));\n }\n if (ts.isLiteralTypeNode(node)) {\n return fromLiteral(ts, node);\n }\n if (ts.isTypeReferenceNode(node)) {\n return fromReference(ts, node);\n }\n return ts.isTupleTypeNode(node) ? fromTuple(ts, node) : fromComposite(ts, node);\n}\n\n/**\n * Whether the factory's parenthesizer put these parentheses in (same rules as the IR printer):\n * unions, intersections and `readonly` types as array elements, indexed objects and `readonly`\n * operands; unions and intersections as members of other unions or intersections.\n */\nfunction isFactoryParenthesis(\n ts: TypeScriptModule,\n inner: ts.TypeNode,\n parent: ts.Node | undefined,\n): boolean {\n if (parent === undefined) {\n return false;\n }\n const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);\n const isPostfixOrReadonlyParent =\n ts.isArrayTypeNode(parent) ||\n ts.isIndexedAccessTypeNode(parent) ||\n ts.isTypeOperatorNode(parent);\n if (isPostfixOrReadonlyParent) {\n return isComposite || ts.isTypeOperatorNode(inner);\n }\n const isCompositeParent = ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent);\n return isCompositeParent && isComposite;\n}\n\n/**\n * Convert a type node. `parent` is the node that contains it: synthesized nodes have no `parent`\n * link, and it is needed to tell parentheses the factory inserted from ones the user wrote.\n */\nexport function fromTypeNode(ts: TypeScriptModule, node: ts.TypeNode, parent?: ts.Node): IrType {\n if (isIrNode(node)) {\n return node;\n }\n if (needsPrintedText(ts, node)) {\n return asRaw(ts, node);\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return isFactoryParenthesis(ts, node.type, parent)\n ? fromTypeNode(ts, node.type, parent)\n : asRaw(ts, node);\n }\n return fromStructure(ts, node) ?? asRaw(ts, node);\n}\n"],"names":["irRaw","isIrNode","needsPrintedText","asRaw"],"mappings":";;;;;AAsBA,SAAS,SAAA,CAAU,IAAsB,IAAA,EAA4C;AACnF,EAAA,MAAM,QAAA,uBAAsD,GAAA,CAAI;AAAA,IAC9D,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,c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,MAAM,CAAA,GAC7C,YAAA,CAAa,EAAA,EAAI,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA,GAClCA,uBAAA,CAAM,IAAI,IAAI,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAc,EAAA,EAAI,IAAI,CAAA,IAAKA,uBAAA,CAAM,IAAI,IAAI,CAAA;AAClD;;;"}
1
+ {"version":3,"file":"typescript-to-ir.cjs","sources":["../../../src/adapters/type-ast-bridge/typescript-to-ir.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { irRaw } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport { asRaw, isIrNode, needsPrintedText } from \"./typescript-raw-text.js\";\n\n/**\n * Read TypeScript type nodes from user callbacks into IR (ADR-004, decision 3). Synthesized nodes\n * are mapped by structure. Anything the IR cannot express exactly is printed with the TypeScript\n * printer, the way the original output it, and kept as a `raw` node: parsed nodes, nodes with\n * comments, explicit parentheses, single-quoted strings, numbers not in canonical form, and syntax\n * the IR does not model. Every function takes the user's TypeScript module (ADR-004, decision 4):\n * `SyntaxKind` numbers differ between versions, so a node is read with the module that made it.\n */\n\nfunction keywordOf(ts: TypeScriptModule, kind: ts.SyntaxKind): IrKeyword | undefined {\n const keywords: ReadonlyMap<ts.SyntaxKind, IrKeyword> = new Map([\n [ts.SyntaxKind.StringKeyword, \"string\"],\n [ts.SyntaxKind.NumberKeyword, \"number\"],\n [ts.SyntaxKind.BooleanKeyword, \"boolean\"],\n [ts.SyntaxKind.UndefinedKeyword, \"undefined\"],\n [ts.SyntaxKind.UnknownKeyword, \"unknown\"],\n [ts.SyntaxKind.NeverKeyword, \"never\"],\n ]);\n return keywords.get(kind);\n}\n\nfunction isCanonicalNumber(text: string): boolean {\n return String(Number(text)) === text;\n}\n\nfunction fromNumber(ts: TypeScriptModule, literal: ts.Expression): IrType | null {\n if (ts.isNumericLiteral(literal)) {\n return isCanonicalNumber(literal.text)\n ? { kind: \"numberLiteral\", value: Number(literal.text) }\n : null;\n }\n const isNegative =\n ts.isPrefixUnaryExpression(literal) &&\n literal.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(literal.operand) &&\n isCanonicalNumber(literal.operand.text) &&\n Number(literal.operand.text) !== 0;\n return isNegative\n ? { kind: \"numberLiteral\", value: -Number((literal.operand as ts.NumericLiteral).text) }\n : null;\n}\n\nfunction fromLiteral(ts: TypeScriptModule, node: ts.LiteralTypeNode): IrType | null {\n const { literal } = node;\n if (ts.isStringLiteral(literal)) {\n const isSingleQuoted = (literal as { singleQuote?: boolean }).singleQuote === true;\n return isSingleQuoted\n ? null\n : { kind: \"stringLiteral\", value: literal.text, encoding: \"escaped\" };\n }\n if (literal.kind === ts.SyntaxKind.NullKeyword) {\n return { kind: \"keyword\", keyword: \"null\" };\n }\n if (literal.kind === ts.SyntaxKind.TrueKeyword || literal.kind === ts.SyntaxKind.FalseKeyword) {\n return { kind: \"booleanLiteral\", value: literal.kind === ts.SyntaxKind.TrueKeyword };\n }\n return fromNumber(ts, literal);\n}\n\n/** Converts the children of one node, which becomes their parent. */\nfunction childrenOf(ts: TypeScriptModule, parent: ts.Node): (child: ts.TypeNode) => IrType {\n return (child) => fromTypeNode(ts, child, parent);\n}\n\nfunction fromReference(ts: TypeScriptModule, node: ts.TypeReferenceNode): IrType | null {\n if (!ts.isIdentifier(node.typeName)) {\n return null;\n }\n const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));\n return { kind: \"reference\", name: ts.idText(node.typeName), typeArguments };\n}\n\nfunction fromTupleElement(\n ts: TypeScriptModule,\n element: ts.TypeNode,\n convert: (node: ts.TypeNode) => IrType,\n): IrTupleElement {\n if (ts.isRestTypeNode(element)) {\n return { type: convert(element.type), isRest: true, isOptional: false };\n }\n if (ts.isOptionalTypeNode(element)) {\n // The `?` is the parent of the type: it decides which parentheses the factory put in.\n return { type: fromTypeNode(ts, element.type, element), isRest: false, isOptional: true };\n }\n return { type: convert(element), isRest: false, isOptional: false };\n}\n\n/** A tuple of plain, rest and optional elements; one with named members stays text. */\nfunction fromTuple(ts: TypeScriptModule, node: ts.TupleTypeNode): IrType | null {\n if (node.elements.some((element) => ts.isNamedTupleMember(element))) {\n return null;\n }\n const convert = childrenOf(ts, node);\n return {\n kind: \"tuple\",\n elements: node.elements.map((element) => fromTupleElement(ts, element, convert)),\n };\n}\n\n/**\n * Leading comments in order, or null when the IR cannot hold them: trailing comments, or a\n * comment without a line break after it (the IR always writes one).\n */\nfunction fromComments(ts: TypeScriptModule, node: ts.Node): IrComment[] | null {\n const comments = ts.getSyntheticLeadingComments(node) ?? [];\n const hasTrailing = (ts.getSyntheticTrailingComments(node)?.length ?? 0) > 0;\n if (hasTrailing || comments.some((comment) => !comment.hasTrailingNewLine)) {\n return null;\n }\n return comments.map((comment) => ({\n kind: comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? \"block\" : \"line\",\n text: comment.text,\n }));\n}\n\nfunction fromPropertyName(ts: TypeScriptModule, name: ts.PropertyName): IrPropertyName | null {\n if (ts.isIdentifier(name)) {\n return { kind: \"identifier\", text: ts.idText(name) };\n }\n if (ts.isStringLiteral(name) && (name as { singleQuote?: boolean }).singleQuote !== true) {\n return { kind: \"string\", value: name.text };\n }\n return ts.isNumericLiteral(name) ? { kind: \"number\", text: name.text } : null;\n}\n\n/** Only `readonly` is modeled; any other modifier makes the member unreadable as IR. */\nfunction readonlyFlag(ts: TypeScriptModule, node: ts.TypeElement): boolean | null {\n const modifiers = ts.canHaveModifiers(node) ? (ts.getModifiers(node) ?? []) : [];\n const isOnlyReadonly = modifiers.every(\n (modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword,\n );\n return isOnlyReadonly ? modifiers.length > 0 : null;\n}\n\n/** A property signature as IR, or null when it uses syntax the IR does not model. */\nexport function fromPropertySignature(\n ts: TypeScriptModule,\n node: ts.PropertySignature,\n): IrPropertySignature | null {\n const name = fromPropertyName(ts, node.name);\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n if (name === null || comments === null || isReadonly === null || node.type === undefined) {\n return null;\n }\n return {\n kind: \"property\",\n name,\n type: fromTypeNode(ts, node.type, node),\n isOptional: node.questionToken !== undefined,\n isReadonly,\n comments,\n };\n}\n\nfunction fromIndexSignature(\n ts: TypeScriptModule,\n node: ts.IndexSignatureDeclaration,\n): IrMember | null {\n const [parameter, ...others] = node.parameters;\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n const isPlain =\n parameter?.type !== undefined && ts.isIdentifier(parameter.name) && others.length === 0;\n if (!isPlain || comments === null || isReadonly === null) {\n return null;\n }\n return {\n kind: \"indexSignature\",\n parameterName: ts.idText(parameter.name as ts.Identifier),\n parameterType: fromTypeNode(ts, parameter.type as ts.TypeNode, node),\n type: fromTypeNode(ts, node.type, node),\n isReadonly,\n comments,\n };\n}\n\nfunction fromMember(ts: TypeScriptModule, member: ts.TypeElement): IrMember | null {\n if (member.pos >= 0) {\n return null;\n }\n if (ts.isPropertySignature(member)) {\n return fromPropertySignature(ts, member);\n }\n return ts.isIndexSignatureDeclaration(member) ? fromIndexSignature(ts, member) : null;\n}\n\nfunction fromTypeLiteral(ts: TypeScriptModule, node: ts.TypeLiteralNode): IrType | null {\n const members = node.members.map((member) => fromMember(ts, member));\n const isReadable = members.every((member) => member !== null);\n return isReadable ? { kind: \"object\", members: members as IrMember[] } : null;\n}\n\nfunction fromComposite(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const convert = childrenOf(ts, node);\n if (ts.isArrayTypeNode(node)) {\n return { kind: \"array\", element: convert(node.elementType) };\n }\n if (ts.isUnionTypeNode(node)) {\n return { kind: \"union\", types: node.types.map(convert) };\n }\n if (ts.isIntersectionTypeNode(node)) {\n return { kind: \"intersection\", types: node.types.map(convert) };\n }\n if (ts.isIndexedAccessTypeNode(node)) {\n return {\n kind: \"indexedAccess\",\n object: convert(node.objectType),\n index: convert(node.indexType),\n };\n }\n if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) {\n return { kind: \"readonly\", type: convert(node.type) };\n }\n return ts.isTypeLiteralNode(node) ? fromTypeLiteral(ts, node) : null;\n}\n\nfunction fromStructure(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const keyword = keywordOf(ts, node.kind);\n if (keyword !== undefined) {\n return { kind: \"keyword\", keyword };\n }\n if (ts.isIdentifier(node)) {\n // The original writes JSON string literals and some references as bare identifiers.\n return irRaw(ts.idText(node));\n }\n if (ts.isLiteralTypeNode(node)) {\n return fromLiteral(ts, node);\n }\n if (ts.isTypeReferenceNode(node)) {\n return fromReference(ts, node);\n }\n return ts.isTupleTypeNode(node) ? fromTuple(ts, node) : fromComposite(ts, node);\n}\n\n/**\n * Whether the factory's parenthesizer put these parentheses in (same rules as the IR printer):\n * unions, intersections and `readonly` types as array elements, indexed objects, optional tuple\n * elements and `readonly` operands; unions and intersections as members of other unions or\n * intersections.\n */\nfunction isFactoryParenthesis(\n ts: TypeScriptModule,\n inner: ts.TypeNode,\n parent: ts.Node | undefined,\n): boolean {\n if (parent === undefined) {\n return false;\n }\n const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);\n const isPostfixOrReadonlyParent =\n ts.isArrayTypeNode(parent) ||\n ts.isIndexedAccessTypeNode(parent) ||\n ts.isOptionalTypeNode(parent) ||\n ts.isTypeOperatorNode(parent);\n if (isPostfixOrReadonlyParent) {\n return isComposite || ts.isTypeOperatorNode(inner);\n }\n const isCompositeParent = ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent);\n return isCompositeParent && isComposite;\n}\n\n/**\n * Convert a type node. `parent` is the node that contains it: synthesized nodes have no `parent`\n * link, and it is needed to tell parentheses the factory inserted from ones the user wrote.\n */\nexport function fromTypeNode(ts: TypeScriptModule, node: ts.TypeNode, parent?: ts.Node): IrType {\n if (isIrNode(node)) {\n return node;\n }\n if (needsPrintedText(ts, node)) {\n return asRaw(ts, node);\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return isFactoryParenthesis(ts, node.type, parent)\n ? fromTypeNode(ts, node.type, parent)\n : asRaw(ts, node);\n }\n return fromStructure(ts, node) ?? asRaw(ts, node);\n}\n"],"names":["irRaw","isIrNode","needsPrintedText","asRaw"],"mappings":";;;;;AAuBA,SAAS,SAAA,CAAU,IAAsB,IAAA,EAA4C;AACnF,EAAA,MAAM,QAAA,uBAAsD,GAAA,CAAI;AAAA,IAC9D,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,cAAA,EAAgB,SAAS,CAAA;AAAA,IACxC,CAAC,EAAA,CAAG,UAAA,CAAW,gBAAA,EAAkB,WAAW,CAAA;AAAA,IAC5C,CAAC,EAAA,CAAG,UAAA,CAAW,cAAA,EAAgB,SAAS,CAAA;AAAA,IACxC,CAAC,EAAA,CAAG,UAAA,CAAW,YAAA,EAAc,OAAO;AAAA,GACrC,CAAA;AACD,EAAA,OAAO,QAAA,CAAS,IAAI,IAAI,CAAA;AAC1B;AAEA,SAAS,kBAAkB,IAAA,EAAuB;AAChD,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,IAAI,CAAC,CAAA,KAAM,IAAA;AAClC;AAEA,SAAS,UAAA,CAAW,IAAsB,OAAA,EAAuC;AAC/E,EAAA,IAAI,EAAA,CAAG,gBAAA,CAAiB,OAAO,CAAA,EAAG;AAChC,IAAA,OAAO,iBAAA,CAAkB,OAAA,CAAQ,IAAI,CAAA,GACjC,EAAE,IAAA,EAAM,eAAA,EAAiB,KAAA,EAAO,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAE,GACrD,IAAA;AA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CAAA,IAAK,EAAA,CAAG,uBAAuB,KAAK,CAAA;AAChF,EAAA,MAAM,yBAAA,GACJ,EAAA,CAAG,eAAA,CAAgB,MAAM,KACzB,EAAA,CAAG,uBAAA,CAAwB,MAAM,CAAA,IACjC,GAAG,kBAAA,CAAmB,MAAM,CAAA,IAC5B,EAAA,CAAG,mBAAmB,MAAM,CAAA;AAC9B,EAAA,IAAI,yBAAA,EAA2B;AAC7B,IAAA,OAAO,WAAA,IAAe,EAAA,CAAG,kBAAA,CAAmB,KAAK,CAAA;AAAA,EACnD;AACA,EAAA,MAAM,oBAAoB,EAAA,CAAG,eAAA,CAAgB,MAAM,CAAA,IAAK,EAAA,CAAG,uBAAuB,MAAM,CAAA;AACxF,EAAA,OAAO,iBAAA,IAAqB,WAAA;AAC9B;AAMO,SAAS,YAAA,CAAa,EAAA,EAAsB,IAAA,EAAmB,MAAA,EAA0B;AAC9F,EAAA,IAAIC,0BAAA,CAAS,IAAI,CAAA,EAAG;AAClB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAIC,kCAAA,CAAiB,EAAA,EAAI,IAAI,CAAA,EAAG;AAC9B,IAAA,OAAOC,uBAAA,CAAM,IAAI,IAAI,CAAA;AAAA,EACvB;AACA,EAAA,IAAI,EAAA,CAAG,uBAAA,CAAwB,IAAI,CAAA,EAAG;AACpC,IAAA,OAAO,oBAAA,CAAqB,EAAA,EAAI,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA,GAC7C,YAAA,CAAa,EAAA,EAAI,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA,GAClCA,uBAAA,CAAM,IAAI,IAAI,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAc,EAAA,EAAI,IAAI,CAAA,IAAKA,uBAAA,CAAM,IAAI,IAAI,CAAA;AAClD;;;"}
@@ -46,18 +46,24 @@ function fromReference(ts, node) {
46
46
  const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));
47
47
  return { kind: "reference", name: ts.idText(node.typeName), typeArguments };
48
48
  }
49
+ function fromTupleElement(ts, element, convert) {
50
+ if (ts.isRestTypeNode(element)) {
51
+ return { type: convert(element.type), isRest: true, isOptional: false };
52
+ }
53
+ if (ts.isOptionalTypeNode(element)) {
54
+ return { type: fromTypeNode(ts, element.type, element), isRest: false, isOptional: true };
55
+ }
56
+ return { type: convert(element), isRest: false, isOptional: false };
57
+ }
49
58
  function fromTuple(ts, node) {
50
- const isPlain = node.elements.every(
51
- (element) => !ts.isNamedTupleMember(element) && !ts.isOptionalTypeNode(element)
52
- );
53
- if (!isPlain) {
59
+ if (node.elements.some((element) => ts.isNamedTupleMember(element))) {
54
60
  return null;
55
61
  }
56
62
  const convert = childrenOf(ts, node);
57
- const elements = node.elements.map(
58
- (element) => ts.isRestTypeNode(element) ? { type: convert(element.type), isRest: true } : { type: convert(element), isRest: false }
59
- );
60
- return { kind: "tuple", elements };
63
+ return {
64
+ kind: "tuple",
65
+ elements: node.elements.map((element) => fromTupleElement(ts, element, convert))
66
+ };
61
67
  }
62
68
  function fromComments(ts, node) {
63
69
  const comments = ts.getSyntheticLeadingComments(node) ?? [];
@@ -177,7 +183,7 @@ function isFactoryParenthesis(ts, inner, parent) {
177
183
  return false;
178
184
  }
179
185
  const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);
180
- const isPostfixOrReadonlyParent = ts.isArrayTypeNode(parent) || ts.isIndexedAccessTypeNode(parent) || ts.isTypeOperatorNode(parent);
186
+ const isPostfixOrReadonlyParent = ts.isArrayTypeNode(parent) || ts.isIndexedAccessTypeNode(parent) || ts.isOptionalTypeNode(parent) || ts.isTypeOperatorNode(parent);
181
187
  if (isPostfixOrReadonlyParent) {
182
188
  return isComposite || ts.isTypeOperatorNode(inner);
183
189
  }
@@ -1 +1 @@
1
- {"version":3,"file":"typescript-to-ir.mjs","sources":["../../../src/adapters/type-ast-bridge/typescript-to-ir.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { irRaw } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport { asRaw, isIrNode, needsPrintedText } from \"./typescript-raw-text.js\";\n\n/**\n * Read TypeScript type nodes from user callbacks into IR (ADR-004, decision 3). Synthesized nodes\n * are mapped by structure. Anything the IR cannot express exactly is printed with the TypeScript\n * printer, the way the original output it, and kept as a `raw` node: parsed nodes, nodes with\n * comments, explicit parentheses, single-quoted strings, numbers not in canonical form, and syntax\n * the IR does not model. Every function takes the user's TypeScript module (ADR-004, decision 4):\n * `SyntaxKind` numbers differ between versions, so a node is read with the module that made it.\n */\n\nfunction keywordOf(ts: TypeScriptModule, kind: ts.SyntaxKind): IrKeyword | undefined {\n const keywords: ReadonlyMap<ts.SyntaxKind, IrKeyword> = new Map([\n [ts.SyntaxKind.StringKeyword, \"string\"],\n [ts.SyntaxKind.NumberKeyword, \"number\"],\n [ts.SyntaxKind.BooleanKeyword, \"boolean\"],\n [ts.SyntaxKind.UndefinedKeyword, \"undefined\"],\n [ts.SyntaxKind.UnknownKeyword, \"unknown\"],\n [ts.SyntaxKind.NeverKeyword, \"never\"],\n ]);\n return keywords.get(kind);\n}\n\nfunction isCanonicalNumber(text: string): boolean {\n return String(Number(text)) === text;\n}\n\nfunction fromNumber(ts: TypeScriptModule, literal: ts.Expression): IrType | null {\n if (ts.isNumericLiteral(literal)) {\n return isCanonicalNumber(literal.text)\n ? { kind: \"numberLiteral\", value: Number(literal.text) }\n : null;\n }\n const isNegative =\n ts.isPrefixUnaryExpression(literal) &&\n literal.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(literal.operand) &&\n isCanonicalNumber(literal.operand.text) &&\n Number(literal.operand.text) !== 0;\n return isNegative\n ? { kind: \"numberLiteral\", value: -Number((literal.operand as ts.NumericLiteral).text) }\n : null;\n}\n\nfunction fromLiteral(ts: TypeScriptModule, node: ts.LiteralTypeNode): IrType | null {\n const { literal } = node;\n if (ts.isStringLiteral(literal)) {\n const isSingleQuoted = (literal as { singleQuote?: boolean }).singleQuote === true;\n return isSingleQuoted\n ? null\n : { kind: \"stringLiteral\", value: literal.text, encoding: \"escaped\" };\n }\n if (literal.kind === ts.SyntaxKind.NullKeyword) {\n return { kind: \"keyword\", keyword: \"null\" };\n }\n if (literal.kind === ts.SyntaxKind.TrueKeyword || literal.kind === ts.SyntaxKind.FalseKeyword) {\n return { kind: \"booleanLiteral\", value: literal.kind === ts.SyntaxKind.TrueKeyword };\n }\n return fromNumber(ts, literal);\n}\n\n/** Converts the children of one node, which becomes their parent. */\nfunction childrenOf(ts: TypeScriptModule, parent: ts.Node): (child: ts.TypeNode) => IrType {\n return (child) => fromTypeNode(ts, child, parent);\n}\n\nfunction fromReference(ts: TypeScriptModule, node: ts.TypeReferenceNode): IrType | null {\n if (!ts.isIdentifier(node.typeName)) {\n return null;\n }\n const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));\n return { kind: \"reference\", name: ts.idText(node.typeName), typeArguments };\n}\n\nfunction fromTuple(ts: TypeScriptModule, node: ts.TupleTypeNode): IrType | null {\n const isPlain = node.elements.every(\n (element) => !ts.isNamedTupleMember(element) && !ts.isOptionalTypeNode(element),\n );\n if (!isPlain) {\n return null;\n }\n const convert = childrenOf(ts, node);\n const elements = node.elements.map((element) =>\n ts.isRestTypeNode(element)\n ? { type: convert(element.type), isRest: true }\n : { type: convert(element), isRest: false },\n );\n return { kind: \"tuple\", elements };\n}\n\n/**\n * Leading comments in order, or null when the IR cannot hold them: trailing comments, or a\n * comment without a line break after it (the IR always writes one).\n */\nfunction fromComments(ts: TypeScriptModule, node: ts.Node): IrComment[] | null {\n const comments = ts.getSyntheticLeadingComments(node) ?? [];\n const hasTrailing = (ts.getSyntheticTrailingComments(node)?.length ?? 0) > 0;\n if (hasTrailing || comments.some((comment) => !comment.hasTrailingNewLine)) {\n return null;\n }\n return comments.map((comment) => ({\n kind: comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? \"block\" : \"line\",\n text: comment.text,\n }));\n}\n\nfunction fromPropertyName(ts: TypeScriptModule, name: ts.PropertyName): IrPropertyName | null {\n if (ts.isIdentifier(name)) {\n return { kind: \"identifier\", text: ts.idText(name) };\n }\n if (ts.isStringLiteral(name) && (name as { singleQuote?: boolean }).singleQuote !== true) {\n return { kind: \"string\", value: name.text };\n }\n return ts.isNumericLiteral(name) ? { kind: \"number\", text: name.text } : null;\n}\n\n/** Only `readonly` is modeled; any other modifier makes the member unreadable as IR. */\nfunction readonlyFlag(ts: TypeScriptModule, node: ts.TypeElement): boolean | null {\n const modifiers = ts.canHaveModifiers(node) ? (ts.getModifiers(node) ?? []) : [];\n const isOnlyReadonly = modifiers.every(\n (modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword,\n );\n return isOnlyReadonly ? modifiers.length > 0 : null;\n}\n\n/** A property signature as IR, or null when it uses syntax the IR does not model. */\nexport function fromPropertySignature(\n ts: TypeScriptModule,\n node: ts.PropertySignature,\n): IrPropertySignature | null {\n const name = fromPropertyName(ts, node.name);\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n if (name === null || comments === null || isReadonly === null || node.type === undefined) {\n return null;\n }\n return {\n kind: \"property\",\n name,\n type: fromTypeNode(ts, node.type, node),\n isOptional: node.questionToken !== undefined,\n isReadonly,\n comments,\n };\n}\n\nfunction fromIndexSignature(\n ts: TypeScriptModule,\n node: ts.IndexSignatureDeclaration,\n): IrMember | null {\n const [parameter, ...others] = node.parameters;\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n const isPlain =\n parameter?.type !== undefined && ts.isIdentifier(parameter.name) && others.length === 0;\n if (!isPlain || comments === null || isReadonly === null) {\n return null;\n }\n return {\n kind: \"indexSignature\",\n parameterName: ts.idText(parameter.name as ts.Identifier),\n parameterType: fromTypeNode(ts, parameter.type as ts.TypeNode, node),\n type: fromTypeNode(ts, node.type, node),\n isReadonly,\n comments,\n };\n}\n\nfunction fromMember(ts: TypeScriptModule, member: ts.TypeElement): IrMember | null {\n if (member.pos >= 0) {\n return null;\n }\n if (ts.isPropertySignature(member)) {\n return fromPropertySignature(ts, member);\n }\n return ts.isIndexSignatureDeclaration(member) ? fromIndexSignature(ts, member) : null;\n}\n\nfunction fromTypeLiteral(ts: TypeScriptModule, node: ts.TypeLiteralNode): IrType | null {\n const members = node.members.map((member) => fromMember(ts, member));\n const isReadable = members.every((member) => member !== null);\n return isReadable ? { kind: \"object\", members: members as IrMember[] } : null;\n}\n\nfunction fromComposite(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const convert = childrenOf(ts, node);\n if (ts.isArrayTypeNode(node)) {\n return { kind: \"array\", element: convert(node.elementType) };\n }\n if (ts.isUnionTypeNode(node)) {\n return { kind: \"union\", types: node.types.map(convert) };\n }\n if (ts.isIntersectionTypeNode(node)) {\n return { kind: \"intersection\", types: node.types.map(convert) };\n }\n if (ts.isIndexedAccessTypeNode(node)) {\n return {\n kind: \"indexedAccess\",\n object: convert(node.objectType),\n index: convert(node.indexType),\n };\n }\n if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) {\n return { kind: \"readonly\", type: convert(node.type) };\n }\n return ts.isTypeLiteralNode(node) ? fromTypeLiteral(ts, node) : null;\n}\n\nfunction fromStructure(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const keyword = keywordOf(ts, node.kind);\n if (keyword !== undefined) {\n return { kind: \"keyword\", keyword };\n }\n if (ts.isIdentifier(node)) {\n // The original writes JSON string literals and some references as bare identifiers.\n return irRaw(ts.idText(node));\n }\n if (ts.isLiteralTypeNode(node)) {\n return fromLiteral(ts, node);\n }\n if (ts.isTypeReferenceNode(node)) {\n return fromReference(ts, node);\n }\n return ts.isTupleTypeNode(node) ? fromTuple(ts, node) : fromComposite(ts, node);\n}\n\n/**\n * Whether the factory's parenthesizer put these parentheses in (same rules as the IR printer):\n * unions, intersections and `readonly` types as array elements, indexed objects and `readonly`\n * operands; unions and intersections as members of other unions or intersections.\n */\nfunction isFactoryParenthesis(\n ts: TypeScriptModule,\n inner: ts.TypeNode,\n parent: ts.Node | undefined,\n): boolean {\n if (parent === undefined) {\n return false;\n }\n const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);\n const isPostfixOrReadonlyParent =\n ts.isArrayTypeNode(parent) ||\n ts.isIndexedAccessTypeNode(parent) ||\n ts.isTypeOperatorNode(parent);\n if (isPostfixOrReadonlyParent) {\n return isComposite || ts.isTypeOperatorNode(inner);\n }\n const isCompositeParent = ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent);\n return isCompositeParent && isComposite;\n}\n\n/**\n * Convert a type node. `parent` is the node that contains it: synthesized nodes have no `parent`\n * link, and it is needed to tell parentheses the factory inserted from ones the user wrote.\n */\nexport function fromTypeNode(ts: TypeScriptModule, node: ts.TypeNode, parent?: ts.Node): IrType {\n if (isIrNode(node)) {\n return node;\n }\n if (needsPrintedText(ts, node)) {\n return asRaw(ts, node);\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return isFactoryParenthesis(ts, node.type, parent)\n ? fromTypeNode(ts, node.type, parent)\n : asRaw(ts, node);\n }\n return fromStructure(ts, node) ?? asRaw(ts, node);\n}\n"],"names":[],"mappings":";;;AAsBA,SAAS,SAAA,CAAU,IAAsB,IAAA,EAA4C;AACnF,EAAA,MAAM,QAAA,uBAAsD,GAAA,CAAI;AAAA,IAC9D,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,cAAA,EAAgB,SAAS,CAAA;AAAA,IACxC,CAAC,EAAA,CAAG,UAAA,CAAW,gBAAA,EAAkB,WAAW,CAAA;AAAA,IAC5C,CA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AAAA,EACpB;AACA,EAAA,OAAO,cAAc,EAAA,EAAI,IAAI,CAAA,IAAK,KAAA,CAAM,IAAI,IAAI,CAAA;AAClD;;"}
1
+ {"version":3,"file":"typescript-to-ir.mjs","sources":["../../../src/adapters/type-ast-bridge/typescript-to-ir.ts"],"sourcesContent":["import type ts from \"typescript\";\nimport { irRaw } from \"../../domain/ir/constructors.js\";\nimport type {\n IrComment,\n IrKeyword,\n IrMember,\n IrPropertyName,\n IrPropertySignature,\n IrTupleElement,\n IrType,\n} from \"../../domain/ir/nodes.js\";\nimport type { TypeScriptModule } from \"./load-typescript.js\";\nimport { asRaw, isIrNode, needsPrintedText } from \"./typescript-raw-text.js\";\n\n/**\n * Read TypeScript type nodes from user callbacks into IR (ADR-004, decision 3). Synthesized nodes\n * are mapped by structure. Anything the IR cannot express exactly is printed with the TypeScript\n * printer, the way the original output it, and kept as a `raw` node: parsed nodes, nodes with\n * comments, explicit parentheses, single-quoted strings, numbers not in canonical form, and syntax\n * the IR does not model. Every function takes the user's TypeScript module (ADR-004, decision 4):\n * `SyntaxKind` numbers differ between versions, so a node is read with the module that made it.\n */\n\nfunction keywordOf(ts: TypeScriptModule, kind: ts.SyntaxKind): IrKeyword | undefined {\n const keywords: ReadonlyMap<ts.SyntaxKind, IrKeyword> = new Map([\n [ts.SyntaxKind.StringKeyword, \"string\"],\n [ts.SyntaxKind.NumberKeyword, \"number\"],\n [ts.SyntaxKind.BooleanKeyword, \"boolean\"],\n [ts.SyntaxKind.UndefinedKeyword, \"undefined\"],\n [ts.SyntaxKind.UnknownKeyword, \"unknown\"],\n [ts.SyntaxKind.NeverKeyword, \"never\"],\n ]);\n return keywords.get(kind);\n}\n\nfunction isCanonicalNumber(text: string): boolean {\n return String(Number(text)) === text;\n}\n\nfunction fromNumber(ts: TypeScriptModule, literal: ts.Expression): IrType | null {\n if (ts.isNumericLiteral(literal)) {\n return isCanonicalNumber(literal.text)\n ? { kind: \"numberLiteral\", value: Number(literal.text) }\n : null;\n }\n const isNegative =\n ts.isPrefixUnaryExpression(literal) &&\n literal.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(literal.operand) &&\n isCanonicalNumber(literal.operand.text) &&\n Number(literal.operand.text) !== 0;\n return isNegative\n ? { kind: \"numberLiteral\", value: -Number((literal.operand as ts.NumericLiteral).text) }\n : null;\n}\n\nfunction fromLiteral(ts: TypeScriptModule, node: ts.LiteralTypeNode): IrType | null {\n const { literal } = node;\n if (ts.isStringLiteral(literal)) {\n const isSingleQuoted = (literal as { singleQuote?: boolean }).singleQuote === true;\n return isSingleQuoted\n ? null\n : { kind: \"stringLiteral\", value: literal.text, encoding: \"escaped\" };\n }\n if (literal.kind === ts.SyntaxKind.NullKeyword) {\n return { kind: \"keyword\", keyword: \"null\" };\n }\n if (literal.kind === ts.SyntaxKind.TrueKeyword || literal.kind === ts.SyntaxKind.FalseKeyword) {\n return { kind: \"booleanLiteral\", value: literal.kind === ts.SyntaxKind.TrueKeyword };\n }\n return fromNumber(ts, literal);\n}\n\n/** Converts the children of one node, which becomes their parent. */\nfunction childrenOf(ts: TypeScriptModule, parent: ts.Node): (child: ts.TypeNode) => IrType {\n return (child) => fromTypeNode(ts, child, parent);\n}\n\nfunction fromReference(ts: TypeScriptModule, node: ts.TypeReferenceNode): IrType | null {\n if (!ts.isIdentifier(node.typeName)) {\n return null;\n }\n const typeArguments = (node.typeArguments ?? []).map(childrenOf(ts, node));\n return { kind: \"reference\", name: ts.idText(node.typeName), typeArguments };\n}\n\nfunction fromTupleElement(\n ts: TypeScriptModule,\n element: ts.TypeNode,\n convert: (node: ts.TypeNode) => IrType,\n): IrTupleElement {\n if (ts.isRestTypeNode(element)) {\n return { type: convert(element.type), isRest: true, isOptional: false };\n }\n if (ts.isOptionalTypeNode(element)) {\n // The `?` is the parent of the type: it decides which parentheses the factory put in.\n return { type: fromTypeNode(ts, element.type, element), isRest: false, isOptional: true };\n }\n return { type: convert(element), isRest: false, isOptional: false };\n}\n\n/** A tuple of plain, rest and optional elements; one with named members stays text. */\nfunction fromTuple(ts: TypeScriptModule, node: ts.TupleTypeNode): IrType | null {\n if (node.elements.some((element) => ts.isNamedTupleMember(element))) {\n return null;\n }\n const convert = childrenOf(ts, node);\n return {\n kind: \"tuple\",\n elements: node.elements.map((element) => fromTupleElement(ts, element, convert)),\n };\n}\n\n/**\n * Leading comments in order, or null when the IR cannot hold them: trailing comments, or a\n * comment without a line break after it (the IR always writes one).\n */\nfunction fromComments(ts: TypeScriptModule, node: ts.Node): IrComment[] | null {\n const comments = ts.getSyntheticLeadingComments(node) ?? [];\n const hasTrailing = (ts.getSyntheticTrailingComments(node)?.length ?? 0) > 0;\n if (hasTrailing || comments.some((comment) => !comment.hasTrailingNewLine)) {\n return null;\n }\n return comments.map((comment) => ({\n kind: comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? \"block\" : \"line\",\n text: comment.text,\n }));\n}\n\nfunction fromPropertyName(ts: TypeScriptModule, name: ts.PropertyName): IrPropertyName | null {\n if (ts.isIdentifier(name)) {\n return { kind: \"identifier\", text: ts.idText(name) };\n }\n if (ts.isStringLiteral(name) && (name as { singleQuote?: boolean }).singleQuote !== true) {\n return { kind: \"string\", value: name.text };\n }\n return ts.isNumericLiteral(name) ? { kind: \"number\", text: name.text } : null;\n}\n\n/** Only `readonly` is modeled; any other modifier makes the member unreadable as IR. */\nfunction readonlyFlag(ts: TypeScriptModule, node: ts.TypeElement): boolean | null {\n const modifiers = ts.canHaveModifiers(node) ? (ts.getModifiers(node) ?? []) : [];\n const isOnlyReadonly = modifiers.every(\n (modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword,\n );\n return isOnlyReadonly ? modifiers.length > 0 : null;\n}\n\n/** A property signature as IR, or null when it uses syntax the IR does not model. */\nexport function fromPropertySignature(\n ts: TypeScriptModule,\n node: ts.PropertySignature,\n): IrPropertySignature | null {\n const name = fromPropertyName(ts, node.name);\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n if (name === null || comments === null || isReadonly === null || node.type === undefined) {\n return null;\n }\n return {\n kind: \"property\",\n name,\n type: fromTypeNode(ts, node.type, node),\n isOptional: node.questionToken !== undefined,\n isReadonly,\n comments,\n };\n}\n\nfunction fromIndexSignature(\n ts: TypeScriptModule,\n node: ts.IndexSignatureDeclaration,\n): IrMember | null {\n const [parameter, ...others] = node.parameters;\n const comments = fromComments(ts, node);\n const isReadonly = readonlyFlag(ts, node);\n const isPlain =\n parameter?.type !== undefined && ts.isIdentifier(parameter.name) && others.length === 0;\n if (!isPlain || comments === null || isReadonly === null) {\n return null;\n }\n return {\n kind: \"indexSignature\",\n parameterName: ts.idText(parameter.name as ts.Identifier),\n parameterType: fromTypeNode(ts, parameter.type as ts.TypeNode, node),\n type: fromTypeNode(ts, node.type, node),\n isReadonly,\n comments,\n };\n}\n\nfunction fromMember(ts: TypeScriptModule, member: ts.TypeElement): IrMember | null {\n if (member.pos >= 0) {\n return null;\n }\n if (ts.isPropertySignature(member)) {\n return fromPropertySignature(ts, member);\n }\n return ts.isIndexSignatureDeclaration(member) ? fromIndexSignature(ts, member) : null;\n}\n\nfunction fromTypeLiteral(ts: TypeScriptModule, node: ts.TypeLiteralNode): IrType | null {\n const members = node.members.map((member) => fromMember(ts, member));\n const isReadable = members.every((member) => member !== null);\n return isReadable ? { kind: \"object\", members: members as IrMember[] } : null;\n}\n\nfunction fromComposite(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const convert = childrenOf(ts, node);\n if (ts.isArrayTypeNode(node)) {\n return { kind: \"array\", element: convert(node.elementType) };\n }\n if (ts.isUnionTypeNode(node)) {\n return { kind: \"union\", types: node.types.map(convert) };\n }\n if (ts.isIntersectionTypeNode(node)) {\n return { kind: \"intersection\", types: node.types.map(convert) };\n }\n if (ts.isIndexedAccessTypeNode(node)) {\n return {\n kind: \"indexedAccess\",\n object: convert(node.objectType),\n index: convert(node.indexType),\n };\n }\n if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) {\n return { kind: \"readonly\", type: convert(node.type) };\n }\n return ts.isTypeLiteralNode(node) ? fromTypeLiteral(ts, node) : null;\n}\n\nfunction fromStructure(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {\n const keyword = keywordOf(ts, node.kind);\n if (keyword !== undefined) {\n return { kind: \"keyword\", keyword };\n }\n if (ts.isIdentifier(node)) {\n // The original writes JSON string literals and some references as bare identifiers.\n return irRaw(ts.idText(node));\n }\n if (ts.isLiteralTypeNode(node)) {\n return fromLiteral(ts, node);\n }\n if (ts.isTypeReferenceNode(node)) {\n return fromReference(ts, node);\n }\n return ts.isTupleTypeNode(node) ? fromTuple(ts, node) : fromComposite(ts, node);\n}\n\n/**\n * Whether the factory's parenthesizer put these parentheses in (same rules as the IR printer):\n * unions, intersections and `readonly` types as array elements, indexed objects, optional tuple\n * elements and `readonly` operands; unions and intersections as members of other unions or\n * intersections.\n */\nfunction isFactoryParenthesis(\n ts: TypeScriptModule,\n inner: ts.TypeNode,\n parent: ts.Node | undefined,\n): boolean {\n if (parent === undefined) {\n return false;\n }\n const isComposite = ts.isUnionTypeNode(inner) || ts.isIntersectionTypeNode(inner);\n const isPostfixOrReadonlyParent =\n ts.isArrayTypeNode(parent) ||\n ts.isIndexedAccessTypeNode(parent) ||\n ts.isOptionalTypeNode(parent) ||\n ts.isTypeOperatorNode(parent);\n if (isPostfixOrReadonlyParent) {\n return isComposite || ts.isTypeOperatorNode(inner);\n }\n const isCompositeParent = ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent);\n return isCompositeParent && isComposite;\n}\n\n/**\n * Convert a type node. `parent` is the node that contains it: synthesized nodes have no `parent`\n * link, and it is needed to tell parentheses the factory inserted from ones the user wrote.\n */\nexport function fromTypeNode(ts: TypeScriptModule, node: ts.TypeNode, parent?: ts.Node): IrType {\n if (isIrNode(node)) {\n return node;\n }\n if (needsPrintedText(ts, node)) {\n return asRaw(ts, node);\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return isFactoryParenthesis(ts, node.type, parent)\n ? fromTypeNode(ts, node.type, parent)\n : asRaw(ts, node);\n }\n return fromStructure(ts, node) ?? asRaw(ts, node);\n}\n"],"names":[],"mappings":";;;AAuBA,SAAS,SAAA,CAAU,IAAsB,IAAA,EAA4C;AACnF,EAAA,MAAM,QAAA,uBAAsD,GAAA,CAAI;AAAA,IAC9D,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,aAAA,EAAe,QAAQ,CAAA;AAAA,IACtC,CAAC,EAAA,CAAG,UAAA,CAAW,cAAA,EAAgB,SAAS,CAAA;AAAA,IACxC,CAAC,EAAA,CAAG,UAAA,CAAW,gBAAA,EAAkB,WAAW,CAAA;AAAA,IAC5C,CAAC,EAAA,CAAG,UAAA,CAAW,cAAA,EAAgB,SAAS,CAAA;AAAA,IACxC,CAAC,EAAA,CAAG,UAAA,CAAW,YAAA,EAAc,OAAO;AAAA,GACrC,CAAA;AACD,EAAA,OAAO,QAAA,CAAS,IAAI,IAAI,CAAA;AAC1B;AAEA,SAAS,kBAAkB,IAAA,EAAuB;AAChD,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,IAAI,CAAC,CAAA,KAAM,IAAA;AAClC;AAEA,SAAS,UAAA,CAAW,IAAsB,OAAA,EAAuC;AAC/E,EAAA,IAAI,EAAA,CAAG,gBAAA,CAAiB,OAAO,CAAA,EAAG;AAChC,IAAA,OAAO,iBAAA,CAAkB,OAAA,CAAQ,IAAI,CAAA,GACjC,EAAE,IAAA,EAAM,eAAA,EAAiB,KAAA,EAAO,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAE,GACrD,IAAA;AAAA,EACN;AACA,EAAA,MAAM,UAAA,GACJ,EAAA,CAAG,uBAAA,CAAwB,OAAO,CAAA,IAClC,QAAQ,QAAA,KAAa,EAAA,CAAG,UAAA,CAAW,UAAA,IACnC,EAAA,CAAG,gBAA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,GAAG,kBAAA,CAAmB,MAAM,CAAA,IAC5B,EAAA,CAAG,mBAAmB,MAAM,CAAA;AAC9B,EAAA,IAAI,yBAAA,EAA2B;AAC7B,IAAA,OAAO,WAAA,IAAe,EAAA,CAAG,kBAAA,CAAmB,KAAK,CAAA;AAAA,EACnD;AACA,EAAA,MAAM,oBAAoB,EAAA,CAAG,eAAA,CAAgB,MAAM,CAAA,IAAK,EAAA,CAAG,uBAAuB,MAAM,CAAA;AACxF,EAAA,OAAO,iBAAA,IAAqB,WAAA;AAC9B;AAMO,SAAS,YAAA,CAAa,EAAA,EAAsB,IAAA,EAAmB,MAAA,EAA0B;AAC9F,EAAA,IAAI,QAAA,CAAS,IAAI,CAAA,EAAG;AAClB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,gBAAA,CAAiB,EAAA,EAAI,IAAI,CAAA,EAAG;AAC9B,IAAA,OAAO,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,EACvB;AACA,EAAA,IAAI,EAAA,CAAG,uBAAA,CAAwB,IAAI,CAAA,EAAG;AACpC,IAAA,OAAO,oBAAA,CAAqB,EAAA,EAAI,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA,GAC7C,YAAA,CAAa,EAAA,EAAI,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA,GAClC,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAc,EAAA,EAAI,IAAI,CAAA,IAAK,KAAA,CAAM,IAAI,IAAI,CAAA;AAClD;;"}
@@ -22,6 +22,13 @@ function defaultLogger(silent) {
22
22
  });
23
23
  }
24
24
  const REMOTE_REF_TIMEOUT_MS = 6e4;
25
+ const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
26
+ maxDocuments: 1e4,
27
+ maxParallelFetches: 16
28
+ };
29
+ function processCwd() {
30
+ return process.cwd();
31
+ }
25
32
  function monotonicNow() {
26
33
  return node_perf_hooks.performance.now();
27
34
  }
@@ -30,9 +37,11 @@ function defaultRedoclyConfig() {
30
37
  return openapiCore.createConfig({ rules }, { extends: ["minimal"] });
31
38
  }
32
39
 
40
+ exports.DEFAULT_REMOTE_DOCUMENT_LIMITS = DEFAULT_REMOTE_DOCUMENT_LIMITS;
33
41
  exports.REMOTE_REF_TIMEOUT_MS = REMOTE_REF_TIMEOUT_MS;
34
42
  exports.defaultLogger = defaultLogger;
35
43
  exports.defaultRedoclyConfig = defaultRedoclyConfig;
36
44
  exports.monotonicNow = monotonicNow;
45
+ exports.processCwd = processCwd;
37
46
  exports.terminalSupportsColor = terminalSupportsColor;
38
47
  //# sourceMappingURL=default-ports.cjs.map
@@ -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 { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.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/**\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/** 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","performance","createConfig"],"mappings":";;;;;;;;;;;AAYO,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;AAOO,MAAM,qBAAA,GAAwB;AAG9B,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 type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.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/**\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","performance","createConfig"],"mappings":";;;;;;;;;;;AAaO,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;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;;;;;;;;"}
@@ -16,6 +16,13 @@ function defaultLogger(silent) {
16
16
  });
17
17
  }
18
18
  const REMOTE_REF_TIMEOUT_MS = 6e4;
19
+ const DEFAULT_REMOTE_DOCUMENT_LIMITS = {
20
+ maxDocuments: 1e4,
21
+ maxParallelFetches: 16
22
+ };
23
+ function processCwd() {
24
+ return process.cwd();
25
+ }
19
26
  function monotonicNow() {
20
27
  return performance.now();
21
28
  }
@@ -24,5 +31,5 @@ function defaultRedoclyConfig() {
24
31
  return createConfig({ rules }, { extends: ["minimal"] });
25
32
  }
26
33
 
27
- export { REMOTE_REF_TIMEOUT_MS, defaultLogger, defaultRedoclyConfig, monotonicNow, terminalSupportsColor };
34
+ export { DEFAULT_REMOTE_DOCUMENT_LIMITS, REMOTE_REF_TIMEOUT_MS, defaultLogger, defaultRedoclyConfig, monotonicNow, processCwd, terminalSupportsColor };
28
35
  //# sourceMappingURL=default-ports.mjs.map
@@ -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 { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.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/**\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/** 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":";;;;;AAYO,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;AAOO,MAAM,qBAAA,GAAwB;AAG9B,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 type { RemoteDocumentLimits } from \"../adapters/redocly-loader/remote-fetch.js\";\nimport { createTerminalLogger } from \"../adapters/terminal-logger/terminal-logger.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/**\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":";;;;;AAaO,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;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;;"}
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const discriminatorConflicts = require('../domain/openapi/discriminator-conflicts.cjs');
4
+ const outputFixes = require('../domain/output-fixes.cjs');
5
+ const warnings = require('../domain/warnings.cjs');
6
+
7
+ const DOCS_BASE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs";
8
+ const DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;
9
+ function listed(values) {
10
+ return values.map((value) => JSON.stringify(value)).join(", ");
11
+ }
12
+ function warningOf(conflict) {
13
+ const { member, owner, propertyName, values, allowed, isImplicit } = conflict;
14
+ const rule = isImplicit ? `A Discriminator Object without a mapping entry for a schema gives it its schema name as the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: "${member}".` : "The Discriminator Object maps these values to the schema; map the values it allows.";
15
+ return `${member}: the discriminator "${propertyName}" of ${owner} gives this schema the value ${listed(values)}, which its "${propertyName}" property does not allow (${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} See ${DOCS_URL}`;
16
+ }
17
+ function warnDiscriminatorValueConflicts(document, fixes, logger) {
18
+ const isUnionReused = fixes.includes(outputFixes.OutputFix.ALLOF_DISCRIMINATED_UNION);
19
+ for (const conflict of discriminatorConflicts.findDiscriminatorValueConflicts(document, { isUnionReused })) {
20
+ logger.warn(warnings.warningText(warningOf(conflict), warnings.WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));
21
+ }
22
+ }
23
+
24
+ exports.warnDiscriminatorValueConflicts = warnDiscriminatorValueConflicts;
25
+ //# sourceMappingURL=discriminator-conflict-warnings.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminator-conflict-warnings.cjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(OutputFix.ALLOF_DISCRIMINATED_UNION);\n for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {\n logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));\n }\n}\n"],"names":["OutputFix","findDiscriminatorValueConflicts","warningText","WARNING_CODES"],"mappings":";;;;;;AAQA,MAAM,aAAA,GAAgB,qEAAA;AACtB,MAAM,QAAA,GAAW,GAAG,aAAa,CAAA,iCAAA,CAAA;AAEjC,SAAS,OAAO,MAAA,EAAoC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