@bitstack/ng-query-codegen-openapi 0.0.31-alpha.4 → 0.0.31-alpha.5
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 +26 -26
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +18 -18
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +18 -18
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/common-types-generator.ts +1 -1
- package/src/generators/rtk-enhance-endpoints-generator.ts +4 -4
- package/src/generators/rtk-query-generator.ts +14 -13
package/lib/index.js
CHANGED
|
@@ -499,7 +499,7 @@ export interface IRequestConfig extends RequestOptions {
|
|
|
499
499
|
}
|
|
500
500
|
|
|
501
501
|
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
502
|
-
(undefined | {fetchOptions?: IRequestConfig;}):
|
|
502
|
+
(undefined | {fetchOptions?: IRequestConfig;config?: QueryConfig;}):
|
|
503
503
|
{
|
|
504
504
|
variables: TVariables;
|
|
505
505
|
fetchOptions?: IRequestConfig;
|
|
@@ -927,15 +927,15 @@ function generateRtkQueryFile(endpointInfos, options) {
|
|
|
927
927
|
/**
|
|
928
928
|
* ${info.summary}
|
|
929
929
|
*/
|
|
930
|
-
${info.operationName}Query(
|
|
931
|
-
return this.ntkQuery.query<${info.responseTypeName}, ${info.
|
|
932
|
-
queryKey: [ECacheTagTypes.${info.queryKeyName}${info.
|
|
930
|
+
${info.operationName}Query(args: IRestFulEndpointsQueryReturn<${info.argTypeName}>): Observable<QueryState<${info.responseTypeName}>> {
|
|
931
|
+
return this.ntkQuery.query<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}>({
|
|
932
|
+
queryKey: [ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ", args.variables" : ""}],
|
|
933
933
|
queryFn: () => {
|
|
934
|
-
return this.apiService.${info.operationName}(
|
|
934
|
+
return this.apiService.${info.operationName}(args);
|
|
935
935
|
},
|
|
936
936
|
fetchOptions: args?.fetchOptions,
|
|
937
937
|
config: args?.config,
|
|
938
|
-
})
|
|
938
|
+
})(args);
|
|
939
939
|
}`
|
|
940
940
|
).join("");
|
|
941
941
|
const mutationMethods = endpointInfos.filter((info) => !info.isQuery).map(
|
|
@@ -944,13 +944,13 @@ function generateRtkQueryFile(endpointInfos, options) {
|
|
|
944
944
|
* ${info.summary}
|
|
945
945
|
*/
|
|
946
946
|
${info.operationName}Mutation(): MutationResponse<${info.responseTypeName}, {
|
|
947
|
-
variables: ${info.
|
|
947
|
+
variables: ${!info.isVoidArg ? info.argTypeName : "void"};
|
|
948
948
|
fetchOptions?: RequestOptions;
|
|
949
949
|
}, HttpErrorResponse> {
|
|
950
|
-
return this.ntkQuery.mutation<${info.responseTypeName}, ${info.
|
|
950
|
+
return this.ntkQuery.mutation<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}, HttpErrorResponse>({
|
|
951
951
|
endpointName: '${info.operationName}',
|
|
952
|
-
mutationFn: (
|
|
953
|
-
return this.apiService.${info.operationName}(
|
|
952
|
+
mutationFn: (args) => {
|
|
953
|
+
return this.apiService.${info.operationName}(args);
|
|
954
954
|
},
|
|
955
955
|
});
|
|
956
956
|
}`
|
|
@@ -961,18 +961,18 @@ function generateRtkQueryFile(endpointInfos, options) {
|
|
|
961
961
|
* ${info.summary}
|
|
962
962
|
*/
|
|
963
963
|
${info.operationName}LazyQuery(): {
|
|
964
|
-
trigger: (${info.
|
|
964
|
+
trigger: (${!info.isVoidArg ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, ` : ""}options?: { skipCache?: boolean }) => Observable<${info.responseTypeName}>
|
|
965
965
|
} {
|
|
966
966
|
return {
|
|
967
|
-
trigger: (${info.
|
|
967
|
+
trigger: (${!info.isVoidArg ? "args, " : ""}options = {}) => {
|
|
968
968
|
const { skipCache = true } = options;
|
|
969
969
|
if (!skipCache) {
|
|
970
|
-
const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${info.
|
|
970
|
+
const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ", args.variables" : ""}]);
|
|
971
971
|
if (cachedResult) {
|
|
972
972
|
return cachedResult;
|
|
973
973
|
}
|
|
974
974
|
}
|
|
975
|
-
return this.apiService.${info.operationName}(
|
|
975
|
+
return this.apiService.${info.operationName}('args');
|
|
976
976
|
}
|
|
977
977
|
};
|
|
978
978
|
}`
|
|
@@ -1025,7 +1025,7 @@ export class ${apiServiceClassName} {
|
|
|
1025
1025
|
|
|
1026
1026
|
${endpointInfos.map((info) => {
|
|
1027
1027
|
const isGet = info.verb.toUpperCase() === "GET";
|
|
1028
|
-
const hasArgs = info.
|
|
1028
|
+
const hasArgs = !info.isVoidArg;
|
|
1029
1029
|
const hasRequestBody = info.hasRequestBody;
|
|
1030
1030
|
const generateUrlTemplate = (path5) => {
|
|
1031
1031
|
const hasPathParams = path5.includes("{");
|
|
@@ -1045,8 +1045,8 @@ ${endpointInfos.map((info) => {
|
|
|
1045
1045
|
paramsSection = `params: {${paramsLines}},`;
|
|
1046
1046
|
}
|
|
1047
1047
|
return `{
|
|
1048
|
-
...args
|
|
1049
|
-
headers: { 'Content-Type': '${info.contentType}', ...args
|
|
1048
|
+
...args?.fetchOptions,
|
|
1049
|
+
headers: { 'Content-Type': '${info.contentType}', ...args?.fetchOptions?.headers },
|
|
1050
1050
|
${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ""}
|
|
1051
1051
|
}`;
|
|
1052
1052
|
};
|
|
@@ -1055,7 +1055,7 @@ ${endpointInfos.map((info) => {
|
|
|
1055
1055
|
* ${info.summary}
|
|
1056
1056
|
*/
|
|
1057
1057
|
${info.operationName}(
|
|
1058
|
-
|
|
1058
|
+
args: IRestFulEndpointsQueryReturn<${info.argTypeName}>,
|
|
1059
1059
|
): Observable<${info.responseTypeName}> {
|
|
1060
1060
|
const url = ${generateUrlTemplate(info.path)};
|
|
1061
1061
|
return this.http.request('${info.verb.toLowerCase()}', url, ${generateRequestOptions()});
|