better-call 1.1.5 → 1.1.7

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.
Files changed (98) hide show
  1. package/README.md +35 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/adapters/node/request.cjs +125 -0
  4. package/dist/adapters/node/request.cjs.map +1 -0
  5. package/dist/{node.d.ts → adapters/node/request.d.cts} +2 -6
  6. package/dist/adapters/node/request.d.mts +16 -0
  7. package/dist/{node.js → adapters/node/request.mjs} +2 -13
  8. package/dist/adapters/node/request.mjs.map +1 -0
  9. package/dist/client.cjs +8 -1
  10. package/dist/client.cjs.map +1 -1
  11. package/dist/client.d.cts +12 -13
  12. package/dist/client.d.mts +53 -0
  13. package/dist/client.mjs +14 -0
  14. package/dist/client.mjs.map +1 -0
  15. package/dist/context.cjs +102 -0
  16. package/dist/context.cjs.map +1 -0
  17. package/dist/context.d.cts +340 -0
  18. package/dist/context.d.mts +340 -0
  19. package/dist/context.mjs +102 -0
  20. package/dist/context.mjs.map +1 -0
  21. package/dist/cookies.cjs +87 -0
  22. package/dist/cookies.cjs.map +1 -0
  23. package/dist/cookies.d.cts +103 -0
  24. package/dist/cookies.d.mts +103 -0
  25. package/dist/cookies.mjs +84 -0
  26. package/dist/cookies.mjs.map +1 -0
  27. package/dist/crypto.cjs +39 -0
  28. package/dist/crypto.cjs.map +1 -0
  29. package/dist/crypto.mjs +36 -0
  30. package/dist/crypto.mjs.map +1 -0
  31. package/dist/endpoint.cjs +70 -0
  32. package/dist/endpoint.cjs.map +1 -0
  33. package/dist/endpoint.d.cts +428 -0
  34. package/dist/endpoint.d.mts +428 -0
  35. package/dist/endpoint.mjs +70 -0
  36. package/dist/endpoint.mjs.map +1 -0
  37. package/dist/error.cjs +141 -0
  38. package/dist/error.cjs.map +1 -0
  39. package/dist/error.d.cts +103 -0
  40. package/dist/error.d.mts +103 -0
  41. package/dist/error.mjs +135 -0
  42. package/dist/error.mjs.map +1 -0
  43. package/dist/helper.d.cts +12 -0
  44. package/dist/helper.d.mts +12 -0
  45. package/dist/index.cjs +26 -968
  46. package/dist/index.d.cts +11 -14
  47. package/dist/index.d.mts +11 -0
  48. package/dist/index.mjs +10 -0
  49. package/dist/middleware.cjs +39 -0
  50. package/dist/middleware.cjs.map +1 -0
  51. package/dist/middleware.d.cts +123 -0
  52. package/dist/middleware.d.mts +123 -0
  53. package/dist/middleware.mjs +39 -0
  54. package/dist/middleware.mjs.map +1 -0
  55. package/dist/node.cjs +4 -151
  56. package/dist/node.cjs.map +1 -1
  57. package/dist/node.d.cts +2 -13
  58. package/dist/node.d.mts +9 -0
  59. package/dist/node.mjs +15 -0
  60. package/dist/node.mjs.map +1 -0
  61. package/dist/openapi.cjs +191 -0
  62. package/dist/openapi.cjs.map +1 -0
  63. package/dist/openapi.d.cts +113 -0
  64. package/dist/openapi.d.mts +113 -0
  65. package/dist/openapi.mjs +189 -0
  66. package/dist/openapi.mjs.map +1 -0
  67. package/dist/router.cjs +117 -0
  68. package/dist/router.cjs.map +1 -0
  69. package/dist/router.d.cts +4 -1242
  70. package/dist/router.d.mts +97 -0
  71. package/dist/router.mjs +116 -0
  72. package/dist/router.mjs.map +1 -0
  73. package/dist/standard-schema.d.cts +59 -0
  74. package/dist/standard-schema.d.mts +59 -0
  75. package/dist/to-response.cjs +96 -0
  76. package/dist/to-response.cjs.map +1 -0
  77. package/dist/to-response.d.cts +12 -0
  78. package/dist/to-response.d.mts +12 -0
  79. package/dist/to-response.mjs +96 -0
  80. package/dist/to-response.mjs.map +1 -0
  81. package/dist/utils.cjs +77 -0
  82. package/dist/utils.cjs.map +1 -0
  83. package/dist/utils.mjs +74 -0
  84. package/dist/utils.mjs.map +1 -0
  85. package/dist/validator.cjs +58 -0
  86. package/dist/validator.cjs.map +1 -0
  87. package/dist/validator.mjs +57 -0
  88. package/dist/validator.mjs.map +1 -0
  89. package/package.json +23 -13
  90. package/dist/client.d.ts +0 -54
  91. package/dist/client.js +0 -13
  92. package/dist/client.js.map +0 -1
  93. package/dist/index.cjs.map +0 -1
  94. package/dist/index.d.ts +0 -14
  95. package/dist/index.js +0 -951
  96. package/dist/index.js.map +0 -1
  97. package/dist/node.js.map +0 -1
  98. package/dist/router.d.ts +0 -1335
