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/full-v5.cjs
CHANGED
|
@@ -848,16 +848,20 @@ const mqtt_opts_v5 =
|
|
|
848
848
|
encode_fns: mqtt_encode_v5,
|
|
849
849
|
mqtt_writer: mqtt_writer_v5, };
|
|
850
850
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
851
|
+
/**
|
|
852
|
+
* @param {string|RegExp} input The route pattern
|
|
853
|
+
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
854
|
+
*/
|
|
855
|
+
function parse(input, loose) {
|
|
856
|
+
if (input instanceof RegExp) return { keys:false, pattern:input };
|
|
857
|
+
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
|
|
854
858
|
arr[0] || arr.shift();
|
|
855
859
|
|
|
856
860
|
while (tmp = arr.shift()) {
|
|
857
861
|
c = tmp[0];
|
|
858
862
|
if (c === '*') {
|
|
859
|
-
keys.push(
|
|
860
|
-
pattern += '/(.*)';
|
|
863
|
+
keys.push(c);
|
|
864
|
+
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
|
|
861
865
|
} else if (c === ':') {
|
|
862
866
|
o = tmp.indexOf('?', 1);
|
|
863
867
|
ext = tmp.indexOf('.', 1);
|
|
@@ -933,7 +937,10 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
933
937
|
// alias: unsub_topic
|
|
934
938
|
unsubscribe_topic(topic_route, ...args) {
|
|
935
939
|
let router = this.router;
|
|
936
|
-
|
|
940
|
+
|
|
941
|
+
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
942
|
+
router.remove(topic_route, true, fn);
|
|
943
|
+
|
|
937
944
|
let topic = router.mqtt_topic(topic_route);
|
|
938
945
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
939
946
|
|
|
@@ -986,65 +993,79 @@ function mqtt_topic_path_router() {
|
|
|
986
993
|
if (fn) {throw new TypeError()}
|
|
987
994
|
fn = _ignore;}
|
|
988
995
|
|
|
989
|
-
let
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
pri_lsts[priority ? 0 : 1].push(rte);
|
|
996
|
+
let route = parse(as_topic_path(topic_route));
|
|
997
|
+
route.topic = topic_route;
|
|
998
|
+
route.tgt = fn;
|
|
999
|
+
pri_lsts[priority ? 0 : 1].push(route);
|
|
994
1000
|
return this}
|
|
995
1001
|
|
|
996
|
-
, remove(
|
|
997
|
-
let lst = pri_lsts
|
|
998
|
-
|
|
1002
|
+
, remove(query, ...args) {
|
|
1003
|
+
let lst = pri_lsts;
|
|
1004
|
+
if ('boolean' === typeof args[0]) {
|
|
1005
|
+
lst = [pri_lsts[args.shift() ? 0 : 1]];}
|
|
1006
|
+
|
|
1007
|
+
if ('string' === typeof query) {
|
|
1008
|
+
query ={topic: query, tgt: args.pop()}; }
|
|
1009
|
+
return _route_remove(lst, query)}
|
|
999
1010
|
|
|
1000
1011
|
, clear(priority) {
|
|
1001
|
-
pri_lsts[priority ? 0 : 1] = [];
|
|
1002
1012
|
if (null == priority) {
|
|
1003
|
-
pri_lsts
|
|
1013
|
+
pri_lsts = [[],[]]; }// null clears both lists
|
|
1014
|
+
else {
|
|
1015
|
+
pri_lsts[priority ? 0 : 1] = [];} }
|
|
1004
1016
|
|
|
1005
1017
|
, async invoke(pkt, ctx) {
|
|
1006
1018
|
ctx.idx = 0;
|
|
1007
1019
|
ctx.rm = rm;
|
|
1008
1020
|
|
|
1009
|
-
for (let [fn, params] of find(pkt.topic)) {
|
|
1021
|
+
for (let [fn, params, route] of find(pkt.topic)) {
|
|
1010
1022
|
let res = await fn(pkt, params, ctx);
|
|
1011
1023
|
|
|
1012
1024
|
if (rm === res) {
|
|
1013
|
-
_route_remove(pri_lsts,
|
|
1025
|
+
_route_remove(pri_lsts, route);}
|
|
1014
1026
|
|
|
1015
|
-
if (ctx.done) {
|
|
1016
|
-
break}
|
|
1027
|
+
if (ctx.done) {break}
|
|
1017
1028
|
else ctx.idx++;}
|
|
1018
1029
|
|
|
1019
1030
|
if (1 === pkt.qos) {
|
|
1020
1031
|
await ctx.mqtt.puback(pkt);} } } }
|
|
1021
1032
|
|
|
1022
1033
|
|
|
1034
|
+
const _regexparam ={
|
|
1035
|
+
get wild() {return this['*']}
|
|
1036
|
+
, set wild(v) {return this['*']=wild} };
|
|
1037
|
+
|
|
1023
1038
|
function * _routes_iter(all_route_lists, topic) {
|
|
1024
1039
|
topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
|
|
1025
|
-
for (let
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1040
|
+
for (let route of all_route_lists.flat()) {
|
|
1041
|
+
let match = route?.pattern.exec(topic);
|
|
1042
|
+
if (match) {
|
|
1043
|
+
let keys = route.keys;
|
|
1044
|
+
if (keys) {
|
|
1045
|
+
let k, i=0, params={__proto__:_regexparam};
|
|
1046
|
+
for (k of keys) {
|
|
1047
|
+
params[k] = match[++i];}
|
|
1048
|
+
yield [route.tgt, params, route];}
|
|
1049
|
+
else {
|
|
1050
|
+
yield [route.tgt, match.groups ?? match, route];} } } }
|
|
1035
1051
|
|
|
1036
1052
|
|
|
1037
1053
|
function _route_remove(all_route_lists, query) {
|
|
1038
|
-
let
|
|
1039
|
-
route===query
|
|
1040
|
-
|| route.tgt===query
|
|
1041
|
-
|| route.key===query);
|
|
1054
|
+
let ans = false;
|
|
1042
1055
|
for (let lst of all_route_lists) {
|
|
1043
|
-
let
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1056
|
+
let idx_tip = 0;
|
|
1057
|
+
for (let route of lst) {
|
|
1058
|
+
// skip matching routes to remove from compacted list
|
|
1059
|
+
let skip = route === query;
|
|
1060
|
+
if (!skip && route.topic === query.topic)
|
|
1061
|
+
skip = (null == query.tgt) || (route.tgt === query.tgt);
|
|
1062
|
+
|
|
1063
|
+
if (!skip) lst[idx_tip++] = route;}
|
|
1064
|
+
|
|
1065
|
+
// truncate remaining list
|
|
1066
|
+
lst.length = idx_tip;}
|
|
1067
|
+
|
|
1068
|
+
return ans}
|
|
1048
1069
|
|
|
1049
1070
|
function decode_varint(u8, i0=0, invalid) {
|
|
1050
1071
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1659,7 +1680,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1659
1680
|
|
|
1660
1681
|
return this} }
|
|
1661
1682
|
|
|
1662
|
-
const version = '0.6.
|
|
1683
|
+
const version = '0.6.5-node';
|
|
1663
1684
|
|
|
1664
1685
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1665
1686
|
with_topic_path_router(
|