Fixed Buffer deprecated warnings when using node >= v10

This commit is contained in:
Nicolas Dextraze 2019-11-01 12:53:24 -07:00
parent 78677ba53e
commit 67dab18d53
8 changed files with 43 additions and 29 deletions

33
package-lock.json generated
View File

@ -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",

View File

@ -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"

View File

@ -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);
}

View File

@ -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;
exports.unparse = unparse;

View File

@ -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);
}

View File

@ -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;
module.exports = EventStoreNodeConnection;

View File

@ -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;
module.exports = TcpPackage;

View File

@ -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;
module.exports = LengthPrefixMessageFramer;