From b8a7c339d2f384c40b24eab5b29d430af960f546 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Mon, 24 Jul 2023 18:08:01 +0200 Subject: [PATCH] fix: improve subscribe types --- src/lib/client.ts | 48 ++++++----------------------------------- test/abstract_client.ts | 4 ++-- 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/lib/client.ts b/src/lib/client.ts index 1f6c2f487..d1a5abfe7 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -331,60 +331,26 @@ export interface IClientSubscribeOptions extends IClientSubscribeProperties { * */ rh?: number } - -export interface ISubscriptionGrant { +export interface ISubscriptionRequest extends IClientSubscribeOptions { /** * is a subscribed to topic */ topic: string +} + +export interface ISubscriptionGrant + extends Omit { /** * is the granted qos level on it, may return 128 on error */ qos: QoS | 128 - /* - * no local flag - * */ - nl?: boolean - /* - * Retain As Published flag - * */ - rap?: boolean - /* - * Retain Handling option - * */ - rh?: number -} -export interface ISubscriptionRequest extends IClientSubscribeProperties { - /** - * is a subscribed to topic - */ - topic: string - /** - * is the granted qos level on it - */ - qos: QoS - /* - * no local flag - * */ - nl?: boolean - /* - * Retain As Published flag - * */ - rap?: boolean - /* - * Retain Handling option - * */ - rh?: number } -export interface ISubscriptionOptions - extends Omit {} - export type ISubscriptionMap = { /** * object which has topic names as object keys and as value the options, like {'test1': {qos: 0}, 'test2': {qos: 2}}. */ - [topic: string]: ISubscriptionOptions + [topic: string]: IClientSubscribeOptions } & { resubscribe?: boolean } @@ -1180,7 +1146,7 @@ export default class MqttClient extends TypedEventEmitter { if (this.options.reconnectPeriod > 0) { - const topic: ISubscriptionOptions = { qos: sub.qos } + const topic: IClientSubscribeOptions = { qos: sub.qos } if (version === 5) { topic.nl = sub.nl || false topic.rap = sub.rap || false diff --git a/test/abstract_client.ts b/test/abstract_client.ts index 2b2bf6e0a..abe89dec8 100644 --- a/test/abstract_client.ts +++ b/test/abstract_client.ts @@ -15,7 +15,7 @@ import handlePublish from '../src/lib/handlers/publish' import { IClientOptions, IClientPublishOptions, - ISubscriptionOptions, + IClientSubscribeOptions, ISubscriptionMap, ISubscriptionRequest, } from '../src/lib/client' @@ -2223,7 +2223,7 @@ export default function abstractTest(server, config) { it('should accept an options parameter', function _test(done) { const client = connect() const topic = 'test' - const opts: ISubscriptionOptions = { qos: 1 } + const opts: IClientSubscribeOptions = { qos: 1 } client.once('connect', () => { client.subscribe(topic, opts)