From be0d7c53f8a86ab30f211478d617edf4aa300cfd Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 23 Oct 2025 15:05:44 -0700 Subject: [PATCH] refactor: implement singleton pattern for in-memory stores Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) --- .../user/tests/infrastructure/InMemorySessionStore.ts | 10 ++++++++++ .../user/tests/infrastructure/InMemoryStateStore.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/user/tests/infrastructure/InMemorySessionStore.ts b/src/modules/user/tests/infrastructure/InMemorySessionStore.ts index a41d59cf..800e7c70 100644 --- a/src/modules/user/tests/infrastructure/InMemorySessionStore.ts +++ b/src/modules/user/tests/infrastructure/InMemorySessionStore.ts @@ -7,8 +7,18 @@ import { * In-memory implementation of NodeSavedSessionStore for testing */ export class InMemorySessionStore implements NodeSavedSessionStore { + private static instance: InMemorySessionStore; private sessions: Map = new Map(); + private constructor() {} + + public static getInstance(): InMemorySessionStore { + if (!InMemorySessionStore.instance) { + InMemorySessionStore.instance = new InMemorySessionStore(); + } + return InMemorySessionStore.instance; + } + async get(key: string): Promise { return this.sessions.get(key); } diff --git a/src/modules/user/tests/infrastructure/InMemoryStateStore.ts b/src/modules/user/tests/infrastructure/InMemoryStateStore.ts index f38ab692..8a94bcb3 100644 --- a/src/modules/user/tests/infrastructure/InMemoryStateStore.ts +++ b/src/modules/user/tests/infrastructure/InMemoryStateStore.ts @@ -7,8 +7,18 @@ import { * In-memory implementation of NodeSavedStateStore for testing */ export class InMemoryStateStore implements NodeSavedStateStore { + private static instance: InMemoryStateStore; private states: Map = new Map(); + private constructor() {} + + public static getInstance(): InMemoryStateStore { + if (!InMemoryStateStore.instance) { + InMemoryStateStore.instance = new InMemoryStateStore(); + } + return InMemoryStateStore.instance; + } + async get(key: string): Promise { return this.states.get(key); } -- 2.51.2