Skip to content

Commit 71dae75

Browse files
author
Yoseph Maguire
authored
Merge pull request mqttjs#1249 from bkp7/bkp7-typescript-changes
Improved TypeScript declarations for userProperties
2 parents 59d257a + 61bcbe6 commit 71dae75

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"help-me": "^3.0.0",
7070
"inherits": "^2.0.3",
7171
"minimist": "^1.2.5",
72-
"mqtt-packet": "^6.6.0",
72+
"mqtt-packet": "^6.8.0",
7373
"pump": "^3.0.0",
7474
"readable-stream": "^3.6.0",
7575
"reinterval": "^1.1.0",

types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export {
2323
IPingreqPacket,
2424
IPingrespPacket,
2525
IDisconnectPacket,
26-
Packet
26+
Packet,
27+
UserProperties
2728
} from 'mqtt-packet'

types/lib/client-options.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MqttClient } from './client'
22
import { Store } from './store'
3-
import { QoS } from 'mqtt-packet'
3+
import { QoS, UserProperties } from 'mqtt-packet'
44

55
export declare type StorePutCallback = () => void
66

@@ -99,7 +99,7 @@ export interface IClientOptions extends ISecureClientOptions {
9999
contentType?: string,
100100
responseTopic?: string,
101101
correlationData?: Buffer,
102-
userProperties?: Object
102+
userProperties?: UserProperties
103103
}
104104
}
105105
transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string,
@@ -110,7 +110,7 @@ export interface IClientOptions extends ISecureClientOptions {
110110
topicAliasMaximum?: number,
111111
requestResponseInformation?: boolean,
112112
requestProblemInformation?: boolean,
113-
userProperties?: Object,
113+
userProperties?: UserProperties,
114114
authenticationMethod?: string,
115115
authenticationData?: Buffer
116116
}
@@ -152,7 +152,7 @@ export interface IClientPublishOptions {
152152
topicAlias?: string,
153153
responseTopic?: string,
154154
correlationData?: Buffer,
155-
userProperties?: Object,
155+
userProperties?: UserProperties,
156156
subscriptionIdentifier?: number,
157157
contentType?: string
158158
}

types/lib/client.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
IClientReconnectOptions
99
} from './client-options'
1010
import { Store } from './store'
11-
import { Packet, QoS } from 'mqtt-packet'
11+
import { Packet, IConnectPacket, IPublishPacket, IDisconnectPacket, QoS } from 'mqtt-packet'
1212

1313
export interface ISubscriptionGrant {
1414
/**
@@ -66,9 +66,10 @@ export interface ISubscriptionMap {
6666
}
6767
}
6868

69-
export declare type OnConnectCallback = (packet: Packet) => void
69+
export declare type OnConnectCallback = (packet: IConnectPacket) => void
70+
export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
7071
export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
71-
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: Packet) => void
72+
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void
7273
export declare type OnPacketCallback = (packet: Packet) => void
7374
export declare type OnErrorCallback = (error: Error) => void
7475
export declare type PacketCallback = (error?: Error, packet?: Packet) => any
@@ -101,13 +102,19 @@ export declare class MqttClient extends events.EventEmitter {
101102
public on (event: 'connect', cb: OnConnectCallback): this
102103
public on (event: 'message', cb: OnMessageCallback): this
103104
public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
105+
public on (event: 'disconnect', cb: OnDisconnectCallback): this
104106
public on (event: 'error', cb: OnErrorCallback): this
107+
public on (event: 'close', cb: OnCloseCallback): this
108+
public on (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
105109
public on (event: string, cb: Function): this
106110

107111
public once (event: 'connect', cb: OnConnectCallback): this
108112
public once (event: 'message', cb: OnMessageCallback): this
109113
public once (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
114+
public once (event: 'disconnect', cb: OnDisconnectCallback): this
110115
public once (event: 'error', cb: OnErrorCallback): this
116+
public once (event: 'close', cb: OnCloseCallback): this
117+
public once (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
111118
public once (event: string, cb: Function): this
112119

113120
/**

0 commit comments

Comments
 (0)