u8-mqtt 0.6.3 → 0.6.5
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 +61 -40
- package/cjs/full-v4.cjs.map +1 -1
- package/cjs/full-v5.cjs +61 -40
- package/cjs/full-v5.cjs.map +1 -1
- package/cjs/index.cjs +61 -40
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +61 -40
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +61 -40
- package/cjs/v5.cjs.map +1 -1
- package/code/router_path.jsy +47 -33
- 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 +61 -40
- package/esm/deno/full-v4.js.map +1 -1
- package/esm/deno/full-v5.js +61 -40
- package/esm/deno/full-v5.js.map +1 -1
- package/esm/deno/index.js +61 -40
- package/esm/deno/index.js.map +1 -1
- package/esm/deno/v4.js +61 -40
- package/esm/deno/v4.js.map +1 -1
- package/esm/deno/v5.js +61 -40
- package/esm/deno/v5.js.map +1 -1
- package/esm/full-v4.js +61 -40
- package/esm/full-v4.js.map +1 -1
- package/esm/full-v5.js +61 -40
- package/esm/full-v5.js.map +1 -1
- package/esm/index.js +61 -40
- 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 +61 -40
- package/esm/node/full-v4.js.map +1 -1
- package/esm/node/full-v4.mjs +61 -40
- package/esm/node/full-v4.mjs.map +1 -1
- package/esm/node/full-v5.js +61 -40
- package/esm/node/full-v5.js.map +1 -1
- package/esm/node/full-v5.mjs +61 -40
- package/esm/node/full-v5.mjs.map +1 -1
- package/esm/node/index.js +61 -40
- package/esm/node/index.js.map +1 -1
- package/esm/node/index.mjs +61 -40
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +61 -40
- package/esm/node/v4.js.map +1 -1
- package/esm/node/v4.mjs +61 -40
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +61 -40
- package/esm/node/v5.js.map +1 -1
- package/esm/node/v5.mjs +61 -40
- package/esm/node/v5.mjs.map +1 -1
- package/esm/v4.js +61 -40
- package/esm/v4.js.map +1 -1
- package/esm/v5.js +61 -40
- 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 +61 -40
- 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 +61 -40
- 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 +61 -40
- 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 +61 -40
- 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 +61 -40
- 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 +5 -5
package/esm/v5.js
CHANGED
|
@@ -666,16 +666,20 @@ const mqtt_opts_v5 =
|
|
|
666
666
|
encode_fns: mqtt_encode_v5,
|
|
667
667
|
mqtt_writer: mqtt_writer_v5, };
|
|
668
668
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
669
|
+
/**
|
|
670
|
+
* @param {string|RegExp} input The route pattern
|
|
671
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
672
|
+
*/
|
|
673
|
+
function parse(input, loose) {
|
|
674
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
675
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
672
676
|
arr[0] || arr.shift();
|
|
673
677
|
|
|
674
678
|
while (tmp = arr.shift()) {
|
|
675
679
|
c = tmp[0];
|
|
676
680
|
if (c === '*') {
|
|
677
|
-
keys.push(
|
|
678
|
-
pattern += '/(.*)';
|
|
681
|
+
keys.push(c);
|
|
682
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
679
683
|
} else if (c === ':') {
|
|
680
684
|
o = tmp.indexOf('?', 1);
|
|
681
685
|
ext = tmp.indexOf('.', 1);
|
|
@@ -751,7 +755,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
751
755
|
// alias: unsub_topic
|
|
752
756
|
unsubscribe_topic(topic_route, ...args) {
|
|
753
757
|
let router = this.router;
|
|
754
|
-
|
|
758
|
+
|
|
759
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
760
|
+
router.remove(topic_route, true, fn);
|
|
761
|
+
|
|
755
762
|
let topic = router.mqtt_topic(topic_route);
|
|
756
763
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
757
764
|
|
|
@@ -804,65 +811,79 @@ function mqtt_topic_path_router() {
|
|
|
804
811
|
if (fn) {throw new TypeError()}
|
|
805
812
|
fn = _ignore;}
|
|
806
813
|
|
|
807
|
-
let
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
814
|
+
let route = parse(as_topic_path(topic_route));
|
|
815
|
+
route.topic = topic_route;
|
|
816
|
+
route.tgt = fn;
|
|
817
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
812
818
|
return this}
|
|
813
819
|
|
|
814
|
-
, remove(
|
|
815
|
-
let lst = pri_lsts
|
|
816
|
-
|
|
820
|
+
, remove(query, ...args) {
|
|
821
|
+
let lst = pri_lsts;
|
|
822
|
+
if ('boolean' === typeof args[0]) {
|
|
823
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
824
|
+
|
|
825
|
+
if ('string' === typeof query) {
|
|
826
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
827
|
+
return _route_remove(lst, query)}
|
|
817
828
|
|
|
818
829
|
, clear(priority) {
|
|
819
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
820
830
|
if (null == priority) {
|
|
821
|
-
pri_lsts
|
|
831
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
832
|
+
else {
|
|
833
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
822
834
|
|
|
823
835
|
, async invoke(pkt, ctx) {
|
|
824
836
|
ctx.idx = 0;
|
|
825
837
|
ctx.rm = rm;
|
|
826
838
|
|
|
827
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
839
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
828
840
|
let res = await fn(pkt, params, ctx);
|
|
829
841
|
|
|
830
842
|
if (rm === res) {
|
|
831
|
-
_route_remove(pri_lsts,
|
|
843
|
+
_route_remove(pri_lsts, route);}
|
|
832
844
|
|
|
833
|
-
if (ctx.done) {
|
|
834
|
-
break}
|
|
845
|
+
if (ctx.done) {break}
|
|
835
846
|
else ctx.idx++;}
|
|
836
847
|
|
|
837
848
|
if (1 === pkt.qos) {
|
|
838
849
|
await ctx.mqtt.puback(pkt);} } } }
|
|
839
850
|
|
|
840
851
|
|
|
852
|
+
const _regexparam ={
|
|
853
|
+
get wild() {return this['*']}
|
|
854
|
+
, set wild(v) {return this['*']=wild} };
|
|
855
|
+
|
|
841
856
|
function * _routes_iter(all_route_lists, topic) {
|
|
842
857
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
843
|
-
for (let
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
858
|
+
for (let route of all_route_lists.flat()) {
|
|
859
|
+
let match = route?.pattern.exec(topic);
|
|
860
|
+
if (match) {
|
|
861
|
+
let keys = route.keys;
|
|
862
|
+
if (keys) {
|
|
863
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
864
|
+
for (k of keys) {
|
|
865
|
+
params[k] = match[++i];}
|
|
866
|
+
yield [route.tgt, params, route];}
|
|
867
|
+
else {
|
|
868
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
853
869
|
|
|
854
870
|
|
|
855
871
|
function _route_remove(all_route_lists, query) {
|
|
856
|
-
let
|
|
857
|
-
route===query
|
|
858
|
-
|| route.tgt===query
|
|
859
|
-
|| route.key===query);
|
|
872
|
+
let ans = false;
|
|
860
873
|
for (let lst of all_route_lists) {
|
|
861
|
-
let
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
874
|
+
let idx_tip = 0;
|
|
875
|
+
for (let route of lst) {
|
|
876
|
+
// skip matching routes to remove from compacted list
|
|
877
|
+
let skip = route === query;
|
|
878
|
+
if (!skip && route.topic === query.topic)
|
|
879
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
880
|
+
|
|
881
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
882
|
+
|
|
883
|
+
// truncate remaining list
|
|
884
|
+
lst.length = idx_tip;}
|
|
885
|
+
|
|
886
|
+
return ans}
|
|
866
887
|
|
|
867
888
|
function decode_varint(u8, i0=0, invalid) {
|
|
868
889
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1477,7 +1498,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1477
1498
|
|
|
1478
1499
|
return this} }
|
|
1479
1500
|
|
|
1480
|
-
const version = '0.6.
|
|
1501
|
+
const version = '0.6.5';
|
|
1481
1502
|
|
|
1482
1503
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1483
1504
|
with_topic_path_router(
|