0.0.1 • Published 10 years ago

neo4j-stream-deserializer v0.0.1

Weekly downloads
-
License
-
Repository
github
Last release
10 years ago

neo4j-stream-deserializer

Streams neo4j responses as formatted objects.

A typical neo4j response:

{"columns":["n"],"data":[[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4307/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4307/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4307/relationships/out","traverse":"http://localhost:7474/db/data/node/4307/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4307/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4307/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4307/relationships/all","self":"http://localhost:7474/db/data/node/4307","properties":"http://localhost:7474/db/data/node/4307/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4307/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4307/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4307/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4307/relationships","data":{"test":true,"uuid":"27d1b700-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4308/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4308/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4308/relationships/out","traverse":"http://localhost:7474/db/data/node/4308/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4308/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4308/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4308/relationships/all","self":"http://localhost:7474/db/data/node/4308","properties":"http://localhost:7474/db/data/node/4308/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4308/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4308/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4308/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4308/relationships","data":{"test":true,"uuid":"2ed844b0-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4309/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4309/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4309/relationships/out","traverse":"http://localhost:7474/db/data/node/4309/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4309/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4309/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4309/relationships/all","self":"http://localhost:7474/db/data/node/4309","properties":"http://localhost:7474/db/data/node/4309/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4309/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4309/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4309/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4309/relationships","data":{"test":true,"uuid":"36204830-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4310/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4310/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4310/relationships/out","traverse":"http://localhost:7474/db/data/node/4310/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4310/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4310/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4310/relationships/all","self":"http://localhost:7474/db/data/node/4310","properties":"http://localhost:7474/db/data/node/4310/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4310/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4310/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4310/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4310/relationships","data":{"test":true,"uuid":"3c4bdf30-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4311/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4311/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4311/relationships/out","traverse":"http://localhost:7474/db/data/node/4311/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4311/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4311/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4311/relationships/all","self":"http://localhost:7474/db/data/node/4311","properties":"http://localhost:7474/db/data/node/4311/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4311/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4311/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4311/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4311/relationships","data":{"test":true,"uuid":"43245800-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4312/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4312/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4312/relationships/out","traverse":"http://localhost:7474/db/data/node/4312/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4312/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4312/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4312/relationships/all","self":"http://localhost:7474/db/data/node/4312","properties":"http://localhost:7474/db/data/node/4312/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4312/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4312/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4312/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4312/relationships","data":{"test":true,"uuid":"4a41c910-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4313/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4313/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4313/relationships/out","traverse":"http://localhost:7474/db/data/node/4313/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4313/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4313/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4313/relationships/all","self":"http://localhost:7474/db/data/node/4313","properties":"http://localhost:7474/db/data/node/4313/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4313/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4313/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4313/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4313/relationships","data":{"test":true,"uuid":"50743de0-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4314/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4314/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4314/relationships/out","traverse":"http://localhost:7474/db/data/node/4314/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4314/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4314/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4314/relationships/all","self":"http://localhost:7474/db/data/node/4314","properties":"http://localhost:7474/db/data/node/4314/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4314/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4314/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4314/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4314/relationships","data":{"test":true,"uuid":"56d7fbe0-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4315/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4315/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4315/relationships/out","traverse":"http://localhost:7474/db/data/node/4315/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4315/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4315/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4315/relationships/all","self":"http://localhost:7474/db/data/node/4315","properties":"http://localhost:7474/db/data/node/4315/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4315/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4315/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4315/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4315/relationships","data":{"test":true,"uuid":"5df3bf40-88aa-11e3-9992-d7608d571cea"}}],[{"extensions":{},"paged_traverse":"http://localhost:7474/db/data/node/4316/paged/traverse/{returnType}{?pageSize,leaseTime}","labels":"http://localhost:7474/db/data/node/4316/labels","outgoing_relationships":"http://localhost:7474/db/data/node/4316/relationships/out","traverse":"http://localhost:7474/db/data/node/4316/traverse/{returnType}","all_typed_relationships":"http://localhost:7474/db/data/node/4316/relationships/all/{-list|&|types}","property":"http://localhost:7474/db/data/node/4316/properties/{key}","all_relationships":"http://localhost:7474/db/data/node/4316/relationships/all","self":"http://localhost:7474/db/data/node/4316","properties":"http://localhost:7474/db/data/node/4316/properties","outgoing_typed_relationships":"http://localhost:7474/db/data/node/4316/relationships/out/{-list|&|types}","incoming_relationships":"http://localhost:7474/db/data/node/4316/relationships/in","incoming_typed_relationships":"http://localhost:7474/db/data/node/4316/relationships/in/{-list|&|types}","create_relationship":"http://localhost:7474/db/data/node/4316/relationships","data":{"test":true,"uuid":"64217920-88aa-11e3-9992-d7608d571cea"}}]]}

Parsing a cypher request

var Neo4jStreamDeserializer = require('neo4j-stream-deserializer');
var request                 = require('request');

request.post({
    url     : 'http://localhost:7474/db/data/cypher',
    form    : { query: 'match (n:User) return n' },
    headers : { "X-Stream": true, "Accept": "application/json" }
  })
  .pipe(new Neo4jStreamDeserializer())
  .on('data', function (result){
    console.log(result.user);
  })
  .on('end', function() {
    console.log('all done');
  })
;

Reading from a file

var should                  = require("should");
var Neo4jStreamDeserializer = require('../index');
var fs                      = require('fs');

describe('Neo4j deserializer', function () {

  it('should be able to parse a file', function (done) {
    var results = 0;
    fs
      .createReadStream('./test/mock/neo4j_response.json')
      .pipe(new Neo4jStreamDeserializer())
      .on('data', function (result){
        results++;
        result.n.test.should.be.ok;
      })
      .on('end', function() {
        results.should.eql(10);
        done();
      })
    ;
  });
});