@toa.io/norm 0.6.0-dev.0 → 0.6.0-dev.3
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/LICENSE +22 -0
- package/features/component.operations.feature +4 -44
- package/features/steps/.test/manifest.test.js +4 -80
- package/features/steps/manifest.js +12 -39
- package/features/steps/parameters.js +0 -6
- package/package.json +9 -8
- package/src/.component/.normalize/index.js +0 -2
- package/src/.component/normalize.js +1 -2
- package/src/.component/schema.yaml +1 -3
- package/test/component/validate.fixtures.js +0 -1
- package/types/component.d.ts +0 -1
- package/src/.component/.normalize/receivers.js +0 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2020-present Artem Gurtovoi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -11,13 +11,13 @@ Feature: Operations declaration
|
|
|
11
11
|
foo: string
|
|
12
12
|
bar: 1
|
|
13
13
|
"""
|
|
14
|
-
When I declare
|
|
14
|
+
When I declare assignment with:
|
|
15
15
|
"""
|
|
16
16
|
<channel>:
|
|
17
17
|
foo: .
|
|
18
18
|
baz: .bar
|
|
19
19
|
"""
|
|
20
|
-
Then normalized
|
|
20
|
+
Then normalized 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
|
|
41
|
+
When I declare assignment with:
|
|
42
42
|
"""
|
|
43
43
|
output:
|
|
44
44
|
id: .
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
Then normalized
|
|
47
|
+
Then normalized assignment declaration must contain:
|
|
48
48
|
"""
|
|
49
49
|
output:
|
|
50
50
|
type: object
|
|
@@ -52,43 +52,3 @@ 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
|
-
"""
|
|
@@ -41,8 +41,8 @@ describe('Given I have an entity schema:', () => {
|
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
describe('When I declare
|
|
45
|
-
const step = gherkin.steps.Wh('I declare
|
|
44
|
+
describe('When I declare {operation} with:', () => {
|
|
45
|
+
const step = gherkin.steps.Wh('I declare {operation} with:')
|
|
46
46
|
|
|
47
47
|
it('should be', () => undefined)
|
|
48
48
|
|
|
@@ -58,84 +58,8 @@ describe('When I declare operation {operation} with:', () => {
|
|
|
58
58
|
})
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
describe('
|
|
62
|
-
const step = gherkin.steps.
|
|
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 = 'save'
|
|
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:')
|
|
61
|
+
describe('Then normalized {operation} declaration must contain:', () => {
|
|
62
|
+
const step = gherkin.steps.Th('normalized {operation} declaration must contain:')
|
|
139
63
|
|
|
140
64
|
it('should be', () => undefined)
|
|
141
65
|
|
|
@@ -10,26 +10,6 @@ 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
|
-
|
|
33
13
|
Given('I have an entity schema:',
|
|
34
14
|
/**
|
|
35
15
|
* @param {string} yaml
|
|
@@ -41,7 +21,7 @@ Given('I have an entity schema:',
|
|
|
41
21
|
this.manifest.entity = { schema }
|
|
42
22
|
})
|
|
43
23
|
|
|
44
|
-
When('I declare
|
|
24
|
+
When('I declare {operation} with:',
|
|
45
25
|
/**
|
|
46
26
|
* @param {toa.norm.component.operations.Type} type
|
|
47
27
|
* @param {string} yaml
|
|
@@ -57,31 +37,24 @@ When('I declare operation {operation} with:',
|
|
|
57
37
|
this.manifest.operations = { [type]: declaration }
|
|
58
38
|
})
|
|
59
39
|
|
|
60
|
-
|
|
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:',
|
|
40
|
+
Then('normalized {operation} declaration must contain:',
|
|
68
41
|
/**
|
|
69
42
|
* @param {toa.norm.component.operations.Type} type
|
|
70
43
|
* @param {string} yaml
|
|
71
44
|
* @this {toa.norm.features.Context}
|
|
72
45
|
*/
|
|
73
46
|
async function (type, yaml) {
|
|
74
|
-
await
|
|
75
|
-
|
|
47
|
+
const temp = await directory.temp()
|
|
48
|
+
const path = join(temp, 'manifest.toa.yaml')
|
|
76
49
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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)
|
|
85
58
|
})
|
|
86
59
|
|
|
87
60
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.3",
|
|
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,13 +19,14 @@
|
|
|
19
19
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@toa.io/mock": "0.6.0-dev.
|
|
22
|
+
"@toa.io/mock": "0.6.0-dev.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@toa.io/core": "0.6.0-dev.
|
|
26
|
-
"@toa.io/generic": "0.6.0-dev.
|
|
27
|
-
"@toa.io/schema": "0.6.0-dev.
|
|
28
|
-
"@toa.io/schemas": "0.6.0-dev.
|
|
29
|
-
"@toa.io/yaml": "0.6.0-dev.
|
|
30
|
-
}
|
|
25
|
+
"@toa.io/core": "0.6.0-dev.3",
|
|
26
|
+
"@toa.io/generic": "0.6.0-dev.1",
|
|
27
|
+
"@toa.io/schema": "0.6.0-dev.1",
|
|
28
|
+
"@toa.io/schemas": "0.6.0-dev.1",
|
|
29
|
+
"@toa.io/yaml": "0.6.0-dev.1"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "08ffb832d6593ec1b42bff71cfbfd8fcd871c501"
|
|
31
32
|
}
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
const { events } = require('./events')
|
|
4
4
|
const { extensions } = require('./extensions')
|
|
5
5
|
const { operations } = require('./operations')
|
|
6
|
-
const { receivers } = require('./receivers');
|
|
7
6
|
|
|
8
7
|
exports.events = events
|
|
9
8
|
exports.extensions = extensions
|
|
10
9
|
exports.operations = operations
|
|
11
|
-
exports.receivers = receivers
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { convolve } = require('@toa.io/generic')
|
|
4
|
-
const { events, operations, extensions
|
|
4
|
+
const { events, operations, extensions } = 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)
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
exports.normalize = normalize
|
package/types/component.d.ts
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
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
|