@toa.io/norm 0.10.1-dev.0 → 0.20.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/norm",
3
- "version": "0.10.1-dev.0",
3
+ "version": "0.20.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.0"
22
+ "@toa.io/mock": "0.20.0-dev.1"
23
23
  },
24
24
  "dependencies": {
25
- "@toa.io/core": "0.8.1",
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"
25
+ "@toa.io/core": "0.20.0-dev.1",
26
+ "@toa.io/generic": "0.11.0-dev.3",
27
+ "@toa.io/schema": "0.20.0-dev.1",
28
+ "@toa.io/schemas": "0.20.0-dev.1",
29
+ "@toa.io/yaml": "0.20.0-dev.1"
30
30
  },
31
- "gitHead": "7f1fdbfe3aa33eb4a06cb1a33d15be18854bcd88"
31
+ "gitHead": "23a9b4399af908101aac4ae03f22f7b948dfe55f"
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)
@@ -3,15 +3,7 @@
3
3
  // these defaults are required before validation
4
4
  const defaults = (manifest) => {
5
5
  if (manifest.prototype === undefined) manifest.prototype = '@toa.io/prototype'
6
-
7
- if (manifest.bindings === undefined) {
8
- const local = process.env.TOA_DEV === '1'
9
-
10
- manifest.bindings = local
11
- ? ['@toa.io/bindings.amqp']
12
- : ['@toa.io/bindings.http', '@toa.io/bindings.amqp']
13
- }
14
-
6
+ if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
15
7
  if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
16
8
 
17
9
  if (manifest.entity === null || manifest.entity === undefined) manifest.entity = { storage: null }
@@ -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
@@ -11,7 +11,13 @@ properties:
11
11
  type: string
12
12
  packages:
13
13
  type: string
14
+ build:
15
+ type: object
16
+ properties:
17
+ command:
18
+ type: string
14
19
  runtime:
20
+ type: object
15
21
  properties:
16
22
  version:
17
23
  $ref: 'definitions#/definitions/version'
@@ -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
  })
@@ -8,6 +8,9 @@ const context = {
8
8
  description: 'context fixture',
9
9
  version: '0.0.0',
10
10
  packages: 'namespaces/**/*',
11
+ build: {
12
+ command: 'echo test'
13
+ },
11
14
  registry: {
12
15
  base: 'localhost:5000',
13
16
  platforms: ['linux/amd64', 'linux/arm/v7', 'linux/arm64']
@@ -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
@@ -1,6 +1,4 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { Component } from './component'
1
+ import * as _component from './component'
4
2
  import { Locator } from '@toa.io/core/types'
5
3
 
6
4
  declare namespace toa.norm {
@@ -14,13 +12,17 @@ declare namespace toa.norm {
14
12
  }
15
13
 
16
14
  interface Registry {
17
- base: string
15
+ base?: string
18
16
  platforms?: string[] | null
17
+ build?: {
18
+ arguments?: string[]
19
+ run?: string
20
+ }
19
21
  }
20
22
 
21
23
  interface Composition {
22
24
  name: string,
23
- components: string[] | Component[]
25
+ components: string[] | _component.Component[]
24
26
  }
25
27
 
26
28
  namespace dependencies {
@@ -31,7 +33,7 @@ declare namespace toa.norm {
31
33
  }
32
34
 
33
35
  type References = {
34
- [reference: string]: Component[]
36
+ [reference: string]: _component.Component[]
35
37
  }
36
38
 
37
39
  }
@@ -42,11 +44,11 @@ declare namespace toa.norm {
42
44
 
43
45
  interface Declaration {
44
46
  name: string
45
- description: string
46
- version: string
47
- runtime: Runtime | string
48
- registry: Registry | string
49
- packages: string
47
+ description?: string
48
+ version?: string
49
+ runtime?: Runtime | string
50
+ registry?: Registry | string
51
+ packages?: string
50
52
  compositions?: Composition[]
51
53
  annotations?: Record<string, object>
52
54
  }
@@ -55,11 +57,10 @@ declare namespace toa.norm {
55
57
  }
56
58
 
57
59
  interface Context extends context.Declaration {
58
- locator: Locator
59
- runtime: context.Runtime
60
+ runtime?: context.Runtime
60
61
  environment?: string
61
- registry: context.Registry
62
- components: Component[]
62
+ registry?: context.Registry
63
+ components?: _component.Component[]
63
64
  dependencies?: context.Dependencies
64
65
  }
65
66