From d08665f370115461683a37dc20c6f339e60d21b2 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Mon, 30 Mar 2020 16:51:36 -0700 Subject: [PATCH] [express-mysql-session] Improve typings (#43436) * [express-mysql-session] Improve typings * [express-mysql-session] Revert unneeded changes * [express-mysql-session] Update version header * Revert "[express-mysql-session] Update version header" This reverts commit a6a15b97f6496603370df36dfdcdffb5ad0a601f. * [express-mysql-session] Use better name in all() callback --- .../express-mysql-session-tests.ts | 7 ++++++ types/express-mysql-session/index.d.ts | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/types/express-mysql-session/express-mysql-session-tests.ts b/types/express-mysql-session/express-mysql-session-tests.ts index a48a1acf2d..a3c0cba22c 100644 --- a/types/express-mysql-session/express-mysql-session-tests.ts +++ b/types/express-mysql-session/express-mysql-session-tests.ts @@ -9,8 +9,15 @@ const options = { user: 'root', password: '', database: 'session_test', + schema: { + columnNames: { + data: 'content', + }, + }, }; const sessionStore = new MySQLStore(options); sessionStore.close(); +sessionStore.get('my-session-id', (error, session) => {}); +sessionStore.all(); diff --git a/types/express-mysql-session/index.d.ts b/types/express-mysql-session/index.d.ts index 29f1f000e1..38668e3c10 100644 --- a/types/express-mysql-session/index.d.ts +++ b/types/express-mysql-session/index.d.ts @@ -1,6 +1,8 @@ // Type definitions for express-mysql-session 2.1 // Project: https://github.com/chill117/express-mysql-session#readme -// Definitions by: Akim95 , Sebastian Krüger +// Definitions by: Akim95 +// Sebastian Krüger +// Ionaru // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import * as expressSession from 'express-session'; @@ -20,17 +22,19 @@ declare namespace MySQLStore { expiration?: number; createDatabaseTable?: boolean; connectionLimit?: number; - schema?: Schema; + schema?: Partial; } interface Schema { tableName: string; - columnNames: ColumnNames; + columnNames: Partial; } interface ColumnNames { session_id: string; expires: string; data: string; } + + type MySQLStore = MySQLStoreClass; } declare class MySQLStoreClass { @@ -38,6 +42,10 @@ declare class MySQLStoreClass { setDefaultOptions(): void; + setOptions(options: MySQLStore.Options): void; + + validateOptions(options: MySQLStore.Options): void; + createDatabaseTable(callback?: (error: any) => void): void; get(sessionId: string, callback?: (error: any, session: any) => void): void; @@ -50,19 +58,17 @@ declare class MySQLStoreClass { length(callback?: (error: any, count: any) => void): void; + all(callback?: (error: any, sessions: any) => void): void; + clear(callback?: (error: any) => void): void; clearExpiredSessions(callback?: (error: any) => void): void; + query(sql: string, params: any, callback?: (error: any, rows: any, fields: any) => void): void; + setExpirationInterval(interval: number): void; clearExpirationInterval(): void; close(callback?: () => void): void; - - default(object: any, defaultValues: any, options?: any): void; - - clone(object: any): void; - - isObject(value: any): void; }