@orkestrel/queue 0.0.10 → 0.0.12

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.
@@ -3,11 +3,12 @@ import { DriverInterface } from '@orkestrel/database';
3
3
  import { EmitterErrorHandler } from '@orkestrel/emitter';
4
4
  import { EmitterHooks } from '@orkestrel/emitter';
5
5
  import { EmitterInterface } from '@orkestrel/emitter';
6
+ import { Guard } from '@orkestrel/contract';
6
7
  import { Infer } from '@orkestrel/contract';
7
8
  import { TableInterface } from '@orkestrel/database';
8
9
 
9
10
  /**
10
- * Create a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,
11
+ * Creates a {@link DatabaseQueueStore} over any {@link DriverInterface} — the durable,
11
12
  * driver-pluggable backing for a queue's outstanding entries.
12
13
  *
13
14
  * @remarks
@@ -42,7 +43,7 @@ import { TableInterface } from '@orkestrel/database';
42
43
  export declare function createDatabaseQueueStore<TInput extends ContractShape>(input: TInput, driver: DriverInterface): QueueStoreInterface<Infer<TInput>>;
43
44
 
44
45
  /**
45
- * Create an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store
46
+ * Creates an in-memory {@link MemoryQueueStore} — the zero-plumbing DEFAULT queue store
46
47
  * over a plain `Map` (the twin of {@link DatabaseQueueStore}).
47
48
  *
48
49
  * @remarks
@@ -69,7 +70,7 @@ export declare function createDatabaseQueueStore<TInput extends ContractShape>(i
69
70
  export declare function createMemoryQueueStore<TInput extends ContractShape>(input: TInput): QueueStoreInterface<Infer<TInput>>;
70
71
 
71
72
  /**
72
- * Create a concurrent, cooperative job queue — a bounded-concurrency engine that
73
+ * Creates a concurrent, cooperative job queue — a bounded-concurrency engine that
73
74
  * runs each enqueued input through a handler, with retries and a per-attempt
74
75
  * timeout / abort, all over the L1 `Abort` / `Timeout` primitives.
75
76
  *
@@ -79,13 +80,14 @@ export declare function createMemoryQueueStore<TInput extends ContractShape>(inp
79
80
  * returns a promise that settles when the entry finally completes, fails (after its
80
81
  * retries), or is rejected by an abort. A queue-level `abort` never retries; the
81
82
  * lifecycle (`start` / `stop` / `pause` / `resume` / `abort` / `clear` / `destroy`)
82
- * follows AGENTS §10. The queue is observable (§13): a typed `emitter` surfaces
83
+ * follows the fixed lifecycle vocabulary. The queue is observable: a typed `emitter` surfaces
83
84
  * `enqueue` / `start` / `retry` / `success` / `failure` / `abort` / `drain`.
84
85
  *
85
86
  * @typeParam TInput - The work input each entry carries
86
87
  * @typeParam TResult - The value the handler resolves for an entry
87
- * @param options - The `handler` plus optional `concurrency` (default `1`),
88
- * `retries` (default `0`), and a default per-attempt `timeout` in milliseconds
88
+ * @param options - The `handler` plus optional `concurrency`, `retries`, and a default
89
+ * per-attempt `timeout` in milliseconds. Default: `concurrency` `1`, `retries` `0`,
90
+ * `timeout` `0`.
89
91
  * @returns A working {@link QueueInterface}
90
92
  *
91
93
  * @example
@@ -105,7 +107,7 @@ export declare function createMemoryQueueStore<TInput extends ContractShape>(inp
105
107
  export declare function createQueue<TInput, TResult>(options: QueueOptions<TInput, TResult>): QueueInterface<TInput, TResult>;
106
108
 
107
109
  /**
108
- * A {@link QueueStoreInterface} backed by one table of the `databases` layer — a
110
+ * Represents a {@link QueueStoreInterface} backed by one table of the `@orkestrel/database` layer — a
109
111
  * queue's durable state IS a table, so persistence reduces to keyed CRUD over a
110
112
  * `TableInterface`.
111
113
  *
@@ -115,7 +117,7 @@ export declare function createQueue<TInput, TResult>(options: QueueOptions<TInpu
115
117
  * `save` upserts an entry by its primary key (`set`), `remove` drops one (`remove`),
116
118
  * `load` returns every outstanding entry (`records` with no criteria), and `clear`
117
119
  * empties the table. Reads are narrowed through the table's contract, so `load`
118
- * returns typed {@link StoredEntry}`<TInput>[]` with no cast (AGENTS §1) — the table
120
+ * returns typed {@link StoredEntry}`<TInput>[]` with no cast — the table
119
121
  * is created over the `{ id; input; attempts }` column map, which `Infer`s to exactly
120
122
  * that row. The store holds only OUTSTANDING work (completed entries are `remove`d), so
121
123
  * `load` on startup yields precisely the entries to resume.
@@ -136,27 +138,27 @@ export declare function createQueue<TInput, TResult>(options: QueueOptions<TInpu
136
138
  export declare class DatabaseQueueStore<TInput> implements QueueStoreInterface<TInput> {
137
139
  #private;
138
140
  /**
139
- * Wrap a table as a queue store.
141
+ * Wraps a table as a queue store.
140
142
  *
141
143
  * @param table - The {@link TableInterface} holding the outstanding entries — its
142
144
  * row is a {@link StoredEntry}`<TInput>` (the `{ id; input; attempts }` shape)
143
145
  */
