connect-session-knex
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -7,7 +7,13 @@ Change Log | ||
**2.1.0** | ||
- [Add disableDbCleanup option](https://github.com/gx0r/connect-session-knex/pull/78) | ||
- [Add Postgres support for case sensitive custom tablename](https://github.com/gx0r/connect-session-knex/pull/79) | ||
- [Added 'lint' script to package.json](https://github.com/gx0r/connect-session-knex/pull/80) | ||
- [Implemented store.all() method](https://github.com/gx0r/connect-session-knex/pull/81) | ||
**2.0.0** | ||
- Bug fix: https://github.com/llambda/connect-session-knex/pull/73 (As this fix is a typing change, a major version was incremented) | ||
- [Fix typings for createtable option](https://github.com/llambda/connect-session-knex/pull/73) (As this fix is a typing change, a major version was incremented) | ||
**1.7.3** | ||
- Bug fix: https://github.com/llambda/connect-session-knex/pull/68 | ||
- [Fix handling datatype in older mysql versions(< 5.7.8)](https://github.com/gx0r/connect-session-knex/pull/68) | ||
@@ -20,3 +26,3 @@ **1.7.2** | ||
- Bug fix: https://github.com/llambda/connect-session-knex/pull/65 | ||
- [Fix missing argument on next tick of dbCleanup](https://github.com/gx0r/connect-session-knex/pull/65) | ||
- Split the lib into 1. lib 2. tests 3. examples 4. typings to make it more maintainable | ||
@@ -23,0 +29,0 @@ - Added Changelog.md |
@@ -6,3 +6,3 @@ /* eslint-disable func-names */ | ||
const {resolve} = Bluebird; | ||
const { resolve } = Bluebird; | ||
const util = require('util'); | ||
@@ -60,3 +60,2 @@ const { | ||
module.exports = function (connect) { | ||
@@ -88,2 +87,8 @@ /** | ||
if (!options.disableDbCleanup) { | ||
// Flag to prevent dbCleanup from being initialized | ||
// eslint-disable-next-line no-param-reassign | ||
options.disableDbCleanup = false; | ||
} | ||
self.createtable = Object.prototype.hasOwnProperty.call(options, 'createtable') | ||
@@ -108,4 +113,4 @@ ? options.createtable | ||
return new Promise((res) => { | ||
isDbSupportJSON(self.knex).then((isSupport) => { | ||
return self.knex.schema.createTable(self.tablename, (table) => { | ||
isDbSupportJSON(self.knex) | ||
.then((isSupport) => self.knex.schema.createTable(self.tablename, (table) => { | ||
table.string(self.sidfieldname).primary(); | ||
@@ -129,4 +134,3 @@ if (isSupport) { | ||
res(); | ||
}); | ||
}); | ||
})); | ||
}); | ||
@@ -137,3 +141,3 @@ } | ||
.then((exists) => { | ||
if (exists) { | ||
if (exists && !options.disableDbCleanup) { | ||
dbCleanup(self, options.clearInterval, KnexStore); | ||
@@ -185,3 +189,3 @@ } | ||
const self = this; | ||
const {maxAge} = sessObject.cookie; | ||
const { maxAge } = sessObject.cookie; | ||
const now = new Date().getTime(); | ||
@@ -339,3 +343,37 @@ const expired = maxAge ? now + maxAge : now + oneDay; | ||
/* fetch the dbCleanupTimeout */ | ||
KnexStore.prototype.getNextDbCleanup = function () { | ||
return KnexStore.nextDbCleanup ? KnexStore.nextDbCleanup : null; | ||
}; | ||
/* | ||
* Attempt to fetch all sessions. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
KnexStore.prototype.all = function (fn) { | ||
if (typeof fn !== 'function') { | ||
throw new Error('Callback is required.'); | ||
} | ||
const self = this; | ||
return self.ready.then(() => { | ||
const condition = expiredCondition(self.knex); | ||
return resolve(self.knex | ||
.select('sess') | ||
.from(self.tablename) | ||
.whereRaw(condition, dateAsISO(self.knex)) | ||
.then((rows) => rows.map((row) => { | ||
if (typeof row.sess === 'string') { | ||
return JSON.parse(row.sess); | ||
} | ||
return row.sess; | ||
}))) | ||
.asCallback(fn); | ||
}); | ||
}; | ||
return KnexStore; | ||
}; |
@@ -66,3 +66,2 @@ /* | ||
/* | ||
@@ -105,5 +104,5 @@ * Return datastore appropriate string of the current time | ||
+ '( ' | ||
+ ` update ${ | ||
+ ` update "${ | ||
tablename | ||
} cs set ` | ||
}" cs set ` | ||
+ ` ${ | ||
@@ -124,5 +123,5 @@ sidfieldname | ||
+ ')' | ||
+ `insert into ${ | ||
+ `insert into "${ | ||
tablename | ||
} (${ | ||
}" (${ | ||
sidfieldname | ||
@@ -202,3 +201,2 @@ }, expired, sess) ` | ||
/* | ||
@@ -205,0 +203,0 @@ * Return dialect-aware type name for timestamp |
{ | ||
"name": "connect-session-knex", | ||
"description": "A knex.js session store for Express and Connect", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -16,10 +16,12 @@ "typings": "typings/index.d.ts", | ||
"type": "git", | ||
"url": "git@github.com:llambda/connect-session-knex.git" | ||
"url": "git@github.com:gx0r/connect-session-knex.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/llambda/connect-session-knex/issues" | ||
"url": "https://github.com/gx0r/connect-session-knex/issues" | ||
}, | ||
"homepage": "https://github.com/llambda/connect-session-knex", | ||
"homepage": "https://github.com/gx0r/connect-session-knex", | ||
"scripts": { | ||
"test": "node tests/index.js" | ||
"test": "node tests/index.js", | ||
"lint": "eslint lib/ tests/", | ||
"lint-fix": "eslint --fix lib/ tests" | ||
}, | ||
@@ -26,0 +28,0 @@ "license": "ISC", |
@@ -40,2 +40,3 @@ # Connect Session Knex | ||
- `clearInterval` milliseconds between clearing expired sessions. Defaults to 60000. | ||
- `disableDbCleanup` disables the automatic clearing of expired sessions. Defaults to false. | ||
@@ -87,2 +88,3 @@ If the table does not exist in the schema, this module will attempt to create it unless the 'createtable' option is false. | ||
Install Postgresql | ||
Instructions for Ubuntu after intalling the db: | ||
@@ -111,2 +113,3 @@ | ||
Install Mysql | ||
Instructions for Ubuntu after installing the db: | ||
@@ -113,0 +116,0 @@ |
@@ -11,2 +11,3 @@ import * as Knex from 'knex'; | ||
clearInterval?: number; | ||
disableDbCleanup?: boolean; | ||
}; | ||
@@ -13,0 +14,0 @@ |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
23774
588
147
1