7.0.1 • Published 3 months ago

prisma-class-dto-generator v7.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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

5 months ago

6.0.1

6 months ago

6.0.0

6 months ago

6.3.0

5 months ago

6.0.3

6 months ago

6.0.2

6 months ago

6.5.0

4 months ago

6.4.1

4 months ago

6.3.2

4 months ago

6.0.5

6 months ago

6.4.0

4 months ago

6.3.1

5 months ago

6.0.4

6 months ago

7.0.0

3 months ago

7.0.1

3 months ago

6.5.2

4 months ago

6.0.7

5 months ago

6.5.1

4 months ago

6.4.2

4 months ago

6.0.6

5 months ago

6.4.5

4 months ago

6.4.4

4 months ago

6.0.8

5 months ago

5.0.2

11 months ago

5.0.0

1 year ago