@toa.io/boot 0.24.0-alpha.9 → 1.0.0-alpha.2

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": "0.24.0-alpha.9",
3
+ "version": "1.0.0-alpha.2",
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,15 @@
20
20
  "test": "echo \"Error: run tests from root\" && exit 1"
21
21
  },
22
22
  "dependencies": {
23
- "@toa.io/core": "0.24.0-alpha.9",
24
- "@toa.io/filesystem": "0.24.0-alpha.9",
25
- "@toa.io/generic": "0.24.0-alpha.9",
26
- "@toa.io/norm": "0.24.0-alpha.9",
27
- "@toa.io/schema": "0.24.0-alpha.9",
28
- "clone-deep": "4.0.1",
23
+ "@toa.io/core": "1.0.0-alpha.2",
24
+ "@toa.io/filesystem": "1.0.0-alpha.2",
25
+ "@toa.io/generic": "1.0.0-alpha.2",
26
+ "@toa.io/norm": "1.0.0-alpha.2",
27
+ "@toa.io/schema": "1.0.0-alpha.2",
29
28
  "dotenv": "16.1.1"
30
29
  },
31
- "gitHead": "aaa343035500526a21666a4416ab76a445ab184d"
30
+ "devDependencies": {
31
+ "clone-deep": "4.0.1"
32
+ },
33
+ "gitHead": "7688e6e980a65c82ac2e459be4e355eebf406cd0"
32
34
  }
package/src/call.js CHANGED
@@ -4,10 +4,10 @@ const { Call, Transmission } = require('@toa.io/core')
4
4
 
5
5
  const boot = require('./index')
6
6
 
