dougong 0.8.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +22 -97
  2. package/dist/advanced.d.ts +9 -0
  3. package/dist/advanced.d.ts.map +1 -0
  4. package/dist/advanced.js +39 -0
  5. package/dist/composition/change-set.d.ts +56 -0
  6. package/dist/composition/change-set.d.ts.map +1 -0
  7. package/dist/composition/configuration.d.ts +8 -0
  8. package/dist/composition/configuration.d.ts.map +1 -0
  9. package/dist/composition/declarations.d.ts +60 -0
  10. package/dist/composition/declarations.d.ts.map +1 -0
  11. package/dist/composition/group.d.ts +10 -0
  12. package/dist/composition/group.d.ts.map +1 -0
  13. package/dist/composition/installation-graph.d.ts +17 -0
  14. package/dist/composition/installation-graph.d.ts.map +1 -0
  15. package/dist/composition/installation.d.ts +33 -0
  16. package/dist/composition/installation.d.ts.map +1 -0
  17. package/dist/composition/plan.d.ts +109 -0
  18. package/dist/composition/plan.d.ts.map +1 -0
  19. package/dist/composition/planner.d.ts +18 -0
  20. package/dist/composition/planner.d.ts.map +1 -0
  21. package/dist/composition/plugin-description.d.ts +34 -0
  22. package/dist/composition/plugin-description.d.ts.map +1 -0
  23. package/dist/composition/plugin.d.ts +65 -0
  24. package/dist/composition/plugin.d.ts.map +1 -0
  25. package/dist/contracts/contract-registry.d.ts +18 -0
  26. package/dist/contracts/contract-registry.d.ts.map +1 -0
  27. package/dist/contracts/contracts.d.ts +51 -0
  28. package/dist/contracts/contracts.d.ts.map +1 -0
  29. package/dist/contracts/errors.d.ts +93 -0
  30. package/dist/contracts/errors.d.ts.map +1 -0
  31. package/dist/contracts/logging.d.ts +20 -0
  32. package/dist/contracts/logging.d.ts.map +1 -0
  33. package/dist/contracts/resource.d.ts +16 -0
  34. package/dist/contracts/resource.d.ts.map +1 -0
  35. package/dist/contracts/status.d.ts +3 -0
  36. package/dist/contracts/status.d.ts.map +1 -0
  37. package/dist/contributions/contribution-store.d.ts +51 -0
  38. package/dist/contributions/contribution-store.d.ts.map +1 -0
  39. package/dist/events/event-hub.d.ts +27 -0
  40. package/dist/events/event-hub.d.ts.map +1 -0
  41. package/dist/execution/engine.d.ts +27 -0
  42. package/dist/execution/engine.d.ts.map +1 -0
  43. package/dist/execution/host-api.d.ts +49 -0
  44. package/dist/execution/host-api.d.ts.map +1 -0
  45. package/dist/execution/host.d.ts +4 -0
  46. package/dist/execution/host.d.ts.map +1 -0
  47. package/dist/execution/instance.d.ts +34 -0
  48. package/dist/execution/instance.d.ts.map +1 -0
  49. package/dist/index.d.ts +18 -3
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +2271 -8
  52. package/dist/inspection/diagnostics.d.ts +36 -0
  53. package/dist/inspection/diagnostics.d.ts.map +1 -0
  54. package/dist/internal/abort.d.ts +4 -0
  55. package/dist/internal/abort.d.ts.map +1 -0
  56. package/dist/internal/async-result.d.ts +10 -0
  57. package/dist/internal/async-result.d.ts.map +1 -0
  58. package/dist/internal/data-array.d.ts +3 -0
  59. package/dist/internal/data-array.d.ts.map +1 -0
  60. package/dist/internal/disposal-runtime.d.ts +5 -0
  61. package/dist/internal/disposal-runtime.d.ts.map +1 -0
  62. package/dist/internal/record.d.ts +11 -0
  63. package/dist/internal/record.d.ts.map +1 -0
  64. package/dist/internal/serial-queue.d.ts +7 -0
  65. package/dist/internal/serial-queue.d.ts.map +1 -0
  66. package/dist/lifetime/lifetime-diagnostics.d.ts +21 -0
  67. package/dist/lifetime/lifetime-diagnostics.d.ts.map +1 -0
  68. package/dist/lifetime/lifetime.d.ts +78 -0
  69. package/dist/lifetime/lifetime.d.ts.map +1 -0
  70. package/dist/observation/readonly-map.d.ts +13 -0
  71. package/dist/observation/readonly-map.d.ts.map +1 -0
  72. package/dist/observation/snapshot-view.d.ts +17 -0
  73. package/dist/observation/snapshot-view.d.ts.map +1 -0
  74. package/dist/serial-queue-DjEs2KFf.js +559 -0
  75. package/package.json +17 -8
  76. package/runtime/abort-listener.d.mts +2 -0
  77. package/runtime/abort-listener.mjs +27 -0
