dougong 0.8.3 → 0.10.0

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