u8-mqtt 0.6.3 → 0.6.4

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.
Files changed (96) hide show
  1. package/cjs/basic-v4.cjs +1 -1
  2. package/cjs/basic-v5.cjs +1 -1
  3. package/cjs/full-v4.cjs +44 -30
  4. package/cjs/full-v4.cjs.map +1 -1
  5. package/cjs/full-v5.cjs +44 -30
  6. package/cjs/full-v5.cjs.map +1 -1
  7. package/cjs/index.cjs +44 -30
  8. package/cjs/index.cjs.map +1 -1
  9. package/cjs/v4.cjs +44 -30
  10. package/cjs/v4.cjs.map +1 -1
  11. package/cjs/v5.cjs +44 -30
  12. package/cjs/v5.cjs.map +1 -1
  13. package/code/router_path.jsy +39 -28
  14. package/code/with_topic_router.jsy +4 -1
  15. package/esm/basic-v4.js +1 -1
  16. package/esm/basic-v5.js +1 -1
  17. package/esm/deno/basic-v4.js +1 -1
  18. package/esm/deno/basic-v5.js +1 -1
  19. package/esm/deno/full-v4.js +44 -30
  20. package/esm/deno/full-v4.js.map +1 -1
  21. package/esm/deno/full-v5.js +44 -30
  22. package/esm/deno/full-v5.js.map +1 -1
  23. package/esm/deno/index.js +44 -30
  24. package/esm/deno/index.js.map +1 -1
  25. package/esm/deno/v4.js +44 -30
  26. package/esm/deno/v4.js.map +1 -1
  27. package/esm/deno/v5.js +44 -30
  28. package/esm/deno/v5.js.map +1 -1
  29. package/esm/full-v4.js +44 -30
  30. package/esm/full-v4.js.map +1 -1
  31. package/esm/full-v5.js +44 -30
  32. package/esm/full-v5.js.map +1 -1
  33. package/esm/index.js +44 -30
  34. package/esm/index.js.map +1 -1
  35. package/esm/node/basic-v4.js +1 -1
  36. package/esm/node/basic-v4.mjs +1 -1
  37. package/esm/node/basic-v5.js +1 -1
  38. package/esm/node/basic-v5.mjs +1 -1
  39. package/esm/node/full-v4.js +44 -30
  40. package/esm/node/full-v4.js.map +1 -1
  41. package/esm/node/full-v4.mjs +44 -30
  42. package/esm/node/full-v4.mjs.map +1 -1
  43. package/esm/node/full-v5.js +44 -30
  44. package/esm/node/full-v5.js.map +1 -1
  45. package/esm/node/full-v5.mjs +44 -30
  46. package/esm/node/full-v5.mjs.map +1 -1
  47. package/esm/node/index.js +44 -30
  48. package/esm/node/index.js.map +1 -1
  49. package/esm/node/index.mjs +44 -30
  50. package/esm/node/index.mjs.map +1 -1
  51. package/esm/node/v4.js +44 -30
  52. package/esm/node/v4.js.map +1 -1
  53. package/esm/node/v4.mjs +44 -30
  54. package/esm/node/v4.mjs.map +1 -1
  55. package/esm/node/v5.js +44 -30
  56. package/esm/node/v5.js.map +1 -1
  57. package/esm/node/v5.mjs +44 -30
  58. package/esm/node/v5.mjs.map +1 -1
  59. package/esm/v4.js +44 -30
  60. package/esm/v4.js.map +1 -1
  61. package/esm/v5.js +44 -30
  62. package/esm/v5.js.map +1 -1
  63. package/esm/web/basic-v4.js +1 -1
  64. package/esm/web/basic-v4.min.js +1 -1
  65. package/esm/web/basic-v4.min.js.br +0 -0
  66. package/esm/web/basic-v4.min.js.gz +0 -0
  67. package/esm/web/basic-v5.js +1 -1
  68. package/esm/web/basic-v5.min.js +1 -1
  69. package/esm/web/basic-v5.min.js.br +0 -0
  70. package/esm/web/basic-v5.min.js.gz +0 -0
  71. package/esm/web/full-v4.js +44 -30
  72. package/esm/web/full-v4.js.map +1 -1
  73. package/esm/web/full-v4.min.js +1 -1
  74. package/esm/web/full-v4.min.js.br +0 -0
  75. package/esm/web/full-v4.min.js.gz +0 -0
  76. package/esm/web/full-v5.js +44 -30
  77. package/esm/web/full-v5.js.map +1 -1
  78. package/esm/web/full-v5.min.js +1 -1
  79. package/esm/web/full-v5.min.js.br +0 -0
  80. package/esm/web/full-v5.min.js.gz +0 -0
  81. package/esm/web/index.js +44 -30
  82. package/esm/web/index.js.map +1 -1
  83. package/esm/web/index.min.js +1 -1
  84. package/esm/web/index.min.js.br +0 -0
  85. package/esm/web/index.min.js.gz +0 -0
  86. package/esm/web/v4.js +44 -30
  87. package/esm/web/v4.js.map +1 -1
  88. package/esm/web/v4.min.js +1 -1
  89. package/esm/web/v4.min.js.br +0 -0
  90. package/esm/web/v4.min.js.gz +0 -0
  91. package/esm/web/v5.js +44 -30
  92. package/esm/web/v5.js.map +1 -1
  93. package/esm/web/v5.min.js +1 -1
  94. package/esm/web/v5.min.js.br +0 -0
  95. package/esm/web/v5.min.js.gz +0 -0
  96. package/package.json +4 -4
