Comparing version 0.0.0-semantic-release to 0.0.1
153
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function hello() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
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; }; }(); | ||
return 'Hello, ' + name + '!'; | ||
} | ||
var _quic = require('quic'); | ||
function goodbye() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
var _arbitraryPromise = require('arbitrary-promise'); | ||
return 'Bye ' + name + '.'; | ||
} | ||
var _arbitraryPromise2 = _interopRequireDefault(_arbitraryPromise); | ||
exports.default = { | ||
hello: hello, | ||
goodbye: goodbye | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// quic.listen(2345) // also takes address, defaults to localhost | ||
// .then(() => {}) | ||
// .onError(error => {}) | ||
// .onData((data, stream) => {}) | ||
// // stream has .write() function | ||
// quic.stopListening() | ||
// .then(() => {}) | ||
// quic.getServer() // low level server object | ||
// quic.getClient() // low level client object | ||
// quic.getAddress() // { port: number,family:string (like "IPv4"),address: string (ip address) } | ||
// quic.send(url, data) | ||
// .onError(error => {}) | ||
// .onData(data => {}) | ||
// simple convenience helper | ||
var rejectPromise = function rejectPromise(promise, err, message) { | ||
promise.reject(Object.assign(err, { class: message })); | ||
}; | ||
var Quic = function () { | ||
function Quic() { | ||
_classCallCheck(this, Quic); | ||
} | ||
_createClass(Quic, [{ | ||
key: 'listen', | ||
value: function listen(port) { | ||
var address = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'localhost'; | ||
var promise = new _arbitraryPromise2.default([['resolve', 'then'], ['reject', 'onError'], ['handleData', 'onData']]); | ||
if (!port) return promise.reject('must supply port argument!'); | ||
this._server = new _quic.Server(); | ||
this._server.on('error', function (err) { | ||
return rejectPromise(promise, err, 'server error'); | ||
}).on('session', function (session) { | ||
session.on('error', function (err) { | ||
return rejectPromise(promise, err, 'server session error'); | ||
}).on('stream', function (stream) { | ||
var message = ''; // TODO turn into buf? | ||
stream.on('error', function (err) { | ||
return rejectPromise(promise, err, 'server stream error'); | ||
}).on('data', function (data) { | ||
message += data.toString(); | ||
}).on('end', function () { | ||
var oldWrite = stream.write.bind(stream); | ||
stream.write = function () { | ||
oldWrite.apply(undefined, arguments); | ||
stream.end(); | ||
}; | ||
promise.handleData(message, stream); | ||
// TODO have to have mechanism to end stream when not returning anything | ||
// stream.end() | ||
}).on('finish', function () { | ||
// ilog.info(`server stream ${stream.id} finished`) | ||
}); | ||
}); | ||
}); | ||
this._server.listen(port, address).then(promise.resolve).catch(promise.reject); | ||
return promise; | ||
} | ||
}, { | ||
key: 'stopListening', | ||
value: async function stopListening() { | ||
// TODO returned promise to return onError instead of catch | ||
this._server && (await this._server.close()); | ||
delete this._server; | ||
} | ||
}, { | ||
key: 'getServer', | ||
value: function getServer() { | ||
return this._server; | ||
} | ||
}, { | ||
key: 'getAddress', | ||
value: function getAddress() { | ||
var defaul = { port: 0, family: '', address: '' }; | ||
return this._server && this._server.address() || defaul; | ||
} | ||
}, { | ||
key: 'send', | ||
value: function send(port, address, data) { | ||
// TODO change port, address to address:port? | ||
var promise = new _arbitraryPromise2.default([['resolve', 'then'], ['reject', 'onError'], ['handleData', 'onData']]); | ||
if (!port || !address || !data) return promise.reject('must supply three parameters'); | ||
if (typeof data !== 'string') data = JSON.stringify(data); | ||
var client = new _quic.Client(); | ||
client.connect(port, address).then(function () { | ||
var stream = client.request(); | ||
var message = ''; | ||
stream.on('error', function (err) { | ||
return rejectPromise(promise, err, 'client stream error'); | ||
}).on('data', function (data) { | ||
return message += data.toString(); | ||
}).on('end', function () { | ||
client.close(); | ||
client.destroy(); | ||
promise.handleData(message); | ||
}).on('finish', function () {}); | ||
stream.write(data, function () { | ||
promise.resolve(); | ||
stream.end(); | ||
}); | ||
}); | ||
return promise; | ||
} | ||
}]); | ||
return Quic; | ||
}(); | ||
module.exports = new Quic(); |
{ | ||
"name": "node-quic", | ||
"version": "0.0.0-semantic-release", | ||
"version": "0.0.1", | ||
"description": "A wrapper around fidm/quic, node-quic is a dead simple stream based QUIC server / client for use in node.js.", | ||
@@ -10,4 +10,5 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"test": "cross-env BABEL_ENV=test mocha --compilers js:babel-core/register --recursive", | ||
"test:with-coverage": "npm run clean:coverage && cross-env BABEL_ENV=test nyc --reporter=lcov mocha --compilers js:babel-core/register --recursive", | ||
"test": "cross-env BABEL_ENV=test mocha --require babel-core/register --recursive", | ||
"test:watch": "nodemon -x npm run test", | ||
"test:with-coverage": "npm run clean:coverage && cross-env BABEL_ENV=test nyc --reporter=lcov mocha --require babel-core/register --recursive", | ||
"test:check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
@@ -57,2 +58,3 @@ "test:publish-coverage": "codecov", | ||
"mocha": "^5.2.0", | ||
"nodemon": "^1.18.3", | ||
"npm-run-all": "^2.1.2", | ||
@@ -67,3 +69,5 @@ "nyc": "^13.0.0", | ||
"dependencies": { | ||
"in-publish": "^2.0.0" | ||
"arbitrary-promise": "1.2.0", | ||
"in-publish": "2.0.0", | ||
"quic": "0.4.2" | ||
}, | ||
@@ -70,0 +74,0 @@ "config": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14284
9
112
3
26
1
80
+ Addedarbitrary-promise@1.2.0
+ Addedquic@0.4.2
+ Addedarbitrary-promise@1.2.0(transitive)
+ Addedin-publish@2.0.0(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedquic@0.4.2(transitive)
- Removedin-publish@2.0.1(transitive)
Updatedin-publish@2.0.0