/**
* 核心Http
* TKServer
* @author ranyunlong<549510622@qq.com>
* license MIT
*/
///
///
import { ServerOptions } from 'https';
import * as Koa from 'koa';
import { Middleware } from 'koa';
import * as Knex from 'knex';
import * as KoaBody from 'koa-body';
import * as KoaStatic from 'koa-static';
import * as KoaRouter from 'koa-router';
import { I18n } from './i18n';
import { Config } from 'http-proxy-middleware';
export declare class TKServer {
readonly app: Koa;
readonly port: number;
constructor(options: TKServer.Options);
}
export declare namespace TKServer {
interface Context extends Koa.Context {
}
interface Response extends Koa.Response {
}
interface Request extends Koa.Request {
}
interface Router extends KoaRouter {
[index: string]: any;
}
type ClassDecorator = (target: C) => C | void;
type Decorator = ClassDecorator | ParameterDecorator | MethodDecorator | PropertyDecorator;
type RequestMethodTypes = 'all' | 'delete' | 'get' | 'post' | 'head' | 'options' | 'patch' | 'put';
type PropertyDecoratorTypes = 'query' | 'body' | 'session' | 'files' | 'params' | 'header' | 'headers' | 'request' | 'response';
type Database = Knex;
interface ServerStaticOptions {
root: string;
options: KoaStatic.Options;
}
interface ServerSessionOptions {
key?: string;
maxAge?: number;
overwrite: boolean;
httpOnly: boolean;
signed?: boolean;
rolling?: boolean;
}
interface ServerBodyOptions extends KoaBody.IKoaBodyOptions {
}
interface ServerDatabaseOptions extends Knex.Config {
}
interface SpaOptions {
root: string;
filename: string;
}
interface ProxyTableOptions {
[key: string]: Config;
}
interface OptionsConfigs {
database?: ServerDatabaseOptions;
static?: ServerStaticOptions;
session?: ServerSessionOptions;
body?: KoaBody.IKoaBodyOptions;
i18n?: I18n;
spa?: SpaOptions;
proxy?: boolean;
proxyTable?: ProxyTableOptions;
response?: {
type?: 'json' | 'raw';
};
}
interface Options {
debug?: boolean;
https?: ServerOptions;
port?: number;
language?: 'zh-CN' | 'en-US';
configs?: OptionsConfigs;
controllers?: Array;
middlewares?: Array;
proxy?: boolean;
proxyTable?: ProxyTableOptions;
keys?: string[];
spa?: SpaOptions;
ssr?: Middleware;
}
interface Server {
app: Koa;
port: number;
}
interface ServerConstructor {
app: Koa;
port: number;
new (options: Options): Server;
}
interface Parameters {
type?: PropertyDecoratorTypes;
parameterIndex?: number;
args?: string | string[] | object;
}
interface ControllerOptionsParameter {
[key: string]: Array;
}
interface ControllerOptionsMethod {
[key: string]: {
propertyKey?: string;
type?: RequestMethodTypes | RequestMethodTypes[];
method?: () => Promise;
};
}
interface ControllerOptionsDatabase {
[key: string]: string | null;
}
interface ControllerOptions {
propertys?: {
[key: string]: PropertyDecoratorTypes;
};
parameters?: ControllerOptionsParameter;
databases?: ControllerOptionsDatabase;
methods?: ControllerOptionsMethod;
registerServices?: (ctx: Context) => any[];
mixinsPropertys?: (ctx: Context) => void;
mixinsParameters?: (ctx: Context, propertyKey: string, option: Options) => any[];
mixinsDatabases?: (ctx: Context, config: ServerDatabaseOptions) => void;
baseRoute?: string;
metaData?: {
new (...args: any[]): any;
}[];
target?: Controller;
}
interface Controller {
new (...args: Array): any | void;
$options?: ControllerOptions;
[key: string]: any;
}
interface Validator {
data: T;
}
}