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

@xtr-dev/zodiac

v0.0.3

Published

Zodiac - Type-safe WebSocket messaging with Zod validation

Readme

Zodiac

npm version TypeScript Documentation License Bundle Size

Type-safe WebSocket messaging with Zod validation. A lean, modern library for real-time communication.

Features

  • 🔒 Type Safety: Full TypeScript support with automatic type inference
  • Runtime Validation: Powered by Zod schemas for data integrity
  • 🌐 Universal: Works in both browser and Node.js environments
  • 🎯 Simple API: Clean, intuitive message handling with on/off methods
  • 🔄 Multiple Transports: WebSocket, WebRTC P2P data channels
  • 🚀 Zero Dependencies: Only depends on Zod for validation
  • 📦 Lightweight: Minimal bundle size with tree-shaking support

Quick Start

npm install @xtr-dev/zodiac zod

Define Messages

import { defineMessage, z } from '@xtr-dev/zodiac';

// Define type-safe messages
const userMessage = defineMessage('user-message', z.object({
  name: z.string(),
  message: z.string(),
  timestamp: z.number().optional()
}));

const chatJoin = defineMessage('chat-join', z.object({
  userId: z.string(),
  username: z.string()
}));

Browser Usage

import { BrowserChannel } from '@xtr-dev/zodiac';

const channel = new BrowserChannel();

// Listen for messages with full type safety
channel.on(userMessage, (data, message) => {
  console.log(`${data.name}: ${data.message}`);
  // data.name and data.message are fully typed!
});

channel.on(chatJoin, (data) => {
  console.log(`${data.username} joined!`);
});

// Connect and send messages
await channel.connect('wss://your-websocket-server.com');

// Send with automatic validation
await channel.sendMessage(userMessage, {
  name: 'Alice',
  message: 'Hello everyone!',
  timestamp: Date.now()
});

Node.js Usage

import { NodeChannel } from '@xtr-dev/zodiac';

const channel = new NodeChannel();

// Same API as browser
channel.on(userMessage, async (data) => {
  console.log(`Received: ${data.message}`);
  
  // Echo back
  await channel.sendMessage(userMessage, {
    name: 'Server',
    message: `Echo: ${data.message}`
  });
});

await channel.connect('ws://localhost:8080');

Zodiac also supports WebRTC peer-to-peer communication with PeerChannel for direct browser-to-browser messaging. See the API documentation for details.

Interactive Demo

Try the live HTML demo to see Zodiac in action:

git clone <this-repo>
cd zodiac
npm install
npm run example

This starts both a WebSocket todo server and opens an interactive demo where you can:

  • Experience multi-user real-time todo list synchronization
  • Send type-safe todo operations with validation
  • Test collaborative todo management
  • Open multiple tabs for multi-user testing
  • See TypeScript types and validation in action

Validation & Type Safety

Zodiac provides both compile-time and runtime safety:

const userMsg = defineMessage('user', z.object({
  name: z.string(),
  age: z.number()
}));

// ✅ TypeScript knows the exact shape
channel.on(userMsg, (data) => {
  console.log(data.name); // string
  console.log(data.age);  // number
});

// ✅ Runtime validation prevents invalid data
await channel.sendMessage(userMsg, {
  name: 'Alice',
  age: 'invalid' // ❌ Throws validation error
});

API Reference

defineMessage(id, schema)

Creates a type-safe message definition with validation schema:

const myMessage = defineMessage('my-message', z.object({
  content: z.string(),
  priority: z.enum(['low', 'high'])
}));

// Returns: { id: string, schema: ZodSchema, messageSchema: ZodObject }

Channel Methods

All channels (BrowserChannel, NodeChannel, PeerChannel) share the same core API:

  • channel.on(definition, handler) - Listen for messages with full type safety
  • channel.off(definition, handler) - Remove message listeners
  • channel.sendMessage(definition, data) - Send validated messages
  • channel.connect(url) - Establish connection
  • channel.disconnect() - Close connection
  • channel.isOpen() - Check connection status

See the full API documentation for complete details.

📖 Documentation

  • API Documentation - Complete TypeDoc-generated API docs
  • Examples - Live demos and usage examples
  • Local docs: Run npm run docs to generate docs locally

Generate and serve docs locally:

npm run docs        # Generate documentation
npm run docs:serve  # Serve docs at http://localhost:8080

License

UNLICENSED - No rights reserved