Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// grpc streaming methods
@GrpcStreamMethod('HeroService')
async getHeroByIdStream(messages: Observable): Promise {
return new Promise((resolve, reject) => {
messages.subscribe(msg => {
resolve(this.items.find(({ id }) => id === msg.id));
}, err => {
reject(err);
});
});
}
@GrpcStreamMethod('HeroService')
async listHeroesByNameStream(messages: Observable): Promise {
return new Promise((resolve, reject) => {
messages.subscribe(msg => {
resolve({ heroes: this.items.filter(({ name }) => name.startsWith(msg.name)) });
}, err => {
reject(err);
});
});
}
}
// grpc methods
@GrpcMethod('HeroService')
getHeroById(data: HeroById, metadata: any): Hero {
return this.items.find(({ id }) => id === data.id);
}
@GrpcMethod('HeroService')
listHeroesByName(data: HeroByName, metadata: any): object {
return { heroes: this.items.filter(({ name }) => name.startsWith(data.name)) };
}
// grpc streaming methods
@GrpcStreamMethod('HeroService')
async getHeroByIdStream(messages: Observable): Promise {
return new Promise((resolve, reject) => {
messages.subscribe(msg => {
resolve(this.items.find(({ id }) => id === msg.id));
}, err => {
reject(err);
});
});
}
@GrpcStreamMethod('HeroService')
async listHeroesByNameStream(messages: Observable): Promise {
return new Promise((resolve, reject) => {
messages.subscribe(msg => {
resolve({ heroes: this.items.filter(({ name }) => name.startsWith(msg.name)) });
}, err => {
return of({
id: 1,
itemTypes: [1],
shipmentType: {
from: 'test',
to: 'test1',
carrier: 'test-carrier',
},
});
}
/**
* GRPC stub implementation for sync stream method
* @param messages
*/
@GrpcStreamMethod('orders.OrderService')
async sync(messages: Observable): Promise {
const s = new Subject();
const o = s.asObservable();
messages.subscribe(msg => {
s.next({
id: 1,
itemTypes: [1],
shipmentType: {
from: 'test',
to: 'test1',
carrier: 'test-carrier',
},
});
});
return o;
}