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