144
146
  constructor(table: TableInterface<StoredEntry<TInput>>);
145
- /** Upsert an entry by its `id` (a re-`save` of an existing `id` overwrites it). */
147
+ /** Upserts an entry by its `id` (a re-`save` of an existing `id` overwrites it). */
146
148
  save(entry: StoredEntry<TInput>): Promise<void>;
147
- /** Drop a finished entry by `id`; absent is a no-op (no throw). */
149
+ /** Drops a finished entry by `id`; absent is a no-op (no throw). */
148
150
  remove(id: string): Promise<void>;
149
- /** Every outstanding entry — the work to resume after a restart. */
151
+ /** Returns every outstanding entry — the work to resume after a restart. */
150
152
  load(): Promise<ReadonlyArray<StoredEntry<TInput>>>;
151
- /** Empty the store — drop every outstanding entry. */
153
+ /** Empties the store — drops every outstanding entry. */
152
154
  clear(): Promise<void>;
153
155
  }
154
156
 
155
157
  /**
156
- * Determine whether a value is a valid queue concurrency.
158
+ * Determines whether a value is a valid queue concurrency.
157
159
  *
158
160
  * @param value - Value to inspect
159
- * @returns Whether the value is a positive safe integer
161
+ * @returns True if the value is a positive safe integer; false otherwise
160
162
  *
161
163
  * @example
162
164
  * ```ts
@@ -167,10 +169,11 @@ export declare class DatabaseQueueStore<TInput> implements QueueStoreInterface<T
167
169
  export declare function isQueueConcurrency(value: unknown): value is number;
168
170
 
169
171
  /**
170
- * Determine whether an unknown value is a {@link QueueError}.
172
+ * Determines whether an unknown value is a {@link QueueError}.
171
173
  *
172
174
  * @param value - The value to inspect
173
- * @returns `true` only for a `QueueError`; hostile values return `false`
175
+ * @returns True if the value is a real `QueueError` instance; false otherwise, including for
176
+ * a hostile value
174
177
  *
175
178
  * @example
176
179
  * ```ts
@@ -184,10 +187,10 @@ export declare function isQueueConcurrency(value: unknown): value is number;
184
187
  export declare function isQueueError(value: unknown): value is QueueError;
185
188
 
186
189
  /**
187
- * Determine whether a value is a valid queue retry count.
190
+ * Determines whether a value is a valid queue retry count.
188
191
  *
189
192
  * @param value - Value to inspect
190
- * @returns Whether the value is a nonnegative safe integer
193
+ * @returns True if the value is a nonnegative safe integer; false otherwise
191
194
  *
192
195
  * @example
193
196
  * ```ts
@@ -198,10 +201,10 @@ export declare function isQueueError(value: unknown): value is QueueError;
198
201
  export declare function isQueueRetries(value: unknown): value is number;
199
202
 
200
203
  /**
201
- * Determine whether a value is a native abort signal usable by the queue.
204
+ * Determines whether a value is a native abort signal usable by the queue.
202
205
  *
203
206
  * @param value - Value to inspect
204
- * @returns Whether the value carries the native `AbortSignal` internal slot
207
+ * @returns True if the value carries the native `AbortSignal` internal slot; false otherwise
205
208
  *
206
209
  * @example
207
210
  * ```ts
@@ -212,10 +215,11 @@ export declare function isQueueRetries(value: unknown): value is number;
212
215
  export declare function isQueueSignal(value: unknown): value is AbortSignal;
213
216
 
214
217
  /**
215
- * Determine whether a value is a valid queue timeout.
218
+ * Determines whether a value is a valid queue timeout.
216
219
  *
217
220
  * @param value - Value to inspect
218
- * @returns Whether the value is an integer within the native timer range, inclusive
221
+ * @returns True if the value is an integer within the native timer range,
222
+ * inclusive; false otherwise
219
223
  *
220
224
  * @example
221
225
  * ```ts
@@ -226,7 +230,27 @@ export declare function isQueueSignal(value: unknown): value is AbortSignal;
226
230
  export declare function isQueueTimeout(value: unknown): value is number;
227
231
 
228
232
  /**
229
- * An in-memory store owning validated, immutable JSON snapshots of outstanding entries.
233
+ * Checks whether a value is a valid stored queue entry.
234
+ *
235
+ * @remarks
236
+ * The single test for what a {@link StoredEntry} is, shared by the queue's `restore`
237
+ * boundary and the memory store's `save` boundary. `input` carries the caller's own
238
+ * payload type, so only its presence is checked.
239
+ *
240
+ * @param value - Value to inspect
241
+ * @returns True if the value is a record holding a string `id`, an `input` member, and a
242
+ * nonnegative safe-integer `attempts`; false otherwise
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * isStoredEntry({ id: 'job-1', input: 'task', attempts: 0 }) // true
247
+ * isStoredEntry({ id: 'job-1', input: 'task', attempts: -1 }) // false
248
+ * ```
249
+ */
250
+ export declare function isStoredEntry(value: unknown): value is StoredEntry<unknown>;
251
+
252
+ /**
253
+ * Represents an in-memory store owning validated, immutable JSON snapshots of outstanding entries.
230
254
  *
231
255
  * @typeParam TInput - The contract shape for each stored input
232
256
  *
@@ -242,23 +266,23 @@ export declare function isQueueTimeout(value: unknown): value is number;
242
266
  export declare class MemoryQueueStore<TInput extends ContractShape> implements QueueStoreInterface<Infer<TInput>> {
243
267
  #private;
244
268
  /**
245
- * Create an in-memory queue store.
269
+ * Creates an in-memory queue store.
246
270
  *
247
271
  * @param input - Runtime contract for each stored input
248
272
  */
