mobx-tanstack-query-api 0.36.0 → 0.36.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.
- package/cli.cjs +93 -81
- package/cli.cjs.map +1 -1
- package/cli.js +93 -81
- package/cli.js.map +1 -1
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -385,17 +385,17 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
385
385
|
} = params;
|
|
386
386
|
const { _ } = utils;
|
|
387
387
|
const dataContractNamesInThisFile = [];
|
|
388
|
+
const dataContactNames = new Set(
|
|
389
|
+
Object.keys(
|
|
390
|
+
configuration.config.swaggerSchema?.components?.schemas
|
|
391
|
+
).map((schemaName) => utils.formatModelName(schemaName))
|
|
392
|
+
);
|
|
388
393
|
const newEndpointTemplates = routes.map((route) => {
|
|
389
394
|
const newEndpointTemplateData = newEndpointTmpl({
|
|
390
395
|
...params,
|
|
391
396
|
route
|
|
392
397
|
});
|
|
393
398
|
const { reservedDataContractNames } = newEndpointTemplateData;
|
|
394
|
-
const dataContactNames = new Set(
|
|
395
|
-
Object.keys(
|
|
396
|
-
configuration.config.swaggerSchema?.components?.schemas
|
|
397
|
-
).map((schemaName) => utils.formatModelName(schemaName))
|
|
398
|
-
);
|
|
399
399
|
reservedDataContractNames.forEach((reservedDataContractName) => {
|
|
400
400
|
if (!dataContactNames.has(reservedDataContractName)) {
|
|
401
401
|
dataContractNamesInThisFile.push(reservedDataContractName);
|
|
@@ -438,14 +438,14 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
438
438
|
}
|
|
439
439
|
)
|
|
440
440
|
);
|
|
441
|
+
const endpointTemplatesContent = endpointTemplates.filter(Boolean).join("\n\n");
|
|
441
442
|
if (metaInfo) {
|
|
442
443
|
extraImportLines.push(
|
|
443
444
|
`import { ${[groupName && "Group", metaInfo?.namespace && "namespace", "Tag"].filter(Boolean).join(",")} } from "${groupName ? "../" : "./"}meta-info";`
|
|
444
445
|
);
|
|
445
446
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
content: await formatTSContent(`${LINTERS_IGNORE}
|
|
447
|
+
const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
|
|
448
|
+
const contentWithImportToken = await formatTSContent(`${LINTERS_IGNORE}
|
|
449
449
|
import {
|
|
450
450
|
RequestParams,
|
|
451
451
|
HttpResponse,
|
|
@@ -455,32 +455,40 @@ const allEndpointPerFileTmpl = async (params) => {
|
|
|
455
455
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
456
456
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
457
457
|
${extraImportLines.join("\n")}
|
|
458
|
-
|
|
459
|
-
${configuration.modelTypes.length > 0 ? `
|
|
460
|
-
import { ${configuration.modelTypes.map((it) => it.name).filter(
|
|
461
|
-
(it) => !dataContractNamesInThisFile.includes(it)
|
|
462
|
-
)} } from "${relativePathDataContracts}";
|
|
463
|
-
` : ""}
|
|
458
|
+
${dataContractImportToken}
|
|
464
459
|
|
|
465
460
|
${(await Promise.all(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
461
|
+
dataContractNamesInThisFile.map(async (dataContractName) => {
|
|
462
|
+
const modelType = configuration.modelTypes.find(
|
|
463
|
+
(modelType2) => modelType2.name === dataContractName
|
|
464
|
+
);
|
|
465
|
+
if (!modelType) {
|
|
466
|
+
return "";
|
|
467
|
+
}
|
|
468
|
+
const contractType = await dataContractTmpl({
|
|
469
|
+
...params,
|
|
470
|
+
contract: modelType,
|
|
471
|
+
addExportKeyword: true
|
|
472
|
+
});
|
|
473
|
+
return contractType;
|
|
474
|
+
})
|
|
475
|
+
)).filter(Boolean).join("\n\n")}
|
|
481
476
|
|
|
482
|
-
${
|
|
483
|
-
`)
|
|
477
|
+
${endpointTemplatesContent}
|
|
478
|
+
`);
|
|
479
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
480
|
+
const usedDataContractNames = configuration.modelTypes.map((modelType) => modelType.name).filter(
|
|
481
|
+
(modelTypeName) => !dataContractNamesInThisFile.includes(modelTypeName) && dataContactNames.has(modelTypeName) && new RegExp(`\\b${escapeRegExp(modelTypeName)}\\b`).test(
|
|
482
|
+
contentWithImportToken
|
|
483
|
+
)
|
|
484
|
+
);
|
|
485
|
+
const dataContractImportLine = usedDataContractNames.length > 0 ? `import { ${usedDataContractNames.join(", ")} } from "${relativePathDataContracts}";` : "";
|
|
486
|
+
return {
|
|
487
|
+
reservedDataContractNames: dataContractNamesInThisFile,
|
|
488
|
+
content: contentWithImportToken.replace(
|
|
489
|
+
dataContractImportToken,
|
|
490
|
+
dataContractImportLine
|
|
491
|
+
)
|
|
484
492
|
};
|
|
485
493
|
};
|
|
486
494
|
const allExportsTmpl = async ({
|
|
@@ -565,9 +573,8 @@ const endpointPerFileTmpl = async (params) => {
|
|
|
565
573
|
`import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`
|
|
566
574
|
);
|
|
567
575
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
content: await formatTSContent(`${LINTERS_IGNORE}
|
|
576
|
+
const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
|
|
577
|
+
const contentWithImportToken = await formatTSContent(`${LINTERS_IGNORE}
|
|
571
578
|
import {
|
|
572
579
|
RequestParams,
|
|
573
580
|
HttpResponse,
|
|
@@ -577,47 +584,55 @@ const endpointPerFileTmpl = async (params) => {
|
|
|
577
584
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
578
585
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
579
586
|
${extraImportLines.join("\n")}
|
|
580
|
-
|
|
581
|
-
${configuration.modelTypes.length > 0 ? `
|
|
582
|
-
import { ${configuration.modelTypes.map((it) => it.name).filter(
|
|
583
|
-
(it) => !dataContractNamesInThisFile.includes(it)
|
|
584
|
-
)} } from "${relativePathDataContracts}";
|
|
585
|
-
` : ""}
|
|
587
|
+
${dataContractImportToken}
|
|
586
588
|
|
|
587
589
|
${(await Promise.all(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
590
|
+
dataContractNamesInThisFile.map(async (dataContractName) => {
|
|
591
|
+
const modelType = configuration.modelTypes.find(
|
|
592
|
+
(modelType2) => modelType2.name === dataContractName
|
|
593
|
+
);
|
|
594
|
+
if (!modelType) {
|
|
595
|
+
return "";
|
|
596
|
+
}
|
|
597
|
+
const contractType = await dataContractTmpl({
|
|
598
|
+
...params,
|
|
599
|
+
contract: modelType,
|
|
600
|
+
addExportKeyword: true
|
|
601
|
+
});
|
|
602
|
+
return contractType;
|
|
603
|
+
})
|
|
604
|
+
)).filter(Boolean).join("\n\n")}
|
|
603
605
|
|
|
604
606
|
${(await Promise.all(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
607
|
+
localModelTypes.map(async (modelType) => {
|
|
608
|
+
const contractType = await dataContractTmpl({
|
|
609
|
+
...params,
|
|
610
|
+
contract: modelType,
|
|
611
|
+
addExportKeyword: true
|
|
612
|
+
});
|
|
613
|
+
return contractType;
|
|
614
|
+
})
|
|
615
|
+
)).filter(Boolean).join("\n\n")}
|
|
614
616
|
|
|
615
617
|
${endpointJSDocTmpl({
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
618
|
+
...params,
|
|
619
|
+
route
|
|
620
|
+
})}
|
|
619
621
|
export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
|
|
620
|
-
`)
|
|
622
|
+
`);
|
|
623
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
624
|
+
const usedDataContractNames = configuration.modelTypes.map((modelType) => modelType.name).filter(
|
|
625
|
+
(modelTypeName) => !dataContractNamesInThisFile.includes(modelTypeName) && dataContactNames.has(modelTypeName) && new RegExp(`\\b${escapeRegExp(modelTypeName)}\\b`).test(
|
|
626
|
+
contentWithImportToken
|
|
627
|
+
)
|
|
628
|
+
);
|
|
629
|
+
const dataContractImportLine = usedDataContractNames.length > 0 ? `import { ${usedDataContractNames.join(", ")} } from "${relativePathDataContracts}";` : "";
|
|
630
|
+
return {
|
|
631
|
+
reservedDataContractNames: dataContractNamesInThisFile,
|
|
632
|
+
content: contentWithImportToken.replace(
|
|
633
|
+
dataContractImportToken,
|
|
634
|
+
dataContractImportLine
|
|
635
|
+
)
|
|
621
636
|
};
|
|
622
637
|
};
|
|
623
638
|
const indexTsForEndpointPerFileTmpl = async ({
|
|
@@ -731,15 +746,11 @@ const removeUnusedTypesItteration = async ({
|
|
|
731
746
|
}
|
|
732
747
|
}
|
|
733
748
|
let removedCount = 0;
|
|
734
|
-
const
|
|
735
|
-
keepTypes,
|
|
736
|
-
(name) => name,
|
|
737
|
-
false
|
|
738
|
-
);
|
|
749
|
+
const isKeepType = unpackFilterOption(keepTypes, (name) => name, false);
|
|
739
750
|
for (const [name, declarations] of candidateTypes) {
|
|
740
751
|
if (usedTypes.has(name)) continue;
|
|
741
752
|
for (const decl of declarations) {
|
|
742
|
-
if ("remove" in decl &&
|
|
753
|
+
if ("remove" in decl && !isKeepType(name)) {
|
|
743
754
|
decl.remove();
|
|
744
755
|
removedCount++;
|
|
745
756
|
}
|
|
@@ -930,6 +941,7 @@ const generateApi = async (params) => {
|
|
|
930
941
|
});
|
|
931
942
|
const utils = codegenProcess.getRenderTemplateData().utils;
|
|
932
943
|
const { _ } = utils;
|
|
944
|
+
const outputType = params.outputType ?? "one-endpoint-per-file";
|
|
933
945
|
const shouldGenerateBarrelFiles = !params.noBarrelFiles;
|
|
934
946
|
let namespace = null;
|
|
935
947
|
if (params.namespace) {
|
|
@@ -940,8 +952,8 @@ const generateApi = async (params) => {
|
|
|
940
952
|
}
|
|
941
953
|
}
|
|
942
954
|
const codegenFs = codegenProcess.fileSystem;
|
|
943
|
-
codegenFs.cleanDir(
|
|
944
|
-
codegenFs.createDir(
|
|
955
|
+
codegenFs.cleanDir(paths.outputDir);
|
|
956
|
+
codegenFs.createDir(paths.outputDir);
|
|
945
957
|
const filterTypes = unpackFilterOption(
|
|
946
958
|
params.filterTypes,
|
|
947
959
|
(modelType) => modelType.name
|
|
@@ -973,7 +985,7 @@ const generateApi = async (params) => {
|
|
|
973
985
|
const tagsSet = /* @__PURE__ */ new Set();
|
|
974
986
|
if (params.groupBy == null) {
|
|
975
987
|
collectedExportFilesFromIndexFile.push("endpoints");
|
|
976
|
-
if (
|
|
988
|
+
if (outputType === "one-endpoint-per-file") {
|
|
977
989
|
codegenFs.createDir(path.resolve(params.output, "endpoints"));
|
|
978
990
|
const fileNamesWithRequestInfo = [];
|
|
979
991
|
for await (const route of allRoutes) {
|
|
@@ -1053,7 +1065,7 @@ const generateApi = async (params) => {
|
|
|
1053
1065
|
const fileName = "endpoints.ts";
|
|
1054
1066
|
collectedExportFilesFromIndexFile.push("endpoints");
|
|
1055
1067
|
codegenFs.createFile({
|
|
1056
|
-
path:
|
|
1068
|
+
path: paths.outputDir,
|
|
1057
1069
|
fileName,
|
|
1058
1070
|
withPrefix: false,
|
|
1059
1071
|
content: requestInfoPerFileContent
|
|
@@ -1095,7 +1107,7 @@ const generateApi = async (params) => {
|
|
|
1095
1107
|
);
|
|
1096
1108
|
codegenFs.createDir(groupDirectory);
|
|
1097
1109
|
let hasFilteredRoutes = false;
|
|
1098
|
-
if (
|
|
1110
|
+
if (outputType === "one-endpoint-per-file") {
|
|
1099
1111
|
codegenFs.createDir(path.resolve(groupDirectory, "endpoints"));
|
|
1100
1112
|
for await (const route of routes) {
|
|
1101
1113
|
const {
|
|
@@ -1192,7 +1204,7 @@ export * as ${exportGroupName} from './endpoints';
|
|
|
1192
1204
|
`
|
|
1193
1205
|
});
|
|
1194
1206
|
}
|
|
1195
|
-
if (shouldGenerateBarrelFiles &&
|
|
1207
|
+
if (shouldGenerateBarrelFiles && outputType === "one-endpoint-per-file") {
|
|
1196
1208
|
codegenFs.createFile({
|
|
1197
1209
|
path: path.resolve(groupDirectory, "endpoints"),
|
|
1198
1210
|
fileName: "index.ts",
|
|
@@ -1276,7 +1288,7 @@ export * as ${namespace} from './__exports';
|
|
|
1276
1288
|
}
|
|
1277
1289
|
if (params.removeUnusedTypes) {
|
|
1278
1290
|
await removeUnusedTypes({
|
|
1279
|
-
directory:
|
|
1291
|
+
directory: paths.outputDir,
|
|
1280
1292
|
keepTypes: params.removeUnusedTypes === true ? void 0 : params.removeUnusedTypes.keepTypes
|
|
1281
1293
|
});
|
|
1282
1294
|
}
|