diff --git a/types/documentdb-session/documentdb-session-tests.ts b/types/documentdb-session/documentdb-session-tests.ts new file mode 100644 index 0000000000..af5dba62cb --- /dev/null +++ b/types/documentdb-session/documentdb-session-tests.ts @@ -0,0 +1,18 @@ +import express = require("express"); +import session = require("express-session"); +import DocumentDBSession = require("documentdb-session"); + +const DocumentDBStore = DocumentDBSession(session); +const store = new DocumentDBStore({ + database: "MY_DATABASE", + collection: "MY_COLLECTION", + host: "https://sample.documents.azure.com:443/", + ttl: 60 * 60 * 10, // 10 hours + key: "magic key" +}); + +const app = express(); +session({ + store, + secret: "I can count all the way to 55", +}); diff --git a/types/documentdb-session/index.d.ts b/types/documentdb-session/index.d.ts new file mode 100644 index 0000000000..69914bdc6c --- /dev/null +++ b/types/documentdb-session/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for documentdb-session 1.0 +// Project: https://github.com/dwhieb/documentdb-session#readme +// Definitions by: Daniel Rosenwasser +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import session = require("express-session"); + +export = DocumentDBSession; + +declare function DocumentDBSession(expressSession: typeof session): DocumentDBStoreConstructor; + +interface DocumentDBStoreConstructor { + new (options: Options): session.Store; +} + +interface Options { + /** + * The ID of the collection where the session data should be stored. + * If the collection does not exist, it will be created when the session store initializes. + * The collection may contain other data, or it may be a dedicated collection just for sessions. + * + * @default `"sessions"` + */ + collection?: string; + + /** + * The ID of the database where the session data should be stored. + * If the database does not exist, it will be creaed when the session store initializes. + * + * @default `"sessionstore"` + */ + database?: string; + + /** + * By default, `documentdb-session` sets a `"type"` attribute on each session document with a value of `"session"`, + * to distinguish session documents from other documents in the collection. + * If you would like a different attribute or value to be used to discriminate session documents from other documents, + * enter that as an attribute-value pair in an object here, e.g. `{ site: "mysite.com" }` or `{ _type: "session" }`. + * + * @default `{ type: "session" }` + */ + discriminator?: object; + /** + * The URL / hostname of your DocumentDB database account, usually of the form `https://mydbaccount.documents.azure.com:443/`. + * You can also provide this in an environment variable, (`DOCUMENTDB_URL`) instead. + */ + host: string; + /** + * The primary key for your DocumentDB account. + * A primary key is required because `documentdb-session` may create a new database for your account, if none exists. + * You can also provide this in an environment variable (`DOCUMENTDB_KEY`) instead. + */ + key: string; + /** + * The TTL (time-to-live or expiration time) for your sessions, in seconds. + * After this time has elapsed since the last change to the session data, the session will be deleted. + * A session's TTL is extended each time session data is changed, restarting the timer. + * See more on [**Configuring TTL**](https://github.com/dwhieb/documentdb-session#configuring-ttl-time-to-live-or-expiration-time). + * *Enabling TTL is strongly recommended.* + */ + ttl?: number; +} diff --git a/types/documentdb-session/tsconfig.json b/types/documentdb-session/tsconfig.json new file mode 100644 index 0000000000..478f009cc6 --- /dev/null +++ b/types/documentdb-session/tsconfig.json @@ -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", + "documentdb-session-tests.ts" + ] +} diff --git a/types/documentdb-session/tslint.json b/types/documentdb-session/tslint.json new file mode 100644 index 0000000000..4978339df9 --- /dev/null +++ b/types/documentdb-session/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-irregular-whitespace": false + } +} \ No newline at end of file