mobx-tanstack-query-api 0.24.0 → 0.26.0

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 (264) hide show
  1. package/builtin.cjs +27 -0
  2. package/builtin.cjs.map +1 -0
  3. package/builtin.d.ts +6 -0
  4. package/builtin.js +27 -0
  5. package/builtin.js.map +1 -0
  6. package/cli.cjs +1279 -0
  7. package/cli.cjs.map +1 -0
  8. package/{codegen/types/generate-query-api-params.d.cts → cli.d.ts} +55 -10
  9. package/cli.js +1278 -0
  10. package/cli.js.map +1 -0
  11. package/index.cjs +771 -16
  12. package/index.cjs.map +1 -0
  13. package/index.d.ts +322 -2
  14. package/index.js +768 -2
  15. package/index.js.map +1 -0
  16. package/package.json +21 -64
  17. package/builtin/index.cjs +0 -25
  18. package/builtin/index.d.cts +0 -4
  19. package/builtin/index.d.cts.map +0 -1
  20. package/builtin/index.d.ts +0 -4
  21. package/builtin/index.d.ts.map +0 -1
  22. package/builtin/index.js +0 -22
  23. package/cli/bin.cjs +0 -17
  24. package/cli/bin.d.cts +0 -2
  25. package/cli/bin.d.cts.map +0 -1
  26. package/cli/bin.d.ts +0 -2
  27. package/cli/bin.d.ts.map +0 -1
  28. package/cli/bin.js +0 -15
  29. package/cli/index.cjs +0 -18
  30. package/cli/index.d.cts +0 -3
  31. package/cli/index.d.cts.map +0 -1
  32. package/cli/index.d.ts +0 -3
  33. package/cli/index.d.ts.map +0 -1
  34. package/cli/index.js +0 -2
  35. package/cli/utils/define-config.cjs +0 -9
  36. package/cli/utils/define-config.d.cts +0 -4
  37. package/cli/utils/define-config.d.cts.map +0 -1
  38. package/cli/utils/define-config.d.ts +0 -4
  39. package/cli/utils/define-config.d.ts.map +0 -1
  40. package/cli/utils/define-config.js +0 -5
  41. package/cli/utils/exec-config-path.cjs +0 -16
  42. package/cli/utils/exec-config-path.d.cts +0 -2
  43. package/cli/utils/exec-config-path.d.cts.map +0 -1
  44. package/cli/utils/exec-config-path.d.ts +0 -2
  45. package/cli/utils/exec-config-path.d.ts.map +0 -1
  46. package/cli/utils/exec-config-path.js +0 -12
  47. package/cli/utils/resolve-config-path.cjs +0 -65
  48. package/cli/utils/resolve-config-path.d.cts +0 -3
  49. package/cli/utils/resolve-config-path.d.cts.map +0 -1
  50. package/cli/utils/resolve-config-path.d.ts +0 -3
  51. package/cli/utils/resolve-config-path.d.ts.map +0 -1
  52. package/cli/utils/resolve-config-path.js +0 -25
  53. package/codegen/index.cjs +0 -545
  54. package/codegen/index.d.cts +0 -4
  55. package/codegen/index.d.cts.map +0 -1
  56. package/codegen/index.d.ts +0 -4
  57. package/codegen/index.d.ts.map +0 -1
  58. package/codegen/index.js +0 -524
  59. package/codegen/templates/all-endpoints-per-file.tmpl.cjs +0 -94
  60. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts +0 -14
  61. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +0 -1
  62. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts +0 -14
  63. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
  64. package/codegen/templates/all-endpoints-per-file.tmpl.js +0 -90
  65. package/codegen/templates/all-exports.tmpl.cjs +0 -14
  66. package/codegen/templates/all-exports.tmpl.d.cts +0 -9
  67. package/codegen/templates/all-exports.tmpl.d.cts.map +0 -1
  68. package/codegen/templates/all-exports.tmpl.d.ts +0 -9
  69. package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
  70. package/codegen/templates/all-exports.tmpl.js +0 -9
  71. package/codegen/templates/constants.cjs +0 -5
  72. package/codegen/templates/constants.d.cts +0 -2
  73. package/codegen/templates/constants.d.cts.map +0 -1
  74. package/codegen/templates/constants.d.ts +0 -2
  75. package/codegen/templates/constants.d.ts.map +0 -1
  76. package/codegen/templates/constants.js +0 -2
  77. package/codegen/templates/data-contract.tmpl.cjs +0 -49
  78. package/codegen/templates/data-contract.tmpl.d.cts +0 -8
  79. package/codegen/templates/data-contract.tmpl.d.cts.map +0 -1
  80. package/codegen/templates/data-contract.tmpl.d.ts +0 -8
  81. package/codegen/templates/data-contract.tmpl.d.ts.map +0 -1
  82. package/codegen/templates/data-contract.tmpl.js +0 -45
  83. package/codegen/templates/data-contracts-file.tmpl.cjs +0 -27
  84. package/codegen/templates/data-contracts-file.tmpl.d.cts +0 -6
  85. package/codegen/templates/data-contracts-file.tmpl.d.cts.map +0 -1
  86. package/codegen/templates/data-contracts-file.tmpl.d.ts +0 -6
  87. package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
  88. package/codegen/templates/data-contracts-file.tmpl.js +0 -23
  89. package/codegen/templates/endpoint-jsdoc.tmpl.cjs +0 -111
  90. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts +0 -8
  91. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +0 -1
  92. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts +0 -8
  93. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
  94. package/codegen/templates/endpoint-jsdoc.tmpl.js +0 -107
  95. package/codegen/templates/endpoint-per-file.tmpl.cjs +0 -87
  96. package/codegen/templates/endpoint-per-file.tmpl.d.cts +0 -14
  97. package/codegen/templates/endpoint-per-file.tmpl.d.cts.map +0 -1
  98. package/codegen/templates/endpoint-per-file.tmpl.d.ts +0 -14
  99. package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
  100. package/codegen/templates/endpoint-per-file.tmpl.js +0 -83
  101. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +0 -10
  102. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +0 -6
  103. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +0 -1
  104. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +0 -6
  105. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +0 -1
  106. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.js +0 -6
  107. package/codegen/templates/meta-info.tmpl.cjs +0 -48
  108. package/codegen/templates/meta-info.tmpl.d.cts +0 -9
  109. package/codegen/templates/meta-info.tmpl.d.cts.map +0 -1
  110. package/codegen/templates/meta-info.tmpl.d.ts +0 -9
  111. package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
  112. package/codegen/templates/meta-info.tmpl.js +0 -42
  113. package/codegen/templates/new-endpoint.tmpl.cjs +0 -188
  114. package/codegen/templates/new-endpoint.tmpl.d.cts +0 -15
  115. package/codegen/templates/new-endpoint.tmpl.d.cts.map +0 -1
  116. package/codegen/templates/new-endpoint.tmpl.d.ts +0 -15
  117. package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
  118. package/codegen/templates/new-endpoint.tmpl.js +0 -184
  119. package/codegen/types/all-import-file-params.cjs +0 -2
  120. package/codegen/types/all-import-file-params.d.cts +0 -5
  121. package/codegen/types/all-import-file-params.d.cts.map +0 -1
  122. package/codegen/types/all-import-file-params.d.ts +0 -5
  123. package/codegen/types/all-import-file-params.d.ts.map +0 -1
  124. package/codegen/types/all-import-file-params.js +0 -1
  125. package/codegen/types/base-tmpl-params.cjs +0 -2
  126. package/codegen/types/base-tmpl-params.d.cts +0 -16
  127. package/codegen/types/base-tmpl-params.d.cts.map +0 -1
  128. package/codegen/types/base-tmpl-params.d.ts +0 -16
  129. package/codegen/types/base-tmpl-params.d.ts.map +0 -1
  130. package/codegen/types/base-tmpl-params.js +0 -1
  131. package/codegen/types/codegen-data-utils.cjs +0 -2
  132. package/codegen/types/codegen-data-utils.d.cts +0 -8
  133. package/codegen/types/codegen-data-utils.d.cts.map +0 -1
  134. package/codegen/types/codegen-data-utils.d.ts +0 -8
  135. package/codegen/types/codegen-data-utils.d.ts.map +0 -1
  136. package/codegen/types/codegen-data-utils.js +0 -1
  137. package/codegen/types/endpoint-data.cjs +0 -2
  138. package/codegen/types/endpoint-data.d.cts +0 -3
  139. package/codegen/types/endpoint-data.d.cts.map +0 -1
  140. package/codegen/types/endpoint-data.d.ts +0 -3
  141. package/codegen/types/endpoint-data.d.ts.map +0 -1
  142. package/codegen/types/endpoint-data.js +0 -1
  143. package/codegen/types/generate-query-api-params.cjs +0 -2
  144. package/codegen/types/generate-query-api-params.d.cts.map +0 -1
  145. package/codegen/types/generate-query-api-params.d.ts +0 -162
  146. package/codegen/types/generate-query-api-params.d.ts.map +0 -1
  147. package/codegen/types/generate-query-api-params.js +0 -1
  148. package/codegen/types/import-file-params.cjs +0 -2
  149. package/codegen/types/import-file-params.d.cts +0 -5
  150. package/codegen/types/import-file-params.d.cts.map +0 -1
  151. package/codegen/types/import-file-params.d.ts +0 -5
  152. package/codegen/types/import-file-params.d.ts.map +0 -1
  153. package/codegen/types/import-file-params.js +0 -1
  154. package/codegen/types/index.cjs +0 -23
  155. package/codegen/types/index.d.cts +0 -8
  156. package/codegen/types/index.d.cts.map +0 -1
  157. package/codegen/types/index.d.ts +0 -8
  158. package/codegen/types/index.d.ts.map +0 -1
  159. package/codegen/types/index.js +0 -7
  160. package/codegen/types/meta-info.cjs +0 -2
  161. package/codegen/types/meta-info.d.cts +0 -6
  162. package/codegen/types/meta-info.d.cts.map +0 -1
  163. package/codegen/types/meta-info.d.ts +0 -6
  164. package/codegen/types/meta-info.d.ts.map +0 -1
  165. package/codegen/types/meta-info.js +0 -1
  166. package/codegen/types/type-info.cjs +0 -2
  167. package/codegen/types/type-info.d.cts +0 -4
  168. package/codegen/types/type-info.d.cts.map +0 -1
  169. package/codegen/types/type-info.d.ts +0 -4
  170. package/codegen/types/type-info.d.ts.map +0 -1
  171. package/codegen/types/type-info.js +0 -1
  172. package/codegen/utils/create-short-model-type.cjs +0 -12
  173. package/codegen/utils/create-short-model-type.d.cts +0 -5
  174. package/codegen/utils/create-short-model-type.d.cts.map +0 -1
  175. package/codegen/utils/create-short-model-type.d.ts +0 -5
  176. package/codegen/utils/create-short-model-type.d.ts.map +0 -1
  177. package/codegen/utils/create-short-model-type.js +0 -8
  178. package/codegen/utils/remove-unused-types.cjs +0 -117
  179. package/codegen/utils/remove-unused-types.d.cts +0 -7
  180. package/codegen/utils/remove-unused-types.d.cts.map +0 -1
  181. package/codegen/utils/remove-unused-types.d.ts +0 -7
  182. package/codegen/utils/remove-unused-types.d.ts.map +0 -1
  183. package/codegen/utils/remove-unused-types.js +0 -110
  184. package/codegen/utils/unpack-filter-option.cjs +0 -23
  185. package/codegen/utils/unpack-filter-option.d.cts +0 -7
  186. package/codegen/utils/unpack-filter-option.d.cts.map +0 -1
  187. package/codegen/utils/unpack-filter-option.d.ts +0 -7
  188. package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
  189. package/codegen/utils/unpack-filter-option.js +0 -19
  190. package/index.d.cts +0 -3
  191. package/index.d.cts.map +0 -1
  192. package/index.d.ts.map +0 -1
  193. package/runtime/endpoint-infinite-query.cjs +0 -101
  194. package/runtime/endpoint-infinite-query.d.cts +0 -17
  195. package/runtime/endpoint-infinite-query.d.cts.map +0 -1
  196. package/runtime/endpoint-infinite-query.d.ts +0 -17
  197. package/runtime/endpoint-infinite-query.d.ts.map +0 -1
  198. package/runtime/endpoint-infinite-query.js +0 -97
  199. package/runtime/endpoint-infinite-query.types.cjs +0 -2
  200. package/runtime/endpoint-infinite-query.types.d.cts +0 -30
  201. package/runtime/endpoint-infinite-query.types.d.cts.map +0 -1
  202. package/runtime/endpoint-infinite-query.types.d.ts +0 -30
  203. package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
  204. package/runtime/endpoint-infinite-query.types.js +0 -1
  205. package/runtime/endpoint-mutation.cjs +0 -74
  206. package/runtime/endpoint-mutation.d.cts +0 -13
  207. package/runtime/endpoint-mutation.d.cts.map +0 -1
  208. package/runtime/endpoint-mutation.d.ts +0 -13
  209. package/runtime/endpoint-mutation.d.ts.map +0 -1
  210. package/runtime/endpoint-mutation.js +0 -70
  211. package/runtime/endpoint-mutation.types.cjs +0 -2
  212. package/runtime/endpoint-mutation.types.d.cts +0 -36
  213. package/runtime/endpoint-mutation.types.d.cts.map +0 -1
  214. package/runtime/endpoint-mutation.types.d.ts +0 -36
  215. package/runtime/endpoint-mutation.types.d.ts.map +0 -1
  216. package/runtime/endpoint-mutation.types.js +0 -1
  217. package/runtime/endpoint-query-client.cjs +0 -79
  218. package/runtime/endpoint-query-client.d.cts +0 -13
  219. package/runtime/endpoint-query-client.d.cts.map +0 -1
  220. package/runtime/endpoint-query-client.d.ts +0 -13
  221. package/runtime/endpoint-query-client.d.ts.map +0 -1
  222. package/runtime/endpoint-query-client.js +0 -75
  223. package/runtime/endpoint-query-client.types.cjs +0 -2
  224. package/runtime/endpoint-query-client.types.d.cts +0 -16
  225. package/runtime/endpoint-query-client.types.d.cts.map +0 -1
  226. package/runtime/endpoint-query-client.types.d.ts +0 -16
  227. package/runtime/endpoint-query-client.types.d.ts.map +0 -1
  228. package/runtime/endpoint-query-client.types.js +0 -1
  229. package/runtime/endpoint-query.cjs +0 -214
  230. package/runtime/endpoint-query.d.cts +0 -29
  231. package/runtime/endpoint-query.d.cts.map +0 -1
  232. package/runtime/endpoint-query.d.ts +0 -29
  233. package/runtime/endpoint-query.d.ts.map +0 -1
  234. package/runtime/endpoint-query.js +0 -208
  235. package/runtime/endpoint-query.types.cjs +0 -2
  236. package/runtime/endpoint-query.types.d.cts +0 -42
  237. package/runtime/endpoint-query.types.d.cts.map +0 -1
  238. package/runtime/endpoint-query.types.d.ts +0 -42
  239. package/runtime/endpoint-query.types.d.ts.map +0 -1
  240. package/runtime/endpoint-query.types.js +0 -1
  241. package/runtime/endpoint.cjs +0 -131
  242. package/runtime/endpoint.d.cts +0 -73
  243. package/runtime/endpoint.d.cts.map +0 -1
  244. package/runtime/endpoint.d.ts +0 -73
  245. package/runtime/endpoint.d.ts.map +0 -1
  246. package/runtime/endpoint.js +0 -127
  247. package/runtime/endpoint.types.cjs +0 -2
  248. package/runtime/endpoint.types.d.cts +0 -24
  249. package/runtime/endpoint.types.d.cts.map +0 -1
  250. package/runtime/endpoint.types.d.ts +0 -24
  251. package/runtime/endpoint.types.d.ts.map +0 -1
  252. package/runtime/endpoint.types.js +0 -1
  253. package/runtime/http-client.cjs +0 -190
  254. package/runtime/http-client.d.cts +0 -85
  255. package/runtime/http-client.d.cts.map +0 -1
  256. package/runtime/http-client.d.ts +0 -85
  257. package/runtime/http-client.d.ts.map +0 -1
  258. package/runtime/http-client.js +0 -184
  259. package/runtime/index.cjs +0 -25
  260. package/runtime/index.d.cts +0 -10
  261. package/runtime/index.d.cts.map +0 -1
  262. package/runtime/index.d.ts +0 -10
  263. package/runtime/index.d.ts.map +0 -1
  264. package/runtime/index.js +0 -9
