sloki-node-client
Advanced tools
Comparing version 0.0.6 to 0.0.7
# Changelog | ||
## [0.0.7] - UNRELEASED | ||
### Added | ||
* add getMethodsName() [#3](https://github.com/sloki-project/sloki-node-client/issues/3) | ||
* add getMethodDescription() [#4](https://github.com/sloki-project/sloki-node-client/issues/4) | ||
* TLS clients [#7](https://github.com/sloki-project/sloki-node-client/issues/7) | ||
### Changed | ||
* use named parameters in jsonrpc layer [#6](https://github.com/sloki-project/sloki-node-client/issues/6) | ||
## [0.0.6] - 2019-02-09 | ||
* Support Promises | ||
### Added | ||
* All methods now support Promises [#2](https://github.com/sloki-project/sloki-node-client/issues/2) | ||
## [0.0.3] - 2019-01-27 | ||
* First version, only TCP client is implemented | ||
* Use callback | ||
### Added | ||
* First version : TCP client | ||
* All methods support callback only for moment |
@@ -11,9 +11,9 @@ const Client = require('../') | ||
(next) => { | ||
client.loadDatabase('myTestDatabase', next); | ||
client.loadDatabase({ database:'myTestDatabase' }, next); | ||
}, | ||
(db, next) => { | ||
client.insert('devices',{'foo':'bar'}, next); | ||
client.insert({ collection:'devices', document:{'foo':'bar'} }, next); | ||
}, | ||
(result, next) => { | ||
client.find('devices', next); | ||
client.find({ collection:'devices' }, next); | ||
}, | ||
@@ -20,0 +20,0 @@ (devices, next) => { |
@@ -1,2 +0,2 @@ | ||
const Client = require('../') | ||
const Client = require('../'); | ||
@@ -8,5 +8,5 @@ const client = new Client('tcp://127.0.0.1:6370'); | ||
await client.connect(); | ||
await client.loadDatabase('myTestDatabase'); | ||
await client.insert('devices',{'foo':'bar'}); | ||
const devices = await client.find('devices'); | ||
await client.loadDatabase({ db:'myTestDatabase' }); | ||
await client.insert({ col:'devices', doc:{ 'foo':'bar' } }); | ||
const devices = await client.find({ col:'devices' }); | ||
await client.saveDatabase(); | ||
@@ -21,5 +21,5 @@ await client.close(); | ||
} | ||
} | ||
}; | ||
client.init(); |
76
index.js
@@ -1,54 +0,54 @@ | ||
const implementedTransports = ['tcp','tls']; | ||
const defaultOptions = { | ||
applicationLayer:'jayson' | ||
} | ||
const implementedTransports = [ | ||
'tcp', // alias for binary | ||
'tls', // alias for binarys | ||
'binary', | ||
'binarys', | ||
'jsonrpc', | ||
'jsonrpcs' | ||
]; | ||
function Client(url, options) { | ||
let client; | ||
let e = url.match(/^([^:]+)/); | ||
if (!url) { | ||
throw new Error('no endpoint specified (i.e tcp://localhost)'); | ||
} | ||
const e = url.match(/^([^:]+)/); | ||
if (!e) { | ||
throw new Error('URL must start with ' + implementedProtocols.join(',')+''); | ||
process.exit(-1); | ||
return; | ||
throw new Error(`endpoint must start with ${implementedTransports.join(',')}`); | ||
} | ||
options = Object.assign(defaultOptions, options||{}); | ||
options = options||{}; | ||
let transportLayer; | ||
options.protocol = e[1].toLowerCase(); | ||
if (implementedTransports.indexOf(options.protocol)<0) { | ||
throw new Error(`endpoint does not contain any implemented protocol ${implementedTransports.join(',')}`); | ||
} | ||
if (e) { | ||
transportLayer = e[1].toLowerCase(); | ||
if (implementedTransports.indexOf(transportLayer)<0) { | ||
throw new Error('URL does not contain any implemented protocol (' + implementedTransports.join(',')+')'); | ||
return null; | ||
} | ||
if (options.protocol === 'tcp') { | ||
options.protocol = 'binary'; | ||
} | ||
if (transportLayer === "tls") { | ||
throw new Error('Protocol '+proto+' not yet implemented'); | ||
process.exit(-1); | ||
if (options.protocol === 'tls') { | ||
options.protocol = 'binarys'; | ||
} | ||
if (transportLayer === "tcp" || transportLayer === "tls") { | ||
url = url.replace(/(tcp|tls):\/\//,'').split(':'); | ||
let host = url[0]; | ||
let port = parseInt(url[1]); | ||
let myClient; | ||
url = url.replace(/^[^:]+:\/\//, '').split(':'); | ||
const host = url[0]; | ||
const port = parseInt(url[1]); | ||
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'); | ||
} | ||
let MyClient; | ||
if (options.protocol.match(/jsonrpc/)) { | ||
MyClient = require('./src/jsonrpc'); | ||
} else if (options.protocol.match(/binary/)) { | ||
MyClient = require('./src/binary'); | ||
} else { | ||
throw new Error(`Unknow protocol ${options.protocol}`); | ||
} | ||
return new MyClient(port, host, options); | ||
} | ||
module.exports = Client; |
{ | ||
"name": "sloki-node-client", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "NodeJS Client for Sloki", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/sloki-project/sloki-node-client.git" | ||
"url": "git+https://github.com/sloki-project/sloki.git" | ||
}, | ||
@@ -21,11 +21,12 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/sloki-project/sloki-node-client/issues" | ||
"url": "https://github.com/sloki-project/sloki/issues" | ||
}, | ||
"homepage": "https://github.com/sloki-project/sloki-node-client#readme", | ||
"homepage": "https://github.com/sloki-project/sloki/blob/master/clients/node/README.md", | ||
"dependencies": { | ||
"JSONStream": "^1.3.5", | ||
"async": "^2.6.1", | ||
"debug": "^4.1.1", | ||
"hyperid": "^2.0.2" | ||
"JSONStream": "1.3.5", | ||
"async": "2.6.1", | ||
"debug": "4.1.1", | ||
"hyperid": "2.0.2", | ||
"missive": "3.0.1" | ||
} | ||
} |
# Sloki-node-client | ||
A NodeJS Client for [Sloki](https://github.com/sloki-project/sloki) | ||
[![Join the chat at https://gitter.im/sloki-server/community](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sloki-server/community) | ||
[![npm version](https://badge.fury.io/js/sloki-node-client.svg)](http://badge.fury.io/js/sloki-node-client) | ||
[![alt packagequality](http://npm.packagequality.com/shield/sloki-node-client.svg)](http://packagequality.com/#?package=sloki-node-client) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/sloki-project/sloki-node-client/badge.svg?targetFile=package.json)](https://snyk.io/test/github/sloki-project/sloki-node-client?targetFile=package.json) | ||
[![npm version](https://badge.fury.io/js/sloki-node-client.svg?v=0)](http://badge.fury.io/js/sloki-node-client) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/sloki-project/sloki/badge.svg?targetFile=clients/node/package.json)](https://snyk.io/test/github/sloki-project/sloki?targetFile=clients/node/package.json) | ||
[![Dependencies](https://david-dm.org/sloki-project/sloki.svg?path=clients/node)](https://david-dm.org/sloki-project/sloki-node-client) | ||
[![Dev Dependencies](https://david-dm.org/sloki-project/sloki/dev-status.svg?path=clients/node)](https://david-dm.org/sloki-project/sloki-node-client?type=dev) | ||
@@ -16,8 +16,11 @@ ----- | ||
----- | ||
## Usage | ||
TODO | ||
See [examples](examples/) | ||
---- | ||
## Source code | ||
See [sloki repository](https://github.com/sloki-project/sloki/tree/master/clients/node) |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
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
17123
430
26
5
10
3
3
+ Addedmissive@3.0.1
+ Addedasync@2.6.1(transitive)
+ Addeddebug@4.1.1(transitive)
+ Addedfringe@1.1.1(transitive)
+ Addedhyperid@2.0.2(transitive)
+ Addedmissive@3.0.1(transitive)
+ Addeduuid@3.4.0(transitive)
- Removedasync@2.6.4(transitive)
- Removeddebug@4.4.0(transitive)
- Removedhyperid@2.3.1(transitive)
- Removeduuid@8.3.2(transitive)
UpdatedJSONStream@1.3.5
Updatedasync@2.6.1
Updateddebug@4.1.1
Updatedhyperid@2.0.2