A social knowledge tool for researchers built on ATProto
1import { Result, ok, err } from 'src/shared/core/Result';
2import {
3 IAppPasswordSessionRepository,
4 SessionWithAppPassword,
5} from '../../infrastructure/repositories/IAppPasswordSessionRepository';
6
7export class InMemoryAppPasswordSessionRepository
8 implements IAppPasswordSessionRepository
9{
10 private sessions: Map<string, SessionWithAppPassword> = new Map();
11
12 async saveSession(
13 did: string,
14 session: SessionWithAppPassword,
15 ): Promise<Result<void>> {
16 try {
17 this.sessions.set(did, session);
18 return ok(undefined);
19 } catch (error: any) {
20 return err(error);
21 }
22 }
23
24 async getSession(
25 did: string,
26 ): Promise<Result<SessionWithAppPassword | null>> {
27 try {
28 const session = this.sessions.get(did) || null;
29 return ok(session);
30 } catch (error: any) {
31 return err(error);
32 }
33 }
34
35 // Test utility methods
36 clear(): void {
37 this.sessions.clear();
38 }
39
40 size(): number {
41 return this.sessions.size;
42 }
43}