better-call 0.2.11 → 0.2.13-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/index.d.cts CHANGED
@@ -1,127 +1,15 @@
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-DIrNt-mY.cjs';
2
- export { A as APIError, u as Cookie, v as CookieConstraint, t as EndpointBody, p as InferMethod, r as InferParam, n as InferParamPath, o as InferParamWildCard, q as InferQuery, S as SignedCookie, k as createRouter, l as getBody, w as parse, x as parseSigned, y as serialize, z as serializeSigned, s as shouldSerialize, m as statusCode } from './router-DIrNt-mY.cjs';
3
- import { IncomingMessage, ServerResponse } from 'node:http';
1
+ import { E as EndpointOptions, a as EndpointResponse, b as Endpoint, c as EndpointContext, C as CookiePrefixOptions, d as CookieOptions } from './shared/better-call.342be6c5.cjs';
2
+ export { i as Context, o as Cookie, p as CookieConstraint, H as HasRequiredKeys, l as InferResponse, I as Input, h as IsEmptyObject, J as JSONResponse, P as Prettify, g as RequiredKeysOf, R as Router, S as SignedCookie, U as UnionToIntersection, e as createEndpoint, k as createGetHeader, m as createJSON, f as createRouter, j as createSetHeader, n as fromError, q as parse, s as parseSigned, r as runValidation, t as serialize, u as serializeSigned } from './shared/better-call.342be6c5.cjs';
3
+ import { BufferSource } from 'stream/web';
4
4
  import 'zod';
5
5
 
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
- };
40
-
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>;
6
+ type MiddlewareHandler<Options extends EndpointOptions, R extends EndpointResponse> = (context: EndpointContext<any, Options>) => Promise<R>;
7
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
8
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
121
9
 
122
10
  declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
123
11
  declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
124
12
  declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
125
13
  declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
126
14
 
127
- export { Context, ContextTools, CookieOptions, CookiePrefixOptions, Endpoint, type EndpointConfig, EndpointOptions, EndpointResponse, Handler, InferBody, InferHeaders, InferRequest, InferUse, InferUseOptions, Method, type Middleware, type MiddlewareHandler, Prettify, Router, createEndpoint, createEndpointCreator, createMiddleware, createMiddlewareCreator, getCookie, getRequest, getSignedCookie, setCookie, setResponse, setSignedCookie, toNodeHandler };
15
+ export { CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointResponse, createMiddleware, getCookie, getSignedCookie, setCookie, setSignedCookie };
@@ -0,0 +1,15 @@
1
+ import { E as EndpointOptions, a as EndpointResponse, b as Endpoint, c as EndpointContext, C as CookiePrefixOptions, d as CookieOptions } from './shared/better-call.342be6c5.mjs';
2
+ export { i as Context, o as Cookie, p as CookieConstraint, H as HasRequiredKeys, l as InferResponse, I as Input, h as IsEmptyObject, J as JSONResponse, P as Prettify, g as RequiredKeysOf, R as Router, S as SignedCookie, U as UnionToIntersection, e as createEndpoint, k as createGetHeader, m as createJSON, f as createRouter, j as createSetHeader, n as fromError, q as parse, s as parseSigned, r as runValidation, t as serialize, u as serializeSigned } from './shared/better-call.342be6c5.mjs';
3
+ import { BufferSource } from 'stream/web';
4
+ import 'zod';
5
+
6
+ type MiddlewareHandler<Options extends EndpointOptions, R extends EndpointResponse> = (context: EndpointContext<any, Options>) => Promise<R>;
7
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
8
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
9
+
10
+ declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
11
+ declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
12
+ declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
13
+ declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
14
+
15
+ export { CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointResponse, createMiddleware, getCookie, getSignedCookie, setCookie, setSignedCookie };
package/dist/index.d.ts CHANGED
@@ -1,127 +1,15 @@
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-DIrNt-mY.js';
2
- export { A as APIError, u as Cookie, v as CookieConstraint, t as EndpointBody, p as InferMethod, r as InferParam, n as InferParamPath, o as InferParamWildCard, q as InferQuery, S as SignedCookie, k as createRouter, l as getBody, w as parse, x as parseSigned, y as serialize, z as serializeSigned, s as shouldSerialize, m as statusCode } from './router-DIrNt-mY.js';
3
- import { IncomingMessage, ServerResponse } from 'node:http';
1
+ import { E as EndpointOptions, a as EndpointResponse, b as Endpoint, c as EndpointContext, C as CookiePrefixOptions, d as CookieOptions } from './shared/better-call.342be6c5.js';
2
+ export { i as Context, o as Cookie, p as CookieConstraint, H as HasRequiredKeys, l as InferResponse, I as Input, h as IsEmptyObject, J as JSONResponse, P as Prettify, g as RequiredKeysOf, R as Router, S as SignedCookie, U as UnionToIntersection, e as createEndpoint, k as createGetHeader, m as createJSON, f as createRouter, j as createSetHeader, n as fromError, q as parse, s as parseSigned, r as runValidation, t as serialize, u as serializeSigned } from './shared/better-call.342be6c5.js';
3
+ import { BufferSource } from 'stream/web';
4
4
  import 'zod';
5
5
 
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
- };
40
-
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>;
6
+ type MiddlewareHandler<Options extends EndpointOptions, R extends EndpointResponse> = (context: EndpointContext<any, Options>) => Promise<R>;
7
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
8
+ declare function createMiddleware<Opts extends EndpointOptions, R extends EndpointResponse>(optionsOrHandler: Opts, handler: MiddlewareHandler<Opts, R>): Endpoint<MiddlewareHandler<Opts, R>, Opts>;
121
9
 
122
10
  declare const getCookie: (cookie: string, key: string, prefix?: CookiePrefixOptions) => string | undefined;
123
11
  declare const setCookie: (header: Headers, name: string, value: string, opt?: CookieOptions) => void;
124
12
  declare const setSignedCookie: (header: Headers, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
125
13
  declare const getSignedCookie: (header: Headers, secret: string, key: string, prefix?: CookiePrefixOptions) => Promise<string | false | undefined>;
126
14
 
127
- export { Context, ContextTools, CookieOptions, CookiePrefixOptions, Endpoint, type EndpointConfig, EndpointOptions, EndpointResponse, Handler, InferBody, InferHeaders, InferRequest, InferUse, InferUseOptions, Method, type Middleware, type MiddlewareHandler, Prettify, Router, createEndpoint, createEndpointCreator, createMiddleware, createMiddlewareCreator, getCookie, getRequest, getSignedCookie, setCookie, setResponse, setSignedCookie, toNodeHandler };
15
+ export { CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointResponse, createMiddleware, getCookie, getSignedCookie, setCookie, setSignedCookie };