|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to when working with code in this repository. |
| 4 | + |
| 5 | +## Common Development Commands |
| 6 | + |
| 7 | +### Build and Development |
| 8 | +- `npm run build` - Compile TypeScript source files from src/ to lib/ |
| 9 | +- `npm run start` - Build and run Prisma generate (builds lib/ directory and generates models) |
| 10 | +- `npx prisma generate` - Generate class validator models using the local generator |
| 11 | + |
| 12 | +### Testing |
| 13 | +- `npm test` - Run tests in watch mode |
| 14 | +- `npm run test:ci` - Run tests once with coverage for CI |
| 15 | +- `npm run test:coverage` - Run tests with coverage report |
| 16 | +- `npm run test:type-check` - Run TypeScript type checking without emitting files |
| 17 | + |
| 18 | +### Code Quality |
| 19 | +- `npm run format` - Format code with Prettier |
| 20 | +- `npm run format:check` - Check if code is formatted correctly |
| 21 | + |
| 22 | +### Publishing |
| 23 | +- `npm run package:publish` - Build package and publish to npm (runs package.sh script) |
| 24 | + |
| 25 | +### Testing Generator Locally |
| 26 | +- Use test schemas in tests/schemas/ with `npx prisma generate --schema=tests/schemas/basic.prisma` |
| 27 | +- Generated models appear in tests/generated/ directory for testing |
| 28 | +- Main example in prisma/schema.prisma generates to prisma/generated/models/ |
| 29 | + |
| 30 | +## Architecture Overview |
| 31 | + |
| 32 | +This is a Prisma generator that creates TypeScript class validator models from Prisma schema definitions. The generator integrates with Prisma's generation pipeline to automatically create class-validator decorated TypeScript classes. |
| 33 | + |
| 34 | +### Core Architecture |
| 35 | +- **Entry Point**: `src/index.ts` - Sets up the Prisma generator handler |
| 36 | +- **Main Generator**: `src/prisma-generator.ts` - Orchestrates the generation process |
| 37 | +- **Class Generation**: `src/generate-class.ts` - Creates individual model classes with decorators |
| 38 | +- **Enum Generation**: `src/generate-enum.ts` - Handles Prisma enum generation |
| 39 | +- **Helpers**: `src/helpers.ts` - Utility functions for decorators, imports, and type mapping |
| 40 | + |
| 41 | +### Generation Flow |
| 42 | +1. Generator reads Prisma DMMF (Data Model Meta Format) |
| 43 | +2. Creates output directory structure (models/, enums/, helpers/) |
| 44 | +3. Generates class validator decorators based on Prisma field types |
| 45 | +4. Creates TypeScript classes with proper imports and type definitions |
| 46 | +5. Generates index files for easy importing |
| 47 | + |
| 48 | +### Key Components |
| 49 | +- **Field Type Mapping**: Maps Prisma types to TypeScript types and class-validator decorators |
| 50 | +- **Relation Handling**: Manages model relationships and circular import resolution |
| 51 | +- **Decorator Generation**: Applies appropriate class-validator decorators (@IsString, @IsInt, etc.) |
| 52 | +- **Project Structure**: Uses ts-morph for TypeScript AST manipulation |
| 53 | + |
| 54 | +### Output Structure |
| 55 | +``` |
| 56 | +generated/ |
| 57 | +├── models/ |
| 58 | +│ ├── User.model.ts |
| 59 | +│ ├── Post.model.ts |
| 60 | +│ └── index.ts |
| 61 | +├── enums/ |
| 62 | +│ └── index.ts |
| 63 | +└── helpers/ |
| 64 | + └── index.ts |
| 65 | +``` |
| 66 | + |
| 67 | +The generator is configured via Prisma schema: |
| 68 | +```prisma |
| 69 | +generator class_validator { |
| 70 | + provider = "prisma-class-validator-generator" |
| 71 | + output = "./generated" // optional, defaults to ./generated |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## Modern Development Setup (Prisma 6+) |
| 76 | + |
| 77 | +### Key Changes in Prisma 6 |
| 78 | +- **Bytes fields**: Now generate `Uint8Array` instead of `Buffer` (breaking change handled) |
| 79 | +- **Node.js requirements**: Minimum Node 18.18+, 20.9+, or 22.11+ |
| 80 | +- **TypeScript**: Minimum version 5.1.0, using 5.8.3 |
| 81 | + |
| 82 | +### Testing Infrastructure |
| 83 | +- **Vitest**: Modern test runner with coverage support |
| 84 | +- **Test Schemas**: Multiple schema files in tests/schemas/ for different scenarios |
| 85 | +- **CI/CD**: GitHub Actions with Node 18/20/22 matrix testing |
| 86 | +- **Automated Releases**: Tag-based releases to npm with GitHub releases |
| 87 | + |
| 88 | +### Code Quality Tools |
| 89 | +- **Prettier**: Consistent code formatting |
| 90 | +- **TypeScript strict mode**: Enhanced type safety |
| 91 | +- **Coverage reporting**: Comprehensive test coverage tracking |
0 commit comments