better-call 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +12 -5
- package/dist/client.d.ts +12 -5
- package/dist/client.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{router-DQIhoWK3.d.cts → router-D9DesiMG.d.cts} +360 -224
- package/dist/{router-DQIhoWK3.d.ts → router-D9DesiMG.d.ts} +360 -224
- package/package.json +5 -1
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Improve this type if possible
|
|
3
|
-
*/
|
|
4
|
-
type Input<T> = {
|
|
5
|
-
[K in keyof T as T[K] extends never ? never : undefined extends T[K] ? never : K]: T[K];
|
|
6
|
-
} & {
|
|
7
|
-
[K in keyof T as undefined extends T[K] ? K : never]?: T[K];
|
|
8
|
-
};
|
|
9
|
-
type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
10
|
-
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
|
|
11
|
-
}[keyof BaseType], undefined>;
|
|
12
|
-
type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
13
|
-
type Prettify<T> = {
|
|
14
|
-
[K in keyof T]: T[K];
|
|
15
|
-
} & {};
|
|
16
|
-
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
17
|
-
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never;
|
|
18
|
-
type MergeObject<T extends Record<string, any> | never, S extends Record<string, any> | never> = T extends never ? S : S extends never ? T : T & S;
|
|
19
|
-
type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
20
|
-
[K in Param | keyof InferParamPath<Rest>]: string;
|
|
21
|
-
} : Path extends `${infer _Start}:${infer Param}` ? {
|
|
22
|
-
[K in Param]: string;
|
|
23
|
-
} : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
|
|
24
|
-
type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? {
|
|
25
|
-
[K in Param | keyof InferParamPath<Rest>]: string;
|
|
26
|
-
} : Path extends `${infer _Start}/*` ? {
|
|
27
|
-
[K in "_"]: string;
|
|
28
|
-
} : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
|
|
29
|
-
|
|
30
1
|
declare const _statusCode: {
|
|
31
2
|
OK: number;
|
|
32
3
|
CREATED: number;
|
|
@@ -94,6 +65,144 @@ declare class APIError extends Error {
|
|
|
94
65
|
} & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
|
|
95
66
|
}
|
|
96
67
|
|
|
68
|
+
type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
69
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
|
|
70
|
+
}[keyof BaseType], undefined>;
|
|
71
|
+
type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
72
|
+
type Prettify<T> = {
|
|
73
|
+
[K in keyof T]: T[K];
|
|
74
|
+
} & {};
|
|
75
|
+
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
76
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never;
|
|
77
|
+
type MergeObject<T extends Record<string, any> | never, S extends Record<string, any> | never> = T extends never ? S : S extends never ? T : T & S;
|
|
78
|
+
type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
79
|
+
[K in Param | keyof InferParamPath<Rest>]: string;
|
|
80
|
+
} : Path extends `${infer _Start}:${infer Param}` ? {
|
|
81
|
+
[K in Param]: string;
|
|
82
|
+
} : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
|
|
83
|
+
type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? {
|
|
84
|
+
[K in Param | keyof InferParamPath<Rest>]: string;
|
|
85
|
+
} : Path extends `${infer _Start}/*` ? {
|
|
86
|
+
[K in "_"]: string;
|
|
87
|
+
} : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
|
|
88
|
+
|
|
89
|
+
interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {
|
|
90
|
+
}
|
|
91
|
+
type MiddlewareResponse = null | void | undefined | Record<string, any>;
|
|
92
|
+
type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
|
|
93
|
+
method: "*";
|
|
94
|
+
}> & {
|
|
95
|
+
/**
|
|
96
|
+
* Method
|
|
97
|
+
*
|
|
98
|
+
* The request method
|
|
99
|
+
*/
|
|
100
|
+
method: string;
|
|
101
|
+
/**
|
|
102
|
+
* Path
|
|
103
|
+
*
|
|
104
|
+
* The path of the endpoint
|
|
105
|
+
*/
|
|
106
|
+
path: string;
|
|
107
|
+
/**
|
|
108
|
+
* Body
|
|
109
|
+
*
|
|
110
|
+
* The body object will be the parsed JSON from the request and validated
|
|
111
|
+
* against the body schema if it exists
|
|
112
|
+
*/
|
|
113
|
+
body: InferMiddlewareBody<Options>;
|
|
114
|
+
/**
|
|
115
|
+
* Query
|
|
116
|
+
*
|
|
117
|
+
* The query object will be the parsed query string from the request
|
|
118
|
+
* and validated against the query schema if it exists
|
|
119
|
+
*/
|
|
120
|
+
query: InferMiddlewareQuery<Options>;
|
|
121
|
+
/**
|
|
122
|
+
* Params
|
|
123
|
+
*
|
|
124
|
+
* If the path is `/user/:id` and the request is `/user/1` then the
|
|
125
|
+
* params will
|
|
126
|
+
* be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
|
|
127
|
+
* then the
|
|
128
|
+
* params will be `{ _: "1" }` where `_` is the wildcard key. If the
|
|
129
|
+
* wildcard
|
|
130
|
+
* is named like `/user/**:name` then the params will be `{ name: string }`
|
|
131
|
+
*/
|
|
132
|
+
params: string;
|
|
133
|
+
/**
|
|
134
|
+
* Request object
|
|
135
|
+
*
|
|
136
|
+
* If `requireRequest` is set to true in the endpoint options this will be
|
|
137
|
+
* required
|
|
138
|
+
*/
|
|
139
|
+
request: InferRequest<Options>;
|
|
140
|
+
/**
|
|
141
|
+
* Headers
|
|
142
|
+
*
|
|
143
|
+
* If `requireHeaders` is set to true in the endpoint options this will be
|
|
144
|
+
* required
|
|
145
|
+
*/
|
|
146
|
+
headers: InferHeaders<Options>;
|
|
147
|
+
/**
|
|
148
|
+
* Set header
|
|
149
|
+
*
|
|
150
|
+
* If it's called outside of a request it will just be ignored.
|
|
151
|
+
*/
|
|
152
|
+
setHeader: (key: string, value: string) => void;
|
|
153
|
+
/**
|
|
154
|
+
* Get header
|
|
155
|
+
*
|
|
156
|
+
* If it's called outside of a request it will just return null
|
|
157
|
+
*
|
|
158
|
+
* @param key - The key of the header
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
getHeader: (key: string) => string | null;
|
|
162
|
+
/**
|
|
163
|
+
* JSON
|
|
164
|
+
*
|
|
165
|
+
* a helper function to create a JSON response with
|
|
166
|
+
* the correct headers
|
|
167
|
+
* and status code. If `asResponse` is set to true in
|
|
168
|
+
* the context then
|
|
169
|
+
* it will return a Response object instead of the
|
|
170
|
+
* JSON object.
|
|
171
|
+
*
|
|
172
|
+
* @param json - The JSON object to return
|
|
173
|
+
* @param routerResponse - The response object to
|
|
174
|
+
* return if `asResponse` is
|
|
175
|
+
* true in the context this will take precedence
|
|
176
|
+
*/
|
|
177
|
+
json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
|
|
178
|
+
status?: number;
|
|
179
|
+
headers?: Record<string, string>;
|
|
180
|
+
response?: Response;
|
|
181
|
+
} | Response) => Promise<R>;
|
|
182
|
+
/**
|
|
183
|
+
* Middleware context
|
|
184
|
+
*/
|
|
185
|
+
context: Prettify<Context>;
|
|
186
|
+
};
|
|
187
|
+
declare function createMiddleware<Options extends MiddlewareOptions, R>(options: Options, handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
|
|
188
|
+
declare function createMiddleware<Options extends MiddlewareOptions, R>(handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
|
|
189
|
+
declare namespace createMiddleware {
|
|
190
|
+
var create: <E extends {
|
|
191
|
+
use?: Middleware[];
|
|
192
|
+
}>(opts?: E) => {
|
|
193
|
+
<Options extends MiddlewareOptions, R>(options: Options, handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R>): (inputContext: MiddlewareInputContext<Options>) => Promise<R>;
|
|
194
|
+
<Options extends MiddlewareOptions, R_1>(handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R_1>): (inputContext: MiddlewareInputContext<Options>) => Promise<R_1>;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
type MiddlewareInputContext<Options extends MiddlewareOptions> = InferBodyInput<Options> & InferQueryInput<Options> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
198
|
+
asResponse?: boolean;
|
|
199
|
+
returnHeaders?: boolean;
|
|
200
|
+
use?: Middleware[];
|
|
201
|
+
};
|
|
202
|
+
type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
|
|
203
|
+
options: Options;
|
|
204
|
+
};
|
|
205
|
+
|
|
97
206
|
type CookiePrefixOptions = "host" | "secure";
|
|
98
207
|
type CookieOptions = {
|
|
99
208
|
/**
|
|
@@ -252,77 +361,67 @@ declare namespace StandardSchemaV1 {
|
|
|
252
361
|
|
|
253
362
|
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
254
363
|
type Method = HTTPMethod | "*";
|
|
255
|
-
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions
|
|
364
|
+
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = Options["metadata"] extends {
|
|
256
365
|
$Infer: {
|
|
257
|
-
body: infer
|
|
366
|
+
body: infer B;
|
|
258
367
|
};
|
|
259
|
-
} ?
|
|
368
|
+
} ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined> = undefined extends Body ? {
|
|
369
|
+
body?: Body;
|
|
370
|
+
} : {
|
|
371
|
+
body: Body;
|
|
372
|
+
};
|
|
260
373
|
type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
261
374
|
$Infer: {
|
|
262
375
|
body: infer Body;
|
|
263
376
|
};
|
|
264
377
|
} ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
|
|
265
|
-
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions
|
|
378
|
+
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = Options["metadata"] extends {
|
|
266
379
|
$Infer: {
|
|
267
380
|
query: infer Query;
|
|
268
381
|
};
|
|
269
|
-
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined
|
|
382
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined> = undefined extends Query ? {
|
|
383
|
+
query?: Query;
|
|
384
|
+
} : {
|
|
385
|
+
query: Query;
|
|
386
|
+
};
|
|
270
387
|
type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
271
388
|
$Infer: {
|
|
272
389
|
query: infer Query;
|
|
273
390
|
};
|
|
274
391
|
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
|
|
275
392
|
type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
|
|
276
|
-
type InferInputMethod<Options extends EndpointOptions
|
|
393
|
+
type InferInputMethod<Options extends EndpointOptions, Method = Options["method"] extends Array<any> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined> = undefined extends Method ? {
|
|
394
|
+
method?: Method;
|
|
395
|
+
} : {
|
|
396
|
+
method: Method;
|
|
397
|
+
};
|
|
277
398
|
type InferParam<Path extends string> = IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
399
|
+
type InferParamInput<Path extends string> = IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
|
|
400
|
+
params?: Record<string, any>;
|
|
401
|
+
} : {
|
|
402
|
+
params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
|
|
403
|
+
};
|
|
278
404
|
type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
|
|
405
|
+
type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
|
|
406
|
+
request: Request;
|
|
407
|
+
} : {
|
|
408
|
+
request?: Request;
|
|
409
|
+
};
|
|
279
410
|
type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
|
|
280
|
-
type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ?
|
|
411
|
+
type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
|
|
412
|
+
headers: HeadersInit;
|
|
413
|
+
} : {
|
|
414
|
+
headers?: HeadersInit;
|
|
415
|
+
};
|
|
281
416
|
type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
|
|
282
417
|
type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
|
|
283
418
|
type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
|
|
284
|
-
type InputContext<Path extends string, Options extends EndpointOptions> =
|
|
285
|
-
/**
|
|
286
|
-
* Payload
|
|
287
|
-
*/
|
|
288
|
-
body: InferBodyInput<Options>;
|
|
289
|
-
/**
|
|
290
|
-
* Request Method
|
|
291
|
-
*/
|
|
292
|
-
method: InferInputMethod<Options>;
|
|
293
|
-
/**
|
|
294
|
-
* Query Params
|
|
295
|
-
*/
|
|
296
|
-
query: InferQueryInput<Options>;
|
|
297
|
-
/**
|
|
298
|
-
* Dynamic Params
|
|
299
|
-
*/
|
|
300
|
-
params: InferParam<Path>;
|
|
301
|
-
/**
|
|
302
|
-
* Request Object
|
|
303
|
-
*/
|
|
304
|
-
request: InferRequest<Options>;
|
|
305
|
-
/**
|
|
306
|
-
* Headers
|
|
307
|
-
*/
|
|
308
|
-
headers: InferHeadersInput<Options>;
|
|
309
|
-
/**
|
|
310
|
-
* Return a `Response` object
|
|
311
|
-
*/
|
|
419
|
+
type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
312
420
|
asResponse?: boolean;
|
|
313
|
-
/**
|
|
314
|
-
* include headers on the return
|
|
315
|
-
*/
|
|
316
421
|
returnHeaders?: boolean;
|
|
317
|
-
/**
|
|
318
|
-
* Middlewares to use
|
|
319
|
-
*/
|
|
320
422
|
use?: Middleware[];
|
|
321
|
-
/**
|
|
322
|
-
* Customize the path
|
|
323
|
-
*/
|
|
324
423
|
path?: string;
|
|
325
|
-
}
|
|
424
|
+
};
|
|
326
425
|
declare const createInternalContext: (context: InputContext<any, any>, { options, path, }: {
|
|
327
426
|
options: EndpointOptions;
|
|
328
427
|
path: string;
|
|
@@ -354,152 +453,103 @@ declare const createInternalContext: (context: InputContext<any, any>, { options
|
|
|
354
453
|
body?: Record<string, any>;
|
|
355
454
|
} | Response) => Record<string, any>;
|
|
356
455
|
responseHeaders: Headers;
|
|
357
|
-
asResponse?: boolean
|
|
358
|
-
returnHeaders?: boolean
|
|
359
|
-
use?: Middleware[]
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
type MiddlewareResponse = null | void | undefined | Record<string, any>;
|
|
365
|
-
type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
|
|
366
|
-
method: "*";
|
|
367
|
-
}> & {
|
|
368
|
-
/**
|
|
369
|
-
* Method
|
|
370
|
-
*
|
|
371
|
-
* The request method
|
|
372
|
-
*/
|
|
373
|
-
method: string;
|
|
374
|
-
/**
|
|
375
|
-
* Path
|
|
376
|
-
*
|
|
377
|
-
* The path of the endpoint
|
|
378
|
-
*/
|
|
456
|
+
asResponse?: boolean;
|
|
457
|
+
returnHeaders?: boolean;
|
|
458
|
+
use?: Middleware[];
|
|
459
|
+
} | {
|
|
460
|
+
body: any;
|
|
461
|
+
query: any;
|
|
379
462
|
path: string;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
body: InferMiddlewareBody<Options>;
|
|
387
|
-
/**
|
|
388
|
-
* Query
|
|
389
|
-
*
|
|
390
|
-
* The query object will be the parsed query string from the request
|
|
391
|
-
* and validated against the query schema if it exists
|
|
392
|
-
*/
|
|
393
|
-
query: InferMiddlewareQuery<Options>;
|
|
394
|
-
/**
|
|
395
|
-
* Params
|
|
396
|
-
*
|
|
397
|
-
* If the path is `/user/:id` and the request is `/user/1` then the
|
|
398
|
-
* params will
|
|
399
|
-
* be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
|
|
400
|
-
* then the
|
|
401
|
-
* params will be `{ _: "1" }` where `_` is the wildcard key. If the
|
|
402
|
-
* wildcard
|
|
403
|
-
* is named like `/user/**:name` then the params will be `{ name: string }`
|
|
404
|
-
*/
|
|
405
|
-
params: string;
|
|
406
|
-
/**
|
|
407
|
-
* Request object
|
|
408
|
-
*
|
|
409
|
-
* If `requireRequest` is set to true in the endpoint options this will be
|
|
410
|
-
* required
|
|
411
|
-
*/
|
|
412
|
-
request: InferRequest<Options>;
|
|
413
|
-
/**
|
|
414
|
-
* Headers
|
|
415
|
-
*
|
|
416
|
-
* If `requireHeaders` is set to true in the endpoint options this will be
|
|
417
|
-
* required
|
|
418
|
-
*/
|
|
419
|
-
headers: InferHeaders<Options>;
|
|
420
|
-
/**
|
|
421
|
-
* Set header
|
|
422
|
-
*
|
|
423
|
-
* If it's called outside of a request it will just be ignored.
|
|
424
|
-
*/
|
|
463
|
+
context: {};
|
|
464
|
+
returned: any;
|
|
465
|
+
headers: HeadersInit | undefined;
|
|
466
|
+
request: Request | undefined;
|
|
467
|
+
params: Record<string, any> | undefined;
|
|
468
|
+
method: any;
|
|
425
469
|
setHeader: (key: string, value: string) => void;
|
|
426
|
-
/**
|
|
427
|
-
* Get header
|
|
428
|
-
*
|
|
429
|
-
* If it's called outside of a request it will just return null
|
|
430
|
-
*
|
|
431
|
-
* @param key - The key of the header
|
|
432
|
-
* @returns
|
|
433
|
-
*/
|
|
434
470
|
getHeader: (key: string) => string | null;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
* @param json - The JSON object to return
|
|
446
|
-
* @param routerResponse - The response object to
|
|
447
|
-
* return if `asResponse` is
|
|
448
|
-
* true in the context this will take precedence
|
|
449
|
-
*/
|
|
450
|
-
json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
|
|
471
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
472
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
473
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
474
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
475
|
+
redirect: (url: string) => APIError;
|
|
476
|
+
error: (status: keyof typeof _statusCode | Status, body?: {
|
|
477
|
+
message?: string;
|
|
478
|
+
code?: string;
|
|
479
|
+
} | undefined, headers?: HeadersInit) => APIError;
|
|
480
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
451
481
|
status?: number;
|
|
452
482
|
headers?: Record<string, string>;
|
|
453
483
|
response?: Response;
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
484
|
+
body?: Record<string, any>;
|
|
485
|
+
} | Response) => Record<string, any>;
|
|
486
|
+
responseHeaders: Headers;
|
|
487
|
+
asResponse?: boolean;
|
|
488
|
+
returnHeaders?: boolean;
|
|
489
|
+
use?: Middleware[];
|
|
490
|
+
} | {
|
|
491
|
+
body: any;
|
|
492
|
+
query: any;
|
|
493
|
+
path: string;
|
|
494
|
+
context: {};
|
|
495
|
+
returned: any;
|
|
496
|
+
headers: HeadersInit | undefined;
|
|
497
|
+
request: Request | undefined;
|
|
498
|
+
params: Record<string, any> | undefined;
|
|
499
|
+
method: any;
|
|
500
|
+
setHeader: (key: string, value: string) => void;
|
|
501
|
+
getHeader: (key: string) => string | null;
|
|
502
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
503
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
504
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
505
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
506
|
+
redirect: (url: string) => APIError;
|
|
507
|
+
error: (status: keyof typeof _statusCode | Status, body?: {
|
|
508
|
+
message?: string;
|
|
509
|
+
code?: string;
|
|
510
|
+
} | undefined, headers?: HeadersInit) => APIError;
|
|
511
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
512
|
+
status?: number;
|
|
513
|
+
headers?: Record<string, string>;
|
|
514
|
+
response?: Response;
|
|
515
|
+
body?: Record<string, any>;
|
|
516
|
+
} | Response) => Record<string, any>;
|
|
517
|
+
responseHeaders: Headers;
|
|
518
|
+
asResponse?: boolean;
|
|
519
|
+
returnHeaders?: boolean;
|
|
520
|
+
use?: Middleware[];
|
|
521
|
+
} | {
|
|
522
|
+
body: any;
|
|
523
|
+
query: any;
|
|
524
|
+
path: string;
|
|
525
|
+
context: {};
|
|
526
|
+
returned: any;
|
|
527
|
+
headers: HeadersInit | undefined;
|
|
528
|
+
request: Request | undefined;
|
|
529
|
+
params: Record<string, any> | undefined;
|
|
530
|
+
method: any;
|
|
531
|
+
setHeader: (key: string, value: string) => void;
|
|
532
|
+
getHeader: (key: string) => string | null;
|
|
533
|
+
getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
|
|
534
|
+
getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
|
|
535
|
+
setCookie: (key: string, value: string, options?: CookieOptions) => string;
|
|
536
|
+
setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
|
|
537
|
+
redirect: (url: string) => APIError;
|
|
538
|
+
error: (status: keyof typeof _statusCode | Status, body?: {
|
|
539
|
+
message?: string;
|
|
540
|
+
code?: string;
|
|
541
|
+
} | undefined, headers?: HeadersInit) => APIError;
|
|
542
|
+
json: (json: Record<string, any>, routerResponse?: {
|
|
543
|
+
status?: number;
|
|
544
|
+
headers?: Record<string, string>;
|
|
545
|
+
response?: Response;
|
|
546
|
+
body?: Record<string, any>;
|
|
547
|
+
} | Response) => Record<string, any>;
|
|
548
|
+
responseHeaders: Headers;
|
|
490
549
|
asResponse?: boolean;
|
|
491
|
-
/**
|
|
492
|
-
* include headers on the return
|
|
493
|
-
*/
|
|
494
550
|
returnHeaders?: boolean;
|
|
495
|
-
/**
|
|
496
|
-
* Middlewares to use
|
|
497
|
-
*/
|
|
498
551
|
use?: Middleware[];
|
|
499
552
|
}>;
|
|
500
|
-
type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
|
|
501
|
-
options: Options;
|
|
502
|
-
};
|
|
503
553
|
|
|
504
554
|
type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
505
555
|
interface OpenAPIParameter {
|
|
@@ -879,11 +929,13 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
|
|
|
879
929
|
};
|
|
880
930
|
declare const createEndpoint: {
|
|
881
931
|
<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: (context: EndpointContext<Path, Options>) => Promise<R>): {
|
|
882
|
-
<
|
|
883
|
-
asResponse
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
932
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(...inputCtx: HasRequiredKeys<InputContext<Path, Options>> extends true ? [InputContext<Path, Options> & {
|
|
933
|
+
asResponse?: AsResponse;
|
|
934
|
+
returnHeaders?: ReturnHeaders;
|
|
935
|
+
}] : [(InputContext<Path, Options> & {
|
|
936
|
+
asResponse?: AsResponse;
|
|
937
|
+
returnHeaders?: ReturnHeaders;
|
|
938
|
+
})?]): Promise<AsResponse extends true ? Response : ReturnHeaders extends true ? {
|
|
887
939
|
headers: Headers;
|
|
888
940
|
response: R;
|
|
889
941
|
} : R>;
|
|
@@ -893,17 +945,101 @@ declare const createEndpoint: {
|
|
|
893
945
|
create<E extends {
|
|
894
946
|
use?: Middleware[];
|
|
895
947
|
}>(opts?: E): <Path extends string, Opts extends EndpointOptions, R>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, InferUse<E["use"]>>) => Promise<R>) => {
|
|
896
|
-
<
|
|
948
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(...inputCtx: HasRequiredKeys<InputContext<Path, Opts & {
|
|
949
|
+
use: any[];
|
|
950
|
+
}>> extends true ? [InferBodyInput<Opts & {
|
|
951
|
+
use: any[];
|
|
952
|
+
}, (Opts & {
|
|
953
|
+
use: any[];
|
|
954
|
+
})["metadata"] extends {
|
|
955
|
+
$Infer: {
|
|
956
|
+
body: infer B;
|
|
957
|
+
};
|
|
958
|
+
} ? B : (Opts & {
|
|
959
|
+
use: any[];
|
|
960
|
+
})["body"] extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferInput<(Opts & {
|
|
961
|
+
use: any[];
|
|
962
|
+
})["body"]> : undefined> & InferInputMethod<Opts & {
|
|
963
|
+
use: any[];
|
|
964
|
+
}, (Opts & {
|
|
965
|
+
use: any[];
|
|
966
|
+
})["method"] extends any[] ? (Opts & {
|
|
967
|
+
use: any[];
|
|
968
|
+
})["method"][number] : (Opts & {
|
|
969
|
+
use: any[];
|
|
970
|
+
})["method"] extends "*" ? HTTPMethod : (Opts & {
|
|
971
|
+
use: any[];
|
|
972
|
+
})["method"] | undefined> & InferQueryInput<Opts & {
|
|
973
|
+
use: any[];
|
|
974
|
+
}, (Opts & {
|
|
975
|
+
use: any[];
|
|
976
|
+
})["metadata"] extends {
|
|
977
|
+
$Infer: {
|
|
978
|
+
query: infer Query;
|
|
979
|
+
};
|
|
980
|
+
} ? Query : (Opts & {
|
|
981
|
+
use: any[];
|
|
982
|
+
})["query"] extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferInput<(Opts & {
|
|
983
|
+
use: any[];
|
|
984
|
+
})["query"]> : Record<string, any> | undefined> & InferParamInput<Path> & InferRequestInput<Opts & {
|
|
985
|
+
use: any[];
|
|
986
|
+
}> & InferHeadersInput<Opts & {
|
|
987
|
+
use: any[];
|
|
988
|
+
}> & {
|
|
989
|
+
asResponse?: boolean;
|
|
990
|
+
returnHeaders?: boolean;
|
|
991
|
+
use?: Middleware[];
|
|
992
|
+
path?: string;
|
|
993
|
+
} & {
|
|
994
|
+
asResponse?: AsResponse | undefined;
|
|
995
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
996
|
+
}] : [((InferBodyInput<Opts & {
|
|
997
|
+
use: any[];
|
|
998
|
+
}, (Opts & {
|
|
999
|
+
use: any[];
|
|
1000
|
+
})["metadata"] extends {
|
|
1001
|
+
$Infer: {
|
|
1002
|
+
body: infer B;
|
|
1003
|
+
};
|
|
1004
|
+
} ? B : (Opts & {
|
|
1005
|
+
use: any[];
|
|
1006
|
+
})["body"] extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferInput<(Opts & {
|
|
1007
|
+
use: any[];
|
|
1008
|
+
})["body"]> : undefined> & InferInputMethod<Opts & {
|
|
1009
|
+
use: any[];
|
|
1010
|
+
}, (Opts & {
|
|
1011
|
+
use: any[];
|
|
1012
|
+
})["method"] extends any[] ? (Opts & {
|
|
1013
|
+
use: any[];
|
|
1014
|
+
})["method"][number] : (Opts & {
|
|
1015
|
+
use: any[];
|
|
1016
|
+
})["method"] extends "*" ? HTTPMethod : (Opts & {
|
|
1017
|
+
use: any[];
|
|
1018
|
+
})["method"] | undefined> & InferQueryInput<Opts & {
|
|
1019
|
+
use: any[];
|
|
1020
|
+
}, (Opts & {
|
|
1021
|
+
use: any[];
|
|
1022
|
+
})["metadata"] extends {
|
|
1023
|
+
$Infer: {
|
|
1024
|
+
query: infer Query;
|
|
1025
|
+
};
|
|
1026
|
+
} ? Query : (Opts & {
|
|
1027
|
+
use: any[];
|
|
1028
|
+
})["query"] extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferInput<(Opts & {
|
|
897
1029
|
use: any[];
|
|
898
|
-
}
|
|
1030
|
+
})["query"]> : Record<string, any> | undefined> & InferParamInput<Path> & InferRequestInput<Opts & {
|
|
899
1031
|
use: any[];
|
|
900
|
-
}>
|
|
1032
|
+
}> & InferHeadersInput<Opts & {
|
|
901
1033
|
use: any[];
|
|
902
|
-
}>
|
|
903
|
-
asResponse
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1034
|
+
}> & {
|
|
1035
|
+
asResponse?: boolean;
|
|
1036
|
+
returnHeaders?: boolean;
|
|
1037
|
+
use?: Middleware[];
|
|
1038
|
+
path?: string;
|
|
1039
|
+
} & {
|
|
1040
|
+
asResponse?: AsResponse | undefined;
|
|
1041
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
1042
|
+
}) | undefined)?]): Promise<AsResponse extends true ? Response : ReturnHeaders extends true ? {
|
|
907
1043
|
headers: Headers;
|
|
908
1044
|
response: R;
|
|
909
1045
|
} : R>;
|
|
@@ -989,4 +1125,4 @@ declare const createRouter: <E extends Record<string, Endpoint>, Config extends
|
|
|
989
1125
|
};
|
|
990
1126
|
type Router = ReturnType<typeof createRouter>;
|
|
991
1127
|
|
|
992
|
-
export {
|
|
1128
|
+
export { type InferParamWildCard as $, APIError as A, type InferRequest as B, type CookiePrefixOptions as C, type InferRequestInput as D, type EndpointOptions as E, type InferHeaders as F, type InferHeadersInput as G, type HTTPMethod as H, type InferBodyInput as I, type InferUse as J, type InferMiddlewareBody as K, type InferMiddlewareQuery as L, type MiddlewareOptions as M, type InputContext as N, type OpenAPISchemaType as O, type Path as P, createInternalContext as Q, type RouterConfig as R, type Status as S, type RequiredKeysOf as T, type HasRequiredKeys as U, type Prettify as V, type IsEmptyObject as W, type UnionToIntersection as X, type MergeObject as Y, type InferParamPath as Z, _statusCode as _, type EndpointContext as a, StandardSchemaV1 as a0, 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 InferParamInput as z };
|