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/cjs/v5.cjs
CHANGED
|
@@ -673,16 +673,20 @@ const mqtt_opts_v5 =
|
|
|
673
673
|
encode_fns: mqtt_encode_v5,
|
|
674
674
|
mqtt_writer: mqtt_writer_v5, };
|
|
675
675
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
676
|
+
/**
|
|
677
|
+
* @param {string|RegExp} input The route pattern
|
|
678
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
679
|
+
*/
|
|
680
|
+
function parse(input, loose) {
|
|
681
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
682
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
679
683
|
arr[0] || arr.shift();
|
|
680
684
|
|
|
681
685
|
while (tmp = arr.shift()) {
|
|
682
686
|
c = tmp[0];
|
|
683
687
|
if (c === '*') {
|
|
684
|
-
keys.push(
|
|
685
|
-
pattern += '/(.*)';
|
|
688
|
+
keys.push(c);
|
|
689
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
686
690
|
} else if (c === ':') {
|
|
687
691
|
o = tmp.indexOf('?', 1);
|
|
688
692
|
ext = tmp.indexOf('.', 1);
|
|
@@ -758,7 +762,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
758
762
|
// alias: unsub_topic
|
|
759
763
|
unsubscribe_topic(topic_route, ...args) {
|
|
760
764
|
let router = this.router;
|
|
761
|
-
|
|
765
|
+
|
|
766
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
767
|
+
router.remove(topic_route, true, fn);
|
|
768
|
+
|
|
762
769
|
let topic = router.mqtt_topic(topic_route);
|
|
763
770
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
764
771
|
|
|
@@ -811,65 +818,79 @@ function mqtt_topic_path_router() {
|
|
|
811
818
|
if (fn) {throw new TypeError()}
|
|
812
819
|
fn = _ignore;}
|
|
813
820
|
|
|
814
|
-
let
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
821
|
+
let route = parse(as_topic_path(topic_route));
|
|
822
|
+
route.topic = topic_route;
|
|
823
|
+
route.tgt = fn;
|
|
824
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
819
825
|
return this}
|
|
820
826
|
|
|
821
|
-
, remove(
|
|
822
|
-
let lst = pri_lsts
|
|
823
|
-
|
|
827
|
+
, remove(query, ...args) {
|
|
828
|
+
let lst = pri_lsts;
|
|
829
|
+
if ('boolean' === typeof args[0]) {
|
|
830
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
831
|
+
|
|
832
|
+
if ('string' === typeof query) {
|
|
833
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
834
|
+
return _route_remove(lst, query)}
|
|
824
835
|
|
|
825
836
|
, clear(priority) {
|
|
826
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
827
837
|
if (null == priority) {
|
|
828
|
-
pri_lsts
|
|
838
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
839
|
+
else {
|
|
840
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
829
841
|
|
|
830
842
|
, async invoke(pkt, ctx) {
|
|
831
843
|
ctx.idx = 0;
|
|
832
844
|
ctx.rm = rm;
|
|
833
845
|
|
|
834
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
846
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
835
847
|
let res = await fn(pkt, params, ctx);
|
|
836
848
|
|
|
837
849
|
if (rm === res) {
|
|
838
|
-
_route_remove(pri_lsts,
|
|
850
|
+
_route_remove(pri_lsts, route);}
|
|
839
851
|
|
|
840
|
-
if (ctx.done) {
|
|
841
|
-
break}
|
|
852
|
+
if (ctx.done) {break}
|
|
842
853
|
else ctx.idx++;}
|
|
843
854
|
|
|
844
855
|
if (1 === pkt.qos) {
|
|
845
856
|
await ctx.mqtt.puback(pkt);} } } }
|
|
846
857
|
|
|
847
858
|
|
|
859
|
+
const _regexparam ={
|
|
860
|
+
get wild() {return this['*']}
|
|
861
|
+
, set wild(v) {return this['*']=wild} };
|
|
862
|
+
|
|
848
863
|
function * _routes_iter(all_route_lists, topic) {
|
|
849
864
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
850
|
-
for (let
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
865
|
+
for (let route of all_route_lists.flat()) {
|
|
866
|
+
let match = route?.pattern.exec(topic);
|
|
867
|
+
if (match) {
|
|
868
|
+
let keys = route.keys;
|
|
869
|
+
if (keys) {
|
|
870
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
871
|
+
for (k of keys) {
|
|
872
|
+
params[k] = match[++i];}
|
|
873
|
+
yield [route.tgt, params, route];}
|
|
874
|
+
else {
|
|
875
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
860
876
|
|
|
861
877
|
|
|
862
878
|
function _route_remove(all_route_lists, query) {
|
|
863
|
-
let
|
|
864
|
-
route===query
|
|
865
|
-
|| route.tgt===query
|
|
866
|
-
|| route.key===query);
|
|
879
|
+
let ans = false;
|
|
867
880
|
for (let lst of all_route_lists) {
|
|
868
|
-
let
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
881
|
+
let idx_tip = 0;
|
|
882
|
+
for (let route of lst) {
|
|
883
|
+
// skip matching routes to remove from compacted list
|
|
884
|
+
let skip = route === query;
|
|
885
|
+
if (!skip && route.topic === query.topic)
|
|
886
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
887
|
+
|
|
888
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
889
|
+
|
|
890
|
+
// truncate remaining list
|
|
891
|
+
lst.length = idx_tip;}
|
|
892
|
+
|
|
893
|
+
return ans}
|
|
873
894
|
|
|
874
895
|
function decode_varint(u8, i0=0, invalid) {
|
|
875
896
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1484,7 +1505,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1484
1505
|
|
|
1485
1506
|
return this} }
|
|
1486
1507
|
|
|
1487
|
-
const version = '0.6.
|
|
1508
|
+
const version = '0.6.5-node';
|
|
1488
1509
|
|
|
1489
1510
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1490
1511
|
with_topic_path_router(
|