@towns-protocol/web3 0.0.452 → 0.0.455
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/dist/cache/EntitlementCache.d.ts +16 -11
- package/dist/cache/EntitlementCache.d.ts.map +1 -1
- package/dist/cache/EntitlementCache.js +49 -27
- package/dist/cache/EntitlementCache.js.map +1 -1
- package/dist/cache/ICacheStorage.d.ts +44 -0
- package/dist/cache/ICacheStorage.d.ts.map +1 -0
- package/dist/cache/ICacheStorage.js +2 -0
- package/dist/cache/ICacheStorage.js.map +1 -0
- package/dist/cache/KVCacheStorage.d.ts +79 -0
- package/dist/cache/KVCacheStorage.d.ts.map +1 -0
- package/dist/cache/KVCacheStorage.js +227 -0
- package/dist/cache/KVCacheStorage.js.map +1 -0
- package/dist/cache/Keyable.d.ts +15 -26
- package/dist/cache/Keyable.d.ts.map +1 -1
- package/dist/cache/Keyable.js +57 -42
- package/dist/cache/Keyable.js.map +1 -1
- package/dist/cache/SimpleCache.d.ts +18 -13
- package/dist/cache/SimpleCache.d.ts.map +1 -1
- package/dist/cache/SimpleCache.js +58 -39
- package/dist/cache/SimpleCache.js.map +1 -1
- package/dist/cache/TTLCacheStorage.d.ts +19 -0
- package/dist/cache/TTLCacheStorage.d.ts.map +1 -0
- package/dist/cache/TTLCacheStorage.js +40 -0
- package/dist/cache/TTLCacheStorage.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/space/IEntitlementsShim.d.ts +2 -7
- package/dist/space/IEntitlementsShim.d.ts.map +1 -1
- package/dist/space/IEntitlementsShim.js +4 -11
- package/dist/space/IEntitlementsShim.js.map +1 -1
- package/dist/space/ITippingShim.d.ts +1 -1
- package/dist/space/ITippingShim.d.ts.map +1 -1
- package/dist/space/ITippingShim.js +2 -2
- package/dist/space/ITippingShim.js.map +1 -1
- package/dist/space/OwnableFacetShim.d.ts +2 -7
- package/dist/space/OwnableFacetShim.d.ts.map +1 -1
- package/dist/space/OwnableFacetShim.js +4 -11
- package/dist/space/OwnableFacetShim.js.map +1 -1
- package/dist/space/Space.d.ts +2 -1
- package/dist/space/Space.d.ts.map +1 -1
- package/dist/space/Space.js +3 -3
- package/dist/space/Space.js.map +1 -1
- package/dist/space/entitlements/ConvertersEntitlements.js +1 -1
- package/dist/space/entitlements/ConvertersEntitlements.js.map +1 -1
- package/dist/space-dapp/SpaceDapp.d.ts +16 -11
- package/dist/space-dapp/SpaceDapp.d.ts.map +1 -1
- package/dist/space-dapp/SpaceDapp.js +67 -57
- package/dist/space-dapp/SpaceDapp.js.map +1 -1
- package/dist/space-dapp/SpaceDappFactory.d.ts +2 -2
- package/dist/space-dapp/SpaceDappFactory.d.ts.map +1 -1
- package/dist/space-dapp/SpaceDappFactory.js +2 -2
- package/dist/space-dapp/SpaceDappFactory.js.map +1 -1
- package/dist/space-owner/SpaceOwner.d.ts +2 -1
- package/dist/space-owner/SpaceOwner.d.ts.map +1 -1
- package/dist/space-owner/SpaceOwner.js +5 -12
- package/dist/space-owner/SpaceOwner.js.map +1 -1
- package/dist/space-registrar/SpaceRegistrar.d.ts +3 -1
- package/dist/space-registrar/SpaceRegistrar.d.ts.map +1 -1
- package/dist/space-registrar/SpaceRegistrar.js +4 -2
- package/dist/space-registrar/SpaceRegistrar.js.map +1 -1
- package/dist/towns-token/TownsToken.d.ts +2 -1
- package/dist/towns-token/TownsToken.d.ts.map +1 -1
- package/dist/towns-token/TownsToken.js +4 -11
- package/dist/towns-token/TownsToken.js.map +1 -1
- package/package.json +5 -4
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { Keyable } from './Keyable';
|
|
2
|
+
import { CreateStorageFn } from './ICacheStorage';
|
|
2
3
|
export interface CacheResult<V> {
|
|
3
4
|
value: V;
|
|
4
5
|
cacheHit: boolean;
|
|
5
6
|
isPositive: boolean;
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
export interface EntitlementCacheOptions<V> {
|
|
9
|
+
positiveCacheTTLSeconds?: number;
|
|
10
|
+
negativeCacheTTLSeconds?: number;
|
|
11
|
+
positiveCacheSize?: number;
|
|
12
|
+
negativeCacheSize?: number;
|
|
13
|
+
/** Factory function to create storage. Defaults to in-memory TTLCacheStorage */
|
|
14
|
+
createStorageFn: CreateStorageFn<CacheResult<V>> | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare class EntitlementCache<V> {
|
|
17
|
+
private readonly negativeStorage;
|
|
18
|
+
private readonly positiveStorage;
|
|
19
|
+
private readonly pendingFetches;
|
|
20
|
+
constructor(options: EntitlementCacheOptions<V>);
|
|
21
|
+
invalidate(keyable: Keyable): Promise<void>;
|
|
22
|
+
executeUsingCache(keyable: Keyable, onCacheMiss: (k: Keyable) => Promise<CacheResult<V>>): Promise<CacheResult<V>>;
|
|
18
23
|
}
|
|
19
24
|
//# sourceMappingURL=EntitlementCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntitlementCache.d.ts","sourceRoot":"","sources":["../../src/cache/EntitlementCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntitlementCache.d.ts","sourceRoot":"","sources":["../../src/cache/EntitlementCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC1B,KAAK,EAAE,CAAC,CAAA;IACR,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACtC,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gFAAgF;IAChF,eAAe,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;CAC/D;AAED,qBAAa,gBAAgB,CAAC,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6C;IAC7E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6C;IAC7E,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkD;gBAErE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAqBzC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,iBAAiB,CACnB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CA2C7B"}
|
|
@@ -1,46 +1,68 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createDefaultStorage } from './TTLCacheStorage';
|
|
2
2
|
export class EntitlementCache {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
negativeStorage;
|
|
4
|
+
positiveStorage;
|
|
5
|
+
pendingFetches = new Map();
|
|
5
6
|
constructor(options) {
|
|
6
7
|
const positiveCacheTTLSeconds = options?.positiveCacheTTLSeconds ?? 15 * 60;
|
|
7
8
|
const negativeCacheTTLSeconds = options?.negativeCacheTTLSeconds ?? 2;
|
|
8
9
|
const positiveCacheSize = options?.positiveCacheSize ?? 10000;
|
|
9
10
|
const negativeCacheSize = options?.negativeCacheSize ?? 10000;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const createFn = options?.createStorageFn ?? createDefaultStorage;
|
|
12
|
+
this.negativeStorage = createFn({
|
|
13
|
+
ttlMs: negativeCacheTTLSeconds * 1000,
|
|
14
|
+
maxSize: negativeCacheSize,
|
|
15
|
+
keyPostfix: 'neg',
|
|
13
16
|
});
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
this.positiveStorage = createFn({
|
|
18
|
+
ttlMs: positiveCacheTTLSeconds * 1000,
|
|
19
|
+
maxSize: positiveCacheSize,
|
|
20
|
+
keyPostfix: 'pos',
|
|
17
21
|
});
|
|
18
22
|
}
|
|
19
|
-
invalidate(keyable) {
|
|
23
|
+
async invalidate(keyable) {
|
|
20
24
|
const key = keyable.toKey();
|
|
21
|
-
|
|
22
|
-
this.
|
|
25
|
+
// Clear pending fetch first to prevent returning stale in-flight data
|
|
26
|
+
this.pendingFetches.delete(key);
|
|
27
|
+
await Promise.all([this.negativeStorage.delete(key), this.positiveStorage.delete(key)]);
|
|
23
28
|
}
|
|
24
29
|
async executeUsingCache(keyable, onCacheMiss) {
|
|
25
30
|
const key = keyable.toKey();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// 1. Check for pending fetch FIRST (synchronous check before any await)
|
|
32
|
+
// This prevents race conditions where concurrent calls interleave
|
|
33
|
+
const pendingPromise = this.pendingFetches.get(key);
|
|
34
|
+
if (pendingPromise) {
|
|
35
|
+
return pendingPromise;
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
// 2. Create promise that checks caches then fetches if needed
|
|
38
|
+
// Store it synchronously BEFORE any await to prevent races
|
|
39
|
+
const operationPromise = (async () => {
|
|
40
|
+
const negativeCacheResult = await this.negativeStorage.get(key);
|
|
41
|
+
if (negativeCacheResult !== undefined) {
|
|
42
|
+
negativeCacheResult.cacheHit = true;
|
|
43
|
+
return negativeCacheResult;
|
|
44
|
+
}
|
|
45
|
+
const positiveCacheResult = await this.positiveStorage.get(key);
|
|
46
|
+
if (positiveCacheResult !== undefined) {
|
|
47
|
+
positiveCacheResult.cacheHit = true;
|
|
48
|
+
return positiveCacheResult;
|
|
49
|
+
}
|
|
50
|
+
const result = await onCacheMiss(keyable);
|
|
51
|
+
if (result.isPositive) {
|
|
52
|
+
await this.positiveStorage.set(key, result);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await this.negativeStorage.set(key, result);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
})();
|
|
59
|
+
this.pendingFetches.set(key, operationPromise);
|
|
60
|
+
try {
|
|
61
|
+
return await operationPromise;
|
|
35
62
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.positiveCache.set(key, result);
|
|
63
|
+
finally {
|
|
64
|
+
this.pendingFetches.delete(key);
|
|
39
65
|
}
|
|
40
|
-
else {
|
|
41
|
-
this.negativeCache.set(key, result);
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
66
|
}
|
|
45
67
|
}
|
|
46
68
|
//# sourceMappingURL=EntitlementCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntitlementCache.js","sourceRoot":"","sources":["../../src/cache/EntitlementCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntitlementCache.js","sourceRoot":"","sources":["../../src/cache/EntitlementCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAiBxD,MAAM,OAAO,gBAAgB;IACR,eAAe,CAA6C;IAC5D,eAAe,CAA6C;IAC5D,cAAc,GAAyC,IAAI,GAAG,EAAE,CAAA;IAEjF,YAAY,OAAmC;QAC3C,MAAM,uBAAuB,GAAG,OAAO,EAAE,uBAAuB,IAAI,EAAE,GAAG,EAAE,CAAA;QAC3E,MAAM,uBAAuB,GAAG,OAAO,EAAE,uBAAuB,IAAI,CAAC,CAAA;QACrE,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,KAAK,CAAA;QAC7D,MAA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;YAC/D,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;gBACpC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAA;gBACnC,OAAO,mBAAmB,CAAA;YAC9B,CAAC;YAED,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC/D,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;gBACpC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAA;gBACnC,OAAO,mBAAmB,CAAA;YAC9B,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;YACzC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YAC/C,CAAC;YAED,OAAO,MAAM,CAAA;QACjB,CAAC,CAAC,EAAE,CAAA;QAEJ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;QAE9C,IAAI,CAAC;YACD,OAAO,MAAM,gBAAgB,CAAA;QACjC,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnC,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for cache storage backends
|
|
3
|
+
* This abstracts the underlying storage mechanism (TTLCache, KV, Redis, etc.)
|
|
4
|
+
*/
|
|
5
|
+
export interface ICacheStorage<V> {
|
|
6
|
+
/**
|
|
7
|
+
* Get a value from the cache
|
|
8
|
+
* Returns undefined if not found or expired
|
|
9
|
+
*/
|
|
10
|
+
get(key: string): Promise<V | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Set a value in the cache
|
|
13
|
+
* @param key Cache key
|
|
14
|
+
* @param value Value to store
|
|
15
|
+
* @param ttlMs Time-to-live in milliseconds (optional, uses default if not provided)
|
|
16
|
+
*/
|
|
17
|
+
set(key: string, value: V, ttlMs?: number): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Delete a value from the cache
|
|
20
|
+
*/
|
|
21
|
+
delete(key: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Clear all values from the cache (optional - not all implementations support this)
|
|
24
|
+
*/
|
|
25
|
+
clear?(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for creating cache storage instances
|
|
29
|
+
*/
|
|
30
|
+
export interface CacheStorageConfig {
|
|
31
|
+
/** Default TTL in milliseconds */
|
|
32
|
+
ttlMs?: number;
|
|
33
|
+
/** Maximum number of entries (for size-limited caches) */
|
|
34
|
+
maxSize?: number;
|
|
35
|
+
/** Key postfix (for differentiating things like positive/negative entitlements) */
|
|
36
|
+
keyPostfix?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Factory function type for creating cache storage instances
|
|
40
|
+
* This allows injection of different storage backends (memory, KV, etc.)
|
|
41
|
+
* keys are unique per instantiation, and unique globally once `keyPostfix` is applied
|
|
42
|
+
*/
|
|
43
|
+
export type CreateStorageFn<V> = (config: CacheStorageConfig) => ICacheStorage<V>;
|
|
44
|
+
//# sourceMappingURL=ICacheStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICacheStorage.d.ts","sourceRoot":"","sources":["../../src/cache/ICacheStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC5B;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IAExC;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzD;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElC;;OAEG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,kBAAkB,KAAK,aAAa,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICacheStorage.js","sourceRoot":"","sources":["../../src/cache/ICacheStorage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { CacheStorageConfig, CreateStorageFn, ICacheStorage } from './ICacheStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options specific to KVCacheStorage
|
|
4
|
+
*/
|
|
5
|
+
export interface KVCacheStorageConfig extends CacheStorageConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Disable the local in-memory cache layer.
|
|
8
|
+
* When enabled (default), a local TTLCache is used as a synchronous first-level cache
|
|
9
|
+
* before falling back to KV. This is intended for use in workers where the local
|
|
10
|
+
* cache only exists for the duration of a single request, providing fast access
|
|
11
|
+
* for repeated reads within the same request without hitting KV multiple times.
|
|
12
|
+
*/
|
|
13
|
+
disableLocalCache?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cloudflare KV namespace interface
|
|
17
|
+
*/
|
|
18
|
+
export interface KVNamespace {
|
|
19
|
+
get(key: string, options?: {
|
|
20
|
+
type?: 'text' | 'json' | 'arrayBuffer' | 'stream';
|
|
21
|
+
}): Promise<string | null>;
|
|
22
|
+
put(key: string, value: string, options?: {
|
|
23
|
+
expirationTtl?: number;
|
|
24
|
+
expiration?: number;
|
|
25
|
+
metadata?: unknown;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
delete(key: string): Promise<void>;
|
|
28
|
+
list(options?: {
|
|
29
|
+
prefix?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
cursor?: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
keys: {
|
|
34
|
+
name: string;
|
|
35
|
+
expiration?: number;
|
|
36
|
+
metadata?: unknown;
|
|
37
|
+
}[];
|
|
38
|
+
list_complete: boolean;
|
|
39
|
+
cursor?: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cloudflare KV-backed cache storage implementation
|
|
44
|
+
* Implements ICacheStorage from @towns-protocol/web3 for use as a SpaceDapp cache backend
|
|
45
|
+
*
|
|
46
|
+
* This implementation includes an optional local in-memory cache layer (enabled by default)
|
|
47
|
+
* that sits in front of KV. This is intended for use in Cloudflare Workers or similar
|
|
48
|
+
* serverless environments where the local cache only exists for the duration of a single
|
|
49
|
+
* request. This provides fast access for repeated reads within the same request without
|
|
50
|
+
* hitting KV multiple times, while still benefiting from KV's persistence across requests.
|
|
51
|
+
*/
|
|
52
|
+
export declare class KVCacheStorage<V> implements ICacheStorage<V> {
|
|
53
|
+
private readonly kv;
|
|
54
|
+
private readonly keyPostfix;
|
|
55
|
+
private readonly defaultTtlMs;
|
|
56
|
+
private readonly minKVTtlSeconds;
|
|
57
|
+
/**
|
|
58
|
+
* Local in-memory cache that serves as a synchronous first-level cache before KV.
|
|
59
|
+
* In a worker context, this cache only exists for the duration of the request,
|
|
60
|
+
* providing fast repeated access without additional KV reads.
|
|
61
|
+
* TTLCache handles expiration automatically via its built-in TTL support.
|
|
62
|
+
*/
|
|
63
|
+
private readonly localCache;
|
|
64
|
+
constructor(kv: KVNamespace, config: KVCacheStorageConfig);
|
|
65
|
+
private getKey;
|
|
66
|
+
get(key: string): Promise<V | undefined>;
|
|
67
|
+
set(key: string, value: V, ttlMs?: number): Promise<void>;
|
|
68
|
+
delete(key: string): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a factory function that creates KV-backed cache storage instances
|
|
72
|
+
* This is what you pass to SpaceDapp as the createStorageFn parameter
|
|
73
|
+
*
|
|
74
|
+
* @param kv The Cloudflare or Hosting provider KV namespace
|
|
75
|
+
* @param options Optional configuration for the KV storage (e.g., disableLocalCache)
|
|
76
|
+
* @returns A factory function compatible with SpaceDapp's createStorageFn parameter
|
|
77
|
+
*/
|
|
78
|
+
export declare function createKVStorageFactory<V = unknown>(kv: KVNamespace, options?: Pick<KVCacheStorageConfig, 'disableLocalCache'>): CreateStorageFn<V>;
|
|
79
|
+
//# sourceMappingURL=KVCacheStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KVCacheStorage.d.ts","sourceRoot":"","sources":["../../src/cache/KVCacheStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAKpF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC5D;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAoHD;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,GAAG,CACC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAA;KAAE,GAChE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IACzB,GAAG,CACC,GAAG,EAAE,MAAM,EAC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AAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BzD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAe3C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,OAAO,EAC9C,EAAE,EAAE,WAAW,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,GAC1D,eAAe,CAAC,CAAC,CAAC,CAKpB"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import SuperJson from 'superjson';
|
|
3
|
+
import TTLCache from '@isaacs/ttlcache';
|
|
4
|
+
import { dlogger } from '@towns-protocol/utils';
|
|
5
|
+
const logger = dlogger('web3:kvcache');
|
|
6
|
+
// Register ethers BigNumber with SuperJSON
|
|
7
|
+
SuperJson.registerCustom({
|
|
8
|
+
isApplicable: (v) => BigNumber.isBigNumber(v),
|
|
9
|
+
serialize: (v) => v.toHexString(),
|
|
10
|
+
deserialize: (v) => BigNumber.from(v),
|
|
11
|
+
}, 'ethers.BigNumber');
|
|
12
|
+
/**
|
|
13
|
+
* Detects if a value is an ethers.js struct output (array with named properties).
|
|
14
|
+
* These are arrays that have string-keyed properties in addition to numeric indices.
|
|
15
|
+
*/
|
|
16
|
+
function isEthersStructOutput(value) {
|
|
17
|
+
if (!Array.isArray(value))
|
|
18
|
+
return false;
|
|
19
|
+
const namedKeys = Object.keys(value).filter((key) => isNaN(Number(key)));
|
|
20
|
+
return namedKeys.length > 0;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts ethers.js struct outputs to plain objects for proper serialization.
|
|
24
|
+
* Works recursively for nested structures.
|
|
25
|
+
*/
|
|
26
|
+
function normalizeEthersOutput(value) {
|
|
27
|
+
if (value === null || value === undefined) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
// Let SuperJson's registered BigNumber serializer handle BigNumbers
|
|
31
|
+
// BigNumber properties (_hex, _isBigNumber) are non-enumerable, so Object.entries
|
|
32
|
+
// would return an empty array and corrupt the BigNumber into {}
|
|
33
|
+
if (BigNumber.isBigNumber(value)) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
// Handle ethers struct outputs (arrays with named properties)
|
|
37
|
+
if (isEthersStructOutput(value)) {
|
|
38
|
+
const namedKeys = Object.keys(value).filter((key) => isNaN(Number(key)));
|
|
39
|
+
const obj = { __ethersStruct: true };
|
|
40
|
+
for (const key of namedKeys) {
|
|
41
|
+
obj[key] = normalizeEthersOutput(value[key]);
|
|
42
|
+
}
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
// Handle regular arrays (recurse into elements)
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value.map(normalizeEthersOutput);
|
|
48
|
+
}
|
|
49
|
+
// Handle plain objects (recurse into values)
|
|
50
|
+
if (typeof value === 'object') {
|
|
51
|
+
const obj = {};
|
|
52
|
+
for (const [key, val] of Object.entries(value)) {
|
|
53
|
+
obj[key] = normalizeEthersOutput(val);
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
// Primitives pass through unchanged
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Restores ethers-like struct outputs from normalized objects.
|
|
62
|
+
* The restored object has both array indices and named properties.
|
|
63
|
+
*/
|
|
64
|
+
function denormalizeEthersOutput(value) {
|
|
65
|
+
if (value === null || value === undefined) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
// Preserve BigNumber objects - they've already been deserialized by SuperJson
|
|
69
|
+
// BigNumber properties are non-enumerable, so Object.entries would corrupt them
|
|
70
|
+
if (BigNumber.isBigNumber(value)) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
// Handle normalized ethers struct objects
|
|
74
|
+
if (typeof value === 'object' &&
|
|
75
|
+
!Array.isArray(value) &&
|
|
76
|
+
value.__ethersStruct === true) {
|
|
77
|
+
const valueObj = value;
|
|
78
|
+
const keys = Object.keys(valueObj).filter((k) => k !== '__ethersStruct');
|
|
79
|
+
// Create array-like object with both indices and named properties
|
|
80
|
+
const result = keys.map((key) => denormalizeEthersOutput(valueObj[key]));
|
|
81
|
+
for (let i = 0; i < keys.length; i++) {
|
|
82
|
+
result[keys[i]] = result[i];
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
// Handle regular arrays (recurse into elements)
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
return value.map(denormalizeEthersOutput);
|
|
89
|
+
}
|
|
90
|
+
// Handle plain objects (recurse into values)
|
|
91
|
+
if (typeof value === 'object') {
|
|
92
|
+
const obj = {};
|
|
93
|
+
for (const [key, val] of Object.entries(value)) {
|
|
94
|
+
obj[key] = denormalizeEthersOutput(val);
|
|
95
|
+
}
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
// Primitives pass through unchanged
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Cloudflare KV-backed cache storage implementation
|
|
103
|
+
* Implements ICacheStorage from @towns-protocol/web3 for use as a SpaceDapp cache backend
|
|
104
|
+
*
|
|
105
|
+
* This implementation includes an optional local in-memory cache layer (enabled by default)
|
|
106
|
+
* that sits in front of KV. This is intended for use in Cloudflare Workers or similar
|
|
107
|
+
* serverless environments where the local cache only exists for the duration of a single
|
|
108
|
+
* request. This provides fast access for repeated reads within the same request without
|
|
109
|
+
* hitting KV multiple times, while still benefiting from KV's persistence across requests.
|
|
110
|
+
*/
|
|
111
|
+
export class KVCacheStorage {
|
|
112
|
+
kv;
|
|
113
|
+
keyPostfix;
|
|
114
|
+
defaultTtlMs;
|
|
115
|
+
minKVTtlSeconds = 60; // KV minimum TTL
|
|
116
|
+
/**
|
|
117
|
+
* Local in-memory cache that serves as a synchronous first-level cache before KV.
|
|
118
|
+
* In a worker context, this cache only exists for the duration of the request,
|
|
119
|
+
* providing fast repeated access without additional KV reads.
|
|
120
|
+
* TTLCache handles expiration automatically via its built-in TTL support.
|
|
121
|
+
*/
|
|
122
|
+
localCache;
|
|
123
|
+
constructor(kv, config) {
|
|
124
|
+
this.kv = kv;
|
|
125
|
+
this.keyPostfix = config?.keyPostfix ?? '';
|
|
126
|
+
this.defaultTtlMs = config?.ttlMs ?? 15 * 60 * 1000; // 15 minutes default
|
|
127
|
+
// Initialize local cache unless explicitly disabled
|
|
128
|
+
// Uses the same TTL and maxSize config as the KV cache
|
|
129
|
+
this.localCache = config?.disableLocalCache
|
|
130
|
+
? null
|
|
131
|
+
: new TTLCache({
|
|
132
|
+
ttl: this.defaultTtlMs,
|
|
133
|
+
max: config?.maxSize ?? 10_000,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getKey(key) {
|
|
137
|
+
return this.keyPostfix ? `${key}:${this.keyPostfix}` : key;
|
|
138
|
+
}
|
|
139
|
+
async get(key) {
|
|
140
|
+
try {
|
|
141
|
+
// Check local cache first if enabled (synchronous)
|
|
142
|
+
if (this.localCache) {
|
|
143
|
+
const localValue = this.localCache.get(key);
|
|
144
|
+
if (localValue !== undefined) {
|
|
145
|
+
return localValue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const cached = await this.kv.get(this.getKey(key));
|
|
149
|
+
if (cached === null) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const entry = SuperJson.parse(cached);
|
|
153
|
+
// Check if expired (belt-and-suspenders with KV TTL)
|
|
154
|
+
if (entry.expiresAt <= Date.now()) {
|
|
155
|
+
// Expired - clean up and return undefined
|
|
156
|
+
void this.kv.delete(this.getKey(key));
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
// Denormalize ethers.js struct outputs back to array-like objects with named properties
|
|
160
|
+
const value = denormalizeEthersOutput(entry.value);
|
|
161
|
+
// Populate local cache on successful KV fetch with remaining TTL
|
|
162
|
+
if (this.localCache) {
|
|
163
|
+
const remainingTtlMs = entry.expiresAt - Date.now();
|
|
164
|
+
if (remainingTtlMs > 0) {
|
|
165
|
+
this.localCache.set(key, value, { ttl: remainingTtlMs });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
logger.error('KVCacheStorage.get error:', error);
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async set(key, value, ttlMs) {
|
|
176
|
+
try {
|
|
177
|
+
const effectiveTtlMs = ttlMs ?? this.defaultTtlMs;
|
|
178
|
+
const expiresAt = Date.now() + effectiveTtlMs;
|
|
179
|
+
// Set in local cache if enabled (synchronous)
|
|
180
|
+
if (this.localCache) {
|
|
181
|
+
this.localCache.set(key, value, { ttl: effectiveTtlMs });
|
|
182
|
+
}
|
|
183
|
+
// Normalize ethers.js struct outputs to plain objects for proper serialization
|
|
184
|
+
const normalizedValue = normalizeEthersOutput(value);
|
|
185
|
+
const entry = {
|
|
186
|
+
value: normalizedValue,
|
|
187
|
+
expiresAt,
|
|
188
|
+
};
|
|
189
|
+
// KV requires minimum 60 second TTL
|
|
190
|
+
const kvTtlSeconds = Math.max(this.minKVTtlSeconds, Math.ceil(effectiveTtlMs / 1000));
|
|
191
|
+
const valueStr = SuperJson.stringify(entry);
|
|
192
|
+
await this.kv.put(this.getKey(key), valueStr, {
|
|
193
|
+
expirationTtl: kvTtlSeconds,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger.error('KVCacheStorage.set error:', error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async delete(key) {
|
|
201
|
+
try {
|
|
202
|
+
// Delete from local cache if enabled (synchronous)
|
|
203
|
+
if (this.localCache) {
|
|
204
|
+
this.localCache.delete(key);
|
|
205
|
+
}
|
|
206
|
+
await this.kv.delete(this.getKey(key));
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
logger.error('KVCacheStorage.delete error:', error);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Create a factory function that creates KV-backed cache storage instances
|
|
215
|
+
* This is what you pass to SpaceDapp as the createStorageFn parameter
|
|
216
|
+
*
|
|
217
|
+
* @param kv The Cloudflare or Hosting provider KV namespace
|
|
218
|
+
* @param options Optional configuration for the KV storage (e.g., disableLocalCache)
|
|
219
|
+
* @returns A factory function compatible with SpaceDapp's createStorageFn parameter
|
|
220
|
+
*/
|
|
221
|
+
export function createKVStorageFactory(kv, options) {
|
|
222
|
+
return (config) => {
|
|
223
|
+
// Combine base prefix with config prefix and options
|
|
224
|
+
return new KVCacheStorage(kv, { ...config, ...options });
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=KVCacheStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KVCacheStorage.js","sourceRoot":"","sources":["../../src/cache/KVCacheStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAE/C,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAgBtC,2CAA2C;AAC3C,SAAS,CAAC,cAAc,CACpB;IACI,YAAY,EAAE,CAAC,CAAC,EAAkB,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7D,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE;IACjC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;CACxC,EACD,kBAAkB,CACrB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E,QAAQ,EAAE;gBAC1C,aAAa,EAAE,YAAY;aAC9B,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;QACpD,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACpB,IAAI,CAAC;YACD,mDAAmD;YACnD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC/B,CAAC;YAED,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAA;QACvD,CAAC;IACL,CAAC;CAIJ;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAClC,EAAe,EACf,OAAyD;IAEzD,OAAO,CAAC,MAA0B,EAAoB,EAAE;QACpD,qDAAqD;QACrD,OAAO,IAAI,cAAc,CAAI,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAA;AACL,CAAC"}
|
package/dist/cache/Keyable.d.ts
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { Permission } from '../types/ContractTypes';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare class BannedTokenIdsRequest implements Keyable {
|
|
7
|
-
spaceId: string;
|
|
8
|
-
constructor(spaceId: string);
|
|
9
|
-
toKey(): string;
|
|
10
|
-
}
|
|
11
|
-
export declare class OwnerOfTokenRequest implements Keyable {
|
|
12
|
-
spaceId: string;
|
|
13
|
-
tokenId: ethers.BigNumber;
|
|
14
|
-
constructor(spaceId: string, tokenId: ethers.BigNumber);
|
|
15
|
-
toKey(): string;
|
|
16
|
-
}
|
|
17
|
-
export declare class IsTokenBanned implements Keyable {
|
|
18
|
-
spaceId: string;
|
|
19
|
-
tokenId: ethers.BigNumber;
|
|
20
|
-
constructor(spaceId: string, tokenId: ethers.BigNumber);
|
|
21
|
-
toKey(): string;
|
|
22
|
-
}
|
|
23
|
-
export declare class EntitlementRequest implements Keyable {
|
|
24
|
-
spaceId: string;
|
|
25
|
-
channelId: string;
|
|
26
|
-
userId: string;
|
|
27
|
-
permission: Permission;
|
|
28
|
-
constructor(spaceId: string, channelId: string, userId: string, permission: Permission);
|
|
3
|
+
export declare class Keyable {
|
|
4
|
+
private readonly parts;
|
|
5
|
+
constructor(...args: unknown[]);
|
|
29
6
|
toKey(): string;
|
|
7
|
+
static spaceInfoRequest(spaceId: string): Keyable;
|
|
8
|
+
static getEntitlementsRequest(spaceAddress: string): Keyable;
|
|
9
|
+
static ownerRequest(spaceAddress: string): Keyable;
|
|
10
|
+
static balanceOfRequest(accountAddress: string): Keyable;
|
|
11
|
+
static bannedTokenIdsRequest(spaceId: string): Keyable;
|
|
12
|
+
static ownerOfTokenRequest(spaceId: string, tokenId: ethers.BigNumber): Keyable;
|
|
13
|
+
static isTokenBanned(spaceId: string, tokenId: ethers.BigNumber): Keyable;
|
|
14
|
+
static entitlementRequest(spaceId: string, channelId: string, userId: string, permission: Permission): Keyable;
|
|
15
|
+
static spaceEntitlementRequest(spaceId: string, permission: Permission): Keyable;
|
|
16
|
+
static spaceEntitlementEvaluationRequest(spaceId: string, rootKey: string, permission: Permission): Keyable;
|
|
17
|
+
static channelEntitlementRequest(spaceId: string, channelId: string, permission: Permission): Keyable;
|
|
18
|
+
static channelEntitlementEvaluationRequest(spaceId: string, channelNetworkId: string, userId: string, permission: Permission): Keyable;
|
|
30
19
|
}
|
|
31
20
|
//# sourceMappingURL=Keyable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Keyable.d.ts","sourceRoot":"","sources":["../../src/cache/Keyable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"Keyable.d.ts","sourceRoot":"","sources":["../../src/cache/Keyable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,qBAAa,OAAO;IAChB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;gBAErB,GAAG,IAAI,EAAE,OAAO,EAAE;IAI9B,KAAK,IAAI,MAAM;IAiBf,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjD,MAAM,CAAC,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAI5D,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAIlD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAIxD,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAItD,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,GAAG,OAAO;IAI/E,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,GAAG,OAAO;IAIzE,MAAM,CAAC,kBAAkB,CACrB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GACvB,OAAO;IAIV,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAIhF,MAA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