xinyuehtx/dsh-plugin-hooks-ordering0

@tengxiaohtx/dsh-plugin-hooks-ordering

Cordis 钩子顺序控制插件,为跨插件的瀑布流钩子提供确定性的前后执行顺序控制。

AI 分析

核心用途是解决多插件场景下的钩子执行冲突与竞争问题。适合 DSH 插件开发者,用于确保特定生命周期钩子(如请求组装)按预期顺序执行。

包名
@tengxiaohtx/dsh-plugin-hooks-ordering
版本
0.1.0
许可证
MIT
最近更新
2026年8月17日

安装

此插件尚未提供可验证的 bundle,或兼容性检查未通过。请先阅读仓库说明。 阅读完整 README ↗

Usage

import HookOrdering from '@tengxiaohtx/dsh-plugin-hooks-ordering'

ctx.plugin(HookOrdering)

// The hook owner (or app composition) takes control ONCE. This installs the
// single bracket listener; controlling twice throws, so the prepend race
// cannot come back.
ctx.hooksOrdering.control('request/assemble')

// Vendor A — names only its own constraint, imports nothing from vendor B.
ctx.hooksOrdering.register('request/assemble', 'front', {
  name: 'auth',
  before: ['logging'],
  run: (req) => authenticate(req),
})

// Vendor B — a different package, unaware of A.
ctx.hooksOrdering.register('request/assemble', 'front', {
  name: 'logging',
  run: (req) => log(req),
})

// Vendor C — must run after everything, even the host default.
ctx.hooksOrdering.register('request/assemble', 'back', {
  name: 'metrics',
  run: (req) => emitMetrics(req),
})

Regardless of the order these three plugins load or register, auth runs before logging, and metrics runs last.