Skip to content

Documentation / @cashconnect-js/templates-dev / storage/store-inmemory

StoreInMemory ​

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:9

Implementation of BaseStore using Memory as the storage backend.

Remarks ​

This implementation can be used testing and caching of expensive operations.

Extends ​

Constructors ​

Constructor ​

ts
new StoreInMemory(): StoreInMemory;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:17

Returns ​

StoreInMemory

Overrides ​

BaseStore.constructor

Methods ​

from() ​

ts
static from(): StoreInMemory;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:11

Returns ​

StoreInMemory

all() ​

ts
all<T>(): Promise<{
[key: string]: T;
}>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:23

Retrieves all key-value pairs from the store.

Type Parameters ​
Type ParameterDescription
TThe type of the values in the store
Returns ​

Promise<{ [key: string]: T; }>

Overrides ​

BaseStore.all

keys() ​

ts
keys(): Promise<string[]>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:31

Returns an array of all keys in the store.

Returns ​

Promise<string[]>

Overrides ​

BaseStore.keys

get() ​

ts
get<T>(key): Promise<T>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:35

Retrieves a value from the store by its key.

Type Parameters ​
Type ParameterDescription
TThe type of the value to retrieve
Parameters ​
ParameterTypeDescription
keystringThe key to lookup
Returns ​

Promise<T>

Overrides ​

BaseStore.get

set() ​

ts
set<T>(key, value): Promise<void>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:39

Stores a value in the store with the specified key.

Type Parameters ​
Type ParameterDescription
TThe type of the value to store
Parameters ​
ParameterTypeDescription
keystringThe key under which to store the value
valueTThe value to store
Returns ​

Promise<void>

Overrides ​

BaseStore.set

delete() ​

ts
delete(key): Promise<void>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:44

Removes a value from the store by its key.

Parameters ​
ParameterTypeDescription
keystringThe key to remove
Returns ​

Promise<void>

Overrides ​

BaseStore.delete

clear() ​

ts
clear(): Promise<void>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:49

Removes all key-value pairs from the store.

Returns ​

Promise<void>

Overrides ​

BaseStore.clear

has() ​

ts
has(key): Promise<boolean>;

Defined in: packages/templates-dev/src/storage/store-inmemory.ts:54

Checks if a key exists in the store.

Parameters ​
ParameterTypeDescription
keystringThe key to check
Returns ​

Promise<boolean>

Overrides ​

BaseStore.has

batchGet() ​

ts
batchGet<T>(keys): Promise<Map<string, T>>;

Defined in: packages/templates-dev/src/storage/base-store.ts:153

Retrieves multiple values from the store by their keys. Filters out undefined values from the results.

Type Parameters ​
Type ParameterDescription
TThe type of the values to retrieve
Parameters ​
ParameterTypeDescription
keysstring[]Array of keys to retrieve
Returns ​

Promise<Map<string, T>>

Inherited from ​

BaseStore.batchGet

batchSet() ​

ts
batchSet<T>(items): Promise<void>;

Defined in: packages/templates-dev/src/storage/base-store.ts:173

Stores multiple key-value pairs in the store. Emits 'set' events for each key-value pair.

Type Parameters ​
Type ParameterDescription
TThe type of the values to store
Parameters ​
ParameterTypeDescription
itemsMap<string, T>Map of key-value pairs to store
Returns ​

Promise<void>

Inherited from ​

BaseStore.batchSet

close() ​

ts
close(): Promise<void>;

Defined in: packages/templates-dev/src/storage/base-store.ts:188

Closes the store connection. Override this method in implementing classes if needed.

Returns ​

Promise<void>

Inherited from ​

BaseStore.close

getOrFail() ​

ts
getOrFail<T>(key): Promise<T>;

Defined in: packages/templates-dev/src/storage/base-store.ts:196

Retrieves a value from the store by its key, throwing an error if the value doesn't exist.

Type Parameters ​
Type ParameterDescription
TThe type of the value to retrieve
Parameters ​
ParameterTypeDescription
keystringThe key to lookup
Returns ​

Promise<T>

Inherited from ​

BaseStore.getOrFail

getOrSet() ​

ts
getOrSet<T>(key, setter): Promise<T>;

Defined in: packages/templates-dev/src/storage/base-store.ts:216

Retrieves a value from the store by its key, or sets it using the provided setter function if it doesn't exist.

Type Parameters ​
Type ParameterDescription
TThe type of the value to retrieve or set
Parameters ​
ParameterTypeDescription
keystringThe key to lookup
setter() => T | Promise<T>Function to generate the value if it doesn't exist
Returns ​

Promise<T>

Inherited from ​

BaseStore.getOrSet

proxy() ​

