1.0.1 • Published 6 months ago
@whoisarpit/supabase-to-zod v1.0.1
Supabase to Zod Type Generator
Supabase to Zod Type Generator is a tool that automatically converts Supabase TypeScript type definitions into Zod schemas.
Prerequisites
- Node.js (v18+)
- npm or pnpm
- Supabase CLI
Installation
# Using npm
npm install --save-dev @whoisarpit/supabase-to-zod
# Using pnpm
pnpm add -D @whoisarpit/supabase-to-zod
Usage
CLI
# Generate Zod schemas from default types_db.ts
supabase-to-zod
# Specify custom input file
supabase-to-zod -i ./custom-types.ts
# Specify output file
supabase-to-zod -o ./zod-schemas.ts
# Pipe Supabase generated types
supabase gen types | supabase-to-zod
# Pipe with custom output
supabase gen types | supabase-to-zod -o ./zod-schemas.ts
CLI Options
-i, --input
: Input TypeScript file (optional, default:./types_db.ts
)-o, --output
: Output Zod schemas file (optional, defaults to stdout)-h, --help
: Show help message
Programmatic Usage
import { generateZodSchemas } from "@whoisarpit/supabase-to-zod";
// From file
generateZodSchemas(fileContents, "./types_db.zod.ts");
// From string
const schemas = await generateZodSchemas(typeDefinitionString);
console.log(schemas);
Development
# Clone the repository
git clone https://github.com/whoisarpit/supabase-to-zod.git
cd supabase-to-zod
# Install dependencies
pnpm install
# Run development script
pnpm dev
Scripts
pnpm build
: Compile TypeScriptpnpm dev
: Run the type generator
Publishing
Versioning Commands
pnpm release:patch
: Increment patch versionpnpm release:minor
: Increment minor versionpnpm release:major
: Increment major versionpnpm prerelease:beta
: Create a beta prerelease version
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the ISC License.