@bitstack/ng-query-codegen-openapi 0.0.31-alpha.0 → 0.0.31-alpha.1
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 +21 -16
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.d.mts +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +13 -20
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +13 -20
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/common-types-generator.ts +2 -2
- package/src/generators/rtk-enhance-endpoints-generator.ts +17 -17
- package/src/types.ts +5 -0
|
@@ -12,8 +12,10 @@ export function generateRtkEnhanceEndpointsFile(
|
|
|
12
12
|
queryParams: any[];
|
|
13
13
|
pathParams: any[];
|
|
14
14
|
isVoidArg: boolean;
|
|
15
|
-
hasRequestBody: boolean;
|
|
16
15
|
summary: string;
|
|
16
|
+
contentType: string;
|
|
17
|
+
hasRequestBody: boolean;
|
|
18
|
+
tags: string[];
|
|
17
19
|
}>,
|
|
18
20
|
options: GenerationOptions
|
|
19
21
|
) {
|
|
@@ -27,7 +29,7 @@ export function generateRtkEnhanceEndpointsFile(
|
|
|
27
29
|
return `/* eslint-disable */
|
|
28
30
|
// [Warning] Generated automatically - do not edit manually
|
|
29
31
|
|
|
30
|
-
import { ${httpClient!.
|
|
32
|
+
import { ${httpClient!.importReturnTypeName} } from '${httpClient!.file}';
|
|
31
33
|
import { Injectable, inject } from '@angular/core';
|
|
32
34
|
import { Observable } from 'rxjs';
|
|
33
35
|
import { ${apiConfiguration!.importName} } from '${apiConfiguration!.file}';
|
|
@@ -40,7 +42,7 @@ import {${endpointInfos.map((info) => ` ${info.argTypeName}, ${info.responseType
|
|
|
40
42
|
})
|
|
41
43
|
export class ${apiServiceClassName} {
|
|
42
44
|
private config = inject(${apiConfiguration!.importName});
|
|
43
|
-
private http = inject(${httpClient!.
|
|
45
|
+
private http = inject(${httpClient!.importReturnTypeName});
|
|
44
46
|
|
|
45
47
|
${endpointInfos
|
|
46
48
|
.map((info) => {
|
|
@@ -65,22 +67,20 @@ ${endpointInfos
|
|
|
65
67
|
|
|
66
68
|
// 生成 HTTP 請求選項
|
|
67
69
|
const generateRequestOptions = () => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (hasQueryParams && hasArgs) {
|
|
76
|
-
options.push(generateQueryParams(info.queryParams));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (hasRequestBody) {
|
|
80
|
-
options.push('body: args.variables.body');
|
|
70
|
+
// 處理 query parameters
|
|
71
|
+
let paramsSection = '';
|
|
72
|
+
if (info.queryParams && info.queryParams.length > 0) {
|
|
73
|
+
const paramsLines = info.queryParams
|
|
74
|
+
.map((param: any) => `${param.name}: args.variables.${param.name},`)
|
|
75
|
+
.join('\n');
|
|
76
|
+
paramsSection = `params: {${paramsLines}},`;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
return
|
|
79
|
+
return `{
|
|
80
|
+
...args.fetchOptions,
|
|
81
|
+
headers: { 'Content-Type': '${info.contentType}', ...args.fetchOptions?.headers },
|
|
82
|
+
${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ''}
|
|
83
|
+
}`;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
return `
|
package/src/types.ts
CHANGED
|
@@ -142,6 +142,11 @@ export interface CommonOptions {
|
|
|
142
142
|
* File path for importing IRestFulEndpointsQueryReturn type
|
|
143
143
|
*/
|
|
144
144
|
endpointsQueryReturnTypeFile?: string;
|
|
145
|
+
/**
|
|
146
|
+
* defaults to 60 (seconds)
|
|
147
|
+
* Number of seconds to wait before refetching data when component mounts or args change
|
|
148
|
+
*/
|
|
149
|
+
refetchOnMountOrArgChange?: number;
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
export type TextMatcher = string | RegExp | (string | RegExp)[];
|