better-call 0.2.13-beta.8 → 0.2.13
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/README.md +378 -2
- package/dist/client.cjs +33 -8
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +3 -7
- package/dist/client.d.ts +3 -7
- package/dist/client.js +14 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +694 -390
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -20
- package/dist/index.d.ts +115 -20
- package/dist/index.js +1057 -0
- package/dist/index.js.map +1 -0
- package/dist/router-Bn7zn81P.d.cts +342 -0
- package/dist/router-Bn7zn81P.d.ts +342 -0
- package/package.json +21 -27
- package/dist/adapter/node.cjs +0 -210
- package/dist/adapter/node.d.cts +0 -19
- package/dist/adapter/node.d.mts +0 -19
- package/dist/adapter/node.d.ts +0 -19
- package/dist/adapter/node.mjs +0 -206
- package/dist/client.d.mts +0 -42
- package/dist/client.mjs +0 -12
- package/dist/index.d.mts +0 -32
- package/dist/index.mjs +0 -768
- package/dist/shared/better-call.25f0dd59.d.cts +0 -677
- package/dist/shared/better-call.25f0dd59.d.mts +0 -677
- package/dist/shared/better-call.25f0dd59.d.ts +0 -677
package/dist/adapter/node.mjs
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
function splitCookiesString(cookiesString) {
|
|
2
|
-
if (Array.isArray(cookiesString)) {
|
|
3
|
-
return cookiesString;
|
|
4
|
-
}
|
|
5
|
-
if (typeof cookiesString !== "string") {
|
|
6
|
-
return [];
|
|
7
|
-
}
|
|
8
|
-
const cookiesStrings = [];
|
|
9
|
-
let pos = 0;
|
|
10
|
-
let start;
|
|
11
|
-
let ch;
|
|
12
|
-
let lastComma;
|
|
13
|
-
let nextStart;
|
|
14
|
-
let cookiesSeparatorFound;
|
|
15
|
-
function skipWhitespace() {
|
|
16
|
-
if (Array.isArray(cookiesString)) {
|
|
17
|
-
return pos < cookiesString.length;
|
|
18
|
-
}
|
|
19
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
20
|
-
pos += 1;
|
|
21
|
-
}
|
|
22
|
-
return pos < cookiesString.length;
|
|
23
|
-
}
|
|
24
|
-
function notSpecialChar() {
|
|
25
|
-
if (Array.isArray(cookiesString)) {
|
|
26
|
-
return pos < cookiesString.length;
|
|
27
|
-
}
|
|
28
|
-
ch = cookiesString.charAt(pos);
|
|
29
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
30
|
-
}
|
|
31
|
-
while (pos < cookiesString.length) {
|
|
32
|
-
start = pos;
|
|
33
|
-
cookiesSeparatorFound = false;
|
|
34
|
-
while (skipWhitespace()) {
|
|
35
|
-
ch = cookiesString.charAt(pos);
|
|
36
|
-
if (ch === ",") {
|
|
37
|
-
lastComma = pos;
|
|
38
|
-
pos += 1;
|
|
39
|
-
skipWhitespace();
|
|
40
|
-
nextStart = pos;
|
|
41
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
|
42
|
-
pos += 1;
|
|
43
|
-
}
|
|
44
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
45
|
-
cookiesSeparatorFound = true;
|
|
46
|
-
pos = nextStart;
|
|
47
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
48
|
-
start = pos;
|
|
49
|
-
} else {
|
|
50
|
-
pos = lastComma + 1;
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
pos += 1;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
57
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return cookiesStrings;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function get_raw_body(req, body_size_limit) {
|
|
64
|
-
const h = req.headers;
|
|
65
|
-
if (!h["content-type"])
|
|
66
|
-
return null;
|
|
67
|
-
const content_length = Number(h["content-length"]);
|
|
68
|
-
if (req.httpVersionMajor === 1 && isNaN(content_length) && h["transfer-encoding"] == null || content_length === 0) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
let length = content_length;
|
|
72
|
-
if (body_size_limit) {
|
|
73
|
-
if (!length) {
|
|
74
|
-
length = body_size_limit;
|
|
75
|
-
} else if (length > body_size_limit) {
|
|
76
|
-
throw Error(
|
|
77
|
-
`Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (req.destroyed) {
|
|
82
|
-
const readable = new ReadableStream();
|
|
83
|
-
readable.cancel();
|
|
84
|
-
return readable;
|
|
85
|
-
}
|
|
86
|
-
let size = 0;
|
|
87
|
-
let cancelled = false;
|
|
88
|
-
return new ReadableStream({
|
|
89
|
-
start(controller) {
|
|
90
|
-
req.on("error", (error) => {
|
|
91
|
-
cancelled = true;
|
|
92
|
-
controller.error(error);
|
|
93
|
-
});
|
|
94
|
-
req.on("end", () => {
|
|
95
|
-
if (cancelled)
|
|
96
|
-
return;
|
|
97
|
-
controller.close();
|
|
98
|
-
});
|
|
99
|
-
req.on("data", (chunk) => {
|
|
100
|
-
if (cancelled)
|
|
101
|
-
return;
|
|
102
|
-
size += chunk.length;
|
|
103
|
-
if (size > length) {
|
|
104
|
-
cancelled = true;
|
|
105
|
-
controller.error(
|
|
106
|
-
new Error(
|
|
107
|
-
`request body size exceeded ${content_length ? "'content-length'" : "BODY_SIZE_LIMIT"} of ${length}`
|
|
108
|
-
)
|
|
109
|
-
);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
controller.enqueue(chunk);
|
|
113
|
-
if (controller.desiredSize === null || controller.desiredSize <= 0) {
|
|
114
|
-
req.pause();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
pull() {
|
|
119
|
-
req.resume();
|
|
120
|
-
},
|
|
121
|
-
cancel(reason) {
|
|
122
|
-
cancelled = true;
|
|
123
|
-
req.destroy(reason);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
function getRequest({
|
|
128
|
-
request,
|
|
129
|
-
base,
|
|
130
|
-
bodySizeLimit
|
|
131
|
-
}) {
|
|
132
|
-
return new Request(base + request.url, {
|
|
133
|
-
duplex: "half",
|
|
134
|
-
method: request.method,
|
|
135
|
-
body: get_raw_body(request, bodySizeLimit),
|
|
136
|
-
headers: request.headers
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async function setResponse(res, response) {
|
|
140
|
-
for (const [key, value] of response.headers) {
|
|
141
|
-
try {
|
|
142
|
-
res.setHeader(
|
|
143
|
-
key,
|
|
144
|
-
key === "set-cookie" ? splitCookiesString(response.headers.get(key)) : value
|
|
145
|
-
);
|
|
146
|
-
} catch (error) {
|
|
147
|
-
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
148
|
-
res.writeHead(500).end(String(error));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
res.writeHead(response.status);
|
|
153
|
-
if (!response.body) {
|
|
154
|
-
res.end();
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (response.body.locked) {
|
|
158
|
-
res.end(
|
|
159
|
-
"Fatal error: Response body is locked. This can happen when the response was already read (for example through 'response.json()' or 'response.text()')."
|
|
160
|
-
);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const reader = response.body.getReader();
|
|
164
|
-
if (res.destroyed) {
|
|
165
|
-
reader.cancel();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const cancel = (error) => {
|
|
169
|
-
res.off("close", cancel);
|
|
170
|
-
res.off("error", cancel);
|
|
171
|
-
reader.cancel(error).catch(() => {
|
|
172
|
-
});
|
|
173
|
-
if (error)
|
|
174
|
-
res.destroy(error);
|
|
175
|
-
};
|
|
176
|
-
res.on("close", cancel);
|
|
177
|
-
res.on("error", cancel);
|
|
178
|
-
next();
|
|
179
|
-
async function next() {
|
|
180
|
-
try {
|
|
181
|
-
for (; ; ) {
|
|
182
|
-
const { done, value } = await reader.read();
|
|
183
|
-
if (done)
|
|
184
|
-
break;
|
|
185
|
-
if (!res.write(value)) {
|
|
186
|
-
res.once("drain", next);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
res.end();
|
|
191
|
-
} catch (error) {
|
|
192
|
-
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function toNodeHandler(handler) {
|
|
198
|
-
return async (req, res) => {
|
|
199
|
-
const protocol = req.connection?.encrypted ? "https" : "http";
|
|
200
|
-
const base = `${protocol}://${req.headers[":authority"] || req.headers.host}`;
|
|
201
|
-
const response = await handler(getRequest({ base, request: req }));
|
|
202
|
-
setResponse(res, response);
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export { getRequest, setResponse, toNodeHandler };
|
package/dist/client.d.mts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
-
import { R as Router, U as UnionToIntersection, b as Endpoint, H as HasRequiredKeys } from './shared/better-call.25f0dd59.mjs';
|
|
3
|
-
import 'zod';
|
|
4
|
-
import '@asteasolutions/zod-to-openapi/dist/zod-extensions';
|
|
5
|
-
import '@asteasolutions/zod-to-openapi';
|
|
6
|
-
import '@asteasolutions/zod-to-openapi/dist/openapi-registry';
|
|
7
|
-
import 'stream/web';
|
|
8
|
-
|
|
9
|
-
type HasRequired<T extends {
|
|
10
|
-
body?: any;
|
|
11
|
-
query?: any;
|
|
12
|
-
params?: any;
|
|
13
|
-
}> = HasRequiredKeys<T> extends true ? HasRequiredKeys<T["body"]> extends false ? HasRequiredKeys<T["query"]> extends false ? HasRequiredKeys<T["params"]> extends false ? false : true : true : true : true;
|
|
14
|
-
type InferContext<T> = T extends (ctx: infer Ctx) => any ? Ctx extends object ? Ctx : never : never;
|
|
15
|
-
interface ClientOptions extends BetterFetchOption {
|
|
16
|
-
baseURL: string;
|
|
17
|
-
}
|
|
18
|
-
type WithRequired<T, K> = T & {
|
|
19
|
-
[P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];
|
|
20
|
-
};
|
|
21
|
-
type RequiredOptionKeys<C extends {
|
|
22
|
-
body?: any;
|
|
23
|
-
query?: any;
|
|
24
|
-
params?: any;
|
|
25
|
-
}> = (undefined extends C["body"] ? {} : {
|
|
26
|
-
body: true;
|
|
27
|
-
}) & (undefined extends C["query"] ? {} : {
|
|
28
|
-
query: true;
|
|
29
|
-
}) & (undefined extends C["params"] ? {} : {
|
|
30
|
-
params: true;
|
|
31
|
-
});
|
|
32
|
-
declare const createClient: <R extends Router | Router["endpoints"]>(options: ClientOptions) => <OPT extends UnionToIntersection<(R extends {
|
|
33
|
-
endpoints: Record<string, Endpoint>;
|
|
34
|
-
} ? R["endpoints"] : R) extends {
|
|
35
|
-
[key: string]: infer T_1;
|
|
36
|
-
} ? T_1 extends Endpoint ? { [key in T_1["options"]["method"] extends "GET" ? T_1["path"] : `@${T_1["options"]["method"] extends string ? Lowercase<T_1["options"]["method"]> : never}${T_1["path"]}`]: T_1; } : {} : {}> extends infer T ? { [K_1 in keyof T]: UnionToIntersection<(R extends {
|
|
37
|
-
endpoints: Record<string, Endpoint>;
|
|
38
|
-
} ? R["endpoints"] : R) extends {
|
|
39
|
-
[key: string]: infer T_1;
|
|
40
|
-
} ? T_1 extends Endpoint ? { [key in T_1["options"]["method"] extends "GET" ? T_1["path"] : `@${T_1["options"]["method"] extends string ? Lowercase<T_1["options"]["method"]> : never}${T_1["path"]}`]: T_1; } : {} : {}>[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<BetterFetchOption<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>] : [BetterFetchOption<C["body"], C["query"], C["params"]>?]) => Promise<BetterFetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
|
|
41
|
-
|
|
42
|
-
export { type ClientOptions, type RequiredOptionKeys, createClient };
|
package/dist/client.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createFetch } from '@better-fetch/fetch';
|
|
2
|
-
|
|
3
|
-
const createClient = (options) => {
|
|
4
|
-
const fetch = createFetch(options);
|
|
5
|
-
return async (path, ...options2) => {
|
|
6
|
-
return await fetch(path, {
|
|
7
|
-
...options2[0]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { createClient };
|
package/dist/index.d.mts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { E as EndpointOptions, a as EndpointResponse, b as Endpoint, c as EndpointContext, I as InferUse, C as CookiePrefixOptions, d as CookieOptions } from './shared/better-call.25f0dd59.mjs';
|
|
2
|
-
export { A as APIError, j as Context, o as Cookie, p as CookieConstraint, H as HasRequiredKeys, m as InferResponse, g as Input, i as IsEmptyObject, J as JSONResponse, M as MergeObject, P as Prettify, h as RequiredKeysOf, R as Router, S as SignedCookie, U as UnionToIntersection, _ as _statusCode, e as createEndpoint, l as createGetHeader, f as createRouter, k as createSetHeader, n as fromError, q as parse, s as parseSigned, r as runValidation, t as serialize, u as serializeSigned } from './shared/better-call.25f0dd59.mjs';
|
|
3
|
-
import { BufferSource } from 'stream/web';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import '@asteasolutions/zod-to-openapi/dist/zod-extensions';
|
|
6
|
-
import '@asteasolutions/zod-to-openapi';
|
|
7
|
-
import '@asteasolutions/zod-to-openapi/dist/openapi-registry';
|
|
8
|
-
|
|
9
|
-
type MiddlewareHandler<Options extends EndpointOptions, R extends EndpointResponse> = (context: EndpointContext<any, Options>) => Promise<R>;
|
|
10
|
-
declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
|
|
11
|
-
declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
|
|
12
|
-
declare namespace createMiddleware {
|
|
13
|
-
var creator: typeof createMiddlewareCreator;
|
|
14
|
-
}
|
|
15
|
-
declare function createMiddlewareCreator<E extends {
|
|
16
|
-
use: Endpoint[];
|
|
17
|
-
}>(opts: E): <R extends EndpointResponse>(handler: <InferE extends EndpointContext<any, any>>(ctx: Omit<InferE, "context"> & {
|
|
18
|
-
context: InferUse<E["use"]>;
|
|
19
|
-
}) => Promise<R>) => Endpoint<MiddlewareHandler<{
|
|
20
|
-
method: "*";
|
|
21
|
-
use: Endpoint[];
|
|
22
|
-
}, R>, {
|
|
23
|
-
method: "*";
|
|
24
|
-
use: Endpoint[];
|
|
25
|
-
}>;
|
|
26
|
-
|
|
27
|
-
declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
|
|
28
|
-
declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
|
|
29
|
-
declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
|
|
30
|
-
declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
|
|
31
|
-
|
|
32
|
-
export { CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointResponse, createMiddleware, getCookie, getSignedCookie, setCookie, setSignedCookie };
|