Skip to content

feat(NODE-4522)!: remove callback support #3499

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

Merged
merged 37 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
17e87cf
test(NODE-4919): import mongodb-legacy in tests
nbbeeken Jan 4, 2023
82ac2b9
move test file, update coverage
nbbeeken Jan 19, 2023
4ac5a2f
test(NODE-4919): import mongodb-legacy in tests
nbbeeken Jan 4, 2023
d71a302
feat: remove callbacks from admin.ts
nbbeeken Dec 20, 2022
b1d5971
feat: remove callbacks from bulk/common.ts
nbbeeken Dec 20, 2022
af01cc7
feat: remove callbacks from change_stream.ts
nbbeeken Dec 20, 2022
28d2093
feat: remove callbacks from collection.ts
nbbeeken Dec 20, 2022
16ee978
feat: remove callbacks from cursors
nbbeeken Dec 20, 2022
5623462
feat: remove callbacks from db.ts
nbbeeken Dec 20, 2022
53ad68e
feat: remove callbacks from mongo_client.ts
nbbeeken Dec 20, 2022
51b0649
feat: remove callbacks from sessions.ts
nbbeeken Dec 20, 2022
bfaf3c9
feat: remove callbacks from gridfs
nbbeeken Dec 20, 2022
217101d
async keyword withTransaction and agg.explain
nbbeeken Jan 19, 2023
ffcd2d8
fle: bump to promise first fle commit
nbbeeken Jan 20, 2023
5f43565
fix: withSession
nbbeeken Jan 20, 2023
c3f2769
rm test file
nbbeeken Jan 20, 2023
4d67771
fix: lint
nbbeeken Jan 20, 2023
7a015e5
fix and skip tests
nbbeeken Jan 20, 2023
84f4f9a
jira ticket
nbbeeken Jan 20, 2023
7c06196
fix: await things
nbbeeken Jan 20, 2023
c1d5738
flip messages to check
nbbeeken Jan 20, 2023
266ec54
use fle alpha
nbbeeken Jan 20, 2023
2a1ee77
round one: fight
nbbeeken Jan 20, 2023
c12c401
comments
nbbeeken Jan 21, 2023
fb12143
consistent default arguments
nbbeeken Jan 21, 2023
e0b9538
fix tests, migration
nbbeeken Jan 21, 2023
43a0dbb
strangely close returns undefined
nbbeeken Jan 21, 2023
1ee4f9a
fix test
nbbeeken Jan 21, 2023
66a8942
Merge branch 'main' into NODE-4522-rm-callbacks
nbbeeken Jan 21, 2023
a11d175
argument defaulting fix
nbbeeken Jan 21, 2023
cad2804
fixup test
nbbeeken Jan 21, 2023
5b7dc71
fix async function strangeness
nbbeeken Jan 22, 2023
b489aca
handle close error
nbbeeken Jan 23, 2023
c0b36a9
migration suggestions
nbbeeken Jan 23, 2023
b91886c
rm todos
nbbeeken Jan 23, 2023
b0fda7d
Merge branch 'main' into NODE-4522-rm-callbacks
nbbeeken Jan 23, 2023
5c54370
Merge branch 'main' into NODE-4522-rm-callbacks
nbbeeken Jan 23, 2023
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
Prev Previous commit
Next Next commit
comments
  • Loading branch information
