-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcompat.ts
38 lines (32 loc) · 1.17 KB
/
compat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { EventEmitter } from "events";
import { callbackify, inherits, promisify } from "util";
import MemoryStore from "./memory-store";
import { SessionStore } from "./types";
// no-op for compat
function expressSession(options?: any): any {}
function ExpressStore(this: any) {
EventEmitter.call(this);
}
inherits(ExpressStore, EventEmitter);
expressSession.Store = ExpressStore;
function CallbackMemoryStore(this: MemoryStore) {
this.store = new Map();
}
inherits(CallbackMemoryStore, ExpressStore);
CallbackMemoryStore.prototype.get = callbackify(MemoryStore.prototype.get);
CallbackMemoryStore.prototype.set = callbackify(MemoryStore.prototype.set);
CallbackMemoryStore.prototype.destroy = callbackify(
MemoryStore.prototype.destroy
);
expressSession.MemoryStore = CallbackMemoryStore;
export { expressSession };
export function promisifyStore(connectStore: any): SessionStore {
return {
get: promisify(connectStore.get).bind(connectStore),
set: promisify(connectStore.set).bind(connectStore),
destroy: promisify(connectStore.destroy).bind(connectStore),
...(connectStore.touch && {
touch: promisify(connectStore.touch).bind(connectStore),
}),
};
}