Add koa-generic-session types (#16155)

Add an optional extended description…
This commit is contained in:
Nicholas Simmons
2017-04-26 18:21:38 -04:00
committed by Sheetal Nandi
parent 692a3c7637
commit c340b2e633
4 changed files with 112 additions and 0 deletions

54
types/koa-generic-session/index.d.ts vendored Normal file
View File

@@ -0,0 +1,54 @@
// Type definitions for koa-generic-session 1.x
// Project: https://github.com/koajs/generic-session
// Definitions by: Nick Simmons <https://github.com/nsimmons/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as Koa from "koa";
declare namespace koaSession {
interface Session {
cookie: any;
}
interface SessionIdStore {
get(): any;
set(sid: string, session: Session): void;
reset(): void;
}
interface SessionStore {
(): SessionStore;
get(sid: string): any;
set(sid: string, session: Session, ttl: number): void;
destroy(sid: string): void;
}
interface SessionOptions {
key?: string;
store?: SessionStore;
ttl?: number;
prefix?: string;
cookie?: {
path?: string;
rewrite?: boolean;
signed?: boolean;
maxAge?: number;
secure?: boolean;
httpOnly?: boolean;
};
allowEmpty?: boolean;
defer?: boolean;
reconnectTimeout?: number;
rolling?: boolean;
sessionIdStore?: SessionIdStore;
genSid?(length: number): string;
errorHandler?(error: Error, type: string, ctx: Koa.Context): void;
valid?(ctx: Koa.Context, session: Session): boolean;
beforeSave?(ctx: Koa.Context, session: Session): void;
}
const MemoryStore: SessionStore;
}
declare function koaSession(options: koaSession.SessionOptions): Koa.Middleware;
export = koaSession;

View File

@@ -0,0 +1,35 @@
import * as Koa from "koa";
import {MemoryStore, Session} from "koa-generic-session";
import session = require("koa-generic-session");
const app = new Koa();
app.use(session({
key: 'sessionKey',
store: MemoryStore(),
ttl: 60 * 60,
prefix: 'a-prefix',
cookie: {
path: '/test',
rewrite: false,
signed: false,
maxAge: 60 * 60,
secure: true,
httpOnly: true,
},
allowEmpty: false,
defer: false,
reconnectTimeout: 100,
rolling: false,
sessionIdStore: {
get: () => 'something',
set: (sid: string, session: Session) => {},
reset: () => {}
},
genSid: (length: number) => 'aSid',
errorHandler: (error: Error, type: string, ctx: Koa.Context) => {},
valid: (ctx: Koa.Context, session: Session) => true,
beforeSave: (ctx: Koa.Context, session: Session) => {}
}));
app.listen(80);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"koa-generic-session-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }