LogoRobo.js
Framework

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:

{encoded-key}.json
{encoded-key}.json

Type Parameters

Type ParameterDefault type
K extends stringstring
Vunknown

Implements

Constructors

new FileAdapter()

new FileAdapter<K, V>(options): FileAdapter<K, V>

Parameters

ParameterType
optionsFileAdapterOptions

Returns

FileAdapter<K, V>

Properties

PropertyModifierTypeDefault valueDescription
namereadonly"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

ParameterType
opsBatchOperation<K, V>[]

Returns

Promise<void>

Implementation of

FlashcoreAdapter.atomicBatch


capabilities()

capabilities(): AdapterCapabilitiesReport

Report extended capabilities.

Returns

AdapterCapabilitiesReport

Implementation of

FlashcoreAdapter.capabilities


clear()

clear(): Promise<void>

Clear all data.

Returns

Promise<void>

Implementation of

FlashcoreAdapter.clear


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

ParameterType
keyK
expectedV
nextV

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

ParameterType
keyK

Returns

Promise<boolean>

Implementation of

FlashcoreAdapter.delete


get()

get(key): Promise<V>

Get a value by key. Returns undefined if the key does not exist.

Parameters

ParameterType
keyK

Returns

Promise<V>

Implementation of

FlashcoreAdapter.get


getBaseDir()

getBaseDir(): string

Get 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

ParameterType
keyK

Returns

Promise<boolean>

Implementation of

FlashcoreAdapter.has


init()

init(): Promise<void>

Initialize the adapter (e.g., connect, create directories). Called once during Flashcore.$.init().

Returns

Promise<void>

Implementation of

FlashcoreAdapter.init


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

ParameterType
prefixK

Returns

Promise<K[]>

Implementation of

FlashcoreAdapter.scan


set()

set(key, value): Promise<boolean>

Set a key-value pair. Returns true if the operation succeeded.

Parameters

ParameterType
keyK
valueV

Returns

Promise<boolean>

Implementation of

FlashcoreAdapter.set


setIfNotExists()

setIfNotExists(key, value): Promise<boolean>

Set a key only if it doesn't exist. Uses exclusive file creation flag to ensure atomicity.

Parameters

ParameterType
keyK
valueV

Returns

Promise<boolean>

Implementation of

FlashcoreAdapter.setIfNotExists


shutdown()

shutdown(): Promise<void>

Shutdown the adapter (e.g., close connections).

Returns

Promise<void>

Implementation of

FlashcoreAdapter.shutdown


size()

size(): Promise<number>

Get the number of stored keys.

Returns

Promise<number>

On this page