@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.d.ts CHANGED
@@ -53,15 +53,6 @@ interface CommonOptions {
53
53
  file: string;
54
54
  importReturnTypeName: string;
55
55
  };
56
- /**
57
- * Cache tag types configuration for RTK Query cache invalidation
58
- * If provided, will import the specified type from the given file in enhanceEndpoints.ts
59
- * Example: { file: "@/store/tagTypes", importName: "ECacheTagTypes" }
60
- */
61
- cacheTagTypes?: {
62
- file: string;
63
- importReturnTypeName: string;
64
- };
65
56
  /**
66
57
  * defaults to "enhancedApi"
67
58
  */
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
 
@@ -1020,7 +1023,6 @@ export default injectedRtkApi;
1020
1023
  // src/generators/rtk-enhance-endpoints-generator.ts
1021
1024
  init_cjs_shims();
1022
1025
  function generateRtkEnhanceEndpointsFile(endpointInfos, options) {
1023
- const { groupKey, cacheTagTypes } = options;
1024
1026
  const endpointConfigs = endpointInfos.map((info) => {
1025
1027
  if (info.isQuery) {
1026
1028
  return ` ${info.operationName}: {
@@ -1032,15 +1034,10 @@ function generateRtkEnhanceEndpointsFile(endpointInfos, options) {
1032
1034
  },`;
1033
1035
  }
1034
1036
  }).join("\n");
1035
- let importStatements = `/* eslint-disable */
1037
+ const importStatements = `/* eslint-disable */
1036
1038
  // [Warning] Generated automatically - do not edit manually
1037
1039
 
1038
- `;
1039
- if (cacheTagTypes) {
1040
- importStatements += `import { ${cacheTagTypes.importReturnTypeName} } from "${cacheTagTypes.file}";
1041
- `;
1042
- }
1043
- importStatements += `import api from "./query.generated";
1040
+ import api from "./query.generated";
1044
1041
  `;
1045
1042
  return `${importStatements}
1046
1043
  const enhancedApi = api.enhanceEndpoints({
@@ -1078,8 +1075,15 @@ var ApiCodeGenerator = class {
1078
1075
  const enhanceEndpointsContent = generateRtkEnhanceEndpointsFile(endpointInfos, this.options);
1079
1076
  const indexContent = this.generateIndex();
1080
1077
  const operationNames = endpointInfos.map((info) => info.operationName);
1078
+ const allTags = /* @__PURE__ */ new Set();
1079
+ endpointInfos.forEach((info) => {
1080
+ if (info.tags && Array.isArray(info.tags)) {
1081
+ info.tags.forEach((tag) => allTags.add(tag));
1082
+ }
1083
+ });
1081
1084
  return {
1082
1085
  operationNames,
1086
+ tags: Array.from(allTags),
1083
1087
  files: {
1084
1088
  types: typesContent,
1085
1089
  queryService: rtkQueryContent,
@@ -1163,6 +1167,27 @@ export function withoutUndefined(obj?: Record<string, any>) {
1163
1167
  `;
1164
1168
  }
1165
1169
 
1170
+ // src/generators/tag-types-generator.ts
1171
+ init_cjs_shims();
1172
+ function generateTagTypesFile(tags) {
1173
+ if (tags.length === 0) {
1174
+ return `/* eslint-disable */
1175
+ // [Warning] Generated automatically - do not edit manually
1176
+
1177
+ export enum ECacheTagTypes {
1178
+ }
1179
+ `;
1180
+ }
1181
+ const enumEntries = tags.sort().map((tag) => ` ${tag} = '${tag}',`).join("\n");
1182
+ return `/* eslint-disable */
1183
+ // [Warning] Generated automatically - do not edit manually
1184
+
1185
+ export enum ECacheTagTypes {
1186
+ ${enumEntries}
1187
+ }
1188
+ `;
1189
+ }
1190
+
1166
1191
  // src/services/unified-code-generator.ts
1167
1192
  var UnifiedCodeGenerator = class {
1168
1193
  _options;
@@ -1180,8 +1205,11 @@ var UnifiedCodeGenerator = class {
1180
1205
  commonTypes: "",
1181
1206
  componentSchema: "",
1182
1207
  doNotModify: "",
1183
- utils: ""
1208
+ utils: "",
1209
+ tagTypes: ""
1184
1210
  };
1211
+ // 收集所有 tags
1212
+ allTags = /* @__PURE__ */ new Set();
1185
1213
  constructor(options) {
1186
1214
  this._options = options;
1187
1215
  }
@@ -1195,6 +1223,7 @@ var UnifiedCodeGenerator = class {
1195
1223
  this.generateSchemaContent();
1196
1224
  this.generateUtilsContent();
1197
1225
  this.generateDoNotModifyContent();
1226
+ this.generateTagTypesContent();
1198
1227
  return await this.release();
1199
1228
  }
1200
1229
  /**
@@ -1247,6 +1276,9 @@ var UnifiedCodeGenerator = class {
1247
1276
  outputPath: groupInfo.outputPath,
1248
1277
  content: groupContent
1249
1278
  });
1279
+ if (groupContent.tags && Array.isArray(groupContent.tags)) {
1280
+ groupContent.tags.forEach((tag) => this.allTags.add(tag));
1281
+ }
1250
1282
  }
1251
1283
  } catch (error) {
1252
1284
  throw new Error(`\u7FA4\u7D44 ${groupInfo.groupKey} \u751F\u6210\u5931\u6557: ${error}`);
@@ -1277,6 +1309,13 @@ var UnifiedCodeGenerator = class {
1277
1309
  async generateUtilsContent() {
1278
1310
  this.generatedContent.utils = generateUtilsFile();
1279
1311
  }
1312
+ /**
1313
+ * 生成 Tag Types
1314
+ */
1315
+ async generateTagTypesContent() {
1316
+ const tagsArray = Array.from(this.allTags);
1317
+ this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
1318
+ }
1280
1319
  /**
1281
1320
  * 發佈階段:統一寫入所有檔案
1282
1321
  */
@@ -1317,6 +1356,13 @@ var UnifiedCodeGenerator = class {
1317
1356
  );
1318
1357
  results.push(...sharedResults);
1319
1358
  }
1359
+ if (this.generatedContent.tagTypes) {
1360
+ const tagTypesResult = await this.fileWriterService.writeFile(
1361
+ import_node_path4.default.join(outputDir, "tagTypes.ts"),
1362
+ this.generatedContent.tagTypes
1363
+ );
1364
+ results.push(tagTypesResult);
1365
+ }
1320
1366
  if (this.generatedContent.componentSchema) {
1321
1367
  const schemaResults = await this.fileWriterService.writeSchemaFile(
1322
1368
  outputDir,