u8-mqtt 0.6.4 → 0.6.6

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 +46 -25
  4. package/cjs/full-v4.cjs.map +1 -1
  5. package/cjs/full-v5.cjs +46 -25
  6. package/cjs/full-v5.cjs.map +1 -1
  7. package/cjs/index.cjs +46 -25
  8. package/cjs/index.cjs.map +1 -1
  9. package/cjs/v4.cjs +46 -25
  10. package/cjs/v4.cjs.map +1 -1
  11. package/cjs/v5.cjs +46 -25
  12. package/cjs/v5.cjs.map +1 -1
  13. package/code/router_path.jsy +34 -21
  14. package/code/with_topic_router.jsy +3 -0
  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 +46 -25
  20. package/esm/deno/full-v4.js.map +1 -1
  21. package/esm/deno/full-v5.js +46 -25
  22. package/esm/deno/full-v5.js.map +1 -1
  23. package/esm/deno/index.js +46 -25
  24. package/esm/deno/index.js.map +1 -1
  25. package/esm/deno/v4.js +46 -25
  26. package/esm/deno/v4.js.map +1 -1
  27. package/esm/deno/v5.js +46 -25
  28. package/esm/deno/v5.js.map +1 -1
  29. package/esm/full-v4.js +46 -25
  30. package/esm/full-v4.js.map +1 -1
  31. package/esm/full-v5.js +46 -25
  32. package/esm/full-v5.js.map +1 -1
  33. package/esm/index.js +46 -25
  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 +46 -25
  40. package/esm/node/full-v4.js.map +1 -1
  41. package/esm/node/full-v4.mjs +46 -25
  42. package/esm/node/full-v4.mjs.map +1 -1
  43. package/esm/node/full-v5.js +46 -25
  44. package/esm/node/full-v5.js.map +1 -1
  45. package/esm/node/full-v5.mjs +46 -25
  46. package/esm/node/full-v5.mjs.map +1 -1
  47. package/esm/node/index.js +46 -25
  48. package/esm/node/index.js.map +1 -1
  49. package/esm/node/index.mjs +46 -25
  50. package/esm/node/index.mjs.map +1 -1
  51. package/esm/node/v4.js +46 -25
  52. package/esm/node/v4.js.map +1 -1
  53. package/esm/node/v4.mjs +46 -25
  54. package/esm/node/v4.mjs.map +1 -1
  55. package/esm/node/v5.js +46 -25
  56. package/esm/node/v5.js.map +1 -1
  57. package/esm/node/v5.mjs +46 -25
  58. package/esm/node/v5.mjs.map +1 -1
  59. package/esm/v4.js +46 -25
  60. package/esm/v4.js.map +1 -1
  61. package/esm/v5.js +46 -25
  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 +46 -25
  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 +46 -25
  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 +46 -25
  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 +46 -25
  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 +46 -25
  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 +2 -2
@@ -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
- function parse(str, loose) {
848
- if (str instanceof RegExp) return { keys:false, pattern:str };
849
- var c, o, tmp, ext, keys=[], pattern='', arr = str.split('/');
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('wild');
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);
@@ -893,6 +897,7 @@ class AbstractTopicRouter ::
893
897
  async invoke(pkt, ctx) ::
894
898
  add(topic_route, ...args) ::
895
899
  remove(topic_route, priority) ::
900
+ count(topic_route) ::
896
901
  clear(priority) ::
897
902
  find(topic) :: // optional
898
903
  mqtt_topic(topic_route)
@@ -932,6 +937,8 @@ const with_topic_router = mqtt_topic_router =>
932
937
 
933
938
  let fn = args.at(-1)?.call ? args.pop() : null;
934
939
  router.remove(topic_route, true, fn);
940
+ if (0 !== router.count(topic_route) ) {
941
+ return null}
935
942
 
936
943
  let topic = router.mqtt_topic(topic_route);
937
944
  return this.unsubscribe(topic, ...args ) }// topic_prefix
@@ -1000,6 +1007,17 @@ function mqtt_topic_path_router() {
1000
1007
  query ={topic: query, tgt: args.pop()}; }
1001
1008
  return _route_remove(lst, query)}
1002
1009
 
1010
+ , count(topic_route) {
1011
+ if (! topic_route) {
1012
+ return pri_lsts.reduce((r,l) => r+l.length, 0)}
1013
+
1014
+ let count = 0;
1015
+ for (let lst of pri_lsts) {
1016
+ for (let route of lst) {
1017
+ if (topic_route === route.topic) {
1018
+ count++;} } }
1019
+ return count}
1020
+
1003
1021
  , clear(priority) {
1004
1022
  if (null == priority) {
1005
1023
  pri_lsts = [[],[]]; }// null clears both lists
@@ -1023,38 +1041,41 @@ function mqtt_topic_path_router() {
1023
1041
  await ctx.mqtt.puback(pkt);} } } }
1024
1042
 
1025
1043
 
1044
+ const _regexparam ={
1045
+ get wild() {return this['*']}
1046
+ , set wild(v) {return this['*']=wild} };
1047
+
1026
1048
  function * _routes_iter(all_route_lists, topic) {
1027
1049
  topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
1028
- for (let route_list of all_route_lists) {
1029
- for (let route of route_list) {
1030
- let match = route.pattern.exec(topic);
1031
- if (match) {
1032
- let params = route.keys
1033
- ? route.keys.reduce(
1034
- (o, k, i) => (o[k] = match[1+i], o)
1035
- , {})
1036
- : match.groups ?? match;
1037
- yield [route.tgt, params, route];} } } }
1050
+ for (let route of all_route_lists.flat()) {
1051
+ let match = route?.pattern.exec(topic);
1052
+ if (match) {
1053
+ let keys = route.keys;
1054
+ if (keys) {
1055
+ let k, i=0, params={__proto__:_regexparam};
1056
+ for (k of keys) {
1057
+ params[k] = match[++i];}
1058
+ yield [route.tgt, params, route];}
1059
+ else {
1060
+ yield [route.tgt, match.groups ?? match, route];} } } }
1038
1061
 
1039
1062
 
1040
1063
  function _route_remove(all_route_lists, query) {
1041
- let ans = false;
1064
+ let n_removed = 0;
1042
1065
  for (let lst of all_route_lists) {
1043
1066
  let idx_tip = 0;
1044
1067
  for (let route of lst) {
1045
- // skip matching routes to remove from compacted list
1046
- if (route === query) continue
1047
1068
  if (route.topic === query.topic) {
1048
- if (null == query.tgt) continue
1049
- if (route.tgt === query.tgt) continue}
1069
+ if (null == query.tgt || route.tgt === query.tgt) {
1070
+ // skip matching routes to remove from compacted list
1071
+ n_removed++;
1072
+ continue} }
1050
1073
 
1051
1074
  lst[idx_tip++] = route;}
1052
1075
 
1053
1076
  // truncate remaining list
1054
- if (lst.splice(idx_tip).length)
1055
- ans = true;}
1056
-
1057
- return ans}
1077
+ lst.length = idx_tip;}
1078
+ return n_removed}
1058
1079
 
1059
1080
  function decode_varint(u8, i0=0, invalid) {
1060
1081
  let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
@@ -1669,7 +1690,7 @@ class MQTTCore extends MQTTBase {
1669
1690
 
1670
1691
  return this} }
1671
1692
 
1672
- const version = '0.6.4-node';
1693
+ const version = '0.6.6-node';
1673
1694
 
1674
1695
  const MQTTClient_v4 = /* #__PURE__ */
1675
1696
  with_topic_path_router(