import type { ClientProxy } from '@nestjs/microservices' ; import { RpcException } from '@nestjs/microservices' ; import { plainToInstance } from 'class-transformer' ; import { catchError , firstValueFrom } from 'rxjs' ; import { PageTypeException } from '../exceptions/page-type.exception' ; import type { Constructor } from '../types' ; import type { PageDto } from './dto/page.dto' ; /**
 * Fixme: This class designed to use with @nestjs/microservices by extending and creating a new class.
 * TODO: Create Implementation and usage of it
 */ export class AbstractClientService < ActionType > { constructor ( private client ) { } public async send ( pattern , data ) ; public async send < R > ( pattern , data , returnDataOptions ) ; public async send < R > ( pattern , data , returnDataOptions ? ) ; public async send < R , I > ( pattern , data , returnDataOptions ? ) { const returnData = await firstValueFrom ( this . client . send ( pattern , data ) . pipe ( catchError ( ( err ) => { throw new RpcException ( err . error ) ; } ) ) , { defaultValue : undefined , } ) ; if ( returnDataOptions ?. isPage && ( ! returnData . data || ! returnData . meta ) ) { throw new PageTypeException ( ) ; } if ( ! returnDataOptions ?. class || returnDataOptions ?. isPage ) { return returnData ; } return plainToInstance ( returnDataOptions . class , returnData ) ; } }