@buoy-gg/storage 7.0.40 → 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.
Files changed (215) hide show
  1. package/README.md +11 -86
  2. package/lib/commonjs/index.js +1 -346
  3. package/lib/commonjs/preset.js +1 -80
  4. package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +1 -36
  5. package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -12
  6. package/lib/commonjs/storage/components/DiffViewer/themes/diffThemes.js +1 -24
  7. package/lib/commonjs/storage/components/GameUIStorageBrowser.js +3 -1258
  8. package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +1 -257
  9. package/lib/commonjs/storage/components/MMKVInstanceSelector.js +1 -418
  10. package/lib/commonjs/storage/components/SelectionActionBar.js +1 -207
  11. package/lib/commonjs/storage/components/StorageActionButtons.js +1 -241
  12. package/lib/commonjs/storage/components/StorageBrowserMode.js +1 -61
  13. package/lib/commonjs/storage/components/StorageEventActionButton.js +1 -121
  14. package/lib/commonjs/storage/components/StorageEventCard.js +1 -117
  15. package/lib/commonjs/storage/components/StorageEventDetailContent.js +1 -494
  16. package/lib/commonjs/storage/components/StorageEventFilterView.js +1 -159
  17. package/lib/commonjs/storage/components/StorageEventsSection.js +1 -24
  18. package/lib/commonjs/storage/components/StorageFilterCards.js +1 -231
  19. package/lib/commonjs/storage/components/StorageKeyCard.js +1 -520
  20. package/lib/commonjs/storage/components/StorageKeyDetailScreen.js +1 -579
  21. package/lib/commonjs/storage/components/StorageKeyRow.js +1 -559
  22. package/lib/commonjs/storage/components/StorageKeySection.js +1 -160
  23. package/lib/commonjs/storage/components/StorageKeyStats.js +1 -344
  24. package/lib/commonjs/storage/components/StorageModalWithTabs.js +1 -954
  25. package/lib/commonjs/storage/components/StorageSaveNotice.js +1 -171
  26. package/lib/commonjs/storage/components/StorageSection.js +1 -43
  27. package/lib/commonjs/storage/components/StorageTypeFilterBar.js +1 -143
  28. package/lib/commonjs/storage/hooks/useAsyncStorageKeys.js +1 -141
  29. package/lib/commonjs/storage/hooks/useMMKVInstances.js +1 -210
  30. package/lib/commonjs/storage/hooks/useMMKVKeys.js +1 -376
  31. package/lib/commonjs/storage/hooks/useSecureStoreKeys.js +1 -159
  32. package/lib/commonjs/storage/hooks/useStorageEvents.js +1 -61
  33. package/lib/commonjs/storage/stores/storageEventStore.js +1 -312
  34. package/lib/commonjs/storage/sync/storageSyncAdapter.js +1 -478
  35. package/lib/commonjs/storage/types.js +1 -5
  36. package/lib/commonjs/storage/utils/AsyncStorageListener.js +1 -691
  37. package/lib/commonjs/storage/utils/AsyncStorageListener.web.js +1 -0
  38. package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +1 -203
  39. package/lib/commonjs/storage/utils/MMKVListener.js +1 -416
  40. package/lib/commonjs/storage/utils/SecureStoreRegistry.js +1 -200
  41. package/lib/commonjs/storage/utils/asyncStorageCompat.js +1 -89
  42. package/lib/commonjs/storage/utils/browserStorageLifecycle.js +1 -0
  43. package/lib/commonjs/storage/utils/browserStorageLifecycle.web.js +1 -0
  44. package/lib/commonjs/storage/utils/clearAllStorage.js +1 -48
  45. package/lib/commonjs/storage/utils/deleteStorageKeys.js +1 -82
  46. package/lib/commonjs/storage/utils/lineDiff.js +1 -30
  47. package/lib/commonjs/storage/utils/mmkvAvailability.js +1 -62
  48. package/lib/commonjs/storage/utils/mmkvAvailability.web.js +1 -0
  49. package/lib/commonjs/storage/utils/mmkvTypeDetection.js +1 -154
  50. package/lib/commonjs/storage/utils/requiredStorageKeyScope.js +1 -17
  51. package/lib/commonjs/storage/utils/setStorageValue.js +1 -218
  52. package/lib/commonjs/storage/utils/snapshotProvider.js +1 -382
  53. package/lib/commonjs/storage/utils/storageActionHelpers.js +1 -46
  54. package/lib/commonjs/storage/utils/storageBrowserRefresh.js +1 -49
  55. package/lib/commonjs/storage/utils/storageLabels.js +1 -0
  56. package/lib/commonjs/storage/utils/storageLabels.web.js +1 -0
  57. package/lib/commonjs/storage/utils/storageOps.js +1 -53
  58. package/lib/commonjs/storage/utils/storageQueryUtils.js +1 -35
  59. package/lib/commonjs/storage/utils/storageTimeTravelUtils.js +1 -288
  60. package/lib/commonjs/storage/utils/valueType.js +1 -83
  61. package/lib/module/index.js +1 -112
  62. package/lib/module/preset.js +1 -76
  63. package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +1 -32
  64. package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -9
  65. package/lib/module/storage/components/DiffViewer/themes/diffThemes.js +1 -10
  66. package/lib/module/storage/components/GameUIStorageBrowser.js +3 -1256
  67. package/lib/module/storage/components/MMKVInstanceInfoPanel.js +1 -253
  68. package/lib/module/storage/components/MMKVInstanceSelector.js +1 -414
  69. package/lib/module/storage/components/SelectionActionBar.js +1 -204
  70. package/lib/module/storage/components/StorageActionButtons.js +1 -237
  71. package/lib/module/storage/components/StorageBrowserMode.js +1 -57
  72. package/lib/module/storage/components/StorageEventActionButton.js +1 -118
  73. package/lib/module/storage/components/StorageEventCard.js +1 -112
  74. package/lib/module/storage/components/StorageEventDetailContent.js +1 -490
  75. package/lib/module/storage/components/StorageEventFilterView.js +1 -155
  76. package/lib/module/storage/components/StorageEventsSection.js +1 -20
  77. package/lib/module/storage/components/StorageFilterCards.js +1 -227
  78. package/lib/module/storage/components/StorageKeyCard.js +1 -517
  79. package/lib/module/storage/components/StorageKeyDetailScreen.js +1 -577
  80. package/lib/module/storage/components/StorageKeyRow.js +1 -554
  81. package/lib/module/storage/components/StorageKeySection.js +1 -155
  82. package/lib/module/storage/components/StorageKeyStats.js +1 -341
  83. package/lib/module/storage/components/StorageModalWithTabs.js +1 -949
  84. package/lib/module/storage/components/StorageSaveNotice.js +1 -168
  85. package/lib/module/storage/components/StorageSection.js +1 -40
  86. package/lib/module/storage/components/StorageTypeFilterBar.js +1 -138
  87. package/lib/module/storage/hooks/useAsyncStorageKeys.js +1 -136
  88. package/lib/module/storage/hooks/useMMKVInstances.js +1 -204
  89. package/lib/module/storage/hooks/useMMKVKeys.js +1 -371
  90. package/lib/module/storage/hooks/useSecureStoreKeys.js +1 -156
  91. package/lib/module/storage/hooks/useStorageEvents.js +1 -58
  92. package/lib/module/storage/stores/storageEventStore.js +1 -301
  93. package/lib/module/storage/sync/storageSyncAdapter.js +1 -474
  94. package/lib/module/storage/types.js +1 -3
  95. package/lib/module/storage/utils/AsyncStorageListener.js +1 -679
  96. package/lib/module/storage/utils/AsyncStorageListener.web.js +1 -0
  97. package/lib/module/storage/utils/MMKVInstanceRegistry.js +1 -197
  98. package/lib/module/storage/utils/MMKVListener.js +1 -403
  99. package/lib/module/storage/utils/SecureStoreRegistry.js +1 -194
  100. package/lib/module/storage/utils/asyncStorageCompat.js +1 -81
  101. package/lib/module/storage/utils/browserStorageLifecycle.js +1 -0
  102. package/lib/module/storage/utils/browserStorageLifecycle.web.js +1 -0
  103. package/lib/module/storage/utils/clearAllStorage.js +1 -43
  104. package/lib/module/storage/utils/deleteStorageKeys.js +1 -78
  105. package/lib/module/storage/utils/lineDiff.js +1 -12
  106. package/lib/module/storage/utils/mmkvAvailability.js +1 -56
  107. package/lib/module/storage/utils/mmkvAvailability.web.js +1 -0
  108. package/lib/module/storage/utils/mmkvTypeDetection.js +1 -148
  109. package/lib/module/storage/utils/requiredStorageKeyScope.js +1 -13
  110. package/lib/module/storage/utils/setStorageValue.js +1 -209
  111. package/lib/module/storage/utils/snapshotProvider.js +1 -380
  112. package/lib/module/storage/utils/storageActionHelpers.js +1 -42
  113. package/lib/module/storage/utils/storageBrowserRefresh.js +1 -44
  114. package/lib/module/storage/utils/storageLabels.js +1 -0
  115. package/lib/module/storage/utils/storageLabels.web.js +1 -0
  116. package/lib/module/storage/utils/storageOps.js +1 -46
  117. package/lib/module/storage/utils/storageQueryUtils.js +1 -30
  118. package/lib/module/storage/utils/storageTimeTravelUtils.js +1 -281
  119. package/lib/module/storage/utils/valueType.js +1 -76
  120. package/lib/typescript/index.d.ts +1 -0
  121. package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts +0 -8
  122. package/lib/typescript/storage/components/StorageEventCard.d.ts +0 -7
  123. package/lib/typescript/storage/components/StorageKeyRow.d.ts +2 -6
  124. package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts +0 -15
  125. package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts +2 -2
  126. package/lib/typescript/storage/sync/storageSyncAdapter.d.ts +7 -13
  127. package/lib/typescript/storage/utils/AsyncStorageListener.web.d.ts +24 -0
  128. package/lib/typescript/storage/utils/browserStorageLifecycle.d.ts +3 -0
  129. package/lib/typescript/storage/utils/browserStorageLifecycle.web.d.ts +2 -0
  130. package/lib/typescript/storage/utils/mmkvAvailability.web.d.ts +4 -0
  131. package/lib/typescript/storage/utils/storageLabels.d.ts +8 -0
  132. package/lib/typescript/storage/utils/storageLabels.web.d.ts +8 -0
  133. package/lib/web/index.mjs +4 -0
  134. package/package.json +40 -14
  135. package/lib/commonjs/storage/components/DiffViewer/DiffOptionsPanel.js +0 -356
  136. package/lib/commonjs/storage/components/DiffViewer/components/DiffSummary.js +0 -122
  137. package/lib/commonjs/storage/components/StorageKeyEditorScreen.js +0 -414
  138. package/lib/commonjs/storage/components/StorageScalarKeyEditor.js +0 -61
  139. package/lib/commonjs/storage/components/StorageValueEditModal.js +0 -24
  140. package/lib/commonjs/storage/hooks/useKeyEditor.js +0 -31
  141. package/lib/commonjs/storage/hooks/useTreeDraft.js +0 -25
  142. package/lib/module/storage/components/DiffViewer/DiffOptionsPanel.js +0 -352
  143. package/lib/module/storage/components/DiffViewer/components/DiffSummary.js +0 -118
  144. package/lib/module/storage/components/StorageKeyEditorScreen.js +0 -410
  145. package/lib/module/storage/components/StorageScalarKeyEditor.js +0 -57
  146. package/lib/module/storage/components/StorageValueEditModal.js +0 -20
  147. package/lib/module/storage/hooks/useKeyEditor.js +0 -27
  148. package/lib/module/storage/hooks/useTreeDraft.js +0 -21
  149. package/lib/typescript/index.d.ts.map +0 -1
  150. package/lib/typescript/preset.d.ts.map +0 -1
  151. package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts +0 -18
  152. package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts.map +0 -1
  153. package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +0 -1
  154. package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts +0 -12
  155. package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts.map +0 -1
  156. package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +0 -1
  157. package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts.map +0 -1
  158. package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +0 -1
  159. package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts.map +0 -1
  160. package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts.map +0 -1
  161. package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +0 -1
  162. package/lib/typescript/storage/components/StorageActionButtons.d.ts.map +0 -1
  163. package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +0 -1
  164. package/lib/typescript/storage/components/StorageEventActionButton.d.ts.map +0 -1
  165. package/lib/typescript/storage/components/StorageEventCard.d.ts.map +0 -1
  166. package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +0 -1
  167. package/lib/typescript/storage/components/StorageEventFilterView.d.ts.map +0 -1
  168. package/lib/typescript/storage/components/StorageEventsSection.d.ts.map +0 -1
  169. package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +0 -1
  170. package/lib/typescript/storage/components/StorageKeyCard.d.ts.map +0 -1
  171. package/lib/typescript/storage/components/StorageKeyDetailScreen.d.ts.map +0 -1
  172. package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts +0 -42
  173. package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts.map +0 -1
  174. package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +0 -1
  175. package/lib/typescript/storage/components/StorageKeySection.d.ts.map +0 -1
  176. package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +0 -1
  177. package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +0 -1
  178. package/lib/typescript/storage/components/StorageSaveNotice.d.ts.map +0 -1
  179. package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts +0 -24
  180. package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts.map +0 -1
  181. package/lib/typescript/storage/components/StorageSection.d.ts.map +0 -1
  182. package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts.map +0 -1
  183. package/lib/typescript/storage/components/StorageValueEditModal.d.ts +0 -14
  184. package/lib/typescript/storage/components/StorageValueEditModal.d.ts.map +0 -1
  185. package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts.map +0 -1
  186. package/lib/typescript/storage/hooks/useKeyEditor.d.ts +0 -27
  187. package/lib/typescript/storage/hooks/useKeyEditor.d.ts.map +0 -1
  188. package/lib/typescript/storage/hooks/useMMKVInstances.d.ts.map +0 -1
  189. package/lib/typescript/storage/hooks/useMMKVKeys.d.ts.map +0 -1
  190. package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts.map +0 -1
  191. package/lib/typescript/storage/hooks/useStorageEvents.d.ts.map +0 -1
  192. package/lib/typescript/storage/hooks/useTreeDraft.d.ts +0 -16
  193. package/lib/typescript/storage/hooks/useTreeDraft.d.ts.map +0 -1
  194. package/lib/typescript/storage/stores/storageEventStore.d.ts.map +0 -1
  195. package/lib/typescript/storage/sync/storageSyncAdapter.d.ts.map +0 -1
  196. package/lib/typescript/storage/types.d.ts.map +0 -1
  197. package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +0 -1
  198. package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +0 -1
  199. package/lib/typescript/storage/utils/MMKVListener.d.ts.map +0 -1
  200. package/lib/typescript/storage/utils/SecureStoreRegistry.d.ts.map +0 -1
  201. package/lib/typescript/storage/utils/asyncStorageCompat.d.ts.map +0 -1
  202. package/lib/typescript/storage/utils/clearAllStorage.d.ts.map +0 -1
  203. package/lib/typescript/storage/utils/deleteStorageKeys.d.ts.map +0 -1
  204. package/lib/typescript/storage/utils/lineDiff.d.ts.map +0 -1
  205. package/lib/typescript/storage/utils/mmkvAvailability.d.ts.map +0 -1
  206. package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts.map +0 -1
  207. package/lib/typescript/storage/utils/requiredStorageKeyScope.d.ts.map +0 -1
  208. package/lib/typescript/storage/utils/setStorageValue.d.ts.map +0 -1
  209. package/lib/typescript/storage/utils/snapshotProvider.d.ts.map +0 -1
  210. package/lib/typescript/storage/utils/storageActionHelpers.d.ts.map +0 -1
  211. package/lib/typescript/storage/utils/storageBrowserRefresh.d.ts.map +0 -1
  212. package/lib/typescript/storage/utils/storageOps.d.ts.map +0 -1
  213. package/lib/typescript/storage/utils/storageQueryUtils.d.ts.map +0 -1
  214. package/lib/typescript/storage/utils/storageTimeTravelUtils.d.ts.map +0 -1
  215. package/lib/typescript/storage/utils/valueType.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.addListener=addListener;exports.default=void 0;exports.getListenerCount=getListenerCount;exports.isListening=isListening;exports.isPaused=isPaused;exports.pauseCapture=pauseCapture;exports.removeAllListeners=removeAllListeners;exports.resumeCapture=resumeCapture;exports.startListening=startListening;exports.stopListening=stopListening;var _utils=require("@buoy-gg/shared-ui/utils");const listeners=new Set;let stop;let paused=false;const ignoredKeys=new Set(["@react_buoy_storage_event_filters","@react_buoy_storage_key_filters","@react_buoy_storage_is_monitoring","REACT_QUERY_OFFLINE_CACHE"]);const ignored=e=>[...ignoredKeys].some(s=>e.startsWith(s));async function startListening(){if(stop||typeof window==="undefined")return;stop=(0,_utils.subscribeToBrowserStorage)(e=>{if(paused||e.area!=="localStorage"||e.key!==void 0&&ignored(e.key))return;const{area:s,action:n,...t}=e;if(t.prevPairs)t.prevPairs=t.prevPairs.filter(([r])=>!ignored(r));const i={action:n,data:t,timestamp:new Date};for(const r of[...listeners]){try{r(i)}catch{}}})}function stopListening(){stop?.();stop=void 0}function addListener(e){listeners.add(e);return()=>{listeners.delete(e)}}function removeAllListeners(){listeners.clear()}function isListening(){return!!stop}function getListenerCount(){return listeners.size}function pauseCapture(){paused=true}function resumeCapture(){paused=false}function isPaused(){return paused}const asyncStorageListener={startListening,stopListening,addListener,removeAllListeners,pause:pauseCapture,resume:resumeCapture,get isActive(){return isListening()},get listenerCount(){return listeners.size},get paused(){return paused}};var _default=exports.default=asyncStorageListener;
