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 → RedisType Parameters
| Type Parameter | Default type |
|---|---|
K extends string | string |
V | unknown |
Constructors
new AdapterBuilder()
new AdapterBuilder<K, V>(baseAdapter): AdapterBuilder<K, V>Parameters
| Parameter | Type |
|---|---|
baseAdapter | FlashcoreAdapter<K, V> |
Returns
AdapterBuilder<K, V>
Methods
build()
build(): FlashcoreAdapter<K, V>Build and return the composed adapter.
Returns
FlashcoreAdapter<K, V>
describe()
describe(): stringGet 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?): thisAdd a custom wrapper.
Use this to add wrappers not included in the standard set.
Parameters
| Parameter | Type |
|---|---|
wrapper | (adapter) => FlashcoreAdapter<K, V> |
name? | string |
Returns
this
withCache()
withCache(options?): thisAdd an LRU cache layer.
The cache is in-memory and reduces reads to the underlying adapter. Cache entries are invalidated on writes.
Parameters
| Parameter | Type |
|---|---|
options? | CacheOptions |
Returns
this
withCompression()
withCompression(options?): thisAdd gzip compression for values above a threshold.
Compressed values are tagged with 'gz:' prefix. Decompression is automatic on read.
Parameters
| Parameter | Type |
|---|---|
options? | CompressionOptions |
Returns
this
withEncryption()
withEncryption(options): thisAdd AES-256 encryption for all values.
Encrypted values are tagged with 'enc:' prefix. Decryption is automatic on read.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | EncryptionOptions | Must include key for encryption |
Returns
this
withResilience()
withResilience(options?): thisAdd automatic retry with exponential backoff.
Retries transient errors (network issues, timeouts, etc.) with configurable max retries and delay.
Parameters
| Parameter | Type |
|---|---|
options? | ResilienceOptions |
Returns
this
