@orkestrel/queue 0.0.6 → 0.0.8
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
CHANGED
|
@@ -88,7 +88,7 @@ function isQueueRetries(value) {
|
|
|
88
88
|
* Determine whether a value is a valid queue timeout.
|
|
89
89
|
*
|
|
90
90
|
* @param value - Value to inspect
|
|
91
|
-
* @returns Whether the value is within the native timer range, inclusive
|
|
91
|
+
* @returns Whether the value is an integer within the native timer range, inclusive
|
|
92
92
|
*
|
|
93
93
|
* @example
|
|
94
94
|
* ```ts
|
|
@@ -97,7 +97,7 @@ function isQueueRetries(value) {
|
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
99
|
function isQueueTimeout(value) {
|
|
100
|
-
return (0, _orkestrel_contract.isFiniteNumber)(value) && value >= 0 && value <= 2147483647;
|
|
100
|
+
return (0, _orkestrel_contract.isFiniteNumber)(value) && (0, _orkestrel_contract.isInteger)(value) && value >= 0 && value <= 2147483647;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Determine whether a value is a native abort signal usable by the queue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#handler","#concurrency","#retries","#timeout","#store","#abort","#emitter","#entries","#live","#pending","#claims","#wakes","#workers","#admissions","#orphans","#cleanups","#paused","#stopped","#aborted","#destroyed","#reserve","#accept","#schedule","#generation","#stopPromise","#spawn","#destroyPromise","#abortPromise","#drain","#cleanOrphans","#wakeAll","#settleBarrier","#finish","#settleDestroy","#drained","#admission","#admit","#cleanup","#settleToken","#emitDrain","#discard","#wake","#worker","#next","#run","#fail","#take","#clean","#release","#interrupt","#attempt","#settle","#saveAttempt","#finishEntry","#latchDrain","#race","#table","#contract","#entries","#snapshot"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.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'\n\n/**\n * Error carrying a machine-readable queue category and optional context.\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 * Create 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 * Determine whether an unknown value is a {@link QueueError}.\n *\n * @param value - The value to inspect\n * @returns `true` only for a `QueueError`; hostile values return `false`\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\ttry {\n\t\treturn value instanceof QueueError\n\t} catch {\n\t\treturn false\n\t}\n}\n","import { isFiniteNumber, isInteger } from '@orkestrel/contract'\n\n/**\n * Determine whether a value is a valid queue concurrency.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a positive safe integer\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 * Determine whether a value is a valid queue retry count.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a nonnegative safe integer\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 * Determine whether a value is a valid queue timeout.\n *\n * @param value - Value to inspect\n * @returns Whether the value is within the native timer range, inclusive\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) && value >= 0 && value <= 2_147_483_647\n}\n\n/**\n * Determine whether a value is a native abort signal usable by the queue.\n *\n * @param value - Value to inspect\n * @returns Whether the value carries the native `AbortSignal` internal slot\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\ttry {\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} catch {\n\t\treturn false\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 { isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { isQueueConcurrency, isQueueRetries, isQueueSignal, isQueueTimeout } from './validators.js'\n\n/**\n * A concurrent, cooperative FIFO job queue with 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: PromiseWithResolvers<TResult>[] = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: (() => 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#aborted = false\n\t#destroyed = false\n\t#drained = true\n\n\t/**\n\t * Create 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 = configuredConcurrency === undefined ? 1 : configuredConcurrency\n\t\tif (!isQueueConcurrency(concurrency)) {\n\t\t\tthrow new QueueError('queue concurrency must be a positive safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'concurrency', value: concurrency },\n\t\t\t})\n\t\t}\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = configuredRetries === undefined ? 0 : configuredRetries\n\t\tif (!isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = configuredTimeout === undefined ? 0 : configuredTimeout\n\t\tif (!isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\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.#aborted\n\t}\n\n\t/**\n\t * Reserve and submit 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} Synchronously when an option is inaccessible or invalid\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tlet supplied: unknown\n\t\ttry {\n\t\t\tsupplied = options?.id\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue entry id could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'id' },\n\t\t\t})\n\t\t}\n\t\tif (supplied !== undefined && !isString(supplied)) {\n\t\t\tthrow new QueueError('queue entry id must be a string', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'id', value: supplied },\n\t\t\t})\n\t\t}\n\t\tlet retries: unknown\n\t\ttry {\n\t\t\tretries = options?.retries\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue retries could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'retries' },\n\t\t\t})\n\t\t}\n\t\tif (retries !== undefined && !isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tlet timeout: unknown\n\t\ttry {\n\t\t\ttimeout = options?.timeout\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue timeout could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'timeout' },\n\t\t\t})\n\t\t}\n\t\tif (timeout !== undefined && !isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\n\t\t}\n\t\tlet signal: unknown\n\t\ttry {\n\t\t\tsignal = options?.signal\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue signal could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'signal' },\n\t\t\t})\n\t\t}\n\t\tif (signal !== undefined && !isQueueSignal(signal)) {\n\t\t\tthrow new QueueError('queue signal must be an AbortSignal', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'signal', value: signal },\n\t\t\t})\n\t\t}\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.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#aborted) {\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/** Load and accept every outstanding stored entry from the current lifecycle generation. */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyed) return\n\t\tconst generation = this.#generation\n\t\tconst entries: 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 id: unknown = stored.id\n\t\t\t\tconst input = stored.input\n\t\t\t\tconst attempts: unknown = stored.attempts\n\t\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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({ id, input, attempts }))\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.#destroyed) return\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyed) return\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/** Begin or restart worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#aborted || this.#destroyed) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/** Reject non-active work and await current-loop and durable cleanup quiescence. */\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/** Suspend new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continue execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancel the queue and await 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.#aborted = true\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(reason instanceof Error ? 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/** Reject non-active work and await its durable cleanup. */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: 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/** Tear down once, destroying the emitter only after cleanup finishes. */\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\tthis.#destroyed = true\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(\n\t\t\t\t\terror instanceof Error ? error.message : 'queue admission save failed',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: 'store',\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (entry.settled || this.#aborted || this.#destroyed || this.#stopped) {\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.#aborted || this.#destroyed) return\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 (generation !== this.#generation || this.#stopped || this.#aborted || this.#destroyed) {\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): readonly 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: 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): readonly Promise<void>[] {\n\t\tconst cleanup: 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\tsignal.reason instanceof Error ? 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: error instanceof 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: readonly 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: readonly 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 * A {@link QueueStoreInterface} backed by one table of the `databases` layer — a\n * queue's durable state IS a table, so persistence reduces to keyed CRUD over a\n * `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 (AGENTS §1) — 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 * Wrap 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/** Upsert 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/** Drop 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/** Every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<readonly StoredEntry<TInput>[]> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empty the store — drop 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, isString } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isQueueRetries } from '../validators.js'\n\n/**\n * An in-memory store owning validated, immutable JSON snapshots of outstanding entries.\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 * Create 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/** Upsert a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst id: unknown = entry.id\n\t\t\tconst input = entry.input\n\t\t\tconst attempts: unknown = entry.attempts\n\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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\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/** Remove 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/** Return fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<readonly StoredEntry<Infer<TInput>>[]> {\n\t\ttry {\n\t\t\tconst snapshots: 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/** Remove 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 * Create 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 AGENTS §10. The queue is observable (§13): 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` (default `1`),\n * `retries` (default `0`), and a default per-attempt `timeout` in milliseconds\n * @returns A working {@link QueueInterface}\n *\n * @example\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * const queue = 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 queue.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 * Create a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries.\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 public signature above 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 * Create an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store\n * over a plain `Map` (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":";;;;;;;;;;;;;;;AAUA,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;;;;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,iBAAiB,KAAK;AAClC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#handler","#concurrency","#retries","#timeout","#store","#abort","#emitter","#entries","#live","#pending","#claims","#wakes","#workers","#admissions","#orphans","#cleanups","#paused","#stopped","#aborted","#destroyed","#reserve","#accept","#schedule","#generation","#stopPromise","#spawn","#destroyPromise","#abortPromise","#drain","#cleanOrphans","#wakeAll","#settleBarrier","#finish","#settleDestroy","#drained","#admission","#admit","#cleanup","#settleToken","#emitDrain","#discard","#wake","#worker","#next","#run","#fail","#take","#clean","#release","#interrupt","#attempt","#settle","#saveAttempt","#finishEntry","#latchDrain","#race","#table","#contract","#entries","#snapshot"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.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'\n\n/**\n * Error carrying a machine-readable queue category and optional context.\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 * Create 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 * Determine whether an unknown value is a {@link QueueError}.\n *\n * @param value - The value to inspect\n * @returns `true` only for a `QueueError`; hostile values return `false`\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\ttry {\n\t\treturn value instanceof QueueError\n\t} catch {\n\t\treturn false\n\t}\n}\n","import { isFiniteNumber, isInteger } from '@orkestrel/contract'\n\n/**\n * Determine whether a value is a valid queue concurrency.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a positive safe integer\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 * Determine whether a value is a valid queue retry count.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a nonnegative safe integer\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 * Determine whether a value is a valid queue timeout.\n *\n * @param value - Value to inspect\n * @returns Whether the value is an integer within the native timer range, inclusive\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 <= 2_147_483_647\n}\n\n/**\n * Determine whether a value is a native abort signal usable by the queue.\n *\n * @param value - Value to inspect\n * @returns Whether the value carries the native `AbortSignal` internal slot\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\ttry {\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} catch {\n\t\treturn false\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 { isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { isQueueConcurrency, isQueueRetries, isQueueSignal, isQueueTimeout } from './validators.js'\n\n/**\n * A concurrent, cooperative FIFO job queue with 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: PromiseWithResolvers<TResult>[] = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: (() => 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#aborted = false\n\t#destroyed = false\n\t#drained = true\n\n\t/**\n\t * Create 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 = configuredConcurrency === undefined ? 1 : configuredConcurrency\n\t\tif (!isQueueConcurrency(concurrency)) {\n\t\t\tthrow new QueueError('queue concurrency must be a positive safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'concurrency', value: concurrency },\n\t\t\t})\n\t\t}\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = configuredRetries === undefined ? 0 : configuredRetries\n\t\tif (!isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = configuredTimeout === undefined ? 0 : configuredTimeout\n\t\tif (!isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\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.#aborted\n\t}\n\n\t/**\n\t * Reserve and submit 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} Synchronously when an option is inaccessible or invalid\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tlet supplied: unknown\n\t\ttry {\n\t\t\tsupplied = options?.id\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue entry id could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'id' },\n\t\t\t})\n\t\t}\n\t\tif (supplied !== undefined && !isString(supplied)) {\n\t\t\tthrow new QueueError('queue entry id must be a string', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'id', value: supplied },\n\t\t\t})\n\t\t}\n\t\tlet retries: unknown\n\t\ttry {\n\t\t\tretries = options?.retries\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue retries could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'retries' },\n\t\t\t})\n\t\t}\n\t\tif (retries !== undefined && !isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tlet timeout: unknown\n\t\ttry {\n\t\t\ttimeout = options?.timeout\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue timeout could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'timeout' },\n\t\t\t})\n\t\t}\n\t\tif (timeout !== undefined && !isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\n\t\t}\n\t\tlet signal: unknown\n\t\ttry {\n\t\t\tsignal = options?.signal\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue signal could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'signal' },\n\t\t\t})\n\t\t}\n\t\tif (signal !== undefined && !isQueueSignal(signal)) {\n\t\t\tthrow new QueueError('queue signal must be an AbortSignal', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'signal', value: signal },\n\t\t\t})\n\t\t}\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.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#aborted) {\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/** Load and accept every outstanding stored entry from the current lifecycle generation. */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyed) return\n\t\tconst generation = this.#generation\n\t\tconst entries: 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 id: unknown = stored.id\n\t\t\t\tconst input = stored.input\n\t\t\t\tconst attempts: unknown = stored.attempts\n\t\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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({ id, input, attempts }))\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.#destroyed) return\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyed) return\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/** Begin or restart worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#aborted || this.#destroyed) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/** Reject non-active work and await current-loop and durable cleanup quiescence. */\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/** Suspend new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continue execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancel the queue and await 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.#aborted = true\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(reason instanceof Error ? 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/** Reject non-active work and await its durable cleanup. */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: 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/** Tear down once, destroying the emitter only after cleanup finishes. */\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\tthis.#destroyed = true\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(\n\t\t\t\t\terror instanceof Error ? error.message : 'queue admission save failed',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: 'store',\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (entry.settled || this.#aborted || this.#destroyed || this.#stopped) {\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.#aborted || this.#destroyed) return\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 (generation !== this.#generation || this.#stopped || this.#aborted || this.#destroyed) {\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): readonly 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: 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): readonly Promise<void>[] {\n\t\tconst cleanup: 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\tsignal.reason instanceof Error ? 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: error instanceof 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: readonly 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: readonly 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 * A {@link QueueStoreInterface} backed by one table of the `databases` layer — a\n * queue's durable state IS a table, so persistence reduces to keyed CRUD over a\n * `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 (AGENTS §1) — 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 * Wrap 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/** Upsert 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/** Drop 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/** Every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<readonly StoredEntry<TInput>[]> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empty the store — drop 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, isString } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isQueueRetries } from '../validators.js'\n\n/**\n * An in-memory store owning validated, immutable JSON snapshots of outstanding entries.\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 * Create 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/** Upsert a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst id: unknown = entry.id\n\t\t\tconst input = entry.input\n\t\t\tconst attempts: unknown = entry.attempts\n\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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\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/** Remove 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/** Return fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<readonly StoredEntry<Infer<TInput>>[]> {\n\t\ttry {\n\t\t\tconst snapshots: 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/** Remove 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 * Create 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 AGENTS §10. The queue is observable (§13): 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` (default `1`),\n * `retries` (default `0`), and a default per-attempt `timeout` in milliseconds\n * @returns A working {@link QueueInterface}\n *\n * @example\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * const queue = 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 queue.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 * Create a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries.\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 public signature above 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 * Create an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store\n * over a plain `Map` (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":";;;;;;;;;;;;;;;AAUA,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;;;;;;;;;;;;;;;;AAiBA,SAAgB,aAAa,OAAqC;CACjE,IAAI;EACH,OAAO,iBAAiB;CACzB,QAAQ;EACP,OAAO;CACR;AACD;;;;;;;;;;;;;;;ACpCA,SAAgB,mBAAmB,OAAiC;CACnE,QAAA,GAAO,oBAAA,UAAA,CAAU,KAAK,KAAK,OAAO,cAAc,KAAK,KAAK,QAAQ;AACnE;;;;;;;;;;;;;AAcA,SAAgB,eAAe,OAAiC;CAC/D,QAAA,GAAO,oBAAA,UAAA,CAAU,KAAK,KAAK,OAAO,cAAc,KAAK,KAAK,SAAS;AACpE;;;;;;;;;;;;;AAcA,SAAgB,eAAe,OAAiC;CAC/D,QAAA,GAAO,oBAAA,eAAA,CAAe,KAAK,MAAA,GAAK,oBAAA,UAAA,CAAU,KAAK,KAAK,SAAS,KAAK,SAAS;AAC5E;;;;;;;;;;;;;AAcA,SAAgB,cAAc,OAAsC;CACnE,IAAI;EACH,MAAM,SAAS,OAAO,yBAAyB,YAAY,WAAW,SAAS,CAAC,EAAE;EAClF,IAAI,WAAW,KAAA,GAAW,OAAO;EACjC,QAAQ,MAAM,QAAQ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1B,CAAC;EAEF,OAAO,OAAO,OAAO;GAAE;GAAI,OAAO;GAAU;EAAS,CAAC;CACvD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClEA,SAAgB,YACf,SACkC;CAClC,OAAO,IAAI,MAAM,OAAO;AACzB;AA8CA,SAAgB,yBACf,OACA,QAC+B;CAC/B,MAAM,UAAU;EACf,KAAA,GAAI,oBAAA,YAAA,CAAY;EAChB;EACA,WAAA,GAAU,oBAAA,aAAA,CAAa;GAAE,KAAK;GAAG,KAAK,OAAO;EAAiB,CAAC;CAChE;CAGA,OAAO,IAAI,oBADL,GADW,oBAAA,eAAA,CAAe;EAAE;EAAQ,QAAQ,EAAE,SAAS,QAAQ;CAAE,CACnB,CAAA,CAAS,MAAM,SACrC,CAAK;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,uBACf,OACqC;CACrC,OAAO,IAAI,iBAAiB,KAAK;AAClC"}
|
|
@@ -215,7 +215,7 @@ export declare function isQueueSignal(value: unknown): value is AbortSignal;
|
|
|
215
215
|
* Determine whether a value is a valid queue timeout.
|
|
216
216
|
*
|
|
217
217
|
* @param value - Value to inspect
|
|
218
|
-
* @returns Whether the value is within the native timer range, inclusive
|
|
218
|
+
* @returns Whether the value is an integer within the native timer range, inclusive
|
|
219
219
|
*
|
|
220
220
|
* @example
|
|
221
221
|
* ```ts
|
|
@@ -331,7 +331,7 @@ export declare type QueueCode = 'invalid' | 'duplicate' | 'stopped' | 'aborted'
|
|
|
331
331
|
* - `id` — a trace label for the entry; defaults to a random UUID.
|
|
332
332
|
* - `retries` — extra attempts after the first on failure (or a per-attempt
|
|
333
333
|
* timeout); overrides the queue default. A queue-level abort never retries.
|
|
334
|
-
* - `timeout` — the nonnegative per-attempt deadline in milliseconds, at most
|
|
334
|
+
* - `timeout` — the nonnegative integer per-attempt deadline in milliseconds, at most
|
|
335
335
|
* `2_147_483_647`; overrides the queue default. Zero means no deadline.
|
|
336
336
|
* - `signal` — an entry-scoped abort; once it fires the entry rejects (its
|
|
337
337
|
* in-flight attempt's `signal` fires too) and does not retry.
|
|
@@ -529,7 +529,7 @@ export declare interface QueueInterface<TInput, TResult> {
|
|
|
529
529
|
* `1` and must be a positive safe integer.
|
|
530
530
|
* - `retries` — the default extra attempts per entry on failure; defaults to `0`
|
|
531
531
|
* and must be a nonnegative safe integer.
|
|
532
|
-
* - `timeout` — the default per-attempt deadline in milliseconds; defaults to zero
|
|
532
|
+
* - `timeout` — the default per-attempt deadline in integer milliseconds; defaults to zero
|
|
533
533
|
* and must be between zero and `2_147_483_647`, inclusive.
|
|
534
534
|
* - `store` — durable backing; outstanding entries survive a restart; call
|
|
535
535
|
* `restore()` to re-run them.
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export declare function isQueueSignal(value: unknown): value is AbortSignal;
|
|
|
215
215
|
* Determine whether a value is a valid queue timeout.
|
|
216
216
|
*
|
|
217
217
|
* @param value - Value to inspect
|
|
218
|
-
* @returns Whether the value is within the native timer range, inclusive
|
|
218
|
+
* @returns Whether the value is an integer within the native timer range, inclusive
|
|
219
219
|
*
|
|
220
220
|
* @example
|
|
221
221
|
* ```ts
|
|
@@ -331,7 +331,7 @@ export declare type QueueCode = 'invalid' | 'duplicate' | 'stopped' | 'aborted'
|
|
|
331
331
|
* - `id` — a trace label for the entry; defaults to a random UUID.
|
|
332
332
|
* - `retries` — extra attempts after the first on failure (or a per-attempt
|
|
333
333
|
* timeout); overrides the queue default. A queue-level abort never retries.
|
|
334
|
-
* - `timeout` — the nonnegative per-attempt deadline in milliseconds, at most
|
|
334
|
+
* - `timeout` — the nonnegative integer per-attempt deadline in milliseconds, at most
|
|
335
335
|
* `2_147_483_647`; overrides the queue default. Zero means no deadline.
|
|
336
336
|
* - `signal` — an entry-scoped abort; once it fires the entry rejects (its
|
|
337
337
|
* in-flight attempt's `signal` fires too) and does not retry.
|
|
@@ -529,7 +529,7 @@ export declare interface QueueInterface<TInput, TResult> {
|
|
|
529
529
|
* `1` and must be a positive safe integer.
|
|
530
530
|
* - `retries` — the default extra attempts per entry on failure; defaults to `0`
|
|
531
531
|
* and must be a nonnegative safe integer.
|
|
532
|
-
* - `timeout` — the default per-attempt deadline in milliseconds; defaults to zero
|
|
532
|
+
* - `timeout` — the default per-attempt deadline in integer milliseconds; defaults to zero
|
|
533
533
|
* and must be between zero and `2_147_483_647`, inclusive.
|
|
534
534
|
* - `store` — durable backing; outstanding entries survive a restart; call
|
|
535
535
|
* `restore()` to re-run them.
|
package/dist/src/core/index.js
CHANGED
|
@@ -87,7 +87,7 @@ function isQueueRetries(value) {
|
|
|
87
87
|
* Determine whether a value is a valid queue timeout.
|
|
88
88
|
*
|
|
89
89
|
* @param value - Value to inspect
|
|
90
|
-
* @returns Whether the value is within the native timer range, inclusive
|
|
90
|
+
* @returns Whether the value is an integer within the native timer range, inclusive
|
|
91
91
|
*
|
|
92
92
|
* @example
|
|
93
93
|
* ```ts
|
|
@@ -96,7 +96,7 @@ function isQueueRetries(value) {
|
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
function isQueueTimeout(value) {
|
|
99
|
-
return isFiniteNumber(value) && value >= 0 && value <= 2147483647;
|
|
99
|
+
return isFiniteNumber(value) && isInteger(value) && value >= 0 && value <= 2147483647;
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Determine whether a value is a native abort signal usable by the queue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#handler","#concurrency","#retries","#timeout","#store","#abort","#emitter","#entries","#live","#pending","#claims","#wakes","#workers","#admissions","#orphans","#cleanups","#paused","#stopped","#aborted","#destroyed","#reserve","#accept","#schedule","#generation","#stopPromise","#spawn","#destroyPromise","#abortPromise","#drain","#cleanOrphans","#wakeAll","#settleBarrier","#finish","#settleDestroy","#drained","#admission","#admit","#cleanup","#settleToken","#emitDrain","#discard","#wake","#worker","#next","#run","#fail","#take","#clean","#release","#interrupt","#attempt","#settle","#saveAttempt","#finishEntry","#latchDrain","#race","#table","#contract","#entries","#snapshot"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.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'\n\n/**\n * Error carrying a machine-readable queue category and optional context.\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 * Create 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 * Determine whether an unknown value is a {@link QueueError}.\n *\n * @param value - The value to inspect\n * @returns `true` only for a `QueueError`; hostile values return `false`\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\ttry {\n\t\treturn value instanceof QueueError\n\t} catch {\n\t\treturn false\n\t}\n}\n","import { isFiniteNumber, isInteger } from '@orkestrel/contract'\n\n/**\n * Determine whether a value is a valid queue concurrency.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a positive safe integer\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 * Determine whether a value is a valid queue retry count.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a nonnegative safe integer\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 * Determine whether a value is a valid queue timeout.\n *\n * @param value - Value to inspect\n * @returns Whether the value is within the native timer range, inclusive\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) && value >= 0 && value <= 2_147_483_647\n}\n\n/**\n * Determine whether a value is a native abort signal usable by the queue.\n *\n * @param value - Value to inspect\n * @returns Whether the value carries the native `AbortSignal` internal slot\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\ttry {\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} catch {\n\t\treturn false\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 { isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { isQueueConcurrency, isQueueRetries, isQueueSignal, isQueueTimeout } from './validators.js'\n\n/**\n * A concurrent, cooperative FIFO job queue with 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: PromiseWithResolvers<TResult>[] = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: (() => 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#aborted = false\n\t#destroyed = false\n\t#drained = true\n\n\t/**\n\t * Create 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 = configuredConcurrency === undefined ? 1 : configuredConcurrency\n\t\tif (!isQueueConcurrency(concurrency)) {\n\t\t\tthrow new QueueError('queue concurrency must be a positive safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'concurrency', value: concurrency },\n\t\t\t})\n\t\t}\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = configuredRetries === undefined ? 0 : configuredRetries\n\t\tif (!isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = configuredTimeout === undefined ? 0 : configuredTimeout\n\t\tif (!isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\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.#aborted\n\t}\n\n\t/**\n\t * Reserve and submit 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} Synchronously when an option is inaccessible or invalid\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tlet supplied: unknown\n\t\ttry {\n\t\t\tsupplied = options?.id\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue entry id could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'id' },\n\t\t\t})\n\t\t}\n\t\tif (supplied !== undefined && !isString(supplied)) {\n\t\t\tthrow new QueueError('queue entry id must be a string', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'id', value: supplied },\n\t\t\t})\n\t\t}\n\t\tlet retries: unknown\n\t\ttry {\n\t\t\tretries = options?.retries\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue retries could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'retries' },\n\t\t\t})\n\t\t}\n\t\tif (retries !== undefined && !isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tlet timeout: unknown\n\t\ttry {\n\t\t\ttimeout = options?.timeout\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue timeout could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'timeout' },\n\t\t\t})\n\t\t}\n\t\tif (timeout !== undefined && !isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\n\t\t}\n\t\tlet signal: unknown\n\t\ttry {\n\t\t\tsignal = options?.signal\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue signal could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'signal' },\n\t\t\t})\n\t\t}\n\t\tif (signal !== undefined && !isQueueSignal(signal)) {\n\t\t\tthrow new QueueError('queue signal must be an AbortSignal', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'signal', value: signal },\n\t\t\t})\n\t\t}\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.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#aborted) {\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/** Load and accept every outstanding stored entry from the current lifecycle generation. */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyed) return\n\t\tconst generation = this.#generation\n\t\tconst entries: 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 id: unknown = stored.id\n\t\t\t\tconst input = stored.input\n\t\t\t\tconst attempts: unknown = stored.attempts\n\t\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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({ id, input, attempts }))\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.#destroyed) return\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyed) return\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/** Begin or restart worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#aborted || this.#destroyed) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/** Reject non-active work and await current-loop and durable cleanup quiescence. */\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/** Suspend new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continue execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancel the queue and await 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.#aborted = true\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(reason instanceof Error ? 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/** Reject non-active work and await its durable cleanup. */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: 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/** Tear down once, destroying the emitter only after cleanup finishes. */\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\tthis.#destroyed = true\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(\n\t\t\t\t\terror instanceof Error ? error.message : 'queue admission save failed',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: 'store',\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (entry.settled || this.#aborted || this.#destroyed || this.#stopped) {\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.#aborted || this.#destroyed) return\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 (generation !== this.#generation || this.#stopped || this.#aborted || this.#destroyed) {\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): readonly 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: 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): readonly Promise<void>[] {\n\t\tconst cleanup: 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\tsignal.reason instanceof Error ? 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: error instanceof 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: readonly 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: readonly 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 * A {@link QueueStoreInterface} backed by one table of the `databases` layer — a\n * queue's durable state IS a table, so persistence reduces to keyed CRUD over a\n * `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 (AGENTS §1) — 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 * Wrap 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/** Upsert 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/** Drop 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/** Every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<readonly StoredEntry<TInput>[]> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empty the store — drop 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, isString } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isQueueRetries } from '../validators.js'\n\n/**\n * An in-memory store owning validated, immutable JSON snapshots of outstanding entries.\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 * Create 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/** Upsert a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst id: unknown = entry.id\n\t\t\tconst input = entry.input\n\t\t\tconst attempts: unknown = entry.attempts\n\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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\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/** Remove 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/** Return fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<readonly StoredEntry<Infer<TInput>>[]> {\n\t\ttry {\n\t\t\tconst snapshots: 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/** Remove 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 * Create 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 AGENTS §10. The queue is observable (§13): 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` (default `1`),\n * `retries` (default `0`), and a default per-attempt `timeout` in milliseconds\n * @returns A working {@link QueueInterface}\n *\n * @example\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * const queue = 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 queue.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 * Create a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries.\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 public signature above 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 * Create an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store\n * over a plain `Map` (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":";;;;;;;;;;;;;;AAUA,IAAa,aAAb,cAAgC,MAAM;CACrC,OAAyB;CACzB;CACA;;;;;;;CAQA,YAAY,SAAiB,SAA4B;EACxD,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA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AS,KAAKA,SAAS,OAAO,GAAG;IAC3C,MAAM,KAAK,MAAM;IACjB,MAAM,QAAQ,MAAM;IACpB,MAAM,WAAW,MAAM;IACvB,UAAU,KAAK,KAAKC,UAAU,IAAI,OAAO,UAAU,MAAM,CAAC;GAC3D;GACA,OAAO,QAAQ,QAAQ,SAAS;EACjC,SAAS,OAAgB;GACxB,OAAO,QAAQ,OACd,IAAI,WAAW,2BAA2B;IACzC,MAAM;IACN,OAAO;IACP,SAAS,EAAE,WAAW,OAAO;GAC9B,CAAC,CACF;EACD;CACD;;CAGA,QAAuB;EACtB,KAAKD,SAAS,MAAM;EACpB,OAAO,QAAQ,QAAQ;CACxB;CAEA,UACC,IACA,OACA,UACA,WAC6B;EAC7B,MAAM,WAAW,eAAe,KAAK;EACrC,IAAI,CAAC,KAAKD,UAAU,GAAG,QAAQ,GAC9B,MAAM,IAAI,WAAW,mDAAmD;GACvE,MAAM;GACN,SAAS;IAAE;IAAI;GAAU;EAC1B,CAAC;EAEF,OAAO,OAAO,OAAO;GAAE;GAAI,OAAO;GAAU;EAAS,CAAC;CACvD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClEA,SAAgB,YACf,SACkC;CAClC,OAAO,IAAI,MAAM,OAAO;AACzB;AA8CA,SAAgB,yBACf,OACA,QAC+B;CAC/B,MAAM,UAAU;EACf,IAAI,YAAY;EAChB;EACA,UAAU,aAAa;GAAE,KAAK;GAAG,KAAK,OAAO;EAAiB,CAAC;CAChE;CAGA,OAAO,IAAI,mBAFM,eAAe;EAAE;EAAQ,QAAQ,EAAE,SAAS,QAAQ;CAAE,CACnB,CAAA,CAAS,MAAM,SACrC,CAAK;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,uBACf,OACqC;CACrC,OAAO,IAAI,iBAAiB,KAAK;AAClC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#handler","#concurrency","#retries","#timeout","#store","#abort","#emitter","#entries","#live","#pending","#claims","#wakes","#workers","#admissions","#orphans","#cleanups","#paused","#stopped","#aborted","#destroyed","#reserve","#accept","#schedule","#generation","#stopPromise","#spawn","#destroyPromise","#abortPromise","#drain","#cleanOrphans","#wakeAll","#settleBarrier","#finish","#settleDestroy","#drained","#admission","#admit","#cleanup","#settleToken","#emitDrain","#discard","#wake","#worker","#next","#run","#fail","#take","#clean","#release","#interrupt","#attempt","#settle","#saveAttempt","#finishEntry","#latchDrain","#race","#table","#contract","#entries","#snapshot"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.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'\n\n/**\n * Error carrying a machine-readable queue category and optional context.\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 * Create 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 * Determine whether an unknown value is a {@link QueueError}.\n *\n * @param value - The value to inspect\n * @returns `true` only for a `QueueError`; hostile values return `false`\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\ttry {\n\t\treturn value instanceof QueueError\n\t} catch {\n\t\treturn false\n\t}\n}\n","import { isFiniteNumber, isInteger } from '@orkestrel/contract'\n\n/**\n * Determine whether a value is a valid queue concurrency.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a positive safe integer\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 * Determine whether a value is a valid queue retry count.\n *\n * @param value - Value to inspect\n * @returns Whether the value is a nonnegative safe integer\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 * Determine whether a value is a valid queue timeout.\n *\n * @param value - Value to inspect\n * @returns Whether the value is an integer within the native timer range, inclusive\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 <= 2_147_483_647\n}\n\n/**\n * Determine whether a value is a native abort signal usable by the queue.\n *\n * @param value - Value to inspect\n * @returns Whether the value carries the native `AbortSignal` internal slot\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\ttry {\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} catch {\n\t\treturn false\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 { isString, preview } from '@orkestrel/contract'\nimport { Emitter } from '@orkestrel/emitter'\nimport { createTimeout } from '@orkestrel/timeout'\nimport { isQueueError, QueueError } from './errors.js'\nimport { isQueueConcurrency, isQueueRetries, isQueueSignal, isQueueTimeout } from './validators.js'\n\n/**\n * A concurrent, cooperative FIFO job queue with 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: PromiseWithResolvers<TResult>[] = []\n\treadonly #claims = new Set<PromiseWithResolvers<TResult>>()\n\treadonly #wakes: (() => 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#aborted = false\n\t#destroyed = false\n\t#drained = true\n\n\t/**\n\t * Create 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 = configuredConcurrency === undefined ? 1 : configuredConcurrency\n\t\tif (!isQueueConcurrency(concurrency)) {\n\t\t\tthrow new QueueError('queue concurrency must be a positive safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'concurrency', value: concurrency },\n\t\t\t})\n\t\t}\n\t\tconst configuredRetries = options.retries\n\t\tconst retries = configuredRetries === undefined ? 0 : configuredRetries\n\t\tif (!isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tconst configuredTimeout = options.timeout\n\t\tconst timeout = configuredTimeout === undefined ? 0 : configuredTimeout\n\t\tif (!isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\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.#aborted\n\t}\n\n\t/**\n\t * Reserve and submit 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} Synchronously when an option is inaccessible or invalid\n\t */\n\tenqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult> {\n\t\tlet supplied: unknown\n\t\ttry {\n\t\t\tsupplied = options?.id\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue entry id could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'id' },\n\t\t\t})\n\t\t}\n\t\tif (supplied !== undefined && !isString(supplied)) {\n\t\t\tthrow new QueueError('queue entry id must be a string', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'id', value: supplied },\n\t\t\t})\n\t\t}\n\t\tlet retries: unknown\n\t\ttry {\n\t\t\tretries = options?.retries\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue retries could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'retries' },\n\t\t\t})\n\t\t}\n\t\tif (retries !== undefined && !isQueueRetries(retries)) {\n\t\t\tthrow new QueueError('queue retries must be a nonnegative safe integer', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'retries', value: retries },\n\t\t\t})\n\t\t}\n\t\tlet timeout: unknown\n\t\ttry {\n\t\t\ttimeout = options?.timeout\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue timeout could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'timeout' },\n\t\t\t})\n\t\t}\n\t\tif (timeout !== undefined && !isQueueTimeout(timeout)) {\n\t\t\tthrow new QueueError('queue timeout must be within the native timer range', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'timeout', value: timeout },\n\t\t\t})\n\t\t}\n\t\tlet signal: unknown\n\t\ttry {\n\t\t\tsignal = options?.signal\n\t\t} catch (error: unknown) {\n\t\t\tthrow new QueueError('queue signal could not be read', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcause: error,\n\t\t\t\tcontext: { option: 'signal' },\n\t\t\t})\n\t\t}\n\t\tif (signal !== undefined && !isQueueSignal(signal)) {\n\t\t\tthrow new QueueError('queue signal must be an AbortSignal', {\n\t\t\t\tcode: 'invalid',\n\t\t\t\tcontext: { option: 'signal', value: signal },\n\t\t\t})\n\t\t}\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.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tif (this.#aborted) {\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/** Load and accept every outstanding stored entry from the current lifecycle generation. */\n\tasync restore(): Promise<void> {\n\t\tif (this.#store === undefined || this.stopped || this.#destroyed) return\n\t\tconst generation = this.#generation\n\t\tconst entries: 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 id: unknown = stored.id\n\t\t\t\tconst input = stored.input\n\t\t\t\tconst attempts: unknown = stored.attempts\n\t\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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({ id, input, attempts }))\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.#destroyed) return\n\t\tfor (const stored of entries) {\n\t\t\tif (generation !== this.#generation || this.stopped || this.#destroyed) return\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/** Begin or restart worker execution unless the queue is terminal. */\n\tstart(): void {\n\t\tif (this.#aborted || this.#destroyed) return\n\t\tthis.#stopped = false\n\t\tthis.#stopPromise = undefined\n\t\tthis.#spawn()\n\t}\n\n\t/** Reject non-active work and await current-loop and durable cleanup quiescence. */\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/** Suspend new execution while leaving active entries untouched. */\n\tpause(): void {\n\t\tif (this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = true\n\t}\n\n\t/** Continue execution after a pause. */\n\tresume(): void {\n\t\tif (!this.#paused || this.stopped || this.#destroyed) return\n\t\tthis.#paused = false\n\t\tthis.#wakeAll()\n\t}\n\n\t/**\n\t * Cancel the queue and await 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.#aborted = true\n\t\tthis.#stopped = true\n\t\tthis.#generation += 1\n\t\tconst error = new QueueError(reason instanceof Error ? 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/** Reject non-active work and await its durable cleanup. */\n\tclear(): Promise<void> {\n\t\tif (this.#destroyed) {\n\t\t\treturn Promise.reject(new QueueError('queue is destroyed', { code: 'destroyed' }))\n\t\t}\n\t\tconst existing: 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/** Tear down once, destroying the emitter only after cleanup finishes. */\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\tthis.#destroyed = true\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(\n\t\t\t\t\terror instanceof Error ? error.message : 'queue admission save failed',\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: 'store',\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tcontext: { id: entry.id, operation: 'save' },\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t})\n\t\t\tthis.#emitDrain()\n\t\t\treturn\n\t\t}\n\t\tif (entry.settled || this.#aborted || this.#destroyed || this.#stopped) {\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.#aborted || this.#destroyed) return\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 (generation !== this.#generation || this.#stopped || this.#aborted || this.#destroyed) {\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): readonly 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: 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): readonly Promise<void>[] {\n\t\tconst cleanup: 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\tsignal.reason instanceof Error ? 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: error instanceof 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: readonly 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: readonly 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 * A {@link QueueStoreInterface} backed by one table of the `databases` layer — a\n * queue's durable state IS a table, so persistence reduces to keyed CRUD over a\n * `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 (AGENTS §1) — 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 * Wrap 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/** Upsert 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/** Drop 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/** Every outstanding entry — the work to resume after a restart. */\n\tload(): Promise<readonly StoredEntry<TInput>[]> {\n\t\treturn this.#table.records()\n\t}\n\n\t/** Empty the store — drop 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, isString } from '@orkestrel/contract'\nimport { QueueError } from '../errors.js'\nimport { isQueueRetries } from '../validators.js'\n\n/**\n * An in-memory store owning validated, immutable JSON snapshots of outstanding entries.\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 * Create 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/** Upsert a validated, owned snapshot under the entry's id. */\n\tsave(entry: StoredEntry<Infer<TInput>>): Promise<void> {\n\t\ttry {\n\t\t\tconst id: unknown = entry.id\n\t\t\tconst input = entry.input\n\t\t\tconst attempts: unknown = entry.attempts\n\t\t\tif (!isString(id) || !isQueueRetries(attempts)) {\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\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/** Remove 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/** Return fresh immutable snapshots of every outstanding entry. */\n\tload(): Promise<readonly StoredEntry<Infer<TInput>>[]> {\n\t\ttry {\n\t\t\tconst snapshots: 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/** Remove 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 * Create 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 AGENTS §10. The queue is observable (§13): 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` (default `1`),\n * `retries` (default `0`), and a default per-attempt `timeout` in milliseconds\n * @returns A working {@link QueueInterface}\n *\n * @example\n * ```ts\n * import { createQueue } from '@orkestrel/queue'\n *\n * const queue = 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 queue.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 * Create a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,\n * driver-pluggable backing for a queue's outstanding entries.\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 public signature above 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 * Create an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store\n * over a plain `Map` (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 ContractSh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Ae;EAAE;EAAQ,QAAQ,EAAE,SAAS,QAAQ;CAAE,CACnB,CAAA,CAAS,MAAM,SACrC,CAAK;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,uBACf,OACqC;CACrC,OAAO,IAAI,iBAAiB,KAAK;AAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkestrel/queue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A typed, persistent-capable FIFO job queue — bounded concurrency, retries, per-attempt timeout/abort, and an optional durable store for resuming outstanding work after a restart. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -65,20 +65,20 @@
|
|
|
65
65
|
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@orkestrel/abort": "^0.0.
|
|
69
|
-
"@orkestrel/contract": "^0.0.
|
|
70
|
-
"@orkestrel/database": "^0.0.
|
|
71
|
-
"@orkestrel/emitter": "^0.0.
|
|
72
|
-
"@orkestrel/timeout": "^0.0.
|
|
68
|
+
"@orkestrel/abort": "^0.0.6",
|
|
69
|
+
"@orkestrel/contract": "^0.0.11",
|
|
70
|
+
"@orkestrel/database": "^0.0.8",
|
|
71
|
+
"@orkestrel/emitter": "^0.0.6",
|
|
72
|
+
"@orkestrel/timeout": "^0.0.6"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@microsoft/api-extractor": "^7.58.12",
|
|
76
|
-
"@orkestrel/guide": "^0.0.
|
|
77
|
-
"@orkestrel/scaffold": "^0.0.
|
|
76
|
+
"@orkestrel/guide": "^0.0.9",
|
|
77
|
+
"@orkestrel/scaffold": "^0.0.26",
|
|
78
78
|
"@types/node": "^26.1.2",
|
|
79
79
|
"@vitest/browser-playwright": "^4.1.10",
|
|
80
|
-
"oxfmt": "^0.
|
|
81
|
-
"oxlint": "^1.
|
|
80
|
+
"oxfmt": "^0.62.0",
|
|
81
|
+
"oxlint": "^1.77.0",
|
|
82
82
|
"typescript": "^6.0.3",
|
|
83
83
|
"vite": "^8.2.0",
|
|
84
84
|
"vite-plugin-dts": "^5.0.3",
|