@3d-outlet/common
v1.3.1
Published
Core shared components for Face3D microservice ecosystem
Downloads
290
Readme
🛠️ @3d-outlet/common
Common Utilities and Modules for 3D OUTLET Microservices
✨ Features
- 🔌 gRPC Client Integration - Simplified setup and usage of gRPC clients in NestJS.
- 🛠️ gRPC Client Factory - Centralized creation and management of gRPC clients.
- 🏗️ Injection Decorators - Convenient decorators for injecting gRPC clients into NestJS services.
- 📦 RPC Statuses - Common RPC status enumeration for error handling.
- 🔄 Conversion Utilities - Helper functions for data manipulation, such as converting
Timestampto ISO format.
📦 Installation
npm install @3d-outlet/common
# or
pnpm add @3d-outlet/common
# or
yarn add @3d-outlet/common
# or
bun add @3d-outlet/common🚀 Quick Start
Registering gRPC Clients
import { GrpcModule } from '@3d-outlet/common'
import { GRPC_CLIENTS } from '@3d-outlet/common/lib/grpc/registry/grpc.registry'
@Module({
imports: [
GrpcModule.register([
'AUTH_PACKAGE', // Example of registering a client for AUTH_PACKAGE
]),
],
})
export class AppModule {}Injecting gRPC Clients
import { Injectable } from '@nestjs/common'
import { ClientGrpc } from '@nestjs/microservices'
import { InjectGrpcClient } from '@3d-outlet/common'
import { AuthServiceClient } from '@3d-outlet/contracts' // Example client
@Injectable()
export class AuthService {
constructor(
@InjectGrpcClient('AUTH_PACKAGE') private readonly authClient: ClientGrpc,
) {}
onModuleInit() {
this.authServiceClient =
this.authClient.getService<AuthServiceClient>('AuthService')
}
// ... use authServiceClient
}Using Utilities
import { timestampToISO, RpcStatus } from '@3d-outlet/common'
import { Timestamp } from '@3d-outlet/contracts/gen/ts/google/protobuf/timestamp'
const grpcTimestamp: Timestamp = { seconds: 1678886400, nanos: 0 } // Example
const isoString = timestampToISO(grpcTimestamp)
console.log(isoString) // "2023-03-15T00:00:00.000Z"
console.log(RpcStatus.OK) // 0📁 Project Structure
common/
├── lib/ # TypeScript source files
│ ├── enums/ # Common enumerations, such as RpcStatus
│ ├── grpc/ # Modules and utilities for working with gRPC
│ │ ├── constants/ # gRPC constants
│ │ ├── decorators/ # Decorators for injecting gRPC clients
│ │ ├── factory/ # Factory for creating gRPC clients
│ │ └── registry/ # Registry of gRPC clients
│ └── utils/ # General utility functions
└── dist/ # Compiled JavaScript (after build)🛠️ Development
Prerequisites
- Node.js: >= 16.0.0
- TypeScript: ^5.9.3
Building the Package
# Install dependencies
npm install
# or
pnpm install
# or
bun install
# Build TypeScript
npm run build📝 License
ISC © TeaCoder & Ilnaz Mingaleev
👨💻 Authors
TeaCoder (Vadim)
- Email: [email protected]
Ilnaz Mingaleev
- Email: [email protected]
Made with ❤️ for the 3D OUTLET project (private repo)
Internal use only.
