@seriousme/opifex 2.0.3 → 2.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.
- package/client/ConnectionState.ts +1 -1
- package/client/client.ts +41 -9
- package/client/context.ts +11 -13
- package/client/deps.ts +8 -5
- package/client/handlers/handleConnack.ts +2 -2
- package/client/mod.ts +13 -2
- package/client/store/memoryStore.ts +11 -10
- package/client/store/store.ts +1 -1
- package/deno/mod.ts +7 -0
- package/deno/tcpClient.ts +21 -8
- package/deno/tcpServer.ts +21 -4
- package/deno/tlsServer.ts +20 -4
- package/deno/wsServer.ts +23 -0
- package/dist/client/ConnectionState.d.ts +1 -1
- package/dist/client/ConnectionState.d.ts.map +1 -1
- package/dist/client/client.d.ts +39 -9
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +24 -0
- package/dist/client/client.js.map +1 -1
- package/dist/client/context.d.ts +8 -8
- package/dist/client/context.d.ts.map +1 -1
- package/dist/client/context.js.map +1 -1
- package/dist/client/deps.d.ts +3 -3
- package/dist/client/deps.d.ts.map +1 -1
- package/dist/client/deps.js.map +1 -1
- package/dist/client/handlers/handleConnack.d.ts.map +1 -1
- package/dist/client/handlers/handleConnack.js.map +1 -1
- package/dist/client/mod.d.ts +3 -2
- package/dist/client/mod.d.ts.map +1 -1
- package/dist/client/mod.js +1 -1
- package/dist/client/mod.js.map +1 -1
- package/dist/client/store/memoryStore.d.ts +3 -3
- package/dist/client/store/memoryStore.d.ts.map +1 -1
- package/dist/client/store/memoryStore.js +2 -2
- package/dist/client/store/memoryStore.js.map +1 -1
- package/dist/client/store/store.d.ts +1 -1
- package/dist/client/store/store.d.ts.map +1 -1
- package/dist/examples/authHandler.test.js +3 -3
- package/dist/examples/authHandler.test.js.map +1 -1
- package/dist/mqttConn/mqttConn.d.ts +2 -17
- package/dist/mqttConn/mqttConn.d.ts.map +1 -1
- package/dist/mqttConn/mqttConn.js +1 -1
- package/dist/mqttConn/mqttConn.js.map +1 -1
- package/dist/mqttPacket/AuthenticationResult.d.ts +4 -0
- package/dist/mqttPacket/AuthenticationResult.d.ts.map +1 -1
- package/dist/mqttPacket/AuthenticationResult.js.map +1 -1
- package/dist/mqttPacket/PacketType.d.ts +4 -0
- package/dist/mqttPacket/PacketType.d.ts.map +1 -1
- package/dist/mqttPacket/Properties.d.ts +2 -2
- package/dist/mqttPacket/Properties.d.ts.map +1 -1
- package/dist/mqttPacket/ReasonCode.d.ts +3 -5
- package/dist/mqttPacket/ReasonCode.d.ts.map +1 -1
- package/dist/mqttPacket/ReasonCode.js.map +1 -1
- package/dist/mqttPacket/RetainHandling.d.ts +4 -0
- package/dist/mqttPacket/RetainHandling.d.ts.map +1 -1
- package/dist/mqttPacket/auth.d.ts +6 -5
- package/dist/mqttPacket/auth.d.ts.map +1 -1
- package/dist/mqttPacket/auth.js +2 -2
- package/dist/mqttPacket/auth.js.map +1 -1
- package/dist/mqttPacket/codec.d.ts.map +1 -1
- package/dist/mqttPacket/codec.js.map +1 -1
- package/dist/mqttPacket/connack.d.ts +9 -7
- package/dist/mqttPacket/connack.d.ts.map +1 -1
- package/dist/mqttPacket/connack.js +2 -2
- package/dist/mqttPacket/connack.js.map +1 -1
- package/dist/mqttPacket/connect.d.ts +5 -4
- package/dist/mqttPacket/connect.d.ts.map +1 -1
- package/dist/mqttPacket/connect.js.map +1 -1
- package/dist/mqttPacket/decoder.d.ts +6 -4
- package/dist/mqttPacket/decoder.d.ts.map +1 -1
- package/dist/mqttPacket/decoder.js +1 -1
- package/dist/mqttPacket/decoder.js.map +1 -1
- package/dist/mqttPacket/disconnect.d.ts +7 -5
- package/dist/mqttPacket/disconnect.d.ts.map +1 -1
- package/dist/mqttPacket/disconnect.js +2 -2
- package/dist/mqttPacket/disconnect.js.map +1 -1
- package/dist/mqttPacket/encoder.d.ts +7 -5
- package/dist/mqttPacket/encoder.d.ts.map +1 -1
- package/dist/mqttPacket/encoder.js +1 -1
- package/dist/mqttPacket/encoder.js.map +1 -1
- package/dist/mqttPacket/mod.d.ts +1 -1
- package/dist/mqttPacket/mod.d.ts.map +1 -1
- package/dist/mqttPacket/pingreq.d.ts +4 -3
- package/dist/mqttPacket/pingreq.d.ts.map +1 -1
- package/dist/mqttPacket/pingreq.js.map +1 -1
- package/dist/mqttPacket/pingres.d.ts +4 -3
- package/dist/mqttPacket/pingres.d.ts.map +1 -1
- package/dist/mqttPacket/pingres.js.map +1 -1
- package/dist/mqttPacket/protocolLevels.d.ts +2 -0
- package/dist/mqttPacket/protocolLevels.d.ts.map +1 -1
- package/dist/mqttPacket/pubblishAcks.d.ts +7 -7
- package/dist/mqttPacket/pubblishAcks.d.ts.map +1 -1
- package/dist/mqttPacket/pubblishAcks.js +2 -2
- package/dist/mqttPacket/pubblishAcks.js.map +1 -1
- package/dist/mqttPacket/publish.d.ts +5 -4
- package/dist/mqttPacket/publish.d.ts.map +1 -1
- package/dist/mqttPacket/publish.js.map +1 -1
- package/dist/mqttPacket/suback.d.ts +7 -5
- package/dist/mqttPacket/suback.d.ts.map +1 -1
- package/dist/mqttPacket/suback.js +2 -2
- package/dist/mqttPacket/suback.js.map +1 -1
- package/dist/mqttPacket/subscribe.d.ts +7 -5
- package/dist/mqttPacket/subscribe.d.ts.map +1 -1
- package/dist/mqttPacket/subscribe.js.map +1 -1
- package/dist/mqttPacket/types.d.ts +1 -21
- package/dist/mqttPacket/types.d.ts.map +1 -1
- package/dist/mqttPacket/unsuback.d.ts +7 -5
- package/dist/mqttPacket/unsuback.d.ts.map +1 -1
- package/dist/mqttPacket/unsuback.js +1 -1
- package/dist/mqttPacket/unsuback.js.map +1 -1
- package/dist/mqttPacket/unsubscribe.d.ts +5 -4
- package/dist/mqttPacket/unsubscribe.d.ts.map +1 -1
- package/dist/mqttPacket/unsubscribe.js.map +1 -1
- package/dist/node/tcpClient.d.ts +21 -1
- package/dist/node/tcpClient.d.ts.map +1 -1
- package/dist/node/tcpClient.js +18 -4
- package/dist/node/tcpClient.js.map +1 -1
- package/dist/node/tcpServer.d.ts +18 -0
- package/dist/node/tcpServer.d.ts.map +1 -1
- package/dist/node/tcpServer.js +17 -2
- package/dist/node/tcpServer.js.map +1 -1
- package/dist/node/tlsServer.d.ts +18 -0
- package/dist/node/tlsServer.d.ts.map +1 -1
- package/dist/node/tlsServer.js +17 -2
- package/dist/node/tlsServer.js.map +1 -1
- package/dist/persistence/basicPersistence.d.ts +4 -4
- package/dist/persistence/basicPersistence.d.ts.map +1 -1
- package/dist/persistence/basicPersistence.js.map +1 -1
- package/dist/persistence/deps.d.ts +1 -1
- package/dist/persistence/deps.d.ts.map +1 -1
- package/dist/persistence/memory/memoryStorage.d.ts +3 -3
- package/dist/persistence/memory/memoryStorage.d.ts.map +1 -1
- package/dist/persistence/mod.d.ts +1 -1
- package/dist/persistence/mod.d.ts.map +1 -1
- package/dist/persistence/persistence.d.ts +3 -3
- package/dist/persistence/persistence.d.ts.map +1 -1
- package/dist/persistence/sqlite/sqliteStorage.d.ts +2 -2
- package/dist/persistence/sqlite/sqliteStorage.d.ts.map +1 -1
- package/dist/persistence/storage.d.ts +1 -1
- package/dist/persistence/storage.d.ts.map +1 -1
- package/dist/server/context.d.ts +4 -4
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js.map +1 -1
- package/dist/server/deps.d.ts +2 -2
- package/dist/server/deps.d.ts.map +1 -1
- package/dist/server/deps.js.map +1 -1
- package/dist/server/handlers/completeConnect.d.ts +3 -2
- package/dist/server/handlers/completeConnect.d.ts.map +1 -1
- package/dist/server/handlers/completeConnect.js.map +1 -1
- package/dist/server/handlers/handlePublish.d.ts.map +1 -1
- package/dist/server/handlers/handlePublish.js.map +1 -1
- package/dist/server/handlers/handleSubscribe.d.ts.map +1 -1
- package/dist/server/handlers/handleSubscribe.js.map +1 -1
- package/dist/server/handlers/handleUnsubscribe.d.ts.map +1 -1
- package/dist/server/handlers/handleUnsubscribe.js.map +1 -1
- package/dist/server/mod.d.ts +1 -1
- package/dist/server/mod.d.ts.map +1 -1
- package/dist/server/server.d.ts +3 -3
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js.map +1 -1
- package/dist/socket/socket.d.ts +22 -0
- package/dist/socket/socket.d.ts.map +1 -1
- package/dist/socket/socket.js +5 -0
- package/dist/socket/socket.js.map +1 -1
- package/dist/utils/logger.d.ts +3 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/web/wsClient.d.ts +12 -0
- package/dist/web/wsClient.d.ts.map +1 -1
- package/dist/web/wsClient.js +12 -1
- package/dist/web/wsClient.js.map +1 -1
- package/examples/authHandler.test.ts +3 -3
- package/mqttConn/mqttConn.ts +2 -18
- package/mqttPacket/AuthenticationResult.ts +6 -0
- package/mqttPacket/PacketType.ts +5 -0
- package/mqttPacket/Properties.ts +2 -2
- package/mqttPacket/ReasonCode.ts +6 -8
- package/mqttPacket/RetainHandling.ts +5 -0
- package/mqttPacket/auth.ts +7 -7
- package/mqttPacket/codec.ts +3 -2
- package/mqttPacket/connack.ts +11 -10
- package/mqttPacket/connect.ts +4 -11
- package/mqttPacket/decoder.ts +9 -11
- package/mqttPacket/disconnect.ts +7 -7
- package/mqttPacket/encoder.test.ts +2 -2
- package/mqttPacket/encoder.ts +9 -7
- package/mqttPacket/mod.ts +0 -4
- package/mqttPacket/pingreq.ts +3 -3
- package/mqttPacket/pingres.ts +3 -3
- package/mqttPacket/protocolLevels.ts +2 -0
- package/mqttPacket/pubblishAcks.ts +9 -9
- package/mqttPacket/publish.ts +4 -11
- package/mqttPacket/publishAcks.test.ts +3 -3
- package/mqttPacket/suback.ts +8 -13
- package/mqttPacket/subscribe.ts +6 -12
- package/mqttPacket/types.ts +1 -26
- package/mqttPacket/unsuback.ts +8 -7
- package/mqttPacket/unsubscribe.ts +4 -10
- package/node/mod.ts +7 -0
- package/node/tcpClient.ts +21 -6
- package/node/tcpServer.ts +23 -6
- package/node/tlsServer.ts +23 -7
- package/package.json +6 -1
- package/persistence/basicPersistence.ts +5 -5
- package/persistence/deps.ts +1 -1
- package/persistence/memory/memoryStorage.ts +3 -3
- package/persistence/mod.ts +1 -1
- package/persistence/persistence.testing.ts +4 -4
- package/persistence/persistence.ts +3 -3
- package/persistence/sqlite/sqliteStorage.ts +2 -2
- package/persistence/storage.ts +1 -1
- package/server/context.ts +5 -5
- package/server/deps.ts +1 -2
- package/server/handlers/completeConnect.ts +2 -2
- package/server/handlers/handlePublish.ts +3 -4
- package/server/handlers/handleSubscribe.ts +3 -4
- package/server/handlers/handleUnsubscribe.ts +2 -2
- package/server/mod.ts +1 -1
- package/server/server.ts +3 -3
- package/socket/socket.ts +31 -2
- package/tools/benchmarks/receiver.ts +2 -2
- package/tools/benchmarks/sender.ts +2 -2
- package/utils/logger.ts +3 -3
- package/web/wsClient.ts +13 -1
package/mqttPacket/subscribe.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CodecOpts,
|
|
3
|
-
PacketId,
|
|
4
|
-
QoS,
|
|
5
|
-
TopicFilter,
|
|
6
|
-
TPacketType,
|
|
7
|
-
TRetainHandling,
|
|
8
|
-
} from "./types.ts";
|
|
1
|
+
import type { CodecOpts, PacketId, QoS, TopicFilter } from "./types.ts";
|
|
9
2
|
import type { ProtocolLevelNoV5 } from "./protocolLevels.ts";
|
|
10
3
|
import type { SubscribeProperties } from "./Properties.ts";
|
|
4
|
+
import type { RetainHandling } from "./RetainHandling.ts";
|
|
11
5
|
import { PacketType } from "./PacketType.ts";
|
|
12
6
|
import { BitMask } from "./BitMask.ts";
|
|
13
7
|
import { Encoder } from "./encoder.ts";
|
|
@@ -18,7 +12,7 @@ import { booleanFlag, Decoder, DecoderError } from "./decoder.ts";
|
|
|
18
12
|
*/
|
|
19
13
|
export type SubscribePacketV4 = {
|
|
20
14
|
/** The type of the MQTT control packet. */
|
|
21
|
-
type:
|
|
15
|
+
type: PacketType;
|
|
22
16
|
/** The protocol version level, restricted to non-v5 variants. */
|
|
23
17
|
protocolLevel: ProtocolLevelNoV5;
|
|
24
18
|
/** The unique 16-bit packet identifier. */
|
|
@@ -32,7 +26,7 @@ export type SubscribePacketV4 = {
|
|
|
32
26
|
*/
|
|
33
27
|
export type SubscribePacketV5 = {
|
|
34
28
|
/** The type of the MQTT control packet. */
|
|
35
|
-
type:
|
|
29
|
+
type: PacketType;
|
|
36
30
|
/** The protocol version level, strictly set to 5. */
|
|
37
31
|
protocolLevel: 5;
|
|
38
32
|
/** The unique 16-bit packet identifier. */
|
|
@@ -71,7 +65,7 @@ export type SubscriptionV5 = {
|
|
|
71
65
|
/** Optional flag indicating whether messages forwarded under this subscription keep their original retain flag. */
|
|
72
66
|
retainAsPublished?: boolean;
|
|
73
67
|
/** Optional setting declaring how retained messages are handled when the subscription is created. */
|
|
74
|
-
retainHandling?:
|
|
68
|
+
retainHandling?: RetainHandling;
|
|
75
69
|
};
|
|
76
70
|
|
|
77
71
|
/** * Represents a generic union of MQTT subscription configurations (v4 or v5).
|
|
@@ -126,7 +120,7 @@ export function decode(
|
|
|
126
120
|
buffer: Uint8Array,
|
|
127
121
|
flags: number,
|
|
128
122
|
codecOpts: CodecOpts,
|
|
129
|
-
packetType:
|
|
123
|
+
packetType: PacketType,
|
|
130
124
|
): SubscribePacket {
|
|
131
125
|
// Bits 3,2,1 and 0 of the fixed header of the SUBSCRIBE Control Packet are reserved and
|
|
132
126
|
// MUST be set to 0,0,1 and 0 respectively. The Server MUST treat any other value as
|
package/mqttPacket/types.ts
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
import type { BitMask } from "./BitMask.ts";
|
|
2
|
-
import type { PacketType } from "./PacketType.ts";
|
|
3
|
-
import type { RetainHandling } from "./RetainHandling.ts";
|
|
4
|
-
import type { AuthenticationResult } from "./AuthenticationResult.ts";
|
|
5
|
-
import type { ReasonCode } from "./ReasonCode.ts";
|
|
6
2
|
import type { ProtocolLevel } from "./protocolLevels.ts";
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Type to limit bit mask to valid values
|
|
10
6
|
*/
|
|
11
|
-
export type
|
|
12
|
-
/**
|
|
13
|
-
* Type to limit packet type to valid values
|
|
14
|
-
*/
|
|
15
|
-
export type TPacketType = typeof PacketType[keyof typeof PacketType];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Type to limit authentication result to valid values
|
|
19
|
-
*/
|
|
20
|
-
export type TAuthenticationResult =
|
|
21
|
-
typeof AuthenticationResult[keyof typeof AuthenticationResult];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Type to limit reason code to valid values
|
|
25
|
-
*/
|
|
26
|
-
export type TReasonCode = typeof ReasonCode[keyof typeof ReasonCode];
|
|
7
|
+
export type BitMask = typeof BitMask[keyof typeof BitMask];
|
|
27
8
|
|
|
28
9
|
/**
|
|
29
10
|
* Quality of Service level
|
|
@@ -65,12 +46,6 @@ export type ReturnCodes = number[];
|
|
|
65
46
|
*/
|
|
66
47
|
export type ClientId = string;
|
|
67
48
|
|
|
68
|
-
/**
|
|
69
|
-
* helper type to limit retain handling values
|
|
70
|
-
*/
|
|
71
|
-
export type TRetainHandling =
|
|
72
|
-
typeof RetainHandling[keyof typeof RetainHandling];
|
|
73
|
-
|
|
74
49
|
/**
|
|
75
50
|
* UTF8 string pair (for v5)
|
|
76
51
|
*/
|
package/mqttPacket/unsuback.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import type { CodecOpts, PacketId
|
|
1
|
+
import type { CodecOpts, PacketId } from "./types.ts";
|
|
2
2
|
import type { ProtocolLevelNoV5 } from "./protocolLevels.ts";
|
|
3
3
|
import type { UnsubackProperties } from "./Properties.ts";
|
|
4
|
+
import type { ReasonCode } from "./ReasonCode.ts";
|
|
4
5
|
import { PacketType } from "./PacketType.ts";
|
|
5
6
|
import { Decoder, hasEmptyFlags } from "./decoder.ts";
|
|
6
7
|
import { Encoder } from "./encoder.ts";
|
|
7
8
|
|
|
8
9
|
export type UnsubackPacketV4 = {
|
|
9
|
-
type:
|
|
10
|
+
type: PacketType;
|
|
10
11
|
protocolLevel: ProtocolLevelNoV5;
|
|
11
12
|
id: PacketId;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export type UnsubackPacketV5 = {
|
|
15
|
-
type:
|
|
16
|
+
type: PacketType;
|
|
16
17
|
protocolLevel: 5;
|
|
17
18
|
id: PacketId;
|
|
18
19
|
properties: UnsubackProperties;
|
|
19
|
-
reasonCodes: Array<
|
|
20
|
+
reasonCodes: Array<ReasonCode>;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -49,7 +50,7 @@ export function decode(
|
|
|
49
50
|
buffer: Uint8Array,
|
|
50
51
|
flags: number,
|
|
51
52
|
codecOpts: CodecOpts,
|
|
52
|
-
packetType:
|
|
53
|
+
packetType: PacketType,
|
|
53
54
|
): UnsubackPacket {
|
|
54
55
|
hasEmptyFlags(flags);
|
|
55
56
|
const decoder = new Decoder(packetType, buffer);
|
|
@@ -58,7 +59,7 @@ export function decode(
|
|
|
58
59
|
const properties = decoder.getProperties(PacketType.unsuback);
|
|
59
60
|
const reasonCodes = [];
|
|
60
61
|
while (!decoder.atEnd()) {
|
|
61
|
-
const reasonCode = decoder.
|
|
62
|
+
const reasonCode = decoder.geReasonCode();
|
|
62
63
|
reasonCodes.push(reasonCode);
|
|
63
64
|
}
|
|
64
65
|
return {
|
|
@@ -66,7 +67,7 @@ export function decode(
|
|
|
66
67
|
protocolLevel: 5,
|
|
67
68
|
id,
|
|
68
69
|
properties,
|
|
69
|
-
reasonCodes: reasonCodes as Array<
|
|
70
|
+
reasonCodes: reasonCodes as Array<ReasonCode>,
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
decoder.done();
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CodecOpts,
|
|
3
|
-
PacketId,
|
|
4
|
-
Topic,
|
|
5
|
-
TopicFilter,
|
|
6
|
-
TPacketType,
|
|
7
|
-
} from "./types.ts";
|
|
1
|
+
import type { CodecOpts, PacketId, Topic, TopicFilter } from "./types.ts";
|
|
8
2
|
import type { ProtocolLevelNoV5 } from "./protocolLevels.ts";
|
|
9
3
|
import type { UnsubscribeProperties } from "./Properties.ts";
|
|
10
4
|
import { PacketType } from "./PacketType.ts";
|
|
@@ -16,7 +10,7 @@ import { Decoder, DecoderError } from "./decoder.ts";
|
|
|
16
10
|
*/
|
|
17
11
|
export type UnsubscribePacketV4 = {
|
|
18
12
|
/** The type of the MQTT control packet. */
|
|
19
|
-
type:
|
|
13
|
+
type: PacketType;
|
|
20
14
|
/** The protocol version level, restricted to non-v5 variants. */
|
|
21
15
|
protocolLevel: ProtocolLevelNoV5;
|
|
22
16
|
/** The unique 16-bit packet identifier. */
|
|
@@ -30,7 +24,7 @@ export type UnsubscribePacketV4 = {
|
|
|
30
24
|
*/
|
|
31
25
|
export type UnsubscribePacketV5 = {
|
|
32
26
|
/** The type of the MQTT control packet. */
|
|
33
|
-
type:
|
|
27
|
+
type: PacketType;
|
|
34
28
|
/** The protocol version level, strictly set to 5. */
|
|
35
29
|
protocolLevel: 5;
|
|
36
30
|
/** The unique 16-bit packet identifier. */
|
|
@@ -77,7 +71,7 @@ export function decode(
|
|
|
77
71
|
buffer: Uint8Array,
|
|
78
72
|
flags: number,
|
|
79
73
|
codecOpts: CodecOpts,
|
|
80
|
-
packetType:
|
|
74
|
+
packetType: PacketType,
|
|
81
75
|
): UnsubscribePacket {
|
|
82
76
|
if (flags !== 0b0010) {
|
|
83
77
|
throw new DecoderError("Invalid header");
|
package/node/mod.ts
ADDED
package/node/tcpClient.ts
CHANGED
|
@@ -12,7 +12,8 @@ import type { SockConn } from "../socket/socket.ts";
|
|
|
12
12
|
import { wrapNodeSocket } from "./wrapNodeSocket.ts";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Fetches data from a file and returns it as a string
|
|
16
|
+
*
|
|
16
17
|
* @param filename
|
|
17
18
|
* @returns Promise
|
|
18
19
|
*
|
|
@@ -20,7 +21,9 @@ import { wrapNodeSocket } from "./wrapNodeSocket.ts";
|
|
|
20
21
|
* @example
|
|
21
22
|
* const data = await getFileData("data.txt");
|
|
22
23
|
*/
|
|
23
|
-
export async function getFileData(
|
|
24
|
+
export async function getFileData(
|
|
25
|
+
filename: string | undefined,
|
|
26
|
+
): Promise<string | undefined> {
|
|
24
27
|
if (!filename) {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
@@ -31,13 +34,16 @@ export async function getFileData(filename: string | undefined) {
|
|
|
31
34
|
return data;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
*
|
|
37
|
+
/**
|
|
38
|
+
* TcpClient extends the Client class to provide TCP based clients
|
|
36
39
|
* it is used by the MQTTclient to connect to the broker
|
|
37
40
|
* see mqtt.ts in the /bin folder as an example
|
|
38
41
|
*/
|
|
39
|
-
|
|
40
42
|
export class TcpClient extends Client {
|
|
43
|
+
/** Connect using MQTT over TCP
|
|
44
|
+
* @param hostname the name of the host to connect to
|
|
45
|
+
* @param port the port number
|
|
46
|
+
*/
|
|
41
47
|
protected connectMQTT(hostname: string, port = 1883): Promise<SockConn> {
|
|
42
48
|
logger.debug({ hostname, port });
|
|
43
49
|
return new Promise((resolve, reject) => {
|
|
@@ -55,6 +61,15 @@ export class TcpClient extends Client {
|
|
|
55
61
|
});
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Connect using MQTT over TLS
|
|
66
|
+
* @param hostname the name of the host to connect to
|
|
67
|
+
* @param port the port number
|
|
68
|
+
* @param caCerts the CA certificates to trust
|
|
69
|
+
* @param cert the clients certificate
|
|
70
|
+
* @param key the clients private key
|
|
71
|
+
* @returns a SockConn object
|
|
72
|
+
*/
|
|
58
73
|
protected connectMQTTS(
|
|
59
74
|
hostname: string,
|
|
60
75
|
port = 8883,
|
|
@@ -83,7 +98,7 @@ export class TcpClient extends Client {
|
|
|
83
98
|
});
|
|
84
99
|
}
|
|
85
100
|
|
|
86
|
-
|
|
101
|
+
/** createConn is used by the base client class */
|
|
87
102
|
protected override createConn(): Promise<SockConn> {
|
|
88
103
|
const { protocol, hostname, port: portStr } = this.connectUrl;
|
|
89
104
|
const port = Number(portStr);
|
package/node/tcpServer.ts
CHANGED
|
@@ -14,19 +14,26 @@ type ServerOptions = {
|
|
|
14
14
|
port?: number;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
* TCP server that wraps a MqttServer, see
|
|
17
|
+
/**
|
|
18
|
+
* TCP server that wraps a MqttServer, see the /examples folder
|
|
19
19
|
*/
|
|
20
20
|
export class TcpServer {
|
|
21
21
|
private mqttServer: MqttServer;
|
|
22
22
|
private server?: Server;
|
|
23
23
|
private serverOptions;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a new TCP server
|
|
27
|
+
*/
|
|
24
28
|
constructor(serverOptions: ServerOptions, mqttOptions: MqttServerOptions) {
|
|
25
29
|
this.mqttServer = new MqttServer(mqttOptions);
|
|
26
30
|
this.serverOptions = serverOptions;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Start listening
|
|
35
|
+
*/
|
|
36
|
+
async start(): Promise<void> {
|
|
30
37
|
this.server = createServer((sock) =>
|
|
31
38
|
this.mqttServer.serve(wrapNodeSocket(sock))
|
|
32
39
|
);
|
|
@@ -39,12 +46,19 @@ export class TcpServer {
|
|
|
39
46
|
await isListening;
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
|
-
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Stop listening
|
|
52
|
+
*/
|
|
53
|
+
stop(): void {
|
|
43
54
|
this.mqttServer.close();
|
|
44
55
|
this.server?.close();
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The port number the server is listening on
|
|
60
|
+
*/
|
|
61
|
+
get port(): number | undefined {
|
|
48
62
|
const address = this.server?.address();
|
|
49
63
|
// deno-coverage-ignore-start
|
|
50
64
|
if (typeof address === "object" && address !== null) {
|
|
@@ -54,7 +68,10 @@ export class TcpServer {
|
|
|
54
68
|
// deno-coverage-ignore-stop
|
|
55
69
|
}
|
|
56
70
|
|
|
57
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The address the server is listening on
|
|
73
|
+
*/
|
|
74
|
+
get address(): string | undefined {
|
|
58
75
|
const addressResult = this.server?.address();
|
|
59
76
|
// deno-coverage-ignore-start
|
|
60
77
|
if (typeof addressResult === "object") {
|
package/node/tlsServer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* This module provides a NodeJS specific implementation of a
|
|
2
|
+
* This module provides a NodeJS specific implementation of a TLS socket listener
|
|
3
3
|
* it uses the platform agnostic MqttServer class
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
@@ -16,20 +16,26 @@ type ServerOptions = {
|
|
|
16
16
|
cert: string;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
*
|
|
19
|
+
/**
|
|
20
|
+
* TLS server that wraps a MqttServer, see the /examples folder
|
|
21
21
|
*/
|
|
22
22
|
export class TlsServer {
|
|
23
23
|
private mqttServer: MqttServer;
|
|
24
24
|
private server?: Server;
|
|
25
25
|
private serverOptions;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Create a new TLS server
|
|
29
|
+
*/
|
|
27
30
|
constructor(serverOptions: ServerOptions, mqttOptions: MqttServerOptions) {
|
|
28
31
|
this.mqttServer = new MqttServer(mqttOptions);
|
|
29
32
|
this.serverOptions = serverOptions;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Start listening
|
|
37
|
+
*/
|
|
38
|
+
async start(): Promise<void> {
|
|
33
39
|
const tlsOptions = {
|
|
34
40
|
minVersion: "TLSv1.3" as const,
|
|
35
41
|
key: this.serverOptions.key,
|
|
@@ -49,12 +55,19 @@ export class TlsServer {
|
|
|
49
55
|
await isListening;
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
52
|
-
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Stop listening
|
|
61
|
+
*/
|
|
62
|
+
stop(): void {
|
|
53
63
|
this.mqttServer.close();
|
|
54
64
|
this.server?.close();
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The port number the server is listening on
|
|
69
|
+
*/
|
|
70
|
+
get port(): number | undefined {
|
|
58
71
|
const address = this.server?.address();
|
|
59
72
|
if (typeof address === "object" && address !== null) {
|
|
60
73
|
return address?.port;
|
|
@@ -62,7 +75,10 @@ export class TlsServer {
|
|
|
62
75
|
return this.serverOptions?.port;
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The address the server is listening on
|
|
80
|
+
*/
|
|
81
|
+
get address(): string | undefined {
|
|
66
82
|
const addressResult = this.server?.address();
|
|
67
83
|
// deno-coverage-ignore-start
|
|
68
84
|
if (typeof addressResult === "object") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seriousme/opifex",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "MQTT client & server for Deno & NodeJS and Bun",
|
|
5
5
|
"author": "Hans Klunder",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"dist/**/*.d.ts.map"
|
|
44
44
|
],
|
|
45
45
|
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"deno": "./deno/mod.ts",
|
|
48
|
+
"node": "./dist/node/mod.js",
|
|
49
|
+
"default": null
|
|
50
|
+
},
|
|
46
51
|
"./tcpClient": {
|
|
47
52
|
"deno": "./deno/tcpClient.ts",
|
|
48
53
|
"default": "./dist/node/tcpClient.js"
|
|
@@ -4,10 +4,10 @@ import type {
|
|
|
4
4
|
ClientSubscription,
|
|
5
5
|
ExtPublishPacket,
|
|
6
6
|
Handler,
|
|
7
|
-
|
|
7
|
+
Persistence,
|
|
8
8
|
ShareName,
|
|
9
9
|
} from "./persistence.ts";
|
|
10
|
-
import type {
|
|
10
|
+
import type { StorageProvider } from "./storage.ts";
|
|
11
11
|
import { PacketDirection } from "./storage.ts";
|
|
12
12
|
import { assert, getOrInsert, logger, Trie } from "./deps.ts";
|
|
13
13
|
import { MAX_PACKET_ID } from "./persistence.ts";
|
|
@@ -60,14 +60,14 @@ function clonePacket(packet: ExtPublishPacket): ExtPublishPacket {
|
|
|
60
60
|
return newPacket;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export class MqttPersistence implements
|
|
63
|
+
export class MqttPersistence implements Persistence {
|
|
64
64
|
private clientHandlerList = new Map<ClientId, Handler>();
|
|
65
65
|
private trie = new Trie<TrieSub>();
|
|
66
66
|
private packetIdCounters = new Map<ClientId, number>();
|
|
67
|
-
private storage:
|
|
67
|
+
private storage: StorageProvider;
|
|
68
68
|
private sharedGroupCounters = new Map<string, number>();
|
|
69
69
|
|
|
70
|
-
constructor(storage:
|
|
70
|
+
constructor(storage: StorageProvider) {
|
|
71
71
|
this.storage = storage;
|
|
72
72
|
}
|
|
73
73
|
|
package/persistence/deps.ts
CHANGED
|
@@ -4,10 +4,10 @@ export type {
|
|
|
4
4
|
PublishPacket,
|
|
5
5
|
PublishPacketV5,
|
|
6
6
|
QoS,
|
|
7
|
+
RetainHandling,
|
|
7
8
|
Subscription,
|
|
8
9
|
Topic,
|
|
9
10
|
TopicFilter,
|
|
10
|
-
TRetainHandling,
|
|
11
11
|
} from "../mqttPacket/mod.ts";
|
|
12
12
|
export { MQTTLevel, PacketType } from "../mqttPacket/mod.ts";
|
|
13
13
|
export { Trie } from "../trie/trie.ts";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module
|
|
3
|
-
* Volatile in-memory implementation of
|
|
3
|
+
* Volatile in-memory implementation of StorageProvider.
|
|
4
4
|
* Completely decoupled from MQTT protocol logic.
|
|
5
5
|
*/
|
|
6
6
|
import type { ClientId, PacketId, Topic, TopicFilter } from "../deps.ts";
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
ExtPublishPacket,
|
|
11
11
|
ShareName,
|
|
12
12
|
} from "../persistence.ts";
|
|
13
|
-
import type {
|
|
13
|
+
import type { StorageProvider, StoredSubscription } from "../storage.ts";
|
|
14
14
|
import { PacketDirection } from "../storage.ts";
|
|
15
15
|
import { getOrInsert, joinTopicFilter, topicFilterToRegExp } from "../deps.ts";
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ type pendingTableEntry = {
|
|
|
20
20
|
createdAtMs: number;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export class MemoryStorage implements
|
|
23
|
+
export class MemoryStorage implements StorageProvider {
|
|
24
24
|
private seqId = 1;
|
|
25
25
|
private sessionTable = new Map<ClientId, ClientRegistrationResult>();
|
|
26
26
|
|
package/persistence/mod.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared test suite for
|
|
2
|
+
* Shared test suite for Persistence implementations.
|
|
3
3
|
* Ensures behavioral parity between MemoryPersistence and SqlitePersistence.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ import type { QoS } from "./deps.ts";
|
|
|
10
10
|
import type {
|
|
11
11
|
ClientSubscription,
|
|
12
12
|
ExtPublishPacket,
|
|
13
|
-
|
|
13
|
+
Persistence,
|
|
14
14
|
} from "./persistence.ts";
|
|
15
15
|
import type { PublishPacketV5 } from "../mqttPacket/publish.ts";
|
|
16
16
|
|
|
@@ -33,7 +33,7 @@ function createPacket(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async function createReceiver(
|
|
36
|
-
persistence:
|
|
36
|
+
persistence: Persistence,
|
|
37
37
|
clientId: string,
|
|
38
38
|
clean = false,
|
|
39
39
|
): Promise<{ received: ExtPublishPacket[] }> {
|
|
@@ -54,7 +54,7 @@ async function createReceiver(
|
|
|
54
54
|
export type PersistenceFactoryOptions = {
|
|
55
55
|
name: string;
|
|
56
56
|
factory: () => {
|
|
57
|
-
persistence:
|
|
57
|
+
persistence: Persistence;
|
|
58
58
|
cleanup: () => void | Promise<void>;
|
|
59
59
|
};
|
|
60
60
|
};
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
PacketId,
|
|
8
8
|
PublishPacketV5,
|
|
9
9
|
QoS,
|
|
10
|
+
RetainHandling,
|
|
10
11
|
TopicFilter,
|
|
11
|
-
TRetainHandling,
|
|
12
12
|
} from "./deps.ts";
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -29,7 +29,7 @@ export type ClientSubscription = {
|
|
|
29
29
|
qos: QoS;
|
|
30
30
|
noLocal?: boolean;
|
|
31
31
|
retainAsPublished?: boolean;
|
|
32
|
-
retainHandling?:
|
|
32
|
+
retainHandling?: RetainHandling;
|
|
33
33
|
subscriptionIdentifier?: number;
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -49,7 +49,7 @@ export type ClientRegistrationResult = {
|
|
|
49
49
|
/**
|
|
50
50
|
* Interface for persistence implementations to store messages and subscriptions
|
|
51
51
|
*/
|
|
52
|
-
export interface
|
|
52
|
+
export interface Persistence {
|
|
53
53
|
// initialize the persistence
|
|
54
54
|
// e.g. setting up the data store
|
|
55
55
|
initialize(): Promise<void>;
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
ShareName,
|
|
8
8
|
} from "../persistence.ts";
|
|
9
9
|
import { PacketDirection } from "../storage.ts";
|
|
10
|
-
import type {
|
|
10
|
+
import type { StorageProvider, StoredSubscription } from "../storage.ts";
|
|
11
11
|
import { topicFilterToRegExp } from "../deps.ts";
|
|
12
12
|
import {
|
|
13
13
|
deleteClientState,
|
|
@@ -37,7 +37,7 @@ function deserializePacket(
|
|
|
37
37
|
return packet;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export class SqliteStorage implements
|
|
40
|
+
export class SqliteStorage implements StorageProvider {
|
|
41
41
|
private db: sqlite.DatabaseSync;
|
|
42
42
|
|
|
43
43
|
private statements: AllStatements;
|
package/persistence/storage.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const PacketDirection = {
|
|
|
15
15
|
export type PacketDirection =
|
|
16
16
|
typeof PacketDirection[keyof typeof PacketDirection];
|
|
17
17
|
|
|
18
|
-
export interface
|
|
18
|
+
export interface StorageProvider {
|
|
19
19
|
initialize(): Promise<void>;
|
|
20
20
|
close?(): Promise<void>;
|
|
21
21
|
|
package/server/context.ts
CHANGED
|
@@ -11,15 +11,15 @@ import type {
|
|
|
11
11
|
AnyPacket,
|
|
12
12
|
ConnectPacket,
|
|
13
13
|
ExtPublishPacket,
|
|
14
|
-
IPersistence,
|
|
15
14
|
PacketId,
|
|
15
|
+
Persistence,
|
|
16
16
|
ProtocolLevel,
|
|
17
17
|
PublishPacket,
|
|
18
18
|
PubrelPacket,
|
|
19
|
+
ReasonCode,
|
|
19
20
|
ShareName,
|
|
20
21
|
SockConn,
|
|
21
22
|
Topic,
|
|
22
|
-
TReasonCode,
|
|
23
23
|
} from "./deps.ts";
|
|
24
24
|
|
|
25
25
|
import { QueueMode } from "./config.ts";
|
|
@@ -36,7 +36,7 @@ export const utf8Encoder = new TextEncoder();
|
|
|
36
36
|
|
|
37
37
|
/** Possible results from isAuthenticated and processAuth handler */
|
|
38
38
|
export type AuthenticatedResult = {
|
|
39
|
-
reasonCode:
|
|
39
|
+
reasonCode: ReasonCode;
|
|
40
40
|
reasonString?: string;
|
|
41
41
|
authData?: Uint8Array;
|
|
42
42
|
};
|
|
@@ -168,7 +168,7 @@ export class Context {
|
|
|
168
168
|
mqttConn: MqttConn;
|
|
169
169
|
|
|
170
170
|
/** The persistence layer instance used by the server. */
|
|
171
|
-
persistence:
|
|
171
|
+
persistence: Persistence;
|
|
172
172
|
|
|
173
173
|
/** The configured authentication and authorization lifecycle hooks. */
|
|
174
174
|
handlers: Handlers;
|
|
@@ -233,7 +233,7 @@ export class Context {
|
|
|
233
233
|
*/
|
|
234
234
|
constructor(
|
|
235
235
|
configuration: Configuration, // all settings
|
|
236
|
-
persistence:
|
|
236
|
+
persistence: Persistence, // The server persistence layer implementation.
|
|
237
237
|
conn: SockConn, // The underlying socket connection.
|
|
238
238
|
handlers: Handlers, // The validation handlers
|
|
239
239
|
) {
|
package/server/deps.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { MqttConn } from "../mqttConn/mqttConn.ts";
|
|
|
3
3
|
export type {
|
|
4
4
|
ClientSubscription,
|
|
5
5
|
ExtPublishPacket,
|
|
6
|
-
|
|
6
|
+
Persistence,
|
|
7
7
|
ShareName,
|
|
8
8
|
} from "../persistence/persistence.ts";
|
|
9
9
|
export { MemoryPersistence } from "../persistence/memory/memoryPersistence.ts";
|
|
@@ -32,7 +32,6 @@ export type {
|
|
|
32
32
|
SubscriptionV5,
|
|
33
33
|
Topic,
|
|
34
34
|
TopicFilter,
|
|
35
|
-
TReasonCode,
|
|
36
35
|
UnsubackPacket,
|
|
37
36
|
UnsubscribePacket,
|
|
38
37
|
} from "../mqttPacket/mod.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthenticationResult, PacketType, ReasonCode } from "../deps.ts";
|
|
2
|
-
import type { ProtocolLevel
|
|
2
|
+
import type { ProtocolLevel } from "../deps.ts";
|
|
3
3
|
import type { Context } from "../context.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -29,7 +29,7 @@ export function reasonToReturnCode(reasonCode: number): number {
|
|
|
29
29
|
export async function completeConnect(
|
|
30
30
|
ctx: Context,
|
|
31
31
|
protocolLevel: ProtocolLevel,
|
|
32
|
-
reasonCode:
|
|
32
|
+
reasonCode: ReasonCode,
|
|
33
33
|
reasonString: string | undefined,
|
|
34
34
|
) {
|
|
35
35
|
const cfg = ctx.config.context;
|