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
@@ -45,34 +45,38 @@ function mqtt_topic_path_router() ::
45
45
  if fn :: throw new TypeError()
46
46
  fn = _ignore
47
47
 
48
- let rte = _rxp_parse @ as_topic_path @ topic_route
49
-
50
- rte.key = topic_route
51
- rte.tgt = fn
52
- pri_lsts[priority ? 0 : 1].push(rte)
48
+ let route = _rxp_parse @ as_topic_path(topic_route)
49
+ route.topic = topic_route
50
+ route.tgt = fn
51
+ pri_lsts[priority ? 0 : 1].push(route)
53
52
  return this
54
53
 
55
- remove(topic_route, priority) ::
56
- let lst = pri_lsts[priority ? 0 : 1]
57
- return _route_remove([lst], topic_route)
54
+ remove(query, ...args) ::
55
+ let lst = pri_lsts
56
+ if ('boolean' === typeof args[0]) ::
57
+ lst = [pri_lsts[args.shift() ? 0 : 1]]
58
+
59
+ if ('string' === typeof query) ::
60
+ query = @{} topic: query, tgt: args.pop()
61
+ return _route_remove(lst, query)
58
62
 
59
63
  clear(priority) ::
60
- pri_lsts[priority ? 0 : 1] = []
61
64
  if null == priority ::
62
- pri_lsts[1] = [] // null clears both lists
65
+ pri_lsts = [[],[]] // null clears both lists
66
+ else ::
67
+ pri_lsts[priority ? 0 : 1] = []
63
68
 
64
69
  async invoke(pkt, ctx) ::
65
70
  ctx.idx = 0
66
71
  ctx.rm = rm
67
72
 
68
- for let [fn, params] of find(pkt.topic) ::
73
+ for let [fn, params, route] of find(pkt.topic) ::
69
74
  let res = await fn(pkt, params, ctx)
70
75
 
71
76
  if rm === res ::
72
- _route_remove(pri_lsts, fn)
77
+ _route_remove(pri_lsts, route)
73
78
 
74
- if ctx.done ::
75
- break
79
+ if ctx.done :: break
76
80
  else ctx.idx++
77
81
 
78
82
  if 1 === pkt.qos ::
@@ -82,26 +86,33 @@ function mqtt_topic_path_router() ::
82
86
  function * _routes_iter(all_route_lists, topic) ::
83
87
  topic = topic.replace(/^[\/]*/, '/') // ensure '/' prefix for regexparam library
84
88
  for let route_list of all_route_lists ::
85
- for let {keys, pattern, tgt} of route_list ::
86
- let match = pattern.exec(topic)
89
+ for let route of route_list ::
90
+ let match = route.pattern.exec(topic)
87
91
  if match ::
88
- let params = keys
89
- ? keys.reduce @
92
+ let params = route.keys
93
+ ? route.keys.reduce @
90
94
  (o, k, i) => (o[k] = match[1+i], o)
91
95
  {}
92
96
  : match.groups ?? match
93
- yield [tgt, params]
97
+ yield [route.tgt, params, route]
94
98
 
95
99
 
96
100
  function _route_remove(all_route_lists, query) ::
97
- let fn_match = route => @
98
- route===query
99
- || route.tgt===query
100
- || route.key===query
101
+ let ans = false
101
102
  for let lst of all_route_lists ::
102
- let i = lst.findIndex(fn_match)
103
- if 0 <= i ::
104
- lst.splice(i,1)
105
- return true
106
- return false
103
+ let idx_tip = 0
104
+ for (let route of lst) ::
105
+ // skip matching routes to remove from compacted list
106
+ if (route === query) continue
107
+ if (route.topic === query.topic) ::
108
+ if (null == query.tgt) continue
109
+ if (route.tgt === query.tgt) continue
110
+
111
+ lst[idx_tip++] = route
112
+
113
+ // truncate remaining list
114
+ if (lst.splice(idx_tip).length)
115
+ ans = true
116
+
117
+ return ans
107
118
 
@@ -39,7 +39,10 @@ export const with_topic_router = mqtt_topic_router =>
39
39
  // alias: unsub_topic
40
40
  unsubscribe_topic(topic_route, ...args) ::
41
41
  let router = this.router
42
- router.remove @ topic_route, true
42
+
43
+ let fn = args.at(-1)?.call ? args.pop() : null
44
+ router.remove @ topic_route, true, fn
45
+
43
46
  let topic = router.mqtt_topic(topic_route)
44
47
  return this.unsubscribe @ topic, ...args // topic_prefix
45
48
 
package/esm/basic-v4.js CHANGED
@@ -1102,7 +1102,7 @@ class MQTTCore extends MQTTBase {
1102
1102
 
1103
1103
  return this} }
1104
1104
 
1105
- const version = '0.6.3';
1105
+ const version = '0.6.4';
1106
1106
 
1107
1107
  const MQTTClient_v4 = /* #__PURE__ */
1108
1108
  MQTTCore.mqtt_ctx(4, mqtt_opts_v4);
package/esm/basic-v5.js CHANGED
@@ -1296,7 +1296,7 @@ class MQTTCore extends MQTTBase {
1296
1296
 
1297
1297
  return this} }
1298
1298
 
1299
- const version = '0.6.3';
1299
+ const version = '0.6.4';
1300
1300
 
1301
1301
  const MQTTClient_v4 = /* #__PURE__ */
1302
1302
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5);
@@ -1102,7 +1102,7 @@ class MQTTCore extends MQTTBase {
1102
1102
 
1103
1103
  return this} }
1104
1104
 
1105
- const version = '0.6.3-deno';
1105
+ const version = '0.6.4-deno';
1106
1106
 
