strata-storage 1.5.0 → 2.0.0
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 +66 -20
- package/dist/README.md +162 -0
- package/dist/adapters/capacitor/FilesystemAdapter.js +4 -4
- package/dist/adapters/capacitor/PreferencesAdapter.js +4 -4
- package/dist/adapters/capacitor/SecureAdapter.js +4 -4
- package/dist/adapters/capacitor/SqliteAdapter.js +4 -4
- package/dist/adapters/capacitor/index.js +4 -4
- package/dist/adapters/web/CacheAdapter.js +3 -3
- package/dist/adapters/web/CookieAdapter.js +2 -2
- package/dist/adapters/web/IndexedDBAdapter.js +3 -3
- package/dist/adapters/web/LocalStorageAdapter.js +3 -3
- package/dist/adapters/web/MemoryAdapter.js +3 -3
- package/dist/adapters/web/SessionStorageAdapter.js +1 -1
- package/dist/adapters/web/index.js +6 -6
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
- package/dist/capacitor.d.ts +20 -0
- package/dist/capacitor.d.ts.map +1 -0
- package/dist/capacitor.js +48 -0
- package/dist/core/AdapterRegistry.js +1 -1
- package/dist/core/BaseAdapter.js +3 -3
- package/dist/core/StorageStrategy.js +1 -0
- package/dist/core/Strata.d.ts +28 -3
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +57 -58
- package/dist/features/compression/index.d.ts +2 -0
- package/dist/features/compression/index.d.ts.map +1 -0
- package/dist/features/compression/index.js +1 -0
- package/dist/features/compression.js +1 -1
- package/dist/features/encryption/index.d.ts +2 -0
- package/dist/features/encryption/index.d.ts.map +1 -0
- package/dist/features/encryption/index.js +1 -0
- package/dist/features/encryption.d.ts.map +1 -1
- package/dist/features/encryption.js +6 -5
- package/dist/features/observer/index.d.ts +2 -0
- package/dist/features/observer/index.d.ts.map +1 -0
- package/dist/features/observer/index.js +1 -0
- package/dist/features/observer.d.ts +20 -0
- package/dist/features/observer.d.ts.map +1 -0
- package/dist/features/observer.js +32 -0
- package/dist/features/query/index.d.ts +2 -0
- package/dist/features/query/index.d.ts.map +1 -0
- package/dist/features/query/index.js +1 -0
- package/dist/features/query.d.ts.map +1 -1
- package/dist/features/query.js +8 -1
- package/dist/features/sync/index.d.ts +2 -0
- package/dist/features/sync/index.d.ts.map +1 -0
- package/dist/features/sync/index.js +1 -0
- package/dist/features/sync.js +1 -1
- package/dist/features/ttl/index.d.ts +2 -0
- package/dist/features/ttl/index.d.ts.map +1 -0
- package/dist/features/ttl/index.js +1 -0
- package/dist/features/ttl.js +1 -1
- package/dist/firebase.d.ts +26 -0
- package/dist/firebase.d.ts.map +1 -0
- package/dist/firebase.js +147 -0
- package/dist/index.d.ts +13 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -58
- package/dist/ios/Plugin/KeychainStorage.swift +87 -0
- package/dist/ios/Plugin/SQLiteStorage.swift +167 -0
- package/dist/ios/Plugin/StrataStoragePlugin.swift +204 -0
- package/dist/ios/Plugin/UserDefaultsStorage.swift +44 -0
- package/dist/package.json +22 -4
- package/dist/plugin/definitions.d.ts +2 -2
- package/dist/plugin/definitions.d.ts.map +1 -1
- package/dist/plugin/index.d.ts +2 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +77 -11
- package/dist/types/index.d.ts +190 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +13 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +34 -0
- package/package.json +15 -24
- package/scripts/build.js +127 -14
- package/scripts/cli.js +6 -2
- package/scripts/configure.js +7 -3
- package/scripts/postinstall.js +21 -10
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
package com.strata.storage;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.database.Cursor;
|
|
5
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
6
|
+
import android.database.sqlite.SQLiteOpenHelper;
|
|
7
|
+
import android.content.ContentValues;
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import java.util.HashMap;
|
|
11
|
+
import java.util.Map;
|
|
12
|
+
|
|
13
|
+
public class SQLiteStorage extends SQLiteOpenHelper {
|
|
14
|
+
private static final int DATABASE_VERSION = 1;
|
|
15
|
+
private static final String TABLE_NAME = "strata_storage";
|
|
16
|
+
|
|
17
|
+
private static final String KEY_ID = "key";
|
|
18
|
+
private static final String KEY_VALUE = "value";
|
|
19
|
+
private static final String KEY_CREATED = "created";
|
|
20
|
+
private static final String KEY_UPDATED = "updated";
|
|
21
|
+
private static final String KEY_EXPIRES = "expires";
|
|
22
|
+
private static final String KEY_TAGS = "tags";
|
|
23
|
+
private static final String KEY_METADATA = "metadata";
|
|
24
|
+
|
|
25
|
+
public SQLiteStorage(Context context, String dbName) {
|
|
26
|
+
super(context, dbName != null ? dbName : "strata.db", null, DATABASE_VERSION);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Override
|
|
30
|
+
public void onCreate(SQLiteDatabase db) {
|
|
31
|
+
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "("
|
|
32
|
+
+ KEY_ID + " TEXT PRIMARY KEY,"
|
|
33
|
+
+ KEY_VALUE + " BLOB NOT NULL,"
|
|
34
|
+
+ KEY_CREATED + " INTEGER NOT NULL,"
|
|
35
|
+
+ KEY_UPDATED + " INTEGER NOT NULL,"
|
|
36
|
+
+ KEY_EXPIRES + " INTEGER,"
|
|
37
|
+
+ KEY_TAGS + " TEXT,"
|
|
38
|
+
+ KEY_METADATA + " TEXT" + ")";
|
|
39
|
+
db.execSQL(CREATE_TABLE);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
44
|
+
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
|
45
|
+
onCreate(db);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public boolean set(String key, byte[] value, Long expires, String tags, String metadata) {
|
|
49
|
+
SQLiteDatabase db = this.getWritableDatabase();
|
|
50
|
+
ContentValues values = new ContentValues();
|
|
51
|
+
|
|
52
|
+
long now = System.currentTimeMillis();
|
|
53
|
+
values.put(KEY_ID, key);
|
|
54
|
+
values.put(KEY_VALUE, value);
|
|
55
|
+
values.put(KEY_CREATED, now);
|
|
56
|
+
values.put(KEY_UPDATED, now);
|
|
57
|
+
|
|
58
|
+
if (expires != null) {
|
|
59
|
+
values.put(KEY_EXPIRES, expires);
|
|
60
|
+
}
|
|
61
|
+
if (tags != null) {
|
|
62
|
+
values.put(KEY_TAGS, tags);
|
|
63
|
+
}
|
|
64
|
+
if (metadata != null) {
|
|
65
|
+
values.put(KEY_METADATA, metadata);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
long result = db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
|
69
|
+
db.close();
|
|
70
|
+
return result != -1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public Map<String, Object> get(String key) {
|
|
74
|
+
SQLiteDatabase db = this.getReadableDatabase();
|
|
75
|
+
Cursor cursor = db.query(TABLE_NAME, null, KEY_ID + "=?",
|
|
76
|
+
new String[]{key}, null, null, null, null);
|
|
77
|
+
|
|
78
|
+
Map<String, Object> result = null;
|
|
79
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
80
|
+
result = new HashMap<>();
|
|
81
|
+
result.put("key", key);
|
|
82
|
+
result.put("value", cursor.getBlob(cursor.getColumnIndex(KEY_VALUE)));
|
|
83
|
+
result.put("created", cursor.getLong(cursor.getColumnIndex(KEY_CREATED)));
|
|
84
|
+
result.put("updated", cursor.getLong(cursor.getColumnIndex(KEY_UPDATED)));
|
|
85
|
+
|
|
86
|
+
int expiresIndex = cursor.getColumnIndex(KEY_EXPIRES);
|
|
87
|
+
if (!cursor.isNull(expiresIndex)) {
|
|
88
|
+
result.put("expires", cursor.getLong(expiresIndex));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
int tagsIndex = cursor.getColumnIndex(KEY_TAGS);
|
|
92
|
+
if (!cursor.isNull(tagsIndex)) {
|
|
93
|
+
result.put("tags", cursor.getString(tagsIndex));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
int metadataIndex = cursor.getColumnIndex(KEY_METADATA);
|
|
97
|
+
if (!cursor.isNull(metadataIndex)) {
|
|
98
|
+
result.put("metadata", cursor.getString(metadataIndex));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
cursor.close();
|
|
102
|
+
}
|
|
103
|
+
db.close();
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public boolean remove(String key) {
|
|
108
|
+
SQLiteDatabase db = this.getWritableDatabase();
|
|
109
|
+
int result = db.delete(TABLE_NAME, KEY_ID + " = ?", new String[]{key});
|
|
110
|
+
db.close();
|
|
111
|
+
return result > 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public boolean clear() {
|
|
115
|
+
SQLiteDatabase db = this.getWritableDatabase();
|
|
116
|
+
db.delete(TABLE_NAME, null, null);
|
|
117
|
+
db.close();
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public List<String> keys() {
|
|
122
|
+
List<String> keys = new ArrayList<>();
|
|
123
|
+
String selectQuery = "SELECT " + KEY_ID + " FROM " + TABLE_NAME;
|
|
124
|
+
|
|
125
|
+
SQLiteDatabase db = this.getReadableDatabase();
|
|
126
|
+
Cursor cursor = db.rawQuery(selectQuery, null);
|
|
127
|
+
|
|
128
|
+
if (cursor.moveToFirst()) {
|
|
129
|
+
do {
|
|
130
|
+
keys.add(cursor.getString(0));
|
|
131
|
+
} while (cursor.moveToNext());
|
|
132
|
+
}
|
|
133
|
+
cursor.close();
|
|
134
|
+
db.close();
|
|
135
|
+
return keys;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public boolean has(String key) {
|
|
139
|
+
SQLiteDatabase db = this.getReadableDatabase();
|
|
140
|
+
Cursor cursor = db.query(TABLE_NAME, new String[]{KEY_ID}, KEY_ID + "=?",
|
|
141
|
+
new String[]{key}, null, null, null, null);
|
|
142
|
+
boolean exists = cursor.getCount() > 0;
|
|
143
|
+
cursor.close();
|
|
144
|
+
db.close();
|
|
145
|
+
return exists;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
package com.strata.storage;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.content.SharedPreferences;
|
|
5
|
+
import java.util.Map;
|
|
6
|
+
import java.util.Set;
|
|
7
|
+
import java.util.HashSet;
|
|
8
|
+
import org.json.JSONObject;
|
|
9
|
+
import org.json.JSONArray;
|
|
10
|
+
|
|
11
|
+
public class SharedPreferencesStorage {
|
|
12
|
+
private final SharedPreferences prefs;
|
|
13
|
+
private final SharedPreferences.Editor editor;
|
|
14
|
+
|
|
15
|
+
public SharedPreferencesStorage(Context context, String name) {
|
|
16
|
+
this.prefs = context.getSharedPreferences(name != null ? name : "StrataStorage", Context.MODE_PRIVATE);
|
|
17
|
+
this.editor = prefs.edit();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public boolean set(String key, Object value) {
|
|
21
|
+
try {
|
|
22
|
+
if (value instanceof String) {
|
|
23
|
+
editor.putString(key, (String) value);
|
|
24
|
+
} else if (value instanceof Integer) {
|
|
25
|
+
editor.putInt(key, (Integer) value);
|
|
26
|
+
} else if (value instanceof Long) {
|
|
27
|
+
editor.putLong(key, (Long) value);
|
|
28
|
+
} else if (value instanceof Float) {
|
|
29
|
+
editor.putFloat(key, (Float) value);
|
|
30
|
+
} else if (value instanceof Boolean) {
|
|
31
|
+
editor.putBoolean(key, (Boolean) value);
|
|
32
|
+
} else if (value instanceof Set) {
|
|
33
|
+
editor.putStringSet(key, (Set<String>) value);
|
|
34
|
+
} else {
|
|
35
|
+
// Convert complex objects to JSON
|
|
36
|
+
String json = value instanceof JSONObject ?
|
|
37
|
+
((JSONObject) value).toString() :
|
|
38
|
+
new JSONObject(value).toString();
|
|
39
|
+
editor.putString(key, json);
|
|
40
|
+
}
|
|
41
|
+
return editor.commit();
|
|
42
|
+
} catch (Exception e) {
|
|
43
|
+
e.printStackTrace();
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public Object get(String key) {
|
|
49
|
+
Map<String, ?> all = prefs.getAll();
|
|
50
|
+
return all.get(key);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public boolean remove(String key) {
|
|
54
|
+
editor.remove(key);
|
|
55
|
+
return editor.commit();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public boolean clear() {
|
|
59
|
+
editor.clear();
|
|
60
|
+
return editor.commit();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public Set<String> keys() {
|
|
64
|
+
return prefs.getAll().keySet();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public boolean has(String key) {
|
|
68
|
+
return prefs.contains(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public Map<String, ?> getAll() {
|
|
72
|
+
return prefs.getAll();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
package com.stratastorage;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
import com.getcapacitor.Plugin;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.getcapacitor.PluginMethod;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
import org.json.JSONArray;
|
|
9
|
+
import org.json.JSONException;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Main Capacitor plugin for Strata Storage
|
|
14
|
+
* Coordinates between different storage types on Android
|
|
15
|
+
*/
|
|
16
|
+
@CapacitorPlugin(name = "StrataStorage")
|
|
17
|
+
public class StrataStoragePlugin extends Plugin {
|
|
18
|
+
private SharedPreferencesStorage sharedPrefsStorage;
|
|
19
|
+
private EncryptedStorage encryptedStorage;
|
|
20
|
+
private SQLiteStorage sqliteStorage;
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public void load() {
|
|
24
|
+
sharedPrefsStorage = new SharedPreferencesStorage(getContext());
|
|
25
|
+
encryptedStorage = new EncryptedStorage(getContext());
|
|
26
|
+
sqliteStorage = new SQLiteStorage(getContext());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if storage is available
|
|
31
|
+
*/
|
|
32
|
+
@PluginMethod
|
|
33
|
+
public void isAvailable(PluginCall call) {
|
|
34
|
+
JSObject result = new JSObject();
|
|
35
|
+
result.put("available", true);
|
|
36
|
+
result.put("platform", "android");
|
|
37
|
+
|
|
38
|
+
JSObject adapters = new JSObject();
|
|
39
|
+
adapters.put("preferences", true);
|
|
40
|
+
adapters.put("secure", true);
|
|
41
|
+
adapters.put("sqlite", true);
|
|
42
|
+
adapters.put("filesystem", true);
|
|
43
|
+
result.put("adapters", adapters);
|
|
44
|
+
|
|
45
|
+
call.resolve(result);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get value from storage
|
|
50
|
+
*/
|
|
51
|
+
@PluginMethod
|
|
52
|
+
public void get(PluginCall call) {
|
|
53
|
+
String key = call.getString("key");
|
|
54
|
+
if (key == null) {
|
|
55
|
+
call.reject("Key is required");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
String storage = call.getString("storage", "preferences");
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
Object value = null;
|
|
63
|
+
|
|
64
|
+
switch (storage) {
|
|
65
|
+
case "secure":
|
|
66
|
+
value = encryptedStorage.get(key);
|
|
67
|
+
break;
|
|
68
|
+
case "sqlite":
|
|
69
|
+
value = sqliteStorage.get(key);
|
|
70
|
+
break;
|
|
71
|
+
case "preferences":
|
|
72
|
+
default:
|
|
73
|
+
value = sharedPrefsStorage.get(key);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
JSObject result = new JSObject();
|
|
78
|
+
result.put("value", value);
|
|
79
|
+
call.resolve(result);
|
|
80
|
+
} catch (Exception e) {
|
|
81
|
+
call.reject("Failed to get value", e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Set value in storage
|
|
87
|
+
*/
|
|
88
|
+
@PluginMethod
|
|
89
|
+
public void set(PluginCall call) {
|
|
90
|
+
String key = call.getString("key");
|
|
91
|
+
if (key == null) {
|
|
92
|
+
call.reject("Key is required");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Object value = call.getData().opt("value");
|
|
97
|
+
String storage = call.getString("storage", "preferences");
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
switch (storage) {
|
|
101
|
+
case "secure":
|
|
102
|
+
encryptedStorage.set(key, value);
|
|
103
|
+
break;
|
|
104
|
+
case "sqlite":
|
|
105
|
+
sqliteStorage.set(key, value);
|
|
106
|
+
break;
|
|
107
|
+
case "preferences":
|
|
108
|
+
default:
|
|
109
|
+
sharedPrefsStorage.set(key, value);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
call.resolve();
|
|
114
|
+
} catch (Exception e) {
|
|
115
|
+
call.reject("Failed to set value", e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Remove value from storage
|
|
121
|
+
*/
|
|
122
|
+
@PluginMethod
|
|
123
|
+
public void remove(PluginCall call) {
|
|
124
|
+
String key = call.getString("key");
|
|
125
|
+
if (key == null) {
|
|
126
|
+
call.reject("Key is required");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
String storage = call.getString("storage", "preferences");
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
switch (storage) {
|
|
134
|
+
case "secure":
|
|
135
|
+
encryptedStorage.remove(key);
|
|
136
|
+
break;
|
|
137
|
+
case "sqlite":
|
|
138
|
+
sqliteStorage.remove(key);
|
|
139
|
+
break;
|
|
140
|
+
case "preferences":
|
|
141
|
+
default:
|
|
142
|
+
sharedPrefsStorage.remove(key);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
call.resolve();
|
|
147
|
+
} catch (Exception e) {
|
|
148
|
+
call.reject("Failed to remove value", e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Clear storage
|
|
154
|
+
*/
|
|
155
|
+
@PluginMethod
|
|
156
|
+
public void clear(PluginCall call) {
|
|
157
|
+
String storage = call.getString("storage", "preferences");
|
|
158
|
+
String prefix = call.getString("prefix");
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
switch (storage) {
|
|
162
|
+
case "secure":
|
|
163
|
+
encryptedStorage.clear(prefix);
|
|
164
|
+
break;
|
|
165
|
+
case "sqlite":
|
|
166
|
+
sqliteStorage.clear(prefix);
|
|
167
|
+
break;
|
|
168
|
+
case "preferences":
|
|
169
|
+
default:
|
|
170
|
+
sharedPrefsStorage.clear(prefix);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
call.resolve();
|
|
175
|
+
} catch (Exception e) {
|
|
176
|
+
call.reject("Failed to clear storage", e);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get all keys from storage
|
|
182
|
+
*/
|
|
183
|
+
@PluginMethod
|
|
184
|
+
public void keys(PluginCall call) {
|
|
185
|
+
String storage = call.getString("storage", "preferences");
|
|
186
|
+
String pattern = call.getString("pattern");
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
List<String> keys = null;
|
|
190
|
+
|
|
191
|
+
switch (storage) {
|
|
192
|
+
case "secure":
|
|
193
|
+
keys = encryptedStorage.keys(pattern);
|
|
194
|
+
break;
|
|
195
|
+
case "sqlite":
|
|
196
|
+
keys = sqliteStorage.keys(pattern);
|
|
197
|
+
break;
|
|
198
|
+
case "preferences":
|
|
199
|
+
default:
|
|
200
|
+
keys = sharedPrefsStorage.keys(pattern);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
JSObject result = new JSObject();
|
|
205
|
+
result.put("keys", new JSONArray(keys));
|
|
206
|
+
call.resolve(result);
|
|
207
|
+
} catch (Exception e) {
|
|
208
|
+
call.reject("Failed to get keys", e);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get storage size information
|
|
214
|
+
*/
|
|
215
|
+
@PluginMethod
|
|
216
|
+
public void size(PluginCall call) {
|
|
217
|
+
String storage = call.getString("storage", "preferences");
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
SizeInfo sizeInfo = null;
|
|
221
|
+
|
|
222
|
+
switch (storage) {
|
|
223
|
+
case "secure":
|
|
224
|
+
sizeInfo = encryptedStorage.size();
|
|
225
|
+
break;
|
|
226
|
+
case "sqlite":
|
|
227
|
+
sizeInfo = sqliteStorage.size();
|
|
228
|
+
break;
|
|
229
|
+
case "preferences":
|
|
230
|
+
default:
|
|
231
|
+
sizeInfo = sharedPrefsStorage.size();
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
JSObject result = new JSObject();
|
|
236
|
+
result.put("total", sizeInfo.total);
|
|
237
|
+
result.put("count", sizeInfo.count);
|
|
238
|
+
call.resolve(result);
|
|
239
|
+
} catch (Exception e) {
|
|
240
|
+
call.reject("Failed to get size", e);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Size information class
|
|
246
|
+
*/
|
|
247
|
+
static class SizeInfo {
|
|
248
|
+
public final long total;
|
|
249
|
+
public final int count;
|
|
250
|
+
|
|
251
|
+
public SizeInfo(long total, int count) {
|
|
252
|
+
this.total = total;
|
|
253
|
+
this.count = count;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Strata } from './core/Strata';
|
|
2
|
+
export { PreferencesAdapter } from './adapters/capacitor/PreferencesAdapter';
|
|
3
|
+
export { SqliteAdapter } from './adapters/capacitor/SqliteAdapter';
|
|
4
|
+
export { SecureAdapter } from './adapters/capacitor/SecureAdapter';
|
|
5
|
+
export { FilesystemAdapter } from './adapters/capacitor/FilesystemAdapter';
|
|
6
|
+
export { StrataStorage } from './plugin';
|
|
7
|
+
/**
|
|
8
|
+
* Register Capacitor adapters with a Strata instance
|
|
9
|
+
* This is completely optional and only needed for Capacitor apps
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerCapacitorAdapters(storage: Strata): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Helper to check if running in Capacitor environment
|
|
14
|
+
*/
|
|
15
|
+
export declare function isCapacitorEnvironment(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get Capacitor-specific storage types
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCapacitorStorageTypes(): string[];
|
|
20
|
+
//# sourceMappingURL=capacitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../src/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAO5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB9E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAMhD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PreferencesAdapter } from "./adapters/capacitor/PreferencesAdapter.js";
|
|
2
|
+
import { SqliteAdapter } from "./adapters/capacitor/SqliteAdapter.js";
|
|
3
|
+
import { SecureAdapter } from "./adapters/capacitor/SecureAdapter.js";
|
|
4
|
+
import { FilesystemAdapter } from "./adapters/capacitor/FilesystemAdapter.js";
|
|
5
|
+
// Export Capacitor adapters
|
|
6
|
+
export { PreferencesAdapter } from "./adapters/capacitor/PreferencesAdapter.js";
|
|
7
|
+
export { SqliteAdapter } from "./adapters/capacitor/SqliteAdapter.js";
|
|
8
|
+
export { SecureAdapter } from "./adapters/capacitor/SecureAdapter.js";
|
|
9
|
+
export { FilesystemAdapter } from "./adapters/capacitor/FilesystemAdapter.js";
|
|
10
|
+
// Export the plugin for direct access if needed
|
|
11
|
+
export { StrataStorage } from "./plugin/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Register Capacitor adapters with a Strata instance
|
|
14
|
+
* This is completely optional and only needed for Capacitor apps
|
|
15
|
+
*/
|
|
16
|
+
export async function registerCapacitorAdapters(storage) {
|
|
17
|
+
// Check if Capacitor is available
|
|
18
|
+
const hasCapacitor = typeof window !== 'undefined' &&
|
|
19
|
+
window.Capacitor &&
|
|
20
|
+
window.Capacitor.isNativePlatform();
|
|
21
|
+
if (!hasCapacitor) {
|
|
22
|
+
console.warn('Capacitor not detected. Capacitor adapters will not be registered.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Register Capacitor adapters
|
|
26
|
+
storage.registerAdapter(new PreferencesAdapter());
|
|
27
|
+
storage.registerAdapter(new SqliteAdapter());
|
|
28
|
+
storage.registerAdapter(new SecureAdapter());
|
|
29
|
+
storage.registerAdapter(new FilesystemAdapter());
|
|
30
|
+
// Re-initialize to make new adapters available
|
|
31
|
+
if (storage.isInitialized) {
|
|
32
|
+
await storage.initialize();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Helper to check if running in Capacitor environment
|
|
37
|
+
*/
|
|
38
|
+
export function isCapacitorEnvironment() {
|
|
39
|
+
return (typeof window !== 'undefined' &&
|
|
40
|
+
window.Capacitor &&
|
|
41
|
+
window.Capacitor.isNativePlatform());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get Capacitor-specific storage types
|
|
45
|
+
*/
|
|
46
|
+
export function getCapacitorStorageTypes() {
|
|
47
|
+
return ['preferences', 'sqlite', 'secure', 'filesystem'];
|
|
48
|
+
}
|
package/dist/core/BaseAdapter.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base adapter implementation with common functionality
|
|
3
3
|
*/
|
|
4
|
-
import { NotSupportedError } from
|
|
5
|
-
import { EventEmitter, matchGlob, getObjectSize } from
|
|
6
|
-
import { QueryEngine } from
|
|
4
|
+
import { NotSupportedError } from "../utils/errors.js";
|
|
5
|
+
import { EventEmitter, matchGlob, getObjectSize } from "../utils/index.js";
|
|
6
|
+
import { QueryEngine } from "../features/query.js";
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base adapter that implements common functionality
|
|
9
9
|
*/
|
package/dist/core/Strata.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Strata Storage - Main entry point
|
|
3
3
|
* Zero-dependency universal storage solution
|
|
4
4
|
*/
|
|
5
|
-
import type { StrataConfig, StorageOptions, StorageType, SizeInfo, ClearOptions, ExportOptions, ImportOptions, SubscriptionCallback, UnsubscribeFunction, QueryCondition, StorageCapabilities } from '@/types';
|
|
5
|
+
import type { StrataConfig, StorageAdapter, StorageOptions, StorageType, Platform, SizeInfo, ClearOptions, ExportOptions, ImportOptions, SubscriptionCallback, UnsubscribeFunction, QueryCondition, StorageCapabilities } from '@/types';
|
|
6
|
+
import { AdapterRegistry } from './AdapterRegistry';
|
|
6
7
|
/**
|
|
7
8
|
* Main Strata class - unified storage interface
|
|
8
9
|
*/
|
|
@@ -11,12 +12,21 @@ export declare class Strata {
|
|
|
11
12
|
private registry;
|
|
12
13
|
private defaultAdapter?;
|
|
13
14
|
private adapters;
|
|
14
|
-
private
|
|
15
|
+
private readonly _platform;
|
|
15
16
|
private encryptionManager?;
|
|
16
17
|
private compressionManager?;
|
|
17
18
|
private syncManager?;
|
|
18
19
|
private ttlManager?;
|
|
20
|
+
private _initialized;
|
|
19
21
|
constructor(config?: StrataConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Check if Strata has been initialized
|
|
24
|
+
*/
|
|
25
|
+
get isInitialized(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Get the detected platform
|
|
28
|
+
*/
|
|
29
|
+
get platform(): Platform;
|
|
20
30
|
/**
|
|
21
31
|
* Initialize Strata with available adapters
|
|
22
32
|
*/
|
|
@@ -107,6 +117,22 @@ export declare class Strata {
|
|
|
107
117
|
* Manually trigger TTL cleanup
|
|
108
118
|
*/
|
|
109
119
|
cleanupExpired(options?: StorageOptions): Promise<number>;
|
|
120
|
+
/**
|
|
121
|
+
* Register a custom storage adapter
|
|
122
|
+
* This allows external adapters to be registered after initialization
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { MyCustomAdapter } from './my-adapter';
|
|
127
|
+
* storage.registerAdapter(new MyCustomAdapter());
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
registerAdapter(adapter: StorageAdapter): void;
|
|
131
|
+
/**
|
|
132
|
+
* Get the adapter registry (for advanced use cases)
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
getRegistry(): AdapterRegistry;
|
|
110
136
|
/**
|
|
111
137
|
* Close all adapters
|
|
112
138
|
*/
|
|
@@ -114,7 +140,6 @@ export declare class Strata {
|
|
|
114
140
|
private normalizeConfig;
|
|
115
141
|
private detectPlatform;
|
|
116
142
|
private getDefaultStorages;
|
|
117
|
-
private registerAdapters;
|
|
118
143
|
private selectDefaultAdapter;
|
|
119
144
|
private initializeAdapters;
|
|
120
145
|
private selectAdapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strata.d.ts","sourceRoot":"","sources":["../../src/core/Strata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,YAAY,
|
|
1
|
+
{"version":3,"file":"Strata.d.ts","sourceRoot":"","sources":["../../src/core/Strata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,iBAAiB,CAAC,CAAoB;IAC9C,OAAO,CAAC,kBAAkB,CAAC,CAAqB;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