dougong 0.8.2 → 0.9.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.
- package/README.md +22 -97
- package/dist/advanced.d.ts +8 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +39 -0
- package/dist/composition/change-set.d.ts +49 -0
- package/dist/composition/change-set.d.ts.map +1 -0
- package/dist/composition/configuration.d.ts +9 -0
- package/dist/composition/configuration.d.ts.map +1 -0
- package/dist/composition/declarations.d.ts +53 -0
- package/dist/composition/declarations.d.ts.map +1 -0
- package/dist/composition/group.d.ts +10 -0
- package/dist/composition/group.d.ts.map +1 -0
- package/dist/composition/installation-graph.d.ts +17 -0
- package/dist/composition/installation-graph.d.ts.map +1 -0
- package/dist/composition/installation.d.ts +34 -0
- package/dist/composition/installation.d.ts.map +1 -0
- package/dist/composition/plan.d.ts +82 -0
- package/dist/composition/plan.d.ts.map +1 -0
- package/dist/composition/planner.d.ts +18 -0
- package/dist/composition/planner.d.ts.map +1 -0
- package/dist/composition/plugin-description.d.ts +34 -0
- package/dist/composition/plugin-description.d.ts.map +1 -0
- package/dist/composition/plugin.d.ts +68 -0
- package/dist/composition/plugin.d.ts.map +1 -0
- package/dist/contracts/contract-registry.d.ts +18 -0
- package/dist/contracts/contract-registry.d.ts.map +1 -0
- package/dist/contracts/contracts.d.ts +51 -0
- package/dist/contracts/contracts.d.ts.map +1 -0
- package/dist/contracts/errors.d.ts +53 -0
- package/dist/contracts/errors.d.ts.map +1 -0
- package/dist/contracts/logging.d.ts +16 -0
- package/dist/contracts/logging.d.ts.map +1 -0
- package/dist/contracts/resource.d.ts +14 -0
- package/dist/contracts/resource.d.ts.map +1 -0
- package/dist/contracts/status.d.ts +3 -0
- package/dist/contracts/status.d.ts.map +1 -0
- package/dist/contributions/contribution-store.d.ts +50 -0
- package/dist/contributions/contribution-store.d.ts.map +1 -0
- package/dist/events/event-hub.d.ts +27 -0
- package/dist/events/event-hub.d.ts.map +1 -0
- package/dist/execution/engine.d.ts +26 -0
- package/dist/execution/engine.d.ts.map +1 -0
- package/dist/execution/host-api.d.ts +43 -0
- package/dist/execution/host-api.d.ts.map +1 -0
- package/dist/execution/host.d.ts +3 -0
- package/dist/execution/host.d.ts.map +1 -0
- package/dist/execution/instance.d.ts +33 -0
- package/dist/execution/instance.d.ts.map +1 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2207 -8
- package/dist/inspection/diagnostics.d.ts +36 -0
- package/dist/inspection/diagnostics.d.ts.map +1 -0
- package/dist/internal/abort.d.ts +4 -0
- package/dist/internal/abort.d.ts.map +1 -0
- package/dist/internal/data-array.d.ts +3 -0
- package/dist/internal/data-array.d.ts.map +1 -0
- package/dist/internal/disposal-runtime.d.ts +5 -0
- package/dist/internal/disposal-runtime.d.ts.map +1 -0
- package/dist/internal/record.d.ts +8 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/serial-queue.d.ts +6 -0
- package/dist/internal/serial-queue.d.ts.map +1 -0
- package/dist/internal/synchronous-result.d.ts +3 -0
- package/dist/internal/synchronous-result.d.ts.map +1 -0
- package/dist/lifetime/lifetime-diagnostics.d.ts +21 -0
- package/dist/lifetime/lifetime-diagnostics.d.ts.map +1 -0
- package/dist/lifetime/lifetime.d.ts +71 -0
- package/dist/lifetime/lifetime.d.ts.map +1 -0
- package/dist/observation/readonly-map.d.ts +13 -0
- package/dist/observation/readonly-map.d.ts.map +1 -0
- package/dist/observation/snapshot-view.d.ts +14 -0
- package/dist/observation/snapshot-view.d.ts.map +1 -0
- package/dist/record-CZVpq8vk.js +493 -0
- package/package.json +17 -7
- package/runtime/abort-listener.d.mts +2 -0
- package/runtime/abort-listener.node.mjs +26 -0
- package/runtime/abort-listener.web.mjs +7 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,2208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v, y } from "./record-CZVpq8vk.js";
|
|
2
|
+
// src/contracts/contracts.ts
|
|
3
|
+
function ee(e, t) {
|
|
4
|
+
if (!b(t)) throw TypeError(typeof t == "string" && t.trim() ? `${e} id cannot start or end with whitespace` : `${e} id must be a non-empty string`);
|
|
5
|
+
}
|
|
6
|
+
function b(e) {
|
|
7
|
+
return typeof e == "string" && e.length > 0 && e === e.trim();
|
|
8
|
+
}
|
|
9
|
+
function x(e, t) {
|
|
10
|
+
return ee("Contract", t), Object.freeze({
|
|
11
|
+
id: t,
|
|
12
|
+
kind: e
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function S(e, t) {
|
|
16
|
+
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
17
|
+
return n && "value" in n ? n.value : void 0;
|
|
18
|
+
}
|
|
19
|
+
function C(e, t) {
|
|
20
|
+
let n = S(e, "id");
|
|
21
|
+
if (b(n) && (t === "service" || t === "extensionPoint" || t === "event")) return {
|
|
22
|
+
id: n,
|
|
23
|
+
kind: t
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function w(e, t, n) {
|
|
27
|
+
let r = e && typeof e == "object" ? C(e, S(e, "kind")) : void 0;
|
|
28
|
+
if (!r || t !== void 0 && r.kind !== t) throw TypeError(n ?? (t ? `Expected ${te(t)}` : "Invalid contract"));
|
|
29
|
+
return Object.freeze(r);
|
|
30
|
+
}
|
|
31
|
+
function te(e) {
|
|
32
|
+
return e === "extensionPoint" ? "an ExtensionPoint" : e === "event" ? "an Event" : "a Service";
|
|
33
|
+
}
|
|
34
|
+
function ne(e) {
|
|
35
|
+
return x("service", e);
|
|
36
|
+
}
|
|
37
|
+
function re(e) {
|
|
38
|
+
return x("event", e);
|
|
39
|
+
}
|
|
40
|
+
function ie(e) {
|
|
41
|
+
return x("extensionPoint", e);
|
|
42
|
+
}
|
|
43
|
+
function ae(e) {
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
kind: "optional",
|
|
46
|
+
service: w(e, "service", "optional() expects a Service")
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function T(e, t = "Expected a Service or ExtensionPoint", n = "Expected a Service") {
|
|
50
|
+
if (!e || typeof e != "object") throw TypeError(t);
|
|
51
|
+
let r = S(e, "kind");
|
|
52
|
+
if (r === "optional") return Object.freeze({
|
|
53
|
+
kind: r,
|
|
54
|
+
service: w(S(e, "service"), "service", n)
|
|
55
|
+
});
|
|
56
|
+
let i = C(e, r);
|
|
57
|
+
if (!i || i.kind === "event") throw TypeError(t);
|
|
58
|
+
return Object.freeze(i);
|
|
59
|
+
}
|
|
60
|
+
// src/contracts/resource.ts
|
|
61
|
+
function E(e) {
|
|
62
|
+
if (typeof e != "object" && typeof e != "function" || e === null) throw TypeError("Resource must implement Symbol.dispose or Symbol.asyncDispose");
|
|
63
|
+
let t = e[y];
|
|
64
|
+
if (t != null) {
|
|
65
|
+
if (typeof t != "function") throw TypeError("Symbol.asyncDispose must be a function");
|
|
66
|
+
return () => Reflect.apply(t, e, []);
|
|
67
|
+
}
|
|
68
|
+
let r = e[n];
|
|
69
|
+
if (typeof r != "function") throw TypeError("Resource must implement Symbol.dispose or Symbol.asyncDispose");
|
|
70
|
+
return () => v(Reflect.apply(r, e, []), "Symbol.dispose must be synchronous");
|
|
71
|
+
}
|
|
72
|
+
// src/lifetime/lifetime.ts
|
|
73
|
+
var D = /* @__PURE__ */ new WeakMap(), oe = class {
|
|
74
|
+
published = !1;
|
|
75
|
+
}, O = Object.freeze(new DOMException("Resource disposed", "AbortError")), se = class {
|
|
76
|
+
id;
|
|
77
|
+
kind;
|
|
78
|
+
#e;
|
|
79
|
+
#t;
|
|
80
|
+
#n;
|
|
81
|
+
#r;
|
|
82
|
+
#i;
|
|
83
|
+
constructor(e, t, n, r, i) {
|
|
84
|
+
this.#i = i, this.id = e, this.kind = t, this.#e = n, this.#t = r;
|
|
85
|
+
}
|
|
86
|
+
get failure() {
|
|
87
|
+
return this.#r;
|
|
88
|
+
}
|
|
89
|
+
dispose() {
|
|
90
|
+
if (this.#n) return this.#n;
|
|
91
|
+
let e = this.#e;
|
|
92
|
+
if (!e) return Promise.resolve();
|
|
93
|
+
let t = Promise.withResolvers();
|
|
94
|
+
return this.#n = Object.freeze(t.promise), Promise.resolve().then(e).then(() => {
|
|
95
|
+
this.#e = void 0;
|
|
96
|
+
let e = this.#t;
|
|
97
|
+
this.#t = void 0, this.#i = void 0, e?.(), t.resolve();
|
|
98
|
+
}, (e) => {
|
|
99
|
+
this.#r = new _(e), this.#i?.(), t.reject(e);
|
|
100
|
+
}), t.promise;
|
|
101
|
+
}
|
|
102
|
+
forget() {
|
|
103
|
+
if (this.#n) return;
|
|
104
|
+
this.#e = void 0, this.#i = void 0;
|
|
105
|
+
let e = this.#t;
|
|
106
|
+
this.#t = void 0, e?.();
|
|
107
|
+
}
|
|
108
|
+
}, ce = class {
|
|
109
|
+
id;
|
|
110
|
+
publication;
|
|
111
|
+
failure;
|
|
112
|
+
constructor(e, t) {
|
|
113
|
+
this.id = e, this.publication = t;
|
|
114
|
+
}
|
|
115
|
+
withdraw() {
|
|
116
|
+
if (this.failure) return !1;
|
|
117
|
+
try {
|
|
118
|
+
v(this.publication[n](), "Publication withdrawal must be synchronous");
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return this.failure = {
|
|
121
|
+
reason: e,
|
|
122
|
+
recorded: new _(e)
|
|
123
|
+
}, !1;
|
|
124
|
+
}
|
|
125
|
+
return !0;
|
|
126
|
+
}
|
|
127
|
+
}, le = class {
|
|
128
|
+
handle;
|
|
129
|
+
#e;
|
|
130
|
+
#t;
|
|
131
|
+
settled;
|
|
132
|
+
constructor(e, t, n) {
|
|
133
|
+
let r = new AbortController();
|
|
134
|
+
this.#e = r, this.#t = n;
|
|
135
|
+
let a = t, o = (e) => {
|
|
136
|
+
if (!a) return;
|
|
137
|
+
let t = a;
|
|
138
|
+
a = void 0;
|
|
139
|
+
try {
|
|
140
|
+
i(r.signal, e) || t(e);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
queueMicrotask(() => {
|
|
143
|
+
throw e;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}, s = Promise.resolve().then(() => {
|
|
147
|
+
try {
|
|
148
|
+
return e(r.signal);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
throw o(e), e;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
this.settled = Object.freeze(s.then(() => this.#n(), (e) => {
|
|
154
|
+
o(e), this.#n();
|
|
155
|
+
})), this.handle = Object.freeze({
|
|
156
|
+
result: s,
|
|
157
|
+
[y]: this.#r.bind(this)
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
#n() {
|
|
161
|
+
this.#e = void 0;
|
|
162
|
+
let e = this.#t;
|
|
163
|
+
this.#t = void 0, e?.();
|
|
164
|
+
}
|
|
165
|
+
#r() {
|
|
166
|
+
return this.cancel(O), this.settled;
|
|
167
|
+
}
|
|
168
|
+
cancel(e) {
|
|
169
|
+
let t = this.#e;
|
|
170
|
+
this.#e = void 0, t?.abort(e);
|
|
171
|
+
}
|
|
172
|
+
}, ue = class t {
|
|
173
|
+
#e;
|
|
174
|
+
#t = new AbortController();
|
|
175
|
+
#n;
|
|
176
|
+
#r = /* @__PURE__ */ new Set();
|
|
177
|
+
#i = /* @__PURE__ */ new Set();
|
|
178
|
+
#a = /* @__PURE__ */ new Set();
|
|
179
|
+
#o = /* @__PURE__ */ new Set();
|
|
180
|
+
#s = /* @__PURE__ */ new Set();
|
|
181
|
+
#c = /* @__PURE__ */ new Set();
|
|
182
|
+
#l;
|
|
183
|
+
#u;
|
|
184
|
+
#d;
|
|
185
|
+
#f = "active";
|
|
186
|
+
#p = 0;
|
|
187
|
+
#m = 0;
|
|
188
|
+
#h;
|
|
189
|
+
#g;
|
|
190
|
+
#_;
|
|
191
|
+
#v;
|
|
192
|
+
#y;
|
|
193
|
+
#b;
|
|
194
|
+
constructor(t, n) {
|
|
195
|
+
if (de(t.label), typeof t.report != "function") throw TypeError("Lifetime error reporter must be a function");
|
|
196
|
+
this.#e = t.label, this.#u = t.report, this.#d = t.changed, this.#l = A(t.shutdownTimeoutMilliseconds), this.#n = n?.visibility ?? new oe(), this.#g = n?.detach, t.parentSignal && (this.#h = e(t.parentSignal, (e) => {
|
|
197
|
+
this.block(), this.#D(e);
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
get handle() {
|
|
201
|
+
return this.#b ??= this.#x({});
|
|
202
|
+
}
|
|
203
|
+
#x(e) {
|
|
204
|
+
let t = this, n = Object.freeze({
|
|
205
|
+
...e,
|
|
206
|
+
get signal() {
|
|
207
|
+
return t.signal;
|
|
208
|
+
},
|
|
209
|
+
use: (e) => this.use(e),
|
|
210
|
+
defer: (e) => this.defer(e),
|
|
211
|
+
child: (e) => this.child(e),
|
|
212
|
+
spawn: (e) => this.spawn(e),
|
|
213
|
+
acquire: (e) => this.acquire(e),
|
|
214
|
+
interrupt: (e) => this.interrupt(e)
|
|
215
|
+
});
|
|
216
|
+
return D.set(n, this), n;
|
|
217
|
+
}
|
|
218
|
+
resolveOwner(e) {
|
|
219
|
+
if (this.#N(), e === void 0) return this;
|
|
220
|
+
let t = D.get(e);
|
|
221
|
+
if (!t || !this.#C(t)) throw TypeError("Lifetime owner must belong to the current scope tree");
|
|
222
|
+
return t.#N(), t;
|
|
223
|
+
}
|
|
224
|
+
*#S() {
|
|
225
|
+
let e = [this];
|
|
226
|
+
for (; e.length;) {
|
|
227
|
+
let t = e.pop();
|
|
228
|
+
yield t;
|
|
229
|
+
for (let n of [...t.#r].reverse()) e.push(n);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
#C(e) {
|
|
233
|
+
for (let t of this.#S()) if (t === e) return !0;
|
|
234
|
+
return !1;
|
|
235
|
+
}
|
|
236
|
+
get signal() {
|
|
237
|
+
return this.#t.signal;
|
|
238
|
+
}
|
|
239
|
+
get phase() {
|
|
240
|
+
return this.#f;
|
|
241
|
+
}
|
|
242
|
+
get acceptsWork() {
|
|
243
|
+
return this.#f === "active" && !o(this.signal);
|
|
244
|
+
}
|
|
245
|
+
get published() {
|
|
246
|
+
return this.#n.published;
|
|
247
|
+
}
|
|
248
|
+
get busy() {
|
|
249
|
+
for (let e of this.#S()) if (e.#p > 0) return !0;
|
|
250
|
+
return !1;
|
|
251
|
+
}
|
|
252
|
+
snapshot() {
|
|
253
|
+
let e = /* @__PURE__ */ new Map();
|
|
254
|
+
for (let t of [...this.#S()].reverse()) e.set(t, t.#w([...t.#r].map((t) => e.get(t))));
|
|
255
|
+
return e.get(this);
|
|
256
|
+
}
|
|
257
|
+
#w(e) {
|
|
258
|
+
let t = [], n = (e, n, r) => {
|
|
259
|
+
r && t.push(Object.freeze({
|
|
260
|
+
id: e,
|
|
261
|
+
kind: n,
|
|
262
|
+
error: r.snapshot
|
|
263
|
+
}));
|
|
264
|
+
};
|
|
265
|
+
for (let e of this.#i) n(e.id, e.kind, e.failure);
|
|
266
|
+
for (let e of this.#a) n(e.id, e.kind, e.failure);
|
|
267
|
+
for (let e of this.#o) n(e.id, "publication", e.failure?.recorded);
|
|
268
|
+
return n(0, "shutdown", this.#y), Object.freeze({
|
|
269
|
+
label: this.#e,
|
|
270
|
+
phase: this.#f,
|
|
271
|
+
cleanups: this.#i.size,
|
|
272
|
+
interrupts: this.#a.size,
|
|
273
|
+
tasks: this.#s.size,
|
|
274
|
+
acquisitions: this.#c.size,
|
|
275
|
+
publications: this.#o.size,
|
|
276
|
+
foreground: this.#p,
|
|
277
|
+
unresolved: Object.freeze(t),
|
|
278
|
+
children: Object.freeze(e)
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
use(e) {
|
|
282
|
+
return this.#T(e), e;
|
|
283
|
+
}
|
|
284
|
+
own(e) {
|
|
285
|
+
let t = this.#T(e);
|
|
286
|
+
return () => t.forget();
|
|
287
|
+
}
|
|
288
|
+
#T(e) {
|
|
289
|
+
this.#N();
|
|
290
|
+
let t = E(e);
|
|
291
|
+
return this.#N(), this.#j(t, "cleanup");
|
|
292
|
+
}
|
|
293
|
+
defer(e) {
|
|
294
|
+
if (this.#N(), typeof e != "function") throw TypeError("Cleanup must be a function");
|
|
295
|
+
let t = this.#j(e, "cleanup");
|
|
296
|
+
return Object.freeze({ [y]: () => t.dispose() });
|
|
297
|
+
}
|
|
298
|
+
interrupt(e) {
|
|
299
|
+
if (this.#N(), typeof e != "function") throw TypeError("Interrupt must be a function");
|
|
300
|
+
let t = this.#j(e, "interrupt");
|
|
301
|
+
return Object.freeze({ [n]: () => t.forget() });
|
|
302
|
+
}
|
|
303
|
+
child(e) {
|
|
304
|
+
this.#N();
|
|
305
|
+
let n = new t({
|
|
306
|
+
label: e,
|
|
307
|
+
report: this.#u,
|
|
308
|
+
...this.#d && { changed: this.#d },
|
|
309
|
+
...this.#l === void 0 ? {} : { shutdownTimeoutMilliseconds: this.#l }
|
|
310
|
+
}, {
|
|
311
|
+
visibility: this.#n,
|
|
312
|
+
detach: (e) => {
|
|
313
|
+
this.#r.delete(e), this.#d?.();
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
this.#r.add(n), this.#d?.();
|
|
317
|
+
let r = n.#x({ [y]: n.dispose.bind(n) });
|
|
318
|
+
return n.#b = r, r;
|
|
319
|
+
}
|
|
320
|
+
spawn(e) {
|
|
321
|
+
return this.#E(e, (e) => this.#M(e));
|
|
322
|
+
}
|
|
323
|
+
prepare(e) {
|
|
324
|
+
return this.#E(e).result;
|
|
325
|
+
}
|
|
326
|
+
#E(e, t) {
|
|
327
|
+
if (this.#N(), typeof e != "function") throw TypeError("Task must be a function");
|
|
328
|
+
let n = new le(e, t, () => {
|
|
329
|
+
this.#s.delete(n), this.#d?.();
|
|
330
|
+
});
|
|
331
|
+
return this.#s.add(n), this.#d?.(), n.handle;
|
|
332
|
+
}
|
|
333
|
+
acquire(e) {
|
|
334
|
+
if (this.#N(), typeof e != "function") throw TypeError("Acquisition must be a function");
|
|
335
|
+
let t = Promise.resolve().then(() => e(this.signal)).then(async (e) => {
|
|
336
|
+
let t = this.#j(E(e), "cleanup");
|
|
337
|
+
if (!this.acceptsWork) {
|
|
338
|
+
let e = o(this.signal) ? s(this.signal) : O;
|
|
339
|
+
throw await t.dispose(), e;
|
|
340
|
+
}
|
|
341
|
+
return Object.freeze({ resource: e });
|
|
342
|
+
}), n = () => {
|
|
343
|
+
this.#c.delete(r), this.#d?.();
|
|
344
|
+
}, r = t.then(n, n);
|
|
345
|
+
return this.#c.add(r), this.#d?.(), t;
|
|
346
|
+
}
|
|
347
|
+
stage(e) {
|
|
348
|
+
this.#N();
|
|
349
|
+
let t, n = e(() => {
|
|
350
|
+
t && !t.failure && this.#o.delete(t), this.#d?.();
|
|
351
|
+
});
|
|
352
|
+
return t = new ce(++this.#m, n), this.#o.add(t), this.#d?.(), this.published && n.publish(), n;
|
|
353
|
+
}
|
|
354
|
+
borrow(e) {
|
|
355
|
+
if (this.#N(), typeof e != "function") throw TypeError("Borrow callback must be a function");
|
|
356
|
+
this.#p++, this.#d?.();
|
|
357
|
+
let t = () => {
|
|
358
|
+
this.#p--, this.#d?.();
|
|
359
|
+
};
|
|
360
|
+
try {
|
|
361
|
+
let n = e(), r = new Promise((e) => e(n));
|
|
362
|
+
return r.then(t, t), r;
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return t(), Promise.reject(e);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
seal() {
|
|
368
|
+
if (this.busy) throw new l("BUSY", "Lifetime has in-flight foreground work");
|
|
369
|
+
this.block();
|
|
370
|
+
}
|
|
371
|
+
block() {
|
|
372
|
+
for (let e of this.#S()) e.#f === "active" && (e.#f = "sealed");
|
|
373
|
+
}
|
|
374
|
+
#D(e) {
|
|
375
|
+
for (let t of this.#S()) {
|
|
376
|
+
t.#t.abort?.(e);
|
|
377
|
+
for (let n of t.#s) n.cancel(e);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
publish() {
|
|
381
|
+
if (this.#N(), this.#g) throw TypeError("Only the root Lifetime may publish declarations");
|
|
382
|
+
if (!this.#n.published) {
|
|
383
|
+
this.#n.published = !0;
|
|
384
|
+
for (let e of this.#S()) for (let t of e.#o) t.publication.publish();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
detachStartupSignal() {
|
|
388
|
+
this.#h?.(), this.#h = void 0;
|
|
389
|
+
}
|
|
390
|
+
dispose() {
|
|
391
|
+
if (this.#_) return this.#_;
|
|
392
|
+
if (this.#f === "disposed") return Promise.resolve();
|
|
393
|
+
try {
|
|
394
|
+
this.seal();
|
|
395
|
+
} catch (e) {
|
|
396
|
+
return Promise.reject(e);
|
|
397
|
+
}
|
|
398
|
+
let e = [...this.#S()].filter((e) => !e.#_), t = [];
|
|
399
|
+
for (let n = e.length - 1; n >= 0; n--) {
|
|
400
|
+
let r = e[n];
|
|
401
|
+
r.#O(r === this ? t : []);
|
|
402
|
+
}
|
|
403
|
+
try {
|
|
404
|
+
h(() => {
|
|
405
|
+
for (let t of e) t.#A();
|
|
406
|
+
this.#d?.();
|
|
407
|
+
});
|
|
408
|
+
} catch (e) {
|
|
409
|
+
t.push(e);
|
|
410
|
+
}
|
|
411
|
+
return this.#D(O), this.#_;
|
|
412
|
+
}
|
|
413
|
+
#O(e) {
|
|
414
|
+
this.#f = "disposing", this.detachStartupSignal();
|
|
415
|
+
let t = Promise.resolve().then(() => this.#k(e));
|
|
416
|
+
if (this.#v = t, this.#l === void 0) {
|
|
417
|
+
this.#_ = Object.freeze(t);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
let n = Promise.withResolvers();
|
|
421
|
+
this.#_ = Object.freeze(n.promise), n.promise.catch(() => void 0);
|
|
422
|
+
let r = setTimeout(() => {
|
|
423
|
+
let e = new l("SHUTDOWN_TIMEOUT", "Lifetime shutdown did not complete before its deadline");
|
|
424
|
+
this.#y = new _(e), this.#f = "quarantined", this.#d?.(), n.reject(e);
|
|
425
|
+
}, this.#l);
|
|
426
|
+
t.then(() => {
|
|
427
|
+
clearTimeout(r), n.resolve();
|
|
428
|
+
}, (e) => {
|
|
429
|
+
clearTimeout(r), n.reject(e);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async #k(e) {
|
|
433
|
+
for (let t of this.#o) t.failure && e.push(t.failure.reason);
|
|
434
|
+
let t = Promise.allSettled([...this.#r].map((e) => e.#v)), n = [...this.#a].reverse().map((e) => e.dispose());
|
|
435
|
+
for (let t of await Promise.allSettled(n)) t.status === "rejected" && e.push(t.reason);
|
|
436
|
+
let r = [...this.#s].map((e) => e.settled);
|
|
437
|
+
await Promise.all(r), await Promise.allSettled([...this.#c]);
|
|
438
|
+
let i = await t;
|
|
439
|
+
for (let t of i) t.status === "rejected" && e.push(t.reason);
|
|
440
|
+
if (i.every((e) => e.status === "fulfilled")) for (let t of [...this.#i].reverse()) try {
|
|
441
|
+
await t.dispose();
|
|
442
|
+
} catch (t) {
|
|
443
|
+
e.push(t);
|
|
444
|
+
}
|
|
445
|
+
if (this.#y = void 0, e.length) throw this.#f = "quarantined", this.#d?.(), AggregateError(e, "Lifetime has unresolved cleanup obligations");
|
|
446
|
+
this.#f = "disposed", this.#t = { signal: AbortSignal.abort(O) }, this.#d?.(), this.#d = void 0;
|
|
447
|
+
let a = this.#g;
|
|
448
|
+
this.#g = void 0, a?.(this), this.#u = void 0;
|
|
449
|
+
}
|
|
450
|
+
#A() {
|
|
451
|
+
for (let e of [...this.#o].reverse()) e.withdraw() ? this.#o.delete(e) : this.#o.add(e);
|
|
452
|
+
}
|
|
453
|
+
#j(e, t) {
|
|
454
|
+
let n = t === "cleanup" ? this.#i : this.#a, r;
|
|
455
|
+
return r = new se(++this.#m, t, e, () => {
|
|
456
|
+
n.delete(r), this.#d?.();
|
|
457
|
+
}, () => this.#d?.()), n.add(r), this.#d?.(), r;
|
|
458
|
+
}
|
|
459
|
+
#M(e) {
|
|
460
|
+
let t = this.#u;
|
|
461
|
+
t && v(t(e), "Lifetime error reporters must be synchronous");
|
|
462
|
+
}
|
|
463
|
+
#N() {
|
|
464
|
+
if (!this.acceptsWork) throw new l("LIFETIME_DISPOSED", "Lifetime is closed to new work");
|
|
465
|
+
}
|
|
466
|
+
}, k = 2 ** 31 - 1;
|
|
467
|
+
function A(e) {
|
|
468
|
+
if (e !== void 0) {
|
|
469
|
+
if (typeof e != "number" || !Number.isFinite(e) || e <= 0 || e > k) throw TypeError(`shutdownTimeoutMilliseconds must be a positive finite number no greater than ${k}`);
|
|
470
|
+
return e;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function de(e) {
|
|
474
|
+
if (typeof e != "string" || !e.trim() || e !== e.trim()) throw TypeError("Lifetime label must be a non-empty trimmed string");
|
|
475
|
+
}
|
|
476
|
+
// src/contracts/contract-registry.ts
|
|
477
|
+
var fe = class {
|
|
478
|
+
#e = /* @__PURE__ */ new Map();
|
|
479
|
+
assertKinds(e) {
|
|
480
|
+
for (let [t, n] of e) this.assertCompatible({
|
|
481
|
+
id: t,
|
|
482
|
+
kind: n
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
assertCompatible(e) {
|
|
486
|
+
M(this.#e, e);
|
|
487
|
+
}
|
|
488
|
+
remember(e) {
|
|
489
|
+
j(this.#e, e);
|
|
490
|
+
}
|
|
491
|
+
writer(e) {
|
|
492
|
+
return new pe(this, e);
|
|
493
|
+
}
|
|
494
|
+
commit(e) {
|
|
495
|
+
this.assertKinds(e);
|
|
496
|
+
for (let [t, n] of e) this.#e.set(t, n);
|
|
497
|
+
}
|
|
498
|
+
}, pe = class {
|
|
499
|
+
#e;
|
|
500
|
+
constructor(e, t) {
|
|
501
|
+
this.#e = {
|
|
502
|
+
phase: "staged",
|
|
503
|
+
registry: e,
|
|
504
|
+
pending: /* @__PURE__ */ new Map()
|
|
505
|
+
};
|
|
506
|
+
for (let [e, n] of t) this.remember({
|
|
507
|
+
id: e,
|
|
508
|
+
kind: n
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
remember(e) {
|
|
512
|
+
let t = this.#e;
|
|
513
|
+
if (t.phase === "committed") t.registry.remember(e);
|
|
514
|
+
else {
|
|
515
|
+
if (t.phase === "discarded") throw Error("Contract registry writer has been discarded");
|
|
516
|
+
t.registry.assertCompatible(e), j(t.pending, e);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
commit() {
|
|
520
|
+
let e = this.#e;
|
|
521
|
+
e.phase === "staged" && (e.registry.commit(e.pending), this.#e = {
|
|
522
|
+
phase: "committed",
|
|
523
|
+
registry: e.registry
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
discard() {
|
|
527
|
+
this.#e.phase === "staged" && (this.#e = { phase: "discarded" });
|
|
528
|
+
}
|
|
9
529
|
};
|
|
530
|
+
function j(e, t) {
|
|
531
|
+
M(e, t), e.set(t.id, t.kind);
|
|
532
|
+
}
|
|
533
|
+
function M(e, t) {
|
|
534
|
+
let n = e.get(t.id);
|
|
535
|
+
if (n && n !== t.kind) throw new l("CONTRACT_CONFLICT", `Contract '${t.id}' is used as both '${n}' and '${t.kind}'`);
|
|
536
|
+
}
|
|
537
|
+
// src/events/event-hub.ts
|
|
538
|
+
var me = class {
|
|
539
|
+
#e;
|
|
540
|
+
#t;
|
|
541
|
+
handle;
|
|
542
|
+
constructor(e, t, r, i, a) {
|
|
543
|
+
this.#e = t, this.#t = {
|
|
544
|
+
hub: e,
|
|
545
|
+
listener: r,
|
|
546
|
+
owner: i,
|
|
547
|
+
detach: a
|
|
548
|
+
}, this.handle = Object.freeze({ [n]: () => this[n]() });
|
|
549
|
+
}
|
|
550
|
+
publish() {
|
|
551
|
+
let e = this.#t;
|
|
552
|
+
e && e.hub.add(this.#e, this);
|
|
553
|
+
}
|
|
554
|
+
invoke(e) {
|
|
555
|
+
let t = this.#t;
|
|
556
|
+
if (!t) return Promise.resolve();
|
|
557
|
+
let { owner: n, listener: r } = t;
|
|
558
|
+
return n.borrow(() => r(e));
|
|
559
|
+
}
|
|
560
|
+
[n]() {
|
|
561
|
+
let e = this.#t;
|
|
562
|
+
e && (this.#t = void 0, e.hub.delete(this.#e, this), e.detach());
|
|
563
|
+
}
|
|
564
|
+
}, he = class {
|
|
565
|
+
#e;
|
|
566
|
+
constructor(e, t, n) {
|
|
567
|
+
this.#e = {
|
|
568
|
+
hub: e,
|
|
569
|
+
owner: t,
|
|
570
|
+
remember: n
|
|
571
|
+
}, t.defer(() => {
|
|
572
|
+
this.#e = void 0;
|
|
573
|
+
}), Object.freeze(this);
|
|
574
|
+
}
|
|
575
|
+
on(e, t, n) {
|
|
576
|
+
let r = this.#t();
|
|
577
|
+
if (typeof t != "function") throw TypeError("Event listener must be a function");
|
|
578
|
+
let i = w(e, "event"), a = r.owner.resolveOwner(n?.lifetime);
|
|
579
|
+
return r.remember(i), r.hub.stage(i.id, t, a);
|
|
580
|
+
}
|
|
581
|
+
async emit(e, ...t) {
|
|
582
|
+
let n = this.#t();
|
|
583
|
+
if (!n.owner.published) throw new l("EVENT_BEFORE_COMMIT", "Candidate setup cannot emit into the committed event graph");
|
|
584
|
+
let r = w(e, "event");
|
|
585
|
+
this.#t(), n.remember(r), await n.hub.emit(r.id, t[0]);
|
|
586
|
+
}
|
|
587
|
+
#t() {
|
|
588
|
+
let e = this.#e;
|
|
589
|
+
if (!e || !e.owner.acceptsWork) throw new l("LIFETIME_DISPOSED", "Event scope is closed");
|
|
590
|
+
return e;
|
|
591
|
+
}
|
|
592
|
+
}, ge = class {
|
|
593
|
+
#e = /* @__PURE__ */ new Map();
|
|
594
|
+
scope(e, t) {
|
|
595
|
+
return new he(this, e, t);
|
|
596
|
+
}
|
|
597
|
+
stage(e, t, n) {
|
|
598
|
+
return n.stage((r) => new me(this, e, t, n, r)).handle;
|
|
599
|
+
}
|
|
600
|
+
add(e, t) {
|
|
601
|
+
let n = this.#e.get(e) ?? /* @__PURE__ */ new Set();
|
|
602
|
+
n.add(t), this.#e.set(e, n);
|
|
603
|
+
}
|
|
604
|
+
delete(e, t) {
|
|
605
|
+
let n = this.#e.get(e);
|
|
606
|
+
n && (n.delete(t), n.size || this.#e.delete(e));
|
|
607
|
+
}
|
|
608
|
+
async emit(e, t) {
|
|
609
|
+
let n = [...this.#e.get(e) ?? []], r = (await Promise.allSettled(n.map((e) => {
|
|
610
|
+
try {
|
|
611
|
+
return e.invoke(t);
|
|
612
|
+
} catch (e) {
|
|
613
|
+
return Promise.reject(e);
|
|
614
|
+
}
|
|
615
|
+
}))).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
616
|
+
if (r.length) throw AggregateError(r, `Event '${e}' listeners failed`);
|
|
617
|
+
}
|
|
618
|
+
}, N = class {
|
|
619
|
+
#e;
|
|
620
|
+
get;
|
|
621
|
+
subscribe;
|
|
622
|
+
use;
|
|
623
|
+
constructor(e) {
|
|
624
|
+
this.#e = e, this.get = () => this.#t(), this.subscribe = (e) => this.#n(e), this.use = (e, t) => {
|
|
625
|
+
try {
|
|
626
|
+
return this.#r().store.use(e, t);
|
|
627
|
+
} catch (e) {
|
|
628
|
+
return Promise.reject(e);
|
|
629
|
+
}
|
|
630
|
+
}, Object.freeze(this);
|
|
631
|
+
}
|
|
632
|
+
#t() {
|
|
633
|
+
return this.#r().store.snapshot();
|
|
634
|
+
}
|
|
635
|
+
#n(e) {
|
|
636
|
+
let t = this.#r();
|
|
637
|
+
if (typeof e != "function") throw TypeError("Contribution subscriber must be a function");
|
|
638
|
+
return t.store.subscribe(() => {
|
|
639
|
+
if (!t.owner || t.owner.acceptsWork) return e();
|
|
640
|
+
}, t.own);
|
|
641
|
+
}
|
|
642
|
+
#r() {
|
|
643
|
+
let e = this.#e.binding;
|
|
644
|
+
if (!e) throw TypeError("Contribution view has been disposed");
|
|
645
|
+
if (e.owner && !e.owner.acceptsWork) throw new l("LIFETIME_DISPOSED", "Contribution view owner is closed");
|
|
646
|
+
return e;
|
|
647
|
+
}
|
|
648
|
+
}, _e = class {
|
|
649
|
+
#e;
|
|
650
|
+
constructor(e) {
|
|
651
|
+
this.#e = e, Object.freeze(this);
|
|
652
|
+
}
|
|
653
|
+
update = (e) => this.#e.update(e);
|
|
654
|
+
[n]() {
|
|
655
|
+
this.#e[n]();
|
|
656
|
+
}
|
|
657
|
+
}, ve = class {
|
|
658
|
+
#e;
|
|
659
|
+
#t;
|
|
660
|
+
handle;
|
|
661
|
+
constructor(e, t, n, r, i) {
|
|
662
|
+
this.#t = t, this.#e = {
|
|
663
|
+
phase: "active",
|
|
664
|
+
store: e,
|
|
665
|
+
value: n,
|
|
666
|
+
owner: r,
|
|
667
|
+
detachFromOwner: i
|
|
668
|
+
}, this.handle = new _e(this);
|
|
669
|
+
}
|
|
670
|
+
publish() {
|
|
671
|
+
let e = this.#e;
|
|
672
|
+
e.phase !== "disposed" && e.store.publishClaim(this.#t, this);
|
|
673
|
+
}
|
|
674
|
+
use(e) {
|
|
675
|
+
let t = this.#e;
|
|
676
|
+
if (t.phase === "disposed") throw new l("CONTRIBUTION_UNAVAILABLE", "Contribution is no longer available");
|
|
677
|
+
let { owner: n, value: r } = t;
|
|
678
|
+
return n.borrow(() => e(r));
|
|
679
|
+
}
|
|
680
|
+
update(e) {
|
|
681
|
+
let t = this.#e;
|
|
682
|
+
if (t.phase === "disposed") throw TypeError(`Contribution '${this.#t}' has been disposed`);
|
|
683
|
+
if (!t.owner.acceptsWork) throw new l("LIFETIME_DISPOSED", "Contribution owner is closed");
|
|
684
|
+
Object.is(t.value, e) || (t.value = e, t.store.valueChanged(this.#t, this));
|
|
685
|
+
}
|
|
686
|
+
[n]() {
|
|
687
|
+
let e = this.#e;
|
|
688
|
+
if (e.phase !== "disposed") {
|
|
689
|
+
this.#e = { phase: "disposed" };
|
|
690
|
+
try {
|
|
691
|
+
e.store.removeContribution(this.#t, this);
|
|
692
|
+
} finally {
|
|
693
|
+
e.detachFromOwner();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}, ye = class {
|
|
698
|
+
#e;
|
|
699
|
+
#t;
|
|
700
|
+
#n = /* @__PURE__ */ new Map();
|
|
701
|
+
#r;
|
|
702
|
+
#i = Object.freeze([]);
|
|
703
|
+
#a = 0;
|
|
704
|
+
#o = 0;
|
|
705
|
+
#s;
|
|
706
|
+
#c = !1;
|
|
707
|
+
constructor(e, t, n) {
|
|
708
|
+
this.#e = e, this.#t = n, this.#r = new f(() => this.#i, t);
|
|
709
|
+
}
|
|
710
|
+
stage(e, t, n, r, i) {
|
|
711
|
+
try {
|
|
712
|
+
Se(t);
|
|
713
|
+
let a = Ce(e, t);
|
|
714
|
+
if (this.#n.has(a)) throw TypeError(`Duplicate contribution '${a}'`);
|
|
715
|
+
return r.stage((e) => {
|
|
716
|
+
i?.();
|
|
717
|
+
let t = new ve(this, a, n, r, e);
|
|
718
|
+
return this.#n.set(a, {
|
|
719
|
+
contribution: t,
|
|
720
|
+
phase: "staged"
|
|
721
|
+
}), t;
|
|
722
|
+
}).handle;
|
|
723
|
+
} catch (e) {
|
|
724
|
+
throw this.#u(), e;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
view(e, t) {
|
|
728
|
+
this.#a++;
|
|
729
|
+
let n = { binding: {
|
|
730
|
+
store: this,
|
|
731
|
+
own: e,
|
|
732
|
+
...t && { owner: t }
|
|
733
|
+
} }, r, i = new P(n, () => {
|
|
734
|
+
let e = r;
|
|
735
|
+
r = void 0;
|
|
736
|
+
try {
|
|
737
|
+
e?.();
|
|
738
|
+
} finally {
|
|
739
|
+
this.#a--, this.#u();
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
try {
|
|
743
|
+
r = e(i);
|
|
744
|
+
} catch (e) {
|
|
745
|
+
throw n.binding = void 0, this.#a--, this.#u(), e;
|
|
746
|
+
}
|
|
747
|
+
return new N(n);
|
|
748
|
+
}
|
|
749
|
+
hostView() {
|
|
750
|
+
return this.#s ??= new N({ binding: { store: this } });
|
|
751
|
+
}
|
|
752
|
+
use(e, t) {
|
|
753
|
+
let n = this.#n.get(e);
|
|
754
|
+
if (n?.phase !== "published") throw new l("CONTRIBUTION_UNAVAILABLE", `Contribution '${e}' is not available`);
|
|
755
|
+
if (typeof t != "function") throw TypeError("Contribution callback must be a function");
|
|
756
|
+
return n.contribution.use(t);
|
|
757
|
+
}
|
|
758
|
+
snapshot() {
|
|
759
|
+
return this.#r.view.get();
|
|
760
|
+
}
|
|
761
|
+
subscribe(e, t) {
|
|
762
|
+
if (typeof e != "function") throw TypeError("Contribution subscriber must be a function");
|
|
763
|
+
let r = this.#r.view.subscribe(e);
|
|
764
|
+
if (!t) return r;
|
|
765
|
+
this.#o++;
|
|
766
|
+
let i, a = new be(r, () => {
|
|
767
|
+
let e = i;
|
|
768
|
+
i = void 0;
|
|
769
|
+
try {
|
|
770
|
+
e?.();
|
|
771
|
+
} finally {
|
|
772
|
+
this.#o--, this.#u();
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
try {
|
|
776
|
+
i = t(a);
|
|
777
|
+
} catch (e) {
|
|
778
|
+
throw a[n](), e;
|
|
779
|
+
}
|
|
780
|
+
return a;
|
|
781
|
+
}
|
|
782
|
+
publishClaim(e, t) {
|
|
783
|
+
let n = this.#l(e, t);
|
|
784
|
+
n.phase === "staged" && (n.phase = "pending", this.#n.delete(e), this.#n.set(e, n), this.#e(this));
|
|
785
|
+
}
|
|
786
|
+
valueChanged(e, t) {
|
|
787
|
+
let n = this.#l(e, t);
|
|
788
|
+
n.phase !== "staged" && (n.phase = "pending", this.#e(this));
|
|
789
|
+
}
|
|
790
|
+
removeContribution(e, t) {
|
|
791
|
+
let n = this.#l(e, t);
|
|
792
|
+
try {
|
|
793
|
+
this.#n.delete(e), n.phase !== "staged" && this.#e(this);
|
|
794
|
+
} finally {
|
|
795
|
+
this.#u();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
publishSnapshot() {
|
|
799
|
+
let e = [], t = !1;
|
|
800
|
+
for (let [n, r] of this.#n) r.phase !== "staged" && ((r.phase === "pending" || this.#i[e.length] !== n) && (t = !0), e.push(n), r.phase = "published");
|
|
801
|
+
(t || e.length !== this.#i.length) && (this.#i = Object.freeze(e), this.#r.invalidate());
|
|
802
|
+
}
|
|
803
|
+
#l(e, t) {
|
|
804
|
+
let n = this.#n.get(e);
|
|
805
|
+
if (n?.contribution !== t) throw Error(`Contribution '${e}' is not the current claim`);
|
|
806
|
+
return n;
|
|
807
|
+
}
|
|
808
|
+
#u() {
|
|
809
|
+
if (!(this.#c || this.#s || this.#n.size || this.#o || this.#a)) {
|
|
810
|
+
this.#c = !0;
|
|
811
|
+
try {
|
|
812
|
+
this.#r[n]();
|
|
813
|
+
} finally {
|
|
814
|
+
this.#t(this);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}, P = class {
|
|
819
|
+
#e;
|
|
820
|
+
constructor(e, t) {
|
|
821
|
+
this.#e = {
|
|
822
|
+
state: e,
|
|
823
|
+
release: t
|
|
824
|
+
}, Object.freeze(this);
|
|
825
|
+
}
|
|
826
|
+
[n]() {
|
|
827
|
+
let e = this.#e;
|
|
828
|
+
e && (this.#e = void 0, e.state.binding = void 0, e.release());
|
|
829
|
+
}
|
|
830
|
+
}, be = class {
|
|
831
|
+
#e;
|
|
832
|
+
constructor(e, t) {
|
|
833
|
+
this.#e = {
|
|
834
|
+
subscription: e,
|
|
835
|
+
release: t
|
|
836
|
+
}, Object.freeze(this);
|
|
837
|
+
}
|
|
838
|
+
[n]() {
|
|
839
|
+
let e = this.#e;
|
|
840
|
+
if (e) {
|
|
841
|
+
this.#e = void 0;
|
|
842
|
+
try {
|
|
843
|
+
e.subscription[n]();
|
|
844
|
+
} finally {
|
|
845
|
+
e.release();
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}, xe = class {
|
|
850
|
+
#e = /* @__PURE__ */ new Map();
|
|
851
|
+
#t = /* @__PURE__ */ new Set();
|
|
852
|
+
#n;
|
|
853
|
+
#r = 0;
|
|
854
|
+
constructor(e) {
|
|
855
|
+
this.#n = e;
|
|
856
|
+
}
|
|
857
|
+
get(e) {
|
|
858
|
+
let t = e.id, n = this.#e.get(t);
|
|
859
|
+
if (n) return n;
|
|
860
|
+
let r = new ye((e) => this.#i(e), this.#n, (e) => {
|
|
861
|
+
this.#e.get(t) === e && (this.#t.delete(e), this.#e.delete(t));
|
|
862
|
+
});
|
|
863
|
+
return this.#e.set(t, r), r;
|
|
864
|
+
}
|
|
865
|
+
view(e, t) {
|
|
866
|
+
let n = this.get(e);
|
|
867
|
+
return t ? n.view((e) => t.own(e), t) : n.hostView();
|
|
868
|
+
}
|
|
869
|
+
scope(e, t, n) {
|
|
870
|
+
return new we(this, e, t, n);
|
|
871
|
+
}
|
|
872
|
+
beginBatch() {
|
|
873
|
+
this.#r++;
|
|
874
|
+
}
|
|
875
|
+
endBatch() {
|
|
876
|
+
if (!this.#r) throw Error("Contribution batch is not active");
|
|
877
|
+
if (this.#r--, this.#r) return;
|
|
878
|
+
let e = [...this.#t];
|
|
879
|
+
this.#t.clear(), h(() => {
|
|
880
|
+
let t = [];
|
|
881
|
+
for (let n of e) try {
|
|
882
|
+
n.publishSnapshot();
|
|
883
|
+
} catch (e) {
|
|
884
|
+
t.push(e);
|
|
885
|
+
}
|
|
886
|
+
if (t.length === 1) throw t[0];
|
|
887
|
+
if (t.length > 1) throw AggregateError(t, "Contribution batch publication failed");
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
#i(e) {
|
|
891
|
+
this.#t.add(e), !this.#r && (this.#t.delete(e), e.publishSnapshot());
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
function Se(e) {
|
|
895
|
+
if (typeof e != "string" || !e.trim()) throw TypeError("Contribution key must be a non-empty string");
|
|
896
|
+
if (e !== e.trim()) throw TypeError("Contribution key cannot start or end with whitespace");
|
|
897
|
+
}
|
|
898
|
+
function Ce(e, t) {
|
|
899
|
+
return `${F(e)}/${F(t)}`;
|
|
900
|
+
}
|
|
901
|
+
function F(e) {
|
|
902
|
+
return e.replaceAll("%", "%25").replaceAll("/", "%2F");
|
|
903
|
+
}
|
|
904
|
+
var we = class {
|
|
905
|
+
#e;
|
|
906
|
+
constructor(e, t, n, r) {
|
|
907
|
+
this.#e = {
|
|
908
|
+
registry: e,
|
|
909
|
+
owner: t,
|
|
910
|
+
installationId: n,
|
|
911
|
+
remember: r
|
|
912
|
+
}, t.defer(() => {
|
|
913
|
+
this.#e = void 0;
|
|
914
|
+
}), Object.freeze(this);
|
|
915
|
+
}
|
|
916
|
+
add(e, t, n, r) {
|
|
917
|
+
let i = this.#e;
|
|
918
|
+
if (!i || !i.owner.acceptsWork) throw new l("LIFETIME_DISPOSED", "Contribution scope is closed");
|
|
919
|
+
let a = w(e, "extensionPoint"), o = i.owner.resolveOwner(r?.lifetime);
|
|
920
|
+
return i.registry.get(a).stage(i.installationId, t, n, o, () => i.remember(a));
|
|
921
|
+
}
|
|
922
|
+
}, Te = 64;
|
|
923
|
+
function I(e) {
|
|
924
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (e, i) => {
|
|
925
|
+
if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return {
|
|
926
|
+
value: e,
|
|
927
|
+
height: 0
|
|
928
|
+
};
|
|
929
|
+
if (typeof e != "object" || !e) throw TypeError(`Unsupported configuration value at ${i}`);
|
|
930
|
+
if (t.has(e)) throw TypeError(`Circular configuration at ${i}`);
|
|
931
|
+
let a = n.get(e);
|
|
932
|
+
if (t.size + (a?.height ?? 1) > Te) throw TypeError("Configuration exceeds the supported nesting depth");
|
|
933
|
+
if (a) return a;
|
|
934
|
+
t.add(e);
|
|
935
|
+
let o = 1, s = (e, t) => {
|
|
936
|
+
let n = r(e, t);
|
|
937
|
+
return o = Math.max(o, n.height + 1), n.value;
|
|
938
|
+
}, c;
|
|
939
|
+
if (Array.isArray(e)) {
|
|
940
|
+
let t = u(e, `Configuration array at ${i}`);
|
|
941
|
+
c = Object.freeze(t.map((e, t) => s(e, `${i}[${t}]`)));
|
|
942
|
+
} else {
|
|
943
|
+
let t = Object.getPrototypeOf(e);
|
|
944
|
+
if (t !== Object.prototype && t !== null) throw TypeError(`Configuration must contain plain records at ${i}`);
|
|
945
|
+
let n = Object.create(null);
|
|
946
|
+
for (let t of Reflect.ownKeys(e)) {
|
|
947
|
+
if (typeof t != "string") throw TypeError(`Configuration keys must be strings at ${i}`);
|
|
948
|
+
let r = Object.getOwnPropertyDescriptor(e, t);
|
|
949
|
+
if (!r || !("value" in r) || !r.enumerable) throw TypeError(`Configuration must contain enumerable data properties at ${i}.${t}`);
|
|
950
|
+
r.value !== void 0 && (n[t] = s(r.value, `${i}.${t}`));
|
|
951
|
+
}
|
|
952
|
+
c = Object.freeze(n);
|
|
953
|
+
}
|
|
954
|
+
t.delete(e);
|
|
955
|
+
let l = {
|
|
956
|
+
value: c,
|
|
957
|
+
height: o
|
|
958
|
+
};
|
|
959
|
+
return n.set(e, l), l;
|
|
960
|
+
};
|
|
961
|
+
return e === void 0 ? void 0 : r(e, "configuration").value;
|
|
962
|
+
}
|
|
963
|
+
async function Ee(e, t, n, i) {
|
|
964
|
+
if (i?.throwIfAborted(), !e) return Object.freeze({ value: t });
|
|
965
|
+
let a = e["~standard"].validate(t), o = i ? (await De(a, i)).result : await a;
|
|
966
|
+
if (i?.throwIfAborted(), !o || typeof o != "object") throw TypeError(`Installation '${n}' configuration validator returned a non-object result`);
|
|
967
|
+
let s = Object.hasOwn(o, "issues") ? o.issues : void 0;
|
|
968
|
+
if (s !== void 0) throw Array.isArray(s) ? new r(s, { details: {
|
|
969
|
+
installation: n,
|
|
970
|
+
phase: "configuration",
|
|
971
|
+
outcome: "rejected"
|
|
972
|
+
} }) : TypeError(`Installation '${n}' configuration validator returned non-array issues`);
|
|
973
|
+
if (!Object.hasOwn(o, "value")) throw TypeError(`Installation '${n}' configuration validator returned neither value nor issues`);
|
|
974
|
+
let c = o.value;
|
|
975
|
+
return Object.freeze({ value: Object.is(c, t) ? t : I(c) });
|
|
976
|
+
}
|
|
977
|
+
function De(t, n) {
|
|
978
|
+
let r = Promise.withResolvers(), { promise: i } = r, a = e(n, (e) => {
|
|
979
|
+
r?.reject(e), r = void 0;
|
|
980
|
+
});
|
|
981
|
+
return Oe(t).then((e) => r?.resolve(e), (e) => r?.reject(e)), i.finally(() => {
|
|
982
|
+
r = void 0, a();
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
async function Oe(e) {
|
|
986
|
+
return { result: await e };
|
|
987
|
+
}
|
|
988
|
+
// src/composition/plugin.ts
|
|
989
|
+
var ke = /* @__PURE__ */ new Set([
|
|
990
|
+
"name",
|
|
991
|
+
"configuration",
|
|
992
|
+
"requires",
|
|
993
|
+
"provides",
|
|
994
|
+
"setup"
|
|
995
|
+
]);
|
|
996
|
+
function Ae(e) {
|
|
997
|
+
return L(e);
|
|
998
|
+
}
|
|
999
|
+
function L(e) {
|
|
1000
|
+
let t = g(e, "Plugin declaration", { fields: ke }), { name: n, configuration: r, setup: i } = t;
|
|
1001
|
+
if (typeof n != "string" || !n.trim()) throw TypeError("Plugin name must be a non-empty string");
|
|
1002
|
+
if (n !== n.trim()) throw TypeError("Plugin name cannot start or end with whitespace");
|
|
1003
|
+
if (typeof i != "function") throw TypeError(`Plugin '${n}' must define setup()`);
|
|
1004
|
+
let a = r === void 0 ? void 0 : je(r, n), o = t.requires === void 0 ? void 0 : g(t.requires, `Plugin '${n}' requires`), s = t.provides === void 0 ? void 0 : g(t.provides, `Plugin '${n}' provides`), c = new Ne(n), l = c.normalizeRequirements(o ?? {}), u = c.normalizeProvisions(s ?? {});
|
|
1005
|
+
return Object.freeze({
|
|
1006
|
+
name: n,
|
|
1007
|
+
...a === void 0 ? {} : { configuration: a },
|
|
1008
|
+
requires: l,
|
|
1009
|
+
provides: u,
|
|
1010
|
+
setup: i
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
var R = /* @__PURE__ */ new WeakSet();
|
|
1014
|
+
function je(e, t) {
|
|
1015
|
+
let n = () => /* @__PURE__ */ TypeError("Plugin '" + t + "' configuration must implement Standard Schema V1");
|
|
1016
|
+
if (!e || typeof e != "object" && typeof e != "function") throw n();
|
|
1017
|
+
if (R.has(e)) return e;
|
|
1018
|
+
let r = e["~standard"];
|
|
1019
|
+
if (!r || typeof r != "object") throw n();
|
|
1020
|
+
let { version: i, vendor: a, validate: o, jsonSchema: s } = r;
|
|
1021
|
+
if (i !== 1 || typeof a != "string" || typeof o != "function") throw n();
|
|
1022
|
+
let c = (...e) => Reflect.apply(o, r, e), l = s === void 0 ? void 0 : Me(s, t), u = Object.freeze({ "~standard": Object.freeze({
|
|
1023
|
+
version: 1,
|
|
1024
|
+
vendor: a,
|
|
1025
|
+
validate: c,
|
|
1026
|
+
...l === void 0 ? {} : { jsonSchema: l }
|
|
1027
|
+
}) });
|
|
1028
|
+
return R.add(u), u;
|
|
1029
|
+
}
|
|
1030
|
+
function Me(e, t) {
|
|
1031
|
+
let n = () => /* @__PURE__ */ TypeError("Plugin '" + t + "' jsonSchema must implement Standard JSON Schema input/output exporters");
|
|
1032
|
+
if (!e || typeof e != "object" && typeof e != "function") throw n();
|
|
1033
|
+
let { input: r, output: i } = e;
|
|
1034
|
+
if (typeof r != "function" || typeof i != "function") throw n();
|
|
1035
|
+
return Object.freeze({
|
|
1036
|
+
input: (t) => Reflect.apply(r, e, [t]),
|
|
1037
|
+
output: (t) => Reflect.apply(i, e, [t])
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
var Ne = class {
|
|
1041
|
+
pluginName;
|
|
1042
|
+
#e = /* @__PURE__ */ new Map();
|
|
1043
|
+
constructor(e) {
|
|
1044
|
+
this.pluginName = e;
|
|
1045
|
+
}
|
|
1046
|
+
normalizeRequirements(e) {
|
|
1047
|
+
let t = Object.create(null);
|
|
1048
|
+
for (let [n, r] of Object.entries(e)) {
|
|
1049
|
+
if (this.#t(n, "requirement"), !r || typeof r != "object") throw TypeError(`Plugin requirement '${n}' is not a contract`);
|
|
1050
|
+
let e = T(g(r, `Plugin requirement '${n}'`), `Plugin requirement '${n}' must be a Service or ExtensionPoint`, `Optional requirement '${n}' must wrap a Service`);
|
|
1051
|
+
this.#n("requirement", n, e.kind === "optional" ? e.service : e), t[n] = e;
|
|
1052
|
+
}
|
|
1053
|
+
return Object.freeze(t);
|
|
1054
|
+
}
|
|
1055
|
+
normalizeProvisions(e) {
|
|
1056
|
+
let t = Object.create(null);
|
|
1057
|
+
for (let [n, r] of Object.entries(e)) {
|
|
1058
|
+
if (this.#t(n, "provision"), n === "then") throw TypeError("Plugin provision alias 'then' conflicts with the Promise protocol");
|
|
1059
|
+
let e = w(r, "service", `Plugin provision '${n}' must be a Service`);
|
|
1060
|
+
this.#n("provision", n, e), t[n] = e;
|
|
1061
|
+
}
|
|
1062
|
+
return Object.freeze(t);
|
|
1063
|
+
}
|
|
1064
|
+
#t(e, t) {
|
|
1065
|
+
if (!e.trim()) throw TypeError(`Plugin ${t} alias cannot be empty`);
|
|
1066
|
+
if (e !== e.trim()) throw TypeError(`Plugin ${t} alias cannot start or end with whitespace`);
|
|
1067
|
+
}
|
|
1068
|
+
#n(e, t, n) {
|
|
1069
|
+
let r = this.#e.get(n.id);
|
|
1070
|
+
if (!r) {
|
|
1071
|
+
this.#e.set(n.id, {
|
|
1072
|
+
alias: t,
|
|
1073
|
+
kind: n.kind,
|
|
1074
|
+
role: e
|
|
1075
|
+
});
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (r.kind !== n.kind) throw TypeError(`Plugin '${this.pluginName}' uses Contract '${n.id}' as both ${z(r.kind)} and ${z(n.kind)}`);
|
|
1079
|
+
let i = z(n.kind);
|
|
1080
|
+
throw r.role === e ? TypeError(`Plugin '${this.pluginName}' ${e} aliases '${r.alias}' and '${t}' reference the same ${i} '${n.id}'`) : TypeError(`Plugin '${this.pluginName}' cannot both require and provide ${i} '${n.id}'`);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
function z(e) {
|
|
1084
|
+
return e === "extensionPoint" ? "ExtensionPoint" : e === "event" ? "Event" : "Service";
|
|
1085
|
+
}
|
|
1086
|
+
function B(e) {
|
|
1087
|
+
return L(e);
|
|
1088
|
+
}
|
|
1089
|
+
// src/composition/installation.ts
|
|
1090
|
+
function V(e, t) {
|
|
1091
|
+
if (e.has(t)) throw new l("INSTALLATION_CONFLICT", "Installation id is already installed: " + t);
|
|
1092
|
+
e.add(t);
|
|
1093
|
+
}
|
|
1094
|
+
function H(e, t, n) {
|
|
1095
|
+
return Object.freeze({
|
|
1096
|
+
plugin: B(e),
|
|
1097
|
+
configuration: I(t),
|
|
1098
|
+
origin: U(n)
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
function U(e) {
|
|
1102
|
+
let t = I(e);
|
|
1103
|
+
if (t !== void 0) {
|
|
1104
|
+
if (t === null || Array.isArray(t) || typeof t != "object") throw TypeError("Installation origin must be a data record");
|
|
1105
|
+
return t;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
var W = class {
|
|
1109
|
+
#e = {
|
|
1110
|
+
status: "pending",
|
|
1111
|
+
origin: void 0
|
|
1112
|
+
};
|
|
1113
|
+
attach(e) {
|
|
1114
|
+
let t = this.#e;
|
|
1115
|
+
e.attach(() => t);
|
|
1116
|
+
}
|
|
1117
|
+
retire() {
|
|
1118
|
+
this.#e.status = "removed";
|
|
1119
|
+
}
|
|
1120
|
+
}, Pe = class {
|
|
1121
|
+
id;
|
|
1122
|
+
index;
|
|
1123
|
+
group;
|
|
1124
|
+
facade;
|
|
1125
|
+
#e;
|
|
1126
|
+
#t = Object.freeze({
|
|
1127
|
+
status: "pending",
|
|
1128
|
+
origin: void 0
|
|
1129
|
+
});
|
|
1130
|
+
constructor(e, t, n) {
|
|
1131
|
+
this.id = e, this.index = t, this.group = n;
|
|
1132
|
+
let r = this;
|
|
1133
|
+
this.facade = Object.freeze({
|
|
1134
|
+
id: e,
|
|
1135
|
+
groupId: n?.id,
|
|
1136
|
+
get status() {
|
|
1137
|
+
return r.#n().status;
|
|
1138
|
+
},
|
|
1139
|
+
get origin() {
|
|
1140
|
+
return r.#n().origin;
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
get groupId() {
|
|
1145
|
+
return this.group?.id;
|
|
1146
|
+
}
|
|
1147
|
+
attach(e) {
|
|
1148
|
+
this.#e = e;
|
|
1149
|
+
}
|
|
1150
|
+
detach(e) {
|
|
1151
|
+
this.#t = Object.freeze(e), this.#e = void 0;
|
|
1152
|
+
}
|
|
1153
|
+
#n() {
|
|
1154
|
+
return this.#e?.() ?? this.#t;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
// src/composition/change-set.ts
|
|
1158
|
+
function G(e, t) {
|
|
1159
|
+
if (typeof e != "string" || !e.trim() || e.trim() !== e) throw TypeError(t + " must be a non-empty trimmed string");
|
|
1160
|
+
}
|
|
1161
|
+
var Fe = class {
|
|
1162
|
+
#e = /* @__PURE__ */ new WeakMap();
|
|
1163
|
+
#t = new W();
|
|
1164
|
+
create(e) {
|
|
1165
|
+
let t = new Ie(this);
|
|
1166
|
+
return this.#n().set(t.handle, {
|
|
1167
|
+
port: e,
|
|
1168
|
+
operations: [],
|
|
1169
|
+
targets: /* @__PURE__ */ new Set()
|
|
1170
|
+
}), t.handle;
|
|
1171
|
+
}
|
|
1172
|
+
take(e) {
|
|
1173
|
+
let t = this.#n(), n = t.get(e);
|
|
1174
|
+
if (!n) throw new l("CHANGE_FOREIGN", "ChangeSet belongs to another Host or was already planned");
|
|
1175
|
+
return t.delete(e), Object.freeze(n.operations);
|
|
1176
|
+
}
|
|
1177
|
+
requireOpen(e) {
|
|
1178
|
+
let t = this.#n().get(e);
|
|
1179
|
+
if (!t) throw TypeError("ChangeSet has already been planned");
|
|
1180
|
+
return t;
|
|
1181
|
+
}
|
|
1182
|
+
track(e) {
|
|
1183
|
+
this.#t.attach(e);
|
|
1184
|
+
}
|
|
1185
|
+
close(e) {
|
|
1186
|
+
this.#e = e, this.#t.retire();
|
|
1187
|
+
}
|
|
1188
|
+
#n() {
|
|
1189
|
+
if (typeof this.#e == "number") throw p(this.#e);
|
|
1190
|
+
return this.#e;
|
|
1191
|
+
}
|
|
1192
|
+
}, Ie = class {
|
|
1193
|
+
authority;
|
|
1194
|
+
handle = Object.freeze({
|
|
1195
|
+
install: this.install.bind(this),
|
|
1196
|
+
update: this.update.bind(this),
|
|
1197
|
+
remove: this.remove.bind(this),
|
|
1198
|
+
group: this.group.bind(this),
|
|
1199
|
+
removeGroup: this.removeGroup.bind(this)
|
|
1200
|
+
});
|
|
1201
|
+
constructor(e) {
|
|
1202
|
+
this.authority = e, Object.freeze(this);
|
|
1203
|
+
}
|
|
1204
|
+
install(e, t) {
|
|
1205
|
+
let { port: n } = this.#t(), r = g(t, "Installation options", { fields: /* @__PURE__ */ new Set([
|
|
1206
|
+
"id",
|
|
1207
|
+
"configuration",
|
|
1208
|
+
"origin",
|
|
1209
|
+
"group"
|
|
1210
|
+
]) });
|
|
1211
|
+
G(r.id, "Installation id");
|
|
1212
|
+
let i = r.group === void 0 ? void 0 : n.resolveGroup(r.group), a = H(e, r.configuration, r.origin);
|
|
1213
|
+
this.#t();
|
|
1214
|
+
let o = n.create(r.id, i);
|
|
1215
|
+
return this.#e(o, {
|
|
1216
|
+
kind: "install",
|
|
1217
|
+
installation: o,
|
|
1218
|
+
declaration: a
|
|
1219
|
+
}), o.facade;
|
|
1220
|
+
}
|
|
1221
|
+
update(e, t) {
|
|
1222
|
+
let { port: n } = this.#t(), r = g(t, "Installation update", { fields: /* @__PURE__ */ new Set([
|
|
1223
|
+
"plugin",
|
|
1224
|
+
"configuration",
|
|
1225
|
+
"origin"
|
|
1226
|
+
]) }), i = Object.hasOwn(r, "plugin"), a = Object.hasOwn(r, "configuration");
|
|
1227
|
+
if (!i && !a) throw TypeError("Installation update requires plugin or configuration");
|
|
1228
|
+
if (!i && Object.hasOwn(r, "origin")) throw TypeError("Origin can only change with its Plugin");
|
|
1229
|
+
let o = {
|
|
1230
|
+
...i ? {
|
|
1231
|
+
plugin: B(r.plugin),
|
|
1232
|
+
origin: U(r.origin)
|
|
1233
|
+
} : {},
|
|
1234
|
+
...a ? { configuration: I(r.configuration) } : {}
|
|
1235
|
+
}, s = n.resolve(e);
|
|
1236
|
+
this.#e(s, {
|
|
1237
|
+
kind: "update",
|
|
1238
|
+
installation: s,
|
|
1239
|
+
update: Object.freeze(o)
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
remove(e) {
|
|
1243
|
+
let t = this.#t().port.resolve(e);
|
|
1244
|
+
this.#e(t, {
|
|
1245
|
+
kind: "remove",
|
|
1246
|
+
installation: t
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
group(e, t) {
|
|
1250
|
+
let { port: n } = this.#t();
|
|
1251
|
+
G(e, "Group id");
|
|
1252
|
+
let r = n.createGroup(e, t === void 0 ? void 0 : n.resolveGroup(t));
|
|
1253
|
+
return this.#e(r, {
|
|
1254
|
+
kind: "group",
|
|
1255
|
+
group: r
|
|
1256
|
+
}), r.facade;
|
|
1257
|
+
}
|
|
1258
|
+
removeGroup(e) {
|
|
1259
|
+
let t = this.#t().port.resolveGroup(e);
|
|
1260
|
+
this.#e(t, {
|
|
1261
|
+
kind: "remove-group",
|
|
1262
|
+
group: t
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
#e(e, t) {
|
|
1266
|
+
let { targets: n, operations: r } = this.#t();
|
|
1267
|
+
if (n.has(e)) throw TypeError("A target can appear only once in a ChangeSet");
|
|
1268
|
+
t.kind === "install" && this.authority.track(t.installation), n.add(e), r.push(Object.freeze(t));
|
|
1269
|
+
}
|
|
1270
|
+
#t() {
|
|
1271
|
+
return this.authority.requireOpen(this.handle);
|
|
1272
|
+
}
|
|
1273
|
+
}, K = class e {
|
|
1274
|
+
declarations;
|
|
1275
|
+
byId;
|
|
1276
|
+
order;
|
|
1277
|
+
layers;
|
|
1278
|
+
providers;
|
|
1279
|
+
dependents;
|
|
1280
|
+
contractKinds;
|
|
1281
|
+
constructor(e, t, n, r, i, a, o) {
|
|
1282
|
+
this.declarations = e, this.byId = t, this.order = n, this.layers = r, this.providers = i, this.dependents = a, this.contractKinds = o;
|
|
1283
|
+
}
|
|
1284
|
+
static build(t) {
|
|
1285
|
+
let n = [...t.keys()].sort((e, t) => e.index - t.index), r = /* @__PURE__ */ new Map(), i = Le(t, r), a = Re(t, i, r), { order: o, layers: s } = ze(n, a.dependents, a.indegree);
|
|
1286
|
+
return new e(t, new Map(n.map((e) => [e.id, e])), Object.freeze(o), Object.freeze(s.map((e) => Object.freeze(e))), i, a.dependents, r);
|
|
1287
|
+
}
|
|
1288
|
+
declarationFor(e) {
|
|
1289
|
+
let t = this.declarations.get(e);
|
|
1290
|
+
if (!t) throw Error(`Installation '${e.id}' is not in this plan`);
|
|
1291
|
+
return t;
|
|
1292
|
+
}
|
|
1293
|
+
affectedByTransitionTo(e, t) {
|
|
1294
|
+
let n = /* @__PURE__ */ new Set();
|
|
1295
|
+
return this.#e(t, n), e.#e(t, n), n;
|
|
1296
|
+
}
|
|
1297
|
+
#e(e, t) {
|
|
1298
|
+
let n = [...e], r = /* @__PURE__ */ new Set();
|
|
1299
|
+
for (let e = 0; e < n.length; e++) {
|
|
1300
|
+
let i = n[e];
|
|
1301
|
+
if (i && !r.has(i)) {
|
|
1302
|
+
r.add(i), t.add(i);
|
|
1303
|
+
for (let e of this.dependents.get(i) ?? []) n.push(e);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
function Le(e, t) {
|
|
1309
|
+
let n = /* @__PURE__ */ new Map();
|
|
1310
|
+
for (let [r, i] of e) for (let e of Object.values(i.plugin.provides)) {
|
|
1311
|
+
j(t, e);
|
|
1312
|
+
let i = n.get(e.id);
|
|
1313
|
+
if (i) throw new l("SERVICE_CONFLICT", `Service '${e.id}' is provided by both '${i.id}' and '${r.id}'`, { details: {
|
|
1314
|
+
outcome: "rejected",
|
|
1315
|
+
contract: e.id,
|
|
1316
|
+
affectedInstallations: [i.id, r.id]
|
|
1317
|
+
} });
|
|
1318
|
+
n.set(e.id, r);
|
|
1319
|
+
}
|
|
1320
|
+
return n;
|
|
1321
|
+
}
|
|
1322
|
+
function Re(e, t, n) {
|
|
1323
|
+
let r = /* @__PURE__ */ new Map(), i = new Map([...e.keys()].map((e) => [e, 0]));
|
|
1324
|
+
for (let [a, o] of e) for (let e of Object.values(o.plugin.requires)) {
|
|
1325
|
+
let o = e.kind === "optional" ? e.service : e;
|
|
1326
|
+
if (j(n, o), o.kind === "extensionPoint") continue;
|
|
1327
|
+
let s = t.get(o.id);
|
|
1328
|
+
if (!s) {
|
|
1329
|
+
if (e.kind === "optional") continue;
|
|
1330
|
+
throw new l("SERVICE_MISSING", `Installation '${a.id}' requires missing Service '${o.id}'`, { details: {
|
|
1331
|
+
outcome: "rejected",
|
|
1332
|
+
installation: a.id,
|
|
1333
|
+
contract: o.id
|
|
1334
|
+
} });
|
|
1335
|
+
}
|
|
1336
|
+
if (s === a) throw new l("SERVICE_CYCLE", `Installation '${a.id}' cannot require Service '${o.id}' that it provides`, { details: {
|
|
1337
|
+
outcome: "rejected",
|
|
1338
|
+
installation: a.id,
|
|
1339
|
+
contract: o.id,
|
|
1340
|
+
dependencyPath: [a.id, a.id]
|
|
1341
|
+
} });
|
|
1342
|
+
let c = r.get(s) ?? /* @__PURE__ */ new Set();
|
|
1343
|
+
c.has(a) || (c.add(a), r.set(s, c), i.set(a, (i.get(a) ?? 0) + 1));
|
|
1344
|
+
}
|
|
1345
|
+
return {
|
|
1346
|
+
dependents: r,
|
|
1347
|
+
indegree: i
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
function ze(e, t, n) {
|
|
1351
|
+
let r = e.filter((e) => n.get(e) === 0), i = [], a = [];
|
|
1352
|
+
for (; r.length;) {
|
|
1353
|
+
r.sort((e, t) => e.index - t.index);
|
|
1354
|
+
let e = r;
|
|
1355
|
+
r = [], a.push(e);
|
|
1356
|
+
for (let a of e) {
|
|
1357
|
+
i.push(a);
|
|
1358
|
+
for (let e of t.get(a) ?? []) {
|
|
1359
|
+
let t = (n.get(e) ?? 0) - 1;
|
|
1360
|
+
n.set(e, t), t || r.push(e);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
if (i.length !== e.length) {
|
|
1365
|
+
let e = Be(t, n);
|
|
1366
|
+
throw new l("SERVICE_CYCLE", `Installation dependency cycle: ${e.map((e) => e.id).join(" -> ")}`, { details: {
|
|
1367
|
+
outcome: "rejected",
|
|
1368
|
+
dependencyPath: e.map((e) => e.id)
|
|
1369
|
+
} });
|
|
1370
|
+
}
|
|
1371
|
+
return {
|
|
1372
|
+
order: i,
|
|
1373
|
+
layers: a
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function Be(e, t) {
|
|
1377
|
+
let n = /* @__PURE__ */ new Map();
|
|
1378
|
+
for (let [r, i] of e) if (t.get(r)) for (let e of i) n.set(e, r);
|
|
1379
|
+
let r = n.keys().next().value, i = /* @__PURE__ */ new Map();
|
|
1380
|
+
for (; !i.has(r);) i.set(r, i.size), r = n.get(r);
|
|
1381
|
+
return [...Array.from(i.keys()).slice(i.get(r)), r].reverse();
|
|
1382
|
+
}
|
|
1383
|
+
// src/composition/group.ts
|
|
1384
|
+
var Ve = class {
|
|
1385
|
+
id;
|
|
1386
|
+
parent;
|
|
1387
|
+
facade;
|
|
1388
|
+
constructor(e, t) {
|
|
1389
|
+
this.id = e, this.parent = t, this.facade = Object.freeze({
|
|
1390
|
+
id: e,
|
|
1391
|
+
parentId: t?.id
|
|
1392
|
+
}), Object.freeze(this);
|
|
1393
|
+
}
|
|
1394
|
+
get parentId() {
|
|
1395
|
+
return this.parent?.id;
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
function He(e, t) {
|
|
1399
|
+
let n = /* @__PURE__ */ new Map();
|
|
1400
|
+
for (let r of e.keys()) {
|
|
1401
|
+
let i = /* @__PURE__ */ new Set(), a = r;
|
|
1402
|
+
for (; a !== void 0 && !n.has(a);) {
|
|
1403
|
+
if (!e.has(a)) throw new l("GROUP_MISSING", "Initial Group is missing: " + a);
|
|
1404
|
+
if (i.has(a)) throw new l("GROUP_CYCLE", "Group ownership must be acyclic");
|
|
1405
|
+
i.add(a), a = e.get(a);
|
|
1406
|
+
}
|
|
1407
|
+
let o = a === void 0 ? void 0 : n.get(a);
|
|
1408
|
+
for (let e of [...i].reverse()) o = t(e, o), n.set(e, o);
|
|
1409
|
+
}
|
|
1410
|
+
return n;
|
|
1411
|
+
}
|
|
1412
|
+
// src/composition/plan.ts
|
|
1413
|
+
function q(e, t) {
|
|
1414
|
+
return new l("PLAN_STALE", "Host state changed during or after planning", { details: {
|
|
1415
|
+
outcome: "rejected",
|
|
1416
|
+
expectedRevision: e,
|
|
1417
|
+
stateRevision: t
|
|
1418
|
+
} });
|
|
1419
|
+
}
|
|
1420
|
+
var Ue = class {
|
|
1421
|
+
#e = /* @__PURE__ */ new WeakMap();
|
|
1422
|
+
#t = /* @__PURE__ */ new WeakMap();
|
|
1423
|
+
#n = new W();
|
|
1424
|
+
#r;
|
|
1425
|
+
get validationSignal() {
|
|
1426
|
+
return (this.#r ??= new AbortController()).signal;
|
|
1427
|
+
}
|
|
1428
|
+
issue(e, t) {
|
|
1429
|
+
let { report: n } = e;
|
|
1430
|
+
if (n.baseStateRevision !== t.revision) throw q(n.baseStateRevision, t.revision);
|
|
1431
|
+
let r = Object.freeze({ report: n });
|
|
1432
|
+
for (let n of e.graph.declarations.keys()) t.graph.declarations.has(n) || this.#n.attach(n);
|
|
1433
|
+
return this.#e.set(r, "issued"), this.#t.set(r, e), r;
|
|
1434
|
+
}
|
|
1435
|
+
read(e, t) {
|
|
1436
|
+
let n = this.#e.get(e);
|
|
1437
|
+
if (n === void 0) throw new l("PLAN_FOREIGN", "Plan was not issued by this Host");
|
|
1438
|
+
if (n === "consumed") throw new l("PLAN_CONSUMED", "Plan has already been executed");
|
|
1439
|
+
let r = this.#t.get(e);
|
|
1440
|
+
if (!r) throw this.consume(e), q(e.report.baseStateRevision, t);
|
|
1441
|
+
return r;
|
|
1442
|
+
}
|
|
1443
|
+
consume(e) {
|
|
1444
|
+
this.#e.set(e, "consumed"), this.#t.delete(e);
|
|
1445
|
+
}
|
|
1446
|
+
invalidate(e, t) {
|
|
1447
|
+
this.#r?.abort(t ? p(e) : q(e - 1, e)), this.#r = void 0, this.#n.retire(), this.#n = new W(), this.#t = /* @__PURE__ */ new WeakMap();
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
function J(e, t = e.order) {
|
|
1451
|
+
return Object.freeze(t.flatMap((t) => Object.values(e.declarationFor(t).plugin.requires).flatMap((n) => {
|
|
1452
|
+
if (n.kind === "extensionPoint") return [];
|
|
1453
|
+
let r = n.kind === "optional" ? n.service : n;
|
|
1454
|
+
return [Object.freeze({
|
|
1455
|
+
installation: t.id,
|
|
1456
|
+
contract: r.id,
|
|
1457
|
+
optional: n.kind === "optional",
|
|
1458
|
+
provider: e.providers.get(r.id)?.id
|
|
1459
|
+
})];
|
|
1460
|
+
})));
|
|
1461
|
+
}
|
|
1462
|
+
function We(e, t, n, r) {
|
|
1463
|
+
let i = [];
|
|
1464
|
+
for (let a of n) {
|
|
1465
|
+
let o = r.get(a);
|
|
1466
|
+
if (o) i.push(Object.freeze({
|
|
1467
|
+
installation: a.id,
|
|
1468
|
+
kind: o
|
|
1469
|
+
}));
|
|
1470
|
+
else for (let r of Object.values(t.declarationFor(a).plugin.requires)) {
|
|
1471
|
+
if (r.kind === "extensionPoint") continue;
|
|
1472
|
+
let o = (r.kind === "optional" ? r.service : r).id, s = e.providers.get(o), c = t.providers.get(o);
|
|
1473
|
+
(s && n.has(s) || c && n.has(c)) && i.push(Object.freeze({
|
|
1474
|
+
installation: a.id,
|
|
1475
|
+
kind: "provider_changed",
|
|
1476
|
+
contract: o,
|
|
1477
|
+
...s === void 0 ? {} : { previousProvider: s.id },
|
|
1478
|
+
...c === void 0 ? {} : { provider: c.id }
|
|
1479
|
+
}));
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return Object.freeze(i);
|
|
1483
|
+
}
|
|
1484
|
+
function Y(e) {
|
|
1485
|
+
return e && Object.freeze({
|
|
1486
|
+
pluginName: e.plugin.name,
|
|
1487
|
+
origin: e.origin
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
// src/composition/planner.ts
|
|
1491
|
+
async function X(e, t, n, r, i) {
|
|
1492
|
+
let a = new Map(e.graph.declarations), o = new Map(e.groups), s = new Set(e.graph.byId.keys()), c = /* @__PURE__ */ new Map();
|
|
1493
|
+
for (let e of t) {
|
|
1494
|
+
if (e.kind === "group") {
|
|
1495
|
+
if (o.has(e.group.id)) throw new l("GROUP_CONFLICT", "Group id is already installed: " + e.group.id);
|
|
1496
|
+
o.set(e.group.id, e.group);
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
if (e.kind === "remove-group") continue;
|
|
1500
|
+
let t = e.installation;
|
|
1501
|
+
if (e.kind === "install") V(s, t.id), a.set(t, e.declaration), c.set(t, "installed");
|
|
1502
|
+
else {
|
|
1503
|
+
let n = a.get(t);
|
|
1504
|
+
if (!n) throw new l("INSTALLATION_REMOVED", "Installation is not committed: " + t.id);
|
|
1505
|
+
if (e.kind === "remove") a.delete(t), c.set(t, "removed");
|
|
1506
|
+
else {
|
|
1507
|
+
let r = e.update, i = Object.hasOwn(r, "plugin");
|
|
1508
|
+
a.set(t, Object.freeze({
|
|
1509
|
+
plugin: r.plugin ?? n.plugin,
|
|
1510
|
+
configuration: Object.hasOwn(r, "configuration") ? r.configuration : n.configuration,
|
|
1511
|
+
origin: i ? r.origin : n.origin
|
|
1512
|
+
})), c.set(t, "updated");
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
for (let n of t) {
|
|
1517
|
+
if (n.kind !== "remove-group") continue;
|
|
1518
|
+
if (e.groups.get(n.group.id) !== n.group) throw new l("GROUP_REMOVED", "Group is not committed: " + n.group.id);
|
|
1519
|
+
let t = /* @__PURE__ */ new Set([n.group.id]), r = !0;
|
|
1520
|
+
for (; r;) {
|
|
1521
|
+
r = !1;
|
|
1522
|
+
for (let e of o.values()) e.parentId && t.has(e.parentId) && !t.has(e.id) && (t.add(e.id), r = !0);
|
|
1523
|
+
}
|
|
1524
|
+
for (let [e] of a) if (e.groupId !== void 0 && t.has(e.groupId)) {
|
|
1525
|
+
if (c.has(e)) throw new l("CHANGE_CONFLICT", "Installation change conflicts with Group removal: " + e.id);
|
|
1526
|
+
a.delete(e), c.set(e, "removed");
|
|
1527
|
+
}
|
|
1528
|
+
for (let n of t) {
|
|
1529
|
+
if (!e.groups.has(n)) throw new l("CHANGE_CONFLICT", "Group creation conflicts with ancestor removal: " + n);
|
|
1530
|
+
o.delete(n);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
Ge(o, a);
|
|
1534
|
+
let u = K.build(a);
|
|
1535
|
+
r.assertKinds(u.contractKinds);
|
|
1536
|
+
let d = n === "change" ? e.graph.affectedByTransitionTo(u, [...c.keys()]) : new Set(u.order), f = /* @__PURE__ */ new Map();
|
|
1537
|
+
for (let [t, r] of a) {
|
|
1538
|
+
let a = e.graph.declarations.get(t) === r ? e.configurations.get(t) : void 0;
|
|
1539
|
+
a ? f.set(t, a) : (n === "start" || c.has(t)) && f.set(t, await Ee(r.plugin.configuration, r.configuration, t.id, i));
|
|
1540
|
+
}
|
|
1541
|
+
if (n !== "change") for (let e of d) c.set(e, n);
|
|
1542
|
+
let p = Object.freeze(n === "stop" || n === "change" && e.phase === "stopped" ? [] : u.order.filter((e) => d.has(e)).map((e) => e.id)), m = Object.freeze({
|
|
1543
|
+
baseStateRevision: e.revision,
|
|
1544
|
+
intent: n,
|
|
1545
|
+
operations: Object.freeze(t.map((t) => "installation" in t ? Object.freeze({
|
|
1546
|
+
kind: t.kind,
|
|
1547
|
+
id: t.installation.id,
|
|
1548
|
+
before: Y(e.graph.declarations.get(t.installation)),
|
|
1549
|
+
after: Y(a.get(t.installation))
|
|
1550
|
+
}) : Object.freeze({
|
|
1551
|
+
kind: t.kind,
|
|
1552
|
+
id: t.group.id,
|
|
1553
|
+
parentId: t.group.parentId
|
|
1554
|
+
}))),
|
|
1555
|
+
bindings: Object.freeze({
|
|
1556
|
+
before: J(e.graph),
|
|
1557
|
+
after: J(u)
|
|
1558
|
+
}),
|
|
1559
|
+
affectedInstallations: Object.freeze([...d].map((e) => e.id)),
|
|
1560
|
+
reasons: We(e.graph, u, d, c),
|
|
1561
|
+
stopOrder: Object.freeze(e.phase === "running" ? e.graph.order.filter((e) => d.has(e)).reverse().map((e) => e.id) : []),
|
|
1562
|
+
prepareOrder: p,
|
|
1563
|
+
publishOrder: p,
|
|
1564
|
+
execution: Object.freeze({
|
|
1565
|
+
atomicPublication: !0,
|
|
1566
|
+
externalEffectsRollback: !1
|
|
1567
|
+
})
|
|
1568
|
+
});
|
|
1569
|
+
return Object.freeze({
|
|
1570
|
+
groups: o,
|
|
1571
|
+
graph: u,
|
|
1572
|
+
affected: d,
|
|
1573
|
+
configurations: f,
|
|
1574
|
+
report: m
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
function Ge(e, t) {
|
|
1578
|
+
for (let t of e.values()) {
|
|
1579
|
+
let n = t.parent;
|
|
1580
|
+
if (n && e.get(n.id) !== n) throw new l("GROUP_MISSING", "Group parent is not committed: " + n.id);
|
|
1581
|
+
}
|
|
1582
|
+
for (let n of t.keys()) if (n.group && e.get(n.group.id) !== n.group) throw new l("GROUP_MISSING", "Installation Group is not committed: " + n.group.id);
|
|
1583
|
+
}
|
|
1584
|
+
// src/execution/instance.ts
|
|
1585
|
+
var Ke = class {
|
|
1586
|
+
installation;
|
|
1587
|
+
declaration;
|
|
1588
|
+
generation;
|
|
1589
|
+
environment;
|
|
1590
|
+
lifetime;
|
|
1591
|
+
#e = /* @__PURE__ */ new Map();
|
|
1592
|
+
constructor(e, t, n, r) {
|
|
1593
|
+
this.installation = e, this.declaration = t, this.generation = n, this.environment = r, this.lifetime = new ue({
|
|
1594
|
+
label: e.id + "@" + n,
|
|
1595
|
+
report: r.report,
|
|
1596
|
+
changed: r.changed,
|
|
1597
|
+
parentSignal: r.startupSignal,
|
|
1598
|
+
...r.shutdownTimeoutMilliseconds === void 0 ? {} : { shutdownTimeoutMilliseconds: r.shutdownTimeoutMilliseconds }
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
async prepare(e, t) {
|
|
1602
|
+
let n = this.environment, r = Object.freeze({
|
|
1603
|
+
hostName: n.hostName,
|
|
1604
|
+
installationId: this.installation.id,
|
|
1605
|
+
pluginName: this.declaration.plugin.name,
|
|
1606
|
+
generation: this.generation,
|
|
1607
|
+
groupId: this.installation.groupId
|
|
1608
|
+
}), i = Object.freeze({
|
|
1609
|
+
dependencies: e,
|
|
1610
|
+
lifetime: this.lifetime.handle,
|
|
1611
|
+
events: n.events.scope(this.lifetime, (e) => n.contracts.remember(e)),
|
|
1612
|
+
contributions: n.contributions.scope(this.lifetime, this.installation.id, (e) => n.contracts.remember(e)),
|
|
1613
|
+
metadata: r,
|
|
1614
|
+
logger: this.lifetime.use(new m(n.logger, r)).handle
|
|
1615
|
+
}), { setup: a } = this.declaration.plugin, o = await this.lifetime.prepare(() => a(i, t));
|
|
1616
|
+
AbortSignal.prototype.throwIfAborted.call(this.lifetime.signal);
|
|
1617
|
+
let s = Object.entries(this.declaration.plugin.provides);
|
|
1618
|
+
if (!s.length) {
|
|
1619
|
+
if (o !== void 0) throw new l("PROVIDES_INVALID", "Plugin without provisions must return undefined");
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
let c = g(o, "Provided Services", { fields: new Set(s.map(([e]) => e)) });
|
|
1623
|
+
AbortSignal.prototype.throwIfAborted.call(this.lifetime.signal);
|
|
1624
|
+
for (let [e, t] of s) {
|
|
1625
|
+
if (!Object.hasOwn(c, e)) throw new l("PROVIDES_INVALID", "Plugin did not provide " + e);
|
|
1626
|
+
this.#e.set(t.id, c[e]);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
read(e) {
|
|
1630
|
+
if (!this.#e.has(e)) throw new l("SERVICE_UNAVAILABLE", "Service has not been prepared: " + e);
|
|
1631
|
+
return this.#e.get(e);
|
|
1632
|
+
}
|
|
1633
|
+
use(e, t) {
|
|
1634
|
+
return this.lifetime.borrow(() => t(this.read(e)));
|
|
1635
|
+
}
|
|
1636
|
+
publish() {
|
|
1637
|
+
this.lifetime.detachStartupSignal(), this.lifetime.publish();
|
|
1638
|
+
}
|
|
1639
|
+
async dispose() {
|
|
1640
|
+
try {
|
|
1641
|
+
await this.lifetime.dispose();
|
|
1642
|
+
} finally {
|
|
1643
|
+
this.lifetime.phase === "disposed" && this.#e.clear();
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
}, Z = class {
|
|
1647
|
+
#e = [];
|
|
1648
|
+
#t;
|
|
1649
|
+
constructor(e) {
|
|
1650
|
+
this.#t = e;
|
|
1651
|
+
}
|
|
1652
|
+
add(e) {
|
|
1653
|
+
this.#e ? this.#e.push(e) : this.#t(e);
|
|
1654
|
+
}
|
|
1655
|
+
seal(e) {
|
|
1656
|
+
let t = this.#e;
|
|
1657
|
+
return this.#e = void 0, t?.length ? t.length === 1 ? t[0] : AggregateError(t, "Plugin preparation failed") : e;
|
|
1658
|
+
}
|
|
1659
|
+
}, qe = class {
|
|
1660
|
+
name;
|
|
1661
|
+
#e;
|
|
1662
|
+
#t;
|
|
1663
|
+
#n;
|
|
1664
|
+
#r = new fe();
|
|
1665
|
+
#i = new ge();
|
|
1666
|
+
#a;
|
|
1667
|
+
#o = new d();
|
|
1668
|
+
#s = new Ue();
|
|
1669
|
+
#c = new Fe();
|
|
1670
|
+
#l = /* @__PURE__ */ new WeakMap();
|
|
1671
|
+
#u = /* @__PURE__ */ new WeakMap();
|
|
1672
|
+
#d;
|
|
1673
|
+
#f;
|
|
1674
|
+
#p;
|
|
1675
|
+
#m = 0;
|
|
1676
|
+
#h = 0;
|
|
1677
|
+
constructor(e = {}) {
|
|
1678
|
+
let t = g(e, "Host options", { fields: /* @__PURE__ */ new Set([
|
|
1679
|
+
"name",
|
|
1680
|
+
"installations",
|
|
1681
|
+
"groups",
|
|
1682
|
+
"logger",
|
|
1683
|
+
"onError",
|
|
1684
|
+
"shutdownTimeoutMilliseconds"
|
|
1685
|
+
]) }), n = t.name === void 0 ? "host" : t.name;
|
|
1686
|
+
if (G(n, "Host name"), this.name = n, t.onError !== void 0 && typeof t.onError != "function") throw TypeError("Host onError must be a function");
|
|
1687
|
+
this.#e = c(t.logger === void 0 ? console : t.logger), this.#t = t.onError ?? ((e) => this.#e.error(e)), this.#n = A(t.shutdownTimeoutMilliseconds), this.#a = new xe((e) => this.#L(e));
|
|
1688
|
+
let r = /* @__PURE__ */ new Map(), i = u(t.groups === void 0 ? [] : t.groups, "Initial Groups"), a = u(t.installations === void 0 ? [] : t.installations, "Initial Installations"), o = /* @__PURE__ */ new Map();
|
|
1689
|
+
for (let e of i) {
|
|
1690
|
+
let t = g(e, "Initial Group", { fields: /* @__PURE__ */ new Set(["id", "parentId"]) });
|
|
1691
|
+
if (G(t.id, "Group id"), t.parentId !== void 0 && G(t.parentId, "Parent Group id"), o.has(t.id)) throw new l("GROUP_CONFLICT", "Duplicate initial Group: " + t.id);
|
|
1692
|
+
o.set(t.id, t.parentId);
|
|
1693
|
+
}
|
|
1694
|
+
let s = He(o, (e, t) => this.#j(e, t)), d = /* @__PURE__ */ new Set();
|
|
1695
|
+
for (let e of a) {
|
|
1696
|
+
let t = g(e, "Initial Installation", { fields: /* @__PURE__ */ new Set([
|
|
1697
|
+
"id",
|
|
1698
|
+
"plugin",
|
|
1699
|
+
"configuration",
|
|
1700
|
+
"origin",
|
|
1701
|
+
"groupId"
|
|
1702
|
+
]) });
|
|
1703
|
+
G(t.id, "Installation id"), t.groupId !== void 0 && G(t.groupId, "Installation Group id"), V(d, t.id);
|
|
1704
|
+
let n = t.groupId === void 0 ? void 0 : s.get(t.groupId);
|
|
1705
|
+
if (t.groupId !== void 0 && !n) throw new l("GROUP_MISSING", "Initial Group is missing: " + t.groupId);
|
|
1706
|
+
let i = this.#O(t.id, n);
|
|
1707
|
+
r.set(i, H(t.plugin, t.configuration, t.origin));
|
|
1708
|
+
}
|
|
1709
|
+
this.#f = Object.freeze({
|
|
1710
|
+
revision: 0,
|
|
1711
|
+
groups: s,
|
|
1712
|
+
graph: K.build(r),
|
|
1713
|
+
configurations: /* @__PURE__ */ new Map(),
|
|
1714
|
+
phase: "stopped",
|
|
1715
|
+
instances: /* @__PURE__ */ new Map(),
|
|
1716
|
+
unresolved: Object.freeze([]),
|
|
1717
|
+
error: void 0
|
|
1718
|
+
}), this.#d = new f(() => this.#F(), (e) => this.#L(e)), this.#r.commit(this.#f.graph.contractKinds);
|
|
1719
|
+
for (let e of r.keys()) this.#k(e);
|
|
1720
|
+
Object.freeze(this);
|
|
1721
|
+
}
|
|
1722
|
+
get status() {
|
|
1723
|
+
return this.#p?.phase ?? this.#f.phase;
|
|
1724
|
+
}
|
|
1725
|
+
get stateRevision() {
|
|
1726
|
+
return this.#f.revision;
|
|
1727
|
+
}
|
|
1728
|
+
get diagnostics() {
|
|
1729
|
+
return this.#d.view;
|
|
1730
|
+
}
|
|
1731
|
+
installation(e) {
|
|
1732
|
+
return this.#f.graph.byId.get(e)?.facade;
|
|
1733
|
+
}
|
|
1734
|
+
group(e) {
|
|
1735
|
+
return this.#f.groups.get(e)?.facade;
|
|
1736
|
+
}
|
|
1737
|
+
explain(e) {
|
|
1738
|
+
let { graph: t } = this.#f, n = t.byId.get(e);
|
|
1739
|
+
return J(t, n ? [n] : []);
|
|
1740
|
+
}
|
|
1741
|
+
change() {
|
|
1742
|
+
return this.#E(), this.#c.create({
|
|
1743
|
+
create: (e, t) => this.#O(e, t),
|
|
1744
|
+
resolve: (e) => this.#M(e),
|
|
1745
|
+
createGroup: (e, t) => this.#j(e, t),
|
|
1746
|
+
resolveGroup: (e) => {
|
|
1747
|
+
let t = this.#u.get(e);
|
|
1748
|
+
if (!t) throw new l("GROUP_FOREIGN", "Group belongs to another Host");
|
|
1749
|
+
return t;
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
async plan(t, n) {
|
|
1754
|
+
this.#E();
|
|
1755
|
+
let r = this.#c.take(t), i = this.#s.validationSignal, a, o;
|
|
1756
|
+
try {
|
|
1757
|
+
if (n !== void 0) {
|
|
1758
|
+
let t = new AbortController(), r = (e) => t.abort(e);
|
|
1759
|
+
o = e(i, r), a = e(n, r), i = t.signal, i.throwIfAborted();
|
|
1760
|
+
}
|
|
1761
|
+
let t = await X(this.#f, r, "change", this.#r, i);
|
|
1762
|
+
return i.throwIfAborted(), this.#r.assertKinds(t.graph.contractKinds), this.#s.issue(t, this.#f);
|
|
1763
|
+
} catch (e) {
|
|
1764
|
+
throw this.#N(r), e;
|
|
1765
|
+
} finally {
|
|
1766
|
+
o?.(), a?.();
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
apply(e) {
|
|
1770
|
+
return this.#p ? Promise.reject(this.#D()) : this.#o.run(() => this.#_(e));
|
|
1771
|
+
}
|
|
1772
|
+
start() {
|
|
1773
|
+
return this.#g("start");
|
|
1774
|
+
}
|
|
1775
|
+
stop() {
|
|
1776
|
+
return this.#g("stop");
|
|
1777
|
+
}
|
|
1778
|
+
use(e, t) {
|
|
1779
|
+
try {
|
|
1780
|
+
if (typeof t != "function") throw TypeError("Service callback must be a function");
|
|
1781
|
+
let n = T(e);
|
|
1782
|
+
if (n.kind === "extensionPoint") throw TypeError("Expected a Service");
|
|
1783
|
+
let r = n.kind === "optional" ? n.service : n;
|
|
1784
|
+
if (this.#r.assertCompatible(r), this.#E(), this.#f.phase !== "running") throw new l("SERVICE_UNAVAILABLE", "Host is not running");
|
|
1785
|
+
let i = this.#f.graph.providers.get(r.id);
|
|
1786
|
+
if (!i) {
|
|
1787
|
+
if (n.kind === "optional") return Promise.resolve(t(void 0));
|
|
1788
|
+
throw new l("SERVICE_UNAVAILABLE", "No provider for " + r.id);
|
|
1789
|
+
}
|
|
1790
|
+
if (this.#p?.affected.has(i)) throw new l("SERVICE_UNAVAILABLE", "Service is changing: " + r.id);
|
|
1791
|
+
let a = this.#f.instances.get(i);
|
|
1792
|
+
if (!a) throw new l("SERVICE_UNAVAILABLE", "Service is not running: " + r.id);
|
|
1793
|
+
return a.use(r.id, t);
|
|
1794
|
+
} catch (e) {
|
|
1795
|
+
return Promise.reject(e);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
contributions(e) {
|
|
1799
|
+
let t = w(e, "extensionPoint");
|
|
1800
|
+
return this.#r.remember(t), this.#a.view(t);
|
|
1801
|
+
}
|
|
1802
|
+
#g(e) {
|
|
1803
|
+
return this.#p ? Promise.reject(this.#D()) : this.#o.run(async () => {
|
|
1804
|
+
if (this.#E(), e === "start" && this.#f.phase === "running" || e === "stop" && this.#f.phase === "stopped") return this.#T([]);
|
|
1805
|
+
e === "start" && (this.#p = {
|
|
1806
|
+
phase: "starting",
|
|
1807
|
+
affected: new Set(this.#f.graph.declarations.keys())
|
|
1808
|
+
}, this.#I());
|
|
1809
|
+
try {
|
|
1810
|
+
let t = await X(this.#f, [], e, this.#r);
|
|
1811
|
+
return await this.#_(this.#s.issue(t, this.#f));
|
|
1812
|
+
} finally {
|
|
1813
|
+
this.#p && (this.#p = void 0, this.#I());
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
async #_(e) {
|
|
1818
|
+
this.#E();
|
|
1819
|
+
let t = this.#s.read(e, this.#f.revision);
|
|
1820
|
+
if (t.report.intent === "change" && t.report.operations.length === 0) return this.#s.consume(e), this.#T([]);
|
|
1821
|
+
let n = this.#f, r = n.graph.order.filter((e) => t.affected.has(e)).flatMap((e) => n.instances.get(e) ?? []);
|
|
1822
|
+
for (let e of r) if (e.lifetime.busy) throw new l("HOST_BUSY", "Affected work is still in flight", { details: {
|
|
1823
|
+
outcome: "rejected",
|
|
1824
|
+
installation: e.installation.id,
|
|
1825
|
+
stateRevision: n.revision
|
|
1826
|
+
} });
|
|
1827
|
+
this.#s.consume(e);
|
|
1828
|
+
let i;
|
|
1829
|
+
try {
|
|
1830
|
+
i = this.#r.writer(t.graph.contractKinds);
|
|
1831
|
+
} catch (e) {
|
|
1832
|
+
throw this.#A(t.graph.declarations.keys()), e;
|
|
1833
|
+
}
|
|
1834
|
+
for (let e of r) e.lifetime.seal();
|
|
1835
|
+
this.#p = {
|
|
1836
|
+
phase: t.report.intent === "start" ? "starting" : t.report.intent === "stop" ? "stopping" : "changing",
|
|
1837
|
+
affected: t.affected
|
|
1838
|
+
}, this.#a.beginBatch(), this.#I();
|
|
1839
|
+
try {
|
|
1840
|
+
if (n.phase === "stopped" && t.report.intent !== "start") return i.commit(), this.#b(t, /* @__PURE__ */ new Map(), "stopped"), this.#T(t.report.affectedInstallations);
|
|
1841
|
+
let e = await this.#C([n], new Set(r));
|
|
1842
|
+
if (e.length || r.some((e) => e.lifetime.phase !== "disposed")) throw i.discard(), await this.#S(n, [], e, t, "stop");
|
|
1843
|
+
if (t.report.intent === "stop") return i.commit(), this.#b(t, /* @__PURE__ */ new Map(), "stopped"), this.#T(t.report.affectedInstallations);
|
|
1844
|
+
let a = new Map(n.instances);
|
|
1845
|
+
for (let e of t.affected) a.delete(e);
|
|
1846
|
+
let o = /* @__PURE__ */ new Map(), s = new Z((e) => this.#L(e));
|
|
1847
|
+
try {
|
|
1848
|
+
await this.#v(t, a, o, i, s);
|
|
1849
|
+
for (let e of o.values()) AbortSignal.prototype.throwIfAborted.call(e.lifetime.signal);
|
|
1850
|
+
i.commit(), s.seal();
|
|
1851
|
+
} catch (e) {
|
|
1852
|
+
i.discard();
|
|
1853
|
+
let r = {
|
|
1854
|
+
graph: t.graph,
|
|
1855
|
+
instances: new Map([...a, ...o])
|
|
1856
|
+
}, c = await this.#C([r], new Set(o.values())), l = s.seal(e);
|
|
1857
|
+
throw c.length || [...o.values()].some((e) => e.lifetime.phase !== "disposed") ? await this.#S(n, [r], [l, ...c], t, "prepare") : n.phase === "stopped" ? (this.#x({
|
|
1858
|
+
...n,
|
|
1859
|
+
error: new _(l).snapshot
|
|
1860
|
+
}), this.#w("TRANSITION_FAILED", "Startup failed", l, "restored", t, "prepare")) : (await this.#y(n, a, t, l), this.#w("TRANSITION_FAILED", "Change failed; previous declarations were restored", l, "restored", t, "prepare"));
|
|
1861
|
+
}
|
|
1862
|
+
for (let [e, t] of o) a.set(e, t);
|
|
1863
|
+
try {
|
|
1864
|
+
this.#b(t, a, "running", o);
|
|
1865
|
+
} catch (e) {
|
|
1866
|
+
throw i.discard(), await this.#S(this.#f, [{
|
|
1867
|
+
graph: t.graph,
|
|
1868
|
+
instances: new Map(a)
|
|
1869
|
+
}], [e], t, "publish");
|
|
1870
|
+
}
|
|
1871
|
+
return this.#T(t.report.affectedInstallations);
|
|
1872
|
+
} finally {
|
|
1873
|
+
this.#p = void 0, this.#A(t.graph.declarations.keys()), h(() => {
|
|
1874
|
+
this.#a.endBatch(), this.#I();
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
async #v(e, t, n, r, i) {
|
|
1879
|
+
let a = new AbortController(), o = ++this.#h;
|
|
1880
|
+
for (let s of e.graph.layers) {
|
|
1881
|
+
let c = s.filter((t) => e.affected.has(t)).map((t) => {
|
|
1882
|
+
let i = new Ke(t, e.graph.declarationFor(t), o, {
|
|
1883
|
+
hostName: this.name,
|
|
1884
|
+
logger: this.#e,
|
|
1885
|
+
report: (e) => this.#L(e),
|
|
1886
|
+
changed: () => {
|
|
1887
|
+
(this.#f.instances.get(t) === i || this.#f.unresolved.includes(i)) && this.#I();
|
|
1888
|
+
},
|
|
1889
|
+
events: this.#i,
|
|
1890
|
+
contributions: this.#a,
|
|
1891
|
+
contracts: r,
|
|
1892
|
+
startupSignal: a.signal,
|
|
1893
|
+
shutdownTimeoutMilliseconds: this.#n
|
|
1894
|
+
});
|
|
1895
|
+
return n.set(t, i), i;
|
|
1896
|
+
});
|
|
1897
|
+
try {
|
|
1898
|
+
await Promise.all(c.map(async (r) => {
|
|
1899
|
+
let o = Object.create(null);
|
|
1900
|
+
for (let [i, a] of Object.entries(r.declaration.plugin.requires)) {
|
|
1901
|
+
if (a.kind === "extensionPoint") {
|
|
1902
|
+
o[i] = this.#a.view(a, r.lifetime);
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
let s = a.kind === "optional" ? a.service : a, c = e.graph.providers.get(s.id);
|
|
1906
|
+
o[i] = c ? (n.get(c) ?? t.get(c))?.read(s.id) : void 0;
|
|
1907
|
+
}
|
|
1908
|
+
try {
|
|
1909
|
+
await r.prepare(Object.freeze(o), e.configurations.get(r.installation)?.value);
|
|
1910
|
+
} catch (e) {
|
|
1911
|
+
throw a.signal.aborted && Object.is(e, a.signal.reason) || i.add(e), a.abort(e), e;
|
|
1912
|
+
}
|
|
1913
|
+
}));
|
|
1914
|
+
} catch (e) {
|
|
1915
|
+
throw a.abort(e), e;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
async #y(e, t, n, r) {
|
|
1920
|
+
let i = /* @__PURE__ */ new Map(), a = new Z((e) => this.#L(e)), o = this.#r.writer(e.graph.contractKinds);
|
|
1921
|
+
try {
|
|
1922
|
+
await this.#v({
|
|
1923
|
+
graph: e.graph,
|
|
1924
|
+
affected: n.affected,
|
|
1925
|
+
configurations: e.configurations
|
|
1926
|
+
}, t, i, o, a);
|
|
1927
|
+
for (let e of i.values()) AbortSignal.prototype.throwIfAborted.call(e.lifetime.signal);
|
|
1928
|
+
a.seal();
|
|
1929
|
+
for (let [e, n] of i) t.set(e, n);
|
|
1930
|
+
o.commit(), this.#x({
|
|
1931
|
+
...e,
|
|
1932
|
+
instances: t,
|
|
1933
|
+
error: new _(r).snapshot
|
|
1934
|
+
});
|
|
1935
|
+
for (let e of i.values()) e.publish();
|
|
1936
|
+
} catch (s) {
|
|
1937
|
+
o.discard();
|
|
1938
|
+
let c = {
|
|
1939
|
+
graph: e.graph,
|
|
1940
|
+
instances: new Map([...t, ...i])
|
|
1941
|
+
}, l = await this.#C([c], new Set(i.values()));
|
|
1942
|
+
throw await this.#S(e, [c], [
|
|
1943
|
+
r,
|
|
1944
|
+
a.seal(s),
|
|
1945
|
+
...l
|
|
1946
|
+
], n, "restore");
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
#b(e, t, n, r = /* @__PURE__ */ new Map()) {
|
|
1950
|
+
let i = this.#f;
|
|
1951
|
+
this.#x({
|
|
1952
|
+
groups: e.groups,
|
|
1953
|
+
graph: e.graph,
|
|
1954
|
+
configurations: e.configurations,
|
|
1955
|
+
phase: n,
|
|
1956
|
+
instances: t,
|
|
1957
|
+
unresolved: Object.freeze([]),
|
|
1958
|
+
error: void 0
|
|
1959
|
+
});
|
|
1960
|
+
for (let t of e.graph.declarations.keys()) i.graph.declarations.has(t) || this.#k(t);
|
|
1961
|
+
for (let t of i.graph.declarations.keys()) e.graph.declarations.has(t) || t.detach({
|
|
1962
|
+
status: "removed",
|
|
1963
|
+
origin: void 0
|
|
1964
|
+
});
|
|
1965
|
+
for (let e of r.values()) e.publish();
|
|
1966
|
+
}
|
|
1967
|
+
#x(e) {
|
|
1968
|
+
this.#f = Object.freeze({
|
|
1969
|
+
...e,
|
|
1970
|
+
revision: this.#f.revision + 1
|
|
1971
|
+
});
|
|
1972
|
+
let t = e.phase === "quarantined";
|
|
1973
|
+
if (this.#s.invalidate(this.#f.revision, t), t) {
|
|
1974
|
+
this.#c.close(this.#f.revision);
|
|
1975
|
+
for (let [t, n] of e.graph.declarations) t.detach({
|
|
1976
|
+
status: "quarantined",
|
|
1977
|
+
origin: n.origin
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
async #S(e, t, n, r, i) {
|
|
1982
|
+
let a = [e, ...t], o = [...new Set(a.flatMap((e) => [...e.instances.values()]))].filter((e) => e.lifetime.phase !== "disposed");
|
|
1983
|
+
for (let e of o) e.lifetime.block();
|
|
1984
|
+
this.#p &&= {
|
|
1985
|
+
...this.#p,
|
|
1986
|
+
affected: /* @__PURE__ */ new Set([...this.#p.affected, ...o.map((e) => e.installation)])
|
|
1987
|
+
};
|
|
1988
|
+
let s = await this.#C(a, new Set(o)), c = o.filter((e) => e.lifetime.phase !== "disposed"), l = AggregateError([...n, ...s], "Execution could not establish a healthy state");
|
|
1989
|
+
return this.#x({
|
|
1990
|
+
...e,
|
|
1991
|
+
phase: "quarantined",
|
|
1992
|
+
instances: /* @__PURE__ */ new Map(),
|
|
1993
|
+
unresolved: Object.freeze(c),
|
|
1994
|
+
error: new _(l).snapshot
|
|
1995
|
+
}), this.#w("HOST_QUARANTINED", "Host is quarantined after execution could not establish a healthy state", l, "quarantined", r, i);
|
|
1996
|
+
}
|
|
1997
|
+
async #C(e, t) {
|
|
1998
|
+
let n = /* @__PURE__ */ new Map();
|
|
1999
|
+
for (let { graph: t, instances: r } of e) for (let [e, i] of t.dependents) {
|
|
2000
|
+
let t = r.get(e);
|
|
2001
|
+
if (!t) continue;
|
|
2002
|
+
let a = n.get(t) ?? /* @__PURE__ */ new Set();
|
|
2003
|
+
for (let e of i) {
|
|
2004
|
+
let t = r.get(e);
|
|
2005
|
+
t && a.add(t);
|
|
2006
|
+
}
|
|
2007
|
+
n.set(t, a);
|
|
2008
|
+
}
|
|
2009
|
+
let r = /* @__PURE__ */ new Map();
|
|
2010
|
+
for (let e of [...t].reverse()) r.set(e, Promise.resolve().then(async () => {
|
|
2011
|
+
let t = [...n.get(e) ?? []];
|
|
2012
|
+
await Promise.allSettled(t.map((e) => r.get(e))), !(t.some((e) => e.lifetime.phase !== "disposed") || e.lifetime.busy || e.lifetime.phase === "disposed" || e.lifetime.phase === "quarantined") && await e.dispose();
|
|
2013
|
+
}));
|
|
2014
|
+
return (await Promise.allSettled(r.values())).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
2015
|
+
}
|
|
2016
|
+
#w(e, t, n, r, i, a) {
|
|
2017
|
+
return new l(e, t, {
|
|
2018
|
+
cause: n,
|
|
2019
|
+
details: {
|
|
2020
|
+
outcome: r,
|
|
2021
|
+
phase: a,
|
|
2022
|
+
stateRevision: this.#f.revision,
|
|
2023
|
+
affectedInstallations: i.report.affectedInstallations
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
#T(e) {
|
|
2028
|
+
return Object.freeze({
|
|
2029
|
+
stateRevision: this.#f.revision,
|
|
2030
|
+
affectedInstallations: Object.freeze([...e])
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
#E() {
|
|
2034
|
+
if (this.#f.phase === "quarantined") throw p(this.#f.revision);
|
|
2035
|
+
}
|
|
2036
|
+
#D() {
|
|
2037
|
+
return new l("HOST_BUSY", "Another Host transition is in progress", { details: {
|
|
2038
|
+
outcome: "rejected",
|
|
2039
|
+
stateRevision: this.#f.revision
|
|
2040
|
+
} });
|
|
2041
|
+
}
|
|
2042
|
+
#O(e, t) {
|
|
2043
|
+
let n = new Pe(e, ++this.#m, t);
|
|
2044
|
+
return this.#l.set(n.facade, n), n;
|
|
2045
|
+
}
|
|
2046
|
+
#k(e) {
|
|
2047
|
+
e.attach(() => ({
|
|
2048
|
+
status: this.#P(e),
|
|
2049
|
+
origin: this.#f.graph.declarations.get(e)?.origin
|
|
2050
|
+
}));
|
|
2051
|
+
}
|
|
2052
|
+
#A(e) {
|
|
2053
|
+
for (let t of e) this.#f.graph.declarations.has(t) || t.detach({
|
|
2054
|
+
status: "removed",
|
|
2055
|
+
origin: void 0
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
#j(e, t) {
|
|
2059
|
+
let n = new Ve(e, t);
|
|
2060
|
+
return this.#u.set(n.facade, n), n;
|
|
2061
|
+
}
|
|
2062
|
+
#M(e) {
|
|
2063
|
+
let t = this.#l.get(e);
|
|
2064
|
+
if (!t) throw new l("INSTALLATION_FOREIGN", "Installation belongs to another Host");
|
|
2065
|
+
return t;
|
|
2066
|
+
}
|
|
2067
|
+
#N(e) {
|
|
2068
|
+
this.#A(e.flatMap((e) => e.kind === "install" ? [e.installation] : []));
|
|
2069
|
+
}
|
|
2070
|
+
#P(e) {
|
|
2071
|
+
return this.#f.graph.declarations.has(e) ? this.#f.phase === "quarantined" ? "quarantined" : this.#p?.affected.has(e) ? "changing" : this.#f.instances.has(e) ? "running" : "stopped" : "pending";
|
|
2072
|
+
}
|
|
2073
|
+
#F() {
|
|
2074
|
+
let e = [...this.#f.graph.declarations].map(([e, t]) => {
|
|
2075
|
+
let n = this.#f.instances.get(e);
|
|
2076
|
+
return Object.freeze({
|
|
2077
|
+
id: e.id,
|
|
2078
|
+
groupId: e.groupId,
|
|
2079
|
+
pluginName: t.plugin.name,
|
|
2080
|
+
status: this.#P(e),
|
|
2081
|
+
origin: t.origin,
|
|
2082
|
+
generation: n?.generation,
|
|
2083
|
+
requires: Object.freeze(Object.values(t.plugin.requires).map((e) => e.kind === "optional" ? e.service.id : e.id)),
|
|
2084
|
+
provides: Object.freeze(Object.values(t.plugin.provides).map((e) => e.id)),
|
|
2085
|
+
lifetime: n?.lifetime.snapshot()
|
|
2086
|
+
});
|
|
2087
|
+
}), t = Map.groupBy(e, (e) => e.groupId);
|
|
2088
|
+
return Object.freeze({
|
|
2089
|
+
name: this.name,
|
|
2090
|
+
status: this.status,
|
|
2091
|
+
stateRevision: this.#f.revision,
|
|
2092
|
+
installations: Object.freeze(e),
|
|
2093
|
+
groups: Object.freeze([...this.#f.groups.values()].map((e) => Object.freeze({
|
|
2094
|
+
id: e.id,
|
|
2095
|
+
parentId: e.parentId,
|
|
2096
|
+
installations: Object.freeze((t.get(e.id) ?? []).map((e) => e.id))
|
|
2097
|
+
}))),
|
|
2098
|
+
bindings: J(this.#f.graph),
|
|
2099
|
+
unresolved: Object.freeze(this.#f.unresolved.map((e) => Object.freeze({
|
|
2100
|
+
installation: e.installation.id,
|
|
2101
|
+
generation: e.generation,
|
|
2102
|
+
lifetime: e.lifetime.snapshot()
|
|
2103
|
+
}))),
|
|
2104
|
+
error: this.#f.error
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
#I() {
|
|
2108
|
+
this.#f.unresolved.some((e) => e.lifetime.phase === "disposed") && (this.#f = Object.freeze({
|
|
2109
|
+
...this.#f,
|
|
2110
|
+
unresolved: Object.freeze(this.#f.unresolved.filter((e) => e.lifetime.phase !== "disposed"))
|
|
2111
|
+
}));
|
|
2112
|
+
try {
|
|
2113
|
+
this.#d.invalidate();
|
|
2114
|
+
} catch (e) {
|
|
2115
|
+
this.#L(e);
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
#L(e) {
|
|
2119
|
+
let t = this.#e, n = (n) => {
|
|
2120
|
+
try {
|
|
2121
|
+
Promise.resolve(t.error(AggregateError([e, n], "Host error reporter failed"))).catch(() => void 0);
|
|
2122
|
+
} catch {}
|
|
2123
|
+
};
|
|
2124
|
+
try {
|
|
2125
|
+
let t = this.#t;
|
|
2126
|
+
Promise.resolve(t(e)).catch(n);
|
|
2127
|
+
} catch (e) {
|
|
2128
|
+
n(e);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
// src/execution/host.ts
|
|
2133
|
+
function Je(e) {
|
|
2134
|
+
let t = new qe(e);
|
|
2135
|
+
return Object.freeze({
|
|
2136
|
+
get name() {
|
|
2137
|
+
return t.name;
|
|
2138
|
+
},
|
|
2139
|
+
get status() {
|
|
2140
|
+
return t.status;
|
|
2141
|
+
},
|
|
2142
|
+
get stateRevision() {
|
|
2143
|
+
return t.stateRevision;
|
|
2144
|
+
},
|
|
2145
|
+
get diagnostics() {
|
|
2146
|
+
return t.diagnostics;
|
|
2147
|
+
},
|
|
2148
|
+
change: () => t.change(),
|
|
2149
|
+
plan: t.plan.bind(t),
|
|
2150
|
+
apply: t.apply.bind(t),
|
|
2151
|
+
start: () => t.start(),
|
|
2152
|
+
stop: () => t.stop(),
|
|
2153
|
+
use: t.use.bind(t),
|
|
2154
|
+
contributions: t.contributions.bind(t),
|
|
2155
|
+
installation: t.installation.bind(t),
|
|
2156
|
+
group: t.group.bind(t),
|
|
2157
|
+
explain: t.explain.bind(t),
|
|
2158
|
+
[y]: async () => {
|
|
2159
|
+
await t.stop();
|
|
2160
|
+
}
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
// src/composition/plugin-description.ts
|
|
2164
|
+
var Ye = /* @__PURE__ */ new Set(["jsonSchemaTarget"]);
|
|
2165
|
+
function Q(e, t = {}) {
|
|
2166
|
+
let n = g(t, "Plugin description options", { fields: Ye }), r = n.jsonSchemaTarget === void 0 ? "draft-2020-12" : n.jsonSchemaTarget;
|
|
2167
|
+
if (typeof r != "string" || !r || r.trim() !== r) throw TypeError("JSON Schema target must be a non-empty trimmed string");
|
|
2168
|
+
let i = B(e), a = i.configuration?.["~standard"], o;
|
|
2169
|
+
if (!a) o = Object.freeze({ status: "none" });
|
|
2170
|
+
else if (!a.jsonSchema) o = Object.freeze({
|
|
2171
|
+
status: "unavailable",
|
|
2172
|
+
vendor: a.vendor
|
|
2173
|
+
});
|
|
2174
|
+
else {
|
|
2175
|
+
let e = Object.freeze({ target: r });
|
|
2176
|
+
o = Object.freeze({
|
|
2177
|
+
status: "available",
|
|
2178
|
+
vendor: a.vendor,
|
|
2179
|
+
target: r,
|
|
2180
|
+
input: $(a.jsonSchema.input(e)),
|
|
2181
|
+
output: $(a.jsonSchema.output(e))
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
return Object.freeze({
|
|
2185
|
+
name: i.name,
|
|
2186
|
+
requires: Object.freeze(Object.entries(i.requires).map(([e, t]) => {
|
|
2187
|
+
let n = t.kind === "optional" ? t.service : t;
|
|
2188
|
+
return Object.freeze({
|
|
2189
|
+
alias: e,
|
|
2190
|
+
id: n.id,
|
|
2191
|
+
kind: n.kind,
|
|
2192
|
+
optional: t.kind === "optional"
|
|
2193
|
+
});
|
|
2194
|
+
})),
|
|
2195
|
+
provides: Object.freeze(Object.entries(i.provides).map(([e, t]) => Object.freeze({
|
|
2196
|
+
alias: e,
|
|
2197
|
+
id: t.id
|
|
2198
|
+
}))),
|
|
2199
|
+
configuration: o
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
function $(e) {
|
|
2203
|
+
v(e, "JSON Schema exporters must be synchronous");
|
|
2204
|
+
let t = I(e);
|
|
2205
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw TypeError("JSON Schema exporters must return a plain data record");
|
|
2206
|
+
return t;
|
|
2207
|
+
}
|
|
2208
|
+
export { r as ConfigurationValidationError, l as DougongError, _ as RecordedFailure, y as asyncDisposeSymbol, I as captureConfiguration, Je as createHost, Ae as definePlugin, Q as describePlugin, n as disposeSymbol, re as event, ie as extensionPoint, i as isCancellationReason, a as isError, t as isLogger, ae as optional, ne as service };
|