signalstory
Version:
Signal-based state management for Angular that grows with your project. Explore a versatile toolbox with enriching plugins for developers at all levels.
815 lines (791 loc) • 34.7 kB
TypeScript
import { Injector, ValueEqualityFn, ProviderToken, Signal } from '@angular/core';
/**
* Configuration for a store effect.
*/
interface StoreEffectConfig {
/**
* Indicates whether the effect requires an injection context. Defaults to true.
*/
withInjectionContext?: boolean;
/**
* Indicates whether the effect sets loading status.
* Only applicable if the `StoreStatus` plugin is used.
* Defaults to false.
*/
setLoadingStatus?: boolean;
/**
* Indicates whether the effect sets initialized status.
* Only applicable if the `StoreStatus` plugin is used.
* Defaults to false.
*/
setInitializedStatus?: boolean;
}
/**
* Represents an effect that can be executed on a store.
*/
interface StoreEffect<TStore extends Store<any>, TArgs extends unknown[], TResult> {
name: string;
func: (store: TStore, ...args: TArgs) => TResult;
config: Readonly<Required<StoreEffectConfig>>;
}
/**
* Creates a new store effect with the provided name, function, and configuration.
* @param name The name of the effect.
* @param func The function representing the effect.
* @param config Configuration options for the effect.
* @returns A store effect object.
*/
declare function createEffect<TStore extends Store<any>, TArgs extends any[], TResult>(name: string, func: (store: TStore, ...args: TArgs) => TResult, config?: StoreEffectConfig): StoreEffect<TStore, TArgs, TResult>;
/**
* Represents a function that processes initialization of a store.
*
* This type defines a function that is called during the initialization of a store.
*
* @param store - The store being initialized.
*/
type InitPostprocessor = (store: Store<any>) => void;
/**
* Represents a function that preprocesses a command before execution.
*
* This type defines a function that is called before a command is executed on a store.
*
* @param store - The store on which the command is being executed.
* @param command - The command being executed, if applicable.
*/
type CommandPreprocessor = (store: Store<any>, command: string | undefined) => void;
/**
* Represents a function that postprocesses a command after execution.
*
* This type defines a function that is called after a command has been executed on a store.
*
* @param store - The store on which the command was executed.
* @param command - The command that was executed, if applicable.
*/
type CommandPostprocessor = (store: Store<any>, command: string | undefined) => void;
/**
* Represents a function that preprocesses an effect before execution.
*
* This type defines a function that is called before an effect is executed on a store.
*
* @typeparam TStore - The generic store type.
* @typeparam TResult - The result type of the effect function.
* @param store - The store on which the effect is being executed.
* @param effect - The effect being executed.
* @param invocationId - The unique identifier for the invocation, generated by combining `performance.now()` and `Math.random()`.
*/
type EffectPreprocessor = (store: Store<any>, effect: StoreEffect<any, any, any>, invocationId: number) => void;
/**
* Represents a function that postprocesses an effect after execution.
*
* This type defines a function that is called after an effect has been executed on a store.
*
* @typeparam TStore - The generic store type.
* @typeparam TResult - The result type of the effect function.
* @param store - The store on which the effect was executed.
* @param effect - The effect that was executed.
* @param result - The result value from the effect function.
* @param invocationId - The unique identifier for the invocation, generated by combining `performance.now()` and `Math.random()`.
*/
type EffectPostprocessor<TResult> = (store: Store<any>, effect: StoreEffect<any, any, TResult>, result: TResult, invocationId: number) => TResult;
/**
* Represents a plugin that can be attached to a store to modify its behavior.
*
* This type defines the structure of a store plugin, which can include various
* functions for initialization, command preprocessing, and command postprocessing.
*
* @property [precedence] - Influcences the ordering of the plugin, high precendence indicates early usage
* @property [init] - A function for initializing the store.
* @property [preprocessCommand] - A function for preprocessing commands.
* @property [postprocessCommand] - A function for postprocessing commands.
* @property [preprocessEffect] - A function for preprocessing effects.
* @property [postprocessEffect] - A function for postprocessing effects.
* @property [others] - Additional properties may be added for plugin-specific functionality.
*/
type StorePlugin = {
precedence?: number;
init?: InitPostprocessor;
preprocessCommand?: CommandPreprocessor;
postprocessCommand?: CommandPostprocessor;
preprocessEffect?: EffectPreprocessor;
postprocessEffect?: EffectPostprocessor<any>;
[others: string]: any;
};
/**
* Configuration options for a signal store.
*
* @typeparam TState The type of the store's initial state.
*/
interface StoreConfig<TState> {
/**
* The initial state of the store.
*/
initialState: TState;
/**
* The name of the store (optional, default: constructor name).
*/
name?: string;
/**
* Optional Di injector can be passed for effects and query objects. Only useful for dynamic stores, that are not registered in DI (optional, default: null)
*/
injector?: Injector | null;
/**
* The equality function to compare previous and new states, determining whether
* a change notification should be published.
* If not provided, the default equality function from Angular signals is used.
* It is recommended that users do not modify the equality function except
* in exceptional and specialized use cases.
*/
stateEqualityFn?: ValueEqualityFn<TState> | null;
/**
* A list of plugins to use
*/
plugins?: StorePlugin[];
}
/**
* Represents an event which may affect a store.
*/
interface StoreEvent<TPayload> {
name: string;
payload?: TPayload;
}
/**
* Creates a store event blueprint with the provided name.
* @param name The name of the event.
* @returns A store event blueprint object.
*/
declare function createEvent<TPayload = never>(name: string): StoreEvent<TPayload>;
/**
* Represents a store query with the specified result type, store dependencies, and optional argument.
*/
type StoreQuery<TResult, TStores extends ProviderToken<any>[], TArg = undefined> = {
stores: TStores;
query: TArg extends undefined ? (...stores: {
[K in keyof TStores]: TStores[K] extends ProviderToken<infer U> ? U : never;
}) => TResult : (...storesAndArg: {
[K in keyof TStores]: TStores[K] extends ProviderToken<infer U> ? U : never;
} & {
arg: TArg;
}) => TResult;
};
/**
* Creates a store query with the specified result type and store dependencies.
* @param stores The store dependencies for the query.
* @param query The query function that operates on the stores.
* @returns The created store query.
*/
declare function createQuery<TResult, TStore1 extends Store<any>, TStore2 extends Store<any>, TStore3 extends Store<any>, TStore4 extends Store<any>, TArg = undefined>(stores: [
ProviderToken<TStore1>,
ProviderToken<TStore2>,
ProviderToken<TStore3>,
ProviderToken<TStore4>
], query: (store1: TStore1, store2: TStore2, store3: TStore3, store4: TStore4, arg: TArg) => TResult): StoreQuery<TResult, [
ProviderToken<TStore1>,
ProviderToken<TStore2>,
ProviderToken<TStore3>,
ProviderToken<TStore4>
], TArg>;
declare function createQuery<TResult, TStore1 extends Store<any>, TStore2 extends Store<any>, TStore3 extends Store<any>, TArg = undefined>(stores: [
ProviderToken<TStore1>,
ProviderToken<TStore2>,
ProviderToken<TStore3>
], query: (store1: TStore1, store2: TStore2, store3: TStore3, arg: TArg) => TResult): StoreQuery<TResult, [
ProviderToken<TStore1>,
ProviderToken<TStore2>,
ProviderToken<TStore3>
], TArg>;
declare function createQuery<TResult, TStore1 extends Store<any>, TStore2 extends Store<any>, TArg = undefined>(stores: [ProviderToken<TStore1>, ProviderToken<TStore2>], query: (store1: TStore1, store2: TStore2, arg: TArg) => TResult): StoreQuery<TResult, [ProviderToken<TStore1>, ProviderToken<TStore2>], TArg>;
declare function createQuery<TResult, TStore1 extends Store<any>, TArg = undefined>(stores: [ProviderToken<TStore1>], query: (store1: TStore1, arg: TArg) => TResult): StoreQuery<TResult, [ProviderToken<TStore1>], TArg>;
/**
* Represents a signal store that manages a state and provides methods for state mutation, event handling, and more.
* @typeparam TState The type of the store's state.
*/
declare class Store<TState> {
private readonly _state;
private readonly initPostprocessor?;
private readonly commandPreprocessor?;
private readonly commandPostprocessor?;
private readonly effectPreprocessor?;
private readonly effectPostprocessor?;
/**
* The config of the store as readonly
*/
readonly config: Readonly<Required<StoreConfig<TState>>>;
/**
* Creates a new instance of the store class.
* @param config The configuration options for the store.
*/
constructor(config: StoreConfig<TState>);
/**
* Gets the name of the store
*/
get name(): string;
/**
* Gets the signal representing the store's current state.
*/
get state(): Signal<TState>;
/**
* Sets the store's state to the provided state, with an optional command name.
* @param newState The new state of the store.
* @param commandName The name of the command associated with the state change.
*/
set(newState: TState, commandName?: string): void;
/**
* Updates the store's state based on the current state, with an optional command name.
* @param updateFn A function that updates the current state.
* @param commandName The name of the command associated with the state change.
*/
update(updateFn: (currentState: TState) => TState, commandName?: string): void;
/**
* Mutates the store's state using the provided mutator function, with an optional command name.
* @param mutator A function that mutates the current state.
* @param commandName The name of the command associated with the state mutation.
*/
mutate(mutator: (currentState: TState) => void, commandName?: string): void;
/**
* Registers a handler for the specified event in the store's mediator.
* @param event The event to register the handler for.
* @param handler The handler function to be executed when the event is published.
*/
registerHandler<TPayload>(event: StoreEvent<TPayload>, handler: (store: this, event: StoreEvent<TPayload>) => void): void;
/**
* Unregister a handler for the specified event(s) in the store's mediator.
* @param event The event to remove the handler for.
* @param events Additional events to remove the handlers for.
*/
unregisterHandler(event: StoreEvent<any>, ...events: StoreEvent<any>[]): void;
/**
* Runs an effect with the provided arguments and returns the result.
* The effect may be associated with the store itself but it may also be unrelated
* @typeparam TStore The types of the effect's target store.
* @typeparam TArgs The types of the effect's arguments.
* @typeparam TResult The type of the effect's result.
* @param effect The store effect to run.
* @param args The arguments to pass to the effect.
* @returns The result of the effect.
*/
runEffect<TArgs extends any[], TResult>(effect: StoreEffect<this, TArgs, TResult>, ...args: TArgs): TResult;
/**
* Runs a store query potentially targeting many differnt stores with the provided arguments and returns the result.
* @typeparam TResult The type of the query's result.
* @typeparam TStores The types of the stores used in the query.
* @typeparam TArgs The type of the query's arguments.
* @param storeQuery The store query to run.
* @param args The arguments to pass to the query.
* @returns The result of the query as computed signal.
*/
runQuery<TResult, TStores extends ProviderToken<any>[], TArgs = undefined>(storeQuery: StoreQuery<TResult, TStores, TArgs>, ...args: TArgs extends undefined ? [] : [TArgs]): Signal<TResult>;
}
/**
* Define a union type of built-in immutable primitives.
*/
type ImmutablePrimitive = string | number | boolean | bigint | symbol | undefined | null | Function | Date | RegExp;
/**
* Checks if a given type is a tuple.
*/
type IsTuple<Type> = Type extends readonly any[] ? any[] extends Type ? never : Type : never;
type AnyArray<T = any> = Array<T> | ReadonlyArray<T>;
type AnySet<T = any> = Set<T> | ReadonlySet<T>;
type AnyMap<TKey = any, TVal = any> = Map<TKey, TVal> | ReadonlyMap<TKey, TVal>;
/**
* Recursively transforms a given type into its deep readonly equivalent.
* This transformation makes sure that the resulting type and its nested properties are immutable.
*/
type Immutable<T> = T extends ImmutablePrimitive ? T : T extends AnyMap<infer Keys, infer Values> ? ReadonlyMap<Immutable<Keys>, Immutable<Values>> : T extends AnySet<infer Values> ? ReadonlySet<Immutable<Values>> : T extends AnyArray<infer Values> ? T extends IsTuple<T> ? {
readonly [Key in keyof T]: Immutable<T[Key]>;
} : ReadonlyArray<Immutable<Values>> : T extends object ? {
readonly [Key in keyof T]: Immutable<T[Key]>;
} : Readonly<T>;
/**
* Configuration options for an immutable signal store.
* @typeparam TState - The type of the store's state.
*/
interface ImmutableStoreConfig<TState> extends StoreConfig<Immutable<TState>> {
/**
* Custom mutation strategy function that returns a new state object instead of operating on the currentState directly.
* @remarks You can provide your own cloning and mutation strategy function similar to libraries like 'immer.js'.
* @param currentState - The current state object to be cloned and mutated.
* @param mutation - A function that modifies a draft copy of the state.
* @returns The new state object after applying the mutation.
* @default Naive implementation using structuredClone or JSON serialize and deserialize @see naiveCloneAndMutateFunc.
*/
mutationProducerFn?: (currentState: TState, mutation: (draftState: TState) => void) => TState;
}
/**
* Represents a store that holds an immutable state, allowing mutation through controlled operations.
*
* @typeparam TState The type of the immutable state held by the store.
*/
declare class ImmutableStore<TState> extends Store<Immutable<TState>> {
private readonly cloneAndMutateFunc;
constructor(config: ImmutableStoreConfig<TState>);
/**
* Clones and mutates the store's state using the provided mutator function, with an optional command name.
* @param mutator A function that mutates the current state.
* @param commandName The name of the command associated with the state mutation.
*/
mutate(mutator: (currentState: TState) => void, commandName?: string): void;
mutate(mutator: (currentState: Immutable<TState>) => void, commandName?: string): void;
}
/**
* Creates a tracker which immediately tracks the history of the specifiedd stores.
* @param maxLength Maximum number of commands to retain in the history.
* @param store Initial store to be tracked in the history.
* @param stores Additional stores to be tracked in the history.
* @returns An instance of `HistoryTracker`.
*
* @remark At least one store has to be specifieid
*/
declare function trackHistory(maxLength: number, store: ImmutableStore<any>, ...stores: ImmutableStore<any>[]): HistoryTracker;
/**
* Hhistory tracker for tracking history of a finite set of stores enabling undo and redo functionality.
*/
interface HistoryTracker {
/**
* Signal indicating whether undo operation is available.
*/
canUndo: Signal<boolean>;
/**
* Signal indicating whether redo operation is available.
*/
canRedo: Signal<boolean>;
/**
* History of commands performed.
*/
getHistory: () => {
/**
* Name of the executed command or transaction tag.
*/
command: string;
/**
* Array containing stores and their corresponding state values before the command was executed.
* Each element is a tuple [store, storeState].
*/
before: [Store<any> | undefined, any][];
}[];
/**
* Destroys the history tracker, cleaning up any resources.
*/
destroy: () => void;
/**
* Begins a new transaction in the history tracker.
* @param tag Optional tag to identify the transaction (only used for pretty printing).
*/
beginTransaction: (tag?: string) => void;
/**
* Ends the current transaction in the history tracker.
*/
endTransaction: () => void;
/**
* Undoes the last command or a group of commands if in a transaction.
* @returns True if the undo operation was successful, false otherwise.
*/
undo: () => boolean;
/**
* Redoes the last undone command or a group of commands (if last undone action was a transaction).
* @returns True if the redo operation was successful, false otherwise.
*/
redo: () => boolean;
}
/**
* Publishes a store event, executing all associated event handlers.
*
* @param {StoreEvent<never>} event - The event to publish.
* @param {undefined} payload - The payload to pass to the event handlers.
* @throws {Error} if the event name is invalid.
* @throws {AggregateError} if there are errors in any event handler.
*/
declare function publishStoreEvent(event: StoreEvent<never>, payload?: undefined): void;
declare function publishStoreEvent<T>(event: StoreEvent<T>, payload: T): void;
/**
* Enables Storeplugin that deep freezes the state after each command
* This middleware introduces some overhead
*
* @returns DeepFreeze Storeplugin.
*/
declare function useDeepFreeze(): StorePlugin;
/**
* Options for configuring the Redux DevTools extension.
*/
interface DevtoolsOptions {
}
/**
* Represents a message sent to the Redux DevTools extension.
*/
interface DevtoolsMessage {
type: string;
payload: {
type: string;
};
state: string;
}
/**
* Represents the Redux DevTools extension interface.
*/
interface Devtools {
send(data: {
type: string;
} & Record<string, unknown>, state: Record<string, never>): void;
init(state: Record<string, never>): void;
unsubscribe(): void;
subscribe(cb: (message: DevtoolsMessage) => void): () => void;
}
/**
* Augments the global Window interface to include Redux DevTools extension functionality.
*/
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION__: {
connect(options: DevtoolsOptions): Devtools;
};
}
}
/**
* Enables Storeplugin that links the store activity with the Redux DevTools extension.
* @returns Devtools Storeplugin
*/
declare function useDevtools(): StorePlugin;
/**
* Represents a logger function that can be used for logging messages.
* @param message - The message to be logged.
* @param optionalParams - Optional parameters to include in the log.
*/
type Logger = (message?: unknown, ...optionalParams: unknown[]) => void;
/**
* Options for configuring the Store Logger Plugin.
*/
interface StoreLoggerPluginOptions {
/**
* Log Function for logging commands and effects. Defaults to `console.log`
*/
logFunction?: Logger;
}
/**
* Enables StorePlugin that logs command and effect execution
* @returns A StorePlugin instance for logging.
*/
declare function useLogger(options?: StoreLoggerPluginOptions): StorePlugin & {
log: Logger;
name: string;
};
/**
* Generates and returns a performance report with various metrics.
* @returns An object containing performance statistics.
*/
declare function getReport(): {
totalCommandCount: number;
averageCommandDurationMs: number;
commandDurationStandartDeviation: number;
totalEffectCount: number;
averageEffectDurationMs: number;
effectDurationStandartDeviation: number;
commands: {
count: number;
maxDurationMs: number;
averageDurationMs: number;
standardDeviation: number;
name: string;
store: string;
}[];
effects: {
count: number;
maxDurationMs: number;
averageDurationMs: number;
standardDeviation: number;
name: string;
store: string;
}[];
};
/**
* Returns a StorePlugin that includes initialization and hooks for tracking command and effect performance.
* @returns The StorePlugin for performance tracking.
*/
declare function usePerformanceCounter(): StorePlugin;
interface AsyncStorage<TValue = unknown> {
initAsync(storeName: string, callback?: () => void): void;
getItemAsync(key: string, callback: (value: TValue | null) => void): void;
setItemAsync(key: string, value: TValue, callback?: () => void): void;
removeItemAsync(key: string, callback?: () => void): void;
}
/**
* Represents the interface for store persistence methods with synchronous operations.
*/
interface SyncStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
}
/**
* Projection functions which are applied before storing and after loading from storage
* This can be useful for obfuscating sensitive data prior to storing or for saving space
*/
interface PersistenceProjection<TState = never, TProjection = never> {
/**
* Function to transform the state before saving it to storage.
* @param state - The current state of the store.
* @returns The transformed state to be stored.
*/
onWrite: (state: TState) => TProjection;
/**
* Function to transform the loaded projection from storage before applying it to the store.
* @param projection - The loaded projection from storage.
* @returns The transformed state to be applied to the store.
*/
onLoad: (projection: TProjection) => TState;
}
/**
* Options for configuring the Store Persistence Plugin.
*/
interface StorePersistencePluginOptions<TState = never, TProjection = never> {
/**
* The key used for storing the state in the persistence storage (Optional, default _persisted_state_of_[storename]).
*/
persistenceKey?: string;
/**
* The storage medium used for persistence (Optional, default localStorage).
*/
persistenceStorage?: SyncStorage | AsyncStorage | 'LOCAL_STORAGE' | 'SESSION_STORAGE';
/**
* Projection functions which are applied before storing and after loading from storage
* This can be useful for obfuscating sensitive data prior to storing or for saving space.
* Optional, default nothing.
*/
projection?: PersistenceProjection<TState, TProjection>;
}
/**
* Represents the Store Persistence Plugin, enhancing a store with state persistence functionality.
*/
type StorePersistencePlugin<TStorage extends SyncStorage | AsyncStorage> = StorePlugin & {
storage: TStorage;
persistenceKey: string;
};
/**
* Clears the value associated with the provided key from local storage.
*
* @template TState - The type of state to clear from local storage.
* @param store - The store instance.
*
*/
declare function clearStoreStorage(store: Store<any>): void;
/**
* Enables Storeplugin that persists the store state to a storage (e.g. local storage).
* State changes are automatically synced with the storage.
* @param options - Options for configuring the StorePersistencePlugin.
* @returns A StorePersistencePlugin instance.
*/
declare function useStorePersistence<TState = never, TProjection = never>(options?: StorePersistencePluginOptions<TState, TProjection>): StorePersistencePlugin<any>;
/**
* Represents the configuration options for IndexedDB setup handlers.
*/
interface IndexedDbSetupHandlers {
/**
* Callback for handling the 'success' event after successfully connecting to the database.
*/
onSuccess?: () => void;
/**
* Callback for handling the 'blocked' event when a connection request is blocked.
*/
onBlocked?: () => void;
/**
* Callback for handling errors during database initialization.
*/
onInitializationError?: () => void;
}
/**
* Represents the options for connecting to an IndexedDB.
*/
interface IndexedDbOptions<TState = never, TProjection = never> {
/**
* The name of the IndexedDB database.
*/
dbName: string;
/**
* The version of the IndexedDB database. If not provided,
* the adapter will attempt to infer the version by inspecting the pool.
* This inference relies on prior configuration through the `migrateIndexedDb` function or previous usage of the same database.
*/
dbVersion?: number;
/**
* The name of the object store to connect to within the database.
* If not provided, it will use the stores name.
*/
objectStoreName?: string;
/**
* The key to use when connecting to a specific record within the object store. Default is store name.
*/
key?: string;
/**
* Configuration options for IndexedDB setup handlers.
*/
handlers?: IndexedDbSetupHandlers;
/**
* Projection functions which are applied before storing and after loading from storage
* This can be useful for obfuscating sensitive data prior to storing or for saving space.
* Optional, default nothing.
*/
projection?: PersistenceProjection<TState, TProjection>;
}
/**
* configures connection to an IndexedDb
* @param options - The configuration options for IndexedDB.
* @returns Store persistence plugin options.
*/
declare function configureIndexedDb<TState = never, TProjection = never>(options: IndexedDbOptions<TState, TProjection>): StorePersistencePluginOptions<TState, TProjection>;
type ObjectStoreMigration = (oldVersion: number, oldState: unknown) => unknown;
type DbUpdateOperation = ObjectStoreMigration | 'CLEAR' | 'DROP' | undefined;
type DbMigration = [string, DbUpdateOperation | IndexedDbStoreMigrator][];
/**
* Class for configuring indexedb object stores and their corresponding miggrations
*/
declare class IndexedDbStoreMigrator {
private readonly migrations;
/**
* Creates an object store if it does not exist
* @param objectStoreName - The name of the object store
* @returns The IndexedDbStoreRegistrator instance for chaining
*/
createStore(objectStoreName: string): this;
/**
* Creates an object store if it does not exist.
* If it does exists, the current object store value is cleared
* @param objectStoreName - The name of the object store
* @returns The IndexedDbStoreRegistrator instance for chaining
*/
createStoreOrClearState(objectStoreName: string): this;
/**
* Creates an object store if it does not exist.
* If it does exists, the current object store value can be transformed using the passed transformation function
* @param objectStoreName - The name of the object store
* @param transformation - Custom transformation function for update
* @returns The IndexedDbStoreRegistrator instance for chaining
*/
createStoreOrTransform(objectStoreName: string, transformation: (oldVersion: number, oldState: unknown) => any): this;
/**
* Creates an object store if it does not exist.
* If it does exists, the current object store value can be transformed using the passed transformation function
* @param objectStoreName - The name of the object store
* @param transformation - Custom transformation function for update
* @returns The IndexedDbStoreRegistrator instance for chaining
*/
createStoreOrMigrateRecords(objectStoreName: string, migration: (records: IndexedDbStoreMigrator) => IndexedDbStoreMigrator): this;
/**
* Deletes the object store if it does exist.
* @param objectStoreName - The name of the object store
* @returns The IndexedDbStoreRegistrator instance for chaining
*/
dropStore(objectStoreName: string): this;
/**
* Get all registrations
*/
getMigrations(): Immutable<DbMigration>;
}
/**
* Configures the IndexedDB with specified store registrations and database migration.
* @param dbName - The name of the IndexedDB database.
* @param dbVersion - The version of the IndexedDB database.
* @param migration - A function defining store registrations and migration operations.
* @remarks Migrations are registered lazily and applied upon the first use of the database.
* @throws Throws an error if no stores are registered for migration.
* @throws Throws an error if a migration for the specified database already exists.
*/
declare function migrateIndexedDb(dbName: string, dbVersion: number, migration: (model: IndexedDbStoreMigrator) => IndexedDbStoreMigrator): void;
/**
* Returns a Signal indicating whether the provided store has been modified.
*
* @note A store is initially considered unmodified. Any command (`set`, `update`, `mutate`) applied to the store
* will mark it as modified. Additionally, an effect created with the `setInitializedStatus` flag will reset the store's
* modification status to unmodified.
*
* @param store - The store to check for modification status.
* @returns Signal<boolean> - A signal indicating whether the store has been modified.
*/
declare function modified(store: Store<any>): Signal<boolean>;
/**
* Returns a Signal indicating whether the provided store has been initialized by an initializing effect.
*
* @note A store is initially considered as deinitialized. An effect created with the `setInitializedStatus` flag will set the store's
* initialization status to `true`.
*
* @param store - The store to check for initialization status.
* @returns Signal<boolean> - A signal indicating whether the store has been initialized.
*/
declare function initialized(store: Store<any>): Signal<boolean>;
/**
* Manually resets the status indicators for the provided store, marking it as deinitialized and unmodified.
* This means that both `unmodified()` and `initialized()` will return false. For manual reset of the loading status,
* use `markAsHavingNoRunningEffects`.
*
* @note This method is intended for exceptional cases.
*
* @param store - The store to manually reset the status.
* @returns void
*/
declare function resetStoreStatus(store: Store<any>): void;
/**
* Returns a Signal indicating whether any of the provided stores is in a loading state.
* If no stores are provided, the returned signal indicates if any store is in a loading state.
*
* @note An effect created with `setLoadingStatus` will mark the associated store as loading while the effect is running.
*
* @param stores - Stores to check for loading status. If no stores are provided, the signal checks all stores.
* @returns Signal<boolean> - A signal indicating whether any store is loading.
*/
declare function isLoading(...stores: Store<any>[]): Signal<boolean>;
/**
* Manually marks the provided store as not having any running effects.
*
* @note This method is intended for exceptional cases, specifically when you observe
* that an effect is not removed from the running state by signalstory automatically.
* If you encounter such a situation, use this method as a temporary workaround and
* be sure to file an issue on GitHub for further investigation and resolution.
*
* @param store - The store to manually mark as not having running effects.
* @returns void
*/
declare function markAsHavingNoRunningEffects(store: Store<any>): void;
/**
* Returns a Signal indicating whether any effect is currently running for any of the provided stores.
* If no Store is provided the returned signal indicates if any store has an effect running
* @param stores - Stores to check for running effects.
* @returns Signal<boolean> - A signal indicating whether any effect is running for any store.
*/
declare function isAnyEffectRunning(...stores: Store<any>[]): Signal<boolean>;
/**
* Returns a Signal indicating whether the specified effect is currently running for any of the provided stores.
* If no Store is provided the returned signal indicates if any store has the given effect running
* @param effect - The effect to check for.
* @param stores - Stores to check for the specified effect.
* @returns Signal<boolean> - A signal indicating whether the specified effect is running for any store.
*/
declare function isEffectRunning(effect: StoreEffect<any, any, any>, ...stores: Store<any>[]): Signal<boolean>;
/**
* Enables StorePlugin that tracks the loading and modification status of a store.
* @returns A StorePlugin instance for loading and modification status tracking.
*/
declare function useStoreStatus(): StorePlugin;
/**
* Represents a snapshot of the application state.
*/
interface StateSnapshot {
/**
* The timestamp when the snapshot was created.
*/
readonly timestamp: number;
/**
* Restores the application state to the captured snapshot.
*/
restore: () => void;
}
/**
* Creates a state snapshot either for specified stores or all stores in scope.
*
* If no stores are provided, the snapshot will include all stores currently in scope.
* Stores can be specified either as instances of Store or as ProviderTokens representing
* Store classes.
*
* @param stores - The stores for which to create a snapshot. Can be either instances
* of Store or ProviderTokens representing Store classes.
* @returns A StateSnapshot instance representing the application state snapshot.
*/
declare function createSnapshot(...stores: (Store<any> | ProviderToken<Store<any>>)[]): StateSnapshot;
export { ImmutableStore, Store, clearStoreStorage, configureIndexedDb, createEffect, createEvent, createQuery, createSnapshot, getReport, initialized, isAnyEffectRunning, isEffectRunning, isLoading, markAsHavingNoRunningEffects, migrateIndexedDb, modified, publishStoreEvent, resetStoreStatus, trackHistory, useDeepFreeze, useDevtools, useLogger, usePerformanceCounter, useStorePersistence, useStoreStatus };
export type { HistoryTracker, Immutable, ImmutableStoreConfig, StoreConfig, StoreEffect, StoreEvent, StorePersistencePluginOptions, StorePlugin, StoreQuery };