Nestia: The Ultimate TypeScript SDK Generator for NestJS Applications
Introduction
Nestia is a revolutionary TypeScript SDK generator and runtime validator for NestJS applications, designed to eliminate redundant schema definitions and enhance development efficiency. Unlike traditional approaches that require multiple schema declarations, Nestia leverages pure TypeScript types to provide comprehensive validation and API documentation.
The Problem Nestia Solves
Traditional NestJS development faces several challenges:
- Triple schema definition requirement (TypeScript type, class-validator, @nestjs/swagger)
- Runtime-only validation errors that escape TypeScript compilation
- Performance overhead from class-validator and class-transformer
- Complex validation rule definitions
Key Features and Benefits
Pure TypeScript Approach
// Traditional NestJS approach with class-validator
export class ArticleDto {
@IsString()
@IsUUID()
@ApiProperty({ format: "uuid" })
id!: string;
@IsOptional()
@IsString()
@MinLength(5)
@MaxLength(100)
@ApiProperty({ nullable: true })
title?: string;
}
// Nestia's pure TypeScript approach
export interface IArticle {
id: string & tags.Format<"uuid">;
title?: string & tags.MinLength<5> & tags.MaxLength<100>;
}
Performance Benefits
Nestia offers remarkable performance improvements:
- Validation: 20,000x faster than class-validator
- JSON Serialization: 200x faster than class-transformer
- Zero runtime overhead through AOT compilation
- Optimized memory usage
SDK Generation
// Automatic type-safe SDK generation
const sdk = createAxiosSDK<typeof MyController>();
// Type-safe API calls
await sdk.articles.store({
title: "Hello World",
body: "Content",
files: []
});
Enhanced Validation System
- Pure TypeScript interface-based validation
- Compile-time type checking
- Built-in type-level validation rules
- Automatic error message generation
Getting Started
Installation
npm install @nestia/core
npm install -D @nestia/sdk
# Configure tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Basic Usage
import { TypedBody, TypedRoute } from "@nestia/core";
import { Controller } from "@nestjs/common";
@Controller("articles")
export class ArticlesController {
@TypedRoute.Post()
public async store(
@TypedBody() input: IArticle.ICreate
): Promise<IArticle> {
return {
...input,
id: "uuid-here",
created_at: new Date().toISOString()
};
}
}
Advanced Features
Type-Safe HTTP Requests
interface IArticle {
id: string & tags.Format<"uuid">;
title: string & tags.MinLength<3> & tags.MaxLength<50>;
body: string;
files: IAttachmentFile[];
created_at: string & tags.Format<"date-time">;
}
Performance Analysis
Benchmark Results
Comparative performance metrics:
-
Validation Speed
- Nestia: 2,000,000 ops/sec
- class-validator: 100 ops/sec
- Improvement: 20,000x faster
-
JSON Serialization
- Nestia: 200,000 ops/sec
- class-transformer: 1,000 ops/sec
- Improvement: 200x faster
Top comments (0)