mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #26696 from NattapongSiri/master
Define type for connect-mongodb-session
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import * as express from 'express'
|
||||
import session = require('express-session')
|
||||
import connectMongo = require('connect-mongodb-session')
|
||||
let MongoDBStore = connectMongo(session)
|
||||
|
||||
var app = express();
|
||||
var store = new MongoDBStore({
|
||||
uri: 'mongodb://localhost:27017/connect_mongodb_session_test',
|
||||
collection: 'mySessions'
|
||||
}, function(error) {
|
||||
// some connection error occur
|
||||
});
|
||||
|
||||
store.on('connected', function() {
|
||||
store.client; // The underlying MongoClient object from the MongoDB driver
|
||||
});
|
||||
|
||||
// Catch errors
|
||||
store.on('error', function(error) {
|
||||
});
|
||||
|
||||
app.use(require('express-session')({
|
||||
secret: 'This is a secret',
|
||||
cookie: {
|
||||
maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week
|
||||
},
|
||||
store: store,
|
||||
// Boilerplate options, see:
|
||||
// * https://www.npmjs.com/package/express-session#resave
|
||||
// * https://www.npmjs.com/package/express-session#saveuninitialized
|
||||
resave: true,
|
||||
saveUninitialized: true
|
||||
}));
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.send('Hello ' + JSON.stringify(req.session));
|
||||
});
|
||||
|
||||
const server = app.listen(3000);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// Type definitions for connect-mongodb-session
|
||||
// Project: https://github.com/kcbanner/connect-mongodb-session
|
||||
// Definitions by: Nattapong Sirilappanich <https://github.com/NattapongSiri>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="express-session" />
|
||||
|
||||
import session = require('express-session');
|
||||
import * as express from 'express';
|
||||
import {MongoClient, MongoClientOptions} from 'mongodb'
|
||||
|
||||
declare function connect(fn : (options?: session.SessionOptions) => express.RequestHandler) : connectMongodbSession.MongoDBStore
|
||||
|
||||
declare namespace connectMongodbSession {
|
||||
export interface MongoDBStore extends session.Store {
|
||||
client : MongoClient
|
||||
new(connection?: ConnectionInfo, callback?: (error : Error) => void) : MongoDBStore
|
||||
}
|
||||
|
||||
export interface ConnectionInfo {
|
||||
idField? : string
|
||||
collection : string
|
||||
connectionOptions?: MongoClientOptions
|
||||
databaseName?: string
|
||||
expires?: number
|
||||
uri : string
|
||||
}
|
||||
}
|
||||
|
||||
export = connect
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "../",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"noEmit": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"connect-mongodb-session-tests.ts",
|
||||
"index.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user