@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.
- package/README.md +607 -0
- package/lib/commonjs/index.js +34 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/preset.js +94 -0
- package/lib/commonjs/storage/components/DiffViewer/DiffOptionsPanel.js +356 -0
- package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +29 -0
- package/lib/commonjs/storage/components/DiffViewer/components/DiffSummary.js +121 -0
- package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +419 -0
- package/lib/commonjs/storage/components/DiffViewer/themes/diffThemes.js +122 -0
- package/lib/commonjs/storage/components/GameUIStorageBrowser.js +924 -0
- package/lib/commonjs/storage/components/GameUIStorageStats.js +746 -0
- package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +257 -0
- package/lib/commonjs/storage/components/MMKVInstanceSelector.js +418 -0
- package/lib/commonjs/storage/components/SelectionActionBar.js +224 -0
- package/lib/commonjs/storage/components/StorageActionButtons.js +239 -0
- package/lib/commonjs/storage/components/StorageActions.js +192 -0
- package/lib/commonjs/storage/components/StorageBrowserMode.js +31 -0
- package/lib/commonjs/storage/components/StorageEventDetailContent.js +1025 -0
- package/lib/commonjs/storage/components/StorageEventFilterView.js +141 -0
- package/lib/commonjs/storage/components/StorageEventListener.js +357 -0
- package/lib/commonjs/storage/components/StorageEventsSection.js +24 -0
- package/lib/commonjs/storage/components/StorageFilterCards.js +345 -0
- package/lib/commonjs/storage/components/StorageFilterViewV2.js +42 -0
- package/lib/commonjs/storage/components/StorageKeyCard.js +516 -0
- package/lib/commonjs/storage/components/StorageKeyRow.js +356 -0
- package/lib/commonjs/storage/components/StorageKeySection.js +105 -0
- package/lib/commonjs/storage/components/StorageKeyStats.js +344 -0
- package/lib/commonjs/storage/components/StorageModalWithTabs.js +871 -0
- package/lib/commonjs/storage/components/StorageSection.js +43 -0
- package/lib/commonjs/storage/hooks/useAsyncStorageKeys.js +126 -0
- package/lib/commonjs/storage/hooks/useMMKVInstances.js +221 -0
- package/lib/commonjs/storage/hooks/useMMKVKeys.js +362 -0
- package/lib/commonjs/storage/hooks/useTickEverySecond.js +21 -0
- package/lib/commonjs/storage/index.js +148 -0
- package/lib/commonjs/storage/types.js +5 -0
- package/lib/commonjs/storage/utils/AsyncStorageListener.js +510 -0
- package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +202 -0
- package/lib/commonjs/storage/utils/MMKVListener.js +380 -0
- package/lib/commonjs/storage/utils/clearAllStorage.js +47 -0
- package/lib/commonjs/storage/utils/index.js +180 -0
- package/lib/commonjs/storage/utils/lineDiff.js +363 -0
- package/lib/commonjs/storage/utils/mmkvAvailability.js +62 -0
- package/lib/commonjs/storage/utils/mmkvTypeDetection.js +139 -0
- package/lib/commonjs/storage/utils/objectDiff.js +157 -0
- package/lib/commonjs/storage/utils/safeAsyncStorage.js +140 -0
- package/lib/commonjs/storage/utils/storageActionHelpers.js +46 -0
- package/lib/commonjs/storage/utils/storageQueryUtils.js +35 -0
- package/lib/commonjs/storage/utils/valueType.js +18 -0
- package/lib/module/index.js +7 -0
- package/lib/module/preset.js +89 -0
- package/lib/module/storage/components/DiffViewer/DiffOptionsPanel.js +352 -0
- package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +25 -0
- package/lib/module/storage/components/DiffViewer/components/DiffSummary.js +117 -0
- package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +415 -0
- package/lib/module/storage/components/DiffViewer/themes/diffThemes.js +118 -0
- package/lib/module/storage/components/GameUIStorageBrowser.js +922 -0
- package/lib/module/storage/components/GameUIStorageStats.js +742 -0
- package/lib/module/storage/components/MMKVInstanceInfoPanel.js +253 -0
- package/lib/module/storage/components/MMKVInstanceSelector.js +414 -0
- package/lib/module/storage/components/SelectionActionBar.js +221 -0
- package/lib/module/storage/components/StorageActionButtons.js +236 -0
- package/lib/module/storage/components/StorageActions.js +189 -0
- package/lib/module/storage/components/StorageBrowserMode.js +27 -0
- package/lib/module/storage/components/StorageEventDetailContent.js +1020 -0
- package/lib/module/storage/components/StorageEventFilterView.js +137 -0
- package/lib/module/storage/components/StorageEventListener.js +354 -0
- package/lib/module/storage/components/StorageEventsSection.js +20 -0
- package/lib/module/storage/components/StorageFilterCards.js +341 -0
- package/lib/module/storage/components/StorageFilterViewV2.js +38 -0
- package/lib/module/storage/components/StorageKeyCard.js +513 -0
- package/lib/module/storage/components/StorageKeyRow.js +353 -0
- package/lib/module/storage/components/StorageKeySection.js +101 -0
- package/lib/module/storage/components/StorageKeyStats.js +340 -0
- package/lib/module/storage/components/StorageModalWithTabs.js +867 -0
- package/lib/module/storage/components/StorageSection.js +40 -0
- package/lib/module/storage/hooks/useAsyncStorageKeys.js +121 -0
- package/lib/module/storage/hooks/useMMKVInstances.js +216 -0
- package/lib/module/storage/hooks/useMMKVKeys.js +359 -0
- package/lib/module/storage/hooks/useTickEverySecond.js +18 -0
- package/lib/module/storage/index.js +25 -0
- package/lib/module/storage/types.js +3 -0
- package/lib/module/storage/utils/AsyncStorageListener.js +500 -0
- package/lib/module/storage/utils/MMKVInstanceRegistry.js +196 -0
- package/lib/module/storage/utils/MMKVListener.js +367 -0
- package/lib/module/storage/utils/clearAllStorage.js +42 -0
- package/lib/module/storage/utils/index.js +22 -0
- package/lib/module/storage/utils/lineDiff.js +359 -0
- package/lib/module/storage/utils/mmkvAvailability.js +56 -0
- package/lib/module/storage/utils/mmkvTypeDetection.js +133 -0
- package/lib/module/storage/utils/objectDiff.js +153 -0
- package/lib/module/storage/utils/safeAsyncStorage.js +134 -0
- package/lib/module/storage/utils/storageActionHelpers.js +42 -0
- package/lib/module/storage/utils/storageQueryUtils.js +30 -0
- package/lib/module/storage/utils/valueType.js +14 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts +90 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts +18 -0
- package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts.map +1 -0
- package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts +7 -0
- package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +1 -0
- package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts +12 -0
- package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts.map +1 -0
- package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts +13 -0
- package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +1 -0
- package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts +64 -0
- package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts.map +1 -0
- package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts +16 -0
- package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +1 -0
- package/lib/typescript/storage/components/GameUIStorageStats.d.ts +7 -0
- package/lib/typescript/storage/components/GameUIStorageStats.d.ts.map +1 -0
- package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts +42 -0
- package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts.map +1 -0
- package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts +35 -0
- package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts.map +1 -0
- package/lib/typescript/storage/components/SelectionActionBar.d.ts +21 -0
- package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageActionButtons.d.ts +21 -0
- package/lib/typescript/storage/components/StorageActionButtons.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageActions.d.ts +10 -0
- package/lib/typescript/storage/components/StorageActions.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageBrowserMode.d.ts +18 -0
- package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageEventDetailContent.d.ts +40 -0
- package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageEventFilterView.d.ts +11 -0
- package/lib/typescript/storage/components/StorageEventFilterView.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageEventListener.d.ts +6 -0
- package/lib/typescript/storage/components/StorageEventListener.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageEventsSection.d.ts +7 -0
- package/lib/typescript/storage/components/StorageEventsSection.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageFilterCards.d.ts +36 -0
- package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageFilterViewV2.d.ts +9 -0
- package/lib/typescript/storage/components/StorageFilterViewV2.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageKeyCard.d.ts +17 -0
- package/lib/typescript/storage/components/StorageKeyCard.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageKeyRow.d.ts +15 -0
- package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageKeySection.d.ts +25 -0
- package/lib/typescript/storage/components/StorageKeySection.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageKeyStats.d.ts +15 -0
- package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageModalWithTabs.d.ts +13 -0
- package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +1 -0
- package/lib/typescript/storage/components/StorageSection.d.ts +10 -0
- package/lib/typescript/storage/components/StorageSection.d.ts.map +1 -0
- package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts +10 -0
- package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts.map +1 -0
- package/lib/typescript/storage/hooks/useMMKVInstances.d.ts +114 -0
- package/lib/typescript/storage/hooks/useMMKVInstances.d.ts.map +1 -0
- package/lib/typescript/storage/hooks/useMMKVKeys.d.ts +94 -0
- package/lib/typescript/storage/hooks/useMMKVKeys.d.ts.map +1 -0
- package/lib/typescript/storage/hooks/useTickEverySecond.d.ts +6 -0
- package/lib/typescript/storage/hooks/useTickEverySecond.d.ts.map +1 -0
- package/lib/typescript/storage/index.d.ts +15 -0
- package/lib/typescript/storage/index.d.ts.map +1 -0
- package/lib/typescript/storage/types.d.ts +41 -0
- package/lib/typescript/storage/types.d.ts.map +1 -0
- package/lib/typescript/storage/utils/AsyncStorageListener.d.ts +195 -0
- package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +1 -0
- package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts +224 -0
- package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +1 -0
- package/lib/typescript/storage/utils/MMKVListener.d.ts +218 -0
- package/lib/typescript/storage/utils/MMKVListener.d.ts.map +1 -0
- package/lib/typescript/storage/utils/clearAllStorage.d.ts +11 -0
- package/lib/typescript/storage/utils/clearAllStorage.d.ts.map +1 -0
- package/lib/typescript/storage/utils/index.d.ts +8 -0
- package/lib/typescript/storage/utils/index.d.ts.map +1 -0
- package/lib/typescript/storage/utils/lineDiff.d.ts +34 -0
- package/lib/typescript/storage/utils/lineDiff.d.ts.map +1 -0
- package/lib/typescript/storage/utils/mmkvAvailability.d.ts +23 -0
- package/lib/typescript/storage/utils/mmkvAvailability.d.ts.map +1 -0
- package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts +71 -0
- package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts.map +1 -0
- package/lib/typescript/storage/utils/objectDiff.d.ts +35 -0
- package/lib/typescript/storage/utils/objectDiff.d.ts.map +1 -0
- package/lib/typescript/storage/utils/safeAsyncStorage.d.ts +56 -0
- package/lib/typescript/storage/utils/safeAsyncStorage.d.ts.map +1 -0
- package/lib/typescript/storage/utils/storageActionHelpers.d.ts +5 -0
- package/lib/typescript/storage/utils/storageActionHelpers.d.ts.map +1 -0
- package/lib/typescript/storage/utils/storageQueryUtils.d.ts +6 -0
- package/lib/typescript/storage/utils/storageQueryUtils.d.ts.map +1 -0
- package/lib/typescript/storage/utils/valueType.d.ts +3 -0
- package/lib/typescript/storage/utils/valueType.d.ts.map +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
# @buoy/storage
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@buoy/storage)
|
|
4
|
+
|
|
5
|
+
Storage browser and monitoring tool for React Native development. Supports both AsyncStorage and MMKV.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Storage Browser**: Browse all AsyncStorage and MMKV keys and values
|
|
10
|
+
- **MMKV Support**: Monitor and debug MMKV instances (including encrypted storage)
|
|
11
|
+
- **Multiple Storage Types**: Support for AsyncStorage, MMKV, and multiple MMKV instances
|
|
12
|
+
- **Live Event Monitoring**: Track all storage operations in real-time
|
|
13
|
+
- **Edit & Delete**: Modify or remove storage items directly
|
|
14
|
+
- **Add New Items**: Create new storage entries
|
|
15
|
+
- **Required Key Validation**: Define and validate required storage keys
|
|
16
|
+
- **Type Checking**: Validate storage value types
|
|
17
|
+
- **Value Validation**: Check if values match expected patterns
|
|
18
|
+
- **Search & Filter**: Search through keys and filter by status
|
|
19
|
+
- **Copy Functionality**: Easily copy keys and values
|
|
20
|
+
- **Beautiful UI**: Modern, game-themed interface matching other React Buoy tools
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
This package is part of the React Buoy monorepo and is automatically available to other packages and the example app.
|
|
25
|
+
|
|
26
|
+
For external projects:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Required: Core storage package and AsyncStorage
|
|
30
|
+
npm install @buoy/storage @react-native-async-storage/async-storage
|
|
31
|
+
|
|
32
|
+
# Optional: MMKV support (recommended for better performance)
|
|
33
|
+
npm install react-native-mmkv
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or with pnpm/yarn:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Required
|
|
40
|
+
pnpm add @buoy/storage @react-native-async-storage/async-storage
|
|
41
|
+
|
|
42
|
+
# Optional: MMKV support
|
|
43
|
+
pnpm add react-native-mmkv
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
### Simplest Setup - Just 1 Line!
|
|
49
|
+
|
|
50
|
+
**Import the preset and add it to your tools array. Done!**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { storageToolPreset } from '@buoy/storage';
|
|
54
|
+
import { FloatingDevTools } from '@buoy/core';
|
|
55
|
+
|
|
56
|
+
const installedApps = [
|
|
57
|
+
storageToolPreset, // That's it! One line.
|
|
58
|
+
// ...your other tools
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
function App() {
|
|
62
|
+
return (
|
|
63
|
+
<FloatingDevTools
|
|
64
|
+
apps={installedApps}
|
|
65
|
+
environment="local"
|
|
66
|
+
userRole="admin"
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Done!** The preset automatically:
|
|
73
|
+
- ✅ Browses all AsyncStorage keys
|
|
74
|
+
- ✅ Monitors storage operations
|
|
75
|
+
- ✅ Provides edit/delete/add functionality
|
|
76
|
+
- ✅ No configuration required
|
|
77
|
+
|
|
78
|
+
### Custom Configuration
|
|
79
|
+
|
|
80
|
+
If you need to validate specific storage keys:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { createStorageTool } from '@buoy/storage';
|
|
84
|
+
|
|
85
|
+
const requiredStorageKeys = [
|
|
86
|
+
{
|
|
87
|
+
key: "@app/session",
|
|
88
|
+
expectedType: "string",
|
|
89
|
+
description: "User session token",
|
|
90
|
+
storageType: "async",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "@app/settings:theme",
|
|
94
|
+
expectedValue: "dark",
|
|
95
|
+
description: "Preferred theme",
|
|
96
|
+
storageType: "async",
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const myStorageTool = createStorageTool({
|
|
101
|
+
requiredStorageKeys,
|
|
102
|
+
colorPreset: "purple",
|
|
103
|
+
enableSharedModalDimensions: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const installedApps = [
|
|
107
|
+
myStorageTool,
|
|
108
|
+
// ...other tools
|
|
109
|
+
];
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Alternative: Manual Setup
|
|
113
|
+
|
|
114
|
+
If you're not using FloatingDevTools or want more control:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { StorageModalWithTabs } from '@buoy/storage';
|
|
118
|
+
|
|
119
|
+
const requiredStorageKeys = [
|
|
120
|
+
{
|
|
121
|
+
key: "@app/session",
|
|
122
|
+
expectedType: "string",
|
|
123
|
+
description: "User session token",
|
|
124
|
+
storageType: "async",
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
function App() {
|
|
129
|
+
const [showStorage, setShowStorage] = useState(false);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<Button onPress={() => setShowStorage(true)}>
|
|
134
|
+
Open Storage Browser
|
|
135
|
+
</Button>
|
|
136
|
+
|
|
137
|
+
<StorageModalWithTabs
|
|
138
|
+
visible={showStorage}
|
|
139
|
+
onClose={() => setShowStorage(false)}
|
|
140
|
+
requiredStorageKeys={requiredStorageKeys}
|
|
141
|
+
/>
|
|
142
|
+
</>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## MMKV Support
|
|
148
|
+
|
|
149
|
+
React Buoy Storage fully supports [react-native-mmkv](https://github.com/mrousavy/react-native-mmkv), a fast, efficient storage solution for React Native.
|
|
150
|
+
|
|
151
|
+
### Why MMKV?
|
|
152
|
+
|
|
153
|
+
- **10x faster** than AsyncStorage
|
|
154
|
+
- **Synchronous API** - no async/await needed
|
|
155
|
+
- **Encryption support** - built-in AES encryption
|
|
156
|
+
- **Multi-process support** - share data between extensions
|
|
157
|
+
- **Small bundle size** - ~30KB
|
|
158
|
+
|
|
159
|
+
### Setup Requirements
|
|
160
|
+
|
|
161
|
+
**⚠️ IMPORTANT:** Manual registration is **required** for MMKV v4. Auto-detection is not possible due to Metro bundler and ES6 module limitations.
|
|
162
|
+
|
|
163
|
+
You must call `registerMMKVInstance()` for each MMKV instance you want to monitor in the DevTools.
|
|
164
|
+
|
|
165
|
+
### Basic MMKV Setup
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
169
|
+
import { registerMMKVInstance } from '@buoy/storage';
|
|
170
|
+
|
|
171
|
+
// 1. Create your MMKV instance
|
|
172
|
+
export const storage = createMMKV({
|
|
173
|
+
id: 'mmkv.default'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// 2. Register it with DevTools (required!)
|
|
177
|
+
registerMMKVInstance('mmkv.default', storage);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**That's it!** Your MMKV instance is now visible in the Storage DevTools.
|
|
181
|
+
|
|
182
|
+
### Encrypted MMKV Setup
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
186
|
+
import { registerMMKVInstance } from '@buoy/storage';
|
|
187
|
+
|
|
188
|
+
// Create encrypted instance
|
|
189
|
+
export const secureStorage = createMMKV({
|
|
190
|
+
id: 'secure-storage',
|
|
191
|
+
encryptionKey: 'my-encryption-key'
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Register with encrypted flag
|
|
195
|
+
registerMMKVInstance('secure-storage', secureStorage, {
|
|
196
|
+
encrypted: true
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Multiple MMKV Instances
|
|
201
|
+
|
|
202
|
+
You can create and monitor multiple MMKV instances for different purposes:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
206
|
+
import { registerMMKVInstance } from '@buoy/storage';
|
|
207
|
+
|
|
208
|
+
// User preferences
|
|
209
|
+
export const userPrefs = createMMKV({ id: 'user-prefs' });
|
|
210
|
+
registerMMKVInstance('user-prefs', userPrefs);
|
|
211
|
+
|
|
212
|
+
// API cache
|
|
213
|
+
export const apiCache = createMMKV({ id: 'api-cache' });
|
|
214
|
+
registerMMKVInstance('api-cache', apiCache);
|
|
215
|
+
|
|
216
|
+
// Secure auth storage
|
|
217
|
+
export const authStorage = createMMKV({
|
|
218
|
+
id: 'auth',
|
|
219
|
+
encryptionKey: process.env.ENCRYPTION_KEY
|
|
220
|
+
});
|
|
221
|
+
registerMMKVInstance('auth', authStorage, { encrypted: true });
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### MMKV with FloatingDevTools
|
|
225
|
+
|
|
226
|
+
Once registered, MMKV instances automatically appear in the Storage Browser:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { FloatingDevTools } from '@buoy/core';
|
|
230
|
+
import { storageToolPreset } from '@buoy/storage';
|
|
231
|
+
import './mmkv-setup'; // Import your MMKV setup file
|
|
232
|
+
|
|
233
|
+
function App() {
|
|
234
|
+
return (
|
|
235
|
+
<FloatingDevTools
|
|
236
|
+
apps={[storageToolPreset]}
|
|
237
|
+
environment="local"
|
|
238
|
+
userRole="admin"
|
|
239
|
+
/>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The Storage Browser will show:
|
|
245
|
+
- All your MMKV instances (default, user-prefs, api-cache, auth, etc.)
|
|
246
|
+
- All AsyncStorage keys
|
|
247
|
+
- Real-time updates when data changes
|
|
248
|
+
- Ability to edit, delete, and add keys
|
|
249
|
+
|
|
250
|
+
### MMKV Registration API
|
|
251
|
+
|
|
252
|
+
#### `registerMMKVInstance(id, instance, config?)`
|
|
253
|
+
|
|
254
|
+
Register an MMKV instance with DevTools for monitoring and debugging.
|
|
255
|
+
|
|
256
|
+
**Parameters:**
|
|
257
|
+
- `id` (string) - Unique identifier for this instance (should match the `id` used in `createMMKV`)
|
|
258
|
+
- `instance` (MMKV) - The MMKV instance returned from `createMMKV()`
|
|
259
|
+
- `config` (optional) - Configuration object
|
|
260
|
+
- `encrypted` (boolean) - Set to `true` if instance uses encryption
|
|
261
|
+
|
|
262
|
+
**Returns:** `void`
|
|
263
|
+
|
|
264
|
+
**Example:**
|
|
265
|
+
```typescript
|
|
266
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
267
|
+
import { registerMMKVInstance } from '@buoy/storage';
|
|
268
|
+
|
|
269
|
+
const storage = createMMKV({ id: 'my-storage' });
|
|
270
|
+
registerMMKVInstance('my-storage', storage);
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### `unregisterMMKVInstance(id)`
|
|
274
|
+
|
|
275
|
+
Unregister an MMKV instance from DevTools monitoring. Typically not needed unless you're dynamically creating/destroying instances.
|
|
276
|
+
|
|
277
|
+
**Parameters:**
|
|
278
|
+
- `id` (string) - The instance ID to unregister
|
|
279
|
+
|
|
280
|
+
**Returns:** `void`
|
|
281
|
+
|
|
282
|
+
**Example:**
|
|
283
|
+
```typescript
|
|
284
|
+
import { unregisterMMKVInstance } from '@buoy/storage';
|
|
285
|
+
|
|
286
|
+
unregisterMMKVInstance('my-storage');
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Why Manual Registration?
|
|
290
|
+
|
|
291
|
+
Auto-detection is fundamentally impossible for MMKV v4 due to:
|
|
292
|
+
|
|
293
|
+
1. **ES6 Module Exports are Sealed** - Cannot monkey-patch `createMMKV` function
|
|
294
|
+
2. **Metro Bundler Limitations** - No access to `require.cache` or module interception
|
|
295
|
+
3. **Nitro Modules Architecture** - MMKV instances created in native C++ layer
|
|
296
|
+
|
|
297
|
+
Manual registration is a simple one-line call per instance and provides explicit control over what's monitored.
|
|
298
|
+
|
|
299
|
+
### MMKV Best Practices
|
|
300
|
+
|
|
301
|
+
**Recommended structure:**
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// utils/storage.ts
|
|
305
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
306
|
+
import { registerMMKVInstance } from '@buoy/storage';
|
|
307
|
+
|
|
308
|
+
export const storage = createMMKV({ id: 'mmkv.default' });
|
|
309
|
+
export const secureStorage = createMMKV({
|
|
310
|
+
id: 'secure',
|
|
311
|
+
encryptionKey: 'your-key'
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
if (__DEV__) {
|
|
315
|
+
registerMMKVInstance('mmkv.default', storage);
|
|
316
|
+
registerMMKVInstance('secure', secureStorage, { encrypted: true });
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Then import in your app:
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { storage, secureStorage } from './utils/storage';
|
|
324
|
+
|
|
325
|
+
// Use anywhere in your app
|
|
326
|
+
storage.set('user.name', 'John Doe');
|
|
327
|
+
secureStorage.set('auth.token', 'secret-token');
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## API Reference
|
|
331
|
+
|
|
332
|
+
### Presets
|
|
333
|
+
|
|
334
|
+
#### `storageToolPreset`
|
|
335
|
+
|
|
336
|
+
Pre-configured AsyncStorage browser tool ready to use with FloatingDevTools.
|
|
337
|
+
|
|
338
|
+
**Example:**
|
|
339
|
+
```typescript
|
|
340
|
+
import { storageToolPreset } from '@buoy/storage';
|
|
341
|
+
|
|
342
|
+
const installedApps = [storageToolPreset];
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
#### `createStorageTool(options?)`
|
|
346
|
+
|
|
347
|
+
Create a custom AsyncStorage browser tool configuration.
|
|
348
|
+
|
|
349
|
+
**Options:**
|
|
350
|
+
```typescript
|
|
351
|
+
{
|
|
352
|
+
/** Tool name (default: "STORAGE") */
|
|
353
|
+
name?: string;
|
|
354
|
+
/** Tool description */
|
|
355
|
+
description?: string;
|
|
356
|
+
/** Icon color preset (default: "green") */
|
|
357
|
+
colorPreset?: "orange" | "cyan" | "purple" | "pink" | "yellow" | "green";
|
|
358
|
+
/** Custom tool ID (default: "storage") */
|
|
359
|
+
id?: string;
|
|
360
|
+
/** Array of required storage keys to validate */
|
|
361
|
+
requiredStorageKeys?: RequiredStorageKey[];
|
|
362
|
+
/** Enable shared modal dimensions */
|
|
363
|
+
enableSharedModalDimensions?: boolean;
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Example:**
|
|
368
|
+
```typescript
|
|
369
|
+
import { createStorageTool } from '@buoy/storage';
|
|
370
|
+
|
|
371
|
+
const requiredStorageKeys = [
|
|
372
|
+
{
|
|
373
|
+
key: "@app/session",
|
|
374
|
+
expectedType: "string",
|
|
375
|
+
description: "User session token",
|
|
376
|
+
storageType: "async",
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
const myStorageTool = createStorageTool({
|
|
381
|
+
name: "APP STORAGE",
|
|
382
|
+
requiredStorageKeys,
|
|
383
|
+
colorPreset: "cyan",
|
|
384
|
+
enableSharedModalDimensions: true,
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Components
|
|
389
|
+
|
|
390
|
+
#### `StorageModalWithTabs`
|
|
391
|
+
|
|
392
|
+
Main modal component with two tabs: Browser and Events.
|
|
393
|
+
|
|
394
|
+
**Props:**
|
|
395
|
+
```typescript
|
|
396
|
+
interface StorageModalWithTabsProps {
|
|
397
|
+
/** Whether the modal is visible */
|
|
398
|
+
visible: boolean;
|
|
399
|
+
/** Callback when modal is closed */
|
|
400
|
+
onClose: () => void;
|
|
401
|
+
/** Optional back button handler */
|
|
402
|
+
onBack?: () => void;
|
|
403
|
+
/** Whether to use shared modal dimensions */
|
|
404
|
+
enableSharedModalDimensions?: boolean;
|
|
405
|
+
/** Array of required storage keys to validate */
|
|
406
|
+
requiredStorageKeys?: RequiredStorageKey[];
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**Example:**
|
|
411
|
+
```typescript
|
|
412
|
+
<StorageModalWithTabs
|
|
413
|
+
visible={isVisible}
|
|
414
|
+
onClose={handleClose}
|
|
415
|
+
requiredStorageKeys={requiredKeys}
|
|
416
|
+
enableSharedModalDimensions={true}
|
|
417
|
+
/>
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Types
|
|
421
|
+
|
|
422
|
+
#### `RequiredStorageKey`
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
interface RequiredStorageKey {
|
|
426
|
+
/** Storage key to validate */
|
|
427
|
+
key: string;
|
|
428
|
+
/** Optional description of the key */
|
|
429
|
+
description?: string;
|
|
430
|
+
/** Expected value type */
|
|
431
|
+
expectedType?: "string" | "number" | "boolean" | "object" | "array";
|
|
432
|
+
/** Expected value */
|
|
433
|
+
expectedValue?: any;
|
|
434
|
+
/** Storage type: "async" for AsyncStorage, "mmkv" for MMKV, "secure" for Secure Storage */
|
|
435
|
+
storageType: "async" | "mmkv" | "secure";
|
|
436
|
+
/** Whether the key is required */
|
|
437
|
+
required?: boolean;
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
#### `AsyncStorageEvent`
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
interface AsyncStorageEvent {
|
|
445
|
+
/** Unique event ID */
|
|
446
|
+
id: string;
|
|
447
|
+
/** Event type (set, get, remove, clear, etc.) */
|
|
448
|
+
type: "set" | "get" | "remove" | "clear" | "multiGet" | "multiSet" | "multiRemove";
|
|
449
|
+
/** Storage key(s) involved */
|
|
450
|
+
key?: string | string[];
|
|
451
|
+
/** Value (for set operations) */
|
|
452
|
+
value?: any;
|
|
453
|
+
/** Timestamp of the event */
|
|
454
|
+
timestamp: number;
|
|
455
|
+
/** Whether the operation succeeded */
|
|
456
|
+
success: boolean;
|
|
457
|
+
/** Error message if operation failed */
|
|
458
|
+
error?: string;
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Use Cases
|
|
463
|
+
|
|
464
|
+
### Session Management
|
|
465
|
+
|
|
466
|
+
Monitor and validate user session storage:
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
import { createStorageTool } from '@buoy/storage';
|
|
470
|
+
|
|
471
|
+
const requiredStorageKeys = [
|
|
472
|
+
{
|
|
473
|
+
key: "@app/session:token",
|
|
474
|
+
expectedType: "string",
|
|
475
|
+
description: "JWT auth token",
|
|
476
|
+
storageType: "async",
|
|
477
|
+
required: true,
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
key: "@app/session:userId",
|
|
481
|
+
expectedType: "string",
|
|
482
|
+
description: "Current user ID",
|
|
483
|
+
storageType: "async",
|
|
484
|
+
required: true,
|
|
485
|
+
},
|
|
486
|
+
];
|
|
487
|
+
|
|
488
|
+
const storageTool = createStorageTool({ requiredStorageKeys });
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### App Settings
|
|
492
|
+
|
|
493
|
+
Validate app configuration storage:
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
const requiredStorageKeys = [
|
|
497
|
+
{
|
|
498
|
+
key: "@app/settings:theme",
|
|
499
|
+
expectedValue: "dark",
|
|
500
|
+
description: "UI theme preference",
|
|
501
|
+
storageType: "async",
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
key: "@app/settings:notifications",
|
|
505
|
+
expectedType: "boolean",
|
|
506
|
+
description: "Notifications enabled",
|
|
507
|
+
storageType: "async",
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
key: "@app/settings:language",
|
|
511
|
+
expectedType: "string",
|
|
512
|
+
description: "User language preference",
|
|
513
|
+
storageType: "async",
|
|
514
|
+
},
|
|
515
|
+
];
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Cache Management
|
|
519
|
+
|
|
520
|
+
Monitor cached data:
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
const requiredStorageKeys = [
|
|
524
|
+
{
|
|
525
|
+
key: "@app/cache:userData",
|
|
526
|
+
expectedType: "object",
|
|
527
|
+
description: "Cached user profile data",
|
|
528
|
+
storageType: "async",
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
key: "@app/cache:timestamp",
|
|
532
|
+
expectedType: "number",
|
|
533
|
+
description: "Cache timestamp",
|
|
534
|
+
storageType: "async",
|
|
535
|
+
},
|
|
536
|
+
];
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
## Features in Detail
|
|
540
|
+
|
|
541
|
+
### Browser Tab
|
|
542
|
+
|
|
543
|
+
- **View All Keys**: See all AsyncStorage keys and their values
|
|
544
|
+
- **Search**: Search through keys by name
|
|
545
|
+
- **Filter**: Filter by validation status (all, missing, issues)
|
|
546
|
+
- **Edit**: Modify existing values directly
|
|
547
|
+
- **Delete**: Remove storage entries
|
|
548
|
+
- **Add**: Create new storage entries
|
|
549
|
+
- **Copy**: Copy keys and values to clipboard
|
|
550
|
+
- **Validation**: See which required keys are missing or invalid
|
|
551
|
+
|
|
552
|
+
### Events Tab
|
|
553
|
+
|
|
554
|
+
- **Live Monitoring**: Watch all storage operations in real-time
|
|
555
|
+
- **Event Types**: Track set, get, remove, clear, and multi-operations
|
|
556
|
+
- **Filtering**: Filter events by type or key
|
|
557
|
+
- **Search**: Search through event history
|
|
558
|
+
- **Timeline**: See chronological order of operations
|
|
559
|
+
- **Pause/Resume**: Control event capture
|
|
560
|
+
- **Clear**: Clear event history
|
|
561
|
+
|
|
562
|
+
### Validation
|
|
563
|
+
|
|
564
|
+
Required storage keys can be validated for:
|
|
565
|
+
- **Existence**: Check if the key exists
|
|
566
|
+
- **Type**: Validate the value type (string, number, boolean, object, array)
|
|
567
|
+
- **Value**: Check if the value matches an expected value
|
|
568
|
+
- **Custom Validation**: Implement custom validation logic
|
|
569
|
+
|
|
570
|
+
## Dependencies
|
|
571
|
+
|
|
572
|
+
- `@buoy/shared-ui` - Common UI components and utilities
|
|
573
|
+
- `@react-native-async-storage/async-storage` - AsyncStorage implementation (peer dependency)
|
|
574
|
+
- `react-native-mmkv` - MMKV storage implementation (optional peer dependency)
|
|
575
|
+
- React and React Native (peer dependencies)
|
|
576
|
+
|
|
577
|
+
## Development
|
|
578
|
+
|
|
579
|
+
### Building
|
|
580
|
+
|
|
581
|
+
```bash
|
|
582
|
+
pnpm build
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### Type Checking
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
pnpm typecheck
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Clean Build
|
|
592
|
+
|
|
593
|
+
```bash
|
|
594
|
+
pnpm clean
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
## License
|
|
598
|
+
|
|
599
|
+
MIT
|
|
600
|
+
|
|
601
|
+
## Contributing
|
|
602
|
+
|
|
603
|
+
See the main repository [CONTRIBUTING.md](../../CONTRIBUTING.md) for contribution guidelines.
|
|
604
|
+
|
|
605
|
+
## Support
|
|
606
|
+
|
|
607
|
+
For issues and feature requests, please visit the [GitHub repository](https://github.com/LovesWorking/react-native-buoy/issues).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
storageToolPreset: true,
|
|
8
|
+
createStorageTool: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "createStorageTool", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _preset.createStorageTool;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "storageToolPreset", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _preset.storageToolPreset;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var _preset = require("./preset");
|
|
23
|
+
var _storage = require("./storage");
|
|
24
|
+
Object.keys(_storage).forEach(function (key) {
|
|
25
|
+
if (key === "default" || key === "__esModule") return;
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
27
|
+
if (key in exports && exports[key] === _storage[key]) return;
|
|
28
|
+
Object.defineProperty(exports, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _storage[key];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|