@toa.io/boot 1.0.0-alpha.4 → 1.0.0-alpha.41

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.4",
3
+ "version": "1.0.0-alpha.41",
4
4
  "description": "Toa Boot",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -20,15 +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.4",
24
- "@toa.io/filesystem": "1.0.0-alpha.4",
25
- "@toa.io/generic": "1.0.0-alpha.4",
26
- "@toa.io/norm": "1.0.0-alpha.4",
27
- "@toa.io/schema": "1.0.0-alpha.4",
23
+ "@toa.io/core": "1.0.0-alpha.41",
24
+ "@toa.io/filesystem": "1.0.0-alpha.41",
25
+ "@toa.io/generic": "1.0.0-alpha.41",
26
+ "@toa.io/norm": "1.0.0-alpha.41",
27
+ "@toa.io/schema": "1.0.0-alpha.41",
28
+ "clone-deep": "4.0.1",
28
29
  "dotenv": "16.1.1"
29
30
  },
30
- "devDependencies": {
31
- "clone-deep": "4.0.1"
32
- },
33
- "gitHead": "80a91c0d9c167484247a91e69a0c0a3c344f90d0"
31
+ "gitHead": "3b338a3f21ff9113cefa75d7789d9267917d41e3"
34
32
  }
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,6 +1,5 @@
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
4
  const { Schema } = require('@toa.io/schema')
6
5
 
@@ -24,14 +23,10 @@ const component = async (manifest) => {
24
23
  const schema = new Schema(manifest.entity.schema)
25
24
  const entity = new entities.Factory(schema)
26
25
 
27
- state = new State(storage, entity, emission, manifest.entity.dependent)
26
+ state = new State(storage, entity, emission, manifest.entity.associated)
28
27
  }
29
28
 
30
- const operations = manifest.operations === undefined
31
- ? {}
32
- : remap(manifest.operations, (definition, endpoint) =>
33
- boot.operation(manifest, endpoint, definition, context, state))
34
-
29
+ const operations = await bootOperations(manifest, context, state)
35
30
  const component = new Component(locator, operations)
36
31
 
37
32
  if (storage) component.depends(storage)
@@ -40,4 +35,16 @@ const component = async (manifest) => {
40
35
  return boot.extensions.component(component)
41
36
  }
42
37
 
38
+ async function bootOperations (manifest, context, state) {
39
+ if (manifest.operations === undefined)
40
+ return {}
41
+
42
+ const operations = {}
43
+
44
+ for (const [endpoint, definition] of Object.entries(manifest.operations))
45
+ operations[endpoint] = await boot.operation(manifest, endpoint, definition, context, state)
46
+
47
+ return operations
48
+ }
49
+
43
50
  exports.component = component
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
- // add `null` manifests
37
- for (const extension of options.extensions) {
38
- if (!(extension in manifest.extensions)) manifest.extensions[extension] = null
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,11 +1,11 @@
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)
@@ -24,7 +24,7 @@ const TYPES = {
24
24
  observation: Observation,
25
25
  assignment: Assignment,
26
26
  computation: Operation,
27
- effect: Operation
27
+ effect: Effect
28
28
  }
29
29
 
30
30
  exports.operation = operation
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