@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.
@@ -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 resolve absolute references', () => {
25
- const origins = manifest.extensions['@toa.io/extensions.origins']
26
- const path = dirname(require.resolve('@toa.io/extensions.origins/package.json'))
22
+ it('should add predefined extensions', () => {
23
+ extensions(manifest)
27
24
 
28
- normalize(manifest)
25
+ expect(manifest.extensions['@toa.io/extensions.telemetry']).toBeNull()
26
+ expect(manifest.extensions['@toa.io/extensions.fetch']).toBeNull()
27
+ })
29
28
 
30
- expect(manifest.extensions[path]).toStrictEqual(origins)
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(/must NOT have additional property/)
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(/must NOT have additional property/)
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(/must NOT have additional property/)
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(/must have required property/)
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 'object'/)
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(/additional property/)
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(/one of the allowed types/)
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 () => {
@@ -21,7 +21,6 @@ const context = {
21
21
  name: 'test',
22
22
  description: 'context fixture',
23
23
  version: '0.0.0',
24
- packages: 'namespaces/**/*',
25
24
  registry: 'localhost:5000',
26
25
  components: [
27
26
  component('a.b'),
@@ -27,7 +27,6 @@ const context = {
27
27
  description: 'context fixture',
28
28
  version: '0.0.0',
29
29
  runtime: '0.0.0',
30
- packages: 'namespaces/**/*',
31
30
  registry: 'localhost:5000',
32
31
  components: [component('a.b'), component('b.a'), component('d.c')],
33
32
  compositions: [
@@ -9,7 +9,6 @@ const context = {
9
9
  name: 'test',
10
10
  description: 'context fixture',
11
11
  version: '0.0.0',
12
- packages: 'namespaces/**/*',
13
12
  registry: 'localhost:5000',
14
13
  compositions: [
15
14
  {
@@ -7,7 +7,6 @@ const context = {
7
7
  name: 'test',
8
8
  description: 'context fixture',
9
9
  version: '0.0.0',
10
- packages: 'namespaces/**/*',
11
10
  build: {
12
11
  command: 'echo test'
13
12
  },
@@ -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
  }