Skip to content

Commit 090ecc9

Browse files
committed
refactor(object-id): properly deprecate deprecated methods
1 parent e6211b4 commit 090ecc9

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

lib/objectid.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Buffer = require('buffer').Buffer;
44
let randomBytes = require('./parser/utils').randomBytes;
5+
const deprecate = require('util').deprecate;
56

67
// constants
78
const PROCESS_UNIQUE = randomBytes(5);
@@ -61,7 +62,7 @@ class ObjectId {
6162
// The most common usecase (blank id, new objectId instance)
6263
if (id == null || typeof id === 'number') {
6364
// Generate a new id
64-
this.id = this.generate(id);
65+
this.id = ObjectId.generate(id);
6566
// If we are caching the hex string
6667
if (ObjectId.cacheHexString) this.__id = this.toString('hex');
6768
// Return the object
@@ -131,24 +132,6 @@ class ObjectId {
131132
return hexString;
132133
}
133134

134-
/**
135-
* Update the ObjectId index used in generating new ObjectId's on the driver
136-
*
137-
* @method
138-
* @return {number} returns next index value.
139-
* @ignore
140-
*/
141-
static get_inc() {
142-
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
143-
}
144-
145-
/**
146-
* @deprecated Please use the static form instead
147-
*/
148-
get_inc() {
149-
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
150-
}
151-
152135
/**
153136
* Update the ObjectId index used in generating new ObjectId's on the driver
154137
*
@@ -157,14 +140,7 @@ class ObjectId {
157140
* @ignore
158141
*/
159142
static getInc() {
160-
return ObjectId.get_inc();
161-
}
162-
163-
/**
164-
* @deprecated Please use the static form instead
165-
*/
166-
getInc() {
167-
return this.get_inc();
143+
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
168144
}
169145

170146
/**
@@ -179,7 +155,7 @@ class ObjectId {
179155
time = ~~(Date.now() / 1000);
180156
}
181157

182-
const inc = this.get_inc();
158+
const inc = ObjectId.getInc();
183159
const buffer = Buffer.alloc(12);
184160

185161
// 4-byte timestamp
@@ -203,13 +179,6 @@ class ObjectId {
203179
return buffer;
204180
}
205181

206-
/**
207-
* @deprecated Please use the static form instead
208-
*/
209-
generate(time) {
210-
return ObjectId.generate(time);
211-
}
212-
213182
/**
214183
* Converts the id into a 24 byte hex string for printing
215184
*
@@ -390,6 +359,27 @@ class ObjectId {
390359
}
391360
}
392361

362+
// Deprecated methods
363+
ObjectId.get_inc = deprecate(
364+
() => ObjectId.getInc(),
365+
'Please use the static `ObjectId.getInc()` instead'
366+
);
367+
368+
ObjectId.prototype.get_inc = deprecate(
369+
() => ObjectId.getInc(),
370+
'Please use the static `ObjectId.getInc()` instead'
371+
);
372+
373+
ObjectId.prototype.getInc = deprecate(
374+
() => ObjectId.getInc(),
375+
'Please use the static `ObjectId.getInc()` instead'
376+
);
377+
378+
ObjectId.prototype.generate = deprecate(
379+
time => ObjectId.generate(time),
380+
'Please use the static `ObjectId.generate(time)` instead'
381+
);
382+
393383
/**
394384
* @ignore
395385
*/

0 commit comments

Comments
 (0)