Skip to content

Commit

Permalink
Merge branch 'feat/import-export-review'
Browse files Browse the repository at this point in the history
  • Loading branch information
mingchuno committed Mar 11, 2021
2 parents db2b101 + bf34738 commit 93be37d
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### **BREAKING CHANGES**

- Use `export =` for better cjs require without `.default`

### Added

- Add typescript example

## [4.3.1] - 2021-03-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion MIGRATION_V4.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Next step is to import the dependencies

Javascript:
```js
const MongoStore = require('connect-mongo').default;
const MongoStore = require('connect-mongo');
```

Typescript:
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MongoDB session store for [Connect](https://github.com/senchalabs/connect) and [
- [Express or Connect integration](#express-or-connect-integration)
- [Connection to MongoDB](#connection-to-mongodb)
- [Known issues](#known-issues)
- [MongoError exports circular dependency](#mongoerror-exports-circular-dependency)
- [Events](#events)
- [Session expiration](#session-expiration)
- [Remove expired sessions](#remove-expired-sessions)
Expand All @@ -39,6 +40,9 @@ npm install connect-mongo
yarn add connect-mongo
```

* If you are upgrading from v3.x to v4, please checkout the [migration guide](./MIGRATION_V4.md) for details.
* If you are upgrading v4.x to latest version, you may check the [example](./example) and [options](#options) for details.

## Compatibility

* Support Express up to `5.0`
Expand All @@ -57,7 +61,17 @@ Express `4.x`, `5.0` and Connect `3.x`:

```js
const session = require('express-session');
const MongoStore = require('connect-mongo').default;
const MongoStore = require('connect-mongo');

app.use(session({
secret: 'foo',
store: MongoStore.create(options)
}));
```

```ts
import session from 'express-session'
import MongoStore from 'connect-mongo'

app.use(session({
secret: 'foo',
Expand Down Expand Up @@ -116,7 +130,16 @@ app.use(session({

## Known issues

[Known issues](https://github.com/jdesboeufs/connect-mongo/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
[Known issues](https://github.com/jdesboeufs/connect-mongo/issues?q=is%3Aopen+is%3Aissue+label%3Abug) in GitHub Issues page.

### MongoError exports circular dependency

The following error can be safely ignore from [official reply](https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/5).

```
(node:16580) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
```

## Events

Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express')
const session = require('express-session')
const MongoStore = require('connect-mongo').default
const MongoStore = require('connect-mongo')

const app = express()
const port = 3000
Expand Down
2 changes: 1 addition & 1 deletion example/mongoose.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express')
const session = require('express-session')
const MongoStore = require('connect-mongo').default
const MongoStore = require('connect-mongo')
const mongoose = require('mongoose');

const app = express()
Expand Down
10 changes: 9 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node index.js"
"start:js": "node index.js",
"start:mongoose": "node mongoose.js",
"start:ts": "tsc && node build/ts-example.js"
},
"resolutions": {
"mongodb": "3.6.3"
},
"dependencies": {
"connect-mongo": "^4.1.0",
"express": "^4.17.1",
"express-session": "^1.17.1",
"mongoose": "5.11.15"
},
"devDependencies": {
"typescript": "^4.2.3"
}
}
32 changes: 32 additions & 0 deletions example/ts-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import express from 'express'
import session from 'express-session'
import MongoStore from 'connect-mongo'

const app = express()
const port = 3000

declare module 'express-session' {
interface SessionData {
foo: string
}
}

app.use(session({
secret: 'foo',
resave: false,
saveUninitialized: false,
store: MongoStore.create({
mongoUrl: 'mongodb://root:example@127.0.0.1:27017',
dbName: "example-db",
stringify: false,
})
}));

app.get('/', (req, res) => {
req.session.foo = 'test-id'
res.send('Hello World!')
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
71 changes: 71 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
54 changes: 23 additions & 31 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"@types/node" "*"

"@types/mongodb@^3.5.27":
version "3.6.8"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.8.tgz#f80f0a3022c44d8db659a936434403ca3f4661df"
integrity sha512-8qNbL5/GFrljXc/QijcuQcUMYZ1iWNcqnJ6tneROwbfU0LsAjQ9bmq3aHi5lWXM4cyBPd2F/n9INAk/pZZttHw==
version "3.6.9"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.9.tgz#55f7e5b04f33904a12d6f0ab4f5d119a5062ade4"
integrity sha512-2XSGr/+IOKeFQ5tU9ATcIiIr7bpHqWyOXNGLOOhp0kg2NnfEvoKZF1SZ25j4zvJRqM2WeSUjfWSvymFJ3HBGJQ==
dependencies:
"@types/bson" "*"
"@types/node" "*"

"@types/node@*":
version "14.14.31"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==
version "14.14.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.33.tgz#9e4f8c64345522e4e8ce77b334a8aaa64e2b6c78"
integrity sha512-oJqcTrgPUF29oUP8AsUqbXGJNuPutsetaa9kTQAQce5Lx5dTYWV02ScBiT/k1BX/Z7pKeqedmvp39Wu4zR7N7g==

accepts@~1.3.7:
version "1.3.7"
Expand Down Expand Up @@ -59,9 +59,9 @@ bluebird@3.5.1:
integrity sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==

bn.js@^4.0.0:
version "4.11.9"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==
version "4.12.0"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==

body-parser@1.19.0:
version "1.19.0"
Expand Down Expand Up @@ -90,13 +90,13 @@ bytes@3.1.0:
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==

connect-mongo@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/connect-mongo/-/connect-mongo-4.1.0.tgz#dcf916398b7e35ad970e4a8cedeb242ab9d8e5d1"
integrity sha512-53b810jIf1l1yrLb/Au6XIJqDPVJrZ2SRMUZDgnECzaQLmDFRplHhF7n6vkPX5myUcz7Kjj59rxxsmWIuEwgjQ==
version "4.3.1"
resolved "https://registry.yarnpkg.com/connect-mongo/-/connect-mongo-4.3.1.tgz#9974cf13dda1a515f06fe97c7c0c9f161882aea9"
integrity sha512-R8X9vQ3ahHLd9ZYzjKbtfnGdW/ReY6EmjJv1IOKaT3v9ZJQdV1cE6peDBoNW4Pd2XmNqOVCywvy2ov2a5/Cnsg==
dependencies:
debug "^4.3.1"
kruptein "^2.2.3"
mongodb "^3.6.3"
kruptein "^3.0.0"
mongodb "3.6.3"

content-disposition@0.5.3:
version "0.5.3"
Expand Down Expand Up @@ -313,10 +313,10 @@ kareem@2.3.2:
resolved "https://registry.yarnpkg.com/kareem/-/kareem-2.3.2.tgz#78c4508894985b8d38a0dc15e1a8e11078f2ca93"
integrity sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ==

kruptein@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/kruptein/-/kruptein-2.2.3.tgz#e09a3942b8072ac71728d10fe089293e0b5e7d42"
integrity sha512-BTwprBPTzkFT9oTugxKd3WnWrX630MqUDsnmBuoa98eQs12oD4n4TeI0GbpdGcYn/73Xueg2rfnw+oK4dovnJg==
kruptein@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/kruptein/-/kruptein-3.0.0.tgz#9a7960248c9758f1e75522d2b87b8388bd40874f"
integrity sha512-Fh5sIb+3XI9L12GsgeBQqXVRPLB1HVViKSUkqPPOcqTEX4NwoF8Z3pEfMSl3Psd1j+QlloV8Uxxwp4gk3aFBGA==
dependencies:
asn1.js "^5.4.1"

Expand Down Expand Up @@ -375,19 +375,6 @@ mongodb@3.6.3:
optionalDependencies:
saslprep "^1.0.0"

mongodb@^3.6.3:
version "3.6.4"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.6.4.tgz#ca59fd65b06831308262372ef9df6b78f9da97be"
integrity sha512-Y+Ki9iXE9jI+n9bVtbTOOdK0B95d6wVGSucwtBkvQ+HIvVdTCfpVRp01FDC24uhC/Q2WXQ8Lpq3/zwtB5Op9Qw==
dependencies:
bl "^2.2.1"
bson "^1.1.4"
denque "^1.4.1"
require_optional "^1.0.1"
safe-buffer "^5.1.2"
optionalDependencies:
saslprep "^1.0.0"

mongoose-legacy-pluralize@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz#3ba9f91fa507b5186d399fb40854bff18fb563e4"
Expand Down Expand Up @@ -646,6 +633,11 @@ type-is@~1.6.17, type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

typescript@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==

uid-safe@~2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/uid-safe/-/uid-safe-2.1.5.tgz#2b3d5c7240e8fc2e58f8aa269e5ee49c0857bd3a"
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "connect-mongo",
"version": "4.3.1",
"version": "4.4.0",
"description": "MongoDB session store for Express and Connect",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/module/index.js",
"keywords": [
"connect",
"mongo",
Expand All @@ -29,7 +28,6 @@
"prebuild": "rm -rf build",
"build": "run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint --cache src --ext .ts --fix",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import MongoStore from './lib/MongoStore'
export default MongoStore
export = MongoStore
11 changes: 0 additions & 11 deletions tsconfig.module.json

This file was deleted.

0 comments on commit 93be37d

Please sign in to comment.