package/codegen/index.cjs DELETED
@@ -1,545 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.generateApi = void 0;
21
- const node_path_1 = __importDefault(require("node:path"));
22
- const node_url_1 = require("node:url");
23
- const lodash_es_1 = require("lodash-es");
24
- const swagger_typescript_api_1 = require("swagger-typescript-api");
25
- const all_endpoints_per_file_tmpl_js_1 = require("./templates/all-endpoints-per-file.tmpl.cjs");
26
- const all_exports_tmpl_js_1 = require("./templates/all-exports.tmpl.cjs");
27
- const constants_js_1 = require("./templates/constants.cjs");
28
- const data_contracts_file_tmpl_js_1 = require("./templates/data-contracts-file.tmpl.cjs");
29
- const endpoint_per_file_tmpl_js_1 = require("./templates/endpoint-per-file.tmpl.cjs");
30
- const index_ts_for_endpoint_per_file_tmpl_js_1 = require("./templates/index-ts-for-endpoint-per-file.tmpl.cjs");
31
- const meta_info_tmpl_js_1 = require("./templates/meta-info.tmpl.cjs");
32
- const remove_unused_types_js_1 = require("./utils/remove-unused-types.cjs");
33
- const unpack_filter_option_js_1 = require("./utils/unpack-filter-option.cjs");
34
- __exportStar(require("./types/index.cjs"), exports);
35
- const __filename = (0, node_url_1.fileURLToPath)(require("url").pathToFileURL(__filename));
36
- const __dirname = node_path_1.default.dirname(__filename);
37
- const __execdirname = process.cwd();
38
- const generateApi = async (params) => {
39
- if (Array.isArray(params)) {
40
- for await (const param of params) {
41
- await (0, exports.generateApi)(param);
42
- }
43
- return;
44
- }
45
- const tsconfigPath = params.tsconfigPath
46
- ? node_path_1.default.resolve(__execdirname, params.tsconfigPath)
47
- : node_path_1.default.resolve(__execdirname, './tsconfig.json');
48
- console.info('using tsconfig', tsconfigPath);
49
- const importFileParams = {
50
- queryClient: !params.queryClient || typeof params.queryClient === 'string'
51
- ? {
52
- exportName: 'queryClient',
53
- path: 'mobx-tanstack-query-api/builtin',
54
- }
55
- : params.queryClient,
56
- endpoint: !params.endpoint || typeof params.endpoint === 'string'
57
- ? {
58
- exportName: 'Endpoint',
59
- path: 'mobx-tanstack-query-api',
60
- }
61
- : params.endpoint,
62
- httpClient: !params.httpClient || typeof params.httpClient === 'string'
63
- ? {
64
- exportName: 'http',
65
- path: 'mobx-tanstack-query-api/builtin',
66
- }
67
- : params.httpClient,
68
- };
69
- const paths = {
70
- templates: node_path_1.default.resolve(__dirname, 'templates'),
71
- requestInfoClass: node_path_1.default.resolve(__dirname, 'templates/request-info-class.ejs'),
72
- httpClient: node_path_1.default.resolve(__dirname, 'templates/http-client.ejs'),
73
- createRequestInfoInstance: node_path_1.default.resolve(__dirname, 'templates/create-request-info-instance.ejs'),
74
- outputDir: node_path_1.default.resolve(process.cwd(), params.output),
75
- };
76
- //#region swagger-typescript-api
77
- const swaggerTypescriptApiCodegenBaseParams = {
78
- httpClientType: 'fetch',
79
- cleanOutput: params.cleanOutput ?? true,
80
- modular: true,
81
- patch: true,
82
- typeSuffix: 'DC',
83
- disableStrictSSL: false,
84
- singleHttpClient: true,
85
- extractRequestBody: true,
86
- extractRequestParams: false,
87
- extractResponseBody: true,
88
- extractResponseError: true,
89
- generateResponses: true,
90
- generateClient: false,
91
- addReadonly: true,
92
- moduleNameFirstTag: true,
93
- sortTypes: true,
94
- templates: paths.templates.toString(),
95
- primitiveTypeConstructs: (constructs) => {
96
- return {
97
- ...constructs,
98
- object: () => `Record<string, any>`,
99
- float: () => `number`,
100
- ...params.otherCodegenParams?.primitiveTypeConstructs?.(constructs),
101
- };
102
- },
103
- requestOptions: params.fetchSchemaRequestOptions,
104
- ...params.otherCodegenParams,
105
- };
106
- let codegenProcess;
107
- if (!params.input) {
108
- console.warn('[mobx-tanstack-query-api/codegen]', 'input is not specified', '\nprocess will be skipped');
109
- return;
110
- }
111
- const inputToCodegenInput = (input) => {
112
- const inputData = {};
113
- if (typeof input === 'string') {
114
- inputData.input = input;
115
- inputData.url = input;
116
- }
117
- else {
118
- inputData.spec = input;
119
- }
120
- return inputData;
121
- };
122
- let mixinSwaggerSchema = null;
123
- if (params.mixinInput) {
124
- await (0, swagger_typescript_api_1.generateApi)({
125
- ...swaggerTypescriptApiCodegenBaseParams,
126
- ...inputToCodegenInput(params.mixinInput),
127
- hooks: {
128
- onInit: (configuration) => {
129
- mixinSwaggerSchema = (0, lodash_es_1.cloneDeep)(configuration.swaggerSchema);
130
- },
131
- onPrepareConfig: (config) => {
132
- config.routes.combined?.forEach((routeInfo) => {
133
- routeInfo.routes.sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
134
- });
135
- },
136
- onFormatRouteName: (routeInfo, usageRouteName) => {
137
- let formattedRouteName = usageRouteName;
138
- if (params.addPathSegmentToRouteName === true ||
139
- typeof params.addPathSegmentToRouteName === 'number') {
140
- const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === 'number'
141
- ? params.addPathSegmentToRouteName
142
- : 0;
143
- const pathSegments = routeInfo.route.split('/').filter(Boolean);
144
- const { _ } = codegenProcess.getRenderTemplateData()
145
- .utils;
146
- formattedRouteName = _.camelCase(`${pathSegments[pathSegmentForSuffix] || ''}_${formattedRouteName}`);
147
- }
148
- const endpointName = formattedRouteName;
149
- return (params?.formatEndpointName?.(endpointName, routeInfo) ??
150
- swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(routeInfo, endpointName) ??
151
- endpointName);
152
- },
153
- },
154
- });
155
- }
156
- const generated = await (0, swagger_typescript_api_1.generateApi)({
157
- ...swaggerTypescriptApiCodegenBaseParams,
158
- ...inputToCodegenInput(params.input),
159
- hooks: {
160
- onInit: (configuration, codeGenProcessFromInit) => {
161
- codegenProcess = codeGenProcessFromInit;
162
- const resultSwaggerSchema = configuration.swaggerSchema;
163
- resultSwaggerSchema.components = resultSwaggerSchema.components || {};
164
- resultSwaggerSchema.components.schemas =
165
- resultSwaggerSchema.components.schemas || {};
166
- resultSwaggerSchema.paths = {
167
- ...resultSwaggerSchema.paths,
168
- ...mixinSwaggerSchema?.paths,
169
- };
170
- resultSwaggerSchema.components.schemas = {
171
- ...resultSwaggerSchema.components.schemas,
172
- ...mixinSwaggerSchema?.components?.schemas,
173
- };
174
- return swaggerTypescriptApiCodegenBaseParams?.hooks?.onInit?.(configuration, codeGenProcessFromInit);
175
- },
176
- onPrepareConfig: (config) => {
177
- config.routes.combined?.forEach((routeInfo) => {
178
- routeInfo.routes.sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
179
- });
180
- return swaggerTypescriptApiCodegenBaseParams?.hooks?.onPrepareConfig?.(config);
181
- },
182
- onFormatRouteName: (routeInfo, usageRouteName) => {
183
- let formattedRouteName = usageRouteName;
184
- if (params.addPathSegmentToRouteName === true ||
185
- typeof params.addPathSegmentToRouteName === 'number') {
186
- const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === 'number'
187
- ? params.addPathSegmentToRouteName
188
- : 0;
189
- const pathSegments = routeInfo.route.split('/').filter(Boolean);
190
- const { _ } = codegenProcess.getRenderTemplateData()
191
- .utils;
192
- formattedRouteName = _.camelCase(`${pathSegments[pathSegmentForSuffix] || ''}_${formattedRouteName}`);
193
- }
194
- const endpointName = formattedRouteName;
195
- return (params?.formatEndpointName?.(endpointName, routeInfo) ??
196
- swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(routeInfo, endpointName) ??
197
- endpointName);
198
- },
199
- },
200
- });
201
- //#endregion
202
- const utils = codegenProcess.getRenderTemplateData()
203
- .utils;
204
- const { _ } = utils;
205
- let namespace = null;
206
- if (params.namespace) {
207
- if (typeof params.namespace === 'function') {
208
- namespace = params.namespace(utils);
209
- }
210
- else {
211
- namespace = utils._.camelCase(params.namespace);
212
- }
213
- }
214
- const codegenFs = codegenProcess.fileSystem;
215
- codegenFs.cleanDir(params.output);
216
- codegenFs.createDir(params.output);
217
- const filterTypes = (0, unpack_filter_option_js_1.unpackFilterOption)(params.filterTypes, (modelType) => modelType.name);
218
- generated.configuration.modelTypes =
219
- generated.configuration.modelTypes.filter((modelType) => filterTypes(modelType));
220
- const allRoutes = Object.values(generated.configuration.routes)
221
- .flat()
222
- .flatMap((routeGroup) => 'routes' in routeGroup ? routeGroup.routes : routeGroup);
223
- const filterEndpoint = (0, unpack_filter_option_js_1.unpackFilterOption)(params.filterEndpoints, (route) => route.raw?.operationId || '');
224
- const baseTmplParams = {
225
- ...generated,
226
- codegenParams: params,
227
- configuration: generated.configuration,
228
- formatTSContent: generated.formatTSContent,
229
- codegenProcess,
230
- importFileParams,
231
- utils,
232
- filterTypes,
233
- };
234
- const reservedDataContractNamesMap = new Map();
235
- const collectedExportFilesFromIndexFile = [];
236
- const groupsMap = new Map();
237
- const nonEmptyGroups = new Set();
238
- const tagsSet = new Set();
239
- if (params.groupBy == null) {
240
- collectedExportFilesFromIndexFile.push('endpoints');
241
- if (params.outputType === 'one-endpoint-per-file') {
242
- // #region кодогенерация 1 эндпоинт - 1 файл без группировки
243
- codegenFs.createDir(node_path_1.default.resolve(params.output, 'endpoints'));
244
- const fileNamesWithRequestInfo = [];
245
- for await (const route of allRoutes) {
246
- const { content: requestInfoPerFileContent, reservedDataContractNames, } = await (0, endpoint_per_file_tmpl_js_1.endpointPerFileTmpl)({
247
- ...baseTmplParams,
248
- route,
249
- relativePathDataContracts: '../data-contracts',
250
- groupName: null,
251
- metaInfo: params.noMetaInfo
252
- ? null
253
- : {
254
- groupNames: [],
255
- namespace,
256
- },
257
- });
258
- if (Array.isArray(route.raw.tags)) {
259
- route.raw.tags.forEach((tag) => {
260
- tagsSet.add(tag);
261
- });
262
- }
263
- reservedDataContractNames.forEach((name) => {
264
- reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
265
- });
266
- if (!filterEndpoint(route)) {
267
- continue;
268
- }
269
- const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
270
- fileNamesWithRequestInfo.push(fileName);
271
- codegenFs.createFile({
272
- path: node_path_1.default.resolve(params.output, 'endpoints'),
273
- fileName,
274
- withPrefix: false,
275
- content: requestInfoPerFileContent,
276
- });
277
- }
278
- codegenFs.createFile({
279
- path: node_path_1.default.resolve(params.output, 'endpoints'),
280
- fileName: 'index.ts',
281
- withPrefix: false,
282
- content: await (0, index_ts_for_endpoint_per_file_tmpl_js_1.indexTsForEndpointPerFileTmpl)({
283
- ...baseTmplParams,
284
- generatedRequestFileNames: fileNamesWithRequestInfo,
285
- }),
286
- });
287
- // #endregion
288
- }
289
- else {
290
- // #region кодогенерация несколько эндпоинтов в 1 файле без группировки
291
- const { content: requestInfoPerFileContent, reservedDataContractNames } = await (0, all_endpoints_per_file_tmpl_js_1.allEndpointPerFileTmpl)({
292
- ...baseTmplParams,
293
- routes: allRoutes,
294
- relativePathDataContracts: './data-contracts',
295
- groupName: null,
296
- metaInfo: params.noMetaInfo
297
- ? null
298
- : {
299
- namespace,
300
- groupNames: [],
301
- },
302
- });
303
- reservedDataContractNames.forEach((name) => {
304
- reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
305
- });
306
- const filteredRoutes = allRoutes.filter(filterEndpoint);
307
- const hasFilteredRoutes = filteredRoutes.length > 0;
308
- if (hasFilteredRoutes) {
309
- filteredRoutes.forEach((route) => {
310
- if (Array.isArray(route.raw.tags)) {
311
- route.raw.tags.forEach((tag) => {
312
- tagsSet.add(tag);
313
- });
314
- }
315
- });
316
- const fileName = 'endpoints.ts';
317
- collectedExportFilesFromIndexFile.push('endpoints');
318
- codegenFs.createFile({
319
- path: params.output,
320
- fileName,
321
- withPrefix: false,
322
- content: requestInfoPerFileContent,
323
- });
324
- }
325
- // #endregion
326
- }
327
- }
328
- else {
329
- // #region кодогенерация с группировкой
330
- // #region разбиение роутов по группам
331
- allRoutes.forEach((route) => {
332
- let group;
333
- if (typeof params.groupBy === 'function') {
334
- group = params.groupBy(route);
335
- }
336
- else if (params.groupBy?.includes('path-segment')) {
337
- const segmentIndex = +params.groupBy.replaceAll(/path-segment-?/g, '') || 0;
338
- group =
339
- route.request.path?.split('/')?.filter(Boolean)?.[segmentIndex] || undefined;
340
- }
341
- else if (params.groupBy?.includes('tag')) {
342
- const tagIndex = +params.groupBy.replaceAll(/tag-?/g, '') || 0;
343
- group = route.raw?.tags?.[tagIndex] ?? undefined;
344
- }
345
- if (group == null) {
346
- group = 'other';
347
- }
348
- if (!groupsMap.has(group)) {
349
- groupsMap.set(group, []);
350
- }
351
- groupsMap.get(group)?.push(route);
352
- });
353
- // #endregion
354
- const filterGroups = (0, unpack_filter_option_js_1.unpackFilterOption)(params.filterGroups, (groupName) => groupName);
355
- for await (const [groupName, routes] of groupsMap) {
356
- if (!filterGroups(groupName)) {
357
- continue;
358
- }
359
- const fileNamesWithRequestInfo = [];
360
- const groupDirectory = node_path_1.default.resolve(params.output, _.kebabCase(groupName));
361
- codegenFs.createDir(groupDirectory);
362
- let hasFilteredRoutes = false;
363
- if (params.outputType === 'one-endpoint-per-file') {
364
- // #region Генерация одного эндпоинта на 1 файл
365
- codegenFs.createDir(node_path_1.default.resolve(groupDirectory, 'endpoints'));
366
- for await (const route of routes) {
367
- const { content: requestInfoPerFileContent, reservedDataContractNames, } = await (0, endpoint_per_file_tmpl_js_1.endpointPerFileTmpl)({
368
- ...baseTmplParams,
369
- route,
370
- relativePathDataContracts: '../../data-contracts',
371
- groupName,
372
- metaInfo: params.noMetaInfo
373
- ? null
374
- : {
375
- namespace,
376
- groupNames: [],
377
- },
378
- });
379
- reservedDataContractNames.forEach((name) => {
380
- reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
381
- });
382
- if (!filterEndpoint(route)) {
383
- continue;
384
- }
385
- hasFilteredRoutes = true;
386
- if (Array.isArray(route.raw.tags)) {
387
- route.raw.tags.forEach((tag) => {
388
- tagsSet.add(tag);
389
- });
390
- }
391
- const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
392
- fileNamesWithRequestInfo.push(fileName);
393
- codegenFs.createFile({
394
- path: node_path_1.default.resolve(params.output, _.kebabCase(groupName), 'endpoints'),
395
- fileName,
396
- withPrefix: false,
397
- content: requestInfoPerFileContent,
398
- });
399
- }
400
- // #endregion
401
- }
402
- else {
403
- // #region Генерация нескольких эндпоинтов на 1 файл
404
- const { content: requestInfoPerFileContent, reservedDataContractNames, } = await (0, all_endpoints_per_file_tmpl_js_1.allEndpointPerFileTmpl)({
405
- ...baseTmplParams,
406
- routes,
407
- relativePathDataContracts: '../data-contracts',
408
- groupName,
409
- metaInfo: params.noMetaInfo
410
- ? null
411
- : {
412
- namespace,
413
- groupNames: [],
414
- },
415
- });
416
- reservedDataContractNames.forEach((name) => {
417
- reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
418
- });
419
- const filteredRoutes = routes.filter(filterEndpoint);
420
- hasFilteredRoutes = filteredRoutes.length > 0;
421
- if (hasFilteredRoutes) {
422
- filteredRoutes.forEach((route) => {
423
- if (Array.isArray(route.raw.tags)) {
424
- route.raw.tags.forEach((tag) => {
425
- tagsSet.add(tag);
426
- });
427
- }
428
- });
429
- const fileName = 'endpoints.ts';
430
- fileNamesWithRequestInfo.push(fileName);
431
- codegenFs.createFile({
432
- path: groupDirectory,
433
- fileName,
434
- withPrefix: false,
435
- content: requestInfoPerFileContent,
436
- });
437
- }
438
- // #endregion
439
- }
440
- if (hasFilteredRoutes) {
441
- nonEmptyGroups.add(groupName);
442
- const exportGroupName = params.formatExportGroupName
443
- ? params.formatExportGroupName(_.camelCase(groupName), utils)
444
- : _.camelCase(groupName);
445
- codegenFs.createFile({
446
- path: groupDirectory,
447
- fileName: 'index.ts',
448
- withPrefix: false,
449
- content: `${constants_js_1.LINTERS_IGNORE}
450
- export * as ${exportGroupName} from './endpoints';
451
- `,
452
- });
453
- if (params.outputType === 'one-endpoint-per-file') {
454
- codegenFs.createFile({
455
- path: node_path_1.default.resolve(groupDirectory, 'endpoints'),
456
- fileName: 'index.ts',
457
- withPrefix: false,
458
- content: await (0, index_ts_for_endpoint_per_file_tmpl_js_1.indexTsForEndpointPerFileTmpl)({
459
- ...baseTmplParams,
460
- generatedRequestFileNames: fileNamesWithRequestInfo,
461
- }),
462
- });
463
- }
464
- collectedExportFilesFromIndexFile.push(_.kebabCase(groupName));
465
- }
466
- else {
467
- codegenFs.removeDir(node_path_1.default.resolve(params.output, _.kebabCase(groupName)));
468
- }
469
- }
470
- // #endregion
471
- }
472
- const metaInfo = !params.noMetaInfo &&
473
- (namespace ?? (nonEmptyGroups.size > 0 || tagsSet.size > 0))
474
- ? {
475
- namespace,
476
- groupNames: [...nonEmptyGroups.values()],
477
- tags: [...tagsSet.values()],
478
- }
479
- : null;
480
- const excludedDataContractNames = Array.from(reservedDataContractNamesMap.entries())
481
- .filter(([_, count]) => count === 1)
482
- .map(([name]) => name);
483
- const dataContractsContent = await (0, data_contracts_file_tmpl_js_1.dataContractsFileTmpl)({
484
- ...baseTmplParams,
485
- excludedDataContractNames,
486
- });
487
- codegenFs.createFile({
488
- path: paths.outputDir,
489
- fileName: 'data-contracts.ts',
490
- withPrefix: false,
491
- content: dataContractsContent,
492
- });
493
- if (metaInfo) {
494
- codegenFs.createFile({
495
- path: paths.outputDir,
496
- fileName: 'meta-info.ts',
497
- withPrefix: false,
498
- content: await (0, meta_info_tmpl_js_1.metaInfoTmpl)({
499
- ...baseTmplParams,
500
- metaInfo,
501
- }),
502
- });
503
- }
504
- if (namespace) {
505
- codegenFs.createFile({
506
- path: paths.outputDir,
507
- fileName: '__exports.ts',
508
- withPrefix: false,
509
- content: await (0, all_exports_tmpl_js_1.allExportsTmpl)({
510
- ...baseTmplParams,
511
- collectedExportFiles: collectedExportFilesFromIndexFile,
512
- metaInfo,
513
- }),
514
- });
515
- codegenFs.createFile({
516
- path: paths.outputDir,
517
- fileName: 'index.ts',
518
- withPrefix: false,
519
- content: `${constants_js_1.LINTERS_IGNORE}
520
- export * as ${namespace} from './__exports';
521
- `,
522
- });
523
- }
524
- else {
525
- codegenFs.createFile({
526
- path: paths.outputDir,
527
- fileName: 'index.ts',
528
- withPrefix: false,
529
- content: await (0, all_exports_tmpl_js_1.allExportsTmpl)({
530
- ...baseTmplParams,
531
- collectedExportFiles: collectedExportFilesFromIndexFile,
532
- metaInfo,
533
- }),
534
- });
535
- }
536
- if (params.removeUnusedTypes) {
537
- (0, remove_unused_types_js_1.removeUnusedTypes)({
538
- directory: params.output,
539
- keepTypes: params.removeUnusedTypes === true
540
- ? undefined
541
- : params.removeUnusedTypes.keepTypes,
542
- });
543
- }
544
- };
545
- exports.generateApi = generateApi;
@@ -1,4 +0,0 @@
1
- import type { GenerateQueryApiParams } from "./types/index.cjs";
2
- export * from "./types/index.cjs";
3
- export declare const generateApi: (params: GenerateQueryApiParams | GenerateQueryApiParams[]) => Promise<void>;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAIV,sBAAsB,EAEvB,0BAAyB;AAI1B,kCAAiC;AAOjC,eAAO,MAAM,WAAW,GACtB,QAAQ,sBAAsB,GAAG,sBAAsB,EAAE,KAExD,OAAO,CAAC,IAAI,CAorBd,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { GenerateQueryApiParams } from "./types/index.js";
2
- export * from "./types/index.js";
3
- export declare const generateApi: (params: GenerateQueryApiParams | GenerateQueryApiParams[]) => Promise<void>;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAIV,sBAAsB,EAEvB,yBAAyB;AAI1B,iCAAiC;AAOjC,eAAO,MAAM,WAAW,GACtB,QAAQ,sBAAsB,GAAG,sBAAsB,EAAE,KAExD,OAAO,CAAC,IAAI,CAorBd,CAAC"}