@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
241 lines (240 loc) • 7.61 kB
JavaScript
import { BadRequest as o, Unauthorized as i, PaymentRequired as u, Forbidden as a, NotFound as d, MethodNotAllowed as s, NotAcceptable as w, ProxyAuthenticationRequired as l, RequestTimeout as p, Conflict as c, Gone as R, LengthRequired as m, PreconditionFailed as q, PayloadTooLarge as g, URITooLong as f, UnsupportedMediaType as y, RangeNotSatisfiable as T, ExpectationFailed as b, ImATeapot as F, MisdirectedRequest as N, UnprocessableEntity as S, Locked as A, FailedDependency as L, TooEarly as h, UpgradeRequired as x, PreconditionRequired as E, TooManyRequests as v, RequestHeaderFieldsTooLarge as M, UnavailableForLegalReasons as U, InternalServerError as I, NotImplemented as P, BadGateway as k, ServiceUnavailable as D, GatewayTimeout as G, HTTPVersionNotSupported as H, VariantAlsoNegotiates as V, InsufficientStorage as z, LoopDetected as B, NotExtended as C, NetworkAuthenticationRequired as j } from "../../responses/exceptions/exceptions-basic.mjs";
import J from "../../responses/middleware-modification-request.mjs";
import K from "../../responses/file-response.mjs";
import O from "../../responses/raw-response.mjs";
import Q from "../../responses/redirect.mjs";
import W from "../../responses/sigil-response.mjs";
import X from "../../responses/exceptions/exception.mjs";
class Y {
/**
* Creates a standard JSON response with status code and headers.
*
* @param payload - The content payload to send.
* @param code - HTTP status code (default: 200).
* @param headers - Optional headers object.
* @returns A SigilResponse instance.
*/
response(e, r = 200, n) {
return new W(e, r, n);
}
/**
* If returned from middleware, will replace response status code and merge with
* existing headers, instead of returning actual response
*
* If returned outside of middleware, will act like
* default SigilResponse with null as body
*
* @param {MiddlewareModificationRequestOptions} options params that will be modified if request accepted
*/
middlewareModificationRequest(e) {
return new J(e);
}
/**
* Creates a raw response with custom headers or init options.
*
* @param payload - The raw content payload (string, buffer, etc.).
* @param headers - Optional headers object, Headers instance, or init.
* @param code - HTTP status code (default: 200).
* @returns A RawResponse instance.
*/
rawResponse(e, r, n = 200) {
return new O(e, r, n);
}
/**
* Creates a redirect response to the specified URL.
*
* @param to - Target URL for redirection.
* @param code - Optional HTTP redirect code (3xx).
* @returns A Redirect instance.
*/
redirect(e, r) {
return new Q(e, r);
}
/**
* Creates a file response serving a file from disk.
*
* @param path - Filesystem path to the file.
* @param contentType - Optional MIME type of the file.
* @param encoding - Optional file encoding (default: utf8).
* @returns A FileResponse instance.
*/
fileResponse(e, r, n) {
return new K(e, r, n);
}
}
class oe extends Y {
/**
* Creates a generic exception response.
*
* @param message - Error message.
* @param code - HTTP status code (default: 500).
* @param name - Optional exception name.
* @returns An Exception instance.
*/
exception(e, r = 500, n) {
return new X({ code: r, message: e, name: n });
}
/** @returns 400 Bad Request exception. */
badRequest(...e) {
return new o(...e);
}
/** @returns 401 Unauthorized exception. */
unauthorized(...e) {
return new i(...e);
}
/** @returns 402 Payment Required exception. */
paymentRequired(...e) {
return new u(...e);
}
/** @returns 403 Forbidden exception. */
forbidden(...e) {
return new a(...e);
}
/** @returns 404 Not Found exception. */
notFound(...e) {
return new d(...e);
}
/** @returns 405 Method Not Allowed exception. */
methodNotAllowed(...e) {
return new s(...e);
}
/** @returns 406 Not Acceptable exception. */
notAcceptable(...e) {
return new w(...e);
}
/** @returns 407 Proxy Authentication Required exception. */
proxyAuthenticationRequired(...e) {
return new l(...e);
}
/** @returns 408 Request Timeout exception. */
requestTimeout(...e) {
return new p(...e);
}
/** @returns 409 Conflict exception. */
conflict(...e) {
return new c(...e);
}
/** @returns 410 Gone exception. */
gone(...e) {
return new R(...e);
}
/** @returns 411 Length Required exception. */
lengthRequired(...e) {
return new m(...e);
}
/** @returns 412 Precondition Failed exception. */
preconditionFailed(...e) {
return new q(...e);
}
/** @returns 413 Payload Too Large exception. */
payloadTooLarge(...e) {
return new g(...e);
}
/** @returns 414 URI Too Long exception. */
uriTooLong(...e) {
return new f(...e);
}
/** @returns 415 Unsupported Media Type exception. */
unsupportedMediaType(...e) {
return new y(...e);
}
/** @returns 416 Range Not Satisfiable exception. */
rangeNotSatisfiable(...e) {
return new T(...e);
}
/** @returns 417 Expectation Failed exception. */
expectationFailed(...e) {
return new b(...e);
}
/** @returns 418 I'm a Teapot exception. */
imATeapot(...e) {
return new F(...e);
}
/** @returns 421 Misdirected Request exception. */
misdirectedRequest(...e) {
return new N(...e);
}
/** @returns 422 Unprocessable Entity exception. */
unprocessableEntity(...e) {
return new S(...e);
}
/** @returns 423 Locked exception. */
locked(...e) {
return new A(...e);
}
/** @returns 424 Failed Dependency exception. */
failedDependency(...e) {
return new L(...e);
}
/** @returns 425 Too Early exception. */
tooEarly(...e) {
return new h(...e);
}
/** @returns 426 Upgrade Required exception. */
upgradeRequired(...e) {
return new x(...e);
}
/** @returns 428 Precondition Required exception. */
preconditionRequired(...e) {
return new E(...e);
}
/** @returns 429 Too Many Requests exception. */
tooManyRequests(...e) {
return new v(...e);
}
/** @returns 431 Request Header Fields Too Large exception. */
requestHeaderFieldsTooLarge(...e) {
return new M(...e);
}
/** @returns 451 Unavailable For Legal Reasons exception. */
unavailableForLegalReasons(...e) {
return new U(...e);
}
/** @returns 500 Internal Server Error exception. */
internalServerError(...e) {
return new I(...e);
}
/** @returns 501 Not Implemented exception. */
notImplemented(...e) {
return new P(...e);
}
/** @returns 502 Bad Gateway exception. */
badGateway(...e) {
return new k(...e);
}
/** @returns 503 Service Unavailable exception. */
serviceUnavailable(...e) {
return new D(...e);
}
/** @returns 504 Gateway Timeout exception. */
gatewayTimeout(...e) {
return new G(...e);
}
/** @returns 505 HTTP Version Not Supported exception. */
httpVersionNotSupported(...e) {
return new H(...e);
}
/** @returns 506 Variant Also Negotiates exception. */
variantAlsoNegotiates(...e) {
return new V(...e);
}
/** @returns 507 Insufficient Storage exception. */
insufficientStorage(...e) {
return new z(...e);
}
/** @returns 508 Loop Detected exception. */
loopDetected(...e) {
return new B(...e);
}
/** @returns 510 Not Extended exception. */
notExtended(...e) {
return new C(...e);
}
/** @returns 511 Network Authentication Required exception. */
networkAuthenticationRequired(...e) {
return new j(...e);
}
}
export {
oe as default
};