ts-runtime-validation 1.6.16 → 1.8.0

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.
Files changed (83) hide show
  1. package/CONTRIBUTING.md +430 -0
  2. package/README.md +505 -62
  3. package/dist/ICommandOptions.js +3 -0
  4. package/dist/ICommandOptions.js.map +1 -0
  5. package/dist/SchemaGenerator.deterministic-extended.test.js +420 -0
  6. package/dist/SchemaGenerator.deterministic-extended.test.js.map +1 -0
  7. package/dist/SchemaGenerator.deterministic.test.js +251 -0
  8. package/dist/SchemaGenerator.deterministic.test.js.map +1 -0
  9. package/dist/SchemaGenerator.integration.test.js +323 -0
  10. package/dist/SchemaGenerator.integration.test.js.map +1 -0
  11. package/dist/SchemaGenerator.js +120 -0
  12. package/dist/SchemaGenerator.js.map +1 -0
  13. package/dist/SchemaGenerator.test.js +226 -0
  14. package/dist/SchemaGenerator.test.js.map +1 -0
  15. package/dist/cli.test.js +155 -0
  16. package/dist/cli.test.js.map +1 -0
  17. package/dist/errors/index.js +95 -0
  18. package/dist/errors/index.js.map +1 -0
  19. package/dist/errors/index.test.js +232 -0
  20. package/dist/errors/index.test.js.map +1 -0
  21. package/dist/getPosixPath.js +13 -0
  22. package/dist/getPosixPath.js.map +1 -0
  23. package/dist/index.js +27 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/lib.js.map +1 -0
  26. package/dist/services/CodeGenerator.js +321 -0
  27. package/dist/services/CodeGenerator.js.map +1 -0
  28. package/dist/services/FileDiscovery.js +123 -0
  29. package/dist/services/FileDiscovery.js.map +1 -0
  30. package/dist/services/FileDiscovery.test.js +184 -0
  31. package/dist/services/FileDiscovery.test.js.map +1 -0
  32. package/dist/services/SchemaProcessor.js +198 -0
  33. package/dist/services/SchemaProcessor.js.map +1 -0
  34. package/dist/services/SchemaProcessor.test.js +455 -0
  35. package/dist/services/SchemaProcessor.test.js.map +1 -0
  36. package/dist/services/SchemaWriter.js +76 -0
  37. package/dist/services/SchemaWriter.js.map +1 -0
  38. package/dist/services/SchemaWriter.test.js +255 -0
  39. package/dist/services/SchemaWriter.test.js.map +1 -0
  40. package/dist/test/basic-scenario/types.jsonschema.js +3 -0
  41. package/dist/test/basic-scenario/types.jsonschema.js.map +1 -0
  42. package/dist/test/duplicate-symbols-different-implementation/IBaseType.js +3 -0
  43. package/dist/test/duplicate-symbols-different-implementation/IBaseType.js.map +1 -0
  44. package/dist/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.js +3 -0
  45. package/dist/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.js.map +1 -0
  46. package/dist/test/duplicate-symbols-different-implementation/IBasicTypesA.jsonschema.js +3 -0
  47. package/dist/test/duplicate-symbols-different-implementation/IBasicTypesA.jsonschema.js.map +1 -0
  48. package/dist/test/duplicate-symbols-different-implementation/IBasicTypesB.jsonschema.js +3 -0
  49. package/dist/test/duplicate-symbols-different-implementation/IBasicTypesB.jsonschema.js.map +1 -0
  50. package/dist/test/duplicate-symbols-identitcal-implementation/IBaseType.js +3 -0
  51. package/dist/test/duplicate-symbols-identitcal-implementation/IBaseType.js.map +1 -0
  52. package/dist/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.js +3 -0
  53. package/dist/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.js.map +1 -0
  54. package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesA.jsonschema.js +3 -0
  55. package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesA.jsonschema.js.map +1 -0
  56. package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesB.jsonschema.js +3 -0
  57. package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesB.jsonschema.js.map +1 -0
  58. package/dist/utils/ProgressReporter.js +67 -0
  59. package/dist/utils/ProgressReporter.js.map +1 -0
  60. package/dist/utils/ProgressReporter.test.js +267 -0
  61. package/dist/utils/ProgressReporter.test.js.map +1 -0
  62. package/dist/writeLine.js +12 -0
  63. package/dist/writeLine.js.map +1 -0
  64. package/package.json +2 -2
  65. package/src/ICommandOptions.ts +7 -0
  66. package/src/SchemaGenerator.deterministic-extended.test.ts +429 -0
  67. package/src/SchemaGenerator.deterministic.test.ts +276 -0
  68. package/src/SchemaGenerator.integration.test.ts +411 -0
  69. package/src/SchemaGenerator.test.ts +118 -0
  70. package/src/SchemaGenerator.ts +112 -298
  71. package/src/cli.test.ts +130 -0
  72. package/src/errors/index.test.ts +319 -0
  73. package/src/errors/index.ts +92 -0
  74. package/src/index.ts +8 -1
  75. package/src/services/CodeGenerator.ts +370 -0
  76. package/src/services/FileDiscovery.test.ts +216 -0
  77. package/src/services/FileDiscovery.ts +140 -0
  78. package/src/services/SchemaProcessor.test.ts +536 -0
  79. package/src/services/SchemaProcessor.ts +194 -0
  80. package/src/services/SchemaWriter.test.ts +304 -0
  81. package/src/services/SchemaWriter.ts +75 -0
  82. package/src/utils/ProgressReporter.test.ts +357 -0
  83. package/src/utils/ProgressReporter.ts +76 -0
