ts-runtime-validation 1.7.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +143 -0
- package/README.md +93 -30
- package/dist/SchemaGenerator.deterministic-extended.test.js +420 -0
- package/dist/SchemaGenerator.deterministic-extended.test.js.map +1 -0
- package/dist/SchemaGenerator.deterministic.test.js +251 -0
- package/dist/SchemaGenerator.deterministic.test.js.map +1 -0
- package/dist/SchemaGenerator.integration.test.js +3 -3
- package/dist/SchemaGenerator.integration.test.js.map +1 -1
- package/dist/SchemaGenerator.test.js +94 -0
- package/dist/SchemaGenerator.test.js.map +1 -1
- package/dist/cli.test.js +155 -0
- package/dist/cli.test.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/CodeGenerator.js +29 -13
- package/dist/services/CodeGenerator.js.map +1 -1
- package/dist/services/FileDiscovery.js +4 -2
- package/dist/services/FileDiscovery.js.map +1 -1
- package/dist/services/FileDiscovery.test.js +1 -1
- package/dist/services/FileDiscovery.test.js.map +1 -1
- package/dist/services/SchemaProcessor.js +27 -11
- package/dist/services/SchemaProcessor.js.map +1 -1
- package/dist/services/SchemaProcessor.test.js +61 -1
- package/dist/services/SchemaProcessor.test.js.map +1 -1
- package/dist/services/SchemaWriter.test.js +1 -1
- package/dist/services/SchemaWriter.test.js.map +1 -1
- package/package.json +10 -9
- package/src/SchemaGenerator.deterministic-extended.test.ts +429 -0
- package/src/SchemaGenerator.deterministic.test.ts +276 -0
- package/src/SchemaGenerator.integration.test.ts +3 -3
- package/src/SchemaGenerator.test.ts +111 -0
- package/src/cli.test.ts +130 -0
- package/src/index.ts +1 -1
- package/src/services/CodeGenerator.ts +30 -12
- package/src/services/FileDiscovery.test.ts +1 -1
- package/src/services/FileDiscovery.ts +5 -2
- package/src/services/SchemaProcessor.test.ts +73 -1
- package/src/services/SchemaProcessor.ts +30 -9
- package/src/services/SchemaWriter.test.ts +1 -1
- package/.claude/settings.local.json +0 -9
- package/dist/test/output/duplicate-symbols-identitcal-implementation/ValidationType.js +0 -3
- package/dist/test/output/duplicate-symbols-identitcal-implementation/ValidationType.js.map +0 -1
- package/dist/test/output/duplicate-symbols-identitcal-implementation/isValidSchema.js +0 -49
- package/dist/test/output/duplicate-symbols-identitcal-implementation/isValidSchema.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.8.1] - 2024-08-25
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- **Major dependency updates** to latest versions for security and performance
|
|
12
|
+
- Updated Jest from 29.7.0 to 30.0.5
|
|
13
|
+
- Updated ts-json-schema-generator from 1.5.1 to 2.4.0
|
|
14
|
+
- Updated ts-morph from 19.0.0 to 26.0.0
|
|
15
|
+
- Updated Commander from 11.1.0 to 14.0.0
|
|
16
|
+
- Updated picomatch from 2.3.1 to 4.0.3
|
|
17
|
+
- Updated all @types packages to latest versions
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Added missing ajv peer dependency
|
|
21
|
+
- Resolved all dependency version conflicts
|
|
22
|
+
|
|
23
|
+
### Security
|
|
24
|
+
- Zero vulnerabilities reported by yarn audit
|
|
25
|
+
- All dependencies updated to secure versions
|
|
26
|
+
|
|
27
|
+
## [1.8.0] - 2024-08-25
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
- Comprehensive deterministic output tests for various scenarios
|
|
31
|
+
- Extended test coverage for circular references, mixed export types, and parallel processing
|
|
32
|
+
- Troubleshooting section in README with common issues and solutions
|
|
33
|
+
- Clear cache instructions and documentation
|
|
34
|
+
- Project marketing page link in README
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
- **Critical**: Non-deterministic hash generation causing different output on each run
|
|
38
|
+
- File processing order inconsistencies in parallel mode
|
|
39
|
+
- Schema map iteration order issues
|
|
40
|
+
- Import statement ordering in generated files
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
- All test output directories now use consistent `.test-tmp/` pattern
|
|
44
|
+
- Simplified `.gitignore` to use single test output pattern
|
|
45
|
+
- Improved README description to better reflect project capabilities
|
|
46
|
+
|
|
47
|
+
### Internal
|
|
48
|
+
- Added sorting to file discovery process
|
|
49
|
+
- Ensured consistent ordering in schema processing pipeline
|
|
50
|
+
- Fixed Map iteration order throughout codebase
|
|
51
|
+
- Sorted all collections before iteration in code generation
|
|
52
|
+
|
|
53
|
+
## [1.7.0] - 2024
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
- **Performance overhaul** with intelligent caching system
|
|
57
|
+
- **Parallel processing** support for faster schema generation
|
|
58
|
+
- **Progress reporting** with visual feedback
|
|
59
|
+
- **Minification** option for production builds
|
|
60
|
+
- **Tree-shaking** friendly exports
|
|
61
|
+
- **Lazy loading** support for validators
|
|
62
|
+
- File-based caching with MD5 hash change detection
|
|
63
|
+
- Verbose logging mode for debugging
|
|
64
|
+
- Enhanced CLI with new performance options
|
|
65
|
+
|
|
66
|
+
### Changed
|
|
67
|
+
- Refactored library entry point
|
|
68
|
+
- Improved README documentation
|
|
69
|
+
- Better TypeScript compilation handling
|
|
70
|
+
|
|
71
|
+
### Fixed
|
|
72
|
+
- TTY handling issues
|
|
73
|
+
- Windows POSIX path handling in helpers
|
|
74
|
+
- TypeScript compilation errors
|
|
75
|
+
|
|
76
|
+
## [1.6.16] - 2024
|
|
77
|
+
|
|
78
|
+
### Added
|
|
79
|
+
- Progress indicator support
|
|
80
|
+
- Namespaced exports feature
|
|
81
|
+
|
|
82
|
+
### Changed
|
|
83
|
+
- Updated dependencies
|
|
84
|
+
- Allow duplicate symbols if definitions are identical
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
- Windows test compatibility
|
|
88
|
+
- Non-boolean CLI options handling
|
|
89
|
+
|
|
90
|
+
## [1.6.15] - 2024
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
- Custom tsconfig path support
|
|
94
|
+
|
|
95
|
+
### Changed
|
|
96
|
+
- Documentation updates
|
|
97
|
+
|
|
98
|
+
## Earlier Versions
|
|
99
|
+
|
|
100
|
+
For changes in earlier versions, please refer to the git history or npm release notes.
|
|
101
|
+
|
|
102
|
+
## Migration Guide
|
|
103
|
+
|
|
104
|
+
### Upgrading to 1.8.0
|
|
105
|
+
|
|
106
|
+
If you're experiencing hash inconsistencies between runs:
|
|
107
|
+
|
|
108
|
+
1. Update to version 1.8.0 or later
|
|
109
|
+
2. Clear your cache: `rm -rf .ts-runtime-validation-cache`
|
|
110
|
+
3. Regenerate your schemas: `ts-runtime-validation --cache`
|
|
111
|
+
|
|
112
|
+
The deterministic output fix ensures consistent file generation across multiple runs, which is essential for:
|
|
113
|
+
- CI/CD pipelines
|
|
114
|
+
- Git diff stability
|
|
115
|
+
- Build reproducibility
|
|
116
|
+
- Cache effectiveness
|
|
117
|
+
|
|
118
|
+
### Upgrading to 1.7.0
|
|
119
|
+
|
|
120
|
+
To take advantage of the new performance features:
|
|
121
|
+
|
|
122
|
+
1. Enable caching for faster incremental builds: `--cache`
|
|
123
|
+
2. Keep parallel processing enabled (default): `--parallel`
|
|
124
|
+
3. Use progress reporting for long operations: `--progress`
|
|
125
|
+
4. For production builds, add: `--minify --tree-shaking`
|
|
126
|
+
|
|
127
|
+
Example migration:
|
|
128
|
+
```bash
|
|
129
|
+
# Old command
|
|
130
|
+
ts-runtime-validation
|
|
131
|
+
|
|
132
|
+
# New command with performance optimizations
|
|
133
|
+
ts-runtime-validation --cache --progress --minify --tree-shaking
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
[Unreleased]: https://github.com/thegalah/ts-runtime-validation/compare/v1.8.1...HEAD
|
|
139
|
+
[1.8.1]: https://github.com/thegalah/ts-runtime-validation/compare/v1.8.0...v1.8.1
|
|
140
|
+
[1.8.0]: https://github.com/thegalah/ts-runtime-validation/compare/v1.7.0...v1.8.0
|
|
141
|
+
[1.7.0]: https://github.com/thegalah/ts-runtime-validation/compare/v1.6.16...v1.7.0
|
|
142
|
+
[1.6.16]: https://github.com/thegalah/ts-runtime-validation/compare/v1.6.15...v1.6.16
|
|
143
|
+
[1.6.15]: https://github.com/thegalah/ts-runtime-validation/releases/tag/v1.6.15
|
package/README.md
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/ts-runtime-validation)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Automatically generate type-safe runtime validation from your existing TypeScript interfaces. Zero configuration, zero decorators - just add JSDoc comments for validation rules and get bulletproof runtime type checking with full TypeScript support.
|
|
6
|
+
|
|
7
|
+
📖 **[Project Marketing Page](https://www.thegalah.com/projects/ts-runtime-validation)**
|
|
6
8
|
|
|
7
9
|
## ✨ Features
|
|
8
10
|
|
|
9
11
|
### Core Features
|
|
12
|
+
|
|
10
13
|
- 🚀 **Zero-effort validation** - Automatically generates JSON Schema validators from TypeScript interfaces
|
|
11
14
|
- 🔒 **Type-safe** - Full TypeScript support with type inference and type guards
|
|
12
15
|
- 📦 **Lightweight** - Minimal dependencies, can be installed as a dev dependency
|
|
@@ -15,6 +18,7 @@ Generate bulletproof runtime type validation from your TypeScript interfaces and
|
|
|
15
18
|
- 📝 **JSDoc annotations** - Add validation rules (min/max length, patterns, formats) directly in your TypeScript code
|
|
16
19
|
|
|
17
20
|
### Performance & Optimization
|
|
21
|
+
|
|
18
22
|
- ⚡ **Incremental builds** - File-based caching for faster subsequent builds
|
|
19
23
|
- 🔄 **Parallel processing** - Concurrent file processing for improved performance
|
|
20
24
|
- 📊 **Progress reporting** - Visual feedback for long-running operations
|
|
@@ -182,7 +186,7 @@ Output Optimization:
|
|
|
182
186
|
--minify Minify generated JSON schemas
|
|
183
187
|
--tree-shaking Generate tree-shaking friendly exports
|
|
184
188
|
--lazy-load Generate lazy-loaded validators
|
|
185
|
-
|
|
189
|
+
|
|
186
190
|
General:
|
|
187
191
|
-h, --help Display help information
|
|
188
192
|
```
|
|
@@ -191,12 +195,12 @@ General:
|
|
|
191
195
|
|
|
192
196
|
The tool generates optimized files in your output directory:
|
|
193
197
|
|
|
194
|
-
| File | Description
|
|
195
|
-
| ------------------------ |
|
|
196
|
-
| `validation.schema.json` | JSON Schema definitions for all your types
|
|
197
|
-
| `SchemaDefinition.ts` | TypeScript interface mapping schema paths to types
|
|
198
|
-
| `isValidSchema.ts` | Type guard helper with runtime validation
|
|
199
|
-
| `ValidationType.ts` | Centralized type exports
|
|
198
|
+
| File | Description | Optimizations |
|
|
199
|
+
| ------------------------ | -------------------------------------------------- | ------------------------------- |
|
|
200
|
+
| `validation.schema.json` | JSON Schema definitions for all your types | Minification with `--minify` |
|
|
201
|
+
| `SchemaDefinition.ts` | TypeScript interface mapping schema paths to types | Tree-shaking ready imports |
|
|
202
|
+
| `isValidSchema.ts` | Type guard helper with runtime validation | Lazy loading with `--lazy-load` |
|
|
203
|
+
| `ValidationType.ts` | Centralized type exports | Individual exports or namespace |
|
|
200
204
|
|
|
201
205
|
### Programmatic API
|
|
202
206
|
|
|
@@ -210,7 +214,7 @@ const generator = new SchemaGenerator({
|
|
|
210
214
|
output: "./validation",
|
|
211
215
|
helpers: true,
|
|
212
216
|
additionalProperties: false,
|
|
213
|
-
tsconfigPath: ""
|
|
217
|
+
tsconfigPath: "",
|
|
214
218
|
});
|
|
215
219
|
|
|
216
220
|
await generator.Generate();
|
|
@@ -224,10 +228,10 @@ const devGenerator = new SchemaGenerator({
|
|
|
224
228
|
additionalProperties: false,
|
|
225
229
|
tsconfigPath: "",
|
|
226
230
|
// Development optimizations
|
|
227
|
-
cache: true,
|
|
228
|
-
progress: true,
|
|
229
|
-
verbose: true,
|
|
230
|
-
parallel: true
|
|
231
|
+
cache: true, // Enable incremental builds
|
|
232
|
+
progress: true, // Show progress feedback
|
|
233
|
+
verbose: true, // Detailed logging
|
|
234
|
+
parallel: true, // Faster processing
|
|
231
235
|
});
|
|
232
236
|
|
|
233
237
|
// Production configuration (optimized output)
|
|
@@ -239,11 +243,11 @@ const prodGenerator = new SchemaGenerator({
|
|
|
239
243
|
additionalProperties: false,
|
|
240
244
|
tsconfigPath: "./tsconfig.json",
|
|
241
245
|
// Production optimizations
|
|
242
|
-
cache: true,
|
|
243
|
-
minify: true,
|
|
244
|
-
treeShaking: true,
|
|
245
|
-
lazyLoad: false,
|
|
246
|
-
parallel: true
|
|
246
|
+
cache: true, // Faster builds
|
|
247
|
+
minify: true, // Smaller output files
|
|
248
|
+
treeShaking: true, // Bundle optimization
|
|
249
|
+
lazyLoad: false, // Eager loading for performance
|
|
250
|
+
parallel: true, // Maximum speed
|
|
247
251
|
});
|
|
248
252
|
|
|
249
253
|
// Large project configuration (memory efficient)
|
|
@@ -254,25 +258,25 @@ const largeProjectGenerator = new SchemaGenerator({
|
|
|
254
258
|
helpers: true,
|
|
255
259
|
additionalProperties: false,
|
|
256
260
|
tsconfigPath: "",
|
|
257
|
-
// Large project optimizations
|
|
258
|
-
cache: true,
|
|
259
|
-
progress: true,
|
|
260
|
-
lazyLoad: true,
|
|
261
|
-
treeShaking: true,
|
|
262
|
-
minify: true
|
|
261
|
+
// Large project optimizations
|
|
262
|
+
cache: true, // Essential for large projects
|
|
263
|
+
progress: true, // Track long operations
|
|
264
|
+
lazyLoad: true, // Reduce initial memory usage
|
|
265
|
+
treeShaking: true, // Optimize bundle size
|
|
266
|
+
minify: true, // Reduce file size
|
|
263
267
|
});
|
|
264
268
|
|
|
265
269
|
// Execute generation
|
|
266
270
|
try {
|
|
267
271
|
await generator.Generate();
|
|
268
|
-
console.log(
|
|
272
|
+
console.log("Schema generation completed successfully!");
|
|
269
273
|
} catch (error) {
|
|
270
|
-
console.error(
|
|
274
|
+
console.error("Generation failed:", error.message);
|
|
271
275
|
}
|
|
272
276
|
|
|
273
277
|
// Utility methods
|
|
274
|
-
generator.clearCache();
|
|
275
|
-
await generator.cleanOutput();
|
|
278
|
+
generator.clearCache(); // Clear file cache
|
|
279
|
+
await generator.cleanOutput(); // Remove generated files
|
|
276
280
|
```
|
|
277
281
|
|
|
278
282
|
### Watch Mode & Development Workflows
|
|
@@ -330,26 +334,48 @@ ts-runtime-validation --cache
|
|
|
330
334
|
```
|
|
331
335
|
|
|
332
336
|
**How it works:**
|
|
337
|
+
|
|
333
338
|
- Generates MD5 hashes of source files to detect changes
|
|
334
339
|
- Stores cache in `.ts-runtime-validation-cache/`
|
|
335
340
|
- Only processes files that have been modified
|
|
336
341
|
- Provides significant speedup for large projects
|
|
337
342
|
|
|
343
|
+
**Clearing the cache:**
|
|
344
|
+
|
|
345
|
+
If you encounter issues with stale generated files or need to force a full regeneration:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
# Method 1: Delete cache directory
|
|
349
|
+
rm -rf .ts-runtime-validation-cache
|
|
350
|
+
|
|
351
|
+
# Method 2: Using programmatic API
|
|
352
|
+
const generator = new SchemaGenerator(options);
|
|
353
|
+
generator.clearCache();
|
|
354
|
+
|
|
355
|
+
# Method 3: Add a clean script to package.json
|
|
356
|
+
"scripts": {
|
|
357
|
+
"generate-types:clean": "rm -rf .ts-runtime-validation-cache && ts-runtime-validation --cache"
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
338
361
|
### Performance Tips
|
|
339
362
|
|
|
340
363
|
**Development Workflow:**
|
|
364
|
+
|
|
341
365
|
```bash
|
|
342
366
|
# Fast iterations with caching and progress
|
|
343
367
|
ts-runtime-validation --cache --progress --verbose
|
|
344
368
|
```
|
|
345
369
|
|
|
346
370
|
**Production Builds:**
|
|
371
|
+
|
|
347
372
|
```bash
|
|
348
373
|
# Optimized output for deployment
|
|
349
374
|
ts-runtime-validation --cache --minify --tree-shaking
|
|
350
375
|
```
|
|
351
376
|
|
|
352
377
|
**Large Projects:**
|
|
378
|
+
|
|
353
379
|
```bash
|
|
354
380
|
# Memory efficient processing
|
|
355
381
|
ts-runtime-validation --cache --lazy-load --progress
|
|
@@ -358,18 +384,21 @@ ts-runtime-validation --cache --lazy-load --progress
|
|
|
358
384
|
### Bundle Optimization
|
|
359
385
|
|
|
360
386
|
**Tree-shaking friendly exports:**
|
|
387
|
+
|
|
361
388
|
```typescript
|
|
362
389
|
// With --tree-shaking flag
|
|
363
|
-
export type IUser = _IUser;
|
|
390
|
+
export type IUser = _IUser; // Individual exports
|
|
364
391
|
export type IProduct = _IProduct;
|
|
365
392
|
|
|
366
393
|
// Default behavior
|
|
367
|
-
namespace ValidationType {
|
|
394
|
+
namespace ValidationType {
|
|
395
|
+
// Namespace exports
|
|
368
396
|
export type IUser = _IUser;
|
|
369
397
|
}
|
|
370
398
|
```
|
|
371
399
|
|
|
372
400
|
**Lazy-loaded validators:**
|
|
401
|
+
|
|
373
402
|
```typescript
|
|
374
403
|
// With --lazy-load flag
|
|
375
404
|
let validator: any = null;
|
|
@@ -426,6 +455,7 @@ ts-runtime-validation uses a modern service-oriented architecture:
|
|
|
426
455
|
### Contributing Guidelines
|
|
427
456
|
|
|
428
457
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed information about:
|
|
458
|
+
|
|
429
459
|
- Service-oriented architecture patterns
|
|
430
460
|
- Error handling strategies
|
|
431
461
|
- Performance optimization techniques
|
|
@@ -488,3 +518,36 @@ Choose **alternatives** when you:
|
|
|
488
518
|
- Prefer schema-first design (define validation, derive types)
|
|
489
519
|
- Need complex runtime transformations or coercions
|
|
490
520
|
- Want extensive built-in validation methods and error messages
|
|
521
|
+
|
|
522
|
+
## 🔧 Troubleshooting
|
|
523
|
+
|
|
524
|
+
### Generated files are not updating
|
|
525
|
+
|
|
526
|
+
If your generated files seem stale or aren't reflecting recent changes:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
# Clear the cache and regenerate
|
|
530
|
+
rm -rf .ts-runtime-validation-cache
|
|
531
|
+
ts-runtime-validation --cache
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### Hash inconsistencies between runs
|
|
535
|
+
|
|
536
|
+
Version 1.8.0+ includes fixes for deterministic output generation. If you're experiencing different file hashes between runs, ensure you're using the latest version.
|
|
537
|
+
|
|
538
|
+
### Performance issues with large projects
|
|
539
|
+
|
|
540
|
+
For optimal performance with large codebases:
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
# Enable all performance optimizations
|
|
544
|
+
ts-runtime-validation --cache --parallel --minify --tree-shaking
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### Cache-related issues
|
|
548
|
+
|
|
549
|
+
The cache directory `.ts-runtime-validation-cache/` can occasionally become corrupted. If you experience unexpected behavior:
|
|
550
|
+
|
|
551
|
+
1. Clear the cache directory: `rm -rf .ts-runtime-validation-cache`
|
|
552
|
+
2. Run generation again with cache enabled: `ts-runtime-validation --cache`
|
|
553
|
+
3. Add `.ts-runtime-validation-cache/` to your `.gitignore` file
|