nbbeeken committed Jan 21, 2023
commit c12c40147c1a0da819e008a2ebf1835a00a3d809
10 changes: 5 additions & 5 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,21 @@ export class Db {
* Add a user to the database
*
* @param username - The username for the new user
* @param password - An optional password for the new user
* @param passwordOrOptions - An optional password for the new user, or the options for the command
* @param options - Optional settings for the command
*/
async addUser(
username: string,
password?: string | AddUserOptions,
passwordOrOptions?: string | AddUserOptions,
options?: AddUserOptions
): Promise<Document> {
options =
options != null && typeof options === 'object'
? options
: password != null && typeof password === 'object'
? password
: passwordOrOptions != null && typeof passwordOrOptions === 'object'
? passwordOrOptions
: undefined;
password = typeof password === 'string' ? password : undefined;
const password = typeof passwordOrOptions === 'string' ? passwordOrOptions : undefined;
return executeOperation(
this.s.client,
new AddUserOperation(this, username, password, resolveOptions(this, options))
Expand Down
53 changes: 19 additions & 34 deletions test/integration/crud/find_cursor_methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,50 +204,35 @@ describe('Find Cursor', function () {
});
});

// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy
context.skip('#clone', function () {
it('should clone a find cursor', function (done) {
context('#clone', function () {
it('should clone a find cursor', async function () {
// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy, callbacks do not work on cloned cursor
const coll = client.db().collection('abstract_cursor');
const cursor = coll.find({});
this.defer(() => cursor.close());

cursor.toArray((err, docs) => {
expect(err).to.not.exist;
expect(docs).to.have.length(6);
expect(cursor).property('closed').to.be.true;

const clonedCursor = cursor.clone();
this.defer(() => clonedCursor.close());
const docsFromOriginal = await cursor.toArray();
expect(docsFromOriginal).to.have.length(6);
expect(cursor).property('closed').to.be.true;

clonedCursor.toArray((err, docs) => {
expect(err).to.not.exist;
expect(docs).to.have.length(6);
expect(clonedCursor).property('closed').to.be.true;
done();
});
});
const clonedCursor = cursor.clone();
const docsFromCloned = await clonedCursor.toArray();
expect(docsFromCloned).to.have.length(6);
expect(cursor).property('closed').to.be.true;
});

it('should clone an aggregate cursor', function (done) {
it('should clone an aggregate cursor', async function () {
// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy, callbacks do not work on cloned cursor
const coll = client.db().collection('abstract_cursor');
const cursor = coll.aggregate([{ $match: {} }]);
this.defer(() => cursor.close());

cursor.toArray((err, docs) => {
expect(err).to.not.exist;
expect(docs).to.have.length(6);
expect(cursor).property('closed').to.be.true;

const clonedCursor = cursor.clone();
this.defer(() => clonedCursor.close());
const docsFromOriginal = await cursor.toArray();
expect(docsFromOriginal).to.have.length(6);
expect(cursor).property('closed').to.be.true;

clonedCursor.toArray((err, docs) => {
expect(err).to.not.exist;
expect(docs).to.have.length(6);
expect(clonedCursor).property('closed').to.be.true;
done();
});
});
const clonedCursor = cursor.clone();
const docsFromCloned = await clonedCursor.toArray();
expect(docsFromCloned).to.have.length(6);
expect(cursor).property('closed').to.be.true;
});
});

Expand Down
70 changes: 16 additions & 54 deletions test/integration/crud/misc_cursors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1671,66 +1671,28 @@ describe('Cursor', function () {
}
});

// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy
it.skip('removes session wheen cloning a find cursor', function (done) {
const configuration = this.configuration;
client.connect((err, client) => {
expect(err).to.not.exist;

const db = client.db(configuration.db);
db.createCollection('clone_find_cursor_session', (err, collection) => {
expect(err).to.not.exist;
it('removes session when cloning an aggregation cursor', async function () {
// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy, callbacks do not work on cloned cursor
const collection = await client.db().collection();

collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;
const cursor = collection.find({});
const clonedCursor = cursor.clone();

const cursor = collection.find();
const clonedCursor = cursor.clone();
cursor.toArray(err => {
expect(err).to.not.exist;
clonedCursor.toArray(err => {
expect(err).to.not.exist;
client.close();
done();
});
});
});
});
});
expect(cursor).to.have.property('session');
expect(clonedCursor).to.have.property('session');
expect(cursor.session).to.not.equal(clonedCursor.session);
});

// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy
it.skip('removes session wheen cloning an aggregation cursor', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded'] }
},

test: function (done) {
const configuration = this.configuration;
client.connect((err, client) => {
expect(err).to.not.exist;

const db = client.db(configuration.db);
db.createCollection('clone_aggregation_cursor_session', (err, collection) => {
expect(err).to.not.exist;
it('removes session when cloning an aggregation cursor', async function () {
// TODO(NODE-4988): Need to fix cursor.clone in mongodb-legacy, callbacks do not work on cloned cursor
const collection = await client.db().collection();

collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;
const cursor = collection.aggregate([{ $match: {} }]);
const clonedCursor = cursor.clone();

const cursor = collection.aggregate([{ $match: { a: 1 } }]);
const clonedCursor = cursor.clone();
cursor.toArray(err => {
expect(err).to.not.exist;
clonedCursor.toArray(err => {
expect(err).to.not.exist;
client.close();
done();
});
});
});
});
});
}
expect(cursor).to.have.property('session');
expect(clonedCursor).to.have.property('session');
expect(cursor.session).to.not.equal(clonedCursor.session);
});

it('destroying a stream stops it', {
Expand Down