249
273
  constructor(input: TInput);
250
- /** Upsert a validated, owned snapshot under the entry's id. */
274
+ /** Upserts a validated, owned snapshot under the entry's id. */
251
275
  save(entry: StoredEntry<Infer<TInput>>): Promise<void>;
252
- /** Remove an entry; an absent id is a no-op. */
276
+ /** Removes an entry; an absent id is a no-op. */
253
277
  remove(id: string): Promise<void>;
254
- /** Return fresh immutable snapshots of every outstanding entry. */
278
+ /** Returns fresh immutable snapshots of every outstanding entry. */
255
279
  load(): Promise<ReadonlyArray<StoredEntry<Infer<TInput>>>>;
256
- /** Remove every outstanding entry. */
280
+ /** Removes every outstanding entry. */
257
281
  clear(): Promise<void>;
258
282
  }
259
283
 
260
284
  /**
261
- * A concurrent, cooperative FIFO job queue with optional outstanding-work persistence.
285
+ * Represents a concurrent, cooperative FIFO job queue with optional outstanding-work persistence.
262
286
  *
263
287
  * @typeParam TInput - The work input each entry carries
264
288
  * @typeParam TResult - The value each entry resolves
@@ -272,7 +296,7 @@ export declare class MemoryQueueStore<TInput extends ContractShape> implements Q
272
296
  export declare class Queue<TInput, TResult> implements QueueInterface<TInput, TResult> {
273
297
  #private;
274
298
  /**
275
- * Create a queue.
299
+ * Creates a queue.
276
300
  *
277
301
  * @param options - Handler, validated execution limits, persistence, and observation hooks
278
302
  */
