Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade mongodb to v6.0.0 #569

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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