@buoy-gg/storage 1.7.2

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.
Files changed (187) hide show
  1. package/README.md +607 -0
  2. package/lib/commonjs/index.js +34 -0
  3. package/lib/commonjs/package.json +1 -0
  4. package/lib/commonjs/preset.js +94 -0
  5. package/lib/commonjs/storage/components/DiffViewer/DiffOptionsPanel.js +356 -0
  6. package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +29 -0
  7. package/lib/commonjs/storage/components/DiffViewer/components/DiffSummary.js +121 -0
  8. package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +419 -0
  9. package/lib/commonjs/storage/components/DiffViewer/themes/diffThemes.js +122 -0
  10. package/lib/commonjs/storage/components/GameUIStorageBrowser.js +924 -0
  11. package/lib/commonjs/storage/components/GameUIStorageStats.js +746 -0
  12. package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +257 -0
  13. package/lib/commonjs/storage/components/MMKVInstanceSelector.js +418 -0
  14. package/lib/commonjs/storage/components/SelectionActionBar.js +224 -0
  15. package/lib/commonjs/storage/components/StorageActionButtons.js +239 -0
  16. package/lib/commonjs/storage/components/StorageActions.js +192 -0
  17. package/lib/commonjs/storage/components/StorageBrowserMode.js +31 -0
  18. package/lib/commonjs/storage/components/StorageEventDetailContent.js +1025 -0
  19. package/lib/commonjs/storage/components/StorageEventFilterView.js +141 -0
  20. package/lib/commonjs/storage/components/StorageEventListener.js +357 -0
  21. package/lib/commonjs/storage/components/StorageEventsSection.js +24 -0
  22. package/lib/commonjs/storage/components/StorageFilterCards.js +345 -0
  23. package/lib/commonjs/storage/components/StorageFilterViewV2.js +42 -0
  24. package/lib/commonjs/storage/components/StorageKeyCard.js +516 -0
  25. package/lib/commonjs/storage/components/StorageKeyRow.js +356 -0
  26. package/lib/commonjs/storage/components/StorageKeySection.js +105 -0
  27. package/lib/commonjs/storage/components/StorageKeyStats.js +344 -0
  28. package/lib/commonjs/storage/components/StorageModalWithTabs.js +871 -0
  29. package/lib/commonjs/storage/components/StorageSection.js +43 -0
  30. package/lib/commonjs/storage/hooks/useAsyncStorageKeys.js +126 -0
  31. package/lib/commonjs/storage/hooks/useMMKVInstances.js +221 -0
  32. package/lib/commonjs/storage/hooks/useMMKVKeys.js +362 -0
  33. package/lib/commonjs/storage/hooks/useTickEverySecond.js +21 -0
  34. package/lib/commonjs/storage/index.js +148 -0
  35. package/lib/commonjs/storage/types.js +5 -0
  36. package/lib/commonjs/storage/utils/AsyncStorageListener.js +510 -0
  37. package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +202 -0
  38. package/lib/commonjs/storage/utils/MMKVListener.js +380 -0
  39. package/lib/commonjs/storage/utils/clearAllStorage.js +47 -0
  40. package/lib/commonjs/storage/utils/index.js +180 -0
  41. package/lib/commonjs/storage/utils/lineDiff.js +363 -0
  42. package/lib/commonjs/storage/utils/mmkvAvailability.js +62 -0
  43. package/lib/commonjs/storage/utils/mmkvTypeDetection.js +139 -0
  44. package/lib/commonjs/storage/utils/objectDiff.js +157 -0
  45. package/lib/commonjs/storage/utils/safeAsyncStorage.js +140 -0
  46. package/lib/commonjs/storage/utils/storageActionHelpers.js +46 -0
  47. package/lib/commonjs/storage/utils/storageQueryUtils.js +35 -0
  48. package/lib/commonjs/storage/utils/valueType.js +18 -0
  49. package/lib/module/index.js +7 -0
  50. package/lib/module/preset.js +89 -0
  51. package/lib/module/storage/components/DiffViewer/DiffOptionsPanel.js +352 -0
  52. package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +25 -0
  53. package/lib/module/storage/components/DiffViewer/components/DiffSummary.js +117 -0
  54. package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +415 -0
  55. package/lib/module/storage/components/DiffViewer/themes/diffThemes.js +118 -0
  56. package/lib/module/storage/components/GameUIStorageBrowser.js +922 -0
  57. package/lib/module/storage/components/GameUIStorageStats.js +742 -0
  58. package/lib/module/storage/components/MMKVInstanceInfoPanel.js +253 -0
  59. package/lib/module/storage/components/MMKVInstanceSelector.js +414 -0
  60. package/lib/module/storage/components/SelectionActionBar.js +221 -0
  61. package/lib/module/storage/components/StorageActionButtons.js +236 -0
  62. package/lib/module/storage/components/StorageActions.js +189 -0
  63. package/lib/module/storage/components/StorageBrowserMode.js +27 -0
  64. package/lib/module/storage/components/StorageEventDetailContent.js +1020 -0
  65. package/lib/module/storage/components/StorageEventFilterView.js +137 -0
  66. package/lib/module/storage/components/StorageEventListener.js +354 -0
  67. package/lib/module/storage/components/StorageEventsSection.js +20 -0
  68. package/lib/module/storage/components/StorageFilterCards.js +341 -0
  69. package/lib/module/storage/components/StorageFilterViewV2.js +38 -0
  70. package/lib/module/storage/components/StorageKeyCard.js +513 -0
  71. package/lib/module/storage/components/StorageKeyRow.js +353 -0
  72. package/lib/module/storage/components/StorageKeySection.js +101 -0
  73. package/lib/module/storage/components/StorageKeyStats.js +340 -0
  74. package/lib/module/storage/components/StorageModalWithTabs.js +867 -0
  75. package/lib/module/storage/components/StorageSection.js +40 -0
  76. package/lib/module/storage/hooks/useAsyncStorageKeys.js +121 -0
  77. package/lib/module/storage/hooks/useMMKVInstances.js +216 -0
  78. package/lib/module/storage/hooks/useMMKVKeys.js +359 -0
  79. package/lib/module/storage/hooks/useTickEverySecond.js +18 -0
  80. package/lib/module/storage/index.js +25 -0
  81. package/lib/module/storage/types.js +3 -0
  82. package/lib/module/storage/utils/AsyncStorageListener.js +500 -0
  83. package/lib/module/storage/utils/MMKVInstanceRegistry.js +196 -0
  84. package/lib/module/storage/utils/MMKVListener.js +367 -0
  85. package/lib/module/storage/utils/clearAllStorage.js +42 -0
  86. package/lib/module/storage/utils/index.js +22 -0
  87. package/lib/module/storage/utils/lineDiff.js +359 -0
  88. package/lib/module/storage/utils/mmkvAvailability.js +56 -0
  89. package/lib/module/storage/utils/mmkvTypeDetection.js +133 -0
  90. package/lib/module/storage/utils/objectDiff.js +153 -0
  91. package/lib/module/storage/utils/safeAsyncStorage.js +134 -0
  92. package/lib/module/storage/utils/storageActionHelpers.js +42 -0
  93. package/lib/module/storage/utils/storageQueryUtils.js +30 -0
  94. package/lib/module/storage/utils/valueType.js +14 -0
  95. package/lib/typescript/index.d.ts +3 -0
  96. package/lib/typescript/index.d.ts.map +1 -0
  97. package/lib/typescript/preset.d.ts +90 -0
  98. package/lib/typescript/preset.d.ts.map +1 -0
  99. package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts +18 -0
  100. package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts.map +1 -0
  101. package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts +7 -0
  102. package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +1 -0
  103. package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts +12 -0
  104. package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts.map +1 -0
  105. package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts +13 -0
  106. package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +1 -0
  107. package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts +64 -0
  108. package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts.map +1 -0
  109. package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts +16 -0
  110. package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +1 -0
  111. package/lib/typescript/storage/components/GameUIStorageStats.d.ts +7 -0
  112. package/lib/typescript/storage/components/GameUIStorageStats.d.ts.map +1 -0
  113. package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts +42 -0
  114. package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts.map +1 -0
  115. package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts +35 -0
  116. package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts.map +1 -0
  117. package/lib/typescript/storage/components/SelectionActionBar.d.ts +21 -0
  118. package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +1 -0
  119. package/lib/typescript/storage/components/StorageActionButtons.d.ts +21 -0
  120. package/lib/typescript/storage/components/StorageActionButtons.d.ts.map +1 -0
  121. package/lib/typescript/storage/components/StorageActions.d.ts +10 -0
  122. package/lib/typescript/storage/components/StorageActions.d.ts.map +1 -0
  123. package/lib/typescript/storage/components/StorageBrowserMode.d.ts +18 -0
  124. package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +1 -0
  125. package/lib/typescript/storage/components/StorageEventDetailContent.d.ts +40 -0
  126. package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +1 -0
  127. package/lib/typescript/storage/components/StorageEventFilterView.d.ts +11 -0
  128. package/lib/typescript/storage/components/StorageEventFilterView.d.ts.map +1 -0
  129. package/lib/typescript/storage/components/StorageEventListener.d.ts +6 -0
  130. package/lib/typescript/storage/components/StorageEventListener.d.ts.map +1 -0
  131. package/lib/typescript/storage/components/StorageEventsSection.d.ts +7 -0
  132. package/lib/typescript/storage/components/StorageEventsSection.d.ts.map +1 -0
  133. package/lib/typescript/storage/components/StorageFilterCards.d.ts +36 -0
  134. package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +1 -0
  135. package/lib/typescript/storage/components/StorageFilterViewV2.d.ts +9 -0
  136. package/lib/typescript/storage/components/StorageFilterViewV2.d.ts.map +1 -0
  137. package/lib/typescript/storage/components/StorageKeyCard.d.ts +17 -0
  138. package/lib/typescript/storage/components/StorageKeyCard.d.ts.map +1 -0
  139. package/lib/typescript/storage/components/StorageKeyRow.d.ts +15 -0
  140. package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +1 -0
  141. package/lib/typescript/storage/components/StorageKeySection.d.ts +25 -0
  142. package/lib/typescript/storage/components/StorageKeySection.d.ts.map +1 -0
  143. package/lib/typescript/storage/components/StorageKeyStats.d.ts +15 -0
  144. package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +1 -0
  145. package/lib/typescript/storage/components/StorageModalWithTabs.d.ts +13 -0
  146. package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +1 -0
  147. package/lib/typescript/storage/components/StorageSection.d.ts +10 -0
  148. package/lib/typescript/storage/components/StorageSection.d.ts.map +1 -0
  149. package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts +10 -0
  150. package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts.map +1 -0
  151. package/lib/typescript/storage/hooks/useMMKVInstances.d.ts +114 -0
  152. package/lib/typescript/storage/hooks/useMMKVInstances.d.ts.map +1 -0
  153. package/lib/typescript/storage/hooks/useMMKVKeys.d.ts +94 -0
  154. package/lib/typescript/storage/hooks/useMMKVKeys.d.ts.map +1 -0
  155. package/lib/typescript/storage/hooks/useTickEverySecond.d.ts +6 -0
  156. package/lib/typescript/storage/hooks/useTickEverySecond.d.ts.map +1 -0
  157. package/lib/typescript/storage/index.d.ts +15 -0
  158. package/lib/typescript/storage/index.d.ts.map +1 -0
  159. package/lib/typescript/storage/types.d.ts +41 -0
  160. package/lib/typescript/storage/types.d.ts.map +1 -0
  161. package/lib/typescript/storage/utils/AsyncStorageListener.d.ts +195 -0
  162. package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +1 -0
  163. package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts +224 -0
  164. package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +1 -0
  165. package/lib/typescript/storage/utils/MMKVListener.d.ts +218 -0
  166. package/lib/typescript/storage/utils/MMKVListener.d.ts.map +1 -0
  167. package/lib/typescript/storage/utils/clearAllStorage.d.ts +11 -0
  168. package/lib/typescript/storage/utils/clearAllStorage.d.ts.map +1 -0
  169. package/lib/typescript/storage/utils/index.d.ts +8 -0
  170. package/lib/typescript/storage/utils/index.d.ts.map +1 -0
  171. package/lib/typescript/storage/utils/lineDiff.d.ts +34 -0
  172. package/lib/typescript/storage/utils/lineDiff.d.ts.map +1 -0
  173. package/lib/typescript/storage/utils/mmkvAvailability.d.ts +23 -0
  174. package/lib/typescript/storage/utils/mmkvAvailability.d.ts.map +1 -0
  175. package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts +71 -0
  176. package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts.map +1 -0
  177. package/lib/typescript/storage/utils/objectDiff.d.ts +35 -0
  178. package/lib/typescript/storage/utils/objectDiff.d.ts.map +1 -0
  179. package/lib/typescript/storage/utils/safeAsyncStorage.d.ts +56 -0
  180. package/lib/typescript/storage/utils/safeAsyncStorage.d.ts.map +1 -0
  181. package/lib/typescript/storage/utils/storageActionHelpers.d.ts +5 -0
  182. package/lib/typescript/storage/utils/storageActionHelpers.d.ts.map +1 -0
  183. package/lib/typescript/storage/utils/storageQueryUtils.d.ts +6 -0
  184. package/lib/typescript/storage/utils/storageQueryUtils.d.ts.map +1 -0
  185. package/lib/typescript/storage/utils/valueType.d.ts +3 -0
  186. package/lib/typescript/storage/utils/valueType.d.ts.map +1 -0
  187. package/package.json +68 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StorageSection = StorageSection;
