@dougongjs/core 0.0.2 → 0.1.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 (66) hide show
  1. package/README.md +97 -10
  2. package/dist/change-set.d.ts +27 -27
  3. package/dist/change-set.d.ts.map +1 -1
  4. package/dist/configuration.d.ts +4 -0
  5. package/dist/configuration.d.ts.map +1 -0
  6. package/dist/contract-registry.d.ts +1 -1
  7. package/dist/contract-registry.d.ts.map +1 -1
  8. package/dist/contracts.d.ts +6 -5
  9. package/dist/contracts.d.ts.map +1 -1
  10. package/dist/{extension-store.d.ts → contribution-store.d.ts} +14 -15
  11. package/dist/contribution-store.d.ts.map +1 -0
  12. package/dist/diagnostics.d.ts +13 -12
  13. package/dist/diagnostics.d.ts.map +1 -1
  14. package/dist/engine.d.ts +32 -0
  15. package/dist/engine.d.ts.map +1 -0
  16. package/dist/errors.d.ts +6 -9
  17. package/dist/errors.d.ts.map +1 -1
  18. package/dist/event-hub.d.ts +6 -2
  19. package/dist/event-hub.d.ts.map +1 -1
  20. package/dist/group-coordinator.d.ts +27 -26
  21. package/dist/group-coordinator.d.ts.map +1 -1
  22. package/dist/group-lifecycle.d.ts +2 -2
  23. package/dist/group-lifecycle.d.ts.map +1 -1
  24. package/dist/group.d.ts +2 -2
  25. package/dist/group.d.ts.map +1 -1
  26. package/dist/host-api.d.ts +72 -0
  27. package/dist/host-api.d.ts.map +1 -0
  28. package/dist/host.d.ts +6 -0
  29. package/dist/host.d.ts.map +1 -0
  30. package/dist/index.d.ts +8 -7
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1412 -1166
  33. package/dist/installation-graph.d.ts +17 -0
  34. package/dist/installation-graph.d.ts.map +1 -0
  35. package/dist/installation-registry.d.ts +49 -0
  36. package/dist/installation-registry.d.ts.map +1 -0
  37. package/dist/installation.d.ts +46 -0
  38. package/dist/installation.d.ts.map +1 -0
  39. package/dist/lifecycle-status.d.ts +2 -0
  40. package/dist/lifecycle-status.d.ts.map +1 -0
  41. package/dist/lifetime-diagnostics.d.ts +2 -2
  42. package/dist/lifetime-diagnostics.d.ts.map +1 -1
  43. package/dist/lifetime.d.ts +17 -16
  44. package/dist/lifetime.d.ts.map +1 -1
  45. package/dist/plugin.d.ts +11 -7
  46. package/dist/plugin.d.ts.map +1 -1
  47. package/dist/readonly-map.d.ts.map +1 -1
  48. package/dist/record.d.ts +8 -0
  49. package/dist/record.d.ts.map +1 -0
  50. package/dist/resource.d.ts +7 -3
  51. package/dist/resource.d.ts.map +1 -1
  52. package/dist/runtime.d.ts +33 -0
  53. package/dist/runtime.d.ts.map +1 -0
  54. package/dist/snapshot-view.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/dist/application-api.d.ts +0 -51
  57. package/dist/application-api.d.ts.map +0 -1
  58. package/dist/application-runtime.d.ts +0 -36
  59. package/dist/application-runtime.d.ts.map +0 -1
  60. package/dist/application.d.ts +0 -6
  61. package/dist/application.d.ts.map +0 -1
  62. package/dist/extension-store.d.ts.map +0 -1
  63. package/dist/plugin-graph.d.ts +0 -17
  64. package/dist/plugin-graph.d.ts.map +0 -1
  65. package/dist/plugin-installation.d.ts +0 -44
  66. package/dist/plugin-installation.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,91 +1,145 @@
