@toa.io/boot 1.0.0-alpha.9 → 1.0.0-alpha.92

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/boot",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.0-alpha.92",
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,14 @@
20
20
  "test": "echo \"Error: run tests from root\" && exit 1"
21
21
  },
22
22
  "dependencies": {
23
- "@toa.io/core": "1.0.0-alpha.9",
24
- "@toa.io/filesystem": "1.0.0-alpha.9",
25
- "@toa.io/generic": "1.0.0-alpha.9",
26
- "@toa.io/norm": "1.0.0-alpha.9",
27
- "@toa.io/schema": "1.0.0-alpha.9",
23
+ "@toa.io/core": "1.0.0-alpha.92",
24
+ "@toa.io/filesystem": "1.0.0-alpha.63",
25
+ "@toa.io/generic": "1.0.0-alpha.63",
26
+ "@toa.io/norm": "1.0.0-alpha.92",
27
+ "@toa.io/schemas": "1.0.0-alpha.63",
28
28
  "clone-deep": "4.0.1",
29
- "dotenv": "16.1.1"
29
+ "dotenv": "16.1.1",
30
+ "openspan": "1.0.0-alpha.92"
30
31
  },
31
- "gitHead": "017a3fa22e8c60654c240f8e55908773d44d4ed1"
32
+ "gitHead": "975ee5af6194354efb6dd8c646b22a89c4d96f7a"
32
33
  }
@@ -9,18 +9,19 @@ const produce = (component, operations) => group(operations, (factory, endpoints
9
9
  const group = (operations, callback) => {
10
10
  const map = {}
11
11
 
12
- for (const [endpoint, operation] of Object.entries(operations)) {
13
- // noinspection JSUnresolvedVariable
14
- const bindings = global.TOA_INTEGRATION_BINDINGS_LOOP_DISABLED
15
- ? operation.bindings
16
- : [LOOP].concat(operation.bindings)
17
-
18
- for (const binding of bindings) {
19
- if (!map[binding]) map[binding] = []
20
-
21
- map[binding].push(endpoint)
12
+ if (operations !== undefined)
13
+ for (const [endpoint, operation] of Object.entries(operations)) {
14
+ // noinspection JSUnresolvedVariable
15
+ const bindings = global.TOA_INTEGRATION_BINDINGS_LOOP_DISABLED
16
+ ? operation.bindings
17
+ : [LOOP].concat(operation.bindings)
18
+
19
+ for (const binding of bindings) {
20
+ if (!map[binding]) map[binding] = []
21
+
22
+ map[binding].push(endpoint)
23
+ }
22
24
  }
23
- }
24
25
 
25
26
  return Object.entries(map).map(([binding, endpoints]) => callback(factory(binding), endpoints))
26
27
  }
package/src/bridge.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const algorithm = (bridge, path, endpoint, context) => {
4
- const algorithm = resolve(bridge).algorithm(path, endpoint, context)
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
- const cascade = (manifest, endpoint, definition, context) => {
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 { Schema } = require('@toa.io/schema')
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 = new Schema(manifest.entity.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.dependent)
22
+ state = new State(storage, entity, emission, manifest.entity.associated)
28
23
  }
29
24
 
30
- const operations = manifest.operations === undefined
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
@@ -1,6 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ const { console } = require('openspan')
3
4
  const { Composition } = require('@toa.io/core')
5
+ const { version } = require('@toa.io/runtime/package.json')
4
6
 
5
7
  const boot = require('./index')
6
8
 
@@ -8,6 +10,12 @@ async function composition (paths, options) {
8
10
  options = Object.assign({}, options)
9
11
 
10
12
  const manifests = await Promise.all(paths.map((path) => boot.manifest(path, options)))
13
+
14
+ console.info('Starting composition', {
15
+ runtime: version,
16
+ components: manifests.map((manifest) => manifest.locator.id)
17
+ })
18
+
11
19
  const tenants = await Promise.all(manifests.map(boot.extensions.tenants))
12
20
  const expositions = await Promise.all(manifests.map(boot.discovery.expose))
13
21
  const components = await Promise.all(manifests.map(boot.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 { Schema } = require('@toa.io/schema')
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 = new Schema(request, { removeAdditional: true }) // soft inputs
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, error) => {
14
- const reply = Reply.schema(output, error)
15
- const schema = new Schema(reply) // outputs strict
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
  }
@@ -6,9 +6,11 @@ const { resolve } = require('./resolve')
6
6
  * @param {toa.norm.Component} manifest
7
7
  */
8
8
  const load = (manifest) => {
9
- if (manifest.extensions === undefined) return
9
+ if (manifest.extensions === undefined)
10
+ return
10
11
 
11
- for (const name of Object.keys(manifest.extensions)) resolve(name, manifest.path)
12
+ for (const name of Object.keys(manifest.extensions))
13
+ resolve(name, manifest.path)
12
14
  }
13
15
 
14
16
  exports.load = load
@@ -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) decorated = factory.receiver(decorated, locator)
14
+ if (factory.receiver !== undefined)
15
+ decorated = factory.receiver(decorated, locator)
15
16
  }
16
17
 
17
18
  return decorated
@@ -16,7 +16,7 @@ const tenants = (manifest) => {
16
16
 
17
17
  if (factory.tenant === undefined) continue
18
18
 
19
- const tenant = factory.tenant(manifest.locator, declaration)
19
+ const tenant = factory.tenant(manifest.locator, declaration, manifest)
20
20
 
21
21
  tenants.push(tenant)
22
22
  }
package/src/manifest.js CHANGED
@@ -5,9 +5,6 @@ const { merge } = require('@toa.io/generic')
5
5
  const { component: load } = require('@toa.io/norm')
6
6
  const { Locator } = require('@toa.io/core')
7
7
 
8
- /**
9
- * @type {toa.boot.Manifest}
10
- */
11
8
  const manifest = async (path, options = {}) => {
12
9
  options = merge(clone(options), DEFAULTS)
13
10
 
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
- const operation = (manifest, endpoint, definition, context, scope) => {
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: Operation
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, runtime) => {
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(runtime)
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 = undefined) => {
9
- const discovery = await boot.discovery.discovery()
8
+ const remote = async (locator, manifest) => {
9
+ let discovery
10
10
 
11
- if (manifest === undefined) manifest = await discovery.lookup(locator)
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
- remote.depends(discovery)
23
+ if (discovery !== undefined)
24
+ remote.depends(discovery)
21
25
 
22
26
  return remote
23
27
  }
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.Component>
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> }