memorio 4.9.10 → 4.9.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ /**
2
+ * MEMORIO REDUX ADAPTER TYPES (hand-written, mirrors modules/redux.ts)
3
+ *
4
+ * `memorio/redux` is an OPTIONAL integration layer. It does not import `redux`
5
+ * or React; Redux-like stores are accepted by structural typing, so `redux`
6
+ * is never a dependency of Memorio (#4, #13).
7
+ */
8
+
9
+ import type { MemoryEntry, MemoryType, MemoryScope } from '../types/memory'
10
+
11
+ export interface MemorioReduxAction {
12
+ type: unknown
13
+ [key: string]: unknown
14
+ }
15
+
16
+ export interface MemorioReduxStoreLike<
17
+ S = unknown,
18
+ A extends MemorioReduxAction = MemorioReduxAction
19
+ > {
20
+ getState(): S
21
+ subscribe(listener: () => void): () => void
22
+ dispatch(action: A): unknown
23
+ }
24
+
25
+ export type MemorioReduxMiddleware<
26
+ S = unknown,
27
+ A extends MemorioReduxAction = MemorioReduxAction
28
+ > = (
29
+ api: { getState: () => S; dispatch: (action: A) => unknown }
30
+ ) => (next: (action: A) => any) => (action: A) => any
31
+
32
+ export interface MemorioMapping<S = any> {
33
+ selector: (state: S) => unknown
34
+ type?: MemoryType
35
+ confidence?: number
36
+ scope?: MemoryScope
37
+ ttl?: number | null
38
+ tags?: string | string[]
39
+ source?: string
40
+ ignoreActions?: unknown[]
41
+ }
42
+
43
+ export interface MemorioReduxOptions<
44
+ S = any,
45
+ A extends MemorioReduxAction = MemorioReduxAction
46
+ > {
47
+ mappings?: Record<string, MemorioMapping<S> | ((state: S) => unknown)>
48
+ whitelist?: unknown[]
49
+ blacklist?: unknown[]
50
+ failSoft?: boolean
51
+ onError?: (err: unknown, context: 'persist' | 'hydrate') => void
52
+ debug?: boolean
53
+ }
54
+
55
+ export interface MemorioMiddlewareHandle<
56
+ S = unknown,
57
+ A extends MemorioReduxAction = MemorioReduxAction
58
+ > {
59
+ middleware: MemorioReduxMiddleware<S, A>
60
+ cache: Record<string, unknown>
61
+ setHydrating: (v: boolean) => void
62
+ flush: () => Promise<void>
63
+ }
64
+
65
+ export interface MemorioReduxBridge<
66
+ S = unknown,
67
+ A extends MemorioReduxAction = MemorioReduxAction
68
+ > {
69
+ readonly middleware: MemorioReduxMiddleware<S, A>
70
+ hydrate: (
71
+ store: MemorioReduxStoreLike<S, A>,
72
+ opts?: { onHydration?: (values: Record<string, unknown>) => void }
73
+ ) => Promise<{ values: Record<string, unknown>; ok: boolean }>
74
+ flush: () => Promise<void>
75
+ disconnect: () => void
76
+ readonly cache: Record<string, unknown>
77
+ }
78
+
79
+ export interface HydrateOptions<S>
80
+ extends Pick<MemorioReduxOptions<S>, 'failSoft' | 'onError' | 'debug'> {
81
+ onHydration?: (values: Record<string, unknown>) => void
82
+ }
83
+
84
+ export interface HydrationResult {
85
+ values: Record<string, unknown>
86
+ ok: boolean
87
+ }
88
+
89
+ export interface HydrateBridge<S> {
90
+ cache: Record<string, unknown>
91
+ setHydrating: (v: boolean) => void
92
+ getState: () => S
93
+ }
94
+
95
+ export declare function createMemorioMiddleware<
96
+ S = any,
97
+ A extends MemorioReduxAction = MemorioReduxAction
98
+ >(opts?: MemorioReduxOptions<S, A>): MemorioMiddlewareHandle<S, A>
99
+
100
+ export declare function hydrateMemorio<S>(
101
+ mappings: Record<string, MemorioMapping<S> | ((state: S) => unknown)>,
102
+ opts?: HydrateOptions<S>,
103
+ bridge?: HydrateBridge<S>
104
+ ): Promise<HydrationResult>
105
+
106
+ export declare function createMemorioReduxBridge<
107
+ S = any,
108
+ A extends MemorioReduxAction = MemorioReduxAction
109
+ >(opts?: MemorioReduxOptions<S, A>): MemorioReduxBridge<S, A>
110
+
111
+ export declare function normalizeMappings<S>(mappings: MemorioReduxOptions<S>['mappings']): Record<string, MemorioMapping<S>>
112
+ export declare function selectValues<S>(state: S, mappings: Record<string, MemorioMapping<S>>): Record<string, unknown>
113
+ export declare function deepEqual(a: unknown, b: unknown): boolean
114
+ export declare function shouldIgnoreAction(action: MemorioReduxAction, opts: MemorioReduxOptions, mapping?: MemorioMapping): boolean
115
+ export declare function actionType(action: MemorioReduxAction): unknown
116
+
117
+ export { type MemoryEntry, type MemoryType, type MemoryScope }
118
+
119
+ export default createMemorioReduxBridge