UNPKG

hono-sess

Version:

A Simple Session Middleware for Hono

55 lines 2.36 kB
/*! * Connect - session - Store * Copyright(c) 2010 Sencha Inc. * Copyright(c) 2011 TJ Holowaychuk * Copyright(c) 2025 Mehmet Güleryüz * MIT Licensed */ import { EventEmitter } from 'events'; import { Session } from './session'; import type { SessionData } from './types'; /** * Abstract base class for session stores. * @public */ export declare abstract class Store extends EventEmitter { constructor(); /** * Re-generate the given requests's session. * * @param {RequestSessionExtender} req * @param {Function} callback */ regenerate(req: any, callback: (err?: any) => void): void; /** * Load a `Session` instance via the given `sid` * and invoke the callback `callback(err, session)`. */ load(sid: string, callback: (err: any, session?: SessionData) => any): void; /** * Create session from JSON `sess` data. */ createSession(req: any, session: SessionData): Omit<Session, '_id' | 'req'> & SessionData; /** * Gets the session from the store given a session ID and passes it to `callback`. * * The `session` argument should be a `Session` object if found, otherwise `null` or `undefined` if the session was not found and there was no error. * A special case is made when `error.code === 'ENOENT'` to act like `callback(null, null)`. */ abstract get(sid: string, callback: (err: any, session?: SessionData | null) => void): void; /** Upsert a session in the store given a session ID and `SessionData` */ abstract set(sid: string, session: SessionData, callback?: (err?: any) => void): void; /** Destroys the session with the given session ID. */ abstract destroy(sid: string, callback?: (err?: any) => void): void; /** Returns all sessions in the store */ abstract all?(callback: (err: any, obj?: SessionData[] | { [sid: string]: SessionData; } | null) => void): void; /** Returns the amount of sessions in the store. */ abstract length?(callback: (err: any, length?: number) => void): void; /** Delete all sessions from the store. */ abstract clear?(callback?: (err?: any) => void): void; /** "Touches" a given session, resetting the idle timer. */ abstract touch?(sid: string, session: SessionData, callback?: (err?: any) => void): void; } //# sourceMappingURL=store.d.ts.map