Comparing version 1.1.3 to 1.2.0
@@ -1,7 +0,2 @@ | ||
import { SessionManager } from './SessionManager'; | ||
import { Redis } from 'ioredis'; | ||
declare function redisess(client: Redis, options?: SessionManager.Options): SessionManager; | ||
declare namespace redisess { | ||
var SessionManager: typeof import("./SessionManager").SessionManager; | ||
} | ||
export = redisess; | ||
export * from './SessionManager'; | ||
export * from './Session'; |
"use strict"; | ||
const SessionManager_1 = require("./SessionManager"); | ||
function redisess(client, options) { | ||
return new SessionManager_1.SessionManager(client, options); | ||
} | ||
redisess.SessionManager = SessionManager_1.SessionManager; | ||
module.exports = redisess; | ||
//# sourceMappingURL=index.js.map | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./SessionManager"), exports); | ||
__exportStar(require("./Session"), exports); |
@@ -7,3 +7,3 @@ "use strict"; | ||
this._src = src; | ||
this._sha = null; | ||
this._sha = ''; | ||
this._numberOfKeys = numberOfKeys || 0; | ||
@@ -22,3 +22,3 @@ } | ||
// Retry | ||
this._sha = null; | ||
this._sha = ''; | ||
return await this._execute(client, ...args); | ||
@@ -41,2 +41,1 @@ } | ||
exports.RedisScript = RedisScript; | ||
//# sourceMappingURL=RedisScript.js.map |
@@ -13,5 +13,5 @@ import { SessionManager } from './SessionManager'; | ||
private _userId; | ||
private _ttl?; | ||
private _lastAccess?; | ||
private _expires?; | ||
private _ttl; | ||
private _lastAccess; | ||
private _expires; | ||
/** | ||
@@ -18,0 +18,0 @@ * |
@@ -23,3 +23,3 @@ "use strict"; | ||
this._sessionId = opts.sessionId; | ||
this._userId = opts.userId; | ||
this._userId = opts.userId || ''; | ||
this._ttl = opts.ttl || 0; | ||
@@ -105,3 +105,3 @@ this._lastAccess = 0; | ||
const resp = await client.hmget(sessKey, ...args); | ||
this._userId = resp[0]; | ||
this._userId = resp[0] || ''; | ||
this._lastAccess = Number(resp[1]) || 0; | ||
@@ -259,2 +259,1 @@ this._expires = Number(resp[2]) || 0; | ||
exports.Session = Session; | ||
//# sourceMappingURL=Session.js.map |
@@ -20,9 +20,9 @@ import { Redis } from 'ioredis'; | ||
private readonly _additionalFields?; | ||
private readonly _killScript?; | ||
private readonly _writeScript?; | ||
private readonly _wipeScript?; | ||
private readonly _killAllScript?; | ||
private readonly _killScript; | ||
private readonly _writeScript; | ||
private readonly _wipeScript; | ||
private readonly _killAllScript; | ||
private _wipeTimer?; | ||
private _wipeInterval?; | ||
private _timediff; | ||
private _timeDiff; | ||
/** | ||
@@ -38,2 +38,4 @@ * | ||
constructor(client: Redis, props?: SessionManager.Options); | ||
get namespace(): string | undefined; | ||
get ttl(): number | undefined; | ||
/** | ||
@@ -73,3 +75,3 @@ * Returns the number of sessions within the last n seconds. | ||
*/ | ||
get(sessionId: string, noUpdate?: boolean): Promise<Session>; | ||
get(sessionId: string, noUpdate?: boolean): Promise<Session | undefined>; | ||
/** | ||
@@ -104,3 +106,3 @@ * Retrieves all session ids which were active within the last n seconds. | ||
*/ | ||
getOldestUserSession(userId: string, noUpdate?: boolean): Promise<Session>; | ||
getOldestUserSession(userId: string, noUpdate?: boolean): Promise<Session | undefined>; | ||
/** | ||
@@ -107,0 +109,0 @@ * Returns true if sessionId exists, false otherwise, |
@@ -32,5 +32,4 @@ "use strict"; | ||
this._ttl = Number(props.ttl) >= 0 ? Number(props.ttl) : (30 * 60); | ||
this._timediff = null; | ||
this._timeDiff = 0; | ||
this._wipeInterval = props.wipeInterval || 1000; | ||
this._wipeTimer = null; | ||
client.once('close', () => this.quit()); | ||
@@ -106,2 +105,8 @@ this._killScript = new RedisScript_1.RedisScript(` | ||
} | ||
get namespace() { | ||
return this._ns; | ||
} | ||
get ttl() { | ||
return this._ttl; | ||
} | ||
/** | ||
@@ -291,4 +296,6 @@ * Returns the number of sessions within the last n seconds. | ||
quit() { | ||
clearTimeout(this._wipeInterval); | ||
this._wipeInterval = null; | ||
if (this._wipeTimer) { | ||
clearTimeout(this._wipeTimer); | ||
this._wipeTimer = undefined; | ||
} | ||
} | ||
@@ -307,3 +314,3 @@ // noinspection JSMethodCanBeStatic | ||
// Synchronize redis server time with local time | ||
this._timediff = (Date.now() / 1000) - | ||
this._timeDiff = (Date.now() / 1000) - | ||
Math.floor(Number(resp[0]) + (Number(resp[1]) / 1000000)); | ||
@@ -313,3 +320,3 @@ return this._now(); | ||
_now() { | ||
return Math.floor(Date.now() / 1000 + this._timediff); | ||
return Math.floor(Date.now() / 1000 + this._timeDiff); | ||
} | ||
@@ -329,3 +336,3 @@ async _getClient() { | ||
} | ||
if (this._timediff == null) | ||
if (this._timeDiff == null) | ||
await this._syncTime(this._client); | ||
@@ -335,4 +342,6 @@ return this._client; | ||
async _wipe() { | ||
clearTimeout(this._wipeTimer); | ||
this._wipeTimer = null; | ||
if (this._wipeTimer) { | ||
clearTimeout(this._wipeTimer); | ||
this._wipeTimer = undefined; | ||
} | ||
const client = await this._getClient(); | ||
@@ -343,2 +352,1 @@ await this._wipeScript.execute(client, this._ns, this._now()); | ||
exports.SessionManager = SessionManager; | ||
//# sourceMappingURL=SessionManager.js.map |
{ | ||
"name": "redisess", | ||
"description": "Powerful redis session manager for NodeJS", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"author": "Panates Ltd.", | ||
@@ -63,6 +63,9 @@ "contributors": [ | ||
"compile": "tsc -b tsconfig.json", | ||
"test": "ts-mocha -p test/tsconfig.json --paths --reporter spec test/**/*.spec.ts", | ||
"cover": "nyc --reporter=cobertura --reporter html --reporter text npm run test", | ||
"test": "mocha --reporter spec test/*.test.js", | ||
"travis-cover": "nyc --reporter lcovonly npm run test" | ||
}, | ||
"dependencies": { | ||
"ts-mocha": "^8.0.0" | ||
} | ||
} |
@@ -26,6 +26,7 @@ | ||
```js | ||
const express = require("express"); | ||
const Redis = require("ioredis"); | ||
const {SessionManager} = require("redisess"); | ||
```ts | ||
import express from 'express'; | ||
import Redis from 'ioredis'; | ||
import {SessionManager} from 'redisess'; | ||
const redis = new Redis(); | ||
@@ -32,0 +33,0 @@ |
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
917
388
39253
2
11
+ Addedts-mocha@^8.0.0
+ Added@types/json5@0.0.29(transitive)
+ Added@ungap/promise-all-settled@1.1.2(transitive)
+ Addedansi-colors@4.1.1(transitive)
+ Addedansi-regex@3.0.15.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbrowser-stdout@1.3.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcamelcase@6.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedchokidar@3.5.1(transitive)
+ Addedcliui@7.0.4(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddebug@4.3.1(transitive)
+ Addeddecamelize@4.0.0(transitive)
+ Addeddiff@3.5.05.0.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedflat@5.0.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedglob@7.1.6(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedgrowl@1.10.5(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhe@1.2.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@2.0.03.0.0(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-plain-obj@2.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-yaml@4.0.0(transitive)
+ Addedjson5@1.0.2(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlog-symbols@4.0.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedminimatch@3.0.4(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedmocha@8.4.0(transitive)
+ Addedms@2.1.2(transitive)
+ Addednanoid@3.1.20(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreaddirp@3.5.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedserialize-javascript@5.0.1(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedstring-width@2.1.14.2.3(transitive)
+ Addedstrip-ansi@4.0.06.0.1(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@7.2.08.1.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedts-mocha@8.0.0(transitive)
+ Addedts-node@7.0.1(transitive)
+ Addedtsconfig-paths@3.15.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwide-align@1.1.3(transitive)
+ Addedworkerpool@6.1.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@16.2.0(transitive)
+ Addedyargs-parser@20.2.4(transitive)
+ Addedyargs-unparser@2.0.0(transitive)
+ Addedyn@2.0.0(transitive)
+ Addedyocto-queue@0.1.0(transitive)