@@ -283,39 +307,56 @@ export declare class Queue<TInput, TResult> implements QueueInterface<TInput, TR
283
307
  get paused(): boolean;
284
308
  get stopped(): boolean;
285
309
  /**
286
- * Reserve and submit one FIFO entry.
310
+ * Reserves and submits one FIFO entry.
287
311
  *
288
312
  * @param input - Handler input
289
313
  * @param options - Optional id, retry/timeout overrides, and entry abort signal
290
314
  * @returns The entry's settle-once execution promise
291
- * @throws {QueueError} Synchronously when an option is inaccessible or invalid
315
+ * @throws {QueueError} Thrown synchronously when an option is inaccessible or invalid.
292
316
  */
293
317
  enqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult>;
294
- /** Load and accept every outstanding stored entry from the current lifecycle generation. */
318
+ /**
319
+ * Loads and accepts every outstanding stored entry from the current lifecycle generation.
320
+ *
321
+ * @returns A promise that settles after every loaded entry is reserved and accepted
322
+ * @throws {QueueError} Thrown when the store's load fails or returns a malformed entry.
323
+ */
295
324
  restore(): Promise<void>;
296
- /** Begin or restart worker execution unless the queue is terminal. */
325
+ /** Begins or restarts worker execution unless the queue is terminal. */
297
326
  start(): void;
298
- /** Reject non-active work and await current-loop and durable cleanup quiescence. */
327
+ /**
328
+ * Rejects non-active work and awaits current-loop and durable cleanup quiescence.
329
+ *
330
+ * @returns The stable stop barrier
331
+ */
299
332
  stop(): Promise<void>;
300
- /** Suspend new execution while leaving active entries untouched. */
333
+ /** Suspends new execution while leaving active entries untouched. */
301
334
  pause(): void;
302
- /** Continue execution after a pause. */
335
+ /** Continues execution after a pause. */
303
336
  resume(): void;
304
337
  /**
305
- * Cancel the queue and await owned cleanup.
338
+ * Cancels the queue and awaits owned cleanup.
306
339
  *
307
340
  * @param reason - Optional cause carried by the coded abort error
308
341
  * @returns The stable abort barrier
309
342
  */
310
343
  abort(reason?: unknown): Promise<void>;
311
- /** Reject non-active work and await its durable cleanup. */
344
+ /**
345
+ * Rejects non-active work and awaits its durable cleanup.
346
+ *
347
+ * @returns A promise that settles after every affected removal completes
348
+ */
312
349
  clear(): Promise<void>;
313
- /** Tear down once, destroying the emitter only after cleanup finishes. */
350
+ /**
351
+ * Tears down once, destroying the emitter only after cleanup finishes.
352
+ *
353
+ * @returns The stable destroy barrier
354
+ */
314
355
  destroy(): Promise<void>;
315
356
  }
316
357
 
