@toa.io/norm 0.4.0 → 0.5.0
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/features/component.operations.feature +44 -4
- package/features/steps/.test/manifest.test.js +83 -6
- package/features/steps/manifest.js +39 -12
- package/features/steps/parameters.js +6 -0
- package/package.json +3 -3
- package/src/.component/.normalize/index.js +2 -0
- package/src/.component/.normalize/receivers.js +11 -0
- package/src/.component/normalize.js +2 -1
- package/src/.component/schema.yaml +3 -1
- package/test/component/validate.fixtures.js +1 -0
- package/types/component.d.ts +1 -0
|
@@ -11,13 +11,13 @@ Feature: Operations declaration
|
|
|
11
11
|
foo: string
|
|
12
12
|
bar: 1
|
|
13
13
|
"""
|
|
14
|
-
When I declare assignment with:
|
|
14
|
+
When I declare operation assignment with:
|
|
15
15
|
"""
|
|
16
16
|
<channel>:
|
|
17
17
|
foo: .
|
|
18
18
|
baz: .bar
|
|
19
19
|
"""
|
|
20
|
-
Then normalized assignment declaration must contain:
|
|
20
|
+
Then normalized operation assignment declaration must contain:
|
|
21
21
|
"""
|
|
22
22
|
<channel>:
|
|
23
23
|
type: object
|
|
@@ -38,13 +38,13 @@ Feature: Operations declaration
|
|
|
38
38
|
|
|
39
39
|
Operation IO schemas must be able to reference prototype's entity properties.
|
|
40
40
|
|
|
41
|
-
When I declare assignment with:
|
|
41
|
+
When I declare operation assignment with:
|
|
42
42
|
"""
|
|
43
43
|
output:
|
|
44
44
|
id: .
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
Then normalized assignment declaration must contain:
|
|
47
|
+
Then normalized operation assignment declaration must contain:
|
|
48
48
|
"""
|
|
49
49
|
output:
|
|
50
50
|
type: object
|
|
@@ -52,3 +52,43 @@ Feature: Operations declaration
|
|
|
52
52
|
id:
|
|
53
53
|
$ref: https://schemas.toa.io/0.0.0/definitions#/definitions/id
|
|
54
54
|
"""
|
|
55
|
+
|
|
56
|
+
Scenario: A receiver with binding should contain 'foreign=true'
|
|
57
|
+
When I declare operation transition with:
|
|
58
|
+
"""
|
|
59
|
+
concurrency: none
|
|
60
|
+
output: null
|
|
61
|
+
"""
|
|
62
|
+
When I declare receiver for profile.updated with:
|
|
63
|
+
"""
|
|
64
|
+
path: ''
|
|
65
|
+
bridge: node
|
|
66
|
+
binding: amqp
|
|
67
|
+
transition: transition
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
Then normalized receiver for event profile.updated must contain:
|
|
71
|
+
"""
|
|
72
|
+
foreign: true
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
Scenario: Receiver foreign property should not change if set:
|
|
76
|
+
When I declare operation transition with:
|
|
77
|
+
"""
|
|
78
|
+
concurrency: none
|
|
79
|
+
output: null
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
When I declare receiver for profile.updated with:
|
|
83
|
+
"""
|
|
84
|
+
path: ''
|
|
85
|
+
foreign: false
|
|
86
|
+
bridge: node
|
|
87
|
+
binding: amqp
|
|
88
|
+
transition: transition
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
Then normalized receiver for event profile.updated must contain:
|
|
92
|
+
"""
|
|
93
|
+
foreign: false
|
|
94
|
+
"""
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { AssertionError } = require('assert')
|
|
4
|
+
const { generate } = require('randomstring')
|
|
4
5
|
const { dump } = require('@toa.io/yaml')
|
|
5
|
-
const
|
|
6
|
+
const gherkin = require('@toa.io/tomato')
|
|
6
7
|
|
|
7
8
|
const mock = { gherkin }
|
|
8
9
|
|
|
@@ -15,7 +16,7 @@ it('should be', () => undefined)
|
|
|
15
16
|
let context
|
|
16
17
|
|
|
17
18
|
beforeEach(() => {
|
|
18
|
-
const manifest = {
|
|
19
|
+
const manifest = /** @type {toa.norm.component.Declaration} */ {
|
|
19
20
|
name: 'test',
|
|
20
21
|
namespace: 'features',
|
|
21
22
|
version: '1.0.0',
|
|
@@ -40,8 +41,8 @@ describe('Given I have an entity schema:', () => {
|
|
|
40
41
|
})
|
|
41
42
|
})
|
|
42
43
|
|
|
43
|
-
describe('When I declare {operation} with:', () => {
|
|
44
|
-
const step = gherkin.steps.Wh('I declare {operation} with:')
|
|
44
|
+
describe('When I declare operation {operation} with:', () => {
|
|
45
|
+
const step = gherkin.steps.Wh('I declare operation {operation} with:')
|
|
45
46
|
|
|
46
47
|
it('should be', () => undefined)
|
|
47
48
|
|
|
@@ -57,8 +58,84 @@ describe('When I declare {operation} with:', () => {
|
|
|
57
58
|
})
|
|
58
59
|
})
|
|
59
60
|
|
|
60
|
-
describe('
|
|
61
|
-
const step = gherkin.steps.
|
|
61
|
+
describe('When I declare receiver for {label} with:', () => {
|
|
62
|
+
const step = gherkin.steps.Wh('I declare receiver for {label} with:')
|
|
63
|
+
|
|
64
|
+
it('should be', () => undefined)
|
|
65
|
+
|
|
66
|
+
it('should declare receiver', () => {
|
|
67
|
+
const event = 'assignment'
|
|
68
|
+
const input = { binding: 'amqp' }
|
|
69
|
+
const yaml = dump(input)
|
|
70
|
+
|
|
71
|
+
step.call(context, event, yaml)
|
|
72
|
+
|
|
73
|
+
expect(context.manifest.receivers[event]).toStrictEqual(input)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('Then normalized receiver for event {label} must contain:', () => {
|
|
79
|
+
const step = gherkin.steps.Th('normalized receiver for event {label} must contain:')
|
|
80
|
+
|
|
81
|
+
it('should be', () => undefined)
|
|
82
|
+
|
|
83
|
+
it('should throw if does not contain', async () => {
|
|
84
|
+
const label = generate()
|
|
85
|
+
const operation = generate()
|
|
86
|
+
|
|
87
|
+
context.manifest.operations = {
|
|
88
|
+
[operation]: {
|
|
89
|
+
type: 'transition',
|
|
90
|
+
scope: 'object',
|
|
91
|
+
concurrency: 'none'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
context.manifest.receivers = {
|
|
96
|
+
[label]: {
|
|
97
|
+
path: '',
|
|
98
|
+
bridge: 'node',
|
|
99
|
+
transition: operation,
|
|
100
|
+
binding: 'amqp'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const input = { binding: 'kafka' }
|
|
105
|
+
const yaml = dump({ input })
|
|
106
|
+
|
|
107
|
+
await expect(step.call(context, label, yaml)).rejects.toThrow(AssertionError)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should not throw if contain', async () => {
|
|
111
|
+
const label = generate()
|
|
112
|
+
const operation = generate()
|
|
113
|
+
|
|
114
|
+
context.manifest.operations = {
|
|
115
|
+
[operation]: {
|
|
116
|
+
type: 'transition',
|
|
117
|
+
scope: 'object',
|
|
118
|
+
concurrency: 'none'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
context.manifest.receivers = {
|
|
123
|
+
[label]: {
|
|
124
|
+
path: '',
|
|
125
|
+
bridge: 'node',
|
|
126
|
+
transition: operation,
|
|
127
|
+
binding: 'amqp'
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const yaml = dump({ transition: operation })
|
|
132
|
+
|
|
133
|
+
await expect(step.call(context, label, yaml)).resolves.not.toThrow()
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
describe('Then normalized operation {operation} declaration must contain:', () => {
|
|
138
|
+
const step = gherkin.steps.Th('normalized operation {operation} declaration must contain:')
|
|
62
139
|
|
|
63
140
|
it('should be', () => undefined)
|
|
64
141
|
|
|
@@ -10,6 +10,26 @@ const { component: load } = require('../../src')
|
|
|
10
10
|
|
|
11
11
|
const { Given, When, Then } = require('@cucumber/cucumber')
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @param variant {'operations'| 'receivers'}
|
|
15
|
+
* @param type {string}
|
|
16
|
+
* @param yaml {string}
|
|
17
|
+
* @return {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
async function checkManifest (variant, type, yaml) {
|
|
20
|
+
const temp = await directory.temp()
|
|
21
|
+
const path = join(temp, 'manifest.toa.yaml')
|
|
22
|
+
|
|
23
|
+
await save(this.manifest, path)
|
|
24
|
+
|
|
25
|
+
const manifest = await load(temp)
|
|
26
|
+
const operation = manifest[variant][type]
|
|
27
|
+
const query = parse(yaml)
|
|
28
|
+
const contains = match(operation, query)
|
|
29
|
+
|
|
30
|
+
assert.equal(contains, true)
|
|
31
|
+
}
|
|
32
|
+
|
|
13
33
|
Given('I have an entity schema:',
|
|
14
34
|
/**
|
|
15
35
|
* @param {string} yaml
|
|
@@ -21,7 +41,7 @@ Given('I have an entity schema:',
|
|
|
21
41
|
this.manifest.entity = { schema }
|
|
22
42
|
})
|
|
23
43
|
|
|
24
|
-
When('I declare {operation} with:',
|
|
44
|
+
When('I declare operation {operation} with:',
|
|
25
45
|
/**
|
|
26
46
|
* @param {toa.norm.component.operations.Type} type
|
|
27
47
|
* @param {string} yaml
|
|
@@ -37,24 +57,31 @@ When('I declare {operation} with:',
|
|
|
37
57
|
this.manifest.operations = { [type]: declaration }
|
|
38
58
|
})
|
|
39
59
|
|
|
40
|
-
|
|
60
|
+
When('I declare receiver for {label} with:',
|
|
61
|
+
async function (label, yaml) {
|
|
62
|
+
const declaration = parse(yaml)
|
|
63
|
+
|
|
64
|
+
this.manifest.receivers = { [label]: declaration }
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
Then('normalized operation {operation} declaration must contain:',
|
|
41
68
|
/**
|
|
42
69
|
* @param {toa.norm.component.operations.Type} type
|
|
43
70
|
* @param {string} yaml
|
|
44
71
|
* @this {toa.norm.features.Context}
|
|
45
72
|
*/
|
|
46
73
|
async function (type, yaml) {
|
|
47
|
-
|
|
48
|
-
|
|
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)
|
|
74
|
+
await checkManifest.call(this, 'operations', type, yaml)
|
|
75
|
+
})
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
Then('normalized receiver for event {label} must contain:',
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} label
|
|
80
|
+
* @param {string} yaml
|
|
81
|
+
* @this {toa.norm.features.Context}
|
|
82
|
+
*/
|
|
83
|
+
async function (label, yaml) {
|
|
84
|
+
await checkManifest.call(this, 'receivers', label, yaml)
|
|
58
85
|
})
|
|
59
86
|
|
|
60
87
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@toa.io/mock": "0.
|
|
22
|
+
"@toa.io/mock": "0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@toa.io/core": "0.
|
|
25
|
+
"@toa.io/core": "0.5.0",
|
|
26
26
|
"@toa.io/generic": "0.4.0",
|
|
27
27
|
"@toa.io/schema": "0.4.0",
|
|
28
28
|
"@toa.io/schemas": "0.4.0",
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
const { events } = require('./events')
|
|
4
4
|
const { extensions } = require('./extensions')
|
|
5
5
|
const { operations } = require('./operations')
|
|
6
|
+
const { receivers } = require('./receivers');
|
|
6
7
|
|
|
7
8
|
exports.events = events
|
|
8
9
|
exports.extensions = extensions
|
|
9
10
|
exports.operations = operations
|
|
11
|
+
exports.receivers = receivers
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const receivers = (component) => {
|
|
4
|
+
if (component.receivers === undefined) return
|
|
5
|
+
|
|
6
|
+
for (const receiver of Object.values(component.receivers)) {
|
|
7
|
+
if (receiver.foreign === undefined) receiver.foreign = receiver.binding !== undefined
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.receivers = receivers
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { convolve } = require('@toa.io/generic')
|
|
4
|
-
const { events, operations, extensions } = require('./.normalize')
|
|
4
|
+
const { events, operations, extensions, receivers } = require('./.normalize')
|
|
5
5
|
|
|
6
6
|
const normalize = (component, environment) => {
|
|
7
7
|
convolve(component, environment)
|
|
8
8
|
operations(component)
|
|
9
9
|
events(component)
|
|
10
10
|
extensions(component)
|
|
11
|
+
receivers(component)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
exports.normalize = normalize
|