You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

import AppClass from '../../lifecycle/AppClass.ts'
import SessionInterface from './SessionInterface.ts'
/**
* Error thrown if a session is looked up using a key that doesn't exist.
* @extends Error
*/
export class InvalidSessionKeyError extends Error {
constructor(key: any) {
super(`Invalid session key: ${key}. No session exists.`)
}
}
/**
* Abstract class for managing sessions.
* @extends AppClass
*/
export default abstract class SessionManager extends AppClass {
/**
* Attempt to find a session by key if it exists, or create one if no key is provided.
* @param {string} [key]
* @return Promise<SessionInterface>
*/
public abstract async get_session(key?: string): Promise<SessionInterface>
/**
* Returns true if the manager has a session with the given key.
* @param {string} key
* @return Promise<boolean>
*/
public abstract async has_session(key: string): Promise<boolean>
/**
* Purge a session by key, if provided, or all sessions.
* @param {string} key
* @return Promise<void>
*/
public abstract async purge(key?: string): Promise<void>
}