@toa.io/norm 1.0.0-alpha.28 → 1.0.0-alpha.283
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 +195 -0
- package/package.json +8 -7
- package/src/.component/.expand/bridge.js +2 -6
- package/src/.component/.expand/entity.js +2 -9
- package/src/.component/.expand/events.js +2 -6
- package/src/.component/.expand/extensions.js +4 -8
- package/src/.component/.expand/index.js +8 -19
- package/src/.component/.expand/operations.js +2 -9
- package/src/.component/.expand/properties.js +2 -6
- package/src/.component/.expand/receivers.js +2 -6
- package/src/.component/.expand/version.js +39 -27
- package/src/.component/.normalize/events.js +12 -5
- package/src/.component/.normalize/index.js +3 -9
- package/src/.component/.normalize/operations.js +2 -6
- package/src/.component/.normalize/receivers.js +1 -5
- package/src/.component/collapse.js +7 -6
- package/src/.component/defaults.js +14 -7
- package/src/.component/dependencies.js +7 -6
- package/src/.component/dereference.js +8 -7
- package/src/.component/expand.js +2 -15
- package/src/.component/extensions.js +13 -7
- package/src/.component/index.js +9 -21
- package/src/.component/merge.js +22 -9
- package/src/.component/normalize.js +3 -7
- package/src/.component/schema.yaml +82 -41
- package/src/.component/validate.js +15 -16
- package/src/.context/.dependencies/connectors.js +2 -6
- package/src/.context/.dependencies/describe.js +1 -5
- package/src/.context/.dependencies/extensions.js +55 -18
- package/src/.context/.dependencies/index.js +3 -9
- package/src/.context/.dependencies/load.js +14 -13
- package/src/.context/.dependencies/resolve.js +23 -6
- package/src/.context/complete.js +1 -5
- package/src/.context/dependencies.js +2 -6
- package/src/.context/dereference.js +9 -6
- package/src/.context/expand.js +8 -6
- package/src/.context/index.js +6 -15
- package/src/.context/normalize.js +2 -6
- package/src/.context/schema.yaml +126 -7
- package/src/.context/validate.js +8 -14
- package/src/component.js +31 -28
- package/src/context.js +28 -20
- package/src/index.js +3 -9
- package/src/shortcuts.js +7 -12
- 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 +13 -13
- package/test/component/expand.test.js +25 -10
- package/test/component/normalize.fixtures.js +3 -7
- package/test/component/normalize.test.js +27 -17
- package/test/component/validate.fixtures.js +1 -5
- package/test/component/validate.test.js +89 -90
- package/test/context/complete.fixtures.js +2 -8
- package/test/context/complete.test.js +10 -8
- package/test/context/dependencies.load.test.js +13 -12
- package/test/context/dereference.fixtures.js +3 -9
- package/test/context/dereference.test.js +17 -7
- package/test/context/expand.fixtures.js +1 -5
- package/test/context/expand.test.js +34 -8
- package/test/context/normalize.fixtures.js +2 -7
- package/test/context/normalize.test.js +10 -8
- package/test/context/validate.fixtures.js +1 -6
- package/test/context/validate.test.js +54 -30
- package/test/shortcuts.fixtures.js +4 -9
- package/test/shortcuts.test.js +16 -15
- package/types/context/declaration.d.ts +25 -2
- package/types/context.d.ts +5 -4
- package/types/index.d.ts +3 -3
|
@@ -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,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const source = {
|
|
4
|
-
path: '',
|
|
1
|
+
export const source = {
|
|
2
|
+
path: import.meta.dirname, // `version` hashes the component directory
|
|
5
3
|
entity: {
|
|
6
4
|
schema: {
|
|
5
|
+
type: 'object',
|
|
7
6
|
properties: {
|
|
8
|
-
foo: 'string'
|
|
7
|
+
foo: { type: 'string' }
|
|
9
8
|
}
|
|
10
9
|
},
|
|
11
10
|
storage: 'mongodb'
|
|
@@ -16,26 +15,30 @@ const source = {
|
|
|
16
15
|
bridge: 'node',
|
|
17
16
|
bindings: ['amqp'],
|
|
18
17
|
input: {
|
|
18
|
+
type: 'object',
|
|
19
19
|
properties: {
|
|
20
|
-
foo: 'integer',
|
|
20
|
+
foo: { type: 'integer' },
|
|
21
21
|
bar: {
|
|
22
22
|
type: 'array',
|
|
23
23
|
items: {
|
|
24
|
+
type: 'object',
|
|
24
25
|
properties: {
|
|
25
|
-
baz: 'string'
|
|
26
|
+
baz: { type: 'string' }
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
output: {
|
|
33
|
+
type: 'object',
|
|
32
34
|
properties: {
|
|
33
|
-
foo: 'integer',
|
|
35
|
+
foo: { type: 'integer' },
|
|
34
36
|
bar: {
|
|
35
37
|
type: 'array',
|
|
36
38
|
items: {
|
|
39
|
+
type: 'object',
|
|
37
40
|
properties: {
|
|
38
|
-
baz: 'string'
|
|
41
|
+
baz: { type: 'string' }
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -59,7 +62,7 @@ const source = {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
const target = {
|
|
65
|
+
export const target = {
|
|
63
66
|
entity: {
|
|
64
67
|
schema: {
|
|
65
68
|
type: 'object',
|
|
@@ -133,6 +136,3 @@ const target = {
|
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
exports.source = source
|
|
138
|
-
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 { expand } from '../../src/.component/index.js'
|
|
7
|
+
import * as fixtures from './expand.fixtures.js'
|
|
7
8
|
|
|
8
9
|
let source
|
|
9
10
|
|
|
@@ -11,9 +12,23 @@ beforeEach(() => {
|
|
|
11
12
|
source = clone(fixtures.source)
|
|
12
13
|
})
|
|
13
14
|
|
|
14
|
-
it('should expand', () => {
|
|
15
|
-
expand(source)
|
|
16
|
-
|
|
15
|
+
it('should expand', async () => {
|
|
16
|
+
await expand(source)
|
|
17
|
+
assert.partialDeepStrictEqual(source, fixtures.target)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should derive version from the component contents', async () => {
|
|
21
|
+
await expand(source)
|
|
22
|
+
|
|
23
|
+
assert.match(source.version, /^[0-9a-f]{8}$/)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should keep declared version', async () => {
|
|
27
|
+
source.version = '1.0.0'
|
|
28
|
+
|
|
29
|
+
await expand(source)
|
|
30
|
+
|
|
31
|
+
assert.deepStrictEqual(source.version, '1.0.0')
|
|
17
32
|
})
|
|
18
33
|
|
|
19
34
|
it('should recognize storages.queues', async () => {
|
|
@@ -21,8 +36,8 @@ it('should recognize storages.queues', async () => {
|
|
|
21
36
|
|
|
22
37
|
source.queues = clone(queues)
|
|
23
38
|
|
|
24
|
-
expand(source)
|
|
39
|
+
await expand(source)
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
assert.strictEqual(source.queues, undefined)
|
|
42
|
+
assert.partialDeepStrictEqual(source.properties['@toa.io/storages.queues'], queues)
|
|
28
43
|
})
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { generate } from 'randomstring'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const operations = {
|
|
3
|
+
export const operations = {
|
|
6
4
|
namespace: 'dummies',
|
|
7
5
|
name: 'dummy',
|
|
8
|
-
path:
|
|
6
|
+
path: import.meta.dirname,
|
|
9
7
|
bindings: ['foo', 'bar'],
|
|
10
8
|
'bindings@local': ['foo'],
|
|
11
9
|
operations: {
|
|
@@ -22,5 +20,3 @@ const operations = {
|
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
exports.operations = operations
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const clone = require('clone-deep')
|
|
4
|
+
import clone from 'clone-deep'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { normalize, extensions } from '../../src/.component/index.js'
|
|
7
|
+
import * as fixtures from './normalize.fixtures.js'
|
|
8
8
|
|
|
9
9
|
let manifest
|
|
10
10
|
|
|
@@ -13,21 +13,31 @@ beforeEach(() => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
describe('operations', () => {
|
|
16
|
-
it('should set default bindings', () => {
|
|
17
|
-
normalize(manifest)
|
|
16
|
+
it('should set default bindings', async () => {
|
|
17
|
+
await normalize(manifest)
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
assert.deepStrictEqual(manifest.operations.add.bindings, manifest.bindings)
|
|
20
20
|
})
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
describe('extensions', () => {
|
|
24
|
-
it('should
|
|
25
|
-
|
|
26
|
-
const path = dirname(require.resolve('@toa.io/extensions.origins/package.json'))
|
|
24
|
+
it('should add predefined extensions', async () => {
|
|
25
|
+
await extensions(manifest)
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
assert.strictEqual(manifest.extensions['@toa.io/extensions.telemetry'], null)
|
|
28
|
+
assert.strictEqual(manifest.extensions['@toa.io/extensions.fetch'], null)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should add predefined extensions without explicit declarations', async () => {
|
|
32
|
+
delete manifest.extensions
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
await extensions(manifest)
|
|
35
|
+
|
|
36
|
+
assert.deepStrictEqual(manifest.extensions, {
|
|
37
|
+
'@toa.io/extensions.telemetry': null,
|
|
38
|
+
'@toa.io/extensions.fetch': null,
|
|
39
|
+
'@toa.io/extensions.introspection': {}
|
|
40
|
+
})
|
|
31
41
|
})
|
|
32
42
|
})
|
|
33
43
|
|
|
@@ -37,9 +47,9 @@ describe('receivers', () => {
|
|
|
37
47
|
'messages.created': 'add'
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
normalize(manifest)
|
|
50
|
+
await normalize(manifest)
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
assert.deepStrictEqual(manifest.receivers, {
|
|
43
53
|
'default.messages.created': 'add'
|
|
44
54
|
})
|
|
45
55
|
})
|
|
@@ -54,9 +64,9 @@ describe('receivers', () => {
|
|
|
54
64
|
'messages.created': receiver
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
normalize(manifest)
|
|
67
|
+
await normalize(manifest)
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
assert.deepStrictEqual(manifest.receivers, {
|
|
60
70
|
'messages.created': receiver
|
|
61
71
|
})
|
|
62
72
|
})
|