@toa.io/norm 0.10.1-dev.0 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/norm",
3
- "version": "0.10.1-dev.0",
3
+ "version": "1.0.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,14 +19,14 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "devDependencies": {
22
- "@toa.io/mock": "0.7.7-dev.0"
22
+ "@toa.io/mock": "0.7.7-dev.1"
23
23
  },
24
24
  "dependencies": {
25
- "@toa.io/core": "0.8.1",
25
+ "@toa.io/core": "1.0.0-dev.0",
26
26
  "@toa.io/generic": "0.9.0",
27
- "@toa.io/schema": "0.7.3",
28
- "@toa.io/schemas": "0.8.1",
29
- "@toa.io/yaml": "0.7.3"
27
+ "@toa.io/schema": "0.7.4-dev.0",
28
+ "@toa.io/schemas": "0.8.2-dev.0",
29
+ "@toa.io/yaml": "0.7.4-dev.0"
30
30
  },
31
- "gitHead": "7f1fdbfe3aa33eb4a06cb1a33d15be18854bcd88"
31
+ "gitHead": "2417f76be3783bd7f790cb4580e4139f2c3ff580"
32
32
  }
@@ -6,7 +6,7 @@ function receivers (manifest) {
6
6
  if (manifest.receivers === undefined) return
7
7
 
8
8
  for (const [locator, receiver] of Object.entries(manifest.receivers)) {
9
- if (typeof receiver === 'string') manifest.receivers[locator] = { transition: receiver }
9
+ if (typeof receiver === 'string') manifest.receivers[locator] = { operation: receiver }
10
10
 
11
11
  if (receiver.binding !== undefined) receiver.binding = resolve(receiver.binding)
12
12
  if (receiver.bridge !== undefined) receiver.bridge = resolve(receiver.bridge)
@@ -207,7 +207,7 @@ properties:
207
207
  '.*':
208
208
  type: object
209
209
  properties:
210
- transition:
210
+ operation:
211
211
  $ref: 'definitions#/definitions/token'
212
212
  bridge:
213
213
  type: string
@@ -223,7 +223,7 @@ properties:
223
223
  adaptive:
224
224
  type: boolean
225
225
  default: false
226
- required: [ transition, bridge, path ]
226
+ required: [ operation ]
227
227
  additionalProperties: false
228
228
 
229
229
  extensions:
@@ -27,14 +27,16 @@ const events = (manifest) => {
27
27
 
28
28
  const receivers = (manifest) => {
29
29
  for (const [locator, receiver] of Object.entries(manifest.receivers)) {
30
- if (manifest.operations?.[receiver.transition] === undefined) {
31
- throw new Error(`Receiver '${locator}' refers to undefined transition '${receiver.transition}'`)
30
+ if (manifest.operations?.[receiver.operation] === undefined) {
31
+ throw new Error(`Receiver '${locator}' refers to undefined operation '${receiver.operation}'`)
32
32
  }
33
33
 
34
- if (manifest.operations[receiver.transition].type !== 'transition') {
35
- throw new Error(`Receiver '${locator}' refers to non-transition '${receiver.transition}'`)
34
+ if (!TYPES.has(manifest.operations[receiver.operation].type)) {
35
+ throw new Error(`Receiver '${locator}' must refer to an operation of one of the allowed types: ${Array.from(TYPES).join(', ')}`)
36
36
  }
37
37
  }
38
38
  }
39
39
 
40
+ const TYPES = new Set(['transition', 'effect'])
41
+
40
42
  exports.validate = validate
@@ -53,7 +53,7 @@ const source = {
53
53
  two: {
54
54
  binding: 'amqp',
55
55
  bridge: 'node',
56
- transition: 'transit'
56
+ operation: 'transit'
57
57
  }
58
58
  }
59
59
  }
@@ -123,12 +123,12 @@ const target = {
123
123
  },
124
124
  receivers: {
125
125
  one: {
126
- transition: 'transit'
126
+ operation: 'transit'
127
127
  },
128
128
  two: {
129
129
  bridge: '@toa.io/bridges.node',
130
130
  binding: '@toa.io/bindings.amqp',
131
- transition: 'transit'
131
+ operation: 'transit'
132
132
  }
133
133
  }
134
134
  }
@@ -47,7 +47,7 @@ const ok = {
47
47
  },
48
48
  receivers: {
49
49
  'foo.bar.happened': {
50
- transition: 'add',
50
+ operation: 'add',
51
51
  bridge: 'whatever',
52
52
  binding: 'amqp',
53
53
  path: '/somewhere'
@@ -229,15 +229,15 @@ describe('operations', () => {
229
229
  })
230
230
 
231
231
  describe('receivers', () => {
232
- it('should throw if transition points to undefined transition', () => {
233
- manifest.receivers['foo.bar.happened'].transition = 'not-exists'
232
+ it('should throw if transition points to undefined operation', () => {
233
+ manifest.receivers['foo.bar.happened'].operation = 'not-exists'
234
234
 
235
- expect(() => validate(manifest)).toThrow(/refers to undefined transition/)
235
+ expect(() => validate(manifest)).toThrow(/refers to undefined operation/)
236
236
  })
237
237
 
238
- it('should throw if transition points to non transition', () => {
239
- manifest.receivers['foo.bar.happened'].transition = 'get'
238
+ it('should throw if transition points to observation', () => {
239
+ manifest.receivers['foo.bar.happened'].operation = 'get'
240
240
 
241
- expect(() => validate(manifest)).toThrow(/refers to non-transition/)
241
+ expect(() => validate(manifest)).toThrow(/one of the allowed types/)
242
242
  })
243
243
  })
@@ -1,4 +1,4 @@
1
- import type { Locator } from '@toa.io/core/types'
1
+ import type {Locator} from '@toa.io/core/types'
2
2
 
3
3
  export namespace toa.norm {
4
4
 
@@ -36,7 +36,7 @@ export namespace toa.norm {
36
36
  }
37
37
 
38
38
  interface Receiver {
39
- transition: string
39
+ operation: string
40
40
  adaptive: boolean
41
41
  conditioned: boolean
42
42
  bridge: string