lakutata
Version:
An IoC-based universal application framework.
73 lines (66 loc) • 2.17 kB
TypeScript
import { P as Provider } from './TypeDef.3.js';
import { D as DTO } from './TypeDef.5.js';
import { A as ActionPattern } from './TypeDef.9.js';
import { IncomingMessage, ServerResponse } from 'node:http';
/**
* Context types
*/
declare enum ContextType {
CLI = "CLI",
HTTP = "HTTP",
SERVICE = "SERVICE"
}
type ContextParams<T extends {} = {}> = T & Record<string, any>;
/**
* Base context class
*/
declare class BaseContext<T extends Record<string, any> = {}> extends DTO {
readonly type: ContextType;
data: ActionPattern<T>;
constructor(params: ContextParams);
}
declare class CLIContext<T extends Record<string, any> = {}> extends BaseContext<T> {
readonly type: ContextType;
command: string;
constructor(params: ContextParams<{
readonly command: string;
readonly data: Record<string, any>;
}>);
}
declare class HTTPContext<T extends Record<string, any> = {}> extends BaseContext<T> {
readonly type: ContextType;
readonly route: string;
readonly method: string;
readonly request: IncomingMessage;
readonly response: ServerResponse;
constructor(params: ContextParams<{
readonly route: string;
readonly method: string;
readonly request: IncomingMessage;
readonly response: ServerResponse;
readonly data: Record<string, any>;
}>);
}
declare class ServiceContext<T extends Record<string, any> = {}> extends BaseContext<T> {
readonly type: ContextType;
input: ActionPattern<T>;
constructor(params: ContextParams<{
readonly data: ActionPattern;
}>);
}
/**
* For action decorator
*/
type ControllerProperty<ClassPrototype extends Controller> = Exclude<keyof ClassPrototype, keyof Controller>;
/**
* Controller base class
*/
declare class Controller extends Provider {
/**
* Context, possible be cli context, http context or service context
* @protected
*/
protected readonly context: CLIContext | HTTPContext | ServiceContext;
}
export { BaseContext as B, Controller as C, HTTPContext as H, ServiceContext as S, CLIContext as a, ContextType as b };
export type { ControllerProperty as c };