better-call 0.2.13-beta.7 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,676 +0,0 @@
1
- import { ZodTypeAny, z, ZodSchema, ZodObject, ZodOptional, ZodError } from 'zod';
2
- import { ZodOpenApiFullMetadata, ZodOpenAPIMetadata } from '@asteasolutions/zod-to-openapi/dist/zod-extensions';
3
- import { ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
- import * as _asteasolutions_zod_to_openapi_dist_openapi_registry from '@asteasolutions/zod-to-openapi/dist/openapi-registry';
5
- import { BufferSource } from 'stream/web';
6
-
7
- /**
8
- * Improve this type if possible
9
- */
10
- type Input<T> = Prettify<{
11
- [K in keyof T as T[K] extends never ? never : undefined extends T[K] ? never : K]: T[K];
12
- } & {
13
- [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
14
- }>;
15
- type RequiredKeysOf<BaseType extends object> = Exclude<{
16
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
17
- }[keyof BaseType], undefined>;
18
- type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
19
- type Prettify<T> = {
20
- [K in keyof T]: T[K];
21
- } & {};
22
- type IsEmptyObject<T> = keyof T extends never ? true : false;
23
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never;
24
-
25
- declare module "zod" {
26
- interface ZodTypeDef {
27
- openapi?: ZodOpenApiFullMetadata;
28
- }
29
- interface ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
30
- openapi<T extends ZodTypeAny>(this: T, metadata: Partial<ZodOpenAPIMetadata<z.input<T>>>): T;
31
- openapi<T extends ZodTypeAny>(this: T, refId: string, metadata?: Partial<ZodOpenAPIMetadata<z.input<T>>>): T;
32
- }
33
- }
34
- type Method = "GET" | "POST" | "PUT" | "DELETE" | "*";
35
- interface EndpointOptions {
36
- /**
37
- * Request Method
38
- */
39
- method: Method | Method[];
40
- /**
41
- * Body Schema
42
- */
43
- body?: ZodSchema;
44
- /**
45
- * Query Schema
46
- */
47
- query?: ZodObject<any> | ZodOptional<ZodObject<any>>;
48
- /**
49
- * If true headers will be required to be passed in the context
50
- */
51
- requireHeaders?: boolean;
52
- /**
53
- * If true request object will be required
54
- */
55
- requireRequest?: boolean;
56
- /**
57
- * Endpoint metadata
58
- */
59
- metadata?: Record<string, any>;
60
- /**
61
- * Middleware to use
62
- */
63
- use?: Endpoint[];
64
- /**
65
- * OpenAPI metadata
66
- */
67
- openAPI?: {
68
- responses: {
69
- [statusCode: string]: ResponseConfig;
70
- };
71
- };
72
- }
73
- type InferBody<Options extends EndpointOptions> = Options["body"] extends ZodSchema<infer T> ? T : never;
74
- type InferQuery<Options extends EndpointOptions> = Options["query"] extends ZodSchema<infer T> ? T : never;
75
- type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
76
- [K in Param | keyof InferParamPath<Rest>]: string;
77
- } : Path extends `${infer _Start}:${infer Param}` ? {
78
- [K in Param]: string;
79
- } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
80
- type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? {
81
- [K in Param | keyof InferParamPath<Rest>]: string;
82
- } : Path extends `${infer _Start}/*` ? {
83
- [K in "_"]: string;
84
- } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
85
- type InferParam<Path extends string> = IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? never : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
86
- type InferRequest<Option extends EndpointOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
87
- type InferHeaders<Option extends EndpointOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
88
- type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Endpoint[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : never;
89
- type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"];
90
-
91
- type Cookie = Record<string, string>;
92
- type SignedCookie = Record<string, string | false>;
93
- type PartitionCookieConstraint = {
94
- partition: true;
95
- secure: true;
96
- } | {
97
- partition?: boolean;
98
- secure?: boolean;
99
- };
100
- type SecureCookieConstraint = {
101
- secure: true;
102
- };
103
- type HostCookieConstraint = {
104
- secure: true;
105
- path: "/";
106
- domain?: undefined;
107
- };
108
- type CookieOptions = {
109
- domain?: string;
110
- expires?: Date;
111
- httpOnly?: boolean;
112
- maxAge?: number;
113
- path?: string;
114
- secure?: boolean;
115
- signingSecret?: string;
116
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
117
- partitioned?: boolean;
118
- prefix?: CookiePrefixOptions;
119
- } & PartitionCookieConstraint;
120
- type CookiePrefixOptions = "host" | "secure";
121
- type CookieConstraint<Name> = Name extends `__Secure-${string}` ? CookieOptions & SecureCookieConstraint : Name extends `__Host-${string}` ? CookieOptions & HostCookieConstraint : CookieOptions;
122
- declare const parse: (cookie: string, name?: string) => Cookie;
123
- declare const parseSigned: (cookie: string, secret: string | BufferSource, name?: string) => Promise<SignedCookie>;
124
- declare const serialize: <Name extends string>(name: Name, value: string, opt?: CookieConstraint<Name>) => string;
125
- declare const serializeSigned: (name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<string>;
126
-
127
- declare const _statusCode: {
128
- OK: number;
129
- CREATED: number;
130
- ACCEPTED: number;
131
- NO_CONTENT: number;
132
- MULTIPLE_CHOICES: number;
133
- MOVED_PERMANENTLY: number;
134
- FOUND: number;
135
- SEE_OTHER: number;
136
- NOT_MODIFIED: number;
137
- TEMPORARY_REDIRECT: number;
138
- BAD_REQUEST: number;
139
- UNAUTHORIZED: number;
140
- PAYMENT_REQUIRED: number;
141
- FORBIDDEN: number;
142
- NOT_FOUND: number;
143
- METHOD_NOT_ALLOWED: number;
144
- NOT_ACCEPTABLE: number;
145
- PROXY_AUTHENTICATION_REQUIRED: number;
146
- REQUEST_TIMEOUT: number;
147
- CONFLICT: number;
148
- GONE: number;
149
- LENGTH_REQUIRED: number;
150
- PRECONDITION_FAILED: number;
151
- PAYLOAD_TOO_LARGE: number;
152
- URI_TOO_LONG: number;
153
- UNSUPPORTED_MEDIA_TYPE: number;
154
- RANGE_NOT_SATISFIABLE: number;
155
- EXPECTATION_FAILED: number;
156
- "I'M_A_TEAPOT": number;
157
- MISDIRECTED_REQUEST: number;
158
- UNPROCESSABLE_ENTITY: number;
159
- LOCKED: number;
160
- FAILED_DEPENDENCY: number;
161
- TOO_EARLY: number;
162
- UPGRADE_REQUIRED: number;
163
- PRECONDITION_REQUIRED: number;
164
- TOO_MANY_REQUESTS: number;
165
- REQUEST_HEADER_FIELDS_TOO_LARGE: number;
166
- UNAVAILABLE_FOR_LEGAL_REASONS: number;
167
- INTERNAL_SERVER_ERROR: number;
168
- NOT_IMPLEMENTED: number;
169
- BAD_GATEWAY: number;
170
- SERVICE_UNAVAILABLE: number;
171
- GATEWAY_TIMEOUT: number;
172
- HTTP_VERSION_NOT_SUPPORTED: number;
173
- VARIANT_ALSO_NEGOTIATES: number;
174
- INSUFFICIENT_STORAGE: number;
175
- LOOP_DETECTED: number;
176
- NOT_EXTENDED: number;
177
- NETWORK_AUTHENTICATION_REQUIRED: number;
178
- };
179
- declare class APIError extends Error {
180
- status: keyof typeof _statusCode;
181
- body: {
182
- message?: string;
183
- code?: string;
184
- } | undefined;
185
- headers: {};
186
- statusCode: number;
187
- constructor(status?: keyof typeof _statusCode, body?: {
188
- message?: string;
189
- code?: string;
190
- } | undefined, headers?: {}, statusCode?: number);
191
- }
192
-
193
- interface EndpointContext<Path extends string, Options extends EndpointOptions> {
194
- /**
195
- * JSON
196
- *
197
- * a helper function to create a JSON response with the correct headers
198
- * and status code. If `asResponse` is set to true in the context then
199
- * it will return a Response object instead of the JSON object.
200
- *
201
- * @param json - The JSON object to return
202
- * @param routerResponse - The response object to return if `asResponse` is
203
- * true in the context this will take precedence
204
- */
205
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
206
- status?: number;
207
- headers?: Record<string, string>;
208
- response?: Response;
209
- } | Response) => Promise<R>;
210
- /**
211
- * Body
212
- *
213
- * The body object will be the parsed JSON from the request and validated
214
- * against the body schema if it exists
215
- */
216
- body: InferBody<Options>;
217
- /**
218
- * Path
219
- *
220
- * The path of the endpoint
221
- */
222
- path: Path;
223
- /**
224
- * Method
225
- */
226
- method: InferMethod<Options>;
227
- /**
228
- * Query
229
- *
230
- * The query object will be the parsed query string from the request
231
- * and validated against the query schema if it exists
232
- */
233
- query: InferQuery<Options>;
234
- /**
235
- * Params
236
- *
237
- * If the path is `/user/:id` and the request is `/user/1` then the params will
238
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*` then the
239
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the wildcard
240
- * is named like `/user/**:name` then the params will be `{ name: string }`
241
- */
242
- params: InferParam<Path>;
243
- /**
244
- * Request object
245
- *
246
- * If `requireRequest` is set to true in the endpoint options this will be
247
- * required
248
- */
249
- request: InferRequest<Options>;
250
- /**
251
- * Headers
252
- *
253
- * If `requireHeaders` is set to true in the endpoint options this will be
254
- * required
255
- */
256
- headers: InferHeaders<Options>;
257
- /**
258
- * Middleware context
259
- */
260
- context: InferUse<Options["use"]>;
261
- /**
262
- * Set header
263
- *
264
- * If it's called outside of a request it will just be ignored.
265
- */
266
- setHeader: (key: string, value: string) => void;
267
- /**
268
- * Get header
269
- *
270
- * If it's called outside of a request it will just return null
271
- *
272
- * @param key - The key of the header
273
- * @returns
274
- */
275
- getHeader: (key: string) => string | null;
276
- /**
277
- * cookie setter.
278
- *
279
- * If it's called outside of a request it will just be ignored.
280
- */
281
- setCookie: (key: string, value: string, options?: CookieOptions) => void;
282
- /**
283
- * Get cookie value
284
- *
285
- * If it's called outside of a request it will just be ignored.
286
- */
287
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | undefined;
288
- /**
289
- * Set signed cookie
290
- */
291
- setSignedCookie: (key: string, value: string, secret: string | Buffer, options?: CookieOptions) => Promise<void>;
292
- /**
293
- * Get signed cookie value
294
- */
295
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | undefined | false>;
296
- /**
297
- * Redirect to url
298
- */
299
- redirect: (url: string) => APIError;
300
- }
301
- type Context<Path extends string, Options extends EndpointOptions> = Input<{
302
- body: InferBody<Options>;
303
- method?: InferMethod<Options>;
304
- query: InferQuery<Options>;
305
- params: InferParam<Path>;
306
- request: InferRequest<Options>;
307
- headers: InferHeaders<Options>;
308
- asResponse?: boolean;
309
- }>;
310
- declare function createSetHeader(headers: Headers): (key: string, value: string) => void;
311
- declare function createGetHeader(headers: Headers): (key: string) => string | null;
312
-
313
- interface JSONResponse<R = any> {
314
- /**
315
- * Body of the response
316
- * It'll be inferred as the response body.
317
- * and on the server side this will be returned
318
- * as a response of a handler.
319
- */
320
- body: R;
321
- /**
322
- * The actual response object
323
- */
324
- routerResponse: {
325
- body?: Record<string, any>;
326
- status?: number;
327
- headers?: Record<string, string>;
328
- };
329
- /**
330
- * Flag to identify the response type
331
- */
332
- _flag: "json";
333
- }
334
- type EndpointResponse = JSONResponse | Response | void | Record<string, any> | null;
335
- type InferResponse<Ctx, R> = Ctx extends {
336
- asResponse: true;
337
- } ? Response : R extends JSONResponse<infer T> ? T : R;
338
- type ValidationResponse = {
339
- data: {
340
- body: any;
341
- query: any;
342
- };
343
- error: null;
344
- } | {
345
- data: null;
346
- error: {
347
- message: string;
348
- };
349
- };
350
- declare function runValidation(options: EndpointOptions, context: EndpointContext<any, any>): ValidationResponse;
351
- declare function fromError(error: ZodError): {
352
- message: string;
353
- };
354
-
355
- declare const createEndpoint: {
356
- <Path extends string, Options extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Options, handler: (context: EndpointContext<Path, Options>) => Promise<R>): {
357
- <Ctx extends Context<Path, Options>>(...inputCtx: HasRequiredKeys<Ctx> extends true ? [Ctx] : [Ctx?]): Promise<Ctx["asResponse"] extends true ? Response : R>;
358
- path: Path;
359
- options: Options;
360
- openAPI: {
361
- definitions: _asteasolutions_zod_to_openapi_dist_openapi_registry.OpenAPIDefinitions[];
362
- };
363
- };
364
- creator: typeof createEndpointCreator;
365
- };
366
- declare function createEndpointCreator<E extends {
367
- use: Endpoint[];
368
- }>(opts: E): <Path extends string, Opts extends EndpointOptions, R extends EndpointResponse>(path: Path, options: Opts, handler: <InferE extends EndpointContext<Path, Opts>>(ctx: Omit<InferE, "context"> & {
369
- context: InferUse<E["use"]> & (InferE["context"] extends never ? {} : InferE["context"]);
370
- }) => Promise<R>) => {
371
- <Ctx extends ({
372
- body: InferBody<Opts & {
373
- use: Endpoint[];
374
- }>;
375
- method?: InferMethod<Opts & {
376
- use: Endpoint[];
377
- }> | undefined;
378
- query: InferQuery<Opts & {
379
- use: Endpoint[];
380
- }>;
381
- params: InferParam<Path>;
382
- request: InferRequest<Opts & {
383
- use: Endpoint[];
384
- }>;
385
- headers: InferHeaders<Opts & {
386
- use: Endpoint[];
387
- }>;
388
- asResponse?: boolean;
389
- } extends infer T_1 ? { [K_1 in keyof T_1 as {
390
- body: InferBody<Opts & {
391
- use: Endpoint[];
392
- }>;
393
- method?: InferMethod<Opts & {
394
- use: Endpoint[];
395
- }> | undefined;
396
- query: InferQuery<Opts & {
397
- use: Endpoint[];
398
- }>;
399
- params: InferParam<Path>;
400
- request: InferRequest<Opts & {
401
- use: Endpoint[];
402
- }>;
403
- headers: InferHeaders<Opts & {
404
- use: Endpoint[];
405
- }>;
406
- asResponse?: boolean;
407
- }[K_1] extends never ? never : undefined extends {
408
- body: InferBody<Opts & {
409
- use: Endpoint[];
410
- }>;
411
- method?: InferMethod<Opts & {
412
- use: Endpoint[];
413
- }> | undefined;
414
- query: InferQuery<Opts & {
415
- use: Endpoint[];
416
- }>;
417
- params: InferParam<Path>;
418
- request: InferRequest<Opts & {
419
- use: Endpoint[];
420
- }>;
421
- headers: InferHeaders<Opts & {
422
- use: Endpoint[];
423
- }>;
424
- asResponse?: boolean;
425
- }[K_1] ? never : K_1]: {
426
- body: InferBody<Opts & {
427
- use: Endpoint[];
428
- }>;
429
- method?: InferMethod<Opts & {
430
- use: Endpoint[];
431
- }> | undefined;
432
- query: InferQuery<Opts & {
433
- use: Endpoint[];
434
- }>;
435
- params: InferParam<Path>;
436
- request: InferRequest<Opts & {
437
- use: Endpoint[];
438
- }>;
439
- headers: InferHeaders<Opts & {
440
- use: Endpoint[];
441
- }>;
442
- asResponse?: boolean;
443
- }[K_1]; } : never) & ({
444
- body: InferBody<Opts & {
445
- use: Endpoint[];
446
- }>;
447
- method?: InferMethod<Opts & {
448
- use: Endpoint[];
449
- }> | undefined;
450
- query: InferQuery<Opts & {
451
- use: Endpoint[];
452
- }>;
453
- params: InferParam<Path>;
454
- request: InferRequest<Opts & {
455
- use: Endpoint[];
456
- }>;
457
- headers: InferHeaders<Opts & {
458
- use: Endpoint[];
459
- }>;
460
- asResponse?: boolean;
461
- } extends infer T_2 ? { [K_2 in keyof T_2 as undefined extends {
462
- body: InferBody<Opts & {
463
- use: Endpoint[];
464
- }>;
465
- method?: InferMethod<Opts & {
466
- use: Endpoint[];
467
- }> | undefined;
468
- query: InferQuery<Opts & {
469
- use: Endpoint[];
470
- }>;
471
- params: InferParam<Path>;
472
- request: InferRequest<Opts & {
473
- use: Endpoint[];
474
- }>;
475
- headers: InferHeaders<Opts & {
476
- use: Endpoint[];
477
- }>;
478
- asResponse?: boolean;
479
- }[K_2] ? K_2 : never]?: {
480
- body: InferBody<Opts & {
481
- use: Endpoint[];
482
- }>;
483
- method?: InferMethod<Opts & {
484
- use: Endpoint[];
485
- }> | undefined;
486
- query: InferQuery<Opts & {
487
- use: Endpoint[];
488
- }>;
489
- params: InferParam<Path>;
490
- request: InferRequest<Opts & {
491
- use: Endpoint[];
492
- }>;
493
- headers: InferHeaders<Opts & {
494
- use: Endpoint[];
495
- }>;
496
- asResponse?: boolean;
497
- }[K_2] | undefined; } : never) extends infer T ? { [K in keyof T]: (({
498
- body: InferBody<Opts & {
499
- use: Endpoint[];
500
- }>;
501
- method?: InferMethod<Opts & {
502
- use: Endpoint[];
503
- }> | undefined;
504
- query: InferQuery<Opts & {
505
- use: Endpoint[];
506
- }>;
507
- params: InferParam<Path>;
508
- request: InferRequest<Opts & {
509
- use: Endpoint[];
510
- }>;
511
- headers: InferHeaders<Opts & {
512
- use: Endpoint[];
513
- }>;
514
- asResponse?: boolean;
515
- } extends infer T_1 ? { [K_1 in keyof T_1 as {
516
- body: InferBody<Opts & {
517
- use: Endpoint[];
518
- }>;
519
- method?: InferMethod<Opts & {
520
- use: Endpoint[];
521
- }> | undefined;
522
- query: InferQuery<Opts & {
523
- use: Endpoint[];
524
- }>;
525
- params: InferParam<Path>;
526
- request: InferRequest<Opts & {
527
- use: Endpoint[];
528
- }>;
529
- headers: InferHeaders<Opts & {
530
- use: Endpoint[];
531
- }>;
532
- asResponse?: boolean;
533
- }[K_1] extends never ? never : undefined extends {
534
- body: InferBody<Opts & {
535
- use: Endpoint[];
536
- }>;
537
- method?: InferMethod<Opts & {
538
- use: Endpoint[];
539
- }> | undefined;
540
- query: InferQuery<Opts & {
541
- use: Endpoint[];
542
- }>;
543
- params: InferParam<Path>;
544
- request: InferRequest<Opts & {
545
- use: Endpoint[];
546
- }>;
547
- headers: InferHeaders<Opts & {
548
- use: Endpoint[];
549
- }>;
550
- asResponse?: boolean;
551
- }[K_1] ? never : K_1]: {
552
- body: InferBody<Opts & {
553
- use: Endpoint[];
554
- }>;
555
- method?: InferMethod<Opts & {
556
- use: Endpoint[];
557
- }> | undefined;
558
- query: InferQuery<Opts & {
559
- use: Endpoint[];
560
- }>;
561
- params: InferParam<Path>;
562
- request: InferRequest<Opts & {
563
- use: Endpoint[];
564
- }>;
565
- headers: InferHeaders<Opts & {
566
- use: Endpoint[];
567
- }>;
568
- asResponse?: boolean;
569
- }[K_1]; } : never) & ({
570
- body: InferBody<Opts & {
571
- use: Endpoint[];
572
- }>;
573
- method?: InferMethod<Opts & {
574
- use: Endpoint[];
575
- }> | undefined;
576
- query: InferQuery<Opts & {
577
- use: Endpoint[];
578
- }>;
579
- params: InferParam<Path>;
580
- request: InferRequest<Opts & {
581
- use: Endpoint[];
582
- }>;
583
- headers: InferHeaders<Opts & {
584
- use: Endpoint[];
585
- }>;
586
- asResponse?: boolean;
587
- } extends infer T_2 ? { [K_2 in keyof T_2 as undefined extends {
588
- body: InferBody<Opts & {
589
- use: Endpoint[];
590
- }>;
591
- method?: InferMethod<Opts & {
592
- use: Endpoint[];
593
- }> | undefined;
594
- query: InferQuery<Opts & {
595
- use: Endpoint[];
596
- }>;
597
- params: InferParam<Path>;
598
- request: InferRequest<Opts & {
599
- use: Endpoint[];
600
- }>;
601
- headers: InferHeaders<Opts & {
602
- use: Endpoint[];
603
- }>;
604
- asResponse?: boolean;
605
- }[K_2] ? K_2 : never]?: {
606
- body: InferBody<Opts & {
607
- use: Endpoint[];
608
- }>;
609
- method?: InferMethod<Opts & {
610
- use: Endpoint[];
611
- }> | undefined;
612
- query: InferQuery<Opts & {
613
- use: Endpoint[];
614
- }>;
615
- params: InferParam<Path>;
616
- request: InferRequest<Opts & {
617
- use: Endpoint[];
618
- }>;
619
- headers: InferHeaders<Opts & {
620
- use: Endpoint[];
621
- }>;
622
- asResponse?: boolean;
623
- }[K_2] | undefined; } : never))[K]; } : never>(...inputCtx: HasRequiredKeys<Ctx> extends true ? [Ctx] : [(Ctx | undefined)?]): Promise<Ctx["asResponse"] extends true ? Response : R>;
624
- path: Path;
625
- options: Opts & {
626
- use: Endpoint[];
627
- };
628
- openAPI: {
629
- definitions: _asteasolutions_zod_to_openapi_dist_openapi_registry.OpenAPIDefinitions[];
630
- };
631
- };
632
- type Endpoint<Handler extends (ctx: any) => Promise<any> = (ctx: any) => Promise<any>, Options extends EndpointOptions = EndpointOptions> = {
633
- path: string;
634
- options: Options;
635
- } & Handler;
636
-
637
- interface RouterConfig {
638
- /**
639
- * Throw error if error occurred other than APIError
640
- */
641
- throwError?: boolean;
642
- /**
643
- * Handle error
644
- */
645
- onError?: (e: unknown) => void | Promise<void> | Response | Promise<Response>;
646
- /**
647
- * Base path for the router
648
- */
649
- basePath?: string;
650
- /**
651
- * Middlewares for the router
652
- */
653
- routerMiddleware?: {
654
- path: string;
655
- middleware: Endpoint;
656
- }[];
657
- /**
658
- * On response interceptor
659
- */
660
- onResponse?: (res: Response) => any | Promise<any>;
661
- /**
662
- * On request interceptor
663
- */
664
- onRequest?: (req: Request) => any | Promise<any>;
665
- /**
666
- * Extra context to pass to the handler
667
- */
668
- extraContext?: Record<string, any>;
669
- }
670
- declare const createRouter: <E extends Record<string, Endpoint>, Config extends RouterConfig>(endpoints: E, config?: Config) => {
671
- handler: (request: Request) => Promise<Response>;
672
- endpoints: E;
673
- };
674
- type Router = ReturnType<typeof createRouter>;
675
-
676
- export { APIError as A, type CookiePrefixOptions as C, type EndpointOptions as E, type HasRequiredKeys as H, type InferUse as I, type JSONResponse as J, type Prettify as P, type Router as R, type SignedCookie as S, type UnionToIntersection as U, _statusCode as _, type EndpointResponse as a, type Endpoint as b, type EndpointContext as c, type CookieOptions as d, createEndpoint as e, createRouter as f, type Input as g, type RequiredKeysOf as h, type IsEmptyObject as i, type Context as j, createSetHeader as k, createGetHeader as l, type InferResponse as m, fromError as n, type Cookie as o, type CookieConstraint as p, parse as q, runValidation as r, parseSigned as s, serialize as t, serializeSigned as u };