bởi stellar

NestJS is a TypeScript-first Node.js framework for building efficient, scalable, and maintainable server-side applications using OOP, FP, and FRP patterns with Express or Fastify under the hood.
@nestjs/common)This block provides the core building blocks of the NestJS framework: decorators, pipes, guards, interceptors, filters, exceptions, and interfaces. It is the primary import surface for any NestJS application and is used by developers building structured, TypeScript-first HTTP or hybrid Node.js services.
decorators/ - Class and method decorators split into core/, http/, and modules/ sub-groupsenums/ - Enumerations for HTTP status codes, request methods, route param types, shutdown signals, and versioningexceptions/ - Full set of typed HTTP exceptions (e.g. NotFoundException, BadRequestException)file-stream/ - Interfaces and utilities for streaming file responsesinterfaces/ - TypeScript interfaces for providers, modules, guards, pipes, interceptors, and lifecycle hooksmodule-utils/ - Utilities for building configurable dynamic modulespipes/ - Built-in pipes including ValidationPipe and ParseIntPipeserializer/ - ClassSerializerInterceptor and related serialization utilitiesservices/ - HttpService and Logger service implementationsutils/ - Internal utility functions (shared helpers)constants.ts - Framework-wide constant valuesindex.ts - Barrel re-export of all public API symbolsnpm install reflect-metadata rxjs class-transformer class-validator tslib
npm install iterare fast-safe-stringify fast-json-stringify object-hash uid
npm install path-to-regexp file-type load-esm ansis
reflect-metadata must be imported once at the application entry point before any NestJS code runs. No native build steps, pod installs, or binary linking are required.
Copy the source/ directory into your project, e.g. src/vendor/nestjs-common/.
Ensure your tsconfig.json has the following compiler options:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2020",
"module": "commonjs",
"strict": true
}
}
Khởi chạy sandbox cách ly và chạy phía máy chủ — không cần cài đặt cục bộ.
Tetrees AI Review cho phiên bản này
This Express backend / api completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Quy trình avcp-2026-08-04.1 · SHA-256 138004a6013e517d…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Đã đánh giá 4 thg 8, 2026
Đưa sản phẩm này thẳng vào AI IDE, trình tạo web hoặc cloud IDE của bạn.
Kết nối Tetrees với AI IDE tương thích để liệt kê sản phẩm bạn sở hữu và nhận ZIP đã xác minh mà không cấp quyền tải lên của người bán.
Chưa có đánh giá.
Sign in to join the discussion
Loading discussion…
{
"compilerOptions": {
"paths": {
"@nestjs/common": ["./src/vendor/nestjs-common/index.ts"]
}
}
}
main.ts), import reflect-metadata before anything else:import 'reflect-metadata';
function Injectable(options?: { scope?: Scope }): ClassDecorator;
Marks a class as a NestJS provider that can be injected via the DI container. Use it on any service, repository, or helper class that needs to participate in dependency injection.
function Controller(prefix?: string | string[]): ClassDecorator;
function Controller(options: ControllerOptions): ClassDecorator;
Declares a class as an HTTP controller and optionally sets a route prefix. Apply it to any class that handles incoming HTTP requests; NestJS will scan it for route handler decorators such as @Get and @Post.
function Module(metadata: ModuleMetadata): ClassDecorator;
Defines a NestJS module. ModuleMetadata accepts imports, controllers, providers, and exports arrays. Every NestJS application is composed of at least one module decorated with @Module.
class HttpException extends Error {
constructor(response: string | Record<string, unknown>, status: number, options?: HttpExceptionOptions);
getStatus(): number;
getResponse(): string | object;
}
Base class for all HTTP exceptions. Extend it to create custom error types, or use the pre-built subclasses (NotFoundException, BadRequestException, etc.) for standard HTTP status codes.
function SetMetadata<K = string, V = unknown>(metadataKey: K, metadataValue: V): CustomDecorator<K>;
Attaches arbitrary metadata to a class or method. Typically paired with a custom Reflector call inside a guard or interceptor to implement role-based access control or feature flags.
function UseGuards(...guards: (CanActivate | Function)[]): MethodDecorator & ClassDecorator;
Binds one or more guards to a controller or route handler. Guards run before the route handler and can short-circuit the request pipeline by returning false or throwing an exception.
A typical CRUD setup: a provider injected into a controller that handles a GET route.
import 'reflect-metadata';
import {
Controller,
Get,
Injectable,
Module,
NotFoundException,
} from './src/vendor/nestjs-common/index';
@Injectable()
class CatsService {
private cats = [{ id: 1, name: 'Tom' }];
findOne(id: number) {
const cat = this.cats.find(c => c.id === id);
if (!cat) throw new NotFoundException(`Cat #${id} not found`);
return cat;
}
}
@Controller('cats')
class CatsController {
constructor(private readonly catsService: CatsService) {}
@Get(':id')
getOne() {
return this.catsService.findOne(1);
}
}
@Module({
controllers: [CatsController],
providers: [CatsService],
})
class CatsModule {}
Attach role metadata to a route and read it inside a guard.
import 'reflect-metadata';
import {
SetMetadata,
UseGuards,
CanActivate,
ExecutionContext,
Injectable,
Controller,
Get,
} from './src/vendor/nestjs-common/index';
const Roles = (...roles: string[]) => SetMetadata('roles', roles);
@Injectable()
class RolesGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
// In a real app, retrieve Reflector from DI and read metadata
const request = context.switchToHttp().getRequest();
return request.user?.role === 'admin';
}
}
@Controller('admin')
class AdminController {
@Get()
@Roles('admin')
@UseGuards(RolesGuard)
dashboard() {
return { status: 'ok' };
}
}
Extend HttpException or use a built-in subclass for structured error responses.
import 'reflect-metadata';
import {
HttpException,
HttpStatus,
BadRequestException,
UnprocessableEntityException,
} from './src/vendor/nestjs-common/index';
// Using a built-in subclass
function validateAge(age: number) {
if (age < 0) {
throw new BadRequestException('Age must be a positive number');
}
}
// Using a custom structured response
function requireFeatureFlag(flag: string) {
if (!flag) {
throw new HttpException(
{ statusCode: 403, message: 'Feature not enabled', error: 'Forbidden' },
HttpStatus.FORBIDDEN,
);
}
}
// Unprocessable entity with validation errors
function throwValidation() {
throw new UnprocessableEntityException({
message: 'Validation failed',
fields: { email: 'must be a valid email' },
});
}
index.ts - Root barrel; re-exports everything from decorators, enums, exceptions, file-stream, and interfaces. Import from here.decorators/core/ - DI and metadata decorators: @Injectable, @Inject, @Controller, @Catch, @UseGuards, @UseInterceptors, @UsePipes, @SetMetadata, @Optional, @Version, applyDecorators.decorators/http/ - HTTP route decorators: @Get, @Post, @Put, etc. (request-mapping), route param decorators (@Param, @Body, @Query), @Header, @Redirect, @Render, @Sse, @HttpCode.decorators/modules/ - Module-level decorators: @Module and @Global.enums/ - HttpStatus, RequestMethod, RouteParamtypes, ShutdownSignal, VersionType enumerations.exceptions/ - One file per HTTP error class plus HttpException base and IntrinsicException.file-stream/ - Interfaces and helpers for StreamableFile responses.interfaces/ - TypeScript interfaces (PipeTransform, CanActivate, NestInterceptor, ExceptionFilter, lifecycle hooks, provider shapes, etc.).module-utils/ - Helpers for building ConfigurableModuleBuilder patterns.pipes/ - ValidationPipe, ParseIntPipe, ParseBoolPipe, and other built-in pipes.serializer/ - ClassSerializerInterceptor and ClassSerializerContextOptions.services/ - Logger and ConsoleLogger implementations.utils/ - Internal helpers (not part of the public API).constants.ts - Shared framework constants (metadata keys, tokens).reflect-metadata import: Decorators silently fail at runtime. Fix: add import 'reflect-metadata' as the very first line of your entry file.emitDecoratorMetadata not enabled: Constructor parameter types are not emitted, breaking DI. Fix: set "emitDecoratorMetadata": true in tsconfig.json.load-esm: Some transitive deps use ESM. Fix: set "module": "node16" or "nodenext" only if your whole project is ESM; otherwise stick with "commonjs".class-validator / class-transformer version mismatch: ValidationPipe requires compatible major versions. Fix: pin class-validator@^0.14 and class-transformer@^0.5 together.path-to-regexp v8 breaking change: NestJS 11 requires path-to-regexp@^8. If another dep installs v6 or v7, hoist the v8 version in package.json overrides.@UseGuards, @UseInterceptors, and @UsePipes execute bottom-up when stacked. Fix: place more specific decorators closer to the method signature.I have added the NestJS Common source code to `src/vendor/nestjs-common/`
and there is a USAGE.md file at the root of that directory.
Upstream package: @nestjs/core@11.1.10 / @nestjs/common
Source root: src/vendor/nestjs-common/
USAGE.md: src/vendor/nestjs-common/USAGE.md
Please integrate this into my existing project step by step:
1. Read USAGE.md fully before writing any code.
2. Add `import 'reflect-metadata'` to my entry file if not already present.
3. Enable `experimentalDecorators` and `emitDecoratorMetadata` in tsconfig.json.
4. Add a tsconfig path alias mapping `@nestjs/common` to `src/vendor/nestjs-common/index.ts`.
5. Create a sample module, controller, and injectable service using only the
exports visible in src/vendor/nestjs-common/index.ts.
6. Show me how to wire it into my existing Express app or NestFactory bootstrap.
7. Point out any dependency version conflicts in my package.json and suggest fixes.
This source is part of the NestJS framework, copyright Kamil Mysliwiec, licensed under the MIT License. See source/PACKAGE.md or the upstream repository for full license text. Upstream npm package: @nestjs/common.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
Hướng dẫn cài đặt đầy đủ và prompt tích hợp sẽ mở khóa sau khi mua.
Automation, Utilities & Developer Tools
Miễn phí