@toa.io/norm 0.10.1-dev.0 → 0.20.0-dev.10

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.10",
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",
@@ -18,15 +18,12 @@
18
18
  "scripts": {
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
- "devDependencies": {
22
- "@toa.io/mock": "0.7.7-dev.0"
23
- },
24
21
  "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"
22
+ "@toa.io/core": "0.20.0-dev.10",
23
+ "@toa.io/generic": "0.20.0-dev.10",
24
+ "@toa.io/schema": "0.20.0-dev.10",
25
+ "@toa.io/schemas": "0.20.0-dev.10",
26
+ "@toa.io/yaml": "0.20.0-dev.10"
30
27
  },
31
- "gitHead": "7f1fdbfe3aa33eb4a06cb1a33d15be18854bcd88"
28
+ "gitHead": "cd3ffb1ae1af014f13a62ef9fc8ada58d8688e4a"
32
29
  }
@@ -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)
@@ -1,19 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ const { hash } = require('@toa.io/generic')
4
+
3
5
  // these defaults are required before validation
4
6
  const defaults = (manifest) => {
5
7
  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
-
8
+ if (manifest.name === undefined) manifest.name = protoName(manifest)
9
+ if (manifest.bindings === undefined) manifest.bindings = ['@toa.io/bindings.amqp']
15
10
  if (manifest.bridge === undefined) manifest.bridge = '@toa.io/bridges.node'
16
-
17
11
  if (manifest.entity === null || manifest.entity === undefined) manifest.entity = { storage: null }
18
12
  if (manifest.entity.storage === undefined) manifest.entity.storage = '@toa.io/storages.mongodb'
19
13
  if (manifest.entity.storage === null) manifest.entity.storage = '@toa.io/storages.null'
@@ -22,4 +16,8 @@ const defaults = (manifest) => {
22
16
  if (manifest.version === undefined) manifest.version = '0.0.0'
23
17
  }
24
18
 
19
+ function protoName (manifest) {
20
+ return 'proto' + hash(manifest.path)
21
+ }
22
+
25
23
  exports.defaults = defaults
@@ -20,7 +20,7 @@ properties:
20
20
  operations:
21
21
  type: object
22
22
  propertyNames:
23
- $ref: 'definitions#/definitions/token'
23
+ $ref: 'definitions#/definitions/name'
24
24
  patternProperties:
25
25
  '.*':
26
26
  type: object
@@ -39,14 +39,15 @@ properties:
39
39
  label:
40
40
  $ref: 'definitions#/definitions/label'
41
41
 
42
+ name:
43
+ $ref: 'definitions#/definitions/token'
44
+
42
45
  namespace:
43
46
  $ref: 'definitions#/definitions/token'
44
47
  default: 'default'
45
48
  not:
46
49
  oneOf:
47
50
  - const: 'system'
48
- name:
49
- $ref: 'definitions#/definitions/token'
50
51
 
51
52
  version:
52
53
  $ref: 'definitions#/definitions/version'
@@ -67,12 +68,12 @@ properties:
67
68
  type: object
68
69
  propertyNames:
69
70
  oneOf:
70
- - $ref: 'definitions#/definitions/token'
71
- - enum: [ _version ]
71
+ - $ref: 'definitions#/definitions/name'
72
+ - enum: [_version]
72
73
  initialized:
73
74
  type: boolean
74
75
  default: false
75
- required: [ schema ]
76
+ required: [schema]
76
77
  additionalProperties: false
77
78
 
78
79
  bindings:
@@ -88,19 +89,19 @@ properties:
88
89
  operations:
89
90
  type: object
90
91
  propertyNames:
91
- $ref: 'definitions#/definitions/token'
92
+ $ref: 'definitions#/definitions/name'
92
93
  patternProperties:
93
94
  '.*':
94
95
  type: object
95
96
  properties:
96
97
  type:
97
- enum: [ transition, observation, assignment, computation, effect ]
98
+ enum: [transition, observation, assignment, computation, effect]
98
99
  scope:
99
- enum: [ object, objects, changeset, none ]
100
+ enum: [object, objects, changeset, none]
100
101
  concurrency:
101
- enum: [ none, retry ]
102
+ enum: [none, retry]
102
103
  forward:
103
- $ref: 'definitions#/definitions/token'
104
+ $ref: 'definitions#/definitions/name'
104
105
  bridge:
105
106
  type: string
106
107
  bindings:
@@ -111,7 +112,7 @@ properties:
111
112
  $ref: 'definitions#/definitions/schema'
112
113
  query:
113
114
  type: boolean
114
- required: [ type, scope, bindings ]
115
+ required: [type, scope, bindings]
115
116
  allOf:
116
117
  - if: # transition
117
118
  properties:
@@ -120,15 +121,15 @@ properties:
120
121
  then:
121
122
  properties:
122
123
  scope:
123
- enum: [ object ]
124
+ enum: [object]
124
125
  if: # transition query: false
125
126
  not:
126
127
  properties:
127
128
  query:
128
129
  const: false
129
- required: [ query ]
130
+ required: [query]
130
131
  then:
131
- required: [ concurrency ]
132
+ required: [concurrency]
132
133
  - if: # not transition
133
134
  not:
134
135
  properties:
@@ -145,7 +146,7 @@ properties:
145
146
  then:
146
147
  properties:
147
148
  scope:
148
- enum: [ object, objects, none ]
149
+ enum: [object, objects, none]
149
150
  query:
150
151
  not:
151
152
  const: false
@@ -156,7 +157,7 @@ properties:
156
157
  then:
157
158
  properties:
158
159
  scope:
159
- enum: [ changeset ]
160
+ enum: [changeset]
160
161
  - if: # computation
161
162
  properties:
162
163
  type:
@@ -181,7 +182,7 @@ properties:
181
182
  events:
182
183
  type: object
183
184
  propertyNames:
184
- $ref: 'definitions#/definitions/token'
185
+ $ref: 'definitions#/definitions/name'
185
186
  patternProperties:
186
187
  '.*':
187
188
  type: object
@@ -198,7 +199,7 @@ properties:
198
199
  subjective:
199
200
  type: boolean
200
201
  default: false
201
- required: [ bridge, path ]
202
+ required: [bridge, path]
202
203
  additionalProperties: false
203
204
 
204
205
  receivers:
@@ -207,14 +208,14 @@ properties:
207
208
  '.*':
208
209
  type: object
209
210
  properties:
210
- transition:
211
- $ref: 'definitions#/definitions/token'
211
+ operation:
212
+ $ref: 'definitions#/definitions/name'
212
213
  bridge:
213
214
  type: string
214
215
  binding:
215
216
  type: string
216
217
  source:
217
- $ref: 'definitions#/definitions/token'
218
+ $ref: 'definitions#/definitions/name'
218
219
  path:
219
220
  type: string
220
221
  conditioned:
@@ -223,7 +224,7 @@ properties:
223
224
  adaptive:
224
225
  type: boolean
225
226
  default: false
226
- required: [ transition, bridge, path ]
227
+ required: [operation]
227
228
  additionalProperties: false
228
229
 
229
230
  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'
package/src/component.js CHANGED
@@ -35,7 +35,7 @@ const load = async (path, base) => {
35
35
  if (base !== undefined) path = find(path, base, MANIFEST)
36
36
 
37
37
  const file = join(path, MANIFEST)
38
- const manifest = /** @type {toa.norm.Component} */ await yaml(file)
38
+ const manifest = /** @type {toa.norm.Component} */ await yaml(file) ?? {}
39
39
 
40
40
  manifest.path = path
41
41
 
package/src/context.js CHANGED
@@ -19,7 +19,7 @@ const {
19
19
  /**
20
20
  * @type {toa.norm.context.Constructor}
21
21
  */
22
- const context = async (root, environment = undefined) => {
22
+ const context = async (root, environment = process.env.TOA_ENV) => {
23
23
  const path = resolve(root, CONTEXT)
24
24
  const context = /** @type {toa.norm.Context} */ await load(path)
25
25
  const pattern = resolve(root, context.packages)
@@ -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'
@@ -37,14 +37,14 @@ describe('namespace', () => {
37
37
  manifest.namespace = 'foo_'
38
38
  expect(() => validate(manifest)).toThrow(/must match pattern/)
39
39
 
40
- manifest.namespace = 'foo-'
40
+ manifest.namespace = 'foo_bar'
41
41
  expect(() => validate(manifest)).toThrow(/must match pattern/)
42
42
 
43
- manifest.namespace = 'foo-BAR'
44
- expect(() => validate(manifest)).not.toThrow()
43
+ manifest.namespace = 'foo-'
44
+ expect(() => validate(manifest)).toThrow(/must match pattern/)
45
45
 
46
- manifest.namespace = 'foo_bar'
47
- expect(() => validate(manifest)).not.toThrow()
46
+ manifest.namespace = 'foo-bar'
47
+ expect(() => validate(manifest)).toThrow('must match pattern')
48
48
 
49
49
  manifest.namespace = 'FooBar12'
50
50
  expect(() => validate(manifest)).not.toThrow()
@@ -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 = 'notExists'
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