@zenweb/core
Version:
ZenWeb Core Module - Module loader and Server
67 lines (66 loc) • 2.02 kB
TypeScript
import { Core } from './core.js';
import { Application, Context, Middleware, SetupAfterFunction, SetupDestroyFunction } from './types.js';
import { Debugger } from './util.js';
export declare const SETUP_AFTER: unique symbol;
export declare const SETUP_DESTROY: unique symbol;
export declare class SetupHelper {
/**
* Core 实例
*/
readonly core: Core;
/**
* 取得 Koa Application 实例
*/
readonly app: Application;
[SETUP_AFTER]?: SetupAfterFunction;
[SETUP_DESTROY]?: SetupDestroyFunction;
/**
* 模块名称
*/
readonly name: string;
/**
* 模块命名空间调试信息输出
*/
readonly debug: Debugger;
constructor(core: Core, name: string);
/**
* 定义核心属性
* @param prop
* @param attributes
* @returns
*/
defineCoreProperty(prop: PropertyKey, attributes: PropertyDescriptor): void;
/**
* 定义上下文附加属性
* @param prop
* @param attributes
* @returns
*/
defineContextProperty(prop: PropertyKey, attributes: PropertyDescriptor): void;
/**
* 在 Context 中定义属性并缓存,当第一次调用属性时执行 get 方法,之后不再调用 get
* @param prop 属性名称
* @param get 第一次访问时回调
*/
defineContextCacheProperty(prop: PropertyKey, get: (ctx: Context) => any): void;
private _checkContextPropertyExists;
/**
* 检查模块是否存在 - 如果不存在则直接抛出异常
* @param name 模块名称
* @param msg 自定义错误信息
*/
assertModuleExists(name: string, msg?: string): void;
/**
* 所有模块初始化完成后执行回调
*/
after(callback: SetupAfterFunction): void;
/**
* 销毁回调
* 服务停止时会调用方法,等待方法完成
*/
destroy(callback: SetupDestroyFunction): void;
/**
* 使用全局中间件
*/
middleware(middleware: Middleware): void;
}