@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.js CHANGED
@@ -920,7 +920,7 @@ function getTypeFromParameter(param, schemaTypeMap = {}) {
920
920
  init_cjs_shims();
921
921
  function generateRtkQueryFile(endpointInfos, options) {
922
922
  const { groupKey } = options;
923
- const httpClientTypeName = options.httpClient?.importReturnTypeName || options.httpClient?.importName || "IRestFulEndpointsQueryReturn";
923
+ const httpClientTypeName = options.httpClient?.importReturnTypeName || "IRestFulEndpointsQueryReturn";
924
924
  const endpoints = endpointInfos.map((info) => {
925
925
  const methodType = info.isQuery ? "query" : "mutation";
926
926
  const argType = info.isVoidArg ? "void" : `${httpClientTypeName}<${info.argTypeName}>`;
@@ -945,7 +945,7 @@ ${paramsLines}
945
945
  }
946
946
  let tagsSection = "";
947
947
  if (info.tags && info.tags.length > 0) {
948
- const tagsArray = info.tags.map((tag) => `"${tag}"`).join(", ");
948
+ const tagsArray = info.tags.map((tag) => `ECacheTagTypes.${tag}`).join(", ");
949
949
  if (info.isQuery) {
950
950
  tagsSection = `
951
951
  providesTags: [${tagsArray}],`;
@@ -981,10 +981,13 @@ ${paramsLines}
981
981
  const httpClientImport = options.httpClient ? `import {${options.httpClient.importReturnTypeName}} from "${options.httpClient.file}";
982
982
  ` : `import {IRestFulEndpointsQueryReturn} from "@acrool/react-fetcher";
983
983
  `;
984
+ const hasTags = endpointInfos.some((info) => info.tags && info.tags.length > 0);
985
+ const tagTypesImport = hasTags ? `import {ECacheTagTypes} from "../tagTypes";
986
+ ` : "";
984
987
  return `/* eslint-disable */
985
988
  // [Warning] Generated automatically - do not edit manually
986
989
 
987
- ${apiImport}${httpClientImport}
990
+ ${apiImport}${httpClientImport}${tagTypesImport}
988
991
  ${typeImportStatement}
989
992
 
990
993
 
@@ -1078,8 +1081,15 @@ var ApiCodeGenerator = class {
1078
1081
  const enhanceEndpointsContent = generateRtkEnhanceEndpointsFile(endpointInfos, this.options);
1079
1082
  const indexContent = this.generateIndex();
1080
1083
  const operationNames = endpointInfos.map((info) => info.operationName);
1084
+ const allTags = /* @__PURE__ */ new Set();
1085
+ endpointInfos.forEach((info) => {
1086
+ if (info.tags && Array.isArray(info.tags)) {
1087
+ info.tags.forEach((tag) => allTags.add(tag));
1088
+ }
1089
+ });
1081
1090
  return {
1082
1091
  operationNames,
1092
+ tags: Array.from(allTags),
1083
1093
  files: {
1084
1094
  types: typesContent,
1085
1095
  queryService: rtkQueryContent,
@@ -1163,6 +1173,27 @@ export function withoutUndefined(obj?: Record<string, any>) {
1163
1173
  `;
1164
1174
  }
1165
1175
 
1176
+ // src/generators/tag-types-generator.ts
1177
+ init_cjs_shims();
1178
+ function generateTagTypesFile(tags) {
1179
+ if (tags.length === 0) {
1180
+ return `/* eslint-disable */
1181
+ // [Warning] Generated automatically - do not edit manually
1182
+
1183
+ export enum ECacheTagTypes {
1184
+ }
1185
+ `;
1186
+ }
1187
+ const enumEntries = tags.sort().map((tag) => ` ${tag} = '${tag}',`).join("\n");
1188
+ return `/* eslint-disable */
1189
+ // [Warning] Generated automatically - do not edit manually
1190
+
1191
+ export enum ECacheTagTypes {
1192
+ ${enumEntries}
1193
+ }
1194
+ `;
1195
+ }
1196
+
1166
1197
  // src/services/unified-code-generator.ts
1167
1198
  var UnifiedCodeGenerator = class {
1168
1199
  _options;
@@ -1180,8 +1211,11 @@ var UnifiedCodeGenerator = class {
1180
1211
  commonTypes: "",
1181
1212
  componentSchema: "",
1182
1213
  doNotModify: "",
1183
- utils: ""
1214
+ utils: "",
1215
+ tagTypes: ""
1184
1216
  };
1217
+ // 收集所有 tags
1218
+ allTags = /* @__PURE__ */ new Set();
1185
1219
  constructor(options) {
1186
1220
  this._options = options;
1187
1221
  }
@@ -1195,6 +1229,7 @@ var UnifiedCodeGenerator = class {
1195
1229
  this.generateSchemaContent();
1196
1230
  this.generateUtilsContent();
1197
1231
  this.generateDoNotModifyContent();
1232
+ this.generateTagTypesContent();
1198
1233
  return await this.release();
1199
1234
  }
1200
1235
  /**
@@ -1247,6 +1282,9 @@ var UnifiedCodeGenerator = class {
1247
1282
  outputPath: groupInfo.outputPath,
1248
1283
  content: groupContent
1249
1284
  });
1285
+ if (groupContent.tags && Array.isArray(groupContent.tags)) {
1286
+ groupContent.tags.forEach((tag) => this.allTags.add(tag));
1287
+ }
1250
1288
  }
1251
1289
  } catch (error) {
1252
1290
  throw new Error(`\u7FA4\u7D44 ${groupInfo.groupKey} \u751F\u6210\u5931\u6557: ${error}`);
@@ -1277,6 +1315,13 @@ var UnifiedCodeGenerator = class {
1277
1315
  async generateUtilsContent() {
1278
1316
  this.generatedContent.utils = generateUtilsFile();
1279
1317
  }
1318
+ /**
1319
+ * 生成 Tag Types
1320
+ */
1321
+ async generateTagTypesContent() {
1322
+ const tagsArray = Array.from(this.allTags);
1323
+ this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
1324
+ }
1280
1325
  /**
1281
1326
  * 發佈階段:統一寫入所有檔案
1282
1327
  */
@@ -1317,6 +1362,13 @@ var UnifiedCodeGenerator = class {
1317
1362
  );
1318
1363
  results.push(...sharedResults);
1319
1364
  }
1365
+ if (this.generatedContent.tagTypes) {
1366
+ const tagTypesResult = await this.fileWriterService.writeFile(
1367
+ import_node_path4.default.join(outputDir, "tagTypes.ts"),
1368
+ this.generatedContent.tagTypes
1369
+ );
1370
+ results.push(tagTypesResult);
1371
+ }
1320
1372
  if (this.generatedContent.componentSchema) {
1321
1373
  const schemaResults = await this.fileWriterService.writeSchemaFile(
1322
1374
  outputDir,