UNPKG

synapse-storage

Version:

Набор инструментов для управления состоянием и апи-запросами

92 lines (91 loc) 3.33 kB
import { StorageKeyType } from './storage-key'; /** * Sentinel object returned by middleware to signal that the value has not changed. * BaseStorage checks for this by reference equality to skip subscriber notifications. */ export declare const VALUE_NOT_CHANGED: unique symbol; export type StorageActionType = 'get' | 'set' | 'delete' | 'clear' | 'init' | 'keys' | 'update' | 'reset'; export type StorageAction = { type: StorageActionType; key?: StorageKeyType; value?: any; metadata?: Record<string, any>; source?: string; timestamp?: number; }; export type MiddlewareAPI = { dispatch: (action: StorageAction) => Promise<any>; getState: () => Promise<Record<string, any>>; storage: { doGet: (key: StorageKeyType) => Promise<any>; doSet: (key: StorageKeyType, value: any) => Promise<void>; doUpdate: (updates: Array<{ key: StorageKeyType; value: any; }>) => Promise<void>; doDelete: (key: StorageKeyType) => Promise<boolean>; doClear: () => Promise<void>; doKeys: () => Promise<string[]>; notifySubscribers: (key: StorageKeyType, value: any) => void; }; }; export type NextFunction = (action: StorageAction) => Promise<any>; export type SetupEventsFunction = (api: MiddlewareAPI) => void; export type Middleware = { name: string; setup?: SetupEventsFunction; cleanup?: () => Promise<void> | void; reducer: (api: MiddlewareAPI) => (next: NextFunction) => (action: StorageAction) => Promise<any>; }; export type AsyncMiddlewareAPI = MiddlewareAPI; export type AsyncNextFunction = NextFunction; export type AsyncMiddleware = Middleware; export type SyncMiddlewareAPI = { dispatch: (action: StorageAction) => any; getState: () => Record<string, any>; storage: { doGet: (key: StorageKeyType) => any; doSet: (key: StorageKeyType, value: any) => void; doUpdate: (updates: Array<{ key: StorageKeyType; value: any; }>) => void; doRemove: (key: StorageKeyType) => boolean; doClear: () => void; doKeys: () => string[]; notifySubscribers: (key: StorageKeyType, value: any) => void; }; }; export type SyncNextFunction = (action: StorageAction) => any; export type SyncSetupEventsFunction = (api: SyncMiddlewareAPI) => void; export type SyncMiddleware = { name: string; setup?: SyncSetupEventsFunction; cleanup?: () => void; reducer: (api: SyncMiddlewareAPI) => (next: SyncNextFunction) => (action: StorageAction) => any; }; export declare class AsyncMiddlewareModule { private middlewares; private api; private initialized; private dispatchFn; constructor(storage: any); private baseOperation; private initializeMiddlewares; use(middleware: Middleware): void; dispatch(action: StorageAction): Promise<any>; } /** @deprecated Use AsyncMiddlewareModule */ export declare class MiddlewareModule extends AsyncMiddlewareModule { } export declare class SyncMiddlewareModule { private middlewares; private api; private initialized; private dispatchFn; constructor(storage: any); private baseOperation; private initializeMiddlewares; use(middleware: SyncMiddleware): void; dispatch(action: StorageAction): any; }