gremlin-client
Advanced tools
Comparing version 0.3.1 to 1.0.0
@@ -0,3 +1,8 @@ | ||
'use strict'; | ||
var gulp = require('gulp'); | ||
var browserify = require('gulp-browserify'); | ||
var browserify = require('browserify'); | ||
var babelify = require('babelify'); | ||
var source = require('vinyl-source-stream'); | ||
var buffer = require('gulp-buffer'); | ||
var uglify = require('gulp-uglify'); | ||
@@ -20,21 +25,32 @@ var size = require('gulp-size'); | ||
var bundler; | ||
function getBundler() { | ||
if (!bundler) { | ||
bundler = browserify('./index.js', { | ||
debug: true, | ||
standalone: 'gremlin' | ||
}); | ||
} | ||
return bundler; | ||
} | ||
gulp.task('build', function() { | ||
gulp.src('index.js') | ||
.pipe(browserify({ | ||
debug: true, | ||
standalone: 'gremlin' | ||
})) | ||
.pipe(rename('gremlin.js')) | ||
.pipe(gulp.dest('./')) | ||
.pipe(size({ showFiles: true })) | ||
// Minified version | ||
.pipe(uglify()) | ||
.pipe(rename('gremlin.min.js')) | ||
.pipe(gulp.dest('./')) | ||
.pipe(size({ showFiles: true })); | ||
return getBundler() | ||
.transform(babelify) | ||
.bundle() | ||
.on('error', function(err) { console.log('Error: ' + err.message); }) | ||
.pipe(source('./gremlin.js')) | ||
.pipe(gulp.dest('./')) | ||
.pipe(buffer()) | ||
.pipe(size({ showFiles: true })) | ||
.pipe(uglify()) | ||
.pipe(rename('gremlin.min.js')) | ||
.pipe(size({ showFiles: true })) | ||
.pipe(gulp.dest('./')); | ||
}); | ||
gulp.task('test-node', function() { | ||
require('chai').should(); | ||
gulp.task('test', ['test:node', 'test:browsers']); | ||
gulp.task('test:node', function() { | ||
return gulp.src('test/**/*') | ||
@@ -48,3 +64,3 @@ .pipe(mocha({ | ||
gulp.task('test-browsers', function(done) { | ||
gulp.task('test:browsers', function(done) { | ||
var karmaCommonConf = { | ||
@@ -74,2 +90,2 @@ browsers: ['Chrome', 'Firefox', 'Safari'], | ||
gulp.task('dev', ['test-browsers', 'test-node', 'watch']); | ||
gulp.task('dev', ['test', 'watch']); |
{ | ||
"name": "gremlin-client", | ||
"version": "0.3.1", | ||
"version": "1.0.0", | ||
"description": "JavaScript client for TinkerPop3 Gremlin Server", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"author": "Jean-Baptiste Musso <jbmusso+github@gmail.com>", | ||
"license": "Apache", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -31,16 +31,18 @@ "url": "https://github.com/gulthor/gremlin-client/issues" | ||
"lodash.defaults": "^2.4.1", | ||
"lodash.isarray": "^3.0.0", | ||
"readable-stream": "^1.0.31", | ||
"ws": "^0.4.32" | ||
"ws": "^0.7.1" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^4.0.0", | ||
"chai": "^1.9.1", | ||
"babelify": "^5.0.4", | ||
"browserify": "^9.0.3", | ||
"chai": "^2.1.1", | ||
"finalhandler": "^0.1.0", | ||
"gulp": "^3.8.8", | ||
"gulp-browserify": "^0.5.0", | ||
"gulp-mocha": "^1.1.0", | ||
"gulp-buffer": "0.0.2", | ||
"gulp-mocha": "^2.0.0", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-size": "^1.0.0", | ||
"gulp-uglify": "^0.3.1", | ||
"karma": "^0.12.22", | ||
"karma": "^0.12.31", | ||
"karma-browserify": "^0.2.1", | ||
@@ -50,8 +52,9 @@ "karma-chai": "^0.1.0", | ||
"karma-firefox-launcher": "^0.1.3", | ||
"karma-mocha": "^0.1.9", | ||
"karma-mocha": "^0.1.10", | ||
"karma-safari-launcher": "^0.1.1", | ||
"mocha": "^1.21.4", | ||
"serve-static": "^1.5.3", | ||
"vinyl-source-stream": "^1.0.0", | ||
"yargs": "^1.3.1" | ||
} | ||
} |
@@ -224,1 +224,5 @@ gremlin-client | ||
* performance optimization | ||
## License | ||
MIT(LICENSE) |
@@ -6,3 +6,2 @@ /*jslint -W079 */ | ||
var inherits = require('util').inherits; | ||
var domain = require('domain'); | ||
@@ -18,2 +17,5 @@ var WebSocket = require('ws'); | ||
var executeHandler = require('./executehandler'); | ||
function GremlinClient(port, host, options) { | ||
@@ -28,3 +30,4 @@ this.port = port || 8182; | ||
processor: '', | ||
accept: 'application/json' | ||
accept: 'application/json', | ||
executeHandler: executeHandler | ||
}); | ||
@@ -68,15 +71,18 @@ | ||
var command = this.commands[rawMessage.requestId]; | ||
var stream = command.stream; | ||
var statusCode = rawMessage.status.code; | ||
var messageStream = command.messageStream; | ||
switch (statusCode) { | ||
case 200: | ||
stream.push(rawMessage); | ||
break; | ||
case 299: | ||
case 200: // SUCCESS | ||
delete this.commands[rawMessage.requestId]; // TODO: optimize performance | ||
stream.push(null); | ||
messageStream.push(rawMessage); | ||
messageStream.push(null); | ||
break; | ||
case 204: // NO_CONTENT | ||
break; | ||
case 206: // PARTIAL_CONTENT | ||
messageStream.push(rawMessage); | ||
break; | ||
default: | ||
stream.emit('error', new Error(rawMessage.status.message + ' (Error '+ statusCode +')')); | ||
messageStream.emit('error', new Error(rawMessage.status.message + ' (Error '+ statusCode +')')); | ||
break; | ||
@@ -135,3 +141,3 @@ } | ||
command = commands[key]; | ||
command.stream.emit('error', error); | ||
command.messageStream.emit('error', error); | ||
}); | ||
@@ -154,3 +160,3 @@ }; | ||
var stream = new MessageStream({ objectMode: true }); | ||
var messageStream = new MessageStream({ objectMode: true }); | ||
var guid = Guid.create().value; | ||
@@ -173,3 +179,3 @@ var args = _.defaults(message && message.args || {}, { | ||
message: message, | ||
stream: stream | ||
messageStream: messageStream | ||
}; | ||
@@ -179,8 +185,6 @@ | ||
// Assume that people want to use the 'session' processor unless specified | ||
command.message.processor = this.options.processor || 'session'; | ||
command.message.processor = message.processor || this.options.processor || 'session'; | ||
command.message.args.session = this.sessionId; | ||
} | ||
this.sendCommand(command); //todo improve for streams | ||
return command; | ||
@@ -229,23 +233,10 @@ }; | ||
var _ = highland; | ||
var messageStream = this.messageStream(script, bindings, message); | ||
// Handling all stream errors | ||
// TO CHECK: errors handling could be improved | ||
// See https://groups.google.com/d/msg/nodejs/lJYT9hZxFu0/L59CFbqWGyYJ | ||
var d = domain.create(); | ||
d.on('error', function(err) { | ||
callback(err.message); | ||
}); | ||
// for an example using domains | ||
var executeHandler = this.options.executeHandler; | ||
var messageStream = this.messageStream(script, bindings, message); | ||
d.run(function() { | ||
_(messageStream) | ||
.map(function(message) { | ||
return message.result.data; | ||
}) | ||
.sequence() | ||
.toArray(function(results) { | ||
callback(null, results); | ||
}); | ||
}); | ||
executeHandler(messageStream, callback); | ||
}; | ||
@@ -281,2 +272,6 @@ | ||
messageStream.on('error', function(e) { | ||
stream.emit('error', new Error(e)); | ||
}); | ||
return stream; | ||
@@ -303,3 +298,5 @@ }; | ||
return command.stream; | ||
this.sendCommand(command); //todo improve for streams | ||
return command.messageStream; | ||
}; | ||
@@ -306,0 +303,0 @@ |
/*jshint -W030 */ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -8,3 +9,3 @@ | ||
client.execute('g.v(x)', { x: 1 }, function(err, result) { | ||
client.execute('g.V(x)', { x: 1 }, function(err, result) { | ||
(err === null).should.be.true; | ||
@@ -18,3 +19,3 @@ result.length.should.equal(1); | ||
var client = gremlin.createClient(); | ||
var stream = client.stream('g.v(x)', { x: 1 }); | ||
var stream = client.stream('g.V(x)', { x: 1 }); | ||
@@ -30,6 +31,9 @@ stream.on('data', function(result) { | ||
it('should give an error with erroneous binding name in .exec', function(done) { | ||
it.skip('should give an error with reserved binding name in .exec', function(done) { | ||
var client = gremlin.createClient(); | ||
client.execute('g.v(id)', { id: 1 }, function(err, result) { | ||
// This is supposed to throw a NoSuchElementException in Gremlin Server: | ||
// --> "The vertex with id id of type does not exist in the graph" | ||
// id is a reserved (imported) variable and can't be used in a script | ||
client.execute('g.V(id)', { id: 1 }, function(err, result) { | ||
(err !== null).should.be.true; | ||
@@ -36,0 +40,0 @@ (result === undefined).should.be.true; |
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -15,10 +16,21 @@ | ||
it('should allow setting a custom processor', function() { | ||
var client = gremlin.createClient({ session: true, processor: 'custom' }); | ||
var customProcessor = 'shouldNotBeIgnored'; | ||
var client = gremlin.createClient({ session: true, processor: customProcessor }); | ||
var command = client.buildCommand(); | ||
command.message.processor.should.equal('custom'); | ||
command.message.processor.should.equal(customProcessor); | ||
(command.message.args.session === undefined).should.not.be.true; | ||
}); | ||
it('should allow setting a per-message processor when using sessions', function() { | ||
var customProcessor = 'shouldNotBeIgnored'; | ||
var client = gremlin.createClient(8182, 'localhost', { session: true }); | ||
var command = client.buildCommand(null, null, { processor: customProcessor }); | ||
command.message.processor.should.equal(customProcessor); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -9,9 +10,8 @@ | ||
client.host.should.equal('localhost'); | ||
client.options.should.eql({ | ||
language: 'gremlin-groovy', | ||
session: false, | ||
op: 'eval', | ||
processor: '', | ||
accept: 'application/json' | ||
}); | ||
client.options.language.should.eql('gremlin-groovy'); | ||
client.options.session.should.eql(false); | ||
client.options.op.should.eql('eval'); | ||
client.options.processor.should.eql(''); | ||
client.options.accept.should.eql('application/json'); | ||
}); | ||
@@ -58,3 +58,3 @@ | ||
var s = client.stream('g.v(1)', null, { op: 'eval' }); | ||
var s = client.stream('g.V(1)', null, { op: 'eval' }); | ||
@@ -61,0 +61,0 @@ s.on('data', function(result) { |
/*jshint -W030 */ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -38,3 +39,3 @@ | ||
client.execute('g.v(1)', null, { args: { language: 'nashorn' }}, function(err, result) { | ||
client.execute('g.V(1)', null, { args: { language: 'nashorn' }}, function(err, result) { | ||
(err === null).should.be.true; | ||
@@ -49,3 +50,3 @@ result.length.should.equal(1); | ||
client.execute('g.v(x)', { x: 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; | ||
@@ -56,2 +57,13 @@ result.length.should.equal(1); | ||
}); | ||
it('should handle errors', function(done) { | ||
var client = gremlin.createClient(); | ||
// pass a buggy script (missing parenthese) | ||
var script = 'g.V('; | ||
client.execute(script, function(err, result) { | ||
(err === null).should.be.false; | ||
done(); | ||
}); | ||
}); | ||
}); |
/*jshint -W030 */ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -6,6 +7,16 @@ | ||
it('should process raw JavaScript strings', function(done) { | ||
var client = gremlin.createClient({ language: 'nashorn' }); | ||
var client = gremlin.createClient(); | ||
var script = 'g.V()'; | ||
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); | ||
done(); | ||
}); | ||
}); | ||
it.skip('should process raw JavaScript with nashorn disambiguation syntax', function(done) { | ||
var client = gremlin.createClient(); | ||
var script = 'g.V()["filter(Predicate)"](function(it) { return it.get().property("lang").orElse("") == "java" });'; | ||
client.execute(script, function(err, result) { | ||
@@ -19,4 +30,3 @@ (err === null).should.be.true; | ||
it('should process JavaScript functions', function(done) { | ||
var client = gremlin.createClient({ language: 'nashorn' }); | ||
var client = gremlin.createClient(); | ||
var script = function() { | ||
@@ -34,4 +44,3 @@ g.V(); | ||
it('should process inlined JavaScript functions', function(done) { | ||
var client = gremlin.createClient({ language: 'nashorn' }); | ||
var client = gremlin.createClient(); | ||
client.execute(function() { g.V(); }, function(err, result) { | ||
@@ -38,0 +47,0 @@ (err === null).should.be.true; |
@@ -10,3 +10,3 @@ var gremlin = require('../'); | ||
s.on('data', function(message) { | ||
message.status.code.should.eql(200); | ||
message.status.code.should.be.within(200, 206); | ||
message.result.data.should.be.an('array'); | ||
@@ -13,0 +13,0 @@ }); |
@@ -5,3 +5,3 @@ /*jshint -W030 */ | ||
describe('Nashorn syntax', function() { | ||
it('should handle .localeCompare() as replacement for <=> operator', function() { | ||
it.skip('should handle .localeCompare() as replacement for <=> operator', function() { | ||
var client = gremlin.createClient({ language: 'nashorn' }); | ||
@@ -8,0 +8,0 @@ var script = function() { |
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
var gremlin = require('../'); | ||
@@ -7,3 +8,2 @@ | ||
var client = gremlin.createClient(); | ||
var s = client.stream(function() { g.V(); }); | ||
@@ -25,5 +25,4 @@ | ||
var client = gremlin.createClient(); | ||
var s = client.stream('g.V(x)', { x: 1 }); | ||
var s = client.stream('g.v(x)', { x: 1 }); | ||
s.on('data', function(result) { | ||
@@ -40,5 +39,4 @@ result.id.should.equal(1); | ||
var client = gremlin.createClient(); | ||
var s = client.stream('g.V(1)', null, { args: { language: 'nashorn' }}); | ||
var s = client.stream('g.v(1)', null, { args: { language: 'nashorn' }}); | ||
s.on('data', function(result) { | ||
@@ -55,5 +53,4 @@ result.id.should.equal(1); | ||
var client = gremlin.createClient(); | ||
var s = client.stream('g.V(id)', { id : 1 }, { args: { language: 'nashorn' }}); | ||
var s = client.stream('g.v(id)', { id : 1 }, { args: { language: 'nashorn' }}); | ||
s.on('data', function(result) { | ||
@@ -67,2 +64,14 @@ result.id.should.equal(1); | ||
}); | ||
it('should handle errors', function(done) { | ||
var client = gremlin.createClient(); | ||
// pass a buggy script (missing parenthese) | ||
var script = 'g.V('; | ||
var s = client.stream(script); | ||
s.on('error', function(err) { | ||
(err === null).should.be.false; | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
927122
30
0
12137
2
228
6
6
21
1
+ Addedlodash.isarray@^3.0.0
+ Addedbindings@1.2.1(transitive)
+ Addedbufferutil@1.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addednan@1.8.4(transitive)
+ Addedultron@1.0.2(transitive)
+ Addedutf-8-validate@1.1.0(transitive)
+ Addedws@0.7.2(transitive)
- Removedcommander@2.1.0(transitive)
- Removednan@1.0.0(transitive)
- Removedtinycolor@0.0.1(transitive)
- Removedws@0.4.32(transitive)
Updatedws@^0.7.1