strata-storage 1.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.
Files changed (102) hide show
  1. package/Readme.md +113 -0
  2. package/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
  3. package/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
  4. package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
  5. package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
  6. package/dist/adapters/capacitor/FilesystemAdapter.d.ts +46 -0
  7. package/dist/adapters/capacitor/FilesystemAdapter.d.ts.map +1 -0
  8. package/dist/adapters/capacitor/FilesystemAdapter.js +162 -0
  9. package/dist/adapters/capacitor/PreferencesAdapter.d.ts +46 -0
  10. package/dist/adapters/capacitor/PreferencesAdapter.d.ts.map +1 -0
  11. package/dist/adapters/capacitor/PreferencesAdapter.js +162 -0
  12. package/dist/adapters/capacitor/SecureAdapter.d.ts +69 -0
  13. package/dist/adapters/capacitor/SecureAdapter.d.ts.map +1 -0
  14. package/dist/adapters/capacitor/SecureAdapter.js +214 -0
  15. package/dist/adapters/capacitor/SqliteAdapter.d.ts +68 -0
  16. package/dist/adapters/capacitor/SqliteAdapter.d.ts.map +1 -0
  17. package/dist/adapters/capacitor/SqliteAdapter.js +277 -0
  18. package/dist/adapters/capacitor/index.d.ts +9 -0
  19. package/dist/adapters/capacitor/index.d.ts.map +1 -0
  20. package/dist/adapters/capacitor/index.js +8 -0
  21. package/dist/adapters/web/CacheAdapter.d.ts +91 -0
  22. package/dist/adapters/web/CacheAdapter.d.ts.map +1 -0
  23. package/dist/adapters/web/CacheAdapter.js +291 -0
  24. package/dist/adapters/web/CookieAdapter.d.ts +77 -0
  25. package/dist/adapters/web/CookieAdapter.d.ts.map +1 -0
  26. package/dist/adapters/web/CookieAdapter.js +260 -0
  27. package/dist/adapters/web/IndexedDBAdapter.d.ts +78 -0
  28. package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -0
  29. package/dist/adapters/web/IndexedDBAdapter.js +371 -0
  30. package/dist/adapters/web/LocalStorageAdapter.d.ts +63 -0
  31. package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -0
  32. package/dist/adapters/web/LocalStorageAdapter.js +238 -0
  33. package/dist/adapters/web/MemoryAdapter.d.ts +69 -0
  34. package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -0
  35. package/dist/adapters/web/MemoryAdapter.js +165 -0
  36. package/dist/adapters/web/SessionStorageAdapter.d.ts +53 -0
  37. package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -0
  38. package/dist/adapters/web/SessionStorageAdapter.js +180 -0
  39. package/dist/adapters/web/index.d.ts +10 -0
  40. package/dist/adapters/web/index.d.ts.map +1 -0
  41. package/dist/adapters/web/index.js +9 -0
  42. package/dist/core/AdapterRegistry.d.ts +52 -0
  43. package/dist/core/AdapterRegistry.d.ts.map +1 -0
  44. package/dist/core/AdapterRegistry.js +102 -0
  45. package/dist/core/BaseAdapter.d.ts +79 -0
  46. package/dist/core/BaseAdapter.d.ts.map +1 -0
  47. package/dist/core/BaseAdapter.js +197 -0
  48. package/dist/core/StorageStrategy.d.ts +55 -0
  49. package/dist/core/StorageStrategy.d.ts.map +1 -0
  50. package/dist/core/StorageStrategy.js +199 -0
  51. package/dist/core/Strata.d.ts +122 -0
  52. package/dist/core/Strata.d.ts.map +1 -0
  53. package/dist/core/Strata.js +568 -0
  54. package/dist/features/compression.d.ts +65 -0
  55. package/dist/features/compression.d.ts.map +1 -0
  56. package/dist/features/compression.js +205 -0
  57. package/dist/features/encryption.d.ts +68 -0
  58. package/dist/features/encryption.d.ts.map +1 -0
  59. package/dist/features/encryption.js +172 -0
  60. package/dist/features/migration.d.ts +17 -0
  61. package/dist/features/migration.d.ts.map +1 -0
  62. package/dist/features/migration.js +43 -0
  63. package/dist/features/query.d.ts +75 -0
  64. package/dist/features/query.d.ts.map +1 -0
  65. package/dist/features/query.js +305 -0
  66. package/dist/features/sync.d.ts +87 -0
  67. package/dist/features/sync.d.ts.map +1 -0
  68. package/dist/features/sync.js +233 -0
  69. package/dist/features/ttl.d.ts +124 -0
  70. package/dist/features/ttl.d.ts.map +1 -0
  71. package/dist/features/ttl.js +236 -0
  72. package/dist/index.d.ts +44 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +46 -0
  75. package/dist/package.json +60 -0
  76. package/dist/plugin/definitions.d.ts +219 -0
  77. package/dist/plugin/definitions.d.ts.map +1 -0
  78. package/dist/plugin/definitions.js +5 -0
  79. package/dist/plugin/index.d.ts +8 -0
  80. package/dist/plugin/index.d.ts.map +1 -0
  81. package/dist/plugin/index.js +27 -0
  82. package/dist/plugin/web.d.ts +24 -0
  83. package/dist/plugin/web.d.ts.map +1 -0
  84. package/dist/plugin/web.js +35 -0
  85. package/dist/types/index.d.ts +558 -0
  86. package/dist/types/index.d.ts.map +1 -0
  87. package/dist/types/index.js +14 -0
  88. package/dist/utils/errors.d.ts +92 -0
  89. package/dist/utils/errors.d.ts.map +1 -0
  90. package/dist/utils/errors.js +153 -0
  91. package/dist/utils/index.d.ts +105 -0
  92. package/dist/utils/index.d.ts.map +1 -0
  93. package/dist/utils/index.js +329 -0
  94. package/ios/Plugin/KeychainStorage.swift +87 -0
  95. package/ios/Plugin/SQLiteStorage.swift +167 -0
  96. package/ios/Plugin/StrataStoragePlugin.swift +204 -0
  97. package/ios/Plugin/UserDefaultsStorage.swift +44 -0
  98. package/package.json +126 -0
  99. package/scripts/build.js +52 -0
  100. package/scripts/cli.js +60 -0
  101. package/scripts/configure.js +444 -0
  102. package/scripts/postinstall.js +33 -0
