2020-07-24 14:53:30 +00:00
|
|
|
import AppClass from '../../lifecycle/AppClass.ts'
|
2020-07-27 14:41:04 +00:00
|
|
|
import SessionInterface from './SessionInterface.ts'
|
2020-07-24 14:53:30 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2020-07-24 14:53:30 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-07-24 14:53:30 +00:00
|
|
|
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>
|
|
|
|
*/
|
2020-07-27 14:41:04 +00:00
|
|
|
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>
|
|
|
|
*/
|
2020-07-24 14:53:30 +00:00
|
|
|
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>
|
|
|
|
*/
|
2020-07-24 14:53:30 +00:00
|
|
|
public abstract async purge(key?: string): Promise<void>
|
|
|
|
|
|
|
|
}
|