@toa.io/extensions.realtime 1.0.0-alpha.213 → 1.0.0-alpha.214
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.
|
@@ -10,7 +10,7 @@ export class Effect implements Operation {
|
|
|
10
10
|
|
|
11
11
|
public mount (context: Context): void {
|
|
12
12
|
context.state.streams = this.streams
|
|
13
|
-
context.state.stash = new Stash(context.stash, context.configuration)
|
|
13
|
+
context.state.stash = new Stash(context.stash, context.configuration, context.logs)
|
|
14
14
|
|
|
15
15
|
this.logs = context.logs
|
|
16
16
|
this.stash = context.state.stash
|
|
@@ -45,21 +45,27 @@ export class Effect implements Operation {
|
|
|
45
45
|
})
|
|
46
46
|
else
|
|
47
47
|
void this.stash.pop(key, input.token).then((result) => {
|
|
48
|
-
if (result
|
|
48
|
+
if (result === null) return
|
|
49
|
+
|
|
50
|
+
if ('code' in result && result.code === 'NO_RESULTS') return
|
|
51
|
+
|
|
52
|
+
if (result instanceof Error) {
|
|
49
53
|
this.logs.error('Failed to pop from stash', { key, error: result })
|
|
50
|
-
else if (result !== null) {
|
|
51
|
-
const stream = this.streams.get(key)
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const stream = this.streams.get(key)
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
if (stream === undefined)
|
|
61
|
+
return
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
stream.push({ event: event.event, data: event.data })
|
|
63
|
+
const [token, events] = result
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
for (const event of events as Event[])
|
|
66
|
+
stream.push({ event: event.event, data: event.data })
|
|
67
|
+
|
|
68
|
+
stream.push({ event: 'token', data: token })
|
|
63
69
|
})
|
|
64
70
|
|
|
65
71
|
return this.streams.get(key)!
|
|
@@ -3,10 +3,12 @@ import type { Redis } from 'ioredis'
|
|
|
3
3
|
export class Stash {
|
|
4
4
|
private readonly stash: Redis
|
|
5
5
|
private readonly configuration: Configuration
|
|
6
|
+
private readonly logs: any
|
|
6
7
|
|
|
7
|
-
public constructor (stash: any, configuration: Configuration) {
|
|
8
|
+
public constructor (stash: any, configuration: Configuration, logs: any) {
|
|
8
9
|
this.stash = stash
|
|
9
10
|
this.configuration = configuration
|
|
11
|
+
this.logs = logs
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
public async connect (key: string): Promise<string | Error> {
|
|
@@ -43,7 +45,12 @@ export class Stash {
|
|
|
43
45
|
|
|
44
46
|
lastStamp = item[0]
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
const data = json === undefined ? undefined : JSON.parse(json)
|
|
49
|
+
|
|
50
|
+
if (data === undefined)
|
|
51
|
+
this.logs.debug('Undefined event payload', { key, event })
|
|
52
|
+
|
|
53
|
+
events.push({ event, data })
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
if (lastStamp === null)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.realtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.214",
|
|
4
4
|
"description": "Toa Realtime",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"transpile": "npx tsc && npx tsc -p ./components/streams",
|
|
29
29
|
"features": "npx cucumber-js"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "fd87bad02c3eb899b2e734b92ac8e16ea54767f4"
|
|
32
32
|
}
|