mobx-tanstack-query-api 0.25.0 → 0.26.1

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 (269) hide show
  1. package/bin.cjs +53 -0
  2. package/bin.cjs.map +1 -0
  3. package/bin.d.ts +1 -0
  4. package/bin.js +51 -0
  5. package/bin.js.map +1 -0
  6. package/builtin.cjs +27 -0
  7. package/builtin.cjs.map +1 -0
  8. package/builtin.d.ts +6 -0
  9. package/builtin.js +27 -0
  10. package/builtin.js.map +1 -0
  11. package/cli.cjs +1278 -0
  12. package/cli.cjs.map +1 -0
  13. package/{codegen/types/generate-query-api-params.d.cts → cli.d.ts} +54 -10
  14. package/cli.js +1277 -0
  15. package/cli.js.map +1 -0
  16. package/index.cjs +771 -16
  17. package/index.cjs.map +1 -0
  18. package/index.d.ts +322 -2
  19. package/index.js +768 -2
  20. package/index.js.map +1 -0
  21. package/package.json +25 -62
  22. package/builtin/index.cjs +0 -25
  23. package/builtin/index.d.cts +0 -4
  24. package/builtin/index.d.cts.map +0 -1
  25. package/builtin/index.d.ts +0 -4
  26. package/builtin/index.d.ts.map +0 -1
  27. package/builtin/index.js +0 -22
  28. package/cli/bin.cjs +0 -17
  29. package/cli/bin.d.cts +0 -2
  30. package/cli/bin.d.cts.map +0 -1
  31. package/cli/bin.d.ts +0 -2
  32. package/cli/bin.d.ts.map +0 -1
  33. package/cli/bin.js +0 -15
  34. package/cli/index.cjs +0 -18
  35. package/cli/index.d.cts +0 -3
  36. package/cli/index.d.cts.map +0 -1
  37. package/cli/index.d.ts +0 -3
  38. package/cli/index.d.ts.map +0 -1
  39. package/cli/index.js +0 -2
  40. package/cli/utils/define-config.cjs +0 -9
  41. package/cli/utils/define-config.d.cts +0 -4
  42. package/cli/utils/define-config.d.cts.map +0 -1
  43. package/cli/utils/define-config.d.ts +0 -4
  44. package/cli/utils/define-config.d.ts.map +0 -1
  45. package/cli/utils/define-config.js +0 -5
  46. package/cli/utils/exec-config-path.cjs +0 -16
  47. package/cli/utils/exec-config-path.d.cts +0 -2
  48. package/cli/utils/exec-config-path.d.cts.map +0 -1
  49. package/cli/utils/exec-config-path.d.ts +0 -2
  50. package/cli/utils/exec-config-path.d.ts.map +0 -1
  51. package/cli/utils/exec-config-path.js +0 -12
  52. package/cli/utils/resolve-config-path.cjs +0 -65
  53. package/cli/utils/resolve-config-path.d.cts +0 -3
  54. package/cli/utils/resolve-config-path.d.cts.map +0 -1
  55. package/cli/utils/resolve-config-path.d.ts +0 -3
  56. package/cli/utils/resolve-config-path.d.ts.map +0 -1
  57. package/cli/utils/resolve-config-path.js +0 -25
  58. package/codegen/index.cjs +0 -545
  59. package/codegen/index.d.cts +0 -4
  60. package/codegen/index.d.cts.map +0 -1
  61. package/codegen/index.d.ts +0 -4
  62. package/codegen/index.d.ts.map +0 -1
  63. package/codegen/index.js +0 -524
  64. package/codegen/templates/all-endpoints-per-file.tmpl.cjs +0 -94
  65. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts +0 -14
  66. package/codegen/templates/all-endpoints-per-file.tmpl.d.cts.map +0 -1
  67. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts +0 -14
  68. package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +0 -1
  69. package/codegen/templates/all-endpoints-per-file.tmpl.js +0 -90
  70. package/codegen/templates/all-exports.tmpl.cjs +0 -14
  71. package/codegen/templates/all-exports.tmpl.d.cts +0 -9
  72. package/codegen/templates/all-exports.tmpl.d.cts.map +0 -1
  73. package/codegen/templates/all-exports.tmpl.d.ts +0 -9
  74. package/codegen/templates/all-exports.tmpl.d.ts.map +0 -1
  75. package/codegen/templates/all-exports.tmpl.js +0 -9
  76. package/codegen/templates/constants.cjs +0 -5
  77. package/codegen/templates/constants.d.cts +0 -2
  78. package/codegen/templates/constants.d.cts.map +0 -1
  79. package/codegen/templates/constants.d.ts +0 -2
  80. package/codegen/templates/constants.d.ts.map +0 -1
  81. package/codegen/templates/constants.js +0 -2
  82. package/codegen/templates/data-contract.tmpl.cjs +0 -49
  83. package/codegen/templates/data-contract.tmpl.d.cts +0 -8
  84. package/codegen/templates/data-contract.tmpl.d.cts.map +0 -1
  85. package/codegen/templates/data-contract.tmpl.d.ts +0 -8
  86. package/codegen/templates/data-contract.tmpl.d.ts.map +0 -1
  87. package/codegen/templates/data-contract.tmpl.js +0 -45
  88. package/codegen/templates/data-contracts-file.tmpl.cjs +0 -27
  89. package/codegen/templates/data-contracts-file.tmpl.d.cts +0 -6
  90. package/codegen/templates/data-contracts-file.tmpl.d.cts.map +0 -1
  91. package/codegen/templates/data-contracts-file.tmpl.d.ts +0 -6
  92. package/codegen/templates/data-contracts-file.tmpl.d.ts.map +0 -1
  93. package/codegen/templates/data-contracts-file.tmpl.js +0 -23
  94. package/codegen/templates/endpoint-jsdoc.tmpl.cjs +0 -111
  95. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts +0 -8
  96. package/codegen/templates/endpoint-jsdoc.tmpl.d.cts.map +0 -1
  97. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts +0 -8
  98. package/codegen/templates/endpoint-jsdoc.tmpl.d.ts.map +0 -1
  99. package/codegen/templates/endpoint-jsdoc.tmpl.js +0 -107
  100. package/codegen/templates/endpoint-per-file.tmpl.cjs +0 -87
  101. package/codegen/templates/endpoint-per-file.tmpl.d.cts +0 -14
  102. package/codegen/templates/endpoint-per-file.tmpl.d.cts.map +0 -1
  103. package/codegen/templates/endpoint-per-file.tmpl.d.ts +0 -14
  104. package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +0 -1
  105. package/codegen/templates/endpoint-per-file.tmpl.js +0 -83
  106. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.cjs +0 -10
  107. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts +0 -6
  108. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.cts.map +0 -1
  109. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts +0 -6
  110. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.d.ts.map +0 -1
  111. package/codegen/templates/index-ts-for-endpoint-per-file.tmpl.js +0 -6
  112. package/codegen/templates/meta-info.tmpl.cjs +0 -48
  113. package/codegen/templates/meta-info.tmpl.d.cts +0 -9
  114. package/codegen/templates/meta-info.tmpl.d.cts.map +0 -1
  115. package/codegen/templates/meta-info.tmpl.d.ts +0 -9
  116. package/codegen/templates/meta-info.tmpl.d.ts.map +0 -1
  117. package/codegen/templates/meta-info.tmpl.js +0 -42
  118. package/codegen/templates/new-endpoint.tmpl.cjs +0 -188
  119. package/codegen/templates/new-endpoint.tmpl.d.cts +0 -15
  120. package/codegen/templates/new-endpoint.tmpl.d.cts.map +0 -1
  121. package/codegen/templates/new-endpoint.tmpl.d.ts +0 -15
  122. package/codegen/templates/new-endpoint.tmpl.d.ts.map +0 -1
  123. package/codegen/templates/new-endpoint.tmpl.js +0 -184
  124. package/codegen/types/all-import-file-params.cjs +0 -2
  125. package/codegen/types/all-import-file-params.d.cts +0 -5
  126. package/codegen/types/all-import-file-params.d.cts.map +0 -1
  127. package/codegen/types/all-import-file-params.d.ts +0 -5
  128. package/codegen/types/all-import-file-params.d.ts.map +0 -1
  129. package/codegen/types/all-import-file-params.js +0 -1
  130. package/codegen/types/base-tmpl-params.cjs +0 -2
  131. package/codegen/types/base-tmpl-params.d.cts +0 -16
  132. package/codegen/types/base-tmpl-params.d.cts.map +0 -1
  133. package/codegen/types/base-tmpl-params.d.ts +0 -16
  134. package/codegen/types/base-tmpl-params.d.ts.map +0 -1
  135. package/codegen/types/base-tmpl-params.js +0 -1
  136. package/codegen/types/codegen-data-utils.cjs +0 -2
  137. package/codegen/types/codegen-data-utils.d.cts +0 -8
  138. package/codegen/types/codegen-data-utils.d.cts.map +0 -1
  139. package/codegen/types/codegen-data-utils.d.ts +0 -8
  140. package/codegen/types/codegen-data-utils.d.ts.map +0 -1
  141. package/codegen/types/codegen-data-utils.js +0 -1
  142. package/codegen/types/endpoint-data.cjs +0 -2
  143. package/codegen/types/endpoint-data.d.cts +0 -3
  144. package/codegen/types/endpoint-data.d.cts.map +0 -1
  145. package/codegen/types/endpoint-data.d.ts +0 -3
  146. package/codegen/types/endpoint-data.d.ts.map +0 -1
  147. package/codegen/types/endpoint-data.js +0 -1
  148. package/codegen/types/generate-query-api-params.cjs +0 -2
  149. package/codegen/types/generate-query-api-params.d.cts.map +0 -1
  150. package/codegen/types/generate-query-api-params.d.ts +0 -162
  151. package/codegen/types/generate-query-api-params.d.ts.map +0 -1
  152. package/codegen/types/generate-query-api-params.js +0 -1
  153. package/codegen/types/import-file-params.cjs +0 -2
  154. package/codegen/types/import-file-params.d.cts +0 -5
  155. package/codegen/types/import-file-params.d.cts.map +0 -1
  156. package/codegen/types/import-file-params.d.ts +0 -5
  157. package/codegen/types/import-file-params.d.ts.map +0 -1
  158. package/codegen/types/import-file-params.js +0 -1
  159. package/codegen/types/index.cjs +0 -23
  160. package/codegen/types/index.d.cts +0 -8
  161. package/codegen/types/index.d.cts.map +0 -1
  162. package/codegen/types/index.d.ts +0 -8
  163. package/codegen/types/index.d.ts.map +0 -1
  164. package/codegen/types/index.js +0 -7
  165. package/codegen/types/meta-info.cjs +0 -2
  166. package/codegen/types/meta-info.d.cts +0 -6
  167. package/codegen/types/meta-info.d.cts.map +0 -1
  168. package/codegen/types/meta-info.d.ts +0 -6
  169. package/codegen/types/meta-info.d.ts.map +0 -1
  170. package/codegen/types/meta-info.js +0 -1
  171. package/codegen/types/type-info.cjs +0 -2
  172. package/codegen/types/type-info.d.cts +0 -4
  173. package/codegen/types/type-info.d.cts.map +0 -1
  174. package/codegen/types/type-info.d.ts +0 -4
  175. package/codegen/types/type-info.d.ts.map +0 -1
  176. package/codegen/types/type-info.js +0 -1
  177. package/codegen/utils/create-short-model-type.cjs +0 -12
  178. package/codegen/utils/create-short-model-type.d.cts +0 -5
  179. package/codegen/utils/create-short-model-type.d.cts.map +0 -1
  180. package/codegen/utils/create-short-model-type.d.ts +0 -5
  181. package/codegen/utils/create-short-model-type.d.ts.map +0 -1
  182. package/codegen/utils/create-short-model-type.js +0 -8
  183. package/codegen/utils/remove-unused-types.cjs +0 -117
  184. package/codegen/utils/remove-unused-types.d.cts +0 -7
  185. package/codegen/utils/remove-unused-types.d.cts.map +0 -1
  186. package/codegen/utils/remove-unused-types.d.ts +0 -7
  187. package/codegen/utils/remove-unused-types.d.ts.map +0 -1
  188. package/codegen/utils/remove-unused-types.js +0 -110
  189. package/codegen/utils/unpack-filter-option.cjs +0 -23
  190. package/codegen/utils/unpack-filter-option.d.cts +0 -7
  191. package/codegen/utils/unpack-filter-option.d.cts.map +0 -1
  192. package/codegen/utils/unpack-filter-option.d.ts +0 -7
  193. package/codegen/utils/unpack-filter-option.d.ts.map +0 -1
  194. package/codegen/utils/unpack-filter-option.js +0 -19
  195. package/index.d.cts +0 -3
  196. package/index.d.cts.map +0 -1
  197. package/index.d.ts.map +0 -1
  198. package/runtime/endpoint-infinite-query.cjs +0 -101
  199. package/runtime/endpoint-infinite-query.d.cts +0 -17
  200. package/runtime/endpoint-infinite-query.d.cts.map +0 -1
  201. package/runtime/endpoint-infinite-query.d.ts +0 -17
  202. package/runtime/endpoint-infinite-query.d.ts.map +0 -1
  203. package/runtime/endpoint-infinite-query.js +0 -97
  204. package/runtime/endpoint-infinite-query.types.cjs +0 -2
  205. package/runtime/endpoint-infinite-query.types.d.cts +0 -30
  206. package/runtime/endpoint-infinite-query.types.d.cts.map +0 -1
  207. package/runtime/endpoint-infinite-query.types.d.ts +0 -30
  208. package/runtime/endpoint-infinite-query.types.d.ts.map +0 -1
  209. package/runtime/endpoint-infinite-query.types.js +0 -1
  210. package/runtime/endpoint-mutation.cjs +0 -74
  211. package/runtime/endpoint-mutation.d.cts +0 -13
  212. package/runtime/endpoint-mutation.d.cts.map +0 -1
  213. package/runtime/endpoint-mutation.d.ts +0 -13
  214. package/runtime/endpoint-mutation.d.ts.map +0 -1
  215. package/runtime/endpoint-mutation.js +0 -70
  216. package/runtime/endpoint-mutation.types.cjs +0 -2
  217. package/runtime/endpoint-mutation.types.d.cts +0 -36
  218. package/runtime/endpoint-mutation.types.d.cts.map +0 -1
  219. package/runtime/endpoint-mutation.types.d.ts +0 -36
  220. package/runtime/endpoint-mutation.types.d.ts.map +0 -1
  221. package/runtime/endpoint-mutation.types.js +0 -1
  222. package/runtime/endpoint-query-client.cjs +0 -79
  223. package/runtime/endpoint-query-client.d.cts +0 -13
  224. package/runtime/endpoint-query-client.d.cts.map +0 -1
  225. package/runtime/endpoint-query-client.d.ts +0 -13
  226. package/runtime/endpoint-query-client.d.ts.map +0 -1
  227. package/runtime/endpoint-query-client.js +0 -75
  228. package/runtime/endpoint-query-client.types.cjs +0 -2
  229. package/runtime/endpoint-query-client.types.d.cts +0 -16
  230. package/runtime/endpoint-query-client.types.d.cts.map +0 -1
  231. package/runtime/endpoint-query-client.types.d.ts +0 -16
  232. package/runtime/endpoint-query-client.types.d.ts.map +0 -1
  233. package/runtime/endpoint-query-client.types.js +0 -1
  234. package/runtime/endpoint-query.cjs +0 -214
  235. package/runtime/endpoint-query.d.cts +0 -29
  236. package/runtime/endpoint-query.d.cts.map +0 -1
  237. package/runtime/endpoint-query.d.ts +0 -29
  238. package/runtime/endpoint-query.d.ts.map +0 -1
  239. package/runtime/endpoint-query.js +0 -208
  240. package/runtime/endpoint-query.types.cjs +0 -2
  241. package/runtime/endpoint-query.types.d.cts +0 -42
  242. package/runtime/endpoint-query.types.d.cts.map +0 -1
  243. package/runtime/endpoint-query.types.d.ts +0 -42
  244. package/runtime/endpoint-query.types.d.ts.map +0 -1
  245. package/runtime/endpoint-query.types.js +0 -1
  246. package/runtime/endpoint.cjs +0 -131
  247. package/runtime/endpoint.d.cts +0 -73
  248. package/runtime/endpoint.d.cts.map +0 -1
  249. package/runtime/endpoint.d.ts +0 -73
  250. package/runtime/endpoint.d.ts.map +0 -1
  251. package/runtime/endpoint.js +0 -127
  252. package/runtime/endpoint.types.cjs +0 -2
  253. package/runtime/endpoint.types.d.cts +0 -24
  254. package/runtime/endpoint.types.d.cts.map +0 -1
  255. package/runtime/endpoint.types.d.ts +0 -24
  256. package/runtime/endpoint.types.d.ts.map +0 -1
  257. package/runtime/endpoint.types.js +0 -1
  258. package/runtime/http-client.cjs +0 -190
  259. package/runtime/http-client.d.cts +0 -85
  260. package/runtime/http-client.d.cts.map +0 -1
  261. package/runtime/http-client.d.ts +0 -85
  262. package/runtime/http-client.d.ts.map +0 -1
  263. package/runtime/http-client.js +0 -184
  264. package/runtime/index.cjs +0 -25
  265. package/runtime/index.d.cts +0 -10
  266. package/runtime/index.d.cts.map +0 -1
  267. package/runtime/index.d.ts +0 -10
  268. package/runtime/index.d.ts.map +0 -1
  269. package/runtime/index.js +0 -9
