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
@@ -1105,7 +1105,7 @@ class MQTTCore extends MQTTBase {
1105
1105
 
1106
1106
  return this} }
1107
1107
 
1108
- const version = '0.6.4-node';
1108
+ const version = '0.6.6-node';
1109
1109
 
1110
1110
  const MQTTClient_v4 = /* #__PURE__ */
1111
1111
  MQTTCore.mqtt_ctx(4, mqtt_opts_v4);
@@ -1299,7 +1299,7 @@ class MQTTCore extends MQTTBase {
1299
1299
 
1300
1300
  return this} }
1301
1301
 
1302
- const version = '0.6.4-node';
1302
+ const version = '0.6.6-node';
1303
1303
 
1304
1304
  const MQTTClient_v4 = /* #__PURE__ */
1305
1305
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5);
@@ -1299,7 +1299,7 @@ class MQTTCore extends MQTTBase {
1299
1299
 
1300
1300
  return this} }
1301
1301
 
1302
- const version = '0.6.4-node';
1302
+ const version = '0.6.6-node';
1303
1303
 
1304
1304
  const MQTTClient_v4 = /* #__PURE__ */
1305
1305
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5);
@@ -649,16 +649,20 @@ const mqtt_opts_v4 =
649
649
  encode_fns: mqtt_encode_v4,
650
650
  mqtt_writer: mqtt_writer_v4, };
651
651
 
652
- function parse(str, loose) {
653
- if (str instanceof RegExp) return { keys:false, pattern:str };
654
- var c, o, tmp, ext, keys=[], pattern='', arr = str.split('/');
652
+ /**
653
+ * @param {string|RegExp} input The route pattern
654
+ * @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
655
+ */
656
+ function parse(input, loose) {
657
+ if (input instanceof RegExp) return { keys:false, pattern:input };
658
+ var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
655
659
  arr[0] || arr.shift();
656
660
 
657
661
  while (tmp = arr.shift()) {
658
662
  c = tmp[0];
659
663
  if (c === '*') {
660
- keys.push('wild');
661
- pattern += '/(.*)';
664
+ keys.push(c);
665
+ pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
662
666
  } else if (c === ':') {
663
667
  o = tmp.indexOf('?', 1);
664
668
  ext = tmp.indexOf('.', 1);
@@ -698,6 +702,7 @@ class AbstractTopicRouter ::
698
702
  async invoke(pkt, ctx) ::
699
703
  add(topic_route, ...args) ::
700
704
  remove(topic_route, priority) ::
705
+ count(topic_route) ::
701
706
  clear(priority) ::
702
707
  find(topic) :: // optional
703
708
  mqtt_topic(topic_route)
@@ -737,6 +742,8 @@ const with_topic_router = mqtt_topic_router =>
737
742
 
738
743
  let fn = args.at(-1)?.call ? args.pop() : null;
739
744
  router.remove(topic_route, true, fn);
745
+ if (0 !== router.count(topic_route) ) {
746
+ return null}
740
747
 
741
748
  let topic = router.mqtt_topic(topic_route);
742
749
  return this.unsubscribe(topic, ...args ) }// topic_prefix
@@ -805,6 +812,17 @@ function mqtt_topic_path_router() {
805
812
  query ={topic: query, tgt: args.pop()}; }
806
813
  return _route_remove(lst, query)}
807
814
 
815
+ , count(topic_route) {
816
+ if (! topic_route) {
817
+ return pri_lsts.reduce((r,l) => r+l.length, 0)}
818
+
819
+ let count = 0;
820
+ for (let lst of pri_lsts) {
821
+ for (let route of lst) {
822
+ if (topic_route === route.topic) {
823
+ count++;} } }
824
+ return count}
825
+
808
826
  , clear(priority) {
809
827
  if (null == priority) {
810
828
  pri_lsts = [[],[]]; }// null clears both lists
@@ -828,38 +846,41 @@ function mqtt_topic_path_router() {
828
846
  await ctx.mqtt.puback(pkt);} } } }
829
847
 
830
848
 
849
+ const _regexparam ={
850
+ get wild() {return this['*']}
851
+ , set wild(v) {return this['*']=wild} };
852
+
831
853
  function * _routes_iter(all_route_lists, topic) {
832
854
  topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
833
- for (let route_list of all_route_lists) {
834
- for (let route of route_list) {
835
- let match = route.pattern.exec(topic);
836
- if (match) {
837
- let params = route.keys
838
- ? route.keys.reduce(
839
- (o, k, i) => (o[k] = match[1+i], o)
840
- , {})
841
- : match.groups ?? match;
842
- yield [route.tgt, params, route];} } } }
855
+ for (let route of all_route_lists.flat()) {
856
+ let match = route?.pattern.exec(topic);
857
+ if (match) {
858
+ let keys = route.keys;
859
+ if (keys) {
860
+ let k, i=0, params={__proto__:_regexparam};
861
+ for (k of keys) {
862
+ params[k] = match[++i];}
863
+ yield [route.tgt, params, route];}
864
+ else {
865
+ yield [route.tgt, match.groups ?? match, route];} } } }
843
866
 
844
867
 
845
868
  function _route_remove(all_route_lists, query) {
846
- let ans = false;
869
+ let n_removed = 0;
847
870
  for (let lst of all_route_lists) {
848
871
  let idx_tip = 0;
849
872
  for (let route of lst) {
850
- // skip matching routes to remove from compacted list
851
- if (route === query) continue
852
873
  if (route.topic === query.topic) {
853
- if (null == query.tgt) continue
854
- if (route.tgt === query.tgt) continue}
874
+ if (null == query.tgt || route.tgt === query.tgt) {
875
+ // skip matching routes to remove from compacted list
876
+ n_removed++;
877
+ continue} }
855
878
 
856
879
  lst[idx_tip++] = route;}
857
880
 
858
881
  // truncate remaining list
859
- if (lst.splice(idx_tip).length)
860
- ans = true;}
861
-
862
- return ans}
882
+ lst.length = idx_tip;}
883
+ return n_removed}
863
884
 
864
885
  function decode_varint(u8, i0=0, invalid) {
865
886
  let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
@@ -1474,7 +1495,7 @@ class MQTTCore extends MQTTBase {
1474
1495
 
1475
1496
  return this} }
1476
1497
 
1477
- const version = '0.6.4-node';
1498
+ const version = '0.6.6-node';
1478
1499
 
1479
1500
  const MQTTClient_v4 = /* #__PURE__ */
1480
1501
  with_topic_path_router(