snapcap
API ReferenceInterfaces

DataStore

Interface: DataStore

Defined in: storage/data-store.ts:52

Persistent key-value storage interface — the SDK's pluggable persistence backbone.

Remarks

Implementations back the sandbox's localStorage / sessionStorage / indexedDB / cookie jar. Bring your own (Redis, S3, KMS, …) by satisfying this three-method async surface; pass an instance into new SnapcapClient({ dataStore }).

Values are arbitrary Uint8Array bytes — the SDK and bundle take care of serialization on top.

Example

Minimal in-memory implementation (essentially MemoryDataStore):

class MyStore implements DataStore {
  private map = new Map<string, Uint8Array>();
  async get(key: string)            { return this.map.get(key); }
  async set(key: string, v: Uint8Array) { this.map.set(key, v); }
  async delete(key: string)         { this.map.delete(key); }
}

See

Methods

delete()

delete(key: string): Promise<void>;

Defined in: storage/data-store.ts:74

Delete the entry at key. No-op if the key is absent.

Parameters

ParameterTypeDescription
keystringThe storage key to remove.

Returns

Promise<void>


get()

get(key: string): Promise<
  | Uint8Array<ArrayBufferLike>
| undefined>;

Defined in: storage/data-store.ts:59

Read the value at key.

Parameters

ParameterTypeDescription
keystringThe storage key.

Returns

Promise< | Uint8Array<ArrayBufferLike> | undefined>

The stored bytes, or undefined if the key is absent.


set()

set(key: string, value: Uint8Array): Promise<void>;

Defined in: storage/data-store.ts:68

Write value to key, overwriting any prior entry. Implementations SHOULD make this durable before resolving.

Parameters

ParameterTypeDescription
keystringThe storage key.
valueUint8ArrayThe bytes to store. Treat as immutable; the SDK never mutates the supplied buffer after passing it.

Returns

Promise<void>

On this page