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

@api-zero/zod

v0.1.5

Published

Zod runtime contracts and schema validation adapters for api-zero.

Readme

@api-zero/zod

Zod runtime contracts and schema validation adapters for api-zero.

Installation

npm install @api-zero/zod @api-zero/core zod
# or
pnpm add @api-zero/zod @api-zero/core zod

Features

  • 🎯 Full Type Inference: Automatically infers TypeScript types using z.infer<typeof schema>.
  • ⚡️ Zero Bloat in Core: Keep @api-zero/core ultralight and install @api-zero/zod only when schema validation is desired.
  • 🛡️ Fail-Fast Outbound Validation: zodBody() validates payloads before sending them across the network.
  • 🔄 Automatic Transforms & Coercion: Fully supports Zod transforms (.transform(), z.coerce).
  • 🚨 Structured Errors: ZodValidationError extends ApiError with .issues, .flatten(), and .format().

Usage

1. zodResponse (Inferred Return Types)

import { createClient } from "@api-zero/core";
import { zodResponse } from "@api-zero/zod";
import { z } from "zod";

const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string().email(),
  createdAt: z.string().transform((iso) => new Date(iso)),
});

const client = createClient({ baseURL: "https://api.example.com" });

// user is automatically typed as { id: number; name: string; email: string; createdAt: Date }
const user = await client.get("/users/1", zodResponse(UserSchema));

2. zodBody (Fail-Fast Outbound Validation)

import { zodBody } from "@api-zero/zod";

const CreateUserSchema = z.object({
  name: z.string().min(2),
  email: z.string().email(),
});

// Throws ZodValidationError locally without making a network request if body is invalid
const newUser = await client.post(
  "/users",
  { name: "A", email: "invalid" },
  zodBody(CreateUserSchema),
);

3. withZod / createZodClient (Fluent Client)

import { createZodClient } from "@api-zero/zod";

const api = createZodClient({ baseURL: "https://api.example.com" });

// Direct typed verbs
const user = await api.get("/users/1", UserSchema);
const created = await api.post(
  "/users",
  { name: "Alice", email: "[email protected]" },
  { response: UserSchema, body: CreateUserSchema },
);

4. Error Handling with ZodValidationError

import { ZodValidationError } from "@api-zero/zod";

try {
  await api.get("/users/1", UserSchema);
} catch (error) {
  if (error instanceof ZodValidationError) {
    console.error("Target:", error.target); // 'response' | 'body'
    console.error("Issues:", error.issues);
    console.error("Field errors:", error.flatten().fieldErrors);
  }
}

License

MIT