Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/lib/rammerhead/src/classes/RammerheadSessionAbstractStore.js
5253 views
1
/* eslint-disable no-unused-vars */
2
3
/**
4
* @private
5
* @typedef {import("./RammerheadSession")} RammerheadSession
6
*/
7
8
/**
9
* this is the minimum in order to have a fully working versatile session store. Though it is an abstract
10
* class and should be treated as such, it includes default functions deemed necessary that are not
11
* particular to different implementations
12
* @abstract
13
*/
14
class RammerheadSessionAbstractStore {
15
constructor() {
16
if (this.constructor === RammerheadSessionAbstractStore) {
17
throw new Error('abstract classes cannot be instantiated');
18
}
19
}
20
21
/**
22
*
23
* @param {import('./RammerheadProxy')} proxy - this will overwrite proxy.openSessions with this class instance and
24
* adds a request handler that calls loadSessionToMemory
25
* @param {boolean} removeExistingSessions - whether to remove all sessions before overwriting proxy.openSessions
26
*/
27
attachToProxy(proxy, removeExistingSessions = true) {
28
if (proxy.openSessions === this) throw new TypeError('already attached to proxy');
29
30
if (removeExistingSessions) {
31
for (const [, session] of proxy.openSessions.entries()) {
32
proxy.closeSession(session);
33
}
34
}
35
proxy.openSessions = this;
36
}
37
38
/**
39
* @private
40
*/
41
_mustImplement() {
42
throw new Error('must be implemented');
43
}
44
45
/**
46
* @abstract
47
* @returns {string[]} - list of session ids in store
48
*/
49
keys() {
50
this._mustImplement();
51
}
52
/**
53
* @abstract
54
* @param {string} id
55
* @returns {boolean}
56
*/
57
has(id) {
58
this._mustImplement();
59
}
60
/**
61
* @abstract
62
* @param {string} id
63
* @param {boolean} updateActiveTimestamp
64
* @returns {RammerheadSession|undefined}
65
*/
66
get(id, updateActiveTimestamp = true) {
67
this._mustImplement();
68
}
69
/**
70
* the implemented method here will use the dataOperation option in RammerheadSession however they
71
* see fit
72
* @abstract
73
* @param {string} id
74
* @returns {RammerheadSession}
75
*/
76
add(id) {
77
this._mustImplement();
78
}
79
/**
80
* @abstract
81
* @param {string} id
82
* @returns {boolean} - returns true when a delete operation is performed
83
*/
84
delete(id) {
85
this._mustImplement();
86
}
87
/**
88
* @abstract
89
* @param {string} id
90
* @param {string} serializedSession
91
*/
92
addSerializedSession(id, serializedSession) {
93
this._mustImplement();
94
}
95
/**
96
* optional abstract method
97
*/
98
close() {}
99
}
100
101
module.exports = RammerheadSessionAbstractStore;
102
103