@@ -0,0 +1,559 @@
1
+ import { listenForAbort as e } from "#abort-listener";
2
+ // src/internal/disposal-runtime.ts
3
+ function t(e) {
4
+ if (typeof e != "function") throw Error("Unsupported JavaScript runtime: Promise.withResolvers is required");
5
+ }
6
+ function n(e, t) {
7
+ return e ?? Symbol.for(t);
8
+ }
9
+ t(Promise.withResolvers);
10
+ var r = n(Symbol.dispose, "Symbol.dispose"), i = n(Symbol.asyncDispose, "Symbol.asyncDispose"), a = Promise.prototype, o = a.then;
11
+ async function s(e) {
12
+ return l(e) ?? Object.freeze({ value: e });
13
+ }
14
+ function c(e, t) {
15
+ let n = l(e);
16
+ if (n) throw n.then(() => void 0, () => void 0), TypeError(t);
17
+ }
18
+ function l(e) {
19
+ if (e === null || typeof e != "object" && typeof e != "function") return;
20
+ if (u(e)) {
21
+ let t = Promise.withResolvers();
22
+ return Reflect.apply(o, e, [(e) => t.resolve(Object.freeze({ value: e })), t.reject]), t.promise;
23
+ }
24
+ let t = e.then;
25
+ if (typeof t != "function") return;
26
+ let n = Promise.withResolvers();
27
+ return queueMicrotask(() => {
28
+ try {
29
+ Reflect.apply(t, e, [n.resolve, n.reject]);
30
+ } catch (e) {
31
+ n.reject(e);
32
+ }
33
+ }), n.promise.then((e) => Object.freeze({ value: e }));
34
+ }
35
+ function u(e) {
36
+ let t = /* @__PURE__ */ new Set();
37
+ for (let n = Object.getPrototypeOf(e); n !== null; n = Object.getPrototypeOf(n)) {
38
+ if (n === a) return !0;
39
+ if (t.has(n)) throw TypeError("Result has a cyclic prototype chain");
40
+ t.add(n);
41
+ }
42
+ return !1;
43
+ }
44
+ // src/internal/abort.ts
45
+ function d(e) {
46
+ return Reflect.get(AbortSignal.prototype, "aborted", e);
47
+ }
48
+ function f(e) {
49
+ return Reflect.get(AbortSignal.prototype, "reason", e);
50
+ }
51
+ function p(t, n) {
52
+ if (typeof n != "function") throw TypeError("Abort listener must be a function");
53
+ if (d(t)) return n(f(t)), () => {};
54
+ let r = {
55
+ signal: t,
56
+ callback: n
57
+ }, i;
58
+ function a() {
59
+ r = void 0, i?.(), i = void 0;
60
+ }
61
+ function o() {
62
+ if (!r || !d(r.signal)) return;
63
+ let { signal: e, callback: t } = r, n = f(e);
64
+ a(), t(n);
65
+ }
66
+ return i = e(t, o), r ? o() : a(), a;
67
+ }
68
+ // src/internal/data-array.ts
69
+ function m(e, t) {
70
+ if (!Array.isArray(e)) throw TypeError(`${t} must be an array`);
71
+ let n = Reflect.ownKeys(e), r = n.length - 1;
72
+ if (r !== Reflect.getOwnPropertyDescriptor(e, "length")?.value) throw TypeError(`${t} must be a dense array`);
73
+ let i = [];
74
+ for (let a of n) {
75
+ if (a === "length") continue;
76
+ let n = typeof a == "string" ? Number(a) : NaN;
77
+ if (!Number.isInteger(n) || n < 0 || n >= r || String(n) !== a) throw TypeError(`${t} must contain only dense array indices`);
78
+ let o = Reflect.getOwnPropertyDescriptor(e, a);
79
+ if (!o || !("value" in o)) throw TypeError(`${t} must contain data properties`);
80
+ i[n] = o.value;
81
+ }
82
+ return Object.freeze(i);
83
+ }
84
+ // src/contracts/errors.ts
85
+ var h = "BUSY", g = "CHANGE_CONFLICT", _ = "CHANGE_FOREIGN", v = "CONFIGURATION_INVALID", y = "CONTRACT_CONFLICT", b = "CONTRIBUTION_UNAVAILABLE", x = "EVENT_BEFORE_COMMIT", S = "GROUP_CONFLICT", C = "GROUP_CYCLE", w = "GROUP_FOREIGN", T = "GROUP_MISSING", E = "GROUP_REMOVED", D = "HOST_BUSY", O = "HOST_QUARANTINED", ee = "INSTALLATION_CONFLICT", te = "INSTALLATION_FOREIGN", ne = "INSTALLATION_REMOVED", k = "LIFETIME_DISPOSED", re = "PLAN_CONSUMED", ie = "PLAN_FOREIGN", ae = "PLAN_STALE", oe = "PROVIDES_INVALID", se = "SERVICE_CONFLICT", ce = "SERVICE_CYCLE", le = "SERVICE_MISSING", ue = "SERVICE_UNAVAILABLE", de = "SHUTDOWN_TIMEOUT", fe = "TRANSITION_FAILED", A = 8, j = 256, M = 256, pe = 8, me = 4, he = 32, ge = 256, _e = 256, N = 4096, ve = 16384, ye = 8, be = 8, xe = 16, Se = 256, P = 256, Ce = 32, F = {
86
+ outcome: "outcome",
87
+ phase: "text",
88
+ installation: "text",
89
+ contract: "text",
90
+ dependencyPath: "path",
91
+ affectedInstallations: "path",
92
+ stateRevision: "revision",
93
+ expectedRevision: "revision"
94
+ }, we = [
95
+ "rejected",
96
+ "restored",
97
+ "quarantined"
98
+ ];
99
+ function I(e, t) {
100
+ let n = {};
101
+ for (let r of t ? Object.keys(F) : Reflect.ownKeys(e)) {
102
+ if (typeof r != "string" || !Object.hasOwn(F, r)) throw TypeError(`Unknown error detail '${String(r)}'`);
103
+ let i = t ? V(e, r) : Reflect.get(e, r);
104
+ if (i === void 0) continue;
105
+ let a;
106
+ switch (F[r]) {
107
+ case "outcome":
108
+ a = we.find((e) => e === i);
109
+ break;
110
+ case "text":
111
+ typeof i == "string" && (a = t ? t.clip(i, P) : i);
112
+ break;
113
+ case "revision":
114
+ typeof i == "number" && Number.isSafeInteger(i) && i >= 0 && (a = i);
115
+ break;
116
+ case "path": if (t) a = t.strings(i, Ce, P);
117
+ else {
118
+ let e = m(i, r);
119
+ e.every((e) => typeof e == "string") && (a = e);
120
+ }
121
+ }
122
+ if (a !== void 0) n[r] = a;
123
+ else if (!t) throw TypeError(`Invalid error detail '${r}'`);
124
+ }
125
+ return Object.freeze(n);
126
+ }
127
+ var L = class extends Error {
128
+ name = "DougongError";
129
+ code;
130
+ details;
131
+ constructor(e, t, n) {
132
+ if (typeof e != "string" || e.trim() !== e || e.length === 0) throw TypeError("DougongError code must be a non-empty trimmed string");
133
+ if (typeof t != "string") throw TypeError("DougongError message must be a string");
134
+ super(t, n), this.code = e;
135
+ let r = n?.details;
136
+ if (r !== void 0 && (!r || typeof r != "object" || Array.isArray(r))) throw TypeError("Error details must be an object");
137
+ this.details = I(r ?? {});
138
+ }
139
+ };
140
+ function Te(e) {
141
+ return new L(O, "Host execution is permanently quarantined", { details: {
142
+ outcome: "quarantined",
143
+ stateRevision: e
144
+ } });
145
+ }
146
+ var R = class e extends Error {
147
+ name = "RecordedFailure";
148
+ code;
149
+ #e;
150
+ get snapshot() {
151
+ return this.#e;
152
+ }
153
+ static #t(e) {
154
+ return typeof e == "object" && e && #e in e ? e.#e : void 0;
155
+ }
156
+ constructor(t, n = []) {
157
+ let r = m(n, "Diagnostic field names");
158
+ if (r.length > A || r.some((e) => typeof e != "string" || !e || e.length > j)) throw TypeError(`Select at most ${A} diagnostic field names of 1–${j} characters each`);
159
+ let i = e.#t(t) ?? Ee(t, e.#t, new Set(r));
160
+ super(i.message), this.code = i.code, this.#e = i, this.stack = i.stack ?? `${this.name}: ${i.message}`, Object.freeze(this);
161
+ }
162
+ };
163
+ function Ee(e, t, n) {
164
+ let r = /* @__PURE__ */ new Set(), i = he, a = (e, o, s = !1) => {
165
+ let c = s ? e : t(e), l = c ?? e;
166
+ if (o > me || i-- <= 0 || r.has(l)) return Object.freeze({
167
+ name: "TruncatedError",
168
+ message: "Error chain truncated",
169
+ truncated: !0
170
+ });
171
+ if (!c && !z(l)) {
172
+ let e = l === null || [
173
+ "string",
174
+ "number",
175
+ "boolean",
176
+ "undefined",
177
+ "bigint",
178
+ "symbol"
179
+ ].includes(typeof l) ? String(l) : "Non-Error object omitted";
180
+ return Object.freeze({
181
+ name: "NonError",
182
+ message: e.slice(0, N),
183
+ ...e.length > N ? { truncated: !0 } : {}
184
+ });
185
+ }
186
+ r.add(l);
187
+ let u = c?.truncated ?? !1, d = (e, t) => (e.length > t && (u = !0), e.slice(0, t)), f = (e, t) => {
188
+ let n = V(l, e);
189
+ return typeof n == "string" ? d(n, t) : void 0;
190
+ }, p = (e, t) => {
191
+ if (!De(e)) return;
192
+ let n = V(e, "length");
193
+ if (!(typeof n != "number" || !Number.isSafeInteger(n) || n < 0)) return n > t && (u = !0), Array.from({ length: Math.min(n, t) }, (t, n) => V(e, n));
194
+ }, m = f("name", ge) ?? "Error", h = f("message", N) ?? "", g = f("stack", ve), _ = f("code", _e), v = V(l, "cause"), y = p(V(l, "errors"), ye), b = (e, t, n) => {
195
+ let r = p(e, t);
196
+ return r && Object.freeze(r.filter((e) => typeof e == "string").map((e) => d(e, n)));
197
+ }, x = c?.fields;
198
+ if (!c && n.size) {
199
+ let e = [];
200
+ for (let t of n) {
201
+ let n = B(l, t)?.value, r = typeof n == "string" ? d(n, M) : b(n, pe, M);
202
+ r !== void 0 && e.push([t, r]);
203
+ }
204
+ e.length && (x = Object.freeze(Object.fromEntries(e)));
205
+ }
206
+ let S = p(V(l, "issues"), be)?.map((e) => {
207
+ let t = V(e, "message"), n = p(V(e, "path"), xe)?.map((e) => {
208
+ let t = e && typeof e == "object" ? V(e, "key") : e;
209
+ return typeof t == "number" ? t : typeof t == "string" || typeof t == "symbol" ? d(String(t), Se) : "[omitted]";
210
+ });
211
+ return Object.freeze({
212
+ message: typeof t == "string" ? d(t, N) : "",
213
+ ...n ? { path: Object.freeze(n) } : {}
214
+ });
215
+ }), C = V(l, "details"), w = typeof C == "object" && C ? I(C, {
216
+ clip: d,
217
+ strings: b
218
+ }) : void 0, T = (e) => a(e, o + 1, !!c), E = B(l, "error"), D = E && B(l, "suppressed");
219
+ return Object.freeze({
220
+ name: m,
221
+ message: h,
222
+ ..._ === void 0 ? {} : { code: _ },
223
+ ...g === void 0 ? {} : { stack: g },
224
+ ...v === void 0 ? {} : { cause: T(v) },
225
+ ...y === void 0 ? {} : { errors: Object.freeze(y.map(T)) },
226
+ ...E && D ? {
227
+ error: T(E.value),
228
+ suppressed: T(D.value)
229
+ } : {},
230
+ ...x === void 0 ? {} : { fields: x },
231
+ ...S === void 0 ? {} : { issues: Object.freeze(S) },
232
+ ...w === void 0 ? {} : { details: w },
233
+ ...u ? { truncated: !0 } : {}
234
+ });
235
+ };
236
+ return a(e, 0);
237
+ }
238
+ function z(e) {
239
+ try {
240
+ return e instanceof Error ? !0 : typeof e != "object" || !e ? !1 : "isError" in Error && typeof Error.isError == "function" ? Error.isError(e) : !(Symbol.toStringTag in e) && Object.prototype.toString.call(e) === "[object Error]";
241
+ } catch {
242
+ return !1;
243
+ }
244
+ }
245
+ function De(e) {
246
+ try {
247
+ return Array.isArray(e);
248
+ } catch {
249
+ return !1;
250
+ }
251
+ }
252
+ function B(e, t) {
253
+ try {
254
+ let n = Object.getOwnPropertyDescriptor(e, t);
255
+ return n && "value" in n ? n : void 0;
256
+ } catch {
257
+ return;
258
+ }
259
+ }
260
+ function V(e, t) {
261
+ try {
262
+ return e && typeof e == "object" ? e[t] : void 0;
263
+ } catch {
264
+ return;
265
+ }
266
+ }
267
+ function Oe(e, t) {
268
+ try {
269
+ if (!d(e)) return !1;
270
+ } catch (e) {
271
+ throw TypeError("Cancellation classifier expects an AbortSignal", { cause: e });
272
+ }
273
+ let n = f(e);
274
+ return Object.is(t, n) ? !0 : z(t) && V(t, "name") === "AbortError" && Object.is(B(t, "cause")?.value, n);
275
+ }
276
+ var ke = class extends L {
277
+ name = "ConfigurationValidationError";
278
+ issues;
279
+ constructor(e, t) {
280
+ let n = Ae(e);
281
+ super(v, `Invalid Plugin configuration:\n${n.map((e) => ` - ${e.message}`).join("\n")}`, t), this.issues = n;
282
+ }
283
+ };
284
+ function Ae(e) {
285
+ return Object.freeze(H(e, "Configuration validation issues").map((e, t) => {
286
+ if (!e || typeof e != "object" && typeof e != "function") throw TypeError(`Configuration validation issue at index ${t} must be an object`);
287
+ let n = e, r = n.message;
288
+ if (typeof r != "string") throw TypeError(`Configuration validation issue at index ${t} message must be a string`);
289
+ let i = n.path;
290
+ return Object.freeze({
291
+ message: r,
292
+ ...i === void 0 ? {} : { path: je(i, t) }
293
+ });
294
+ }));
295
+ }
296
+ function je(e, t) {
297
+ return Object.freeze(H(e, `Configuration validation issue at index ${t} path`).map((e, n) => {
298
+ if (U(e)) return e;
299
+ if (!e || typeof e != "object" && typeof e != "function") throw TypeError(`Configuration validation issue at index ${t} path segment ${n} must be a property key`);
300
+ let r = e.key;
301
+ if (!U(r)) throw TypeError(`Configuration validation issue at index ${t} path segment ${n} must contain a property key`);
302
+ return Object.freeze({ key: r });
303
+ }));
304
+ }
305
+ function H(e, t) {
306
+ if (!Array.isArray(e)) throw TypeError(`${t} must be an array`);
307
+ let n = e.length;
308
+ if (typeof n != "number" || !Number.isSafeInteger(n) || n < 0) throw TypeError(`${t} must have a valid array length`);
309
+ let r = [];
310
+ for (let i = 0; i < n; i++) {
311
+ if (!(i in e)) throw TypeError(`${t} must be a dense array`);
312
+ r.push(e[i]);
313
+ }
314
+ return Object.freeze(r);
315
+ }
316
+ function U(e) {
317
+ return typeof e == "string" || typeof e == "number" || typeof e == "symbol";
318
+ }
319
+ // src/internal/record.ts
320
+ function Me() {
321
+ return (...e) => new Set(e);
322
+ }
323
+ var Ne = Function.prototype.toString.call(Object);
324
+ function Pe(e) {
325
+ let t = Object.getPrototypeOf(e);
326
+ if (t === Object.prototype || t === null) return !0;
327
+ if (Object.getPrototypeOf(t) !== null) return !1;
328
+ let n = Object.getOwnPropertyDescriptor(t, "constructor")?.value;
329
+ return typeof n == "function" && Function.prototype.toString.call(n) === Ne && Object.getOwnPropertyDescriptor(n, "prototype")?.value === t;
330
+ }
331
+ function Fe(e, t, n = {}) {
332
+ if (!e || typeof e != "object" || Array.isArray(e) || !Pe(e)) throw W(n, `${t} must be a plain record`);
333
+ let r = Object.create(null);
334
+ for (let i of Reflect.ownKeys(e)) {
335
+ let a = Reflect.getOwnPropertyDescriptor(e, i);
336
+ if (typeof i != "string" || !a?.enumerable) throw W(n, `${t} keys must be enumerable strings`);
337
+ if (!("value" in a)) throw W(n, `${t} field '${i}' must be a data property`);
338
+ if (n.fields && !n.fields.has(i)) throw W(n, `${t}: unknown field '${i}'`);
339
+ r[i] = a.value;
340
+ }
341
+ return Object.freeze(r);
342
+ }
343
+ function W(e, t) {
344
+ return e.createError?.(t) ?? TypeError(t);
345
+ }
346
+ // src/observation/snapshot-view.ts
347
+ var G = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new Set(), q = 0, J = !1;
348
+ function Y(e) {
349
+ q++;
350
+ let t = [];
351
+ try {
352
+ c(e(), "Snapshot notification batches must be synchronous");
353
+ } catch (e) {
354
+ t.push(e);
355
+ } finally {
356
+ if (q--, !q) try {
357
+ X();
358
+ } catch (e) {
359
+ t.push(e);
360
+ }
361
+ }
362
+ if (t.length === 1) throw t[0];
363
+ if (t.length > 1) throw AggregateError(t, "Snapshot batch failed");
364
+ }
365
+ function X() {
366
+ if (J) return;
367
+ J = !0;
368
+ let e = [];
369
+ try {
370
+ for (; K.size;) {
371
+ let t = K.values().next().value;
372
+ K.delete(t), Le(t, e);
373
+ }
374
+ } finally {
375
+ J = !1, K.clear();
376
+ }
377
+ if (e.length) throw AggregateError(e, "Snapshot error reporting failed");
378
+ }
379
+ var Ie = class {
380
+ #e = /* @__PURE__ */ new Set();
381
+ #t;
382
+ #n;
383
+ #r = !1;
384
+ #i = !1;
385
+ constructor(e, t) {
386
+ if (typeof e != "function") throw TypeError("Snapshot reader must be a function");
387
+ if (typeof t != "function") throw TypeError("Snapshot error reporter must be a function");
388
+ this.#t = {
389
+ phase: "active",
390
+ read: e,
391
+ report: t
392
+ }, this.#n = {
393
+ phase: "value",
394
+ value: e()
395
+ }, Object.freeze(this);
396
+ }
397
+ view = Object.freeze({
398
+ get: () => this.#a(),
399
+ subscribe: (e) => this.#o(e)
400
+ });
401
+ invalidate() {
402
+ this.#c(), this.#r = !0;
403
+ for (let e of this.#e) K.add(e);
404
+ q || X();
405
+ }
406
+ [r]() {
407
+ let e = this.#t;
408
+ if (e.phase !== "disposed") {
409
+ if (this.#i) throw TypeError("Cannot dispose a snapshot publisher while its reader is running");
410
+ this.#t = { phase: "disposed" };
411
+ try {
412
+ this.#s(e.read);
413
+ } finally {
414
+ this.#r = !1;
415
+ let e = [...this.#e];
416
+ this.#e.clear();
417
+ for (let t of e) Q(t);
418
+ }
419
+ }
420
+ }
421
+ #a() {
422
+ if (this.#i) throw TypeError("Circular snapshot read");
423
+ let e = this.#t;
424
+ e.phase === "active" && this.#s(e.read);
425
+ let t = this.#n;
426
+ if (t.phase === "error") throw t.error;
427
+ return t.value;
428
+ }
429
+ #o(e) {
430
+ if (typeof e != "function") throw TypeError("Subscriber must be a function");
431
+ let { report: t } = this.#c(), n = new Z(e, t, (e) => {
432
+ this.#e.delete(e);
433
+ });
434
+ return this.#e.add(n), n;
435
+ }
436
+ #s(e) {
437
+ this.#r && Y(() => {
438
+ this.#r = !1, this.#i = !0;
439
+ try {
440
+ this.#n = {
441
+ phase: "value",
442
+ value: e()
443
+ };
444
+ } catch (e) {
445
+ throw this.#r = !0, this.#t.phase === "disposed" && (this.#n = {
446
+ phase: "error",
447
+ error: new R(e)
448
+ }), e;
449
+ } finally {
450
+ this.#i = !1;
451
+ }
452
+ });
453
+ }
454
+ #c() {
455
+ let e = this.#t;
456
+ if (e.phase === "disposed") throw TypeError("Snapshot publisher is disposed");
457
+ return e;
458
+ }
459
+ }, Z = class {
460
+ constructor(e, t, n) {
461
+ G.set(this, {
462
+ listener: e,
463
+ report: t,
464
+ detach: n
465
+ }), Object.freeze(this);
466
+ }
467
+ [r]() {
468
+ let e = G.get(this);
469
+ e && (Q(this), e.detach(this));
470
+ }
471
+ };
472
+ function Le(e, t) {
473
+ let n = G.get(e);
474
+ if (n) try {
475
+ let { listener: e } = n;
476
+ c(e(), "Snapshot subscribers must be synchronous");
477
+ } catch (e) {
478
+ try {
479
+ let { report: t } = n;
480
+ c(t(e), "Snapshot error reporters must be synchronous");
481
+ } catch (n) {
482
+ t.push(e, n);
483
+ }
484
+ }
485
+ }
486
+ function Q(e) {
487
+ K.delete(e), G.delete(e);
488
+ }
489
+ // src/contracts/logging.ts
490
+ function $(e) {
491
+ if (!e || typeof e != "object" && typeof e != "function") throw TypeError("Logger must implement debug/info/warn/error");
492
+ let t = (t) => {
493
+ let n = e[t];
494
+ if (typeof n != "function") throw TypeError("Logger must implement debug/info/warn/error");
495
+ return (...t) => Reflect.apply(n, e, t);
496
+ };
497
+ return Object.freeze({
498
+ debug: t("debug"),
499
+ info: t("info"),
500
+ warn: t("warn"),
501
+ error: t("error")
502
+ });
503
+ }
504
+ function Re(e) {
505
+ try {
506
+ return $(e), !0;
507
+ } catch {
508
+ return !1;
509
+ }
510
+ }
511
+ var ze = class {
512
+ handle = Object.freeze({
513
+ debug: (e, ...t) => this.#t("debug", e, t),
514
+ info: (e, ...t) => this.#t("info", e, t),
515
+ warn: (e, ...t) => this.#t("warn", e, t),
516
+ error: (e, ...t) => this.#t("error", e, t)
517
+ });
518
+ #e;
519
+ constructor(e, t) {
520
+ this.#e = {
521
+ logger: e,
522
+ metadata: t
523
+ };
524
+ }
525
+ [r]() {
526
+ this.#e = void 0;
527
+ }
528
+ #t(e, t, n) {
529
+ let r = this.#e;
530
+ if (!r) throw new L(k, "Logger scope has ended");
531
+ c(r.logger[e](t, r.metadata, ...n), "Logger methods must be synchronous");
532
+ }
533
+ }, Be = class {
534
+ #e = /* @__PURE__ */ new Set();
535
+ #t = !1;
536
+ get settled() {
537
+ return this.run(() => void 0).then(() => void 0);
538
+ }
539
+ run(e, t) {
540
+ if (typeof e != "function") throw TypeError("SerialQueue operation must be a function");
541
+ let n = Promise.withResolvers(), r = n.promise.then(() => void 0, () => void 0), i = () => {
542
+ a?.();
543
+ try {
544
+ s(e()).then(n.resolve, n.reject);
545
+ } catch (e) {
546
+ n.reject(e);
547
+ }
548
+ return r;
549
+ }, a = t === void 0 ? void 0 : p(t, (e) => {
550
+ this.#e.delete(i), n.reject(e);
551
+ });
552
+ return t !== void 0 && d(t) || (this.#e.add(i), this.#t || (this.#t = !0, queueMicrotask(() => void this.#n()))), n.promise;
553
+ }
554
+ async #n() {
555
+ for (let e of this.#e) this.#e.delete(e), await e();
556
+ this.#t = !1;
557
+ }
558
+ };
559
+ export { k as A, de as B, O as C, Oe as D, ne as E, Te as F, p as G, m as H, se as I, i as J, c as K, ce as L, ie as M, ae as N, z as O, oe as P, le as R, D as S, te as T, f as U, fe as V, d as W, r as Y, S as _, Ie as a, T as b, Me as c, R as d, g as f, x as g, b as h, Re as i, re as j, h as k, ke as l, y as m, ze as n, Y as o, _ as p, s as q, $ as r, Fe as s, Be as t, L as u, C as v, ee as w, E as x, w as y, ue as z };
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "dougong",
3
- "version": "0.8.3",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "engines": {
6
- "node": ">=22"
6
+ "node": "^24.22.0 || >=26.10.0"
7
7
  },
8
8
  "browserslist": [
9
9
  "Chrome >= 119",
10
10
  "Edge >= 119",
11
- "Firefox >= 121",
11
+ "Firefox >= 124",
12
12
  "Safari >= 17.4"
13
13
  ],
14
14
  "sideEffects": false,
15
15
  "files": [
16
16
  "dist",
17
+ "runtime",
17
18
  "README.md",
18
19
  "LICENSE"
19
20
  ],
@@ -21,14 +22,22 @@
21
22
  ".": {
22
23
  "types": "./dist/index.d.ts",
23
24
  "import": "./dist/index.js"
25
+ },
26
+ "./advanced": {
27
+ "types": "./dist/advanced.d.ts",
28
+ "import": "./dist/advanced.js"
29
+ }
30
+ },
31
+ "imports": {
32
+ "#abort-listener": {
33
+ "types": "./runtime/abort-listener.d.mts",
34
+ "default": "./runtime/abort-listener.mjs"
24
35
  }
25
36
  },
