Skip to content

Functions

Big Mogician edited this page Dec 11, 2018 · 7 revisions

功能函数

  1. 中间件辅助
// 中间件的注入范围
interface IMiddlewaresScope<T = IContext> {
  // 当前范围的手工注入器
  injector: InjectService;
  // 全局配置容器
  configs: Configs;
  // koa上下文对象
  ctx: T;
  // koa 下一个中间件调用
  next: () => Promise<void>;
}

// 创建具有依赖注入能力的中间件
function injectScope<T extends IContext = IContext>(middleware: ProvideInvoker<T>): Koa.Middleware;
  1. 配置生成器
// 生成一个运行时options
function createOptions<T>(key: string): ConfigToken<T>;
// 生成一个与从config.*.js映射的options
function createConfig<T>(key: string): ConfigToken<T>;
  1. 多重继承构建函数
/**
 * ## 创建DI多重继承
 * * Proxy实现,只适合作为顶层服务存在
 * * 自定义多重先祖的优先级顺序
 * * 手动实现重载逻辑(如有必要)
 * * 不支持`deleteProperty`,`defineProperty`
 * * 不要使用`prop in object`来检查属性
 * * 不支持`toString`
 * * 不支持序列化
 * @description
 * @author Big Mogician
 * @export
 * @template T 对象DI类型
 * @param {T} target 当前对象
 * @param {string[]} depts 所有祖先实例在内部的字段名
 */
function createInjectMixin<T extends object>(target: T, depts: string[]): T;
  1. 路由预处理函数
interface IPreProcess {
  /** 是否自动生成2.0的routers,默认:`false` */
  enabled: boolean;
  /** 是否强制刷新2.0的routers,默认:`false` */
  always: boolean;
  /** 整个项目的url前缀,默认:`'/'` */
  appRoot: string;
  /** 生成router文件的文件类型,默认:`'js'` */
  fileType: "js" | "ts";
}

function preInitFn(configs: Partial<IPreProcess>): void;

@bonbons/di


astroboy-router

所有

Clone this wiki locally