import { IMiddleWare, MiddleWare, ISenerContext, IOnError, IServerOptions, ISenerOptions, IResponse, ICookieOptions, countExpire, IPromiseMayBe, IHookReturn, IServeMethod, IJson } from 'sener-types'; export * from 'sener-types'; import http, { IncomingMessage } from 'http'; import { ISenerHelper } from 'sener-extend'; declare class MiddleWareManager { middlewares: (IMiddleWare | MiddleWare)[]; use(middleware: IMiddleWare | MiddleWare): void; remove(middleware: IMiddleWare): void; init(ctx: ISenerContext): Promise; enter(ctx: ISenerContext): Promise; leave(ctx: ISenerContext): Promise; private onSingeHook; } declare class Server { server: http.Server; middleware: MiddleWareManager; helper: ISenerHelper; port: number; onerror?: IOnError; constructor({ port, onerror, }: IServerOptions); injectMiddleWare(middleware: IMiddleWare | MiddleWare): void; private onError; private initServer; private sendData; } declare class Sener { static Version: string | undefined; server: Server; static get Dir(): string; static set Dir(v: string); constructor({ port, middlewares, onerror, }?: ISenerOptions); use(...middlewares: (MiddleWare | IMiddleWare | null | undefined)[]): void; remove(middleware: IMiddleWare): void; } declare module 'sener-extend' { interface ISenerHelper { cookie: CookieClient; } } type ICookieValue = string | number | boolean | null | ICookieOptions; declare class CookieClient { private _cookie; request: IncomingMessage; response: IResponse; clientDomain: string; private _options; constructor(request: IncomingMessage, response: IResponse, options?: ICookieOptions); get(key: string): string; get(key: T): { [prop in keyof T]: string; }; getResponseCookie(key: string): string; getResponseCookie(key: T): { [prop in keyof T]: string; }; set(key: string, value?: ICookieValue, options?: ICookieOptions): void; set(json: Record, options?: ICookieOptions): void; remove(key: string | string[], opt?: ICookieOptions): void; expire: typeof countExpire; } declare class Cookie extends MiddleWare { private _options; constructor(options?: ICookieOptions); init(ctx: ISenerContext): void; } interface ICorsOptions { origin?: string; methods?: IServeMethod[] | string; headers?: string[] | string; credentials?: boolean; exposeHeaders?: string[] | string; maxAge?: number; } declare const DefaultHeaders: { [x: string]: string; }; type IHeaderKey = { [prop in keyof typeof DefaultHeaders]?: string; }; declare class Cors extends MiddleWare { name: string; headers: IHeaderKey; acceptOptions: boolean; acceptResponded: boolean; acceptSended: boolean; constructor(options?: ICorsOptions); init({ headers }: ISenerContext): IPromiseMayBe; } type IEnvOptions = IJson<((ctx: ISenerContext) => any)>; type IEnvMap any)>> = { [prop in keyof T]: ReturnType; }; declare class Env extends MiddleWare { map: IEnvOptions; constructor(map: IEnvOptions); init(ctx: ISenerContext): void; } interface IIpMonitorOptions { range?: number; times?: number; oncheck?: (ctx: ISenerContext) => boolean; handler?: (ctx: ISenerContext) => IHookReturn; } declare class IpMonitorClient { private _store; check: (ctx: ISenerContext) => boolean; handler?: (ctx: ISenerContext) => any; constructor({ times, range, oncheck, handler }?: IIpMonitorOptions); } declare class IpMonitor extends MiddleWare { client: IpMonitorClient; constructor(options?: IIpMonitorOptions); enter(ctx: ISenerContext): IHookReturn; } type IRouter = IJson; type IRouterHandler = (data: ISenerContext) => IPromiseMayBe; interface IRouterHandlerData { handler: IRouterHandler; meta?: IJson; alias?: string[]; reg?: RegExp; paramMap?: IJson; } interface IRouterHelper { meta: IJson; index: () => number; route(url: string, data?: Partial): IPromiseMayBe; params: IJson; redirect: (url: string, query?: IJson, header?: IJson) => void; } declare module 'sener-extend' { interface ISenerHelper extends IRouterHelper { } } declare function createRoute(base: string, route: IRouter): IRouter; declare function createRoute(route: IRouter): IRouter; declare class Router extends MiddleWare { routers: IJson; fuzzyRouters: IJson; private _privateRouters; constructor(...routers: IRouter[]); private addToRouter; private _getMap; private extractMeta; private fillUrl; init(ctx: ISenerContext): void; private _extractFuzzyParam; enter(ctx: ISenerContext): IHookReturn; private routeTo404; private getRoute; private getRouteByUrl; private findRouteByKey; private buildRouteKey; private _route; private _createRoute; } declare module 'sener-extend' { interface ISenerHelper { session: SessionClient; } } interface ISessionClientOptions { idGenerator?: () => string; storeDays?: number; } declare class SessionClient { static baseDir: string; static idGenerator: typeof generateSessionId; static _timer: any; static init({ idGenerator, storeDays }: ISessionClientOptions): void; sessionId: string; Expired: symbol; constructor(cookie: CookieClient, storeDays?: number); private _filePath; get filePath(): string; get(key: string): any; get(key: T): { [prop in keyof T]: any; }; set(key: string | Record, value?: null | any | number, expire?: number): void; remove(key: string | string[]): void; isExpired(value: any): boolean; expire: typeof countExpire; } declare function generateSessionId(): string; declare class Session extends MiddleWare { session: SessionClient; options: ISessionClientOptions; constructor(options?: ISessionClientOptions); init(ctx: ISenerContext): void; } interface IFormatMap { 'number': number; 'string': string; 'boolean': boolean; 'any': any; } type IValidFormat = keyof IFormatMap; type IValidRule = 'required' | 'optional' | RegExp | ((v: any, formatValue: any) => boolean); type IValidTemplate = { [prop in string]: IValidFormat | [IValidFormat, IValidRule]; }; type IValidFunc = (template: D) => ({ [prop in keyof D]: IFormatMap[(D[prop] extends string ? D[prop] : D[prop][0])]; } & { [prop in string]: any; }); interface IValidatorHelper { vquery: IValidFunc; vbody: IValidFunc; validate: (data: IJson, template: D) => ({ [prop in keyof D]: IFormatMap[(D[prop] extends string ? D[prop] : D[prop][0])]; }); } declare module 'sener-extend' { interface ISenerHelper extends IValidatorHelper { } } declare class Validator extends MiddleWare { private _validate; init(res: ISenerContext): void; } export { Cookie, CookieClient, Cors, Env, ICookieValue, IEnvMap, IEnvOptions, IIpMonitorOptions, IRouter, IRouterHandler, IRouterHandlerData, IValidFormat, IValidRule, IValidTemplate, IpMonitor, IpMonitorClient, Router, Sener, Session, SessionClient, Validator, createRoute };