UNPKG

2.76 kBTypeScriptView Raw
1import type { Middleware } from 'redux';
2/**
3 * Returns true if the passed value is "plain", i.e. a value that is either
4 * directly JSON-serializable (boolean, number, string, array, plain object)
5 * or `undefined`.
6 *
7 * @param val The value to check.
8 *
9 * @public
10 */
11export declare function isPlain(val: any): boolean;
12interface NonSerializableValue {
13 keyPath: string;
14 value: unknown;
15}
16/**
17 * @public
18 */
19export declare function findNonSerializableValue(value: unknown, path?: string, isSerializable?: (value: unknown) => boolean, getEntries?: (value: unknown) => [string, any][], ignoredPaths?: readonly string[]): NonSerializableValue | false;
20/**
21 * Options for `createSerializableStateInvariantMiddleware()`.
22 *
23 * @public
24 */
25export interface SerializableStateInvariantMiddlewareOptions {
26 /**
27 * The function to check if a value is considered serializable. This
28 * function is applied recursively to every value contained in the
29 * state. Defaults to `isPlain()`.
30 */
31 isSerializable?: (value: any) => boolean;
32 /**
33 * The function that will be used to retrieve entries from each
34 * value. If unspecified, `Object.entries` will be used. Defaults
35 * to `undefined`.
36 */
37 getEntries?: (value: any) => [string, any][];
38 /**
39 * An array of action types to ignore when checking for serializability.
40 * Defaults to []
41 */
42 ignoredActions?: string[];
43 /**
44 * An array of dot-separated path strings to ignore when checking
45 * for serializability, Defaults to ['meta.arg', 'meta.baseQueryMeta']
46 */
47 ignoredActionPaths?: string[];
48 /**
49 * An array of dot-separated path strings to ignore when checking
50 * for serializability, Defaults to []
51 */
52 ignoredPaths?: string[];
53 /**
54 * Execution time warning threshold. If the middleware takes longer
55 * than `warnAfter` ms, a warning will be displayed in the console.
56 * Defaults to 32ms.
57 */
58 warnAfter?: number;
59 /**
60 * Opt out of checking state. When set to `true`, other state-related params will be ignored.
61 */
62 ignoreState?: boolean;
63 /**
64 * Opt out of checking actions. When set to `true`, other action-related params will be ignored.
65 */
66 ignoreActions?: boolean;
67}
68/**
69 * Creates a middleware that, after every state change, checks if the new
70 * state is serializable. If a non-serializable value is found within the
71 * state, an error is printed to the console.
72 *
73 * @param options Middleware options.
74 *
75 * @public
76 */
77export declare function createSerializableStateInvariantMiddleware(options?: SerializableStateInvariantMiddlewareOptions): Middleware;
78export {};