- TypeScript 82.6%
- Shell 14.4%
- JavaScript 3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| bench | ||
| scripts | ||
| src | ||
| .gitignore | ||
| .nvmrc | ||
| .swcrc | ||
| LICENSE.md | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| rspack.config.js | ||
| tsconfig.json | ||
ð¡ï¸ Node.js Data Validation & High-Performance Tooling Playground
A technical exploration into modern Type-Safe Data Validation and the High-Performance Tooling (Go & Rust) ecosystem. This project analyzes the intersection of Runtime Safety, Developer Experience (DX), and Production Performance (Bundle Size/Tree-shaking).
ðï¸ Architectural Concepts
1. Validation as a Boundary ("Parse, Don't Validate")
This project implements the "Parse, Don't Validate" philosophy: data is not just checked for correctness but is transformed into trusted internal types at the application boundary (API Gateway, Database Layer).
2. Schema-Driven Type Inference
We prioritize libraries that support Automatic Type Inference. By defining a schema once, both the runtime validator and the TypeScript interfaces are derived, eliminating manual interface drift and ensuring synchronization between code and data.
ð Benchmarks & Comparative Analysis
The following data represents the "bundle tax" of adding validation to an application, measured using esbuild (Minified + Gzipped).
Library Bundle Size (scripts/bundle-size.sh)
| Library | Minified | Gzipped | Verdict |
|---|---|---|---|
| Valibot | 4.0K | 1.6K | Best for Edge/Web. Modular, functional API allows for aggressive tree-shaking. |
| Ajv | 114K | 35K | Best for Backend. High performance via JSON Schema pre-compilation. |
| Joi | 174K | 56K | Node-Specific. Powerful declarative API, but lacks native TS inference. |
| Zod | 304K | 61K | Industry Standard. Comprehensive feature set and first-class TS integration. |
ð ï¸ Tooling Comparison: Go (esbuild) vs. Rust (Rspack)
| Tool | Ecosystem | Language | Core Strength |
|---|---|---|---|
| esbuild | Bundler/Minifier | Go | Speed-focused, zero-config bundling. |
| SWC | Transpiler | Rust | High-speed single-file transformations (Babel replacement). |
| Rspack | Optimized Bundler | Rust | Webpack compatibility with Rust-based performance. |
ð¬ Insight: Tree-Shaking Efficiency
During benchmarking, a significant difference was observed in how Rspack (Rust) and esbuild (Go) handle the zod library:
- esbuild output: ~304KB
- Rspack output: ~97KB Conclusion: Rspack's dependency graph analysis is more effective at pruning unused code from monolithic libraries like Zod compared to esbuild's simpler, faster approach.
ð Implementation Patterns
The src/ directory contains implementations of several validation patterns:
src/01-parse-dont-validate.ts: Data transformation (e.g., strings toDateobjects) during the parsing phase.src/06-api-gateway.ts: Discriminated Unions and RFC 7807 (Problem Details) for standardized, machine-readable error responses.src/07-branded-types.ts: Branded Types to prevent "Primitive Obsession" (e.g., preventing aUserIdfrom being used where anOrderIdis expected).src/08-recursive-schemas.ts: Handling self-referential structures (like categories or file systems) withz.lazy().
ð Usage
Installation
pnpm install
Running Benchmarks
pnpm run bench:size # Analyze library bundle sizes
pnpm run bench:tools # Compare esbuild (Go) vs Rspack (Rust)
Running Demos
pnpm run demo:parse # Parse, Don't Validate + Transformation
pnpm run demo:branded # Branded Types (Domain Safety)
pnpm run demo:api # RFC 7807 Standardized Errors
pnpm run demo:recursive # Recursive Schema Handling
ð Summary
For client-side and edge environments where bundle size is critical, Valibot is the recommended choice. For backend-heavy TypeScript projects requiring the best DX and feature set, Zod paired with Rspack provides the optimal balance of type safety and bundle efficiency.