package/esm/full-v5.js CHANGED
@@ -926,7 +926,10 @@ const with_topic_router = mqtt_topic_router =>
926
926
  // alias: unsub_topic
927
927
  unsubscribe_topic(topic_route, ...args) {
928
928
  let router = this.router;
929
- router.remove(topic_route, true);
929
+
930
+ let fn = args.at(-1)?.call ? args.pop() : null;
931
+ router.remove(topic_route, true, fn);
932
+
930
933
  let topic = router.mqtt_topic(topic_route);
931
934
  return this.unsubscribe(topic, ...args ) }// topic_prefix
932
935
 
@@ -979,34 +982,38 @@ function mqtt_topic_path_router() {
979
982
  if (fn) {throw new TypeError()}
980
983
  fn = _ignore;}
981
984
 
982
- let rte = parse(as_topic_path(topic_route));
983
-
984
- rte.key = topic_route;
985
- rte.tgt = fn;
986
- pri_lsts[priority ? 0 : 1].push(rte);
985
+ let route = parse(as_topic_path(topic_route));
986
+ route.topic = topic_route;
987
+ route.tgt = fn;
988
+ pri_lsts[priority ? 0 : 1].push(route);
987
989
  return this}
988
990
 
989
- , remove(topic_route, priority) {
990
- let lst = pri_lsts[priority ? 0 : 1];
991
- return _route_remove([lst], topic_route)}
991
+ , remove(query, ...args) {
992
+ let lst = pri_lsts;
993
+ if ('boolean' === typeof args[0]) {
994
+ lst = [pri_lsts[args.shift() ? 0 : 1]];}
995
+
996
+ if ('string' === typeof query) {
997
+ query ={topic: query, tgt: args.pop()}; }
998
+ return _route_remove(lst, query)}
992
999
 
993
1000
  , clear(priority) {
994
- pri_lsts[priority ? 0 : 1] = [];
995
1001
  if (null == priority) {
996
- pri_lsts[1] = []; } }// null clears both lists
1002
+ pri_lsts = [[],[]]; }// null clears both lists
1003
+ else {
1004
+ pri_lsts[priority ? 0 : 1] = [];} }
997
1005
 
998
1006
  , async invoke(pkt, ctx) {
999
1007
  ctx.idx = 0;
1000
1008
  ctx.rm = rm;
1001
1009
 
1002
- for (let [fn, params] of find(pkt.topic)) {
1010
+ for (let [fn, params, route] of find(pkt.topic)) {
1003
1011
  let res = await fn(pkt, params, ctx);
1004
1012
 
1005
1013
  if (rm === res) {
1006
- _route_remove(pri_lsts, fn);}
1014
+ _route_remove(pri_lsts, route);}
1007
1015
 
1008
- if (ctx.done) {
1009
- break}
1016
+ if (ctx.done) {break}
1010
1017
  else ctx.idx++;}
1011
1018
 
1012
1019
  if (1 === pkt.qos) {
@@ -1016,28 +1023,35 @@ function mqtt_topic_path_router() {
1016
1023
  function * _routes_iter(all_route_lists, topic) {
1017
1024
  topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
1018
1025
  for (let route_list of all_route_lists) {
1019
- for (let {keys, pattern, tgt} of route_list) {
1020
- let match = pattern.exec(topic);
1026
+ for (let route of route_list) {
1027
+ let match = route.pattern.exec(topic);
1021
1028
  if (match) {
1022
- let params = keys
1023
- ? keys.reduce(
1029
+ let params = route.keys
1030
+ ? route.keys.reduce(
1024
1031
  (o, k, i) => (o[k] = match[1+i], o)
1025
1032
  , {})
1026
1033
  : match.groups ?? match;
1027
- yield [tgt, params];} } } }
1034
+ yield [route.tgt, params, route];} } } }
1028
1035
 
1029
1036
 
1030
1037
  function _route_remove(all_route_lists, query) {
1031
- let fn_match = route =>(
1032
- route===query
1033
- || route.tgt===query
1034
- || route.key===query);
1038
+ let ans = false;
1035
1039
  for (let lst of all_route_lists) {
1036
- let i = lst.findIndex(fn_match);
1037
- if (0 <= i) {
1038
- lst.splice(i,1);
1039
- return true} }
1040
- return false}
1040
+ let idx_tip = 0;
1041
+ for (let route of lst) {
1042
+ // skip matching routes to remove from compacted list
1043
+ if (route === query) continue
1044
+ if (route.topic === query.topic) {
1045
+ if (null == query.tgt) continue
1046
+ if (route.tgt === query.tgt) continue}
1047
+
1048
+ lst[idx_tip++] = route;}
1049
+
1050
+ // truncate remaining list
1051
+ if (lst.splice(idx_tip).length)
1052
+ ans = true;}
1053
+
1054
+ return ans}
1041
1055
 
1042
1056
  function decode_varint(u8, i0=0, invalid) {
1043
1057
  let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
@@ -1652,7 +1666,7 @@ class MQTTCore extends MQTTBase {
1652
1666
 
1653
1667
  return this} }
1654
1668
 
1655
- const version = '0.6.3';
1669
+ const version = '0.6.4';
1656
1670
 
1657
1671
  const MQTTClient_v4 = /* #__PURE__ */
1658
1672
  with_topic_path_router(