Skip to content

Commit e1fb55b

Browse files
authored
Merge pull request #23 from Isqanderm/feature/22-validation-jit
feat: Add high-performance validation with JIT compilation (MVP) This PR implements a comprehensive validation system with: - JIT compilation engine (70-909x faster than baseline) - 30+ validation decorators (class-validator compatible) - 518 tests with 95.08% statement coverage - Property-based testing (~2,000 random checks) - Benchmark tests (performance validation) - Memory leak tests (no leaks detected) - Integration tests (5 real-world scenarios) Closes #22
2 parents fe699c7 + 4d6cae6 commit e1fb55b

120 files changed

Lines changed: 27728 additions & 7365 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.augment/rules/rule-release.md

Lines changed: 781 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/benchmark.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ jobs:
4848
npm run bench:compat > benchmark-compat.txt 2>&1 || echo "Comparison benchmark failed" > benchmark-compat.txt
4949
cat benchmark-compat.txt
5050
51+
- name: Run class-validator comparison benchmark
52+
run: |
53+
npm run bench:validation > benchmark-validation.txt 2>&1 || echo "Validation benchmark failed" > benchmark-validation.txt
54+
cat benchmark-validation.txt
55+
5156
- name: Run simple benchmark
5257
continue-on-error: true
5358
run: |
@@ -72,6 +77,12 @@ jobs:
7277
echo "Benchmark results for tracking:"
7378
cat bench-results.json
7479
80+
- name: Generate JSON validation benchmark results
81+
run: |
82+
node benchmarks/suites/compat/validation-comparison-json.js > bench-validation-results.json 2>&1 || echo "[]" > bench-validation-results.json
83+
echo "Validation benchmark results for tracking:"
84+
cat bench-validation-results.json
85+
7586
- name: Clean up benchmark text files before switching branches
7687
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
7788
run: |
@@ -101,9 +112,11 @@ jobs:
101112
name: benchmark-results
102113
path: |
103114
bench-results.json
115+
bench-validation-results.json
104116
benchmark-simple.txt
105117
benchmark-complex.txt
106118
benchmark-compat.txt
119+
benchmark-validation.txt
107120
retention-days: 30
108121

109122
- name: Comment PR with comparison results
@@ -115,6 +128,7 @@ jobs:
115128
116129
// Read all benchmark results
117130
let compatResults = '';
131+
let validationResults = '';
118132
let simpleResults = '';
119133
let complexResults = '';
120134
@@ -124,6 +138,12 @@ jobs:
124138
compatResults = 'Comparison benchmark not available';
125139
}
126140
141+
try {
142+
validationResults = fs.readFileSync('benchmark-validation.txt', 'utf8');
143+
} catch (e) {
144+
validationResults = 'Validation benchmark not available';
145+
}
146+
127147
try {
128148
simpleResults = fs.readFileSync('benchmark-simple.txt', 'utf8');
129149
} catch (e) {
@@ -182,9 +202,14 @@ jobs:
182202
}
183203
184204
const body = '## 🚀 Performance Benchmark Results\n\n' +
205+
'### 📦 class-transformer Compatibility\n\n' +
185206
improvedSummary +
186-
'<details>\n<summary>📋 Full Benchmark Output</summary>\n\n' +
207+
'<details>\n<summary>📋 Full class-transformer Benchmark Output</summary>\n\n' +
187208
'```\n' + compatResults + '\n```\n\n</details>\n\n' +
209+
'### ✅ class-validator Compatibility\n\n' +
210+
'<details>\n<summary>📋 Full class-validator Benchmark Output</summary>\n\n' +
211+
'```\n' + validationResults + '\n```\n\n</details>\n\n' +
212+
'### 🎯 Core Performance\n\n' +
188213
'<details>\n<summary>⚡ Simple Mapping Benchmark</summary>\n\n' +
189214
'```\n' + simpleResults + '\n```\n\n</details>\n\n' +
190215
'<details>\n<summary>🔧 Complex Transformations Benchmark</summary>\n\n' +

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ node_modules
33
coverage
44
build
55
bench-results.json
6+
7+
# Ignore compiled JavaScript files in src directory
8+
# (TypeScript source files only, compiled output goes to dist/)
9+
src/**/*.js
10+
src/**/*.js.map

