@toa.io/boot 1.0.0-alpha.0 → 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 +10 -8
- package/src/call.js +2 -2
- package/src/component.js +13 -5
- package/src/contract.js +3 -3
- package/src/discovery.js +9 -5
- package/src/index.js +0 -5
- package/src/manifest.js +7 -8
- package/src/operation.js +5 -2
- package/src/remote.js +3 -7
- package/src/storage.js +5 -7
- package/src/deployment.js +0 -34
- package/src/images.js +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/boot",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
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": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/filesystem": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
26
|
-
"@toa.io/norm": "1.0.0-alpha.
|
|
27
|
-
"@toa.io/schema": "1.0.0-alpha.
|
|
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
|
-
"
|
|
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
|
-
|
|
25
|
-
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
discovery.instance = new Discovery(lookup)
|
|
7
|
+
let promise
|
|
8
|
+
let instance = null
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
const discovery = async () => {
|
|
11
|
+
if (instance === null) {
|
|
12
|
+
instance = new Discovery(lookup)
|
|
13
|
+
promise = instance.connect()
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
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,22 +14,21 @@ const manifest = async (path, options = {}) => {
|
|
|
14
14
|
const manifest = await load(path)
|
|
15
15
|
|
|
16
16
|
if (options?.bindings !== undefined) {
|
|
17
|
-
|
|
18
|
-
operation
|
|
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
|
-
|
|
26
|
+
if ('events' in manifest)
|
|
27
|
+
for (const event of Object.values(manifest.events)) event.binding = asyncBinding
|
|
27
28
|
|
|
28
|
-
if (manifest
|
|
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 =
|
|
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 =
|
|
19
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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(
|
|
13
|
+
const storage = factory.storage(manifest.locator, properties)
|
|
16
14
|
|
|
17
15
|
return extensions.storage(storage)
|
|
18
16
|
}
|
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