Typing koa.Context for koa-generic-session

This commit is contained in:
Ragg
2017-05-22 23:32:29 +09:00
parent ec48aab17f
commit 8117819ce7
2 changed files with 22 additions and 1 deletions
+10 -1
View File
@@ -1,6 +1,6 @@
// Type definitions for koa-generic-session 1.x
// Project: https://github.com/koajs/generic-session
// Definitions by: Nick Simmons <https://github.com/nsimmons/>
// Definitions by: Nick Simmons <https://github.com/nsimmons/>, Ragg <https://github.com/Ragg-/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as Koa from "koa";
@@ -8,6 +8,7 @@ import * as Koa from "koa";
declare namespace koaSession {
interface Session {
cookie: any;
[key: string]: any;
}
interface SessionIdStore {
@@ -50,5 +51,13 @@ declare namespace koaSession {
const MemoryStore: SessionStore;
}
declare module 'koa' {
interface Context {
session: koaSession.Session|null;
sessionSave: boolean|null;
regenerateSession(): Generator;
}
}
declare function koaSession(options: koaSession.SessionOptions): Koa.Middleware;
export = koaSession;
@@ -32,4 +32,16 @@ app.use(session({
beforeSave: (ctx: Koa.Context, session: Session) => {}
}));
app.use((context: Koa.Context) => {
if (! context.session) {
return;
}
context.regenerateSession();
context.sessionSave = true;
context.session.cookie;
context.session.key = 'value';
context.session = null;
});
app.listen(80);