cypher-stream
Advanced tools
Comparing version 0.0.1 to 0.1.0
55
index.js
@@ -1,16 +0,45 @@ | ||
var request = require('request'); | ||
var Neo4jStreamDeserializer = require('neo4j-stream-deserializer'); | ||
var oboe = require('oboe'); | ||
var Readable = require('stream').Readable; | ||
var util = require('util'); | ||
module.exports = function(url) { | ||
return function(query, params) { | ||
var form = { query: query }; | ||
if(params) { | ||
form.params = params; | ||
} | ||
return request.post({ | ||
url : url, | ||
form : form, | ||
headers : { "X-Stream": true, "Accept": "application/json" } | ||
}).pipe(new Neo4jStreamDeserializer()); | ||
util.inherits(CypherStream, Readable); | ||
function CypherStream (url, query, params) { | ||
Readable.call(this, { objectMode: true }); | ||
var columns; | ||
var stream = this; | ||
oboe({ | ||
url : url+'/db/data/cypher', | ||
method : 'POST', | ||
headers : { "X-Stream": true, "Accept": "application/json" }, | ||
body : { query: query, params: params } | ||
}) | ||
.node('!columns', function (c) { | ||
stream.emit('columns', c); | ||
columns = c; | ||
this.forget(); | ||
}) | ||
.node('!data[*]', function (result, path, ancestors) { | ||
var data = {}; | ||
columns.forEach(function (column, i) { | ||
data[column] = result[i].data | ||
}); | ||
stream.push(data) | ||
}) | ||
.done(function (complete) { | ||
stream.push(null); | ||
}) | ||
.fail(function(error) { | ||
stream.emit('error', error); | ||
stream.push(null); | ||
}); | ||
this._read = function () { } | ||
return this; | ||
}; | ||
module.exports = function Connection(url) { | ||
return function CypherStreamFactory (query, params) { | ||
return new CypherStream(url, query, params); | ||
} | ||
}; |
{ | ||
"name": "cypher-stream", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Streams cypher query results in a clean format", | ||
@@ -25,4 +25,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"neo4j-stream-deserializer": "git://github.com/brian-gates/neo4j-stream-deserializer.git", | ||
"request": "~2.33.0" | ||
"oboe": "~1.12.2" | ||
}, | ||
@@ -29,0 +28,0 @@ "devDependencies": { |
@@ -1,10 +0,18 @@ | ||
# cypher-stream | ||
# cypher-stream [![NPM version](https://badge.fury.io/js/cypher-stream.png)](http://badge.fury.io/js/cypher-stream) [![devDependency Status](https://david-dm.org/brian-gates/cypher-stream.png?theme=shields.io)](https://david-dm.org/brian-gates/cypher-stream.png#info=devDependencies) | ||
Streams cypher query results as easy to manage objects. | ||
Neo4j cypher queries as node object streams. | ||
The majority of magic happens in the deserializer, which can be found here: | ||
https://github.com/brian-gates/neo4j-stream-deserializer | ||
## Installation | ||
``` | ||
npm install cypher-stream | ||
``` | ||
## Basic usage | ||
``` js | ||
var neo4j_cypher_stream = require('cypher-stream'); | ||
var cypher = neo4j_cypher_stream('http://localhost:7474/db/data/cypher'); | ||
var cypher = require('cypher-stream')('http://localhost:7474'); | ||
@@ -20,1 +28,19 @@ cypher('match (user:User) return user') | ||
``` | ||
## Handling errors | ||
``` js | ||
var cypher = require('cypher-stream')('http://localhost:7474'); | ||
cypher('invalid query') | ||
.on('data', function (data){ | ||
console.log(data); // never called | ||
}) | ||
.on('error', function (error) { | ||
console.log(error.statusCode); // 400 | ||
}) | ||
.on('end', function() { | ||
console.log('all done'); | ||
}) | ||
; | ||
}); | ||
``` |
@@ -1,10 +0,19 @@ | ||
var neo4j_cypher_stream = require('../index'); | ||
var should = require('should'); | ||
var cypher = neo4j_cypher_stream('http://localhost:7474/db/data/cypher'); | ||
var cypher = require('../index')('http://localhost:7474'); | ||
describe('Cypher stream', function () { | ||
before(function (done){ | ||
cypher('FOREACH (x IN range(1,10) | CREATE(:Test {test: true}))') | ||
.on('end', done) | ||
.resume(); | ||
}); | ||
after(function (done){ | ||
cypher('MATCH (n:Test) DELETE n') | ||
.on('end', done) | ||
.resume(); | ||
}); | ||
it('it works', function (done) { | ||
it('works', function (done) { | ||
var results = 0; | ||
cypher('match (n {test: true}) return n limit 10') | ||
cypher('match (n:Test) return n limit 10') | ||
.on('data', function (result){ | ||
@@ -21,2 +30,19 @@ results++; | ||
it('handles errors', function (done) { | ||
var errored = false; | ||
cypher('invalid query') | ||
.on('data', function (data){ | ||
console.log(data); | ||
}) | ||
.on('error', function (error) { | ||
errored = true; | ||
error.statusCode.should.eql(400); | ||
}) | ||
.on('end', function() { | ||
errored.should.be.true; | ||
done(); | ||
}) | ||
; | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
15755
1
7
82
45
0
+ Addedoboe@~1.12.2
+ Addedclarinet@0.8.1(transitive)
+ Addedoboe@1.12.4(transitive)
- Removedneo4j-stream-deserializer@git://github.com/brian-gates/neo4j-stream-deserializer.git
- Removedrequest@~2.33.0
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedmime@1.2.11(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.33.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtldts@6.1.65(transitive)
- Removedtldts-core@6.1.65(transitive)
- Removedtough-cookie@5.0.0(transitive)
- Removedtunnel-agent@0.3.0(transitive)