koa-session
Advanced tools
Comparing version 6.3.1 to 6.4.0
6.4.0 / 2023-02-04 | ||
================== | ||
**features** | ||
* [[`4cd3bef`](http://github.com/koajs/session/commit/4cd3bef4fc1900b847d2e133e3b2599a711f1aea)] - feat: Add Session.regenerate() method (#221) (Jürg Lehni <<juerg@scratchdisk.com>>) | ||
6.3.1 / 2023-01-03 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -216,3 +216,3 @@ 'use strict'; | ||
async commit() { | ||
async commit({ save = false, regenerate = false } = {}) { | ||
const session = this.session; | ||
@@ -230,4 +230,9 @@ const opts = this.opts; | ||
} | ||
if (regenerate) { | ||
await this.remove(); | ||
if (this.store) this.externalKey = opts.genid && opts.genid(ctx); | ||
} | ||
const reason = this._shouldSaveSession(); | ||
// force save session when `session._requireSave` set | ||
const reason = save || regenerate || session._requireSave ? 'force' : this._shouldSaveSession(); | ||
debug('should save session: %s', reason); | ||
@@ -248,5 +253,2 @@ if (!reason) return; | ||
// force save session when `session._requireSave` set | ||
if (session._requireSave) return 'force'; | ||
// do nothing if new and not populated | ||
@@ -253,0 +255,0 @@ const json = session.toJSON(); |
@@ -120,10 +120,22 @@ 'use strict'; | ||
* | ||
* @param {Function} callback the optional function to call after saving the session | ||
* @api public | ||
*/ | ||
save() { | ||
this._requireSave = true; | ||
save(callback) { | ||
return this.commit({ save: true }, callback); | ||
} | ||
/** | ||
* regenerate this session | ||
* | ||
* @param {Function} callback the optional function to call after regenerating the session | ||
* @api public | ||
*/ | ||
regenerate(callback) { | ||
return this.commit({ regenerate: true }, callback); | ||
} | ||
/** | ||
* commit this session's headers if autoCommit is set to false | ||
@@ -134,8 +146,20 @@ * | ||
async manuallyCommit() { | ||
await this._sessCtx.commit(); | ||
manuallyCommit() { | ||
return this.commit(); | ||
} | ||
commit(options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
const promise = this._sessCtx.commit(options); | ||
if (callback) { | ||
promise.then(() => callback(), callback); | ||
} else { | ||
return promise; | ||
} | ||
} | ||
} | ||
module.exports = Session; |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/session", | ||
"version": "6.3.1", | ||
"version": "6.4.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "koa", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35458
592