strata-storage 2.0.3 → 2.1.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 (31) hide show
  1. package/Readme.md +109 -27
  2. package/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
  3. package/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
  4. package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
  5. package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
  6. package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
  7. package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
  8. package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
  9. package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
  10. package/dist/capacitor.d.ts.map +1 -1
  11. package/dist/capacitor.js +4 -3
  12. package/dist/core/Strata.d.ts +133 -2
  13. package/dist/core/Strata.d.ts.map +1 -1
  14. package/dist/core/Strata.js +133 -2
  15. package/dist/firebase.d.ts.map +1 -1
  16. package/dist/firebase.js +21 -1
  17. package/dist/ios/Plugin/KeychainStorage.swift +31 -9
  18. package/dist/ios/Plugin/SQLiteStorage.swift +29 -6
  19. package/dist/ios/Plugin/UserDefaultsStorage.swift +25 -7
  20. package/dist/package.json +5 -5
  21. package/dist/plugin/web.d.ts +10 -6
  22. package/dist/plugin/web.d.ts.map +1 -1
  23. package/dist/plugin/web.js +42 -13
  24. package/dist/utils/index.d.ts +0 -3
  25. package/dist/utils/index.d.ts.map +1 -1
  26. package/dist/utils/index.js +0 -3
  27. package/ios/Plugin/KeychainStorage.swift +31 -9
  28. package/ios/Plugin/SQLiteStorage.swift +29 -6
  29. package/ios/Plugin/UserDefaultsStorage.swift +25 -7
  30. package/package.json +15 -15
  31. package/dist/README.md +0 -179
