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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@custom-generators/simple-prisma-dto-gen

v1.2.1

Published

Prisma generator for NestJS DTOs, enums and service scaffolding

Readme

Simple Prisma DTO Gen

Prisma generator focused on NestJS projects.

It generates:

  • DTO classes for Prisma models
  • Insert DTO classes
  • Enum files
  • A DatabaseGenService with CRUD helpers
  • An optional PrismaService
  • A model.json file with the Prisma DMMF

Scope

This package is not a generic Prisma code generator.

Current assumptions:

  • DTOs import @nestjs/swagger
  • The optional generated PrismaService imports @nestjs/common
  • The optional generated PrismaService uses @prisma/adapter-mariadb (or @prisma/adapter-postgresql)
  • The generated service layer is designed for NestJS-style usage

Because of that, the package fits best in NestJS + Prisma projects.

Generated Output

Given an output directory, the generator creates:

<output>/
  dtos/
  insert.dtos/
  enums/
  service/
    database.gen.ts
    prisma.service.ts   # only when generatePrismaService = true
  model.json

Installation

Install the generator and Prisma:

npm install --save-dev prisma @custom-generators/simple-prisma-dto-gen
npm install --save @prisma/client @nestjs/swagger

Install these only if you want the generated PrismaService for MariaDB/MySQL:

npm install --save @nestjs/common @prisma/adapter-mariadb mariadb dotenv

Install these only if you want the generated PrismaService for PostgreSQL:

npm install --save @nestjs/common @prisma/adapter-postgresql pg dotenv

Install this only if you want generated InsertDto classes to include class-validator decorators:

npm install --save class-validator class-transformer

Prisma Schema Configuration

Example schema.prisma:

generator client {
  provider   = "prisma-client"
  output     = "../src/generated/prisma"
  engineType = "library"
}

generator classGenerator {
  provider                     = "npx simple-prisma-dto-gen"
  output                       = "../src/gen.dto"
  customPrismaClientImportPath = "src/generated/prisma/client"
  generatePrismaService        = true
  databaseType                 = "postgresql"
  activeField                  = "active"
  useClassValidator            = "true"
}

Generator Options

  • output: target directory for generated files
  • customPrismaClientImportPath: import path used in generated service files
  • generatePrismaService: when true, generates service/prisma.service.ts; when false, DatabaseGenService depends directly on PrismaClient
  • databaseType: database adapter used by generated PrismaService; supported values are mariadb and postgresql
  • activeField: when set, generated findOne* and findMany* methods filter by this field set to true, and generated delete* methods perform soft delete by setting this field to false
  • useClassValidator: when true, generated InsertDto classes include class-validator decorators

If activeField is not configured, generated delete* methods call Prisma delete().

If databaseType is not configured, the generated PrismaService uses the MariaDB adapter.

JSON Fields

Prisma Json fields are generated with Prisma's own JSON types.

For regular DTOs:

payload: Prisma.JsonValue
metadata?: Prisma.JsonValue | null

For InsertDto classes:

payload: Prisma.InputJsonValue
metadata?: Prisma.InputJsonValue | Prisma.NullableJsonNullValueInput

Generated files import Prisma only when the model has at least one Json field:

import { Prisma } from "src/generated/prisma/client"

Swagger metadata for Json fields is generated as type: () => Object. JSON arrays also receive isArray: true.

Class Validator

When useClassValidator = "true", generated InsertDto classes include decorators from class-validator.

Example output:

import { ApiProperty } from "@nestjs/swagger"
import { IsNotEmpty, IsOptional, IsString } from "class-validator"

export class UserInsertDto {

  @ApiProperty()
  @IsString()
  @IsNotEmpty()
  name: string

  @ApiProperty({required: false, nullable: true})
  @IsOptional()
  @IsString()
  nickname?: string
}

Current validator mapping:

  • String: IsString; required strings without defaults also receive IsNotEmpty
  • Int and BigInt: IsInt
  • Float and Decimal: IsNumber
  • Boolean: IsBoolean
  • DateTime: IsDate
  • Json: IsObject for non-array fields
  • Enum: IsEnum
  • list fields: IsArray and item validation with each: true when applicable
  • optional fields and fields with defaults: IsOptional

Usage

Initialize Prisma if needed:

npx prisma init

Configure your database connection, then introspect or maintain your schema as usual:

npx prisma db pull

Run generators:

npx prisma generate

The provider value must be an executable command that Prisma can run. For this package, use the published bin command, not the npm package name. Using @custom-generators/simple-prisma-dto-gen directly will fail because Prisma tries to execute that exact string in the shell.

If you prefer, you can still use the explicit executable path as a fallback:

generator classGenerator {
  provider = "node node_modules/@custom-generators/simple-prisma-dto-gen/dist/bin.js"
}

Release

Before publishing, make sure you are logged in to npm:

npm login

Run the build locally:

npm run build

Update the package version with one of npm's version commands:

npm version patch

Use minor or major instead of patch when the release contains broader changes:

npm version minor
npm version major

Publish the package:

npm publish

The package is configured with:

{
  "files": [
    "dist"
  ],
  "prepublishOnly": "npm run build",
  "publishConfig": {
    "access": "public"
  }
}

Because of that, only the compiled dist directory is published, npm publish runs the build automatically before publishing, and the scoped package is published with public access.

After publishing, install or update the package in the consuming project:

npm install --save-dev @custom-generators/simple-prisma-dto-gen@latest

Then regenerate Prisma artifacts in the consuming project:

npx prisma generate

NestJS Integration

If you generate PrismaService, load environment variables before the Nest app bootstraps:

import 'dotenv/config'

Example wrapper service:

import { Injectable } from "@nestjs/common"
import { DatabaseGenService } from "./gen.dto/service/database.gen"
import { PrismaService } from "./gen.dto/service/prisma.service"

@Injectable()
export class DatabaseService extends DatabaseGenService {
  constructor(prisma: PrismaService) {
    super(prisma)
  }
}

Register services in your module:

providers: [DatabaseService, PrismaService]

Example

For a Prisma model like:

model User {
  id     Int     @id @default(autoincrement())
  name   String
  active Boolean @default(true)
}

The generator will produce files similar to:

  • dtos/user.dto.ts
  • insert.dtos/user.insert.dto.ts
  • service/database.gen.ts

And DatabaseGenService will include methods like:

  • findOneUser
  • findManyUser
  • createUser
  • updateUser
  • deleteUser

Limitations

  • The generated DTOs are tailored to NestJS Swagger usage
  • This package is intentionally opinionated and project-style driven