@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.js
CHANGED
|
@@ -489,12 +489,59 @@ export interface IRequestConfig {
|
|
|
489
489
|
timeout?: number;
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
-
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
493
|
-
void | {fetchOptions?: IRequestConfig;}:
|
|
492
|
+
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
493
|
+
void | {fetchOptions?: IRequestConfig;}:
|
|
494
494
|
{
|
|
495
495
|
variables: TVariables;
|
|
496
496
|
fetchOptions?: IRequestConfig;
|
|
497
497
|
};
|
|
498
|
+
|
|
499
|
+
export interface RtkQueryBaseOptions {
|
|
500
|
+
skip?: boolean;
|
|
501
|
+
pollingInterval?: number;
|
|
502
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
503
|
+
refetchOnFocus?: boolean;
|
|
504
|
+
refetchOnReconnect?: boolean;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export interface RtkQueryResult<TData> {
|
|
508
|
+
data: TData | undefined;
|
|
509
|
+
currentData: TData | undefined;
|
|
510
|
+
isLoading: boolean;
|
|
511
|
+
isFetching: boolean;
|
|
512
|
+
isSuccess: boolean;
|
|
513
|
+
isError: boolean;
|
|
514
|
+
isUninitialized: boolean;
|
|
515
|
+
error: unknown;
|
|
516
|
+
refetch: () => void;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export type SimpleQueryHook<TData, TArg> = (
|
|
520
|
+
arg: TArg,
|
|
521
|
+
options?: RtkQueryBaseOptions
|
|
522
|
+
) => RtkQueryResult<TData>;
|
|
523
|
+
|
|
524
|
+
export type SimpleVoidQueryHook<TData> = (
|
|
525
|
+
options?: RtkQueryBaseOptions
|
|
526
|
+
) => RtkQueryResult<TData>;
|
|
527
|
+
|
|
528
|
+
export type SimpleLazyQueryHook<TData, TArg> = () => readonly [
|
|
529
|
+
(arg: TArg) => void,
|
|
530
|
+
RtkQueryResult<TData>
|
|
531
|
+
];
|
|
532
|
+
|
|
533
|
+
export type UseSimpleMutation<TRes, TArg = void> = () => readonly [
|
|
534
|
+
(arg: TArg) => Promise<TRes>,
|
|
535
|
+
{
|
|
536
|
+
data: TRes | undefined;
|
|
537
|
+
isLoading: boolean;
|
|
538
|
+
isSuccess: boolean;
|
|
539
|
+
isError: boolean;
|
|
540
|
+
isUninitialized: boolean;
|
|
541
|
+
error: unknown;
|
|
542
|
+
reset: () => void;
|
|
543
|
+
}
|
|
544
|
+
];
|
|
498
545
|
`;
|
|
499
546
|
}
|
|
500
547
|
|
|
@@ -1107,10 +1154,42 @@ ${paramsLines}
|
|
|
1107
1154
|
const hasTags = endpointInfos.some((info) => info.tags && info.tags.length > 0);
|
|
1108
1155
|
const tagTypesImport = hasTags ? `import {ECacheTagTypes} from "../tagTypes";
|
|
1109
1156
|
` : "";
|
|
1157
|
+
const hasVoidQuery = endpointInfos.some((info) => info.isQuery && info.isVoidArg);
|
|
1158
|
+
const hasArgQuery = endpointInfos.some((info) => info.isQuery && !info.isVoidArg);
|
|
1159
|
+
const hasLazyQuery = endpointInfos.some((info) => info.isQuery) && !!options.useLazyQueries;
|
|
1160
|
+
const hasMutation = endpointInfos.some((info) => !info.isQuery);
|
|
1161
|
+
const simpleTypeImports = [];
|
|
1162
|
+
if (hasArgQuery) simpleTypeImports.push("SimpleQueryHook");
|
|
1163
|
+
if (hasVoidQuery) simpleTypeImports.push("SimpleVoidQueryHook");
|
|
1164
|
+
if (hasLazyQuery) simpleTypeImports.push("SimpleLazyQueryHook");
|
|
1165
|
+
if (hasMutation) simpleTypeImports.push("UseSimpleMutation");
|
|
1166
|
+
const simpleTypeImportStatement = simpleTypeImports.length > 0 ? `import type { ${simpleTypeImports.join(", ")} } from "../common-types";
|
|
1167
|
+
` : "";
|
|
1168
|
+
const hookExports = endpointInfos.map((info) => {
|
|
1169
|
+
const capitalizedOperationName = info.operationName.charAt(0).toUpperCase() + info.operationName.slice(1);
|
|
1170
|
+
const argType = info.isVoidArg ? "void" : `${httpClientTypeName}<${info.argTypeName}>`;
|
|
1171
|
+
const lines = [];
|
|
1172
|
+
if (info.isQuery) {
|
|
1173
|
+
const regularHook = `use${capitalizedOperationName}Query`;
|
|
1174
|
+
if (info.isVoidArg) {
|
|
1175
|
+
lines.push(`export const ${regularHook} = injectedRtkApi.${regularHook} as SimpleVoidQueryHook<${info.responseTypeName}>;`);
|
|
1176
|
+
} else {
|
|
1177
|
+
lines.push(`export const ${regularHook} = injectedRtkApi.${regularHook} as SimpleQueryHook<${info.responseTypeName}, ${argType}>;`);
|
|
1178
|
+
}
|
|
1179
|
+
if (options.useLazyQueries) {
|
|
1180
|
+
const lazyHook = `useLazy${capitalizedOperationName}Query`;
|
|
1181
|
+
lines.push(`export const ${lazyHook} = injectedRtkApi.${lazyHook} as unknown as SimpleLazyQueryHook<${info.responseTypeName}, ${argType}>;`);
|
|
1182
|
+
}
|
|
1183
|
+
} else {
|
|
1184
|
+
const mutationHook = `use${capitalizedOperationName}Mutation`;
|
|
1185
|
+
lines.push(`export const ${mutationHook} = injectedRtkApi.${mutationHook} as unknown as UseSimpleMutation<${info.responseTypeName}, ${argType}>;`);
|
|
1186
|
+
}
|
|
1187
|
+
return lines.join("\n");
|
|
1188
|
+
}).join("\n");
|
|
1110
1189
|
return `/* eslint-disable */
|
|
1111
1190
|
// [Warning] Generated automatically - do not edit manually
|
|
1112
1191
|
|
|
1113
|
-
${apiImport}${httpClientImport}${tagTypesImport}
|
|
1192
|
+
${apiImport}${httpClientImport}${tagTypesImport}${simpleTypeImportStatement}
|
|
1114
1193
|
${typeImportStatement}
|
|
1115
1194
|
|
|
1116
1195
|
|
|
@@ -1120,24 +1199,7 @@ ${endpoints}
|
|
|
1120
1199
|
}),
|
|
1121
1200
|
});
|
|
1122
1201
|
|
|
1123
|
-
|
|
1124
|
-
${endpointInfos.map((info) => {
|
|
1125
|
-
const capitalizedOperationName = info.operationName.charAt(0).toUpperCase() + info.operationName.slice(1);
|
|
1126
|
-
if (info.isQuery) {
|
|
1127
|
-
const regularHook = `use${capitalizedOperationName}Query`;
|
|
1128
|
-
if (options.useLazyQueries) {
|
|
1129
|
-
const lazyHook = `useLazy${capitalizedOperationName}Query`;
|
|
1130
|
-
return ` ${regularHook},
|
|
1131
|
-
${lazyHook},`;
|
|
1132
|
-
} else {
|
|
1133
|
-
return ` ${regularHook},`;
|
|
1134
|
-
}
|
|
1135
|
-
} else {
|
|
1136
|
-
const mutationHook = `use${capitalizedOperationName}Mutation`;
|
|
1137
|
-
return ` ${mutationHook},`;
|
|
1138
|
-
}
|
|
1139
|
-
}).join("\n")}
|
|
1140
|
-
} = injectedRtkApi;
|
|
1202
|
+
${hookExports}
|
|
1141
1203
|
|
|
1142
1204
|
export default injectedRtkApi;
|
|
1143
1205
|
`;
|
|
@@ -1697,12 +1759,6 @@ var UnifiedCodeGenerator = class {
|
|
|
1697
1759
|
);
|
|
1698
1760
|
results.push(...schemaResults);
|
|
1699
1761
|
}
|
|
1700
|
-
const mainIndexContent = this.generateMainIndex(generatedGroups);
|
|
1701
|
-
const mainIndexResult = await this.fileWriterService.writeFile(
|
|
1702
|
-
import_node_path4.default.join(outputDir, "index.ts"),
|
|
1703
|
-
mainIndexContent
|
|
1704
|
-
);
|
|
1705
|
-
results.push(mainIndexResult);
|
|
1706
1762
|
} catch (error) {
|
|
1707
1763
|
errors.push(error);
|
|
1708
1764
|
}
|