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 🙏

© 2025 – Pkg Stats / Ryan Hefner

supazod

v4.1.0

Published

Generate Zod schemas from Supabase CLI generated types

Readme

Supazod

Generate Zod schemas from Typescript types generated by the Supabase CLI.

Quick Start

$ pnpm add --D supazod
$ supabase gen types typescript --local > types.ts
$ pnpm supazod -i types.ts -o schemas.ts -t schemas.d.ts -s public,schema_a,schema_b

That's it! Check your schemas.ts file - you should have Zod schemas generated for all your tables, views, enums and functions.

Generated Output

Supazod generates clean, consistent schema names:

// ✅ Clean naming (v2.0+)
export const publicUsersInsertSchema = z.object({...});
export const publicUsersUpdateSchema = z.object({...});
export const publicUserStatusSchema = z.union([...]);
export const publicGetStatusArgsSchema = z.object({...});

// TypeScript types without "Schema" suffix
export type PublicUsersInsert = z.infer<typeof generated.publicUsersInsertSchema>;
export type PublicUserStatus = z.infer<typeof generated.publicUserStatusSchema>;

Configuration

TypeScript Configuration (Recommended)

Create a supazod.config.ts file for type-safe configuration with IntelliSense:

import { defineConfig } from 'supazod';

export default defineConfig({
  namingConfig: {
    // TypeScript provides autocomplete for placeholders:
    // {schema}, {table}, {operation}, {function}, {name}
    tableOperationPattern: '{schema}_{table}_{operation}',
    tableSchemaPattern: '{schema}{table}{operation}',
    enumPattern: '{schema}_{name}_Enum',
    enumSchemaPattern: '{schema}{name}',
    functionArgsPattern: '{schema}_{function}_Args',
    functionArgsSchemaPattern: '{schema}{function}Args',
    functionReturnsPattern: '{schema}_{function}_Returns',
    functionReturnsSchemaPattern: '{schema}{function}Returns',

    // Capitalization and formatting
    capitalizeSchema: true,
    capitalizeNames: true,
    separator: '_',
  }
});

JSON Configuration

{
  "namingConfig": {
    "tableOperationPattern": "{schema}_{table}_{operation}",
    "tableSchemaPattern": "{schema}{table}{operation}",
    "enumPattern": "{schema}_{name}_Enum",
    "enumSchemaPattern": "{schema}{name}",
    "capitalizeSchema": true,
    "capitalizeNames": true,
    "separator": "_"
  }
}

Supported config files:

  • supazod.config.ts (recommended)
  • supazod.config.js
  • supazod.config.json
  • .supazodrc.ts
  • .supazodrc.js
  • .supazodrc.json

CLI Options

supazod [options]

-i, --input <path>         Input TypeScript file
-o, --output <path>        Output Zod schemas file
-t, --types-output <path>  Output type definitions (optional)
-s, --schema <name>        Schema to process (optional, defaults to all)
--verbose                  Enable debug logs

# Naming Configuration (overrides config file)
--table-operation-pattern <pattern>    Pattern for table operations
--table-schema-pattern <pattern>       Pattern for table schema constants
--enum-pattern <pattern>               Pattern for enums  
--enum-schema-pattern <pattern>        Pattern for enum schema constants  
--function-args-pattern <pattern>      Pattern for function arguments
--function-args-schema-pattern <pattern>  Pattern for function arg schema constants
--function-returns-pattern <pattern>   Pattern for function returns
--function-returns-schema-pattern <pattern> Pattern for function return schema constants
--config <path>                        Path to a Supazod config file
--capitalize-schema <boolean>          Capitalize schema names
--capitalize-names <boolean>           Capitalize type names
--separator <string>                   Separator between name parts

Example with Custom Naming

# Generate with custom naming patterns
$ pnpm supazod -i types.ts -o schemas.ts \
  --table-operation-pattern '{schema}_{table}_{operation}' \
  --table-schema-pattern '{schema}{table}{operation}' \
  --enum-pattern '{schema}_{name}_Enum' \
  --enum-schema-pattern '{schema}{name}' \
  --separator '_'

Separating Type and Schema Names

For each naming pattern there is an optional companion for the generated Zod schema constants (for example tableSchemaPattern). Use these when you want custom suffixes on TypeScript types without affecting the schema identifiers that appear in schemas.ts.

Patterns now preserve any separators you include (like _ or -) in the emitted type aliases and schema constants, so you can rely on the exact formatting you configure.

Available Placeholders

  • {schema} - Database schema name (e.g., "public", "auth")
  • {table} - Table name (e.g., "users", "posts")
  • {operation} - Operation type ("Insert", "Update", "Row")
  • {function} - Function name (e.g., "get_status")
  • {name} - Type name (e.g., "user_status" for enums)

Features

  • 🎯 Complete Coverage: Full support for tables, views, enums, functions and composite types
  • 🔧 Multi-Schema: Process multiple database schemas with a single command
  • 📦 Type Declarations: Generate corresponding .d.ts files alongside Zod schemas
  • ⚙️ Type-Safe Configuration: TypeScript config with IntelliSense support
  • 🏷️ Flexible Naming: Customizable naming patterns with placeholders
  • Clean Output: Fixed schema naming (no more "SchemaSchema" duplication)

Programmatic API

import { generateContent } from 'supazod';

const result = await generateContent({
  input: './types.ts',
  output: './schema.ts',
  schema: ['public'],
  namingConfig: {
    tableOperationPattern: '{schema}_{table}_{operation}',
    enumPattern: '{schema}_{name}_Enum',
  }
});

Migration from v1.x

If upgrading from v1.x, see MIGRATION.md for detailed migration instructions. The main changes:

  • ✅ Fixed duplicated "Schema" suffixes (publicUsersInsertSchemaSchemapublicUsersInsertSchema)
  • ✅ Clean TypeScript type names (removed "Schema" suffix from types)
  • ✅ New type-safe configuration system

Credits

This project started as a fork of supabase-to-zod by @psteinroe. While maintaining the original concept, the codebase has been completely rewritten to provide better performance, enhanced type safety, and a more robust architecture. Thanks to psteinroe for the initial inspiration! 💚