2
2
3
3
const Buffer = require ( 'buffer' ) . Buffer ;
4
4
let randomBytes = require ( './parser/utils' ) . randomBytes ;
5
+ const deprecate = require ( 'util' ) . deprecate ;
5
6
6
7
// constants
7
8
const PROCESS_UNIQUE = randomBytes ( 5 ) ;
@@ -61,7 +62,7 @@ class ObjectId {
61
62
// The most common usecase (blank id, new objectId instance)
62
63
if ( id == null || typeof id === 'number' ) {
63
64
// Generate a new id
64
- this . id = this . generate ( id ) ;
65
+ this . id = ObjectId . generate ( id ) ;
65
66
// If we are caching the hex string
66
67
if ( ObjectId . cacheHexString ) this . __id = this . toString ( 'hex' ) ;
67
68
// Return the object
@@ -131,24 +132,6 @@ class ObjectId {
131
132
return hexString ;
132
133
}
133
134
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
-
152
135
/**
153
136
* Update the ObjectId index used in generating new ObjectId's on the driver
154
137
*
@@ -157,14 +140,7 @@ class ObjectId {
157
140
* @ignore
158
141
*/
159
142
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 ) ;
168
144
}
169
145
170
146
/**
@@ -179,7 +155,7 @@ class ObjectId {
179
155
time = ~ ~ ( Date . now ( ) / 1000 ) ;
180
156
}
181
157
182
- const inc = this . get_inc ( ) ;
158
+ const inc = ObjectId . getInc ( ) ;
183
159
const buffer = Buffer . alloc ( 12 ) ;
184
160
185
161
// 4-byte timestamp
@@ -203,13 +179,6 @@ class ObjectId {
203
179
return buffer ;
204
180
}
205
181
206
- /**
207
- * @deprecated Please use the static form instead
208
- */
209
- generate ( time ) {
210
- return ObjectId . generate ( time ) ;
211
- }
212
-
213
182
/**
214
183
* Converts the id into a 24 byte hex string for printing
215
184
*
@@ -390,6 +359,27 @@ class ObjectId {
390
359
}
391
360
}
392
361
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
+
393
383
/**
394
384
* @ignore
395
385
*/
0 commit comments