Path: blob/master/lib/rammerhead/src/classes/RammerheadSessionAbstractStore.js
5253 views
/* eslint-disable no-unused-vars */12/**3* @private4* @typedef {import("./RammerheadSession")} RammerheadSession5*/67/**8* this is the minimum in order to have a fully working versatile session store. Though it is an abstract9* class and should be treated as such, it includes default functions deemed necessary that are not10* particular to different implementations11* @abstract12*/13class RammerheadSessionAbstractStore {14constructor() {15if (this.constructor === RammerheadSessionAbstractStore) {16throw new Error('abstract classes cannot be instantiated');17}18}1920/**21*22* @param {import('./RammerheadProxy')} proxy - this will overwrite proxy.openSessions with this class instance and23* adds a request handler that calls loadSessionToMemory24* @param {boolean} removeExistingSessions - whether to remove all sessions before overwriting proxy.openSessions25*/26attachToProxy(proxy, removeExistingSessions = true) {27if (proxy.openSessions === this) throw new TypeError('already attached to proxy');2829if (removeExistingSessions) {30for (const [, session] of proxy.openSessions.entries()) {31proxy.closeSession(session);32}33}34proxy.openSessions = this;35}3637/**38* @private39*/40_mustImplement() {41throw new Error('must be implemented');42}4344/**45* @abstract46* @returns {string[]} - list of session ids in store47*/48keys() {49this._mustImplement();50}51/**52* @abstract53* @param {string} id54* @returns {boolean}55*/56has(id) {57this._mustImplement();58}59/**60* @abstract61* @param {string} id62* @param {boolean} updateActiveTimestamp63* @returns {RammerheadSession|undefined}64*/65get(id, updateActiveTimestamp = true) {66this._mustImplement();67}68/**69* the implemented method here will use the dataOperation option in RammerheadSession however they70* see fit71* @abstract72* @param {string} id73* @returns {RammerheadSession}74*/75add(id) {76this._mustImplement();77}78/**79* @abstract80* @param {string} id81* @returns {boolean} - returns true when a delete operation is performed82*/83delete(id) {84this._mustImplement();85}86/**87* @abstract88* @param {string} id89* @param {string} serializedSession90*/91addSerializedSession(id, serializedSession) {92this._mustImplement();93}94/**95* optional abstract method96*/97close() {}98}99100module.exports = RammerheadSessionAbstractStore;101102103