Skip to content

Commit

Permalink
bugfix(@nestjs/microservices) extract external typings nestjs#594
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 28, 2018
1 parent 5cfb0bf commit 3ad570e
Show file tree
Hide file tree
Showing 19 changed files with 796 additions and 23 deletions.
3 changes: 3 additions & 0 deletions packages/common/interfaces/external/cors-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @see https://github.com/expressjs/cors
*/
export type CustomOrigin = (
requestOrigin: string,
callback: (err: Error | null, allow?: boolean) => void,
Expand Down
141 changes: 141 additions & 0 deletions packages/common/interfaces/external/mqtt-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* @see https://github.com/mqttjs/MQTT.js/
*/
export declare type QoS = 0 | 1 | 2;

export interface MqttClientOptions extends ISecureClientOptions {
port?: number; // port is made into a number subsequently
host?: string; // host does NOT include port
hostname?: string;
path?: string;
protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs';

wsOptions?: {
[x: string]: any;
};
/**
* 10 seconds, set to 0 to disable
*/
keepalive?: number;
/**
* 'mqttjs_' + Math.random().toString(16).substr(2, 8)
*/
clientId?: string;
/**
* 'MQTT'
*/
protocolId?: string;
/**
* 4
*/
protocolVersion?: number;
/**
* true, set to false to receive QoS 1 and 2 messages while offline
*/
clean?: boolean;
/**
* 1000 milliseconds, interval between two reconnections
*/
reconnectPeriod?: number;
/**
* 30 * 1000 milliseconds, time to wait before a CONNACK is received
*/
connectTimeout?: number;
/**
* the username required by your broker, if any
*/
username?: string;
/**
* the password required by your broker, if any
*/
password?: string;
/**
* a any for the incoming packets
*/
incomingStore?: any;
/**
* a any for the outgoing packets
*/
outgoingStore?: any;
queueQoSZero?: boolean;
reschedulePings?: boolean;
servers?: Array<{
host: string;
port: number;
}>;
/**
* true, set to false to disable re-subscribe functionality
*/
resubscribe?: boolean;
/**
* a message that will sent by the broker automatically when the client disconnect badly.
*/
will?: {
/**
* the topic to publish
*/
topic: string;
/**
* the message to publish
*/
payload: string;
/**
* the QoS
*/
qos: QoS;
/**
* the retain flag
*/
retain: boolean;
};
transformWsUrl?: (
url: string,
options: any,
client: any,
) => string;
}
export interface ISecureClientOptions {
/**
* optional private keys in PEM format
*/
key?: string | string[] | Buffer | Buffer[] | Object[];
/**
* optional cert chains in PEM format
*/
cert?: string | string[] | Buffer | Buffer[];
/**
* Optionally override the trusted CA certificates in PEM format
*/
ca?: string | string[] | Buffer | Buffer[];
rejectUnauthorized?: boolean;
}
export interface IClientPublishOptions {
/**
* the QoS
*/
qos: QoS;
/**
* the retain flag
*/
retain?: boolean;
/**
* whether or not mark a message as duplicate
*/
dup?: boolean;
}
export interface IClientSubscribeOptions {
/**
* the QoS
*/
qos: QoS;
}
export interface IClientReconnectOptions {
/**
* a any for the incoming packets
*/
incomingStore?: any;
/**
* a any for the outgoing packets
*/
outgoingStore?: any;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @see https://github.com/expressjs/multer
*/
export interface MulterOptions {
dest?: string;
/** The storage engine to use for uploaded files. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Reference: https://www.npmjs.com/package/@types/serve-static

/**
* @see https://www.npmjs.com/package/@types/serve-static
*/
export interface ServeStaticOptions {
/**
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
Expand Down Expand Up @@ -65,4 +66,4 @@ export interface ServeStaticOptions {
* stat the stat object of the file that is being sent
*/
setHeaders?: (res, path: string, stat: any) => any;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Transport } from '../../enums/transport.enum';
import { CustomTransportStrategy } from './custom-transport-strategy.interface';
import { IClientOptions } from 'mqtt';
import { ServerCredentials } from 'grpc';
import { MqttClientOptions } from '../external/mqtt-options.interface';

export type MicroserviceOptions =
| GrpcOptions
Expand All @@ -20,7 +19,7 @@ export interface GrpcOptions {
transport?: Transport.GRPC;
options: {
url?: string;
credentials?: ServerCredentials;
credentials?: any;
protoPath: string;
package: string;
};
Expand All @@ -47,7 +46,7 @@ export interface RedisOptions {

export interface MqttOptions {
transport?: Transport.MQTT;
options?: IClientOptions & {
options?: MqttClientOptions & {
url?: string;
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/exceptions/exceptions-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class ExceptionsHandler {
statusCode: exception.getStatus(),
message: res,
};

this.applicationRef.reply(
ctx.getArgByIndex(1),
message,
Expand Down
3 changes: 1 addition & 2 deletions packages/microservices/client/client-grpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GrpcObject } from 'grpc';
import { ClientProxy } from './client-proxy';
import { Logger } from '@nestjs/common/services/logger.service';
import { ClientOptions } from '../interfaces/client-metadata.interface';
Expand Down Expand Up @@ -98,7 +97,7 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
return grpcPkg;
}

public loadProto(): GrpcObject {
public loadProto(): any {
try {
const context = grpcPackage.load(
this.getOptionsProp<GrpcOptions>(this.options, 'protoPath'),
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/client/client-mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MqttClient } from 'mqtt';
import { ClientProxy } from './client-proxy';
import { Logger } from '@nestjs/common/services/logger.service';
import { ClientOptions } from '../interfaces/client-metadata.interface';
Expand All @@ -11,6 +10,7 @@ import {
} from './../constants';
import { WritePacket, MqttOptions } from './../interfaces';
import { ReadPacket, PacketId } from './../interfaces';
import { MqttClient } from '../external/mqtt-client.interface';

let mqttPackage: any = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/client/client-nats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Client } from 'nats';
import { ClientProxy } from './client-proxy';
import { Logger } from '@nestjs/common/services/logger.service';
import { ClientOptions } from '../interfaces/client-metadata.interface';
Expand All @@ -9,6 +8,7 @@ import {
ReadPacket,
PacketId,
} from './../interfaces';
import { Client } from '../external/nats-client.interface';

let natsPackage: any = {};

Expand Down
6 changes: 5 additions & 1 deletion packages/microservices/client/client-redis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ClientOpts, RetryStrategyOptions, RedisClient } from 'redis';
import { ClientProxy } from './client-proxy';
import { Logger } from '@nestjs/common/services/logger.service';
import { ClientOptions } from '../interfaces/client-metadata.interface';
Expand All @@ -15,6 +14,11 @@ import {
ReadPacket,
PacketId,
} from './../interfaces';
import {
RedisClient,
ClientOpts,
RetryStrategyOptions,
} from '../external/redis.interface';

let redisPackage: any = {};

Expand Down
Loading

0 comments on commit 3ad570e

Please sign in to comment.