@toa.io/extensions.realtime 0.0.0 → 0.22.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.
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import { type Readable } from 'node:stream'
|
|
2
|
+
import { type Operation } from '@toa.io/types'
|
|
2
3
|
import { type Context } from './types'
|
|
3
|
-
import {
|
|
4
|
+
import { Stream } from './lib/stream'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
|
|
6
|
+
export class Effect implements Operation {
|
|
7
|
+
private readonly streams = new Map<string, Stream>()
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
public mount (context: Context): void {
|
|
10
|
+
context.state.streams = this.streams
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
public async execute (input: Input, context: Context): Promise<Readable> {
|
|
14
|
+
const key = input.key
|
|
15
|
+
|
|
16
|
+
if (!this.streams.has(key))
|
|
17
|
+
this.createStream(key)
|
|
18
|
+
|
|
19
|
+
return (this.streams.get(key) as Stream).fork()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private createStream (key: string): void {
|
|
23
|
+
const stream = new Stream()
|
|
24
|
+
|
|
25
|
+
this.streams.set(key, stream)
|
|
26
|
+
|
|
27
|
+
stream.once('close', () => this.streams.delete(key))
|
|
28
|
+
}
|
|
12
29
|
}
|
|
13
30
|
|
|
14
31
|
interface Input {
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { PassThrough, Readable } from 'node:stream'
|
|
2
2
|
|
|
3
|
-
export function addStream (key: string, map: Record<string, Stream>): void {
|
|
4
|
-
const stream = new Stream()
|
|
5
|
-
|
|
6
|
-
map[key] = stream
|
|
7
|
-
|
|
8
|
-
stream.once('close', () => delete map[key])
|
|
9
|
-
}
|
|
10
|
-
|
|
11
3
|
export class Stream extends Readable {
|
|
12
4
|
private forks: number = 0
|
|
13
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.realtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Toa Realtime",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"testEnvironment": "node"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"transpile": "npx tsc && npx tsc -p ./components/streams",
|
|
27
|
+
"transpile": "rm -rf transpiled && npx tsc && rm -rf ./components/streams/operations && npx tsc -p ./components/streams",
|
|
28
28
|
"features": "npx cucumber-js"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "c463348c8eb54a43f7755ec8aeba9acafb56d53b"
|
|
31
31
|
}
|