@keq-request/cli 5.0.0-alpha.22 → 5.0.0-alpha.24

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 (319) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cli.cjs +1946 -1468
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +1943 -1465
  5. package/dist/cli.js.map +1 -1
  6. package/dist/compiler/compiler.d.ts +8 -20
  7. package/dist/compiler/compiler.d.ts.map +1 -1
  8. package/dist/compiler/index.d.ts +2 -0
  9. package/dist/compiler/index.d.ts.map +1 -1
  10. package/dist/compiler/intercepter/index.d.ts +3 -0
  11. package/dist/compiler/intercepter/index.d.ts.map +1 -0
  12. package/dist/compiler/intercepter/print-information.d.ts +1 -1
  13. package/dist/compiler/intercepter/print-information.d.ts.map +1 -1
  14. package/dist/compiler/tasks/compile/index.d.ts +6 -0
  15. package/dist/compiler/tasks/compile/index.d.ts.map +1 -0
  16. package/dist/{tasks → compiler/tasks}/download/index.d.ts +3 -3
  17. package/dist/compiler/tasks/download/index.d.ts.map +1 -0
  18. package/dist/compiler/tasks/index.d.ts +6 -0
  19. package/dist/compiler/tasks/index.d.ts.map +1 -0
  20. package/dist/compiler/tasks/persist/index.d.ts +5 -0
  21. package/dist/compiler/tasks/persist/index.d.ts.map +1 -0
  22. package/dist/{tasks → compiler/tasks}/setup/index.d.ts +4 -5
  23. package/dist/compiler/tasks/setup/index.d.ts.map +1 -0
  24. package/dist/compiler/tasks/setup/utils/find-nearest-package-json.d.ts.map +1 -0
  25. package/dist/compiler/tasks/setup/utils/get-project-module-system.d.ts.map +1 -0
  26. package/dist/compiler/tasks/setup/utils/index.d.ts.map +1 -0
  27. package/dist/compiler/tasks/setup/utils/validate-modules.d.ts.map +1 -0
  28. package/dist/compiler/tasks/types/base-task-options.d.ts +6 -0
  29. package/dist/compiler/tasks/types/base-task-options.d.ts.map +1 -0
  30. package/dist/compiler/tasks/types/index.d.ts +3 -0
  31. package/dist/compiler/tasks/types/index.d.ts.map +1 -0
  32. package/dist/compiler/tasks/types/task-wrapper.d.ts +4 -0
  33. package/dist/compiler/tasks/types/task-wrapper.d.ts.map +1 -0
  34. package/dist/compiler/types/compiler-context.d.ts +11 -0
  35. package/dist/compiler/types/compiler-context.d.ts.map +1 -0
  36. package/dist/compiler/types/compiler-hooks.d.ts +18 -0
  37. package/dist/compiler/types/compiler-hooks.d.ts.map +1 -0
  38. package/dist/compiler/types/index.d.ts +3 -0
  39. package/dist/compiler/types/index.d.ts.map +1 -0
  40. package/dist/constants/index.d.ts +4 -0
  41. package/dist/constants/index.d.ts.map +1 -0
  42. package/dist/exception.d.ts +1 -1
  43. package/dist/exception.d.ts.map +1 -1
  44. package/dist/generators/index.d.ts +2 -0
  45. package/dist/generators/index.d.ts.map +1 -0
  46. package/dist/index.cjs +1901 -1413
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.ts +4 -11
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1895 -1407
  51. package/dist/index.js.map +1 -1
  52. package/dist/models/anchor.d.ts.map +1 -0
  53. package/dist/{tasks/utils → models}/api-document_v3_1.d.ts +1 -1
  54. package/dist/models/api-document_v3_1.d.ts.map +1 -0
  55. package/dist/models/artifact.d.ts +17 -0
  56. package/dist/models/artifact.d.ts.map +1 -0
  57. package/dist/models/asset.d.ts +5 -0
  58. package/dist/models/asset.d.ts.map +1 -0
  59. package/dist/{tasks/utils → models}/index.d.ts +2 -5
  60. package/dist/models/index.d.ts.map +1 -0
  61. package/dist/{tasks/utils → models}/module-definition.d.ts +1 -0
  62. package/dist/models/module-definition.d.ts.map +1 -0
  63. package/dist/{tasks/utils → models}/operation-definition.d.ts +1 -0
  64. package/dist/models/operation-definition.d.ts.map +1 -0
  65. package/dist/{tasks/utils → models}/schema-definition.d.ts +3 -2
  66. package/dist/models/schema-definition.d.ts.map +1 -0
  67. package/dist/models/utils/to-comment.d.ts.map +1 -0
  68. package/dist/plugins/body-fallback/index.d.ts.map +1 -1
  69. package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts +5 -0
  70. package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts.map +1 -0
  71. package/dist/plugins/chinese-to-pinyin/index.d.ts +2 -0
  72. package/dist/plugins/chinese-to-pinyin/index.d.ts.map +1 -0
  73. package/dist/plugins/download-http-file/download-http-file.plugin.d.ts +8 -0
  74. package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -0
  75. package/dist/plugins/download-http-file/index.d.ts +2 -0
  76. package/dist/plugins/download-http-file/index.d.ts.map +1 -0
  77. package/dist/plugins/download-local-file/download-local-file.plugin.d.ts +6 -0
  78. package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -0
  79. package/dist/plugins/download-local-file/index.d.ts +2 -0
  80. package/dist/plugins/download-local-file/index.d.ts.map +1 -0
  81. package/dist/plugins/generate-declaration/constants/index.d.ts +2 -0
  82. package/dist/plugins/generate-declaration/constants/index.d.ts.map +1 -0
  83. package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts +12 -0
  84. package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts.map +1 -0
  85. package/dist/plugins/generate-declaration/generate-declaration.plugin.d.ts +15 -0
  86. package/dist/plugins/generate-declaration/generate-declaration.plugin.d.ts.map +1 -0
  87. package/dist/plugins/generate-declaration/generators/index.d.ts +3 -0
  88. package/dist/plugins/generate-declaration/generators/index.d.ts.map +1 -0
  89. package/dist/plugins/generate-declaration/generators/operation-declaration/index.d.ts +2 -0
  90. package/dist/plugins/generate-declaration/generators/operation-declaration/index.d.ts.map +1 -0
  91. package/dist/plugins/generate-declaration/generators/operation-declaration/operation.generator.d.ts +15 -0
  92. package/dist/plugins/generate-declaration/generators/operation-declaration/operation.generator.d.ts.map +1 -0
  93. package/dist/plugins/generate-declaration/generators/schema-declaration/index.d.ts +2 -0
  94. package/dist/plugins/generate-declaration/generators/schema-declaration/index.d.ts.map +1 -0
  95. package/dist/plugins/generate-declaration/generators/schema-declaration/schema.generator.d.ts +15 -0
  96. package/dist/plugins/generate-declaration/generators/schema-declaration/schema.generator.d.ts.map +1 -0
  97. package/dist/plugins/generate-declaration/index.d.ts +3 -0
  98. package/dist/plugins/generate-declaration/index.d.ts.map +1 -0
  99. package/dist/plugins/generate-micro-function/constants/index.d.ts +2 -0
  100. package/dist/plugins/generate-micro-function/constants/index.d.ts.map +1 -0
  101. package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts +11 -0
  102. package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts.map +1 -0
  103. package/dist/plugins/generate-micro-function/generate-micro-function.plugin.d.ts +11 -0
  104. package/dist/plugins/generate-micro-function/generate-micro-function.plugin.d.ts.map +1 -0
  105. package/dist/plugins/generate-micro-function/generators/index.d.ts +3 -0
  106. package/dist/plugins/generate-micro-function/generators/index.d.ts.map +1 -0
  107. package/dist/plugins/generate-micro-function/generators/micro_function/index.d.ts +2 -0
  108. package/dist/plugins/generate-micro-function/generators/micro_function/index.d.ts.map +1 -0
  109. package/dist/plugins/generate-micro-function/generators/micro_function/micro-function.generator.d.ts +15 -0
  110. package/dist/plugins/generate-micro-function/generators/micro_function/micro-function.generator.d.ts.map +1 -0
  111. package/dist/plugins/generate-micro-function/generators/request/index.d.ts +2 -0
  112. package/dist/plugins/generate-micro-function/generators/request/index.d.ts.map +1 -0
  113. package/dist/plugins/generate-micro-function/generators/request/request.generator.d.ts +11 -0
  114. package/dist/plugins/generate-micro-function/generators/request/request.generator.d.ts.map +1 -0
  115. package/dist/plugins/generate-micro-function/index.d.ts +3 -0
  116. package/dist/plugins/generate-micro-function/index.d.ts.map +1 -0
  117. package/dist/plugins/generate-nestjs-module/constants/index.d.ts +2 -0
  118. package/dist/plugins/generate-nestjs-module/constants/index.d.ts.map +1 -0
  119. package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts +10 -0
  120. package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts.map +1 -0
  121. package/dist/plugins/generate-nestjs-module/generate-nestjs-module.d.ts +10 -0
  122. package/dist/plugins/generate-nestjs-module/generate-nestjs-module.d.ts.map +1 -0
  123. package/dist/plugins/generate-nestjs-module/generators/index.d.ts +2 -0
  124. package/dist/plugins/generate-nestjs-module/generators/index.d.ts.map +1 -0
  125. package/dist/plugins/generate-nestjs-module/generators/nestjs-module.generator.d.ts +14 -0
  126. package/dist/plugins/generate-nestjs-module/generators/nestjs-module.generator.d.ts.map +1 -0
  127. package/dist/plugins/generate-nestjs-module/index.d.ts +3 -0
  128. package/dist/plugins/generate-nestjs-module/index.d.ts.map +1 -0
  129. package/dist/plugins/index.d.ts +11 -0
  130. package/dist/plugins/index.d.ts.map +1 -1
  131. package/dist/plugins/initialize/index.d.ts +2 -0
  132. package/dist/plugins/initialize/index.d.ts.map +1 -0
  133. package/dist/plugins/initialize/initialize.plugin.d.ts +15 -0
  134. package/dist/plugins/initialize/initialize.plugin.d.ts.map +1 -0
  135. package/dist/plugins/overwrite-operation-id/index.d.ts +2 -0
  136. package/dist/plugins/overwrite-operation-id/index.d.ts.map +1 -0
  137. package/dist/plugins/overwrite-operation-id/overwrite-operation-id.plugin.d.ts +20 -0
  138. package/dist/plugins/overwrite-operation-id/overwrite-operation-id.plugin.d.ts.map +1 -0
  139. package/dist/plugins/overwrite-query-options/index.d.ts +2 -0
  140. package/dist/plugins/overwrite-query-options/index.d.ts.map +1 -0
  141. package/dist/plugins/overwrite-query-options/overwrite-query-options.plugin.d.ts +18 -0
  142. package/dist/plugins/overwrite-query-options/overwrite-query-options.plugin.d.ts.map +1 -0
  143. package/dist/plugins/prettier/index.d.ts +1 -5
  144. package/dist/plugins/prettier/index.d.ts.map +1 -1
  145. package/dist/plugins/prettier/prettier.plugin.d.ts +6 -0
  146. package/dist/plugins/prettier/prettier.plugin.d.ts.map +1 -0
  147. package/dist/plugins/shaking/index.d.ts +2 -0
  148. package/dist/plugins/shaking/index.d.ts.map +1 -0
  149. package/dist/plugins/shaking/shaking.plugin.d.ts +8 -0
  150. package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -0
  151. package/dist/plugins/terminal-select/index.d.ts +2 -0
  152. package/dist/plugins/terminal-select/index.d.ts.map +1 -0
  153. package/dist/plugins/terminal-select/terminal-select.plugin.d.ts +18 -0
  154. package/dist/plugins/terminal-select/terminal-select.plugin.d.ts.map +1 -0
  155. package/dist/plugins/terminal-select/types/ignore-mode.d.ts.map +1 -0
  156. package/dist/plugins/terminal-select/types/index.d.ts +2 -0
  157. package/dist/plugins/terminal-select/types/index.d.ts.map +1 -0
  158. package/dist/plugins/terminal-select/utils/index.d.ts +2 -0
  159. package/dist/plugins/terminal-select/utils/index.d.ts.map +1 -0
  160. package/dist/plugins/terminal-select/utils/select-operation-definitions.d.ts +5 -0
  161. package/dist/plugins/terminal-select/utils/select-operation-definitions.d.ts.map +1 -0
  162. package/dist/plugins.cjs +2305 -31
  163. package/dist/plugins.cjs.map +1 -1
  164. package/dist/plugins.js +2283 -30
  165. package/dist/plugins.js.map +1 -1
  166. package/dist/transformers/api-document/api-document.transformer.d.ts +8 -0
  167. package/dist/transformers/api-document/api-document.transformer.d.ts.map +1 -0
  168. package/dist/transformers/api-document/index.d.ts +2 -0
  169. package/dist/transformers/api-document/index.d.ts.map +1 -0
  170. package/dist/transformers/api-document/nestjs-client.renderer.d.ts +14 -0
  171. package/dist/transformers/api-document/nestjs-client.renderer.d.ts.map +1 -0
  172. package/dist/transformers/api-document/nestjs-module.renderer.d.ts +12 -0
  173. package/dist/transformers/api-document/nestjs-module.renderer.d.ts.map +1 -0
  174. package/dist/transformers/entrypoint/entrypoint.transformer.d.ts +10 -0
  175. package/dist/transformers/entrypoint/entrypoint.transformer.d.ts.map +1 -0
  176. package/dist/transformers/entrypoint/index.d.ts +2 -0
  177. package/dist/transformers/entrypoint/index.d.ts.map +1 -0
  178. package/dist/transformers/index.d.ts +6 -0
  179. package/dist/transformers/index.d.ts.map +1 -0
  180. package/dist/transformers/json-schema/comment.renderer.d.ts +8 -0
  181. package/dist/transformers/json-schema/comment.renderer.d.ts.map +1 -0
  182. package/dist/transformers/json-schema/declaration.renderer.d.ts +26 -0
  183. package/dist/transformers/json-schema/declaration.renderer.d.ts.map +1 -0
  184. package/dist/transformers/json-schema/index.d.ts +4 -0
  185. package/dist/transformers/json-schema/index.d.ts.map +1 -0
  186. package/dist/transformers/json-schema/json-schema.transformer.d.ts +7 -0
  187. package/dist/transformers/json-schema/json-schema.transformer.d.ts.map +1 -0
  188. package/dist/transformers/json-schema/reference.transformer.d.ts +5 -0
  189. package/dist/transformers/json-schema/reference.transformer.d.ts.map +1 -0
  190. package/dist/transformers/json-schema/types/any-other-attribute.d.ts.map +1 -0
  191. package/dist/transformers/json-schema/types/index.d.ts +3 -0
  192. package/dist/transformers/json-schema/types/index.d.ts.map +1 -0
  193. package/dist/transformers/json-schema/types/mixed-schema-object.d.ts.map +1 -0
  194. package/dist/transformers/operation-definition/comment.renderer.d.ts +8 -0
  195. package/dist/transformers/operation-definition/comment.renderer.d.ts.map +1 -0
  196. package/dist/transformers/operation-definition/declaration.renderer.d.ts +20 -0
  197. package/dist/transformers/operation-definition/declaration.renderer.d.ts.map +1 -0
  198. package/dist/transformers/operation-definition/index.d.ts +3 -0
  199. package/dist/transformers/operation-definition/index.d.ts.map +1 -0
  200. package/dist/transformers/operation-definition/micro-function.renderer.d.ts +19 -0
  201. package/dist/transformers/operation-definition/micro-function.renderer.d.ts.map +1 -0
  202. package/dist/transformers/operation-definition/nestjs-method.renderer.d.ts +15 -0
  203. package/dist/transformers/operation-definition/nestjs-method.renderer.d.ts.map +1 -0
  204. package/dist/transformers/operation-definition/operation-definition.transformer.d.ts +11 -0
  205. package/dist/transformers/operation-definition/operation-definition.transformer.d.ts.map +1 -0
  206. package/dist/transformers/operation-definition/typescript-snippet.d.ts +22 -0
  207. package/dist/transformers/operation-definition/typescript-snippet.d.ts.map +1 -0
  208. package/dist/transformers/operation-definition/utils/index.d.ts +2 -0
  209. package/dist/transformers/operation-definition/utils/index.d.ts.map +1 -0
  210. package/dist/transformers/operation-definition/utils/type-name-factory.d.ts +4 -0
  211. package/dist/transformers/operation-definition/utils/type-name-factory.d.ts.map +1 -0
  212. package/dist/transformers/schema-definition/index.d.ts +2 -0
  213. package/dist/transformers/schema-definition/index.d.ts.map +1 -0
  214. package/dist/transformers/schema-definition/schema-definition.transformer.d.ts +10 -0
  215. package/dist/transformers/schema-definition/schema-definition.transformer.d.ts.map +1 -0
  216. package/dist/transformers/types/renderer.d.ts +4 -0
  217. package/dist/transformers/types/renderer.d.ts.map +1 -0
  218. package/dist/types/generator.d.ts +7 -0
  219. package/dist/types/generator.d.ts.map +1 -0
  220. package/dist/types/index.d.ts +1 -2
  221. package/dist/types/index.d.ts.map +1 -1
  222. package/dist/types/runtime-config.d.ts +2 -17
  223. package/dist/types/runtime-config.d.ts.map +1 -1
  224. package/dist/utils/ignore-matcher.d.ts +1 -2
  225. package/dist/utils/ignore-matcher.d.ts.map +1 -1
  226. package/dist/utils/indent.d.ts +2 -0
  227. package/dist/utils/indent.d.ts.map +1 -0
  228. package/dist/utils/openapi-utils/index.d.ts +6 -2
  229. package/dist/utils/openapi-utils/index.d.ts.map +1 -1
  230. package/dist/utils/openapi-utils/map-operation.d.ts +4 -0
  231. package/dist/utils/openapi-utils/map-operation.d.ts.map +1 -0
  232. package/dist/utils/openapi-utils/map-parameter.d.ts +4 -0
  233. package/dist/utils/openapi-utils/map-parameter.d.ts.map +1 -0
  234. package/dist/utils/openapi-utils/to-3_1.d.ts +3 -0
  235. package/dist/utils/openapi-utils/to-3_1.d.ts.map +1 -0
  236. package/package.json +3 -3
  237. package/dist/renderer/json-schema/index.d.ts +0 -3
  238. package/dist/renderer/json-schema/index.d.ts.map +0 -1
  239. package/dist/renderer/operation-request/error-to-comment.d.ts +0 -2
  240. package/dist/renderer/operation-request/error-to-comment.d.ts.map +0 -1
  241. package/dist/renderer/operation-request/index.d.ts +0 -8
  242. package/dist/renderer/operation-request/index.d.ts.map +0 -1
  243. package/dist/renderer/operation-request/request-body.d.ts +0 -4
  244. package/dist/renderer/operation-request/request-body.d.ts.map +0 -1
  245. package/dist/renderer/operation-type/index.d.ts +0 -6
  246. package/dist/renderer/operation-type/index.d.ts.map +0 -1
  247. package/dist/renderer/request/index.d.ts +0 -2
  248. package/dist/renderer/request/index.d.ts.map +0 -1
  249. package/dist/renderer/types/any-other-attribute.d.ts.map +0 -1
  250. package/dist/renderer/types/mixed-schema-object.d.ts.map +0 -1
  251. package/dist/renderer/utils/generate-schema.d.ts +0 -6
  252. package/dist/renderer/utils/generate-schema.d.ts.map +0 -1
  253. package/dist/tasks/compile/index.d.ts +0 -6
  254. package/dist/tasks/compile/index.d.ts.map +0 -1
  255. package/dist/tasks/compile/utils/compile-operation-definition.d.ts +0 -15
  256. package/dist/tasks/compile/utils/compile-operation-definition.d.ts.map +0 -1
  257. package/dist/tasks/compile/utils/compile-schema-definition.d.ts +0 -13
  258. package/dist/tasks/compile/utils/compile-schema-definition.d.ts.map +0 -1
  259. package/dist/tasks/download/index.d.ts.map +0 -1
  260. package/dist/tasks/index.d.ts +0 -10
  261. package/dist/tasks/index.d.ts.map +0 -1
  262. package/dist/tasks/interactive/index.d.ts +0 -15
  263. package/dist/tasks/interactive/index.d.ts.map +0 -1
  264. package/dist/tasks/interactive/utils/select-operation-definitions.d.ts +0 -5
  265. package/dist/tasks/interactive/utils/select-operation-definitions.d.ts.map +0 -1
  266. package/dist/tasks/persist/index.d.ts +0 -6
  267. package/dist/tasks/persist/index.d.ts.map +0 -1
  268. package/dist/tasks/setup/index.d.ts.map +0 -1
  269. package/dist/tasks/setup/utils/find-nearest-package-json.d.ts.map +0 -1
  270. package/dist/tasks/setup/utils/get-project-module-system.d.ts.map +0 -1
  271. package/dist/tasks/setup/utils/index.d.ts.map +0 -1
  272. package/dist/tasks/setup/utils/validate-modules.d.ts.map +0 -1
  273. package/dist/tasks/shaking/index.d.ts +0 -10
  274. package/dist/tasks/shaking/index.d.ts.map +0 -1
  275. package/dist/tasks/types/base-task-options.d.ts +0 -6
  276. package/dist/tasks/types/base-task-options.d.ts.map +0 -1
  277. package/dist/tasks/types/file.d.ts +0 -4
  278. package/dist/tasks/types/file.d.ts.map +0 -1
  279. package/dist/tasks/types/ignore-mode.d.ts.map +0 -1
  280. package/dist/tasks/types/index.d.ts +0 -6
  281. package/dist/tasks/types/index.d.ts.map +0 -1
  282. package/dist/tasks/types/task-context.d.ts +0 -28
  283. package/dist/tasks/types/task-context.d.ts.map +0 -1
  284. package/dist/tasks/types/task-wrapper.d.ts +0 -4
  285. package/dist/tasks/types/task-wrapper.d.ts.map +0 -1
  286. package/dist/tasks/utils/anchor.d.ts.map +0 -1
  287. package/dist/tasks/utils/api-document.d.ts +0 -18
  288. package/dist/tasks/utils/api-document.d.ts.map +0 -1
  289. package/dist/tasks/utils/api-document_v3_1.d.ts.map +0 -1
  290. package/dist/tasks/utils/artifact.d.ts +0 -27
  291. package/dist/tasks/utils/artifact.d.ts.map +0 -1
  292. package/dist/tasks/utils/dependency.d.ts +0 -24
  293. package/dist/tasks/utils/dependency.d.ts.map +0 -1
  294. package/dist/tasks/utils/index.d.ts.map +0 -1
  295. package/dist/tasks/utils/json-schema.d.ts +0 -8
  296. package/dist/tasks/utils/json-schema.d.ts.map +0 -1
  297. package/dist/tasks/utils/module-definition.d.ts.map +0 -1
  298. package/dist/tasks/utils/operation-definition.d.ts.map +0 -1
  299. package/dist/tasks/utils/proxy-task-wrapper.d.ts +0 -3
  300. package/dist/tasks/utils/proxy-task-wrapper.d.ts.map +0 -1
  301. package/dist/tasks/utils/schema-definition.d.ts.map +0 -1
  302. package/dist/tasks/utils/to-comment.d.ts.map +0 -1
  303. package/dist/tasks/validate/index.d.ts +0 -6
  304. package/dist/tasks/validate/index.d.ts.map +0 -1
  305. package/dist/types/operation-id-factory.d.ts +0 -10
  306. package/dist/types/operation-id-factory.d.ts.map +0 -1
  307. package/dist/types/qs.d.ts +0 -9
  308. package/dist/types/qs.d.ts.map +0 -1
  309. package/dist/utils/openapi-utils/update-operation-id.d.ts +0 -5
  310. package/dist/utils/openapi-utils/update-operation-id.d.ts.map +0 -1
  311. /package/dist/{tasks → compiler/tasks}/setup/utils/find-nearest-package-json.d.ts +0 -0
  312. /package/dist/{tasks → compiler/tasks}/setup/utils/get-project-module-system.d.ts +0 -0
  313. /package/dist/{tasks → compiler/tasks}/setup/utils/index.d.ts +0 -0
  314. /package/dist/{tasks → compiler/tasks}/setup/utils/validate-modules.d.ts +0 -0
  315. /package/dist/{tasks/utils → models}/anchor.d.ts +0 -0
  316. /package/dist/{tasks → models}/utils/to-comment.d.ts +0 -0
  317. /package/dist/{tasks → plugins/terminal-select}/types/ignore-mode.d.ts +0 -0
  318. /package/dist/{renderer → transformers/json-schema}/types/any-other-attribute.d.ts +0 -0
  319. /package/dist/{renderer → transformers/json-schema}/types/mixed-schema-object.d.ts +0 -0
