@midwayjs/session 3.13.0 → 3.13.6
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/dist/interface.d.ts +5 -1
- package/dist/lib/context.d.ts +5 -2
- package/dist/lib/context.js +10 -5
- package/dist/lib/session.d.ts +10 -2
- package/dist/lib/session.js +26 -4
- package/package.json +4 -4
package/dist/interface.d.ts
CHANGED
|
@@ -21,10 +21,14 @@ export interface ISession {
|
|
|
21
21
|
* commit this session's headers if autoCommit is set to false.
|
|
22
22
|
*/
|
|
23
23
|
manuallyCommit(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* regenerate this session
|
|
26
|
+
*/
|
|
27
|
+
regenerate(callback?: () => void): void;
|
|
24
28
|
/**
|
|
25
29
|
* save this session no matter whether it is populated
|
|
26
30
|
*/
|
|
27
|
-
save(): void;
|
|
31
|
+
save(callback?: () => void): void;
|
|
28
32
|
/**
|
|
29
33
|
* allow to put any value on session object
|
|
30
34
|
*/
|
package/dist/lib/context.d.ts
CHANGED
|
@@ -64,8 +64,11 @@ export declare class ContextSession {
|
|
|
64
64
|
*
|
|
65
65
|
* @api public
|
|
66
66
|
*/
|
|
67
|
-
commit(
|
|
68
|
-
|
|
67
|
+
commit({ save, regenerate }?: {
|
|
68
|
+
save?: boolean;
|
|
69
|
+
regenerate?: boolean;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
_shouldSaveSession(): "" | "changed" | "rolling" | "renew";
|
|
69
72
|
/**
|
|
70
73
|
* remove session
|
|
71
74
|
* @api private
|
package/dist/lib/context.js
CHANGED
|
@@ -194,7 +194,7 @@ class ContextSession {
|
|
|
194
194
|
*
|
|
195
195
|
* @api public
|
|
196
196
|
*/
|
|
197
|
-
async commit() {
|
|
197
|
+
async commit({ save = false, regenerate = false } = {}) {
|
|
198
198
|
const session = this.session;
|
|
199
199
|
const opts = this.opts;
|
|
200
200
|
const ctx = this.ctx;
|
|
@@ -206,7 +206,15 @@ class ContextSession {
|
|
|
206
206
|
await this.remove();
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
if (regenerate) {
|
|
210
|
+
await this.remove();
|
|
211
|
+
if (this.store)
|
|
212
|
+
this.externalKey = opts.genid && opts.genid(ctx);
|
|
213
|
+
}
|
|
214
|
+
// force save session when `session._requireSave` set
|
|
215
|
+
const reason = save || regenerate || session._requireSave
|
|
216
|
+
? 'force'
|
|
217
|
+
: this._shouldSaveSession();
|
|
210
218
|
debug('should save session: %s', reason);
|
|
211
219
|
if (!reason)
|
|
212
220
|
return;
|
|
@@ -220,9 +228,6 @@ class ContextSession {
|
|
|
220
228
|
_shouldSaveSession() {
|
|
221
229
|
const prevHash = this.prevHash;
|
|
222
230
|
const session = this.session;
|
|
223
|
-
// force save session when `session._requireSave` set
|
|
224
|
-
if (session._requireSave)
|
|
225
|
-
return 'force';
|
|
226
231
|
// do nothing if new and not populated
|
|
227
232
|
const json = session.toJSON();
|
|
228
233
|
if (!prevHash && !Object.keys(json).length)
|
package/dist/lib/session.d.ts
CHANGED
|
@@ -61,12 +61,20 @@ export declare class Session implements ISession {
|
|
|
61
61
|
*
|
|
62
62
|
* @api public
|
|
63
63
|
*/
|
|
64
|
-
save():
|
|
64
|
+
save(callback: any): any;
|
|
65
|
+
/**
|
|
66
|
+
* regenerate this session
|
|
67
|
+
*
|
|
68
|
+
* @param {Function} callback the optional function to call after regenerating the session
|
|
69
|
+
* @api public
|
|
70
|
+
*/
|
|
71
|
+
regenerate(callback: any): any;
|
|
65
72
|
/**
|
|
66
73
|
* commit this session's headers if autoCommit is set to false
|
|
67
74
|
*
|
|
68
75
|
* @api public
|
|
69
76
|
*/
|
|
70
|
-
manuallyCommit():
|
|
77
|
+
manuallyCommit(): any;
|
|
78
|
+
commit(options?: any, callback?: any): any;
|
|
71
79
|
}
|
|
72
80
|
//# sourceMappingURL=session.d.ts.map
|
package/dist/lib/session.js
CHANGED
|
@@ -96,16 +96,38 @@ class Session {
|
|
|
96
96
|
*
|
|
97
97
|
* @api public
|
|
98
98
|
*/
|
|
99
|
-
save() {
|
|
100
|
-
this.
|
|
99
|
+
save(callback) {
|
|
100
|
+
return this.commit({ save: true }, callback);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* regenerate this session
|
|
104
|
+
*
|
|
105
|
+
* @param {Function} callback the optional function to call after regenerating the session
|
|
106
|
+
* @api public
|
|
107
|
+
*/
|
|
108
|
+
regenerate(callback) {
|
|
109
|
+
return this.commit({ regenerate: true }, callback);
|
|
101
110
|
}
|
|
102
111
|
/**
|
|
103
112
|
* commit this session's headers if autoCommit is set to false
|
|
104
113
|
*
|
|
105
114
|
* @api public
|
|
106
115
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
manuallyCommit() {
|
|
117
|
+
return this.commit();
|
|
118
|
+
}
|
|
119
|
+
commit(options, callback) {
|
|
120
|
+
if (typeof options === 'function') {
|
|
121
|
+
callback = options;
|
|
122
|
+
options = {};
|
|
123
|
+
}
|
|
124
|
+
const promise = this._sessCtx.commit(options);
|
|
125
|
+
if (callback) {
|
|
126
|
+
promise.then(() => callback(), callback);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return promise;
|
|
130
|
+
}
|
|
109
131
|
}
|
|
110
132
|
}
|
|
111
133
|
exports.Session = Session;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/session",
|
|
3
3
|
"description": "midway session component for koa and faas",
|
|
4
|
-
"version": "3.13.
|
|
4
|
+
"version": "3.13.6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"index.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@midwayjs/core": "^3.13.
|
|
14
|
-
"@midwayjs/mock": "^3.13.
|
|
13
|
+
"@midwayjs/core": "^3.13.6",
|
|
14
|
+
"@midwayjs/mock": "^3.13.6"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@midwayjs/cookies": "^1.0.2"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"type": "git",
|
|
40
40
|
"url": "https://github.com/midwayjs/midway.git"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "684bb9ff9e66bf0d4e2e13559fac562dd9205bc4"
|
|
43
43
|
}
|