import { getService } from '@loopback/service-proxy' ; import { inject , Provider , bind } from '@loopback/core' ; import { RecommenderGrpcDataSource } from '../datasources' ; import { Product } from '../models' ; import { RecommenderService , recommender } from './recommender.service' ; export interface RecommenderGrpc { recommend ( req ) : Promise < { products : Product [ ] ; } > ; } /**
 * gRPC based recommender service
 */ @ bind ( recommender ( 'grpc' ) ) export class RecommenderGrpcServiceProvider implements Provider < RecommenderService > { constructor ( @ inject ( 'datasources.recommender_grpc' ) protected dataSource = new RecommenderGrpcDataSource ( ) ) { } async value ( ) { const grpcService = await getService < RecommenderGrpc > ( this . dataSource ) ; const service = { getProductRecommendations : async ( userId ) => { const res = await grpcService . recommend ( { userId } ) ; return res . products ; } , } ; return service ; } }