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/basic-v5.js
CHANGED
package/esm/deno/basic-v4.js
CHANGED
package/esm/deno/basic-v5.js
CHANGED
package/esm/deno/full-v4.js
CHANGED
|
@@ -646,16 +646,20 @@ const mqtt_opts_v4 =
|
|
|
646
646
|
encode_fns: mqtt_encode_v4,
|
|
647
647
|
mqtt_writer: mqtt_writer_v4, };
|
|
648
648
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
/**
|
|
650
|
+
* @param {string|RegExp} input The route pattern
|
|
651
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
652
|
+
*/
|
|
653
|
+
function parse(input, loose) {
|
|
654
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
655
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
652
656
|
arr[0] || arr.shift();
|
|
653
657
|
|
|
654
658
|
while (tmp = arr.shift()) {
|
|
655
659
|
c = tmp[0];
|
|
656
660
|
if (c === '*') {
|
|
657
|
-
keys.push(
|
|
658
|
-
pattern += '/(.*)';
|
|
661
|
+
keys.push(c);
|
|
662
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
659
663
|
} else if (c === ':') {
|
|
660
664
|
o = tmp.indexOf('?', 1);
|
|
661
665
|
ext = tmp.indexOf('.', 1);
|
|
@@ -731,7 +735,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
731
735
|
// alias: unsub_topic
|
|
732
736
|
unsubscribe_topic(topic_route, ...args) {
|
|
733
737
|
let router = this.router;
|
|
734
|
-
|
|
738
|
+
|
|
739
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
740
|
+
router.remove(topic_route, true, fn);
|
|
741
|
+
|
|
735
742
|
let topic = router.mqtt_topic(topic_route);
|
|
736
743
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
737
744
|
|
|
@@ -784,65 +791,79 @@ function mqtt_topic_path_router() {
|
|
|
784
791
|
if (fn) {throw new TypeError()}
|
|
785
792
|
fn = _ignore;}
|
|
786
793
|
|
|
787
|
-
let
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
794
|
+
let route = parse(as_topic_path(topic_route));
|
|
795
|
+
route.topic = topic_route;
|
|
796
|
+
route.tgt = fn;
|
|
797
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
792
798
|
return this}
|
|
793
799
|
|
|
794
|
-
, remove(
|
|
795
|
-
let lst = pri_lsts
|
|
796
|
-
|
|
800
|
+
, remove(query, ...args) {
|
|
801
|
+
let lst = pri_lsts;
|
|
802
|
+
if ('boolean' === typeof args[0]) {
|
|
803
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
804
|
+
|
|
805
|
+
if ('string' === typeof query) {
|
|
806
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
807
|
+
return _route_remove(lst, query)}
|
|
797
808
|
|
|
798
809
|
, clear(priority) {
|
|
799
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
800
810
|
if (null == priority) {
|
|
801
|
-
pri_lsts
|
|
811
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
812
|
+
else {
|
|
813
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
802
814
|
|
|
803
815
|
, async invoke(pkt, ctx) {
|
|
804
816
|
ctx.idx = 0;
|
|
805
817
|
ctx.rm = rm;
|
|
806
818
|
|
|
807
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
819
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
808
820
|
let res = await fn(pkt, params, ctx);
|
|
809
821
|
|
|
810
822
|
if (rm === res) {
|
|
811
|
-
_route_remove(pri_lsts,
|
|
823
|
+
_route_remove(pri_lsts, route);}
|
|
812
824
|
|
|
813
|
-
if (ctx.done) {
|
|
814
|
-
break}
|
|
825
|
+
if (ctx.done) {break}
|
|
815
826
|
else ctx.idx++;}
|
|
816
827
|
|
|
817
828
|
if (1 === pkt.qos) {
|
|
818
829
|
await ctx.mqtt.puback(pkt);} } } }
|
|
819
830
|
|
|
820
831
|
|
|
832
|
+
const _regexparam ={
|
|
833
|
+
get wild() {return this['*']}
|
|
834
|
+
, set wild(v) {return this['*']=wild} };
|
|
835
|
+
|
|
821
836
|
function * _routes_iter(all_route_lists, topic) {
|
|
822
837
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
823
|
-
for (let
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
838
|
+
for (let route of all_route_lists.flat()) {
|
|
839
|
+
let match = route?.pattern.exec(topic);
|
|
840
|
+
if (match) {
|
|
841
|
+
let keys = route.keys;
|
|
842
|
+
if (keys) {
|
|
843
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
844
|
+
for (k of keys) {
|
|
845
|
+
params[k] = match[++i];}
|
|
846
|
+
yield [route.tgt, params, route];}
|
|
847
|
+
else {
|
|
848
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
833
849
|
|
|
834
850
|
|
|
835
851
|
function _route_remove(all_route_lists, query) {
|
|
836
|
-
let
|
|
837
|
-
route===query
|
|
838
|
-
|| route.tgt===query
|
|
839
|
-
|| route.key===query);
|
|
852
|
+
let ans = false;
|
|
840
853
|
for (let lst of all_route_lists) {
|
|
841
|
-
let
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
854
|
+
let idx_tip = 0;
|
|
855
|
+
for (let route of lst) {
|
|
856
|
+
// skip matching routes to remove from compacted list
|
|
857
|
+
let skip = route === query;
|
|
858
|
+
if (!skip && route.topic === query.topic)
|
|
859
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
860
|
+
|
|
861
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
862
|
+
|
|
863
|
+
// truncate remaining list
|
|
864
|
+
lst.length = idx_tip;}
|
|
865
|
+
|
|
866
|
+
return ans}
|
|
846
867
|
|
|
847
868
|
function decode_varint(u8, i0=0, invalid) {
|
|
848
869
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1457,7 +1478,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1457
1478
|
|
|
1458
1479
|
return this} }
|
|
1459
1480
|
|
|
1460
|
-
const version = '0.6.
|
|
1481
|
+
const version = '0.6.5-deno';
|
|
1461
1482
|
|
|
1462
1483
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1463
1484
|
with_topic_path_router(
|