u8-mqtt 0.3.0 → 0.3.2-0

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 (46) hide show
  1. package/README.md +25 -10
  2. package/cjs/index.cjs +35 -8
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/v4.cjs +35 -8
  5. package/cjs/v4.cjs.map +1 -1
  6. package/cjs/v5.cjs +35 -8
  7. package/cjs/v5.cjs.map +1 -1
  8. package/code/core.jsy +41 -15
  9. package/code/{index.mjs → index.js} +2 -1
  10. package/code/{v4.mjs → v4.js} +1 -0
  11. package/code/{v5.mjs → v5.js} +1 -0
  12. package/code/version.js +1 -0
  13. package/esm/deno/index.js +40 -15
  14. package/esm/deno/index.js.map +1 -1
  15. package/esm/deno/v4.js +40 -15
  16. package/esm/deno/v4.js.map +1 -1
  17. package/esm/deno/v5.js +40 -15
  18. package/esm/deno/v5.js.map +1 -1
  19. package/esm/node/index.js +34 -8
  20. package/esm/node/index.js.map +1 -1
  21. package/esm/node/index.mjs +34 -8
  22. package/esm/node/index.mjs.map +1 -1
  23. package/esm/node/v4.js +34 -8
  24. package/esm/node/v4.js.map +1 -1
  25. package/esm/node/v4.mjs +34 -8
  26. package/esm/node/v4.mjs.map +1 -1
  27. package/esm/node/v5.js +34 -8
  28. package/esm/node/v5.js.map +1 -1
  29. package/esm/node/v5.mjs +34 -8
  30. package/esm/node/v5.mjs.map +1 -1
  31. package/esm/web/index.js +29 -4
  32. package/esm/web/index.js.map +1 -1
  33. package/esm/web/index.min.js +1 -1
  34. package/esm/web/index.min.js.br +0 -0
  35. package/esm/web/index.min.js.gz +0 -0
  36. package/esm/web/v4.js +29 -4
  37. package/esm/web/v4.js.map +1 -1
  38. package/esm/web/v4.min.js +1 -1
  39. package/esm/web/v4.min.js.br +0 -0
  40. package/esm/web/v4.min.js.gz +0 -0
  41. package/esm/web/v5.js +29 -4
  42. package/esm/web/v5.js.map +1 -1
  43. package/esm/web/v5.min.js +1 -1
  44. package/esm/web/v5.min.js.br +0 -0
  45. package/esm/web/v5.min.js.gz +0 -0
  46. package/package.json +6 -5
package/code/core.jsy CHANGED
@@ -3,6 +3,7 @@ import { MQTTBase } from './base.jsy'
3
3
 
4
4
  #IF PLAT_NODEJS
5
5
  import {connect as tcp_connect} from 'node:net'
6
+ import {connect as tls_connect} from 'node:tls'
6
7
 
