@orkestrel/queue 0.0.16 → 0.0.18
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/src/core/index.cjs +99 -69
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +5 -2
- package/dist/src/core/index.d.ts +5 -2
- package/dist/src/core/index.js +100 -70
- package/dist/src/core/index.js.map +1 -1
- package/package.json +18 -18
package/dist/src/core/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ let _orkestrel_timeout = require("@orkestrel/timeout");
|
|
|
4
4
|
let _orkestrel_abort = require("@orkestrel/abort");
|
|
5
5
|
let _orkestrel_emitter = require("@orkestrel/emitter");
|
|
6
6
|
let _orkestrel_database = require("@orkestrel/database");
|
|
7
|
-
|
|
7
|
+
// src/core/errors.ts
|
|
8
8
|
/**
|
|
9
9
|
* Represents a queue failure carrying a lowercase machine-readable `code`, optional
|
|
10
10
|
* structured context, and an optional cause.
|
|
@@ -27,6 +27,7 @@ var QueueError = class extends Error {
|
|
|
27
27
|
constructor(message, options) {
|
|
28
28
|
const cause = options.cause;
|
|
29
29
|
super(message, cause === void 0 ? void 0 : { cause });
|
|
30
|
+
_orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/queue.QueueError"), { value: this });
|
|
30
31
|
this.code = options.code;
|
|
31
32
|
this.context = options.context === void 0 ? void 0 : Object.freeze({ ...options.context });
|
|
32
33
|
}
|
|
@@ -35,9 +36,12 @@ var QueueError = class extends Error {
|
|
|
35
36
|
* Determines whether an unknown value is a {@link QueueError}, staying total for a hostile
|
|
36
37
|
* value.
|
|
37
38
|
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Recognizes the shared brand and declared members across package copies, including subclasses.
|
|
41
|
+
* Refuses a transparent proxy because its brand holds the target's identity.
|
|
42
|
+
*
|
|
38
43
|
* @param value - The value to inspect
|
|
39
|
-
* @returns True if
|
|
40
|
-
* a hostile value
|
|
44
|
+
* @returns True if a branded error or subclass has valid members; false otherwise.
|
|
41
45
|
*
|
|
42
46
|
* @example
|
|
43
47
|
* ```ts
|
|
@@ -49,10 +53,24 @@ var QueueError = class extends Error {
|
|
|
49
53
|
* ```
|
|
50
54
|
*/
|
|
51
55
|
function isQueueError(value) {
|
|
52
|
-
return (0, _orkestrel_contract.
|
|
56
|
+
return (0, _orkestrel_contract.holds)(() => {
|
|
57
|
+
if (!(0, _orkestrel_contract.isError)(value) || _orkestrel_contract.INTRINSICS.prototype(value) === Error.prototype) return false;
|
|
58
|
+
const brand = _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/queue.QueueError"));
|
|
59
|
+
if (brand === void 0 || brand.value !== value) return false;
|
|
60
|
+
const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
|
|
61
|
+
if (code !== "invalid" && code !== "duplicate" && code !== "stopped" && code !== "aborted" && code !== "destroyed" && code !== "cleared" && code !== "timeout" && code !== "store" && code !== "cleanup") return false;
|
|
62
|
+
const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
|
|
63
|
+
if (context === void 0) return true;
|
|
64
|
+
if (!(0, _orkestrel_contract.isObject)(context) && !(0, _orkestrel_contract.isFunction)(context)) return false;
|
|
65
|
+
const id = _orkestrel_contract.INTRINSICS.reflect.read(context, "id");
|
|
66
|
+
if (id !== void 0 && !(0, _orkestrel_contract.isString)(id)) return false;
|
|
67
|
+
const option = _orkestrel_contract.INTRINSICS.reflect.read(context, "option");
|
|
68
|
+
if (option !== void 0 && option !== "id" && option !== "concurrency" && option !== "retries" && option !== "timeout" && option !== "signal") return false;
|
|
69
|
+
const operation = _orkestrel_contract.INTRINSICS.reflect.read(context, "operation");
|
|
70
|
+
return operation === void 0 || operation === "save" || operation === "remove" || operation === "load" || operation === "clear";
|
|
71
|
+
});
|
|
53
72
|
}
|
|
54
|
-
|
|
55
|
-
//#region src/core/validators.ts
|
|
73
|
+
// src/core/validators.ts
|
|
56
74
|
/**
|
|
57
75
|
* Determines whether a value is a valid queue concurrency — a positive safe integer.
|
|
58
76
|
*
|
|
@@ -143,8 +161,7 @@ function isQueueSignal(value) {
|
|
|
143
161
|
function isStoredEntry(value) {
|
|
144
162
|
return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && (0, _orkestrel_contract.isString)(value.id) && "input" in value && isQueueRetries(value.attempts));
|
|
145
163
|
}
|
|
146
|
-
|
|
147
|
-
//#region src/core/helpers.ts
|
|
164
|
+
// src/core/helpers.ts
|
|
148
165
|
/**
|
|
149
166
|
* Reads one named option from a caller-supplied entry options object exactly once,
|
|
150
167
|
* containing a throwing getter as a coded failure.
|
|
@@ -202,8 +219,35 @@ function validateOption(value, guard, option, message) {
|
|
|
202
219
|
}
|
|
203
220
|
});
|
|
204
221
|
}
|
|
205
|
-
|
|
206
|
-
|
|
222
|
+
// src/core/QueueEntry.ts
|
|
223
|
+
/** Holds one queue reservation's execution and settlement state. */
|
|
224
|
+
var QueueEntry = class {
|
|
225
|
+
id;
|
|
226
|
+
input;
|
|
227
|
+
options;
|
|
228
|
+
#attempts;
|
|
229
|
+
#settled = false;
|
|
230
|
+
constructor(id, input, options, attempts) {
|
|
231
|
+
this.id = id;
|
|
232
|
+
this.input = input;
|
|
233
|
+
this.options = options;
|
|
234
|
+
this.#attempts = attempts;
|
|
235
|
+
}
|
|
236
|
+
get attempts() {
|
|
237
|
+
return this.#attempts;
|
|
238
|
+
}
|
|
239
|
+
get settled() {
|
|
240
|
+
return this.#settled;
|
|
241
|
+
}
|
|
242
|
+
complete() {
|
|
243
|
+
this.#attempts += 1;
|
|
244
|
+
return this.#attempts;
|
|
245
|
+
}
|
|
246
|
+
settle() {
|
|
247
|
+
this.#settled = true;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
// src/core/Queue.ts
|
|
207
251
|
/**
|
|
208
252
|
* Represents a concurrent, cooperative FIFO job queue — a wake-park worker loop with
|
|
209
253
|
* retries, a per-attempt timeout, abort, and optional outstanding-work persistence.
|
|
@@ -326,30 +370,8 @@ var Queue = class {
|
|
|
326
370
|
async restore() {
|
|
327
371
|
if (this.#store === void 0 || this.stopped || this.#destroyPromise !== void 0) return;
|
|
328
372
|
const generation = this.#generation;
|
|
329
|
-
const entries =
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const loaded = await this.#store.load();
|
|
333
|
-
for (const stored of loaded) {
|
|
334
|
-
const candidate = {
|
|
335
|
-
id: stored.id,
|
|
336
|
-
input: stored.input,
|
|
337
|
-
attempts: stored.attempts
|
|
338
|
-
};
|
|
339
|
-
if (!isStoredEntry(candidate)) {
|
|
340
|
-
malformed = true;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
entries.push(Object.freeze(candidate));
|
|
344
|
-
}
|
|
345
|
-
} catch (error) {
|
|
346
|
-
throw new QueueError("queue store load failed", {
|
|
347
|
-
code: "store",
|
|
348
|
-
cause: error,
|
|
349
|
-
context: { operation: "load" }
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
if (malformed) throw new QueueError("queue store returned an invalid entry", {
|
|
373
|
+
const entries = await this.#load(this.#store);
|
|
374
|
+
if (entries === void 0) throw new QueueError("queue store returned an invalid entry", {
|
|
353
375
|
code: "store",
|
|
354
376
|
context: { operation: "load" }
|
|
355
377
|
});
|
|
@@ -362,6 +384,33 @@ var Queue = class {
|
|
|
362
384
|
token.promise.catch(() => {});
|
|
363
385
|
}
|
|
364
386
|
}
|
|
387
|
+
async #load(store) {
|
|
388
|
+
try {
|
|
389
|
+
const loaded = await store.load();
|
|
390
|
+
const entries = [...this.#snapshot(loaded)];
|
|
391
|
+
return entries.some((entry) => entry === void 0) ? void 0 : entries.filter((entry) => entry !== void 0);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
throw new QueueError("queue store load failed", {
|
|
394
|
+
code: "store",
|
|
395
|
+
cause: error,
|
|
396
|
+
context: { operation: "load" }
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
*#snapshot(loaded) {
|
|
401
|
+
for (const stored of loaded) {
|
|
402
|
+
const candidate = {
|
|
403
|
+
id: stored.id,
|
|
404
|
+
input: stored.input,
|
|
405
|
+
attempts: stored.attempts
|
|
406
|
+
};
|
|
407
|
+
if (!isStoredEntry(candidate)) {
|
|
408
|
+
yield void 0;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
yield Object.freeze(candidate);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
365
414
|
/** Begins or restarts worker execution unless the queue is terminal. */
|
|
366
415
|
start() {
|
|
367
416
|
if (this.#abortPromise !== void 0 || this.#destroyPromise !== void 0) return;
|
|
@@ -466,13 +515,7 @@ var Queue = class {
|
|
|
466
515
|
}
|
|
467
516
|
#reserve(id, input, options, attempts) {
|
|
468
517
|
const token = Promise.withResolvers();
|
|
469
|
-
this.#entries.set(token,
|
|
470
|
-
id,
|
|
471
|
-
input,
|
|
472
|
-
options,
|
|
473
|
-
attempts,
|
|
474
|
-
settled: false
|
|
475
|
-
});
|
|
518
|
+
this.#entries.set(token, new QueueEntry(id, input, options, attempts));
|
|
476
519
|
this.#live.set(id, token);
|
|
477
520
|
this.#drained = false;
|
|
478
521
|
return token;
|
|
@@ -662,12 +705,11 @@ var Queue = class {
|
|
|
662
705
|
const retries = entry.options?.retries ?? this.#retries;
|
|
663
706
|
const timeout = entry.options?.timeout ?? this.#timeout;
|
|
664
707
|
const signal = entry.options?.signal;
|
|
665
|
-
let completed = entry.attempts;
|
|
666
708
|
this.#emitter.emit("start", entry.id);
|
|
667
709
|
while (true) {
|
|
668
710
|
if (await this.#interrupt(token, signal)) return;
|
|
669
711
|
const outcome = await this.#attempt(entry.id, entry.input, timeout, signal);
|
|
670
|
-
completed
|
|
712
|
+
const completed = entry.complete();
|
|
671
713
|
if (outcome.success) {
|
|
672
714
|
await this.#settle(token, outcome);
|
|
673
715
|
return;
|
|
@@ -756,7 +798,7 @@ var Queue = class {
|
|
|
756
798
|
#settleToken(token, outcome) {
|
|
757
799
|
const entry = this.#entries.get(token);
|
|
758
800
|
if (entry === void 0 || entry.settled) return false;
|
|
759
|
-
entry.
|
|
801
|
+
entry.settle();
|
|
760
802
|
if (outcome.success) token.resolve(outcome.value);
|
|
761
803
|
else token.reject(outcome.error);
|
|
762
804
|
if (this.#live.get(entry.id) !== token) this.#entries.delete(token);
|
|
@@ -772,16 +814,12 @@ var Queue = class {
|
|
|
772
814
|
}
|
|
773
815
|
async #attempt(id, input, timeout, signal) {
|
|
774
816
|
const cancel = signal === void 0 ? this.#abort.signal : AbortSignal.any([this.#abort.signal, signal]);
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
});
|
|
782
|
-
deadline.start();
|
|
783
|
-
attemptSignal = AbortSignal.any([cancel, deadline.signal]);
|
|
784
|
-
}
|
|
817
|
+
const deadline = timeout > 0 ? (0, _orkestrel_timeout.createTimeout)({
|
|
818
|
+
ms: timeout,
|
|
819
|
+
signal: cancel
|
|
820
|
+
}) : void 0;
|
|
821
|
+
deadline?.start();
|
|
822
|
+
const attemptSignal = deadline === void 0 ? cancel : AbortSignal.any([cancel, deadline.signal]);
|
|
785
823
|
try {
|
|
786
824
|
return {
|
|
787
825
|
success: true,
|
|
@@ -851,12 +889,7 @@ var Queue = class {
|
|
|
851
889
|
}
|
|
852
890
|
}
|
|
853
891
|
async #settleDestroy(barrier, aborting) {
|
|
854
|
-
|
|
855
|
-
try {
|
|
856
|
-
await aborting;
|
|
857
|
-
} catch (error) {
|
|
858
|
-
failure = error;
|
|
859
|
-
}
|
|
892
|
+
const failure = await aborting.catch((error) => error);
|
|
860
893
|
try {
|
|
861
894
|
await this.#finish([
|
|
862
895
|
...this.#workers,
|
|
@@ -865,11 +898,12 @@ var Queue = class {
|
|
|
865
898
|
...this.#cleanOrphans(true)
|
|
866
899
|
], "queue destroy cleanup failed");
|
|
867
900
|
} catch (error) {
|
|
868
|
-
failure
|
|
901
|
+
barrier.reject(failure === void 0 ? error : new QueueError("queue destroy cleanup failed", {
|
|
869
902
|
code: "cleanup",
|
|
870
903
|
cause: new AggregateError([failure, error], "queue destroy cleanup failed"),
|
|
871
904
|
context: { operation: "remove" }
|
|
872
|
-
});
|
|
905
|
+
}));
|
|
906
|
+
return;
|
|
873
907
|
} finally {
|
|
874
908
|
this.#emitter.destroy();
|
|
875
909
|
}
|
|
@@ -877,8 +911,7 @@ var Queue = class {
|
|
|
877
911
|
else barrier.reject(failure);
|
|
878
912
|
}
|
|
879
913
|
};
|
|
880
|
-
|
|
881
|
-
//#region src/core/stores/DatabaseQueueStore.ts
|
|
914
|
+
// src/core/stores/DatabaseQueueStore.ts
|
|
882
915
|
/**
|
|
883
916
|
* Represents the opt-in durable store for a queue's outstanding entries, backed by one table
|
|
884
917
|
* of the `@orkestrel/database` layer — a queue's durable state is a table, so persistence
|
|
@@ -936,8 +969,7 @@ var DatabaseQueueStore = class {
|
|
|
936
969
|
await this.#table.clear();
|
|
937
970
|
}
|
|
938
971
|
};
|
|
939
|
-
|
|
940
|
-
//#region src/core/stores/MemoryQueueStore.ts
|
|
972
|
+
// src/core/stores/MemoryQueueStore.ts
|
|
941
973
|
/**
|
|
942
974
|
* Represents an in-memory store of a queue's outstanding entries — a process-lifetime `Map`
|
|
943
975
|
* owning validated, immutable JSON snapshots.
|
|
@@ -1032,8 +1064,7 @@ var MemoryQueueStore = class {
|
|
|
1032
1064
|
});
|
|
1033
1065
|
}
|
|
1034
1066
|
};
|
|
1035
|
-
|
|
1036
|
-
//#region src/core/factories.ts
|
|
1067
|
+
// src/core/factories.ts
|
|
1037
1068
|
/**
|
|
1038
1069
|
* Creates a concurrent, cooperative job queue — a bounded-concurrency engine that
|
|
1039
1070
|
* runs each enqueued input through a handler, with retries and a per-attempt
|
|
@@ -1121,7 +1152,6 @@ function createDatabaseQueueStore(input, driver) {
|
|
|
1121
1152
|
function createMemoryQueueStore(input) {
|
|
1122
1153
|
return new MemoryQueueStore(input);
|
|
1123
1154
|
}
|
|
1124
|
-
//#endregion
|
|
1125
1155
|
exports.DatabaseQueueStore = DatabaseQueueStore;
|
|
1126
1156
|
exports.MemoryQueueStore = MemoryQueueStore;
|
|
1127
1157
|
exports.Queue = Queue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isInstance","isInteger","isFiniteNumber","MAX_TIMEOUT_MS","holds","isRecord","isString","createAbort","Emitter","isString","isError","createTimeout","preview","createContract","cloneJSONValue","stringShape","integerShape","createDatabase"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/Queue.ts","../../../src/core/stores/DatabaseQueueStore.ts","../../../src/core/stores/MemoryQueueStore.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { QueueErrorContext, QueueErrorOptions } from './types.js'\nimport { isInstance } from '@orkestrel/contract'\n\n/**\n * Represents a queue failure carrying a lowercase machine-readable `code`, optional\n * structured context, and an optional cause.\n *\n * @example\n * ```ts\n * new QueueError('duplicate id', { code: 'duplicate', context: { id: 'job-1' } })\n * ```\n */\nexport class QueueError extends Error {\n\toverride readonly name = 'QueueError'\n\treadonly code\n\treadonly context: QueueErrorContext | undefined\n\n\t/**\n\t * Creates a queue error.\n\t *\n\t * @param message - Human-readable failure description\n\t * @param options - Machine-readable category, optional context, and optional cause\n\t */\n\tconstructor(message: string, options: QueueErrorOptions) {\n\t\tconst cause = options.cause\n\t\tsuper(message, cause === undefined ? undefined : { cause })\n\t\tthis.code = options.code\n\t\tthis.context = options.context === undefined ? undefined : Object.freeze({ ...options.context })\n\t}\n}\n\n/**\n * Determines whether an unknown value is a {@link QueueError}, staying total for a hostile\n * value.\n *\n * @param value - The value to inspect\n * @returns True if the value is a real `QueueError` instance; false otherwise, including for\n * a hostile value\n *\n * @example\n * ```ts\n * try {\n * \tawait queue.clear()\n * } catch (error) {\n * \tif (isQueueError(error) && error.code === 'cleanup') report(error.context)\n * }\n * ```\n */\nexport function isQueueError(value: unknown): value is QueueError {\n\treturn isInstance(value, QueueError)\n}\n","import type { StoredEntry } from './types.js'\nimport { holds, isFiniteNumber, isInteger, isRecord, isString } from '@orkestrel/contract'\nimport { MAX_TIMEOUT_MS } from '@orkestrel/timeout'\n\n/**\n * Determines whether a value is a valid queue concurrency — a positive safe integer.\n *\n * @param value - Value to inspect\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isQueueConcurrency(4) // true\n * isQueueConcurrency(0) // false\n * ```\n */\nexport function isQueueConcurrency(value: unknown): value is number {\n\treturn isInteger(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Determines whether a value is a valid queue retry count — a nonnegative safe integer.\n *\n * @param value - Value to inspect\n * @returns True if the value is a nonnegative safe integer; false otherwise\n *\n * @example\n * ```ts\n * isQueueRetries(2) // true\n * isQueueRetries(-1) // false\n * ```\n */\nexport function isQueueRetries(value: unknown): value is number {\n\treturn isInteger(value) && Number.isSafeInteger(value) && value >= 0\n}\n\n/**\n * Determines whether a value is a valid queue timeout — an integer count of milliseconds\n * inside the native timer range.\n *\n * @param value - Value to inspect\n * @returns True if the value is an integer within the native timer range,\n * inclusive; false otherwise\n *\n * @example\n * ```ts\n * isQueueTimeout(500) // true\n * isQueueTimeout(2_147_483_648) // false\n * ```\n */\nexport function isQueueTimeout(value: unknown): value is number {\n\treturn isFiniteNumber(value) && isInteger(value) && value >= 0 && value <= MAX_TIMEOUT_MS\n}\n\n/**\n * Determines whether a value is a native abort signal usable by the queue, testing the\n * native brand rather than the shape.\n *\n * @param value - Value to inspect\n * @returns True if the value carries the native `AbortSignal` internal slot; false otherwise\n *\n * @example\n * ```ts\n * isQueueSignal(new AbortController().signal) // true\n * isQueueSignal({}) // false\n * ```\n */\nexport function isQueueSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n\n/**\n * Determines whether a value is a valid stored queue entry — a record holding a string\n * `id`, an `input`, and a nonnegative safe-integer `attempts`.\n *\n * @remarks\n * The single test for what a {@link StoredEntry} is, shared by the queue's `restore`\n * boundary and the memory store's `save` boundary. `input` carries the caller's own\n * payload type, so only its presence is checked.\n *\n * @param value - Value to inspect\n * @returns True if the value is a record holding a string `id`, an `input` member, and a\n * nonnegative safe-integer `attempts`; false otherwise\n *\n * @example\n * ```ts\n * isStoredEntry({ id: 'job-1', input: 'task', attempts: 0 }) // true\n * isStoredEntry({ id: 'job-1', input: 'task', attempts: -1 }) // false\n * ```\n */\nexport function isStoredEntry(value: unknown): value is StoredEntry<unknown> {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) && isString(value.id) && 'input' in value && isQueueRetries(value.attempts),\n\t)\n}\n","import type { Guard } from '@orkestrel/contract'\nimport type { QueueEntryOptions, QueueOption } from './types.js'\nimport { QueueError } from './errors.js'\n\n/**\n * Reads one named option from a caller-supplied entry options object exactly once,\n * containing a throwing getter as a coded failure.\n *\n * @remarks\n * An absent options object reads nothing and yields `undefined`.\n *\n * @param options - The caller's own entry options, or `undefined`\n * @param option - The option key to read\n * @param message - The failure description the thrown error carries\n * @returns The value the property held, or `undefined` when no options object was supplied\n * @throws {QueueError} Thrown when reading the property throws, coded `invalid` with the\n * option in its context.\n *\n * @example\n * ```ts\n * readOption({ retries: 2 }, 'retries', 'queue retries could not be read') // 2\n * ```\n */\nexport function readOption(\n\toptions: QueueEntryOptions | undefined,\n\toption: keyof QueueEntryOptions,\n\tmessage: string,\n): unknown {\n\ttry {\n\t\treturn options?.[option]\n\t} catch (error: unknown) {\n\t\tthrow new QueueError(message, {\n\t\t\tcode: 'invalid',\n\t\t\tcause: error,\n\t\t\tcontext: { option },\n\t\t})\n\t}\n}\n\n/**\n * Validates one already-read queue option against its guard, and throws the coded invalid\n * failure carrying the option and the refused value when the guard refuses it.\n *\n * @param value - The option value to check\n * @param guard - The total guard the value must satisfy\n * @param option - The option key the failure context reports\n * @param message - The failure description the thrown error carries\n * @returns The same value, narrowed by the guard\n * @throws {QueueError} Thrown when the guard refuses the value, coded `invalid` with the\n * option and the refused value in its context.\n *\n * @example\n * ```ts\n * validateOption(4, isQueueConcurrency, 'concurrency', 'queue concurrency must be positive') // 4\n * ```\n */\nexport function validateOption<TValue>(\n\tvalue: unknown,\n\tguard: Guard<TValue>,\n\toption: QueueOption,\n\tmessage: string,\n): TValue {\n\tif (guard(value)) return value\n\tthrow new QueueError(message, {\n\t\tcode: 'invalid',\n\t\tcontext: { option, value },\n\t})\n}\n","import type { AbortInterface } from '@orkestrel/abort'\nimport type { Result } from '@orkestrel/contract'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type { TimeoutInterface } from '@orkestrel/timeout'\nimport type {\n\tQueueEntryOptions,\n\tQueueEventMap,\n\tQueueHandler,\n\tQueueInterface,\n\tQueueOptions,\n\tQueueStoreInterface,\n\tStoredEntry,\n} from './types.js'\nimport { createAbort } from '@orkestrel/abort'\nimport { isError, isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { readOption, validateOption } from './helpers.js'\nimport {\n\tisQueueConcurrency,\n\tisQueueRetries,\n\tisQueueSignal,\n\tisQueueTimeout,\n\tisStoredEntry,\n} from './validators.js'\n\n/**\n * Represents a concurrent, cooperative FIFO job queue — a wake-park worker loop with\n * retries, a per-attempt timeout, abort, and optional outstanding-work persistence.\n *\n * @typeParam TInput - The work input each entry carries\n * @typeParam TResult - The value each entry resolves\n *\n * @example\n * ```ts\n * const queue = new Queue<number, number>({ handler: (input) => input * 2 })\n * const result = await queue.enqueue(21)\n * ```\n */\nexport class Queue<TInput, TResult> implements QueueInterface<TInput, TResult> {\n\treadonly #handler: QueueHandler<TInput, TResult>\n\treadonly #concurrency: number\n\treadonly #retries: number\n\treadonly #timeout: number\n\treadonly #store: QueueStoreInterface<TInput> | undefined\n\treadonly #abort: AbortInterface = createAbort()\n\treadonly #emitter: Emitter<QueueEventMap<TResult>>\n\treadonly #entries = new Map<\n\t\tPromiseWithResolvers<TResult>,\n\t\t{\n\t\t\treadonly id: string\n\t\t\treadonly input: TInput\n\t\t\treadonly options: QueueEntryOptions | undefined\n\t\t\treadonly attempts: number\n\t\t\tsettled: boolean\n\t\t}\n\t>()\n\treadonly #live = new Map<string, PromiseWithResolvers<TResult>>()\n\treadonly #pending: Array<PromiseWithResolvers<TResult>> = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: Array<() => void> = []\n\treadonly #workers = new Set<Promise<void>>()\n\treadonly #admissions = new Map<PromiseWithResolvers<TResult>, Promise<void>>()\n\treadonly #orphans = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #cleanups = new Map<PromiseWithResolvers<TResult>, Promise<void>>()\n\t#admission: Promise<void> = Promise.resolve()\n\t#stopPromise: Promise<void> | undefined\n\t#abortPromise: Promise<void> | undefined\n\t#destroyPromise: Promise<void> | undefined\n\t#generation = 0\n\t#paused = false\n\t#stopped = false\n\t#drained = true\n\n\t/**\n\t * Creates a queue.\n\t *\n\t * @param options - Handler, validated execution limits, persistence, and observation hooks\n\t */\n\tconstructor(options: QueueOptions<TInput, TResult>) {\n\t\tconst configuredConcurrency = options.concurrency\n\t\tconst concurrency = validateOption(\n\t\t\tconfiguredConcurrency === undefined ? 1 : configuredConcurrency,\n\t\t\tisQueueConcurrency,\n\t\t\t'concurrency',\n\t\t\t'queue concurrency must be a positive safe integer',\n\t\t)\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = validateOption(\n\t\t\tconfiguredRetries === undefined ? 0 : configuredRetries,\n\t\t\tisQueueRetries,\n\t\t\t'retries',\n\t\t\t'queue retries must be a nonnegative safe integer',\n\t\t)\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = validateOption(\n\t\t\tconfiguredTimeout === undefined ? 0 : configuredTimeout,\n\t\t\tisQueueTimeout,\n\t\t\t'timeout',\n\t\t\t'queue timeout must be within the native timer range',\n\t\t)\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#handler = options.handler\n\t\tthis.#concurrency = concurrency\n\t\tthis.#retries = retries\n\t\tthis.#timeout = timeout\n\t\tthis.#store = options.store\n\t\tthis.#emitter = new Emitter<QueueEventMap<TResult>>({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\tget emitter(): EmitterInterface<QueueEventMap<TResult>> {\n\t\treturn this.#emitter\n\t}\n\n\tget count(): number {\n\t\treturn this.#live.size\n\t}\n\n\tget active(): number {\n\t\treturn this.#claims.size\n\t}\n\n\tget paused(): boolean {\n\t\treturn this.#paused\n\t}\n\n\tget stopped(): boolean {\n\t\treturn this.#stopped || this.#abortPromise !== undefined\n\t}\n\n\t/**\n\t * Reserves and submits one FIFO entry.\n\t *\n\t * @param input - Handler input\n\t * @param options - Optional id, retry/timeout overrides, and entry abort signal\n\t * @returns The entry's settle-once execution promise\n\t * @throws {QueueError} Thrown synchronously when an option is inaccessible or invalid.\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tconst rawId = readOption(options, 'id', 'queue entry id could not be read')\n\t\tconst supplied =\n\t\t\trawId === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(rawId, isString, 'id', 'queue entry id must be a string')\n\t\tconst rawRetries = readOption(options, 'retries', 'queue retries could not be read')\n\t\tconst retries =\n\t\t\trawRetries === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(\n\t\t\t\t\t\trawRetries,\n\t\t\t\t\t\tisQueueRetries,\n\t\t\t\t\t\t'retries',\n\t\t\t\t\t\t'queue retries must be a nonnegative safe integer',\n\t\t\t\t\t)\n\t\tconst rawTimeout = readOption(options, 'timeout', 'queue timeout could not be read')\n\t\tconst timeout =\n\t\t\trawTimeout === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(\n\t\t\t\t\t\trawTimeout,\n\t\t\t\t\t\tisQueueTimeout,\n\t\t\t\t\t\t'timeout',\n\t\t\t\t\t\t'queue timeout must be within the native timer range',\n\t\t\t\t\t)\n\t\tconst rawSignal = readOption(options, 'signal', 'queue signal could not be read')\n\t\tconst signal =\n\t\t\trawSignal === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(rawSignal, isQueueSignal, 'signal', 'queue signal must be an AbortSignal')\n\t\tconst normalized: QueueEntryOptions | undefined =\n\t\t\toptions === undefined\n\t\t\t\t? undefined\n\t\t\t\t: Object.freeze({\n\t\t\t\t\t\t...(supplied === undefined ? {} : { id: supplied }),\n\t\t\t\t\t\t...(retries === undefined ? {} : { retries }),\n\t\t\t\t\t\t...(timeout === undefined ? {} : { timeout }),\n\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t})\n\t\tif (this.#destroyPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#abortPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is aborted', { code: 'aborted' }))\n\t\t}\n\t\tif (this.#stopped) {\n\t\t\treturn Promise.reject(new QueueError('queue is stopped', { code: 'stopped' }))\n\t\t}\n\t\tconst id = supplied ?? crypto.randomUUID()\n\t\tif (this.#live.has(id)) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue entry id is already live', {\n\t\t\t\t\tcode: 'duplicate',\n\t\t\t\t\tcontext: { id },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\tconst token = this.#reserve(id, input, normalized, 0)\n\t\tif (this.#store === undefined) this.#accept(token)\n\t\telse this.#schedule(token)\n\t\treturn token.promise\n\t}\n\n\t/**\n\t * Loads and accepts every outstanding stored entry from the current lifecycle generation.\n\t *\n\t * @returns A promise that settles after every loaded entry is reserved and accepted\n\t * @throws {QueueError} Thrown when the store's load fails or returns a malformed entry.\n\t */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyPromise !== undefined) return\n\t\tconst generation = this.#generation\n\t\tconst entries: Array<StoredEntry<TInput>> = []\n\t\tlet malformed = false\n\t\ttry {\n\t\t\tconst loaded = await this.#store.load()\n\t\t\tfor (const stored of loaded) {\n\t\t\t\tconst candidate = { id: stored.id, input: stored.input, attempts: stored.attempts }\n\t\t\t\tif (!isStoredEntry(candidate)) {\n\t\t\t\t\tmalformed = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tentries.push(Object.freeze(candidate))\n\t\t\t}\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue store load failed', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { operation: 'load' },\n\t\t\t})\n\t\t}\n\t\tif (malformed) {\n\t\t\tthrow new QueueError('queue store returned an invalid entry', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcontext: { operation: 'load' },\n\t\t\t})\n\t\t}\n\t\tif (generation !== this.#generation || this.stopped || this.#destroyPromise !== undefined)\n\t\t\treturn\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyPromise !== undefined)\n\t\t\t\treturn\n\t\t\tif (this.#live.has(stored.id)) continue\n\t\t\tconst token = this.#reserve(stored.id, stored.input, undefined, stored.attempts)\n\t\t\tthis.#accept(token)\n\t\t\tvoid token.promise.catch(() => {})\n\t\t}\n\t}\n\n\t/** Begins or restarts worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#abortPromise !== undefined || this.#destroyPromise !== undefined) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/**\n\t * Rejects non-active work and awaits current-loop and durable cleanup quiescence.\n\t *\n\t * @returns The stable stop barrier\n\t */\n\tstop(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) return this.#destroyPromise\n\t\tif (this.#abortPromise !== undefined) return this.#abortPromise\n\t\tif (this.#stopped && this.#stopPromise !== undefined) return this.#stopPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#stopPromise = barrier.promise\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst existing = [...this.#cleanups.values()]\n\t\tconst cleanup = [\n\t\t\t...this.#drain(new QueueError('queue is stopped', { code: 'stopped' })),\n\t\t\t...this.#cleanOrphans(true),\n\t\t]\n\t\tconst tasks = [...this.#workers, ...this.#admissions.values(), ...existing, ...cleanup]\n\t\tthis.#wakeAll()\n\t\tvoid this.#settleBarrier(barrier, tasks, 'queue stop cleanup failed')\n\t\treturn barrier.promise\n\t}\n\n\t/** Suspends new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyPromise !== undefined) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continues execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyPromise !== undefined) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancels the queue and awaits owned cleanup.\n\t *\n\t * @param reason - Optional cause carried by the coded abort error\n\t * @returns The stable abort barrier\n\t */\n\tabort(reason?: unknown): Promise<void> {\n\t\tif (this.#abortPromise !== undefined) return this.#abortPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#abortPromise = barrier.promise\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(isError(reason) ? reason.message : 'queue is aborted', {\n\t\t\tcode: 'aborted',\n\t\t\t...(reason === undefined ? {} : { cause: reason }),\n\t\t})\n\t\tthis.#abort.abort(error)\n\t\tconst existing = [...this.#cleanups.values()]\n\t\tconst cleanup = [...this.#drain(error), ...this.#cleanOrphans(true)]\n\t\tconst tasks = [...this.#workers, ...this.#admissions.values(), ...existing, ...cleanup]\n\t\tthis.#wakeAll()\n\t\tthis.#emitter.emit('abort', error)\n\t\tvoid this.#settleBarrier(barrier, tasks, 'queue abort cleanup failed')\n\t\treturn barrier.promise\n\t}\n\n\t/**\n\t * Rejects non-active work and awaits its durable cleanup.\n\t *\n\t * @returns A promise that settles after every affected removal completes\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: Array<Promise<void>> = []\n\t\tfor (const [token, cleanup] of this.#cleanups) {\n\t\t\tif (!this.#claims.has(token)) existing.push(cleanup)\n\t\t}\n\t\tconst cleanup = [\n\t\t\t...this.#drain(new QueueError('queue is cleared', { code: 'cleared' })),\n\t\t\t...this.#cleanOrphans(false),\n\t\t]\n\t\treturn this.#finish(\n\t\t\t[...this.#admissions.values(), ...existing, ...cleanup],\n\t\t\t'queue clear cleanup failed',\n\t\t)\n\t}\n\n\t/**\n\t * Tears down once, destroying the emitter only after cleanup finishes.\n\t *\n\t * @returns The stable destroy barrier\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) return this.#destroyPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#destroyPromise = barrier.promise\n\t\tconst aborting = this.abort(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\tvoid this.#settleDestroy(barrier, aborting)\n\t\treturn barrier.promise\n\t}\n\n\t#reserve(\n\t\tid: string,\n\t\tinput: TInput,\n\t\toptions: QueueEntryOptions | undefined,\n\t\tattempts: number,\n\t): PromiseWithResolvers<TResult> {\n\t\tconst token = Promise.withResolvers<TResult>()\n\t\tthis.#entries.set(token, { id, input, options, attempts, settled: false })\n\t\tthis.#live.set(id, token)\n\t\tthis.#drained = false\n\t\treturn token\n\t}\n\n\t#schedule(token: PromiseWithResolvers<TResult>): void {\n\t\tconst task = this.#admission.then(() => this.#admit(token))\n\t\tthis.#admissions.set(token, task)\n\t\tthis.#admission = task.catch(() => {})\n\t\tvoid task.finally(() => this.#admissions.delete(token)).catch(() => {})\n\t}\n\n\tasync #admit(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || this.#store === undefined) return\n\t\ttry {\n\t\t\tawait this.#store.save({ id: entry.id, input: entry.input, attempts: entry.attempts })\n\t\t} catch (error: unknown) {\n\t\t\ttry {\n\t\t\t\tawait this.#cleanup(token)\n\t\t\t} catch (cleanup: unknown) {\n\t\t\t\tthis.#settleToken(token, { success: false, error: cleanup })\n\t\t\t\tthis.#emitDrain()\n\t\t\t\tthrow cleanup\n\t\t\t}\n\t\t\tthis.#settleToken(token, {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: new QueueError(isError(error) ? error.message : 'queue admission save failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t}),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tentry.settled ||\n\t\t\tthis.#abortPromise !== undefined ||\n\t\t\tthis.#destroyPromise !== undefined ||\n\t\t\tthis.#stopped\n\t\t) {\n\t\t\tawait this.#discard(token)\n\t\t\treturn\n\t\t}\n\t\tthis.#accept(token)\n\t}\n\n\t#accept(token: PromiseWithResolvers<TResult>): void {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return\n\t\tthis.#pending.push(token)\n\t\tthis.#emitter.emit('enqueue', entry.id)\n\t\tthis.#spawn()\n\t\tthis.#wake()\n\t}\n\n\t#spawn(): void {\n\t\tif (this.#stopped || this.#abortPromise !== undefined || this.#destroyPromise !== undefined)\n\t\t\treturn\n\t\tconst demand = Math.min(this.#concurrency, this.#claims.size + this.#pending.length)\n\t\twhile (this.#workers.size < demand) {\n\t\t\tconst generation = this.#generation\n\t\t\tconst worker = this.#worker(generation)\n\t\t\tthis.#workers.add(worker)\n\t\t\tvoid worker\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.#workers.delete(worker)\n\t\t\t\t\tthis.#spawn()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\t}\n\n\tasync #worker(generation: number): Promise<void> {\n\t\twhile (generation === this.#generation) {\n\t\t\tconst token = await this.#next(generation)\n\t\t\tif (token === undefined) return\n\t\t\ttry {\n\t\t\t\tawait this.#run(token)\n\t\t\t} catch (error: unknown) {\n\t\t\t\tawait this.#fail(token, error)\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\t#next(generation: number): Promise<PromiseWithResolvers<TResult> | undefined> {\n\t\treturn new Promise((resolve) => this.#take(generation, resolve))\n\t}\n\n\t#take(\n\t\tgeneration: number,\n\t\tresolve: (token: PromiseWithResolvers<TResult> | undefined) => void,\n\t): void {\n\t\tif (\n\t\t\tgeneration !== this.#generation ||\n\t\t\tthis.#stopped ||\n\t\t\tthis.#abortPromise !== undefined ||\n\t\t\tthis.#destroyPromise !== undefined\n\t\t) {\n\t\t\tresolve(undefined)\n\t\t\treturn\n\t\t}\n\t\tif (this.#paused || this.#pending.length === 0) {\n\t\t\tthis.#wakes.push(() => this.#take(generation, resolve))\n\t\t\treturn\n\t\t}\n\t\tconst token = this.#pending.shift()\n\t\tif (token === undefined) {\n\t\t\tthis.#wakes.push(() => this.#take(generation, resolve))\n\t\t\treturn\n\t\t}\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) {\n\t\t\tthis.#take(generation, resolve)\n\t\t\treturn\n\t\t}\n\t\tthis.#claims.add(token)\n\t\tresolve(token)\n\t}\n\n\t#wake(): void {\n\t\tconst resolver = this.#wakes.shift()\n\t\tif (resolver !== undefined) resolver()\n\t}\n\n\t#wakeAll(): void {\n\t\tconst resolvers = this.#wakes.splice(0)\n\t\tfor (const resolver of resolvers) resolver()\n\t}\n\n\t#drain(error: QueueError): ReadonlyArray<Promise<void>> {\n\t\tfor (const token of this.#admissions.keys()) this.#settleToken(token, { success: false, error })\n\t\tconst tokens = this.#pending.splice(0)\n\t\tconst cleanup: Array<Promise<void>> = []\n\t\tfor (const token of tokens) {\n\t\t\tthis.#settleToken(token, { success: false, error })\n\t\t\tcleanup.push(this.#discard(token))\n\t\t}\n\t\treturn cleanup\n\t}\n\n\t#cleanOrphans(claimed: boolean): ReadonlyArray<Promise<void>> {\n\t\tconst cleanup: Array<Promise<void>> = []\n\t\tfor (const token of this.#orphans) {\n\t\t\tif (claimed || !this.#claims.has(token)) cleanup.push(this.#discard(token))\n\t\t}\n\t\treturn cleanup\n\t}\n\n\tasync #discard(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} finally {\n\t\t\tthis.#emitDrain()\n\t\t}\n\t}\n\n\t#cleanup(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst current = this.#cleanups.get(token)\n\t\tif (current !== undefined) return current\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#cleanups.set(token, barrier.promise)\n\t\tvoid this.#clean(token, barrier)\n\t\treturn barrier.promise\n\t}\n\n\tasync #clean(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\tbarrier: PromiseWithResolvers<void>,\n\t): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) {\n\t\t\tbarrier.resolve()\n\t\t\tthis.#cleanups.delete(token)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tif (this.#store !== undefined) await this.#store.remove(entry.id)\n\t\t\tthis.#release(token)\n\t\t\tbarrier.resolve()\n\t\t} catch (error: unknown) {\n\t\t\tif (this.#live.get(entry.id) === token) this.#orphans.add(token)\n\t\t\tbarrier.reject(\n\t\t\t\tnew QueueError('queue entry cleanup failed', {\n\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { id: entry.id, operation: 'remove' },\n\t\t\t\t}),\n\t\t\t)\n\t\t} finally {\n\t\t\tif (this.#cleanups.get(token) === barrier.promise) this.#cleanups.delete(token)\n\t\t}\n\t}\n\n\t#release(token: PromiseWithResolvers<TResult>): void {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || this.#live.get(entry.id) !== token) return\n\t\tthis.#live.delete(entry.id)\n\t\tthis.#orphans.delete(token)\n\t\tif (entry.settled) this.#entries.delete(token)\n\t}\n\n\tasync #run(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return\n\t\tconst retries = entry.options?.retries ?? this.#retries\n\t\tconst timeout = entry.options?.timeout ?? this.#timeout\n\t\tconst signal = entry.options?.signal\n\t\tlet completed = entry.attempts\n\t\tthis.#emitter.emit('start', entry.id)\n\t\twhile (true) {\n\t\t\tif (await this.#interrupt(token, signal)) return\n\t\t\tconst outcome = await this.#attempt(entry.id, entry.input, timeout, signal)\n\t\t\tcompleted += 1\n\t\t\tif (outcome.success) {\n\t\t\t\tawait this.#settle(token, outcome)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (await this.#interrupt(token, signal)) return\n\t\t\tif (completed > retries) {\n\t\t\t\tawait this.#settle(token, outcome)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait this.#saveAttempt(token, completed)\n\t\t\tthis.#emitter.emit('retry', entry.id, completed)\n\t\t}\n\t}\n\n\tasync #interrupt(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<boolean> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return true\n\t\tif (this.#abort.aborted) {\n\t\t\tawait this.#settle(token, { success: false, error: this.#abort.signal.reason })\n\t\t\treturn true\n\t\t}\n\t\tif (!signal?.aborted) return false\n\t\tawait this.#settle(token, {\n\t\t\tsuccess: false,\n\t\t\terror: new QueueError(\n\t\t\t\tisError(signal.reason) ? signal.reason.message : 'queue entry is aborted',\n\t\t\t\t{\n\t\t\t\t\tcode: 'aborted',\n\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\tcontext: { id: entry.id },\n\t\t\t\t},\n\t\t\t),\n\t\t})\n\t\treturn true\n\t}\n\n\tasync #saveAttempt(token: PromiseWithResolvers<TResult>, attempts: number): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (this.#store === undefined || entry === undefined) return\n\t\ttry {\n\t\t\tawait this.#store.save({ id: entry.id, input: entry.input, attempts })\n\t\t} catch {\n\t\t\t// Live execution is authoritative; a crash may replay an earlier persisted attempt.\n\t\t}\n\t}\n\n\tasync #fail(token: PromiseWithResolvers<TResult>, error: unknown): Promise<void> {\n\t\tif (!this.#claims.has(token)) return\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} catch (cleanup: unknown) {\n\t\t\tthis.#finishEntry(token, { success: false, error: cleanup })\n\t\t\tthrow cleanup\n\t\t}\n\t\tthis.#finishEntry(token, { success: false, error })\n\t}\n\n\tasync #settle(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\toutcome: Result<TResult, unknown>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#finishEntry(token, { success: false, error })\n\t\t\tthrow error\n\t\t}\n\t\tthis.#finishEntry(token, outcome)\n\t}\n\n\t#finishEntry(token: PromiseWithResolvers<TResult>, outcome: Result<TResult, unknown>): void {\n\t\tif (!this.#claims.delete(token)) return\n\t\tconst entry = this.#entries.get(token)\n\t\tconst drain = this.#latchDrain()\n\t\tif (entry === undefined || !this.#settleToken(token, outcome)) {\n\t\t\tif (drain) this.#emitter.emit('drain')\n\t\t\treturn\n\t\t}\n\t\tif (outcome.success) this.#emitter.emit('success', entry.id, outcome.value)\n\t\telse this.#emitter.emit('failure', entry.id, outcome.error)\n\t\tif (drain) this.#emitter.emit('drain')\n\t}\n\n\t#settleToken(token: PromiseWithResolvers<TResult>, outcome: Result<TResult, unknown>): boolean {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || entry.settled) return false\n\t\tentry.settled = true\n\t\tif (outcome.success) token.resolve(outcome.value)\n\t\telse token.reject(outcome.error)\n\t\tif (this.#live.get(entry.id) !== token) this.#entries.delete(token)\n\t\treturn true\n\t}\n\n\t#latchDrain(): boolean {\n\t\tif (this.#drained || this.#claims.size !== 0 || this.#live.size !== 0) return false\n\t\tthis.#drained = true\n\t\treturn true\n\t}\n\n\t#emitDrain(): void {\n\t\tif (this.#latchDrain()) this.#emitter.emit('drain')\n\t}\n\n\tasync #attempt(\n\t\tid: string,\n\t\tinput: TInput,\n\t\ttimeout: number,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Result<TResult>> {\n\t\tconst cancel =\n\t\t\tsignal === undefined ? this.#abort.signal : AbortSignal.any([this.#abort.signal, signal])\n\t\tlet deadline: TimeoutInterface | undefined\n\t\tlet attemptSignal = cancel\n\t\tif (timeout > 0) {\n\t\t\tdeadline = createTimeout({ ms: timeout, signal: cancel })\n\t\t\tdeadline.start()\n\t\t\tattemptSignal = AbortSignal.any([cancel, deadline.signal])\n\t\t}\n\t\ttry {\n\t\t\tconst value = await this.#race(id, input, attemptSignal, deadline)\n\t\t\treturn { success: true, value }\n\t\t} catch (error: unknown) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: isError(error) ? error : new Error(preview(error), { cause: error }),\n\t\t\t}\n\t\t} finally {\n\t\t\tdeadline?.clear()\n\t\t}\n\t}\n\n\t#race(\n\t\tid: string,\n\t\tinput: TInput,\n\t\tsignal: AbortSignal,\n\t\tdeadline: TimeoutInterface | undefined,\n\t): Promise<TResult> {\n\t\tif (signal.aborted) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError(\n\t\t\t\t\tdeadline?.expired === true ? 'queue attempt timed out' : 'queue attempt aborted',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: deadline?.expired === true ? 'timeout' : 'aborted',\n\t\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\t\tcontext: { id },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\tconst cleanup = new AbortController()\n\t\treturn new Promise<TResult>((resolve, reject) => {\n\t\t\tsignal.addEventListener(\n\t\t\t\t'abort',\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew QueueError(\n\t\t\t\t\t\t\tdeadline?.expired === true ? 'queue attempt timed out' : 'queue attempt aborted',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: deadline?.expired === true ? 'timeout' : 'aborted',\n\t\t\t\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\t\t\t\tcontext: { id },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t{ once: true, signal: cleanup.signal },\n\t\t\t)\n\t\t\ttry {\n\t\t\t\tPromise.resolve(this.#handler(input, { id, signal })).then(\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tcleanup.abort()\n\t\t\t\t\t\tresolve(value)\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tcleanup.abort()\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t} catch (error: unknown) {\n\t\t\t\tcleanup.abort()\n\t\t\t\treject(error)\n\t\t\t}\n\t\t})\n\t}\n\n\tasync #finish(tasks: ReadonlyArray<Promise<void>>, message: string): Promise<void> {\n\t\tconst results = await Promise.allSettled(tasks)\n\t\tconst errors: unknown[] = []\n\t\tfor (const result of results) {\n\t\t\tif (result.status === 'rejected' && !errors.includes(result.reason)) {\n\t\t\t\terrors.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (errors.length === 0) return\n\t\tconst error = errors[0]\n\t\tif (errors.length === 1 && isQueueError(error)) throw error\n\t\tthrow new QueueError(message, {\n\t\t\tcode: 'cleanup',\n\t\t\tcause: new AggregateError(errors, message),\n\t\t\tcontext: { operation: 'remove' },\n\t\t})\n\t}\n\n\tasync #settleBarrier(\n\t\tbarrier: PromiseWithResolvers<void>,\n\t\ttasks: ReadonlyArray<Promise<void>>,\n\t\tmessage: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#finish(tasks, message)\n\t\t\tbarrier.resolve()\n\t\t} catch (error: unknown) {\n\t\t\tbarrier.reject(error)\n\t\t}\n\t}\n\n\tasync #settleDestroy(\n\t\tbarrier: PromiseWithResolvers<void>,\n\t\taborting: Promise<void>,\n\t): Promise<void> {\n\t\tlet failure: unknown\n\t\ttry {\n\t\t\tawait aborting\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t}\n\t\ttry {\n\t\t\tawait this.#finish(\n\t\t\t\t[\n\t\t\t\t\t...this.#workers,\n\t\t\t\t\t...this.#admissions.values(),\n\t\t\t\t\t...this.#cleanups.values(),\n\t\t\t\t\t...this.#cleanOrphans(true),\n\t\t\t\t],\n\t\t\t\t'queue destroy cleanup failed',\n\t\t\t)\n\t\t} catch (error: unknown) {\n\t\t\tfailure =\n\t\t\t\tfailure === undefined\n\t\t\t\t\t? error\n\t\t\t\t\t: new QueueError('queue destroy cleanup failed', {\n\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\tcause: new AggregateError([failure, error], 'queue destroy cleanup failed'),\n\t\t\t\t\t\t\tcontext: { operation: 'remove' },\n\t\t\t\t\t\t})\n\t\t} finally {\n\t\t\tthis.#emitter.destroy()\n\t\t}\n\t\tif (failure === undefined) barrier.resolve()\n\t\telse barrier.reject(failure)\n\t}\n}\n","import type { TableInterface } from '@orkestrel/database'\nimport type { QueueStoreInterface, StoredEntry } from '../types.js'\n\n/**\n * Represents the opt-in durable store for a queue's outstanding entries, backed by one table\n * of the `@orkestrel/database` layer — a queue's durable state is a table, so persistence\n * reduces to keyed CRUD over a `TableInterface`.\n *\n * @remarks\n * The store is driver-agnostic: it holds a single {@link TableInterface} whose\n * backend (memory, JSON, SQLite) is chosen by whoever builds it (the factories).\n * `save` upserts an entry by its primary key (`set`), `remove` drops one (`remove`),\n * `load` returns every outstanding entry (`records` with no criteria), and `clear`\n * empties the table. Reads are narrowed through the table's contract, so `load`\n * returns typed {@link StoredEntry}`<TInput>[]` with no cast — the table\n * is created over the `{ id; input; attempts }` column map, which `Infer`s to exactly\n * that row. The store holds only outstanding work (completed entries are `remove`d), so\n * `load` on startup yields precisely the entries to resume.\n *\n * @typeParam TInput - The work input each {@link StoredEntry} carries\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { createMemoryDriver } from '@orkestrel/database'\n * import { createDatabaseQueueStore } from '@orkestrel/queue'\n *\n * const store = createDatabaseQueueStore(stringShape(), createMemoryDriver())\n * await store.save({ id: 'job-1', input: 'https://example.com', attempts: 0 })\n * const outstanding = await store.load() // readonly StoredEntry<string>[]\n * ```\n */\nexport class DatabaseQueueStore<TInput> implements QueueStoreInterface<TInput> {\n\treadonly #table: TableInterface<StoredEntry<TInput>>\n\n\t/**\n\t * Wraps a table as a queue store.\n\t *\n\t * @param table - The {@link TableInterface} holding the outstanding entries — its\n\t * row is a {@link StoredEntry}`<TInput>` (the `{ id; input; attempts }` shape)\n\t */\n\tconstructor(table: TableInterface<StoredEntry<TInput>>) {\n\t\tthis.#table = table\n\t}\n\n\t/** Upserts an entry by its `id` (a re-`save` of an existing `id` overwrites it). */\n\tasync save(entry: StoredEntry<TInput>): Promise<void> {\n\t\tawait this.#table.set(entry)\n\t}\n\n\t/** Drops a finished entry by `id`; absent is a no-op (no throw). */\n\tasync remove(id: string): Promise<void> {\n\t\tawait this.#table.remove(id)\n\t}\n\n\t/** Returns every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<ReadonlyArray<StoredEntry<TInput>>> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empties the store — drops every outstanding entry. */\n\tasync clear(): Promise<void> {\n\t\tawait this.#table.clear()\n\t}\n}\n","import type { ContractInterface, ContractShape, Infer } from '@orkestrel/contract'\nimport type { QueueStoreInterface, StoredEntry } from '../types.js'\nimport { cloneJSONValue, createContract } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isStoredEntry } from '../validators.js'\n\n/**\n * Represents an in-memory store of a queue's outstanding entries — a process-lifetime `Map`\n * owning validated, immutable JSON snapshots.\n *\n * @typeParam TInput - The contract shape for each stored input\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { MemoryQueueStore } from '@orkestrel/queue'\n *\n * const store = new MemoryQueueStore(stringShape())\n * await store.save({ id: 'job-1', input: 'task', attempts: 0 })\n * ```\n */\nexport class MemoryQueueStore<TInput extends ContractShape> implements QueueStoreInterface<\n\tInfer<TInput>\n> {\n\treadonly #contract: ContractInterface<Infer<TInput>>\n\treadonly #entries = new Map<string, StoredEntry<Infer<TInput>>>()\n\n\t/**\n\t * Creates an in-memory queue store.\n\t *\n\t * @param input - Runtime contract for each stored input\n\t */\n\tconstructor(input: TInput) {\n\t\tthis.#contract = createContract(input)\n\t}\n\n\t/** Upserts a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst candidate = { id: entry.id, input: entry.input, attempts: entry.attempts }\n\t\t\tif (!isStoredEntry(candidate)) {\n\t\t\t\tthrow new QueueError('queue store entry is invalid', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcontext: { operation: 'save' },\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst { id, input, attempts } = candidate\n\t\t\tthis.#entries.set(id, this.#snapshot(id, input, attempts, 'save'))\n\t\t\treturn Promise.resolve()\n\t\t} catch (error: unknown) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue store save failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { operation: 'save' },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t}\n\n\t/** Removes an entry; an absent id is a no-op. */\n\tremove(id: string): Promise<void> {\n\t\tthis.#entries.delete(id)\n\t\treturn Promise.resolve()\n\t}\n\n\t/** Returns fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<ReadonlyArray<StoredEntry<Infer<TInput>>>> {\n\t\ttry {\n\t\t\tconst snapshots: Array<StoredEntry<Infer<TInput>>> = []\n\t\t\tfor (const entry of this.#entries.values()) {\n\t\t\t\tconst id = entry.id\n\t\t\t\tconst input = entry.input\n\t\t\t\tconst attempts = entry.attempts\n\t\t\t\tsnapshots.push(this.#snapshot(id, input, attempts, 'load'))\n\t\t\t}\n\t\t\treturn Promise.resolve(snapshots)\n\t\t} catch (error: unknown) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue store load failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { operation: 'load' },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t}\n\n\t/** Removes every outstanding entry. */\n\tclear(): Promise<void> {\n\t\tthis.#entries.clear()\n\t\treturn Promise.resolve()\n\t}\n\n\t#snapshot(\n\t\tid: string,\n\t\tinput: Infer<TInput>,\n\t\tattempts: number,\n\t\toperation: 'save' | 'load',\n\t): StoredEntry<Infer<TInput>> {\n\t\tconst snapshot = cloneJSONValue(input)\n\t\tif (!this.#contract.is(snapshot)) {\n\t\t\tthrow new QueueError('queue store input does not satisfy its contract', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcontext: { id, operation },\n\t\t\t})\n\t\t}\n\t\treturn Object.freeze({ id, input: snapshot, attempts })\n\t}\n}\n","import type { ContractShape, Infer } from '@orkestrel/contract'\nimport type { DriverInterface, TableInterface } from '@orkestrel/database'\nimport type { QueueInterface, QueueOptions, QueueStoreInterface, StoredEntry } from './types.js'\nimport { integerShape, stringShape } from '@orkestrel/contract'\nimport { createDatabase } from '@orkestrel/database'\nimport { Queue } from './Queue.js'\nimport { DatabaseQueueStore } from './stores/DatabaseQueueStore.js'\nimport { MemoryQueueStore } from './stores/MemoryQueueStore.js'\n\n/**\n * Creates a concurrent, cooperative job queue — a bounded-concurrency engine that\n * runs each enqueued input through a handler, with retries and a per-attempt\n * timeout / abort, all over the L1 `Abort` / `Timeout` primitives.\n *\n * @remarks\n * Worker loops park on a wake list when no entry is ready and are woken one-at-a-time\n * by `enqueue` / `resume`, so an idle queue consumes no CPU (no polling). `enqueue`\n * returns a promise that settles when the entry finally completes, fails (after its\n * retries), or is rejected by an abort. A queue-level `abort` never retries; the\n * lifecycle (`start` / `stop` / `pause` / `resume` / `abort` / `clear` / `destroy`)\n * follows the fixed lifecycle vocabulary. The queue is observable: a typed `emitter` surfaces\n * `enqueue` / `start` / `retry` / `success` / `failure` / `abort` / `drain`.\n *\n * @typeParam TInput - The work input each entry carries\n * @typeParam TResult - The value the handler resolves for an entry\n * @param options - The `handler` plus optional `concurrency`, `retries`, and a default\n * per-attempt `timeout` in milliseconds. Default: `concurrency` `1`, `retries` `0`,\n * `timeout` `0`.\n * @returns A working {@link QueueInterface}\n *\n * @example Create a queue\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * // Ordered (concurrency defaults to 1): each entry runs to completion before the next.\n * const queue = createQueue<Job, Output>({ handler: (job) => run(job) })\n *\n * const output = await queue.enqueue(job)\n *\n * // Bounded, retried, and time-boxed: four in flight, two extra attempts, 5s per attempt.\n * const fetches = createQueue<string, number>({\n * \thandler: async (url, { signal }) => (await fetch(url, { signal })).status,\n * \tconcurrency: 4,\n * \tretries: 2,\n * \ttimeout: 5_000,\n * })\n *\n * const status = await fetches.enqueue('https://example.com')\n * ```\n */\nexport function createQueue<TInput, TResult>(\n\toptions: QueueOptions<TInput, TResult>,\n): QueueInterface<TInput, TResult> {\n\treturn new Queue(options)\n}\n\n/**\n * Creates a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries, across a memory, JSON, or\n * SQLite driver.\n *\n * @remarks\n * Builds a one-table database (`entries`, keyed by `id`) over the supplied driver, with\n * the fixed `{ id; input; attempts }` column map — `input` is the caller's own shape,\n * so the stored entry's payload is validated and typed by it. Reads narrow through that\n * contract, so the store's `load` returns typed `StoredEntry<Infer<TInput>>[]` with no\n * cast. Pass `createMemoryDriver()` for an ephemeral store, a server `createJSONDriver` /\n * `createSQLiteDriver` for a persistent one — the durability is the driver's job, the\n * store engine is shared. The `input` shape must be JSON-serializable to survive a JSON\n * or SQLite driver.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param input - The {@link ContractShape} for the work payload (used directly as the\n * `input` column)\n * @param driver - The storage backend the entries persist to\n * @returns A {@link QueueStoreInterface} over the driver, typed by `input`\n *\n * @example\n * ```ts\n * import { objectShape, stringShape } from '@orkestrel/contract'\n * import { createMemoryDriver } from '@orkestrel/database'\n * import { createDatabaseQueueStore } from '@orkestrel/queue'\n *\n * const store = createDatabaseQueueStore(\n * \tobjectShape({ url: stringShape(), label: stringShape() }),\n * \tcreateMemoryDriver(),\n * )\n * await store.save({ id: 'job-1', input: { url: 'https://example.com', label: 'home' }, attempts: 0 })\n * ```\n */\nexport function createDatabaseQueueStore<TInput extends ContractShape>(\n\tinput: TInput,\n\tdriver: DriverInterface,\n): QueueStoreInterface<Infer<TInput>>\n// The preceding public signature types the store by `Infer<TInput>`. The implementation\n// runs on the broad `ContractShape`, so the `entries` row is built and the table read\n// once — not re-instantiated per concrete `TInput`. (A generic `TInput` member can't be\n// reduced by the contract's object inference, which would also trip TS's\n// instantiation-depth guard; the broad body sidesteps both, and every call site still\n// sees the precise `Infer<TInput>` from the overload.) No cast: the contract-narrowed\n// row satisfies `StoredEntry<unknown>` structurally.\nexport function createDatabaseQueueStore(\n\tinput: ContractShape,\n\tdriver: DriverInterface,\n): QueueStoreInterface<unknown> {\n\tconst columns = {\n\t\tid: stringShape(),\n\t\tinput,\n\t\tattempts: integerShape({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n\t}\n\tconst database = createDatabase({ driver, tables: { entries: columns } })\n\tconst table: TableInterface<StoredEntry<unknown>> = database.table('entries')\n\treturn new DatabaseQueueStore(table)\n}\n\n/**\n * Creates an in-memory {@link MemoryQueueStore} over a plain `Map` — the zero-plumbing\n * {@link QueueStoreInterface} a queue takes when its outstanding entries need not outlive\n * the process, and the twin of {@link DatabaseQueueStore}.\n *\n * @remarks\n * The entries live in a process-lifetime `Map` and are gone when the process exits. The\n * supplied shape is compiled and enforced for every save. Exact JSON inputs are cloned\n * into deeply frozen owned snapshots, and each load returns fresh snapshots, so neither\n * caller mutation nor a returned object can alias stored state. For durability across\n * restarts, build the store over a persistent driver with\n * {@link createDatabaseQueueStore}.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param input - The runtime {@link ContractShape} for the work payload\n * @returns A validated memory-backed {@link QueueStoreInterface}, typed by `input`\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { createMemoryQueueStore } from '@orkestrel/queue'\n *\n * const store = createMemoryQueueStore(stringShape())\n * await store.save({ id: 'job-1', input: 'task', attempts: 0 })\n * ```\n */\nexport function createMemoryQueueStore<TInput extends ContractShape>(\n\tinput: TInput,\n): QueueStoreInterface<Infer<TInput>> {\n\treturn new MemoryQueueStore(input)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,IAAa,aAAb,cAAgC,MAAM;CACrC,OAAyB;CACzB;CACA;;;;;;;CAQA,YAAY,SAAiB,SAA4B;EACxD,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,CAAC;EAC1D,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ,YAAY,KAAA,IAAY,KAAA,IAAY,OAAO,OAAO,EAAE,GAAG,QAAQ,QAAQ,CAAC;CAChG;AACD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAAa,OAAqC;CACjE,QAAA,GAAOA,oBAAAA,WAAAA,CAAW,OAAO,UAAU;AACpC;;;;;;;;;;;;;;;AClCA,SAAgB,mBAAmB,O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AAO;GAAE;GAAI,OAAO;GAAU;EAAS,CAAC;CACvD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DA,SAAgB,YACf,SACkC;CAClC,OAAO,IAAI,MAAM,OAAO;AACzB;AA+CA,SAAgB,yBACf,OACA,QAC+B;CAC/B,MAAM,UAAU;EACf,KAAA,GAAIC,oBAAAA,YAAAA,CAAY;EAChB;EACA,WAAA,GAAUC,oBAAAA,aAAAA,CAAa;GAAE,KAAK;GAAG,KAAK,OAAO;EAAiB,CAAC;CAChE;CAGA,OAAO,IAAI,oBADL,GADWC,oBAAAA,eAAAA,CAAe;EAAE;EAAQ,QAAQ,EAAE,SAAS,QAAQ;CAAE,CACnB,CAAA,CAAS,MAAM,SACrC,CAAK;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,uBACf,OACqC;CACrC,OAAO,IAAI,iBAAiB,KAAK;AAClC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["holds","isError","INTRINSICS","isObject","isFunction","isString","isInteger","isFiniteNumber","MAX_TIMEOUT_MS","holds","isRecord","isString","createAbort","Emitter","isString","isError","createTimeout","preview","createContract","cloneJSONValue","stringShape","integerShape","createDatabase"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/QueueEntry.ts","../../../src/core/Queue.ts","../../../src/core/stores/DatabaseQueueStore.ts","../../../src/core/stores/MemoryQueueStore.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { QueueErrorContext, QueueErrorOptions } from './types.js'\nimport { holds, INTRINSICS, isError, isFunction, isObject, isString } from '@orkestrel/contract'\n\n/**\n * Represents a queue failure carrying a lowercase machine-readable `code`, optional\n * structured context, and an optional cause.\n *\n * @example\n * ```ts\n * new QueueError('duplicate id', { code: 'duplicate', context: { id: 'job-1' } })\n * ```\n */\nexport class QueueError extends Error {\n\toverride readonly name = 'QueueError'\n\treadonly code\n\treadonly context: QueueErrorContext | undefined\n\n\t/**\n\t * Creates a queue error.\n\t *\n\t * @param message - Human-readable failure description\n\t * @param options - Machine-readable category, optional context, and optional cause\n\t */\n\tconstructor(message: string, options: QueueErrorOptions) {\n\t\tconst cause = options.cause\n\t\tsuper(message, cause === undefined ? undefined : { cause })\n\t\tINTRINSICS.define(this, Symbol.for('@orkestrel/queue.QueueError'), { value: this })\n\t\tthis.code = options.code\n\t\tthis.context = options.context === undefined ? undefined : Object.freeze({ ...options.context })\n\t}\n}\n\n/**\n * Determines whether an unknown value is a {@link QueueError}, staying total for a hostile\n * value.\n *\n * @remarks\n * Recognizes the shared brand and declared members across package copies, including subclasses.\n * Refuses a transparent proxy because its brand holds the target's identity.\n *\n * @param value - The value to inspect\n * @returns True if a branded error or subclass has valid members; false otherwise.\n *\n * @example\n * ```ts\n * try {\n * \tawait queue.clear()\n * } catch (error) {\n * \tif (isQueueError(error) && error.code === 'cleanup') report(error.context)\n * }\n * ```\n */\nexport function isQueueError(value: unknown): value is QueueError {\n\treturn holds(() => {\n\t\tif (!isError(value) || INTRINSICS.prototype(value) === Error.prototype) return false\n\t\tconst brand = INTRINSICS.describe(value, Symbol.for('@orkestrel/queue.QueueError'))\n\t\tif (brand === undefined || brand.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tif (\n\t\t\tcode !== 'invalid' &&\n\t\t\tcode !== 'duplicate' &&\n\t\t\tcode !== 'stopped' &&\n\t\t\tcode !== 'aborted' &&\n\t\t\tcode !== 'destroyed' &&\n\t\t\tcode !== 'cleared' &&\n\t\t\tcode !== 'timeout' &&\n\t\t\tcode !== 'store' &&\n\t\t\tcode !== 'cleanup'\n\t\t)\n\t\t\treturn false\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\tif (context === undefined) return true\n\t\tif (!isObject(context) && !isFunction(context)) return false\n\t\tconst id: unknown = INTRINSICS.reflect.read(context, 'id')\n\t\tif (id !== undefined && !isString(id)) return false\n\t\tconst option: unknown = INTRINSICS.reflect.read(context, 'option')\n\t\tif (\n\t\t\toption !== undefined &&\n\t\t\toption !== 'id' &&\n\t\t\toption !== 'concurrency' &&\n\t\t\toption !== 'retries' &&\n\t\t\toption !== 'timeout' &&\n\t\t\toption !== 'signal'\n\t\t)\n\t\t\treturn false\n\t\tconst operation: unknown = INTRINSICS.reflect.read(context, 'operation')\n\t\treturn (\n\t\t\toperation === undefined ||\n\t\t\toperation === 'save' ||\n\t\t\toperation === 'remove' ||\n\t\t\toperation === 'load' ||\n\t\t\toperation === 'clear'\n\t\t)\n\t})\n}\n","import type { StoredEntry } from './types.js'\nimport { holds, isFiniteNumber, isInteger, isRecord, isString } from '@orkestrel/contract'\nimport { MAX_TIMEOUT_MS } from '@orkestrel/timeout'\n\n/**\n * Determines whether a value is a valid queue concurrency — a positive safe integer.\n *\n * @param value - Value to inspect\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isQueueConcurrency(4) // true\n * isQueueConcurrency(0) // false\n * ```\n */\nexport function isQueueConcurrency(value: unknown): value is number {\n\treturn isInteger(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Determines whether a value is a valid queue retry count — a nonnegative safe integer.\n *\n * @param value - Value to inspect\n * @returns True if the value is a nonnegative safe integer; false otherwise\n *\n * @example\n * ```ts\n * isQueueRetries(2) // true\n * isQueueRetries(-1) // false\n * ```\n */\nexport function isQueueRetries(value: unknown): value is number {\n\treturn isInteger(value) && Number.isSafeInteger(value) && value >= 0\n}\n\n/**\n * Determines whether a value is a valid queue timeout — an integer count of milliseconds\n * inside the native timer range.\n *\n * @param value - Value to inspect\n * @returns True if the value is an integer within the native timer range,\n * inclusive; false otherwise\n *\n * @example\n * ```ts\n * isQueueTimeout(500) // true\n * isQueueTimeout(2_147_483_648) // false\n * ```\n */\nexport function isQueueTimeout(value: unknown): value is number {\n\treturn isFiniteNumber(value) && isInteger(value) && value >= 0 && value <= MAX_TIMEOUT_MS\n}\n\n/**\n * Determines whether a value is a native abort signal usable by the queue, testing the\n * native brand rather than the shape.\n *\n * @param value - Value to inspect\n * @returns True if the value carries the native `AbortSignal` internal slot; false otherwise\n *\n * @example\n * ```ts\n * isQueueSignal(new AbortController().signal) // true\n * isQueueSignal({}) // false\n * ```\n */\nexport function isQueueSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n\n/**\n * Determines whether a value is a valid stored queue entry — a record holding a string\n * `id`, an `input`, and a nonnegative safe-integer `attempts`.\n *\n * @remarks\n * The single test for what a {@link StoredEntry} is, shared by the queue's `restore`\n * boundary and the memory store's `save` boundary. `input` carries the caller's own\n * payload type, so only its presence is checked.\n *\n * @param value - Value to inspect\n * @returns True if the value is a record holding a string `id`, an `input` member, and a\n * nonnegative safe-integer `attempts`; false otherwise\n *\n * @example\n * ```ts\n * isStoredEntry({ id: 'job-1', input: 'task', attempts: 0 }) // true\n * isStoredEntry({ id: 'job-1', input: 'task', attempts: -1 }) // false\n * ```\n */\nexport function isStoredEntry(value: unknown): value is StoredEntry<unknown> {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) && isString(value.id) && 'input' in value && isQueueRetries(value.attempts),\n\t)\n}\n","import type { Guard } from '@orkestrel/contract'\nimport type { QueueEntryOptions, QueueOption } from './types.js'\nimport { QueueError } from './errors.js'\n\n/**\n * Reads one named option from a caller-supplied entry options object exactly once,\n * containing a throwing getter as a coded failure.\n *\n * @remarks\n * An absent options object reads nothing and yields `undefined`.\n *\n * @param options - The caller's own entry options, or `undefined`\n * @param option - The option key to read\n * @param message - The failure description the thrown error carries\n * @returns The value the property held, or `undefined` when no options object was supplied\n * @throws {QueueError} Thrown when reading the property throws, coded `invalid` with the\n * option in its context.\n *\n * @example\n * ```ts\n * readOption({ retries: 2 }, 'retries', 'queue retries could not be read') // 2\n * ```\n */\nexport function readOption(\n\toptions: QueueEntryOptions | undefined,\n\toption: keyof QueueEntryOptions,\n\tmessage: string,\n): unknown {\n\ttry {\n\t\treturn options?.[option]\n\t} catch (error: unknown) {\n\t\tthrow new QueueError(message, {\n\t\t\tcode: 'invalid',\n\t\t\tcause: error,\n\t\t\tcontext: { option },\n\t\t})\n\t}\n}\n\n/**\n * Validates one already-read queue option against its guard, and throws the coded invalid\n * failure carrying the option and the refused value when the guard refuses it.\n *\n * @param value - The option value to check\n * @param guard - The total guard the value must satisfy\n * @param option - The option key the failure context reports\n * @param message - The failure description the thrown error carries\n * @returns The same value, narrowed by the guard\n * @throws {QueueError} Thrown when the guard refuses the value, coded `invalid` with the\n * option and the refused value in its context.\n *\n * @example\n * ```ts\n * validateOption(4, isQueueConcurrency, 'concurrency', 'queue concurrency must be positive') // 4\n * ```\n */\nexport function validateOption<TValue>(\n\tvalue: unknown,\n\tguard: Guard<TValue>,\n\toption: QueueOption,\n\tmessage: string,\n): TValue {\n\tif (guard(value)) return value\n\tthrow new QueueError(message, {\n\t\tcode: 'invalid',\n\t\tcontext: { option, value },\n\t})\n}\n","import type { QueueEntryOptions } from './types.js'\n\n/** Holds one queue reservation's execution and settlement state. */\nexport class QueueEntry<TInput> {\n\treadonly id: string\n\treadonly input: TInput\n\treadonly options: QueueEntryOptions | undefined\n\t#attempts: number\n\t#settled = false\n\n\tconstructor(id: string, input: TInput, options: QueueEntryOptions | undefined, attempts: number) {\n\t\tthis.id = id\n\t\tthis.input = input\n\t\tthis.options = options\n\t\tthis.#attempts = attempts\n\t}\n\n\tget attempts(): number {\n\t\treturn this.#attempts\n\t}\n\n\tget settled(): boolean {\n\t\treturn this.#settled\n\t}\n\n\tcomplete(): number {\n\t\tthis.#attempts += 1\n\t\treturn this.#attempts\n\t}\n\n\tsettle(): void {\n\t\tthis.#settled = true\n\t}\n}\n","import type { AbortInterface } from '@orkestrel/abort'\nimport type { Result } from '@orkestrel/contract'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type { TimeoutInterface } from '@orkestrel/timeout'\nimport type {\n\tQueueEntryOptions,\n\tQueueEventMap,\n\tQueueHandler,\n\tQueueInterface,\n\tQueueOptions,\n\tQueueStoreInterface,\n\tStoredEntry,\n} from './types.js'\nimport { createAbort } from '@orkestrel/abort'\nimport { isError, isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { readOption, validateOption } from './helpers.js'\nimport { QueueEntry } from './QueueEntry.js'\nimport {\n\tisQueueConcurrency,\n\tisQueueRetries,\n\tisQueueSignal,\n\tisQueueTimeout,\n\tisStoredEntry,\n} from './validators.js'\n\n/**\n * Represents a concurrent, cooperative FIFO job queue — a wake-park worker loop with\n * retries, a per-attempt timeout, abort, and optional outstanding-work persistence.\n *\n * @typeParam TInput - The work input each entry carries\n * @typeParam TResult - The value each entry resolves\n *\n * @example\n * ```ts\n * const queue = new Queue<number, number>({ handler: (input) => input * 2 })\n * const result = await queue.enqueue(21)\n * ```\n */\nexport class Queue<TInput, TResult> implements QueueInterface<TInput, TResult> {\n\treadonly #handler: QueueHandler<TInput, TResult>\n\treadonly #concurrency: number\n\treadonly #retries: number\n\treadonly #timeout: number\n\treadonly #store: QueueStoreInterface<TInput> | undefined\n\treadonly #abort: AbortInterface = createAbort()\n\treadonly #emitter: Emitter<QueueEventMap<TResult>>\n\treadonly #entries = new Map<PromiseWithResolvers<TResult>, QueueEntry<TInput>>()\n\treadonly #live = new Map<string, PromiseWithResolvers<TResult>>()\n\treadonly #pending: Array<PromiseWithResolvers<TResult>> = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: Array<() => void> = []\n\treadonly #workers = new Set<Promise<void>>()\n\treadonly #admissions = new Map<PromiseWithResolvers<TResult>, Promise<void>>()\n\treadonly #orphans = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #cleanups = new Map<PromiseWithResolvers<TResult>, Promise<void>>()\n\t#admission: Promise<void> = Promise.resolve()\n\t#stopPromise: Promise<void> | undefined\n\t#abortPromise: Promise<void> | undefined\n\t#destroyPromise: Promise<void> | undefined\n\t#generation = 0\n\t#paused = false\n\t#stopped = false\n\t#drained = true\n\n\t/**\n\t * Creates a queue.\n\t *\n\t * @param options - Handler, validated execution limits, persistence, and observation hooks\n\t */\n\tconstructor(options: QueueOptions<TInput, TResult>) {\n\t\tconst configuredConcurrency = options.concurrency\n\t\tconst concurrency = validateOption(\n\t\t\tconfiguredConcurrency === undefined ? 1 : configuredConcurrency,\n\t\t\tisQueueConcurrency,\n\t\t\t'concurrency',\n\t\t\t'queue concurrency must be a positive safe integer',\n\t\t)\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = validateOption(\n\t\t\tconfiguredRetries === undefined ? 0 : configuredRetries,\n\t\t\tisQueueRetries,\n\t\t\t'retries',\n\t\t\t'queue retries must be a nonnegative safe integer',\n\t\t)\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = validateOption(\n\t\t\tconfiguredTimeout === undefined ? 0 : configuredTimeout,\n\t\t\tisQueueTimeout,\n\t\t\t'timeout',\n\t\t\t'queue timeout must be within the native timer range',\n\t\t)\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#handler = options.handler\n\t\tthis.#concurrency = concurrency\n\t\tthis.#retries = retries\n\t\tthis.#timeout = timeout\n\t\tthis.#store = options.store\n\t\tthis.#emitter = new Emitter<QueueEventMap<TResult>>({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\tget emitter(): EmitterInterface<QueueEventMap<TResult>> {\n\t\treturn this.#emitter\n\t}\n\n\tget count(): number {\n\t\treturn this.#live.size\n\t}\n\n\tget active(): number {\n\t\treturn this.#claims.size\n\t}\n\n\tget paused(): boolean {\n\t\treturn this.#paused\n\t}\n\n\tget stopped(): boolean {\n\t\treturn this.#stopped || this.#abortPromise !== undefined\n\t}\n\n\t/**\n\t * Reserves and submits one FIFO entry.\n\t *\n\t * @param input - Handler input\n\t * @param options - Optional id, retry/timeout overrides, and entry abort signal\n\t * @returns The entry's settle-once execution promise\n\t * @throws {QueueError} Thrown synchronously when an option is inaccessible or invalid.\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tconst rawId = readOption(options, 'id', 'queue entry id could not be read')\n\t\tconst supplied =\n\t\t\trawId === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(rawId, isString, 'id', 'queue entry id must be a string')\n\t\tconst rawRetries = readOption(options, 'retries', 'queue retries could not be read')\n\t\tconst retries =\n\t\t\trawRetries === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(\n\t\t\t\t\t\trawRetries,\n\t\t\t\t\t\tisQueueRetries,\n\t\t\t\t\t\t'retries',\n\t\t\t\t\t\t'queue retries must be a nonnegative safe integer',\n\t\t\t\t\t)\n\t\tconst rawTimeout = readOption(options, 'timeout', 'queue timeout could not be read')\n\t\tconst timeout =\n\t\t\trawTimeout === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(\n\t\t\t\t\t\trawTimeout,\n\t\t\t\t\t\tisQueueTimeout,\n\t\t\t\t\t\t'timeout',\n\t\t\t\t\t\t'queue timeout must be within the native timer range',\n\t\t\t\t\t)\n\t\tconst rawSignal = readOption(options, 'signal', 'queue signal could not be read')\n\t\tconst signal =\n\t\t\trawSignal === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateOption(rawSignal, isQueueSignal, 'signal', 'queue signal must be an AbortSignal')\n\t\tconst normalized: QueueEntryOptions | undefined =\n\t\t\toptions === undefined\n\t\t\t\t? undefined\n\t\t\t\t: Object.freeze({\n\t\t\t\t\t\t...(supplied === undefined ? {} : { id: supplied }),\n\t\t\t\t\t\t...(retries === undefined ? {} : { retries }),\n\t\t\t\t\t\t...(timeout === undefined ? {} : { timeout }),\n\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t})\n\t\tif (this.#destroyPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#abortPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is aborted', { code: 'aborted' }))\n\t\t}\n\t\tif (this.#stopped) {\n\t\t\treturn Promise.reject(new QueueError('queue is stopped', { code: 'stopped' }))\n\t\t}\n\t\tconst id = supplied ?? crypto.randomUUID()\n\t\tif (this.#live.has(id)) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue entry id is already live', {\n\t\t\t\t\tcode: 'duplicate',\n\t\t\t\t\tcontext: { id },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\tconst token = this.#reserve(id, input, normalized, 0)\n\t\tif (this.#store === undefined) this.#accept(token)\n\t\telse this.#schedule(token)\n\t\treturn token.promise\n\t}\n\n\t/**\n\t * Loads and accepts every outstanding stored entry from the current lifecycle generation.\n\t *\n\t * @returns A promise that settles after every loaded entry is reserved and accepted\n\t * @throws {QueueError} Thrown when the store's load fails or returns a malformed entry.\n\t */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyPromise !== undefined) return\n\t\tconst generation = this.#generation\n\t\tconst entries = await this.#load(this.#store)\n\t\tif (entries === undefined) {\n\t\t\tthrow new QueueError('queue store returned an invalid entry', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcontext: { operation: 'load' },\n\t\t\t})\n\t\t}\n\t\tif (generation !== this.#generation || this.stopped || this.#destroyPromise !== undefined)\n\t\t\treturn\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyPromise !== undefined)\n\t\t\t\treturn\n\t\t\tif (this.#live.has(stored.id)) continue\n\t\t\tconst token = this.#reserve(stored.id, stored.input, undefined, stored.attempts)\n\t\t\tthis.#accept(token)\n\t\t\tvoid token.promise.catch(() => {})\n\t\t}\n\t}\n\n\tasync #load(\n\t\tstore: QueueStoreInterface<TInput>,\n\t): Promise<ReadonlyArray<StoredEntry<TInput>> | undefined> {\n\t\ttry {\n\t\t\tconst loaded = await store.load()\n\t\t\tconst entries = [...this.#snapshot(loaded)]\n\t\t\treturn entries.some((entry) => entry === undefined)\n\t\t\t\t? undefined\n\t\t\t\t: entries.filter((entry) => entry !== undefined)\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue store load failed', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { operation: 'load' },\n\t\t\t})\n\t\t}\n\t}\n\n\t*#snapshot(loaded: Iterable<StoredEntry<TInput>>): Generator<StoredEntry<TInput> | undefined> {\n\t\tfor (const stored of loaded) {\n\t\t\tconst candidate = { id: stored.id, input: stored.input, attempts: stored.attempts }\n\t\t\tif (!isStoredEntry(candidate)) {\n\t\t\t\tyield undefined\n\t\t\t\treturn\n\t\t\t}\n\t\t\tyield Object.freeze(candidate)\n\t\t}\n\t}\n\n\t/** Begins or restarts worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#abortPromise !== undefined || this.#destroyPromise !== undefined) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/**\n\t * Rejects non-active work and awaits current-loop and durable cleanup quiescence.\n\t *\n\t * @returns The stable stop barrier\n\t */\n\tstop(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) return this.#destroyPromise\n\t\tif (this.#abortPromise !== undefined) return this.#abortPromise\n\t\tif (this.#stopped && this.#stopPromise !== undefined) return this.#stopPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#stopPromise = barrier.promise\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst existing = [...this.#cleanups.values()]\n\t\tconst cleanup = [\n\t\t\t...this.#drain(new QueueError('queue is stopped', { code: 'stopped' })),\n\t\t\t...this.#cleanOrphans(true),\n\t\t]\n\t\tconst tasks = [...this.#workers, ...this.#admissions.values(), ...existing, ...cleanup]\n\t\tthis.#wakeAll()\n\t\tvoid this.#settleBarrier(barrier, tasks, 'queue stop cleanup failed')\n\t\treturn barrier.promise\n\t}\n\n\t/** Suspends new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyPromise !== undefined) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continues execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyPromise !== undefined) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancels the queue and awaits owned cleanup.\n\t *\n\t * @param reason - Optional cause carried by the coded abort error\n\t * @returns The stable abort barrier\n\t */\n\tabort(reason?: unknown): Promise<void> {\n\t\tif (this.#abortPromise !== undefined) return this.#abortPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#abortPromise = barrier.promise\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(isError(reason) ? reason.message : 'queue is aborted', {\n\t\t\tcode: 'aborted',\n\t\t\t...(reason === undefined ? {} : { cause: reason }),\n\t\t})\n\t\tthis.#abort.abort(error)\n\t\tconst existing = [...this.#cleanups.values()]\n\t\tconst cleanup = [...this.#drain(error), ...this.#cleanOrphans(true)]\n\t\tconst tasks = [...this.#workers, ...this.#admissions.values(), ...existing, ...cleanup]\n\t\tthis.#wakeAll()\n\t\tthis.#emitter.emit('abort', error)\n\t\tvoid this.#settleBarrier(barrier, tasks, 'queue abort cleanup failed')\n\t\treturn barrier.promise\n\t}\n\n\t/**\n\t * Rejects non-active work and awaits its durable cleanup.\n\t *\n\t * @returns A promise that settles after every affected removal completes\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: Array<Promise<void>> = []\n\t\tfor (const [token, cleanup] of this.#cleanups) {\n\t\t\tif (!this.#claims.has(token)) existing.push(cleanup)\n\t\t}\n\t\tconst cleanup = [\n\t\t\t...this.#drain(new QueueError('queue is cleared', { code: 'cleared' })),\n\t\t\t...this.#cleanOrphans(false),\n\t\t]\n\t\treturn this.#finish(\n\t\t\t[...this.#admissions.values(), ...existing, ...cleanup],\n\t\t\t'queue clear cleanup failed',\n\t\t)\n\t}\n\n\t/**\n\t * Tears down once, destroying the emitter only after cleanup finishes.\n\t *\n\t * @returns The stable destroy barrier\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#destroyPromise !== undefined) return this.#destroyPromise\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#destroyPromise = barrier.promise\n\t\tconst aborting = this.abort(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\tvoid this.#settleDestroy(barrier, aborting)\n\t\treturn barrier.promise\n\t}\n\n\t#reserve(\n\t\tid: string,\n\t\tinput: TInput,\n\t\toptions: QueueEntryOptions | undefined,\n\t\tattempts: number,\n\t): PromiseWithResolvers<TResult> {\n\t\tconst token = Promise.withResolvers<TResult>()\n\t\tthis.#entries.set(token, new QueueEntry(id, input, options, attempts))\n\t\tthis.#live.set(id, token)\n\t\tthis.#drained = false\n\t\treturn token\n\t}\n\n\t#schedule(token: PromiseWithResolvers<TResult>): void {\n\t\tconst task = this.#admission.then(() => this.#admit(token))\n\t\tthis.#admissions.set(token, task)\n\t\tthis.#admission = task.catch(() => {})\n\t\tvoid task.finally(() => this.#admissions.delete(token)).catch(() => {})\n\t}\n\n\tasync #admit(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || this.#store === undefined) return\n\t\ttry {\n\t\t\tawait this.#store.save({ id: entry.id, input: entry.input, attempts: entry.attempts })\n\t\t} catch (error: unknown) {\n\t\t\ttry {\n\t\t\t\tawait this.#cleanup(token)\n\t\t\t} catch (cleanup: unknown) {\n\t\t\t\tthis.#settleToken(token, { success: false, error: cleanup })\n\t\t\t\tthis.#emitDrain()\n\t\t\t\tthrow cleanup\n\t\t\t}\n\t\t\tthis.#settleToken(token, {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: new QueueError(isError(error) ? error.message : 'queue admission save failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t}),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tentry.settled ||\n\t\t\tthis.#abortPromise !== undefined ||\n\t\t\tthis.#destroyPromise !== undefined ||\n\t\t\tthis.#stopped\n\t\t) {\n\t\t\tawait this.#discard(token)\n\t\t\treturn\n\t\t}\n\t\tthis.#accept(token)\n\t}\n\n\t#accept(token: PromiseWithResolvers<TResult>): void {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return\n\t\tthis.#pending.push(token)\n\t\tthis.#emitter.emit('enqueue', entry.id)\n\t\tthis.#spawn()\n\t\tthis.#wake()\n\t}\n\n\t#spawn(): void {\n\t\tif (this.#stopped || this.#abortPromise !== undefined || this.#destroyPromise !== undefined)\n\t\t\treturn\n\t\tconst demand = Math.min(this.#concurrency, this.#claims.size + this.#pending.length)\n\t\twhile (this.#workers.size < demand) {\n\t\t\tconst generation = this.#generation\n\t\t\tconst worker = this.#worker(generation)\n\t\t\tthis.#workers.add(worker)\n\t\t\tvoid worker\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.#workers.delete(worker)\n\t\t\t\t\tthis.#spawn()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\t}\n\n\tasync #worker(generation: number): Promise<void> {\n\t\twhile (generation === this.#generation) {\n\t\t\tconst token = await this.#next(generation)\n\t\t\tif (token === undefined) return\n\t\t\ttry {\n\t\t\t\tawait this.#run(token)\n\t\t\t} catch (error: unknown) {\n\t\t\t\tawait this.#fail(token, error)\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\t#next(generation: number): Promise<PromiseWithResolvers<TResult> | undefined> {\n\t\treturn new Promise((resolve) => this.#take(generation, resolve))\n\t}\n\n\t#take(\n\t\tgeneration: number,\n\t\tresolve: (token: PromiseWithResolvers<TResult> | undefined) => void,\n\t): void {\n\t\tif (\n\t\t\tgeneration !== this.#generation ||\n\t\t\tthis.#stopped ||\n\t\t\tthis.#abortPromise !== undefined ||\n\t\t\tthis.#destroyPromise !== undefined\n\t\t) {\n\t\t\tresolve(undefined)\n\t\t\treturn\n\t\t}\n\t\tif (this.#paused || this.#pending.length === 0) {\n\t\t\tthis.#wakes.push(() => this.#take(generation, resolve))\n\t\t\treturn\n\t\t}\n\t\tconst token = this.#pending.shift()\n\t\tif (token === undefined) {\n\t\t\tthis.#wakes.push(() => this.#take(generation, resolve))\n\t\t\treturn\n\t\t}\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) {\n\t\t\tthis.#take(generation, resolve)\n\t\t\treturn\n\t\t}\n\t\tthis.#claims.add(token)\n\t\tresolve(token)\n\t}\n\n\t#wake(): void {\n\t\tconst resolver = this.#wakes.shift()\n\t\tif (resolver !== undefined) resolver()\n\t}\n\n\t#wakeAll(): void {\n\t\tconst resolvers = this.#wakes.splice(0)\n\t\tfor (const resolver of resolvers) resolver()\n\t}\n\n\t#drain(error: QueueError): ReadonlyArray<Promise<void>> {\n\t\tfor (const token of this.#admissions.keys()) this.#settleToken(token, { success: false, error })\n\t\tconst tokens = this.#pending.splice(0)\n\t\tconst cleanup: Array<Promise<void>> = []\n\t\tfor (const token of tokens) {\n\t\t\tthis.#settleToken(token, { success: false, error })\n\t\t\tcleanup.push(this.#discard(token))\n\t\t}\n\t\treturn cleanup\n\t}\n\n\t#cleanOrphans(claimed: boolean): ReadonlyArray<Promise<void>> {\n\t\tconst cleanup: Array<Promise<void>> = []\n\t\tfor (const token of this.#orphans) {\n\t\t\tif (claimed || !this.#claims.has(token)) cleanup.push(this.#discard(token))\n\t\t}\n\t\treturn cleanup\n\t}\n\n\tasync #discard(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} finally {\n\t\t\tthis.#emitDrain()\n\t\t}\n\t}\n\n\t#cleanup(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst current = this.#cleanups.get(token)\n\t\tif (current !== undefined) return current\n\t\tconst barrier = Promise.withResolvers<void>()\n\t\tthis.#cleanups.set(token, barrier.promise)\n\t\tvoid this.#clean(token, barrier)\n\t\treturn barrier.promise\n\t}\n\n\tasync #clean(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\tbarrier: PromiseWithResolvers<void>,\n\t): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) {\n\t\t\tbarrier.resolve()\n\t\t\tthis.#cleanups.delete(token)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tif (this.#store !== undefined) await this.#store.remove(entry.id)\n\t\t\tthis.#release(token)\n\t\t\tbarrier.resolve()\n\t\t} catch (error: unknown) {\n\t\t\tif (this.#live.get(entry.id) === token) this.#orphans.add(token)\n\t\t\tbarrier.reject(\n\t\t\t\tnew QueueError('queue entry cleanup failed', {\n\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { id: entry.id, operation: 'remove' },\n\t\t\t\t}),\n\t\t\t)\n\t\t} finally {\n\t\t\tif (this.#cleanups.get(token) === barrier.promise) this.#cleanups.delete(token)\n\t\t}\n\t}\n\n\t#release(token: PromiseWithResolvers<TResult>): void {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || this.#live.get(entry.id) !== token) return\n\t\tthis.#live.delete(entry.id)\n\t\tthis.#orphans.delete(token)\n\t\tif (entry.settled) this.#entries.delete(token)\n\t}\n\n\tasync #run(token: PromiseWithResolvers<TResult>): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return\n\t\tconst retries = entry.options?.retries ?? this.#retries\n\t\tconst timeout = entry.options?.timeout ?? this.#timeout\n\t\tconst signal = entry.options?.signal\n\t\tthis.#emitter.emit('start', entry.id)\n\t\twhile (true) {\n\t\t\tif (await this.#interrupt(token, signal)) return\n\t\t\tconst outcome = await this.#attempt(entry.id, entry.input, timeout, signal)\n\t\t\tconst completed = entry.complete()\n\t\t\tif (outcome.success) {\n\t\t\t\tawait this.#settle(token, outcome)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (await this.#interrupt(token, signal)) return\n\t\t\tif (completed > retries) {\n\t\t\t\tawait this.#settle(token, outcome)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait this.#saveAttempt(token, completed)\n\t\t\tthis.#emitter.emit('retry', entry.id, completed)\n\t\t}\n\t}\n\n\tasync #interrupt(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<boolean> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined) return true\n\t\tif (this.#abort.aborted) {\n\t\t\tawait this.#settle(token, { success: false, error: this.#abort.signal.reason })\n\t\t\treturn true\n\t\t}\n\t\tif (!signal?.aborted) return false\n\t\tawait this.#settle(token, {\n\t\t\tsuccess: false,\n\t\t\terror: new QueueError(\n\t\t\t\tisError(signal.reason) ? signal.reason.message : 'queue entry is aborted',\n\t\t\t\t{\n\t\t\t\t\tcode: 'aborted',\n\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\tcontext: { id: entry.id },\n\t\t\t\t},\n\t\t\t),\n\t\t})\n\t\treturn true\n\t}\n\n\tasync #saveAttempt(token: PromiseWithResolvers<TResult>, attempts: number): Promise<void> {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (this.#store === undefined || entry === undefined) return\n\t\ttry {\n\t\t\tawait this.#store.save({ id: entry.id, input: entry.input, attempts })\n\t\t} catch {\n\t\t\t// Live execution is authoritative; a crash may replay an earlier persisted attempt.\n\t\t}\n\t}\n\n\tasync #fail(token: PromiseWithResolvers<TResult>, error: unknown): Promise<void> {\n\t\tif (!this.#claims.has(token)) return\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} catch (cleanup: unknown) {\n\t\t\tthis.#finishEntry(token, { success: false, error: cleanup })\n\t\t\tthrow cleanup\n\t\t}\n\t\tthis.#finishEntry(token, { success: false, error })\n\t}\n\n\tasync #settle(\n\t\ttoken: PromiseWithResolvers<TResult>,\n\t\toutcome: Result<TResult, unknown>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#cleanup(token)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#finishEntry(token, { success: false, error })\n\t\t\tthrow error\n\t\t}\n\t\tthis.#finishEntry(token, outcome)\n\t}\n\n\t#finishEntry(token: PromiseWithResolvers<TResult>, outcome: Result<TResult, unknown>): void {\n\t\tif (!this.#claims.delete(token)) return\n\t\tconst entry = this.#entries.get(token)\n\t\tconst drain = this.#latchDrain()\n\t\tif (entry === undefined || !this.#settleToken(token, outcome)) {\n\t\t\tif (drain) this.#emitter.emit('drain')\n\t\t\treturn\n\t\t}\n\t\tif (outcome.success) this.#emitter.emit('success', entry.id, outcome.value)\n\t\telse this.#emitter.emit('failure', entry.id, outcome.error)\n\t\tif (drain) this.#emitter.emit('drain')\n\t}\n\n\t#settleToken(token: PromiseWithResolvers<TResult>, outcome: Result<TResult, unknown>): boolean {\n\t\tconst entry = this.#entries.get(token)\n\t\tif (entry === undefined || entry.settled) return false\n\t\tentry.settle()\n\t\tif (outcome.success) token.resolve(outcome.value)\n\t\telse token.reject(outcome.error)\n\t\tif (this.#live.get(entry.id) !== token) this.#entries.delete(token)\n\t\treturn true\n\t}\n\n\t#latchDrain(): boolean {\n\t\tif (this.#drained || this.#claims.size !== 0 || this.#live.size !== 0) return false\n\t\tthis.#drained = true\n\t\treturn true\n\t}\n\n\t#emitDrain(): void {\n\t\tif (this.#latchDrain()) this.#emitter.emit('drain')\n\t}\n\n\tasync #attempt(\n\t\tid: string,\n\t\tinput: TInput,\n\t\ttimeout: number,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Result<TResult>> {\n\t\tconst cancel =\n\t\t\tsignal === undefined ? this.#abort.signal : AbortSignal.any([this.#abort.signal, signal])\n\t\tconst deadline = timeout > 0 ? createTimeout({ ms: timeout, signal: cancel }) : undefined\n\t\tdeadline?.start()\n\t\tconst attemptSignal =\n\t\t\tdeadline === undefined ? cancel : AbortSignal.any([cancel, deadline.signal])\n\t\ttry {\n\t\t\tconst value = await this.#race(id, input, attemptSignal, deadline)\n\t\t\treturn { success: true, value }\n\t\t} catch (error: unknown) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: isError(error) ? error : new Error(preview(error), { cause: error }),\n\t\t\t}\n\t\t} finally {\n\t\t\tdeadline?.clear()\n\t\t}\n\t}\n\n\t#race(\n\t\tid: string,\n\t\tinput: TInput,\n\t\tsignal: AbortSignal,\n\t\tdeadline: TimeoutInterface | undefined,\n\t): Promise<TResult> {\n\t\tif (signal.aborted) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError(\n\t\t\t\t\tdeadline?.expired === true ? 'queue attempt timed out' : 'queue attempt aborted',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: deadline?.expired === true ? 'timeout' : 'aborted',\n\t\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\t\tcontext: { id },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\tconst cleanup = new AbortController()\n\t\treturn new Promise<TResult>((resolve, reject) => {\n\t\t\tsignal.addEventListener(\n\t\t\t\t'abort',\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew QueueError(\n\t\t\t\t\t\t\tdeadline?.expired === true ? 'queue attempt timed out' : 'queue attempt aborted',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: deadline?.expired === true ? 'timeout' : 'aborted',\n\t\t\t\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\t\t\t\tcontext: { id },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t{ once: true, signal: cleanup.signal },\n\t\t\t)\n\t\t\ttry {\n\t\t\t\tPromise.resolve(this.#handler(input, { id, signal })).then(\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tcleanup.abort()\n\t\t\t\t\t\tresolve(value)\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tcleanup.abort()\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t} catch (error: unknown) {\n\t\t\t\tcleanup.abort()\n\t\t\t\treject(error)\n\t\t\t}\n\t\t})\n\t}\n\n\tasync #finish(tasks: ReadonlyArray<Promise<void>>, message: string): Promise<void> {\n\t\tconst results = await Promise.allSettled(tasks)\n\t\tconst errors: unknown[] = []\n\t\tfor (const result of results) {\n\t\t\tif (result.status === 'rejected' && !errors.includes(result.reason)) {\n\t\t\t\terrors.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (errors.length === 0) return\n\t\tconst error = errors[0]\n\t\tif (errors.length === 1 && isQueueError(error)) throw error\n\t\tthrow new QueueError(message, {\n\t\t\tcode: 'cleanup',\n\t\t\tcause: new AggregateError(errors, message),\n\t\t\tcontext: { operation: 'remove' },\n\t\t})\n\t}\n\n\tasync #settleBarrier(\n\t\tbarrier: PromiseWithResolvers<void>,\n\t\ttasks: ReadonlyArray<Promise<void>>,\n\t\tmessage: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.#finish(tasks, message)\n\t\t\tbarrier.resolve()\n\t\t} catch (error: unknown) {\n\t\t\tbarrier.reject(error)\n\t\t}\n\t}\n\n\tasync #settleDestroy(\n\t\tbarrier: PromiseWithResolvers<void>,\n\t\taborting: Promise<void>,\n\t): Promise<void> {\n\t\tconst failure: unknown = await aborting.catch((error: unknown) => error)\n\t\ttry {\n\t\t\tawait this.#finish(\n\t\t\t\t[\n\t\t\t\t\t...this.#workers,\n\t\t\t\t\t...this.#admissions.values(),\n\t\t\t\t\t...this.#cleanups.values(),\n\t\t\t\t\t...this.#cleanOrphans(true),\n\t\t\t\t],\n\t\t\t\t'queue destroy cleanup failed',\n\t\t\t)\n\t\t} catch (error: unknown) {\n\t\t\tbarrier.reject(\n\t\t\t\tfailure === undefined\n\t\t\t\t\t? error\n\t\t\t\t\t: new QueueError('queue destroy cleanup failed', {\n\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\tcause: new AggregateError([failure, error], 'queue destroy cleanup failed'),\n\t\t\t\t\t\t\tcontext: { operation: 'remove' },\n\t\t\t\t\t\t}),\n\t\t\t)\n\t\t\treturn\n\t\t} finally {\n\t\t\tthis.#emitter.destroy()\n\t\t}\n\t\tif (failure === undefined) barrier.resolve()\n\t\telse barrier.reject(failure)\n\t}\n}\n","import type { TableInterface } from '@orkestrel/database'\nimport type { QueueStoreInterface, StoredEntry } from '../types.js'\n\n/**\n * Represents the opt-in durable store for a queue's outstanding entries, backed by one table\n * of the `@orkestrel/database` layer — a queue's durable state is a table, so persistence\n * reduces to keyed CRUD over a `TableInterface`.\n *\n * @remarks\n * The store is driver-agnostic: it holds a single {@link TableInterface} whose\n * backend (memory, JSON, SQLite) is chosen by whoever builds it (the factories).\n * `save` upserts an entry by its primary key (`set`), `remove` drops one (`remove`),\n * `load` returns every outstanding entry (`records` with no criteria), and `clear`\n * empties the table. Reads are narrowed through the table's contract, so `load`\n * returns typed {@link StoredEntry}`<TInput>[]` with no cast — the table\n * is created over the `{ id; input; attempts }` column map, which `Infer`s to exactly\n * that row. The store holds only outstanding work (completed entries are `remove`d), so\n * `load` on startup yields precisely the entries to resume.\n *\n * @typeParam TInput - The work input each {@link StoredEntry} carries\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { createMemoryDriver } from '@orkestrel/database'\n * import { createDatabaseQueueStore } from '@orkestrel/queue'\n *\n * const store = createDatabaseQueueStore(stringShape(), createMemoryDriver())\n * await store.save({ id: 'job-1', input: 'https://example.com', attempts: 0 })\n * const outstanding = await store.load() // readonly StoredEntry<string>[]\n * ```\n */\nexport class DatabaseQueueStore<TInput> implements QueueStoreInterface<TInput> {\n\treadonly #table: TableInterface<StoredEntry<TInput>>\n\n\t/**\n\t * Wraps a table as a queue store.\n\t *\n\t * @param table - The {@link TableInterface} holding the outstanding entries — its\n\t * row is a {@link StoredEntry}`<TInput>` (the `{ id; input; attempts }` shape)\n\t */\n\tconstructor(table: TableInterface<StoredEntry<TInput>>) {\n\t\tthis.#table = table\n\t}\n\n\t/** Upserts an entry by its `id` (a re-`save` of an existing `id` overwrites it). */\n\tasync save(entry: StoredEntry<TInput>): Promise<void> {\n\t\tawait this.#table.set(entry)\n\t}\n\n\t/** Drops a finished entry by `id`; absent is a no-op (no throw). */\n\tasync remove(id: string): Promise<void> {\n\t\tawait this.#table.remove(id)\n\t}\n\n\t/** Returns every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<ReadonlyArray<StoredEntry<TInput>>> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empties the store — drops every outstanding entry. */\n\tasync clear(): Promise<void> {\n\t\tawait this.#table.clear()\n\t}\n}\n","import type { ContractInterface, ContractShape, Infer } from '@orkestrel/contract'\nimport type { QueueStoreInterface, StoredEntry } from '../types.js'\nimport { cloneJSONValue, createContract } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isStoredEntry } from '../validators.js'\n\n/**\n * Represents an in-memory store of a queue's outstanding entries — a process-lifetime `Map`\n * owning validated, immutable JSON snapshots.\n *\n * @typeParam TInput - The contract shape for each stored input\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { MemoryQueueStore } from '@orkestrel/queue'\n *\n * const store = new MemoryQueueStore(stringShape())\n * await store.save({ id: 'job-1', input: 'task', attempts: 0 })\n * ```\n */\nexport class MemoryQueueStore<TInput extends ContractShape> implements QueueStoreInterface<\n\tInfer<TInput>\n> {\n\treadonly #contract: ContractInterface<Infer<TInput>>\n\treadonly #entries = new Map<string, StoredEntry<Infer<TInput>>>()\n\n\t/**\n\t * Creates an in-memory queue store.\n\t *\n\t * @param input - Runtime contract for each stored input\n\t */\n\tconstructor(input: TInput) {\n\t\tthis.#contract = createContract(input)\n\t}\n\n\t/** Upserts a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst candidate = { id: entry.id, input: entry.input, attempts: entry.attempts }\n\t\t\tif (!isStoredEntry(candidate)) {\n\t\t\t\tthrow new QueueError('queue store entry is invalid', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcontext: { operation: 'save' },\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst { id, input, attempts } = candidate\n\t\t\tthis.#entries.set(id, this.#snapshot(id, input, attempts, 'save'))\n\t\t\treturn Promise.resolve()\n\t\t} catch (error: unknown) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue store save failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { operation: 'save' },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t}\n\n\t/** Removes an entry; an absent id is a no-op. */\n\tremove(id: string): Promise<void> {\n\t\tthis.#entries.delete(id)\n\t\treturn Promise.resolve()\n\t}\n\n\t/** Returns fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<ReadonlyArray<StoredEntry<Infer<TInput>>>> {\n\t\ttry {\n\t\t\tconst snapshots: Array<StoredEntry<Infer<TInput>>> = []\n\t\t\tfor (const entry of this.#entries.values()) {\n\t\t\t\tconst id = entry.id\n\t\t\t\tconst input = entry.input\n\t\t\t\tconst attempts = entry.attempts\n\t\t\t\tsnapshots.push(this.#snapshot(id, input, attempts, 'load'))\n\t\t\t}\n\t\t\treturn Promise.resolve(snapshots)\n\t\t} catch (error: unknown) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew QueueError('queue store load failed', {\n\t\t\t\t\tcode: 'store',\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { operation: 'load' },\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t}\n\n\t/** Removes every outstanding entry. */\n\tclear(): Promise<void> {\n\t\tthis.#entries.clear()\n\t\treturn Promise.resolve()\n\t}\n\n\t#snapshot(\n\t\tid: string,\n\t\tinput: Infer<TInput>,\n\t\tattempts: number,\n\t\toperation: 'save' | 'load',\n\t): StoredEntry<Infer<TInput>> {\n\t\tconst snapshot = cloneJSONValue(input)\n\t\tif (!this.#contract.is(snapshot)) {\n\t\t\tthrow new QueueError('queue store input does not satisfy its contract', {\n\t\t\t\tcode: 'store',\n\t\t\t\tcontext: { id, operation },\n\t\t\t})\n\t\t}\n\t\treturn Object.freeze({ id, input: snapshot, attempts })\n\t}\n}\n","import type { ContractShape, Infer } from '@orkestrel/contract'\nimport type { DriverInterface, TableInterface } from '@orkestrel/database'\nimport type { QueueInterface, QueueOptions, QueueStoreInterface, StoredEntry } from './types.js'\nimport { integerShape, stringShape } from '@orkestrel/contract'\nimport { createDatabase } from '@orkestrel/database'\nimport { Queue } from './Queue.js'\nimport { DatabaseQueueStore } from './stores/DatabaseQueueStore.js'\nimport { MemoryQueueStore } from './stores/MemoryQueueStore.js'\n\n/**\n * Creates a concurrent, cooperative job queue — a bounded-concurrency engine that\n * runs each enqueued input through a handler, with retries and a per-attempt\n * timeout / abort, all over the L1 `Abort` / `Timeout` primitives.\n *\n * @remarks\n * Worker loops park on a wake list when no entry is ready and are woken one-at-a-time\n * by `enqueue` / `resume`, so an idle queue consumes no CPU (no polling). `enqueue`\n * returns a promise that settles when the entry finally completes, fails (after its\n * retries), or is rejected by an abort. A queue-level `abort` never retries; the\n * lifecycle (`start` / `stop` / `pause` / `resume` / `abort` / `clear` / `destroy`)\n * follows the fixed lifecycle vocabulary. The queue is observable: a typed `emitter` surfaces\n * `enqueue` / `start` / `retry` / `success` / `failure` / `abort` / `drain`.\n *\n * @typeParam TInput - The work input each entry carries\n * @typeParam TResult - The value the handler resolves for an entry\n * @param options - The `handler` plus optional `concurrency`, `retries`, and a default\n * per-attempt `timeout` in milliseconds. Default: `concurrency` `1`, `retries` `0`,\n * `timeout` `0`.\n * @returns A working {@link QueueInterface}\n *\n * @example Create a queue\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * // Ordered (concurrency defaults to 1): each entry runs to completion before the next.\n * const queue = createQueue<Job, Output>({ handler: (job) => run(job) })\n *\n * const output = await queue.enqueue(job)\n *\n * // Bounded, retried, and time-boxed: four in flight, two extra attempts, 5s per attempt.\n * const fetches = createQueue<string, number>({\n * \thandler: async (url, { signal }) => (await fetch(url, { signal })).status,\n * \tconcurrency: 4,\n * \tretries: 2,\n * \ttimeout: 5_000,\n * })\n *\n * const status = await fetches.enqueue('https://example.com')\n * ```\n */\nexport function createQueue<TInput, TResult>(\n\toptions: QueueOptions<TInput, TResult>,\n): QueueInterface<TInput, TResult> {\n\treturn new Queue(options)\n}\n\n/**\n * Creates a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries, across a memory, JSON, or\n * SQLite driver.\n *\n * @remarks\n * Builds a one-table database (`entries`, keyed by `id`) over the supplied driver, with\n * the fixed `{ id; input; attempts }` column map — `input` is the caller's own shape,\n * so the stored entry's payload is validated and typed by it. Reads narrow through that\n * contract, so the store's `load` returns typed `StoredEntry<Infer<TInput>>[]` with no\n * cast. Pass `createMemoryDriver()` for an ephemeral store, a server `createJSONDriver` /\n * `createSQLiteDriver` for a persistent one — the durability is the driver's job, the\n * store engine is shared. The `input` shape must be JSON-serializable to survive a JSON\n * or SQLite driver.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param input - The {@link ContractShape} for the work payload (used directly as the\n * `input` column)\n * @param driver - The storage backend the entries persist to\n * @returns A {@link QueueStoreInterface} over the driver, typed by `input`\n *\n * @example\n * ```ts\n * import { objectShape, stringShape } from '@orkestrel/contract'\n * import { createMemoryDriver } from '@orkestrel/database'\n * import { createDatabaseQueueStore } from '@orkestrel/queue'\n *\n * const store = createDatabaseQueueStore(\n * \tobjectShape({ url: stringShape(), label: stringShape() }),\n * \tcreateMemoryDriver(),\n * )\n * await store.save({ id: 'job-1', input: { url: 'https://example.com', label: 'home' }, attempts: 0 })\n * ```\n */\nexport function createDatabaseQueueStore<TInput extends ContractShape>(\n\tinput: TInput,\n\tdriver: DriverInterface,\n): QueueStoreInterface<Infer<TInput>>\n// The preceding public signature types the store by `Infer<TInput>`. The implementation\n// runs on the broad `ContractShape`, so the `entries` row is built and the table read\n// once — not re-instantiated per concrete `TInput`. (A generic `TInput` member can't be\n// reduced by the contract's object inference, which would also trip TS's\n// instantiation-depth guard; the broad body sidesteps both, and every call site still\n// sees the precise `Infer<TInput>` from the overload.) No cast: the contract-narrowed\n// row satisfies `StoredEntry<unknown>` structurally.\nexport function createDatabaseQueueStore(\n\tinput: ContractShape,\n\tdriver: DriverInterface,\n): QueueStoreInterface<unknown> {\n\tconst columns = {\n\t\tid: stringShape(),\n\t\tinput,\n\t\tattempts: integerShape({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n\t}\n\tconst database = createDatabase({ driver, tables: { entries: columns } })\n\tconst table: TableInterface<StoredEntry<unknown>> = database.table('entries')\n\treturn new DatabaseQueueStore(table)\n}\n\n/**\n * Creates an in-memory {@link MemoryQueueStore} over a plain `Map` — the zero-plumbing\n * {@link QueueStoreInterface} a queue takes when its outstanding entries need not outlive\n * the process, and the twin of {@link DatabaseQueueStore}.\n *\n * @remarks\n * The entries live in a process-lifetime `Map` and are gone when the process exits. The\n * supplied shape is compiled and enforced for every save. Exact JSON inputs are cloned\n * into deeply frozen owned snapshots, and each load returns fresh snapshots, so neither\n * caller mutation nor a returned object can alias stored state. For durability across\n * restarts, build the store over a persistent driver with\n * {@link createDatabaseQueueStore}.\n *\n * @typeParam TInput - The contract shape of each entry's `input` payload\n * @param input - The runtime {@link ContractShape} for the work payload\n * @returns A validated memory-backed {@link QueueStoreInterface}, typed by `input`\n *\n * @example\n * ```ts\n * import { stringShape } from '@orkestrel/contract'\n * import { createMemoryQueueStore } from '@orkestrel/queue'\n *\n * const store = createMemoryQueueStore(stringShape())\n * await store.save({ id: 'job-1', input: 'task', attempts: 0 })\n * ```\n */\nexport function createMemoryQueueStore<TInput extends ContractShape>(\n\tinput: TInput,\n): QueueStoreInterface<Infer<TInput>> {\n\treturn new MemoryQueueStore(input)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,IAAa,aAAb,cAAgC,MAAM;CACrC,OAAyB;CACzB;CACA;;;;;;;CAQA,YAAY,SAAiB,SAA4B;EACxD,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,CAAC;EAC1D,oBAAA,WAAW,OAAO,MAAM,OAAO,IAAI,6BAA6B,GAAG,EAAE,OAAO,KAAK,CAAC;EAClF,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ,YAAY,KAAA,IAAY,KAAA,IAAY,OAAO,OAAO,EAAE,GAAG,QAAQ,QAAQ,CAAC;CAChG;AACD;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,aAAa,OAAqC;CACjE,QAAA,GAAOA,oBAAAA,MAAAA,OAAY;EAClB,IAAI,EAAA,GAACC,oBAAAA,QAAAA,CAAQ,KAAK,KAAKC,oBAAAA,WAAW,UAAU,KAAK,MAAM,MAAM,WAAW,OAAO;EAC/E,MAAM,QAAQA,oBAAAA,WAAW,SAAS,OAAO,OAAO,IAAI,6BAA6B,CAAC;EAClF,IAAI,UAAU,KAAA,KAAa,MAAM,UAAU,OAAO,OAAO;EACzD,MAAM,OAAgBA,oBAAAA,WAAW,QAAQ,KAAK,OAAO,MAAM;EAC3D,IACC,SAAS,aACT,SAAS,eACT,SAAS,aACT,SAAS,aACT,SAAS,eACT,SAAS,a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