@toa.io/norm 0.4.0-dev.9 → 0.5.0-dev.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.
@@ -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 { gherkin } = require('@toa.io/mock')
6
+ const gherkin = require('@toa.io/tomato')
6
7
 
7
8
  const mock = { gherkin }
8
9
 
@@ -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,90 @@ describe('When I declare {operation} with:', () => {
57
58
  })
58
59
  })
59
60
 
60
- describe('Then normalized {operation} declaration must contain:', () => {
61
- const step = gherkin.steps.Th('normalized {operation} declaration must contain:')
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 = {
69
+ binding: 'amqp'
70
+ }
71
+ const yaml = dump(input)
72
+
73
+ step.call(context, event, yaml)
74
+ expect(context.manifest.receivers[event]).toStrictEqual(input)
75
+ })
76
+
77
+ })
78
+
79
+ describe('Then normalized receiver for event {label} must contain:', () => {
80
+ const step = gherkin.steps.Th('normalized receiver for event {label} must contain:')
81
+
82
+ it('should be', () => undefined)
83
+
84
+ it('should throw if does not contain', async () => {
85
+ const label = generate()
86
+ const operation = generate();
87
+
88
+ context.manifest.operations = {
89
+ [operation]: {
90
+ type: 'transition',
91
+ scope: 'object',
92
+ concurrency: 'none'
93
+ }
94
+ }
95
+
96
+ context.manifest.receivers = {
97
+ [label]: {
98
+ path: '',
99
+ bridge: 'node',
100
+ transition: operation,
101
+ binding: 'amqp'
102
+ }
103
+ }
104
+
105
+ const input = {
106
+ binding: 'sql',
107
+ }
108
+
109
+ const yaml = dump({ input })
110
+
111
+ await expect(step.call(context, label, yaml)).rejects.toThrow(AssertionError)
112
+ })
113
+
114
+ it('should not throw if contain', async () => {
115
+ const label = generate()
116
+ const operation = generate();
117
+
118
+ context.manifest.operations = {
119
+ [operation]: {
120
+ type: 'transition',
121
+ scope: 'object',
122
+ concurrency: 'none'
123
+ }
124
+ }
125
+
126
+ context.manifest.receivers = {
127
+ [label]: {
128
+ path: '',
129
+ bridge: 'node',
130
+ transition: operation,
131
+ binding: 'amqp'
132
+ }
133
+ }
134
+
135
+ const yaml = dump({
136
+ transition: operation
137
+ })
138
+
139
+ await expect(step.call(context, label, yaml)).resolves.not.toThrow()
140
+ })
141
+ })
142
+
143
+ describe('Then normalized operation {operation} declaration must contain:', () => {
144
+ const step = gherkin.steps.Th('normalized operation {operation} declaration must contain:')
62
145
 
63
146
  it('should be', () => undefined)
64
147
 
@@ -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
- Then('normalized {operation} declaration must contain:',
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
- 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)
74
+ await checkManifest.call(this, 'operations', type, yaml)
75
+ })
56
76
 
57
- assert.equal(contains, true)
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
  /**
@@ -7,3 +7,9 @@ defineParameterType({
7
7
  regexp: /transition|observation|assignment/,
8
8
  transformer: (type) => type
9
9
  })
10
+
11
+ defineParameterType({
12
+ name: 'label',
13
+ regexp: /\S+/,
14
+ transformer: (name) => name
15
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/norm",
3
- "version": "0.4.0-dev.9",
3
+ "version": "0.5.0-dev.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,13 +19,13 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "devDependencies": {
22
- "@toa.io/mock": "0.4.0-dev.9"
22
+ "@toa.io/mock": "0.5.0-dev.0"
23
23
  },
24
24
  "dependencies": {
25
- "@toa.io/core": "0.4.0-dev.9",
26
- "@toa.io/generic": "0.4.0-dev.9",
27
- "@toa.io/schema": "0.4.0-dev.9",
28
- "@toa.io/schemas": "0.4.0-dev.9",
29
- "@toa.io/yaml": "0.4.0-dev.9"
25
+ "@toa.io/core": "0.5.0-dev.0",
26
+ "@toa.io/generic": "0.4.0",
27
+ "@toa.io/schema": "0.4.0",
28
+ "@toa.io/schemas": "0.4.0",
29
+ "@toa.io/yaml": "0.4.0"
30
30
  }
31
31
  }
@@ -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
@@ -213,7 +213,9 @@ properties:
213
213
  adaptive:
214
214
  type: boolean
215
215
  default: false
216
- required: [transition, bridge, path]
216
+ foreign:
217
+ type: boolean
218
+ required: [transition, bridge, path, foreign]
217
219
  additionalProperties: false
218
220
 
219
221
  extensions:
@@ -47,6 +47,7 @@ const ok = {
47
47
  },
48
48
  receivers: {
49
49
  'foo.bar.happened': {
50
+ foreign: true,
50
51
  transition: 'add',
51
52
  bridge: 'whatever',
52
53
  binding: 'amqp',
@@ -42,6 +42,7 @@ export namespace toa.norm {
42
42
  bridge: string
43
43
  binding: string
44
44
  path: string
45
+ foreign: boolean
45
46
  }
46
47
 
47
48
  type Entity = {