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

prisma-zod-generator

v2.9.0

Published

Prisma 2+ generator to emit Zod schemas from your Prisma schema

Readme

Prisma Zod Generator

A Prisma generator that emits Zod schemas from your Prisma schema. It runs as part of prisma generate, so your validation schemas are regenerated from the same source of truth as your Prisma Client.

npm version downloads CI license MIT

Documentation · PZG Pro

Requirements

| Dependency | Supported | | ---------- | ------------------------------------------------- | | Node.js | >= 20.19.0 (22.x recommended) | | Prisma | 7.x | | Zod | >= 3.25.0 < 5 (both v3 and v4 output are emitted) | | TypeScript | >= 5.4 (5.9.x recommended) |

Install

npm install --save-dev prisma-zod-generator
npm install zod

Install the generator locally rather than globally: Prisma resolves the generator executable from node_modules/.bin, so a project-local install is what makes provider = "prisma-zod-generator" work. zod is a peer dependency (>=3.25.0 <5) because the generated files import it at runtime.

Usage

Add the generator to schema.prisma:

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

generator zod {
  provider = "prisma-zod-generator"
  // output defaults to <schema dir>/generated
  // config = "./zod-generator.config.json"
}

Then run:

npx prisma generate

With no configuration you get one schema file per Prisma CRUD operation, plus the input object and enum schemas they reference:

prisma/generated/schemas/
├── findManyUser.schema.ts     # UserFindManySchema, UserFindManyZodSchema
├── createOneUser.schema.ts    # UserCreateOneSchema, UserCreateOneZodSchema
├── objects/                   # UserWhereInputObjectSchema, UserCreateInputObjectSchema, ...
├── enums/                     # SortOrderSchema, UserScalarFieldEnumSchema, ...
├── results/                   # UserFindManyResultSchema, ...
├── variants/                  # pure/ input/ result/ variants of each model
└── index.ts                   # barrel re-export

A helpers/ directory is emitted next to schemas/ when the Prisma schema contains Json or Decimal fields, and models/ appears under schemas/ once pureModels is enabled.

Every operation file exports the schema twice. <Model><Operation>Schema is annotated as z.ZodType<Prisma.<Model><Operation>Args>, so parsed output can be handed straight to the Prisma Client; <Model><Operation>ZodSchema is the unannotated object, for when you need .extend(), .partial() or .omit().

import { UserFindManySchema } from './prisma/generated/schemas/findManyUser.schema';

const args = UserFindManySchema.parse(req.query);
const users = await prisma.user.findMany(args);

Model schemas

Set pureModels: true to also emit one plain schema per model, with no CRUD wrappers and no Prisma types:

// prisma/generated/schemas/models/User.schema.ts
import * as z from 'zod';

export const UserSchema = z.object({
  id: z.number().int(),
  email: z.string(),
  name: z.string().nullish(),
});

export type UserType = z.infer<typeof UserSchema>;

Validators declared in the Prisma schema

@zod annotations in triple-slash comments are compiled into the generated field schemas:

model User {
  id    Int     @id @default(autoincrement())
  /// @zod.email()
  email String  @unique
  /// @zod.min(2).max(80)
  name  String?
}

See Zod comment annotations for the supported validators, custom imports, and metadata annotations.

Configuration

Options can be set in the generator block or in a JSON file next to schema.prisma. zod-generator.config.json is discovered automatically; any other path can be passed via config = "./my-config.json" (resolved relative to the schema file).

{
  "$schema": "../node_modules/prisma-zod-generator/lib/config/schema.json",
  "mode": "full",
  "pureModels": true,
  "useMultipleFiles": true
}

The $schema line gives autocomplete, hover docs, and validation in any JSON-aware editor; adjust the relative path to match your layout. Commonly used options: mode (full | minimal | custom), output, useMultipleFiles / singleFileName, pureModels, variants, naming, optionalFieldBehavior, dateTimeStrategy, strictMode, emit, zodImportTarget, zodImportPath. useMultipleFiles: false collapses the output into a single schemas.ts.

The recipes/ directory holds ready-made config presets (minimal CRUD, models only, single file, tRPC-optimized, and more); each one is a zod-generator.config.json with a short README explaining the trade-offs.

PZG Pro

The generator above is MIT licensed and complete on its own. The commercial packs generate the layers people usually hand-write around it:

  • Server Actions — typed Next.js 'use server' actions per model, validation already wired in.
  • Form UX — working forms from your schema for shadcn, MUI, Chakra, Mantine, or plain elements, with react-hook-form and your Zod schemas connected.
  • Policies & Redaction — turn /// @policy and /// @pii comments in your schema into enforced access rules and redacted logs, plus PostgreSQL row-level security.
  • Drift Guard — a CI command that compares two git refs and fails the build on a breaking schema change, with an allow-list for the ones you accept.
  • SDK Publisher — a publishable TypeScript or Python client for your models.
  • API Docs, Contract Testing, Data Factories, Performance, Multi-Tenant Kit — OpenAPI plus a mock server, Pact consumer and provider tests, seed factories typed to your schema, precompiled generation for large schemas, and tenant isolation enforced in the client.

| Pack | Minimum plan | | ----------------------------------------------------------------------------- | ------------ | | Server Actions, Form UX | Starter | | Policies & Redaction, Drift Guard, PostgreSQL RLS, SDK Publisher, Performance | Professional | | API Docs, Contract Testing, Data Factories | Business | | Multi-Tenant Kit | Enterprise |

Pro code ships inside the published package, is unlocked with a PZG_LICENSE_KEY, and is invoked through the bundled pzg-pro CLI. Pro features · Pricing

Buying a licence

Licences are sold through GitHub Sponsors, which needs one thing spelled out: open the One-time tab — the second one — and pick a yearly PZG Starter, PZG Professional, PZG Business, or PZG Enterprise tier. The monthly support tiers on the first tab do not include a PZG Pro licence.

https://github.com/sponsors/omar-dulaimi

Sponsor

Sponsorships fund maintenance and new feature work, separately from any Pro licence: https://github.com/sponsors/omar-dulaimi

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md for the repository layout, commit conventions, and test commands. Please open an issue before large refactors, and keep diffs focused.

License

MIT © Omar Dulaimi — see LICENSE. PZG Pro packs are covered by a separate commercial license (LICENSE-PRO.md).