@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.
- package/README.md +11 -86
- package/lib/commonjs/index.js +1 -346
- package/lib/commonjs/preset.js +1 -80
- package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +1 -36
- package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -12
- package/lib/commonjs/storage/components/DiffViewer/themes/diffThemes.js +1 -24
- package/lib/commonjs/storage/components/GameUIStorageBrowser.js +3 -1258
- package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +1 -257
- package/lib/commonjs/storage/components/MMKVInstanceSelector.js +1 -418
- package/lib/commonjs/storage/components/SelectionActionBar.js +1 -207
- package/lib/commonjs/storage/components/StorageActionButtons.js +1 -241
- package/lib/commonjs/storage/components/StorageBrowserMode.js +1 -61
- package/lib/commonjs/storage/components/StorageEventActionButton.js +1 -121
- package/lib/commonjs/storage/components/StorageEventCard.js +1 -117
- package/lib/commonjs/storage/components/StorageEventDetailContent.js +1 -494
- package/lib/commonjs/storage/components/StorageEventFilterView.js +1 -159
- package/lib/commonjs/storage/components/StorageEventsSection.js +1 -24
- package/lib/commonjs/storage/components/StorageFilterCards.js +1 -231
- package/lib/commonjs/storage/components/StorageKeyCard.js +1 -520
- package/lib/commonjs/storage/components/StorageKeyDetailScreen.js +1 -579
- package/lib/commonjs/storage/components/StorageKeyRow.js +1 -559
- package/lib/commonjs/storage/components/StorageKeySection.js +1 -160
- package/lib/commonjs/storage/components/StorageKeyStats.js +1 -344
- package/lib/commonjs/storage/components/StorageModalWithTabs.js +1 -954
- package/lib/commonjs/storage/components/StorageSaveNotice.js +1 -171
- package/lib/commonjs/storage/components/StorageSection.js +1 -43
- package/lib/commonjs/storage/components/StorageTypeFilterBar.js +1 -143
- package/lib/commonjs/storage/hooks/useAsyncStorageKeys.js +1 -141
- package/lib/commonjs/storage/hooks/useMMKVInstances.js +1 -210
- package/lib/commonjs/storage/hooks/useMMKVKeys.js +1 -376
- package/lib/commonjs/storage/hooks/useSecureStoreKeys.js +1 -159
- package/lib/commonjs/storage/hooks/useStorageEvents.js +1 -61
- package/lib/commonjs/storage/stores/storageEventStore.js +1 -312
- package/lib/commonjs/storage/sync/storageSyncAdapter.js +1 -478
- package/lib/commonjs/storage/types.js +1 -5
- package/lib/commonjs/storage/utils/AsyncStorageListener.js +1 -691
- package/lib/commonjs/storage/utils/AsyncStorageListener.web.js +1 -0
- package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +1 -203
- package/lib/commonjs/storage/utils/MMKVListener.js +1 -416
- package/lib/commonjs/storage/utils/SecureStoreRegistry.js +1 -200
- package/lib/commonjs/storage/utils/asyncStorageCompat.js +1 -89
- package/lib/commonjs/storage/utils/browserStorageLifecycle.js +1 -0
- package/lib/commonjs/storage/utils/browserStorageLifecycle.web.js +1 -0
- package/lib/commonjs/storage/utils/clearAllStorage.js +1 -48
- package/lib/commonjs/storage/utils/deleteStorageKeys.js +1 -82
- package/lib/commonjs/storage/utils/lineDiff.js +1 -30
- package/lib/commonjs/storage/utils/mmkvAvailability.js +1 -62
- package/lib/commonjs/storage/utils/mmkvAvailability.web.js +1 -0
- package/lib/commonjs/storage/utils/mmkvTypeDetection.js +1 -154
- package/lib/commonjs/storage/utils/requiredStorageKeyScope.js +1 -17
- package/lib/commonjs/storage/utils/setStorageValue.js +1 -218
- package/lib/commonjs/storage/utils/snapshotProvider.js +1 -382
- package/lib/commonjs/storage/utils/storageActionHelpers.js +1 -46
- package/lib/commonjs/storage/utils/storageBrowserRefresh.js +1 -49
- package/lib/commonjs/storage/utils/storageLabels.js +1 -0
- package/lib/commonjs/storage/utils/storageLabels.web.js +1 -0
- package/lib/commonjs/storage/utils/storageOps.js +1 -53
- package/lib/commonjs/storage/utils/storageQueryUtils.js +1 -35
- package/lib/commonjs/storage/utils/storageTimeTravelUtils.js +1 -288
- package/lib/commonjs/storage/utils/valueType.js +1 -83
- package/lib/module/index.js +1 -112
- package/lib/module/preset.js +1 -76
- package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +1 -32
- package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +1 -9
- package/lib/module/storage/components/DiffViewer/themes/diffThemes.js +1 -10
- package/lib/module/storage/components/GameUIStorageBrowser.js +3 -1256
- package/lib/module/storage/components/MMKVInstanceInfoPanel.js +1 -253
- package/lib/module/storage/components/MMKVInstanceSelector.js +1 -414
- package/lib/module/storage/components/SelectionActionBar.js +1 -204
- package/lib/module/storage/components/StorageActionButtons.js +1 -237
- package/lib/module/storage/components/StorageBrowserMode.js +1 -57
- package/lib/module/storage/components/StorageEventActionButton.js +1 -118
- package/lib/module/storage/components/StorageEventCard.js +1 -112
- package/lib/module/storage/components/StorageEventDetailContent.js +1 -490
- package/lib/module/storage/components/StorageEventFilterView.js +1 -155
- package/lib/module/storage/components/StorageEventsSection.js +1 -20
- package/lib/module/storage/components/StorageFilterCards.js +1 -227
- package/lib/module/storage/components/StorageKeyCard.js +1 -517
- package/lib/module/storage/components/StorageKeyDetailScreen.js +1 -577
- package/lib/module/storage/components/StorageKeyRow.js +1 -554
- package/lib/module/storage/components/StorageKeySection.js +1 -155
- package/lib/module/storage/components/StorageKeyStats.js +1 -341
- package/lib/module/storage/components/StorageModalWithTabs.js +1 -949
- package/lib/module/storage/components/StorageSaveNotice.js +1 -168
- package/lib/module/storage/components/StorageSection.js +1 -40
- package/lib/module/storage/components/StorageTypeFilterBar.js +1 -138
- package/lib/module/storage/hooks/useAsyncStorageKeys.js +1 -136
- package/lib/module/storage/hooks/useMMKVInstances.js +1 -204
- package/lib/module/storage/hooks/useMMKVKeys.js +1 -371
- package/lib/module/storage/hooks/useSecureStoreKeys.js +1 -156
- package/lib/module/storage/hooks/useStorageEvents.js +1 -58
- package/lib/module/storage/stores/storageEventStore.js +1 -301
- package/lib/module/storage/sync/storageSyncAdapter.js +1 -474
- package/lib/module/storage/types.js +1 -3
- package/lib/module/storage/utils/AsyncStorageListener.js +1 -679
- package/lib/module/storage/utils/AsyncStorageListener.web.js +1 -0
- package/lib/module/storage/utils/MMKVInstanceRegistry.js +1 -197
- package/lib/module/storage/utils/MMKVListener.js +1 -403
- package/lib/module/storage/utils/SecureStoreRegistry.js +1 -194
- package/lib/module/storage/utils/asyncStorageCompat.js +1 -81
- package/lib/module/storage/utils/browserStorageLifecycle.js +1 -0
- package/lib/module/storage/utils/browserStorageLifecycle.web.js +1 -0
- package/lib/module/storage/utils/clearAllStorage.js +1 -43
- package/lib/module/storage/utils/deleteStorageKeys.js +1 -78
- package/lib/module/storage/utils/lineDiff.js +1 -12
- package/lib/module/storage/utils/mmkvAvailability.js +1 -56
- package/lib/module/storage/utils/mmkvAvailability.web.js +1 -0
- package/lib/module/storage/utils/mmkvTypeDetection.js +1 -148
- package/lib/module/storage/utils/requiredStorageKeyScope.js +1 -13
- package/lib/module/storage/utils/setStorageValue.js +1 -209
- package/lib/module/storage/utils/snapshotProvider.js +1 -380
- package/lib/module/storage/utils/storageActionHelpers.js +1 -42
- package/lib/module/storage/utils/storageBrowserRefresh.js +1 -44
- package/lib/module/storage/utils/storageLabels.js +1 -0
- package/lib/module/storage/utils/storageLabels.web.js +1 -0
- package/lib/module/storage/utils/storageOps.js +1 -46
- package/lib/module/storage/utils/storageQueryUtils.js +1 -30
- package/lib/module/storage/utils/storageTimeTravelUtils.js +1 -281
- package/lib/module/storage/utils/valueType.js +1 -76
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts +0 -8
- package/lib/typescript/storage/components/StorageEventCard.d.ts +0 -7
- package/lib/typescript/storage/components/StorageKeyRow.d.ts +2 -6
- package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts +0 -15
- package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts +2 -2
- package/lib/typescript/storage/sync/storageSyncAdapter.d.ts +7 -13
- package/lib/typescript/storage/utils/AsyncStorageListener.web.d.ts +24 -0
- package/lib/typescript/storage/utils/browserStorageLifecycle.d.ts +3 -0
- package/lib/typescript/storage/utils/browserStorageLifecycle.web.d.ts +2 -0
- package/lib/typescript/storage/utils/mmkvAvailability.web.d.ts +4 -0
- package/lib/typescript/storage/utils/storageLabels.d.ts +8 -0
- package/lib/typescript/storage/utils/storageLabels.web.d.ts +8 -0
- package/lib/web/index.mjs +4 -0
- package/package.json +40 -14
- package/lib/commonjs/storage/components/DiffViewer/DiffOptionsPanel.js +0 -356
- package/lib/commonjs/storage/components/DiffViewer/components/DiffSummary.js +0 -122
- package/lib/commonjs/storage/components/StorageKeyEditorScreen.js +0 -414
- package/lib/commonjs/storage/components/StorageScalarKeyEditor.js +0 -61
- package/lib/commonjs/storage/components/StorageValueEditModal.js +0 -24
- package/lib/commonjs/storage/hooks/useKeyEditor.js +0 -31
- package/lib/commonjs/storage/hooks/useTreeDraft.js +0 -25
- package/lib/module/storage/components/DiffViewer/DiffOptionsPanel.js +0 -352
- package/lib/module/storage/components/DiffViewer/components/DiffSummary.js +0 -118
- package/lib/module/storage/components/StorageKeyEditorScreen.js +0 -410
- package/lib/module/storage/components/StorageScalarKeyEditor.js +0 -57
- package/lib/module/storage/components/StorageValueEditModal.js +0 -20
- package/lib/module/storage/hooks/useKeyEditor.js +0 -27
- package/lib/module/storage/hooks/useTreeDraft.js +0 -21
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts +0 -18
- package/lib/typescript/storage/components/DiffViewer/DiffOptionsPanel.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts +0 -12
- package/lib/typescript/storage/components/DiffViewer/components/DiffSummary.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +0 -1
- package/lib/typescript/storage/components/DiffViewer/themes/diffThemes.d.ts.map +0 -1
- package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +0 -1
- package/lib/typescript/storage/components/MMKVInstanceInfoPanel.d.ts.map +0 -1
- package/lib/typescript/storage/components/MMKVInstanceSelector.d.ts.map +0 -1
- package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageActionButtons.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventActionButton.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventCard.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventFilterView.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageEventsSection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyCard.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyDetailScreen.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts +0 -42
- package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeySection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageSaveNotice.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts +0 -24
- package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageSection.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts.map +0 -1
- package/lib/typescript/storage/components/StorageValueEditModal.d.ts +0 -14
- package/lib/typescript/storage/components/StorageValueEditModal.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useAsyncStorageKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useKeyEditor.d.ts +0 -27
- package/lib/typescript/storage/hooks/useKeyEditor.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useMMKVInstances.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useMMKVKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useStorageEvents.d.ts.map +0 -1
- package/lib/typescript/storage/hooks/useTreeDraft.d.ts +0 -16
- package/lib/typescript/storage/hooks/useTreeDraft.d.ts.map +0 -1
- package/lib/typescript/storage/stores/storageEventStore.d.ts.map +0 -1
- package/lib/typescript/storage/sync/storageSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/storage/types.d.ts.map +0 -1
- package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +0 -1
- package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +0 -1
- package/lib/typescript/storage/utils/MMKVListener.d.ts.map +0 -1
- package/lib/typescript/storage/utils/SecureStoreRegistry.d.ts.map +0 -1
- package/lib/typescript/storage/utils/asyncStorageCompat.d.ts.map +0 -1
- package/lib/typescript/storage/utils/clearAllStorage.d.ts.map +0 -1
- package/lib/typescript/storage/utils/deleteStorageKeys.d.ts.map +0 -1
- package/lib/typescript/storage/utils/lineDiff.d.ts.map +0 -1
- package/lib/typescript/storage/utils/mmkvAvailability.d.ts.map +0 -1
- package/lib/typescript/storage/utils/mmkvTypeDetection.d.ts.map +0 -1
- package/lib/typescript/storage/utils/requiredStorageKeyScope.d.ts.map +0 -1
- package/lib/typescript/storage/utils/setStorageValue.d.ts.map +0 -1
- package/lib/typescript/storage/utils/snapshotProvider.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageActionHelpers.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageBrowserRefresh.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageOps.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageQueryUtils.d.ts.map +0 -1
- package/lib/typescript/storage/utils/storageTimeTravelUtils.d.ts.map +0 -1
- package/lib/typescript/storage/utils/valueType.d.ts.map +0 -1
|
@@ -1,154 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.detectMMKVType = detectMMKVType;
|
|
7
|
-
exports.formatMMKVValue = formatMMKVValue;
|
|
8
|
-
exports.isTypeMatch = isTypeMatch;
|
|
9
|
-
/**
|
|
10
|
-
* MMKV Type Detection Utilities
|
|
11
|
-
*
|
|
12
|
-
* MMKV stores values with native types (string, number, boolean, ArrayBuffer).
|
|
13
|
-
* This module provides utilities to detect the type of a stored value by trying
|
|
14
|
-
* each getter sequentially.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// Use 'any' type for MMKV to avoid hard dependency on react-native-mmkv
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Detect the type of a value stored in MMKV by trying each getter.
|
|
21
|
-
*
|
|
22
|
-
* Since MMKV doesn't provide a getType() method, we must try each getter
|
|
23
|
-
* (getString, getNumber, getBoolean, getBuffer) until one returns a value.
|
|
24
|
-
*
|
|
25
|
-
* Order matters: We try in order of most common types first.
|
|
26
|
-
*
|
|
27
|
-
* @param instance - MMKV instance to read from
|
|
28
|
-
* @param key - Storage key
|
|
29
|
-
* @returns Value and its detected type
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const instance = createMMKV();
|
|
34
|
-
* instance.set('name', 'John');
|
|
35
|
-
* instance.set('age', 30);
|
|
36
|
-
* instance.set('active', true);
|
|
37
|
-
*
|
|
38
|
-
* detectMMKVType(instance, 'name'); // { value: 'John', type: 'string' }
|
|
39
|
-
* detectMMKVType(instance, 'age'); // { value: 30, type: 'number' }
|
|
40
|
-
* detectMMKVType(instance, 'active'); // { value: true, type: 'boolean' }
|
|
41
|
-
* detectMMKVType(instance, 'missing');// { value: undefined, type: 'unknown' }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
function detectMMKVType(instance, key) {
|
|
45
|
-
// MMKV stores no type metadata, so the native getters can cross-read: in
|
|
46
|
-
// particular `getString` returns "" (an empty string, NOT undefined) for many
|
|
47
|
-
// non-string values like numbers and `false`. Trying getString first and
|
|
48
|
-
// trusting its result therefore mis-detects those as empty strings — e.g.
|
|
49
|
-
// a key set to 42 or false would render as "". Probe the getters and only let
|
|
50
|
-
// getString win when it returns a NON-empty string; treat an empty result as
|
|
51
|
-
// ambiguous and prefer the number/boolean getters.
|
|
52
|
-
const stringValue = instance.getString(key);
|
|
53
|
-
|
|
54
|
-
// A non-empty string is unambiguously a string.
|
|
55
|
-
if (stringValue !== undefined && stringValue !== '') {
|
|
56
|
-
return {
|
|
57
|
-
value: stringValue,
|
|
58
|
-
type: 'string'
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Empty getString result is ambiguous (genuine "" vs a number/boolean the
|
|
63
|
-
// native layer decoded to ""). Prefer typed getters when they have a value.
|
|
64
|
-
const numberValue = instance.getNumber(key);
|
|
65
|
-
if (numberValue !== undefined) {
|
|
66
|
-
return {
|
|
67
|
-
value: numberValue,
|
|
68
|
-
type: 'number'
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const booleanValue = instance.getBoolean(key);
|
|
72
|
-
if (booleanValue !== undefined) {
|
|
73
|
-
return {
|
|
74
|
-
value: booleanValue,
|
|
75
|
-
type: 'boolean'
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// getString returned "" and nothing else matched -> a genuine empty string.
|
|
80
|
-
if (stringValue === '') {
|
|
81
|
-
return {
|
|
82
|
-
value: '',
|
|
83
|
-
type: 'string'
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Try buffer (least common)
|
|
88
|
-
const bufferValue = instance.getBuffer(key);
|
|
89
|
-
if (bufferValue !== undefined) {
|
|
90
|
-
// Format buffer for display (don't return raw ArrayBuffer)
|
|
91
|
-
return {
|
|
92
|
-
value: `<ArrayBuffer ${bufferValue.byteLength} bytes>`,
|
|
93
|
-
type: 'buffer'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Key doesn't exist or unknown type
|
|
98
|
-
return {
|
|
99
|
-
value: undefined,
|
|
100
|
-
type: 'unknown'
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Format an MMKV value for display in the UI.
|
|
106
|
-
*
|
|
107
|
-
* @param value - The value to format
|
|
108
|
-
* @param type - The detected type
|
|
109
|
-
* @returns Formatted string representation
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* formatMMKVValue('hello', 'string'); // '"hello"'
|
|
114
|
-
* formatMMKVValue(42, 'number'); // '42'
|
|
115
|
-
* formatMMKVValue(true, 'boolean'); // 'true'
|
|
116
|
-
* formatMMKVValue('<ArrayBuffer 1024 bytes>', 'buffer'); // '<ArrayBuffer 1024 bytes>'
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
function formatMMKVValue(value, type) {
|
|
120
|
-
if (value === undefined) return 'undefined';
|
|
121
|
-
if (value === null) return 'null';
|
|
122
|
-
switch (type) {
|
|
123
|
-
case 'string':
|
|
124
|
-
return `"${value}"`;
|
|
125
|
-
case 'number':
|
|
126
|
-
return String(value);
|
|
127
|
-
case 'boolean':
|
|
128
|
-
return value ? 'true' : 'false';
|
|
129
|
-
case 'buffer':
|
|
130
|
-
// Value is already formatted as "<ArrayBuffer X bytes>"
|
|
131
|
-
return value;
|
|
132
|
-
case 'unknown':
|
|
133
|
-
return 'unknown';
|
|
134
|
-
default:
|
|
135
|
-
return String(value);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Check if a value type matches an expected type for validation.
|
|
141
|
-
*
|
|
142
|
-
* @param actualType - Detected type
|
|
143
|
-
* @param expectedType - Expected type from configuration
|
|
144
|
-
* @returns True if types match
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* isTypeMatch('string', 'string'); // true
|
|
149
|
-
* isTypeMatch('number', 'string'); // false
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
function isTypeMatch(actualType, expectedType) {
|
|
153
|
-
return actualType === expectedType;
|
|
154
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectMMKVType=detectMMKVType;exports.formatMMKVValue=formatMMKVValue;exports.isTypeMatch=isTypeMatch;function detectMMKVType(e,n){const r=e.getString(n);if(r!==void 0&&r!==""){return{value:r,type:"string"}}const t=e.getNumber(n);if(t!==void 0){return{value:t,type:"number"}}const u=e.getBoolean(n);if(u!==void 0){return{value:u,type:"boolean"}}if(r===""){return{value:"",type:"string"}}const f=e.getBuffer(n);if(f!==void 0){return{value:`<ArrayBuffer ${f.byteLength} bytes>`,type:"buffer"}}return{value:void 0,type:"unknown"}}function formatMMKVValue(e,n){if(e===void 0)return"undefined";if(e===null)return"null";switch(n){case"string":return`"${e}"`;case"number":return String(e);case"boolean":return e?"true":"false";case"buffer":return e;case"unknown":return"unknown";default:return String(e)}}function isTypeMatch(e,n){return e===n}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.requiredKeyAppliesTo = requiredKeyAppliesTo;
|
|
7
|
-
/**
|
|
8
|
-
* Whether a required-key declaration should be enforced by a given backend
|
|
9
|
-
* hook. Explicit `storageType` wins; bare string keys default to AsyncStorage
|
|
10
|
-
* (the historical zero-config backend). Objects without `storageType` still
|
|
11
|
-
* apply to every backend — matching prior behavior for apps that never set it.
|
|
12
|
-
*/
|
|
13
|
-
function requiredKeyAppliesTo(req, backend) {
|
|
14
|
-
if (typeof req === "string") return backend === "async";
|
|
15
|
-
if (req.storageType) return req.storageType === backend;
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requiredKeyAppliesTo=requiredKeyAppliesTo;function requiredKeyAppliesTo(e,r){if(typeof e==="string")return r==="async";if(e.storageType)return e.storageType===r;return true}
|
|
@@ -1,218 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setStorageValue = setStorageValue;
|
|
7
|
-
exports.storageEditBlockedReason = storageEditBlockedReason;
|
|
8
|
-
exports.storageValueToEditableText = storageValueToEditableText;
|
|
9
|
-
exports.structuredStorageValue = structuredStorageValue;
|
|
10
|
-
exports.validateStorageValue = validateStorageValue;
|
|
11
|
-
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
12
|
-
var _SecureStoreRegistry = require("./SecureStoreRegistry");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
/**
|
|
15
|
-
* Writing a storage value back, in one place.
|
|
16
|
-
*
|
|
17
|
-
* The counterpart to `deleteStorageKeys` — and the same reasoning applies: each
|
|
18
|
-
* backend writes differently, and a second copy of that fan-out is how one
|
|
19
|
-
* backend quietly starts corrupting values.
|
|
20
|
-
*
|
|
21
|
-
* The hard part is NOT the write, it's the types:
|
|
22
|
-
*
|
|
23
|
-
* - **AsyncStorage** stores strings only. A value that was stored as JSON must
|
|
24
|
-
* stay valid JSON, or an object silently becomes a quoted string and the app
|
|
25
|
-
* that reads it breaks in a way that looks nothing like a devtools edit.
|
|
26
|
-
* - **MMKV** is natively typed (string / number / boolean / buffer). Writing
|
|
27
|
-
* `"42"` over a number turns it into a string, so the original type is
|
|
28
|
-
* restored from `valueType`. Buffers can't round-trip at all — the snapshot
|
|
29
|
-
* only ever carried a `<ArrayBuffer n bytes>` placeholder.
|
|
30
|
-
* - **SecureStore** stores strings, and biometric-protected keys are never
|
|
31
|
-
* touched (writing needs the same auth prompt reading does).
|
|
32
|
-
*
|
|
33
|
-
* Pro gating and confirmation are deliberately NOT here; they belong to the UI
|
|
34
|
-
* that has the user's attention. This assumes the caller already asked.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Why a key can't be edited, or null when it can. UI uses this both to hide the
|
|
39
|
-
* edit affordance and to explain itself, rather than failing at save time.
|
|
40
|
-
*/
|
|
41
|
-
function storageEditBlockedReason(storageKey, mmkvInstances = []) {
|
|
42
|
-
if (storageKey.storageType === "mmkv") {
|
|
43
|
-
if (storageKey.valueType === "buffer") {
|
|
44
|
-
return "Buffer values can't be edited — the tool only ever sees their byte length, not their contents.";
|
|
45
|
-
}
|
|
46
|
-
const instance = mmkvInstances.find(i => i.id === (storageKey.instanceId || "default"));
|
|
47
|
-
if (instance?.readOnly) {
|
|
48
|
-
return `MMKV instance "${instance.id}" is registered read-only.`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (storageKey.storageType === "secure") {
|
|
52
|
-
const entry = _SecureStoreRegistry.secureStoreRegistry.getAll().find(e => e.key === storageKey.key);
|
|
53
|
-
if (entry?.options.requireAuthentication) {
|
|
54
|
-
return "Biometric-protected keys can't be edited — writing one would fire an auth prompt.";
|
|
55
|
-
}
|
|
56
|
-
if (!_SecureStoreRegistry.secureStoreRegistry.getModule()) {
|
|
57
|
-
return "No SecureStore module is registered.";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Validate `raw` for this key WITHOUT writing. Returns an error message, or
|
|
65
|
-
* null when the text is acceptable. The editor calls this as you type.
|
|
66
|
-
*/
|
|
67
|
-
function validateStorageValue(storageKey, raw) {
|
|
68
|
-
if (storageKey.storageType === "mmkv") {
|
|
69
|
-
const type = mmkvTargetType(storageKey);
|
|
70
|
-
if (type === "number") {
|
|
71
|
-
if (raw.trim() === "" || Number.isNaN(Number(raw))) {
|
|
72
|
-
return "Must be a number — this MMKV key is stored as a number.";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (type === "boolean") {
|
|
76
|
-
const t = raw.trim().toLowerCase();
|
|
77
|
-
if (t !== "true" && t !== "false") {
|
|
78
|
-
return 'Must be "true" or "false" — this MMKV key is stored as a boolean.';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// AsyncStorage + SecureStore are string-valued. Only guard the case where
|
|
85
|
-
// the CURRENT value is structured: silently flattening an object into a
|
|
86
|
-
// string is the corruption worth preventing. A plain string stays free-form.
|
|
87
|
-
if (isStructured(storageKey.value)) {
|
|
88
|
-
try {
|
|
89
|
-
JSON.parse(raw);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return `This key holds JSON — ${e instanceof Error ? e.message : "invalid JSON"}`;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The text an editor should open with: JSON pretty-printed so it's actually
|
|
99
|
-
* editable, everything else verbatim.
|
|
100
|
-
*/
|
|
101
|
-
function storageValueToEditableText(value) {
|
|
102
|
-
if (value === undefined || value === null) return "";
|
|
103
|
-
if (typeof value === "string") {
|
|
104
|
-
// Values arrive already parsed when they were JSON, so a string here is a
|
|
105
|
-
// real string — except AsyncStorage hands back raw JSON text sometimes.
|
|
106
|
-
const trimmed = value.trim();
|
|
107
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
108
|
-
try {
|
|
109
|
-
return JSON.stringify(JSON.parse(value), null, 2);
|
|
110
|
-
} catch {
|
|
111
|
-
return value;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
if (typeof value === "object") return JSON.stringify(value, null, 2);
|
|
117
|
-
return String(value);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The value as a STRUCTURE, for the tree editor to apply ops against.
|
|
122
|
-
*
|
|
123
|
-
* Backends disagree on how far they've already parsed: `useAsyncStorageKeys`
|
|
124
|
-
* hands back a parsed object, while MMKV reports its native type so a JSON blob
|
|
125
|
-
* arrives as the raw string. Both have to end up as the same thing before an op
|
|
126
|
-
* can address a path inside them.
|
|
127
|
-
*
|
|
128
|
-
* Returns `undefined` when the value isn't a container — scalars are edited
|
|
129
|
-
* through the plain value editor, not the tree.
|
|
130
|
-
*/
|
|
131
|
-
function structuredStorageValue(storageKey) {
|
|
132
|
-
const {
|
|
133
|
-
value
|
|
134
|
-
} = storageKey;
|
|
135
|
-
if (value !== null && typeof value === "object") return value;
|
|
136
|
-
if (typeof value === "string") {
|
|
137
|
-
const trimmed = value.trim();
|
|
138
|
-
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return undefined;
|
|
139
|
-
try {
|
|
140
|
-
const parsed = JSON.parse(value);
|
|
141
|
-
return parsed !== null && typeof parsed === "object" ? parsed : undefined;
|
|
142
|
-
} catch {
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Write `raw` to whichever backend holds this key, restoring the value's
|
|
151
|
-
* original type. Rejects (rather than writing something lossy) when the key
|
|
152
|
-
* isn't editable or the text doesn't fit the type — callers surface that.
|
|
153
|
-
*/
|
|
154
|
-
async function setStorageValue(storageKey, raw, mmkvInstances = []) {
|
|
155
|
-
const blocked = storageEditBlockedReason(storageKey, mmkvInstances);
|
|
156
|
-
if (blocked) throw new Error(blocked);
|
|
157
|
-
const invalid = validateStorageValue(storageKey, raw);
|
|
158
|
-
if (invalid) throw new Error(invalid);
|
|
159
|
-
switch (storageKey.storageType) {
|
|
160
|
-
case "async":
|
|
161
|
-
{
|
|
162
|
-
await _asyncStorage.default.setItem(storageKey.key, normalizeJsonText(storageKey, raw));
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
case "secure":
|
|
166
|
-
{
|
|
167
|
-
await _SecureStoreRegistry.secureStoreRegistry.setValue(storageKey.key, normalizeJsonText(storageKey, raw));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
case "mmkv":
|
|
171
|
-
{
|
|
172
|
-
const instanceId = storageKey.instanceId || "default";
|
|
173
|
-
const target = mmkvInstances.find(i => i.id === instanceId);
|
|
174
|
-
if (!target) {
|
|
175
|
-
throw new Error(`MMKV instance "${instanceId}" is not registered.`);
|
|
176
|
-
}
|
|
177
|
-
target.instance.set(storageKey.key, coerceMMKV(storageKey, raw));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
default:
|
|
181
|
-
{
|
|
182
|
-
throw new Error(`Unsupported storage type "${String(storageKey.storageType)}"`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** True when the value is an object/array (so its text must stay valid JSON). */
|
|
188
|
-
function isStructured(value) {
|
|
189
|
-
return value !== null && typeof value === "object";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Re-serialize JSON so the stored string is compact and canonical, matching
|
|
194
|
-
* what the app itself would have written with `JSON.stringify`. Free-form
|
|
195
|
-
* strings pass through untouched.
|
|
196
|
-
*/
|
|
197
|
-
function normalizeJsonText(storageKey, raw) {
|
|
198
|
-
if (!isStructured(storageKey.value)) return raw;
|
|
199
|
-
return JSON.stringify(JSON.parse(raw));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** The MMKV native type to write back, defaulting to the current JS type. */
|
|
203
|
-
function mmkvTargetType(storageKey) {
|
|
204
|
-
if (storageKey.valueType) return storageKey.valueType;
|
|
205
|
-
if (typeof storageKey.value === "number") return "number";
|
|
206
|
-
if (typeof storageKey.value === "boolean") return "boolean";
|
|
207
|
-
return "string";
|
|
208
|
-
}
|
|
209
|
-
function coerceMMKV(storageKey, raw) {
|
|
210
|
-
switch (mmkvTargetType(storageKey)) {
|
|
211
|
-
case "number":
|
|
212
|
-
return Number(raw);
|
|
213
|
-
case "boolean":
|
|
214
|
-
return raw.trim().toLowerCase() === "true";
|
|
215
|
-
default:
|
|
216
|
-
return raw;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.setStorageValue=setStorageValue;exports.storageEditBlockedReason=storageEditBlockedReason;exports.storageValueToEditableText=storageValueToEditableText;exports.structuredStorageValue=structuredStorageValue;exports.validateStorageValue=validateStorageValue;var _asyncStorage=_interopRequireDefault(require("@react-native-async-storage/async-storage"));var _SecureStoreRegistry=require("./SecureStoreRegistry");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function storageEditBlockedReason(e,t=[]){if(e.storageType==="mmkv"){if(e.valueType==="buffer"){return"Buffer values can't be edited \u2014 the tool only ever sees their byte length, not their contents."}const r=t.find(n=>n.id===(e.instanceId||"default"));if(r?.readOnly){return`MMKV instance "${r.id}" is registered read-only.`}}if(e.storageType==="secure"){const r=_SecureStoreRegistry.secureStoreRegistry.getAll().find(n=>n.key===e.key);if(r?.options.requireAuthentication){return"Biometric-protected keys can't be edited \u2014 writing one would fire an auth prompt."}if(!_SecureStoreRegistry.secureStoreRegistry.getModule()){return"No SecureStore module is registered."}}return null}function validateStorageValue(e,t){if(e.storageType==="mmkv"){const r=mmkvTargetType(e);if(r==="number"){if(t.trim()===""||Number.isNaN(Number(t))){return"Must be a number \u2014 this MMKV key is stored as a number."}}if(r==="boolean"){const n=t.trim().toLowerCase();if(n!=="true"&&n!=="false"){return'Must be "true" or "false" \u2014 this MMKV key is stored as a boolean.'}}return null}if(isStructured(e.value)){try{JSON.parse(t)}catch(r){return`This key holds JSON \u2014 ${r instanceof Error?r.message:"invalid JSON"}`}}return null}function storageValueToEditableText(e){if(e===void 0||e===null)return"";if(typeof e==="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}return e}if(typeof e==="object")return JSON.stringify(e,null,2);return String(e)}function structuredStorageValue(e){const{value:t}=e;if(t!==null&&typeof t==="object")return t;if(typeof t==="string"){const r=t.trim();if(!r.startsWith("{")&&!r.startsWith("["))return void 0;try{const n=JSON.parse(t);return n!==null&&typeof n==="object"?n:void 0}catch{return void 0}}return void 0}async function setStorageValue(e,t,r=[]){const n=storageEditBlockedReason(e,r);if(n)throw new Error(n);const i=validateStorageValue(e,t);if(i)throw new Error(i);switch(e.storageType){case"async":{await _asyncStorage.default.setItem(e.key,normalizeJsonText(e,t));return}case"secure":{await _SecureStoreRegistry.secureStoreRegistry.setValue(e.key,normalizeJsonText(e,t));return}case"mmkv":{const u=e.instanceId||"default";const o=r.find(s=>s.id===u);if(!o){throw new Error(`MMKV instance "${u}" is not registered.`)}o.instance.set(e.key,coerceMMKV(e,t));return}default:{throw new Error(`Unsupported storage type "${String(e.storageType)}"`)}}}function isStructured(e){return e!==null&&typeof e==="object"}function normalizeJsonText(e,t){if(!isStructured(e.value))return t;return JSON.stringify(JSON.parse(t))}function mmkvTargetType(e){if(e.valueType)return e.valueType;if(typeof e.value==="number")return"number";if(typeof e.value==="boolean")return"boolean";return"string"}function coerceMMKV(e,t){switch(mmkvTargetType(e)){case"number":return Number(t);case"boolean":return t.trim().toLowerCase()==="true";default:return t}}
|