File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,5 +11,6 @@ export * from './decorators';
1111export * from './enums' ;
1212export * from './exceptions' ;
1313export * from './interfaces' ;
14+ export * from './module' ;
1415export * from './nest-microservice' ;
1516export * from './server' ;
Original file line number Diff line number Diff line change 1+ import { getClientToken } from './clients.utils' ;
2+
3+ export const InjectClient = ( name : string ) => getClientToken ( name ) ;
Original file line number Diff line number Diff line change 1+ import { DynamicModule , Module } from '@nestjs/common' ;
2+ import { ClientProxyFactory } from 'client' ;
3+ import { getClientToken } from './clients.utils' ;
4+ import { ClientsModuleOptions } from './interfaces/clients-module.interface' ;
5+
6+ @Module ( { } )
7+ export class ClientsModule {
8+ static register ( options : ClientsModuleOptions ) : DynamicModule {
9+ const clients = ( options || [ ] ) . map ( item => ( {
10+ provide : getClientToken ( item . name ) ,
11+ useValue : ClientProxyFactory . create ( item . options ) ,
12+ } ) ) ;
13+ return {
14+ module : ClientsModule ,
15+ providers : clients ,
16+ exports : clients ,
17+ } ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ export const getClientToken = ( name : string ) => `${ name . toUpperCase ( ) } _CLIENT` ;
Original file line number Diff line number Diff line change 1+ export * from './clients.decorators' ;
2+ export * from './clients.module' ;
3+ export * from './clients.utils' ;
Original file line number Diff line number Diff line change 1+ import { ClientOptions } from '../../interfaces' ;
2+
3+ export interface ClientProviderOptions {
4+ name : string ;
5+ options : ClientOptions ;
6+ }
7+
8+ export interface ClientsModuleOptions extends Array < ClientProviderOptions > { }
You can’t perform that action at this time.
0 commit comments