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
| Parameter | Type | Description |
|---|---|---|
filePath | string | Absolute 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
| Parameter | Type | Description |
|---|---|---|
key | string | The storage key to remove. |
Returns
Promise<void>
Implementation of
get()
get(key: string): Promise<
| Uint8Array<ArrayBufferLike>
| undefined>;Defined in: storage/data-store.ts:156
Read the value at key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The storage key. |
Returns
Promise<
| Uint8Array<ArrayBufferLike>
| undefined>
The stored bytes, or undefined if the key is absent.
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
key | string | The 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
| Parameter | Type | Description |
|---|---|---|
prefix? | string | Optional 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
| Parameter | Type | Description |
|---|---|---|
key | string | The storage key. |
value | Uint8Array | The bytes to store. Treat as immutable; the SDK never mutates the supplied buffer after passing it. |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
key | string | The storage key. |
value | Uint8Array | The bytes to store. |
Returns
void