@toa.io/extensions.configuration 0.7.3 → 0.20.0-alpha.0

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.
Files changed (77) hide show
  1. package/package.json +15 -9
  2. package/readme.md +77 -137
  3. package/schemas/annotation.cos.yaml +1 -0
  4. package/schemas/manifest.cos.yaml +2 -0
  5. package/source/Aspect.test.ts +15 -0
  6. package/source/Aspect.ts +23 -0
  7. package/source/Factory.ts +12 -0
  8. package/source/configuration.test.ts +89 -0
  9. package/source/configuration.ts +53 -0
  10. package/source/deployment.test.ts +21 -0
  11. package/source/deployment.ts +69 -0
  12. package/source/index.ts +3 -0
  13. package/source/manifest.test.ts +15 -0
  14. package/source/manifest.ts +15 -0
  15. package/source/schemas.ts +8 -0
  16. package/transpiled/Aspect.d.ts +7 -0
  17. package/transpiled/Aspect.js +21 -0
  18. package/transpiled/Aspect.js.map +1 -0
  19. package/transpiled/Aspect.test.d.ts +1 -0
  20. package/transpiled/Aspect.test.js +15 -0
  21. package/transpiled/Aspect.test.js.map +1 -0
  22. package/transpiled/Factory.d.ts +5 -0
  23. package/transpiled/Factory.js +13 -0
  24. package/transpiled/Factory.js.map +1 -0
  25. package/transpiled/configuration.d.ts +4 -0
  26. package/transpiled/configuration.js +66 -0
  27. package/transpiled/configuration.js.map +1 -0
  28. package/transpiled/configuration.test.d.ts +1 -0
  29. package/transpiled/configuration.test.js +64 -0
  30. package/transpiled/configuration.test.js.map +1 -0
  31. package/transpiled/deployment.d.ts +8 -0
  32. package/transpiled/deployment.js +75 -0
  33. package/transpiled/deployment.js.map +1 -0
  34. package/transpiled/deployment.test.d.ts +1 -0
  35. package/transpiled/deployment.test.js +18 -0
  36. package/transpiled/deployment.test.js.map +1 -0
  37. package/transpiled/index.d.ts +3 -0
  38. package/transpiled/index.js +10 -0
  39. package/transpiled/index.js.map +1 -0
  40. package/transpiled/manifest.d.ts +6 -0
  41. package/transpiled/manifest.js +35 -0
  42. package/transpiled/manifest.js.map +1 -0
  43. package/transpiled/manifest.test.d.ts +1 -0
  44. package/transpiled/manifest.test.js +14 -0
  45. package/transpiled/manifest.test.js.map +1 -0
  46. package/transpiled/schemas.d.ts +2 -0
  47. package/transpiled/schemas.js +33 -0
  48. package/transpiled/schemas.js.map +1 -0
  49. package/transpiled/tsconfig.tsbuildinfo +1 -0
  50. package/tsconfig.json +9 -0
  51. package/docs/discussion.md +0 -109
  52. package/src/.manifest/.normalize/verbose.js +0 -48
  53. package/src/.manifest/index.js +0 -7
  54. package/src/.manifest/normalize.js +0 -16
  55. package/src/.manifest/schema.yaml +0 -8
  56. package/src/.manifest/validate.js +0 -13
  57. package/src/.provider/form.js +0 -20
  58. package/src/annotation.js +0 -36
  59. package/src/aspect.js +0 -36
  60. package/src/configuration.js +0 -19
  61. package/src/deployment.js +0 -23
  62. package/src/factory.js +0 -39
  63. package/src/index.js +0 -13
  64. package/src/manifest.js +0 -13
  65. package/src/provider.js +0 -114
  66. package/test/annotations.fixtures.js +0 -38
  67. package/test/annotations.test.js +0 -43
  68. package/test/aspect.fixtures.js +0 -33
  69. package/test/aspect.test.js +0 -77
  70. package/test/deployment.fixtures.js +0 -38
  71. package/test/deployment.test.js +0 -45
  72. package/test/factory.test.js +0 -22
  73. package/test/manifest.test.js +0 -132
  74. package/types/aspect.ts +0 -11
  75. package/types/factory.d.ts +0 -12
  76. package/types/provider.d.ts +0 -22
  77. /package/{docs → notes}/consistency.md +0 -0
