snapcap
API ReferenceClasses

MemoryDataStore

Class: MemoryDataStore

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

In-memory DataStore implementation — useful for tests and ephemeral sandboxes.

Remarks

Same surface as FileDataStore (including the synchronous helpers the Web Storage shims need) but with no persistence. Contents are lost when the process exits.

Example

import { SnapcapClient, MemoryDataStore } from "@snapcap/native";
const client = new SnapcapClient({
  dataStore: new MemoryDataStore(),
  username, password,
});

Implements

Constructors

Constructor

new MemoryDataStore(): MemoryDataStore;

Returns

MemoryDataStore

Methods

delete()

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

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

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

Parameters

ParameterTypeDescription
keystringThe storage key to remove.

Returns

Promise<void>

Implementation of

DataStore.delete


get()

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

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

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.

Implementation of

DataStore.get


getSync()

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

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

Synchronous read — for Web Storage shims that can't await.

Parameters

ParameterType
keystring

Returns

| Uint8Array<ArrayBufferLike> | undefined


keys()

keys(prefix?: string): string[];

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

Iterate stored keys, optionally filtered by prefix.

Parameters

ParameterTypeDescription
prefix?stringOptional prefix filter. When omitted, every key is returned.

Returns

string[]

A snapshot array of matching keys.


set()

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

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

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>

Implementation of

DataStore.set


setSync()

setSync(key: string, value: Uint8Array): void;

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

Synchronous variant of MemoryDataStore.set.

Parameters

ParameterType
keystring
valueUint8Array

Returns

void

On this page