@bitstack/ng-query-codegen-openapi 0.0.31-alpha.4 → 0.0.31-alpha.6

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.mjs CHANGED
@@ -484,7 +484,7 @@ export interface IRequestConfig extends RequestOptions {
484
484
  }
485
485
 
486
486
  export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
487
- (undefined | {fetchOptions?: IRequestConfig;}):
487
+ (undefined | {fetchOptions?: IRequestConfig;config?: QueryConfig;}):
488
488
  {
489
489
  variables: TVariables;
490
490
  fetchOptions?: IRequestConfig;
@@ -912,15 +912,15 @@ function generateRtkQueryFile(endpointInfos, options) {
912
912
  /**
913
913
  * ${info.summary}
914
914
  */
915
- ${info.operationName}Query(${info.argTypeName !== "VoidApiArg" ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>` : ""}): Observable<QueryState<${info.responseTypeName}>> {
916
- return this.ntkQuery.query<${info.responseTypeName}, ${info.argTypeName !== "VoidApiArg" ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}>({
917
- queryKey: [ECacheTagTypes.${info.queryKeyName}${info.argTypeName !== "VoidApiArg" ? ", args.variables" : ""}],
915
+ ${info.operationName}Query(args: IRestFulEndpointsQueryReturn<${info.argTypeName}>): Observable<QueryState<${info.responseTypeName}>> {
916
+ return this.ntkQuery.query<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}>({
917
+ queryKey: [ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ", args.variables" : ""}],
918
918
  queryFn: () => {
919
- return this.apiService.${info.operationName}(${info.argTypeName !== "VoidApiArg" ? "args" : ""});
919
+ return this.apiService.${info.operationName}(args);
920
920
  },
921
921
  fetchOptions: args?.fetchOptions,
922
922
  config: args?.config,
923
- })${info.argTypeName !== "VoidApiArg" ? "(args)" : "()"};
923
+ })(args);
924
924
  }`
925
925
  ).join("");
926
926
  const mutationMethods = endpointInfos.filter((info) => !info.isQuery).map(
@@ -929,13 +929,13 @@ function generateRtkQueryFile(endpointInfos, options) {
929
929
  * ${info.summary}
930
930
  */
931
931
  ${info.operationName}Mutation(): MutationResponse<${info.responseTypeName}, {
932
- variables: ${info.argTypeName !== "VoidApiArg" ? info.argTypeName : "void"};
932
+ variables: ${!info.isVoidArg ? info.argTypeName : "void"};
933
933
  fetchOptions?: RequestOptions;
934
934
  }, HttpErrorResponse> {
935
- return this.ntkQuery.mutation<${info.responseTypeName}, ${info.argTypeName !== "VoidApiArg" ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}, HttpErrorResponse>({
935
+ return this.ntkQuery.mutation<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : "void"}, HttpErrorResponse>({
936
936
  endpointName: '${info.operationName}',
937
- mutationFn: (${info.argTypeName !== "VoidApiArg" ? "args" : ""}) => {
938
- return this.apiService.${info.operationName}(${info.argTypeName !== "VoidApiArg" ? "args" : ""});
937
+ mutationFn: (args) => {
938
+ return this.apiService.${info.operationName}(args);
939
939
  },
940
940
  });
941
941
  }`
@@ -946,18 +946,18 @@ function generateRtkQueryFile(endpointInfos, options) {
946
946
  * ${info.summary}
947
947
  */
948
948
  ${info.operationName}LazyQuery(): {
949
- trigger: (${info.argTypeName !== "VoidApiArg" ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, ` : ""}options?: { skipCache?: boolean }) => Observable<${info.responseTypeName}>
949
+ trigger: (args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, options?: { skipCache?: boolean }) => Observable<${info.responseTypeName}>
950
950
  } {
951
951
  return {
952
- trigger: (${info.argTypeName !== "VoidApiArg" ? "args, " : ""}options = {}) => {
952
+ trigger: (${!info.isVoidArg ? "args, " : ""}options = {}) => {
953
953
  const { skipCache = true } = options;
954
954
  if (!skipCache) {
955
- const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${info.argTypeName !== "VoidApiArg" ? ", args.variables" : ""}]);
955
+ const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ", args.variables" : ""}]);
956
956
  if (cachedResult) {
957
957
  return cachedResult;
958
958
  }
959
959
  }
960
- return this.apiService.${info.operationName}(${info.argTypeName !== "VoidApiArg" ? "args" : ""});
960
+ return this.apiService.${info.operationName}(args);
961
961
  }
962
962
  };
963
963
  }`
@@ -1010,7 +1010,7 @@ export class ${apiServiceClassName} {
1010
1010
 
1011
1011
  ${endpointInfos.map((info) => {
1012
1012
  const isGet = info.verb.toUpperCase() === "GET";
1013
- const hasArgs = info.argTypeName !== "VoidApiArg";
1013
+ const hasArgs = !info.isVoidArg;
1014
1014
  const hasRequestBody = info.hasRequestBody;
1015
1015
  const generateUrlTemplate = (path5) => {
1016
1016
  const hasPathParams = path5.includes("{");
@@ -1030,8 +1030,8 @@ ${endpointInfos.map((info) => {
1030
1030
  paramsSection = `params: {${paramsLines}},`;
1031
1031
  }
1032
1032
  return `{
1033
- ...args.fetchOptions,
1034
- headers: { 'Content-Type': '${info.contentType}', ...args.fetchOptions?.headers },
1033
+ ...args?.fetchOptions,
1034
+ headers: { 'Content-Type': '${info.contentType}', ...args?.fetchOptions?.headers },
1035
1035
  ${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ""}
1036
1036
  }`;
1037
1037
  };
@@ -1040,7 +1040,7 @@ ${endpointInfos.map((info) => {
1040
1040
  * ${info.summary}
1041
1041
  */
1042
1042
  ${info.operationName}(
1043
- ${hasArgs ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, ` : ""}
1043
+ args: IRestFulEndpointsQueryReturn<${info.argTypeName}>,
1044
1044
  ): Observable<${info.responseTypeName}> {
1045
1045
  const url = ${generateUrlTemplate(info.path)};
1046
1046
  return this.http.request('${info.verb.toLowerCase()}', url, ${generateRequestOptions()});