strata-storage 2.1.0 → 2.3.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 (32) hide show
  1. package/LICENSE +35 -21
  2. package/Readme.md +11 -1
  3. package/android/src/main/java/com/strata/storage/EncryptedStorage.java +56 -7
  4. package/android/src/main/java/com/strata/storage/SQLiteStorage.java +57 -2
  5. package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +38 -4
  6. package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +10 -20
  7. package/dist/LICENSE +35 -21
  8. package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -1
  9. package/dist/adapters/web/LocalStorageAdapter.js +11 -2
  10. package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -1
  11. package/dist/adapters/web/MemoryAdapter.js +27 -6
  12. package/dist/adapters/web/SessionStorageAdapter.d.ts +1 -1
  13. package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -1
  14. package/dist/adapters/web/SessionStorageAdapter.js +10 -5
  15. package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +56 -7
  16. package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +57 -2
  17. package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +38 -4
  18. package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +10 -20
  19. package/dist/core/BaseAdapter.d.ts.map +1 -1
  20. package/dist/core/BaseAdapter.js +32 -5
  21. package/dist/core/Strata.d.ts.map +1 -1
  22. package/dist/core/Strata.js +12 -1
  23. package/dist/ios/Plugin/KeychainStorage.swift +44 -9
  24. package/dist/ios/Plugin/SQLiteStorage.swift +36 -2
  25. package/dist/ios/Plugin/UserDefaultsStorage.swift +14 -0
  26. package/dist/package.json +2 -2
  27. package/dist/types/index.d.ts +8 -0
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/ios/Plugin/KeychainStorage.swift +44 -9
  30. package/ios/Plugin/SQLiteStorage.swift +36 -2
  31. package/ios/Plugin/UserDefaultsStorage.swift +14 -0
  32. package/package.json +9 -9
