API Reference

object-store

API entries in this module: 2

Current object-store implementation

IObjectStorage resolves to ObjectStorage in singleton scope. The default implementation uses IndexedDB with one database (objectStore_6a46e952c07d42629cd8fca03b21ce30) and one object store (objects).

set(key, value) performs a read-write transaction and stores/replaces the value by key. get(key) performs a read-only transaction and returns the stored value (or undefined when the key does not exist).

close() closes the cached database connection. The next call to get or set reopens it automatically. Because it depends on IDBFactory, this service is browser-only and not available during SSR.

IndexedDB stores values with the structured-clone algorithm, so stored values must be structured-clone compatible. For example, functions, DOM nodes, and class instances with non-cloneable state cannot be persisted directly.

Example: use IObjectStorage

import {
  InjectionContainer,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  type IObjectStorage,
} from '@rs-x/core';

await InjectionContainer.load(RsXCoreModule);

const objectStorage = InjectionContainer.get<IObjectStorage>(
  RsXCoreInjectionTokens.IObjectStorage,
);

await objectStorage.set('user:1', { id: 1, name: 'Ada' });
const user = await objectStorage.get<{ id: number; name: string }>('user:1');

console.log(user?.name); // Ada
objectStorage.close();

How to extend or modify

Rebind IObjectStorage to replace IndexedDB storage (for example memory storage in tests, remote storage, or encrypted persistence), while keeping the same async API contract.

Override object storage service

import {
  ContainerModule,
  Injectable,
  InjectionContainer,
  RsXCoreInjectionTokens,
  type IObjectStorage,
} from '@rs-x/core';

@Injectable()
class MemoryObjectStorage implements IObjectStorage {
  private readonly map = new Map<string, unknown>();

  public async get<T>(key: string): Promise<T> {
    return this.map.get(key) as T;
  }

  public async set<T>(key: string, value: T): Promise<void> {
    this.map.set(key, value);
  }

  public close(): void {
    this.map.clear();