declare const _statusCode: { OK: number; CREATED: number; ACCEPTED: number; NO_CONTENT: number; MULTIPLE_CHOICES: number; MOVED_PERMANENTLY: number; FOUND: number; SEE_OTHER: number; NOT_MODIFIED: number; TEMPORARY_REDIRECT: number; BAD_REQUEST: number; UNAUTHORIZED: number; PAYMENT_REQUIRED: number; FORBIDDEN: number; NOT_FOUND: number; METHOD_NOT_ALLOWED: number; NOT_ACCEPTABLE: number; PROXY_AUTHENTICATION_REQUIRED: number; REQUEST_TIMEOUT: number; CONFLICT: number; GONE: number; LENGTH_REQUIRED: number; PRECONDITION_FAILED: number; PAYLOAD_TOO_LARGE: number; URI_TOO_LONG: number; UNSUPPORTED_MEDIA_TYPE: number; RANGE_NOT_SATISFIABLE: number; EXPECTATION_FAILED: number; "I'M_A_TEAPOT": number; MISDIRECTED_REQUEST: number; UNPROCESSABLE_ENTITY: number; LOCKED: number; FAILED_DEPENDENCY: number; TOO_EARLY: number; UPGRADE_REQUIRED: number; PRECONDITION_REQUIRED: number; TOO_MANY_REQUESTS: number; REQUEST_HEADER_FIELDS_TOO_LARGE: number; UNAVAILABLE_FOR_LEGAL_REASONS: number; INTERNAL_SERVER_ERROR: number; NOT_IMPLEMENTED: number; BAD_GATEWAY: number; SERVICE_UNAVAILABLE: number; GATEWAY_TIMEOUT: number; HTTP_VERSION_NOT_SUPPORTED: number; VARIANT_ALSO_NEGOTIATES: number; INSUFFICIENT_STORAGE: number; LOOP_DETECTED: number; NOT_EXTENDED: number; NETWORK_AUTHENTICATION_REQUIRED: number; }; 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; declare class APIError extends Error { status: keyof typeof _statusCode | Status; body: ({ message?: string; code?: string; } & Record) | undefined; headers: HeadersInit; statusCode: number; constructor(status?: keyof typeof _statusCode | Status, body?: ({ message?: string; code?: string; } & Record) | undefined, headers?: HeadersInit, statusCode?: number); } type RequiredKeysOf = Exclude<{ [Key in keyof BaseType]: BaseType extends Record ? Key : never; }[keyof BaseType], undefined>; type HasRequiredKeys = RequiredKeysOf extends never ? false : true; type Prettify = { [K in keyof T]: T[K]; } & {}; type IsEmptyObject = keyof T extends never ? true : false; type UnionToIntersection = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection & Union : never; type MergeObject | never, S extends Record | never> = T extends never ? S : S extends never ? T : T & S; type InferParamPath = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath]: string; } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string; } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath : {}; type InferParamWildCard = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath]: string; } : Path extends `${infer _Start}/*` ? { [K in "_"]: string; } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath : {}; interface MiddlewareOptions extends Omit { } type MiddlewareResponse = null | void | undefined | Record; type MiddlewareContext = EndpointContext & { /** * Method * * The request method */ method: string; /** * Path * * The path of the endpoint */ path: string; /** * Body * * The body object will be the parsed JSON from the request and validated * against the body schema if it exists */ body: InferMiddlewareBody; /** * Query * * The query object will be the parsed query string from the request * and validated against the query schema if it exists */ query: InferMiddlewareQuery; /** * Params * * If the path is `/user/:id` and the request is `/user/1` then the * params will * be `{ id: "1" }` and if the path includes a wildcard like `/user/*` * then the * params will be `{ _: "1" }` where `_` is the wildcard key. If the * wildcard * is named like `/user/**:name` then the params will be `{ name: string }` */ params: string; /** * Request object * * If `requireRequest` is set to true in the endpoint options this will be * required */ request: InferRequest; /** * Headers * * If `requireHeaders` is set to true in the endpoint options this will be * required */ headers: InferHeaders; /** * Set header * * If it's called outside of a request it will just be ignored. */ setHeader: (key: string, value: string) => void; /** * Get header * * If it's called outside of a request it will just return null * * @param key - The key of the header * @returns */ getHeader: (key: string) => string | null; /** * JSON * * a helper function to create a JSON response with * the correct headers * and status code. If `asResponse` is set to true in * the context then * it will return a Response object instead of the * JSON object. * * @param json - The JSON object to return * @param routerResponse - The response object to * return if `asResponse` is * true in the context this will take precedence */ json: | null>(json: R, routerResponse?: { status?: number; headers?: Record; response?: Response; } | Response) => Promise; /** * Middleware context */ context: Prettify; }; declare function createMiddleware(options: Options, handler: (context: MiddlewareContext) => Promise): >(inputContext: InputCtx) => Promise; declare function createMiddleware(handler: (context: MiddlewareContext) => Promise): >(inputContext: InputCtx) => Promise; declare namespace createMiddleware { var create: (opts?: E) => { (options: Options, handler: (ctx: MiddlewareContext>) => Promise): (inputContext: MiddlewareInputContext) => Promise; (handler: (ctx: MiddlewareContext>) => Promise): (inputContext: MiddlewareInputContext) => Promise; }; } type MiddlewareInputContext = InferBodyInput & InferQueryInput & InferRequestInput & InferHeadersInput & { asResponse?: boolean; returnHeaders?: boolean; use?: Middleware[]; }; type Middleware Promise = any> = Handler & { options: Options; }; type CookiePrefixOptions = "host" | "secure"; type CookieOptions = { /** * Domain of the cookie * * The Domain attribute specifies which server can receive a cookie. If specified, cookies are * available on the specified server and its subdomains. If the it is not * specified, the cookies are available on the server that sets it but not on * its subdomains. * * @example * `domain: "example.com"` */ domain?: string; /** * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the * Expires attribute: * * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and * takes precedence when both are set. The rationale behind this is that when you set an * Expires date and time, they're relative to the client the cookie is being set on. If the * server is set to a different time, this could cause errors */ expires?: Date; /** * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie * property. Note that a cookie that has been created with HttpOnly will still be sent with * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch(). * This mitigates attacks against cross-site scripting */ httpOnly?: boolean; /** * Indicates the number of seconds until the cookie expires. A zero or negative number will * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence. * * @example 604800 - 7 days */ maxAge?: number; /** * Indicates the path that must exist in the requested URL for the browser to send the Cookie * header. * * @example * "/docs" * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match. */ path?: string; /** * Indicates that the cookie is sent to the server only when a request is made with the https: * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks. */ secure?: boolean; /** * Controls whether or not a cookie is sent with cross-site requests, providing some protection * against cross-site request forgery attacks (CSRF). * * Strict - Means that the browser sends the cookie only for same-site requests, that is, * requests originating from the same site that set the cookie. If a request originates from a * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict * attribute are sent. * * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load * images or frames, but is sent when a user is navigating to the origin site from an external * site (for example, when following a link). This is the default behavior if the SameSite * attribute is not specified. * * None - Means that the browser sends the cookie with both cross-site and same-site requests. * The Secure attribute must also be set when setting this value. */ sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none"; /** * Indicates that the cookie should be stored using partitioned storage. Note that if this is * set, the Secure directive must also be set. * * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies */ partitioned?: boolean; /** * Cooke Prefix * * - secure: `__Secure-` -> `__Secure-cookie-name` * - host: `__Host-` -> `__Host-cookie-name` * * `secure` must be set to true to use prefixes */ prefix?: CookiePrefixOptions; }; declare const getCookieKey: (key: string, prefix?: CookiePrefixOptions) => string | undefined; /** * Parse an HTTP Cookie header string and returning an object of all cookie * name-value pairs. * * Inspired by https://github.com/unjs/cookie-es/blob/main/src/cookie/parse.ts * * @param str the string representing a `Cookie` header value */ declare function parseCookies(str: string): Map; declare const serializeCookie: (key: string, value: string, opt?: CookieOptions) => string; declare const serializeSignedCookie: (key: string, value: string, secret: string, opt?: CookieOptions) => Promise; /** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result | Promise>; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ type Result = SuccessResult | FailureResult; /** The result interface if validation succeeds. */ interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ type InferOutput = NonNullable["output"]; } type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; type Method = HTTPMethod | "*"; type InferBodyInput : undefined> = undefined extends Body ? { body?: Body; } : { body: Body; }; type InferBody = Options["metadata"] extends { $Infer: { body: infer Body; }; } ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : any; type InferQueryInput : Record | undefined> = undefined extends Query ? { query?: Query; } : { query: Query; }; type InferQuery = Options["metadata"] extends { $Infer: { query: infer Query; }; } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : Record | undefined; type InferMethod = Options["method"] extends Array ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"]; type InferInputMethod ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined> = undefined extends Method ? { method?: Method; } : { method: Method; }; type InferParam = IsEmptyObject & InferParamWildCard> extends true ? Record | undefined : Prettify & InferParamWildCard>; type InferParamInput = IsEmptyObject & InferParamWildCard> extends true ? { params?: Record; } : { params: Prettify & InferParamWildCard>; }; type InferRequest