u8-mqtt 0.6.3 → 0.6.4
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 +44 -30
- package/cjs/full-v4.cjs.map +1 -1
- package/cjs/full-v5.cjs +44 -30
- package/cjs/full-v5.cjs.map +1 -1
- package/cjs/index.cjs +44 -30
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +44 -30
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +44 -30
- package/cjs/v5.cjs.map +1 -1
- package/code/router_path.jsy +39 -28
- package/code/with_topic_router.jsy +4 -1
- 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 +44 -30
- package/esm/deno/full-v4.js.map +1 -1
- package/esm/deno/full-v5.js +44 -30
- package/esm/deno/full-v5.js.map +1 -1
- package/esm/deno/index.js +44 -30
- package/esm/deno/index.js.map +1 -1
- package/esm/deno/v4.js +44 -30
- package/esm/deno/v4.js.map +1 -1
- package/esm/deno/v5.js +44 -30
- package/esm/deno/v5.js.map +1 -1
- package/esm/full-v4.js +44 -30
- package/esm/full-v4.js.map +1 -1
- package/esm/full-v5.js +44 -30
- package/esm/full-v5.js.map +1 -1
- package/esm/index.js +44 -30
- 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 +44 -30
- package/esm/node/full-v4.js.map +1 -1
- package/esm/node/full-v4.mjs +44 -30
- package/esm/node/full-v4.mjs.map +1 -1
- package/esm/node/full-v5.js +44 -30
- package/esm/node/full-v5.js.map +1 -1
- package/esm/node/full-v5.mjs +44 -30
- package/esm/node/full-v5.mjs.map +1 -1
- package/esm/node/index.js +44 -30
- package/esm/node/index.js.map +1 -1
- package/esm/node/index.mjs +44 -30
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +44 -30
- package/esm/node/v4.js.map +1 -1
- package/esm/node/v4.mjs +44 -30
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +44 -30
- package/esm/node/v5.js.map +1 -1
- package/esm/node/v5.mjs +44 -30
- package/esm/node/v5.mjs.map +1 -1
- package/esm/v4.js +44 -30
- package/esm/v4.js.map +1 -1
- package/esm/v5.js +44 -30
- 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 +44 -30
- 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 +44 -30
- 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 +44 -30
- 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 +44 -30
- 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 +44 -30
- 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 +4 -4
package/code/router_path.jsy
CHANGED
|
@@ -45,34 +45,38 @@ function mqtt_topic_path_router() ::
|
|
|
45
45
|
if fn :: throw new TypeError()
|
|
46
46
|
fn = _ignore
|
|
47
47
|
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
pri_lsts[priority ? 0 : 1].push(rte)
|
|
48
|
+
let route = _rxp_parse @ as_topic_path(topic_route)
|
|
49
|
+
route.topic = topic_route
|
|
50
|
+
route.tgt = fn
|
|
51
|
+
pri_lsts[priority ? 0 : 1].push(route)
|
|
53
52
|
return this
|
|
54
53
|
|
|
55
|
-
remove(
|
|
56
|
-
let lst = pri_lsts
|
|
57
|
-
|
|
54
|
+
remove(query, ...args) ::
|
|
55
|
+
let lst = pri_lsts
|
|
56
|
+
if ('boolean' === typeof args[0]) ::
|
|
57
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]]
|
|
58
|
+
|
|
59
|
+
if ('string' === typeof query) ::
|
|
60
|
+
query = @{} topic: query, tgt: args.pop()
|
|
61
|
+
return _route_remove(lst, query)
|
|
58
62
|
|
|
59
63
|
clear(priority) ::
|
|
60
|
-
pri_lsts[priority ? 0 : 1] = []
|
|
61
64
|
if null == priority ::
|
|
62
|
-
pri_lsts
|
|
65
|
+
pri_lsts = [[],[]] // null clears both lists
|
|
66
|
+
else ::
|
|
67
|
+
pri_lsts[priority ? 0 : 1] = []
|
|
63
68
|
|
|
64
69
|
async invoke(pkt, ctx) ::
|
|
65
70
|
ctx.idx = 0
|
|
66
71
|
ctx.rm = rm
|
|
67
72
|
|
|
68
|
-
for let [fn, params] of find(pkt.topic) ::
|
|
73
|
+
for let [fn, params, route] of find(pkt.topic) ::
|
|
69
74
|
let res = await fn(pkt, params, ctx)
|
|
70
75
|
|
|
71
76
|
if rm === res ::
|
|
72
|
-
_route_remove(pri_lsts,
|
|
77
|
+
_route_remove(pri_lsts, route)
|
|
73
78
|
|
|
74
|
-
if ctx.done ::
|
|
75
|
-
break
|
|
79
|
+
if ctx.done :: break
|
|
76
80
|
else ctx.idx++
|
|
77
81
|
|
|
78
82
|
if 1 === pkt.qos ::
|
|
@@ -82,26 +86,33 @@ function mqtt_topic_path_router() ::
|
|
|
82
86
|
function * _routes_iter(all_route_lists, topic) ::
|
|
83
87
|
topic = topic.replace(/^[\/]*/, '/') // ensure '/' prefix for regexparam library
|
|
84
88
|
for let route_list of all_route_lists ::
|
|
85
|
-
for let
|
|
86
|
-
let match = pattern.exec(topic)
|
|
89
|
+
for let route of route_list ::
|
|
90
|
+
let match = route.pattern.exec(topic)
|
|
87
91
|
if match ::
|
|
88
|
-
let params = keys
|
|
89
|
-
? keys.reduce @
|
|
92
|
+
let params = route.keys
|
|
93
|
+
? route.keys.reduce @
|
|
90
94
|
(o, k, i) => (o[k] = match[1+i], o)
|
|
91
95
|
{}
|
|
92
96
|
: match.groups ?? match
|
|
93
|
-
yield [tgt, params]
|
|
97
|
+
yield [route.tgt, params, route]
|
|
94
98
|
|
|
95
99
|
|
|
96
100
|
function _route_remove(all_route_lists, query) ::
|
|
97
|
-
let
|
|
98
|
-
route===query
|
|
99
|
-
|| route.tgt===query
|
|
100
|
-
|| route.key===query
|
|
101
|
+
let ans = false
|
|
101
102
|
for let lst of all_route_lists ::
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
let idx_tip = 0
|
|
104
|
+
for (let route of lst) ::
|
|
105
|
+
// skip matching routes to remove from compacted list
|
|
106
|
+
if (route === query) continue
|
|
107
|
+
if (route.topic === query.topic) ::
|
|
108
|
+
if (null == query.tgt) continue
|
|
109
|
+
if (route.tgt === query.tgt) continue
|
|
110
|
+
|
|
111
|
+
lst[idx_tip++] = route
|
|
112
|
+
|
|
113
|
+
// truncate remaining list
|
|
114
|
+
if (lst.splice(idx_tip).length)
|
|
115
|
+
ans = true
|
|
116
|
+
|
|
117
|
+
return ans
|
|
107
118
|
|
|
@@ -39,7 +39,10 @@ export const with_topic_router = mqtt_topic_router =>
|
|
|
39
39
|
// alias: unsub_topic
|
|
40
40
|
unsubscribe_topic(topic_route, ...args) ::
|
|
41
41
|
let router = this.router
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
let fn = args.at(-1)?.call ? args.pop() : null
|
|
44
|
+
router.remove @ topic_route, true, fn
|
|
45
|
+
|
|
43
46
|
let topic = router.mqtt_topic(topic_route)
|
|
44
47
|
return this.unsubscribe @ topic, ...args // topic_prefix
|
|
45
48
|
|
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
|
@@ -731,7 +731,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
731
731
|
// alias: unsub_topic
|
|
732
732
|
unsubscribe_topic(topic_route, ...args) {
|
|
733
733
|
let router = this.router;
|
|
734
|
-
|
|
734
|
+
|
|
735
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
736
|
+
router.remove(topic_route, true, fn);
|
|
737
|
+
|
|
735
738
|
let topic = router.mqtt_topic(topic_route);
|
|
736
739
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
737
740
|
|
|
@@ -784,34 +787,38 @@ function mqtt_topic_path_router() {
|
|
|
784
787
|
if (fn) {throw new TypeError()}
|
|
785
788
|
fn = _ignore;}
|
|
786
789
|
|
|
787
|
-
let
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
790
|
+
let route = parse(as_topic_path(topic_route));
|
|
791
|
+
route.topic = topic_route;
|
|
792
|
+
route.tgt = fn;
|
|
793
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
792
794
|
return this}
|
|
793
795
|
|
|
794
|
-
, remove(
|
|
795
|
-
let lst = pri_lsts
|
|
796
|
-
|
|
796
|
+
, remove(query, ...args) {
|
|
797
|
+
let lst = pri_lsts;
|
|
798
|
+
if ('boolean' === typeof args[0]) {
|
|
799
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
800
|
+
|
|
801
|
+
if ('string' === typeof query) {
|
|
802
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
803
|
+
return _route_remove(lst, query)}
|
|
797
804
|
|
|
798
805
|
, clear(priority) {
|
|
799
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
800
806
|
if (null == priority) {
|
|
801
|
-
pri_lsts
|
|
807
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
808
|
+
else {
|
|
809
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
802
810
|
|
|
803
811
|
, async invoke(pkt, ctx) {
|
|
804
812
|
ctx.idx = 0;
|
|
805
813
|
ctx.rm = rm;
|
|
806
814
|
|
|
807
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
815
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
808
816
|
let res = await fn(pkt, params, ctx);
|
|
809
817
|
|
|
810
818
|
if (rm === res) {
|
|
811
|
-
_route_remove(pri_lsts,
|
|
819
|
+
_route_remove(pri_lsts, route);}
|
|
812
820
|
|
|
813
|
-
if (ctx.done) {
|
|
814
|
-
break}
|
|
821
|
+
if (ctx.done) {break}
|
|
815
822
|
else ctx.idx++;}
|
|
816
823
|
|
|
817
824
|
if (1 === pkt.qos) {
|
|
@@ -821,28 +828,35 @@ function mqtt_topic_path_router() {
|
|
|
821
828
|
function * _routes_iter(all_route_lists, topic) {
|
|
822
829
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
823
830
|
for (let route_list of all_route_lists) {
|
|
824
|
-
for (let
|
|
825
|
-
let match = pattern.exec(topic);
|
|
831
|
+
for (let route of route_list) {
|
|
832
|
+
let match = route.pattern.exec(topic);
|
|
826
833
|
if (match) {
|
|
827
|
-
let params = keys
|
|
828
|
-
? keys.reduce(
|
|
834
|
+
let params = route.keys
|
|
835
|
+
? route.keys.reduce(
|
|
829
836
|
(o, k, i) => (o[k] = match[1+i], o)
|
|
830
837
|
, {})
|
|
831
838
|
: match.groups ?? match;
|
|
832
|
-
yield [tgt, params];} } } }
|
|
839
|
+
yield [route.tgt, params, route];} } } }
|
|
833
840
|
|
|
834
841
|
|
|
835
842
|
function _route_remove(all_route_lists, query) {
|
|
836
|
-
let
|
|
837
|
-
route===query
|
|
838
|
-
|| route.tgt===query
|
|
839
|
-
|| route.key===query);
|
|
843
|
+
let ans = false;
|
|
840
844
|
for (let lst of all_route_lists) {
|
|
841
|
-
let
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
845
|
+
let idx_tip = 0;
|
|
846
|
+
for (let route of lst) {
|
|
847
|
+
// skip matching routes to remove from compacted list
|
|
848
|
+
if (route === query) continue
|
|
849
|
+
if (route.topic === query.topic) {
|
|
850
|
+
if (null == query.tgt) continue
|
|
851
|
+
if (route.tgt === query.tgt) continue}
|
|
852
|
+
|
|
853
|
+
lst[idx_tip++] = route;}
|
|
854
|
+
|
|
855
|
+
// truncate remaining list
|
|
856
|
+
if (lst.splice(idx_tip).length)
|
|
857
|
+
ans = true;}
|
|
858
|
+
|
|
859
|
+
return ans}
|
|
846
860
|
|
|
847
861
|
function decode_varint(u8, i0=0, invalid) {
|
|
848
862
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1457,7 +1471,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1457
1471
|
|
|
1458
1472
|
return this} }
|
|
1459
1473
|
|
|
1460
|
-
const version = '0.6.
|
|
1474
|
+
const version = '0.6.4-deno';
|
|
1461
1475
|
|
|
1462
1476
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1463
1477
|
with_topic_path_router(
|