import { Q as QueueItem } from '../index-DmoyvP-O.js'; export { E as EnqueueInput, a as QueueItemStatus, c as createQueue } from '../index-DmoyvP-O.js'; import '../runtime-types-f231H8Gq.js'; import '../core-sEWVgnpI.js'; import '@standard-schema/spec'; /** * internal/work-queue/adapter — the verb seam over the pure queue ops. * * The pure ops in `./ops` are the BLESSED transitions, but their names and * argument tuples (`enqueueOp(queue, input, now, id)`, `claimNextOp(queue, * now)`, …) and their `{ next, item }` / `{ next, changed }` result shapes are * the STORE's vocabulary, not the consumer's. An L2 composition that owns a * `QueueItem[]` slice (`monitored-run`, `saga`, `idempotent-intake`, * `fan-out`) used to import those ops by name and call them directly, so a * change to the op surface — or to `QueueItem`'s fields — cascaded to every * call site. * * `QueueAdapter` is the insulating interface: four VERBS (`enqueue` / * `claim` / `markDone` / `patch`) that consumers depend on instead of the raw * ops. The verbs keep the ops' pure `(queue, …) => { next, … }` contract — they * are pure array transforms, no I/O, no `Date.now` (the clock is injected as * `now`, exactly as the ops require it) — so a consumer folding the adapter * through its reducer stays inside invariant 2 (pure transitions). * * `queueAdapter()` is the canonical implementation, a thin binding of the * blessed ops. Because the verbs are the only surface consumers touch, a * `QueueItem` shape change (a new field, a renamed status, a different op * signature) is now absorbed HERE — re-bind the verb once — rather than at the * 4 consumer call sites. The `patch` verb deliberately takes the same * `(item) => item` closure `patchItemOp` does, so the one place a `QueueItem` * literal is spread stays the consumer's patch closure, never a re-rolled * record. * * This is an INTERNAL seam (no public-API port): consumers import the adapter * from this subpath the same way they imported the ops. The ops remain * exported for the in-process `createQueue` adapter (`./index`) and for any * call site that genuinely wants the op directly. */ /** * The verb interface over a `QueueItem[]` slice. Each verb mirrors a blessed * op's pure contract but speaks the consumer's lifecycle vocabulary, so the * consumer never names a `*Op` function or reaches into a `QueueItem` field it * did not put there. */ interface QueueAdapter { /** Append a new `pending` item stamped `now` under `id`. */ enqueue(queue: readonly QueueItem[], input: I, now: number, id: string): { next: QueueItem[]; item: QueueItem; }; /** * Claim the first `pending` item — flip it `running`, stamp `startedAt` to * `now` — or `null` if nothing is pending. */ claim(queue: readonly QueueItem[], now: number): { next: QueueItem[]; claimed: QueueItem; } | null; /** Drop the item `id` from the queue (completed runs leave the queue). */ markDone(queue: readonly QueueItem[], id: string): { next: QueueItem[]; changed: boolean; }; /** * Single-item transition: replace the item `id` with `patch(item)`. The * closure is the only place a `QueueItem` literal is constructed, so the * field shape stays out of the consumer's hands except through this verb. */ patch(queue: readonly QueueItem[], id: string, patch: (item: QueueItem) => QueueItem): { next: QueueItem[]; changed: boolean; }; } /** * The canonical `QueueAdapter`, binding each verb to its blessed op. Pure * and stateless — call once at module scope in a consumer and fold its verbs * through the reducer. A `QueueItem` shape change is absorbed by re-binding a * verb here, not at the consumers. */ declare function queueAdapter(): QueueAdapter; /** * Pure queue-lifecycle ops over `QueueItem[]` — the BLESSED delegation * surface for this package. * * Each op is `(queue, ...args) => { next, result? }`. No I/O, no Date.now * indirection beyond a plain call site — the adapter in `./index.ts` injects * `Store[]>` and orchestrates `load → mutate → save`. * * Substrate-agnostic by construction: nothing here references chrome.storage, * Cloudflare, or any concrete persistence layer. The audit-specific shape * (journeyId, projectId, ...) is lifted into the caller's `I` parameter. * * Importable two ways. The `createQueue(...)` adapter in `./index.ts` binds * these ops to a `Store` for in-process use (same one-shape-per-package rule * as `@demlik/tea/do`). L2 compositions that own their own Model slice * (`monitored-run`, `idempotent-intake`, …) instead reach these ops directly * from `internal/work-queue/ops`, so a status flip is delegated * here rather than re-rolled per call site. */ /** Append a new pending item. Returns the new queue and the created item. */ declare function enqueueOp(queue: readonly QueueItem[], input: I, now: number, id: string): { next: QueueItem[]; item: QueueItem; }; /** * Claim the first pending item by flipping it to `running` and stamping * `startedAt`. Returns the new queue and the claimed item, or `null` if no * pending item exists. */ declare function claimNextOp(queue: readonly QueueItem[], now: number): { next: QueueItem[]; claimed: QueueItem; } | null; /** * Done items leave the queue — completed runs live wherever the caller * persists their output. Returns the new queue (or the original reference if * no item matched, so the adapter can skip a save). */ declare function markDoneOp(queue: readonly QueueItem[], id: string): { next: QueueItem[]; changed: boolean; }; /** * Generic single-item status transition. Used by `markFailed`, * `markCancelled`, `retryItem`, `bindOutput`. The patch closure receives the * matched item and returns its replacement; returning the same reference is * fine (the adapter only saves on `changed`). */ declare function patchItemOp(queue: readonly QueueItem[], id: string, patch: (item: QueueItem) => QueueItem): { next: QueueItem[]; changed: boolean; }; /** Reset every `running` item back to `pending`, clearing `startedAt`. */ declare function resetRunningOp(queue: readonly QueueItem[]): { next: QueueItem[]; changed: boolean; }; /** Hard-delete an item regardless of status. */ declare function removeOp(queue: readonly QueueItem[], id: string): { next: QueueItem[]; changed: boolean; }; export { type QueueAdapter, QueueItem, claimNextOp, enqueueOp, markDoneOp, patchItemOp, queueAdapter, removeOp, resetRunningOp };