@kronos-integration/endpoint 9.4.30 → 9.4.33
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/README.md +1 -1
- package/package.json +6 -6
- package/src/multi-connection-endpoint.mjs +10 -10
- package/src/send-endpoint.mjs +20 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/@kronos-integration/endpoint)
|
|
2
2
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
-
[](https://bundlejs.com/?q=@kronos-integration/endpoint)
|
|
4
4
|
[](https://npmjs.org/package/@kronos-integration/endpoint)
|
|
5
5
|
[](https://github.com/Kronos-Integration/endpoint/issues)
|
|
6
6
|
[](https://actions-badge.atrox.dev/Kronos-Integration/endpoint/goto)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/endpoint",
|
|
3
|
-
"version": "9.4.
|
|
3
|
+
"version": "9.4.33",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@kronos-integration/interceptor": "^10.2.
|
|
35
|
+
"@kronos-integration/interceptor": "^10.2.25"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"ava": "^4.3.
|
|
39
|
-
"c8": "^7.
|
|
38
|
+
"ava": "^4.3.1",
|
|
39
|
+
"c8": "^7.12.0",
|
|
40
40
|
"documentation": "^13.2.5",
|
|
41
|
-
"semantic-release": "^19.0.
|
|
41
|
+
"semantic-release": "^19.0.3"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=16.
|
|
44
|
+
"node": ">=16.16.0"
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"type": "git",
|
|
@@ -6,12 +6,12 @@ import { ReceivableEndpoint } from "./receivable-endpoint.mjs";
|
|
|
6
6
|
* Can hold several connections.
|
|
7
7
|
*/
|
|
8
8
|
export class MultiConnectionEndpoint extends ReceivableEndpoint {
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
#connections = new Map();
|
|
11
|
+
|
|
10
12
|
constructor(name, owner, options = {}) {
|
|
11
13
|
super(name, owner, options);
|
|
12
14
|
|
|
13
|
-
this._connections = new Map();
|
|
14
|
-
|
|
15
15
|
if (isEndpoint(options.connected)) {
|
|
16
16
|
this.addConnection(options.connected);
|
|
17
17
|
}
|
|
@@ -23,7 +23,7 @@ export class MultiConnectionEndpoint extends ReceivableEndpoint {
|
|
|
23
23
|
* @return {any} our state for the connection to other
|
|
24
24
|
*/
|
|
25
25
|
getConnectionState(other) {
|
|
26
|
-
return this.
|
|
26
|
+
return this.#connections.get(other);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -32,7 +32,7 @@ export class MultiConnectionEndpoint extends ReceivableEndpoint {
|
|
|
32
32
|
* @param {any} state for the connection to other
|
|
33
33
|
*/
|
|
34
34
|
setConnectionState(other, state) {
|
|
35
|
-
this.
|
|
35
|
+
this.#connections.set(other, state);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
addConnection(other, backpointer) {
|
|
@@ -42,18 +42,18 @@ export class MultiConnectionEndpoint extends ReceivableEndpoint {
|
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (!this.
|
|
45
|
+
if (!this.#connections.get(other)) {
|
|
46
46
|
if (!backpointer) {
|
|
47
47
|
other.addConnection(this, true);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
this.
|
|
50
|
+
this.#connections.set(other, undefined); // dummy
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
removeConnection(other, backpointer) {
|
|
55
55
|
this.closeConnection(other);
|
|
56
|
-
this.
|
|
56
|
+
this.#connections.delete(other);
|
|
57
57
|
|
|
58
58
|
if (!backpointer) {
|
|
59
59
|
other.removeConnection(this, true);
|
|
@@ -66,13 +66,13 @@ export class MultiConnectionEndpoint extends ReceivableEndpoint {
|
|
|
66
66
|
* @return {boolean} true if we are connected with other
|
|
67
67
|
*/
|
|
68
68
|
isConnected(other) {
|
|
69
|
-
return this.
|
|
69
|
+
return this.#connections.has(other);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* All connections
|
|
74
74
|
*/
|
|
75
75
|
*connections() {
|
|
76
|
-
yield* this.
|
|
76
|
+
yield* this.#connections.keys();
|
|
77
77
|
}
|
|
78
78
|
}
|
package/src/send-endpoint.mjs
CHANGED
|
@@ -12,6 +12,10 @@ import { ReceivableEndpoint } from "./receivable-endpoint.mjs";
|
|
|
12
12
|
* @param {Function} [options.didConnect] called after receiver is present
|
|
13
13
|
*/
|
|
14
14
|
export class SendEndpoint extends ReceivableEndpoint {
|
|
15
|
+
|
|
16
|
+
#connection;
|
|
17
|
+
#state;
|
|
18
|
+
|
|
15
19
|
constructor(name, owner, options = {}) {
|
|
16
20
|
super(name, owner, options);
|
|
17
21
|
if (isEndpoint(options.connected)) {
|
|
@@ -28,21 +32,21 @@ export class SendEndpoint extends ReceivableEndpoint {
|
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
get isOpen() {
|
|
31
|
-
return this
|
|
35
|
+
return this.#connection !== undefined;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
getConnectionState(other) {
|
|
35
|
-
return other === this
|
|
39
|
+
return other === this.#connection ? this.#state : undefined;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
setConnectionState(other, state) {
|
|
39
|
-
if (other === this
|
|
40
|
-
this
|
|
43
|
+
if (other === this.#connection) {
|
|
44
|
+
this.#state = state;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
addConnection(other, backpointer) {
|
|
45
|
-
if (this
|
|
49
|
+
if (this.#connection === other) {
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
52
|
|
|
@@ -52,18 +56,18 @@ export class SendEndpoint extends ReceivableEndpoint {
|
|
|
52
56
|
);
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
if (this
|
|
59
|
+
if (this.#connection !== undefined) {
|
|
56
60
|
// do not break standing connection if only setting backpinter
|
|
57
61
|
if (backpointer) {
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
throw new Error(`Already connected to: ${this.
|
|
65
|
+
throw new Error(`Already connected to: ${this.#connection.identifier}`);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
this.removeConnection(this
|
|
68
|
+
this.removeConnection(this.#connection, backpointer);
|
|
65
69
|
|
|
66
|
-
this
|
|
70
|
+
this.#connection = other;
|
|
67
71
|
|
|
68
72
|
if (!backpointer) {
|
|
69
73
|
other.addConnection(this, true);
|
|
@@ -76,22 +80,22 @@ export class SendEndpoint extends ReceivableEndpoint {
|
|
|
76
80
|
if (!backpointer && other !== undefined) {
|
|
77
81
|
other.removeConnection(this, true);
|
|
78
82
|
}
|
|
79
|
-
this
|
|
83
|
+
this.#connection = undefined;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
*connections() {
|
|
83
|
-
if (this
|
|
84
|
-
yield this
|
|
87
|
+
if (this.#connection) {
|
|
88
|
+
yield this.#connection;
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
async send(...args) {
|
|
89
|
-
if (this
|
|
93
|
+
if (this.#connection === undefined) {
|
|
90
94
|
throw new Error(`${this.identifier} is not connected`);
|
|
91
95
|
}
|
|
92
|
-
if (!this.
|
|
96
|
+
if (!this.#connection.isOpen) {
|
|
93
97
|
throw new Error(
|
|
94
|
-
`${this.identifier}: ${this.
|
|
98
|
+
`${this.identifier}: ${this.#connection.identifier} is not open`
|
|
95
99
|
);
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -100,7 +104,7 @@ export class SendEndpoint extends ReceivableEndpoint {
|
|
|
100
104
|
|
|
101
105
|
const next = async (...args) =>
|
|
102
106
|
c >= interceptors.length
|
|
103
|
-
? this.
|
|
107
|
+
? this.#connection.receive(...args)
|
|
104
108
|
: interceptors[c++].receive(this, next, ...args);
|
|
105
109
|
|
|
106
110
|
return next(...args);
|