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/cjs/basic-v4.cjs
CHANGED
package/cjs/basic-v5.cjs
CHANGED
package/cjs/full-v4.cjs
CHANGED
|
@@ -653,16 +653,20 @@ const mqtt_opts_v4 =
|
|
|
653
653
|
encode_fns: mqtt_encode_v4,
|
|
654
654
|
mqtt_writer: mqtt_writer_v4, };
|
|
655
655
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
656
|
+
/**
|
|
657
|
+
* @param {string|RegExp} input The route pattern
|
|
658
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
659
|
+
*/
|
|
660
|
+
function parse(input, loose) {
|
|
661
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
662
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
659
663
|
arr[0] || arr.shift();
|
|
660
664
|
|
|
661
665
|
while (tmp = arr.shift()) {
|
|
662
666
|
c = tmp[0];
|
|
663
667
|
if (c === '*') {
|
|
664
|
-
keys.push(
|
|
665
|
-
pattern += '/(.*)';
|
|
668
|
+
keys.push(c);
|
|
669
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
666
670
|
} else if (c === ':') {
|
|
667
671
|
o = tmp.indexOf('?', 1);
|
|
668
672
|
ext = tmp.indexOf('.', 1);
|
|
@@ -702,6 +706,7 @@ class AbstractTopicRouter ::
|
|
|
702
706
|
async invoke(pkt, ctx) ::
|
|
703
707
|
add(topic_route, ...args) ::
|
|
704
708
|
remove(topic_route, priority) ::
|
|
709
|
+
count(topic_route) ::
|
|
705
710
|
clear(priority) ::
|
|
706
711
|
find(topic) :: // optional
|
|
707
712
|
mqtt_topic(topic_route)
|
|
@@ -741,6 +746,8 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
741
746
|
|
|
742
747
|
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
743
748
|
router.remove(topic_route, true, fn);
|
|
749
|
+
if (0 !== router.count(topic_route) ) {
|
|
750
|
+
return null}
|
|
744
751
|
|
|
745
752
|
let topic = router.mqtt_topic(topic_route);
|
|
746
753
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
@@ -809,6 +816,17 @@ function mqtt_topic_path_router() {
|
|
|
809
816
|
query ={topic: query, tgt: args.pop()}; }
|
|
810
817
|
return _route_remove(lst, query)}
|
|
811
818
|
|
|
819
|
+
, count(topic_route) {
|
|
820
|
+
if (! topic_route) {
|
|
821
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)}
|
|
822
|
+
|
|
823
|
+
let count = 0;
|
|
824
|
+
for (let lst of pri_lsts) {
|
|
825
|
+
for (let route of lst) {
|
|
826
|
+
if (topic_route === route.topic) {
|
|
827
|
+
count++;} } }
|
|
828
|
+
return count}
|
|
829
|
+
|
|
812
830
|
, clear(priority) {
|
|
813
831
|
if (null == priority) {
|
|
814
832
|
pri_lsts = [[],[]]; }// null clears both lists
|
|
@@ -832,38 +850,41 @@ function mqtt_topic_path_router() {
|
|
|
832
850
|
await ctx.mqtt.puback(pkt);} } } }
|
|
833
851
|
|
|
834
852
|
|
|
853
|
+
const _regexparam ={
|
|
854
|
+
get wild() {return this['*']}
|
|
855
|
+
, set wild(v) {return this['*']=wild} };
|
|
856
|
+
|
|
835
857
|
function * _routes_iter(all_route_lists, topic) {
|
|
836
858
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
837
|
-
for (let
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
859
|
+
for (let route of all_route_lists.flat()) {
|
|
860
|
+
let match = route?.pattern.exec(topic);
|
|
861
|
+
if (match) {
|
|
862
|
+
let keys = route.keys;
|
|
863
|
+
if (keys) {
|
|
864
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
865
|
+
for (k of keys) {
|
|
866
|
+
params[k] = match[++i];}
|
|
867
|
+
yield [route.tgt, params, route];}
|
|
868
|
+
else {
|
|
869
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
847
870
|
|
|
848
871
|
|
|
849
872
|
function _route_remove(all_route_lists, query) {
|
|
850
|
-
let
|
|
873
|
+
let n_removed = 0;
|
|
851
874
|
for (let lst of all_route_lists) {
|
|
852
875
|
let idx_tip = 0;
|
|
853
876
|
for (let route of lst) {
|
|
854
|
-
// skip matching routes to remove from compacted list
|
|
855
|
-
if (route === query) continue
|
|
856
877
|
if (route.topic === query.topic) {
|
|
857
|
-
if (null == query.tgt)
|
|
858
|
-
|
|
878
|
+
if (null == query.tgt || route.tgt === query.tgt) {
|
|
879
|
+
// skip matching routes to remove from compacted list
|
|
880
|
+
n_removed++;
|
|
881
|
+
continue} }
|
|
859
882
|
|
|
860
883
|
lst[idx_tip++] = route;}
|
|
861
884
|
|
|
862
885
|
// truncate remaining list
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return ans}
|
|
886
|
+
lst.length = idx_tip;}
|
|
887
|
+
return n_removed}
|
|
867
888
|
|
|
868
889
|
function decode_varint(u8, i0=0, invalid) {
|
|
869
890
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1478,7 +1499,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1478
1499
|
|
|
1479
1500
|
return this} }
|
|
1480
1501
|
|
|
1481
|
-
const version = '0.6.
|
|
1502
|
+
const version = '0.6.6-node';
|
|
1482
1503
|
|
|
1483
1504
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1484
1505
|
with_topic_path_router(
|