@toa.io/norm 0.4.0-dev.2 → 0.4.0-dev.6

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.4.0-dev.2",
3
+ "version": "0.4.0-dev.6",
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,13 +19,13 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "devDependencies": {
22
- "@toa.io/mock": "0.4.0-dev.2"
22
+ "@toa.io/mock": "0.4.0-dev.6"
23
23
  },
24
24
  "dependencies": {
25
- "@toa.io/core": "0.4.0-dev.2",
26
- "@toa.io/generic": "0.4.0-dev.2",
27
- "@toa.io/schema": "0.4.0-dev.2",
28
- "@toa.io/schemas": "0.4.0-dev.2",
29
- "@toa.io/yaml": "0.4.0-dev.2"
25
+ "@toa.io/core": "0.4.0-dev.6",
26
+ "@toa.io/generic": "0.4.0-dev.6",
27
+ "@toa.io/schema": "0.4.0-dev.6",
28
+ "@toa.io/schemas": "0.4.0-dev.6",
29
+ "@toa.io/yaml": "0.4.0-dev.6"
30
30
  }
31
31
  }
@@ -3,8 +3,14 @@
3
3
  const { recognize } = require('../../shortcuts')
4
4
 
5
5
  function extensions (manifest) {
6
- recognize(manifest, 'extensions')
7
- recognize(manifest.extensions)
6
+ recognize(SHORTCUTS, manifest, 'extensions')
7
+ recognize(SHORTCUTS, manifest.extensions)
8
+ }
9
+
10
+ const SHORTCUTS = {
11
+ exposition: '@toa.io/extensions.exposition',
12
+ origins: '@toa.io/extensions.origins',
13
+ configuration: '@toa.io/extensions.configuration'
8
14
  }
9
15
 
10
16
  exports.extensions = extensions
@@ -5,6 +5,7 @@ const { entity } = require('./entity')
5
5
  const { events } = require('./events')
6
6
  const { extensions } = require('./extensions')
7
7
  const { operations } = require('./operations')
8
+ const { properties } = require('./properties')
8
9
  const { receivers } = require('./receivers')
9
10
 
10
11
  exports.bridge = bridge
@@ -12,4 +13,5 @@ exports.entity = entity
12
13
  exports.events = events
13
14
  exports.extensions = extensions
14
15
  exports.operations = operations
16
+ exports.properties = properties
15
17
  exports.receivers = receivers
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const { recognize } = require('../../shortcuts')
4
+
5
+ function properties (manifest) {
6
+ recognize(SHORTCUTS, manifest, 'properties')
7
+ recognize(SHORTCUTS, manifest.properties)
8
+ }
9
+
10
+ const SHORTCUTS = {
11
+ queues: '@toa.io/storages.queues'
12
+ }
13
+
14
+ exports.properties = properties
@@ -1,6 +1,14 @@
1
1
  'use strict'
2
2
 
3
- const { entity, bridge, operations, events, receivers, extensions } = require('./.expand')
3
+ const {
4
+ entity,
5
+ bridge,
6
+ operations,
7
+ events,
8
+ receivers,
9
+ extensions,
10
+ properties
11
+ } = require('./.expand')
4
12
 