package/README.md CHANGED
@@ -1,110 +1,553 @@
1
1
  # ts-runtime-validation
2
2
 
3
- ## Why?
3
+ [![npm version](https://badge.fury.io/js/ts-runtime-validation.svg)](https://www.npmjs.com/package/ts-runtime-validation)
4
4
 
5
- Get bulletproof type validation based off typescript interfaces without any extra work. This package will ingest your existing types and generate the code for you.
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
6
 
7
- ## How?
7
+ 📖 **[Project Marketing Page](https://www.thegalah.com/projects/ts-runtime-validation)**
8
8
 
9
- This is a code generator that is designed to run as a yarn / npm script. By default scans your source directory for files ending in the provided glob pattern. It will generate types based off exported type aliases and typescript interfaces. By default: `*.jsonschema.{ts,tsx}`. The output will create three files:
9
+ ## Features
10
10
 
11
- 1. `./src/ts-runtime-validation/validation.schema.json` - containing the [jsonschema](http://json-schema.org/) types
12
- 1. `./src/SchemaDefinition.ts` - containing the typescript.
13
- 1. `./src/isValidSchema.ts` - containing a type guard type inferring helper method (intended for consumption in your code base - examples below)
14
- 1. `./src/ValidationType.ts` - containing an exported namespace containing every single exported validation type
11
+ ### Core Features
15
12
 
16
- ## Limitations
13
+ - 🚀 **Zero-effort validation** - Automatically generates JSON Schema validators from TypeScript interfaces
14
+ - 🔒 **Type-safe** - Full TypeScript support with type inference and type guards
15
+ - 📦 **Lightweight** - Minimal dependencies, can be installed as a dev dependency
16
+ - 🛠️ **CLI & Programmatic API** - Use as a CLI tool or integrate into your build process
17
+ - 🎯 **Selective generation** - Control which types to validate using file naming conventions
18
+ - 📝 **JSDoc annotations** - Add validation rules (min/max length, patterns, formats) directly in your TypeScript code
17
19
 
18
- The schema generator does not allow multiple interfaces / types to share the same name.
20
+ ### Performance & Optimization
19
21
 
20
- ## Footnote
22
+ - ⚡ **Incremental builds** - File-based caching for faster subsequent builds
23
+ - 🔄 **Parallel processing** - Concurrent file processing for improved performance
24
+ - 📊 **Progress reporting** - Visual feedback for long-running operations
25
+ - 🌳 **Tree-shaking friendly** - Generate optimized exports for smaller bundles
26
+ - 💤 **Lazy loading** - Optional deferred validator initialization
27
+ - 📦 **Minified output** - Compressed JSON schemas for production
28
+ - 🔧 **Verbose logging** - Detailed debugging information when needed
21
29
 
22
- The helper file assumes you have [ajv-validator](https://github.com/ajv-validator/ajv) peer dependency installed. Since this is only a code generation tool this package can be installed as a dev dependency.
30
+ ## 📋 Prerequisites
23
31
 
24
- ## Installation
32
+ - Node.js >= 12
33
+ - TypeScript >= 4.0
34
+ - `ajv` >= 8.11.0 (peer dependency for runtime validation)
35
+
36
+ ## 📦 Installation
25
37
 
26
38
  ```bash
27
- # yarn
39
+ # Using yarn (recommended)
28
40
  yarn add --dev ts-runtime-validation
29
- # npm
30
- npm install --dev ts-runtime-validation
41
+ yarn add ajv # Required peer dependency
42
+
43
+ # Using npm
44
+ npm install --save-dev ts-runtime-validation
45
+ npm install ajv # Required peer dependency
46
+ ```
47
+
48
+ ## 🚀 Quick Start
49
+
50
+ ### 1. Mark your types for validation
51
+
52
+ Create files ending with `.jsonschema.ts` for types you want to validate:
53
+
54
+ ```typescript
55
+ // user.jsonschema.ts
56
+ export interface IUser {
57
+ id: string;
58
+ email: string;
59
+ name?: string;
60
+ age: number;
61
+ roles: string[];
62
+ }
63
+
64
+ export type UserRole = "admin" | "user" | "guest";
65
+ ```
66
+
67
+ #### JSDoc Annotations for Validation Rules
68
+
69
+ You can add validation constraints using JSDoc annotations that will be converted to JSON Schema properties:
70
+
71
+ ```typescript
72
+ // api.jsonschema.ts
73
+ export interface IGetUserFormsPathParams {
74
+ /**
75
+ * User ID to get forms for
76
+ * @minLength 24
77
+ * @maxLength 24
78
+ * @pattern ^[a-fA-F0-9]{24}$
79
+ */
80
+ readonly userId: string;
81
+ }
82
+
83
+ export interface IProduct {
84
+ /**
85
+ * Product name
86
+ * @minLength 1
87
+ * @maxLength 100
88
+ */
89
+ name: string;
90
+
91
+ /**
92
+ * Product price in cents
93
+ * @minimum 0
94
+ * @maximum 1000000
95
+ * @multipleOf 1
96
+ */
97
+ price: number;
98
+
99
+ /**
100
+ * Product tags
101
+ * @minItems 1
102
+ * @maxItems 10
103
+ * @uniqueItems true
104
+ */
105
+ tags: string[];
106
+
107
+ /**
108
+ * Email for support
109
+ * @format email
110
+ */
111
+ supportEmail?: string;
112
+
113
+ /**
114
+ * Product website
115
+ * @format uri
116
+ * @pattern ^https://
117
+ */
118
+ website?: string;
119
+ }
120
+ ```
121
+
122
+ Supported JSDoc annotations include:
123
+
124
+ - **Strings**: `@minLength`, `@maxLength`, `@pattern`, `@format` (email, uri, uuid, date-time, etc.)
125
+ - **Numbers**: `@minimum`, `@maximum`, `@exclusiveMinimum`, `@exclusiveMaximum`, `@multipleOf`
126
+ - **Arrays**: `@minItems`, `@maxItems`, `@uniqueItems`
127
+ - **Objects**: `@minProperties`, `@maxProperties`
128
+ - **General**: `@description`, `@default`, `@examples`
129
+
130
+ ### 2. Add to your package.json scripts
131
+
132
+ ```json
133
+ { "scripts": { "generate-types": "ts-runtime-validation" } }
31
134
  ```
32
135
 
33
- ## CLI usage
136
+ ### 3. Generate validators
34
137
 
35
- Ensure your project files containing the schemas you want to validate end with the prefix `.jsonschema.ts`
138
+ ```bash
139
+ yarn generate-types
140
+ ```
36
141
 
142
+ ### 4. Use the generated validators
143
+
144
+ ```typescript
145
+ import { isValidSchema } from "./.ts-runtime-validation/isValidSchema";
146
+ import { IUser } from "./user.jsonschema";
147
+
148
+ const userData = await fetch("/api/user").then((r) => r.json());
149
+
150
+ if (isValidSchema(userData, "#/definitions/IUser")) {
151
+ // userData is now typed as IUser
152
+ console.log(userData.email); // TypeScript knows this is a string
153
+ } else {
154
+ console.error("Invalid user data received");
155
+ }
37
156
  ```
38
- Usage: ts-runtime-validation [options]
39
157
 
40
- Options:
41
- --glob Glob file path of typescript files to generate ts-interface -> json-schema validations - default: *.jsonschema.{ts,tsx}
42
- --rootPath <rootFolder> RootPath of source (default: "./src")
43
- --output <outputFolder> Code generation output directory (relative to root path) (default: "./.ts-runtime-validation")
44
- --tsconfigPath <tsconfigPath> Path to customt tsconfig (relative to root path) (default: "")
45
- --generate-helpers Only generate JSON schema without typescript helper files (default: true)
46
- --additionalProperties Allow additional properties to pass validation (default: false)
47
- -h, --help display help for command
48
- Done in 0.44s.
158
+ ## 📖 Usage
159
+
160
+ ### CLI Options
161
+
162
+ ```bash
163
+ ts-runtime-validation [options]
164
+
165
+ Core Options:
166
+ --glob <pattern> Glob pattern for schema files
167
+ (default: "*.jsonschema.{ts,tsx}")
168
+ --rootPath <rootFolder> Source directory root
169
+ (default: "./src")
170
+ --output <outputFolder> Output directory for generated files
171
+ (default: "./.ts-runtime-validation")
172
+ --tsconfigPath <path> Path to tsconfig.json
173
+ (default: "")
174
+ --generate-helpers Generate TypeScript helper files
175
+ (default: true)
176
+ --additionalProperties Allow additional properties in validation
177
+ (default: false)
178
+
179
+ Performance Options:
180
+ --cache Enable file caching for incremental builds
181
+ --no-parallel Disable parallel processing (enabled by default)
182
+ --verbose Enable detailed logging and debugging info
183
+ --progress Show progress bars and status updates
184
+
185
+ Output Optimization:
186
+ --minify Minify generated JSON schemas
187
+ --tree-shaking Generate tree-shaking friendly exports
188
+ --lazy-load Generate lazy-loaded validators
189
+
190
+ General:
191
+ -h, --help Display help information
49
192
  ```
50
193
 
51
- ## npm script usage
194
+ ### Generated Files
195
+
196
+ The tool generates optimized files in your output directory:
197
+
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 |
204
+
205
+ ### Programmatic API
206
+
207
+ ```typescript
208
+ import { SchemaGenerator } from "ts-runtime-validation";
209
+
210
+ // Basic usage
211
+ const generator = new SchemaGenerator({
212
+ glob: "**/*.jsonschema.ts",
213
+ rootPath: "./src",
214
+ output: "./validation",
215
+ helpers: true,
216
+ additionalProperties: false,
217
+ tsconfigPath: "",
218
+ });
219
+
220
+ await generator.Generate();
221
+
222
+ // Development configuration (fast iterations)
223
+ const devGenerator = new SchemaGenerator({
224
+ glob: "**/*.jsonschema.ts",
225
+ rootPath: "./src",
226
+ output: "./.ts-runtime-validation",
227
+ helpers: true,
228
+ additionalProperties: false,
229
+ tsconfigPath: "",
230
+ // Development optimizations
231
+ cache: true, // Enable incremental builds
232
+ progress: true, // Show progress feedback
233
+ verbose: true, // Detailed logging
234
+ parallel: true, // Faster processing
235
+ });
236
+
237
+ // Production configuration (optimized output)
238
+ const prodGenerator = new SchemaGenerator({
239
+ glob: "**/*.jsonschema.ts",
240
+ rootPath: "./src",
241
+ output: "./dist/validation",
242
+ helpers: true,
243
+ additionalProperties: false,
244
+ tsconfigPath: "./tsconfig.json",
245
+ // Production optimizations
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
251
+ });
252
+
253
+ // Large project configuration (memory efficient)
254
+ const largeProjectGenerator = new SchemaGenerator({
255
+ glob: "**/*.jsonschema.ts",
256
+ rootPath: "./src",
257
+ output: "./validation",
258
+ helpers: true,
259
+ additionalProperties: false,
260
+ tsconfigPath: "",
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
267
+ });
268
+
269
+ // Execute generation
270
+ try {
271
+ await generator.Generate();
272
+ console.log("Schema generation completed successfully!");
273
+ } catch (error) {
274
+ console.error("Generation failed:", error.message);
275
+ }
276
+
277
+ // Utility methods
278
+ generator.clearCache(); // Clear file cache
279
+ await generator.cleanOutput(); // Remove generated files
280
+ ```
52
281
 
53
- The intended use for ts-runtime-validation is as a npm script. Here it can also be tweaked to watch (eg. using nodemon)
282
+ ### Watch Mode & Development Workflows
54
283
 
55
284
  ```json
56
285
  {
57
286
  "scripts": {
58
- "generate-types": "ts-runtime-validation"
59
- },
60
- "devDependencies": {
61
- "ts-runtime-validation": "^1.4.1"
287
+ "generate-types": "ts-runtime-validation --cache --progress",
288
+ "generate-types:watch": "nodemon --watch 'src/**/*.jsonschema.ts' --exec 'yarn generate-types'",
289
+ "generate-types:dev": "ts-runtime-validation --cache --verbose --progress",
290
+ "generate-types:prod": "ts-runtime-validation --cache --minify --tree-shaking",
291
+ "generate-types:clean": "rimraf .ts-runtime-validation-cache && yarn generate-types"
62
292
  }
63
293
  }
64
294
  ```
65
295
 
66
- ## Example snippets
296
+ ### Custom File Patterns
67
297
 
68
- ### Type guard
298
+ ```bash
299
+ # Basic usage
300
+ ts-runtime-validation
69
301
 
70
- ```typescript
71
- import { isValidSchema } from "./.ts-runtime-validation/isValidSchema"; // this is autogenerated by the CLI as a helper file
302
+ # Custom file patterns
303
+ ts-runtime-validation --glob "**/*.types.ts"
304
+ ts-runtime-validation --glob "**/*.{types,schemas}.ts"
72
305
 
73
- if (isValidSchema(data, "#/definitions/ITypeA")) {
74
- // variable: data in this block will have typings for ITypeA
75
- } else {
76
- // type is invalid and not known here
77
- throw new Error("Failed to validate payload");
306
+ # Development workflow (fast iterations)
307
+ ts-runtime-validation --cache --progress --verbose
308
+
309
+ # Production build (optimized output)
310
+ ts-runtime-validation --cache --minify --tree-shaking
311
+
312
+ # Large projects (performance focused)
313
+ ts-runtime-validation --cache --progress --lazy-load
314
+
315
+ # Specific directories
316
+ ts-runtime-validation --rootPath "./src/api" --output "./api-validation"
317
+
318
+ # CI/CD optimized
319
+ ts-runtime-validation --cache --minify --no-parallel
320
+
321
+ # Debug mode (maximum verbosity)
322
+ ts-runtime-validation --verbose --progress --no-parallel
323
+ ```
324
+
325
+ ## 🚀 Performance & Optimization
326
+
327
+ ### Caching System
328
+
329
+ ts-runtime-validation includes an intelligent caching system for faster incremental builds:
330
+
331
+ ```bash
332
+ # Enable caching (recommended for development)
333
+ ts-runtime-validation --cache
334
+ ```
335
+
336
+ **How it works:**
337
+
338
+ - Generates MD5 hashes of source files to detect changes
339
+ - Stores cache in `.ts-runtime-validation-cache/`
340
+ - Only processes files that have been modified
341
+ - Provides significant speedup for large projects
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"
78
358
  }
79
359
  ```
80
360
 
81
- ### Type assertion
361
+ ### Performance Tips
362
+
363
+ **Development Workflow:**
364
+
365
+ ```bash
366
+ # Fast iterations with caching and progress
367
+ ts-runtime-validation --cache --progress --verbose
368
+ ```
369
+
370
+ **Production Builds:**
371
+
372
+ ```bash
373
+ # Optimized output for deployment
374
+ ts-runtime-validation --cache --minify --tree-shaking
375
+ ```
376
+
377
+ **Large Projects:**
378
+
379
+ ```bash
380
+ # Memory efficient processing
381
+ ts-runtime-validation --cache --lazy-load --progress
382
+ ```
383
+
384
+ ### Bundle Optimization
82
385
 
386
+ **Tree-shaking friendly exports:**
387
+
388
+ ```typescript
389
+ // With --tree-shaking flag
390
+ export type IUser = _IUser; // Individual exports
391
+ export type IProduct = _IProduct;
392
+
393
+ // Default behavior
394
+ namespace ValidationType {
395
+ // Namespace exports
396
+ export type IUser = _IUser;
397
+ }
83
398
  ```
84
- import * as schema from "../runtime-validation/validation.schema.json";
85
- import Ajv from "ajv";
86
- import { ISchema, schemas } from "../runtime-validation/SchemaDefinition";
87
399
 
88
- const validator = new Ajv({ allErrors: true });
89
- validator.compile(schema);
400
+ **Lazy-loaded validators:**
90
401
 
91
- export const assertValidSchema = <T extends keyof typeof schemas>(data: unknown, schemaKeyRef: T): data is ISchema[T] => {
92
- validator.validate(schemaKeyRef as string, data);
93
- if (validator.errors || Boolean(validator.errors)) {
94
- const error = { schemaKeyRef, errors: validator.errorsText(), data };
95
- if (process.env.ENVIRONMENT === "dev") {
96
- console.log(error);
97
- }
98
- throw new Error(JSON.stringify(error));
402
+ ```typescript
403
+ // With --lazy-load flag
404
+ let validator: any = null;
405
+ const getValidator = () => {
406
+ if (!validator) {
407
+ const Ajv = require("ajv");
408
+ validator = new Ajv({ allErrors: true });
409
+ validator.compile(schema);
99
410
  }
100
- return true;
411
+ return validator;
101
412
  };
102
413
  ```
103
414
 
104
- ## Contributing
415
+ ## ⚠️ Limitations
416
+
417
+ - **No duplicate type names** - Each interface/type must have a unique name across all schema files
418
+ - **TypeScript-only constructs** - Some advanced TypeScript features (like conditional types) may not be fully supported
419
+ - **Circular references** - Limited support for circular type references
420
+
421
+ ## 🤝 Contributing
422
+
423
+ We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
424
+
425
+ ### Development Setup
426
+
427
+ ```bash
428
+ # Clone the repository
429
+ git clone https://github.com/thegalah/ts-runtime-validation.git
430
+ cd ts-runtime-validation
431
+
432
+ # Install dependencies
433
+ yarn install
434
+
435
+ # Build the project
436
+ yarn build
437
+
438
+ # Run comprehensive test suite (103+ tests)
439
+ yarn test
440
+
441
+ # Link for local development
442
+ yarn link
443
+ ```
444
+
445
+ ### Architecture
446
+
447
+ ts-runtime-validation uses a modern service-oriented architecture:
448
+
449
+ - **FileDiscovery**: File system operations and intelligent caching
450
+ - **SchemaProcessor**: TypeScript AST processing with parallel execution
451
+ - **CodeGenerator**: Optimized TypeScript file generation
452
+ - **SchemaWriter**: Efficient file writing with minification
453
+ - **ProgressReporter**: User-friendly progress tracking
454
+
455
+ ### Contributing Guidelines
456
+
457
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed information about:
458
+
459
+ - Service-oriented architecture patterns
460
+ - Error handling strategies
461
+ - Performance optimization techniques
462
+ - Testing approaches and best practices
463
+
464
+ ## 🙏 Acknowledgments
465
+
466
+ Built with modern tools and optimized for performance:
467
+
468
+ - [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator) - TypeScript to JSON Schema conversion
469
+ - [ajv](https://github.com/ajv-validator/ajv) - Runtime JSON Schema validation
470
+ - [ts-morph](https://github.com/dsherret/ts-morph) - TypeScript AST manipulation and code generation
471
+ - [fdir](https://github.com/thecodrr/fdir) - Fast file system traversal
472
+ - [picomatch](https://github.com/micromatch/picomatch) - Efficient glob pattern matching
473
+
474
+ ## 📚 Related Projects & Comparisons
475
+
476
+ ### How ts-runtime-validation differs from alternatives:
477
+
478
+ | Library | Approach | When to Use |
479
+ | -------------------------------------------- | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
480
+ | **ts-runtime-validation** | Generates validators from existing TypeScript interfaces via CLI/build step | You already have TypeScript interfaces and want automatic validation without runtime dependencies or API changes |
481
+ | **[zod](https://github.com/colinhacks/zod)** | Define schemas in code that create both types and validators | You want to define your schema once and derive TypeScript types from it, with a runtime validation library |
482
+ | **[io-ts](https://github.com/gcanti/io-ts)** | Functional programming approach with codecs for encoding/decoding | You need bidirectional transformations and prefer functional programming patterns |
483
+ | **[yup](https://github.com/jquense/yup)** | Runtime schema builder with fluent API | You're working with forms/frontend validation and want a battle-tested solution with built-in error messages |
484
+
485
+ ### Key Differences:
486
+
487
+ **ts-runtime-validation**:
488
+
489
+ - ✅ **Zero runtime API** - Works with your existing TypeScript interfaces
490
+ - ✅ **Build-time generation** - No runtime overhead for schema creation
491
+ - ✅ **JSDoc validation rules** - Add constraints via comments
492
+ - ✅ **Intelligent caching** - Fast incremental builds with change detection
493
+ - ✅ **Performance optimized** - Parallel processing and bundle optimization
494
+ - ❌ **Requires build step** - Must regenerate when types change
495
+ - ❌ **No runtime schema composition** - Can't dynamically create schemas
496
+
497
+ **zod/io-ts/yup**:
498
+
499
+ - ✅ **Runtime flexibility** - Create and compose schemas dynamically
500
+ - ✅ **Single source of truth** - Schema and type defined together
501
+ - ✅ **No build step** - Works immediately in your code
502
+ - ❌ **Runtime overhead** - Schemas created at runtime
503
+ - ❌ **Duplicate type definitions** - Can't reuse existing TypeScript interfaces
504
+
505
+ Choose **ts-runtime-validation** when you:
506
+
507
+ - Have existing TypeScript interfaces you want to validate
508
+ - Prefer build-time code generation over runtime libraries
509
+ - Want to keep validation rules close to your type definitions via JSDoc
510
+ - Need minimal runtime dependencies
511
+ - Require high performance with caching and parallel processing
512
+ - Want bundle optimization (tree-shaking, lazy loading)
513
+ - Need incremental builds for large projects
514
+
515
+ Choose **alternatives** when you:
516
+
517
+ - Want to define schemas at runtime dynamically
518
+ - Prefer schema-first design (define validation, derive types)
519
+ - Need complex runtime transformations or coercions
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
+ ```
105
546
 
106
- Submit a PR
547
+ ### Cache-related issues
107
548
 
108
- ## License
549
+ The cache directory `.ts-runtime-validation-cache/` can occasionally become corrupted. If you experience unexpected behavior:
109
550
 
110
- MIT
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
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ICommandOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICommandOptions.js","sourceRoot":"","sources":["../src/ICommandOptions.ts"],"names":[],"mappings":""}