strata-storage 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +113 -0
- package/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
- package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
- package/dist/adapters/capacitor/FilesystemAdapter.d.ts +46 -0
- package/dist/adapters/capacitor/FilesystemAdapter.d.ts.map +1 -0
- package/dist/adapters/capacitor/FilesystemAdapter.js +162 -0
- package/dist/adapters/capacitor/PreferencesAdapter.d.ts +46 -0
- package/dist/adapters/capacitor/PreferencesAdapter.d.ts.map +1 -0
- package/dist/adapters/capacitor/PreferencesAdapter.js +162 -0
- package/dist/adapters/capacitor/SecureAdapter.d.ts +69 -0
- package/dist/adapters/capacitor/SecureAdapter.d.ts.map +1 -0
- package/dist/adapters/capacitor/SecureAdapter.js +214 -0
- package/dist/adapters/capacitor/SqliteAdapter.d.ts +68 -0
- package/dist/adapters/capacitor/SqliteAdapter.d.ts.map +1 -0
- package/dist/adapters/capacitor/SqliteAdapter.js +277 -0
- package/dist/adapters/capacitor/index.d.ts +9 -0
- package/dist/adapters/capacitor/index.d.ts.map +1 -0
- package/dist/adapters/capacitor/index.js +8 -0
- package/dist/adapters/web/CacheAdapter.d.ts +91 -0
- package/dist/adapters/web/CacheAdapter.d.ts.map +1 -0
- package/dist/adapters/web/CacheAdapter.js +291 -0
- package/dist/adapters/web/CookieAdapter.d.ts +77 -0
- package/dist/adapters/web/CookieAdapter.d.ts.map +1 -0
- package/dist/adapters/web/CookieAdapter.js +260 -0
- package/dist/adapters/web/IndexedDBAdapter.d.ts +78 -0
- package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -0
- package/dist/adapters/web/IndexedDBAdapter.js +371 -0
- package/dist/adapters/web/LocalStorageAdapter.d.ts +63 -0
- package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -0
- package/dist/adapters/web/LocalStorageAdapter.js +238 -0
- package/dist/adapters/web/MemoryAdapter.d.ts +69 -0
- package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -0
- package/dist/adapters/web/MemoryAdapter.js +165 -0
- package/dist/adapters/web/SessionStorageAdapter.d.ts +53 -0
- package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -0
- package/dist/adapters/web/SessionStorageAdapter.js +180 -0
- package/dist/adapters/web/index.d.ts +10 -0
- package/dist/adapters/web/index.d.ts.map +1 -0
- package/dist/adapters/web/index.js +9 -0
- package/dist/core/AdapterRegistry.d.ts +52 -0
- package/dist/core/AdapterRegistry.d.ts.map +1 -0
- package/dist/core/AdapterRegistry.js +102 -0
- package/dist/core/BaseAdapter.d.ts +79 -0
- package/dist/core/BaseAdapter.d.ts.map +1 -0
- package/dist/core/BaseAdapter.js +197 -0
- package/dist/core/StorageStrategy.d.ts +55 -0
- package/dist/core/StorageStrategy.d.ts.map +1 -0
- package/dist/core/StorageStrategy.js +199 -0
- package/dist/core/Strata.d.ts +122 -0
- package/dist/core/Strata.d.ts.map +1 -0
- package/dist/core/Strata.js +568 -0
- package/dist/features/compression.d.ts +65 -0
- package/dist/features/compression.d.ts.map +1 -0
- package/dist/features/compression.js +205 -0
- package/dist/features/encryption.d.ts +68 -0
- package/dist/features/encryption.d.ts.map +1 -0
- package/dist/features/encryption.js +172 -0
- package/dist/features/migration.d.ts +17 -0
- package/dist/features/migration.d.ts.map +1 -0
- package/dist/features/migration.js +43 -0
- package/dist/features/query.d.ts +75 -0
- package/dist/features/query.d.ts.map +1 -0
- package/dist/features/query.js +305 -0
- package/dist/features/sync.d.ts +87 -0
- package/dist/features/sync.d.ts.map +1 -0
- package/dist/features/sync.js +233 -0
- package/dist/features/ttl.d.ts +124 -0
- package/dist/features/ttl.d.ts.map +1 -0
- package/dist/features/ttl.js +236 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/package.json +60 -0
- package/dist/plugin/definitions.d.ts +219 -0
- package/dist/plugin/definitions.d.ts.map +1 -0
- package/dist/plugin/definitions.js +5 -0
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +27 -0
- package/dist/plugin/web.d.ts +24 -0
- package/dist/plugin/web.d.ts.map +1 -0
- package/dist/plugin/web.js +35 -0
- package/dist/types/index.d.ts +558 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/utils/errors.d.ts +92 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +153 -0
- package/dist/utils/index.d.ts +105 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +329 -0
- package/ios/Plugin/KeychainStorage.swift +87 -0
- package/ios/Plugin/SQLiteStorage.swift +167 -0
- package/ios/Plugin/StrataStoragePlugin.swift +204 -0
- package/ios/Plugin/UserDefaultsStorage.swift +44 -0
- package/package.json +126 -0
- package/scripts/build.js +52 -0
- package/scripts/cli.js +60 -0
- package/scripts/configure.js +444 -0
- package/scripts/postinstall.js +33 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Adapter - Native SQLite database storage
|
|
3
|
+
* Available on iOS and Android
|
|
4
|
+
*/
|
|
5
|
+
import { BaseAdapter } from '@/core/BaseAdapter';
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, QueryCondition, Transaction } from '@/types';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for SQLite adapter
|
|
9
|
+
*/
|
|
10
|
+
export interface SqliteConfig {
|
|
11
|
+
database?: string;
|
|
12
|
+
table?: string;
|
|
13
|
+
version?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Native SQLite adapter using Capacitor plugin
|
|
17
|
+
*/
|
|
18
|
+
export declare class SqliteAdapter extends BaseAdapter {
|
|
19
|
+
readonly name: StorageType;
|
|
20
|
+
readonly capabilities: StorageCapabilities;
|
|
21
|
+
private database;
|
|
22
|
+
private table;
|
|
23
|
+
constructor(config?: SqliteConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Check if SQLite is available
|
|
26
|
+
*/
|
|
27
|
+
isAvailable(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the adapter
|
|
30
|
+
*/
|
|
31
|
+
initialize(config?: SqliteConfig): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get a value from SQLite
|
|
34
|
+
*/
|
|
35
|
+
get<T = unknown>(key: string): Promise<StorageValue<T> | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Set a value in SQLite
|
|
38
|
+
*/
|
|
39
|
+
set<T = unknown>(key: string, value: StorageValue<T>): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Remove a value from SQLite
|
|
42
|
+
*/
|
|
43
|
+
remove(key: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Clear SQLite table
|
|
46
|
+
*/
|
|
47
|
+
clear(options?: ClearOptions): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Get all keys
|
|
50
|
+
*/
|
|
51
|
+
keys(pattern?: string | RegExp): Promise<string[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Query SQLite with conditions
|
|
54
|
+
*/
|
|
55
|
+
query<T = unknown>(condition: QueryCondition): Promise<Array<{
|
|
56
|
+
key: string;
|
|
57
|
+
value: T;
|
|
58
|
+
}>>;
|
|
59
|
+
/**
|
|
60
|
+
* Get storage size
|
|
61
|
+
*/
|
|
62
|
+
size(detailed?: boolean): Promise<SizeInfo>;
|
|
63
|
+
/**
|
|
64
|
+
* Begin a transaction
|
|
65
|
+
*/
|
|
66
|
+
transaction(): Promise<Transaction>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=SqliteAdapter.d.ts.map
|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AAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBlD;;OAEG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0BxD;;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;IA4B9F;;OAEG;IACG,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAejD;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;CAK1C"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Adapter - Native SQLite database storage
|
|
3
|
+
* Available on iOS and Android
|
|
4
|
+
*/
|
|
5
|
+
import { BaseAdapter } from '@/core/BaseAdapter';
|
|
6
|
+
import { StrataStorage } from '@/plugin';
|
|
7
|
+
import { StorageError, TransactionError } from '@/utils/errors';
|
|
8
|
+
import { isCapacitor } from '@/utils';
|
|
9
|
+
/**
|
|
10
|
+
* Native SQLite adapter using Capacitor plugin
|
|
11
|
+
*/
|
|
12
|
+
export class SqliteAdapter extends BaseAdapter {
|
|
13
|
+
name = 'sqlite';
|
|
14
|
+
capabilities = {
|
|
15
|
+
persistent: true,
|
|
16
|
+
synchronous: false,
|
|
17
|
+
observable: false,
|
|
18
|
+
transactional: true,
|
|
19
|
+
queryable: true,
|
|
20
|
+
maxSize: -1, // Limited by device storage
|
|
21
|
+
binary: true,
|
|
22
|
+
encrypted: false, // Can be encrypted at OS level
|
|
23
|
+
crossTab: true,
|
|
24
|
+
};
|
|
25
|
+
database;
|
|
26
|
+
table;
|
|
27
|
+
constructor(config = {}) {
|
|
28
|
+
super();
|
|
29
|
+
this.database = config.database || 'strata_storage';
|
|
30
|
+
this.table = config.table || 'storage';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if SQLite is available
|
|
34
|
+
*/
|
|
35
|
+
async isAvailable() {
|
|
36
|
+
if (!isCapacitor())
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
const result = await StrataStorage.isAvailable({ storage: 'sqlite' });
|
|
40
|
+
return result.available;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Initialize the adapter
|
|
48
|
+
*/
|
|
49
|
+
async initialize(config) {
|
|
50
|
+
if (config?.database)
|
|
51
|
+
this.database = config.database;
|
|
52
|
+
if (config?.table)
|
|
53
|
+
this.table = config.table;
|
|
54
|
+
this.startTTLCleanup();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get a value from SQLite
|
|
58
|
+
*/
|
|
59
|
+
async get(key) {
|
|
60
|
+
try {
|
|
61
|
+
const result = await StrataStorage.get({
|
|
62
|
+
key,
|
|
63
|
+
storage: 'sqlite',
|
|
64
|
+
database: this.database,
|
|
65
|
+
table: this.table,
|
|
66
|
+
});
|
|
67
|
+
if (!result.value)
|
|
68
|
+
return null;
|
|
69
|
+
const value = result.value;
|
|
70
|
+
// Check TTL
|
|
71
|
+
if (this.isExpired(value)) {
|
|
72
|
+
await this.remove(key);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Failed to get key ${key} from SQLite:`, error);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Set a value in SQLite
|
|
84
|
+
*/
|
|
85
|
+
async set(key, value) {
|
|
86
|
+
const oldValue = await this.get(key);
|
|
87
|
+
try {
|
|
88
|
+
await StrataStorage.set({
|
|
89
|
+
key,
|
|
90
|
+
value,
|
|
91
|
+
storage: 'sqlite',
|
|
92
|
+
database: this.database,
|
|
93
|
+
table: this.table,
|
|
94
|
+
});
|
|
95
|
+
this.emitChange(key, oldValue?.value, value.value, 'local');
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new StorageError(`Failed to set key ${key} in SQLite: ${error}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Remove a value from SQLite
|
|
103
|
+
*/
|
|
104
|
+
async remove(key) {
|
|
105
|
+
const oldValue = await this.get(key);
|
|
106
|
+
try {
|
|
107
|
+
await StrataStorage.remove({
|
|
108
|
+
key,
|
|
109
|
+
storage: 'sqlite',
|
|
110
|
+
database: this.database,
|
|
111
|
+
table: this.table,
|
|
112
|
+
});
|
|
113
|
+
if (oldValue) {
|
|
114
|
+
this.emitChange(key, oldValue.value, undefined, 'local');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new StorageError(`Failed to remove key ${key} from SQLite: ${error}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear SQLite table
|
|
123
|
+
*/
|
|
124
|
+
async clear(options) {
|
|
125
|
+
if (!options || (!options.pattern && !options.tags && !options.expiredOnly)) {
|
|
126
|
+
try {
|
|
127
|
+
await StrataStorage.clear({
|
|
128
|
+
storage: 'sqlite',
|
|
129
|
+
database: this.database,
|
|
130
|
+
table: this.table,
|
|
131
|
+
});
|
|
132
|
+
this.emitChange('*', undefined, undefined, 'local');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new StorageError(`Failed to clear SQLite: ${error}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Use base implementation for filtered clear
|
|
140
|
+
await super.clear(options);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get all keys
|
|
144
|
+
*/
|
|
145
|
+
async keys(pattern) {
|
|
146
|
+
try {
|
|
147
|
+
const result = await StrataStorage.keys({
|
|
148
|
+
storage: 'sqlite',
|
|
149
|
+
database: this.database,
|
|
150
|
+
table: this.table,
|
|
151
|
+
pattern: pattern instanceof RegExp ? pattern.source : pattern,
|
|
152
|
+
});
|
|
153
|
+
const keys = result.keys;
|
|
154
|
+
// Check for expired keys
|
|
155
|
+
const validKeys = [];
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
const value = await this.get(key);
|
|
158
|
+
if (value) {
|
|
159
|
+
validKeys.push(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return this.filterKeys(validKeys, pattern);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new StorageError(`Failed to get keys from SQLite: ${error}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Query SQLite with conditions
|
|
170
|
+
*/
|
|
171
|
+
async query(condition) {
|
|
172
|
+
try {
|
|
173
|
+
if (!StrataStorage.query) {
|
|
174
|
+
throw new StorageError('Query not supported on this platform');
|
|
175
|
+
}
|
|
176
|
+
const result = await StrataStorage.query({
|
|
177
|
+
storage: 'sqlite',
|
|
178
|
+
database: this.database,
|
|
179
|
+
table: this.table,
|
|
180
|
+
condition,
|
|
181
|
+
});
|
|
182
|
+
// Filter expired entries
|
|
183
|
+
const validResults = [];
|
|
184
|
+
for (const item of result.results) {
|
|
185
|
+
const value = await this.get(item.key);
|
|
186
|
+
if (value) {
|
|
187
|
+
validResults.push({ key: item.key, value: value.value });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return validResults;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw new StorageError(`Failed to query SQLite: ${error}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get storage size
|
|
198
|
+
*/
|
|
199
|
+
async size(detailed) {
|
|
200
|
+
try {
|
|
201
|
+
const result = await StrataStorage.size({
|
|
202
|
+
storage: 'sqlite',
|
|
203
|
+
database: this.database,
|
|
204
|
+
table: this.table,
|
|
205
|
+
detailed,
|
|
206
|
+
});
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throw new StorageError(`Failed to get size of SQLite: ${error}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Begin a transaction
|
|
215
|
+
*/
|
|
216
|
+
async transaction() {
|
|
217
|
+
// Transactions are handled natively
|
|
218
|
+
// For now, return a simple implementation
|
|
219
|
+
return new SqliteTransaction(this);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* SQLite transaction implementation
|
|
224
|
+
*/
|
|
225
|
+
class SqliteTransaction {
|
|
226
|
+
adapter;
|
|
227
|
+
operations = [];
|
|
228
|
+
committed = false;
|
|
229
|
+
aborted = false;
|
|
230
|
+
constructor(adapter) {
|
|
231
|
+
this.adapter = adapter;
|
|
232
|
+
}
|
|
233
|
+
async get(key) {
|
|
234
|
+
if (this.aborted)
|
|
235
|
+
throw new TransactionError('Transaction already aborted');
|
|
236
|
+
const value = await this.adapter.get(key);
|
|
237
|
+
return value ? value.value : null;
|
|
238
|
+
}
|
|
239
|
+
async set(key, value) {
|
|
240
|
+
if (this.aborted)
|
|
241
|
+
throw new TransactionError('Transaction already aborted');
|
|
242
|
+
this.operations.push(async () => {
|
|
243
|
+
const now = Date.now();
|
|
244
|
+
await this.adapter.set(key, {
|
|
245
|
+
value,
|
|
246
|
+
created: now,
|
|
247
|
+
updated: now,
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
async remove(key) {
|
|
252
|
+
if (this.aborted)
|
|
253
|
+
throw new TransactionError('Transaction already aborted');
|
|
254
|
+
this.operations.push(async () => {
|
|
255
|
+
await this.adapter.remove(key);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async commit() {
|
|
259
|
+
if (this.aborted)
|
|
260
|
+
throw new TransactionError('Cannot commit aborted transaction');
|
|
261
|
+
if (this.committed)
|
|
262
|
+
throw new TransactionError('Transaction already committed');
|
|
263
|
+
this.committed = true;
|
|
264
|
+
// Execute all operations
|
|
265
|
+
for (const operation of this.operations) {
|
|
266
|
+
await operation();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async rollback() {
|
|
270
|
+
if (this.committed)
|
|
271
|
+
throw new TransactionError('Cannot rollback committed transaction');
|
|
272
|
+
if (this.aborted)
|
|
273
|
+
return;
|
|
274
|
+
this.aborted = true;
|
|
275
|
+
this.operations = [];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor Native Storage Adapters
|
|
3
|
+
* Export all native platform storage implementations
|
|
4
|
+
*/
|
|
5
|
+
export { PreferencesAdapter } from './PreferencesAdapter';
|
|
6
|
+
export { SqliteAdapter } from './SqliteAdapter';
|
|
7
|
+
export { SecureAdapter } from './SecureAdapter';
|
|
8
|
+
export { FilesystemAdapter } from './FilesystemAdapter';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/capacitor/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor Native Storage Adapters
|
|
3
|
+
* Export all native platform storage implementations
|
|
4
|
+
*/
|
|
5
|
+
export { PreferencesAdapter } from './PreferencesAdapter';
|
|
6
|
+
export { SqliteAdapter } from './SqliteAdapter';
|
|
7
|
+
export { SecureAdapter } from './SecureAdapter';
|
|
8
|
+
export { FilesystemAdapter } from './FilesystemAdapter';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Adapter - Service Worker Cache API implementation
|
|
3
|
+
* Provides network-aware storage for offline support
|
|
4
|
+
*/
|
|
5
|
+
import { BaseAdapter } from '@/core/BaseAdapter';
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, QueryCondition } from '@/types';
|
|
7
|
+
/**
|
|
8
|
+
* Cache API adapter for Service Worker environments
|
|
9
|
+
*/
|
|
10
|
+
export declare class CacheAdapter extends BaseAdapter {
|
|
11
|
+
readonly name: StorageType;
|
|
12
|
+
readonly capabilities: StorageCapabilities;
|
|
13
|
+
private cacheName;
|
|
14
|
+
private baseUrl;
|
|
15
|
+
private cache?;
|
|
16
|
+
constructor(cacheName?: string, baseUrl?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Check if Cache API is available
|
|
19
|
+
*/
|
|
20
|
+
isAvailable(): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the adapter
|
|
23
|
+
*/
|
|
24
|
+
initialize(config?: {
|
|
25
|
+
cacheName?: string;
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Open cache
|
|
30
|
+
*/
|
|
31
|
+
private openCache;
|
|
32
|
+
/**
|
|
33
|
+
* Create URL for key
|
|
34
|
+
*/
|
|
35
|
+
private keyToUrl;
|
|
36
|
+
/**
|
|
37
|
+
* Extract key from URL
|
|
38
|
+
*/
|
|
39
|
+
private urlToKey;
|
|
40
|
+
/**
|
|
41
|
+
* Get a value from cache
|
|
42
|
+
*/
|
|
43
|
+
get<T = unknown>(key: string): Promise<StorageValue<T> | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Set a value in cache
|
|
46
|
+
*/
|
|
47
|
+
set<T = unknown>(key: string, value: StorageValue<T>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Remove a value from cache
|
|
50
|
+
*/
|
|
51
|
+
remove(key: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Clear cache
|
|
54
|
+
*/
|
|
55
|
+
clear(options?: ClearOptions): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Get all keys
|
|
58
|
+
*/
|
|
59
|
+
keys(pattern?: string | RegExp): Promise<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Query cache with conditions
|
|
62
|
+
*/
|
|
63
|
+
query<T = unknown>(condition: QueryCondition): Promise<Array<{
|
|
64
|
+
key: string;
|
|
65
|
+
value: T;
|
|
66
|
+
}>>;
|
|
67
|
+
/**
|
|
68
|
+
* Get storage size
|
|
69
|
+
*/
|
|
70
|
+
size(detailed?: boolean): Promise<SizeInfo>;
|
|
71
|
+
/**
|
|
72
|
+
* Store binary data
|
|
73
|
+
*/
|
|
74
|
+
setBinary(key: string, data: ArrayBuffer | Blob, metadata?: Record<string, unknown>): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Get binary data
|
|
77
|
+
*/
|
|
78
|
+
getBinary(key: string): Promise<{
|
|
79
|
+
data: ArrayBuffer;
|
|
80
|
+
metadata?: Record<string, unknown>;
|
|
81
|
+
} | null>;
|
|
82
|
+
/**
|
|
83
|
+
* Close the adapter
|
|
84
|
+
*/
|
|
85
|
+
close(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Check if error is quota exceeded
|
|
88
|
+
*/
|
|
89
|
+
private isQuotaError;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=CacheAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/CacheAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,E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