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