ProtectionQueue<TInput>
Generic protection queue engine — accepts inputs, processes them through a user-supplied function, and outputs sealed blobs via callbacks.
No dependencies on any app store, zustand, or tenant context. Backed by p-queue for concurrency control.
Example
const queue = new ProtectionQueue({
process: ({ blob, metadata }) => sealAsset(blob, metadata, config),
callbacks: {
onProtected: (id, sealed) => upload(sealed),
onError: (id, err) => console.error(err),
},
});
const id = queue.add({ blob: rawPhoto, metadata: labelContent });Type Parameters
| Type Parameter |
|---|
TInput |
Constructors
Constructor
new ProtectionQueue<TInput>(options): ProtectionQueue<TInput>;Parameters
| Parameter | Type |
|---|---|
options | ProtectionQueueOptions<TInput> |
Returns
ProtectionQueue<TInput>
Accessors
completed
Get Signature
get completed(): number;Number of completed items.
Returns
number
failed
Get Signature
get failed(): number;Number of failed items.
Returns
number
failures
Get Signature
get failures(): ProtectionQueueItem[];Snapshots of all failed items.
Returns
isAllDone
Get Signature
get isAllDone(): boolean;True when all items have either completed or failed.
Returns
boolean
pending
Get Signature
get pending(): number;Number of pending + processing items.
Returns
number
Methods
add()
add(input, customId?): string;Add an input to the protection queue. Returns a unique ID for tracking.
Parameters
| Parameter | Type | Description |
|---|---|---|
input | TInput | The data to process |
customId? | string | Optional custom ID; defaults to a generated UUID |
Returns
string
clear()
clear(): void;Clear all completed and failed items from tracking.
Returns
void
drain()
drain(): Promise<void>;Resolves when all currently queued items have been processed.
Returns
Promise<void>
getItem()
getItem(id):
| ProtectionQueueItem
| undefined;Get a snapshot of a specific queue item (returns a copy).
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
| ProtectionQueueItem
| undefined
getStatus()
getStatus(id): ProtectionStatus | undefined;Get the current status of a queued item.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
ProtectionStatus | undefined
remove()
remove(id): void;Remove an item from tracking (does not cancel in-flight work).
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
void
reset()
reset(): void;Cancel all pending items and clear the queue.
Returns
void