@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
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.objectDiff = objectDiff;
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if a value is a plain object (not array or null)
|
|
9
|
+
*
|
|
10
|
+
* @param obj - Value to check
|
|
11
|
+
* @returns True if the value is a plain object
|
|
12
|
+
*/
|
|
13
|
+
function isObject(obj) {
|
|
14
|
+
return obj !== null && typeof obj === "object" && !Array.isArray(obj);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to check if a value is an array
|
|
19
|
+
*
|
|
20
|
+
* @param obj - Value to check
|
|
21
|
+
* @returns True if the value is an array
|
|
22
|
+
*/
|
|
23
|
+
function isArray(obj) {
|
|
24
|
+
return Array.isArray(obj);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Recursively compare two values and collect differences
|
|
29
|
+
*
|
|
30
|
+
* This function handles deep comparison of objects, arrays, and primitive values,
|
|
31
|
+
* building a comprehensive diff that tracks the exact path of each change.
|
|
32
|
+
*
|
|
33
|
+
* @param oldVal - The original value to compare from
|
|
34
|
+
* @param newVal - The new value to compare to
|
|
35
|
+
* @param path - Current path in the object structure (for nested properties)
|
|
36
|
+
* @param diffs - Array to collect difference items
|
|
37
|
+
*
|
|
38
|
+
* @performance Uses recursive traversal with path tracking for memory efficiency
|
|
39
|
+
* @performance Handles large nested structures without stack overflow concerns for typical use cases
|
|
40
|
+
*/
|
|
41
|
+
function compareValues(oldVal, newVal, path, diffs) {
|
|
42
|
+
// Both are objects
|
|
43
|
+
if (isObject(oldVal) && isObject(newVal)) {
|
|
44
|
+
const allKeys = new Set([...Object.keys(oldVal), ...Object.keys(newVal)]);
|
|
45
|
+
for (const key of allKeys) {
|
|
46
|
+
const newPath = [...path, key];
|
|
47
|
+
if (!(key in oldVal)) {
|
|
48
|
+
// Key was added
|
|
49
|
+
diffs.push({
|
|
50
|
+
type: "CREATE",
|
|
51
|
+
path: newPath,
|
|
52
|
+
value: newVal[key]
|
|
53
|
+
});
|
|
54
|
+
} else if (!(key in newVal)) {
|
|
55
|
+
// Key was removed
|
|
56
|
+
diffs.push({
|
|
57
|
+
type: "REMOVE",
|
|
58
|
+
path: newPath,
|
|
59
|
+
oldValue: oldVal[key]
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
// Key exists in both, compare values
|
|
63
|
+
compareValues(oldVal[key], newVal[key], newPath, diffs);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Both are arrays
|
|
68
|
+
else if (isArray(oldVal) && isArray(newVal)) {
|
|
69
|
+
const maxLength = Math.max(oldVal.length, newVal.length);
|
|
70
|
+
for (let i = 0; i < maxLength; i++) {
|
|
71
|
+
const newPath = [...path, i];
|
|
72
|
+
if (i >= oldVal.length) {
|
|
73
|
+
// Item was added
|
|
74
|
+
diffs.push({
|
|
75
|
+
type: "CREATE",
|
|
76
|
+
path: newPath,
|
|
77
|
+
value: newVal[i]
|
|
78
|
+
});
|
|
79
|
+
} else if (i >= newVal.length) {
|
|
80
|
+
// Item was removed
|
|
81
|
+
diffs.push({
|
|
82
|
+
type: "REMOVE",
|
|
83
|
+
path: newPath,
|
|
84
|
+
oldValue: oldVal[i]
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
// Item exists in both, compare values
|
|
88
|
+
compareValues(oldVal[i], newVal[i], newPath, diffs);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Values are different types or primitives
|
|
93
|
+
else if (oldVal !== newVal) {
|
|
94
|
+
diffs.push({
|
|
95
|
+
type: "CHANGE",
|
|
96
|
+
path,
|
|
97
|
+
oldValue: oldVal,
|
|
98
|
+
value: newVal
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Generate a comprehensive diff between two objects or values
|
|
105
|
+
*
|
|
106
|
+
* This function performs a deep comparison between two values and returns
|
|
107
|
+
* a detailed list of all differences, including additions, removals, and changes.
|
|
108
|
+
* Each difference includes the exact path where the change occurred.
|
|
109
|
+
*
|
|
110
|
+
* @param oldObj - The original object/value to compare from
|
|
111
|
+
* @param newObj - The new object/value to compare to
|
|
112
|
+
* @returns Array of DiffItem objects describing all differences
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const oldData = { user: { name: "John", age: 30 }, items: [1, 2] };
|
|
117
|
+
* const newData = { user: { name: "Jane", age: 30 }, items: [1, 2, 3] };
|
|
118
|
+
*
|
|
119
|
+
* const diffs = objectDiff(oldData, newData);
|
|
120
|
+
* // Returns:
|
|
121
|
+
* // [
|
|
122
|
+
* // { type: "CHANGE", path: ["user", "name"], oldValue: "John", value: "Jane" },
|
|
123
|
+
* // { type: "CREATE", path: ["items", 2], value: 3 }
|
|
124
|
+
* // ]
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @performance Handles circular references and deep nesting efficiently
|
|
128
|
+
* @performance Uses Set for key deduplication to optimize comparison speed
|
|
129
|
+
*/
|
|
130
|
+
function objectDiff(oldObj, newObj) {
|
|
131
|
+
const diffs = [];
|
|
132
|
+
|
|
133
|
+
// Handle null/undefined cases
|
|
134
|
+
if (oldObj === newObj) {
|
|
135
|
+
return diffs;
|
|
136
|
+
}
|
|
137
|
+
if (oldObj === null || oldObj === undefined) {
|
|
138
|
+
if (newObj !== null && newObj !== undefined) {
|
|
139
|
+
diffs.push({
|
|
140
|
+
type: "CREATE",
|
|
141
|
+
path: [],
|
|
142
|
+
value: newObj
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return diffs;
|
|
146
|
+
}
|
|
147
|
+
if (newObj === null || newObj === undefined) {
|
|
148
|
+
diffs.push({
|
|
149
|
+
type: "REMOVE",
|
|
150
|
+
path: [],
|
|
151
|
+
oldValue: oldObj
|
|
152
|
+
});
|
|
153
|
+
return diffs;
|
|
154
|
+
}
|
|
155
|
+
compareValues(oldObj, newObj, [], diffs);
|
|
156
|
+
return diffs;
|
|
157
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAsyncStorageInstance = getAsyncStorageInstance;
|
|
7
|
+
exports.isAsyncStorageAvailable = isAsyncStorageAvailable;
|
|
8
|
+
exports.safeAsyncStorage = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Safe AsyncStorage wrapper that handles missing dependencies gracefully.
|
|
11
|
+
*
|
|
12
|
+
* This wrapper allows the storage dev tools to work even when
|
|
13
|
+
* @react-native-async-storage/async-storage is not installed in the host app.
|
|
14
|
+
*
|
|
15
|
+
* When AsyncStorage is not available:
|
|
16
|
+
* - All operations return empty results or no-ops
|
|
17
|
+
* - No errors are thrown
|
|
18
|
+
* - The dev tools can still load (but storage features will be limited)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
let AsyncStorage = null;
|
|
22
|
+
let isAvailable = false;
|
|
23
|
+
let checkedAvailability = false;
|
|
24
|
+
let checkError = null;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if AsyncStorage is available in the host app
|
|
28
|
+
* This handles three cases:
|
|
29
|
+
* 1. Package not installed (module not found)
|
|
30
|
+
* 2. Package installed but native module not linked (native module null)
|
|
31
|
+
* 3. Package installed and working
|
|
32
|
+
*/
|
|
33
|
+
function checkAsyncStorageAvailability() {
|
|
34
|
+
if (checkedAvailability) {
|
|
35
|
+
return isAvailable;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
// Attempt to require AsyncStorage
|
|
39
|
+
// This might throw if:
|
|
40
|
+
// - Package is not installed (module not found)
|
|
41
|
+
// - Native module is not linked (RCTAsyncStorage is null)
|
|
42
|
+
const AsyncStorageModule = require("@react-native-async-storage/async-storage");
|
|
43
|
+
AsyncStorage = AsyncStorageModule?.default || AsyncStorageModule;
|
|
44
|
+
|
|
45
|
+
// Verify it's actually usable (has the methods we need)
|
|
46
|
+
if (AsyncStorage && typeof AsyncStorage.getItem === "function") {
|
|
47
|
+
isAvailable = true;
|
|
48
|
+
} else {
|
|
49
|
+
isAvailable = false;
|
|
50
|
+
AsyncStorage = null;
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// Catch ALL errors:
|
|
54
|
+
// - Module not found (package not installed)
|
|
55
|
+
// - Native module errors (package installed but native not linked)
|
|
56
|
+
// - Any other initialization errors
|
|
57
|
+
checkError = error;
|
|
58
|
+
isAvailable = false;
|
|
59
|
+
AsyncStorage = null;
|
|
60
|
+
}
|
|
61
|
+
checkedAvailability = true;
|
|
62
|
+
return isAvailable;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Returns true if AsyncStorage is available in the host app
|
|
67
|
+
*/
|
|
68
|
+
function isAsyncStorageAvailable() {
|
|
69
|
+
return checkAsyncStorageAvailability();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* No-op AsyncStorage implementation for when the package is not installed
|
|
74
|
+
*/
|
|
75
|
+
const noOpAsyncStorage = {
|
|
76
|
+
getItem: async _key => null,
|
|
77
|
+
setItem: async (_key, _value) => {},
|
|
78
|
+
removeItem: async _key => {},
|
|
79
|
+
getAllKeys: async () => [],
|
|
80
|
+
multiGet: async _keys => [],
|
|
81
|
+
multiSet: async _keyValuePairs => {},
|
|
82
|
+
multiRemove: async _keys => {},
|
|
83
|
+
clear: async () => {},
|
|
84
|
+
mergeItem: async (_key, _value) => {},
|
|
85
|
+
multiMerge: async _keyValuePairs => {}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Safe AsyncStorage wrapper that provides no-op fallbacks when unavailable.
|
|
90
|
+
*
|
|
91
|
+
* Usage:
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { safeAsyncStorage } from './utils/safeAsyncStorage';
|
|
94
|
+
*
|
|
95
|
+
* // This will work even if AsyncStorage is not installed
|
|
96
|
+
* const value = await safeAsyncStorage.getItem('myKey');
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
const safeAsyncStorage = exports.safeAsyncStorage = new Proxy(noOpAsyncStorage, {
|
|
100
|
+
get(_target, prop) {
|
|
101
|
+
// Avoid triggering check for React internal properties or symbols
|
|
102
|
+
if (typeof prop === "symbol" || prop.startsWith("_") || prop.startsWith("$$")) {
|
|
103
|
+
return noOpAsyncStorage[prop];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Only check availability when actually accessing AsyncStorage methods
|
|
107
|
+
try {
|
|
108
|
+
checkAsyncStorageAvailability();
|
|
109
|
+
if (isAvailable && AsyncStorage) {
|
|
110
|
+
return AsyncStorage[prop];
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
// If check throws for any reason, fall back to no-op
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Return no-op implementation
|
|
117
|
+
return noOpAsyncStorage[prop];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get the actual AsyncStorage instance if available, or null if not.
|
|
123
|
+
* Use this when you need to check if AsyncStorage is available before using it.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const storage = getAsyncStorageInstance();
|
|
128
|
+
* if (storage) {
|
|
129
|
+
* // AsyncStorage is available
|
|
130
|
+
* await storage.setItem('key', 'value');
|
|
131
|
+
* } else {
|
|
132
|
+
* // AsyncStorage is not available, handle gracefully
|
|
133
|
+
* console.warn('AsyncStorage not available');
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
function getAsyncStorageInstance() {
|
|
138
|
+
checkAsyncStorageAvailability();
|
|
139
|
+
return isAvailable ? AsyncStorage : null;
|
|
140
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.translateStorageAction = translateStorageAction;
|
|
7
|
+
/**
|
|
8
|
+
* Translates storage action types to human-readable labels
|
|
9
|
+
*/
|
|
10
|
+
function translateStorageAction(action) {
|
|
11
|
+
switch (action) {
|
|
12
|
+
// AsyncStorage actions
|
|
13
|
+
case "setItem":
|
|
14
|
+
return "SET";
|
|
15
|
+
case "removeItem":
|
|
16
|
+
return "REMOVE";
|
|
17
|
+
case "mergeItem":
|
|
18
|
+
return "MERGE";
|
|
19
|
+
case "clear":
|
|
20
|
+
return "CLEAR";
|
|
21
|
+
case "multiSet":
|
|
22
|
+
return "MULTI SET";
|
|
23
|
+
case "multiRemove":
|
|
24
|
+
return "MULTI REMOVE";
|
|
25
|
+
case "multiMerge":
|
|
26
|
+
return "MULTI MERGE";
|
|
27
|
+
|
|
28
|
+
// MMKV actions - simplified to match AsyncStorage
|
|
29
|
+
case "set.string":
|
|
30
|
+
case "set.number":
|
|
31
|
+
case "set.boolean":
|
|
32
|
+
case "set.buffer":
|
|
33
|
+
return "SET";
|
|
34
|
+
case "delete":
|
|
35
|
+
return "REMOVE";
|
|
36
|
+
case "clearAll":
|
|
37
|
+
return "CLEAR";
|
|
38
|
+
case "get.string":
|
|
39
|
+
case "get.number":
|
|
40
|
+
case "get.boolean":
|
|
41
|
+
case "get.buffer":
|
|
42
|
+
return "GET";
|
|
43
|
+
default:
|
|
44
|
+
return "UNKNOWN ACTION";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStorageTypeHexColor = getStorageTypeHexColor;
|
|
7
|
+
exports.getStorageTypeLabel = getStorageTypeLabel;
|
|
8
|
+
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
9
|
+
/** Human readable label for a storage type id. */
|
|
10
|
+
function getStorageTypeLabel(storageType) {
|
|
11
|
+
switch (storageType) {
|
|
12
|
+
case "mmkv":
|
|
13
|
+
return "MMKV";
|
|
14
|
+
case "async":
|
|
15
|
+
return "Async";
|
|
16
|
+
case "secure":
|
|
17
|
+
return "Secure";
|
|
18
|
+
default:
|
|
19
|
+
return storageType;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Preferred color token for rendering a given storage type. */
|
|
24
|
+
function getStorageTypeHexColor(storageType) {
|
|
25
|
+
switch (storageType) {
|
|
26
|
+
case "mmkv":
|
|
27
|
+
return _sharedUi.gameUIColors.info;
|
|
28
|
+
case "async":
|
|
29
|
+
return _sharedUi.gameUIColors.warning;
|
|
30
|
+
case "secure":
|
|
31
|
+
return _sharedUi.gameUIColors.success;
|
|
32
|
+
default:
|
|
33
|
+
return _sharedUi.gameUIColors.muted;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getValueTypeLabel = getValueTypeLabel;
|
|
7
|
+
/** Return a concise string describing the JavaScript type of the provided value. */
|
|
8
|
+
function getValueTypeLabel(value) {
|
|
9
|
+
if (value === null) return "null";
|
|
10
|
+
if (value === undefined) return "undefined";
|
|
11
|
+
if (Array.isArray(value)) return "array";
|
|
12
|
+
const type = typeof value;
|
|
13
|
+
if (type === "object") return "object";
|
|
14
|
+
if (type === "boolean") return "boolean";
|
|
15
|
+
if (type === "number") return "number";
|
|
16
|
+
if (type === "string") return "string";
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pre-configured AsyncStorage browser tool for FloatingDevTools
|
|
5
|
+
*
|
|
6
|
+
* This preset provides a zero-config way to add AsyncStorage inspection to your dev tools.
|
|
7
|
+
* Just import and add it to your apps array!
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { storageToolPreset } from '@buoy-gg/storage';
|
|
12
|
+
*
|
|
13
|
+
* const installedApps = [
|
|
14
|
+
* storageToolPreset, // That's it!
|
|
15
|
+
* // ...other tools
|
|
16
|
+
* ];
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { StorageIcon } from "@buoy-gg/floating-tools-core";
|
|
21
|
+
import { StorageModalWithTabs } from "./storage/components/StorageModalWithTabs";
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
/**
|
|
24
|
+
* Pre-configured AsyncStorage browser tool for FloatingDevTools.
|
|
25
|
+
* Includes:
|
|
26
|
+
* - Browse all AsyncStorage keys and values
|
|
27
|
+
* - Edit, delete, and add storage items
|
|
28
|
+
* - Live storage event monitoring
|
|
29
|
+
* - Required key validation
|
|
30
|
+
*/
|
|
31
|
+
export const storageToolPreset = {
|
|
32
|
+
id: "storage",
|
|
33
|
+
name: "STORAGE",
|
|
34
|
+
description: "AsyncStorage browser",
|
|
35
|
+
slot: "both",
|
|
36
|
+
icon: ({
|
|
37
|
+
size
|
|
38
|
+
}) => /*#__PURE__*/_jsx(StorageIcon, {
|
|
39
|
+
size: size
|
|
40
|
+
}),
|
|
41
|
+
component: StorageModalWithTabs,
|
|
42
|
+
props: {
|
|
43
|
+
requiredStorageKeys: [],
|
|
44
|
+
enableSharedModalDimensions: false
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create a custom AsyncStorage browser tool configuration.
|
|
50
|
+
* Use this if you want to override default settings or provide required storage keys.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* import { createStorageTool } from '@buoy-gg/storage';
|
|
55
|
+
*
|
|
56
|
+
* const requiredStorageKeys = [
|
|
57
|
+
* {
|
|
58
|
+
* key: "@app/session",
|
|
59
|
+
* expectedType: "string",
|
|
60
|
+
* description: "User session token",
|
|
61
|
+
* storageType: "async",
|
|
62
|
+
* },
|
|
63
|
+
* ];
|
|
64
|
+
*
|
|
65
|
+
* const myStorageTool = createStorageTool({
|
|
66
|
+
* requiredStorageKeys,
|
|
67
|
+
* colorPreset: "purple",
|
|
68
|
+
* enableSharedModalDimensions: true,
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function createStorageTool(options) {
|
|
73
|
+
return {
|
|
74
|
+
id: options?.id || "storage",
|
|
75
|
+
name: options?.name || "STORAGE",
|
|
76
|
+
description: options?.description || "AsyncStorage browser",
|
|
77
|
+
slot: "both",
|
|
78
|
+
icon: ({
|
|
79
|
+
size
|
|
80
|
+
}) => /*#__PURE__*/_jsx(StorageIcon, {
|
|
81
|
+
size: size
|
|
82
|
+
}),
|
|
83
|
+
component: StorageModalWithTabs,
|
|
84
|
+
props: {
|
|
85
|
+
requiredStorageKeys: options?.requiredStorageKeys || [],
|
|
86
|
+
enableSharedModalDimensions: options?.enableSharedModalDimensions !== undefined ? options.enableSharedModalDimensions : false
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|