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

arturo-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arturo-client - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

test.js

237

lib/client.js

@@ -7,4 +7,2 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _nssocket = require('nssocket');

@@ -16,10 +14,5 @@

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
class Client {
constructor(port) {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Client = function () {
function Client(port) {
_classCallCheck(this, Client);
this._port = 61818;

@@ -29,192 +22,64 @@ this._connection = null;

_createClass(Client, [{
key: 'connection',
value: function connection() {
var _this = this;
if (!this._connection) {
this._connection = new Promise(function (resolve, reject) {
var connection = new _nssocket2.default.NsSocket();
connection.on('error', reject);
connection.on('close', function (err) {
return err && reject(err);
});
connection.on('timeout', function () {
return client.close();
});
connection.data(['connected'], function () {
return resolve();
});
connection.connect(_this._port);
});
}
return this._connection;
connection() {
if (!this._connection) {
this._connection = new Promise((resolve, reject) => {
const connection = new _nssocket2.default.NsSocket();
connection.on('error', reject);
connection.on('close', err => err && reject(err));
connection.on('timeout', () => client.close());
connection.data(['connected'], () => resolve());
connection.connect(this._port);
});
}
}, {
key: '_transmit',
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(method, data) {
var workers, connection, operations;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
workers = Client.toArray(data);
_context.next = 3;
return this.connection();
case 3:
connection = _context.sent;
operations = workers.map(function (worker) {
return new Promise(function (resolve, reject) {
return this._connection;
}
var successEvent = ['worker', method, 'success'];
client.on(successEvent, function onSuccess(result) {
if (result.id !== worker.id) return;
client.removeListener(successEvent, onSuccess);
resolve();
});
async _transmit(method, data) {
const workers = Client.toArray(data);
const connection = await this.connection();
var errorEvent = ['worker', method, 'error'];
client.on(errorEvent, function onError(result) {
if (result.id !== worker.id) return;
client.removeListener(errorEvent, onError);
reject();
});
const operations = workers.map(worker => new Promise((resolve, reject) => {
client.send(['worker', method], worker);
}).catch(function (err) {
return console.error(err);
});
});
return _context.abrupt('return', Promise.all(operations));
const successEvent = ['worker', method, 'success'];
client.on(successEvent, function onSuccess(result) {
if (result.id !== worker.id) return;
client.removeListener(successEvent, onSuccess);
resolve();
});
case 6:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
const errorEvent = ['worker', method, 'error'];
client.on(errorEvent, function onError(result) {
if (result.id !== worker.id) return;
client.removeListener(errorEvent, onError);
reject();
});
function _transmit(_x, _x2) {
return _ref.apply(this, arguments);
}
client.send(['worker', method], worker);
}).catch(err => console.error(err)));
return _transmit;
}()
}, {
key: 'addWorker',
value: function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(workers) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt('return', this._transmit('create', workers));
return Promise.all(operations);
}
case 1:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
async addWorker(workers) {
return this._transmit('create', workers);
}
function addWorker(_x3) {
return _ref2.apply(this, arguments);
}
async removeWorker(data) {
return this._transmit('destroy', workers);
}
return addWorker;
}()
}, {
key: 'removeWorker',
value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(data) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt('return', this._transmit('destroy', workers));
async destroy() {
return this.end();
}
case 1:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
async end() {
const connection = await this.connection();
connection.end();
}
function removeWorker(_x4) {
return _ref3.apply(this, arguments);
}
return removeWorker;
}()
}, {
key: 'destroy',
value: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt('return', this.end());
case 1:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function destroy() {
return _ref4.apply(this, arguments);
}
return destroy;
}()
}, {
key: 'end',
value: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
var connection;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.connection();
case 2:
connection = _context5.sent;
connection.end();
case 4:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function end() {
return _ref5.apply(this, arguments);
}
return end;
}()
}], [{
key: 'toArray',
value: function toArray(data) {
return Array.isArray(data) ? data : [data];
}
}]);
return Client;
}();
static toArray(data) {
return Array.isArray(data) ? data : [data];
}
}
exports.default = Client;
{
"name": "arturo-client",
"version": "1.0.2",
"version": "1.0.3",
"main": "lib/client.js",

@@ -5,0 +5,0 @@ "author": "chad.d.elliott@gmail.com",

@@ -12,4 +12,4 @@ # arturo-client [![NPM version](https://badge.fury.io/js/arturo-client.svg)](https://npmjs.org/package/arturo-client)

```js
const ArturoClient = require('arturo-client')
const client = new ArturoClient(port)
const Client = require('arturo-client').default
const client = new Client(port)

@@ -16,0 +16,0 @@ client.addWorker({route: '/route', path: 'asbolute/path/to/worker'})

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