-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): subscribe definition #1527
Conversation
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #1527 +/- ##
=======================================
Coverage 85.74% 85.74%
=======================================
Files 13 13
Lines 1249 1249
=======================================
Hits 1071 1071
Misses 178 178 ☔ View full report in Codecov by Sentry. |
e5bea58
to
dc21001
Compare
/* | ||
* MQTT 5.0 properies object of subscribe | ||
* */ | ||
properties?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we actually handling this somewhere in code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "in code" mean? If it means MQTT.js internal code, the answer is no.
However, this is a part of public APIs. MQTT.js users that access MQTT.js APIs via TypeScript require it.
For example, my project using MQTT.js via TypeScript requires setting SubscriptionIdentifier property when subscrine() API calling. Lack of this TypeScript definition, I need to use type unsafe JavaScript code directly.
This definition improve type safety for TypeScript users.
Add missing ISubscriptionMap for multi entries subscribe. Add IClientSubscribeProperties to support muptiple subscribe entries that have individual options (qos, nl, rap, and rh) and in common properties (subscriptionIdentifier, userProperty).
8fb8e9f
to
80f33c0
Compare
TypeScript definition of subscribe() has two functions.
MQTT.js/types/lib/client.d.ts
Lines 165 to 167 in aa49aaf
The type of the first parameter is string or string[].
The second parameter is opts. opts could have properties. e.g.)SubscriptionIdentifier
MQTT.js/types/lib/client.d.ts
Lines 168 to 171 in aa49aaf
The type of the first parameter is string, string[], or ISubscriptionMap.
ISubscriptionMap is defined as follows:
MQTT.js/types/lib/client.d.ts
Lines 57 to 67 in aa49aaf
MQTT spec defines properties are in common for all subscription entries on one subscription.
So ISubscriptionMap doesn't have properties.
When ISubscriptionMap is passed as the first argument, then the following code is processed:
MQTT.js/lib/client.js
Lines 760 to 780 in aa49aaf
qos, nl, rap, and rh are extraced from ISubscriptionMap, but propertiy such as SubscriptionIdentifier are gotten from opts. Because properties are in common for subscribe entries.
However, the TypeScript definition doesn't have a combination of ISubscriptionMap and opts (for properties).
So this PR add it to the following definition:
MQTT.js/types/lib/client.d.ts
Lines 165 to 167 in aa49aaf
The type of opts is IClientSubscribeOptions that is defined as follows:
MQTT.js/types/lib/client-options.d.ts
Lines 170 to 194 in aa49aaf
When opts is used with ISubscriptionMap, only properties field is required. So I added IClientSubscribeProperties.