npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhin.js/middleware

v1.1.24

Published

Convention-based Middleware Feature for Zhin Plugin Runtime

Readme

@zhin.js/middleware

Zhin Plugin Runtime 的 Middleware Feature。它从 middlewares/**/*/index.ts 发现定义,并按 phase、order、Plugin topology 与 capability identity 形成稳定执行链。

依赖 zhin.js 时从门面导入(勿再单独安装本包):

import { defineMiddleware } from 'zhin.js/middleware';

export default defineMiddleware({
  phase: 'before-dispatch',
  handle(_context, next) { return next(); },
});

Middleware 不直接持有 Root 或运行时 registry;每次执行使用同一 generation snapshot, 更新时由 Feature Slot 原子替换。

入站中间件可返回文本、JSX 或其他发送内容。return next() 保留下游的返回值与作者; await next() 后不返回也透传下游结果,返回新内容则替换待自动回复内容。不调用 next() 会消费输入;不返回内容时不会自动回复。Runtime 在整条入站链回卷后只自动回复一次, 显式调用 input.$reply() 仍可发送多条消息。已经发送的显式消息不会被返回值替换撤回。

出站中间件使用 target: 'outbound',通过 input.replace(content) 修改候选 payload, 再调用 next() 放行;返回类型为 void,不参与入站的自动回复与 continuation 传递。

next() 的 continuation 只用于透传,不暴露内容,也不可跨调用保存复用。每层只能调用 一次 next();遗漏 await 的下游操作仍会在当前 scope 结束前结算,异常向调用方传播。

单文件插件可用 setup({ addMiddleware }) 注册 defineMiddleware(...);它仍参与 统一 phase/order/topology 排序和 generation 回滚。

验证:pnpm --filter @zhin.js/middleware test && pnpm --filter @zhin.js/middleware build。

生命周期与 HMR 说明见 目标架构。