@toa.io/norm 1.0.0-alpha.28 → 1.0.0-alpha.283
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 +195 -0
- package/package.json +8 -7
- package/src/.component/.expand/bridge.js +2 -6
- package/src/.component/.expand/entity.js +2 -9
- package/src/.component/.expand/events.js +2 -6
- package/src/.component/.expand/extensions.js +4 -8
- package/src/.component/.expand/index.js +8 -19
- package/src/.component/.expand/operations.js +2 -9
- package/src/.component/.expand/properties.js +2 -6
- package/src/.component/.expand/receivers.js +2 -6
- package/src/.component/.expand/version.js +39 -27
- package/src/.component/.normalize/events.js +12 -5
- package/src/.component/.normalize/index.js +3 -9
- package/src/.component/.normalize/operations.js +2 -6
- package/src/.component/.normalize/receivers.js +1 -5
- package/src/.component/collapse.js +7 -6
- package/src/.component/defaults.js +14 -7
- package/src/.component/dependencies.js +7 -6
- package/src/.component/dereference.js +8 -7
- package/src/.component/expand.js +2 -15
- package/src/.component/extensions.js +13 -7
- package/src/.component/index.js +9 -21
- package/src/.component/merge.js +22 -9
- package/src/.component/normalize.js +3 -7
- package/src/.component/schema.yaml +82 -41
- package/src/.component/validate.js +15 -16
- package/src/.context/.dependencies/connectors.js +2 -6
- package/src/.context/.dependencies/describe.js +1 -5
- package/src/.context/.dependencies/extensions.js +55 -18
- package/src/.context/.dependencies/index.js +3 -9
- package/src/.context/.dependencies/load.js +14 -13
- package/src/.context/.dependencies/resolve.js +23 -6
- package/src/.context/complete.js +1 -5
- package/src/.context/dependencies.js +2 -6
- package/src/.context/dereference.js +9 -6
- package/src/.context/expand.js +8 -6
- package/src/.context/index.js +6 -15
- package/src/.context/normalize.js +2 -6
- package/src/.context/schema.yaml +126 -7
- package/src/.context/validate.js +8 -14
- package/src/component.js +31 -28
- package/src/context.js +28 -20
- package/src/index.js +3 -9
- package/src/shortcuts.js +7 -12
- package/test/component/collapse.fixtures.js +2 -5
- package/test/component/collapse.test.js +17 -10
- package/test/component/dependencies.test.js +12 -10
- package/test/component/dereference.fixtures.js +2 -7
- package/test/component/dereference.test.js +9 -8
- package/test/component/dummies/extension/index.js +1 -5
- package/test/component/expand.fixtures.js +13 -13
- package/test/component/expand.test.js +25 -10
- package/test/component/normalize.fixtures.js +3 -7
- package/test/component/normalize.test.js +27 -17
- package/test/component/validate.fixtures.js +1 -5
- package/test/component/validate.test.js +89 -90
- package/test/context/complete.fixtures.js +2 -8
- package/test/context/complete.test.js +10 -8
- package/test/context/dependencies.load.test.js +13 -12
- package/test/context/dereference.fixtures.js +3 -9
- package/test/context/dereference.test.js +17 -7
- package/test/context/expand.fixtures.js +1 -5
- package/test/context/expand.test.js +34 -8
- package/test/context/normalize.fixtures.js +2 -7
- package/test/context/normalize.test.js +10 -8
- package/test/context/validate.fixtures.js +1 -6
- package/test/context/validate.test.js +54 -30
- package/test/shortcuts.fixtures.js +4 -9
- package/test/shortcuts.test.js +16 -15
- package/types/context/declaration.d.ts +25 -2
- package/types/context.d.ts +5 -4
- package/types/index.d.ts +3 -3
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import * as runtime from '@toa.io/runtime'
|
|
2
|
+
import { it, beforeEach } from 'node:test'
|
|
3
|
+
import assert from 'node:assert/strict'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
import clone from 'clone-deep'
|
|
6
|
+
import { generate } from 'randomstring'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
import * as fixtures from './normalize.fixtures.js'
|
|
9
|
+
import { normalize } from '../../src/.context/index.js'
|
|
8
10
|
|
|
9
11
|
let context
|
|
10
12
|
|
|
@@ -17,8 +19,8 @@ it('should resolve local version', () => {
|
|
|
17
19
|
|
|
18
20
|
normalize(context)
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
assert.notDeepStrictEqual(context.runtime, '.')
|
|
23
|
+
assert.deepStrictEqual(context.runtime.version, runtime.version)
|
|
22
24
|
})
|
|
23
25
|
|
|
24
26
|
it('should expand registry', () => {
|
|
@@ -28,7 +30,7 @@ it('should expand registry', () => {
|
|
|
28
30
|
|
|
29
31
|
normalize(context)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
assert.deepStrictEqual(context.registry, {
|
|
32
34
|
base
|
|
33
35
|
})
|
|
34
36
|
})
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const context = {
|
|
1
|
+
export const context = {
|
|
4
2
|
runtime: {
|
|
5
3
|
version: '0.0.0'
|
|
6
4
|
},
|
|
7
5
|
name: 'test',
|
|
8
6
|
description: 'context fixture',
|
|
9
7
|
version: '0.0.0',
|
|
10
|
-
packages: 'namespaces/**/*',
|
|
11
8
|
build: {
|
|
12
9
|
command: 'echo test'
|
|
13
10
|
},
|
|
@@ -37,5 +34,3 @@ const context = {
|
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
exports.context = context
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, before, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import clone from 'clone-deep'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { validate } from '../../src/.context/index.js'
|
|
7
|
+
import * as fixtures from './validate.fixtures.js'
|
|
7
8
|
|
|
8
9
|
let context
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
before(() => {
|
|
12
|
+
assert.doesNotThrow(() => validate(fixtures.context))
|
|
12
13
|
})
|
|
13
14
|
|
|
14
15
|
beforeEach(() => {
|
|
@@ -18,23 +19,23 @@ beforeEach(() => {
|
|
|
18
19
|
describe('runtime', () => {
|
|
19
20
|
it('should require', () => {
|
|
20
21
|
delete context.runtime
|
|
21
|
-
|
|
22
|
+
assert.throws(() => validate(context), (error) => /required/.test(error.message))
|
|
22
23
|
})
|
|
23
24
|
|
|
24
25
|
it('should require registry to match uri format', () => {
|
|
25
26
|
context.runtime.registry = 'not-a-uri'
|
|
26
|
-
|
|
27
|
+
assert.throws(() => validate(context), (error) => /must match format/.test(error.message))
|
|
27
28
|
|
|
28
29
|
context.runtime.registry = 'http://localhost'
|
|
29
|
-
|
|
30
|
+
assert.doesNotThrow(() => validate(context))
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
it('should require proxy to match uri format', () => {
|
|
33
34
|
context.runtime.proxy = 'not-a-uri'
|
|
34
|
-
|
|
35
|
+
assert.throws(() => validate(context), (error) => /must match format/.test(error.message))
|
|
35
36
|
|
|
36
37
|
context.runtime.proxy = 'http://localhost'
|
|
37
|
-
|
|
38
|
+
assert.doesNotThrow(() => validate(context))
|
|
38
39
|
})
|
|
39
40
|
})
|
|
40
41
|
|
|
@@ -42,13 +43,7 @@ describe('registry', () => {
|
|
|
42
43
|
it('should require', () => {
|
|
43
44
|
delete context.registry
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should require base', () => {
|
|
49
|
-
delete context.registry.base
|
|
50
|
-
|
|
51
|
-
expect(() => validate(context)).toThrow(/required property 'base'/)
|
|
46
|
+
assert.throws(() => validate(context), (error) => /required property 'registry'/.test(error.message))
|
|
52
47
|
})
|
|
53
48
|
|
|
54
49
|
it('should set default platforms', () => {
|
|
@@ -56,29 +51,58 @@ describe('registry', () => {
|
|
|
56
51
|
|
|
57
52
|
validate(context)
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
assert.ok(context.registry.platforms instanceof Array)
|
|
55
|
+
assert.deepStrictEqual(context.registry.platforms, ['linux/amd64', 'linux/arm/v7', 'linux/arm64'])
|
|
61
56
|
})
|
|
62
57
|
})
|
|
63
58
|
|
|
64
59
|
it('should require name as label', () => {
|
|
65
60
|
delete context.name
|
|
66
|
-
|
|
61
|
+
assert.throws(() => validate(context), (error) => /required/.test(error.message))
|
|
67
62
|
|
|
68
63
|
context.name = 'foo bar'
|
|
69
|
-
|
|
64
|
+
assert.throws(() => validate(context), (error) => /pattern/.test(error.message))
|
|
70
65
|
|
|
71
66
|
context.name = 'foo-bar'
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should set default packages location', () => {
|
|
76
|
-
delete context.packages
|
|
77
|
-
expect(() => validate(context)).not.toThrow()
|
|
78
|
-
expect(context.packages).toBe('components/*')
|
|
67
|
+
assert.doesNotThrow(() => validate(context))
|
|
79
68
|
})
|
|
80
69
|
|
|
81
70
|
it('should require registry url', () => {
|
|
82
71
|
delete context.registry
|
|
83
|
-
|
|
72
|
+
assert.throws(() => validate(context), (error) => /required/.test(error.message))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should allow mono replicas and resources', () => {
|
|
76
|
+
context.mono = {
|
|
77
|
+
replicas: 2,
|
|
78
|
+
resources: {
|
|
79
|
+
cpu: ['200m', '2'],
|
|
80
|
+
memory: ['256Mi', '2Gi']
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
assert.doesNotThrow(() => validate(context))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('compositions', () => {
|
|
88
|
+
it('should allow services', () => {
|
|
89
|
+
context.compositions[0].services = ['@toa.io/extensions.exposition']
|
|
90
|
+
|
|
91
|
+
assert.doesNotThrow(() => validate(context))
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should require services to be a non-empty array of strings', () => {
|
|
95
|
+
context.compositions[0].services = []
|
|
96
|
+
assert.throws(() => validate(context), (error) => /fewer than 1 items/.test(error.message))
|
|
97
|
+
|
|
98
|
+
context.compositions[0].services = 'exposition'
|
|
99
|
+
assert.throws(() => validate(context), (error) => /must be array/.test(error.message))
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('should reject an unknown property', () => {
|
|
103
|
+
context.compositions[0].compoments = ['a.b']
|
|
104
|
+
|
|
105
|
+
assert.throws(() => validate(context),
|
|
106
|
+
(error) => /Property compoments is not expected to be here/.test(error.message))
|
|
107
|
+
})
|
|
84
108
|
})
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { generate } from 'randomstring'
|
|
2
|
+
import { random } from '@toa.io/generic'
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
const { random } = require('@toa.io/generic')
|
|
5
|
-
|
|
6
|
-
const SHORTCUTS = {
|
|
4
|
+
export const SHORTCUTS = {
|
|
7
5
|
amqp: '@toa.io/bindings.amqp',
|
|
8
6
|
mongodb: '@toa.io/storages.mongodb'
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
const object = { foo: random(), bar: { baz: generate() } }
|
|
12
|
-
|
|
13
|
-
exports.object = object
|
|
14
|
-
exports.SHORTCUTS = SHORTCUTS
|
|
9
|
+
export const object = { foo: random(), bar: { baz: generate() } }
|
package/test/shortcuts.test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import clone from 'clone-deep'
|
|
5
|
+
import { generate } from 'randomstring'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { recognize, resolve } from '../src/shortcuts.js'
|
|
8
|
+
import * as fixtures from './shortcuts.fixtures.js'
|
|
8
9
|
|
|
9
10
|
let object
|
|
10
11
|
|
|
@@ -14,16 +15,16 @@ beforeEach(() => {
|
|
|
14
15
|
|
|
15
16
|
describe('resolve', () => {
|
|
16
17
|
it('should be defined', () => {
|
|
17
|
-
|
|
18
|
+
assert.notStrictEqual(resolve, undefined)
|
|
18
19
|
})
|
|
19
20
|
|
|
20
21
|
it('should resolve', () => {
|
|
21
|
-
|
|
22
|
+
assert.ok(Object.keys(fixtures.SHORTCUTS).length > 0)
|
|
22
23
|
|
|
23
24
|
for (const [key, value] of Object.entries(fixtures.SHORTCUTS)) {
|
|
24
25
|
const resolved = resolve(key)
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
assert.deepStrictEqual(resolved, value)
|
|
27
28
|
}
|
|
28
29
|
})
|
|
29
30
|
})
|
|
@@ -32,7 +33,7 @@ describe('recognize', () => {
|
|
|
32
33
|
it('should not change unknown', () => {
|
|
33
34
|
recognize(fixtures.SHORTCUTS, object)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
assert.deepStrictEqual(object, fixtures.object)
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
it('should resolve known', () => {
|
|
@@ -41,8 +42,8 @@ describe('recognize', () => {
|
|
|
41
42
|
recognize(fixtures.SHORTCUTS, object)
|
|
42
43
|
|
|
43
44
|
for (const [alias, name] of Object.entries(fixtures.SHORTCUTS)) {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
assert.strictEqual(object[alias], undefined)
|
|
46
|
+
assert.deepStrictEqual(object[name], known[name])
|
|
46
47
|
}
|
|
47
48
|
})
|
|
48
49
|
|
|
@@ -52,9 +53,9 @@ describe('recognize', () => {
|
|
|
52
53
|
|
|
53
54
|
recognize(fixtures.SHORTCUTS, object, group)
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
assert.deepStrictEqual(object[group], known)
|
|
56
57
|
|
|
57
|
-
for (const alias of Object.keys(fixtures.SHORTCUTS))
|
|
58
|
+
for (const alias of Object.keys(fixtures.SHORTCUTS)) assert.strictEqual(object[alias], undefined)
|
|
58
59
|
})
|
|
59
60
|
|
|
60
61
|
it('should not overwrite group', () => {
|
|
@@ -67,7 +68,7 @@ describe('recognize', () => {
|
|
|
67
68
|
|
|
68
69
|
recognize(fixtures.SHORTCUTS, object, group)
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
assert.partialDeepStrictEqual(object[group], existing)
|
|
71
72
|
})
|
|
72
73
|
|
|
73
74
|
it('should not create empty group', () => {
|
|
@@ -75,7 +76,7 @@ describe('recognize', () => {
|
|
|
75
76
|
|
|
76
77
|
recognize(object, group)
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
assert.strictEqual(object[group], undefined)
|
|
79
80
|
})
|
|
80
81
|
|
|
81
82
|
const append = () => {
|
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Registry, Runtime } from '../context.js'
|
|
2
2
|
|
|
3
|
+
/** A composition as declared, before its members are resolved. */
|
|
3
4
|
interface Composition {
|
|
4
5
|
name: string,
|
|
5
6
|
components: string[]
|
|
7
|
+
services?: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Resources {
|
|
11
|
+
cpu?: [string, string]
|
|
12
|
+
memory?: [string, string]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Mono {
|
|
16
|
+
replicas?: number
|
|
17
|
+
resources?: Resources
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Cluster-level ingress configuration, applied to every service that declares one.
|
|
22
|
+
*/
|
|
23
|
+
export interface Ingress {
|
|
24
|
+
hosts?: string[]
|
|
25
|
+
class?: string
|
|
26
|
+
annotations?: Record<string, string>
|
|
27
|
+
default?: boolean
|
|
6
28
|
}
|
|
7
29
|
|
|
8
30
|
export interface Declaration {
|
|
@@ -11,7 +33,8 @@ export interface Declaration {
|
|
|
11
33
|
version?: string
|
|
12
34
|
runtime?: Runtime | string
|
|
13
35
|
registry?: Registry | string
|
|
14
|
-
packages?: string
|
|
15
36
|
compositions?: Composition[]
|
|
37
|
+
mono?: Mono
|
|
38
|
+
ingress?: Ingress
|
|
16
39
|
annotations?: Record<string, object>
|
|
17
40
|
}
|
package/types/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Manifest } from './component'
|
|
1
|
+
import { Manifest } from './component.js'
|
|
2
2
|
import { Locator } from '@toa.io/core'
|
|
3
|
-
import type { Declaration } from './context/declaration'
|
|
3
|
+
import type { Declaration } from './context/declaration.js'
|
|
4
4
|
|
|
5
5
|
interface Runtime{
|
|
6
6
|
version: string
|
|
@@ -20,7 +20,8 @@ interface Registry{
|
|
|
20
20
|
|
|
21
21
|
interface Composition{
|
|
22
22
|
name: string,
|
|
23
|
-
components:
|
|
23
|
+
components: Manifest[]
|
|
24
|
+
services?: string[]
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface Dependency<T = undefined>{
|
|
@@ -34,7 +35,7 @@ interface Context extends Declaration{
|
|
|
34
35
|
environment?: string
|
|
35
36
|
registry?: Registry
|
|
36
37
|
compositions?: Composition[]
|
|
37
|
-
components?:
|
|
38
|
+
components?: Manifest[]
|
|
38
39
|
dependencies?: Record<string, Dependency[]>
|
|
39
40
|
}
|
|
40
41
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * as context from './context'
|
|
2
|
-
export * as component from './component'
|
|
1
|
+
export * as context from './context.js'
|
|
2
|
+
export * as component from './component.js'
|
|
3
3
|
|
|
4
|
-
export { Manifest } from './component'
|
|
4
|
+
export { Manifest } from './component.js'
|