@acrool/rtk-query-codegen-openapi 1.4.0-alpha.1 → 1.4.0-alpha.3
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/bin/cli.mjs +94 -48
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +83 -27
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +83 -27
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/common-types-generator.ts +49 -2
- package/src/generators/rtk-query-generator.ts +44 -20
- package/src/services/unified-code-generator.ts +1 -7
package/lib/index.mjs
CHANGED
|
@@ -474,12 +474,59 @@ export interface IRequestConfig {
|
|
|
474
474
|
timeout?: number;
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
478
|
-
void | {fetchOptions?: IRequestConfig;}:
|
|
477
|
+
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
478
|
+
void | {fetchOptions?: IRequestConfig;}:
|
|
479
479
|
{
|
|
480
480
|
variables: TVariables;
|
|
481
481
|
fetchOptions?: IRequestConfig;
|
|
482
482
|
};
|
|
483
|
+
|
|
484
|
+
export interface RtkQueryBaseOptions {
|
|
485
|
+
skip?: boolean;
|
|
486
|
+
pollingInterval?: number;
|
|
487
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
488
|
+
refetchOnFocus?: boolean;
|
|
489
|
+
refetchOnReconnect?: boolean;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface RtkQueryResult<TData> {
|
|
493
|
+
data: TData | undefined;
|
|
494
|
+
currentData: TData | undefined;
|
|
495
|
+
isLoading: boolean;
|
|
496
|
+
isFetching: boolean;
|
|
497
|
+
isSuccess: boolean;
|
|
498
|
+
isError: boolean;
|
|
499
|
+
isUninitialized: boolean;
|
|
500
|
+
error: unknown;
|
|
501
|
+
refetch: () => void;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export type SimpleQueryHook<TData, TArg> = (
|
|
505
|
+
arg: TArg,
|
|
506
|
+
options?: RtkQueryBaseOptions
|
|
507
|
+
) => RtkQueryResult<TData>;
|
|
508
|
+
|
|
509
|
+
export type SimpleVoidQueryHook<TData> = (
|
|
510
|
+
options?: RtkQueryBaseOptions
|
|
511
|
+
) => RtkQueryResult<TData>;
|
|
512
|
+
|
|
513
|
+
export type SimpleLazyQueryHook<TData, TArg> = () => readonly [
|
|
514
|
+
(arg: TArg) => void,
|
|
515
|
+
RtkQueryResult<TData>
|
|
516
|
+
];
|
|
517
|
+
|
|
518
|
+
export type UseSimpleMutation<TRes, TArg = void> = () => readonly [
|
|
519
|
+
(arg: TArg) => Promise<TRes>,
|
|
520
|
+
{
|
|
521
|
+
data: TRes | undefined;
|
|
522
|
+
isLoading: boolean;
|
|
523
|
+
isSuccess: boolean;
|
|
524
|
+
isError: boolean;
|
|
525
|
+
isUninitialized: boolean;
|
|
526
|
+
error: unknown;
|
|
527
|
+
reset: () => void;
|
|
528
|
+
}
|
|
529
|
+
];
|
|
483
530
|
`;
|
|
484
531
|
}
|
|
485
532
|
|
|
@@ -1092,10 +1139,42 @@ ${paramsLines}
|
|
|
1092
1139
|
const hasTags = endpointInfos.some((info) => info.tags && info.tags.length > 0);
|
|
1093
1140
|
const tagTypesImport = hasTags ? `import {ECacheTagTypes} from "../tagTypes";
|
|
1094
1141
|
` : "";
|
|
1142
|
+
const hasVoidQuery = endpointInfos.some((info) => info.isQuery && info.isVoidArg);
|
|
1143
|
+
const hasArgQuery = endpointInfos.some((info) => info.isQuery && !info.isVoidArg);
|
|
1144
|
+
const hasLazyQuery = endpointInfos.some((info) => info.isQuery) && !!options.useLazyQueries;
|
|
1145
|
+
const hasMutation = endpointInfos.some((info) => !info.isQuery);
|
|
1146
|
+
const simpleTypeImports = [];
|
|
1147
|
+
if (hasArgQuery) simpleTypeImports.push("SimpleQueryHook");
|
|
1148
|
+
if (hasVoidQuery) simpleTypeImports.push("SimpleVoidQueryHook");
|
|
1149
|
+
if (hasLazyQuery) simpleTypeImports.push("SimpleLazyQueryHook");
|
|
1150
|
+
if (hasMutation) simpleTypeImports.push("UseSimpleMutation");
|
|
1151
|
+
const simpleTypeImportStatement = simpleTypeImports.length > 0 ? `import type { ${simpleTypeImports.join(", ")} } from "../common-types";
|
|
1152
|
+
` : "";
|
|
1153
|
+
const hookExports = endpointInfos.map((info) => {
|
|
1154
|
+
const capitalizedOperationName = info.operationName.charAt(0).toUpperCase() + info.operationName.slice(1);
|
|
1155
|
+
const argType = info.isVoidArg ? "void" : `${httpClientTypeName}<${info.argTypeName}>`;
|
|
1156
|
+
const lines = [];
|
|
1157
|
+
if (info.isQuery) {
|
|
1158
|
+
const regularHook = `use${capitalizedOperationName}Query`;
|
|
1159
|
+
if (info.isVoidArg) {
|
|
1160
|
+
lines.push(`export const ${regularHook} = injectedRtkApi.${regularHook} as SimpleVoidQueryHook<${info.responseTypeName}>;`);
|
|
1161
|
+
} else {
|
|
1162
|
+
lines.push(`export const ${regularHook} = injectedRtkApi.${regularHook} as SimpleQueryHook<${info.responseTypeName}, ${argType}>;`);
|
|
1163
|
+
}
|
|
1164
|
+
if (options.useLazyQueries) {
|
|
1165
|
+
const lazyHook = `useLazy${capitalizedOperationName}Query`;
|
|
1166
|
+
lines.push(`export const ${lazyHook} = injectedRtkApi.${lazyHook} as unknown as SimpleLazyQueryHook<${info.responseTypeName}, ${argType}>;`);
|
|
1167
|
+
}
|
|
1168
|
+
} else {
|
|
1169
|
+
const mutationHook = `use${capitalizedOperationName}Mutation`;
|
|
1170
|
+
lines.push(`export const ${mutationHook} = injectedRtkApi.${mutationHook} as unknown as UseSimpleMutation<${info.responseTypeName}, ${argType}>;`);
|
|
1171
|
+
}
|
|
1172
|
+
return lines.join("\n");
|
|
1173
|
+
}).join("\n");
|
|
1095
1174
|
return `/* eslint-disable */
|
|
1096
1175
|
// [Warning] Generated automatically - do not edit manually
|
|
1097
1176
|
|
|
1098
|
-
${apiImport}${httpClientImport}${tagTypesImport}
|
|
1177
|
+
${apiImport}${httpClientImport}${tagTypesImport}${simpleTypeImportStatement}
|
|
1099
1178
|
${typeImportStatement}
|
|
1100
1179
|
|
|
1101
1180
|
|
|
@@ -1105,24 +1184,7 @@ ${endpoints}
|
|
|
1105
1184
|
}),
|
|
1106
1185
|
});
|
|
1107
1186
|
|
|
1108
|
-
|
|
1109
|
-
${endpointInfos.map((info) => {
|
|
1110
|
-
const capitalizedOperationName = info.operationName.charAt(0).toUpperCase() + info.operationName.slice(1);
|
|
1111
|
-
if (info.isQuery) {
|
|
1112
|
-
const regularHook = `use${capitalizedOperationName}Query`;
|
|
1113
|
-
if (options.useLazyQueries) {
|
|
1114
|
-
const lazyHook = `useLazy${capitalizedOperationName}Query`;
|
|
1115
|
-
return ` ${regularHook},
|
|
1116
|
-
${lazyHook},`;
|
|
1117
|
-
} else {
|
|
1118
|
-
return ` ${regularHook},`;
|
|
1119
|
-
}
|
|
1120
|
-
} else {
|
|
1121
|
-
const mutationHook = `use${capitalizedOperationName}Mutation`;
|
|
1122
|
-
return ` ${mutationHook},`;
|
|
1123
|
-
}
|
|
1124
|
-
}).join("\n")}
|
|
1125
|
-
} = injectedRtkApi;
|
|
1187
|
+
${hookExports}
|
|
1126
1188
|
|
|
1127
1189
|
export default injectedRtkApi;
|
|
1128
1190
|
`;
|
|
@@ -1682,12 +1744,6 @@ var UnifiedCodeGenerator = class {
|
|
|
1682
1744
|
);
|
|
1683
1745
|
results.push(...schemaResults);
|
|
1684
1746
|
}
|
|
1685
|
-
const mainIndexContent = this.generateMainIndex(generatedGroups);
|
|
1686
|
-
const mainIndexResult = await this.fileWriterService.writeFile(
|
|
1687
|
-
path4.join(outputDir, "index.ts"),
|
|
1688
|
-
mainIndexContent
|
|
1689
|
-
);
|
|
1690
|
-
results.push(mainIndexResult);
|
|
1691
1747
|
} catch (error) {
|
|
1692
1748
|
errors.push(error);
|
|
1693
1749
|
}
|