better-call 1.0.3 → 1.0.4-beta.2
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/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.cjs +47 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +47 -44
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/router-uAmry411.d.cts +984 -0
- package/dist/router-uAmry411.d.ts +984 -0
- package/package.json +1 -1
- package/dist/router-DUkPVacX.d.cts +0 -2322
- package/dist/router-DUkPVacX.d.ts +0 -2322
package/dist/client.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
-
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-
|
|
2
|
+
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-uAmry411.cjs';
|
|
3
3
|
|
|
4
4
|
type HasRequired<T extends {
|
|
5
5
|
body?: any;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
-
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-
|
|
2
|
+
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-uAmry411.js';
|
|
3
3
|
|
|
4
4
|
type HasRequired<T extends {
|
|
5
5
|
body?: any;
|
package/dist/index.cjs
CHANGED
|
@@ -108,6 +108,50 @@ var APIError = class extends Error {
|
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
// src/utils.ts
|
|
112
|
+
async function getBody(request) {
|
|
113
|
+
const contentType = request.headers.get("content-type") || "";
|
|
114
|
+
if (!request.body) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
if (contentType.includes("application/json")) {
|
|
118
|
+
return await request.json();
|
|
119
|
+
}
|
|
120
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
121
|
+
const formData = await request.formData();
|
|
122
|
+
const result = {};
|
|
123
|
+
formData.forEach((value, key) => {
|
|
124
|
+
result[key] = value.toString();
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
if (contentType.includes("multipart/form-data")) {
|
|
129
|
+
const formData = await request.formData();
|
|
130
|
+
const result = {};
|
|
131
|
+
formData.forEach((value, key) => {
|
|
132
|
+
result[key] = value;
|
|
133
|
+
});
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
if (contentType.includes("text/plain")) {
|
|
137
|
+
return await request.text();
|
|
138
|
+
}
|
|
139
|
+
if (contentType.includes("application/octet-stream")) {
|
|
140
|
+
return await request.arrayBuffer();
|
|
141
|
+
}
|
|
142
|
+
if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("video/")) {
|
|
143
|
+
const blob = await request.blob();
|
|
144
|
+
return blob;
|
|
145
|
+
}
|
|
146
|
+
if (contentType.includes("application/stream") || request.body instanceof ReadableStream) {
|
|
147
|
+
return request.body;
|
|
148
|
+
}
|
|
149
|
+
return await request.text();
|
|
150
|
+
}
|
|
151
|
+
function isAPIError(error) {
|
|
152
|
+
return error instanceof APIError || error.name === "APIError";
|
|
153
|
+
}
|
|
154
|
+
|
|
111
155
|
// src/to-response.ts
|
|
112
156
|
function isJSONSerializable(value) {
|
|
113
157
|
if (value === void 0) {
|
|
@@ -147,7 +191,7 @@ function toResponse(data, init) {
|
|
|
147
191
|
status: data.status
|
|
148
192
|
});
|
|
149
193
|
}
|
|
150
|
-
if (data
|
|
194
|
+
if (isAPIError(data)) {
|
|
151
195
|
return toResponse(data.body, {
|
|
152
196
|
status: data.statusCode,
|
|
153
197
|
statusText: data.status.toString(),
|
|
@@ -532,7 +576,7 @@ var createEndpoint2 = (path, options, handler) => {
|
|
|
532
576
|
path
|
|
533
577
|
});
|
|
534
578
|
const response = await handler(internalContext).catch((e) => {
|
|
535
|
-
if (e
|
|
579
|
+
if (isAPIError(e) && context.asResponse) {
|
|
536
580
|
return e;
|
|
537
581
|
}
|
|
538
582
|
throw e;
|
|
@@ -4744,47 +4788,6 @@ var getHTML = (apiReference, config) => `<!doctype html>
|
|
|
4744
4788
|
</body>
|
|
4745
4789
|
</html>`;
|
|
4746
4790
|
|
|
4747
|
-
// src/utils.ts
|
|
4748
|
-
async function getBody(request) {
|
|
4749
|
-
const contentType = request.headers.get("content-type") || "";
|
|
4750
|
-
if (!request.body) {
|
|
4751
|
-
return void 0;
|
|
4752
|
-
}
|
|
4753
|
-
if (contentType.includes("application/json")) {
|
|
4754
|
-
return await request.json();
|
|
4755
|
-
}
|
|
4756
|
-
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
4757
|
-
const formData = await request.formData();
|
|
4758
|
-
const result = {};
|
|
4759
|
-
formData.forEach((value, key) => {
|
|
4760
|
-
result[key] = value.toString();
|
|
4761
|
-
});
|
|
4762
|
-
return result;
|
|
4763
|
-
}
|
|
4764
|
-
if (contentType.includes("multipart/form-data")) {
|
|
4765
|
-
const formData = await request.formData();
|
|
4766
|
-
const result = {};
|
|
4767
|
-
formData.forEach((value, key) => {
|
|
4768
|
-
result[key] = value;
|
|
4769
|
-
});
|
|
4770
|
-
return result;
|
|
4771
|
-
}
|
|
4772
|
-
if (contentType.includes("text/plain")) {
|
|
4773
|
-
return await request.text();
|
|
4774
|
-
}
|
|
4775
|
-
if (contentType.includes("application/octet-stream")) {
|
|
4776
|
-
return await request.arrayBuffer();
|
|
4777
|
-
}
|
|
4778
|
-
if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("video/")) {
|
|
4779
|
-
const blob = await request.blob();
|
|
4780
|
-
return blob;
|
|
4781
|
-
}
|
|
4782
|
-
if (contentType.includes("application/stream") || request.body instanceof ReadableStream) {
|
|
4783
|
-
return request.body;
|
|
4784
|
-
}
|
|
4785
|
-
return await request.text();
|
|
4786
|
-
}
|
|
4787
|
-
|
|
4788
4791
|
// src/router.ts
|
|
4789
4792
|
var createRouter = (endpoints, config) => {
|
|
4790
4793
|
if (!config?.openapi?.disabled) {
|
|
@@ -4863,7 +4866,7 @@ var createRouter = (endpoints, config) => {
|
|
|
4863
4866
|
const response = await handler(context);
|
|
4864
4867
|
return response;
|
|
4865
4868
|
} catch (error) {
|
|
4866
|
-
if (error
|
|
4869
|
+
if (isAPIError(error)) {
|
|
4867
4870
|
return toResponse(error);
|
|
4868
4871
|
}
|
|
4869
4872
|
console.error(`# SERVER_ERROR: `, error);
|