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