Skip to content

Commit 5e14405

Browse files
committed
refactor(object-id): provide static forms for OID generation
This appears to have been an oversight during the 4.x refactoring. These methods should be statics, not called on instances of an ObjectId class. Moved them over to statics, provided a non-BC breaking instance method, and documented them as deprecated.
1 parent 6da78e3 commit 5e14405

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/objectid.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class ObjectId {
138138
* @return {number} returns next index value.
139139
* @ignore
140140
*/
141+
static get_inc() {
142+
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
143+
}
144+
145+
/**
146+
* @deprecated Please use the static form instead
147+
*/
141148
get_inc() {
142149
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
143150
}
@@ -149,6 +156,13 @@ class ObjectId {
149156
* @return {number} returns next index value.
150157
* @ignore
151158
*/
159+
static getInc() {
160+
return ObjectId.get_inc();
161+
}
162+
163+
/**
164+
* @deprecated Please use the static form instead
165+
*/
152166
getInc() {
153167
return this.get_inc();
154168
}
@@ -160,7 +174,7 @@ class ObjectId {
160174
* @param {number} [time] optional parameter allowing to pass in a second based timestamp.
161175
* @return {Buffer} return the 12 byte id buffer string.
162176
*/
163-
generate(time) {
177+
static generate(time) {
164178
if ('number' !== typeof time) {
165179
time = ~~(Date.now() / 1000);
166180
}
@@ -189,6 +203,13 @@ class ObjectId {
189203
return buffer;
190204
}
191205

206+
/**
207+
* @deprecated Please use the static form instead
208+
*/
209+
generate(time) {
210+
return ObjectId.generate(time);
211+
}
212+
192213
/**
193214
* Converts the id into a 24 byte hex string for printing
194215
*

0 commit comments

Comments
 (0)