strata-storage 2.0.1 → 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/LICENSE +21 -0
- package/Readme.md +17 -0
- 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/LICENSE +21 -0
- package/dist/adapters/web/CacheAdapter.d.ts.map +1 -1
- package/dist/adapters/web/CacheAdapter.js +1 -3
- package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -1
- package/dist/adapters/web/IndexedDBAdapter.js +1 -3
- package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/web/LocalStorageAdapter.js +1 -3
- package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -1
- package/dist/adapters/web/MemoryAdapter.js +1 -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/AdapterRegistry.d.ts +1 -1
- package/dist/core/AdapterRegistry.d.ts.map +1 -1
- package/dist/core/AdapterRegistry.js +10 -3
- package/dist/core/BaseAdapter.d.ts +2 -2
- package/dist/core/BaseAdapter.d.ts.map +1 -1
- package/dist/core/Strata.d.ts +133 -2
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +153 -14
- package/dist/firebase.d.ts.map +1 -1
- package/dist/firebase.js +21 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -16
- 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/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- 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 -162
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
|
|
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
|
|
41
|
+
window.Capacitor?.isNativePlatform?.()) ??
|
|
42
|
+
false);
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Get Capacitor-specific storage types
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdapterRegistry.d.ts","sourceRoot":"","sources":["../../src/core/AdapterRegistry.ts"],"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AW,GAAG,OAAO;IAKtC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAYhC"}
|
|
@@ -37,8 +37,15 @@ export class AdapterRegistry {
|
|
|
37
37
|
}
|
|
38
38
|
// Initialize if not already done
|
|
39
39
|
if (!this.initialized.has(name)) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
try {
|
|
41
|
+
await adapter.initialize(config);
|
|
42
|
+
this.initialized.add(name);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new AdapterNotAvailableError(name, {
|
|
46
|
+
reason: `Initialization failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
return adapter;
|
|
44
51
|
}
|
|
@@ -58,7 +65,7 @@ export class AdapterRegistry {
|
|
|
58
65
|
* Get all registered adapters
|
|
59
66
|
*/
|
|
60
67
|
getAll() {
|
|
61
|
-
return
|
|
68
|
+
return this.adapters;
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Get available adapters for current platform
|
|
@@ -53,7 +53,7 @@ export declare abstract class BaseAdapter implements StorageAdapter {
|
|
|
53
53
|
/**
|
|
54
54
|
* Subscribe to changes (if supported)
|
|
55
55
|
*/
|
|
56
|
-
subscribe
|
|
56
|
+
subscribe(callback: SubscriptionCallback): UnsubscribeFunction;
|
|
57
57
|
/**
|
|
58
58
|
* Emit change event
|
|
59
59
|
*/
|
|
@@ -68,7 +68,7 @@ export declare abstract class BaseAdapter implements StorageAdapter {
|
|
|
68
68
|
/**
|
|
69
69
|
* Close adapter (cleanup)
|
|
70
70
|
*/
|
|
71
|
-
close
|
|
71
|
+
close(): Promise<void>;
|
|
72
72
|
abstract isAvailable(): Promise<boolean>;
|
|
73
73
|
abstract initialize(config?: unknown): Promise<void>;
|
|
74
74
|
abstract get<T = unknown>(key: string): Promise<StorageValue<T> | null>;
|
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GAAG,OAAO,CAAC,IAAI,CAAC;IAC7E,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAC5D"}
|
package/dist/core/Strata.d.ts
CHANGED
|
@@ -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,EACd,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,C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;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) {
|
|
@@ -516,29 +647,37 @@ export class Strata {
|
|
|
516
647
|
}
|
|
517
648
|
async selectDefaultAdapter() {
|
|
518
649
|
const storages = this.config.defaultStorages || this.getDefaultStorages();
|
|
650
|
+
if (storages.length === 0) {
|
|
651
|
+
throw new StorageError('No storage adapters registered or configured');
|
|
652
|
+
}
|
|
519
653
|
for (const storage of storages) {
|
|
520
654
|
try {
|
|
521
|
-
const adapter =
|
|
655
|
+
const adapter = this.registry.get(storage);
|
|
656
|
+
if (!adapter) {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const isAvailable = await adapter.isAvailable();
|
|
660
|
+
if (!isAvailable) {
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
// Initialize adapter with config if provided
|
|
664
|
+
const config = this.config.adapters?.[storage];
|
|
665
|
+
await adapter.initialize(config);
|
|
522
666
|
this.defaultAdapter = adapter;
|
|
523
667
|
this.adapters.set(storage, adapter);
|
|
524
668
|
return;
|
|
525
669
|
}
|
|
526
|
-
catch {
|
|
670
|
+
catch (error) {
|
|
671
|
+
console.warn(`Failed to initialize ${storage} adapter:`, error);
|
|
527
672
|
// Continue to next adapter
|
|
528
673
|
}
|
|
529
674
|
}
|
|
530
|
-
throw new StorageError(
|
|
675
|
+
throw new StorageError(`No available storage adapters found. Tried: ${storages.join(', ')}. ` +
|
|
676
|
+
`Registered adapters: ${Array.from(this.registry.getAll().keys()).join(', ')}`);
|
|
531
677
|
}
|
|
532
678
|
async initializeAdapters() {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
if (config && typeof config === 'object') {
|
|
536
|
-
await adapter.initialize(config);
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
await adapter.initialize();
|
|
540
|
-
}
|
|
541
|
-
}
|
|
679
|
+
// Adapters are already initialized in selectDefaultAdapter
|
|
680
|
+
// This method is kept for compatibility but doesn't re-initialize
|
|
542
681
|
}
|
|
543
682
|
async selectAdapter(storage) {
|
|
544
683
|
if (!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
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type { StorageType, StorageOptions, StorageValue, StorageAdapter, Adapter
|
|
|
17
17
|
export { isValidKey, isValidValue, serializeValue, deserializeValue, generateId, createError, retry, debounce, throttle, } from './utils';
|
|
18
18
|
import { Strata } from './core/Strata';
|
|
19
19
|
declare const storage: Strata;
|
|
20
|
-
|
|
20
|
+
declare const ensureInitialized: () => Promise<void>;
|
|
21
|
+
export { storage, ensureInitialized };
|
|
21
22
|
export default storage;
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA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,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,YAAY,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACb,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,KAAK,EACL,QAAQ,EACR,QAAQ,GACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AASvC,QAAA,MAAM,OAAO,QAGX,CAAC;AAoBH,QAAA,MAAM,iBAAiB,qBAQtB,CAAC;AAMF,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAGtC,eAAe,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,27 +28,37 @@ import { CacheAdapter } from "./adapters/web/CacheAdapter.js";
|
|
|
28
28
|
import { MemoryAdapter } from "./adapters/web/MemoryAdapter.js";
|
|
29
29
|
// Create a singleton instance with web adapters pre-registered
|
|
30
30
|
const storage = new Strata({
|
|
31
|
-
|
|
31
|
+
defaultStorages: ['memory', 'localStorage', 'sessionStorage', 'indexedDB'], // Order of preference
|
|
32
32
|
autoInitialize: false, // We'll initialize it ourselves
|
|
33
33
|
});
|
|
34
34
|
// Register only web adapters by default
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
storage.registerAdapter(new
|
|
38
|
-
storage
|
|
39
|
-
storage.registerAdapter(new
|
|
40
|
-
storage.registerAdapter(new
|
|
35
|
+
try {
|
|
36
|
+
// Memory adapter should always be available as fallback
|
|
37
|
+
storage.registerAdapter(new MemoryAdapter());
|
|
38
|
+
// Browser storage adapters
|
|
39
|
+
storage.registerAdapter(new LocalStorageAdapter());
|
|
40
|
+
storage.registerAdapter(new SessionStorageAdapter());
|
|
41
|
+
storage.registerAdapter(new IndexedDBAdapter());
|
|
42
|
+
storage.registerAdapter(new CookieAdapter());
|
|
43
|
+
storage.registerAdapter(new CacheAdapter());
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.warn('Strata Storage adapter registration warning:', error);
|
|
47
|
+
}
|
|
41
48
|
// Initialize the storage instance
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
let initializationPromise = null;
|
|
50
|
+
const ensureInitialized = async () => {
|
|
51
|
+
if (!initializationPromise) {
|
|
52
|
+
initializationPromise = storage.initialize().catch((error) => {
|
|
53
|
+
console.warn('Strata Storage initialization warning:', error);
|
|
54
|
+
// Continue working even if some adapters fail
|
|
55
|
+
});
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})();
|
|
57
|
+
return initializationPromise;
|
|
58
|
+
};
|
|
59
|
+
// Start initialization immediately but don't block module loading
|
|
60
|
+
ensureInitialized();
|
|
51
61
|
// Export the ready-to-use storage instance
|
|
52
|
-
export { storage };
|
|
62
|
+
export { storage, ensureInitialized };
|
|
53
63
|
// Default export for convenience
|
|
54
64
|
export default storage;
|