Skip to content

Commit 3ad570e

Browse files
bugfix(@nestjs/microservices) extract external typings nestjs#594
1 parent 5cfb0bf commit 3ad570e

19 files changed

Lines changed: 796 additions & 23 deletions

packages/common/interfaces/external/cors-options.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @see https://github.com/expressjs/cors
3+
*/
14
export type CustomOrigin = (
25
requestOrigin: string,
36
callback: (err: Error | null, allow?: boolean) => void,
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* @see https://github.com/mqttjs/MQTT.js/
3+
*/
4+
export declare type QoS = 0 | 1 | 2;
5+
6+
export interface MqttClientOptions extends ISecureClientOptions {
7+
port?: number; // port is made into a number subsequently
8+
host?: string; // host does NOT include port
9+
hostname?: string;
10+
path?: string;
11+
protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs';
12+
13+
wsOptions?: {
14+
[x: string]: any;
15+
};
16+
/**
17+
* 10 seconds, set to 0 to disable
18+
*/
19+
keepalive?: number;
20+
/**
21+
* 'mqttjs_' + Math.random().toString(16).substr(2, 8)
22+
*/
23+
clientId?: string;
24+
/**
25+
* 'MQTT'
26+
*/
27+
protocolId?: string;
28+
/**
29+
* 4
30+
*/
31+
protocolVersion?: number;
32+
/**
33+
* true, set to false to receive QoS 1 and 2 messages while offline
34+
*/
35+
clean?: boolean;
36+
/**
37+
* 1000 milliseconds, interval between two reconnections
38+
*/
39+
reconnectPeriod?: number;
40+
/**
41+
* 30 * 1000 milliseconds, time to wait before a CONNACK is received
42+
*/
43+
connectTimeout?: number;
44+
/**
45+
* the username required by your broker, if any
46+
*/
47+
username?: string;
48+
/**
49+
* the password required by your broker, if any
50+
*/
51+
password?: string;
52+
/**
53+
* a any for the incoming packets
54+
*/
55+
incomingStore?: any;
56+
/**
57+
* a any for the outgoing packets
58+
*/
59+
outgoingStore?: any;
60+
queueQoSZero?: boolean;
61+
reschedulePings?: boolean;
62+
servers?: Array<{
63+
host: string;
64+
port: number;
65+
}>;
66+
/**
67+
* true, set to false to disable re-subscribe functionality
68+
*/
69+
resubscribe?: boolean;
70+
/**
71+
* a message that will sent by the broker automatically when the client disconnect badly.
72+
*/
73+
will?: {
74+
/**
75+
* the topic to publish
76+
*/
77+
topic: string;
78+
/**
79+
* the message to publish
80+
*/
81+
payload: string;
82+
/**
83+
* the QoS
84+
*/
85+
qos: QoS;
86+
/**
87+
* the retain flag
88+
*/
89+
retain: boolean;
90+
};
91+
transformWsUrl?: (
92+
url: string,
93+
options: any,
94+
client: any,
95+
) => string;
96+
}
97+
export interface ISecureClientOptions {
98+
/**
99+
* optional private keys in PEM format
100+
*/
101+
key?: string | string[] | Buffer | Buffer[] | Object[];
102+
/**
103+
* optional cert chains in PEM format
104+
*/
105+
cert?: string | string[] | Buffer | Buffer[];
106+
/**
107+
* Optionally override the trusted CA certificates in PEM format
108+
*/
109+
ca?: string | string[] | Buffer | Buffer[];
110+
rejectUnauthorized?: boolean;
111+
}
112+
export interface IClientPublishOptions {
113+
/**
114+
* the QoS
115+
*/
116+
qos: QoS;
117+
/**
118+
* the retain flag
119+
*/
120+
retain?: boolean;
121+
/**
122+
* whether or not mark a message as duplicate
123+
*/
124+
dup?: boolean;
125+
}
126+
export interface IClientSubscribeOptions {
127+
/**
128+
* the QoS
129+
*/
130+
qos: QoS;
131+
}
132+
export interface IClientReconnectOptions {
133+
/**
134+
* a any for the incoming packets
135+
*/
136+
incomingStore?: any;
137+
/**
138+
* a any for the outgoing packets
139+
*/
140+
outgoingStore?: any;
141+
}

packages/common/interfaces/external/multer-options.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @see https://github.com/expressjs/multer
3+
*/
14
export interface MulterOptions {
25
dest?: string;
36
/** The storage engine to use for uploaded files. */

packages/common/interfaces/external/serve-static-options.interface.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/// Reference: https://www.npmjs.com/package/@types/serve-static
2-
1+
/**
2+
* @see https://www.npmjs.com/package/@types/serve-static
3+
*/
34
export interface ServeStaticOptions {
45
/**
56
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
@@ -65,4 +66,4 @@ export interface ServeStaticOptions {
6566
* stat the stat object of the file that is being sent
6667
*/
6768
setHeaders?: (res, path: string, stat: any) => any;
68-
}
69+
}

packages/common/interfaces/microservices/microservice-configuration.interface.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Transport } from '../../enums/transport.enum';
22
import { CustomTransportStrategy } from './custom-transport-strategy.interface';
3-
import { IClientOptions } from 'mqtt';
4-
import { ServerCredentials } from 'grpc';
3+
import { MqttClientOptions } from '../external/mqtt-options.interface';
54

