New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gremlin-client

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gremlin-client - npm Package Compare versions

Comparing version

to
0.3.1

test/bindings.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## 0.3.1
- Handle new response format
- Better error handling in callback mode
- Add support for sessions with arbitrary processors
## 0.3.0

@@ -2,0 +7,0 @@ - `client.stream()` now re-emits one distinct `data` event per result fetched instead of emiting an array of results

2

Gulpfile.js

@@ -8,2 +8,3 @@ var gulp = require('gulp');

var karma = require('karma').server;
var args = require('yargs').argv;

@@ -42,2 +43,3 @@

reporter: 'spec',
bail: !!args.bail
}))

@@ -44,0 +46,0 @@ .on('error', printError);

9

package.json
{
"name": "gremlin-client",
"version": "0.3.0",
"version": "0.3.1",
"description": "JavaScript client for TinkerPop3 Gremlin Server",

@@ -37,5 +37,5 @@ "main": "index.js",

"finalhandler": "^0.1.0",
"gulp": "^3.8.7",
"gulp": "^3.8.8",
"gulp-browserify": "^0.5.0",
"gulp-mocha": "^1.0.0",
"gulp-mocha": "^1.1.0",
"gulp-rename": "^1.2.0",

@@ -52,4 +52,5 @@ "gulp-size": "^1.0.0",

"mocha": "^1.21.4",
"serve-static": "^1.5.3"
"serve-static": "^1.5.3",
"yargs": "^1.3.1"
}
}

@@ -6,2 +6,3 @@ /*jslint -W079 */

var inherits = require('util').inherits;
var domain = require('domain');

@@ -63,15 +64,18 @@ var WebSocket = require('ws');

GremlinClient.prototype.handleMessage = function(event) {
var message = JSON.parse(event.data || event); // Node.js || Browser API
var command = this.commands[message.requestId];
var rawMessage = JSON.parse(event.data || event); // Node.js || Browser API
var command = this.commands[rawMessage.requestId];
var stream = command.stream;
var statusCode = rawMessage.status.code;
switch (message.code) {
switch (statusCode) {
case 200:
stream.push(message);
stream.push(rawMessage);
break;
case 299:
message.result = command.result;
delete this.commands[message.requestId]; // TODO: optimize performance
delete this.commands[rawMessage.requestId]; // TODO: optimize performance
stream.push(null);
break;
default:
stream.emit('error', new Error(rawMessage.status.message + ' (Error '+ statusCode +')'));
break;
}

@@ -169,3 +173,4 @@ };

if (this.useSession) {
command.message.processor = 'session';
// Assume that people want to use the 'session' processor unless specified
command.message.processor = this.options.processor || 'session';
command.message.args.session = this.sessionId;

@@ -219,19 +224,22 @@ }

var stream = this.messageStream(script, bindings, message);
var results = [];
var _ = highland;
// Using a Highland.js stream here because it's not publicly exposed
stream = highland(stream)
.map(function(message) { return message.result; });
stream.on('data', function(data) {
results = results.concat(data);
// Handling all stream errors
// See https://groups.google.com/d/msg/nodejs/lJYT9hZxFu0/L59CFbqWGyYJ
var d = domain.create();
d.on('error', function(err) {
callback(err.message);
});
stream.on('end', function() {
callback(null, results);
});
var messageStream = this.messageStream(script, bindings, message);
stream.on('error', function(error) {
callback(new Error('Stream error: ' + error));
d.run(function() {
_(messageStream)
.map(function(message) {
return message.result.data;
})
.sequence()
.toArray(function(results) {
callback(null, results);
});
});

@@ -261,3 +269,3 @@ };

_.map(function(message) {
return message.result;
return message.result.data;
}),

@@ -264,0 +272,0 @@ _.sequence()

/*jshint -W030 */
var gremlin = require('../');
describe('.exec()', function() {
describe('.execute()', function() {
it('should return a result and a response', function(done) {

@@ -35,12 +35,2 @@ var client = gremlin.createClient();

it('should handle bound parameters', function(done) {
var client = gremlin.createClient();
client.execute('g.v(id)', { id: 1 }, function(err, result) {
(err === null).should.be.true;
result.length.should.equal(1);
done();
});
});
it('should handle optional args', function(done) {

@@ -59,3 +49,3 @@ var client = gremlin.createClient();

client.execute('g.v(id)', { id : 1 }, { args: { language: 'nashorn' }}, function(err, result) {
client.execute('g.v(x)', { x: 1 }, { args: { language: 'nashorn' }}, function(err, result) {
(err === null).should.be.true;

@@ -62,0 +52,0 @@ result.length.should.equal(1);

@@ -8,5 +8,7 @@ /*jshint -W030 */

client.execute('g.V().filter(function(it) { return it.get().value("name") !== "gremlin" });', function(err, result) {
var script = 'g.V()["filter(SPredicate)"](function(it) { return it.get().property("lang").orElse("") == "java" });';
client.execute(script, function(err, result) {
(err === null).should.be.true;
result.length.should.equal(6);
result.length.should.equal(2);
done();

@@ -13,0 +15,0 @@ });

@@ -10,4 +10,4 @@ var gremlin = require('../');

s.on('data', function(message) {
message.code.should.eql(200);
message.result.should.be.an('array');
message.status.code.should.eql(200);
message.result.data.should.be.an('array');
});

@@ -14,0 +14,0 @@

@@ -5,3 +5,3 @@ /*jshint -W030 */

describe('Nashorn syntax', function() {
it('should handle .localeCompare() in lieu of <=> operator', function() {
it('should handle .localeCompare() as replacement for <=> operator', function() {
var client = gremlin.createClient({ language: 'nashorn' });

@@ -16,6 +16,6 @@ var script = function() {

(err === null).should.be.true;
result[0].properties.name.should.equal('josh');
result[5].properties.name.should.equal('vadas');
result[0].properties.name[0].value.should.equal('josh');
result[5].properties.name[0].value.should.equal('vadas');
});
});
});

@@ -6,3 +6,3 @@ var gremlin = require('../');

it('should emit `data` events with a chunk of results and the raw response', function(done) {
var client = gremlin.createClient({ language: 'nashorn' });
var client = gremlin.createClient();

@@ -26,6 +26,6 @@ var s = client.stream(function() { g.V(); });

var s = client.stream('g.v(id)', { id: 1 });
var s = client.stream('g.v(x)', { x: 1 });
s.on('data', function(result) {
result.should.be.an('object');
result.id.should.equal(1);
});

@@ -44,3 +44,3 @@

s.on('data', function(result) {
result.should.be.an('object');
result.id.should.equal(1);
});

@@ -59,3 +59,3 @@

s.on('data', function(result) {
result.should.be.an('object');
result.id.should.equal(1);
});

@@ -62,0 +62,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display