strata-storage 2.6.0 → 2.7.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/AI-INTEGRATION-GUIDE.md +97 -10
- package/README.md +70 -70
- package/android/AGENTS.md +18 -3
- package/android/CLAUDE.md +36 -3
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/strata/storage/EncryptedStorage.java +31 -18
- package/android/src/main/java/com/strata/storage/FilesystemStorage.java +62 -10
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +65 -13
- package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +63 -51
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +80 -11
- package/dist/README.md +70 -70
- package/dist/adapters/capacitor/FilesystemAdapter.d.ts +2 -2
- package/dist/adapters/capacitor/FilesystemAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/FilesystemAdapter.js +6 -2
- package/dist/adapters/capacitor/PreferencesAdapter.d.ts +2 -2
- package/dist/adapters/capacitor/PreferencesAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/PreferencesAdapter.js +6 -2
- package/dist/adapters/capacitor/SecureAdapter.d.ts +3 -3
- package/dist/adapters/capacitor/SecureAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/SecureAdapter.js +6 -2
- package/dist/adapters/capacitor/SqliteAdapter.d.ts +24 -3
- package/dist/adapters/capacitor/SqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/SqliteAdapter.js +105 -23
- package/dist/adapters/capacitor/index.d.ts +4 -4
- package/dist/adapters/web/CacheAdapter.d.ts +2 -2
- package/dist/adapters/web/CookieAdapter.d.ts +2 -2
- package/dist/adapters/web/IndexedDBAdapter.d.ts +10 -3
- package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -1
- package/dist/adapters/web/IndexedDBAdapter.js +14 -3
- package/dist/adapters/web/LocalStorageAdapter.d.ts +2 -2
- package/dist/adapters/web/MemoryAdapter.d.ts +2 -2
- package/dist/adapters/web/SessionStorageAdapter.d.ts +10 -10
- package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/web/SessionStorageAdapter.js +3 -2
- package/dist/adapters/web/URLAdapter.d.ts +2 -2
- package/dist/adapters/web/index.d.ts +7 -7
- package/dist/capacitor.d.ts +6 -6
- package/dist/capacitor.d.ts.map +1 -1
- package/dist/capacitor.js +5 -4
- package/dist/core/AdapterRegistry.d.ts +1 -1
- package/dist/core/BaseAdapter.d.ts +21 -5
- package/dist/core/BaseAdapter.d.ts.map +1 -1
- package/dist/core/BaseAdapter.js +29 -1
- package/dist/core/Strata.d.ts +41 -7
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +476 -118
- package/dist/features/compression/index.d.ts +1 -1
- package/dist/features/compression.d.ts +5 -1
- package/dist/features/compression.d.ts.map +1 -1
- package/dist/features/encryption/index.d.ts +1 -1
- package/dist/features/encryption.d.ts +55 -2
- package/dist/features/encryption.d.ts.map +1 -1
- package/dist/features/encryption.js +139 -26
- package/dist/features/migration.d.ts +1 -1
- package/dist/features/observer/index.d.ts +1 -1
- package/dist/features/observer.d.ts +1 -1
- package/dist/features/query/index.d.ts +1 -1
- package/dist/features/query.d.ts +1 -1
- package/dist/features/query.d.ts.map +1 -1
- package/dist/features/query.js +3 -1
- package/dist/features/sync/index.d.ts +1 -1
- package/dist/features/sync.d.ts +19 -3
- package/dist/features/sync.d.ts.map +1 -1
- package/dist/features/sync.js +57 -9
- package/dist/features/ttl/index.d.ts +1 -1
- package/dist/features/ttl.d.ts +2 -2
- package/dist/firebase.d.ts +1 -1
- package/dist/firebase.d.ts.map +1 -1
- package/dist/firebase.js +34 -9
- package/dist/index.d.ts +24 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/integrations/angular/index.d.ts +2 -2
- package/dist/integrations/angular/index.d.ts.map +1 -1
- package/dist/integrations/angular/index.js +7 -8
- package/dist/integrations/react/index.d.ts +3 -3
- package/dist/integrations/react/index.d.ts.map +1 -1
- package/dist/integrations/react/index.js +16 -4
- package/dist/integrations/vue/index.d.ts +2 -2
- package/dist/integrations/vue/index.d.ts.map +1 -1
- package/dist/integrations/vue/index.js +5 -2
- package/dist/package.json +11 -2
- package/dist/plugin/definitions.d.ts +29 -3
- package/dist/plugin/definitions.d.ts.map +1 -1
- package/dist/plugin/index.d.ts +2 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -0
- package/dist/plugin/web.d.ts +11 -2
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +23 -4
- package/dist/types/index.d.ts +50 -20
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -10
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -0
- package/ios/AGENTS.md +14 -3
- package/ios/CLAUDE.md +25 -3
- package/ios/Plugin/FilesystemStorage.swift +19 -0
- package/ios/Plugin/SQLiteStorage.swift +59 -9
- package/ios/Plugin/StrataStoragePlugin.m +1 -0
- package/ios/Plugin/StrataStoragePlugin.swift +87 -34
- package/ios/Plugin/UserDefaultsStorage.swift +47 -46
- package/package.json +29 -26
- package/scripts/build.js +16 -14
- package/scripts/cli.js +1 -1
- package/scripts/configure.js +2 -2
- package/scripts/postinstall.js +3 -2
- package/dist/android/AGENTS.md +0 -51
- package/dist/android/CLAUDE.md +0 -89
- package/dist/android/build.gradle +0 -58
- package/dist/android/proguard-rules.pro +0 -11
- package/dist/android/settings.gradle +0 -2
- package/dist/android/src/main/AndroidManifest.xml +0 -2
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +0 -218
- package/dist/android/src/main/java/com/strata/storage/FilesystemStorage.java +0 -287
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +0 -371
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +0 -209
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +0 -616
- package/dist/core/StorageStrategy.d.ts +0 -55
- package/dist/core/StorageStrategy.d.ts.map +0 -1
- package/dist/core/StorageStrategy.js +0 -200
- package/dist/ios/AGENTS.md +0 -48
- package/dist/ios/CLAUDE.md +0 -84
- package/dist/ios/Plugin/FilesystemStorage.swift +0 -218
- package/dist/ios/Plugin/KeychainStorage.swift +0 -233
- package/dist/ios/Plugin/SQLiteStorage.swift +0 -426
- package/dist/ios/Plugin/StrataStoragePlugin.m +0 -23
- package/dist/ios/Plugin/StrataStoragePlugin.swift +0 -411
- package/dist/ios/Plugin/UserDefaultsStorage.swift +0 -87
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Cookie Adapter - Browser cookie implementation
|
|
3
3
|
* Provides limited storage with 4KB per cookie limit
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Cookie options.
|
|
9
9
|
*
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* IndexedDB Adapter - Browser IndexedDB implementation
|
|
3
3
|
* Provides large-scale persistent storage with advanced features
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, QueryCondition, Transaction } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, QueryCondition, Transaction } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Browser IndexedDB adapter
|
|
9
9
|
*/
|
|
@@ -63,7 +63,14 @@ export declare class IndexedDBAdapter extends BaseAdapter {
|
|
|
63
63
|
*/
|
|
64
64
|
size(detailed?: boolean): Promise<SizeInfo>;
|
|
65
65
|
/**
|
|
66
|
-
* Begin a transaction
|
|
66
|
+
* Begin a transaction.
|
|
67
|
+
*
|
|
68
|
+
* IMPORTANT — IndexedDB transactions auto-commit as soon as control returns to
|
|
69
|
+
* the event loop with no pending requests. Issue all `set`/`remove`/`get`
|
|
70
|
+
* calls back-to-back and `await` them together (e.g. `Promise.all([...])`)
|
|
71
|
+
* BEFORE awaiting anything unrelated. Awaiting a non-IndexedDB promise between
|
|
72
|
+
* operations lets the transaction close, after which further calls fail with
|
|
73
|
+
* `TransactionInactiveError`. For most multi-write needs prefer `setMany()`.
|
|
67
74
|
*/
|
|
68
75
|
transaction(): Promise<Transaction>;
|
|
69
76
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDBAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/IndexedDBAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,WAAW,EACZ,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;IAC/C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAe;IACzC,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAUxC;IAEF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,EAAE,CAAC,CAAc;gBAEb,MAAM,SAAkB,EAAE,SAAS,SAAY,EAAE,OAAO,SAAI;IAOxE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;OAEG;IACG,UAAU,CAAC,MAAM,CAAC,EAAE;QACxB,MAAM,CAA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AAC,GAAG,OAAO,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IA2C9F;;OAEG;IACG,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAwDjD;;;;;;;;;OASG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAQzC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;OAEG;IACH,OAAO,CAAC,YAAY;CAMrB"}
|
|
@@ -281,7 +281,14 @@ export class IndexedDBAdapter extends BaseAdapter {
|
|
|
281
281
|
return promise;
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
|
-
* Begin a transaction
|
|
284
|
+
* Begin a transaction.
|
|
285
|
+
*
|
|
286
|
+
* IMPORTANT — IndexedDB transactions auto-commit as soon as control returns to
|
|
287
|
+
* the event loop with no pending requests. Issue all `set`/`remove`/`get`
|
|
288
|
+
* calls back-to-back and `await` them together (e.g. `Promise.all([...])`)
|
|
289
|
+
* BEFORE awaiting anything unrelated. Awaiting a non-IndexedDB promise between
|
|
290
|
+
* operations lets the transaction close, after which further calls fail with
|
|
291
|
+
* `TransactionInactiveError`. For most multi-write needs prefer `setMany()`.
|
|
285
292
|
*/
|
|
286
293
|
async transaction() {
|
|
287
294
|
const db = await this.openDatabase();
|
|
@@ -328,7 +335,7 @@ class IndexedDBTransaction {
|
|
|
328
335
|
const request = this.store.get(key);
|
|
329
336
|
request.onsuccess = () => {
|
|
330
337
|
const result = request.result;
|
|
331
|
-
resolve(result ? result.value : null);
|
|
338
|
+
resolve(result ? (result.value?.value ?? result.value) : null);
|
|
332
339
|
};
|
|
333
340
|
request.onerror = () => reject(new StorageError(`Transaction get failed: ${request.error}`));
|
|
334
341
|
return promise;
|
|
@@ -340,7 +347,11 @@ class IndexedDBTransaction {
|
|
|
340
347
|
const now = Date.now();
|
|
341
348
|
const record = {
|
|
342
349
|
key,
|
|
343
|
-
value
|
|
350
|
+
value: {
|
|
351
|
+
value,
|
|
352
|
+
created: now,
|
|
353
|
+
updated: now,
|
|
354
|
+
},
|
|
344
355
|
created: now,
|
|
345
356
|
updated: now,
|
|
346
357
|
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* LocalStorage Adapter - Browser localStorage implementation
|
|
3
3
|
* Provides persistent storage with 5-10MB limit
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, SubscriptionCallback, UnsubscribeFunction } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, SizeInfo, SubscriptionCallback, UnsubscribeFunction } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Browser localStorage adapter
|
|
9
9
|
*/
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Memory Adapter - In-memory storage implementation
|
|
3
3
|
* Provides fast, non-persistent storage using Map
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, QueryCondition } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions, QueryCondition } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* In-memory storage adapter using Map
|
|
9
9
|
*/
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* SessionStorage Adapter - Browser sessionStorage implementation
|
|
3
3
|
* Provides session-scoped storage with 5-10MB limit
|
|
4
4
|
*/
|
|
5
|
-
import { LocalStorageAdapter } from
|
|
6
|
-
import type { StorageType, StorageCapabilities } from
|
|
5
|
+
import { LocalStorageAdapter } from "./LocalStorageAdapter.js";
|
|
6
|
+
import type { StorageType, StorageCapabilities } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Browser sessionStorage adapter
|
|
9
9
|
* Extends LocalStorageAdapter as the API is identical
|
|
@@ -23,19 +23,19 @@ export declare class SessionStorageAdapter extends LocalStorageAdapter {
|
|
|
23
23
|
/**
|
|
24
24
|
* Get a value from sessionStorage
|
|
25
25
|
*/
|
|
26
|
-
get<T = unknown>(key: string): Promise<import(
|
|
26
|
+
get<T = unknown>(key: string): Promise<import("../../types/index.js").StorageValue<T> | null>;
|
|
27
27
|
/**
|
|
28
28
|
* Get a value from sessionStorage (synchronous)
|
|
29
29
|
*/
|
|
30
|
-
getSync<T = unknown>(key: string): import(
|
|
30
|
+
getSync<T = unknown>(key: string): import("../../types/index.js").StorageValue<T> | null;
|
|
31
31
|
/**
|
|
32
32
|
* Set a value in sessionStorage
|
|
33
33
|
*/
|
|
34
|
-
set<T = unknown>(key: string, value: import(
|
|
34
|
+
set<T = unknown>(key: string, value: import("../../types/index.js").StorageValue<T>): Promise<void>;
|
|
35
35
|
/**
|
|
36
36
|
* Set a value in sessionStorage (synchronous)
|
|
37
37
|
*/
|
|
38
|
-
setSync<T = unknown>(key: string, value: import(
|
|
38
|
+
setSync<T = unknown>(key: string, value: import("../../types/index.js").StorageValue<T>): void;
|
|
39
39
|
/**
|
|
40
40
|
* Remove a value from sessionStorage
|
|
41
41
|
*/
|
|
@@ -47,11 +47,11 @@ export declare class SessionStorageAdapter extends LocalStorageAdapter {
|
|
|
47
47
|
/**
|
|
48
48
|
* Clear sessionStorage
|
|
49
49
|
*/
|
|
50
|
-
clear(options?: import(
|
|
50
|
+
clear(options?: import("../../types/index.js").ClearOptions): Promise<void>;
|
|
51
51
|
/**
|
|
52
52
|
* Clear sessionStorage (synchronous)
|
|
53
53
|
*/
|
|
54
|
-
clearSync(options?: import(
|
|
54
|
+
clearSync(options?: import("../../types/index.js").ClearOptions): void;
|
|
55
55
|
/**
|
|
56
56
|
* Get all keys
|
|
57
57
|
*/
|
|
@@ -67,11 +67,11 @@ export declare class SessionStorageAdapter extends LocalStorageAdapter {
|
|
|
67
67
|
/**
|
|
68
68
|
* Get storage size
|
|
69
69
|
*/
|
|
70
|
-
size(detailed?: boolean): Promise<import(
|
|
70
|
+
size(detailed?: boolean): Promise<import("../../types/index.js").SizeInfo>;
|
|
71
71
|
/**
|
|
72
72
|
* Subscribe to storage changes
|
|
73
73
|
* Note: sessionStorage doesn't fire storage events in the same tab
|
|
74
74
|
*/
|
|
75
|
-
subscribe(callback: import(
|
|
75
|
+
subscribe(callback: import("../../types/index.js").SubscriptionCallback): import("../../types/index.js").UnsubscribeFunction;
|
|
76
76
|
}
|
|
77
77
|
//# sourceMappingURL=SessionStorageAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/SessionStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"SessionStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/web/SessionStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEhE;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,mBAAmB;IAC5D,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAoB;IAC9C,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAUxC;gBAEU,MAAM,SAAK;IAIvB;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAgBrC;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,OAAO;IAO/B;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG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AQ,CAAC;IAwCnE;;;OAGG;IACH,SAAS,CACP,QAAQ,EAAE,OAAO,SAAS,EAAE,oBAAoB,GAC/C,OAAO,SAAS,EAAE,mBAAmB;CAKzC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Provides session-scoped storage with 5-10MB limit
|
|
4
4
|
*/
|
|
5
5
|
import { LocalStorageAdapter } from "./LocalStorageAdapter.js";
|
|
6
|
+
import { serialize, deserialize } from "../../utils/index.js";
|
|
6
7
|
import { QuotaExceededError, SerializationError, StorageError } from "../../utils/errors.js";
|
|
7
8
|
import { logger } from "../../utils/logger.js";
|
|
8
9
|
/**
|
|
@@ -66,7 +67,7 @@ export class SessionStorageAdapter extends LocalStorageAdapter {
|
|
|
66
67
|
const item = window.sessionStorage.getItem(this.prefix + key);
|
|
67
68
|
if (!item)
|
|
68
69
|
return null;
|
|
69
|
-
const value =
|
|
70
|
+
const value = deserialize(item);
|
|
70
71
|
// Check TTL
|
|
71
72
|
if (this.isExpired(value)) {
|
|
72
73
|
this.removeSync(key);
|
|
@@ -92,7 +93,7 @@ export class SessionStorageAdapter extends LocalStorageAdapter {
|
|
|
92
93
|
const fullKey = this.prefix + key;
|
|
93
94
|
const oldValue = this.getSync(key);
|
|
94
95
|
try {
|
|
95
|
-
const serialized =
|
|
96
|
+
const serialized = serialize(value);
|
|
96
97
|
window.sessionStorage.setItem(fullKey, serialized);
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* - Query mode is visible to the server on navigation; hash mode is client-only.
|
|
13
13
|
* - Not available outside a browser (SSR/Node) — `isAvailable()` returns false.
|
|
14
14
|
*/
|
|
15
|
-
import { BaseAdapter } from
|
|
16
|
-
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions } from
|
|
15
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
16
|
+
import type { StorageType, StorageCapabilities, StorageValue, ClearOptions } from "../../types/index.js";
|
|
17
17
|
/** Configuration for the URL adapter. */
|
|
18
18
|
export interface URLAdapterConfig {
|
|
19
19
|
/** Where to store params: query string (default) or hash fragment. */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Web storage adapters
|
|
3
3
|
*/
|
|
4
|
-
export { MemoryAdapter } from
|
|
5
|
-
export { LocalStorageAdapter } from
|
|
6
|
-
export { SessionStorageAdapter } from
|
|
7
|
-
export { IndexedDBAdapter } from
|
|
8
|
-
export { CookieAdapter } from
|
|
9
|
-
export { CacheAdapter } from
|
|
10
|
-
export { URLAdapter, type URLAdapterConfig } from
|
|
4
|
+
export { MemoryAdapter } from "./MemoryAdapter.js";
|
|
5
|
+
export { LocalStorageAdapter } from "./LocalStorageAdapter.js";
|
|
6
|
+
export { SessionStorageAdapter } from "./SessionStorageAdapter.js";
|
|
7
|
+
export { IndexedDBAdapter } from "./IndexedDBAdapter.js";
|
|
8
|
+
export { CookieAdapter } from "./CookieAdapter.js";
|
|
9
|
+
export { CacheAdapter } from "./CacheAdapter.js";
|
|
10
|
+
export { URLAdapter, type URLAdapterConfig } from "./URLAdapter.js";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/capacitor.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Strata } from
|
|
2
|
-
export { PreferencesAdapter } from
|
|
3
|
-
export { SqliteAdapter } from
|
|
4
|
-
export { SecureAdapter } from
|
|
5
|
-
export { FilesystemAdapter } from
|
|
6
|
-
export { StrataStorage } from
|
|
1
|
+
import type { Strata } from "./core/Strata.js";
|
|
2
|
+
export { PreferencesAdapter } from "./adapters/capacitor/PreferencesAdapter.js";
|
|
3
|
+
export { SqliteAdapter } from "./adapters/capacitor/SqliteAdapter.js";
|
|
4
|
+
export { SecureAdapter } from "./adapters/capacitor/SecureAdapter.js";
|
|
5
|
+
export { FilesystemAdapter } from "./adapters/capacitor/FilesystemAdapter.js";
|
|
6
|
+
export { StrataStorage } from "./plugin/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Register Capacitor adapters with a Strata instance
|
|
9
9
|
* This is completely optional and only needed for Capacitor apps
|
package/dist/capacitor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../src/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../src/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB9E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAShD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD"}
|
package/dist/capacitor.js
CHANGED
|
@@ -28,10 +28,11 @@ export async function registerCapacitorAdapters(storage) {
|
|
|
28
28
|
storage.registerAdapter(new SqliteAdapter());
|
|
29
29
|
storage.registerAdapter(new SecureAdapter());
|
|
30
30
|
storage.registerAdapter(new FilesystemAdapter());
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// Attach the newly registered adapters. initialize() is idempotent and would
|
|
32
|
+
// NOT pick up adapters registered after first init, so refreshAdapters()
|
|
33
|
+
// initializes + attaches them (and re-selects the default) whether or not the
|
|
34
|
+
// instance was already initialized.
|
|
35
|
+
await storage.refreshAdapters();
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Helper to check if running in Capacitor environment
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base adapter implementation with common functionality
|
|
3
3
|
*/
|
|
4
|
-
import type { StorageAdapter, StorageValue, StorageType, StorageCapabilities, ClearOptions, SizeInfo, SubscriptionCallback, UnsubscribeFunction, QueryCondition } from
|
|
5
|
-
import { EventEmitter } from
|
|
6
|
-
import { QueryEngine } from
|
|
4
|
+
import type { StorageAdapter, StorageValue, StorageType, StorageCapabilities, ClearOptions, SizeInfo, SubscriptionCallback, UnsubscribeFunction, QueryCondition } from "../types/index.js";
|
|
5
|
+
import { EventEmitter } from "../utils/index.js";
|
|
6
|
+
import { QueryEngine } from "../features/query.js";
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base adapter that implements common functionality
|
|
9
9
|
*/
|
|
@@ -23,9 +23,16 @@ export declare abstract class BaseAdapter implements StorageAdapter {
|
|
|
23
23
|
*/
|
|
24
24
|
protected stopTTLCleanup(): void;
|
|
25
25
|
/**
|
|
26
|
-
* Clean up expired items
|
|
26
|
+
* Clean up expired items, returning how many were removed.
|
|
27
|
+
*
|
|
28
|
+
* Default implementation is a per-key sweep (enumerate keys, drop the expired
|
|
29
|
+
* ones). Backends that can filter expired rows in the storage engine itself
|
|
30
|
+
* (e.g. SQLite) override this with a single bulk delete — and because such a
|
|
31
|
+
* backend's `keys()` no longer surfaces expired entries, this per-key sweep
|
|
32
|
+
* would not see them anyway. Called by the automatic TTL tick and by
|
|
33
|
+
* `Strata.cleanupExpired()`.
|
|
27
34
|
*/
|
|
28
|
-
|
|
35
|
+
cleanupExpired(): Promise<number>;
|
|
29
36
|
/**
|
|
30
37
|
* Check if value is expired
|
|
31
38
|
*/
|
|
@@ -62,6 +69,15 @@ export declare abstract class BaseAdapter implements StorageAdapter {
|
|
|
62
69
|
* Subscribe to changes (if supported)
|
|
63
70
|
*/
|
|
64
71
|
subscribe(callback: SubscriptionCallback): UnsubscribeFunction;
|
|
72
|
+
/**
|
|
73
|
+
* Whether any subscriber is currently attached to this adapter's change
|
|
74
|
+
* stream. Adapters that talk to a slow backend (native bridge, network) use
|
|
75
|
+
* this to avoid a wasted read-before-write: fetching the previous value just
|
|
76
|
+
* to populate a change event is pointless when nobody is listening. When a
|
|
77
|
+
* subscriber IS attached, callers must still capture the old value so the
|
|
78
|
+
* emitted change is complete. See `SqliteAdapter.set`/`remove`.
|
|
79
|
+
*/
|
|
80
|
+
protected hasChangeListeners(): boolean;
|
|
65
81
|
/**
|
|
66
82
|
* Emit change event
|
|
67
83
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAdapter.d.ts","sourceRoot":"","sources":["../../src/core/BaseAdapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,mBAAmB,EAEnB,YAAY,EACZ,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,YAAY,EAA4B,MAAM,SAAS,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,8BAAsB,WAAY,YAAW,cAAc;IAC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O,CAAC,IAAI,CAAC;IAM5B,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IACpD,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvE,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,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/BaseAdapter.js
CHANGED
|
@@ -38,17 +38,27 @@ export class BaseAdapter {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Clean up expired items
|
|
41
|
+
* Clean up expired items, returning how many were removed.
|
|
42
|
+
*
|
|
43
|
+
* Default implementation is a per-key sweep (enumerate keys, drop the expired
|
|
44
|
+
* ones). Backends that can filter expired rows in the storage engine itself
|
|
45
|
+
* (e.g. SQLite) override this with a single bulk delete — and because such a
|
|
46
|
+
* backend's `keys()` no longer surfaces expired entries, this per-key sweep
|
|
47
|
+
* would not see them anyway. Called by the automatic TTL tick and by
|
|
48
|
+
* `Strata.cleanupExpired()`.
|
|
42
49
|
*/
|
|
43
50
|
async cleanupExpired() {
|
|
44
51
|
const now = Date.now();
|
|
45
52
|
const keys = await this.keys();
|
|
53
|
+
let removed = 0;
|
|
46
54
|
for (const key of keys) {
|
|
47
55
|
const item = await this.get(key);
|
|
48
56
|
if (item?.expires && item.expires <= now) {
|
|
49
57
|
await this.remove(key);
|
|
58
|
+
removed++;
|
|
50
59
|
}
|
|
51
60
|
}
|
|
61
|
+
return removed;
|
|
52
62
|
}
|
|
53
63
|
/**
|
|
54
64
|
* Check if value is expired
|
|
@@ -135,6 +145,13 @@ export class BaseAdapter {
|
|
|
135
145
|
shouldDelete = false;
|
|
136
146
|
}
|
|
137
147
|
}
|
|
148
|
+
if (shouldDelete && options?.olderThan !== undefined) {
|
|
149
|
+
const value = await this.get(key);
|
|
150
|
+
const olderThan = options.olderThan instanceof Date ? options.olderThan.getTime() : options.olderThan;
|
|
151
|
+
if (!value || value.created >= olderThan) {
|
|
152
|
+
shouldDelete = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
138
155
|
if (shouldDelete) {
|
|
139
156
|
await this.remove(key);
|
|
140
157
|
}
|
|
@@ -194,6 +211,17 @@ export class BaseAdapter {
|
|
|
194
211
|
this.eventEmitter.off('change', handler);
|
|
195
212
|
};
|
|
196
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Whether any subscriber is currently attached to this adapter's change
|
|
216
|
+
* stream. Adapters that talk to a slow backend (native bridge, network) use
|
|
217
|
+
* this to avoid a wasted read-before-write: fetching the previous value just
|
|
218
|
+
* to populate a change event is pointless when nobody is listening. When a
|
|
219
|
+
* subscriber IS attached, callers must still capture the old value so the
|
|
220
|
+
* emitted change is complete. See `SqliteAdapter.set`/`remove`.
|
|
221
|
+
*/
|
|
222
|
+
hasChangeListeners() {
|
|
223
|
+
return this.eventEmitter.listenerCount('change') > 0;
|
|
224
|
+
}
|
|
197
225
|
/**
|
|
198
226
|
* Emit change event
|
|
199
227
|
*/
|
package/dist/core/Strata.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Strata Storage - Main entry point
|
|
3
3
|
* Zero-dependency universal storage solution
|
|
4
4
|
*/
|
|
5
|
-
import type { StrataConfig, StorageAdapter, StorageOptions, StorageType, Platform, SizeInfo, ClearOptions, ExportOptions, ImportOptions, SubscriptionCallback, UnsubscribeFunction, QueryCondition, StorageCapabilities } from
|
|
6
|
-
import { AdapterRegistry } from
|
|
5
|
+
import type { StrataConfig, StorageAdapter, StorageOptions, StorageType, Platform, SizeInfo, ClearOptions, ExportOptions, ImportOptions, SubscriptionCallback, UnsubscribeFunction, QueryCondition, QueryOptions, StorageCapabilities } from "../types/index.js";
|
|
6
|
+
import { AdapterRegistry } from "./AdapterRegistry.js";
|
|
7
7
|
/**
|
|
8
8
|
* Main Strata class - unified storage interface
|
|
9
9
|
*/
|
|
@@ -17,9 +17,11 @@ export declare class Strata {
|
|
|
17
17
|
private compressionManager?;
|
|
18
18
|
private syncManager?;
|
|
19
19
|
private ttlManager?;
|
|
20
|
+
private readonly queryEngine;
|
|
20
21
|
private _initialized;
|
|
21
22
|
private _readyPromise?;
|
|
22
23
|
private _autoBackupTimer?;
|
|
24
|
+
private _ttlCleanupTimer?;
|
|
23
25
|
constructor(config?: StrataConfig);
|
|
24
26
|
/**
|
|
25
27
|
* Check if Strata has been initialized
|
|
@@ -49,7 +51,7 @@ export declare class Strata {
|
|
|
49
51
|
* @param options - Storage options
|
|
50
52
|
* @param options.storage - Specific storage type to use (e.g., 'localStorage', 'indexedDB')
|
|
51
53
|
* @param options.decrypt - Whether to decrypt the value (default: auto-detect)
|
|
52
|
-
* @param options.
|
|
54
|
+
* @param options.encryptionPassword - Password for decryption (uses config password if not provided)
|
|
53
55
|
* @returns The stored value or null if not found
|
|
54
56
|
* @throws {StorageError} If the storage adapter is not available
|
|
55
57
|
* @throws {EncryptionError} If decryption fails
|
|
@@ -64,11 +66,18 @@ export declare class Strata {
|
|
|
64
66
|
*
|
|
65
67
|
* // Get encrypted value
|
|
66
68
|
* const value = await storage.get('secure-key', {
|
|
67
|
-
*
|
|
69
|
+
* encryptionPassword: 'myPassword'
|
|
68
70
|
* });
|
|
69
71
|
* ```
|
|
70
72
|
*/
|
|
71
73
|
get<T = unknown>(key: string, options?: StorageOptions): Promise<T | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Reverse the write-time transform pipeline on a stored wrapper: decrypt (if
|
|
76
|
+
* encrypted) and then decompress (if compressed). Shared by get() and query()
|
|
77
|
+
* so query results are decoded identically to direct reads. Returns the raw
|
|
78
|
+
* encrypted payload when `skipDecryption` is set.
|
|
79
|
+
*/
|
|
80
|
+
private decodeStoredValue;
|
|
72
81
|
/**
|
|
73
82
|
* Set a value in storage
|
|
74
83
|
*
|
|
@@ -172,6 +181,8 @@ export declare class Strata {
|
|
|
172
181
|
* ```
|
|
173
182
|
*/
|
|
174
183
|
clear(options?: ClearOptions & StorageOptions): Promise<void>;
|
|
184
|
+
/** Expiry check that works before the TTL manager exists (e.g. pre-init). */
|
|
185
|
+
private isItemExpired;
|
|
175
186
|
/**
|
|
176
187
|
* Get all keys from storage
|
|
177
188
|
*
|
|
@@ -216,7 +227,7 @@ export declare class Strata {
|
|
|
216
227
|
/**
|
|
217
228
|
* Get storage size information
|
|
218
229
|
*/
|
|
219
|
-
size(detailed?: boolean): Promise<SizeInfo>;
|
|
230
|
+
size(detailed?: boolean, options?: StorageOptions): Promise<SizeInfo>;
|
|
220
231
|
/**
|
|
221
232
|
* Subscribe to storage changes
|
|
222
233
|
*/
|
|
@@ -224,14 +235,18 @@ export declare class Strata {
|
|
|
224
235
|
/**
|
|
225
236
|
* Query storage (if supported)
|
|
226
237
|
*/
|
|
227
|
-
query<T = unknown>(condition: QueryCondition, options?: StorageOptions): Promise<Array<{
|
|
238
|
+
query<T = unknown>(condition: QueryCondition, options?: StorageOptions & QueryOptions): Promise<Array<{
|
|
228
239
|
key: string;
|
|
229
240
|
value: T;
|
|
230
241
|
}>>;
|
|
242
|
+
/** Apply QueryOptions (sort → skip → limit → select) to decoded query results. */
|
|
243
|
+
private applyQueryOptions;
|
|
231
244
|
/**
|
|
232
245
|
* Export storage data
|
|
233
246
|
*/
|
|
234
247
|
export(options?: ExportOptions): Promise<string>;
|
|
248
|
+
/** Detect a full StorageValue wrapper (e.g. from export({ includeMetadata })). */
|
|
249
|
+
private isStorageValueWrapper;
|
|
235
250
|
/**
|
|
236
251
|
* Import storage data
|
|
237
252
|
*/
|
|
@@ -294,11 +309,19 @@ export declare class Strata {
|
|
|
294
309
|
*
|
|
295
310
|
* @example
|
|
296
311
|
* ```typescript
|
|
297
|
-
* import { MyCustomAdapter } from
|
|
312
|
+
* import { MyCustomAdapter } from "./my-adapter.js";
|
|
298
313
|
* storage.registerAdapter(new MyCustomAdapter());
|
|
299
314
|
* ```
|
|
300
315
|
*/
|
|
301
316
|
registerAdapter(adapter: StorageAdapter): void;
|
|
317
|
+
/**
|
|
318
|
+
* Initialize and attach any registered adapters that are not yet active, then
|
|
319
|
+
* re-pick the default adapter. Call this after `registerAdapter()` on an
|
|
320
|
+
* already-initialized instance (e.g. `registerCapacitorAdapters()`), so the
|
|
321
|
+
* newly registered adapters become available to multi-adapter operations
|
|
322
|
+
* (keys/clear/size/subscribe) — not just to explicit `{ storage }` calls.
|
|
323
|
+
*/
|
|
324
|
+
refreshAdapters(): Promise<void>;
|
|
302
325
|
/**
|
|
303
326
|
* Get the adapter registry (for advanced use cases)
|
|
304
327
|
* @internal
|
|
@@ -310,6 +333,16 @@ export declare class Strata {
|
|
|
310
333
|
close(): Promise<void>;
|
|
311
334
|
private normalizeConfig;
|
|
312
335
|
private detectPlatform;
|
|
336
|
+
/** Effective namespace for an operation: a per-call value wins over the
|
|
337
|
+
* instance default (`config.namespace`). Empty strings are treated as none. */
|
|
338
|
+
private effectiveNamespace;
|
|
339
|
+
/** Map a logical key to the physical key actually stored (namespace-prefixed). */
|
|
340
|
+
private resolveKey;
|
|
341
|
+
/** Reduce physical keys to the logical keys owned by `ns`, then apply pattern. */
|
|
342
|
+
private scopeAndStripKeys;
|
|
343
|
+
/** Pattern matcher mirroring BaseAdapter.filterKeys (prefix / glob / RegExp). */
|
|
344
|
+
private filterKeysByPattern;
|
|
345
|
+
private static normalizeTimestamp;
|
|
313
346
|
private getDefaultStorages;
|
|
314
347
|
private initializeAdapters;
|
|
315
348
|
private selectDefaultAdapter;
|
|
@@ -320,6 +353,7 @@ export declare class Strata {
|
|
|
320
353
|
* natively via the `storage` event and sessionStorage is per-tab, so both are
|
|
321
354
|
* skipped here to avoid redundant re-writes.
|
|
322
355
|
*/
|
|
356
|
+
private cleanupAllAdapters;
|
|
323
357
|
private applyRemoteChange;
|
|
324
358
|
private mirrorAdapters;
|
|
325
359
|
private mirrorWrite;
|
|
@@ -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,EAGpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
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,YAAY,EACZ,mBAAmB,EAGpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA0BpD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,QAAQ,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