StorageTransaction
Implements
Index
Properties
Accessors
Methods
Properties
readonlyjournal
The ordered, append-only journal — the source of truth for commit, introspection and reads.
readonlypolicy
Per-storage-type write policy.
Accessors
datasetItems
Items pushed to datasets during the transaction, in push order.
Returns { datasetId: string; item: Dictionary }[]
enqueuedUrls
URLs enqueued to request queues during the transaction, under either write policy. Recorded as requested, so duplicate, already-present and backend-rejected URLs are included.
One gap: unless a caller of
addRequestsBatched()waits for every chunk (waitForAllRequestsToBeAddedormaxNewRequests, both of which enqueueLinks sets when a crawl limit applies), the chunks after the first are added by a background writer that outlives the transaction and is not recorded here.Returns { label?: string; url: string }[]
isActive
trueonly whilestate === 'open'. This is the single predicate every storage operation consults — operations performed after the transaction is closed pass through to the real backend.Returns boolean
keyValueStoreChanges
Key-value store changes made during the transaction, keyed by store id, last write per key.
Returns Record<string, Record<string, { changedValue: unknown; options?: RecordOptions }>>
state
Returns StorageTransactionState
Methods
commit
Replays the journaled writes into real storage. A no-op unless the transaction is
open.The transaction transitions to
committingbefore anything is flushed, so a commit that throws partway lands infailed(never back inopen) and subsequent storage operations pass through rather than recording into a dead transaction. Delivery is at-least-once — a commit that fails partway may have applied some of the writes already.Returns Promise<void>
dispose
Releases the journal and the write-time snapshots it holds. Must be called for every terminal state,
failedincluded. Idempotent, never throws, and does not changestate. Any StorageTransactionView of this transaction is only valid until this is called.Returns void
rollback
Discards the journaled writes. A no-op unless the transaction is
open— in particular, calling it after a successfulcommit()(which the crawler's error handling can legitimately do) does nothing and never throws.Returns void
run
Runs
callbackwith this transaction installed in the async context.Parameters
callback: () => Awaitable<T>
Returns Promise<T>
A storage transaction scoped to a request's lifecycle. Writes made through the storage frontends (Dataset, KeyValueStore, RequestQueue) while the transaction is active are recorded rather than applied; on
commit()they are replayed into real storage, onrollback()they are dropped. Reads consult the recorded writes first, so a handler sees its own writes.Create one with createStorageTransaction (explicit commit/rollback) or withStorageTransaction (scoped sugar). Crawlers open one automatically around every request handler unless
transactionalStorage: falseis set.