@toa.io/extensions.configuration 1.0.0-alpha.28 → 1.0.0-alpha.282

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 (152) hide show
  1. package/CHANGELOG.md +347 -0
  2. package/components/configuration.values/manifest.toa.yaml +158 -0
  3. package/components/configuration.values/operations/create.d.ts +16 -0
  4. package/components/configuration.values/operations/create.js +31 -0
  5. package/components/configuration.values/operations/create.js.map +1 -0
  6. package/components/configuration.values/operations/fetch.d.ts +11 -0
  7. package/components/configuration.values/operations/fetch.js +13 -0
  8. package/components/configuration.values/operations/fetch.js.map +1 -0
  9. package/components/configuration.values/operations/get.d.ts +17 -0
  10. package/components/configuration.values/operations/get.js +19 -0
  11. package/components/configuration.values/operations/get.js.map +1 -0
  12. package/components/configuration.values/operations/lib/map.d.ts +11 -0
  13. package/components/configuration.values/operations/lib/map.js +21 -0
  14. package/components/configuration.values/operations/lib/map.js.map +1 -0
  15. package/components/configuration.values/operations/lib/map.test.d.ts +1 -0
  16. package/components/configuration.values/operations/lib/map.test.js +26 -0
  17. package/components/configuration.values/operations/lib/map.test.js.map +1 -0
  18. package/components/configuration.values/operations/lib/resolve.d.ts +27 -0
  19. package/components/configuration.values/operations/lib/resolve.js +24 -0
  20. package/components/configuration.values/operations/lib/resolve.js.map +1 -0
  21. package/components/configuration.values/operations/list.d.ts +10 -0
  22. package/components/configuration.values/operations/list.js +11 -0
  23. package/components/configuration.values/operations/list.js.map +1 -0
  24. package/components/configuration.values/source/create.ts +56 -0
  25. package/components/configuration.values/source/fetch.ts +24 -0
  26. package/components/configuration.values/source/get.ts +33 -0
  27. package/components/configuration.values/source/lib/map.test.ts +37 -0
  28. package/components/configuration.values/source/lib/map.ts +34 -0
  29. package/components/configuration.values/source/lib/resolve.ts +54 -0
  30. package/components/configuration.values/source/list.ts +19 -0
  31. package/components/configuration.values/tsconfig.json +10 -0
  32. package/components/configuration.values/tsconfig.tsbuildinfo +1 -0
  33. package/cucumber.mjs +5 -0
  34. package/features/site/_app/immutable/asset.js +1 -0
  35. package/features/site/favicon.ico +0 -0
  36. package/features/site/index.html +6 -0
  37. package/features/steps/UI.ts +91 -0
  38. package/features/steps/tsconfig.json +9 -0
  39. package/features/ui.feature +93 -0
  40. package/package.json +11 -10
  41. package/readme.md +160 -47
  42. package/schemas/annotation.cos.yaml +29 -1
  43. package/schemas/manifest.cos.yaml +9 -2
  44. package/source/Aspect.test.ts +89 -9
  45. package/source/Aspect.ts +64 -5
  46. package/source/Client.test.ts +108 -0
  47. package/source/Client.ts +258 -0
  48. package/source/Composition.ts +57 -0
  49. package/source/Factory.ts +28 -6
  50. package/source/Secret.test.ts +32 -0
  51. package/source/Secret.ts +29 -0
  52. package/source/UI.ts +212 -0
  53. package/source/configuration.test.ts +96 -40
  54. package/source/configuration.ts +30 -11
  55. package/source/const.ts +17 -0
  56. package/source/deployment.test.ts +78 -12
  57. package/source/deployment.ts +75 -27
  58. package/source/epoch.test.ts +29 -0
  59. package/source/epoch.ts +21 -0
  60. package/source/index.ts +4 -3
  61. package/source/manifest.test.ts +8 -5
  62. package/source/manifest.ts +2 -4
  63. package/source/schemas.ts +1 -1
  64. package/transpiled/Aspect.d.ts +18 -4
  65. package/transpiled/Aspect.js +50 -9
  66. package/transpiled/Aspect.js.map +1 -1
  67. package/transpiled/Aspect.test.js +63 -12
  68. package/transpiled/Aspect.test.js.map +1 -1
  69. package/transpiled/Client.d.ts +61 -0
  70. package/transpiled/Client.js +169 -0
  71. package/transpiled/Client.js.map +1 -0
  72. package/transpiled/Client.test.d.ts +1 -0
  73. package/transpiled/Client.test.js +78 -0
  74. package/transpiled/Client.test.js.map +1 -0
  75. package/transpiled/Composition.d.ts +14 -0
  76. package/transpiled/Composition.js +38 -0
  77. package/transpiled/Composition.js.map +1 -0
  78. package/transpiled/Factory.d.ts +8 -2
  79. package/transpiled/Factory.js +20 -9
  80. package/transpiled/Factory.js.map +1 -1
  81. package/transpiled/Secret.d.ts +12 -0
  82. package/transpiled/Secret.js +22 -0
  83. package/transpiled/Secret.js.map +1 -0
  84. package/transpiled/Secret.test.d.ts +1 -0
  85. package/transpiled/Secret.test.js +26 -0
  86. package/transpiled/Secret.test.js.map +1 -0
  87. package/transpiled/UI.d.ts +25 -0
  88. package/transpiled/UI.js +172 -0
  89. package/transpiled/UI.js.map +1 -0
  90. package/transpiled/configuration.d.ts +7 -2
  91. package/transpiled/configuration.js +30 -41
  92. package/transpiled/configuration.js.map +1 -1
  93. package/transpiled/configuration.test.js +90 -43
  94. package/transpiled/configuration.test.js.map +1 -1
  95. package/transpiled/const.d.ts +11 -0
  96. package/transpiled/const.js +11 -0
  97. package/transpiled/const.js.map +1 -0
  98. package/transpiled/deployment.d.ts +9 -3
  99. package/transpiled/deployment.js +62 -57
  100. package/transpiled/deployment.js.map +1 -1
  101. package/transpiled/deployment.test.js +61 -13
  102. package/transpiled/deployment.test.js.map +1 -1
  103. package/transpiled/epoch.d.ts +2 -0
  104. package/transpiled/epoch.js +17 -0
  105. package/transpiled/epoch.js.map +1 -0
  106. package/transpiled/epoch.test.d.ts +1 -0
  107. package/transpiled/epoch.test.js +22 -0
  108. package/transpiled/epoch.test.js.map +1 -0
  109. package/transpiled/index.d.ts +4 -3
  110. package/transpiled/index.js +4 -9
  111. package/transpiled/index.js.map +1 -1
  112. package/transpiled/manifest.d.ts +1 -1
  113. package/transpiled/manifest.js +2 -31
  114. package/transpiled/manifest.js.map +1 -1
  115. package/transpiled/manifest.test.js +9 -9
  116. package/transpiled/manifest.test.js.map +1 -1
  117. package/transpiled/schemas.js +5 -31
  118. package/transpiled/schemas.js.map +1 -1
  119. package/tsconfig.json +2 -1
  120. package/tsconfig.tsbuildinfo +1 -0
  121. package/ui/dist/_app/env.js +1 -0
  122. package/ui/dist/_app/immutable/assets/0.CNS8Cqhc.css +2 -0
  123. package/ui/dist/_app/immutable/assets/inter-cyrillic-ext-wght-normal.BOeWTOD4.woff2 +0 -0
  124. package/ui/dist/_app/immutable/assets/inter-cyrillic-wght-normal.DqGufNeO.woff2 +0 -0
  125. package/ui/dist/_app/immutable/assets/inter-greek-ext-wght-normal.DlzME5K_.woff2 +0 -0
  126. package/ui/dist/_app/immutable/assets/inter-greek-wght-normal.CkhJZR-_.woff2 +0 -0
  127. package/ui/dist/_app/immutable/assets/inter-latin-ext-wght-normal.DO1Apj_S.woff2 +0 -0
  128. package/ui/dist/_app/immutable/assets/inter-latin-wght-normal.Dx4kXJAl.woff2 +0 -0
  129. package/ui/dist/_app/immutable/assets/inter-vietnamese-wght-normal.CBcvBZtf.woff2 +0 -0
  130. package/ui/dist/_app/immutable/assets/ui.BghF56l_.css +1 -0
  131. package/ui/dist/_app/immutable/chunks/BI4iTnyC.js +1 -0
  132. package/ui/dist/_app/immutable/chunks/Bjy-W4x2.js +81 -0
  133. package/ui/dist/_app/immutable/chunks/CcD_ISxM.js +3 -0
  134. package/ui/dist/_app/immutable/chunks/CcWYApmX.js +6 -0
  135. package/ui/dist/_app/immutable/chunks/DNNahQnI.js +8 -0
  136. package/ui/dist/_app/immutable/chunks/XPGIBZyO.js +1 -0
  137. package/ui/dist/_app/immutable/chunks/_OCUOSf_.js +50 -0
  138. package/ui/dist/_app/immutable/chunks/xihTtKlq.js +1 -0
  139. package/ui/dist/_app/immutable/entry/app.Dm0NVzuV.js +2 -0
  140. package/ui/dist/_app/immutable/entry/start.DWjxVbPv.js +1 -0
  141. package/ui/dist/_app/immutable/nodes/0.C1zAG1m5.js +1 -0
  142. package/ui/dist/_app/immutable/nodes/1.QblBNjka.js +1 -0
  143. package/ui/dist/_app/immutable/nodes/2.CyVYZW9A.js +1 -0
  144. package/ui/dist/_app/immutable/nodes/3.DJ58VY-o.js +1 -0
  145. package/ui/dist/_app/immutable/nodes/4.CZA2PMJQ.js +1 -0
  146. package/ui/dist/_app/version.json +1 -0
  147. package/ui/dist/apple-touch-icon.png +0 -0
  148. package/ui/dist/favicon-96x96.png +0 -0
  149. package/ui/dist/favicon.ico +0 -0
  150. package/ui/dist/index.html +52 -0
  151. package/ui/dist/robots.txt +3 -0
  152. package/transpiled/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,169 @@
