StoreRegistry
Defined in: store/StoreRegistry.ts:147
Store Registry coordinating store loading, caching, and retention
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StoreRegistry(
config):StoreRegistry
Defined in: store/StoreRegistry.ts:185
Creates a new StoreRegistry instance.
Parameters
Section titled “Parameters”config
Section titled “config”StoreRegistryConfig = {}
Returns
Section titled “Returns”StoreRegistry
Example
Section titled “Example”const registry = new StoreRegistry({ defaultOptions: { batchUpdates, unusedCacheTime: 30_000, }})Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose():
Promise<void>
Defined in: store/StoreRegistry.ts:382
Disposes the registry and all its managed stores, immediately releasing resources (database connections, WebSocket connections, web workers, etc.).
Most applications should use a single StoreRegistry and don’t need to call
this method. It’s only necessary when creating multiple short-lived registries to
immediately release resources and avoid conflicts with subsequent registries.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when disposal is complete
Remarks
Section titled “Remarks”- No-op if a custom
contextwas provided to the constructor (caller owns cleanup) - Idempotent: safe to call multiple times
- After disposal, the registry should not be used
getOrLoad()
Section titled “getOrLoad()”getOrLoad<
TSchema,TContext,TSyncPayloadSchema>(options):Effect<Store<TSchema,TContext>,UnknownError,Scope>
Defined in: store/StoreRegistry.ts:237
Gets a cached store or loads a new one, with the store lifetime scoped to the caller.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends LiveStoreSchema
The schema type for the store
TContext
Section titled “TContext”TContext = { }
The context type for the store
TSyncPayloadSchema
Section titled “TSyncPayloadSchema”TSyncPayloadSchema extends Codec<Json, Json> = any
The sync payload schema type
Parameters
Section titled “Parameters”options
Section titled “options”RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>
Returns
Section titled “Returns”Effect<Store<TSchema, TContext>, UnknownError, Scope>
An Effect that yields the store, scoped to the provided Scope
Remarks
Section titled “Remarks”- Stores are kept in cache and reused while any scope holds them
- When the scope closes, the reference is released; the store is disposed after
unusedCacheTimeif no other scopes retain it - Concurrent calls with the same storeId share the same store instance
getOrLoadPromise()
Section titled “getOrLoadPromise()”getOrLoadPromise<
TSchema,TContext,TSyncPayloadSchema>(options):Store<TSchema,TContext> |Promise<Store<TSchema,TContext>>
Defined in: store/StoreRegistry.ts:268
Get or load a store, returning it directly if already loaded or a promise if loading.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends LiveStoreSchema
The schema type for the store
TContext
Section titled “TContext”TContext = { }
The context type for the store
TSyncPayloadSchema
Section titled “TSyncPayloadSchema”TSyncPayloadSchema extends Codec<Json, Json> = any
The sync payload schema type
Parameters
Section titled “Parameters”options
Section titled “options”RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>
Returns
Section titled “Returns”Store<TSchema, TContext> | Promise<Store<TSchema, TContext>>
The loaded store if available, or a Promise that resolves to the loaded store
Throws
Section titled “Throws”unknown - store loading error
Remarks
Section titled “Remarks”- Returns the store instance directly (synchronous) when already loaded
- Returns a stable Promise reference when loading is in progress or needs to be initiated
- Throws with the same error instance on subsequent calls after failure
- Applies default options from registry config, with call-site options taking precedence
- Concurrent calls with the same storeId share the same store instance
preload()
Section titled “preload()”preload<
TSchema,TContext,TSyncPayloadSchema>(options):Promise<void>
Defined in: store/StoreRegistry.ts:353
Loads a store (without suspending) to warm up the cache.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends LiveStoreSchema
The schema of the store to preload
TContext
Section titled “TContext”TContext = { }
The context type for the store
TSyncPayloadSchema
Section titled “TSyncPayloadSchema”TSyncPayloadSchema extends Codec<Json, Json> = any
The sync payload schema type
Parameters
Section titled “Parameters”options
Section titled “options”RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the loading is complete (success or failure)
Remarks
Section titled “Remarks”- We don’t return the store or throw as this is a fire-and-forget operation.
- If the entry remains unused after preload resolves/rejects, it is scheduled for disposal.
- Does not affect the retention of the store in cache.
retain()
Section titled “retain()”retain<
TSchema,TContext,TSyncPayloadSchema>(options): () =>void
Defined in: store/StoreRegistry.ts:320
Retains the store in cache.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends LiveStoreSchema
The schema type for the store
TContext
Section titled “TContext”TContext = { }
The context type for the store
TSyncPayloadSchema
Section titled “TSyncPayloadSchema”TSyncPayloadSchema extends Codec<Json, Json> = any
The sync payload schema type
Parameters
Section titled “Parameters”options
Section titled “options”RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>
Returns
Section titled “Returns”A release function that, when called, removes this retention hold
():
void
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”- Multiple retains on the same store are independent; each must be released separately
- If the store isn’t cached yet, it will be loaded and then retained
- The store will remain in cache until all retains are released and after
unusedCacheTimeexpires