Skip to content

nestlibs/nestlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3,634 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿชบ Nestlib โ€“ NestJS Modules & Decorators Monorepo

LSK.js NPM version NPM downloads Package size Ask us in Telegram

โค๏ธโ€๐Ÿ”ฅ Comprehensive collection of modules, decorators, and utilities for building powerful NestJS applications โค๏ธโ€๐Ÿ”ฅ

๐Ÿš€ Production Ready: Battle-tested modules used in production environments
๐Ÿ’Ž TypeScript: Full TypeScript support with strict type checking
โšก Fast: Optimized for performance with minimal overhead
๐Ÿ”ง Modular: Use only what you need, tree-shakeable packages
๐Ÿ“ฆ Well Documented: Comprehensive documentation and examples
๐ŸŽฏ Focused: Essential functionality without bloat

๐Ÿ“ฆ Packages

Package Version Size Description
@nestlib/access-logger npm size HTTP request logging middleware for NestJS
@nestlib/auth npm size Authentication helpers with OTP support
@nestlib/cache npm size Caching decorators and utilities
@nestlib/config npm size Configuration management module
@nestlib/crypto npm size Cryptographic operations (bcrypt, hashing)
@nestlib/decorators npm size Custom parameter decorators and transformers
@nestlib/interceptors npm size Response and error interceptors
@nestlib/lsk npm size LSK module wrapper for NestJS
@nestlib/mikro-orm npm size MikroORM logger factory integration
@nestlib/mutex npm size Distributed locking and mutex utilities
@nestlib/notify npm size Notification sender (Telegram, Slack, Email)
@nestlib/rabbitmq npm size RabbitMQ integration with RPC support
@nestlib/redis npm size Redis client and service wrapper
@nestlib/upload npm size File upload service for AWS S3
@nestlib/utils npm size Common utilities and helpers

๐Ÿš€ Quick Start

Access Logger

npm install @nestlib/access-logger
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { AccessLoggerMiddleware } from '@nestlib/access-logger';

@Module({})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AccessLoggerMiddleware)
      .forRoutes('*');
  }
}

Auth

npm install @nestlib/auth
import { AuthModule } from '@nestlib/auth';

@Module({
  imports: [AuthModule.forRoot({ ... })],
})
export class AppModule {}

Cache

npm install @nestlib/cache
import { Cache } from '@nestlib/cache';

@Controller('users')
export class UsersController {
  @Cache({ ttl: 60 })
  @Get(':id')
  async getUser(@Param('id') id: string) {
    return this.usersService.findOne(id);
  }
}

Config

npm install @nestlib/config
import { ConfigModule } from '@nestlib/config';

@Module({
  imports: [ConfigModule.forRoot()],
})
export class AppModule {}

Crypto

npm install @nestlib/crypto
import { CryptoService } from '@nestlib/crypto';

@Injectable()
export class AuthService {
  constructor(private cryptoService: CryptoService) {}

  async hashPassword(password: string) {
    return this.cryptoService.hash(password);
  }
}

Decorators

npm install @nestlib/decorators
import { Query, Data } from '@nestlib/decorators';

@Controller('search')
export class SearchController {
  @Get()
  async search(@Query('q') query: string, @Data() data: any) {
    // ...
  }
}

Interceptors

npm install @nestlib/interceptors
import { ResponseInterceptor, ErrorInterceptor } from '@nestlib/interceptors';

@UseInterceptors(ResponseInterceptor, ErrorInterceptor)
@Controller('api')
export class ApiController {}

Redis

npm install @nestlib/redis
import { RedisModule } from '@nestlib/redis';

@Module({
  imports: [RedisModule.forRoot({ ... })],
})
export class AppModule {}

RabbitMQ

npm install @nestlib/rabbitmq
import { RmqModule } from '@nestlib/rabbitmq';

@Module({
  imports: [RmqModule.forRoot({ ... })],
})
export class AppModule {}

