diff --git a/lib/datastore/entity.js b/lib/datastore/entity.js index c73c042836c..3a013dfdc1f 100644 --- a/lib/datastore/entity.js +++ b/lib/datastore/entity.js @@ -76,8 +76,16 @@ var SIGN_TO_ORDER = { * }); */ function Key(options) { - this.namespace_ = options.namespace; - this.path_ = options.path; + Object.defineProperties(this, { + namespace: { + enumerable: true, + value: options.namespace + }, + path: { + enumerable: true, + value: options.path + } + }); } module.exports.Key = Key; @@ -219,7 +227,7 @@ module.exports.keyFromKeyProto = keyFromKeyProto; * // } */ function keyToKeyProto(key) { - var keyPath = key.path_; + var keyPath = key.path; if (keyPath.length < 2) { throw new Error('A key should contain at least a kind and an identifier.'); } @@ -240,9 +248,9 @@ function keyToKeyProto(key) { var proto = { path_element: path }; - if (key.namespace_) { + if (key.namespace) { proto.partition_id = { - namespace: key.namespace_ + namespace: key.namespace }; } return proto; diff --git a/regression/datastore.js b/regression/datastore.js index 2d1c6076b9e..3a1ed3f86ec 100644 --- a/regression/datastore.js +++ b/regression/datastore.js @@ -51,7 +51,7 @@ describe('datastore', function() { var postKey = ds.key('Post', 'post1'); ds.save({ key: postKey, data: post }, function(err, key) { assert.ifError(err); - assert.equal(key.path_[1], 'post1'); + assert.equal(key.path[1], 'post1'); ds.get(key, function(err, entity) { assert.ifError(err); assert.deepEqual(entity.data, post); @@ -70,7 +70,7 @@ describe('datastore', function() { data: post }, function(err, key) { assert.ifError(err); - assert.equal(key.path_[1], 123456789); + assert.equal(key.path[1], 123456789); ds.get(key, function(err, entity) { assert.ifError(err); assert.deepEqual(entity.data, post); @@ -88,7 +88,7 @@ describe('datastore', function() { data: post }, function(err, key) { assert.ifError(err); - var assignedId = key.path_[1]; + var assignedId = key.path[1]; assert(assignedId); ds.get(ds.key('Post', assignedId), function(err, entity) { assert.ifError(err); @@ -118,8 +118,8 @@ describe('datastore', function() { ], function(err, keys) { assert.ifError(err); assert.equal(keys.length,2); - var firstKey = ds.key('Post', keys[0].path_[1]); - var secondKey = ds.key('Post', keys[1].path_[1]); + var firstKey = ds.key('Post', keys[0].path[1]); + var secondKey = ds.key('Post', keys[1].path[1]); ds.get([firstKey, secondKey], function(err, entities) { assert.ifError(err); assert.equal(entities.length, 2); diff --git a/test/datastore/dataset.js b/test/datastore/dataset.js index ba441d6dada..e442928f8fe 100644 --- a/test/datastore/dataset.js +++ b/test/datastore/dataset.js @@ -29,8 +29,8 @@ describe('Dataset', function() { it('should return a key scoped by namespace', function() { var ds = new datastore.Dataset({ projectId: 'test', namespace: 'my-ns' }); var key = ds.key('Company', 1); - assert.equal(key.namespace_, 'my-ns'); - assert.deepEqual(key.path_, ['Company', 1]); + assert.equal(key.namespace, 'my-ns'); + assert.deepEqual(key.path, ['Company', 1]); }); it('should allow namespace specification when creating a key', function() { @@ -39,8 +39,8 @@ describe('Dataset', function() { namespace: 'custom-ns', path: ['Company', 1] }); - assert.equal(key.namespace_, 'custom-ns'); - assert.deepEqual(key.path_, ['Company', 1]); + assert.equal(key.namespace, 'custom-ns'); + assert.deepEqual(key.path, ['Company', 1]); }); it('should get by key', function(done) { @@ -52,7 +52,7 @@ describe('Dataset', function() { }; ds.get(ds.key('Kind', 123), function(err, entity) { var data = entity.data; - assert.deepEqual(entity.key.path_, ['Kind', 5732568548769792]); + assert.deepEqual(entity.key.path, ['Kind', 5732568548769792]); assert.strictEqual(data.author, 'Silvano'); assert.strictEqual(data.isDraft, false); assert.deepEqual(data.publishedAt, new Date(978336000000)); @@ -71,7 +71,7 @@ describe('Dataset', function() { ds.get([key], function(err, entities) { var entity = entities[0]; var data = entity.data; - assert.deepEqual(entity.key.path_, ['Kind', 5732568548769792]); + assert.deepEqual(entity.key.path, ['Kind', 5732568548769792]); assert.strictEqual(data.author, 'Silvano'); assert.strictEqual(data.isDraft, false); assert.deepEqual(data.publishedAt, new Date(978336000000)); @@ -306,7 +306,7 @@ describe('Dataset', function() { ds.runQuery(query, function (err, entities) { assert.ifError(err); - assert.deepEqual(entities[0].key.path_, ['Kind', 5732568548769792]); + assert.deepEqual(entities[0].key.path, ['Kind', 5732568548769792]); var data = entities[0].data; assert.strictEqual(data.author, 'Silvano');