@toa.io/userland 1.0.0-alpha.29 → 1.0.0-alpha.291
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/CHANGELOG.md +32 -0
- package/example/components/echo/manifest.toa.yaml +15 -5
- package/example/components/echo/operations/get.js +1 -5
- package/example/components/echo/operations/resolve.js +1 -5
- package/example/components/echo/operations/signal.js +3 -7
- package/example/components/math.calculations/manifest.toa.yaml +19 -6
- package/example/components/math.calculations/operations/add.js +1 -5
- package/example/components/math.calculations/operations/increment.js +1 -5
- package/example/components/math.proxy/manifest.toa.yaml +8 -3
- package/example/components/math.proxy/operations/add.js +1 -5
- package/example/components/tea.pots/manifest.toa.yaml +37 -9
- package/example/components/tea.pots/operations/same.js +1 -5
- package/example/components/tea.pots/receivers/store.orders.created.js +1 -5
- package/example/components/web/manifest.toa.yaml +2 -4
- package/example/components/web/operations/get.js +3 -8
- package/example/context.toa.yaml +2 -7
- package/example/stage/call.test.js +17 -10
- package/example/stage/events.test.js +63 -16
- package/example/stage/invoke.test.js +12 -9
- package/package.json +18 -12
- package/stage/package.json +1 -0
- package/stage/src/component.js +3 -12
- package/stage/src/composition.js +3 -11
- package/stage/src/index.js +15 -17
- package/stage/src/manifest.js +2 -6
- package/stage/src/remote.js +11 -8
- package/stage/src/service.js +11 -10
- package/stage/src/shutdown.js +2 -8
- package/stage/src/state.js +1 -4
- package/stage/test/boot.mock.js +9 -11
- package/stage/test/component.test.js +20 -10
- package/stage/test/composition.test.js +11 -20
- package/stage/test/manifest.test.js +15 -8
- package/stage/test/remote.test.js +14 -12
- package/stage/test/shutdown.test.js +26 -22
- package/stage/test/state.mock.js +5 -6
- package/stage/test/state.test.js +13 -12
- package/stage/types/index.d.ts +11 -10
- package/stage/types/state.d.ts +2 -4
- package/stage/src/binding/binding.js +0 -50
- package/stage/src/binding/consumer.js +0 -32
- package/stage/src/binding/emitter.js +0 -27
- package/stage/src/binding/factory.js +0 -49
- package/stage/src/binding/index.js +0 -10
- package/stage/src/binding/label.js +0 -12
- package/stage/src/binding/producer.js +0 -43
- package/stage/src/binding/receiver.js +0 -34
- package/stage/test/binding/binding.test.js +0 -15
- package/stage/test/binding/consumer.test.js +0 -52
- package/stage/test/binding/emitter.test.js +0 -78
- package/stage/test/binding/producer.fixtures.js +0 -10
- package/stage/test/binding/producer.test.js +0 -49
- package/stage/test/binding/receiver.fixtures.js +0 -7
- package/stage/test/binding/receiver.test.js +0 -54
- package/stage/test/binding.mock.js +0 -8
- package/stage/types/binding.d.ts +0 -20
package/stage/src/manifest.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const boot = require('@toa.io/boot')
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @type {toa.stage.Manifest}
|
|
7
5
|
*/
|
|
8
|
-
const manifest = async (path) => {
|
|
6
|
+
export const manifest = async (path) => {
|
|
9
7
|
return boot.manifest(path)
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
exports.manifest = manifest
|
package/stage/src/remote.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
2
|
+
import { Locator } from '@toa.io/core'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const { Locator } = require('@toa.io/core')
|
|
5
|
-
|
|
6
|
-
const { state } = require('./state')
|
|
4
|
+
import { state } from './state.js'
|
|
7
5
|
|
|
8
6
|
/** @type {toa.stage.Remote} */
|
|
9
|
-
const remote = async (id) => {
|
|
7
|
+
export const remote = async (id) => {
|
|
10
8
|
const segments = id.split('.')
|
|
11
9
|
|
|
12
10
|
if (segments.length === 1) segments.unshift('default')
|
|
13
11
|
|
|
14
12
|
const [namespace, name] = segments
|
|
15
13
|
const locator = new Locator(name, namespace)
|
|
16
|
-
const remote = await boot.remote(locator)
|
|
14
|
+
const remote = await boot.remote(locator, SOURCE)
|
|
17
15
|
|
|
18
16
|
await remote.connect()
|
|
19
17
|
|
|
@@ -22,4 +20,9 @@ const remote = async (id) => {
|
|
|
22
20
|
return remote
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A feature suite calls components the way a service does, so it says so: without this
|
|
25
|
+
* every call it makes is attributed to an unidentified origin, and a test run leaves
|
|
26
|
+
* `unknown` on the application's map.
|
|
27
|
+
*/
|
|
28
|
+
const SOURCE = { service: 'features' }
|
package/stage/src/service.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import * as boot from '@toa.io/boot'
|
|
4
|
+
import { state } from './state.js'
|
|
5
|
+
import { shortcuts } from '@toa.io/norm'
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const { shortcuts } = require('@toa.io/norm')
|
|
7
|
+
// a shortcut resolves to a package name, which is not a path
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
6
9
|
|
|
7
|
-
const service = async (ref) => {
|
|
10
|
+
export const service = async (ref) => {
|
|
8
11
|
const path = shortcuts.resolve(ref)
|
|
9
|
-
const { Factory } = require(path)
|
|
10
|
-
const factory = new Factory(boot)
|
|
11
|
-
const service = factory.service()
|
|
12
|
+
const { Factory } = await import(pathToFileURL(require.resolve(path)).href)
|
|
13
|
+
const factory = new Factory(boot.host())
|
|
14
|
+
const service = await factory.service()
|
|
12
15
|
|
|
13
16
|
await service.connect()
|
|
14
17
|
|
|
@@ -16,5 +19,3 @@ const service = async (ref) => {
|
|
|
16
19
|
|
|
17
20
|
return service
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
exports.service = service
|
package/stage/src/shutdown.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { state } = require('./state')
|
|
4
|
-
const { binding } = require('./binding')
|
|
1
|
+
import { state } from './state.js'
|
|
5
2
|
|
|
6
3
|
/** @type {toa.stage.Shutdown} */
|
|
7
|
-
const shutdown = async () => {
|
|
4
|
+
export const shutdown = async () => {
|
|
8
5
|
const components = state.components.map((component) => component.disconnect())
|
|
9
6
|
const compositions = state.compositions.map((composition) => composition.disconnect())
|
|
10
7
|
const services = state.services.map((service) => service.disconnect())
|
|
@@ -14,7 +11,4 @@ const shutdown = async () => {
|
|
|
14
11
|
await Promise.all(disconnections)
|
|
15
12
|
|
|
16
13
|
state.reset()
|
|
17
|
-
binding.reset()
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
exports.shutdown = shutdown
|
package/stage/src/state.js
CHANGED
package/stage/test/boot.mock.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { generate } from 'randomstring'
|
|
4
4
|
|
|
5
5
|
const connector = () => ({
|
|
6
|
-
connect:
|
|
7
|
-
disconnect:
|
|
8
|
-
link:
|
|
6
|
+
connect: mock.fn(),
|
|
7
|
+
disconnect: mock.fn(),
|
|
8
|
+
link: mock.fn()
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
const manifest =
|
|
12
|
-
const component =
|
|
13
|
-
const composition =
|
|
14
|
-
const remote =
|
|
15
|
-
|
|
16
|
-
module.exports = { manifest, component, composition, remote }
|
|
11
|
+
export const manifest = mock.fn(async () => generate())
|
|
12
|
+
export const component = mock.fn(async () => connector())
|
|
13
|
+
export const composition = mock.fn(async () => connector())
|
|
14
|
+
export const remote = mock.fn(async () => connector())
|
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
import { generate } from 'randomstring'
|
|
6
|
+
import * as _boot from './boot.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
9
|
+
boot: _boot
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
13
|
|
|
11
|
-
const stage =
|
|
14
|
+
const stage = await import('../src/index.js')
|
|
12
15
|
|
|
13
16
|
it('should be', () => {
|
|
14
|
-
|
|
17
|
+
assert.notStrictEqual(stage.component, undefined)
|
|
15
18
|
})
|
|
16
19
|
|
|
17
20
|
it('should boot component', async () => {
|
|
18
21
|
const path = generate()
|
|
19
22
|
const component = await stage.component(path)
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
assert.deepStrictEqual(mock.boot.manifest.mock.calls[0].arguments[0], path)
|
|
25
|
+
const manifest = await mock.boot.manifest.mock.calls[0].result
|
|
26
|
+
|
|
27
|
+
assert.ok(
|
|
28
|
+
mock.boot.component.mock.calls.some(
|
|
29
|
+
(call) =>
|
|
30
|
+
call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], manifest)
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
assert.deepStrictEqual(component, await mock.boot.component.mock.calls[0].result)
|
|
34
|
+
assert.ok(component.connect.mock.callCount() > 0)
|
|
25
35
|
})
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
4
6
|
|
|
5
7
|
const mock = {
|
|
6
|
-
boot:
|
|
8
|
+
boot: _boot
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
12
|
|
|
11
|
-
const stage =
|
|
13
|
+
const stage = await import('../src/index.js')
|
|
12
14
|
|
|
13
15
|
const paths = [generate(), generate()]
|
|
14
16
|
|
|
15
17
|
it('should be', () => {
|
|
16
|
-
|
|
18
|
+
assert.notStrictEqual(stage.composition, undefined)
|
|
17
19
|
})
|
|
18
20
|
|
|
19
21
|
it('should boot composition', async () => {
|
|
20
22
|
await stage.composition(paths)
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
assert.deepStrictEqual(mock.boot.composition.mock.calls[0].arguments[0], paths)
|
|
23
25
|
|
|
24
|
-
const composition = await mock.boot.composition.mock.
|
|
26
|
+
const composition = await mock.boot.composition.mock.calls[0].result
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should override bindings', async () => {
|
|
30
|
-
await stage.composition(paths)
|
|
31
|
-
|
|
32
|
-
const path = require.resolve('../src/binding')
|
|
33
|
-
|
|
34
|
-
/** @type {toa.boot.composition.Options} */
|
|
35
|
-
const options = { bindings: [path] }
|
|
36
|
-
|
|
37
|
-
expect(mock.boot.composition.mock.calls[0][1]).toStrictEqual(options)
|
|
28
|
+
assert.ok(composition.connect.mock.callCount() > 0)
|
|
38
29
|
})
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
import { generate } from 'randomstring'
|
|
6
|
+
import * as _boot from './boot.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
9
|
+
boot: _boot
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
13
|
|
|
11
|
-
const stage =
|
|
14
|
+
const stage = await import('../src/index.js')
|
|
12
15
|
|
|
13
16
|
it('should be', () => {
|
|
14
|
-
|
|
17
|
+
assert.notStrictEqual(stage.manifest, undefined)
|
|
15
18
|
})
|
|
16
19
|
|
|
17
20
|
it('should boot manifest', async () => {
|
|
@@ -19,6 +22,10 @@ it('should boot manifest', async () => {
|
|
|
19
22
|
|
|
20
23
|
const manifest = await stage.manifest(path)
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
assert.ok(
|
|
26
|
+
mock.boot.manifest.mock.calls.some(
|
|
27
|
+
(call) => call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], path)
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
assert.deepStrictEqual(manifest, await mock.boot.manifest.mock.calls[0].result)
|
|
24
31
|
})
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
4
6
|
|
|
5
7
|
const mock = {
|
|
6
|
-
boot:
|
|
8
|
+
boot: _boot
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
12
|
|
|
11
|
-
const stage =
|
|
13
|
+
const stage = await import('../src/index.js')
|
|
12
14
|
|
|
13
15
|
it('should be', () => {
|
|
14
|
-
|
|
16
|
+
assert.notStrictEqual(stage.remote, undefined)
|
|
15
17
|
})
|
|
16
18
|
|
|
17
19
|
it('should connect remote', async () => {
|
|
@@ -21,12 +23,12 @@ it('should connect remote', async () => {
|
|
|
21
23
|
|
|
22
24
|
const remote = await stage.remote(id)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
assert.ok(mock.boot.remote.mock.callCount() > 0)
|
|
27
|
+
assert.deepStrictEqual(remote, await mock.boot.remote.mock.calls[0].result)
|
|
28
|
+
assert.ok(remote.connect.mock.callCount() > 0)
|
|
27
29
|
|
|
28
|
-
const locator = mock.boot.remote.mock.calls[0][0]
|
|
30
|
+
const locator = mock.boot.remote.mock.calls[0].arguments[0]
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
assert.notStrictEqual(locator, undefined)
|
|
33
|
+
assert.partialDeepStrictEqual(locator, { name, namespace })
|
|
32
34
|
})
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, beforeEach, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
6
|
+
import * as _state from './state.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
7
|
-
state:
|
|
8
|
-
binding: require('./binding.mock')
|
|
9
|
+
boot: _boot,
|
|
10
|
+
state: _state
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
jest.mock('../src/binding', () => mock.binding)
|
|
13
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
14
|
+
mocking.module('../src/state', { namedExports: mock.state })
|
|
14
15
|
|
|
15
|
-
const { state } =
|
|
16
|
-
const
|
|
17
|
-
const stage = require('../')
|
|
16
|
+
const { state } = await import('../src/state.js')
|
|
17
|
+
const stage = await import('../src/index.js')
|
|
18
18
|
|
|
19
19
|
beforeEach(() => {
|
|
20
|
-
|
|
20
|
+
resetCalls()
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
it('should be', () => {
|
|
24
|
-
|
|
24
|
+
assert.notStrictEqual(stage.shutdown, undefined)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('should disconnect components', async () => {
|
|
@@ -30,7 +30,7 @@ it('should disconnect components', async () => {
|
|
|
30
30
|
|
|
31
31
|
await stage.shutdown()
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
assert.ok(component.disconnect.mock.callCount() > 0)
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
it('should disconnect compositions', async () => {
|
|
@@ -39,9 +39,9 @@ it('should disconnect compositions', async () => {
|
|
|
39
39
|
await stage.composition(paths)
|
|
40
40
|
await stage.shutdown()
|
|
41
41
|
|
|
42
|
-
const composition = await mock.boot.composition.mock.
|
|
42
|
+
const composition = await mock.boot.composition.mock.calls[0].result
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
assert.ok(composition.disconnect.mock.callCount() > 0)
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
it('should disconnect remotes', async () => {
|
|
@@ -50,17 +50,21 @@ it('should disconnect remotes', async () => {
|
|
|
50
50
|
const remote = await stage.remote(id)
|
|
51
51
|
await stage.shutdown()
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
assert.ok(remote.disconnect.mock.callCount() > 0)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
it('should reset state', async () => {
|
|
57
57
|
await stage.shutdown()
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
assert.ok(state.reset.mock.callCount() > 0)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
function resetCalls(target = [assert, mock, stage], seen = new Set()) {
|
|
63
|
+
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
seen.add(target)
|
|
66
|
+
|
|
67
|
+
for (const value of Object.values(target))
|
|
68
|
+
if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
|
|
69
|
+
else resetCalls(value, seen)
|
|
70
|
+
}
|
package/stage/test/state.mock.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// this module defines the replacement, so it still sees the real one
|
|
4
|
+
import * as original from '../src/state.js'
|
|
4
5
|
|
|
5
|
-
const reset =
|
|
6
|
-
const state = { ...original.state, reset }
|
|
7
|
-
|
|
8
|
-
module.exports = { state }
|
|
6
|
+
const reset = mock.fn(() => original.state.reset())
|
|
7
|
+
export const state = { ...original.state, reset }
|
package/stage/test/state.test.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { state } from '../src/state.js'
|
|
4
5
|
|
|
5
6
|
it('should be', () => {
|
|
6
|
-
|
|
7
|
+
assert.notStrictEqual(state, undefined)
|
|
7
8
|
})
|
|
8
9
|
|
|
9
10
|
it('should reset', () => {
|
|
10
|
-
const component = /** @type {toa.core.Component} */ 1
|
|
11
|
-
const composition = /** @type {toa.core.Connector} */ 2
|
|
12
|
-
const remote = /** @type {toa.core.Component} */ 3
|
|
11
|
+
const component = /** @type {import('@toa.io/core').Component} */ 1
|
|
12
|
+
const composition = /** @type {import('@toa.io/core').Connector} */ 2
|
|
13
|
+
const remote = /** @type {import('@toa.io/core').Component} */ 3
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
assert.deepStrictEqual(state.components.length, 0)
|
|
16
|
+
assert.deepStrictEqual(state.compositions.length, 0)
|
|
17
|
+
assert.deepStrictEqual(state.remotes.length, 0)
|
|
17
18
|
|
|
18
19
|
state.components.push(component)
|
|
19
20
|
state.compositions.push(composition)
|
|
@@ -21,7 +22,7 @@ it('should reset', () => {
|
|
|
21
22
|
|
|
22
23
|
state.reset()
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
assert.deepStrictEqual(state.components.length, 0)
|
|
26
|
+
assert.deepStrictEqual(state.compositions.length, 0)
|
|
27
|
+
assert.deepStrictEqual(state.remotes.length, 0)
|
|
27
28
|
})
|
package/stage/types/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import * as _core from '@toa.io/core'
|
|
1
|
+
import type * as _core from '@toa.io/core'
|
|
2
2
|
import * as _norm from '@toa.io/norm/types'
|
|
3
3
|
import * as _composition from '@toa.io/boot/types/composition'
|
|
4
4
|
|
|
5
|
-
export function manifest
|
|
5
|
+
export function manifest(path: string): Promise<_norm.Component>
|
|
6
6
|
|
|
7
|
-
export function component
|
|
7
|
+
export function component(path: string): Promise<_core.Component>
|
|
8
8
|
|
|
9
|
-
export function composition
|
|
9
|
+
export function composition(
|
|
10
|
+
paths: string[],
|
|
11
|
+
options?: _composition.Options
|
|
12
|
+
): Promise<void>
|
|
10
13
|
|
|
11
|
-
export function compose
|
|
14
|
+
export function compose(paths: string[]): Promise<void>
|
|
12
15
|
|
|
13
|
-
export function serve
|
|
16
|
+
export function serve(ref: string): Promise<_core.Component>
|
|
14
17
|
|
|
15
|
-
export function remote
|
|
18
|
+
export function remote(id: string): Promise<_core.Component>
|
|
16
19
|
|
|
17
|
-
export function shutdown
|
|
18
|
-
|
|
19
|
-
export * as binding from './binding'
|
|
20
|
+
export function shutdown(): Promise<void>
|
package/stage/types/state.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as _core from '@toa.io/core'
|
|
2
|
-
|
|
3
|
-
declare namespace toa.stage{
|
|
1
|
+
import type * as _core from '@toa.io/core'
|
|
4
2
|
|
|
3
|
+
declare namespace toa.stage {
|
|
5
4
|
type State = {
|
|
6
5
|
reset: () => void
|
|
7
6
|
components: _core.Component[]
|
|
@@ -9,7 +8,6 @@ declare namespace toa.stage{
|
|
|
9
8
|
services: _core.Connector[]
|
|
10
9
|
remotes: _core.Component[]
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export type State = toa.stage.State
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @implements {toa.stage.binding.Binding}
|
|
5
|
-
*/
|
|
6
|
-
class Binding {
|
|
7
|
-
/** @type {Record<string, function[]>} */
|
|
8
|
-
#callbacks = {}
|
|
9
|
-
|
|
10
|
-
/** @type {Record<string, function>} */
|
|
11
|
-
#producers = {}
|
|
12
|
-
|
|
13
|
-
async subscribe (label, callback) {
|
|
14
|
-
if (this.#callbacks[label] === undefined) this.#callbacks[label] = []
|
|
15
|
-
|
|
16
|
-
this.#callbacks[label].push(callback)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async emit (label, message) {
|
|
20
|
-
if (!(label in this.#callbacks)) return
|
|
21
|
-
|
|
22
|
-
const callbacks = this.#callbacks[label]
|
|
23
|
-
const promises = callbacks.map((callback) => callback(message))
|
|
24
|
-
|
|
25
|
-
await Promise.all(promises)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async reply (label, produce) {
|
|
29
|
-
if (label in this.#producers) throw new Error(`Label '${label}' is already bound`)
|
|
30
|
-
|
|
31
|
-
this.#producers[label] = produce
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async request (label, request) {
|
|
35
|
-
if (!(label in this.#producers)) throw new Error(`Label '${label}' is not bound`)
|
|
36
|
-
|
|
37
|
-
const produce = this.#producers[label]
|
|
38
|
-
|
|
39
|
-
return produce(request)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
reset () {
|
|
43
|
-
this.#callbacks = {}
|
|
44
|
-
this.#producers = {}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const binding = new Binding()
|
|
49
|
-
|
|
50
|
-
exports.binding = binding
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('@toa.io/core')
|
|
4
|
-
|
|
5
|
-
const { binding } = require('./binding')
|
|
6
|
-
const { label } = require('./label')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @implements {toa.core.bindings.Consumer}
|
|
10
|
-
*/
|
|
11
|
-
class Consumer extends Connector {
|
|
12
|
-
/** @type {string} */
|
|
13
|
-
#label
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {toa.core.Locator} locator
|
|
17
|
-
* @param {string} endpoint
|
|
18
|
-
*/
|
|
19
|
-
constructor (locator, endpoint) {
|
|
20
|
-
super()
|
|
21
|
-
|
|
22
|
-
this.#label = label(locator, endpoint)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async request (request) {
|
|
26
|
-
request = JSON.parse(JSON.stringify(request))
|
|
27
|
-
|
|
28
|
-
return binding.request(this.#label, request)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.Consumer = Consumer
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('@toa.io/core')
|
|
4
|
-
|
|
5
|
-
const { binding } = require('./binding')
|
|
6
|
-
const { label } = require('./label')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @implements {toa.core.bindings.Emitter}
|
|
10
|
-
*/
|
|
11
|
-
class Emitter extends Connector {
|
|
12
|
-
/** @type {string} */
|
|
13
|
-
#label
|
|
14
|
-
|
|
15
|
-
constructor (locator, endpoint) {
|
|
16
|
-
super()
|
|
17
|
-
|
|
18
|
-
this.#label = label(locator, endpoint)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async emit (message) {
|
|
22
|
-
message = JSON.parse(JSON.stringify(message))
|
|
23
|
-
await binding.emit(this.#label, message)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.Emitter = Emitter
|