@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.
@@ -28,6 +28,7 @@ export function generateRtkQueryFile(
28
28
 
29
29
  const apiServiceName = groupKey ? `${groupKey.charAt(0).toUpperCase() + groupKey.slice(1)}ApiService` : 'ApiService';
30
30
 
31
+
31
32
  // 分別處理 Query 和 Mutation 方法
32
33
  const queryMethods = endpointInfos
33
34
  .filter((info) => info.isQuery)
@@ -36,15 +37,15 @@ export function generateRtkQueryFile(
36
37
  /**
37
38
  * ${info.summary}
38
39
  */
39
- ${info.operationName}Query(${info.argTypeName !== 'VoidApiArg' ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>` : ''}): Observable<QueryState<${info.responseTypeName}>> {
40
- return this.ntkQuery.query<${info.responseTypeName}, ${info.argTypeName !== 'VoidApiArg' ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : 'void'}>({
41
- queryKey: [ECacheTagTypes.${info.queryKeyName}${info.argTypeName !== 'VoidApiArg' ? ', args.variables' : ''}],
40
+ ${info.operationName}Query(args: IRestFulEndpointsQueryReturn<${info.argTypeName}>): Observable<QueryState<${info.responseTypeName}>> {
41
+ return this.ntkQuery.query<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : 'void'}>({
42
+ queryKey: [ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ', args.variables' : ''}],
42
43
  queryFn: () => {
43
- return this.apiService.${info.operationName}(${info.argTypeName !== 'VoidApiArg' ? 'args' : ''});
44
+ return this.apiService.${info.operationName}(args);
44
45
  },
45
46
  fetchOptions: args?.fetchOptions,
46
47
  config: args?.config,
47
- })${info.argTypeName !== 'VoidApiArg' ? '(args)' : '()'};
48
+ })(args);
48
49
  }`
49
50
  )
50
51
  .join('');
@@ -57,13 +58,13 @@ export function generateRtkQueryFile(
57
58
  * ${info.summary}
58
59
  */
59
60
  ${info.operationName}Mutation(): MutationResponse<${info.responseTypeName}, {
60
- variables: ${info.argTypeName !== 'VoidApiArg' ? info.argTypeName : 'void'};
61
+ variables: ${!info.isVoidArg ? info.argTypeName : 'void'};
61
62
  fetchOptions?: RequestOptions;
62
63
  }, HttpErrorResponse> {
63
- return this.ntkQuery.mutation<${info.responseTypeName}, ${info.argTypeName !== 'VoidApiArg' ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : 'void'}, HttpErrorResponse>({
64
+ return this.ntkQuery.mutation<${info.responseTypeName}, ${!info.isVoidArg ? `IRestFulEndpointsQueryReturn<${info.argTypeName}>` : 'void'}, HttpErrorResponse>({
64
65
  endpointName: '${info.operationName}',
65
- mutationFn: (${info.argTypeName !== 'VoidApiArg' ? 'args' : ''}) => {
66
- return this.apiService.${info.operationName}(${info.argTypeName !== 'VoidApiArg' ? 'args' : ''});
66
+ mutationFn: (args) => {
67
+ return this.apiService.${info.operationName}(args);
67
68
  },
68
69
  });
69
70
  }`
@@ -78,18 +79,18 @@ export function generateRtkQueryFile(
78
79
  * ${info.summary}
79
80
  */
80
81
  ${info.operationName}LazyQuery(): {
81
- trigger: (${info.argTypeName !== 'VoidApiArg' ? `args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, ` : ''}options?: { skipCache?: boolean }) => Observable<${info.responseTypeName}>
82
+ trigger: (args: IRestFulEndpointsQueryReturn<${info.argTypeName}>, options?: { skipCache?: boolean }) => Observable<${info.responseTypeName}>
82
83
  } {
83
84
  return {
84
- trigger: (${info.argTypeName !== 'VoidApiArg' ? 'args, ' : ''}options = {}) => {
85
+ trigger: (${!info.isVoidArg ? 'args, ' : ''}options = {}) => {
85
86
  const { skipCache = true } = options;
86
87
  if (!skipCache) {
87
- const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${info.argTypeName !== 'VoidApiArg' ? ', args.variables' : ''}]);
88
+ const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ', args.variables' : ''}]);
88
89
  if (cachedResult) {
89
90
  return cachedResult;
90
91
  }
91
92
  }
92
- return this.apiService.${info.operationName}(${info.argTypeName !== 'VoidApiArg' ? 'args' : ''});
93
+ return this.apiService.${info.operationName}(args);
93
94
  }
94
95
  };
95
96
  }`