@toa.io/norm 0.10.1-dev.0 → 1.0.0-dev.1
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 +8 -8
- package/src/.component/.expand/receivers.js +1 -1
- package/src/.component/schema.yaml +2 -2
- package/src/.component/validate.js +6 -4
- package/test/component/expand.fixtures.js +3 -3
- package/test/component/validate.fixtures.js +1 -1
- package/test/component/validate.test.js +6 -6
- package/types/component.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-dev.1",
|
|
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.
|
|
22
|
+
"@toa.io/mock": "0.7.7-dev.2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@toa.io/core": "0.
|
|
26
|
-
"@toa.io/generic": "0.9.0",
|
|
27
|
-
"@toa.io/schema": "0.7.
|
|
28
|
-
"@toa.io/schemas": "0.8.1",
|
|
29
|
-
"@toa.io/yaml": "0.7.
|
|
25
|
+
"@toa.io/core": "1.0.0-dev.1",
|
|
26
|
+
"@toa.io/generic": "0.9.1-dev.0",
|
|
27
|
+
"@toa.io/schema": "0.7.4-dev.1",
|
|
28
|
+
"@toa.io/schemas": "0.8.2-dev.1",
|
|
29
|
+
"@toa.io/yaml": "0.7.4-dev.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1121d84f7051a0d54ecf899efeaf3b328d7894c0"
|
|
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] = {
|
|
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
|
-
|
|
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: [
|
|
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.
|
|
31
|
-
throw new Error(`Receiver '${locator}' refers to undefined
|
|
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.
|
|
35
|
-
throw new Error(`Receiver '${locator}'
|
|
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
|
-
|
|
56
|
+
operation: 'transit'
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -123,12 +123,12 @@ const target = {
|
|
|
123
123
|
},
|
|
124
124
|
receivers: {
|
|
125
125
|
one: {
|
|
126
|
-
|
|
126
|
+
operation: 'transit'
|
|
127
127
|
},
|
|
128
128
|
two: {
|
|
129
129
|
bridge: '@toa.io/bridges.node',
|
|
130
130
|
binding: '@toa.io/bindings.amqp',
|
|
131
|
-
|
|
131
|
+
operation: 'transit'
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -229,15 +229,15 @@ describe('operations', () => {
|
|
|
229
229
|
})
|
|
230
230
|
|
|
231
231
|
describe('receivers', () => {
|
|
232
|
-
it('should throw if transition points to undefined
|
|
233
|
-
manifest.receivers['foo.bar.happened'].
|
|
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
|
|
235
|
+
expect(() => validate(manifest)).toThrow(/refers to undefined operation/)
|
|
236
236
|
})
|
|
237
237
|
|
|
238
|
-
it('should throw if transition points to
|
|
239
|
-
manifest.receivers['foo.bar.happened'].
|
|
238
|
+
it('should throw if transition points to observation', () => {
|
|
239
|
+
manifest.receivers['foo.bar.happened'].operation = 'get'
|
|
240
240
|
|
|
241
|
-
expect(() => validate(manifest)).toThrow(/
|
|
241
|
+
expect(() => validate(manifest)).toThrow(/one of the allowed types/)
|
|
242
242
|
})
|
|
243
243
|
})
|
package/types/component.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
39
|
+
operation: string
|
|
40
40
|
adaptive: boolean
|
|
41
41
|
conditioned: boolean
|
|
42
42
|
bridge: string
|