317
358
  /**
318
- * Machine-readable queue failure categories.
359
+ * Represents the machine-readable queue failure categories.
319
360
  *
320
361
  * @example
321
362
  * ```ts
@@ -325,10 +366,32 @@ export declare class Queue<TInput, TResult> implements QueueInterface<TInput, TR
325
366
  export declare type QueueCode = 'invalid' | 'duplicate' | 'stopped' | 'aborted' | 'destroyed' | 'cleared' | 'timeout' | 'store' | 'cleanup';
326
367
 
327
368
  /**
328
- * Per-entry options for `enqueue`.
369
+ * Represents the per-attempt context a queue handler receives.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const handler: QueueHandler<string, string> = (input, { id, signal }) =>
374
+ * signal.aborted ? id : input
375
+ * ```
376
+ */
377
+ export declare interface QueueContext {
378
+ /**
379
+ * Holds the entry's stable id — equal across every attempt and across a crash-replay
380
+ * (`restore` re-runs an entry under its original id). Durable persistence is
381
+ * at-least-once (a crash between handler-success and the store's `remove`, or a
382
+ * failed `remove`, re-runs the entry), so use this id to make a handler idempotent
383
+ * — de-dup against it over the replay window.
384
+ */
385
+ readonly id: string;
386
+ /** Fires on the per-attempt timeout, a queue-level abort, or the entry's own signal. */
387
+ readonly signal: AbortSignal;
388
+ }
389
+
390
+ /**
391
+ * Represents the per-entry options for `enqueue`.
329
392
  *
330
393
  * @remarks
331
- * - `id` — a trace label for the entry; defaults to a random UUID.
394
+ * - `id` — a trace label for the entry. Default: a random UUID.
332
395
  * - `retries` — extra attempts after the first on failure (or a per-attempt
333
396
  * timeout); overrides the queue default. A queue-level abort never retries.
334
397
  * - `timeout` — the nonnegative integer per-attempt deadline in milliseconds, at most
@@ -349,7 +412,7 @@ export declare interface QueueEntryOptions {
349
412
  }
350
413
 
351
414
  /**
352
- * Error carrying a machine-readable queue category and optional context.
415
+ * Represents a failure carrying a machine-readable queue category and optional context.
353
416
  *
354
417
  * @example
355
418
  * ```ts
@@ -361,7 +424,7 @@ export declare class QueueError extends Error {
361
424
  readonly code: QueueCode;
362
425
  readonly context: QueueErrorContext | undefined;
363
426
  /**
364
- * Create a queue error.
427
+ * Creates a queue error.
365
428
  *
366
429
  * @param message - Human-readable failure description
367
430
  * @param options - Machine-readable category, optional context, and optional cause
@@ -370,7 +433,7 @@ export declare class QueueError extends Error {
370
433
  }
371
434
 
372
435
  /**
373
- * Structured context carried by a {@link QueueError}.
436
+ * Represents the structured context carried by a {@link QueueError}.
374
437
  *
375
438
  * @example
376
439
  * ```ts
@@ -379,13 +442,13 @@ export declare class QueueError extends Error {
379
442
  */
380
443
  export declare interface QueueErrorContext {
381
444
  readonly id?: string;
382
- readonly option?: 'id' | 'concurrency' | 'retries' | 'timeout' | 'signal';
445
+ readonly option?: QueueOption;
383
446
  readonly operation?: 'save' | 'remove' | 'load' | 'clear';
384
447
  readonly value?: unknown;
385
448
  }
386
449
 
387
450
  /**
388
- * Construction options for a {@link QueueError}.
451
+ * Represents the construction options for a {@link QueueError}.
389
452
  *
390
453
  * @example
391
454
  * ```ts
@@ -399,7 +462,7 @@ export declare interface QueueErrorOptions {
399
462
  }
400
463
 
401
464
  /**
402
- * The push observation surface of a {@link QueueInterface} (AGENTS §13) — the lifecycle
465
+ * Represents the push observation surface of a {@link QueueInterface} — the lifecycle
403
466
  * moments a fire-and-forget observer (logging, metrics, tracing) subscribes to, ALONGSIDE
404
467
  * the per-entry `enqueue` promise.
405
468
  *
@@ -407,15 +470,15 @@ export declare interface QueueErrorOptions {
407
470
  * {@link QueueInterface}'s own `TResult` — so the map is `QueueEventMap<TResult>`.
408
471
  *
409
472
  * @remarks
410
- * Listener isolation is the emitter's (AGENTS §13): every event is emitted directly and a
473
+ * Listener isolation is the emitter's: every event is emitted directly and a
411
474
  * listener throw is routed to the emitter's OWN `error` handler (the `error` option), never
412
475
  * onto this domain map and never into the cooperative wake-park / settle-once engine — so a
413
476
  * buggy observer can never reorder, throw into, or corrupt the queue. Every emit sits AFTER
414
477
  * the relevant wake / park / settle transition, so observation is purely a side-channel: a
415
- * throwing observer cannot unbalance `active` or strand a parked worker. Subscribe via
478
+ * throwing observer cannot unbalance `active` or strand a parked worker. Subscribe through
416
479
  * `queue.emitter.on(...)`.
417
480
  *
418
- * Declared as a `type` alias (not `interface extends EventMap`, §4.5 — `EventMap` is a
481
+ * Declared as a `type` alias (not `interface extends EventMap` — `EventMap` is a
419
482
  * `type` kind): a type-literal satisfies the `EventMap` constraint
420
483
  * (`Record<string, readonly unknown[]>`) structurally, whereas an interface lacks the
421
484
  * required index signature.
@@ -426,44 +489,22 @@ export declare interface QueueErrorOptions {
426
489
  * ```
427
490
  */
