@toa.io/extensions.configuration 1.0.0-alpha.29 → 1.0.0-alpha.292
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 +42 -0
- package/components/configuration.values/manifest.toa.yaml +151 -0
- package/components/configuration.values/migrations/0002-indexes.yaml +7 -0
- package/components/configuration.values/operations/create.js +30 -0
- package/components/configuration.values/operations/fetch.js +13 -0
- package/components/configuration.values/operations/get.js +19 -0
- package/components/configuration.values/operations/lib/map.js +22 -0
- package/components/configuration.values/operations/lib/resolve.js +24 -0
- package/components/configuration.values/operations/list.js +11 -0
- package/components/configuration.values/source/create.ts +54 -0
- package/components/configuration.values/source/fetch.ts +26 -0
- package/components/configuration.values/source/get.ts +32 -0
- package/components/configuration.values/source/lib/map.test.ts +42 -0
- package/components/configuration.values/source/lib/map.ts +36 -0
- package/components/configuration.values/source/lib/resolve.ts +57 -0
- package/components/configuration.values/source/list.ts +21 -0
- package/components/configuration.values/tsconfig.json +10 -0
- package/components/configuration.values/tsconfig.tsbuildinfo +1 -0
- package/components/configuration.values/types/index.d.ts +3 -0
- package/components/configuration.values/types/toa.d.ts +68 -0
- package/cucumber.mjs +8 -0
- package/features/site/_app/immutable/asset.js +1 -0
- package/features/site/favicon.ico +0 -0
- package/features/site/index.html +10 -0
- package/features/steps/UI.ts +98 -0
- package/features/steps/tsconfig.json +9 -0
- package/features/ui.feature +93 -0
- package/notes/consistency.md +10 -9
- package/package.json +12 -10
- package/readme.md +165 -51
- package/source/Aspect.test.ts +114 -10
- package/source/Aspect.ts +76 -8
- package/source/Client.test.ts +125 -0
- package/source/Client.ts +251 -0
- package/source/Composition.ts +57 -0
- package/source/Factory.ts +29 -7
- package/source/Secret.test.ts +32 -0
- package/source/Secret.ts +32 -0
- package/source/UI.ts +213 -0
- package/source/configuration.test.ts +105 -43
- package/source/configuration.ts +36 -21
- package/source/epoch.test.ts +35 -0
- package/source/index.ts +5 -3
- package/transpiled/Aspect.d.ts +19 -4
- package/transpiled/Aspect.js +62 -9
- package/transpiled/Aspect.js.map +1 -1
- package/transpiled/Client.d.ts +61 -0
- package/transpiled/Client.js +175 -0
- package/transpiled/Client.js.map +1 -0
- package/transpiled/Composition.d.ts +14 -0
- package/transpiled/Composition.js +38 -0
- package/transpiled/Composition.js.map +1 -0
- package/transpiled/Factory.d.ts +9 -2
- package/transpiled/Factory.js +20 -9
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Secret.d.ts +15 -0
- package/transpiled/Secret.js +26 -0
- package/transpiled/Secret.js.map +1 -0
- package/transpiled/UI.d.ts +25 -0
- package/transpiled/UI.js +173 -0
- package/transpiled/UI.js.map +1 -0
- package/transpiled/configuration.d.ts +7 -2
- package/transpiled/configuration.js +32 -43
- package/transpiled/configuration.js.map +1 -1
- package/transpiled/index.d.ts +3 -3
- package/transpiled/index.js +4 -9
- package/transpiled/index.js.map +1 -1
- package/tsconfig.json +5 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/ui/dist/_app/env.js +1 -0
- package/ui/dist/_app/immutable/assets/0.CNS8Cqhc.css +2 -0
- package/ui/dist/_app/immutable/assets/inter-cyrillic-ext-wght-normal.BOeWTOD4.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-cyrillic-wght-normal.DqGufNeO.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-greek-ext-wght-normal.DlzME5K_.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-greek-wght-normal.CkhJZR-_.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-latin-ext-wght-normal.DO1Apj_S.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-latin-wght-normal.Dx4kXJAl.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-vietnamese-wght-normal.CBcvBZtf.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/ui.BghF56l_.css +1 -0
- package/ui/dist/_app/immutable/chunks/-d-dxcbq.js +8 -0
- package/ui/dist/_app/immutable/chunks/64H_hMtE.js +50 -0
- package/ui/dist/_app/immutable/chunks/BeorVtKF.js +6 -0
- package/ui/dist/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/ui/dist/_app/immutable/chunks/C1Pl1PSE.js +1 -0
- package/ui/dist/_app/immutable/chunks/CcD_ISxM.js +3 -0
- package/ui/dist/_app/immutable/chunks/DzmF9ykx.js +1 -0
- package/ui/dist/_app/immutable/chunks/xihTtKlq.js +1 -0
- package/ui/dist/_app/immutable/entry/app.D5YrjA4l.js +2 -0
- package/ui/dist/_app/immutable/entry/start.CKkVSyXd.js +1 -0
- package/ui/dist/_app/immutable/nodes/0.Cm3Z3YNE.js +1 -0
- package/ui/dist/_app/immutable/nodes/1.e2aDXaPj.js +1 -0
- package/ui/dist/_app/immutable/nodes/2.Blh7Ex_K.js +1 -0
- package/ui/dist/_app/immutable/nodes/3.61NbGuZc.js +1 -0
- package/ui/dist/_app/immutable/nodes/4.B6OdRyVa.js +1 -0
- package/ui/dist/_app/version.json +1 -0
- package/ui/dist/apple-touch-icon.png +0 -0
- package/ui/dist/favicon-96x96.png +0 -0
- package/ui/dist/favicon.ico +0 -0
- package/ui/dist/index.html +57 -0
- package/ui/dist/robots.txt +3 -0
- package/schemas/annotation.cos.yaml +0 -1
- package/schemas/manifest.cos.yaml +0 -2
- package/source/deployment.test.ts +0 -21
- package/source/deployment.ts +0 -86
- package/source/manifest.test.ts +0 -15
- package/source/manifest.ts +0 -15
- package/source/schemas.ts +0 -9
- package/transpiled/Aspect.test.d.ts +0 -1
- package/transpiled/Aspect.test.js +0 -15
- package/transpiled/Aspect.test.js.map +0 -1
- package/transpiled/configuration.test.d.ts +0 -1
- package/transpiled/configuration.test.js +0 -64
- package/transpiled/configuration.test.js.map +0 -1
- package/transpiled/deployment.d.ts +0 -8
- package/transpiled/deployment.js +0 -88
- package/transpiled/deployment.js.map +0 -1
- package/transpiled/deployment.test.d.ts +0 -1
- package/transpiled/deployment.test.js +0 -18
- package/transpiled/deployment.test.js.map +0 -1
- package/transpiled/manifest.d.ts +0 -6
- package/transpiled/manifest.js +0 -35
- package/transpiled/manifest.js.map +0 -1
- package/transpiled/manifest.test.d.ts +0 -1
- package/transpiled/manifest.test.js +0 -14
- package/transpiled/manifest.test.js.map +0 -1
- package/transpiled/schemas.d.ts +0 -3
- package/transpiled/schemas.js +0 -33
- package/transpiled/schemas.js.map +0 -1
- package/transpiled/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { console } from 'openspan';
|
|
2
|
+
import { Connector, Locator } from '@toa.io/core';
|
|
3
|
+
import { EVENT, SOURCE } from '@toa.io/definitions/extensions.configuration';
|
|
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', {
|
|
134
|
+
components: waiting,
|
|
135
|
+
round: this.round
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
backoff() {
|
|
139
|
+
return Math.min(this.options.base * Math.pow(FACTOR, this.round), this.options.max);
|
|
140
|
+
}
|
|
141
|
+
/** A created object goes to the subscribers of its component and epoch, as it is. */
|
|
142
|
+
deliver(created) {
|
|
143
|
+
const listeners = this.listeners.get(id(created.component, created.epoch));
|
|
144
|
+
if (listeners === undefined)
|
|
145
|
+
return;
|
|
146
|
+
const value = {
|
|
147
|
+
configuration: created.configuration,
|
|
148
|
+
created: created.CREATED
|
|
149
|
+
};
|
|
150
|
+
for (const listener of listeners)
|
|
151
|
+
listener(value);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** What the event consumer hands deliveries to. */
|
|
155
|
+
class Subscription extends Connector {
|
|
156
|
+
handler;
|
|
157
|
+
constructor(handler) {
|
|
158
|
+
super();
|
|
159
|
+
this.handler = handler;
|
|
160
|
+
}
|
|
161
|
+
async receive(message) {
|
|
162
|
+
this.handler(message.payload);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function id(component, epoch) {
|
|
166
|
+
return component + '\0' + epoch;
|
|
167
|
+
}
|
|
168
|
+
const LOCATOR = new Locator('values', 'configuration');
|
|
169
|
+
const FACTOR = 1.5;
|
|
170
|
+
const DEFAULTS = {
|
|
171
|
+
base: 1000,
|
|
172
|
+
max: 10000,
|
|
173
|
+
warn: 5
|
|
174
|
+
};
|
|
175
|
+
//# 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,8CAA8C,CAAA;AAK5E;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IACnC,gGAAgG;IACzF,QAAQ,GAAG,KAAK,CAAA;IAEN,IAAI,CAAM;IACV,OAAO,CAAS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AA;IAC/B,CAAC;CACF;AAED,SAAS,EAAE,CAAC,SAAiB,EAAE,KAAa;IAC1C,OAAO,SAAS,GAAG,IAAI,GAAG,KAAK,CAAA;AACjC,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;AACtD,MAAM,MAAM,GAAG,GAAG,CAAA;AAElB,MAAM,QAAQ,GAAY;IACxB,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,CAAC;CACR,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 { uiPort } from '@toa.io/definitions/extensions.configuration';
|
|
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(uiPort());
|
|
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,MAAM,EAAE,MAAM,8CAA8C,CAAA;AACrE,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAG5B,yDAAyD;AACzD,MAAM,OAAO,WAAY,SAAQ,SAAS;IACvB,IAAI,CAAM;IAE3B,YAAmB,IAAU;QAC3B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAA;QAEnE,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;QAE3B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAEzB,kFAAkF;QAClF,iEAAiE;QACjE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,CAAA;QAE3B,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA;QAElB,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAClB,CAAC;CACF;AAED,MAAM,UAAU,UAAU;IACxB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;QACzC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC;AAED,SAAS,OAAO;IACd,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IAE1D,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;AACvD,CAAC;AAOD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA"}
|
package/transpiled/Factory.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type Connector, type Locator } from '@toa.io/core';
|
|
2
|
+
import type { extensions } from '@toa.io/core/types';
|
|
3
|
+
import type { Manifest } from '@toa.io/definitions/extensions.configuration';
|
|
3
4
|
export declare class Factory implements extensions.Factory {
|
|
5
|
+
private readonly host;
|
|
6
|
+
private client;
|
|
7
|
+
constructor(host: Host);
|
|
4
8
|
aspect(locator: Locator, manifest: Manifest): extensions.Aspect;
|
|
9
|
+
service(): Connector;
|
|
10
|
+
private shared;
|
|
5
11
|
}
|
|
12
|
+
export type Host = extensions.Host;
|
package/transpiled/Factory.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
9
|
-
return new
|
|
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":"
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":"AAEA,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,YAAmB,IAAU;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,MAAM,CAAC,OAAgB,EAAE,QAAkB;QAChD,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;YAAE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
/**
|
|
3
|
+
* A configuration value that must not leak: a string only to whoever asks for it.
|
|
4
|
+
*
|
|
5
|
+
* This is what a value declared `format: secret` is on a component's context.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Secret {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(value: string);
|
|
10
|
+
unwrap(): string;
|
|
11
|
+
toString(): string;
|
|
12
|
+
toJSON(): string;
|
|
13
|
+
[inspect.custom](): string;
|
|
14
|
+
}
|
|
15
|
+
export declare const REDACTED = "<REDACTED>";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
/**
|
|
3
|
+
* A configuration value that must not leak: a string only to whoever asks for it.
|
|
4
|
+
*
|
|
5
|
+
* This is what a value declared `format: secret` is on a component's context.
|
|
6
|
+
*/
|
|
7
|
+
export class Secret {
|
|
8
|
+
#value;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.#value = value;
|
|
11
|
+
}
|
|
12
|
+
unwrap() {
|
|
13
|
+
return this.#value;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return REDACTED;
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return REDACTED;
|
|
20
|
+
}
|
|
21
|
+
[inspect.custom]() {
|
|
22
|
+
return REDACTED;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const REDACTED = '<REDACTED>';
|
|
26
|
+
//# 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;AAEnC;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACR,MAAM,CAAQ;IAEvB,YAAmB,KAAa;QAC9B,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,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
|
+
}
|
package/transpiled/UI.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as http from 'node:http';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { Connector } from '@toa.io/core';
|
|
5
|
+
import { console } from 'openspan';
|
|
6
|
+
import { UI_PATH } from '@toa.io/definitions/extensions.configuration';
|
|
7
|
+
/**
|
|
8
|
+
* Serves the configuration UI: the directory `ui` builds, and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* The page is a single-page application whose mount path is baked into the bundle,
|
|
11
|
+
* so this server routes relative to `UI_PATH` — which is also what the ingress
|
|
12
|
+
* forwards. `/configuration/*` is left alone: that is the component's own API.
|
|
13
|
+
*/
|
|
14
|
+
export class UI extends Connector {
|
|
15
|
+
server = http.createServer();
|
|
16
|
+
port;
|
|
17
|
+
root;
|
|
18
|
+
constructor(port, root = SITE) {
|
|
19
|
+
super();
|
|
20
|
+
this.port = port;
|
|
21
|
+
this.root = root;
|
|
22
|
+
this.server.on('request', (request, response) => {
|
|
23
|
+
this.listen(request, response);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async open() {
|
|
27
|
+
/*
|
|
28
|
+
* A taken port is a real error: uniqueness across services is settled at export
|
|
29
|
+
* time, so nothing here has to negotiate for one.
|
|
30
|
+
*/
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const failed = (error) => {
|
|
33
|
+
this.server.off('listening', listening);
|
|
34
|
+
reject(error);
|
|
35
|
+
};
|
|
36
|
+
const listening = () => {
|
|
37
|
+
this.server.off('error', failed);
|
|
38
|
+
resolve();
|
|
39
|
+
};
|
|
40
|
+
this.server.once('error', failed);
|
|
41
|
+
this.server.once('listening', listening);
|
|
42
|
+
this.server.listen(this.port);
|
|
43
|
+
});
|
|
44
|
+
if (!isFile(path.join(this.root, 'index.html')))
|
|
45
|
+
console.warn('Configuration UI is not built', { root: this.root });
|
|
46
|
+
console.info('Configuration UI started', { port: this.port, path: UI_PATH + '/' });
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
const closed = new Promise((resolve) => this.server.once('close', () => {
|
|
50
|
+
resolve();
|
|
51
|
+
}));
|
|
52
|
+
this.server.close();
|
|
53
|
+
this.server.closeAllConnections();
|
|
54
|
+
await closed;
|
|
55
|
+
}
|
|
56
|
+
listen(request, response) {
|
|
57
|
+
void this.respond(request, response).catch((error) => {
|
|
58
|
+
console.error('Configuration UI failure', { message: error.message });
|
|
59
|
+
if (!response.writableEnded)
|
|
60
|
+
response.writeHead(500).end();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async respond(request, response) {
|
|
64
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
65
|
+
response.writeHead(405, { allow: 'GET, HEAD' }).end();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const pathname = decode(request.url ?? '/');
|
|
69
|
+
if (pathname === null) {
|
|
70
|
+
response.writeHead(400).end();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// the port is the explorer's alone, so the root is the way in
|
|
74
|
+
if (pathname === '/') {
|
|
75
|
+
response.writeHead(302, { location: UI_PATH + '/' }).end();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const file = this.resolve(pathname);
|
|
79
|
+
if (file === null)
|
|
80
|
+
response.writeHead(404).end();
|
|
81
|
+
else
|
|
82
|
+
await this.send(file, request, response);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The file a request lands on, or `null` when nothing does. A path that exists is
|
|
86
|
+
* served as it is; anything else that could be a route falls back to the page,
|
|
87
|
+
* because the client router — not this server — knows what routes there are.
|
|
88
|
+
*/
|
|
89
|
+
resolve(pathname) {
|
|
90
|
+
if (!pathname.startsWith(UI_PATH))
|
|
91
|
+
return null;
|
|
92
|
+
const relative = pathname.slice(UI_PATH.length);
|
|
93
|
+
if (relative !== '' && !relative.startsWith('/'))
|
|
94
|
+
return null;
|
|
95
|
+
const file = path.join(this.root, relative);
|
|
96
|
+
if (file !== this.root && !file.startsWith(this.root + path.sep))
|
|
97
|
+
return null;
|
|
98
|
+
if (isFile(file))
|
|
99
|
+
return file;
|
|
100
|
+
/*
|
|
101
|
+
* A missing asset is missing, but a route can look like one: `identity.passkeys` is a
|
|
102
|
+
* component, not a file with an extension. What this server would have served is what
|
|
103
|
+
* it knows how to serve, so anything else is a route and falls back to the page — as
|
|
104
|
+
* does anything ending in a slash, which is no name for a file at all.
|
|
105
|
+
*/
|
|
106
|
+
const asset = !relative.endsWith('/') && path.extname(relative) in TYPES;
|
|
107
|
+
return asset ? null : path.join(this.root, 'index.html');
|
|
108
|
+
}
|
|
109
|
+
async send(file, request, response) {
|
|
110
|
+
const stats = await fs.promises.stat(file).catch(() => null);
|
|
111
|
+
if (stats === null) {
|
|
112
|
+
response
|
|
113
|
+
.writeHead(503, { 'content-type': 'text/plain' })
|
|
114
|
+
.end('The configuration UI is not built. Run `npm run build:ui`.\n');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
response.writeHead(200, {
|
|
118
|
+
'content-type': TYPES[path.extname(file)] ?? 'application/octet-stream',
|
|
119
|
+
'content-length': stats.size,
|
|
120
|
+
'cache-control': caching(path.relative(this.root, file))
|
|
121
|
+
});
|
|
122
|
+
if (request.method === 'HEAD')
|
|
123
|
+
response.end();
|
|
124
|
+
else
|
|
125
|
+
fs.createReadStream(file).pipe(response);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function decode(url) {
|
|
129
|
+
try {
|
|
130
|
+
return decodeURIComponent(url.split('?')[0]);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function isFile(file) {
|
|
137
|
+
return fs.existsSync(file) && fs.statSync(file).isFile();
|
|
138
|
+
}
|
|
139
|
+
/** Where `npm run build:ui` puts the page, from both `source` and `transpiled`. */
|
|
140
|
+
const SITE = path.resolve(import.meta.dirname, '..', 'ui', 'dist');
|
|
141
|
+
/** Assets under this prefix carry their build hash in the name. */
|
|
142
|
+
const IMMUTABLE = path.join('_app', 'immutable');
|
|
143
|
+
const FOREVER = 'public, max-age=31536000, immutable';
|
|
144
|
+
/** The icons: named without a hash, so they are re-read, but rarely. */
|
|
145
|
+
const ICONS = new Set(['favicon.ico', 'favicon-96x96.png', 'apple-touch-icon.png']);
|
|
146
|
+
const DAY = 'public, max-age=86400';
|
|
147
|
+
/**
|
|
148
|
+
* How long what is served may be held. The page is never cached — it names the assets,
|
|
149
|
+
* and their names carry the build. An icon is named for what it is rather than for its
|
|
150
|
+
* content, so it is asked about again, but not on every page load.
|
|
151
|
+
*/
|
|
152
|
+
function caching(relative) {
|
|
153
|
+
if (relative.startsWith(IMMUTABLE))
|
|
154
|
+
return FOREVER;
|
|
155
|
+
return ICONS.has(relative) ? DAY : 'no-cache';
|
|
156
|
+
}
|
|
157
|
+
const TYPES = {
|
|
158
|
+
'.css': 'text/css; charset=utf-8',
|
|
159
|
+
'.html': 'text/html; charset=utf-8',
|
|
160
|
+
'.ico': 'image/x-icon',
|
|
161
|
+
'.jpg': 'image/jpeg',
|
|
162
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
163
|
+
'.json': 'application/json; charset=utf-8',
|
|
164
|
+
'.map': 'application/json; charset=utf-8',
|
|
165
|
+
'.png': 'image/png',
|
|
166
|
+
'.svg': 'image/svg+xml',
|
|
167
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
168
|
+
'.webmanifest': 'application/manifest+json',
|
|
169
|
+
'.webp': 'image/webp',
|
|
170
|
+
'.woff': 'font/woff',
|
|
171
|
+
'.woff2': 'font/woff2'
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=UI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UI.js","sourceRoot":"","sources":["../source/UI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,8CAA8C,CAAA;AAEtE;;;;;;GAMG;AACH,MAAM,OAAO,EAAG,SAAQ,SAAS;IACd,MAAM,GAAgB,IAAI,CAAC,YAAY,EAAE,CAAA;IACzC,IAAI,CAAQ;IACZ,IAAI,CAAQ;IAE7B,YAAmB,IAAY,EAAE,IAAI,GAAW,IAAI;QAClD,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAChC,CAAC,CAAC,CAAA;IACJ,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B;;;WAGG;QACH,MAAM,IAAI,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G,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAChD,MAAM,OAAO,GAAG,qCAAqC,CAAA;AAErD,wEAAwE;AACxE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,mBAAmB,EAAE,sBAAsB,CAAC,CAAC,CAAA;AACnF,MAAM,GAAG,GAAG,uBAAuB,CAAA;AAEnC;;;;GAIG;AACH,SAAS,OAAO,CAAC,QAAgB;IAC/B,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,OAAO,CAAA;IAElD,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAA;AAC/C,CAAC;AAED,MAAM,KAAK,GAA2B;IACpC,MAAM,EAAE,yBAAyB;IACjC,OAAO,EAAE,0BAA0B;IACnC,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,gCAAgC;IACvC,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,iCAAiC;IACzC,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,2BAA2B;IACnC,cAAc,EAAE,2BAA2B;IAC3C,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,WAAW;IACpB,QAAQ,EAAE,YAAY;CACvB,CAAA"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type Locator } from '@toa.io/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { Manifest } from '@toa.io/definitions/extensions.configuration';
|
|
3
|
+
/** The variable is set, so the values service is not consulted. */
|
|
4
|
+
export declare function overridden(locator: Locator): boolean;
|
|
5
|
+
/** The variable, the manifest defaults, then the schema. */
|
|
6
|
+
export declare function local(locator: Locator, manifest: Manifest): Node;
|
|
7
|
+
/** A copy of the value with the schema applied and the secrets substituted. */
|
|
8
|
+
export declare function fit(raw: object, manifest: Manifest): Node;
|
|
4
9
|
export type Node = Record<string, unknown>;
|