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