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

cypher-stream

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypher-stream - npm Package Compare versions

Comparing version 1.0.2-alpha to 1.0.2

15

index.js

@@ -1,2 +0,1 @@

'use strict';
var CypherStream = require('./CypherStream');

@@ -15,5 +14,7 @@ var neo4j = require('neo4j-driver').v1;

var notNil = compose(not, isNil);
var notNil = compose(not, isNil);
// (user, pass) => auth || undefined
/**
* user -> pass -> auth | undefined
*/
var auth = cond([

@@ -24,6 +25,5 @@ [unapply(all(notNil)), neo4j.auth.basic ],

module.exports = function Connection(url, options) {
options = options || {};
module.exports = function Connection(url, username, password) {
var driver = neo4j.driver(url || 'bolt://localhost', auth(options.username, options.password));
var driver = neo4j.driver(url || 'bolt://localhost', auth(username, password));

@@ -45,3 +45,6 @@ var factory = function CypherStreamFactory(statement, parameters, options) {

factory.driver = driver;
factory.neo4j = neo4j;
return factory;
};

8

package.json
{
"name": "cypher-stream",
"version": "1.0.2-alpha",
"version": "1.0.2",
"description": "Streams cypher query results in a clean format",
"main": "index.js",
"scripts": {
"test": "make test"
"test": "mocha"
},

@@ -26,3 +26,3 @@ "repository": {

"highland": "^2.9.0",
"neo4j-driver": "^1.0.3",
"neo4j-driver": "^1.4.0",
"ramda": "^0.22.1"

@@ -33,3 +33,3 @@ },

"mocha-lcov-reporter": "1.2.0",
"mocha": "~3.0.2",
"mocha": "~3.2.0",
"should": "~11.1.0",

@@ -36,0 +36,0 @@ "istanbul": "^0.4.4"

# cypher-stream
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/brian-gates/cypher-stream?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/brian-gates/cypher-stream.png?branch=master)](https://travis-ci.org/brian-gates/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) [![Coverage Status](https://coveralls.io/repos/brian-gates/cypher-stream/badge.png?branch=coverage)](https://coveralls.io/r/brian-gates/cypher-stream)
[![Build Status](https://travis-ci.org/codex-digital/cypher-stream.svg?branch=master)](https://travis-ci.org/codex-digital/cypher-stream)
[![devDependency Status](https://david-dm.org/codex-digital/cypher-stream.png?theme=shields.io)](https://david-dm.org/codex-digital/cypher-stream.png#info=devDependencies)
[![NPM version](https://badge.fury.io/js/cypher-stream.png)](http://badge.fury.io/js/cypher-stream)
[![Coverage Status](https://coveralls.io/repos/github/codex-digital/cypher-stream/badge.svg?branch=master)](https://coveralls.io/github/codex-digital/cypher-stream?branch=master)
[![Slack Status](https://codex-community-slackin.herokuapp.com/badge.svg)](https://codex-community-slackin.herokuapp.com)
Neo4j cypher queries as node object streams.
## 1.0.0-alpha
1.0.0-alpha is Powered by Bolt™. Updated documentation is forthcoming. For the brave, check the source, tests, and go wild.
The API is largely unchanged, with the exception of authentication and some configuration options which no longer make sense in the Bolt world (i.e. http headers).
Performance should be significantly improved, given that the library no longer has to stream-parse HTTP JSON responses.
TODO:
* Documentation / Migration guide
* Facilitate access to underlying Neo4j objects
* Benchmark
## Installation

@@ -26,8 +15,2 @@ ```

Or, for Bolt
```
npm install cypher-stream@1.0.0-alpha
```
## Basic usage

@@ -54,16 +37,20 @@

var errored = false;
cypher('invalid query')
.on('error', function (error) {
cypher('invalid query')
.on('error', error => {
errored = true;
String(error).should.equal('Error: Query failure: Invalid input \'i\': expected SingleStatement (line 1, column 1)\n"invalid query"\n ^');
error.neo4j.exception.should.equal('SyntaxException');
error.neo4j.stacktrace.should.be.an.array;
error.neo4j.statusCode.should.equal(400);
should.equal(
error.code,
'Neo.ClientError.Statement.SyntaxError'
);
should.equal(
error.message,
'Invalid input \'i\': expected <init> (line 1, column 1 (offset: 0))\n"invalid query"\n ^'
);
})
.on('end', function() {
errored.should.be.true;
.on('end', () => {
should.equal(true, errored);
done();
})
.resume() // need to manually start it since we have no on('data')
;
.resume()
;
});

@@ -76,3 +63,3 @@

Transactions are duplex streams that allow you to write query statements then commit or roll back the written queries.
Transactions are duplex streams that allow you to write query statements and read the results.

@@ -93,3 +80,3 @@ Transactions have three methods: `write`, `commit`, and `rollback`, which add queries and commit or rollback the queue respectively.

A `query_statement` can either be a string or a query statement object. A query statement object consists of a `statement` property and an optional `parameters` property. Additionally, you can pass an array of either.
A `query_statement` can be a string or a query statement object. A query statement object consists of a `statement` property and an optional `parameters` property. Additionally, you can pass an array of either.

@@ -100,4 +87,7 @@ The following are all valid options:

var transaction = cypher.transaction();
transaction.write('match (n:User) return n');
transaction.write({ statement: 'match (n:User) return n' });
transaction.write({

@@ -107,2 +97,3 @@ statement : 'match (n:User) where n.first_name = {first_name} return n',

});
transaction.write([

@@ -124,6 +115,7 @@ {

Alternatively, a query statement may also contain a `commit` or `rollback` property instead of calling `commit()` or `rollback()` directly.
Alternatively, a query statement may contain a `commit` or `rollback` property.
``` js
transaction.write({ statement: 'match (n:User) return n', commit: true });
transaction.write({

@@ -146,2 +138,3 @@ statement : 'match (n:User) where n.first_name = {first_name} return n',

var query = 'match (n:Test) return n limit 2';
function callback(stream) {

@@ -159,4 +152,7 @@ stream

}
var statement = { statement: query, callback: callback };
cypher([ statement, statement ]).on('end', function () {
cypher([ statement, statement ])
.on('end', function () {
calls.should.equal(2);

@@ -166,3 +162,4 @@ ended.should.equal(2);

done();
}).resume();
})
.resume();
```

@@ -175,2 +172,3 @@

var query = 'match (n:Test) return n limit 2';
function callback(stream) {

@@ -188,8 +186,14 @@ stream

}
var statement = { statement: query, callback: callback };
var transaction = cypher.transaction();
transaction.write(statement);
transaction.write(statement);
transaction.commit();
transaction.resume();
transaction.on('end', function() {

@@ -202,1 +206,9 @@ calls.should.equal(2);

```
## Unsafe Integers
Unsafe integers* are returned as strings. If your system deals with particularly large or small numbers, this will require special handling.
See "[A note on numbers and the Integer type](https://github.com/neo4j/neo4j-javascript-driver/#a-note-on-numbers-and-the-integer-type)" on the neo4j-javascript-driver README for more information.
\* Unsafe integers are any integers greater than Number.MAX_SAFE_INTEGER or less than Number.MIN_SAFE_INTEGER.

@@ -13,3 +13,3 @@ 'use strict';

before(function(done) {
// Travis CI is slow. Give him more time.
// Travis CI is slow. Give more time.
if (process.env.TRAVIS_CI) {

@@ -30,2 +30,50 @@ this.timeout(5000);

it('exposes base Neo4j Node and Relationship for external comparisons', () => {
cypher.neo4j.types.should.have.properties('Node', 'Relationship');
});
describe('numbers', () => {
it('returns integer for max safe', done =>
cypher(`return ${Number.MAX_SAFE_INTEGER} as number`)
.on('data', result => {
result.number.should.eql(Number.MAX_SAFE_INTEGER);
})
.on('error', shouldNotError)
.on('end', done)
);
it('returns integer for min safe', done =>
cypher(`return ${Number.MIN_SAFE_INTEGER} as number`)
.on('data', result => {
result.number.should.be.a.Number();
result.number.should.eql(Number.MIN_SAFE_INTEGER);
})
.on('error', shouldNotError)
.on('end', done)
);
it('returns strings for > max safe', done =>
cypher(`return ${Number.MAX_SAFE_INTEGER+1} as number`)
.on('data', result => {
result.number.should.be.a.String();
result.number.should.eql(String(Number.MAX_SAFE_INTEGER+1))
})
.on('error', shouldNotError)
.on('end', done)
);
it('returns strings for < min safe', done =>
cypher(`return ${Number.MIN_SAFE_INTEGER-1} as number`)
.on('data', result => {
result.number.should.be.a.String();
result.number.should.eql(String(Number.MIN_SAFE_INTEGER-1))
})
.on('error', shouldNotError)
.on('end', done)
);
});
it('works', done => {

@@ -65,3 +113,3 @@ var results = 0;

})
.resume() // need to manually start it since we have no on('data')
.resume()
;

@@ -201,3 +249,11 @@ });

it('converts properties of Nodes to native', done => {
cypher('create (n { foo: 1 }) return n ')
.on('data', result => result.should.eql({
n: { foo: 1 }
}))
.on('error', shouldNotError)
.on('end', done)
;
});
});

@@ -333,3 +333,3 @@ 'use strict';

it.only('can return Neo4j data types', done => {
it('can return Neo4j data types', done => {
var tx = cypher.transaction({ returnType: 'neo4j' });

@@ -336,0 +336,0 @@

@@ -27,5 +27,5 @@ 'use strict';

[isNil, identity],
[is(neo4j.types.Node), prop('properties')],
[is(neo4j.types.Node), x => compose(toNative, prop('properties'))(x)],
[is(neo4j.types.Relationship), prop('properties')],
[neo4j.isInt, invoker(0, 'toInt')],
[neo4j.isInt, x => x.inSafeRange() ? x.toNumber() : x.toString()],
[isArrayLike, x => map(toNative, x)],

@@ -37,2 +37,2 @@ [isRecord, x => compose(toNative, recordToNative)(x)],

module.exports = toNative;
module.exports = toNative;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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