Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bson - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

benchmarks/benchmarks.js

16

lib/bson/objectid.js

@@ -46,4 +46,6 @@ /**

return ObjectID.createFromHexString(id);
} else if(!checkForHexRegExp.test(id)) {
throw new Error("Value passed in is not a valid 24 character hex string");
}
if(ObjectID.cacheHexString) this.__id = this.toHexString();

@@ -63,3 +65,3 @@ };

if(ObjectID.cacheHexString && this.__id) return this.__id;
var hexString = ''

@@ -76,3 +78,3 @@ , number

}
if(ObjectID.cacheHexString) this.__id = hexString;

@@ -104,3 +106,3 @@ return hexString;

* Generate a 12 byte id string used in ObjectID's
*
*
* @param {Number} [time] optional parameter allowing to pass in a second based timestamp.

@@ -130,3 +132,3 @@ * @return {String} return the 12 byte id binary string.

* Converts the id into a 24 byte hex string for printing
*
*
* @return {String} return the 24 byte hex string representation.

@@ -159,3 +161,3 @@ * @api private

* Compares the equality of this ObjectID with `otherID`.
*
*
* @param {Object} otherID ObjectID instance to compare against.

@@ -175,3 +177,3 @@ * @return {Bool} the result of comparing two ObjectID's

* Returns the generation time in seconds that this ID was generated.
*
*
* @return {Number} return number of seconds in the timestamp part of the 12 byte id.

@@ -178,0 +180,0 @@ * @api public

{ "name" : "bson"
, "description" : "A bson parser for node.js and the browser"
, "keywords" : ["mongodb", "bson", "parser"]
, "version" : "0.1.0"
, "version" : "0.1.1"
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"

@@ -9,5 +9,5 @@ , "contributors" : []

, "repository" : { "type" : "git"
, "url" : "git@github.com:christkv/bson.git" }
, "url" : "git@github.com:mongodb/js-bson.git" }
, "bugs" : { "mail" : "node-mongodb-native@googlegroups.com"
, "url" : "https://github.com/christkv/bson/issues" }
, "url" : "https://github.com/mongodb/js-bson/issues" }
, "devDependencies": {

@@ -17,3 +17,3 @@ "nodeunit": "0.7.3"

}
, "config": { "native" : false }
, "config": { "native" : false }
, "main": "./lib/bson/index"

@@ -20,0 +20,0 @@ , "directories" : { "lib" : "./lib/bson" }

@@ -12,9 +12,9 @@ var sys = require('util'),

Binary = require('../../lib/bson/bson').Binary,
Code = require('../../lib/bson/bson').Code,
DBRef = require('../../lib/bson/bson').DBRef,
Symbol = require('../../lib/bson/bson').Symbol,
Double = require('../../lib/bson/bson').Double,
MaxKey = require('../../lib/bson/bson').MaxKey,
MinKey = require('../../lib/bson/bson').MinKey,
Timestamp = require('../../lib/bson/bson').Timestamp,
Code = require('../../lib/bson/bson').Code,
DBRef = require('../../lib/bson/bson').DBRef,
Symbol = require('../../lib/bson/bson').Symbol,
Double = require('../../lib/bson/bson').Double,
MaxKey = require('../../lib/bson/bson').MaxKey,
MinKey = require('../../lib/bson/bson').MinKey,
Timestamp = require('../../lib/bson/bson').Timestamp,
gleak = require('../../tools/gleak'),

@@ -25,8 +25,8 @@ assert = require('assert');

var bsonC = new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
/**
* Retrieve the server information for the current
* instance of the db client
*
*
* @ignore

@@ -41,3 +41,3 @@ */

* instance of the db client
*
*
* @ignore

@@ -52,3 +52,3 @@ */

