@toa.io/norm 0.20.0-dev.4 → 0.20.0-dev.40
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 +8 -7
- package/src/.component/.expand/extensions.js +3 -1
- package/src/.component/normalize.js +0 -2
- package/src/.component/schema.yaml +25 -22
- package/src/.context/.dependencies/resolve.js +2 -1
- package/src/context.js +1 -1
- package/src/shortcuts.js +2 -1
- package/test/component/normalize.test.js +0 -7
- package/test/component/validate.test.js +12 -6
- package/types/context/declaration.d.ts +17 -0
- package/types/context.d.ts +31 -66
- package/types/index.d.ts +2 -5
- package/features/component.operations.feature +0 -54
- package/features/steps/.test/manifest.test.js +0 -111
- package/features/steps/.types/context.d.ts +0 -9
- package/features/steps/hooks.js +0 -18
- package/features/steps/manifest.js +0 -66
- package/features/steps/parameters.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/norm",
|
|
3
|
-
"version": "0.20.0-dev.
|
|
3
|
+
"version": "0.20.0-dev.40",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/toa-io/toa/issues"
|
|
13
13
|
},
|
|
14
14
|
"main": "src/index.js",
|
|
15
|
+
"types": "types/index.d.ts",
|
|
15
16
|
"publishConfig": {
|
|
16
17
|
"access": "public"
|
|
17
18
|
},
|
|
@@ -19,11 +20,11 @@
|
|
|
19
20
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@toa.io/core": "0.20.0-dev.
|
|
23
|
-
"@toa.io/generic": "0.20.0-dev.
|
|
24
|
-
"@toa.io/schema": "0.20.0-dev.
|
|
25
|
-
"@toa.io/schemas": "0.20.0-dev.
|
|
26
|
-
"@toa.io/yaml": "0.20.0-dev.
|
|
23
|
+
"@toa.io/core": "0.20.0-dev.40",
|
|
24
|
+
"@toa.io/generic": "0.20.0-dev.40",
|
|
25
|
+
"@toa.io/schema": "0.20.0-dev.40",
|
|
26
|
+
"@toa.io/schemas": "0.20.0-dev.40",
|
|
27
|
+
"@toa.io/yaml": "0.20.0-dev.40"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "594543488de934deba3598ec5805744af1b3f4c0"
|
|
29
30
|
}
|
|
@@ -10,7 +10,9 @@ function extensions (manifest) {
|
|
|
10
10
|
const SHORTCUTS = {
|
|
11
11
|
exposition: '@toa.io/extensions.exposition',
|
|
12
12
|
origins: '@toa.io/extensions.origins',
|
|
13
|
-
configuration: '@toa.io/extensions.configuration'
|
|
13
|
+
configuration: '@toa.io/extensions.configuration',
|
|
14
|
+
state: '@toa.io/extensions.state',
|
|
15
|
+
stash: '@toa.io/extensions.stash'
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
exports.extensions = extensions
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { convolve } = require('@toa.io/generic')
|
|
4
3
|
const { events, operations, extensions, receivers } = require('./.normalize')
|
|
5
4
|
|
|
6
5
|
const normalize = (component, environment) => {
|
|
7
|
-
convolve(component, environment)
|
|
8
6
|
operations(component)
|
|
9
7
|
events(component)
|
|
10
8
|
receivers(component)
|
|
@@ -20,7 +20,7 @@ properties:
|
|
|
20
20
|
operations:
|
|
21
21
|
type: object
|
|
22
22
|
propertyNames:
|
|
23
|
-
$ref: 'definitions#/definitions/
|
|
23
|
+
$ref: 'definitions#/definitions/name'
|
|
24
24
|
patternProperties:
|
|
25
25
|
'.*':
|
|
26
26
|
type: object
|
|
@@ -39,14 +39,15 @@ properties:
|
|
|
39
39
|
label:
|
|
40
40
|
$ref: 'definitions#/definitions/label'
|
|
41
41
|
|
|
42
|
+
name:
|
|
43
|
+
$ref: 'definitions#/definitions/token'
|
|
44
|
+
|
|
42
45
|
namespace:
|
|
43
46
|
$ref: 'definitions#/definitions/token'
|
|
44
47
|
default: 'default'
|
|
45
48
|
not:
|
|
46
49
|
oneOf:
|
|
47
50
|
- const: 'system'
|
|
48
|
-
name:
|
|
49
|
-
$ref: 'definitions#/definitions/token'
|
|
50
51
|
|
|
51
52
|
version:
|
|
52
53
|
$ref: 'definitions#/definitions/version'
|
|
@@ -67,12 +68,12 @@ properties:
|
|
|
67
68
|
type: object
|
|
68
69
|
propertyNames:
|
|
69
70
|
oneOf:
|
|
70
|
-
- $ref: 'definitions#/definitions/
|
|
71
|
-
- enum: [
|
|
71
|
+
- $ref: 'definitions#/definitions/name'
|
|
72
|
+
- enum: [_version]
|
|
72
73
|
initialized:
|
|
73
74
|
type: boolean
|
|
74
75
|
default: false
|
|
75
|
-
required: [
|
|
76
|
+
required: [schema]
|
|
76
77
|
additionalProperties: false
|
|
77
78
|
|
|
78
79
|
bindings:
|
|
@@ -88,19 +89,19 @@ properties:
|
|
|
88
89
|
operations:
|
|
89
90
|
type: object
|
|
90
91
|
propertyNames:
|
|
91
|
-
$ref: 'definitions#/definitions/
|
|
92
|
+
$ref: 'definitions#/definitions/name'
|
|
92
93
|
patternProperties:
|
|
93
94
|
'.*':
|
|
94
95
|
type: object
|
|
95
96
|
properties:
|
|
96
97
|
type:
|
|
97
|
-
enum: [
|
|
98
|
+
enum: [transition, observation, assignment, computation, effect]
|
|
98
99
|
scope:
|
|
99
|
-
enum: [
|
|
100
|
+
enum: [object, objects, changeset, none]
|
|
100
101
|
concurrency:
|
|
101
|
-
enum: [
|
|
102
|
+
enum: [none, retry]
|
|
102
103
|
forward:
|
|
103
|
-
$ref: 'definitions#/definitions/
|
|
104
|
+
$ref: 'definitions#/definitions/name'
|
|
104
105
|
bridge:
|
|
105
106
|
type: string
|
|
106
107
|
bindings:
|
|
@@ -111,7 +112,7 @@ properties:
|
|
|
111
112
|
$ref: 'definitions#/definitions/schema'
|
|
112
113
|
query:
|
|
113
114
|
type: boolean
|
|
114
|
-
required: [
|
|
115
|
+
required: [type, scope, bindings]
|
|
115
116
|
allOf:
|
|
116
117
|
- if: # transition
|
|
117
118
|
properties:
|
|
@@ -120,15 +121,15 @@ properties:
|
|
|
120
121
|
then:
|
|
121
122
|
properties:
|
|
122
123
|
scope:
|
|
123
|
-
enum: [
|
|
124
|
+
enum: [object]
|
|
124
125
|
if: # transition query: false
|
|
125
126
|
not:
|
|
126
127
|
properties:
|
|
127
128
|
query:
|
|
128
129
|
const: false
|
|
129
|
-
required: [
|
|
130
|
+
required: [query]
|
|
130
131
|
then:
|
|
131
|
-
required: [
|
|
132
|
+
required: [concurrency]
|
|
132
133
|
- if: # not transition
|
|
133
134
|
not:
|
|
134
135
|
properties:
|
|
@@ -145,7 +146,7 @@ properties:
|
|
|
145
146
|
then:
|
|
146
147
|
properties:
|
|
147
148
|
scope:
|
|
148
|
-
enum: [
|
|
149
|
+
enum: [object, objects, none]
|
|
149
150
|
query:
|
|
150
151
|
not:
|
|
151
152
|
const: false
|
|
@@ -156,7 +157,7 @@ properties:
|
|
|
156
157
|
then:
|
|
157
158
|
properties:
|
|
158
159
|
scope:
|
|
159
|
-
enum: [
|
|
160
|
+
enum: [changeset]
|
|
160
161
|
- if: # computation
|
|
161
162
|
properties:
|
|
162
163
|
type:
|
|
@@ -181,7 +182,7 @@ properties:
|
|
|
181
182
|
events:
|
|
182
183
|
type: object
|
|
183
184
|
propertyNames:
|
|
184
|
-
$ref: 'definitions#/definitions/
|
|
185
|
+
$ref: 'definitions#/definitions/name'
|
|
185
186
|
patternProperties:
|
|
186
187
|
'.*':
|
|
187
188
|
type: object
|
|
@@ -198,7 +199,7 @@ properties:
|
|
|
198
199
|
subjective:
|
|
199
200
|
type: boolean
|
|
200
201
|
default: false
|
|
201
|
-
required: [
|
|
202
|
+
required: [bridge, path]
|
|
202
203
|
additionalProperties: false
|
|
203
204
|
|
|
204
205
|
receivers:
|
|
@@ -208,13 +209,15 @@ properties:
|
|
|
208
209
|
type: object
|
|
209
210
|
properties:
|
|
210
211
|
operation:
|
|
211
|
-
$ref: 'definitions#/definitions/
|
|
212
|
+
$ref: 'definitions#/definitions/name'
|
|
212
213
|
bridge:
|
|
213
214
|
type: string
|
|
214
215
|
binding:
|
|
215
216
|
type: string
|
|
216
217
|
source:
|
|
217
|
-
$ref: 'definitions#/definitions/
|
|
218
|
+
$ref: 'definitions#/definitions/name'
|
|
219
|
+
not:
|
|
220
|
+
const: context
|
|
218
221
|
path:
|
|
219
222
|
type: string
|
|
220
223
|
conditioned:
|
|
@@ -223,7 +226,7 @@ properties:
|
|
|
223
226
|
adaptive:
|
|
224
227
|
type: boolean
|
|
225
228
|
default: false
|
|
226
|
-
required: [
|
|
229
|
+
required: [operation]
|
|
227
230
|
additionalProperties: false
|
|
228
231
|
|
|
229
232
|
extensions:
|
|
@@ -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
|
package/src/context.js
CHANGED
|
@@ -19,7 +19,7 @@ const {
|
|
|
19
19
|
/**
|
|
20
20
|
* @type {toa.norm.context.Constructor}
|
|
21
21
|
*/
|
|
22
|
-
const context = async (root, environment =
|
|
22
|
+
const context = async (root, environment = process.env.TOA_ENV) => {
|
|
23
23
|
const path = resolve(root, CONTEXT)
|
|
24
24
|
const context = /** @type {toa.norm.Context} */ await load(path)
|
|
25
25
|
const pattern = resolve(root, context.packages)
|
package/src/shortcuts.js
CHANGED
|
@@ -47,7 +47,8 @@ const SHORTCUTS = {
|
|
|
47
47
|
queues: '@toa.io/storages.queues',
|
|
48
48
|
exposition: '@toa.io/extensions.exposition',
|
|
49
49
|
configuration: '@toa.io/extensions.configuration',
|
|
50
|
-
origins: '@toa.io/extensions.origins'
|
|
50
|
+
origins: '@toa.io/extensions.origins',
|
|
51
|
+
stash: '@toa.io/extensions.stash'
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
exports.recognize = recognize
|
|
@@ -12,13 +12,6 @@ beforeEach(() => {
|
|
|
12
12
|
manifest = clone(fixtures.operations)
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
describe('environment', () => {
|
|
16
|
-
it('should convolve with environment argument', () => {
|
|
17
|
-
normalize(manifest, 'local')
|
|
18
|
-
expect(manifest.operations.add.bindings).toStrictEqual(['foo'])
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
15
|
describe('operations', () => {
|
|
23
16
|
it('should set default bindings', () => {
|
|
24
17
|
normalize(manifest)
|
|
@@ -37,14 +37,14 @@ describe('namespace', () => {
|
|
|
37
37
|
manifest.namespace = 'foo_'
|
|
38
38
|
expect(() => validate(manifest)).toThrow(/must match pattern/)
|
|
39
39
|
|
|
40
|
+
manifest.namespace = 'foo_bar'
|
|
41
|
+
expect(() => validate(manifest)).toThrow(/must match pattern/)
|
|
42
|
+
|
|
40
43
|
manifest.namespace = 'foo-'
|
|
41
44
|
expect(() => validate(manifest)).toThrow(/must match pattern/)
|
|
42
45
|
|
|
43
|
-
manifest.namespace = 'foo-
|
|
44
|
-
expect(() => validate(manifest)).
|
|
45
|
-
|
|
46
|
-
manifest.namespace = 'foo_bar'
|
|
47
|
-
expect(() => validate(manifest)).not.toThrow()
|
|
46
|
+
manifest.namespace = 'foo-bar'
|
|
47
|
+
expect(() => validate(manifest)).toThrow('must match pattern')
|
|
48
48
|
|
|
49
49
|
manifest.namespace = 'FooBar12'
|
|
50
50
|
expect(() => validate(manifest)).not.toThrow()
|
|
@@ -230,7 +230,7 @@ describe('operations', () => {
|
|
|
230
230
|
|
|
231
231
|
describe('receivers', () => {
|
|
232
232
|
it('should throw if transition points to undefined operation', () => {
|
|
233
|
-
manifest.receivers['foo.bar.happened'].operation = '
|
|
233
|
+
manifest.receivers['foo.bar.happened'].operation = 'notExists'
|
|
234
234
|
|
|
235
235
|
expect(() => validate(manifest)).toThrow(/refers to undefined operation/)
|
|
236
236
|
})
|
|
@@ -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
|
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Composition, Registry, Runtime } from '../context'
|
|
2
|
+
|
|
3
|
+
interface Composition {
|
|
4
|
+
name: string,
|
|
5
|
+
components: string[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Declaration {
|
|
9
|
+
name: string
|
|
10
|
+
description?: string
|
|
11
|
+
version?: string
|
|
12
|
+
runtime?: Runtime | string
|
|
13
|
+
registry?: Registry | string
|
|
14
|
+
packages?: string
|
|
15
|
+
compositions?: Composition[]
|
|
16
|
+
annotations?: Record<string, object>
|
|
17
|
+
}
|
package/types/context.d.ts
CHANGED
|
@@ -1,76 +1,41 @@
|
|
|
1
1
|
import * as _component from './component'
|
|
2
2
|
import { Locator } from '@toa.io/core/types'
|
|
3
|
+
import type { Declaration } from './context/declaration'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
version: string
|
|
10
|
-
registry?: string
|
|
11
|
-
proxy?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface Registry {
|
|
15
|
-
base?: string
|
|
16
|
-
platforms?: string[] | null
|
|
17
|
-
build?: {
|
|
18
|
-
arguments?: string[]
|
|
19
|
-
run?: string
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface Composition {
|
|
24
|
-
name: string,
|
|
25
|
-
components: string[] | _component.Component[]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
namespace dependencies {
|
|
29
|
-
|
|
30
|
-
type Instance = {
|
|
31
|
-
locator: Locator
|
|
32
|
-
manifest?: Object
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type References = {
|
|
36
|
-
[reference: string]: _component.Component[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface Dependencies {
|
|
42
|
-
[reference: string]: dependencies.Instance[]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface Declaration {
|
|
46
|
-
name: string
|
|
47
|
-
description?: string
|
|
48
|
-
version?: string
|
|
49
|
-
runtime?: Runtime | string
|
|
50
|
-
registry?: Registry | string
|
|
51
|
-
packages?: string
|
|
52
|
-
compositions?: Composition[]
|
|
53
|
-
annotations?: Record<string, object>
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type Constructor = (path: string, environment?: string) => Promise<Context>
|
|
57
|
-
}
|
|
5
|
+
interface Runtime {
|
|
6
|
+
version: string
|
|
7
|
+
registry?: string
|
|
8
|
+
proxy?: string
|
|
9
|
+
}
|
|
58
10
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
11
|
+
interface Registry {
|
|
12
|
+
base?: string
|
|
13
|
+
platforms?: string[] | null
|
|
14
|
+
build?: {
|
|
15
|
+
arguments?: string[]
|
|
16
|
+
run?: string
|
|
17
|
+
},
|
|
18
|
+
credentials: string
|
|
19
|
+
}
|
|
66
20
|
|
|
21
|
+
interface Composition {
|
|
22
|
+
name: string,
|
|
23
|
+
components: _component.Component[]
|
|
67
24
|
}
|
|
68
25
|
|
|
69
|
-
export
|
|
70
|
-
|
|
26
|
+
export interface Dependency<T = undefined> {
|
|
27
|
+
locator: Locator
|
|
28
|
+
manifest: T,
|
|
29
|
+
component: _component.Component
|
|
30
|
+
}
|
|
71
31
|
|
|
72
|
-
|
|
73
|
-
|
|
32
|
+
interface Context extends Declaration {
|
|
33
|
+
runtime?: Runtime
|
|
34
|
+
environment?: string
|
|
35
|
+
registry?: Registry
|
|
36
|
+
compositions?: Composition[]
|
|
37
|
+
components?: _component.Component[]
|
|
38
|
+
dependencies?: Record<string, Dependency[]>
|
|
74
39
|
}
|
|
75
40
|
|
|
76
|
-
export
|
|
41
|
+
export function context (path: string, environment?: string): Promise<Context>
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export type { Composition, dependencies } from './context'
|
|
5
|
-
export type { Component, Operation } from './component'
|
|
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
|
-
})
|
package/features/steps/hooks.js
DELETED
|
@@ -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
|
-
}
|