@toa.io/norm 1.0.0-alpha.274 → 1.0.0-alpha.277
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 +9 -0
- package/package.json +8 -7
- package/src/.component/.expand/bridge.js +2 -6
- package/src/.component/.expand/entity.js +2 -6
- package/src/.component/.expand/events.js +2 -6
- package/src/.component/.expand/extensions.js +2 -6
- package/src/.component/.expand/index.js +8 -19
- package/src/.component/.expand/operations.js +2 -6
- package/src/.component/.expand/properties.js +2 -6
- package/src/.component/.expand/receivers.js +2 -6
- package/src/.component/.expand/version.js +4 -8
- package/src/.component/.normalize/events.js +12 -5
- package/src/.component/.normalize/index.js +3 -9
- package/src/.component/.normalize/operations.js +1 -5
- package/src/.component/.normalize/receivers.js +1 -5
- package/src/.component/collapse.js +2 -6
- package/src/.component/defaults.js +2 -6
- package/src/.component/dependencies.js +7 -6
- package/src/.component/dereference.js +2 -6
- package/src/.component/expand.js +2 -15
- package/src/.component/extensions.js +6 -9
- package/src/.component/index.js +9 -21
- package/src/.component/merge.js +7 -8
- package/src/.component/normalize.js +3 -7
- package/src/.component/validate.js +11 -13
- package/src/.context/.dependencies/connectors.js +2 -6
- package/src/.context/.dependencies/describe.js +1 -5
- package/src/.context/.dependencies/extensions.js +4 -7
- package/src/.context/.dependencies/index.js +3 -9
- package/src/.context/.dependencies/load.js +14 -13
- package/src/.context/.dependencies/resolve.js +6 -10
- package/src/.context/complete.js +1 -5
- package/src/.context/dependencies.js +2 -6
- package/src/.context/dereference.js +1 -5
- package/src/.context/expand.js +2 -6
- package/src/.context/index.js +6 -15
- package/src/.context/normalize.js +2 -6
- package/src/.context/validate.js +7 -11
- package/src/component.js +14 -25
- package/src/context.js +12 -21
- package/src/index.js +3 -9
- package/src/shortcuts.js +4 -10
- package/test/component/collapse.fixtures.js +2 -5
- package/test/component/collapse.test.js +17 -10
- package/test/component/dependencies.test.js +12 -10
- package/test/component/dereference.fixtures.js +2 -7
- package/test/component/dereference.test.js +9 -8
- package/test/component/dummies/extension/index.js +1 -5
- package/test/component/expand.fixtures.js +3 -8
- package/test/component/expand.test.js +10 -9
- package/test/component/normalize.fixtures.js +3 -7
- package/test/component/normalize.test.js +20 -18
- package/test/component/validate.fixtures.js +1 -5
- package/test/component/validate.test.js +88 -86
- package/test/context/complete.fixtures.js +2 -7
- package/test/context/complete.test.js +10 -8
- package/test/context/dependencies.load.test.js +13 -12
- package/test/context/dereference.fixtures.js +3 -8
- package/test/context/dereference.test.js +8 -7
- package/test/context/expand.fixtures.js +1 -5
- package/test/context/expand.test.js +9 -8
- package/test/context/normalize.fixtures.js +2 -6
- package/test/context/normalize.test.js +10 -8
- package/test/context/validate.fixtures.js +1 -5
- package/test/context/validate.test.js +20 -19
- package/test/shortcuts.fixtures.js +4 -9
- package/test/shortcuts.test.js +16 -15
- package/types/context/declaration.d.ts +1 -1
- package/types/context.d.ts +2 -2
- package/types/index.d.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.277](https://github.com/toa-io/toa/compare/v1.0.0-alpha.276...v1.0.0-alpha.277) (2026-09-03)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* read a manifest the way js-yaml read one before ([fcea1b2](https://github.com/toa-io/toa/commit/fcea1b21996d6efa6c3198acbfc9f70f1ce0c35c))
|
|
11
|
+
* settle what the module loader made asynchronous ([d4ab9df](https://github.com/toa-io/toa/commit/d4ab9dfb09e382da311dba08f52214e7645f4a6c))
|
|
12
|
+
* what the loader resolves, and what it will not ([1b8a02f](https://github.com/toa-io/toa/commit/1b8a02ff0a5e0f18ee62e3f71bc81116f86f9af1))
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
# [1.0.0-alpha.274](https://github.com/toa-io/toa/compare/v1.0.0-alpha.273...v1.0.0-alpha.274) (2026-09-02)
|
|
7
16
|
|
|
8
17
|
**Note:** Version bump only for package @toa.io/norm
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.277",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Toa declarations normalization and validation",
|
|
5
6
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
7
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -20,11 +21,11 @@
|
|
|
20
21
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/schemas": "1.0.0-alpha.
|
|
26
|
-
"fast-glob": "3.
|
|
27
|
-
"js-yaml": "4.
|
|
24
|
+
"@toa.io/core": "1.0.0-alpha.277",
|
|
25
|
+
"@toa.io/generic": "1.0.0-alpha.277",
|
|
26
|
+
"@toa.io/schemas": "1.0.0-alpha.277",
|
|
27
|
+
"fast-glob": "3.3.3",
|
|
28
|
+
"js-yaml": "5.4.1"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "0c0071418c2c56a44e621ba5ced5cdd23dff1738"
|
|
30
31
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function entity (manifest) {
|
|
3
|
+
export function entity (manifest) {
|
|
6
4
|
if (!('entity' in manifest)) return
|
|
7
5
|
|
|
8
6
|
manifest.entity.storage = resolve(manifest.entity.storage)
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
exports.entity = entity
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function events (manifest) {
|
|
3
|
+
export function events (manifest) {
|
|
6
4
|
if (manifest.events === undefined) return
|
|
7
5
|
|
|
8
6
|
for (const event of Object.values(manifest.events)) {
|
|
@@ -10,5 +8,3 @@ function events (manifest) {
|
|
|
10
8
|
if (event.bridge !== undefined) event.bridge = resolve(event.bridge)
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
exports.events = events
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { recognize } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function extensions (manifest) {
|
|
3
|
+
export function extensions (manifest) {
|
|
6
4
|
recognize(SHORTCUTS, manifest, 'extensions')
|
|
7
5
|
recognize(SHORTCUTS, manifest.extensions)
|
|
8
6
|
}
|
|
@@ -16,5 +14,3 @@ const SHORTCUTS = {
|
|
|
16
14
|
storages: '@toa.io/extensions.storages',
|
|
17
15
|
introspection: '@toa.io/extensions.introspection'
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
exports.extensions = extensions
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { receivers } = require('./receivers')
|
|
10
|
-
const { version } = require('./version')
|
|
11
|
-
|
|
12
|
-
exports.bridge = bridge
|
|
13
|
-
exports.entity = entity
|
|
14
|
-
exports.events = events
|
|
15
|
-
exports.extensions = extensions
|
|
16
|
-
exports.operations = operations
|
|
17
|
-
exports.properties = properties
|
|
18
|
-
exports.receivers = receivers
|
|
19
|
-
exports.version = version
|
|
1
|
+
export { bridge } from './bridge.js'
|
|
2
|
+
export { entity } from './entity.js'
|
|
3
|
+
export { events } from './events.js'
|
|
4
|
+
export { extensions } from './extensions.js'
|
|
5
|
+
export { operations } from './operations.js'
|
|
6
|
+
export { properties } from './properties.js'
|
|
7
|
+
export { receivers } from './receivers.js'
|
|
8
|
+
export { version } from './version.js'
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function operations (manifest) {
|
|
3
|
+
export function operations (manifest) {
|
|
6
4
|
if (manifest.operations === undefined) return
|
|
7
5
|
|
|
8
6
|
for (const operation of Object.values(manifest.operations)) {
|
|
@@ -13,5 +11,3 @@ function operations (manifest) {
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
exports.operations = operations
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { recognize } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function properties (manifest) {
|
|
3
|
+
export function properties (manifest) {
|
|
6
4
|
recognize(SHORTCUTS, manifest, 'properties')
|
|
7
5
|
recognize(SHORTCUTS, manifest.properties)
|
|
8
6
|
}
|
|
@@ -10,5 +8,3 @@ function properties (manifest) {
|
|
|
10
8
|
const SHORTCUTS = {
|
|
11
9
|
queues: '@toa.io/storages.queues'
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
exports.properties = properties
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from '../../shortcuts.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function receivers (manifest) {
|
|
3
|
+
export function receivers (manifest) {
|
|
6
4
|
if (manifest.receivers === undefined) return
|
|
7
5
|
|
|
8
6
|
for (const [locator, receiver] of Object.entries(manifest.receivers)) {
|
|
@@ -12,5 +10,3 @@ function receivers (manifest) {
|
|
|
12
10
|
if (receiver.bridge !== undefined) receiver.bridge = resolve(receiver.bridge)
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
exports.receivers = receivers
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const { createHash } = require('node:crypto')
|
|
5
|
-
const fs = require('node:fs/promises')
|
|
6
|
-
|
|
7
|
-
async function version (manifest) {
|
|
5
|
+
export async function version (manifest) {
|
|
8
6
|
manifest.version ??= await hash(manifest.path)
|
|
9
7
|
}
|
|
10
8
|
|
|
@@ -57,5 +55,3 @@ async function digest (path) {
|
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
const EXCLUDED = new Set(['node_modules', '.git'])
|
|
60
|
-
|
|
61
|
-
exports.version = version
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const events = (component) => {
|
|
1
|
+
export const events = async (component) => {
|
|
4
2
|
if (component.events === undefined) return
|
|
5
3
|
|
|
6
|
-
const binding = component.bindings
|
|
4
|
+
const binding = await asynchronous(component.bindings)
|
|
7
5
|
|
|
8
6
|
for (const event of Object.values(component.events)) {
|
|
9
7
|
if (event.binding === undefined) event.binding = binding
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
/** The first binding that carries events, which only its module can say. */
|
|
12
|
+
async function asynchronous (bindings) {
|
|
13
|
+
for (const binding of bindings) {
|
|
14
|
+
const { properties } = await import(binding)
|
|
15
|
+
|
|
16
|
+
if (properties.async === true) return binding
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { operations } = require('./operations')
|
|
5
|
-
const { receivers } = require('./receivers')
|
|
6
|
-
|
|
7
|
-
exports.events = events
|
|
8
|
-
exports.operations = operations
|
|
9
|
-
exports.receivers = receivers
|
|
1
|
+
export { events } from './events.js'
|
|
2
|
+
export { operations } from './operations.js'
|
|
3
|
+
export { receivers } from './receivers.js'
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const operations = (component) => {
|
|
1
|
+
export const operations = (component) => {
|
|
4
2
|
if (component.operations === undefined) return
|
|
5
3
|
|
|
6
4
|
for (const [endpoint, operation] of Object.entries(component.operations)) {
|
|
@@ -12,5 +10,3 @@ const operations = (component) => {
|
|
|
12
10
|
if (operation.virtual === true) delete component.operations[endpoint]
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
exports.operations = operations
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function receivers (component) {
|
|
1
|
+
export function receivers (component) {
|
|
4
2
|
if (component.receivers === undefined) return
|
|
5
3
|
|
|
6
4
|
const receivers = component.receivers
|
|
@@ -18,5 +16,3 @@ function receivers (component) {
|
|
|
18
16
|
receivers[newKey] = value
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
exports.receivers = receivers
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { merge } from '@toa.io/generic'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const collapse = (manifest, prototype) => {
|
|
3
|
+
export const collapse = (manifest, prototype) => {
|
|
6
4
|
delete manifest.prototype
|
|
7
5
|
|
|
8
6
|
if (prototype.operations) {
|
|
@@ -49,5 +47,3 @@ const collapse = (manifest, prototype) => {
|
|
|
49
47
|
|
|
50
48
|
merge(manifest, { entity, events, extensions })
|
|
51
49
|
}
|
|
52
|
-
|
|
53
|
-
exports.collapse = collapse
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { hash } = require('@toa.io/generic')
|
|
1
|
+
import { hash } from '@toa.io/generic'
|
|
4
2
|
|
|
5
3
|
// these defaults are required before validation
|
|
6
|
-
const defaults = (manifest, proto) => {
|
|
4
|
+
export const defaults = (manifest, proto) => {
|
|
7
5
|
if (manifest.name === undefined)
|
|
8
6
|
if (proto) manifest.name = protoName(manifest)
|
|
9
7
|
else nameAfterDir(manifest)
|
|
@@ -34,5 +32,3 @@ function nameAfterDir (manifest) {
|
|
|
34
32
|
manifest.name = name
|
|
35
33
|
manifest.namespace = namespace
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
exports.defaults = defaults
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { join, dirname } from 'node:path'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
// import.meta.resolve takes no paths, and a storage is resolved against the
|
|
5
|
+
// component that names it
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* @param {toa.norm.Component} component
|
|
7
10
|
*/
|
|
8
|
-
const dependencies = (component) => {
|
|
11
|
+
export const dependencies = (component) => {
|
|
9
12
|
if ('entity' in component) component.entity.storage = resolve(component.path, component.entity.storage)
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
function resolve (root, reference) {
|
|
13
|
-
const paths = [root,
|
|
16
|
+
const paths = [root, import.meta.dirname]
|
|
14
17
|
const options = { paths }
|
|
15
18
|
|
|
16
19
|
let path
|
|
@@ -25,5 +28,3 @@ function resolve (root, reference) {
|
|
|
25
28
|
|
|
26
29
|
return dirname(path)
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
exports.dependencies = dependencies
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { merge } from '@toa.io/generic'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const dereference = (manifest) => {
|
|
3
|
+
export const dereference = (manifest) => {
|
|
6
4
|
// schemas
|
|
7
5
|
const resolver = createResolver(manifest.entity?.schema?.properties)
|
|
8
6
|
|
|
@@ -77,5 +75,3 @@ const forward = (operation, operations) => {
|
|
|
77
75
|
|
|
78
76
|
merge(operation, real)
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
exports.dereference = dereference
|
package/src/.component/expand.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { entity, bridge, operations, events, receivers, extensions, properties, version } from './.expand/index.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
entity,
|
|
5
|
-
bridge,
|
|
6
|
-
operations,
|
|
7
|
-
events,
|
|
8
|
-
receivers,
|
|
9
|
-
extensions,
|
|
10
|
-
properties,
|
|
11
|
-
version
|
|
12
|
-
} = require('./.expand')
|
|
13
|
-
|
|
14
|
-
async function expand (manifest) {
|
|
3
|
+
export async function expand (manifest) {
|
|
15
4
|
entity(manifest)
|
|
16
5
|
bridge(manifest)
|
|
17
6
|
operations(manifest)
|
|
@@ -22,5 +11,3 @@ async function expand (manifest) {
|
|
|
22
11
|
|
|
23
12
|
await version(manifest)
|
|
24
13
|
}
|
|
25
|
-
|
|
26
|
-
exports.expand = expand
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { find } = require('@toa.io/generic')
|
|
4
|
-
const { resolve } = require('../shortcuts')
|
|
1
|
+
import { find } from '@toa.io/generic'
|
|
2
|
+
import { resolve } from '../shortcuts.js'
|
|
5
3
|
|
|
6
4
|
const cache = {}
|
|
7
5
|
|
|
8
|
-
const extensions = (manifest) => {
|
|
6
|
+
export const extensions = async (manifest) => {
|
|
9
7
|
manifest.extensions = Object.assign({}, PREDEFINED, manifest.extensions)
|
|
10
8
|
|
|
11
9
|
const extensions = manifest.extensions
|
|
@@ -16,8 +14,9 @@ const extensions = (manifest) => {
|
|
|
16
14
|
// relative path
|
|
17
15
|
if (key[0] === '.') key = find(key, manifest.path)
|
|
18
16
|
|
|
19
|
-
cache[key] ??=
|
|
20
|
-
|
|
17
|
+
cache[key] ??= import(key)
|
|
18
|
+
|
|
19
|
+
const extension = await cache[key]
|
|
21
20
|
|
|
22
21
|
if (extension.manifest !== undefined) {
|
|
23
22
|
declaration = extension.manifest(declaration, manifest)
|
|
@@ -37,5 +36,3 @@ const PREDEFINED = {
|
|
|
37
36
|
'@toa.io/extensions.fetch': null,
|
|
38
37
|
'@toa.io/extensions.introspection': null
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
exports.extensions = extensions
|
package/src/.component/index.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { validate } = require('./validate')
|
|
11
|
-
const { extensions } = require('./extensions')
|
|
12
|
-
|
|
13
|
-
exports.collapse = collapse
|
|
14
|
-
exports.defaults = defaults
|
|
15
|
-
exports.dependencies = dependencies
|
|
16
|
-
exports.dereference = dereference
|
|
17
|
-
exports.expand = expand
|
|
18
|
-
exports.merge = merge
|
|
19
|
-
exports.normalize = normalize
|
|
20
|
-
exports.validate = validate
|
|
21
|
-
exports.extensions = extensions
|
|
1
|
+
export { collapse } from './collapse.js'
|
|
2
|
+
export { defaults } from './defaults.js'
|
|
3
|
+
export { dependencies } from './dependencies.js'
|
|
4
|
+
export { dereference } from './dereference.js'
|
|
5
|
+
export { expand } from './expand.js'
|
|
6
|
+
export { merge } from './merge.js'
|
|
7
|
+
export { normalize } from './normalize.js'
|
|
8
|
+
export { validate } from './validate.js'
|
|
9
|
+
export { extensions } from './extensions.js'
|
package/src/.component/merge.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { merge } = require('@toa.io/generic')
|
|
1
|
+
import { merge } from '@toa.io/generic'
|
|
4
2
|
|
|
5
3
|
const bridge = async (root, manifest) => {
|
|
6
4
|
await Promise.all([
|
|
@@ -20,7 +18,7 @@ const define = async (root, manifest, property) => {
|
|
|
20
18
|
if (item.bridge === undefined || item.bridge === manifest.bridge) continue // default bridge later
|
|
21
19
|
|
|
22
20
|
const bridge = item.bridge || manifest.bridge
|
|
23
|
-
const define = req(bridge)
|
|
21
|
+
const { define } = await req(bridge)
|
|
24
22
|
const definition = await define[singular](root, endpoint)
|
|
25
23
|
|
|
26
24
|
merge(item, definition)
|
|
@@ -58,18 +56,19 @@ const define = async (root, manifest, property) => {
|
|
|
58
56
|
|
|
59
57
|
const cache = {}
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
// the promise is what is remembered, so a bridge is loaded once
|
|
60
|
+
function req (mod) {
|
|
61
|
+
cache[mod] ??= import(mod)
|
|
63
62
|
|
|
64
63
|
return cache[mod]
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
const scan = async (bridge, root, property) => {
|
|
68
|
-
const define = req(bridge)
|
|
67
|
+
const { define } = await req(bridge)
|
|
69
68
|
|
|
70
69
|
if (property in define)
|
|
71
70
|
return define[property](root)
|
|
72
71
|
else return undefined
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
export { bridge as merge }
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { events, operations, receivers } from './.normalize/index.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const normalize = (component) => {
|
|
3
|
+
export const normalize = async (component) => {
|
|
6
4
|
operations(component)
|
|
7
|
-
events(component)
|
|
5
|
+
await events(component)
|
|
8
6
|
receivers(component)
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
exports.normalize = normalize
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { yaml } from '@toa.io/generic'
|
|
5
|
+
import * as schemas from '@toa.io/schemas'
|
|
4
6
|
|
|
5
|
-
const
|
|
6
|
-
const { load: parseYAML } = require('js-yaml')
|
|
7
|
-
const schemas = require('@toa.io/schemas')
|
|
8
|
-
|
|
9
|
-
const object = parseYAML(readFileSync(path.resolve(__dirname, 'schema.yaml'), 'utf8'))
|
|
7
|
+
const object = yaml.load(readFileSync(path.resolve(import.meta.dirname, 'schema.yaml'), 'utf8'))
|
|
10
8
|
const schema = schemas.schema(object)
|
|
11
9
|
|
|
12
|
-
const validate = (manifest) => {
|
|
10
|
+
export const validate = async (manifest) => {
|
|
13
11
|
const error = schema.fit(manifest)
|
|
14
12
|
|
|
15
13
|
if (error) throw error
|
|
16
14
|
|
|
17
|
-
if (manifest.events !== undefined) events(manifest)
|
|
15
|
+
if (manifest.events !== undefined) await events(manifest)
|
|
18
16
|
if (manifest.receivers !== undefined) receivers(manifest)
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
const events = (manifest) => {
|
|
19
|
+
const events = async (manifest) => {
|
|
22
20
|
for (const [label, event] of Object.entries(manifest.events)) {
|
|
23
|
-
|
|
21
|
+
const { properties } = await import(event.binding)
|
|
22
|
+
|
|
23
|
+
if (properties.async !== true) {
|
|
24
24
|
throw new Error(`Event '${label}' binding '${event.binding}' is not async`)
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -39,5 +39,3 @@ const receivers = (manifest) => {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const TYPES = new Set(['transition', 'assignment', 'effect', 'unmanaged'])
|
|
42
|
-
|
|
43
|
-
exports.validate = validate
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const connectors = (context, extracted) => {
|
|
3
|
+
export const connectors = (context, extracted) => {
|
|
6
4
|
const connectors = {}
|
|
7
5
|
|
|
8
6
|
const components = (context.components === undefined
|
|
@@ -47,5 +45,3 @@ const connectors = (context, extracted) => {
|
|
|
47
45
|
|
|
48
46
|
return connectors
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
exports.connectors = connectors
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @param {toa.norm.Component} component
|
|
5
3
|
* @param {Object} manifest
|
|
6
4
|
* @returns {toa.norm.context.dependencies.Instance}
|
|
7
5
|
*/
|
|
8
|
-
const describe = (component, manifest = undefined) => ({ locator: component.locator, manifest })
|
|
9
|
-
|
|
10
|
-
exports.describe = describe
|
|
6
|
+
export const describe = (component, manifest = undefined) => ({ locator: component.locator, manifest })
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { component as load } from '../../component.js'
|
|
2
|
+
import { load as loadDependency } from './load.js'
|
|
2
3
|
|
|
3
|
-
const extensions = async (context) => {
|
|
4
|
+
export const extensions = async (context) => {
|
|
4
5
|
const extensions = {}
|
|
5
6
|
const components = context.components?.slice() ?? []
|
|
6
7
|
const extracted = await extractExtensionComponents(components, extensions, context.annotations)
|
|
@@ -21,8 +22,6 @@ const extensions = async (context) => {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
async function extractExtensionComponents (components, extensions, annotations) {
|
|
24
|
-
const { component: load } = require('../../component')
|
|
25
|
-
const { load: loadDependency } = require('./load')
|
|
26
25
|
|
|
27
26
|
const extracted = []
|
|
28
27
|
|
|
@@ -34,7 +33,7 @@ async function extractExtensionComponents (components, extensions, annotations)
|
|
|
34
33
|
|
|
35
34
|
extensions[reference] = []
|
|
36
35
|
|
|
37
|
-
const { metadata, module: mod } = loadDependency(reference)
|
|
36
|
+
const { metadata, module: mod } = await loadDependency(reference)
|
|
38
37
|
|
|
39
38
|
if (mod.components === undefined) continue
|
|
40
39
|
|
|
@@ -56,5 +55,3 @@ async function extractExtensionComponents (components, extensions, annotations)
|
|
|
56
55
|
|
|
57
56
|
return extracted.concat(deeper)
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
exports.extensions = extensions
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { extensions } = require('./extensions')
|
|
5
|
-
const { resolve } = require('./resolve')
|
|
6
|
-
|
|
7
|
-
exports.connectors = connectors
|
|
8
|
-
exports.extensions = extensions
|
|
9
|
-
exports.resolve = resolve
|
|
1
|
+
export { connectors } from './connectors.js'
|
|
2
|
+
export { extensions } from './extensions.js'
|
|
3
|
+
export { resolve } from './resolve.js'
|