5
13
  const expand = (manifest) => {
6
14
  entity(manifest)
@@ -8,6 +16,7 @@ const expand = (manifest) => {
8
16
  operations(manifest)
9
17
  events(manifest)
10
18
  receivers(manifest)
19
+ properties(manifest)
11
20
  extensions(manifest)
12
21
  }
13
22
 
@@ -193,8 +193,6 @@ properties:
193
193
 
194
194
  receivers:
195
195
  type: object
196
- propertyNames:
197
- $ref: 'definitions#/definitions/endpoint'
198
196
  patternProperties:
199
197
  '.*':
200
198
  type: object
@@ -205,6 +203,8 @@ properties:
205
203
  type: string
206
204
  binding:
207
205
  type: string
206
+ source:
207
+ $ref: 'definitions#/definitions/token'
208
208
  path:
209
209
  type: string
210
210
  conditioned:
@@ -219,4 +219,7 @@ properties:
219
219
  extensions:
220
220
  type: object
221
221
 
222
+ properties:
223
+ type: object
224
+
222
225
  additionalProperties: false
@@ -1,14 +1,13 @@
1
1
  'use strict'
2
2
 
3
- const { recognize } = require('../shortcuts')
3
+ const shortcuts = require('../shortcuts')
4
4
 
5
5
  /**
6
6
  * @param {toa.norm.context.Declaration | object} context
7
7
  */
8
8
  const expand = (context) => {
9
- recognize(context, 'annotations')
10
- recognize(context.annotations)
11
-
9
+ shortcuts.recognize(shortcuts.SHORTCUTS, context, 'annotations')
10
+ shortcuts.recognize(shortcuts.SHORTCUTS, context.annotations)
12
11
  }
13
12
 
14
13
  exports.expand = expand
package/src/shortcuts.js CHANGED
@@ -16,15 +16,16 @@ const resolve = (token) => {
16
16
  /**
17
17
  * Finds object keys with known shortcuts, resolves and groups them to a given group key if provided
18
18
  *
19
+ * @param {Object} shortcuts
19
20
  * @param {Object} object
20
21
  * @param {string} [group]
21
22
  */
22
- const recognize = (object, group) => {
23
+ const recognize = (shortcuts, object, group) => {
23
24
  if (object === undefined) return
24
25
 
25
26
  const target = group === undefined ? object : {}
26
27
 
27
- for (const [alias, name] of Object.entries(SHORTCUTS)) {
28
+ for (const [alias, name] of Object.entries(shortcuts)) {
28
29
  const value = object[alias]
29
30
 
30
31
  if (value === undefined) continue
@@ -43,10 +44,11 @@ const SHORTCUTS = {
43
44
  node: '@toa.io/bridges.node',
44
45
  mongodb: '@toa.io/storages.mongodb',
45
46
  sql: '@toa.io/storages.sql',
47
+ queues: '@toa.io/storages.queues',
46
48
  exposition: '@toa.io/extensions.exposition',
47
- origins: '@toa.io/extensions.origins',
48
49
  configuration: '@toa.io/extensions.configuration'
49
50
  }
50
51
 
51
52
  exports.recognize = recognize
52
53
  exports.resolve = resolve
54
+ exports.SHORTCUTS = SHORTCUTS
@@ -15,3 +15,14 @@ it('should expand', () => {
15
15
  expand(source)
16
16
  expect(source).toMatchObject(fixtures.target)
17
17
  })
18
+
19
+ it('should recognize storages.queues', async () => {
20
+ const queues = { foo: 'bar' }
21
+
22
+ source.queues = clone(queues)
23
+
24
+ expand(source)
25
+
26
+ expect(source.queues).toBeUndefined()
27
+ expect(source.properties['@toa.io/storages.queues']).toMatchObject(queues)
28
+ })
@@ -6,9 +6,7 @@ const { random } = require('@toa.io/generic')
6
6
  const SHORTCUTS = {
7
7
  http: '@toa.io/bindings.http',
8
8
  amqp: '@toa.io/bindings.amqp',
9
- mongodb: '@toa.io/storages.mongodb',
10
- exposition: '@toa.io/extensions.exposition',
11
- origins: '@toa.io/extensions.origins'
9
+ mongodb: '@toa.io/storages.mongodb'
12
10
  }
13
11
 
14
12
  const object = { foo: random(), bar: { baz: generate() } }
@@ -30,7 +30,7 @@ describe('resolve', () => {
30
30
 
31
31
  describe('recognize', () => {
32
32
  it('should not change unknown', () => {
33
- recognize(object)
33
+ recognize(fixtures.SHORTCUTS, object)
34
34
 
35
35
  expect(object).toStrictEqual(fixtures.object)
36
36
  })
@@ -38,7 +38,7 @@ describe('recognize', () => {
38
38
  it('should resolve known', () => {
39
39
  const known = append()
40
40
 
41
- recognize(object)
41
+ recognize(fixtures.SHORTCUTS, object)
42
42
 
43
43
  for (const [alias, name] of Object.entries(fixtures.SHORTCUTS)) {
44
44
  expect(object[alias]).toBeUndefined()
@@ -50,7 +50,7 @@ describe('recognize', () => {
50
50
  const known = append()
51
51
  const group = generate()
52
52
 
53
- recognize(object, group)
53
+ recognize(fixtures.SHORTCUTS, object, group)
54
54
 
55
55
  expect(object[group]).toStrictEqual(known)
56
56
 
@@ -59,12 +59,13 @@ describe('recognize', () => {
59
59
 
60
60
  it('should not overwrite group', () => {
61
61
  append()
62
+
62
63
  const group = generate()
63
64
  const existing = { [generate()]: generate() }
64
65
 
65
66
  object[group] = clone(existing)
66
67
 
67
- recognize(object, group)
68
+ recognize(fixtures.SHORTCUTS, object, group)
68
69
 
69
70
  expect(object[group]).toStrictEqual(expect.objectContaining(existing))
70
71
  })