@toa.io/boot 1.0.0-alpha.0 → 1.0.0-alpha.11

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.0",
3
+ "version": "1.0.0-alpha.11",
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,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.0",
24
- "@toa.io/filesystem": "1.0.0-alpha.0",
25
- "@toa.io/generic": "1.0.0-alpha.0",
26
- "@toa.io/norm": "1.0.0-alpha.0",
27
- "@toa.io/schema": "1.0.0-alpha.0",
23
+ "@toa.io/core": "1.0.0-alpha.11",
24
+ "@toa.io/filesystem": "1.0.0-alpha.11",
25
+ "@toa.io/generic": "1.0.0-alpha.11",
26
+ "@toa.io/norm": "1.0.0-alpha.11",
27
+ "@toa.io/schema": "1.0.0-alpha.11",
28
28
  "clone-deep": "4.0.1",
29
29
  "dotenv": "16.1.1"
30
30
  },
31
- "gitHead": "06c64546f6292cc07c52f74b31415101037f7616"
31
+ "gitHead": "e343ac81eef12957cfa5e520119b1276b8ec0ad2"
32
32
  }
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/index.js CHANGED
@@ -7,10 +7,8 @@ const { cascade } = require('./cascade')
7
7
  const { component } = require('./component')
8
8
  const { composition } = require('./composition')
9
9
  const { context } = require('./context')
10
- const { deployment, registry } = require('./deployment')
11
10
  const { emission } = require('./emission')
12
11
  const { exposition } = require('./exposition')
13
- const { images } = require('./images')
14
12
  const { manifest } = require('./manifest')
15
13
  const { operation } = require('./operation')
16
14
  const { receivers, receive } = require('./receivers')
@@ -28,14 +26,11 @@ exports.cascade = cascade
28
26
  exports.component = component
29
27
  exports.composition = composition
30
28
  exports.context = context
31
- exports.deployment = deployment
32
29
  exports.emission = emission
33
30
  exports.exposition = exposition
34
- exports.images = images
35
31
  exports.manifest = manifest
36
32
  exports.operation = operation
37
33
  exports.receivers = receivers
38
34
  exports.receive = receive
39
- exports.registry = registry
40
35
  exports.remote = remote
41
36
  exports.storage = storage
package/src/manifest.js CHANGED
@@ -14,8 +14,10 @@ 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
17
+ if ('operations' in manifest) {
18
+ for (const operation of Object.values(manifest.operations)) {
19
+ operation.bindings = options.bindings
20
+ }
19
21
  }
20
22
 
21
23
  const check = (binding) => require(binding).properties?.async === true
@@ -23,9 +25,11 @@ const manifest = async (path, options = {}) => {
23
25
 
24
26
  if (asyncBinding === undefined) throw new Error('Bindings override must contain at least one async binding')
25
27
 
26
- for (const event of Object.values(manifest.events)) event.binding = asyncBinding
28
+ if ('events' in manifest) {
29
+ for (const event of Object.values(manifest.events)) event.binding = asyncBinding
30
+ }
27
31
 
28
- if (manifest.receivers) {
32
+ if ('receivers' in manifest) {
29
33
  for (const receiver of Object.values(manifest.receivers)) {
30
34
  if (receiver.source === undefined) receiver.binding = asyncBinding
31
35
  }
@@ -34,9 +38,10 @@ const manifest = async (path, options = {}) => {
34
38
 
35
39
  if (manifest.extensions === undefined) manifest.extensions = {}
36
40
 
37
- // add `null` manifests
38
- for (const extension of options.extensions) {
39
- 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
+ }
40
45
  }
41
46
 
42
47
  if ('storage' in options && 'entity' in manifest) manifest.entity.storage = options.storage
@@ -46,8 +51,6 @@ const manifest = async (path, options = {}) => {
46
51
  return manifest
47
52
  }
48
53
 
49
- const DEFAULTS = {
50
- extensions: ['@toa.io/extensions.sampling']
51
- }
54
+ const DEFAULTS = {}
52
55
 
53
56
  exports.manifest = manifest
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 = 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, manifest.entity)
16
14
 
17
15
  return extensions.storage(storage)
18
16
  }
@@ -22,22 +20,7 @@ function load (component) {
22
20
  const path = require.resolve(reference, { paths: [component.path, __dirname] })
23
21
  const { Factory } = require(path)
24
22
 
25
- const pkg = loadPackageJson(component.path, reference)
26
- const properties = pkg === null ? null : component.properties?.[pkg.name]
27
-
28
- return [Factory, properties]
29
- }
30
-
31
- function loadPackageJson (root, reference) {
32
- const packageJson = join(reference, 'package.json')
33
-
34
- try {
35
- const path = require.resolve(packageJson, { paths: [root, __dirname] })
36
-
37
- return require(path)
38
- } catch (e) {
39
- return null
40
- }
23
+ return Factory
41
24
  }
42
25
 
43
26
  exports.storage = storage
@@ -1,3 +1,3 @@
1
1
  import type { bindings } from '@toa.io/core'
2
2
 
3
- export function broadcast (name: string, group?: string, binding?: string): bindings.Broadcast
3
+ export function broadcast<T> (name: string, group?: string, binding?: string): bindings.Broadcast<T>
package/src/deployment.js DELETED
@@ -1,34 +0,0 @@
1
- 'use strict'
2
-
3
- const { deployment: { Factory } } = require('@toa.io/operations')
4
- const { context: load } = require('@toa.io/norm')
5
-
6
- /**
7
- * @param {string} path
8
- * @param {string} [environment]
9
- * @returns {Promise<toa.deployment.Operator>}
10
- */
11
- const deployment = async (path, environment) => {
12
- const factory = await getFactory(path, environment)
13
-
14
- return factory.operator()
15
- }
16
-
17
- /**
18
- * @param {string} path
19
- * @returns {Promise<toa.deployment.Registry>}
20
- */
21
- const registry = async (path) => {
22
- const factory = await getFactory(path)
23
-
24
- return factory.registry()
25
- }
26
-
27
- async function getFactory (path, environment) {
28
- const context = await load(path, environment)
29
-
30
- return new Factory(context)
31
- }
32
-
33
- exports.deployment = deployment
34
- exports.registry = registry
package/src/images.js DELETED
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- const { Images } = require('@toa.io/operations')
4
- const { context: load } = require('@toa.io/norm')
5
-
6
- const images = async (path) => {
7
- const context = await load(path)
8
-
9
- return new Images(context)
10
- }
11
-
12
- exports.images = images