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

jubaclient

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jubaclient - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

36

app.js

@@ -7,3 +7,3 @@ const assert = require('assert');

function toCamelCase(value) {
return value.replace(/_([a-z])/g, (match, group1) => group1.toUpperCase());
return value.replace(/_([a-z])/g, (match, group1) => group1.toUpperCase());
}

@@ -13,3 +13,3 @@ exports.toCamelCase = toCamelCase;

function toSnakeCase(value) {
return value.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
return value.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
}

@@ -19,5 +19,5 @@ exports.toSnakeCase = toSnakeCase;

function resolveService(service) {
const serviseName = toCamelCase('_' + service);
const { [serviseName.toLowerCase()]: { client: { [serviseName]: Service } } } = jubatus;
return Service;
const serviseName = toCamelCase('_' + service);
const { [serviseName.toLowerCase()]: { client: { [serviseName]: Service } } } = jubatus;
return Service;
}

@@ -27,7 +27,7 @@ exports.resolveService = resolveService;

function request(service, method, params, rpcClient, name) {
const methodName = toCamelCase(method);
const Service = resolveService(service);
const client = new Service({ rpcClient, name });
debug(client);
return client[methodName].apply(client, params);
const methodName = toCamelCase(method);
const Service = resolveService(service);
const client = new Service({ rpcClient, name });
debug(client);
return client[methodName].apply(client, params);
}

@@ -37,13 +37,13 @@ exports.request = request;

function assertServiceMethod(service, method) {
assert.ok(service && typeof service === 'string', 'service is required.');
assert.ok(method && typeof method === 'string', 'method is required.');
assert.ok(service && typeof service === 'string', 'service is required.');
assert.ok(method && typeof method === 'string', 'method is required.');
const serviseName = toCamelCase('_' + service);
const namespace = serviseName.toLowerCase();
assert.ok(Object.keys(jubatus).some(key => namespace === key), `${ namespace } is unspport service.`);
const serviseName = toCamelCase('_' + service);
const namespace = serviseName.toLowerCase();
assert.ok(Object.keys(jubatus).some(key => namespace === key), `${ namespace } is unspport service.`);
const { [namespace]: { client: { [serviseName]: Service } } } = jubatus;
const methodName = toCamelCase(method);
assert.ok(Object.keys(Service.prototype).some(key => methodName === key), `${ methodName } is unspport method.`);
const { [namespace]: { client: { [serviseName]: Service } } } = jubatus;
const methodName = toCamelCase(method);
assert.ok(Object.keys(Service.prototype).some(key => methodName === key), `${ methodName } is unspport method.`);
}
exports.assertServiceMethod = assertServiceMethod;

@@ -15,12 +15,18 @@ #!/usr/bin/env node

const argsOption = {
boolean: [ 'i' ],
string: [ 'h', 'n' ],
alias : { 'p': 'port', 'h': 'host', 'n': 'name', 't': 'timeout', 'i': 'interactive' },
default: { p: 9199, h: 'localhost', n: '', t: 0, i: false },
unknown: false
boolean: [ 'i', 'v' ],
string: [ 'h', 'n' ],
alias : { 'p': 'port', 'h': 'host', 'n': 'name', 't': 'timeout', 'i': 'interactive', 'v': 'version' },
default: { p: 9199, h: 'localhost', n: '', t: 0, i: false },
unknown: false
};
const args = minimist(process.argv.slice(2), argsOption);
const { p: port, h: host, n: name, t: timeout, i: interactive } = args;
const { port, host, name, timeout, interactive, version } = args;
let { '_': [ service, method ] } = args;
if (version) {
const npmPackage = require('./package.json');
console.log(npmPackage.version);
process.exit(0);
}
if (typeof port !== 'number') { throw new Error('Illegal option: -p'); }

@@ -34,8 +40,8 @@ if (typeof timeout !== 'number') { throw new Error('Illegal option: -t'); }

const completer = line => {
const hits = completions.filter(completion => completion.startsWith(line));
return [ hits.length ? hits : completions, line ];
const hits = completions.filter(completion => completion.startsWith(line));
return [ hits.length ? hits : completions, line ];
};
function question(rl, message) {
return new Promise(resolve => rl.question(message, resolve));
return new Promise(resolve => rl.question(message, resolve));
}

@@ -47,64 +53,62 @@

