import { Middleware, Store as ReduxStoreBase, UnknownAction } from 'redux'; import { SagaGenerator } from 'typed-redux-saga'; import { Observable } from 'kefir'; import { StoreRuntime } from './store-runtime'; export type StoreAction = { type: string; payload: PL; }; export type GenericAction = StoreAction; export type PayloadModifier = (...args: ARGS) => PL; export type StoreActionCreator = { (...args: ARGS): StoreAction; type: string; toString: () => string; }; export type SuccessResponse = { request: PL; response: R; }; export type ErrorResponse = { request: PL; error: Error; }; export type StoreAsyncAction = { type: string; asyncActionType: string; payload: PL; promise: Promise; success: StoreActionCreator<[R], SuccessResponse>; failure: StoreActionCreator<[Error], ErrorResponse>; }; export type StoreAsyncActionCreator = { (...args: ARGS): StoreAsyncAction; type: string; asyncActionType: string; success: StoreActionCreator<[R], SuccessResponse>; failure: StoreActionCreator<[Error], ErrorResponse>; toString: () => string; }; export type MiddlewareFunction = (action: GenericAction, api: { dispatch: ReduxStore["dispatch"]; getState: ReduxStore["getState"]; }) => GenericAction | Promise | void; export type StoreMiddleware = Middleware; type StateDomain = string; export type StoreStateMap = Record; export type StoreReducerFunction = (state: any, action: any) => TState; export type ReducersMap = Record; export type SelectorTracingOptions = { traceExecution?: boolean; traceCache?: boolean; traceInvalidation?: boolean; traceArguments?: boolean; traceResults?: boolean; traceCadence?: boolean; minDurationMs?: number; minRecomputationCount?: number; minCacheMissCount?: number; summaryEnabled?: boolean; summaryIntervalMs?: number; }; export type NormalizedSelectorTracingOptions = { traceExecution: boolean; traceCache: boolean; traceInvalidation: boolean; traceArguments: boolean; traceResults: boolean; traceCadence: boolean; minDurationMs: number; minRecomputationCount: number; minCacheMissCount: number; summaryEnabled: boolean; summaryIntervalMs: number; }; export type SelectorTraceInvalidationReason = 'first-execution' | 'selector-arguments-changed' | 'accessed-state-paths-changed' | 'previous-result-unavailable'; export type SelectorTraceResultOutcome = 'initial' | 'changed' | 'retained-reference'; export type SelectorTraceDurationSummary = Readonly<{ count: number; totalMs: number; averageMs: number; maximumMs: number; p95Ms: number; }>; export type SelectorTraceCacheSummary = Readonly<{ requestCount: number; hitCount: number; missCount: number; hitRatio: number | null; }>; export type SelectorTraceSelectorSummary = Readonly<{ selectorSource: string; executionCount: number; recomputationCount: number; invalidationReasons: Readonly>; resultOutcomes: Readonly>; duration: SelectorTraceDurationSummary; cache: SelectorTraceCacheSummary; }>; export type SelectorTraceSummary = ReadonlyArray; export type SelectorTracePeriodSummary = Readonly<{ selectorSource: string; executionCount: number; recomputationCount: number; invalidationReasons: Readonly>; resultOutcomes: Readonly>; arguments: Readonly<{ count: number; changedCount: number; }>; duration: Readonly>; cache: SelectorTraceCacheSummary; }>; export type SelectorTraceAggregate = Readonly<{ intervalMs: number; selectors: ReadonlyArray; }>; export type SelectorDetailTraceEvent = Readonly<{ kind: 'selector' | 'cache'; selectorSource: string; [field: string]: unknown; }>; export type SelectorCadenceTraceEvent = Readonly<{ type: 'tick' | 'subscribe'; timestamp?: number; listenerCount: number; }>; export type SagaMonitorTraceEvent = Readonly<{ type: 'effectTriggered'; event: unknown; } | { type: 'effectResolved'; effectId: number; result: unknown; } | { type: 'effectRejected'; effectId: number; error: unknown; } | { type: 'effectCancelled'; effectId: number; } | { type: 'actionDispatched'; action: unknown; }>; export type RuntimeErrorTraceEvent = Readonly<{ error: unknown; source?: string; message?: string; payload?: unknown; }>; export type ReduxActionTraceEvent = Readonly<{ /** The dispatched action payload. Redact sensitive values before sharing. */ action: unknown; /** State reference before the reducer chain ran. */ prevState: unknown; /** State reference returned by the reducer chain. */ nextState: unknown; /** Whether the reducer chain returned a different state reference. */ stateChanged: boolean; }>; export type StoreRuntimeErrorReporter = (event: RuntimeErrorTraceEvent) => void; export type StoreTraceStreams = Readonly<{ selectorDetail: Observable; selectorSummary: Observable; selectorCadence: Observable; sagaMonitor: Observable; runtimeError: Observable; reduxAction: Observable; }>; export type StoreLoggerFactory = (streams: StoreTraceStreams) => void | (() => void); export type StoreOptions = { /** * Reactive selector emission frequency in frames per second. * Defaults to 64 FPS and accepts finite values in the inclusive 1..256 range. */ throttledSelectorFrequency?: number; /** * Enables the built-in redux-saga monitor for Store-owned saga middleware. * Defaults to false, leaving saga monitoring disabled. */ sagaMonitor?: boolean; /** * Enables Store-owned Redux action logging. Defaults to false. */ logReduxActions?: boolean; /** * Enables diagnostic selector flush tracing. * Defaults to false, leaving selector tracing silent. */ traceSelectors?: boolean | SelectorTracingOptions; /** * Creates a Store-owned logger subscription for this instance's trace streams. * The returned disposer is called when the Store is disposed. */ loggerFactory?: StoreLoggerFactory; }; export type NormalizedStoreOptions = { throttledSelectorFrequency: number; sagaMonitor: boolean; logReduxActions: boolean; traceSelectors: NormalizedSelectorTracingOptions; loggerFactory?: StoreLoggerFactory; }; export type StoreReducerState = Reducer extends StoreReducerFunction ? State : never; export type StoreStateFromStateMap = { [Domain in keyof TStateMap]: TStateMap[Domain]; }; export type StoreStateFromReducers = { [Domain in keyof Reducers]: StoreReducerState; }; export type StoreState = TStore extends { readonly state: infer State; } ? State : TStore extends { getReducers(): infer Reducers; } ? Reducers extends ReducersMap ? StoreStateFromReducers : Record : Record; /** * StoreInstanceState is a readable alias for the selector state shape of a concrete Store instance. */ export type StoreInstanceState = StoreState; export type PreloadedStoreState = Partial; type ReduxStore = ReduxStoreBase; type ReadableValue = { subscribe(run: (value: T) => void, invalidate?: (value?: T) => void): () => void; }; /** * Framework-neutral compatibility contract for readable selector arguments. */ export type ReadableArgs = { [K in keyof ARGS]: ARGS[K] | ReadableValue; }; export type StoreSelectorCallback = (state: TState, ...args: ARGS) => R; export type StoreSelectorReadable = (...args: ReadableArgs) => ReadableValue; export type StoreSelectorSelect = StoreSelectorCallback; export type StoreSelectorEffect = (...args: ARGS) => SagaGenerator; type StoreSelectorWithStore = StoreRuntime> = (store: TStore) => StoreSelectorReadable; export type StoreSelector = StoreRuntime> = StoreSelectorReadable & { withStore: StoreSelectorWithStore; select: StoreSelectorSelect; effect: StoreSelectorEffect; }; export type CreateSelector = , ARGS extends any[] = [], R = unknown>(store: TStore, selectorFunc: StoreSelectorCallback>) => StoreSelector, TStore>; export {}; //# sourceMappingURL=types.d.ts.map