connect-lowdb
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -15,51 +15,59 @@ const lowdbStore = (session) => { | ||
async get(sid, cb) { | ||
await this.db.read(); | ||
get(sid, cb) { | ||
this.db.read() | ||
.then(() => { | ||
this.db.data ||= { sessions: [] }; | ||
this.db.data.sessions ||= []; | ||
this.db.data.sessions ||= []; | ||
const dbSession = this.db.data.sessions | ||
.find(session => session.sid === sid); | ||
const dbSession = this.db.data.sessions | ||
.find(session => session.sid === sid); | ||
cb(null, dbSession ? dbSession.session : null); | ||
cb(null, dbSession ? dbSession.session : null); | ||
}) | ||
.catch((err) => { cb(err); });; | ||
} | ||
async set(sid, session, cb) { | ||
await this.db.read(); | ||
this.db.data.sessions ||= []; | ||
const sessionObj = { | ||
sid, | ||
session, | ||
}; | ||
const dbSession = this.db.data.sessions | ||
.find(session => session.sid === sid); | ||
if (dbSession) { | ||
const dbSessionIx = this.db.data.sessions | ||
.findIndex(session => session.sid === sid); | ||
this.db.data.sessions[dbSessionIx] = sessionObj; | ||
} else { | ||
this.db.data.sessions.push(sessionObj); | ||
} | ||
await this.db.write(); | ||
cb(null); | ||
set(sid, session, cb) { | ||
this.db.read() | ||
.then(() => { | ||
this.db.data ||= { sessions: [] }; | ||
this.db.data.sessions ||= []; | ||
const sessionObj = { sid, session }; | ||
const dbSession = this.db.data.sessions | ||
.find(session => session.sid === sid); | ||
if (dbSession) { | ||
const dbSessionIx = this.db.data.sessions | ||
.findIndex(session => session.sid === sid); | ||
this.db.data.sessions[dbSessionIx] = sessionObj; | ||
} else { | ||
this.db.data.sessions.push(sessionObj); | ||
} | ||
this.db.write() | ||
.then(() => { cb(null); }) | ||
.catch((err) => { cb(err); });; | ||
}) | ||
.catch((err) => { cb(err); });; | ||
} | ||
async destroy(sid, cb) { | ||
await this.db.read(); | ||
destroy(sid, cb) { | ||
this.db.read() | ||
.then(() => { | ||
this.db.data ||= { sessions: [] }; | ||
this.db.data.sessions ||= []; | ||
this.db.data.sessions ||= []; | ||
const dbSessionIx = this.db.data.sessions | ||
.findIndex(session => session.sid === sid); | ||
const dbSessionIx = this.db.data.sessions | ||
.findIndex(session => session.sid === sid); | ||
this.db.data.sessions.splice(dbSessionIx, 1); | ||
await this.db.write(); | ||
cb(null); | ||
this.db.data.sessions.splice(dbSessionIx, 1); | ||
this.db.write() | ||
.then(() => { cb(null); }) | ||
.catch((err) => { cb(err); }); | ||
}) | ||
.catch((err) => { cb(err); });; | ||
} | ||
@@ -66,0 +74,0 @@ } |
{ | ||
"name": "connect-lowdb", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "lowdb session store for Connect", | ||
@@ -5,0 +5,0 @@ "exports": "./index.js", |
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
5842
61