@toa.io/norm 0.20.0-alpha.1 → 0.20.0-alpha.2

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.20.0-alpha.1",
3
+ "version": "0.20.0-alpha.2",
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",
@@ -20,11 +20,11 @@
20
20
  "test": "echo \"Error: run tests from root\" && exit 1"
21
21
  },
22
22
  "dependencies": {
23
- "@toa.io/core": "0.20.0-alpha.1",
24
- "@toa.io/generic": "0.20.0-alpha.1",
25
- "@toa.io/schema": "0.20.0-alpha.1",
26
- "@toa.io/schemas": "0.20.0-alpha.1",
27
- "@toa.io/yaml": "0.20.0-alpha.1"
23
+ "@toa.io/core": "0.20.0-alpha.2",
24
+ "@toa.io/generic": "0.20.0-alpha.2",
25
+ "@toa.io/schema": "0.20.0-alpha.2",
26
+ "@toa.io/schemas": "0.20.0-alpha.2",
27
+ "@toa.io/yaml": "0.20.0-alpha.2"
28
28
  },
29
- "gitHead": "d1a5369c0ee4ee423f792b83e9753fd2fd943cce"
29
+ "gitHead": "d6e8c5bdae26e2beb66f4d7f37f71a3494fe9fcb"
30
30
  }