428
491
  export declare type QueueEventMap<TResult> = {
429
- /** An entry was accepted (and durably persisted, when a store is set) — its id. */
492
+ /** Signals that an entry was accepted (and durably persisted, when a store is set) — its id. */
430
493
  readonly enqueue: readonly [id: string];
431
- /** An attempt began running — the entry's id (after it was dequeued, in flight). */
494
+ /** Signals that an attempt began running — the entry's id (after it was dequeued, in flight). */
432
495
  readonly start: readonly [id: string];
433
- /** A failed attempt is being retried — the entry id + completed-attempt count. */
496
+ /** Signals that a failed attempt is being retried — the entry id + completed-attempt count. */
434
497
  readonly retry: readonly [id: string, attempt: number];
435
- /** An entry settled successfully — its id + the resolved result. */
498
+ /** Signals that an entry settled successfully — its id + the resolved result. */
436
499
  readonly success: readonly [id: string, result: TResult];
437
- /** An entry settled with a terminal failure — its id + the error (always `unknown`). */
500
+ /** Signals that an entry settled with a terminal failure — its id + the error (always `unknown`). */
438
501
  readonly failure: readonly [id: string, error: unknown];
439
- /** The queue was aborted — its coded abort error. */
502
+ /** Signals that the queue was aborted — its coded abort error. */
440
503
  readonly abort: readonly [reason: unknown];
441
- /** The queue transitioned to no reserved live ids (drained). */
504
+ /** Signals that the queue transitioned to no reserved live ids (drained). */
442
505
  readonly drain: readonly [];
443
506
  };
444
507
 
445
- /**
446
- * The per-attempt execution handle a queue handler receives.
447
- *
448
- * @example
449
- * ```ts
450
- * const handler: QueueHandler<string, string> = (input, { id, signal }) =>
451
- * signal.aborted ? id : input
452
- * ```
453
- */
454
- export declare interface QueueExecution {
455
- /**
456
- * The entry's stable id — equal across every attempt and across a crash-replay
457
- * (`restore` re-runs an entry under its original id). Durable persistence is
458
- * at-least-once (a crash between handler-success and the store's `remove`, or a
459
- * failed `remove`, re-runs the entry), so use this id to make a handler idempotent
460
- * — de-dup against it over the replay window.
461
- */
462
- readonly id: string;
463
- /** Fires on the per-attempt timeout, a queue-level abort, or the entry's own signal. */
464
- readonly signal: AbortSignal;
465
- }
466
-
467
508
  /**
468
509
  * Runs one queued entry's work; may reject to trigger a retry.
469
510
  *
@@ -475,18 +516,18 @@ export declare interface QueueExecution {
475
516
  * const handler: QueueHandler<number, number> = (input) => input * 2
476
517
  * ```
477
518
  */
478
- export declare type QueueHandler<TInput, TResult> = (input: TInput, execution: QueueExecution) => Promise<TResult> | TResult;
519
+ export declare type QueueHandler<TInput, TResult> = (input: TInput, context: QueueContext) => Promise<TResult> | TResult;
479
520
 
480
521
  /**
481
- * A concurrent, cooperative job queue.
522
+ * Represents a concurrent, cooperative job queue.
482
523
  *
483
524
  * @remarks
484
- * Exposes a typed {@link emitter} (AGENTS §13) carrying its lifecycle moments
525
+ * Exposes a typed {@link emitter} carrying its lifecycle moments
485
526
  * ({@link QueueEventMap}) for fire-and-forget observers, ALONGSIDE each `enqueue` promise.
486
527
  * Emitting is observation-only — every event fires AFTER the relevant wake / park / settle
487
528
  * transition, so a buggy observer can never reorder or corrupt the wake-park / settle-once
488
529
  * engine: the emitter isolates a listener throw and routes it to its `error` handler (the
489
- * `error` option), never the engine. Subscribe via `queue.emitter.on(...)`.
530
+ * `error` option), never the engine. Subscribe through `queue.emitter.on(...)`.
490
531
  *
491
532
  * @example
492
533
  * ```ts
@@ -494,47 +535,62 @@ export declare type QueueHandler<TInput, TResult> = (input: TInput, execution: Q
494
535
  * ```
495
536
  */
