@acrool/rtk-query-codegen-openapi 1.2.0-alpha.0 → 1.2.0-alpha.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/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
 
@@ -1063,8 +1066,15 @@ var ApiCodeGenerator = class {
1063
1066
  const enhanceEndpointsContent = generateRtkEnhanceEndpointsFile(endpointInfos, this.options);
1064
1067
  const indexContent = this.generateIndex();
1065
1068
  const operationNames = endpointInfos.map((info) => info.operationName);
1069
+ const allTags = /* @__PURE__ */ new Set();
1070
+ endpointInfos.forEach((info) => {
1071
+ if (info.tags && Array.isArray(info.tags)) {
1072
+ info.tags.forEach((tag) => allTags.add(tag));
1073
+ }
1074
+ });
1066
1075
  return {
1067
1076
  operationNames,
1077
+ tags: Array.from(allTags),
1068
1078
  files: {
1069
1079
  types: typesContent,
1070
1080
  queryService: rtkQueryContent,
@@ -1148,6 +1158,27 @@ export function withoutUndefined(obj?: Record<string, any>) {
1148
1158
  `;
1149
1159
  }
1150
1160
 
1161
+ // src/generators/tag-types-generator.ts
1162
+ init_esm_shims();
1163
+ function generateTagTypesFile(tags) {
1164
+ if (tags.length === 0) {
1165
+ return `/* eslint-disable */
1166
+ // [Warning] Generated automatically - do not edit manually
1167
+
1168
+ export enum ECacheTagTypes {
1169
+ }
1170
+ `;
1171
+ }
1172
+ const enumEntries = tags.sort().map((tag) => ` ${tag} = '${tag}',`).join("\n");
1173
+ return `/* eslint-disable */
1174
+ // [Warning] Generated automatically - do not edit manually
1175
+
1176
+ export enum ECacheTagTypes {
1177
+ ${enumEntries}
1178
+ }
1179
+ `;
1180
+ }
1181
+
1151
1182
  // src/services/unified-code-generator.ts
1152
1183
  var UnifiedCodeGenerator = class {
1153
1184
  _options;
@@ -1165,8 +1196,11 @@ var UnifiedCodeGenerator = class {
1165
1196
  commonTypes: "",
1166
1197
  componentSchema: "",
1167
1198
  doNotModify: "",
1168
- utils: ""
1199
+ utils: "",
1200
+ tagTypes: ""
1169
1201
  };
1202
+ // 收集所有 tags
1203
+ allTags = /* @__PURE__ */ new Set();
1170
1204
  constructor(options) {
1171
1205
  this._options = options;
1172
1206
  }
@@ -1180,6 +1214,7 @@ var UnifiedCodeGenerator = class {
1180
1214
  this.generateSchemaContent();
1181
1215
  this.generateUtilsContent();
1182
1216
  this.generateDoNotModifyContent();
1217
+ this.generateTagTypesContent();
1183
1218
  return await this.release();
1184
1219
  }
1185
1220
  /**
@@ -1232,6 +1267,9 @@ var UnifiedCodeGenerator = class {
1232
1267
  outputPath: groupInfo.outputPath,
1233
1268
  content: groupContent
1234
1269
  });
1270
+ if (groupContent.tags && Array.isArray(groupContent.tags)) {
1271
+ groupContent.tags.forEach((tag) => this.allTags.add(tag));
1272
+ }
1235
1273
  }
1236
1274
  } catch (error) {
1237
1275
  throw new Error(`\u7FA4\u7D44 ${groupInfo.groupKey} \u751F\u6210\u5931\u6557: ${error}`);
@@ -1262,6 +1300,13 @@ var UnifiedCodeGenerator = class {
1262
1300
  async generateUtilsContent() {
1263
1301
  this.generatedContent.utils = generateUtilsFile();
1264
1302
  }
1303
+ /**
1304
+ * 生成 Tag Types
1305
+ */
1306
+ async generateTagTypesContent() {
1307
+ const tagsArray = Array.from(this.allTags);
1308
+ this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
1309
+ }
1265
1310
  /**
1266
1311
  * 發佈階段:統一寫入所有檔案
1267
1312
  */
@@ -1302,6 +1347,13 @@ var UnifiedCodeGenerator = class {
1302
1347
  );
1303
1348
  results.push(...sharedResults);
1304
1349
  }
1350
+ if (this.generatedContent.tagTypes) {
1351
+ const tagTypesResult = await this.fileWriterService.writeFile(
1352
+ path4.join(outputDir, "tagTypes.ts"),
1353
+ this.generatedContent.tagTypes
1354
+ );
1355
+ results.push(tagTypesResult);
1356
+ }
1305
1357
  if (this.generatedContent.componentSchema) {
1306
1358
  const schemaResults = await this.fileWriterService.writeSchemaFile(
1307
1359
  outputDir,