7
- const call = (locator, endpoint, definition) => {
7
+ const call = (locator, endpoint, definition, entity) => {
8
8
  const consumers = boot.bindings.consume(locator, endpoint, definition.bindings)
9
9
  const transmission = new Transmission(consumers)
10
- const contract = boot.contract.request(definition)
10
+ const contract = boot.contract.request(definition, entity)
11
11
 
12
12
  return new Call(transmission, contract)
13
13
  }
package/src/component.js CHANGED
@@ -17,12 +17,20 @@ const component = async (manifest) => {
17
17
  const storage = boot.storage(manifest)
18
18
  const context = await boot.context(manifest)
19
19
  const emission = boot.emission(manifest.events, locator, context)
20
- const schema = new Schema(manifest.entity.schema)
21
- const entity = new entities.Factory(schema)
22
- const state = new State(storage, entity, emission, manifest.entity.initialized)
23
20
 
24
- const operations = remap(manifest.operations, (definition, endpoint) =>
25
- boot.operation(manifest, endpoint, definition, context, state))
21
+ let state
22
+
23
+ if (manifest.entity !== undefined) {
24
+ const schema = new Schema(manifest.entity.schema)
25
+ const entity = new entities.Factory(schema)
26
+
27
+ state = new State(storage, entity, emission, manifest.entity.dependent)
28
+ }
29
+
30
+ const operations = manifest.operations === undefined
31
+ ? {}
32
+ : remap(manifest.operations, (definition, endpoint) =>
33
+ boot.operation(manifest, endpoint, definition, context, state))
26
34
 
27
35
  const component = new Component(locator, operations)
28
36
 
package/src/contract.js CHANGED
@@ -3,9 +3,9 @@
3
3
  const { contract: { Request, Reply } } = require('@toa.io/core')
4
4
  const { Schema } = require('@toa.io/schema')
5
5
 
6
- const request = (definition) => {
7
- const request = Request.schema(definition)
8
- const schema = new Schema(request, { removeAdditional: true }) // inputs soft
6
+ const request = (definition, entity) => {
7
+ const request = Request.schema(definition, entity)
8
+ const schema = new Schema(request, { removeAdditional: true }) // soft inputs
9
9
 
10
10
  return new Request(schema)
11
11
  }
package/src/discovery.js CHANGED
@@ -4,14 +4,18 @@ const { Discovery, Exposition } = require('@toa.io/core')
4
4
 
5
5
  const boot = require('./index')
6
6
 
7
- const discovery = async () => {
8
- if (discovery.instance === undefined) {
9
- discovery.instance = new Discovery(lookup)
7
+ let promise
8
+ let instance = null
10
9
 
11
- await discovery.instance.connect()
10
+ const discovery = async () => {
11
+ if (instance === null) {
12
+ instance = new Discovery(lookup)
13
+ promise = instance.connect()
12
14
  }
13
15
 
14
- return discovery.instance
16
+ await promise
17
+
18
+ return instance
15
19
  }
16
20
 
17
21
  const lookup = async (locator) => {
package/src/manifest.js CHANGED
@@ -14,22 +14,21 @@ const manifest = async (path, options = {}) => {
14
14
  const manifest = await load(path)
15
15
 
16
16
  if (options?.bindings !== undefined) {
17
- for (const operation of Object.values(manifest.operations)) {
18
- operation.bindings = options.bindings
19
- }
17
+ if ('operations' in manifest)
18
+ for (const operation of Object.values(manifest.operations))
19
+ operation.bindings = options.bindings
20
20
 
21
21
  const check = (binding) => require(binding).properties?.async === true
22
22
  const asyncBinding = options.bindings.find(check)
23
23
 
24
24
  if (asyncBinding === undefined) throw new Error('Bindings override must contain at least one async binding')
25
25
 
26
- for (const event of Object.values(manifest.events)) event.binding = asyncBinding
26
+ if ('events' in manifest)
27
+ for (const event of Object.values(manifest.events)) event.binding = asyncBinding
27
28
 
28
- if (manifest.receivers) {
29
- for (const receiver of Object.values(manifest.receivers)) {
29
+ if ('receivers' in manifest)
30
+ for (const receiver of Object.values(manifest.receivers))
30
31
  if (receiver.source === undefined) receiver.binding = asyncBinding
31
- }
32
- }
33
32
  }
34
33
 
35
34
  if (manifest.extensions === undefined) manifest.extensions = {}
package/src/operation.js CHANGED
@@ -8,9 +8,12 @@ const operation = (manifest, endpoint, definition, context, scope) => {
8
8
  const cascade = boot.cascade(manifest, endpoint, definition, context)
9
9
  const reply = boot.contract.reply(definition.output, definition.error)
10
10
  const input = definition.input
11
- const request = boot.contract.request({ input })
11
+ const request = boot.contract.request({ input }, manifest.entity)
12
12
  const contracts = { reply, request }
13
- const query = new Query(manifest.entity.schema.properties)
13
+ const query = manifest.entity === undefined
14
+ ? undefined
15
+ : new Query(manifest.entity.schema.properties)
16
+
14
17
  const Type = TYPES[definition.type]
15
18
 
16
19
  return new Type(cascade, scope, contracts, query, definition)
package/src/remote.js CHANGED
@@ -5,18 +5,14 @@ const { remap } = require('@toa.io/generic')
5
5
 
6
6
  const boot = require('./index')
7
7
 
8
- /**
9
- * @param {toa.core.Locator} locator
10
- * @param {toa.norm.Component} manifest
11
- * @returns {Promise<Remote>}
12
- */
13
8
  const remote = async (locator, manifest = undefined) => {
14
9
  const discovery = await boot.discovery.discovery()
15
10
 
16
11
  if (manifest === undefined) manifest = await discovery.lookup(locator)
17
12
 
18
- const calls = remap(manifest.operations,
19
- (definition, endpoint) => boot.call(locator, endpoint, definition))
13
+ const calls = manifest.operations === undefined
14
+ ? {}
15
+ : remap(manifest.operations, (definition, endpoint) => boot.call(locator, endpoint, definition, manifest.entity))
20
16
 
21
17
  const remote = new Remote(locator, calls)
22
18
 
package/src/storage.js CHANGED
@@ -3,16 +3,14 @@
3
3
  const { join } = require('node:path')
4
4
  const extensions = require('./extensions')
5
5
 
6
- /**
7
- * @param {toa.norm.Component} component
8
- * @returns {toa.core.Storage}
9
- */
10
- const storage = (component) => {
11
- const [Factory, properties] = load(component)
6
+ const storage = (manifest) => {
7
+ if (manifest.entity === undefined) return
8
+
9
+ const [Factory, properties] = load(manifest)
12
10
 
13
11
  /** @type {toa.core.storages.Factory} */
14
12
  const factory = new Factory()
15
- const storage = factory.storage(component.locator, properties)
13
+ const storage = factory.storage(manifest.locator, properties)
16
14
 
17
15
  return extensions.storage(storage)
18
16
  }