496
537
  export declare interface QueueInterface<TInput, TResult> {
538
+ /** Holds the typed push observation surface carrying this queue's {@link QueueEventMap} moments. */
497
539
  readonly emitter: EmitterInterface<QueueEventMap<TResult>>;
540
+ /** Counts the reserved live entries — admitting, pending, claimed, or awaiting cleanup. */
498
541
  readonly count: number;
542
+ /** Counts the claimed entries in flight, never above the queue's concurrency. */
499
543
  readonly active: number;
544
+ /** Reports the pause state: true while `pause` has suspended dequeuing; false otherwise. */
500
545
  readonly paused: boolean;
546
+ /** Reports the halt state: true after `stop` or `abort` has halted the queue; false otherwise. */
501
547
  readonly stopped: boolean;
502
- /** Reserve and submit one FIFO entry. */
548
+ /** Reserves and submits one FIFO entry. */
503
549
  enqueue(input: TInput, options?: QueueEntryOptions): Promise<TResult>;
504
- /** Re-enqueue outstanding entries loaded from the store; no-op without a store. */
550
+ /** Re-enqueues outstanding entries loaded from the store; no-op without a store. */
505
551
  restore(): Promise<void>;
506
- /** Begin or restart worker execution. */
552
+ /** Begins or restarts worker execution. */
507
553
  start(): void;
508
- /** Reject non-active work and await current-loop/durable quiescence. */
554
+ /** Rejects non-active work and awaits current-loop/durable quiescence. */
509
555
  stop(): Promise<void>;
510
- /** Suspend new execution resumably. */
556
+ /** Suspends new execution resumably. */
511
557
  pause(): void;
512
- /** Continue execution after a pause. */
558
+ /** Continues execution after a pause. */
513
559
  resume(): void;
514
- /** Cancel active work, reject pending work, and await cleanup. */
560
+ /** Cancels active work, rejects pending work, and awaits cleanup. */
515
561
  abort(reason?: unknown): Promise<void>;
516
- /** Reject non-active work and await its durable cleanup. */
562
+ /** Rejects non-active work and awaits its durable cleanup. */
517
563
  clear(): Promise<void>;
518
- /** Tear down idempotently and destroy observation last. */
564
+ /** Tears down idempotently and destroys observation last. */
519
565
  destroy(): Promise<void>;
520
566
  }
521
567
 
522
568
  /**
523
- * Options for `createQueue`.
569
+ * Represents the construction and per-entry option keys a queue validates.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * const option: QueueOption = 'concurrency'
574
+ * ```
575
+ */
576
+ export declare type QueueOption = 'id' | 'concurrency' | 'retries' | 'timeout' | 'signal';
577
+
578
+ /**
579
+ * Represents the options for `createQueue`.
524
580
  *
525
581
  * @remarks
526
582
  * - `handler` — runs each entry's work; rejecting triggers a retry while attempts
527
583
  * remain.
528
- * - `concurrency` — the maximum number of entries in flight at once; defaults to
529
- * `1` and must be a positive safe integer.
530
- * - `retries` — the default extra attempts per entry on failure; defaults to `0`
531
- * and must be a nonnegative safe integer.
532
- * - `timeout` — the default per-attempt deadline in integer milliseconds; defaults to zero
533
- * and must be between zero and `2_147_483_647`, inclusive.
584
+ * - `concurrency` — the maximum number of entries in flight at once. Default: `1`.
585
+ * Must be a positive safe integer.
586
+ * - `retries` — the default extra attempts per entry on failure. Default: `0`.
587
+ * Must be a nonnegative safe integer.
588
+ * - `timeout` — the default per-attempt deadline in integer milliseconds. Default: `0`,
589
+ * which disables the deadline. Must be between `0` and `2_147_483_647`, inclusive.
534
590
  * - `store` — durable backing; outstanding entries survive a restart; call
535
591
  * `restore()` to re-run them.
536
- * - `on` — the reserved {@link EmitterHooks} key (§8): initial listeners for the queue's
537
- * {@link QueueEventMap}, wired at construction (e.g. `{ drain: () => log('idle') }`).
592
+ * - `on` — the reserved {@link EmitterHooks} key: initial listeners for the queue's
593
+ * {@link QueueEventMap}, wired at construction, for example `{ drain: () => log('idle') }`.
538
594
  *
539
595
  * @example
540
596
  * ```ts
@@ -543,7 +599,7 @@ export declare interface QueueInterface<TInput, TResult> {
543
599
  */
