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.3 to 0.6.4

22

lib/index.js

@@ -162,3 +162,3 @@ var async = require('async');

read: function(type, indexName, key, value, callback) {
readAsList: function(type, indexName, key, value, callback) {
if (typeof value === 'function') {

@@ -194,8 +194,2 @@ callback = value;

if (entityObjects.length === 1) {
entityObjects = entityObjects[0];
} else if (entityObjects.length === 0) {
entityObjects = false;
}
callback(null, entityObjects);

@@ -205,2 +199,16 @@ });

read: function(type, indexName, key, value, callback) {
indexModule.readAsList.call(this, type, indexName, key, value, function (err, results) {
if (err) return callback(err);
if (results.length === 1) {
callback(null, results[0]);
} else if (results.length === 0) {
callback(null, false);
} else {
callback(null, results);
}
});
},
getOrSaveUnique: saveUnique('get_or_create'),

@@ -207,0 +215,0 @@ saveUniqueOrFail: saveUnique('create_or_fail'),

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

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

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

@@ -99,4 +99,4 @@ # Seraph.js

* options (default=`{ server: "http://localhost:7474", endpoint: "/db/data" }` - `server` is protocol and authority part of Neo4J REST API URI, and `endpoint` should be the path segment of the URI.
* server (string) - Short form to specify server parameter only. `"http://localhorse:4747"` is equivalent to `{ server: "http://localhorse:4747" }`.
* `options` (default=`{ server: "http://localhost:7474", endpoint: "/db/data" }` - `server` is protocol and authority part of Neo4J REST API URI, and `endpoint` should be the path segment of the URI.
* `server` (string) - Short form to specify server parameter only. `"http://localhorse:4747"` is equivalent to `{ server: "http://localhorse:4747" }`.

@@ -140,8 +140,8 @@ __Example__

* query - Cypher query as a format string.
* params (optional, default=`{}`). Replace `{key}` parts in query string. See
* `query` - Cypher query as a format string.
* `params` (optional, default=`{}`). Replace `{key}` parts in query string. See
cypher documentation for details. **note** that if you want to send a list of
ids as a parameter, you should send them as an array, rather than a string
representing them (`[2,3]` rather than `"2,3"`).
* callback - (err, result). Result is an array of objects.
* `callback` - (err, result). Result is an array of objects.

@@ -193,7 +193,7 @@ __Example__

* path - the path fragment of the request URL with no leading slash.
* method (optional, default=`'GET'`|`'POST'`) - the HTTP method to use. When
* `path` - the path fragment of the request URL with no leading slash.
* `method` (optional, default=`'GET'`|`'POST'`) - the HTTP method to use. When
`data` is an object, `method` defaults to 'POST'. Otherwise, `method`
defaults to `GET`.
* data (optional) - an object to send to the server with the request.
* `data` (optional) - an object to send to the server with the request.

@@ -221,5 +221,5 @@ __Example__

* operation - an operation created by [operation](#operation) that specifies
* `operation` - an operation created by [operation](#operation) that specifies
what to request from the server
* callback - function(err, result, response). `result` is the JSON parsed body
* `callback` - function(err, result, response). `result` is the JSON parsed body
from the server (otherwise empty). `response` is the response object from the

@@ -404,7 +404,7 @@ request.

* node - an object to create or update
* key, value (optional) - a property key and a value to update it with. This
* `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
* `callback` - function(err, node). `node` is the newly saved or updated node. If
a create was performed, `node` will now have an id property. The returned

@@ -442,7 +442,7 @@ object is not the same reference as the passed object (the passed object will

* node - an object to create or update
* index - the index in which `key` and `value` are relevant
* key - the key under which to index this node and enforce uniqueness
* value - the value under which to index this node and enforce uniqueness
* returnExistingOnConflict (optional, default=`false`) - what to do when there is
* `node` - an object to create or update
* `index` - the index in which `key` and `value` are relevant
* `key` - the key under which to index this node and enforce uniqueness
* `value` - the value under which to index this node and enforce uniqueness
* `returnExistingOnConflict` (optional, default=`false`) - what to do when there is
a conflict (when the index you specified already refers to a node). If set to

@@ -452,3 +452,3 @@ `true`, the node that the index currently refers to is returned. Otherwise,

testing `err.statusCode == 409`.
* callback - function(err, node) - `node` is the newly created node or the node
* `callback` - function(err, node) - `node` is the newly created node or the node
that was in the specified index, depending on `returnExistingOnConflict`.

@@ -490,5 +490,5 @@

* id|object - either the id of the node to read, or an object containing an id
* `id | object` - either the id of the node to read, or an object containing an id
property of the node to read.
* callback - function(err, node). `node` is an object containing the properties
* `callback` - function(err, node). `node` is an object containing the properties
of the node with the given id.

@@ -516,6 +516,6 @@

* id|object - either the id of the node to delete, or an object containing an id
* `id | object` - either the id of the node to delete, or an object containing an id
property of the node to delete.
* force - if truthy, will delete all the node's relations prior to deleting the node.
* callback - function(err). if `err` is falsy, the node has been deleted.
* `force` - if truthy, will delete all the node's relations prior to deleting the node.
* `callback` - function(err). if `err` is falsy, the node has been deleted.

@@ -543,9 +543,9 @@ __Example__

* predicate - Partially defined object. Will return elements which match
* `predicate` - Partially defined object. Will return elements which match
the defined attributes of predicate.
* any (optional, default=`false`) - If true, elements need only match on one
* `any` (optional, default=`false`) - If true, elements need only match on one
attribute. If false, elements must match on all attributes.
* start (optional, default=`'node(*)'`) - The scope of the search. For alternate
* `start` (optional, default=`'node(*)'`) - The scope of the search. For alternate
values, check the [neo4j docs on the cypher START command](http://docs.neo4j.org/chunked/stable/query-start.html).
* callback - function(err, results) - `results` is an array of the resulting
* `callback` - function(err, results) - `results` is an array of the resulting
nodes.

@@ -584,9 +584,9 @@

* id|object - either the id of a node, or an object containing an id property of
* `id | object` - either the id of a node, or an object containing an id property of
a node.
* direction ('all'|'in'|'out') (optional unless `type` is passed,
* `direction` ('all'|'in'|'out') (optional unless `type` is passed,
default=`'all'`) - the direction of relationships to read.
* type (optional, default=`''` (match all relationships)) - the relationship
* `type` (optional, default=`''` (match all relationships)) - the relationship
type to find
* callback - function(err, relationships) - `relationships` is an array of the
* `callback` - function(err, relationships) - `relationships` is an array of the
matching relationships

@@ -613,9 +613,9 @@

* firstId|firstObject - id of the start node or an object with an id property
* `firstId | firstObject` - id of the start node or an object with an id property
for the start node
* type - the name of the relationship
* secondId|secondObject - id of the end node or an object with an id property
* `type` - the name of the relationship
* `secondId | secondObject` - id of the end node or an object with an id property
for the end node
* properties (optional, default=`{}`) - properties of the relationship
* callback - function(err, relationship) - `relationship` is the newly created
* `properties` (optional, default=`{}`) - properties of the relationship
* `callback` - function(err, relationship) - `relationship` is the newly created
relationship

@@ -649,12 +649,12 @@

* firstId|firstObject - id of the start node or an object with an id property
* `firstId | firstObject` - id of the start node or an object with an id property
for the start node
* type - the name of the relationship
* secondId|secondObject - id of the end node or an object with an id property
* `type` - the name of the relationship
* `secondId | secondObject` - id of the end node or an object with an id property
for the end node
* properties (optional, default=`{}`) - properties of the relationship
* index - the index in which `key` and `value` are relevant
* key - the key under which to index this relationship and enforce uniqueness
* value - the value under which to index this relationship and enforce uniqueness
* returnExistingOnConflict (optional, default=`false`) - what to do when there is
* `properties` (optional, default=`{}`) - properties of the relationship
* `index` - the index in which `key` and `value` are relevant
* `key` - the key under which to index this relationship and enforce uniqueness
* `value` - the value under which to index this relationship and enforce uniqueness
* `returnExistingOnConflict` (optional, default=`false`) - what to do when there is
a conflict (when the index you specified already refers to a relationship). If

@@ -664,3 +664,3 @@ set to `true`, the relationship that the index currently refers to is returned.

check this by testing `err.statusCode == 409`.
* callback - function(err, relationship) - `relationship` is the newly created
* `callback` - function(err, relationship) - `relationship` is the newly created
relationship or the relationship that was in the specified index, depending

@@ -701,6 +701,6 @@ on `returnExistingOnConflict`

* relationship - the relationship object with some changed properties
* key, value (optional) - if a key and value is specified, only the property with
* `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.
* `callback` - function(err). if err is falsy, the update succeeded.

@@ -730,5 +730,5 @@ __Example__

* object|id - the id of the relationship to read or an object with an id
* `object | id` - the id of the relationship to read or an object with an id
property of the relationship to read.
* callback - function(err, relationship). `relationship` is an object
* `callback` - function(err, relationship). `relationship` is an object
representing the read relationship.

@@ -762,5 +762,5 @@

* object|id - the id of the relationship to delete or an object with an id
* `object | id` - the id of the relationship to delete or an object with an id
property of the relationship to delete.
* callback - function(err). If `err` is falsy, the relationship has been
* `callback` - function(err). If `err` is falsy, the relationship has been
deleted.

@@ -797,6 +797,6 @@

* name - the name of the index that is being created
* config (optional, default=`{}`) - the configuration of the index. See the [neo4j docs](http://docs.neo4j.org/chunked/milestone/rest-api-indexes.html#rest-api-create-node-index-with-configuration)
* `name` - the name of the index that is being created
* `config` (optional, default=`{}`) - the configuration of the index. See the [neo4j docs](http://docs.neo4j.org/chunked/milestone/rest-api-indexes.html#rest-api-create-node-index-with-configuration)
for more information.
* callback - function(err). If `err` is falsy, the index has been created.
* `callback` - function(err). If `err` is falsy, the index has been created.

@@ -831,8 +831,8 @@ __Example__

* indexName - the name of the index to add the node/relationship to.
* id|object - the id of the node/relationship to add to the index or an object
* `indexName` - the name of the index to add the node/relationship to.
* `id | object` - the id of the node/relationship to add to the index or an object
with an id property of the node/relationship to add to the index.
* key - the key to index the node/relationship with
* value - the value to index the node/relationship with
* callback - function(err). If `err` is falsy, the node/relationship has
* `key` - the key to index the node/relationship with
* `value` - the value to index the node/relationship with
* `callback` - function(err). If `err` is falsy, the node/relationship has
been indexed.

@@ -856,3 +856,4 @@

Read the object(s) from an index that match a key-value pair.
Read the object(s) from an index that match a key-value pair. See also
[index.readAsList](#index.readAsList).

@@ -868,8 +869,10 @@ __NOTE for index functions:__ there are two different types on index in neo4j -

* indexName - the index to read from
* key - the key to match
* value - the value to match
* callback - function(err, results). `results` is a node or relationship object
* `indexName` - the index to read from
* `key` - the key to match
* `value` - the value to match
* `callback` - function(err, results). `results` is a node or relationship object
(or an array of them if there was more than one) that matched the given
key-value pair in the given index. If nothing matched, `results === false`.
[index.readAsList](#index.readAsList) is similar, but always gives `results` as
an array, with zero, one or more elements.

@@ -887,2 +890,37 @@ __Example__

<a name="index.readAsList" />
### node.index.readAsList(indexName, key, value, callback);
### rel.index.readAsList(indexName, key, value, callback);
Read the object(s) from an index that match a key-value pair. See also
[index.read](#index.read).
__NOTE for index functions:__ there are two different types on index in neo4j -
__node__ indexes and __relationship__ indexes. When you're working with __node__
indexes, you use the functions on `node.index`. Similarly, when you're working
on __relationship__ indexes you use the functions on `rel.index`. Most of the
functions on both of these are identical (excluding the uniqueness functions),
but one acts upon node indexes, and the other upon relationship indexes.
__Arguments__
* `indexName` - the index to read from
* `key` - the key to match
* `value` - the value to match
* `callback` - function(err, results). `results` is an array of node or
relationship objects that matched the given key-value pair in the given index.
[index.read](#index.read) is similar, but gives `results` as `false`, an object
or an array of objects depending on the number of hits.
__Example__
```javascript
db.rel.index.readAsList('friendships', 'location', 'Norway', function(err, rels) {
// `rels` is an array of all relationships indexed in the `friendships`
// index, with a value `Norway` for the key `location`.
});
```
---------------------------------------
<a name="index.remove" />

@@ -903,12 +941,12 @@ ### node.index.remove(indexName, id|object, [key, [value,]] callback);

* indexName - the index to remove the node/relationship from.
* id|object - the id of the node/relationship to remove from the index or an
* `indexName` - the index to remove the node/relationship from.
* `id | object` - the id of the node/relationship to remove from the index or an
object with an id property of the node/relationship to remove from the index.
* key (optional) - the key from which to remove the node/relationship. If none
* `key` (optional) - the key from which to remove the node/relationship. If none
is specified, every reference to the node/relationship is deleted from the
index.
* value (optional) - the value from which to remove the node/relationship. If
* `value` (optional) - the value from which to remove the node/relationship. If
none is specified, every reference to the node/relationship is deleted for the
given key.
* callback - function(err). If `err` is falsy, the specified references have
* `callback` - function(err). If `err` is falsy, the specified references have
been removed.

@@ -945,4 +983,4 @@

* name - the name of the index to delete
* callback - function(err). if `err` is falsy, the index has been deleted.
* `name` - the name of the index to delete
* `callback` - function(err). if `err` is falsy, the index has been deleted.

@@ -949,0 +987,0 @@ __Example__

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

});
});
it('should support indexing and index.readAsList', function(done) {
var txn = db.batch();
var idx = uniqn();
var person = txn.save({name:'Jon'});
txn.index(idx, person, 'thing', 'stuff');
txn.commit(function(err, txnResults) {
assert(!err);
db.index.readAsList(idx, 'thing', 'stuff', function(err, readResults) {
assert(!err);
assert.equal(readResults.length, 1);
assert.deepEqual(readResults[0], txnResults[person]);
done();
});
});
});

@@ -281,0 +298,0 @@

@@ -85,2 +85,24 @@ /* -*- Mode: Javascript; js-indent-level: 2 -*- */

it('should read zero objects from an index as `false`', function(done) {
var iname = uniqn();
function createAndIndex(done) {
db.save({ name: 'Helge' }, function(err, node) {
db.node.index(iname, node, 'person', 'true', function(err) {
done();
});
});
}
function readIndex(done) {
db.index.read(iname, 'person', 'false', function(err, results) {
assert.ok(!err);
assert.equal(results, false);
done();
})
}
async.series([createAndIndex, readIndex], done);
});
it('should read a single object from an index', function(done) {

@@ -92,3 +114,3 @@ var iname = uniqn();

db.node.index(iname, node, 'person', 'true', function(err) {
done();
done();
});

@@ -115,3 +137,3 @@ });

db.node.index(iname, node, 'person', 'has a space', function(err) {
done();
done();
});

@@ -139,3 +161,3 @@ });

db.node.index(iname, node, 'person', 'has a space', function(err) {
done();
done();
});

@@ -162,3 +184,3 @@ });

db.node.index(iname, nodes, 'company', 'brik', function(err) {
done();
done();
});

@@ -207,2 +229,71 @@ });

it('should readAsList zero objects from an index as `[]`', function(done) {
var iname = uniqn();
function createAndIndex(done) {
db.save({ name: 'Helge' }, function(err, node) {
db.node.index(iname, node, 'person', 'true', function(err) {
done();
});
});
}
function readIndex(done) {
db.index.readAsList(iname, 'person', 'false', function(err, results) {
assert.ok(!err);
assert.deepEqual(results, []);
done();
})
}
async.series([createAndIndex, readIndex], done);
});
it('should readAsList a single object from an index as a list', function(done) {
var iname = uniqn();
function createAndIndex(done) {
db.save({ name: 'Helge' }, function(err, node) {
db.node.index(iname, node, 'person', 'true', function(err) {
done();
});
});
}
function readIndex(done) {
db.index.readAsList(iname, 'person', 'true', function(err, results) {
assert.ok(!err);
assert.equal(results.length, 1);
assert.equal(results[0].name, 'Helge');
done();
})
}
async.series([createAndIndex, readIndex], done);
});
it('should readAsList all values of a kv pair in an index', function(done) {
var iname = uniqn();
function createAndIndex(done) {
db.save([{ name: 'Helge' }, { name: 'Erlend' }], function(err, nodes) {
db.node.index(iname, nodes, 'company', 'brik', function(err) {
done();
});
});
}
function readIndex(done) {
db.index.readAsList(iname, 'company', 'brik', function(err, nodes) {
assert.ok(!err);
var names = nodes.map(function(node) { return node.name });
assert.ok(names.indexOf("Helge") !== -1);
assert.ok(names.indexOf("Erlend") !== -1);
done();
})
}
async.series([createAndIndex, readIndex], done);
});
it('should remove a node from an index', function(done) {

@@ -214,3 +305,3 @@ var iname = uniqn();

db.node.index(iname, node, 'person', 'true', function(err) {
done();
done();
});

@@ -244,3 +335,3 @@ });

db.node.index(iname, node, 'person', 'false', function(err) {
done();
done();
});

@@ -279,3 +370,3 @@ });

db.node.index(iname, node, 'otherkey', 'false', function(err) {
done();
done();
});

@@ -314,3 +405,3 @@ });

db.node.index(iname, node, 'otherkey', 'false', function(err) {
done();
done();
});

@@ -317,0 +408,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