elysia
Version:
Ergonomic Framework for Human
265 lines (264 loc) • 12.9 kB
TypeScript
import type { TSchema } from '@sinclair/typebox';
import type { TypeCheck, ValueError, ValueErrorIterator } from '@sinclair/typebox/compiler';
import { StatusMap, InvertedStatusMap } from './utils';
import type { ElysiaTypeCheck } from './schema';
export declare const ERROR_CODE: unique symbol;
export type ERROR_CODE = typeof ERROR_CODE;
export declare const isProduction: boolean;
export type ElysiaErrors = InternalServerError | NotFoundError | ParseError | ValidationError | InvalidCookieSignature;
export declare class ElysiaCustomStatusResponse<const in out Code extends number | keyof StatusMap, const in out T = Code extends keyof InvertedStatusMap ? InvertedStatusMap[Code] : Code, const in out Status extends Code extends keyof StatusMap ? StatusMap[Code] : Code = Code extends keyof StatusMap ? StatusMap[Code] : Code> {
code: Status;
response: T;
constructor(code: Code, response: T);
}
export declare const status: <const Code extends number | keyof StatusMap, const T = Code extends keyof InvertedStatusMap ? InvertedStatusMap[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent 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 Content" | "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" ? {
readonly Continue: 100;
readonly 'Switching Protocols': 101;
readonly Processing: 102;
readonly 'Early Hints': 103;
readonly OK: 200;
readonly Created: 201;
readonly Accepted: 202;
readonly 'Non-Authoritative Information': 203;
readonly 'No Content': 204;
readonly 'Reset Content': 205;
readonly 'Partial Content': 206;
readonly 'Multi-Status': 207;
readonly 'Already Reported': 208;
readonly 'Multiple Choices': 300;
readonly 'Moved Permanently': 301;
readonly Found: 302;
readonly 'See Other': 303;
readonly 'Not Modified': 304;
readonly 'Temporary Redirect': 307;
readonly 'Permanent Redirect': 308;
readonly 'Bad Request': 400;
readonly Unauthorized: 401;
readonly 'Payment Required': 402;
readonly Forbidden: 403;
readonly 'Not Found': 404;
readonly 'Method Not Allowed': 405;
readonly 'Not Acceptable': 406;
readonly 'Proxy Authentication Required': 407;
readonly 'Request Timeout': 408;
readonly Conflict: 409;
readonly Gone: 410;
readonly 'Length Required': 411;
readonly 'Precondition Failed': 412;
readonly 'Payload Too Large': 413;
readonly 'URI Too Long': 414;
readonly 'Unsupported Media Type': 415;
readonly 'Range Not Satisfiable': 416;
readonly 'Expectation Failed': 417;
readonly "I'm a teapot": 418;
readonly 'Misdirected Request': 421;
readonly 'Unprocessable Content': 422;
readonly Locked: 423;
readonly 'Failed Dependency': 424;
readonly 'Too Early': 425;
readonly 'Upgrade Required': 426;
readonly 'Precondition Required': 428;
readonly 'Too Many Requests': 429;
readonly 'Request Header Fields Too Large': 431;
readonly 'Unavailable For Legal Reasons': 451;
readonly 'Internal Server Error': 500;
readonly 'Not Implemented': 501;
readonly 'Bad Gateway': 502;
readonly 'Service Unavailable': 503;
readonly 'Gateway Timeout': 504;
readonly 'HTTP Version Not Supported': 505;
readonly 'Variant Also Negotiates': 506;
readonly 'Insufficient Storage': 507;
readonly 'Loop Detected': 508;
readonly 'Not Extended': 510;
readonly 'Network Authentication Required': 511;
}[Code] : Code>;
/**
* @deprecated use `Elysia.status` instead
*/
export declare const error: <const Code extends number | keyof StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 300 | 304 | 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 ? {
readonly 100: "Continue";
readonly 101: "Switching Protocols";
readonly 102: "Processing";
readonly 103: "Early Hints";
readonly 200: "OK";
readonly 201: "Created";
readonly 202: "Accepted";
readonly 203: "Non-Authoritative Information";
readonly 204: "No Content";
readonly 205: "Reset Content";
readonly 206: "Partial Content";
readonly 207: "Multi-Status";
readonly 208: "Already Reported";
readonly 300: "Multiple Choices";
readonly 301: "Moved Permanently";
readonly 302: "Found";
readonly 303: "See Other";
readonly 304: "Not Modified";
readonly 307: "Temporary Redirect";
readonly 308: "Permanent Redirect";
readonly 400: "Bad Request";
readonly 401: "Unauthorized";
readonly 402: "Payment Required";
readonly 403: "Forbidden";
readonly 404: "Not Found";
readonly 405: "Method Not Allowed";
readonly 406: "Not Acceptable";
readonly 407: "Proxy Authentication Required";
readonly 408: "Request Timeout";
readonly 409: "Conflict";
readonly 410: "Gone";
readonly 411: "Length Required";
readonly 412: "Precondition Failed";
readonly 413: "Payload Too Large";
readonly 414: "URI Too Long";
readonly 415: "Unsupported Media Type";
readonly 416: "Range Not Satisfiable";
readonly 417: "Expectation Failed";
readonly 418: "I'm a teapot";
readonly 421: "Misdirected Request";
readonly 422: "Unprocessable Content";
readonly 423: "Locked";
readonly 424: "Failed Dependency";
readonly 425: "Too Early";
readonly 426: "Upgrade Required";
readonly 428: "Precondition Required";
readonly 429: "Too Many Requests";
readonly 431: "Request Header Fields Too Large";
readonly 451: "Unavailable For Legal Reasons";
readonly 500: "Internal Server Error";
readonly 501: "Not Implemented";
readonly 502: "Bad Gateway";
readonly 503: "Service Unavailable";
readonly 504: "Gateway Timeout";
readonly 505: "HTTP Version Not Supported";
readonly 506: "Variant Also Negotiates";
readonly 507: "Insufficient Storage";
readonly 508: "Loop Detected";
readonly 510: "Not Extended";
readonly 511: "Network Authentication Required";
}[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent 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 Content" | "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" ? {
readonly Continue: 100;
readonly 'Switching Protocols': 101;
readonly Processing: 102;
readonly 'Early Hints': 103;
readonly OK: 200;
readonly Created: 201;
readonly Accepted: 202;
readonly 'Non-Authoritative Information': 203;
readonly 'No Content': 204;
readonly 'Reset Content': 205;
readonly 'Partial Content': 206;
readonly 'Multi-Status': 207;
readonly 'Already Reported': 208;
readonly 'Multiple Choices': 300;
readonly 'Moved Permanently': 301;
readonly Found: 302;
readonly 'See Other': 303;
readonly 'Not Modified': 304;
readonly 'Temporary Redirect': 307;
readonly 'Permanent Redirect': 308;
readonly 'Bad Request': 400;
readonly Unauthorized: 401;
readonly 'Payment Required': 402;
readonly Forbidden: 403;
readonly 'Not Found': 404;
readonly 'Method Not Allowed': 405;
readonly 'Not Acceptable': 406;
readonly 'Proxy Authentication Required': 407;
readonly 'Request Timeout': 408;
readonly Conflict: 409;
readonly Gone: 410;
readonly 'Length Required': 411;
readonly 'Precondition Failed': 412;
readonly 'Payload Too Large': 413;
readonly 'URI Too Long': 414;
readonly 'Unsupported Media Type': 415;
readonly 'Range Not Satisfiable': 416;
readonly 'Expectation Failed': 417;
readonly "I'm a teapot": 418;
readonly 'Misdirected Request': 421;
readonly 'Unprocessable Content': 422;
readonly Locked: 423;
readonly 'Failed Dependency': 424;
readonly 'Too Early': 425;
readonly 'Upgrade Required': 426;
readonly 'Precondition Required': 428;
readonly 'Too Many Requests': 429;
readonly 'Request Header Fields Too Large': 431;
readonly 'Unavailable For Legal Reasons': 451;
readonly 'Internal Server Error': 500;
readonly 'Not Implemented': 501;
readonly 'Bad Gateway': 502;
readonly 'Service Unavailable': 503;
readonly 'Gateway Timeout': 504;
readonly 'HTTP Version Not Supported': 505;
readonly 'Variant Also Negotiates': 506;
readonly 'Insufficient Storage': 507;
readonly 'Loop Detected': 508;
readonly 'Not Extended': 510;
readonly 'Network Authentication Required': 511;
}[Code] : Code>;
export declare class InternalServerError extends Error {
code: string;
status: number;
constructor(message?: string);
}
export declare class NotFoundError extends Error {
code: string;
status: number;
constructor(message?: string);
}
export declare class ParseError extends Error {
code: string;
status: number;
constructor(cause?: Error);
}
export declare class InvalidCookieSignature extends Error {
key: string;
code: string;
status: number;
constructor(key: string, message?: string);
}
export declare const mapValueError: (error: ValueError | undefined) => {
summary: undefined;
} | {
summary: string;
type: import("@sinclair/typebox/value").ValueErrorType;
schema: TSchema;
path: string;
value: unknown;
message: string;
errors: ValueErrorIterator[];
};
export declare class InvalidFileType extends Error {
property: string;
expected: string | string[];
message: string;
code: string;
status: number;
constructor(property: string, expected: string | string[], message?: string);
toResponse(headers?: Record<string, any>): Response;
}
export declare class ValidationError extends Error {
type: string;
validator: TSchema | TypeCheck<any> | ElysiaTypeCheck<any>;
value: unknown;
code: string;
status: number;
constructor(type: string, validator: TSchema | TypeCheck<any> | ElysiaTypeCheck<any>, value: unknown, errors?: ValueErrorIterator);
get all(): ({
summary: undefined;
} | {
summary: string;
type: import("@sinclair/typebox/value").ValueErrorType;
schema: TSchema;
path: string;
value: unknown;
message: string;
errors: ValueErrorIterator[];
})[];
static simplifyModel(validator: TSchema | TypeCheck<any> | ElysiaTypeCheck<any>): any;
get model(): any;
toResponse(headers?: Record<string, any>): Response;
}