Socket
Socket
Sign inDemoInstall

mysql2

Package Overview
Dependencies
Maintainers
3
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql2 - npm Package Compare versions

Comparing version 3.0.0-rc.1 to 3.0.0

9

index.d.ts

@@ -167,9 +167,2 @@ import {

type authPlugins = (pluginMetadata: {
connection: Connection;
command: string;
}) => (
pluginData: Buffer
) => Promise<string> | string | Buffer | Promise<Buffer> | null;
export interface ConnectionOptions extends mysql.ConnectionOptions {

@@ -195,3 +188,3 @@ charsetNumber?: number;

authPlugins?: {
[key: string]: authPlugins;
[key: string]: mysql.AuthPlugin;
};

@@ -198,0 +191,0 @@ }

1

index.js

@@ -46,2 +46,3 @@ 'use strict';

exports.PoolConnection = require('./lib/pool_connection');
exports.authPlugins = require('./lib/auth_plugins');
exports.escape = SqlString.escape;

@@ -48,0 +49,0 @@ exports.escapeId = SqlString.escapeId;

@@ -1,12 +0,17 @@

'use strict'
'use strict';
module.exports = pluginOptions => ({ connection, command }) => {
const password =
command.password || pluginOptions.password || connection.config.password;
function bufferFromStr(str) {
return Buffer.from(`${str}\0`);
}
const cleartextPassword = function(password) {
return Buffer.from(`${password}\0`)
const create_mysql_clear_password_plugin = pluginOptions =>
function mysql_clear_password_plugin({ connection, command }) {
const password =
command.password || pluginOptions.password || connection.config.password;
return function (/* pluginData */) {
return bufferFromStr(password);
};
};
return cleartextPassword(password)
};
module.exports = create_mysql_clear_password_plugin;

@@ -58,2 +58,6 @@ // This file was modified by Oracle on June 1, 2021.

this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay);
// Enable TCP_NODELAY flag. This is needed so that the network packets
// are sent immediately to the server
this.stream.setNoDelay(true);
}

@@ -74,3 +78,3 @@ // if stream is a function, treat it as "stream agent / factory"

max: this.config.maxPreparedStatements,
dispose: function(key, statement) {
dispose: function(statement) {
statement.close();

@@ -101,2 +105,6 @@ }

});
this.stream.on('end', () => {
// emit the end event so that the pooled connection can close the connection
this.emit('end');
});
this.stream.on('close', () => {

@@ -348,2 +356,5 @@ // we need to set this flag everywhere where we want connection to close

const rejectUnauthorized = this.config.ssl.rejectUnauthorized;
const verifyIdentity = this.config.ssl.verifyIdentity;
const host = this.config.host;
let secureEstablished = false;

@@ -356,2 +367,5 @@ const secureSocket = new Tls.TLSSocket(this.stream, {

});
if (typeof host === 'string') {
secureSocket.setServername(host);
}
// error handler for secure socket

@@ -367,3 +381,11 @@ secureSocket.on('_tlsError', err => {

secureEstablished = true;
onSecure(rejectUnauthorized ? secureSocket.ssl.verifyError() : null);
let callbackValue = null;
if (rejectUnauthorized) {
callbackValue = secureSocket.ssl.verifyError()
if (!callbackValue && typeof host === 'string' && verifyIdentity) {
const cert = secureSocket.ssl.getPeerCertificate(true);
callbackValue = Tls.checkServerIdentity(host, cert)
}
}
onSecure(callbackValue);
});

@@ -410,2 +432,6 @@ secureSocket.on('data', data => {

}
get fatalError() {
return this._fatalError;
}

@@ -597,3 +623,3 @@ handlePacket(packet) {

if (stmt) {
this._statements.del(key);
this._statements.delete(key);
stmt.close();

@@ -825,3 +851,9 @@ }

writeTextResult(rows, columns) {
writeBinaryRow(column) {
this.writePacket(
Packets.BinaryRow.toPacket(column, this.serverConfig.encoding)
);
}
writeTextResult(rows, columns, binary=false) {
this.writeColumns(columns);

@@ -833,3 +865,6 @@ rows.forEach(row => {

});
this.writeTextRow(arrayRow);
if(binary) {
this.writeBinaryRow(arrayRow);
}
else this.writeTextRow(arrayRow);
});

@@ -836,0 +871,0 @@ this.writeEof();

@@ -13,4 +13,51 @@ 'use strict';

toPacket() {
throw new Error('Not implemented');
static toPacket(columns, encoding) {
// throw new Error('Not implemented');
const sequenceId = 0; // TODO remove, this is calculated now in connecton
let length = 0;
columns.forEach(val => {
if (val === null || typeof val === 'undefined') {
++length;
return;
}
length += Packet.lengthCodedStringLength(val.toString(10), encoding);
});
length = length + 2;
const buffer = Buffer.allocUnsafe(length + 4);
const packet = new Packet(sequenceId, buffer, 0, length + 4);
packet.offset = 4;
packet.writeInt8(0);
let bitmap = 0;
let bitValue = 1;
columns.forEach(parameter => {
if (parameter.type === Types.NULL) {
bitmap += bitValue;
}
bitValue *= 2;
if (bitValue === 256) {
packet.writeInt8(bitmap);
bitmap = 0;
bitValue = 1;
}
});
if (bitValue !== 1) {
packet.writeInt8(bitmap);
}
columns.forEach(val => {
if (val === null) {
packet.writeNull();
return;
}
if (typeof val === 'undefined') {
packet.writeInt8(0);
return;
}
packet.writeLengthCodedString(val.toString(10), encoding);
});
return packet;
}

@@ -17,0 +64,0 @@

@@ -46,3 +46,3 @@ 'use strict';

function clearCache() {
parserCache.reset();
parserCache.clear();
}

@@ -49,0 +49,0 @@

@@ -88,4 +88,11 @@ 'use strict';

name: field.name,
string: function() {
return _this.packet.readLengthCodedString(field.encoding);
string: function(encoding = field.encoding) {
if (field.columnType === Types.JSON && encoding === field.encoding) {
// Since for JSON columns mysql always returns charset 63 (BINARY),
// we have to handle it according to JSON specs and use "utf8",
// see https://github.com/sidorares/node-mysql2/issues/1661
console.warn(`typeCast: JSON column "${field.name}" is interpreted as BINARY by default, recommended to manually set utf8 encoding: \`field.string("utf8")\``);
}
return _this.packet.readLengthCodedString(encoding);
},

@@ -176,3 +183,3 @@ buffer: function() {

}
}
}
}

@@ -196,3 +203,3 @@

return parserFn.toFunction({wrap});
}
}
return parserFn.toFunction();

@@ -199,0 +206,0 @@ }