package/dist/router.d.cts CHANGED
@@ -1,1244 +1,6 @@
1
- //#region src/helper.d.ts
2
- type RequiredKeysOf<BaseType extends object> = Exclude<{ [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never }[keyof BaseType], undefined>;
3
- type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
4
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
5
- type IsEmptyObject<T> = keyof T extends never ? true : false;
6
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
7
- type MergeObject<T extends Record<string, any> | never, S extends Record<string, any> | never> = T extends never ? S : S extends never ? T : T & S;
8
- type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
9
- type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}/*` ? { [K in "_"]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamWildCard<Rest> : {};
10
- //#endregion
11
- //#region src/standard-schema.d.ts
12
- /** The Standard Schema interface. */
13
- interface StandardSchemaV1<Input = unknown, Output = Input> {
14
- /** The Standard Schema properties. */
15
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
16
- }
17
- declare namespace StandardSchemaV1 {
18
- /** The Standard Schema properties interface. */
19
- interface Props<Input = unknown, Output = Input> {
20
- /** The version number of the standard. */
21
- readonly version: 1;
22
- /** The vendor name of the schema library. */
23
- readonly vendor: string;
24
- /** Validates unknown input values. */
25
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
26
- /** Inferred types associated with the schema. */
27
- readonly types?: Types<Input, Output> | undefined;
28
- }
29
- /** The result interface of the validate function. */
30
- type Result<Output> = SuccessResult<Output> | FailureResult;
31
- /** The result interface if validation succeeds. */
32
- interface SuccessResult<Output> {
33
- /** The typed output value. */
34
- readonly value: Output;
35
- /** The non-existent issues. */
36
- readonly issues?: undefined;
37
- }
38
- /** The result interface if validation fails. */
39
- interface FailureResult {
40
- /** The issues of failed validation. */
41
- readonly issues: ReadonlyArray<Issue>;
42
- }
43
- /** The issue interface of the failure output. */
44
- interface Issue {
45
- /** The error message of the issue. */
46
- readonly message: string;
47
- /** The path of the issue, if any. */
48
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
49
- }
50
- /** The path segment interface of the issue. */
51
- interface PathSegment {
52
- /** The key representing a path segment. */
53
- readonly key: PropertyKey;
54
- }
55
- /** The Standard Schema types interface. */
56
- interface Types<Input = unknown, Output = Input> {
57
- /** The input type of the schema. */
58
- readonly input: Input;
59
- /** The output type of the schema. */
60
- readonly output: Output;
61
- }
62
- /** Infers the input type of a Standard Schema. */
63
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
64
- /** Infers the output type of a Standard Schema. */
65
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
66
- }
67
- //#endregion
68
- //#region src/error.d.ts
69
- /**
70
- * Hide internal stack frames from the error stack trace.
71
- */
72
- declare function hideInternalStackFrames(stack: string): string;
73
- /**
74
- * Creates a custom error class that hides stack frames.
75
- */
76
- declare function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(Base: B, clazz: any): {
77
- new (...args: ConstructorParameters<B>): InstanceType<B> & {
78
- errorStack: string | undefined;
79
- };
80
- };
81
- declare const statusCodes: {
82
- OK: number;
83
- CREATED: number;
84
- ACCEPTED: number;
85
- NO_CONTENT: number;
86
- MULTIPLE_CHOICES: number;
87
- MOVED_PERMANENTLY: number;
88
- FOUND: number;
89
- SEE_OTHER: number;
90
- NOT_MODIFIED: number;
91
- TEMPORARY_REDIRECT: number;
92
- BAD_REQUEST: number;
93
- UNAUTHORIZED: number;
94
- PAYMENT_REQUIRED: number;
95
- FORBIDDEN: number;
96
- NOT_FOUND: number;
97
- METHOD_NOT_ALLOWED: number;
98
- NOT_ACCEPTABLE: number;
99
- PROXY_AUTHENTICATION_REQUIRED: number;
100
- REQUEST_TIMEOUT: number;
101
- CONFLICT: number;
102
- GONE: number;
103
- LENGTH_REQUIRED: number;
104
- PRECONDITION_FAILED: number;
105
- PAYLOAD_TOO_LARGE: number;
106
- URI_TOO_LONG: number;
107
- UNSUPPORTED_MEDIA_TYPE: number;
108
- RANGE_NOT_SATISFIABLE: number;
109
- EXPECTATION_FAILED: number;
110
- "I'M_A_TEAPOT": number;
111
- MISDIRECTED_REQUEST: number;
112
- UNPROCESSABLE_ENTITY: number;
113
- LOCKED: number;
114
- FAILED_DEPENDENCY: number;
115
- TOO_EARLY: number;
116
- UPGRADE_REQUIRED: number;
117
- PRECONDITION_REQUIRED: number;
118
- TOO_MANY_REQUESTS: number;
119
- REQUEST_HEADER_FIELDS_TOO_LARGE: number;
120
- UNAVAILABLE_FOR_LEGAL_REASONS: number;
121
- INTERNAL_SERVER_ERROR: number;
122
- NOT_IMPLEMENTED: number;
123
- BAD_GATEWAY: number;
124
- SERVICE_UNAVAILABLE: number;
125
- GATEWAY_TIMEOUT: number;
126
- HTTP_VERSION_NOT_SUPPORTED: number;
127
- VARIANT_ALSO_NEGOTIATES: number;
128
- INSUFFICIENT_STORAGE: number;
129
- LOOP_DETECTED: number;
130
- NOT_EXTENDED: number;
131
- NETWORK_AUTHENTICATION_REQUIRED: number;
132
- };
133
- type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
134
- declare class InternalAPIError extends Error {
135
- status: keyof typeof statusCodes | Status;
136
- body: ({
137
- message?: string;
138
- code?: string;
139
- cause?: unknown;
140
- } & Record<string, any>) | undefined;
141
- headers: HeadersInit;
142
- statusCode: number;
143
- constructor(status?: keyof typeof statusCodes | Status, body?: ({
144
- message?: string;
145
- code?: string;
146
- cause?: unknown;
147
- } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
148
- }
149
- declare class ValidationError extends InternalAPIError {
150
- message: string;
151
- issues: readonly StandardSchemaV1.Issue[];
152
- constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
153
- }
154
- declare class BetterCallError extends Error {
155
- constructor(message: string);
156
- }
157
- type APIError = InstanceType<typeof InternalAPIError>;
158
- declare const APIError: new (status?: "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED" | Status | undefined, body?: ({
159
- message?: string;
160
- code?: string;
161
- cause?: unknown;
162
- } & Record<string, any>) | undefined, headers?: HeadersInit | undefined, statusCode?: number | undefined) => InternalAPIError & {
163
- errorStack: string | undefined;
164
- };
165
- //#endregion
166
- //#region src/cookies.d.ts
167
- type CookiePrefixOptions = "host" | "secure";
168
- type CookieOptions = {
169
- /**
170
- * Domain of the cookie
171
- *
172
- * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
173
- * available on the specified server and its subdomains. If the it is not
174
- * specified, the cookies are available on the server that sets it but not on
175
- * its subdomains.
176
- *
177
- * @example
178
- * `domain: "example.com"`
179
- */
180
- domain?: string;
181
- /**
182
- * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
183
- * Expires attribute:
184
- *
185
- * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
186
- * takes precedence when both are set. The rationale behind this is that when you set an
187
- * Expires date and time, they're relative to the client the cookie is being set on. If the
188
- * server is set to a different time, this could cause errors
189
- */
190
- expires?: Date;
191
- /**
192
- * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
193
- * property. Note that a cookie that has been created with HttpOnly will still be sent with
194
- * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
195
- * This mitigates attacks against cross-site scripting
196
- */
197
- httpOnly?: boolean;
198
- /**
199
- * Indicates the number of seconds until the cookie expires. A zero or negative number will
200
- * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
201
- *
202
- * @example 604800 - 7 days
203
- */
204
- maxAge?: number;
205
- /**
206
- * Indicates the path that must exist in the requested URL for the browser to send the Cookie
207
- * header.
208
- *
209
- * @example
210
- * "/docs"
211
- * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
212
- */
213
- path?: string;
214
- /**
215
- * Indicates that the cookie is sent to the server only when a request is made with the https:
216
- * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
217
- */
218
- secure?: boolean;
219
- /**
220
- * Controls whether or not a cookie is sent with cross-site requests, providing some protection
221
- * against cross-site request forgery attacks (CSRF).
222
- *
223
- * Strict - Means that the browser sends the cookie only for same-site requests, that is,
224
- * requests originating from the same site that set the cookie. If a request originates from a
225
- * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
226
- * attribute are sent.
227
- *
228
- * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
229
- * images or frames, but is sent when a user is navigating to the origin site from an external
230
- * site (for example, when following a link). This is the default behavior if the SameSite
231
- * attribute is not specified.
232
- *
233
- * None - Means that the browser sends the cookie with both cross-site and same-site requests.
234
- * The Secure attribute must also be set when setting this value.
235
- */
236
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
237
- /**
238
- * Indicates that the cookie should be stored using partitioned storage. Note that if this is
239
- * set, the Secure directive must also be set.
240
- *
241
- * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
242
- */
243
- partitioned?: boolean;
244
- /**
245
- * Cooke Prefix
246
- *
247
- * - secure: `__Secure-` -> `__Secure-cookie-name`
248
- * - host: `__Host-` -> `__Host-cookie-name`
249
- *
250
- * `secure` must be set to true to use prefixes
251
- */
252
- prefix?: CookiePrefixOptions;
253
- };
254
- declare const getCookieKey: (key: string, prefix?: CookiePrefixOptions) => string | undefined;
255
- /**
256
- * Parse an HTTP Cookie header string and returning an object of all cookie
257
- * name-value pairs.
258
- *
259
- * Inspired by https://github.com/unjs/cookie-es/blob/main/src/cookie/parse.ts
260
- *
261
- * @param str the string representing a `Cookie` header value
262
- */
263
- declare function parseCookies(str: string): Map<string, string>;
264
- declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string;
265
- declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise<string>;
266
- //#endregion
267
- //#region src/context.d.ts
268
- type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
269
- type Method = HTTPMethod | "*";
270
- type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = (Options["metadata"] extends {
271
- $Infer: {
272
- body: infer B;
273
- };
274
- } ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined)> = undefined extends Body ? {
275
- body?: Body;
276
- } : {
277
- body: Body;
278
- };
279
- type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
280
- $Infer: {
281
- body: infer Body;
282
- };
283
- } ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
284
- type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = (Options["metadata"] extends {
285
- $Infer: {
286
- query: infer Query;
287
- };
288
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined)> = undefined extends Query ? {
289
- query?: Query;
290
- } : {
291
- query: Query;
292
- };
293
- type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
294
- $Infer: {
295
- query: infer Query;
296
- };
297
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
298
- type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
299
- type InferInputMethod<Options extends EndpointOptions, Method = (Options["method"] extends Array<any> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined)> = undefined extends Method ? {
300
- method?: Method;
301
- } : {
302
- method: Method;
303
- };
304
- type InferParam<Path extends string> = [Path] extends [never] ? Record<string, any> | undefined : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
305
- type InferParamInput<Path extends string> = [Path] extends [never] ? {
306
- params?: Record<string, any>;
307
- } : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
308
- params?: Record<string, any>;
309
- } : {
310
- params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
311
- };
312
- type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
313
- type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
314
- request: Request;
315
- } : {
316
- request?: Request;
317
- };
318
- type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
319
- type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
320
- headers: HeadersInit;
321
- } : {
322
- headers?: HeadersInit;
323
- };
324
- type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
325
- type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
326
- type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
327
- type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
328
- asResponse?: boolean;
329
- returnHeaders?: boolean;
330
- returnStatus?: boolean;
331
- use?: Middleware[];
332
- path?: string;
333
- };
334
- declare const createInternalContext: (context: InputContext<any, any>, {
335
- options,
336
- path
337
- }: {
338
- options: EndpointOptions;
339
- path?: string;
340
- }) => Promise<{
341
- body: any;
342
- query: any;
343
- path: string;
344
- context: {};
345
- returned: any;
346
- headers: HeadersInit | undefined;
347
- request: Request | undefined;
348
- params: Record<string, any> | undefined;
349
- method: any;
350
- setHeader: (key: string, value: string) => void;
351
- getHeader: (key: string) => string | null;
352
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
353
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
354
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
355
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
356
- redirect: (url: string) => {
357
- status: keyof typeof statusCodes | Status;
358
- body: ({
359
- message?: string;
360
- code?: string;
361
- cause?: unknown;
362
- } & Record<string, any>) | undefined;
363
- headers: HeadersInit;
364
- statusCode: number;
365
- name: string;
366
- message: string;
367
- stack?: string;
368
- cause?: unknown;
369
- } & {
370
- errorStack: string | undefined;
371
- };
372
- error: (status: keyof typeof statusCodes | Status, body?: {
373
- message?: string;
374
- code?: string;
375
- } | undefined, headers?: HeadersInit) => {
376
- status: keyof typeof statusCodes | Status;
377
- body: ({
378
- message?: string;
379
- code?: string;
380
- cause?: unknown;
381
- } & Record<string, any>) | undefined;
382
- headers: HeadersInit;
383
- statusCode: number;
384
- name: string;
385
- message: string;
386
- stack?: string;
387
- cause?: unknown;
388
- } & {
389
- errorStack: string | undefined;
390
- };
391
- setStatus: (status: Status) => void;
392
- json: (json: Record<string, any>, routerResponse?: {
393
- status?: number;
394
- headers?: Record<string, string>;
395
- response?: Response;
396
- body?: Record<string, any>;
397
- } | Response) => Record<string, any>;
398
- responseHeaders: Headers;
399
- responseStatus: Status | undefined;
400
- asResponse?: boolean;
401
- returnHeaders?: boolean;
402
- returnStatus?: boolean;
403
- use?: Middleware[];
404
- } | {
405
- body: any;
406
- query: any;
407
- path: string;
408
- context: {};
409
- returned: any;
410
- headers: HeadersInit | undefined;
411
- request: Request | undefined;
412
- params: Record<string, any> | undefined;
413
- method: any;
414
- setHeader: (key: string, value: string) => void;
415
- getHeader: (key: string) => string | null;
416
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
417
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
418
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
419
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
420
- redirect: (url: string) => {
421
- status: keyof typeof statusCodes | Status;
422
- body: ({
423
- message?: string;
424
- code?: string;
425
- cause?: unknown;
426
- } & Record<string, any>) | undefined;
427
- headers: HeadersInit;
428
- statusCode: number;
429
- name: string;
430
- message: string;
431
- stack?: string;
432
- cause?: unknown;
433
- } & {
434
- errorStack: string | undefined;
435
- };
436
- error: (status: keyof typeof statusCodes | Status, body?: {
437
- message?: string;
438
- code?: string;
439
- } | undefined, headers?: HeadersInit) => {
440
- status: keyof typeof statusCodes | Status;
441
- body: ({
442
- message?: string;
443
- code?: string;
444
- cause?: unknown;
445
- } & Record<string, any>) | undefined;
446
- headers: HeadersInit;
447
- statusCode: number;
448
- name: string;
449
- message: string;
450
- stack?: string;
451
- cause?: unknown;
452
- } & {
453
- errorStack: string | undefined;
454
- };
455
- setStatus: (status: Status) => void;
456
- json: (json: Record<string, any>, routerResponse?: {
457
- status?: number;
458
- headers?: Record<string, string>;
459
- response?: Response;
460
- body?: Record<string, any>;
461
- } | Response) => Record<string, any>;
462
- responseHeaders: Headers;
463
- responseStatus: Status | undefined;
464
- asResponse?: boolean;
465
- returnHeaders?: boolean;
466
- returnStatus?: boolean;
467
- use?: Middleware[];
468
- } | {
469
- body: any;
470
- query: any;
471
- path: string;
472
- context: {};
473
- returned: any;
474
- headers: HeadersInit | undefined;
475
- request: Request | undefined;
476
- params: Record<string, any> | undefined;
477
- method: any;
478
- setHeader: (key: string, value: string) => void;
479
- getHeader: (key: string) => string | null;
480
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
481
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
482
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
483
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
484
- redirect: (url: string) => {
485
- status: keyof typeof statusCodes | Status;
486
- body: ({
487
- message?: string;
488
- code?: string;
489
- cause?: unknown;
490
- } & Record<string, any>) | undefined;
491
- headers: HeadersInit;
492
- statusCode: number;
493
- name: string;
494
- message: string;
495
- stack?: string;
496
- cause?: unknown;
497
- } & {
498
- errorStack: string | undefined;
499
- };
500
- error: (status: keyof typeof statusCodes | Status, body?: {
501
- message?: string;
502
- code?: string;
503
- } | undefined, headers?: HeadersInit) => {
504
- status: keyof typeof statusCodes | Status;
505
- body: ({
506
- message?: string;
507
- code?: string;
508
- cause?: unknown;
509
- } & Record<string, any>) | undefined;
510
- headers: HeadersInit;
511
- statusCode: number;
512
- name: string;
513
- message: string;
514
- stack?: string;
515
- cause?: unknown;
516
- } & {
517
- errorStack: string | undefined;
518
- };
519
- setStatus: (status: Status) => void;
520
- json: (json: Record<string, any>, routerResponse?: {
521
- status?: number;
522
- headers?: Record<string, string>;
523
- response?: Response;
524
- body?: Record<string, any>;
525
- } | Response) => Record<string, any>;
526
- responseHeaders: Headers;
527
- responseStatus: Status | undefined;
528
- asResponse?: boolean;
529
- returnHeaders?: boolean;
530
- returnStatus?: boolean;
531
- use?: Middleware[];
532
- } | {
533
- body: any;
534
- query: any;
535
- path: string;
536
- context: {};
537
- returned: any;
538
- headers: HeadersInit | undefined;
539
- request: Request | undefined;
540
- params: Record<string, any> | undefined;
541
- method: any;
542
- setHeader: (key: string, value: string) => void;
543
- getHeader: (key: string) => string | null;
544
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
545
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | false | null>;
546
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
547
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
548
- redirect: (url: string) => {
549
- status: keyof typeof statusCodes | Status;
550
- body: ({
551
- message?: string;
552
- code?: string;
553
- cause?: unknown;
554
- } & Record<string, any>) | undefined;
555
- headers: HeadersInit;
556
- statusCode: number;
557
- name: string;
558
- message: string;
559
- stack?: string;
560
- cause?: unknown;
561
- } & {
562
- errorStack: string | undefined;
563
- };
564
- error: (status: keyof typeof statusCodes | Status, body?: {
565
- message?: string;
566
- code?: string;
567
- } | undefined, headers?: HeadersInit) => {
568
- status: keyof typeof statusCodes | Status;
569
- body: ({
570
- message?: string;
571
- code?: string;
572
- cause?: unknown;
573
- } & Record<string, any>) | undefined;
574
- headers: HeadersInit;
575
- statusCode: number;
576
- name: string;
577
- message: string;
578
- stack?: string;
579
- cause?: unknown;
580
- } & {
581
- errorStack: string | undefined;
582
- };
583
- setStatus: (status: Status) => void;
584
- json: (json: Record<string, any>, routerResponse?: {
585
- status?: number;
586
- headers?: Record<string, string>;
587
- response?: Response;
588
- body?: Record<string, any>;
589
- } | Response) => Record<string, any>;
590
- responseHeaders: Headers;
591
- responseStatus: Status | undefined;
592
- asResponse?: boolean;
593
- returnHeaders?: boolean;
594
- returnStatus?: boolean;
595
- use?: Middleware[];
596
- }>;
597
- //#endregion
598
- //#region src/middleware.d.ts
599
- interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {}
600
- type MiddlewareResponse = null | void | undefined | Record<string, any>;
601
- type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
602
- method: "*";
603
- }> & {
604
- /**
605
- * Method
606
- *
607
- * The request method
608
- */
609
- method: string;
610
- /**
611
- * Path
612
- *
613
- * The path of the endpoint
614
- */
615
- path: string;
616
- /**
617
- * Body
618
- *
619
- * The body object will be the parsed JSON from the request and validated
620
- * against the body schema if it exists
621
- */
622
- body: InferMiddlewareBody<Options>;
623
- /**
624
- * Query
625
- *
626
- * The query object will be the parsed query string from the request
627
- * and validated against the query schema if it exists
628
- */
629
- query: InferMiddlewareQuery<Options>;
630
- /**
631
- * Params
632
- *
633
- * If the path is `/user/:id` and the request is `/user/1` then the
634
- * params will
635
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
636
- * then the
637
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the
638
- * wildcard
639
- * is named like `/user/**:name` then the params will be `{ name: string }`
640
- */
641
- params: string;
642
- /**
643
- * Request object
644
- *
645
- * If `requireRequest` is set to true in the endpoint options this will be
646
- * required
647
- */
648
- request: InferRequest<Options>;
649
- /**
650
- * Headers
651
- *
652
- * If `requireHeaders` is set to true in the endpoint options this will be
653
- * required
654
- */
655
- headers: InferHeaders<Options>;
656
- /**
657
- * Set header
658
- *
659
- * If it's called outside of a request it will just be ignored.
660
- */
661
- setHeader: (key: string, value: string) => void;
662
- /**
663
- * Get header
664
- *
665
- * If it's called outside of a request it will just return null
666
- *
667
- * @param key - The key of the header
668
- * @returns
669
- */
670
- getHeader: (key: string) => string | null;
671
- /**
672
- * JSON
673
- *
674
- * a helper function to create a JSON response with
675
- * the correct headers
676
- * and status code. If `asResponse` is set to true in
677
- * the context then
678
- * it will return a Response object instead of the
679
- * JSON object.
680
- *
681
- * @param json - The JSON object to return
682
- * @param routerResponse - The response object to
683
- * return if `asResponse` is
684
- * true in the context this will take precedence
685
- */
686
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
687
- status?: number;
688
- headers?: Record<string, string>;
689
- response?: Response;
690
- } | Response) => Promise<R>;
691
- /**
692
- * Middleware context
693
- */
694
- context: Prettify<Context>;
695
- };
696
- declare function createMiddleware<Options extends MiddlewareOptions, R>(options: Options, handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
697
- declare function createMiddleware<Options extends MiddlewareOptions, R>(handler: (context: MiddlewareContext<Options>) => Promise<R>): <InputCtx extends MiddlewareInputContext<Options>>(inputContext: InputCtx) => Promise<R>;
698
- declare namespace createMiddleware {
699
- var create: <E extends {
700
- use?: Middleware[];
701
- }>(opts?: E) => {
702
- <Options extends MiddlewareOptions, R>(options: Options, handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R>): (inputContext: MiddlewareInputContext<Options>) => Promise<R>;
703
- <Options extends MiddlewareOptions, R_1>(handler: (ctx: MiddlewareContext<Options, InferUse<E["use"]>>) => Promise<R_1>): (inputContext: MiddlewareInputContext<Options>) => Promise<R_1>;
704
- };
705
- }
706
- type MiddlewareInputContext<Options extends MiddlewareOptions> = InferBodyInput<Options> & InferQueryInput<Options> & InferRequestInput<Options> & InferHeadersInput<Options> & {
707
- asResponse?: boolean;
708
- returnHeaders?: boolean;
709
- use?: Middleware[];
710
- };
711
- type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
712
- options: Options;
713
- };
714
- //#endregion
715
- //#region src/openapi.d.ts
716
- type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
717
- interface OpenAPIParameter {
718
- in: "query" | "path" | "header" | "cookie";
719
- name?: string;
720
- description?: string;
721
- required?: boolean;
722
- schema?: {
723
- type: OpenAPISchemaType;
724
- format?: string;
725
- items?: {
726
- type: OpenAPISchemaType;
727
- };
728
- enum?: string[];
729
- minLength?: number;
730
- description?: string;
731
- default?: string;
732
- example?: string;
733
- };
734
- }
735
- interface Path$1 {
736
- get?: {
737
- tags?: string[];
738
- operationId?: string;
739
- description?: string;
740
- security?: [{
741
- bearerAuth: string[];
742
- }];
743
- parameters?: OpenAPIParameter[];
744
- responses?: { [key in string]: {
745
- description?: string;
746
- content: {
747
- "application/json": {
748
- schema: {
749
- type?: OpenAPISchemaType;
750
- properties?: Record<string, any>;
751
- required?: string[];
752
- $ref?: string;
753
- };
754
- };
755
- };
756
- } };
757
- };
758
- post?: {
759
- tags?: string[];
760
- operationId?: string;
761
- description?: string;
762
- security?: [{
763
- bearerAuth: string[];
764
- }];
765
- parameters?: OpenAPIParameter[];
766
- requestBody?: {
767
- content: {
768
- "application/json": {
769
- schema: {
770
- type?: OpenAPISchemaType;
771
- properties?: Record<string, any>;
772
- required?: string[];
773
- $ref?: string;
774
- };
775
- };
776
- };
777
- };
778
- responses?: { [key in string]: {
779
- description?: string;
780
- content: {
781
- "application/json": {
782
- schema: {
783
- type?: OpenAPISchemaType;
784
- properties?: Record<string, any>;
785
- required?: string[];
786
- $ref?: string;
787
- };
788
- };
789
- };
790
- } };
791
- };
792
- }
793
- declare function generator(endpoints: Record<string, Endpoint>, config?: {
794
- url: string;
795
- }): Promise<{
796
- openapi: string;
797
- info: {
798
- title: string;
799
- description: string;
800
- version: string;
801
- };
802
- components: {
803
- schemas: {};
804
- };
805
- security: {
806
- apiKeyCookie: never[];
807
- }[];
808
- servers: {
809
- url: string | undefined;
810
- }[];
811
- tags: {
812
- name: string;
813
- description: string;
814
- }[];
815
- paths: Record<string, Path$1>;
816
- }>;
817
- declare const getHTML: (apiReference: Record<string, any>, config?: {
818
- logo?: string;
819
- theme?: string;
820
- title?: string;
821
- description?: string;
822
- }) => string;
823
- //#endregion
824
- //#region src/endpoint.d.ts
825
- interface EndpointBaseOptions {
826
- /**
827
- * Query Schema
828
- */
829
- query?: StandardSchemaV1;
830
- /**
831
- * Error Schema
832
- */
833
- error?: StandardSchemaV1;
834
- /**
835
- * If true headers will be required to be passed in the context
836
- */
837
- requireHeaders?: boolean;
838
- /**
839
- * If true request object will be required
840
- */
841
- requireRequest?: boolean;
842
- /**
843
- * Clone the request object from the router
844
- */
845
- cloneRequest?: boolean;
846
- /**
847
- * If true the body will be undefined
848
- */
849
- disableBody?: boolean;
850
- /**
851
- * Endpoint metadata
852
- */
853
- metadata?: {
854
- /**
855
- * Open API definition
856
- */
857
- openapi?: {
858
- summary?: string;
859
- description?: string;
860
- tags?: string[];
861
- operationId?: string;
862
- parameters?: OpenAPIParameter[];
863
- requestBody?: {
864
- content: {
865
- "application/json": {
866
- schema: {
867
- type?: OpenAPISchemaType;
868
- properties?: Record<string, any>;
869
- required?: string[];
870
- $ref?: string;
871
- };
872
- };
873
- };
874
- };
875
- responses?: {
876
- [status: string]: {
877
- description: string;
878
- content?: {
879
- "application/json"?: {
880
- schema: {
881
- type?: OpenAPISchemaType;
882
- properties?: Record<string, any>;
883
- required?: string[];
884
- $ref?: string;
885
- };
886
- };
887
- "text/plain"?: {
888
- schema?: {
889
- type?: OpenAPISchemaType;
890
- properties?: Record<string, any>;
891
- required?: string[];
892
- $ref?: string;
893
- };
894
- };
895
- "text/html"?: {
896
- schema?: {
897
- type?: OpenAPISchemaType;
898
- properties?: Record<string, any>;
899
- required?: string[];
900
- $ref?: string;
901
- };
902
- };
903
- };
904
- };
905
- };
906
- };
907
- /**
908
- * Infer body and query type from ts interface
909
- *
910
- * useful for generic and dynamic types
911
- *
912
- * @example
913
- * ```ts
914
- * const endpoint = createEndpoint("/path", {
915
- * method: "POST",
916
- * body: z.record(z.string()),
917
- * $Infer: {
918
- * body: {} as {
919
- * type: InferTypeFromOptions<Option> // custom type inference
920
- * }
921
- * }
922
- * }, async(ctx)=>{
923
- * const body = ctx.body
924
- * })
925
- * ```
926
- */
927
- $Infer?: {
928
- /**
929
- * Body
930
- */
931
- body?: any;
932
- /**
933
- * Query
934
- */
935
- query?: Record<string, any>;
936
- };
937
- /**
938
- * If enabled, endpoint won't be exposed over a router
939
- * @deprecated Use path-less endpoints instead
940
- */
941
- SERVER_ONLY?: boolean;
942
- /**
943
- * If enabled, endpoint won't be exposed as an action to the client
944
- * @deprecated Use path-less endpoints instead
945
- */
946
- isAction?: boolean;
947
- /**
948
- * Defines the places where the endpoint will be available
949
- *
950
- * Possible options:
951
- * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
952
- * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
953
- * - `http` - the endpoint is only exposed to the router
954
- * @default "rpc"
955
- */
956
- scope?: "rpc" | "server" | "http";
957
- /**
958
- * List of allowed media types (MIME types) for the endpoint
959
- *
960
- * if provided, only the media types in the list will be allowed to be passed in the body
961
- *
962
- * @example
963
- * ```ts
964
- * const endpoint = createEndpoint("/path", {
965
- * method: "POST",
966
- * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
967
- * }, async(ctx)=>{
968
- * const body = ctx.body
969
- * })
970
- * ```
971
- */
972
- allowedMediaTypes?: string[];
973
- /**
974
- * Extra metadata
975
- */
976
- [key: string]: any;
977
- };
978
- /**
979
- * List of middlewares to use
980
- */
981
- use?: Middleware[];
982
- /**
983
- * A callback to run before any API error is throw or returned
984
- *
985
- * @param e - The API error
986
- * @returns - The response to return
987
- */
988
- onAPIError?: (e: APIError) => void | Promise<void>;
989
- /**
990
- * A callback to run before a validation error is thrown
991
- * You can customize the validation error message by throwing your own APIError
992
- */
993
- onValidationError?: ({
994
- issues,
995
- message
996
- }: {
997
- message: string;
998
- issues: readonly StandardSchemaV1.Issue[];
999
- }) => void | Promise<void>;
1000
- }
1001
- type EndpointBodyMethodOptions = {
1002
- /**
1003
- * Request Method
1004
- */
1005
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
1006
- /**
1007
- * Body Schema
1008
- */
1009
- body?: StandardSchemaV1;
1010
- } | {
1011
- /**
1012
- * Request Method
1013
- */
1014
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
1015
- /**
1016
- * Body Schema
1017
- */
1018
- body?: never;
1019
- } | {
1020
- /**
1021
- * Request Method
1022
- */
1023
- method: "*";
1024
- /**
1025
- * Body Schema
1026
- */
1027
- body?: StandardSchemaV1;
1028
- } | {
1029
- /**
1030
- * Request Method
1031
- */
1032
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
1033
- /**
1034
- * Body Schema
1035
- */
1036
- body?: StandardSchemaV1;
1037
- };
1038
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
1039
- type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
1040
- /**
1041
- * Method
1042
- *
1043
- * The request method
1044
- */
1045
- method: InferMethod<Options>;
1046
- /**
1047
- * Path
1048
- *
1049
- * The path of the endpoint
1050
- */
1051
- path: Path;
1052
- /**
1053
- * Body
1054
- *
1055
- * The body object will be the parsed JSON from the request and validated
1056
- * against the body schema if it exists.
1057
- */
1058
- body: InferBody<Options>;
1059
- /**
1060
- * Query
1061
- *
1062
- * The query object will be the parsed query string from the request
1063
- * and validated against the query schema if it exists
1064
- */
1065
- query: InferQuery<Options>;
1066
- /**
1067
- * Params
1068
- *
1069
- * If the path is `/user/:id` and the request is `/user/1` then the params will
1070
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*` then the
1071
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the wildcard
1072
- * is named like `/user/**:name` then the params will be `{ name: string }`
1073
- */
1074
- params: InferParam<Path>;
1075
- /**
1076
- * Request object
1077
- *
1078
- * If `requireRequest` is set to true in the endpoint options this will be
1079
- * required
1080
- */
1081
- request: InferRequest<Options>;
1082
- /**
1083
- * Headers
1084
- *
1085
- * If `requireHeaders` is set to true in the endpoint options this will be
1086
- * required
1087
- */
1088
- headers: InferHeaders<Options>;
1089
- /**
1090
- * Set header
1091
- *
1092
- * If it's called outside of a request it will just be ignored.
1093
- */
1094
- setHeader: (key: string, value: string) => void;
1095
- /**
1096
- * Set the response status code
1097
- */
1098
- setStatus: (status: Status) => void;
1099
- /**
1100
- * Get header
1101
- *
1102
- * If it's called outside of a request it will just return null
1103
- *
1104
- * @param key - The key of the header
1105
- * @returns
1106
- */
1107
- getHeader: (key: string) => string | null;
1108
- /**
1109
- * Get a cookie value from the request
1110
- *
1111
- * @param key - The key of the cookie
1112
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
1113
- * @returns - The value of the cookie
1114
- */
1115
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
1116
- /**
1117
- * Get a signed cookie value from the request
1118
- *
1119
- * @param key - The key of the cookie
1120
- * @param secret - The secret of the signed cookie
1121
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
1122
- * @returns - The value of the cookie or null if the cookie is not found or false if the signature is invalid
1123
- */
1124
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
1125
- /**
1126
- * Set a cookie value in the response
1127
- *
1128
- * @param key - The key of the cookie
1129
- * @param value - The value to set
1130
- * @param options - The options of the cookie
1131
- * @returns - The cookie string
1132
- */
1133
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
1134
- /**
1135
- * Set signed cookie
1136
- *
1137
- * @param key - The key of the cookie
1138
- * @param value - The value to set
1139
- * @param secret - The secret to sign the cookie with
1140
- * @param options - The options of the cookie
1141
- * @returns - The cookie string
1142
- */
1143
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
1144
- /**
1145
- * JSON
1146
- *
1147
- * a helper function to create a JSON response with
1148
- * the correct headers
1149
- * and status code. If `asResponse` is set to true in
1150
- * the context then
1151
- * it will return a Response object instead of the
1152
- * JSON object.
1153
- *
1154
- * @param json - The JSON object to return
1155
- * @param routerResponse - The response object to
1156
- * return if `asResponse` is
1157
- * true in the context this will take precedence
1158
- */
1159
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
1160
- status?: number;
1161
- headers?: Record<string, string>;
1162
- response?: Response;
1163
- body?: Record<string, string>;
1164
- } | Response) => Promise<R>;
1165
- /**
1166
- * Middleware context
1167
- */
1168
- context: Prettify<Context & InferUse<Options["use"]>>;
1169
- /**
1170
- * Redirect to a new URL
1171
- */
1172
- redirect: (url: string) => APIError;
1173
- /**
1174
- * Return error
1175
- */
1176
- error: (status: keyof typeof statusCodes | Status, body?: {
1177
- message?: string;
1178
- code?: string;
1179
- } & Record<string, any>, headers?: HeadersInit) => APIError;
1180
- };
1181
- type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options>) => Promise<R>;
1182
- declare function createEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
1183
- declare function createEndpoint<Options extends EndpointOptions, R>(options: Options, handler: EndpointHandler<never, Options, R>): StrictEndpoint<never, Options, R>;
1184
- declare namespace createEndpoint {
1185
- var create: <E extends {
1186
- use?: Middleware[];
1187
- }>(opts?: E) => <Path extends string, Opts extends EndpointOptions, R extends Promise<any>>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, InferUse<E["use"]>>) => R) => StrictEndpoint<Path, Opts & {
1188
- use: any[];
1189
- }, any>;
1190
- }
1191
- type StrictEndpoint<Path extends string, Options extends EndpointOptions, R = any> = {
1192
- (context: InputContext<Path, Options> & {
1193
- asResponse: true;
1194
- }): Promise<Response>;
1195
- (context: InputContext<Path, Options> & {
1196
- returnHeaders: true;
1197
- returnStatus: true;
1198
- }): Promise<{
1199
- headers: Headers;
1200
- status: number;
1201
- response: Awaited<R>;
1202
- }>;
1203
- (context: InputContext<Path, Options> & {
1204
- returnHeaders: true;
1205
- returnStatus: false;
1206
- }): Promise<{
1207
- headers: Headers;
1208
- response: Awaited<R>;
1209
- }>;
1210
- (context: InputContext<Path, Options> & {
1211
- returnHeaders: false;
1212
- returnStatus: true;
1213
- }): Promise<{
1214
- status: number;
1215
- response: Awaited<R>;
1216
- }>;
1217
- (context: InputContext<Path, Options> & {
1218
- returnHeaders: false;
1219
- returnStatus: false;
1220
- }): Promise<R>;
1221
- (context: InputContext<Path, Options> & {
1222
- returnHeaders: true;
1223
- }): Promise<{
1224
- headers: Headers;
1225
- response: Awaited<R>;
1226
- }>;
1227
- (context: InputContext<Path, Options> & {
1228
- returnStatus: true;
1229
- }): Promise<{
1230
- status: number;
1231
- response: Awaited<R>;
1232
- }>;
1233
- (context?: InputContext<Path, Options>): Promise<R>;
1234
- options: Options;
1235
- path: Path;
1236
- };
1237
- type Endpoint<Path extends string = string, Options extends EndpointOptions = EndpointOptions, Handler extends (inputCtx: any) => Promise<any> = (inputCtx: any) => Promise<any>> = Handler & {
1238
- options: Options;
1239
- path: Path;
1240
- };
1241
- //#endregion
1
+ import { Middleware } from "./middleware.cjs";
2
+ import { Endpoint } from "./endpoint.cjs";
3
+
1242
4
  //#region src/router.d.ts
