@buoy-gg/storage 7.0.41 → 7.0.42
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.
- package/README.md +11 -90
- package/lib/commonjs/index.js +1 -353
- package/lib/commonjs/preset.js +1 -85
- package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +1 -36
- package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -12
- package/lib/commonjs/storage/components/DiffViewer/themes/diffThemes.js +1 -24
- package/lib/commonjs/storage/components/GameUIStorageBrowser.js +3 -1259
- package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +1 -257
- package/lib/commonjs/storage/components/MMKVInstanceSelector.js +1 -419
- package/lib/commonjs/storage/components/SelectionActionBar.js +1 -207
- package/lib/commonjs/storage/components/StorageActionButtons.js +1 -242
- package/lib/commonjs/storage/components/StorageBrowserMode.js +1 -61
- package/lib/commonjs/storage/components/StorageEventActionButton.js +1 -121
- package/lib/commonjs/storage/components/StorageEventCard.js +1 -118
- package/lib/commonjs/storage/components/StorageEventDetailContent.js +1 -494
- package/lib/commonjs/storage/components/StorageEventFilterView.js +1 -160
- package/lib/commonjs/storage/components/StorageEventsSection.js +1 -24
- package/lib/commonjs/storage/components/StorageFilterCards.js +1 -231
- package/lib/commonjs/storage/components/StorageKeyCard.js +1 -520
- package/lib/commonjs/storage/components/StorageKeyDetailScreen.js +1 -579
- package/lib/commonjs/storage/components/StorageKeyRow.js +1 -559
- package/lib/commonjs/storage/components/StorageKeySection.js +1 -160
- package/lib/commonjs/storage/components/StorageKeyStats.js +1 -345
- package/lib/commonjs/storage/components/StorageModalWithTabs.js +1 -954
- package/lib/commonjs/storage/components/StorageSaveNotice.js +1 -171
- package/lib/commonjs/storage/components/StorageSection.js +1 -43
- package/lib/commonjs/storage/components/StorageTypeFilterBar.js +1 -144
- package/lib/commonjs/storage/hooks/useAsyncStorageKeys.js +1 -141
- package/lib/commonjs/storage/hooks/useMMKVInstances.js +1 -210
- package/lib/commonjs/storage/hooks/useMMKVKeys.js +1 -376
- package/lib/commonjs/storage/hooks/useSecureStoreKeys.js +1 -202
- package/lib/commonjs/storage/hooks/useStorageEvents.js +1 -61
- package/lib/commonjs/storage/stores/storageEventStore.js +1 -312
- package/lib/commonjs/storage/sync/storageSyncAdapter.js +1 -492
- package/lib/commonjs/storage/types.js +1 -5
- package/lib/commonjs/storage/utils/AsyncStorageListener.js +1 -691
- package/lib/commonjs/storage/utils/AsyncStorageListener.web.js +1 -89
- package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +1 -203
- package/lib/commonjs/storage/utils/MMKVListener.js +1 -416
- package/lib/commonjs/storage/utils/SecureStoreRegistry.js +1 -200
- package/lib/commonjs/storage/utils/asyncStorageCompat.js +1 -89
- package/lib/commonjs/storage/utils/browserStorageLifecycle.js +1 -10
- package/lib/commonjs/storage/utils/browserStorageLifecycle.web.js +1 -70
- package/lib/commonjs/storage/utils/clearAllStorage.js +1 -48
- package/lib/commonjs/storage/utils/deleteStorageKeys.js +1 -82
- package/lib/commonjs/storage/utils/lineDiff.js +1 -30
- package/lib/commonjs/storage/utils/mmkvAvailability.js +1 -62
- package/lib/commonjs/storage/utils/mmkvAvailability.web.js +1 -21
- package/lib/commonjs/storage/utils/mmkvTypeDetection.js +1 -154
- package/lib/commonjs/storage/utils/requiredStorageKeyScope.js +1 -17
- package/lib/commonjs/storage/utils/setStorageValue.js +1 -218
- package/lib/commonjs/storage/utils/snapshotProvider.js +1 -382
- package/lib/commonjs/storage/utils/storageActionHelpers.js +1 -46
- package/lib/commonjs/storage/utils/storageBrowserRefresh.js +1 -49
- package/lib/commonjs/storage/utils/storageLabels.js +1 -13
- package/lib/commonjs/storage/utils/storageLabels.web.js +1 -13
- package/lib/commonjs/storage/utils/storageOps.js +1 -53
- package/lib/commonjs/storage/utils/storageQueryUtils.js +1 -35
- package/lib/commonjs/storage/utils/storageTimeTravelUtils.js +1 -288
- package/lib/commonjs/storage/utils/valueType.js +1 -83
- package/lib/module/index.js +1 -114
- package/lib/module/preset.js +1 -82
- package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +1 -32
- package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -9
- package/lib/module/storage/components/DiffViewer/themes/diffThemes.js +1 -10
- package/lib/module/storage/components/GameUIStorageBrowser.js +3 -1257
- package/lib/module/storage/components/MMKVInstanceInfoPanel.js +1 -253
- package/lib/module/storage/components/MMKVInstanceSelector.js +1 -415
- package/lib/module/storage/components/SelectionActionBar.js +1 -204
- package/lib/module/storage/components/StorageActionButtons.js +1 -238
- package/lib/module/storage/components/StorageBrowserMode.js +1 -57
- package/lib/module/storage/components/StorageEventActionButton.js +1 -118
- package/lib/module/storage/components/StorageEventCard.js +1 -113
- package/lib/module/storage/components/StorageEventDetailContent.js +1 -490
- package/lib/module/storage/components/StorageEventFilterView.js +1 -156
- package/lib/module/storage/components/StorageEventsSection.js +1 -20
- package/lib/module/storage/components/StorageFilterCards.js +1 -227
- package/lib/module/storage/components/StorageKeyCard.js +1 -517
- package/lib/module/storage/components/StorageKeyDetailScreen.js +1 -577
- package/lib/module/storage/components/StorageKeyRow.js +1 -554
- package/lib/module/storage/components/StorageKeySection.js +1 -155
- package/lib/module/storage/components/StorageKeyStats.js +1 -342
- package/lib/module/storage/components/StorageModalWithTabs.js +1 -949
- package/lib/module/storage/components/StorageSaveNotice.js +1 -168
- package/lib/module/storage/components/StorageSection.js +1 -40
- package/lib/module/storage/components/StorageTypeFilterBar.js +1 -139
- package/lib/module/storage/hooks/useAsyncStorageKeys.js +1 -136
- package/lib/module/storage/hooks/useMMKVInstances.js +1 -204
- package/lib/module/storage/hooks/useMMKVKeys.js +1 -371
- package/lib/module/storage/hooks/useSecureStoreKeys.js +1 -199
- package/lib/module/storage/hooks/useStorageEvents.js +1 -58
- package/lib/module/storage/stores/storageEventStore.js +1 -301
- package/lib/module/storage/sync/storageSyncAdapter.js +1 -486
- package/lib/module/storage/types.js +1 -3
- package/lib/module/storage/utils/AsyncStorageListener.js +1 -679
- package/lib/module/storage/utils/AsyncStorageListener.web.js +1 -76
- package/lib/module/storage/utils/MMKVInstanceRegistry.js +1 -197
- package/lib/module/storage/utils/MMKVListener.js +1 -403
- package/lib/module/storage/utils/SecureStoreRegistry.js +1 -194
- package/lib/module/storage/utils/asyncStorageCompat.js +1 -81
- package/lib/module/storage/utils/browserStorageLifecycle.js +1 -6
- package/lib/module/storage/utils/browserStorageLifecycle.web.js +1 -66
- package/lib/module/storage/utils/clearAllStorage.js +1 -43
- package/lib/module/storage/utils/deleteStorageKeys.js +1 -78
- package/lib/module/storage/utils/lineDiff.js +1 -12
- package/lib/module/storage/utils/mmkvAvailability.js +1 -56
- package/lib/module/storage/utils/mmkvAvailability.web.js +1 -15
- package/lib/module/storage/utils/mmkvTypeDetection.js +1 -148
- package/lib/module/storage/utils/requiredStorageKeyScope.js +1 -13
- package/lib/module/storage/utils/setStorageValue.js +1 -209
- package/lib/module/storage/utils/snapshotProvider.js +1 -380
- package/lib/module/storage/utils/storageActionHelpers.js +1 -42
- package/lib/module/storage/utils/storageBrowserRefresh.js +1 -44
- package/lib/module/storage/utils/storageLabels.js +1 -9
- package/lib/module/storage/utils/storageLabels.web.js +1 -9
- package/lib/module/storage/utils/storageOps.js +1 -46
- package/lib/module/storage/utils/storageQueryUtils.js +1 -30
- package/lib/module/storage/utils/storageTimeTravelUtils.js +1 -281
- package/lib/module/storage/utils/valueType.js +1 -76
- package/lib/web/index.mjs +2 -3
- package/package.json +5 -5
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts.map +0 -1
- package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +0 -1
- package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts.map +0 -1
- package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts.map +0 -1
- package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageActionButtons.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventActionButton.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventCard.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventFilterView.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventsSection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyCard.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyDetailScreen.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeySection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageSaveNotice.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageSection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useMMKVInstances.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useMMKVKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useStorageEvents.d.ts.map +0 -1
- package/lib/typescript/storage/stores/storageEventStore.d.ts.map +0 -1
- package/lib/typescript/storage/sync/storageSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/storage/types.d.ts.map +0 -1
- package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +0 -1
- package/lib/typescript/storage/utils/AsyncStorageListener.web.d.ts.map +0 -1
- package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +0 -1
- package/lib/typescript/storage/utils/MMKVListener.d.ts.map +0 -1
- package/lib/typescript/storage/utils/SecureStoreRegistry.d.ts.map +0 -1
- package/lib/typescript/storage/utils/asyncStorageCompat.d.ts.map +0 -1
- package/lib/typescript/storage/utils/browserStorageLifecycle.d.ts.map +0 -1
- package/lib/typescript/storage/utils/browserStorageLifecycle.web.d.ts.map +0 -1
- package/lib/typescript/storage/utils/clearAllStorage.d.ts.map +0 -1
- package/lib/typescript/storage/utils/deleteStorageKeys.d.ts.map +0 -1
- package/lib/typescript/storage/utils/lineDiff.d.ts.map +0 -1
- package/lib/typescript/storage/utils/mmkvAvailability.d.ts.map +0 -1
- package/lib/typescript/storage/utils/mmkvAvailability.web.d.ts.map +0 -1
- package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts.map +0 -1
- package/lib/typescript/storage/utils/requiredStorageKeyScope.d.ts.map +0 -1
- package/lib/typescript/storage/utils/setStorageValue.d.ts.map +0 -1
- package/lib/typescript/storage/utils/snapshotProvider.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageActionHelpers.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageBrowserRefresh.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageLabels.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageLabels.web.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageOps.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageQueryUtils.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageTimeTravelUtils.d.ts.map +0 -1
- package/lib/typescript/storage/utils/valueType.d.ts.map +0 -1
|
@@ -1,204 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* useMMKVInstances Hook
|
|
5
|
-
*
|
|
6
|
-
* React hook to monitor all registered MMKV instances and their metadata.
|
|
7
|
-
* Works with MMKVInstanceRegistry to provide UI components with instance information.
|
|
8
|
-
*
|
|
9
|
-
* This hook enables:
|
|
10
|
-
* - Multi-instance dropdown/selector UI
|
|
11
|
-
* - Instance metadata display (encrypted, readOnly, key count)
|
|
12
|
-
* - Dynamic updates when instances are added/removed
|
|
13
|
-
*
|
|
14
|
-
* @see MMKVInstanceRegistry.ts for instance registration
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { useState, useEffect } from 'react';
|
|
18
|
-
// The registry is pure JS (no react-native-mmkv dependency) — import it
|
|
19
|
-
// unconditionally so registered instances show up even without the native
|
|
20
|
-
// module (e.g. remote-backed wrappers on the desktop dashboard).
|
|
21
|
-
import { mmkvInstanceRegistry } from '../utils/MMKVInstanceRegistry';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Metadata about an MMKV instance with additional runtime information
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Hook to monitor all registered MMKV instances
|
|
29
|
-
*
|
|
30
|
-
* @param autoRefresh - If true, refreshes every 1 second to detect new instances
|
|
31
|
-
*
|
|
32
|
-
* @returns Object containing instances array, count, and refresh function
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* import { useMMKVInstances } from '@buoy-gg/storage';
|
|
37
|
-
*
|
|
38
|
-
* function MMKVInstanceSelector() {
|
|
39
|
-
* const { instances, instanceCount, refresh } = useMMKVInstances();
|
|
40
|
-
*
|
|
41
|
-
* return (
|
|
42
|
-
* <View>
|
|
43
|
-
* <Text>Found {instanceCount} MMKV instances</Text>
|
|
44
|
-
* {instances.map(inst => (
|
|
45
|
-
* <TouchableOpacity key={inst.id} onPress={() => selectInstance(inst)}>
|
|
46
|
-
* <Text>{inst.id}</Text>
|
|
47
|
-
* <Text>{inst.keyCount} keys</Text>
|
|
48
|
-
* {inst.encrypted && <Text>🔒 Encrypted</Text>}
|
|
49
|
-
* {inst.readOnly && <Text>👁️ Read-only</Text>}
|
|
50
|
-
* </TouchableOpacity>
|
|
51
|
-
* ))}
|
|
52
|
-
* <Button onPress={refresh}>Refresh</Button>
|
|
53
|
-
* </View>
|
|
54
|
-
* );
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export function useMMKVInstances(autoRefresh = false) {
|
|
59
|
-
const [instances, setInstances] = useState([]);
|
|
60
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
61
|
-
|
|
62
|
-
// Fetch all instances and their metadata
|
|
63
|
-
const fetchInstances = () => {
|
|
64
|
-
setIsLoading(true);
|
|
65
|
-
try {
|
|
66
|
-
const allInstances = mmkvInstanceRegistry.getAll();
|
|
67
|
-
|
|
68
|
-
// Enhance with metadata
|
|
69
|
-
const instancesWithMetadata = allInstances.map(instanceInfo => {
|
|
70
|
-
const {
|
|
71
|
-
instance,
|
|
72
|
-
id,
|
|
73
|
-
encrypted,
|
|
74
|
-
readOnly
|
|
75
|
-
} = instanceInfo;
|
|
76
|
-
|
|
77
|
-
// Get key count
|
|
78
|
-
const keys = instance.getAllKeys();
|
|
79
|
-
const keyCount = keys?.length || 0;
|
|
80
|
-
|
|
81
|
-
// Get size if available (MMKV might not expose this directly)
|
|
82
|
-
// For now, we don't have a direct way to get size
|
|
83
|
-
const size = undefined;
|
|
84
|
-
return {
|
|
85
|
-
id,
|
|
86
|
-
instance,
|
|
87
|
-
encrypted,
|
|
88
|
-
readOnly,
|
|
89
|
-
keyCount,
|
|
90
|
-
size
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
setInstances(instancesWithMetadata);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
setInstances([]);
|
|
96
|
-
} finally {
|
|
97
|
-
setIsLoading(false);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// Initial fetch
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
fetchInstances();
|
|
104
|
-
}, []);
|
|
105
|
-
|
|
106
|
-
// Auto-refresh if enabled
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (!autoRefresh) return;
|
|
109
|
-
const interval = setInterval(() => {
|
|
110
|
-
fetchInstances();
|
|
111
|
-
}, 1000); // Refresh every second
|
|
112
|
-
|
|
113
|
-
return () => clearInterval(interval);
|
|
114
|
-
}, [autoRefresh]);
|
|
115
|
-
return {
|
|
116
|
-
instances,
|
|
117
|
-
instanceCount: instances.length,
|
|
118
|
-
isLoading,
|
|
119
|
-
refresh: fetchInstances
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Hook to monitor a single MMKV instance by ID
|
|
125
|
-
*
|
|
126
|
-
* @param instanceId - ID of the instance to monitor
|
|
127
|
-
*
|
|
128
|
-
* @returns Instance metadata or null if not found
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* function MMKVInstanceDetail({ instanceId }: { instanceId: string }) {
|
|
133
|
-
* const instance = useMMKVInstance(instanceId);
|
|
134
|
-
*
|
|
135
|
-
* if (!instance) {
|
|
136
|
-
* return <Text>Instance not found</Text>;
|
|
137
|
-
* }
|
|
138
|
-
*
|
|
139
|
-
* return (
|
|
140
|
-
* <View>
|
|
141
|
-
* <Text>ID: {instance.id}</Text>
|
|
142
|
-
* <Text>Keys: {instance.keyCount}</Text>
|
|
143
|
-
* <Text>Encrypted: {instance.encrypted ? 'Yes' : 'No'}</Text>
|
|
144
|
-
* <Text>Read-only: {instance.readOnly ? 'Yes' : 'No'}</Text>
|
|
145
|
-
* </View>
|
|
146
|
-
* );
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
export function useMMKVInstance(instanceId) {
|
|
151
|
-
const [instance, setInstance] = useState(null);
|
|
152
|
-
useEffect(() => {
|
|
153
|
-
if (!mmkvInstanceRegistry) {
|
|
154
|
-
setInstance(null);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const instanceInfo = mmkvInstanceRegistry.get(instanceId);
|
|
158
|
-
if (!instanceInfo) {
|
|
159
|
-
setInstance(null);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const keys = instanceInfo.instance.getAllKeys();
|
|
163
|
-
const keyCount = keys?.length || 0;
|
|
164
|
-
setInstance({
|
|
165
|
-
...instanceInfo,
|
|
166
|
-
keyCount,
|
|
167
|
-
size: undefined
|
|
168
|
-
});
|
|
169
|
-
}, [instanceId]);
|
|
170
|
-
return instance;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Hook to check if a specific instance ID is registered
|
|
175
|
-
*
|
|
176
|
-
* @param instanceId - ID to check
|
|
177
|
-
*
|
|
178
|
-
* @returns True if instance is registered
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```typescript
|
|
182
|
-
* function MMKVStatus({ instanceId }: { instanceId: string }) {
|
|
183
|
-
* const isRegistered = useMMKVInstanceExists(instanceId);
|
|
184
|
-
*
|
|
185
|
-
* return (
|
|
186
|
-
* <View>
|
|
187
|
-
* <Text>{instanceId}</Text>
|
|
188
|
-
* <Text>{isRegistered ? '✅ Registered' : '❌ Not registered'}</Text>
|
|
189
|
-
* </View>
|
|
190
|
-
* );
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
export function useMMKVInstanceExists(instanceId) {
|
|
195
|
-
const [exists, setExists] = useState(false);
|
|
196
|
-
useEffect(() => {
|
|
197
|
-
if (!mmkvInstanceRegistry) {
|
|
198
|
-
setExists(false);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
setExists(mmkvInstanceRegistry.has(instanceId));
|
|
202
|
-
}, [instanceId]);
|
|
203
|
-
return exists;
|
|
204
|
-
}
|
|
1
|
+
"use strict";import{useState as i,useEffect as l}from"react";import{mmkvInstanceRegistry as c}from"../utils/MMKVInstanceRegistry";export function useMMKVInstances(n=false){const[e,t]=i([]);const[s,a]=i(true);const r=()=>{a(true);try{const o=c.getAll();const f=o.map(y=>{const{instance:u,id:g,encrypted:I,readOnly:d}=y;const h=u.getAllKeys();const m=h?.length||0;const p=void 0;return{id:g,instance:u,encrypted:I,readOnly:d,keyCount:m,size:p}});t(f)}catch(o){t([])}finally{a(false)}};l(()=>{r()},[]);l(()=>{if(!n)return;const o=setInterval(()=>{r()},1e3);return()=>clearInterval(o)},[n]);return{instances:e,instanceCount:e.length,isLoading:s,refresh:r}}export function useMMKVInstance(n){const[e,t]=i(null);l(()=>{if(!c){t(null);return}const s=c.get(n);if(!s){t(null);return}const a=s.instance.getAllKeys();const r=a?.length||0;t({...s,keyCount:r,size:void 0})},[n]);return e}export function useMMKVInstanceExists(n){const[e,t]=i(false);l(()=>{if(!c){t(false);return}t(c.has(n))},[n]);return e}
|
|
@@ -1,371 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* useMMKVKeys Hook
|
|
5
|
-
*
|
|
6
|
-
* Fetch and validate MMKV keys from a specific MMKV instance.
|
|
7
|
-
* Equivalent to useAsyncStorageKeys but for MMKV storage.
|
|
8
|
-
*
|
|
9
|
-
* Key Differences from AsyncStorage:
|
|
10
|
-
* - Synchronous API (getAllKeys(), getString(), etc.)
|
|
11
|
-
* - Native types (string, number, boolean, buffer) vs string-only
|
|
12
|
-
* - Multi-instance support (requires instanceId parameter)
|
|
13
|
-
* - No multiGet - must fetch keys individually
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
17
|
-
import { requiredKeyAppliesTo } from '../utils/requiredStorageKeyScope';
|
|
18
|
-
// Pure-JS utilities (no react-native-mmkv dependency) — safe to import
|
|
19
|
-
// unconditionally. They operate on whatever instance objects are registered,
|
|
20
|
-
// including remote-backed wrappers on the desktop dashboard.
|
|
21
|
-
import { detectMMKVType, isTypeMatch } from '../utils/mmkvTypeDetection';
|
|
22
|
-
|
|
23
|
-
// Conditionally import MMKV types
|
|
24
|
-
// Use 'any' to avoid hard dependency on react-native-mmkv
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Hook to fetch and monitor keys from an MMKV instance
|
|
28
|
-
*
|
|
29
|
-
* @param instance - MMKV instance to monitor
|
|
30
|
-
* @param instanceId - Unique identifier for this instance (e.g., "mmkv.default", "secure")
|
|
31
|
-
* @param requiredStorageKeys - Optional array of required keys for validation
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* import { MMKV } from 'react-native-mmkv';
|
|
36
|
-
* import { useMMKVKeys } from '@buoy-gg/storage';
|
|
37
|
-
*
|
|
38
|
-
* const storage = new MMKV();
|
|
39
|
-
*
|
|
40
|
-
* function MyComponent() {
|
|
41
|
-
* const { storageKeys, isLoading, error, refresh } = useMMKVKeys(
|
|
42
|
-
* storage,
|
|
43
|
-
* 'mmkv.default',
|
|
44
|
-
* [
|
|
45
|
-
* 'user.token',
|
|
46
|
-
* { key: 'user.id', expectedType: 'number' },
|
|
47
|
-
* { key: 'app.theme', expectedValue: 'dark' }
|
|
48
|
-
* ]
|
|
49
|
-
* );
|
|
50
|
-
*
|
|
51
|
-
* if (isLoading) return <LoadingSpinner />;
|
|
52
|
-
* if (error) return <ErrorMessage error={error} />;
|
|
53
|
-
*
|
|
54
|
-
* return (
|
|
55
|
-
* <View>
|
|
56
|
-
* {storageKeys.map(keyInfo => (
|
|
57
|
-
* <StorageKeyCard key={keyInfo.key} keyInfo={keyInfo} />
|
|
58
|
-
* ))}
|
|
59
|
-
* <Button onPress={refresh}>Refresh</Button>
|
|
60
|
-
* </View>
|
|
61
|
-
* );
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export function useMMKVKeys(instance, instanceId, requiredStorageKeys = []) {
|
|
66
|
-
// State management
|
|
67
|
-
const [storageKeys, setStorageKeys] = useState([]);
|
|
68
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
69
|
-
const [error, setError] = useState(null);
|
|
70
|
-
|
|
71
|
-
// Depend on a stable content signature rather than the array identity — a
|
|
72
|
-
// fresh `requiredStorageKeys` literal each render would otherwise loop the
|
|
73
|
-
// fetch effect. Read the latest array via ref inside the fetch.
|
|
74
|
-
const requiredSignature = JSON.stringify(requiredStorageKeys);
|
|
75
|
-
const requiredRef = useRef(requiredStorageKeys);
|
|
76
|
-
requiredRef.current = requiredStorageKeys;
|
|
77
|
-
|
|
78
|
-
// Fetch all keys and values from MMKV instance
|
|
79
|
-
const fetchStorageData = useCallback(() => {
|
|
80
|
-
const requiredStorageKeys = requiredRef.current;
|
|
81
|
-
setIsLoading(true);
|
|
82
|
-
setError(null);
|
|
83
|
-
try {
|
|
84
|
-
// Guard: Check if instance is provided. (No isMMKVAvailable() gate —
|
|
85
|
-
// registered instances may be remote-backed wrappers with no native
|
|
86
|
-
// module, e.g. on the desktop dashboard.)
|
|
87
|
-
if (!instance) {
|
|
88
|
-
setStorageKeys([]);
|
|
89
|
-
setIsLoading(false);
|
|
90
|
-
return; // Silently return empty when no instance
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 1. Get all keys from MMKV (synchronous)
|
|
94
|
-
const allKeys = instance.getAllKeys();
|
|
95
|
-
if (!allKeys || allKeys.length === 0) {
|
|
96
|
-
// Still need to check for missing required keys scoped to MMKV
|
|
97
|
-
const missingRequiredKeys = requiredStorageKeys.filter(req => requiredKeyAppliesTo(req, 'mmkv')).map(req => {
|
|
98
|
-
const key = typeof req === 'string' ? req : req.key;
|
|
99
|
-
const description = typeof req === 'object' ? req.description : undefined;
|
|
100
|
-
const expectedValue = typeof req === 'object' ? req.expectedValue : undefined;
|
|
101
|
-
const expectedType = typeof req === 'object' ? req.expectedType : undefined;
|
|
102
|
-
return {
|
|
103
|
-
key,
|
|
104
|
-
value: undefined,
|
|
105
|
-
valueType: undefined,
|
|
106
|
-
storageType: 'mmkv',
|
|
107
|
-
instanceId,
|
|
108
|
-
status: 'required_missing',
|
|
109
|
-
category: 'required',
|
|
110
|
-
description,
|
|
111
|
-
expectedValue,
|
|
112
|
-
expectedType
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
setStorageKeys(missingRequiredKeys);
|
|
116
|
-
setIsLoading(false);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 2. Process each key to get value and type
|
|
121
|
-
const allStorageKeys = [];
|
|
122
|
-
allKeys.forEach(key => {
|
|
123
|
-
// Detect value and type using type detection utility
|
|
124
|
-
const {
|
|
125
|
-
value,
|
|
126
|
-
type
|
|
127
|
-
} = detectMMKVType(instance, key);
|
|
128
|
-
|
|
129
|
-
// Check if this is a required key scoped to MMKV
|
|
130
|
-
const requiredConfig = requiredStorageKeys.find(req => {
|
|
131
|
-
if (!requiredKeyAppliesTo(req, 'mmkv')) return false;
|
|
132
|
-
if (typeof req === 'string') return req === key;
|
|
133
|
-
return req.key === key;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Determine status based on validation rules
|
|
137
|
-
let status = 'optional_present';
|
|
138
|
-
if (requiredConfig) {
|
|
139
|
-
if (value === undefined) {
|
|
140
|
-
status = 'required_missing';
|
|
141
|
-
} else if (typeof requiredConfig === 'object' && requiredConfig.expectedValue !== undefined) {
|
|
142
|
-
// Value validation
|
|
143
|
-
status = String(value) === String(requiredConfig.expectedValue) ? 'required_present' : 'required_wrong_value';
|
|
144
|
-
} else if (typeof requiredConfig === 'object' && requiredConfig.expectedType !== undefined) {
|
|
145
|
-
// Type validation
|
|
146
|
-
status = isTypeMatch(type, requiredConfig.expectedType) ? 'required_present' : 'required_wrong_type';
|
|
147
|
-
} else {
|
|
148
|
-
// Key exists and is required (no specific validation)
|
|
149
|
-
status = 'required_present';
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Build StorageKeyInfo object
|
|
154
|
-
const keyInfo = {
|
|
155
|
-
key,
|
|
156
|
-
value,
|
|
157
|
-
valueType: type !== 'unknown' ? type : undefined,
|
|
158
|
-
storageType: 'mmkv',
|
|
159
|
-
instanceId,
|
|
160
|
-
status,
|
|
161
|
-
category: requiredConfig ? 'required' : 'optional',
|
|
162
|
-
lastUpdated: new Date(),
|
|
163
|
-
...(typeof requiredConfig === 'object' && requiredConfig.expectedValue !== undefined && {
|
|
164
|
-
expectedValue: requiredConfig.expectedValue
|
|
165
|
-
}),
|
|
166
|
-
...(typeof requiredConfig === 'object' && requiredConfig.expectedType !== undefined && {
|
|
167
|
-
expectedType: requiredConfig.expectedType
|
|
168
|
-
}),
|
|
169
|
-
...(typeof requiredConfig === 'object' && requiredConfig.description !== undefined && {
|
|
170
|
-
description: requiredConfig.description
|
|
171
|
-
})
|
|
172
|
-
};
|
|
173
|
-
allStorageKeys.push(keyInfo);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// 3. Add missing required keys that weren't found in storage
|
|
177
|
-
requiredStorageKeys.forEach(req => {
|
|
178
|
-
if (!requiredKeyAppliesTo(req, 'mmkv')) return;
|
|
179
|
-
const key = typeof req === 'string' ? req : req.key;
|
|
180
|
-
const exists = allStorageKeys.some(k => k.key === key);
|
|
181
|
-
if (!exists) {
|
|
182
|
-
allStorageKeys.push({
|
|
183
|
-
key,
|
|
184
|
-
value: undefined,
|
|
185
|
-
valueType: undefined,
|
|
186
|
-
storageType: 'mmkv',
|
|
187
|
-
instanceId,
|
|
188
|
-
status: 'required_missing',
|
|
189
|
-
category: 'required',
|
|
190
|
-
...(typeof req === 'object' && req.expectedValue !== undefined && {
|
|
191
|
-
expectedValue: req.expectedValue
|
|
192
|
-
}),
|
|
193
|
-
...(typeof req === 'object' && req.expectedType !== undefined && {
|
|
194
|
-
expectedType: req.expectedType
|
|
195
|
-
}),
|
|
196
|
-
...(typeof req === 'object' && req.description !== undefined && {
|
|
197
|
-
description: req.description
|
|
198
|
-
})
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
setStorageKeys(allStorageKeys);
|
|
203
|
-
} catch (err) {
|
|
204
|
-
setError(err instanceof Error ? err : new Error('Failed to fetch MMKV storage data'));
|
|
205
|
-
setStorageKeys([]);
|
|
206
|
-
} finally {
|
|
207
|
-
setIsLoading(false);
|
|
208
|
-
}
|
|
209
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
210
|
-
}, [instance, instanceId, requiredSignature]);
|
|
211
|
-
|
|
212
|
-
// Initial fetch
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
fetchStorageData();
|
|
215
|
-
}, [fetchStorageData]);
|
|
216
|
-
return {
|
|
217
|
-
storageKeys,
|
|
218
|
-
isLoading,
|
|
219
|
-
error,
|
|
220
|
-
refresh: fetchStorageData
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Hook to fetch keys from multiple MMKV instances
|
|
226
|
-
*
|
|
227
|
-
* @param instances - Array of MMKV instances with their IDs
|
|
228
|
-
* @param requiredStorageKeys - Optional array of required keys for validation
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```typescript
|
|
232
|
-
* import { MMKV } from 'react-native-mmkv';
|
|
233
|
-
* import { useMultiMMKVKeys } from '@buoy-gg/storage';
|
|
234
|
-
*
|
|
235
|
-
* const defaultStorage = new MMKV();
|
|
236
|
-
* const secureStorage = new MMKV({ id: 'secure', encryptionKey: key });
|
|
237
|
-
*
|
|
238
|
-
* function MyComponent() {
|
|
239
|
-
* const { storageKeys, isLoading, error } = useMultiMMKVKeys(
|
|
240
|
-
* [
|
|
241
|
-
* { instance: defaultStorage, id: 'mmkv.default' },
|
|
242
|
-
* { instance: secureStorage, id: 'secure' }
|
|
243
|
-
* ],
|
|
244
|
-
* ['user.token', 'app.theme']
|
|
245
|
-
* );
|
|
246
|
-
*
|
|
247
|
-
* // storageKeys will contain keys from both instances
|
|
248
|
-
* // with instanceId field to identify which instance each key belongs to
|
|
249
|
-
* }
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
export function useMultiMMKVKeys(instances, requiredStorageKeys = []) {
|
|
253
|
-
const [storageKeys, setStorageKeys] = useState([]);
|
|
254
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
255
|
-
const [error, setError] = useState(null);
|
|
256
|
-
|
|
257
|
-
// Depend on a stable content signature rather than the array identity — a
|
|
258
|
-
// fresh `requiredStorageKeys` literal each render would otherwise loop the
|
|
259
|
-
// fetch effect. Read the latest array via ref inside the fetch.
|
|
260
|
-
const requiredSignature = JSON.stringify(requiredStorageKeys);
|
|
261
|
-
const requiredRef = useRef(requiredStorageKeys);
|
|
262
|
-
requiredRef.current = requiredStorageKeys;
|
|
263
|
-
const fetchStorageData = useCallback(() => {
|
|
264
|
-
const requiredStorageKeys = requiredRef.current;
|
|
265
|
-
setIsLoading(true);
|
|
266
|
-
setError(null);
|
|
267
|
-
try {
|
|
268
|
-
const allStorageKeys = [];
|
|
269
|
-
|
|
270
|
-
// Fetch keys from each instance
|
|
271
|
-
instances.forEach(({
|
|
272
|
-
instance,
|
|
273
|
-
id
|
|
274
|
-
}) => {
|
|
275
|
-
const allKeys = instance.getAllKeys();
|
|
276
|
-
if (!allKeys || allKeys.length === 0) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
allKeys.forEach(key => {
|
|
280
|
-
const {
|
|
281
|
-
value,
|
|
282
|
-
type
|
|
283
|
-
} = detectMMKVType(instance, key);
|
|
284
|
-
const requiredConfig = requiredStorageKeys.find(req => {
|
|
285
|
-
if (!requiredKeyAppliesTo(req, 'mmkv')) return false;
|
|
286
|
-
if (typeof req === 'string') return req === key;
|
|
287
|
-
return req.key === key;
|
|
288
|
-
});
|
|
289
|
-
let status = 'optional_present';
|
|
290
|
-
if (requiredConfig) {
|
|
291
|
-
if (value === undefined) {
|
|
292
|
-
status = 'required_missing';
|
|
293
|
-
} else if (typeof requiredConfig === 'object' && requiredConfig.expectedValue !== undefined) {
|
|
294
|
-
status = String(value) === String(requiredConfig.expectedValue) ? 'required_present' : 'required_wrong_value';
|
|
295
|
-
} else if (typeof requiredConfig === 'object' && requiredConfig.expectedType !== undefined) {
|
|
296
|
-
status = isTypeMatch(type, requiredConfig.expectedType) ? 'required_present' : 'required_wrong_type';
|
|
297
|
-
} else {
|
|
298
|
-
status = 'required_present';
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const keyInfo = {
|
|
302
|
-
key,
|
|
303
|
-
value,
|
|
304
|
-
valueType: type !== 'unknown' ? type : undefined,
|
|
305
|
-
storageType: 'mmkv',
|
|
306
|
-
instanceId: id,
|
|
307
|
-
status,
|
|
308
|
-
category: requiredConfig ? 'required' : 'optional',
|
|
309
|
-
lastUpdated: new Date(),
|
|
310
|
-
...(typeof requiredConfig === 'object' && requiredConfig.expectedValue !== undefined && {
|
|
311
|
-
expectedValue: requiredConfig.expectedValue
|
|
312
|
-
}),
|
|
313
|
-
...(typeof requiredConfig === 'object' && requiredConfig.expectedType !== undefined && {
|
|
314
|
-
expectedType: requiredConfig.expectedType
|
|
315
|
-
}),
|
|
316
|
-
...(typeof requiredConfig === 'object' && requiredConfig.description !== undefined && {
|
|
317
|
-
description: requiredConfig.description
|
|
318
|
-
})
|
|
319
|
-
};
|
|
320
|
-
allStorageKeys.push(keyInfo);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// Add missing required keys scoped to MMKV
|
|
325
|
-
requiredStorageKeys.forEach(req => {
|
|
326
|
-
if (!requiredKeyAppliesTo(req, 'mmkv')) return;
|
|
327
|
-
const key = typeof req === 'string' ? req : req.key;
|
|
328
|
-
const exists = allStorageKeys.some(k => k.key === key);
|
|
329
|
-
if (!exists) {
|
|
330
|
-
// Add missing key for first instance (or all instances?)
|
|
331
|
-
// For now, add to first instance
|
|
332
|
-
const firstInstanceId = instances[0]?.id || 'mmkv.default';
|
|
333
|
-
allStorageKeys.push({
|
|
334
|
-
key,
|
|
335
|
-
value: undefined,
|
|
336
|
-
valueType: undefined,
|
|
337
|
-
storageType: 'mmkv',
|
|
338
|
-
instanceId: firstInstanceId,
|
|
339
|
-
status: 'required_missing',
|
|
340
|
-
category: 'required',
|
|
341
|
-
...(typeof req === 'object' && req.expectedValue !== undefined && {
|
|
342
|
-
expectedValue: req.expectedValue
|
|
343
|
-
}),
|
|
344
|
-
...(typeof req === 'object' && req.expectedType !== undefined && {
|
|
345
|
-
expectedType: req.expectedType
|
|
346
|
-
}),
|
|
347
|
-
...(typeof req === 'object' && req.description !== undefined && {
|
|
348
|
-
description: req.description
|
|
349
|
-
})
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
setStorageKeys(allStorageKeys);
|
|
354
|
-
} catch (err) {
|
|
355
|
-
setError(err instanceof Error ? err : new Error('Failed to fetch multi-MMKV storage data'));
|
|
356
|
-
setStorageKeys([]);
|
|
357
|
-
} finally {
|
|
358
|
-
setIsLoading(false);
|
|
359
|
-
}
|
|
360
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
361
|
-
}, [instances, requiredSignature]);
|
|
362
|
-
useEffect(() => {
|
|
363
|
-
fetchStorageData();
|
|
364
|
-
}, [fetchStorageData]);
|
|
365
|
-
return {
|
|
366
|
-
storageKeys,
|
|
367
|
-
isLoading,
|
|
368
|
-
error,
|
|
369
|
-
refresh: fetchStorageData
|
|
370
|
-
};
|
|
371
|
-
}
|
|
1
|
+
"use strict";import{useState as x,useEffect as j,useCallback as K,useRef as S}from"react";import{requiredKeyAppliesTo as T}from"../utils/requiredStorageKeyScope";import{detectMMKVType as E,isTypeMatch as M}from"../utils/mmkvTypeDetection";export function useMMKVKeys(p,c,m=[]){const[v,f]=x([]);const[V,a]=x(true);const[_,b]=x(null);const h=JSON.stringify(m);const y=S(m);y.current=m;const l=K(()=>{const i=y.current;a(true);b(null);try{if(!p){f([]);a(false);return}const r=p.getAllKeys();if(!r||r.length===0){const t=i.filter(e=>T(e,"mmkv")).map(e=>{const d=typeof e==="string"?e:e.key;const n=typeof e==="object"?e.description:void 0;const o=typeof e==="object"?e.expectedValue:void 0;const u=typeof e==="object"?e.expectedType:void 0;return{key:d,value:void 0,valueType:void 0,storageType:"mmkv",instanceId:c,status:"required_missing",category:"required",description:n,expectedValue:o,expectedType:u}});f(t);a(false);return}const s=[];r.forEach(t=>{const{value:e,type:d}=E(p,t);const n=i.find(g=>{if(!T(g,"mmkv"))return false;if(typeof g==="string")return g===t;return g.key===t});let o="optional_present";if(n){if(e===void 0){o="required_missing"}else if(typeof n==="object"&&n.expectedValue!==void 0){o=String(e)===String(n.expectedValue)?"required_present":"required_wrong_value"}else if(typeof n==="object"&&n.expectedType!==void 0){o=M(d,n.expectedType)?"required_present":"required_wrong_type"}else{o="required_present"}}const u={key:t,value:e,valueType:d!=="unknown"?d:void 0,storageType:"mmkv",instanceId:c,status:o,category:n?"required":"optional",lastUpdated:new Date,...typeof n==="object"&&n.expectedValue!==void 0&&{expectedValue:n.expectedValue},...typeof n==="object"&&n.expectedType!==void 0&&{expectedType:n.expectedType},...typeof n==="object"&&n.description!==void 0&&{description:n.description}};s.push(u)});i.forEach(t=>{if(!T(t,"mmkv"))return;const e=typeof t==="string"?t:t.key;const d=s.some(n=>n.key===e);if(!d){s.push({key:e,value:void 0,valueType:void 0,storageType:"mmkv",instanceId:c,status:"required_missing",category:"required",...typeof t==="object"&&t.expectedValue!==void 0&&{expectedValue:t.expectedValue},...typeof t==="object"&&t.expectedType!==void 0&&{expectedType:t.expectedType},...typeof t==="object"&&t.description!==void 0&&{description:t.description}})}});f(s)}catch(r){b(r instanceof Error?r:new Error("Failed to fetch MMKV storage data"));f([])}finally{a(false)}},[p,c,h]);j(()=>{l()},[l]);return{storageKeys:v,isLoading:V,error:_,refresh:l}}export function useMultiMMKVKeys(p,c=[]){const[m,v]=x([]);const[f,V]=x(true);const[a,_]=x(null);const b=JSON.stringify(c);const h=S(c);h.current=c;const y=K(()=>{const l=h.current;V(true);_(null);try{const i=[];p.forEach(({instance:r,id:s})=>{const t=r.getAllKeys();if(!t||t.length===0){return}t.forEach(e=>{const{value:d,type:n}=E(r,e);const o=l.find(k=>{if(!T(k,"mmkv"))return false;if(typeof k==="string")return k===e;return k.key===e});let u="optional_present";if(o){if(d===void 0){u="required_missing"}else if(typeof o==="object"&&o.expectedValue!==void 0){u=String(d)===String(o.expectedValue)?"required_present":"required_wrong_value"}else if(typeof o==="object"&&o.expectedType!==void 0){u=M(n,o.expectedType)?"required_present":"required_wrong_type"}else{u="required_present"}}const g={key:e,value:d,valueType:n!=="unknown"?n:void 0,storageType:"mmkv",instanceId:s,status:u,category:o?"required":"optional",lastUpdated:new Date,...typeof o==="object"&&o.expectedValue!==void 0&&{expectedValue:o.expectedValue},...typeof o==="object"&&o.expectedType!==void 0&&{expectedType:o.expectedType},...typeof o==="object"&&o.description!==void 0&&{description:o.description}};i.push(g)})});l.forEach(r=>{if(!T(r,"mmkv"))return;const s=typeof r==="string"?r:r.key;const t=i.some(e=>e.key===s);if(!t){const e=p[0]?.id||"mmkv.default";i.push({key:s,value:void 0,valueType:void 0,storageType:"mmkv",instanceId:e,status:"required_missing",category:"required",...typeof r==="object"&&r.expectedValue!==void 0&&{expectedValue:r.expectedValue},...typeof r==="object"&&r.expectedType!==void 0&&{expectedType:r.expectedType},...typeof r==="object"&&r.description!==void 0&&{description:r.description}})}});v(i)}catch(i){_(i instanceof Error?i:new Error("Failed to fetch multi-MMKV storage data"));v([])}finally{V(false)}},[p,b]);j(()=>{y()},[y]);return{storageKeys:m,isLoading:f,error:a,refresh:y}}
|