prisma-zod-generator  by omar-dulaimi

Generate Zod schemas from Prisma schema definitions

Created 3 years ago
741 stars

Top 46.7% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a Prisma 2+ generator that automatically creates Zod schemas from your Prisma schema. It aims to offer zero-boilerplate validation and typed data for your models, benefiting developers who use Prisma and Zod for data validation and type safety in their applications.

How It Works

The generator transforms your Prisma schema definitions into corresponding Zod schemas. It offers multiple generation modes: "Full Mode" for a complete ecosystem of CRUD operations, input/result schemas, and enums; "Minimal Mode" for essential CRUD operations with lean output; and "Custom Mode" for granular control and selective generation based on user-defined rules. This approach ensures consistent, type-safe validation across your application without manual schema creation.

Quick Start & Requirements

  • Prerequisites: Node.js 18+, Prisma installed and initialized (npx prisma init), Zod installed (runtime dependency).
  • Installation:
    • npm: npm i -D prisma-zod-generator
    • pnpm: pnpm add -D prisma-zod-generator
    • yarn: yarn add -D prisma-zod-generator
    • bun: bun add -d prisma-zod-generator
  • Configuration: Add the generator block to schema.prisma:
    generator zod {
        provider = "prisma-zod-generator"
    }
    
  • Generation: Run npx prisma generate.
  • Usage: Import generated schemas (e.g., import { UserSchema } from './prisma/generated/schemas';) and use Zod's safeParse for validation.
  • Docs: https://omar-dulaimi.github.io/prisma-zod-generator/

Highlighted Details

  • Generation Modes: Offers "Full" (complete ecosystem), "Minimal" (essential CRUD), and "Custom" (granular control) modes.
  • Schema Variants: Generates Pure Models, CRUD operations, Input/Result Objects, Enums, and supports user-defined Custom Variants.
  • Filtering & Selection: Provides granular control via model, operation, and field filtering, including wildcard patterns.
  • Organization & Naming: Flexible file organization (multi-file, single-file, custom paths) and extensive naming control presets and patterns.
  • Type Safety & Performance: Features dual exports (Prisma-bound/pure Zod), strict type binding, ESM/CJS support, and optimized generation for minimal bundles and fast performance.
  • Data Handling & Advanced Features: Supports JSON/Bytes fields, flexible DateTime strategies, @zod comments for enhanced parsing, JSON schema generation, and fixes for circular dependencies.

Maintenance & Community

The project encourages contributions via Pull Requests and discusses larger changes in issues. Sponsorship is welcomed to support maintenance and new features via GitHub Sponsors.

Licensing & Compatibility

The project is licensed under the MIT license. This license is permissive and generally compatible with commercial use and closed-source applications.

Limitations & Caveats

The provided README does not explicitly mention any limitations, alpha status, known bugs, or deprecations. The project appears to be actively maintained with a clear feature set.

Health Check
Last Commit

3 days ago

Responsiveness

Inactive

Pull Requests (30d)
34
Issues (30d)
18
Star History
47 stars in the last 30 days

Explore Similar Projects

Starred by Marc Klingen Marc Klingen(Cofounder of Langfuse), John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), and
2 more.

zod-gpt by dzhng

0.2%
627
SDK for structured JSON output from LLMs, validated via Zod schemas
Created 2 years ago
Updated 1 year ago
Feedback? Help us improve.