@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
84 lines (83 loc) • 2.52 kB
JavaScript
import r from "../requests/containers/incoming-headers.mjs";
class i {
/**
* Creates a new BasicResponse.
*
* @param content - The response payload (body).
* @param code - HTTP status code (100-599). Defaults to 200.
* @param headers - Optional raw headers object or IncomingHeaders instance.
* @throws Error if `code` is outside the valid HTTP range.
*/
constructor(n, s = 200, t) {
if (this.content = n, this.code = s, s < 100 || s > 599)
throw new Error("Invalid response code: " + s);
this.headers = t instanceof r ? t : new r(t);
}
/**
* HTTP headers for the response.
*/
headers;
}
class a extends i {
/**
* Name of the schema to apply for this response in OpenAPI docs.
* @internal
*/
__$schemaName;
/**
* Raw flag
* @internal
*/
__$raw;
/**
* Constructs an internal named response with default values.
*/
constructor() {
super(null, 200, {});
}
}
class h extends i {
/**
* Creates a new SigilResponse.
*
* @param content - The response payload.
* @param code - HTTP status code. Defaults to 200.
* @param headers - Optional raw headers or IncomingHeaders instance.
*/
constructor(n, s = 200, t) {
super(n, s, t), this.content = n, this.code = s;
}
/**
* Creates a named response for OpenAPI schema generation.
* The returned instance carries a `__$schemaName` property.
*
* @param name - Schema name reference for documentation.
* @param content - The response payload.
* @param code - Optional HTTP status code. Defaults to 200.
* @param headers - Optional raw headers object.
* @returns An internal named response instance.
*/
static describe(n, s, t, c) {
const e = new a();
return n && (e.__$schemaName = n), e.content = s, e.code = t || 200, e.headers = new r(c), e;
}
/**
* Creates a raw named response for OpenAPI schema generation.
* The returned instance carries a `__$schemaName` property.
*
* @param name - Schema name reference for documentation.
* @param content - The response payload.
* @param code - Optional HTTP status code. Defaults to 200.
* @param headers - Optional raw headers object.
* @returns An internal named response instance.
*/
static describeRaw(n, s, t, c) {
const e = new a();
return n && (e.__$schemaName = n), e.__$raw = !0, e.content = s, e.code = t || 200, e.headers = new r(c), e;
}
}
export {
a as $InternalNamedSigilResponse,
i as BasicResponse,
h as default
};