@toa.io/norm 0.20.0-dev.31 → 0.20.0-dev.34

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-dev.31",
3
+ "version": "0.20.0-dev.34",
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-dev.31",
24
- "@toa.io/generic": "0.20.0-dev.31",
25
- "@toa.io/schema": "0.20.0-dev.31",
26
- "@toa.io/schemas": "0.20.0-dev.31",
27
- "@toa.io/yaml": "0.20.0-dev.31"
23
+ "@toa.io/core": "0.20.0-dev.34",
24
+ "@toa.io/generic": "0.20.0-dev.34",
25
+ "@toa.io/schema": "0.20.0-dev.34",
26
+ "@toa.io/schemas": "0.20.0-dev.34",
27
+ "@toa.io/yaml": "0.20.0-dev.34"
28
28
  },
29
- "gitHead": "f9ad6bf2bab1298b96ca52557b7e36b6041cfc88"
29
+ "gitHead": "7035b1985fe9bb844069308a272d061bfbd38bf0"
30
30
  }
@@ -216,6 +216,8 @@ properties:
216
216
  type: string
217
217
  source:
218
218
  $ref: 'definitions#/definitions/name'
219
+ not:
220
+ const: context
219
221
  path:
220
222
  type: string
221
223
  conditioned:
@@ -18,7 +18,8 @@ const resolve = (references, annotations) => {
18
18
 
19
19
  const instances = components.map((component) => ({
20
20
  locator: component.locator,
21
- manifest: component.extensions?.[id]
21
+ manifest: component.extensions?.[id],
22
+ component
22
23
  }))
23
24
 
24
25
  dependencies[dependency] = instances
@@ -240,4 +240,10 @@ describe('receivers', () => {
240
240
 
241
241
  expect(() => validate(manifest)).toThrow(/one of the allowed types/)
242
242
  })
243
+
244
+ it('should throw if source has a name `context`', async () => {
245
+ manifest.receivers['foo.bar.happened'].source = 'context'
246
+
247
+ expect(() => validate(manifest)).toThrow(/must NOT be valid/)
248
+ })
243
249
  })
@@ -23,9 +23,10 @@ interface Composition {
23
23
  components: _component.Component[]
24
24
  }
25
25
 