ts
proxy<T>(key): StoreValueProxy<T>;

Defined in: packages/templates-dev/src/storage/base-store.ts:245

Creates a wrapper object that provides convenient access to a stored value. The wrapper allows getting and setting the value using async property access.

Type Parameters ​
Type ParameterDescription
TThe type of the value to wrap
Parameters ​
ParameterTypeDescription
keystringThe key under which the value is stored
Returns ​

StoreValueProxy<T>

An object with a getter and setter for the stored value

Example ​
typescript
const numValue = store.proxy<number>('myNumber');
const value = await numValue.get(); // gets the stored value
await numValue.set(42); // sets the stored value
Inherited from ​

BaseStore.proxy

on() ​

ts
on<K>(
   type, 
   listener, 
   debounceMilliseconds?): OffCallback;

Defined in: packages/core/dist/primitives.d.ts:593

Registers a listener for the specified event type.

Type Parameters ​
Type ParameterDescription
K extends keyof StoreEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to listen for
listenerListener<StoreEvents[K]>The function to call when the event is emitted
debounceMilliseconds?numberOptional debounce time in milliseconds
Returns ​

OffCallback

A callback function that can be used to unregister this listener

Example ​
typescript
const off = emitter.on('data-change', (data) => {
  console.log('Data updated:', data);
}, 300); // Debounce for 300ms

// Later, unregister the listener
off();
Inherited from ​

BaseStore.on

once() ​

ts
once<K>(
   type, 
   listener, 
   debounceMilliseconds?): OffCallback;

Defined in: packages/core/dist/primitives.d.ts:611

Registers a one-time listener for the specified event type. The listener will be automatically removed after being called once.

Type Parameters ​
Type ParameterDescription
K extends keyof StoreEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to listen for
listenerListener<StoreEvents[K]>The function to call when the event is emitted
debounceMilliseconds?numberOptional debounce time in milliseconds
Returns ​

OffCallback

A callback function that can be used to unregister this listener before it fires

Example ​
typescript
emitter.once('user-login', ({ userId }) => {
  console.log(`Welcome ${userId}! This will only show once.`);
});
Inherited from ​

BaseStore.once

off() ​

ts
off<K>(type, listener): void;

Defined in: packages/core/dist/primitives.d.ts:626

Removes a specific listener for the given event type.

Type Parameters ​
Type ParameterDescription
K extends keyof StoreEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to remove the listener from
listenerListener<StoreEvents[K]>The listener function to remove
Returns ​

void

Example ​
typescript
const handler = (data) => console.log(data);
emitter.on('test', handler);
emitter.off('test', handler); // Removes the listener
Inherited from ​

BaseStore.off

emit() ​

ts
emit<K>(type, payload): boolean;

Defined in: packages/core/dist/primitives.d.ts:648

Emits an event of the specified type with the given payload. All registered listeners for this event type will be called.

Type Parameters ​
Type ParameterDescription
K extends keyof StoreEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to emit
payloadStoreEvents[K]The data to pass to all listeners
Returns ​

boolean

true if there were listeners for this event, false otherwise

Example ​
typescript
const hasListeners = emitter.emit('user-login', {
  userId: '123',
  timestamp: Date.now()
});

if (!hasListeners) {
  console.log('No one was listening for user-login events');
}
Inherited from ​

BaseStore.emit

removeAllListeners() ​

ts
removeAllListeners(): void;

Defined in: packages/core/dist/primitives.d.ts:659

Removes all listeners for all events. This effectively resets the EventEmitter to its initial state.

Returns ​

void

Example ​
typescript
emitter.removeAllListeners();
// All previously registered listeners are now gone
Inherited from ​

BaseStore.removeAllListeners

waitFor() ​

ts
waitFor<K>(
   type, 
   predicate, 
   timeoutMs?): Promise<StoreEvents[K]>;

Defined in: packages/core/dist/primitives.d.ts:685

Returns a Promise that resolves when an event of the specified type is emitted and matches the given predicate.

Type Parameters ​
Type ParameterDescription
K extends keyof StoreEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to wait for
predicate(payload) => booleanA function that determines if the event payload matches what we're waiting for
timeoutMs?numberOptional timeout in milliseconds. If specified, the promise will reject after this time
Returns ​

Promise<StoreEvents[K]>

A Promise that resolves with the event payload when the condition is met

Throws ​

If the timeout is reached before a matching event occurs

Example ​
typescript
try {
  const loginData = await emitter.waitFor(
    'user-login',
    ({ userId }) => userId === 'admin',
    5000 // Wait up to 5 seconds
  );
  console.log('Admin logged in:', loginData);
} catch (error) {
  console.log('Timeout: Admin never logged in');
}
Inherited from ​

BaseStore.waitFor