@furystack/filesystem-store
Version:
Simple File System store implementation for FuryStack
37 lines • 1.24 kB
JavaScript
import { defineStore } from '@furystack/core';
import { FileSystemStore } from './filesystem-store.js';
/**
* Mints a singleton {@link StoreToken} backed by a {@link FileSystemStore}.
*
* Declare the token once at module scope — calling {@link defineFileSystemStore}
* inline every time produces a new token identity per call and defeats
* singleton caching.
*
* The token automatically disposes the underlying store (flushing pending
* changes, closing the FS watcher, clearing the save interval) when the
* owning injector is disposed — {@link defineStore} registers the hook.
*
* @example
* ```ts
* export const UserStore = defineFileSystemStore({
* name: 'my-app/UserStore',
* model: User,
* primaryKey: 'username',
* fileName: './data/users.json',
* })
*
* const store = injector.get(UserStore)
* ```
*/
export const defineFileSystemStore = (options) => defineStore({
name: options.name,
model: options.model,
primaryKey: options.primaryKey,
factory: () => new FileSystemStore({
model: options.model,
primaryKey: options.primaryKey,
fileName: options.fileName,
tickMs: options.tickMs,
}),
});
//# sourceMappingURL=define-filesystem-store.js.map