From 738be5a0cf47fee540099dadc4fff08a02dbe55a Mon Sep 17 00:00:00 2001 From: Andras Date: Sat, 7 Feb 2015 14:36:06 -0500 Subject: [PATCH 01/22] doc: Readme edits --- Readme.md | 24 +++++++++++++++++++++--- package.json | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 04e20f8..5c83f1c 100644 --- a/Readme.md +++ b/Readme.md @@ -11,6 +11,23 @@ The ids are guaranteed unique on any one server, and can be configured to be unique across a cluster of up to 16 million (2^24) servers. Uniqueness is guaranteed by unique {server, process} id pairs. + +## Installation + + npm install mongoid-js + npm test mongoid-js + + +## Summary + + var mongoid = require('mongoid-js'); + var id = mondoid(); // => 543f376340e2816497000001 + + var MongoId = require('mongoid-js').MongoId; + var idFactory = new MongoId(/*systemId:*/ 0x123); + var id = idFactory.fetch(); // => 543f3789001230649f000001 + + ## Functions ### mongoid( ) @@ -41,7 +58,8 @@ globally unique ids (ie, globally for an installation). Decompose the id string into its parts -- unix timestamp, machine id, process id and sequence number. Unix timestamps are seconds since the -start of the epoch (1970-01-01 UTC) +start of the epoch (1970-01-01 GMT). Note that parse() returns seconds, +while getTimestamp() returns milliseconds. var parts = MongoId.parse("543f376340e2816497000013"); // => { timestamp: 1413429091, @@ -52,8 +70,8 @@ start of the epoch (1970-01-01 UTC) ### MongoId.getTimestamp( idString ) Return just the javascript timestamp part of the id. Javascript timestamps -are milliseconds since the start of the epoch (they are 1000 x more than the -unix timestamp.) +are milliseconds since the start of the epoch. Each mongoid embeds a seconds +precision unix timestamp; getTimestamp() returns that multiplied by 1000. MongoId.getTimestamp("543f376340e2816497000013"); // => 1413429091000 diff --git a/package.json b/package.json index 1142673..c2b120b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoid-js", - "version": "1.0.5", + "version": "1.0.6", "description": "very fast mongoid compatible unique ids", "license": "Apache-2.0", "main": "index.js", From 1e8703228b2ecb591f7688ea9939aabbe2b6b2c5 Mon Sep 17 00:00:00 2001 From: Andras Date: Sat, 7 Feb 2015 14:48:06 -0500 Subject: [PATCH 02/22] doc: more Readme edits --- Readme.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 5c83f1c..ffce0d5 100644 --- a/Readme.md +++ b/Readme.md @@ -37,11 +37,11 @@ MongoId singleton initialized with a random machine id. All subsequent calls to mongoid() in this process will fetch ids from this singleton. // ids with a randomly chosen system id (here 0x40e281) - var mongoid = require('mongoid-js'); + var mongoid = require('mongoid-js').mongoid; var id1 = mongoid(); // => 543f376340e2816497000001 var id2 = mongoid(); // => 543f376340e2816497000002 -### new MongoId( systemId ).fetch( ) +### MongoId( systemId ) unique id factory that embeds the given system id in each generated unique id. By a systematic assignment of system ids to servers, this approach can guarantee @@ -51,10 +51,29 @@ globally unique ids (ie, globally for an installation). var MongoId = require('mongoid-js').MongoId; var systemId = 4656; var idFactory = new MongoId(systemId); + +#### id.fetch( ) + var id1 = idFactory().fetch(); // => 543f3789001230649f000001 var id2 = idFactory().fetch(); // => 543f3789001230649f000002 -### MongoId.parse( idString ) +#### id.parse( ) + +same as MongoId.parse(id.toString()), see below + +#### id.getTimestamp( ) + +same as MongoId.getTimestam(id.toString()), see below + +#### id.toString( ) + +each MongoId object itself can have a distinct unique id, created on demand +when toString() is called. The object invokes itself as an id factory and +fetches for itself the next id in the sequence. The + +### Class Methods + +#### MongoId.parse( idString ) Decompose the id string into its parts -- unix timestamp, machine id, process id and sequence number. Unix timestamps are seconds since the @@ -67,7 +86,7 @@ while getTimestamp() returns milliseconds. // pid: 25751, // sequence: 19 } -### MongoId.getTimestamp( idString ) +#### MongoId.getTimestamp( idString ) Return just the javascript timestamp part of the id. Javascript timestamps are milliseconds since the start of the epoch. Each mongoid embeds a seconds From cdeb7ebfc0cd67a5cdbc1c16a55654389675b956 Mon Sep 17 00:00:00 2001 From: Andras Date: Sat, 7 Feb 2015 14:58:00 -0500 Subject: [PATCH 03/22] doc: Readme edits --- Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Readme.md b/Readme.md index ffce0d5..05c4b45 100644 --- a/Readme.md +++ b/Readme.md @@ -47,6 +47,8 @@ unique id factory that embeds the given system id in each generated unique id. By a systematic assignment of system ids to servers, this approach can guarantee globally unique ids (ie, globally for an installation). +The systemId must be an integer between 0 and 16777215 (0xFFFFFF), inclusive. + // ids with a unique system id var MongoId = require('mongoid-js').MongoId; var systemId = 4656; @@ -54,6 +56,12 @@ globally unique ids (ie, globally for an installation). #### id.fetch( ) +generate and return the next id in the sequence. Up to 16 million distinct +ids (16777216) can be fetched during the same wallclock second; trying to +fetch more throws an error. The second starts when the clock reads _*000_ +milliseconds, not when the first id is fetched. The second ends 1000 +milliseconds after the start, when the clock next reads _*000_ milliseconds. + var id1 = idFactory().fetch(); // => 543f3789001230649f000001 var id2 = idFactory().fetch(); // => 543f3789001230649f000002 From 425c5abaadbaa6104ff856be36f54ac500dfe63d Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 01:38:51 -0400 Subject: [PATCH 04/22] tighten 24-hexchar id test --- test/test-mongoid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-mongoid.js b/test/test-mongoid.js index 665236c..3dd1f3f 100644 --- a/test/test-mongoid.js +++ b/test/test-mongoid.js @@ -57,7 +57,7 @@ module.exports.require = { module.exports.mongoid_function = { testShouldReturn24CharHexString: function(test) { var id = mongoid(); - test.ok(id.match(/[0-9a-fA-F]{24}/), "should return a 24-char id string"); + test.ok(id.match(/^[0-9a-fA-F]{24}$/), "should return a 24-char id string"); test.done(); }, From 2ef6b8eb0a33c2debe0c4f709a6b6e781ef673e3 Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 01:44:37 -0400 Subject: [PATCH 05/22] fix sequence wrapping and test that sequence id wraps --- Readme.md | 2 +- mongoid.js | 2 ++ test/test-mongoid.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 05c4b45..cb61d74 100644 --- a/Readme.md +++ b/Readme.md @@ -71,7 +71,7 @@ same as MongoId.parse(id.toString()), see below #### id.getTimestamp( ) -same as MongoId.getTimestam(id.toString()), see below +same as MongoId.getTimestamp(id.toString()), see below #### id.toString( ) diff --git a/mongoid.js b/mongoid.js index 5273adc..be9f0d0 100644 --- a/mongoid.js +++ b/mongoid.js @@ -76,7 +76,9 @@ MongoId.prototype._getTimestampStr = timestampCache[1]; var _hexDigits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; MongoId.prototype.fetch = function() { + this.sequenceId += 1; if (this.sequenceId >= 0x1000000) { + // sequence wrapped, we can make an id only if the timestamp advanced var _timestamp = this._getTimestamp(); if (_timestamp === this.sequenceStartTimestamp) { // TODO: find a more elegant way to deal with overflow diff --git a/test/test-mongoid.js b/test/test-mongoid.js index 3dd1f3f..1546a6f 100644 --- a/test/test-mongoid.js +++ b/test/test-mongoid.js @@ -76,6 +76,26 @@ module.exports.mongoid_function = { test.ok(t2-t1 < 100, "should generate > 100k ids / sec"); test.done(); }, + + 'should throw Error if wrapped in same second': function(t) { + factory = new MongoId(0x111111); + factory.sequenceId = 0xffffff; + factory.sequencePrefix = "fffff"; + // note: race condition: this test will fail if the seconds increase before the fetch + t.throws(function(){ factory.fetch() }, 'should throw'); + t.done(); + }, + + 'should wrap at max id': function(t) { + factory = new MongoId(0x222222); + factory.sequenceId = 0xfffffe; + factory.sequencePrefix = "fffff"; + factory.sequenceStartTimestamp -= 1000; + t.equal(factory.fetch().slice(-6), 'ffffff'); + t.equal(factory.fetch().slice(-6), '000000'); + t.equal(factory.fetch().slice(-6), '000001'); + t.done(); + }, }; module.exports.MongoId_class = { From 08469248c8175b087e4641e9f6276b68ebe20d9b Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 01:46:01 -0400 Subject: [PATCH 06/22] quantize timestamp to second boundariesg --- mongoid.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mongoid.js b/mongoid.js index be9f0d0..aeb017d 100644 --- a/mongoid.js +++ b/mongoid.js @@ -64,8 +64,9 @@ var timestampCache = (function() { if (!_timestamp || ++_ncalls > 1000) { _ncalls = 0; _timestamp = Date.now(); - _timestampStr = hexFormat(Math.floor(_timestamp/1000), 8); setTimeout(function(){ _timestamp = null; }, 10); + _timestamp -= _timestamp % 1000; + _timestampStr = hexFormat(_timestamp/1000, 8); } return _timestampStr; } From eee1c0f0e6bdb69bbf3e5cc27da884311f93a8c4 Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 01:54:43 -0400 Subject: [PATCH 07/22] optimize when the _timestamp is reset, strength reduce mod and div to binary bitmask ops --- mongoid.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mongoid.js b/mongoid.js index aeb017d..c96c5ce 100644 --- a/mongoid.js +++ b/mongoid.js @@ -64,7 +64,8 @@ var timestampCache = (function() { if (!_timestamp || ++_ncalls > 1000) { _ncalls = 0; _timestamp = Date.now(); - setTimeout(function(){ _timestamp = null; }, 10); + var msToNextTimestamp = 1000 - _timestamp % 1000; + setTimeout(function(){ _timestamp = null; }, Math.min(msToNextTimestamp - 1, 100)); _timestamp -= _timestamp % 1000; _timestampStr = hexFormat(_timestamp/1000, 8); } @@ -89,8 +90,8 @@ MongoId.prototype.fetch = function() { this.sequenceStartTimestamp = _timestamp; } - if (++this.sequenceId % 16 === 0) { - this.sequencePrefix = hexFormat((this.sequenceId / 16 | 0).toString(16), 5); + if ((this.sequenceId & 0xF) === 0) { + this.sequencePrefix = hexFormat((this.sequenceId >>> 4).toString(16), 5); } return this._getTimestampStr() + this.processIdStr + this.sequencePrefix + _hexDigits[this.sequenceId % 16]; }; From 8a71dff1b8c1ff3d3d588aaf70a688213b6adcc3 Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 01:55:05 -0400 Subject: [PATCH 08/22] fix getTimestamp method func decl --- mongoid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoid.js b/mongoid.js index c96c5ce..272cee1 100644 --- a/mongoid.js +++ b/mongoid.js @@ -128,7 +128,7 @@ MongoId.prototype.parse = function( idstring ) { MongoId.getTimestamp = function( idstring ) { return parseInt(idstring.slice(0, 8), 16) * 1000; }; -MongoId.prototype.getTimestamp = function( idstring ) { +MongoId.prototype.getTimestamp = function( ) { return MongoId.getTimestamp(this.toString()); }; From be4175760134abf3491288157d959c06a046c26d Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 02:08:10 -0400 Subject: [PATCH 09/22] update header --- mongoid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoid.js b/mongoid.js index 272cee1..582adc7 100644 --- a/mongoid.js +++ b/mongoid.js @@ -3,7 +3,7 @@ * Ids are a hex number built out of the timestamp, a per-server unique id, * the process id and a sequence number. * - * Copyright (C) 2014 Andras Radics + * Copyright (C) 2014,2016 Andras Radics * Licensed under the Apache License, Version 2.0 * * MongoDB object ids are 12 bytes (24 hexadecimal chars), composed out of From 73e6b5849d8ec4675df2cca5eea8c66e52001cf3 Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:34:43 -0400 Subject: [PATCH 10/22] expose the global singleton to unit tests --- mongoid.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mongoid.js b/mongoid.js index 582adc7..d1f2cac 100644 --- a/mongoid.js +++ b/mongoid.js @@ -23,6 +23,7 @@ module.exports = MongoId; module.exports.mongoid = mongoid; module.exports.MongoId = MongoId; +module.exports._singleton = globalSingleton; var globalSingleton = null; @@ -32,6 +33,7 @@ function mongoid( ) { } else { globalSingleton = new MongoId(); + module.exports._singleton = globalSingleton; return globalSingleton.fetch(); } } From e5d11a9d5979d95b8a34008d2539e4ddd941256f Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:37:33 -0400 Subject: [PATCH 11/22] make _getTimestamp accessible as a file-scope function --- mongoid.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mongoid.js b/mongoid.js index d1f2cac..5f5805a 100644 --- a/mongoid.js +++ b/mongoid.js @@ -38,6 +38,9 @@ function mongoid( ) { } } +var _getTimestamp = null; +var _getTimestampStr = null; + function MongoId( machineId ) { // if called as a function, return an id from the singleton if (this === global || !this) return mongoid(); @@ -51,7 +54,7 @@ function MongoId( machineId ) { this.sequenceId = 0; this.sequencePrefix = "00000"; this.id = null; - this.sequenceStartTimestamp = this._getTimestamp(); + this.sequenceStartTimestamp = _getTimestamp(); } var timestampCache = (function() { @@ -75,8 +78,8 @@ var timestampCache = (function() { } return [getTimestamp, getTimestampStr]; })(); -MongoId.prototype._getTimestamp = timestampCache[0]; -MongoId.prototype._getTimestampStr = timestampCache[1]; +_getTimestamp = MongoId.prototype._getTimestamp = timestampCache[0]; +_getTimestampStr = MongoId.prototype._getTimestampStr = timestampCache[1]; var _hexDigits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; MongoId.prototype.fetch = function() { From 4e04bc9b70447ca92c6d6fed5be830b7c4ed1f7a Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:39:00 -0400 Subject: [PATCH 12/22] browserify compat: use a random process.pid if not available, have constructor use only functions not methods --- mongoid.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongoid.js b/mongoid.js index 5f5805a..9ccb2d9 100644 --- a/mongoid.js +++ b/mongoid.js @@ -50,7 +50,10 @@ function MongoId( machineId ) { else if (machineId < 0 || machineId > 0x1000000) throw new Error("machine id out of range 0.." + parseInt(0x1000000)); - this.processIdStr = this.hexFormat(machineId, 6) + this.hexFormat(process.pid, 4); + // if process.pid not available, use a random 2-byte number between 10k and 30k + var processId = process.pid || 10000 + Math.floor(Math.random() * 20000); + + this.processIdStr = hexFormat(machineId, 6) + hexFormat(processId, 4); this.sequenceId = 0; this.sequencePrefix = "00000"; this.id = null; From 699fde5b1346be0d2b4ab4b77a892d77a3770f35 Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:39:34 -0400 Subject: [PATCH 13/22] fix off-by-one in machine id range test --- mongoid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoid.js b/mongoid.js index 9ccb2d9..ab4abeb 100644 --- a/mongoid.js +++ b/mongoid.js @@ -47,7 +47,7 @@ function MongoId( machineId ) { // if no machine id specified, use a 3-byte random number if (!machineId) machineId = Math.floor(Math.random() * 0x1000000); - else if (machineId < 0 || machineId > 0x1000000) + else if (machineId < 0 || machineId >= 0x1000000) throw new Error("machine id out of range 0.." + parseInt(0x1000000)); // if process.pid not available, use a random 2-byte number between 10k and 30k From 7136fccba87552c5738fbf00e8e0f6ffadb66eca Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:47:06 -0400 Subject: [PATCH 14/22] more unit tests, now 100% coverage --- mongoid.js | 1 + test/test-mongoid.js | 96 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 80 insertions(+), 17 deletions(-) diff --git a/mongoid.js b/mongoid.js index ab4abeb..6f5367e 100644 --- a/mongoid.js +++ b/mongoid.js @@ -118,6 +118,7 @@ MongoId.prototype.toString = function( ) { }; MongoId.parse = function( idstring ) { + // TODO: should throw an Error not coerce, but is a breaking change if (typeof idstring !== 'string') idstring = "" + idstring; return { timestamp: parseInt(idstring.slice( 0, 0+8), 16), diff --git a/test/test-mongoid.js b/test/test-mongoid.js index 1546a6f..e618d2b 100644 --- a/test/test-mongoid.js +++ b/test/test-mongoid.js @@ -77,23 +77,17 @@ module.exports.mongoid_function = { test.done(); }, - 'should throw Error if wrapped in same second': function(t) { - factory = new MongoId(0x111111); - factory.sequenceId = 0xffffff; - factory.sequencePrefix = "fffff"; - // note: race condition: this test will fail if the seconds increase before the fetch - t.throws(function(){ factory.fetch() }, 'should throw'); - t.done(); - }, - - 'should wrap at max id': function(t) { - factory = new MongoId(0x222222); - factory.sequenceId = 0xfffffe; - factory.sequencePrefix = "fffff"; - factory.sequenceStartTimestamp -= 1000; - t.equal(factory.fetch().slice(-6), 'ffffff'); - t.equal(factory.fetch().slice(-6), '000000'); - t.equal(factory.fetch().slice(-6), '000001'); + 'it should use the global singleton': function(t) { + mongoid(); + var called = false; + var actualFetch = mongoid._singleton.fetch; + mongoid._singleton.fetch = function(){ + called = true; + return actualFetch.call(mongoid._singleton) + }; + mongoid(); + mongoid._singleton.fetch = actualFetch; + t.equal(called, true); t.done(); }, }; @@ -127,6 +121,67 @@ module.exports.MongoId_class = { test.done(); }, + 'should throw Error if wrapped in same second': function(t) { + factory = new MongoId(0x111111); + factory.sequenceId = 0xffffff; + factory.sequencePrefix = "fffff"; + // note: race condition: this test will fail if the seconds increase before the fetch + t.throws(function(){ factory.fetch() }, 'should throw'); + t.done(); + }, + + 'should wrap at max id': function(t) { + factory = new MongoId(0x222222); + factory.sequenceId = 0xfffffe; + factory.sequencePrefix = "fffff"; + factory.sequenceStartTimestamp -= 1000; + t.equal(factory.fetch().slice(-6), 'ffffff'); + t.equal(factory.fetch().slice(-6), '000000'); + t.equal(factory.fetch().slice(-6), '000001'); + t.done(); + }, + + 'id should include timestamp': function(t) { + var t1 = Date.now(); + var id = new MongoId().toString(); + var timestamp = MongoId.getTimestamp(id); + t.ok(t1 - t1 % 1000 <= timestamp && timestamp <= Date.now()); + t.done(); + }, + + 'id should include pid': function(t) { + var id = new MongoId().toString(); + t.ok(id.indexOf(process.pid.toString(16)) == 14); + t.done(); + }, + + 'id should include a random pid if process.pid is not set': function(t) { + var processPid = process.pid; + delete process.pid; + var id = new MongoId().toString(); + var pid = parseInt(id.slice(14, 18), 16); + t.ok(pid >= 10000 && pid <= 32767); + process.pid = processPid; + t.done(); + }, + + 'it should reject a machine id out of range': function(t) { + t.throws(function(){ new MongoId(0xffffff + 1) }); + t.done(); + }, + + '_getTimestamp should return second precision timestamps 50ms apart': function(t) { + var factory = new MongoId(); + var t1 = factory._getTimestamp(); + setTimeout(function(){ + var t2 = factory._getTimestamp(); + t.equal(t1 % 1000, 0); + t.equal(t2 % 1000, 0); + t.ok(t2 >= t1); + t.done(); + }, 100 + 5); + }, + testShouldParseId: function(test) { var timestamp = Math.floor(Date.now()/1000); var obj = new MongoId(0x123456); @@ -138,6 +193,13 @@ module.exports.MongoId_class = { test.done(); }, + testShouldParseNonString: function(t) { + // TODO: should throw, not coerce (but is a breaking change) + var hash = MongoId.parse(0x12345678); + t.equal(hash.timestamp, parseInt(("" + 0x12345678).slice(0, 8), 16)); + t.done(); + }, + testIdShouldContainParsedParts: function(test) { var obj = new MongoId(); var hexFormat = obj.hexFormat; From 57225440c2b65c7201e4203fc7ea8d8f2cd403ee Mon Sep 17 00:00:00 2001 From: Andras Date: Tue, 25 Oct 2016 22:52:28 -0400 Subject: [PATCH 15/22] thanks cordovapolymer for browserify suggestions --- mongoid.js | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoid.js b/mongoid.js index 6f5367e..2482aa8 100644 --- a/mongoid.js +++ b/mongoid.js @@ -51,6 +51,7 @@ function MongoId( machineId ) { throw new Error("machine id out of range 0.." + parseInt(0x1000000)); // if process.pid not available, use a random 2-byte number between 10k and 30k + // suggestions for better browserify support from @cordovapolymer at github var processId = process.pid || 10000 + Math.floor(Math.random() * 20000); this.processIdStr = hexFormat(machineId, 6) + hexFormat(processId, 4); From f927a50ffcdb224f7705b15360e15f410829beaf Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:13:12 -0400 Subject: [PATCH 16/22] also test that rejects negative machineId --- test/test-mongoid.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-mongoid.js b/test/test-mongoid.js index e618d2b..1ec7f2f 100644 --- a/test/test-mongoid.js +++ b/test/test-mongoid.js @@ -166,6 +166,7 @@ module.exports.MongoId_class = { }, 'it should reject a machine id out of range': function(t) { + t.throws(function(){ new MongoId(-1) }); t.throws(function(){ new MongoId(0xffffff + 1) }); t.done(); }, From 3960eeeb8c2a63a06e99733a3313b461b5141a2b Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:14:10 -0400 Subject: [PATCH 17/22] fix test name --- test/test-mongoid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-mongoid.js b/test/test-mongoid.js index 1ec7f2f..ab28e71 100644 --- a/test/test-mongoid.js +++ b/test/test-mongoid.js @@ -171,7 +171,7 @@ module.exports.MongoId_class = { t.done(); }, - '_getTimestamp should return second precision timestamps 50ms apart': function(t) { + '_getTimestamp should return second precision timestamps 100ms apart': function(t) { var factory = new MongoId(); var t1 = factory._getTimestamp(); setTimeout(function(){ From f9dbaf8e10b4507739192e4e107defaf0e6b0fb4 Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:19:45 -0400 Subject: [PATCH 18/22] test with qnit; 1.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2b120b..7781b2c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,6 @@ "dependencies": { }, "devDependencies": { - "nodeunit": "0.9.0" + "qnit": "*" } } From 5147bcf4206556f142e56ae929482507d863ee85 Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:22:27 -0400 Subject: [PATCH 19/22] deprecate index.js; 1.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7781b2c..de9d115 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.6", "description": "very fast mongoid compatible unique ids", "license": "Apache-2.0", - "main": "index.js", + "main": "mongoid.js", "author": { "name": "Andras", "url": "http://github.com/andrasq" From 1de2d760150a2a1133ad13b2f4c60a0b9feccc0f Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:35:26 -0400 Subject: [PATCH 20/22] set version 1.0.7 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index de9d115..7c2b746 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoid-js", - "version": "1.0.6", + "version": "1.0.7", "description": "very fast mongoid compatible unique ids", "license": "Apache-2.0", "main": "mongoid.js", @@ -10,7 +10,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/andrasq/node-mongoid-js" + "url": "git://github.com/andrasq/node-mongoid-js.git" }, "engines": { "node": ">=0.0.0" From a7161f16b3b6c57eeef7c6b18e368b04b52dda94 Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:39:39 -0400 Subject: [PATCH 21/22] start changelog section in readme --- Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Readme.md b/Readme.md index cb61d74..72b3165 100644 --- a/Readme.md +++ b/Readme.md @@ -102,3 +102,11 @@ precision unix timestamp; getTimestamp() returns that multiplied by 1000. MongoId.getTimestamp("543f376340e2816497000013"); // => 1413429091000 + + +Change Log +---------- + +- 1.0.7 - fix getTimestamp and quantize correctly, deprecate index.js, test with qnit, fix sequence wrapping +- 1.0.6 - doc edits +- 1.0.5 - stable, fast version From 08781f98bbcc4bc623298e9f7e9de0ec9b0ce740 Mon Sep 17 00:00:00 2001 From: Andras Date: Wed, 26 Oct 2016 22:47:50 -0400 Subject: [PATCH 22/22] update changelog, bump to version 1.1.0 --- Readme.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 72b3165..58d996c 100644 --- a/Readme.md +++ b/Readme.md @@ -107,6 +107,7 @@ precision unix timestamp; getTimestamp() returns that multiplied by 1000. Change Log ---------- +- 1.1.0 - tentative `browserify` support: use a random pid if process.pid is not set, avoid object methods in constructor, 100% unit test coverage - 1.0.7 - fix getTimestamp and quantize correctly, deprecate index.js, test with qnit, fix sequence wrapping - 1.0.6 - doc edits - 1.0.5 - stable, fast version diff --git a/package.json b/package.json index 7c2b746..2a6a19f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoid-js", - "version": "1.0.7", + "version": "1.1.0", "description": "very fast mongoid compatible unique ids", "license": "Apache-2.0", "main": "mongoid.js",