better-call 1.1.5 → 1.1.7
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 +35 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/adapters/node/request.cjs +125 -0
- package/dist/adapters/node/request.cjs.map +1 -0
- package/dist/{node.d.ts → adapters/node/request.d.cts} +2 -6
- package/dist/adapters/node/request.d.mts +16 -0
- package/dist/{node.js → adapters/node/request.mjs} +2 -13
- package/dist/adapters/node/request.mjs.map +1 -0
- package/dist/client.cjs +8 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +12 -13
- package/dist/client.d.mts +53 -0
- package/dist/client.mjs +14 -0
- package/dist/client.mjs.map +1 -0
- package/dist/context.cjs +102 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +340 -0
- package/dist/context.d.mts +340 -0
- package/dist/context.mjs +102 -0
- package/dist/context.mjs.map +1 -0
- package/dist/cookies.cjs +87 -0
- package/dist/cookies.cjs.map +1 -0
- package/dist/cookies.d.cts +103 -0
- package/dist/cookies.d.mts +103 -0
- package/dist/cookies.mjs +84 -0
- package/dist/cookies.mjs.map +1 -0
- package/dist/crypto.cjs +39 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.mjs +36 -0
- package/dist/crypto.mjs.map +1 -0
- package/dist/endpoint.cjs +70 -0
- package/dist/endpoint.cjs.map +1 -0
- package/dist/endpoint.d.cts +428 -0
- package/dist/endpoint.d.mts +428 -0
- package/dist/endpoint.mjs +70 -0
- package/dist/endpoint.mjs.map +1 -0
- package/dist/error.cjs +141 -0
- package/dist/error.cjs.map +1 -0
- package/dist/error.d.cts +103 -0
- package/dist/error.d.mts +103 -0
- package/dist/error.mjs +135 -0
- package/dist/error.mjs.map +1 -0
- package/dist/helper.d.cts +12 -0
- package/dist/helper.d.mts +12 -0
- package/dist/index.cjs +26 -968
- package/dist/index.d.cts +11 -14
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +10 -0
- package/dist/middleware.cjs +39 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +123 -0
- package/dist/middleware.d.mts +123 -0
- package/dist/middleware.mjs +39 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/node.cjs +4 -151
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +2 -13
- package/dist/node.d.mts +9 -0
- package/dist/node.mjs +15 -0
- package/dist/node.mjs.map +1 -0
- package/dist/openapi.cjs +191 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +113 -0
- package/dist/openapi.d.mts +113 -0
- package/dist/openapi.mjs +189 -0
- package/dist/openapi.mjs.map +1 -0
- package/dist/router.cjs +117 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +4 -1242
- package/dist/router.d.mts +97 -0
- package/dist/router.mjs +116 -0
- package/dist/router.mjs.map +1 -0
- package/dist/standard-schema.d.cts +59 -0
- package/dist/standard-schema.d.mts +59 -0
- package/dist/to-response.cjs +96 -0
- package/dist/to-response.cjs.map +1 -0
- package/dist/to-response.d.cts +12 -0
- package/dist/to-response.d.mts +12 -0
- package/dist/to-response.mjs +96 -0
- package/dist/to-response.mjs.map +1 -0
- package/dist/utils.cjs +77 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.mjs +74 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/validator.cjs +58 -0
- package/dist/validator.cjs.map +1 -0
- package/dist/validator.mjs +57 -0
- package/dist/validator.mjs.map +1 -0
- package/package.json +23 -13
- package/dist/client.d.ts +0 -54
- package/dist/client.js +0 -13
- package/dist/client.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -951
- package/dist/index.js.map +0 -1
- package/dist/node.js.map +0 -1
- package/dist/router.d.ts +0 -1335
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { InferParamPath, InferParamWildCard, IsEmptyObject, Prettify, UnionToIntersection } from "./helper.cjs";
|
|
2
|
+
import { StandardSchemaV1 } from "./standard-schema.cjs";
|
|
3
|
+
import { Status, statusCodes } from "./error.cjs";
|
|
4
|
+
import { CookieOptions, CookiePrefixOptions } from "./cookies.cjs";
|
|
5
|
+
import { Middleware, MiddlewareOptions } from "./middleware.cjs";
|
|
6
|
+
import { EndpointOptions } from "./endpoint.cjs";
|
|
7
|
+
|
|
8
|
+
//#region src/context.d.ts
|
|
9
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
10
|
+
type Method = HTTPMethod | "*";
|
|
11
|
+
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = (Options["metadata"] extends {
|
|
12
|
+
$Infer: {
|
|
13
|
+
body: infer B;
|
|
14
|
+
};
|
|
15
|
+
} ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined)> = undefined extends Body ? {
|
|
16
|
+
body?: Body;
|
|
17
|
+
} : {
|
|
18
|
+
body: Body;
|
|
19
|
+
};
|
|
20
|
+
type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
21
|
+
$Infer: {
|
|
22
|
+
body: infer Body;
|
|
23
|
+
};
|
|
24
|
+
} ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
|
|
25
|
+
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = (Options["metadata"] extends {
|
|
26
|
+
$Infer: {
|
|
27
|
+
query: infer Query;
|
|
28
|
+
};
|
|
29
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined)> = undefined extends Query ? {
|
|
30
|
+
query?: Query;
|
|
31
|
+
} : {
|
|
32
|
+
query: Query;
|
|
33
|
+
};
|
|
34
|
+
type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
35
|
+
$Infer: {
|
|
36
|
+
query: infer Query;
|
|
37
|
+
};
|
|
38
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
|
|
39
|
+
type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
|
|
40
|
+
type InferInputMethod<Options extends EndpointOptions, Method$1 = (Options["method"] extends Array<any> ? Options["method"][number] | undefined : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined)> = undefined extends Method$1 ? {
|
|
41
|
+
method?: Method$1;
|
|
42
|
+
} : {
|
|
43
|
+
method: Method$1;
|
|
44
|
+
};
|
|
45
|
+
type InferParam<Path extends string> = [Path] extends [never] ? Record<string, any> | undefined : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
46
|
+
type InferParamInput<Path extends string> = [Path] extends [never] ? {
|
|
47
|
+
params?: Record<string, any>;
|
|
48
|
+
} : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
|
|
49
|
+
params?: Record<string, any>;
|
|
50
|
+
} : {
|
|
51
|
+
params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
52
|
+
};
|
|
53
|
+
type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
|
|
54
|
+
type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
|
|
55
|
+
request: Request;
|
|
56
|
+
} : {
|
|
57
|
+
request?: Request;
|
|
58
|
+
};
|
|
59
|
+
type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
|
|
60
|
+
type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
|
|
61
|
+
headers: HeadersInit;
|
|
62
|
+
} : {
|
|
63
|
+
headers?: HeadersInit;
|
|
64
|
+
};
|
|
65
|
+
type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
|
|
66
|
+
type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
|
|
67
|
+
type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
|
|
68
|
+
type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
69
|
+
asResponse?: boolean;
|
|
70
|
+
returnHeaders?: boolean;
|
|
71
|
+
returnStatus?: boolean;
|
|
72
|
+
use?: Middleware[];
|
|
73
|
+
path?: string;
|
|
74
|
+
};
|
|
75
|
+
declare const createInternalContext: (context: InputContext<any, any>, {
|
|
76
|
+
options,
|
|
77
|
+
path
|
|
78
|
+
}: {
|
|
79
|
+
options: EndpointOptions;
|
|
80
|
+
path?: string;
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
body: any;
|
|
83
|
+
query: any;
|
|
84
|
+
path: string;
|
|
85
|
+
context: {};
|
|
86
|
+
returned: any;
|
|
87
|
+
headers: HeadersInit | undefined;
|
|
88
|
+
request: Request | undefined;
|
|
89
|
+
params: Record<string, any> | undefined;
|
|
90
|
+
method: any;
|
|
91
|
+
setHeader: (key: string, value: string) => void;
|
|
92
|
+
getHeader: (key: string) => string | null;
|
|
93
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
94
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
95
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
96
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
97
|
+
redirect: (url: string) => {
|
|
98
|
+
status: keyof typeof statusCodes | Status;
|
|
99
|
+
body: ({
|
|
100
|
+
message?: string;
|
|
101
|
+
code?: string;
|
|
102
|
+
cause?: unknown;
|
|
103
|
+
} & Record<string, any>) | undefined;
|
|
104
|
+
headers: HeadersInit;
|
|
105
|
+
statusCode: number;
|
|
106
|
+
name: string;
|
|
107
|
+
message: string;
|
|
108
|
+
stack?: string;
|
|
109
|
+
cause?: unknown;
|
|
110
|
+
} & {
|
|
111
|
+
errorStack: string | undefined;
|
|
112
|
+
};
|
|
113
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
114
|
+
message?: string;
|
|
115
|
+
code?: string;
|
|
116
|
+
} | undefined, headers?: HeadersInit) => {
|
|
117
|
+
status: keyof typeof statusCodes | Status;
|
|
118
|
+
body: ({
|
|
119
|
+
message?: string;
|
|
120
|
+
code?: string;
|
|
121
|
+
cause?: unknown;
|
|
122
|
+
} & Record<string, any>) | undefined;
|
|
123
|
+
headers: HeadersInit;
|
|
124
|
+
statusCode: number;
|
|
125
|
+
name: string;
|
|
126
|
+
message: string;
|
|
127
|
+
stack?: string;
|
|
128
|
+
cause?: unknown;
|
|
129
|
+
} & {
|
|
130
|
+
errorStack: string | undefined;
|
|
131
|
+
};
|
|
132
|
+
setStatus: (status: Status) => void;
|
|
133
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
134
|
+
status?: number;
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
response?: Response;
|
|
137
|
+
body?: Record<string, any>;
|
|
138
|
+
} | Response) => Record<string, any>;
|
|
139
|
+
responseHeaders: Headers;
|
|
140
|
+
responseStatus: Status | undefined;
|
|
141
|
+
asResponse?: boolean;
|
|
142
|
+
returnHeaders?: boolean;
|
|
143
|
+
returnStatus?: boolean;
|
|
144
|
+
use?: Middleware[];
|
|
145
|
+
} | {
|
|
146
|
+
body: any;
|
|
147
|
+
query: any;
|
|
148
|
+
path: string;
|
|
149
|
+
context: {};
|
|
150
|
+
returned: any;
|
|
151
|
+
headers: HeadersInit | undefined;
|
|
152
|
+
request: Request | undefined;
|
|
153
|
+
params: Record<string, any> | undefined;
|
|
154
|
+
method: any;
|
|
155
|
+
setHeader: (key: string, value: string) => void;
|
|
156
|
+
getHeader: (key: string) => string | null;
|
|
157
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
158
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
159
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
160
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
161
|
+
redirect: (url: string) => {
|
|
162
|
+
status: keyof typeof statusCodes | Status;
|
|
163
|
+
body: ({
|
|
164
|
+
message?: string;
|
|
165
|
+
code?: string;
|
|
166
|
+
cause?: unknown;
|
|
167
|
+
} & Record<string, any>) | undefined;
|
|
168
|
+
headers: HeadersInit;
|
|
169
|
+
statusCode: number;
|
|
170
|
+
name: string;
|
|
171
|
+
message: string;
|
|
172
|
+
stack?: string;
|
|
173
|
+
cause?: unknown;
|
|
174
|
+
} & {
|
|
175
|
+
errorStack: string | undefined;
|
|
176
|
+
};
|
|
177
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
178
|
+
message?: string;
|
|
179
|
+
code?: string;
|
|
180
|
+
} | undefined, headers?: HeadersInit) => {
|
|
181
|
+
status: keyof typeof statusCodes | Status;
|
|
182
|
+
body: ({
|
|
183
|
+
message?: string;
|
|
184
|
+
code?: string;
|
|
185
|
+
cause?: unknown;
|
|
186
|
+
} & Record<string, any>) | undefined;
|
|
187
|
+
headers: HeadersInit;
|
|
188
|
+
statusCode: number;
|
|
189
|
+
name: string;
|
|
190
|
+
message: string;
|
|
191
|
+
stack?: string;
|
|
192
|
+
cause?: unknown;
|
|
193
|
+
} & {
|
|
194
|
+
errorStack: string | undefined;
|
|
195
|
+
};
|
|
196
|
+
setStatus: (status: Status) => void;
|
|
197
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
198
|
+
status?: number;
|
|
199
|
+
headers?: Record<string, string>;
|
|
200
|
+
response?: Response;
|
|
201
|
+
body?: Record<string, any>;
|
|
202
|
+
} | Response) => Record<string, any>;
|
|
203
|
+
responseHeaders: Headers;
|
|
204
|
+
responseStatus: Status | undefined;
|
|
205
|
+
asResponse?: boolean;
|
|
206
|
+
returnHeaders?: boolean;
|
|
207
|
+
returnStatus?: boolean;
|
|
208
|
+
use?: Middleware[];
|
|
209
|
+
} | {
|
|
210
|
+
body: any;
|
|
211
|
+
query: any;
|
|
212
|
+
path: string;
|
|
213
|
+
context: {};
|
|
214
|
+
returned: any;
|
|
215
|
+
headers: HeadersInit | undefined;
|
|
216
|
+
request: Request | undefined;
|
|
217
|
+
params: Record<string, any> | undefined;
|
|
218
|
+
method: any;
|
|
219
|
+
setHeader: (key: string, value: string) => void;
|
|
220
|
+
getHeader: (key: string) => string | null;
|
|
221
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
222
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
223
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
224
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
225
|
+
redirect: (url: string) => {
|
|
226
|
+
status: keyof typeof statusCodes | Status;
|
|
227
|
+
body: ({
|
|
228
|
+
message?: string;
|
|
229
|
+
code?: string;
|
|
230
|
+
cause?: unknown;
|
|
231
|
+
} & Record<string, any>) | undefined;
|
|
232
|
+
headers: HeadersInit;
|
|
233
|
+
statusCode: number;
|
|
234
|
+
name: string;
|
|
235
|
+
message: string;
|
|
236
|
+
stack?: string;
|
|
237
|
+
cause?: unknown;
|
|
238
|
+
} & {
|
|
239
|
+
errorStack: string | undefined;
|
|
240
|
+
};
|
|
241
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
242
|
+
message?: string;
|
|
243
|
+
code?: string;
|
|
244
|
+
} | undefined, headers?: HeadersInit) => {
|
|
245
|
+
status: keyof typeof statusCodes | Status;
|
|
246
|
+
body: ({
|
|
247
|
+
message?: string;
|
|
248
|
+
code?: string;
|
|
249
|
+
cause?: unknown;
|
|
250
|
+
} & Record<string, any>) | undefined;
|
|
251
|
+
headers: HeadersInit;
|
|
252
|
+
statusCode: number;
|
|
253
|
+
name: string;
|
|
254
|
+
message: string;
|
|
255
|
+
stack?: string;
|
|
256
|
+
cause?: unknown;
|
|
257
|
+
} & {
|
|
258
|
+
errorStack: string | undefined;
|
|
259
|
+
};
|
|
260
|
+
setStatus: (status: Status) => void;
|
|
261
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
262
|
+
status?: number;
|
|
263
|
+
headers?: Record<string, string>;
|
|
264
|
+
response?: Response;
|
|
265
|
+
body?: Record<string, any>;
|
|
266
|
+
} | Response) => Record<string, any>;
|
|
267
|
+
responseHeaders: Headers;
|
|
268
|
+
responseStatus: Status | undefined;
|
|
269
|
+
asResponse?: boolean;
|
|
270
|
+
returnHeaders?: boolean;
|
|
271
|
+
returnStatus?: boolean;
|
|
272
|
+
use?: Middleware[];
|
|
273
|
+
} | {
|
|
274
|
+
body: any;
|
|
275
|
+
query: any;
|
|
276
|
+
path: string;
|
|
277
|
+
context: {};
|
|
278
|
+
returned: any;
|
|
279
|
+
headers: HeadersInit | undefined;
|
|
280
|
+
request: Request | undefined;
|
|
281
|
+
params: Record<string, any> | undefined;
|
|
282
|
+
method: any;
|
|
283
|
+
setHeader: (key: string, value: string) => void;
|
|
284
|
+
getHeader: (key: string) => string | null;
|
|
285
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
286
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
287
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
288
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
289
|
+
redirect: (url: string) => {
|
|
290
|
+
status: keyof typeof statusCodes | Status;
|
|
291
|
+
body: ({
|
|
292
|
+
message?: string;
|
|
293
|
+
code?: string;
|
|
294
|
+
cause?: unknown;
|
|
295
|
+
} & Record<string, any>) | undefined;
|
|
296
|
+
headers: HeadersInit;
|
|
297
|
+
statusCode: number;
|
|
298
|
+
name: string;
|
|
299
|
+
message: string;
|
|
300
|
+
stack?: string;
|
|
301
|
+
cause?: unknown;
|
|
302
|
+
} & {
|
|
303
|
+
errorStack: string | undefined;
|
|
304
|
+
};
|
|
305
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
306
|
+
message?: string;
|
|
307
|
+
code?: string;
|
|
308
|
+
} | undefined, headers?: HeadersInit) => {
|
|
309
|
+
status: keyof typeof statusCodes | Status;
|
|
310
|
+
body: ({
|
|
311
|
+
message?: string;
|
|
312
|
+
code?: string;
|
|
313
|
+
cause?: unknown;
|
|
314
|
+
} & Record<string, any>) | undefined;
|
|
315
|
+
headers: HeadersInit;
|
|
316
|
+
statusCode: number;
|
|
317
|
+
name: string;
|
|
318
|
+
message: string;
|
|
319
|
+
stack?: string;
|
|
320
|
+
cause?: unknown;
|
|
321
|
+
} & {
|
|
322
|
+
errorStack: string | undefined;
|
|
323
|
+
};
|
|
324
|
+
setStatus: (status: Status) => void;
|
|
325
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
326
|
+
status?: number;
|
|
327
|
+
headers?: Record<string, string>;
|
|
328
|
+
response?: Response;
|
|
329
|
+
body?: Record<string, any>;
|
|
330
|
+
} | Response) => Record<string, any>;
|
|
331
|
+
responseHeaders: Headers;
|
|
332
|
+
responseStatus: Status | undefined;
|
|
333
|
+
asResponse?: boolean;
|
|
334
|
+
returnHeaders?: boolean;
|
|
335
|
+
returnStatus?: boolean;
|
|
336
|
+
use?: Middleware[];
|
|
337
|
+
}>;
|
|
338
|
+
//#endregion
|
|
339
|
+
export { HTTPMethod, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, Method, createInternalContext };
|
|
340
|
+
//# sourceMappingURL=context.d.cts.map
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { InferParamPath, InferParamWildCard, IsEmptyObject, Prettify, UnionToIntersection } from "./helper.mjs";
|
|
2
|
+
import { StandardSchemaV1 } from "./standard-schema.mjs";
|
|
3
|
+
import { Status, statusCodes } from "./error.mjs";
|
|
4
|
+
import { CookieOptions, CookiePrefixOptions } from "./cookies.mjs";
|
|
5
|
+
import { Middleware, MiddlewareOptions } from "./middleware.mjs";
|
|
6
|
+
import { EndpointOptions } from "./endpoint.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/context.d.ts
|
|
9
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
10
|
+
type Method = HTTPMethod | "*";
|
|
11
|
+
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = (Options["metadata"] extends {
|
|
12
|
+
$Infer: {
|
|
13
|
+
body: infer B;
|
|
14
|
+
};
|
|
15
|
+
} ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined)> = undefined extends Body ? {
|
|
16
|
+
body?: Body;
|
|
17
|
+
} : {
|
|
18
|
+
body: Body;
|
|
19
|
+
};
|
|
20
|
+
type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
21
|
+
$Infer: {
|
|
22
|
+
body: infer Body;
|
|
23
|
+
};
|
|
24
|
+
} ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
|
|
25
|
+
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = (Options["metadata"] extends {
|
|
26
|
+
$Infer: {
|
|
27
|
+
query: infer Query;
|
|
28
|
+
};
|
|
29
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined)> = undefined extends Query ? {
|
|
30
|
+
query?: Query;
|
|
31
|
+
} : {
|
|
32
|
+
query: Query;
|
|
33
|
+
};
|
|
34
|
+
type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
35
|
+
$Infer: {
|
|
36
|
+
query: infer Query;
|
|
37
|
+
};
|
|
38
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
|
|
39
|
+
type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
|
|
40
|
+
type InferInputMethod<Options extends EndpointOptions, Method$1 = (Options["method"] extends Array<any> ? Options["method"][number] | undefined : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined)> = undefined extends Method$1 ? {
|
|
41
|
+
method?: Method$1;
|
|
42
|
+
} : {
|
|
43
|
+
method: Method$1;
|
|
44
|
+
};
|
|
45
|
+
type InferParam<Path extends string> = [Path] extends [never] ? Record<string, any> | undefined : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
46
|
+
type InferParamInput<Path extends string> = [Path] extends [never] ? {
|
|
47
|
+
params?: Record<string, any>;
|
|
48
|
+
} : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
|
|
49
|
+
params?: Record<string, any>;
|
|
50
|
+
} : {
|
|
51
|
+
params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
52
|
+
};
|
|
53
|
+
type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
|
|
54
|
+
type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
|
|
55
|
+
request: Request;
|
|
56
|
+
} : {
|
|
57
|
+
request?: Request;
|
|
58
|
+
};
|
|
59
|
+
type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
|
|
60
|
+
type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
|
|
61
|
+
headers: HeadersInit;
|
|
62
|
+
} : {
|
|
63
|
+
headers?: HeadersInit;
|
|
64
|
+
};
|
|
65
|
+
type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
|
|
66
|
+
type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
|
|
67
|
+
type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
|
|
68
|
+
type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
69
|
+
asResponse?: boolean;
|
|
70
|
+
returnHeaders?: boolean;
|
|
71
|
+
returnStatus?: boolean;
|
|
72
|
+
use?: Middleware[];
|
|
73
|
+
path?: string;
|
|
74
|
+
};
|
|
75
|
+
declare const createInternalContext: (context: InputContext<any, any>, {
|
|
76
|
+
options,
|
|
77
|
+
path
|
|
78
|
+
}: {
|
|
79
|
+
options: EndpointOptions;
|
|
80
|
+
path?: string;
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
body: any;
|
|
83
|
+
query: any;
|
|
84
|
+
path: string;
|
|
85
|
+
context: {};
|
|
86
|
+
returned: any;
|
|
87
|
+
headers: HeadersInit | undefined;
|
|
88
|
+
request: Request | undefined;
|
|
89
|
+
params: Record<string, any> | undefined;
|
|
90
|
+
method: any;
|
|
91
|
+
setHeader: (key: string, value: string) => void;
|
|
92
|
+
getHeader: (key: string) => string | null;
|
|
93
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
94
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
95
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
96
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
97
|
+
redirect: (url: string) => {
|
|
98
|
+
status: keyof typeof statusCodes | Status;
|
|
99
|
+
body: ({
|
|
100
|
+
message?: string;
|
|
101
|
+
code?: string;
|
|
102
|
+
cause?: unknown;
|
|
103
|
+
} & Record<string, any>) | undefined;
|
|
104
|
+
headers: HeadersInit;
|
|
105
|
+
statusCode: number;
|
|
106
|
+
name: string;
|
|
107
|
+
message: string;
|
|
108
|
+
stack?: string;
|
|
109
|
+
cause?: unknown;
|
|
110
|
+
} & {
|
|
111
|
+
errorStack: string | undefined;
|
|
112
|
+
};
|
|
113
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
114
|
+
message?: string;
|
|
115
|
+
code?: string;
|
|
116
|
+
} | undefined, headers?: HeadersInit) => {
|
|
117
|
+
status: keyof typeof statusCodes | Status;
|
|
118
|
+
body: ({
|
|
119
|
+
message?: string;
|
|
120
|
+
code?: string;
|
|
121
|
+
cause?: unknown;
|
|
122
|
+
} & Record<string, any>) | undefined;
|
|
123
|
+
headers: HeadersInit;
|
|
124
|
+
statusCode: number;
|
|
125
|
+
name: string;
|
|
126
|
+
message: string;
|
|
127
|
+
stack?: string;
|
|
128
|
+
cause?: unknown;
|
|
129
|
+
} & {
|
|
130
|
+
errorStack: string | undefined;
|
|
131
|
+
};
|
|
132
|
+
setStatus: (status: Status) => void;
|
|
133
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
134
|
+
status?: number;
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
response?: Response;
|
|
137
|
+
body?: Record<string, any>;
|
|
138
|
+
} | Response) => Record<string, any>;
|
|
139
|
+
responseHeaders: Headers;
|
|
140
|
+
responseStatus: Status | undefined;
|
|
141
|
+
asResponse?: boolean;
|
|
142
|
+
returnHeaders?: boolean;
|
|
143
|
+
returnStatus?: boolean;
|
|
144
|
+
use?: Middleware[];
|
|
145
|
+
} | {
|
|
146
|
+
body: any;
|
|
147
|
+
query: any;
|
|
148
|
+
path: string;
|
|
149
|
+
context: {};
|
|
150
|
+
returned: any;
|
|
151
|
+
headers: HeadersInit | undefined;
|
|
152
|
+
request: Request | undefined;
|
|
153
|
+
params: Record<string, any> | undefined;
|
|
154
|
+
method: any;
|
|
155
|
+
setHeader: (key: string, value: string) => void;
|
|
156
|
+
getHeader: (key: string) => string | null;
|
|
157
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
158
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
159
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
160
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
161
|
+
redirect: (url: string) => {
|
|
162
|
+
status: keyof typeof statusCodes | Status;
|
|
163
|
+
body: ({
|
|
164
|
+
message?: string;
|
|
165
|
+
code?: string;
|
|
166
|
+
cause?: unknown;
|
|
167
|
+
} & Record<string, any>) | undefined;
|
|
168
|
+
headers: HeadersInit;
|
|
169
|
+
statusCode: number;
|
|
170
|
+
name: string;
|
|
171
|
+
message: string;
|
|
172
|
+
stack?: string;
|
|
173
|
+
cause?: unknown;
|
|
174
|
+
} & {
|
|
175
|
+
errorStack: string | undefined;
|
|
176
|
+
};
|
|
177
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
178
|
+
message?: string;
|
|
179
|
+
code?: string;
|
|
180
|
+
} | undefined, headers?: HeadersInit) => {
|
|
181
|
+
status: keyof typeof statusCodes | Status;
|
|
182
|
+
body: ({
|
|
183
|
+
message?: string;
|
|
184
|
+
code?: string;
|
|
185
|
+
cause?: unknown;
|
|
186
|
+
} & Record<string, any>) | undefined;
|
|
187
|
+
headers: HeadersInit;
|
|
188
|
+
statusCode: number;
|
|
189
|
+
name: string;
|
|
190
|
+
message: string;
|
|
191
|
+
stack?: string;
|
|
192
|
+
cause?: unknown;
|
|
193
|
+
} & {
|
|
194
|
+
errorStack: string | undefined;
|
|
195
|
+
};
|
|
196
|
+
setStatus: (status: Status) => void;
|
|
197
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
198
|
+
status?: number;
|
|
199
|
+
headers?: Record<string, string>;
|
|
200
|
+
response?: Response;
|
|
201
|
+
body?: Record<string, any>;
|
|
202
|
+
} | Response) => Record<string, any>;
|
|
203
|
+
responseHeaders: Headers;
|
|
204
|
+
responseStatus: Status | undefined;
|
|
205
|
+
asResponse?: boolean;
|
|
206
|
+
returnHeaders?: boolean;
|
|
207
|
+
returnStatus?: boolean;
|
|
208
|
+
use?: Middleware[];
|
|
209
|
+
} | {
|
|
210
|
+
body: any;
|
|
211
|
+
query: any;
|
|
212
|
+
path: string;
|
|
213
|
+
context: {};
|
|
214
|
+
returned: any;
|
|
215
|
+
headers: HeadersInit | undefined;
|
|
216
|
+
request: Request | undefined;
|
|
217
|
+
params: Record<string, any> | undefined;
|
|
218
|
+
method: any;
|
|
219
|
+
setHeader: (key: string, value: string) => void;
|
|
220
|
+
getHeader: (key: string) => string | null;
|
|
221
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
222
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
223
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
224
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
225
|
+
redirect: (url: string) => {
|
|
226
|
+
status: keyof typeof statusCodes | Status;
|
|
227
|
+
body: ({
|
|
228
|
+
message?: string;
|
|
229
|
+
code?: string;
|
|
230
|
+
cause?: unknown;
|
|
231
|
+
} & Record<string, any>) | undefined;
|
|
232
|
+
headers: HeadersInit;
|
|
233
|
+
statusCode: number;
|
|
234
|
+
name: string;
|
|
235
|
+
message: string;
|
|
236
|
+
stack?: string;
|
|
237
|
+
cause?: unknown;
|
|
238
|
+
} & {
|
|
239
|
+
errorStack: string | undefined;
|
|
240
|
+
};
|
|
241
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
242
|
+
message?: string;
|
|
243
|
+
code?: string;
|
|
244
|
+
} | undefined, headers?: HeadersInit) => {
|
|
245
|
+
status: keyof typeof statusCodes | Status;
|
|
246
|
+
body: ({
|
|
247
|
+
message?: string;
|
|
248
|
+
code?: string;
|
|
249
|
+
cause?: unknown;
|
|
250
|
+
} & Record<string, any>) | undefined;
|
|
251
|
+
headers: HeadersInit;
|
|
252
|
+
statusCode: number;
|
|
253
|
+
name: string;
|
|
254
|
+
message: string;
|
|
255
|
+
stack?: string;
|
|
256
|
+
cause?: unknown;
|
|
257
|
+
} & {
|
|
258
|
+
errorStack: string | undefined;
|
|
259
|
+
};
|
|
260
|
+
setStatus: (status: Status) => void;
|
|
261
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
262
|
+
status?: number;
|
|
263
|
+
headers?: Record<string, string>;
|
|
264
|
+
response?: Response;
|
|
265
|
+
body?: Record<string, any>;
|
|
266
|
+
} | Response) => Record<string, any>;
|
|
267
|
+
responseHeaders: Headers;
|
|
268
|
+
responseStatus: Status | undefined;
|
|
269
|
+
asResponse?: boolean;
|
|
270
|
+
returnHeaders?: boolean;
|
|
271
|
+
returnStatus?: boolean;
|
|
272
|
+
use?: Middleware[];
|
|
273
|
+
} | {
|
|
274
|
+
body: any;
|
|
275
|
+
query: any;
|
|
276
|
+
path: string;
|
|
277
|
+
context: {};
|
|
278
|
+
returned: any;
|
|
279
|
+
headers: HeadersInit | undefined;
|
|
280
|
+
request: Request | undefined;
|
|
281
|
+
params: Record<string, any> | undefined;
|
|
282
|
+
method: any;
|
|
283
|
+
setHeader: (key: string, value: string) => void;
|
|
284
|
+
getHeader: (key: string) => string | null;
|
|
285
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
286
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
287
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
288
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
289
|
+
redirect: (url: string) => {
|
|
290
|
+
status: keyof typeof statusCodes | Status;
|
|
291
|
+
body: ({
|
|
292
|
+
message?: string;
|
|
293
|
+
code?: string;
|
|
294
|
+
cause?: unknown;
|
|
295
|
+
} & Record<string, any>) | undefined;
|
|
296
|
+
headers: HeadersInit;
|
|
297
|
+
statusCode: number;
|
|
298
|
+
name: string;
|
|
299
|
+
message: string;
|
|
300
|
+
stack?: string;
|
|
301
|
+
cause?: unknown;
|
|
302
|
+
} & {
|
|
303
|
+
errorStack: string | undefined;
|
|
304
|
+
};
|
|
305
|
+
error: (status: keyof typeof statusCodes | Status, body?: {
|
|
306
|
+
message?: string;
|
|
307
|
+
code?: string;
|
|
308
|
+
} | undefined, headers?: HeadersInit) => {
|
|
309
|
+
status: keyof typeof statusCodes | Status;
|
|
310
|
+
body: ({
|
|
311
|
+
message?: string;
|
|
312
|
+
code?: string;
|
|
313
|
+
cause?: unknown;
|
|
314
|
+
} & Record<string, any>) | undefined;
|
|
315
|
+
headers: HeadersInit;
|
|
316
|
+
statusCode: number;
|
|
317
|
+
name: string;
|
|
318
|
+
message: string;
|
|
319
|
+
stack?: string;
|
|
320
|
+
cause?: unknown;
|
|
321
|
+
} & {
|
|
322
|
+
errorStack: string | undefined;
|
|
323
|
+
};
|
|
324
|
+
setStatus: (status: Status) => void;
|
|
325
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
326
|
+
status?: number;
|
|
327
|
+
headers?: Record<string, string>;
|
|
328
|
+
response?: Response;
|
|
329
|
+
body?: Record<string, any>;
|
|
330
|
+
} | Response) => Record<string, any>;
|
|
331
|
+
responseHeaders: Headers;
|
|
332
|
+
responseStatus: Status | undefined;
|
|
333
|
+
asResponse?: boolean;
|
|
334
|
+
returnHeaders?: boolean;
|
|
335
|
+
returnStatus?: boolean;
|
|
336
|
+
use?: Middleware[];
|
|
337
|
+
}>;
|
|
338
|
+
//#endregion
|
|
339
|
+
export { HTTPMethod, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, Method, createInternalContext };
|
|
340
|
+
//# sourceMappingURL=context.d.mts.map
|