Registry / database / prisma-class-generator

prisma-class-generator

JSON →
library0.2.11jsnpmunverified

A Prisma generator that creates TypeScript class definitions from your Prisma schema, primarily for use with NestJS decorators like @nestjs/swagger and TypeGraphQL. Current version 0.2.11 generates per-model classes with optional separate relational fields. It integrates into the Prisma generate workflow, automatically producing classes that mirror the Prisma model structure. Key differentiator: bridges Prisma's type-only output with NestJS's class- and decorator-based ecosystem, reducing boilerplate when using swagger or GraphQL decorators. Release cadence is sporadic, last updated 2021.

npm install prisma-class-generator
INSTALL
IMPORT
SIG · PRISMA-CLASS-GENER
P
prisma-class-generator
databasejavascriptv0.2.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Product
import { Product } from './generated/prisma-class-generator/product'
import { Product } from '@prisma/client'
Generated classes are output to a default directory; adjust path based on your output setting.
ProductRelations
import { ProductRelations } from './generated/prisma-class-generator/product_relations'
Only generated if separateRelationFields option is true.
PrismaClassGenerator (generator block)
generator prismaClassGenerator { provider = "prisma-class-generator" }
generator prisma_class_generator { provider = "prisma-class-generator" }
The generator name must be 'prismaClassGenerator' (no hyphens or underscores).

Demonstrates adding the generator to schema.prisma, generating classes, and using a generated class in a NestJS DTO with swagger decorators.

// schema.prisma generator prismaClassGenerator { provider = "prisma-class-generator" } model Product { id Int @id @default(autoincrement()) title String @db.VarChar(255) price Float? } // Run: npx prisma generate // Output: generated/prisma-class-generator/product.ts export class Product { id: number; title: string; price: number | null; } // Use in NestJS: import { Product } from './generated/prisma-class-generator/product'; import { ApiProperty } from '@nestjs/swagger'; // Decorate if needed export class ProductDto extends Product { @ApiProperty({ type: Number }) declare id: number; @ApiProperty({ type: String }) declare title: string; @ApiProperty({ type: Number, required: false }) declare price: number | null; }
Debug
Known issues
gotchaGenerator does not automatically update on schema changes; you must re-run 'npx prisma generate' after each schema modification.
fix
Run 'npx prisma generate' after editing schema.prisma.
affects: >=0.0.0
breakingGenerated class names may conflict with existing Prisma client types if not using a separate output directory.
fix
Configure output path in generator options, e.g., output = "../src/generated/classes".
affects: >=0.0.0
gotchaThe generator does not handle composite types or unsupported Prisma features; models with unsupported field types may be skipped or generate incorrectly.
fix
Check generated files for completeness; manually define classes for models with unsupported types.
affects: >=0.0.0
deprecatedThe 'separateRelationFields' option was added in v0.2.0; earlier versions always generate a single class per model.
fix
Upgrade to version 0.2.0 or later to use separateRelationFields option.
affects: >=0.0.0 <0.2.0
gotchaGenerated classes do not include Prisma's built-in validation or type transformations; they are plain TypeScript classes.
fix
Add custom validation (e.g., class-validator decorators) as needed.
affects: >=0.0.0
Errors
Common errors & fixes
Generator "prisma-class-generator" not found.
Missing npm install or incorrect generator name in schema.prisma.
fix
Install the package: npm install prisma-class-generator. Ensure generator block uses 'provider = "prisma-class-generator"'.
Error: Could not find prisma-class-generator. Please install it.
The generator is not installed or not in node_modules.
fix
Run 'npm install prisma-class-generator' in your project.
Cannot find module './generated/prisma-class-generator/product'
Output directory path mismatch in import statement.
fix
Adjust import path to match the actual generated file location, check generator output option.
Class 'Product' incorrectly extends base class 'Product' (Property 'id' is private in 'Product').
Using 'declare' on inherited properties without proper visibility; NestJS DTO patterns may conflict.
fix
Use 'declare' keyword or re-define properties with public access modifier.
Unknown type 'Json' in schema. (JSON fields require special handling)
Prisma JSON fields generate as 'any' or 'Prisma.JsonValue'; class generator may not handle them correctly.
fix
Manually define Json field type as 'Prisma.JsonValue' or use a wrapper type.
Upgrade
Version history
0.2.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
prisma-class-generator — npm install prisma-class-generator · libregistry