package/LICENSE CHANGED
@@ -1,21 +1,35 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ahsan Mahmood
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Copyright 2024 Ahsan Mahmood
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ ================================================================================
16
+
17
+ Full Apache License 2.0 text: https://www.apache.org/licenses/LICENSE-2.0.txt
18
+
19
+ ================================================================================
20
+
21
+ Additional Terms:
22
+
23
+ 1. Attribution Requirement:
24
+ You must retain all copyright notices and this license in any distribution.
25
+
26
+ 2. Contribution Agreement:
27
+ Any contributions submitted for inclusion shall be under the same license.
28
+
29
+ 3. Name and Trademark:
30
+ "Strata Storage" name may not be used for derivative works without permission.
31
+
32
+ 4. Patent Grant:
33
+ This license includes express patent grants from contributors.
34
+
35
+ For the complete license terms and plain English explanation, see LICENSE.md
package/Readme.md CHANGED
@@ -60,6 +60,9 @@
60
60
  - **[GitHub](https://github.com/aoneahsan/strata-storage)** - Source code
61
61
  - **[NPM](https://www.npmjs.com/package/strata-storage)** - Package registry
62
62
  - **[Example App](./examples/react-capacitor-app)** - Full demo application
63
+ - **[Contributing](./.github/CONTRIBUTING.md)** - How to contribute
64
+ - **[Support](./.github/SUPPORT.md)** - Get help
65
+ - **[Security](./.github/SECURITY.md)** - Report vulnerabilities
63
66
 
64
67
  ---
65
68
 
@@ -254,7 +257,14 @@ Automatically selects the best available storage based on:
254
257
 
255
258
  ## 📄 License
256
259
 
257
- MIT
260
+ **Apache 2.0** - See [LICENSE](./LICENSE) and [License Details](./docs/LICENSE.md)
261
+
262
+ ### Quick Summary:
263
+ - ✅ **Free for commercial use**
264
+ - ✅ **Modify and distribute**
265
+ - ✅ **Patent protection included**
266
+ - ⚠️ **Must keep attribution**
267
+ - ❌ **No warranty provided**
258
268
 
259
269
  ---
260
270
 
@@ -8,6 +8,9 @@ import androidx.security.crypto.MasterKey;
8
8
  import java.util.Set;
9
9
  import java.util.HashSet;
10
10
  import java.util.Map;
11
+ import java.util.List;
12
+ import java.util.ArrayList;
13
+ import org.json.JSONObject;
11
14
 
12
15
  public class EncryptedStorage {
13
16
  private SharedPreferences encryptedPrefs;
@@ -42,9 +45,23 @@ public class EncryptedStorage {
42
45
  }
43
46
  }
44
47
 
45
- public boolean set(String key, String value) {
46
- editor.putString(key, value);
47
- return editor.commit();
48
+ public boolean set(String key, Object value) {
49
+ try {
50
+ String stringValue;
51
+ if (value instanceof String) {
52
+ stringValue = (String) value;
53
+ } else {
54
+ // Convert complex objects to JSON
55
+ stringValue = value instanceof JSONObject ?
56
+ ((JSONObject) value).toString() :
57
+ new JSONObject(value).toString();
58
+ }
59
+ editor.putString(key, stringValue);
60
+ return editor.commit();
61
+ } catch (Exception e) {
62
+ e.printStackTrace();
63
+ return false;
64
+ }
48
65
  }
49
66
 
50
67
  public String get(String key) {
@@ -79,19 +96,19 @@ public class EncryptedStorage {
79
96
  return editor.commit();
80
97
  }
81
98
 
82
- public Set<String> keys() {
99
+ public List<String> keys() {
83
100
  return keys(null);
84
101
  }
85
102
 
86
- public Set<String> keys(String pattern) {
103
+ public List<String> keys(String pattern) {
87
104
  Set<String> allKeys = encryptedPrefs.getAll().keySet();
88
105
 
89
106
  if (pattern == null) {
90
- return allKeys;
107
+ return new ArrayList<>(allKeys);
91
108
  }
92
109
 
93
110
  // Filter keys by pattern
94
- Set<String> filteredKeys = new HashSet<>();
111
+ List<String> filteredKeys = new ArrayList<>();
95
112
  for (String key : allKeys) {
96
113
  if (key.startsWith(pattern) || key.contains(pattern)) {
97
114
  filteredKeys.add(key);
@@ -103,4 +120,36 @@ public class EncryptedStorage {
103
120
  public boolean has(String key) {
104
121
  return encryptedPrefs.contains(key);
105
122
  }
123
+
124
+ public SizeInfo size() {
125
+ Map<String, ?> all = encryptedPrefs.getAll();
126
+ long totalSize = 0;
127
+ int count = all.size();
128
+
129
+ for (Map.Entry<String, ?> entry : all.entrySet()) {
130
+ String key = entry.getKey();
131
+ Object value = entry.getValue();
132
+
133
+ // Estimate size (key + value in bytes)
134
+ totalSize += key.getBytes().length;
135
+ if (value != null) {
136
+ totalSize += value.toString().getBytes().length;
137
+ }
138
+ }
139
+
140
+ return new SizeInfo(totalSize, count);
141
+ }
142
+
143
+ /**
144
+ * Size information class
145
+ */
146
+ public static class SizeInfo {
147
+ public final long total;
148
+ public final int count;
149
+
150
+ public SizeInfo(long total, int count) {
151
+ this.total = total;
152
+ this.count = count;
153
+ }
154
+ }
106
155
  }
@@ -9,6 +9,8 @@ import java.util.ArrayList;
9
9
  import java.util.List;
10
10
  import java.util.HashMap;
11
11
  import java.util.Map;
12
+ import org.json.JSONObject;
13
+ import java.nio.charset.StandardCharsets;
12
14
 
13
15
  public class SQLiteStorage extends SQLiteOpenHelper {
14
16
  private static final int DATABASE_VERSION = 1;
@@ -50,13 +52,31 @@ public class SQLiteStorage extends SQLiteOpenHelper {
50
52
  onCreate(db);
51
53
  }
52
54
 
53
- public boolean set(String key, byte[] value, Long expires, String tags, String metadata) {
55
+ public boolean set(String key, Object value, Long expires, String tags, String metadata) {
56
+ byte[] valueBytes;
57
+
58
+ try {
59
+ if (value instanceof byte[]) {
60
+ valueBytes = (byte[]) value;
61
+ } else if (value instanceof String) {
62
+ valueBytes = ((String) value).getBytes(StandardCharsets.UTF_8);
63
+ } else {
64
+ // Convert complex objects to JSON then to bytes
65
+ String json = value instanceof JSONObject ?
66
+ ((JSONObject) value).toString() :
67
+ new JSONObject(value).toString();
68
+ valueBytes = json.getBytes(StandardCharsets.UTF_8);
69
+ }
70
+ } catch (Exception e) {
71
+ e.printStackTrace();
72
+ return false;
73
+ }
54
74
  SQLiteDatabase db = this.getWritableDatabase();
55
75
  ContentValues values = new ContentValues();
56
76
 
57
77
  long now = System.currentTimeMillis();
58
78
  values.put(KEY_ID, key);
59
- values.put(KEY_VALUE, value);
79
+ values.put(KEY_VALUE, valueBytes);
60
80
  values.put(KEY_CREATED, now);
61
81
  values.put(KEY_UPDATED, now);
62
82
 
@@ -75,6 +95,11 @@ public class SQLiteStorage extends SQLiteOpenHelper {
75
95
  return result != -1;
76
96
  }
77
97
 
98
+ // Convenience method for simple Object values
99
+ public boolean set(String key, Object value) {
100
+ return set(key, value, null, null, null);
101
+ }
102
+
78
103
  public Map<String, Object> get(String key) {
79
104
  SQLiteDatabase db = this.getReadableDatabase();
80
105
  Cursor cursor = db.query(TABLE_NAME, null, KEY_ID + "=?",
@@ -174,4 +199,34 @@ public class SQLiteStorage extends SQLiteOpenHelper {
174
199
  db.close();
175
200
  return exists;
176
201
  }
202
+
203
+ public SizeInfo size() {
204
+ SQLiteDatabase db = this.getReadableDatabase();
205
+ Cursor cursor = db.rawQuery("SELECT COUNT(*), SUM(LENGTH(" + KEY_VALUE + ")) FROM " + TABLE_NAME, null);
206
+
207
+ long totalSize = 0;
208
+ int count = 0;
209
+
210
+ if (cursor != null && cursor.moveToFirst()) {
211
+ count = cursor.getInt(0);
212
+ totalSize = cursor.getLong(1);
213
+ cursor.close();
214
+ }
215
+
216
+ db.close();
217
+ return new SizeInfo(totalSize, count);
218
+ }
219
+
220
+ /**
221
+ * Size information class
222
+ */
223
+ public static class SizeInfo {
224
+ public final long total;
225
+ public final int count;
226
+
227
+ public SizeInfo(long total, int count) {
228
+ this.total = total;
229
+ this.count = count;
230
+ }
231
+ }
177
232
  }
@@ -5,6 +5,8 @@ import android.content.SharedPreferences;
5
5
  import java.util.Map;
6
6
  import java.util.Set;
7
7
  import java.util.HashSet;
8
+ import java.util.List;
9
+ import java.util.ArrayList;
8
10
  import org.json.JSONObject;
9
11
  import org.json.JSONArray;
10
12
 
@@ -83,19 +85,19 @@ public class SharedPreferencesStorage {
83
85
  return editor.commit();
84
86
  }
85
87
 
86
- public Set<String> keys() {
88
+ public List<String> keys() {
87
89
  return keys(null);
88
90
  }
89
91
 
90
- public Set<String> keys(String pattern) {
92
+ public List<String> keys(String pattern) {
91
93
  Set<String> allKeys = prefs.getAll().keySet();
92
94
 
93
95
  if (pattern == null) {
94
- return allKeys;
96
+ return new ArrayList<>(allKeys);
95
97
  }
96
98
 
97
99
  // Filter keys by pattern
98
- Set<String> filteredKeys = new HashSet<>();
100
+ List<String> filteredKeys = new ArrayList<>();
99
101
  for (String key : allKeys) {
100
102
  if (key.startsWith(pattern) || key.contains(pattern)) {
101
103
  filteredKeys.add(key);
@@ -111,4 +113,36 @@ public class SharedPreferencesStorage {
111
113
  public Map<String, ?> getAll() {
112
114
  return prefs.getAll();
113
115
  }
116
+
117
+ public SizeInfo size() {
118
+ Map<String, ?> all = prefs.getAll();
119
+ long totalSize = 0;
120
+ int count = all.size();
121
+
122
+ for (Map.Entry<String, ?> entry : all.entrySet()) {
123
+ String key = entry.getKey();
124
+ Object value = entry.getValue();
125
+
126
+ // Estimate size (key + value in bytes)
127
+ totalSize += key.getBytes().length;
128
+ if (value != null) {
129
+ totalSize += value.toString().getBytes().length;
130
+ }
131
+ }
132
+
133
+ return new SizeInfo(totalSize, count);
134
+ }
135
+
136
+ /**
137
+ * Size information class
138
+ */
139
+ public static class SizeInfo {
140
+ public final long total;
141
+ public final int count;
142
+
143
+ public SizeInfo(long total, int count) {
144
+ this.total = total;
145
+ this.count = count;
146
+ }
147
+ }
114
148
  }
@@ -11,7 +11,6 @@ import com.strata.storage.SQLiteStorage;
11
11
  import org.json.JSONArray;
12
12
  import org.json.JSONException;
13
13
  import java.util.List;
14
- import java.util.Set;
15
14
 
16
15
  /**
17
16
  * Main Capacitor plugin for Strata Storage
@@ -226,40 +225,31 @@ public class StrataStoragePlugin extends Plugin {
226
225
  String storage = call.getString("storage", "preferences");
227
226
 
228
227
  try {
229
- SizeInfo sizeInfo = null;
228
+ JSObject result = new JSObject();
230
229
 
231
230
  switch (storage) {
232
231
  case "secure":
233
- sizeInfo = encryptedStorage.size();
232
+ EncryptedStorage.SizeInfo encryptedSizeInfo = encryptedStorage.size();
233
+ result.put("total", encryptedSizeInfo.total);
234
+ result.put("count", encryptedSizeInfo.count);
234
235
  break;
235
236
  case "sqlite":
236
- sizeInfo = sqliteStorage.size();
237
+ SQLiteStorage.SizeInfo sqliteSizeInfo = sqliteStorage.size();
238
+ result.put("total", sqliteSizeInfo.total);
239
+ result.put("count", sqliteSizeInfo.count);
237
240
  break;
238
241
  case "preferences":
239
242
  default:
240
- sizeInfo = sharedPrefsStorage.size();
243
+ SharedPreferencesStorage.SizeInfo prefsSizeInfo = sharedPrefsStorage.size();
244
+ result.put("total", prefsSizeInfo.total);
245
+ result.put("count", prefsSizeInfo.count);
241
246
  break;
242
247
  }
243
248
 
244
- JSObject result = new JSObject();
245
- result.put("total", sizeInfo.total);
246
- result.put("count", sizeInfo.count);
247
249
  call.resolve(result);
248
250
  } catch (Exception e) {
249
251
  call.reject("Failed to get size", e);
250
252
  }
251
253
  }
252
254
 
253
- /**
254
- * Size information class
255
- */
256
- static class SizeInfo {
257
- public final long total;
258
- public final int count;
259
-
260
- public SizeInfo(long total, int count) {
261
- this.total = total;
262
- this.count = count;
263
- }
264
- }
265
255
  }
package/dist/LICENSE CHANGED
@@ -1,21 +1,35 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ahsan Mahmood
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Copyright 2024 Ahsan Mahmood
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ ================================================================================
16
+
17
+ Full Apache License 2.0 text: https://www.apache.org/licenses/LICENSE-2.0.txt
18
+
19
+ ================================================================================
20
+
21
+ Additional Terms:
22
+
23
+ 1. Attribution Requirement:
24
+ You must retain all copyright notices and this license in any distribution.
25
+
26
+ 2. Contribution Agreement:
27
+ Any contributions submitted for inclusion shall be under the same license.
28
+
29
+ 3. Name and Trademark:
30
+ "Strata Storage" name may not be used for derivative works without permission.
31
+
32
+ 4. Patent Grant:
33
+ This license includes express patent grants from contributors.
34
+
35
+ For the complete license terms and plain English explanation, see LICENSE.md
@@ -1 +1 @@
1
- {"version":3,"file":"LocalStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/LocalStorageAdapter.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,EACR,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAkB;IAC5C,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAUxC;IAEF,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAa;gBAE9E,MAAM,SAAY;IAK9B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAgBrC;;OAEG;IACG,UAAU,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAA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,EAAE,OAAO,GAAG,OAAO;CAUhD"}
@@ -23,7 +23,7 @@ export class LocalStorageAdapter extends BaseAdapter {
23
23
  };
24
24
  prefix;
25
25
  listeners = new Map();
26
- constructor(prefix = 'strata:') {
26
+ constructor(prefix = '') {
27
27
  super();
28
28
  this.prefix = prefix;
29
29
  }
@@ -111,7 +111,8 @@ export class LocalStorageAdapter extends BaseAdapter {
111
111
  * Clear localStorage
112
112
  */
113
113
  async clear(options) {
114
- if (!options || (!options.pattern && !options.tags && !options.expiredOnly)) {
114
+ if (!options ||
115
+ (!options.pattern && !options.prefix && !options.tags && !options.expiredOnly)) {
115
116
  // Clear all with our prefix
116
117
  const keysToRemove = [];
117
118
  for (let i = 0; i < window.localStorage.length; i++) {
@@ -153,23 +154,27 @@ export class LocalStorageAdapter extends BaseAdapter {
153
154
  let count = 0;
154
155
  let keySize = 0;
155
156
  let valueSize = 0;
157
+ const byKey = {};
156
158
  for (let i = 0; i < window.localStorage.length; i++) {
157
159
  const fullKey = window.localStorage.key(i);
158
160
  if (fullKey?.startsWith(this.prefix)) {
159
161
  const item = window.localStorage.getItem(fullKey);
160
162
  if (item) {
161
163
  count++;
164
+ const key = fullKey.substring(this.prefix.length);
162
165
  const itemSize = (fullKey.length + item.length) * 2; // UTF-16
163
166
  total += itemSize;
164
167
  if (detailed) {
165
168
  keySize += fullKey.length * 2;
166
169
  valueSize += item.length * 2;
170
+ byKey[key] = itemSize;
167
171
  }
168
172
  }
169
173
  }
170
174
  }
171
175
  const result = { total, count };
172
176
  if (detailed) {
177
+ result.byKey = byKey;
173
178
  result.detailed = {
174
179
  keys: keySize,
175
180
  values: valueSize,
@@ -182,6 +187,9 @@ export class LocalStorageAdapter extends BaseAdapter {
182
187
  * Subscribe to storage changes
183
188
  */
184
189
  subscribe(callback) {
190
+ // Subscribe to local changes from this adapter
191
+ const unsubscribeLocal = super.subscribe(callback);
192
+ // Also subscribe to remote changes via storage events
185
193
  const listener = (event) => {
186
194
  // Only process events from other windows/tabs
187
195
  if (event.storageArea !== window.localStorage)
@@ -204,6 +212,7 @@ export class LocalStorageAdapter extends BaseAdapter {
204
212
  window.addEventListener('storage', listener);
205
213
  this.listeners.set(callback, listener);
206
214
  return () => {
215
+ unsubscribeLocal();
207
216
  const storedListener = this.listeners.get(callback);
208
217
  if (storedListener) {
209
218
  window.removeEventListener('storage', storedListener);
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/MemoryAdapter.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,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAY;IACtC,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAUxC;IAEF,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,WAAW,CAAK;IAExB;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;OAEG;IACG,UAAU,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9D;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAepE;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B1E;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,M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AAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9D;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAepE;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B1E;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxC;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBlD;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC;;OAEG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBxD;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAgC9F;;OAEG;IACH,cAAc,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAOlD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -92,7 +92,8 @@ export class MemoryAdapter extends BaseAdapter {
92
92
  * Clear memory storage
93
93
  */
94
94
  async clear(options) {
95
- if (!options || (!options.pattern && !options.tags && !options.expiredOnly)) {
95
+ if (!options ||
96
+ (!options.pattern && !options.prefix && !options.tags && !options.expiredOnly)) {
96
97
  // Clear everything
97
98
  this.storage.clear();
98
99
  this.currentSize = 0;
@@ -101,6 +102,11 @@ export class MemoryAdapter extends BaseAdapter {
101
102
  }
102
103
  // Use base implementation for filtered clear
103
104
  await super.clear(options);
105
+ // Recalculate size after filtered clear
106
+ this.currentSize = 0;
107
+ for (const value of this.storage.values()) {
108
+ this.currentSize += this.calculateSize(value);
109
+ }
104
110
  }
105
111
  /**
106
112
  * Check if key exists
@@ -134,11 +140,26 @@ export class MemoryAdapter extends BaseAdapter {
134
140
  async query(condition) {
135
141
  const results = [];
136
142
  for (const [key, item] of this.storage.entries()) {
137
- if (!this.isExpired(item) && this.queryEngine.matches(item, condition)) {
138
- results.push({
139
- key,
140
- value: deepClone(item.value),
141
- });
143
+ if (!this.isExpired(item)) {
144
+ // Check if querying storage metadata (tags, metadata, etc) or the actual value
145
+ let matches = false;
146
+ // Check for storage-level properties
147
+ const storageProps = ['tags', 'metadata', 'created', 'updated', 'expires'];
148
+ const isStorageQuery = Object.keys(condition).some((k) => storageProps.includes(k));
149
+ if (isStorageQuery) {
150
+ // Query against the storage wrapper
151
+ matches = this.queryEngine.matches(item, condition);
152
+ }
153
+ else {
154
+ // Query against the stored value
155
+ matches = this.queryEngine.matches(item.value, condition);
156
+ }
157
+ if (matches) {
158
+ results.push({
159
+ key,
160
+ value: deepClone(item.value),
161
+ });
162
+ }
142
163
  }
143
164
  }
144
165
  return results;
@@ -48,6 +48,6 @@ export declare class SessionStorageAdapter extends LocalStorageAdapter {
48
48
  * Subscribe to storage changes
49
49
  * Note: sessionStorage doesn't fire storage events in the same tab
50
50
  */
51
- subscribe(_callback: import('@/types').SubscriptionCallback): import('@/types').UnsubscribeFunction;
51
+ subscribe(callback: import('@/types').SubscriptionCallback): import('@/types').UnsubscribeFunction;
52
52
  }
53
53
  //# sourceMappingURL=SessionStorageAdapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SessionStorageAdapter.d.ts","sourceRoot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