7
8
  const pkt_api = {
8
9
  utf8(u8) { return new TextDecoder('utf-8').decode(u8 || this.payload ) },
@@ -27,7 +28,7 @@ export class MQTTCore extends MQTTBase ::
27
28
  return this
28
29
 
29
30
  //log_conn(evt, arg, err_arg) ::
30
- //console.info @ '[[u8-mqtt log: %s]]', evt, arg, err_arg
31
+ // console.info @ '[[u8-mqtt log: %s]]', evt, arg, err_arg
31
32
 
32
33
  on_live(client, is_reconnect) ::
33
34
  if is_reconnect ::
@@ -69,30 +70,55 @@ export class MQTTCore extends MQTTBase ::
69
70
  return this
70
71
 
71
72
 
73
+
72
74
  #IF PLAT_DENO
73
- with_tcp(port, hostname) ::
74
- if !Number.isFinite(port) ::
75
- ({port, hostname} = new URL(port))
75
+ with_tcp(...opt) ::
76
+ opt = this._conn_opt(opt)
77
+ opt.transport = 'tcp'
78
+ return this._use_conn @=>
79
+ this.with_deno_iter @
80
+ Deno.connect(opt)
76
81
 
77
- return this._use_conn @::
78
- let conn = Deno.connect @:
79
- port, hostname, transport: 'tcp'
82
+ with_tls(...opt) ::
83
+ opt = this._conn_opt(opt)
84
+ return this._use_conn @=>
85
+ this.with_deno_iter @
86
+ Deno.connectTls(opt)
80
87
 
81
- this.with_async_iter @
82
- conn.then @ Deno.iter,
83
- async u8_pkt => (await conn).write(u8_pkt)
88
+ with_deno_iter(conn) ::
89
+ return this.with_async_iter @
90
+ conn.then(Deno.iter),
91
+ async u8_pkt =>
92
+ (await conn).write(u8_pkt)
84
93
 
85
- return this
94
+ _conn_opt([a0, a1, a2]) ::
95
+ // (port, hostname, options) or (url, options)
96
+ if Number.isFinite(a0) ::
97
+ return {...a2, port: a0, hostname: a1}
86
98
 
99
+ a0 = new URL(a0)
100
+ return {...a1, port: a0.port, hostname: a0.hostname}
87
101
 
88
102
  #IF PLAT_NODEJS
89
- with_tcp(port, hostname) ::
90
- if !Number.isFinite(port) ::
91
- ({port, hostname} = new URL(port))
103
+ with_tcp(...opt) ::
104
+ opt = this._conn_opt(opt)
105
+ console.log @: opt
106
+ return this._use_conn @=>
107
+ this.with_stream @
108
+ tcp_connect(opt)
92
109
 
110
+ with_tls(...opt) ::
111
+ opt = this._conn_opt(opt)
93
112
  return this._use_conn @=>
94
113
  this.with_stream @
95
- tcp_connect(port, hostname)
114
+ tls_connect(opt)
115
+
116
+ _conn_opt([a0, a1, a2]) ::
117
+ // (port, hostname, options) or (url, options)
118
+ if Number.isFinite(a0) ::
119
+ return {...a2, port: a0, host: a1}
120
+ a0 = new URL(a0)
121
+ return {...a1, port: a0.port, host: a0.hostname}
96
122
 
97
123
 
98
124
  with_stream(read_stream, write_stream) ::
@@ -1,7 +1,8 @@
1
1
  export {
2
+ version,
2
3
  MQTTClient_v5, mqtt_v5,
3
4
  MQTTClient_v4, mqtt_v4, mqtt_v4 as default, // u8-mqtt-packet version 5 can also parse version 4 (3.1.1) packets
4
- } from './v5.mjs'
5
+ } from './v5.js'
5
6
 
6
7
  export * from './core.jsy'
7
8
  export * from './base.jsy'
@@ -1,5 +1,6 @@
1
1
  import mqtt_opts_v4 from 'u8-mqtt-packet/esm/codec_v4_client.js'
2
2
  import MQTTCore from './core.jsy'
3
+ export * from './version.js'
3
4
 
4
5
  const MQTTClient_v4 = /* #__PURE__ */
5
6
  MQTTCore.mqtt_ctx(4, mqtt_opts_v4)
@@ -1,5 +1,6 @@
1
1
  import mqtt_opts_v5 from 'u8-mqtt-packet/esm/codec_v5_client.js'
2
2
  import MQTTCore from './core.jsy'
3
+ export * from './version.js'
3
4
 
4
5
  const MQTTClient_v4 = /* #__PURE__ */
5
6
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5)
@@ -0,0 +1 @@
1
+ export const version = 'GITREPO'
package/esm/deno/index.js CHANGED
@@ -867,8 +867,6 @@ function mqtt_pkt_ctx(mqtt_level, opts, pkt_ctx) {
867
867
  }
868
868
  }
869
869
 
