@toa.io/extensions.realtime 1.0.0-alpha.19 → 1.0.0-alpha.194
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/components/streams/manifest.toa.yaml +0 -1
- package/components/streams/operations/create.d.ts +4 -2
- package/components/streams/operations/create.js +15 -9
- package/components/streams/operations/create.js.map +1 -1
- package/components/streams/operations/lib/{stream.d.ts → Stream.d.ts} +5 -1
- package/components/streams/operations/lib/Stream.js +54 -0
- package/components/streams/operations/lib/Stream.js.map +1 -0
- package/components/streams/operations/{types.d.ts → lib/types.d.ts} +4 -1
- package/components/streams/operations/lib/types.js.map +1 -0
- package/components/streams/operations/push.d.ts +1 -1
- package/components/streams/operations/tsconfig.tsbuildinfo +1 -1
- package/components/streams/source/create.ts +20 -9
- package/components/streams/source/lib/Stream.ts +69 -0
- package/components/streams/source/{types.ts → lib/types.ts} +4 -1
- package/components/streams/source/push.ts +1 -1
- package/features/static.feature +34 -0
- package/features/steps/Realtime.ts +1 -1
- package/features/steps/components/messages/manifest.toa.yaml +2 -0
- package/package.json +6 -2
- package/readme.md +32 -6
- package/source/Composition.ts +1 -7
- package/source/Realtime.ts +4 -2
- package/source/Receiver.ts +49 -0
- package/source/Routes.ts +6 -26
- package/source/extension.ts +69 -0
- package/source/index.ts +1 -0
- package/transpiled/Composition.d.ts +1 -1
- package/transpiled/Composition.js +2 -5
- package/transpiled/Composition.js.map +1 -1
- package/transpiled/Realtime.js +5 -3
- package/transpiled/Realtime.js.map +1 -1
- package/transpiled/Receiver.d.ts +11 -0
- package/transpiled/Receiver.js +41 -0
- package/transpiled/Receiver.js.map +1 -0
- package/transpiled/Routes.d.ts +0 -1
- package/transpiled/Routes.js +5 -17
- package/transpiled/Routes.js.map +1 -1
- package/transpiled/extension.d.ts +8 -0
- package/transpiled/extension.js +46 -0
- package/transpiled/extension.js.map +1 -0
- package/transpiled/index.d.ts +1 -0
- package/transpiled/index.js +15 -0
- package/transpiled/index.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
- package/components/streams/operations/lib/stream.js +0 -31
- package/components/streams/operations/lib/stream.js.map +0 -1
- package/components/streams/operations/types.js.map +0 -1
- package/components/streams/source/lib/stream.ts +0 -37
- package/stage/streams.test.ts +0 -128
- /package/components/streams/operations/{types.js → lib/types.js} +0 -0
package/stage/streams.test.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path'
|
|
2
|
-
import { type Readable } from 'node:stream'
|
|
3
|
-
import { generate } from 'randomstring'
|
|
4
|
-
import * as stage from '@toa.io/userland/stage'
|
|
5
|
-
import { type Component } from '@toa.io/core'
|
|
6
|
-
import { newid, timeout } from '@toa.io/generic'
|
|
7
|
-
|
|
8
|
-
let component: Component
|
|
9
|
-
let stream: Readable
|
|
10
|
-
let events: Record<string, any[]> = {}
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
await run()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
afterEach(async () => {
|
|
17
|
-
stream?.destroy()
|
|
18
|
-
await stop()
|
|
19
|
-
events = {}
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should route events', async () => {
|
|
23
|
-
const event = generate()
|
|
24
|
-
const data = generate()
|
|
25
|
-
const key1 = newid()
|
|
26
|
-
const key2 = newid()
|
|
27
|
-
|
|
28
|
-
await create(key1)
|
|
29
|
-
await create(key2)
|
|
30
|
-
await push(key1, event, data)
|
|
31
|
-
await push(key2, event, data)
|
|
32
|
-
|
|
33
|
-
expect(events[key1]).toEqual([{ event, data }])
|
|
34
|
-
expect(events[key2]).toEqual([{ event, data }])
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('should create fresh stream', async () => {
|
|
38
|
-
const data = { foo: generate() }
|
|
39
|
-
const key = newid()
|
|
40
|
-
|
|
41
|
-
await create(key)
|
|
42
|
-
await push(key, 'first', data)
|
|
43
|
-
|
|
44
|
-
expect(events[key]).toEqual([{ event: 'first', data }])
|
|
45
|
-
|
|
46
|
-
await create(key)
|
|
47
|
-
await timeout(0)
|
|
48
|
-
|
|
49
|
-
expect(events[key]).toEqual([])
|
|
50
|
-
|
|
51
|
-
await push(key, 'second', data)
|
|
52
|
-
|
|
53
|
-
expect(events[key]).toEqual([{ event: 'second', data }])
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should ignore pushes to non-created streams', async () => {
|
|
57
|
-
const data = { foo: generate() }
|
|
58
|
-
const key = newid()
|
|
59
|
-
|
|
60
|
-
await push(key, 'first', data)
|
|
61
|
-
await create(key)
|
|
62
|
-
|
|
63
|
-
expect(events[key]).toEqual([])
|
|
64
|
-
|
|
65
|
-
await push(key, 'second', data)
|
|
66
|
-
|
|
67
|
-
expect(events[key]).toEqual([{ event: 'second', data }])
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should not destroy source stream if one of the forks is destroyed', async () => {
|
|
71
|
-
const data = generate()
|
|
72
|
-
const key = newid()
|
|
73
|
-
|
|
74
|
-
await create(key)
|
|
75
|
-
await push(key, 'first', data)
|
|
76
|
-
|
|
77
|
-
const firstStream = stream
|
|
78
|
-
const firstStreamEvents = events[key]
|
|
79
|
-
|
|
80
|
-
await create(key)
|
|
81
|
-
await push(key, 'second', data)
|
|
82
|
-
|
|
83
|
-
expect(firstStreamEvents).toEqual([{ event: 'first', data }, { event: 'second', data }])
|
|
84
|
-
expect(stream === firstStream).toBe(false)
|
|
85
|
-
|
|
86
|
-
stream.destroy()
|
|
87
|
-
|
|
88
|
-
await push(key, 'third', data)
|
|
89
|
-
|
|
90
|
-
expect(firstStreamEvents).toEqual([
|
|
91
|
-
{ event: 'first', data },
|
|
92
|
-
{ event: 'second', data },
|
|
93
|
-
{ event: 'third', data }
|
|
94
|
-
])
|
|
95
|
-
|
|
96
|
-
firstStream.destroy()
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
/// region component
|
|
100
|
-
|
|
101
|
-
async function run (name: string = 'streams'): Promise<void> {
|
|
102
|
-
const path = resolve(__dirname, `../components/${name}`)
|
|
103
|
-
|
|
104
|
-
component = await stage.component(path)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function create (key: string): Promise<void> {
|
|
108
|
-
const chunks: any[] = []
|
|
109
|
-
|
|
110
|
-
events[key] = chunks
|
|
111
|
-
|
|
112
|
-
stream = await component.invoke('create', { input: { key } })
|
|
113
|
-
stream.on('data', (chunk) => chunks.push(chunk))
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function stop (): Promise<void> {
|
|
117
|
-
await component?.disconnect()
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function push (key: string, event: string, data: any): Promise<void> {
|
|
121
|
-
const reply = await component.invoke<any>('push', { input: { key, event, data } })
|
|
122
|
-
|
|
123
|
-
expect(reply?.exception).toBeUndefined()
|
|
124
|
-
|
|
125
|
-
await timeout(0) // wait for stream internals
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/// endregion
|
|
File without changes
|