@rexeus/typeweaver-clients 0.4.0 → 0.4.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/dist/lib/ApiClient.ts +17 -13
- package/package.json +6 -6
package/dist/lib/ApiClient.ts
CHANGED
|
@@ -70,6 +70,7 @@ export abstract class ApiClient {
|
|
|
70
70
|
"Base URL must be provided either in axios instance or in constructor"
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
|
+
this.axiosInstance.defaults.baseURL = undefined;
|
|
73
74
|
|
|
74
75
|
this.unknownResponseHandling = props.unknownResponseHandling ?? "throw";
|
|
75
76
|
this.isSuccessStatusCode =
|
|
@@ -169,7 +170,7 @@ export abstract class ApiClient {
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
return Object.entries(param).reduce((acc, [key, value]) => {
|
|
172
|
-
const result = acc.replace(`:${key}`, value);
|
|
173
|
+
const result = acc.replace(`:${key}`, encodeURIComponent(value));
|
|
173
174
|
|
|
174
175
|
if (result === acc) {
|
|
175
176
|
throw new Error(
|
|
@@ -181,33 +182,36 @@ export abstract class ApiClient {
|
|
|
181
182
|
}, path);
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
private
|
|
185
|
+
private createUrl(path: string, query?: IHttpQuery): string {
|
|
186
|
+
const base = this.baseUrl.replace(/\/+$/, "");
|
|
187
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
188
|
+
const queryString = this.buildQueryString(query);
|
|
189
|
+
return queryString
|
|
190
|
+
? `${base}${normalizedPath}?${queryString}`
|
|
191
|
+
: `${base}${normalizedPath}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private buildQueryString(query?: IHttpQuery): string {
|
|
185
195
|
if (!query) {
|
|
186
|
-
return;
|
|
196
|
+
return "";
|
|
187
197
|
}
|
|
188
198
|
|
|
189
|
-
const
|
|
199
|
+
const params = new URLSearchParams();
|
|
190
200
|
for (const [key, value] of Object.entries(query)) {
|
|
191
201
|
if (value === undefined) {
|
|
192
202
|
continue;
|
|
193
203
|
}
|
|
194
204
|
if (!Array.isArray(value)) {
|
|
195
|
-
|
|
205
|
+
params.append(key, value);
|
|
196
206
|
continue;
|
|
197
207
|
}
|
|
198
|
-
|
|
199
208
|
for (const item of value) {
|
|
200
209
|
if (item !== undefined) {
|
|
201
|
-
|
|
210
|
+
params.append(key, item);
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
private createUrl(path: string, query?: IHttpQuery): string {
|
|
208
|
-
const url = new URL(path, this.baseUrl);
|
|
209
|
-
this.addQuery(url, query);
|
|
210
|
-
return url.toString();
|
|
214
|
+
return params.toString();
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
private createHeader(header: any): any {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-clients",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Generates HTTP clients directly from your API definitions. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"axios": "^1.13.0",
|
|
51
51
|
"zod": "^4.3.0",
|
|
52
|
-
"@rexeus/typeweaver-core": "^0.4.
|
|
53
|
-
"@rexeus/typeweaver-gen": "^0.4.
|
|
52
|
+
"@rexeus/typeweaver-core": "^0.4.1",
|
|
53
|
+
"@rexeus/typeweaver-gen": "^0.4.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@hono/node-server": "^1.19.7",
|
|
57
57
|
"axios": "^1.13.2",
|
|
58
58
|
"test-utils": "file:../test-utils",
|
|
59
59
|
"zod": "^4.3.6",
|
|
60
|
-
"@rexeus/typeweaver-core": "^0.4.
|
|
61
|
-
"@rexeus/typeweaver-gen": "^0.4.
|
|
60
|
+
"@rexeus/typeweaver-core": "^0.4.1",
|
|
61
|
+
"@rexeus/typeweaver-gen": "^0.4.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"case": "^1.6.3",
|
|
65
|
-
"@rexeus/typeweaver-zod-to-ts": "^0.4.
|
|
65
|
+
"@rexeus/typeweaver-zod-to-ts": "^0.4.1"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"typecheck": "tsc --noEmit",
|