import { MonoTypeOperatorFunction, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { ServiceBusEvent } from '../interface/service-bus.type'; /** * 将流中的data换为serviceBusEvent */ export function dataToServiceBusEvent(event: ServiceBusEvent): MonoTypeOperatorFunction { return (source: Observable) => { return source.pipe( map((response) => { return { type: event.type, isRequest: false, data: response }; }) ); }; } /** * 将流中的serviceBusEvent转换为data * */ export function serviceBusEventToData(): MonoTypeOperatorFunction { return (source: Observable) => { return source.pipe( map((response: ServiceBusEvent) => { return response.data; }) ); }; }