{
"name": "mysql2",
"version": "3.0.0-rc.1",
"version": "3.0.0",
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",

@@ -41,3 +41,3 @@ "main": "index.js",

"lib",
"typings",
"typings/mysql",
"index.js",

@@ -59,11 +59,9 @@ "index.d.ts",

"dependencies": {
"@types/chai": "^4.3.3",
"chai": "^4.3.6",
"denque": "^2.0.1",
"denque": "^2.1.0",
"eslint-config-prettier": "^8.5.0",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^4.0.0",
"lru-cache": "^6.0.0",
"mocha": "^10.0.0",
"named-placeholders": "^1.1.2",
"long": "^5.2.1",
"lru-cache": "^7.14.1",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",

@@ -73,17 +71,19 @@ "sqlstring": "^2.3.2"

"devDependencies": {
"@types/mocha": "^9.1.1",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.0",
"@types/node": "^18.7.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"assert-diff": "^3.0.2",
"benchmark": "^2.1.4",
"c8": "^7.10.0",
"chai": "^4.3.7",
"error-stack-parser": "^2.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint": "^8.27.0",
"eslint-plugin-async-await": "0.0.0",
"eslint-plugin-markdown": "^2.2.1",
"husky": "^7.0.2",
"eslint-plugin-markdown": "^3.0.0",
"husky": "^8.0.2",
"is-async-supported": "^1.2.0",
"lint-staged": "^11.2.0",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"portfinder": "^1.0.28",

@@ -90,0 +90,0 @@ "prettier": "^2.4.1",

@@ -148,2 +148,3 @@ import {

): Promise<Connection>;
export function createPool(connectionUri: string): Pool;
export function createPool(config: PoolOptions): Pool;

@@ -150,0 +151,0 @@

@@ -11,3 +11,3 @@ ## Node MySQL 2

[简体中文 Simplified Chinese](./documentation_zh-cn/)
English | [简体中文](./documentation_zh-cn/)

@@ -14,0 +14,0 @@ > MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl [much more](https://github.com/sidorares/node-mysql2/tree/master/documentation)

@@ -0,1 +1,2 @@

import * as crypto from 'crypto';

@@ -46,2 +47,30 @@ import BaseConnection = require('./lib/Connection');

export interface Query extends BaseQuery {}
export interface Prepare extends BasePrepare {}
export interface Prepare extends BasePrepare {}
export type AuthPlugin = (pluginMetadata: {
connection: Connection;
command: string;
}) => (
pluginData: Buffer
) => Promise<string> | string | Buffer | Promise<Buffer> | null;
type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin
export const authPlugins: {
caching_sha2_password: AuthPluginDefinition<{
overrideIsSecure?: boolean,
serverPublicKey?: crypto.RsaPublicKey | crypto.RsaPrivateKey | crypto.KeyLike,
jonServerPublicKey?: (data: Buffer) => void;
}>,
mysql_clear_password: AuthPluginDefinition<{
password?: string;
}>,
mysql_native_password: AuthPluginDefinition<{
password?: string;
passwordSha1?: string;
}>,
sha256_password: AuthPluginDefinition<{
serverPublicKey?: crypto.RsaPublicKey | crypto.RsaPrivateKey | crypto.KeyLike,
joinServerPublicKey?: (data: Buffer) => void;
}>,
}

@@ -133,3 +133,3 @@ // This file was modified by Oracle on November 04, 2021.

* bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
* represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
* represented with [JavaScript Number objects](https://262.ecma-international.org/5.1/#sec-8.5)
* (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects.

@@ -231,2 +231,8 @@ * This option is ignored if supportBigNumbers is disabled.

minVersion?: string;
/**
* You can verify the server name identity presented on the server certificate when connecting to a MySQL server.
* You should enable this but it is disabled by default right now for backwards compatibility.
*/
verifyIdentity?: boolean;
}

@@ -277,4 +283,6 @@ }

execute(sql: string, values: Array<any>, cb: (err: any, rows: Array<any>, fields: Array<any>) => any): any;
execute(sql: string, callback?: (err: any, rows: Array<any>, fields: Array<any>) => any): any;
execute(sql: string, values: any | any[] | { [param: string]: any }, callback?: (err: any, rows: Array<any>, fields: Array<any>) => any): any;
unprepare(sql: string): any;

@@ -281,0 +289,0 @@

Sorry, the diff of this file is too big to display

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