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