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