65
export type MicroserviceOptions =
76
| GrpcOptions
@@ -20,7 +19,7 @@ export interface GrpcOptions {
2019
transport?: Transport.GRPC;
2120
options: {
2221
url?: string;
23-
credentials?: ServerCredentials;
22+
credentials?: any;
2423
protoPath: string;
2524
package: string;
2625
};
@@ -47,7 +46,7 @@ export interface RedisOptions {
4746

4847
export interface MqttOptions {
4948
transport?: Transport.MQTT;
50-
options?: IClientOptions & {
49+
options?: MqttClientOptions & {
5150
url?: string;
5251
};
5352
}

packages/core/exceptions/exceptions-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class ExceptionsHandler {
3737
statusCode: exception.getStatus(),
3838
message: res,
3939
};
40+
4041
this.applicationRef.reply(
4142
ctx.getArgByIndex(1),
4243
message,

packages/microservices/client/client-grpc.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { GrpcObject } from 'grpc';
21
import { ClientProxy } from './client-proxy';
32
import { Logger } from '@nestjs/common/services/logger.service';
43
import { ClientOptions } from '../interfaces/client-metadata.interface';
@@ -98,7 +97,7 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
9897
return grpcPkg;
9998
}
10099

101-
public loadProto(): GrpcObject {
100+
public loadProto(): any {
102101
try {
103102
const context = grpcPackage.load(
104103
this.getOptionsProp<GrpcOptions>(this.options, 'protoPath'),

packages/microservices/client/client-mqtt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { MqttClient } from 'mqtt';
21
import { ClientProxy } from './client-proxy';
32
import { Logger } from '@nestjs/common/services/logger.service';
43
import { ClientOptions } from '../interfaces/client-metadata.interface';
@@ -11,6 +10,7 @@ import {
1110
} from './../constants';
1211
import { WritePacket, MqttOptions } from './../interfaces';
1312
import { ReadPacket, PacketId } from './../interfaces';
13+
import { MqttClient } from '../external/mqtt-client.interface';
1414

1515
let mqttPackage: any = {};
1616

packages/microservices/client/client-nats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Client } from 'nats';
21
import { ClientProxy } from './client-proxy';
32
import { Logger } from '@nestjs/common/services/logger.service';
43
import { ClientOptions } from '../interfaces/client-metadata.interface';
@@ -9,6 +8,7 @@ import {
98
ReadPacket,
109
PacketId,
1110
} from './../interfaces';
11+
import { Client } from '../external/nats-client.interface';
1212

1313
let natsPackage: any = {};
1414

packages/microservices/client/client-redis.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ClientOpts, RetryStrategyOptions, RedisClient } from 'redis';
21
import { ClientProxy } from './client-proxy';
32
import { Logger } from '@nestjs/common/services/logger.service';
43
import { ClientOptions } from '../interfaces/client-metadata.interface';
@@ -15,6 +14,11 @@ import {
1514
ReadPacket,
1615
PacketId,
1716
} from './../interfaces';
17+
import {
18+
RedisClient,
19+
ClientOpts,
20+
RetryStrategyOptions,
21+
} from '../external/redis.interface';
1822

1923
let redisPackage: any = {};
2024

0 commit comments

Comments
 (0)