7
+ var _sharedUi = require("@buoy-gg/shared-ui");
8
+ var _useAsyncStorageKeys = require("../hooks/useAsyncStorageKeys");
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ /**
11
+ * Storage section component for the dev tools console.
12
+ * Shows storage statistics and provides access to storage browser.
13
+ */
14
+ function StorageSection({
15
+ onPress
16
+ }) {
17
+ const {
18
+ storageKeys
19
+ } = (0, _useAsyncStorageKeys.useAsyncStorageKeys)();
20
+
21
+ // Filter out dev tool keys for the count
22
+ const appKeys = storageKeys.filter(k => !(0, _sharedUi.isDevToolsStorageKey)(k.key));
23
+ const asyncCount = appKeys.length;
24
+ const total = asyncCount;
25
+ const getStorageSubtitle = () => {
26
+ if (total === 0) {
27
+ return "Empty";
28
+ }
29
+
30
+ // For now, only AsyncStorage is supported
31
+ return `${asyncCount} Async`;
32
+ };
33
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.CyberpunkSectionButton, {
34
+ id: "storage",
35
+ title: "STORAGE",
36
+ subtitle: getStorageSubtitle(),
37
+ icon: _sharedUi.HardDrive,
38
+ iconColor: "#00FF88",
39
+ iconBackgroundColor: "rgba(0, 255, 136, 0.1)",
40
+ onPress: onPress,
41
+ index: 2
42
+ });
43
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAsyncStorageKeys = useAsyncStorageKeys;
7
+ var _react = require("react");
8
+ var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function useAsyncStorageKeys(requiredStorageKeys = []) {
11
+ // State management
12
+ const [storageKeys, setStorageKeys] = (0, _react.useState)([]);
13
+ const [isLoading, setIsLoading] = (0, _react.useState)(true);
14
+ const [error, setError] = (0, _react.useState)(null);
15
+
16
+ // Fetch all keys and values from AsyncStorage
17
+ const fetchStorageData = (0, _react.useCallback)(async () => {
18
+ setIsLoading(true);
19
+ setError(null);
20
+ try {
21
+ // 1. Get all keys from AsyncStorage
22
+ const allKeys = await _asyncStorage.default.getAllKeys();
23
+ if (!allKeys || allKeys.length === 0) {
24
+ setStorageKeys([]);
25
+ setIsLoading(false);
26
+ return;
27
+ }
28
+
29
+ // 2. Get all values using multiGet
30
+ const allKeyValuePairs = await _asyncStorage.default.multiGet(allKeys);
31
+
32
+ // 3. Process keys into StorageKeyInfo format
33
+ const allStorageKeys = [];
34
+ allKeyValuePairs.forEach(([key, value]) => {
35
+ // Parse value
36
+ let parsedValue = value;
37
+ if (value) {
38
+ try {
39
+ parsedValue = JSON.parse(value);
40
+ } catch {
41
+ parsedValue = value; // Keep as string if not JSON
42
+ }
43
+ }
44
+
45
+ // Check if this is a required key
46
+ const requiredConfig = requiredStorageKeys.find(req => {
47
+ if (typeof req === 'string') return req === key;
48
+ return req.key === key;
49
+ });
50
+
51
+ // Determine status
52
+ let status = 'optional_present';
53
+ if (requiredConfig) {
54
+ if (parsedValue === undefined || parsedValue === null) {
55
+ status = 'required_missing';
56
+ } else if (typeof requiredConfig === 'object' && 'expectedValue' in requiredConfig) {
57
+ status = parsedValue === requiredConfig.expectedValue ? 'required_present' : 'required_wrong_value';
58
+ } else if (typeof requiredConfig === 'object' && 'expectedType' in requiredConfig) {
59
+ const actualType = parsedValue === null ? 'null' : typeof parsedValue;
60
+ status = actualType.toLowerCase() === requiredConfig.expectedType.toLowerCase() ? 'required_present' : 'required_wrong_type';
61
+ } else {
62
+ status = 'required_present';
63
+ }
64
+ }
65
+ const keyInfo = {
66
+ key,
67
+ value: parsedValue,
68
+ storageType: 'async',
69
+ status,
70
+ category: requiredConfig ? 'required' : 'optional',
71
+ ...(typeof requiredConfig === 'object' && 'expectedValue' in requiredConfig && {
72
+ expectedValue: requiredConfig.expectedValue
73
+ }),
74
+ ...(typeof requiredConfig === 'object' && 'expectedType' in requiredConfig && {
75
+ expectedType: requiredConfig.expectedType
76
+ }),
77
+ ...(typeof requiredConfig === 'object' && 'description' in requiredConfig && {
78
+ description: requiredConfig.description
79
+ })
80
+ };
81
+ allStorageKeys.push(keyInfo);
82
+ });
83
+
84
+ // 4. Add missing required keys
85
+ requiredStorageKeys.forEach(req => {
86
+ const key = typeof req === 'string' ? req : req.key;
87
+ const exists = allStorageKeys.some(k => k.key === key);
88
+ if (!exists) {
89
+ allStorageKeys.push({
90
+ key,
91
+ value: undefined,
92
+ storageType: 'async',
93
+ status: 'required_missing',
94
+ category: 'required',
95
+ ...(typeof req === 'object' && 'expectedValue' in req && {
96
+ expectedValue: req.expectedValue
97
+ }),
98
+ ...(typeof req === 'object' && 'expectedType' in req && {
99
+ expectedType: req.expectedType
100
+ }),
101
+ ...(typeof req === 'object' && 'description' in req && {
102
+ description: req.description
103
+ })
104
+ });
105
+ }
106
+ });
107
+ setStorageKeys(allStorageKeys);
108
+ } catch (err) {
109
+ setError(err instanceof Error ? err : new Error('Failed to fetch storage data'));
110
+ setStorageKeys([]);
111
+ } finally {
112
+ setIsLoading(false);
113
+ }
114
+ }, [requiredStorageKeys]);
115
+
116
+ // Initial fetch
117
+ (0, _react.useEffect)(() => {
118
+ fetchStorageData();
119
+ }, [fetchStorageData]);
120
+ return {
121
+ storageKeys,
122
+ isLoading,
123
+ error,
124
+ refresh: fetchStorageData
125
+ };
126
+ }
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMMKVInstance = useMMKVInstance;
7
+ exports.useMMKVInstanceExists = useMMKVInstanceExists;
8
+ exports.useMMKVInstances = useMMKVInstances;
9
+ var _react = require("react");
10
+ var _mmkvAvailability = require("../utils/mmkvAvailability");
11
+ /**
12
+ * useMMKVInstances Hook
13
+ *
14
+ * React hook to monitor all registered MMKV instances and their metadata.
15
+ * Works with MMKVInstanceRegistry to provide UI components with instance information.
16
+ *
17
+ * This hook enables:
18
+ * - Multi-instance dropdown/selector UI
19
+ * - Instance metadata display (encrypted, readOnly, key count)
20
+ * - Dynamic updates when instances are added/removed
21
+ *
22
+ * @see MMKVInstanceRegistry.ts for instance registration
23
+ */
24
+
25
+ // Conditionally import registry
26
+ let mmkvInstanceRegistry;
27
+ if ((0, _mmkvAvailability.isMMKVAvailable)()) {
28
+ const registry = require('../utils/MMKVInstanceRegistry');
29
+ mmkvInstanceRegistry = registry.mmkvInstanceRegistry;
30
+ }
31
+
32
+ /**
33
+ * Metadata about an MMKV instance with additional runtime information
34
+ */
35
+
36
+ /**
37
+ * Hook to monitor all registered MMKV instances
38
+ *
39
+ * @param autoRefresh - If true, refreshes every 1 second to detect new instances
40
+ *
41
+ * @returns Object containing instances array, count, and refresh function
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { useMMKVInstances } from '@buoy-gg/storage';
46
+ *
47
+ * function MMKVInstanceSelector() {
48
+ * const { instances, instanceCount, refresh } = useMMKVInstances();
49
+ *
50
+ * return (
51
+ * <View>
52
+ * <Text>Found {instanceCount} MMKV instances</Text>
53
+ * {instances.map(inst => (
54
+ * <TouchableOpacity key={inst.id} onPress={() => selectInstance(inst)}>
55
+ * <Text>{inst.id}</Text>
56
+ * <Text>{inst.keyCount} keys</Text>
57
+ * {inst.encrypted && <Text>🔒 Encrypted</Text>}
58
+ * {inst.readOnly && <Text>👁️ Read-only</Text>}
59
+ * </TouchableOpacity>
60
+ * ))}
61
+ * <Button onPress={refresh}>Refresh</Button>
62
+ * </View>
63
+ * );
64
+ * }
65
+ * ```
66
+ */
67
+ function useMMKVInstances(autoRefresh = false) {
68
+ const [instances, setInstances] = (0, _react.useState)([]);
69
+ const [isLoading, setIsLoading] = (0, _react.useState)(true);
70
+
71
+ // Fetch all instances and their metadata
72
+ const fetchInstances = () => {
73
+ setIsLoading(true);
74
+ try {
75
+ // Guard: Check if MMKV is available
76
+ if (!(0, _mmkvAvailability.isMMKVAvailable)() || !mmkvInstanceRegistry) {
77
+ setInstances([]);
78
+ setIsLoading(false);
79
+ return; // Silently return empty when MMKV not available
80
+ }
81
+ const allInstances = mmkvInstanceRegistry.getAll();
82
+
83
+ // Enhance with metadata
84
+ const instancesWithMetadata = allInstances.map(instanceInfo => {
85
+ const {
86
+ instance,
87
+ id,
88
+ encrypted,
89
+ readOnly
90
+ } = instanceInfo;
91
+
92
+ // Get key count
93
+ const keys = instance.getAllKeys();
94
+ const keyCount = keys?.length || 0;
95
+
96
+ // Get size if available (MMKV might not expose this directly)
97
+ // For now, we don't have a direct way to get size
98
+ const size = undefined;
99
+ return {
100
+ id,
101
+ instance,
102
+ encrypted,
103
+ readOnly,
104
+ keyCount,
105
+ size
106
+ };
107
+ });
108
+ setInstances(instancesWithMetadata);
109
+ } catch (error) {
110
+ setInstances([]);
111
+ } finally {
112
+ setIsLoading(false);
113
+ }
114
+ };
115
+
116
+ // Initial fetch
117
+ (0, _react.useEffect)(() => {
118
+ fetchInstances();
119
+ }, []);
120
+
121
+ // Auto-refresh if enabled
122
+ (0, _react.useEffect)(() => {
123
+ if (!autoRefresh) return;
124
+ const interval = setInterval(() => {
125
+ fetchInstances();
126
+ }, 1000); // Refresh every second
127
+
128
+ return () => clearInterval(interval);
129
+ }, [autoRefresh]);
130
+ return {
131
+ instances,
132
+ instanceCount: instances.length,
133
+ isLoading,
134
+ refresh: fetchInstances
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Hook to monitor a single MMKV instance by ID
140
+ *
141
+ * @param instanceId - ID of the instance to monitor
142
+ *
143
+ * @returns Instance metadata or null if not found
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * function MMKVInstanceDetail({ instanceId }: { instanceId: string }) {
148
+ * const instance = useMMKVInstance(instanceId);
149
+ *
150
+ * if (!instance) {
151
+ * return <Text>Instance not found</Text>;
152
+ * }
153
+ *
154
+ * return (
155
+ * <View>
156
+ * <Text>ID: {instance.id}</Text>
157
+ * <Text>Keys: {instance.keyCount}</Text>
158
+ * <Text>Encrypted: {instance.encrypted ? 'Yes' : 'No'}</Text>
159
+ * <Text>Read-only: {instance.readOnly ? 'Yes' : 'No'}</Text>
160
+ * </View>
161
+ * );
162
+ * }
163
+ * ```
164
+ */
165
+ function useMMKVInstance(instanceId) {
166
+ const [instance, setInstance] = (0, _react.useState)(null);
167
+ (0, _react.useEffect)(() => {
168
+ // Guard: Check if MMKV is available
169
+ if (!(0, _mmkvAvailability.isMMKVAvailable)() || !mmkvInstanceRegistry) {
170
+ setInstance(null);
171
+ return;
172
+ }
173
+ const instanceInfo = mmkvInstanceRegistry.get(instanceId);
174
+ if (!instanceInfo) {
175
+ setInstance(null);
176
+ return;
177
+ }
178
+ const keys = instanceInfo.instance.getAllKeys();
179
+ const keyCount = keys?.length || 0;
180
+ setInstance({
181
+ ...instanceInfo,
182
+ keyCount,
183
+ size: undefined
184
+ });
185
+ }, [instanceId]);
186
+ return instance;
187
+ }
188
+
189
+ /**
190
+ * Hook to check if a specific instance ID is registered
191
+ *
192
+ * @param instanceId - ID to check
193
+ *
194
+ * @returns True if instance is registered
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * function MMKVStatus({ instanceId }: { instanceId: string }) {
199
+ * const isRegistered = useMMKVInstanceExists(instanceId);
200
+ *
201
+ * return (
202
+ * <View>
203
+ * <Text>{instanceId}</Text>
204
+ * <Text>{isRegistered ? '✅ Registered' : '❌ Not registered'}</Text>
205
+ * </View>
206
+ * );
207
+ * }
208
+ * ```
209
+ */
210
+ function useMMKVInstanceExists(instanceId) {
211
+ const [exists, setExists] = (0, _react.useState)(false);
212
+ (0, _react.useEffect)(() => {
213
+ // Guard: Check if MMKV is available
214
+ if (!(0, _mmkvAvailability.isMMKVAvailable)() || !mmkvInstanceRegistry) {
215
+ setExists(false);
216
+ return;
217
+ }
218
+ setExists(mmkvInstanceRegistry.has(instanceId));
219
+ }, [instanceId]);
220
+ return exists;
221
+ }