Comparing version 3.0.0-rc.1 to 3.0.0
@@ -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 @@ } |
@@ -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
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
498124
9
12337
1
23
96
+ Added@eslint-community/eslint-utils@4.4.0(transitive)
+ Added@eslint-community/regexpp@4.11.1(transitive)
+ Added@eslint/config-array@0.18.0(transitive)
+ Added@eslint/core@0.7.0(transitive)
+ Added@eslint/eslintrc@3.1.0(transitive)
+ Added@eslint/js@9.13.0(transitive)
+ Added@eslint/object-schema@2.1.4(transitive)
+ Added@eslint/plugin-kit@0.2.1(transitive)
+ Added@humanfs/core@0.19.0(transitive)
+ Added@humanfs/node@0.16.5(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/retry@0.3.1(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Addedacorn@8.13.0(transitive)
+ Addedacorn-jsx@5.3.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedeslint@9.13.0(transitive)
+ Addedeslint-config-prettier@8.10.0(transitive)
+ Addedeslint-scope@8.1.0(transitive)
+ Addedeslint-visitor-keys@3.4.34.1.0(transitive)
+ Addedespree@10.2.0(transitive)
+ Addedesquery@1.6.0(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfile-entry-cache@8.0.0(transitive)
+ Addedflat-cache@4.0.1(transitive)
+ Addedflatted@3.3.1(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedglobals@14.0.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlevn@0.4.1(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlong@5.2.3(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednatural-compare@1.4.0(transitive)
+ Addedoptionator@0.9.4(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedprelude-ls@1.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtype-check@0.4.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
- Removed@types/chai@^4.3.3
- Removedchai@^4.3.6
- Removedmocha@^10.0.0
- Removed@types/chai@4.3.20(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedanymatch@3.1.3(transitive)
- Removedassertion-error@1.1.0(transitive)
- Removedbinary-extensions@2.3.0(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedbraces@3.0.3(transitive)
- Removedbrowser-stdout@1.3.1(transitive)
- Removedcamelcase@6.3.0(transitive)
- Removedchai@4.5.0(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removedchokidar@3.6.0(transitive)
- Removedcliui@7.0.4(transitive)
- Removeddecamelize@4.0.0(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removeddiff@5.2.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescalade@3.2.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedflat@5.0.2(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfsevents@2.3.3(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedglob@8.1.0(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedhe@1.2.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-binary-path@2.1.0(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-plain-obj@2.1.0(transitive)
- Removedis-unicode-supported@0.1.0(transitive)
- Removedlog-symbols@4.1.0(transitive)
- Removedlong@4.0.0(transitive)
- Removedloupe@2.3.7(transitive)
- Removedlru-cache@6.0.0(transitive)
- Removedminimatch@5.1.6(transitive)
- Removedmocha@10.7.3(transitive)
- Removednormalize-path@3.0.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedpathval@1.1.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedreaddirp@3.6.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedserialize-javascript@6.0.2(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@8.1.1(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtype-detect@4.1.0(transitive)
- Removedworkerpool@6.5.1(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
- Removedyargs-unparser@2.0.0(transitive)
Updateddenque@^2.1.0
Updatedlong@^5.2.1
Updatedlru-cache@^7.14.1
Updatednamed-placeholders@^1.1.3