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/node/full-v4.mjs
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);
|
|
@@ -734,7 +738,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
734
738
|
// alias: unsub_topic
|
|
735
739
|
unsubscribe_topic(topic_route, ...args) {
|
|
736
740
|
let router = this.router;
|
|
737
|
-
|
|
741
|
+
|
|
742
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
743
|
+
router.remove(topic_route, true, fn);
|
|
744
|
+
|
|
738
745
|
let topic = router.mqtt_topic(topic_route);
|
|
739
746
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
740
747
|
|
|
@@ -787,65 +794,79 @@ function mqtt_topic_path_router() {
|
|
|
787
794
|
if (fn) {throw new TypeError()}
|
|
788
795
|
fn = _ignore;}
|
|
789
796
|
|
|
790
|
-
let
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
797
|
+
let route = parse(as_topic_path(topic_route));
|
|
798
|
+
route.topic = topic_route;
|
|
799
|
+
route.tgt = fn;
|
|
800
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
795
801
|
return this}
|
|
796
802
|
|
|
797
|
-
, remove(
|
|
798
|
-
let lst = pri_lsts
|
|
799
|
-
|
|
803
|
+
, remove(query, ...args) {
|
|
804
|
+
let lst = pri_lsts;
|
|
805
|
+
if ('boolean' === typeof args[0]) {
|
|
806
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
807
|
+
|
|
808
|
+
if ('string' === typeof query) {
|
|
809
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
810
|
+
return _route_remove(lst, query)}
|
|
800
811
|
|
|
801
812
|
, clear(priority) {
|
|
802
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
803
813
|
if (null == priority) {
|
|
804
|
-
pri_lsts
|
|
814
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
815
|
+
else {
|
|
816
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
805
817
|
|
|
806
818
|
, async invoke(pkt, ctx) {
|
|
807
819
|
ctx.idx = 0;
|
|
808
820
|
ctx.rm = rm;
|
|
809
821
|
|
|
810
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
822
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
811
823
|
let res = await fn(pkt, params, ctx);
|
|
812
824
|
|
|
813
825
|
if (rm === res) {
|
|
814
|
-
_route_remove(pri_lsts,
|
|
826
|
+
_route_remove(pri_lsts, route);}
|
|
815
827
|
|
|
816
|
-
if (ctx.done) {
|
|
817
|
-
break}
|
|
828
|
+
if (ctx.done) {break}
|
|
818
829
|
else ctx.idx++;}
|
|
819
830
|
|
|
820
831
|
if (1 === pkt.qos) {
|
|
821
832
|
await ctx.mqtt.puback(pkt);} } } }
|
|
822
833
|
|
|
823
834
|
|
|
835
|
+
const _regexparam ={
|
|
836
|
+
get wild() {return this['*']}
|
|
837
|
+
, set wild(v) {return this['*']=wild} };
|
|
838
|
+
|
|
824
839
|
function * _routes_iter(all_route_lists, topic) {
|
|
825
840
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
826
|
-
for (let
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
841
|
+
for (let route of all_route_lists.flat()) {
|
|
842
|
+
let match = route?.pattern.exec(topic);
|
|
843
|
+
if (match) {
|
|
844
|
+
let keys = route.keys;
|
|
845
|
+
if (keys) {
|
|
846
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
847
|
+
for (k of keys) {
|
|
848
|
+
params[k] = match[++i];}
|
|
849
|
+
yield [route.tgt, params, route];}
|
|
850
|
+
else {
|
|
851
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
836
852
|
|
|
837
853
|
|
|
838
854
|
function _route_remove(all_route_lists, query) {
|
|
839
|
-
let
|
|
840
|
-
route===query
|
|
841
|
-
|| route.tgt===query
|
|
842
|
-
|| route.key===query);
|
|
855
|
+
let ans = false;
|
|
843
856
|
for (let lst of all_route_lists) {
|
|
844
|
-
let
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
857
|
+
let idx_tip = 0;
|
|
858
|
+
for (let route of lst) {
|
|
859
|
+
// skip matching routes to remove from compacted list
|
|
860
|
+
let skip = route === query;
|
|
861
|
+
if (!skip && route.topic === query.topic)
|
|
862
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
863
|
+
|
|
864
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
865
|
+
|
|
866
|
+
// truncate remaining list
|
|
867
|
+
lst.length = idx_tip;}
|
|
868
|
+
|
|
869
|
+
return ans}
|
|
849
870
|
|
|
850
871
|
function decode_varint(u8, i0=0, invalid) {
|
|
851
872
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1460,7 +1481,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1460
1481
|
|
|
1461
1482
|
return this} }
|
|
1462
1483
|
|
|
1463
|
-
const version = '0.6.
|
|
1484
|
+
const version = '0.6.5-node';
|
|
1464
1485
|
|
|
1465
1486
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1466
1487
|
with_topic_path_router(
|