26
- export interface Dependency {
26
+ export interface Dependency<T = undefined> {
27
27
  locator: Locator
28
- manifest?: object
28
+ manifest: T,
29
+ component: _component.Component
29
30
  }
30
31
 
31
32
  interface Context extends Declaration {
package/types/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * as context from './context'
2
+ export * as component from './component'
@@ -1,54 +0,0 @@
1
- Feature: Operations declaration
2
-
3
- Scenario Outline: Operation <channel> entity references
4
-
5
- Operation IO schemas may reference entity's properties using syntax:
6
- - `.` - entity's property with the same name
7
- - '.foo` - entity's property with `foo` name
8
-
9
- Given I have an entity schema:
10
- """
11
- foo: string
12
- bar: 1
13
- """
14
- When I declare assignment with:
15
- """
16
- <channel>:
17
- foo: .
18
- baz: .bar
19
- """
20
- Then normalized assignment declaration must contain:
21
- """
22
- <channel>:
23
- type: object
24
- properties:
25
- foo:
26
- type: string
27
- baz:
28
- type: number
29
- default: 1
30
- """
31
-
32
- Examples:
33
- | channel |
34
- | input |
35
- | output |
36
-
37
- Scenario: Prototype property reference
38
-
39
- Operation IO schemas must be able to reference prototype's entity properties.
40
-
41
- When I declare assignment with:
42
- """
43
- output:
44
- id: .
45
- """
46
-
47
- Then normalized assignment declaration must contain:
48
- """
49
- output:
50
- type: object
51
- properties:
52
- id:
53
- $ref: https://schemas.toa.io/0.0.0/definitions#/definitions/id
54
- """
@@ -1,111 +0,0 @@
1
- 'use strict'
2
-
3
- const { AssertionError } = require('assert')
4
- const { generate } = require('randomstring')
5
- const { dump } = require('@toa.io/yaml')
6
- const gherkin = require('@toa.io/tomato')
7
-
8
- const mock = { gherkin }
9
-
10
- jest.mock('@cucumber/cucumber', () => mock.gherkin)
11
- require('../manifest')
12
-
13
- it('should be', () => undefined)
14
-
15
- /** @type {toa.norm.features.Context} */
16
- let context
17
-
18
- beforeEach(() => {
19
- const manifest = /** @type {toa.norm.component.Declaration} */ {
20
- name: 'test',
21
- namespace: 'features',
22
- version: '1.0.0',
23
- entity: null
24
- }
25
-
26
- context = { manifest }
27
- })
28
-
29
- describe('Given I have an entity schema:', () => {
30
- const step = gherkin.steps.Gi('I have an entity schema:')
31
-
32
- it('should be', () => undefined)
33
-
34
- it('should set entity schema', () => {
35
- const schema = { foo: 'string' }
36
- const yaml = dump(schema)
37
-
38
- step.call(context, yaml)
39
-
40
- expect(context.manifest.entity).toStrictEqual({ schema })
41
- })
42
- })
43
-
44
- describe('When I declare {operation} with:', () => {
45
- const step = gherkin.steps.Wh('I declare {operation} with:')
46
-
47
- it('should be', () => undefined)
48
-
49
- it('should declare operation', () => {
50
- const type = 'assignment'
51
- const scope = 'changeset'
52
- const input = {}
53
- const yaml = dump(input)
54
-
55
- step.call(context, type, yaml)
56
-
57
- expect(context.manifest.operations[type]).toStrictEqual({ type, scope })
58
- })
59
- })
60
-
61
- describe('Then normalized {operation} declaration must contain:', () => {
62
- const step = gherkin.steps.Th('normalized {operation} declaration must contain:')
63
-
64
- it('should be', () => undefined)
65
-
66
- it('should throw if does not contain', async () => {
67
- const type = 'assignment'
68
-
69
- context.manifest.operations = {
70
- [type]: {
71
- type,
72
- input: { bar: 'number' },
73
- scope: 'changeset'
74
- }
75
- }
76
-
77
- const input = {
78
- type: 'object',
79
- properties: {
80
- bar: { type: 'string' }
81
- }
82
- }
83
-
84
- const yaml = dump({ input })
85
-
86
- await expect(step.call(context, type, yaml)).rejects.toThrow(AssertionError)
87
- })
88
-
89
- it('should not throw if contain', async () => {
90
- const type = 'assignment'
91
-
92
- context.manifest.operations = {
93
- [type]: {
94
- type,
95
- input: { bar: 'number' },
96
- scope: 'changeset'
97
- }
98
- }
99
-
100
- const input = {
101
- type: 'object',
102
- properties: {
103
- bar: { type: 'number' }
104
- }
105
- }
106
-
107
- const yaml = dump({ input })
108
-
109
- await expect(step.call(context, type, yaml)).resolves.not.toThrow()
110
- })
111
- })
@@ -1,9 +0,0 @@
1
- import { Declaration } from '../../../types/component'
2
-
3
- declare namespace toa.norm.features {
4
-
5
- type Context = {
6
- manifest?: Declaration
7
- }
8
-
9
- }
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- const { Before } = require('@cucumber/cucumber')
4
-
5
- Before(
6
- /**
7
- * @this {toa.norm.features.Context}
8
- */
9
- function () {
10
- this.manifest = {
11
- name: 'test',
12
- namespace: 'features',
13
- version: '1.0.0',
14
- entity: {
15
- storage: null
16
- }
17
- }
18
- })
@@ -1,66 +0,0 @@
1
- 'use strict'
2
-
3
- const assert = require('node:assert')
4
- const { join } = require('node:path')
5
- const { parse, save } = require('@toa.io/yaml')
6
- const { directory } = require('@toa.io/filesystem')
7
- const { match } = require('@toa.io/generic')
8
-
9
- const { component: load } = require('../../src')
10
-
11
- const { Given, When, Then } = require('@cucumber/cucumber')
12
-
13
- Given('I have an entity schema:',
14
- /**
15
- * @param {string} yaml
16
- * @this {toa.norm.features.Context}
17
- */
18
- function (yaml) {
19
- const schema = parse(yaml)
20
-
21
- this.manifest.entity = { schema }
22
- })
23
-
24
- When('I declare {operation} with:',
25
- /**
26
- * @param {toa.norm.component.operations.Type} type
27
- * @param {string} yaml
28
- * @this {toa.norm.features.Context}
29
- */
30
- function (type, yaml) {
31
- /** @type {toa.norm.component.Operation} */
32
- const declaration = parse(yaml)
33
-
34
- declaration.type = type
35
- declaration.scope = scope(type)
36
-
37
- this.manifest.operations = { [type]: declaration }
38
- })
39
-
40
- Then('normalized {operation} declaration must contain:',
41
- /**
42
- * @param {toa.norm.component.operations.Type} type
43
- * @param {string} yaml
44
- * @this {toa.norm.features.Context}
45
- */
46
- async function (type, yaml) {
47
- const temp = await directory.temp()
48
- const path = join(temp, 'manifest.toa.yaml')
49
-
50
- await save(this.manifest, path)
51
-
52
- const manifest = await load(temp)
53
- const operation = manifest.operations[type]
54
- const query = parse(yaml)
55
- const contains = match(operation, query)
56
-
57
- assert.equal(contains, true)
58
- })
59
-
60
- /**
61
- * @param {toa.norm.component.operations.Type} type
62
- * @returns {toa.norm.component.operations.Scope}
63
- */
64
- const scope = (type) => {
65
- return type === 'assignment' ? 'changeset' : 'object'
66
- }
@@ -1,9 +0,0 @@
1
- 'use strict'
2
-
3
- const { defineParameterType } = require('@cucumber/cucumber')
4
-
5
- defineParameterType({
6
- name: 'operation',
7
- regexp: /transition|observation|assignment/,
8
- transformer: (type) => type
9
- })