gypsum
Version:
Simple and easy lightweight typescript server side framework on Node.js.
80 lines (79 loc) • 3.05 kB
TypeScript
import * as express from 'express';
import { Logger } from './misc/logger';
import { Model } from './models';
import { IService } from './decorators';
import { API_TYPES, RESPONSE_DOMAINS, Response, IResponseError, IResponse } from './types';
export interface IContext {
rid: string;
headers: any;
query: any;
body: any;
params: any[];
model: Model;
service: IService;
cookies?: any;
req?: express.Request;
res?: express.Response;
socket?: any;
appName?: string;
namespace?: string;
domain?: RESPONSE_DOMAINS;
room?: string;
}
export declare type IContextOptions = {
[key in keyof IContext]?: IContext[key];
};
export declare class Context {
private _rid;
private _locals;
private _cookies;
private _domain;
private _mainHandler;
private _resolve;
private _reject;
private _stack;
readonly _socket: any | undefined;
readonly _appName: string;
readonly _namespace: string;
readonly _req: express.Request | undefined;
readonly _res: express.Response | undefined;
response: Response;
room: string;
model: Model;
service: IService;
apiType: API_TYPES.REST | API_TYPES.SOCKET;
headers: any;
query: any;
body: any;
params: any;
user: any;
logger: Logger;
constructor(type: API_TYPES.REST | API_TYPES.SOCKET, data: IContext, init?: boolean);
static Publish(model: Model, serviceName: string, data: IResponse): Promise<{}>;
static Rest(appName: string, model: Model, service: IService): (req: express.Request, res: express.Response, next: express.NextFunction) => void;
static Socket(appName: string, namespace: string, socket: any, model: Model, service: IService): (data: any) => void;
private _mInit(hooks?, extraHooks?, extraHooksPos?);
private _mRespond();
private _mPushStack(hooksList);
switchService(model: Model, serviceName: string, hooks?: 'before' | 'after' | 'both' | 'none', useOwnHooks?: 0 | 1 | -1): void;
runService(model: Model, serviceName: string, data: IContextOptions, user: any): Promise<{}>;
useServiceHooks(service: IService, clearOwnHooks?: boolean): void;
domain: RESPONSE_DOMAINS;
readonly isMainHandler: boolean;
getHeader(name: string): string;
get(name: string): any;
set(name: string, value: any): Context;
remove(name: string): Context;
cookie(name: string, value: string, options?: any): Context;
cookies(name: string): string;
clearCookie(name: string): Context;
private toggleRoom(action, rooms, users?);
joinRoom(rooms: string | string[], users?: string | string[]): Promise<{}>;
leaveRoom(rooms: string | string[], users?: string | string[]): Promise<{}>;
private getRealArgsValues(args, hookName);
next(err?: IResponseError): void;
nextHook(hook: any, args?: any[]): this;
ok(res: Response): void;
private _mSendHtml(html, code?);
private _mSendFile(filePath, code?);
}