Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

seraph

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seraph - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

32

lib/node.js

@@ -14,6 +14,12 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

*/
save: function(obj, callback) {
save: function(obj, key, val, callback) {
if (typeof key == 'function') {
callback = key;
key = val = undefined;
}
if (Array.isArray(obj)) {
var txn = this._safeBatch();
async.map(obj, txn.save, callback);
var args = [key, val];
async.map(obj, naan.ecurry(txn.save, args, [1, 2]), callback);
return this._safeBatchCommit(txn);

@@ -31,3 +37,4 @@ }

} else {
this.node._update(obj, callback);
if (key) this.node._updateProp(obj, key, val, callback);
else this.node._update(obj, callback);
}

@@ -62,2 +69,3 @@ },

var untouchedObj = _.clone(obj);

@@ -79,2 +87,20 @@ if (untouchedObj[this.options.id] != null) {

_updateProp: function(obj, key, val, callback) {
var id = this._getId(obj, true);
if (!this._isValidId(id)) {
return callback(new Error("Invalid ID"));
}
var endpoint = util.format('%s/properties/%s', this._nodeRoot(id), key);
var op = this.operation(endpoint, 'PUT', val);
this.call(op, function(err, body) {
if (err) return callback(err);
else {
obj = _.clone(obj);
obj[key] = val;
callback(null, obj);
}
});
},
/**

@@ -81,0 +107,0 @@ * Read an object's properties. Maps to GET node/{id}/properties.

14

lib/relationship.js

@@ -68,6 +68,12 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

*/
update: function(rel, callback) {
update: function(rel, key, val, callback) {
if (typeof key == 'function') {
callback = key;
key = val = undefined;
}
if (Array.isArray(rel)) {
var txn = this._safeBatch();
async.map(rel, txn.rel.update, callback);
var args = [key, val];
async.map(rel, naan.ecurry(txn.rel.update, args, [1, 2]), callback);
return this._safeBatchCommit(txn);

@@ -83,3 +89,5 @@ }

var endpoint = util.format('%s/properties', this._relRoot(id));
var op = this.operation(endpoint, 'PUT', rel.properties);
if (key) endpoint += '/' + key;
var op = this.operation(endpoint, 'PUT', key ? val : rel.properties);
this.call(op, function(err) {

@@ -86,0 +94,0 @@ callback(err);

@@ -8,3 +8,3 @@ {

"description": "A thin and familiar layer between node and neo4j's REST api.",
"version": "0.6.2",
"version": "0.6.3",
"repository": {

@@ -11,0 +11,0 @@ "url": "https://github.com/brikteknologier/seraph"

@@ -391,3 +391,3 @@ # Seraph.js

<a name="node.save" />
### save(object, callback)
### save(object, [key, value,] callback)
*Aliases: __node.save__*

@@ -402,2 +402,5 @@

* node - an object to create or update
* key, value (optional) - a property key and a value to update it with. This
allows you to only update a single property of the node, without touching any
others. If `key` is specified, `value` must also be.
* callback - function(err, node). `node` is the newly saved or updated node. If

@@ -677,3 +680,3 @@ a create was performed, `node` will now have an id property. The returned

<a name="rel.update" />
### rel.update(relationship, callback)
### rel.update(relationship, [key, value,] callback)

@@ -688,2 +691,4 @@ Update the properties of a relationship. __Note__ that you cannot use this

* relationship - the relationship object with some changed properties
* key, value (optional) - if a key and value is specified, only the property with
that key will be updated. the rest of the object will not be touched.
* callback - function(err). if err is falsy, the update succeeded.

@@ -690,0 +695,0 @@

@@ -106,2 +106,21 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

it('should save a single property of an object', function(done) {
db.save({name: 'bob', age: 46}, function(err, node) {
assert(!err)
assert.equal(node.name, 'bob');
assert.equal(node.age, 46);
node.name = 'hidden name man';
db.save(node, 'age', 47, function(err, node) {
assert(!err);
assert.equal(node.age, 47);
db.read(node, function(err, node) {
assert(!err);
assert.equal(node.age, 47);
assert.equal(node.name, 'bob');
done();
});
});
});
});
it('should handle an empty array of objects to save', function(done) {

@@ -108,0 +127,0 @@ db.save([], done);

@@ -190,2 +190,48 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

});
it('should update a single property of a rel', function(done) {
function createObjs(done) {
db.save([{name: 'Jon'}, {name: 'Helge'}], function(err, users) {
done(null, users[0], users[1]);
});
}
function linkObjs(user1, user2, done) {
db.rel.create(user1, 'coworker', user2, {
prop: 'test',
anotherProp: 'test2',
thirdProp: 'test3'
}, function(err, link) {
assert.deepEqual(link.properties, {
prop: 'test',
anotherProp: 'test2',
thirdProp: 'test3'
});
done(null, link);
});
}
function updateLink(link, done) {
link.properties.thirdProp = 'fake new value';
db.rel.update(link, 'anotherProp', 'amazing new value', function(err) {
assert.ok(!err);
done(null, link);
});
}
function readLink(link, done) {
var linkId = link.id;
db.rel.read(link.id, function(err, link) {
assert.deepEqual(link.properties, {
prop: 'test',
anotherProp: 'amazing new value',
thirdProp: 'test3'
});
done(null);
});
}
async.waterfall([createObjs, linkObjs, updateLink, readLink], done);
});
});

@@ -192,0 +238,0 @@

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