package/Readme.md ADDED
@@ -0,0 +1,113 @@
1
+ # Strata Storage
2
+
3
+ ## 📚 Documentation
4
+
5
+ - **[Full Documentation](https://strata-storage.dev)** *(coming soon)*
6
+ - **[API Reference](https://strata-storage.dev/api)**
7
+ - **[Platform Guides](https://strata-storage.dev/platforms)**
8
+ - **[Examples](https://strata-storage.dev/examples)**
9
+ - **[GitHub](https://github.com/aoneahsan/strata-storage)**
10
+
11
+ ---
12
+
13
+ **One API. Every Storage. Everywhere.**
14
+
15
+ Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms.
16
+
17
+ ## 🚀 Quick Start
18
+
19
+ ```bash
20
+ npm install strata-storage
21
+ ```
22
+
23
+ ```typescript
24
+ import { Strata } from 'strata-storage';
25
+
26
+ const storage = new Strata();
27
+ await storage.initialize();
28
+
29
+ // Works everywhere - web, iOS, Android
30
+ await storage.set('user', { name: 'John', age: 30 });
31
+ const user = await storage.get('user');
32
+ ```
33
+
34
+ ## ✨ Features
35
+
36
+ ### Core Features
37
+ - ✅ **Zero Dependencies** - No external packages, pure implementation
38
+ - ✅ **Universal API** - Single interface for all storage types
39
+ - ✅ **Cross-Platform** - Web, iOS, Android support
40
+ - ✅ **TypeScript** - Full type safety and IntelliSense
41
+ - ✅ **Auto Fallback** - Intelligent storage selection
42
+
43
+ ### Storage Adapters
44
+ - ✅ **Memory** - Fast in-memory storage
45
+ - ✅ **LocalStorage** - Persistent browser storage
46
+ - ✅ **SessionStorage** - Session-based browser storage
47
+ - ✅ **IndexedDB** - Large-scale browser database
48
+ - ✅ **Cookies** - HTTP cookie storage
49
+ - ✅ **Cache API** - Service worker cache storage
50
+ - ✅ **Capacitor Preferences** - Native mobile preferences
51
+ - ✅ **SQLite** - Mobile SQL database
52
+ - ✅ **Secure Storage** - Keychain (iOS) / Encrypted SharedPreferences (Android)
53
+ - ✅ **Filesystem** - File-based storage
54
+
55
+ ### Advanced Features
56
+ - ✅ **Encryption** - AES-GCM encryption with Web Crypto API
57
+ - ✅ **Compression** - LZ-string compression algorithm
58
+ - ✅ **Cross-Tab Sync** - Real-time synchronization across tabs
59
+ - ✅ **Query Engine** - MongoDB-like queries for filtering data
60
+ - ✅ **TTL Support** - Automatic expiration with sliding TTL
61
+ - ✅ **Migration System** - Version-based data migrations
62
+ - 🚧 **Framework Integrations** - React, Vue, Angular (coming soon)
63
+
64
+ ## 📖 Basic Usage
65
+
66
+ ```typescript
67
+ // Initialize with configuration
68
+ const storage = new Strata({
69
+ defaultStorages: ['indexedDB', 'localStorage', 'memory'],
70
+ encryption: { enabled: true },
71
+ compression: { enabled: true },
72
+ ttl: { defaultTTL: 3600000 } // 1 hour
73
+ });
74
+
75
+ await storage.initialize();
76
+
77
+ // Store with options
78
+ await storage.set('key', value, {
79
+ ttl: 3600000, // Expire in 1 hour
80
+ encrypt: true, // Encrypt this value
81
+ compress: true, // Compress if beneficial
82
+ tags: ['user-data'] // Tag for grouping
83
+ });
84
+
85
+ // Query data
86
+ const results = await storage.query({
87
+ tags: { $in: ['user-data'] },
88
+ 'value.age': { $gte: 18 }
89
+ });
90
+
91
+ // Subscribe to changes
92
+ storage.subscribe((change) => {
93
+ console.log(`${change.key} changed from ${change.oldValue} to ${change.newValue}`);
94
+ });
95
+ ```
96
+
97
+ ## 🏗 Project Status
98
+
99
+ Currently in active development. Phase 1-5 completed:
100
+ - ✅ Project setup and core architecture
101
+ - ✅ Memory and web storage adapters
102
+ - ✅ Capacitor plugin structure
103
+ - ✅ Advanced features (encryption, compression, sync, query, TTL)
104
+ - 🚧 Native implementations (iOS/Android)
105
+ - 🚧 Testing and documentation
106
+
107
+ ## 📄 License
108
+
109
+ MIT
110
+
111
+ ---
112
+
113
+ Created by Ahsan Mahmood
@@ -0,0 +1,65 @@
1
+ package com.strata.storage;
2
+
3
+ import android.content.Context;
4
+ import android.content.SharedPreferences;
5
+ import android.os.Build;
6
+ import androidx.security.crypto.EncryptedSharedPreferences;
7
+ import androidx.security.crypto.MasterKey;
8
+ import java.util.Set;
9
+ import java.util.Map;
10
+
11
+ public class EncryptedStorage {
12
+ private SharedPreferences encryptedPrefs;
13
+ private SharedPreferences.Editor editor;
14
+
15
+ public EncryptedStorage(Context context, String name) throws Exception {
16
+ String fileName = name != null ? name : "StrataSecureStorage";
17
+
18
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
19
+ MasterKey masterKey = new MasterKey.Builder(context)
20
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
21
+ .build();
22
+
23
+ encryptedPrefs = EncryptedSharedPreferences.create(
24
+ context,
25
+ fileName,
26
+ masterKey,
27
+ EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
28
+ EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
29
+ );
30
+
31
+ editor = encryptedPrefs.edit();
32
+ } else {
33
+ // Fallback to regular SharedPreferences for older devices
34
+ encryptedPrefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
35
+ editor = encryptedPrefs.edit();
36
+ }
37
+ }
38
+
39
+ public boolean set(String key, String value) {
40
+ editor.putString(key, value);
41
+ return editor.commit();
42
+ }
43
+
44
+ public String get(String key) {
45
+ return encryptedPrefs.getString(key, null);
46
+ }
47
+
48
+ public boolean remove(String key) {
49
+ editor.remove(key);
50
+ return editor.commit();
51
+ }
52
+
53
+ public boolean clear() {
54
+ editor.clear();
55
+ return editor.commit();
56
+ }
57
+
58
+ public Set<String> keys() {
59
+ return encryptedPrefs.getAll().keySet();
60
+ }
61
+
62
+ public boolean has(String key) {
63
+ return encryptedPrefs.contains(key);
64
+ }
65
+ }
@@ -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,46 @@
1
+ /**
2
+ * Filesystem Adapter - Native file system storage
3
+ * Direct file access on iOS and Android
4
+ */
5
+ import { BaseAdapter } from '@/core/BaseAdapter';
6
+ import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo } from '@/types';
7
+ /**
8
+ * Native filesystem adapter using Capacitor plugin
9
+ */
10
+ export declare class FilesystemAdapter extends BaseAdapter {
11
+ readonly name: StorageType;
12
+ readonly capabilities: StorageCapabilities;
13
+ /**
14
+ * Check if filesystem is available
15
+ */
16
+ isAvailable(): Promise<boolean>;
17
+ /**
18
+ * Initialize the adapter
19
+ */
20
+ initialize(): Promise<void>;
21
+ /**
22
+ * Get a value from filesystem
23
+ */
24
+ get<T = unknown>(key: string): Promise<StorageValue<T> | null>;
25
+ /**
26
+ * Set a value in filesystem
27
+ */
28
+ set<T = unknown>(key: string, value: StorageValue<T>): Promise<void>;
29
+ /**
30
+ * Remove a value from filesystem
31
+ */
32
+ remove(key: string): Promise<void>;
33
+ /**
34
+ * Clear filesystem storage
35
+ */
36
+ clear(options?: ClearOptions): Promise<void>;
37
+ /**
38
+ * Get all keys
39
+ */
40
+ keys(pattern?: string | RegExp): Promise<string[]>;
41
+ /**
42
+ * Get storage size
43
+ */
44
+ size(detailed?: boolean): Promise<SizeInfo>;
45
+ }
46
+ //# sourceMappingURL=FilesystemAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilesystemAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/capacitor/FilesystemAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAgB;IAC1C,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAUxC;IAEF;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAWrC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAwBpE;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB1E;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxC;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlD;;OAEG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAwBxD;;OAEG;IACG,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAYlD"}