@shware/security 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/dist/auth/index.cjs +17 -9
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +5 -2
- package/dist/auth/index.d.ts +5 -2
- package/dist/auth/index.mjs +14 -6
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.cjs.map +1 -1
- package/dist/auth/types.d.cts +3 -2
- package/dist/auth/types.d.ts +3 -2
- package/dist/index.cjs +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.mjs +6 -2
- package/dist/index.mjs.map +1 -1
- package/dist/session/__test__/redis.test.cjs +5 -4
- package/dist/session/__test__/redis.test.cjs.map +1 -1
- package/dist/session/__test__/redis.test.mjs +3 -2
- package/dist/session/__test__/redis.test.mjs.map +1 -1
- package/dist/session/common.cjs +46 -0
- package/dist/session/common.cjs.map +1 -0
- package/dist/session/common.d.cts +8 -0
- package/dist/session/common.d.ts +8 -0
- package/dist/session/common.mjs +19 -0
- package/dist/session/common.mjs.map +1 -0
- package/dist/session/db.cjs +127 -0
- package/dist/session/db.cjs.map +1 -0
- package/dist/session/db.d.cts +43 -0
- package/dist/session/db.d.ts +43 -0
- package/dist/session/db.mjs +102 -0
- package/dist/session/db.mjs.map +1 -0
- package/dist/session/map-session.cjs +108 -0
- package/dist/session/map-session.cjs.map +1 -0
- package/dist/session/map-session.d.cts +27 -0
- package/dist/session/map-session.d.ts +27 -0
- package/dist/session/map-session.mjs +83 -0
- package/dist/session/map-session.mjs.map +1 -0
- package/dist/session/redis.cjs +32 -128
- package/dist/session/redis.cjs.map +1 -1
- package/dist/session/redis.d.cts +11 -30
- package/dist/session/redis.d.ts +11 -30
- package/dist/session/redis.mjs +20 -116
- package/dist/session/redis.mjs.map +1 -1
- package/dist/session/types.cjs.map +1 -1
- package/dist/session/types.d.cts +6 -4
- package/dist/session/types.d.ts +6 -4
- package/package.json +1 -1
- package/dist/session/index.cjs +0 -33
- package/dist/session/index.cjs.map +0 -1
- package/dist/session/index.d.cts +0 -4
- package/dist/session/index.d.ts +0 -4
- package/dist/session/index.mjs +0 -10
- package/dist/session/index.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/session/map-session.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport { Session } from './types';\n\nfunction generateId() {\n return randomUUID();\n}\n\nconst DEFAULT_MAX_INACTIVE_INTERVAL = 1800;\n\nexport class MapSession implements Session {\n private id: string;\n private sessionAttrs = new Map<string, string | number>();\n private creationTime = Date.now();\n private lastAccessedTime = this.creationTime;\n private maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;\n\n constructor(id?: string);\n constructor(session: Session);\n constructor(input?: string | Session) {\n if (typeof input === 'undefined') {\n this.id = generateId();\n } else if (typeof input === 'string') {\n this.id = input;\n } else {\n const session = input;\n this.id = session.getId();\n\n for (const attrName of session.getAttributeNames()) {\n const attrValue = session.getAttribute(attrName);\n if (attrValue !== null) {\n this.setAttribute(attrName, attrValue);\n }\n }\n\n this.lastAccessedTime = session.getLastAccessedTime();\n this.creationTime = session.getCreationTime();\n this.maxInactiveInterval = session.getMaxInactiveInterval();\n }\n }\n\n setCreationTime(creationTime: number) {\n this.creationTime = creationTime;\n }\n\n // override\n getId() {\n return this.id;\n }\n\n changeSessionId() {\n const changedId = generateId();\n this.id = changedId;\n return changedId;\n }\n\n getAttribute(name: string) {\n return this.sessionAttrs.get(name) ?? null;\n }\n\n getAttributeNames(): string[] {\n return Array.from(this.sessionAttrs.keys());\n }\n\n setAttribute(name: string, value: string | number) {\n if (value === null) {\n this.removeAttribute(name);\n } else {\n this.sessionAttrs.set(name, value);\n }\n }\n\n removeAttribute(name: string) {\n this.sessionAttrs.delete(name);\n }\n\n getCreationTime() {\n return this.creationTime;\n }\n\n getLastAccessedTime() {\n return this.lastAccessedTime;\n }\n\n setLastAccessedTime(lastAccessedTime: number) {\n this.lastAccessedTime = lastAccessedTime;\n }\n\n getMaxInactiveInterval() {\n return this.maxInactiveInterval;\n }\n\n setMaxInactiveInterval(interval: number) {\n this.maxInactiveInterval = interval;\n }\n\n isExpired() {\n if (this.maxInactiveInterval < 0) return false;\n return Date.now() - this.maxInactiveInterval * 1000 - this.lastAccessedTime >= 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAG3B,SAAS,aAAa;AACpB,aAAO,0BAAW;AACpB;AAEA,IAAM,gCAAgC;AAE/B,IAAM,aAAN,MAAoC;AAAA,EACjC;AAAA,EACA,eAAe,oBAAI,IAA6B;AAAA,EAChD,eAAe,KAAK,IAAI;AAAA,EACxB,mBAAmB,KAAK;AAAA,EACxB,sBAAsB;AAAA,EAI9B,YAAY,OAA0B;AACpC,QAAI,OAAO,UAAU,aAAa;AAChC,WAAK,KAAK,WAAW;AAAA,IACvB,WAAW,OAAO,UAAU,UAAU;AACpC,WAAK,KAAK;AAAA,IACZ,OAAO;AACL,YAAM,UAAU;AAChB,WAAK,KAAK,QAAQ,MAAM;AAExB,iBAAW,YAAY,QAAQ,kBAAkB,GAAG;AAClD,cAAM,YAAY,QAAQ,aAAa,QAAQ;AAC/C,YAAI,cAAc,MAAM;AACtB,eAAK,aAAa,UAAU,SAAS;AAAA,QACvC;AAAA,MACF;AAEA,WAAK,mBAAmB,QAAQ,oBAAoB;AACpD,WAAK,eAAe,QAAQ,gBAAgB;AAC5C,WAAK,sBAAsB,QAAQ,uBAAuB;AAAA,IAC5D;AAAA,EACF;AAAA,EAEA,gBAAgB,cAAsB;AACpC,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,QAAQ;AACN,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,kBAAkB;AAChB,UAAM,YAAY,WAAW;AAC7B,SAAK,KAAK;AACV,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,MAAc;AACzB,WAAO,KAAK,aAAa,IAAI,IAAI,KAAK;AAAA,EACxC;AAAA,EAEA,oBAA8B;AAC5B,WAAO,MAAM,KAAK,KAAK,aAAa,KAAK,CAAC;AAAA,EAC5C;AAAA,EAEA,aAAa,MAAc,OAAwB;AACjD,QAAI,UAAU,MAAM;AAClB,WAAK,gBAAgB,IAAI;AAAA,IAC3B,OAAO;AACL,WAAK,aAAa,IAAI,MAAM,KAAK;AAAA,IACnC;AAAA,EACF;AAAA,EAEA,gBAAgB,MAAc;AAC5B,SAAK,aAAa,OAAO,IAAI;AAAA,EAC/B;AAAA,EAEA,kBAAkB;AAChB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,sBAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,oBAAoB,kBAA0B;AAC5C,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEA,yBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,uBAAuB,UAAkB;AACvC,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,YAAY;AACV,QAAI,KAAK,sBAAsB,EAAG,QAAO;AACzC,WAAO,KAAK,IAAI,IAAI,KAAK,sBAAsB,MAAO,KAAK,oBAAoB;AAAA,EACjF;AACF;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Session } from './types.cjs';
|
|
2
|
+
import '../core/index.cjs';
|
|
3
|
+
|
|
4
|
+
declare class MapSession implements Session {
|
|
5
|
+
private id;
|
|
6
|
+
private sessionAttrs;
|
|
7
|
+
private creationTime;
|
|
8
|
+
private lastAccessedTime;
|
|
9
|
+
private maxInactiveInterval;
|
|
10
|
+
constructor(id?: string);
|
|
11
|
+
constructor(session: Session);
|
|
12
|
+
setCreationTime(creationTime: number): void;
|
|
13
|
+
getId(): string;
|
|
14
|
+
changeSessionId(): `${string}-${string}-${string}-${string}-${string}`;
|
|
15
|
+
getAttribute(name: string): string | number | null;
|
|
16
|
+
getAttributeNames(): string[];
|
|
17
|
+
setAttribute(name: string, value: string | number): void;
|
|
18
|
+
removeAttribute(name: string): void;
|
|
19
|
+
getCreationTime(): number;
|
|
20
|
+
getLastAccessedTime(): number;
|
|
21
|
+
setLastAccessedTime(lastAccessedTime: number): void;
|
|
22
|
+
getMaxInactiveInterval(): number;
|
|
23
|
+
setMaxInactiveInterval(interval: number): void;
|
|
24
|
+
isExpired(): boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { MapSession };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Session } from './types.js';
|
|
2
|
+
import '../core/index.js';
|
|
3
|
+
|
|
4
|
+
declare class MapSession implements Session {
|
|
5
|
+
private id;
|
|
6
|
+
private sessionAttrs;
|
|
7
|
+
private creationTime;
|
|
8
|
+
private lastAccessedTime;
|
|
9
|
+
private maxInactiveInterval;
|
|
10
|
+
constructor(id?: string);
|
|
11
|
+
constructor(session: Session);
|
|
12
|
+
setCreationTime(creationTime: number): void;
|
|
13
|
+
getId(): string;
|
|
14
|
+
changeSessionId(): `${string}-${string}-${string}-${string}-${string}`;
|
|
15
|
+
getAttribute(name: string): string | number | null;
|
|
16
|
+
getAttributeNames(): string[];
|
|
17
|
+
setAttribute(name: string, value: string | number): void;
|
|
18
|
+
removeAttribute(name: string): void;
|
|
19
|
+
getCreationTime(): number;
|
|
20
|
+
getLastAccessedTime(): number;
|
|
21
|
+
setLastAccessedTime(lastAccessedTime: number): void;
|
|
22
|
+
getMaxInactiveInterval(): number;
|
|
23
|
+
setMaxInactiveInterval(interval: number): void;
|
|
24
|
+
isExpired(): boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { MapSession };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/session/map-session.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
function generateId() {
|
|
4
|
+
return randomUUID();
|
|
5
|
+
}
|
|
6
|
+
var DEFAULT_MAX_INACTIVE_INTERVAL = 1800;
|
|
7
|
+
var MapSession = class {
|
|
8
|
+
id;
|
|
9
|
+
sessionAttrs = /* @__PURE__ */ new Map();
|
|
10
|
+
creationTime = Date.now();
|
|
11
|
+
lastAccessedTime = this.creationTime;
|
|
12
|
+
maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;
|
|
13
|
+
constructor(input) {
|
|
14
|
+
if (typeof input === "undefined") {
|
|
15
|
+
this.id = generateId();
|
|
16
|
+
} else if (typeof input === "string") {
|
|
17
|
+
this.id = input;
|
|
18
|
+
} else {
|
|
19
|
+
const session = input;
|
|
20
|
+
this.id = session.getId();
|
|
21
|
+
for (const attrName of session.getAttributeNames()) {
|
|
22
|
+
const attrValue = session.getAttribute(attrName);
|
|
23
|
+
if (attrValue !== null) {
|
|
24
|
+
this.setAttribute(attrName, attrValue);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.lastAccessedTime = session.getLastAccessedTime();
|
|
28
|
+
this.creationTime = session.getCreationTime();
|
|
29
|
+
this.maxInactiveInterval = session.getMaxInactiveInterval();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
setCreationTime(creationTime) {
|
|
33
|
+
this.creationTime = creationTime;
|
|
34
|
+
}
|
|
35
|
+
// override
|
|
36
|
+
getId() {
|
|
37
|
+
return this.id;
|
|
38
|
+
}
|
|
39
|
+
changeSessionId() {
|
|
40
|
+
const changedId = generateId();
|
|
41
|
+
this.id = changedId;
|
|
42
|
+
return changedId;
|
|
43
|
+
}
|
|
44
|
+
getAttribute(name) {
|
|
45
|
+
return this.sessionAttrs.get(name) ?? null;
|
|
46
|
+
}
|
|
47
|
+
getAttributeNames() {
|
|
48
|
+
return Array.from(this.sessionAttrs.keys());
|
|
49
|
+
}
|
|
50
|
+
setAttribute(name, value) {
|
|
51
|
+
if (value === null) {
|
|
52
|
+
this.removeAttribute(name);
|
|
53
|
+
} else {
|
|
54
|
+
this.sessionAttrs.set(name, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
removeAttribute(name) {
|
|
58
|
+
this.sessionAttrs.delete(name);
|
|
59
|
+
}
|
|
60
|
+
getCreationTime() {
|
|
61
|
+
return this.creationTime;
|
|
62
|
+
}
|
|
63
|
+
getLastAccessedTime() {
|
|
64
|
+
return this.lastAccessedTime;
|
|
65
|
+
}
|
|
66
|
+
setLastAccessedTime(lastAccessedTime) {
|
|
67
|
+
this.lastAccessedTime = lastAccessedTime;
|
|
68
|
+
}
|
|
69
|
+
getMaxInactiveInterval() {
|
|
70
|
+
return this.maxInactiveInterval;
|
|
71
|
+
}
|
|
72
|
+
setMaxInactiveInterval(interval) {
|
|
73
|
+
this.maxInactiveInterval = interval;
|
|
74
|
+
}
|
|
75
|
+
isExpired() {
|
|
76
|
+
if (this.maxInactiveInterval < 0) return false;
|
|
77
|
+
return Date.now() - this.maxInactiveInterval * 1e3 - this.lastAccessedTime >= 0;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
MapSession
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=map-session.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/session/map-session.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport { Session } from './types';\n\nfunction generateId() {\n return randomUUID();\n}\n\nconst DEFAULT_MAX_INACTIVE_INTERVAL = 1800;\n\nexport class MapSession implements Session {\n private id: string;\n private sessionAttrs = new Map<string, string | number>();\n private creationTime = Date.now();\n private lastAccessedTime = this.creationTime;\n private maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;\n\n constructor(id?: string);\n constructor(session: Session);\n constructor(input?: string | Session) {\n if (typeof input === 'undefined') {\n this.id = generateId();\n } else if (typeof input === 'string') {\n this.id = input;\n } else {\n const session = input;\n this.id = session.getId();\n\n for (const attrName of session.getAttributeNames()) {\n const attrValue = session.getAttribute(attrName);\n if (attrValue !== null) {\n this.setAttribute(attrName, attrValue);\n }\n }\n\n this.lastAccessedTime = session.getLastAccessedTime();\n this.creationTime = session.getCreationTime();\n this.maxInactiveInterval = session.getMaxInactiveInterval();\n }\n }\n\n setCreationTime(creationTime: number) {\n this.creationTime = creationTime;\n }\n\n // override\n getId() {\n return this.id;\n }\n\n changeSessionId() {\n const changedId = generateId();\n this.id = changedId;\n return changedId;\n }\n\n getAttribute(name: string) {\n return this.sessionAttrs.get(name) ?? null;\n }\n\n getAttributeNames(): string[] {\n return Array.from(this.sessionAttrs.keys());\n }\n\n setAttribute(name: string, value: string | number) {\n if (value === null) {\n this.removeAttribute(name);\n } else {\n this.sessionAttrs.set(name, value);\n }\n }\n\n removeAttribute(name: string) {\n this.sessionAttrs.delete(name);\n }\n\n getCreationTime() {\n return this.creationTime;\n }\n\n getLastAccessedTime() {\n return this.lastAccessedTime;\n }\n\n setLastAccessedTime(lastAccessedTime: number) {\n this.lastAccessedTime = lastAccessedTime;\n }\n\n getMaxInactiveInterval() {\n return this.maxInactiveInterval;\n }\n\n setMaxInactiveInterval(interval: number) {\n this.maxInactiveInterval = interval;\n }\n\n isExpired() {\n if (this.maxInactiveInterval < 0) return false;\n return Date.now() - this.maxInactiveInterval * 1000 - this.lastAccessedTime >= 0;\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAG3B,SAAS,aAAa;AACpB,SAAO,WAAW;AACpB;AAEA,IAAM,gCAAgC;AAE/B,IAAM,aAAN,MAAoC;AAAA,EACjC;AAAA,EACA,eAAe,oBAAI,IAA6B;AAAA,EAChD,eAAe,KAAK,IAAI;AAAA,EACxB,mBAAmB,KAAK;AAAA,EACxB,sBAAsB;AAAA,EAI9B,YAAY,OAA0B;AACpC,QAAI,OAAO,UAAU,aAAa;AAChC,WAAK,KAAK,WAAW;AAAA,IACvB,WAAW,OAAO,UAAU,UAAU;AACpC,WAAK,KAAK;AAAA,IACZ,OAAO;AACL,YAAM,UAAU;AAChB,WAAK,KAAK,Q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K,IAAI,IAAI,KAAK,sBAAsB,MAAO,KAAK,oBAAoB;AAAA,EACjF;AACF;","names":[]}
|
package/dist/session/redis.cjs
CHANGED
|
@@ -20,105 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/session/redis.ts
|
|
21
21
|
var redis_exports = {};
|
|
22
22
|
__export(redis_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
RedisIndexedSessionRepository: () => RedisIndexedSessionRepository,
|
|
24
|
+
RedisKVRepository: () => RedisKVRepository
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(redis_exports);
|
|
27
|
-
var
|
|
28
|
-
var
|
|
27
|
+
var import_common = require("./common.cjs");
|
|
28
|
+
var import_map_session = require("./map-session.cjs");
|
|
29
29
|
var CREATION_TIME_KEY = "creationTime";
|
|
30
30
|
var LAST_ACCESSED_TIME_KEY = "lastAccessedTime";
|
|
31
31
|
var MAX_INACTIVE_INTERVAL_KEY = "maxInactiveInterval";
|
|
32
32
|
var ATTRIBUTE_PREFIX = "sessionAttr:";
|
|
33
33
|
var SESSION_EXPIRES_PREFIX = "expires:";
|
|
34
|
-
var SPRING_SECURITY_CONTEXT = "SPRING_SECURITY_CONTEXT";
|
|
35
|
-
var PRINCIPAL_NAME_INDEX_NAME = `org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME`;
|
|
36
|
-
function generateId() {
|
|
37
|
-
return (0, import_crypto.randomUUID)();
|
|
38
|
-
}
|
|
39
|
-
var MapSession = class {
|
|
40
|
-
id;
|
|
41
|
-
sessionAttrs = /* @__PURE__ */ new Map();
|
|
42
|
-
creationTime = Date.now();
|
|
43
|
-
lastAccessedTime = this.creationTime;
|
|
44
|
-
maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;
|
|
45
|
-
constructor(input) {
|
|
46
|
-
if (typeof input === "undefined") {
|
|
47
|
-
this.id = generateId();
|
|
48
|
-
} else if (typeof input === "string") {
|
|
49
|
-
this.id = input;
|
|
50
|
-
} else {
|
|
51
|
-
const session = input;
|
|
52
|
-
this.id = session.getId();
|
|
53
|
-
for (const attrName of session.getAttributeNames()) {
|
|
54
|
-
const attrValue = session.getAttribute(attrName);
|
|
55
|
-
if (attrValue !== null) {
|
|
56
|
-
this.setAttribute(attrName, attrValue);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
this.lastAccessedTime = session.getLastAccessedTime();
|
|
60
|
-
this.creationTime = session.getCreationTime();
|
|
61
|
-
this.maxInactiveInterval = session.getMaxInactiveInterval();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
setCreationTime(creationTime) {
|
|
65
|
-
this.creationTime = creationTime;
|
|
66
|
-
}
|
|
67
|
-
// override
|
|
68
|
-
getId() {
|
|
69
|
-
return this.id;
|
|
70
|
-
}
|
|
71
|
-
changeSessionId() {
|
|
72
|
-
const changedId = generateId();
|
|
73
|
-
this.id = changedId;
|
|
74
|
-
return changedId;
|
|
75
|
-
}
|
|
76
|
-
getAttribute(name) {
|
|
77
|
-
return this.sessionAttrs.get(name) ?? null;
|
|
78
|
-
}
|
|
79
|
-
getAttributeNames() {
|
|
80
|
-
return Array.from(this.sessionAttrs.keys());
|
|
81
|
-
}
|
|
82
|
-
setAttribute(name, value) {
|
|
83
|
-
if (value === null) {
|
|
84
|
-
this.removeAttribute(name);
|
|
85
|
-
} else {
|
|
86
|
-
this.sessionAttrs.set(name, value);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
removeAttribute(name) {
|
|
90
|
-
this.sessionAttrs.delete(name);
|
|
91
|
-
}
|
|
92
|
-
getCreationTime() {
|
|
93
|
-
return this.creationTime;
|
|
94
|
-
}
|
|
95
|
-
getLastAccessedTime() {
|
|
96
|
-
return this.lastAccessedTime;
|
|
97
|
-
}
|
|
98
|
-
setLastAccessedTime(lastAccessedTime) {
|
|
99
|
-
this.lastAccessedTime = lastAccessedTime;
|
|
100
|
-
}
|
|
101
|
-
getMaxInactiveInterval() {
|
|
102
|
-
return this.maxInactiveInterval;
|
|
103
|
-
}
|
|
104
|
-
setMaxInactiveInterval(interval) {
|
|
105
|
-
this.maxInactiveInterval = interval;
|
|
106
|
-
}
|
|
107
|
-
isExpired() {
|
|
108
|
-
if (this.maxInactiveInterval < 0) return false;
|
|
109
|
-
return Date.now() - this.maxInactiveInterval * 1e3 - this.lastAccessedTime >= 0;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
function resolveIndexesFor(session) {
|
|
113
|
-
const principalName = session.getAttribute(PRINCIPAL_NAME_INDEX_NAME);
|
|
114
|
-
if (principalName !== null) return principalName;
|
|
115
|
-
const jsonString = session.getAttribute(SPRING_SECURITY_CONTEXT);
|
|
116
|
-
if (typeof jsonString === "string") {
|
|
117
|
-
const context = JSON.parse(jsonString);
|
|
118
|
-
return context?.authentication?.name ?? context.authentication?.principal?.name ?? null;
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
34
|
var RedisSession = class {
|
|
123
35
|
cached;
|
|
124
36
|
isNew;
|
|
@@ -130,7 +42,7 @@ var RedisSession = class {
|
|
|
130
42
|
this.cached = cached;
|
|
131
43
|
this.isNew = isNew;
|
|
132
44
|
this.originalSessionId = cached.getId();
|
|
133
|
-
this.originalPrincipalName = resolveIndexesFor(this);
|
|
45
|
+
this.originalPrincipalName = (0, import_common.resolveIndexesFor)(this);
|
|
134
46
|
if (isNew) {
|
|
135
47
|
this.delta.set(CREATION_TIME_KEY, cached.getCreationTime());
|
|
136
48
|
this.delta.set(LAST_ACCESSED_TIME_KEY, cached.getLastAccessedTime());
|
|
@@ -190,7 +102,6 @@ var SortedSetRedisSessionExpirationStore = class {
|
|
|
190
102
|
redis;
|
|
191
103
|
namespace;
|
|
192
104
|
expirationsKey;
|
|
193
|
-
cleanupCount = 100;
|
|
194
105
|
constructor(redis, namespace) {
|
|
195
106
|
this.redis = redis;
|
|
196
107
|
this.namespace = namespace;
|
|
@@ -211,15 +122,10 @@ var SortedSetRedisSessionExpirationStore = class {
|
|
|
211
122
|
await this.remove(session.originalSessionId);
|
|
212
123
|
await this.save(session);
|
|
213
124
|
}
|
|
214
|
-
async cleanupExpiredSessions() {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
0,
|
|
219
|
-
"LIMIT",
|
|
220
|
-
0,
|
|
221
|
-
this.cleanupCount
|
|
222
|
-
);
|
|
125
|
+
async cleanupExpiredSessions(cleanupCount = 100) {
|
|
126
|
+
const key = this.expirationsKey;
|
|
127
|
+
const score = Date.now();
|
|
128
|
+
const sessionIds = await this.redis.zrevrangebyscore(key, score, 0, "LIMIT", 0, cleanupCount);
|
|
223
129
|
if (sessionIds.length === 0) return;
|
|
224
130
|
for (const sessionId of sessionIds) {
|
|
225
131
|
const sessionKey = this.getSessionKey(sessionId);
|
|
@@ -227,7 +133,7 @@ var SortedSetRedisSessionExpirationStore = class {
|
|
|
227
133
|
}
|
|
228
134
|
}
|
|
229
135
|
};
|
|
230
|
-
var
|
|
136
|
+
var RedisIndexedSessionRepository = class {
|
|
231
137
|
redis;
|
|
232
138
|
namespace;
|
|
233
139
|
expirationStore;
|
|
@@ -250,13 +156,13 @@ var RedisSessionRepository = class {
|
|
|
250
156
|
return ATTRIBUTE_PREFIX + name;
|
|
251
157
|
}
|
|
252
158
|
getPrincipalKey(principalName) {
|
|
253
|
-
return `${this.namespace}:index:${PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;
|
|
159
|
+
return `${this.namespace}:index:${import_common.PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;
|
|
254
160
|
}
|
|
255
161
|
async getSession(id, allowExpired) {
|
|
256
162
|
const key = this.getSessionKey(id);
|
|
257
163
|
const entries = await this.redis.hgetall(key);
|
|
258
164
|
if (!entries || Object.keys(entries).length === 0) return null;
|
|
259
|
-
const loaded = new MapSession(id);
|
|
165
|
+
const loaded = new import_map_session.MapSession(id);
|
|
260
166
|
if (!entries.creationTime) throw new Error("creationTime attribute not found");
|
|
261
167
|
if (!entries.lastAccessedTime) throw new Error("lastAccessedTime attribute not found");
|
|
262
168
|
if (!entries.maxInactiveInterval) throw new Error("maxInactiveInterval attribute not found");
|
|
@@ -288,14 +194,14 @@ var RedisSessionRepository = class {
|
|
|
288
194
|
if (removes.length !== 0) {
|
|
289
195
|
await this.redis.hdel(this.getSessionKey(sessionId), ...removes);
|
|
290
196
|
}
|
|
291
|
-
const principalSessionKey = this.getSessionAttrNameKey(PRINCIPAL_NAME_INDEX_NAME);
|
|
292
|
-
const securityPrincipalSessionKey = this.getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);
|
|
197
|
+
const principalSessionKey = this.getSessionAttrNameKey(import_common.PRINCIPAL_NAME_INDEX_NAME);
|
|
198
|
+
const securityPrincipalSessionKey = this.getSessionAttrNameKey(import_common.SPRING_SECURITY_CONTEXT);
|
|
293
199
|
if (session.delta.has(principalSessionKey) || session.delta.has(securityPrincipalSessionKey)) {
|
|
294
200
|
if (session.originalPrincipalName !== null) {
|
|
295
201
|
const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);
|
|
296
202
|
await this.redis.srem(originalPrincipalRedisKey, sessionId);
|
|
297
203
|
}
|
|
298
|
-
const principal = resolveIndexesFor(session);
|
|
204
|
+
const principal = (0, import_common.resolveIndexesFor)(session);
|
|
299
205
|
session.originalPrincipalName = principal;
|
|
300
206
|
if (principal !== null) {
|
|
301
207
|
const principalRedisKey = this.getPrincipalKey(principal);
|
|
@@ -346,7 +252,7 @@ var RedisSessionRepository = class {
|
|
|
346
252
|
}
|
|
347
253
|
// override
|
|
348
254
|
createSession() {
|
|
349
|
-
const cached = new MapSession();
|
|
255
|
+
const cached = new import_map_session.MapSession();
|
|
350
256
|
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
|
|
351
257
|
return new RedisSession(cached, true);
|
|
352
258
|
}
|
|
@@ -360,7 +266,7 @@ var RedisSessionRepository = class {
|
|
|
360
266
|
async deleteById(sessionId) {
|
|
361
267
|
const session = await this.getSession(sessionId, true);
|
|
362
268
|
if (!session) return;
|
|
363
|
-
const principal = resolveIndexesFor(session);
|
|
269
|
+
const principal = (0, import_common.resolveIndexesFor)(session);
|
|
364
270
|
if (principal !== null) {
|
|
365
271
|
await this.redis.srem(this.getPrincipalKey(principal), sessionId);
|
|
366
272
|
}
|
|
@@ -371,7 +277,7 @@ var RedisSessionRepository = class {
|
|
|
371
277
|
await this.save(session);
|
|
372
278
|
}
|
|
373
279
|
async findByIndexNameAndIndexValue(indexName, indexValue) {
|
|
374
|
-
if (indexName !== PRINCIPAL_NAME_INDEX_NAME) {
|
|
280
|
+
if (indexName !== import_common.PRINCIPAL_NAME_INDEX_NAME) {
|
|
375
281
|
return /* @__PURE__ */ new Map();
|
|
376
282
|
}
|
|
377
283
|
const principalKey = this.getPrincipalKey(indexValue);
|
|
@@ -389,36 +295,34 @@ var RedisSessionRepository = class {
|
|
|
389
295
|
return sessions;
|
|
390
296
|
}
|
|
391
297
|
async findByPrincipalName(principalName) {
|
|
392
|
-
return this.findByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);
|
|
298
|
+
return this.findByIndexNameAndIndexValue(import_common.PRINCIPAL_NAME_INDEX_NAME, principalName);
|
|
393
299
|
}
|
|
394
|
-
async cleanupExpiredSessions() {
|
|
395
|
-
await this.expirationStore.cleanupExpiredSessions();
|
|
300
|
+
async cleanupExpiredSessions(cleanupCount) {
|
|
301
|
+
await this.expirationStore.cleanupExpiredSessions(cleanupCount);
|
|
396
302
|
}
|
|
397
|
-
|
|
398
|
-
|
|
303
|
+
};
|
|
304
|
+
var RedisKVRepository = class {
|
|
305
|
+
redis;
|
|
306
|
+
constructor(redis) {
|
|
307
|
+
this.redis = redis;
|
|
399
308
|
}
|
|
400
309
|
async setItem(key, value, expiresIn) {
|
|
401
|
-
const k = this.getItemKey(key);
|
|
402
|
-
const v = JSON.stringify(value);
|
|
403
310
|
if (expiresIn) {
|
|
404
|
-
await this.redis.set(
|
|
311
|
+
await this.redis.set(key, value, "EX", expiresIn);
|
|
405
312
|
} else {
|
|
406
|
-
await this.redis.set(
|
|
313
|
+
await this.redis.set(key, value);
|
|
407
314
|
}
|
|
408
315
|
}
|
|
409
316
|
async getItem(key) {
|
|
410
|
-
|
|
411
|
-
const json = await this.redis.get(k);
|
|
412
|
-
return json ? JSON.parse(json) : null;
|
|
317
|
+
return await this.redis.get(key);
|
|
413
318
|
}
|
|
414
319
|
async removeItem(key) {
|
|
415
|
-
|
|
416
|
-
await this.redis.del(k);
|
|
320
|
+
await this.redis.del(key);
|
|
417
321
|
}
|
|
418
322
|
};
|
|
419
323
|
// Annotate the CommonJS export names for ESM import in node:
|
|
420
324
|
0 && (module.exports = {
|
|
421
|
-
|
|
422
|
-
|
|
325
|
+
RedisIndexedSessionRepository,
|
|
326
|
+
RedisKVRepository
|
|
423
327
|
});
|
|
424
328
|
//# sourceMappingURL=redis.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/session/redis.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport type { Redis } from 'ioredis';\nimport type { Namespace, SecurityContext, Session, SessionRepository } from './types';\n\nconst DEFAULT_MAX_INACTIVE_INTERVAL = 1800;\n\nconst CREATION_TIME_KEY = 'creationTime';\nconst LAST_ACCESSED_TIME_KEY = 'lastAccessedTime';\nconst MAX_INACTIVE_INTERVAL_KEY = 'maxInactiveInterval';\nconst ATTRIBUTE_PREFIX = 'sessionAttr:';\nconst SESSION_EXPIRES_PREFIX = 'expires:';\n\nconst SPRING_SECURITY_CONTEXT = 'SPRING_SECURITY_CONTEXT';\nexport const PRINCIPAL_NAME_INDEX_NAME = `org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME`;\n\nfunction generateId() {\n return randomUUID();\n}\n\nclass MapSession implements Session {\n private id: string;\n private sessionAttrs = new Map<string, string | number>();\n private creationTime = Date.now();\n private lastAccessedTime = this.creationTime;\n private maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;\n\n constructor(id?: string);\n constructor(session: Session);\n constructor(input?: string | Session) {\n if (typeof input === 'undefined') {\n this.id = generateId();\n } else if (typeof input === 'string') {\n this.id = input;\n } else {\n const session = input;\n this.id = session.getId();\n\n for (const attrName of session.getAttributeNames()) {\n const attrValue = session.getAttribute(attrName);\n if (attrValue !== null) {\n this.setAttribute(attrName, attrValue);\n }\n }\n\n this.lastAccessedTime = session.getLastAccessedTime();\n this.creationTime = session.getCreationTime();\n this.maxInactiveInterval = session.getMaxInactiveInterval();\n }\n }\n\n setCreationTime(creationTime: number) {\n this.creationTime = creationTime;\n }\n\n // override\n getId() {\n return this.id;\n }\n\n changeSessionId() {\n const changedId = generateId();\n this.id = changedId;\n return changedId;\n }\n\n getAttribute(name: string) {\n return this.sessionAttrs.get(name) ?? null;\n }\n\n getAttributeNames(): string[] {\n return Array.from(this.sessionAttrs.keys());\n }\n\n setAttribute(name: string, value: string | number) {\n if (value === null) {\n this.removeAttribute(name);\n } else {\n this.sessionAttrs.set(name, value);\n }\n }\n\n removeAttribute(name: string) {\n this.sessionAttrs.delete(name);\n }\n\n getCreationTime() {\n return this.creationTime;\n }\n\n getLastAccessedTime() {\n return this.lastAccessedTime;\n }\n\n setLastAccessedTime(lastAccessedTime: number) {\n this.lastAccessedTime = lastAccessedTime;\n }\n\n getMaxInactiveInterval() {\n return this.maxInactiveInterval;\n }\n\n setMaxInactiveInterval(interval: number) {\n this.maxInactiveInterval = interval;\n }\n\n isExpired() {\n if (this.maxInactiveInterval < 0) return false;\n return Date.now() - this.maxInactiveInterval * 1000 - this.lastAccessedTime >= 0;\n }\n}\n\nfunction resolveIndexesFor(session: Session): string | null {\n const principalName = session.getAttribute(PRINCIPAL_NAME_INDEX_NAME) as string | null;\n if (principalName !== null) return principalName;\n\n const jsonString = session.getAttribute(SPRING_SECURITY_CONTEXT);\n if (typeof jsonString === 'string') {\n const context = JSON.parse(jsonString) as SecurityContext;\n return context?.authentication?.name ?? context.authentication?.principal?.name ?? null;\n }\n return null;\n}\n\nclass RedisSession implements Session {\n private readonly cached: MapSession;\n\n public isNew: boolean;\n public delta = new Map<string, string | number | null>();\n public originalSessionId: string;\n public originalPrincipalName: string | null;\n public originalLastAccessTime: number | null = null;\n\n constructor(cached: MapSession, isNew: boolean) {\n this.cached = cached;\n this.isNew = isNew;\n this.originalSessionId = cached.getId();\n this.originalPrincipalName = resolveIndexesFor(this);\n\n if (isNew) {\n this.delta.set(CREATION_TIME_KEY, cached.getCreationTime());\n this.delta.set(LAST_ACCESSED_TIME_KEY, cached.getLastAccessedTime());\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, cached.getMaxInactiveInterval());\n this.cached.getAttributeNames().forEach((name) => {\n const value = this.cached.getAttribute(name);\n if (value) this.delta.set(this.getSessionAttrNameKey(name), value);\n });\n }\n }\n\n getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n // override\n setLastAccessedTime(lastAccessedTime: number) {\n this.cached.setLastAccessedTime(lastAccessedTime);\n this.delta.set(LAST_ACCESSED_TIME_KEY, lastAccessedTime);\n }\n\n isExpired() {\n return this.cached.isExpired();\n }\n\n getCreationTime() {\n return this.cached.getCreationTime();\n }\n\n getId() {\n return this.cached.getId();\n }\n\n changeSessionId() {\n return this.cached.changeSessionId();\n }\n\n getLastAccessedTime() {\n return this.cached.getLastAccessedTime();\n }\n\n setMaxInactiveInterval(interval: number) {\n this.cached.setMaxInactiveInterval(interval);\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, interval);\n }\n\n getMaxInactiveInterval() {\n return this.cached.getMaxInactiveInterval();\n }\n\n getAttribute(name: string) {\n return this.cached.getAttribute(name);\n }\n\n getAttributeNames() {\n return this.cached.getAttributeNames();\n }\n\n setAttribute(name: string, value: string) {\n this.cached.setAttribute(name, value);\n this.delta.set(this.getSessionAttrNameKey(name), value);\n }\n\n removeAttribute(name: string) {\n this.cached.removeAttribute(name);\n this.delta.set(this.getSessionAttrNameKey(name), null);\n }\n}\n\ninterface RedisSessionExpirationStore {\n save(session: RedisSession): Promise<void>;\n remove(sessionId: string): Promise<void>;\n rename(session: RedisSession): Promise<void>;\n cleanupExpiredSessions(): Promise<void>;\n}\n\nclass SortedSetRedisSessionExpirationStore implements RedisSessionExpirationStore {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationsKey: string;\n\n private cleanupCount = 100;\n\n constructor(redis: Redis, namespace: Namespace) {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationsKey = `${this.namespace}:sessions:expirations`;\n }\n\n getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n async save(session: RedisSession) {\n const expirationInMillis =\n session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000;\n await this.redis.zadd(this.expirationsKey, expirationInMillis, session.getId());\n }\n\n async remove(sessionId: string) {\n await this.redis.zrem(this.expirationsKey, sessionId);\n }\n\n async rename(session: RedisSession) {\n if (session.originalSessionId === null || session.originalSessionId === session.getId()) return;\n await this.remove(session.originalSessionId);\n await this.save(session);\n }\n\n async cleanupExpiredSessions() {\n const sessionIds = await this.redis.zrevrangebyscore(\n this.expirationsKey,\n Date.now(),\n 0,\n 'LIMIT',\n 0,\n this.cleanupCount\n );\n if (sessionIds.length === 0) return;\n for (const sessionId of sessionIds) {\n const sessionKey = this.getSessionKey(sessionId);\n // Checks if the session exists. By trying to access the session we only trigger a deletion\n // if the TTL is expired.\n await this.redis.exists(sessionKey);\n }\n }\n}\n\n// 15549130 <spring:session:sessions:uuid, hash<session>> + 300s\n// 15549147 <spring:session:sessions:expirations, sorted_set<uuid>> + 300s\n// 15548839 <spring:session:sessions:expires:uuid, string<empty>>\nexport class RedisSessionRepository implements SessionRepository<RedisSession> {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationStore: RedisSessionExpirationStore;\n\n private defaultMaxInactiveInterval = 1800;\n\n constructor(redis: Redis, namespace: Namespace = 'spring:session') {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationStore = new SortedSetRedisSessionExpirationStore(redis, namespace);\n }\n\n setDefaultMaxInactiveInterval(interval: number) {\n this.defaultMaxInactiveInterval = interval;\n }\n\n private getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n private getExpiredKey(sessionId: string) {\n return `${this.namespace}:sessions:expires:${sessionId}`;\n }\n\n private getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n private getPrincipalKey(principalName: string) {\n return `${this.namespace}:index:${PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;\n }\n\n private async getSession(id: string, allowExpired: boolean): Promise<RedisSession | null> {\n const key = this.getSessionKey(id);\n const entries = await this.redis.hgetall(key);\n if (!entries || Object.keys(entries).length === 0) return null;\n const loaded = new MapSession(id);\n if (!entries.creationTime) throw new Error('creationTime attribute not found');\n if (!entries.lastAccessedTime) throw new Error('lastAccessedTime attribute not found');\n if (!entries.maxInactiveInterval) throw new Error('maxInactiveInterval attribute not found');\n\n loaded.setCreationTime(Number(entries.creationTime));\n loaded.setLastAccessedTime(Number(entries.lastAccessedTime));\n loaded.setMaxInactiveInterval(Number(entries.maxInactiveInterval));\n\n for (const [key, value] of Object.entries(entries)) {\n if (key.startsWith(ATTRIBUTE_PREFIX)) {\n loaded.setAttribute(key.slice(ATTRIBUTE_PREFIX.length), value);\n }\n }\n\n if (!allowExpired && loaded.isExpired()) return null;\n const result = new RedisSession(loaded, false);\n result.originalLastAccessTime = loaded.getLastAccessedTime();\n return result;\n }\n\n private async saveDelta(session: RedisSession) {\n if (session.delta.size === 0) return;\n const sessionId = session.getId();\n const delta = new Map<string, string | number>();\n const removes: string[] = [];\n session.delta.forEach((value, key) => {\n if (value !== null) delta.set(key, value);\n else removes.push(key);\n });\n\n if (delta.size !== 0) {\n await this.redis.hset(this.getSessionKey(sessionId), delta);\n }\n if (removes.length !== 0) {\n await this.redis.hdel(this.getSessionKey(sessionId), ...removes);\n }\n\n const principalSessionKey = this.getSessionAttrNameKey(PRINCIPAL_NAME_INDEX_NAME);\n const securityPrincipalSessionKey = this.getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);\n if (session.delta.has(principalSessionKey) || session.delta.has(securityPrincipalSessionKey)) {\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, sessionId);\n }\n const principal = resolveIndexesFor(session);\n session.originalPrincipalName = principal;\n if (principal !== null) {\n const principalRedisKey = this.getPrincipalKey(principal);\n await this.redis.sadd(principalRedisKey, sessionId);\n }\n }\n\n if (session.isNew) {\n // here your can send session created message to channel\n session.isNew = false;\n }\n\n const sessionExpireInSeconds = session.getMaxInactiveInterval();\n\n // createShadowKey start\n const keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();\n const sessionKey = this.getSessionKey(keyToExpire);\n\n if (sessionExpireInSeconds < 0) {\n await this.redis.append(sessionKey, '');\n await this.redis.persist(sessionKey);\n await this.redis.persist(this.getSessionKey(session.getId()));\n } else if (sessionExpireInSeconds === 0) {\n await this.redis.del(sessionKey);\n } else {\n await this.redis.append(sessionKey, '');\n await this.redis.expire(sessionKey, sessionExpireInSeconds);\n }\n // createShadowKey end\n\n if (sessionExpireInSeconds > 0) {\n const fiveMinutesAfterExpires = sessionExpireInSeconds + 5 * 60;\n await this.redis.expire(this.getSessionKey(session.getId()), fiveMinutesAfterExpires);\n }\n\n await this.expirationStore.save(session);\n session.delta.clear();\n }\n\n private async saveChangeSessionId(session: RedisSession) {\n const sessionId = session.getId();\n if (sessionId === session.originalSessionId) return;\n if (!session.isNew) {\n const originalSessionIdKey = this.getSessionKey(session.originalSessionId);\n const sessionIdKey = this.getSessionKey(sessionId);\n const originalExpiredKey = this.getExpiredKey(session.originalSessionId);\n const expiredKey = this.getExpiredKey(sessionId);\n\n await this.redis.rename(originalSessionIdKey, sessionIdKey);\n await this.redis.rename(originalExpiredKey, expiredKey);\n\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, session.originalSessionId);\n await this.redis.sadd(originalPrincipalRedisKey, sessionId);\n }\n await this.expirationStore.rename(session);\n }\n session.originalSessionId = sessionId;\n }\n\n // override\n createSession() {\n const cached = new MapSession();\n cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);\n return new RedisSession(cached, true);\n }\n\n async save(session: RedisSession) {\n await this.saveChangeSessionId(session);\n await this.saveDelta(session);\n }\n\n async findById(sessionId: string): Promise<RedisSession | null> {\n return this.getSession(sessionId, false);\n }\n\n async deleteById(sessionId: string) {\n const session = await this.getSession(sessionId, true);\n if (!session) return;\n // 1. cleanup index\n const principal = resolveIndexesFor(session);\n if (principal !== null) {\n await this.redis.srem(this.getPrincipalKey(principal), sessionId);\n }\n // 2. delete in set\n await this.expirationStore.remove(sessionId);\n // 3. delete expired key\n const expiredKey = this.getExpiredKey(sessionId);\n await this.redis.del(expiredKey);\n\n session.setMaxInactiveInterval(0);\n await this.save(session);\n }\n\n async findByIndexNameAndIndexValue(indexName: string, indexValue: string) {\n if (indexName !== PRINCIPAL_NAME_INDEX_NAME) {\n return new Map<string, RedisSession>();\n }\n\n const principalKey = this.getPrincipalKey(indexValue);\n const sessionIds = await this.redis.smembers(principalKey);\n if (!sessionIds || sessionIds.length === 0) {\n return new Map<string, RedisSession>();\n }\n const sessions = new Map<string, RedisSession>();\n for (const sessionId of sessionIds) {\n const session = await this.findById(sessionId);\n if (session !== null) {\n sessions.set(sessionId, session);\n }\n }\n return sessions;\n }\n\n async findByPrincipalName(principalName: string) {\n return this.findByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);\n }\n\n async cleanupExpiredSessions() {\n await this.expirationStore.cleanupExpiredSessions();\n }\n\n private getItemKey(key: string) {\n return `${this.namespace.replace('session', 'storage')}:${key}`;\n }\n\n async setItem(key: string, value: unknown, expiresIn?: number) {\n const k = this.getItemKey(key);\n const v = JSON.stringify(value);\n if (expiresIn) {\n await this.redis.set(k, v, 'EX', expiresIn);\n } else {\n await this.redis.set(k, v);\n }\n }\n\n async getItem<T = unknown>(key: string): Promise<T | null> {\n const k = this.getItemKey(key);\n const json = await this.redis.get(k);\n return json ? (JSON.parse(json) as T) : null;\n }\n\n async removeItem(key: string) {\n const k = this.getItemKey(key);\n await this.redis.del(k);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAI3B,IAAM,gCAAgC;AAEtC,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,4BAA4B;AAClC,IAAM,mBAAmB;AACzB,IAAM,yBAAyB;AAE/B,IAAM,0BAA0B;AACzB,IAAM,4BAA4B;AAEzC,SAAS,aAAa;AACpB,aAAO,0BAAW;AACpB;AAEA,IAAM,aAAN,MAAoC;AAAA,EAC1B;AAAA,EACA,eAAe,oBAAI,IAA6B;AAAA,EAChD,eAAe,KAAK,IAAI;AAAA,EACxB,mBAAmB,KAAK;AAAA,EACxB,sBAAsB;AAAA,EAI9B,YAAY,OAA0B;AACpC,QAAI,OAAO,UAAU,aAAa;AAChC,WAAK,KAAK,WAAW;AAAA,IACvB,WAAW,OAAO,UAAU,UAAU;AACpC,WAAK,KAAK;AAAA,IACZ,OAAO;AACL,YAAM,UAAU;AAChB,WAAK,KAAK,QAAQ,MAAM;AAExB,iBAAW,YAAY,QAAQ,kBAAkB,GAAG;AAClD,cAAM,YAAY,QAAQ,aAAa,QAAQ;AAC/C,YAAI,cAAc,MAAM;AACtB,eAAK,aAAa,UAAU,SAAS;AAAA,QACvC;AAAA,MACF;AAEA,WAAK,mBAAmB,QAAQ,oBAAoB;AACpD,WAAK,eAAe,QAAQ,gBAAgB;AAC5C,WAAK,sBAAsB,QAAQ,uBAAuB;AA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ACzD,UAAM,IAAI,KAAK,WAAW,GAAG;AAC7B,UAAM,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC;AACnC,WAAO,OAAQ,KAAK,MAAM,IAAI,IAAU;AAAA,EAC1C;AAAA,EAEA,MAAM,WAAW,KAAa;AAC5B,UAAM,IAAI,KAAK,WAAW,GAAG;AAC7B,UAAM,KAAK,MAAM,IAAI,CAAC;AAAA,EACxB;AACF;","names":["key"]}
|
|
1
|
+
{"version":3,"sources":["../../src/session/redis.ts"],"sourcesContent":["import { resolveIndexesFor, PRINCIPAL_NAME_INDEX_NAME, SPRING_SECURITY_CONTEXT } from './common';\nimport { MapSession } from './map-session';\nimport type { Redis } from 'ioredis';\nimport type { KVRepository, Namespace, Session, SessionRepository } from './types';\n\nconst CREATION_TIME_KEY = 'creationTime';\nconst LAST_ACCESSED_TIME_KEY = 'lastAccessedTime';\nconst MAX_INACTIVE_INTERVAL_KEY = 'maxInactiveInterval';\nconst ATTRIBUTE_PREFIX = 'sessionAttr:';\nconst SESSION_EXPIRES_PREFIX = 'expires:';\n\nclass RedisSession implements Session {\n private readonly cached: MapSession;\n\n public isNew: boolean;\n public delta = new Map<string, string | number | null>();\n public originalSessionId: string;\n public originalPrincipalName: string | null;\n public originalLastAccessTime: number | null = null;\n\n constructor(cached: MapSession, isNew: boolean) {\n this.cached = cached;\n this.isNew = isNew;\n this.originalSessionId = cached.getId();\n this.originalPrincipalName = resolveIndexesFor(this);\n\n if (isNew) {\n this.delta.set(CREATION_TIME_KEY, cached.getCreationTime());\n this.delta.set(LAST_ACCESSED_TIME_KEY, cached.getLastAccessedTime());\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, cached.getMaxInactiveInterval());\n this.cached.getAttributeNames().forEach((name) => {\n const value = this.cached.getAttribute(name);\n if (value) this.delta.set(this.getSessionAttrNameKey(name), value);\n });\n }\n }\n\n getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n // override\n setLastAccessedTime(lastAccessedTime: number) {\n this.cached.setLastAccessedTime(lastAccessedTime);\n this.delta.set(LAST_ACCESSED_TIME_KEY, lastAccessedTime);\n }\n\n isExpired() {\n return this.cached.isExpired();\n }\n\n getCreationTime() {\n return this.cached.getCreationTime();\n }\n\n getId() {\n return this.cached.getId();\n }\n\n changeSessionId() {\n return this.cached.changeSessionId();\n }\n\n getLastAccessedTime() {\n return this.cached.getLastAccessedTime();\n }\n\n setMaxInactiveInterval(interval: number) {\n this.cached.setMaxInactiveInterval(interval);\n this.delta.set(MAX_INACTIVE_INTERVAL_KEY, interval);\n }\n\n getMaxInactiveInterval() {\n return this.cached.getMaxInactiveInterval();\n }\n\n getAttribute(name: string) {\n return this.cached.getAttribute(name);\n }\n\n getAttributeNames() {\n return this.cached.getAttributeNames();\n }\n\n setAttribute(name: string, value: string) {\n this.cached.setAttribute(name, value);\n this.delta.set(this.getSessionAttrNameKey(name), value);\n }\n\n removeAttribute(name: string) {\n this.cached.removeAttribute(name);\n this.delta.set(this.getSessionAttrNameKey(name), null);\n }\n}\n\ninterface RedisSessionExpirationStore {\n save(session: RedisSession): Promise<void>;\n remove(sessionId: string): Promise<void>;\n rename(session: RedisSession): Promise<void>;\n cleanupExpiredSessions(cleanupCount?: number): Promise<void>;\n}\n\nclass SortedSetRedisSessionExpirationStore implements RedisSessionExpirationStore {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationsKey: string;\n\n constructor(redis: Redis, namespace: Namespace) {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationsKey = `${this.namespace}:sessions:expirations`;\n }\n\n getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n async save(session: RedisSession) {\n const expirationInMillis =\n session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000;\n await this.redis.zadd(this.expirationsKey, expirationInMillis, session.getId());\n }\n\n async remove(sessionId: string) {\n await this.redis.zrem(this.expirationsKey, sessionId);\n }\n\n async rename(session: RedisSession) {\n if (session.originalSessionId === null || session.originalSessionId === session.getId()) return;\n await this.remove(session.originalSessionId);\n await this.save(session);\n }\n\n async cleanupExpiredSessions(cleanupCount: number = 100) {\n const key = this.expirationsKey;\n const score = Date.now();\n const sessionIds = await this.redis.zrevrangebyscore(key, score, 0, 'LIMIT', 0, cleanupCount);\n if (sessionIds.length === 0) return;\n for (const sessionId of sessionIds) {\n const sessionKey = this.getSessionKey(sessionId);\n // Checks if the session exists. By trying to access the session we only trigger a deletion\n // if the TTL is expired.\n await this.redis.exists(sessionKey);\n }\n }\n}\n\n// 15549130 <spring:session:sessions:uuid, hash<session>> + 300s\n// 15549147 <spring:session:sessions:expirations, sorted_set<uuid>> + 300s\n// 15548839 <spring:session:sessions:expires:uuid, string<empty>>\nexport class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {\n private readonly redis: Redis;\n private readonly namespace: Namespace;\n private readonly expirationStore: RedisSessionExpirationStore;\n\n private defaultMaxInactiveInterval = 1800;\n\n constructor(redis: Redis, namespace: Namespace = 'spring:session') {\n this.redis = redis;\n this.namespace = namespace;\n this.expirationStore = new SortedSetRedisSessionExpirationStore(redis, namespace);\n }\n\n setDefaultMaxInactiveInterval(interval: number) {\n this.defaultMaxInactiveInterval = interval;\n }\n\n private getSessionKey(sessionId: string) {\n return `${this.namespace}:sessions:${sessionId}`;\n }\n\n private getExpiredKey(sessionId: string) {\n return `${this.namespace}:sessions:expires:${sessionId}`;\n }\n\n private getSessionAttrNameKey(name: string) {\n return ATTRIBUTE_PREFIX + name;\n }\n\n private getPrincipalKey(principalName: string) {\n return `${this.namespace}:index:${PRINCIPAL_NAME_INDEX_NAME}:${principalName}`;\n }\n\n private async getSession(id: string, allowExpired: boolean): Promise<RedisSession | null> {\n const key = this.getSessionKey(id);\n const entries = await this.redis.hgetall(key);\n if (!entries || Object.keys(entries).length === 0) return null;\n const loaded = new MapSession(id);\n if (!entries.creationTime) throw new Error('creationTime attribute not found');\n if (!entries.lastAccessedTime) throw new Error('lastAccessedTime attribute not found');\n if (!entries.maxInactiveInterval) throw new Error('maxInactiveInterval attribute not found');\n\n loaded.setCreationTime(Number(entries.creationTime));\n loaded.setLastAccessedTime(Number(entries.lastAccessedTime));\n loaded.setMaxInactiveInterval(Number(entries.maxInactiveInterval));\n\n for (const [key, value] of Object.entries(entries)) {\n if (key.startsWith(ATTRIBUTE_PREFIX)) {\n loaded.setAttribute(key.slice(ATTRIBUTE_PREFIX.length), value);\n }\n }\n\n if (!allowExpired && loaded.isExpired()) return null;\n const result = new RedisSession(loaded, false);\n result.originalLastAccessTime = loaded.getLastAccessedTime();\n return result;\n }\n\n private async saveDelta(session: RedisSession) {\n if (session.delta.size === 0) return;\n const sessionId = session.getId();\n const delta = new Map<string, string | number>();\n const removes: string[] = [];\n session.delta.forEach((value, key) => {\n if (value !== null) delta.set(key, value);\n else removes.push(key);\n });\n\n if (delta.size !== 0) {\n await this.redis.hset(this.getSessionKey(sessionId), delta);\n }\n if (removes.length !== 0) {\n await this.redis.hdel(this.getSessionKey(sessionId), ...removes);\n }\n\n const principalSessionKey = this.getSessionAttrNameKey(PRINCIPAL_NAME_INDEX_NAME);\n const securityPrincipalSessionKey = this.getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);\n if (session.delta.has(principalSessionKey) || session.delta.has(securityPrincipalSessionKey)) {\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, sessionId);\n }\n const principal = resolveIndexesFor(session);\n session.originalPrincipalName = principal;\n if (principal !== null) {\n const principalRedisKey = this.getPrincipalKey(principal);\n await this.redis.sadd(principalRedisKey, sessionId);\n }\n }\n\n if (session.isNew) {\n // here your can send session created message to channel\n session.isNew = false;\n }\n\n const sessionExpireInSeconds = session.getMaxInactiveInterval();\n\n // createShadowKey start\n const keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();\n const sessionKey = this.getSessionKey(keyToExpire);\n\n if (sessionExpireInSeconds < 0) {\n await this.redis.append(sessionKey, '');\n await this.redis.persist(sessionKey);\n await this.redis.persist(this.getSessionKey(session.getId()));\n } else if (sessionExpireInSeconds === 0) {\n await this.redis.del(sessionKey);\n } else {\n await this.redis.append(sessionKey, '');\n await this.redis.expire(sessionKey, sessionExpireInSeconds);\n }\n // createShadowKey end\n\n if (sessionExpireInSeconds > 0) {\n const fiveMinutesAfterExpires = sessionExpireInSeconds + 5 * 60;\n await this.redis.expire(this.getSessionKey(session.getId()), fiveMinutesAfterExpires);\n }\n\n await this.expirationStore.save(session);\n session.delta.clear();\n }\n\n private async saveChangeSessionId(session: RedisSession) {\n const sessionId = session.getId();\n if (sessionId === session.originalSessionId) return;\n if (!session.isNew) {\n const originalSessionIdKey = this.getSessionKey(session.originalSessionId);\n const sessionIdKey = this.getSessionKey(sessionId);\n const originalExpiredKey = this.getExpiredKey(session.originalSessionId);\n const expiredKey = this.getExpiredKey(sessionId);\n\n await this.redis.rename(originalSessionIdKey, sessionIdKey);\n await this.redis.rename(originalExpiredKey, expiredKey);\n\n if (session.originalPrincipalName !== null) {\n const originalPrincipalRedisKey = this.getPrincipalKey(session.originalPrincipalName);\n await this.redis.srem(originalPrincipalRedisKey, session.originalSessionId);\n await this.redis.sadd(originalPrincipalRedisKey, sessionId);\n }\n await this.expirationStore.rename(session);\n }\n session.originalSessionId = sessionId;\n }\n\n // override\n createSession() {\n const cached = new MapSession();\n cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);\n return new RedisSession(cached, true);\n }\n\n async save(session: RedisSession) {\n await this.saveChangeSessionId(session);\n await this.saveDelta(session);\n }\n\n async findById(sessionId: string): Promise<RedisSession | null> {\n return this.getSession(sessionId, false);\n }\n\n async deleteById(sessionId: string) {\n const session = await this.getSession(sessionId, true);\n if (!session) return;\n // 1. cleanup index\n const principal = resolveIndexesFor(session);\n if (principal !== null) {\n await this.redis.srem(this.getPrincipalKey(principal), sessionId);\n }\n // 2. delete in set\n await this.expirationStore.remove(sessionId);\n // 3. delete expired key\n const expiredKey = this.getExpiredKey(sessionId);\n await this.redis.del(expiredKey);\n\n session.setMaxInactiveInterval(0);\n await this.save(session);\n }\n\n async findByIndexNameAndIndexValue(indexName: string, indexValue: string) {\n if (indexName !== PRINCIPAL_NAME_INDEX_NAME) {\n return new Map<string, RedisSession>();\n }\n\n const principalKey = this.getPrincipalKey(indexValue);\n const sessionIds = await this.redis.smembers(principalKey);\n if (!sessionIds || sessionIds.length === 0) {\n return new Map<string, RedisSession>();\n }\n const sessions = new Map<string, RedisSession>();\n for (const sessionId of sessionIds) {\n const session = await this.findById(sessionId);\n if (session !== null) {\n sessions.set(sessionId, session);\n }\n }\n return sessions;\n }\n\n async findByPrincipalName(principalName: string) {\n return this.findByIndexNameAndIndexValue(PRINCIPAL_NAME_INDEX_NAME, principalName);\n }\n\n async cleanupExpiredSessions(cleanupCount?: number) {\n await this.expirationStore.cleanupExpiredSessions(cleanupCount);\n }\n}\n\nexport class RedisKVRepository implements KVRepository {\n private readonly redis: Redis;\n\n constructor(redis: Redis) {\n this.redis = redis;\n }\n\n async setItem(key: string, value: string, expiresIn?: number) {\n if (expiresIn) {\n await this.redis.set(key, value, 'EX', expiresIn);\n } else {\n await this.redis.set(key, value);\n }\n }\n\n async getItem(key: string): Promise<string | null> {\n return await this.redis.get(key);\n }\n\n async removeItem(key: string) {\n await this.redis.del(key);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAsF;AACtF,yBAA2B;AAI3B,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,4BAA4B;AAClC,IAAM,mBAAmB;AACzB,IAAM,yBAAyB;AAE/B,IAAM,eAAN,MAAsC;AAAA,EACnB;AAAA,EAEV;AAAA,EACA,QAAQ,oBAAI,IAAoC;AAAA,EAChD;AAAA,EACA;AAAA,EACA,yBAAwC;AAAA,EAE/C,YAAY,QAAoB,OAAgB;AAC9C,SAAK,SAAS;AACd,SAA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AA,IACvC;AAEA,UAAM,eAAe,KAAK,gBAAgB,UAAU;AACpD,UAAM,aAAa,MAAM,KAAK,MAAM,SAAS,YAAY;AACzD,QAAI,CAAC,cAAc,WAAW,WAAW,GAAG;AAC1C,aAAO,oBAAI,IAA0B;AAAA,IACvC;AACA,UAAM,WAAW,oBAAI,IAA0B;AAC/C,eAAW,aAAa,YAAY;AAClC,YAAM,UAAU,MAAM,KAAK,SAAS,SAAS;AAC7C,UAAI,YAAY,MAAM;AACpB,iBAAS,IAAI,WAAW,OAAO;AAAA,MACjC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,oBAAoB,eAAuB;AAC/C,WAAO,KAAK,6BAA6B,yCAA2B,aAAa;AAAA,EACnF;AAAA,EAEA,MAAM,uBAAuB,cAAuB;AAClD,UAAM,KAAK,gBAAgB,uBAAuB,YAAY;AAAA,EAChE;AACF;AAEO,IAAM,oBAAN,MAAgD;AAAA,EACpC;AAAA,EAEjB,YAAY,OAAc;AACxB,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,MAAM,QAAQ,KAAa,OAAe,WAAoB;AAC5D,QAAI,WAAW;AACb,YAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,SAAS;AAAA,IAClD,OAAO;AACL,YAAM,KAAK,MAAM,IAAI,KAAK,KAAK;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ,KAAqC;AACjD,WAAO,MAAM,KAAK,MAAM,IAAI,GAAG;AAAA,EACjC;AAAA,EAEA,MAAM,WAAW,KAAa;AAC5B,UAAM,KAAK,MAAM,IAAI,GAAG;AAAA,EAC1B;AACF;","names":["key"]}
|
package/dist/session/redis.d.cts
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MapSession } from './map-session.cjs';
|
|
2
2
|
import { Redis } from 'ioredis';
|
|
3
|
+
import { SessionRepository, Session, Namespace, KVRepository } from './types.cjs';
|
|
3
4
|
import '../core/index.cjs';
|
|
4
5
|
|
|
5
|
-
declare const PRINCIPAL_NAME_INDEX_NAME = "org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME";
|
|
6
|
-
declare class MapSession implements Session {
|
|
7
|
-
private id;
|
|
8
|
-
private sessionAttrs;
|
|
9
|
-
private creationTime;
|
|
10
|
-
private lastAccessedTime;
|
|
11
|
-
private maxInactiveInterval;
|
|
12
|
-
constructor(id?: string);
|
|
13
|
-
constructor(session: Session);
|
|
14
|
-
setCreationTime(creationTime: number): void;
|
|
15
|
-
getId(): string;
|
|
16
|
-
changeSessionId(): `${string}-${string}-${string}-${string}-${string}`;
|
|
17
|
-
getAttribute(name: string): string | number | null;
|
|
18
|
-
getAttributeNames(): string[];
|
|
19
|
-
setAttribute(name: string, value: string | number): void;
|
|
20
|
-
removeAttribute(name: string): void;
|
|
21
|
-
getCreationTime(): number;
|
|
22
|
-
getLastAccessedTime(): number;
|
|
23
|
-
setLastAccessedTime(lastAccessedTime: number): void;
|
|
24
|
-
getMaxInactiveInterval(): number;
|
|
25
|
-
setMaxInactiveInterval(interval: number): void;
|
|
26
|
-
isExpired(): boolean;
|
|
27
|
-
}
|
|
28
6
|
declare class RedisSession implements Session {
|
|
29
7
|
private readonly cached;
|
|
30
8
|
isNew: boolean;
|
|
@@ -47,7 +25,7 @@ declare class RedisSession implements Session {
|
|
|
47
25
|
setAttribute(name: string, value: string): void;
|
|
48
26
|
removeAttribute(name: string): void;
|
|
49
27
|
}
|
|
50
|
-
declare class
|
|
28
|
+
declare class RedisIndexedSessionRepository implements SessionRepository<RedisSession> {
|
|
51
29
|
private readonly redis;
|
|
52
30
|
private readonly namespace;
|
|
53
31
|
private readonly expirationStore;
|
|
@@ -67,11 +45,14 @@ declare class RedisSessionRepository implements SessionRepository<RedisSession>
|
|
|
67
45
|
deleteById(sessionId: string): Promise<void>;
|
|
68
46
|
findByIndexNameAndIndexValue(indexName: string, indexValue: string): Promise<Map<string, RedisSession>>;
|
|
69
47
|
findByPrincipalName(principalName: string): Promise<Map<string, RedisSession>>;
|
|
70
|
-
cleanupExpiredSessions(): Promise<void>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
cleanupExpiredSessions(cleanupCount?: number): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
declare class RedisKVRepository implements KVRepository {
|
|
51
|
+
private readonly redis;
|
|
52
|
+
constructor(redis: Redis);
|
|
53
|
+
setItem(key: string, value: string, expiresIn?: number): Promise<void>;
|
|
54
|
+
getItem(key: string): Promise<string | null>;
|
|
74
55
|
removeItem(key: string): Promise<void>;
|
|
75
56
|
}
|
|
76
57
|
|
|
77
|
-
export {
|
|
58
|
+
export { RedisIndexedSessionRepository, RedisKVRepository };
|