strata-storage 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
- package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +44 -3
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -5
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +43 -3
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +12 -3
- package/dist/capacitor.d.ts.map +1 -1
- package/dist/capacitor.js +4 -3
- package/dist/core/Strata.d.ts +133 -2
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +133 -2
- package/dist/firebase.d.ts.map +1 -1
- package/dist/firebase.js +21 -1
- package/dist/ios/Plugin/KeychainStorage.swift +31 -9
- package/dist/ios/Plugin/SQLiteStorage.swift +29 -6
- package/dist/ios/Plugin/UserDefaultsStorage.swift +25 -7
- package/dist/package.json +5 -5
- package/dist/plugin/web.d.ts +10 -6
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +42 -13
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -3
- package/ios/Plugin/KeychainStorage.swift +31 -9
- package/ios/Plugin/SQLiteStorage.swift +29 -6
- package/ios/Plugin/UserDefaultsStorage.swift +25 -7
- package/package.json +15 -15
- package/dist/README.md +0 -179
|
@@ -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,EAC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,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"}
|
package/dist/core/Strata.js
CHANGED
|
@@ -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) {
|
package/dist/firebase.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;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
|
-
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
145
|
-
|
|
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
|
|
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
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
+
"version": "2.0.4",
|
|
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": ">=
|
|
48
|
-
"@capacitor/core": "
|
|
49
|
-
"react": ">=
|
|
50
|
-
"vue": ">=3.
|
|
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": {
|
package/dist/plugin/web.d.ts
CHANGED
|
@@ -10,15 +10,19 @@ export declare class StrataStorageWeb implements StrataStoragePlugin {
|
|
|
10
10
|
}): Promise<{
|
|
11
11
|
available: boolean;
|
|
12
12
|
}>;
|
|
13
|
-
get(
|
|
13
|
+
get(options: NativeGetOptions): Promise<{
|
|
14
14
|
value: StorageValue | null;
|
|
15
15
|
}>;
|
|
16
|
-
set(
|
|
17
|
-
remove(
|
|
18
|
-
clear(
|
|
19
|
-
keys(
|
|
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(
|
|
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
|
package/dist/plugin/web.d.ts.map
CHANGED
|
@@ -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;
|
|
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;IAWtF,GAAG,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;KAAE,CAAC;IAOvE,GAAG,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnD,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAO7D,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAOjE;;OAEG;IACH,OAAO,CAAC,aAAa;CAatB"}
|
package/dist/plugin/web.js
CHANGED
|
@@ -6,30 +6,59 @@ export class StrataStorageWeb {
|
|
|
6
6
|
async isAvailable(_options) {
|
|
7
7
|
// Web platform doesn't support native storage types
|
|
8
8
|
// This is handled by the web adapters instead
|
|
9
|
-
return {
|
|
9
|
+
return {
|
|
10
|
+
available: false,
|
|
11
|
+
platform: 'web',
|
|
12
|
+
message: 'Native storage not available on web. Use web adapters: localStorage, sessionStorage, indexedDB, cookies, or cache instead.',
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
|
-
async get(
|
|
15
|
+
async get(options) {
|
|
12
16
|
// Not implemented for web - use web adapters instead
|
|
13
|
-
|
|
17
|
+
const storageType = options.storage || 'preferences';
|
|
18
|
+
const suggestion = this.getSuggestion(storageType);
|
|
19
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
14
20
|
}
|
|
15
|
-
async set(
|
|
21
|
+
async set(options) {
|
|
16
22
|
// Not implemented for web - use web adapters instead
|
|
17
|
-
|
|
23
|
+
const storageType = options.storage || 'preferences';
|
|
24
|
+
const suggestion = this.getSuggestion(storageType);
|
|
25
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
18
26
|
}
|
|
19
|
-
async remove(
|
|
27
|
+
async remove(options) {
|
|
20
28
|
// Not implemented for web - use web adapters instead
|
|
21
|
-
|
|
29
|
+
const storageType = options.storage || 'preferences';
|
|
30
|
+
const suggestion = this.getSuggestion(storageType);
|
|
31
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
22
32
|
}
|
|
23
|
-
async clear(
|
|
33
|
+
async clear(options) {
|
|
24
34
|
// Not implemented for web - use web adapters instead
|
|
25
|
-
|
|
35
|
+
const storageType = options.storage || 'preferences';
|
|
36
|
+
const suggestion = this.getSuggestion(storageType);
|
|
37
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
26
38
|
}
|
|
27
|
-
async keys(
|
|
39
|
+
async keys(options) {
|
|
28
40
|
// Not implemented for web - use web adapters instead
|
|
29
|
-
|
|
41
|
+
const storageType = options.storage || 'preferences';
|
|
42
|
+
const suggestion = this.getSuggestion(storageType);
|
|
43
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
30
44
|
}
|
|
31
|
-
async size(
|
|
45
|
+
async size(options) {
|
|
32
46
|
// Not implemented for web - use web adapters instead
|
|
33
|
-
|
|
47
|
+
const storageType = options.storage || 'preferences';
|
|
48
|
+
const suggestion = this.getSuggestion(storageType);
|
|
49
|
+
throw new Error(`Native storage '${storageType}' not available on web platform. ${suggestion}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get suggestion for web alternative based on native storage type
|
|
53
|
+
*/
|
|
54
|
+
getSuggestion(storageType) {
|
|
55
|
+
const suggestions = {
|
|
56
|
+
preferences: 'Use localStorage adapter for persistent key-value storage.',
|
|
57
|
+
secure: 'Use indexedDB adapter with encryption enabled for secure storage.',
|
|
58
|
+
sqlite: 'Use indexedDB adapter for database-like storage.',
|
|
59
|
+
filesystem: 'Use Cache API adapter or indexedDB for file storage.',
|
|
60
|
+
};
|
|
61
|
+
return (suggestions[storageType] ||
|
|
62
|
+
'Use one of the web adapters: localStorage, sessionStorage, indexedDB, cookies, or cache.');
|
|
34
63
|
}
|
|
35
64
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -118,8 +118,5 @@ export declare function serializeValue(value: unknown): string;
|
|
|
118
118
|
* Deserialize a value from storage
|
|
119
119
|
*/
|
|
120
120
|
export declare function deserializeValue(value: string): unknown;
|
|
121
|
-
/**
|
|
122
|
-
* Create an error with additional context
|
|
123
|
-
*/
|
|
124
121
|
export declare function createError(message: string, code?: string, details?: unknown): Error;
|
|
125
122
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,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AG,IAAI;CAOzC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAUD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,KAAK,CAKpF"}
|
package/dist/utils/index.js
CHANGED
|
@@ -352,9 +352,6 @@ export function serializeValue(value) {
|
|
|
352
352
|
export function deserializeValue(value) {
|
|
353
353
|
return deserialize(value);
|
|
354
354
|
}
|
|
355
|
-
/**
|
|
356
|
-
* Create an error with additional context
|
|
357
|
-
*/
|
|
358
355
|
export function createError(message, code, details) {
|
|
359
356
|
const error = new Error(message);
|
|
360
357
|
error.code = code;
|
|
@@ -40,16 +40,29 @@ import Security
|
|
|
40
40
|
return status == errSecSuccess
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
@objc public func clear() -> Bool {
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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] {
|