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/code/router_path.jsy
CHANGED
|
@@ -60,6 +60,17 @@ function mqtt_topic_path_router() ::
|
|
|
60
60
|
query = @{} topic: query, tgt: args.pop()
|
|
61
61
|
return _route_remove(lst, query)
|
|
62
62
|
|
|
63
|
+
count(topic_route) ::
|
|
64
|
+
if ! topic_route ::
|
|
65
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)
|
|
66
|
+
|
|
67
|
+
let count = 0
|
|
68
|
+
for let lst of pri_lsts ::
|
|
69
|
+
for let route of lst ::
|
|
70
|
+
if topic_route === route.topic ::
|
|
71
|
+
count++
|
|
72
|
+
return count
|
|
73
|
+
|
|
63
74
|
clear(priority) ::
|
|
64
75
|
if null == priority ::
|
|
65
76
|
pri_lsts = [[],[]] // null clears both lists
|
|
@@ -83,36 +94,38 @@ function mqtt_topic_path_router() ::
|
|
|
83
94
|
await ctx.mqtt.puback(pkt)
|
|
84
95
|
|
|
85
96
|
|
|
97
|
+
const _regexparam = @{}
|
|
98
|
+
get wild() :: return this['*']
|
|
99
|
+
set wild(v) :: return this['*']=wild
|
|
100
|
+
|
|
86
101
|
function * _routes_iter(all_route_lists, topic) ::
|
|
87
102
|
topic = topic.replace(/^[\/]*/, '/') // ensure '/' prefix for regexparam library
|
|
88
|
-
for let
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
: match.groups ?? match
|
|
103
|
+
for let route of all_route_lists.flat() ::
|
|
104
|
+
let match = route?.pattern.exec(topic)
|
|
105
|
+
if match ::
|
|
106
|
+
let keys = route.keys
|
|
107
|
+
if (keys) ::
|
|
108
|
+
let k, i=0, params={__proto__:_regexparam}
|
|
109
|
+
for (k of keys) ::
|
|
110
|
+
params[k] = match[++i]
|
|
97
111
|
yield [route.tgt, params, route]
|
|
112
|
+
else ::
|
|
113
|
+
yield [route.tgt, match.groups ?? match, route]
|
|
98
114
|
|
|
99
115
|
|
|
100
116
|
function _route_remove(all_route_lists, query) ::
|
|
101
|
-
let
|
|
117
|
+
let n_removed = 0
|
|
102
118
|
for let lst of all_route_lists ::
|
|
103
119
|
let idx_tip = 0
|
|
104
|
-
for
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
for let route of lst ::
|
|
121
|
+
if route.topic === query.topic ::
|
|
122
|
+
if null == query.tgt || route.tgt === query.tgt ::
|
|
123
|
+
// skip matching routes to remove from compacted list
|
|
124
|
+
n_removed++
|
|
125
|
+
continue
|
|
110
126
|
|
|
111
127
|
lst[idx_tip++] = route
|
|
112
128
|
|
|
113
129
|
// truncate remaining list
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return ans
|
|
118
|
-
|
|
130
|
+
lst.length = idx_tip
|
|
131
|
+
return n_removed
|
|
@@ -3,6 +3,7 @@ class AbstractTopicRouter ::
|
|
|
3
3
|
async invoke(pkt, ctx) ::
|
|
4
4
|
add(topic_route, ...args) ::
|
|
5
5
|
remove(topic_route, priority) ::
|
|
6
|
+
count(topic_route) ::
|
|
6
7
|
clear(priority) ::
|
|
7
8
|
find(topic) :: // optional
|
|
8
9
|
mqtt_topic(topic_route)
|
|
@@ -42,6 +43,8 @@ export const with_topic_router = mqtt_topic_router =>
|
|
|
42
43
|
|
|
43
44
|
let fn = args.at(-1)?.call ? args.pop() : null
|
|
44
45
|
router.remove @ topic_route, true, fn
|
|
46
|
+
if 0 !== router.count @ topic_route ::
|
|
47
|
+
return null
|
|
45
48
|
|
|
46
49
|
let topic = router.mqtt_topic(topic_route)
|
|
47
50
|
return this.unsubscribe @ topic, ...args // topic_prefix
|
package/esm/basic-v4.js
CHANGED
package/esm/basic-v5.js
CHANGED
package/esm/deno/basic-v4.js
CHANGED
package/esm/deno/basic-v5.js
CHANGED
package/esm/deno/full-v4.js
CHANGED
|
@@ -646,16 +646,20 @@ const mqtt_opts_v4 =
|
|
|
646
646
|
encode_fns: mqtt_encode_v4,
|
|
647
647
|
mqtt_writer: mqtt_writer_v4, };
|
|
648
648
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
/**
|
|
650
|
+
* @param {string|RegExp} input The route pattern
|
|
651
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
652
|
+
*/
|
|
653
|
+
function parse(input, loose) {
|
|
654
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
655
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
652
656
|
arr[0] || arr.shift();
|
|
653
657
|
|
|
654
658
|
while (tmp = arr.shift()) {
|
|
655
659
|
c = tmp[0];
|
|
656
660
|
if (c === '*') {
|
|
657
|
-
keys.push(
|
|
658
|
-
pattern += '/(.*)';
|
|
661
|
+
keys.push(c);
|
|
662
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
659
663
|
} else if (c === ':') {
|
|
660
664
|
o = tmp.indexOf('?', 1);
|
|
661
665
|
ext = tmp.indexOf('.', 1);
|
|
@@ -695,6 +699,7 @@ class AbstractTopicRouter ::
|
|
|
695
699
|
async invoke(pkt, ctx) ::
|
|
696
700
|
add(topic_route, ...args) ::
|
|
697
701
|
remove(topic_route, priority) ::
|
|
702
|
+
count(topic_route) ::
|
|
698
703
|
clear(priority) ::
|
|
699
704
|
find(topic) :: // optional
|
|
700
705
|
mqtt_topic(topic_route)
|
|
@@ -734,6 +739,8 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
734
739
|
|
|
735
740
|
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
736
741
|
router.remove(topic_route, true, fn);
|
|
742
|
+
if (0 !== router.count(topic_route) ) {
|
|
743
|
+
return null}
|
|
737
744
|
|
|
738
745
|
let topic = router.mqtt_topic(topic_route);
|
|
739
746
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
@@ -802,6 +809,17 @@ function mqtt_topic_path_router() {
|
|
|
802
809
|
query ={topic: query, tgt: args.pop()}; }
|
|
803
810
|
return _route_remove(lst, query)}
|
|
804
811
|
|
|
812
|
+
, count(topic_route) {
|
|
813
|
+
if (! topic_route) {
|
|
814
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)}
|
|
815
|
+
|
|
816
|
+
let count = 0;
|
|
817
|
+
for (let lst of pri_lsts) {
|
|
818
|
+
for (let route of lst) {
|
|
819
|
+
if (topic_route === route.topic) {
|
|
820
|
+
count++;} } }
|
|
821
|
+
return count}
|
|
822
|
+
|
|
805
823
|
, clear(priority) {
|
|
806
824
|
if (null == priority) {
|
|
807
825
|
pri_lsts = [[],[]]; }// null clears both lists
|
|
@@ -825,38 +843,41 @@ function mqtt_topic_path_router() {
|
|
|
825
843
|
await ctx.mqtt.puback(pkt);} } } }
|
|
826
844
|
|
|
827
845
|
|
|
846
|
+
const _regexparam ={
|
|
847
|
+
get wild() {return this['*']}
|
|
848
|
+
, set wild(v) {return this['*']=wild} };
|
|
849
|
+
|
|
828
850
|
function * _routes_iter(all_route_lists, topic) {
|
|
829
851
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
830
|
-
for (let
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
852
|
+
for (let route of all_route_lists.flat()) {
|
|
853
|
+
let match = route?.pattern.exec(topic);
|
|
854
|
+
if (match) {
|
|
855
|
+
let keys = route.keys;
|
|
856
|
+
if (keys) {
|
|
857
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
858
|
+
for (k of keys) {
|
|
859
|
+
params[k] = match[++i];}
|
|
860
|
+
yield [route.tgt, params, route];}
|
|
861
|
+
else {
|
|
862
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
840
863
|
|
|
841
864
|
|
|
842
865
|
function _route_remove(all_route_lists, query) {
|
|
843
|
-
let
|
|
866
|
+
let n_removed = 0;
|
|
844
867
|
for (let lst of all_route_lists) {
|
|
845
868
|
let idx_tip = 0;
|
|
846
869
|
for (let route of lst) {
|
|
847
|
-
// skip matching routes to remove from compacted list
|
|
848
|
-
if (route === query) continue
|
|
849
870
|
if (route.topic === query.topic) {
|
|
850
|
-
if (null == query.tgt)
|
|
851
|
-
|
|
871
|
+
if (null == query.tgt || route.tgt === query.tgt) {
|
|
872
|
+
// skip matching routes to remove from compacted list
|
|
873
|
+
n_removed++;
|
|
874
|
+
continue} }
|
|
852
875
|
|
|
853
876
|
lst[idx_tip++] = route;}
|
|
854
877
|
|
|
855
878
|
// truncate remaining list
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
return ans}
|
|
879
|
+
lst.length = idx_tip;}
|
|
880
|
+
return n_removed}
|
|
860
881
|
|
|
861
882
|
function decode_varint(u8, i0=0, invalid) {
|
|
862
883
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1471,7 +1492,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1471
1492
|
|
|
1472
1493
|
return this} }
|
|
1473
1494
|
|
|
1474
|
-
const version = '0.6.
|
|
1495
|
+
const version = '0.6.6-deno';
|
|
1475
1496
|
|
|
1476
1497
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1477
1498
|
with_topic_path_router(
|