New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

@galaxy-stack/orbit-common

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@galaxy-stack/orbit-common

Common decorators, pipes, guards, interceptors for Orbit

Source
npmnpm
Version
0.1.5
Version published
Weekly downloads
4.3K
Maintainers
1
Weekly downloads
 
Created
Source

@galaxy-stack/orbit-common

Mô tả

Package chứa các decorators, pipes, guards, interceptors và exceptions dùng chung trong Orbit framework.

Tính năng chính

1. HTTP Decorators

import { 
  Controller, 
  Get, Post, Put, Patch, Delete,
  Body, Query, Param, Headers, Req, Res
} from '@galaxy-stack/orbit-common';

@Controller('api')
class ApiController {
  @Get('items')
  getItems(@Query('page') page: string) {}

  @Post('items')
  createItem(@Body() data: any) {}
}

2. Built-in Pipes

  • ParseIntPipe: Chuyển string thành number
  • ParseFloatPipe: Chuyển string thành float
  • ParseBoolPipe: Chuyển string thành boolean
  • ParseArrayPipe: Chuyển string thành array
  • DefaultValuePipe: Giá trị mặc định
  • TrimPipe: Xóa khoảng trắng
@Get(':id')
getUser(@Param('id', ParseIntPipe) id: number) {
  // id đã được convert sang number
}

3. HTTP Exceptions

import {
  BadRequestException,
  UnauthorizedException,
  ForbiddenException,
  NotFoundException,
  ConflictException,
  InternalServerErrorException,
} from '@galaxy-stack/orbit-common';

throw new NotFoundException('User not found');

4. Guards

import { CanActivate, ExecutionContext } from '@galaxy-stack/orbit-common';

class AuthGuard implements CanActivate {
  canActivate(context: ExecutionContext): boolean {
    const request = context.switchToHttp().getRequest();
    return !!request.headers.authorization;
  }
}

5. Interceptors

import { Interceptor, ExecutionContext } from '@galaxy-stack/orbit-common';

class LoggingInterceptor implements Interceptor {
  async intercept(context: ExecutionContext, next: () => Promise<any>) {
    console.log('Before...');
    const result = await next();
    console.log('After...');
    return result;
  }
}

Cách sử dụng

import { 
  Controller, Get, UseGuards, UsePipes,
  ParseIntPipe, AuthGuard 
} from '@galaxy-stack/orbit-common';

@Controller('users')
@UseGuards(AuthGuard)
class UserController {
  @Get(':id')
  @UsePipes(ParseIntPipe)
  getUser(@Param('id') id: number) {
    return { id };
  }
}

FAQs

Package last updated on 22 Sep 2026

Related posts