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

@cxai/yapi

v0.3.0

Published

Content-negotiated Y.Map server — Hono middleware with Mustache templates, path param filters, JSON/HTML/SSE handlers.

Downloads

213

Readme

@cxai/yapi

Content-negotiated Y.Map server built on Hono. Define routes declaratively — get JSON, HTML (Mustache), and SSE endpoints automatically from Yjs documents. Supports path-param filtering and dynamic collection resolution via templates.

Install

npm install @cxai/yapi

Usage

Standalone

import * as Y from "yjs";
import { createApp } from "@cxai/yapi";

const doc = new Y.Doc();

const app = createApp(doc, {
  routes: {
    "/users": {
      collection: "users",
      json: { template: { data: "{{list}}", total: "{{count}}" } },
      html: { template: "<ul>{{#list}}<li>{{name}}</li>{{/list}}</ul>" },
      sse: { event: "user-update" },
      post: { key: "id" },
    },
    "/users/:userId": {
      collection: { template: "users" },  // dynamic collection resolution
      select: "first",
    },
  },
});

// Content negotiation via Accept header or ?format= query
// GET /users              → JSON (Accept: application/json)
// GET /users?format=html  → HTML
// GET /users?format=sse   → SSE stream
// POST /users             → write to Y.Map

Combined with @cxai/faker

import { createFakerJob } from "@cxai/faker";
import { createApp } from "@cxai/yapi";

const doc = new Y.Doc();

// Faker pushes items into doc
createFakerJob(doc, "events", {
  id: "{{string.uuid}}",
  type: "{{helpers.arrayElement(['click','scroll','submit'])}}",
  timestamp: "{{date.recent}}",
}, { count: 100, interval: [500, 1000], autoStart: true });

// yapi serves them in real-time
const api = createApp(doc, {
  routes: {
    "/events": { collection: "events", sse: { event: "{{type}}" } },
    "/events/:type": { collection: "events" },  // filtered by path param
  },
});

Combined with @cxai/job

import { createJob } from "@cxai/job";
import { createApp } from "@cxai/yapi";

const job = createJob({ doc, path: "discoveries", iterable: appDiscoverySource });
const api = createApp(doc, {
  routes: { "/discoveries": { collection: "discoveries", sse: {} } },
});
job.trigger(); // SSE clients see items arrive in real-time

CLI

npx cxai-yapi --config routes.yaml --port 3000

API Reference

createApp(doc, config): Hono

Creates the full content-negotiated app. Routes are prefixed by format internally (/json/*, /html/*, /sse/*) and selected via getPath content negotiation.

YapiConfig

interface YapiConfig {
  routes: Record<string, RouteDef | string>;  // string shorthand = collection name
}

RouteDef

interface RouteDef {
  collection: string | { template: string };  // Mustache template for dynamic resolution
  select?: "list" | "first" | "last";
  json?: { template?: Record<string, any> };
  html?: { template: string };                // Mustache template
  sse?: { event?: string; template?: string | Record<string, any> };
  post?: PostDef | boolean;
}

interface PostDef {
  key?: string;              // body field to use as Y.Map key (default: "id")
  template?: Record<string, any>;  // response template
}

createYapiMiddleware(doc, config)

Standalone middleware that resolves context variables:

| Variable | Type | Description | |----------|------|-------------| | c.get("doc") | Y.Doc | The document | | c.get("source") | Y.Map | Raw collection | | c.get("collection") | Y.Map | Filtered + synced collection | | c.get("config") | RouteDef | Matched route definition |

getPath(req): string

Content negotiation helper — prefixes path with /json, /html, or /sse based on Accept header or ?format= query param.

Sub-app factories

| Function | Description | |----------|-------------| | createJsonApp(config) | JSON GET + POST routes | | createHtmlApp(config) | Mustache-rendered HTML | | createSseApp(config) | SSE via @cxai/stream yMapIterate |

Helpers

  • renderObject(template, ctx) — recursive Mustache object rendering
  • renderValue(value, ctx) — single value render (preserves raw types for exact {{key}} matches)
  • findMatchingRoute(path, routes) — path-param route matching

Examples

See Also