@@ -1,203 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mmkvInstanceRegistry = void 0;
7
- exports.registerMMKVInstance = registerMMKVInstance;
8
- exports.unregisterMMKVInstance = unregisterMMKVInstance;
9
- var _MMKVListener = require("./MMKVListener");
10
- /**
11
- * MMKV Instance Registry
12
- *
13
- * Centralized registry for tracking all MMKV instances in the application.
14
- * Provides a singleton pattern to manage multiple MMKV instances and their metadata.
15
- *
16
- * @module MMKVInstanceRegistry
17
- * @since 1.0.0
18
- */
19
-
20
- // Static ESM import. This was previously a dynamic `require('./MMKVListener')`
21
- // inside register/unregister "to avoid a circular dependency" — but MMKVListener
22
- // imports only ./mmkvTypeDetection, never this file, so there is no cycle. The
23
- // require() form threw `ReferenceError: require is not defined` when this source
24
- // is bundled as ESM (the desktop dashboard imports it through Vite), crashing on
25
- // StorageInline unmount. A static import behaves identically on Metro and Vite.
26
-
27
- /**
28
- * Type-safe representation of an MMKV instance.
29
- * Uses conditional typing to avoid hard dependency on react-native-mmkv.
30
- *
31
- * @public
32
- */
33
-
34
- /**
35
- * Metadata about a registered MMKV instance
36
- *
37
- * @public
38
- */
39
-
40
- /**
41
- * Configuration options for registering an MMKV instance
42
- *
43
- * @public
44
- */
45
-
46
- class MMKVInstanceRegistry {
47
- instances = new Map();
48
-
49
- /**
50
- * Register an MMKV instance for monitoring
51
- *
52
- * @param id - Unique identifier for this instance
53
- * @param instance - The MMKV instance to register
54
- * @param config - Optional configuration (e.g., encrypted flag)
55
- */
56
- register(id, instance, config) {
57
- const instanceInfo = {
58
- id,
59
- instance,
60
- encrypted: config?.encrypted ?? false,
61
- readOnly: instance.isReadOnly ?? false
62
- };
63
- this.instances.set(id, instanceInfo);
64
- }
65
-
66
- /**
67
- * Unregister an MMKV instance
68
- */
69
- unregister(id) {
70
- this.instances.delete(id);
71
- }
72
-
73
- /**
74
- * Get a specific instance by ID
75
- */
76
- get(id) {
77
- return this.instances.get(id);
78
- }
79
-
80
- /**
81
- * Get all registered instances
82
- */
83
- getAll() {
84
- return Array.from(this.instances.values());
85
- }
86
-
87
- /**
88
- * Check if an instance is registered
89
- */
90
- has(id) {
91
- return this.instances.has(id);
92
- }
93
-
94
- /**
95
- * Get count of registered instances
96
- */
97
- count() {
98
- return this.instances.size;
99
- }
100
- }
101
-
102
- // Singleton instance
103
- const mmkvInstanceRegistry = exports.mmkvInstanceRegistry = new MMKVInstanceRegistry();
104
-
105
- /**
106
- * Register an MMKV instance with React Buoy DevTools for monitoring and debugging.
107
- *
108
- * **⚠️ REQUIRED**: Manual registration is required for `react-native-mmkv` v4.
109
- * Auto-detection is not possible due to Metro bundler and ES6 module limitations.
110
- *
111
- * Call this function immediately after creating each MMKV instance you want to monitor.
112
- * The DevTools will then be able to:
113
- * - Display all keys and values
114
- * - Show real-time updates when data changes
115
- * - Allow editing values directly from the DevTools
116
- * - Track storage size and performance
117
- *
118
- * @param id - Unique identifier for this MMKV instance. Should match the `id` you used when creating the instance.
119
- * @param instance - The MMKV instance returned from `createMMKV()`
120
- * @param config - Optional configuration
121
- * @param config.encrypted - Set to `true` if this instance uses encryption (has an `encryptionKey`)
122
- *
123
- * @example
124
- * **Basic usage:**
125
- * ```typescript
126
- * import { createMMKV } from 'react-native-mmkv';
127
- * import { registerMMKVInstance } from '@buoy-gg/storage';
128
- *
129
- * // Create and register default instance
130
- * export const storage = createMMKV({ id: 'mmkv.default' });
131
- * registerMMKVInstance('mmkv.default', storage);
132
- * ```
133
- *
134
- * @example
135
- * **With encryption:**
136
- * ```typescript
137
- * import { createMMKV } from 'react-native-mmkv';
138
- * import { registerMMKVInstance } from '@buoy-gg/storage';
139
- *
140
- * // Create encrypted instance
141
- * export const secureStorage = createMMKV({
142
- * id: 'secure-storage',
143
- * encryptionKey: 'my-encryption-key'
144
- * });
145
- *
146
- * // Register with encrypted flag
147
- * registerMMKVInstance('secure-storage', secureStorage, { encrypted: true });
148
- * ```
149
- *
150
- * @example
151
- * **Multiple instances:**
152
- * ```typescript
153
- * import { createMMKV } from 'react-native-mmkv';
154
- * import { registerMMKVInstance } from '@buoy-gg/storage';
155
- *
156
- * // User preferences
157
- * export const userPrefs = createMMKV({ id: 'user-prefs' });
158
- * registerMMKVInstance('user-prefs', userPrefs);
159
- *
160
- * // Cache
161
- * export const cache = createMMKV({ id: 'cache' });
162
- * registerMMKVInstance('cache', cache);
163
- *
164
- * // Auth (encrypted)
165
- * export const auth = createMMKV({ id: 'auth', encryptionKey: 'key' });
166
- * registerMMKVInstance('auth', auth, { encrypted: true });
167
- * ```
168
- *
169
- * @public
170
- * @since 1.0.0
171
- */
172
- function registerMMKVInstance(id, instance, config) {
173
- // Register in registry
174
- mmkvInstanceRegistry.register(id, instance, config);
175
-
176
- // Add listener for real-time monitoring (CRITICAL: enables event emission)
177
- // v4: Use ONLY native listener (addOnValueChangedListener), skip method wrapping
178
- _MMKVListener.mmkvListener.addInstance(instance, id);
179
- }
180
-
181
- /**
182
- * Unregister an MMKV instance from DevTools monitoring.
183
- *
184
- * This stops the DevTools from tracking changes to this instance.
185
- * Typically not needed unless you're dynamically creating/destroying instances.
186
- *
187
- * @param id - The instance ID to unregister
188
- *
189
- * @example
190
- * ```typescript
191
- * unregisterMMKVInstance('cache');
192
- * ```
193
- *
194
- * @public
195
- * @since 1.0.0
196
- */
197
- function unregisterMMKVInstance(id) {
198
- // Remove listener first
199
- _MMKVListener.mmkvListener.removeInstance(id);
200
-
201
- // Then remove from registry
202
- mmkvInstanceRegistry.unregister(id);
203
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.mmkvInstanceRegistry=void 0;exports.registerMMKVInstance=registerMMKVInstance;exports.unregisterMMKVInstance=unregisterMMKVInstance;var _MMKVListener=require("./MMKVListener");class MMKVInstanceRegistry{instances=new Map;register(e,t,n){const r={id:e,instance:t,encrypted:n?.encrypted??false,readOnly:t.isReadOnly??false};this.instances.set(e,r)}unregister(e){this.instances.delete(e)}get(e){return this.instances.get(e)}getAll(){return Array.from(this.instances.values())}has(e){return this.instances.has(e)}count(){return this.instances.size}}const mmkvInstanceRegistry=exports.mmkvInstanceRegistry=new MMKVInstanceRegistry;function registerMMKVInstance(s,e,t){mmkvInstanceRegistry.register(s,e,t);_MMKVListener.mmkvListener.addInstance(e,s)}function unregisterMMKVInstance(s){_MMKVListener.mmkvListener.removeInstance(s);mmkvInstanceRegistry.unregister(s)}
@@ -1,416 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.removeMMKVInstance = exports.removeAllMMKVListeners = exports.removeAllMMKVInstances = exports.mmkvListener = exports.isMMKVListening = exports.isMMKVInstanceMonitored = exports.getMonitoredMMKVInstances = exports.getMMKVListenerCount = exports.getMMKVInstanceCount = exports.default = exports.addMMKVListener = exports.addMMKVInstance = void 0;
7
- var _mmkvTypeDetection = require("./mmkvTypeDetection");
8
- /**
9
- * MMKVListener - Hybrid Monitoring Strategy
10
- *
11
- * This module provides comprehensive monitoring for MMKV storage instances using
12
- * a hybrid approach that combines:
13
- *
14
- * 1. MMKV's built-in addOnValueChangedListener() - for write operations
15
- * 2. Method wrapping - for read operations and type detection
16
- *
17
- * Why Hybrid Strategy?
18
- * - MMKV listeners only fire on writes (set/delete), not reads
19
- * - MMKV listeners don't provide value type information
20
- * - Method wrapping captures ALL operations with full context
21
- * - Combining both gives complete observability
22
- *
23
- * Key Differences from AsyncStorage:
24
- * - Synchronous API (no async/await needed)
25
- * - Multi-instance support (track multiple MMKV instances)
26
- * - Native types (string, number, boolean, buffer)
27
- * - Built-in listener support (MMKV.addOnValueChangedListener)
28
- *
29
- * @see AsyncStorageListener.ts for AsyncStorage equivalent
30
- */
31
-
32
- // Use 'any' type for MMKV to avoid hard dependency on react-native-mmkv
33
-
34
- // MMKV method signatures
35
-
36
- /**
37
- * Event types for MMKV operations
38
- */
39
-
40
- /**
41
- * Instance tracking for MMKV monitoring
42
- */
43
-
44
- /**
45
- * Singleton class for monitoring MMKV operations across multiple instances
46
- *
47
- * Uses a hybrid monitoring strategy:
48
- * 1. MMKV's built-in listener API for write notifications
49
- * 2. Method wrapping for read operations and type information
50
- *
51
- * @example
52
- * ```typescript
53
- * import { MMKV } from 'react-native-mmkv';
54
- * import { mmkvListener } from './MMKVListener';
55
- *
56
- * const storage = new MMKV();
57
- *
58
- * // Start monitoring this instance
59
- * mmkvListener.addInstance(storage, 'mmkv.default');
60
- *
61
- * // Add listener for all MMKV events
62
- * const unsubscribe = mmkvListener.addListener((event) => {
63
- * console.log(`[${event.instanceId}] ${event.action}:`, event.data);
64
- * });
65
- *
66
- * // Cleanup
67
- * unsubscribe();
68
- * mmkvListener.removeInstance('mmkv.default');
69
- * ```
70
- */
71
- class MMKVListener {
72
- listeners = [];
73
- instances = new Map();
74
-
75
- // Keys to ignore to prevent dev tools from triggering self-events
76
- ignoredKeys = new Set(["@react_buoy_storage_event_filters", "@react_buoy_storage_key_filters", "@react_buoy_storage_is_monitoring", "REACT_QUERY_OFFLINE_CACHE"]);
77
-
78
- /**
79
- * Determines if a storage key should be ignored
80
- */
81
- shouldIgnoreKey(key) {
82
- if (this.ignoredKeys.has(key)) return true;
83
- for (const ignoredKey of this.ignoredKeys) {
84
- if (key.startsWith(ignoredKey)) return true;
85
- }
86
- return false;
87
- }
88
-
89
- /**
90
- * Emit an MMKV event to all registered listeners
91
- */
92
- emit(event) {
93
- if (this.listeners.length === 0) return;
94
- this.listeners.forEach(listener => {
95
- try {
96
- listener(event);
97
- } catch (error) {
98
- // Error in MMKV event listener - continuing with others
99
- }
100
- });
101
- }
102
-
103
- /**
104
- * Add an MMKV instance for monitoring
105
- *
106
- * This method sets up both native MMKV listeners and method wrapping
107
- * to provide complete observability.
108
- *
109
- * @param instance - MMKV instance to monitor
110
- * @param instanceId - Unique identifier for this instance
111
- *
112
- * @example
113
- * ```typescript
114
- * const storage = new MMKV();
115
- * mmkvListener.addInstance(storage, 'mmkv.default');
116
- *
117
- * const secureStorage = new MMKV({ id: 'secure', encryptionKey: key });
118
- * mmkvListener.addInstance(secureStorage, 'secure');
119
- * ```
120
- */
121
- addInstance(instance, instanceId) {
122
- // Check if already monitoring this instance
123
- if (this.instances.has(instanceId)) {
124
- return;
125
- }
126
-
127
- // v4 COMPATIBILITY: Use ONLY native listener (no method wrapping)
128
- // react-native-mmkv v4 instances have frozen/read-only methods that cannot be wrapped
129
- // The native listener (addOnValueChangedListener) is sufficient for monitoring writes
130
-
131
- let nativeListenerUnsubscribe;
132
-
133
- // Seed the shadow copy so the FIRST observed write already knows what it
134
- // replaced. Without this, every key's first event would claim the key never
135
- // existed even when it was carried over from a previous launch.
136
- const lastKnownValues = new Map();
137
- try {
138
- for (const key of instance.getAllKeys() ?? []) {
139
- if (this.shouldIgnoreKey(key)) continue;
140
- lastKnownValues.set(key, (0, _mmkvTypeDetection.detectMMKVType)(instance, key).value);
141
- }
142
- } catch {
143
- // Key scan unavailable — prevValue is simply absent until each key is
144
- // written once, which is strictly better than reporting a wrong value.
145
- }
146
- if (typeof instance.addOnValueChangedListener === "function") {
147
- try {
148
- nativeListenerUnsubscribe = instance.addOnValueChangedListener(key => {
149
- // Ignore dev tools keys
150
- if (this.shouldIgnoreKey(key)) return;
151
-
152
- // Detect the value type
153
- const {
154
- value,
155
- type
156
- } = (0, _mmkvTypeDetection.detectMMKVType)(instance, key);
157
-
158
- // Read the shadow copy BEFORE overwriting it — this is the value the
159
- // write replaced. `undefined` means the key did not exist.
160
- const prevValue = lastKnownValues.get(key);
161
-
162
- // Determine action: if value is undefined/unknown, it was deleted
163
- const isDelete = type === "unknown" || value === undefined;
164
- if (isDelete) {
165
- lastKnownValues.delete(key);
166
-
167
- // Key was deleted
168
- const event = {
169
- action: "delete",
170
- timestamp: new Date(),
171
- instanceId,
172
- data: {
173
- key,
174
- prevValue,
175
- success: true
176
- }
177
- };
178
- this.emit(event);
179
- } else {
180
- lastKnownValues.set(key, value);
181
-
182
- // Key was set/updated
183
- const action = type === "string" ? "set.string" : type === "number" ? "set.number" : type === "boolean" ? "set.boolean" : type === "buffer" ? "set.buffer" : "set.string"; // fallback
184
-
185
- const event = {
186
- action,
187
- timestamp: new Date(),
188
- instanceId,
189
- data: {
190
- key,
191
- value,
192
- prevValue,
193
- valueType: type,
194
- success: true
195
- }
196
- };
197
- this.emit(event);
198
- }
199
- });
200
- } catch (error) {
201
- // Could not add native listener
202
- }
203
- }
204
-
205
- // Store instance tracking (no originalMethods needed for v4)
206
- this.instances.set(instanceId, {
207
- instance,
208
- instanceId,
209
- originalMethods: {},
210
- // Not used in v4
211
- nativeListenerUnsubscribe,
212
- lastKnownValues
213
- });
214
- }
215
-
216
- /**
217
- * Remove an MMKV instance from monitoring
218
- *
219
- * Restores original methods and removes native listener.
220
- *
221
- * @param instanceId - Identifier of instance to stop monitoring
222
- */
223
- removeInstance(instanceId) {
224
- const tracked = this.instances.get(instanceId);
225
- if (!tracked) {
226
- return;
227
- }
228
- const {
229
- nativeListenerUnsubscribe
230
- } = tracked;
231
-
232
- // Remove native listener. The return of addOnValueChangedListener varies by
233
- // implementation: a bare unsubscribe function, or a Listener object with a
234
- // `.remove()` method (react-native-mmkv v4 and the desktop RemoteMMKV
235
- // back-end). Handle both, and never let teardown throw — this runs during
236
- // React unmount, where an exception escapes every error boundary and blanks
237
- // the whole app.
238
- try {
239
- if (typeof nativeListenerUnsubscribe === "function") {
240
- nativeListenerUnsubscribe();
241
- } else if (typeof nativeListenerUnsubscribe?.remove === "function") {
242
- nativeListenerUnsubscribe.remove();
243
- }
244
- } catch {
245
- /* listener already gone / back-end offline — nothing to clean up */
246
- }
247
-
248
- // Remove from tracking
249
- this.instances.delete(instanceId);
250
- }
251
-
252
- /**
253
- * Remove all monitored instances
254
- */
255
- removeAllInstances() {
256
- const instanceIds = Array.from(this.instances.keys());
257
- instanceIds.forEach(id => this.removeInstance(id));
258
- }
259
-
260
- /**
261
- * Add a listener for MMKV events across all monitored instances
262
- *
263
- * @param listener - Callback function to handle MMKV events
264
- * @returns Unsubscribe function to remove the listener
265
- *
266
- * @example
267
- * ```typescript
268
- * const unsubscribe = mmkvListener.addListener((event) => {
269
- * console.log(`[${event.instanceId}] ${event.action}:`, event.data);
270
- * });
271
- *
272
- * // Later, remove the listener
273
- * unsubscribe();
274
- * ```
275
- */
276
- addListener(listener) {
277
- this.listeners.push(listener);
278
-
279
- // Return unsubscribe function
280
- return () => {
281
- const index = this.listeners.indexOf(listener);
282
- if (index > -1) {
283
- this.listeners.splice(index, 1);
284
- }
285
- };
286
- }
287
-
288
- /**
289
- * Remove all registered event listeners
290
- */
291
- removeAllListeners() {
292
- this.listeners = [];
293
- }
294
-
295
- /**
296
- * Check if an instance is currently being monitored
297
- */
298
- hasInstance(instanceId) {
299
- return this.instances.has(instanceId);
300
- }
301
-
302
- /**
303
- * Get list of all monitored instance IDs
304
- */
305
- getMonitoredInstances() {
306
- return Array.from(this.instances.keys());
307
- }
308
-
309
- /**
310
- * Get the number of currently monitored instances
311
- */
312
- get instanceCount() {
313
- return this.instances.size;
314
- }
315
-
316
- /**
317
- * Get the number of currently registered event listeners
318
- */
319
- get listenerCount() {
320
- return this.listeners.length;
321
- }
322
-
323
- /**
324
- * Check if any instances are being monitored
325
- */
326
- get isActive() {
327
- return this.instances.size > 0;
328
- }
329
- }
330
-
331
- /**
332
- * Singleton instance of MMKVListener
333
- *
334
- * This ensures only one listener manager exists across the entire application.
335
- */
336
- const mmkvListener = exports.mmkvListener = new MMKVListener();
337
-
338
- /**
339
- * Add an MMKV instance for monitoring
340
- *
341
- * @param instance - MMKV instance to monitor
342
- * @param instanceId - Unique identifier for this instance
343
- *
344
- * @example
345
- * ```typescript
346
- * import { MMKV } from 'react-native-mmkv';
347
- * import { addMMKVInstance } from '@buoy-gg/storage';
348
- *
349
- * const storage = new MMKV();
350
- * addMMKVInstance(storage, 'mmkv.default');
351
- * ```
352
- */
353
- const addMMKVInstance = (instance, instanceId) => mmkvListener.addInstance(instance, instanceId);
354
-
355
- /**
356
- * Remove an MMKV instance from monitoring
357
- */
358
- exports.addMMKVInstance = addMMKVInstance;
359
- const removeMMKVInstance = instanceId => mmkvListener.removeInstance(instanceId);
360
-
361
- /**
362
- * Remove all monitored MMKV instances
363
- */
364
- exports.removeMMKVInstance = removeMMKVInstance;
365
- const removeAllMMKVInstances = () => mmkvListener.removeAllInstances();
366
-
367
- /**
368
- * Add an event listener for MMKV operations
369
- *
370
- * @param listener - Callback function to handle events
371
- * @returns Unsubscribe function to remove the listener
372
- */
373
- exports.removeAllMMKVInstances = removeAllMMKVInstances;
374
- const addMMKVListener = listener => mmkvListener.addListener(listener);
375
-
376
- /**
377
- * Remove all registered event listeners
378
- */
379
- exports.addMMKVListener = addMMKVListener;
380
- const removeAllMMKVListeners = () => mmkvListener.removeAllListeners();
381
-
382
- /**
383
- * Check if an MMKV instance is currently being monitored
384
- */
385
- exports.removeAllMMKVListeners = removeAllMMKVListeners;
386
- const isMMKVInstanceMonitored = instanceId => mmkvListener.hasInstance(instanceId);
387
-
388
- /**
389
- * Get list of all monitored MMKV instance IDs
390
- */
391
- exports.isMMKVInstanceMonitored = isMMKVInstanceMonitored;
392
- const getMonitoredMMKVInstances = () => mmkvListener.getMonitoredInstances();
393
-
394
- /**
395
- * Get the current number of monitored MMKV instances
396
- */
397
- exports.getMonitoredMMKVInstances = getMonitoredMMKVInstances;
398
- const getMMKVInstanceCount = () => mmkvListener.instanceCount;
399
-
400
- /**
401
- * Get the current number of registered event listeners
402
- */
403
- exports.getMMKVInstanceCount = getMMKVInstanceCount;
404
- const getMMKVListenerCount = () => mmkvListener.listenerCount;
405
-
406
- /**
407
- * Check if any MMKV instances are being monitored
408
- */
409
- exports.getMMKVListenerCount = getMMKVListenerCount;
410
- const isMMKVListening = () => mmkvListener.isActive;
411
-
412
- /**
413
- * Export the singleton instance for advanced usage
414
- */
415
- exports.isMMKVListening = isMMKVListening;
416
- var _default = exports.default = mmkvListener;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.removeMMKVInstance=exports.removeAllMMKVListeners=exports.removeAllMMKVInstances=exports.mmkvListener=exports.isMMKVListening=exports.isMMKVInstanceMonitored=exports.getMonitoredMMKVInstances=exports.getMMKVListenerCount=exports.getMMKVInstanceCount=exports.default=exports.addMMKVListener=exports.addMMKVInstance=void 0;var _mmkvTypeDetection=require("./mmkvTypeDetection");class MMKVListener{listeners=[];instances=new Map;ignoredKeys=new Set(["@react_buoy_storage_event_filters","@react_buoy_storage_key_filters","@react_buoy_storage_is_monitoring","REACT_QUERY_OFFLINE_CACHE"]);shouldIgnoreKey(e){if(this.ignoredKeys.has(e))return true;for(const t of this.ignoredKeys){if(e.startsWith(t))return true}return false}emit(e){if(this.listeners.length===0)return;this.listeners.forEach(t=>{try{t(e)}catch(r){}})}addInstance(e,t){if(this.instances.has(t)){return}let r;const i=new Map;try{for(const s of e.getAllKeys()??[]){if(this.shouldIgnoreKey(s))continue;i.set(s,(0,_mmkvTypeDetection.detectMMKVType)(e,s).value)}}catch{}if(typeof e.addOnValueChangedListener==="function"){try{r=e.addOnValueChangedListener(s=>{if(this.shouldIgnoreKey(s))return;const{value:a,type:o}=(0,_mmkvTypeDetection.detectMMKVType)(e,s);const M=i.get(s);const l=o==="unknown"||a===void 0;if(l){i.delete(s);const c={action:"delete",timestamp:new Date,instanceId:t,data:{key:s,prevValue:M,success:true}};this.emit(c)}else{i.set(s,a);const c=o==="string"?"set.string":o==="number"?"set.number":o==="boolean"?"set.boolean":o==="buffer"?"set.buffer":"set.string";const u={action:c,timestamp:new Date,instanceId:t,data:{key:s,value:a,prevValue:M,valueType:o,success:true}};this.emit(u)}})}catch(s){}}this.instances.set(t,{instance:e,instanceId:t,originalMethods:{},nativeListenerUnsubscribe:r,lastKnownValues:i})}removeInstance(e){const t=this.instances.get(e);if(!t){return}const{nativeListenerUnsubscribe:r}=t;try{if(typeof r==="function"){r()}else if(typeof r?.remove==="function"){r.remove()}}catch{}this.instances.delete(e)}removeAllInstances(){const e=Array.from(this.instances.keys());e.forEach(t=>this.removeInstance(t))}addListener(e){this.listeners.push(e);return()=>{const t=this.listeners.indexOf(e);if(t>-1){this.listeners.splice(t,1)}}}removeAllListeners(){this.listeners=[]}hasInstance(e){return this.instances.has(e)}getMonitoredInstances(){return Array.from(this.instances.keys())}get instanceCount(){return this.instances.size}get listenerCount(){return this.listeners.length}get isActive(){return this.instances.size>0}}const mmkvListener=exports.mmkvListener=new MMKVListener;const addMMKVInstance=(n,e)=>mmkvListener.addInstance(n,e);exports.addMMKVInstance=addMMKVInstance;const removeMMKVInstance=n=>mmkvListener.removeInstance(n);exports.removeMMKVInstance=removeMMKVInstance;const removeAllMMKVInstances=()=>mmkvListener.removeAllInstances();exports.removeAllMMKVInstances=removeAllMMKVInstances;const addMMKVListener=n=>mmkvListener.addListener(n);exports.addMMKVListener=addMMKVListener;const removeAllMMKVListeners=()=>mmkvListener.removeAllListeners();exports.removeAllMMKVListeners=removeAllMMKVListeners;const isMMKVInstanceMonitored=n=>mmkvListener.hasInstance(n);exports.isMMKVInstanceMonitored=isMMKVInstanceMonitored;const getMonitoredMMKVInstances=()=>mmkvListener.getMonitoredInstances();exports.getMonitoredMMKVInstances=getMonitoredMMKVInstances;const getMMKVInstanceCount=()=>mmkvListener.instanceCount;exports.getMMKVInstanceCount=getMMKVInstanceCount;const getMMKVListenerCount=()=>mmkvListener.listenerCount;exports.getMMKVListenerCount=getMMKVListenerCount;const isMMKVListening=()=>mmkvListener.isActive;exports.isMMKVListening=isMMKVListening;var _default=exports.default=mmkvListener;