1107
1107
  const MQTTClient_v4 = /* #__PURE__ */
1108
1108
  MQTTCore.mqtt_ctx(4, mqtt_opts_v4);
@@ -1296,7 +1296,7 @@ class MQTTCore extends MQTTBase {
1296
1296
 
1297
1297
  return this} }
1298
1298
 
1299
- const version = '0.6.3-deno';
1299
+ const version = '0.6.4-deno';
1300
1300
 
1301
1301
  const MQTTClient_v4 = /* #__PURE__ */
1302
1302
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5);
@@ -731,7 +731,10 @@ const with_topic_router = mqtt_topic_router =>
731
731
  // alias: unsub_topic
732
732
  unsubscribe_topic(topic_route, ...args) {
733
733
  let router = this.router;
734
- router.remove(topic_route, true);
734
+
735
+ let fn = args.at(-1)?.call ? args.pop() : null;
736
+ router.remove(topic_route, true, fn);
737
+
735
738
  let topic = router.mqtt_topic(topic_route);
736
739
  return this.unsubscribe(topic, ...args ) }// topic_prefix
737
740
 
@@ -784,34 +787,38 @@ function mqtt_topic_path_router() {
784
787
  if (fn) {throw new TypeError()}
785
788
  fn = _ignore;}
786
789
 
787
- let rte = parse(as_topic_path(topic_route));
788
-
789
- rte.key = topic_route;
790
- rte.tgt = fn;
791
- pri_lsts[priority ? 0 : 1].push(rte);
790
+ let route = parse(as_topic_path(topic_route));
791
+ route.topic = topic_route;
792
+ route.tgt = fn;
793
+ pri_lsts[priority ? 0 : 1].push(route);
792
794
  return this}
793
795
 
794
- , remove(topic_route, priority) {
795
- let lst = pri_lsts[priority ? 0 : 1];
796
- return _route_remove([lst], topic_route)}
796
+ , remove(query, ...args) {
797
+ let lst = pri_lsts;
798
+ if ('boolean' === typeof args[0]) {
799
+ lst = [pri_lsts[args.shift() ? 0 : 1]];}
800
+
801
+ if ('string' === typeof query) {
802
+ query ={topic: query, tgt: args.pop()}; }
803
+ return _route_remove(lst, query)}
797
804
 
798
805
  , clear(priority) {
799
- pri_lsts[priority ? 0 : 1] = [];
800
806
  if (null == priority) {
801
- pri_lsts[1] = []; } }// null clears both lists
807
+ pri_lsts = [[],[]]; }// null clears both lists
808
+ else {
809
+ pri_lsts[priority ? 0 : 1] = [];} }
802
810
 
803
811
  , async invoke(pkt, ctx) {
804
812
  ctx.idx = 0;
805
813
  ctx.rm = rm;
806
814
 
807
- for (let [fn, params] of find(pkt.topic)) {
815
+ for (let [fn, params, route] of find(pkt.topic)) {
808
816
  let res = await fn(pkt, params, ctx);
809
817
 
810
818
  if (rm === res) {
811
- _route_remove(pri_lsts, fn);}
819
+ _route_remove(pri_lsts, route);}
812
820
 
813
- if (ctx.done) {
814
- break}
821
+ if (ctx.done) {break}
815
822
  else ctx.idx++;}
816
823
 
817
824
  if (1 === pkt.qos) {
@@ -821,28 +828,35 @@ function mqtt_topic_path_router() {
821
828
  function * _routes_iter(all_route_lists, topic) {
822
829
  topic = topic.replace(/^[\/]*/, '/'); // ensure '/' prefix for regexparam library
823
830
  for (let route_list of all_route_lists) {
824
- for (let {keys, pattern, tgt} of route_list) {
825
- let match = pattern.exec(topic);
831
+ for (let route of route_list) {
832
+ let match = route.pattern.exec(topic);
826
833
  if (match) {
827
- let params = keys
828
- ? keys.reduce(
834
+ let params = route.keys
835
+ ? route.keys.reduce(
829
836
  (o, k, i) => (o[k] = match[1+i], o)
830
837
  , {})
831
838
  : match.groups ?? match;
832
- yield [tgt, params];} } } }
839
+ yield [route.tgt, params, route];} } } }
833
840
 
834
841
 
835
842
  function _route_remove(all_route_lists, query) {
836
- let fn_match = route =>(
837
- route===query
838
- || route.tgt===query
839
- || route.key===query);
843
+ let ans = false;
840
844
  for (let lst of all_route_lists) {
841
- let i = lst.findIndex(fn_match);
842
- if (0 <= i) {
843
- lst.splice(i,1);
844
- return true} }
845
- return false}
845
+ let idx_tip = 0;
846
+ for (let route of lst) {
847
+ // skip matching routes to remove from compacted list
848
+ if (route === query) continue
849
+ if (route.topic === query.topic) {
850
+ if (null == query.tgt) continue
851
+ if (route.tgt === query.tgt) continue}
852
+
853
+ lst[idx_tip++] = route;}
854
+
855
+ // truncate remaining list
856
+ if (lst.splice(idx_tip).length)
857
+ ans = true;}
858
+
859
+ return ans}
846
860
 
847
861
  function decode_varint(u8, i0=0, invalid) {
848
862
  let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
@@ -1457,7 +1471,7 @@ class MQTTCore extends MQTTBase {
1457
1471
 
1458
1472
  return this} }
1459
1473
 
1460
- const version = '0.6.3-deno';
1474
+ const version = '0.6.4-deno';
1461
1475
 
1462
1476
  const MQTTClient_v4 = /* #__PURE__ */
1463
1477
  with_topic_path_router(