@superhero/eventflow-spoke 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/index.js +49 -15
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -284,27 +284,56 @@ export default class Spoke
|
|
|
284
284
|
|
|
285
285
|
return new Promise(async (accept, reject) =>
|
|
286
286
|
{
|
|
287
|
-
const
|
|
287
|
+
const timeoutId = setTimeout(() =>
|
|
288
288
|
{
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
289
|
+
unsubscribe().catch(reject).then(() =>
|
|
290
|
+
{
|
|
291
|
+
const error = new Error(`wait timed out (${timeout}) for ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
292
|
+
error.code = 'E_EVENTFLOW_WAIT_TIMEOUT'
|
|
293
|
+
reject(error)
|
|
294
|
+
})
|
|
292
295
|
}, timeout)
|
|
293
296
|
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
if(event.pid === pid)
|
|
297
|
+
const
|
|
298
|
+
unsubscribe = async () =>
|
|
297
299
|
{
|
|
298
|
-
|
|
299
|
-
.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
300
|
+
const
|
|
301
|
+
unsubscribers = eventNames.map((name) => this.unsubscribe(domain, name, subscriber)),
|
|
302
|
+
results = await Promise.allSettled(unsubscribers),
|
|
303
|
+
rejections = results.filter((result) => 'rejected' === result.status)
|
|
304
|
+
|
|
305
|
+
if(rejections.length)
|
|
306
|
+
{
|
|
307
|
+
const error = new Error(`unsubscribe failed: ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
308
|
+
error.code = 'E_EVENTFLOW_WAIT_UNSUBSCRIBE_FAILED'
|
|
309
|
+
error.cause = rejections.map((result) => result.reason)
|
|
310
|
+
throw error
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
subscriber = async (event) =>
|
|
314
|
+
{
|
|
315
|
+
if(event.pid === pid)
|
|
316
|
+
{
|
|
317
|
+
clearTimeout(timeoutId)
|
|
318
|
+
await unsubscribe().catch(reject)
|
|
319
|
+
accept(event)
|
|
320
|
+
}
|
|
304
321
|
}
|
|
305
|
-
}
|
|
306
322
|
|
|
307
|
-
|
|
323
|
+
const
|
|
324
|
+
subscribers = eventNames.map((name) => this.subscribe(domain, name, subscriber)),
|
|
325
|
+
results = await Promise.allSettled(subscribers),
|
|
326
|
+
rejections = results.filter((result) => 'rejected' === result.status)
|
|
327
|
+
|
|
328
|
+
if(rejections.length)
|
|
329
|
+
{
|
|
330
|
+
clearTimeout(timeoutId)
|
|
331
|
+
await unsubscribe().catch(reject)
|
|
332
|
+
const error = new Error(`subscribe failed: ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
333
|
+
error.code = 'E_EVENTFLOW_WAIT_SUBSCRIBE_FAILED'
|
|
334
|
+
error.cause = rejections.map((result) => result.reason)
|
|
335
|
+
reject(error)
|
|
336
|
+
}
|
|
308
337
|
})
|
|
309
338
|
}
|
|
310
339
|
|
|
@@ -377,6 +406,11 @@ export default class Spoke
|
|
|
377
406
|
return await this.db.readEventsByDomainAndPid(domain, pid)
|
|
378
407
|
}
|
|
379
408
|
|
|
409
|
+
async readEventlogByTimestamp(domain, pid, timestampMin, timestampMax)
|
|
410
|
+
{
|
|
411
|
+
return await this.db.readEventsByDomainAndPidBetweenTimestamps(domain, pid, timestampMin, timestampMax)
|
|
412
|
+
}
|
|
413
|
+
|
|
380
414
|
async readEventlogFilteredByNames(domain, pid, names)
|
|
381
415
|
{
|
|
382
416
|
return await this.db.readEventsByDomainAndPidAndNames(domain, pid, names)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/eventflow-spoke",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Eventflow spoke is the client component in the eventflow ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eventflow",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@superhero/deep": "^4.2.0",
|
|
19
19
|
"@superhero/eventflow-certificates": "^4.0.5",
|
|
20
|
-
"@superhero/eventflow-db": "^4.2.
|
|
20
|
+
"@superhero/eventflow-db": "^4.2.3",
|
|
21
21
|
"@superhero/id-name-generator": "^4.0.0",
|
|
22
22
|
"@superhero/log": "^4.0.1",
|
|
23
23
|
"@superhero/tcp-record-channel": "^4.2.1"
|