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