better-call 0.3.3 → 1.0.0-beta.4

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/index.d.cts CHANGED
@@ -1,127 +1,5 @@
1
- import { E as Endpoint, a as EndpointOptions, b as EndpointResponse, P as Prettify, C as Context, I as InferUse, c as ContextTools, H as HasRequiredKeys, M as Method, d as Handler, e as InferBody, f as InferRequest, g as InferHeaders, h as InferUseOptions, R as Router, i as CookiePrefixOptions, j as CookieOptions } from './router-DtwxtvxY.cjs';
2
- export { A as APIError, w as Cookie, x as CookieConstraint, v as EndpointBody, r as InferMethod, u as InferParam, p as InferParamPath, q as InferParamWildCard, t as InferQuery, o as OpenAPIParameter, O as OpenAPISchemaType, G as RequiredKeysOf, k as RouterConfig, S as SignedCookie, U as UnionToIntersection, l as createRouter, m as getBody, J as json, y as parse, z as parseSigned, B as serialize, D as serializeSigned, s as shouldSerialize, F as signCookieValue, n as statusCode } from './router-DtwxtvxY.cjs';
3
- import { IncomingMessage, ServerResponse } from 'node:http';
4
- import 'zod';
1
+ export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, t as InferBody, I as InferBodyInput, B as InferHeaders, D as InferHeadersInput, x as InferInputMethod, w as InferMethod, G as InferMiddlewareBody, J as InferMiddlewareQuery, y as InferParam, v as InferQuery, u as InferQueryInput, z as InferRequest, F as InferUse, K as InputContext, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, j as Router, R as RouterConfig, S as Status, _ as _statusCode, c as createEndpoint, L as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-CyNMWgsC.cjs';
5
2
 
6
- interface EndpointConfig {
7
- /**
8
- * Throw when the response isn't in 200 range
9
- */
10
- throwOnError?: boolean;
11
- }
12
- declare function createEndpointCreator<E extends {
13
- use?: Endpoint[];
14
- }>(opts?: E): <Path extends string, Opts extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Opts, handler: (ctx: Prettify<Context<Path, Opts> & InferUse<Opts["use"]> & InferUse<E["use"]> & Omit<ContextTools, "_flag">>) => Promise<R>) => {
15
- <C extends HasRequiredKeys<Context<Path, Opts>> extends true ? [Context<Path, Opts>] : [(Context<Path, Opts> | undefined)?]>(...ctx: C): Promise<C extends [{
16
- asResponse: true;
17
- }] ? Response : R extends {
18
- _flag: "json";
19
- } ? R extends {
20
- body: infer B;
21
- } ? B : null : Awaited<R>>;
22
- path: Path;
23
- options: Opts;
24
- method: Method | Method[];
25
- headers: Headers;
26
- };
27
- declare function createEndpoint<Path extends string, Opts extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Opts, handler: Handler<Path, Opts, R>): {
28
- <C extends HasRequiredKeys<Context<Path, Opts>> extends true ? [Context<Path, Opts>] : [Context<Path, Opts>?]>(...ctx: C): Promise<C extends [{
29
- asResponse: true;
30
- }] ? Response : R extends {
31
- _flag: "json";
32
- } ? R extends {
33
- body: infer B;
34
- } ? B : null : Awaited<R>>;
35
- path: Path;
36
- options: Opts;
37
- method: Method | Method[];
38
- headers: Headers;
39
- };
3
+ declare function toResponse(data?: any, init?: ResponseInit): Response;
40
4
 
