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