Skip to content

Commit c10b49a

Browse files
authored
Merge pull request #22 from omar-dulaimi/feature/modernize-prisma-6
Modernize for Prisma 6 with comprehensive documentation and testing
2 parents 6845282 + c6a8121 commit c10b49a

18 files changed

+3803
-428
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
github: omar-dulaimi
2-
custom: ["https://www.buymeacoffee.com/omardulaimi"]

.github/workflows/ci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, feature/* ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [20.x, 22.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Build project
31+
run: npm run build
32+
33+
- name: Run type checking
34+
run: npm run test:type-check
35+
36+
- name: Check code formatting
37+
run: npm run format:check
38+
39+
- name: Run tests
40+
run: npm run test:ci
41+
42+
- name: Test with example schemas
43+
run: |
44+
npx prisma generate --schema=tests/schemas/basic.prisma
45+
npx prisma generate --schema=tests/schemas/comprehensive.prisma
46+
47+
package-test:
48+
runs-on: ubuntu-latest
49+
needs: test
50+
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
55+
- name: Setup Node.js
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: '20.x'
59+
cache: 'npm'
60+
61+
- name: Install dependencies
62+
run: npm ci
63+
64+
- name: Build and package
65+
run: |
66+
npm run build
67+
./package.sh
68+
69+
- name: Test package integrity
70+
run: |
71+
cd package
72+
npm pack --dry-run
73+
74+
- name: Upload package artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: package-build
78+
path: package/
79+
retention-days: 7

.github/workflows/release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- 'v*'
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
packages: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20.x'
25+
cache: 'npm'
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Build project
32+
run: npm run build
33+
34+
- name: Run tests
35+
run: npm run test:ci
36+
37+
- name: Determine release type and version
38+
id: release-info
39+
run: |
40+
if [[ $GITHUB_REF == refs/tags/* ]]; then
41+
# Tagged release
42+
echo "release_type=tagged" >> $GITHUB_OUTPUT
43+
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
44+
echo "npm_tag=latest" >> $GITHUB_OUTPUT
45+
echo "prerelease=false" >> $GITHUB_OUTPUT
46+
else
47+
# Auto release from master - use beta
48+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
49+
BETA_VERSION="${PACKAGE_VERSION}-beta.$(date +%Y%m%d%H%M%S)"
50+
echo "release_type=auto" >> $GITHUB_OUTPUT
51+
echo "version=v${BETA_VERSION}" >> $GITHUB_OUTPUT
52+
echo "npm_tag=beta" >> $GITHUB_OUTPUT
53+
echo "prerelease=true" >> $GITHUB_OUTPUT
54+
55+
# Update package.json version for beta
56+
npm version $BETA_VERSION --no-git-tag-version
57+
fi
58+
59+
- name: Build package
60+
run: ./package.sh
61+
62+
- name: Publish to npm
63+
run: |
64+
cd package
65+
npm publish --tag ${{ steps.release-info.outputs.npm_tag }}
66+
env:
67+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
68+
69+
- name: Create GitHub Release
70+
uses: actions/create-release@v1
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
with:
74+
tag_name: ${{ steps.release-info.outputs.version }}
75+
release_name: Release ${{ steps.release-info.outputs.version }}
76+
body: |
77+
${{ steps.release-info.outputs.release_type == 'auto' && '🧪 **Beta Release** - Automatically generated from latest master branch' || 'Stable release' }}
78+
79+
## Changes
80+
See the [full changelog](https://github.com/omar-dulaimi/prisma-class-validator-generator/compare/v5.0.0...${{ steps.release-info.outputs.version }}) for details.
81+
draft: false
82+
prerelease: ${{ steps.release-info.outputs.prerelease == 'true' }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
lib
33
package
44
npm-debug.log*
5-
prisma/generated
5+
prisma/generated
6+
coverage/
7+
tests/generated/

.prettierignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
lib/**/*
2-
package/**/*
2+
package/**/*
3+
node_modules/
4+
prisma/generated/
5+
tests/generated/
6+
*.md
7+
*.json

CLAUDE.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

Comments
 (0)