41
- type MiddlewareHandler<Opts extends EndpointOptions, R extends EndpointResponse, Extra extends Record<string, any> = {}> = (ctx: Prettify<InferBody<Opts> & InferRequest<Opts> & InferHeaders<Opts> & {
42
- params?: Record<string, string>;
43
- query?: Record<string, string>;
44
- } & ContextTools> & Extra) => Promise<R>;
45
- declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<Handler<string, Opts, R>, Opts>;
46
- declare function createMiddleware<Opts extends Omit<EndpointOptions, "method">, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts & {
47
- method: "*";
48
- }, R>): Endpoint<Handler<string, Opts & {
49
- method: "*";
50
- }, R>, Opts & {
51
- method: "*";
52
- }>;
53
- declare const createMiddlewareCreator: <E extends {
54
- use?: Endpoint[];
55
- }>(opts?: E) => {
56
- <Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: (ctx: InferBody<Opts, Opts["body"] & (undefined extends InferUseOptions<Opts>["body"] ? {} : InferUseOptions<Opts>["body"])> & InferUse<E["use"]> & InferRequest<Opts, Opts["requireRequest"]> & InferHeaders<Opts, Opts["requireHeaders"]> & {
57
- params?: Record<string, string>;
58
- query?: Record<string, string>;
59
- } & ContextTools extends infer T ? { [key in keyof T]: (InferBody<Opts, Opts["body"] & (undefined extends InferUseOptions<Opts>["body"] ? {} : InferUseOptions<Opts>["body"])> & InferUse<E["use"]> & InferRequest<Opts, Opts["requireRequest"]> & InferHeaders<Opts, Opts["requireHeaders"]> & {
60
- params?: Record<string, string>;
61
- query?: Record<string, string>;
62
- } & ContextTools)[key]; } : never) => Promise<R>): Endpoint<Handler<string, Opts, R>, Opts>;
63
- <Opts extends Omit<EndpointOptions, "method">, R_1 extends EndpointResponse>(optionsOrHandler: Opts, handler: (ctx: InferBody<Opts & {
64
- method: "*";
65
- }, (Opts & {
66
- method: "*";
67
- })["body"] & (undefined extends InferUseOptions<Opts & {
68
- method: "*";
69
- }>["body"] ? {} : InferUseOptions<Opts & {
70
- method: "*";
71
- }>["body"])> & InferUse<E["use"]> & InferRequest<Opts & {
72
- method: "*";
73
- }, (Opts & {
74
- method: "*";
75
- })["requireRequest"]> & InferHeaders<Opts & {
76
- method: "*";
77
- }, (Opts & {
78
- method: "*";
79
- })["requireHeaders"]> & {
80
- params?: Record<string, string>;
81
- query?: Record<string, string>;
82
- } & ContextTools extends infer T ? { [key in keyof T]: (InferBody<Opts & {
83
- method: "*";
84
- }, (Opts & {
85
- method: "*";
86
- })["body"] & (undefined extends InferUseOptions<Opts & {
87
- method: "*";
88
- }>["body"] ? {} : InferUseOptions<Opts & {
89
- method: "*";
90
- }>["body"])> & InferUse<E["use"]> & InferRequest<Opts & {
91
- method: "*";
92
- }, (Opts & {
93
- method: "*";
94
- })["requireRequest"]> & InferHeaders<Opts & {
95
- method: "*";
96
- }, (Opts & {
97
- method: "*";
98
- })["requireHeaders"]> & {
99
- params?: Record<string, string>;
100
- query?: Record<string, string>;
101
- } & ContextTools)[key]; } : never) => Promise<R_1>): Endpoint<Handler<string, Opts & {
102
- method: "*";
103
- }, R_1>, Opts & {
104
- method: "*";
105
- }>;
106
- };
107
- type Middleware<Opts extends EndpointOptions = EndpointOptions, R extends EndpointResponse = EndpointResponse> = (opts: Opts, handler: (ctx: {
108
- body?: InferBody<Opts>;
109
- params?: Record<string, string>;
110
- query?: Record<string, string>;
111
- }) => Promise<R>) => Endpoint;
112
-
113
- declare function getRequest({ request, base, bodySizeLimit, }: {
114
- base: string;
115
- bodySizeLimit?: number;
116
- request: IncomingMessage;
117
- }): Request;
118
- declare function setResponse(res: ServerResponse, response: Response): Promise<void>;
119
-
120
- declare function toNodeHandler(handler: Router["handler"]): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
121
-
122
- declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
123
- declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
124
- declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
125
- declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
126
-
127
- export { Context, ContextTools, CookieOptions, CookiePrefixOptions, Endpoint, type EndpointConfig, EndpointOptions, EndpointResponse, Handler, HasRequiredKeys, InferBody, InferHeaders, InferRequest, InferUse, InferUseOptions, Method, type Middleware, type MiddlewareHandler, Prettify, Router, createEndpoint, createEndpointCreator, createMiddleware, createMiddlewareCreator, getCookie, getRequest, getSignedCookie, setCookie, setResponse, setSignedCookie, toNodeHandler };
5
+ export { toResponse };
package/dist/index.d.ts CHANGED
@@ -1,127 +1,5 @@
1
- import { E as Endpoint, a as EndpointOptions, b as EndpointResponse, P as Prettify, C as Context, I as InferUse, c as ContextTools, H as HasRequiredKeys, M as Method, d as Handler, e as InferBody, f as InferRequest, g as InferHeaders, h as InferUseOptions, R as Router, i as CookiePrefixOptions, j as CookieOptions } from './router-DtwxtvxY.js';
2
- export { A as APIError, w as Cookie, x as CookieConstraint, v as EndpointBody, r as InferMethod, u as InferParam, p as InferParamPath, q as InferParamWildCard, t as InferQuery, o as OpenAPIParameter, O as OpenAPISchemaType, G as RequiredKeysOf, k as RouterConfig, S as SignedCookie, U as UnionToIntersection, l as createRouter, m as getBody, J as json, y as parse, z as parseSigned, B as serialize, D as serializeSigned, s as shouldSerialize, F as signCookieValue, n as statusCode } from './router-DtwxtvxY.js';
3
- import { IncomingMessage, ServerResponse } from 'node:http';
4
- import 'zod';
1
+ export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, t as InferBody, I as InferBodyInput, B as InferHeaders, D as InferHeadersInput, x as InferInputMethod, w as InferMethod, G as InferMiddlewareBody, J as InferMiddlewareQuery, y as InferParam, v as InferQuery, u as InferQueryInput, z as InferRequest, F as InferUse, K as InputContext, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, j as Router, R as RouterConfig, S as Status, _ as _statusCode, c as createEndpoint, L as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-CyNMWgsC.js';
5
2
 
