UNPKG

2.14 kBTypeScriptView Raw
1import { LoggerService } from '@nestjs/common/services/logger.service';
2import { Observable, ObservedValueOf, Subscription } from 'rxjs';
3import { BaseRpcContext } from '../ctx-host/base-rpc.context';
4import { ClientOptions, MessageHandler, MicroserviceOptions, MsPattern, ReadPacket, WritePacket } from '../interfaces';
5import { ConsumerDeserializer } from '../interfaces/deserializer.interface';
6import { ConsumerSerializer } from '../interfaces/serializer.interface';
7/**
8 * @publicApi
9 */
10export declare abstract class Server {
11 protected readonly messageHandlers: Map<string, MessageHandler<any, any, any>>;
12 protected readonly logger: LoggerService;
13 protected serializer: ConsumerSerializer;
14 protected deserializer: ConsumerDeserializer;
15 addHandler(pattern: any, callback: MessageHandler, isEventHandler?: boolean, extras?: Record<string, any>): void;
16 getHandlers(): Map<string, MessageHandler>;
17 getHandlerByPattern(pattern: string): MessageHandler | null;
18 send(stream$: Observable<any>, respond: (data: WritePacket) => unknown | Promise<unknown>): Subscription;
19 handleEvent(pattern: string, packet: ReadPacket, context: BaseRpcContext): Promise<any>;
20 transformToObservable<T>(resultOrDeferred: Observable<T> | Promise<T>): Observable<T>;
21 transformToObservable<T>(resultOrDeferred: T): never extends Observable<ObservedValueOf<T>> ? Observable<T> : Observable<ObservedValueOf<T>>;
22 getOptionsProp<T extends MicroserviceOptions['options'], K extends keyof T>(obj: T, prop: K, defaultValue?: T[K]): T[K];
23 protected handleError(error: string): void;
24 protected loadPackage<T = any>(name: string, ctx: string, loader?: Function): T;
25 protected initializeSerializer(options: ClientOptions['options']): void;
26 protected initializeDeserializer(options: ClientOptions['options']): void;
27 /**
28 * Transforms the server Pattern to valid type and returns a route for him.
29 *
30 * @param {string} pattern - server pattern
31 * @returns string
32 */
33 protected getRouteFromPattern(pattern: string): string;
34 protected normalizePattern(pattern: MsPattern): string;
35}