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

@vectorfyco/valbridge-zod

v1.1.0

Published

Render valbridge IR into Zod schemas

Downloads

823

Readme

valbridge-zod

Zod 4.x adapter for valbridge -- converts JSON Schema into idiomatic Zod validators with full TypeScript type inference.


Installation

pnpm add @vectorfyco/valbridge-zod zod

Supported Zod range: ^4.0.0. Verified in CI against zod 4.3.6.

Usage

This adapter is invoked by the valbridge CLI. Define schemas in a config file:

// user.valbridge.jsonc
{
  "$schema": "https://github.com/vectorfy-co/valbridge/schemas/typescript.jsonc",
  "schemas": [
    {
      "id": "User",
      "adapter": "@vectorfyco/valbridge-zod",
      "sourceType": "file",
      "source": "./schemas/user.json"
    }
  ]
}

Then generate:

valbridge generate

Use the generated schemas with the valbridge runtime client.

JSON Schema compliance

See compliance/results/REPORT.md for detailed test results from the JSON Schema Test Suite.

Verification

Run from the adapter directory (typescript/packages/adapters/zod/):

# JSON Schema Test Suite compliance (requires Go CLI)
pnpm run compliance

# Unit tests
pnpm run test

# Type checking
pnpm run typecheck

# Type-fidelity harness (checks for any-leakage regressions)
pnpm run type-fidelity

Fallback typing guardrails

The adapter uses z.unknown() as a safe fallback for unbounded domains and z.any() only where Zod's type system cannot represent the constraint statically. The goal: minimize any in inferred TypeScript types.

Allowed z.any() fallbacks

| Construct | Reason | |-----------|--------| | IR any node | Empty schema {} or true -- no constraints to express | | Empty/all-any intersection | Zero effective schemas | | Tuple base | z.tuple() does not support open tuples with rest items | | Complex const array | Deep equality validated via runtime helper | | Complex enum values | Values span multiple types | | Prototype-property objects | z.object() cannot handle __proto__, constructor, etc. |

Constructs that must NOT use any

These are validated by the type-fidelity harness and will fail CI on regression:

  • oneOf, not, conditional, typeGuarded -- must use z.unknown()
  • const (object) -- must use z.object({}).passthrough().refine(...)

Troubleshooting

  • Type-fidelity shows IMPROVED -- a probe got narrower than expected. Update expectAny to false to lock in the improvement.
  • Type-fidelity shows FAIL -- a renderer change regressed the type output. Fix the regression.
  • ZodEffects method errors -- array size constraints must come before .superRefine()/.refine() calls.

Related packages

| Package | Purpose | | --- | --- | | @vectorfyco/valbridge | Runtime client for generated validators | | @vectorfyco/valbridge-core | Core IR and JSON Schema parser | | @vectorfyco/valbridge-zod-bridge | Bridge helpers for Zod generation |

Learn more