strata-storage 2.3.0 → 2.4.1
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/android/src/main/java/com/strata/storage/EncryptedStorage.java +84 -21
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +140 -58
- package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +66 -5
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +83 -10
- package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -1
- package/dist/adapters/web/MemoryAdapter.js +7 -1
- package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/web/SessionStorageAdapter.js +3 -2
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +84 -21
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +140 -58
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +66 -5
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +83 -10
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +4 -6
- package/dist/firebase.d.ts.map +1 -1
- package/dist/firebase.js +75 -13
- package/dist/ios/Plugin/SQLiteStorage.swift +100 -30
- package/dist/ios/Plugin/UserDefaultsStorage.swift +13 -2
- package/dist/package.json +5 -5
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +31 -6
- package/dist/plugin/web.d.ts +5 -1
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +55 -32
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -2
- package/ios/Plugin/SQLiteStorage.swift +100 -30
- package/ios/Plugin/UserDefaultsStorage.swift +13 -2
- package/package.json +17 -19
|
@@ -5,11 +5,13 @@ import android.database.Cursor;
|
|
|
5
5
|
import android.database.sqlite.SQLiteDatabase;
|
|
6
6
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
7
7
|
import android.content.ContentValues;
|
|
8
|
+
import android.util.Log;
|
|
8
9
|
import java.util.ArrayList;
|
|
9
10
|
import java.util.List;
|
|
10
11
|
import java.util.HashMap;
|
|
11
12
|
import java.util.Map;
|
|
12
13
|
import org.json.JSONObject;
|
|
14
|
+
import org.json.JSONArray;
|
|
13
15
|
import java.nio.charset.StandardCharsets;
|
|
14
16
|
|
|
15
17
|
public class SQLiteStorage extends SQLiteOpenHelper {
|
|
@@ -62,13 +64,22 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
62
64
|
valueBytes = ((String) value).getBytes(StandardCharsets.UTF_8);
|
|
63
65
|
} else {
|
|
64
66
|
// Convert complex objects to JSON then to bytes
|
|
65
|
-
String json
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
String json;
|
|
68
|
+
if (value instanceof JSONObject) {
|
|
69
|
+
json = ((JSONObject) value).toString();
|
|
70
|
+
} else {
|
|
71
|
+
// Use helper method to convert object to JSON string
|
|
72
|
+
try {
|
|
73
|
+
json = objectToJsonString(value);
|
|
74
|
+
} catch (Exception jsonEx) {
|
|
75
|
+
// Fallback to string representation
|
|
76
|
+
json = value.toString();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
68
79
|
valueBytes = json.getBytes(StandardCharsets.UTF_8);
|
|
69
80
|
}
|
|
70
81
|
} catch (Exception e) {
|
|
71
|
-
e
|
|
82
|
+
Log.e("StrataStorage", "Failed to set value in SQLite", e);
|
|
72
83
|
return false;
|
|
73
84
|
}
|
|
74
85
|
SQLiteDatabase db = this.getWritableDatabase();
|
|
@@ -102,36 +113,41 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
102
113
|
|
|
103
114
|
public Map<String, Object> get(String key) {
|
|
104
115
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
105
|
-
Cursor cursor =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
result =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
Cursor cursor = null;
|
|
117
|
+
try {
|
|
118
|
+
cursor = db.query(TABLE_NAME, null, KEY_ID + "=?",
|
|
119
|
+
new String[]{key}, null, null, null, null);
|
|
120
|
+
|
|
121
|
+
Map<String, Object> result = null;
|
|
122
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
123
|
+
result = new HashMap<>();
|
|
124
|
+
result.put("key", key);
|
|
125
|
+
result.put("value", cursor.getBlob(cursor.getColumnIndex(KEY_VALUE)));
|
|
126
|
+
result.put("created", cursor.getLong(cursor.getColumnIndex(KEY_CREATED)));
|
|
127
|
+
result.put("updated", cursor.getLong(cursor.getColumnIndex(KEY_UPDATED)));
|
|
128
|
+
|
|
129
|
+
int expiresIndex = cursor.getColumnIndex(KEY_EXPIRES);
|
|
130
|
+
if (!cursor.isNull(expiresIndex)) {
|
|
131
|
+
result.put("expires", cursor.getLong(expiresIndex));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
int tagsIndex = cursor.getColumnIndex(KEY_TAGS);
|
|
135
|
+
if (!cursor.isNull(tagsIndex)) {
|
|
136
|
+
result.put("tags", cursor.getString(tagsIndex));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
int metadataIndex = cursor.getColumnIndex(KEY_METADATA);
|
|
140
|
+
if (!cursor.isNull(metadataIndex)) {
|
|
141
|
+
result.put("metadata", cursor.getString(metadataIndex));
|
|
142
|
+
}
|
|
124
143
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
144
|
+
return result;
|
|
145
|
+
} finally {
|
|
146
|
+
if (cursor != null) {
|
|
147
|
+
cursor.close();
|
|
129
148
|
}
|
|
130
|
-
|
|
131
|
-
cursor.close();
|
|
149
|
+
db.close();
|
|
132
150
|
}
|
|
133
|
-
db.close();
|
|
134
|
-
return result;
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
public boolean remove(String key) {
|
|
@@ -169,52 +185,118 @@ public class SQLiteStorage extends SQLiteOpenHelper {
|
|
|
169
185
|
List<String> keys = new ArrayList<>();
|
|
170
186
|
String selectQuery;
|
|
171
187
|
String[] selectionArgs = null;
|
|
172
|
-
|
|
188
|
+
|
|
173
189
|
if (pattern != null) {
|
|
174
190
|
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME + " WHERE " + KEY_ID + " LIKE ?";
|
|
175
|
-
selectionArgs = new String[]{"%
|
|
191
|
+
selectionArgs = new String[]{"%" + pattern + "%"};
|
|
176
192
|
} else {
|
|
177
193
|
selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME;
|
|
178
194
|
}
|
|
179
|
-
|
|
195
|
+
|
|
180
196
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
181
|
-
Cursor cursor =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
Cursor cursor = null;
|
|
198
|
+
try {
|
|
199
|
+
cursor = db.rawQuery(selectQuery, selectionArgs);
|
|
200
|
+
|
|
201
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
202
|
+
do {
|
|
203
|
+
keys.add(cursor.getString(0));
|
|
204
|
+
} while (cursor.moveToNext());
|
|
205
|
+
}
|
|
206
|
+
return keys;
|
|
207
|
+
} finally {
|
|
208
|
+
if (cursor != null) {
|
|
209
|
+
cursor.close();
|
|
210
|
+
}
|
|
211
|
+
db.close();
|
|
187
212
|
}
|
|
188
|
-
cursor.close();
|
|
189
|
-
db.close();
|
|
190
|
-
return keys;
|
|
191
213
|
}
|
|
192
214
|
|
|
193
215
|
public boolean has(String key) {
|
|
194
216
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
195
|
-
Cursor cursor =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
Cursor cursor = null;
|
|
218
|
+
try {
|
|
219
|
+
cursor = db.query(TABLE_NAME, new String[]{KEY_ID}, KEY_ID + "=?",
|
|
220
|
+
new String[]{key}, null, null, null, null);
|
|
221
|
+
boolean exists = cursor != null && cursor.getCount() > 0;
|
|
222
|
+
return exists;
|
|
223
|
+
} finally {
|
|
224
|
+
if (cursor != null) {
|
|
225
|
+
cursor.close();
|
|
226
|
+
}
|
|
227
|
+
db.close();
|
|
228
|
+
}
|
|
201
229
|
}
|
|
202
230
|
|
|
203
231
|
public SizeInfo size() {
|
|
204
232
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
205
|
-
Cursor cursor =
|
|
233
|
+
Cursor cursor = null;
|
|
234
|
+
try {
|
|
235
|
+
cursor = db.rawQuery("SELECT COUNT(*), SUM(LENGTH(" + KEY_VALUE + ")) FROM " + TABLE_NAME, null);
|
|
236
|
+
|
|
237
|
+
long totalSize = 0;
|
|
238
|
+
int count = 0;
|
|
239
|
+
|
|
240
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
241
|
+
count = cursor.getInt(0);
|
|
242
|
+
// Check for NULL values from SQL SUM function
|
|
243
|
+
if (!cursor.isNull(1)) {
|
|
244
|
+
totalSize = cursor.getLong(1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return new SizeInfo(totalSize, count);
|
|
249
|
+
} finally {
|
|
250
|
+
if (cursor != null) {
|
|
251
|
+
cursor.close();
|
|
252
|
+
}
|
|
253
|
+
db.close();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Convert an object to JSON string using reflection
|
|
259
|
+
*/
|
|
260
|
+
private String objectToJsonString(Object obj) throws Exception {
|
|
261
|
+
if (obj == null) {
|
|
262
|
+
return "null";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) {
|
|
266
|
+
return obj.toString();
|
|
267
|
+
}
|
|
206
268
|
|
|
207
|
-
|
|
208
|
-
|
|
269
|
+
if (obj instanceof Map) {
|
|
270
|
+
JSONObject jsonObj = new JSONObject();
|
|
271
|
+
Map<?, ?> map = (Map<?, ?>) obj;
|
|
272
|
+
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
273
|
+
String key = entry.getKey().toString();
|
|
274
|
+
jsonObj.put(key, entry.getValue());
|
|
275
|
+
}
|
|
276
|
+
return jsonObj.toString();
|
|
277
|
+
}
|
|
209
278
|
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
279
|
+
if (obj instanceof List || obj.getClass().isArray()) {
|
|
280
|
+
JSONArray jsonArray = new JSONArray();
|
|
281
|
+
if (obj instanceof List) {
|
|
282
|
+
List<?> list = (List<?>) obj;
|
|
283
|
+
for (Object item : list) {
|
|
284
|
+
jsonArray.put(item);
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
Object[] array = (Object[]) obj;
|
|
288
|
+
for (Object item : array) {
|
|
289
|
+
jsonArray.put(item);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return jsonArray.toString();
|
|
214
293
|
}
|
|
215
294
|
|
|
216
|
-
|
|
217
|
-
|
|
295
|
+
// For other objects, create a simple JSON object with their string representation
|
|
296
|
+
JSONObject jsonObj = new JSONObject();
|
|
297
|
+
jsonObj.put("value", obj.toString());
|
|
298
|
+
jsonObj.put("type", obj.getClass().getSimpleName());
|
|
299
|
+
return jsonObj.toString();
|
|
218
300
|
}
|
|
219
301
|
|
|
220
302
|
/**
|
|
@@ -2,6 +2,7 @@ package com.strata.storage;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.content.SharedPreferences;
|
|
5
|
+
import android.util.Log;
|
|
5
6
|
import java.util.Map;
|
|
6
7
|
import java.util.Set;
|
|
7
8
|
import java.util.HashSet;
|
|
@@ -37,17 +38,32 @@ public class SharedPreferencesStorage {
|
|
|
37
38
|
} else if (value instanceof Boolean) {
|
|
38
39
|
editor.putBoolean(key, (Boolean) value);
|
|
39
40
|
} else if (value instanceof Set) {
|
|
40
|
-
|
|
41
|
+
// Safely convert to Set<String>
|
|
42
|
+
Set<?> rawSet = (Set<?>) value;
|
|
43
|
+
Set<String> stringSet = new HashSet<>();
|
|
44
|
+
for (Object item : rawSet) {
|
|
45
|
+
stringSet.add(item != null ? item.toString() : "null");
|
|
46
|
+
}
|
|
47
|
+
editor.putStringSet(key, stringSet);
|
|
41
48
|
} else {
|
|
42
49
|
// Convert complex objects to JSON
|
|
43
|
-
String json
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
String json;
|
|
51
|
+
if (value instanceof JSONObject) {
|
|
52
|
+
json = ((JSONObject) value).toString();
|
|
53
|
+
} else {
|
|
54
|
+
// Use reflection to convert object to JSON string
|
|
55
|
+
try {
|
|
56
|
+
json = objectToJsonString(value);
|
|
57
|
+
} catch (Exception e) {
|
|
58
|
+
// Fallback to string representation
|
|
59
|
+
json = value.toString();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
46
62
|
editor.putString(key, json);
|
|
47
63
|
}
|
|
48
64
|
return editor.commit();
|
|
49
65
|
} catch (Exception e) {
|
|
50
|
-
e
|
|
66
|
+
Log.e("StrataStorage", "Failed to set value in SharedPreferences", e);
|
|
51
67
|
return false;
|
|
52
68
|
}
|
|
53
69
|
}
|
|
@@ -133,6 +149,51 @@ public class SharedPreferencesStorage {
|
|
|
133
149
|
return new SizeInfo(totalSize, count);
|
|
134
150
|
}
|
|
135
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Convert an object to JSON string using reflection
|
|
154
|
+
*/
|
|
155
|
+
private String objectToJsonString(Object obj) throws Exception {
|
|
156
|
+
if (obj == null) {
|
|
157
|
+
return "null";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) {
|
|
161
|
+
return obj.toString();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (obj instanceof Map) {
|
|
165
|
+
JSONObject jsonObj = new JSONObject();
|
|
166
|
+
Map<?, ?> map = (Map<?, ?>) obj;
|
|
167
|
+
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
168
|
+
String key = entry.getKey().toString();
|
|
169
|
+
jsonObj.put(key, entry.getValue());
|
|
170
|
+
}
|
|
171
|
+
return jsonObj.toString();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (obj instanceof List || obj.getClass().isArray()) {
|
|
175
|
+
JSONArray jsonArray = new JSONArray();
|
|
176
|
+
if (obj instanceof List) {
|
|
177
|
+
List<?> list = (List<?>) obj;
|
|
178
|
+
for (Object item : list) {
|
|
179
|
+
jsonArray.put(item);
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
Object[] array = (Object[]) obj;
|
|
183
|
+
for (Object item : array) {
|
|
184
|
+
jsonArray.put(item);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return jsonArray.toString();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// For other objects, create a simple JSON object with their string representation
|
|
191
|
+
JSONObject jsonObj = new JSONObject();
|
|
192
|
+
jsonObj.put("value", obj.toString());
|
|
193
|
+
jsonObj.put("type", obj.getClass().getSimpleName());
|
|
194
|
+
return jsonObj.toString();
|
|
195
|
+
}
|
|
196
|
+
|
|
136
197
|
/**
|
|
137
198
|
* Size information class
|
|
138
199
|
*/
|
|
@@ -8,6 +8,7 @@ import com.getcapacitor.annotation.CapacitorPlugin;
|
|
|
8
8
|
import com.strata.storage.SharedPreferencesStorage;
|
|
9
9
|
import com.strata.storage.EncryptedStorage;
|
|
10
10
|
import com.strata.storage.SQLiteStorage;
|
|
11
|
+
import android.util.Log;
|
|
11
12
|
import org.json.JSONArray;
|
|
12
13
|
import org.json.JSONException;
|
|
13
14
|
import java.util.List;
|
|
@@ -30,7 +31,7 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
30
31
|
sqliteStorage = new SQLiteStorage(getContext());
|
|
31
32
|
} catch (Exception e) {
|
|
32
33
|
// Log error but don't crash - some storage types may not be available
|
|
33
|
-
e
|
|
34
|
+
Log.e("StrataStorage", "Failed to initialize storage", e);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -68,20 +69,32 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
68
69
|
|
|
69
70
|
try {
|
|
70
71
|
Object value = null;
|
|
71
|
-
|
|
72
|
+
|
|
72
73
|
switch (storage) {
|
|
73
74
|
case "secure":
|
|
75
|
+
if (encryptedStorage == null) {
|
|
76
|
+
call.reject("Encrypted storage not available");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
74
79
|
value = encryptedStorage.get(key);
|
|
75
80
|
break;
|
|
76
81
|
case "sqlite":
|
|
82
|
+
if (sqliteStorage == null) {
|
|
83
|
+
call.reject("SQLite storage not available");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
77
86
|
value = sqliteStorage.get(key);
|
|
78
87
|
break;
|
|
79
88
|
case "preferences":
|
|
80
89
|
default:
|
|
90
|
+
if (sharedPrefsStorage == null) {
|
|
91
|
+
call.reject("Preferences storage not available");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
81
94
|
value = sharedPrefsStorage.get(key);
|
|
82
95
|
break;
|
|
83
96
|
}
|
|
84
|
-
|
|
97
|
+
|
|
85
98
|
JSObject result = new JSObject();
|
|
86
99
|
result.put("value", value);
|
|
87
100
|
call.resolve(result);
|
|
@@ -107,17 +120,29 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
107
120
|
try {
|
|
108
121
|
switch (storage) {
|
|
109
122
|
case "secure":
|
|
123
|
+
if (encryptedStorage == null) {
|
|
124
|
+
call.reject("Encrypted storage not available");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
110
127
|
encryptedStorage.set(key, value);
|
|
111
128
|
break;
|
|
112
129
|
case "sqlite":
|
|
130
|
+
if (sqliteStorage == null) {
|
|
131
|
+
call.reject("SQLite storage not available");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
113
134
|
sqliteStorage.set(key, value);
|
|
114
135
|
break;
|
|
115
136
|
case "preferences":
|
|
116
137
|
default:
|
|
138
|
+
if (sharedPrefsStorage == null) {
|
|
139
|
+
call.reject("Preferences storage not available");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
117
142
|
sharedPrefsStorage.set(key, value);
|
|
118
143
|
break;
|
|
119
144
|
}
|
|
120
|
-
|
|
145
|
+
|
|
121
146
|
call.resolve();
|
|
122
147
|
} catch (Exception e) {
|
|
123
148
|
call.reject("Failed to set value", e);
|
|
@@ -140,17 +165,29 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
140
165
|
try {
|
|
141
166
|
switch (storage) {
|
|
142
167
|
case "secure":
|
|
168
|
+
if (encryptedStorage == null) {
|
|
169
|
+
call.reject("Encrypted storage not available");
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
143
172
|
encryptedStorage.remove(key);
|
|
144
173
|
break;
|
|
145
174
|
case "sqlite":
|
|
175
|
+
if (sqliteStorage == null) {
|
|
176
|
+
call.reject("SQLite storage not available");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
146
179
|
sqliteStorage.remove(key);
|
|
147
180
|
break;
|
|
148
181
|
case "preferences":
|
|
149
182
|
default:
|
|
183
|
+
if (sharedPrefsStorage == null) {
|
|
184
|
+
call.reject("Preferences storage not available");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
150
187
|
sharedPrefsStorage.remove(key);
|
|
151
188
|
break;
|
|
152
189
|
}
|
|
153
|
-
|
|
190
|
+
|
|
154
191
|
call.resolve();
|
|
155
192
|
} catch (Exception e) {
|
|
156
193
|
call.reject("Failed to remove value", e);
|
|
@@ -168,17 +205,29 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
168
205
|
try {
|
|
169
206
|
switch (storage) {
|
|
170
207
|
case "secure":
|
|
208
|
+
if (encryptedStorage == null) {
|
|
209
|
+
call.reject("Encrypted storage not available");
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
171
212
|
encryptedStorage.clear(prefix);
|
|
172
213
|
break;
|
|
173
214
|
case "sqlite":
|
|
215
|
+
if (sqliteStorage == null) {
|
|
216
|
+
call.reject("SQLite storage not available");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
174
219
|
sqliteStorage.clear(prefix);
|
|
175
220
|
break;
|
|
176
221
|
case "preferences":
|
|
177
222
|
default:
|
|
223
|
+
if (sharedPrefsStorage == null) {
|
|
224
|
+
call.reject("Preferences storage not available");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
178
227
|
sharedPrefsStorage.clear(prefix);
|
|
179
228
|
break;
|
|
180
229
|
}
|
|
181
|
-
|
|
230
|
+
|
|
182
231
|
call.resolve();
|
|
183
232
|
} catch (Exception e) {
|
|
184
233
|
call.reject("Failed to clear storage", e);
|
|
@@ -195,20 +244,32 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
195
244
|
|
|
196
245
|
try {
|
|
197
246
|
List<String> keys = null;
|
|
198
|
-
|
|
247
|
+
|
|
199
248
|
switch (storage) {
|
|
200
249
|
case "secure":
|
|
250
|
+
if (encryptedStorage == null) {
|
|
251
|
+
call.reject("Encrypted storage not available");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
201
254
|
keys = encryptedStorage.keys(pattern);
|
|
202
255
|
break;
|
|
203
256
|
case "sqlite":
|
|
257
|
+
if (sqliteStorage == null) {
|
|
258
|
+
call.reject("SQLite storage not available");
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
204
261
|
keys = sqliteStorage.keys(pattern);
|
|
205
262
|
break;
|
|
206
263
|
case "preferences":
|
|
207
264
|
default:
|
|
265
|
+
if (sharedPrefsStorage == null) {
|
|
266
|
+
call.reject("Preferences storage not available");
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
208
269
|
keys = sharedPrefsStorage.keys(pattern);
|
|
209
270
|
break;
|
|
210
271
|
}
|
|
211
|
-
|
|
272
|
+
|
|
212
273
|
JSObject result = new JSObject();
|
|
213
274
|
result.put("keys", new JSONArray(keys));
|
|
214
275
|
call.resolve(result);
|
|
@@ -226,26 +287,38 @@ public class StrataStoragePlugin extends Plugin {
|
|
|
226
287
|
|
|
227
288
|
try {
|
|
228
289
|
JSObject result = new JSObject();
|
|
229
|
-
|
|
290
|
+
|
|
230
291
|
switch (storage) {
|
|
231
292
|
case "secure":
|
|
293
|
+
if (encryptedStorage == null) {
|
|
294
|
+
call.reject("Encrypted storage not available");
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
232
297
|
EncryptedStorage.SizeInfo encryptedSizeInfo = encryptedStorage.size();
|
|
233
298
|
result.put("total", encryptedSizeInfo.total);
|
|
234
299
|
result.put("count", encryptedSizeInfo.count);
|
|
235
300
|
break;
|
|
236
301
|
case "sqlite":
|
|
302
|
+
if (sqliteStorage == null) {
|
|
303
|
+
call.reject("SQLite storage not available");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
237
306
|
SQLiteStorage.SizeInfo sqliteSizeInfo = sqliteStorage.size();
|
|
238
307
|
result.put("total", sqliteSizeInfo.total);
|
|
239
308
|
result.put("count", sqliteSizeInfo.count);
|
|
240
309
|
break;
|
|
241
310
|
case "preferences":
|
|
242
311
|
default:
|
|
312
|
+
if (sharedPrefsStorage == null) {
|
|
313
|
+
call.reject("Preferences storage not available");
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
243
316
|
SharedPreferencesStorage.SizeInfo prefsSizeInfo = sharedPrefsStorage.size();
|
|
244
317
|
result.put("total", prefsSizeInfo.total);
|
|
245
318
|
result.put("count", prefsSizeInfo.count);
|
|
246
319
|
break;
|
|
247
320
|
}
|
|
248
|
-
|
|
321
|
+
|
|
249
322
|
call.resolve(result);
|
|
250
323
|
} catch (Exception e) {
|
|
251
324
|
call.reject("Failed to get size", e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strata.d.ts","sourceRoot":"","sources":["../../src/core/Strata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAE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js";
|
|
6
|
-
import { isBrowser, isNode } from "../utils/index.js";
|
|
6
|
+
import { isBrowser, isNode, deepMerge } from "../utils/index.js";
|
|
7
7
|
import { StorageError, EncryptionError } from "../utils/errors.js";
|
|
8
8
|
import { EncryptionManager } from "../features/encryption.js";
|
|
9
9
|
import { CompressionManager } from "../features/compression.js";
|
|
@@ -474,11 +474,9 @@ export class Strata {
|
|
|
474
474
|
else if (options?.merge) {
|
|
475
475
|
const existing = await this.get(key);
|
|
476
476
|
if (options.merge === 'deep' && typeof existing === 'object' && typeof value === 'object') {
|
|
477
|
-
//
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
...value,
|
|
481
|
-
});
|
|
477
|
+
// Use deep merge utility for proper nested object merging
|
|
478
|
+
const merged = deepMerge(existing, value);
|
|
479
|
+
await this.set(key, merged);
|
|
482
480
|
}
|
|
483
481
|
else {
|
|
484
482
|
await this.set(key, value);
|
package/dist/firebase.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CAyOf;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5D"}
|