@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
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
// import.meta.resolve takes no paths, and a dependency is named rather than
|
|
7
|
+
// written as a path
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* @param {string} path
|
|
7
|
-
* @returns {{ metadata: object, module: object }}
|
|
12
|
+
* @returns {Promise<{ metadata: object, module: object }>}
|
|
8
13
|
*/
|
|
9
|
-
function load (path) {
|
|
14
|
+
export async function load (path) {
|
|
10
15
|
const metadata = loadMetadata(path)
|
|
11
|
-
const module = loadModule(path)
|
|
16
|
+
const module = await loadModule(path)
|
|
12
17
|
|
|
13
18
|
return { metadata, module }
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
function loadMetadata (reference) {
|
|
17
|
-
reference = join(reference, 'package.json')
|
|
18
|
-
|
|
19
22
|
try {
|
|
20
|
-
return require(reference)
|
|
23
|
+
return JSON.parse(readFileSync(require.resolve(join(reference, 'package.json')), 'utf8'))
|
|
21
24
|
} catch {
|
|
22
25
|
return null
|
|
23
26
|
}
|
|
@@ -25,12 +28,10 @@ function loadMetadata (reference) {
|
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* @param {string} reference
|
|
28
|
-
* @returns {object}
|
|
31
|
+
* @returns {Promise<object>}
|
|
29
32
|
*/
|
|
30
|
-
function loadModule (reference) {
|
|
33
|
+
async function loadModule (reference) {
|
|
31
34
|
const path = require.resolve(reference)
|
|
32
35
|
|
|
33
|
-
return
|
|
36
|
+
return await import(pathToFileURL(path).href)
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
exports.load = load
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { load } from './load.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const resolve = (references, annotations) => {
|
|
3
|
+
export const resolve = async (references, annotations) => {
|
|
6
4
|
const dependencies = {}
|
|
7
5
|
|
|
8
6
|
for (const [dependency, components] of Object.entries(references)) {
|
|
9
|
-
const { metadata, module } = load(dependency)
|
|
7
|
+
const { metadata, module } = await load(dependency)
|
|
10
8
|
const id = metadata.name
|
|
11
9
|
|
|
12
10
|
const instances = components.map((component) => ({
|
|
@@ -28,7 +26,7 @@ const resolve = (references, annotations) => {
|
|
|
28
26
|
if (dependency in dependencies) continue
|
|
29
27
|
|
|
30
28
|
// an annotation may be keyed by a dependency id rather than by a module reference
|
|
31
|
-
const module = optional(dependency)
|
|
29
|
+
const module = await optional(dependency)
|
|
32
30
|
|
|
33
31
|
if (module?.standalone === true) dependencies[dependency] = []
|
|
34
32
|
}
|
|
@@ -40,12 +38,10 @@ const resolve = (references, annotations) => {
|
|
|
40
38
|
* @param {string} reference
|
|
41
39
|
* @returns {object | null}
|
|
42
40
|
*/
|
|
43
|
-
function optional (reference) {
|
|
41
|
+
async function optional (reference) {
|
|
44
42
|
try {
|
|
45
|
-
return load(reference).module
|
|
43
|
+
return (await load(reference)).module
|
|
46
44
|
} catch {
|
|
47
45
|
return null
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
exports.resolve = resolve
|
package/src/.context/complete.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Completes missing compositions with unused components
|
|
5
3
|
* @param {toa.norm.Context} context
|
|
6
4
|
* @returns {void}
|
|
7
5
|
*/
|
|
8
|
-
const complete = (context) => {
|
|
6
|
+
export const complete = (context) => {
|
|
9
7
|
/** @type {Set<string>} */
|
|
10
8
|
const composed = new Set()
|
|
11
9
|
|
|
@@ -29,5 +27,3 @@ const complete = (context) => {
|
|
|
29
27
|
context.compositions.push({ name, components: [component] })
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
exports.complete = complete
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { connectors, extensions, resolve } from './.dependencies/index.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const dependencies = async (context) => {
|
|
3
|
+
export const dependencies = async (context) => {
|
|
6
4
|
const { extensions: e, components } = await extensions(context)
|
|
7
5
|
const c = connectors(context, components)
|
|
8
6
|
const references = { ...c, ...e }
|
|
9
7
|
|
|
10
8
|
return resolve(references, context.annotations)
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
exports.dependencies = dependencies
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Resolves component IDs within compositions with Component objects
|
|
5
3
|
* @param {toa.norm.Context} context
|
|
6
4
|
* @returns {void}
|
|
7
5
|
*/
|
|
8
|
-
const dereference = (context) => {
|
|
6
|
+
export const dereference = (context) => {
|
|
9
7
|
const components = map(context.components)
|
|
10
8
|
|
|
11
9
|
if (context.compositions !== undefined) {
|
|
@@ -27,5 +25,3 @@ const map = (components) => {
|
|
|
27
25
|
|
|
28
26
|
return map
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
exports.dereference = dereference
|
package/src/.context/expand.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const shortcuts = require('../shortcuts')
|
|
1
|
+
import * as shortcuts from '../shortcuts.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @param {toa.norm.context.Declaration | object} context
|
|
7
5
|
*/
|
|
8
|
-
const expand = (context) => {
|
|
6
|
+
export const expand = (context) => {
|
|
9
7
|
shortcuts.recognize(shortcuts.SHORTCUTS, context, 'annotations')
|
|
10
8
|
shortcuts.recognize(shortcuts.SHORTCUTS, context.annotations)
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
exports.expand = expand
|
package/src/.context/index.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { normalize } = require('./normalize')
|
|
8
|
-
const { validate } = require('./validate')
|
|
9
|
-
|
|
10
|
-
exports.complete = complete
|
|
11
|
-
exports.dependencies = dependencies
|
|
12
|
-
exports.dereference = dereference
|
|
13
|
-
exports.expand = expand
|
|
14
|
-
exports.normalize = normalize
|
|
15
|
-
exports.validate = validate
|
|
1
|
+
export { complete } from './complete.js'
|
|
2
|
+
export { dependencies } from './dependencies.js'
|
|
3
|
+
export { dereference } from './dereference.js'
|
|
4
|
+
export { expand } from './expand.js'
|
|
5
|
+
export { normalize } from './normalize.js'
|
|
6
|
+
export { validate } from './validate.js'
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import * as runtime from '@toa.io/runtime'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {toa.norm.context.Declaration | Object} context
|
|
5
5
|
*/
|
|
6
|
-
const normalize = (context) => {
|
|
7
|
-
const runtime = require('@toa.io/runtime')
|
|
8
|
-
|
|
6
|
+
export const normalize = (context) => {
|
|
9
7
|
if (context.runtime === undefined) context.runtime = { version: runtime.version }
|
|
10
8
|
if (typeof context.runtime === 'string') context.runtime = { version: context.runtime }
|
|
11
9
|
|
|
@@ -15,5 +13,3 @@ const normalize = (context) => {
|
|
|
15
13
|
|
|
16
14
|
if (typeof context.registry === 'string') context.registry = { base: context.registry }
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
exports.normalize = normalize
|
package/src/.context/validate.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } 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
|
|
7
|
-
const schemas = require('@toa.io/schemas')
|
|
8
|
-
|
|
9
|
-
const path = resolve(__dirname, 'schema.yaml')
|
|
10
|
-
const object = parseYAML(readFileSync(path, 'utf8'))
|
|
7
|
+
const path = resolve(import.meta.dirname, 'schema.yaml')
|
|
8
|
+
const object = yaml.load(readFileSync(path, 'utf8'))
|
|
11
9
|
const schema = schemas.schema(object)
|
|
12
10
|
|
|
13
|
-
const validate = (context) => {
|
|
11
|
+
export const validate = (context) => {
|
|
14
12
|
schema.validate(context)
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
exports.validate = validate
|
package/src/component.js
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
expand,
|
|
12
|
-
merge,
|
|
13
|
-
validate,
|
|
14
|
-
collapse,
|
|
15
|
-
dereference,
|
|
16
|
-
defaults,
|
|
17
|
-
normalize,
|
|
18
|
-
extensions
|
|
19
|
-
} = require('./.component')
|
|
20
|
-
|
|
21
|
-
const component = async (path) => {
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { yaml as jsyaml } from '@toa.io/generic'
|
|
5
|
+
import { find } from '@toa.io/generic'
|
|
6
|
+
import { Locator } from '@toa.io/core'
|
|
7
|
+
|
|
8
|
+
import { expand, merge, validate, collapse, dereference, defaults, normalize, extensions } from './.component/index.js'
|
|
9
|
+
|
|
10
|
+
export const component = async (path) => {
|
|
22
11
|
const manifest = await load(path)
|
|
23
12
|
|
|
24
|
-
normalize(manifest, path)
|
|
25
|
-
validate(manifest)
|
|
26
|
-
extensions(manifest)
|
|
13
|
+
await normalize(manifest, path)
|
|
14
|
+
await validate(manifest)
|
|
15
|
+
await extensions(manifest)
|
|
27
16
|
|
|
28
17
|
manifest.locator = new Locator(manifest.name, manifest.namespace)
|
|
29
18
|
|
|
@@ -57,7 +46,7 @@ const load = async (path, base, proto = false) => {
|
|
|
57
46
|
|
|
58
47
|
const MANIFEST = 'manifest.toa.yaml'
|
|
59
48
|
|
|
60
|
-
|
|
49
|
+
|
|
61
50
|
|
|
62
51
|
/**
|
|
63
52
|
* Reads a YAML file, resolving anchors into distinct objects so that
|
package/src/context.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
dependencies,
|
|
13
|
-
normalize,
|
|
14
|
-
complete,
|
|
15
|
-
dereference,
|
|
16
|
-
expand,
|
|
17
|
-
validate
|
|
18
|
-
} = require('./.context')
|
|
19
|
-
|
|
20
|
-
const context = async (root, environment = process.env.TOA_ENV) => {
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import { convolve } from '@toa.io/generic'
|
|
3
|
+
import glob from 'fast-glob'
|
|
4
|
+
import { readFile } from 'node:fs/promises'
|
|
5
|
+
import { yaml as jsyaml } from '@toa.io/generic'
|
|
6
|
+
|
|
7
|
+
import { component } from './component.js'
|
|
8
|
+
|
|
9
|
+
import { dependencies, normalize, complete, dereference, expand, validate } from './.context/index.js'
|
|
10
|
+
|
|
11
|
+
export const context = async (root, environment = process.env.TOA_ENV) => {
|
|
21
12
|
const path = resolve(root, CONTEXT)
|
|
22
13
|
const context = /** @type {toa.norm.Context} */ await read(path)
|
|
23
14
|
|
|
@@ -46,7 +37,7 @@ const COMPONENTS = 'components/*'
|
|
|
46
37
|
|
|
47
38
|
const GLOB = { onlyDirectories: true, absolute: true }
|
|
48
39
|
|
|
49
|
-
|
|
40
|
+
|
|
50
41
|
|
|
51
42
|
/**
|
|
52
43
|
* Reads a YAML file, resolving anchors into distinct objects so that
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { component } = require('./component')
|
|
5
|
-
|
|
6
|
-
exports.shortcuts = require('./shortcuts')
|
|
7
|
-
|
|
8
|
-
exports.context = context
|
|
9
|
-
exports.component = component
|
|
1
|
+
export { context } from './context.js'
|
|
2
|
+
export { component } from './component.js'
|
|
3
|
+
export * as shortcuts from './shortcuts.js'
|
package/src/shortcuts.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { empty, merge } = require('@toa.io/generic')
|
|
1
|
+
import { empty, merge } from '@toa.io/generic'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Resolves shortcuts
|
|
@@ -8,7 +6,7 @@ const { empty, merge } = require('@toa.io/generic')
|
|
|
8
6
|
* @param {string} token
|
|
9
7
|
* @returns {string}
|
|
10
8
|
*/
|
|
11
|
-
const resolve = (token) => {
|
|
9
|
+
export const resolve = (token) => {
|
|
12
10
|
if (token in SHORTCUTS) return SHORTCUTS[token]
|
|
13
11
|
else return token
|
|
14
12
|
}
|
|
@@ -20,7 +18,7 @@ const resolve = (token) => {
|
|
|
20
18
|
* @param {Object} object
|
|
21
19
|
* @param {string} [group]
|
|
22
20
|
*/
|
|
23
|
-
const recognize = (shortcuts, object, group) => {
|
|
21
|
+
export const recognize = (shortcuts, object, group) => {
|
|
24
22
|
if (object === undefined) return
|
|
25
23
|
|
|
26
24
|
const target = group === undefined ? object : {}
|
|
@@ -38,7 +36,7 @@ const recognize = (shortcuts, object, group) => {
|
|
|
38
36
|
if (group !== undefined && !empty(target)) object[group] = merge(object[group], target)
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const SHORTCUTS = {
|
|
39
|
+
export const SHORTCUTS = {
|
|
42
40
|
amqp: '@toa.io/bindings.amqp',
|
|
43
41
|
node: '@toa.io/bridges.node',
|
|
44
42
|
bash: '@toa.io/bridges.bash',
|
|
@@ -53,7 +51,3 @@ const SHORTCUTS = {
|
|
|
53
51
|
telemetry: '@toa.io/extensions.telemetry',
|
|
54
52
|
introspection: '@toa.io/extensions.introspection'
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
exports.recognize = recognize
|
|
58
|
-
exports.resolve = resolve
|
|
59
|
-
exports.SHORTCUTS = SHORTCUTS
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
1
|
+
import { generate } from 'randomstring'
|
|
4
2
|
|
|
5
3
|
const entity = {
|
|
6
4
|
manifest: {
|
|
@@ -88,7 +86,6 @@ const operations = {
|
|
|
88
86
|
result: {
|
|
89
87
|
prototype: {
|
|
90
88
|
prototype: null,
|
|
91
|
-
path: expect.any(String),
|
|
92
89
|
operations: {
|
|
93
90
|
add: {
|
|
94
91
|
bridge: 'a'
|
|
@@ -131,4 +128,4 @@ const remotes = {
|
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
130
|
|
|
134
|
-
|
|
131
|
+
export const samples = { entity, operations, remotes }
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import clone from 'clone-deep'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import * as fixtures from './collapse.fixtures.js'
|
|
7
|
+
import { collapse } from '../../src/.component/index.js'
|
|
7
8
|
|
|
8
9
|
let samples
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ it('should ignore locator', () => {
|
|
|
18
19
|
|
|
19
20
|
collapse(manifest, prototype)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
assert.deepStrictEqual(manifest, source)
|
|
22
23
|
})
|
|
23
24
|
|
|
24
25
|
it('should remove prototype property', () => {
|
|
@@ -26,7 +27,7 @@ it('should remove prototype property', () => {
|
|
|
26
27
|
|
|
27
28
|
collapse(manifest, {})
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
assert.deepStrictEqual(manifest, {})
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
describe('entity', () => {
|
|
@@ -34,7 +35,7 @@ describe('entity', () => {
|
|
|
34
35
|
const manifest = clone(samples.entity.manifest)
|
|
35
36
|
|
|
36
37
|
collapse(manifest, samples.entity.prototype)
|
|
37
|
-
|
|
38
|
+
assert.deepStrictEqual(manifest, samples.entity.result)
|
|
38
39
|
})
|
|
39
40
|
})
|
|
40
41
|
|
|
@@ -44,12 +45,12 @@ it('should ignore bindings', () => {
|
|
|
44
45
|
const manifest = clone(source)
|
|
45
46
|
|
|
46
47
|
collapse(manifest, prototype)
|
|
47
|
-
|
|
48
|
+
assert.deepStrictEqual(manifest, source)
|
|
48
49
|
|
|
49
50
|
delete manifest.bindings
|
|
50
51
|
|
|
51
52
|
collapse(manifest, prototype)
|
|
52
|
-
|
|
53
|
+
assert.deepStrictEqual(manifest, {})
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
it('should merge operations', () => {
|
|
@@ -57,5 +58,11 @@ it('should merge operations', () => {
|
|
|
57
58
|
const prototype = clone(samples.operations.prototype)
|
|
58
59
|
|
|
59
60
|
collapse(manifest, prototype, '/somewhere')
|
|
60
|
-
|
|
61
|
+
|
|
62
|
+
// the prototype's path is generated, so it is checked apart from the shape
|
|
63
|
+
assert.strictEqual(typeof manifest.prototype.path, 'string')
|
|
64
|
+
|
|
65
|
+
const { path, ...rest } = manifest.prototype
|
|
66
|
+
|
|
67
|
+
assert.deepStrictEqual({ ...manifest, prototype: rest }, samples.operations.result)
|
|
61
68
|
})
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import { dependencies } from '../../src/.component/index.js'
|
|
5
6
|
|
|
6
|
-
const NORM = resolve(
|
|
7
|
+
const NORM = resolve(import.meta.dirname, '../../')
|
|
7
8
|
|
|
8
9
|
it('should be', async () => {
|
|
9
|
-
|
|
10
|
+
assert.ok(dependencies instanceof Function)
|
|
10
11
|
})
|
|
11
12
|
|
|
12
13
|
/** @type {toa.norm.Component} */
|
|
13
14
|
let component
|
|
14
15
|
|
|
15
16
|
beforeEach(() => {
|
|
16
|
-
component = /** @type {toa.norm.Component} */ { path:
|
|
17
|
+
component = /** @type {toa.norm.Component} */ { path: import.meta.dirname }
|
|
17
18
|
})
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
for (const [_, reference] of [
|
|
20
21
|
['package id', '@toa.io/norm'],
|
|
21
22
|
['relative path', '../../']
|
|
22
|
-
])
|
|
23
|
+
])
|
|
24
|
+
describe(`${_}`, () => {
|
|
23
25
|
it('should resolve storage', async () => {
|
|
24
26
|
component.entity = { storage: reference, schema: {} }
|
|
25
27
|
|
|
26
28
|
dependencies(component)
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
assert.deepStrictEqual(component.entity.storage, NORM)
|
|
29
31
|
})
|
|
30
32
|
})
|
|
31
33
|
|
|
@@ -34,5 +36,5 @@ it('should resolve toa packages', async () => {
|
|
|
34
36
|
|
|
35
37
|
dependencies(component)
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
assert.notStrictEqual(component.entity.storage, undefined)
|
|
38
40
|
})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const source = {
|
|
1
|
+
export const source = {
|
|
4
2
|
entity: {
|
|
5
3
|
schema: {
|
|
6
4
|
properties: {
|
|
@@ -66,7 +64,7 @@ const source = {
|
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
const target = {
|
|
67
|
+
export const target = {
|
|
70
68
|
entity: {
|
|
71
69
|
schema: {
|
|
72
70
|
properties: {
|
|
@@ -160,6 +158,3 @@ const target = {
|
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
exports.source = source
|
|
165
|
-
exports.target = target
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import clone from 'clone-deep'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { dereference } from '../../src/.component/index.js'
|
|
7
|
+
import * as fixtures from './dereference.fixtures.js'
|
|
7
8
|
|
|
8
9
|
let source
|
|
9
10
|
|
|
@@ -14,18 +15,18 @@ beforeEach(() => {
|
|
|
14
15
|
it('should dereference', () => {
|
|
15
16
|
dereference(source)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
assert.deepStrictEqual(source, fixtures.target)
|
|
18
19
|
})
|
|
19
20
|
|
|
20
21
|
it('should throw on invalid schema reference', () => {
|
|
21
22
|
source.operations.transit.output.properties.baz = { type: 'string', default: '.' }
|
|
22
|
-
|
|
23
|
+
assert.throws(() => dereference(source), (error) => /is not defined/.test(error.message))
|
|
23
24
|
|
|
24
25
|
source.operations.transit.output.properties.baz = { type: 'string', default: '.baz' }
|
|
25
|
-
|
|
26
|
+
assert.throws(() => dereference(source), (error) => /is not defined/.test(error.message))
|
|
26
27
|
})
|
|
27
28
|
|
|
28
29
|
it('should throw on invalid forwarding', () => {
|
|
29
30
|
source.operations.create.forward = 'foo'
|
|
30
|
-
|
|
31
|
+
assert.throws(() => dereference(source), (error) => /is not defined/.test(error.message))
|
|
31
32
|
})
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const source = {
|
|
4
|
-
path: __dirname, // `version` hashes the component directory
|
|
1
|
+
export const source = {
|
|
2
|
+
path: import.meta.dirname, // `version` hashes the component directory
|
|
5
3
|
entity: {
|
|
6
4
|
schema: {
|
|
7
5
|
type: 'object',
|
|
@@ -64,7 +62,7 @@ const source = {
|
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
const target = {
|
|
65
|
+
export const target = {
|
|
68
66
|
entity: {
|
|
69
67
|
schema: {
|
|
70
68
|
type: 'object',
|
|
@@ -138,6 +136,3 @@ const target = {
|
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
|
-
|
|
142
|
-
exports.source = source
|
|
143
|
-
exports.target = target
|