///
import * as http from 'http';
import response from './response';
import error from './error';
import { Server } from './server';
import { StaticActive } from './server.static';
import MapApi, * as Map from './map';
import RoleApi, * as Role from './role';
import LinkApi, * as Link from './link';
import RouterApi, * as Router from './router';
import UrlApi, * as Url from './url';
import { Info, MiniInfo, ExtendedObject, AppExtendedObject } from './info';
import { CookieOpt } from './server.cookie';
import { File, saveFile, getUrl, getPath } from './server.multipart';
import { server as virtualServer } from './server.virtual';
import { pathMatch } from './util.path-match';
import { Readable } from 'stream';
export { File, Map, Role, Link, Router, Url, Server, virtualServer, MiniInfo as BaseInfo, MiniInfo, Info, response as Response, error as Error, };
declare type Optional- = {
[key in keyof item]?: item[key] extends {
[key: string]: any;
} ? (item[key] extends Function ? item[key] : Optional
- ) : item[key];
};
/** 用户管理 */
export interface UserManager {
/** token 使用的 cookie */
tokenName: string;
/** 用于设置登陆用户的方法 */
login(uid: string, config: object, info: Info): string | boolean | Promise;
/** 用于退出用户的方法 */
exit(config: object, info: Info): boolean | Promise;
/** 用于判定当前用户是否登陆的方法 */
checkCookie(cookie: string, config: object, info: Info): string | [string] | [string, string] | Promise;
/** 获取用户权限 */
getPower(uid: string): any;
}
export declare type BaseUserManager = Optional>;
/** 文件保存相关 API */
export interface FileCfg {
save: saveFile;
getUrl: getUrl;
getPath: getPath;
}
export declare type BaseFileCfg = Optional;
/** 日志相关 API */
/** 有连接 */
export interface LinkLog {
(method: string, path: string, header: http.IncomingHttpHeaders): void;
}
/** 产生错误 */
export interface ErrorLog {
(error: Error): void;
}
/** 处理结果 */
export interface HandleLog {
(beginTime: Date, statusCode: number, type: string, method: string, path: string, header: http.IncomingHttpHeaders): void;
}
export interface LogCfg {
link: LinkLog;
error: ErrorLog;
handle: HandleLog;
}
export declare type BaseLogCfg = Optional;
/** 静态相关 API */
export interface StaticCfg {
basePath(appId: string): string | string[];
index(accept: string[]): string | string[];
extension(accept: string[]): string | string[];
active?: StaticActive;
}
export declare type BaseStaticCfg = Optional;
export declare type BufferType = {
buffer: ArrayBuffer | SharedArrayBuffer;
} | ArrayBuffer | SharedArrayBuffer | Buffer;
/** 页面渲染接口 */
export interface Render {
(data: object, path: string, appId?: string): BufferType | string | Readable | Promise;
}
/** Info 扩展接口 */
export interface Extends {
(appId?: string): AppExtendedObject | Promise;
}
/** 配置 */
export interface Config {
/** 是否为调试模式 */
isDebug: boolean;
/** 默认端口号 */
port: number;
/** 默认协议 */
protocol: string;
/** jsonp 回调函数名称 */
cbName: string;
/** cookie 选项 */
cookie: CookieOpt;
/** 动态渲染函数 */
render?: Render;
/** Info 扩展接口 */
extends: Extends;
/** 用户管理 */
userManager: UserManager;
/** 静态管理 */
static: StaticCfg;
/** 文件相关协议 */
file: FileCfg;
util: Ext['util'];
api: Ext['api'];
userApi: (uid: string) => Ext['user'] | null;
log: LogCfg;
}
export declare type BaseConfig = Optional>;
interface xurouter {
readonly map: MapApi;
readonly role: RoleApi;
readonly link: LinkApi;
readonly router: RouterApi;
readonly Response: typeof response;
readonly Error: typeof error;
readonly url: UrlApi;
readonly server: Server;
match: pathMatch;
readonly config: Config;
}
declare function xurouter(cfg?: BaseConfig): xurouter;
export default xurouter;