rl.on('line', line => {
debug(`${ ++count }: ${ line }`);
debug(`${ ++count }: ${ line }`);
if (interactive && line === '') {
rl.prompt();
return;
}
if (interactive && line === '') {
rl.prompt();
return;
}
new Promise((resolve, reject) => {
resolve(JSON.parse(line));
}).then(params => {
debug(params);
return app.request(service, method, params, client, name);
}).then(response => {
debug(response);
const [ result, msgid ] = response;
console.log(JSON.stringify(result));
new Promise((resolve, reject) => {
resolve(JSON.parse(line));
}).then(params => {
debug(params);
return app.request(service, method, params, client, name);
}).then(response => {
debug(response);
const [ result, msgid ] = response;
console.log(JSON.stringify(result));
if (interactive) { rl.prompt(); }
}).catch(error => {
console.error(error);
if (interactive) { rl.prompt(); }
}).catch(error => {
console.error(error);
if (interactive) { rl.prompt(); }
});
})
.on('SIGINT', () => {
if (!interactive) {
rl.close();
return;
}
if (interactive) { rl.prompt(); }
});
}).on('SIGINT', () => {
if (!interactive) {
rl.close();
return;
}
completions = Object.keys(jubatus);
question(rl, `service [${ service }]: `).then(serviceName => {
service = serviceName || service;
app.assertServiceMethod(service || service, 'get_client');
const clientClass = app.resolveService(service);
const notRPCMethodNames = [ 'getClient', 'getName', 'setName' ];
const methods = Object.keys(clientClass.prototype)
.filter(method => !(notRPCMethodNames.some(notRPCMethod => method === notRPCMethod)))
.map(app.toSnakeCase);
completions = methods;
return question(rl, `${ service } method [${ method }]: `);
}).then(methodName => {
method = methodName || method;
app.assertServiceMethod(service, method);
rl.setPrompt(`${ service }#${ method } > `);
completions = [ '[]' ];
rl.prompt();
}).catch(error => {
console.error(error.toString());
process.exit(1);
});
})
.on('close', () => {
debug(`${ count }`);
client.close();
completions = Object.keys(jubatus);
question(rl, `service [${ service }]: `).then(serviceName => {
service = serviceName || service;
app.assertServiceMethod(service || service, 'get_client');
const clientClass = app.resolveService(service);
const notRPCMethodNames = [ 'getClient', 'getName', 'setName' ];
const methods = Object.keys(clientClass.prototype)
.filter(method => !(notRPCMethodNames.some(notRPCMethod => method === notRPCMethod)))
.map(app.toSnakeCase);
completions = methods;
return question(rl, `${ service } method [${ method }]: `);
}).then(methodName => {
method = methodName || method;
app.assertServiceMethod(service, method);
rl.setPrompt(`${ service }#${ method } > `);
completions = [ '[]' ];
rl.prompt();
}).catch(error => {
console.error(error.toString());
process.exit(1);
});
}).on('close', () => {
debug(`${ count }`);
client.close();
});
if (interactive) {
rl.write(null, { ctrl: true, name: 'c' });
rl.write(null, { ctrl: true, name: 'c' });
} else {
app.assertServiceMethod(service, method);
app.assertServiceMethod(service, method);
}
{
"name": "jubaclient",
"version": "0.2.3",
"version": "0.2.4",
"description": "Jubatus CLI client (unofficial)",

@@ -31,3 +31,3 @@ "main": "index.js",

"dependencies": {
"jubatus": "^0.7.0",
"jubatus": "^0.7.1",
"minimist": "^1.2.0"

@@ -34,0 +34,0 @@ },

@@ -36,10 +36,10 @@ # jubaclient

**Note**: To install on Windows, you need the C compiler and Python 2. See also: [with windows-build-tools - npm](https://www.npmjs.com/package/windows-build-tools/tutorial)
## Usage ##
<code>jubaclient _service_ _method_ [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>**jubaclient** _service_ _method_ [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>jubaclient -i [_service_] [_method_] [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>**jubaclient** **-i** [_service_] [_method_] [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>**jubaclient** **-v**</code>
The `jubaclient` command requests JSON received from standard input with the specified method to the Jubatus server, and returns the response to the standard output.

@@ -63,2 +63,3 @@

- <code>**-i**</code> : interactive mode
- <code>**-v**</code> : Print jubaclient's version.

@@ -65,0 +66,0 @@ ## Examples ##

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