FileAdapter<K, V>
Class: FileAdapter<K, V>
File-based storage adapter using the filesystem.
Features:
- Atomic writes via temp file + rename
- Filesystem-safe key encoding
- scan(prefix) via directory listing
- setIfNotExists via exclusive file creation
Storage layout:
Type Parameters
| Type Parameter | Default type |
|---|---|
K extends string | string |
V | unknown |
Implements
FlashcoreAdapter<K,V>
Constructors
new FileAdapter()
new FileAdapter<K, V>(options): FileAdapter<K, V>Parameters
| Parameter | Type |
|---|---|
options | FileAdapterOptions |
Returns
FileAdapter<K, V>
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
name | readonly | "FileAdapter" | 'FileAdapter' | Human-readable adapter name for logging and introspection. |
Methods
atomicBatch()
atomicBatch(ops): Promise<void>Apply a batch of operations atomically.
Note: This is NOT truly atomic at the filesystem level. For crash safety, use WAL at a higher level.
Parameters
| Parameter | Type |
|---|---|
ops | BatchOperation<K, V>[] |
Returns
Promise<void>
Implementation of
capabilities()
capabilities(): AdapterCapabilitiesReportReport extended capabilities.
Returns
Implementation of
clear()
clear(): Promise<void>Clear all data.
Returns
Promise<void>
Implementation of
compareAndSwap()
compareAndSwap(
key,
expected,
next): Promise<boolean>Compare and swap: atomically update if current value matches expected.
Note: This implementation is NOT truly atomic on the filesystem level, but uses in-memory comparison. For true atomicity, use with chunk/catalog locks.
Parameters
| Parameter | Type |
|---|---|
key | K |
expected | V |
next | V |
Returns
Promise<boolean>
Implementation of
FlashcoreAdapter.compareAndSwap
delete()
delete(key): Promise<boolean>Delete a key. Returns true if the key existed and was deleted.
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<boolean>
Implementation of
get()
get(key): Promise<V>Get a value by key. Returns undefined if the key does not exist.
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<V>
Implementation of
getBaseDir()
getBaseDir(): stringGet the storage directory path.
Returns
string
has()
has(key): Promise<boolean>Check if a key exists. Must return true for stored falsy values (0, false, '', null).
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
Promise<boolean>
Implementation of
init()
init(): Promise<void>Initialize the adapter (e.g., connect, create directories). Called once during Flashcore.$.init().
Returns
Promise<void>
Implementation of
keys()
keys(): Promise<K[]>Get all stored keys (for testing/debugging).
Returns
Promise<K[]>
scan()
scan(prefix): Promise<K[]>Scan for keys with a given prefix. Scans the directory and filters by prefix after decoding filenames.
Parameters
| Parameter | Type |
|---|---|
prefix | K |
Returns
Promise<K[]>
Implementation of
set()
set(key, value): Promise<boolean>Set a key-value pair. Returns true if the operation succeeded.
Parameters
| Parameter | Type |
|---|---|
key | K |
value | V |
Returns
Promise<boolean>
Implementation of
setIfNotExists()
setIfNotExists(key, value): Promise<boolean>Set a key only if it doesn't exist. Uses exclusive file creation flag to ensure atomicity.
Parameters
| Parameter | Type |
|---|---|
key | K |
value | V |
Returns
Promise<boolean>
Implementation of
FlashcoreAdapter.setIfNotExists
shutdown()
shutdown(): Promise<void>Shutdown the adapter (e.g., close connections).
Returns
Promise<void>
Implementation of
size()
size(): Promise<number>Get the number of stored keys.
Returns
Promise<number>
