better-call 1.0.3 → 1.0.4-beta.1

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.
@@ -1,2322 +0,0 @@
1
- declare const _statusCode: {
2
- OK: number;
3
- CREATED: number;
4
- ACCEPTED: number;
5
- NO_CONTENT: number;
6
- MULTIPLE_CHOICES: number;
7
- MOVED_PERMANENTLY: number;
8
- FOUND: number;
9
- SEE_OTHER: number;
10
- NOT_MODIFIED: number;
11
- TEMPORARY_REDIRECT: number;
12
- BAD_REQUEST: number;
13
- UNAUTHORIZED: number;
14
- PAYMENT_REQUIRED: number;
15
- FORBIDDEN: number;
16
- NOT_FOUND: number;
17
- METHOD_NOT_ALLOWED: number;
18
- NOT_ACCEPTABLE: number;
19
- PROXY_AUTHENTICATION_REQUIRED: number;
20
- REQUEST_TIMEOUT: number;
21
- CONFLICT: number;
22
- GONE: number;
23
- LENGTH_REQUIRED: number;
24
- PRECONDITION_FAILED: number;
25
- PAYLOAD_TOO_LARGE: number;
26
- URI_TOO_LONG: number;
27
- UNSUPPORTED_MEDIA_TYPE: number;
28
- RANGE_NOT_SATISFIABLE: number;
29
- EXPECTATION_FAILED: number;
30
- "I'M_A_TEAPOT": number;
31
- MISDIRECTED_REQUEST: number;
32
- UNPROCESSABLE_ENTITY: number;
33
- LOCKED: number;
34
- FAILED_DEPENDENCY: number;
35
- TOO_EARLY: number;
36
- UPGRADE_REQUIRED: number;
37
- PRECONDITION_REQUIRED: number;
38
- TOO_MANY_REQUESTS: number;
39
- REQUEST_HEADER_FIELDS_TOO_LARGE: number;
40
- UNAVAILABLE_FOR_LEGAL_REASONS: number;
41
- INTERNAL_SERVER_ERROR: number;
42
- NOT_IMPLEMENTED: number;
43
- BAD_GATEWAY: number;
44
- SERVICE_UNAVAILABLE: number;
45
- GATEWAY_TIMEOUT: number;
46
- HTTP_VERSION_NOT_SUPPORTED: number;
47
- VARIANT_ALSO_NEGOTIATES: number;
48
- INSUFFICIENT_STORAGE: number;
49
- LOOP_DETECTED: number;
50
- NOT_EXTENDED: number;
51
- NETWORK_AUTHENTICATION_REQUIRED: number;
52
- };
53
- type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
54
- declare class APIError extends Error {
55
- status: keyof typeof _statusCode | Status;
56
- body: ({
57
- message?: string;
58
- code?: string;
59
- } & Record<string, any>) | undefined;
60
- headers: HeadersInit;
61
- statusCode: number;
62
- constructor(status?: keyof typeof _statusCode | Status, body?: ({
63
- message?: string;
64
- code?: string;
65
- } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
66
- }
67
-
68
- /**
69
- * Improve this type if possible
70
- */
71
- type Input<T> = Prettify<{
72
- [K in keyof T as T[K] extends never ? never : undefined extends T[K] ? never : K]: T[K];
73
- } & {
74
- [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
75
- }>;
76
- type RequiredKeysOf<BaseType extends object> = Exclude<{
77
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
78
- }[keyof BaseType], undefined>;
79
- type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
80
- type Prettify<T> = {
81
- [K in keyof T]: T[K];
82
- } & {};
83
- type IsEmptyObject<T> = keyof T extends never ? true : false;
84
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never;
85
- type MergeObject<T extends Record<string, any> | never, S extends Record<string, any> | never> = T extends never ? S : S extends never ? T : T & S;
86
- type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
87
- [K in Param | keyof InferParamPath<Rest>]: string;
88
- } : Path extends `${infer _Start}:${infer Param}` ? {
89
- [K in Param]: string;
90
- } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
91
- type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? {
92
- [K in Param | keyof InferParamPath<Rest>]: string;
93
- } : Path extends `${infer _Start}/*` ? {
94
- [K in "_"]: string;
95
- } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
96
-
97
- interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {
98
- }
99
- type MiddlewareResponse = null | void | undefined | Record<string, any>;
100
- type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
101
- method: "*";
102
- }> & {
103
- /**
104
- * Method
105
- *
106
- * The request method
107
- */
108
- method: string;
109
- /**
110
- * Path
111
- *
112
- * The path of the endpoint
113
- */
114
- path: string;
115
- /**
116
- * Body
117
- *
118
- * The body object will be the parsed JSON from the request and validated
119
- * against the body schema if it exists
120
- */
121
- body: InferMiddlewareBody<Options>;
122
- /**
123
- * Query
124
- *
125
- * The query object will be the parsed query string from the request
126
- * and validated against the query schema if it exists
127
- */
128
- query: InferMiddlewareQuery<Options>;
129
- /**
130
- * Params
131
- *
132
- * If the path is `/user/:id` and the request is `/user/1` then the
133
- * params will
134
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
135
- * then the
136
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the
137
- * wildcard
138
- * is named like `/user/**:name` then the params will be `{ name: string }`
139
- */
140
- params: string;
141
- /**
142
- * Request object
143
- *
144
- * If `requireRequest` is set to true in the endpoint options this will be
145
- * required
146
- */
147
- request: InferRequest<Options>;
148
- /**
149
- * Headers
150
- *
151
- * If `requireHeaders` is set to true in the endpoint options this will be
152
- * required
153
- */
154
- headers: InferHeaders<Options>;
155
- /**
156
- * Set header
157
- *
158
- * If it's called outside of a request it will just be ignored.
159
- */
160
- setHeader: (key: string, value: string) => void;
161
- /**
162
- * Get header
163
- *
164
- * If it's called outside of a request it will just return null
165
- *
166
- * @param key - The key of the header
167
- * @returns
168
- */
169
- getHeader: (key: string) => string | null;
170
- /**
171
- * JSON
172
- *
173
- * a helper function to create a JSON response with
174
- * the correct headers
175
- * and status code. If `asResponse` is set to true in
176
- * the context then
177
- * it will return a Response object instead of the
178
- * JSON object.
179
- *
180
- * @param json - The JSON object to return
181
- * @param routerResponse - The response object to
182
- * return if `asResponse` is
183
- * true in the context this will take precedence
184
- */
185
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
186
- status?: number;
187
- headers?: Record<string, string>;
188
- response?: Response;
189
- } | Response) => Promise<R>;
190
- /**
191
- * Middleware context
192
- */
193
- context: Prettify<Context>;
194
- };
195
- declare function createMiddleware<Options extends MiddlewareOptions, R>(options: Options, handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
196
- declare function createMiddleware<Options extends MiddlewareOptions, R>(handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
197
- declare namespace createMiddleware {
198
- var create: <E extends {
199
- use?: Middleware[];
200
- }>(opts?: E) => {
201
- <Options extends MiddlewareOptions, R>(options: Options, handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R>): (inputContext: MiddlewareInputContext<Options>) => Promise<R>;
202
- <Options extends MiddlewareOptions, R_1>(handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R_1>): (inputContext: MiddlewareInputContext<Options>) => Promise<R_1>;
203
- };
204
- }
205
- type MiddlewareInputContext<Options extends MiddlewareOptions> = Input<{
206
- /**
207
- * Payload
208
- */
209
- body: InferBody<Options>;
210
- /**
211
- * Query Params
212
- */
213
- query: InferQuery<Options>;
214
- /**
215
- * Request Object
216
- */
217
- request: InferRequest<Options>;
218
- /**
219
- * Headers
220
- */
221
- headers: InferHeaders<Options>;
222
- /**
223
- * Return a `Response` object
224
- */
225
- asResponse?: boolean;
226
- /**
227
- * include headers on the return
228
- */
229
- returnHeaders?: boolean;
230
- /**
231
- * Middlewares to use
232
- */
233
- use?: Middleware[];
234
- }>;
235
- type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
236
- options: Options;
237
- };
238
-
239
- type CookiePrefixOptions = "host" | "secure";
240
- type CookieOptions = {
241
- /**
242
- * Domain of the cookie
243
- *
244
- * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
245
- * available on the specified server and its subdomains. If the it is not
246
- * specified, the cookies are available on the server that sets it but not on
247
- * its subdomains.
248
- *
249
- * @example
250
- * `domain: "example.com"`
251
- */
252
- domain?: string;
253
- /**
254
- * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
255
- * Expires attribute:
256
- *
257
- * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
258
- * takes precedence when both are set. The rationale behind this is that when you set an
259
- * Expires date and time, they're relative to the client the cookie is being set on. If the
260
- * server is set to a different time, this could cause errors
261
- */
262
- expires?: Date;
263
- /**
264
- * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
265
- * property. Note that a cookie that has been created with HttpOnly will still be sent with
266
- * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
267
- * This mitigates attacks against cross-site scripting
268
- */
269
- httpOnly?: boolean;
270
- /**
271
- * Indicates the number of seconds until the cookie expires. A zero or negative number will
272
- * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
273
- *
274
- * @example 604800 - 7 days
275
- */
276
- maxAge?: number;
277
- /**
278
- * Indicates the path that must exist in the requested URL for the browser to send the Cookie
279
- * header.
280
- *
281
- * @example
282
- * "/docs"
283
- * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
284
- */
285
- path?: string;
286
- /**
287
- * Indicates that the cookie is sent to the server only when a request is made with the https:
288
- * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
289
- */
290
- secure?: boolean;
291
- /**
292
- * Controls whether or not a cookie is sent with cross-site requests, providing some protection
293
- * against cross-site request forgery attacks (CSRF).
294
- *
295
- * Strict - Means that the browser sends the cookie only for same-site requests, that is,
296
- * requests originating from the same site that set the cookie. If a request originates from a
297
- * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
298
- * attribute are sent.
299
- *
300
- * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
301
- * images or frames, but is sent when a user is navigating to the origin site from an external
302
- * site (for example, when following a link). This is the default behavior if the SameSite
303
- * attribute is not specified.
304
- *
305
- * None - Means that the browser sends the cookie with both cross-site and same-site requests.
306
- * The Secure attribute must also be set when setting this value.
307
- */
308
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
309
- /**
310
- * Indicates that the cookie should be stored using partitioned storage. Note that if this is
311
- * set, the Secure directive must also be set.
312
- *
313
- * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
314
- */
315
- partitioned?: boolean;
316
- /**
317
- * Cooke Prefix
318
- *
319
- * - secure: `__Secure-` -> `__Secure-cookie-name`
320
- * - host: `__Host-` -> `__Host-cookie-name`
321
- *
322
- * `secure` must be set to true to use prefixes
323
- */
324
- prefix?: CookiePrefixOptions;
325
- };
326
- declare const getCookieKey: (key: string, prefix?: CookiePrefixOptions) => string | undefined;
327
- declare function parseCookies(cookieHeader: string): Map<string, string>;
328
- declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string;
329
- declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise<string>;
330
-
331
- /** The Standard Schema interface. */
332
- interface StandardSchemaV1<Input = unknown, Output = Input> {
333
- /** The Standard Schema properties. */
334
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
335
- }
336
- declare namespace StandardSchemaV1 {
337
- /** The Standard Schema properties interface. */
338
- interface Props<Input = unknown, Output = Input> {
339
- /** The version number of the standard. */
340
- readonly version: 1;
341
- /** The vendor name of the schema library. */
342
- readonly vendor: string;
343
- /** Validates unknown input values. */
344
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
345
- /** Inferred types associated with the schema. */
346
- readonly types?: Types<Input, Output> | undefined;
347
- }
348
- /** The result interface of the validate function. */
349
- type Result<Output> = SuccessResult<Output> | FailureResult;
350
- /** The result interface if validation succeeds. */
351
- interface SuccessResult<Output> {
352
- /** The typed output value. */
353
- readonly value: Output;
354
- /** The non-existent issues. */
355
- readonly issues?: undefined;
356
- }
357
- /** The result interface if validation fails. */
358
- interface FailureResult {
359
- /** The issues of failed validation. */
360
- readonly issues: ReadonlyArray<Issue>;
361
- }
362
- /** The issue interface of the failure output. */
363
- interface Issue {
364
- /** The error message of the issue. */
365
- readonly message: string;
366
- /** The path of the issue, if any. */
367
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
368
- }
369
- /** The path segment interface of the issue. */
370
- interface PathSegment {
371
- /** The key representing a path segment. */
372
- readonly key: PropertyKey;
373
- }
374
- /** The Standard Schema types interface. */
375
- interface Types<Input = unknown, Output = Input> {
376
- /** The input type of the schema. */
377
- readonly input: Input;
378
- /** The output type of the schema. */
379
- readonly output: Output;
380
- }
381
- /** Infers the input type of a Standard Schema. */
382
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
383
- /** Infers the output type of a Standard Schema. */
384
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
385
- }
386
-
387
- type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
388
- type Method = HTTPMethod | "*";
389
- type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
390
- $Infer: {
391
- body: infer Body;
392
- };
393
- } ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined;
394
- type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
395
- $Infer: {
396
- body: infer Body;
397
- };
398
- } ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
399
- type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
400
- $Infer: {
401
- query: infer Query;
402
- };
403
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined;
404
- type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
405
- $Infer: {
406
- query: infer Query;
407
- };
408
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
409
- type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
410
- type InferInputMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined;
411
- type InferParam<Path extends string> = IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
412
- type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
413
- type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
414
- type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? HeadersInit : HeadersInit | undefined;
415
- type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
416
- type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
417
- type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
418
- type InputContext<Path extends string, Options extends EndpointOptions> = Input<{
419
- /**
420
- * Payload
421
- */
422
- body: InferBodyInput<Options>;
423
- /**
424
- * Request Method
425
- */
426
- method: InferInputMethod<Options>;
427
- /**
428
- * Query Params
429
- */
430
- query: InferQueryInput<Options>;
431
- /**
432
- * Dynamic Params
433
- */
434
- params: InferParam<Path>;
435
- /**
436
- * Request Object
437
- */
438
- request: InferRequest<Options>;
439
- /**
440
- * Headers
441
- */
442
- headers: InferHeadersInput<Options>;
443
- /**
444
- * Return a `Response` object
445
- */
446
- asResponse?: boolean;
447
- /**
448
- * include headers on the return
449
- */
450
- returnHeaders?: boolean;
451
- /**
452
- * Middlewares to use
453
- */
454
- use?: Middleware[];
455
- /**
456
- * Customize the path
457
- */
458
- path?: string;
459
- }>;
460
- declare const createInternalContext: (context: InputContext<any, any>, { options, path, }: {
461
- options: EndpointOptions;
462
- path: string;
463
- }) => Promise<{
464
- body: any;
465
- query: any;
466
- path: string;
467
- context: {};
468
- returned: any;
469
- headers: HeadersInit | undefined;
470
- request: Request | undefined;
471
- params: Record<string, any> | undefined;
472
- method: any;
473
- setHeader: (key: string, value: string) => void;
474
- getHeader: (key: string) => string | null;
475
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
476
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
477
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
478
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
479
- redirect: (url: string) => APIError;
480
- error: (status: keyof typeof _statusCode | Status, body?: {
481
- message?: string;
482
- code?: string;
483
- } | undefined, headers?: HeadersInit) => APIError;
484
- json: (json: Record<string, any>, routerResponse?: {
485
- status?: number;
486
- headers?: Record<string, string>;
487
- response?: Response;
488
- body?: Record<string, any>;
489
- } | Response) => Record<string, any>;
490
- responseHeaders: Headers;
491
- asResponse?: boolean | undefined;
492
- returnHeaders?: boolean | undefined;
493
- use?: Middleware[] | undefined;
494
- }>;
495
-
496
- type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
497
- interface OpenAPIParameter {
498
- in: "query" | "path" | "header" | "cookie";
499
- name?: string;
500
- description?: string;
501
- required?: boolean;
502
- schema?: {
503
- type: OpenAPISchemaType;
504
- format?: string;
505
- items?: {
506
- type: OpenAPISchemaType;
507
- };
508
- enum?: string[];
509
- minLength?: number;
510
- description?: string;
511
- default?: string;
512
- example?: string;
513
- };
514
- }
515
- interface Path {
516
- get?: {
517
- tags?: string[];
518
- operationId?: string;
519
- description?: string;
520
- security?: [{
521
- bearerAuth: string[];
522
- }];
523
- parameters?: OpenAPIParameter[];
524
- responses?: {
525
- [key in string]: {
526
- description?: string;
527
- content: {
528
- "application/json": {
529
- schema: {
530
- type?: OpenAPISchemaType;
531
- properties?: Record<string, any>;
532
- required?: string[];
533
- $ref?: string;
534
- };
535
- };
536
- };
537
- };
538
- };
539
- };
540
- post?: {
541
- tags?: string[];
542
- operationId?: string;
543
- description?: string;
544
- security?: [{
545
- bearerAuth: string[];
546
- }];
547
- parameters?: OpenAPIParameter[];
548
- requestBody?: {
549
- content: {
550
- "application/json": {
551
- schema: {
552
- type?: OpenAPISchemaType;
553
- properties?: Record<string, any>;
554
- required?: string[];
555
- $ref?: string;
556
- };
557
- };
558
- };
559
- };
560
- responses?: {
561
- [key in string]: {
562
- description?: string;
563
- content: {
564
- "application/json": {
565
- schema: {
566
- type?: OpenAPISchemaType;
567
- properties?: Record<string, any>;
568
- required?: string[];
569
- $ref?: string;
570
- };
571
- };
572
- };
573
- };
574
- };
575
- };
576
- }
577
- declare function generator(endpoints: Record<string, Endpoint>, config?: {
578
- url: string;
579
- }): Promise<{
580
- openapi: string;
581
- info: {
582
- title: string;
583
- description: string;
584
- version: string;
585
- };
586
- components: {
587
- schemas: {};
588
- };
589
- security: {
590
- apiKeyCookie: never[];
591
- }[];
592
- servers: {
593
- url: string | undefined;
594
- }[];
595
- tags: {
596
- name: string;
597
- description: string;
598
- }[];
599
- paths: Record<string, Path>;
600
- }>;
601
- declare const getHTML: (apiReference: Record<string, any>, config?: {
602
- logo?: string;
603
- theme?: string;
604
- title?: string;
605
- description?: string;
606
- }) => string;
607
-
608
- interface EndpointOptions {
609
- /**
610
- * Request Method
611
- */
612
- method: Method | Method[];
613
- /**
614
- * Body Schema
615
- */
616
- body?: StandardSchemaV1;
617
- /**
618
- * Query Schema
619
- */
620
- query?: StandardSchemaV1;
621
- /**
622
- * If true headers will be required to be passed in the context
623
- */
624
- requireHeaders?: boolean;
625
- /**
626
- * If true request object will be required
627
- */
628
- requireRequest?: boolean;
629
- /**
630
- * Clone the request object from the router
631
- */
632
- cloneRequest?: boolean;
633
- /**
634
- * Endpoint metadata
635
- */
636
- metadata?: {
637
- /**
638
- * Open API definition
639
- */
640
- openapi?: {
641
- summary?: string;
642
- description?: string;
643
- tags?: string[];
644
- operationId?: string;
645
- parameters?: OpenAPIParameter[];
646
- requestBody?: {
647
- content: {
648
- "application/json": {
649
- schema: {
650
- type?: OpenAPISchemaType;
651
- properties?: Record<string, any>;
652
- required?: string[];
653
- $ref?: string;
654
- };
655
- };
656
- };
657
- };
658
- responses?: {
659
- [status: string]: {
660
- description: string;
661
- content?: {
662
- "application/json"?: {
663
- schema: {
664
- type?: OpenAPISchemaType;
665
- properties?: Record<string, any>;
666
- required?: string[];
667
- $ref?: string;
668
- };
669
- };
670
- "text/plain"?: {
671
- schema?: {
672
- type?: OpenAPISchemaType;
673
- properties?: Record<string, any>;
674
- required?: string[];
675
- $ref?: string;
676
- };
677
- };
678
- "text/html"?: {
679
- schema?: {
680
- type?: OpenAPISchemaType;
681
- properties?: Record<string, any>;
682
- required?: string[];
683
- $ref?: string;
684
- };
685
- };
686
- };
687
- };
688
- };
689
- };
690
- /**
691
- * Infer body and query type from ts interface
692
- *
693
- * useful for generic and dynamic types
694
- *
695
- * @example
696
- * ```ts
697
- * const endpoint = createEndpoint("/path", {
698
- * method: "POST",
699
- * body: z.record(z.string()),
700
- * $Infer: {
701
- * body: {} as {
702
- * type: InferTypeFromOptions<Option> // custom type inference
703
- * }
704
- * }
705
- * }, async(ctx)=>{
706
- * const body = ctx.body
707
- * })
708
- * ```
709
- */
710
- $Infer?: {
711
- /**
712
- * Body
713
- */
714
- body?: any;
715
- /**
716
- * Query
717
- */
718
- query?: Record<string, any>;
719
- };
720
- /**
721
- * If enabled, endpoint won't be exposed over a router
722
- */
723
- SERVER_ONLY?: boolean;
724
- /**
725
- * Extra metadata
726
- */
727
- [key: string]: any;
728
- };
729
- /**
730
- * List of middlewares to use
731
- */
732
- use?: Middleware[];
733
- }
734
- type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
735
- /**
736
- * Method
737
- *
738
- * The request method
739
- */
740
- method: InferMethod<Options>;
741
- /**
742
- * Path
743
- *
744
- * The path of the endpoint
745
- */
746
- path: Path;
747
- /**
748
- * Body
749
- *
750
- * The body object will be the parsed JSON from the request and validated
751
- * against the body schema if it exists.
752
- */
753
- body: InferBody<Options>;
754
- /**
755
- * Query
756
- *
757
- * The query object will be the parsed query string from the request
758
- * and validated against the query schema if it exists
759
- */
760
- query: InferQuery<Options>;
761
- /**
762
- * Params
763
- *
764
- * If the path is `/user/:id` and the request is `/user/1` then the params will
765
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*` then the
766
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the wildcard
767
- * is named like `/user/**:name` then the params will be `{ name: string }`
768
- */
769
- params: InferParam<Path>;
770
- /**
771
- * Request object
772
- *
773
- * If `requireRequest` is set to true in the endpoint options this will be
774
- * required
775
- */
776
- request: InferRequest<Options>;
777
- /**
778
- * Headers
779
- *
780
- * If `requireHeaders` is set to true in the endpoint options this will be
781
- * required
782
- */
783
- headers: InferHeaders<Options>;
784
- /**
785
- * Set header
786
- *
787
- * If it's called outside of a request it will just be ignored.
788
- */
789
- setHeader: (key: string, value: string) => void;
790
- /**
791
- * Get header
792
- *
793
- * If it's called outside of a request it will just return null
794
- *
795
- * @param key - The key of the header
796
- * @returns
797
- */
798
- getHeader: (key: string) => string | null;
799
- /**
800
- * Get a cookie value from the request
801
- *
802
- * @param key - The key of the cookie
803
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
804
- * @returns - The value of the cookie
805
- */
806
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
807
- /**
808
- * Get a signed cookie value from the request
809
- *
810
- * @param key - The key of the cookie
811
- * @param secret - The secret of the signed cookie
812
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
813
- * @returns
814
- */
815
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null>;
816
- /**
817
- * Set a cookie value in the response
818
- *
819
- * @param key - The key of the cookie
820
- * @param value - The value to set
821
- * @param options - The options of the cookie
822
- * @returns - The cookie string
823
- */
824
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
825
- /**
826
- * Set signed cookie
827
- *
828
- * @param key - The key of the cookie
829
- * @param value - The value to set
830
- * @param secret - The secret to sign the cookie with
831
- * @param options - The options of the cookie
832
- * @returns - The cookie string
833
- */
834
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
835
- /**
836
- * JSON
837
- *
838
- * a helper function to create a JSON response with
839
- * the correct headers
840
- * and status code. If `asResponse` is set to true in
841
- * the context then
842
- * it will return a Response object instead of the
843
- * JSON object.
844
- *
845
- * @param json - The JSON object to return
846
- * @param routerResponse - The response object to
847
- * return if `asResponse` is
848
- * true in the context this will take precedence
849
- */
850
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
851
- status?: number;
852
- headers?: Record<string, string>;
853
- response?: Response;
854
- body?: Record<string, string>;
855
- } | Response) => Promise<R>;
856
- /**
857
- * Middleware context
858
- */
859
- context: Prettify<Context & InferUse<Options["use"]>>;
860
- /**
861
- * Redirect to a new URL
862
- */
863
- redirect: (url: string) => APIError;
864
- /**
865
- * Return error
866
- */
867
- error: (status: keyof typeof _statusCode | Status, body?: {
868
- message?: string;
869
- code?: string;
870
- } & Record<string, any>, headers?: HeadersInit) => APIError;
871
- };
872
- declare const createEndpoint: {
873
- <Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: (context: EndpointContext<Path, Options>) => Promise<R>): {
874
- <C extends HasRequiredKeys<({
875
- body: InferBodyInput<Options>;
876
- method: InferInputMethod<Options>;
877
- query: InferQueryInput<Options>;
878
- params: InferParam<Path>;
879
- request: InferRequest<Options>;
880
- headers: InferHeadersInput<Options>;
881
- asResponse?: boolean;
882
- returnHeaders?: boolean;
883
- use?: Middleware[];
884
- path?: string;
885
- } extends infer T_3 ? { [K_1 in keyof T_3 as {
886
- body: InferBodyInput<Options>;
887
- method: InferInputMethod<Options>;
888
- query: InferQueryInput<Options>;
889
- params: InferParam<Path>;
890
- request: InferRequest<Options>;
891
- headers: InferHeadersInput<Options>;
892
- asResponse?: boolean;
893
- returnHeaders?: boolean;
894
- use?: Middleware[];
895
- path?: string;
896
- }[K_1] extends never ? never : undefined extends {
897
- body: InferBodyInput<Options>;
898
- method: InferInputMethod<Options>;
899
- query: InferQueryInput<Options>;
900
- params: InferParam<Path>;
901
- request: InferRequest<Options>;
902
- headers: InferHeadersInput<Options>;
903
- asResponse?: boolean;
904
- returnHeaders?: boolean;
905
- use?: Middleware[];
906
- path?: string;
907
- }[K_1] ? never : K_1]: {
908
- body: InferBodyInput<Options>;
909
- method: InferInputMethod<Options>;
910
- query: InferQueryInput<Options>;
911
- params: InferParam<Path>;
912
- request: InferRequest<Options>;
913
- headers: InferHeadersInput<Options>;
914
- asResponse?: boolean;
915
- returnHeaders?: boolean;
916
- use?: Middleware[];
917
- path?: string;
918
- }[K_1]; } : never) & ({
919
- body: InferBodyInput<Options>;
920
- method: InferInputMethod<Options>;
921
- query: InferQueryInput<Options>;
922
- params: InferParam<Path>;
923
- request: InferRequest<Options>;
924
- headers: InferHeadersInput<Options>;
925
- asResponse?: boolean;
926
- returnHeaders?: boolean;
927
- use?: Middleware[];
928
- path?: string;
929
- } extends infer T_4 ? { [K_2 in keyof T_4 as undefined extends {
930
- body: InferBodyInput<Options>;
931
- method: InferInputMethod<Options>;
932
- query: InferQueryInput<Options>;
933
- params: InferParam<Path>;
934
- request: InferRequest<Options>;
935
- headers: InferHeadersInput<Options>;
936
- asResponse?: boolean;
937
- returnHeaders?: boolean;
938
- use?: Middleware[];
939
- path?: string;
940
- }[K_2] ? K_2 : never]?: {
941
- body: InferBodyInput<Options>;
942
- method: InferInputMethod<Options>;
943
- query: InferQueryInput<Options>;
944
- params: InferParam<Path>;
945
- request: InferRequest<Options>;
946
- headers: InferHeadersInput<Options>;
947
- asResponse?: boolean;
948
- returnHeaders?: boolean;
949
- use?: Middleware[];
950
- path?: string;
951
- }[K_2] | undefined; } : never) extends infer T ? { [K in keyof T]: (({
952
- body: InferBodyInput<Options>;
953
- method: InferInputMethod<Options>;
954
- query: InferQueryInput<Options>;
955
- params: InferParam<Path>;
956
- request: InferRequest<Options>;
957
- headers: InferHeadersInput<Options>;
958
- asResponse?: boolean;
959
- returnHeaders?: boolean;
960
- use?: Middleware[];
961
- path?: string;
962
- } extends infer T_1 ? { [K_1 in keyof T_1 as {
963
- body: InferBodyInput<Options>;
964
- method: InferInputMethod<Options>;
965
- query: InferQueryInput<Options>;
966
- params: InferParam<Path>;
967
- request: InferRequest<Options>;
968
- headers: InferHeadersInput<Options>;
969
- asResponse?: boolean;
970
- returnHeaders?: boolean;
971
- use?: Middleware[];
972
- path?: string;
973
- }[K_1] extends never ? never : undefined extends {
974
- body: InferBodyInput<Options>;
975
- method: InferInputMethod<Options>;
976
- query: InferQueryInput<Options>;
977
- params: InferParam<Path>;
978
- request: InferRequest<Options>;
979
- headers: InferHeadersInput<Options>;
980
- asResponse?: boolean;
981
- returnHeaders?: boolean;
982
- use?: Middleware[];
983
- path?: string;
984
- }[K_1] ? never : K_1]: {
985
- body: InferBodyInput<Options>;
986
- method: InferInputMethod<Options>;
987
- query: InferQueryInput<Options>;
988
- params: InferParam<Path>;
989
- request: InferRequest<Options>;
990
- headers: InferHeadersInput<Options>;
991
- asResponse?: boolean;
992
- returnHeaders?: boolean;
993
- use?: Middleware[];
994
- path?: string;
995
- }[K_1]; } : never) & ({
996
- body: InferBodyInput<Options>;
997
- method: InferInputMethod<Options>;
998
- query: InferQueryInput<Options>;
999
- params: InferParam<Path>;
1000
- request: InferRequest<Options>;
1001
- headers: InferHeadersInput<Options>;
1002
- asResponse?: boolean;
1003
- returnHeaders?: boolean;
1004
- use?: Middleware[];
1005
- path?: string;
1006
- } extends infer T_2 ? { [K_2 in keyof T_2 as undefined extends {
1007
- body: InferBodyInput<Options>;
1008
- method: InferInputMethod<Options>;
1009
- query: InferQueryInput<Options>;
1010
- params: InferParam<Path>;
1011
- request: InferRequest<Options>;
1012
- headers: InferHeadersInput<Options>;
1013
- asResponse?: boolean;
1014
- returnHeaders?: boolean;
1015
- use?: Middleware[];
1016
- path?: string;
1017
- }[K_2] ? K_2 : never]?: {
1018
- body: InferBodyInput<Options>;
1019
- method: InferInputMethod<Options>;
1020
- query: InferQueryInput<Options>;
1021
- params: InferParam<Path>;
1022
- request: InferRequest<Options>;
1023
- headers: InferHeadersInput<Options>;
1024
- asResponse?: boolean;
1025
- returnHeaders?: boolean;
1026
- use?: Middleware[];
1027
- path?: string;
1028
- }[K_2] | undefined; } : never))[K]; } : never> extends true ? [({
1029
- body: InferBodyInput<Options>;
1030
- method: InferInputMethod<Options>;
1031
- query: InferQueryInput<Options>;
1032
- params: InferParam<Path>;
1033
- request: InferRequest<Options>;
1034
- headers: InferHeadersInput<Options>;
1035
- asResponse?: boolean;
1036
- returnHeaders?: boolean;
1037
- use?: Middleware[];
1038
- path?: string;
1039
- } extends infer T_8 ? { [K_1 in keyof T_8 as {
1040
- body: InferBodyInput<Options>;
1041
- method: InferInputMethod<Options>;
1042
- query: InferQueryInput<Options>;
1043
- params: InferParam<Path>;
1044
- request: InferRequest<Options>;
1045
- headers: InferHeadersInput<Options>;
1046
- asResponse?: boolean;
1047
- returnHeaders?: boolean;
1048
- use?: Middleware[];
1049
- path?: string;
1050
- }[K_1] extends never ? never : undefined extends {
1051
- body: InferBodyInput<Options>;
1052
- method: InferInputMethod<Options>;
1053
- query: InferQueryInput<Options>;
1054
- params: InferParam<Path>;
1055
- request: InferRequest<Options>;
1056
- headers: InferHeadersInput<Options>;
1057
- asResponse?: boolean;
1058
- returnHeaders?: boolean;
1059
- use?: Middleware[];
1060
- path?: string;
1061
- }[K_1] ? never : K_1]: {
1062
- body: InferBodyInput<Options>;
1063
- method: InferInputMethod<Options>;
1064
- query: InferQueryInput<Options>;
1065
- params: InferParam<Path>;
1066
- request: InferRequest<Options>;
1067
- headers: InferHeadersInput<Options>;
1068
- asResponse?: boolean;
1069
- returnHeaders?: boolean;
1070
- use?: Middleware[];
1071
- path?: string;
1072
- }[K_1]; } : never) & ({
1073
- body: InferBodyInput<Options>;
1074
- method: InferInputMethod<Options>;
1075
- query: InferQueryInput<Options>;
1076
- params: InferParam<Path>;
1077
- request: InferRequest<Options>;
1078
- headers: InferHeadersInput<Options>;
1079
- asResponse?: boolean;
1080
- returnHeaders?: boolean;
1081
- use?: Middleware[];
1082
- path?: string;
1083
- } extends infer T_9 ? { [K_2 in keyof T_9 as undefined extends {
1084
- body: InferBodyInput<Options>;
1085
- method: InferInputMethod<Options>;
1086
- query: InferQueryInput<Options>;
1087
- params: InferParam<Path>;
1088
- request: InferRequest<Options>;
1089
- headers: InferHeadersInput<Options>;
1090
- asResponse?: boolean;
1091
- returnHeaders?: boolean;
1092
- use?: Middleware[];
1093
- path?: string;
1094
- }[K_2] ? K_2 : never]?: {
1095
- body: InferBodyInput<Options>;
1096
- method: InferInputMethod<Options>;
1097
- query: InferQueryInput<Options>;
1098
- params: InferParam<Path>;
1099
- request: InferRequest<Options>;
1100
- headers: InferHeadersInput<Options>;
1101
- asResponse?: boolean;
1102
- returnHeaders?: boolean;
1103
- use?: Middleware[];
1104
- path?: string;
1105
- }[K_2] | undefined; } : never) extends infer T_5 ? { [K in keyof T_5]: (({
1106
- body: InferBodyInput<Options>;
1107
- method: InferInputMethod<Options>;
1108
- query: InferQueryInput<Options>;
1109
- params: InferParam<Path>;
1110
- request: InferRequest<Options>;
1111
- headers: InferHeadersInput<Options>;
1112
- asResponse?: boolean;
1113
- returnHeaders?: boolean;
1114
- use?: Middleware[];
1115
- path?: string;
1116
- } extends infer T_6 ? { [K_1 in keyof T_6 as {
1117
- body: InferBodyInput<Options>;
1118
- method: InferInputMethod<Options>;
1119
- query: InferQueryInput<Options>;
1120
- params: InferParam<Path>;
1121
- request: InferRequest<Options>;
1122
- headers: InferHeadersInput<Options>;
1123
- asResponse?: boolean;
1124
- returnHeaders?: boolean;
1125
- use?: Middleware[];
1126
- path?: string;
1127
- }[K_1] extends never ? never : undefined extends {
1128
- body: InferBodyInput<Options>;
1129
- method: InferInputMethod<Options>;
1130
- query: InferQueryInput<Options>;
1131
- params: InferParam<Path>;
1132
- request: InferRequest<Options>;
1133
- headers: InferHeadersInput<Options>;
1134
- asResponse?: boolean;
1135
- returnHeaders?: boolean;
1136
- use?: Middleware[];
1137
- path?: string;
1138
- }[K_1] ? never : K_1]: {
1139
- body: InferBodyInput<Options>;
1140
- method: InferInputMethod<Options>;
1141
- query: InferQueryInput<Options>;
1142
- params: InferParam<Path>;
1143
- request: InferRequest<Options>;
1144
- headers: InferHeadersInput<Options>;
1145
- asResponse?: boolean;
1146
- returnHeaders?: boolean;
1147
- use?: Middleware[];
1148
- path?: string;
1149
- }[K_1]; } : never) & ({
1150
- body: InferBodyInput<Options>;
1151
- method: InferInputMethod<Options>;
1152
- query: InferQueryInput<Options>;
1153
- params: InferParam<Path>;
1154
- request: InferRequest<Options>;
1155
- headers: InferHeadersInput<Options>;
1156
- asResponse?: boolean;
1157
- returnHeaders?: boolean;
1158
- use?: Middleware[];
1159
- path?: string;
1160
- } extends infer T_7 ? { [K_2 in keyof T_7 as undefined extends {
1161
- body: InferBodyInput<Options>;
1162
- method: InferInputMethod<Options>;
1163
- query: InferQueryInput<Options>;
1164
- params: InferParam<Path>;
1165
- request: InferRequest<Options>;
1166
- headers: InferHeadersInput<Options>;
1167
- asResponse?: boolean;
1168
- returnHeaders?: boolean;
1169
- use?: Middleware[];
1170
- path?: string;
1171
- }[K_2] ? K_2 : never]?: {
1172
- body: InferBodyInput<Options>;
1173
- method: InferInputMethod<Options>;
1174
- query: InferQueryInput<Options>;
1175
- params: InferParam<Path>;
1176
- request: InferRequest<Options>;
1177
- headers: InferHeadersInput<Options>;
1178
- asResponse?: boolean;
1179
- returnHeaders?: boolean;
1180
- use?: Middleware[];
1181
- path?: string;
1182
- }[K_2] | undefined; } : never))[K]; } : never] : [(({
1183
- body: InferBodyInput<Options>;
1184
- method: InferInputMethod<Options>;
1185
- query: InferQueryInput<Options>;
1186
- params: InferParam<Path>;
1187
- request: InferRequest<Options>;
1188
- headers: InferHeadersInput<Options>;
1189
- asResponse?: boolean;
1190
- returnHeaders?: boolean;
1191
- use?: Middleware[];
1192
- path?: string;
1193
- } extends infer T_8 ? { [K_1 in keyof T_8 as {
1194
- body: InferBodyInput<Options>;
1195
- method: InferInputMethod<Options>;
1196
- query: InferQueryInput<Options>;
1197
- params: InferParam<Path>;
1198
- request: InferRequest<Options>;
1199
- headers: InferHeadersInput<Options>;
1200
- asResponse?: boolean;
1201
- returnHeaders?: boolean;
1202
- use?: Middleware[];
1203
- path?: string;
1204
- }[K_1] extends never ? never : undefined extends {
1205
- body: InferBodyInput<Options>;
1206
- method: InferInputMethod<Options>;
1207
- query: InferQueryInput<Options>;
1208
- params: InferParam<Path>;
1209
- request: InferRequest<Options>;
1210
- headers: InferHeadersInput<Options>;
1211
- asResponse?: boolean;
1212
- returnHeaders?: boolean;
1213
- use?: Middleware[];
1214
- path?: string;
1215
- }[K_1] ? never : K_1]: {
1216
- body: InferBodyInput<Options>;
1217
- method: InferInputMethod<Options>;
1218
- query: InferQueryInput<Options>;
1219
- params: InferParam<Path>;
1220
- request: InferRequest<Options>;
1221
- headers: InferHeadersInput<Options>;
1222
- asResponse?: boolean;
1223
- returnHeaders?: boolean;
1224
- use?: Middleware[];
1225
- path?: string;
1226
- }[K_1]; } : never) & ({
1227
- body: InferBodyInput<Options>;
1228
- method: InferInputMethod<Options>;
1229
- query: InferQueryInput<Options>;
1230
- params: InferParam<Path>;
1231
- request: InferRequest<Options>;
1232
- headers: InferHeadersInput<Options>;
1233
- asResponse?: boolean;
1234
- returnHeaders?: boolean;
1235
- use?: Middleware[];
1236
- path?: string;
1237
- } extends infer T_9 ? { [K_2 in keyof T_9 as undefined extends {
1238
- body: InferBodyInput<Options>;
1239
- method: InferInputMethod<Options>;
1240
- query: InferQueryInput<Options>;
1241
- params: InferParam<Path>;
1242
- request: InferRequest<Options>;
1243
- headers: InferHeadersInput<Options>;
1244
- asResponse?: boolean;
1245
- returnHeaders?: boolean;
1246
- use?: Middleware[];
1247
- path?: string;
1248
- }[K_2] ? K_2 : never]?: {
1249
- body: InferBodyInput<Options>;
1250
- method: InferInputMethod<Options>;
1251
- query: InferQueryInput<Options>;
1252
- params: InferParam<Path>;
1253
- request: InferRequest<Options>;
1254
- headers: InferHeadersInput<Options>;
1255
- asResponse?: boolean;
1256
- returnHeaders?: boolean;
1257
- use?: Middleware[];
1258
- path?: string;
1259
- }[K_2] | undefined; } : never) extends infer T_5 ? { [K in keyof T_5]: (({
1260
- body: InferBodyInput<Options>;
1261
- method: InferInputMethod<Options>;
1262
- query: InferQueryInput<Options>;
1263
- params: InferParam<Path>;
1264
- request: InferRequest<Options>;
1265
- headers: InferHeadersInput<Options>;
1266
- asResponse?: boolean;
1267
- returnHeaders?: boolean;
1268
- use?: Middleware[];
1269
- path?: string;
1270
- } extends infer T_6 ? { [K_1 in keyof T_6 as {
1271
- body: InferBodyInput<Options>;
1272
- method: InferInputMethod<Options>;
1273
- query: InferQueryInput<Options>;
1274
- params: InferParam<Path>;
1275
- request: InferRequest<Options>;
1276
- headers: InferHeadersInput<Options>;
1277
- asResponse?: boolean;
1278
- returnHeaders?: boolean;
1279
- use?: Middleware[];
1280
- path?: string;
1281
- }[K_1] extends never ? never : undefined extends {
1282
- body: InferBodyInput<Options>;
1283
- method: InferInputMethod<Options>;
1284
- query: InferQueryInput<Options>;
1285
- params: InferParam<Path>;
1286
- request: InferRequest<Options>;
1287
- headers: InferHeadersInput<Options>;
1288
- asResponse?: boolean;
1289
- returnHeaders?: boolean;
1290
- use?: Middleware[];
1291
- path?: string;
1292
- }[K_1] ? never : K_1]: {
1293
- body: InferBodyInput<Options>;
1294
- method: InferInputMethod<Options>;
1295
- query: InferQueryInput<Options>;
1296
- params: InferParam<Path>;
1297
- request: InferRequest<Options>;
1298
- headers: InferHeadersInput<Options>;
1299
- asResponse?: boolean;
1300
- returnHeaders?: boolean;
1301
- use?: Middleware[];
1302
- path?: string;
1303
- }[K_1]; } : never) & ({
1304
- body: InferBodyInput<Options>;
1305
- method: InferInputMethod<Options>;
1306
- query: InferQueryInput<Options>;
1307
- params: InferParam<Path>;
1308
- request: InferRequest<Options>;
1309
- headers: InferHeadersInput<Options>;
1310
- asResponse?: boolean;
1311
- returnHeaders?: boolean;
1312
- use?: Middleware[];
1313
- path?: string;
1314
- } extends infer T_7 ? { [K_2 in keyof T_7 as undefined extends {
1315
- body: InferBodyInput<Options>;
1316
- method: InferInputMethod<Options>;
1317
- query: InferQueryInput<Options>;
1318
- params: InferParam<Path>;
1319
- request: InferRequest<Options>;
1320
- headers: InferHeadersInput<Options>;
1321
- asResponse?: boolean;
1322
- returnHeaders?: boolean;
1323
- use?: Middleware[];
1324
- path?: string;
1325
- }[K_2] ? K_2 : never]?: {
1326
- body: InferBodyInput<Options>;
1327
- method: InferInputMethod<Options>;
1328
- query: InferQueryInput<Options>;
1329
- params: InferParam<Path>;
1330
- request: InferRequest<Options>;
1331
- headers: InferHeadersInput<Options>;
1332
- asResponse?: boolean;
1333
- returnHeaders?: boolean;
1334
- use?: Middleware[];
1335
- path?: string;
1336
- }[K_2] | undefined; } : never))[K]; } : never)?]>(...inputCtx: C): Promise<C extends [{
1337
- asResponse: true;
1338
- }] ? Response : C extends [{
1339
- returnHeaders: true;
1340
- }] ? {
1341
- headers: Headers;
1342
- response: R;
1343
- } : R>;
1344
- options: Options;
1345
- path: Path;
1346
- };
1347
- create<E extends {
1348
- use?: Middleware[];
1349
- }>(opts?: E): <Path extends string, Opts extends EndpointOptions, R>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, InferUse<E["use"]>>) => Promise<R>) => {
1350
- <C extends HasRequiredKeys<({
1351
- body: InferBodyInput<Opts & {
1352
- use: any[];
1353
- }>;
1354
- method: InferInputMethod<Opts & {
1355
- use: any[];
1356
- }>;
1357
- query: InferQueryInput<Opts & {
1358
- use: any[];
1359
- }>;
1360
- params: InferParam<Path>;
1361
- request: InferRequest<Opts & {
1362
- use: any[];
1363
- }>;
1364
- headers: InferHeadersInput<Opts & {
1365
- use: any[];
1366
- }>;
1367
- asResponse?: boolean;
1368
- returnHeaders?: boolean;
1369
- use?: Middleware[];
1370
- path?: string;
1371
- } extends infer T_3 ? { [K_1 in keyof T_3 as {
1372
- body: InferBodyInput<Opts & {
1373
- use: any[];
1374
- }>;
1375
- method: InferInputMethod<Opts & {
1376
- use: any[];
1377
- }>;
1378
- query: InferQueryInput<Opts & {
1379
- use: any[];
1380
- }>;
1381
- params: InferParam<Path>;
1382
- request: InferRequest<Opts & {
1383
- use: any[];
1384
- }>;
1385
- headers: InferHeadersInput<Opts & {
1386
- use: any[];
1387
- }>;
1388
- asResponse?: boolean;
1389
- returnHeaders?: boolean;
1390
- use?: Middleware[];
1391
- path?: string;
1392
- }[K_1] extends never ? never : undefined extends {
1393
- body: InferBodyInput<Opts & {
1394
- use: any[];
1395
- }>;
1396
- method: InferInputMethod<Opts & {
1397
- use: any[];
1398
- }>;
1399
- query: InferQueryInput<Opts & {
1400
- use: any[];
1401
- }>;
1402
- params: InferParam<Path>;
1403
- request: InferRequest<Opts & {
1404
- use: any[];
1405
- }>;
1406
- headers: InferHeadersInput<Opts & {
1407
- use: any[];
1408
- }>;
1409
- asResponse?: boolean;
1410
- returnHeaders?: boolean;
1411
- use?: Middleware[];
1412
- path?: string;
1413
- }[K_1] ? never : K_1]: {
1414
- body: InferBodyInput<Opts & {
1415
- use: any[];
1416
- }>;
1417
- method: InferInputMethod<Opts & {
1418
- use: any[];
1419
- }>;
1420
- query: InferQueryInput<Opts & {
1421
- use: any[];
1422
- }>;
1423
- params: InferParam<Path>;
1424
- request: InferRequest<Opts & {
1425
- use: any[];
1426
- }>;
1427
- headers: InferHeadersInput<Opts & {
1428
- use: any[];
1429
- }>;
1430
- asResponse?: boolean;
1431
- returnHeaders?: boolean;
1432
- use?: Middleware[];
1433
- path?: string;
1434
- }[K_1]; } : never) & ({
1435
- body: InferBodyInput<Opts & {
1436
- use: any[];
1437
- }>;
1438
- method: InferInputMethod<Opts & {
1439
- use: any[];
1440
- }>;
1441
- query: InferQueryInput<Opts & {
1442
- use: any[];
1443
- }>;
1444
- params: InferParam<Path>;
1445
- request: InferRequest<Opts & {
1446
- use: any[];
1447
- }>;
1448
- headers: InferHeadersInput<Opts & {
1449
- use: any[];
1450
- }>;
1451
- asResponse?: boolean;
1452
- returnHeaders?: boolean;
1453
- use?: Middleware[];
1454
- path?: string;
1455
- } extends infer T_4 ? { [K_2 in keyof T_4 as undefined extends {
1456
- body: InferBodyInput<Opts & {
1457
- use: any[];
1458
- }>;
1459
- method: InferInputMethod<Opts & {
1460
- use: any[];
1461
- }>;
1462
- query: InferQueryInput<Opts & {
1463
- use: any[];
1464
- }>;
1465
- params: InferParam<Path>;
1466
- request: InferRequest<Opts & {
1467
- use: any[];
1468
- }>;
1469
- headers: InferHeadersInput<Opts & {
1470
- use: any[];
1471
- }>;
1472
- asResponse?: boolean;
1473
- returnHeaders?: boolean;
1474
- use?: Middleware[];
1475
- path?: string;
1476
- }[K_2] ? K_2 : never]?: {
1477
- body: InferBodyInput<Opts & {
1478
- use: any[];
1479
- }>;
1480
- method: InferInputMethod<Opts & {
1481
- use: any[];
1482
- }>;
1483
- query: InferQueryInput<Opts & {
1484
- use: any[];
1485
- }>;
1486
- params: InferParam<Path>;
1487
- request: InferRequest<Opts & {
1488
- use: any[];
1489
- }>;
1490
- headers: InferHeadersInput<Opts & {
1491
- use: any[];
1492
- }>;
1493
- asResponse?: boolean;
1494
- returnHeaders?: boolean;
1495
- use?: Middleware[];
1496
- path?: string;
1497
- }[K_2] | undefined; } : never) extends infer T ? { [K in keyof T]: (({
1498
- body: InferBodyInput<Opts & {
1499
- use: any[];
1500
- }>;
1501
- method: InferInputMethod<Opts & {
1502
- use: any[];
1503
- }>;
1504
- query: InferQueryInput<Opts & {
1505
- use: any[];
1506
- }>;
1507
- params: InferParam<Path>;
1508
- request: InferRequest<Opts & {
1509
- use: any[];
1510
- }>;
1511
- headers: InferHeadersInput<Opts & {
1512
- use: any[];
1513
- }>;
1514
- asResponse?: boolean;
1515
- returnHeaders?: boolean;
1516
- use?: Middleware[];
1517
- path?: string;
1518
- } extends infer T_1 ? { [K_1 in keyof T_1 as {
1519
- body: InferBodyInput<Opts & {
1520
- use: any[];
1521
- }>;
1522
- method: InferInputMethod<Opts & {
1523
- use: any[];
1524
- }>;
1525
- query: InferQueryInput<Opts & {
1526
- use: any[];
1527
- }>;
1528
- params: InferParam<Path>;
1529
- request: InferRequest<Opts & {
1530
- use: any[];
1531
- }>;
1532
- headers: InferHeadersInput<Opts & {
1533
- use: any[];
1534
- }>;
1535
- asResponse?: boolean;
1536
- returnHeaders?: boolean;
1537
- use?: Middleware[];
1538
- path?: string;
1539
- }[K_1] extends never ? never : undefined extends {
1540
- body: InferBodyInput<Opts & {
1541
- use: any[];
1542
- }>;
1543
- method: InferInputMethod<Opts & {
1544
- use: any[];
1545
- }>;
1546
- query: InferQueryInput<Opts & {
1547
- use: any[];
1548
- }>;
1549
- params: InferParam<Path>;
1550
- request: InferRequest<Opts & {
1551
- use: any[];
1552
- }>;
1553
- headers: InferHeadersInput<Opts & {
1554
- use: any[];
1555
- }>;
1556
- asResponse?: boolean;
1557
- returnHeaders?: boolean;
1558
- use?: Middleware[];
1559
- path?: string;
1560
- }[K_1] ? never : K_1]: {
1561
- body: InferBodyInput<Opts & {
1562
- use: any[];
1563
- }>;
1564
- method: InferInputMethod<Opts & {
1565
- use: any[];
1566
- }>;
1567
- query: InferQueryInput<Opts & {
1568
- use: any[];
1569
- }>;
1570
- params: InferParam<Path>;
1571
- request: InferRequest<Opts & {
1572
- use: any[];
1573
- }>;
1574
- headers: InferHeadersInput<Opts & {
1575
- use: any[];
1576
- }>;
1577
- asResponse?: boolean;
1578
- returnHeaders?: boolean;
1579
- use?: Middleware[];
1580
- path?: string;
1581
- }[K_1]; } : never) & ({
1582
- body: InferBodyInput<Opts & {
1583
- use: any[];
1584
- }>;
1585
- method: InferInputMethod<Opts & {
1586
- use: any[];
1587
- }>;
1588
- query: InferQueryInput<Opts & {
1589
- use: any[];
1590
- }>;
1591
- params: InferParam<Path>;
1592
- request: InferRequest<Opts & {
1593
- use: any[];
1594
- }>;
1595
- headers: InferHeadersInput<Opts & {
1596
- use: any[];
1597
- }>;
1598
- asResponse?: boolean;
1599
- returnHeaders?: boolean;
1600
- use?: Middleware[];
1601
- path?: string;
1602
- } extends infer T_2 ? { [K_2 in keyof T_2 as undefined extends {
1603
- body: InferBodyInput<Opts & {
1604
- use: any[];
1605
- }>;
1606
- method: InferInputMethod<Opts & {
1607
- use: any[];
1608
- }>;
1609
- query: InferQueryInput<Opts & {
1610
- use: any[];
1611
- }>;
1612
- params: InferParam<Path>;
1613
- request: InferRequest<Opts & {
1614
- use: any[];
1615
- }>;
1616
- headers: InferHeadersInput<Opts & {
1617
- use: any[];
1618
- }>;
1619
- asResponse?: boolean;
1620
- returnHeaders?: boolean;
1621
- use?: Middleware[];
1622
- path?: string;
1623
- }[K_2] ? K_2 : never]?: {
1624
- body: InferBodyInput<Opts & {
1625
- use: any[];
1626
- }>;
1627
- method: InferInputMethod<Opts & {
1628
- use: any[];
1629
- }>;
1630
- query: InferQueryInput<Opts & {
1631
- use: any[];
1632
- }>;
1633
- params: InferParam<Path>;
1634
- request: InferRequest<Opts & {
1635
- use: any[];
1636
- }>;
1637
- headers: InferHeadersInput<Opts & {
1638
- use: any[];
1639
- }>;
1640
- asResponse?: boolean;
1641
- returnHeaders?: boolean;
1642
- use?: Middleware[];
1643
- path?: string;
1644
- }[K_2] | undefined; } : never))[K]; } : never> extends true ? [({
1645
- body: InferBodyInput<Opts & {
1646
- use: any[];
1647
- }>;
1648
- method: InferInputMethod<Opts & {
1649
- use: any[];
1650
- }>;
1651
- query: InferQueryInput<Opts & {
1652
- use: any[];
1653
- }>;
1654
- params: InferParam<Path>;
1655
- request: InferRequest<Opts & {
1656
- use: any[];
1657
- }>;
1658
- headers: InferHeadersInput<Opts & {
1659
- use: any[];
1660
- }>;
1661
- asResponse?: boolean;
1662
- returnHeaders?: boolean;
1663
- use?: Middleware[];
1664
- path?: string;
1665
- } extends infer T_8 ? { [K_1 in keyof T_8 as {
1666
- body: InferBodyInput<Opts & {
1667
- use: any[];
1668
- }>;
1669
- method: InferInputMethod<Opts & {
1670
- use: any[];
1671
- }>;
1672
- query: InferQueryInput<Opts & {
1673
- use: any[];
1674
- }>;
1675
- params: InferParam<Path>;
1676
- request: InferRequest<Opts & {
1677
- use: any[];
1678
- }>;
1679
- headers: InferHeadersInput<Opts & {
1680
- use: any[];
1681
- }>;
1682
- asResponse?: boolean;
1683
- returnHeaders?: boolean;
1684
- use?: Middleware[];
1685
- path?: string;
1686
- }[K_1] extends never ? never : undefined extends {
1687
- body: InferBodyInput<Opts & {
1688
- use: any[];
1689
- }>;
1690
- method: InferInputMethod<Opts & {
1691
- use: any[];
1692
- }>;
1693
- query: InferQueryInput<Opts & {
1694
- use: any[];
1695
- }>;
1696
- params: InferParam<Path>;
1697
- request: InferRequest<Opts & {
1698
- use: any[];
1699
- }>;
1700
- headers: InferHeadersInput<Opts & {
1701
- use: any[];
1702
- }>;
1703
- asResponse?: boolean;
1704
- returnHeaders?: boolean;
1705
- use?: Middleware[];
1706
- path?: string;
1707
- }[K_1] ? never : K_1]: {
1708
- body: InferBodyInput<Opts & {
1709
- use: any[];
1710
- }>;
1711
- method: InferInputMethod<Opts & {
1712
- use: any[];
1713
- }>;
1714
- query: InferQueryInput<Opts & {
1715
- use: any[];
1716
- }>;
1717
- params: InferParam<Path>;
1718
- request: InferRequest<Opts & {
1719
- use: any[];
1720
- }>;
1721
- headers: InferHeadersInput<Opts & {
1722
- use: any[];
1723
- }>;
1724
- asResponse?: boolean;
1725
- returnHeaders?: boolean;
1726
- use?: Middleware[];
1727
- path?: string;
1728
- }[K_1]; } : never) & ({
1729
- body: InferBodyInput<Opts & {
1730
- use: any[];
1731
- }>;
1732
- method: InferInputMethod<Opts & {
1733
- use: any[];
1734
- }>;
1735
- query: InferQueryInput<Opts & {
1736
- use: any[];
1737
- }>;
1738
- params: InferParam<Path>;
1739
- request: InferRequest<Opts & {
1740
- use: any[];
1741
- }>;
1742
- headers: InferHeadersInput<Opts & {
1743
- use: any[];
1744
- }>;
1745
- asResponse?: boolean;
1746
- returnHeaders?: boolean;
1747
- use?: Middleware[];
1748
- path?: string;
1749
- } extends infer T_9 ? { [K_2 in keyof T_9 as undefined extends {
1750
- body: InferBodyInput<Opts & {
1751
- use: any[];
1752
- }>;
1753
- method: InferInputMethod<Opts & {
1754
- use: any[];
1755
- }>;
1756
- query: InferQueryInput<Opts & {
1757
- use: any[];
1758
- }>;
1759
- params: InferParam<Path>;
1760
- request: InferRequest<Opts & {
1761
- use: any[];
1762
- }>;
1763
- headers: InferHeadersInput<Opts & {
1764
- use: any[];
1765
- }>;
1766
- asResponse?: boolean;
1767
- returnHeaders?: boolean;
1768
- use?: Middleware[];
1769
- path?: string;
1770
- }[K_2] ? K_2 : never]?: {
1771
- body: InferBodyInput<Opts & {
1772
- use: any[];
1773
- }>;
1774
- method: InferInputMethod<Opts & {
1775
- use: any[];
1776
- }>;
1777
- query: InferQueryInput<Opts & {
1778
- use: any[];
1779
- }>;
1780
- params: InferParam<Path>;
1781
- request: InferRequest<Opts & {
1782
- use: any[];
1783
- }>;
1784
- headers: InferHeadersInput<Opts & {
1785
- use: any[];
1786
- }>;
1787
- asResponse?: boolean;
1788
- returnHeaders?: boolean;
1789
- use?: Middleware[];
1790
- path?: string;
1791
- }[K_2] | undefined; } : never) extends infer T_5 ? { [K in keyof T_5]: (({
1792
- body: InferBodyInput<Opts & {
1793
- use: any[];
1794
- }>;
1795
- method: InferInputMethod<Opts & {
1796
- use: any[];
1797
- }>;
1798
- query: InferQueryInput<Opts & {
1799
- use: any[];
1800
- }>;
1801
- params: InferParam<Path>;
1802
- request: InferRequest<Opts & {
1803
- use: any[];
1804
- }>;
1805
- headers: InferHeadersInput<Opts & {
1806
- use: any[];
1807
- }>;
1808
- asResponse?: boolean;
1809
- returnHeaders?: boolean;
1810
- use?: Middleware[];
1811
- path?: string;
1812
- } extends infer T_6 ? { [K_1 in keyof T_6 as {
1813
- body: InferBodyInput<Opts & {
1814
- use: any[];
1815
- }>;
1816
- method: InferInputMethod<Opts & {
1817
- use: any[];
1818
- }>;
1819
- query: InferQueryInput<Opts & {
1820
- use: any[];
1821
- }>;
1822
- params: InferParam<Path>;
1823
- request: InferRequest<Opts & {
1824
- use: any[];
1825
- }>;
1826
- headers: InferHeadersInput<Opts & {
1827
- use: any[];
1828
- }>;
1829
- asResponse?: boolean;
1830
- returnHeaders?: boolean;
1831
- use?: Middleware[];
1832
- path?: string;
1833
- }[K_1] extends never ? never : undefined extends {
1834
- body: InferBodyInput<Opts & {
1835
- use: any[];
1836
- }>;
1837
- method: InferInputMethod<Opts & {
1838
- use: any[];
1839
- }>;
1840
- query: InferQueryInput<Opts & {
1841
- use: any[];
1842
- }>;
1843
- params: InferParam<Path>;
1844
- request: InferRequest<Opts & {
1845
- use: any[];
1846
- }>;
1847
- headers: InferHeadersInput<Opts & {
1848
- use: any[];
1849
- }>;
1850
- asResponse?: boolean;
1851
- returnHeaders?: boolean;
1852
- use?: Middleware[];
1853
- path?: string;
1854
- }[K_1] ? never : K_1]: {
1855
- body: InferBodyInput<Opts & {
1856
- use: any[];
1857
- }>;
1858
- method: InferInputMethod<Opts & {
1859
- use: any[];
1860
- }>;
1861
- query: InferQueryInput<Opts & {
1862
- use: any[];
1863
- }>;
1864
- params: InferParam<Path>;
1865
- request: InferRequest<Opts & {
1866
- use: any[];
1867
- }>;
1868
- headers: InferHeadersInput<Opts & {
1869
- use: any[];
1870
- }>;
1871
- asResponse?: boolean;
1872
- returnHeaders?: boolean;
1873
- use?: Middleware[];
1874
- path?: string;
1875
- }[K_1]; } : never) & ({
1876
- body: InferBodyInput<Opts & {
1877
- use: any[];
1878
- }>;
1879
- method: InferInputMethod<Opts & {
1880
- use: any[];
1881
- }>;
1882
- query: InferQueryInput<Opts & {
1883
- use: any[];
1884
- }>;
1885
- params: InferParam<Path>;
1886
- request: InferRequest<Opts & {
1887
- use: any[];
1888
- }>;
1889
- headers: InferHeadersInput<Opts & {
1890
- use: any[];
1891
- }>;
1892
- asResponse?: boolean;
1893
- returnHeaders?: boolean;
1894
- use?: Middleware[];
1895
- path?: string;
1896
- } extends infer T_7 ? { [K_2 in keyof T_7 as undefined extends {
1897
- body: InferBodyInput<Opts & {
1898
- use: any[];
1899
- }>;
1900
- method: InferInputMethod<Opts & {
1901
- use: any[];
1902
- }>;
1903
- query: InferQueryInput<Opts & {
1904
- use: any[];
1905
- }>;
1906
- params: InferParam<Path>;
1907
- request: InferRequest<Opts & {
1908
- use: any[];
1909
- }>;
1910
- headers: InferHeadersInput<Opts & {
1911
- use: any[];
1912
- }>;
1913
- asResponse?: boolean;
1914
- returnHeaders?: boolean;
1915
- use?: Middleware[];
1916
- path?: string;
1917
- }[K_2] ? K_2 : never]?: {
1918
- body: InferBodyInput<Opts & {
1919
- use: any[];
1920
- }>;
1921
- method: InferInputMethod<Opts & {
1922
- use: any[];
1923
- }>;
1924
- query: InferQueryInput<Opts & {
1925
- use: any[];
1926
- }>;
1927
- params: InferParam<Path>;
1928
- request: InferRequest<Opts & {
1929
- use: any[];
1930
- }>;
1931
- headers: InferHeadersInput<Opts & {
1932
- use: any[];
1933
- }>;
1934
- asResponse?: boolean;
1935
- returnHeaders?: boolean;
1936
- use?: Middleware[];
1937
- path?: string;
1938
- }[K_2] | undefined; } : never))[K]; } : never] : [((({
1939
- body: InferBodyInput<Opts & {
1940
- use: any[];
1941
- }>;
1942
- method: InferInputMethod<Opts & {
1943
- use: any[];
1944
- }>;
1945
- query: InferQueryInput<Opts & {
1946
- use: any[];
1947
- }>;
1948
- params: InferParam<Path>;
1949
- request: InferRequest<Opts & {
1950
- use: any[];
1951
- }>;
1952
- headers: InferHeadersInput<Opts & {
1953
- use: any[];
1954
- }>;
1955
- asResponse?: boolean;
1956
- returnHeaders?: boolean;
1957
- use?: Middleware[];
1958
- path?: string;
1959
- } extends infer T_13 ? { [K_1 in keyof T_13 as {
1960
- body: InferBodyInput<Opts & {
1961
- use: any[];
1962
- }>;
1963
- method: InferInputMethod<Opts & {
1964
- use: any[];
1965
- }>;
1966
- query: InferQueryInput<Opts & {
1967
- use: any[];
1968
- }>;
1969
- params: InferParam<Path>;
1970
- request: InferRequest<Opts & {
1971
- use: any[];
1972
- }>;
1973
- headers: InferHeadersInput<Opts & {
1974
- use: any[];
1975
- }>;
1976
- asResponse?: boolean;
1977
- returnHeaders?: boolean;
1978
- use?: Middleware[];
1979
- path?: string;
1980
- }[K_1] extends never ? never : undefined extends {
1981
- body: InferBodyInput<Opts & {
1982
- use: any[];
1983
- }>;
1984
- method: InferInputMethod<Opts & {
1985
- use: any[];
1986
- }>;
1987
- query: InferQueryInput<Opts & {
1988
- use: any[];
1989
- }>;
1990
- params: InferParam<Path>;
1991
- request: InferRequest<Opts & {
1992
- use: any[];
1993
- }>;
1994
- headers: InferHeadersInput<Opts & {
1995
- use: any[];
1996
- }>;
1997
- asResponse?: boolean;
1998
- returnHeaders?: boolean;
1999
- use?: Middleware[];
2000
- path?: string;
2001
- }[K_1] ? never : K_1]: {
2002
- body: InferBodyInput<Opts & {
2003
- use: any[];
2004
- }>;
2005
- method: InferInputMethod<Opts & {
2006
- use: any[];
2007
- }>;
2008
- query: InferQueryInput<Opts & {
2009
- use: any[];
2010
- }>;
2011
- params: InferParam<Path>;
2012
- request: InferRequest<Opts & {
2013
- use: any[];
2014
- }>;
2015
- headers: InferHeadersInput<Opts & {
2016
- use: any[];
2017
- }>;
2018
- asResponse?: boolean;
2019
- returnHeaders?: boolean;
2020
- use?: Middleware[];
2021
- path?: string;
2022
- }[K_1]; } : never) & ({
2023
- body: InferBodyInput<Opts & {
2024
- use: any[];
2025
- }>;
2026
- method: InferInputMethod<Opts & {
2027
- use: any[];
2028
- }>;
2029
- query: InferQueryInput<Opts & {
2030
- use: any[];
2031
- }>;
2032
- params: InferParam<Path>;
2033
- request: InferRequest<Opts & {
2034
- use: any[];
2035
- }>;
2036
- headers: InferHeadersInput<Opts & {
2037
- use: any[];
2038
- }>;
2039
- asResponse?: boolean;
2040
- returnHeaders?: boolean;
2041
- use?: Middleware[];
2042
- path?: string;
2043
- } extends infer T_14 ? { [K_2 in keyof T_14 as undefined extends {
2044
- body: InferBodyInput<Opts & {
2045
- use: any[];
2046
- }>;
2047
- method: InferInputMethod<Opts & {
2048
- use: any[];
2049
- }>;
2050
- query: InferQueryInput<Opts & {
2051
- use: any[];
2052
- }>;
2053
- params: InferParam<Path>;
2054
- request: InferRequest<Opts & {
2055
- use: any[];
2056
- }>;
2057
- headers: InferHeadersInput<Opts & {
2058
- use: any[];
2059
- }>;
2060
- asResponse?: boolean;
2061
- returnHeaders?: boolean;
2062
- use?: Middleware[];
2063
- path?: string;
2064
- }[K_2] ? K_2 : never]?: {
2065
- body: InferBodyInput<Opts & {
2066
- use: any[];
2067
- }>;
2068
- method: InferInputMethod<Opts & {
2069
- use: any[];
2070
- }>;
2071
- query: InferQueryInput<Opts & {
2072
- use: any[];
2073
- }>;
2074
- params: InferParam<Path>;
2075
- request: InferRequest<Opts & {
2076
- use: any[];
2077
- }>;
2078
- headers: InferHeadersInput<Opts & {
2079
- use: any[];
2080
- }>;
2081
- asResponse?: boolean;
2082
- returnHeaders?: boolean;
2083
- use?: Middleware[];
2084
- path?: string;
2085
- }[K_2] | undefined; } : never) extends infer T_10 ? { [K in keyof T_10]: (({
2086
- body: InferBodyInput<Opts & {
2087
- use: any[];
2088
- }>;
2089
- method: InferInputMethod<Opts & {
2090
- use: any[];
2091
- }>;
2092
- query: InferQueryInput<Opts & {
2093
- use: any[];
2094
- }>;
2095
- params: InferParam<Path>;
2096
- request: InferRequest<Opts & {
2097
- use: any[];
2098
- }>;
2099
- headers: InferHeadersInput<Opts & {
2100
- use: any[];
2101
- }>;
2102
- asResponse?: boolean;
2103
- returnHeaders?: boolean;
2104
- use?: Middleware[];
2105
- path?: string;
2106
- } extends infer T_11 ? { [K_1 in keyof T_11 as {
2107
- body: InferBodyInput<Opts & {
2108
- use: any[];
2109
- }>;
2110
- method: InferInputMethod<Opts & {
2111
- use: any[];
2112
- }>;
2113
- query: InferQueryInput<Opts & {
2114
- use: any[];
2115
- }>;
2116
- params: InferParam<Path>;
2117
- request: InferRequest<Opts & {
2118
- use: any[];
2119
- }>;
2120
- headers: InferHeadersInput<Opts & {
2121
- use: any[];
2122
- }>;
2123
- asResponse?: boolean;
2124
- returnHeaders?: boolean;
2125
- use?: Middleware[];
2126
- path?: string;
2127
- }[K_1] extends never ? never : undefined extends {
2128
- body: InferBodyInput<Opts & {
2129
- use: any[];
2130
- }>;
2131
- method: InferInputMethod<Opts & {
2132
- use: any[];
2133
- }>;
2134
- query: InferQueryInput<Opts & {
2135
- use: any[];
2136
- }>;
2137
- params: InferParam<Path>;
2138
- request: InferRequest<Opts & {
2139
- use: any[];
2140
- }>;
2141
- headers: InferHeadersInput<Opts & {
2142
- use: any[];
2143
- }>;
2144
- asResponse?: boolean;
2145
- returnHeaders?: boolean;
2146
- use?: Middleware[];
2147
- path?: string;
2148
- }[K_1] ? never : K_1]: {
2149
- body: InferBodyInput<Opts & {
2150
- use: any[];
2151
- }>;
2152
- method: InferInputMethod<Opts & {
2153
- use: any[];
2154
- }>;
2155
- query: InferQueryInput<Opts & {
2156
- use: any[];
2157
- }>;
2158
- params: InferParam<Path>;
2159
- request: InferRequest<Opts & {
2160
- use: any[];
2161
- }>;
2162
- headers: InferHeadersInput<Opts & {
2163
- use: any[];
2164
- }>;
2165
- asResponse?: boolean;
2166
- returnHeaders?: boolean;
2167
- use?: Middleware[];
2168
- path?: string;
2169
- }[K_1]; } : never) & ({
2170
- body: InferBodyInput<Opts & {
2171
- use: any[];
2172
- }>;
2173
- method: InferInputMethod<Opts & {
2174
- use: any[];
2175
- }>;
2176
- query: InferQueryInput<Opts & {
2177
- use: any[];
2178
- }>;
2179
- params: InferParam<Path>;
2180
- request: InferRequest<Opts & {
2181
- use: any[];
2182
- }>;
2183
- headers: InferHeadersInput<Opts & {
2184
- use: any[];
2185
- }>;
2186
- asResponse?: boolean;
2187
- returnHeaders?: boolean;
2188
- use?: Middleware[];
2189
- path?: string;
2190
- } extends infer T_12 ? { [K_2 in keyof T_12 as undefined extends {
2191
- body: InferBodyInput<Opts & {
2192
- use: any[];
2193
- }>;
2194
- method: InferInputMethod<Opts & {
2195
- use: any[];
2196
- }>;
2197
- query: InferQueryInput<Opts & {
2198
- use: any[];
2199
- }>;
2200
- params: InferParam<Path>;
2201
- request: InferRequest<Opts & {
2202
- use: any[];
2203
- }>;
2204
- headers: InferHeadersInput<Opts & {
2205
- use: any[];
2206
- }>;
2207
- asResponse?: boolean;
2208
- returnHeaders?: boolean;
2209
- use?: Middleware[];
2210
- path?: string;
2211
- }[K_2] ? K_2 : never]?: {
2212
- body: InferBodyInput<Opts & {
2213
- use: any[];
2214
- }>;
2215
- method: InferInputMethod<Opts & {
2216
- use: any[];
2217
- }>;
2218
- query: InferQueryInput<Opts & {
2219
- use: any[];
2220
- }>;
2221
- params: InferParam<Path>;
2222
- request: InferRequest<Opts & {
2223
- use: any[];
2224
- }>;
2225
- headers: InferHeadersInput<Opts & {
2226
- use: any[];
2227
- }>;
2228
- asResponse?: boolean;
2229
- returnHeaders?: boolean;
2230
- use?: Middleware[];
2231
- path?: string;
2232
- }[K_2] | undefined; } : never))[K]; } : never) | undefined)?]>(...inputCtx: C): Promise<C extends [{
2233
- asResponse: true;
2234
- }] ? Response : C extends [{
2235
- returnHeaders: true;
2236
- }] ? {
2237
- headers: Headers;
2238
- response: R;
2239
- } : R>;
2240
- options: Opts & {
2241
- use: any[];
2242
- };
2243
- path: Path;
2244
- };
2245
- };
2246
- type Endpoint<Path extends string = string, Options extends EndpointOptions = EndpointOptions, Handler extends (inputCtx: any) => Promise<any> = (inputCtx: any) => Promise<any>> = Handler & {
2247
- options: Options;
2248
- path: Path;
2249
- };
2250
-
2251
- interface RouterConfig {
2252
- throwError?: boolean;
2253
- onError?: (e: unknown) => void | Promise<void> | Response | Promise<Response>;
2254
- basePath?: string;
2255
- routerMiddleware?: Array<{
2256
- path: string;
2257
- middleware: Middleware;
2258
- }>;
2259
- /**
2260
- * additional Context that needs to passed to endpoints
2261
- *
2262
- * this will be available on `ctx.context` on endpoints
2263
- */
2264
- routerContext?: Record<string, any>;
2265
- /**
2266
- * A callback to run before any response
2267
- */
2268
- onResponse?: (res: Response) => any | Promise<any>;
2269
- /**
2270
- * A callback to run before any request
2271
- */
2272
- onRequest?: (req: Request) => any | Promise<any>;
2273
- /**
2274
- * Open API route configuration
2275
- */
2276
- openapi?: {
2277
- /**
2278
- * Disable openapi route
2279
- *
2280
- * @default false
2281
- */
2282
- disabled?: boolean;
2283
- /**
2284
- * A path to display open api using scalar
2285
- *
2286
- * @default "/api/reference"
2287
- */
2288
- path?: string;
2289
- /**
2290
- * Scalar Configuration
2291
- */
2292
- scalar?: {
2293
- /**
2294
- * Title
2295
- * @default "Open API Reference"
2296
- */
2297
- title?: string;
2298
- /**
2299
- * Description
2300
- *
2301
- * @default "Better Call Open API Reference"
2302
- */
2303
- description?: string;
2304
- /**
2305
- * Logo URL
2306
- */
2307
- logo?: string;
2308
- /**
2309
- * Scalar theme
2310
- * @default "saturn"
2311
- */
2312
- theme?: string;
2313
- };
2314
- };
2315
- }
2316
- declare const createRouter: <E extends Record<string, Endpoint>, Config extends RouterConfig>(endpoints: E, config?: Config) => {
2317
- handler: (request: Request) => Promise<Response>;
2318
- endpoints: E;
2319
- };
2320
- type Router = ReturnType<typeof createRouter>;
2321
-
2322
- export { StandardSchemaV1 as $, APIError as A, type InferHeaders as B, type CookiePrefixOptions as C, type InferHeadersInput as D, type EndpointOptions as E, type InferUse as F, type InferMiddlewareBody as G, type HTTPMethod as H, type InferBodyInput as I, type InferMiddlewareQuery as J, type InputContext as K, createInternalContext as L, type MiddlewareOptions as M, type Input as N, type OpenAPISchemaType as O, type Path as P, type RequiredKeysOf as Q, type RouterConfig as R, type Status as S, type HasRequiredKeys as T, type Prettify as U, type IsEmptyObject as V, type UnionToIntersection as W, type MergeObject as X, type InferParamPath as Y, type InferParamWildCard as Z, _statusCode as _, type EndpointContext as a, type Endpoint as b, createEndpoint as c, type MiddlewareResponse as d, type MiddlewareContext as e, createMiddleware as f, type MiddlewareInputContext as g, type Middleware as h, createRouter as i, type Router as j, type CookieOptions as k, getCookieKey as l, serializeSignedCookie as m, type OpenAPIParameter as n, generator as o, parseCookies as p, getHTML as q, type Method as r, serializeCookie as s, type InferBody as t, type InferQueryInput as u, type InferQuery as v, type InferMethod as w, type InferInputMethod as x, type InferParam as y, type InferRequest as z };