import type { Handler } from "../types"; import type { BunRequest } from "../core/request"; /** * Extend this interface to add typed session data fields with full autocomplete. * @example * declare module "bunway" { * interface SessionData { * user: User; * cart: CartItem[]; * } * } */ export interface SessionData { [key: string]: unknown; } export interface Session extends SessionData { id: string; cookie: SessionCookieData; regenerate(callback?: (err?: Error) => void): void; destroy(callback?: (err?: Error) => void): void; reload(callback?: (err?: Error) => void): void; save(callback?: (err?: Error) => void): void; touch(): void; flash(type: string, message?: string): string | string[] | undefined; } interface SessionCookieData { maxAge?: number; expires?: Date; secure?: boolean; httpOnly?: boolean; path?: string; sameSite?: "strict" | "lax" | "none"; } export interface SessionStore { get(sid: string): Promise; set(sid: string, session: SessionData, maxAge?: number): Promise; destroy(sid: string): Promise; touch?(sid: string, session: SessionData): Promise; all?(): Promise; length?(): Promise; clear?(): Promise; on?(event: string, listener: (...args: any[]) => void): this; emit?(event: string, ...args: any[]): boolean; } export interface LegacySessionStore { get(sid: string, cb: (err: any, session?: SessionData | null) => void): void; set(sid: string, session: SessionData, cb?: (err?: any) => void): void; destroy(sid: string, cb?: (err?: any) => void): void; touch?(sid: string, session: SessionData, cb?: (err?: any) => void): void; } export declare function fromExpressStore(store: LegacySessionStore): SessionStore; export interface SessionOptions { secret: string | string[]; name?: string; cookie?: { maxAge?: number; secure?: boolean; httpOnly?: boolean; path?: string; sameSite?: "strict" | "lax" | "none"; }; store?: SessionStore; resave?: boolean; saveUninitialized?: boolean; rolling?: boolean; genid?: (req: BunRequest) => string; } export declare class MemoryStore implements SessionStore { private sessions; get(sid: string): Promise; set(sid: string, session: SessionData, maxAge?: number): Promise; destroy(sid: string): Promise; touch(sid: string, _session: SessionData): Promise; all(): Promise; length(): Promise; clear(): Promise; get size(): number; } export interface FileStoreOptions { path: string; ttl?: number; } export declare class FileStore implements SessionStore { private path; private ttl; constructor(options: FileStoreOptions); private getFilePath; get(sid: string): Promise; set(sid: string, session: SessionData, maxAge?: number): Promise; destroy(sid: string): Promise; touch(sid: string, session: SessionData): Promise; clear(): Promise; length(): Promise; } export declare function session(options: SessionOptions): Handler; export {}; //# sourceMappingURL=session.d.ts.map