@toa.io/boot 1.0.0-alpha.6 → 1.0.0-alpha.61
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 +7 -7
- package/src/bridge.js +3 -2
- package/src/cascade.js +3 -3
- package/src/component.js +16 -13
- package/src/contract.js +6 -6
- package/src/extensions/receiver.js +2 -1
- package/src/manifest.js +15 -11
- package/src/operation.js +5 -4
- package/src/receivers.js +2 -2
- package/src/remote.js +8 -4
- package/src/storage.js +3 -18
- package/types/index.d.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/boot",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.61",
|
|
4
4
|
"description": "Toa Boot",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/filesystem": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
26
|
-
"@toa.io/norm": "1.0.0-alpha.
|
|
27
|
-
"@toa.io/
|
|
23
|
+
"@toa.io/core": "1.0.0-alpha.59",
|
|
24
|
+
"@toa.io/filesystem": "1.0.0-alpha.59",
|
|
25
|
+
"@toa.io/generic": "1.0.0-alpha.59",
|
|
26
|
+
"@toa.io/norm": "1.0.0-alpha.61",
|
|
27
|
+
"@toa.io/schemas": "1.0.0-alpha.61",
|
|
28
28
|
"clone-deep": "4.0.1",
|
|
29
29
|
"dotenv": "16.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "25e32ccba495a1f7197e378a5208cfc1a6b3b8a1"
|
|
32
32
|
}
|
package/src/bridge.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
async function algorithm (bridge, path, endpoint, context) {
|
|
4
|
+
const factory = resolve(bridge)
|
|
5
|
+
const algorithm = await factory.algorithm(path, endpoint, context)
|
|
5
6
|
|
|
6
7
|
algorithm.depends(context)
|
|
7
8
|
|
package/src/cascade.js
CHANGED
|
@@ -4,13 +4,13 @@ const { Cascade } = require('@toa.io/core')
|
|
|
4
4
|
|
|
5
5
|
const boot = require('./index')
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
async function cascade (manifest, endpoint, definition, context) {
|
|
8
8
|
const bridges = []
|
|
9
9
|
|
|
10
10
|
if (definition.forward) endpoint = definition.forward
|
|
11
11
|
|
|
12
12
|
if (definition.bridge) {
|
|
13
|
-
const bridge = boot.bridge.algorithm(definition.bridge, manifest.path, endpoint, context)
|
|
13
|
+
const bridge = await boot.bridge.algorithm(definition.bridge, manifest.path, endpoint, context)
|
|
14
14
|
|
|
15
15
|
bridges.unshift(bridge)
|
|
16
16
|
}
|
|
@@ -22,7 +22,7 @@ const cascade = (manifest, endpoint, definition, context) => {
|
|
|
22
22
|
|
|
23
23
|
if (operation === undefined) continue
|
|
24
24
|
|
|
25
|
-
const bridge = boot.bridge.algorithm(operation.bridge, prototype.path, endpoint, context)
|
|
25
|
+
const bridge = await boot.bridge.algorithm(operation.bridge, prototype.path, endpoint, context)
|
|
26
26
|
|
|
27
27
|
bridges.unshift(bridge)
|
|
28
28
|
}
|
package/src/component.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { remap } = require('@toa.io/generic')
|
|
4
3
|
const { Component, Locator, State, entities } = require('@toa.io/core')
|
|
5
|
-
const
|
|
4
|
+
const schemas = require('@toa.io/schemas')
|
|
6
5
|
|
|
7
6
|
const boot = require('./index')
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* @param {toa.norm.Component} manifest
|
|
11
|
-
* @returns {Promise<toa.core.Component>}
|
|
12
|
-
*/
|
|
13
8
|
const component = async (manifest) => {
|
|
14
9
|
boot.extensions.load(manifest)
|
|
15
10
|
|
|
@@ -21,17 +16,13 @@ const component = async (manifest) => {
|
|
|
21
16
|
let state
|
|
22
17
|
|
|
23
18
|
if (manifest.entity !== undefined) {
|
|
24
|
-
const schema =
|
|
19
|
+
const schema = schemas.schema(manifest.entity.schema)
|
|
25
20
|
const entity = new entities.Factory(schema)
|
|
26
21
|
|
|
27
|
-
state = new State(storage, entity, emission, manifest.entity.
|
|
22
|
+
state = new State(storage, entity, emission, manifest.entity.associated)
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
const operations = manifest
|
|
31
|
-
? {}
|
|
32
|
-
: remap(manifest.operations, (definition, endpoint) =>
|
|
33
|
-
boot.operation(manifest, endpoint, definition, context, state))
|
|
34
|
-
|
|
25
|
+
const operations = await bootOperations(manifest, context, state)
|
|
35
26
|
const component = new Component(locator, operations)
|
|
36
27
|
|
|
37
28
|
if (storage) component.depends(storage)
|
|
@@ -40,4 +31,16 @@ const component = async (manifest) => {
|
|
|
40
31
|
return boot.extensions.component(component)
|
|
41
32
|
}
|
|
42
33
|
|
|
34
|
+
async function bootOperations (manifest, context, state) {
|
|
35
|
+
if (manifest.operations === undefined)
|
|
36
|
+
return {}
|
|
37
|
+
|
|
38
|
+
const operations = {}
|
|
39
|
+
|
|
40
|
+
for (const [endpoint, definition] of Object.entries(manifest.operations))
|
|
41
|
+
operations[endpoint] = await boot.operation(manifest, endpoint, definition, context, state)
|
|
42
|
+
|
|
43
|
+
return operations
|
|
44
|
+
}
|
|
45
|
+
|
|
43
46
|
exports.component = component
|
package/src/contract.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { contract: { Request, Reply } } = require('@toa.io/core')
|
|
4
|
-
const
|
|
4
|
+
const schemas = require('@toa.io/schemas')
|
|
5
5
|
|
|
6
6
|
const request = (definition, entity) => {
|
|
7
7
|
const request = Request.schema(definition, entity)
|
|
8
|
-
const schema =
|
|
8
|
+
const schema = schemas.schema(request, { removeAdditional: true })
|
|
9
9
|
|
|
10
|
-
return new Request(schema)
|
|
10
|
+
return new Request(schema, definition)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const reply = (output,
|
|
14
|
-
const reply = Reply.schema(output,
|
|
15
|
-
const schema =
|
|
13
|
+
const reply = (output, errors) => {
|
|
14
|
+
const reply = Reply.schema(output, errors)
|
|
15
|
+
const schema = schemas.schema(reply)
|
|
16
16
|
|
|
17
17
|
return new Reply(schema)
|
|
18
18
|
}
|
|
@@ -11,7 +11,8 @@ const receiver = (receiver, locator) => {
|
|
|
11
11
|
let decorated = receiver
|
|
12
12
|
|
|
13
13
|
for (const factory of Object.values(instances)) {
|
|
14
|
-
if (factory.receiver !== undefined)
|
|
14
|
+
if (factory.receiver !== undefined)
|
|
15
|
+
decorated = factory.receiver(decorated, locator)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
return decorated
|
package/src/manifest.js
CHANGED
|
@@ -14,28 +14,34 @@ const manifest = async (path, options = {}) => {
|
|
|
14
14
|
const manifest = await load(path)
|
|
15
15
|
|
|
16
16
|
if (options?.bindings !== undefined) {
|
|
17
|
-
if ('operations' in manifest)
|
|
18
|
-
for (const operation of Object.values(manifest.operations))
|
|
17
|
+
if ('operations' in manifest) {
|
|
18
|
+
for (const operation of Object.values(manifest.operations)) {
|
|
19
19
|
operation.bindings = options.bindings
|
|
20
|
+
}
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
const check = (binding) => require(binding).properties?.async === true
|
|
22
24
|
const asyncBinding = options.bindings.find(check)
|
|
23
25
|
|
|
24
26
|
if (asyncBinding === undefined) throw new Error('Bindings override must contain at least one async binding')
|
|
25
27
|
|
|
26
|
-
if ('events' in manifest)
|
|
28
|
+
if ('events' in manifest) {
|
|
27
29
|
for (const event of Object.values(manifest.events)) event.binding = asyncBinding
|
|
30
|
+
}
|
|
28
31
|
|
|
29
|
-
if ('receivers' in manifest)
|
|
30
|
-
for (const receiver of Object.values(manifest.receivers))
|
|
32
|
+
if ('receivers' in manifest) {
|
|
33
|
+
for (const receiver of Object.values(manifest.receivers)) {
|
|
31
34
|
if (receiver.source === undefined) receiver.binding = asyncBinding
|
|
35
|
+
}
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
if (manifest.extensions === undefined) manifest.extensions = {}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if (options.extensions !== undefined) {
|
|
42
|
+
for (const extension of options.extensions) {
|
|
43
|
+
if (!(extension in manifest.extensions)) manifest.extensions[extension] = null
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
if ('storage' in options && 'entity' in manifest) manifest.entity.storage = options.storage
|
|
@@ -45,8 +51,6 @@ const manifest = async (path, options = {}) => {
|
|
|
45
51
|
return manifest
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
const DEFAULTS = {
|
|
49
|
-
extensions: ['@toa.io/extensions.sampling']
|
|
50
|
-
}
|
|
54
|
+
const DEFAULTS = {}
|
|
51
55
|
|
|
52
56
|
exports.manifest = manifest
|
package/src/operation.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { Transition, Observation, Assignment, Operation, Query } = require('@toa.io/core')
|
|
3
|
+
const { Transition, Observation, Assignment, Operation, Query, Effect } = require('@toa.io/core')
|
|
4
4
|
|
|
5
5
|
const boot = require('./index')
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const cascade = boot.cascade(manifest, endpoint, definition, context)
|
|
7
|
+
async function operation (manifest, endpoint, definition, context, scope) {
|
|
8
|
+
const cascade = await boot.cascade(manifest, endpoint, definition, context)
|
|
9
9
|
const reply = boot.contract.reply(definition.output, definition.error)
|
|
10
10
|
const input = definition.input
|
|
11
11
|
const request = boot.contract.request({ input }, manifest.entity)
|
|
12
12
|
const contracts = { reply, request }
|
|
13
|
+
|
|
13
14
|
const query = manifest.entity === undefined
|
|
14
15
|
? undefined
|
|
15
16
|
: new Query(manifest.entity.schema.properties)
|
|
@@ -24,7 +25,7 @@ const TYPES = {
|
|
|
24
25
|
observation: Observation,
|
|
25
26
|
assignment: Assignment,
|
|
26
27
|
computation: Operation,
|
|
27
|
-
effect:
|
|
28
|
+
effect: Effect
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
exports.operation = operation
|
package/src/receivers.js
CHANGED
|
@@ -5,7 +5,7 @@ const { Receiver, Locator } = require('@toa.io/core')
|
|
|
5
5
|
const boot = require('./index')
|
|
6
6
|
const extensions = require('./extensions')
|
|
7
7
|
|
|
8
|
-
const receivers = async (manifest,
|
|
8
|
+
const receivers = async (manifest, component) => {
|
|
9
9
|
if (manifest.receivers === undefined) return []
|
|
10
10
|
|
|
11
11
|
const receivers = []
|
|
@@ -21,7 +21,7 @@ const receivers = async (manifest, runtime) => {
|
|
|
21
21
|
const source = definition.source ? Locator.parse(definition.source) : locator
|
|
22
22
|
const binding = boot.bindings.receive(transport, source, label, manifest.locator.id, decorator)
|
|
23
23
|
|
|
24
|
-
binding.depends(
|
|
24
|
+
binding.depends(component)
|
|
25
25
|
receivers.push(binding)
|
|
26
26
|
}
|
|
27
27
|
|
package/src/remote.js
CHANGED
|
@@ -5,10 +5,13 @@ const { remap } = require('@toa.io/generic')
|
|
|
5
5
|
|
|
6
6
|
const boot = require('./index')
|
|
7
7
|
|
|
8
|
-
const remote = async (locator, manifest
|
|
9
|
-
|
|
8
|
+
const remote = async (locator, manifest) => {
|
|
9
|
+
let discovery
|
|
10
10
|
|
|
11
|
-
if (manifest === undefined)
|
|
11
|
+
if (manifest === undefined) {
|
|
12
|
+
discovery = await boot.discovery.discovery(locator)
|
|
13
|
+
manifest = await discovery.lookup(locator)
|
|
14
|
+
}
|
|
12
15
|
|
|
13
16
|
const calls = manifest.operations === undefined
|
|
14
17
|
? {}
|
|
@@ -17,7 +20,8 @@ const remote = async (locator, manifest = undefined) => {
|
|
|
17
20
|
const remote = new Remote(locator, calls)
|
|
18
21
|
|
|
19
22
|
// ensure discovery shutdown
|
|
20
|
-
|
|
23
|
+
if (discovery !== undefined)
|
|
24
|
+
remote.depends(discovery)
|
|
21
25
|
|
|
22
26
|
return remote
|
|
23
27
|
}
|
package/src/storage.js
CHANGED
|
@@ -6,11 +6,11 @@ const extensions = require('./extensions')
|
|
|
6
6
|
const storage = (manifest) => {
|
|
7
7
|
if (manifest.entity === undefined) return
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const Factory = load(manifest)
|
|
10
10
|
|
|
11
11
|
/** @type {toa.core.storages.Factory} */
|
|
12
12
|
const factory = new Factory()
|
|
13
|
-
const storage = factory.storage(manifest.locator,
|
|
13
|
+
const storage = factory.storage(manifest.locator, manifest.entity)
|
|
14
14
|
|
|
15
15
|
return extensions.storage(storage)
|
|
16
16
|
}
|
|
@@ -20,22 +20,7 @@ function load (component) {
|
|
|
20
20
|
const path = require.resolve(reference, { paths: [component.path, __dirname] })
|
|
21
21
|
const { Factory } = require(path)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
const properties = pkg === null ? null : component.properties?.[pkg.name]
|
|
25
|
-
|
|
26
|
-
return [Factory, properties]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function loadPackageJson (root, reference) {
|
|
30
|
-
const packageJson = join(reference, 'package.json')
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const path = require.resolve(packageJson, { paths: [root, __dirname] })
|
|
34
|
-
|
|
35
|
-
return require(path)
|
|
36
|
-
} catch (e) {
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
23
|
+
return Factory
|
|
39
24
|
}
|
|
40
25
|
|
|
41
26
|
exports.storage = storage
|
package/types/index.d.ts
CHANGED
|
@@ -5,17 +5,17 @@ export * as bindings from './bindings'
|
|
|
5
5
|
|
|
6
6
|
export async function composition (paths: string[], options?: composition.Options): Promise<core.Connector>
|
|
7
7
|
|
|
8
|
-
export async function remote (locator: core.Locator): Promise<core.
|
|
8
|
+
export async function remote (locator: core.Locator): Promise<core.Remote>
|
|
9
9
|
|
|
10
10
|
export async function receive<T = any> (
|
|
11
11
|
label: string,
|
|
12
|
-
receiver: Receiver
|
|
12
|
+
receiver: Receiver
|
|
13
13
|
): Promise<core.Connector>
|
|
14
14
|
|
|
15
15
|
export async function receive<T = any> (
|
|
16
16
|
label: string,
|
|
17
17
|
group: string | undefined,
|
|
18
|
-
receiver: Receiver
|
|
18
|
+
receiver: Receiver
|
|
19
19
|
): Promise<core.Connector>
|
|
20
20
|
|
|
21
21
|
type Receiver = { receive: (message: core.Message<T>) => void | Promise<void> }
|