@toa.io/norm 1.0.0-alpha.27 → 1.0.0-alpha.272
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/CHANGELOG.md +143 -0
- package/package.json +6 -7
- package/src/.component/.expand/extensions.js +2 -2
- package/src/.component/.expand/version.js +36 -20
- package/src/.component/.normalize/operations.js +1 -1
- package/src/.component/collapse.js +5 -0
- package/src/.component/defaults.js +14 -3
- package/src/.component/dereference.js +6 -1
- package/src/.component/extensions.js +11 -2
- package/src/.component/merge.js +19 -5
- package/src/.component/schema.yaml +81 -41
- package/src/.component/validate.js +5 -5
- package/src/.context/.dependencies/extensions.js +9 -5
- package/src/.context/.dependencies/resolve.js +21 -0
- package/src/.context/schema.yaml +115 -7
- package/src/.context/validate.js +2 -5
- package/src/component.js +5 -5
- package/src/context.js +2 -2
- package/src/shortcuts.js +3 -2
- package/test/component/expand.fixtures.js +1 -1
- package/test/component/expand.test.js +17 -3
- package/test/component/normalize.test.js +16 -8
- package/test/component/validate.test.js +8 -11
- package/test/context/complete.fixtures.js +0 -1
- package/test/context/dereference.fixtures.js +0 -1
- package/test/context/normalize.fixtures.js +0 -1
- package/test/context/validate.fixtures.js +0 -1
- package/test/context/validate.test.js +12 -12
- package/types/context/declaration.d.ts +22 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
3
|
-
const { dirname } = require('node:path')
|
|
4
2
|
const clone = require('clone-deep')
|
|
5
3
|
|
|
6
|
-
const { normalize } = require('../../src/.component')
|
|
4
|
+
const { normalize, extensions } = require('../../src/.component')
|
|
7
5
|
const fixtures = require('./normalize.fixtures')
|
|
8
6
|
|
|
9
7
|
let manifest
|
|
@@ -21,13 +19,23 @@ describe('operations', () => {
|
|
|
21
19
|
})
|
|
22
20
|
|
|
23
21
|
describe('extensions', () => {
|
|
24
|
-
it('should
|
|
25
|
-
|
|
26
|
-
const path = dirname(require.resolve('@toa.io/extensions.origins/package.json'))
|
|
22
|
+
it('should add predefined extensions', () => {
|
|
23
|
+
extensions(manifest)
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
expect(manifest.extensions['@toa.io/extensions.telemetry']).toBeNull()
|
|
26
|
+
expect(manifest.extensions['@toa.io/extensions.fetch']).toBeNull()
|
|
27
|
+
})
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
it('should add predefined extensions without explicit declarations', () => {
|
|
30
|
+
delete manifest.extensions
|
|
31
|
+
|
|
32
|
+
extensions(manifest)
|
|
33
|
+
|
|
34
|
+
expect(manifest.extensions).toStrictEqual({
|
|
35
|
+
'@toa.io/extensions.telemetry': null,
|
|
36
|
+
'@toa.io/extensions.fetch': null,
|
|
37
|
+
'@toa.io/extensions.introspection': {}
|
|
38
|
+
})
|
|
31
39
|
})
|
|
32
40
|
})
|
|
33
41
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noinspection JSUnresolvedVariable
|
|
2
|
-
|
|
3
1
|
'use strict'
|
|
4
2
|
|
|
5
3
|
const clone = require('clone-deep')
|
|
@@ -20,13 +18,13 @@ it('should be ok', () => {
|
|
|
20
18
|
it('should provide error', () => {
|
|
21
19
|
manifest.foo = 'bar'
|
|
22
20
|
|
|
23
|
-
expect(() => validate(manifest)).toThrow(
|
|
21
|
+
expect(() => validate(manifest)).toThrow()
|
|
24
22
|
})
|
|
25
23
|
|
|
26
24
|
it('should not have additional properties', () => {
|
|
27
25
|
manifest.foo = 'bar'
|
|
28
26
|
|
|
29
|
-
expect(() => validate(manifest)).toThrow(
|
|
27
|
+
expect(() => validate(manifest)).toThrow()
|
|
30
28
|
})
|
|
31
29
|
|
|
32
30
|
describe('namespace', () => {
|
|
@@ -83,13 +81,13 @@ describe('entity', () => {
|
|
|
83
81
|
|
|
84
82
|
it('should not have additional properties', () => {
|
|
85
83
|
manifest.entity.foo = 'bar'
|
|
86
|
-
expect(() => validate(manifest)).toThrow(
|
|
84
|
+
expect(() => validate(manifest)).toThrow()
|
|
87
85
|
})
|
|
88
86
|
|
|
89
87
|
describe('schema', () => {
|
|
90
88
|
it('should be required', () => {
|
|
91
89
|
delete manifest.entity.schema
|
|
92
|
-
expect(() => validate(manifest)).toThrow(
|
|
90
|
+
expect(() => validate(manifest)).toThrow()
|
|
93
91
|
})
|
|
94
92
|
|
|
95
93
|
it('should be JSON schema object', () => {
|
|
@@ -99,7 +97,7 @@ describe('entity', () => {
|
|
|
99
97
|
|
|
100
98
|
it('should be JSON schema object of type object', () => {
|
|
101
99
|
manifest.entity.schema = { type: 'integer' }
|
|
102
|
-
expect(() => validate(manifest)).toThrow(/must be equal to constant
|
|
100
|
+
expect(() => validate(manifest)).toThrow(/must be equal to constant/)
|
|
103
101
|
|
|
104
102
|
manifest.entity.schema = {}
|
|
105
103
|
validate(manifest)
|
|
@@ -154,7 +152,7 @@ describe('operations', () => {
|
|
|
154
152
|
|
|
155
153
|
it('should not have additional properties', () => {
|
|
156
154
|
manifest.operations.get.foo = 'bar'
|
|
157
|
-
expect(() => validate(manifest)).toThrow(
|
|
155
|
+
expect(() => validate(manifest)).toThrow()
|
|
158
156
|
})
|
|
159
157
|
|
|
160
158
|
it('should have type (transition or observation)', () => {
|
|
@@ -176,8 +174,7 @@ describe('operations', () => {
|
|
|
176
174
|
})
|
|
177
175
|
|
|
178
176
|
it.each([
|
|
179
|
-
['computation', 'compute']
|
|
180
|
-
['effect', 'affect']
|
|
177
|
+
['computation', 'compute']
|
|
181
178
|
])('should set query: false for %s', async (_, operation) => {
|
|
182
179
|
validate(manifest)
|
|
183
180
|
|
|
@@ -250,7 +247,7 @@ describe('receivers', () => {
|
|
|
250
247
|
it('should throw if transition points to observation', () => {
|
|
251
248
|
manifest.receivers['foo.bar.happened'].operation = 'get'
|
|
252
249
|
|
|
253
|
-
expect(() => validate(manifest)).toThrow(/
|
|
250
|
+
expect(() => validate(manifest)).toThrow(/of the allowed types/)
|
|
254
251
|
})
|
|
255
252
|
|
|
256
253
|
it('should throw if source has a name `context`', async () => {
|
|
@@ -45,12 +45,6 @@ describe('registry', () => {
|
|
|
45
45
|
expect(() => validate(context)).toThrow(/required property 'registry'/)
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
it('should require base', () => {
|
|
49
|
-
delete context.registry.base
|
|
50
|
-
|
|
51
|
-
expect(() => validate(context)).toThrow(/required property 'base'/)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
48
|
it('should set default platforms', () => {
|
|
55
49
|
delete context.registry.platforms
|
|
56
50
|
|
|
@@ -72,13 +66,19 @@ it('should require name as label', () => {
|
|
|
72
66
|
expect(() => validate(context)).not.toThrow(/pattern/)
|
|
73
67
|
})
|
|
74
68
|
|
|
75
|
-
it('should set default packages location', () => {
|
|
76
|
-
delete context.packages
|
|
77
|
-
expect(() => validate(context)).not.toThrow()
|
|
78
|
-
expect(context.packages).toBe('components/*')
|
|
79
|
-
})
|
|
80
|
-
|
|
81
69
|
it('should require registry url', () => {
|
|
82
70
|
delete context.registry
|
|
83
71
|
expect(() => validate(context)).toThrow(/required/)
|
|
84
72
|
})
|
|
73
|
+
|
|
74
|
+
it('should allow mono replicas and resources', () => {
|
|
75
|
+
context.mono = {
|
|
76
|
+
replicas: 2,
|
|
77
|
+
resources: {
|
|
78
|
+
cpu: ['200m', '2'],
|
|
79
|
+
memory: ['256Mi', '2Gi']
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
expect(() => validate(context)).not.toThrow()
|
|
84
|
+
})
|
|
@@ -5,13 +5,34 @@ interface Composition {
|
|
|
5
5
|
components: string[]
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export interface Resources {
|
|
9
|
+
cpu?: [string, string]
|
|
10
|
+
memory?: [string, string]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Mono {
|
|
14
|
+
replicas?: number
|
|
15
|
+
resources?: Resources
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Cluster-level ingress configuration, applied to every service that declares one.
|
|
20
|
+
*/
|
|
21
|
+
export interface Ingress {
|
|
22
|
+
hosts?: string[]
|
|
23
|
+
class?: string
|
|
24
|
+
annotations?: Record<string, string>
|
|
25
|
+
default?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
8
28
|
export interface Declaration {
|
|
9
29
|
name: string
|
|
10
30
|
description?: string
|
|
11
31
|
version?: string
|
|
12
32
|
runtime?: Runtime | string
|
|
13
33
|
registry?: Registry | string
|
|
14
|
-
packages?: string
|
|
15
34
|
compositions?: Composition[]
|
|
35
|
+
mono?: Mono
|
|
36
|
+
ingress?: Ingress
|
|
16
37
|
annotations?: Record<string, object>
|
|
17
38
|
}
|