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

@mqttkit/core

v0.2.2

Published

Elysia-like MQTT application framework for TypeScript.

Downloads

27

Readme

@mqttkit/core

English

TypeScript 写的 Elysia 风格 MQTT 应用框架。提供运行时:有序 middleware、topic router、类型化 context、服务注入、lifecycle events、RPC、schema 校验、指标、优雅关停,以及 broker adapter 接口。

完整文档:https://mqttkit.keyp.dev/zh/

安装

bun add @mqttkit/core @mqttkit/aedes aedes

使用

import { aedes } from '@mqttkit/aedes'
import { MqttApp, router } from '@mqttkit/core'

const app = new MqttApp()
  .use(aedes({ tcp: { port: 1883 }, ws: { port: 8888, path: '/mqtt' } }))
  .use(
    router().topic('devices/:uid/events', {
      async onMessage(ctx) {
        await ctx.publish(`server/${ctx.params.uid}/echo`, ctx.payload)
      },
    }),
  )

await app.listen()

功能

  • 路由与 middleware —— router().topic(pattern, config) 用 Elysia 风格 :param / *app.use() 有序 middleware;app.decorate() 注入业务服务。
  • Schema 校验 —— topic({ schema }) 接任意 Standard Schema v1 校验器;原始 TypeBox 通过 addSchemaProvider 接入。
  • MQTT 5 RPC —— app.request(topic, payload) / ctx.reply(payload)responseTopic + correlationData
  • MQTT 5 共享订阅 —— 自动识别 $share/<group>/<filter>,剥前缀后用真正 filter 匹配路由,并把 group 透到 subscribe policy 的 shared.group
  • 路由级护栏 —— topic({ timeout, concurrency });触发后 onError phase 分别是 'timeout' / 'overload'
  • 指标 —— app.onMetric(handler) 每次 dispatch / publish 触发一次结构化事件。
  • 优雅关停 —— app.stop({ drain: true, timeout }) 等在飞 handler 跑完再关 broker;app.activeCount() 看在飞总数。
  • Tracing —— ctx.userProperties 读入站 MQTT 5 user properties;app.onBeforePublish(hook) 给出站注 user properties(W3C traceparent、correlation ID 等)。
  • 生命周期 —— app.on(eventName, handler) 监听 broker 事件;app.onStart / app.onStop 是应用边界。
  • 测试 —— @mqttkit/core/testing 提供内存版 TestBroker,跑单测不用起 aedes。

onError 阶段:validation | policy | middleware | handler | timeout | overload | publish。错误负载里带原始 payload,方便 Sentry / 结构化日志拿到出错的消息内容。

文档