connect-pg-simple: add types (#20109)

* connect-pg-simple: add types

* connect-pg-simple: PGStoreOptions should be optional

* connect-pg-simple: add close and pruneSessions methods

* connect-pg-simple: use correct import form in tests
This commit is contained in:
Pasi Eronen
2017-10-03 21:04:10 +03:00
committed by Ryan Cavanaugh
parent a6954cc035
commit 1fcbed38d7
4 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import connectPgSimple = require("connect-pg-simple");
import * as session from "express-session";
import * as pg from "pg";
import * as express from "express";
const pgSession = connectPgSimple(session);
const pgPool = new pg.Pool({});
const store1: session.Store = new pgSession({
pool: pgPool,
tableName: "user_sessions",
pruneSessionInterval: 300
});
const app = express();
app.use(session({
store: store1,
secret: "foo"
}));
const store2: session.Store = new pgSession({
conString: "postgres://postgres@localhost:5432/foo",
ttl: 3600,
schemaName: "someschema",
pruneSessionInterval: false,
errorLog: (...args) => console.error(...args)
});
const store3 = new pgSession({
conObject: {
host: "localhost",
user: "database-user",
max: 20,
idleTimeoutMillis: 30000
}
});
const store4 = new pgSession();
store4.close();
store4.pruneSessions();
store4.pruneSessions(err => console.log(err));

33
types/connect-pg-simple/index.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
// Type definitions for connect-pg-simple 4.2
// Project: https://github.com/voxpelli/node-connect-pg-simple#readme
// Definitions by: Pasi Eronen <https://github.com/pasieronen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
import { RequestHandler } from "express";
import { Store, SessionOptions } from "express-session";
import { Pool, PoolConfig } from "pg";
declare function connectPgSimple(session: (options?: SessionOptions) => RequestHandler): typeof connectPgSimple.PGStore;
declare namespace connectPgSimple {
class PGStore extends Store {
constructor(options?: PGStoreOptions);
close(): void;
pruneSessions(callback?: (err: Error) => void): void;
}
interface PGStoreOptions {
pool?: Pool;
pgPromise?: object; // not typed to avoid dependency to "pg-promise" module (which includes its own types)
conString?: string;
conObject?: PoolConfig;
ttl?: number;
schemaName?: string;
tableName?: string;
pruneSessionInterval?: false | number;
// tslint:disable-next-line:prefer-method-signature
errorLog?: (...args: any[]) => void;
}
}
export = connectPgSimple;

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",
"connect-pg-simple-tests.ts"
]
}

View File

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