LogoRobo.js
Framework

AdapterBuilder<K, V>

Class: AdapterBuilder<K, V>

Builder for composing adapter wrappers.

Wrappers are applied in the order they are called. The innermost wrapper (first added) is closest to the base adapter.

Example

const adapter = new AdapterBuilder(new RedisAdapter(redis))
  .withResilience({ maxRetries: 5 })
  .withCompression({ threshold: 512 })
  .withEncryption({ key: process.env.SECRET! })
  .withCache({ maxSize: 1000 })
  .build()

// Data flow:
// get() → Cache → Encryption → Compression → Resilience → Redis
// set() → Cache → Encryption → Compression → Resilience → Redis

Type Parameters

Type ParameterDefault type
K extends stringstring
Vunknown

Constructors

new AdapterBuilder()

new AdapterBuilder<K, V>(baseAdapter): AdapterBuilder<K, V>

Parameters

ParameterType
baseAdapterFlashcoreAdapter<K, V>

Returns

AdapterBuilder<K, V>

Methods

build()

build(): FlashcoreAdapter<K, V>

Build and return the composed adapter.

Returns

FlashcoreAdapter<K, V>


describe()

describe(): string

Get a description of the wrapper stack.

Returns

string


getWrapperNames()

getWrapperNames(): string[]

Get the list of applied wrappers (in order from outer to inner).

Returns

string[]


with()

with(wrapper, name?): this

Add a custom wrapper.

Use this to add wrappers not included in the standard set.

Parameters

ParameterType
wrapper(adapter) => FlashcoreAdapter<K, V>
name?string

Returns

this


withCache()

withCache(options?): this

Add an LRU cache layer.

The cache is in-memory and reduces reads to the underlying adapter. Cache entries are invalidated on writes.

Parameters

ParameterType
options?CacheOptions

Returns

this


withCompression()

withCompression(options?): this

Add gzip compression for values above a threshold.

Compressed values are tagged with 'gz:' prefix. Decompression is automatic on read.

Parameters

ParameterType
options?CompressionOptions

Returns

this


withEncryption()

withEncryption(options): this

Add AES-256 encryption for all values.

Encrypted values are tagged with 'enc:' prefix. Decryption is automatic on read.

Parameters

ParameterTypeDescription
optionsEncryptionOptionsMust include key for encryption

Returns

this


withResilience()

withResilience(options?): this

Add automatic retry with exponential backoff.

Retries transient errors (network issues, timeouts, etc.) with configurable max retries and delay.

Parameters

ParameterType
options?ResilienceOptions

Returns

this

On this page