-
Notifications
You must be signed in to change notification settings - Fork 2
feat(NODE-4541): implement legacy callback wrapper library #1
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0d0558b
feat(NODE-4520): add wrappers async driver APIs
nbbeeken 27aef12
fix: comments
nbbeeken 1c319d3
chore: add static connect
nbbeeken 90180d4
test: check for static override connect method
nbbeeken 69ffa9e
add assertion about extraneous methods
nbbeeken d14c4d1
fix: variable name
nbbeeken f814a0b
fix up comments and test
nbbeeken fbbb0b4
fix: remove toLegacy on mongoclient, breaks subclass
nbbeeken 6ff3ff3
rm: unnecessary .then
nbbeeken 3b42c3b
fix: findOneAndReplace
nbbeeken 78a8669
rm then
nbbeeken 4c3cb49
fix: findOneAndUpdate
nbbeeken 7233dbe
add test location info
nbbeeken 8cc9a6b
fix: addUser arg handling
nbbeeken c9fcecb
ensure connect rejects if construction fails
nbbeeken 3437d0f
update test location comment
nbbeeken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
!mongodb-legacy.d.ts | ||
.vscode/ | ||
*.tgz | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,79 @@ | ||
'use strict'; | ||
|
||
throw new Error('Work In Progress - Not intended for use at this time'); | ||
const mongodb = require('mongodb'); | ||
|
||
const { makeLegacyMongoClient } = require('./legacy_wrappers/mongo_client'); | ||
const { makeLegacyDb } = require('./legacy_wrappers/db'); | ||
const { makeLegacyCollection } = require('./legacy_wrappers/collection'); | ||
const { makeLegacyAdmin } = require('./legacy_wrappers/admin'); | ||
const { | ||
makeLegacyAggregationCursor, | ||
makeLegacyFindCursor, | ||
makeLegacyListCollectionsCursor, | ||
makeLegacyListIndexesCursor | ||
} = require('./legacy_wrappers/cursors'); | ||
const { | ||
makeLegacyGridFSBucket, | ||
makeLegacyGridFSBucketWriteStream | ||
} = require('./legacy_wrappers/gridfs'); | ||
const { makeLegacyChangeStream } = require('./legacy_wrappers/change_stream'); | ||
const { makeLegacyClientSession } = require('./legacy_wrappers/session'); | ||
const { | ||
makeLegacyUnorderedBulkOperation, | ||
makeLegacyOrderedBulkOperation | ||
} = require('./legacy_wrappers/bulk'); | ||
|
||
/** @type {import('..')} */ | ||
module.exports = Object.create(null); | ||
Object.defineProperty(module.exports, '__esModule', { value: true }); | ||
|
||
const classesWithAsyncAPIs = new Map([ | ||
['Admin', makeLegacyAdmin], | ||
['FindCursor', makeLegacyFindCursor], | ||
['ListCollectionsCursor', makeLegacyListCollectionsCursor], | ||
['ListIndexesCursor', makeLegacyListIndexesCursor], | ||
['AggregationCursor', makeLegacyAggregationCursor], | ||
['ChangeStream', makeLegacyChangeStream], | ||
['Collection', makeLegacyCollection], | ||
['Db', makeLegacyDb], | ||
['GridFSBucket', makeLegacyGridFSBucket], | ||
['ClientSession', makeLegacyClientSession], | ||
['MongoClient', makeLegacyMongoClient], | ||
|
||
// Need to be exported top-level still | ||
['ClientSession', makeLegacyClientSession], | ||
['GridFSBucketWriteStream', makeLegacyGridFSBucketWriteStream], | ||
['OrderedBulkOperation', makeLegacyOrderedBulkOperation], | ||
['UnorderedBulkOperation', makeLegacyUnorderedBulkOperation] | ||
]); | ||
|
||
const TODO_SPECIAL_IMPORTS = new Map([ | ||
['ClientSession', '/lib/sessions'], | ||
['GridFSBucketWriteStream', '/lib/gridfs/upload'], | ||
['OrderedBulkOperation', '/lib/bulk/ordered'], | ||
['UnorderedBulkOperation', '/lib/bulk/unordered'] | ||
]); | ||
|
||
for (const [missingTopLevelClassName, location] of TODO_SPECIAL_IMPORTS) { | ||
mongodb[missingTopLevelClassName] = require(`mongodb${location}`)[missingTopLevelClassName]; | ||
} | ||
|
||
for (const [mongodbExportName, mongodbExportValue] of Object.entries(mongodb)) { | ||
let makeLegacyClass = classesWithAsyncAPIs.get(mongodbExportName); | ||
if (makeLegacyClass != null) { | ||
const patchedClass = makeLegacyClass(mongodbExportValue); | ||
Object.defineProperty(module.exports, mongodbExportName, { | ||
enumerable: true, | ||
get: function () { | ||
return patchedClass; | ||
} | ||
}); | ||
} else { | ||
Object.defineProperty(module.exports, mongodbExportName, { | ||
enumerable: true, | ||
get: function () { | ||
return mongodbExportValue; | ||
} | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
'use strict'; | ||
|
||
const { toLegacy, maybeCallback } = require('../utils'); | ||
|
||
module.exports = Object.create(null); | ||
Object.defineProperty(module.exports, '__esModule', { value: true }); | ||
|
||
module.exports.makeLegacyAdmin = function (baseClass) { | ||
class LegacyAdmin extends baseClass { | ||
addUser(username, password, options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: typeof password === 'function' | ||
? password | ||
: undefined; | ||
options = | ||
options != null && typeof options === 'object' | ||
? options | ||
: password != null && typeof password === 'object' | ||
? password | ||
: undefined; | ||
return maybeCallback(super.addUser(username, password, options), callback); | ||
} | ||
|
||
buildInfo(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.buildInfo(options), callback); | ||
} | ||
|
||
command(command, options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.command(command, options), callback); | ||
} | ||
|
||
listDatabases(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.listDatabases(options), callback); | ||
} | ||
|
||
ping(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.ping(options), callback); | ||
} | ||
|
||
removeUser(username, options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.removeUser(username, options), callback); | ||
} | ||
|
||
replSetGetStatus(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.replSetGetStatus(options), callback); | ||
} | ||
|
||
serverInfo(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.serverInfo(options), callback); | ||
} | ||
|
||
serverStatus(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.serverStatus(options), callback); | ||
} | ||
|
||
validateCollection(name, options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.validateCollection(name, options), callback); | ||
} | ||
} | ||
|
||
Object.defineProperty(baseClass.prototype, toLegacy, { | ||
enumerable: false, | ||
value: function () { | ||
return Object.setPrototypeOf(this, LegacyAdmin.prototype); | ||
} | ||
}); | ||
|
||
return LegacyAdmin; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const { maybeCallback } = require('../utils'); | ||
|
||
module.exports = Object.create(null); | ||
Object.defineProperty(module.exports, '__esModule', { value: true }); | ||
|
||
module.exports.makeLegacyOrderedBulkOperation = function (baseClass) { | ||
return class LegacyOrderedBulkOperation extends baseClass { | ||
execute(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.execute(options), callback); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.makeLegacyUnorderedBulkOperation = function (baseClass) { | ||
return class LegacyUnorderedBulkOperation extends baseClass { | ||
execute(options, callback) { | ||
callback = | ||
typeof callback === 'function' | ||
? callback | ||
: typeof options === 'function' | ||
? options | ||
: undefined; | ||
options = typeof options !== 'function' ? options : undefined; | ||
return maybeCallback(super.execute(options), callback); | ||
} | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const { toLegacy, maybeCallback } = require('../utils'); | ||
|
||
module.exports = Object.create(null); | ||
Object.defineProperty(module.exports, '__esModule', { value: true }); | ||
|
||
module.exports.makeLegacyChangeStream = function (baseClass) { | ||
class LegacyChangeStream extends baseClass { | ||
close(callback) { | ||
return maybeCallback(super.close(), callback); | ||
} | ||
hasNext(callback) { | ||
return maybeCallback(super.hasNext(), callback); | ||
} | ||
next(callback) { | ||
return maybeCallback(super.next(), callback); | ||
} | ||
tryNext(callback) { | ||
return maybeCallback(super.tryNext(), callback); | ||
} | ||
} | ||
|
||
Object.defineProperty(baseClass.prototype, toLegacy, { | ||
enumerable: false, | ||
value: function () { | ||
return Object.setPrototypeOf(this, LegacyChangeStream.prototype); | ||
} | ||
}); | ||
|
||
return LegacyChangeStream; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.