@busy-hour/blaze
Version:
<h1 align='center'>🔥 Blaze</h1> <div align='center'> An event driven framework for 🔥 Hono.js </div>
72 lines (71 loc) • 3.37 kB
TypeScript
import type { ZodSchema } from 'zod';
import type { RecordString, RecordUnknown } from '../../types/common';
import type { GenericStatusCode, ResponseType } from '../../types/rest';
import { BlazeBroker as Broker } from '../broker/index';
import type { ContextConstructorOption, ContextRequest, ContextSetter, CreateContextOption } from './types';
export declare class BlazeContext<M extends RecordUnknown = RecordUnknown, H extends RecordString = RecordString, P extends RecordUnknown = RecordUnknown, Q extends RecordUnknown = RecordUnknown, B extends RecordUnknown = RecordUnknown> {
private $honoCtx;
private $meta;
private $query;
private $body;
private $params;
private $reqHeaders;
/**
* Set the typeof of the REST response such as `json`, `body`, `text`, or `html`.
*/
response: ResponseType | null;
/**
* Set the status code of the REST response, such as `200`, `404`, `500`, etc.
*/
status: GenericStatusCode | null;
private $resHeaders;
/**
* Flag that indicates whether the context is from a REST request or not.
*/
readonly isRest: boolean;
readonly broker: Broker;
readonly call: Broker['call'];
readonly emit: Broker['emit'];
readonly event: Broker['event'];
constructor(options: ContextConstructorOption<M, H, P, Q, B>);
get meta(): {
set<K extends keyof M, V extends M[K]>(key: K, value: V): any;
get<K_1 extends keyof M, V_1 extends M[K_1]>(key: K_1): V_1;
entries(): [string, unknown][];
};
get headers(): {
append(key: string, value: string): void;
set(key: string, value: string): any;
get(key: string): string | string[];
entries(): [string, string | string[]][];
};
get query(): Q;
private get params();
private get reqHeaders();
private getBody;
/**
* @description Access the request information from the context such as `headers`, `query`, `params`, and `body`.
*/
get request(): ContextRequest<H, P, Q, B>;
/**
* @description Shorthand for `this.request`
* @description Access the request information from the context such as `headers`, `query`, `params`, and `body`.
*/
get req(): ContextRequest<H, P, Q, B>;
/**
* @description Access the response information from the context such as `headers`, `status`, and `response`.
* @description It exists for the developer's convenience on handling the response.
*/
get res(): {
headers: {
append(key: string, value: string): void;
set(key: string, value: string): any;
get(key: string): string | string[];
entries(): [string, string | string[]][];
};
status: GenericStatusCode | null;
response: ResponseType | null;
};
static setter<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown>(ctx: BlazeContext<M, H, P, Q, B>): ContextSetter<M, H, P, Q, B>;
static create<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown, HV extends ZodSchema, PV extends ZodSchema, QV extends ZodSchema, BV extends ZodSchema>(options: CreateContextOption<M, H, P, Q, B, HV, PV, QV, BV>): Promise<BlazeContext<M, H, P, Q, B>>;
}