daton/lib/src/http/session/SessionManager.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import AppClass from '../../lifecycle/AppClass.ts'
import SessionInterface from './SessionInterface.ts'
2020-08-17 14:44:23 +00:00
/**
* 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.`)
}
}
2020-08-17 14:44:23 +00:00
/**
* Abstract class for managing sessions.
* @extends AppClass
*/
export default abstract class SessionManager extends AppClass {
2020-08-17 14:44:23 +00:00
/**
* 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>
2020-08-17 14:44:23 +00:00
/**
* 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>
2020-08-17 14:44:23 +00:00
/**
* Purge a session by key, if provided, or all sessions.
* @param {string} key
* @return Promise<void>
*/
public abstract async purge(key?: string): Promise<void>
}