Skip to content

Instantly share code, notes, and snippets.

@NaridaL
Created May 31, 2017 23:07
Show Gist options
  • Save NaridaL/e86703c5f93d128dc8c9fc94e1c064f9 to your computer and use it in GitHub Desktop.
Save NaridaL/e86703c5f93d128dc8c9fc94e1c064f9 to your computer and use it in GitHub Desktop.
declare module 'express-session' {
import express = require('express');
import node = require('events');
function session(options?: session.SessionOptions): express.RequestHandler;
namespace session {
export interface SessionOptions {
secret: string;
name?: string;
store?: Store | MemoryStore;
cookie?: express.CookieOptions;
genid?: (req: express.Request) => string;
rolling?: boolean;
resave?: boolean;
proxy?: boolean;
saveUninitialized?: boolean;
unset?: string;
}
export interface BaseMemoryStore {
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
destroy: (sid: string, callback: (err: any) => void) => void;
length?: (callback: (err: any, length: number) => void) => void;
clear?: (callback: (err: any) => void) => void;
}
export abstract class Store extends node.EventEmitter {
constructor(config?: any);
regenerate(req: express.Request, fn: (err: any) => any): void;
load(sid: string, fn: (err: any, session: Express.Session) => any): void;
createSession(req: express.Request, sess: Express.SessionData): void;
get(sid: string, callback: (err: any, session: Express.SessionData) => void): void;
set(sid: string, session: Express.Session, callback: (err: any) => void): void;
destroy(sid: string, callback: (err: any) => void): void;
all(callback: (err: any, obj: { [sid: string]: Express.SessionData; }) => void): void;
length(callback: (err: any, length: number) => void): void;
clear(callback: (err: any) => void): void;
}
export class MemoryStore implements BaseMemoryStore {
get(sid: string, callback: (err: any, session: Express.Session) => void): void;
set(sid: string, session: Express.Session, callback: (err: any) => void): void;
destroy(sid: string, callback: (err: any) => void): void;
all(callback: (err: any, obj: { [sid: string]: Express.Session; }) => void): void;
length(callback: (err: any, length: number) => void): void;
clear(callback: (err: any) => void): void;
}
}
global {
namespace Express {
export interface Request {
session?: Session;
sessionID?: string;
sessionStore: session.Store
}
export interface SessionData {
[key: string]: any;
cookie: Express.SessionCookieData;
}
export interface SessionCookieData {
originalMaxAge: number;
path: string;
maxAge: number;
secure?: boolean;
httpOnly: boolean;
domain?: string;
expires: Date | boolean;
}
export interface SessionCookie extends SessionCookieData {
serialize: (name: string, value: string) => string;
}
export interface Session extends SessionData {
id: string;
regenerate: (callback: (err: any) => void) => void;
destroy: (callback: (err: any) => void) => void;
reload: (callback: (err: any) => void) => void;
save: (callback: (err: any) => void) => void;
touch: (callback: (err: any) => void) => void;
cookie: SessionCookie;
}
}
//export = express
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment