xinyuehtx/dsh-plugin-hooks-ordering0

@tengxiaohtx/dsh-plugin-hooks-ordering

Deterministic before/after ordering for Cordis waterfall hooks, contributed across independent plugins

AI 分析

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

パッケージ
@tengxiaohtx/dsh-plugin-hooks-ordering
バージョン
0.1.0
ライセンス
MIT
最終更新
2026/08/17

インストール

検証済み bundle がないか、互換性チェックに失敗しています。先にリポジトリの説明を読んでください。 README 全文を読む ↗

ドキュメント

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.