Skip to content

Commit 3e37498

Browse files
committed
feat: add [email protected] support
BREAKING CHANGE: it is hard to support both versions (3.x and 4.x) of native driver on the same branch because 4.x has native types definitions and they diverge from the ones provided by @types/mongodb. This means that this version might still be compatible with previous versions of mongodb native driver (3.6.x and 3.7.x), but we aren't testing them due to typescript mismatch. Please open an issue and we will try to support your use case.
1 parent e1faffa commit 3e37498

File tree

5 files changed

+122
-70
lines changed

5 files changed

+122
-70
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ jobs:
3131
matrix:
3232
node-version: [12.x, 14.x, 16.x]
3333
mongodb-version: ['4.0', '4.2', '4.4']
34-
# these should match the minimum peerDependencies definitions
35-
mongodb-types: ['3.6.20', '^3.6.20']
36-
mongodb-lib: ['3.6.7', '^3.6.7']
34+
mongodb-lib: ['4.3.1', '^4.3.1']
3735

3836
env:
3937
NODE: ${{ matrix.node-version }}
@@ -56,7 +54,6 @@ jobs:
5654
- run: yarn install --frozen-lockfile
5755

5856
# peerDeps installs
59-
- run: yarn add -D @types/mongodb@${{matrix.mongodb-types}}
6057
- run: yarn add -D mongodb@${{matrix.mongodb-lib}}
6158

6259
- run: yarn test --coverage

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"test": "jest"
2323
},
2424
"peerDependencies": {
25-
"@types/mongodb": "^3.6.20",
26-
"mongodb": "^3.6.7"
25+
"mongodb": "^4.3.1"
2726
},
2827
"peerDependenciesMeta": {
2928
"@types/mongodb": {
@@ -40,7 +39,7 @@
4039
"@rollup/plugin-commonjs": "^21.0.1",
4140
"@rollup/plugin-node-resolve": "^13.1.3",
4241
"@types/jest": "^27.4.0",
43-
"@types/mongodb": "^3.6.20",
42+
"@types/mongodb": "^4.0.7",
4443
"@typescript-eslint/eslint-plugin": "^5.9.1",
4544
"@typescript-eslint/parser": "^5.9.1",
4645
"builtin-modules": "^3.2.0",
@@ -51,7 +50,7 @@
5150
"husky": "^7.0.4",
5251
"jest": "^27.4.7",
5352
"lint-staged": "^12.1.7",
54-
"mongodb": "^3.6.7",
53+
"mongodb": "^4.3.1",
5554
"prettier": "^2.5.1",
5655
"rollup": "^2.64.0",
5756
"standard-version": "^9.3.2",

src/mongodb-queue.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
*/
88

99
import crypto from 'crypto';
10-
import type { Db, FilterQuery, ObjectId, UpdateQuery } from 'mongodb';
10+
import type { Db, Filter, UpdateFilter } from 'mongodb';
1111

1212
// some helper functions
1313
function id() {
1414
return crypto.randomBytes(16).toString('hex');
1515
}
1616

1717
type MessageSchema = {
18-
_id: ObjectId;
1918
createdAt: Date;
2019
updatedAt?: Date;
2120
visible: Date;
@@ -104,7 +103,7 @@ class MongoDbQueueImpl<T = unknown> implements MongoDbQueue {
104103
return result.insertedId.toHexString();
105104
}
106105

107-
let filter: FilterQuery<MessageSchema> = {
106+
let filter: Filter<MessageSchema> = {
108107
payload: { $eq: hashKey },
109108
};
110109

@@ -144,7 +143,7 @@ class MongoDbQueueImpl<T = unknown> implements MongoDbQueue {
144143
deleted: null,
145144
visible: { $lte: new Date(now) },
146145
};
147-
const update: UpdateQuery<MessageSchema> = {
146+
const update: UpdateFilter<MessageSchema> = {
148147
$inc: { tries: 1 },
149148
$set: {
150149
updatedAt: new Date(now),

src/specs/__helpers__/setup-mongo.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ class SetupMongo {
55
private _dbName: string;
66

77
get client() {
8-
if (!this._client.isConnected()) {
9-
throw new Error('Please wait for `connection()` on `beforeAll` hook');
10-
}
11-
128
return this._client;
139
}
1410

@@ -17,7 +13,7 @@ class SetupMongo {
1713
}
1814

1915
constructor(url: string, dbName: string) {
20-
this._client = new MongoClient(url, { useUnifiedTopology: true });
16+
this._client = new MongoClient(url);
2117
this._dbName = dbName;
2218
}
2319

0 commit comments

Comments
 (0)