1
+ import { console } from 'openspan';
2
+ import { Connector, Locator } from '@toa.io/core';
3
+ import { EVENT, SOURCE } from './const.js';
4
+ /**
5
+ * One per process: one remote to the values service and one subscription to its events,
6
+ * shared by every Aspect. What the Aspects ask for is collected and sent as one call;
7
+ * what the service creates afterwards is handed to whoever subscribed.
8
+ */
9
+ export class Client extends Connector {
10
+ /** Disconnected once, a connector keeps what it depended on, so a gone client is not reused. */
11
+ disposed = false;
12
+ host;
13
+ options;
14
+ pending = new Map();
15
+ listeners = new Map();
16
+ remote = null;
17
+ timer = null;
18
+ flushing = false;
19
+ fresh = false;
20
+ round = 0;
21
+ constructor(host, options = {}) {
22
+ super();
23
+ this.host = host;
24
+ this.options = { ...DEFAULTS, ...options };
25
+ }
26
+ /** The configuration of a component for an epoch, once the service has one. */
27
+ async fetch(component, epoch) {
28
+ const key = id(component, epoch);
29
+ let entry = this.pending.get(key);
30
+ if (entry === undefined) {
31
+ entry = { component, epoch, waiters: [] };
32
+ this.pending.set(key, entry);
33
+ }
34
+ const promise = new Promise((resolve) => {
35
+ entry.waiters.push(resolve);
36
+ });
37
+ if (this.flushing)
38
+ this.fresh = true;
39
+ else
40
+ this.schedule(0);
41
+ return await promise;
42
+ }
43
+ subscribe(component, epoch, listener) {
44
+ const key = id(component, epoch);
45
+ if (!this.listeners.has(key))
46
+ this.listeners.set(key, new Set());
47
+ this.listeners.get(key).add(listener);
48
+ }
49
+ unsubscribe(component, epoch, listener) {
50
+ this.listeners.get(id(component, epoch))?.delete(listener);
51
+ }
52
+ async open() {
53
+ this.remote = await this.host.remote(LOCATOR, SOURCE);
54
+ this.depends(this.remote);
55
+ await this.remote.connect();
56
+ const subscription = new Subscription(this.deliver.bind(this));
57
+ const consumer = await this.host.receive(EVENT, subscription);
58
+ this.depends(consumer);
59
+ await consumer.connect();
60
+ }
61
+ async close() {
62
+ if (this.timer !== null) {
63
+ clearTimeout(this.timer);
64
+ this.timer = null;
65
+ }
66
+ }
67
+ async dispose() {
68
+ this.disposed = true;
69
+ }
70
+ schedule(delay) {
71
+ if (this.flushing)
72
+ return;
73
+ if (this.timer !== null) {
74
+ // a request that has just arrived does not wait for the round already planned
75
+ if (delay > 0)
76
+ return;
77
+ clearTimeout(this.timer);
78
+ }
79
+ this.timer = setTimeout(() => {
80
+ void this.flush();
81
+ }, delay);
82
+ }
83
+ async flush() {
84
+ this.timer = null;
85
+ this.flushing = true;
86
+ this.fresh = false;
87
+ const batch = [...this.pending.values()];
88
+ const input = batch.map(({ component, epoch }) => ({ component, epoch }));
89
+ try {
90
+ const output = await this.remote.invoke('fetch', { input });
91
+ if (output instanceof Error)
92
+ throw output;
93
+ this.settle(output);
94
+ }
95
+ catch (error) {
96
+ console.warn('Configuration fetch failed', { error });
97
+ }
98
+ finally {
99
+ this.flushing = false;
100
+ }
101
+ this.report(batch);
102
+ if (this.pending.size === 0)
103
+ return;
104
+ if (this.fresh)
105
+ this.schedule(0);
106
+ else
107
+ this.schedule(this.backoff());
108
+ }
109
+ /** Those the service has served are told; the rest stay for the next round. */
110
+ settle(output) {
111
+ for (const { component, epoch, configuration, created } of output) {
112
+ if (configuration === null)
113
+ continue;
114
+ const key = id(component, epoch);
115
+ const entry = this.pending.get(key);
116
+ if (entry === undefined)
117
+ continue;
118
+ this.pending.delete(key);
119
+ for (const resolve of entry.waiters)
120
+ resolve({ configuration, created });
121
+ }
122
+ }
123
+ report(batch) {
124
+ const waiting = batch
125
+ .filter(({ component, epoch }) => this.pending.has(id(component, epoch)))
126
+ .map(({ component }) => component);
127
+ if (waiting.length === 0) {
128
+ this.round = 0;
129
+ return;
130
+ }
131
+ this.round++;
132
+ if (this.round % this.options.warn === 1)
133
+ console.warn('Waiting for configuration', { components: waiting, round: this.round });
134
+ }
135
+ backoff() {
136
+ return Math.min(this.options.base * Math.pow(FACTOR, this.round), this.options.max);
137
+ }
138
+ /** A created object goes to the subscribers of its component and epoch, as it is. */
139
+ deliver(created) {
140
+ const listeners = this.listeners.get(id(created.component, created.epoch));
141
+ if (listeners === undefined)
142
+ return;
143
+ const value = { configuration: created.configuration, created: created._created };
144
+ for (const listener of listeners)
145
+ listener(value);
146
+ }
147
+ }
148
+ /** What the event consumer hands deliveries to. */
149
+ class Subscription extends Connector {
150
+ handler;
151
+ constructor(handler) {
152
+ super();
153
+ this.handler = handler;
154
+ }
155
+ async receive(message) {
156
+ this.handler(message.payload);
157
+ }
158
+ }
159
+ function id(component, epoch) {
160
+ return component + '\0' + epoch;
161
+ }
162
+ const LOCATOR = new Locator('values', 'configuration');
163
+ const FACTOR = 1.5;
164
+ const DEFAULTS = {
165
+ base: 1000,
166
+ max: 10000,
167
+ warn: 5
168
+ };
169
+ //# sourceMappingURL=Client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Client.js","sourceRoot":"","sources":["../source/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAI1C;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IACnC,gGAAgG;IACzF,QAAQ,GAAG,KAAK,CAAA;IAEN,IAAI,CAAM;IACV,OAAO,CAAS;IAChB,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAA;IACpC,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;IACrD,MAAM,GAAkB,IAAI,CAAA;IAC5B,KAAK,GAA0B,IAAI,CAAA;IACnC,QAAQ,GAAG,KAAK,CAAA;IAChB,KAAK,GAAG,KAAK,CAAA;IACb,KAAK,GAAG,CAAC,CAAA;IAEjB,YAAoB,IAAU,EAAE,OAAO,GAAqB,EAAE;QAC5D,KAAK,EAAE,C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,CAAC;CACR,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ import { it, beforeEach, afterEach, mock } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { isDeepStrictEqual } from 'node:util';
4
+ import { Connector } from '@toa.io/core';
5
+ import { timeout } from '@toa.io/generic';
6
+ import { Client } from './Client.js';
7
+ import { EVENT } from './const.js';
8
+ class Remote extends Connector {
9
+ invoke = mock.fn(async (_endpoint, request) => request.input.map((pair) => ({
10
+ ...pair,
11
+ configuration: this.values[pair.component] ?? null,
12
+ created: this.values[pair.component] === undefined ? 0 : 7
13
+ })));
14
+ values = {};
15
+ }
16
+ let remote;
17
+ let receiver;
18
+ let host;
19
+ let client;
20
+ beforeEach(() => {
21
+ remote = new Remote();
22
+ receiver = null;
23
+ host = {
24
+ remote: mock.fn(async (locator) => {
25
+ assert.deepStrictEqual(locator.id, 'configuration.values');
26
+ return remote;
27
+ }),
28
+ receive: mock.fn(async (label, consumer) => {
29
+ assert.deepStrictEqual(label, EVENT);
30
+ receiver = consumer;
31
+ return new Connector();
32
+ })
33
+ };
34
+ client = new Client(host, { base: 10, max: 20, warn: 2 });
35
+ });
36
+ afterEach(async () => {
37
+ await client.disconnect();
38
+ });
39
+ it('should send the requests of one tick as one call', async () => {
40
+ remote.values = { 'a.one': { foo: 1 }, 'a.two': { foo: 2 } };
41
+ await client.connect();
42
+ const [one, two] = await Promise.all([client.fetch('a.one', 'e1'), client.fetch('a.two', 'e2')]);
43
+ assert.deepStrictEqual(one, { configuration: { foo: 1 }, created: 7 });
44
+ assert.deepStrictEqual(two, { configuration: { foo: 2 }, created: 7 });
45
+ assert.strictEqual(remote.invoke.mock.callCount(), 1);
46
+ assert.deepStrictEqual(remote.invoke.mock.calls[0].arguments[1], {
47
+ input: [{ component: 'a.one', epoch: 'e1' }, { component: 'a.two', epoch: 'e2' }]
48
+ });
49
+ });
50
+ it('should keep asking until served', async () => {
51
+ await client.connect();
52
+ const fetching = client.fetch('a.one', 'e1');
53
+ const deadline = Date.now() + 1000;
54
+ while (remote.invoke.mock.calls.length < 2 && Date.now() < deadline)
55
+ await timeout(5);
56
+ assert.ok(remote.invoke.mock.calls.length >= 2);
57
+ remote.values = { 'a.one': { foo: 1 } };
58
+ assert.deepStrictEqual((await fetching).configuration, { foo: 1 });
59
+ });
60
+ it('should hand a created object to its subscribers', async () => {
61
+ await client.connect();
62
+ const listener = mock.fn();
63
+ const other = mock.fn();
64
+ client.subscribe('a.one', 'e1', listener);
65
+ client.subscribe('a.one', 'e0', other);
66
+ await receiver.receive({
67
+ payload: { component: 'a.one', epoch: 'e1', configuration: { foo: 2 }, _created: 12 }
68
+ });
69
+ assert.ok(listener.mock.calls.some((call) => call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], { configuration: { foo: 2 }, created: 12 })));
70
+ assert.strictEqual(other.mock.callCount(), 0);
71
+ assert.strictEqual(remote.invoke.mock.callCount(), 0);
72
+ client.unsubscribe('a.one', 'e1', listener);
73
+ await receiver.receive({
74
+ payload: { component: 'a.one', epoch: 'e1', configuration: { foo: 3 }, _created: 13 }
75
+ });
76
+ assert.strictEqual(listener.mock.callCount(), 1);
77
+ });
78
+ //# sourceMappingURL=Client.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Client.test.js","sourceRoot":"","sources":["../source/Client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EAAE,SAAS,EAA6C,MAAM,cAAc,CAAA;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAgB,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGl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,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;KACpE,CAAC,CAAA;IAEpB,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IACnK,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAA;IAC7C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAA;IAErD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAE3C,MAAM,QAAS,CAAC,OAAO,CAAC;QACtB,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;KACpE,CAAC,CAAA;IAEpB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { Connector } from '@toa.io/core';
2
+ import type { Host } from './Factory.js';
3
+ /** Hosts the values component in the service process. */
4
+ export declare class Composition extends Connector {
5
+ private readonly host;
6
+ constructor(host: Host);
7
+ protected open(): Promise<void>;
8
+ }
9
+ export declare function components(): Components;
10
+ interface Components {
11
+ labels: string[];
12
+ paths: string[];
13
+ }
14
+ export {};
@@ -0,0 +1,38 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { Connector } from '@toa.io/core';
4
+ import { UI_PORT } from './const.js';
5
+ import { UI } from './UI.js';
6
+ /** Hosts the values component in the service process. */
7
+ export class Composition extends Connector {
8
+ host;
9
+ constructor(host) {
10
+ super();
11
+ this.host = host;
12
+ }
13
+ async open() {
14
+ const composition = await this.host.composition(components().paths);
15
+ await composition.connect();
16
+ this.depends(composition);
17
+ // connected here rather than declared as a dependency: dependencies are connected
18
+ // before `open` runs, so one added from inside it would never be
19
+ const ui = new UI(UI_PORT);
20
+ await ui.connect();
21
+ this.depends(ui);
22
+ }
23
+ }
24
+ export function components() {
25
+ const labels = [];
26
+ const paths = [];
27
+ for (const entry of entries()) {
28
+ labels.push(entry.name.replace('.', '-'));
29
+ paths.push(resolve(ROOT, entry.name));
30
+ }
31
+ return { labels, paths };
32
+ }
33
+ function entries() {
34
+ const entries = readdirSync(ROOT, { withFileTypes: true });
35
+ return entries.filter((entry) => entry.isDirectory());
36
+ }
37
+ const ROOT = resolve(import.meta.dirname, '../components/');
38
+ //# sourceMappingURL=Composition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Composition.js","sourceRoot":"","sources":["../source/Composition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAG5B,yDAAyD;AACzD,MAAM,OAAO,WAAY,SAAQ,SAAS;IACvB,IAAI,CAAM;IAE3B,YAAoB,IAAU;QAC5B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,IAAI,GA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type Manifest } from './manifest';
1
+ import { type Connector, type Locator, type extensions } from '@toa.io/core';
2
+ import type { Manifest } from './manifest.js';
3
3
  export declare class Factory implements extensions.Factory {
4
+ private readonly host;
5
+ private client;
6
+ constructor(host: Host);
4
7
  aspect(locator: Locator, manifest: Manifest): extensions.Aspect;
8
+ service(): Connector;
9
+ private shared;
5
10
  }
