Skip to content
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

New TypeScript typings #93

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
export type MySQLSessionStoreOptions = {

/** Host name for database connection: */
host: string;

/** Port number for database connection: */
port: number;

/** Database user: */
user: string;

/** Password for the above database user: */
password: string;

/** Database name: */
database: string;



/** Whether or not to automatically check for and clear expired sessions: */
clearExpired?: boolean;

/** How frequently expired sessions will be cleared; milliseconds: */
checkExpirationInterval?: number;

/** The maximum age of a valid session; milliseconds: */
expiration?: number;

/** Whether or not to create the sessions database table, if one does not already exist: */
createDatabaseTable?: boolean;

/** Number of connections when creating a connection pool: */
connectionLimit?: number;

/** Whether or not to end the database connection when the store is closed.
The default value of this option depends on whether or not a connection was passed to the constructor.
If a connection object is passed to the constructor, the default value for this option is false. */
endConnectionOnClose?: boolean;

charset?: string;

schema?: {
tableName: string;
columnNames: {
session_id: string;
expires: string;
data: string;
}
}
}



export class MySQLStore {
constructor(options: MySQLSessionStoreOptions, connection?: any, callback?: (error?: any) => void);
constructor(options: Partial<MySQLSessionStoreOptions>, connection: any, callback?: (error?: any) => void);

setOptions(options: MySQLSessionStoreOptions): any;
validateOptions(options: any): boolean;
createDatabaseTable(cb: (error?: any) => void): any;

// Internal functions
private query(sql: any, params: any, cb: any): any;
private clearExpiredSessions(cb: (error?: any) => void): any;
private setExpirationInterval(interval: number): any;
private clearExpirationInterval(): any;
private close(cb: (error?: any) => void): any;

// Implemented Store methods
get: (sid: string, callback: (err: any, session?: Express.SessionData | null) => void) => void;
set: (sid: string, session: Express.SessionData, callback?: (err?: any) => void) => void;
destroy: (sid: string, callback?: (err?: any) => void) => void;
all: (callback: (err: any, obj?: { [sid: string]: Express.SessionData; } | null) => void) => void;
length: (callback: (err: any, length?: number | null) => void) => void;
clear: (callback?: (err?: any) => void) => void;
touch: (sid: string, session: Express.SessionData, callback?: (err?: any) => void) => void;
}


export default function MySQLStoreFactory(session: any): typeof MySQLStore;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "A MySQL session store for express.js",
"version": "2.1.1",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"benchmarks": "./node_modules/.bin/mocha test/benchmarks/ --recursive --reporter spec --ui bdd",
"lint": "./node_modules/.bin/eslint --config .eslintrc.js *.js test/**/*.js",
Expand Down