()
| 65 | // ----------------------------------------------------------------------------- |
| 66 | |
| 67 | function createMemoryStore(): AFSStore { |
| 68 | const sessions = new Map<string, Session>(); |
| 69 | const annotations = new Map<string, Annotation>(); |
| 70 | const events: AFSEvent[] = []; |
| 71 | |
| 72 | function generateId(): string { |
| 73 | return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`; |
| 74 | } |
| 75 | |
| 76 | return { |
| 77 | createSession(url: string, projectId?: string): Session { |
| 78 | const session: Session = { |
| 79 | id: generateId(), |
| 80 | url, |
| 81 | status: "active", |
| 82 | createdAt: new Date().toISOString(), |
| 83 | projectId, |
| 84 | }; |
| 85 | sessions.set(session.id, session); |
| 86 | |
| 87 | const event = eventBus.emit("session.created", session.id, session); |
| 88 | events.push(event); |
| 89 | |
| 90 | return session; |
| 91 | }, |
| 92 | |
| 93 | getSession(id: string): Session | undefined { |
| 94 | return sessions.get(id); |
| 95 | }, |
| 96 | |
| 97 | getSessionWithAnnotations(id: string): SessionWithAnnotations | undefined { |
| 98 | const session = sessions.get(id); |
| 99 | if (!session) return undefined; |
| 100 | |
| 101 | const sessionAnnotations = Array.from(annotations.values()).filter( |
| 102 | (a) => a.sessionId === id |
| 103 | ); |
| 104 | |
| 105 | return { |
| 106 | ...session, |
| 107 | annotations: sessionAnnotations, |
| 108 | }; |
| 109 | }, |
| 110 | |
| 111 | updateSessionStatus(id: string, status: SessionStatus): Session | undefined { |
| 112 | const session = sessions.get(id); |
| 113 | if (!session) return undefined; |
| 114 | |
| 115 | session.status = status; |
| 116 | session.updatedAt = new Date().toISOString(); |
| 117 | |
| 118 | const eventType = status === "closed" ? "session.closed" : "session.updated"; |
| 119 | const event = eventBus.emit(eventType, id, session); |
| 120 | events.push(event); |
| 121 | |
| 122 | return session; |
| 123 | }, |
| 124 |
no outgoing calls
no test coverage detected
searching dependent graphs…