@depup/mysql2 3.19.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/License +19 -0
  2. package/README.md +114 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +77 -0
  5. package/lib/auth_41.js +95 -0
  6. package/lib/auth_plugins/caching_sha2_password.js +114 -0
  7. package/lib/auth_plugins/caching_sha2_password.md +18 -0
  8. package/lib/auth_plugins/index.js +8 -0
  9. package/lib/auth_plugins/mysql_clear_password.js +17 -0
  10. package/lib/auth_plugins/mysql_native_password.js +34 -0
  11. package/lib/auth_plugins/sha256_password.js +68 -0
  12. package/lib/base/connection.js +988 -0
  13. package/lib/base/pool.js +282 -0
  14. package/lib/base/pool_connection.js +77 -0
  15. package/lib/commands/auth_switch.js +129 -0
  16. package/lib/commands/binlog_dump.js +109 -0
  17. package/lib/commands/change_user.js +68 -0
  18. package/lib/commands/client_handshake.js +383 -0
  19. package/lib/commands/close_statement.js +18 -0
  20. package/lib/commands/command.js +54 -0
  21. package/lib/commands/execute.js +112 -0
  22. package/lib/commands/index.js +27 -0
  23. package/lib/commands/ping.js +36 -0
  24. package/lib/commands/prepare.js +143 -0
  25. package/lib/commands/query.js +361 -0
  26. package/lib/commands/quit.js +29 -0
  27. package/lib/commands/register_slave.js +27 -0
  28. package/lib/commands/server_handshake.js +202 -0
  29. package/lib/compressed_protocol.js +153 -0
  30. package/lib/connection.js +12 -0
  31. package/lib/connection_config.js +293 -0
  32. package/lib/constants/charset_encodings.js +317 -0
  33. package/lib/constants/charsets.js +317 -0
  34. package/lib/constants/client.js +38 -0
  35. package/lib/constants/commands.js +36 -0
  36. package/lib/constants/cursor.js +8 -0
  37. package/lib/constants/encoding_charset.js +50 -0
  38. package/lib/constants/errors.js +3973 -0
  39. package/lib/constants/field_flags.js +20 -0
  40. package/lib/constants/server_status.js +44 -0
  41. package/lib/constants/session_track.js +11 -0
  42. package/lib/constants/ssl_profiles.js +11 -0
  43. package/lib/constants/types.js +64 -0
  44. package/lib/create_connection.js +10 -0
  45. package/lib/create_pool.js +10 -0
  46. package/lib/create_pool_cluster.js +9 -0
  47. package/lib/helpers.js +83 -0
  48. package/lib/packet_parser.js +195 -0
  49. package/lib/packets/auth_next_factor.js +35 -0
  50. package/lib/packets/auth_switch_request.js +38 -0
  51. package/lib/packets/auth_switch_request_more_data.js +33 -0
  52. package/lib/packets/auth_switch_response.js +30 -0
  53. package/lib/packets/binary_row.js +95 -0
  54. package/lib/packets/binlog_dump.js +33 -0
  55. package/lib/packets/binlog_query_statusvars.js +115 -0
  56. package/lib/packets/change_user.js +97 -0
  57. package/lib/packets/close_statement.js +21 -0
  58. package/lib/packets/column_definition.js +291 -0
  59. package/lib/packets/execute.js +214 -0
  60. package/lib/packets/handshake.js +112 -0
  61. package/lib/packets/handshake_response.js +173 -0
  62. package/lib/packets/index.js +152 -0
  63. package/lib/packets/packet.js +946 -0
  64. package/lib/packets/prepare_statement.js +27 -0
  65. package/lib/packets/prepared_statement_header.js +16 -0
  66. package/lib/packets/query.js +27 -0
  67. package/lib/packets/register_slave.js +46 -0
  68. package/lib/packets/resultset_header.js +124 -0
  69. package/lib/packets/ssl_request.js +25 -0
  70. package/lib/packets/text_row.js +47 -0
  71. package/lib/parsers/binary_parser.js +235 -0
  72. package/lib/parsers/parser_cache.js +68 -0
  73. package/lib/parsers/static_binary_parser.js +213 -0
  74. package/lib/parsers/static_text_parser.js +152 -0
  75. package/lib/parsers/string.js +50 -0
  76. package/lib/parsers/text_parser.js +214 -0
  77. package/lib/pool.js +12 -0
  78. package/lib/pool_cluster.js +375 -0
  79. package/lib/pool_config.js +30 -0
  80. package/lib/pool_connection.js +12 -0
  81. package/lib/promise/connection.js +228 -0
  82. package/lib/promise/inherit_events.js +27 -0
  83. package/lib/promise/make_done_cb.js +19 -0
  84. package/lib/promise/pool.js +118 -0
  85. package/lib/promise/pool_cluster.js +54 -0
  86. package/lib/promise/pool_connection.js +23 -0
  87. package/lib/promise/prepared_statement_info.js +32 -0
  88. package/lib/results_stream.js +38 -0
  89. package/lib/server.js +37 -0
  90. package/package.json +96 -0
  91. package/promise.d.ts +139 -0
  92. package/promise.js +208 -0
  93. package/typings/mysql/LICENSE.txt +15 -0
  94. package/typings/mysql/index.d.ts +84 -0
  95. package/typings/mysql/info.txt +1 -0
  96. package/typings/mysql/lib/Auth.d.ts +30 -0
  97. package/typings/mysql/lib/Connection.d.ts +442 -0
  98. package/typings/mysql/lib/Pool.d.ts +71 -0
  99. package/typings/mysql/lib/PoolCluster.d.ts +92 -0
  100. package/typings/mysql/lib/PoolConnection.d.ts +11 -0
  101. package/typings/mysql/lib/Server.d.ts +11 -0
  102. package/typings/mysql/lib/constants/CharsetToEncoding.d.ts +8 -0
  103. package/typings/mysql/lib/constants/Charsets.d.ts +326 -0
  104. package/typings/mysql/lib/constants/Types.d.ts +70 -0
  105. package/typings/mysql/lib/constants/index.d.ts +5 -0
  106. package/typings/mysql/lib/parsers/ParserCache.d.ts +4 -0
  107. package/typings/mysql/lib/parsers/index.d.ts +18 -0
  108. package/typings/mysql/lib/parsers/typeCast.d.ts +54 -0
  109. package/typings/mysql/lib/protocol/packets/Field.d.ts +10 -0
  110. package/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +27 -0
  111. package/typings/mysql/lib/protocol/packets/OkPacket.d.ts +23 -0
  112. package/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts +13 -0
  113. package/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts +18 -0
  114. package/typings/mysql/lib/protocol/packets/RowDataPacket.d.ts +9 -0
  115. package/typings/mysql/lib/protocol/packets/index.d.ts +28 -0
  116. package/typings/mysql/lib/protocol/packets/params/ErrorPacketParams.d.ts +6 -0
  117. package/typings/mysql/lib/protocol/packets/params/OkPacketParams.d.ts +9 -0
  118. package/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts +41 -0
  119. package/typings/mysql/lib/protocol/sequences/Prepare.d.ts +65 -0
  120. package/typings/mysql/lib/protocol/sequences/Query.d.ts +228 -0
  121. package/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts +41 -0
  122. package/typings/mysql/lib/protocol/sequences/Sequence.d.ts +5 -0
  123. package/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts +17 -0
  124. package/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts +18 -0
