Skip to content

Commit eae0e05

Browse files
authored
chore(NODE-3303): deprecate md5 hash and isConnected (#2960)
1 parent 77ab63e commit eae0e05

File tree

4 files changed

+89
-64
lines changed

4 files changed

+89
-64
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ connect.Int32 = core.BSON.Int32;
5050
connect.Long = core.BSON.Long;
5151
connect.MinKey = core.BSON.MinKey;
5252
connect.MaxKey = core.BSON.MaxKey;
53+
/** @deprecated Please use `ObjectId` */
5354
connect.ObjectID = core.BSON.ObjectID;
5455
connect.ObjectId = core.BSON.ObjectID;
5556
connect.Symbol = core.BSON.Symbol;

lib/gridfs-stream/index.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var shallowClone = require('../utils').shallowClone;
77
var toError = require('../utils').toError;
88
var util = require('util');
99
var executeLegacyOperation = require('../utils').executeLegacyOperation;
10+
const deprecateOptions = require('../utils').deprecateOptions;
1011

1112
var DEFAULT_GRIDFS_BUCKET_OPTIONS = {
1213
bucketName: 'fs',
@@ -79,21 +80,28 @@ util.inherits(GridFSBucket, Emitter);
7980
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
8081
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
8182
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
82-
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
83+
* @param {boolean} [options.disableMD5=false] **Deprecated** If true, disables adding an md5 field to file data
8384
* @return {GridFSBucketWriteStream}
8485
*/
8586

86-
GridFSBucket.prototype.openUploadStream = function(filename, options) {
87-
if (options) {
88-
options = shallowClone(options);
89-
} else {
90-
options = {};
91-
}
92-
if (!options.chunkSizeBytes) {
93-
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
87+
GridFSBucket.prototype.openUploadStream = deprecateOptions(
88+
{
89+
name: 'GridFSBucket.openUploadStream',
90+
deprecatedOptions: ['disableMD5'],
91+
optionsIndex: 1
92+
},
93+
function(filename, options) {
94+
if (options) {
95+
options = shallowClone(options);
96+
} else {
97+
options = {};
98+
}
99+
if (!options.chunkSizeBytes) {
100+
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
101+
}
102+
return new GridFSBucketWriteStream(this, filename, options);
94103
}
95-
return new GridFSBucketWriteStream(this, filename, options);
96-
};
104+
);
97105

98106
/**
99107
* Returns a writable stream (GridFSBucketWriteStream) for writing
@@ -107,25 +115,32 @@ GridFSBucket.prototype.openUploadStream = function(filename, options) {
107115
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
108116
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
109117
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
110-
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
118+
* @param {boolean} [options.disableMD5=false] **Deprecated** If true, disables adding an md5 field to file data
111119
* @return {GridFSBucketWriteStream}
112120
*/
113121

114-
GridFSBucket.prototype.openUploadStreamWithId = function(id, filename, options) {
115-
if (options) {
116-
options = shallowClone(options);
117-
} else {
118-
options = {};
119-
}
122+
GridFSBucket.prototype.openUploadStreamWithId = deprecateOptions(
123+
{
124+
name: 'GridFSBucket.openUploadStreamWithId',
125+
deprecatedOptions: ['disableMD5'],
126+
optionsIndex: 2
127+
},
128+
function(id, filename, options) {
129+
if (options) {
130+
options = shallowClone(options);
131+
} else {
132+
options = {};
133+
}
120134

121-
if (!options.chunkSizeBytes) {
122-
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
123-
}
135+
if (!options.chunkSizeBytes) {
136+
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
137+
}
124138

125-
options.id = id;
139+
options.id = id;
126140

127-
return new GridFSBucketWriteStream(this, filename, options);
128-
};
141+
return new GridFSBucketWriteStream(this, filename, options);
142+
}
143+
);
129144

130145
/**
131146
* Returns a readable stream (GridFSBucketReadStream) for streaming file

lib/gridfs-stream/upload.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ var crypto = require('crypto');
55
var stream = require('stream');
66
var util = require('util');
77
var Buffer = require('safe-buffer').Buffer;
8+
const deprecateOptions = require('../utils').deprecateOptions;
89

9-
var ERROR_NAMESPACE_NOT_FOUND = 26;
10-
11-
module.exports = GridFSBucketWriteStream;
10+
const ERROR_NAMESPACE_NOT_FOUND = 26;
1211

1312
/**
1413
* A writable stream that enables you to write buffers to GridFS.
@@ -31,42 +30,49 @@ module.exports = GridFSBucketWriteStream;
3130
* @fires GridFSBucketWriteStream#finish
3231
*/
3332

34-
function GridFSBucketWriteStream(bucket, filename, options) {
35-
options = options || {};
36-
stream.Writable.call(this, options);
37-
this.bucket = bucket;
38-
this.chunks = bucket.s._chunksCollection;
39-
this.filename = filename;
40-
this.files = bucket.s._filesCollection;
41-
this.options = options;
42-
// Signals the write is all done
43-
this.done = false;
44-
45-
this.id = options.id ? options.id : core.BSON.ObjectId();
46-
this.chunkSizeBytes = this.options.chunkSizeBytes;
47-
this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
48-
this.length = 0;
49-
this.md5 = !options.disableMD5 && crypto.createHash('md5');
50-
this.n = 0;
51-
this.pos = 0;
52-
this.state = {
53-
streamEnd: false,
54-
outstandingRequests: 0,
55-
errored: false,
56-
aborted: false,
57-
promiseLibrary: this.bucket.s.promiseLibrary
58-
};
59-
60-
if (!this.bucket.s.calledOpenUploadStream) {
61-
this.bucket.s.calledOpenUploadStream = true;
62-
63-
var _this = this;
64-
checkIndexes(this, function() {
65-
_this.bucket.s.checkedIndexes = true;
66-
_this.bucket.emit('index');
67-
});
33+
const GridFSBucketWriteStream = deprecateOptions(
34+
{
35+
name: 'GridFSBucketWriteStream',
36+
deprecatedOptions: ['disableMD5'],
37+
optionsIndex: 2
38+
},
39+
function(bucket, filename, options) {
40+
options = options || {};
41+
stream.Writable.call(this, options);
42+
this.bucket = bucket;
43+
this.chunks = bucket.s._chunksCollection;
44+
this.filename = filename;
45+
this.files = bucket.s._filesCollection;
46+
this.options = options;
47+
// Signals the write is all done
48+
this.done = false;
49+
50+
this.id = options.id ? options.id : core.BSON.ObjectId();
51+
this.chunkSizeBytes = this.options.chunkSizeBytes;
52+
this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
53+
this.length = 0;
54+
this.md5 = !options.disableMD5 && crypto.createHash('md5');
55+
this.n = 0;
56+
this.pos = 0;
57+
this.state = {
58+
streamEnd: false,
59+
outstandingRequests: 0,
60+
errored: false,
61+
aborted: false,
62+
promiseLibrary: this.bucket.s.promiseLibrary
63+
};
64+
65+
if (!this.bucket.s.calledOpenUploadStream) {
66+
this.bucket.s.calledOpenUploadStream = true;
67+
68+
var _this = this;
69+
checkIndexes(this, function() {
70+
_this.bucket.s.checkedIndexes = true;
71+
_this.bucket.emit('index');
72+
});
73+
}
6874
}
69-
}
75+
);
7076

7177
util.inherits(GridFSBucketWriteStream, stream.Writable);
7278

@@ -539,3 +545,5 @@ function checkAborted(_this, callback) {
539545
}
540546
return false;
541547
}
548+
549+
module.exports = GridFSBucketWriteStream;

lib/mongo_client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,18 @@ MongoClient.prototype.db = function(dbName, options) {
388388
* Check if MongoClient is connected
389389
*
390390
* @method
391+
* @deprecated
391392
* @param {object} [options] Optional settings.
392393
* @param {boolean} [options.noListener=false] Do not make the db an event listener to the original connection.
393394
* @param {boolean} [options.returnNonCachedInstance=false] Control if you want to return a cached instance or have a new one created
394395
* @return {boolean}
395396
*/
396-
MongoClient.prototype.isConnected = function(options) {
397+
MongoClient.prototype.isConnected = deprecate(function(options) {
397398
options = options || {};
398399

399400
if (!this.topology) return false;
400401
return this.topology.isConnected(options);
401-
};
402+
}, 'isConnected is deprecated and will be removed in the next major version');
402403

403404
/**
404405
* Connect to MongoDB using a url as documented at

0 commit comments

Comments
 (0)