โœจ Features

๐Ÿ” Access Logger

  • Request ID Generation: Unique request IDs for tracing
  • Smart Log Levels: Automatic log level based on status codes and response time
  • Comprehensive Logging: Method, URL, IP, user agent, status, duration, and more
  • WebSocket Support: Special handling for WebSocket connections
  • IP Detection: Automatic client IP extraction from headers

๐Ÿ” Auth

  • OTP Support: One-time password generation and validation
  • Session Management: Express session integration with MongoDB storage
  • Password Reset: Complete password reset flow with email support
  • User Models: Ready-to-use user and OTP models for MikroORM
  • Guards & Decorators: @Auth() decorator and AuthGuard for route protection

๐Ÿ’พ Cache

  • Decorator-based: @Cache() and @LruCache() decorators
  • LRU Cache: In-memory LRU cache support
  • Cache Manager Integration: Works with NestJS Cache Manager
  • Cache Invalidation: @IgnoreCache() decorator for selective invalidation

โš™๏ธ Config

  • Environment Variables: Automatic .env file loading
  • Type-safe Configuration: Full TypeScript support
  • Module Integration: Seamless NestJS Config module integration
  • Validation: Configuration validation with error handling

๐Ÿ”’ Crypto

  • Password Hashing: bcrypt and bcryptjs support
  • Secure Operations: Cryptographic utilities for hashing and comparison
  • Async Operations: Promise-based API

๐ŸŽจ Decorators

  • Parameter Decorators: @Query(), @Data(), @FindParams(), @QueryOrBody()
  • Transformers: @Trim(), @ToLowerCase() for data transformation
  • Validation: Integrated with class-validator

๐Ÿ›ก๏ธ Interceptors

  • Response Interceptor: Standardized API response format
  • Error Interceptor: Comprehensive error handling and formatting
  • Pretty Errors: Human-readable error messages in development
  • Request Context: Request ID and metadata tracking

๐Ÿ”„ Mutex

  • Distributed Locking: Redis-based distributed locks
  • In-memory Locks: Async lock support for single-instance applications
  • Decorator Support: @Lock() decorator for automatic locking
  • Timeout Handling: Configurable lock timeouts

๐Ÿ“ข Notify

  • Multi-channel: Telegram, Slack, and Email support
  • Service Integration: Injectable NotifyService for easy use
  • Error Notifications: Automatic error reporting

๐Ÿฐ RabbitMQ

  • RPC Support: @RmqRPC() decorator for RPC handlers
  • Message Publishing: Easy message publishing with RmqService
  • Error Handling: Automatic error callbacks and retries
  • Interceptor: Request/response logging and error handling

๐Ÿ”ด Redis

  • Service Wrapper: Simplified Redis client interface
  • Connection Management: Automatic connection handling
  • Type Safety: Full TypeScript support

๐Ÿ“ค Upload

  • AWS S3 Integration: Direct S3 upload support
  • Presigned URLs: Generate presigned URLs for secure uploads
  • File Management: Upload, delete, and manage files in S3

๐Ÿ› ๏ธ Utils

  • Exception Filter: AnyExceptionFilter for global error handling
  • Validation Pipe: AnyValidationPipe for request validation
  • Logger Factory: createNestLogger for consistent logging
  • Time Decorator: @Time() decorator for performance measurement

๐Ÿ›  Development

# Install dependencies
pnpm install

# Build all packages
pnpm run build

# Run tests
pnpm run test

# Release packages
pnpm run release

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork it (https://github.com/lskjs/nestlib/fork)
  2. Create your feature branch (git checkout -b features/fooBar)
  3. Commit your changes (git commit -am 'feat: Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

๐Ÿ“ License

MIT ยฉ Igor Suvorov

๐Ÿ”— Links


@nestlib โ€“ Comprehensive modules and decorators for NestJS ๐ŸŽฏ

About

Module & Decorator collection for Nest.js

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

โšก