@toa.io/boot 1.0.0-alpha.7 → 1.0.0-alpha.75

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.7",
3
+ "version": "1.0.0-alpha.75",
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.7",
24
- "@toa.io/filesystem": "1.0.0-alpha.7",
25
- "@toa.io/generic": "1.0.0-alpha.7",
26
- "@toa.io/norm": "1.0.0-alpha.7",
27
- "@toa.io/schema": "1.0.0-alpha.7",
23
+ "@toa.io/core": "1.0.0-alpha.75",
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.75",
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.73"
30
31
  },
31
- "gitHead": "4f5ac0bc342d4b7bd469fbe5c74266f050b55c9f"
32
+ "gitHead": "5050fff4a676bbcd7b6f89c1788411701b7ecba6"
32
33
  }
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,37 +5,40 @@ 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
 
14
11
  const manifest = await load(path)
15
12
 
16
13
  if (options?.bindings !== undefined) {
17
- if ('operations' in manifest)
18
- for (const operation of Object.values(manifest.operations))
14
+ if ('operations' in manifest) {
15
+ for (const operation of Object.values(manifest.operations)) {
19
16
  operation.bindings = options.bindings
17
+ }
18
+ }
20
19
 
21
20
  const check = (binding) => require(binding).properties?.async === true
22
21
  const asyncBinding = options.bindings.find(check)
23
22
 
24
23
  if (asyncBinding === undefined) throw new Error('Bindings override must contain at least one async binding')
25
24
 
26
- if ('events' in manifest)
25
+ if ('events' in manifest) {
27
26
  for (const event of Object.values(manifest.events)) event.binding = asyncBinding
27
+ }
28
28
 
29
- if ('receivers' in manifest)
30
- for (const receiver of Object.values(manifest.receivers))
29
+ if ('receivers' in manifest) {
30
+ for (const receiver of Object.values(manifest.receivers)) {
31
31
  if (receiver.source === undefined) receiver.binding = asyncBinding
32
+ }
33
+ }
32
34
  }
33
35
 
34
36
  if (manifest.extensions === undefined) manifest.extensions = {}
35
37
 
36
- // add `null` manifests
37
- for (const extension of options.extensions) {
38
- if (!(extension in manifest.extensions)) manifest.extensions[extension] = null
38
+ if (options.extensions !== undefined) {
39
+ for (const extension of options.extensions) {
40
+ if (!(extension in manifest.extensions)) manifest.extensions[extension] = null
41
+ }
39
42
  }
40
43
 
41
44
  if ('storage' in options && 'entity' in manifest) manifest.entity.storage = options.storage
@@ -45,8 +48,6 @@ const manifest = async (path, options = {}) => {
45
48
  return manifest
46
49
  }
47
50
 
48
- const DEFAULTS = {
49
- extensions: ['@toa.io/extensions.sampling']
50
- }
51
+ const DEFAULTS = {}
51
52
 
52
53
  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
- 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/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 [Factory, properties] = load(manifest)
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, properties)
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
- const pkg = loadPackageJson(component.path, reference)
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.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> }