CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-walletconnect--types

tessl install tessl/npm-walletconnect--types@2.21.0

TypeScript type definitions and interfaces for the WalletConnect Protocol v2, enabling type-safe development across the WalletConnect ecosystem

Agent Success

Agent success rate when using this tile

70%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.19x

Baseline

Agent success rate without this tile

59%

task.mdevals/scenario-8/

Session Cache Manager

Build a session cache manager that stores and retrieves user session data with filtering capabilities.

Requirements

Your task is to implement a session cache manager with the following features:

  1. Store session data - Save session objects with unique identifiers
  2. Retrieve session data - Get individual sessions by identifier or retrieve all sessions
  3. Update session data - Modify existing session entries
  4. Delete session data - Remove sessions individually or all at once
  5. Filter sessions - Query sessions that match specific criteria (e.g., find all sessions for a particular user or all active sessions)

The session data should have the following structure:

  • id: unique session identifier (string)
  • userId: user identifier (string)
  • active: whether the session is currently active (boolean)
  • expiresAt: expiration timestamp (number)

Implementation Details

Create a SessionCacheManager class that manages session storage. The implementation should:

  • Initialize with an empty storage
  • Support storing sessions with unique IDs
  • Allow retrieving all sessions or filtered subsets
  • Support updating existing sessions
  • Handle deletion of individual sessions or bulk deletion with a reason

Test Cases @test

Create a test file named session-cache.test.ts with the following test cases:

Test 1: Basic Storage and Retrieval @test

// Store a session and retrieve it
const manager = new SessionCacheManager();
const session = {
  id: 'session-1',
  userId: 'user-123',
  active: true,
  expiresAt: Date.now() + 3600000
};
await manager.store(session);
const retrieved = await manager.get('session-1');
// Should return the stored session

Test 2: Filter Sessions @test

// Store multiple sessions and filter by criteria
const manager = new SessionCacheManager();
await manager.store({
  id: 'session-1',
  userId: 'user-123',
  active: true,
  expiresAt: Date.now() + 3600000
});
await manager.store({
  id: 'session-2',
  userId: 'user-456',
  active: false,
  expiresAt: Date.now() + 7200000
});
await manager.store({
  id: 'session-3',
  userId: 'user-123',
  active: true,
  expiresAt: Date.now() + 1800000
});

const userSessions = await manager.filter({ userId: 'user-123' });
// Should return 2 sessions (session-1 and session-3)

const activeSessions = await manager.filter({ active: true });
// Should return 2 sessions (session-1 and session-3)

Test 3: Update and Delete @test

// Update a session and then delete it
const manager = new SessionCacheManager();
const session = {
  id: 'session-1',
  userId: 'user-123',
  active: true,
  expiresAt: Date.now() + 3600000
};
await manager.store(session);

// Update the session
await manager.update('session-1', { active: false });
const updated = await manager.get('session-1');
// Should have active: false

// Delete the session
await manager.delete('session-1', 'User logged out');
const deleted = await manager.get('session-1');
// Should be undefined

Dependencies { .dependencies }

@walletconnect/types { .dependency }

Provides TypeScript type definitions for WalletConnect Protocol v2, including storage interface types.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@walletconnect/types@2.21.x
tile.json