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

jubatus

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

jubatus - npm Package Compare versions

Comparing version 0.6.2 to 0.6.4

lib/debug.js

81

index.js
/*jslint node: true */
var assert = require('assert'),
util = require('util'),
validate = require('json-schema').validate,
api = require('./api'),
rpc = require('./lib/msgpack-rpc');
const assert = require('assert');
const util = require('util');
const validate = require('json-schema').validate;
const debug = require('./lib/debug')('jubatus-node-client');
const api = require('./api');
const rpc = require('./lib/msgpack-rpc');
exports.msgpack = require('msgpack-js');
const isProduct = process.env.NODE_ENV && (/production/).test(process.env.NODE_ENV);
var isDebugEnabled = process.env.NODE_DEBUG && (/jubatus/).test(process.env.NODE_DEBUG),
isProduct = process.env.NODE_ENV && (/production/).test(process.env.NODE_ENV),
debug = isDebugEnabled ? function (x) { console.error('JUBATUS:', x); } : function () {};
function toArray(args) {

@@ -26,15 +23,18 @@ return Array.prototype.slice.call(args);

function createConstructor(className) {
var constructor = function constructor(port = 9199, host = 'localhost', name = 'cluster', timeoutSeconds = 0) {
if (!(this instanceof constructor)) {
throw new Error(className + ' is constructor.');
}
var constructor = function constructor(options = 9199, ...args) {
if (!(this instanceof constructor)) { throw new Error(`${className} is constructor.`); }
const client = rpc.createClient(port, host, timeoutSeconds * 1000);
const rpcClient = options instanceof rpc.Client ? options : options.rpcClient;
const port = typeof options === 'number' ? options : (options.port || 9199);
const host = options.host || args[0] || 'localhost';
let name = options.name || args[1] || '';
const timeoutSeconds = options.timeoutSeconds || args[2] || 0;
const client = rpcClient || rpc.createClient(port, host, timeoutSeconds * 1000);
Object.defineProperty(this, 'client', {
get: function() { return client; }
get() { return client; }
});
Object.defineProperty(this, 'name', {
get: function() { return name; },
set: function(value) { name = value; }
get() { return name; },
set(value) { name = value; }
});

@@ -47,3 +47,3 @@ return this;

return this.client;
}
};

@@ -53,3 +53,3 @@ // This is not an RPC method.

return this.name;
}
};

@@ -59,26 +59,23 @@ // This is not an RPC method.

