better-call 1.0.4 → 1.0.6-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +36 -8
- 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 +36 -8
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{router-uAmry411.d.cts → router-D9DesiMG.d.cts} +369 -225
- package/dist/{router-uAmry411.d.ts → router-D9DesiMG.d.ts} +369 -225
- package/package.json +9 -5
|
@@ -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
|
/**
|
|
@@ -182,7 +291,15 @@ type CookieOptions = {
|
|
|
182
291
|
prefix?: CookiePrefixOptions;
|
|
183
292
|
};
|
|
184
293
|
declare const getCookieKey: (key: string, prefix?: CookiePrefixOptions) => string | undefined;
|
|
185
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
296
|
+
* name-value pairs.
|
|
297
|
+
*
|
|
298
|
+
* Inspired by https://github.com/unjs/cookie-es/blob/main/src/cookie/parse.ts
|
|
299
|
+
*
|
|
300
|
+
* @param str the string representing a `Cookie` header value
|
|
301
|
+
*/
|
|
302
|
+
declare function parseCookies(str: string): Map<string, string>;
|
|
186
303
|
declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string;
|
|
187
304
|
declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise<string>;
|
|
188
305
|
|
|
@@ -244,77 +361,67 @@ declare namespace StandardSchemaV1 {
|
|
|
244
361
|
|
|
245
362
|
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
246
363
|
type Method = HTTPMethod | "*";
|
|
247
|
-
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions
|
|
364
|
+
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = Options["metadata"] extends {
|
|
248
365
|
$Infer: {
|
|
249
|
-
body: infer
|
|
366
|
+
body: infer B;
|
|
250
367
|
};
|
|
251
|
-
} ?
|
|
368
|
+
} ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined> = undefined extends Body ? {
|
|
369
|
+
body?: Body;
|
|
370
|
+
} : {
|
|
371
|
+
body: Body;
|
|
372
|
+
};
|
|
252
373
|
type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
253
374
|
$Infer: {
|
|
254
375
|
body: infer Body;
|
|
255
376
|
};
|
|
256
377
|
} ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
|
|
257
|
-
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions
|
|
378
|
+
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = Options["metadata"] extends {
|
|
258
379
|
$Infer: {
|
|
259
380
|
query: infer Query;
|
|
260
381
|
};
|
|
261
|
-
} ? 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
|
+
};
|
|
262
387
|
type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
|
|
263
388
|
$Infer: {
|
|
264
389
|
query: infer Query;
|
|
265
390
|
};
|
|
266
391
|
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
|
|
267
392
|
type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
|
|
268
|
-
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
|
+
};
|
|
269
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
|
+
};
|
|
270
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
|
+
};
|
|
271
410
|
type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
|
|
272
|
-
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
|
+
};
|
|
273
416
|
type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
|
|
274
417
|
type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
|
|
275
418
|
type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
|
|
276
|
-
type InputContext<Path extends string, Options extends EndpointOptions> =
|
|
277
|
-
/**
|
|
278
|
-
* Payload
|
|
279
|
-
*/
|
|
280
|
-
body: InferBodyInput<Options>;
|
|
281
|
-
/**
|
|
282
|
-
* Request Method
|
|
283
|
-
*/
|
|
284
|
-
method: InferInputMethod<Options>;
|
|
285
|
-
/**
|
|
286
|
-
* Query Params
|
|
287
|
-
*/
|
|
288
|
-
query: InferQueryInput<Options>;
|
|
289
|
-
/**
|
|
290
|
-
* Dynamic Params
|
|
291
|
-
*/
|
|
292
|
-
params: InferParam<Path>;
|
|
293
|
-
/**
|
|
294
|
-
* Request Object
|
|
295
|
-
*/
|
|
296
|
-
request: InferRequest<Options>;
|
|
297
|
-
/**
|
|
298
|
-
* Headers
|
|
299
|
-
*/
|
|
300
|
-
headers: InferHeadersInput<Options>;
|
|
301
|
-
/**
|
|
302
|
-
* Return a `Response` object
|
|
303
|
-
*/
|
|
419
|
+
type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
304
420
|
asResponse?: boolean;
|
|
305
|
-
/**
|
|
306
|
-
* include headers on the return
|
|
307
|
-
*/
|
|
308
421
|
returnHeaders?: boolean;
|
|
309
|
-
/**
|
|
310
|
-
* Middlewares to use
|
|
311
|
-
*/
|
|
312
422
|
use?: Middleware[];
|
|
313
|
-
/**
|
|
314
|
-
* Customize the path
|
|
315
|
-
*/
|
|
316
423
|
path?: string;
|
|
317
|
-
}
|
|
424
|
+
};
|
|
318
425
|
declare const createInternalContext: (context: InputContext<any, any>, { options, path, }: {
|
|
319
426
|
options: EndpointOptions;
|
|
320
427
|
path: string;
|
|
@@ -346,152 +453,103 @@ declare const createInternalContext: (context: InputContext<any, any>, { options
|
|
|
346
453
|
body?: Record<string, any>;
|
|
347
454
|
} | Response) => Record<string, any>;
|
|
348
455
|
responseHeaders: Headers;
|
|
349
|
-
asResponse?: boolean
|
|
350
|
-
returnHeaders?: boolean
|
|
351
|
-
use?: Middleware[]
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
type MiddlewareResponse = null | void | undefined | Record<string, any>;
|
|
357
|
-
type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
|
|
358
|
-
method: "*";
|
|
359
|
-
}> & {
|
|
360
|
-
/**
|
|
361
|
-
* Method
|
|
362
|
-
*
|
|
363
|
-
* The request method
|
|
364
|
-
*/
|
|
365
|
-
method: string;
|
|
366
|
-
/**
|
|
367
|
-
* Path
|
|
368
|
-
*
|
|
369
|
-
* The path of the endpoint
|
|
370
|
-
*/
|
|
456
|
+
asResponse?: boolean;
|
|
457
|
+
returnHeaders?: boolean;
|
|
458
|
+
use?: Middleware[];
|
|
459
|
+
} | {
|
|
460
|
+
body: any;
|
|
461
|
+
query: any;
|
|
371
462
|
path: string;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
body: InferMiddlewareBody<Options>;
|
|
379
|
-
/**
|
|
380
|
-
* Query
|
|
381
|
-
*
|
|
382
|
-
* The query object will be the parsed query string from the request
|
|
383
|
-
* and validated against the query schema if it exists
|
|
384
|
-
*/
|
|
385
|
-
query: InferMiddlewareQuery<Options>;
|
|
386
|
-
/**
|
|
387
|
-
* Params
|
|
388
|
-
*
|
|
389
|
-
* If the path is `/user/:id` and the request is `/user/1` then the
|
|
390
|
-
* params will
|
|
391
|
-
* be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
|
|
392
|
-
* then the
|
|
393
|
-
* params will be `{ _: "1" }` where `_` is the wildcard key. If the
|
|
394
|
-
* wildcard
|
|
395
|
-
* is named like `/user/**:name` then the params will be `{ name: string }`
|
|
396
|
-
*/
|
|
397
|
-
params: string;
|
|
398
|
-
/**
|
|
399
|
-
* Request object
|
|
400
|
-
*
|
|
401
|
-
* If `requireRequest` is set to true in the endpoint options this will be
|
|
402
|
-
* required
|
|
403
|
-
*/
|
|
404
|
-
request: InferRequest<Options>;
|
|
405
|
-
/**
|
|
406
|
-
* Headers
|
|
407
|
-
*
|
|
408
|
-
* If `requireHeaders` is set to true in the endpoint options this will be
|
|
409
|
-
* required
|
|
410
|
-
*/
|
|
411
|
-
headers: InferHeaders<Options>;
|
|
412
|
-
/**
|
|
413
|
-
* Set header
|
|
414
|
-
*
|
|
415
|
-
* If it's called outside of a request it will just be ignored.
|
|
416
|
-
*/
|
|
463
|
+
context: {};
|
|
464
|
+
returned: any;
|
|
465
|
+
headers: HeadersInit | undefined;
|
|
466
|
+
request: Request | undefined;
|
|
467
|
+
params: Record<string, any> | undefined;
|
|
468
|
+
method: any;
|
|
417
469
|
setHeader: (key: string, value: string) => void;
|
|
418
|
-
/**
|
|
419
|
-
* Get header
|
|
420
|
-
*
|
|
421
|
-
* If it's called outside of a request it will just return null
|
|
422
|
-
*
|
|
423
|
-
* @param key - The key of the header
|
|
424
|
-
* @returns
|
|
425
|
-
*/
|
|
426
470
|
getHeader: (key: string) => string | null;
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
* @param json - The JSON object to return
|
|
438
|
-
* @param routerResponse - The response object to
|
|
439
|
-
* return if `asResponse` is
|
|
440
|
-
* true in the context this will take precedence
|
|
441
|
-
*/
|
|
442
|
-
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?: {
|
|
443
481
|
status?: number;
|
|
444
482
|
headers?: Record<string, string>;
|
|
445
483
|
response?: Response;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
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;
|
|
482
549
|
asResponse?: boolean;
|
|
483
|
-
/**
|
|
484
|
-
* include headers on the return
|
|
485
|
-
*/
|
|
486
550
|
returnHeaders?: boolean;
|
|
487
|
-
/**
|
|
488
|
-
* Middlewares to use
|
|
489
|
-
*/
|
|
490
551
|
use?: Middleware[];
|
|
491
552
|
}>;
|
|
492
|
-
type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
|
|
493
|
-
options: Options;
|
|
494
|
-
};
|
|
495
553
|
|
|
496
554
|
type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
497
555
|
interface OpenAPIParameter {
|
|
@@ -871,11 +929,13 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
|
|
|
871
929
|
};
|
|
872
930
|
declare const createEndpoint: {
|
|
873
931
|
<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: (context: EndpointContext<Path, Options>) => Promise<R>): {
|
|
874
|
-
<
|
|
875
|
-
asResponse
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
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 ? {
|
|
879
939
|
headers: Headers;
|
|
880
940
|
response: R;
|
|
881
941
|
} : R>;
|
|
@@ -885,17 +945,101 @@ declare const createEndpoint: {
|
|
|
885
945
|
create<E extends {
|
|
886
946
|
use?: Middleware[];
|
|
887
947
|
}>(opts?: E): <Path extends string, Opts extends EndpointOptions, R>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, InferUse<E["use"]>>) => Promise<R>) => {
|
|
888
|
-
<
|
|
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 & {
|
|
889
1029
|
use: any[];
|
|
890
|
-
}
|
|
1030
|
+
})["query"]> : Record<string, any> | undefined> & InferParamInput<Path> & InferRequestInput<Opts & {
|
|
891
1031
|
use: any[];
|
|
892
|
-
}>
|
|
1032
|
+
}> & InferHeadersInput<Opts & {
|
|
893
1033
|
use: any[];
|
|
894
|
-
}>
|
|
895
|
-
asResponse
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
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 ? {
|
|
899
1043
|
headers: Headers;
|
|
900
1044
|
response: R;
|
|
901
1045
|
} : R>;
|
|
@@ -981,4 +1125,4 @@ declare const createRouter: <E extends Record<string, Endpoint>, Config extends
|
|
|
981
1125
|
};
|
|
982
1126
|
type Router = ReturnType<typeof createRouter>;
|
|
983
1127
|
|
|
984
|
-
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 };
|