@toa.io/boot 1.0.0-alpha.31 → 1.0.0-alpha.311
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/CHANGELOG.md +224 -0
- package/package.json +11 -8
- package/src/atom.js +41 -0
- package/src/atomicity.js +11 -0
- package/src/bindings/broadcast.js +3 -6
- package/src/bindings/constants.js +1 -3
- package/src/bindings/consume.js +8 -8
- package/src/bindings/emit.js +3 -6
- package/src/bindings/factory.js +5 -9
- package/src/bindings/inbound.js +11 -0
- package/src/bindings/index.js +7 -13
- package/src/bindings/outbound.js +10 -0
- package/src/bindings/produce.js +40 -18
- package/src/bindings/receive.js +3 -6
- package/src/bridge.js +22 -16
- package/src/call.js +22 -9
- package/src/cascade.js +16 -10
- package/src/component.js +94 -32
- package/src/composition.js +106 -15
- package/src/context.js +7 -8
- package/src/contract.js +11 -12
- package/src/emission.js +21 -14
- package/src/env.js +19 -12
- package/src/events.js +27 -0
- package/src/extensions/aspects.js +4 -8
- package/src/extensions/component.js +4 -8
- package/src/extensions/context.js +4 -8
- package/src/extensions/destinations.js +27 -0
- package/src/extensions/emitter.js +7 -9
- package/src/extensions/index.js +10 -19
- package/src/extensions/instances.js +2 -4
- package/src/extensions/load.js +7 -7
- package/src/extensions/manage.js +15 -0
- package/src/extensions/receiver.js +5 -9
- package/src/extensions/resolve.js +36 -11
- package/src/extensions/storage.js +6 -9
- package/src/extensions/tenants.js +5 -9
- package/src/guards.js +20 -0
- package/src/host.js +29 -0
- package/src/inbox.js +10 -0
- package/src/index.js +27 -34
- package/src/manifest.js +78 -36
- package/src/manifest.test.js +85 -8
- package/src/map.js +98 -0
- package/src/operation.js +25 -13
- package/src/outbox.js +22 -0
- package/src/rc.js +5 -0
- package/src/receivers.js +53 -23
- package/src/remote.js +37 -22
- package/src/span.js +19 -0
- package/src/storage.js +50 -16
- package/src/storage.test.js +57 -0
- package/src/workload.js +281 -0
- package/src/workload.test.js +321 -0
- package/types/bindings.d.ts +6 -2
- package/types/index.d.ts +62 -10
- package/types/manifest.d.ts +5 -4
- package/src/discovery.js +0 -43
- package/src/exposition.js +0 -17
package/src/component.js
CHANGED
|
@@ -1,48 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Component,
|
|
6
|
-
Locator,
|
|
7
|
-
State,
|
|
8
|
-
entities
|
|
9
|
-
} = require('@toa.io/core')
|
|
10
|
-
const { Schema } = require('@toa.io/schema')
|
|
11
|
-
|
|
12
|
-
const boot = require('./index')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {toa.norm.Component} manifest
|
|
16
|
-
* @returns {Promise<toa.core.Component>}
|
|
17
|
-
*/
|
|
18
|
-
const component = async (manifest) => {
|
|
19
|
-
boot.extensions.load(manifest)
|
|
1
|
+
import { Component, Locator, State, entities } from '@toa.io/core'
|
|
2
|
+
import { entity as declaration } from '@toa.io/norm'
|
|
3
|
+
import { schema as compileSchema } from '@toa.io/schemas'
|
|
4
|
+
import { environment } from '@toa.io/generic'
|
|
20
5
|
|
|
6
|
+
import * as boot from './index.js'
|
|
7
|
+
import { span } from './span.js'
|
|
8
|
+
|
|
9
|
+
export const component = async (manifest) => {
|
|
21
10
|
const locator = new Locator(manifest.name, manifest.namespace)
|
|
22
|
-
|
|
11
|
+
|
|
12
|
+
return span(`component ${locator.id}`, () => create(manifest, locator))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const create = async (manifest, locator) => {
|
|
16
|
+
// what a test set after this package loaded goes to the store now, before a module of the
|
|
17
|
+
// component is imported: nothing of it is left in `process.env` for that module to read
|
|
18
|
+
environment.absorb()
|
|
19
|
+
|
|
20
|
+
// the suffix is what it is now, `.env` having been read: whatever this process sets for the
|
|
21
|
+
// processes it starts later does not rename what it has
|
|
22
|
+
environment.suffix()
|
|
23
|
+
|
|
24
|
+
await boot.extensions.load(manifest)
|
|
25
|
+
|
|
26
|
+
// the storage is told whether there will be an outbox, so what it publishes to comes first:
|
|
27
|
+
// its own events, and whatever an extension adds
|
|
28
|
+
const events = boot.events(manifest)
|
|
29
|
+
const destinations = await boot.extensions.destinations(manifest)
|
|
30
|
+
const storage = await boot.storage(
|
|
31
|
+
manifest,
|
|
32
|
+
events !== undefined || destinations.length > 0,
|
|
33
|
+
boot.inbox(manifest)
|
|
34
|
+
)
|
|
23
35
|
const context = await boot.context(manifest)
|
|
24
|
-
const emission = boot.emission(
|
|
36
|
+
const emission = await boot.emission(events, locator, context)
|
|
37
|
+
const outbox = boot.outbox(manifest, storage, emission, destinations)
|
|
25
38
|
|
|
26
39
|
let state
|
|
27
40
|
|
|
28
41
|
if (manifest.entity !== undefined) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
42
|
+
const schemas = compile(manifest.entity)
|
|
43
|
+
const guards = await boot.guards(manifest, context)
|
|
44
|
+
const blank = manifest.entity.blank ?? {}
|
|
31
45
|
|
|
32
|
-
|
|
33
|
-
|
|
46
|
+
// fitted here rather than where the first record is written, so a component that
|
|
47
|
+
// declares a blank nothing can hold does not boot
|
|
48
|
+
const error = schemas.changeset.fit(blank)
|
|
49
|
+
|
|
50
|
+
if (error !== null)
|
|
51
|
+
throw new Error(`Component '${locator.id}' entity blank: ${error.message}`)
|
|
34
52
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
state = new State(
|
|
54
|
+
storage,
|
|
55
|
+
new entities.Factory(schemas, blank, guards),
|
|
56
|
+
outbox,
|
|
57
|
+
manifest.entity.associated
|
|
58
|
+
)
|
|
59
|
+
}
|
|
39
60
|
|
|
61
|
+
const phases = await boot.rc(manifest, context)
|
|
62
|
+
const operations = await bootOperations(manifest, context, state, phases?.preflight)
|
|
40
63
|
const component = new Component(locator, operations)
|
|
41
64
|
|
|
42
65
|
if (storage) component.depends(storage)
|
|
43
|
-
if (emission) component.depends(emission)
|
|
44
66
|
|
|
45
|
-
|
|
67
|
+
// the outbox owns the emission and the storage, so it drains before either goes down
|
|
68
|
+
if (outbox) component.depends(outbox)
|
|
69
|
+
else if (emission) component.depends(emission)
|
|
70
|
+
|
|
71
|
+
const decorated = boot.extensions.component(component)
|
|
72
|
+
|
|
73
|
+
if (phases?.settle !== undefined) decorated.settle = phases.settle
|
|
74
|
+
|
|
75
|
+
if (phases?.ready !== undefined) decorated.ready = phases.ready
|
|
76
|
+
|
|
77
|
+
// a dependency closes after its dependant, so the component is already closed
|
|
78
|
+
// when the RC releases what it opened
|
|
79
|
+
if (phases?.dispose !== undefined) decorated.depends(phases.dispose)
|
|
80
|
+
|
|
81
|
+
// a dependency of the component, so the walk that stops a tree reaches it there
|
|
82
|
+
if (phases?.quiescence !== undefined) decorated.depends(phases.quiescence)
|
|
83
|
+
|
|
84
|
+
return decorated
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function bootOperations(manifest, context, state, preflight) {
|
|
88
|
+
if (manifest.operations === undefined) return {}
|
|
89
|
+
|
|
90
|
+
const entries = Object.entries(manifest.operations)
|
|
91
|
+
|
|
92
|
+
// each one loads its algorithm from disk and compiles its contracts
|
|
93
|
+
const booted = await Promise.all(
|
|
94
|
+
entries.map(([endpoint, definition]) =>
|
|
95
|
+
boot.operation(manifest, endpoint, definition, context, state, preflight)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
const operations = {}
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < entries.length; i++) operations[entries[i][0]] = booted[i]
|
|
102
|
+
|
|
103
|
+
return operations
|
|
46
104
|
}
|
|
47
105
|
|
|
48
|
-
|
|
106
|
+
/** What a stored record must fit, and what a changeset may. */
|
|
107
|
+
const compile = (entity) => ({
|
|
108
|
+
entity: compileSchema(declaration.schema(entity)),
|
|
109
|
+
changeset: compileSchema(declaration.changeset(entity))
|
|
110
|
+
})
|
package/src/composition.js
CHANGED
|
@@ -1,24 +1,115 @@
|
|
|
1
|
-
|
|
1
|
+
import { console } from 'openspan'
|
|
2
|
+
import { Composition } from '@toa.io/core'
|
|
3
|
+
import { version } from '@toa.io/definitions'
|
|
4
|
+
import { environment } from '@toa.io/generic'
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
import * as boot from './index.js'
|
|
7
|
+
import { span } from './span.js'
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
export async function composition(paths, options) {
|
|
10
|
+
// what a test set after this package loaded goes to the store now, before a module of a
|
|
11
|
+
// component is imported: nothing of it is left in `process.env` for that module to read
|
|
12
|
+
environment.absorb()
|
|
13
|
+
|
|
14
|
+
// the suffix is what it is now, `.env` having been read: whatever this process sets for the
|
|
15
|
+
// processes it starts later does not rename what it has
|
|
16
|
+
environment.suffix()
|
|
6
17
|
|
|
7
|
-
async function composition (paths, options) {
|
|
8
18
|
options = Object.assign({}, options)
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
return span('boot composition', async () => {
|
|
21
|
+
const manifests = await span(
|
|
22
|
+
'load manifests',
|
|
23
|
+
async () => await Promise.all(paths.map((path) => boot.manifest(path, options)))
|
|
24
|
+
)
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
console.info('Starting composition', {
|
|
27
|
+
runtime: version,
|
|
28
|
+
components: manifests.map((manifest) => manifest.locator.id)
|
|
29
|
+
})
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
boot.
|
|
31
|
+
// what this process composes it knows, and the map it was given says the same
|
|
32
|
+
await boot.map.compose(manifests)
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
const tenants = await span(
|
|
35
|
+
'create tenants',
|
|
36
|
+
async () => await Promise.all(manifests.map(boot.extensions.tenants))
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const components = await span(
|
|
40
|
+
'create components',
|
|
41
|
+
async () => await Promise.all(manifests.map(boot.component))
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
const groups = await Promise.all(
|
|
45
|
+
components.map(
|
|
46
|
+
async (component, index) =>
|
|
47
|
+
await boot.bindings.produce(component, manifests[index].operations)
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const receivers = await span(
|
|
52
|
+
'create receivers',
|
|
53
|
+
async () =>
|
|
54
|
+
await Promise.all(
|
|
55
|
+
components.map((component, index) =>
|
|
56
|
+
boot.receivers(manifests[index], component)
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const producers = []
|
|
62
|
+
const settles = []
|
|
63
|
+
const readies = []
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < components.length; i++) {
|
|
66
|
+
const { local, other } = groups[i]
|
|
67
|
+
const { settle, ready } = components[i]
|
|
68
|
+
const serving = [...local, ...other]
|
|
69
|
+
|
|
70
|
+
producers.push(...serving)
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* A receiver turns an event into a call to an operation of its own component, and
|
|
74
|
+
* that call is served by these — the loop producer first, the broker's if it has
|
|
75
|
+
* already gone. They are siblings under the composition otherwise, so a receiver
|
|
76
|
+
* still draining a delivery would be left calling something already torn down.
|
|
77
|
+
*/
|
|
78
|
+
// one at a time: `depends` given an array links the group it makes rather than its
|
|
79
|
+
// members, and it is the members whose teardown has to wait for this one
|
|
80
|
+
for (const receiver of receivers[i])
|
|
81
|
+
for (const producer of serving) receiver.depends(producer)
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* The broker producers serve the stateful endpoints under the process's name, and the
|
|
85
|
+
* name is held once they are open — before then a call to it is refused. `ready` is where
|
|
86
|
+
* a component hands the name out, so it waits for every producer and receiver of its own.
|
|
87
|
+
*/
|
|
88
|
+
if (ready !== undefined) {
|
|
89
|
+
for (const producer of serving) ready.depends(producer)
|
|
23
90
|
|
|
24
|
-
|
|
91
|
+
for (const receiver of receivers[i]) ready.depends(receiver)
|
|
92
|
+
|
|
93
|
+
readies.push(ready)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (settle === undefined) continue
|
|
97
|
+
|
|
98
|
+
if (local.length > 0) settle.depends(local)
|
|
99
|
+
|
|
100
|
+
for (const producer of other) producer.depends(settle)
|
|
101
|
+
|
|
102
|
+
for (const receiver of receivers[i]) receiver.depends(settle)
|
|
103
|
+
|
|
104
|
+
settles.push(settle)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const composition = new Composition(
|
|
108
|
+
producers.concat(settles, readies),
|
|
109
|
+
receivers.flat(),
|
|
110
|
+
tenants.flat()
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
return boot.extensions.manage(composition)
|
|
114
|
+
})
|
|
115
|
+
}
|
package/src/context.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { Context, Locator } from '@toa.io/core'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as boot from './index.js'
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const context = async (manifest) => {
|
|
8
|
-
const local = await boot.remote(manifest.locator, manifest)
|
|
5
|
+
export const context = async (manifest) => {
|
|
6
|
+
const local = await boot.remote(manifest.locator, undefined, { contract: manifest })
|
|
9
7
|
const aspects = boot.extensions.aspects(manifest)
|
|
10
8
|
|
|
9
|
+
// a system aspect: it is there in every component, declared by none of them
|
|
10
|
+
aspects.push(boot.atom(manifest.locator.id))
|
|
11
|
+
|
|
11
12
|
const lookup = async (namespace, name) => {
|
|
12
13
|
const locator = new Locator(name, namespace)
|
|
13
14
|
const remote = await boot.remote(locator)
|
|
@@ -21,5 +22,3 @@ const context = async (manifest) => {
|
|
|
21
22
|
|
|
22
23
|
return boot.extensions.context(context)
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
exports.context = context
|
package/src/contract.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { contract } from '@toa.io/core'
|
|
2
|
+
import * as schemas from '@toa.io/schemas'
|
|
2
3
|
|
|
3
|
-
const {
|
|
4
|
-
const { Schema } = require('@toa.io/schema')
|
|
4
|
+
const { Request, Reply } = contract
|
|
5
5
|
|
|
6
|
-
const request = (definition, entity) => {
|
|
6
|
+
export const request = (definition, entity) => {
|
|
7
7
|
const request = Request.schema(definition, entity)
|
|
8
|
-
const schema =
|
|
8
|
+
const schema = schemas.schema(request)
|
|
9
9
|
|
|
10
|
-
return new Request(schema)
|
|
10
|
+
return new Request(schema, definition, entity)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const reply = (output,
|
|
14
|
-
const reply = Reply.schema(output,
|
|
15
|
-
|
|
13
|
+
export const reply = (output, errors) => {
|
|
14
|
+
const reply = Reply.schema(output, errors)
|
|
15
|
+
|
|
16
|
+
// a reply is read, not shaped: a value that only fits once coerced does not fit
|
|
17
|
+
const schema = schemas.schema(reply, { coerceTypes: false })
|
|
16
18
|
|
|
17
19
|
return new Reply(schema)
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
exports.request = request
|
|
21
|
-
exports.reply = reply
|
package/src/emission.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { Emission, Event } from '@toa.io/core'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as boot from './index.js'
|
|
4
|
+
import * as extensions from './extensions/index.js'
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const extensions = require('./extensions')
|
|
7
|
-
|
|
8
|
-
const emission = (definitions, locator, context) => {
|
|
6
|
+
export const emission = async (definitions, locator, context) => {
|
|
9
7
|
if (definitions === undefined) return
|
|
10
8
|
|
|
11
|
-
const events =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const events = await Promise.all(
|
|
10
|
+
Object.entries(definitions).map(async ([label, definition]) => {
|
|
11
|
+
const emitter = await boot.bindings.emit(definition.binding, locator, label)
|
|
12
|
+
const decorator = extensions.emitter(emitter, label, locator)
|
|
13
|
+
const bridge = await boot.bridge.event(
|
|
14
|
+
definition.bridge,
|
|
15
|
+
definition.path,
|
|
16
|
+
label,
|
|
17
|
+
context
|
|
18
|
+
)
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
return new Event(
|
|
21
|
+
{ ...definition, label: `${locator.id}.${label}` },
|
|
22
|
+
decorator,
|
|
23
|
+
bridge
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
)
|
|
18
27
|
|
|
19
28
|
return new Emission(events)
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
exports.emission = emission
|
package/src/env.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import dotenv from 'dotenv'
|
|
3
|
+
import { environment, findUp } from '@toa.io/generic'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/*
|
|
6
|
+
* A local run reads what `toa env` wrote. What the file says goes to the environment store
|
|
7
|
+
* and never into `process.env`: a `.env` is where a local run keeps its secrets, and a
|
|
8
|
+
* component's code must not find them. A variable already set is left alone, as `dotenv`
|
|
9
|
+
* left it, so what the environment says still wins — and reading the file costs nothing
|
|
10
|
+
* where there is none: a deployment has no `.env` to find.
|
|
11
|
+
*
|
|
12
|
+
* It used to be read only where `TOA_ENV` was unset, taking that one variable as proof the
|
|
13
|
+
* environment had been injected. Setting it for any other reason then dropped the file
|
|
14
|
+
* whole, and every variable in it with it.
|
|
15
|
+
*/
|
|
16
|
+
export function load(path) {
|
|
17
|
+
environment.absorbEntries(dotenv.parse(readFileSync(path, 'utf8')))
|
|
9
18
|
}
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})()
|
|
15
|
-
}
|
|
20
|
+
const path = findUp('.env')
|
|
21
|
+
|
|
22
|
+
if (path !== undefined) load(path)
|
package/src/events.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { environment } from '@toa.io/generic'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The events of this component that something consumes. An event nobody consumes is not
|
|
5
|
+
* published, so it gets no emitter and no exchange, and a component none of whose events are
|
|
6
|
+
* consumed gets no emission — and therefore no outbox and no transaction.
|
|
7
|
+
*
|
|
8
|
+
* The deployment computes this from the whole context. Without one — a local run, `toa mono`,
|
|
9
|
+
* a composition booted in a test — the variable is absent and every event is published.
|
|
10
|
+
*
|
|
11
|
+
* @param {toa.norm.Component} manifest
|
|
12
|
+
* @returns {toa.norm.Events | undefined}
|
|
13
|
+
*/
|
|
14
|
+
export const events = (manifest) => {
|
|
15
|
+
if (manifest.events === undefined) return
|
|
16
|
+
|
|
17
|
+
const value = environment.get(VARIABLE + manifest.locator.uppercase)
|
|
18
|
+
|
|
19
|
+
if (value === undefined) return manifest.events
|
|
20
|
+
|
|
21
|
+
const consumed = new Set(value.split(' ').filter(Boolean))
|
|
22
|
+
const entries = Object.entries(manifest.events).filter(([label]) => consumed.has(label))
|
|
23
|
+
|
|
24
|
+
return entries.length === 0 ? undefined : Object.fromEntries(entries)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const VARIABLE = 'TOA_EVENTS_'
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { resolve } = require('./resolve')
|
|
1
|
+
import { instance } from './resolve.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @param {toa.norm.Component} manifest
|
|
7
|
-
* @returns {toa.core.extensions.Aspect[]}
|
|
5
|
+
* @returns {import('@toa.io/core/types').extensions.Aspect[]}
|
|
8
6
|
*/
|
|
9
|
-
const aspects = (manifest) => {
|
|
7
|
+
export const aspects = (manifest) => {
|
|
10
8
|
const aspects = []
|
|
11
9
|
|
|
12
10
|
if (manifest.extensions === undefined) return aspects
|
|
13
11
|
|
|
14
12
|
for (const [name, declaration] of Object.entries(manifest.extensions)) {
|
|
15
|
-
const factory =
|
|
13
|
+
const factory = instance(name, manifest.path)
|
|
16
14
|
|
|
17
15
|
if (factory.aspect === undefined) continue
|
|
18
16
|
|
|
@@ -24,5 +22,3 @@ const aspects = (manifest) => {
|
|
|
24
22
|
|
|
25
23
|
return aspects
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
exports.aspects = aspects
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { instances } = require('./instances')
|
|
1
|
+
import { instances } from './instances.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* @param {toa.core.Component} component
|
|
7
|
-
* @returns {toa.core.Component}
|
|
4
|
+
* @param {import('@toa.io/core').Component} component
|
|
5
|
+
* @returns {import('@toa.io/core').Component}
|
|
8
6
|
*/
|
|
9
|
-
const component = (component) => {
|
|
7
|
+
export const component = (component) => {
|
|
10
8
|
let decorated = component
|
|
11
9
|
|
|
12
10
|
for (const factory of Object.values(instances)) {
|
|
@@ -15,5 +13,3 @@ const component = (component) => {
|
|
|
15
13
|
|
|
16
14
|
return decorated
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
exports.component = component
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { instances } = require('./instances')
|
|
1
|
+
import { instances } from './instances.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* @param {toa.core.Context} component
|
|
7
|
-
* @returns {toa.core.Context}
|
|
4
|
+
* @param {import('@toa.io/core').Context} component
|
|
5
|
+
* @returns {import('@toa.io/core').Context}
|
|
8
6
|
*/
|
|
9
|
-
const context = (component) => {
|
|
7
|
+
export const context = (component) => {
|
|
10
8
|
let decorated = component
|
|
11
9
|
|
|
12
10
|
for (const factory of Object.values(instances)) {
|
|
@@ -15,5 +13,3 @@ const context = (component) => {
|
|
|
15
13
|
|
|
16
14
|
return decorated
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
exports.context = context
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { instance } from './resolve.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where a committed state change of this component goes, beside its own events. An extension
|
|
5
|
+
* that contributes one gives the component an outbox whether or not it declares an event, so
|
|
6
|
+
* this is read before the storage is made.
|
|
7
|
+
*
|
|
8
|
+
* @param {toa.norm.Component} manifest
|
|
9
|
+
* @returns {Promise<import('@toa.io/core/types').outbox.Destination[]>}
|
|
10
|
+
*/
|
|
11
|
+
export const destinations = async (manifest) => {
|
|
12
|
+
const destinations = []
|
|
13
|
+
|
|
14
|
+
if (manifest.extensions === undefined) return destinations
|
|
15
|
+
|
|
16
|
+
for (const [name, declaration] of Object.entries(manifest.extensions)) {
|
|
17
|
+
const factory = instance(name, manifest.path)
|
|
18
|
+
|
|
19
|
+
if (factory.destination === undefined) continue
|
|
20
|
+
|
|
21
|
+
const destination = await factory.destination(manifest.locator, declaration, manifest)
|
|
22
|
+
|
|
23
|
+
if (destination !== undefined) destinations.push(destination)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return destinations
|
|
27
|
+
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { instances } = require('./instances')
|
|
1
|
+
import { instances } from './instances.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* @param {toa.core.bindings.Emitter} emitter
|
|
4
|
+
* @param {import('@toa.io/core/types').bindings.Emitter} emitter
|
|
7
5
|
* @param {string} label
|
|
8
|
-
* @
|
|
6
|
+
* @param {import('@toa.io/core').Locator} locator
|
|
7
|
+
* @returns {import('@toa.io/core/types').bindings.Emitter}
|
|
9
8
|
*/
|
|
10
|
-
const emitter = (emitter, label) => {
|
|
9
|
+
export const emitter = (emitter, label, locator) => {
|
|
11
10
|
let decorated = emitter
|
|
12
11
|
|
|
13
12
|
for (const factory of Object.values(instances)) {
|
|
14
|
-
if (factory.emitter !== undefined)
|
|
13
|
+
if (factory.emitter !== undefined)
|
|
14
|
+
decorated = factory.emitter(decorated, label, locator)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
return decorated
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
exports.emitter = emitter
|
package/src/extensions/index.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.aspects = aspects
|
|
13
|
-
exports.component = component
|
|
14
|
-
exports.context = context
|
|
15
|
-
exports.emitter = emitter
|
|
16
|
-
exports.load = load
|
|
17
|
-
exports.receiver = receiver
|
|
18
|
-
exports.storage = storage
|
|
19
|
-
exports.tenants = tenants
|
|
1
|
+
export { aspects } from './aspects.js'
|
|
2
|
+
export { component } from './component.js'
|
|
3
|
+
export { context } from './context.js'
|
|
4
|
+
export { destinations } from './destinations.js'
|
|
5
|
+
export { emitter } from './emitter.js'
|
|
6
|
+
export { load } from './load.js'
|
|
7
|
+
export { manage } from './manage.js'
|
|
8
|
+
export { receiver } from './receiver.js'
|
|
9
|
+
export { storage } from './storage.js'
|
|
10
|
+
export { tenants } from './tenants.js'
|
package/src/extensions/load.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { resolve } = require('./resolve')
|
|
1
|
+
import { resolve } from './resolve.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @param {toa.norm.Component} manifest
|
|
7
5
|
*/
|
|
8
|
-
const load = (manifest) => {
|
|
6
|
+
export const load = async (manifest) => {
|
|
9
7
|
if (manifest.extensions === undefined) return
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
await Promise.all(
|
|
10
|
+
Object.keys(manifest.extensions).map(
|
|
11
|
+
async (name) => await resolve(name, manifest.path)
|
|
12
|
+
)
|
|
13
|
+
)
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
exports.load = load
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { instances } from './instances.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('@toa.io/core').Connector} composition
|
|
5
|
+
* @returns {import('@toa.io/core').Connector}
|
|
6
|
+
*/
|
|
7
|
+
export const manage = (composition) => {
|
|
8
|
+
let managed = composition
|
|
9
|
+
|
|
10
|
+
for (const factory of Object.values(instances)) {
|
|
11
|
+
if (factory.manage !== undefined) managed = factory.manage(managed)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return managed
|
|
15
|
+
}
|