sloki-node-client
Advanced tools
Comparing version 0.0.3 to 0.0.4
44
index.js
@@ -1,4 +0,7 @@ | ||
const implementedProtocols = ['tcp','tls']; | ||
const implementedTransports = ['tcp','tls']; | ||
const defaultOptions = { | ||
applicationLayer:'jayson' | ||
} | ||
function Client(url) { | ||
function Client(url, options) { | ||
let client; | ||
@@ -12,8 +15,10 @@ let e = url.match(/^([^:]+)/); | ||
let proto; | ||
options = Object.assign(defaultOptions, options||{}); | ||
let transportLayer; | ||
if (e) { | ||
proto = e[1].toLowerCase(); | ||
if (implementedProtocols.indexOf(proto)<0) { | ||
throw new Error('URL does not contain any implemented protocol (' + implementedProtocols.join(',')+')'); | ||
transportLayer = e[1].toLowerCase(); | ||
if (implementedTransports.indexOf(transportLayer)<0) { | ||
throw new Error('URL does not contain any implemented protocol (' + implementedTransports.join(',')+')'); | ||
return null; | ||
@@ -23,3 +28,3 @@ } | ||
if (proto === "tls") { | ||
if (transportLayer === "tls") { | ||
throw new Error('Protocol '+proto+' not yet implemented'); | ||
@@ -29,16 +34,23 @@ process.exit(-1); | ||
if (proto === "tcp" || proto === "tls") { | ||
if (transportLayer === "tcp" || transportLayer === "tls") { | ||
url = url.replace(/(tcp|tls):\/\//,'').split(':'); | ||
let host = url[0]; | ||
let port = url[1]; | ||
let port = parseInt(url[1]); | ||
let myClient; | ||
if (proto === "tcp") { | ||
const ClientTCP = require('./tcp'); | ||
return new ClientTCP(port, host); | ||
switch (transportLayer) { | ||
case "tcp": | ||
switch (options.applicationLayer) { | ||
case "jayson": | ||
MyClient = require('./src/tcpJayson'); | ||
return new MyClient(port, host, options); | ||
break; | ||
default: | ||
throw new Error('Unknow application layer '+options.applicationLayer); | ||
} | ||
case "tls": | ||
throw new Error('Transport layer TLS not yet implemented'); | ||
} | ||
if (proto === "tls") { | ||
const ClientTLS = require('./tls'); | ||
return new require('./tls')(port, host); | ||
} | ||
console.log(MyClient); | ||
} | ||
@@ -45,0 +57,0 @@ } |
{ | ||
"name": "sloki-node-client", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "NodeJS Client for Sloki", | ||
@@ -26,4 +26,4 @@ "main": "index.js", | ||
"evillogger": "^1.2.2", | ||
"uuid": "^3.3.2" | ||
"hyperid": "^2.0.2" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
13532
211
0
2
+ Addedhyperid@^2.0.2
+ Addedhyperid@2.3.1(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addeduuid-parse@1.1.0(transitive)
- Removeduuid@^3.3.2
- Removeduuid@3.4.0(transitive)