-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement session.all() #343
Conversation
6f0178e
to
49adffc
Compare
49adffc
to
e559ffd
Compare
Codecov Report
@@ Coverage Diff @@
## master #343 +/- ##
==========================================
+ Coverage 90.34% 90.37% +0.02%
==========================================
Files 112 112
Lines 3324 3334 +10
Branches 791 791
==========================================
+ Hits 3003 3013 +10
Misses 281 281
Partials 40 40
Continue to review full report at Codecov.
|
e559ffd
to
644ab17
Compare
src/session/SessionStore.js
Outdated
@@ -5,6 +5,7 @@ import { type Session } from './Session'; | |||
export interface SessionStore { | |||
init(): Promise<SessionStore>; | |||
read(key: string): Promise<Session | null>; | |||
all(): Promise<Array<?Session>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise<Array<Session>>
@@ -27,6 +27,10 @@ export default class CacheBasedSessionStore implements SessionStore { | |||
return (this._cache.get(key): any); | |||
} | |||
|
|||
async all(): Promise<Array<?Session>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise<Array<Session>>
src/session/MongoSessionStore.js
Outdated
@@ -8,6 +7,7 @@ import { type Session } from './Session'; | |||
import { type SessionStore } from './SessionStore'; | |||
|
|||
type MongoCollection = { | |||
find: () => { toArray: () => Promise<Array<any>> }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find returns a Cursor: http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html
type Cursor = {
toArray: () => Promise<Array<any>>
};
type MongoCollection = {
find: () => Cursor
//
};
src/session/MongoSessionStore.js
Outdated
@@ -61,6 +61,17 @@ export default class MongoSessionStore implements SessionStore { | |||
} | |||
} | |||
|
|||
async all(): Promise<Array<?Session>> { | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not try catch here for the user, just return it:
return this._sessions.find().toArray();
f909a50
to
6c2d9e8
Compare
await store.put('x', { a: 1 }, 5); | ||
await store.put('y', { a: 2 }, 5); | ||
|
||
const result1 = await store.all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why using result1 instead of result?
|
||
const result1 = await store.all(); | ||
|
||
expect(result1).toEqual(expect.arrayContaining([{ a: 1 }, { a: 2 }])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work without arrayContaining
src/session/FileSessionStore.js
Outdated
@@ -39,6 +39,11 @@ export default class FileSessionStore implements SessionStore { | |||
return session; | |||
} | |||
|
|||
async all(): Promise<Array<Session>> { | |||
const sessions = await this._jfs.all(); | |||
return sessions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this._jfs.all()
cd14741
to
fc50702
Compare
src/cache/RedisCacheStore.js
Outdated
|
||
while (cursor !== '0') { | ||
/* eslint-disable no-await-in-loop */ | ||
const result = await this._redis.scan(cursor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [nextCursor, newkeys] = await this._redis.scan(cursor);
cursor = nextCursor;
keys = keys.concat(newkeys);
fc50702
to
4fc6fa2
Compare
4fc6fa2
to
6053ec3
Compare
close #316