mobx-tanstack-query-api 0.36.0 → 0.37.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.
- package/cli.cjs +277 -110
- package/cli.cjs.map +1 -1
- package/cli.js +277 -110
- package/cli.js.map +1 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -53,38 +53,72 @@ ${contract2.content}}`;
|
|
|
53
53
|
const contractType = `${"export "}${templateFn(contract)}`;
|
|
54
54
|
return result + contractType;
|
|
55
55
|
};
|
|
56
|
+
function getResponseContentTypes(raw) {
|
|
57
|
+
const out = [];
|
|
58
|
+
if (Array.isArray(raw.produces)) out.push(...raw.produces);
|
|
59
|
+
const status = raw.responses && Object.keys(raw.responses).find((s) => {
|
|
60
|
+
const code = Number.parseInt(s, 10);
|
|
61
|
+
return code >= 200 && code < 300;
|
|
62
|
+
});
|
|
63
|
+
const content = status && raw.responses[status]?.content;
|
|
64
|
+
if (content && typeof content === "object") out.push(...Object.keys(content));
|
|
65
|
+
return [...new Set(out)];
|
|
66
|
+
}
|
|
67
|
+
function getRequestContentTypes(raw) {
|
|
68
|
+
const out = [];
|
|
69
|
+
if (Array.isArray(raw.consumes)) out.push(...raw.consumes);
|
|
70
|
+
const body = raw.requestBody?.content;
|
|
71
|
+
if (body && typeof body === "object") out.push(...Object.keys(body));
|
|
72
|
+
return [...new Set(out)];
|
|
73
|
+
}
|
|
74
|
+
function getSecuritySchemeNames(security) {
|
|
75
|
+
if (!Array.isArray(security)) return [];
|
|
76
|
+
return security.flatMap(
|
|
77
|
+
(s) => typeof s === "object" && s !== null ? Object.keys(s) : []
|
|
78
|
+
).filter(Boolean);
|
|
79
|
+
}
|
|
80
|
+
function getExternalDocsLine(externalDocs, formatDescription) {
|
|
81
|
+
if (!externalDocs || typeof externalDocs !== "object" || !("url" in externalDocs))
|
|
82
|
+
return null;
|
|
83
|
+
const url = externalDocs.url;
|
|
84
|
+
if (!url) return null;
|
|
85
|
+
const desc = externalDocs.description;
|
|
86
|
+
const extDesc = desc ? ` ${formatDescription(String(desc).slice(0, 60), true)}` : "";
|
|
87
|
+
return { name: "see", content: `${url}${extDesc}`.trim() };
|
|
88
|
+
}
|
|
89
|
+
function getSummaryAndDescriptionLines(rawRoute, formatDescription) {
|
|
90
|
+
const out = [];
|
|
91
|
+
if (rawRoute.summary) {
|
|
92
|
+
const summaryLines = splitTextByLines(rawRoute.summary, 60).filter(Boolean).map((line) => ({ content: `**${formatDescription(line, true)}**` }));
|
|
93
|
+
if (summaryLines.length > 0) out.push(...summaryLines, { content: "" });
|
|
94
|
+
}
|
|
95
|
+
if (rawRoute.description) {
|
|
96
|
+
const descriptionLines = splitTextByLines(rawRoute.description, 60).filter(Boolean).map((line) => ({ content: formatDescription(line, true) }));
|
|
97
|
+
if (descriptionLines.length > 0)
|
|
98
|
+
out.push(...descriptionLines, { content: "" });
|
|
99
|
+
} else if (!rawRoute.summary) {
|
|
100
|
+
out.push({ content: "No description" });
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
56
104
|
const endpointJSDocTmpl = (params) => {
|
|
57
105
|
const { route, configuration, offset = 0 } = params;
|
|
58
106
|
const { routeName } = route;
|
|
59
107
|
const rawRoute = route.raw;
|
|
60
108
|
const routeRequest = route.request;
|
|
109
|
+
const path2 = routeRequest?.path;
|
|
110
|
+
const method = routeRequest?.method;
|
|
61
111
|
const { utils } = configuration;
|
|
62
112
|
const { _, formatDescription } = utils;
|
|
113
|
+
const schema = configuration.config?.swaggerSchema ?? configuration.swaggerSchema;
|
|
114
|
+
const pathKey = path2?.startsWith("/") ? path2 : `/${path2 || ""}`;
|
|
115
|
+
const methodKey = method?.toLowerCase?.() ?? method;
|
|
116
|
+
const schemaOp = pathKey && methodKey ? schema?.paths?.[pathKey]?.[methodKey] : null;
|
|
117
|
+
const rawWithSpec = schemaOp && typeof schemaOp === "object" ? { ...schemaOp, ...rawRoute } : rawRoute;
|
|
63
118
|
const jsDocLines = [];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
if (summaryLines.length > 0) {
|
|
69
|
-
jsDocLines.push(...summaryLines, { content: "" });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (rawRoute.description) {
|
|
73
|
-
const descriptionLines = splitTextByLines(rawRoute.description, 60).filter(Boolean).map((line) => ({
|
|
74
|
-
content: formatDescription(line, true)
|
|
75
|
-
}));
|
|
76
|
-
if (descriptionLines.length > 0) {
|
|
77
|
-
jsDocLines.push(...descriptionLines, { content: "" });
|
|
78
|
-
} else {
|
|
79
|
-
jsDocLines.push({
|
|
80
|
-
content: "No description"
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
jsDocLines.push({
|
|
85
|
-
content: "No description"
|
|
86
|
-
});
|
|
87
|
-
}
|
|
119
|
+
jsDocLines.push(
|
|
120
|
+
...getSummaryAndDescriptionLines(rawRoute, formatDescription)
|
|
121
|
+
);
|
|
88
122
|
if (rawRoute.operationId) {
|
|
89
123
|
jsDocLines.push({
|
|
90
124
|
name: "operationId",
|
|
@@ -101,6 +135,20 @@ const endpointJSDocTmpl = (params) => {
|
|
|
101
135
|
name: "request",
|
|
102
136
|
content: `**${_.upperCase(routeRequest.method)}:${rawRoute.route}**`
|
|
103
137
|
});
|
|
138
|
+
const responseTypes = getResponseContentTypes(rawWithSpec);
|
|
139
|
+
if (responseTypes.length > 0) {
|
|
140
|
+
jsDocLines.push({
|
|
141
|
+
name: "produces",
|
|
142
|
+
content: responseTypes.join(", ")
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const requestTypes = getRequestContentTypes(rawWithSpec);
|
|
146
|
+
if (requestTypes.length > 0) {
|
|
147
|
+
jsDocLines.push({
|
|
148
|
+
name: "consumes",
|
|
149
|
+
content: requestTypes.join(", ")
|
|
150
|
+
});
|
|
151
|
+
}
|
|
104
152
|
if (rawRoute.deprecated) {
|
|
105
153
|
jsDocLines.push({
|
|
106
154
|
name: "deprecated"
|
|
@@ -118,10 +166,17 @@ const endpointJSDocTmpl = (params) => {
|
|
|
118
166
|
);
|
|
119
167
|
}
|
|
120
168
|
if (routeRequest.security) {
|
|
121
|
-
jsDocLines.push({
|
|
122
|
-
|
|
123
|
-
|
|
169
|
+
jsDocLines.push({ name: "secure" });
|
|
170
|
+
const schemeNames = getSecuritySchemeNames(rawWithSpec.security);
|
|
171
|
+
if (schemeNames.length > 0) {
|
|
172
|
+
jsDocLines.push({ name: "security", content: schemeNames.join(", ") });
|
|
173
|
+
}
|
|
124
174
|
}
|
|
175
|
+
const externalDocsLine = getExternalDocsLine(
|
|
176
|
+
rawWithSpec.externalDocs,
|
|
177
|
+
formatDescription
|
|
178
|
+
);
|
|
179
|
+
if (externalDocsLine) jsDocLines.push(externalDocsLine);
|
|
125
180
|
if (rawRoute.responsesTypes.length > 0) {
|
|
126
181
|
jsDocLines.push({
|
|
127
182
|
name: "responses"
|
|
@@ -216,6 +271,94 @@ const responseContentKind = {
|
|
|
216
271
|
FORM_DATA: '"formData"',
|
|
217
272
|
BYTES: '"bytes"'
|
|
218
273
|
};
|
|
274
|
+
function inferResponseFormatFromRaw(raw) {
|
|
275
|
+
const contentTypes = [];
|
|
276
|
+
if (Array.isArray(raw.produces)) {
|
|
277
|
+
contentTypes.push(...raw.produces);
|
|
278
|
+
}
|
|
279
|
+
const successStatus = raw.responses && Object.keys(raw.responses).find((s) => {
|
|
280
|
+
const code = Number.parseInt(s, 10);
|
|
281
|
+
return code >= 200 && code < 300;
|
|
282
|
+
});
|
|
283
|
+
const content = successStatus && raw.responses[successStatus]?.content;
|
|
284
|
+
if (content && typeof content === "object") {
|
|
285
|
+
contentTypes.push(...Object.keys(content));
|
|
286
|
+
}
|
|
287
|
+
if (contentTypes.length === 0) return null;
|
|
288
|
+
const mimeToFormat = (mime) => {
|
|
289
|
+
if (mime.includes("application/json") || mime.includes("+json"))
|
|
290
|
+
return '"json"';
|
|
291
|
+
if (mime.startsWith("text/")) return '"text"';
|
|
292
|
+
if (mime.includes("form-data") || mime.includes("multipart"))
|
|
293
|
+
return '"formData"';
|
|
294
|
+
if (mime.includes("octet-stream") || mime.includes("spreadsheet") || mime.includes("vnd.") || mime.startsWith("application/") || mime.startsWith("image/") || mime.startsWith("audio/") || mime.startsWith("video/") || mime.startsWith("font/") || mime.startsWith("model/") || mime.startsWith("message/") || mime.startsWith("haptics/"))
|
|
295
|
+
return '"blob"';
|
|
296
|
+
return null;
|
|
297
|
+
};
|
|
298
|
+
const preferredOrder = ['"json"', '"text"', '"formData"', '"blob"'];
|
|
299
|
+
for (const fmt of preferredOrder) {
|
|
300
|
+
const found = contentTypes.map(mimeToFormat).find((f) => f === fmt);
|
|
301
|
+
if (found) return found;
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
function getResponseFormat(responseBodyInfo, raw, configuration, path2, method) {
|
|
306
|
+
const fromContentKind = responseContentKind[responseBodyInfo.success?.schema?.contentKind];
|
|
307
|
+
if (fromContentKind) return fromContentKind;
|
|
308
|
+
const swaggerSchema = configuration.config?.swaggerSchema ?? configuration.swaggerSchema;
|
|
309
|
+
const schemaPaths = swaggerSchema?.paths;
|
|
310
|
+
const pathKey = path2?.startsWith("/") ? path2 : `/${path2 || ""}`;
|
|
311
|
+
const methodKey = method?.toLowerCase?.() ?? method;
|
|
312
|
+
const schemaOperation = pathKey && methodKey ? schemaPaths?.[pathKey]?.[methodKey] : null;
|
|
313
|
+
const rawWithProduces = schemaOperation && typeof schemaOperation === "object" ? { ...schemaOperation, ...raw } : raw;
|
|
314
|
+
return inferResponseFormatFromRaw(rawWithProduces);
|
|
315
|
+
}
|
|
316
|
+
function inferRequestBodyContentTypeFromRaw(raw) {
|
|
317
|
+
const contentTypes = [];
|
|
318
|
+
if (Array.isArray(raw.consumes)) {
|
|
319
|
+
contentTypes.push(...raw.consumes);
|
|
320
|
+
}
|
|
321
|
+
const requestBody = raw.requestBody;
|
|
322
|
+
if (requestBody?.content && typeof requestBody.content === "object") {
|
|
323
|
+
contentTypes.push(...Object.keys(requestBody.content));
|
|
324
|
+
}
|
|
325
|
+
if (contentTypes.length === 0) return null;
|
|
326
|
+
const mimeToContentType = (mime) => {
|
|
327
|
+
if (mime.includes("application/json") || mime.includes("+json"))
|
|
328
|
+
return '"application/json"';
|
|
329
|
+
if (mime.includes("application/x-www-form-urlencoded"))
|
|
330
|
+
return '"application/x-www-form-urlencoded"';
|
|
331
|
+
if (mime.includes("multipart/form-data") || mime.includes("multipart/"))
|
|
332
|
+
return '"multipart/form-data"';
|
|
333
|
+
if (mime.startsWith("text/")) return '"text/plain"';
|
|
334
|
+
if (mime.includes("octet-stream") || mime.startsWith("application/") || mime.startsWith("image/") || mime.startsWith("audio/") || mime.startsWith("video/") || mime.startsWith("font/") || mime.startsWith("model/") || mime.includes("vnd."))
|
|
335
|
+
return '"application/octet-stream"';
|
|
336
|
+
return null;
|
|
337
|
+
};
|
|
338
|
+
const preferredOrder = [
|
|
339
|
+
'"application/json"',
|
|
340
|
+
'"application/x-www-form-urlencoded"',
|
|
341
|
+
'"multipart/form-data"',
|
|
342
|
+
'"text/plain"',
|
|
343
|
+
'"application/octet-stream"'
|
|
344
|
+
];
|
|
345
|
+
for (const ct of preferredOrder) {
|
|
346
|
+
const found = contentTypes.map(mimeToContentType).find((c) => c === ct);
|
|
347
|
+
if (found) return found;
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
function getRequestBodyContentType(requestBodyInfo, raw, configuration, path2, method) {
|
|
352
|
+
const fromContentKind = requestContentKind[requestBodyInfo?.contentKind];
|
|
353
|
+
if (fromContentKind) return fromContentKind;
|
|
354
|
+
const swaggerSchema = configuration.config?.swaggerSchema ?? configuration.swaggerSchema;
|
|
355
|
+
const schemaPaths = swaggerSchema?.paths;
|
|
356
|
+
const pathKey = path2?.startsWith("/") ? path2 : `/${path2 || ""}`;
|
|
357
|
+
const methodKey = method?.toLowerCase?.() ?? method;
|
|
358
|
+
const schemaOperation = pathKey && methodKey ? schemaPaths?.[pathKey]?.[methodKey] : null;
|
|
359
|
+
const rawWithConsumes = schemaOperation && typeof schemaOperation === "object" ? { ...schemaOperation, ...raw } : raw;
|
|
360
|
+
return inferRequestBodyContentTypeFromRaw(rawWithConsumes);
|
|
361
|
+
}
|
|
219
362
|
const newEndpointTmpl = ({
|
|
220
363
|
route,
|
|
221
364
|
codegenParams,
|
|
@@ -282,8 +425,20 @@ const newEndpointTmpl = ({
|
|
|
282
425
|
const requestInfoMeta = codegenParams.getEndpointMeta?.(route, utils);
|
|
283
426
|
const requestMeta = codegenParams.getRequestMeta?.(route, utils);
|
|
284
427
|
const resultPath = (codegenParams.requestPathPrefix ?? "") + path2 + (codegenParams.requestPathSuffix ?? "");
|
|
285
|
-
const bodyContentType =
|
|
286
|
-
|
|
428
|
+
const bodyContentType = getRequestBodyContentType(
|
|
429
|
+
requestBodyInfo,
|
|
430
|
+
raw,
|
|
431
|
+
configuration,
|
|
432
|
+
path2,
|
|
433
|
+
method
|
|
434
|
+
) || null;
|
|
435
|
+
const responseFormat = getResponseFormat(
|
|
436
|
+
responseBodyInfo,
|
|
437
|
+
raw,
|
|
438
|
+
configuration,
|
|
439
|
+
path2,
|
|
440
|
+
method
|
|
441
|
+
) || null;
|
|
287
442
|
const reservedDataContractNames = _.uniq([
|
|
288
443
|
...requestOutputDataTypes,
|
|
289
444
|
requestOutputErrorType || "any",
|
|
@@ -382,17 +537,17 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
382
537
|
} = params;
|
|
383
538
|
const { _ } = utils;
|
|
384
539
|
const dataContractNamesInThisFile = [];
|
|
540
|
+
const dataContactNames = new Set(
|
|
541
|
+
Object.keys(
|
|
542
|
+
configuration.config.swaggerSchema?.components?.schemas
|
|
543
|
+
).map((schemaName) => utils.formatModelName(schemaName))
|
|
544
|
+
);
|
|
385
545
|
const newEndpointTemplates = routes.map((route) => {
|
|
386
546
|
const newEndpointTemplateData = newEndpointTmpl({
|
|
387
547
|
...params,
|
|
388
548
|
route
|
|
389
549
|
});
|
|
390
550
|
const { reservedDataContractNames } = newEndpointTemplateData;
|
|
391
|
-
const dataContactNames = new Set(
|
|
392
|
-
Object.keys(
|
|
393
|
-
configuration.config.swaggerSchema?.components?.schemas
|
|
394
|
-
).map((schemaName) => utils.formatModelName(schemaName))
|
|
395
|
-
);
|
|
396
551
|
reservedDataContractNames.forEach((reservedDataContractName) => {
|
|
397
552
|
if (!dataContactNames.has(reservedDataContractName)) {
|
|
398
553
|
dataContractNamesInThisFile.push(reservedDataContractName);
|
|
@@ -435,14 +590,14 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
435
590
|
}
|
|
436
591
|
)
|
|
437
592
|
);
|
|
593
|
+
const endpointTemplatesContent = endpointTemplates.filter(Boolean).join("\n\n");
|
|
438
594
|
if (metaInfo) {
|
|
439
595
|
extraImportLines.push(
|
|
440
596
|
`import { ${[groupName && "Group", metaInfo?.namespace && "namespace", "Tag"].filter(Boolean).join(",")} } from "${groupName ? "../" : "./"}meta-info";`
|
|
441
597
|
);
|
|
442
598
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
content: await formatTSContent(`${LINTERS_IGNORE}
|
|
599
|
+
const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
|
|
600
|
+
const contentWithImportToken = await formatTSContent(`${LINTERS_IGNORE}
|
|
446
601
|
import {
|
|
447
602
|
RequestParams,
|
|
448
603
|
HttpResponse,
|
|
@@ -452,32 +607,40 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
452
607
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
453
608
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
454
609
|
${extraImportLines.join("\n")}
|
|
455
|
-
|
|
456
|
-
${configuration.modelTypes.length > 0 ? `
|
|
457
|
-
import { ${configuration.modelTypes.map((it) => it.name).filter(
|
|
458
|
-
(it) => !dataContractNamesInThisFile.includes(it)
|
|
459
|
-
)} } from "${relativePathDataContracts}";
|
|
460
|
-
` : ""}
|
|
610
|
+
${dataContractImportToken}
|
|
461
611
|
|
|
462
612
|
${(await Promise.all(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
613
|
+
dataContractNamesInThisFile.map(async (dataContractName) => {
|
|
614
|
+
const modelType = configuration.modelTypes.find(
|
|
615
|
+
(modelType2) => modelType2.name === dataContractName
|
|
616
|
+
);
|
|
617
|
+
if (!modelType) {
|
|
618
|
+
return "";
|
|
619
|
+
}
|
|
620
|
+
const contractType = await dataContractTmpl({
|
|
621
|
+
...params,
|
|
622
|
+
contract: modelType,
|
|
623
|
+
addExportKeyword: true
|
|
624
|
+
});
|
|
625
|
+
return contractType;
|
|
626
|
+
})
|
|
627
|
+
)).filter(Boolean).join("\n\n")}
|
|
478
628
|
|
|
479
|
-
${
|
|
480
|
-
`)
|
|
629
|
+
${endpointTemplatesContent}
|
|
630
|
+
`);
|
|
631
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
632
|
+
const usedDataContractNames = configuration.modelTypes.map((modelType) => modelType.name).filter(
|
|
633
|
+
(modelTypeName) => !dataContractNamesInThisFile.includes(modelTypeName) && dataContactNames.has(modelTypeName) && new RegExp(`\\b${escapeRegExp(modelTypeName)}\\b`).test(
|
|
634
|
+
contentWithImportToken
|
|
635
|
+
)
|
|
636
|
+
);
|
|
637
|
+
const dataContractImportLine = usedDataContractNames.length > 0 ? `import { ${usedDataContractNames.join(", ")} } from "${relativePathDataContracts}";` : "";
|
|
638
|
+
return {
|
|
639
|
+
reservedDataContractNames: dataContractNamesInThisFile,
|
|
640
|
+
content: contentWithImportToken.replace(
|
|
641
|
+
dataContractImportToken,
|
|
642
|
+
dataContractImportLine
|
|
643
|
+
)
|
|
481
644
|
};
|
|
482
645
|
};
|
|
483
646
|
const allExportsTmpl = async ({
|
|
@@ -562,9 +725,8 @@ const endpointPerFileTmpl = async (params) => {
|
|
|
562
725
|
`import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`
|
|
563
726
|
);
|
|
564
727
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
content: await formatTSContent(`${LINTERS_IGNORE}
|
|
728
|
+
const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
|
|
729
|
+
const contentWithImportToken = await formatTSContent(`${LINTERS_IGNORE}
|
|
568
730
|
import {
|
|
569
731
|
RequestParams,
|
|
570
732
|
HttpResponse,
|
|
@@ -574,47 +736,55 @@ const endpointPerFileTmpl = async (params) => {
|
|
|
574
736
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
575
737
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
576
738
|
${extraImportLines.join("\n")}
|
|
577
|
-
|
|
578
|
-
${configuration.modelTypes.length > 0 ? `
|
|
579
|
-
import { ${configuration.modelTypes.map((it) => it.name).filter(
|
|
580
|
-
(it) => !dataContractNamesInThisFile.includes(it)
|
|
581
|
-
)} } from "${relativePathDataContracts}";
|
|
582
|
-
` : ""}
|
|
739
|
+
${dataContractImportToken}
|
|
583
740
|
|
|
584
741
|
${(await Promise.all(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
742
|
+
dataContractNamesInThisFile.map(async (dataContractName) => {
|
|
743
|
+
const modelType = configuration.modelTypes.find(
|
|
744
|
+
(modelType2) => modelType2.name === dataContractName
|
|
745
|
+
);
|
|
746
|
+
if (!modelType) {
|
|
747
|
+
return "";
|
|
748
|
+
}
|
|
749
|
+
const contractType = await dataContractTmpl({
|
|
750
|
+
...params,
|
|
751
|
+
contract: modelType,
|
|
752
|
+
addExportKeyword: true
|
|
753
|
+
});
|
|
754
|
+
return contractType;
|
|
755
|
+
})
|
|
756
|
+
)).filter(Boolean).join("\n\n")}
|
|
600
757
|
|
|
601
758
|
${(await Promise.all(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
759
|
+
localModelTypes.map(async (modelType) => {
|
|
760
|
+
const contractType = await dataContractTmpl({
|
|
761
|
+
...params,
|
|
762
|
+
contract: modelType,
|
|
763
|
+
addExportKeyword: true
|
|
764
|
+
});
|
|
765
|
+
return contractType;
|
|
766
|
+
})
|
|
767
|
+
)).filter(Boolean).join("\n\n")}
|
|
611
768
|
|
|
612
769
|
${endpointJSDocTmpl({
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
770
|
+
...params,
|
|
771
|
+
route
|
|
772
|
+
})}
|
|
616
773
|
export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
|
|
617
|
-
`)
|
|
774
|
+
`);
|
|
775
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
776
|
+
const usedDataContractNames = configuration.modelTypes.map((modelType) => modelType.name).filter(
|
|
777
|
+
(modelTypeName) => !dataContractNamesInThisFile.includes(modelTypeName) && dataContactNames.has(modelTypeName) && new RegExp(`\\b${escapeRegExp(modelTypeName)}\\b`).test(
|
|
778
|
+
contentWithImportToken
|
|
779
|
+
)
|
|
780
|
+
);
|
|
781
|
+
const dataContractImportLine = usedDataContractNames.length > 0 ? `import { ${usedDataContractNames.join(", ")} } from "${relativePathDataContracts}";` : "";
|
|
782
|
+
return {
|
|
783
|
+
reservedDataContractNames: dataContractNamesInThisFile,
|
|
784
|
+
content: contentWithImportToken.replace(
|
|
785
|
+
dataContractImportToken,
|
|
786
|
+
dataContractImportLine
|
|
787
|
+
)
|
|
618
788
|
};
|
|
619
789
|
};
|
|
620
790
|
const indexTsForEndpointPerFileTmpl = async ({
|
|
@@ -728,15 +898,11 @@ const removeUnusedTypesItteration = async ({
|
|
|
728
898
|
}
|
|
729
899
|
}
|
|
730
900
|
let removedCount = 0;
|
|
731
|
-
const
|
|
732
|
-
keepTypes,
|
|
733
|
-
(name) => name,
|
|
734
|
-
false
|
|
735
|
-
);
|
|
901
|
+
const isKeepType = unpackFilterOption(keepTypes, (name) => name, false);
|
|
736
902
|
for (const [name, declarations] of candidateTypes) {
|
|
737
903
|
if (usedTypes.has(name)) continue;
|
|
738
904
|
for (const decl of declarations) {
|
|
739
|
-
if ("remove" in decl &&
|
|
905
|
+
if ("remove" in decl && !isKeepType(name)) {
|
|
740
906
|
decl.remove();
|
|
741
907
|
removedCount++;
|
|
742
908
|
}
|
|
@@ -927,6 +1093,7 @@ const generateApi = async (params) => {
|
|
|
927
1093
|
});
|
|
928
1094
|
const utils = codegenProcess.getRenderTemplateData().utils;
|
|
929
1095
|
const { _ } = utils;
|
|
1096
|
+
const outputType = params.outputType ?? "one-endpoint-per-file";
|
|
930
1097
|
const shouldGenerateBarrelFiles = !params.noBarrelFiles;
|
|
931
1098
|
let namespace = null;
|
|
932
1099
|
if (params.namespace) {
|
|
@@ -937,8 +1104,8 @@ const generateApi = async (params) => {
|
|
|
937
1104
|
}
|
|
938
1105
|
}
|
|
939
1106
|
const codegenFs = codegenProcess.fileSystem;
|
|
940
|
-
codegenFs.cleanDir(
|
|
941
|
-
codegenFs.createDir(
|
|
1107
|
+
codegenFs.cleanDir(paths.outputDir);
|
|
1108
|
+
codegenFs.createDir(paths.outputDir);
|
|
942
1109
|
const filterTypes = unpackFilterOption(
|
|
943
1110
|
params.filterTypes,
|
|
944
1111
|
(modelType) => modelType.name
|
|
@@ -970,7 +1137,7 @@ const generateApi = async (params) => {
|
|
|
970
1137
|
const tagsSet = /* @__PURE__ */ new Set();
|
|
971
1138
|
if (params.groupBy == null) {
|
|
972
1139
|
collectedExportFilesFromIndexFile.push("endpoints");
|
|
973
|
-
if (
|
|
1140
|
+
if (outputType === "one-endpoint-per-file") {
|
|
974
1141
|
codegenFs.createDir(path.resolve(params.output, "endpoints"));
|
|
975
1142
|
const fileNamesWithRequestInfo = [];
|
|
976
1143
|
for await (const route of allRoutes) {
|
|
@@ -1050,7 +1217,7 @@ const generateApi = async (params) => {
|
|
|
1050
1217
|
const fileName = "endpoints.ts";
|
|
1051
1218
|
collectedExportFilesFromIndexFile.push("endpoints");
|
|
1052
1219
|
codegenFs.createFile({
|
|
1053
|
-
path:
|
|
1220
|
+
path: paths.outputDir,
|
|
1054
1221
|
fileName,
|
|
1055
1222
|
withPrefix: false,
|
|
1056
1223
|
content: requestInfoPerFileContent
|
|
@@ -1092,7 +1259,7 @@ const generateApi = async (params) => {
|
|
|
1092
1259
|
);
|
|
1093
1260
|
codegenFs.createDir(groupDirectory);
|
|
1094
1261
|
let hasFilteredRoutes = false;
|
|
1095
|
-
if (
|
|
1262
|
+
if (outputType === "one-endpoint-per-file") {
|
|
1096
1263
|
codegenFs.createDir(path.resolve(groupDirectory, "endpoints"));
|
|
1097
1264
|
for await (const route of routes) {
|
|
1098
1265
|
const {
|
|
@@ -1189,7 +1356,7 @@ export * as ${exportGroupName} from './endpoints';
|
|
|
1189
1356
|
`
|
|
1190
1357
|
});
|
|
1191
1358
|
}
|
|
1192
|
-
if (shouldGenerateBarrelFiles &&
|
|
1359
|
+
if (shouldGenerateBarrelFiles && outputType === "one-endpoint-per-file") {
|
|
1193
1360
|
codegenFs.createFile({
|
|
1194
1361
|
path: path.resolve(groupDirectory, "endpoints"),
|
|
1195
1362
|
fileName: "index.ts",
|
|
@@ -1273,7 +1440,7 @@ export * as ${namespace} from './__exports';
|
|
|
1273
1440
|
}
|
|
1274
1441
|
if (params.removeUnusedTypes) {
|
|
1275
1442
|
await removeUnusedTypes({
|
|
1276
|
-
directory:
|
|
1443
|
+
directory: paths.outputDir,
|
|
1277
1444
|
keepTypes: params.removeUnusedTypes === true ? void 0 : params.removeUnusedTypes.keepTypes
|
|
1278
1445
|
});
|
|
1279
1446
|
}
|