package/promise.js ADDED
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+
3
+ const SqlString = require('sql-escaper');
4
+ const EventEmitter = require('events').EventEmitter;
5
+ const parserCache = require('./lib/parsers/parser_cache.js');
6
+ const PoolCluster = require('./lib/pool_cluster.js');
7
+ const createConnection = require('./lib/create_connection.js');
8
+ const createPool = require('./lib/create_pool.js');
9
+ const createPoolCluster = require('./lib/create_pool_cluster.js');
10
+ const PromiseConnection = require('./lib/promise/connection.js');
11
+ const PromisePool = require('./lib/promise/pool.js');
12
+ const makeDoneCb = require('./lib/promise/make_done_cb.js');
13
+ const PromisePoolConnection = require('./lib/promise/pool_connection.js');
14
+ const inheritEvents = require('./lib/promise/inherit_events.js');
15
+ const PromisePoolNamespace = require('./lib/promise/pool_cluster');
16
+
17
+ function createConnectionPromise(opts) {
18
+ const coreConnection = createConnection(opts);
19
+ const createConnectionErr = new Error();
20
+ const thePromise = opts.Promise || Promise;
21
+ if (!thePromise) {
22
+ throw new Error(
23
+ 'no Promise implementation available.' +
24
+ 'Use promise-enabled node version or pass userland Promise' +
25
+ " implementation as parameter, for example: { Promise: require('bluebird') }"
26
+ );
27
+ }
28
+ return new thePromise((resolve, reject) => {
29
+ coreConnection.once('connect', () => {
30
+ resolve(new PromiseConnection(coreConnection, thePromise));
31
+ });
32
+ coreConnection.once('error', (err) => {
33
+ createConnectionErr.message = err.message;
34
+ createConnectionErr.code = err.code;
35
+ createConnectionErr.errno = err.errno;
36
+ createConnectionErr.sqlState = err.sqlState;
37
+ reject(createConnectionErr);
38
+ });
39
+ });
40
+ }
41
+
42
+ // note: the callback of "changeUser" is not called on success
43
+ // hence there is no possibility to call "resolve"
44
+
45
+ function createPromisePool(opts) {
46
+ const corePool = createPool(opts);
47
+ const thePromise = opts.Promise || Promise;
48
+ if (!thePromise) {
49
+ throw new Error(
50
+ 'no Promise implementation available.' +
51
+ 'Use promise-enabled node version or pass userland Promise' +
52
+ " implementation as parameter, for example: { Promise: require('bluebird') }"
53
+ );
54
+ }
55
+
56
+ return new PromisePool(corePool, thePromise);
57
+ }
58
+
59
+ class PromisePoolCluster extends EventEmitter {
60
+ constructor(poolCluster, thePromise) {
61
+ super();
62
+ this.poolCluster = poolCluster;
63
+ this.Promise = thePromise || Promise;
64
+ inheritEvents(poolCluster, this, ['warn', 'remove', 'online', 'offline']);
65
+ }
66
+
67
+ getConnection(pattern, selector) {
68
+ const corePoolCluster = this.poolCluster;
69
+ return new this.Promise((resolve, reject) => {
70
+ corePoolCluster.getConnection(
71
+ pattern,
72
+ selector,
73
+ (err, coreConnection) => {
74
+ if (err) {
75
+ reject(err);
76
+ } else {
77
+ resolve(new PromisePoolConnection(coreConnection, this.Promise));
78
+ }
79
+ }
80
+ );
81
+ });
82
+ }
83
+
84
+ query(sql, args) {
85
+ const corePoolCluster = this.poolCluster;
86
+ const localErr = new Error();
87
+ if (typeof args === 'function') {
88
+ throw new Error(
89
+ 'Callback function is not available with promise clients.'
90
+ );
91
+ }
92
+ return new this.Promise((resolve, reject) => {
93
+ const done = makeDoneCb(resolve, reject, localErr);
94
+ corePoolCluster.query(sql, args, done);
95
+ });
96
+ }
97
+
98
+ execute(sql, args) {
99
+ const corePoolCluster = this.poolCluster;
100
+ const localErr = new Error();
101
+ if (typeof args === 'function') {
102
+ throw new Error(
103
+ 'Callback function is not available with promise clients.'
104
+ );
105
+ }
106
+ return new this.Promise((resolve, reject) => {
107
+ const done = makeDoneCb(resolve, reject, localErr);
108
+ corePoolCluster.execute(sql, args, done);
109
+ });
110
+ }
111
+
112
+ of(pattern, selector) {
113
+ return new PromisePoolNamespace(
114
+ this.poolCluster.of(pattern, selector),
115
+ this.Promise
116
+ );
117
+ }
118
+
119
+ end() {
120
+ const corePoolCluster = this.poolCluster;
121
+ const localErr = new Error();
122
+ return new this.Promise((resolve, reject) => {
123
+ corePoolCluster.end((err) => {
124
+ if (err) {
125
+ localErr.message = err.message;
126
+ localErr.code = err.code;
127
+ localErr.errno = err.errno;
128
+ localErr.sqlState = err.sqlState;
129
+ localErr.sqlMessage = err.sqlMessage;
130
+ reject(localErr);
131
+ } else {
132
+ resolve();
133
+ }
134
+ });
135
+ });
136
+ }
137
+
138
+ async [Symbol.asyncDispose]() {
139
+ if (!this.poolCluster._closed) {
140
+ await this.end();
141
+ }
142
+ }
143
+ }
144
+
145
+ /**
146
+ * proxy poolCluster synchronous functions
147
+ */
148
+ (function (functionsToWrap) {
149
+ for (let i = 0; functionsToWrap && i < functionsToWrap.length; i++) {
150
+ const func = functionsToWrap[i];
151
+
152
+ if (
153
+ typeof PoolCluster.prototype[func] === 'function' &&
154
+ PromisePoolCluster.prototype[func] === undefined
155
+ ) {
156
+ PromisePoolCluster.prototype[func] = (function factory(funcName) {
157
+ return function () {
158
+ return PoolCluster.prototype[funcName].apply(
159
+ this.poolCluster,
160
+ arguments
161
+ );
162
+ };
163
+ })(func);
164
+ }
165
+ }
166
+ })(['add', 'remove']);
167
+
168
+ function createPromisePoolCluster(opts) {
169
+ const corePoolCluster = createPoolCluster(opts);
170
+ const thePromise = (opts && opts.Promise) || Promise;
171
+ if (!thePromise) {
172
+ throw new Error(
173
+ 'no Promise implementation available.' +
174
+ 'Use promise-enabled node version or pass userland Promise' +
175
+ " implementation as parameter, for example: { Promise: require('bluebird') }"
176
+ );
177
+ }
178
+ return new PromisePoolCluster(corePoolCluster, thePromise);
179
+ }
180
+
181
+ exports.createConnection = createConnectionPromise;
182
+ exports.createPool = createPromisePool;
183
+ exports.createPoolCluster = createPromisePoolCluster;
184
+ exports.escape = SqlString.escape;
185
+ exports.escapeId = SqlString.escapeId;
186
+ exports.format = SqlString.format;
187
+ exports.raw = SqlString.raw;
188
+ exports.PromisePool = PromisePool;
189
+ exports.PromiseConnection = PromiseConnection;
190
+ exports.PromisePoolConnection = PromisePoolConnection;
191
+
192
+ exports.__defineGetter__('Types', () => require('./lib/constants/types.js'));
193
+
194
+ exports.__defineGetter__('Charsets', () =>
195
+ require('./lib/constants/charsets.js')
196
+ );
197
+
198
+ exports.__defineGetter__('CharsetToEncoding', () =>
199
+ require('./lib/constants/charset_encodings.js')
200
+ );
201
+
202
+ exports.setMaxParserCache = function (max) {
203
+ parserCache.setMaxCache(max);
204
+ };
205
+
206
+ exports.clearParserCache = function () {
207
+ parserCache.clearCache();
208
+ };
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2016, Felix Frederick Becker
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,84 @@
1
+ import { Pool as BasePool, PoolOptions } from './lib/Pool.js';
2
+ import {
3
+ Connection as BaseConnection,
4
+ ConnectionOptions,
5
+ SslOptions,
6
+ } from './lib/Connection.js';
7
+ import {
8
+ Query as BaseQuery,
9
+ QueryOptions,
10
+ QueryError,
11
+ } from './lib/protocol/sequences/Query.js';
12
+ import {
13
+ PoolCluster as BasePoolCluster,
14
+ PoolClusterOptions,
15
+ PoolNamespace,
16
+ } from './lib/PoolCluster.js';
17
+ import { PoolConnection as BasePoolConnection } from './lib/PoolConnection.js';
18
+ import {
19
+ Prepare as BasePrepare,
20
+ PrepareStatementInfo,
21
+ } from './lib/protocol/sequences/Prepare.js';
22
+ import { Server } from './lib/Server.js';
23
+ import {
24
+ escape as SqlStringEscape,
25
+ escapeId as SqlStringEscapeId,
26
+ format as SqlStringFormat,
27
+ raw as SqlStringRaw,
28
+ } from 'sql-escaper';
29
+ export type { Raw, SqlValue, Timezone } from 'sql-escaper';
30
+
31
+ export {
32
+ ConnectionOptions,
33
+ SslOptions,
34
+ PoolOptions,
35
+ PoolClusterOptions,
36
+ PoolNamespace,
37
+ QueryOptions,
38
+ QueryError,
39
+ PrepareStatementInfo,
40
+ };
41
+
42
+ export * from './lib/protocol/packets/index.js';
43
+ export * from './lib/Auth.js';
44
+ export * from './lib/constants/index.js';
45
+ export * from './lib/parsers/index.js';
46
+ export * from './lib/Connection.js';
47
+
48
+ // Expose class interfaces
49
+ export interface Connection extends BaseConnection {}
50
+ export interface Pool extends BasePool {}
51
+ export interface PoolConnection extends BasePoolConnection {}
52
+ export interface PoolCluster extends BasePoolCluster {}
53
+ export interface Query extends BaseQuery {}
54
+ export interface Prepare extends BasePrepare {}
55
+
56
+ export function createConnection(connectionUri: string): BaseConnection;
57
+ export function createConnection(config: ConnectionOptions): BaseConnection;
58
+
59
+ export function createPool(connectionUri: string): BasePool;
60
+ export function createPool(config: PoolOptions): BasePool;
61
+
62
+ export function createPoolCluster(config?: PoolClusterOptions): PoolCluster;
63
+
64
+ export const escape: typeof SqlStringEscape;
65
+ export const escapeId: typeof SqlStringEscapeId;
66
+ export const format: typeof SqlStringFormat;
67
+ export const raw: typeof SqlStringRaw;
68
+
69
+ export interface ConnectionConfig extends ConnectionOptions {
70
+ mergeFlags(defaultFlags: string[], userFlags: string[] | string): number;
71
+ getDefaultFlags(options?: ConnectionOptions): string[];
72
+ getCharsetNumber(charset: string): number;
73
+ getSSLProfile(name: string): { ca: string[] };
74
+ parseUrl(url: string): {
75
+ host: string;
76
+ port: number;
77
+ database: string;
78
+ user: string;
79
+ password: string;
80
+ [key: string]: any;
81
+ };
82
+ }
83
+
84
+ export function createServer(handler: (conn: BaseConnection) => any): Server;
@@ -0,0 +1 @@
1
+ temporary workaround, see https://github.com/sidorares/node-mysql2/issues/1210
@@ -0,0 +1,30 @@
1
+ import { RsaPublicKey, RsaPrivateKey, KeyLike } from 'crypto';
2
+ import { Connection } from './Connection.js';
3
+
4
+ export type AuthPlugin = (pluginMetadata: {
5
+ connection: Connection;
6
+ command: string;
7
+ }) => (
8
+ pluginData: Buffer
9
+ ) => Promise<string> | string | Buffer | Promise<Buffer> | null;
10
+
11
+ type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin;
12
+
13
+ export const authPlugins: {
14
+ caching_sha2_password: AuthPluginDefinition<{
15
+ overrideIsSecure?: boolean;
16
+ serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
17
+ onServerPublicKey?: (data: Buffer) => void;
18
+ }>;
19
+ mysql_clear_password: AuthPluginDefinition<{
20
+ password?: string;
21
+ }>;
22
+ mysql_native_password: AuthPluginDefinition<{
23
+ password?: string;
24
+ passwordSha1?: string;
25
+ }>;
26
+ sha256_password: AuthPluginDefinition<{
27
+ serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
28
+ onServerPublicKey?: (data: Buffer) => void;
29
+ }>;
30
+ };