SnapshotStore
Defined in: snapshot.ts:130
Storage-backed snapshot operations. Constructed over any FlagsStorage. The runtime provider uses only the read methods.
Example
Section titled “Example”import { SnapshotStore } from "@xtandard/flags";import { createMemoryStorage } from "@xtandard/flags/storage/memory";
const storage = createMemoryStorage();const store = new SnapshotStore(storage);
const draft = { projectKey: "default", environmentKey: "staging", flags: {} };const snapshot = await store.publish(draft, { createdBy: { id: "ci" } });// snapshot.version === "v1"
const active = await store.getActiveSnapshot("default", "staging");// active?.version === "v1"Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SnapshotStore(storage): SnapshotStore;Defined in: snapshot.ts:131
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
storage |
KvStorage |
Returns
Section titled “Returns”SnapshotStore
Methods
Section titled “Methods”appendAudit()
Section titled “appendAudit()”appendAudit( projectKey, environmentKey, entry): Promise<void>;Defined in: snapshot.ts:242
Append an audit entry to the immutable, append-only log. Every event is kept (never keyed by version), so a rollback to an earlier version does not overwrite that version’s original publish record.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
entry |
AuditEntry |
Returns
Section titled “Returns”Promise<void>
deleteSnapshot()
Section titled “deleteSnapshot()”deleteSnapshot( projectKey, environmentKey, version): Promise<void>;Defined in: snapshot.ts:176
Remove a snapshot’s payload (does not touch active_version or audit). Guards (never the active/latest version) live in the core, which also removes the copy in runtime storage — use ../core.FlagsCore.deleteSnapshot.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
version |
string |
Returns
Section titled “Returns”Promise<void>
getActiveSnapshot()
Section titled “getActiveSnapshot()”getActiveSnapshot(projectKey, environmentKey): Promise<Snapshot | null>;Defined in: snapshot.ts:148
Read the currently active snapshot (active_version → snapshot), or null.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
Returns
Section titled “Returns”Promise<Snapshot | null>
getActiveVersion()
Section titled “getActiveVersion()”getActiveVersion(projectKey, environmentKey): Promise<string | null>;Defined in: snapshot.ts:134
Current active version string, or null if nothing is published.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
Returns
Section titled “Returns”Promise<string | null>
getDraft()
Section titled “getDraft()”getDraft(projectKey, environmentKey): Promise<Draft | null>;Defined in: snapshot.ts:269
Read the working draft, or null.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
Returns
Section titled “Returns”Promise<Draft | null>
getSnapshot()
Section titled “getSnapshot()”getSnapshot( projectKey, environmentKey, version): Promise<Snapshot | null>;Defined in: snapshot.ts:139
Read a specific snapshot by version.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
version |
string |
Returns
Section titled “Returns”Promise<Snapshot | null>
listAudit()
Section titled “listAudit()”listAudit(projectKey, environmentKey): Promise<AuditEntry[]>;Defined in: snapshot.ts:263
List audit entries, newest first.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
Returns
Section titled “Returns”Promise<AuditEntry[]>
listVersions()
Section titled “listVersions()”listVersions(projectKey, environmentKey): Promise<string[]>;Defined in: snapshot.ts:155
List all snapshot version strings, newest first.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
Returns
Section titled “Returns”Promise<string[]>
publish()
Section titled “publish()”publish(draft, options?): Promise<Snapshot>;Defined in: snapshot.ts:193
Compile the draft, persist it as the next snapshot, flip active_version, and append an audit entry. Returns the new snapshot.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
draft |
Draft |
options? |
{ createdBy?: Actor | null; message?: string; } |
options.createdBy? |
Actor | null |
options.message? |
string |
Returns
Section titled “Returns”Promise<Snapshot>
putDraft()
Section titled “putDraft()”putDraft(draft): Promise<void>;Defined in: snapshot.ts:274
Write the working draft.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
draft |
Draft |
Returns
Section titled “Returns”Promise<void>
putSnapshot()
Section titled “putSnapshot()”putSnapshot(snapshot): Promise<void>;Defined in: snapshot.ts:164
Persist a snapshot (does not change active_version).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
Snapshot |
Returns
Section titled “Returns”Promise<void>
replaceAudit()
Section titled “replaceAudit()”replaceAudit( projectKey, environmentKey, entries): Promise<void>;Defined in: snapshot.ts:254
Overwrite the audit log with entries (oldest-first, the stored order).
Used by retention pruning in the core; the removed entries are surfaced to
after hooks (audit.pruned) so they can be offloaded before they’re gone.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
entries |
AuditEntry[] |
Returns
Section titled “Returns”Promise<void>
rollback()
Section titled “rollback()”rollback( projectKey, environmentKey, targetVersion, options?): Promise<Snapshot>;Defined in: snapshot.ts:216
Flip active_version back to an existing snapshot and record an audit entry. Throws if the target version does not exist.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
targetVersion |
string |
options? |
{ by?: Actor | null; message?: string; } |
options.by? |
Actor | null |
options.message? |
string |
Returns
Section titled “Returns”Promise<Snapshot>
setActiveVersion()
Section titled “setActiveVersion()”setActiveVersion( projectKey, environmentKey, version): Promise<void>;Defined in: snapshot.ts:181
Set the active version pointer.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
projectKey |
string |
environmentKey |
string |
version |
string |
Returns
Section titled “Returns”Promise<void>