Opt-in archive of named and automatic versions for one document. It stores
content-addressed checkpoints plus the committed transactions since each
one, through a host HistoryStorageAdapter. A grid that never imports this
module has no history state.
Calls that change the archive run one at a time. Each publishes atomically, so a failure or abort leaves the last durable version readable.
Members
Methods
constructor(options: HistoryArchiveOptions, limits: Readonly<HistoryLimits>, manifest: HistoryManifest);Private: use HistoryArchive.open.
deleteVersion: (id: string, signal?: AbortSignal) => Promise<void>;Delete one version. Records it shares with other versions stay.
One page of the changes between two retained versions. It lists the cells that changed, with before and after and who wrote them; sheets added, removed or changed outside their cells; and workbook fields that changed.
Both versions are rebuilt in private engine instances, or taken from the
last readVersion or restore, and compared in bounded windows by the
history diff kernel, a separate WASM module that loads on the first diff.
Rows and columns are aligned through the structural operations of the log,
so an inserted row does not make the rows below it changed. Only the
checkpoint pages that can differ are read and rebuilt (see
selectPages); the result is the same as rebuilding both versions whole.
A diff keeps nothing between pages: pass cursor to continue, and each
page rebuilds what it needs again.
Store the first checkpoint: a complete, committed snapshot of the document at time.
One bounded page of version metadata, newest first.
prune: (options?: PruneOptions) => Promise<void>;Remove old automatic versions to free space. It removes those made at or
before beforeTime (default: the age ceiling) and, oldest first, more
while the archive is above targetBytes. Named versions and every record
they need stay.
Rebuild the document of one version. A reader lease keeps its records
alive while a concurrent prune runs; the lease is released on every exit.
The archive keeps the rebuilt version for the calls that follow, until
releaseMemory.
record: (commit: CommittedTransaction, capture?: HistorySnapshotProvider, signal?: AbortSignal) => Promise<void>;Append one committed transaction. capture runs only when a checkpoint is
due and must return the committed document at commit.revision. An
automatic version is made after automaticIntervalMs of active time.
releaseMemory: () => void;Free the version that the archive keeps rebuilt between calls. The version history panel calls it when it closes and when its grid trims memory. A call that still uses the version frees it when it returns.
restoreVersion: (grid: Grid, id: string, scope: HistoryRestoreScope, options?: HistoryRestoreOptions) => Promise<ApplyTransactionResult>;Restore one version, or one sheet or range of it, on grid as one undoable
transaction. The version is rebuilt in a private engine instance, or taken
from the last readVersion or restore, and compared with the grid's
current document; the difference is committed as one atomic restore, which
SyncCoordinator sends as one transaction that is never rebased.
With options.sync, the coordinator must be online with no pending or
conflicted commits. When its server version is the archive head, the grid
holds the head, so only the checkpoint pages where the version and the head
differ are read and written again (see selectRestorePages).
A change to the grid while the version is read, or a scope that cuts a merged cell or hyperlink, rejects before anything changes. See the restore section of the persistence guide for what each scope covers.
saveVersion: (name: string, authorId: string, time: number, signal?: AbortSignal) => Promise<HistoryVersion>;Save the current version under a name. The host flushes pending edits first, so the name covers them.
Retained bytes and counts, read from the manifest without fetching any payload.
Open an archive by reading its manifest only; no workbook is loaded.
Declaration
View full TypeScript declaration
class HistoryArchive { constructor( ); deleteVersion: (id: string, signal?: AbortSignal) => Promise<void>; initialize: ( time: number, signal?: AbortSignal, ) => Promise<void>; prune: (options?: PruneOptions) => Promise<void>; readVersion: ( id: string, signal?: AbortSignal, record: ( signal?: AbortSignal, ) => Promise<void>; releaseMemory: () => void; restoreVersion: ( id: string, saveVersion: ( name: string, authorId: string, time: number, signal?: AbortSignal, static open: ( signal?: AbortSignal, ) => Promise<HistoryArchive>;}