*/
exports['Should Correctly Serialize and Deserialize simple edge value'] = function(test) {
exports['Should Correctly Serialize and Deserialize simple edge value'] = function(test) {
// Simple serialization and deserialization of edge value

@@ -59,3 +59,3 @@ var doc = {doc:0x1ffffffffffffe};

assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
var doc = {doc:-0x1ffffffffffffe};

@@ -71,13 +71,13 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Should Correctly execute toJSON'] = function(test) {
exports['Should Correctly execute toJSON'] = function(test) {
var a = Long.fromNumber(10);
assert.equal(10, a);
var a = Long.fromNumber(9223372036854775807);
assert.equal(9223372036854775807, a);
// Simple serialization and deserialization test for a Single String value
var doc = {doc:'Serialize'};
var simple_string_serialized = bsonC.serialize(doc, true, false);
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));

@@ -91,7 +91,7 @@ assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));

*/
exports['Should Serialize and Deserialize nested document'] = function(test) {
exports['Should Serialize and Deserialize nested document'] = function(test) {
// Nested doc
var doc = {a:{b:{c:1}}};
var simple_string_serialized = bsonC.serialize(doc, false, true);
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));

@@ -105,3 +105,3 @@ assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));

*/
exports['Simple integer serialization/deserialization test, including testing boundary conditions'] = function(test) {
exports['Simple integer serialization/deserialization test, including testing boundary conditions'] = function(test) {
var doc = {doc:-1};

@@ -111,7 +111,7 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
var doc = {doc:2147483648};
var simple_string_serialized = bsonC.serialize(doc, false, true);
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
var doc = {doc:-2147483648};

@@ -127,3 +127,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization test for a Long value'] = function(test) {
exports['Simple serialization and deserialization test for a Long value'] = function(test) {
var doc = {doc:Long.fromNumber(9223372036854775807)};

@@ -133,3 +133,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
var doc = {doc:Long.fromNumber(-9223372036854775807)};

@@ -145,3 +145,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization for a Float value'] = function(test) {
exports['Simple serialization and deserialization for a Float value'] = function(test) {
var doc = {doc:2222.3333};

@@ -151,3 +151,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
var doc = {doc:-2222.3333};

@@ -163,3 +163,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization for a null value'] = function(test) {
exports['Simple serialization and deserialization for a null value'] = function(test) {
var doc = {doc:null};

@@ -175,3 +175,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
var doc = {doc:true};

@@ -187,3 +187,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization for a date value'] = function(test) {
exports['Simple serialization and deserialization for a date value'] = function(test) {
var date = new Date();

@@ -200,3 +200,3 @@ var doc = {doc:date};

*/
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
var doc = {doc:/abcd/mi};

@@ -206,3 +206,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.equal(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
var doc = {doc:/abcd/};

@@ -218,7 +218,7 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

*/
exports['Simple serialization and deserialization for a objectId value'] = function(test) {
exports['Simple serialization and deserialization for a objectId value'] = function(test) {
var doc = {doc:new ObjectID()};
var simple_string_serialized = bsonC.serialize(doc, false, true);
var doc2 = {doc:ObjectID.createFromHexString(doc.doc.toHexString())};
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc2, false, true));

@@ -232,7 +232,7 @@ assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());

*/
exports['Simple serialization and deserialization for a Binary value'] = function(test) {
exports['Simple serialization and deserialization for a Binary value'] = function(test) {
var binary = new Binary();
var string = 'binstring'
for(var index = 0; index < string.length; index++) { binary.put(string.charAt(index)); }
var simple_string_serialized = bsonC.serialize({doc:binary}, false, true);

@@ -247,7 +247,7 @@ assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:binary}, false, true));

*/
exports['Simple serialization and deserialization for a Code value'] = function(test) {
exports['Simple serialization and deserialization for a Code value'] = function(test) {
var code = new Code('this.a > i', {'i': 1});
var simple_string_serialized_2 = bsonJS.serialize({doc:code}, false, true);
var simple_string_serialized = bsonC.serialize({doc:code}, false, true);
assert.deepEqual(simple_string_serialized, simple_string_serialized_2);

@@ -261,3 +261,3 @@ assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc.scope, bsonC.deserialize(simple_string_serialized).doc.scope);

*/
exports['Simple serialization and deserialization for an Object'] = function(test) {
exports['Simple serialization and deserialization for an Object'] = function(test) {
var simple_string_serialized = bsonC.serialize({doc:{a:1, b:{c:2}}}, false, true);

@@ -267,7 +267,7 @@ var simple_string_serialized_2 = bsonJS.serialize({doc:{a:1, b:{c:2}}}, false, true);

assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);
// Simple serialization and deserialization for an Array
var simple_string_serialized = bsonC.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
var simple_string_serialized_2 = bsonJS.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)

@@ -281,3 +281,3 @@ assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);

*/
exports['Simple serialization and deserialization for a DBRef'] = function(test) {
exports['Simple serialization and deserialization for a DBRef'] = function(test) {
var oid = new ObjectID()

@@ -287,3 +287,3 @@ var oid2 = new ObjectID.createFromHexString(oid.toHexString())

var simple_string_serialized_2 = bsonC.serialize({doc:new DBRef('namespace', oid, 'integration_tests_')}, false, true);
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)

@@ -293,3 +293,3 @@ // Ensure we have the same values for the dbref

var object_c = bsonC.deserialize(simple_string_serialized);
assert.equal(object_js.doc.namespace, object_c.doc.namespace);

@@ -304,3 +304,3 @@ assert.equal(object_js.doc.oid.toHexString(), object_c.doc.oid.toHexString());

*/
exports['Should correctly deserialize bytes array'] = function(test) {
exports['Should correctly deserialize bytes array'] = function(test) {
// Serialized document

@@ -323,3 +323,3 @@ var bytes = [47,0,0,0,2,110,97,109,101,0,6,0,0,0,80,97,116,116,121,0,16,97,103,101,0,34,0,0,0,7,95,105,100,0,76,100,12,23,11,30,39,8,89,0,0,1,0];

*/
exports['Serialize utf8'] = function(test) {
exports['Serialize utf8'] = function(test) {
var doc = { "name" : "本荘由利地域に洪水警報", "name1" : "öüóőúéáűíÖÜÓŐÚÉÁŰÍ", "name2" : "abcdedede"};

@@ -329,3 +329,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.deepEqual(simple_string_serialized, simple_string_serialized2)
var object = bsonC.deserialize(simple_string_serialized);

@@ -341,3 +341,3 @@ assert.equal(doc.name, object.name)

*/
exports['Serialize object with array'] = function(test) {
exports['Serialize object with array'] = function(test) {
var doc = {b:[1, 2, 3]};

@@ -347,3 +347,3 @@ var simple_string_serialized = bsonC.serialize(doc, false, true);

assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
var object = bsonC.deserialize(simple_string_serialized);

@@ -357,3 +357,3 @@ assert.deepEqual(doc, object)

*/
exports['Test equality of an object ID'] = function(test) {
exports['Test equality of an object ID'] = function(test) {
var object_id = new ObjectID();

@@ -369,3 +369,3 @@ var object_id_2 = new ObjectID();

*/
exports['Test same serialization for Object ID'] = function(test) {
exports['Test same serialization for Object ID'] = function(test) {
var object_id = new ObjectID();

@@ -375,3 +375,3 @@ var object_id2 = ObjectID.createFromHexString(object_id.toString())

var simple_string_serialized_2 = bsonC.serialize({doc:object_id2}, false, true);
assert.equal(simple_string_serialized_2.length, simple_string_serialized.length);

@@ -388,3 +388,3 @@ assert.deepEqual(simple_string_serialized, simple_string_serialized_2)

*/
exports['Complex object serialization'] = function(test) {
exports['Complex object serialization'] = function(test) {
// JS Object

@@ -399,5 +399,5 @@ var c1 = { _id: new ObjectID, comments: [], title: 'number 1' };

};
var simple_string_serialized = bsonJS.serialize(doc, false, true);
// C++ Object

@@ -412,5 +412,5 @@ var c1 = { _id: ObjectID.createFromHexString(c1._id.toHexString()), comments: [], title: 'number 1' };

};
var simple_string_serialized_2 = bsonC.serialize(doc, false, true);
for(var i = 0; i < simple_string_serialized_2.length; i++) {

@@ -426,3 +426,3 @@ // debug(i + "[" + simple_string_serialized_2[i] + "] = [" + simple_string_serialized[i] + "]")

assert.equal(doc1._id.id, doc2._id.id)
var doc = {

@@ -433,3 +433,3 @@ _id: 'testid',

};
var simple_string_serialized = bsonJS.serialize(doc, false, true);

@@ -443,3 +443,3 @@ var simple_string_serialized_2 = bsonC.serialize(doc, false, true);

*/
exports['Serialize function'] = function(test) {
exports['Serialize function'] = function(test) {
var doc = {

@@ -449,3 +449,3 @@ _id: 'testid',

}
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);

@@ -464,7 +464,7 @@ var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);

*/
exports['Serialize document with special operators'] = function(test) {
exports['Serialize document with special operators'] = function(test) {
var doc = {"user_id":"4e9fc8d55883d90100000003","lc_status":{"$ne":"deleted"},"owner_rating":{"$exists":false}};
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);
var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);
// Should serialize to the same value

@@ -481,3 +481,3 @@ assert.equal(simple_string_serialized_2.toString('base64'), simple_string_serialized.toString('base64'))

*/
exports['Create ObjectID from hex string'] = function(test) {
exports['Create ObjectID from hex string'] = function(test) {
// Hex Id

@@ -496,3 +496,3 @@ var hexId = new ObjectID().toString();

*/
exports['Serialize big complex document'] = function(test) {
exports['Serialize big complex document'] = function(test) {
// Complex document serialization

@@ -509,2 +509,15 @@ var doc = {"DateTime": "Tue Nov 40 2011 17:27:55 GMT+0000 (WEST)","isActive": true,"Media": {"URL": "http://videos.sapo.pt/Tc85NsjaKjj8o5aV7Ubb"},"Title": "Lisboa fecha a ganhar 0.19%","SetPosition": 60,"Type": "videos","Thumbnail": [{"URL": "http://rd3.videos.sapo.pt/Tc85NsjaKjj8o5aV7Ubb/pic/320x240","Dimensions": {"Height": 240,"Width": 320}}],"Source": {"URL": "http://videos.sapo.pt","SetID": "1288","SourceID": "http://videos.sapo.pt/tvnet/rss2","SetURL": "http://noticias.sapo.pt/videos/tv-net_1288/","ItemID": "Tc85NsjaKjj8o5aV7Ubb","Name": "SAPO Vídeos"},"Category": "Tec_ciencia","Description": "Lisboa fecha a ganhar 0.19%","GalleryID": new ObjectID("4eea2a634ce8573200000000"),"InternalRefs": {"RegisterDate": "Thu Dec 15 2011 17:12:51 GMT+0000 (WEST)","ChangeDate": "Thu Dec 15 2011 17:12:51 GMT+0000 (WEST)","Hash": 332279244514},"_id": new ObjectID("4eea2a96e52778160000003a")}

*/
exports['Should error out due to 24 characters but not valid hexstring for ObjectID'] = function(test) {
try {
var oid = new ObjectID("tttttttttttttttttttttttt");
test.ok(false);
} catch(err) {}
test.done();
}
/**
* @ignore
*/
exports.noGlobalsLeaked = function(test) {

@@ -511,0 +524,0 @@ var leaks = gleak.detectNew();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc