New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.7 to 0.7.0

test/label.js

81

lib/node.js

@@ -306,3 +306,84 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

}
},
label: function(node, label, replace, callback) {
if (typeof replace == 'function') {
callback = replace;
replace = false;
}
if (Array.isArray(node)) {
var txn = this._safeBatch();
async.map(node, naan.ecurry(txn.label, [label, replace], [1,2]), callback);
return this._safeBatchCommit(txn);
}
var id = this._getId(node);
if (!this._isValidId(id)) return callback(new Error("Invalid ID"));
var endpoint = util.format('%s/labels', this._nodeRoot(id));
var op = this.operation(endpoint, replace ? 'PUT' : 'POST', label);
this.call(op, function(err) {
if (err) callback(err);
else callback();
});
},
removeLabel: function(node, label, callback) {
if (Array.isArray(node)) {
var txn = this._safeBatch();
async.map(node, naan.ncurry(txn.removeLabel, label, 1), callback);
return this._safeBatchCommit(txn);
}
var id = this._getId(node);
if (!this._isValidId(id)) return callback(new Error("Invalid ID"));
var endpoint = util.format('%s/labels/%s', this._nodeRoot(id), label);
var op = this.operation(endpoint, 'DELETE');
this.call(op, function(err) {
if (err) callback(err);
else callback();
});
},
nodesWithLabel: function(label, callback) {
var endpoint = util.format('label/%s/nodes', label);
var op = this.operation(endpoint, 'GET');
this.call(op, function(err, nodes) {
if (err || !nodes) return callback(err, nodes);
nodes = nodes.map(this._createNodeObject);
callback(null, nodes);
});
},
readLabels: function(node, callback) {
if (typeof node == 'function') {
callback = node;
node = undefined;
}
if (Array.isArray(node)) {
var txn = this._safeBatch();
async.map(node, txn.readLabels, function(err, allLabels) {
if (err) return callback(err);
callback(null, _.uniq(_.flatten(allLabels)));
});
return this._safeBatchCommit(txn);
}
var endpoint;
if (node) {
var id = this._getId(node);
if (!this._isValidId(id)) return callback(new Error("Invalid ID"));
endpoint = util.format('%s/labels', this._nodeRoot(id));
} else {
endpoint = 'labels';
}
var op = this.operation(endpoint, 'GET');
this.call(op, function(err, labels) {
if (err) callback(err);
else callback(null, labels);
});
}
}

11

lib/seraph.js

@@ -420,2 +420,9 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

function transformBatchArgs(args) {
return args.map(function(arg) {
if (Array.isArray(arg)) return transformBatchArgs(arg);
return isBatchId(arg) ? arg.refersTo : arg;
});
};
function wrapFunctions(parent, target) {

@@ -459,5 +466,3 @@ var derived = target || {};

args = args.map(function(arg) {
return isBatchId(arg) ? arg.refersTo : arg;
});
args = transformBatchArgs(args);

@@ -464,0 +469,0 @@ // Context does not matter because all functions are bound upon seraph init

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

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

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

@@ -56,2 +56,9 @@ # Seraph.js

* [index (node.index)](#node.index) - add a node to an index
* [label (node.label)](#node.label) - add a label to a node
* [removeLabel (node.removeLabel)](#node.removeLabel) - remove a label from a
node
* [nodesWithLabel (node.nodesWithLabel)](#node.nodesWithLabel) - fetch all nodes
with a label
* [readLabels (node.readLabels)](#node.readLabels) - read the labels of a node
or all available labels.

@@ -79,3 +86,3 @@ ### Relationship Operations

Seraph has been tested with Neo4j 2.0.0-M03. If you would like to test
Seraph 0.6.7 has been tested with Neo4j 2.0.0-M06. If you would like to test
compatibility with another version of neo4j, change the version values stored in

@@ -599,2 +606,112 @@ `test/util/database.js`.

---------------------------------------
<a name="node.label" />
### label(id|object(s), label(s), [replace,] callback)
*Aliases: __node.label__*
Add a label to a node.
__Arguments__
* `id|object(s)` - either the id of the node to label, or an object containing an
id property of the node to label. can be an array of objects/ids.
* `label(s)` - the label(s) to apply. can be an array of labels.
* `replace` (optional) - if set to true, this label will replace any previous
labels.
* `callback` - function(err). if err is falsy, the operation succeeded.
__Example__
```javascript
db.save({ make: 'Citroen', model: 'DS4' }, function(err, node) {
db.label(node, ['Car', 'Hatchback'], function(err) {
// `node` is now labelled with "Car" and "Hatchback"!
});
})
```
---------------------------------------
<a name="node.removeLabel" />
### removeLabel(id|object(s), label, callback)
*Aliases: __node.removeLabel__*
Remove a label from a node.
__Arguments__
* `id|object(s)` - either the id of the node to delabel, or an object containing
an id property of the node to delabel. can be an array of objects/ids.
* `label` - the label to remove. cannot be an array.
* `callback` - function(err). if err is falsy, the operation succeeded.
__Example__
```javascript
db.save({ make: 'Citroen', model: 'DS4' }, function(err, node) {
db.label(node, ['Car', 'Hatchback'], function(err) {
// `node` is now labelled with "Car" and "Hatchback"!
db.removeLabel(node, 'Hatchback', function(err) {
// `node` is now only labelled with "Car".
});
});
})
```
---------------------------------------
<a name="node.nodesWithLabel" />
### nodesWithLabel(label, callback)
*Aliases: __node.nodesWithLabel__*
Fetch all of the nodes that are labelled with a specific label.
__Arguments__
* `label` - the label.
* `callback` - function(err, results). results is always an array (assuming no
error), containing the nodes that were labelled with `label`. if no nodes were
labelled with `label`, `results` is an empty array.
__Example__
```javascript
db.save({ make: 'Citroen', model: 'DS4' }, function(err, node) {
db.label(node, ['Car', 'Hatchback'], function(err) {
db.nodesWithLabel('Car', function(err, results) {
results[0].model // -> 'DS4'
});
});
})
```
---------------------------------------
<a name="node.readLabels" />
### readLabels([node(s),] callback)
*Aliases: __node.readLabels__*
Read the labels of a node, or all labels in the database.
__Arguments__
* `node(s)` (optional) - the node to return the labels of. if not specified, every
label in the database is returned. can be an array of nodes.
* `callback` - function(err, labels). labels is an array of labels.
__Example__
```javascript
db.save({ make: 'Citroen', model: 'DS4' }, function(err, node) {
db.label(node, ['Car', 'Hatchback'], function(err) {
db.readLabels(node, function(err, labels) {
//labels -> ['Car', 'Hatchback']
});
});
})
```
---------------------------------------
## Relationship Operations

@@ -601,0 +718,0 @@

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

disposableSeraph({
version: '2.0.0-M04',
version: '2.0.0-M06',
edition: 'community',

@@ -17,0 +17,0 @@ port: TEST_INSTANCE_PORT

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