CHANGELOG.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,86 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [4.1.0] - 2025-10-16
11+
12+
### Added
13+
14+
#### Testing Infrastructure
15+
16+
- **Property-Based Testing** - Added comprehensive property-based tests using fast-check library
17+
- 25 new property-based tests with ~2,000 random data checks
18+
- Validators tested: @IsEmail, @IsURL, @IsUUID, @IsISO8601, @IsInt, @IsPositive, @IsNegative, @Min, @Max, @MinLength, @MaxLength, @IsAlpha, @IsAlphanumeric, @IsHexColor, @IsPort
19+
- Ensures validators work correctly with edge cases and random inputs
20+
- File: `tests/unit/compat/class-validator/property-based.test.ts`
21+
22+
- **Integration Tests** - Added 5 real-world scenario tests
23+
- User registration with nested address validation
24+
- API order request with items array and shipping address
25+
- Contact form with optional fields
26+
- API response transformation + validation
27+
- Nested objects transformation (posts with comments)
28+
- File: `tests/integration/real-world-scenarios.test.ts`
29+
30+
- **Benchmark Regression Tests** - Added 7 performance regression tests
31+
- Simple validation: **0.0023ms** (217x faster than baseline)
32+
- Complex validation: **0.0022ms** (909x faster than baseline)
33+
- Nested arrays: **0.0050ms** (600x faster than baseline)
34+
- Transformation: **0.0043ms** (70x faster than baseline)
35+
- Transform + Validate: **0.0042ms** (238x faster than baseline)
36+
- Async validation: **0.0076ms**
37+
- File: `tests/benchmarks/regression.test.ts`
38+
39+
- **Memory Leak Tests** - Added 6 memory leak detection tests
40+
- Tests validate no memory leaks after 3,000-10,000 iterations
41+
- Simple validation: -4.06MB (-30.53%) - Memory freed!
42+
- Create + validate: -0.99MB (-8.83%) - Memory freed!
43+
- Nested validation: -0.19MB (-1.68%) - Stable!
44+
- Array validation: -0.03MB (-0.26%) - Stable!
45+
- Transformation: -1.49MB (-13.13%) - Memory freed!
46+
- Transform + validate: +0.65MB (+5.47%) - Minimal growth!
47+
- File: `tests/benchmarks/memory-leak.test.ts`
48+
49+
- **Branch Coverage Tests** - Added 25 tests to improve branch coverage
50+
- Validation groups with constraints
51+
- Optional properties with groups
52+
- Conditional validation (@ValidateIf)
53+
- Nested validation for arrays and objects
54+
- Multiple constraints with different groups
55+
- Async validation with groups
56+
- Files: `tests/unit/compat/class-validator/branch-coverage-boost.test.ts`, `tests/unit/compat/class-validator/complex-combinations.test.ts`
57+
58+
#### Dependencies
59+
60+
- **fast-check@4.3.0** - Added for property-based testing (dev dependency)
61+
62+
### Changed
63+
64+
#### Test Coverage Improvements
65+
66+
- **Total tests**: 450 → 518 (+68 tests, +15.1%)
67+
- **Test files**: 30 → 34 (+4 files)
68+
- **Statements coverage**: 94.69% → 95.08% (+0.39%)
69+
- **Branches coverage**: 76.29% → 77.58% (+1.29%)
70+
- **Functions coverage**: 90.64% (maintained)
71+
- **Lines coverage**: 94.69% → 95.08% (+0.39%)
72+
73+
### Performance
74+
75+
- **Validation Performance** - Confirmed exceptional performance in benchmark tests
76+
- 70-909x faster than baseline expectations
77+
- All performance regression tests pass with 10% tolerance
78+
- No performance degradation detected
79+
80+
- **Memory Efficiency** - Confirmed no memory leaks
81+
- All memory leak tests pass
82+
- Memory usage stable or decreasing after repeated operations
83+
- Garbage collection working effectively
84+
85+
### Related
86+
87+
- PR [#23](https://github.com/Isqanderm/data-mapper/pull/23) - Add high-performance validation with JIT compilation (MVP)
88+
- Commit: cb2532c6bd2245105f52a786ed30009498f4ff12
89+
1090
## [4.0.0] - 2025-10-14
1191

1292
### BREAKING CHANGES
@@ -187,5 +267,7 @@ For existing users:
187267

188268
This changelog was introduced after version 2.0.5. Previous version history can be found in git commit messages.
189269

190-
[Unreleased]: https://github.com/Isqanderm/data-mapper/compare/v2.0.5...HEAD
270+
[Unreleased]: https://github.com/Isqanderm/data-mapper/compare/v4.1.0...HEAD
271+
[4.1.0]: https://github.com/Isqanderm/data-mapper/compare/v4.0.0...v4.1.0
272+
[4.0.0]: https://github.com/Isqanderm/data-mapper/compare/v2.0.5...v4.0.0
191273
[2.0.5]: https://github.com/Isqanderm/data-mapper/releases/tag/v2.0.5

README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1212
[![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue.svg)](https://www.typescriptlang.org/)
1313
[![Downloads](https://img.shields.io/npm/dm/om-data-mapper.svg)](https://www.npmjs.com/package/om-data-mapper)
14+
[![Documentation](https://img.shields.io/badge/docs-English%20%7C%20Russian-blue)](./docs/README.md)
1415

1516
`om-data-mapper` is a high-performance, type-safe object mapping library for TypeScript and JavaScript. It features a modern **Decorator API** with JIT compilation that delivers **up to 42.7x better performance** than class-transformer, while providing a clean, declarative syntax and zero runtime dependencies.
1617

@@ -67,7 +68,7 @@ const user = plainToInstance(UserMapper, data); // 4.3M ops/sec (13.2x faster!)
6768
| Array (100 items) | 5.2K ops/sec | 69K ops/sec | **12.3x faster** |
6869
| Custom Logic | 333K ops/sec | 4.8M ops/sec | **13.4x faster** |
6970

70-
[📊 See full comparison](./docs/COMPARISON.md)
71+
📊 See [Transformer Usage Guide](./docs/transformer-usage.md) for detailed performance comparisons
7172

7273
## ✨ Features
7374

@@ -266,7 +267,7 @@ Your existing code works exactly the same, but **17.28x faster** on average!
266267
- ✅ 70% smaller bundle size
267268
- ✅ TC39 Stage 3 decorators
268269

269-
[📖 Full migration guide](./docs/COMPARISON.md#migration-guide)
270+
[📖 Full migration guide](./docs/transformer-usage.md#migration-from-class-transformer)
270271

271272
### Legacy API (Still Supported)
272273

@@ -311,7 +312,7 @@ om-data-mapper delivers **exceptional performance** through JIT compilation and
311312

312313
### vs class-transformer
313314

314-
**17.28x faster on average!** See [full comparison](./docs/COMPARISON.md).
315+
**17.28x faster on average!** See [Transformer Usage Guide](./docs/transformer-usage.md) for detailed comparisons.
315316

316317
| Scenario | class-transformer | om-data-mapper | Improvement |
317318
|----------|-------------------|----------------|-------------|
@@ -365,7 +366,6 @@ We use automated benchmarks to track performance regressions:
365366
- 📊 **PR Comments**: Results posted automatically to pull requests
366367
- 📈 **Historical Tracking**: Performance trends on [GitHub Pages](https://isqanderm.github.io/data-mapper/dev/bench/)
367368
- 🔔 **Alerts**: Automatic notifications on regressions >150%
368-
- 📚 **Documentation**: See [Benchmark Setup Guide](./docs/BENCHMARK_SETUP.md) for details
369369

370370
**Run benchmarks locally:**
371371
```bash
@@ -596,11 +596,6 @@ console.log(user.password); // undefined
596596
-**Type Safe** - Full TypeScript support
597597
-**Zero Breaking Changes** - Works exactly like class-transformer
598598

599-
### Documentation
600-
601-
- [Class-Transformer Compatibility Guide](./docs/CLASS_TRANSFORMER_COMPATIBILITY.md) - Complete API reference
602-
- [TC39 Decorators Migration Guide](./docs/TC39_DECORATORS_MIGRATION.md) - Migration from legacy decorators
603-
604599
---
605600

606601
## Real-World Examples
@@ -745,7 +740,37 @@ const formData = new FormData(form);
745740
const registration = plainToInstance(RegistrationMapper, Object.fromEntries(formData));
746741
```
747742

748-
## API Documentation
743+
## 📚 Documentation
744+
745+
Complete documentation is available in both **English** and **Russian**:
746+
747+
### English Documentation
748+
749+
📖 **[Documentation Index](./docs/README.md)** - Start here for complete guides
750+
751+
**User Guides:**
752+
- [Validation Module - User Guide](./docs/validation-usage.md) - Complete guide to validation decorators and functions
753+
- [Transformer Module - User Guide](./docs/transformer-usage.md) - Complete guide to transformation APIs (Decorator API & class-transformer compatibility)
754+
755+
**Internal Architecture:**
756+
- [Validation JIT Compilation Internals](./docs/validation-jit-internals.md) - Deep dive into validation JIT compilation
757+
- [Transformer JIT Compilation Internals](./docs/transformer-jit-internals.md) - Deep dive into transformer JIT compilation
758+
759+
### Russian Documentation (Русская документация)
760+
761+
📖 **[Индекс документации](./docs-ru/README.md)** - Начните отсюда для полных руководств
762+
763+
**Руководства пользователя:**
764+
- [Модуль валидации - Руководство пользователя](./docs-ru/validation-usage.md) - Полное руководство по декораторам и функциям валидации
765+
- [Модуль трансформации - Руководство пользователя](./docs-ru/transformer-usage.md) - Полное руководство по API трансформации
766+
767+
**Внутренняя архитектура:**
768+
- [Внутреннее устройство JIT-компиляции валидации](./docs-ru/validation-jit-internals.md) - Глубокое погружение в JIT-компиляцию валидации
769+
- [Внутреннее устройство JIT-компиляции трансформации](./docs-ru/transformer-jit-internals.md) - Глубокое погружение в JIT-компиляцию трансформации
770+
771+
---
772+
773+
## API Quick Reference
749774

750775
### Decorators
751776

@@ -765,14 +790,7 @@ const registration = plainToInstance(RegistrationMapper, Object.fromEntries(form
765790
- **`tryPlainToInstance<S, T>(MapperClass, source)`** - Safe transformation with error handling
766791
- **`createMapper<S, T>(MapperClass)`** - Create reusable mapper instance
767792

768-
### Advanced Usage
769-
770-
For more detailed examples and advanced patterns:
771-
772-
- [📖 Decorator API Guide](./docs/DECORATOR_API.md) - Complete decorator reference
773-
- [🔄 Migration Guide](./docs/MIGRATION_GUIDE.md) - Migrating from class-transformer
774-
- [🏗️ Nested Mapper Composition](./docs/nested-mapper-composition.md) - Complex mapping patterns
775-
- [📁 Examples Directory](./examples) - Real-world code examples
793+
For complete API documentation, see the [Transformer Usage Guide](./docs/transformer-usage.md).
776794

777795
## Contributing
778796

0 commit comments

Comments
 (0)