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