@toa.io/boot 0.1.0-dev.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/LICENSE +22 -0
- package/package.json +30 -0
- package/src/bindings/constants.js +3 -0
- package/src/bindings/consume.js +9 -0
- package/src/bindings/emit.js +7 -0
- package/src/bindings/factory.js +11 -0
- package/src/bindings/index.js +11 -0
- package/src/bindings/produce.js +27 -0
- package/src/bindings/receive.js +7 -0
- package/src/bridge.js +28 -0
- package/src/call.js +15 -0
- package/src/cascade.js +34 -0
- package/src/composition.js +29 -0
- package/src/context.js +22 -0
- package/src/contract.js +21 -0
- package/src/deployment.js +12 -0
- package/src/discovery.js +38 -0
- package/src/emission.js +20 -0
- package/src/exposition.js +17 -0
- package/src/extensions.js +25 -0
- package/src/index.js +36 -0
- package/src/manifest.js +20 -0
- package/src/operation.js +29 -0
- package/src/receivers.js +38 -0
- package/src/remote.js +24 -0
- package/src/runtime.js +25 -0
- package/src/storage.js +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2020-present Artem Gurtovoi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@toa.io/boot",
|
|
3
|
+
"version": "0.1.0-dev.0",
|
|
4
|
+
"description": "Toa Boot",
|
|
5
|
+
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/toa-io/toa#readme",
|
|
7
|
+
"main": "src/index.js",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/toa-io/toa.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/toa-io/toa/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@toa.io/bindings.loop": "^0.1.0-dev.0",
|
|
23
|
+
"@toa.io/core": "^0.1.0-dev.0",
|
|
24
|
+
"@toa.io/operations": "^0.1.0-dev.0",
|
|
25
|
+
"@toa.io/package": "^0.1.0-dev.0",
|
|
26
|
+
"@toa.io/schema": "^0.1.0-dev.0",
|
|
27
|
+
"clone-deep": "4.0.1"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "632df6cead03909ad2cfb8852e178914ac4ab5d2"
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { LOOP } = require('./constants')
|
|
4
|
+
const { factory } = require('./factory')
|
|
5
|
+
|
|
6
|
+
const consume = (locator, endpoint, bindings) =>
|
|
7
|
+
[LOOP].concat(bindings).map((binding) => factory(binding).consumer(locator, endpoint))
|
|
8
|
+
|
|
9
|
+
exports.consume = consume
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { consume } = require('./consume')
|
|
4
|
+
const { emit } = require('./emit')
|
|
5
|
+
const { produce } = require('./produce')
|
|
6
|
+
const { receive } = require('./receive')
|
|
7
|
+
|
|
8
|
+
exports.consume = consume
|
|
9
|
+
exports.emit = emit
|
|
10
|
+
exports.produce = produce
|
|
11
|
+
exports.receive = receive
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { LOOP } = require('./constants')
|
|
4
|
+
const { factory } = require('./factory')
|
|
5
|
+
|
|
6
|
+
const produce = (runtime, operations) => group(operations, (factory, endpoints) =>
|
|
7
|
+
factory.producer(runtime.locator, endpoints, runtime))
|
|
8
|
+
|
|
9
|
+
const group = (operations, callback) => {
|
|
10
|
+
const map = {}
|
|
11
|
+
|
|
12
|
+
for (const [endpoint, operation] of Object.entries(operations)) {
|
|
13
|
+
const bindings = global.TOA_INTEGRATION_BINDINGS_LOOP_DISABLED
|
|
14
|
+
? operation.bindings
|
|
15
|
+
: [LOOP].concat(operation.bindings)
|
|
16
|
+
|
|
17
|
+
for (const binding of bindings) {
|
|
18
|
+
if (!map[binding]) map[binding] = []
|
|
19
|
+
|
|
20
|
+
map[binding].push(endpoint)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return Object.entries(map).map(([binding, endpoints]) => callback(factory(binding), endpoints))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.produce = produce
|
package/src/bridge.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const operation = (bridge, path, endpoint, context) => {
|
|
4
|
+
const operation = resolve(bridge).operation(path, endpoint, context)
|
|
5
|
+
|
|
6
|
+
operation.depends(context)
|
|
7
|
+
|
|
8
|
+
return operation
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const event = (bridge, path, label) => resolve(bridge).event(path, label)
|
|
12
|
+
const receiver = (bridge, path, label) => resolve(bridge).receiver(path, label)
|
|
13
|
+
|
|
14
|
+
const factories = {}
|
|
15
|
+
|
|
16
|
+
const resolve = (bridge) => {
|
|
17
|
+
if (factories[bridge] === undefined) {
|
|
18
|
+
const { Factory } = require(bridge)
|
|
19
|
+
|
|
20
|
+
factories[bridge] = new Factory()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return factories[bridge]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.operation = operation
|
|
27
|
+
exports.event = event
|
|
28
|
+
exports.receiver = receiver
|
package/src/call.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Call, Transmission } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const call = (locator, endpoint, definition) => {
|
|
8
|
+
const consumers = boot.bindings.consume(locator, endpoint, definition.bindings)
|
|
9
|
+
const transmission = new Transmission(consumers)
|
|
10
|
+
const contract = boot.contract.request(definition)
|
|
11
|
+
|
|
12
|
+
return new Call(transmission, contract)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.call = call
|
package/src/cascade.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Cascade } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const cascade = (manifest, endpoint, definition, context) => {
|
|
8
|
+
const bridges = []
|
|
9
|
+
|
|
10
|
+
if (definition.forward) endpoint = definition.forward
|
|
11
|
+
|
|
12
|
+
if (definition.bridge) {
|
|
13
|
+
const bridge = boot.bridge.operation(definition.bridge, manifest.path, endpoint, context)
|
|
14
|
+
|
|
15
|
+
bridges.unshift(bridge)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let prototype = manifest
|
|
19
|
+
|
|
20
|
+
while ((prototype = prototype.prototype) !== null) {
|
|
21
|
+
const operation = prototype.operations[endpoint]
|
|
22
|
+
|
|
23
|
+
if (operation === undefined) continue
|
|
24
|
+
|
|
25
|
+
const bridge = boot.bridge.operation(operation.bridge, prototype.path, endpoint, context)
|
|
26
|
+
|
|
27
|
+
bridges.unshift(bridge)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (bridges.length > 1) return new Cascade(bridges)
|
|
31
|
+
else return bridges[0]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.cascade = cascade
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Composition } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
async function composition (paths, options) {
|
|
8
|
+
normalize(options)
|
|
9
|
+
|
|
10
|
+
const manifests = await Promise.all(paths.map((path) => boot.manifest(path, options)))
|
|
11
|
+
const extensions = await Promise.all(manifests.map(boot.extensions))
|
|
12
|
+
const expositions = await Promise.all(manifests.map(boot.discovery.expose))
|
|
13
|
+
const runtimes = await Promise.all(manifests.map(boot.runtime))
|
|
14
|
+
|
|
15
|
+
const producers = runtimes.map((runtime, index) =>
|
|
16
|
+
boot.bindings.produce(runtime, manifests[index].operations))
|
|
17
|
+
|
|
18
|
+
const receivers = await Promise.all(runtimes.map((runtime, index) =>
|
|
19
|
+
boot.receivers(manifests[index], runtime)))
|
|
20
|
+
|
|
21
|
+
return new Composition(expositions.flat(), producers.flat(), receivers.flat(), extensions.flat())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalize = (options) => {
|
|
25
|
+
if (options === undefined) return
|
|
26
|
+
if (options.bindings === null) options.bindings = []
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.composition = composition
|
package/src/context.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Context, Locator } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const context = async (manifest) => {
|
|
8
|
+
const local = await boot.remote(manifest.locator, manifest)
|
|
9
|
+
|
|
10
|
+
const lookup = async (domain, name) => {
|
|
11
|
+
const locator = new Locator({ domain, name })
|
|
12
|
+
const remote = await boot.remote(locator)
|
|
13
|
+
|
|
14
|
+
await remote.connect()
|
|
15
|
+
|
|
16
|
+
return remote
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return new Context(local, lookup)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.context = context
|
package/src/contract.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { contract: { Request, Reply } } = require('@toa.io/core')
|
|
4
|
+
const { Schema } = require('@toa.io/schema')
|
|
5
|
+
|
|
6
|
+
const request = (definition) => {
|
|
7
|
+
const request = Request.schema(definition)
|
|
8
|
+
const schema = new Schema(request)
|
|
9
|
+
|
|
10
|
+
return new Request(schema)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const reply = (output, error) => {
|
|
14
|
+
const reply = Reply.schema(output, error)
|
|
15
|
+
const schema = new Schema(reply)
|
|
16
|
+
|
|
17
|
+
return new Reply(schema)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.request = request
|
|
21
|
+
exports.reply = reply
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Deployment } = require('@toa.io/operations')
|
|
4
|
+
const { context: load } = require('@toa.io/package')
|
|
5
|
+
|
|
6
|
+
const deployment = async (path) => {
|
|
7
|
+
const context = await load(path)
|
|
8
|
+
|
|
9
|
+
return new Deployment(context)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.deployment = deployment
|
package/src/discovery.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Discovery, Exposition } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const discovery = async () => {
|
|
8
|
+
if (discovery.instance === undefined) {
|
|
9
|
+
discovery.instance = new Discovery(lookup)
|
|
10
|
+
|
|
11
|
+
await discovery.instance.connect()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return discovery.instance
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const lookup = async (locator) => {
|
|
18
|
+
const call = boot.call(locator, ENDPOINT, { bindings: BINDINGS })
|
|
19
|
+
await call.connect()
|
|
20
|
+
|
|
21
|
+
return call
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const expose = async (manifest) => {
|
|
25
|
+
const exposition = new Exposition(manifest.locator, manifest)
|
|
26
|
+
const operations = { [ENDPOINT]: { bindings: BINDINGS } }
|
|
27
|
+
const producers = boot.bindings.produce(exposition, operations)
|
|
28
|
+
|
|
29
|
+
await Promise.all(producers.map((producer) => producer.connect()))
|
|
30
|
+
|
|
31
|
+
return producers
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const BINDINGS = ['@toa.io/bindings.amqp']
|
|
35
|
+
const ENDPOINT = '.lookup'
|
|
36
|
+
|
|
37
|
+
exports.discovery = discovery
|
|
38
|
+
exports.expose = expose
|
package/src/emission.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Emission, Event } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const emission = (definitions, locator) => {
|
|
8
|
+
if (definitions === undefined) return
|
|
9
|
+
|
|
10
|
+
const events = Object.entries(definitions).map(([label, definition]) => {
|
|
11
|
+
const transmitter = boot.bindings.emit(definition.binding, locator, label)
|
|
12
|
+
const bridge = boot.bridge.event(definition.bridge, definition.path, label)
|
|
13
|
+
|
|
14
|
+
return new Event(definition, transmitter, bridge)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return new Emission(events)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.emission = emission
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Exposition, Locator } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const exposition = async (manifest) => {
|
|
8
|
+
const locator = new Locator()
|
|
9
|
+
const exposition = new Exposition(locator, manifest)
|
|
10
|
+
const producers = boot.bindings.expose(exposition)
|
|
11
|
+
|
|
12
|
+
await Promise.all(producers.map((producer) => producer.connect()))
|
|
13
|
+
|
|
14
|
+
return producers
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.exposition = exposition
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const extensions = (manifest) => {
|
|
4
|
+
if (manifest.extensions === undefined) return
|
|
5
|
+
|
|
6
|
+
const extensions = []
|
|
7
|
+
|
|
8
|
+
for (const [key, value] of Object.entries(manifest.extensions)) {
|
|
9
|
+
extensions.push(extension(key, value, manifest))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return extensions
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const extension = (name, definition, manifest) => {
|
|
16
|
+
if (factories[name] === undefined) {
|
|
17
|
+
factories[name] = new (require(name).Factory)()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return factories[name].connector(manifest.locator, definition)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const factories = {}
|
|
24
|
+
|
|
25
|
+
exports.extensions = extensions
|
package/src/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { call } = require('./call')
|
|
4
|
+
const { cascade } = require('./cascade')
|
|
5
|
+
const { composition } = require('./composition')
|
|
6
|
+
const { context } = require('./context')
|
|
7
|
+
const { deployment } = require('./deployment')
|
|
8
|
+
const { emission } = require('./emission')
|
|
9
|
+
const { exposition } = require('./exposition')
|
|
10
|
+
const { extensions } = require('./extensions')
|
|
11
|
+
const { manifest } = require('./manifest')
|
|
12
|
+
const { operation } = require('./operation')
|
|
13
|
+
const { receivers } = require('./receivers')
|
|
14
|
+
const { remote } = require('./remote')
|
|
15
|
+
const { runtime } = require('./runtime')
|
|
16
|
+
const { storage } = require('./storage')
|
|
17
|
+
|
|
18
|
+
exports.bindings = require('./bindings')
|
|
19
|
+
exports.bridge = require('./bridge')
|
|
20
|
+
exports.contract = require('./contract')
|
|
21
|
+
exports.discovery = require('./discovery')
|
|
22
|
+
|
|
23
|
+
exports.call = call
|
|
24
|
+
exports.cascade = cascade
|
|
25
|
+
exports.composition = composition
|
|
26
|
+
exports.context = context
|
|
27
|
+
exports.deployment = deployment
|
|
28
|
+
exports.emission = emission
|
|
29
|
+
exports.exposition = exposition
|
|
30
|
+
exports.extensions = extensions
|
|
31
|
+
exports.manifest = manifest
|
|
32
|
+
exports.operation = operation
|
|
33
|
+
exports.receivers = receivers
|
|
34
|
+
exports.remote = remote
|
|
35
|
+
exports.runtime = runtime
|
|
36
|
+
exports.storage = storage
|
package/src/manifest.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { manifest: load } = require('@toa.io/package')
|
|
4
|
+
const { Locator } = require('@toa.io/core')
|
|
5
|
+
|
|
6
|
+
const manifest = async (path, options) => {
|
|
7
|
+
const manifest = await load(path)
|
|
8
|
+
|
|
9
|
+
if (options?.bindings !== undefined) {
|
|
10
|
+
for (const operation of Object.values(manifest.operations)) {
|
|
11
|
+
operation.bindings = options.bindings
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
manifest.locator = new Locator(manifest)
|
|
16
|
+
|
|
17
|
+
return manifest
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.manifest = manifest
|
package/src/operation.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Transition, Observation, Assignment, State, Query, entities } = require('@toa.io/core')
|
|
4
|
+
const { Schema } = require('@toa.io/schema')
|
|
5
|
+
|
|
6
|
+
const boot = require('./index')
|
|
7
|
+
|
|
8
|
+
const operation = (manifest, endpoint, definition, context, storage, emission) => {
|
|
9
|
+
const cascade = boot.cascade(manifest, endpoint, definition, context)
|
|
10
|
+
const contract = boot.contract.reply(definition.output, definition.error)
|
|
11
|
+
const schema = new Schema(manifest.entity.schema)
|
|
12
|
+
const entity = new entities.Factory(schema)
|
|
13
|
+
const subject = new State(storage, entity, emission, manifest.entity.initialized)
|
|
14
|
+
const query = new Query(manifest.entity.schema.properties)
|
|
15
|
+
|
|
16
|
+
subject.query = subject[definition.subject]
|
|
17
|
+
|
|
18
|
+
const Type = TYPES[definition.type]
|
|
19
|
+
|
|
20
|
+
return new Type(cascade, subject, contract, query, definition)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TYPES = {
|
|
24
|
+
transition: Transition,
|
|
25
|
+
observation: Observation,
|
|
26
|
+
assignment: Assignment
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.operation = operation
|
package/src/receivers.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Receiver, Locator } = require('@toa.io/core')
|
|
4
|
+
|
|
5
|
+
const boot = require('./index')
|
|
6
|
+
|
|
7
|
+
const receivers = async (manifest, runtime) => {
|
|
8
|
+
if (manifest.receivers === undefined) return []
|
|
9
|
+
|
|
10
|
+
const receivers = []
|
|
11
|
+
|
|
12
|
+
for (const [label, definition] of Object.entries(manifest.receivers)) {
|
|
13
|
+
const local = await boot.remote(manifest.locator, manifest)
|
|
14
|
+
const bridge = boot.bridge.receiver(definition.bridge, manifest.path, label)
|
|
15
|
+
const receiver = new Receiver(definition, local, bridge)
|
|
16
|
+
|
|
17
|
+
let transport = definition.binding
|
|
18
|
+
const locator = new Locator(label)
|
|
19
|
+
const { endpoint } = Locator.parse(label)
|
|
20
|
+
|
|
21
|
+
if (transport === undefined) {
|
|
22
|
+
const discovery = await boot.discovery.discovery()
|
|
23
|
+
const { events } = await discovery.lookup(locator)
|
|
24
|
+
|
|
25
|
+
transport = events[endpoint].binding
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { id } = new Locator(manifest)
|
|
29
|
+
const binding = boot.bindings.receive(transport, locator, endpoint, id, receiver)
|
|
30
|
+
|
|
31
|
+
binding.depends(runtime)
|
|
32
|
+
receivers.push(binding)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return receivers
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.receivers = receivers
|
package/src/remote.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Remote } = require('@toa.io/core')
|
|
4
|
+
const { remap } = require('@toa.io/gears')
|
|
5
|
+
|
|
6
|
+
const boot = require('./index')
|
|
7
|
+
|
|
8
|
+
const remote = async (locator, manifest) => {
|
|
9
|
+
const discovery = await boot.discovery.discovery()
|
|
10
|
+
|
|
11
|
+
if (manifest === undefined) manifest = await discovery.lookup(locator)
|
|
12
|
+
|
|
13
|
+
const calls = remap(manifest.operations,
|
|
14
|
+
(definition, endpoint) => boot.call(locator, endpoint, definition))
|
|
15
|
+
|
|
16
|
+
const remote = new Remote(locator, calls)
|
|
17
|
+
|
|
18
|
+
// ensure discovery shutdown
|
|
19
|
+
remote.depends(discovery)
|
|
20
|
+
|
|
21
|
+
return remote
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.remote = remote
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { remap } = require('@toa.io/gears')
|
|
4
|
+
const { Runtime, Locator } = require('@toa.io/core')
|
|
5
|
+
|
|
6
|
+
const boot = require('./index')
|
|
7
|
+
|
|
8
|
+
const runtime = async (manifest) => {
|
|
9
|
+
const locator = new Locator(manifest)
|
|
10
|
+
const storage = boot.storage(locator, manifest.entity.storage)
|
|
11
|
+
const context = await boot.context(manifest)
|
|
12
|
+
const emission = boot.emission(manifest.events, locator)
|
|
13
|
+
|
|
14
|
+
const operations = remap(manifest.operations, (definition, endpoint) =>
|
|
15
|
+
boot.operation(manifest, endpoint, definition, context, storage, emission))
|
|
16
|
+
|
|
17
|
+
const runtime = new Runtime(locator, operations)
|
|
18
|
+
|
|
19
|
+
if (storage) runtime.depends(storage)
|
|
20
|
+
if (emission) runtime.depends(emission)
|
|
21
|
+
|
|
22
|
+
return runtime
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.runtime = runtime
|