Skip to content

SnapshotStore

Defined in: snapshot.ts:130

Storage-backed snapshot operations. Constructed over any FlagsStorage. The runtime provider uses only the read methods.

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"
new SnapshotStore(storage): SnapshotStore;

Defined in: snapshot.ts:131

Parameter Type
storage KvStorage

SnapshotStore

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.

Parameter Type
projectKey string
environmentKey string
entry AuditEntry

Promise<void>


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.

Parameter Type
projectKey string
environmentKey string
version string

Promise<void>


getActiveSnapshot(projectKey, environmentKey): Promise<Snapshot | null>;

Defined in: snapshot.ts:148

Read the currently active snapshot (active_version → snapshot), or null.

Parameter Type
projectKey string
environmentKey string

Promise<Snapshot | null>


getActiveVersion(projectKey, environmentKey): Promise<string | null>;

Defined in: snapshot.ts:134

Current active version string, or null if nothing is published.

Parameter Type
projectKey string
environmentKey string

Promise<string | null>


getDraft(projectKey, environmentKey): Promise<Draft | null>;

Defined in: snapshot.ts:269

Read the working draft, or null.

Parameter Type
projectKey string
environmentKey string

Promise<Draft | null>


getSnapshot(
projectKey,
environmentKey,
version
): Promise<Snapshot | null>;

Defined in: snapshot.ts:139

Read a specific snapshot by version.

Parameter Type
projectKey string
environmentKey string
version string

Promise<Snapshot | null>


listAudit(projectKey, environmentKey): Promise<AuditEntry[]>;

Defined in: snapshot.ts:263

List audit entries, newest first.

Parameter Type
projectKey string
environmentKey string

Promise<AuditEntry[]>


listVersions(projectKey, environmentKey): Promise<string[]>;

Defined in: snapshot.ts:155

List all snapshot version strings, newest first.

Parameter Type
projectKey string
environmentKey string

Promise<string[]>


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.

Parameter Type
draft Draft
options? { createdBy?: Actor | null; message?: string; }
options.createdBy? Actor | null
options.message? string

Promise<Snapshot>


putDraft(draft): Promise<void>;

Defined in: snapshot.ts:274

Write the working draft.

Parameter Type
draft Draft

Promise<void>


putSnapshot(snapshot): Promise<void>;

Defined in: snapshot.ts:164

Persist a snapshot (does not change active_version).

Parameter Type
snapshot Snapshot

Promise<void>


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.

Parameter Type
projectKey string
environmentKey string
entries AuditEntry[]

Promise<void>


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.

Parameter Type
projectKey string
environmentKey string
targetVersion string
options? { by?: Actor | null; message?: string; }
options.by? Actor | null
options.message? string

Promise<Snapshot>


setActiveVersion(
projectKey,
environmentKey,
version
): Promise<void>;

Defined in: snapshot.ts:181

Set the active version pointer.

Parameter Type
projectKey string
environmentKey string
version string

Promise<void>