11
+ export type Host = extensions.Host;
@@ -1,13 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Factory = void 0;
4
- const Aspect_1 = require("./Aspect");
5
- const configuration_1 = require("./configuration");
6
- class Factory {
1
+ import { Aspect } from './Aspect.js';
2
+ import { Client } from './Client.js';
3
+ import { Composition } from './Composition.js';
4
+ import { overridden } from './configuration.js';
5
+ export class Factory {
6
+ host;
7
+ client = null;
8
+ constructor(host) {
9
+ this.host = host;
10
+ }
7
11
  aspect(locator, manifest) {
8
- const value = (0, configuration_1.get)(locator, manifest);
9
- return new Aspect_1.Aspect(value);
12
+ const client = overridden(locator) ? null : this.shared();
13
+ return new Aspect(locator, manifest, client);
14
+ }
15
+ service() {
16
+ return new Composition(this.host);
17
+ }
18
+ shared() {
19
+ if (this.client === null || this.client.disposed)
20
+ this.client = new Client(this.host);
21
+ return this.client;
10
22
  }
11
23
  }
12
- exports.Factory = Factory;
13
24
  //# sourceMappingURL=Factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;AACA,qCAAiC;AAEjC,mDAAqC;AAErC,MAAa,OAAO;IACX,MAAM,CAAE,OAAgB,EAAE,QAAkB;QACjD,MAAM,KAAK,GAAG,IAAA,mBAAG,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAEpC,OAAO,IAAI,eAAM,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;CACF;AAND,0BAMC"}
1
+ {"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAG/C,MAAM,OAAO,OAAO;IACD,IAAI,CAAM;IACnB,MAAM,GAAkB,IAAI,CAAA;IAEpC,YAAoB,IAAU;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,MAAM,CAAE,OAAgB,EAAE,QAAkB;QACjD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;QAEzD,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC9C,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAEO,MAAM;QACZ,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAErC,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { inspect } from 'node:util';
2
+ import type { Secret as Contract } from '@toa.io/types';
3
+ /** A configuration value that must not leak: a string only to whoever asks for it. */
4
+ export declare class Secret implements Contract {
5
+ #private;
6
+ constructor(value: string);
7
+ unwrap(): string;
8
+ toString(): string;
9
+ toJSON(): string;
10
+ [inspect.custom](): string;
11
+ }
12
+ export declare const REDACTED = "<REDACTED>";
@@ -0,0 +1,22 @@
1
+ import { inspect } from 'node:util';
2
+ /** A configuration value that must not leak: a string only to whoever asks for it. */
3
+ export class Secret {
4
+ #value;
5
+ constructor(value) {
6
+ this.#value = value;
7
+ }
8
+ unwrap() {
9
+ return this.#value;
10
+ }
11
+ toString() {
12
+ return REDACTED;
13
+ }
14
+ toJSON() {
15
+ return REDACTED;
16
+ }
17
+ [inspect.custom]() {
18
+ return REDACTED;
19
+ }
20
+ }
21
+ export const REDACTED = '<REDACTED>';
22
+ //# sourceMappingURL=Secret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secret.js","sourceRoot":"","sources":["../source/Secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,sFAAsF;AACtF,MAAM,OAAO,MAAM;IACR,MAAM,CAAQ;IAEvB,YAAoB,KAAa;QAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAEM,QAAQ;QACb,OAAO,QAAQ,CAAA;IACjB,CAAC;IAEM,MAAM;QACX,OAAO,QAAQ,CAAA;IACjB,CAAC;IAEM,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { inspect } from 'node:util';
4
+ import { REDACTED, Secret } from './Secret.js';
5
+ const secret = new Secret('s3cret');
6
+ it('should unwrap', () => {
7
+ assert.deepStrictEqual(secret.unwrap(), 's3cret');
8
+ });
9
+ it('should not show as a string', () => {
10
+ assert.deepStrictEqual(String(secret), REDACTED);
11
+ assert.deepStrictEqual(`${secret}`, REDACTED);
12
+ assert.deepStrictEqual('' + secret, REDACTED);
13
+ });
14
+ it('should not show in JSON', () => {
15
+ assert.deepStrictEqual(JSON.stringify({ key: secret }), '{"key":"<REDACTED>"}');
16
+ });
17
+ it('should not show when inspected', () => {
18
+ assert.deepStrictEqual(inspect(secret), REDACTED);
19
+ assert.ok(inspect({ key: secret }).includes(REDACTED));
20
+ assert.ok(!(inspect({ key: secret }).includes('s3cret')));
21
+ });
22
+ it('should not expose the value as a property', () => {
23
+ assert.deepStrictEqual(Object.keys(secret), []);
24
+ assert.deepStrictEqual({ ...secret }, {});
25
+ });
26
+ //# sourceMappingURL=Secret.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secret.test.js","sourceRoot":"","sources":["../source/Secret.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAC9B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAA;AAEnC,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;IACvB,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAA;AACnD,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACrC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAA;IAChD,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAA;IAC7C,MAAM,CAAC,eAAe,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,CAAC,CAAA;AAC/C,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACjC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,sBAAsB,CAAC,CAAA;AACjF,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;IACxC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAA;IACjD,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;IACtD,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AAC3D,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/C,MAAM,CAAC,eAAe,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;AAC3C,CAAC,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { Connector } from '@toa.io/core';
2
+ /**
3
+ * Serves the configuration UI: the directory `ui` builds, and nothing else.
4
+ *
5
+ * The page is a single-page application whose mount path is baked into the bundle,
6
+ * so this server routes relative to `UI_PATH` — which is also what the ingress
7
+ * forwards. `/configuration/*` is left alone: that is the component's own API.
8
+ */
9
+ export declare class UI extends Connector {
10
+ private readonly server;
11
+ private readonly port;
12
+ private readonly root;
13
+ constructor(port: number, root?: string);
14
+ protected open(): Promise<void>;
15
+ protected close(): Promise<void>;
16
+ private listen;
17
+ private respond;
18
+ /**
19
+ * The file a request lands on, or `null` when nothing does. A path that exists is
20
+ * served as it is; anything else that could be a route falls back to the page,
21
+ * because the client router — not this server — knows what routes there are.
22
+ */
23
+ private resolve;
24
+ private send;
25
+ }