UNPKG

6.36 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Type } from '@nestjs/common';
3import { ConnectionOptions } from 'tls';
4import { Transport } from '../enums/transport.enum';
5import { ChannelOptions } from '../external/grpc-options.interface';
6import { ConsumerConfig, ConsumerRunConfig, ConsumerSubscribeTopics, KafkaConfig, ProducerConfig, ProducerRecord } from '../external/kafka.interface';
7import { MqttClientOptions, QoS } from '../external/mqtt-options.interface';
8import { IORedisOptions } from '../external/redis.interface';
9import { RmqUrl } from '../external/rmq-url.interface';
10import { TcpSocket } from '../helpers';
11import { CustomTransportStrategy } from './custom-transport-strategy.interface';
12import { Deserializer } from './deserializer.interface';
13import { Serializer } from './serializer.interface';
14export type MicroserviceOptions = GrpcOptions | TcpOptions | RedisOptions | NatsOptions | MqttOptions | RmqOptions | KafkaOptions | CustomStrategy;
15/**
16 * @publicApi
17 */
18export interface CustomStrategy {
19 strategy: CustomTransportStrategy;
20 options?: {};
21}
22/**
23 * @publicApi
24 */
25export interface GrpcOptions {
26 transport?: Transport.GRPC;
27 options: {
28 url?: string;
29 maxSendMessageLength?: number;
30 maxReceiveMessageLength?: number;
31 maxMetadataSize?: number;
32 keepalive?: {
33 keepaliveTimeMs?: number;
34 keepaliveTimeoutMs?: number;
35 keepalivePermitWithoutCalls?: number;
36 http2MaxPingsWithoutData?: number;
37 http2MinTimeBetweenPingsMs?: number;
38 http2MinPingIntervalWithoutDataMs?: number;
39 http2MaxPingStrikes?: number;
40 };
41 channelOptions?: ChannelOptions;
42 credentials?: any;
43 protoPath: string | string[];
44 package: string | string[];
45 protoLoader?: string;
46 packageDefinition?: any;
47 gracefulShutdown?: boolean;
48 loader?: {
49 keepCase?: boolean;
50 alternateCommentMode?: boolean;
51 longs?: Function;
52 enums?: Function;
53 bytes?: Function;
54 defaults?: boolean;
55 arrays?: boolean;
56 objects?: boolean;
57 oneofs?: boolean;
58 json?: boolean;
59 includeDirs?: string[];
60 };
61 };
62}
63/**
64 * @publicApi
65 */
66export interface TcpOptions {
67 transport?: Transport.TCP;
68 options?: {
69 host?: string;
70 port?: number;
71 retryAttempts?: number;
72 retryDelay?: number;
73 serializer?: Serializer;
74 tlsOptions?: ConnectionOptions;
75 deserializer?: Deserializer;
76 socketClass?: Type<TcpSocket>;
77 };
78}
79/**
80 * @publicApi
81 */
82export interface RedisOptions {
83 transport?: Transport.REDIS;
84 options?: {
85 host?: string;
86 port?: number;
87 retryAttempts?: number;
88 retryDelay?: number;
89 /**
90 * Use `psubscribe`/`pmessage` to enable wildcards in the patterns
91 */
92 wildcards?: boolean;
93 serializer?: Serializer;
94 deserializer?: Deserializer;
95 } & IORedisOptions;
96}
97/**
98 * @publicApi
99 */
100export interface MqttOptions {
101 transport?: Transport.MQTT;
102 options?: MqttClientOptions & {
103 url?: string;
104 serializer?: Serializer;
105 deserializer?: Deserializer;
106 subscribeOptions?: {
107 /**
108 * The QoS
109 */
110 qos: QoS;
111 nl?: boolean;
112 rap?: boolean;
113 rh?: number;
114 };
115 userProperties?: Record<string, string | string[]>;
116 };
117}
118/**
119 * @publicApi
120 */
121export interface NatsOptions {
122 transport?: Transport.NATS;
123 options?: {
124 headers?: Record<string, string>;
125 authenticator?: any;
126 debug?: boolean;
127 ignoreClusterUpdates?: boolean;
128 inboxPrefix?: string;
129 encoding?: string;
130 name?: string;
131 user?: string;
132 pass?: string;
133 maxPingOut?: number;
134 maxReconnectAttempts?: number;
135 reconnectTimeWait?: number;
136 reconnectJitter?: number;
137 reconnectJitterTLS?: number;
138 reconnectDelayHandler?: any;
139 servers?: string[] | string;
140 nkey?: any;
141 reconnect?: boolean;
142 pedantic?: boolean;
143 tls?: any;
144 queue?: string;
145 serializer?: Serializer;
146 deserializer?: Deserializer;
147 userJWT?: string;
148 nonceSigner?: any;
149 userCreds?: any;
150 useOldRequestStyle?: boolean;
151 pingInterval?: number;
152 preserveBuffers?: boolean;
153 waitOnFirstConnect?: boolean;
154 verbose?: boolean;
155 noEcho?: boolean;
156 noRandomize?: boolean;
157 timeout?: number;
158 token?: string;
159 yieldTime?: number;
160 tokenHandler?: any;
161 [key: string]: any;
162 };
163}
164/**
165 * @publicApi
166 */
167export interface RmqOptions {
168 transport?: Transport.RMQ;
169 options?: {
170 urls?: string[] | RmqUrl[];
171 queue?: string;
172 prefetchCount?: number;
173 isGlobalPrefetchCount?: boolean;
174 queueOptions?: any;
175 socketOptions?: any;
176 noAck?: boolean;
177 consumerTag?: string;
178 serializer?: Serializer;
179 deserializer?: Deserializer;
180 replyQueue?: string;
181 persistent?: boolean;
182 headers?: Record<string, string>;
183 noAssert?: boolean;
184 /**
185 * Maximum number of connection attempts.
186 * Applies only to the consumer configuration.
187 * -1 === infinite
188 * @default -1
189 */
190 maxConnectionAttempts?: number;
191 };
192}
193/**
194 * @publicApi
195 */
196export interface KafkaParserConfig {
197 keepBinary?: boolean;
198}
199/**
200 * @publicApi
201 */
202export interface KafkaOptions {
203 transport?: Transport.KAFKA;
204 options?: {
205 /**
206 * Defaults to `"-server"` on server side and `"-client"` on client side.
207 */
208 postfixId?: string;
209 client?: KafkaConfig;
210 consumer?: ConsumerConfig;
211 run?: Omit<ConsumerRunConfig, 'eachBatch' | 'eachMessage'>;
212 subscribe?: Omit<ConsumerSubscribeTopics, 'topics'>;
213 producer?: ProducerConfig;
214 send?: Omit<ProducerRecord, 'topic' | 'messages'>;
215 serializer?: Serializer;
216 deserializer?: Deserializer;
217 parser?: KafkaParserConfig;
218 producerOnlyMode?: boolean;
219 };
220}