@toa.io/norm 1.0.0-alpha.272 → 1.0.0-alpha.273
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 +8 -0
- package/package.json +7 -6
- package/src/.component/.expand/entity.js +0 -3
- package/src/.component/.expand/operations.js +0 -3
- package/src/.component/extensions.js +1 -1
- package/src/.component/validate.js +3 -2
- package/src/.context/validate.js +3 -2
- package/src/component.js +17 -3
- package/src/context.js +21 -4
- package/test/component/expand.fixtures.js +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.273](https://github.com/toa-io/toa/compare/v1.0.0-alpha.272...v1.0.0-alpha.273) (2026-09-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @toa.io/norm
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [1.0.0-alpha.272](https://github.com/toa-io/toa/compare/v1.0.0-alpha.271...v1.0.0-alpha.272) (2026-09-01)
|
|
7
15
|
|
|
8
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.273",
|
|
4
4
|
"description": "Toa declarations normalization and validation",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -20,10 +20,11 @@
|
|
|
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/generic": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/schemas": "1.0.0-alpha.
|
|
26
|
-
"
|
|
23
|
+
"@toa.io/core": "1.0.0-alpha.273",
|
|
24
|
+
"@toa.io/generic": "1.0.0-alpha.273",
|
|
25
|
+
"@toa.io/schemas": "1.0.0-alpha.273",
|
|
26
|
+
"fast-glob": "3.2.12",
|
|
27
|
+
"js-yaml": "4.3.1"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "ad3284850ece95ffd5325fd0995707fc144c9c3d"
|
|
29
30
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { expand } = require('@toa.io/schemas')
|
|
4
|
-
|
|
5
3
|
const { resolve } = require('../../shortcuts')
|
|
6
4
|
|
|
7
5
|
function entity (manifest) {
|
|
8
6
|
if (!('entity' in manifest)) return
|
|
9
|
-
if ('schema' in manifest.entity) manifest.entity.schema = expand(manifest.entity.schema)
|
|
10
7
|
|
|
11
8
|
manifest.entity.storage = resolve(manifest.entity.storage)
|
|
12
9
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { expand } = require('@toa.io/schemas')
|
|
4
3
|
const { resolve } = require('../../shortcuts')
|
|
5
4
|
|
|
6
5
|
function operations (manifest) {
|
|
7
6
|
if (manifest.operations === undefined) return
|
|
8
7
|
|
|
9
8
|
for (const operation of Object.values(manifest.operations)) {
|
|
10
|
-
if (operation.input !== undefined) operation.input = expand(operation.input)
|
|
11
|
-
if (operation.output !== undefined) operation.output = expand(operation.output)
|
|
12
9
|
if (operation.bridge !== undefined) operation.bridge = resolve(operation.bridge)
|
|
13
10
|
|
|
14
11
|
if (operation.bindings !== undefined && operation.bindings !== null) {
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('node:path')
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { readFileSync } = require('node:fs')
|
|
6
|
+
const { load: parseYAML } = require('js-yaml')
|
|
6
7
|
const schemas = require('@toa.io/schemas')
|
|
7
8
|
|
|
8
|
-
const object =
|
|
9
|
+
const object = parseYAML(readFileSync(path.resolve(__dirname, 'schema.yaml'), 'utf8'))
|
|
9
10
|
const schema = schemas.schema(object)
|
|
10
11
|
|
|
11
12
|
const validate = (manifest) => {
|
package/src/.context/validate.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const { resolve } = require('node:path')
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { readFileSync } = require('node:fs')
|
|
6
|
+
const { load: parseYAML } = require('js-yaml')
|
|
6
7
|
const schemas = require('@toa.io/schemas')
|
|
7
8
|
|
|
8
9
|
const path = resolve(__dirname, 'schema.yaml')
|
|
9
|
-
const object =
|
|
10
|
+
const object = parseYAML(readFileSync(path, 'utf8'))
|
|
10
11
|
const schema = schemas.schema(object)
|
|
11
12
|
|
|
12
13
|
const validate = (context) => {
|
package/src/component.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const { join } = require('node:path')
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
const
|
|
5
|
+
const { readFile } = require('node:fs/promises')
|
|
6
|
+
const jsyaml = require('js-yaml')
|
|
7
|
+
const { find } = require('@toa.io/generic')
|
|
7
8
|
const { Locator } = require('@toa.io/core')
|
|
8
9
|
|
|
9
10
|
const {
|
|
@@ -33,7 +34,7 @@ const load = async (path, base, proto = false) => {
|
|
|
33
34
|
if (base !== undefined) path = find(path, base, MANIFEST)
|
|
34
35
|
|
|
35
36
|
const file = join(path, MANIFEST)
|
|
36
|
-
const manifest = await
|
|
37
|
+
const manifest = await read(file) ?? {}
|
|
37
38
|
|
|
38
39
|
manifest.path = path
|
|
39
40
|
|
|
@@ -57,3 +58,16 @@ const load = async (path, base, proto = false) => {
|
|
|
57
58
|
const MANIFEST = 'manifest.toa.yaml'
|
|
58
59
|
|
|
59
60
|
exports.component = component
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Reads a YAML file, resolving anchors into distinct objects so that
|
|
64
|
+
* mutating one node cannot reach another.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} path
|
|
67
|
+
* @return {Promise<object>}
|
|
68
|
+
*/
|
|
69
|
+
async function read (path) {
|
|
70
|
+
const object = jsyaml.load(await readFile(path, 'utf8'))
|
|
71
|
+
|
|
72
|
+
return jsyaml.load(jsyaml.dump(object, { noRefs: true, lineWidth: -1 }))
|
|
73
|
+
}
|
package/src/context.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const { resolve } = require('node:path')
|
|
4
4
|
const { convolve } = require('@toa.io/generic')
|
|
5
|
-
const
|
|
6
|
-
const {
|
|
5
|
+
const glob = require('fast-glob')
|
|
6
|
+
const { readFile } = require('node:fs/promises')
|
|
7
|
+
const jsyaml = require('js-yaml')
|
|
7
8
|
|
|
8
9
|
const { component } = require('./component')
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ const {
|
|
|
18
19
|
|
|
19
20
|
const context = async (root, environment = process.env.TOA_ENV) => {
|
|
20
21
|
const path = resolve(root, CONTEXT)
|
|
21
|
-
const context = /** @type {toa.norm.Context} */ await
|
|
22
|
+
const context = /** @type {toa.norm.Context} */ await read(path)
|
|
22
23
|
|
|
23
24
|
context.environment = environment
|
|
24
25
|
|
|
@@ -28,7 +29,7 @@ const context = async (root, environment = process.env.TOA_ENV) => {
|
|
|
28
29
|
|
|
29
30
|
validate(context)
|
|
30
31
|
|
|
31
|
-
const paths = await glob(resolve(root, COMPONENTS))
|
|
32
|
+
const paths = await glob(resolve(root, COMPONENTS), GLOB)
|
|
32
33
|
|
|
33
34
|
context.components = await Promise.all(paths.map(component))
|
|
34
35
|
context.dependencies = await dependencies(context)
|
|
@@ -42,4 +43,20 @@ const context = async (root, environment = process.env.TOA_ENV) => {
|
|
|
42
43
|
const CONTEXT = 'context.toa.yaml'
|
|
43
44
|
const COMPONENTS = 'components/*'
|
|
44
45
|
|
|
46
|
+
|
|
47
|
+
const GLOB = { onlyDirectories: true, absolute: true }
|
|
48
|
+
|
|
45
49
|
exports.context = context
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reads a YAML file, resolving anchors into distinct objects so that
|
|
53
|
+
* mutating one node cannot reach another.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} path
|
|
56
|
+
* @return {Promise<object>}
|
|
57
|
+
*/
|
|
58
|
+
async function read (path) {
|
|
59
|
+
const object = jsyaml.load(await readFile(path, 'utf8'))
|
|
60
|
+
|
|
61
|
+
return jsyaml.load(jsyaml.dump(object, { noRefs: true, lineWidth: -1 }))
|
|
62
|
+
}
|
|
@@ -4,8 +4,9 @@ const source = {
|
|
|
4
4
|
path: __dirname, // `version` hashes the component directory
|
|
5
5
|
entity: {
|
|
6
6
|
schema: {
|
|
7
|
+
type: 'object',
|
|
7
8
|
properties: {
|
|
8
|
-
foo: 'string'
|
|
9
|
+
foo: { type: 'string' }
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
storage: 'mongodb'
|
|
@@ -16,26 +17,30 @@ const source = {
|
|
|
16
17
|
bridge: 'node',
|
|
17
18
|
bindings: ['amqp'],
|
|
18
19
|
input: {
|
|
20
|
+
type: 'object',
|
|
19
21
|
properties: {
|
|
20
|
-
foo: 'integer',
|
|
22
|
+
foo: { type: 'integer' },
|
|
21
23
|
bar: {
|
|
22
24
|
type: 'array',
|
|
23
25
|
items: {
|
|
26
|
+
type: 'object',
|
|
24
27
|
properties: {
|
|
25
|
-
baz: 'string'
|
|
28
|
+
baz: { type: 'string' }
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
output: {
|
|
35
|
+
type: 'object',
|
|
32
36
|
properties: {
|
|
33
|
-
foo: 'integer',
|
|
37
|
+
foo: { type: 'integer' },
|
|
34
38
|
bar: {
|
|
35
39
|
type: 'array',
|
|
36
40
|
items: {
|
|
41
|
+
type: 'object',
|
|
37
42
|
properties: {
|
|
38
|
-
baz: 'string'
|
|
43
|
+
baz: { type: 'string' }
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
}
|