connect-redis
Advanced tools
Comparing version 7.0.1 to 7.1.0
@@ -11,3 +11,3 @@ import { SessionData, Store } from "express-session"; | ||
interface Serializer { | ||
parse(s: string): SessionData; | ||
parse(s: string): SessionData | Promise<SessionData>; | ||
stringify(s: SessionData): string; | ||
@@ -20,3 +20,5 @@ } | ||
serializer?: Serializer; | ||
ttl?: number; | ||
ttl?: number | { | ||
(sess: SessionData): number; | ||
}; | ||
disableTTL?: boolean; | ||
@@ -30,3 +32,5 @@ disableTouch?: boolean; | ||
serializer: Serializer; | ||
ttl: number; | ||
ttl: number | { | ||
(sess: SessionData): number; | ||
}; | ||
disableTTL: boolean; | ||
@@ -33,0 +37,0 @@ disableTouch: boolean; |
@@ -56,3 +56,3 @@ "use strict"; | ||
return cb(); | ||
return cb(null, this.serializer.parse(data)); | ||
return cb(null, await this.serializer.parse(data)); | ||
} | ||
@@ -158,2 +158,5 @@ catch (err) { | ||
_getTTL(sess) { | ||
if (typeof this.ttl === "function") { | ||
return this.ttl(sess); | ||
} | ||
let ttl; | ||
@@ -160,0 +163,0 @@ if (sess && sess.cookie && sess.cookie.expires) { |
@@ -11,3 +11,3 @@ import { SessionData, Store } from "express-session"; | ||
interface Serializer { | ||
parse(s: string): SessionData; | ||
parse(s: string): SessionData | Promise<SessionData>; | ||
stringify(s: SessionData): string; | ||
@@ -20,3 +20,5 @@ } | ||
serializer?: Serializer; | ||
ttl?: number; | ||
ttl?: number | { | ||
(sess: SessionData): number; | ||
}; | ||
disableTTL?: boolean; | ||
@@ -30,3 +32,5 @@ disableTouch?: boolean; | ||
serializer: Serializer; | ||
ttl: number; | ||
ttl: number | { | ||
(sess: SessionData): number; | ||
}; | ||
disableTTL: boolean; | ||
@@ -33,0 +37,0 @@ disableTouch: boolean; |
@@ -54,3 +54,3 @@ import { Store } from "express-session"; | ||
return cb(); | ||
return cb(null, this.serializer.parse(data)); | ||
return cb(null, await this.serializer.parse(data)); | ||
} | ||
@@ -156,2 +156,5 @@ catch (err) { | ||
_getTTL(sess) { | ||
if (typeof this.ttl === "function") { | ||
return this.ttl(sess); | ||
} | ||
let ttl; | ||
@@ -158,0 +161,0 @@ if (sess && sess.cookie && sess.cookie.expires) { |
12
index.ts
@@ -15,3 +15,3 @@ import {SessionData, Store} from "express-session" | ||
interface Serializer { | ||
parse(s: string): SessionData | ||
parse(s: string): SessionData | Promise<SessionData> | ||
stringify(s: SessionData): string | ||
@@ -25,3 +25,3 @@ } | ||
serializer?: Serializer | ||
ttl?: number | ||
ttl?: number | {(sess: SessionData): number} | ||
disableTTL?: boolean | ||
@@ -36,3 +36,3 @@ disableTouch?: boolean | ||
serializer: Serializer | ||
ttl: number | ||
ttl: number | {(sess: SessionData): number} | ||
disableTTL: boolean | ||
@@ -89,3 +89,3 @@ disableTouch: boolean | ||
if (!data) return cb() | ||
return cb(null, this.serializer.parse(data)) | ||
return cb(null, await this.serializer.parse(data)) | ||
} catch (err) { | ||
@@ -188,2 +188,6 @@ return cb(err) | ||
private _getTTL(sess: SessionData) { | ||
if (typeof this.ttl === "function") { | ||
return this.ttl(sess) | ||
} | ||
let ttl | ||
@@ -190,0 +194,0 @@ if (sess && sess.cookie && sess.cookie.expires) { |
{ | ||
"name": "connect-redis", | ||
"description": "Redis session store for Connect", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -92,2 +92,11 @@ ![Build Status](https://github.com/tj/connect-redis/workflows/build/badge.svg?branch=master) [![npm](https://img.shields.io/npm/v/connect-redis.svg)](https://npmjs.com/package/connect-redis) [![code-style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://gitter.im/jlongster/prettier) ![Downloads](https://img.shields.io/npm/dm/connect-redis.svg) | ||
```ts | ||
interface RedisStoreOptions { | ||
... | ||
ttl?: number | {(sess: SessionData): number} | ||
} | ||
``` | ||
`ttl` also has external callback support. You can use it for dynamic TTL generation. It has access to `session` data. | ||
**Note**: The TTL is reset every time a user interacts with the server. You can disable this behavior in _some_ instances by using `disableTouch`. | ||
@@ -117,5 +126,7 @@ | ||
Optionally `parse` method can be async if need be. | ||
```ts | ||
interface Serializer { | ||
parse(string): object | ||
parse(string): object | Promise<object> | ||
stringify(object): string | ||
@@ -122,0 +133,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
43707
984
140