package/dist/capacitor.js CHANGED
@@ -17,7 +17,7 @@ export async function registerCapacitorAdapters(storage) {
17
17
  // Check if Capacitor is available
18
18
  const hasCapacitor = typeof window !== 'undefined' &&
19
19
  window.Capacitor &&
20
- window.Capacitor.isNativePlatform();
20
+ window.Capacitor?.isNativePlatform?.();
21
21
  if (!hasCapacitor) {
22
22
  console.warn('Capacitor not detected. Capacitor adapters will not be registered.');
23
23
  return;
@@ -36,9 +36,10 @@ export async function registerCapacitorAdapters(storage) {
36
36
  * Helper to check if running in Capacitor environment
37
37
  */
38
38
  export function isCapacitorEnvironment() {
39
- return (typeof window !== 'undefined' &&
39
+ return ((typeof window !== 'undefined' &&
40
40
  window.Capacitor &&
41
- window.Capacitor.isNativePlatform());
41
+ window.Capacitor?.isNativePlatform?.()) ??
42
+ false);
42
43
  }
43
44
  /**
44
45
  * Get Capacitor-specific storage types
@@ -33,26 +33,157 @@ export declare class Strata {
33
33
  initialize(): Promise<void>;
34
34
  /**
35
35
  * Get a value from storage
36
+ *
37
+ * @param key - The key to retrieve
38
+ * @param options - Storage options
39
+ * @param options.storage - Specific storage type to use (e.g., 'localStorage', 'indexedDB')
40
+ * @param options.decrypt - Whether to decrypt the value (default: auto-detect)
41
+ * @param options.decryptionPassword - Password for decryption (uses config password if not provided)
42
+ * @returns The stored value or null if not found
43
+ * @throws {StorageError} If the storage adapter is not available
44
+ * @throws {EncryptionError} If decryption fails
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Simple get
49
+ * const value = await storage.get('myKey');
50
+ *
51
+ * // Get from specific storage
52
+ * const value = await storage.get('myKey', { storage: 'indexedDB' });
53
+ *
54
+ * // Get encrypted value
55
+ * const value = await storage.get('secure-key', {
56
+ * decryptionPassword: 'myPassword'
57
+ * });
58
+ * ```
36
59
  */
37
60
  get<T = unknown>(key: string, options?: StorageOptions): Promise<T | null>;
38
61
  /**
39
62
  * Set a value in storage
63
+ *
64
+ * @param key - The key to store under
65
+ * @param value - The value to store (can be any serializable type)
66
+ * @param options - Storage options
67
+ * @param options.storage - Specific storage type to use
68
+ * @param options.encrypt - Whether to encrypt the value
69
+ * @param options.encryptionPassword - Password for encryption
70
+ * @param options.compress - Whether to compress the value
71
+ * @param options.ttl - Time-to-live in milliseconds
72
+ * @param options.tags - Tags for categorization
73
+ * @param options.metadata - Additional metadata to store
74
+ * @throws {StorageError} If the storage adapter is not available
75
+ * @throws {EncryptionError} If encryption fails
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Simple set
80
+ * await storage.set('myKey', 'myValue');
81
+ *
82
+ * // Set with TTL (expires in 1 hour)
83
+ * await storage.set('tempKey', data, { ttl: 3600000 });
84
+ *
85
+ * // Set with encryption and compression
86
+ * await storage.set('secure-key', sensitiveData, {
87
+ * encrypt: true,
88
+ * compress: true,
89
+ * encryptionPassword: 'myPassword'
90
+ * });
91
+ *
92
+ * // Set with metadata
93
+ * await storage.set('user-123', userData, {
94
+ * tags: ['user', 'active'],
95
+ * metadata: { version: 2, source: 'api' }
96
+ * });
97
+ * ```
40
98
  */
41
99
  set<T = unknown>(key: string, value: T, options?: StorageOptions): Promise<void>;
42
100
  /**
43
101
  * Remove a value from storage
102
+ *
103
+ * @param key - The key to remove
104
+ * @param options - Storage options
105
+ * @param options.storage - Specific storage type to use
106
+ * @throws {StorageError} If the storage adapter is not available
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * // Remove from default storage
111
+ * await storage.remove('myKey');
112
+ *
113
+ * // Remove from specific storage
114
+ * await storage.remove('myKey', { storage: 'cookies' });
115
+ * ```
44
116
  */
45
117
  remove(key: string, options?: StorageOptions): Promise<void>;
46
118
  /**
47
- * Check if a key exists
119
+ * Check if a key exists in storage
120
+ *
121
+ * @param key - The key to check
122
+ * @param options - Storage options
123
+ * @param options.storage - Specific storage type to check
124
+ * @returns True if the key exists, false otherwise
125
+ * @throws {StorageError} If the storage adapter is not available
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Check in default storage
130
+ * const exists = await storage.has('myKey');
131
+ *
132
+ * // Check in specific storage
133
+ * const exists = await storage.has('myKey', { storage: 'sessionStorage' });
134
+ * ```
48
135
  */
49
136
  has(key: string, options?: StorageOptions): Promise<boolean>;
50
137
  /**
51
138
  * Clear storage
139
+ *
140
+ * @param options - Clear options
141
+ * @param options.storage - Specific storage to clear (clears all if not specified)
142
+ * @param options.prefix - Only clear keys with this prefix
143
+ * @param options.tags - Only clear items with these tags
144
+ * @param options.olderThan - Only clear items older than this date
145
+ * @throws {StorageError} If the storage adapter is not available
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Clear all storage
150
+ * await storage.clear();
151
+ *
152
+ * // Clear specific storage
153
+ * await storage.clear({ storage: 'localStorage' });
154
+ *
155
+ * // Clear by prefix
156
+ * await storage.clear({ prefix: 'temp-' });
157
+ *
158
+ * // Clear old items
159
+ * const yesterday = Date.now() - 86400000;
160
+ * await storage.clear({ olderThan: yesterday });
161
+ * ```
52
162
  */
53
163
  clear(options?: ClearOptions & StorageOptions): Promise<void>;
54
164
  /**
55
- * Get all keys
165
+ * Get all keys from storage
166
+ *
167
+ * @param pattern - Optional pattern to filter keys (string prefix or RegExp)
168
+ * @param options - Storage options
169
+ * @param options.storage - Specific storage to get keys from (gets from all if not specified)
170
+ * @returns Array of matching keys
171
+ * @throws {StorageError} If the storage adapter is not available
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Get all keys
176
+ * const keys = await storage.keys();
177
+ *
178
+ * // Get keys with prefix
179
+ * const userKeys = await storage.keys('user-');
180
+ *
181
+ * // Get keys with regex pattern
182
+ * const tempKeys = await storage.keys(/^temp-.*$/);
183
+ *
184
+ * // Get keys from specific storage
185
+ * const localKeys = await storage.keys(null, { storage: 'localStorage' });
186
+ * ```
56
187
  */
57
188
  keys(pattern?: string | RegExp, options?: StorageOptions): Promise<string[]>;
58
189
  /**
@@ -1 +1 @@
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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AM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAU3E;;OAEG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxF;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnE;;OAEG;IACG,WAAW,CACf,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAWrD;;OAEG;IACG,cAAc,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAa/D;;;;;;;;;OASG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAI9C;;;OAGG;IACH,WAAW,IAAI,eAAe;IAI9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B5B,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,kBAAkB;YAgBZ,oBAAoB;YAsCpB,kBAAkB;YAKlB,aAAa;CA2B5B"}
@@ -82,6 +82,29 @@ export class Strata {
82
82
  }
83
83
  /**
84
84
  * Get a value from storage
85
+ *
86
+ * @param key - The key to retrieve
87
+ * @param options - Storage options
88
+ * @param options.storage - Specific storage type to use (e.g., 'localStorage', 'indexedDB')
89
+ * @param options.decrypt - Whether to decrypt the value (default: auto-detect)
90
+ * @param options.decryptionPassword - Password for decryption (uses config password if not provided)
91
+ * @returns The stored value or null if not found
92
+ * @throws {StorageError} If the storage adapter is not available
93
+ * @throws {EncryptionError} If decryption fails
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Simple get
98
+ * const value = await storage.get('myKey');
99
+ *
100
+ * // Get from specific storage
101
+ * const value = await storage.get('myKey', { storage: 'indexedDB' });
102
+ *
103
+ * // Get encrypted value
104
+ * const value = await storage.get('secure-key', {
105
+ * decryptionPassword: 'myPassword'
106
+ * });
107
+ * ```
85
108
  */
86
109
  async get(key, options) {
87
110
  const adapter = await this.selectAdapter(options?.storage);
@@ -135,6 +158,41 @@ export class Strata {
135
158
  }
136
159
  /**
137
160
  * Set a value in storage
161
+ *
162
+ * @param key - The key to store under
163
+ * @param value - The value to store (can be any serializable type)
164
+ * @param options - Storage options
165
+ * @param options.storage - Specific storage type to use
166
+ * @param options.encrypt - Whether to encrypt the value
167
+ * @param options.encryptionPassword - Password for encryption
168
+ * @param options.compress - Whether to compress the value
169
+ * @param options.ttl - Time-to-live in milliseconds
170
+ * @param options.tags - Tags for categorization
171
+ * @param options.metadata - Additional metadata to store
172
+ * @throws {StorageError} If the storage adapter is not available
173
+ * @throws {EncryptionError} If encryption fails
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * // Simple set
178
+ * await storage.set('myKey', 'myValue');
179
+ *
180
+ * // Set with TTL (expires in 1 hour)
181
+ * await storage.set('tempKey', data, { ttl: 3600000 });
182
+ *
183
+ * // Set with encryption and compression
184
+ * await storage.set('secure-key', sensitiveData, {
185
+ * encrypt: true,
186
+ * compress: true,
187
+ * encryptionPassword: 'myPassword'
188
+ * });
189
+ *
190
+ * // Set with metadata
191
+ * await storage.set('user-123', userData, {
192
+ * tags: ['user', 'active'],
193
+ * metadata: { version: 2, source: 'api' }
194
+ * });
195
+ * ```
138
196
  */
139
197
  async set(key, value, options) {
140
198
  const adapter = await this.selectAdapter(options?.storage);
@@ -185,6 +243,20 @@ export class Strata {
185
243
  }
186
244
  /**
187
245
  * Remove a value from storage
246
+ *
247
+ * @param key - The key to remove
248
+ * @param options - Storage options
249
+ * @param options.storage - Specific storage type to use
250
+ * @throws {StorageError} If the storage adapter is not available
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * // Remove from default storage
255
+ * await storage.remove('myKey');
256
+ *
257
+ * // Remove from specific storage
258
+ * await storage.remove('myKey', { storage: 'cookies' });
259
+ * ```
188
260
  */
189
261
  async remove(key, options) {
190
262
  const adapter = await this.selectAdapter(options?.storage);
@@ -200,7 +272,22 @@ export class Strata {
200
272
  }
201
273
  }
202
274
  /**
203
- * Check if a key exists
275
+ * Check if a key exists in storage
276
+ *
277
+ * @param key - The key to check
278
+ * @param options - Storage options
279
+ * @param options.storage - Specific storage type to check
280
+ * @returns True if the key exists, false otherwise
281
+ * @throws {StorageError} If the storage adapter is not available
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * // Check in default storage
286
+ * const exists = await storage.has('myKey');
287
+ *
288
+ * // Check in specific storage
289
+ * const exists = await storage.has('myKey', { storage: 'sessionStorage' });
290
+ * ```
204
291
  */
205
292
  async has(key, options) {
206
293
  const adapter = await this.selectAdapter(options?.storage);
@@ -208,6 +295,29 @@ export class Strata {
208
295
  }
209
296
  /**
210
297
  * Clear storage
298
+ *
299
+ * @param options - Clear options
300
+ * @param options.storage - Specific storage to clear (clears all if not specified)
301
+ * @param options.prefix - Only clear keys with this prefix
302
+ * @param options.tags - Only clear items with these tags
303
+ * @param options.olderThan - Only clear items older than this date
304
+ * @throws {StorageError} If the storage adapter is not available
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // Clear all storage
309
+ * await storage.clear();
310
+ *
311
+ * // Clear specific storage
312
+ * await storage.clear({ storage: 'localStorage' });
313
+ *
314
+ * // Clear by prefix
315
+ * await storage.clear({ prefix: 'temp-' });
316
+ *
317
+ * // Clear old items
318
+ * const yesterday = Date.now() - 86400000;
319
+ * await storage.clear({ olderThan: yesterday });
320
+ * ```
211
321
  */
212
322
  async clear(options) {
213
323
  if (options?.storage) {
@@ -222,7 +332,28 @@ export class Strata {
222
332
  }
223
333
  }
224
334
  /**
225
- * Get all keys
335
+ * Get all keys from storage
336
+ *
337
+ * @param pattern - Optional pattern to filter keys (string prefix or RegExp)
338
+ * @param options - Storage options
339
+ * @param options.storage - Specific storage to get keys from (gets from all if not specified)
340
+ * @returns Array of matching keys
341
+ * @throws {StorageError} If the storage adapter is not available
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * // Get all keys
346
+ * const keys = await storage.keys();
347
+ *
348
+ * // Get keys with prefix
349
+ * const userKeys = await storage.keys('user-');
350
+ *
351
+ * // Get keys with regex pattern
352
+ * const tempKeys = await storage.keys(/^temp-.*$/);
353
+ *
354
+ * // Get keys from specific storage
355
+ * const localKeys = await storage.keys(null, { storage: 'localStorage' });
356
+ * ```
226
357
  */
227
358
  async keys(pattern, options) {
228
359
  if (options?.storage) {
@@ -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;AAE5C;;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,CA2If;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAO5D"}
1
+ {"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C;;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,CA8Jf;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5D"}
package/dist/firebase.js CHANGED
@@ -5,6 +5,7 @@
5
5
  export async function enableFirebaseSync(storage, config) {
6
6
  // Dynamically import Firebase only when this function is called
7
7
  try {
8
+ // @ts-expect-error - Firebase is an optional peer dependency
8
9
  const { initializeApp, getApps } = await import('firebase/app');
9
10
  // Initialize Firebase if not already initialized
10
11
  if (!getApps().length) {
@@ -18,6 +19,7 @@ export async function enableFirebaseSync(storage, config) {
18
19
  });
19
20
  }
20
21
  if (config.firestore) {
22
+ // @ts-expect-error - Firebase is an optional peer dependency
21
23
  const { getFirestore, doc, setDoc, getDoc, deleteDoc } = await import('firebase/firestore');
22
24
  const db = getFirestore();
23
25
  const collectionName = config.collectionName || 'strata-storage';
@@ -70,11 +72,20 @@ export async function enableFirebaseSync(storage, config) {
70
72
  async isAvailable() {
71
73
  return true;
72
74
  },
75
+ subscribe() {
76
+ // Not implemented for Firebase adapter
77
+ return () => { };
78
+ },
79
+ async close() {
80
+ // No cleanup needed
81
+ },
73
82
  };
74
83
  // Register the Firestore adapter
84
+ // Cast to unknown first to bypass type checking for custom adapter
75
85
  storage.registerAdapter(firestoreAdapter);
76
86
  }
77
87
  if (config.realtimeDatabase) {
88
+ // @ts-expect-error - Firebase is an optional peer dependency
78
89
  const { getDatabase, ref, set, get, remove } = await import('firebase/database');
79
90
  const db = getDatabase();
80
91
  // Create custom adapter for Realtime Database
@@ -123,11 +134,19 @@ export async function enableFirebaseSync(storage, config) {
123
134
  async isAvailable() {
124
135
  return true;
125
136
  },
137
+ subscribe() {
138
+ // Not implemented for Firebase adapter
139
+ return () => { };
140
+ },
141
+ async close() {
142
+ // No cleanup needed
143
+ },
126
144
  };
127
145
  // Register the Realtime Database adapter
146
+ // Cast to unknown first to bypass type checking for custom adapter
128
147
  storage.registerAdapter(realtimeAdapter);
129
148
  }
130
- console.log('Firebase sync enabled successfully');
149
+ // Firebase sync enabled successfully
131
150
  }
132
151
  catch (error) {
133
152
  throw new Error(`Failed to enable Firebase sync: ${error instanceof Error ? error.message : 'Unknown error'}`);
@@ -138,6 +157,7 @@ export async function enableFirebaseSync(storage, config) {
138
157
  */
139
158
  export async function isFirebaseAvailable() {
140
159
  try {
160
+ // @ts-expect-error - Firebase is an optional peer dependency
141
161
  await import('firebase/app');
142
162
  return true;
143
163
  }
@@ -40,16 +40,29 @@ import Security
40
40
  return status == errSecSuccess
41
41
  }
42
42
 
43
- @objc public func clear() -> Bool {
44
- let query: [String: Any] = [
45
- kSecClass as String: kSecClassGenericPassword,
46
- kSecAttrService as String: service
47
- ]
48
- let status = SecItemDelete(query as CFDictionary)
49
- return status == errSecSuccess || status == errSecItemNotFound
43
+ @objc public func clear(prefix: String? = nil) -> Bool {
44
+ if let prefix = prefix {
45
+ // Clear only keys with the given prefix
46
+ let keysToRemove = keys(pattern: prefix)
47
+ var allSuccess = true
48
+ for key in keysToRemove {
49
+ if !remove(key: key) {
50
+ allSuccess = false
51
+ }
52
+ }
53
+ return allSuccess
54
+ } else {
55
+ // Clear all keys
56
+ let query: [String: Any] = [
57
+ kSecClass as String: kSecClassGenericPassword,
58
+ kSecAttrService as String: service
59
+ ]
60
+ let status = SecItemDelete(query as CFDictionary)
61
+ return status == errSecSuccess || status == errSecItemNotFound
62
+ }
50
63
  }
51
64
 
52
- @objc public func keys() -> [String] {
65
+ @objc public func keys(pattern: String? = nil) -> [String] {
53
66
  var query: [String: Any] = [
54
67
  kSecClass as String: kSecClassGenericPassword,
55
68
  kSecAttrService as String: service,
@@ -67,7 +80,16 @@ import Security
67
80
  guard status == errSecSuccess,
68
81
  let items = result as? [[String: Any]] else { return [] }
69
82
 
70
- return items.compactMap { $0[kSecAttrAccount as String] as? String }
83
+ let allKeys = items.compactMap { $0[kSecAttrAccount as String] as? String }
84
+
85
+ guard let pattern = pattern else {
86
+ return allKeys
87
+ }
88
+
89
+ // Filter keys by pattern (simple prefix matching)
90
+ return allKeys.filter { key in
91
+ key.hasPrefix(pattern) || key.contains(pattern)
92
+ }
71
93
  }
72
94
 
73
95
  private func createQuery(key: String) -> [String: Any] {
@@ -137,23 +137,46 @@ import SQLite3
137
137
  return result
138
138
  }
139
139
 
140
- @objc public func clear() -> Bool {
141
- let deleteSQL = "DELETE FROM \(tableName)"
140
+ @objc public func clear(prefix: String? = nil) -> Bool {
141
+ let deleteSQL: String
142
+ if let prefix = prefix {
143
+ deleteSQL = "DELETE FROM \(tableName) WHERE key LIKE ?"
144
+ } else {
145
+ deleteSQL = "DELETE FROM \(tableName)"
146
+ }
147
+
142
148
  var statement: OpaquePointer?
149
+ var result = sqlite3_prepare_v2(db, deleteSQL, -1, &statement, nil) == SQLITE_OK
143
150
 
144
- let result = sqlite3_prepare_v2(db, deleteSQL, -1, &statement, nil) == SQLITE_OK &&
145
- sqlite3_step(statement) == SQLITE_DONE
151
+ if result && prefix != nil {
152
+ result = sqlite3_bind_text(statement, 1, "\(prefix!)%", -1, nil) == SQLITE_OK
153
+ }
154
+
155
+ if result {
156
+ result = sqlite3_step(statement) == SQLITE_DONE
157
+ }
146
158
 
147
159
  sqlite3_finalize(statement)
148
160
  return result
149
161
  }
150
162
 
151
- @objc public func keys() -> [String] {
152
- let querySQL = "SELECT key FROM \(tableName)"
163
+ @objc public func keys(pattern: String? = nil) -> [String] {
164
+ let querySQL: String
165
+ if let pattern = pattern {
166
+ querySQL = "SELECT key FROM \(tableName) WHERE key LIKE ?"
167
+ } else {
168
+ querySQL = "SELECT key FROM \(tableName)"
169
+ }
170
+
153
171
  var statement: OpaquePointer?
154
172
  var keys: [String] = []
155
173
 
156
174
  if sqlite3_prepare_v2(db, querySQL, -1, &statement, nil) == SQLITE_OK {
175
+ if let pattern = pattern {
176
+ // Use % wildcard for SQL LIKE pattern matching
177
+ sqlite3_bind_text(statement, 1, "%\(pattern)%", -1, nil)
178
+ }
179
+
157
180
  while sqlite3_step(statement) == SQLITE_ROW {
158
181
  if let key = sqlite3_column_text(statement, 0) {
159
182
  keys.append(String(cString: key))
@@ -24,18 +24,36 @@ import Foundation
24
24
  return userDefaults.synchronize()
25
25
  }
26
26
 
27
- @objc public func clear() -> Bool {
28
- if let suiteName = suiteName {
29
- UserDefaults(suiteName: suiteName)?.removePersistentDomain(forName: suiteName)
27
+ @objc public func clear(prefix: String? = nil) -> Bool {
28
+ if let prefix = prefix {
29
+ // Clear only keys with the given prefix
30
+ let keysToRemove = keys(pattern: prefix)
31
+ for key in keysToRemove {
32
+ userDefaults.removeObject(forKey: key)
33
+ }
30
34
  } else {
31
- let domain = Bundle.main.bundleIdentifier!
32
- userDefaults.removePersistentDomain(forName: domain)
35
+ // Clear all keys
36
+ if let suiteName = suiteName {
37
+ UserDefaults(suiteName: suiteName)?.removePersistentDomain(forName: suiteName)
38
+ } else {
39
+ let domain = Bundle.main.bundleIdentifier!
40
+ userDefaults.removePersistentDomain(forName: domain)
41
+ }
33
42
  }
34
43
  return userDefaults.synchronize()
35
44
  }
36
45
 
37
- @objc public func keys() -> [String] {
38
- return Array(userDefaults.dictionaryRepresentation().keys)
46
+ @objc public func keys(pattern: String? = nil) -> [String] {
47
+ let allKeys = Array(userDefaults.dictionaryRepresentation().keys)
48
+
49
+ guard let pattern = pattern else {
50
+ return allKeys
51
+ }
52
+
53
+ // Filter keys by pattern (simple prefix matching)
54
+ return allKeys.filter { key in
55
+ key.hasPrefix(pattern) || key.contains(pattern)
56
+ }
39
57
  }
40
58
 
41
59
  @objc public func has(key: String) -> Bool {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-storage",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -44,10 +44,10 @@
44
44
  "android"
45
45
  ],
46
46
  "peerDependencies": {
47
- "@angular/core": ">=12.0.0",
48
- "@capacitor/core": "^5.0.0 || ^6.0.0",
49
- "react": ">=16.8.0",
50
- "vue": ">=3.0.0"
47
+ "@angular/core": ">=20.3.0",
48
+ "@capacitor/core": ">=7.4.0",
49
+ "react": ">=19.1.0",
50
+ "vue": ">=3.6.0"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "@capacitor/core": {
@@ -10,15 +10,19 @@ export declare class StrataStorageWeb implements StrataStoragePlugin {
10
10
  }): Promise<{
11
11
  available: boolean;
12
12
  }>;
13
- get(_options: NativeGetOptions): Promise<{
13
+ get(options: NativeGetOptions): Promise<{
14
14
  value: StorageValue | null;
15
15
  }>;
16
- set(_options: NativeSetOptions): Promise<void>;
17
- remove(_options: NativeRemoveOptions): Promise<void>;
18
- clear(_options: NativeClearOptions): Promise<void>;
19
- keys(_options: NativeKeysOptions): Promise<{
16
+ set(options: NativeSetOptions): Promise<void>;
17
+ remove(options: NativeRemoveOptions): Promise<void>;
18
+ clear(options: NativeClearOptions): Promise<void>;
19
+ keys(options: NativeKeysOptions): Promise<{
20
20
  keys: string[];
21
21
  }>;
22
- size(_options: NativeSizeOptions): Promise<NativeSizeResult>;
22
+ size(options: NativeSizeOptions): Promise<NativeSizeResult>;
23
+ /**
24
+ * Get suggestion for web alternative based on native storage type
25
+ */
26
+ private getSuggestion;
23
27
  }
24
28
  //# sourceMappingURL=web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/plugin/web.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,qBAAa,gBAAiB,YAAW,mBAAmB;IACpD,WAAW,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,iBAAiB,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAMtF,GAAG,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;KAAE,CAAC;IAKxE,GAAG,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C,MAAM,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpD,KAAK,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAK9D,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAInE"}
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/plugin/web.ts"],"names":[],"m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