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

@avanda/http

v0.6.0

Published

Avanda http module

Readme

@avanda/http

Two-way streaming sockets: @Streamable

@Streamable turns a controller method into a long-lived, two-way websocket. Use it for uploads, audio/video ingestion, or any protocol where the client sends many frames and the server answers only when it has something to say.

import { Controller, Response, Request, Streamable, StreamHandlers } from "@avanda/http";

export default class Recording extends Controller {
  @Streamable({ middlewares: [Auth], maxPayload: 4 * 1024 * 1024 })
  upload(res: Response, req: Request): StreamHandlers {
    const chunks: Buffer[] = [];
    const title = req.getData<string>("title"); // from ?data=

    return {
      onBinary: async (chunk) => {
        chunks.push(chunk);
      },
      onMessage: async (data) => {
        if (data.end) {
          const id = await save(req.getAttrs("user"), title, Buffer.concat(chunks));
          res.socket.send({ id });
          res.socket.close(1000, "done");
        }
      },
      onClose: (code) => {
        chunks.length = 0;
      },
    };
  }
}

Connecting

Connect to /watch exactly as for @Watchable:

ws://host/watch?query={"n":"Recording","f":"upload"}&data={"title":"Intro"}

Lifecycle

  1. Connect. The middlewares run once, with the connection's headers. If one fails, the socket is closed with code 4401 and the middleware's message as the close reason, and the method is never called.
  2. Open. The method is called once with (res, req). req holds the middleware attrs (req.getAttrs()) and the ?data= params (req.getData()). It returns the handlers below.
  3. Frames.
    • onBinary(chunk: Buffer) receives binary frames as raw bytes. They are never parsed.
    • onMessage(data) receives text frames, JSON-parsed. Invalid JSON, or a handler that throws, sends an error frame (status_code: 400) and the socket stays open.
    • Frames are delivered in arrival order. Each handler, including async ones, finishes before the next frame is delivered. Frames that arrive while the method is still opening wait for it.
    • Nothing is sent back automatically. Reply with res.socket.send() when you want to.
  4. Close. onClose(code) runs exactly once, whether the client or the server closes, and only after every queued frame has been handled.

res.socket

| Member | Description | | --- | --- | | id | The connection id (same as req.id). | | send(data) | Sends one JSON Avanda response frame ({ msg, data, status_code, ... }). Pass a Response to control msg/status_code. Ignored once the socket is closing. | | close(code = 1000, reason = "") | Closes the socket. The reason is truncated to the 123-byte websocket limit. |

Options

| Option | Default | Description | | --- | --- | --- | | middlewares | [] | Run once at connect; failure closes with 4401. | | maxPayload | 1048576 (1 MB) | A frame larger than this closes the socket with 1009. The websocket server's own 100 MiB limit still applies above this. |

Close codes

| Code | Meaning | | --- | --- | | 4401 | A middleware rejected the connection. | | 1009 | A frame exceeded maxPayload. | | 1011 | The method threw while opening the stream. | | 1007 | The ?query= or ?data= param was not valid JSON (any /watch socket). |

A @Streamable method can only be opened over a websocket; calling it over HTTP returns an error response.