diff --git a/package-lock.json b/package-lock.json index a6d8037..d678128 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1984,7 +1984,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2005,12 +2006,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2031,7 +2034,8 @@ "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", @@ -2182,6 +2186,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2189,12 +2194,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2213,6 +2220,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2306,6 +2314,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2391,7 +2400,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2447,6 +2457,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2490,12 +2501,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -4181,9 +4194,9 @@ "integrity": "sha512-1w52Nyx4Gq47uuu0EVcsHBxZFJgurQ+rTKS3qMHxR1GY2T8c2AJYd6vZoZ9q1rupaDjU0yT+Jc2XTyXkjeMA+Q==" }, "@types/node": { - "version": "10.14.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.14.tgz", - "integrity": "sha512-xXD08vZsvpv4xptQXj1+ky22f7ZoKu5ZNI/4l+/BXG3X+XaeZsmaFbbTKuhSE3NjjvRuZFxFf9sQBMXIcZNFMQ==" + "version": "10.17.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.3.tgz", + "integrity": "sha512-QZ9CjUB3QoA3f2afw3utKlfRPhpmufB7jC2+oDhLWnXqoyx333fhKSQDLQu2EK7OE0a15X67eYiRAaJsHXrpMA==" }, "long": { "version": "4.0.0", diff --git a/package.json b/package.json index fc46e39..c0a5938 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,12 @@ "main": "index.js", "types": "index.d.ts", "engines": { - "node": ">=4.0" + "node": ">=5.10" }, "engineStrict": true, "scripts": { "clean": "rm lib/dist.js", + "prebuild": "npm run clean", "build": "webpack", "pretest": "npm run build", "test": "nodeunit", @@ -45,7 +46,7 @@ }, "homepage": "https://github.com/nicdex/node-eventstore-client#readme", "dependencies": { - "long": "^3.2", + "long": "^3.2.0", "protobufjs": "^6.8.8", "strict-event-emitter-types": "^1.2.0", "uuid": "^3.0.1" diff --git a/src/client.js b/src/client.js index a4851f9..cc986cf 100644 --- a/src/client.js +++ b/src/client.js @@ -33,8 +33,8 @@ Object.freeze(streamPosition); function createJsonEventData(eventId, event, metadata, type) { if (!event || typeof event !== 'object') throw new TypeError("data must be an object."); - var eventBuf = new Buffer(JSON.stringify(event)); - var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null; + var eventBuf = Buffer.from(JSON.stringify(event)); + var metaBuf = metadata ? Buffer.from(JSON.stringify(metadata)) : null; return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf); } diff --git a/src/common/guid-parse.js b/src/common/guid-parse.js index f8663a7..aed969e 100644 --- a/src/common/guid-parse.js +++ b/src/common/guid-parse.js @@ -14,14 +14,14 @@ function parse(s, buf, offset) { var ii = 0; if (buf) buf.fill(0, i, i + 16); - buf = buf || new Buffer(16); + buf = buf || Buffer.alloc(16); s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) { if (ii < 16) { // Don't overflow! buf[i + ii++] = _hexToByte[oct]; } }); - var buf2 = new Buffer(buf.slice(i, i + 16)); + var buf2 = Buffer.from(buf.slice(i, i + 16)); buf[i + 0] = buf2[3]; buf[i + 1] = buf2[2]; buf[i + 2] = buf2[1]; @@ -44,4 +44,4 @@ function unparse(buf, offset) { } exports.parse = parse; -exports.unparse = unparse; \ No newline at end of file +exports.unparse = unparse; diff --git a/src/eventData.js b/src/eventData.js index 54ed411..5b51b24 100644 --- a/src/eventData.js +++ b/src/eventData.js @@ -24,8 +24,8 @@ function EventData(eventId, type, isJson, data, metadata) { this.eventId = eventId; this.type = type; this.isJson = isJson || false; - this.data = data || new Buffer(0); - this.metadata = metadata || new Buffer(0); + this.data = data || Buffer.alloc(0); + this.metadata = metadata || Buffer.alloc(0); Object.freeze(this); } diff --git a/src/eventStoreNodeConnection.js b/src/eventStoreNodeConnection.js index aab5e90..bfea12a 100644 --- a/src/eventStoreNodeConnection.js +++ b/src/eventStoreNodeConnection.js @@ -650,7 +650,7 @@ EventStoreNodeConnection.prototype.setStreamMetadataRaw = function( if (err) return reject(err); resolve(result); } - var data = metadata ? new Buffer(JSON.stringify(metadata)) : null; + var data = metadata ? Buffer.from(JSON.stringify(metadata)) : null; var metaevent = new EventData(uuid.v4(), systemEventTypes.StreamMetadata, true, data, null); self._enqueueOperation( new AppendToStreamOperation(self._settings.log, cb, self._settings.requireMaster, @@ -720,4 +720,4 @@ EventStoreNodeConnection.prototype._enqueueOperation = function(operation) { setImmediate(tryEnqueue) }; -module.exports = EventStoreNodeConnection; \ No newline at end of file +module.exports = EventStoreNodeConnection; diff --git a/src/systemData/tcpPackage.js b/src/systemData/tcpPackage.js index d311c3e..5debd30 100644 --- a/src/systemData/tcpPackage.js +++ b/src/systemData/tcpPackage.js @@ -50,12 +50,12 @@ TcpPackage.fromBufferSegment = function(data) { TcpPackage.prototype.asBuffer = function() { if ((this.flags & TcpFlags.Authenticated) !== 0) { - var loginBytes = new Buffer(this.login); + var loginBytes = Buffer.from(this.login); if (loginBytes.length > 255) throw new Error("Login serialized length should be less than 256 bytes."); - var passwordBytes = new Buffer(this.password); + var passwordBytes = Buffer.from(this.password); if (passwordBytes.length > 255) throw new Error("Password serialized length should be less than 256 bytes."); - var res = new Buffer(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0)); + var res = Buffer.alloc(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0)); res[CommandOffset] = this.command; res[FlagsOffset] = this.flags; guidParse.parse(this.correlationId, res, CorrelationOffset); @@ -69,7 +69,7 @@ TcpPackage.prototype.asBuffer = function() { return res; } else { - var res = new Buffer(MandatorySize + (this.data ? this.data.count : 0)); + var res = Buffer.alloc(MandatorySize + (this.data ? this.data.count : 0)); res[CommandOffset] = this.command; res[FlagsOffset] = this.flags; guidParse.parse(this.correlationId, res, CorrelationOffset); @@ -82,4 +82,4 @@ TcpPackage.prototype.asBufferSegment = function() { return createBufferSegment(this.asBuffer()); }; -module.exports = TcpPackage; \ No newline at end of file +module.exports = TcpPackage; diff --git a/src/transport/tcp/lengthPrefixMessageFramer.js b/src/transport/tcp/lengthPrefixMessageFramer.js index 404c66e..c813d2b 100644 --- a/src/transport/tcp/lengthPrefixMessageFramer.js +++ b/src/transport/tcp/lengthPrefixMessageFramer.js @@ -35,7 +35,7 @@ LengthPrefixMessageFramer.prototype._parse = function(bytes) { throw new Error(["Package size is out of bounds: ", this._packageLength, "(max: ", this._maxPackageSize, "."].join('')); } - this._messageBuffer = new Buffer(this._packageLength); + this._messageBuffer = Buffer.alloc(this._packageLength); } } else @@ -58,7 +58,7 @@ LengthPrefixMessageFramer.prototype._parse = function(bytes) { LengthPrefixMessageFramer.prototype.frameData = function(data) { var length = data.count; - var lengthBuffer = new Buffer(HeaderLength); + var lengthBuffer = Buffer.alloc(HeaderLength); lengthBuffer.writeInt32LE(length, 0); return [ createBufferSegment(lengthBuffer, 0, HeaderLength), @@ -71,4 +71,4 @@ LengthPrefixMessageFramer.prototype.registerMessageArrivedCallback = function(ha }; -module.exports = LengthPrefixMessageFramer; \ No newline at end of file +module.exports = LengthPrefixMessageFramer;