@toa.io/boot 0.20.0-dev.8 → 0.20.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.
- package/package.json +8 -7
- package/src/bindings/broadcast.js +1 -1
- package/src/bindings/receive.js +1 -1
- package/src/bridge.js +1 -1
- package/src/component.js +1 -1
- package/src/composition.js +0 -6
- package/src/emission.js +2 -2
- package/src/index.js +2 -1
- package/src/manifest.js +5 -4
- package/src/manifest.test.js +23 -0
- package/src/receivers.js +14 -1
- package/types/bindings.d.ts +3 -0
- package/types/composition.d.ts +4 -19
- package/types/index.d.ts +20 -2
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/boot",
|
|
3
|
-
"version": "0.20.0
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Toa Boot",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
7
7
|
"main": "src/index.js",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/toa-io/toa.git"
|
|
@@ -19,13 +20,13 @@
|
|
|
19
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@toa.io/core": "0.20.0
|
|
23
|
-
"@toa.io/filesystem": "0.20.0
|
|
24
|
-
"@toa.io/generic": "0.20.0
|
|
25
|
-
"@toa.io/norm": "0.20.0
|
|
26
|
-
"@toa.io/schema": "0.20.0
|
|
23
|
+
"@toa.io/core": "0.20.0",
|
|
24
|
+
"@toa.io/filesystem": "0.20.0",
|
|
25
|
+
"@toa.io/generic": "0.20.0",
|
|
26
|
+
"@toa.io/norm": "0.20.0",
|
|
27
|
+
"@toa.io/schema": "0.20.0",
|
|
27
28
|
"clone-deep": "4.0.1",
|
|
28
29
|
"dotenv": "16.1.1"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "28fc4b45c224c3683acaaf0e4abd1eb04e07b408"
|
|
31
32
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { factory } = require('./factory')
|
|
4
4
|
|
|
5
|
-
const broadcast = (
|
|
5
|
+
const broadcast = (channel, group, binding = '@toa.io/bindings.amqp') => factory(binding).broadcast(channel, group)
|
|
6
6
|
|
|
7
7
|
exports.broadcast = broadcast
|
package/src/bindings/receive.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { factory } = require('./factory')
|
|
4
4
|
|
|
5
|
-
const receive = (binding,
|
|
5
|
+
const receive = (binding, locator, label, group, receiver) => factory(binding).receiver(locator, label, group, receiver)
|
|
6
6
|
|
|
7
7
|
exports.receive = receive
|
package/src/bridge.js
CHANGED
|
@@ -8,7 +8,7 @@ const algorithm = (bridge, path, endpoint, context) => {
|
|
|
8
8
|
return algorithm
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const event = (bridge, path, label) => resolve(bridge).event(path, label)
|
|
11
|
+
const event = (bridge, path, label, context) => resolve(bridge).event(path, label, context)
|
|
12
12
|
const receiver = (bridge, path, label) => resolve(bridge).receiver(path, label)
|
|
13
13
|
|
|
14
14
|
const factories = {}
|
package/src/component.js
CHANGED
|
@@ -16,7 +16,7 @@ const component = async (manifest) => {
|
|
|
16
16
|
const locator = new Locator(manifest.name, manifest.namespace)
|
|
17
17
|
const storage = boot.storage(manifest)
|
|
18
18
|
const context = await boot.context(manifest)
|
|
19
|
-
const emission = boot.emission(manifest.events, locator)
|
|
19
|
+
const emission = boot.emission(manifest.events, locator, context)
|
|
20
20
|
const schema = new Schema(manifest.entity.schema)
|
|
21
21
|
const entity = new entities.Factory(schema)
|
|
22
22
|
const state = new State(storage, entity, emission, manifest.entity.initialized)
|
package/src/composition.js
CHANGED
|
@@ -7,15 +7,9 @@ const boot = require('./index')
|
|
|
7
7
|
async function composition (paths, options) {
|
|
8
8
|
options = Object.assign({}, options)
|
|
9
9
|
|
|
10
|
-
/** @type {toa.norm.Component[]} */
|
|
11
10
|
const manifests = await Promise.all(paths.map((path) => boot.manifest(path, options)))
|
|
12
|
-
|
|
13
|
-
/** @type {toa.core.Connector[]} */
|
|
14
11
|
const tenants = await Promise.all(manifests.map(boot.extensions.tenants))
|
|
15
|
-
|
|
16
12
|
const expositions = await Promise.all(manifests.map(boot.discovery.expose))
|
|
17
|
-
|
|
18
|
-
/** @type {toa.core.Component[]} */
|
|
19
13
|
const components = await Promise.all(manifests.map(boot.component))
|
|
20
14
|
|
|
21
15
|
const producers = components.map((component, index) =>
|
package/src/emission.js
CHANGED
|
@@ -5,13 +5,13 @@ const { Emission, Event } = require('@toa.io/core')
|
|
|
5
5
|
const boot = require('./index')
|
|
6
6
|
const extensions = require('./extensions')
|
|
7
7
|
|
|
8
|
-
const emission = (definitions, locator) => {
|
|
8
|
+
const emission = (definitions, locator, context) => {
|
|
9
9
|
if (definitions === undefined) return
|
|
10
10
|
|
|
11
11
|
const events = Object.entries(definitions).map(([label, definition]) => {
|
|
12
12
|
const emitter = boot.bindings.emit(definition.binding, locator, label)
|
|
13
13
|
const decorator = extensions.emitter(emitter, label)
|
|
14
|
-
const bridge = boot.bridge.event(definition.bridge, definition.path, label)
|
|
14
|
+
const bridge = boot.bridge.event(definition.bridge, definition.path, label, context)
|
|
15
15
|
|
|
16
16
|
return new Event(definition, decorator, bridge)
|
|
17
17
|
})
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const { exposition } = require('./exposition')
|
|
|
13
13
|
const { images } = require('./images')
|
|
14
14
|
const { manifest } = require('./manifest')
|
|
15
15
|
const { operation } = require('./operation')
|
|
16
|
-
const { receivers } = require('./receivers')
|
|
16
|
+
const { receivers, receive } = require('./receivers')
|
|
17
17
|
const { remote } = require('./remote')
|
|
18
18
|
const { storage } = require('./storage')
|
|
19
19
|
|
|
@@ -35,6 +35,7 @@ exports.images = images
|
|
|
35
35
|
exports.manifest = manifest
|
|
36
36
|
exports.operation = operation
|
|
37
37
|
exports.receivers = receivers
|
|
38
|
+
exports.receive = receive
|
|
38
39
|
exports.registry = registry
|
|
39
40
|
exports.remote = remote
|
|
40
41
|
exports.storage = storage
|
package/src/manifest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const clone = require('clone-deep')
|
|
3
4
|
const { merge } = require('@toa.io/generic')
|
|
4
5
|
const { component: load } = require('@toa.io/norm')
|
|
5
6
|
const { Locator } = require('@toa.io/core')
|
|
@@ -8,7 +9,7 @@ const { Locator } = require('@toa.io/core')
|
|
|
8
9
|
* @type {toa.boot.Manifest}
|
|
9
10
|
*/
|
|
10
11
|
const manifest = async (path, options = {}) => {
|
|
11
|
-
merge(options, DEFAULTS)
|
|
12
|
+
options = merge(clone(options), DEFAULTS)
|
|
12
13
|
|
|
13
14
|
const manifest = await load(path)
|
|
14
15
|
|
|
@@ -31,8 +32,9 @@ const manifest = async (path, options = {}) => {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
if (
|
|
35
|
+
if (manifest.extensions === undefined) manifest.extensions = {}
|
|
35
36
|
|
|
37
|
+
// add `null` manifests
|
|
36
38
|
for (const extension of options.extensions) {
|
|
37
39
|
if (!(extension in manifest.extensions)) manifest.extensions[extension] = null
|
|
38
40
|
}
|
|
@@ -44,9 +46,8 @@ const manifest = async (path, options = {}) => {
|
|
|
44
46
|
return manifest
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
/** @type {toa.boot.composition.Options} */
|
|
48
49
|
const DEFAULTS = {
|
|
49
|
-
extensions: ['@toa.io/extensions.sampling'
|
|
50
|
+
extensions: ['@toa.io/extensions.sampling']
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
exports.manifest = manifest
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { generate } = require('randomstring')
|
|
4
|
+
|
|
5
|
+
jest.mock('@toa.io/norm', () => ({
|
|
6
|
+
component: () => mockComponent()
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
const { manifest } = require('./manifest')
|
|
10
|
+
|
|
11
|
+
const path = generate()
|
|
12
|
+
|
|
13
|
+
it('should not modify options', async () => {
|
|
14
|
+
const options = { extensions: ['foo', 'bar'] }
|
|
15
|
+
|
|
16
|
+
await manifest(path, options)
|
|
17
|
+
|
|
18
|
+
expect(options.extensions.length).toStrictEqual(2)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function mockComponent () {
|
|
22
|
+
return { name: generate(), namespace: generate() }
|
|
23
|
+
}
|
package/src/receivers.js
CHANGED
|
@@ -9,9 +9,9 @@ const receivers = async (manifest, runtime) => {
|
|
|
9
9
|
if (manifest.receivers === undefined) return []
|
|
10
10
|
|
|
11
11
|
const receivers = []
|
|
12
|
+
const local = await boot.remote(manifest.locator, manifest)
|
|
12
13
|
|
|
13
14
|
for (const [label, definition] of Object.entries(manifest.receivers)) {
|
|
14
|
-
const local = await boot.remote(manifest.locator, manifest)
|
|
15
15
|
const bridge = definition.bridge !== undefined ? boot.bridge.receiver(definition.bridge, manifest.path, label) : undefined
|
|
16
16
|
const receiver = new Receiver(definition, local, bridge)
|
|
17
17
|
const decorator = extensions.receiver(receiver, manifest.locator)
|
|
@@ -28,6 +28,18 @@ const receivers = async (manifest, runtime) => {
|
|
|
28
28
|
return receivers
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
async function receive (label, group, callback) {
|
|
32
|
+
if (callback === undefined) {
|
|
33
|
+
callback = group
|
|
34
|
+
group = undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const locator = Locator.parse(label)
|
|
38
|
+
const transport = await resolveBinding(locator, label)
|
|
39
|
+
|
|
40
|
+
return boot.bindings.receive(transport, locator, label, group, callback)
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
/**
|
|
32
44
|
* @param {toa.core.Locator} locator
|
|
33
45
|
* @param {string} label
|
|
@@ -42,3 +54,4 @@ async function resolveBinding (locator, label) {
|
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
exports.receivers = receivers
|
|
57
|
+
exports.receive = receive
|
package/types/composition.d.ts
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
namespace composition {
|
|
6
|
-
|
|
7
|
-
type Options = {
|
|
8
|
-
bindings?: string[]
|
|
9
|
-
storage?: string
|
|
10
|
-
extensions?: string[]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type Composition = (paths: string[], options: composition.Options) => Promise<_core.Connector>
|
|
16
|
-
|
|
1
|
+
export type Options = {
|
|
2
|
+
bindings?: string[]
|
|
3
|
+
storage?: string
|
|
4
|
+
extensions?: string[]
|
|
17
5
|
}
|
|
18
|
-
|
|
19
|
-
export type Options = toa.boot.composition.Options
|
|
20
|
-
export type Composition = toa.boot.Composition
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as core from '@toa.io/core'
|
|
2
|
+
import * as composition from './composition'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export * as bindings from './bindings'
|
|
5
|
+
|
|
6
|
+
export async function composition (paths: string[], options?: composition.Options): Promise<core.Connector>
|
|
7
|
+
|
|
8
|
+
export async function remote (locator: core.Locator): Promise<core.Component>
|
|
9
|
+
|
|
10
|
+
export async function receive<T = any> (
|
|
11
|
+
label: string,
|
|
12
|
+
receiver: Receiver,
|
|
13
|
+
): Promise<core.Connector>
|
|
14
|
+
|
|
15
|
+
export async function receive<T = any> (
|
|
16
|
+
label: string,
|
|
17
|
+
group: string | undefined,
|
|
18
|
+
receiver: Receiver,
|
|
19
|
+
): Promise<core.Connector>
|
|
20
|
+
|
|
21
|
+
type Receiver = { receive: (message: core.Message<T>) => void | Promise<void> }
|