snapcap
API ReferenceClasses

FileDataStore

Class: FileDataStore

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

File-backed DataStore implementation.

Remarks

A single JSON file holds all entries; loaded into memory at construction; eager flush on every set / delete.

Also exposes synchronous FileDataStore.getSync / FileDataStore.setSync / FileDataStore.keys for the Web Storage shims, which implement the synchronous Web Storage API.

Example

import { SnapcapClient, FileDataStore } from "@snapcap/native";
const dataStore = new FileDataStore(".tmp/auth/auth.json");
const client = new SnapcapClient({ dataStore, username, password });

Implements

Constructors

Constructor

new FileDataStore(filePath: string): FileDataStore;

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

Parameters

ParameterTypeDescription
filePathstringAbsolute or working-directory-relative path to the JSON file backing this store. Parent directories are created on first flush; the file may be absent at construction time.

Returns

FileDataStore

Methods

delete()

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

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

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:156

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:138

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

Parameters

ParameterTypeDescription
keystringThe storage key.

Returns

| Uint8Array<ArrayBufferLike> | undefined

The stored bytes, or undefined if absent.


keys()

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

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

Iterate cached keys, optionally filtered by prefix.

Parameters

ParameterTypeDescription
prefix?stringOptional prefix; only keys starting with this string are returned. When omitted, every key in the cache is returned.

Returns

string[]

A snapshot array of matching keys.


set()

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

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

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:150

Synchronous variant of FileDataStore.set — fire-and-forget flush. The in-memory cache update is immediate; the file write happens asynchronously.

Parameters

ParameterTypeDescription
keystringThe storage key.
valueUint8ArrayThe bytes to store.

Returns

void

On this page