Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Store

StoreManager is an abstraction over persistent storage backends. Unlike CacheManager, values have no TTL — the Store is for durable key-value data.

Register it by including StoreProvider in your providers (or use the built-in defaultProviders):

import { Application, defaultProviders } from "@artisansdk/architect"

Application.configure().withProviders(defaultProviders).run()

Basic usage

import { Store } from "@artisansdk/architect/support/facades"

await Store.set("theme", "dark")
const theme = await Store.get<string>("theme")   // "dark" | null
const exists = await Store.has("theme")          // true
await Store.delete("theme")
await Store.clear()
const keys = await Store.keys()

Drivers

DriverBacked byNotes
memoryIn-memory MapDefault. Lost on page reload.
locallocalStorageSurvives reload. Falls back to memory if unavailable.
indexedIndexedDBLarger capacity. Falls back to memory if unavailable.

Switching drivers

Store.use("indexed")

// Access a specific driver directly
const local = Store.driver("local")
await local.set("key", value)

Configuration

Unlike CacheManager, StoreManager doesn’t support multiple named store configs — it reads a single active driver name from store.driver:

Application.configure({
  config: {
    store: {
      driver: "indexed",
    },
  },
})

Registering a custom driver

import { type StoreManager, type ContainerContract as Container } from "@artisansdk/architect"

boot(container: Container) {
  // Unlike CacheManager/LogManager, StoreProvider only binds the string identifier "store" —
  // it never registers StoreManager as a class binding, so container.make(StoreManager) would
  // construct an unrelated, disconnected instance instead of resolving the shared one.
  const store = container.make<StoreManager>("store")

  store.extend("native", (config) => {
    return new TauriStoreAdapter(config.get("store.native"))
  })
}

Adapters

You can use the built-in adapters directly if you need a raw storage layer without the manager:

import {
  MemoryStoreAdapter,
  LocalStorageAdapter,
  IndexedDbAdapter,
} from "@artisansdk/architect"

const memory = new MemoryStoreAdapter()
const local = new LocalStorageAdapter(window.localStorage)
const indexed = new IndexedDbAdapter()

await memory.set("key", value)
const result = await memory.get("key")

IndexedDbAdapter options

const indexed = new IndexedDbAdapter({
  name: "my-app-store",       // database name (default: "ioc-store")
  factory: globalThis.indexedDB,  // IDBFactory (default: globalThis.indexedDB)
  fallback: new MemoryStoreAdapter(), // fallback when IDB unavailable
})