@toa.io/norm 0.20.0-dev.31 → 0.20.0-dev.34
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/package.json +7 -7
- package/src/.component/schema.yaml +2 -0
- package/src/.context/.dependencies/resolve.js +2 -1
- package/test/component/validate.test.js +6 -0
- package/types/context.d.ts +3 -2
- package/types/index.d.ts +1 -0
- package/features/component.operations.feature +0 -54
- package/features/steps/.test/manifest.test.js +0 -111
- package/features/steps/.types/context.d.ts +0 -9
- package/features/steps/hooks.js +0 -18
- package/features/steps/manifest.js +0 -66
- package/features/steps/parameters.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.20.0-dev.
|
|
3
|
+
"version": "0.20.0-dev.34",
|
|
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,11 +20,11 @@
|
|
|
20
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@toa.io/core": "0.20.0-dev.
|
|
24
|
-
"@toa.io/generic": "0.20.0-dev.
|
|
25
|
-
"@toa.io/schema": "0.20.0-dev.
|
|
26
|
-
"@toa.io/schemas": "0.20.0-dev.
|
|
27
|
-
"@toa.io/yaml": "0.20.0-dev.
|
|
23
|
+
"@toa.io/core": "0.20.0-dev.34",
|
|
24
|
+
"@toa.io/generic": "0.20.0-dev.34",
|
|
25
|
+
"@toa.io/schema": "0.20.0-dev.34",
|
|
26
|
+
"@toa.io/schemas": "0.20.0-dev.34",
|
|
27
|
+
"@toa.io/yaml": "0.20.0-dev.34"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "7035b1985fe9bb844069308a272d061bfbd38bf0"
|
|
30
30
|
}
|
|
@@ -18,7 +18,8 @@ const resolve = (references, annotations) => {
|
|
|
18
18
|
|
|
19
19
|
const instances = components.map((component) => ({
|
|
20
20
|
locator: component.locator,
|
|
21
|
-
manifest: component.extensions?.[id]
|
|
21
|
+
manifest: component.extensions?.[id],
|
|
22
|
+
component
|
|
22
23
|
}))
|
|
23
24
|
|
|
24
25
|
dependencies[dependency] = instances
|
|
@@ -240,4 +240,10 @@ describe('receivers', () => {
|
|
|
240
240
|
|
|
241
241
|
expect(() => validate(manifest)).toThrow(/one of the allowed types/)
|
|
242
242
|
})
|
|
243
|
+
|
|
244
|
+
it('should throw if source has a name `context`', async () => {
|
|
245
|
+
manifest.receivers['foo.bar.happened'].source = 'context'
|
|
246
|
+
|
|
247
|
+
expect(() => validate(manifest)).toThrow(/must NOT be valid/)
|
|
248
|
+
})
|
|
243
249
|
})
|
package/types/context.d.ts
CHANGED
|
@@ -23,9 +23,10 @@ interface Composition {
|
|
|
23
23
|
components: _component.Component[]
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export interface Dependency {
|
|
26
|
+
export interface Dependency<T = undefined> {
|
|
27
27
|
locator: Locator
|
|
28
|
-
manifest
|
|
28
|
+
manifest: T,
|
|
29
|
+
component: _component.Component
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
interface Context extends Declaration {
|
package/types/index.d.ts
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Feature: Operations declaration
|
|
2
|
-
|
|
3
|
-
Scenario Outline: Operation <channel> entity references
|
|
4
|
-
|
|
5
|
-
Operation IO schemas may reference entity's properties using syntax:
|
|
6
|
-
- `.` - entity's property with the same name
|
|
7
|
-
- '.foo` - entity's property with `foo` name
|
|
8
|
-
|
|
9
|
-
Given I have an entity schema:
|
|
10
|
-
"""
|
|
11
|
-
foo: string
|
|
12
|
-
bar: 1
|
|
13
|
-
"""
|
|
14
|
-
When I declare assignment with:
|
|
15
|
-
"""
|
|
16
|
-
<channel>:
|
|
17
|
-
foo: .
|
|
18
|
-
baz: .bar
|
|
19
|
-
"""
|
|
20
|
-
Then normalized assignment declaration must contain:
|
|
21
|
-
"""
|
|
22
|
-
<channel>:
|
|
23
|
-
type: object
|
|
24
|
-
properties:
|
|
25
|
-
foo:
|
|
26
|
-
type: string
|
|
27
|
-
baz:
|
|
28
|
-
type: number
|
|
29
|
-
default: 1
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
Examples:
|
|
33
|
-
| channel |
|
|
34
|
-
| input |
|
|
35
|
-
| output |
|
|
36
|
-
|
|
37
|
-
Scenario: Prototype property reference
|
|
38
|
-
|
|
39
|
-
Operation IO schemas must be able to reference prototype's entity properties.
|
|
40
|
-
|
|
41
|
-
When I declare assignment with:
|
|
42
|
-
"""
|
|
43
|
-
output:
|
|
44
|
-
id: .
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
Then normalized assignment declaration must contain:
|
|
48
|
-
"""
|
|
49
|
-
output:
|
|
50
|
-
type: object
|
|
51
|
-
properties:
|
|
52
|
-
id:
|
|
53
|
-
$ref: https://schemas.toa.io/0.0.0/definitions#/definitions/id
|
|
54
|
-
"""
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { AssertionError } = require('assert')
|
|
4
|
-
const { generate } = require('randomstring')
|
|
5
|
-
const { dump } = require('@toa.io/yaml')
|
|
6
|
-
const gherkin = require('@toa.io/tomato')
|
|
7
|
-
|
|
8
|
-
const mock = { gherkin }
|
|
9
|
-
|
|
10
|
-
jest.mock('@cucumber/cucumber', () => mock.gherkin)
|
|
11
|
-
require('../manifest')
|
|
12
|
-
|
|
13
|
-
it('should be', () => undefined)
|
|
14
|
-
|
|
15
|
-
/** @type {toa.norm.features.Context} */
|
|
16
|
-
let context
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
const manifest = /** @type {toa.norm.component.Declaration} */ {
|
|
20
|
-
name: 'test',
|
|
21
|
-
namespace: 'features',
|
|
22
|
-
version: '1.0.0',
|
|
23
|
-
entity: null
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
context = { manifest }
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('Given I have an entity schema:', () => {
|
|
30
|
-
const step = gherkin.steps.Gi('I have an entity schema:')
|
|
31
|
-
|
|
32
|
-
it('should be', () => undefined)
|
|
33
|
-
|
|
34
|
-
it('should set entity schema', () => {
|
|
35
|
-
const schema = { foo: 'string' }
|
|
36
|
-
const yaml = dump(schema)
|
|
37
|
-
|
|
38
|
-
step.call(context, yaml)
|
|
39
|
-
|
|
40
|
-
expect(context.manifest.entity).toStrictEqual({ schema })
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('When I declare {operation} with:', () => {
|
|
45
|
-
const step = gherkin.steps.Wh('I declare {operation} with:')
|
|
46
|
-
|
|
47
|
-
it('should be', () => undefined)
|
|
48
|
-
|
|
49
|
-
it('should declare operation', () => {
|
|
50
|
-
const type = 'assignment'
|
|
51
|
-
const scope = 'changeset'
|
|
52
|
-
const input = {}
|
|
53
|
-
const yaml = dump(input)
|
|
54
|
-
|
|
55
|
-
step.call(context, type, yaml)
|
|
56
|
-
|
|
57
|
-
expect(context.manifest.operations[type]).toStrictEqual({ type, scope })
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('Then normalized {operation} declaration must contain:', () => {
|
|
62
|
-
const step = gherkin.steps.Th('normalized {operation} declaration must contain:')
|
|
63
|
-
|
|
64
|
-
it('should be', () => undefined)
|
|
65
|
-
|
|
66
|
-
it('should throw if does not contain', async () => {
|
|
67
|
-
const type = 'assignment'
|
|
68
|
-
|
|
69
|
-
context.manifest.operations = {
|
|
70
|
-
[type]: {
|
|
71
|
-
type,
|
|
72
|
-
input: { bar: 'number' },
|
|
73
|
-
scope: 'changeset'
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const input = {
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: {
|
|
80
|
-
bar: { type: 'string' }
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const yaml = dump({ input })
|
|
85
|
-
|
|
86
|
-
await expect(step.call(context, type, yaml)).rejects.toThrow(AssertionError)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should not throw if contain', async () => {
|
|
90
|
-
const type = 'assignment'
|
|
91
|
-
|
|
92
|
-
context.manifest.operations = {
|
|
93
|
-
[type]: {
|
|
94
|
-
type,
|
|
95
|
-
input: { bar: 'number' },
|
|
96
|
-
scope: 'changeset'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const input = {
|
|
101
|
-
type: 'object',
|
|
102
|
-
properties: {
|
|
103
|
-
bar: { type: 'number' }
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const yaml = dump({ input })
|
|
108
|
-
|
|
109
|
-
await expect(step.call(context, type, yaml)).resolves.not.toThrow()
|
|
110
|
-
})
|
|
111
|
-
})
|
package/features/steps/hooks.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Before } = require('@cucumber/cucumber')
|
|
4
|
-
|
|
5
|
-
Before(
|
|
6
|
-
/**
|
|
7
|
-
* @this {toa.norm.features.Context}
|
|
8
|
-
*/
|
|
9
|
-
function () {
|
|
10
|
-
this.manifest = {
|
|
11
|
-
name: 'test',
|
|
12
|
-
namespace: 'features',
|
|
13
|
-
version: '1.0.0',
|
|
14
|
-
entity: {
|
|
15
|
-
storage: null
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
})
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const assert = require('node:assert')
|
|
4
|
-
const { join } = require('node:path')
|
|
5
|
-
const { parse, save } = require('@toa.io/yaml')
|
|
6
|
-
const { directory } = require('@toa.io/filesystem')
|
|
7
|
-
const { match } = require('@toa.io/generic')
|
|
8
|
-
|
|
9
|
-
const { component: load } = require('../../src')
|
|
10
|
-
|
|
11
|
-
const { Given, When, Then } = require('@cucumber/cucumber')
|
|
12
|
-
|
|
13
|
-
Given('I have an entity schema:',
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} yaml
|
|
16
|
-
* @this {toa.norm.features.Context}
|
|
17
|
-
*/
|
|
18
|
-
function (yaml) {
|
|
19
|
-
const schema = parse(yaml)
|
|
20
|
-
|
|
21
|
-
this.manifest.entity = { schema }
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
When('I declare {operation} with:',
|
|
25
|
-
/**
|
|
26
|
-
* @param {toa.norm.component.operations.Type} type
|
|
27
|
-
* @param {string} yaml
|
|
28
|
-
* @this {toa.norm.features.Context}
|
|
29
|
-
*/
|
|
30
|
-
function (type, yaml) {
|
|
31
|
-
/** @type {toa.norm.component.Operation} */
|
|
32
|
-
const declaration = parse(yaml)
|
|
33
|
-
|
|
34
|
-
declaration.type = type
|
|
35
|
-
declaration.scope = scope(type)
|
|
36
|
-
|
|
37
|
-
this.manifest.operations = { [type]: declaration }
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
Then('normalized {operation} declaration must contain:',
|
|
41
|
-
/**
|
|
42
|
-
* @param {toa.norm.component.operations.Type} type
|
|
43
|
-
* @param {string} yaml
|
|
44
|
-
* @this {toa.norm.features.Context}
|
|
45
|
-
*/
|
|
46
|
-
async function (type, yaml) {
|
|
47
|
-
const temp = await directory.temp()
|
|
48
|
-
const path = join(temp, 'manifest.toa.yaml')
|
|
49
|
-
|
|
50
|
-
await save(this.manifest, path)
|
|
51
|
-
|
|
52
|
-
const manifest = await load(temp)
|
|
53
|
-
const operation = manifest.operations[type]
|
|
54
|
-
const query = parse(yaml)
|
|
55
|
-
const contains = match(operation, query)
|
|
56
|
-
|
|
57
|
-
assert.equal(contains, true)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @param {toa.norm.component.operations.Type} type
|
|
62
|
-
* @returns {toa.norm.component.operations.Scope}
|
|
63
|
-
*/
|
|
64
|
-
const scope = (type) => {
|
|
65
|
-
return type === 'assignment' ? 'changeset' : 'object'
|
|
66
|
-
}
|