544
600
  export declare interface QueueOptions<TInput, TResult> {
545
601
  readonly on?: EmitterHooks<QueueEventMap<TResult>>;
546
- /** The emitter's listener-error handler (AGENTS §13) — a listener throw routes here, not to a domain event. */
602
+ /** Holds the emitter's listener-error handler — a listener throw routes here, not to a domain event. */
547
603
  readonly error?: EmitterErrorHandler;
548
604
  readonly handler: QueueHandler<TInput, TResult>;
549
605
  readonly concurrency?: number;
@@ -553,14 +609,14 @@ export declare interface QueueOptions<TInput, TResult> {
553
609
  }
554
610
 
555
611
  /**
556
- * Durable backing for a Queue's outstanding entries.
612
+ * Represents the durable backing for a Queue's outstanding entries.
557
613
  *
558
614
  * @remarks
559
615
  * The store holds ONLY work that has not yet completed: `save` upserts an entry
560
616
  * (by its `id`), `remove` drops a finished one, `load` returns everything
561
617
  * outstanding (to restore a queue after a restart), and `clear` empties it. It is
562
- * a minimal interface (AGENTS §21) over the `databases` layer — a queue's durable
563
- * state is just a table — so any `DriverInterface` backend (memory, JSON, SQLite)
618
+ * a minimal interface over the `@orkestrel/database` layer — a queue's durable
619
+ * state is a table — so any `DriverInterface` backend (memory, JSON, SQLite)
564
620
  * persists it without the store knowing which.
565
621
  *
566
622
  * @typeParam TInput - The work input each {@link StoredEntry} carries
@@ -578,7 +634,28 @@ export declare interface QueueStoreInterface<TInput> {
578
634
  }
579
635
 
580
636
  /**
581
- * A durably persisted, still-outstanding queue entry — re-run after a restart.
637
+ * Reads one named option from a caller-supplied entry options object.
638
+ *
639
+ * @remarks
640
+ * The property is read exactly once, inside a boundary that contains a throwing
641
+ * getter. An absent options object reads nothing and yields `undefined`.
642
+ *
643
+ * @param options - The caller's own entry options, or `undefined`
644
+ * @param option - The option key to read
645
+ * @param message - The failure description the thrown error carries
646
+ * @returns The value the property held, or `undefined` when no options object was supplied
647
+ * @throws {QueueError} Thrown when reading the property throws, coded `invalid` with the
648
+ * option in its context.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * readOption({ retries: 2 }, 'retries', 'queue retries could not be read') // 2
653
+ * ```
654
+ */
655
+ export declare function readOption(options: QueueEntryOptions | undefined, option: keyof QueueEntryOptions, message: string): unknown;
656
+
657
+ /**
658
+ * Represents a durably persisted, still-outstanding queue entry — re-run after a restart.
582
659
  *
583
660
  * @remarks
584
661
  * The store holds only entries that have NOT yet completed, so what `load`
@@ -598,4 +675,22 @@ export declare interface StoredEntry<TInput> {
598
675
  readonly attempts: number;
599
676
  }
600
677
 
678
+ /**
679
+ * Validates one already-read queue option against its guard.
680
+ *
681
+ * @param value - The option value to check
682
+ * @param guard - The total guard the value must satisfy
683
+ * @param option - The option key the failure context reports
684
+ * @param message - The failure description the thrown error carries
685
+ * @returns The same value, narrowed by the guard
686
+ * @throws {QueueError} Thrown when the guard refuses the value, coded `invalid` with the
687
+ * option and the refused value in its context.
688
+ *
689
+ * @example
690
+ * ```ts
691
+ * validateOption(4, isQueueConcurrency, 'concurrency', 'queue concurrency must be positive') // 4
692
+ * ```
693
+ */
694
+ export declare function validateOption<TValue>(value: unknown, guard: Guard<TValue>, option: QueueOption, message: string): TValue;
695
+
601
696
  export { }