package/dist/plugins.js CHANGED
@@ -11,14 +11,14 @@ var EslintPlugin = class _EslintPlugin {
11
11
  ...this.options.disable.map((rule) => `/* eslint-disable ${rule} */`)
12
12
  ].join("\n");
13
13
  compiler.hooks.afterCompile.tap(_EslintPlugin.name, () => {
14
- const artifacts = compiler.context.compiled?.artifacts || [];
14
+ const artifacts = compiler.context.artifacts || [];
15
15
  for (const artifact of artifacts) {
16
16
  artifact.anchor.append("file:start", $rules);
17
17
  }
18
18
  });
19
19
  }
20
20
  compiler.hooks.afterPersist.tapPromise(_EslintPlugin.name, async (task) => {
21
- const files = compiler.context.persisted?.files || [];
21
+ const files = compiler.context.assets || [];
22
22
  if (files.length === 0) return;
23
23
  const eslint = new ESLint({ fix: true });
24
24
  const results = await eslint.lintFiles(files.map((file) => file.path));
@@ -27,7 +27,7 @@ var EslintPlugin = class _EslintPlugin {
27
27
  }
28
28
  };
29
29
 
30
- // src/plugins/prettier/index.ts
30
+ // src/plugins/prettier/prettier.plugin.ts
31
31
  import { exec } from "child_process";
32
32
  import { promisify } from "util";
33
33
  var execAsync = promisify(exec);
@@ -35,7 +35,7 @@ var PrettierPlugin = class _PrettierPlugin {
35
35
  apply(compiler) {
36
36
  if (!compiler.options.build) return;
37
37
  compiler.hooks.afterPersist.tapPromise(_PrettierPlugin.name, async () => {
38
- const files = compiler.context.persisted?.files || [];
38
+ const files = compiler.context.assets || [];
39
39
  if (files.length === 0) return;
40
40
  const filePaths = files.map((file) => file.path).join(" ");
41
41
  await execAsync(`prettier --write ${filePaths}`);
@@ -44,7 +44,7 @@ var PrettierPlugin = class _PrettierPlugin {
44
44
  };
45
45
 
46
46
  // src/plugins/body-fallback/index.ts
47
- import * as R from "ramda";
47
+ import * as R19 from "ramda";
48
48
 
49
49
  // src/utils/json-schema-utils/is-array.ts
50
50
  function isArray(schema) {
@@ -74,39 +74,2292 @@ var JsonSchemaUtils = class {
74
74
  static isMixed = isMixed;
75
75
  };
76
76
 
77
+ // src/plugins/generate-micro-function/generate-micro-function.plugin.ts
78
+ import { AsyncSeriesWaterfallHook as AsyncSeriesWaterfallHook2 } from "tapable";
79
+
80
+ // src/plugins/generate-micro-function/constants/metadata-storage.ts
81
+ var MetadataStorage = /* @__PURE__ */ new WeakMap();
82
+
83
+ // src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
84
+ import * as R18 from "ramda";
85
+ import * as path7 from "path";
86
+ import * as changeCase6 from "change-case";
87
+
88
+ // src/models/artifact.ts
89
+ import * as path from "path";
90
+
91
+ // src/models/anchor.ts
92
+ var AnchorBlock = class {
93
+ constructor(artifact) {
94
+ this.artifact = artifact;
95
+ }
96
+ /**
97
+ * Append content to the end of the anchor block.
98
+ */
99
+ append(anchorName, content) {
100
+ const lines = this.artifact.content.split("\n");
101
+ const anchor = `@anchor:${anchorName}:end`;
102
+ const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
103
+ if (anchorIndex === -1) {
104
+ throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
105
+ }
106
+ lines.splice(anchorIndex, 0, content);
107
+ this.artifact.content = lines.join("\n");
108
+ }
109
+ prepend(anchorName, content) {
110
+ const lines = this.artifact.content.split("\n");
111
+ const anchor = `@anchor:${anchorName}:start`;
112
+ const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
113
+ if (anchorIndex === -1) {
114
+ throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
115
+ }
116
+ lines.splice(anchorIndex + 1, 0, content);
117
+ this.artifact.content = lines.join("\n");
118
+ }
119
+ replace(anchorName, content) {
120
+ const lines = this.artifact.content.split("\n");
121
+ const startIndex = lines.findIndex((line) => line.includes(`/* @anchor:${anchorName}:start */`));
122
+ const endIndex = lines.findIndex((line) => line.includes(`/* @anchor:${anchorName}:end */`));
123
+ if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
124
+ throw new Error(`"@anchor:${anchorName}:start" or "@anchor:${anchorName}:end" not found in artifact "${this.artifact.filepath}".`);
125
+ }
126
+ lines.splice(startIndex + 1, endIndex - startIndex - 1, content);
127
+ this.artifact.content = lines.join("\n");
128
+ }
129
+ };
130
+ var Anchor = class {
131
+ constructor(artifact) {
132
+ this.artifact = artifact;
133
+ this.block = new AnchorBlock(artifact);
134
+ }
135
+ block;
136
+ append(anchorName, content) {
137
+ const lines = this.artifact.content.split("\n");
138
+ const anchor = `@anchor:${anchorName}`;
139
+ const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
140
+ if (anchorIndex === -1) {
141
+ throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
142
+ }
143
+ lines.splice(anchorIndex + 1, 0, content);
144
+ this.artifact.content = lines.join("\n");
145
+ }
146
+ prepend(anchorName, content) {
147
+ const lines = this.artifact.content.split("\n");
148
+ const anchor = `@anchor:${anchorName}`;
149
+ const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
150
+ if (anchorIndex === -1) {
151
+ throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
152
+ }
153
+ lines.splice(anchorIndex, 0, content);
154
+ this.artifact.content = lines.join("\n");
155
+ }
156
+ };
157
+
158
+ // src/models/artifact.ts
159
+ var HeaderComment = [
160
+ "// Code generated by keq-cli. DO NOT EDIT.",
161
+ "// Code generated by keq-cli. DO NOT EDIT.",
162
+ "// Code generated by keq-cli. DO NOT EDIT.",
163
+ "",
164
+ ""
165
+ ].join("\n");
166
+ var Artifact = class {
167
+ id;
168
+ filepath;
169
+ content;
170
+ extensionName;
171
+ anchor = new Anchor(this);
172
+ constructor(options) {
173
+ this.id = options.id;
174
+ this.filepath = options.filepath;
175
+ this.extensionName = options.extensionName || path.extname(options.filepath);
176
+ this.content = options.content;
177
+ }
178
+ get dirname() {
179
+ return path.dirname(this.filepath);
180
+ }
181
+ renderer() {
182
+ return `${HeaderComment}${this.content}`;
183
+ }
184
+ };
185
+
186
+ // src/models/api-document_v3_1.ts
187
+ import * as R3 from "ramda";
188
+
189
+ // src/models/module-definition.ts
190
+ var ModuleDefinition = class _ModuleDefinition {
191
+ name;
192
+ address;
193
+ constructor(name, address) {
194
+ this.name = name;
195
+ this.address = address;
196
+ }
197
+ static unknown() {
198
+ return new _ModuleDefinition("", "");
199
+ }
200
+ };
201
+
202
+ // src/constants/supported-methods.ts
203
+ var SupportedMethods = [
204
+ "get",
205
+ "post",
206
+ "put",
207
+ "delete",
208
+ "patch",
209
+ "head",
210
+ "options"
211
+ ];
212
+
213
+ // src/models/operation-definition.ts
214
+ import * as R2 from "ramda";
215
+
216
+ // src/utils/is-keywords.ts
217
+ var keywords = [
218
+ "break",
219
+ "case",
220
+ "catch",
221
+ "continue",
222
+ "default",
223
+ "delete",
224
+ "do",
225
+ "else",
226
+ "finally",
227
+ "for",
228
+ "function",
229
+ "if",
230
+ "in",
231
+ "instanceof",
232
+ "new",
233
+ "return",
234
+ "switch",
235
+ "this",
236
+ "throw",
237
+ "try",
238
+ "typeof",
239
+ "var",
240
+ "void",
241
+ "while",
242
+ "with"
243
+ ];
244
+ function isKeywords(str) {
245
+ return keywords.includes(str);
246
+ }
247
+
248
+ // src/utils/is-reserved-word.ts
249
+ var reservedWords = [
250
+ "abstract",
251
+ "boolean",
252
+ "byte",
253
+ "char",
254
+ "class",
255
+ "const",
256
+ "debugger",
257
+ "double",
258
+ "enum",
259
+ "export",
260
+ "extends",
261
+ "final",
262
+ "float",
263
+ "goto",
264
+ "implements",
265
+ "import",
266
+ "int",
267
+ "interface",
268
+ "long",
269
+ "native",
270
+ "package",
271
+ "private",
272
+ "protected",
273
+ "public",
274
+ "short",
275
+ "static",
276
+ "super",
277
+ "synchronized",
278
+ "throws",
279
+ "transient",
280
+ "volatile"
281
+ ];
282
+ function isReservedWord(str) {
283
+ return reservedWords.includes(str);
284
+ }
285
+
286
+ // src/models/operation-definition.ts
287
+ import { JSONPath as JSONPath2 } from "jsonpath-plus";
288
+
289
+ // src/models/schema-definition.ts
290
+ import * as R from "ramda";
291
+ import { JSONPath } from "jsonpath-plus";
292
+ var SchemaDefinition = class _SchemaDefinition {
293
+ name;
294
+ schema;
295
+ module;
296
+ document;
297
+ get id() {
298
+ return `${this.module.address}#/components/schemas/${this.name}`;
299
+ }
300
+ constructor(args) {
301
+ this.module = args.module;
302
+ this.name = args.name;
303
+ this.schema = args.schema;
304
+ this.document = args.document;
305
+ }
306
+ getDependencies() {
307
+ const refs = R.uniq(JSONPath({
308
+ path: "$..*['$ref']",
309
+ json: this.schema
310
+ }));
311
+ return refs.filter((ref) => typeof ref === "string" && !!ref.trim()).map((ref) => {
312
+ const definition = this.document.dereference(ref);
313
+ if (definition) return definition;
314
+ return _SchemaDefinition.unknown();
315
+ });
316
+ }
317
+ static unknown() {
318
+ return new _SchemaDefinition({
319
+ name: "",
320
+ schema: {},
321
+ module: ModuleDefinition.unknown(),
322
+ document: ApiDocumentV3_1.unknown()
323
+ });
324
+ }
325
+ static isUnknown(definition) {
326
+ return definition.name === "";
327
+ }
328
+ };
329
+
330
+ // src/models/operation-definition.ts
331
+ var OperationDefinition = class {
332
+ module;
333
+ operationId;
334
+ method;
335
+ pathname;
336
+ operation;
337
+ document;
338
+ get id() {
339
+ return `${this.module.address}#/paths/${this.pathname}/${this.method}`;
340
+ }
341
+ constructor(args) {
342
+ this.module = args.module;
343
+ this.method = args.method.toLowerCase();
344
+ this.pathname = args.pathname;
345
+ this.document = args.document;
346
+ this.operationId = this.formatOperationId(args.method, args.pathname, args.operation);
347
+ this.operation = {
348
+ ...args.operation,
349
+ operationId: this.operationId
350
+ };
351
+ }
352
+ formatOperationId(method, pathname, operation) {
353
+ const operationId = operation.operationId;
354
+ if (operationId && operationId !== "index" && !isKeywords(operationId) && !isReservedWord(operationId)) {
355
+ return operationId;
356
+ }
357
+ return `${method}_${pathname}`.replace(/\//g, "_").replace(/-/g, "_").replace(/:/g, "$$").replace(/{(.+)}/, "$$$1");
358
+ }
359
+ getDependencies() {
360
+ const refs = R2.uniq([
361
+ ...JSONPath2({
362
+ path: "$.requestBody.content..schema..$ref",
363
+ json: this.operation
364
+ }),
365
+ ...JSONPath2({
366
+ path: "$.responses..content..schema..$ref",
367
+ json: this.operation
368
+ }),
369
+ ...JSONPath2({
370
+ path: "$.parameters..schema..$ref",
371
+ json: this.operation
372
+ })
373
+ ]);
374
+ const dependencies = refs.filter((ref) => typeof ref === "string" && ref).map((ref) => {
375
+ const schemaDefinition = this.document.dereference(ref);
376
+ if (schemaDefinition) return schemaDefinition;
377
+ return SchemaDefinition.unknown();
378
+ });
379
+ return dependencies;
380
+ }
381
+ };
382
+
383
+ // src/utils/logger.ts
384
+ import chalk from "chalk";
385
+ var logger = {
386
+ log: (str) => console.log(chalk.green(str)),
387
+ warn: (str) => console.warn(chalk.yellow(str)),
388
+ error: (str) => console.error(chalk.red(str))
389
+ };
390
+
391
+ // src/models/api-document_v3_1.ts
392
+ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
393
+ module;
394
+ specification;
395
+ constructor(specification, module) {
396
+ this.module = module;
397
+ this.specification = specification;
398
+ }
399
+ get schemas() {
400
+ const module = this.module;
401
+ return Object.entries(this.specification.components?.schemas || {}).map(([name, schema]) => new SchemaDefinition({
402
+ name,
403
+ schema,
404
+ module,
405
+ document: this
406
+ }));
407
+ }
408
+ get operations() {
409
+ const module = this.module;
410
+ return Object.entries(this.specification.paths || {}).flatMap(([pathname, pathItem]) => Object.entries(pathItem || {}).filter(([method]) => SupportedMethods.includes(method.toLowerCase())).map(([method, operation]) => new OperationDefinition({
411
+ method,
412
+ pathname,
413
+ operation,
414
+ module,
415
+ document: this
416
+ })));
417
+ }
418
+ isEmpty() {
419
+ return R3.isEmpty(this.specification.paths);
420
+ }
421
+ dereference($ref) {
422
+ if ($ref.startsWith("#/")) {
423
+ return this.schemas.find((schema) => schema.id.endsWith($ref));
424
+ }
425
+ logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} openapi/swagger.`);
426
+ }
427
+ isRefDefined($ref) {
428
+ if ($ref.startsWith("#/")) {
429
+ const path10 = $ref.replace("#/", "").split("/");
430
+ return R3.path(path10, this.specification) !== void 0;
431
+ }
432
+ return false;
433
+ }
434
+ static unknown() {
435
+ return new _ApiDocumentV3_1({}, ModuleDefinition.unknown());
436
+ }
437
+ };
438
+
439
+ // src/plugins/generate-declaration/generate-declaration.plugin.ts
440
+ import { AsyncSeriesWaterfallHook } from "tapable";
441
+
442
+ // src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
443
+ import * as path6 from "path";
444
+ import * as changeCase5 from "change-case";
445
+
446
+ // src/transformers/json-schema/comment.renderer.ts
447
+ var CommentRenderer = class {
448
+ constructor(schema) {
449
+ this.schema = schema;
450
+ }
451
+ render() {
452
+ const schema = this.schema;
453
+ const lines = ["/**"];
454
+ if (schema.description) {
455
+ const description = schema.description.replace("*/", "*\\/");
456
+ lines.push(...description.split("\n").map((line) => ` * ${line}`));
457
+ }
458
+ if (schema.deprecated) {
459
+ lines.push(" * @deprecated");
460
+ }
461
+ if (schema.readOnly) {
462
+ lines.push(" * @readonly");
463
+ }
464
+ if (schema.format) {
465
+ lines.push(` * @format ${schema.format}`);
466
+ }
467
+ lines.push(" */");
468
+ if (lines.length === 2) return "";
469
+ return lines.join("\n");
470
+ }
471
+ };
472
+
473
+ // src/transformers/json-schema/declaration.renderer.ts
474
+ import * as R5 from "ramda";
475
+
476
+ // src/utils/indent.ts
477
+ function indent(space, text) {
478
+ if (text === "") return "";
479
+ const indentation = " ".repeat(space);
480
+ return text.split("\n").map((line) => line ? `${indentation}${line}` : line).join("\n");
481
+ }
482
+
483
+ // src/transformers/json-schema/reference.transformer.ts
484
+ import * as R4 from "ramda";
485
+ var ReferenceTransformer = class {
486
+ static toDeclaration(schema, alias2 = R4.identity) {
487
+ if (!schema.$ref || !schema.$ref.startsWith("#")) return `unknown /* ${schema.$ref.replace("*/", "*\\/")} */`;
488
+ const parts = schema.$ref.split("/");
489
+ return alias2(parts[parts.length - 1]) || "unknown";
490
+ }
491
+ };
492
+
493
+ // src/transformers/json-schema/declaration.renderer.ts
494
+ var DeclarationRenderer = class {
495
+ constructor(schema, options = {}) {
496
+ this.schema = schema;
497
+ this.options = options;
498
+ }
499
+ render() {
500
+ return this.renderSchema(this.schema);
501
+ }
502
+ renderSchema(schema) {
503
+ if (typeof schema === "boolean") return "unknown";
504
+ if (JsonSchemaUtils.isRef(schema)) return this.renderReference(schema);
505
+ if (JsonSchemaUtils.isMixed(schema)) return this.renderMixed(schema);
506
+ if (JsonSchemaUtils.isArray(schema)) return this.renderArray(schema);
507
+ if (schema.type === "object") return this.renderObject(schema);
508
+ if (schema.enum) return this.renderEnum(schema);
509
+ if (schema.oneOf) return this.renderOneOf(schema);
510
+ if (schema.anyOf) return this.renderAnyOf(schema);
511
+ if (schema.allOf) return this.renderAllOf(schema);
512
+ if (schema.type === "string") return this.renderString(schema);
513
+ if (schema.type === "number") return this.renderNumber(schema);
514
+ if (schema.type === "boolean") return this.renderBoolean(schema);
515
+ if (schema.type === "null") return this.renderNull(schema);
516
+ if (schema.type === "integer") return this.renderInteger(schema);
517
+ return "unknown";
518
+ }
519
+ renderMixed(schema) {
520
+ if (Array.isArray(schema.type)) {
521
+ schema.type.map((type) => ({ ...schema, type })).map((schema2) => this.renderSchema(schema2)).join(" | ");
522
+ }
523
+ return "unknown";
524
+ }
525
+ renderReference(schema) {
526
+ if (!this.options.referenceTransformer) {
527
+ return ReferenceTransformer.toDeclaration(schema);
528
+ }
529
+ return this.options.referenceTransformer(schema);
530
+ }
531
+ renderArray(schema) {
532
+ if (schema.items && Array.isArray(schema.items)) {
533
+ const items = schema.items.map((s) => this.renderSchema(s)).join(", ");
534
+ return `[${items}]`;
535
+ }
536
+ if (schema.items && typeof schema.items === "object") {
537
+ return `${this.renderSchema(schema.items)}[]`;
538
+ }
539
+ return "any[]";
540
+ }
541
+ renderObject(schema) {
542
+ if ((!schema.properties || R5.isEmpty(schema.properties)) && (!schema.additionalProperties || R5.isEmpty(schema.additionalProperties))) {
543
+ return "object";
544
+ }
545
+ const $properties = Object.entries(schema.properties || {}).map(([propertyName, propertySchema]) => {
546
+ let $comment = new CommentRenderer(propertySchema).render();
547
+ if ($comment) $comment += "\n";
548
+ const $key = `"${propertyName}"${schema.required?.includes(propertyName) ? "" : "?"}`;
549
+ const $value = this.renderSchema(propertySchema);
550
+ return indent(2, `${$comment}${$key}: ${$value}`);
551
+ });
552
+ if (schema.additionalProperties) {
553
+ const $value = schema.additionalProperties === true ? "any" : this.renderSchema(schema.additionalProperties);
554
+ $properties.push(indent(2, `[key: string]: ${$value}`));
555
+ }
556
+ return [
557
+ "{",
558
+ ...$properties,
559
+ "}"
560
+ ].join("\n");
561
+ }
562
+ renderOneOf(schema) {
563
+ if (!schema.oneOf) return "unknown";
564
+ return schema.oneOf.map((s) => this.renderSchema(s)).join(" | ");
565
+ }
566
+ renderAnyOf(schema) {
567
+ if (!schema.anyOf) return "unknown";
568
+ return schema.anyOf.map((s) => this.renderSchema(s)).join(" | ");
569
+ }
570
+ renderAllOf(schema) {
571
+ if (!schema.allOf) return "unknown";
572
+ return schema.allOf.map((s) => this.renderSchema(s)).join(" & ");
573
+ }
574
+ renderEnum(schema) {
575
+ if (!schema.enum) return "unknown";
576
+ return schema.enum.map((v) => JSON.stringify(v)).join(" | ");
577
+ }
578
+ renderString(schema) {
579
+ if (schema.contentMediaType === "application/octet-stream") return "Blob | Buffer";
580
+ if (schema.format === "binary") return "Blob | Buffer";
581
+ return "string";
582
+ }
583
+ renderNumber(schema) {
584
+ return "number";
585
+ }
586
+ renderBoolean(schema) {
587
+ return "boolean";
588
+ }
589
+ renderNull(schema) {
590
+ return "null";
591
+ }
592
+ renderInteger(schema) {
593
+ return "number";
594
+ }
595
+ };
596
+
597
+ // src/transformers/json-schema/json-schema.transformer.ts
598
+ var JsonSchemaTransformer = class {
599
+ static toComment(schema) {
600
+ return new CommentRenderer(schema).render();
601
+ }
602
+ static toDeclaration(schema, options) {
603
+ return new DeclarationRenderer(schema, options).render();
604
+ }
605
+ };
606
+
607
+ // src/transformers/schema-definition/schema-definition.transformer.ts
608
+ import * as R6 from "ramda";
609
+ var SchemaDefinitionTransformer = class {
610
+ static toDeclaration(schemaDefinition, options) {
611
+ const dependencies = schemaDefinition.getDependencies();
612
+ let $dependencies = dependencies.filter((dep) => !SchemaDefinition.isUnknown(dep)).map((dep) => {
613
+ const filepath = options.getDependentSchemaDefinitionFilepath(dep);
614
+ return `import type { ${dep.name} } from "${filepath}"`;
615
+ }).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
616
+ if ($dependencies) $dependencies += "\n";
617
+ let $comment = JsonSchemaTransformer.toComment(schemaDefinition.schema);
618
+ if ($comment) $comment += "\n";
619
+ if (typeof schemaDefinition.schema === "boolean") {
620
+ return [
621
+ "/* @anchor:file:start */",
622
+ "",
623
+ $dependencies,
624
+ $comment || void 0,
625
+ `type ${schemaDefinition.name} = unknown`,
626
+ "",
627
+ "/* @anchor:file:end */"
628
+ ].filter(R6.isNotNil).join("\n");
629
+ }
630
+ if (JsonSchemaUtils.isNonArray(schemaDefinition.schema) && schemaDefinition.schema.type === "object") {
631
+ const $schema = JsonSchemaTransformer.toDeclaration(schemaDefinition.schema);
632
+ const $declaration = $schema.startsWith("{") ? `export interface ${schemaDefinition.name} ${$schema}` : `export type ${schemaDefinition.name} = ${$schema}`;
633
+ return [
634
+ "/* @anchor:file:start */",
635
+ "",
636
+ $dependencies,
637
+ $comment || void 0,
638
+ $declaration,
639
+ "",
640
+ "/* @anchor:file:end */"
641
+ ].filter(R6.isNotNil).join("\n");
642
+ }
643
+ return [
644
+ "/* @anchor:file:start */",
645
+ "",
646
+ $dependencies,
647
+ $comment || void 0,
648
+ `export type ${schemaDefinition.name} = ${JsonSchemaTransformer.toDeclaration(schemaDefinition.schema)}`,
649
+ "",
650
+ "/* @anchor:file:end */"
651
+ ].filter(R6.isNotNil).join("\n");
652
+ }
653
+ };
654
+
655
+ // src/transformers/operation-definition/comment.renderer.ts
656
+ import * as R7 from "ramda";
657
+ var CommentRenderer2 = class {
658
+ constructor(operationDefinition) {
659
+ this.operationDefinition = operationDefinition;
660
+ }
661
+ render() {
662
+ const operation = this.operationDefinition.operation;
663
+ if (!operation.summary && !operation.description) return "";
664
+ const lines = ["/**"];
665
+ if (operation.summary && typeof operation.summary === "string") {
666
+ lines.push(` * ${R7.trim(operation.summary)}`);
667
+ lines.push(" *");
668
+ }
669
+ if (operation.description && typeof operation.description === "string") {
670
+ lines.push(` * @description ${R7.trim(operation.description)}`);
671
+ }
672
+ lines.push(" */");
673
+ return lines.join("\n");
674
+ }
675
+ };
676
+
677
+ // src/transformers/operation-definition/declaration.renderer.ts
678
+ import * as R12 from "ramda";
679
+
680
+ // src/transformers/operation-definition/utils/type-name-factory.ts
681
+ import * as changeCase from "change-case";
682
+ function typeNameFactory(operationDefinition) {
683
+ const pascalCaseOperationId = changeCase.pascalCase(operationDefinition.operationId);
684
+ return (name) => `${pascalCaseOperationId}${name}`;
685
+ }
686
+
687
+ // src/utils/openapi-utils/dereference.ts
688
+ function dereference($ref, swagger) {
689
+ let value;
690
+ for (const key of $ref.split("/")) {
691
+ if (key === "#") {
692
+ value = swagger;
693
+ } else {
694
+ value = value[key];
695
+ }
696
+ if (!value) break;
697
+ }
698
+ return value;
699
+ }
700
+
701
+ // src/utils/openapi-utils/dereference-operation.ts
702
+ import * as R10 from "ramda";
703
+ import jsonpointer2 from "jsonpointer";
704
+ import { JSONPath as JSONPath4 } from "jsonpath-plus";
705
+
706
+ // src/utils/openapi-utils/remove-undefined-ref.ts
707
+ import * as R9 from "ramda";
708
+ import jsonpointer from "jsonpointer";
709
+ import { JSONPath as JSONPath3 } from "jsonpath-plus";
710
+
711
+ // src/utils/openapi-utils/is-ref-defined.ts
712
+ import * as R8 from "ramda";
713
+ function isRefDefined($ref, swagger) {
714
+ if ($ref.startsWith("#/")) {
715
+ const path10 = $ref.replace("#/", "").split("/");
716
+ return R8.path(path10, swagger) !== void 0;
717
+ }
718
+ return false;
719
+ }
720
+
721
+ // src/utils/openapi-utils/remove-undefined-ref.ts
722
+ function removeUndefinedRef(swagger) {
723
+ const shadow = R9.clone(swagger);
724
+ const matches = JSONPath3({
725
+ path: "$..*['$ref']^",
726
+ json: swagger,
727
+ resultType: "all"
728
+ });
729
+ for (const match of matches) {
730
+ if (match.value.$ref && !isRefDefined(match.value.$ref, swagger)) {
731
+ jsonpointer.set(shadow, match.pointer, R9.omit(["$ref"], match.value));
732
+ }
733
+ }
734
+ return shadow;
735
+ }
736
+
737
+ // src/utils/openapi-utils/dereference-operation.ts
738
+ function dereferencePathObject(swagger) {
739
+ const matches = JSONPath4({
740
+ path: "$.paths.*.$ref^",
741
+ json: swagger,
742
+ resultType: "all"
743
+ });
744
+ for (const match of matches) {
745
+ const value = dereference(match.value.$ref, swagger);
746
+ jsonpointer2.set(swagger, match.pointer, value);
747
+ }
748
+ }
749
+ function dereferenceRequestBody(swagger) {
750
+ const matches = JSONPath4({
751
+ path: "$.paths.*.*.requestBody.$ref^",
752
+ json: swagger,
753
+ resultType: "all"
754
+ });
755
+ for (const match of matches) {
756
+ const value = dereference(match.value.$ref, swagger);
757
+ jsonpointer2.set(swagger, match.pointer, value);
758
+ }
759
+ }
760
+ function dereferenceResponses(swagger) {
761
+ const matches = [
762
+ ...JSONPath4({
763
+ path: "$.paths.*.*.responses.*.$ref^",
764
+ json: swagger,
765
+ resultType: "all"
766
+ }),
767
+ ...JSONPath4({
768
+ path: "$.paths.*.*.responses.*.headers.*.$ref^",
769
+ json: swagger,
770
+ resultType: "all"
771
+ })
772
+ ];
773
+ for (const match of matches) {
774
+ const value = dereference(match.value.$ref, swagger);
775
+ jsonpointer2.set(swagger, match.pointer, value);
776
+ }
777
+ }
778
+ function dereferenceParameters(swagger) {
779
+ const matches = JSONPath4({
780
+ path: "$.paths.*.*.parameters.*.$ref^",
781
+ json: swagger,
782
+ resultType: "all"
783
+ });
784
+ for (const match of matches) {
785
+ const value = dereference(match.value.$ref, swagger);
786
+ jsonpointer2.set(swagger, match.pointer, value);
787
+ }
788
+ }
789
+ function dereferenceOperation(swagger) {
790
+ const shadow = R10.clone(swagger);
791
+ dereferencePathObject(shadow);
792
+ dereferenceRequestBody(shadow);
793
+ dereferenceResponses(shadow);
794
+ dereferenceParameters(shadow);
795
+ return removeUndefinedRef(shadow);
796
+ }
797
+
798
+ // src/utils/openapi-utils/dereference-deep.ts
799
+ function dereferenceDeep($ref, swagger) {
800
+ const stack = [$ref];
801
+ let value;
802
+ while (true) {
803
+ const last = stack[stack.length - 1];
804
+ value = dereference(last, swagger);
805
+ if (JsonSchemaUtils.isRef(value)) {
806
+ if (!stack.includes(value.$ref)) {
807
+ stack.push(value.$ref);
808
+ continue;
809
+ } else {
810
+ throw new Error(`Circular reference detected: ${stack.join(" -> ")} -> ${value.$ref}`);
811
+ }
812
+ }
813
+ break;
814
+ }
815
+ return value;
816
+ }
817
+
818
+ // src/utils/openapi-utils/to-3_1.ts
819
+ import { upgrade } from "@scalar/openapi-parser";
820
+ function To3_1(openapi) {
821
+ const { specification } = upgrade(openapi);
822
+ return specification;
823
+ }
824
+
825
+ // src/utils/openapi-utils/map-operation.ts
826
+ import * as R11 from "ramda";
827
+ function mapOperation(specification, mapper) {
828
+ const shadow = R11.clone(specification);
829
+ for (const [pathname, pathItem] of Object.entries(shadow.paths || {})) {
830
+ for (const m in pathItem) {
831
+ const method = m.toLowerCase();
832
+ if (!SupportedMethods.includes(method)) continue;
833
+ if (typeof pathItem[m] !== "object" || Array.isArray(pathItem[m]) || pathItem[m] === null) continue;
834
+ const operation = pathItem[m];
835
+ pathItem[m] = mapper(method, pathname, operation);
836
+ }
837
+ }
838
+ return shadow;
839
+ }
840
+
841
+ // src/utils/openapi-utils/map-parameter.ts
842
+ function mapParameter(specification, mapper) {
843
+ return mapOperation(specification, (method, pathname, operation) => {
844
+ if (!operation.parameters) return operation;
845
+ operation.parameters = operation.parameters.map((parameter) => mapper(method, pathname, operation, parameter));
846
+ return operation;
847
+ });
848
+ }
849
+
850
+ // src/utils/openapi-utils/index.ts
851
+ var OpenapiUtils = class {
852
+ static isRefDefined = isRefDefined;
853
+ static dereference = dereference;
854
+ static dereferenceDeep = dereferenceDeep;
855
+ static removeUndefinedRef = removeUndefinedRef;
856
+ static dereferenceOperation = dereferenceOperation;
857
+ static mapOperation = mapOperation;
858
+ static mapParameter = mapParameter;
859
+ // static updateOperationId = updateOperationId
860
+ static to3_1 = To3_1;
861
+ };
862
+
863
+ // src/transformers/operation-definition/declaration.renderer.ts
864
+ var alias = (name) => `${name}Schema`;
865
+ var DeclarationRenderer2 = class {
866
+ constructor(operationDefinition, options) {
867
+ this.operationDefinition = operationDefinition;
868
+ this.options = options;
869
+ this.typeName = typeNameFactory(operationDefinition);
870
+ }
871
+ typeName;
872
+ renderResponseBodies(operation, options) {
873
+ if (!operation.responses || R12.isEmpty(operation.responses)) {
874
+ return `export interface ${this.typeName("ResponseBodies")} {}`;
875
+ }
876
+ const $responses = Object.entries(operation.responses).map(([statusCode, response]) => {
877
+ if (!JsonSchemaUtils.isRef(response)) {
878
+ const $value = Object.entries(response.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schema]) => {
879
+ if (mediaType.includes("text/event-stream")) return "ReadableStream<ServerSentEvent>";
880
+ if (mediaType.includes("multipart/form-data")) return "FormData";
881
+ if (!schema) return "unknown";
882
+ return JsonSchemaTransformer.toDeclaration(schema, options);
883
+ }).join(" | ");
884
+ return indent(2, `${statusCode}: ${$value || "void"}`);
885
+ }
886
+ }).join("\n");
887
+ return [
888
+ `export interface ${this.typeName("ResponseBodies")} {`,
889
+ $responses,
890
+ "}"
891
+ ].join("\n");
892
+ }
893
+ renderRequestBodies(operation, options) {
894
+ let $requestBodies = `export interface ${this.typeName("RequestBodies")} {}`;
895
+ if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
896
+ const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schema]) => {
897
+ if (!schema) return `${JSON.stringify(mediaType)}: unknown`;
898
+ return `${JSON.stringify(mediaType)}: ${JsonSchemaTransformer.toDeclaration(schema, options)}`;
899
+ }).map((pair) => indent(2, pair));
900
+ $requestBodies = [
901
+ `export interface ${this.typeName("RequestBodies")} {`,
902
+ ...$mediaTypes,
903
+ "}"
904
+ ].join("\n");
905
+ }
906
+ return $requestBodies;
907
+ }
908
+ renderParameterBodies(operationDefinition, options) {
909
+ const { operation } = operationDefinition;
910
+ let parameterBodies = "";
911
+ if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
912
+ const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schemaOrRef]) => {
913
+ if (!schemaOrRef) return `${JSON.stringify(mediaType)}: unknown`;
914
+ const schema = JsonSchemaUtils.isRef(schemaOrRef) ? OpenapiUtils.dereferenceDeep(schemaOrRef.$ref, operationDefinition.document.specification) : schemaOrRef;
915
+ if (schema.type === "object" || schema.properties) {
916
+ return `${JSON.stringify(mediaType)}: ${JsonSchemaTransformer.toDeclaration(schemaOrRef, options)} & { [key: string]: any }`;
917
+ }
918
+ return `${JSON.stringify(mediaType)}: { [key: string]: any }`;
919
+ }).map((pair) => indent(2, pair));
920
+ parameterBodies = [
921
+ `interface ${this.typeName("ParameterBodies")} {`,
922
+ ...$mediaTypes,
923
+ "}",
924
+ ""
925
+ ].join("\n");
926
+ }
927
+ return parameterBodies;
928
+ }
929
+ renderRequestParameters(operation, options) {
930
+ const mediaTypes = operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody) ? Object.keys(operation.requestBody.content || {}) : [];
931
+ const base = `${this.typeName("RequestQuery")} & ${this.typeName("RouteParameters")} & ${this.typeName("RequestHeaders")}`;
932
+ if (mediaTypes.length === 1) {
933
+ return `export type ${this.typeName("RequestParameters")} = ${base} & ${this.typeName("RequestBodies")}[${JSON.stringify(mediaTypes[0])}]`;
934
+ }
935
+ if (mediaTypes.length > 1) {
936
+ const unions = mediaTypes.map((mediaType) => `(${base} & ${this.typeName("RequestBodies")}[${JSON.stringify(mediaType)}] & { "content-type": ${JSON.stringify(mediaType)} })`).join("\n| ");
937
+ return `export type ${this.typeName("RequestParameters")} = ${unions}`;
938
+ }
939
+ return `export type ${this.typeName("RequestParameters")} = ${base}`;
940
+ }
941
+ rendererParameters(name, parameters, options) {
942
+ if (parameters.length === 0) {
943
+ return `export type ${name} = {}`;
944
+ }
945
+ const $parameters = parameters.map((parameter) => {
946
+ const parameterName = `"${parameter.name}"`;
947
+ const $key = parameter.required ? parameterName : `${parameterName}?`;
948
+ const $value = JsonSchemaTransformer.toDeclaration(parameter.schema || { type: "any" }, options);
949
+ return indent(2, `${$key}: ${$value}`);
950
+ }).join("\n");
951
+ return [
952
+ `export type ${name} = {`,
953
+ $parameters,
954
+ "}"
955
+ ].filter(Boolean).join("\n");
956
+ }
957
+ renderDependencies() {
958
+ const schemaDefinitions = this.operationDefinition.getDependencies().filter((schemaDefinition) => !SchemaDefinition.isUnknown(schemaDefinition));
959
+ const $schemaDefinitions = schemaDefinitions.map((schemaDefinition) => {
960
+ const filepath = this.options.getDependentSchemaDefinitionFilepath(schemaDefinition);
961
+ const schemaName = schemaDefinition.name;
962
+ return `import type { ${schemaName} as ${alias(schemaName)} } from "${filepath}"`;
963
+ }).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"'));
964
+ return [
965
+ 'import type { KeqOperation, KeqPathParameterInit, KeqQueryInit, ServerSentEvent } from "keq"',
966
+ ...$schemaDefinitions
967
+ ].join("\n");
968
+ }
969
+ render() {
970
+ const { operation } = this.operationDefinition;
971
+ if (!operation.responses) return "";
972
+ const jsonSchemaDeclarationRendererOptions = {
973
+ referenceTransformer: (schema) => {
974
+ return ReferenceTransformer.toDeclaration(schema, alias);
975
+ }
976
+ };
977
+ const $dependencies = this.renderDependencies();
978
+ const $responseBodies = this.renderResponseBodies(operation, jsonSchemaDeclarationRendererOptions);
979
+ const $requestBodies = this.renderRequestBodies(operation, jsonSchemaDeclarationRendererOptions);
980
+ const $parameterBodies = this.renderParameterBodies(this.operationDefinition, jsonSchemaDeclarationRendererOptions);
981
+ const $requestParameters = this.renderRequestParameters(operation, jsonSchemaDeclarationRendererOptions);
982
+ const $requestQuery = this.rendererParameters(
983
+ `${this.typeName("RequestQuery")}`,
984
+ operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "query") || [],
985
+ jsonSchemaDeclarationRendererOptions
986
+ );
987
+ const $routeParameters = this.rendererParameters(
988
+ `${this.typeName("RouteParameters")}`,
989
+ operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "path") || [],
990
+ jsonSchemaDeclarationRendererOptions
991
+ );
992
+ const $requestHeaders = this.rendererParameters(
993
+ `${this.typeName("RequestHeaders")}`,
994
+ operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "header") || [],
995
+ jsonSchemaDeclarationRendererOptions
996
+ );
997
+ return [
998
+ "/* @anchor:file:start */",
999
+ "",
1000
+ $dependencies,
1001
+ "",
1002
+ $responseBodies,
1003
+ "",
1004
+ $requestBodies,
1005
+ "",
1006
+ $requestQuery,
1007
+ "",
1008
+ $routeParameters,
1009
+ "",
1010
+ $requestHeaders,
1011
+ "",
1012
+ $parameterBodies || void 0,
1013
+ $requestParameters,
1014
+ "",
1015
+ `export interface ${this.typeName("Operation")}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${$parameterBodies ? `keyof ${this.typeName("ParameterBodies")}` : "string"} > extends KeqOperation {`,
1016
+ ` requestParams: ${this.typeName("RouteParameters")} & { [key: string]: KeqPathParameterInit }`,
1017
+ ` requestQuery: ${this.typeName("RequestQuery")} & { [key: string]: KeqQueryInit }`,
1018
+ ` requestHeaders: ${this.typeName("RequestHeaders")} & { [key: string]: string | number }`,
1019
+ ` requestBody: ${$parameterBodies ? `${this.typeName("ParameterBodies")}[CONTENT_TYPE] | ` : "object | "}BodyInit`,
1020
+ ` responseBody: ${this.typeName("ResponseBodies")}[STATUS]`,
1021
+ "}",
1022
+ "",
1023
+ "/* @anchor:file:end */"
1024
+ ].filter(R12.isNotNil).join("\n");
1025
+ }
1026
+ };
1027
+
1028
+ // src/transformers/operation-definition/micro-function.renderer.ts
1029
+ import * as R14 from "ramda";
1030
+
1031
+ // src/exception.ts
1032
+ import { CustomError } from "ts-custom-error";
1033
+ import wrap from "word-wrap";
1034
+ var Exception = class extends CustomError {
1035
+ constructor(module, message) {
1036
+ const moduleName = typeof module === "string" ? module : module.name;
1037
+ const msg = wrap(message, { width: 60, indent: " " });
1038
+ super(`${moduleName} module failed to compile:
1039
+ ${msg}`);
1040
+ Object.defineProperty(this, "name", { value: "KeqCLI_Exception" });
1041
+ }
1042
+ };
1043
+
1044
+ // src/transformers/operation-definition/typescript-snippet.ts
1045
+ import * as R13 from "ramda";
1046
+
1047
+ // src/constants/qs-array-format.ts
1048
+ var QsArrayFormat = /* @__PURE__ */ ((QsArrayFormat2) => {
1049
+ QsArrayFormat2["brackets"] = "brackets";
1050
+ QsArrayFormat2["indices"] = "indices";
1051
+ QsArrayFormat2["repeat"] = "repeat";
1052
+ QsArrayFormat2["comma"] = "comma";
1053
+ QsArrayFormat2["space"] = "space";
1054
+ QsArrayFormat2["pipe"] = "pipe";
1055
+ return QsArrayFormat2;
1056
+ })(QsArrayFormat || {});
1057
+
1058
+ // src/transformers/operation-definition/typescript-snippet.ts
1059
+ var OperationDefinitionSnippet = class {
1060
+ constructor(operationDefinition, options) {
1061
+ this.operationDefinition = operationDefinition;
1062
+ this.options = options;
1063
+ this.typeName = typeNameFactory(operationDefinition);
1064
+ }
1065
+ typeName;
1066
+ getQsParameters(parameter) {
1067
+ let arrayFormat;
1068
+ let allowDots;
1069
+ let indices;
1070
+ const style = parameter.style || "form";
1071
+ const explode = parameter.explode ?? true;
1072
+ if ("x-qs-array-format" in parameter) {
1073
+ arrayFormat = parameter["x-qs-array-format"];
1074
+ } else {
1075
+ if (style === "deepObject") {
1076
+ arrayFormat = "brackets" /* brackets */;
1077
+ } else if (explode) {
1078
+ arrayFormat = "repeat" /* repeat */;
1079
+ } else {
1080
+ if (style === "form") {
1081
+ arrayFormat = "comma" /* comma */;
1082
+ } else if (style === "spaceDelimited") {
1083
+ arrayFormat = "space" /* space */;
1084
+ } else if (style === "pipeDelimited") {
1085
+ arrayFormat = "pipe" /* pipe */;
1086
+ }
1087
+ }
1088
+ }
1089
+ if ("x-qs-allow-dots" in parameter) {
1090
+ allowDots = Boolean(parameter["x-qs-allow-dots"]);
1091
+ }
1092
+ if ("x-qs-indices" in parameter) {
1093
+ indices = Boolean(parameter["x-qs-indices"]);
1094
+ }
1095
+ if (arrayFormat || allowDots !== void 0 || indices !== void 0) {
1096
+ return {
1097
+ ...arrayFormat ? { arrayFormat } : {},
1098
+ ...allowDots !== void 0 ? { allowDots } : {},
1099
+ ...indices !== void 0 ? { indices } : {}
1100
+ };
1101
+ }
1102
+ return void 0;
1103
+ }
1104
+ // render: "if (args && 'Authorization' in args) req.header('Authorization', args['Authorization'])"
1105
+ renderRequestHeaders() {
1106
+ const { operation } = this.operationDefinition;
1107
+ const $headers = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "header").map((p) => `if (args && ${JSON.stringify(p.name)} in args) req.header(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}])`).join("\n");
1108
+ return $headers;
1109
+ }
1110
+ // render: "if (args && 'id' in args) req.query('id', args['id'], options)"
1111
+ renderRequestQuery() {
1112
+ const { operation } = this.operationDefinition;
1113
+ const $query = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "query").map((p) => {
1114
+ const option = this.getQsParameters(p);
1115
+ const $option = !option || R13.isEmpty(option) ? "" : `, ${JSON.stringify(option)}`;
1116
+ return `if (args && ${JSON.stringify(p.name)} in args) req.query(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}]${$option})`;
1117
+ }).join("\n");
1118
+ return $query;
1119
+ }
1120
+ // render: "if (args && 'id' in args) req.params('id', args['id'])"
1121
+ renderRequestPathParameters() {
1122
+ const { operation } = this.operationDefinition;
1123
+ const $pathParameters = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "path").map((p) => `if (args && ${JSON.stringify(p.name)} in args) req.params(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}])`).join("\n");
1124
+ return $pathParameters;
1125
+ }
1126
+ getRequestMediaTypes() {
1127
+ const { operation } = this.operationDefinition;
1128
+ const requestBodyContent = operation.requestBody?.content || {};
1129
+ return Object.keys(requestBodyContent);
1130
+ }
1131
+ // render "req.type("application/json")"
1132
+ renderMediaType() {
1133
+ const mediaTypes = this.getRequestMediaTypes();
1134
+ if (mediaTypes.length === 1 && !mediaTypes[0].endsWith("/*")) {
1135
+ return `req.type("${mediaTypes[0]}")
1136
+ `;
1137
+ } else if (mediaTypes.some((mediaType) => mediaType === "*/*")) {
1138
+ } else if (mediaTypes.some((mediaType) => mediaType.endsWith("/*"))) {
1139
+ return 'if(args?.["content-type"]) req.type(args["content-type"])\n';
1140
+ } else if (mediaTypes.length > 1) {
1141
+ return 'if(args?.["content-type"]) req.type(args["content-type"])\n';
1142
+ }
1143
+ return "";
1144
+ }
1145
+ // render body
1146
+ requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType) {
1147
+ try {
1148
+ const $propertyName = JSON.stringify(propertyName);
1149
+ const schema = JsonSchemaUtils.isRef(propertySchema) ? OpenapiUtils.dereferenceDeep(propertySchema.$ref, this.operationDefinition.document.specification) : propertySchema;
1150
+ if (schema.type === "string" && schema.format === "binary" || schema.contentMediaType === "application/octet-stream") {
1151
+ return `if (args && ${$propertyName} in args && args[${$propertyName}]) req.attach(${$propertyName}, args[${$propertyName}])`;
1152
+ } else if (schema.type === "string" || schema.type === "array" && schema.items && schema.items.type === "string") {
1153
+ return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, args[${$propertyName}])`;
1154
+ } else if (schema.type === "number" || schema.type === "integer") {
1155
+ return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, String(args[${$propertyName}]))`;
1156
+ }
1157
+ return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, String(args[${$propertyName}]) /* type is non-string in schema; triggers type coercion here */)`;
1158
+ } catch (err) {
1159
+ return this.renderErrorComment(err, mediaType);
1160
+ }
1161
+ }
1162
+ requestBodyPropertyRenderer(propertyName, propertySchema, mediaType) {
1163
+ if (mediaType === "application/json") {
1164
+ const $propertyName = JSON.stringify(propertyName);
1165
+ return `if (args && ${$propertyName} in args) req.send({ ${$propertyName}: args[${$propertyName}] })`;
1166
+ } else if (mediaType === "multipart/form-data") {
1167
+ return this.requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType);
1168
+ } else {
1169
+ throw new Error(`Unsupported media type: ${mediaType}`);
1170
+ }
1171
+ }
1172
+ renderRequestBody() {
1173
+ const { operation } = this.operationDefinition;
1174
+ const requestBodyContent = operation.requestBody?.content || {};
1175
+ const $requestBody = Object.entries(requestBodyContent).map(([mediaType, mediaTypeObject]) => {
1176
+ if (!mediaTypeObject.schema) return;
1177
+ try {
1178
+ const schema = JsonSchemaUtils.isRef(mediaTypeObject.schema) ? OpenapiUtils.dereferenceDeep(mediaTypeObject.schema.$ref, this.operationDefinition.document.specification) : mediaTypeObject.schema;
1179
+ if (schema.type !== "object") return;
1180
+ const properties = schema.properties || {};
1181
+ return Object.entries(properties).map(([propertyName, propertySchema]) => this.requestBodyPropertyRenderer(propertyName, propertySchema, mediaType)).join("\n");
1182
+ } catch (err) {
1183
+ return this.renderErrorComment(err, mediaType);
1184
+ }
1185
+ }).filter(R13.isNotNil).join("\n");
1186
+ return $requestBody;
1187
+ }
1188
+ renderErrorComment(err, mediaType) {
1189
+ const $err = String(err).split("\n").map(((line) => ` * ${line}`)).join("\n");
1190
+ return [
1191
+ "/**",
1192
+ ` * Unable to dereference schema for media type ${mediaType}`,
1193
+ $err,
1194
+ " */"
1195
+ ].join("\n");
1196
+ }
1197
+ };
1198
+
1199
+ // src/transformers/operation-definition/micro-function.renderer.ts
1200
+ var OperationDefinitionMicroFunctionRenderer = class {
1201
+ constructor(operationDefinition, options) {
1202
+ this.operationDefinition = operationDefinition;
1203
+ this.options = options;
1204
+ this.typeName = typeNameFactory(operationDefinition);
1205
+ this.helper = new OperationDefinitionSnippet(operationDefinition, options);
1206
+ }
1207
+ helper;
1208
+ typeName;
1209
+ render() {
1210
+ const { operation, operationId, method, pathname } = this.operationDefinition;
1211
+ if (!operation.responses) return "";
1212
+ const $dependencies = this.renderDependencies();
1213
+ const $comment = new CommentRenderer2(this.operationDefinition).render();
1214
+ const moduleName = this.operationDefinition.module.name;
1215
+ const $method = method.toLowerCase();
1216
+ const $queryParameters = this.helper.renderRequestQuery();
1217
+ const $headerParameters = this.helper.renderRequestHeaders();
1218
+ const $pathParameters = this.helper.renderRequestPathParameters();
1219
+ const $mediaType = this.helper.renderMediaType();
1220
+ const $requestBody = this.helper.renderRequestBody();
1221
+ const $operationDeclaration = this.renderOperationDeclaration();
1222
+ return [
1223
+ "/* @anchor:file:start */",
1224
+ "",
1225
+ $dependencies,
1226
+ "",
1227
+ `const moduleName = "${moduleName}"`,
1228
+ `const method = "${method}"`,
1229
+ `const pathname = "${pathname}"`,
1230
+ "",
1231
+ $comment || void 0,
1232
+ `export ${$operationDeclaration} {`,
1233
+ ` const req = request.${$method}<${this.typeName("ResponseBodies")}[STATUS]>("${pathname}")`,
1234
+ " .option('module', { name: moduleName, pathname, method })",
1235
+ "",
1236
+ $mediaType || void 0,
1237
+ " /* @anchor:query:start */",
1238
+ $queryParameters ? indent(2, $queryParameters) : void 0,
1239
+ " /* @anchor:query:end */",
1240
+ "",
1241
+ " /* @anchor:headers:start */",
1242
+ $headerParameters ? indent(2, $headerParameters) : void 0,
1243
+ " /* @anchor:headers:end */",
1244
+ "",
1245
+ " /* @anchor:path-parameters:start */",
1246
+ $pathParameters ? indent(2, $pathParameters) : void 0,
1247
+ " /* @anchor:path-parameters:end */",
1248
+ "",
1249
+ " /* @anchor:body:start */",
1250
+ $requestBody ? indent(2, $requestBody) : void 0,
1251
+ " /* @anchor:body:end */",
1252
+ "",
1253
+ " /* @anchor:operation-return */",
1254
+ ` return req as ReturnType<typeof ${operationId}<STATUS${$operationDeclaration.includes("CONTENT_TYPE") ? ", CONTENT_TYPE" : ""}>>`,
1255
+ "}",
1256
+ "",
1257
+ `${operationId}.pathname = pathname`,
1258
+ `${operationId}.method = method`,
1259
+ "/* @anchor:file:end */"
1260
+ ].filter(R14.isNotNil).join("\n");
1261
+ }
1262
+ renderDependencies() {
1263
+ const declarationFilepath = this.options.getOperationDefinitionDeclarationFilepath(this.operationDefinition);
1264
+ const requestFilepath = this.options.getRequestFilepath();
1265
+ return [
1266
+ 'import { Keq } from "keq"',
1267
+ `import { request } from "${requestFilepath}"`,
1268
+ `import type { ${this.typeName("Operation")}, ${this.typeName("ResponseBodies")}, ${this.typeName("RequestParameters")} } from "${declarationFilepath}"`,
1269
+ `export type { ${this.typeName("RequestQuery")}, ${this.typeName("RequestHeaders")}, ${this.typeName("RequestBodies")} } from "${declarationFilepath}"`
1270
+ ].map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
1271
+ }
1272
+ renderOperationDeclaration() {
1273
+ const { operationId } = this.operationDefinition;
1274
+ const mediaTypes = this.helper.getRequestMediaTypes();
1275
+ if (mediaTypes.length === 0) {
1276
+ return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends never = never>(args?: ${this.typeName("RequestParameters")}): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1277
+ } else if (mediaTypes.length === 1) {
1278
+ return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${JSON.stringify(mediaTypes[0])} = ${JSON.stringify(mediaTypes[0])}>(args?: ${this.typeName("RequestParameters")}): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1279
+ } else if (mediaTypes.length > 1) {
1280
+ return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${this.typeName("RequestParameters")}["content-type"]>(args?: Extract<${this.typeName("RequestParameters")}, { "content-type": CONTENT_TYPE }>): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1281
+ }
1282
+ throw new Exception(this.operationDefinition.module, "[operationDeclarationRenderer] Unreachable");
1283
+ }
1284
+ };
1285
+
1286
+ // src/transformers/operation-definition/nestjs-method.renderer.ts
1287
+ import * as R15 from "ramda";
1288
+ var OperationDefinitionNestjsMethodRenderer = class {
1289
+ constructor(operationDefinition, options) {
1290
+ this.operationDefinition = operationDefinition;
1291
+ this.options = options;
1292
+ this.typeName = typeNameFactory(operationDefinition);
1293
+ this.helper = new OperationDefinitionSnippet(operationDefinition, options);
1294
+ }
1295
+ helper;
1296
+ typeName;
1297
+ render() {
1298
+ const pathname = this.operationDefinition.pathname;
1299
+ const $comment = new CommentRenderer2(this.operationDefinition).render();
1300
+ const $method = this.operationDefinition.method.toLowerCase();
1301
+ const $mediaType = this.helper.renderMediaType();
1302
+ const $operationDeclaration = this.renderOperationDeclaration(this.operationDefinition);
1303
+ const $queryParameters = this.helper.renderRequestQuery();
1304
+ const $headerParameters = this.helper.renderRequestHeaders();
1305
+ const $pathParameters = this.helper.renderRequestPathParameters();
1306
+ const $requestBody = this.helper.renderRequestBody();
1307
+ return [
1308
+ $comment,
1309
+ `${$operationDeclaration} {`,
1310
+ ` const req = this.request.${$method}<${this.typeName("ResponseBodies")}[STATUS]>(${JSON.stringify(pathname)})`,
1311
+ " .option(",
1312
+ ' "module",',
1313
+ " {",
1314
+ ` name: ${JSON.stringify(this.operationDefinition.module.name)},`,
1315
+ ` pathname: ${JSON.stringify(pathname)},`,
1316
+ ` method: ${JSON.stringify($method)},`,
1317
+ " },",
1318
+ " )",
1319
+ "",
1320
+ $mediaType ? indent(2, $mediaType) : void 0,
1321
+ "",
1322
+ " /* @anchor:query:start */",
1323
+ $queryParameters ? indent(2, $queryParameters) : void 0,
1324
+ " /* @anchor:query:end */",
1325
+ "",
1326
+ " /* @anchor:headers:start */",
1327
+ $headerParameters ? indent(2, $headerParameters) : void 0,
1328
+ " /* @anchor:headers:end */",
1329
+ "",
1330
+ " /* @anchor:path-parameters:start */",
1331
+ $pathParameters ? indent(2, $pathParameters) : void 0,
1332
+ " /* @anchor:path-parameters:end */",
1333
+ "",
1334
+ " /* @anchor:body:start */",
1335
+ $requestBody ? indent(2, $requestBody) : void 0,
1336
+ " /* @anchor:body:end */",
1337
+ "",
1338
+ " return req",
1339
+ "}"
1340
+ ].filter(R15.isNotNil).join("\n");
1341
+ }
1342
+ renderOperationDeclaration(operationDefinition) {
1343
+ const { operationId } = operationDefinition;
1344
+ const typeName = typeNameFactory(operationDefinition);
1345
+ const mediaTypes = this.helper.getRequestMediaTypes();
1346
+ if (mediaTypes.length === 0) {
1347
+ return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends never = never>(args?: ${typeName("RequestParameters")}): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1348
+ } else if (mediaTypes.length === 1) {
1349
+ return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends ${JSON.stringify(mediaTypes[0])} = ${JSON.stringify(mediaTypes[0])}>(args?: ${typeName("RequestParameters")}): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1350
+ } else if (mediaTypes.length > 1) {
1351
+ return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends ${typeName("RequestParameters")}["content-type"]>(args?: Extract<${typeName("RequestParameters")}, { "content-type": CONTENT_TYPE }>): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
1352
+ }
1353
+ throw new Exception(operationDefinition.module, "[operationDeclarationRenderer] Unreachable");
1354
+ }
1355
+ };
1356
+
1357
+ // src/transformers/operation-definition/operation-definition.transformer.ts
1358
+ var OperationDefinitionTransformer = class {
1359
+ static toDeclaration(operationDefinition, options) {
1360
+ return new DeclarationRenderer2(operationDefinition, options).render();
1361
+ }
1362
+ static toMicroFunction(operationDefinition, options) {
1363
+ return new OperationDefinitionMicroFunctionRenderer(operationDefinition, options).render();
1364
+ }
1365
+ static toNestjsMethod(operationDefinition, options) {
1366
+ return new OperationDefinitionNestjsMethodRenderer(operationDefinition, options).render();
1367
+ }
1368
+ static toComment(operationDefinition) {
1369
+ return new CommentRenderer2(operationDefinition).render();
1370
+ }
1371
+ };
1372
+
1373
+ // src/transformers/entrypoint/entrypoint.transformer.ts
1374
+ import * as path4 from "path";
1375
+ var EntrypointTransformer = class {
1376
+ static toTypescript(exports, options) {
1377
+ const $exports = exports.map((exportArtifact) => {
1378
+ const relativePath = path4.relative(
1379
+ options.dirpath,
1380
+ exportArtifact.filepath
1381
+ ).replace(/(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?$/, options.esm ? ".js" : "");
1382
+ return relativePath.startsWith(".") ? `export * from '${relativePath}'` : `export * from './${relativePath}'`;
1383
+ });
1384
+ return [
1385
+ "/* @anchor:file:start */",
1386
+ "",
1387
+ ...$exports,
1388
+ "",
1389
+ "/* @anchor:file:end */"
1390
+ ].join("\n");
1391
+ }
1392
+ };
1393
+
1394
+ // src/transformers/api-document/nestjs-client.renderer.ts
1395
+ import * as R16 from "ramda";
1396
+ import * as changeCase2 from "change-case";
1397
+ var NestjsClientRenderer = class {
1398
+ constructor(document, options) {
1399
+ this.document = document;
1400
+ this.options = options;
1401
+ }
1402
+ renderDependencies() {
1403
+ const $operations = this.document.operations.map((operationDefinition) => {
1404
+ const filepath = this.options.getOperationDefinitionDeclarationFilepath(operationDefinition);
1405
+ const typeName = typeNameFactory(operationDefinition);
1406
+ return `import type { ${typeName("Operation")}, ${typeName("ResponseBodies")}, ${typeName("RequestParameters")} } from "${filepath}"`;
1407
+ }).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"'));
1408
+ return [
1409
+ 'import { Injectable, Logger } from "@nestjs/common"',
1410
+ 'import { Keq, KeqRequest } from "keq"',
1411
+ ...$operations
1412
+ ].join("\n");
1413
+ }
1414
+ render() {
1415
+ const moduleName = changeCase2.pascalCase(this.document.module.name);
1416
+ const $dependencies = this.renderDependencies();
1417
+ const $operations = this.document.operations.map((operation) => OperationDefinitionTransformer.toNestjsMethod(operation, {
1418
+ esm: this.options.esm
1419
+ })).join("\n\n");
1420
+ return [
1421
+ "/* @anchor:file:start */",
1422
+ "",
1423
+ $dependencies,
1424
+ "",
1425
+ "@Injectable()",
1426
+ `export class ${moduleName}Client {`,
1427
+ ` private readonly logger = new Logger(${moduleName}Client.name)`,
1428
+ "",
1429
+ " constructor(",
1430
+ " // @anchor:client-constructor-parameters:start",
1431
+ " private readonly request: KeqRequest,",
1432
+ " // @anchor:client-constructor-parameters:end",
1433
+ " ) {}",
1434
+ "",
1435
+ indent(2, $operations),
1436
+ "}",
1437
+ "",
1438
+ "/* @anchor:file:end */"
1439
+ ].filter(R16.isNotNil).join("\n");
1440
+ }
1441
+ };
1442
+
1443
+ // src/transformers/api-document/nestjs-module.renderer.ts
1444
+ import * as changeCase3 from "change-case";
1445
+ var NestjsModuleRenderer = class {
1446
+ constructor(document, options) {
1447
+ this.document = document;
1448
+ this.options = options;
1449
+ }
1450
+ render() {
1451
+ const moduleName = changeCase3.pascalCase(this.document.module.name);
1452
+ const clientFilepath = this.options.getNestjsClientFilepath(this.document).replace(/(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?$/, this.options.esm ? ".js" : "");
1453
+ return [
1454
+ "/* @anchor:file:start */",
1455
+ 'import { Module, Inject, ConfigurableModuleBuilder, Global } from "@nestjs/common"',
1456
+ 'import { KeqRequest } from "keq"',
1457
+ 'import { KeqModuleOptions } from "@keq-request/nestjs"',
1458
+ `import { ${moduleName}Client } from "${clientFilepath}"`,
1459
+ "",
1460
+ "",
1461
+ "const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new ConfigurableModuleBuilder<KeqModuleOptions>().build()",
1462
+ "",
1463
+ "@Global()",
1464
+ "@Module({",
1465
+ " imports: [],",
1466
+ " controllers: [],",
1467
+ ` providers: [${moduleName}Client],`,
1468
+ ` exports: [${moduleName}Client],`,
1469
+ "})",
1470
+ `export class ${moduleName}Module extends ConfigurableModuleClass {`,
1471
+ "",
1472
+ " constructor(",
1473
+ " @Inject(MODULE_OPTIONS_TOKEN) private readonly options: KeqModuleOptions,",
1474
+ " private readonly request: KeqRequest,",
1475
+ " ) {",
1476
+ " super()",
1477
+ " }",
1478
+ "",
1479
+ " onModuleInit() {",
1480
+ " if (this.options.middlewares) {",
1481
+ " for (const middleware of this.options.middlewares) {",
1482
+ " this.request.use(middleware)",
1483
+ " }",
1484
+ " }",
1485
+ " }",
1486
+ "}",
1487
+ "",
1488
+ "/* @anchor:file:end */"
1489
+ ].join("\n");
1490
+ }
1491
+ };
1492
+
1493
+ // src/transformers/api-document/api-document.transformer.ts
1494
+ var ApiDocumentTransformer = class {
1495
+ static toNestjsModule(document, options) {
1496
+ return new NestjsModuleRenderer(document, options).render();
1497
+ }
1498
+ static toNestjsClient(document, options) {
1499
+ return new NestjsClientRenderer(document, options).render();
1500
+ }
1501
+ };
1502
+
1503
+ // src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
1504
+ import * as R17 from "ramda";
1505
+ import * as path5 from "path";
1506
+ import * as changeCase4 from "change-case";
1507
+
1508
+ // src/plugins/generate-declaration/constants/metadata-storage.ts
1509
+ var MetadataStorage2 = /* @__PURE__ */ new WeakMap();
1510
+
1511
+ // src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
1512
+ var SCHEMA_GENERATOR = "schemaGenerator";
1513
+ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
1514
+ async compile(compiler, task) {
1515
+ const context = compiler.context;
1516
+ const metadata = MetadataStorage2.get(compiler);
1517
+ const rc = context.rc;
1518
+ const documents = context.documents;
1519
+ const schemaDefinitions = documents.flatMap((document) => document.schemas);
1520
+ const artifactMap = new Map(
1521
+ await Promise.all(
1522
+ schemaDefinitions.map(async (schemaDefinition) => [
1523
+ schemaDefinition,
1524
+ await metadata.hooks.afterSchemaDeclarationArtifactGenerated.promise(
1525
+ this.generateSchemaDefinitionsArtifact(schemaDefinition, rc),
1526
+ schemaDefinition,
1527
+ task
1528
+ )
1529
+ ])
1530
+ )
1531
+ );
1532
+ const entrypoints = R17.collectBy(
1533
+ (schemaDefinition) => schemaDefinition.module.name,
1534
+ schemaDefinitions
1535
+ ).map((schemaDefinitions2) => [
1536
+ schemaDefinitions2[0].module,
1537
+ schemaDefinitions2.map((schemaDefinition) => artifactMap.get(schemaDefinition)).filter((artifact) => Boolean(artifact))
1538
+ ]).map(([moduleDefinition, artifacts]) => this.generateEntrypointArtifact(
1539
+ moduleDefinition,
1540
+ artifacts,
1541
+ rc
1542
+ ));
1543
+ return [...artifactMap.values(), ...entrypoints];
1544
+ }
1545
+ generateSchemaDefinitionsArtifact(schemaDefinition, rc) {
1546
+ const filepath = _SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(schemaDefinition, rc.fileNamingStyle);
1547
+ const dirpath = path5.dirname(filepath);
1548
+ const artifact = new Artifact({
1549
+ id: _SchemaDeclarationGenerator.getSchemaDefinitionArtifactId(schemaDefinition),
1550
+ filepath,
1551
+ content: SchemaDefinitionTransformer.toDeclaration(
1552
+ schemaDefinition,
1553
+ {
1554
+ esm: rc.esm,
1555
+ getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
1556
+ const relativePath = path5.relative(
1557
+ dirpath,
1558
+ _SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
1559
+ );
1560
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1561
+ }
1562
+ }
1563
+ ),
1564
+ extensionName: ".schema.ts"
1565
+ });
1566
+ return artifact;
1567
+ }
1568
+ generateEntrypointArtifact(moduleDefinition, exports, rc) {
1569
+ const filepath = _SchemaDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
1570
+ const dirpath = path5.dirname(filepath);
1571
+ const artifact = new Artifact({
1572
+ id: _SchemaDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
1573
+ filepath,
1574
+ content: EntrypointTransformer.toTypescript(exports, { dirpath })
1575
+ });
1576
+ return artifact;
1577
+ }
1578
+ static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
1579
+ return [
1580
+ ".",
1581
+ changeCase4[fileNamingStyle](moduleDefinition.name),
1582
+ "types",
1583
+ "components",
1584
+ "schemas",
1585
+ "index.ts"
1586
+ ].join("/");
1587
+ }
1588
+ static getEntrypointArtifactId(moduleDefinition) {
1589
+ return `${moduleDefinition.address}/components/schemas/entrypoint?generator=${SCHEMA_GENERATOR}`;
1590
+ }
1591
+ static getSchemaDefinitionArtifactFilepath(schemaDefinition, fileNamingStyle) {
1592
+ const filename = `${changeCase4[fileNamingStyle](schemaDefinition.name)}.schema.ts`;
1593
+ return [
1594
+ ".",
1595
+ changeCase4[fileNamingStyle](schemaDefinition.module.name),
1596
+ "types",
1597
+ "components",
1598
+ "schemas",
1599
+ filename
1600
+ ].join("/");
1601
+ }
1602
+ static getSchemaDefinitionArtifactId(schemaDefinition) {
1603
+ return `${schemaDefinition.id}?generator=${SCHEMA_GENERATOR}`;
1604
+ }
1605
+ };
1606
+
1607
+ // src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
1608
+ var OPERATION_GENERATOR = "operationDeclarationGenerator";
1609
+ var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
1610
+ async compile(compiler, task) {
1611
+ const context = compiler.context;
1612
+ const metadata = MetadataStorage2.get(compiler);
1613
+ const rc = context.rc;
1614
+ const documents = context.documents;
1615
+ const operationDefinitions = documents.flatMap((document) => document.operations);
1616
+ const artifactMap = new Map(
1617
+ await Promise.all(
1618
+ operationDefinitions.map(async (operationDefinition) => [
1619
+ operationDefinition,
1620
+ await metadata.hooks.afterOperationDeclarationArtifactGenerated.promise(
1621
+ this.generateOperationDefinitionArtifact(operationDefinition, rc),
1622
+ operationDefinition,
1623
+ task
1624
+ )
1625
+ ])
1626
+ )
1627
+ );
1628
+ return Array.from(artifactMap.values());
1629
+ }
1630
+ generateOperationDefinitionArtifact(operationDefinition, rc) {
1631
+ const filepath = _OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
1632
+ const dirpath = path6.dirname(filepath);
1633
+ const artifact = new Artifact({
1634
+ id: _OperationDeclarationGenerator.getOperationDefinitionArtifactId(operationDefinition),
1635
+ filepath,
1636
+ content: OperationDefinitionTransformer.toDeclaration(
1637
+ operationDefinition,
1638
+ {
1639
+ esm: rc.esm,
1640
+ getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
1641
+ const relativePath = path6.relative(
1642
+ dirpath,
1643
+ SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
1644
+ );
1645
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1646
+ }
1647
+ }
1648
+ ),
1649
+ extensionName: ".type.ts"
1650
+ });
1651
+ return artifact;
1652
+ }
1653
+ generateEntrypointArtifact(moduleDefinition, exports, rc) {
1654
+ const filepath = _OperationDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
1655
+ const dirpath = path6.dirname(filepath);
1656
+ const artifact = new Artifact({
1657
+ id: _OperationDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
1658
+ filepath,
1659
+ content: EntrypointTransformer.toTypescript(exports, { dirpath })
1660
+ });
1661
+ return artifact;
1662
+ }
1663
+ static getOperationDefinitionArtifactFilepath(operationDefinition, fileNamingStyle) {
1664
+ const filename = `${changeCase5[fileNamingStyle](operationDefinition.operationId)}.type.ts`;
1665
+ const filepath = [
1666
+ ".",
1667
+ changeCase5[fileNamingStyle](operationDefinition.module.name),
1668
+ "types",
1669
+ "operations",
1670
+ filename
1671
+ ].join("/");
1672
+ return filepath;
1673
+ }
1674
+ static getOperationDefinitionArtifactId(operationDefinition) {
1675
+ return `${operationDefinition.id}?generator=${OPERATION_GENERATOR}`;
1676
+ }
1677
+ static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
1678
+ return [
1679
+ ".",
1680
+ changeCase5[fileNamingStyle](moduleDefinition.name),
1681
+ "types",
1682
+ "operations",
1683
+ "index.ts"
1684
+ ].join("/");
1685
+ }
1686
+ static getEntrypointArtifactId(moduleDefinition) {
1687
+ return `${moduleDefinition.address}/paths/entrypoint?generator=${OPERATION_GENERATOR}`;
1688
+ }
1689
+ };
1690
+
1691
+ // src/plugins/generate-declaration/generate-declaration.plugin.ts
1692
+ var DECLARATION_GENERATOR = "declarationGenerator";
1693
+ var GenerateDeclarationPlugin = class _GenerateDeclarationPlugin {
1694
+ name = DECLARATION_GENERATOR;
1695
+ operationGenerator = new OperationDeclarationGenerator();
1696
+ schemaGenerator = new SchemaDeclarationGenerator();
1697
+ constructor() {
1698
+ }
1699
+ apply(compiler) {
1700
+ _GenerateDeclarationPlugin.register(compiler);
1701
+ compiler.hooks.compile.tapPromise(_GenerateDeclarationPlugin.name, async (task) => {
1702
+ compiler.context.artifacts?.push(
1703
+ ...await this.schemaGenerator.compile(compiler, task),
1704
+ ...await this.operationGenerator.compile(compiler, task)
1705
+ );
1706
+ });
1707
+ }
1708
+ static register(compiler) {
1709
+ if (!MetadataStorage2.has(compiler)) {
1710
+ MetadataStorage2.set(compiler, {
1711
+ hooks: {
1712
+ afterEntrypointArtifactGenerated: new AsyncSeriesWaterfallHook(["artifact", "task"]),
1713
+ afterSchemaDeclarationArtifactGenerated: new AsyncSeriesWaterfallHook(["artifact", "schemaDefinition", "task"]),
1714
+ afterOperationDeclarationArtifactGenerated: new AsyncSeriesWaterfallHook(["artifact", "operationDefinition", "task"])
1715
+ }
1716
+ });
1717
+ }
1718
+ return MetadataStorage2.get(compiler);
1719
+ }
1720
+ static of(compiler) {
1721
+ return this.register(compiler);
1722
+ }
1723
+ };
1724
+
1725
+ // src/plugins/generate-micro-function/generators/request/request.generator.ts
1726
+ var MICRO_FUNCTION_REQUEST_GENERATOR = "microFunctionRequestGenerator";
1727
+ var RequestGenerator = class _RequestGenerator {
1728
+ generateRequestArtifact() {
1729
+ const content = [
1730
+ "/* @anchor:file:start */",
1731
+ "",
1732
+ 'import { KeqRequest } from "keq"',
1733
+ "",
1734
+ "/* @anchor:request-declaration */",
1735
+ "export const request = new KeqRequest()",
1736
+ "",
1737
+ "/* @anchor:file:end */"
1738
+ ].join("\n");
1739
+ return new Artifact({
1740
+ id: _RequestGenerator.getRequestArtifactId(),
1741
+ filepath: _RequestGenerator.getRequestArtifactFilepath(),
1742
+ content
1743
+ });
1744
+ }
1745
+ // eslint-disable-next-line @typescript-eslint/require-await
1746
+ async compile(compiler, task) {
1747
+ return [
1748
+ this.generateRequestArtifact()
1749
+ ];
1750
+ }
1751
+ static getRequestArtifactFilepath() {
1752
+ return "./request.ts";
1753
+ }
1754
+ static getRequestArtifactId() {
1755
+ return `request?generator=${MICRO_FUNCTION_REQUEST_GENERATOR}`;
1756
+ }
1757
+ };
1758
+
1759
+ // src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
1760
+ var MICRO_FUNCTION_GENERATOR = "microFunctionGenerator";
1761
+ var MicroFunctionGenerator = class _MicroFunctionGenerator {
1762
+ async compile(compiler, task) {
1763
+ const metadata = MetadataStorage.get(compiler);
1764
+ const context = compiler.context;
1765
+ const rc = context.rc;
1766
+ const documents = context.documents;
1767
+ const operationDefinitions = documents.flatMap((document) => document.operations);
1768
+ const artifactMap = new Map(
1769
+ await Promise.all(
1770
+ operationDefinitions.map(async (operationDefinition) => [
1771
+ operationDefinition,
1772
+ await metadata.hooks.afterMicroFunctionArtifactGenerated.promise(
1773
+ this.generateOperationDefinitionArtifact(operationDefinition, rc),
1774
+ operationDefinition,
1775
+ task
1776
+ )
1777
+ ])
1778
+ )
1779
+ );
1780
+ const entrypoints = await Promise.all(
1781
+ R18.collectBy(
1782
+ (operationDefinition) => operationDefinition.module.name,
1783
+ operationDefinitions
1784
+ ).map((operationDefinitions2) => [
1785
+ operationDefinitions2[0].module,
1786
+ operationDefinitions2.map((operationDefinition) => artifactMap.get(operationDefinition)).filter((artifact) => Boolean(artifact))
1787
+ ]).map(async ([moduleDefinition, artifacts]) => await metadata.hooks.afterEntrypointArtifactGenerated.promise(
1788
+ this.generateEntrypointArtifact(
1789
+ moduleDefinition,
1790
+ artifacts,
1791
+ rc
1792
+ ),
1793
+ task
1794
+ ))
1795
+ );
1796
+ return [...entrypoints, ...artifactMap.values()];
1797
+ }
1798
+ generateOperationDefinitionArtifact(operationDefinition, rc) {
1799
+ const filepath = _MicroFunctionGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
1800
+ const dirpath = path7.dirname(filepath);
1801
+ const artifact = new Artifact({
1802
+ id: _MicroFunctionGenerator.getOperationDefinitionArtifactId(operationDefinition),
1803
+ filepath,
1804
+ content: OperationDefinitionTransformer.toMicroFunction(operationDefinition, {
1805
+ esm: rc.esm,
1806
+ getOperationDefinitionDeclarationFilepath(operationDefinition2) {
1807
+ const relativePath = path7.relative(
1808
+ dirpath,
1809
+ OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition2, rc.fileNamingStyle)
1810
+ );
1811
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1812
+ },
1813
+ getRequestFilepath() {
1814
+ const relativePath = path7.relative(
1815
+ dirpath,
1816
+ RequestGenerator.getRequestArtifactFilepath()
1817
+ );
1818
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1819
+ }
1820
+ }),
1821
+ extensionName: ".type.ts"
1822
+ });
1823
+ return artifact;
1824
+ }
1825
+ generateEntrypointArtifact(moduleDefinition, exports, rc) {
1826
+ const filepath = _MicroFunctionGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
1827
+ const dirpath = filepath.substring(0, filepath.lastIndexOf("/"));
1828
+ const artifact = new Artifact({
1829
+ id: _MicroFunctionGenerator.getEntrypointArtifactId(moduleDefinition),
1830
+ filepath,
1831
+ content: EntrypointTransformer.toTypescript(exports, { dirpath })
1832
+ });
1833
+ return artifact;
1834
+ }
1835
+ static getOperationDefinitionArtifactFilepath(operationDefinition, fileNamingStyle) {
1836
+ const filename = `${changeCase6[fileNamingStyle](operationDefinition.operationId)}.fn.ts`;
1837
+ const filepath = [
1838
+ ".",
1839
+ changeCase6[fileNamingStyle](operationDefinition.module.name),
1840
+ "operations",
1841
+ filename
1842
+ ].join("/");
1843
+ return filepath;
1844
+ }
1845
+ static getOperationDefinitionArtifactId(operationDefinition) {
1846
+ return `${operationDefinition.id}?generator=${MICRO_FUNCTION_GENERATOR}`;
1847
+ }
1848
+ static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
1849
+ return [
1850
+ ".",
1851
+ changeCase6[fileNamingStyle](moduleDefinition.name),
1852
+ "operations",
1853
+ "index.ts"
1854
+ ].join("/");
1855
+ }
1856
+ static getEntrypointArtifactId(moduleDefinition) {
1857
+ return `${moduleDefinition.address}/paths/entrypoint?generator=${MICRO_FUNCTION_GENERATOR}`;
1858
+ }
1859
+ };
1860
+
1861
+ // src/plugins/generate-micro-function/generate-micro-function.plugin.ts
1862
+ var GenerateMicroFunctionPlugin = class _GenerateMicroFunctionPlugin {
1863
+ microFunctionGenerator = new MicroFunctionGenerator();
1864
+ requestGenerator = new RequestGenerator();
1865
+ apply(compiler) {
1866
+ _GenerateMicroFunctionPlugin.register(compiler);
1867
+ compiler.hooks.compile.tapPromise(_GenerateMicroFunctionPlugin.name, async (task) => {
1868
+ const artifacts = [
1869
+ ...await this.requestGenerator.compile(compiler, task),
1870
+ ...await this.microFunctionGenerator.compile(compiler, task)
1871
+ ];
1872
+ compiler.context.artifacts.push(...artifacts);
1873
+ });
1874
+ }
1875
+ static register(compiler) {
1876
+ if (!MetadataStorage.has(compiler)) {
1877
+ MetadataStorage.set(compiler, {
1878
+ hooks: {
1879
+ afterEntrypointArtifactGenerated: new AsyncSeriesWaterfallHook2(["artifact", "task"]),
1880
+ afterMicroFunctionArtifactGenerated: new AsyncSeriesWaterfallHook2(["artifact", "operationDefinition", "task"])
1881
+ }
1882
+ });
1883
+ }
1884
+ return MetadataStorage.get(compiler);
1885
+ }
1886
+ static of(compiler) {
1887
+ return this.register(compiler);
1888
+ }
1889
+ };
1890
+
77
1891
  // src/plugins/body-fallback/index.ts
78
1892
  var BodyFallbackPlugin = class _BodyFallbackPlugin {
79
1893
  apply(compiler) {
80
- compiler.hooks.afterCompileOperationRequest.tap(_BodyFallbackPlugin.name, (artifact, operationDefinition) => {
81
- const operation = operationDefinition.operation;
82
- const parameters = operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p)) || [];
83
- const keys = parameters.map((p) => p.name).filter(R.isNotNil);
84
- const $acc = !keys.length ? " acc[key] = args[key]" : [
85
- ` if (![${keys.map((k) => JSON.stringify(k)).join(", ")}].includes(key)) {`,
86
- " acc[key] = args[key]",
87
- " }"
88
- ].join("\n");
89
- artifact.anchor.block.replace("body", [
90
- // $mediaType ? `${$mediaType}\n` : undefined,
91
- ' if (typeof args === "object" && args !== null && !Array.isArray(args)) {',
92
- " const requestBody = Object.keys(args)",
93
- " .reduce((acc, key) => {",
94
- $acc,
95
- " return acc",
96
- " }, {} as Record<string, unknown>)",
97
- "",
98
- " if (Object.keys(requestBody).length > 0) {",
99
- " req.send(requestBody)",
100
- " }",
101
- " }"
102
- ].filter(R.isNotNil).join("\n"));
103
- return artifact;
1894
+ compiler.hooks.setup.tap(_BodyFallbackPlugin.name, () => {
1895
+ const generateMicroFunctionPluginMetadata = GenerateMicroFunctionPlugin.of(compiler);
1896
+ if (!generateMicroFunctionPluginMetadata) {
1897
+ throw new Error("BodyFallbackPlugin requires GenerateMicroFunctionPlugin to be applied first.");
1898
+ }
1899
+ generateMicroFunctionPluginMetadata.hooks.afterMicroFunctionArtifactGenerated.tap(_BodyFallbackPlugin.name, (artifact, operationDefinition) => {
1900
+ const operation = operationDefinition.operation;
1901
+ const parameters = operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p)) || [];
1902
+ const keys2 = parameters.map((p) => p.name).filter(R19.isNotNil);
1903
+ const $acc = !keys2.length ? " acc[key] = args[key]" : [
1904
+ ` if (![${keys2.map((k) => JSON.stringify(k)).join(", ")}].includes(key)) {`,
1905
+ " acc[key] = args[key]",
1906
+ " }"
1907
+ ].join("\n");
1908
+ artifact.anchor.block.replace("body", [
1909
+ // $mediaType ? `${$mediaType}\n` : undefined,
1910
+ ' if (typeof args === "object" && args !== null && !Array.isArray(args)) {',
1911
+ " const requestBody = Object.keys(args)",
1912
+ " .reduce((acc, key) => {",
1913
+ $acc,
1914
+ " return acc",
1915
+ " }, {} as Record<string, unknown>)",
1916
+ "",
1917
+ " if (Object.keys(requestBody).length > 0) {",
1918
+ " req.send(requestBody)",
1919
+ " }",
1920
+ " }"
1921
+ ].filter(R19.isNotNil).join("\n"));
1922
+ return artifact;
1923
+ });
1924
+ });
1925
+ }
1926
+ };
1927
+
1928
+ // src/plugins/generate-nestjs-module/generate-nestjs-module.ts
1929
+ import { AsyncSeriesWaterfallHook as AsyncSeriesWaterfallHook3 } from "tapable";
1930
+
1931
+ // src/plugins/generate-nestjs-module/constants/metadata-storage.ts
1932
+ var MetadataStorage3 = /* @__PURE__ */ new WeakMap();
1933
+
1934
+ // src/plugins/generate-nestjs-module/generators/nestjs-module.generator.ts
1935
+ import * as path8 from "path";
1936
+ import * as changeCase7 from "change-case";
1937
+ var NESTJS_MODULE_GENERATOR = "nestjs-module-generator";
1938
+ var NestjsModuleGenerator = class _NestjsModuleGenerator {
1939
+ generateNestjsModuleArtifact(document, rc) {
1940
+ const filepath = _NestjsModuleGenerator.getNestjsModuleArtifactFilepath(document, rc.fileNamingStyle);
1941
+ const dirname6 = path8.dirname(filepath);
1942
+ const artifact = new Artifact({
1943
+ id: _NestjsModuleGenerator.getNestjsModuleArtifactId(document),
1944
+ filepath,
1945
+ content: ApiDocumentTransformer.toNestjsModule(document, {
1946
+ esm: rc.esm,
1947
+ getNestjsClientFilepath(document2) {
1948
+ const relativePath = path8.relative(
1949
+ dirname6,
1950
+ _NestjsModuleGenerator.getNestjsClientArtifactFilepath(document2, rc.fileNamingStyle)
1951
+ );
1952
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1953
+ }
1954
+ })
1955
+ });
1956
+ return artifact;
1957
+ }
1958
+ generateNestjsClientArtifact(document, rc) {
1959
+ const filepath = _NestjsModuleGenerator.getNestjsClientArtifactFilepath(document, rc.fileNamingStyle);
1960
+ const dirpath = path8.dirname(filepath);
1961
+ const artifact = new Artifact({
1962
+ id: _NestjsModuleGenerator.getNestjsClientArtifactId(document),
1963
+ filepath,
1964
+ content: ApiDocumentTransformer.toNestjsClient(document, {
1965
+ esm: rc.esm,
1966
+ getOperationDefinitionDeclarationFilepath(operationDefinition) {
1967
+ const relativePath = path8.relative(
1968
+ dirpath,
1969
+ OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle)
1970
+ );
1971
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
1972
+ }
1973
+ })
1974
+ });
1975
+ return artifact;
1976
+ }
1977
+ async compile(compiler, task) {
1978
+ const metadata = MetadataStorage3.get(compiler);
1979
+ const rc = compiler.context.rc;
1980
+ const documents = compiler.context.documents;
1981
+ const nestjsModuleArtifacts = await Promise.all(
1982
+ documents.map((document) => metadata.hooks.afterNestjsModuleArtifactGenerated.promise(
1983
+ this.generateNestjsModuleArtifact(document, rc),
1984
+ document,
1985
+ task
1986
+ ))
1987
+ );
1988
+ const nestjsClientArtifacts = await Promise.all(
1989
+ documents.map((document) => metadata.hooks.afterNestjsModuleArtifactGenerated.promise(
1990
+ this.generateNestjsClientArtifact(document, rc),
1991
+ document,
1992
+ task
1993
+ ))
1994
+ );
1995
+ return [...nestjsModuleArtifacts, ...nestjsClientArtifacts];
1996
+ }
1997
+ static getNestjsModuleArtifactFilepath(document, fileNamingStyle) {
1998
+ const filename = `${changeCase7[fileNamingStyle](document.module.name)}.module.ts`;
1999
+ const filepath = [
2000
+ ".",
2001
+ changeCase7[fileNamingStyle](document.module.name),
2002
+ filename
2003
+ ];
2004
+ return filepath.join("/");
2005
+ }
2006
+ static getNestjsModuleArtifactId(document) {
2007
+ return `${document.module.address}?generate=${NESTJS_MODULE_GENERATOR}`;
2008
+ }
2009
+ static getNestjsClientArtifactFilepath(document, fileNamingStyle) {
2010
+ const filename = `${changeCase7[fileNamingStyle](document.module.name)}.client.ts`;
2011
+ const filepath = [
2012
+ ".",
2013
+ changeCase7[fileNamingStyle](document.module.name),
2014
+ filename
2015
+ ];
2016
+ return filepath.join("/");
2017
+ }
2018
+ static getNestjsClientArtifactId(document) {
2019
+ return `${document.module.address}?generate=${NESTJS_MODULE_GENERATOR}-client`;
2020
+ }
2021
+ };
2022
+
2023
+ // src/plugins/generate-nestjs-module/generate-nestjs-module.ts
2024
+ var GenerateNestjsModulePlugin = class _GenerateNestjsModulePlugin {
2025
+ nestjsModuleGenerator = new NestjsModuleGenerator();
2026
+ apply(compiler) {
2027
+ _GenerateNestjsModulePlugin.register(compiler);
2028
+ compiler.hooks.compile.tapPromise(_GenerateNestjsModulePlugin.name, async (task) => {
2029
+ const artifacts = await this.nestjsModuleGenerator.compile(compiler, task);
2030
+ compiler.context.artifacts.push(...artifacts);
2031
+ });
2032
+ }
2033
+ static register(compiler) {
2034
+ if (!MetadataStorage3.has(compiler)) {
2035
+ MetadataStorage3.set(compiler, {
2036
+ hooks: {
2037
+ afterNestjsModuleArtifactGenerated: new AsyncSeriesWaterfallHook3(["artifact", "document", "task"])
2038
+ }
2039
+ });
2040
+ }
2041
+ return MetadataStorage3.get(compiler);
2042
+ }
2043
+ static of(compiler) {
2044
+ return MetadataStorage3.get(compiler);
2045
+ }
2046
+ };
2047
+
2048
+ // src/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.ts
2049
+ import { fixSwagger } from "swagger-fix";
2050
+ var ChineseToPinyinPlugin = class _ChineseToPinyinPlugin {
2051
+ apply(compiler) {
2052
+ compiler.hooks.afterDownload.tap(_ChineseToPinyinPlugin.name, (task) => {
2053
+ const documents = compiler.context.documents;
2054
+ compiler.context.documents = documents.map((doc) => {
2055
+ return new ApiDocumentV3_1(
2056
+ fixSwagger(doc.specification),
2057
+ doc.module
2058
+ );
2059
+ });
2060
+ });
2061
+ }
2062
+ };
2063
+
2064
+ // src/plugins/download-http-file/download-http-file.plugin.ts
2065
+ import * as validUrl from "valid-url";
2066
+ var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
2067
+ apply(compiler) {
2068
+ compiler.hooks.download.tapPromise(_DownloadHttpFilePlugin.name, async (address, task) => {
2069
+ if (!validUrl.isUri(address)) return void 0;
2070
+ const content = await this.download(address);
2071
+ const spec = this.deserialize(content);
2072
+ return JSON.stringify(spec);
2073
+ });
2074
+ }
2075
+ async download(address) {
2076
+ try {
2077
+ const res = await fetch(address);
2078
+ if (res.status >= 400) throw new Error(`failed with status code ${res.status}`);
2079
+ return await res.text();
2080
+ } catch (e) {
2081
+ if (e instanceof Error) {
2082
+ e.message = `Unable get the openapi/swagger file from ${address}: ${e.message}`;
2083
+ }
2084
+ throw e;
2085
+ }
2086
+ }
2087
+ deserialize(content) {
2088
+ const json = JSON.parse(content);
2089
+ const spec = OpenapiUtils.to3_1(json);
2090
+ return spec;
2091
+ }
2092
+ };
2093
+
2094
+ // src/plugins/download-local-file/download-local-file.plugin.ts
2095
+ import * as path9 from "path";
2096
+ import * as fs from "fs/promises";
2097
+ import * as yaml from "js-yaml";
2098
+ var DownloadLocalFilePlugin = class _DownloadLocalFilePlugin {
2099
+ apply(compiler) {
2100
+ compiler.hooks.download.tapPromise(_DownloadLocalFilePlugin.name, async (address, task) => {
2101
+ if (!address.startsWith("./") && !address.startsWith("/") && !address.startsWith("../")) return void 0;
2102
+ const fileExt = path9.extname(address);
2103
+ const content = await fs.readFile(address, "utf8");
2104
+ if ([".yml", ".yaml"].includes(fileExt)) {
2105
+ const value = yaml.load(content);
2106
+ return JSON.stringify(OpenapiUtils.to3_1(value));
2107
+ } else if (fileExt === ".json") {
2108
+ return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(content)));
2109
+ }
2110
+ });
2111
+ }
2112
+ };
2113
+
2114
+ // src/plugins/shaking/shaking.plugin.ts
2115
+ import { openapiShakingSync } from "@opendoc/openapi-shaking";
2116
+ var ShakingPlugin = class _ShakingPlugin {
2117
+ apply(compiler) {
2118
+ compiler.hooks.beforeCompile.tap(_ShakingPlugin.name, (task) => {
2119
+ const matcher = compiler.context.matcher;
2120
+ const documents = compiler.context.documents;
2121
+ compiler.context.documents = documents.map((document) => this.shaking(compiler, document)).filter((document) => !document.isEmpty()).filter((document) => !matcher.isModuleIgnored(document.module));
2122
+ });
2123
+ }
2124
+ shaking(compiler, document) {
2125
+ const rc = compiler.context.rc;
2126
+ const matcher = compiler.context.matcher;
2127
+ const isAccepted = (pathname, method, operation) => {
2128
+ if (!SupportedMethods.includes(method)) return false;
2129
+ return !matcher.isOperationIgnored(new OperationDefinition({
2130
+ method,
2131
+ pathname,
2132
+ operation,
2133
+ module: document.module,
2134
+ document
2135
+ }));
2136
+ };
2137
+ const sharkedSwagger = openapiShakingSync(
2138
+ document.specification,
2139
+ isAccepted,
2140
+ { tolerant: rc.tolerant }
2141
+ );
2142
+ return new ApiDocumentV3_1(
2143
+ sharkedSwagger,
2144
+ new ModuleDefinition(
2145
+ document.module.name,
2146
+ `file://${document.module.name}.v3_1.sharked.json`
2147
+ )
2148
+ );
2149
+ }
2150
+ };
2151
+
2152
+ // src/plugins/terminal-select/utils/select-operation-definitions.ts
2153
+ import { select } from "inquirer-select-pro";
2154
+ import { ListrInquirerPromptAdapter } from "@listr2/prompt-adapter-inquirer";
2155
+ async function selectOperationDefinitions(task, operationDefinitions) {
2156
+ const selectedOperationDefinitions = await task.prompt(ListrInquirerPromptAdapter).run(
2157
+ select,
2158
+ {
2159
+ message: "Select Pathname",
2160
+ defaultValue: [],
2161
+ options: (input) => {
2162
+ const items = operationDefinitions.map((op) => ({ name: `${op.module.name} ${op.method.toUpperCase()} ${op.pathname}`, value: op }));
2163
+ if (!input) return items;
2164
+ const keys2 = input.trim().toLowerCase().split(/\s+/);
2165
+ return items.filter((i) => {
2166
+ const name = i.name.toLowerCase();
2167
+ return keys2.every((q) => name.includes(q));
2168
+ });
2169
+ }
2170
+ }
2171
+ );
2172
+ return selectedOperationDefinitions;
2173
+ }
2174
+
2175
+ // src/plugins/terminal-select/terminal-select.plugin.ts
2176
+ var TerminalSelectPlugin = class _TerminalSelectPlugin {
2177
+ constructor(options) {
2178
+ this.options = options;
2179
+ }
2180
+ apply(compiler) {
2181
+ compiler.hooks.afterDownload.tapPromise(_TerminalSelectPlugin.name, async (task) => {
2182
+ const context = compiler.context;
2183
+ const matcher = context.matcher;
2184
+ const documents = context.documents;
2185
+ const operationDefinitions = documents.flatMap((document) => document.operations);
2186
+ const selectedOperationDefinitions = await selectOperationDefinitions(task, operationDefinitions);
2187
+ if (this.options.clear) {
2188
+ matcher.append({
2189
+ persist: false,
2190
+ ignore: true,
2191
+ moduleName: "*",
2192
+ operationMethod: "*",
2193
+ operationPathname: "*"
2194
+ });
2195
+ }
2196
+ for (const op of selectedOperationDefinitions) {
2197
+ matcher.append({
2198
+ persist: !!this.options.persist,
2199
+ ignore: this.options.mode === "add",
2200
+ moduleName: op.module.name,
2201
+ operationMethod: op.method,
2202
+ operationPathname: op.pathname
2203
+ });
2204
+ }
2205
+ });
2206
+ }
2207
+ };
2208
+
2209
+ // src/plugins/initialize/initialize.plugin.ts
2210
+ import * as R20 from "ramda";
2211
+ var InitializePlugin = class _InitializePlugin {
2212
+ constructor(options) {
2213
+ this.options = options;
2214
+ }
2215
+ apply(compiler) {
2216
+ compiler.hooks.setup.tap(_InitializePlugin.name, (task) => {
2217
+ new DownloadHttpFilePlugin().apply(compiler);
2218
+ new DownloadLocalFilePlugin().apply(compiler);
2219
+ new GenerateDeclarationPlugin().apply(compiler);
2220
+ if (this.options.build) {
2221
+ new ShakingPlugin().apply(compiler);
2222
+ }
2223
+ if (this.options.interactive) {
2224
+ new TerminalSelectPlugin(
2225
+ typeof this.options.interactive === "object" ? this.options.interactive : { mode: "except" }
2226
+ ).apply(compiler);
2227
+ }
2228
+ const rc = compiler.context.rc;
2229
+ if (rc.mode === "micro-function") {
2230
+ new GenerateMicroFunctionPlugin().apply(compiler);
2231
+ } else if (rc.mode === "nestjs-module") {
2232
+ new GenerateNestjsModulePlugin().apply(compiler);
2233
+ }
2234
+ if (rc.plugins && rc.plugins.length) {
2235
+ for (const plugin of rc.plugins) {
2236
+ plugin.apply(compiler);
2237
+ }
2238
+ }
2239
+ });
2240
+ if (this.options.includes && this.options.includes.length) {
2241
+ const modulesIncludes = this.options.includes;
2242
+ compiler.hooks.afterSetup.tap(_InitializePlugin.name, (task) => {
2243
+ const rc = compiler.context.rc;
2244
+ const matcher = compiler.context.matcher;
2245
+ const notExistModules = modulesIncludes.filter((moduleName) => !(moduleName in rc.modules));
2246
+ if (notExistModules.length) {
2247
+ throw new Error(`Cannot find module(s) ${notExistModules.join(", ")} in config file.`);
2248
+ }
2249
+ const ignoredModules = R20.difference(R20.keys(rc.modules), modulesIncludes);
2250
+ for (const moduleName of ignoredModules) {
2251
+ matcher.append({
2252
+ persist: false,
2253
+ ignore: true,
2254
+ moduleName,
2255
+ operationMethod: "*",
2256
+ operationPathname: "*"
2257
+ });
2258
+ }
2259
+ });
2260
+ }
2261
+ }
2262
+ };
2263
+
2264
+ // src/plugins/overwrite-operation-id/overwrite-operation-id.plugin.ts
2265
+ var OverwriteOperationIdPlugin = class _OverwriteOperationIdPlugin {
2266
+ constructor(factory) {
2267
+ this.factory = factory;
2268
+ }
2269
+ apply(compiler) {
2270
+ compiler.hooks.afterDownload.tap(_OverwriteOperationIdPlugin.name, () => {
2271
+ const documents = compiler.context.documents;
2272
+ const factory = this.factory;
2273
+ compiler.context.documents = documents.map((document) => {
2274
+ const spec = OpenapiUtils.mapOperation(
2275
+ document.specification,
2276
+ (method, pathname, operation) => {
2277
+ const operationId = factory({ method, pathname, operation, module: document.module });
2278
+ if (typeof operationId === "string") {
2279
+ if (operationId.length === 0) {
2280
+ throw new Exception(document.module, `The generated operationId for [${method.toUpperCase()} ${pathname}] is an empty string.`);
2281
+ }
2282
+ operation.operationId = operationId;
2283
+ return operation;
2284
+ }
2285
+ return operation;
2286
+ }
2287
+ );
2288
+ return new ApiDocumentV3_1(spec, document.module);
2289
+ });
2290
+ });
2291
+ }
2292
+ };
2293
+
2294
+ // src/plugins/overwrite-query-options/overwrite-query-options.plugin.ts
2295
+ var QsArrayFormatUnion = Object.values(QsArrayFormat);
2296
+ var OverwriteQueryOptionsPlugin = class _OverwriteQueryOptionsPlugin {
2297
+ constructor(factory) {
2298
+ this.factory = factory;
2299
+ }
2300
+ apply(compiler) {
2301
+ compiler.hooks.afterDownload.tap(_OverwriteQueryOptionsPlugin.name, (task) => {
2302
+ const documents = compiler.context.documents;
2303
+ const factory = this.factory;
2304
+ compiler.context.documents = documents.map((document) => {
2305
+ const specification = OpenapiUtils.mapParameter(
2306
+ document.specification,
2307
+ (method, pathname, operation, parameter) => {
2308
+ const qsOptions = typeof factory === "function" ? factory({ parameter, operation, pathname, method, module: document.module }) : factory;
2309
+ if (!qsOptions) return parameter;
2310
+ if (qsOptions.arrayFormat) {
2311
+ if (!QsArrayFormatUnion.includes(qsOptions.arrayFormat)) {
2312
+ throw new Exception(document.module, `The 'arrayFormat' value '${qsOptions.arrayFormat}' for the query parameter '${parameter.name}' in [${method.toUpperCase()} ${pathname}] is invalid.`);
2313
+ }
2314
+ parameter["x-qs-array-format"] = qsOptions.arrayFormat;
2315
+ }
2316
+ if (qsOptions.allowDots !== void 0) {
2317
+ if (typeof qsOptions.allowDots !== "boolean") {
2318
+ throw new Exception(document.module, `The 'allowDots' value for the query parameter '${parameter.name}' in [${method.toUpperCase()} ${pathname}] must be a boolean.`);
2319
+ }
2320
+ parameter["x-qs-allow-dots"] = Boolean(qsOptions.allowDots);
2321
+ }
2322
+ if (qsOptions.indices !== void 0) {
2323
+ if (typeof qsOptions.indices !== "boolean") {
2324
+ throw new Exception(document.module, `The 'indices' value for the query parameter '${parameter.name}' in [${method.toUpperCase()} ${pathname}] must be a boolean.`);
2325
+ }
2326
+ parameter["x-qs-indices"] = Boolean(qsOptions.indices);
2327
+ }
2328
+ return parameter;
2329
+ }
2330
+ );
2331
+ return new ApiDocumentV3_1(
2332
+ specification,
2333
+ document.module
2334
+ );
2335
+ });
104
2336
  });
105
2337
  }
106
2338
  };
107
2339
  export {
108
2340
  BodyFallbackPlugin,
2341
+ ChineseToPinyinPlugin,
2342
+ DECLARATION_GENERATOR,
2343
+ DownloadHttpFilePlugin,
2344
+ DownloadLocalFilePlugin,
109
2345
  EslintPlugin,
110
- PrettierPlugin
2346
+ GenerateDeclarationPlugin,
2347
+ GenerateMicroFunctionPlugin,
2348
+ GenerateNestjsModulePlugin,
2349
+ InitializePlugin,
2350
+ MICRO_FUNCTION_GENERATOR,
2351
+ MICRO_FUNCTION_REQUEST_GENERATOR,
2352
+ MicroFunctionGenerator,
2353
+ NestjsModuleGenerator,
2354
+ OPERATION_GENERATOR,
2355
+ OperationDeclarationGenerator,
2356
+ OverwriteOperationIdPlugin,
2357
+ OverwriteQueryOptionsPlugin,
2358
+ PrettierPlugin,
2359
+ RequestGenerator,
2360
+ SCHEMA_GENERATOR,
2361
+ SchemaDeclarationGenerator,
2362
+ ShakingPlugin,
2363
+ TerminalSelectPlugin
111
2364
  };
112
2365
  //# sourceMappingURL=plugins.js.map