1
- function F(r, t) {
1
+ function tt(r, t) {
2
2
  if (typeof t != "string" || !t.trim())
3
3
  throw new TypeError(`${r} id must be a non-empty string`);
4
4
  if (t !== t.trim())
5
5
  throw new TypeError(`${r} id cannot start or end with whitespace`);
6
6
  }
7
- function k(r, t) {
8
- return F("Contract", t), Object.freeze({ id: t, kind: r });
7
+ function N(r, t) {
8
+ return tt("Contract", t), Object.freeze({ id: t, kind: r });
9
9
  }
10
10
  function w(r, t) {
11
11
  if (!r || typeof r != "object") return !1;
12
12
  const e = r;
13
- return typeof e.id == "string" && e.id.length > 0 && e.id === e.id.trim() && (e.kind === "service" || e.kind === "extension" || e.kind === "event") && (t === void 0 || e.kind === t);
13
+ return typeof e.id == "string" && e.id.length > 0 && e.id === e.id.trim() && (e.kind === "service" || e.kind === "extensionPoint" || e.kind === "event") && (t === void 0 || e.kind === t);
14
14
  }
15
- function v(r, t) {
15
+ function y(r, t) {
16
16
  if (!w(r, t))
17
- throw new TypeError(t ? `Expected a ${t} contract` : "Invalid contract");
17
+ throw new TypeError(t ? `Expected ${et(t)}` : "Invalid contract");
18
18
  }
19
- function qt(r) {
20
- return k("service", r);
19
+ function et(r) {
20
+ return r === "extensionPoint" ? "an ExtensionPoint" : r === "event" ? "an Event" : "a Service";
21
21
  }
22
- function Dt(r) {
23
- return k("event", r);
22
+ function ne(r) {
23
+ return N("service", r);
24
24
  }
25
- function Gt(r) {
26
- return k("extension", r);
25
+ function oe(r) {
26
+ return N("event", r);
27
27
  }
28
- function Vt(r) {
28
+ function ae(r) {
29
+ return N("extensionPoint", r);
30
+ }
31
+ function he(r) {
29
32
  if (!w(r, "service"))
30
- throw new TypeError("optional() expects a service contract");
33
+ throw new TypeError("optional() expects a Service");
31
34
  return Object.freeze({ kind: "optional", service: r });
32
35
  }
33
- class p extends Error {
36
+ class u extends Error {
34
37
  constructor(t, e, i) {
35
38
  super(e, i), this.code = t;
36
39
  }
37
40
  code;
38
41
  name = "DougongError";
39
42
  }
40
- function $(r, t, e) {
41
- return r instanceof Error ? r : new p(t, e, { cause: r });
43
+ class j extends u {
42
44
  }
43
- class H extends p {
45
+ function A(r, t, e) {
46
+ return r instanceof j ? r.code === t ? r : new j(t, e, { cause: r.cause }) : r instanceof Error ? r : new j(t, e, { cause: r });
47
+ }
48
+ function Y(r, t) {
49
+ if (!r || typeof r != "object" || typeof r.aborted != "boolean" || typeof r.addEventListener != "function" || typeof r.removeEventListener != "function" || typeof r.throwIfAborted != "function")
50
+ throw new TypeError("Cancellation classifier expects an AbortSignal");
51
+ return r.aborted ? Object.is(t, r.reason) ? !0 : t instanceof Error && t.name === "AbortError" : !1;
52
+ }
53
+ class it extends u {
44
54
  name = "ConfigValidationError";
45
55
  issues;
46
56
  constructor(t) {
47
- const e = Object.freeze(
48
- t.map(
49
- (i) => Object.freeze({
50
- message: i.message,
51
- ...i.path === void 0 ? {} : {
52
- path: Object.freeze(
53
- i.path.map(
54
- (s) => typeof s == "object" && s !== null ? Object.freeze({ key: s.key }) : s
55
- )
56
- )
57
- }
58
- })
59
- )
60
- );
57
+ const e = st(t);
61
58
  super(
62
59
  "CONFIG_INVALID",
63
- `Invalid plugin config:
60
+ `Invalid Plugin config:
64
61
  ${e.map((i) => ` - ${i.message}`).join(`
65
62
  `)}`
66
63
  ), this.issues = e;
67
64
  }
68
65
  }
69
- class K {
66
+ function st(r) {
67
+ if (!Array.isArray(r))
68
+ throw new TypeError("Config validation issues must be an array");
69
+ return Object.freeze(
70
+ Array.from(r, (t, e) => {
71
+ if (!t || typeof t != "object")
72
+ throw new TypeError(`Config validation issue at index ${e} must be an object`);
73
+ const i = t;
74
+ if (typeof i.message != "string")
75
+ throw new TypeError(`Config validation issue at index ${e} message must be a string`);
76
+ return Object.freeze({
77
+ message: i.message,
78
+ ...i.path === void 0 ? {} : { path: rt(i.path, e) }
79
+ });
80
+ })
81
+ );
82
+ }
83
+ function rt(r, t) {
84
+ if (!Array.isArray(r))
85
+ throw new TypeError(`Config validation issue at index ${t} path must be an array`);
86
+ return Object.freeze(
87
+ Array.from(r, (e, i) => {
88
+ if (M(e)) return e;
89
+ if (!e || typeof e != "object")
90
+ throw new TypeError(
91
+ `Config validation issue at index ${t} path segment ${i} must be a property key`
92
+ );
93
+ const s = e.key;
94
+ if (!M(s))
95
+ throw new TypeError(
96
+ `Config validation issue at index ${t} path segment ${i} must contain a property key`
97
+ );
98
+ return Object.freeze({ key: s });
99
+ })
100
+ );
101
+ }
102
+ function M(r) {
103
+ return typeof r == "string" || typeof r == "number" || typeof r == "symbol";
104
+ }
105
+ async function Q(r, t, e) {
106
+ if (!r) return t;
107
+ const i = await r["~standard"].validate(t);
108
+ if (!i || typeof i != "object")
109
+ throw new TypeError(
110
+ `Installation '${e}' config validator returned a non-object result`
111
+ );
112
+ const s = Object.hasOwn(i, "issues") ? i.issues : void 0;
113
+ if (s !== void 0)
114
+ throw Array.isArray(s) ? new it(s) : new TypeError(
115
+ `Installation '${e}' config validator returned non-array issues`
116
+ );
117
+ if (!Object.hasOwn(i, "value"))
118
+ throw new TypeError(
119
+ `Installation '${e}' config validator returned neither value nor issues`
120
+ );
121
+ return i.value;
122
+ }
123
+ class nt {
70
124
  #t = /* @__PURE__ */ new Map();
71
125
  get kinds() {
72
126
  return this.#t;
73
127
  }
74
128
  assertCompatible(t) {
75
- V(this.#t, t);
129
+ J(this.#t, t);
76
130
  }
77
131
  remember(t) {
78
- S(this.#t, t);
132
+ $(this.#t, t);
79
133
  }
80
134
  draft(t) {
81
- return new W(this, t);
135
+ return new ot(this, t);
82
136
  }
83
137
  commit(t) {
84
138
  for (const [e, i] of t) this.assertCompatible({ id: e, kind: i });
85
139
  for (const [e, i] of t) this.#t.set(e, i);
86
140
  }
87
141
  }
88
- class W {
142
+ class ot {
89
143
  #t;
90
144
  constructor(t, e) {
91
145
  this.#t = { phase: "open", registry: t, pending: /* @__PURE__ */ new Map() };
@@ -98,8 +152,8 @@ class W {
98
152
  return;
99
153
  }
100
154
  if (e.phase === "discarded")
101
- throw new TypeError("Contract registry draft has been discarded");
102
- e.registry.assertCompatible(t), !e.registry.kinds.has(t.id) && S(e.pending, t);
155
+ throw new Error("Contract registry draft has been discarded");
156
+ e.registry.assertCompatible(t), !e.registry.kinds.has(t.id) && $(e.pending, t);
103
157
  }
104
158
  commit() {
105
159
  const t = this.#t;
@@ -109,81 +163,152 @@ class W {
109
163
  this.#t.phase === "open" && (this.#t = { phase: "discarded" });
110
164
  }
111
165
  }
112
- function S(r, t) {
113
- V(r, t), r.set(t.id, t.kind);
166
+ function $(r, t) {
167
+ J(r, t), r.set(t.id, t.kind);
114
168
  }
115
- function V(r, t) {
169
+ function J(r, t) {
116
170
  const e = r.get(t.id);
117
171
  if (e && e !== t.kind)
118
- throw new p(
172
+ throw new u(
119
173
  "CONTRACT_CONFLICT",
120
174
  `Contract '${t.id}' is used as both '${e}' and '${t.kind}'`
121
175
  );
122
176
  }
123
- class Y {
124
- #t;
125
- constructor(t) {
126
- this.#t = t, Object.freeze(this);
177
+ class x {
178
+ constructor(t, e, i, s, n, o) {
179
+ this.order = t, this.layers = e, this.providers = i, this.dependents = s, this.contractKinds = n, this.#t = o;
127
180
  }
128
- dispose() {
129
- const t = this.#t;
130
- this.#t = void 0, t?.dispose();
181
+ order;
182
+ layers;
183
+ providers;
184
+ dependents;
185
+ contractKinds;
186
+ #t;
187
+ static build(t, e) {
188
+ const i = [...t].sort((h, d) => h.index - d.index), s = new Map(e), n = at(i, s), o = ht(i, n, s), { order: a, layers: c } = ct(
189
+ i,
190
+ o.dependents,
191
+ o.indegree
192
+ );
193
+ return new x(
194
+ Object.freeze(a),
195
+ Object.freeze(c.map((h) => Object.freeze(h))),
196
+ n,
197
+ o.dependents,
198
+ s,
199
+ o.resolvedProviders
200
+ );
131
201
  }
132
- [Symbol.dispose]() {
133
- this.dispose();
202
+ providerFor(t, e) {
203
+ return this.#t.get(t)?.get(e);
134
204
  }
135
- }
136
- class Q {
137
- #t;
138
- #e;
139
- handle;
140
- constructor(t, e, i, s) {
141
- this.#e = e, this.#t = { phase: "staged", hub: t, listener: i, release: s }, this.handle = new Y(this);
205
+ provider(t) {
206
+ return this.providers.get(t);
142
207
  }
143
- publish() {
144
- const t = this.#t;
145
- t.phase === "staged" && (t.hub.add(this.#e, t.listener), t.phase = "published");
208
+ affectedByTransitionTo(t, e) {
209
+ const i = /* @__PURE__ */ new Set();
210
+ return this.#e(e, i), t.#e(e, i), i;
146
211
  }
147
- dispose() {
148
- const t = this.#t;
149
- if (t.phase !== "removed") {
150
- this.#t = { phase: "removed" };
151
- try {
152
- t.phase === "published" && t.hub.delete(this.#e, t.listener);
153
- } finally {
154
- t.release(this);
212
+ #e(t, e) {
213
+ const i = [...t], s = /* @__PURE__ */ new Set();
214
+ for (let n = 0; n < i.length; n++) {
215
+ const o = i[n];
216
+ if (o && !s.has(o)) {
217
+ s.add(o), e.add(o);
218
+ for (const a of this.dependents.get(o) ?? []) i.push(a);
155
219
  }
156
220
  }
157
221
  }
158
- [Symbol.dispose]() {
159
- this.dispose();
160
- }
161
222
  }
162
- class J {
163
- #t = /* @__PURE__ */ new Map();
164
- stage(t, e, i) {
165
- if (typeof e != "function") throw new TypeError("Event listener must be a function");
166
- return new Q(this, t, e, i);
167
- }
168
- add(t, e) {
169
- const i = this.#t.get(t) ?? /* @__PURE__ */ new Set();
170
- this.#t.set(t, i), i.add(e);
223
+ function at(r, t) {
224
+ const e = /* @__PURE__ */ new Map();
225
+ for (const i of r)
226
+ for (const s of Object.values(i.declaration.plugin.provides ?? {})) {
227
+ $(t, s);
228
+ const n = e.get(s.id);
229
+ if (n)
230
+ throw new u(
231
+ "SERVICE_CONFLICT",
232
+ `Service '${s.id}' is provided by both '${n.id}' and '${i.id}'`
233
+ );
234
+ e.set(s.id, i);
235
+ }
236
+ return e;
237
+ }
238
+ function ht(r, t, e) {
239
+ const i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), n = new Map(r.map((o) => [o, 0]));
240
+ for (const o of r)
241
+ for (const a of Object.values(o.declaration.plugin.requires ?? {})) {
242
+ const c = a.kind === "optional" ? a.service : a;
243
+ if ($(e, c), c.kind === "extensionPoint") continue;
244
+ const h = t.get(c.id);
245
+ if (!h) {
246
+ if (a.kind === "optional") continue;
247
+ throw new u(
248
+ "SERVICE_MISSING",
249
+ `Installation '${o.id}' requires missing Service '${c.id}'`
250
+ );
251
+ }
252
+ if (h === o)
253
+ throw new u(
254
+ "SERVICE_CYCLE",
255
+ `Installation '${o.id}' cannot require Service '${c.id}' that it provides`
256
+ );
257
+ const d = i.get(o) ?? /* @__PURE__ */ new Map();
258
+ d.set(c.id, h), i.set(o, d);
259
+ const l = s.get(h) ?? /* @__PURE__ */ new Set();
260
+ l.has(o) || (l.add(o), s.set(h, l), n.set(o, (n.get(o) ?? 0) + 1));
261
+ }
262
+ return { resolvedProviders: i, dependents: s, indegree: n };
263
+ }
264
+ function ct(r, t, e) {
265
+ let i = r.filter((o) => e.get(o) === 0);
266
+ const s = [], n = [];
267
+ for (; i.length; ) {
268
+ i.sort((a, c) => a.index - c.index);
269
+ const o = i;
270
+ i = [], n.push(o), s.push(...o);
271
+ for (const a of o)
272
+ for (const c of t.get(a) ?? []) {
273
+ const h = (e.get(c) ?? 0) - 1;
274
+ e.set(c, h), h || i.push(c);
275
+ }
171
276
  }
172
- delete(t, e) {
173
- const i = this.#t.get(t);
174
- i && (i.delete(e), i.size || this.#t.delete(t));
277
+ if (s.length !== r.length) {
278
+ const o = dt(r, t);
279
+ throw new u(
280
+ "SERVICE_CYCLE",
281
+ `Installation dependency cycle: ${o.map((a) => a.id).join(" -> ")}`
282
+ );
175
283
  }
176
- async emit(t, e) {
177
- const i = [...this.#t.get(t) ?? []], n = (await Promise.allSettled(
178
- i.map((o) => Promise.resolve().then(() => o(e)))
179
- )).filter((o) => o.status === "rejected").map((o) => o.reason);
180
- if (n.length)
181
- throw new AggregateError(n, `Event '${t}' listeners failed`);
284
+ return { order: s, layers: n };
285
+ }
286
+ function dt(r, t) {
287
+ const e = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = [], n = (o) => {
288
+ i.add(o), s.push(o);
289
+ for (const a of t.get(o) ?? []) {
290
+ if (i.has(a)) {
291
+ const h = s.indexOf(a);
292
+ return [...s.slice(h), a];
293
+ }
294
+ if (e.has(a)) continue;
295
+ const c = n(a);
296
+ if (c) return c;
297
+ }
298
+ s.pop(), i.delete(o), e.add(o);
299
+ };
300
+ for (const o of r) {
301
+ if (e.has(o)) continue;
302
+ const a = n(o);
303
+ if (a) return a;
182
304
  }
305
+ throw new Error("Dependency graph is cyclic but no cycle path was found");
183
306
  }
184
- class C {
307
+ class O {
185
308
  #t;
186
- constructor(t) {
309
+ constructor(t = []) {
310
+ if (!t || typeof t != "object" && typeof t != "function" || typeof t[Symbol.iterator] != "function")
311
+ throw new TypeError("ReadonlyMapSnapshot values must be an iterable object");
187
312
  this.#t = new Map(t), Object.freeze(this);
188
313
  }
189
314
  get size() {
@@ -211,7 +336,96 @@ class C {
211
336
  return this.entries();
212
337
  }
213
338
  }
214
- class X {
339
+ const v = /* @__PURE__ */ new WeakMap();
340
+ class q {
341
+ #t = /* @__PURE__ */ new Set();
342
+ #e;
343
+ #i;
344
+ #s = !1;
345
+ constructor(t, e) {
346
+ if (typeof t != "function") throw new TypeError("Snapshot reader must be a function");
347
+ if (typeof e != "function")
348
+ throw new TypeError("Snapshot error reporter must be a function");
349
+ this.#e = { phase: "active", read: t, report: e }, this.#i = t(), Object.freeze(this);
350
+ }
351
+ view = Object.freeze({
352
+ get: () => this.#n(),
353
+ subscribe: (t) => this.#a(t)
354
+ });
355
+ invalidate() {
356
+ const { report: t } = this.#o();
357
+ this.#s = !0;
358
+ const e = [];
359
+ for (const i of [...this.#t])
360
+ try {
361
+ ut(i);
362
+ } catch (s) {
363
+ try {
364
+ t(s);
365
+ } catch (n) {
366
+ e.push(s, n);
367
+ }
368
+ }
369
+ if (e.length)
370
+ throw new AggregateError(e, "Snapshot error reporting failed");
371
+ }
372
+ dispose() {
373
+ const t = this.#e;
374
+ if (t.phase !== "disposed") {
375
+ this.#e = { phase: "disposed" };
376
+ try {
377
+ this.#r(t.read);
378
+ } finally {
379
+ this.#s = !1;
380
+ const e = [...this.#t];
381
+ this.#t.clear();
382
+ for (const i of e) ft(i);
383
+ }
384
+ }
385
+ }
386
+ [Symbol.dispose]() {
387
+ this.dispose();
388
+ }
389
+ #n() {
390
+ const t = this.#e;
391
+ return t.phase === "active" && this.#r(t.read), this.#i;
392
+ }
393
+ #a(t) {
394
+ if (typeof t != "function") throw new TypeError("Subscriber must be a function");
395
+ this.#o();
396
+ const e = new lt(t, (i) => {
397
+ this.#t.delete(i);
398
+ });
399
+ return this.#t.add(e), e;
400
+ }
401
+ #r(t) {
402
+ this.#s && (this.#i = t(), this.#s = !1);
403
+ }
404
+ #o() {
405
+ const t = this.#e;
406
+ if (t.phase === "disposed") throw new TypeError("Snapshot publisher is disposed");
407
+ return t;
408
+ }
409
+ }
410
+ class lt {
411
+ constructor(t, e) {
412
+ v.set(this, { listener: t, detach: e }), Object.freeze(this);
413
+ }
414
+ dispose() {
415
+ const t = v.get(this);
416
+ t && (v.delete(this), t.detach(this));
417
+ }
418
+ [Symbol.dispose]() {
419
+ this.dispose();
420
+ }
421
+ }
422
+ function ut(r) {
423
+ v.get(r)?.listener();
424
+ }
425
+ function ft(r) {
426
+ v.delete(r);
427
+ }
428
+ class pt {
215
429
  #t;
216
430
  get;
217
431
  subscribe;
@@ -219,7 +433,7 @@ class X {
219
433
  this.#t = t, this.get = () => this.#e(), this.subscribe = (e) => this.#i(e), Object.freeze(this);
220
434
  }
221
435
  // The handle retains only revocable binding state. Disposing its lease clears
222
- // the Store edge even when downstream code retains the public view.
436
+ // the ContributionStore edge even when downstream code retains the public view.
223
437
  #e() {
224
438
  return this.#s().store.snapshot();
225
439
  }
@@ -229,11 +443,11 @@ class X {
229
443
  }
230
444
  #s() {
231
445
  const t = this.#t.binding;
232
- if (!t) throw new TypeError("Extension view has been disposed");
446
+ if (!t) throw new TypeError("Contribution view has been disposed");
233
447
  return t;
234
448
  }
235
449
  }
236
- class Z {
450
+ class gt {
237
451
  #t;
238
452
  constructor(t) {
239
453
  this.#t = t, Object.freeze(this);
@@ -248,16 +462,22 @@ class Z {
248
462
  this.dispose();
249
463
  }
250
464
  }
251
- class tt {
465
+ class wt {
252
466
  #t;
253
467
  #e;
254
468
  handle;
255
469
  constructor(t, e, i, s) {
256
- this.#e = e, this.#t = { phase: "staged", store: t, value: i, detachFromOwner: s }, this.handle = new Z(this);
470
+ this.#e = e, this.#t = { phase: "staged", store: t, value: i, detachFromOwner: s }, this.handle = new gt(this);
257
471
  }
258
472
  publish() {
259
473
  const t = this.#t;
260
- t.phase === "staged" && (t.store.insert(this.#e, this, t.value), t.phase = "published");
474
+ t.phase === "staged" && t.store.insert(this.#e, this, t.value);
475
+ }
476
+ commitPublication() {
477
+ const t = this.#t;
478
+ if (t.phase !== "staged")
479
+ throw new Error(`Contribution '${this.#e}' is not staged`);
480
+ t.phase = "published";
261
481
  }
262
482
  update(t) {
263
483
  const e = this.#t;
@@ -280,93 +500,115 @@ class tt {
280
500
  this.dispose();
281
501
  }
282
502
  }
283
- class et {
503
+ class vt {
284
504
  #t;
285
505
  #e;
286
- #i;
506
+ #i = /* @__PURE__ */ new Map();
287
507
  #s = /* @__PURE__ */ new Map();
288
- #r = /* @__PURE__ */ new Map();
289
- #n = /* @__PURE__ */ new Set();
290
- #a = new C();
508
+ #n;
509
+ #a = new O();
510
+ #r = 0;
291
511
  #o = 0;
512
+ #c = !1;
292
513
  constructor(t, e, i) {
293
- this.#t = t, this.#e = e, this.#i = i;
514
+ this.#t = t, this.#e = i, this.#n = new q(() => this.#a, e);
294
515
  }
295
516
  stage(t, e, i, s) {
296
- nt(e);
297
- const n = ot(t, e);
298
- if (this.#s.has(n))
299
- throw new TypeError(`Duplicate extension contribution '${n}'`);
300
- const o = new tt(this, n, i, s);
301
- return this.#s.set(n, o), o;
517
+ Et(e);
518
+ const n = Ct(t, e);
519
+ if (this.#i.has(n))
520
+ throw new TypeError(`Duplicate contribution '${n}'`);
521
+ const o = new wt(this, n, i, s);
522
+ return this.#i.set(n, o), o;
302
523
  }
303
524
  view(t) {
304
- this.#o++;
525
+ this.#r++;
305
526
  const e = { binding: { store: this, own: t } };
306
527
  let i;
307
- const s = new it(e, () => {
528
+ const s = new bt(e, () => {
308
529
  const n = i;
309
530
  i = void 0;
310
531
  try {
311
532
  n?.();
312
533
  } finally {
313
- this.#o--, this.#h();
534
+ this.#r--, this.#l();
314
535
  }
315
536
  });
316
537
  try {
317
538
  i = t(s, "view");
318
539
  } catch (n) {
319
- throw e.binding = void 0, this.#o--, this.#h(), n;
540
+ throw e.binding = void 0, this.#r--, this.#l(), n;
320
541
  }
321
- return new X(e);
542
+ return new pt(e);
322
543
  }
323
544
  snapshot() {
324
- return this.#a;
545
+ return this.#n.view.get();
325
546
  }
326
547
  subscribe(t, e) {
327
548
  if (typeof t != "function")
328
- throw new TypeError("Extension subscriber must be a function");
329
- let i;
330
- const s = new st(this, t, () => {
331
- const n = i;
332
- i = void 0, n?.();
549
+ throw new TypeError("Contribution subscriber must be a function");
550
+ const i = this.#n.view.subscribe(t);
551
+ this.#o++;
552
+ let s;
553
+ const n = new mt(i, () => {
554
+ const o = s;
555
+ s = void 0;
556
+ try {
557
+ o?.();
558
+ } finally {
559
+ this.#o--, this.#l();
560
+ }
333
561
  });
334
- return i = e(s, "subscription"), this.#n.add(t), s;
562
+ try {
563
+ s = e(n, "subscription");
564
+ } catch (o) {
565
+ throw n.dispose(), o;
566
+ }
567
+ return n;
335
568
  }
336
569
  insert(t, e, i) {
337
- if (this.#s.get(t) !== e)
338
- throw new Error(`Extension contribution '${t}' is not the current claim`);
339
- if (this.#r.has(t))
340
- throw new Error(`Extension contribution '${t}' is already published`);
341
- this.#r.set(t, { contribution: e, value: i }), this.#t(this);
570
+ if (this.#f(t, e), this.#s.has(t))
571
+ throw new Error(`Contribution '${t}' is already published`);
572
+ e.commitPublication(), this.#s.set(t, { contribution: e, value: i }), this.#t(this);
342
573
  }
343
574
  update(t, e, i) {
344
- const s = this.#r.get(t);
345
- s?.contribution === e && (s.value = i, this.#t(this));
575
+ const s = this.#u(t, e);
576
+ s.value = i, this.#t(this);
346
577
  }
347
578
  removeContribution(t, e, i) {
348
- this.#s.get(t) === e && this.#s.delete(t), i === "published" && this.#r.get(t)?.contribution === e && (this.#r.delete(t), this.#t(this)), this.#h();
579
+ this.#f(t, e), i === "published" && this.#u(t, e);
580
+ try {
581
+ this.#i.delete(t), i === "published" && (this.#s.delete(t), this.#t(this));
582
+ } finally {
583
+ this.#l();
584
+ }
349
585
  }
350
586
  publishSnapshot() {
351
- const t = [...this.#r].map(([i, s]) => [i, s.value]);
352
- if (!(t.length === this.#a.size && t.every(([i, s]) => Object.is(this.#a.get(i), s)))) {
353
- this.#a = new C(t);
354
- for (const i of [...this.#n])
355
- try {
356
- i();
357
- } catch (s) {
358
- this.#e(s);
359
- }
360
- }
587
+ const t = [...this.#s].map(([i, s]) => [i, s.value]);
588
+ t.length === this.#a.size && t.every(([i, s]) => Object.is(this.#a.get(i), s)) || (this.#a = new O(t), this.#n.invalidate());
361
589
  }
362
- removeListener(t) {
363
- this.#n.delete(t), this.#h();
590
+ #f(t, e) {
591
+ if (this.#i.get(t) !== e)
592
+ throw new Error(`Contribution '${t}' is not the current claim`);
364
593
  }
365
- #h() {
366
- this.#s.size || this.#r.size || this.#n.size || this.#o || this.#i(this);
594
+ #u(t, e) {
595
+ const i = this.#s.get(t);
596
+ if (i?.contribution !== e)
597
+ throw new Error(`Contribution '${t}' is not the published entry`);
598
+ return i;
599
+ }
600
+ #l() {
601
+ if (!(this.#c || this.#i.size || this.#s.size || this.#o || this.#r)) {
602
+ this.#c = !0;
603
+ try {
604
+ this.#n.dispose();
605
+ } finally {
606
+ this.#e(this);
607
+ }
608
+ }
367
609
  }
368
610
  }
369
- class it {
611
+ class bt {
370
612
  #t;
371
613
  constructor(t, e) {
372
614
  this.#t = { state: t, release: e }, Object.freeze(this);
@@ -379,17 +621,17 @@ class it {
379
621
  this.dispose();
380
622
  }
381
623
  }
382
- class st {
624
+ class mt {
383
625
  #t;
384
- constructor(t, e, i) {
385
- this.#t = { store: t, listener: e, release: i }, Object.freeze(this);
626
+ constructor(t, e) {
627
+ this.#t = { subscription: t, release: e }, Object.freeze(this);
386
628
  }
387
629
  dispose() {
388
630
  const t = this.#t;
389
631
  if (t) {
390
632
  this.#t = void 0;
391
633
  try {
392
- t.store.removeListener(t.listener);
634
+ t.subscription.dispose();
393
635
  } finally {
394
636
  t.release();
395
637
  }
@@ -399,7 +641,7 @@ class st {
399
641
  this.dispose();
400
642
  }
401
643
  }
402
- class rt {
644
+ class yt {
403
645
  #t = /* @__PURE__ */ new Map();
404
646
  #e = /* @__PURE__ */ new Set();
405
647
  #i;
@@ -410,8 +652,8 @@ class rt {
410
652
  get(t) {
411
653
  const e = this.#t.get(t.id);
412
654
  if (e) return e;
413
- const i = new et(
414
- (s) => this.#r(s),
655
+ const i = new vt(
656
+ (s) => this.#n(s),
415
657
  this.#i,
416
658
  (s) => {
417
659
  this.#t.get(t.id) === s && (this.#e.delete(s), this.#t.delete(t.id));
@@ -423,122 +665,112 @@ class rt {
423
665
  this.#s++;
424
666
  }
425
667
  endBatch() {
426
- if (!this.#s) throw new TypeError("Extension batch is not active");
668
+ if (!this.#s) throw new Error("Contribution batch is not active");
427
669
  if (this.#s--, this.#s) return;
428
670
  const t = [...this.#e];
429
671
  this.#e.clear();
430
- for (const e of t) e.publishSnapshot();
672
+ const e = [];
673
+ for (const i of t)
674
+ try {
675
+ i.publishSnapshot();
676
+ } catch (s) {
677
+ e.push(s);
678
+ }
679
+ if (e.length === 1) throw e[0];
680
+ if (e.length > 1)
681
+ throw new AggregateError(e, "Contribution batch publication failed");
431
682
  }
432
- #r(t) {
683
+ #n(t) {
433
684
  this.#e.add(t), !this.#s && (this.#e.delete(t), t.publishSnapshot());
434
685
  }
435
686
  }
436
- function nt(r) {
687
+ function Et(r) {
437
688
  if (typeof r != "string" || !r.trim())
438
689
  throw new TypeError("Contribution key must be a non-empty string");
439
690
  if (r !== r.trim())
440
691
  throw new TypeError("Contribution key cannot start or end with whitespace");
441
692
  }
442
- function ot(r, t) {
443
- return `${x(r)}/${x(t)}`;
693
+ function Ct(r, t) {
694
+ return `${D(r)}/${D(t)}`;
444
695
  }
445
- function x(r) {
696
+ function D(r) {
446
697
  return r.replaceAll("%", "%25").replaceAll("/", "%2F");
447
698
  }
448
- const m = /* @__PURE__ */ new WeakMap();
449
- class U {
450
- #t = /* @__PURE__ */ new Set();
451
- #e;
452
- #i;
453
- #s = !1;
454
- constructor(t, e) {
455
- if (typeof t != "function") throw new TypeError("Snapshot reader must be a function");
456
- if (typeof e != "function")
457
- throw new TypeError("Snapshot error reporter must be a function");
458
- this.#e = { phase: "active", read: t, report: e }, this.#i = t(), Object.freeze(this);
699
+ class Ot {
700
+ #t;
701
+ constructor(t) {
702
+ this.#t = t, Object.freeze(this);
459
703
  }
460
- view = Object.freeze({
461
- get: () => this.#r(),
462
- subscribe: (t) => this.#n(t)
463
- });
464
- invalidate() {
465
- const { report: t } = this.#o();
466
- this.#s = !0;
467
- for (const e of [...this.#t])
468
- try {
469
- ht(e);
470
- } catch (i) {
471
- t(i);
472
- }
704
+ dispose() {
705
+ const t = this.#t;
706
+ this.#t = void 0, t?.dispose();
707
+ }
708
+ [Symbol.dispose]() {
709
+ this.dispose();
710
+ }
711
+ }
712
+ class St {
713
+ #t;
714
+ #e;
715
+ handle;
716
+ constructor(t, e, i, s) {
717
+ this.#e = e, this.#t = { phase: "staged", hub: t, slot: { listener: i }, release: s }, this.handle = new Ot(this);
718
+ }
719
+ publish() {
720
+ const t = this.#t;
721
+ t.phase === "staged" && (t.hub.add(this.#e, t.slot), t.phase = "published");
473
722
  }
474
723
  dispose() {
475
- const t = this.#e;
476
- if (t.phase !== "disposed") {
477
- this.#e = { phase: "disposed" };
724
+ const t = this.#t;
725
+ if (t.phase !== "removed") {
726
+ this.#t = { phase: "removed" };
478
727
  try {
479
- this.#a(t.read);
728
+ t.phase === "published" && t.hub.delete(this.#e, t.slot);
480
729
  } finally {
481
- this.#s = !1;
482
- const e = [...this.#t];
483
- this.#t.clear();
484
- for (const i of e) ct(i);
730
+ t.release(this);
485
731
  }
486
732
  }
487
733
  }
488
734
  [Symbol.dispose]() {
489
735
  this.dispose();
490
736
  }
491
- #r() {
492
- const t = this.#e;
493
- return t.phase === "active" && this.#a(t.read), this.#i;
494
- }
495
- #n(t) {
496
- if (typeof t != "function") throw new TypeError("Subscriber must be a function");
497
- this.#o();
498
- const e = new at(t, (i) => {
499
- this.#t.delete(i);
500
- });
501
- return this.#t.add(e), e;
502
- }
503
- #a(t) {
504
- this.#s && (this.#i = t(), this.#s = !1);
505
- }
506
- #o() {
507
- const t = this.#e;
508
- if (t.phase === "disposed") throw new TypeError("Snapshot publisher is disposed");
509
- return t;
510
- }
511
737
  }
512
- class at {
513
- constructor(t, e) {
514
- m.set(this, { listener: t, detach: e }), Object.freeze(this);
738
+ class It {
739
+ #t = /* @__PURE__ */ new Map();
740
+ stage(t, e, i) {
741
+ if (typeof e != "function") throw new TypeError("Event listener must be a function");
742
+ return new St(this, t, e, i);
515
743
  }
516
- dispose() {
517
- const t = m.get(this);
518
- t && (m.delete(this), t.detach(this));
744
+ add(t, e) {
745
+ const i = this.#t.get(t) ?? /* @__PURE__ */ new Set();
746
+ this.#t.set(t, i), i.add(e);
519
747
  }
520
- [Symbol.dispose]() {
521
- this.dispose();
748
+ delete(t, e) {
749
+ const i = this.#t.get(t);
750
+ i && (i.delete(e), i.size || this.#t.delete(t));
751
+ }
752
+ async emit(t, e) {
753
+ const i = [...this.#t.get(t) ?? []].map(
754
+ (o) => o.listener
755
+ ), n = (await Promise.allSettled(
756
+ i.map((o) => Promise.resolve().then(() => o(e)))
757
+ )).filter((o) => o.status === "rejected").map((o) => o.reason);
758
+ if (n.length)
759
+ throw new AggregateError(n, `Event '${t}' listeners failed`);
522
760
  }
523
761
  }
524
- function ht(r) {
525
- m.get(r)?.listener();
526
- }
527
- function ct(r) {
528
- m.delete(r);
529
- }
530
- class dt {
762
+ class At {
531
763
  #t;
532
764
  root;
533
765
  view;
534
766
  constructor(t, e) {
535
- this.root = R(t), this.#t = new U(() => B(this.root), e), this.view = this.#t.view;
767
+ this.root = G(t), this.#t = new q(() => X(this.root), e), this.view = this.#t.view;
536
768
  }
537
769
  createNode(t) {
538
- return R(t);
770
+ return G(t);
539
771
  }
540
772
  attach(t, e) {
541
- if (t.children.has(e)) throw new TypeError("Lifetime diagnostic node is attached");
773
+ if (t.children.has(e)) throw new Error("Lifetime diagnostic node is attached");
542
774
  t.children.add(e), this.#t.invalidate();
543
775
  }
544
776
  detach(t, e) {
@@ -546,7 +778,7 @@ class dt {
546
778
  }
547
779
  change(t, e, i) {
548
780
  const s = t.counts[e] + i;
549
- if (s < 0) throw new TypeError(`Lifetime '${e}' count cannot be negative`);
781
+ if (s < 0) throw new Error(`Lifetime '${e}' count cannot be negative`);
550
782
  t.counts[e] = s, this.#t.invalidate();
551
783
  }
552
784
  beginDisposing(t) {
@@ -556,7 +788,7 @@ class dt {
556
788
  this.root.phase !== "disposed" && (this.root.phase = "disposed", this.#t.invalidate(), this.#t.dispose());
557
789
  }
558
790
  }
559
- function R(r) {
791
+ function G(r) {
560
792
  return {
561
793
  label: r,
562
794
  phase: "active",
@@ -565,14 +797,14 @@ function R(r) {
565
797
  tasks: 0,
566
798
  listeners: 0,
567
799
  contributions: 0,
568
- extensionViews: 0,
800
+ contributionViews: 0,
569
801
  subscriptions: 0
570
802
  },
571
803
  children: /* @__PURE__ */ new Set()
572
804
  };
573
805
  }
574
- function B(r) {
575
- const t = Object.freeze([...r.children].map(B));
806
+ function X(r) {
807
+ const t = Object.freeze([...r.children].map(X));
576
808
  return Object.freeze({
577
809
  label: r.label,
578
810
  phase: r.phase,
@@ -580,7 +812,14 @@ function B(r) {
580
812
  children: t
581
813
  });
582
814
  }
583
- const A = Object.freeze(new DOMException("Resource disposed", "AbortError"));
815
+ function $t(r) {
816
+ if (!r || typeof r != "object") return !1;
817
+ const t = r;
818
+ return [t.debug, t.info, t.warn, t.error].every(
819
+ (e) => typeof e == "function"
820
+ );
821
+ }
822
+ const L = Object.freeze(new DOMException("Resource disposed", "AbortError"));
584
823
  class g {
585
824
  #t = /* @__PURE__ */ new Set();
586
825
  #e;
@@ -588,7 +827,7 @@ class g {
588
827
  this.#e = t;
589
828
  }
590
829
  add(t) {
591
- if (this.#t.has(t)) throw new TypeError("Lifetime already owns this resource");
830
+ if (this.#t.has(t)) throw new Error("Lifetime already owns this resource");
592
831
  this.#t.add(t);
593
832
  const e = this.#e;
594
833
  e && e.diagnostics.change(e.node, e.kind, 1);
@@ -619,7 +858,7 @@ class g {
619
858
  return this.#t[Symbol.iterator]();
620
859
  }
621
860
  }
622
- class lt {
861
+ class Tt {
623
862
  #t;
624
863
  constructor(t, e) {
625
864
  this.#t = { phase: "active", cleanup: t, detachFromParent: e }, Object.freeze(this);
@@ -643,7 +882,7 @@ class lt {
643
882
  return this.dispose();
644
883
  }
645
884
  }
646
- class ut {
885
+ class jt {
647
886
  #t;
648
887
  #e;
649
888
  #i;
@@ -656,7 +895,7 @@ class ut {
656
895
  () => this.#s(),
657
896
  (a) => {
658
897
  try {
659
- n.signal.aborted || i(a);
898
+ Y(n.signal, a) || i(a);
660
899
  } finally {
661
900
  this.#s();
662
901
  }
@@ -674,78 +913,78 @@ class ut {
674
913
  () => {
675
914
  }
676
915
  );
677
- return this.#i = { phase: "disposing", completion: e }, t.controller.abort(A), this.#r(), e;
916
+ return this.#i = { phase: "disposing", completion: e }, t.controller.abort(L), this.#n(), e;
678
917
  }
679
918
  [Symbol.asyncDispose]() {
680
919
  return this.dispose();
681
920
  }
682
921
  #s() {
683
922
  if (this.#i.phase === "settled") return;
684
- this.#i = { phase: "settled" }, this.#r();
923
+ this.#i = { phase: "settled" }, this.#n();
685
924
  const t = this.#e;
686
925
  this.#e = void 0, t?.(this);
687
926
  }
688
- #r() {
927
+ #n() {
689
928
  const t = this.#t;
690
929
  this.#t = void 0, t?.();
691
930
  }
692
931
  }
693
- class L {
932
+ class V {
694
933
  #t;
695
934
  #e;
696
935
  #i;
697
936
  #s;
698
- #r;
699
937
  #n;
700
938
  #a;
939
+ #r;
701
940
  #o;
702
- #h;
703
941
  #c;
704
- #p;
705
- #g;
706
- handle;
942
+ #f;
943
+ #u;
707
944
  #l;
945
+ handle;
946
+ #d;
708
947
  constructor(t, e, i = {}) {
709
- this.#e = e, this.handle = new pt(this);
948
+ this.#e = e, this.handle = new kt(this);
710
949
  const s = new AbortController();
711
- this.#l = {
950
+ this.#d = {
712
951
  phase: "active",
713
952
  controller: s,
714
953
  declarations: i.declarations ?? "staged"
715
954
  };
716
955
  const n = i.parent;
717
- this.#g = n?.detach, this.#c = n ? "child" : "root";
718
- const o = n?.diagnostics ?? new dt(e, (l) => t.report(l)), a = n?.diagnosticNode ?? o.root;
719
- this.#t = { host: t, diagnostics: o, diagnosticNode: a };
720
- const h = (l) => ({
956
+ this.#l = n?.detach, this.#f = n ? "child" : "root";
957
+ const o = n?.diagnostics ?? new At(e, (l) => t.report(l)), a = n?.diagnosticNode ?? o.root;
958
+ this.#t = { port: t, diagnostics: o, diagnosticNode: a };
959
+ const c = (l) => ({
721
960
  diagnostics: o,
722
961
  node: a,
723
962
  kind: l
724
963
  });
725
- this.#i = new g(h("listeners")), this.#s = new g(h("contributions")), this.#r = new g(h("extensionViews")), this.#n = new g(h("subscriptions")), this.#a = new g(h("tasks")), this.#o = new g(), this.#h = new g(h("cleanups"));
726
- const c = i.parentSignal;
727
- if (!c) return;
728
- const d = () => s.abort(c.reason);
729
- c.addEventListener("abort", d, { once: !0 }), this.#p = () => c.removeEventListener("abort", d), c.aborted && d();
964
+ this.#i = new g(c("listeners")), this.#s = new g(c("contributions")), this.#n = new g(c("contributionViews")), this.#a = new g(c("subscriptions")), this.#r = new g(c("tasks")), this.#o = new g(), this.#c = new g(c("cleanups"));
965
+ const h = i.parentSignal;
966
+ if (!h) return;
967
+ const d = () => s.abort(h.reason);
968
+ h.addEventListener("abort", d, { once: !0 }), this.#u = () => h.removeEventListener("abort", d), h.aborted && d();
730
969
  }
731
970
  get signal() {
732
- const t = this.#l;
971
+ const t = this.#d;
733
972
  return t.phase === "disposed" ? t.signal : t.controller.signal;
734
973
  }
735
974
  get diagnostics() {
736
- return this.#d().diagnostics.view;
975
+ return this.#h().diagnostics.view;
737
976
  }
738
977
  cleanup(t) {
739
- if (this.#d(), typeof t != "function") throw new TypeError("Cleanup must be a function");
740
- const e = new lt(t, this.#h.release);
741
- return this.#h.add(e), e;
978
+ if (this.#h(), typeof t != "function") throw new TypeError("Cleanup must be a function");
979
+ const e = new Tt(t, this.#c.release);
980
+ return this.#c.add(e), e;
742
981
  }
743
982
  lifetime(t) {
744
- const { host: e, diagnostics: i, diagnosticNode: s } = this.#d();
745
- ft(t);
746
- const n = i.createNode(t), o = new L(e, this.#e, {
983
+ const { port: e, diagnostics: i, diagnosticNode: s } = this.#h();
984
+ Pt(t);
985
+ const n = i.createNode(t), o = new V(e, this.#e, {
747
986
  parentSignal: this.signal,
748
- declarations: this.#w(),
987
+ declarations: this.#g(),
749
988
  parent: {
750
989
  diagnostics: i,
751
990
  diagnosticNode: n,
@@ -757,94 +996,94 @@ class L {
757
996
  return this.#o.add(o), i.attach(s, n), o.handle;
758
997
  }
759
998
  spawn(t) {
760
- const { host: e } = this.#d();
999
+ const { port: e } = this.#h();
761
1000
  if (typeof t != "function") throw new TypeError("Background task must be a function");
762
- const i = new ut(
1001
+ const i = new jt(
763
1002
  this.signal,
764
1003
  t,
765
1004
  (s) => e.report(s),
766
- this.#a.release
1005
+ this.#r.release
767
1006
  );
768
- return this.#a.add(i), i;
1007
+ return this.#r.add(i), i;
769
1008
  }
770
1009
  on(t, e) {
771
- const { host: i } = this.#d(), s = i.stageOn(this.#e, t, e, this.#i.release);
772
- return this.#i.add(s), this.#w() === "published" && s.publish(), s.handle;
1010
+ const { port: i } = this.#h(), s = i.stageOn(this.#e, t, e, this.#i.release);
1011
+ return this.#i.add(s), this.#g() === "published" && s.publish(), s.handle;
773
1012
  }
774
1013
  emit(t, e) {
775
- return this.#d().host.emit(this.#e, t, e);
1014
+ return this.#h().port.emit(this.#e, t, e);
776
1015
  }
777
1016
  contribute(t, e, i) {
778
- const { host: s } = this.#d(), n = s.stageContribution(
1017
+ const { port: s } = this.#h(), n = s.stageContribution(
779
1018
  this.#e,
780
1019
  t,
781
1020
  e,
782
1021
  i,
783
1022
  this.#s.release
784
1023
  );
785
- return this.#s.add(n), this.#w() === "published" && n.publish(), n.handle;
1024
+ return this.#s.add(n), this.#g() === "published" && n.publish(), n.handle;
786
1025
  }
787
1026
  /** Owns an internal live capability without exposing a second Context API. */
788
1027
  ownLease(t, e) {
789
- return this.#d(), (e === "view" ? this.#r : this.#n).own(t);
1028
+ return this.#h(), (e === "view" ? this.#n : this.#a).own(t);
790
1029
  }
791
1030
  /** Releases a temporary startup cancellation edge after its layer commits. */
792
1031
  detachStartupSignal() {
793
- const t = this.#p;
794
- this.#p = void 0, t?.();
1032
+ const t = this.#u;
1033
+ this.#u = void 0, t?.();
795
1034
  }
796
1035
  /** Atomically makes all declarations staged during setup visible. */
797
1036
  publish() {
798
- const t = this.#l;
1037
+ const t = this.#d;
799
1038
  if (t.phase !== "active") throw b();
800
- if (this.#d(), t.declarations !== "published") {
1039
+ if (this.#h(), t.declarations !== "published") {
801
1040
  for (const e of this.#i) e.publish();
802
1041
  for (const e of this.#s) e.publish();
803
1042
  for (const e of this.#o) e.publish();
804
- this.#l = { ...t, declarations: "published" };
1043
+ this.#d = { ...t, declarations: "published" };
805
1044
  }
806
1045
  }
807
1046
  dispose() {
808
- const t = this.#l;
1047
+ const t = this.#d;
809
1048
  if (t.phase === "disposing") return t.completion;
810
1049
  if (t.phase === "disposed") return Promise.resolve();
811
- const e = this.#b(), i = Promise.resolve().then(async () => {
1050
+ const e = this.#p(), i = Promise.resolve().then(async () => {
812
1051
  const s = [];
813
- if (await this.#i.dispose(s), await this.#s.dispose(s), await this.#n.dispose(s), await this.#r.dispose(s), t.controller.abort(A), this.detachStartupSignal(), await this.#a.dispose(s), await this.#o.dispose(s), await this.#h.dispose(s), s.length === 1) throw s[0];
1052
+ if (await this.#i.dispose(s), await this.#s.dispose(s), await this.#a.dispose(s), await this.#n.dispose(s), t.controller.abort(L), this.detachStartupSignal(), await this.#r.dispose(s), await this.#o.dispose(s), await this.#c.dispose(s), s.length === 1) throw s[0];
814
1053
  if (s.length > 1) throw new AggregateError(s, "Lifetime cleanup failed");
815
1054
  }).finally(() => {
816
- this.#l = { phase: "disposed", signal: AbortSignal.abort(A) };
817
- const s = this.#g;
818
- this.#g = void 0;
1055
+ this.#d = { phase: "disposed", signal: AbortSignal.abort(L) };
1056
+ const s = this.#l;
1057
+ this.#l = void 0;
819
1058
  try {
820
- s?.(this), this.#c === "root" && e.diagnostics.finishRoot();
1059
+ s?.(this), this.#f === "root" && e.diagnostics.finishRoot();
821
1060
  } finally {
822
1061
  this.#t = void 0;
823
1062
  }
824
1063
  });
825
- return this.#l = { phase: "disposing", controller: t.controller, completion: i }, e.diagnostics.beginDisposing(e.diagnosticNode), i;
1064
+ return this.#d = { phase: "disposing", controller: t.controller, completion: i }, e.diagnostics.beginDisposing(e.diagnosticNode), i;
826
1065
  }
827
1066
  [Symbol.asyncDispose]() {
828
1067
  return this.dispose();
829
1068
  }
830
- #d() {
1069
+ #h() {
831
1070
  const t = this.#t;
832
- if (this.#l.phase !== "active" || this.signal.aborted || !t)
1071
+ if (this.#d.phase !== "active" || this.signal.aborted || !t)
833
1072
  throw b();
834
1073
  return t;
835
1074
  }
836
- #b() {
1075
+ #p() {
837
1076
  const t = this.#t;
838
1077
  if (!t) throw b();
839
1078
  return t;
840
1079
  }
841
- #w() {
842
- const t = this.#l;
1080
+ #g() {
1081
+ const t = this.#d;
843
1082
  if (t.phase !== "active") throw b();
844
1083
  return t.declarations;
845
1084
  }
846
1085
  }
847
- class pt {
1086
+ class kt {
848
1087
  #t;
849
1088
  constructor(t) {
850
1089
  this.#t = t, Object.freeze(this);
@@ -877,7 +1116,7 @@ class pt {
877
1116
  return this.dispose();
878
1117
  }
879
1118
  }
880
- function ft(r) {
1119
+ function Pt(r) {
881
1120
  if (typeof r != "string" || !r.trim())
882
1121
  throw new TypeError("Lifetime label must be a non-empty string");
883
1122
  if (r !== r.trim())
@@ -886,632 +1125,409 @@ function ft(r) {
886
1125
  function b() {
887
1126
  return new TypeError("Lifetime is disposing or has been disposed");
888
1127
  }
889
- class z {
890
- constructor(t, e, i, s, n, o) {
891
- this.order = t, this.layers = e, this.providers = i, this.dependents = s, this.contractKinds = n, this.#t = o;
892
- }
893
- order;
894
- layers;
895
- providers;
896
- dependents;
897
- contractKinds;
1128
+ class z extends AggregateError {
1129
+ }
1130
+ class Lt {
898
1131
  #t;
899
- static build(t, e) {
900
- const i = [...t].sort((c, d) => c.index - d.index), s = new Map(e), n = gt(i, s), o = wt(i, n, s), { order: a, layers: h } = mt(
901
- i,
902
- o.dependents,
903
- o.indegree
904
- );
905
- return new z(
906
- Object.freeze(a),
907
- Object.freeze(h.map((c) => Object.freeze(c))),
908
- n,
909
- o.dependents,
910
- s,
911
- o.resolvedProviders
912
- );
1132
+ #e;
1133
+ #i;
1134
+ #s;
1135
+ #n = /* @__PURE__ */ new Map();
1136
+ #a = new It();
1137
+ #r;
1138
+ #o = [];
1139
+ constructor(t) {
1140
+ this.#t = t.hostName, this.#e = t.logger, this.#i = t.isInstalled, this.#s = t.report, this.#r = new yt(t.report);
913
1141
  }
914
- providerFor(t, e) {
915
- return this.#t.get(t)?.get(e);
1142
+ readService(t, e) {
1143
+ const i = this.#n.get(t);
1144
+ return i?.has(e) ? { found: !0, value: i.get(e) } : { found: !1 };
916
1145
  }
917
- provider(t) {
918
- return this.providers.get(t);
1146
+ captureConfigs(t) {
1147
+ const e = /* @__PURE__ */ new Map();
1148
+ for (const i of t) {
1149
+ const s = i.instance;
1150
+ s && e.set(i, s.config);
1151
+ }
1152
+ return e;
919
1153
  }
920
- affectedByTransitionTo(t, e) {
921
- const i = /* @__PURE__ */ new Set();
922
- return this.#e(e, i), t.#e(e, i), i;
1154
+ resetActivationState() {
1155
+ this.#n.clear(), this.#o = [];
923
1156
  }
924
- #e(t, e) {
925
- const i = [...t], s = /* @__PURE__ */ new Set();
926
- for (let n = 0; n < i.length; n++) {
927
- const o = i[n];
928
- if (o && !s.has(o)) {
929
- s.add(o), e.add(o);
930
- for (const a of this.dependents.get(o) ?? []) i.push(a);
1157
+ commitActivationOrder(t) {
1158
+ this.#o = t.slice();
1159
+ }
1160
+ deactivateAll() {
1161
+ return this.deactivate(new Set(this.#o));
1162
+ }
1163
+ async activate(t, e, i, s) {
1164
+ const n = this.#h(s);
1165
+ for (const o of t.layers) {
1166
+ const a = o.filter(
1167
+ (f) => e.has(f) && !f.instance
1168
+ );
1169
+ if (!a.length) continue;
1170
+ const c = new AbortController(), h = await Promise.allSettled(
1171
+ a.map(async (f) => {
1172
+ try {
1173
+ const p = i.has(f) ? i.get(f) : await Q(
1174
+ f.declaration.plugin.config,
1175
+ f.declaration.config,
1176
+ f.id
1177
+ );
1178
+ return await this.#c(
1179
+ t,
1180
+ f,
1181
+ p,
1182
+ c.signal,
1183
+ n
1184
+ );
1185
+ } catch (p) {
1186
+ throw c.abort(p), p;
1187
+ }
1188
+ })
1189
+ ), d = zt(h, c.signal), l = h.filter(
1190
+ (f) => f.status === "fulfilled"
1191
+ ).map((f) => f.value);
1192
+ if (d.length) {
1193
+ const f = await this.#u(l), p = d.length === 1 ? d[0] : new AggregateError(d, "Installation startup layer failed");
1194
+ throw f.length ? new z(
1195
+ [p, ...f],
1196
+ "Installation startup layer failed and could not be cleanly disposed"
1197
+ ) : p;
931
1198
  }
1199
+ this.#f(l);
932
1200
  }
933
1201
  }
934
- }
935
- function gt(r, t) {
936
- const e = /* @__PURE__ */ new Map();
937
- for (const i of r)
938
- for (const s of Object.values(i.spec.plugin.provides ?? {})) {
939
- S(t, s);
940
- const n = e.get(s.id);
941
- if (n)
942
- throw new p(
943
- "SERVICE_CONFLICT",
944
- `Service '${s.id}' is provided by both '${n.id}' and '${i.id}'`
945
- );
946
- e.set(s.id, i);
947
- }
948
- return e;
949
- }
950
- function wt(r, t, e) {
951
- const i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), n = new Map(r.map((o) => [o, 0]));
952
- for (const o of r)
953
- for (const a of Object.values(o.spec.plugin.requires ?? {})) {
954
- const h = a.kind === "optional" ? a.service : a;
955
- if (S(e, h), h.kind === "extension") continue;
956
- const c = t.get(h.id);
957
- if (!c) {
958
- if (a.kind === "optional") continue;
959
- throw new p(
960
- "SERVICE_MISSING",
961
- `Plugin '${o.id}' requires missing service '${h.id}'`
962
- );
1202
+ async deactivate(t) {
1203
+ const e = [], i = this.#o.filter((s) => t.has(s)).reverse();
1204
+ this.#o = this.#o.filter(
1205
+ (s) => !t.has(s)
1206
+ );
1207
+ for (const s of i) {
1208
+ const n = s.instance;
1209
+ if (n) {
1210
+ s.beginStopping(), this.#n.delete(s);
1211
+ try {
1212
+ await n.lifetime.dispose();
1213
+ } catch (o) {
1214
+ e.push(o);
1215
+ } finally {
1216
+ s.deactivate();
1217
+ }
963
1218
  }
964
- if (c === o)
965
- throw new p(
966
- "SERVICE_CYCLE",
967
- `Plugin '${o.id}' cannot require service '${h.id}' that it provides`
968
- );
969
- const d = i.get(o) ?? /* @__PURE__ */ new Map();
970
- d.set(h.id, c), i.set(o, d);
971
- const l = s.get(c) ?? /* @__PURE__ */ new Set();
972
- l.has(o) || (l.add(o), s.set(c, l), n.set(o, (n.get(o) ?? 0) + 1));
973
1219
  }
974
- return { resolvedProviders: i, dependents: s, indegree: n };
975
- }
976
- function mt(r, t, e) {
977
- let i = r.filter((o) => e.get(o) === 0);
978
- const s = [], n = [];
979
- for (; i.length; ) {
980
- i.sort((a, h) => a.index - h.index);
981
- const o = i;
982
- i = [], n.push(o), s.push(...o);
983
- for (const a of o)
984
- for (const h of t.get(a) ?? []) {
985
- const c = (e.get(h) ?? 0) - 1;
986
- e.set(h, c), c || i.push(h);
987
- }
1220
+ return e;
988
1221
  }
989
- if (s.length !== r.length) {
990
- const o = vt(r, t);
991
- throw new p(
992
- "SERVICE_CYCLE",
993
- `Plugin dependency cycle: ${o.map((a) => a.id).join(" -> ")}`
994
- );
1222
+ async withContributionBatch(t) {
1223
+ this.#r.beginBatch();
1224
+ let e;
1225
+ try {
1226
+ e = { ok: !0, value: await t() };
1227
+ } catch (s) {
1228
+ e = { ok: !1, error: s };
1229
+ }
1230
+ let i;
1231
+ try {
1232
+ this.#r.endBatch(), i = { ok: !0 };
1233
+ } catch (s) {
1234
+ i = { ok: !1, error: s };
1235
+ }
1236
+ if (!e.ok && !i.ok)
1237
+ throw new AggregateError(
1238
+ [e.error, i.error],
1239
+ "Host operation and contribution publication failed"
1240
+ );
1241
+ if (!e.ok) throw e.error;
1242
+ if (!i.ok) throw i.error;
1243
+ return e.value;
995
1244
  }
996
- return { order: s, layers: n };
997
- }
998
- function vt(r, t) {
999
- const e = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = [], n = (o) => {
1000
- i.add(o), s.push(o);
1001
- for (const a of t.get(o) ?? []) {
1002
- if (i.has(a)) {
1003
- const c = s.indexOf(a);
1004
- return [...s.slice(c), a];
1245
+ async #c(t, e, i, s, n) {
1246
+ e.deactivate();
1247
+ const o = e.declaration.plugin, a = new V(n, e.id, { parentSignal: s });
1248
+ try {
1249
+ const c = this.#l(t, e, o, a), h = {
1250
+ hostName: this.#t,
1251
+ pluginName: o.name,
1252
+ installationId: e.id,
1253
+ groupId: e.groupId
1254
+ }, d = this.#d(a, h, c), l = await o.setup(d, i), f = /* @__PURE__ */ new Map();
1255
+ for (const [p, Z] of Object.entries(o.provides ?? {})) {
1256
+ if (typeof l != "object" || l === null || !Object.hasOwn(l, p))
1257
+ throw new u(
1258
+ "SERVICE_NOT_RETURNED",
1259
+ `Installation '${e.id}' did not return provided Service '${p}'`
1260
+ );
1261
+ f.set(Z.id, l[p]);
1005
1262
  }
1006
- if (e.has(a)) continue;
1007
- const h = n(a);
1008
- if (h) return h;
1263
+ return Object.freeze({
1264
+ installation: e,
1265
+ instance: Object.freeze({ plugin: o, config: i, lifetime: a }),
1266
+ services: f
1267
+ });
1268
+ } catch (c) {
1269
+ const h = e.fail(c);
1270
+ try {
1271
+ await a.dispose();
1272
+ } catch (d) {
1273
+ throw new z(
1274
+ [h, d],
1275
+ `Installation '${e.id}' failed to start and could not be cleanly disposed`
1276
+ );
1277
+ }
1278
+ throw h;
1009
1279
  }
1010
- s.pop(), i.delete(o), e.add(o);
1011
- };
1012
- for (const o of r) {
1013
- if (e.has(o)) continue;
1014
- const a = n(o);
1015
- if (a) return a;
1016
- }
1017
- throw new TypeError("Dependency graph is cyclic but no cycle path was found");
1018
- }
1019
- function N(r, t) {
1020
- return Object.freeze({ plugin: r, config: t });
1021
- }
1022
- class bt {
1023
- constructor(t, e, i, s) {
1024
- this.id = t, this.index = e, this.groupId = i.id, this.#i = { spec: s, group: i, notifyChanged: void 0 };
1025
1280
  }
1026
- id;
1027
- index;
1028
- #t = { phase: "pending" };
1029
- #e;
1030
- #i;
1031
- groupId;
1032
- #s = /* @__PURE__ */ new Set();
1033
- attach(t) {
1034
- const e = this.#h();
1035
- if (e.notifyChanged) throw new TypeError(`Plugin '${this.id}' is already attached`);
1036
- e.notifyChanged = t;
1281
+ #f(t) {
1282
+ for (const { installation: e, instance: i, services: s } of t)
1283
+ this.#n.set(e, s), e.activate(i), this.#o.push(e);
1284
+ for (const { instance: e } of t)
1285
+ e.lifetime.publish(), e.lifetime.detachStartupSignal();
1037
1286
  }
1038
- get status() {
1039
- return this.#t.phase;
1040
- }
1041
- get runtime() {
1042
- const t = this.#t;
1043
- return t.phase === "active" || t.phase === "stopping" ? t.runtime : void 0;
1044
- }
1045
- get error() {
1046
- const t = this.#t;
1047
- if (t.phase === "failed")
1048
- return t.failure.retention === "live" ? t.failure.error : Et(t.failure.summary);
1049
- if (t.phase === "removed")
1050
- return new p("PLUGIN_REMOVED", `Plugin '${this.id}' has been removed`);
1051
- }
1052
- get group() {
1053
- return this.#h().group;
1054
- }
1055
- get spec() {
1056
- return this.#h().spec;
1057
- }
1058
- reconfigure(t) {
1059
- this.#h().spec = t;
1287
+ async #u(t) {
1288
+ const e = [];
1289
+ for (const i of [...t].reverse())
1290
+ try {
1291
+ await i.instance.lifetime.dispose();
1292
+ } catch (s) {
1293
+ e.push(s);
1294
+ }
1295
+ return e;
1060
1296
  }
1061
- ready() {
1062
- const t = this.#e;
1063
- return t ? t.barrier.then(() => this.#r()) : this.#r();
1297
+ #l(t, e, i, s) {
1298
+ const n = /* @__PURE__ */ Object.create(null);
1299
+ for (const [o, a] of Object.entries(i.requires ?? {}))
1300
+ if (a.kind === "optional") {
1301
+ const c = t.providerFor(e, a.service.id);
1302
+ if (!c) {
1303
+ n[o] = void 0;
1304
+ continue;
1305
+ }
1306
+ const h = this.#n.get(c);
1307
+ if (!h?.has(a.service.id))
1308
+ throw new u(
1309
+ "SERVICE_UNAVAILABLE",
1310
+ `Optional Service '${a.service.id}' is not active for Installation '${e.id}'`
1311
+ );
1312
+ n[o] = h.get(a.service.id);
1313
+ } else if (a.kind === "service") {
1314
+ const c = t.providerFor(e, a.id), h = c ? this.#n.get(c) : void 0;
1315
+ if (!c || !h?.has(a.id))
1316
+ throw new u(
1317
+ "SERVICE_UNAVAILABLE",
1318
+ `Service '${a.id}' is not active for Installation '${e.id}'`
1319
+ );
1320
+ n[o] = h.get(a.id);
1321
+ } else
1322
+ n[o] = this.#b(a, s);
1323
+ return n;
1064
1324
  }
1065
- trackReadiness(t) {
1066
- const e = {}, i = t.then(
1067
- () => {
1068
- this.#e?.attempt === e && (this.#e = void 0);
1325
+ #d(t, e, i) {
1326
+ return Object.freeze({
1327
+ ...i,
1328
+ get signal() {
1329
+ return t.signal;
1069
1330
  },
1070
- (s) => {
1071
- if (this.#e?.attempt === e && (this.#e = void 0), this.#t.phase !== "active") throw s;
1072
- }
1073
- );
1074
- this.#e = { attempt: e, barrier: i }, i.catch(() => {
1075
- });
1076
- }
1077
- #r() {
1078
- const t = this.#t;
1079
- if ((t.phase === "active" || t.phase === "failed" || t.phase === "removed") && t.readiness === "settled") {
1080
- if (t.phase === "active") return Promise.resolve();
1081
- if (t.phase === "failed" || t.phase === "removed")
1082
- return Promise.reject(
1083
- this.error ?? new p("PLUGIN_UNAVAILABLE", `Plugin '${this.id}' is ${t.phase}`)
1084
- );
1085
- }
1086
- return new Promise((e, i) => {
1087
- this.#s.add({ resolve: e, reject: i });
1331
+ meta: Object.freeze(e),
1332
+ log: this.#e,
1333
+ cleanup: t.cleanup.bind(t),
1334
+ lifetime: t.lifetime.bind(t),
1335
+ spawn: t.spawn.bind(t),
1336
+ on: t.on.bind(t),
1337
+ emit: t.emit.bind(t),
1338
+ contribute: t.contribute.bind(t)
1088
1339
  });
1089
1340
  }
1090
- activate(t) {
1091
- this.#a({ phase: "active", runtime: t, readiness: "unsettled" });
1092
- }
1093
- settleReady() {
1094
- const t = this.#t;
1095
- if (!(t.phase !== "active" && t.phase !== "failed" && t.phase !== "removed") && t.readiness !== "settled") {
1096
- if (this.#t = { ...t, readiness: "settled" }, t.phase === "active")
1097
- for (const e of this.#s) e.resolve();
1098
- else {
1099
- const e = this.error ?? new p("PLUGIN_UNAVAILABLE", `Plugin '${this.id}' is ${t.phase}`);
1100
- for (const i of this.#s) i.reject(e);
1101
- }
1102
- this.#s.clear();
1103
- }
1104
- }
1105
- beginStopping() {
1106
- const t = this.#t;
1107
- return t.phase !== "active" ? !1 : (this.#a({ phase: "stopping", runtime: t.runtime }), !0);
1108
- }
1109
- deactivate() {
1110
- this.#a({ phase: "pending" });
1111
- }
1112
- fail(t) {
1113
- this.#n(t);
1114
- }
1115
- discard(t) {
1116
- const e = this.#o(t);
1117
- this.#a({
1118
- phase: "failed",
1119
- failure: { retention: "summary", summary: yt(e) },
1120
- readiness: "settled"
1121
- });
1122
- for (const i of this.#s) i.reject(e);
1123
- this.#s.clear(), this.#e = void 0, this.#i = void 0;
1341
+ #h(t) {
1342
+ return {
1343
+ stageOn: (e, i, s, n) => this.#p(e, i, s, n, t),
1344
+ emit: (e, i, s) => this.#g(e, i, s, t),
1345
+ stageContribution: (e, i, s, n, o) => this.#v(e, i, s, n, o, t),
1346
+ report: this.#s
1347
+ };
1124
1348
  }
1125
- #n(t) {
1126
- const e = this.#o(t);
1127
- return this.#a({
1128
- phase: "failed",
1129
- failure: { retention: "live", error: e },
1130
- readiness: "unsettled"
1131
- }), e;
1349
+ #p(t, e, i, s, n) {
1350
+ return this.#w(t), y(e, "event"), n.remember(e), this.#a.stage(e.id, i, s);
1132
1351
  }
1133
- remove() {
1134
- this.#a({ phase: "removed", readiness: "unsettled" }), this.#e = void 0, this.#i = void 0;
1352
+ #g(t, e, i, s) {
1353
+ return this.#w(t), y(e, "event"), s.remember(e), this.#a.emit(e.id, i);
1135
1354
  }
1136
- #a(t) {
1137
- this.#t = t, this.#i?.notifyChanged?.();
1355
+ #v(t, e, i, s, n, o) {
1356
+ return this.#w(t), y(e, "extensionPoint"), o.remember(e), this.#r.get(e).stage(t, i, s, n);
1138
1357
  }
1139
- #o(t) {
1140
- return $(
1141
- t,
1142
- "PLUGIN_UNAVAILABLE",
1143
- `Plugin '${this.id}' failed with a non-Error value`
1144
- );
1358
+ #b(t, e) {
1359
+ return this.#r.get(t).view((i, s) => e.ownLease(i, s));
1145
1360
  }
1146
- #h() {
1147
- const t = this.#i;
1148
- if (!t) throw new TypeError(`Plugin '${this.id}' is no longer installed`);
1149
- return t;
1361
+ #w(t) {
1362
+ if (!this.#i(t))
1363
+ throw new Error(`Installation '${t}' is not installed`);
1150
1364
  }
1151
1365
  }
1152
- function yt(r) {
1153
- return r instanceof p ? { name: r.name, message: r.message, code: r.code } : { name: r.name, message: r.message };
1154
- }
1155
- function Et(r) {
1156
- const t = r.code === void 0 ? new Error(r.message) : new p(r.code, r.message);
1157
- return t.name = r.name, t;
1158
- }
1159
- class O extends AggregateError {
1366
+ function zt(r, t) {
1367
+ const e = [];
1368
+ let i = !1;
1369
+ for (const s of r)
1370
+ s.status !== "fulfilled" && (Object.is(s.reason, t.reason) ? (i || e.push(s.reason), i = !0) : Y(t, s.reason) || e.push(s.reason));
1371
+ return e;
1160
1372
  }
1161
- class Ct {
1162
- #t;
1373
+ class Rt {
1374
+ #t = new nt();
1163
1375
  #e;
1164
1376
  #i;
1165
- #s;
1166
- #r = /* @__PURE__ */ new Map();
1167
- #n = new K();
1168
- #a = new J();
1169
- #o;
1170
- #h;
1171
- #c = [];
1172
1377
  constructor(t) {
1173
- this.#t = t.applicationName, this.#e = t.logger, this.#i = t.isInstalled, this.#s = t.report, this.#o = new rt(t.report);
1378
+ this.#e = new Lt(t);
1174
1379
  }
1175
1380
  get hasCommittedPlan() {
1176
- return this.#h !== void 0;
1381
+ return this.#i !== void 0;
1177
1382
  }
1178
1383
  get(t, e) {
1179
- if (v(t, "service"), this.#n.assertCompatible(t), e === "unavailable")
1180
- throw M();
1181
- const i = this.#I().provider(t.id), s = i ? this.#r.get(i) : void 0;
1182
- if (!i || !s?.has(t.id))
1183
- throw new p("SERVICE_UNAVAILABLE", `Service '${t.id}' is not active`);
1184
- return s.get(t.id);
1384
+ if (y(t, "service"), this.#t.assertCompatible(t), e === "unavailable") throw B();
1385
+ const i = this.#o().provider(t.id);
1386
+ if (!i)
1387
+ throw new u("SERVICE_UNAVAILABLE", `Service '${t.id}' is not active`);
1388
+ const s = this.#e.readService(i, t.id);
1389
+ if (!s.found)
1390
+ throw new u("SERVICE_UNAVAILABLE", `Service '${t.id}' is not active`);
1391
+ return s.value;
1185
1392
  }
1186
1393
  buildPlan(t) {
1187
- return z.build(t, this.#n.kinds);
1394
+ return x.build(t, this.#t.kinds);
1188
1395
  }
1189
1396
  async start(t) {
1190
- const e = this.#n.draft(t.contractKinds);
1397
+ const e = this.#t.draft(t.contractKinds);
1191
1398
  try {
1192
- await this.#j(() => this.#p(t, e)), this.#h = t;
1399
+ await this.#e.withContributionBatch(() => this.#s(t, e)), this.#i = t;
1193
1400
  } catch (i) {
1194
- throw e.discard(), this.#h = void 0, i;
1401
+ throw e.discard(), this.#i = void 0, i;
1195
1402
  }
1196
1403
  }
1197
1404
  async stop() {
1198
- const t = await this.#j(
1199
- () => this.#f(new Set(this.#c))
1200
- );
1201
- return this.#h = void 0, t;
1405
+ const t = await this.#e.withContributionBatch(() => this.#e.deactivateAll());
1406
+ return this.#i = void 0, t;
1202
1407
  }
1203
1408
  async transition(t, e, i) {
1204
- return this.#j(async () => {
1205
- const s = this.#I(), n = s.affectedByTransitionTo(t, e);
1409
+ return this.#e.withContributionBatch(async () => {
1410
+ const s = this.#o(), n = s.affectedByTransitionTo(t, e);
1206
1411
  let o, a;
1207
1412
  try {
1208
- o = await this.#v(
1413
+ o = await this.#r(
1209
1414
  t.order.filter((d) => n.has(d))
1210
- ), a = this.#n.draft(t.contractKinds);
1415
+ ), a = this.#t.draft(t.contractKinds);
1211
1416
  } catch (d) {
1212
1417
  throw i(), d;
1213
1418
  }
1214
- const h = /* @__PURE__ */ new Map();
1215
- for (const d of n) {
1216
- const l = d.runtime;
1217
- l && h.set(d, l.config);
1218
- }
1219
- const c = await this.#f(n);
1220
- if (c.length)
1221
- return a.discard(), this.#g(
1419
+ const c = this.#e.captureConfigs(n), h = await this.#e.deactivate(n);
1420
+ if (h.length)
1421
+ return a.discard(), this.#n(
1222
1422
  i,
1223
- c,
1224
- "Plugin change could not cleanly stop the affected runtime"
1423
+ h,
1424
+ "Installation change could not cleanly stop the affected Instances"
1225
1425
  );
1226
1426
  try {
1227
- return await this.#d(t, n, o, a), a.commit(), this.#c = t.order.slice(), this.#h = t, Object.freeze({ kind: "committed", affected: n });
1427
+ return await this.#e.activate(t, n, o, a), a.commit(), this.#e.commitActivationOrder(t.order), this.#i = t, Object.freeze({ kind: "committed", affected: n });
1228
1428
  } catch (d) {
1229
- const l = await this.#f(n);
1230
- return a.discard(), d instanceof O || l.length ? this.#g(
1429
+ const l = await this.#e.deactivate(n);
1430
+ return a.discard(), d instanceof z || l.length ? this.#n(
1231
1431
  i,
1232
1432
  [d, ...l],
1233
- "Plugin change failed and its partial runtime could not be cleanly disposed"
1234
- ) : this.#l(i, s, n, h, [
1433
+ "Installation change failed and its partial activation could not be cleanly disposed"
1434
+ ) : this.#a(i, s, n, c, [
1235
1435
  d,
1236
1436
  ...l
1237
1437
  ]);
1238
1438
  }
1239
1439
  });
1240
1440
  }
1241
- async #p(t, e) {
1242
- const i = new Set(t.order), s = await this.#v(t.order);
1243
- this.#r.clear(), this.#c = [];
1441
+ async #s(t, e) {
1442
+ const i = new Set(t.order), s = await this.#r(t.order);
1443
+ this.#e.resetActivationState();
1244
1444
  try {
1245
- await this.#d(t, i, s, e), e.commit(), this.#c = t.order.slice();
1445
+ await this.#e.activate(t, i, s, e), e.commit(), this.#e.commitActivationOrder(t.order);
1246
1446
  } catch (n) {
1247
- const o = await this.#f(i);
1248
- throw o.length ? new AggregateError([n, ...o], "Application startup failed") : n;
1447
+ const o = await this.#e.deactivate(i);
1448
+ throw o.length ? new AggregateError([n, ...o], "Host startup failed") : n;
1249
1449
  }
1250
1450
  }
1251
- async #g(t, e, i) {
1451
+ async #n(t, e, i) {
1252
1452
  t();
1253
- const s = await this.#f(new Set(this.#c));
1254
- throw this.#h = void 0, new AggregateError([...e, ...s], i);
1453
+ const s = await this.#e.deactivateAll();
1454
+ throw this.#i = void 0, new AggregateError([...e, ...s], i);
1255
1455
  }
1256
- async #l(t, e, i, s, n) {
1456
+ async #a(t, e, i, s, n) {
1257
1457
  t();
1258
- const o = this.#n.draft(e.contractKinds);
1458
+ const o = this.#t.draft(e.contractKinds);
1259
1459
  try {
1260
- await this.#d(e, i, s, o), o.commit(), this.#c = e.order.slice(), this.#h = e;
1261
- } catch (h) {
1262
- const c = await this.#f(new Set(this.#c));
1263
- throw o.discard(), this.#h = void 0, new AggregateError(
1264
- [...n, h, ...c],
1265
- "Plugin change failed and the previous application could not be restored"
1460
+ await this.#e.activate(e, i, s, o), o.commit(), this.#e.commitActivationOrder(e.order), this.#i = e;
1461
+ } catch (c) {
1462
+ const h = await this.#e.deactivateAll();
1463
+ throw o.discard(), this.#i = void 0, new AggregateError(
1464
+ [...n, c, ...h],
1465
+ "Installation change failed and the previous Instances could not be restored"
1266
1466
  );
1267
1467
  }
1268
- const a = n.length === 1 ? n[0] : new AggregateError(n, "Plugin change failed");
1468
+ const a = n.length === 1 ? n[0] : new AggregateError(n, "Installation change failed");
1269
1469
  return Object.freeze({ kind: "rolled-back", affected: i, error: a });
1270
1470
  }
1271
- async #d(t, e, i, s) {
1272
- const n = this.#E(s);
1273
- for (const o of t.layers) {
1274
- const a = o.filter(
1275
- (u) => e.has(u) && !u.runtime
1276
- );
1277
- if (!a.length) continue;
1278
- const h = new AbortController(), c = await Promise.allSettled(
1279
- a.map(async (u) => {
1280
- try {
1281
- const f = i.has(u) ? i.get(u) : await this.#y(
1282
- u.spec.plugin.config,
1283
- u.spec.config
1284
- );
1285
- return await this.#b(
1286
- t,
1287
- u,
1288
- f,
1289
- h.signal,
1290
- n
1291
- );
1292
- } catch (f) {
1293
- throw h.abort(f), f;
1294
- }
1295
- })
1296
- ), d = c.filter((u) => u.status === "rejected").map((u) => u.reason), l = c.filter(
1297
- (u) => u.status === "fulfilled"
1298
- ).map((u) => u.value);
1299
- if (d.length) {
1300
- const u = await this.#O(l), f = d.length === 1 ? d[0] : new AggregateError(d, "Plugin startup layer failed");
1301
- throw u.length ? new O(
1302
- [f, ...u],
1303
- "Plugin startup layer failed and could not be cleanly disposed"
1304
- ) : f;
1305
- }
1306
- for (const u of l) this.#w(u);
1307
- }
1308
- }
1309
- async #b(t, e, i, s, n) {
1310
- e.deactivate();
1311
- const o = e.spec.plugin, a = new L(n, e.id, { parentSignal: s });
1312
- try {
1313
- const h = this.#C(t, e, o, a), c = {
1314
- applicationName: this.#t,
1315
- pluginName: o.name,
1316
- installationId: e.id,
1317
- groupId: e.groupId
1318
- }, d = this.#T(a, c, h), l = await o.setup(d, i), u = /* @__PURE__ */ new Map();
1319
- for (const [f, _] of Object.entries(o.provides ?? {})) {
1320
- if (typeof l != "object" || l === null || !Object.hasOwn(l, f))
1321
- throw new p(
1322
- "SERVICE_NOT_RETURNED",
1323
- `Plugin '${e.id}' did not return provided service '${f}'`
1324
- );
1325
- u.set(_.id, l[f]);
1326
- }
1327
- return Object.freeze({
1328
- installation: e,
1329
- runtime: Object.freeze({ plugin: o, config: i, lifetime: a }),
1330
- services: u
1331
- });
1332
- } catch (h) {
1333
- e.fail(h);
1471
+ async #r(t) {
1472
+ const e = /* @__PURE__ */ new Map();
1473
+ for (const i of t)
1334
1474
  try {
1335
- await a.dispose();
1336
- } catch (c) {
1337
- throw new O(
1338
- [h, c],
1339
- `Plugin '${e.id}' failed to start and could not be cleanly disposed`
1475
+ e.set(
1476
+ i,
1477
+ await Q(
1478
+ i.declaration.plugin.config,
1479
+ i.declaration.config,
1480
+ i.id
1481
+ )
1340
1482
  );
1341
- }
1342
- throw h;
1343
- }
1344
- }
1345
- #w(t) {
1346
- const { installation: e, runtime: i, services: s } = t;
1347
- this.#r.set(e, s), i.lifetime.publish(), i.lifetime.detachStartupSignal(), e.activate(i), this.#c.push(e);
1348
- }
1349
- async #O(t) {
1350
- const e = [];
1351
- for (const i of [...t].reverse())
1352
- try {
1353
- await i.runtime.lifetime.dispose();
1354
1483
  } catch (s) {
1355
- e.push(s);
1356
- }
1357
- return e;
1358
- }
1359
- async #f(t) {
1360
- const e = [], i = this.#c.filter((s) => t.has(s)).reverse();
1361
- this.#c = this.#c.filter(
1362
- (s) => !t.has(s)
1363
- );
1364
- for (const s of i) {
1365
- const n = s.runtime;
1366
- if (n) {
1367
- s.beginStopping(), this.#r.delete(s);
1368
- try {
1369
- await n.lifetime.dispose();
1370
- } catch (o) {
1371
- e.push(o);
1372
- } finally {
1373
- s.deactivate();
1374
- }
1484
+ throw A(
1485
+ s,
1486
+ "INSTALLATION_UNAVAILABLE",
1487
+ `Installation '${i.id}' failed with a non-Error value`
1488
+ );
1375
1489
  }
1376
- }
1377
1490
  return e;
1378
1491
  }
1379
- async #v(t) {
1380
- const e = /* @__PURE__ */ new Map();
1381
- for (const i of t)
1382
- e.set(
1383
- i,
1384
- await this.#y(i.spec.plugin.config, i.spec.config)
1385
- );
1386
- return e;
1387
- }
1388
- #C(t, e, i, s) {
1389
- const n = /* @__PURE__ */ Object.create(null);
1390
- for (const [o, a] of Object.entries(i.requires ?? {}))
1391
- if (a.kind === "optional") {
1392
- const h = t.providerFor(e, a.service.id);
1393
- if (!h) {
1394
- n[o] = void 0;
1395
- continue;
1396
- }
1397
- const c = this.#r.get(h);
1398
- if (!c?.has(a.service.id))
1399
- throw new p(
1400
- "SERVICE_UNAVAILABLE",
1401
- `Optional service '${a.service.id}' is not active for plugin '${e.id}'`
1402
- );
1403
- n[o] = c.get(a.service.id);
1404
- } else if (a.kind === "service") {
1405
- const h = t.providerFor(e, a.id), c = h ? this.#r.get(h) : void 0;
1406
- if (!h || !c?.has(a.id))
1407
- throw new p(
1408
- "SERVICE_UNAVAILABLE",
1409
- `Service '${a.id}' is not active for plugin '${e.id}'`
1410
- );
1411
- n[o] = c.get(a.id);
1412
- } else
1413
- n[o] = this.#u(a, s);
1414
- return n;
1415
- }
1416
- #T(t, e, i) {
1417
- return Object.freeze({
1418
- ...i,
1419
- get signal() {
1420
- return t.signal;
1421
- },
1422
- meta: Object.freeze(e),
1423
- log: this.#e,
1424
- cleanup: t.cleanup.bind(t),
1425
- lifetime: t.lifetime.bind(t),
1426
- spawn: t.spawn.bind(t),
1427
- on: t.on.bind(t),
1428
- emit: t.emit.bind(t),
1429
- contribute: t.contribute.bind(t)
1430
- });
1431
- }
1432
- async #y(t, e) {
1433
- if (!t) return e;
1434
- const i = await t["~standard"].validate(e);
1435
- if (i.issues)
1436
- throw new H(
1437
- i.issues.map((s) => ({
1438
- message: s.message,
1439
- ...s.path ? { path: s.path } : {}
1440
- }))
1441
- );
1442
- return i.value;
1443
- }
1444
- #E(t) {
1445
- return {
1446
- stageOn: (e, i, s, n) => this.#A(e, i, s, n, t),
1447
- emit: (e, i, s) => this.#P(e, i, s, t),
1448
- stageContribution: (e, i, s, n, o) => this.#S(e, i, s, n, o, t),
1449
- report: this.#s
1450
- };
1451
- }
1452
- #A(t, e, i, s, n) {
1453
- return this.#m(t), v(e, "event"), n.remember(e), this.#a.stage(e.id, i, s);
1454
- }
1455
- #P(t, e, i, s) {
1456
- return this.#m(t), v(e, "event"), s.remember(e), this.#a.emit(e.id, i);
1457
- }
1458
- #S(t, e, i, s, n, o) {
1459
- return this.#m(t), v(e, "extension"), o.remember(e), this.#o.get(e).stage(t, i, s, n);
1460
- }
1461
- #u(t, e) {
1462
- return this.#o.get(t).view((i, s) => e.ownLease(i, s));
1463
- }
1464
- #m(t) {
1465
- if (!this.#i(t)) throw new TypeError(`Plugin '${t}' is not installed`);
1466
- }
1467
- async #j(t) {
1468
- this.#o.beginBatch();
1469
- try {
1470
- return await t();
1471
- } finally {
1472
- this.#o.endBatch();
1473
- }
1474
- }
1475
- #I() {
1476
- if (!this.#h)
1477
- throw M();
1478
- return this.#h;
1492
+ #o() {
1493
+ if (!this.#i) throw B();
1494
+ return this.#i;
1479
1495
  }
1480
1496
  }
1481
- function M() {
1482
- return new p("SERVICE_UNAVAILABLE", "Application services are not active");
1497
+ function B() {
1498
+ return new u("SERVICE_UNAVAILABLE", "Host services are not active");
1483
1499
  }
1484
- class Pt {
1500
+ class Nt {
1485
1501
  #t;
1486
1502
  #e;
1487
1503
  #i;
1488
1504
  #s = 0;
1489
1505
  view;
1490
1506
  constructor(t, e, i) {
1491
- this.#t = t, this.#i = this.#r("idle", [], e), this.#e = new U(() => this.#i, i), this.view = this.#e.view;
1507
+ this.#t = t, this.#i = this.#n("idle", [], e), this.#e = new q(() => this.#i, i), this.view = this.#e.view;
1492
1508
  }
1493
1509
  publish(t, e, i) {
1494
- this.#s++, this.#i = this.#r(t, e, i), this.#e.invalidate();
1510
+ this.#s++, this.#i = this.#n(t, e, i), this.#e.invalidate();
1495
1511
  }
1496
- #r(t, e, i) {
1512
+ #n(t, e, i) {
1497
1513
  const s = /* @__PURE__ */ new Map();
1498
1514
  for (const o of e) {
1499
1515
  const a = {
1500
1516
  id: o.id,
1501
- name: o.spec.plugin.name,
1517
+ pluginName: o.declaration.plugin.name,
1502
1518
  groupId: o.groupId,
1503
1519
  status: o.status,
1504
1520
  requires: Object.freeze(
1505
- Object.values(o.spec.plugin.requires ?? {}).map((c) => c.kind === "optional" ? c.service.id : c.id)
1521
+ Object.values(o.declaration.plugin.requires ?? {}).map((h) => h.kind === "optional" ? h.service.id : h.id)
1506
1522
  ),
1507
1523
  provides: Object.freeze(
1508
- Object.values(o.spec.plugin.provides ?? {}).map((c) => c.id)
1524
+ Object.values(o.declaration.plugin.provides ?? {}).map((h) => h.id)
1509
1525
  ),
1510
- ...o.runtime ? { lifetime: o.runtime.lifetime.diagnostics } : {}
1511
- }, h = o.error;
1526
+ ...o.instance ? { lifetime: o.instance.lifetime.diagnostics } : {}
1527
+ }, c = o.error;
1512
1528
  s.set(
1513
1529
  o.id,
1514
- Object.freeze(h === void 0 ? a : { ...a, error: h })
1530
+ Object.freeze(c === void 0 ? a : { ...a, error: c })
1515
1531
  );
1516
1532
  }
1517
1533
  const n = /* @__PURE__ */ new Map();
@@ -1526,12 +1542,28 @@ class Pt {
1526
1542
  name: this.#t,
1527
1543
  status: t,
1528
1544
  revision: this.#s,
1529
- plugins: new C(s),
1530
- groups: new C(n)
1545
+ installations: new O(s),
1546
+ groups: new O(n)
1531
1547
  });
1532
1548
  }
1533
1549
  }
1534
- const St = /* @__PURE__ */ new Set([
1550
+ function T(r, t, e = {}) {
1551
+ if (!r || typeof r != "object" || Array.isArray(r))
1552
+ throw m(e, `${t} must be a plain record`);
1553
+ const i = Object.getPrototypeOf(r);
1554
+ if (i !== Object.prototype && i !== null)
1555
+ throw m(e, `${t} must be a plain record`);
1556
+ for (const s of Reflect.ownKeys(r)) {
1557
+ if (typeof s != "string" || !Object.prototype.propertyIsEnumerable.call(r, s))
1558
+ throw m(e, `${t} keys must be enumerable strings`);
1559
+ if (e.fields && !e.fields.has(s))
1560
+ throw m(e, `${t}: unknown field '${s}'`);
1561
+ }
1562
+ }
1563
+ function m(r, t) {
1564
+ return r.createError?.(t) ?? new TypeError(t);
1565
+ }
1566
+ const xt = /* @__PURE__ */ new Set([
1535
1567
  "signal",
1536
1568
  "meta",
1537
1569
  "log",
@@ -1541,138 +1573,184 @@ const St = /* @__PURE__ */ new Set([
1541
1573
  "on",
1542
1574
  "emit",
1543
1575
  "contribute"
1544
- ]);
1545
- function q(r) {
1546
- if (typeof r?.name != "string" || !r.name.trim())
1576
+ ]), qt = /* @__PURE__ */ new Set(["name", "config", "requires", "provides", "setup"]);
1577
+ function Vt(r) {
1578
+ Mt(r);
1579
+ const t = Object.hasOwn(r, "name") ? r.name : void 0, e = Object.hasOwn(r, "config") ? r.config : void 0, i = Object.hasOwn(r, "requires") ? r.requires : void 0, s = Object.hasOwn(r, "provides") ? r.provides : void 0, n = Object.hasOwn(r, "setup") ? r.setup : void 0;
1580
+ if (typeof t != "string" || !t.trim())
1547
1581
  throw new TypeError("Plugin name must be a non-empty string");
1548
- if (r.name !== r.name.trim())
1582
+ if (t !== t.trim())
1549
1583
  throw new TypeError("Plugin name cannot start or end with whitespace");
1550
- if (typeof r.setup != "function")
1551
- throw new TypeError(`Plugin '${r.name}' must define setup()`);
1552
- if (r.config !== void 0 && typeof r.config["~standard"]?.validate != "function")
1553
- throw new TypeError(`Plugin '${r.name}' config must implement Standard Schema`);
1554
- for (const [i, s] of Object.entries(r.requires ?? {})) {
1555
- if (!i.trim()) throw new TypeError("Plugin requirement alias cannot be empty");
1556
- if (i !== i.trim())
1584
+ if (typeof n != "function")
1585
+ throw new TypeError(`Plugin '${t}' must define setup()`);
1586
+ if (e !== void 0 && !Dt(e))
1587
+ throw new TypeError(`Plugin '${t}' config must implement Standard Schema V1`);
1588
+ F(i, t, "requires"), F(s, t, "provides");
1589
+ const o = i ? Object.freeze({ ...i }) : void 0, a = s ? Object.freeze({ ...s }) : void 0, c = /* @__PURE__ */ new Map();
1590
+ for (const [h, d] of Object.entries(o ?? {})) {
1591
+ if (!h.trim()) throw new TypeError("Plugin requirement alias cannot be empty");
1592
+ if (h !== h.trim())
1557
1593
  throw new TypeError("Plugin requirement alias cannot start or end with whitespace");
1558
- if (St.has(i))
1559
- throw new TypeError(`Plugin requirement '${i}' conflicts with the context API`);
1560
- if (!s || typeof s != "object")
1561
- throw new TypeError(`Plugin requirement '${i}' is not a contract`);
1562
- if (s.kind === "optional") {
1563
- if (!w(s.service, "service"))
1564
- throw new TypeError(`Optional requirement '${i}' must wrap a service contract`);
1565
- } else if (!w(s, "service") && !w(s, "extension"))
1566
- throw new TypeError(`Plugin requirement '${i}' must be a service or extension contract`);
1567
- }
1568
- for (const [i, s] of Object.entries(r.provides ?? {})) {
1569
- if (!i.trim()) throw new TypeError("Plugin provision alias cannot be empty");
1570
- if (i !== i.trim())
1594
+ if (xt.has(h))
1595
+ throw new TypeError(`Plugin requirement '${h}' conflicts with the context API`);
1596
+ if (!d || typeof d != "object")
1597
+ throw new TypeError(`Plugin requirement '${h}' is not a contract`);
1598
+ if (d.kind === "optional") {
1599
+ if (!w(d.service, "service"))
1600
+ throw new TypeError(`Optional requirement '${h}' must wrap a Service`);
1601
+ } else if (!w(d, "service") && !w(d, "extensionPoint"))
1602
+ throw new TypeError(`Plugin requirement '${h}' must be a Service or ExtensionPoint`);
1603
+ U(
1604
+ t,
1605
+ c,
1606
+ "requirement",
1607
+ h,
1608
+ d.kind === "optional" ? d.service : d
1609
+ );
1610
+ }
1611
+ for (const [h, d] of Object.entries(a ?? {})) {
1612
+ if (!h.trim()) throw new TypeError("Plugin provision alias cannot be empty");
1613
+ if (h !== h.trim())
1571
1614
  throw new TypeError("Plugin provision alias cannot start or end with whitespace");
1572
- if (!w(s, "service"))
1573
- throw new TypeError(`Plugin provision '${i}' must be a service contract`);
1615
+ if (!w(d, "service"))
1616
+ throw new TypeError(`Plugin provision '${h}' must be a Service`);
1617
+ U(t, c, "provision", h, d);
1574
1618
  }
1575
- const t = r.requires ? Object.freeze({ ...r.requires }) : void 0, e = r.provides ? Object.freeze({ ...r.provides }) : void 0;
1576
1619
  return Object.freeze({
1577
- ...r,
1578
- ...t ? { requires: t } : {},
1579
- ...e ? { provides: e } : {}
1620
+ name: t,
1621
+ ...e === void 0 ? {} : { config: e },
1622
+ ...o ? { requires: o } : {},
1623
+ ...a ? { provides: a } : {},
1624
+ setup: n
1580
1625
  });
1581
1626
  }
1582
- const j = /* @__PURE__ */ new WeakMap();
1583
- function Ot(r, t) {
1584
- j.get(r)?.(t);
1627
+ function Mt(r) {
1628
+ T(r, "Plugin declaration", { fields: qt });
1585
1629
  }
1586
- class Tt {
1630
+ function Dt(r) {
1631
+ if (!r || typeof r != "object" && typeof r != "function") return !1;
1632
+ const t = r["~standard"];
1633
+ if (!t || typeof t != "object") return !1;
1634
+ const e = t;
1635
+ return e.version === 1 && typeof e.vendor == "string" && typeof e.validate == "function";
1636
+ }
1637
+ function F(r, t, e) {
1638
+ r !== void 0 && T(r, `Plugin '${t}' ${e}`);
1639
+ }
1640
+ function U(r, t, e, i, s) {
1641
+ const n = t.get(s.id);
1642
+ if (!n) {
1643
+ t.set(s.id, { alias: i, kind: s.kind, role: e });
1644
+ return;
1645
+ }
1646
+ if (n.kind !== s.kind)
1647
+ throw new TypeError(
1648
+ `Plugin '${r}' uses Contract '${s.id}' as both ${k(n.kind)} and ${k(s.kind)}`
1649
+ );
1650
+ const o = k(s.kind);
1651
+ throw n.role !== e ? new TypeError(
1652
+ `Plugin '${r}' cannot both require and provide ${o} '${s.id}'`
1653
+ ) : new TypeError(
1654
+ `Plugin '${r}' ${e} aliases '${n.alias}' and '${i}' reference the same ${o} '${s.id}'`
1655
+ );
1656
+ }
1657
+ function k(r) {
1658
+ return r === "extensionPoint" ? "ExtensionPoint" : r === "event" ? "Event" : "Service";
1659
+ }
1660
+ function _(r) {
1661
+ return Vt(r);
1662
+ }
1663
+ const Gt = /* @__PURE__ */ new Set(["plugin", "config"]), R = /* @__PURE__ */ new WeakMap();
1664
+ function Bt(r, t) {
1665
+ R.get(r)?.(t);
1666
+ }
1667
+ class Ft {
1587
1668
  #t = /* @__PURE__ */ new Map();
1588
1669
  #e;
1589
1670
  constructor(t) {
1590
- this.#e = { phase: "open", host: t }, j.set(this, (e) => this.#i(e)), Object.freeze(this);
1671
+ this.#e = { phase: "open", port: t }, R.set(this, (e) => this.#i(e)), Object.freeze(this);
1591
1672
  }
1592
1673
  install(t, ...e) {
1593
- const i = this.#r(), s = q(t), n = i.create(s, e[0]);
1594
- return this.#s({ kind: "install", installation: n.installation }), n.handle;
1674
+ const i = this.#n(), s = _(t), n = i.create(s, e[0]);
1675
+ return this.#s({ kind: "install", installation: n.record }), n.publicInstallation;
1595
1676
  }
1596
1677
  update(t, e) {
1597
- const i = this.#r();
1598
- if (!e || typeof e != "object")
1599
- throw new TypeError("Plugin update must be an object");
1678
+ const i = this.#n();
1679
+ T(e, "Installation update", { fields: Gt });
1600
1680
  const s = Object.hasOwn(e, "plugin"), n = Object.hasOwn(e, "config");
1601
1681
  if (!s && !n)
1602
- throw new TypeError("Plugin update must include 'plugin' or 'config'");
1682
+ throw new TypeError("Installation update must include 'plugin' or 'config'");
1603
1683
  const o = i.resolve(t);
1604
1684
  let a;
1605
1685
  if (s) {
1606
1686
  const d = e.plugin;
1607
- if (!d) throw new TypeError("Plugin update 'plugin' must be a plugin definition");
1608
- a = q(d);
1687
+ if (!d) throw new TypeError("Installation update 'plugin' must be a Plugin");
1688
+ a = _(d);
1609
1689
  }
1610
- let h;
1611
- a && n ? h = { kind: "plugin-and-config", plugin: a, config: e.config } : a ? h = { kind: "plugin", plugin: a } : h = { kind: "config", config: e.config };
1612
- const c = { kind: "update", installation: o, declaration: h };
1613
- return this.#s(c), this;
1690
+ let c;
1691
+ a && n ? c = { kind: "plugin-and-config", plugin: a, config: e.config } : a ? c = { kind: "plugin", plugin: a } : c = { kind: "config", config: e.config };
1692
+ const h = { kind: "update", installation: o, declaration: c };
1693
+ return this.#s(h), this;
1614
1694
  }
1615
1695
  remove(t) {
1616
- const e = this.#r();
1696
+ const e = this.#n();
1617
1697
  return this.#s({ kind: "remove", installation: e.resolve(t) }), this;
1618
1698
  }
1619
1699
  commit() {
1620
1700
  const t = this.#e;
1621
1701
  if (t.phase === "submitted") return t.promise;
1622
1702
  if (t.phase === "discarded")
1623
- throw new TypeError("Cannot commit a discarded ChangeSet");
1703
+ throw new Error("Cannot commit a discarded ChangeSet");
1624
1704
  if (t.phase === "committing")
1625
- throw new TypeError("Core ChangeSet commit is already being prepared");
1705
+ throw new Error("Core ChangeSet commit is already being prepared");
1626
1706
  this.#e = { phase: "committing" };
1627
- const e = Object.freeze([...this.#t.values()]), i = t.host;
1707
+ const e = Object.freeze([...this.#t.values()]), i = t.port;
1628
1708
  try {
1629
1709
  for (const n of e)
1630
1710
  n.kind === "install" && i.attach(n.installation);
1631
1711
  } catch (n) {
1632
1712
  for (const o of e)
1633
1713
  o.kind === "install" && i.discard(o.installation, n);
1634
- return this.#n(Promise.reject(n));
1714
+ return this.#a(Promise.reject(n));
1635
1715
  }
1636
- if (!e.length)
1637
- return this.#n(Promise.resolve());
1638
1716
  let s;
1639
1717
  try {
1640
1718
  s = i.execute(e);
1641
1719
  } catch (n) {
1642
1720
  s = Promise.reject(n);
1643
1721
  }
1644
- return this.#n(s);
1722
+ return this.#a(s);
1645
1723
  }
1646
1724
  #i(t) {
1647
1725
  const e = this.#e;
1648
1726
  if (e.phase !== "open") return;
1649
1727
  this.#e = { phase: "discarded" };
1650
1728
  const i = [...this.#t.values()];
1651
- this.#a();
1729
+ this.#r();
1652
1730
  for (const s of i)
1653
- s.kind === "install" && e.host.discard(s.installation, t);
1731
+ s.kind === "install" && e.port.discard(s.installation, t);
1654
1732
  }
1655
1733
  #s(t) {
1656
1734
  if (this.#t.has(t.installation))
1657
1735
  throw new TypeError(
1658
- `Plugin '${t.installation.id}' can only appear once in the same ChangeSet`
1736
+ `Installation '${t.installation.id}' can only appear once in the same ChangeSet`
1659
1737
  );
1660
1738
  this.#t.set(t.installation, Object.freeze(t));
1661
1739
  }
1662
- #r() {
1740
+ #n() {
1663
1741
  const t = this.#e;
1664
1742
  if (t.phase !== "open")
1665
1743
  throw new TypeError(`Cannot modify a ${t.phase} ChangeSet`);
1666
- return t.host;
1744
+ return t.port;
1667
1745
  }
1668
- #n(t) {
1669
- return this.#e = { phase: "submitted", promise: t }, this.#a(), t;
1746
+ #a(t) {
1747
+ return this.#e = { phase: "submitted", promise: t }, this.#r(), t;
1670
1748
  }
1671
- #a() {
1672
- this.#t.clear(), j.delete(this);
1749
+ #r() {
1750
+ this.#t.clear(), R.delete(this);
1673
1751
  }
1674
1752
  }
1675
- class At {
1753
+ class Ut {
1676
1754
  #t;
1677
1755
  constructor(t, e, i) {
1678
1756
  this.#t = { phase: "open", draft: t, discard: e, normalize: i };
@@ -1683,7 +1761,7 @@ class At {
1683
1761
  requireDraft() {
1684
1762
  const t = this.#t;
1685
1763
  if (t.phase === "failed") throw t.error;
1686
- if (t.phase === "sealed") throw T();
1764
+ if (t.phase === "sealed") throw P();
1687
1765
  return t.draft;
1688
1766
  }
1689
1767
  assertOpen() {
@@ -1692,7 +1770,7 @@ class At {
1692
1770
  fail(t) {
1693
1771
  const e = this.#t;
1694
1772
  if (e.phase === "failed") return e.error;
1695
- if (e.phase === "sealed") throw T();
1773
+ if (e.phase === "sealed") throw P();
1696
1774
  const i = e.normalize(t);
1697
1775
  return this.#t = {
1698
1776
  phase: "failed",
@@ -1704,7 +1782,7 @@ class At {
1704
1782
  seal() {
1705
1783
  const t = this.#t;
1706
1784
  if (t.phase === "failed") throw t.error;
1707
- if (t.phase === "sealed") throw T();
1785
+ if (t.phase === "sealed") throw P();
1708
1786
  return this.#t = { phase: "sealed" }, t.draft;
1709
1787
  }
1710
1788
  discard(t) {
@@ -1714,10 +1792,10 @@ class At {
1714
1792
  this.#t = { phase: "sealed" }, e.discard(e.draft, i);
1715
1793
  }
1716
1794
  }
1717
- function T() {
1718
- return new TypeError("Group configuration has been sealed");
1795
+ function P() {
1796
+ return new Error("Group configuration has been sealed");
1719
1797
  }
1720
- class P {
1798
+ class S {
1721
1799
  constructor(t, e, i) {
1722
1800
  this.id = t, this.name = e, this.#e = { phase: "attached", parent: i };
1723
1801
  }
@@ -1726,7 +1804,7 @@ class P {
1726
1804
  #t = /* @__PURE__ */ new Map();
1727
1805
  #e;
1728
1806
  static root(t) {
1729
- return new P("/", t, void 0);
1807
+ return new S("/", t, void 0);
1730
1808
  }
1731
1809
  get attached() {
1732
1810
  return this.#e.phase !== "detached";
@@ -1739,13 +1817,16 @@ class P {
1739
1817
  return t.phase === "detached" ? void 0 : t.parent;
1740
1818
  }
1741
1819
  create(t) {
1742
- if (this.assertAttached(), jt(t), this.#t.has(t))
1820
+ if (this.assertAttached(), _t(t), this.#t.has(t))
1743
1821
  throw new TypeError(`Group '${this.#i(t)}' already exists`);
1744
- const e = new P(this.#i(t), t, this);
1822
+ const e = new S(this.#i(t), t, this);
1745
1823
  return this.#t.set(t, e), e;
1746
1824
  }
1747
- containsId(t) {
1748
- return this.id === "/" ? t.startsWith("/") : t === this.id || t.startsWith(`${this.id}/`);
1825
+ contains(t) {
1826
+ if (t === this) return !0;
1827
+ for (const e of this.#t.values())
1828
+ if (e.contains(t)) return !0;
1829
+ return !1;
1749
1830
  }
1750
1831
  assertAttached() {
1751
1832
  if (this.#e.phase === "detached")
@@ -1770,14 +1851,14 @@ class P {
1770
1851
  return this.id === "/" ? `/${t}` : `${this.id}/${t}`;
1771
1852
  }
1772
1853
  }
1773
- function jt(r) {
1854
+ function _t(r) {
1774
1855
  if (typeof r != "string" || !r.trim())
1775
1856
  throw new TypeError("Group name must be a non-empty string");
1776
1857
  if (r !== r.trim())
1777
1858
  throw new TypeError("Group name cannot start or end with whitespace");
1778
1859
  if (r.includes("/")) throw new TypeError("Group name cannot contain '/'");
1779
1860
  }
1780
- class D {
1861
+ class H {
1781
1862
  constructor(t, e, i) {
1782
1863
  this.node = t, this.#t = { phase: e }, this.#e = i;
1783
1864
  }
@@ -1804,7 +1885,7 @@ class D {
1804
1885
  this.#i(s) && (this.#t = { phase: "established" }, this.#e?.());
1805
1886
  },
1806
1887
  (o) => {
1807
- const a = $(
1888
+ const a = A(
1808
1889
  o,
1809
1890
  "GROUP_UNAVAILABLE",
1810
1891
  `Group '${this.node.id}' operation failed with a non-Error value`
@@ -1829,14 +1910,14 @@ class D {
1829
1910
  }
1830
1911
  }
1831
1912
  function I(r) {
1832
- return new p("GROUP_REMOVED", `Group '${r.id}' has been removed`);
1913
+ return new u("GROUP_REMOVED", `Group '${r.id}' has been removed`);
1833
1914
  }
1834
- const y = /* @__PURE__ */ new WeakMap();
1835
- class It {
1915
+ const E = /* @__PURE__ */ new WeakMap();
1916
+ class Ht {
1836
1917
  #t;
1837
1918
  #e;
1838
1919
  constructor(t, e, i) {
1839
- this.#t = e, this.#e = i ? { phase: "configuring", coordinator: t, configuration: i } : { phase: "attached", coordinator: t }, y.set(this, {
1920
+ this.#t = e, this.#e = i ? { phase: "configuring", coordinator: t, configuration: i } : { phase: "attached", coordinator: t }, E.set(this, {
1840
1921
  finishConfiguration: () => {
1841
1922
  const s = this.#e;
1842
1923
  s.phase === "configuring" && (this.#e = { phase: "attached", coordinator: s.coordinator });
@@ -1861,12 +1942,8 @@ class It {
1861
1942
  return t.phase === "revoked" ? Promise.reject(I(this.#t)) : t.coordinator.ready(this.#t);
1862
1943
  }
1863
1944
  install(t, ...e) {
1864
- const i = this.#e;
1865
- return i.phase === "configuring" ? i.configuration.requireDraft().install(t, ...e) : this.#i().install(
1866
- this.#t,
1867
- t,
1868
- e[0]
1869
- );
1945
+ const i = this.#e;
1946
+ return i.phase === "configuring" ? i.configuration.requireDraft().install(t, ...e) : this.#i().install(this.#t, t, ...e);
1870
1947
  }
1871
1948
  change() {
1872
1949
  if (this.#e.phase === "configuring")
@@ -1894,15 +1971,15 @@ class It {
1894
1971
  return t.coordinator;
1895
1972
  }
1896
1973
  }
1897
- class kt {
1974
+ class Kt {
1898
1975
  root;
1899
1976
  #t;
1900
1977
  #e = /* @__PURE__ */ new WeakMap();
1901
1978
  #i = /* @__PURE__ */ new WeakMap();
1902
1979
  constructor(t, e) {
1903
- this.root = P.root(t), this.#t = e, this.#i.set(
1980
+ this.root = S.root(t), this.#t = e, this.#i.set(
1904
1981
  this.root,
1905
- new D(this.root, "established", () => e.notifyChanged())
1982
+ new H(this.root, "established", () => e.notifyChanged())
1906
1983
  );
1907
1984
  }
1908
1985
  nodes() {
@@ -1910,68 +1987,71 @@ class kt {
1910
1987
  }
1911
1988
  install(t, e, ...i) {
1912
1989
  const s = this.change(t), n = s.install(e, ...i);
1913
- return G(s.commit()), n;
1990
+ return K(s.commit()), n;
1914
1991
  }
1915
1992
  change(t, e = "immediate") {
1916
- return t.assertAttached(), new Tt({
1917
- create: (i, s) => this.#t.createDraft(t, i, s),
1993
+ return this.#r(t), new Ft({
1994
+ create: (i, s) => (this.#r(t), this.#t.createDraft(t, i, s)),
1918
1995
  resolve: (i) => {
1919
- const s = this.#t.resolveHandle(i);
1920
- if (!t.containsId(s.groupId))
1921
- throw new TypeError(
1922
- `Plugin '${s.id}' is outside ChangeSet group '${t.id}'`
1923
- );
1996
+ this.#r(t);
1997
+ const s = this.#t.resolveInstallation(i);
1998
+ if (!s.attached) throw s.unavailableError();
1999
+ if (!t.contains(s.group))
2000
+ throw new TypeError(`Installation '${s.id}' is outside Group '${t.id}'`);
1924
2001
  return s;
1925
2002
  },
1926
2003
  execute: (i) => {
1927
- const s = this.#t.executeChanges(i);
2004
+ this.#r(t);
2005
+ const s = this.#t.executeChanges(t, i);
1928
2006
  for (const n of i) n.installation.trackReadiness(s);
1929
- return e === "immediate" && this.#n(t, s), s;
2007
+ return i.length && e === "immediate" && this.#a(t, s), s;
2008
+ },
2009
+ attach: (i) => {
2010
+ this.#r(t), this.#t.attachInstallation(i);
1930
2011
  },
1931
- attach: (i) => this.#t.attachInstallation(i),
1932
2012
  discard: (i, s) => this.#t.discardInstallation(i, s)
1933
2013
  });
1934
2014
  }
1935
2015
  create(t, e, i, s) {
1936
2016
  if (typeof i != "function") throw new TypeError("Group configure must be a function");
1937
2017
  const n = t.create(e);
1938
- this.#i.set(n, new D(n, "new", () => this.#t.notifyChanged()));
1939
- const o = s === void 0, a = s ?? new At(
2018
+ this.#i.set(n, new H(n, "new", () => this.#t.notifyChanged()));
2019
+ const o = s === void 0, a = s ?? new Ut(
1940
2020
  this.change(n, "deferred"),
1941
- Ot,
1942
- (c) => $(
1943
- c,
2021
+ Bt,
2022
+ (h) => A(
2023
+ h,
1944
2024
  "GROUP_UNAVAILABLE",
1945
2025
  `Group '${n.id}' configuration failed with a non-Error value`
1946
2026
  )
1947
- ), h = new It(this, n, a);
1948
- this.#e.set(n, h);
2027
+ ), c = new Ht(this, n, a);
2028
+ this.#e.set(n, c);
1949
2029
  try {
1950
- const c = i(h);
1951
- Lt(c) && $t(c);
2030
+ const h = i(c);
2031
+ Yt(h) && Wt(h);
1952
2032
  const d = a.failure;
1953
2033
  if (d) throw d;
1954
- } catch (c) {
1955
- const d = a.fail(c), l = n.walk();
2034
+ } catch (h) {
2035
+ const d = a.fail(h), l = n.walk();
1956
2036
  throw n.detach(), this.#o(l), o && a.discard(d), this.#t.notifyChanged(), d;
1957
2037
  }
1958
2038
  if (o) {
1959
- const c = a.seal().commit();
2039
+ const h = a.seal().commit();
1960
2040
  for (const d of n.walk()) {
1961
2041
  const l = this.#e.get(d);
1962
- l && y.get(l)?.finishConfiguration(), this.#n(d, c);
2042
+ l && E.get(l)?.finishConfiguration(), this.#a(d, h);
1963
2043
  }
1964
- G(c);
2044
+ K(h);
1965
2045
  }
1966
- return this.#t.notifyChanged(), h;
2046
+ return this.#t.notifyChanged(), c;
1967
2047
  }
1968
2048
  async ready(t) {
1969
- await this.#a(t).ready(async () => {
2049
+ await this.#r(t).ready(async () => {
1970
2050
  await Promise.all(this.#s(t).map((e) => e.ready()));
1971
2051
  });
1972
2052
  }
1973
2053
  status(t) {
1974
- return t.attached ? this.#a(t).status(this.#r(t)) : "removed";
2054
+ return t.attached ? this.#r(t).status(this.#n(t)) : "removed";
1975
2055
  }
1976
2056
  remove(t) {
1977
2057
  if (t === this.root) throw new TypeError("The root Group cannot be removed");
@@ -1980,74 +2060,214 @@ class kt {
1980
2060
  this.#o([t]);
1981
2061
  return;
1982
2062
  }
1983
- const e = t.walk(), i = this.#s(t).map(
1984
- (s) => ({ kind: "remove", installation: s })
1985
- );
2063
+ const e = t.walk(), i = this.#s(t).map((s) => ({
2064
+ kind: "remove",
2065
+ installation: s
2066
+ }));
1986
2067
  await this.#t.removeInstallations(i), t.detach(), this.#o(e), this.#t.notifyChanged();
1987
2068
  }) : (this.#o([t]), Promise.resolve());
1988
2069
  }
1989
2070
  #s(t) {
1990
2071
  return [...this.#t.installations()].filter(
1991
- (e) => t.containsId(e.groupId)
2072
+ (e) => t.contains(e.group)
1992
2073
  );
1993
2074
  }
1994
- #r(t) {
2075
+ #n(t) {
1995
2076
  const e = this.#s(t);
1996
2077
  return e.some((i) => i.status === "failed") ? "failed" : e.some((i) => i.status === "stopping") ? "stopping" : e.length && e.every((i) => i.status === "active") ? "active" : e.length ? "pending" : "active";
1997
2078
  }
1998
- #n(t, e) {
1999
- this.#a(t).track(e);
2079
+ #a(t, e) {
2080
+ this.#r(t).track(e);
2000
2081
  }
2001
- #a(t) {
2082
+ #r(t) {
2002
2083
  const e = this.#i.get(t);
2003
- if (!e) throw I(t);
2084
+ if (!t.attached || !e) throw I(t);
2004
2085
  return e;
2005
2086
  }
2006
2087
  #o(t) {
2007
2088
  for (const e of t) {
2008
2089
  this.#i.get(e)?.release(), this.#i.delete(e);
2009
2090
  const i = this.#e.get(e);
2010
- i && (y.get(i)?.revoke(), y.delete(i)), this.#e.delete(e);
2091
+ i && (E.get(i)?.revoke(), E.delete(i)), this.#e.delete(e);
2011
2092
  }
2012
2093
  }
2013
2094
  }
2014
- function G(r) {
2095
+ function K(r) {
2015
2096
  Promise.resolve(r).catch(() => {
2016
2097
  });
2017
2098
  }
2018
- function $t(r) {
2099
+ function Wt(r) {
2019
2100
  throw Promise.resolve(r).catch(() => {
2020
2101
  }), new TypeError("Group configure must be synchronous");
2021
2102
  }
2022
- function Lt(r) {
2103
+ function Yt(r) {
2023
2104
  return r === null || typeof r != "object" && typeof r != "function" ? !1 : typeof r.then == "function";
2024
2105
  }
2025
- class zt {
2026
- #t = Promise.resolve();
2027
- get settled() {
2028
- return this.#t;
2106
+ function W(r, t) {
2107
+ return Object.freeze({ plugin: r, config: t });
2108
+ }
2109
+ class Qt {
2110
+ constructor(t, e, i, s) {
2111
+ this.id = t, this.index = e, this.groupId = i.id, this.#i = { declaration: s, group: i, notifyChanged: void 0 };
2029
2112
  }
2030
- run(t) {
2031
- if (typeof t != "function")
2032
- throw new TypeError("SerialQueue operation must be a function");
2033
- const e = this.#t.then(t);
2034
- return this.#t = e.then(
2113
+ id;
2114
+ index;
2115
+ #t = { phase: "pending" };
2116
+ #e;
2117
+ #i;
2118
+ groupId;
2119
+ #s = /* @__PURE__ */ new Set();
2120
+ attach(t) {
2121
+ const e = this.#c();
2122
+ if (e.notifyChanged) throw new Error(`Installation '${this.id}' is already attached`);
2123
+ e.notifyChanged = t;
2124
+ }
2125
+ get status() {
2126
+ return this.#t.phase;
2127
+ }
2128
+ /** Whether the owning ChangeSet has granted this Installation Host authority. */
2129
+ get attached() {
2130
+ return this.#i?.notifyChanged !== void 0;
2131
+ }
2132
+ get instance() {
2133
+ const t = this.#t;
2134
+ return t.phase === "active" || t.phase === "stopping" ? t.instance : void 0;
2135
+ }
2136
+ get error() {
2137
+ const t = this.#t;
2138
+ if (t.phase === "failed")
2139
+ return t.failure.retention === "live" ? t.failure.error : Xt(t.failure.summary);
2140
+ if (t.phase === "removed")
2141
+ return new u("INSTALLATION_REMOVED", `Installation '${this.id}' has been removed`);
2142
+ }
2143
+ get group() {
2144
+ return this.#c().group;
2145
+ }
2146
+ get declaration() {
2147
+ return this.#c().declaration;
2148
+ }
2149
+ replaceDeclaration(t) {
2150
+ this.#c().declaration = t;
2151
+ }
2152
+ ready() {
2153
+ const t = this.#e;
2154
+ return t ? t.barrier.then(() => this.#n()) : this.#n();
2155
+ }
2156
+ unavailableError() {
2157
+ return this.error ?? new u(
2158
+ "INSTALLATION_UNAVAILABLE",
2159
+ `Installation '${this.id}' has not been committed`
2160
+ );
2161
+ }
2162
+ trackReadiness(t) {
2163
+ const e = {}, i = t.then(
2035
2164
  () => {
2165
+ this.#e?.attempt === e && (this.#e = void 0);
2036
2166
  },
2037
- () => {
2167
+ (s) => {
2168
+ if (this.#e?.attempt === e && (this.#e = void 0), this.#t.phase !== "active") throw s;
2038
2169
  }
2039
- ), e;
2170
+ );
2171
+ this.#e = { attempt: e, barrier: i }, i.catch(() => {
2172
+ });
2173
+ }
2174
+ #n() {
2175
+ const t = this.#t;
2176
+ if ((t.phase === "active" || t.phase === "failed" || t.phase === "removed") && t.readiness === "settled") {
2177
+ if (t.phase === "active") return Promise.resolve();
2178
+ if (t.phase === "failed" || t.phase === "removed")
2179
+ return Promise.reject(
2180
+ this.error ?? new u(
2181
+ "INSTALLATION_UNAVAILABLE",
2182
+ `Installation '${this.id}' is ${t.phase}`
2183
+ )
2184
+ );
2185
+ }
2186
+ const e = Promise.withResolvers();
2187
+ return this.#s.add(e), e.promise;
2188
+ }
2189
+ activate(t) {
2190
+ this.#r({ phase: "active", instance: t, readiness: "unsettled" });
2191
+ }
2192
+ settleReady() {
2193
+ const t = this.#t;
2194
+ if (!(t.phase !== "active" && t.phase !== "failed" && t.phase !== "removed") && t.readiness !== "settled") {
2195
+ if (this.#t = { ...t, readiness: "settled" }, t.phase === "active")
2196
+ for (const e of this.#s) e.resolve();
2197
+ else {
2198
+ const e = this.error ?? new u("INSTALLATION_UNAVAILABLE", `Installation '${this.id}' is ${t.phase}`);
2199
+ for (const i of this.#s) i.reject(e);
2200
+ }
2201
+ this.#s.clear();
2202
+ }
2203
+ }
2204
+ beginStopping() {
2205
+ const t = this.#t;
2206
+ return t.phase !== "active" ? !1 : (this.#r({ phase: "stopping", instance: t.instance }), !0);
2207
+ }
2208
+ deactivate() {
2209
+ this.#r({ phase: "pending" });
2210
+ }
2211
+ fail(t) {
2212
+ return this.#a(t);
2213
+ }
2214
+ discard(t) {
2215
+ const e = this.#o(t);
2216
+ this.#r({
2217
+ phase: "failed",
2218
+ failure: { retention: "summary", summary: Jt(e) },
2219
+ readiness: "settled"
2220
+ });
2221
+ for (const i of this.#s) i.reject(e);
2222
+ this.#s.clear(), this.#e = void 0, this.#i = void 0;
2223
+ }
2224
+ #a(t) {
2225
+ const e = this.#o(t);
2226
+ return this.#r({
2227
+ phase: "failed",
2228
+ failure: { retention: "live", error: e },
2229
+ readiness: "unsettled"
2230
+ }), e;
2231
+ }
2232
+ remove() {
2233
+ this.#r({ phase: "removed", readiness: "unsettled" }), this.#e = void 0, this.#i = void 0;
2234
+ }
2235
+ #r(t) {
2236
+ this.#t = t, this.#i?.notifyChanged?.();
2237
+ }
2238
+ #o(t) {
2239
+ return A(
2240
+ t,
2241
+ "INSTALLATION_UNAVAILABLE",
2242
+ `Installation '${this.id}' failed with a non-Error value`
2243
+ );
2244
+ }
2245
+ #c() {
2246
+ const t = this.#i;
2247
+ if (!t) throw new Error(`Installation '${this.id}' is no longer installed`);
2248
+ return t;
2040
2249
  }
2041
2250
  }
2042
- const xt = console, E = /* @__PURE__ */ new WeakMap();
2043
- class Rt {
2251
+ function Jt(r) {
2252
+ return r instanceof u ? { category: "dougong", name: r.name, message: r.message, code: r.code } : {
2253
+ category: r instanceof TypeError ? "typeError" : "error",
2254
+ name: r.name,
2255
+ message: r.message
2256
+ };
2257
+ }
2258
+ function Xt(r) {
2259
+ const t = r.category === "dougong" ? new u(r.code, r.message) : r.category === "typeError" ? new TypeError(r.message) : new Error(r.message);
2260
+ return t.name = r.name, t;
2261
+ }
2262
+ const C = /* @__PURE__ */ new WeakMap();
2263
+ class Zt {
2044
2264
  #t;
2045
2265
  #e = { phase: "draft" };
2046
2266
  constructor(t) {
2047
- this.#t = t, E.set(this, {
2267
+ this.#t = t, C.set(this, {
2048
2268
  attach: (e, i) => {
2049
2269
  if (this.#e.phase !== "draft")
2050
- throw new TypeError(`Plugin '${this.#t.id}' control is already sealed`);
2270
+ throw new Error(`Installation '${this.#t.id}' control is already sealed`);
2051
2271
  this.#e = {
2052
2272
  phase: "attached",
2053
2273
  update: e,
@@ -2074,8 +2294,7 @@ class Rt {
2074
2294
  async update(t) {
2075
2295
  const e = this.#e;
2076
2296
  if (e.phase === "draft") throw this.#i();
2077
- if (e.phase === "revoked")
2078
- throw this.#t.error ?? new p("PLUGIN_REMOVED", `Plugin '${this.#t.id}' has been removed`);
2297
+ if (e.phase === "revoked") throw this.#t.unavailableError();
2079
2298
  await e.update(t);
2080
2299
  }
2081
2300
  async remove() {
@@ -2084,261 +2303,288 @@ class Rt {
2084
2303
  t.phase === "attached" && await t.remove();
2085
2304
  }
2086
2305
  #i() {
2087
- return new p(
2088
- "PLUGIN_UNAVAILABLE",
2089
- `Plugin '${this.#t.id}' installation has not been committed`
2306
+ return new u(
2307
+ "INSTALLATION_UNAVAILABLE",
2308
+ `Installation '${this.#t.id}' has not been committed`
2090
2309
  );
2091
2310
  }
2092
2311
  }
2093
- class Nt {
2094
- name;
2095
- diagnostics;
2312
+ class te {
2096
2313
  #t = /* @__PURE__ */ new Map();
2097
2314
  #e = /* @__PURE__ */ new WeakMap();
2098
2315
  #i = /* @__PURE__ */ new WeakMap();
2099
2316
  #s;
2100
- #r;
2317
+ #n = 0;
2318
+ constructor(t) {
2319
+ this.#s = t;
2320
+ }
2321
+ values() {
2322
+ return this.#t.values();
2323
+ }
2324
+ has(t) {
2325
+ return this.#t.has(t);
2326
+ }
2327
+ contains(t) {
2328
+ return this.#t.get(t.id) === t;
2329
+ }
2330
+ create(t, e, i) {
2331
+ t.assertAttached();
2332
+ const s = ++this.#n, n = new Qt(
2333
+ `${e.name}:${s}`,
2334
+ s,
2335
+ t,
2336
+ W(e, i)
2337
+ ), o = new Zt(n);
2338
+ return this.#e.set(o, n), this.#i.set(n, o), { record: n, publicInstallation: o };
2339
+ }
2340
+ resolve(t) {
2341
+ const e = this.#e.get(t);
2342
+ if (!e) throw new TypeError("Installation belongs to a different Host");
2343
+ return e;
2344
+ }
2345
+ attach(t) {
2346
+ const e = this.#i.get(t);
2347
+ if (!e) throw new Error(`Installation '${t.id}' has no public facade`);
2348
+ const i = C.get(e);
2349
+ if (!i) throw new Error(`Installation '${t.id}' has no draft control`);
2350
+ t.attach(this.#s.notifyChanged), i.attach(
2351
+ (s) => this.#s.update(t, e, s),
2352
+ () => this.#s.remove(t, e)
2353
+ );
2354
+ }
2355
+ apply(t) {
2356
+ for (const e of t) {
2357
+ if (e.kind === "install") {
2358
+ if (e.installation.group.assertAttached(), this.#t.has(e.installation.id))
2359
+ throw new Error(`Installation '${e.installation.id}' is already installed`);
2360
+ continue;
2361
+ }
2362
+ if (!this.contains(e.installation))
2363
+ throw e.installation.unavailableError();
2364
+ if (e.kind === "update" && e.declaration.kind !== "config" && e.declaration.plugin.name !== e.installation.declaration.plugin.name)
2365
+ throw new u(
2366
+ "INSTALLATION_IDENTITY",
2367
+ `Installation '${e.installation.id}' cannot change name from '${e.installation.declaration.plugin.name}' to '${e.declaration.plugin.name}'`
2368
+ );
2369
+ }
2370
+ for (const e of t)
2371
+ if (e.kind === "install")
2372
+ this.#t.set(e.installation.id, e.installation);
2373
+ else if (e.kind === "update") {
2374
+ const i = e.installation.declaration, s = e.declaration.kind === "config" ? i.plugin : e.declaration.plugin, n = e.declaration.kind === "plugin" ? i.config : e.declaration.config;
2375
+ e.installation.replaceDeclaration(W(s, n));
2376
+ } else this.contains(e.installation) && this.#t.delete(e.installation.id);
2377
+ }
2378
+ settleChanges(t, e) {
2379
+ for (const i of t)
2380
+ i.kind === "remove" ? (i.installation.remove(), i.installation.settleReady(), this.#a(i.installation)) : e || i.installation.deactivate();
2381
+ }
2382
+ settleReadiness(t) {
2383
+ for (const e of t) e.settleReady();
2384
+ }
2385
+ discard(t, e) {
2386
+ t.discard(e), this.#a(t);
2387
+ }
2388
+ capture() {
2389
+ return [...this.#t].map(([t, e]) => ({
2390
+ id: t,
2391
+ installation: e,
2392
+ declaration: e.declaration
2393
+ }));
2394
+ }
2395
+ restore(t) {
2396
+ this.#t.clear();
2397
+ for (const e of t)
2398
+ e.installation.replaceDeclaration(e.declaration), this.#t.set(e.id, e.installation);
2399
+ }
2400
+ #a(t) {
2401
+ const e = this.#i.get(t);
2402
+ e && (C.get(e)?.revoke(), C.delete(e)), this.#i.delete(t);
2403
+ }
2404
+ }
2405
+ class ee {
2406
+ #t = Promise.resolve();
2407
+ get settled() {
2408
+ return this.#t;
2409
+ }
2410
+ run(t) {
2411
+ if (typeof t != "function")
2412
+ throw new TypeError("SerialQueue operation must be a function");
2413
+ const e = this.#t.then(t);
2414
+ return this.#t = e.then(
2415
+ () => {
2416
+ },
2417
+ () => {
2418
+ }
2419
+ ), e;
2420
+ }
2421
+ }
2422
+ const ie = console, se = /* @__PURE__ */ new Set(["name", "logger", "onError"]);
2423
+ class re {
2424
+ name;
2425
+ diagnostics;
2426
+ #t;
2427
+ #e;
2428
+ #i;
2429
+ #s;
2101
2430
  #n;
2102
2431
  #a;
2103
- #o;
2104
- #h = 0;
2105
- #c = "idle";
2106
- #p = new zt();
2432
+ #r = "idle";
2433
+ #o = new ee();
2107
2434
  constructor(t = {}) {
2108
- if (!t || typeof t != "object")
2109
- throw new TypeError("Application options must be an object");
2110
- const e = t.name ?? "app";
2111
- if (typeof e != "string" || !e.trim())
2112
- throw new TypeError("Application name must be a non-empty string");
2113
- if (e !== e.trim())
2114
- throw new TypeError("Application name cannot start or end with whitespace");
2115
- if (t.onError !== void 0 && typeof t.onError != "function")
2116
- throw new TypeError("Application onError must be a function");
2117
- if (t.logger !== void 0 && !Mt(t.logger))
2118
- throw new TypeError("Application logger must implement debug/info/warn/error");
2119
- this.name = e, this.#r = t.logger ?? xt, this.#a = t.onError ?? ((i) => this.#r.error(i)), this.#o = new Ct({
2120
- applicationName: e,
2121
- logger: this.#r,
2122
- isInstalled: (i) => this.#t.has(i),
2123
- report: (i) => this.#S(i)
2124
- }), this.#n = new kt(e, {
2435
+ T(t, "Host options", { fields: se });
2436
+ const e = Object.hasOwn(t, "name") ? t.name : void 0, i = Object.hasOwn(t, "logger") ? t.logger : void 0, s = Object.hasOwn(t, "onError") ? t.onError : void 0, n = e ?? "host";
2437
+ if (typeof n != "string" || !n.trim())
2438
+ throw new TypeError("Host name must be a non-empty string");
2439
+ if (n !== n.trim())
2440
+ throw new TypeError("Host name cannot start or end with whitespace");
2441
+ if (s !== void 0 && typeof s != "function")
2442
+ throw new TypeError("Host onError must be a function");
2443
+ if (i !== void 0 && !$t(i))
2444
+ throw new TypeError("Host logger must implement debug/info/warn/error");
2445
+ this.name = n, this.#i = i ?? ie, this.#n = s ?? ((o) => this.#i.error(o)), this.#t = new te({
2446
+ notifyChanged: () => this.#p(),
2447
+ update: (o, a, c) => this.#s.change(o.group).update(a, c).commit(),
2448
+ remove: (o, a) => this.#s.change(o.group).remove(a).commit()
2449
+ }), this.#a = new Rt({
2450
+ hostName: n,
2451
+ logger: this.#i,
2452
+ isInstalled: (o) => this.#t.has(o),
2453
+ report: (o) => this.#d(o)
2454
+ }), this.#s = new Kt(n, {
2125
2455
  installations: () => this.#t.values(),
2126
- createDraft: (i, s, n) => this.#g(i, s, n),
2127
- resolveHandle: (i) => this.#l(i),
2128
- executeChanges: (i) => this.#d(i),
2129
- attachInstallation: (i) => this.#T(i),
2130
- discardInstallation: (i, s) => {
2131
- this.#C(i, s);
2132
- },
2133
- runExclusive: (i) => this.#p.run(i),
2134
- removeInstallations: (i) => this.#b(i),
2135
- notifyChanged: () => this.#m()
2136
- }), this.#s = new Pt(
2137
- e,
2138
- this.#n.nodes(),
2139
- (i) => this.#S(i)
2140
- ), this.diagnostics = this.#s.view, Object.freeze(this);
2456
+ createDraft: (o, a, c) => this.#t.create(o, a, c),
2457
+ resolveInstallation: (o) => this.#t.resolve(o),
2458
+ executeChanges: (o, a) => this.#c(o, a),
2459
+ attachInstallation: (o) => this.#t.attach(o),
2460
+ discardInstallation: (o, a) => this.#t.discard(o, a),
2461
+ runExclusive: (o) => this.#o.run(o),
2462
+ removeInstallations: (o) => this.#f(o),
2463
+ notifyChanged: () => this.#p()
2464
+ }), this.#e = new Nt(
2465
+ n,
2466
+ this.#s.nodes(),
2467
+ (o) => this.#d(o)
2468
+ ), this.diagnostics = this.#e.view, Object.freeze(this);
2141
2469
  }
2142
2470
  get status() {
2143
- return this.#c;
2471
+ return this.#r;
2144
2472
  }
2145
2473
  get(t) {
2146
- const e = this.#c === "active" ? "available" : "unavailable";
2147
- return this.#o.get(t, e);
2474
+ const e = this.#r === "active" ? "available" : "unavailable";
2475
+ return this.#a.get(t, e);
2148
2476
  }
2149
2477
  install(t, ...e) {
2150
- return this.#n.install(this.#n.root, t, ...e);
2478
+ return this.#s.install(this.#s.root, t, ...e);
2151
2479
  }
2152
2480
  change() {
2153
- return this.#n.change(this.#n.root);
2481
+ return this.#s.change(this.#s.root);
2154
2482
  }
2155
2483
  group(t, e) {
2156
- return this.#n.create(this.#n.root, t, e);
2484
+ return this.#s.create(this.#s.root, t, e);
2157
2485
  }
2158
2486
  start() {
2159
- return this.#p.run(async () => {
2160
- if (this.#c !== "active") {
2161
- this.#u("starting");
2487
+ return this.#o.run(async () => {
2488
+ if (this.#r !== "active") {
2489
+ this.#h("starting");
2162
2490
  try {
2163
- const t = this.#o.buildPlan(this.#t.values());
2164
- await this.#o.start(t), this.#u("active"), this.#E(t.order);
2491
+ const t = this.#a.buildPlan(this.#t.values());
2492
+ await this.#a.start(t), this.#h("active"), this.#t.settleReadiness(t.order);
2165
2493
  } catch (t) {
2166
- this.#u("idle");
2494
+ this.#h("idle");
2167
2495
  for (const e of this.#t.values())
2168
2496
  e.status !== "active" && e.fail(t);
2169
- throw this.#E(this.#t.values()), t;
2497
+ throw this.#t.settleReadiness(this.#t.values()), t;
2170
2498
  }
2171
2499
  }
2172
2500
  });
2173
2501
  }
2174
2502
  stop() {
2175
- return this.#p.run(async () => {
2176
- if (this.#c === "idle") return;
2177
- this.#u("stopping");
2178
- const t = await this.#o.stop();
2179
- if (this.#u("idle"), t.length === 1) throw t[0];
2180
- if (t.length > 1) throw new AggregateError(t, "Application shutdown failed");
2503
+ return this.#o.run(async () => {
2504
+ if (this.#r === "idle") return;
2505
+ this.#h("stopping");
2506
+ const t = await this.#a.stop();
2507
+ if (this.#h("idle"), t.length === 1) throw t[0];
2508
+ if (t.length > 1) throw new AggregateError(t, "Host shutdown failed");
2181
2509
  });
2182
2510
  }
2183
- #g(t, e, i) {
2184
- t.assertAttached();
2185
- const s = ++this.#h, n = `${e.name}:${s}`, o = new bt(
2186
- n,
2187
- s,
2188
- t,
2189
- N(e, i)
2190
- ), a = new Rt(o);
2191
- return this.#e.set(a, o), this.#i.set(o, a), { installation: o, handle: a };
2192
- }
2193
- #l(t) {
2194
- const e = this.#e.get(t);
2195
- if (!e) throw new TypeError("PluginHandle belongs to a different Application");
2196
- return e;
2197
- }
2198
- #d(t) {
2199
- const e = t.filter((i) => i.kind === "install").map((i) => i.installation);
2200
- return this.#p.run(async () => {
2511
+ #c(t, e) {
2512
+ const i = e.filter((s) => s.kind === "install").map((s) => s.installation);
2513
+ return this.#o.run(async () => {
2201
2514
  try {
2202
- this.#c === "active" ? await this.#w(t) : (this.#f(t), this.#v(t)), this.#m();
2203
- } catch (i) {
2204
- for (const s of e)
2205
- this.#t.get(s.id) !== s && this.#C(s, i);
2206
- throw i;
2515
+ if (!t.attached) throw I(t);
2516
+ if (!e.length) return;
2517
+ this.#r === "active" ? await this.#u(e) : (this.#t.apply(e), this.#t.settleChanges(e, !1)), this.#p();
2518
+ } catch (s) {
2519
+ for (const n of i)
2520
+ this.#t.contains(n) || this.#t.discard(n, s);
2521
+ throw s;
2207
2522
  }
2208
2523
  });
2209
2524
  }
2210
- async #b(t) {
2211
- t.length && this.#c === "active" ? await this.#w(t) : (this.#f(t), this.#v(t));
2525
+ async #f(t) {
2526
+ t.length && this.#r === "active" ? await this.#u(t) : (this.#t.apply(t), this.#t.settleChanges(t, !1));
2212
2527
  }
2213
- async #w(t) {
2214
- const e = await this.#O(t);
2215
- if (this.#E(e.affected), e.kind === "rolled-back") throw e.error;
2216
- this.#v(t);
2528
+ async #u(t) {
2529
+ const e = await this.#l(t);
2530
+ if (this.#t.settleReadiness(e.affected), e.kind === "rolled-back") throw e.error;
2531
+ this.#t.settleChanges(t, !0);
2217
2532
  }
2218
- async #O(t) {
2219
- const e = this.#A(), i = new Set(t.map((n) => n.installation));
2220
- this.#u("changing");
2533
+ async #l(t) {
2534
+ const e = this.#t.capture(), i = new Set(t.map((n) => n.installation));
2535
+ this.#h("changing");
2221
2536
  let s;
2222
2537
  try {
2223
- this.#f(t), s = this.#o.buildPlan(this.#t.values());
2538
+ this.#t.apply(t), s = this.#a.buildPlan(this.#t.values());
2224
2539
  } catch (n) {
2225
- throw this.#P(e), this.#u("active"), n;
2540
+ throw this.#t.restore(e), this.#h("active"), n;
2226
2541
  }
2227
2542
  try {
2228
- const n = await this.#o.transition(
2543
+ const n = await this.#a.transition(
2229
2544
  s,
2230
2545
  i,
2231
- () => this.#P(e)
2546
+ () => this.#t.restore(e)
2232
2547
  );
2233
- return this.#u("active"), n;
2548
+ return this.#h("active"), n;
2234
2549
  } catch (n) {
2235
- throw this.#u(this.#o.hasCommittedPlan ? "active" : "idle"), n;
2236
- }
2237
- }
2238
- #f(t) {
2239
- for (const e of t) {
2240
- if (e.kind === "install") {
2241
- if (e.installation.group.assertAttached(), this.#t.has(e.installation.id))
2242
- throw new TypeError(`Plugin '${e.installation.id}' is already installed`);
2243
- continue;
2244
- }
2245
- const i = this.#t.get(e.installation.id) === e.installation;
2246
- if (!(e.kind === "remove" && !i && e.installation.status === "removed")) {
2247
- if (!i)
2248
- throw new p(
2249
- "PLUGIN_REMOVED",
2250
- `Plugin '${e.installation.id}' has been removed`
2251
- );
2252
- if (e.kind === "update" && e.declaration.kind !== "config" && e.declaration.plugin.name !== e.installation.spec.plugin.name)
2253
- throw new p(
2254
- "PLUGIN_IDENTITY",
2255
- `Plugin '${e.installation.id}' cannot change name from '${e.installation.spec.plugin.name}' to '${e.declaration.plugin.name}'`
2256
- );
2257
- }
2550
+ throw this.#h(this.#a.hasCommittedPlan ? "active" : "idle"), n;
2258
2551
  }
2259
- for (const e of t)
2260
- if (e.kind === "install")
2261
- this.#t.set(e.installation.id, e.installation);
2262
- else if (e.kind === "update") {
2263
- const i = e.installation.spec, s = e.declaration.kind === "config" ? i.plugin : e.declaration.plugin, n = e.declaration.kind === "plugin" ? i.config : e.declaration.config;
2264
- e.installation.reconfigure(N(s, n));
2265
- } else this.#t.get(e.installation.id) === e.installation && this.#t.delete(e.installation.id);
2266
- }
2267
- #v(t) {
2268
- for (const e of t)
2269
- e.kind === "remove" ? (e.installation.remove(), e.installation.settleReady(), this.#y(e.installation)) : this.#c !== "active" && e.installation.deactivate();
2270
- }
2271
- #C(t, e) {
2272
- t.discard(e), this.#y(t);
2273
- }
2274
- #T(t) {
2275
- const e = this.#i.get(t);
2276
- if (!e) throw new TypeError(`Plugin '${t.id}' has no control handle`);
2277
- const i = E.get(e);
2278
- if (!i) throw new TypeError(`Plugin '${t.id}' has no draft control`);
2279
- t.attach(() => this.#m()), i.attach(
2280
- (s) => this.#n.change(t.group).update(e, s).commit(),
2281
- () => this.#n.change(t.group).remove(e).commit()
2282
- );
2283
- }
2284
- #y(t) {
2285
- const e = this.#i.get(t);
2286
- e && (E.get(e)?.revoke(), E.delete(e)), this.#i.delete(t);
2287
- }
2288
- #E(t) {
2289
- for (const e of t) e.settleReady();
2290
2552
  }
2291
- #A() {
2292
- return [...this.#t].map(([t, e]) => ({
2293
- id: t,
2294
- installation: e,
2295
- spec: e.spec
2296
- }));
2297
- }
2298
- #P(t) {
2299
- this.#t.clear();
2300
- for (const e of t)
2301
- e.installation.reconfigure(e.spec), this.#t.set(e.id, e.installation);
2302
- }
2303
- #S(t) {
2553
+ #d(t) {
2304
2554
  try {
2305
- this.#a(t);
2555
+ this.#n(t);
2306
2556
  } catch (e) {
2307
2557
  try {
2308
- this.#r.error(
2309
- new AggregateError([t, e], "Application error reporter failed")
2558
+ this.#i.error(
2559
+ new AggregateError([t, e], "Host error reporter failed")
2310
2560
  );
2311
2561
  } catch {
2312
2562
  }
2313
2563
  }
2314
2564
  }
2315
- #u(t) {
2316
- this.#c = t, this.#m();
2565
+ #h(t) {
2566
+ this.#r = t, this.#p();
2317
2567
  }
2318
- #m() {
2319
- this.#s.publish(this.#c, this.#t.values(), this.#n.nodes());
2568
+ #p() {
2569
+ this.#e.publish(this.#r, this.#t.values(), this.#s.nodes());
2320
2570
  }
2321
2571
  }
2322
- function Mt(r) {
2323
- if (!r || typeof r != "object") return !1;
2324
- const t = r;
2325
- return [t.debug, t.info, t.warn, t.error].every(
2326
- (e) => typeof e == "function"
2327
- );
2328
- }
2329
- function Ut(r) {
2330
- return new Nt(r);
2572
+ function ce(r) {
2573
+ return new re(r);
2331
2574
  }
2332
2575
  export {
2333
- H as ConfigValidationError,
2334
- p as DougongError,
2335
- C as ReadonlyMapSnapshot,
2336
- zt as SerialQueue,
2337
- U as SnapshotPublisher,
2338
- Ut as createApp,
2339
- q as definePlugin,
2340
- Dt as event,
2341
- Gt as extension,
2342
- Vt as optional,
2343
- qt as service
2576
+ it as ConfigValidationError,
2577
+ u as DougongError,
2578
+ O as ReadonlyMapSnapshot,
2579
+ ee as SerialQueue,
2580
+ q as SnapshotPublisher,
2581
+ T as assertPlainRecord,
2582
+ ce as createHost,
2583
+ Vt as definePlugin,
2584
+ oe as event,
2585
+ ae as extensionPoint,
2586
+ Y as isCancellationReason,
2587
+ $t as isLogger,
2588
+ he as optional,
2589
+ ne as service
2344
2590
  };