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