mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
refactor: consolidate backend services
Replace per-source services (LocationService, WeatherService, TflService, FeedEngineService) with a single UserSessionManager that owns all per-user state. Source creation is delegated to thin FeedSourceProvider implementations per source type. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
31
apps/aris-backend/src/session/user-session-manager.ts
Normal file
31
apps/aris-backend/src/session/user-session-manager.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { FeedSourceProviderInput } from "./feed-source-provider.ts"
|
||||
import { UserSession } from "./user-session.ts"
|
||||
|
||||
export class UserSessionManager {
|
||||
private sessions = new Map<string, UserSession>()
|
||||
private readonly providers: FeedSourceProviderInput[]
|
||||
|
||||
constructor(providers: FeedSourceProviderInput[]) {
|
||||
this.providers = providers
|
||||
}
|
||||
|
||||
getOrCreate(userId: string): UserSession {
|
||||
let session = this.sessions.get(userId)
|
||||
if (!session) {
|
||||
const sources = this.providers.map((p) =>
|
||||
typeof p === "function" ? p(userId) : p.feedSourceForUser(userId),
|
||||
)
|
||||
session = new UserSession(sources)
|
||||
this.sessions.set(userId, session)
|
||||
}
|
||||
return session
|
||||
}
|
||||
|
||||
remove(userId: string): void {
|
||||
const session = this.sessions.get(userId)
|
||||
if (session) {
|
||||
session.destroy()
|
||||
this.sessions.delete(userId)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user