870
- Object.freeze({ao_done: true});
871
-
872
870
  function ao_defer_ctx(as_res = (...args) => args) {
873
871
  let y,n,_pset = (a,b) => { y=a, n=b; };
874
872
  return p =>(
@@ -1448,7 +1446,7 @@ class MQTTCore extends MQTTBase {
1448
1446
  return this}
1449
1447
 
1450
1448
  //log_conn(evt, arg, err_arg) ::
1451
- //console.info @ '[[u8-mqtt log: %s]]', evt, arg, err_arg
1449
+ // console.info @ '[[u8-mqtt log: %s]]', evt, arg, err_arg
1452
1450
 
1453
1451
  on_live(client, is_reconnect) {
1454
1452
  if (is_reconnect) {
@@ -1490,23 +1488,48 @@ class MQTTCore extends MQTTBase {
1490
1488
  return this}
1491
1489
 
1492
1490
 
1491
+
1493
1492
 
1494
- with_tcp(port, hostname) {
1495
- if (!Number.isFinite(port)) {
1496
- ({port, hostname} = new URL(port));}
1493
+ with_tcp(...opt) {
1494
+ opt = this._conn_opt(opt);
1495
+ opt.transport = 'tcp';
1496
+ return this._use_conn (() =>
1497
+ this.with_deno_iter(
1498
+ Deno.connect(opt)) ) }
1499
+
1500
+ with_tls(...opt) {
1501
+ opt = this._conn_opt(opt);
1502
+ return this._use_conn (() =>
1503
+ this.with_deno_iter(
1504
+ Deno.connectTls(opt)) ) }
1505
+
1506
+ with_deno_iter(conn) {
1507
+ return this.with_async_iter(
1508
+ conn.then(Deno.iter),
1509
+ async u8_pkt =>
1510
+ (await conn).write(u8_pkt)) }
1511
+
1512
+ _conn_opt([a0, a1, a2]) {
1513
+ // (port, hostname, options) or (url, options)
1514
+ if (Number.isFinite(a0)) {
1515
+ return {...a2, port: a0, hostname: a1}}
1516
+
1517
+ a0 = new URL(a0);
1518
+ return {...a1, port: a0.port, hostname: a0.hostname}}
1519
+
1520
+
1521
+
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1497
1528
 
1498
- return this._use_conn (() => {
1499
- let conn = Deno.connect({
1500
- port, hostname, transport: 'tcp'});
1501
1529
 
1502
- this.with_async_iter(
1503
- conn.then(Deno.iter,)
1504
- , async u8_pkt => (await conn).write(u8_pkt));
1505
1530
 
1506
- return this}) }
1507
1531
 
1508
1532
 
1509
-
1510
1533
 
1511
1534
 
1512
1535
 
@@ -1559,6 +1582,8 @@ class MQTTCore extends MQTTBase {
1559
1582
 
1560
1583
  return this} }
1561
1584
 
1585
+ const version = '0.3.2-0';
1586
+
1562
1587
  const MQTTClient_v4 = /* #__PURE__ */
1563
1588
  MQTTCore.mqtt_ctx(4, mqtt_opts_v5);
1564
1589
 
@@ -1571,5 +1596,5 @@ const mqtt_v4 = opt =>
1571
1596
  const mqtt_v5 = opt =>
1572
1597
  new MQTTClient_v5(opt);
1573
1598
 
1574
- export { MQTTBase, MQTTClient_v4, MQTTClient_v5, MQTTCore, MQTTError, _mqtt_cmdid_dispatch, _mqtt_conn, _mqtt_dispatch, _mqtt_route_match_one, _mqtt_route_remove, _mqtt_routes_iter, _mqtt_topic_router, ao_defer_v, mqtt_v4 as default, mqtt_v4, mqtt_v5 };
1599
+ export { MQTTBase, MQTTClient_v4, MQTTClient_v5, MQTTCore, MQTTError, _mqtt_cmdid_dispatch, _mqtt_conn, _mqtt_dispatch, _mqtt_route_match_one, _mqtt_route_remove, _mqtt_routes_iter, _mqtt_topic_router, ao_defer_v, mqtt_v4 as default, mqtt_v4, mqtt_v5, version };
1575
1600
  //# sourceMappingURL=index.js.map