mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-30 06:17:06 +00:00
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import type { Database } from 'bun:sqlite'
|
|
|
|
import type { StoredSession, VersionedUpdateResult } from './types'
|
|
import {
|
|
deleteSession,
|
|
getOrCreateSession,
|
|
getSession,
|
|
getSessionByNamespace,
|
|
getSessions,
|
|
getSessionsByNamespace,
|
|
setSessionTodos,
|
|
updateSessionAgentState,
|
|
updateSessionMetadata
|
|
} from './sessions'
|
|
|
|
export class SessionStore {
|
|
private readonly db: Database
|
|
|
|
constructor(db: Database) {
|
|
this.db = db
|
|
}
|
|
|
|
getOrCreateSession(tag: string, metadata: unknown, agentState: unknown, namespace: string): StoredSession {
|
|
return getOrCreateSession(this.db, tag, metadata, agentState, namespace)
|
|
}
|
|
|
|
updateSessionMetadata(
|
|
id: string,
|
|
metadata: unknown,
|
|
expectedVersion: number,
|
|
namespace: string,
|
|
options?: { touchUpdatedAt?: boolean }
|
|
): VersionedUpdateResult<unknown | null> {
|
|
return updateSessionMetadata(this.db, id, metadata, expectedVersion, namespace, options)
|
|
}
|
|
|
|
updateSessionAgentState(
|
|
id: string,
|
|
agentState: unknown,
|
|
expectedVersion: number,
|
|
namespace: string
|
|
): VersionedUpdateResult<unknown | null> {
|
|
return updateSessionAgentState(this.db, id, agentState, expectedVersion, namespace)
|
|
}
|
|
|
|
setSessionTodos(id: string, todos: unknown, todosUpdatedAt: number, namespace: string): boolean {
|
|
return setSessionTodos(this.db, id, todos, todosUpdatedAt, namespace)
|
|
}
|
|
|
|
getSession(id: string): StoredSession | null {
|
|
return getSession(this.db, id)
|
|
}
|
|
|
|
getSessionByNamespace(id: string, namespace: string): StoredSession | null {
|
|
return getSessionByNamespace(this.db, id, namespace)
|
|
}
|
|
|
|
getSessions(): StoredSession[] {
|
|
return getSessions(this.db)
|
|
}
|
|
|
|
getSessionsByNamespace(namespace: string): StoredSession[] {
|
|
return getSessionsByNamespace(this.db, namespace)
|
|
}
|
|
|
|
deleteSession(id: string, namespace: string): boolean {
|
|
return deleteSession(this.db, id, namespace)
|
|
}
|
|
}
|