26
37
  "dependencies": {
27
- "@dougongjs/core": "0.8.3",
28
- "@dougongjs/platform": "0.8.3",
29
- "@dougongjs/reactive": "0.8.3"
38
+ "@standard-schema/spec": "^1.1.0"
30
39
  },
31
- "description": "Capability composition and structured lifetime kernel, plus its plugin distribution layer.",
40
+ "description": "Capability composition and structured lifetime kernel for JavaScript/TypeScript.",
32
41
  "license": "MIT",
33
42
  "author": "Dougong contributors",
34
43
  "homepage": "https://tangerg.github.io/dougong/",
@@ -52,6 +61,6 @@
52
61
  "access": "public"
53
62
  },
54
63
  "scripts": {
55
- "build": "vite build"
64
+ "build": "node ../../tooling/generate-internal.mjs && vite build"
56
65
  }
57
66
  }
@@ -0,0 +1,2 @@
1
+ // Generated from tooling/internal/abort-listener.d.mts. Run pnpm generate:internal.
2
+ export function listenForAbort(signal: AbortSignal, notify: () => void): () => void;
@@ -0,0 +1,27 @@
1
+ // Generated from tooling/internal/abort-listener.mjs. Run pnpm generate:internal.
2
+ // A separate closure prevents the dependent from retaining the source through its registration.
3
+ function weakAbortListener(reference) {
4
+ return () => reference.deref()?.();
5
+ }
6
+
7
+ export function listenForAbort(signal, notify) {
8
+ const dependent = AbortSignal.any([signal]);
9
+ const listener = weakAbortListener(new WeakRef(notify));
10
+ let registration = { signal, notify, dependent, listener };
11
+ function detach() {
12
+ if (!registration) return;
13
+ const attached = registration;
14
+ registration = undefined;
15
+ EventTarget.prototype.removeEventListener.call(attached.signal, "abort", attached.notify);
16
+ attached.dependent.removeEventListener("abort", attached.listener);
17
+ }
18
+ try {
19
+ // Source listeners preserve native composite lifetimes; the private dependent bypasses stopped events.
20
+ EventTarget.prototype.addEventListener.call(signal, "abort", notify);
21
+ dependent.addEventListener("abort", listener);
22
+ } catch (error) {
23
+ detach();
24
+ throw error;
25
+ }
26
+ return detach;
27
+ }