connect-typeorm
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,6 +0,6 @@ | ||
/// <reference types="express-session" /> | ||
/*! | ||
* Connect - TypeORM | ||
* Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca> | ||
* Copyright(c) 2017 makepost <makepost@firemail.cc> | ||
* Copyright(c) 2017, 2018 makepost <makepost@firemail.cc> | ||
* Copyright(c) 2018 Nathan Phillip Brink <ohnobinki@ohnopublishing.net> | ||
* MIT Licensed | ||
@@ -30,11 +30,11 @@ */ | ||
*/ | ||
set: (sid: string, sess: any, fn: (error?: any) => void) => void; | ||
set: (sid: string, sess: any, fn?: ((error?: any) => void) | undefined) => void; | ||
/** | ||
* Destroys the session associated with the given `sid`. | ||
*/ | ||
destroy: (sid: string | string[], fn: (error?: any) => void) => void; | ||
destroy: (sid: string | string[], fn?: ((error?: any) => void) | undefined) => void; | ||
/** | ||
* Refreshes the time-to-live for the session with the given `sid`. | ||
*/ | ||
touch(sid: string, sess: any, fn: (error?: any) => void): void; | ||
touch: (sid: string, sess: any, fn?: ((error?: any) => void) | undefined) => void; | ||
/** | ||
@@ -44,5 +44,5 @@ * Fetches all sessions. | ||
all: (fn: (error: any, result: any) => void) => void; | ||
private createQueryBuilder(); | ||
private getTTL(sess, sid?); | ||
private handleError(er); | ||
private createQueryBuilder; | ||
private getTTL; | ||
private handleError; | ||
} |
@@ -5,3 +5,4 @@ "use strict"; | ||
* Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca> | ||
* Copyright(c) 2017 makepost <makepost@firemail.cc> | ||
* Copyright(c) 2017, 2018 makepost <makepost@firemail.cc> | ||
* Copyright(c) 2018 Nathan Phillip Brink <ohnobinki@ohnopublishing.net> | ||
* MIT Licensed | ||
@@ -55,3 +56,3 @@ */ | ||
catch (er) { | ||
return fn(er); | ||
return fn ? fn(er) : undefined; | ||
} | ||
@@ -69,6 +70,10 @@ args.push(json); | ||
this.debug("SET complete"); | ||
fn(); | ||
if (fn) { | ||
fn(); | ||
} | ||
}) | ||
.catch((er) => { | ||
fn(er); | ||
if (fn) { | ||
fn(er); | ||
} | ||
this.handleError(er); | ||
@@ -82,8 +87,12 @@ }); | ||
this.debug('DEL "%s"', sid); | ||
Promise.all((Array.isArray(sid) ? sid : [sid]).map((x) => this.repository.deleteById(x))) | ||
Promise.all((Array.isArray(sid) ? sid : [sid]).map((x) => this.repository.delete({ id: x }))) | ||
.then(() => { | ||
fn(); | ||
if (fn) { | ||
fn(); | ||
} | ||
}) | ||
.catch((er) => { | ||
fn(er); | ||
if (fn) { | ||
fn(er); | ||
} | ||
this.handleError(er); | ||
@@ -93,2 +102,26 @@ }); | ||
/** | ||
* Refreshes the time-to-live for the session with the given `sid`. | ||
*/ | ||
this.touch = (sid, sess, fn) => { | ||
const ttl = this.getTTL(sess); | ||
this.debug('EXPIRE "%s" ttl:%s', sid, ttl); | ||
this.repository | ||
.createQueryBuilder() | ||
.update({ expiredAt: Date.now() + ttl * 1000 }) | ||
.whereInIds([sid]) | ||
.execute() | ||
.then(() => { | ||
this.debug("EXPIRE complete"); | ||
if (fn) { | ||
fn(); | ||
} | ||
}) | ||
.catch((er) => { | ||
if (fn) { | ||
fn(er); | ||
} | ||
this.handleError(er); | ||
}); | ||
}; | ||
/** | ||
* Fetches all sessions. | ||
@@ -120,22 +153,2 @@ */ | ||
} | ||
/** | ||
* Refreshes the time-to-live for the session with the given `sid`. | ||
*/ | ||
touch(sid, sess, fn) { | ||
const ttl = this.getTTL(sess); | ||
this.debug('EXPIRE "%s" ttl:%s', sid, ttl); | ||
this.repository | ||
.createQueryBuilder() | ||
.update({ expiredAt: Date.now() + ttl * 1000 }) | ||
.whereInIds([sid]) | ||
.execute() | ||
.then(() => { | ||
this.debug("EXPIRE complete"); | ||
fn(); | ||
}) | ||
.catch((er) => { | ||
fn(er); | ||
this.handleError(er); | ||
}); | ||
} | ||
createQueryBuilder() { | ||
@@ -142,0 +155,0 @@ return this.repository.createQueryBuilder("session") |
{ | ||
"name": "connect-typeorm", | ||
"description": "A TypeORM-based session store", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "out/index", | ||
@@ -9,2 +9,5 @@ "typings": "out/index", | ||
"author": "makepost", | ||
"contributors": [ | ||
"Nathan Phillip Brink <ohnobinki@ohnopublishing.net>" | ||
], | ||
"license": "MIT", | ||
@@ -11,0 +14,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
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
229
15930
12