1243
5
  interface RouterConfig {
1244
6
  throwError?: boolean;
@@ -1331,5 +93,5 @@ declare const createRouter: <E extends Record<string, Endpoint>, Config extends
1331
93
  };
1332
94
  type Router = ReturnType<typeof createRouter>;
1333
95
  //#endregion
1334
- export { statusCodes as $, InferMiddlewareQuery as A, createInternalContext as B, InferBody as C, InferInputMethod as D, InferHeadersInput as E, InferRequest as F, serializeCookie as G, CookiePrefixOptions as H, InferRequestInput as I, BetterCallError as J, serializeSignedCookie as K, InferUse as L, InferParamInput as M, InferQuery as N, InferMethod as O, InferQueryInput as P, makeErrorForHideStackFrame as Q, InputContext as R, HTTPMethod as S, InferHeaders as T, getCookieKey as U, CookieOptions as V, parseCookies as W, ValidationError as X, Status as Y, hideInternalStackFrames as Z, MiddlewareContext as _, EndpointBaseOptions as a, MergeObject as at, MiddlewareResponse as b, EndpointOptions as c, UnionToIntersection as ct, OpenAPIParameter as d, StandardSchemaV1 as et, OpenAPISchemaType as f, Middleware as g, getHTML as h, Endpoint as i, IsEmptyObject as it, InferParam as j, InferMiddlewareBody as k, StrictEndpoint as l, generator as m, RouterConfig as n, InferParamPath as nt, EndpointBodyMethodOptions as o, Prettify as ot, Path$1 as p, APIError as q, createRouter as r, InferParamWildCard as rt, EndpointContext as s, RequiredKeysOf as st, Router as t, HasRequiredKeys as tt, createEndpoint as u, MiddlewareInputContext as v, InferBodyInput as w, createMiddleware as x, MiddlewareOptions as y, Method as z };
96
+ export { Router, RouterConfig, createRouter };
1335
97
  //# sourceMappingURL=router.d.cts.map