{"_id":"@alexcatdad/prisma-dto-generator","_rev":"2-7b11423d382a6f483601bcc3f59ca819","name":"@alexcatdad/prisma-dto-generator","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.4":{"name":"@alexcatdad/prisma-dto-generator","version":"0.0.4","keywords":["prisma","generator","nestjs","dto","swagger","openapi"],"author":{"name":"Alex Alexandrescu","email":"github@escu.dev"},"license":"MIT","_id":"@alexcatdad/prisma-dto-generator@0.0.4","maintainers":[{"name":"alexcatdad","email":"github@escu.dev"}],"homepage":"https://github.com/alexcatdad/prisma-dto-generator#readme","bugs":{"url":"https://github.com/alexcatdad/prisma-dto-generator/issues"},"bin":{"prisma-dto-generator":"dist/index.js"},"dist":{"shasum":"5b50025b7ad5305657f5fbacbe5584f924b5dace","tarball":"https://registry.npmjs.org/@alexcatdad/prisma-dto-generator/-/prisma-dto-generator-0.0.4.tgz","fileCount":27,"integrity":"sha512-8FtrpHd1Fqr/o0WhmGtARqzR/5l+4Zg3FSNCam//telDIX9sYVqHU7/klAUYzRzxaQzlzYZlGDa5a7zL9KAAPg==","signatures":[{"sig":"MEYCIQCGJSIkSrPoqsNh6fTDE9FzPxIPKRyZeVW8nEG+fZy4qgIhALVmqZfZN1tH1OcDyrRspT0D030HNyL9zoE8HQQAMalc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":70586},"main":"dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=18.12"},"gitHead":"65e9f6470242e52091726794bd01b157dfbc366f","scripts":{"dev":"tsc --watch","lint":"biome check .","test":"jest","build":"tsc","format":"biome format --write .","preversion":"pnpm test","test:coverage":"jest --coverage","prepublishOnly":"pnpm build"},"_npmUser":{"name":"alexcatdad","email":"github@escu.dev"},"repository":{"url":"git+https://github.com/alexcatdad/prisma-dto-generator.git","type":"git"},"_npmVersion":"11.6.2","description":"Prisma generator for NestJS DTOs with Swagger support","directories":{},"_nodeVersion":"24.11.0","dependencies":{"@prisma/internals":"^6.16.3","@prisma/generator-helper":"^6.16.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.9.3","@types/jest":"^29.5.12","@types/node":"^24.6.1","@biomejs/biome":"^1.9.4"},"_npmOperationalInternal":{"tmp":"tmp/prisma-dto-generator_0.0.4_1763516460707_0.5192843833294871","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@alexcatdad/prisma-dto-generator","version":"0.0.5","description":"Prisma generator for NestJS DTOs with Swagger support","main":"dist/index.js","bin":{"prisma-dto-generator":"dist/index.js"},"scripts":{"build":"tsc","dev":"tsc --watch","test":"jest","test:coverage":"jest --coverage","lint":"biome check .","format":"biome format --write .","prepublishOnly":"pnpm build","preversion":"pnpm test"},"keywords":["prisma","generator","nestjs","dto","swagger","openapi"],"author":{"name":"Alex Alexandrescu","email":"github@escu.dev"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alexcatdad/prisma-dto-generator.git"},"homepage":"https://github.com/alexcatdad/prisma-dto-generator#readme","bugs":{"url":"https://github.com/alexcatdad/prisma-dto-generator/issues"},"engines":{"node":">=18.12"},"publishConfig":{"access":"public"},"dependencies":{"@prisma/generator-helper":"^6.16.3","@prisma/internals":"^6.16.3"},"devDependencies":{"@biomejs/biome":"^1.9.4","@types/jest":"^29.5.12","@types/node":"^24.6.1","jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.9.3"},"gitHead":"939b6dbef814af11cc03c7b75797ba8a2d70a48e","types":"./dist/index.d.ts","_id":"@alexcatdad/prisma-dto-generator@0.0.5","_nodeVersion":"24.11.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-noW2eqr+qB4aZ9HqHASYXN8zubk+S8VEB3DAOCS3oBq5mrDqjl4MimAuz7rrxcOl9f/qI06307pHap+XgeYGjg==","shasum":"df2547d8d1d11c8d2036fb6f5e5f9dbd4c08a7b5","tarball":"https://registry.npmjs.org/@alexcatdad/prisma-dto-generator/-/prisma-dto-generator-0.0.5.tgz","fileCount":27,"unpackedSize":70677,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCRJhe2NGFNJjulPuyFamQw+eveX1zb0+0LQ1tDcZECGAIgWq6FBVftNXiPVjGTV9427xtCsNwgVXh0c5r74q+LdWA="}]},"_npmUser":{"name":"alexcatdad","email":"github@escu.dev"},"directories":{},"maintainers":[{"name":"alexcatdad","email":"github@escu.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prisma-dto-generator_0.0.5_1763516752944_0.6926598892848344"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-19T01:41:00.561Z","modified":"2025-11-19T01:45:53.336Z","0.0.4":"2025-11-19T01:41:00.945Z","0.0.5":"2025-11-19T01:45:53.137Z"},"bugs":{"url":"https://github.com/alexcatdad/prisma-dto-generator/issues"},"author":{"name":"Alex Alexandrescu","email":"github@escu.dev"},"license":"MIT","homepage":"https://github.com/alexcatdad/prisma-dto-generator#readme","keywords":["prisma","generator","nestjs","dto","swagger","openapi"],"repository":{"type":"git","url":"git+https://github.com/alexcatdad/prisma-dto-generator.git"},"description":"Prisma generator for NestJS DTOs with Swagger support","maintainers":[{"name":"alexcatdad","email":"github@escu.dev"}],"readme":"# @alexcatdad/prisma-dto-generator\n\n[![npm version](https://img.shields.io/npm/v/@alexcatdad/prisma-dto-generator.svg)](https://www.npmjs.com/package/@alexcatdad/prisma-dto-generator)\n[![npm downloads](https://img.shields.io/npm/dm/@alexcatdad/prisma-dto-generator.svg)](https://www.npmjs.com/package/@alexcatdad/prisma-dto-generator)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/alexalexandrescu/prisma-dto-generator/main/coverage.json)\n\nA Prisma generator that automatically creates NestJS DTOs (Data Transfer Objects) with Swagger/OpenAPI decorators from your Prisma schema.\n\n## Features\n\n- 🎯 **Automatic DTO Generation**: Generates Create, Update, and Read DTOs for all Prisma models\n- 📝 **Swagger Integration**: Automatically adds Swagger decorators for OpenAPI documentation\n- ✅ **Validation**: Includes class-validator decorators for type-safe validation\n- 🔗 **Relation Handling**: Configurable handling of Prisma relations (omit, ids, or nested)\n- 📁 **Domain Structure**: Optional domain-based folder organization\n- 🔤 **Enum Support**: Generates TypeScript enums from Prisma enums\n- 🎨 **Customizable**: Extensive configuration options for different use cases\n\n## Inspiration\n\nThis package is heavily inspired by:\n- [@brakebein/prisma-generator-nestjs-dto](https://www.npmjs.com/package/@brakebein/prisma-generator-nestjs-dto)\n- [prisma-generator-nestjs-dto](https://www.npmjs.com/package/prisma-generator-nestjs-dto)\n\nHowever, these packages did not work in some projects due to changes in the latest Prisma and NestJS versions. This package was created as a simplified, modern alternative that works with current versions of Prisma (v6+) and NestJS (v10+).\n\n## Installation\n\n```bash\n# npm\nnpm install --save-dev @alexcatdad/prisma-dto-generator\n\n# yarn\nyarn add -D @alexcatdad/prisma-dto-generator\n\n# pnpm\npnpm add -D @alexcatdad/prisma-dto-generator\n\n# bun\nbun add -d @alexcatdad/prisma-dto-generator\n```\n\n## Quick Start\n\n1. Add the generator to your `schema.prisma`:\n\n```prisma\ngenerator nestdto {\n  provider = \"@alexcatdad/prisma-dto-generator\"\n  output   = \"./dto\"\n}\n```\n\n2. Run Prisma generate:\n\n```bash\n# npm\nnpx prisma generate\n\n# yarn\nyarn prisma generate\n\n# pnpm\npnpm prisma generate\n\n# bun\nbunx prisma generate\n```\n\n3. Use the generated DTOs in your NestJS controllers:\n\n```typescript\nimport { CreateUserDto } from './dto/create-user.dto'\nimport { UpdateUserDto } from './dto/update-user.dto'\n\n@Controller('users')\nexport class UserController {\n  @Post()\n  create(@Body() createUserDto: CreateUserDto) {\n    // ...\n  }\n\n  @Patch(':id')\n  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {\n    // ...\n  }\n}\n```\n\n## Configuration\n\n### Basic Configuration\n\n```prisma\ngenerator nestdto {\n  provider        = \"@alexcatdad/prisma-dto-generator\"\n  output          = \"./dto\"\n  emitBarrel      = \"true\"           // Generate index.ts barrel file\n  relations       = \"ids\"             // How to handle relations: \"omit\" | \"ids\" | \"nested\"\n  folderStructure = \"flat\"            // \"flat\" | \"domain\"\n  heuristics      = \"true\"            // Apply smart field type detection\n  clean           = \"true\"            // Clean output directory before generation\n}\n```\n\n### Advanced Configuration\n\n```prisma\ngenerator nestdto {\n  provider        = \"@alexcatdad/prisma-dto-generator\"\n  output          = \"./dto\"\n  folderStructure = \"domain\"\n  domainMapping   = \"./dto-domain-mapping.json\"\n  dateStrategy    = \"iso-string\"      // \"iso-string\" | \"date\"\n  jsonType        = \"Record<string, unknown>\"\n  fileNaming      = \"kebab\"           // \"kebab\" | \"camel\" | \"pascal\"\n  omitFields      = \"{\\\"User\\\": [\\\"password\\\", \\\"secretKey\\\"]}\"\n  readDtoInclude  = \"{\\\"User\\\": [\\\"profile\\\", \\\"posts\\\"]}\"\n}\n```\n\n## Configuration Options\n\n### `emitBarrel` (boolean, default: `true`)\n\nGenerate an `index.ts` barrel file that exports all DTOs.\n\n### `relations` (`\"omit\" | \"ids\" | \"nested\"`, default: `\"ids\"`)\n\nHow to handle Prisma relations in DTOs:\n\n- **`omit`**: Exclude all relation fields\n- **`ids`**: Include only the foreign key IDs (e.g., `userId: string`)\n- **`nested`**: Include nested relation objects\n\n### `folderStructure` (`\"flat\" | \"domain\"`, default: `\"flat\"`)\n\n- **`flat`**: All DTOs in a single directory\n- **`domain`**: Organize DTOs by domain (requires `domainMapping`)\n\n### `domainMapping` (JSON string or file path, optional)\n\nMap Prisma models to domain folders. You can provide this in two ways:\n\n**Option 1: JSON file (Recommended for better DX)**\n\nCreate a `dto-domain-mapping.json` file:\n\n```json\n{\n  \"User\": \"users/user\",\n  \"Post\": \"content/post\",\n  \"Comment\": \"content/comment\"\n}\n```\n\nThen reference it in your schema:\n\n```prisma\ngenerator nestdto {\n  provider        = \"@alexcatdad/prisma-dto-generator\"\n  output          = \"./dto\"\n  folderStructure = \"domain\"\n  domainMapping   = \"./dto-domain-mapping.json\"\n}\n```\n\n**Option 2: Inline JSON string**\n\n```prisma\ndomainMapping = \"{\\\"User\\\": \\\"users/user\\\", \\\"Post\\\": \\\"content/post\\\", \\\"Comment\\\": \\\"content/comment\\\"}\"\n```\n\n**Note**: Domain mappings are optional and must be explicitly provided. There are no built-in defaults, making the package generic for any project.\n\n### `dateStrategy` (`\"iso-string\" | \"date\"`, default: `\"iso-string\"`)\n\n- **`iso-string`**: Use `string` type with ISO date format\n- **`date`**: Use TypeScript `Date` type\n\n### `jsonType` (string, default: `\"Record<string, unknown>\"`)\n\nTypeScript type for Prisma `Json` fields.\n\n### `fileNaming` (`\"kebab\" | \"camel\" | \"pascal\"`, default: `\"kebab\"`)\n\nNaming convention for generated DTO files:\n- `kebab`: `create-user.dto.ts`\n- `camel`: `createUser.dto.ts`\n- `pascal`: `CreateUser.dto.ts`\n\n### `heuristics` (boolean, default: `true`)\n\nApply smart field type detection:\n- Fields containing \"email\" → `@IsEmail()`\n- Fields containing \"url\" → `@IsUrl()`\n- Fields ending with \"Id\" → `@IsUUID()`\n\n### `omitFields` (JSON string, optional)\n\nExclude specific fields from Create/Update DTOs. Format: `{\"ModelName\": [\"field1\", \"field2\"]}`\n\n### `readDtoInclude` (JSON string, optional)\n\nInclude specific relation fields in Read DTOs. Format: `{\"ModelName\": [\"relation1\", \"relation2\"]}`\n\n### `clean` (boolean, default: `false`)\n\nRemove all files in the output directory before generation.\n\n## Generated DTO Structure\n\n### CreateDTO\n\nContains all fields required for creating a new entity (excluding `id`, `createdAt`, `updatedAt`).\n\n### UpdateDTO\n\nExtends `PartialType(CreateDTO)` from `@nestjs/swagger`, making all fields optional.\n\n### ReadDTO\n\nContains all fields including `id`, `createdAt`, `updatedAt`, and optionally nested relations.\n\n## Domain-Based Folder Structure\n\nWhen using `folderStructure = \"domain\"` with `domainMapping`, DTOs are organized like:\n\n```\ndto/\n  users/\n    user/\n      create-user.dto.ts\n      update-user.dto.ts\n      read-user.dto.ts\n  content/\n    post/\n      create-post.dto.ts\n      update-post.dto.ts\n      read-post.dto.ts\n```\n\n## Examples\n\nSee the `examples/` directory for:\n\n- **Basic**: Simple setup with minimal configuration\n- **Advanced**: Complex schema with relations, enums, and custom mappings\n- **NestJS Integration**: Full controller and service examples\n\n## Requirements\n\n- Node.js >= 16\n- Prisma >= 6.0.0\n- NestJS >= 10.0.0\n- TypeScript >= 5.0.0\n\n## Dependencies\n\nThe generated DTOs require:\n\n- `@nestjs/swagger`\n- `class-validator`\n- `class-transformer`\n\nInstall them:\n\n```bash\n# npm\nnpm install @nestjs/swagger class-validator class-transformer\n\n# yarn\nyarn add @nestjs/swagger class-validator class-transformer\n\n# pnpm\npnpm add @nestjs/swagger class-validator class-transformer\n\n# bun\nbun add @nestjs/swagger class-validator class-transformer\n```\n\n## Troubleshooting\n\n### DTOs not generating\n\n- Ensure the generator is added to `schema.prisma`\n- Run `npx prisma generate` (or `yarn prisma generate`, `pnpm prisma generate`, `bunx prisma generate`)\n- Check the output path is correct\n\n### Domain mappings not working\n\n- Verify `folderStructure = \"domain\"` is set\n- Ensure `domainMapping` is valid JSON string\n- Check model names match your Prisma schema exactly (case-sensitive)\n\n### Missing decorators\n\n- Ensure `@nestjs/swagger`, `class-validator`, and `class-transformer` are installed\n- Check that your NestJS version supports the decorators used\n\n### Type errors\n\n- Ensure all dependencies are installed\n- Run `npx prisma generate` (or `yarn prisma generate`, `pnpm prisma generate`, `bunx prisma generate`) after schema changes\n- Check TypeScript version compatibility\n\n## License\n\nMIT\n\n## Contributing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md) for development guidelines.\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md) for version history.\n\n","readmeFilename":"README.md"}