@@ -1,77 +0,0 @@
1
- 'use strict'
2
-
3
- const { Locator } = require('@toa.io/core')
4
- const { encode } = require('@toa.io/generic')
5
-
6
- const fixtures = require('./aspect.fixtures')
7
- const { Factory } = require('../')
8
- const { generate } = require('randomstring')
9
-
10
- const factory = new Factory()
11
-
12
- /** @type {toa.extensions.configuration.Aspect} */
13
- let aspect
14
-
15
- /** @type {toa.core.Locator} */
16
- let locator
17
-
18
- describe('defaults', () => {
19
- beforeEach(async () => {
20
- const namespace = generate()
21
- const name = generate()
22
-
23
- locator = new Locator(name, namespace)
24
-
25
- aspect = factory.aspect(locator, fixtures.schema)
26
-
27
- await aspect.connect()
28
- })
29
-
30
- it('should return schema defaults', () => {
31
- const foo = aspect.invoke(['foo'])
32
-
33
- expect(foo).toStrictEqual(fixtures.schema.properties.foo.default)
34
- })
35
-
36
- it('should return nested values', () => {
37
- const baz = aspect.invoke(['bar', 'baz'])
38
-
39
- expect(baz).toStrictEqual(fixtures.schema.properties.bar.properties.baz.default)
40
- })
41
-
42
- it('should expose configuration tree', () => {
43
- const configuration = aspect.invoke()
44
-
45
- expect(configuration).toStrictEqual({
46
- foo: fixtures.schema.properties.foo.default,
47
- bar: {
48
- baz: fixtures.schema.properties.bar.properties.baz.default
49
- },
50
- quu: 0
51
- })
52
- })
53
- })
54
-
55
- describe('resolution', () => {
56
- let object
57
- let varname
58
-
59
- beforeEach(() => {
60
- object = { foo: generate() }
61
-
62
- varname = 'TOA_CONFIGURATION_' + locator.uppercase
63
- })
64
-
65
- it('should resolve configuration object from environment variable', async () => {
66
- process.env[varname] = encode(object)
67
-
68
- aspect = factory.aspect(locator, fixtures.schema)
69
-
70
- await aspect.connect()
71
-
72
- const configuration = aspect.invoke()
73
-
74
- expect(configuration.foo).toStrictEqual(object.foo)
75
- expect(configuration.bar.baz).toStrictEqual(fixtures.schema.properties.bar.properties.baz.default)
76
- })
77
- })
@@ -1,38 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
-
5
- const { Locator } = require('@toa.io/core')
6
- const { random } = require('@toa.io/generic')
7
-
8
- const component = () => {
9
- const namespace = generate()
10
- const name = generate()
11
-
12
- return { locator: new Locator(name, namespace) }
13
- }
14
-
15
- /** @type {toa.norm.context.dependencies.Instance[]} */
16
- const components = []
17
- const annotations = {}
18
-
19
- const annotate = (component) => {
20
- const key = component.locator.id
21
-
22
- annotations[key] = { [generate()]: generate() }
23
- }
24
-
25
- for (let i = 0; i < random(10) + 5; i++) components.push(component())
26
- for (let i = 0; i < components.length; i++) if (i % 2 === 0) annotate(components[i])
27
-
28
- /**
29
- * @param {string} id
30
- * @returns {toa.norm.context.dependencies.Instance}
31
- */
32
- const find = (id) => {
33
- return components.find((component) => component.locator.id === id)
34
- }
35
-
36
- exports.components = components
37
- exports.annotations = annotations
38
- exports.find = find
@@ -1,45 +0,0 @@
1
- 'use strict'
2
-
3
- const { encode } = require('@toa.io/generic')
4
-
5
- const fixtures = require('./deployment.fixtures')
6
- const { deployment } = require('../')
7
-
8
- /** @type {toa.deployment.dependency.Declaration} */
9
- let declaration
10
-
11
- beforeAll(() => {
12
- declaration = deployment(fixtures.components, fixtures.annotations)
13
- })
14
-
15
- it('should exist', () => {
16
- expect(deployment).toBeDefined()
17
- })
18
-
19
- it('should declare variables', () => {
20
- expect(declaration.variables).toBeDefined()
21
- })
22
-
23
- it('should map configurations', () => {
24
- const keys = Object.keys(fixtures.annotations)
25
-
26
- expect(keys.length).toBeGreaterThan(0)
27
-
28
- for (const [id, annotations] of Object.entries(fixtures.annotations)) {
29
- const component = fixtures.find(id)
30
- const variables = declaration.variables[component.locator.label]
31
- const encoded = encode(annotations)
32
-
33
- expect(component).toBeDefined()
34
- expect(variables).toBeDefined()
35
- expect(variables).toBeInstanceOf(Array)
36
- expect(variables.length).toStrictEqual(1)
37
-
38
- const env = variables[0]
39
-
40
- expect(env.name).toBeDefined()
41
- expect(env.name).toStrictEqual('TOA_CONFIGURATION_' + component.locator.uppercase)
42
- expect(env.value).toBeDefined()
43
- expect(env.value).toStrictEqual(encoded)
44
- }
45
- })
@@ -1,22 +0,0 @@
1
- 'use strict'
2
-
3
- const { Factory } = require('../')
4
-
5
- it('should export', () => {
6
- expect(Factory).toBeInstanceOf(Function)
7
- })
8
-
9
- /** @type {toa.extensions.configuration.Factory} */
10
- let factory
11
-
12
- beforeAll(async () => {
13
- factory = new Factory()
14
- })
15
-
16
- it('should expose context', () => {
17
- expect(factory.aspect).toBeInstanceOf(Function)
18
- })
19
-
20
- it('should expose provider', () => {
21
- expect(factory.provider).toBeInstanceOf(Function)
22
- })
@@ -1,132 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
- const { random } = require('@toa.io/generic')
5
-
6
- const { manifest } = require('../')
7
-
8
- it('should export', () => {
9
- expect(manifest).toBeInstanceOf(Function)
10
- })
11
-
12
- describe('validation', () => {
13
- it('should throw if not an object', () => {
14
- const call = () => manifest(generate())
15
- expect(call).toThrow(/must be object/)
16
- })
17
-
18
- it('should throw if not a valid schema', () => {
19
- const object = { type: generate() }
20
- const call = () => manifest(object)
21
-
22
- expect(call).toThrow(/one of the allowed values/)
23
- })
24
-
25
- it('should throw if schema is not an object type', () => {
26
- const schema = { type: 'number' }
27
- const call = () => manifest(schema)
28
-
29
- expect(call).toThrow(/equal to constant 'object'/)
30
- })
31
- })
32
-
33
- describe('normalization', () => {
34
- it('should expand concise', () => {
35
- const concise = {
36
- foo: generate(),
37
- bar: {
38
- baz: random()
39
- }
40
- }
41
-
42
- const declaration = manifest(concise)
43
-
44
- expect(declaration).toMatchObject({
45
- type: 'object',
46
- properties: {
47
- foo: {
48
- type: 'string',
49
- default: concise.foo
50
- },
51
- bar: {
52
- type: 'object',
53
- properties: {
54
- baz: {
55
- type: 'number',
56
- default: concise.bar.baz
57
- }
58
- }
59
- }
60
- }
61
- })
62
- })
63
-
64
- it('should expand partially concise', () => {
65
- const concise = {
66
- foo: generate(),
67
- bar: {
68
- baz: random()
69
- },
70
- qux: {
71
- type: 'string',
72
- default: null
73
- }
74
- }
75
-
76
- const declaration = manifest(concise)
77
-
78
- expect(declaration).toMatchObject({
79
- type: 'object',
80
- properties: {
81
- foo: {
82
- type: 'string',
83
- default: concise.foo
84
- },
85
- bar: {
86
- type: 'object',
87
- properties: {
88
- baz: {
89
- type: 'number',
90
- default: concise.bar.baz
91
- }
92
- }
93
- },
94
- qux: {
95
- type: 'string',
96
- default: null
97
- }
98
- }
99
- })
100
- })
101
-
102
- it('should expand arrays', () => {
103
- const concise = { foo: [1, 2, 3] }
104
-
105
- const declaration = manifest(concise)
106
-
107
- expect(declaration).toMatchObject({
108
- type: 'object',
109
- properties: {
110
- foo: {
111
- type: 'array',
112
- items: {
113
- type: 'number'
114
- },
115
- default: [1, 2, 3]
116
- }
117
- }
118
- })
119
- })
120
-
121
- it('should throw on empty array', () => {
122
- const concise = { foo: [] }
123
-
124
- expect(() => manifest(concise)).toThrow(/array items type because it's empty/)
125
- })
126
-
127
- it('should throw on null', () => {
128
- const concise = { foo: null }
129
-
130
- expect(() => manifest(concise)).toThrow(/type of null/)
131
- })
132
- })
package/types/aspect.ts DELETED
@@ -1,11 +0,0 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import * as core from '@toa.io/core/types/extensions'
4
-
5
- declare namespace toa.extensions.configuration {
6
-
7
- interface Aspect extends core.Aspect {
8
- invoke(path?: string[]): any
9
- }
10
-
11
- }
@@ -1,12 +0,0 @@
1
- import { Component } from '@toa.io/norm/types'
2
-
3
- import * as _extensions from '@toa.io/core/types/extensions'
4
- import * as _provider from './provider'
5
-
6
- declare namespace toa.extensions.configuration {
7
-
8
- interface Factory extends _extensions.Factory {
9
- provider(component: Component): _provider.Provider
10
- }
11
-
12
- }
@@ -1,22 +0,0 @@
1
- import { Source } from '@toa.io/core/types/reflection'
2
- import { Connector } from '@toa.io/core/types'
3
-
4
- declare namespace toa.extensions.configuration {
5
-
6
- interface Provider extends Connector {
7
- source: Source
8
- object: Object
9
- key: string
10
-
11
- set(key: string, value: any): void
12
-
13
- unset(key: string): void
14
-
15
- reset(): void
16
-
17
- export(): string
18
- }
19
-
20
- }
21
-
22
- export type Provider = toa.extensions.configuration.Provider
File without changes