@@ -9,6 +9,7 @@ function extensions (manifest) {
9
9
 
10
10
  const SHORTCUTS = {
11
11
  exposition: '@toa.io/extensions.exposition',
12
+ realtime: '@toa.io/extensions.realtime',
12
13
  origins: '@toa.io/extensions.origins',
13
14
  configuration: '@toa.io/extensions.configuration',
14
15
  state: '@toa.io/extensions.state',
@@ -10,7 +10,10 @@ function operations (manifest) {
10
10
  if (operation.input !== undefined) operation.input = expand(operation.input)
11
11
  if (operation.output !== undefined) operation.output = expand(operation.output)
12
12
  if (operation.bridge !== undefined) operation.bridge = resolve(operation.bridge)
13
- if (operation.bindings !== undefined) operation.bindings = operation.bindings.map(resolve)
13
+
14
+ if (operation.bindings !== undefined && operation.bindings !== null) {
15
+ operation.bindings = operation.bindings.map(resolve)
16
+ }
14
17
  }
15
18
  }
16
19
 
@@ -1,11 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  const { events } = require('./events')
4
- const { extensions } = require('./extensions')
5
4
  const { operations } = require('./operations')
6
5
  const { receivers } = require('./receivers')
7
6
 
8
7
  exports.events = events
9
- exports.extensions = extensions
10
8
  exports.operations = operations
11
9
  exports.receivers = receivers
@@ -4,7 +4,11 @@ const operations = (component) => {
4
4
  if (component.operations === undefined) return
5
5
 
6
6
  for (const [endpoint, operation] of Object.entries(component.operations)) {
7
+ if (operation.type === 'computation' || operation.type === 'effect')
8
+ operation.query = false
9
+
7
10
  if (operation.bindings === undefined) operation.bindings = component.bindings
11
+ if (operation.bindings === null) operation.bindings = []
8
12
  if (operation.virtual === true) delete component.operations[endpoint]
9
13
  }
10
14
  }
@@ -1,11 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  const { directory: { find } } = require('@toa.io/filesystem')
4
- const { resolve } = require('../../shortcuts')
4
+ const { resolve } = require('../shortcuts')
5
5
 
6
- /**
7
- * @param {toa.norm.Component} manifest
8
- */
9
6
  const extensions = (manifest) => {
10
7
  if (manifest.extensions === undefined) return
11
8
 
@@ -8,6 +8,7 @@ const { expand } = require('./expand')
8
8
  const { merge } = require('./merge')
9
9
  const { normalize } = require('./normalize')
10
10
  const { validate } = require('./validate')
11
+ const { extensions } = require('./extensions')
11
12
 
12
13
  exports.collapse = collapse
13
14
  exports.defaults = defaults
@@ -17,3 +18,4 @@ exports.expand = expand
17
18
  exports.merge = merge
18
19
  exports.normalize = normalize
19
20
  exports.validate = validate
21
+ exports.extensions = extensions
@@ -1,12 +1,11 @@
1
1
  'use strict'
2
2
 
3
- const { events, operations, extensions, receivers } = require('./.normalize')
3
+ const { events, operations, receivers } = require('./.normalize')
4
4
 
5
- const normalize = (component, environment) => {
5
+ const normalize = (component) => {
6
6
  operations(component)
7
7
  events(component)
8
8
  receivers(component)
9
- extensions(component)
10
9
  }
11
10
 
12
11
  exports.normalize = normalize
@@ -79,7 +79,6 @@ properties:
79
79
  bindings:
80
80
  type: array
81
81
  uniqueItems: true
82
- minItems: 1
83
82
  items:
84
83
  $ref: '#/definitions/binding'
85
84
 
@@ -167,6 +166,9 @@ properties:
167
166
  scope:
168
167
  const: none
169
168
  default: none
169
+ query:
170
+ const: false
171
+ default: false
170
172
  - if: # effect
171
173
  properties:
172
174
  type:
@@ -176,6 +178,9 @@ properties:
176
178
  scope:
177
179
  const: none
178
180
  default: none
181
+ query:
182
+ const: false
183
+ default: false
179
184
  additionalProperties: false
180
185
  additionalProperties: false
181
186
 
package/src/component.js CHANGED
@@ -14,17 +14,16 @@ const {
14
14
  dereference,
15
15
  defaults,
16
16
  dependencies,
17
- normalize
17
+ normalize,
18
+ extensions
18
19
  } = require('./.component')
19
20
 
20
- /**
21
- * @type {toa.norm.component.Constructor}
22
- */
23
21
  const component = async (path) => {
24
22
  const manifest = await load(path)
25
23
 
26
- normalize(manifest, process.env.TOA_ENV)
24
+ normalize(manifest)
27
25
  validate(manifest)
26
+ extensions(manifest)
28
27
 
29
28
  manifest.locator = new Locator(manifest.name, manifest.namespace)
30
29
 
package/src/shortcuts.js CHANGED
@@ -46,6 +46,7 @@ const SHORTCUTS = {
46
46
  sql: '@toa.io/storages.sql',
47
47
  queues: '@toa.io/storages.queues',
48
48
  exposition: '@toa.io/extensions.exposition',
49
+ realtime: '@toa.io/extensions.realtime',
49
50
  configuration: '@toa.io/extensions.configuration',
50
51
  origins: '@toa.io/extensions.origins',
51
52
  stash: '@toa.io/extensions.stash'
@@ -29,12 +29,6 @@ describe('extensions', () => {
29
29
 
30
30
  expect(manifest.extensions[path]).toStrictEqual(origins)
31
31
  })
32
-
33
- it('should throw if manifest is undefined', () => {
34
- manifest.extensions['./dummies/extension'].ok = false
35
-
36
- expect(() => normalize(manifest)).toThrow(/hasn't returned manifest/)
37
- })
38
32
  })
39
33
 
40
34
  describe('receivers', () => {
@@ -34,6 +34,16 @@ const ok = {
34
34
  scope: 'changeset',
35
35
  bridge: 'whatever',
36
36
  bindings: ['@toa.io/bindings.http', '@toa.io/bindings.amqp']
37
+ },
38
+ compute: {
39
+ type: 'computation',
40
+ bridge: 'whatever',
41
+ bindings: ['@toa.io/bindings.http', '@toa.io/bindings.amqp']
42
+ },
43
+ affect: {
44
+ type: 'effect',
45
+ bridge: 'whatever',
46
+ bindings: ['@toa.io/bindings.http', '@toa.io/bindings.amqp']
37
47
  }
38
48
  },
39
49
  events: {
@@ -172,6 +172,15 @@ describe('operations', () => {
172
172
  expect(() => validate(manifest)).toThrow(/must NOT be valid/)
173
173
  })
174
174
 
175
+ it.each([
176
+ ['computation', 'compute'],
177
+ ['effect', 'affect']
178
+ ])('should set query: false for %s', async (_, operation) => {
179
+ validate(manifest)
180
+
181
+ expect(manifest.operations[operation].query).toBe(false)
182
+ })
183
+
175
184
  describe('scope', () => {
176
185
  it('should have scope', () => {
177
186
  delete manifest.operations.get.scope
@@ -11,6 +11,7 @@ type Operation = {
11
11
  input?: any
12
12
  output?: any
13
13
  error?: any
14
+ query?: boolean
14
15
  }
15
16
 
16
17
  type Operations = {