6
- interface EndpointConfig {
7
- /**
8
- * Throw when the response isn't in 200 range
9
- */
10
- throwOnError?: boolean;
11
- }
12
- declare function createEndpointCreator<E extends {
13
- use?: Endpoint[];
14
- }>(opts?: E): <Path extends string, Opts extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Opts, handler: (ctx: Prettify<Context<Path, Opts> & InferUse<Opts["use"]> & InferUse<E["use"]> & Omit<ContextTools, "_flag">>) => Promise<R>) => {
15
- <C extends HasRequiredKeys<Context<Path, Opts>> extends true ? [Context<Path, Opts>] : [(Context<Path, Opts> | undefined)?]>(...ctx: C): Promise<C extends [{
16
- asResponse: true;
17
- }] ? Response : R extends {
18
- _flag: "json";
19
- } ? R extends {
20
- body: infer B;
21
- } ? B : null : Awaited<R>>;
22
- path: Path;
23
- options: Opts;
24
- method: Method | Method[];
25
- headers: Headers;
26
- };
27
- declare function createEndpoint<Path extends string, Opts extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Opts, handler: Handler<Path, Opts, R>): {
28
- <C extends HasRequiredKeys<Context<Path, Opts>> extends true ? [Context<Path, Opts>] : [Context<Path, Opts>?]>(...ctx: C): Promise<C extends [{
29
- asResponse: true;
30
- }] ? Response : R extends {
31
- _flag: "json";
32
- } ? R extends {
33
- body: infer B;
34
- } ? B : null : Awaited<R>>;
35
- path: Path;
36
- options: Opts;
37
- method: Method | Method[];
38
- headers: Headers;
39
- };
3
+ declare function toResponse(data?: any, init?: ResponseInit): Response;
40
4
 
