@superhero/eventflow-hub 4.0.3 → 4.0.5
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 +7 -7
- package/index.js +19 -9
- package/index.test.js +9 -16
- package/manager/spokes.js +1 -4
- package/manager/spokes.test.js +3 -4
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -58,20 +58,20 @@ tests 14
|
|
|
58
58
|
suites 5
|
|
59
59
|
pass 14
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
file | line % | branch % | funcs % | uncovered
|
|
63
|
-
|
|
61
|
+
-------------------------------------------------------------------------------------------------------------
|
|
62
|
+
file | line % | branch % | funcs % | uncovered line
|
|
63
|
+
-------------------------------------------------------------------------------------------------------------
|
|
64
64
|
config.js | 100.00 | 100.00 | 100.00 |
|
|
65
|
-
index.js | 73.36 | 74.42 | 74.07 |
|
|
65
|
+
index.js | 73.36 | 74.42 | 74.07 | 44-47 120-124 144-146 150-154 157-161 183-185 254-2…
|
|
66
66
|
index.test.js | 100.00 | 100.00 | 100.00 |
|
|
67
67
|
manager | | | |
|
|
68
68
|
spokes.js | 100.00 | 100.00 | 100.00 |
|
|
69
69
|
spokes.test.js | 100.00 | 100.00 | 100.00 |
|
|
70
70
|
subscribers.js | 78.21 | 100.00 | 83.33 | 61-77
|
|
71
71
|
subscribers.test.js | 100.00 | 100.00 | 100.00 |
|
|
72
|
-
|
|
73
|
-
all files |
|
|
74
|
-
|
|
72
|
+
-------------------------------------------------------------------------------------------------------------
|
|
73
|
+
all files | 82.97 | 86.32 | 87.50 |
|
|
74
|
+
-------------------------------------------------------------------------------------------------------------
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
## License
|
package/index.js
CHANGED
|
@@ -11,8 +11,8 @@ import { setInterval as asyncInterval } from 'node:timers/promises'
|
|
|
11
11
|
export function locate(locator)
|
|
12
12
|
{
|
|
13
13
|
const
|
|
14
|
-
config = locator
|
|
15
|
-
db = locator('@superhero/eventflow-db'),
|
|
14
|
+
config = locator.config.find('eventflow/hub', {}),
|
|
15
|
+
db = locator.locate('@superhero/eventflow-db'),
|
|
16
16
|
hub = new Hub(config, db)
|
|
17
17
|
|
|
18
18
|
return hub
|
|
@@ -24,7 +24,11 @@ export function locate(locator)
|
|
|
24
24
|
export default class Hub
|
|
25
25
|
{
|
|
26
26
|
#hubID
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
abortion = new AbortController()
|
|
29
|
+
channel = new Channel()
|
|
30
|
+
spokes = new SpokesManager()
|
|
31
|
+
subscribers = new SubscribersManager()
|
|
28
32
|
|
|
29
33
|
get hubID()
|
|
30
34
|
{
|
|
@@ -45,11 +49,8 @@ export default class Hub
|
|
|
45
49
|
this.#hubID = (new IdNameGenerator().generateId() + '.' + config.NAME).toUpperCase()
|
|
46
50
|
this.config = config
|
|
47
51
|
this.db = db
|
|
48
|
-
this.abortion = new AbortController()
|
|
49
52
|
this.log = new Log({ label: `[${config.NAME}]` })
|
|
50
53
|
this.certificates = new CertificatesManager(config.NAME, this.#hubID, config.certificates, db, this.log)
|
|
51
|
-
this.spokes = new SpokesManager()
|
|
52
|
-
this.subscribers = new SubscribersManager()
|
|
53
54
|
|
|
54
55
|
this.channel.on('record', this.#onRecord.bind(this))
|
|
55
56
|
}
|
|
@@ -63,11 +64,20 @@ export default class Hub
|
|
|
63
64
|
|
|
64
65
|
async destroy()
|
|
65
66
|
{
|
|
66
|
-
|
|
67
|
+
const reason = new Error('hub is destroyed')
|
|
68
|
+
reason.code = 'E_EVENTFLOW_HUB_DESTROYED'
|
|
69
|
+
|
|
70
|
+
this.abortion.abort(reason)
|
|
67
71
|
this.server?.close()
|
|
72
|
+
|
|
73
|
+
for(const socket of this.spokes.all)
|
|
74
|
+
{
|
|
75
|
+
socket.end()
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
this.spokes.destroy()
|
|
69
79
|
this.subscribers.destroy()
|
|
70
|
-
this.log.warn`
|
|
80
|
+
this.log.warn`destroyed`
|
|
71
81
|
await this.db.updateHubToQuit(this.#hubID)
|
|
72
82
|
setTimeout(() => this.db.close(), 500)
|
|
73
83
|
}
|
|
@@ -269,7 +279,7 @@ export default class Hub
|
|
|
269
279
|
|
|
270
280
|
async #attemptToConsumeAndBroadcastPublishedMessage(domain, id, name, pid)
|
|
271
281
|
{
|
|
272
|
-
const consumed = await this.db.updateEventPublishedToConsumedByHub(
|
|
282
|
+
const consumed = await this.db.updateEventPublishedToConsumedByHub(id, this.#hubID)
|
|
273
283
|
|
|
274
284
|
if(consumed)
|
|
275
285
|
{
|
package/index.test.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import assert from 'node:assert'
|
|
2
2
|
import util from 'node:util'
|
|
3
|
-
import Config from '@superhero/config'
|
|
4
3
|
import Locator from '@superhero/locator'
|
|
5
4
|
import Channel from '@superhero/tcp-record-channel'
|
|
6
5
|
import { suite, test, beforeEach, afterEach } from 'node:test'
|
|
@@ -16,13 +15,11 @@ suite('@superhero/eventflow-hub', () =>
|
|
|
16
15
|
if(beforeEach.skip) return
|
|
17
16
|
locator = new Locator()
|
|
18
17
|
locator.log.config.mute = true
|
|
19
|
-
|
|
20
|
-
await config.add('
|
|
21
|
-
|
|
22
|
-
config.assign({ eventflow: { hub: { certificates: { CERT_PASS_ENCRYPTION_KEY: 'encryptionKey123' }}}})
|
|
23
|
-
locator.set('@superhero/config', config)
|
|
18
|
+
await locator.config.add('@superhero/eventflow-db')
|
|
19
|
+
await locator.config.add('./config.js')
|
|
20
|
+
locator.config.assign({ eventflow: { hub: { certificates: { CERT_PASS_ENCRYPTION_KEY: 'encryptionKey123' }}}})
|
|
24
21
|
await locator.eagerload('@superhero/eventflow-db')
|
|
25
|
-
await locator.eagerload(config.find('locator'))
|
|
22
|
+
await locator.eagerload(locator.config.find('locator'))
|
|
26
23
|
hub = locator('@superhero/eventflow-hub')
|
|
27
24
|
hub.log.config.mute = true
|
|
28
25
|
await hub.bootstrap()
|
|
@@ -78,14 +75,11 @@ suite('@superhero/eventflow-hub', () =>
|
|
|
78
75
|
&& '50002' === port
|
|
79
76
|
&& hub2.destroy().then(accept))
|
|
80
77
|
|
|
81
|
-
const
|
|
82
|
-
locator2 = new Locator(),
|
|
83
|
-
config2 = new Config()
|
|
84
|
-
|
|
78
|
+
const locator2 = new Locator()
|
|
85
79
|
locator2.log.config.mute = true
|
|
86
|
-
await
|
|
87
|
-
await
|
|
88
|
-
|
|
80
|
+
await locator2.config.add('@superhero/eventflow-db')
|
|
81
|
+
await locator2.config.add('./config.js')
|
|
82
|
+
locator2.config.assign(
|
|
89
83
|
{ eventflow:
|
|
90
84
|
{ hub:
|
|
91
85
|
{ INTERNAL_PORT:50002,
|
|
@@ -93,9 +87,8 @@ suite('@superhero/eventflow-hub', () =>
|
|
|
93
87
|
certificates:
|
|
94
88
|
{ CERT_PASS_ENCRYPTION_KEY: 'encryptionKey123' }}}})
|
|
95
89
|
|
|
96
|
-
locator2.set('@superhero/config', config2)
|
|
97
90
|
await locator2.eagerload('@superhero/eventflow-db')
|
|
98
|
-
await locator2.eagerload(
|
|
91
|
+
await locator2.eagerload(locator2.config.find('locator'))
|
|
99
92
|
const hub2 = locator2('@superhero/eventflow-hub')
|
|
100
93
|
hub2.log.config.mute = true
|
|
101
94
|
await hub2.bootstrap()
|
package/manager/spokes.js
CHANGED
package/manager/spokes.test.js
CHANGED
|
@@ -34,15 +34,14 @@ suite('@superhero/eventflow-hub/manager/spokes', () =>
|
|
|
34
34
|
test('Destroy all sockets', async () =>
|
|
35
35
|
{
|
|
36
36
|
const manager = new SpokesManager()
|
|
37
|
-
const socket1 = { id: 'socket1'
|
|
38
|
-
const socket2 = { id: 'socket2'
|
|
37
|
+
const socket1 = { id: 'socket1' }
|
|
38
|
+
const socket2 = { id: 'socket2' }
|
|
39
39
|
|
|
40
40
|
manager.add(socket1)
|
|
41
41
|
manager.add(socket2)
|
|
42
42
|
manager.destroy()
|
|
43
43
|
|
|
44
|
-
assert.strictEqual(
|
|
45
|
-
assert.strictEqual(socket2.destroyed, true)
|
|
44
|
+
assert.strictEqual(manager.all.length, 0)
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
test('Handle deleting non-existent socket gracefully', async () =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/eventflow-hub",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Eventflow hub is the central server component in the eventflow ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eventflow",
|
|
@@ -14,17 +14,15 @@
|
|
|
14
14
|
"./manager/*": "./manager/*.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@superhero/eventflow-db": "^4.1.2",
|
|
18
17
|
"@superhero/id-name-generator": "^4.0.0",
|
|
19
18
|
"@superhero/log": "^4.0.0",
|
|
20
|
-
"@superhero/eventflow-certificates": "^4.0.
|
|
19
|
+
"@superhero/eventflow-certificates": "^4.0.4",
|
|
21
20
|
"@superhero/openssl": "^4.0.2",
|
|
22
21
|
"@superhero/tcp-record-channel": "^4.2.1",
|
|
23
22
|
"@superhero/deep": "^4.2.0"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@superhero/
|
|
27
|
-
"@superhero/locator": "^4.2.1"
|
|
25
|
+
"@superhero/locator": "^4.2.2"
|
|
28
26
|
},
|
|
29
27
|
"scripts": {
|
|
30
28
|
"test-build": "npm explore @superhero/eventflow-db -- npm run test-build",
|