prisma-fastify-typebox-generator
v3.0.0
Published
Generate TypeBox schemas from your Prisma schema. Create type-safe, runtime-validated schemas for your Fastify or other TypeScript applications.
Maintainers
Readme
Prisma TypeBox Generator
🎮 Interactive Playground
Try out the generator and build your configuration interactively at prisma-typebox-generator.netlify.app
⚡ Prisma Schema Generator for TypeBox
This package generates TypeBox schemas from your Prisma schema, enabling type-safe runtime validation for your Fastify or other TypeScript applications.
🔹 Requirements
- Node.js >= 18.19.0
- Prisma >= 6.6.0
- TypeScript >= 5.7.2
🚀 Installation
npm install prisma-fastify-typebox-generator🔧 Usage
You can use prisma-fastify-typebox-generator in two ways:
CLI Mode
npx prisma-fastify-typebox-generator --path=./prisma/schema.prisma --output=./typebox-schemasor install globally:
npm install -g prisma-fastify-typebox-generator
prisma-fastify-typebox-generator --path=./prisma/schema.prisma --output=./typebox-schemasAvailable CLI Options
Usage: prisma-fastify-typebox-generator --path=[path_to_schema]
Options:
--help, -h Show this help message
--version, -v Show the installed version
--path=[path] Specify a Prisma schema file (default: ./prisma/schema.prisma)
--output=[path] Specify the output directory (default: ./typebox-schemas)
--configFile=[path] Generate an empty configuration file at the specified pathProgrammatic Usage
import { generate } from "prisma-fastify-typebox-generator";
await generate({
cwd: process.cwd(),
schemaPath: "./prisma/schema.prisma",
output: "./typebox-schemas"
});📌 Features
- Type-Safe Schemas – Generate TypeBox schemas with runtime validation
- ESM Support – Fully compatible with modern Node.js environments
- Fastify Integration – Perfect for Fastify applications using TypeBox
- Automated Schema Generation – Creates TypeBox schemas for each Prisma model
- List Schemas – Supports pagination, filters, sorting, and flexible array elements
- Enum Handling – Generates enums from the Prisma schema
- Selective Generation – Fine-grained control over which models and fields to include
- Custom Directives – Supports
@filterable,@exclude input|output,@listable, and@orderableannotations
🔧 Configuration
The tool allows configuring schema generation via a JSON file. You can generate an empty configuration file using the --configFile option:
npx prisma-fastify-typebox-generator --configFileExample configuration:
{
"input": {
"extendModels": {
"Item": {
"fields": [
{ "name": "title", "isRequired": false }
]
}
}
}
}🔗 Links & Resources
- GitHub Repository: unbywyd/prisma-fastify-typebox-generator
- NPM Package: prisma-fastify-typebox-generator
📌 Author
Developed by Artyom Gorlovetskiy.
