@toa.io/operations 1.0.0-alpha.28 → 1.0.0-alpha.280

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 (64) hide show
  1. package/CHANGELOG.md +204 -0
  2. package/image/runtime.Dockerfile +4 -0
  3. package/package.json +10 -10
  4. package/readme.md +16 -0
  5. package/src/deployment/.deployment/.describe/components.js +1 -5
  6. package/src/deployment/.deployment/.describe/compositions.js +8 -7
  7. package/src/deployment/.deployment/.describe/dependencies.js +1 -6
  8. package/src/deployment/.deployment/.describe/events.js +63 -0
  9. package/src/deployment/.deployment/.describe/index.js +4 -13
  10. package/src/deployment/.deployment/.describe/mounts.js +20 -0
  11. package/src/deployment/.deployment/.describe/resources.js +33 -0
  12. package/src/deployment/.deployment/.describe/services.js +28 -5
  13. package/src/deployment/.deployment/.describe/services.test.js +61 -0
  14. package/src/deployment/.deployment/.describe/variables.js +6 -9
  15. package/src/deployment/.deployment/declare.js +1 -5
  16. package/src/deployment/.deployment/describe.js +133 -9
  17. package/src/deployment/.deployment/index.js +3 -9
  18. package/src/deployment/.deployment/merge.js +46 -6
  19. package/src/deployment/.deployment/merge.test.js +72 -0
  20. package/src/deployment/chart/templates/compositions.yaml +70 -0
  21. package/src/deployment/chart/templates/mono.yaml +181 -0
  22. package/src/deployment/chart/templates/services.yaml +75 -4
  23. package/src/deployment/chart/values.yaml +11 -1
  24. package/src/deployment/composition.js +2 -5
  25. package/src/deployment/deployment.js +19 -12
  26. package/src/deployment/factory.js +50 -28
  27. package/src/deployment/images/composition.Dockerfile +2 -2
  28. package/src/deployment/images/composition.js +26 -22
  29. package/src/deployment/images/factory.js +15 -10
  30. package/src/deployment/images/format.js +48 -0
  31. package/src/deployment/images/format.test.js +74 -0
  32. package/src/deployment/images/image.fixtures.js +11 -11
  33. package/src/deployment/images/image.js +20 -22
  34. package/src/deployment/images/image.test.js +6 -5
  35. package/src/deployment/images/index.js +1 -5
  36. package/src/deployment/images/mono.Dockerfile +18 -0
  37. package/src/deployment/images/mono.js +72 -0
  38. package/src/deployment/images/runtime-base.test.js +91 -0
  39. package/src/deployment/images/service.Dockerfile +3 -3
  40. package/src/deployment/images/service.js +8 -8
  41. package/src/deployment/index.js +1 -5
  42. package/src/deployment/operator.js +6 -6
  43. package/src/deployment/operator.test.js +8 -7
  44. package/src/deployment/registry.js +66 -22
  45. package/src/deployment/registry.test.js +177 -0
  46. package/src/deployment/service.js +1 -5
  47. package/src/deployment/workspace.js +13 -8
  48. package/src/index.js +1 -3
  49. package/src/process.js +2 -8
  50. package/src/process.test.js +20 -0
  51. package/types/_deployment/composition.d.ts +1 -1
  52. package/types/_deployment/dependency.d.ts +3 -1
  53. package/types/_deployment/deployment.d.ts +3 -3
  54. package/types/_deployment/factory.d.ts +2 -2
  55. package/types/_deployment/images/factory.d.ts +2 -2
  56. package/types/_deployment/images/image.d.ts +4 -2
  57. package/types/_deployment/images/registry.d.ts +2 -2
  58. package/types/_deployment/operator.d.ts +2 -2
  59. package/types/_deployment/registry.d.ts +10 -8
  60. package/types/_deployment/service.d.ts +4 -1
  61. package/types/dependency.ts +73 -0
  62. package/types/index.ts +1 -0
  63. package/types/dependency.d.ts +0 -39
  64. package/types/index.d.ts +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,204 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.280](https://github.com/toa-io/toa/compare/v1.0.0-alpha.279...v1.0.0-alpha.280) (2026-09-03)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **operations:** call execa, not the module it lives in ([9fe87d5](https://github.com/toa-io/toa/commit/9fe87d54cc02f7ec18e325c85882ff174acbe8ab))
11
+
12
+
13
+ # [1.0.0-alpha.278](https://github.com/toa-io/toa/compare/v1.0.0-alpha.277...v1.0.0-alpha.278) (2026-09-03)
14
+
15
+ **Note:** Version bump only for package @toa.io/operations
16
+
17
+
18
+
19
+
20
+
21
+ # [1.0.0-alpha.277](https://github.com/toa-io/toa/compare/v1.0.0-alpha.276...v1.0.0-alpha.277) (2026-09-03)
22
+
23
+ ### Bug Fixes
24
+
25
+ * read a manifest the way js-yaml read one before ([fcea1b2](https://github.com/toa-io/toa/commit/fcea1b21996d6efa6c3198acbfc9f70f1ce0c35c))
26
+ * settle what the module loader made asynchronous ([d4ab9df](https://github.com/toa-io/toa/commit/d4ab9dfb09e382da311dba08f52214e7645f4a6c))
27
+ * what the loader resolves, and what it will not ([1b8a02f](https://github.com/toa-io/toa/commit/1b8a02ff0a5e0f18ee62e3f71bc81116f86f9af1))
28
+
29
+
30
+ # [1.0.0-alpha.276](https://github.com/toa-io/toa/compare/v1.0.0-alpha.275...v1.0.0-alpha.276) (2026-09-03)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **operations:** let a deployment state that it has no probe ([477b483](https://github.com/toa-io/toa/commit/477b483560cf2464d486a78e432f8e9b47f011dd))
36
+
37
+
38
+
39
+
40
+
41
+ # [1.0.0-alpha.274](https://github.com/toa-io/toa/compare/v1.0.0-alpha.273...v1.0.0-alpha.274) (2026-09-02)
42
+
43
+ **Note:** Version bump only for package @toa.io/operations
44
+
45
+
46
+
47
+
48
+
49
+ # [1.0.0-alpha.273](https://github.com/toa-io/toa/compare/v1.0.0-alpha.272...v1.0.0-alpha.273) (2026-09-02)
50
+
51
+ **Note:** Version bump only for package @toa.io/operations
52
+
53
+
54
+
55
+
56
+
57
+ # [1.0.0-alpha.272](https://github.com/toa-io/toa/compare/v1.0.0-alpha.271...v1.0.0-alpha.272) (2026-09-01)
58
+
59
+
60
+ * feat(atomicity)!: take a quorum of independent servers ([862562f](https://github.com/toa-io/toa/commit/862562f24d77ec00127dbbd88d43802b208c643b))
61
+ * refactor(atomicity)!: take one Redis, not a cluster ([b0a4770](https://github.com/toa-io/toa/commit/b0a4770dff5dfe8fee4b9ae637a4dd297454fcd4))
62
+ * refactor(core)!: pump the outbox in one cycle ([bf590fe](https://github.com/toa-io/toa/commit/bf590fe8ed59c701b5fd1a91ba4874685b79242f))
63
+ * refactor(atomicity)!: rename the connector and free it of the outbox ([21f1a41](https://github.com/toa-io/toa/commit/21f1a41aceafcfd35c7620014062fe46b54afa95))
64
+ * feat(core)!: commit events with the state that produced them ([1eb68cc](https://github.com/toa-io/toa/commit/1eb68cc435dbfa03faa16009fceb866693d22e1a)), closes [#20](https://github.com/toa-io/toa/issues/20)
65
+
66
+
67
+ ### Features
68
+
69
+ * **atomicity:** make the interval a setting, and stop repeating n-and-i ([5c3a6d1](https://github.com/toa-io/toa/commit/5c3a6d1533751a21b7eb7d9c737f1a270bf5a5ae))
70
+
71
+
72
+ ### BREAKING CHANGES
73
+
74
+ * `atomicity.redis` accepts a list again, of independent servers rather
75
+ than cluster nodes, and refuses an even number of them.
76
+
77
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
78
+ * `atomicity.redis` is a string. A list is refused at export.
79
+
80
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
81
+ * `Storage.outbox.pending` takes a fourth argument, the id to
82
+ continue from.
83
+
84
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
85
+ * `@toa.io/partitions.redis` is now `@toa.io/atomicity`, and its
86
+ `lanes(total)` is `slots(total)`. Redis is declared as `atomicity` in the context
87
+ rather than `outbox.redis`, and read from `TOA_ATOMICITY_REDIS`.
88
+ `TOA_OUTBOX_PARTITION_INTERVAL` is `TOA_ATOMICITY_INTERVAL`.
89
+
90
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
91
+ * `event.changeset` is removed; use `origin` and `state`. `State`
92
+ takes an `Outbox` in place of an `Emission`. `difference` is dropped from
93
+ `@toa.io/generic` along with its last caller.
94
+
95
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
96
+
97
+
98
+
99
+
100
+
101
+ # [1.0.0-alpha.270](https://github.com/toa-io/toa/compare/v1.0.0-alpha.269...v1.0.0-alpha.270) (2026-08-31)
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * **operations:** let a composition set its own base image ([61ba331](https://github.com/toa-io/toa/commit/61ba3319dc91915a3197d348111af411bbd5bff1))
107
+
108
+
109
+
110
+
111
+
112
+ # [1.0.0-alpha.266](https://github.com/toa-io/toa/compare/v1.0.0-alpha.265...v1.0.0-alpha.266) (2026-08-29)
113
+
114
+ **Note:** Version bump only for package @toa.io/operations
115
+
116
+
117
+
118
+
119
+
120
+ # [1.0.0-alpha.265](https://github.com/toa-io/toa/compare/v1.0.0-alpha.264...v1.0.0-alpha.265) (2026-08-29)
121
+
122
+ **Note:** Version bump only for package @toa.io/operations
123
+
124
+
125
+
126
+
127
+
128
+ # [1.0.0-alpha.264](https://github.com/toa-io/toa/compare/v1.0.0-alpha.263...v1.0.0-alpha.264) (2026-08-29)
129
+
130
+ **Note:** Version bump only for package @toa.io/operations
131
+
132
+
133
+
134
+
135
+
136
+ # [1.0.0-alpha.263](https://github.com/toa-io/toa/compare/v1.0.0-alpha.262...v1.0.0-alpha.263) (2026-08-29)
137
+
138
+ **Note:** Version bump only for package @toa.io/operations
139
+
140
+
141
+
142
+
143
+
144
+ # [1.0.0-alpha.262](https://github.com/toa-io/toa/compare/v1.0.0-alpha.261...v1.0.0-alpha.262) (2026-08-28)
145
+
146
+
147
+ ### Bug Fixes
148
+
149
+ * **cli:** boot toa mono from components and env, not context ([1518f72](https://github.com/toa-io/toa/commit/1518f729d7611ae88e0538f286231d283a7098ef))
150
+
151
+
152
+ * feat(operations)!: require service ports to be unique ([b22cf87](https://github.com/toa-io/toa/commit/b22cf8770d24c555b5f355a5f117a9043a57799b))
153
+
154
+
155
+ ### Features
156
+
157
+ * **operations:** let a service claim a path prefix on the host ([02677d1](https://github.com/toa-io/toa/commit/02677d17fcd4222b07c3be458d93bcc496a016a8))
158
+
159
+
160
+ ### BREAKING CHANGES
161
+
162
+ * an application whose own extension runs a service on a port
163
+ already taken by another — 8000 by the exposition gateway, 8001 by the telemetry
164
+ readiness probe — must move it.
165
+
166
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
167
+
168
+
169
+
170
+
171
+
172
+ # [1.0.0-alpha.261](https://github.com/toa-io/toa/compare/v1.0.0-alpha.260...v1.0.0-alpha.261) (2026-08-26)
173
+
174
+
175
+ ### Bug Fixes
176
+
177
+ * **operations:** include extension pointer variables in --mono ([f8be23d](https://github.com/toa-io/toa/commit/f8be23d2aaf7bbe1b0580101c8bf4d32c3cab99f))
178
+
179
+
180
+
181
+
182
+
183
+ # [1.0.0-alpha.259](https://github.com/toa-io/toa/compare/v1.0.0-alpha.258...v1.0.0-alpha.259) (2026-08-24)
184
+
185
+ **Note:** Version bump only for package @toa.io/operations
186
+
187
+
188
+
189
+
190
+
191
+ # [1.0.0-alpha.257](https://github.com/toa-io/toa/compare/v1.0.0-alpha.256...v1.0.0-alpha.257) (2026-08-24)
192
+
193
+ **Note:** Version bump only for package @toa.io/operations
194
+
195
+
196
+
197
+
198
+
199
+ # [1.0.0-alpha.256](https://github.com/toa-io/toa/compare/v1.0.0-alpha.255...v1.0.0-alpha.256) (2026-08-23)
200
+
201
+
202
+ ### Features
203
+
204
+ * deploy a single mono image with toa deploy --mono ([a7f14f9](https://github.com/toa-io/toa/commit/a7f14f9877a280e9c74d16c195028b35d74fb15a))
@@ -0,0 +1,4 @@
1
+ FROM node:24.14.0-alpine3.22
2
+
3
+ ARG VERSION
4
+ RUN npm i -g @toa.io/runtime@${VERSION} --omit=dev
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@toa.io/operations",
3
- "version": "1.0.0-alpha.28",
3
+ "version": "1.0.0-alpha.280",
4
+ "type": "module",
4
5
  "description": "Toa Deployment",
5
6
  "homepage": "https://toa.io",
6
7
  "author": {
@@ -16,23 +17,22 @@
16
17
  "url": "https://github.com/toa-io/toa/issues"
17
18
  },
18
19
  "engines": {
19
- "node": ">= 18.0.0"
20
+ "node": ">= 24.0.0"
20
21
  },
21
22
  "publishConfig": {
22
23
  "access": "public"
23
24
  },
24
25
  "main": "src/index.js",
25
- "types": "types/index.d.ts",
26
+ "types": "types/index.ts",
26
27
  "scripts": {
27
28
  "test": "echo \"Error: run tests from root\" && exit 1"
28
29
  },
29
30
  "dependencies": {
30
- "@toa.io/filesystem": "1.0.0-alpha.28",
31
- "@toa.io/generic": "1.0.0-alpha.28",
32
- "@toa.io/norm": "1.0.0-alpha.28",
33
- "@toa.io/yaml": "1.0.0-alpha.28",
34
- "execa": "5.1.1",
35
- "fs-extra": "11.1.1"
31
+ "@toa.io/generic": "1.0.0-alpha.278",
32
+ "@toa.io/norm": "1.0.0-alpha.278",
33
+ "execa": "10.0.1",
34
+ "fs-extra": "11.4.0",
35
+ "js-yaml": "5.4.1"
36
36
  },
37
- "gitHead": "89c3b7d1314e357c9e33df8d95f8d46954cd3bcf"
37
+ "gitHead": "2cf23f576c46efbe56c21427d877cef3e7ed98d4"
38
38
  }
package/readme.md CHANGED
@@ -4,6 +4,22 @@
4
4
 
5
5
  ### Container Registry
6
6
 
7
+ Deploy images default to `FROM ghcr.io/toa-io/runtime:<runtime.version>`
8
+ (published with each Toa release). The base image already has `@toa.io/runtime`
9
+ installed; composition/service Dockerfiles only install component dependencies.
10
+
11
+ To use a custom base image, set `registry.build.image` (or `composition.image`).
12
+ That image must provide the `toa` CLI, or install it via `registry.build.run`:
13
+
14
+ ```yaml
15
+ # context.toa.yaml
16
+
17
+ registry:
18
+ build:
19
+ image: node:24.14.0-alpine3.22
20
+ run: npm i -g @toa.io/runtime --omit=dev
21
+ ```
22
+
7
23
  #### Build Options
8
24
 
9
25
  ```yaml
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
1
  /**
4
2
  * @param {toa.deployment.Composition[]} compositions
5
3
  * @returns {string[]}
6
4
  */
7
- const components = (compositions) => {
5
+ export const components = (compositions) => {
8
6
  /** @type {Set<string>} */
9
7
  const components = new Set()
10
8
 
@@ -16,5 +14,3 @@ const components = (compositions) => {
16
14
 
17
15
  return Array.from(components)
18
16
  }
19
-
20
- exports.components = components
@@ -1,11 +1,12 @@
1
- 'use strict'
1
+ import { addVariables } from './variables.js'
2
+ import { addMounts } from './mounts.js'
2
3
 
3
- const { addVariables } = require('./variables')
4
-
5
- function compositions (compositions, variables) {
4
+ export function compositions (compositions, dependency) {
6
5
  for (const composition of compositions) {
7
- addVariables(composition, variables)
6
+ addVariables(composition, dependency.variables)
7
+ addMounts(composition, dependency.mounts)
8
+
9
+ if (dependency.probe !== undefined && dependency.probe !== false)
10
+ composition.probe ??= dependency.probe
8
11
  }
9
12
  }
10
-
11
- exports.compositions = compositions
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
1
  /**
4
2
  * @param {toa.deployment.dependency.Reference[]} references
5
3
  * @returns {*}
6
4
  */
7
- const dependencies = (references) => {
5
+ export const dependencies = (references) => {
8
6
  return references?.reduce((map, reference) => {
9
7
  const { name, alias, values } = reference
10
8
 
@@ -13,6 +11,3 @@ const dependencies = (references) => {
13
11
  return map
14
12
  }, {})
15
13
  }
16
-
17
-
18
- exports.dependencies = dependencies
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Tells each component which of its events something consumes. An event nobody consumes gets
3
+ * no emitter, no exchange and no outbox row, and a component none of whose events are consumed
4
+ * gets no outbox at all.
5
+ *
6
+ * A component that declares events always gets the variable, empty when nothing is consumed —
7
+ * an absent variable means every event, which is what a run without a deployment gets.
8
+ *
9
+ * @param {toa.norm.Context} context
10
+ * @param {toa.deployment.Dependency} dependency
11
+ */
12
+ export function events (context, dependency) {
13
+ const components = deployed(context)
14
+ const consumed = collect(components, context.events, dependency.events)
15
+
16
+ for (const { locator, events } of components) {
17
+ if (events === undefined) continue
18
+
19
+ const labels = Object.keys(events)
20
+ .filter((label) => consumed.has(locator.id + '.' + label))
21
+
22
+ dependency.variables[locator.label] ??= []
23
+
24
+ dependency.variables[locator.label].push({
25
+ name: VARIABLE + locator.uppercase,
26
+ value: labels.join(' ')
27
+ })
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Every component this context deploys, its own and those its extensions bring. `components`
33
+ * holds only the former; the latter reach a deployment as instances of what they depend on,
34
+ * which is also how they are given the rest of their variables.
35
+ */
36
+ function deployed (context) {
37
+ const components = new Map()
38
+
39
+ for (const instances of Object.values(context.dependencies ?? {}))
40
+ for (const { component } of instances)
41
+ components.set(component.locator.id, component)
42
+
43
+ return [...components.values()]
44
+ }
45
+
46
+ /**
47
+ * Everything that consumes an event of this context: the receivers of its own components, what
48
+ * a dependency declares it consumes, and what the context says is consumed outside it.
49
+ */
50
+ function collect (components, declared, contributed) {
51
+ const consumed = new Set(declared ?? [])
52
+
53
+ for (const label of contributed ?? []) consumed.add(label)
54
+
55
+ for (const { receivers } of components)
56
+ for (const [label, receiver] of Object.entries(receivers ?? {}))
57
+ // a receiver with a source consumes from a foreign broker, not from this context
58
+ if (receiver.source === undefined) consumed.add(label)
59
+
60
+ return consumed
61
+ }
62
+
63
+ const VARIABLE = 'TOA_EVENTS_'
@@ -1,13 +1,4 @@
1
- 'use strict'
2
-
3
- const { dependencies } = require('./dependencies')
4
- const { components } = require('./components')
5
- const { compositions } = require('./compositions')
6
- const { variables } = require('./variables')
7
- const { services } = require('./services')
8
-
9
- exports.dependencies = dependencies
10
- exports.components = components
11
- exports.compositions = compositions
12
- exports.variables = variables
13
- exports.services = services
1
+ export { dependencies } from './dependencies.js'
2
+ export { components } from './components.js'
3
+ export { compositions } from './compositions.js'
4
+ export { services } from './services.js'
@@ -0,0 +1,20 @@
1
+ export function addMounts (composition, mounts, keys = composition.components) {
2
+ if (mounts === undefined)
3
+ return
4
+
5
+ const used = new Set()
6
+
7
+ for (const [key, mount] of Object.entries(mounts)) {
8
+ if (key !== 'global' && !keys?.includes(key))
9
+ continue
10
+
11
+ for (const { name, path, claim } of mount) {
12
+ if (used.has(name))
13
+ continue
14
+
15
+ composition.mounts ??= []
16
+ composition.mounts.push({ name, path, claim })
17
+ used.add(name)
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Every deployment states what it may take. One that states nothing is `BestEffort`: the
3
+ * first evicted under memory pressure and the last given CPU under contention — which on
4
+ * a busy node is slow enough for its own startup probe to kill it, in a loop, while the
5
+ * chart reports nothing wrong. That is not a thing to find out in production.
6
+ *
7
+ * A deployment takes its own declaration, or the context's `resources` where it has none.
8
+ * Deploying without any is a decision rather than an omission, and it is spelled
9
+ * `resources: null` — at either place.
10
+ */
11
+ export function resources (context, values) {
12
+ for (const unit of units(values)) {
13
+ // `null` is an answer and `undefined` is not one, so the fallback reads only the latter
14
+ if (unit.deployment.resources === undefined)
15
+ unit.deployment.resources = context.resources
16
+
17
+ if (unit.deployment.resources === undefined)
18
+ throw new Error(`${unit.subject} declares no resources. ` +
19
+ 'Declare them on it or as the context\'s \'resources\', ' +
20
+ 'or \'resources: null\' to deploy it without any.')
21
+ }
22
+ }
23
+
24
+ function * units (values) {
25
+ if (values.mono !== undefined)
26
+ yield { deployment: values.mono, subject: 'The mono deployment' }
27
+
28
+ for (const composition of values.compositions ?? [])
29
+ yield { deployment: composition, subject: `Composition '${composition.name}'` }
30
+
31
+ for (const service of values.services ?? [])
32
+ yield { deployment: service, subject: `Service '${service.name}'` }
33
+ }
@@ -1,11 +1,34 @@
1
- 'use strict'
1
+ import { addVariables } from './variables.js'
2
2
 
3
- const { addVariables } = require('./variables')
4
-
5
- function services (services, variables) {
3
+ export function services (services, variables, probe, ingress) {
6
4
  for (const service of services) {
7
5
  addVariables(service, variables)
6
+
7
+ if (service.probe === false)
8
+ delete service.probe
9
+ else if (service.probe === undefined && probe !== undefined && probe !== false)
10
+ service.probe = probe
11
+
12
+ if (service.ingress !== undefined)
13
+ expose(service, ingress)
8
14
  }
9
15
  }
10
16
 
11
- exports.services = services
17
+ /**
18
+ * A service declares only its own intent — a path, a port. Where that lands is
19
+ * the context's business, so everything else comes from its `ingress` section.
20
+ * What the service did declare wins.
21
+ */
22
+ function expose (service, ingress = {}) {
23
+ const declared = Object.fromEntries(
24
+ Object.entries(service.ingress).filter(([, value]) => value !== undefined))
25
+
26
+ service.ingress = Object.assign({}, ingress, declared)
27
+
28
+ if (service.ingress.hosts === undefined)
29
+ throw new Error(`Service '${service.name}' declares an ingress, but no hosts are defined. ` +
30
+ "Declare them in the context's 'ingress' section.")
31
+
32
+ if (service.port === undefined)
33
+ throw new Error(`Service '${service.name}' declares an ingress, but no port.`)
34
+ }
@@ -0,0 +1,61 @@
1
+ import { it } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import { services } from './services.js'
5
+
6
+ const service = (extra = {}) => ({ group: 'group', name: 'group-one', version: '0', ...extra })
7
+
8
+ it('should leave a service without an ingress alone', () => {
9
+ const list = [service()]
10
+
11
+ services(list, {}, undefined, { hosts: ['api.dev'] })
12
+
13
+ assert.strictEqual(list[0].ingress, undefined)
14
+ })
15
+
16
+ /*
17
+ * A service declares only where it wants to land; the cluster-level plumbing
18
+ * belongs to the context.
19
+ */
20
+ it('should supply hosts, class and annotations from the context', () => {
21
+ const list = [service({ port: 8002, ingress: { path: '/.introspection' } })]
22
+
23
+ services(list, {}, undefined, { hosts: ['api.dev'], class: 'alb', annotations: { a: 'b' } })
24
+
25
+ assert.deepStrictEqual(list[0].ingress, {
26
+ path: '/.introspection',
27
+ hosts: ['api.dev'],
28
+ class: 'alb',
29
+ annotations: { a: 'b' }
30
+ })
31
+ })
32
+
33
+ it('should keep what the service declared itself', () => {
34
+ const list = [service({ port: 8000, ingress: { path: '/', hosts: ['own.dev'] } })]
35
+
36
+ services(list, {}, undefined, { hosts: ['api.dev'], class: 'alb' })
37
+
38
+ assert.deepStrictEqual(list[0].ingress.hosts, ['own.dev'])
39
+ assert.deepStrictEqual(list[0].ingress.class, 'alb')
40
+ })
41
+
42
+ it('should ignore properties the service left undefined', () => {
43
+ const list = [service({ port: 8000, ingress: { path: '/', class: undefined } })]
44
+
45
+ services(list, {}, undefined, { hosts: ['api.dev'], class: 'alb' })
46
+
47
+ assert.deepStrictEqual(list[0].ingress.class, 'alb')
48
+ })
49
+
50
+ it('should reject an ingress with nowhere to land', () => {
51
+ const list = [service({ port: 8002, ingress: { path: '/.introspection' } })]
52
+
53
+ assert.throws(() => services(list, {}, undefined, undefined), (error) => /Service 'group-one' declares an ingress, but no hosts are defined/.test(error.message))
54
+ })
55
+
56
+ it('should reject an ingress without a port', () => {
57
+ const list = [service({ ingress: { path: '/.introspection' } })]
58
+
59
+ assert.throws(() => services(list, {}, undefined, { hosts: ['api.dev'] }), (error) => /Service 'group-one' declares an ingress, but no port/.test(error.message))
60
+ })
61
+
@@ -1,20 +1,17 @@
1
- 'use strict'
1
+ export function addVariables (composition, variables, keys = composition.components) {
2
+ composition.variables ??= []
2
3
 
3
- function addVariables (deployment, variables) {
4
- const used = new Set()
5
-
6
- deployment.variables ??= []
4
+ const used = new Set(composition.variables.map((variable) => variable.name))
7
5
 
8
6
  for (const [key, set] of Object.entries(variables)) {
9
- if (key !== 'global' && !deployment.components?.includes(key)) continue
7
+ if (key !== 'global' && !keys?.includes(key))
8
+ continue
10
9
 
11
10
  for (const variable of set) {
12
11
  if (used.has(variable.name)) continue
13
12
 
14
- deployment.variables.push(variable)
13
+ composition.variables.push(variable)
15
14
  used.add(variable.name)
16
15
  }
17
16
  }
18
17
  }
19
-
20
- exports.addVariables = addVariables
@@ -1,11 +1,9 @@
1
- 'use strict'
2
-
3
1
  /**
4
2
  * @param {toa.norm.Context} context
5
3
  * @param {toa.deployment.Dependency} dependency
6
4
  * @returns {toa.deployment.Declaration}
7
5
  */
8
- const declare = (context, dependency) => {
6
+ export const declare = (context, dependency) => {
9
7
  const { references } = dependency
10
8
  const { name, description, version } = context
11
9
 
@@ -25,5 +23,3 @@ const DECLARATION = {
25
23
  apiVersion: 'v2',
26
24
  type: 'application'
27
25
  }
28
-
29
- exports.declare = declare