@toa.io/norm 0.9.0-dev.5 → 0.10.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.9.0-dev.5",
3
+ "version": "0.10.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.5-dev.6"
22
+ "@toa.io/mock": "0.7.6-dev.0"
23
23
  },
24
24
  "dependencies": {
25
- "@toa.io/core": "0.8.0-dev.5",
26
- "@toa.io/generic": "0.8.0-dev.5",
27
- "@toa.io/schema": "0.7.2-dev.6",
28
- "@toa.io/schemas": "0.8.0-dev.5",
29
- "@toa.io/yaml": "0.7.2-dev.6"
25
+ "@toa.io/core": "0.8.0",
26
+ "@toa.io/generic": "0.8.0",
27
+ "@toa.io/schema": "0.7.2",
28
+ "@toa.io/schemas": "0.8.0",
29
+ "@toa.io/yaml": "0.7.2"
30
30
  },
31
- "gitHead": "c3391b478f76ec1c28c1aa6669c5f5400159b963"
31
+ "gitHead": "b3bf7cf661b21e8f767fe07689991ee93e885b44"
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
 
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