@toa.io/norm 0.9.0 → 0.10.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.9.0",
3
+ "version": "0.10.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.5"
22
+ "@toa.io/mock": "0.7.6-dev.1"
23
23
  },
24
24
  "dependencies": {
25
25
  "@toa.io/core": "0.8.0",
26
26
  "@toa.io/generic": "0.8.0",
27
- "@toa.io/schema": "0.7.2",
28
- "@toa.io/schemas": "0.8.0",
27
+ "@toa.io/schema": "0.7.3-dev.0",
28
+ "@toa.io/schemas": "0.8.1-dev.0",
29
29
  "@toa.io/yaml": "0.7.2"
30
30
  },
31
- "gitHead": "e0f4773f67000b28d5b332ce0a0094a31acf4ff3"
31
+ "gitHead": "cec62c1e23f4f16baff9baf6e71935ecccf786e5"
32
32
  }
@@ -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,20 @@
1
+ 'use strict'
2
+
3
+ function receivers (component) {
4
+ if (component.receivers === undefined) return
5
+
6
+ const receivers = component.receivers
7
+
8
+ for (const [key, value] of Object.entries(receivers)) {
9
+ const segments = key.split('.')
10
+
11
+ if (segments.length === 3) continue
12
+
13
+ const newKey = 'default.' + key
14
+
15
+ delete receivers[key]
16
+ receivers[newKey] = value
17
+ }
18
+ }
19
+
20
+ exports.receivers = receivers
@@ -32,7 +32,7 @@ const resolve = (schema) => (property) => {
32
32
  }
33
33
 
