import { Server } from "bun"; export interface NewSessionData { uid: string; role: string; data?: T; expired_at?: number; } export interface SessionData extends NewSessionData { sid: string; active: boolean; created_at: number; } export interface SingleSession extends SessionData { track: (arg: { path: string }) => void; destroy: () => boolean; } type FilterSessionArg = { uid: string; sid: string; role: string; active: boolean; created_at: { gt?: number; lt?: number }; expired_at: { gt?: number; lt?: number }; }; export type SessionStore = { create: (arg: { uid: string; role: string; data?: T; expired_at?: number; }) => SingleSession; update: ( where: Partial, data: { active?: boolean; wsid?: string[] } ) => SingleSession[]; findMany: (arg?: Partial) => SingleSession[]; findFirst: (arg?: Partial) => null | SingleSession; }; export type ServerSession = SessionStore & { current?: SingleSession; }; export type ClientSessionStatus = | "checking" | "guest" | "expired" | "active" | "logout"; export type ClientSession = { status: ClientSessionStatus; current: null | T; init(): Promise<{ status: ClientSessionStatus }>; connected: boolean; login(auth: SessionAuth): Promise; logout(): Promise; save(data: T): Promise; load(): Promise; clear(): Promise; }; export interface SessionContext extends ServerContext { session: ServerSession; } export type ServerContext = { req: Request; server: Server; handle: ( req: Request, opt?: { rewrite?: (arg: { body: Bun.BodyInit; headers?: Record; }) => Bun.BodyInit; } ) => Promise; mode: "dev" | "prod"; url: { raw: URL; pathname: string; }; }; export type SessionAuth = ( | { method: "user-pass"; username: string; password: string; } | { method: "user-otp"; uid: string; otp: string; } ) & Record;