Skip to content

Commit

Permalink
feat: Upgrade mongodb to v6.0.0 (#569)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `mongodb` minimum version is now v6.*

BREAKING CHANGE: `node` minimum version is now v16.20.1
  • Loading branch information
avaly authored Sep 5, 2023
1 parent 9462ac6 commit a95bfb4
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 56 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"license": "MIT",
"engines": {
"node": ">=16.0.0"
"node": ">=16.20.1"
},
"type": "module",
"types": "./esm/index.d.ts",
Expand Down Expand Up @@ -77,7 +77,7 @@
"jsdoc-api": "8.0.0",
"jsdoc-parse": "6.2.0",
"lint-staged": "14.0.0",
"mongodb": "5.8.0",
"mongodb": "6.0.0",
"mongodb-memory-server": "8.15.1",
"mongoose": "6.3.5",
"pinst": "3.0.0",
Expand All @@ -88,7 +88,7 @@
"typescript": "5.2.2"
},
"peerDependencies": {
"mongodb": "^5.0.0"
"mongodb": "^6.0.0"
},
"commitlint": {
"extends": [
Expand Down
37 changes: 19 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 11 additions & 19 deletions src/__tests__/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,9 @@ describe('model', () => {
// @ts-expect-error Ignore mock function
findOne: jest.fn().mockResolvedValue(doc),
// @ts-expect-error Ignore mock function
findOneAndDelete: jest.fn().mockResolvedValue({
ok: 1,
value: doc,
}),
findOneAndDelete: jest.fn().mockResolvedValue(doc),
// @ts-expect-error Ignore mock function
findOneAndUpdate: jest.fn().mockResolvedValue({
ok: 1,
value: doc,
}),
findOneAndUpdate: jest.fn().mockResolvedValue(doc),
// @ts-expect-error Ignore mock function
insertMany: jest.fn().mockResolvedValue({
acknowledged: true,
Expand Down Expand Up @@ -1235,11 +1229,9 @@ describe('model', () => {
});

test('throws error on failure', async () => {
(collection.findOneAndDelete as jest.Mocked<Collection['findOneAndDelete']>)
// @ts-expect-error Ignore mock value
.mockResolvedValue({
ok: 0,
});
(
collection.findOneAndDelete as jest.Mocked<Collection['findOneAndDelete']>
).mockRejectedValueOnce(new Error('findOneAndDelete failed'));

await expect(simpleModel.findOneAndDelete({ foo: 'bar' })).rejects.toThrow(
'findOneAndDelete failed'
Expand Down Expand Up @@ -1288,9 +1280,9 @@ describe('model', () => {
});

test('throws error on failure', async () => {
(collection.findOneAndUpdate as jest.Mocked<Collection['findOneAndUpdate']>)
// @ts-expect-error Ignore mock value
.mockResolvedValue({ ok: 0 });
(
collection.findOneAndUpdate as jest.Mocked<Collection['findOneAndUpdate']>
).mockRejectedValueOnce(new Error('findOneAndUpdate failed'));

await expect(
simpleModel.findOneAndUpdate({ foo: 'bar' }, { $set: { bar: 123 } })
Expand Down Expand Up @@ -2515,9 +2507,9 @@ describe('model', () => {
});

test('throws error on failure', async () => {
(collection.findOneAndUpdate as jest.Mocked<Collection['findOneAndUpdate']>)
// @ts-expect-error Ignore mock function
.mockResolvedValue({ ok: false });
(
collection.findOneAndUpdate as jest.Mocked<Collection['findOneAndUpdate']>
).mockRejectedValueOnce(new Error('findOneAndUpdate failed'));

await expect(simpleModel.upsert({ foo: 'foo' }, { $set: { bar: 123 } })).rejects.toThrow(
'findOneAndUpdate failed'
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/mongodbTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('mongodb types', () => {
});

// all BSON types can be used as query values
expectType<PaprFilter<TestDocument>>({ binary: new Binary('', 2) });
expectType<PaprFilter<TestDocument>>({ binary: new Binary([], 2) });
expectType<PaprFilter<TestDocument>>({ bsonSymbol: new BSONSymbol('hi') });
expectType<PaprFilter<TestDocument>>({ code: new Code(() => true) });
expectType<PaprFilter<TestDocument>>({ double: new Double(123.45) });
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('mongodb types', () => {
});

// all BSON types can be used as update values
expectType<PaprUpdateFilter<TestDocument>>({ $set: { binary: new Binary('', 2) } });
expectType<PaprUpdateFilter<TestDocument>>({ $set: { binary: new Binary([], 2) } });
expectType<PaprUpdateFilter<TestDocument>>({
$set: { bsonSymbol: new BSONSymbol('hi') },
});
Expand Down
12 changes: 2 additions & 10 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,7 @@ export function build<TSchema extends BaseSchema, TOptions extends SchemaOptions
} as FindOneAndDeleteOptions
);

if (result.ok === 1) {
return result.value as ProjectionType<TSchema, TProjection>;
}

throw new Error('findOneAndDelete failed');
return result as ProjectionType<TSchema, TProjection>;
});

/**
Expand Down Expand Up @@ -848,11 +844,7 @@ export function build<TSchema extends BaseSchema, TOptions extends SchemaOptions
} as FindOneAndUpdateOptions
);

if (result.ok === 1) {
return result.value as ProjectionType<TSchema, TProjection>;
}

throw new Error('findOneAndUpdate failed');
return result as ProjectionType<TSchema, TProjection>;
});

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"type": "commonjs",
"dependencies": {
"papr": "file:../../build/package",
"mongodb": "5.1.0"
"mongodb": "6.0.0"
}
}
2 changes: 1 addition & 1 deletion tests/esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"type": "module",
"dependencies": {
"papr": "file:../../build/package",
"mongodb": "5.1.0"
"mongodb": "6.0.0"
}
}
2 changes: 1 addition & 1 deletion tests/ts-nodenext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"dependencies": {
"papr": "file:../../build/package",
"mongodb": "5.1.0",
"mongodb": "6.0.0",
"ts-expect": "1.3.0",
"typescript": "5.0.4"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"dependencies": {
"papr": "file:../../build/package",
"mongodb": "5.1.0",
"mongodb": "6.0.0",
"ts-expect": "1.3.0",
"typescript": "5.0.4"
}
Expand Down

0 comments on commit a95bfb4

Please sign in to comment.