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 static instance: InMemoryAppPasswordSessionRepository;
11 private sessions: Map<string, SessionWithAppPassword> = new Map();
12
13 private constructor() {}
14
15 public static getInstance(): InMemoryAppPasswordSessionRepository {
16 if (!InMemoryAppPasswordSessionRepository.instance) {
17 InMemoryAppPasswordSessionRepository.instance =
18 new InMemoryAppPasswordSessionRepository();
19 }
20 return InMemoryAppPasswordSessionRepository.instance;
21 }
22
23 async saveSession(
24 did: string,
25 session: SessionWithAppPassword,
26 ): Promise<Result<void>> {
27 try {
28 this.sessions.set(did, session);
29 return ok(undefined);
30 } catch (error: any) {
31 return err(error);
32 }
33 }
34
35 async getSession(
36 did: string,
37 ): Promise<Result<SessionWithAppPassword | null>> {
38 try {
39 const session = this.sessions.get(did) || null;
40 return ok(session);
41 } catch (error: any) {
42 return err(error);
43 }
44 }
45
46 // Test utility methods
47 clear(): void {
48 this.sessions.clear();
49 }
50
51 size(): number {
52 return this.sessions.size;
53 }
54}