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

@verydia/contracts

v0.1.0

Published

Contract-first event specification for Verydia workflows and frontend streaming

Readme

@verydia/contracts

Contract-first event specification for Verydia workflows and frontend streaming.

Overview

@verydia/contracts provides a type-safe way to define event contracts that can be shared between workflow implementations and frontend consumers. This eliminates type duplication, casting, and ensures full type safety across your entire application.

Installation

npm install @verydia/contracts
# or
pnpm add @verydia/contracts
# or
yarn add @verydia/contracts

Quick Start

1. Define Your Contract

import { defineEventContract, z } from "@verydia/contracts";

export const MyWorkflowContract = defineEventContract({
  started: z.object({
    timestamp: z.string(),
  }),
  progress: z.object({
    percent: z.number().min(0).max(100),
    message: z.string(),
  }),
  completed: z.object({
    result: z.string(),
    duration: z.number(),
  }),
});

2. Use in Workflow (Backend)

import { MyWorkflowContract } from "./contracts";
import type { InferEventPayload } from "@verydia/contracts";

async function myWorkflow(emit: (event: string, data: any) => void) {
  // Emit with full type safety
  emit("started", { timestamp: new Date().toISOString() });
  
  emit("progress", { percent: 50, message: "Processing..." });
  
  emit("completed", { result: "Success!", duration: 1234 });
}

3. Use in Frontend (React)

import { MyWorkflowContract } from "./contracts";
import type { InferEventMap } from "@verydia/contracts";

type WorkflowEvent = InferEventMap<typeof MyWorkflowContract>;

function handleEvent(event: WorkflowEvent) {
  if (event.type === "progress") {
    console.log(event.data.percent); // Fully typed!
  } else if (event.type === "completed") {
    console.log(event.data.result); // Fully typed!
  }
}

API Reference

defineEventContract(spec)

Define an event contract for a workflow.

Parameters:

  • spec - An object mapping event names to Zod schemas

Returns:

  • The same spec, but with enhanced type inference

Example:

const contract = defineEventContract({
  progress: z.object({ percent: z.number() }),
  complete: z.object({ result: z.string() }),
});

EventContract

Type representing a contract mapping event names to their Zod schemas.

type EventContract = Record<string, z.ZodType<any, any, any>>;

InferEventPayload<TContract, K>

Infer the payload type for a specific event in a contract.

Type Parameters:

  • TContract - The event contract type
  • K - The event name (key) in the contract

Example:

const contract = defineEventContract({
  progress: z.object({ percent: z.number() }),
});

type ProgressPayload = InferEventPayload<typeof contract, "progress">;
// Result: { percent: number }

InferEventMap<TContract>

Infer a discriminated union of all events in a contract.

Type Parameters:

  • TContract - The event contract type

Returns:

  • A union of event objects with type (discriminator) and data (payload)

Example:

const contract = defineEventContract({
  progress: z.object({ percent: z.number() }),
  complete: z.object({ result: z.string() }),
});

type Events = InferEventMap<typeof contract>;
// Result: 
// | { type: "progress"; data: { percent: number } }
// | { type: "complete"; data: { result: string } }

Benefits

✅ Single Source of Truth

Define your events once, use them everywhere.

✅ Full Type Safety

No more casts, no more any, no more runtime surprises.

✅ Runtime Validation

Zod schemas provide both TypeScript types and runtime validation.

✅ Discriminated Unions

Frontend event handlers get perfect type narrowing.

✅ Refactoring Confidence

Change a contract and TypeScript will catch all affected code.

Advanced Usage

Complex Contracts

const contract = defineEventContract({
  userAction: z.object({
    userId: z.string().uuid(),
    action: z.enum(["click", "scroll", "submit"]),
    metadata: z.record(z.unknown()).optional(),
  }),
  error: z.object({
    code: z.string(),
    message: z.string(),
    stack: z.string().optional(),
  }),
});

Nested Objects

const contract = defineEventContract({
  dataUpdate: z.object({
    user: z.object({
      id: z.string(),
      name: z.string(),
      email: z.string().email(),
    }),
    changes: z.array(z.object({
      field: z.string(),
      oldValue: z.unknown(),
      newValue: z.unknown(),
    })),
  }),
});

Arrays and Unions

const contract = defineEventContract({
  batchUpdate: z.object({
    items: z.array(z.string()),
    status: z.union([
      z.literal("pending"),
      z.literal("processing"),
      z.literal("complete"),
    ]),
  }),
});

Related Packages

  • @verydia/dev-server - Local development server for workflows
  • @verydia/client-sdk - Client SDK for calling workflows
  • @verydia/tooling-core - Core utilities and types

License

MIT

Support

For issues and questions, please visit our GitHub repository.