fix(chats): remove null from LRUCache type to satisfy TypeScript constraint
CRITICAL FIX: Resolves TypeScript compilation error preventing npm install
ERROR:
src/Socket/chats.ts(117,52): error TS2344: Type 'IAppStateSyncKeyData | null'
does not satisfy the constraint '{}'. Type 'null' is not assignable to type '{}'.
ROOT CAUSE:
LRUCache v10+ has a generic constraint where value type V must satisfy constraint {}.
The type 'IAppStateSyncKeyData | null' includes null, which doesn't satisfy {}.
ANALYSIS:
The code NEVER caches null values (line 152 only calls set() if key is truthy),
so the | null in the type declaration was unnecessary and incorrect.
SOLUTION:
1. Remove | null from LRUCache type parameter (line 121)
2. Simplify getCachedAppStateSyncKey return (line 143)
3. Add documentation about type safety
VALIDATION:
✓ TypeScript error TS2344 resolved
✓ Logic unchanged: still only caches non-null values
✓ LRUCache.get() still returns undefined for missing keys
✓ Null cache poisoning prevention maintained (commit 4e05e62)
This fix enables successful npm install and build.
https://claude.ai/code/session_01NTVq3RHgGpgKL289JGvw55
This commit is contained in:
+7
-4
@@ -113,8 +113,12 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
*
|
||||
* MEMORY SAFETY: Limited by DEFAULT_CACHE_MAX_KEYS.SIGNAL_STORE with 1-hour TTL.
|
||||
* Auto-purges expired entries to maintain memory bounds.
|
||||
*
|
||||
* TYPE SAFETY: Only successful lookups (non-null values) are cached.
|
||||
* Null/undefined values are NOT cached to prevent blocking newly arrived keys.
|
||||
* LRUCache.get() returns undefined for missing keys.
|
||||
*/
|
||||
const appStateSyncKeyCache = new LRUCache<string, proto.Message.IAppStateSyncKeyData | null>({
|
||||
const appStateSyncKeyCache = new LRUCache<string, proto.Message.IAppStateSyncKeyData>({
|
||||
max: DEFAULT_CACHE_MAX_KEYS.SIGNAL_STORE, // Use constant from Defaults (10,000)
|
||||
ttl: DEFAULT_CACHE_TTLS.MSG_RETRY * 1000, // 1 hour TTL (convert seconds to ms)
|
||||
ttlAutopurge: true, // Automatically remove expired entries
|
||||
@@ -135,9 +139,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
// Use get() directly to avoid race between has() and get() (Fix: Copilot C)
|
||||
const cached = appStateSyncKeyCache.get(keyId)
|
||||
if (cached !== undefined) {
|
||||
// Null in cache means we explicitly cached a null (which we don't do anymore)
|
||||
// Undefined means not in cache
|
||||
return cached ?? undefined
|
||||
// Cache hit - return the cached key
|
||||
return cached
|
||||
}
|
||||
|
||||
// Cache miss - fetch from database
|
||||
|
||||
Reference in New Issue
Block a user