this.name = value;
}
};
return api[className].methods.map(method => {
debug(method);
var rpcName = method.id || method,
const { id: rpcName, properties: { args, 'return': returnType } } = method,
methodName = camelCase(rpcName),
properties = method.properties || {},
assertParams = !isProduct && properties.args ? params => {
debug({ params, args: properties.args });
var schema = properties.args,
result = validate(params, schema);
assertParams = isProduct ? () => {} : params => {
debug({ params, args });
const result = validate(params, args);
assert.ok(result.valid, util.format('%j', result.errors));
} : () => {},
assertReturn = !isProduct && properties.return ? returnValue => {
debug({ result: returnValue, 'return': properties.return });
var schema = properties.return,
result = validate(returnValue, schema);
},
assertReturn = isProduct ? () => {} : returnValue => {
debug({ returnValue, returnType });
const result = validate(returnValue, returnType);
assert.ok(result.valid, util.format('%j', result.errors));
} : () => {};
return [ rpcName, methodName, assertParams, assertReturn, properties ];
};
return [ rpcName, methodName, assertParams, assertReturn ];
})
.reduce((constructor, [ rpcName, methodName, assertParams, assertReturn, properties ]) => {
.reduce((constructor, [ rpcName, methodName, assertParams, assertReturn ]) => {
constructor.prototype[methodName] = function () {
var self = this,
const self = this,
client = self.getClient(),

@@ -90,7 +87,7 @@ params = toArray(arguments),

if (hasCallback) {
let callback = params.pop();
const callback = params.pop();
client.call(rpcName, params, (error, result, msgid) => {
if (error)
if (error) {
callback.call(self, new Error(`${ error } ${ result || '' }`), null, msgid);
else {
} else {
assertReturn(result);

@@ -103,5 +100,5 @@ callback.call(self, null, result, msgid);

client.call(rpcName, params, (error, result, msgid) => {
if (error)
reject(new Error(`${ error } ${ result || '' }`))
else {
if (error) {
reject(new Error(`${ error } ${ result || '' }`));
} else {
assertReturn(result);

@@ -108,0 +105,0 @@ resolve([ result, msgid ]);

@@ -1,3 +0,4 @@

var msgpack = require('msgpack-js'),
const msgpack = require('msgpack-js'),
Stream = require('msgpack').Stream,
debug = require('./debug')('jubatus-node-client:lib:msgpack-rpc'),
assert = require('assert'),

@@ -8,10 +9,7 @@ net = require('net'),

var isDebugEnabled = (process.env.NODE_DEBUG && /msgpack-rpc/.test(process.env.NODE_DEBUG)),
debug = isDebugEnabled ? function (x) { console.error('MSGPACK-RPC:', x); } : function () {};
var msgidGenerator = (function () {
var MAX = Math.pow(2, 32) - 1,
msgid = 0;
const msgidGenerator = (function () {
const MAX = Math.pow(2, 32) - 1;
let msgid = 0;
return {
next: function () {
next() {
return (msgid = (msgid < MAX ? msgid + 1 : 0));

@@ -27,13 +25,10 @@ }

var self = this,
let callbacks = {},
port = socket.remotePort,
host = socket.remoteAddress,
callbacks = {},
host = socket.remoteAddress;
const self = this,
receive = function receive(response) {
if (isDebugEnabled) { debug('received message: ' + util.inspect(response, false, null, true)); }
if (debug.enabled) { debug(`received message: ${ util.inspect(response, false, null, true) }`); }
var type = response.shift(),
msgid = response.shift(),
error = response.shift(),
result = response.shift(),
const [ type, msgid, error, result ] = response,
callback = (callbacks[msgid] || function () {});

@@ -45,5 +40,5 @@ callback.call(self, error, result, msgid);

send = function send(request) {
var buf = msgpack.encode(request);
const buf = msgpack.encode(request);
return socket.write(buf, function () {
if (isDebugEnabled) { debug('sent message: ' + util.inspect(request, false, null, true)); }
if (debug.enabled) { debug(`sent message: ${ util.inspect(request, false, null, true) }`); }
});

@@ -59,4 +54,4 @@ },

socket.on(eventName, function () {
debug('socket event [' + eventName + ']');
var args = [eventName].concat(Array.prototype.slice.call(arguments));
debug(`socket event [${ eventName }]`);
const args = [eventName].concat(Array.prototype.slice.call(arguments));
self.emit.apply(self, args);

@@ -69,3 +64,3 @@ });

});
debug({ socket: socket });
debug({ socket });

@@ -79,3 +74,3 @@ this.closed = socket.destroyed;

ready();
var msgid = msgidGenerator.next(),
const msgid = msgidGenerator.next(),
request = [0, msgid, method, [].concat(params)];

@@ -87,3 +82,3 @@ callbacks[msgid] = callback;

ready();
send([2, method, params]);
send([2, method, [].concat(params)]);
};

@@ -95,34 +90,28 @@ }

exports.createClient = function createClient(port, host, timeout) {
debug({ port: port, host: host, timeout: timeout });
var socket = net.connect(port, host || 'localhost');
socket.setTimeout(timeout || 0);
exports.createClient = function createClient(port = 9190, host = 'localhost', timeout = 0) {
debug({ port, host, timeout });
const socket = net.connect(port, host);
socket.setTimeout(timeout);
return new Client(socket);
};
function Server(server) {
assert(server instanceof net.Server, 'Illegal argument');
events.EventEmitter.call(this);
var self = this;
exports.createServer = function createServer(options, connectionListener) {
const server = net.createServer(options, connectionListener);
server.on('connection', function onConnection(socket) {
var stream = new Stream(socket).on('msg', function onMsg(request) {
var type = request.shift(),
msgid = request.shift(),
method = request.shift(),
params = request.shift(),
callback = function (error, result) {
var response = [1, msgid, error, [].concat(result)],
buf = msgpack.encode(response);
socket.write(buf);
};
self.emit(method, params, callback);
});
const stream = new Stream(socket).on('msg', function onMsg(request) {
debug(request);
if (request[0] === 0) {
const [ type, msgid, method, params ] = request;
const callback = (error, result) => {
const response = [ 1, msgid, error, [].concat(result) ];
socket.write(msgpack.encode(response));
};
server.emit(method, params, callback);
} else {
const [ type, method, params ] = request;
server.emit(method, params);
}
});
});
}
util.inherits(Server, events.EventEmitter);
exports.Server = Server;
return server;
};
{
"name": "jubatus",
"version": "0.6.2",
"version": "0.6.4",
"homepage": "https://github.com/naokikimura/jubatus-node-client",

@@ -17,3 +17,3 @@ "main": "./index.js",

"engines": {
"node" : ">=6.3.0",
"node": ">=6.3.0",
"jubatus": "~1.0.7"

@@ -30,8 +30,11 @@ },

"chai": "^4.1.2",
"codacy-coverage": "^2.0.3",
"debug": "^3.1.0",
"istanbul": "^0.4.5",
"mocha": "^5.0.0",
"mocha-lcov-reporter": "^1.3.0",
"portfinder": "^1.0.13"
},
"scripts": {
"test": "mocha"
"test": "istanbul cover ./node_modules/mocha/bin/_mocha"
},

@@ -38,0 +41,0 @@ "config": {

jubatus-node-client
===================
[![Build Status](https://travis-ci.org/naokikimura/jubatus-node-client.svg?branch=master)](https://travis-ci.org/naokikimura/jubatus-node-client) [![npm version](https://badge.fury.io/js/jubatus.svg)](https://badge.fury.io/js/jubatus)
[![Build Status](https://travis-ci.org/naokikimura/jubatus-node-client.svg?branch=master)](https://travis-ci.org/naokikimura/jubatus-node-client)
[![npm version](https://badge.fury.io/js/jubatus.svg)](https://badge.fury.io/js/jubatus)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5eaec4cefec543a5954dc61d5022f6c4)](https://www.codacy.com/app/n.kimura.cap/jubatus-node-client?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/jubatus-node-client&utm_campaign=badger)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/aa18bb3e6b284c4581068ca070060007)](https://www.codacy.com/app/n.kimura.cap/jubatus-node-client?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/jubatus-node-client&utm_campaign=Badge_Coverage)

@@ -6,0 +9,0 @@ Jubatus client for Node.js (unofficial)

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:anomaly');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'anomaly_config.json',
command = 'jubaanomaly',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaanomaly', config = 'anomaly_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.anomaly.client.Anomaly(port, 'localhost');

@@ -44,0 +17,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:bandit');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'bandit_config.json',
command = 'jubabandit',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubabandit', config = 'bandit_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.bandit.client.Bandit(port, 'localhost');

@@ -44,0 +17,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:burst');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'burst_config.json',
command = 'jubaburst',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaburst', config = 'burst_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.burst.client.Burst(port, 'localhost');

@@ -44,0 +17,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:classifier');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'classifier_config.json',
command = 'jubaclassifier',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaclassifier', config = 'classifier_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.classifier.client.Classifier(port, 'localhost');

@@ -56,5 +29,5 @@ done();

it('train', done => {
var datum = [ [ ["foo", "bar"] ], [ ["qux", 1.1] ] ],
label = "baz",
data = [ [label, datum] ];
const datum = [ [ [ 'foo', 'bar' ] ], [ [ 'qux', 1.1 ] ] ],
label = 'baz',
data = [ [ label, datum ] ];
client.train(data).then(([ result ]) => {

@@ -71,3 +44,3 @@ debug(result);

it('classify', done => {
var datum = [ [ ["foo", "bar"] ], [ ["qux", 1] ] ],
const datum = [ [ [ 'foo', 'bar' ] ], [ [ 'qux', 1.1 ] ] ],
data = [ datum ];

@@ -78,8 +51,8 @@ client.classify(data).then(([ result ]) => {

let datum = [ [ ["foo", "bar"] ], [ ["qux", 1] ] ],
label = "baz",
let datum = [ [ [ 'foo', 'bar' ] ], [ [ 'qux', 1 ] ] ],
label = 'baz',
data = [ [ label, datum ] ];
return client.train(data);
}).then(([ result ]) => {
let datum = [ [ ["foo", "bar"] ], [] ],
let datum = [ [ [ 'foo', 'bar' ] ] ],
data = [ datum ];

@@ -91,4 +64,4 @@ return client.classify(data);

result.forEach(estimates => {
expect(estimates[0][0]).to.be.a("string");
expect(estimates[0][1]).to.be.a("number");
expect(estimates[0][0]).to.be.a('string');
expect(estimates[0][1]).to.be.a('number');
});

@@ -117,3 +90,2 @@ done();

}).then(([ result ]) => {
expect(result).to.be.a('boolean');
expect(result).to.equal(true);

@@ -137,11 +109,8 @@ return client.getLabels();

}).then(([ result ]) => {
expect(result).to.be.a('boolean');
expect(result).to.equal(true);
return client.getLabels();
}).then(([ result ]) => {
expect(result).to.be.a('object');
expect(result).to.deep.equal({ [label]: 0 });
return client.deleteLabel(label);
}).then(([ result ]) => {
expect(result).to.be.a('boolean');
expect(result).to.equal(true);

@@ -148,0 +117,0 @@ return client.getLabels();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:clustering');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'clustering_config.json',
command = 'jubaclustering',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaclustering', config = 'clustering_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.clustering.client.Clustering(port, 'localhost');

@@ -56,9 +29,12 @@ done();

it('push', done => {
const variables = [ 'foo', 'bar', 'baz', 'qux', 'quux', 'quuz', 'corge', 'grault', 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud' ];
const points = [];
for (let i = 0; i < 1000; i++) {
const variables = [
'foo', 'bar', 'baz', 'qux', 'quux', 'quuz',
'corge', 'grault', 'garply', 'waldo', 'fred',
'plugh', 'xyzzy', 'thud'
];
const points = Array.apply(null, { length: 1000 }).map((v, i) => {
const index = Math.floor(Math.random() * variables.length);
const variable = variables[index];
points[i] = [ '' + i, [ [ [ 'foobar', variable ] ] ] ];
}
return [ '' + i, [ [ [ 'foobar', variable ] ] ] ];
});
client.push(points).then(([ result ]) => {

@@ -65,0 +41,0 @@ debug(result);

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:common');
const jubatus = require('../index.js');
const testUtil = require('./util');
const jubatus = require('../');
const rpc = require('../lib/msgpack-rpc');

@@ -13,32 +13,6 @@ let server;

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'common_config.json',
command = 'jubaclassifier',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
client = new jubatus.classifier.client.Classifier(port, 'localhost');
const command = 'jubaclassifier', config = 'classifier_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.classifier.client.Classifier(rpc.createClient(port));
done();

@@ -54,5 +28,15 @@ }).catch(done);

describe('common#name', () => {
it('set_name', done => {
expect(client.getName()).to.equal('');
const name = 'test';
client.setName(name);
expect(client).to.has.property('name', name);
done();
});
});
describe('common#save', () => {
it('save', done => {
var id = 'test';
const id = 'test';
client.save(id).then(([ result ]) => {

@@ -68,3 +52,3 @@ debug(result);

it('load', done => {
var id = 'test';
const id = 'test';
client.load(id).then(([ result ]) => {

@@ -80,7 +64,11 @@ debug(result);

it('clear', done => {
client.clear().then(([ result ]) => {
debug(result);
expect(result).to.be.a('boolean');
done();
}).catch(done);
client.clear((error, result) => {
if (error) {
done(error);
} else {
debug(result);
expect(result).to.be.a('boolean');
done();
}
});
});

@@ -127,14 +115,14 @@ });

it('get_proxy_status', done => {
client.getProxyStatus()
.then(([ result ]) => {
debug(result);
expect(result).to.be.a('object');
done();
})
.catch(error => {
debug(error);
expect(error).to.be.ok;
done();
client.getProxyStatus((error, result) => {
if (error) {
debug(error);
expect(error).to.be.ok;
done();
} else {
debug(result);
expect(result).to.be.a('object');
done();
}
});
});
});
/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:graph');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'graph_config.json',
command = 'jubagraph',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubagraph', config = 'graph_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.graph.client.Graph(port, 'localhost');

@@ -79,3 +52,3 @@ done();

it('update_node', done => {
const property = { "foo": "bar" };
const property = { 'foo': 'bar' };
client.createNode().then(([ nodeId ]) => {

@@ -94,3 +67,3 @@ expect(nodeId).to.be.a('string');

it('create_edge', done => {
const property = { "foo": "bar" };
const property = { 'foo': 'bar' };
const edge = [ property , null, null ];

@@ -115,3 +88,3 @@ client.createNode().then(([ source ]) => {

it('update_edge', done => {
const property = { "foo": "bar" };
const property = { 'foo': 'bar' };
const edge = [ property , null, null ];

@@ -151,8 +124,8 @@ client.createNode().then(([ source ]) => {

return Promise.all([
client.createEdge(nodeIds[0], [ { "foobar": "foo" }, nodeIds[0], nodeIds[1] ]),
client.createEdge(nodeIds[1], [ { "foobar": "bar" }, nodeIds[1], nodeIds[2] ]),
client.createEdge(nodeIds[2], [ { "foobar": "baz" }, nodeIds[2], nodeIds[0] ]),
client.createEdge(nodeIds[3], [ { "foobar": "qux" }, nodeIds[0], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { "foobar": "quux" }, nodeIds[1], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { "foobar": "quuz" }, nodeIds[2], nodeIds[3] ])
client.createEdge(nodeIds[0], [ { 'foobar': 'foo' }, nodeIds[0], nodeIds[1] ]),
client.createEdge(nodeIds[1], [ { 'foobar': 'bar' }, nodeIds[1], nodeIds[2] ]),
client.createEdge(nodeIds[2], [ { 'foobar': 'baz' }, nodeIds[2], nodeIds[0] ]),
client.createEdge(nodeIds[3], [ { 'foobar': 'qux' }, nodeIds[0], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { 'foobar': 'quux' }, nodeIds[1], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { 'foobar': 'quuz' }, nodeIds[2], nodeIds[3] ])
]);

@@ -252,6 +225,6 @@ }).then(edges => {

return Promise.all([
client.createEdge(nodeIds[0], [ { "foobar": "foo" }, nodeIds[0], nodeIds[1] ]),
client.createEdge(nodeIds[1], [ { "foobar": "bar" }, nodeIds[1], nodeIds[2] ]),
client.createEdge(nodeIds[2], [ { "foobar": "baz" }, nodeIds[2], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { "foobar": "qux" }, nodeIds[3], nodeIds[0] ])
client.createEdge(nodeIds[0], [ { 'foobar': 'foo' }, nodeIds[0], nodeIds[1] ]),
client.createEdge(nodeIds[1], [ { 'foobar': 'bar' }, nodeIds[1], nodeIds[2] ]),
client.createEdge(nodeIds[2], [ { 'foobar': 'baz' }, nodeIds[2], nodeIds[3] ]),
client.createEdge(nodeIds[3], [ { 'foobar': 'qux' }, nodeIds[3], nodeIds[0] ])
]);

@@ -306,3 +279,3 @@ }).then(edges => {

it('get_edge', done => {
const property = { "foo": "bar" };
const property = { 'foo': 'bar' };
const edge = [ property , null, null ];

@@ -330,3 +303,3 @@ client.createNode().then(([ source ]) => {

it('get_edge', done => {
const property = { "foo": "bar" };
const property = { 'foo': 'bar' };
const edge = [ property , null, null ];

@@ -333,0 +306,0 @@ client.createNode().then(([ source ]) => {

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:nearest_neighbor');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'nearest_neighbor_config.json',
command = 'jubanearest_neighbor',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubanearest_neighbor', config = 'nearest_neighbor_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.nearestneighbor.client.NearestNeighbor(port, 'localhost');

@@ -44,0 +17,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:recommender');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'recommender_config.json',
command = 'jubarecommender',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubarecommender', config = 'recommender_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.recommender.client.Recommender(port, 'localhost');

@@ -44,0 +17,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:regression');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'regression_config.json',
command = 'jubaregression',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaregression', config = 'regression_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.regression.client.Regression(port, 'localhost');

@@ -56,3 +29,3 @@ done();

it('train', done => {
const datum = [ [ ["foo", "bar"] ], [] ],
const datum = [ [ ['foo', 'bar'] ], [] ],
value = 1.01,

@@ -71,3 +44,3 @@ data = [ [value, datum] ];

it('estimate', done => {
var datum = [ [ ["foo", "bar"] ], [] ],
var datum = [ [ ['foo', 'bar'] ], [] ],
data = [ datum ];

@@ -78,3 +51,3 @@ client.estimate(data).then(([ result ]) => {

var datum = [ [ ["foo", "bar"] ], [] ],
var datum = [ [ ['foo', 'bar'] ], [] ],
value = 1,

@@ -84,3 +57,3 @@ data = [ [value, datum] ];

}).then(([ result ]) => {
let datum = [ [ ["foo", "bar"] ], [] ],
let datum = [ [ ['foo', 'bar'] ], [] ],
data = [ datum ];

@@ -92,3 +65,3 @@ return client.estimate(data);

result.forEach(estimate => {
expect(estimate).to.be.a("number");
expect(estimate).to.be.a('number');
});

@@ -95,0 +68,0 @@ done();

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:stat');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -13,31 +12,5 @@

before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'stat_config.json',
command = 'jubastat',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubastat', config = 'stat_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.stat.client.Stat(port, 'localhost');

@@ -56,3 +29,3 @@ done();

it('push', done => {
const key = "foo",
const key = 'foo',
value = 1.01;

@@ -69,3 +42,3 @@ client.push(key, value).then(([ result ]) => {

it('sum', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 0],

@@ -86,3 +59,3 @@ expected = values.reduce((previous, current) => previous + current, 0);

it('stddev', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 0];

@@ -94,3 +67,3 @@ client.clear()

debug(result);
expect(result).to.be.a("number");
expect(result).to.be.a('number');
done();

@@ -103,3 +76,3 @@ }).catch(done);

it('max', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 0],

@@ -120,3 +93,3 @@ expected = values.reduce((previous, current) => Math.max(previous, current), Number.MIN_VALUE);

it('min', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 0, -1],

@@ -129,3 +102,3 @@ expected = values.reduce((previous, current) => Math.min(previous, current), Number.MAX_VALUE);

debug(result);
expect(result).to.be.a("number");
expect(result).to.be.a('number');
expect(result).to.equal(expected);

@@ -139,3 +112,3 @@ done();

it('entropy', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 10, 100];

@@ -147,3 +120,3 @@ client.clear()

debug(result);
expect(result).to.be.a("number");
expect(result).to.be.a('number');
done();

@@ -156,3 +129,3 @@ }).catch(done);

it('moment', done => {
const key = "foo",
const key = 'foo',
values = [1, 1.2, 0],

@@ -166,3 +139,3 @@ degree = 1,

debug(result);
expect(result).to.be.a("number");
expect(result).to.be.a('number');
done();

@@ -169,0 +142,0 @@ }).catch(done);

/*jslint node: true, passfail: false */
const expect = require('chai').expect;
const spawn = require('child_process').spawn;
const portfinder = require('portfinder');
const debug = require('debug')('jubatus-node-client:test:weight');
const testUtil = require('./util');
const jubatus = require('../index.js');

@@ -11,33 +10,6 @@

let client;
before(done => {
const option = { port: Number(process.env.npm_package_config_test_port || 9199) };
portfinder.getPortPromise(option).then(port => {
debug(`port: ${ port }`);
const executor = (resolve, reject) => {
/*jslint nomen: true */
const config = 'weight_config.json',
command = 'jubaweight',
args = ['-p', port, '-f', config],
options = { cwd: __dirname };
server = spawn(command, args, options);
server.on('exit', (code, signal) => {
debug({ code: code, signal: signal });
if (code === null) {
reject(new Error(signal));
}
});
server.stdout.on('data', data => {
if (/RPC server startup/.test(data.toString())) {
resolve(port);
}
});
if (debug.enabled) {
server.stdout.on('data', data => {
process.stderr.write(data);
});
}
};
return new Promise(executor);
}).then(port => {
const command = 'jubaweight', config = 'weight_config.json';
testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
server = serverProcess;
client = new jubatus.weight.client.Weight(port, 'localhost');

@@ -56,6 +28,6 @@ done();

it('update', done => {
const string_values = [ [ "foo", "bar" ] ];
const num_values = [ [ "qux", 1.1 ] ];
const binary_values = [];
const datum = [ string_values, num_values, binary_values ];
const stringValues = [ [ 'foo', 'bar' ] ];
const numValues = [ [ 'qux', 1.1 ] ];
const binaryValues = [];
const datum = [ stringValues, numValues, binaryValues ];
client.update(datum).then(([ result ]) => {

@@ -71,6 +43,6 @@ debug(result);

it('calc_weight', done => {
const string_values = [ [ "foo", "bar" ] ];
const num_values = [ [ "qux", 1.1 ] ];
const binary_values = [];
const datum = [ string_values, num_values, binary_values ];
const stringValues = [ [ 'foo', 'bar' ] ];
const numValues = [ [ 'qux', 1.1 ] ];
const binaryValues = [];
const datum = [ stringValues, numValues, binaryValues ];
client.calcWeight(datum).then(([ result ]) => {

@@ -77,0 +49,0 @@ debug(result);

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