34
34
  const schema = (object, resolve) => {
35
- if (object === undefined || typeof object !== 'object') return
35
+ if (object === undefined || object === null || typeof object !== 'object') return
36
36
  if (object.type === 'string' && object.default?.[0] === '.') return resolve(object.default.substring(1))
37
37
 
38
38
  if (object.type === 'array') {
@@ -1,12 +1,13 @@
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
+ receivers(component)
10
11
  extensions(component)
11
12
  }
12
13
 
@@ -41,10 +41,10 @@ properties:
41
41
 
42
42
  namespace:
43
43
  $ref: 'definitions#/definitions/token'
44
+ default: 'default'
44
45
  not:
45
46
  oneOf:
46
47
  - const: 'system'
47
- - const: 'default'
48
48
  name:
49
49
  $ref: 'definitions#/definitions/token'
50
50
 
@@ -63,19 +63,16 @@ properties:
63
63
  type:
64
64
  default: object
65
65
  const: object
66
- additionalProperties:
67
- default: false
68
- const: false
69
66
  properties:
70
67
  type: object
71
68
  propertyNames:
72
69
  oneOf:
73
70
  - $ref: 'definitions#/definitions/token'
74
- - enum: [_version]
71
+ - enum: [ _version ]
75
72
  initialized:
76
73
  type: boolean
77
74
  default: false
78
- required: [schema]
75
+ required: [ schema ]
79
76
  additionalProperties: false
80
77
 
81
78
  bindings:
@@ -97,11 +94,11 @@ properties:
97
94
  type: object
98
95
  properties:
99
96
  type:
100
- enum: [transition, observation, assignment, computation, effect]
97
+ enum: [ transition, observation, assignment, computation, effect ]
101
98
  scope:
102
- enum: [object, objects, changeset, none]
99
+ enum: [ object, objects, changeset, none ]
103
100
  concurrency:
104
- enum: [none, retry]
101
+ enum: [ none, retry ]
105
102
  forward:
106
103
  $ref: 'definitions#/definitions/token'
107
104
  bridge:
@@ -110,16 +107,11 @@ properties:
110
107
  $ref: '#/properties/bindings'
111
108
  input:
112
109
  $ref: 'definitions#/definitions/schema'
113
- not:
114
- properties:
115
- additionalProperties:
116
- const: true
117
- required: [additionalProperties]
118
110
  output:
119
111
  $ref: 'definitions#/definitions/schema'
120
112
  query:
121
113
  type: boolean
122
- required: [type, scope, bindings]
114
+ required: [ type, scope, bindings ]
123
115
  allOf:
124
116
  - if: # transition
125
117
  properties:
@@ -128,15 +120,15 @@ properties:
128
120
  then:
129
121
  properties:
130
122
  scope:
131
- enum: [object]
123
+ enum: [ object ]
132
124
  if: # transition query: false
133
125
  not:
134
126
  properties:
135
127
  query:
136
128
  const: false
137
- required: [query]
129
+ required: [ query ]
138
130
  then:
139
- required: [concurrency]
131
+ required: [ concurrency ]
140
132
  - if: # not transition
141
133
  not:
142
134
  properties:
@@ -153,7 +145,7 @@ properties:
153
145
  then:
154
146
  properties:
155
147
  scope:
156
- enum: [object, objects, none]
148
+ enum: [ object, objects, none ]
157
149
  query:
158
150
  not:
159
151
  const: false
@@ -164,7 +156,7 @@ properties:
164
156
  then:
165
157
  properties:
166
158
  scope:
167
- enum: [changeset]
159
+ enum: [ changeset ]
168
160
  - if: # computation
169
161
  properties:
170
162
  type:
@@ -206,7 +198,7 @@ properties:
206
198
  subjective:
207
199
  type: boolean
208
200
  default: false
209
- required: [bridge, path]
201
+ required: [ bridge, path ]
210
202
  additionalProperties: false
211
203
 
212
204
  receivers:
@@ -231,7 +223,7 @@ properties:
231
223
  adaptive:
232
224
  type: boolean
233
225
  default: false
234
- required: [transition, bridge, path]
226
+ required: [ transition, bridge, path ]
235
227
  additionalProperties: false
236
228
 
237
229
  extensions:
package/src/component.js CHANGED
@@ -26,6 +26,8 @@ const component = async (path) => {
26
26
  normalize(manifest, process.env.TOA_ENV)
27
27
  validate(manifest)
28
28
 
29
+ manifest.locator = new Locator(manifest.name, manifest.namespace)
30
+
29
31
  return manifest
30
32
  }
31
33
 
@@ -43,8 +45,6 @@ const load = async (path, base) => {
43
45
  await merge(path, manifest)
44
46
 
45
47
  if (manifest.prototype !== null) {
46
- manifest.locator = new Locator(manifest.name, manifest.namespace)
47
-
48
48
  const prototype = await load(manifest.prototype, path)
49
49
 
50
50
  collapse(manifest, prototype)
@@ -43,3 +43,17 @@ describe('extensions', () => {
43
43
  expect(() => normalize(manifest)).toThrow(/hasn't returned manifest/)
44
44
  })
45
45
  })
46
+
47
+ describe('receivers', () => {
48
+ it('should substitute default namespace', async () => {
49
+ manifest.receivers = {
50
+ 'messages.created': 'add'
51
+ }
52
+
53
+ normalize(manifest)
54
+
55
+ expect(manifest.receivers).toStrictEqual({
56
+ 'default.messages.created': 'add'
57
+ })
58
+ })
59
+ })
@@ -55,9 +55,11 @@ describe('namespace', () => {
55
55
  expect(() => validate(manifest)).toThrow(/must NOT be valid/)
56
56
  })
57
57
 
58
- it('should forbid \'default\' namespace', () => {
59
- manifest.namespace = 'default'
60
- expect(() => validate(manifest)).toThrow(/must NOT be valid/)
58
+ it('should set `default` namespace', async () => {
59
+ delete manifest.namespace
60
+
61
+ expect(() => validate(manifest)).not.toThrow()
62
+ expect(manifest.namespace).toStrictEqual('default')
61
63
  })
62
64
  })
63
65