package/cli.js ADDED
@@ -0,0 +1,1277 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { cloneDeep } from "lodash-es";
4
+ import { generateApi as generateApi$1 } from "swagger-typescript-api";
5
+ import { splitTextByLines } from "yummies/text";
6
+ import { Project, SyntaxKind, Node } from "ts-morph";
7
+ const LINTERS_IGNORE = `/* eslint-disable */
8
+ /* tslint:disable */`;
9
+ const buildGenerics = (contract) => {
10
+ if (!contract.genericArgs?.length) return "";
11
+ return "<" + contract.genericArgs.map((arg) => {
12
+ const { name, default: defaultType, extends: extendsType } = arg;
13
+ return [
14
+ name,
15
+ extendsType && `extends ${extendsType}`,
16
+ defaultType && `= ${defaultType}`
17
+ ].filter(Boolean).join(" ");
18
+ }).join(", ") + ">";
19
+ };
20
+ const dataContractTmpl = async ({
21
+ contract,
22
+ configuration,
23
+ addExportKeyword
24
+ }) => {
25
+ const { utils } = configuration;
26
+ const { formatDescription } = utils;
27
+ const dataContractTemplates = {
28
+ enum: (contract2) => {
29
+ return `enum ${contract2.name} {\r
30
+ ${contract2.content}\r
31
+ }`;
32
+ },
33
+ interface: (contract2) => {
34
+ return `interface ${contract2.name}${buildGenerics(contract2)} {\r
35
+ ${contract2.content}}`;
36
+ },
37
+ type: (contract2) => {
38
+ return `type ${contract2.name}${buildGenerics(contract2)} = ${contract2.content === contract2.name ? "any" : contract2.content}`;
39
+ }
40
+ };
41
+ let result = "";
42
+ let jsdoc = "";
43
+ if (contract.description) {
44
+ jsdoc = `/**
45
+ * ${formatDescription(contract.description, true)}
46
+ */
47
+ `;
48
+ }
49
+ if (jsdoc) {
50
+ result += jsdoc;
51
+ }
52
+ const templateFn = dataContractTemplates[contract.typeIdentifier] || dataContractTemplates.type;
53
+ const contractType = `${"export "}${templateFn(contract)}`;
54
+ return result + contractType;
55
+ };
56
+ const endpointJSDocTmpl = (params) => {
57
+ const { route, configuration, offset = 0 } = params;
58
+ const { routeName } = route;
59
+ const rawRoute = route.raw;
60
+ const routeRequest = route.request;
61
+ const { utils } = configuration;
62
+ const { _, formatDescription } = utils;
63
+ const jsDocLines = [];
64
+ if (rawRoute.summary) {
65
+ const summaryLines = splitTextByLines(rawRoute.summary, 60).filter(Boolean).map((line) => ({
66
+ content: `**${formatDescription(line, true)}**`
67
+ }));
68
+ if (summaryLines.length > 0) {
69
+ jsDocLines.push(...summaryLines, { content: "" });
70
+ }
71
+ }
72
+ if (rawRoute.description) {
73
+ const descriptionLines = splitTextByLines(rawRoute.description, 60).filter(Boolean).map((line) => ({
74
+ content: formatDescription(line, true)
75
+ }));
76
+ if (descriptionLines.length > 0) {
77
+ jsDocLines.push(...descriptionLines, { content: "" });
78
+ } else {
79
+ jsDocLines.push({
80
+ content: "No description"
81
+ });
82
+ }
83
+ } else {
84
+ jsDocLines.push({
85
+ content: "No description"
86
+ });
87
+ }
88
+ if (rawRoute.operationId) {
89
+ jsDocLines.push({
90
+ name: "operationId",
91
+ content: rawRoute.operationId
92
+ });
93
+ }
94
+ if (_.size(rawRoute.tags)) {
95
+ jsDocLines.push({
96
+ name: "tags",
97
+ content: rawRoute.tags.join(", ")
98
+ });
99
+ }
100
+ jsDocLines.push({
101
+ name: "request",
102
+ content: `**${_.upperCase(routeRequest.method)}:${rawRoute.route}**`
103
+ });
104
+ if (rawRoute.deprecated) {
105
+ jsDocLines.push({
106
+ name: "deprecated"
107
+ });
108
+ }
109
+ if (routeName.duplicate) {
110
+ jsDocLines.push(
111
+ {
112
+ name: "duplicate"
113
+ },
114
+ {
115
+ name: "originalName",
116
+ content: routeName.original
117
+ }
118
+ );
119
+ }
120
+ if (routeRequest.security) {
121
+ jsDocLines.push({
122
+ name: "secure"
123
+ });
124
+ }
125
+ if (rawRoute.responsesTypes.length > 0) {
126
+ jsDocLines.push({
127
+ name: "responses"
128
+ });
129
+ rawRoute.responsesTypes.forEach((response) => {
130
+ jsDocLines.push({
131
+ name: `**${response.status}**`,
132
+ content: `${_.replace(_.replace(response.type, /\/\*/g, String.raw`\*`), /\*\//g, "*\\")} ${response.description}`
133
+ });
134
+ });
135
+ }
136
+ const jsdocContent = jsDocLines.map((it) => {
137
+ let line = " * ";
138
+ if (it.name) {
139
+ line += `@${it.name} `;
140
+ }
141
+ const content = (it.content ?? "").trimEnd();
142
+ if (content) {
143
+ line += content;
144
+ }
145
+ return line;
146
+ });
147
+ const result = `
148
+ /**
149
+ ${jsdocContent.join("\n")}
150
+ */`;
151
+ if (offset > 0) {
152
+ return result.split("\n").map((line) => line.padStart(offset)).join("\n");
153
+ }
154
+ return result;
155
+ };
156
+ const createShortModelType = (shortModelType) => {
157
+ return {
158
+ ...shortModelType,
159
+ typeIdentifier: shortModelType.typeIdentifier || "type",
160
+ rawContent: shortModelType.rawContent || shortModelType.content,
161
+ description: shortModelType.description || ""
162
+ };
163
+ };
164
+ const formatGroupNameEnumKey = (groupName, { _ }) => _.upperFirst(_.camelCase(groupName));
165
+ const formatTagNameEnumKey = (tagName, utils) => formatGroupNameEnumKey(tagName, utils);
166
+ const metaInfoTmpl = async ({
167
+ metaInfo,
168
+ utils,
169
+ formatTSContent,
170
+ codegenParams,
171
+ ...other
172
+ }) => {
173
+ const tagsMap = new Map(
174
+ other.configuration?.apiConfig?.tags?.map((it) => [
175
+ it.name,
176
+ it
177
+ ])
178
+ );
179
+ return await formatTSContent(`${LINTERS_IGNORE}
180
+ ${[
181
+ metaInfo?.namespace && `export const namespace = "${metaInfo?.namespace}";`,
182
+ metaInfo?.groupNames?.length && `
183
+ export const enum Group {
184
+ ${metaInfo?.groupNames.map((groupName) => `${formatGroupNameEnumKey(groupName, utils)} = "${codegenParams.transforms?.groupEnumValue?.(groupName) ?? groupName}"`).join(",\n")}
185
+ }
186
+ `,
187
+ metaInfo?.tags?.length && `
188
+ export const enum Tag {
189
+ ${metaInfo?.tags.map((tagName) => {
190
+ const tagData = tagsMap.get(tagName);
191
+ let description = tagData?.description;
192
+ if (!description) {
193
+ description = utils._.words(tagName).join(" ");
194
+ }
195
+ return [
196
+ description && `/** ${description} */`,
197
+ `${formatTagNameEnumKey(tagName, utils)} = "${codegenParams.transforms?.tagEnumValue?.(tagName) ?? tagName}"`
198
+ ].filter(Boolean).join("\n");
199
+ }).join(",\n")}
200
+ }
201
+ `
202
+ ].filter(Boolean).join("\n")}
203
+ `);
204
+ };
205
+ const requestContentKind = {
206
+ URL_ENCODED: '"application/x-www-form-urlencoded"',
207
+ FORM_DATA: '"multipart/form-data"',
208
+ TEXT: '"text/plain"',
209
+ BINARY: '"application/octet-stream"'
210
+ };
211
+ const responseContentKind = {
212
+ TEXT: '"text"',
213
+ IMAGE: '"blob"',
214
+ FORM_DATA: '"formData"',
215
+ BYTES: '"bytes"'
216
+ };
217
+ const newEndpointTmpl = ({
218
+ route,
219
+ codegenParams,
220
+ importFileParams,
221
+ utils,
222
+ groupName,
223
+ metaInfo,
224
+ filterTypes,
225
+ configuration
226
+ }) => {
227
+ const { _ } = utils;
228
+ const positiveResponseTypes = route.raw.responsesTypes?.filter(
229
+ (it) => +it.status >= 200 && +it.status < 300 && (!it.typeData || filterTypes(it.typeData))
230
+ );
231
+ const { requestBodyInfo, responseBodyInfo } = route;
232
+ const routeRequest = route.request;
233
+ const routeResponse = route.response;
234
+ const { parameters, path: path2, method, payload, query, requestParams, security } = routeRequest;
235
+ const { raw } = route;
236
+ const queryName = query?.name || "query";
237
+ const pathParams = _.values(parameters);
238
+ const pathParamsNames = _.map(pathParams, "name");
239
+ const requestConfigParam = {
240
+ name: "requestParams",
241
+ optional: true,
242
+ type: "RequestParams",
243
+ defaultValue: "{}"
244
+ };
245
+ const inputParams = [
246
+ ...pathParams,
247
+ payload,
248
+ query,
249
+ requestConfigParam
250
+ ].filter(Boolean);
251
+ const getArgs = ({
252
+ withPayload,
253
+ withRequestConfigParam
254
+ }) => {
255
+ return _.sortBy(
256
+ _.compact([
257
+ ...requestParams ? [
258
+ {
259
+ name: pathParams.length > 0 ? `{ ${_.join(pathParamsNames, ", ")}, ...${queryName} }` : queryName,
260
+ optional: false,
261
+ type: utils.getInlineParseContent(requestParams)
262
+ }
263
+ ] : pathParams,
264
+ payload,
265
+ withRequestConfigParam && requestConfigParam
266
+ ]),
267
+ [(o) => o.optional]
268
+ );
269
+ };
270
+ const tags = (raw.tags || []).filter(Boolean);
271
+ const requestOutputDataTypes = positiveResponseTypes.map((it) => it.type);
272
+ const foundErrorModelType = routeResponse.errorType && configuration.modelTypes.find(
273
+ (it) => it.name === routeResponse.errorType
274
+ ) || null;
275
+ const requestOutputErrorType = foundErrorModelType ? routeResponse.errorType : "any";
276
+ const pathParamsToInline = path2.split("/").slice(1);
277
+ query == null ? null : {
278
+ i: pathParamsToInline.length
279
+ };
280
+ const requestInfoMeta = codegenParams.getEndpointMeta?.(route, utils);
281
+ const requestMeta = codegenParams.getRequestMeta?.(route, utils);
282
+ const resultPath = (codegenParams.requestPathPrefix ?? "") + path2 + (codegenParams.requestPathSuffix ?? "");
283
+ const bodyContentType = requestContentKind[requestBodyInfo.contentKind] || null;
284
+ const responseFormat = responseContentKind[responseBodyInfo.success?.schema?.contentKind] || null;
285
+ const reservedDataContractNames = _.uniq([
286
+ ...requestOutputDataTypes,
287
+ requestOutputErrorType || "any",
288
+ ...getArgs({
289
+ withPayload: true
290
+ }).map((it) => it.type)
291
+ ]);
292
+ const pathDeclaration = resultPath.replaceAll("$", "");
293
+ const getHttpRequestGenerics = () => {
294
+ const defaultOkResponse = positiveResponseTypes?.[0]?.type || "unknown";
295
+ const defaultBadResponse = requestOutputErrorType;
296
+ const responses = raw.responsesTypes?.filter(
297
+ (it) => it.status !== "default" && (!it.typeData || filterTypes(it.typeData))
298
+ ) || [];
299
+ if (!responses?.length) {
300
+ return `HttpResponse<unknown, ${requestOutputErrorType}>`;
301
+ }
302
+ if (responses.length === 1 && responses[0].isSuccess) {
303
+ return `HttpResponse<${responses[0].type}, ${requestOutputErrorType}>`;
304
+ }
305
+ return `HttpMultistatusResponse<{
306
+ ${responses.map((it) => {
307
+ return [
308
+ it.description && `/** ${it.description} */`,
309
+ `${it.status}: ${it.type};`
310
+ ].filter(Boolean).join("\n");
311
+ }).join("\n")}
312
+ },
313
+ ${defaultOkResponse},
314
+ ${defaultBadResponse}
315
+ >`;
316
+ };
317
+ const requestInputTypeDc = createShortModelType({
318
+ typeIdentifier: "type",
319
+ name: _.upperFirst(_.camelCase(`${route.routeName.usage}Params`)),
320
+ content: `{
321
+ ${inputParams.map(({ name, optional, type }) => {
322
+ return `${name}${optional ? "?" : ""}:${type}`;
323
+ }).filter(Boolean).join(", ")}
324
+ }`
325
+ });
326
+ const isAllowedInputType = filterTypes(requestInputTypeDc);
327
+ return {
328
+ reservedDataContractNames,
329
+ localModelTypes: isAllowedInputType ? [requestInputTypeDc] : [],
330
+ content: `
331
+ new ${importFileParams.endpoint.exportName}<
332
+ ${getHttpRequestGenerics()},
333
+ ${isAllowedInputType ? requestInputTypeDc.name : "any"},
334
+ ${requestInfoMeta?.typeName ?? "any"}
335
+ >(
336
+ {
337
+ params: ({
338
+ ${inputParams.map((it) => it.name)}
339
+ }) => ({
340
+ path: \`${resultPath}\`,
341
+ method: '${_.upperCase(method)}',
342
+ ${requestMeta?.tmplData ? `meta: ${requestMeta.tmplData},` : ""}
343
+ ${query == null ? "" : `query: ${query.name},`}
344
+ ${payload?.name ? `body: ${payload.name},` : ""}
345
+ ${security ? "secure: true," : ""}
346
+ ${bodyContentType ? `contentType: ${bodyContentType},` : ""}
347
+ ${responseFormat ? `format: ${responseFormat},` : ""}
348
+ ...${requestConfigParam.name},
349
+ }),
350
+ requiredParams: [${inputParams.filter((it) => !it.optional).map((it) => `"${it.name}"`)}],
351
+ operationId: "${raw.operationId || _.camelCase(route.routeName.usage)}",
352
+ path: [${pathDeclaration.split("/").filter(Boolean).map((it) => `"${it}"`)}],
353
+ tags: [${tags.map((tag) => {
354
+ if (metaInfo) {
355
+ return `Tag.${formatTagNameEnumKey(tag, utils)}`;
356
+ }
357
+ return `"${tag}"`;
358
+ })}],
359
+ ${groupName ? `group: ${metaInfo ? `Group.${formatGroupNameEnumKey(groupName, utils)}` : `"${groupName}"`},` : ""}
360
+ ${metaInfo?.namespace ? `namespace,` : ""}
361
+ meta: ${requestInfoMeta?.tmplData ?? "{} as any"},
362
+ },
363
+ ${importFileParams.queryClient.exportName},
364
+ ${importFileParams.httpClient.exportName},
365
+ )
366
+ `.split("\n").map((it) => it.trim()).filter(Boolean).join("\n")
367
+ };
368
+ };
369
+ const allEndpointPerFileTmpl = async (params) => {
370
+ const {
371
+ routes,
372
+ configuration,
373
+ codegenParams,
374
+ formatTSContent,
375
+ importFileParams,
376
+ utils,
377
+ relativePathDataContracts,
378
+ groupName,
379
+ metaInfo
380
+ } = params;
381
+ const { _ } = utils;
382
+ const dataContractNamesInThisFile = [];
383
+ const newEndpointTemplates = routes.map((route) => {
384
+ const newEndpointTemplateData = newEndpointTmpl({
385
+ ...params,
386
+ route
387
+ });
388
+ const { reservedDataContractNames } = newEndpointTemplateData;
389
+ const dataContactNames = new Set(
390
+ Object.keys(
391
+ configuration.config.swaggerSchema?.components?.schemas
392
+ ).map((schemaName) => utils.formatModelName(schemaName))
393
+ );
394
+ reservedDataContractNames.forEach((reservedDataContractName) => {
395
+ if (!dataContactNames.has(reservedDataContractName)) {
396
+ dataContractNamesInThisFile.push(reservedDataContractName);
397
+ }
398
+ });
399
+ return { ...newEndpointTemplateData, route };
400
+ });
401
+ const extraImportLines = [];
402
+ const endpointTemplates = await Promise.all(
403
+ newEndpointTemplates.map(
404
+ async ({
405
+ content: requestInfoInstanceContent,
406
+ localModelTypes,
407
+ route
408
+ }) => {
409
+ const requestInfoMeta = codegenParams.getEndpointMeta?.(route, utils);
410
+ if (requestInfoMeta?.typeNameImportPath && requestInfoMeta.typeName) {
411
+ extraImportLines.push(
412
+ `import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`
413
+ );
414
+ }
415
+ return `
416
+ ${(await Promise.all(
417
+ localModelTypes.map(async (modelType) => {
418
+ const contractType = await dataContractTmpl({
419
+ ...params,
420
+ contract: modelType,
421
+ addExportKeyword: true
422
+ });
423
+ return contractType;
424
+ })
425
+ )).filter(Boolean).join("\n\n")}
426
+
427
+ ${endpointJSDocTmpl({
428
+ ...params,
429
+ route
430
+ })}
431
+ export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
432
+ `;
433
+ }
434
+ )
435
+ );
436
+ if (metaInfo) {
437
+ extraImportLines.push(
438
+ `import { ${[groupName && "Group", metaInfo?.namespace && "namespace", "Tag"].filter(Boolean).join(",")} } from "${groupName ? "../" : "./"}meta-info";`
439
+ );
440
+ }
441
+ return {
442
+ reservedDataContractNames: dataContractNamesInThisFile,
443
+ content: await formatTSContent(`${LINTERS_IGNORE}
444
+ import {
445
+ RequestParams,
446
+ HttpResponse,
447
+ HttpMultistatusResponse,
448
+ } from "${codegenParams.libImports?.["mobx-tanstack-query-api"] ?? "mobx-tanstack-query-api"}";
449
+ import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
450
+ import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
451
+ import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
452
+ ${extraImportLines.join("\n")}
453
+
454
+ ${configuration.modelTypes.length > 0 ? `
455
+ import { ${configuration.modelTypes.map((it) => it.name).filter(
456
+ (it) => !dataContractNamesInThisFile.includes(it)
457
+ )} } from "${relativePathDataContracts}";
458
+ ` : ""}
459
+
460
+ ${(await Promise.all(
461
+ dataContractNamesInThisFile.map(async (dataContractName) => {
462
+ const modelType = configuration.modelTypes.find(
463
+ (modelType2) => modelType2.name === dataContractName
464
+ );
465
+ if (!modelType) {
466
+ return "";
467
+ }
468
+ const contractType = await dataContractTmpl({
469
+ ...params,
470
+ contract: modelType,
471
+ addExportKeyword: true
472
+ });
473
+ return contractType;
474
+ })
475
+ )).filter(Boolean).join("\n\n")}
476
+
477
+ ${endpointTemplates.filter(Boolean).join("\n\n")}
478
+ `)
479
+ };
480
+ };
481
+ const allExportsTmpl = async ({
482
+ collectedExportFiles,
483
+ metaInfo,
484
+ formatTSContent
485
+ }) => {
486
+ return await formatTSContent(`${LINTERS_IGNORE}
487
+ export * from './data-contracts';
488
+ ${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join("\n")}
489
+ ${metaInfo ? 'export * from "./meta-info";' : ""}
490
+ `);
491
+ };
492
+ const dataContractsFileTmpl = async (params) => {
493
+ const { config, modelTypes } = params.configuration;
494
+ const contractDefinitions = [];
495
+ if (config.internalTemplateOptions?.addUtilRequiredKeysType) {
496
+ contractDefinitions.push(
497
+ `type UtilRequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>`
498
+ );
499
+ }
500
+ for await (const contract of modelTypes) {
501
+ if (params.excludedDataContractNames?.includes(contract.name)) {
502
+ continue;
503
+ }
504
+ contractDefinitions.push(
505
+ await dataContractTmpl({
506
+ ...params,
507
+ contract,
508
+ addExportKeyword: true
509
+ })
510
+ );
511
+ }
512
+ return await params.formatTSContent(`${LINTERS_IGNORE}
513
+
514
+ ${contractDefinitions.length > 0 ? contractDefinitions.join("\n\n") : `export {}`}
515
+ `);
516
+ };
517
+ const endpointPerFileTmpl = async (params) => {
518
+ const {
519
+ route,
520
+ configuration,
521
+ codegenParams,
522
+ formatTSContent,
523
+ importFileParams,
524
+ utils,
525
+ relativePathDataContracts,
526
+ groupName,
527
+ metaInfo
528
+ } = params;
529
+ const { _ } = utils;
530
+ const {
531
+ content: requestInfoInstanceContent,
532
+ reservedDataContractNames,
533
+ localModelTypes
534
+ } = newEndpointTmpl({
535
+ ...params,
536
+ route,
537
+ groupName,
538
+ metaInfo
539
+ });
540
+ const dataContactNames = new Set(
541
+ Object.keys(
542
+ configuration.config.swaggerSchema?.components?.schemas
543
+ ).map((schemaName) => utils.formatModelName(schemaName))
544
+ );
545
+ const dataContractNamesInThisFile = [];
546
+ reservedDataContractNames.forEach((reservedDataContractName) => {
547
+ if (!dataContactNames.has(reservedDataContractName)) {
548
+ dataContractNamesInThisFile.push(reservedDataContractName);
549
+ }
550
+ });
551
+ const extraImportLines = [];
552
+ if (metaInfo) {
553
+ extraImportLines.push(
554
+ `import { ${[groupName && "Group", metaInfo?.namespace && "namespace", "Tag"].filter(Boolean).join(",")} } from "../${groupName ? "../" : ""}meta-info";`
555
+ );
556
+ }
557
+ const requestInfoMeta = codegenParams.getEndpointMeta?.(route, utils);
558
+ if (requestInfoMeta?.typeNameImportPath && requestInfoMeta.typeName) {
559
+ extraImportLines.push(
560
+ `import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`
561
+ );
562
+ }
563
+ return {
564
+ reservedDataContractNames: dataContractNamesInThisFile,
565
+ content: await formatTSContent(`${LINTERS_IGNORE}
566
+ import {
567
+ RequestParams,
568
+ HttpResponse,
569
+ HttpMultistatusResponse,
570
+ } from "${codegenParams.libImports?.["mobx-tanstack-query-api"] ?? "mobx-tanstack-query-api"}";
571
+ import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
572
+ import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
573
+ import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
574
+ ${extraImportLines.join("\n")}
575
+
576
+ ${configuration.modelTypes.length > 0 ? `
577
+ import { ${configuration.modelTypes.map((it) => it.name).filter(
578
+ (it) => !dataContractNamesInThisFile.includes(it)
579
+ )} } from "${relativePathDataContracts}";
580
+ ` : ""}
581
+
582
+ ${(await Promise.all(
583
+ dataContractNamesInThisFile.map(async (dataContractName) => {
584
+ const modelType = configuration.modelTypes.find(
585
+ (modelType2) => modelType2.name === dataContractName
586
+ );
587
+ if (!modelType) {
588
+ return "";
589
+ }
590
+ const contractType = await dataContractTmpl({
591
+ ...params,
592
+ contract: modelType,
593
+ addExportKeyword: true
594
+ });
595
+ return contractType;
596
+ })
597
+ )).filter(Boolean).join("\n\n")}
598
+
599
+ ${(await Promise.all(
600
+ localModelTypes.map(async (modelType) => {
601
+ const contractType = await dataContractTmpl({
602
+ ...params,
603
+ contract: modelType,
604
+ addExportKeyword: true
605
+ });
606
+ return contractType;
607
+ })
608
+ )).filter(Boolean).join("\n\n")}
609
+
610
+ ${endpointJSDocTmpl({
611
+ ...params,
612
+ route
613
+ })}
614
+ export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
615
+ `)
616
+ };
617
+ };
618
+ const indexTsForEndpointPerFileTmpl = async ({
619
+ generatedRequestFileNames
620
+ }) => {
621
+ return `${LINTERS_IGNORE}
622
+ ${generatedRequestFileNames.map((fileName) => `export * from './${fileName.replace(".ts", "")}';`).join("\n")}
623
+ `;
624
+ };
625
+ const unpackFilterOption = (option, argsToString, defaultReturnValue = true) => {
626
+ if (typeof option === "function") {
627
+ return option;
628
+ }
629
+ if (option == null) {
630
+ return () => defaultReturnValue;
631
+ }
632
+ const inputs = Array.isArray(option) ? option : [option];
633
+ return (...args) => inputs.some((input) => {
634
+ const str = argsToString(...args);
635
+ if (typeof input === "string") {
636
+ return input === str;
637
+ }
638
+ return input.test(str);
639
+ });
640
+ };
641
+ const removeUnusedTypesItteration = async ({
642
+ directory,
643
+ keepTypes
644
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
645
+ }) => {
646
+ const project = new Project();
647
+ project.addSourceFilesAtPaths([
648
+ path.join(directory, "**/*.ts"),
649
+ path.join(directory, "**/*.tsx")
650
+ ]);
651
+ const dataContractsSourceFile = project.getSourceFile(
652
+ (sourceFile) => sourceFile.getFilePath().includes(`${directory}/data-contracts.ts`)
653
+ );
654
+ if (!dataContractsSourceFile) return;
655
+ const exportedDeclarations = dataContractsSourceFile.getExportedDeclarations();
656
+ const candidateTypes = /* @__PURE__ */ new Map();
657
+ for (const [name, declarations] of exportedDeclarations) {
658
+ const validDeclarations = declarations.filter(
659
+ (decl) => decl.getKind() === SyntaxKind.InterfaceDeclaration || decl.getKind() === SyntaxKind.TypeAliasDeclaration || decl.getKind() === SyntaxKind.EnumDeclaration
660
+ );
661
+ if (validDeclarations.length > 0) {
662
+ candidateTypes.set(name, validDeclarations);
663
+ }
664
+ }
665
+ if (candidateTypes.size === 0) return;
666
+ const usedTypes = /* @__PURE__ */ new Set();
667
+ const externalFiles = project.getSourceFiles().filter((sf) => sf !== dataContractsSourceFile);
668
+ for (const file of externalFiles) {
669
+ const identifiers = file.getDescendantsOfKind(SyntaxKind.Identifier);
670
+ for (const identifier of identifiers) {
671
+ const name = identifier.getText();
672
+ if (candidateTypes.has(name)) {
673
+ usedTypes.add(name);
674
+ }
675
+ }
676
+ const memberAccessExpressions = file.getDescendantsOfKind(
677
+ SyntaxKind.PropertyAccessExpression
678
+ );
679
+ for (const expr of memberAccessExpressions) {
680
+ const expression = expr.getExpression();
681
+ if (Node.isIdentifier(expression)) {
682
+ const name = expression.getText();
683
+ if (candidateTypes.has(name)) {
684
+ usedTypes.add(name);
685
+ }
686
+ }
687
+ }
688
+ }
689
+ const dependencyGraph = /* @__PURE__ */ new Map();
690
+ for (const [name, declarations] of candidateTypes) {
691
+ const dependencies = /* @__PURE__ */ new Set();
692
+ for (const decl of declarations) {
693
+ const typeReferences = decl.getDescendantsOfKind(
694
+ SyntaxKind.TypeReference
695
+ );
696
+ for (const ref of typeReferences) {
697
+ const typeName = ref.getTypeName().getText();
698
+ if (candidateTypes.has(typeName)) {
699
+ dependencies.add(typeName);
700
+ }
701
+ }
702
+ if (decl.getKind() === SyntaxKind.EnumDeclaration) {
703
+ const initializers = decl.getDescendantsOfKind(SyntaxKind.Identifier);
704
+ for (const init of initializers) {
705
+ const text = init.getText();
706
+ if (candidateTypes.has(text)) {
707
+ dependencies.add(text);
708
+ }
709
+ }
710
+ }
711
+ }
712
+ dependencyGraph.set(name, dependencies);
713
+ }
714
+ const queue = Array.from(usedTypes);
715
+ const visited = new Set(usedTypes);
716
+ while (queue.length > 0) {
717
+ const current = queue.shift();
718
+ if (dependencyGraph.has(current)) {
719
+ for (const dep of dependencyGraph.get(current)) {
720
+ if (!visited.has(dep)) {
721
+ visited.add(dep);
722
+ usedTypes.add(dep);
723
+ queue.push(dep);
724
+ }
725
+ }
726
+ }
727
+ }
728
+ let removedCount = 0;
729
+ const isNeedToRemoveType = unpackFilterOption(
730
+ keepTypes,
731
+ (name) => name,
732
+ false
733
+ );
734
+ for (const [name, declarations] of candidateTypes) {
735
+ if (usedTypes.has(name)) continue;
736
+ for (const decl of declarations) {
737
+ if ("remove" in decl && isNeedToRemoveType(name)) {
738
+ decl.remove();
739
+ removedCount++;
740
+ }
741
+ }
742
+ }
743
+ if (removedCount > 0) {
744
+ await dataContractsSourceFile.save();
745
+ }
746
+ return removedCount;
747
+ };
748
+ const removeUnusedTypes = async (params) => {
749
+ while (true) {
750
+ const removedCount = await removeUnusedTypesItteration(params) ?? 0;
751
+ if (removedCount === 0) break;
752
+ }
753
+ };
754
+ const __filename = fileURLToPath(import.meta.url);
755
+ const __dirname = path.dirname(__filename);
756
+ const __execdirname = process.cwd();
757
+ const generateApi = async (params) => {
758
+ if (Array.isArray(params)) {
759
+ for await (const param of params) {
760
+ await generateApi(param);
761
+ }
762
+ return;
763
+ }
764
+ const tsconfigPath = params.tsconfigPath ? path.resolve(__execdirname, params.tsconfigPath) : path.resolve(__execdirname, "./tsconfig.json");
765
+ console.info("using tsconfig", tsconfigPath);
766
+ const importFileParams = {
767
+ queryClient: !params.queryClient || typeof params.queryClient === "string" ? {
768
+ exportName: "queryClient",
769
+ path: "mobx-tanstack-query-api/builtin"
770
+ } : params.queryClient,
771
+ endpoint: !params.endpoint || typeof params.endpoint === "string" ? {
772
+ exportName: "Endpoint",
773
+ path: "mobx-tanstack-query-api"
774
+ } : params.endpoint,
775
+ httpClient: !params.httpClient || typeof params.httpClient === "string" ? {
776
+ exportName: "http",
777
+ path: "mobx-tanstack-query-api/builtin"
778
+ } : params.httpClient
779
+ };
780
+ const paths = {
781
+ templates: path.resolve(__dirname, "templates"),
782
+ requestInfoClass: path.resolve(
783
+ __dirname,
784
+ "templates/request-info-class.ejs"
785
+ ),
786
+ httpClient: path.resolve(__dirname, "templates/http-client.ejs"),
787
+ createRequestInfoInstance: path.resolve(
788
+ __dirname,
789
+ "templates/create-request-info-instance.ejs"
790
+ ),
791
+ outputDir: path.resolve(process.cwd(), params.output)
792
+ };
793
+ const swaggerTypescriptApiCodegenBaseParams = {
794
+ httpClientType: "fetch",
795
+ cleanOutput: params.cleanOutput ?? true,
796
+ modular: true,
797
+ patch: true,
798
+ typeSuffix: "DC",
799
+ disableStrictSSL: false,
800
+ singleHttpClient: true,
801
+ extractRequestBody: true,
802
+ extractRequestParams: false,
803
+ extractResponseBody: true,
804
+ extractResponseError: true,
805
+ generateResponses: true,
806
+ generateClient: false,
807
+ addReadonly: true,
808
+ moduleNameFirstTag: true,
809
+ sortTypes: true,
810
+ templates: paths.templates.toString(),
811
+ primitiveTypeConstructs: (constructs) => {
812
+ return {
813
+ ...constructs,
814
+ object: () => `Record<string, any>`,
815
+ float: () => `number`,
816
+ ...params.otherCodegenParams?.primitiveTypeConstructs?.(constructs)
817
+ };
818
+ },
819
+ requestOptions: params.fetchSchemaRequestOptions,
820
+ ...params.otherCodegenParams
821
+ };
822
+ let codegenProcess;
823
+ if (!params.input) {
824
+ console.warn(
825
+ "[mobx-tanstack-query-api/codegen]",
826
+ "input is not specified",
827
+ "\nprocess will be skipped"
828
+ );
829
+ return;
830
+ }
831
+ const inputToCodegenInput = (input) => {
832
+ const inputData = {};
833
+ if (typeof input === "string") {
834
+ inputData.input = input;
835
+ inputData.url = input;
836
+ } else {
837
+ inputData.spec = input;
838
+ }
839
+ return inputData;
840
+ };
841
+ let mixinSwaggerSchema = null;
842
+ if (params.mixinInput) {
843
+ await generateApi$1({
844
+ ...swaggerTypescriptApiCodegenBaseParams,
845
+ ...inputToCodegenInput(params.mixinInput),
846
+ hooks: {
847
+ onInit: (configuration) => {
848
+ mixinSwaggerSchema = cloneDeep(configuration.swaggerSchema);
849
+ },
850
+ onPrepareConfig: (config) => {
851
+ config.routes.combined?.forEach((routeInfo) => {
852
+ routeInfo.routes.sort(
853
+ (routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage)
854
+ );
855
+ });
856
+ },
857
+ onFormatRouteName: (routeInfo, usageRouteName) => {
858
+ let formattedRouteName = usageRouteName;
859
+ if (params.addPathSegmentToRouteName === true || typeof params.addPathSegmentToRouteName === "number") {
860
+ const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === "number" ? params.addPathSegmentToRouteName : 0;
861
+ const pathSegments = routeInfo.route.split("/").filter(Boolean);
862
+ const { _: _2 } = codegenProcess.getRenderTemplateData().utils;
863
+ formattedRouteName = _2.camelCase(
864
+ `${pathSegments[pathSegmentForSuffix] || ""}_${formattedRouteName}`
865
+ );
866
+ }
867
+ const endpointName = formattedRouteName;
868
+ return params?.formatEndpointName?.(endpointName, routeInfo) ?? swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(
869
+ routeInfo,
870
+ endpointName
871
+ ) ?? endpointName;
872
+ }
873
+ }
874
+ });
875
+ }
876
+ const generated = await generateApi$1({
877
+ ...swaggerTypescriptApiCodegenBaseParams,
878
+ ...inputToCodegenInput(params.input),
879
+ hooks: {
880
+ onInit: (configuration, codeGenProcessFromInit) => {
881
+ codegenProcess = codeGenProcessFromInit;
882
+ const resultSwaggerSchema = configuration.swaggerSchema;
883
+ resultSwaggerSchema.components = resultSwaggerSchema.components || {};
884
+ resultSwaggerSchema.components.schemas = resultSwaggerSchema.components.schemas || {};
885
+ resultSwaggerSchema.paths = {
886
+ ...resultSwaggerSchema.paths,
887
+ ...mixinSwaggerSchema?.paths
888
+ };
889
+ resultSwaggerSchema.components.schemas = {
890
+ ...resultSwaggerSchema.components.schemas,
891
+ ...mixinSwaggerSchema?.components?.schemas
892
+ };
893
+ return swaggerTypescriptApiCodegenBaseParams?.hooks?.onInit?.(
894
+ configuration,
895
+ codeGenProcessFromInit
896
+ );
897
+ },
898
+ onPrepareConfig: (config) => {
899
+ config.routes.combined?.forEach((routeInfo) => {
900
+ routeInfo.routes.sort(
901
+ (routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage)
902
+ );
903
+ });
904
+ return swaggerTypescriptApiCodegenBaseParams?.hooks?.onPrepareConfig?.(
905
+ config
906
+ );
907
+ },
908
+ onFormatRouteName: (routeInfo, usageRouteName) => {
909
+ let formattedRouteName = usageRouteName;
910
+ if (params.addPathSegmentToRouteName === true || typeof params.addPathSegmentToRouteName === "number") {
911
+ const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === "number" ? params.addPathSegmentToRouteName : 0;
912
+ const pathSegments = routeInfo.route.split("/").filter(Boolean);
913
+ const { _: _2 } = codegenProcess.getRenderTemplateData().utils;
914
+ formattedRouteName = _2.camelCase(
915
+ `${pathSegments[pathSegmentForSuffix] || ""}_${formattedRouteName}`
916
+ );
917
+ }
918
+ const endpointName = formattedRouteName;
919
+ return params?.formatEndpointName?.(endpointName, routeInfo) ?? swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(
920
+ routeInfo,
921
+ endpointName
922
+ ) ?? endpointName;
923
+ }
924
+ }
925
+ });
926
+ const utils = codegenProcess.getRenderTemplateData().utils;
927
+ const { _ } = utils;
928
+ let namespace = null;
929
+ if (params.namespace) {
930
+ if (typeof params.namespace === "function") {
931
+ namespace = params.namespace(utils);
932
+ } else {
933
+ namespace = utils._.camelCase(params.namespace);
934
+ }
935
+ }
936
+ const codegenFs = codegenProcess.fileSystem;
937
+ codegenFs.cleanDir(params.output);
938
+ codegenFs.createDir(params.output);
939
+ const filterTypes = unpackFilterOption(
940
+ params.filterTypes,
941
+ (modelType) => modelType.name
942
+ );
943
+ generated.configuration.modelTypes = generated.configuration.modelTypes.filter(
944
+ (modelType) => filterTypes(modelType)
945
+ );
946
+ const allRoutes = Object.values(generated.configuration.routes).flat().flatMap(
947
+ (routeGroup) => "routes" in routeGroup ? routeGroup.routes : routeGroup
948
+ );
949
+ const filterEndpoint = unpackFilterOption(
950
+ params.filterEndpoints,
951
+ (route) => route.raw?.operationId || ""
952
+ );
953
+ const baseTmplParams = {
954
+ ...generated,
955
+ codegenParams: params,
956
+ configuration: generated.configuration,
957
+ formatTSContent: generated.formatTSContent,
958
+ codegenProcess,
959
+ importFileParams,
960
+ utils,
961
+ filterTypes
962
+ };
963
+ const reservedDataContractNamesMap = /* @__PURE__ */ new Map();
964
+ const collectedExportFilesFromIndexFile = [];
965
+ const groupsMap = /* @__PURE__ */ new Map();
966
+ const nonEmptyGroups = /* @__PURE__ */ new Set();
967
+ const tagsSet = /* @__PURE__ */ new Set();
968
+ if (params.groupBy == null) {
969
+ collectedExportFilesFromIndexFile.push("endpoints");
970
+ if (params.outputType === "one-endpoint-per-file") {
971
+ codegenFs.createDir(path.resolve(params.output, "endpoints"));
972
+ const fileNamesWithRequestInfo = [];
973
+ for await (const route of allRoutes) {
974
+ const {
975
+ content: requestInfoPerFileContent,
976
+ reservedDataContractNames
977
+ } = await endpointPerFileTmpl({
978
+ ...baseTmplParams,
979
+ route,
980
+ relativePathDataContracts: "../data-contracts",
981
+ groupName: null,
982
+ metaInfo: params.noMetaInfo ? null : {
983
+ groupNames: [],
984
+ namespace
985
+ }
986
+ });
987
+ if (Array.isArray(route.raw.tags)) {
988
+ route.raw.tags.forEach((tag) => {
989
+ tagsSet.add(tag);
990
+ });
991
+ }
992
+ reservedDataContractNames.forEach((name) => {
993
+ reservedDataContractNamesMap.set(
994
+ name,
995
+ (reservedDataContractNamesMap.get(name) ?? 0) + 1
996
+ );
997
+ });
998
+ if (!filterEndpoint(route)) {
999
+ continue;
1000
+ }
1001
+ const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
1002
+ fileNamesWithRequestInfo.push(fileName);
1003
+ codegenFs.createFile({
1004
+ path: path.resolve(params.output, "endpoints"),
1005
+ fileName,
1006
+ withPrefix: false,
1007
+ content: requestInfoPerFileContent
1008
+ });
1009
+ }
1010
+ codegenFs.createFile({
1011
+ path: path.resolve(params.output, "endpoints"),
1012
+ fileName: "index.ts",
1013
+ withPrefix: false,
1014
+ content: await indexTsForEndpointPerFileTmpl({
1015
+ generatedRequestFileNames: fileNamesWithRequestInfo
1016
+ })
1017
+ });
1018
+ } else {
1019
+ const { content: requestInfoPerFileContent, reservedDataContractNames } = await allEndpointPerFileTmpl({
1020
+ ...baseTmplParams,
1021
+ routes: allRoutes,
1022
+ relativePathDataContracts: "./data-contracts",
1023
+ groupName: null,
1024
+ metaInfo: params.noMetaInfo ? null : {
1025
+ namespace,
1026
+ groupNames: []
1027
+ }
1028
+ });
1029
+ reservedDataContractNames.forEach((name) => {
1030
+ reservedDataContractNamesMap.set(
1031
+ name,
1032
+ (reservedDataContractNamesMap.get(name) ?? 0) + 1
1033
+ );
1034
+ });
1035
+ const filteredRoutes = allRoutes.filter(filterEndpoint);
1036
+ const hasFilteredRoutes = filteredRoutes.length > 0;
1037
+ if (hasFilteredRoutes) {
1038
+ filteredRoutes.forEach((route) => {
1039
+ if (Array.isArray(route.raw.tags)) {
1040
+ route.raw.tags.forEach((tag) => {
1041
+ tagsSet.add(tag);
1042
+ });
1043
+ }
1044
+ });
1045
+ const fileName = "endpoints.ts";
1046
+ collectedExportFilesFromIndexFile.push("endpoints");
1047
+ codegenFs.createFile({
1048
+ path: params.output,
1049
+ fileName,
1050
+ withPrefix: false,
1051
+ content: requestInfoPerFileContent
1052
+ });
1053
+ }
1054
+ }
1055
+ } else {
1056
+ allRoutes.forEach((route) => {
1057
+ let group;
1058
+ if (typeof params.groupBy === "function") {
1059
+ group = params.groupBy(route);
1060
+ } else if (params.groupBy?.includes("path-segment")) {
1061
+ const segmentIndex = +params.groupBy.replaceAll(/path-segment-?/g, "") || 0;
1062
+ group = route.request.path?.split("/")?.filter(Boolean)?.[segmentIndex] || void 0;
1063
+ } else if (params.groupBy?.includes("tag")) {
1064
+ const tagIndex = +params.groupBy.replaceAll(/tag-?/g, "") || 0;
1065
+ group = route.raw?.tags?.[tagIndex] ?? void 0;
1066
+ }
1067
+ if (group == null) {
1068
+ group = "other";
1069
+ }
1070
+ if (!groupsMap.has(group)) {
1071
+ groupsMap.set(group, []);
1072
+ }
1073
+ groupsMap.get(group)?.push(route);
1074
+ });
1075
+ const filterGroups = unpackFilterOption(
1076
+ params.filterGroups,
1077
+ (groupName) => groupName
1078
+ );
1079
+ for await (const [groupName, routes] of groupsMap) {
1080
+ if (!filterGroups(groupName)) {
1081
+ continue;
1082
+ }
1083
+ const fileNamesWithRequestInfo = [];
1084
+ const groupDirectory = path.resolve(
1085
+ params.output,
1086
+ _.kebabCase(groupName)
1087
+ );
1088
+ codegenFs.createDir(groupDirectory);
1089
+ let hasFilteredRoutes = false;
1090
+ if (params.outputType === "one-endpoint-per-file") {
1091
+ codegenFs.createDir(path.resolve(groupDirectory, "endpoints"));
1092
+ for await (const route of routes) {
1093
+ const {
1094
+ content: requestInfoPerFileContent,
1095
+ reservedDataContractNames
1096
+ } = await endpointPerFileTmpl({
1097
+ ...baseTmplParams,
1098
+ route,
1099
+ relativePathDataContracts: "../../data-contracts",
1100
+ groupName,
1101
+ metaInfo: params.noMetaInfo ? null : {
1102
+ namespace,
1103
+ groupNames: []
1104
+ }
1105
+ });
1106
+ reservedDataContractNames.forEach((name) => {
1107
+ reservedDataContractNamesMap.set(
1108
+ name,
1109
+ (reservedDataContractNamesMap.get(name) ?? 0) + 1
1110
+ );
1111
+ });
1112
+ if (!filterEndpoint(route)) {
1113
+ continue;
1114
+ }
1115
+ hasFilteredRoutes = true;
1116
+ if (Array.isArray(route.raw.tags)) {
1117
+ route.raw.tags.forEach((tag) => {
1118
+ tagsSet.add(tag);
1119
+ });
1120
+ }
1121
+ const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
1122
+ fileNamesWithRequestInfo.push(fileName);
1123
+ codegenFs.createFile({
1124
+ path: path.resolve(
1125
+ params.output,
1126
+ _.kebabCase(groupName),
1127
+ "endpoints"
1128
+ ),
1129
+ fileName,
1130
+ withPrefix: false,
1131
+ content: requestInfoPerFileContent
1132
+ });
1133
+ }
1134
+ } else {
1135
+ const {
1136
+ content: requestInfoPerFileContent,
1137
+ reservedDataContractNames
1138
+ } = await allEndpointPerFileTmpl({
1139
+ ...baseTmplParams,
1140
+ routes,
1141
+ relativePathDataContracts: "../data-contracts",
1142
+ groupName,
1143
+ metaInfo: params.noMetaInfo ? null : {
1144
+ namespace,
1145
+ groupNames: []
1146
+ }
1147
+ });
1148
+ reservedDataContractNames.forEach((name) => {
1149
+ reservedDataContractNamesMap.set(
1150
+ name,
1151
+ (reservedDataContractNamesMap.get(name) ?? 0) + 1
1152
+ );
1153
+ });
1154
+ const filteredRoutes = routes.filter(filterEndpoint);
1155
+ hasFilteredRoutes = filteredRoutes.length > 0;
1156
+ if (hasFilteredRoutes) {
1157
+ filteredRoutes.forEach((route) => {
1158
+ if (Array.isArray(route.raw.tags)) {
1159
+ route.raw.tags.forEach((tag) => {
1160
+ tagsSet.add(tag);
1161
+ });
1162
+ }
1163
+ });
1164
+ const fileName = "endpoints.ts";
1165
+ fileNamesWithRequestInfo.push(fileName);
1166
+ codegenFs.createFile({
1167
+ path: groupDirectory,
1168
+ fileName,
1169
+ withPrefix: false,
1170
+ content: requestInfoPerFileContent
1171
+ });
1172
+ }
1173
+ }
1174
+ if (hasFilteredRoutes) {
1175
+ nonEmptyGroups.add(groupName);
1176
+ const exportGroupName = params.formatExportGroupName ? params.formatExportGroupName(_.camelCase(groupName), utils) : _.camelCase(groupName);
1177
+ codegenFs.createFile({
1178
+ path: groupDirectory,
1179
+ fileName: "index.ts",
1180
+ withPrefix: false,
1181
+ content: `${LINTERS_IGNORE}
1182
+ export * as ${exportGroupName} from './endpoints';
1183
+ `
1184
+ });
1185
+ if (params.outputType === "one-endpoint-per-file") {
1186
+ codegenFs.createFile({
1187
+ path: path.resolve(groupDirectory, "endpoints"),
1188
+ fileName: "index.ts",
1189
+ withPrefix: false,
1190
+ content: await indexTsForEndpointPerFileTmpl({
1191
+ generatedRequestFileNames: fileNamesWithRequestInfo
1192
+ })
1193
+ });
1194
+ }
1195
+ collectedExportFilesFromIndexFile.push(_.kebabCase(groupName));
1196
+ } else {
1197
+ codegenFs.removeDir(
1198
+ path.resolve(params.output, _.kebabCase(groupName))
1199
+ );
1200
+ }
1201
+ }
1202
+ }
1203
+ const metaInfo = !params.noMetaInfo && (namespace ?? (nonEmptyGroups.size > 0 || tagsSet.size > 0)) ? {
1204
+ namespace,
1205
+ groupNames: [...nonEmptyGroups.values()],
1206
+ tags: [...tagsSet.values()]
1207
+ } : null;
1208
+ const excludedDataContractNames = Array.from(
1209
+ reservedDataContractNamesMap.entries()
1210
+ ).filter(([_2, count]) => count === 1).map(([name]) => name);
1211
+ const dataContractsContent = await dataContractsFileTmpl({
1212
+ ...baseTmplParams,
1213
+ excludedDataContractNames
1214
+ });
1215
+ codegenFs.createFile({
1216
+ path: paths.outputDir,
1217
+ fileName: "data-contracts.ts",
1218
+ withPrefix: false,
1219
+ content: dataContractsContent
1220
+ });
1221
+ if (metaInfo) {
1222
+ codegenFs.createFile({
1223
+ path: paths.outputDir,
1224
+ fileName: "meta-info.ts",
1225
+ withPrefix: false,
1226
+ content: await metaInfoTmpl({
1227
+ ...baseTmplParams,
1228
+ metaInfo
1229
+ })
1230
+ });
1231
+ }
1232
+ if (namespace) {
1233
+ codegenFs.createFile({
1234
+ path: paths.outputDir,
1235
+ fileName: "__exports.ts",
1236
+ withPrefix: false,
1237
+ content: await allExportsTmpl({
1238
+ ...baseTmplParams,
1239
+ collectedExportFiles: collectedExportFilesFromIndexFile,
1240
+ metaInfo
1241
+ })
1242
+ });
1243
+ codegenFs.createFile({
1244
+ path: paths.outputDir,
1245
+ fileName: "index.ts",
1246
+ withPrefix: false,
1247
+ content: `${LINTERS_IGNORE}
1248
+ export * as ${namespace} from './__exports';
1249
+ `
1250
+ });
1251
+ } else {
1252
+ codegenFs.createFile({
1253
+ path: paths.outputDir,
1254
+ fileName: "index.ts",
1255
+ withPrefix: false,
1256
+ content: await allExportsTmpl({
1257
+ ...baseTmplParams,
1258
+ collectedExportFiles: collectedExportFilesFromIndexFile,
1259
+ metaInfo
1260
+ })
1261
+ });
1262
+ }
1263
+ if (params.removeUnusedTypes) {
1264
+ removeUnusedTypes({
1265
+ directory: params.output,
1266
+ keepTypes: params.removeUnusedTypes === true ? void 0 : params.removeUnusedTypes.keepTypes
1267
+ });
1268
+ }
1269
+ };
1270
+ const defineConfig = (...configs) => {
1271
+ return configs.flat().filter((config) => !!config);
1272
+ };
1273
+ export {
1274
+ defineConfig,
1275
+ generateApi
1276
+ };
1277
+ //# sourceMappingURL=cli.js.map