u8-mqtt 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/basic-v4.cjs +1 -1
- package/cjs/basic-v5.cjs +1 -1
- package/cjs/full-v4.cjs +46 -25
- package/cjs/full-v4.cjs.map +1 -1
- package/cjs/full-v5.cjs +46 -25
- package/cjs/full-v5.cjs.map +1 -1
- package/cjs/index.cjs +46 -25
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +46 -25
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +46 -25
- package/cjs/v5.cjs.map +1 -1
- package/code/router_path.jsy +34 -21
- package/code/with_topic_router.jsy +3 -0
- package/esm/basic-v4.js +1 -1
- package/esm/basic-v5.js +1 -1
- package/esm/deno/basic-v4.js +1 -1
- package/esm/deno/basic-v5.js +1 -1
- package/esm/deno/full-v4.js +46 -25
- package/esm/deno/full-v4.js.map +1 -1
- package/esm/deno/full-v5.js +46 -25
- package/esm/deno/full-v5.js.map +1 -1
- package/esm/deno/index.js +46 -25
- package/esm/deno/index.js.map +1 -1
- package/esm/deno/v4.js +46 -25
- package/esm/deno/v4.js.map +1 -1
- package/esm/deno/v5.js +46 -25
- package/esm/deno/v5.js.map +1 -1
- package/esm/full-v4.js +46 -25
- package/esm/full-v4.js.map +1 -1
- package/esm/full-v5.js +46 -25
- package/esm/full-v5.js.map +1 -1
- package/esm/index.js +46 -25
- package/esm/index.js.map +1 -1
- package/esm/node/basic-v4.js +1 -1
- package/esm/node/basic-v4.mjs +1 -1
- package/esm/node/basic-v5.js +1 -1
- package/esm/node/basic-v5.mjs +1 -1
- package/esm/node/full-v4.js +46 -25
- package/esm/node/full-v4.js.map +1 -1
- package/esm/node/full-v4.mjs +46 -25
- package/esm/node/full-v4.mjs.map +1 -1
- package/esm/node/full-v5.js +46 -25
- package/esm/node/full-v5.js.map +1 -1
- package/esm/node/full-v5.mjs +46 -25
- package/esm/node/full-v5.mjs.map +1 -1
- package/esm/node/index.js +46 -25
- package/esm/node/index.js.map +1 -1
- package/esm/node/index.mjs +46 -25
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +46 -25
- package/esm/node/v4.js.map +1 -1
- package/esm/node/v4.mjs +46 -25
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +46 -25
- package/esm/node/v5.js.map +1 -1
- package/esm/node/v5.mjs +46 -25
- package/esm/node/v5.mjs.map +1 -1
- package/esm/v4.js +46 -25
- package/esm/v4.js.map +1 -1
- package/esm/v5.js +46 -25
- package/esm/v5.js.map +1 -1
- package/esm/web/basic-v4.js +1 -1
- package/esm/web/basic-v4.min.js +1 -1
- package/esm/web/basic-v4.min.js.br +0 -0
- package/esm/web/basic-v4.min.js.gz +0 -0
- package/esm/web/basic-v5.js +1 -1
- package/esm/web/basic-v5.min.js +1 -1
- package/esm/web/basic-v5.min.js.br +0 -0
- package/esm/web/basic-v5.min.js.gz +0 -0
- package/esm/web/full-v4.js +46 -25
- package/esm/web/full-v4.js.map +1 -1
- package/esm/web/full-v4.min.js +1 -1
- package/esm/web/full-v4.min.js.br +0 -0
- package/esm/web/full-v4.min.js.gz +0 -0
- package/esm/web/full-v5.js +46 -25
- package/esm/web/full-v5.js.map +1 -1
- package/esm/web/full-v5.min.js +1 -1
- package/esm/web/full-v5.min.js.br +0 -0
- package/esm/web/full-v5.min.js.gz +0 -0
- package/esm/web/index.js +46 -25
- package/esm/web/index.js.map +1 -1
- package/esm/web/index.min.js +1 -1
- package/esm/web/index.min.js.br +0 -0
- package/esm/web/index.min.js.gz +0 -0
- package/esm/web/v4.js +46 -25
- package/esm/web/v4.js.map +1 -1
- package/esm/web/v4.min.js +1 -1
- package/esm/web/v4.min.js.br +0 -0
- package/esm/web/v4.min.js.gz +0 -0
- package/esm/web/v5.js +46 -25
- package/esm/web/v5.js.map +1 -1
- package/esm/web/v5.min.js +1 -1
- package/esm/web/v5.min.js.br +0 -0
- package/esm/web/v5.min.js.gz +0 -0
- package/package.json +2 -2
package/esm/full-v5.js
CHANGED
|
@@ -841,16 +841,20 @@ const mqtt_opts_v5 =
|
|
|
841
841
|
encode_fns: mqtt_encode_v5,
|
|
842
842
|
mqtt_writer: mqtt_writer_v5, };
|
|
843
843
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
844
|
+
/**
|
|
845
|
+
* @param {string|RegExp} input The route pattern
|
|
846
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
847
|
+
*/
|
|
848
|
+
function parse(input, loose) {
|
|
849
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
850
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
847
851
|
arr[0] || arr.shift();
|
|
848
852
|
|
|
849
853
|
while (tmp = arr.shift()) {
|
|
850
854
|
c = tmp[0];
|
|
851
855
|
if (c === '*') {
|
|
852
|
-
keys.push(
|
|
853
|
-
pattern += '/(.*)';
|
|
856
|
+
keys.push(c);
|
|
857
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
854
858
|
} else if (c === ':') {
|
|
855
859
|
o = tmp.indexOf('?', 1);
|
|
856
860
|
ext = tmp.indexOf('.', 1);
|
|
@@ -890,6 +894,7 @@ class AbstractTopicRouter ::
|
|
|
890
894
|
async invoke(pkt, ctx) ::
|
|
891
895
|
add(topic_route, ...args) ::
|
|
892
896
|
remove(topic_route, priority) ::
|
|
897
|
+
count(topic_route) ::
|
|
893
898
|
clear(priority) ::
|
|
894
899
|
find(topic) :: // optional
|
|
895
900
|
mqtt_topic(topic_route)
|
|
@@ -929,6 +934,8 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
929
934
|
|
|
930
935
|
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
931
936
|
router.remove(topic_route, true, fn);
|
|
937
|
+
if (0 !== router.count(topic_route) ) {
|
|
938
|
+
return null}
|
|
932
939
|
|
|
933
940
|
let topic = router.mqtt_topic(topic_route);
|
|
934
941
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
@@ -997,6 +1004,17 @@ function mqtt_topic_path_router() {
|
|
|
997
1004
|
query ={topic: query, tgt: args.pop()}; }
|
|
998
1005
|
return _route_remove(lst, query)}
|
|
999
1006
|
|
|
1007
|
+
, count(topic_route) {
|
|
1008
|
+
if (! topic_route) {
|
|
1009
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)}
|
|
1010
|
+
|
|
1011
|
+
let count = 0;
|
|
1012
|
+
for (let lst of pri_lsts) {
|
|
1013
|
+
for (let route of lst) {
|
|
1014
|
+
if (topic_route === route.topic) {
|
|
1015
|
+
count++;} } }
|
|
1016
|
+
return count}
|
|
1017
|
+
|
|
1000
1018
|
, clear(priority) {
|
|
1001
1019
|
if (null == priority) {
|
|
1002
1020
|
pri_lsts = [[],[]]; }// null clears both lists
|
|
@@ -1020,38 +1038,41 @@ function mqtt_topic_path_router() {
|
|
|
1020
1038
|
await ctx.mqtt.puback(pkt);} } } }
|
|
1021
1039
|
|
|
1022
1040
|
|
|
1041
|
+
const _regexparam ={
|
|
1042
|
+
get wild() {return this['*']}
|
|
1043
|
+
, set wild(v) {return this['*']=wild} };
|
|
1044
|
+
|
|
1023
1045
|
function * _routes_iter(all_route_lists, topic) {
|
|
1024
1046
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
1025
|
-
for (let
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1047
|
+
for (let route of all_route_lists.flat()) {
|
|
1048
|
+
let match = route?.pattern.exec(topic);
|
|
1049
|
+
if (match) {
|
|
1050
|
+
let keys = route.keys;
|
|
1051
|
+
if (keys) {
|
|
1052
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
1053
|
+
for (k of keys) {
|
|
1054
|
+
params[k] = match[++i];}
|
|
1055
|
+
yield [route.tgt, params, route];}
|
|
1056
|
+
else {
|
|
1057
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
1035
1058
|
|
|
1036
1059
|
|
|
1037
1060
|
function _route_remove(all_route_lists, query) {
|
|
1038
|
-
let
|
|
1061
|
+
let n_removed = 0;
|
|
1039
1062
|
for (let lst of all_route_lists) {
|
|
1040
1063
|
let idx_tip = 0;
|
|
1041
1064
|
for (let route of lst) {
|
|
1042
|
-
// skip matching routes to remove from compacted list
|
|
1043
|
-
if (route === query) continue
|
|
1044
1065
|
if (route.topic === query.topic) {
|
|
1045
|
-
if (null == query.tgt)
|
|
1046
|
-
|
|
1066
|
+
if (null == query.tgt || route.tgt === query.tgt) {
|
|
1067
|
+
// skip matching routes to remove from compacted list
|
|
1068
|
+
n_removed++;
|
|
1069
|
+
continue} }
|
|
1047
1070
|
|
|
1048
1071
|
lst[idx_tip++] = route;}
|
|
1049
1072
|
|
|
1050
1073
|
// truncate remaining list
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return ans}
|
|
1074
|
+
lst.length = idx_tip;}
|
|
1075
|
+
return n_removed}
|
|
1055
1076
|
|
|
1056
1077
|
function decode_varint(u8, i0=0, invalid) {
|
|
1057
1078
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1666,7 +1687,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1666
1687
|
|
|
1667
1688
|
return this} }
|
|
1668
1689
|
|
|
1669
|
-
const version = '0.6.
|
|
1690
|
+
const version = '0.6.6';
|
|
1670
1691
|
|
|
1671
1692
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1672
1693
|
with_topic_path_router(
|