@acrool/rtk-query-codegen-openapi 1.2.0-alpha.0 → 1.2.0-alpha.2

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/lib/index.mjs CHANGED
@@ -905,7 +905,7 @@ function getTypeFromParameter(param, schemaTypeMap = {}) {
905
905
  init_esm_shims();
906
906
  function generateRtkQueryFile(endpointInfos, options) {
907
907
  const { groupKey } = options;
908
- const httpClientTypeName = options.httpClient?.importReturnTypeName || options.httpClient?.importName || "IRestFulEndpointsQueryReturn";
908
+ const httpClientTypeName = options.httpClient?.importReturnTypeName || "IRestFulEndpointsQueryReturn";
909
909
  const endpoints = endpointInfos.map((info) => {
910
910
  const methodType = info.isQuery ? "query" : "mutation";
911
911
  const argType = info.isVoidArg ? "void" : `${httpClientTypeName}<${info.argTypeName}>`;
@@ -930,7 +930,7 @@ ${paramsLines}
930
930
  }
931
931
  let tagsSection = "";
932
932
  if (info.tags && info.tags.length > 0) {
933
- const tagsArray = info.tags.map((tag) => `"${tag}"`).join(", ");
933
+ const tagsArray = info.tags.map((tag) => `ECacheTagTypes.${tag}`).join(", ");
934
934
  if (info.isQuery) {
935
935
  tagsSection = `
936
936
  providesTags: [${tagsArray}],`;
@@ -966,10 +966,13 @@ ${paramsLines}
966
966
  const httpClientImport = options.httpClient ? `import {${options.httpClient.importReturnTypeName}} from "${options.httpClient.file}";
967
967
  ` : `import {IRestFulEndpointsQueryReturn} from "@acrool/react-fetcher";
968
968
  `;
969
+ const hasTags = endpointInfos.some((info) => info.tags && info.tags.length > 0);
970
+ const tagTypesImport = hasTags ? `import {ECacheTagTypes} from "../tagTypes";
971
+ ` : "";
969
972
  return `/* eslint-disable */
970
973
  // [Warning] Generated automatically - do not edit manually
971
974
 
972
- ${apiImport}${httpClientImport}
975
+ ${apiImport}${httpClientImport}${tagTypesImport}
973
976
  ${typeImportStatement}
974
977
 
975
978
 
@@ -1005,7 +1008,6 @@ export default injectedRtkApi;
1005
1008
  // src/generators/rtk-enhance-endpoints-generator.ts
1006
1009
  init_esm_shims();
1007
1010
  function generateRtkEnhanceEndpointsFile(endpointInfos, options) {
1008
- const { groupKey, cacheTagTypes } = options;
1009
1011
  const endpointConfigs = endpointInfos.map((info) => {
1010
1012
  if (info.isQuery) {
1011
1013
  return ` ${info.operationName}: {
@@ -1017,15 +1019,10 @@ function generateRtkEnhanceEndpointsFile(endpointInfos, options) {
1017
1019
  },`;
1018
1020
  }
1019
1021
  }).join("\n");
1020
- let importStatements = `/* eslint-disable */
1022
+ const importStatements = `/* eslint-disable */
1021
1023
  // [Warning] Generated automatically - do not edit manually
1022
1024
 
1023
- `;
1024
- if (cacheTagTypes) {
1025
- importStatements += `import { ${cacheTagTypes.importReturnTypeName} } from "${cacheTagTypes.file}";
1026
- `;
1027
- }
1028
- importStatements += `import api from "./query.generated";
1025
+ import api from "./query.generated";
1029
1026
  `;
1030
1027
  return `${importStatements}
1031
1028
  const enhancedApi = api.enhanceEndpoints({
@@ -1063,8 +1060,15 @@ var ApiCodeGenerator = class {
1063
1060
  const enhanceEndpointsContent = generateRtkEnhanceEndpointsFile(endpointInfos, this.options);
1064
1061
  const indexContent = this.generateIndex();
1065
1062
  const operationNames = endpointInfos.map((info) => info.operationName);
1063
+ const allTags = /* @__PURE__ */ new Set();
1064
+ endpointInfos.forEach((info) => {
1065
+ if (info.tags && Array.isArray(info.tags)) {
1066
+ info.tags.forEach((tag) => allTags.add(tag));
1067
+ }
1068
+ });
1066
1069
  return {
1067
1070
  operationNames,
1071
+ tags: Array.from(allTags),
1068
1072
  files: {
1069
1073
  types: typesContent,
1070
1074
  queryService: rtkQueryContent,
@@ -1148,6 +1152,27 @@ export function withoutUndefined(obj?: Record<string, any>) {
1148
1152
  `;
1149
1153
  }
1150
1154
 
1155
+ // src/generators/tag-types-generator.ts
1156
+ init_esm_shims();
1157
+ function generateTagTypesFile(tags) {
1158
+ if (tags.length === 0) {
1159
+ return `/* eslint-disable */
1160
+ // [Warning] Generated automatically - do not edit manually
1161
+
1162
+ export enum ECacheTagTypes {
1163
+ }
1164
+ `;
1165
+ }
1166
+ const enumEntries = tags.sort().map((tag) => ` ${tag} = '${tag}',`).join("\n");
1167
+ return `/* eslint-disable */
1168
+ // [Warning] Generated automatically - do not edit manually
1169
+
1170
+ export enum ECacheTagTypes {
1171
+ ${enumEntries}
1172
+ }
1173
+ `;
1174
+ }
1175
+
1151
1176
  // src/services/unified-code-generator.ts
1152
1177
  var UnifiedCodeGenerator = class {
1153
1178
  _options;
@@ -1165,8 +1190,11 @@ var UnifiedCodeGenerator = class {
1165
1190
  commonTypes: "",
1166
1191
  componentSchema: "",
1167
1192
  doNotModify: "",
1168
- utils: ""
1193
+ utils: "",
1194
+ tagTypes: ""
1169
1195
  };
1196
+ // 收集所有 tags
1197
+ allTags = /* @__PURE__ */ new Set();
1170
1198
  constructor(options) {
1171
1199
  this._options = options;
1172
1200
  }
@@ -1180,6 +1208,7 @@ var UnifiedCodeGenerator = class {
1180
1208
  this.generateSchemaContent();
1181
1209
  this.generateUtilsContent();
1182
1210
  this.generateDoNotModifyContent();
1211
+ this.generateTagTypesContent();
1183
1212
  return await this.release();
1184
1213
  }
1185
1214
  /**
@@ -1232,6 +1261,9 @@ var UnifiedCodeGenerator = class {
1232
1261
  outputPath: groupInfo.outputPath,
1233
1262
  content: groupContent
1234
1263
  });
1264
+ if (groupContent.tags && Array.isArray(groupContent.tags)) {
1265
+ groupContent.tags.forEach((tag) => this.allTags.add(tag));
1266
+ }
1235
1267
  }
1236
1268
  } catch (error) {
1237
1269
  throw new Error(`\u7FA4\u7D44 ${groupInfo.groupKey} \u751F\u6210\u5931\u6557: ${error}`);
@@ -1262,6 +1294,13 @@ var UnifiedCodeGenerator = class {
1262
1294
  async generateUtilsContent() {
1263
1295
  this.generatedContent.utils = generateUtilsFile();
1264
1296
  }
1297
+ /**
1298
+ * 生成 Tag Types
1299
+ */
1300
+ async generateTagTypesContent() {
1301
+ const tagsArray = Array.from(this.allTags);
1302
+ this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
1303
+ }
1265
1304
  /**
1266
1305
  * 發佈階段:統一寫入所有檔案
1267
1306
  */
@@ -1302,6 +1341,13 @@ var UnifiedCodeGenerator = class {
1302
1341
  );
1303
1342
  results.push(...sharedResults);
1304
1343
  }
1344
+ if (this.generatedContent.tagTypes) {
1345
+ const tagTypesResult = await this.fileWriterService.writeFile(
1346
+ path4.join(outputDir, "tagTypes.ts"),
1347
+ this.generatedContent.tagTypes
1348
+ );
1349
+ results.push(tagTypesResult);
1350
+ }
1305
1351
  if (this.generatedContent.componentSchema) {
1306
1352
  const schemaResults = await this.fileWriterService.writeSchemaFile(
1307
1353
  outputDir,