7.0.1 • Published 9 months ago

prisma-class-dto-generator v7.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Prisma Class DTO Generator (v7.0.0+)

NPM Version GitHub Stars

⚔ Prisma DTO Generator – CLI & Programmatic Usage

ā—šŸ”“ā— Starting from version 7.0.0, prisma-class-dto-generator is no longer a Prisma generator but a standalone CLI tool and library that can be used independently. The package has been migrated to ESM (ECMAScript Modules) with NextNode to ensure compatibility with modern Node.js environments.

New: Prisma DTO Generator UI Constructor is an intuitive UI tool that helps generate DTO configurations for Prisma without manual edits. Define your settings visually, export a generator-config.json, and seamlessly integrate DTO generation into your workflow.

šŸ”¹ How It Works

You can use prisma-class-dto-generator in two ways: 1. CLI Mode – Run from the command line. 2. Programmatic Mode – Import and execute within your Node.js application.

šŸš€ CLI Usage

npx prisma-class-dto-generator --path=./prisma/schema.prisma --output=./dto_generated

or install globally:

npm install -g prisma-class-dto-generator
prismadtogen --path=./prisma/schema.prisma --output=./dto_generated

šŸŽ› Available CLI Options

Usage: prismadtogen --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: ./dto_generated)

šŸŽÆ Why Use It?

āœ… Standalone & Flexible – Not tied to Prisma's generator system. āœ… ESM & NextNode Support – Fully compatible with modern Node.js environments. āœ… Error-Free DTO Generation – Automates repetitive DTO creation. āœ… Consistent & Maintainable – Ensures uniform DTO structures.


šŸ“¦ Programmatic Usage

You can also use it inside a Node.js project:

import { generate } from "prisma-class-dto-generator";

await generate({
  cwd: process.cwd(),
  schemaPath: "./prisma/schema.prisma",
  output: "./dto_generated"
});

šŸ“Œ Features

  • Automated DTO Generation – Creates input/output DTO classes for each Prisma model.
  • List DTOs – 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 Decorators – Supports @filterable, @exclude input|output, @listable, and @orderable annotations.
  • File Type Support – Includes @IsFile and @IsFiles decorators for file uploads.
  • Lazy Imports for Deep Type Integration – Enables modular DTO architecture.
  • Class-Validator & OpenAPI Integration – Works seamlessly with class-validator, class-transformer, and routing-controllers-openapi.

šŸ›  Installation

npm install prisma-class-dto-generator

or

yarn add prisma-class-dto-generator

šŸ”§ Configuration

The tool allows configuring DTO generation via a JSON file:

{
  "input": {
    "extendModels": {
      "Item": {
        "fields": [
          { "name": "title", "isRequired": false }
        ]
      }
    }
  }
}

šŸ“„ Example Prisma Schema Configuration

To integrate with Prisma, add a generator entry in schema.prisma:

generator class_validator {
  provider   = "node node_modules/prisma-class-dto-generator"
  output     = "../src/dto_sources"
  configPath = "./"
}

šŸ”— Links & Resources

šŸ“Œ Author

Developed by unbywyd.

6.1.0

10 months ago

6.0.1

11 months ago

6.0.0

11 months ago

6.3.0

10 months ago

6.0.3

11 months ago

6.0.2

11 months ago

6.5.0

9 months ago

6.4.1

9 months ago

6.3.2

9 months ago

6.0.5

11 months ago

6.4.0

9 months ago

6.3.1

10 months ago

6.0.4

11 months ago

7.0.0

9 months ago

7.0.1

9 months ago

6.5.2

9 months ago

6.0.7

11 months ago

6.5.1

9 months ago

6.4.2

9 months ago

6.0.6

11 months ago

6.4.5

9 months ago

6.4.4

9 months ago

6.0.8

10 months ago

5.0.2

1 year ago

5.0.0

1 year ago