@toa.io/boot 1.0.0-alpha.243 → 1.0.0-alpha.246

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.243",
3
+ "version": "1.0.0-alpha.246",
4
4
  "description": "Toa Boot",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -20,14 +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.243",
23
+ "@toa.io/core": "1.0.0-alpha.246",
24
24
  "@toa.io/filesystem": "1.0.0-alpha.225",
25
25
  "@toa.io/generic": "1.0.0-alpha.225",
26
- "@toa.io/norm": "1.0.0-alpha.243",
27
- "@toa.io/schemas": "1.0.0-alpha.225",
26
+ "@toa.io/norm": "1.0.0-alpha.246",
27
+ "@toa.io/schemas": "1.0.0-alpha.246",
28
28
  "clone-deep": "4.0.1",
29
29
  "dotenv": "16.1.1",
30
- "openspan": "1.0.0-alpha.173"
30
+ "openspan": "1.0.0-alpha.246"
31
31
  },
32
- "gitHead": "743e8060d35ca750f70487c04aef9698591c5edd"
32
+ "gitHead": "d6ee2a7246c64a44c50c28fadcfd1e27aaf137cb"
33
33
  }
package/src/component.js CHANGED
@@ -4,11 +4,16 @@ const { Component, Locator, State, entities } = require('@toa.io/core')
4
4
  const schemas = require('@toa.io/schemas')
5
5
 
6
6
  const boot = require('./index')
7
+ const { span } = require('./span')
7
8
 
8
9
  const component = async (manifest) => {
9
- boot.extensions.load(manifest)
10
-
11
10
  const locator = new Locator(manifest.name, manifest.namespace)
11
+
12
+ return span(`component ${locator.id}`, () => create(manifest, locator))
13
+ }
14
+
15
+ const create = async (manifest, locator) => {
16
+ boot.extensions.load(manifest)
12
17
  const storage = boot.storage(manifest)
13
18
  const context = await boot.context(manifest)
14
19
  const emission = boot.emission(manifest.events, locator, context)
@@ -5,30 +5,40 @@ const { Composition } = require('@toa.io/core')
5
5
  const { version } = require('@toa.io/runtime/package.json')
6
6
 
7
7
  const boot = require('./index')
8
+ const { span } = require('./span')
8
9
 
9
10
  async function composition (paths, options) {
10
11
  options = Object.assign({}, options)
11
12
 
12
- const manifests = await Promise.all(paths.map((path) => boot.manifest(path, options)))
13
+ return span('boot composition', async () => {
14
+ const manifests = await span('load manifests',
15
+ async () => await Promise.all(paths.map((path) => boot.manifest(path, options))))
13
16
 
14
- console.info('Starting composition', {
15
- runtime: version,
16
- components: manifests.map((manifest) => manifest.locator.id)
17
- })
17
+ console.info('Starting composition', {
18
+ runtime: version,
19
+ components: manifests.map((manifest) => manifest.locator.id)
20
+ })
21
+
22
+ const tenants = await span('create tenants',
23
+ async () => await Promise.all(manifests.map(boot.extensions.tenants)))
18
24
 
19
- const tenants = await Promise.all(manifests.map(boot.extensions.tenants))
20
- const expositions = await Promise.all(manifests.map(boot.discovery.expose))
21
- const components = await Promise.all(manifests.map(boot.component))
25
+ const expositions = await span('expose discovery',
26
+ async () => await Promise.all(manifests.map(boot.discovery.expose)))
22
27
 
23
- const producers = components.map((component, index) =>
24
- boot.bindings.produce(component, manifests[index].operations))
28
+ const components = await span('create components',
29
+ async () => await Promise.all(manifests.map(boot.component)))
25
30
 
26
- const receivers = await Promise.all(components.map((component, index) =>
27
- boot.receivers(manifests[index], component)))
31
+ const producers = components.map((component, index) =>
32
+ boot.bindings.produce(component, manifests[index].operations))
28
33
 
29
- const composition = new Composition(expositions.flat(), producers.flat(), receivers.flat(), tenants.flat())
34
+ const receivers = await span('create receivers',
35
+ async () => await Promise.all(components.map((component, index) =>
36
+ boot.receivers(manifests[index], component))))
30
37
 
31
- return boot.extensions.manage(composition)
38
+ const composition = new Composition(expositions.flat(), producers.flat(), receivers.flat(), tenants.flat())
39
+
40
+ return boot.extensions.manage(composition)
41
+ })
32
42
  }
33
43
 
34
44
  exports.composition = composition
package/src/emission.js CHANGED
@@ -13,7 +13,7 @@ const emission = (definitions, locator, context) => {
13
13
  const decorator = extensions.emitter(emitter, label)
14
14
  const bridge = boot.bridge.event(definition.bridge, definition.path, label, context)
15
15
 
16
- return new Event(definition, decorator, bridge)
16
+ return new Event({ ...definition, label: `${locator.id}.${label}` }, decorator, bridge)
17
17
  })
18
18
 
19
19
  return new Emission(events)
package/src/manifest.js CHANGED
@@ -1,14 +1,18 @@
1
1
  'use strict'
2
2
 
3
3
  const clone = require('clone-deep')
4
+ const { basename } = require('node:path')
4
5
  const { merge } = require('@toa.io/generic')
5
6
  const { component: load } = require('@toa.io/norm')
6
7
  const { Locator } = require('@toa.io/core')
7
8
 
9
+ const { span } = require('./span')
10
+
8
11
  const manifest = async (path, options = {}) => {
9
12
  options = merge(clone(options), DEFAULTS)
10
13
 
11
- const manifest = await load(path)
14
+ const manifest = await span({ name: `manifest ${basename(path)}`, attributes: { path } },
15
+ async () => await load(path))
12
16
 
13
17
  if (options?.bindings !== undefined) {
14
18
  if ('operations' in manifest) {
package/src/receivers.js CHANGED
@@ -12,13 +12,15 @@ const receivers = async (manifest, component) => {
12
12
  const local = await boot.remote(manifest.locator, manifest)
13
13
 
14
14
  for (const [label, definition] of Object.entries(manifest.receivers)) {
15
+ const locator = Locator.parse(label)
16
+ const source = definition.source ? Locator.parse(definition.source) : locator
17
+ const destination = `${source.id}.${label.split('.').pop()}`
18
+
15
19
  const bridge = definition.bridge !== undefined ? boot.bridge.receiver(definition.bridge, manifest.path, label) : undefined
16
- const receiver = new Receiver(definition, local, bridge)
20
+ const receiver = new Receiver({ ...definition, label, destination }, local, bridge)
17
21
  const decorator = extensions.receiver(receiver, manifest.locator)
18
22
 
19
- const locator = Locator.parse(label)
20
23
  const transport = definition.binding ?? await resolveBinding(locator, label)
21
- const source = definition.source ? Locator.parse(definition.source) : locator
22
24
  const binding = boot.bindings.receive(transport, source, label, manifest.locator.id, decorator)
23
25
 
24
26
  binding.depends(component)
package/src/span.js ADDED
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const { console } = require('openspan')
4
+
5
+ const enabled = process.env.TOA_BOOT_TRACE === '1'
6
+
7
+ /**
8
+ * Creates a span if boot tracing is enabled (TOA_BOOT_TRACE=1), otherwise just runs the task
9
+ *
10
+ * @param {string | object} options
11
+ * @param {() => Promise<any>} task
12
+ * @returns {Promise<any>}
13
+ */
14
+ const span = async (options, task) => enabled ? console.span(options, task) : task()
15
+
16
+ exports.span = span