@dougongjs/core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,65 +1,109 @@
1
- function rt(r, t) {
1
+ function at(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
7
  function V(r, t) {
8
- return rt("Contract", t), Object.freeze({ id: t, kind: r });
8
+ return at("Contract", t), Object.freeze({ id: t, kind: r });
9
9
  }
10
10
  function v(r, t) {
11
11
  if (!r || typeof r != "object") return !1;
12
12
  const e = r;
13
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 b(r, t) {
15
+ function m(r, t) {
16
16
  if (!v(r, t))
17
- throw new TypeError(t ? `Expected ${nt(t)}` : "Invalid contract");
17
+ throw new TypeError(t ? `Expected ${ct(t)}` : "Invalid contract");
18
18
  }
19
- function nt(r) {
19
+ function ct(r) {
20
20
  return r === "extensionPoint" ? "an ExtensionPoint" : r === "event" ? "an Event" : "a Service";
21
21
  }
22
- function de(r) {
22
+ function fe(r) {
23
23
  return V("service", r);
24
24
  }
25
- function le(r) {
25
+ function pe(r) {
26
26
  return V("event", r);
27
27
  }
28
- function ue(r) {
28
+ function ge(r) {
29
29
  return V("extensionPoint", r);
30
30
  }
31
- function fe(r) {
31
+ function we(r) {
32
32
  if (!v(r, "service"))
33
33
  throw new TypeError("optional() expects a Service");
34
34
  return Object.freeze({ kind: "optional", service: r });
35
35
  }
36
- function ot(r) {
36
+ function ht(r) {
37
37
  if (!r || typeof r != "object") return !1;
38
38
  const t = r;
39
39
  return t.kind === "optional" && v(t.service, "service");
40
40
  }
41
41
  class u extends Error {
42
+ name = "DougongError";
43
+ code;
42
44
  constructor(t, e, i) {
45
+ if (typeof t != "string" || t.trim() !== t || t.length === 0)
46
+ throw new TypeError("DougongError code must be a non-empty trimmed string");
47
+ if (typeof e != "string") throw new TypeError("DougongError message must be a string");
43
48
  super(e, i), this.code = t;
44
49
  }
45
- code;
46
- name = "DougongError";
47
50
  }
48
- class P extends u {
51
+ class dt {
52
+ #t;
53
+ constructor(t) {
54
+ if (!(t instanceof Error)) throw new TypeError("ErrorSummary expects an Error");
55
+ const e = F(t, "name", "Error"), i = F(t, "message", ""), s = t instanceof u ? lt(t) : void 0;
56
+ this.#t = Object.freeze(
57
+ s === void 0 ? {
58
+ category: t instanceof TypeError ? "typeError" : "error",
59
+ name: e,
60
+ message: i
61
+ } : {
62
+ category: "coded",
63
+ name: e,
64
+ message: i,
65
+ code: s
66
+ }
67
+ ), Object.freeze(this);
68
+ }
69
+ restore(t = (e, i) => new u(e, i)) {
70
+ const e = this.#t, i = e.category === "coded" ? t(e.code, e.message) : e.category === "typeError" ? new TypeError(e.message) : new Error(e.message);
71
+ if (!(i instanceof Error))
72
+ throw new TypeError("ErrorSummary coded error factory must return an Error");
73
+ return i.name = e.name, i;
74
+ }
75
+ }
76
+ function F(r, t, e) {
77
+ try {
78
+ const i = r[t];
79
+ return typeof i == "string" ? i : e;
80
+ } catch {
81
+ return e;
82
+ }
83
+ }
84
+ function lt(r) {
85
+ try {
86
+ const t = r.code;
87
+ return typeof t == "string" && t.trim() === t && t.length > 0 ? t : void 0;
88
+ } catch {
89
+ return;
90
+ }
91
+ }
92
+ class z extends u {
49
93
  }
50
94
  function $(r, t, e) {
51
- return r instanceof P ? r.code === t ? r : new P(t, e, { cause: r.cause }) : r instanceof Error ? r : new P(t, e, { cause: r });
95
+ return r instanceof z ? r.code === t ? r : new z(t, e, { cause: r.cause }) : r instanceof Error ? r : new z(t, e, { cause: r });
52
96
  }
53
- function J(r, t) {
97
+ function tt(r, t) {
54
98
  if (!r || typeof r != "object" || typeof r.aborted != "boolean" || typeof r.addEventListener != "function" || typeof r.removeEventListener != "function" || typeof r.throwIfAborted != "function")
55
99
  throw new TypeError("Cancellation classifier expects an AbortSignal");
56
100
  return r.aborted ? Object.is(t, r.reason) ? !0 : t instanceof Error && t.name === "AbortError" : !1;
57
101
  }
58
- class at extends u {
102
+ class ut extends u {
59
103
  name = "ConfigValidationError";
60
104
  issues;
61
105
  constructor(t) {
62
- const e = ct(t);
106
+ const e = ft(t);
63
107
  super(
64
108
  "CONFIG_INVALID",
65
109
  `Invalid Plugin config:
@@ -68,7 +112,7 @@ ${e.map((i) => ` - ${i.message}`).join(`
68
112
  ), this.issues = e;
69
113
  }
70
114
  }
71
- function ct(r) {
115
+ function ft(r) {
72
116
  if (!Array.isArray(r))
73
117
  throw new TypeError("Config validation issues must be an array");
74
118
  return Object.freeze(
@@ -80,12 +124,12 @@ function ct(r) {
80
124
  throw new TypeError(`Config validation issue at index ${e} message must be a string`);
81
125
  return Object.freeze({
82
126
  message: i.message,
83
- ...i.path === void 0 ? {} : { path: ht(i.path, e) }
127
+ ...i.path === void 0 ? {} : { path: pt(i.path, e) }
84
128
  });
85
129
  })
86
130
  );
87
131
  }
88
- function ht(r, t) {
132
+ function pt(r, t) {
89
133
  if (!Array.isArray(r))
90
134
  throw new TypeError(`Config validation issue at index ${t} path must be an array`);
91
135
  return Object.freeze(
@@ -107,7 +151,7 @@ function ht(r, t) {
107
151
  function G(r) {
108
152
  return typeof r == "string" || typeof r == "number" || typeof r == "symbol";
109
153
  }
110
- async function X(r, t, e) {
154
+ async function et(r, t, e) {
111
155
  if (!r) return t;
112
156
  const i = await r["~standard"].validate(t);
113
157
  if (!i || typeof i != "object")
@@ -116,7 +160,7 @@ async function X(r, t, e) {
116
160
  );
117
161
  const s = Object.hasOwn(i, "issues") ? i.issues : void 0;
118
162
  if (s !== void 0)
119
- throw Array.isArray(s) ? new at(s) : new TypeError(
163
+ throw Array.isArray(s) ? new ut(s) : new TypeError(
120
164
  `Installation '${e}' config validator returned non-array issues`
121
165
  );
122
166
  if (!Object.hasOwn(i, "value"))
@@ -125,26 +169,26 @@ async function X(r, t, e) {
125
169
  );
126
170
  return i.value;
127
171
  }
128
- class dt {
172
+ class gt {
129
173
  #t = /* @__PURE__ */ new Map();
130
174
  get kinds() {
131
175
  return this.#t;
132
176
  }
133
177
  assertCompatible(t) {
134
- Z(this.#t, t);
178
+ it(this.#t, t);
135
179
  }
136
180
  remember(t) {
137
- T(this.#t, t);
181
+ j(this.#t, t);
138
182
  }
139
183
  draft(t) {
140
- return new lt(this, t);
184
+ return new wt(this, t);
141
185
  }
142
186
  commit(t) {
143
187
  for (const [e, i] of t) this.assertCompatible({ id: e, kind: i });
144
188
  for (const [e, i] of t) this.#t.set(e, i);
145
189
  }
146
190
  }
147
- class lt {
191
+ class wt {
148
192
  #t;
149
193
  constructor(t, e) {
150
194
  this.#t = { phase: "open", registry: t, pending: /* @__PURE__ */ new Map() };
@@ -158,7 +202,7 @@ class lt {
158
202
  }
159
203
  if (e.phase === "discarded")
160
204
  throw new Error("Contract registry draft has been discarded");
161
- e.registry.assertCompatible(t), !e.registry.kinds.has(t.id) && T(e.pending, t);
205
+ e.registry.assertCompatible(t), !e.registry.kinds.has(t.id) && j(e.pending, t);
162
206
  }
163
207
  commit() {
164
208
  const t = this.#t;
@@ -168,10 +212,10 @@ class lt {
168
212
  this.#t.phase === "open" && (this.#t = { phase: "discarded" });
169
213
  }
170
214
  }
171
- function T(r, t) {
172
- Z(r, t), r.set(t.id, t.kind);
215
+ function j(r, t) {
216
+ it(r, t), r.set(t.id, t.kind);
173
217
  }
174
- function Z(r, t) {
218
+ function it(r, t) {
175
219
  const e = r.get(t.id);
176
220
  if (e && e !== t.kind)
177
221
  throw new u(
@@ -190,7 +234,7 @@ class M {
190
234
  contractKinds;
191
235
  #t;
192
236
  static build(t, e) {
193
- const i = [...t].sort((c, d) => c.index - d.index), s = new Map(e), n = ut(i, s), o = ft(i, n, s), { order: a, layers: h } = pt(
237
+ const i = [...t].sort((c, d) => c.index - d.index), s = new Map(e), n = vt(i, s), o = bt(i, n, s), { order: a, layers: h } = mt(
194
238
  i,
195
239
  o.dependents,
196
240
  o.indegree
@@ -225,11 +269,11 @@ class M {
225
269
  }
226
270
  }
227
271
  }
228
- function ut(r, t) {
272
+ function vt(r, t) {
229
273
  const e = /* @__PURE__ */ new Map();
230
274
  for (const i of r)
231
275
  for (const s of Object.values(i.declaration.plugin.provides ?? {})) {
232
- T(t, s);
276
+ j(t, s);
233
277
  const n = e.get(s.id);
234
278
  if (n)
235
279
  throw new u(
@@ -240,12 +284,12 @@ function ut(r, t) {
240
284
  }
241
285
  return e;
242
286
  }
243
- function ft(r, t, e) {
287
+ function bt(r, t, e) {
244
288
  const i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), n = new Map(r.map((o) => [o, 0]));
245
289
  for (const o of r)
246
290
  for (const a of Object.values(o.declaration.plugin.requires ?? {})) {
247
291
  const h = a.kind === "optional" ? a.service : a;
248
- if (T(e, h), h.kind === "extensionPoint") continue;
292
+ if (j(e, h), h.kind === "extensionPoint") continue;
249
293
  const c = t.get(h.id);
250
294
  if (!c) {
251
295
  if (a.kind === "optional") continue;
@@ -266,7 +310,7 @@ function ft(r, t, e) {
266
310
  }
267
311
  return { resolvedProviders: i, dependents: s, indegree: n };
268
312
  }
269
- function pt(r, t, e) {
313
+ function mt(r, t, e) {
270
314
  let i = r.filter((o) => e.get(o) === 0);
271
315
  const s = [], n = [];
272
316
  for (; i.length; ) {
@@ -280,7 +324,7 @@ function pt(r, t, e) {
280
324
  }
281
325
  }
282
326
  if (s.length !== r.length) {
283
- const o = gt(r, t);
327
+ const o = yt(r, t);
284
328
  throw new u(
285
329
  "SERVICE_CYCLE",
286
330
  `Installation dependency cycle: ${o.map((a) => a.id).join(" -> ")}`
@@ -288,7 +332,7 @@ function pt(r, t, e) {
288
332
  }
289
333
  return { order: s, layers: n };
290
334
  }
291
- function gt(r, t) {
335
+ function yt(r, t) {
292
336
  const e = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = [], n = (o) => {
293
337
  i.add(o), s.push(o);
294
338
  for (const a of t.get(o) ?? []) {
@@ -309,7 +353,7 @@ function gt(r, t) {
309
353
  }
310
354
  throw new Error("Dependency graph is cyclic but no cycle path was found");
311
355
  }
312
- class S {
356
+ class O {
313
357
  #t;
314
358
  constructor(t = []) {
315
359
  if (!t || typeof t != "object" && typeof t != "function" || typeof t[Symbol.iterator] != "function")
@@ -341,21 +385,30 @@ class S {
341
385
  return this.entries();
342
386
  }
343
387
  }
344
- function wt(r) {
388
+ function Et(r) {
345
389
  if (typeof r != "function")
346
390
  throw new Error("Unsupported JavaScript runtime: Promise.withResolvers is required");
347
391
  }
348
- function tt(r, t) {
392
+ function st(r, t) {
349
393
  return r ?? Symbol.for(t);
350
394
  }
351
- wt(Promise.withResolvers);
352
- const g = tt(
395
+ Et(Promise.withResolvers);
396
+ const g = st(
353
397
  Symbol.dispose,
354
398
  "Symbol.dispose"
355
- ), j = tt(
399
+ ), k = st(
356
400
  Symbol.asyncDispose,
357
401
  "Symbol.asyncDispose"
358
- ), m = /* @__PURE__ */ new WeakMap();
402
+ );
403
+ function P(r, t) {
404
+ if (Ct(r))
405
+ throw Promise.resolve(r).catch(() => {
406
+ }), new TypeError(t);
407
+ }
408
+ function Ct(r) {
409
+ return r === null || typeof r != "object" && typeof r != "function" ? !1 : typeof r.then == "function";
410
+ }
411
+ const y = /* @__PURE__ */ new WeakMap();
359
412
  class q {
360
413
  #t = /* @__PURE__ */ new Set();
361
414
  #e;
@@ -369,18 +422,21 @@ class q {
369
422
  }
370
423
  view = Object.freeze({
371
424
  get: () => this.#n(),
372
- subscribe: (t) => this.#o(t)
425
+ subscribe: (t) => this.#a(t)
373
426
  });
374
427
  invalidate() {
375
- const { report: t } = this.#a();
428
+ const { report: t } = this.#o();
376
429
  this.#s = !0;
377
430
  const e = [];
378
431
  for (const i of [...this.#t])
379
432
  try {
380
- bt(i);
433
+ Ot(i);
381
434
  } catch (s) {
382
435
  try {
383
- t(s);
436
+ P(
437
+ t(s),
438
+ "Snapshot error reporters must be synchronous"
439
+ );
384
440
  } catch (n) {
385
441
  e.push(s, n);
386
442
  }
@@ -398,7 +454,7 @@ class q {
398
454
  this.#s = !1;
399
455
  const e = [...this.#t];
400
456
  this.#t.clear();
401
- for (const i of e) mt(i);
457
+ for (const i of e) It(i);
402
458
  }
403
459
  }
404
460
  }
@@ -409,10 +465,10 @@ class q {
409
465
  const t = this.#e;
410
466
  return t.phase === "active" && this.#r(t.read), this.#i;
411
467
  }
412
- #o(t) {
468
+ #a(t) {
413
469
  if (typeof t != "function") throw new TypeError("Subscriber must be a function");
414
- this.#a();
415
- const e = new vt(t, (i) => {
470
+ this.#o();
471
+ const e = new St(t, (i) => {
416
472
  this.#t.delete(i);
417
473
  });
418
474
  return this.#t.add(e), e;
@@ -420,31 +476,32 @@ class q {
420
476
  #r(t) {
421
477
  this.#s && (this.#i = t(), this.#s = !1);
422
478
  }
423
- #a() {
479
+ #o() {
424
480
  const t = this.#e;
425
481
  if (t.phase === "disposed") throw new TypeError("Snapshot publisher is disposed");
426
482
  return t;
427
483
  }
428
484
  }
429
- class vt {
485
+ class St {
430
486
  constructor(t, e) {
431
- m.set(this, { listener: t, detach: e }), Object.freeze(this);
487
+ y.set(this, { listener: t, detach: e }), Object.freeze(this);
432
488
  }
433
489
  dispose() {
434
- const t = m.get(this);
435
- t && (m.delete(this), t.detach(this));
490
+ const t = y.get(this);
491
+ t && (y.delete(this), t.detach(this));
436
492
  }
437
493
  [g]() {
438
494
  this.dispose();
439
495
  }
440
496
  }
441
- function bt(r) {
442
- m.get(r)?.listener();
497
+ function Ot(r) {
498
+ const t = y.get(r);
499
+ t && P(t.listener(), "Snapshot subscribers must be synchronous");
443
500
  }
444
- function mt(r) {
445
- m.delete(r);
501
+ function It(r) {
502
+ y.delete(r);
446
503
  }
447
- class yt {
504
+ class At {
448
505
  #t;
449
506
  get;
450
507
  subscribe;
@@ -466,7 +523,7 @@ class yt {
466
523
  return t;
467
524
  }
468
525
  }
469
- class Et {
526
+ class Tt {
470
527
  #t;
471
528
  constructor(t) {
472
529
  this.#t = t, Object.freeze(this);
@@ -481,12 +538,12 @@ class Et {
481
538
  this.dispose();
482
539
  }
483
540
  }
484
- class Ct {
541
+ class $t {
485
542
  #t;
486
543
  #e;
487
544
  handle;
488
545
  constructor(t, e, i, s) {
489
- this.#e = e, this.#t = { phase: "staged", store: t, value: i, detachFromOwner: s }, this.handle = new Et(this);
546
+ this.#e = e, this.#t = { phase: "staged", store: t, value: i, detachFromOwner: s }, this.handle = new Tt(this);
490
547
  }
491
548
  publish() {
492
549
  const t = this.#t;
@@ -519,33 +576,33 @@ class Ct {
519
576
  this.dispose();
520
577
  }
521
578
  }
522
- class Ot {
579
+ class jt {
523
580
  #t;
524
581
  #e;
525
582
  #i = /* @__PURE__ */ new Map();
526
583
  #s = /* @__PURE__ */ new Map();
527
584
  #n;
528
- #o = new S();
585
+ #a = new O();
529
586
  #r = 0;
530
- #a = 0;
587
+ #o = 0;
531
588
  #d = !1;
532
589
  #f = !1;
533
590
  constructor(t, e, i) {
534
- this.#t = t, this.#e = i, this.#n = new q(() => this.#o, e);
591
+ this.#t = t, this.#e = i, this.#n = new q(() => this.#a, e);
535
592
  }
536
593
  stage(t, e, i, s) {
537
- $t(e);
538
- const n = Tt(t, e);
594
+ zt(e);
595
+ const n = Rt(t, e);
539
596
  if (this.#i.has(n))
540
597
  throw new TypeError(`Duplicate contribution '${n}'`);
541
- const o = new Ct(this, n, i, s);
598
+ const o = new $t(this, n, i, s);
542
599
  return this.#i.set(n, o), o;
543
600
  }
544
601
  view(t) {
545
602
  this.#r++;
546
603
  const e = { binding: { store: this, own: t } };
547
604
  let i;
548
- const s = new St(e, () => {
605
+ const s = new kt(e, () => {
549
606
  const n = i;
550
607
  i = void 0;
551
608
  try {
@@ -559,7 +616,7 @@ class Ot {
559
616
  } catch (n) {
560
617
  throw e.binding = void 0, this.#r--, this.#h(), n;
561
618
  }
562
- return new yt(e);
619
+ return new At(e);
563
620
  }
564
621
  /** A stable view explicitly owned by the Host for graph-external consumers. */
565
622
  hostView() {
@@ -572,15 +629,15 @@ class Ot {
572
629
  if (typeof t != "function")
573
630
  throw new TypeError("Contribution subscriber must be a function");
574
631
  const i = this.#n.view.subscribe(t);
575
- this.#a++;
632
+ this.#o++;
576
633
  let s;
577
- const n = new It(i, () => {
634
+ const n = new Pt(i, () => {
578
635
  const o = s;
579
636
  s = void 0;
580
637
  try {
581
638
  o?.();
582
639
  } finally {
583
- this.#a--, this.#h();
640
+ this.#o--, this.#h();
584
641
  }
585
642
  });
586
643
  try {
@@ -609,7 +666,7 @@ class Ot {
609
666
  }
610
667
  publishSnapshot() {
611
668
  const t = [...this.#s].map(([i, s]) => [i, s.value]);
612
- t.length === this.#o.size && t.every(([i, s]) => Object.is(this.#o.get(i), s)) || (this.#o = new S(t), this.#n.invalidate());
669
+ t.length === this.#a.size && t.every(([i, s]) => Object.is(this.#a.get(i), s)) || (this.#a = new O(t), this.#n.invalidate());
613
670
  }
614
671
  #l(t, e) {
615
672
  if (this.#i.get(t) !== e)
@@ -622,7 +679,7 @@ class Ot {
622
679
  return i;
623
680
  }
624
681
  #h() {
625
- if (!(this.#f || this.#d || this.#i.size || this.#s.size || this.#a || this.#r)) {
682
+ if (!(this.#f || this.#d || this.#i.size || this.#s.size || this.#o || this.#r)) {
626
683
  this.#f = !0;
627
684
  try {
628
685
  this.#n.dispose();
@@ -632,7 +689,7 @@ class Ot {
632
689
  }
633
690
  }
634
691
  }
635
- class St {
692
+ class kt {
636
693
  #t;
637
694
  constructor(t, e) {
638
695
  this.#t = { state: t, release: e }, Object.freeze(this);
@@ -645,7 +702,7 @@ class St {
645
702
  this.dispose();
646
703
  }
647
704
  }
648
- class It {
705
+ class Pt {
649
706
  #t;
650
707
  constructor(t, e) {
651
708
  this.#t = { subscription: t, release: e }, Object.freeze(this);
@@ -665,7 +722,7 @@ class It {
665
722
  this.dispose();
666
723
  }
667
724
  }
668
- class At {
725
+ class Lt {
669
726
  #t = /* @__PURE__ */ new Map();
670
727
  #e = /* @__PURE__ */ new Set();
671
728
  #i;
@@ -676,7 +733,7 @@ class At {
676
733
  get(t) {
677
734
  const e = this.#t.get(t.id);
678
735
  if (e) return e;
679
- const i = new Ot(
736
+ const i = new jt(
680
737
  (s) => this.#n(s),
681
738
  this.#i,
682
739
  (s) => {
@@ -711,19 +768,19 @@ class At {
711
768
  this.#e.add(t), !this.#s && (this.#e.delete(t), t.publishSnapshot());
712
769
  }
713
770
  }
714
- function $t(r) {
771
+ function zt(r) {
715
772
  if (typeof r != "string" || !r.trim())
716
773
  throw new TypeError("Contribution key must be a non-empty string");
717
774
  if (r !== r.trim())
718
775
  throw new TypeError("Contribution key cannot start or end with whitespace");
719
776
  }
720
- function Tt(r, t) {
721
- return `${B(r)}/${B(t)}`;
777
+ function Rt(r, t) {
778
+ return `${U(r)}/${U(t)}`;
722
779
  }
723
- function B(r) {
780
+ function U(r) {
724
781
  return r.replaceAll("%", "%25").replaceAll("/", "%2F");
725
782
  }
726
- class jt {
783
+ class Nt {
727
784
  #t;
728
785
  constructor(t) {
729
786
  this.#t = t, Object.freeze(this);
@@ -736,12 +793,12 @@ class jt {
736
793
  this.dispose();
737
794
  }
738
795
  }
739
- class kt {
796
+ class xt {
740
797
  #t;
741
798
  #e;
742
799
  handle;
743
800
  constructor(t, e, i, s) {
744
- this.#e = e, this.#t = { phase: "staged", hub: t, slot: { listener: i }, release: s }, this.handle = new jt(this);
801
+ this.#e = e, this.#t = { phase: "staged", hub: t, slot: { listener: i }, release: s }, this.handle = new Nt(this);
745
802
  }
746
803
  publish() {
747
804
  const t = this.#t;
@@ -762,11 +819,11 @@ class kt {
762
819
  this.dispose();
763
820
  }
764
821
  }
765
- class Pt {
822
+ class Dt {
766
823
  #t = /* @__PURE__ */ new Map();
767
824
  stage(t, e, i) {
768
825
  if (typeof e != "function") throw new TypeError("Event listener must be a function");
769
- return new kt(this, t, e, i);
826
+ return new xt(this, t, e, i);
770
827
  }
771
828
  add(t, e) {
772
829
  const i = this.#t.get(t) ?? /* @__PURE__ */ new Set();
@@ -786,15 +843,15 @@ class Pt {
786
843
  throw new AggregateError(n, `Event '${t}' listeners failed`);
787
844
  }
788
845
  }
789
- class Lt {
846
+ class Vt {
790
847
  #t;
791
848
  root;
792
849
  view;
793
850
  constructor(t, e) {
794
- this.root = F(t), this.#t = new q(() => et(this.root), e), this.view = this.#t.view;
851
+ this.root = _(t), this.#t = new q(() => rt(this.root), e), this.view = this.#t.view;
795
852
  }
796
853
  createNode(t) {
797
- return F(t);
854
+ return _(t);
798
855
  }
799
856
  attach(t, e) {
800
857
  if (t.children.has(e)) throw new Error("Lifetime diagnostic node is attached");
@@ -815,7 +872,7 @@ class Lt {
815
872
  this.root.phase !== "disposed" && (this.root.phase = "disposed", this.#t.invalidate(), this.#t.dispose());
816
873
  }
817
874
  }
818
- function F(r) {
875
+ function _(r) {
819
876
  return {
820
877
  label: r,
821
878
  phase: "active",
@@ -830,8 +887,8 @@ function F(r) {
830
887
  children: /* @__PURE__ */ new Set()
831
888
  };
832
889
  }
833
- function et(r) {
834
- const t = Object.freeze([...r.children].map(et));
890
+ function rt(r) {
891
+ const t = Object.freeze([...r.children].map(rt));
835
892
  return Object.freeze({
836
893
  label: r.label,
837
894
  phase: r.phase,
@@ -839,14 +896,18 @@ function et(r) {
839
896
  children: t
840
897
  });
841
898
  }
842
- function zt(r) {
843
- if (!r || typeof r != "object") return !1;
844
- const t = r;
845
- return [t.debug, t.info, t.warn, t.error].every(
846
- (e) => typeof e == "function"
847
- );
899
+ function Mt(r) {
900
+ if (!r || typeof r != "object" && typeof r != "function") return !1;
901
+ try {
902
+ const t = r;
903
+ return [t.debug, t.info, t.warn, t.error].every(
904
+ (e) => typeof e == "function"
905
+ );
906
+ } catch {
907
+ return !1;
908
+ }
848
909
  }
849
- const R = Object.freeze(new DOMException("Resource disposed", "AbortError"));
910
+ const x = Object.freeze(new DOMException("Resource disposed", "AbortError"));
850
911
  class w {
851
912
  #t = /* @__PURE__ */ new Set();
852
913
  #e;
@@ -885,7 +946,7 @@ class w {
885
946
  return this.#t[Symbol.iterator]();
886
947
  }
887
948
  }
888
- class Rt {
949
+ class qt {
889
950
  #t;
890
951
  constructor(t, e) {
891
952
  this.#t = { phase: "active", cleanup: t, detachFromParent: e }, Object.freeze(this);
@@ -905,11 +966,11 @@ class Rt {
905
966
  });
906
967
  return this.#t = { phase: "disposing", completion: e }, e;
907
968
  }
908
- [j]() {
969
+ [k]() {
909
970
  return this.dispose();
910
971
  }
911
972
  }
912
- class Nt {
973
+ class Bt {
913
974
  #t;
914
975
  #e;
915
976
  #i;
@@ -922,7 +983,7 @@ class Nt {
922
983
  () => this.#s(),
923
984
  (a) => {
924
985
  try {
925
- J(n.signal, a) || i(a);
986
+ tt(n.signal, a) || i(a);
926
987
  } finally {
927
988
  this.#s();
928
989
  }
@@ -940,9 +1001,9 @@ class Nt {
940
1001
  () => {
941
1002
  }
942
1003
  );
943
- return this.#i = { phase: "disposing", completion: e }, t.controller.abort(R), this.#n(), e;
1004
+ return this.#i = { phase: "disposing", completion: e }, t.controller.abort(x), this.#n(), e;
944
1005
  }
945
- [j]() {
1006
+ [k]() {
946
1007
  return this.dispose();
947
1008
  }
948
1009
  #s() {
@@ -956,15 +1017,15 @@ class Nt {
956
1017
  this.#t = void 0, t?.();
957
1018
  }
958
1019
  }
959
- class D {
1020
+ class B {
960
1021
  #t;
961
1022
  #e;
962
1023
  #i;
963
1024
  #s;
964
1025
  #n;
965
- #o;
966
- #r;
967
1026
  #a;
1027
+ #r;
1028
+ #o;
968
1029
  #d;
969
1030
  #f;
970
1031
  #l;
@@ -972,7 +1033,7 @@ class D {
972
1033
  handle;
973
1034
  #h;
974
1035
  constructor(t, e, i = {}) {
975
- this.#e = e, this.handle = new xt(this);
1036
+ this.#e = e, this.handle = new Ft(this);
976
1037
  const s = new AbortController();
977
1038
  this.#h = {
978
1039
  phase: "active",
@@ -981,14 +1042,14 @@ class D {
981
1042
  };
982
1043
  const n = i.parent;
983
1044
  this.#u = n?.detach, this.#f = n ? "child" : "root";
984
- const o = n?.diagnostics ?? new Lt(e, (l) => t.report(l)), a = n?.diagnosticNode ?? o.root;
1045
+ const o = n?.diagnostics ?? new Vt(e, (l) => t.report(l)), a = n?.diagnosticNode ?? o.root;
985
1046
  this.#t = { port: t, diagnostics: o, diagnosticNode: a };
986
1047
  const h = (l) => ({
987
1048
  diagnostics: o,
988
1049
  node: a,
989
1050
  kind: l
990
1051
  });
991
- this.#i = new w(h("listeners")), this.#s = new w(h("contributions")), this.#n = new w(h("contributionViews")), this.#o = new w(h("subscriptions")), this.#r = new w(h("tasks")), this.#a = new w(), this.#d = new w(h("cleanups"));
1052
+ this.#i = new w(h("listeners")), this.#s = new w(h("contributions")), this.#n = new w(h("contributionViews")), this.#a = new w(h("subscriptions")), this.#r = new w(h("tasks")), this.#o = new w(), this.#d = new w(h("cleanups"));
992
1053
  const c = i.parentSignal;
993
1054
  if (!c) return;
994
1055
  const d = () => s.abort(c.reason);
@@ -1001,7 +1062,7 @@ class D {
1001
1062
  get diagnostics() {
1002
1063
  return this.#c().diagnostics.view;
1003
1064
  }
1004
- /** A facade whose only Runtime edge disappears when this Lifetime terminates. */
1065
+ /** A facade whose only InstanceCoordinator edge disappears when this Lifetime terminates. */
1005
1066
  contextLogger(t) {
1006
1067
  const e = (i) => (s, ...n) => this.#p().port.writeLog(i, s, t, n);
1007
1068
  return Object.freeze({
@@ -1013,29 +1074,29 @@ class D {
1013
1074
  }
1014
1075
  cleanup(t) {
1015
1076
  if (this.#c(), typeof t != "function") throw new TypeError("Cleanup must be a function");
1016
- const e = new Rt(t, this.#d.release);
1077
+ const e = new qt(t, this.#d.release);
1017
1078
  return this.#d.add(e), e;
1018
1079
  }
1019
1080
  lifetime(t) {
1020
1081
  const { port: e, diagnostics: i, diagnosticNode: s } = this.#c();
1021
- Vt(t);
1022
- const n = i.createNode(t), o = new D(e, this.#e, {
1082
+ Gt(t);
1083
+ const n = i.createNode(t), o = new B(e, this.#e, {
1023
1084
  parentSignal: this.signal,
1024
1085
  declarations: this.#g(),
1025
1086
  parent: {
1026
1087
  diagnostics: i,
1027
1088
  diagnosticNode: n,
1028
1089
  detach: (a) => {
1029
- this.#a.release(a) && i.detach(s, n);
1090
+ this.#o.release(a) && i.detach(s, n);
1030
1091
  }
1031
1092
  }
1032
1093
  });
1033
- return this.#a.add(o), i.attach(s, n), o.handle;
1094
+ return this.#o.add(o), i.attach(s, n), o.handle;
1034
1095
  }
1035
1096
  spawn(t) {
1036
1097
  const { port: e } = this.#c();
1037
1098
  if (typeof t != "function") throw new TypeError("Background task must be a function");
1038
- const i = new Nt(
1099
+ const i = new Bt(
1039
1100
  this.signal,
1040
1101
  t,
1041
1102
  (s) => e.report(s),
@@ -1044,7 +1105,12 @@ class D {
1044
1105
  return this.#r.add(i), i;
1045
1106
  }
1046
1107
  on(t, e) {
1047
- const { port: i } = this.#c(), s = i.stageOn(this.#e, t, e, this.#i.release);
1108
+ const { port: i } = this.#c(), s = i.stageOn(
1109
+ this.#e,
1110
+ t,
1111
+ e,
1112
+ this.#i.release
1113
+ );
1048
1114
  return this.#i.add(s), this.#g() === "published" && s.publish(), s.handle;
1049
1115
  }
1050
1116
  async emit(t, ...e) {
@@ -1063,7 +1129,7 @@ class D {
1063
1129
  }
1064
1130
  /** Owns an internal live capability without exposing a second Context API. */
1065
1131
  ownLease(t, e) {
1066
- return this.#c(), (e === "view" ? this.#n : this.#o).own(t);
1132
+ return this.#c(), (e === "view" ? this.#n : this.#a).own(t);
1067
1133
  }
1068
1134
  /** Releases a temporary startup cancellation edge after its layer commits. */
1069
1135
  detachStartupSignal() {
@@ -1073,11 +1139,11 @@ class D {
1073
1139
  /** Atomically makes all declarations staged during setup visible. */
1074
1140
  publish() {
1075
1141
  const t = this.#h;
1076
- if (t.phase !== "active") throw y();
1142
+ if (t.phase !== "active") throw E();
1077
1143
  if (this.#c(), t.declarations !== "published") {
1078
1144
  for (const e of this.#i) e.publish();
1079
1145
  for (const e of this.#s) e.publish();
1080
- for (const e of this.#a) e.publish();
1146
+ for (const e of this.#o) e.publish();
1081
1147
  this.#h = { ...t, declarations: "published" };
1082
1148
  }
1083
1149
  }
@@ -1087,10 +1153,10 @@ class D {
1087
1153
  if (t.phase === "disposed") return Promise.resolve();
1088
1154
  const e = this.#p(), i = Promise.resolve().then(async () => {
1089
1155
  const s = [];
1090
- if (await this.#i.dispose(s), await this.#s.dispose(s), await this.#o.dispose(s), await this.#n.dispose(s), t.controller.abort(R), this.detachStartupSignal(), await this.#r.dispose(s), await this.#a.dispose(s), await this.#d.dispose(s), s.length === 1) throw s[0];
1156
+ if (await this.#i.dispose(s), await this.#s.dispose(s), await this.#a.dispose(s), await this.#n.dispose(s), t.controller.abort(x), this.detachStartupSignal(), await this.#r.dispose(s), await this.#o.dispose(s), await this.#d.dispose(s), s.length === 1) throw s[0];
1091
1157
  if (s.length > 1) throw new AggregateError(s, "Lifetime cleanup failed");
1092
1158
  }).finally(() => {
1093
- this.#h = { phase: "disposed", signal: AbortSignal.abort(R) };
1159
+ this.#h = { phase: "disposed", signal: AbortSignal.abort(x) };
1094
1160
  const s = this.#u;
1095
1161
  this.#u = void 0;
1096
1162
  try {
@@ -1101,27 +1167,27 @@ class D {
1101
1167
  });
1102
1168
  return this.#h = { phase: "disposing", controller: t.controller, completion: i }, e.diagnostics.beginDisposing(e.diagnosticNode), i;
1103
1169
  }
1104
- [j]() {
1170
+ [k]() {
1105
1171
  return this.dispose();
1106
1172
  }
1107
1173
  #c() {
1108
1174
  const t = this.#t;
1109
1175
  if (this.#h.phase !== "active" || this.signal.aborted || !t)
1110
- throw y();
1176
+ throw E();
1111
1177
  return t;
1112
1178
  }
1113
1179
  #p() {
1114
1180
  const t = this.#t;
1115
- if (!t) throw y();
1181
+ if (!t) throw E();
1116
1182
  return t;
1117
1183
  }
1118
1184
  #g() {
1119
1185
  const t = this.#h;
1120
- if (t.phase !== "active") throw y();
1186
+ if (t.phase !== "active") throw E();
1121
1187
  return t.declarations;
1122
1188
  }
1123
1189
  }
1124
- class xt {
1190
+ class Ft {
1125
1191
  #t;
1126
1192
  constructor(t) {
1127
1193
  this.#t = t, Object.freeze(this);
@@ -1150,32 +1216,32 @@ class xt {
1150
1216
  dispose() {
1151
1217
  return this.#t.dispose();
1152
1218
  }
1153
- [j]() {
1219
+ [k]() {
1154
1220
  return this.dispose();
1155
1221
  }
1156
1222
  }
1157
- function Vt(r) {
1223
+ function Gt(r) {
1158
1224
  if (typeof r != "string" || !r.trim())
1159
1225
  throw new TypeError("Lifetime label must be a non-empty string");
1160
1226
  if (r !== r.trim())
1161
1227
  throw new TypeError("Lifetime label cannot start or end with whitespace");
1162
1228
  }
1163
- function y() {
1229
+ function E() {
1164
1230
  return new u("LIFETIME_DISPOSED", "Lifetime is disposing or has been disposed");
1165
1231
  }
1166
- class N extends AggregateError {
1232
+ class D extends AggregateError {
1167
1233
  }
1168
- class Mt {
1234
+ class Ut {
1169
1235
  #t;
1170
1236
  #e;
1171
1237
  #i;
1172
1238
  #s;
1173
1239
  #n = /* @__PURE__ */ new Map();
1174
- #o = new Pt();
1240
+ #a = new Dt();
1175
1241
  #r;
1176
- #a = [];
1242
+ #o = [];
1177
1243
  constructor(t) {
1178
- this.#t = t.hostName, this.#e = t.logger, this.#i = t.isInstalled, this.#s = t.report, this.#r = new At(t.report);
1244
+ this.#t = t.hostName, this.#e = t.logger, this.#i = t.isInstalled, this.#s = t.report, this.#r = new Lt(t.report);
1179
1245
  }
1180
1246
  readService(t, e) {
1181
1247
  const i = this.#n.get(t);
@@ -1193,13 +1259,13 @@ class Mt {
1193
1259
  return e;
1194
1260
  }
1195
1261
  resetActivationState() {
1196
- this.#n.clear(), this.#a = [];
1262
+ this.#n.clear(), this.#o = [];
1197
1263
  }
1198
1264
  commitActivationOrder(t) {
1199
- this.#a = t.slice();
1265
+ this.#o = t.slice();
1200
1266
  }
1201
1267
  deactivateAll() {
1202
- return this.deactivate(new Set(this.#a));
1268
+ return this.deactivate(new Set(this.#o));
1203
1269
  }
1204
1270
  async activate(t, e, i, s) {
1205
1271
  const n = this.#c(s);
@@ -1211,7 +1277,7 @@ class Mt {
1211
1277
  const h = new AbortController(), c = await Promise.allSettled(
1212
1278
  a.map(async (f) => {
1213
1279
  try {
1214
- const p = i.has(f) ? i.get(f) : await X(
1280
+ const p = i.has(f) ? i.get(f) : await et(
1215
1281
  f.declaration.plugin.config,
1216
1282
  f.declaration.config,
1217
1283
  f.id
@@ -1227,12 +1293,12 @@ class Mt {
1227
1293
  throw h.abort(p), p;
1228
1294
  }
1229
1295
  })
1230
- ), d = qt(c, h.signal), l = c.filter(
1296
+ ), d = _t(c, h.signal), l = c.filter(
1231
1297
  (f) => f.status === "fulfilled"
1232
1298
  ).map((f) => f.value);
1233
1299
  if (d.length) {
1234
1300
  const f = await this.#l(l), p = d.length === 1 ? d[0] : new AggregateError(d, "Installation startup layer failed");
1235
- throw f.length ? new N(
1301
+ throw f.length ? new D(
1236
1302
  [p, ...f],
1237
1303
  "Installation startup layer failed and could not be cleanly disposed"
1238
1304
  ) : p;
@@ -1241,8 +1307,8 @@ class Mt {
1241
1307
  }
1242
1308
  }
1243
1309
  async deactivate(t) {
1244
- const e = [], i = this.#a.filter((s) => t.has(s)).reverse();
1245
- this.#a = this.#a.filter(
1310
+ const e = [], i = this.#o.filter((s) => t.has(s)).reverse();
1311
+ this.#o = this.#o.filter(
1246
1312
  (s) => !t.has(s)
1247
1313
  );
1248
1314
  for (const s of i) {
@@ -1285,7 +1351,7 @@ class Mt {
1285
1351
  }
1286
1352
  async #d(t, e, i, s, n) {
1287
1353
  e.deactivate();
1288
- const o = e.declaration.plugin, a = new D(n, e.id, { parentSignal: s });
1354
+ const o = e.declaration.plugin, a = new B(n, e.id, { parentSignal: s });
1289
1355
  try {
1290
1356
  const h = this.#u(t, e, o, a), c = Object.freeze({
1291
1357
  hostName: this.#t,
@@ -1293,13 +1359,13 @@ class Mt {
1293
1359
  installationId: e.id,
1294
1360
  groupId: e.groupId
1295
1361
  }), d = this.#h(a, c, h), l = await o.setup(d, i), f = /* @__PURE__ */ new Map();
1296
- for (const [p, st] of Object.entries(o.provides ?? {})) {
1362
+ for (const [p, ot] of Object.entries(o.provides ?? {})) {
1297
1363
  if (typeof l != "object" || l === null || !Object.hasOwn(l, p))
1298
1364
  throw new u(
1299
1365
  "SERVICE_NOT_RETURNED",
1300
1366
  `Installation '${e.id}' did not return provided Service '${p}'`
1301
1367
  );
1302
- f.set(st.id, l[p]);
1368
+ f.set(ot.id, l[p]);
1303
1369
  }
1304
1370
  return Object.freeze({
1305
1371
  installation: e,
@@ -1311,7 +1377,7 @@ class Mt {
1311
1377
  try {
1312
1378
  await a.dispose();
1313
1379
  } catch (d) {
1314
- throw new N(
1380
+ throw new D(
1315
1381
  [c, d],
1316
1382
  `Installation '${e.id}' failed to start and could not be cleanly disposed`
1317
1383
  );
@@ -1321,7 +1387,7 @@ class Mt {
1321
1387
  }
1322
1388
  #f(t) {
1323
1389
  for (const { installation: e, instance: i, services: s } of t)
1324
- this.#n.set(e, s), e.activate(i), this.#a.push(e);
1390
+ this.#n.set(e, s), e.activate(i), this.#o.push(e);
1325
1391
  for (const { instance: e } of t)
1326
1392
  e.lifetime.publish(), e.lifetime.detachStartupSignal();
1327
1393
  }
@@ -1384,18 +1450,23 @@ class Mt {
1384
1450
  stageOn: (e, i, s, n) => this.#p(e, i, s, n, t),
1385
1451
  emit: (e, i, s) => this.#g(e, i, s, t),
1386
1452
  stageContribution: (e, i, s, n, o) => this.#v(e, i, s, n, o, t),
1387
- writeLog: (e, i, s, n) => this.#e[e](i, s, ...n),
1453
+ writeLog: (e, i, s, n) => {
1454
+ P(
1455
+ this.#e[e](i, s, ...n),
1456
+ "Logger methods must be synchronous"
1457
+ );
1458
+ },
1388
1459
  report: this.#s
1389
1460
  };
1390
1461
  }
1391
1462
  #p(t, e, i, s, n) {
1392
- return this.#w(t), b(e, "event"), n.remember(e), this.#o.stage(e.id, i, s);
1463
+ return this.#w(t), m(e, "event"), n.remember(e), this.#a.stage(e.id, i, s);
1393
1464
  }
1394
1465
  #g(t, e, i, s) {
1395
- return this.#w(t), b(e, "event"), s.remember(e), this.#o.emit(e.id, i);
1466
+ return this.#w(t), m(e, "event"), s.remember(e), this.#a.emit(e.id, i);
1396
1467
  }
1397
1468
  #v(t, e, i, s, n, o) {
1398
- return this.#w(t), b(e, "extensionPoint"), o.remember(e), this.#r.get(e).stage(t, i, s, n);
1469
+ return this.#w(t), m(e, "extensionPoint"), o.remember(e), this.#r.get(e).stage(t, i, s, n);
1399
1470
  }
1400
1471
  #b(t, e) {
1401
1472
  return this.#r.get(t).view((i, s) => e.ownLease(i, s));
@@ -1405,27 +1476,27 @@ class Mt {
1405
1476
  throw new Error(`Installation '${t}' is not installed`);
1406
1477
  }
1407
1478
  }
1408
- function qt(r, t) {
1479
+ function _t(r, t) {
1409
1480
  const e = [];
1410
1481
  let i = !1;
1411
1482
  for (const s of r)
1412
- s.status !== "fulfilled" && (Object.is(s.reason, t.reason) ? (i || e.push(s.reason), i = !0) : J(t, s.reason) || e.push(s.reason));
1483
+ s.status !== "fulfilled" && (Object.is(s.reason, t.reason) ? (i || e.push(s.reason), i = !0) : tt(t, s.reason) || e.push(s.reason));
1413
1484
  return e;
1414
1485
  }
1415
- class Dt {
1416
- #t = new dt();
1486
+ class Ht {
1487
+ #t = new gt();
1417
1488
  #e;
1418
1489
  #i;
1419
1490
  constructor(t) {
1420
- this.#e = new Mt(t);
1491
+ this.#e = new Ut(t);
1421
1492
  }
1422
1493
  get hasCommittedPlan() {
1423
1494
  return this.#i !== void 0;
1424
1495
  }
1425
1496
  get(t, e) {
1426
- const i = ot(t), s = i ? t.service : t;
1427
- if (b(s, "service"), this.#t.assertCompatible(s), e === "unavailable") throw U();
1428
- const n = this.#a().provider(s.id);
1497
+ const i = ht(t), s = i ? t.service : t;
1498
+ if (m(s, "service"), this.#t.assertCompatible(s), e === "unavailable") throw H();
1499
+ const n = this.#o().provider(s.id);
1429
1500
  if (!n) {
1430
1501
  if (i) return;
1431
1502
  throw new u("SERVICE_UNAVAILABLE", `Service '${s.id}' is not active`);
@@ -1438,7 +1509,7 @@ class Dt {
1438
1509
  return o.value;
1439
1510
  }
1440
1511
  contributions(t) {
1441
- return b(t, "extensionPoint"), this.#t.remember(t), this.#e.contributions(t);
1512
+ return m(t, "extensionPoint"), this.#t.remember(t), this.#e.contributions(t);
1442
1513
  }
1443
1514
  buildPlan(t) {
1444
1515
  return M.build(t, this.#t.kinds);
@@ -1452,12 +1523,14 @@ class Dt {
1452
1523
  }
1453
1524
  }
1454
1525
  async stop() {
1455
- const t = await this.#e.withContributionBatch(() => this.#e.deactivateAll());
1526
+ const t = await this.#e.withContributionBatch(
1527
+ () => this.#e.deactivateAll()
1528
+ );
1456
1529
  return this.#i = void 0, t;
1457
1530
  }
1458
1531
  async transition(t, e, i) {
1459
1532
  return this.#e.withContributionBatch(async () => {
1460
- const s = this.#a(), n = s.affectedByTransitionTo(t, e);
1533
+ const s = this.#o(), n = s.affectedByTransitionTo(t, e);
1461
1534
  let o, a;
1462
1535
  try {
1463
1536
  o = await this.#r(
@@ -1477,11 +1550,11 @@ class Dt {
1477
1550
  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 });
1478
1551
  } catch (d) {
1479
1552
  const l = await this.#e.deactivate(n);
1480
- return a.discard(), d instanceof N || l.length ? this.#n(
1553
+ return a.discard(), d instanceof D || l.length ? this.#n(
1481
1554
  i,
1482
1555
  [d, ...l],
1483
1556
  "Installation change failed and its partial activation could not be cleanly disposed"
1484
- ) : this.#o(i, s, n, h, [
1557
+ ) : this.#a(i, s, n, h, [
1485
1558
  d,
1486
1559
  ...l
1487
1560
  ]);
@@ -1503,7 +1576,7 @@ class Dt {
1503
1576
  const s = await this.#e.deactivateAll();
1504
1577
  throw this.#i = void 0, new AggregateError([...e, ...s], i);
1505
1578
  }
1506
- async #o(t, e, i, s, n) {
1579
+ async #a(t, e, i, s, n) {
1507
1580
  t();
1508
1581
  const o = this.#t.draft(e.contractKinds);
1509
1582
  try {
@@ -1524,7 +1597,7 @@ class Dt {
1524
1597
  try {
1525
1598
  e.set(
1526
1599
  i,
1527
- await X(
1600
+ await et(
1528
1601
  i.declaration.plugin.config,
1529
1602
  i.declaration.config,
1530
1603
  i.id
@@ -1539,15 +1612,15 @@ class Dt {
1539
1612
  }
1540
1613
  return e;
1541
1614
  }
1542
- #a() {
1543
- if (!this.#i) throw U();
1615
+ #o() {
1616
+ if (!this.#i) throw H();
1544
1617
  return this.#i;
1545
1618
  }
1546
1619
  }
1547
- function U() {
1620
+ function H() {
1548
1621
  return new u("SERVICE_UNAVAILABLE", "Host services are not active");
1549
1622
  }
1550
- class Gt {
1623
+ class Kt {
1551
1624
  #t;
1552
1625
  #e;
1553
1626
  #i;
@@ -1592,28 +1665,31 @@ class Gt {
1592
1665
  name: this.#t,
1593
1666
  status: t,
1594
1667
  revision: this.#s,
1595
- installations: new S(s),
1596
- groups: new S(n)
1668
+ installations: new O(s),
1669
+ groups: new O(n)
1597
1670
  });
1598
1671
  }
1599
1672
  }
1600
- function k(r, t, e = {}) {
1673
+ function L(r, t, e = {}) {
1601
1674
  if (!r || typeof r != "object" || Array.isArray(r))
1602
- throw E(e, `${t} must be a plain record`);
1675
+ throw b(e, `${t} must be a plain record`);
1603
1676
  const i = Object.getPrototypeOf(r);
1604
1677
  if (i !== Object.prototype && i !== null)
1605
- throw E(e, `${t} must be a plain record`);
1678
+ throw b(e, `${t} must be a plain record`);
1606
1679
  for (const s of Reflect.ownKeys(r)) {
1607
- if (typeof s != "string" || !Object.prototype.propertyIsEnumerable.call(r, s))
1608
- throw E(e, `${t} keys must be enumerable strings`);
1680
+ const n = Reflect.getOwnPropertyDescriptor(r, s);
1681
+ if (typeof s != "string" || !n?.enumerable)
1682
+ throw b(e, `${t} keys must be enumerable strings`);
1683
+ if (!("value" in n))
1684
+ throw b(e, `${t} field '${s}' must be a data property`);
1609
1685
  if (e.fields && !e.fields.has(s))
1610
- throw E(e, `${t}: unknown field '${s}'`);
1686
+ throw b(e, `${t}: unknown field '${s}'`);
1611
1687
  }
1612
1688
  }
1613
- function E(r, t) {
1689
+ function b(r, t) {
1614
1690
  return r.createError?.(t) ?? new TypeError(t);
1615
1691
  }
1616
- const Bt = /* @__PURE__ */ new Set([
1692
+ const Wt = /* @__PURE__ */ new Set([
1617
1693
  "signal",
1618
1694
  "meta",
1619
1695
  "log",
@@ -1623,12 +1699,12 @@ const Bt = /* @__PURE__ */ new Set([
1623
1699
  "on",
1624
1700
  "emit",
1625
1701
  "contribute"
1626
- ]), Ft = /* @__PURE__ */ new Set(["name", "config", "requires", "provides", "setup"]);
1627
- function pe(r) {
1628
- return it(r);
1702
+ ]), Yt = /* @__PURE__ */ new Set(["name", "config", "requires", "provides", "setup"]);
1703
+ function ve(r) {
1704
+ return nt(r);
1629
1705
  }
1630
- function it(r) {
1631
- Ut(r);
1706
+ function nt(r) {
1707
+ Qt(r);
1632
1708
  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;
1633
1709
  if (typeof t != "string" || !t.trim())
1634
1710
  throw new TypeError("Plugin name must be a non-empty string");
@@ -1636,15 +1712,15 @@ function it(r) {
1636
1712
  throw new TypeError("Plugin name cannot start or end with whitespace");
1637
1713
  if (typeof n != "function")
1638
1714
  throw new TypeError(`Plugin '${t}' must define setup()`);
1639
- if (e !== void 0 && !_t(e))
1715
+ if (e !== void 0 && !Jt(e))
1640
1716
  throw new TypeError(`Plugin '${t}' config must implement Standard Schema V1`);
1641
- _(i, t, "requires"), _(s, t, "provides");
1717
+ K(i, t, "requires"), K(s, t, "provides");
1642
1718
  const o = i ? Object.freeze({ ...i }) : void 0, a = s ? Object.freeze({ ...s }) : void 0, h = /* @__PURE__ */ new Map();
1643
1719
  for (const [c, d] of Object.entries(o ?? {})) {
1644
1720
  if (!c.trim()) throw new TypeError("Plugin requirement alias cannot be empty");
1645
1721
  if (c !== c.trim())
1646
1722
  throw new TypeError("Plugin requirement alias cannot start or end with whitespace");
1647
- if (Bt.has(c))
1723
+ if (Wt.has(c))
1648
1724
  throw new TypeError(`Plugin requirement '${c}' conflicts with the context API`);
1649
1725
  if (!d || typeof d != "object")
1650
1726
  throw new TypeError(`Plugin requirement '${c}' is not a contract`);
@@ -1653,7 +1729,7 @@ function it(r) {
1653
1729
  throw new TypeError(`Optional requirement '${c}' must wrap a Service`);
1654
1730
  } else if (!v(d, "service") && !v(d, "extensionPoint"))
1655
1731
  throw new TypeError(`Plugin requirement '${c}' must be a Service or ExtensionPoint`);
1656
- H(
1732
+ W(
1657
1733
  t,
1658
1734
  h,
1659
1735
  "requirement",
@@ -1667,7 +1743,7 @@ function it(r) {
1667
1743
  throw new TypeError("Plugin provision alias cannot start or end with whitespace");
1668
1744
  if (!v(d, "service"))
1669
1745
  throw new TypeError(`Plugin provision '${c}' must be a Service`);
1670
- H(t, h, "provision", c, d);
1746
+ W(t, h, "provision", c, d);
1671
1747
  }
1672
1748
  return Object.freeze({
1673
1749
  name: t,
@@ -1677,20 +1753,20 @@ function it(r) {
1677
1753
  setup: n
1678
1754
  });
1679
1755
  }
1680
- function Ut(r) {
1681
- k(r, "Plugin declaration", { fields: Ft });
1756
+ function Qt(r) {
1757
+ L(r, "Plugin declaration", { fields: Yt });
1682
1758
  }
1683
- function _t(r) {
1759
+ function Jt(r) {
1684
1760
  if (!r || typeof r != "object" && typeof r != "function") return !1;
1685
1761
  const t = r["~standard"];
1686
1762
  if (!t || typeof t != "object") return !1;
1687
1763
  const e = t;
1688
1764
  return e.version === 1 && typeof e.vendor == "string" && typeof e.validate == "function";
1689
1765
  }
1690
- function _(r, t, e) {
1691
- r !== void 0 && k(r, `Plugin '${t}' ${e}`);
1766
+ function K(r, t, e) {
1767
+ r !== void 0 && L(r, `Plugin '${t}' ${e}`);
1692
1768
  }
1693
- function H(r, t, e, i, s) {
1769
+ function W(r, t, e, i, s) {
1694
1770
  const n = t.get(s.id);
1695
1771
  if (!n) {
1696
1772
  t.set(s.id, { alias: i, kind: s.kind, role: e });
@@ -1698,38 +1774,49 @@ function H(r, t, e, i, s) {
1698
1774
  }
1699
1775
  if (n.kind !== s.kind)
1700
1776
  throw new TypeError(
1701
- `Plugin '${r}' uses Contract '${s.id}' as both ${L(n.kind)} and ${L(s.kind)}`
1777
+ `Plugin '${r}' uses Contract '${s.id}' as both ${R(n.kind)} and ${R(s.kind)}`
1702
1778
  );
1703
- const o = L(s.kind);
1779
+ const o = R(s.kind);
1704
1780
  throw n.role !== e ? new TypeError(
1705
1781
  `Plugin '${r}' cannot both require and provide ${o} '${s.id}'`
1706
1782
  ) : new TypeError(
1707
1783
  `Plugin '${r}' ${e} aliases '${n.alias}' and '${i}' reference the same ${o} '${s.id}'`
1708
1784
  );
1709
1785
  }
1710
- function L(r) {
1786
+ function R(r) {
1711
1787
  return r === "extensionPoint" ? "ExtensionPoint" : r === "event" ? "Event" : "Service";
1712
1788
  }
1713
- function K(r) {
1714
- return it(r);
1789
+ function Y(r) {
1790
+ return nt(r);
1791
+ }
1792
+ const Xt = /* @__PURE__ */ new Set(["plugin", "config"]), I = /* @__PURE__ */ new WeakMap();
1793
+ function Zt(r, t) {
1794
+ I.get(r)?.discard(t);
1715
1795
  }
1716
- const Ht = /* @__PURE__ */ new Set(["plugin", "config"]), x = /* @__PURE__ */ new WeakMap();
1717
- function Kt(r, t) {
1718
- x.get(r)?.(t);
1796
+ function te(r, t, e, i) {
1797
+ const s = I.get(r);
1798
+ if (!s) throw new Error("ChangeSet draft control has been released");
1799
+ return s.install(t, e, i);
1719
1800
  }
1720
- class Wt {
1801
+ class ee {
1721
1802
  #t = /* @__PURE__ */ new Map();
1722
1803
  #e;
1723
1804
  constructor(t) {
1724
- this.#e = { phase: "open", port: t }, x.set(this, (e) => this.#i(e)), Object.freeze(this);
1805
+ this.#e = { phase: "open", port: t }, I.set(this, {
1806
+ discard: (e) => this.#s(e),
1807
+ install: (e, i, s) => this.#i(e, i, s)
1808
+ }), Object.freeze(this);
1725
1809
  }
1726
1810
  install(t, ...e) {
1727
- const i = this.#n(), s = K(t), n = i.create(s, e[0]);
1728
- return this.#s({ kind: "install", installation: n.record }), n.publicInstallation;
1811
+ return this.#i(t, e[0]);
1812
+ }
1813
+ #i(t, e, i) {
1814
+ const s = this.#a(), n = Y(t), o = (i ?? s.create)(n, e);
1815
+ return this.#n({ kind: "install", installation: o.record }), o.facade;
1729
1816
  }
1730
1817
  update(t, e) {
1731
- const i = this.#n();
1732
- k(e, "Installation update", { fields: Ht });
1818
+ const i = this.#a();
1819
+ L(e, "Installation update", { fields: Xt });
1733
1820
  const s = Object.hasOwn(e, "plugin"), n = Object.hasOwn(e, "config");
1734
1821
  if (!s && !n)
1735
1822
  throw new TypeError("Installation update must include 'plugin' or 'config'");
@@ -1738,16 +1825,16 @@ class Wt {
1738
1825
  if (s) {
1739
1826
  const d = e.plugin;
1740
1827
  if (!d) throw new TypeError("Installation update 'plugin' must be a Plugin");
1741
- a = K(d);
1828
+ a = Y(d);
1742
1829
  }
1743
1830
  let h;
1744
1831
  a && n ? h = { kind: "plugin-and-config", plugin: a, config: e.config } : a ? h = { kind: "plugin", plugin: a } : h = { kind: "config", config: e.config };
1745
1832
  const c = { kind: "update", installation: o, declaration: h };
1746
- this.#s(c);
1833
+ this.#n(c);
1747
1834
  }
1748
1835
  remove(t) {
1749
- const e = this.#n();
1750
- this.#s({ kind: "remove", installation: e.resolve(t) });
1836
+ const e = this.#a();
1837
+ this.#n({ kind: "remove", installation: e.resolve(t) });
1751
1838
  }
1752
1839
  commit() {
1753
1840
  const t = this.#e;
@@ -1764,7 +1851,7 @@ class Wt {
1764
1851
  } catch (n) {
1765
1852
  for (const o of e)
1766
1853
  o.kind === "install" && i.discard(o.installation, n);
1767
- return this.#o(Promise.reject(n));
1854
+ return this.#r(Promise.reject(n));
1768
1855
  }
1769
1856
  let s;
1770
1857
  try {
@@ -1772,38 +1859,38 @@ class Wt {
1772
1859
  } catch (n) {
1773
1860
  s = Promise.reject(n);
1774
1861
  }
1775
- return this.#o(s);
1862
+ return this.#r(s);
1776
1863
  }
1777
- #i(t) {
1864
+ #s(t) {
1778
1865
  const e = this.#e;
1779
1866
  if (e.phase !== "open") return;
1780
1867
  this.#e = { phase: "discarded" };
1781
1868
  const i = [...this.#t.values()];
1782
- this.#r();
1869
+ this.#o();
1783
1870
  for (const s of i)
1784
1871
  s.kind === "install" && e.port.discard(s.installation, t);
1785
1872
  }
1786
- #s(t) {
1873
+ #n(t) {
1787
1874
  if (this.#t.has(t.installation))
1788
1875
  throw new TypeError(
1789
1876
  `Installation '${t.installation.id}' can only appear once in the same ChangeSet`
1790
1877
  );
1791
1878
  this.#t.set(t.installation, Object.freeze(t));
1792
1879
  }
1793
- #n() {
1880
+ #a() {
1794
1881
  const t = this.#e;
1795
1882
  if (t.phase !== "open")
1796
1883
  throw new TypeError(`Cannot modify a ${t.phase} ChangeSet`);
1797
1884
  return t.port;
1798
1885
  }
1799
- #o(t) {
1800
- return this.#e = { phase: "submitted", promise: t }, this.#r(), t;
1886
+ #r(t) {
1887
+ return this.#e = { phase: "submitted", promise: t }, this.#o(), t;
1801
1888
  }
1802
- #r() {
1803
- this.#t.clear(), x.delete(this);
1889
+ #o() {
1890
+ this.#t.clear(), I.delete(this);
1804
1891
  }
1805
1892
  }
1806
- class Yt {
1893
+ class ie {
1807
1894
  #t;
1808
1895
  constructor(t, e, i) {
1809
1896
  this.#t = { phase: "open", draft: t, discard: e, normalize: i };
@@ -1814,7 +1901,7 @@ class Yt {
1814
1901
  requireDraft() {
1815
1902
  const t = this.#t;
1816
1903
  if (t.phase === "failed") throw t.error;
1817
- if (t.phase === "sealed") throw z();
1904
+ if (t.phase === "sealed") throw N();
1818
1905
  return t.draft;
1819
1906
  }
1820
1907
  assertOpen() {
@@ -1823,7 +1910,7 @@ class Yt {
1823
1910
  fail(t) {
1824
1911
  const e = this.#t;
1825
1912
  if (e.phase === "failed") return e.error;
1826
- if (e.phase === "sealed") throw z();
1913
+ if (e.phase === "sealed") throw N();
1827
1914
  const i = e.normalize(t);
1828
1915
  return this.#t = {
1829
1916
  phase: "failed",
@@ -1835,7 +1922,7 @@ class Yt {
1835
1922
  seal() {
1836
1923
  const t = this.#t;
1837
1924
  if (t.phase === "failed") throw t.error;
1838
- if (t.phase === "sealed") throw z();
1925
+ if (t.phase === "sealed") throw N();
1839
1926
  return this.#t = { phase: "sealed" }, t.draft;
1840
1927
  }
1841
1928
  discard(t) {
@@ -1845,10 +1932,10 @@ class Yt {
1845
1932
  this.#t = { phase: "sealed" }, e.discard(e.draft, i);
1846
1933
  }
1847
1934
  }
1848
- function z() {
1935
+ function N() {
1849
1936
  return new Error("Group configuration has been sealed");
1850
1937
  }
1851
- class I {
1938
+ class A {
1852
1939
  constructor(t, e, i) {
1853
1940
  this.id = t, this.name = e, this.#e = { phase: "attached", parent: i };
1854
1941
  }
@@ -1857,7 +1944,7 @@ class I {
1857
1944
  #t = /* @__PURE__ */ new Map();
1858
1945
  #e;
1859
1946
  static root(t) {
1860
- return new I("/", t, void 0);
1947
+ return new A("/", t, void 0);
1861
1948
  }
1862
1949
  get attached() {
1863
1950
  return this.#e.phase !== "detached";
@@ -1870,9 +1957,9 @@ class I {
1870
1957
  return t.phase === "detached" ? void 0 : t.parent;
1871
1958
  }
1872
1959
  create(t) {
1873
- if (this.assertAttached(), Qt(t), this.#t.has(t))
1960
+ if (this.assertAttached(), se(t), this.#t.has(t))
1874
1961
  throw new TypeError(`Group '${this.#i(t)}' already exists`);
1875
- const e = new I(this.#i(t), t, this);
1962
+ const e = new A(this.#i(t), t, this);
1876
1963
  return this.#t.set(t, e), e;
1877
1964
  }
1878
1965
  contains(t) {
@@ -1904,14 +1991,14 @@ class I {
1904
1991
  return this.id === "/" ? `/${t}` : `${this.id}/${t}`;
1905
1992
  }
1906
1993
  }
1907
- function Qt(r) {
1994
+ function se(r) {
1908
1995
  if (typeof r != "string" || !r.trim())
1909
1996
  throw new TypeError("Group name must be a non-empty string");
1910
1997
  if (r !== r.trim())
1911
1998
  throw new TypeError("Group name cannot start or end with whitespace");
1912
1999
  if (r.includes("/")) throw new TypeError("Group name cannot contain '/'");
1913
2000
  }
1914
- class W {
2001
+ class Q {
1915
2002
  constructor(t, e, i) {
1916
2003
  this.node = t, this.#t = { phase: e }, this.#e = i;
1917
2004
  }
@@ -1962,11 +2049,11 @@ class W {
1962
2049
  return e.phase === "pending" && e.attempt === t;
1963
2050
  }
1964
2051
  }
1965
- function A(r) {
2052
+ function T(r) {
1966
2053
  return new u("GROUP_REMOVED", `Group '${r.id}' has been removed`);
1967
2054
  }
1968
2055
  const C = /* @__PURE__ */ new WeakMap();
1969
- class Jt {
2056
+ class re {
1970
2057
  #t;
1971
2058
  #e;
1972
2059
  constructor(t, e, i) {
@@ -1992,11 +2079,16 @@ class Jt {
1992
2079
  }
1993
2080
  ready() {
1994
2081
  const t = this.#e;
1995
- return t.phase === "revoked" ? Promise.reject(A(this.#t)) : t.coordinator.ready(this.#t);
2082
+ return t.phase === "revoked" ? Promise.reject(T(this.#t)) : t.coordinator.ready(this.#t);
1996
2083
  }
1997
2084
  install(t, ...e) {
1998
2085
  const i = this.#e;
1999
- return i.phase === "configuring" ? i.configuration.requireDraft().install(t, ...e) : this.#i().install(this.#t, t, ...e);
2086
+ return i.phase === "configuring" ? i.coordinator.stageConfigurationInstall(
2087
+ this.#t,
2088
+ i.configuration,
2089
+ t,
2090
+ ...e
2091
+ ) : this.#i().install(this.#t, t, ...e);
2000
2092
  }
2001
2093
  change() {
2002
2094
  if (this.#e.phase === "configuring")
@@ -2020,19 +2112,19 @@ class Jt {
2020
2112
  }
2021
2113
  #i() {
2022
2114
  const t = this.#e;
2023
- if (t.phase === "revoked") throw A(this.#t);
2115
+ if (t.phase === "revoked") throw T(this.#t);
2024
2116
  return t.coordinator;
2025
2117
  }
2026
2118
  }
2027
- class Xt {
2119
+ class ne {
2028
2120
  root;
2029
2121
  #t;
2030
2122
  #e = /* @__PURE__ */ new WeakMap();
2031
2123
  #i = /* @__PURE__ */ new WeakMap();
2032
2124
  constructor(t, e) {
2033
- this.root = I.root(t), this.#t = e, this.#i.set(
2125
+ this.root = A.root(t), this.#t = e, this.#i.set(
2034
2126
  this.root,
2035
- new W(this.root, "established", () => e.notifyChanged())
2127
+ new Q(this.root, "established", () => e.notifyChanged())
2036
2128
  );
2037
2129
  }
2038
2130
  nodes() {
@@ -2040,10 +2132,18 @@ class Xt {
2040
2132
  }
2041
2133
  install(t, e, ...i) {
2042
2134
  const s = this.change(t), n = s.install(e, ...i);
2043
- return Y(s.commit()), n;
2135
+ return J(s.commit()), n;
2136
+ }
2137
+ stageConfigurationInstall(t, e, i, ...s) {
2138
+ return this.#r(t), te(
2139
+ e.requireDraft(),
2140
+ i,
2141
+ s[0],
2142
+ (n, o) => (this.#r(t), this.#t.createDraft(t, n, o))
2143
+ );
2044
2144
  }
2045
2145
  change(t, e = "immediate") {
2046
- return this.#r(t), new Wt({
2146
+ return this.#r(t), new ee({
2047
2147
  create: (i, s) => (this.#r(t), this.#t.createDraft(t, i, s)),
2048
2148
  resolve: (i) => {
2049
2149
  this.#r(t);
@@ -2057,7 +2157,7 @@ class Xt {
2057
2157
  this.#r(t);
2058
2158
  const s = this.#t.executeChanges(t, i);
2059
2159
  for (const n of i) n.installation.trackReadiness(s);
2060
- return i.length && e === "immediate" && this.#o(t, s), s;
2160
+ return i.length && e === "immediate" && this.#a(t, s), s;
2061
2161
  },
2062
2162
  attach: (i) => {
2063
2163
  this.#r(t), this.#t.attachInstallation(i);
@@ -2068,33 +2168,33 @@ class Xt {
2068
2168
  create(t, e, i, s) {
2069
2169
  if (typeof i != "function") throw new TypeError("Group configure must be a function");
2070
2170
  const n = t.create(e);
2071
- this.#i.set(n, new W(n, "new", () => this.#t.notifyChanged()));
2072
- const o = s === void 0, a = s ?? new Yt(
2171
+ this.#i.set(n, new Q(n, "new", () => this.#t.notifyChanged()));
2172
+ const o = s === void 0, a = s ?? new ie(
2073
2173
  this.change(n, "deferred"),
2074
- Kt,
2174
+ Zt,
2075
2175
  (c) => $(
2076
2176
  c,
2077
2177
  "GROUP_UNAVAILABLE",
2078
2178
  `Group '${n.id}' configuration failed with a non-Error value`
2079
2179
  )
2080
- ), h = new Jt(this, n, a);
2180
+ ), h = new re(this, n, a);
2081
2181
  this.#e.set(n, h);
2082
2182
  try {
2083
2183
  const c = i(h);
2084
- te(c) && Zt(c);
2184
+ P(c, "Group configure must be synchronous");
2085
2185
  const d = a.failure;
2086
2186
  if (d) throw d;
2087
2187
  } catch (c) {
2088
2188
  const d = a.fail(c), l = n.walk();
2089
- throw n.detach(), this.#a(l), o && a.discard(d), this.#t.notifyChanged(), d;
2189
+ throw n.detach(), this.#o(l), o && a.discard(d), this.#t.notifyChanged(), d;
2090
2190
  }
2091
2191
  if (o) {
2092
2192
  const c = a.seal().commit();
2093
2193
  for (const d of n.walk()) {
2094
2194
  const l = this.#e.get(d);
2095
- l && C.get(l)?.finishConfiguration(), this.#o(d, c);
2195
+ l && C.get(l)?.finishConfiguration(), this.#a(d, c);
2096
2196
  }
2097
- Y(c);
2197
+ J(c);
2098
2198
  }
2099
2199
  return this.#t.notifyChanged(), h;
2100
2200
  }
@@ -2110,15 +2210,15 @@ class Xt {
2110
2210
  if (t === this.root) throw new TypeError("The root Group cannot be removed");
2111
2211
  return t.attached ? this.#t.runExclusive(async () => {
2112
2212
  if (!t.attached) {
2113
- this.#a([t]);
2213
+ this.#o([t]);
2114
2214
  return;
2115
2215
  }
2116
2216
  const e = t.walk(), i = this.#s(t).map((s) => ({
2117
2217
  kind: "remove",
2118
2218
  installation: s
2119
2219
  }));
2120
- await this.#t.removeInstallations(i), t.detach(), this.#a(e), this.#t.notifyChanged();
2121
- }) : (this.#a([t]), Promise.resolve());
2220
+ await this.#t.removeInstallations(i), t.detach(), this.#o(e), this.#t.notifyChanged();
2221
+ }) : (this.#o([t]), Promise.resolve());
2122
2222
  }
2123
2223
  #s(t) {
2124
2224
  return [...this.#t.installations()].filter(
@@ -2129,15 +2229,15 @@ class Xt {
2129
2229
  const e = this.#s(t);
2130
2230
  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";
2131
2231
  }
2132
- #o(t, e) {
2232
+ #a(t, e) {
2133
2233
  this.#r(t).track(e);
2134
2234
  }
2135
2235
  #r(t) {
2136
2236
  const e = this.#i.get(t);
2137
- if (!t.attached || !e) throw A(t);
2237
+ if (!t.attached || !e) throw T(t);
2138
2238
  return e;
2139
2239
  }
2140
- #a(t) {
2240
+ #o(t) {
2141
2241
  for (const e of t) {
2142
2242
  this.#i.get(e)?.release(), this.#i.delete(e);
2143
2243
  const i = this.#e.get(e);
@@ -2145,21 +2245,14 @@ class Xt {
2145
2245
  }
2146
2246
  }
2147
2247
  }
2148
- function Y(r) {
2248
+ function J(r) {
2149
2249
  Promise.resolve(r).catch(() => {
2150
2250
  });
2151
2251
  }
2152
- function Zt(r) {
2153
- throw Promise.resolve(r).catch(() => {
2154
- }), new TypeError("Group configure must be synchronous");
2155
- }
2156
- function te(r) {
2157
- return r === null || typeof r != "object" && typeof r != "function" ? !1 : typeof r.then == "function";
2158
- }
2159
- function Q(r, t) {
2252
+ function X(r, t) {
2160
2253
  return Object.freeze({ plugin: r, config: t });
2161
2254
  }
2162
- class ee {
2255
+ class oe {
2163
2256
  constructor(t, e, i, s) {
2164
2257
  this.id = t, this.index = e, this.groupId = i.id, this.#i = { declaration: s, group: i, notifyChanged: void 0 };
2165
2258
  }
@@ -2189,7 +2282,7 @@ class ee {
2189
2282
  get error() {
2190
2283
  const t = this.#t;
2191
2284
  if (t.phase === "failed")
2192
- return t.failure.retention === "live" ? t.failure.error : se(t.failure.summary);
2285
+ return t.failure.retention === "live" ? t.failure.error : t.failure.summary.restore();
2193
2286
  if (t.phase === "removed")
2194
2287
  return new u("INSTALLATION_REMOVED", `Installation '${this.id}' has been removed`);
2195
2288
  }
@@ -2262,20 +2355,20 @@ class ee {
2262
2355
  this.#r({ phase: "pending" });
2263
2356
  }
2264
2357
  fail(t) {
2265
- return this.#o(t);
2358
+ return this.#a(t);
2266
2359
  }
2267
2360
  discard(t) {
2268
- const e = this.#a(t);
2361
+ const e = this.#o(t);
2269
2362
  this.#r({
2270
2363
  phase: "failed",
2271
- failure: { retention: "summary", summary: ie(e) },
2364
+ failure: { retention: "summary", summary: new dt(e) },
2272
2365
  readiness: "settled"
2273
2366
  });
2274
2367
  for (const i of this.#s) i.reject(e);
2275
2368
  this.#s.clear(), this.#e = void 0, this.#i = void 0;
2276
2369
  }
2277
- #o(t) {
2278
- const e = this.#a(t);
2370
+ #a(t) {
2371
+ const e = this.#o(t);
2279
2372
  return this.#r({
2280
2373
  phase: "failed",
2281
2374
  failure: { retention: "live", error: e },
@@ -2288,7 +2381,7 @@ class ee {
2288
2381
  #r(t) {
2289
2382
  this.#t = t, this.#i?.notifyChanged?.();
2290
2383
  }
2291
- #a(t) {
2384
+ #o(t) {
2292
2385
  return $(
2293
2386
  t,
2294
2387
  "INSTALLATION_UNAVAILABLE",
@@ -2301,23 +2394,12 @@ class ee {
2301
2394
  return t;
2302
2395
  }
2303
2396
  }
2304
- function ie(r) {
2305
- return r instanceof u ? { category: "dougong", name: r.name, message: r.message, code: r.code } : {
2306
- category: r instanceof TypeError ? "typeError" : "error",
2307
- name: r.name,
2308
- message: r.message
2309
- };
2310
- }
2311
- function se(r) {
2312
- const t = r.category === "dougong" ? new u(r.code, r.message) : r.category === "typeError" ? new TypeError(r.message) : new Error(r.message);
2313
- return t.name = r.name, t;
2314
- }
2315
- const O = /* @__PURE__ */ new WeakMap();
2316
- class re {
2397
+ const S = /* @__PURE__ */ new WeakMap();
2398
+ class ae {
2317
2399
  #t;
2318
2400
  #e = { phase: "draft" };
2319
2401
  constructor(t) {
2320
- this.#t = t, O.set(this, {
2402
+ this.#t = t, S.set(this, {
2321
2403
  attach: (e, i) => {
2322
2404
  if (this.#e.phase !== "draft")
2323
2405
  throw new Error(`Installation '${this.#t.id}' control is already sealed`);
@@ -2362,7 +2444,7 @@ class re {
2362
2444
  );
2363
2445
  }
2364
2446
  }
2365
- class ne {
2447
+ class ce {
2366
2448
  #t = /* @__PURE__ */ new Map();
2367
2449
  #e = /* @__PURE__ */ new WeakMap();
2368
2450
  #i = /* @__PURE__ */ new WeakMap();
@@ -2382,13 +2464,13 @@ class ne {
2382
2464
  }
2383
2465
  create(t, e, i) {
2384
2466
  t.assertAttached();
2385
- const s = ++this.#n, n = new ee(
2467
+ const s = ++this.#n, n = new oe(
2386
2468
  `${e.name}:${s}`,
2387
2469
  s,
2388
2470
  t,
2389
- Q(e, i)
2390
- ), o = new re(n);
2391
- return this.#e.set(o, n), this.#i.set(n, o), { record: n, publicInstallation: o };
2471
+ X(e, i)
2472
+ ), o = new ae(n);
2473
+ return this.#e.set(o, n), this.#i.set(n, o), { record: n, facade: o };
2392
2474
  }
2393
2475
  resolve(t) {
2394
2476
  const e = this.#e.get(t);
@@ -2398,7 +2480,7 @@ class ne {
2398
2480
  attach(t) {
2399
2481
  const e = this.#i.get(t);
2400
2482
  if (!e) throw new Error(`Installation '${t.id}' has no public facade`);
2401
- const i = O.get(e);
2483
+ const i = S.get(e);
2402
2484
  if (!i) throw new Error(`Installation '${t.id}' has no draft control`);
2403
2485
  t.attach(this.#s.notifyChanged), i.attach(
2404
2486
  (s) => this.#s.update(t, e, s),
@@ -2425,37 +2507,36 @@ class ne {
2425
2507
  this.#t.set(e.installation.id, e.installation);
2426
2508
  else if (e.kind === "update") {
2427
2509
  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;
2428
- e.installation.replaceDeclaration(Q(s, n));
2510
+ e.installation.replaceDeclaration(X(s, n));
2429
2511
  } else this.contains(e.installation) && this.#t.delete(e.installation.id);
2430
2512
  }
2431
2513
  settleChanges(t, e) {
2432
2514
  for (const i of t)
2433
- i.kind === "remove" ? (i.installation.remove(), i.installation.settleReady(), this.#o(i.installation)) : e || i.installation.deactivate();
2515
+ i.kind === "remove" ? (i.installation.remove(), i.installation.settleReady(), this.#a(i.installation)) : e || i.installation.deactivate();
2434
2516
  }
2435
2517
  settleReadiness(t) {
2436
2518
  for (const e of t) e.settleReady();
2437
2519
  }
2438
2520
  discard(t, e) {
2439
- t.discard(e), this.#o(t);
2521
+ t.discard(e), this.#a(t);
2440
2522
  }
2441
2523
  capture() {
2442
- return [...this.#t].map(([t, e]) => ({
2443
- id: t,
2444
- installation: e,
2445
- declaration: e.declaration
2524
+ return [...this.#t.values()].map((t) => ({
2525
+ installation: t,
2526
+ declaration: t.declaration
2446
2527
  }));
2447
2528
  }
2448
2529
  restore(t) {
2449
2530
  this.#t.clear();
2450
2531
  for (const e of t)
2451
- e.installation.replaceDeclaration(e.declaration), this.#t.set(e.id, e.installation);
2532
+ e.installation.replaceDeclaration(e.declaration), this.#t.set(e.installation.id, e.installation);
2452
2533
  }
2453
- #o(t) {
2534
+ #a(t) {
2454
2535
  const e = this.#i.get(t);
2455
- e && (O.get(e)?.revoke(), O.delete(e)), this.#i.delete(t);
2536
+ e && (S.get(e)?.revoke(), S.delete(e)), this.#i.delete(t);
2456
2537
  }
2457
2538
  }
2458
- class oe {
2539
+ class he {
2459
2540
  #t = Promise.resolve();
2460
2541
  get settled() {
2461
2542
  return this.#t;
@@ -2472,8 +2553,8 @@ class oe {
2472
2553
  ), e;
2473
2554
  }
2474
2555
  }
2475
- const ae = console, ce = /* @__PURE__ */ new Set(["name", "logger", "onError"]);
2476
- class he {
2556
+ const de = console, le = /* @__PURE__ */ new Set(["name", "logger", "onError"]);
2557
+ class ue {
2477
2558
  name;
2478
2559
  diagnostics;
2479
2560
  #t;
@@ -2481,11 +2562,11 @@ class he {
2481
2562
  #i;
2482
2563
  #s;
2483
2564
  #n;
2484
- #o;
2565
+ #a;
2485
2566
  #r = "idle";
2486
- #a = new oe();
2567
+ #o = new he();
2487
2568
  constructor(t = {}) {
2488
- k(t, "Host options", { fields: ce });
2569
+ L(t, "Host options", { fields: le });
2489
2570
  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";
2490
2571
  if (typeof n != "string" || !n.trim())
2491
2572
  throw new TypeError("Host name must be a non-empty string");
@@ -2493,9 +2574,9 @@ class he {
2493
2574
  throw new TypeError("Host name cannot start or end with whitespace");
2494
2575
  if (s !== void 0 && typeof s != "function")
2495
2576
  throw new TypeError("Host onError must be a function");
2496
- if (i !== void 0 && !zt(i))
2577
+ if (i !== void 0 && !Mt(i))
2497
2578
  throw new TypeError("Host logger must implement debug/info/warn/error");
2498
- this.name = n, this.#i = i ?? ae, this.#n = s ?? ((o) => this.#i.error(o)), this.#t = new ne({
2579
+ this.name = n, this.#i = i ?? de, this.#n = s ?? ((o) => this.#i.error(o)), this.#t = new ce({
2499
2580
  notifyChanged: () => this.#p(),
2500
2581
  update: (o, a, h) => {
2501
2582
  const c = this.#s.change(o.group);
@@ -2505,22 +2586,22 @@ class he {
2505
2586
  const h = this.#s.change(o.group);
2506
2587
  return h.remove(a), h.commit();
2507
2588
  }
2508
- }), this.#o = new Dt({
2589
+ }), this.#a = new Ht({
2509
2590
  hostName: n,
2510
2591
  logger: this.#i,
2511
2592
  isInstalled: (o) => this.#t.has(o),
2512
2593
  report: (o) => this.#h(o)
2513
- }), this.#s = new Xt(n, {
2594
+ }), this.#s = new ne(n, {
2514
2595
  installations: () => this.#t.values(),
2515
2596
  createDraft: (o, a, h) => this.#t.create(o, a, h),
2516
2597
  resolveInstallation: (o) => this.#t.resolve(o),
2517
2598
  executeChanges: (o, a) => this.#d(o, a),
2518
2599
  attachInstallation: (o) => this.#t.attach(o),
2519
2600
  discardInstallation: (o, a) => this.#t.discard(o, a),
2520
- runExclusive: (o) => this.#a.run(o),
2601
+ runExclusive: (o) => this.#o.run(o),
2521
2602
  removeInstallations: (o) => this.#f(o),
2522
2603
  notifyChanged: () => this.#p()
2523
- }), this.#e = new Gt(
2604
+ }), this.#e = new Kt(
2524
2605
  n,
2525
2606
  this.#s.nodes(),
2526
2607
  (o) => this.#h(o)
@@ -2531,10 +2612,10 @@ class he {
2531
2612
  }
2532
2613
  get(t) {
2533
2614
  const e = this.#r === "active" ? "available" : "unavailable";
2534
- return this.#o.get(t, e);
2615
+ return this.#a.get(t, e);
2535
2616
  }
2536
2617
  contributions(t) {
2537
- return this.#o.contributions(t);
2618
+ return this.#a.contributions(t);
2538
2619
  }
2539
2620
  install(t, ...e) {
2540
2621
  return this.#s.install(this.#s.root, t, ...e);
@@ -2546,12 +2627,12 @@ class he {
2546
2627
  return this.#s.create(this.#s.root, t, e);
2547
2628
  }
2548
2629
  start() {
2549
- return this.#a.run(async () => {
2630
+ return this.#o.run(async () => {
2550
2631
  if (this.#r !== "active") {
2551
2632
  this.#c("starting");
2552
2633
  try {
2553
- const t = this.#o.buildPlan(this.#t.values());
2554
- await this.#o.start(t), this.#c("active"), this.#t.settleReadiness(t.order);
2634
+ const t = this.#a.buildPlan(this.#t.values());
2635
+ await this.#a.start(t), this.#c("active"), this.#t.settleReadiness(t.order);
2555
2636
  } catch (t) {
2556
2637
  this.#c("idle");
2557
2638
  for (const e of this.#t.values())
@@ -2562,19 +2643,19 @@ class he {
2562
2643
  });
2563
2644
  }
2564
2645
  stop() {
2565
- return this.#a.run(async () => {
2646
+ return this.#o.run(async () => {
2566
2647
  if (this.#r === "idle") return;
2567
2648
  this.#c("stopping");
2568
- const t = await this.#o.stop();
2649
+ const t = await this.#a.stop();
2569
2650
  if (this.#c("idle"), t.length === 1) throw t[0];
2570
2651
  if (t.length > 1) throw new AggregateError(t, "Host shutdown failed");
2571
2652
  });
2572
2653
  }
2573
2654
  #d(t, e) {
2574
2655
  const i = e.filter((s) => s.kind === "install").map((s) => s.installation);
2575
- return this.#a.run(async () => {
2656
+ return this.#o.run(async () => {
2576
2657
  try {
2577
- if (!t.attached) throw A(t);
2658
+ if (!t.attached) throw T(t);
2578
2659
  if (!e.length) return;
2579
2660
  this.#r === "active" ? await this.#l(e) : (this.#t.apply(e), this.#t.settleChanges(e, !1)), this.#p();
2580
2661
  } catch (s) {
@@ -2597,31 +2678,30 @@ class he {
2597
2678
  this.#c("changing");
2598
2679
  let s;
2599
2680
  try {
2600
- this.#t.apply(t), s = this.#o.buildPlan(this.#t.values());
2681
+ this.#t.apply(t), s = this.#a.buildPlan(this.#t.values());
2601
2682
  } catch (n) {
2602
2683
  throw this.#t.restore(e), this.#c("active"), n;
2603
2684
  }
2604
2685
  try {
2605
- const n = await this.#o.transition(
2686
+ const n = await this.#a.transition(
2606
2687
  s,
2607
2688
  i,
2608
2689
  () => this.#t.restore(e)
2609
2690
  );
2610
2691
  return this.#c("active"), n;
2611
2692
  } catch (n) {
2612
- throw this.#c(this.#o.hasCommittedPlan ? "active" : "idle"), n;
2693
+ throw this.#c(this.#a.hasCommittedPlan ? "active" : "idle"), n;
2613
2694
  }
2614
2695
  }
2615
2696
  #h(t) {
2697
+ const e = this.#i;
2616
2698
  try {
2617
- this.#n(t);
2618
- } catch (e) {
2619
- try {
2620
- this.#i.error(
2621
- new AggregateError([t, e], "Host error reporter failed")
2622
- );
2623
- } catch {
2624
- }
2699
+ const i = this.#n(t);
2700
+ Promise.resolve(i).catch((s) => {
2701
+ Z(e, t, s);
2702
+ });
2703
+ } catch (i) {
2704
+ Z(e, t, i);
2625
2705
  }
2626
2706
  }
2627
2707
  #c(t) {
@@ -2631,24 +2711,35 @@ class he {
2631
2711
  this.#e.publish(this.#r, this.#t.values(), this.#s.nodes());
2632
2712
  }
2633
2713
  }
2634
- function ge(r) {
2635
- return new he(r);
2714
+ function be(r) {
2715
+ return new ue(r);
2716
+ }
2717
+ function Z(r, t, e) {
2718
+ try {
2719
+ const i = r.error(
2720
+ new AggregateError([t, e], "Host error reporter failed")
2721
+ );
2722
+ Promise.resolve(i).catch(() => {
2723
+ });
2724
+ } catch {
2725
+ }
2636
2726
  }
2637
2727
  export {
2638
- at as ConfigValidationError,
2728
+ ut as ConfigValidationError,
2639
2729
  u as DougongError,
2640
- S as ReadonlyMapSnapshot,
2641
- oe as SerialQueue,
2730
+ dt as ErrorSummary,
2731
+ O as ReadonlyMapSnapshot,
2732
+ he as SerialQueue,
2642
2733
  q as SnapshotPublisher,
2643
- k as assertPlainRecord,
2644
- j as asyncDisposeSymbol,
2645
- ge as createHost,
2646
- pe as definePlugin,
2734
+ L as assertPlainRecord,
2735
+ k as asyncDisposeSymbol,
2736
+ be as createHost,
2737
+ ve as definePlugin,
2647
2738
  g as disposeSymbol,
2648
- le as event,
2649
- ue as extensionPoint,
2650
- J as isCancellationReason,
2651
- zt as isLogger,
2652
- fe as optional,
2653
- de as service
2739
+ pe as event,
2740
+ ge as extensionPoint,
2741
+ tt as isCancellationReason,
2742
+ Mt as isLogger,
2743
+ we as optional,
2744
+ fe as service
2654
2745
  };