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/basic-v4.cjs
CHANGED
package/cjs/basic-v5.cjs
CHANGED
package/cjs/full-v4.cjs
CHANGED
|
@@ -653,16 +653,20 @@ const mqtt_opts_v4 =
|
|
|
653
653
|
encode_fns: mqtt_encode_v4,
|
|
654
654
|
mqtt_writer: mqtt_writer_v4, };
|
|
655
655
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
656
|
+
/**
|
|
657
|
+
* @param {string|RegExp} input The route pattern
|
|
658
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
659
|
+
*/
|
|
660
|
+
function parse(input, loose) {
|
|
661
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
662
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
659
663
|
arr[0] || arr.shift();
|
|
660
664
|
|
|
661
665
|
while (tmp = arr.shift()) {
|
|
662
666
|
c = tmp[0];
|
|
663
667
|
if (c === '*') {
|
|
664
|
-
keys.push(
|
|
665
|
-
pattern += '/(.*)';
|
|
668
|
+
keys.push(c);
|
|
669
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
666
670
|
} else if (c === ':') {
|
|
667
671
|
o = tmp.indexOf('?', 1);
|
|
668
672
|
ext = tmp.indexOf('.', 1);
|
|
@@ -738,7 +742,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
738
742
|
// alias: unsub_topic
|
|
739
743
|
unsubscribe_topic(topic_route, ...args) {
|
|
740
744
|
let router = this.router;
|
|
741
|
-
|
|
745
|
+
|
|
746
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
747
|
+
router.remove(topic_route, true, fn);
|
|
748
|
+
|
|
742
749
|
let topic = router.mqtt_topic(topic_route);
|
|
743
750
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
744
751
|
|
|
@@ -791,65 +798,79 @@ function mqtt_topic_path_router() {
|
|
|
791
798
|
if (fn) {throw new TypeError()}
|
|
792
799
|
fn = _ignore;}
|
|
793
800
|
|
|
794
|
-
let
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
801
|
+
let route = parse(as_topic_path(topic_route));
|
|
802
|
+
route.topic = topic_route;
|
|
803
|
+
route.tgt = fn;
|
|
804
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
799
805
|
return this}
|
|
800
806
|
|
|
801
|
-
, remove(
|
|
802
|
-
let lst = pri_lsts
|
|
803
|
-
|
|
807
|
+
, remove(query, ...args) {
|
|
808
|
+
let lst = pri_lsts;
|
|
809
|
+
if ('boolean' === typeof args[0]) {
|
|
810
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
811
|
+
|
|
812
|
+
if ('string' === typeof query) {
|
|
813
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
814
|
+
return _route_remove(lst, query)}
|
|
804
815
|
|
|
805
816
|
, clear(priority) {
|
|
806
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
807
817
|
if (null == priority) {
|
|
808
|
-
pri_lsts
|
|
818
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
819
|
+
else {
|
|
820
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
809
821
|
|
|
810
822
|
, async invoke(pkt, ctx) {
|
|
811
823
|
ctx.idx = 0;
|
|
812
824
|
ctx.rm = rm;
|
|
813
825
|
|
|
814
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
826
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
815
827
|
let res = await fn(pkt, params, ctx);
|
|
816
828
|
|
|
817
829
|
if (rm === res) {
|
|
818
|
-
_route_remove(pri_lsts,
|
|
830
|
+
_route_remove(pri_lsts, route);}
|
|
819
831
|
|
|
820
|
-
if (ctx.done) {
|
|
821
|
-
break}
|
|
832
|
+
if (ctx.done) {break}
|
|
822
833
|
else ctx.idx++;}
|
|
823
834
|
|
|
824
835
|
if (1 === pkt.qos) {
|
|
825
836
|
await ctx.mqtt.puback(pkt);} } } }
|
|
826
837
|
|
|
827
838
|
|
|
839
|
+
const _regexparam ={
|
|
840
|
+
get wild() {return this['*']}
|
|
841
|
+
, set wild(v) {return this['*']=wild} };
|
|
842
|
+
|
|
828
843
|
function * _routes_iter(all_route_lists, topic) {
|
|
829
844
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
830
|
-
for (let
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
845
|
+
for (let route of all_route_lists.flat()) {
|
|
846
|
+
let match = route?.pattern.exec(topic);
|
|
847
|
+
if (match) {
|
|
848
|
+
let keys = route.keys;
|
|
849
|
+
if (keys) {
|
|
850
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
851
|
+
for (k of keys) {
|
|
852
|
+
params[k] = match[++i];}
|
|
853
|
+
yield [route.tgt, params, route];}
|
|
854
|
+
else {
|
|
855
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
840
856
|
|
|
841
857
|
|
|
842
858
|
function _route_remove(all_route_lists, query) {
|
|
843
|
-
let
|
|
844
|
-
route===query
|
|
845
|
-
|| route.tgt===query
|
|
846
|
-
|| route.key===query);
|
|
859
|
+
let ans = false;
|
|
847
860
|
for (let lst of all_route_lists) {
|
|
848
|
-
let
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
861
|
+
let idx_tip = 0;
|
|
862
|
+
for (let route of lst) {
|
|
863
|
+
// skip matching routes to remove from compacted list
|
|
864
|
+
let skip = route === query;
|
|
865
|
+
if (!skip && route.topic === query.topic)
|
|
866
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
867
|
+
|
|
868
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
869
|
+
|
|
870
|
+
// truncate remaining list
|
|
871
|
+
lst.length = idx_tip;}
|
|
872
|
+
|
|
873
|
+
return ans}
|
|
853
874
|
|
|
854
875
|
function decode_varint(u8, i0=0, invalid) {
|
|
855
876
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1464,7 +1485,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1464
1485
|
|
|
1465
1486
|
return this} }
|
|
1466
1487
|
|
|
1467
|
-
const version = '0.6.
|
|
1488
|
+
const version = '0.6.5-node';
|
|
1468
1489
|
|
|
1469
1490
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1470
1491
|
with_topic_path_router(
|