41
- type MiddlewareHandler<Opts extends EndpointOptions, R extends EndpointResponse, Extra extends Record<string, any> = {}> = (ctx: Prettify<InferBody<Opts> & InferRequest<Opts> & InferHeaders<Opts> & {
42
- params?: Record<string, string>;
43
- query?: Record<string, string>;
44
- } & ContextTools> & Extra) => Promise<R>;
45
- declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<Handler<string, Opts, R>, Opts>;
46
- declare function createMiddleware<Opts extends Omit<EndpointOptions, "method">, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts & {
47
- method: "*";
48
- }, R>): Endpoint<Handler<string, Opts & {
49
- method: "*";
50
- }, R>, Opts & {
51
- method: "*";
52
- }>;
53
- declare const createMiddlewareCreator: <E extends {
54
- use?: Endpoint[];
55
- }>(opts?: E) => {
56
- <Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: (ctx: InferBody<Opts, Opts["body"] & (undefined extends InferUseOptions<Opts>["body"] ? {} : InferUseOptions<Opts>["body"])> & InferUse<E["use"]> & InferRequest<Opts, Opts["requireRequest"]> & InferHeaders<Opts, Opts["requireHeaders"]> & {
57
- params?: Record<string, string>;
58
- query?: Record<string, string>;
59
- } & ContextTools extends infer T ? { [key in keyof T]: (InferBody<Opts, Opts["body"] & (undefined extends InferUseOptions<Opts>["body"] ? {} : InferUseOptions<Opts>["body"])> & InferUse<E["use"]> & InferRequest<Opts, Opts["requireRequest"]> & InferHeaders<Opts, Opts["requireHeaders"]> & {
60
- params?: Record<string, string>;
61
- query?: Record<string, string>;
62
- } & ContextTools)[key]; } : never) => Promise<R>): Endpoint<Handler<string, Opts, R>, Opts>;
63
- <Opts extends Omit<EndpointOptions, "method">, R_1 extends EndpointResponse>(optionsOrHandler: Opts, handler: (ctx: InferBody<Opts & {
64
- method: "*";
65
- }, (Opts & {
66
- method: "*";
67
- })["body"] & (undefined extends InferUseOptions<Opts & {
68
- method: "*";
69
- }>["body"] ? {} : InferUseOptions<Opts & {
70
- method: "*";
71
- }>["body"])> & InferUse<E["use"]> & InferRequest<Opts & {
72
- method: "*";
73
- }, (Opts & {
74
- method: "*";
75
- })["requireRequest"]> & InferHeaders<Opts & {
76
- method: "*";
77
- }, (Opts & {
78
- method: "*";
79
- })["requireHeaders"]> & {
80
- params?: Record<string, string>;
81
- query?: Record<string, string>;
82
- } & ContextTools extends infer T ? { [key in keyof T]: (InferBody<Opts & {
83
- method: "*";
84
- }, (Opts & {
85
- method: "*";
86
- })["body"] & (undefined extends InferUseOptions<Opts & {
87
- method: "*";
88
- }>["body"] ? {} : InferUseOptions<Opts & {
89
- method: "*";
90
- }>["body"])> & InferUse<E["use"]> & InferRequest<Opts & {
91
- method: "*";
92
- }, (Opts & {
93
- method: "*";
94
- })["requireRequest"]> & InferHeaders<Opts & {
95
- method: "*";
96
- }, (Opts & {
97
- method: "*";
98
- })["requireHeaders"]> & {
99
- params?: Record<string, string>;
100
- query?: Record<string, string>;
101
- } & ContextTools)[key]; } : never) => Promise<R_1>): Endpoint<Handler<string, Opts & {
102
- method: "*";
103
- }, R_1>, Opts & {
104
- method: "*";
105
- }>;
106
- };
107
- type Middleware<Opts extends EndpointOptions = EndpointOptions, R extends EndpointResponse = EndpointResponse> = (opts: Opts, handler: (ctx: {
108
- body?: InferBody<Opts>;
109
- params?: Record<string, string>;
110
- query?: Record<string, string>;
111
- }) => Promise<R>) => Endpoint;
112
-
113
- declare function getRequest({ request, base, bodySizeLimit, }: {
114
- base: string;
115
- bodySizeLimit?: number;
116
- request: IncomingMessage;
117
- }): Request;
118
- declare function setResponse(res: ServerResponse, response: Response): Promise<void>;
119
-
120
- declare function toNodeHandler(handler: Router["handler"]): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
121
-
122
- declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
123
- declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
124
- declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
125
- declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
126
-
127
- export { Context, ContextTools, CookieOptions, CookiePrefixOptions, Endpoint, type EndpointConfig, EndpointOptions, EndpointResponse, Handler, HasRequiredKeys, InferBody, InferHeaders, InferRequest, InferUse, InferUseOptions, Method, type Middleware, type MiddlewareHandler, Prettify, Router, createEndpoint, createEndpointCreator, createMiddleware, createMiddlewareCreator, getCookie, getRequest, getSignedCookie, setCookie, setResponse, setSignedCookie, toNodeHandler };
5
+ export { toResponse };