node-server-dev 3.1.5 → 3.1.7
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.
- package/dist/cjs/browser.js +1 -1
- package/dist/cjs/getAllRouter/index.js +1 -1
- package/dist/cjs/hash/index.js +1 -1
- package/dist/cjs/id/index.js +1 -1
- package/dist/cjs/id/random.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/jwt/index.js +1 -1
- package/dist/cjs/mac/index.js +1 -1
- package/dist/cjs/package/mysql2/License +19 -0
- package/dist/cjs/package/mysql2/README.md +114 -0
- package/dist/cjs/package/mysql2/index.d.ts +1 -0
- package/dist/cjs/package/mysql2/index.js +77 -0
- package/dist/cjs/package/mysql2/lib/auth_41.js +95 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/caching_sha2_password.js +108 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/caching_sha2_password.md +18 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/index.js +8 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/mysql_clear_password.js +17 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/mysql_native_password.js +34 -0
- package/dist/cjs/package/mysql2/lib/auth_plugins/sha256_password.js +59 -0
- package/dist/cjs/package/mysql2/lib/base/connection.js +945 -0
- package/dist/cjs/package/mysql2/lib/base/pool.js +233 -0
- package/dist/cjs/package/mysql2/lib/base/pool_connection.js +63 -0
- package/dist/cjs/package/mysql2/lib/commands/auth_switch.js +111 -0
- package/dist/cjs/package/mysql2/lib/commands/binlog_dump.js +109 -0
- package/dist/cjs/package/mysql2/lib/commands/change_user.js +68 -0
- package/dist/cjs/package/mysql2/lib/commands/client_handshake.js +241 -0
- package/dist/cjs/package/mysql2/lib/commands/close_statement.js +18 -0
- package/dist/cjs/package/mysql2/lib/commands/command.js +54 -0
- package/dist/cjs/package/mysql2/lib/commands/execute.js +112 -0
- package/dist/cjs/package/mysql2/lib/commands/index.js +27 -0
- package/dist/cjs/package/mysql2/lib/commands/ping.js +36 -0
- package/dist/cjs/package/mysql2/lib/commands/prepare.js +143 -0
- package/dist/cjs/package/mysql2/lib/commands/query.js +329 -0
- package/dist/cjs/package/mysql2/lib/commands/quit.js +29 -0
- package/dist/cjs/package/mysql2/lib/commands/register_slave.js +27 -0
- package/dist/cjs/package/mysql2/lib/commands/server_handshake.js +203 -0
- package/dist/cjs/package/mysql2/lib/compressed_protocol.js +127 -0
- package/dist/cjs/package/mysql2/lib/connection.js +12 -0
- package/dist/cjs/package/mysql2/lib/connection_config.js +292 -0
- package/dist/cjs/package/mysql2/lib/constants/charset_encodings.js +316 -0
- package/dist/cjs/package/mysql2/lib/constants/charsets.js +317 -0
- package/dist/cjs/package/mysql2/lib/constants/client.js +39 -0
- package/dist/cjs/package/mysql2/lib/constants/commands.js +36 -0
- package/dist/cjs/package/mysql2/lib/constants/cursor.js +8 -0
- package/dist/cjs/package/mysql2/lib/constants/encoding_charset.js +49 -0
- package/dist/cjs/package/mysql2/lib/constants/errors.js +3973 -0
- package/dist/cjs/package/mysql2/lib/constants/field_flags.js +20 -0
- package/dist/cjs/package/mysql2/lib/constants/server_status.js +44 -0
- package/dist/cjs/package/mysql2/lib/constants/session_track.js +11 -0
- package/dist/cjs/package/mysql2/lib/constants/ssl_profiles.js +11 -0
- package/dist/cjs/package/mysql2/lib/constants/types.js +64 -0
- package/dist/cjs/package/mysql2/lib/create_connection.js +10 -0
- package/dist/cjs/package/mysql2/lib/create_pool.js +10 -0
- package/dist/cjs/package/mysql2/lib/create_pool_cluster.js +9 -0
- package/dist/cjs/package/mysql2/lib/helpers.js +86 -0
- package/dist/cjs/package/mysql2/lib/packet_parser.js +195 -0
- package/dist/cjs/package/mysql2/lib/packets/auth_next_factor.js +35 -0
- package/dist/cjs/package/mysql2/lib/packets/auth_switch_request.js +38 -0
- package/dist/cjs/package/mysql2/lib/packets/auth_switch_request_more_data.js +33 -0
- package/dist/cjs/package/mysql2/lib/packets/auth_switch_response.js +30 -0
- package/dist/cjs/package/mysql2/lib/packets/binary_row.js +95 -0
- package/dist/cjs/package/mysql2/lib/packets/binlog_dump.js +33 -0
- package/dist/cjs/package/mysql2/lib/packets/binlog_query_statusvars.js +115 -0
- package/dist/cjs/package/mysql2/lib/packets/change_user.js +97 -0
- package/dist/cjs/package/mysql2/lib/packets/close_statement.js +21 -0
- package/dist/cjs/package/mysql2/lib/packets/column_definition.js +291 -0
- package/dist/cjs/package/mysql2/lib/packets/execute.js +214 -0
- package/dist/cjs/package/mysql2/lib/packets/handshake.js +112 -0
- package/dist/cjs/package/mysql2/lib/packets/handshake_response.js +144 -0
- package/dist/cjs/package/mysql2/lib/packets/index.js +152 -0
- package/dist/cjs/package/mysql2/lib/packets/packet.js +931 -0
- package/dist/cjs/package/mysql2/lib/packets/prepare_statement.js +27 -0
- package/dist/cjs/package/mysql2/lib/packets/prepared_statement_header.js +16 -0
- package/dist/cjs/package/mysql2/lib/packets/query.js +27 -0
- package/dist/cjs/package/mysql2/lib/packets/register_slave.js +46 -0
- package/dist/cjs/package/mysql2/lib/packets/resultset_header.js +118 -0
- package/dist/cjs/package/mysql2/lib/packets/ssl_request.js +25 -0
- package/dist/cjs/package/mysql2/lib/packets/text_row.js +47 -0
- package/dist/cjs/package/mysql2/lib/parsers/binary_parser.js +231 -0
- package/dist/cjs/package/mysql2/lib/parsers/parser_cache.js +66 -0
- package/dist/cjs/package/mysql2/lib/parsers/static_binary_parser.js +211 -0
- package/dist/cjs/package/mysql2/lib/parsers/static_text_parser.js +152 -0
- package/dist/cjs/package/mysql2/lib/parsers/string.js +50 -0
- package/dist/cjs/package/mysql2/lib/parsers/text_parser.js +214 -0
- package/dist/cjs/package/mysql2/lib/pool.js +12 -0
- package/dist/cjs/package/mysql2/lib/pool_cluster.js +369 -0
- package/dist/cjs/package/mysql2/lib/pool_config.js +30 -0
- package/dist/cjs/package/mysql2/lib/pool_connection.js +12 -0
- package/dist/cjs/package/mysql2/lib/promise/connection.js +222 -0
- package/dist/cjs/package/mysql2/lib/promise/inherit_events.js +27 -0
- package/dist/cjs/package/mysql2/lib/promise/make_done_cb.js +19 -0
- package/dist/cjs/package/mysql2/lib/promise/pool.js +112 -0
- package/dist/cjs/package/mysql2/lib/promise/pool_cluster.js +54 -0
- package/dist/cjs/package/mysql2/lib/promise/pool_connection.js +19 -0
- package/dist/cjs/package/mysql2/lib/promise/prepared_statement_info.js +32 -0
- package/dist/cjs/package/mysql2/lib/results_stream.js +38 -0
- package/dist/cjs/package/mysql2/lib/server.js +37 -0
- package/dist/cjs/package/mysql2/package.json +80 -0
- package/dist/cjs/package/mysql2/promise.d.ts +131 -0
- package/dist/cjs/package/mysql2/promise.js +202 -0
- package/dist/cjs/package/mysql2/typings/mysql/LICENSE.txt +15 -0
- package/dist/cjs/package/mysql2/typings/mysql/index.d.ts +95 -0
- package/dist/cjs/package/mysql2/typings/mysql/info.txt +1 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/Auth.d.ts +30 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/Connection.d.ts +428 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/Pool.d.ts +69 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/PoolCluster.d.ts +90 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/PoolConnection.d.ts +10 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/Server.d.ts +11 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/constants/CharsetToEncoding.d.ts +8 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/constants/Charsets.d.ts +326 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/constants/Types.d.ts +70 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/constants/index.d.ts +5 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/parsers/ParserCache.d.ts +4 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/parsers/index.d.ts +18 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/parsers/typeCast.d.ts +54 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/Field.d.ts +10 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +27 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/OkPacket.d.ts +23 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts +13 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts +18 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/RowDataPacket.d.ts +9 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/index.d.ts +28 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/params/ErrorPacketParams.d.ts +6 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/packets/params/OkPacketParams.d.ts +9 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts +40 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/Prepare.d.ts +65 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/Query.d.ts +170 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts +40 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/Sequence.d.ts +5 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts +21 -0
- package/dist/cjs/package/mysql2/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts +21 -0
- package/dist/cjs/package/mysql_backup/index.js +69 -0
- package/dist/cjs/package/mysql_backup/promise.js +187 -0
- package/dist/cjs/server.d.ts +1 -1
- package/dist/cjs/server.d.ts.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/start.js +1 -1
- package/dist/cjs/update.js +1 -1
- package/dist/esm/browser.js +1 -1
- package/dist/esm/getAllRouter/index.js +1 -1
- package/dist/esm/hash/index.js +1 -1
- package/dist/esm/id/index.js +1 -1
- package/dist/esm/id/random.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/jwt/index.js +1 -1
- package/dist/esm/mac/index.js +1 -1
- package/dist/esm/package/mysql2/License +19 -0
- package/dist/esm/package/mysql2/README.md +114 -0
- package/dist/esm/package/mysql2/index.d.ts +1 -0
- package/dist/esm/package/mysql2/index.js +77 -0
- package/dist/esm/package/mysql2/lib/auth_41.js +95 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/caching_sha2_password.js +108 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/caching_sha2_password.md +18 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/index.js +8 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/mysql_clear_password.js +17 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/mysql_native_password.js +34 -0
- package/dist/esm/package/mysql2/lib/auth_plugins/sha256_password.js +59 -0
- package/dist/esm/package/mysql2/lib/base/connection.js +945 -0
- package/dist/esm/package/mysql2/lib/base/pool.js +233 -0
- package/dist/esm/package/mysql2/lib/base/pool_connection.js +63 -0
- package/dist/esm/package/mysql2/lib/commands/auth_switch.js +111 -0
- package/dist/esm/package/mysql2/lib/commands/binlog_dump.js +109 -0
- package/dist/esm/package/mysql2/lib/commands/change_user.js +68 -0
- package/dist/esm/package/mysql2/lib/commands/client_handshake.js +241 -0
- package/dist/esm/package/mysql2/lib/commands/close_statement.js +18 -0
- package/dist/esm/package/mysql2/lib/commands/command.js +54 -0
- package/dist/esm/package/mysql2/lib/commands/execute.js +112 -0
- package/dist/esm/package/mysql2/lib/commands/index.js +27 -0
- package/dist/esm/package/mysql2/lib/commands/ping.js +36 -0
- package/dist/esm/package/mysql2/lib/commands/prepare.js +143 -0
- package/dist/esm/package/mysql2/lib/commands/query.js +329 -0
- package/dist/esm/package/mysql2/lib/commands/quit.js +29 -0
- package/dist/esm/package/mysql2/lib/commands/register_slave.js +27 -0
- package/dist/esm/package/mysql2/lib/commands/server_handshake.js +203 -0
- package/dist/esm/package/mysql2/lib/compressed_protocol.js +127 -0
- package/dist/esm/package/mysql2/lib/connection.js +12 -0
- package/dist/esm/package/mysql2/lib/connection_config.js +292 -0
- package/dist/esm/package/mysql2/lib/constants/charset_encodings.js +316 -0
- package/dist/esm/package/mysql2/lib/constants/charsets.js +317 -0
- package/dist/esm/package/mysql2/lib/constants/client.js +39 -0
- package/dist/esm/package/mysql2/lib/constants/commands.js +36 -0
- package/dist/esm/package/mysql2/lib/constants/cursor.js +8 -0
- package/dist/esm/package/mysql2/lib/constants/encoding_charset.js +49 -0
- package/dist/esm/package/mysql2/lib/constants/errors.js +3973 -0
- package/dist/esm/package/mysql2/lib/constants/field_flags.js +20 -0
- package/dist/esm/package/mysql2/lib/constants/server_status.js +44 -0
- package/dist/esm/package/mysql2/lib/constants/session_track.js +11 -0
- package/dist/esm/package/mysql2/lib/constants/ssl_profiles.js +11 -0
- package/dist/esm/package/mysql2/lib/constants/types.js +64 -0
- package/dist/esm/package/mysql2/lib/create_connection.js +10 -0
- package/dist/esm/package/mysql2/lib/create_pool.js +10 -0
- package/dist/esm/package/mysql2/lib/create_pool_cluster.js +9 -0
- package/dist/esm/package/mysql2/lib/helpers.js +86 -0
- package/dist/esm/package/mysql2/lib/packet_parser.js +195 -0
- package/dist/esm/package/mysql2/lib/packets/auth_next_factor.js +35 -0
- package/dist/esm/package/mysql2/lib/packets/auth_switch_request.js +38 -0
- package/dist/esm/package/mysql2/lib/packets/auth_switch_request_more_data.js +33 -0
- package/dist/esm/package/mysql2/lib/packets/auth_switch_response.js +30 -0
- package/dist/esm/package/mysql2/lib/packets/binary_row.js +95 -0
- package/dist/esm/package/mysql2/lib/packets/binlog_dump.js +33 -0
- package/dist/esm/package/mysql2/lib/packets/binlog_query_statusvars.js +115 -0
- package/dist/esm/package/mysql2/lib/packets/change_user.js +97 -0
- package/dist/esm/package/mysql2/lib/packets/close_statement.js +21 -0
- package/dist/esm/package/mysql2/lib/packets/column_definition.js +291 -0
- package/dist/esm/package/mysql2/lib/packets/execute.js +214 -0
- package/dist/esm/package/mysql2/lib/packets/handshake.js +112 -0
- package/dist/esm/package/mysql2/lib/packets/handshake_response.js +144 -0
- package/dist/esm/package/mysql2/lib/packets/index.js +152 -0
- package/dist/esm/package/mysql2/lib/packets/packet.js +931 -0
- package/dist/esm/package/mysql2/lib/packets/prepare_statement.js +27 -0
- package/dist/esm/package/mysql2/lib/packets/prepared_statement_header.js +16 -0
- package/dist/esm/package/mysql2/lib/packets/query.js +27 -0
- package/dist/esm/package/mysql2/lib/packets/register_slave.js +46 -0
- package/dist/esm/package/mysql2/lib/packets/resultset_header.js +118 -0
- package/dist/esm/package/mysql2/lib/packets/ssl_request.js +25 -0
- package/dist/esm/package/mysql2/lib/packets/text_row.js +47 -0
- package/dist/esm/package/mysql2/lib/parsers/binary_parser.js +231 -0
- package/dist/esm/package/mysql2/lib/parsers/parser_cache.js +66 -0
- package/dist/esm/package/mysql2/lib/parsers/static_binary_parser.js +211 -0
- package/dist/esm/package/mysql2/lib/parsers/static_text_parser.js +152 -0
- package/dist/esm/package/mysql2/lib/parsers/string.js +50 -0
- package/dist/esm/package/mysql2/lib/parsers/text_parser.js +214 -0
- package/dist/esm/package/mysql2/lib/pool.js +12 -0
- package/dist/esm/package/mysql2/lib/pool_cluster.js +369 -0
- package/dist/esm/package/mysql2/lib/pool_config.js +30 -0
- package/dist/esm/package/mysql2/lib/pool_connection.js +12 -0
- package/dist/esm/package/mysql2/lib/promise/connection.js +222 -0
- package/dist/esm/package/mysql2/lib/promise/inherit_events.js +27 -0
- package/dist/esm/package/mysql2/lib/promise/make_done_cb.js +19 -0
- package/dist/esm/package/mysql2/lib/promise/pool.js +112 -0
- package/dist/esm/package/mysql2/lib/promise/pool_cluster.js +54 -0
- package/dist/esm/package/mysql2/lib/promise/pool_connection.js +19 -0
- package/dist/esm/package/mysql2/lib/promise/prepared_statement_info.js +32 -0
- package/dist/esm/package/mysql2/lib/results_stream.js +38 -0
- package/dist/esm/package/mysql2/lib/server.js +37 -0
- package/dist/esm/package/mysql2/package.json +80 -0
- package/dist/esm/package/mysql2/promise.d.ts +131 -0
- package/dist/esm/package/mysql2/promise.js +202 -0
- package/dist/esm/package/mysql2/typings/mysql/LICENSE.txt +15 -0
- package/dist/esm/package/mysql2/typings/mysql/index.d.ts +95 -0
- package/dist/esm/package/mysql2/typings/mysql/info.txt +1 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/Auth.d.ts +30 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/Connection.d.ts +428 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/Pool.d.ts +69 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/PoolCluster.d.ts +90 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/PoolConnection.d.ts +10 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/Server.d.ts +11 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/constants/CharsetToEncoding.d.ts +8 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/constants/Charsets.d.ts +326 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/constants/Types.d.ts +70 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/constants/index.d.ts +5 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/parsers/ParserCache.d.ts +4 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/parsers/index.d.ts +18 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/parsers/typeCast.d.ts +54 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/Field.d.ts +10 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +27 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/OkPacket.d.ts +23 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts +13 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts +18 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/RowDataPacket.d.ts +9 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/index.d.ts +28 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/params/ErrorPacketParams.d.ts +6 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/packets/params/OkPacketParams.d.ts +9 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts +40 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/Prepare.d.ts +65 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/Query.d.ts +170 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts +40 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/Sequence.d.ts +5 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts +21 -0
- package/dist/esm/package/mysql2/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts +21 -0
- package/dist/esm/package/mysql_backup/index.js +69 -0
- package/dist/esm/package/mysql_backup/promise.js +187 -0
- package/dist/esm/server.d.ts +1 -1
- package/dist/esm/server.d.ts.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/start.js +1 -1
- package/dist/esm/update.js +1 -1
- package/package.json +3 -4
@@ -0,0 +1,931 @@
|
|
1
|
+
// This file was modified by Oracle on June 1, 2021.
|
2
|
+
// A comment describing some changes in the strict default SQL mode regarding
|
3
|
+
// non-standard dates was introduced.
|
4
|
+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
5
|
+
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
const ErrorCodeToName = require('../constants/errors.js');
|
9
|
+
const NativeBuffer = require('buffer').Buffer;
|
10
|
+
const Long = require('long');
|
11
|
+
const StringParser = require('../parsers/string.js');
|
12
|
+
const Types = require('../constants/types.js');
|
13
|
+
const INVALID_DATE = new Date(NaN);
|
14
|
+
|
15
|
+
// this is nearly duplicate of previous function so generated code is not slower
|
16
|
+
// due to "if (dateStrings)" branching
|
17
|
+
const pad = '000000000000';
|
18
|
+
function leftPad(num, value) {
|
19
|
+
const s = value.toString();
|
20
|
+
// if we don't need to pad
|
21
|
+
if (s.length >= num) {
|
22
|
+
return s;
|
23
|
+
}
|
24
|
+
return (pad + s).slice(-num);
|
25
|
+
}
|
26
|
+
|
27
|
+
// The whole reason parse* function below exist
|
28
|
+
// is because String creation is relatively expensive (at least with V8), and if we have
|
29
|
+
// a buffer with "12345" content ideally we would like to bypass intermediate
|
30
|
+
// "12345" string creation and directly build 12345 number out of
|
31
|
+
// <Buffer 31 32 33 34 35> data.
|
32
|
+
// In my benchmarks the difference is ~25M 8-digit numbers per second vs
|
33
|
+
// 4.5 M using Number(packet.readLengthCodedString())
|
34
|
+
// not used when size is close to max precision as series of *10 accumulate error
|
35
|
+
// and approximate result mihgt be diffreent from (approximate as well) Number(bigNumStringValue))
|
36
|
+
// In the futire node version if speed difference is smaller parse* functions might be removed
|
37
|
+
// don't consider them as Packet public API
|
38
|
+
|
39
|
+
const minus = '-'.charCodeAt(0);
|
40
|
+
const plus = '+'.charCodeAt(0);
|
41
|
+
|
42
|
+
// TODO: handle E notation
|
43
|
+
const dot = '.'.charCodeAt(0);
|
44
|
+
const exponent = 'e'.charCodeAt(0);
|
45
|
+
const exponentCapital = 'E'.charCodeAt(0);
|
46
|
+
|
47
|
+
class Packet {
|
48
|
+
constructor(id, buffer, start, end) {
|
49
|
+
// hot path, enable checks when testing only
|
50
|
+
// if (!Buffer.isBuffer(buffer) || typeof start == 'undefined' || typeof end == 'undefined')
|
51
|
+
// throw new Error('invalid packet');
|
52
|
+
this.sequenceId = id;
|
53
|
+
this.numPackets = 1;
|
54
|
+
this.buffer = buffer;
|
55
|
+
this.start = start;
|
56
|
+
this.offset = start + 4;
|
57
|
+
this.end = end;
|
58
|
+
}
|
59
|
+
|
60
|
+
// ==============================
|
61
|
+
// readers
|
62
|
+
// ==============================
|
63
|
+
reset() {
|
64
|
+
this.offset = this.start + 4;
|
65
|
+
}
|
66
|
+
|
67
|
+
length() {
|
68
|
+
return this.end - this.start;
|
69
|
+
}
|
70
|
+
|
71
|
+
slice() {
|
72
|
+
return this.buffer.slice(this.start, this.end);
|
73
|
+
}
|
74
|
+
|
75
|
+
dump() {
|
76
|
+
// eslint-disable-next-line no-console
|
77
|
+
console.log(
|
78
|
+
[this.buffer.asciiSlice(this.start, this.end)],
|
79
|
+
this.buffer.slice(this.start, this.end),
|
80
|
+
this.length(),
|
81
|
+
this.sequenceId
|
82
|
+
);
|
83
|
+
}
|
84
|
+
|
85
|
+
haveMoreData() {
|
86
|
+
return this.end > this.offset;
|
87
|
+
}
|
88
|
+
|
89
|
+
skip(num) {
|
90
|
+
this.offset += num;
|
91
|
+
}
|
92
|
+
|
93
|
+
readInt8() {
|
94
|
+
return this.buffer[this.offset++];
|
95
|
+
}
|
96
|
+
|
97
|
+
readInt16() {
|
98
|
+
this.offset += 2;
|
99
|
+
return this.buffer.readUInt16LE(this.offset - 2);
|
100
|
+
}
|
101
|
+
|
102
|
+
readInt24() {
|
103
|
+
return this.readInt16() + (this.readInt8() << 16);
|
104
|
+
}
|
105
|
+
|
106
|
+
readInt32() {
|
107
|
+
this.offset += 4;
|
108
|
+
return this.buffer.readUInt32LE(this.offset - 4);
|
109
|
+
}
|
110
|
+
|
111
|
+
readSInt8() {
|
112
|
+
return this.buffer.readInt8(this.offset++);
|
113
|
+
}
|
114
|
+
|
115
|
+
readSInt16() {
|
116
|
+
this.offset += 2;
|
117
|
+
return this.buffer.readInt16LE(this.offset - 2);
|
118
|
+
}
|
119
|
+
|
120
|
+
readSInt32() {
|
121
|
+
this.offset += 4;
|
122
|
+
return this.buffer.readInt32LE(this.offset - 4);
|
123
|
+
}
|
124
|
+
|
125
|
+
readInt64JSNumber() {
|
126
|
+
const word0 = this.readInt32();
|
127
|
+
const word1 = this.readInt32();
|
128
|
+
const l = new Long(word0, word1, true);
|
129
|
+
return l.toNumber();
|
130
|
+
}
|
131
|
+
|
132
|
+
readSInt64JSNumber() {
|
133
|
+
const word0 = this.readInt32();
|
134
|
+
const word1 = this.readInt32();
|
135
|
+
if (!(word1 & 0x80000000)) {
|
136
|
+
return word0 + 0x100000000 * word1;
|
137
|
+
}
|
138
|
+
const l = new Long(word0, word1, false);
|
139
|
+
return l.toNumber();
|
140
|
+
}
|
141
|
+
|
142
|
+
readInt64String() {
|
143
|
+
const word0 = this.readInt32();
|
144
|
+
const word1 = this.readInt32();
|
145
|
+
const res = new Long(word0, word1, true);
|
146
|
+
return res.toString();
|
147
|
+
}
|
148
|
+
|
149
|
+
readSInt64String() {
|
150
|
+
const word0 = this.readInt32();
|
151
|
+
const word1 = this.readInt32();
|
152
|
+
const res = new Long(word0, word1, false);
|
153
|
+
return res.toString();
|
154
|
+
}
|
155
|
+
|
156
|
+
readInt64() {
|
157
|
+
const word0 = this.readInt32();
|
158
|
+
const word1 = this.readInt32();
|
159
|
+
let res = new Long(word0, word1, true);
|
160
|
+
const resNumber = res.toNumber();
|
161
|
+
const resString = res.toString();
|
162
|
+
res = resNumber.toString() === resString ? resNumber : resString;
|
163
|
+
return res;
|
164
|
+
}
|
165
|
+
|
166
|
+
readSInt64() {
|
167
|
+
const word0 = this.readInt32();
|
168
|
+
const word1 = this.readInt32();
|
169
|
+
let res = new Long(word0, word1, false);
|
170
|
+
const resNumber = res.toNumber();
|
171
|
+
const resString = res.toString();
|
172
|
+
res = resNumber.toString() === resString ? resNumber : resString;
|
173
|
+
return res;
|
174
|
+
}
|
175
|
+
|
176
|
+
isEOF() {
|
177
|
+
return this.buffer[this.offset] === 0xfe && this.length() < 13;
|
178
|
+
}
|
179
|
+
|
180
|
+
eofStatusFlags() {
|
181
|
+
return this.buffer.readInt16LE(this.offset + 3);
|
182
|
+
}
|
183
|
+
|
184
|
+
eofWarningCount() {
|
185
|
+
return this.buffer.readInt16LE(this.offset + 1);
|
186
|
+
}
|
187
|
+
|
188
|
+
readLengthCodedNumber(bigNumberStrings, signed) {
|
189
|
+
const byte1 = this.buffer[this.offset++];
|
190
|
+
if (byte1 < 251) {
|
191
|
+
return byte1;
|
192
|
+
}
|
193
|
+
return this.readLengthCodedNumberExt(byte1, bigNumberStrings, signed);
|
194
|
+
}
|
195
|
+
|
196
|
+
readLengthCodedNumberSigned(bigNumberStrings) {
|
197
|
+
return this.readLengthCodedNumber(bigNumberStrings, true);
|
198
|
+
}
|
199
|
+
|
200
|
+
readLengthCodedNumberExt(tag, bigNumberStrings, signed) {
|
201
|
+
let word0, word1;
|
202
|
+
let res;
|
203
|
+
if (tag === 0xfb) {
|
204
|
+
return null;
|
205
|
+
}
|
206
|
+
if (tag === 0xfc) {
|
207
|
+
return this.readInt8() + (this.readInt8() << 8);
|
208
|
+
}
|
209
|
+
if (tag === 0xfd) {
|
210
|
+
return this.readInt8() + (this.readInt8() << 8) + (this.readInt8() << 16);
|
211
|
+
}
|
212
|
+
if (tag === 0xfe) {
|
213
|
+
// TODO: check version
|
214
|
+
// Up to MySQL 3.22, 0xfe was followed by a 4-byte integer.
|
215
|
+
word0 = this.readInt32();
|
216
|
+
word1 = this.readInt32();
|
217
|
+
if (word1 === 0) {
|
218
|
+
return word0; // don't convert to float if possible
|
219
|
+
}
|
220
|
+
if (word1 < 2097152) {
|
221
|
+
// max exact float point int, 2^52 / 2^32
|
222
|
+
return word1 * 0x100000000 + word0;
|
223
|
+
}
|
224
|
+
res = new Long(word0, word1, !signed); // Long need unsigned
|
225
|
+
const resNumber = res.toNumber();
|
226
|
+
const resString = res.toString();
|
227
|
+
res = resNumber.toString() === resString ? resNumber : resString;
|
228
|
+
return bigNumberStrings ? resString : res;
|
229
|
+
}
|
230
|
+
// eslint-disable-next-line no-console
|
231
|
+
console.trace();
|
232
|
+
throw new Error(`Should not reach here: ${tag}`);
|
233
|
+
}
|
234
|
+
|
235
|
+
readFloat() {
|
236
|
+
const res = this.buffer.readFloatLE(this.offset);
|
237
|
+
this.offset += 4;
|
238
|
+
return res;
|
239
|
+
}
|
240
|
+
|
241
|
+
readDouble() {
|
242
|
+
const res = this.buffer.readDoubleLE(this.offset);
|
243
|
+
this.offset += 8;
|
244
|
+
return res;
|
245
|
+
}
|
246
|
+
|
247
|
+
readBuffer(len) {
|
248
|
+
if (typeof len === 'undefined') {
|
249
|
+
len = this.end - this.offset;
|
250
|
+
}
|
251
|
+
this.offset += len;
|
252
|
+
return this.buffer.slice(this.offset - len, this.offset);
|
253
|
+
}
|
254
|
+
|
255
|
+
// DATE, DATETIME and TIMESTAMP
|
256
|
+
readDateTime(timezone) {
|
257
|
+
if (!timezone || timezone === 'Z' || timezone === 'local') {
|
258
|
+
const length = this.readInt8();
|
259
|
+
if (length === 0xfb) {
|
260
|
+
return null;
|
261
|
+
}
|
262
|
+
let y = 0;
|
263
|
+
let m = 0;
|
264
|
+
let d = 0;
|
265
|
+
let H = 0;
|
266
|
+
let M = 0;
|
267
|
+
let S = 0;
|
268
|
+
let ms = 0;
|
269
|
+
if (length > 3) {
|
270
|
+
y = this.readInt16();
|
271
|
+
m = this.readInt8();
|
272
|
+
d = this.readInt8();
|
273
|
+
}
|
274
|
+
if (length > 6) {
|
275
|
+
H = this.readInt8();
|
276
|
+
M = this.readInt8();
|
277
|
+
S = this.readInt8();
|
278
|
+
}
|
279
|
+
if (length > 10) {
|
280
|
+
ms = this.readInt32() / 1000;
|
281
|
+
}
|
282
|
+
// NO_ZERO_DATE mode and NO_ZERO_IN_DATE mode are part of the strict
|
283
|
+
// default SQL mode used by MySQL 8.0. This means that non-standard
|
284
|
+
// dates like '0000-00-00' become NULL. For older versions and other
|
285
|
+
// possible MySQL flavours we still need to account for the
|
286
|
+
// non-standard behaviour.
|
287
|
+
if (y + m + d + H + M + S + ms === 0) {
|
288
|
+
return INVALID_DATE;
|
289
|
+
}
|
290
|
+
if (timezone === 'Z') {
|
291
|
+
return new Date(Date.UTC(y, m - 1, d, H, M, S, ms));
|
292
|
+
}
|
293
|
+
return new Date(y, m - 1, d, H, M, S, ms);
|
294
|
+
}
|
295
|
+
let str = this.readDateTimeString(6, 'T', null);
|
296
|
+
if (str.length === 10) {
|
297
|
+
str += 'T00:00:00';
|
298
|
+
}
|
299
|
+
return new Date(str + timezone);
|
300
|
+
}
|
301
|
+
|
302
|
+
readDateTimeString(decimals, timeSep, columnType) {
|
303
|
+
const length = this.readInt8();
|
304
|
+
let y = 0;
|
305
|
+
let m = 0;
|
306
|
+
let d = 0;
|
307
|
+
let H = 0;
|
308
|
+
let M = 0;
|
309
|
+
let S = 0;
|
310
|
+
let ms = 0;
|
311
|
+
let str;
|
312
|
+
if (length > 3) {
|
313
|
+
y = this.readInt16();
|
314
|
+
m = this.readInt8();
|
315
|
+
d = this.readInt8();
|
316
|
+
str = [leftPad(4, y), leftPad(2, m), leftPad(2, d)].join('-');
|
317
|
+
}
|
318
|
+
if (length > 6) {
|
319
|
+
H = this.readInt8();
|
320
|
+
M = this.readInt8();
|
321
|
+
S = this.readInt8();
|
322
|
+
str += `${timeSep || ' '}${[
|
323
|
+
leftPad(2, H),
|
324
|
+
leftPad(2, M),
|
325
|
+
leftPad(2, S),
|
326
|
+
].join(':')}`;
|
327
|
+
} else if (columnType === Types.DATETIME) {
|
328
|
+
str += ' 00:00:00';
|
329
|
+
}
|
330
|
+
if (length > 10) {
|
331
|
+
ms = this.readInt32();
|
332
|
+
str += '.';
|
333
|
+
if (decimals) {
|
334
|
+
ms = leftPad(6, ms);
|
335
|
+
if (ms.length > decimals) {
|
336
|
+
ms = ms.substring(0, decimals); // rounding is done at the MySQL side, only 0 are here
|
337
|
+
}
|
338
|
+
}
|
339
|
+
str += ms;
|
340
|
+
}
|
341
|
+
return str;
|
342
|
+
}
|
343
|
+
|
344
|
+
// TIME - value as a string, Can be negative
|
345
|
+
readTimeString(convertTtoMs) {
|
346
|
+
const length = this.readInt8();
|
347
|
+
if (length === 0) {
|
348
|
+
return '00:00:00';
|
349
|
+
}
|
350
|
+
const sign = this.readInt8() ? -1 : 1; // 'isNegative' flag byte
|
351
|
+
let d = 0;
|
352
|
+
let H = 0;
|
353
|
+
let M = 0;
|
354
|
+
let S = 0;
|
355
|
+
let ms = 0;
|
356
|
+
if (length > 6) {
|
357
|
+
d = this.readInt32();
|
358
|
+
H = this.readInt8();
|
359
|
+
M = this.readInt8();
|
360
|
+
S = this.readInt8();
|
361
|
+
}
|
362
|
+
if (length > 10) {
|
363
|
+
ms = this.readInt32();
|
364
|
+
}
|
365
|
+
if (convertTtoMs) {
|
366
|
+
H += d * 24;
|
367
|
+
M += H * 60;
|
368
|
+
S += M * 60;
|
369
|
+
ms += S * 1000;
|
370
|
+
ms *= sign;
|
371
|
+
return ms;
|
372
|
+
}
|
373
|
+
// Format follows mySQL TIME format ([-][h]hh:mm:ss[.u[u[u[u[u[u]]]]]])
|
374
|
+
// For positive times below 24 hours, this makes it equal to ISO 8601 times
|
375
|
+
return (
|
376
|
+
(sign === -1 ? '-' : '') +
|
377
|
+
[leftPad(2, d * 24 + H), leftPad(2, M), leftPad(2, S)].join(':') +
|
378
|
+
(ms ? `.${ms}`.replace(/0+$/, '') : '')
|
379
|
+
);
|
380
|
+
}
|
381
|
+
|
382
|
+
readLengthCodedString(encoding) {
|
383
|
+
const len = this.readLengthCodedNumber();
|
384
|
+
// TODO: check manually first byte here to avoid polymorphic return type?
|
385
|
+
if (len === null) {
|
386
|
+
return null;
|
387
|
+
}
|
388
|
+
this.offset += len;
|
389
|
+
// TODO: Use characterSetCode to get proper encoding
|
390
|
+
// https://github.com/sidorares/node-mysql2/pull/374
|
391
|
+
return StringParser.decode(
|
392
|
+
this.buffer,
|
393
|
+
encoding,
|
394
|
+
this.offset - len,
|
395
|
+
this.offset
|
396
|
+
);
|
397
|
+
}
|
398
|
+
|
399
|
+
readLengthCodedBuffer() {
|
400
|
+
const len = this.readLengthCodedNumber();
|
401
|
+
if (len === null) {
|
402
|
+
return null;
|
403
|
+
}
|
404
|
+
return this.readBuffer(len);
|
405
|
+
}
|
406
|
+
|
407
|
+
readNullTerminatedString(encoding) {
|
408
|
+
const start = this.offset;
|
409
|
+
let end = this.offset;
|
410
|
+
while (this.buffer[end]) {
|
411
|
+
end = end + 1; // TODO: handle OOB check
|
412
|
+
}
|
413
|
+
this.offset = end + 1;
|
414
|
+
return StringParser.decode(this.buffer, encoding, start, end);
|
415
|
+
}
|
416
|
+
|
417
|
+
// TODO reuse?
|
418
|
+
readString(len, encoding) {
|
419
|
+
if (typeof len === 'string' && typeof encoding === 'undefined') {
|
420
|
+
encoding = len;
|
421
|
+
len = undefined;
|
422
|
+
}
|
423
|
+
if (typeof len === 'undefined') {
|
424
|
+
len = this.end - this.offset;
|
425
|
+
}
|
426
|
+
this.offset += len;
|
427
|
+
return StringParser.decode(
|
428
|
+
this.buffer,
|
429
|
+
encoding,
|
430
|
+
this.offset - len,
|
431
|
+
this.offset
|
432
|
+
);
|
433
|
+
}
|
434
|
+
|
435
|
+
parseInt(len, supportBigNumbers) {
|
436
|
+
if (len === null) {
|
437
|
+
return null;
|
438
|
+
}
|
439
|
+
if (len >= 14 && !supportBigNumbers) {
|
440
|
+
const s = this.buffer.toString('ascii', this.offset, this.offset + len);
|
441
|
+
this.offset += len;
|
442
|
+
return Number(s);
|
443
|
+
}
|
444
|
+
let result = 0;
|
445
|
+
const start = this.offset;
|
446
|
+
const end = this.offset + len;
|
447
|
+
let sign = 1;
|
448
|
+
if (len === 0) {
|
449
|
+
return 0; // TODO: assert? exception?
|
450
|
+
}
|
451
|
+
if (this.buffer[this.offset] === minus) {
|
452
|
+
this.offset++;
|
453
|
+
sign = -1;
|
454
|
+
}
|
455
|
+
// max precise int is 9007199254740992
|
456
|
+
let str;
|
457
|
+
const numDigits = end - this.offset;
|
458
|
+
if (supportBigNumbers) {
|
459
|
+
if (numDigits >= 15) {
|
460
|
+
str = this.readString(end - this.offset, 'binary');
|
461
|
+
result = parseInt(str, 10);
|
462
|
+
if (result.toString() === str) {
|
463
|
+
return sign * result;
|
464
|
+
}
|
465
|
+
return sign === -1 ? `-${str}` : str;
|
466
|
+
}
|
467
|
+
if (numDigits > 16) {
|
468
|
+
str = this.readString(end - this.offset);
|
469
|
+
return sign === -1 ? `-${str}` : str;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
if (this.buffer[this.offset] === plus) {
|
473
|
+
this.offset++; // just ignore
|
474
|
+
}
|
475
|
+
while (this.offset < end) {
|
476
|
+
result *= 10;
|
477
|
+
result += this.buffer[this.offset] - 48;
|
478
|
+
this.offset++;
|
479
|
+
}
|
480
|
+
const num = result * sign;
|
481
|
+
if (!supportBigNumbers) {
|
482
|
+
return num;
|
483
|
+
}
|
484
|
+
str = this.buffer.toString('ascii', start, end);
|
485
|
+
if (num.toString() === str) {
|
486
|
+
return num;
|
487
|
+
}
|
488
|
+
return str;
|
489
|
+
}
|
490
|
+
|
491
|
+
// note that if value of inputNumberAsString is bigger than MAX_SAFE_INTEGER
|
492
|
+
// ( or smaller than MIN_SAFE_INTEGER ) the parseIntNoBigCheck result might be
|
493
|
+
// different from what you would get from Number(inputNumberAsString)
|
494
|
+
// String(parseIntNoBigCheck) <> String(Number(inputNumberAsString)) <> inputNumberAsString
|
495
|
+
parseIntNoBigCheck(len) {
|
496
|
+
if (len === null) {
|
497
|
+
return null;
|
498
|
+
}
|
499
|
+
let result = 0;
|
500
|
+
const end = this.offset + len;
|
501
|
+
let sign = 1;
|
502
|
+
if (len === 0) {
|
503
|
+
return 0; // TODO: assert? exception?
|
504
|
+
}
|
505
|
+
if (this.buffer[this.offset] === minus) {
|
506
|
+
this.offset++;
|
507
|
+
sign = -1;
|
508
|
+
}
|
509
|
+
if (this.buffer[this.offset] === plus) {
|
510
|
+
this.offset++; // just ignore
|
511
|
+
}
|
512
|
+
while (this.offset < end) {
|
513
|
+
result *= 10;
|
514
|
+
result += this.buffer[this.offset] - 48;
|
515
|
+
this.offset++;
|
516
|
+
}
|
517
|
+
return result * sign;
|
518
|
+
}
|
519
|
+
|
520
|
+
// copy-paste from https://github.com/mysqljs/mysql/blob/master/lib/protocol/Parser.js
|
521
|
+
parseGeometryValue() {
|
522
|
+
const buffer = this.readLengthCodedBuffer();
|
523
|
+
let offset = 4;
|
524
|
+
if (buffer === null || !buffer.length) {
|
525
|
+
return null;
|
526
|
+
}
|
527
|
+
function parseGeometry() {
|
528
|
+
let x, y, i, j, numPoints, line;
|
529
|
+
let result = null;
|
530
|
+
const byteOrder = buffer.readUInt8(offset);
|
531
|
+
offset += 1;
|
532
|
+
const wkbType = byteOrder
|
533
|
+
? buffer.readUInt32LE(offset)
|
534
|
+
: buffer.readUInt32BE(offset);
|
535
|
+
offset += 4;
|
536
|
+
switch (wkbType) {
|
537
|
+
case 1: // WKBPoint
|
538
|
+
x = byteOrder
|
539
|
+
? buffer.readDoubleLE(offset)
|
540
|
+
: buffer.readDoubleBE(offset);
|
541
|
+
offset += 8;
|
542
|
+
y = byteOrder
|
543
|
+
? buffer.readDoubleLE(offset)
|
544
|
+
: buffer.readDoubleBE(offset);
|
545
|
+
offset += 8;
|
546
|
+
result = { x: x, y: y };
|
547
|
+
break;
|
548
|
+
case 2: // WKBLineString
|
549
|
+
numPoints = byteOrder
|
550
|
+
? buffer.readUInt32LE(offset)
|
551
|
+
: buffer.readUInt32BE(offset);
|
552
|
+
offset += 4;
|
553
|
+
result = [];
|
554
|
+
for (i = numPoints; i > 0; i--) {
|
555
|
+
x = byteOrder
|
556
|
+
? buffer.readDoubleLE(offset)
|
557
|
+
: buffer.readDoubleBE(offset);
|
558
|
+
offset += 8;
|
559
|
+
y = byteOrder
|
560
|
+
? buffer.readDoubleLE(offset)
|
561
|
+
: buffer.readDoubleBE(offset);
|
562
|
+
offset += 8;
|
563
|
+
result.push({ x: x, y: y });
|
564
|
+
}
|
565
|
+
break;
|
566
|
+
case 3: // WKBPolygon
|
567
|
+
// eslint-disable-next-line no-case-declarations
|
568
|
+
const numRings = byteOrder
|
569
|
+
? buffer.readUInt32LE(offset)
|
570
|
+
: buffer.readUInt32BE(offset);
|
571
|
+
offset += 4;
|
572
|
+
result = [];
|
573
|
+
for (i = numRings; i > 0; i--) {
|
574
|
+
numPoints = byteOrder
|
575
|
+
? buffer.readUInt32LE(offset)
|
576
|
+
: buffer.readUInt32BE(offset);
|
577
|
+
offset += 4;
|
578
|
+
line = [];
|
579
|
+
for (j = numPoints; j > 0; j--) {
|
580
|
+
x = byteOrder
|
581
|
+
? buffer.readDoubleLE(offset)
|
582
|
+
: buffer.readDoubleBE(offset);
|
583
|
+
offset += 8;
|
584
|
+
y = byteOrder
|
585
|
+
? buffer.readDoubleLE(offset)
|
586
|
+
: buffer.readDoubleBE(offset);
|
587
|
+
offset += 8;
|
588
|
+
line.push({ x: x, y: y });
|
589
|
+
}
|
590
|
+
result.push(line);
|
591
|
+
}
|
592
|
+
break;
|
593
|
+
case 4: // WKBMultiPoint
|
594
|
+
case 5: // WKBMultiLineString
|
595
|
+
case 6: // WKBMultiPolygon
|
596
|
+
case 7: // WKBGeometryCollection
|
597
|
+
// eslint-disable-next-line no-case-declarations
|
598
|
+
const num = byteOrder
|
599
|
+
? buffer.readUInt32LE(offset)
|
600
|
+
: buffer.readUInt32BE(offset);
|
601
|
+
offset += 4;
|
602
|
+
result = [];
|
603
|
+
for (i = num; i > 0; i--) {
|
604
|
+
result.push(parseGeometry());
|
605
|
+
}
|
606
|
+
break;
|
607
|
+
}
|
608
|
+
return result;
|
609
|
+
}
|
610
|
+
return parseGeometry();
|
611
|
+
}
|
612
|
+
|
613
|
+
parseVector() {
|
614
|
+
const bufLen = this.readLengthCodedNumber();
|
615
|
+
const vectorEnd = this.offset + bufLen;
|
616
|
+
const result = [];
|
617
|
+
while (this.offset < vectorEnd && this.offset < this.end) {
|
618
|
+
result.push(this.readFloat());
|
619
|
+
}
|
620
|
+
return result;
|
621
|
+
}
|
622
|
+
|
623
|
+
parseDate(timezone) {
|
624
|
+
const strLen = this.readLengthCodedNumber();
|
625
|
+
if (strLen === null) {
|
626
|
+
return null;
|
627
|
+
}
|
628
|
+
if (strLen !== 10) {
|
629
|
+
// we expect only YYYY-MM-DD here.
|
630
|
+
// if for some reason it's not the case return invalid date
|
631
|
+
return new Date(NaN);
|
632
|
+
}
|
633
|
+
const y = this.parseInt(4);
|
634
|
+
this.offset++; // -
|
635
|
+
const m = this.parseInt(2);
|
636
|
+
this.offset++; // -
|
637
|
+
const d = this.parseInt(2);
|
638
|
+
if (!timezone || timezone === 'local') {
|
639
|
+
return new Date(y, m - 1, d);
|
640
|
+
}
|
641
|
+
if (timezone === 'Z') {
|
642
|
+
return new Date(Date.UTC(y, m - 1, d));
|
643
|
+
}
|
644
|
+
return new Date(
|
645
|
+
`${leftPad(4, y)}-${leftPad(2, m)}-${leftPad(2, d)}T00:00:00${timezone}`
|
646
|
+
);
|
647
|
+
}
|
648
|
+
|
649
|
+
parseDateTime(timezone) {
|
650
|
+
const str = this.readLengthCodedString('binary');
|
651
|
+
if (str === null) {
|
652
|
+
return null;
|
653
|
+
}
|
654
|
+
if (!timezone || timezone === 'local') {
|
655
|
+
return new Date(str);
|
656
|
+
}
|
657
|
+
return new Date(`${str}${timezone}`);
|
658
|
+
}
|
659
|
+
|
660
|
+
parseFloat(len) {
|
661
|
+
if (len === null) {
|
662
|
+
return null;
|
663
|
+
}
|
664
|
+
let result = 0;
|
665
|
+
const end = this.offset + len;
|
666
|
+
let factor = 1;
|
667
|
+
let pastDot = false;
|
668
|
+
let charCode = 0;
|
669
|
+
if (len === 0) {
|
670
|
+
return 0; // TODO: assert? exception?
|
671
|
+
}
|
672
|
+
if (this.buffer[this.offset] === minus) {
|
673
|
+
this.offset++;
|
674
|
+
factor = -1;
|
675
|
+
}
|
676
|
+
if (this.buffer[this.offset] === plus) {
|
677
|
+
this.offset++; // just ignore
|
678
|
+
}
|
679
|
+
while (this.offset < end) {
|
680
|
+
charCode = this.buffer[this.offset];
|
681
|
+
if (charCode === dot) {
|
682
|
+
pastDot = true;
|
683
|
+
this.offset++;
|
684
|
+
} else if (charCode === exponent || charCode === exponentCapital) {
|
685
|
+
this.offset++;
|
686
|
+
const exponentValue = this.parseInt(end - this.offset);
|
687
|
+
return (result / factor) * Math.pow(10, exponentValue);
|
688
|
+
} else {
|
689
|
+
result *= 10;
|
690
|
+
result += this.buffer[this.offset] - 48;
|
691
|
+
this.offset++;
|
692
|
+
if (pastDot) {
|
693
|
+
factor = factor * 10;
|
694
|
+
}
|
695
|
+
}
|
696
|
+
}
|
697
|
+
return result / factor;
|
698
|
+
}
|
699
|
+
|
700
|
+
parseLengthCodedIntNoBigCheck() {
|
701
|
+
return this.parseIntNoBigCheck(this.readLengthCodedNumber());
|
702
|
+
}
|
703
|
+
|
704
|
+
parseLengthCodedInt(supportBigNumbers) {
|
705
|
+
return this.parseInt(this.readLengthCodedNumber(), supportBigNumbers);
|
706
|
+
}
|
707
|
+
|
708
|
+
parseLengthCodedIntString() {
|
709
|
+
return this.readLengthCodedString('binary');
|
710
|
+
}
|
711
|
+
|
712
|
+
parseLengthCodedFloat() {
|
713
|
+
return this.parseFloat(this.readLengthCodedNumber());
|
714
|
+
}
|
715
|
+
|
716
|
+
peekByte() {
|
717
|
+
return this.buffer[this.offset];
|
718
|
+
}
|
719
|
+
|
720
|
+
// OxFE is often used as "Alt" flag - not ok, not error.
|
721
|
+
// For example, it's first byte of AuthSwitchRequest
|
722
|
+
isAlt() {
|
723
|
+
return this.peekByte() === 0xfe;
|
724
|
+
}
|
725
|
+
|
726
|
+
isError() {
|
727
|
+
return this.peekByte() === 0xff;
|
728
|
+
}
|
729
|
+
|
730
|
+
asError(encoding) {
|
731
|
+
this.reset();
|
732
|
+
this.readInt8(); // fieldCount
|
733
|
+
const errorCode = this.readInt16();
|
734
|
+
let sqlState = '';
|
735
|
+
if (this.buffer[this.offset] === 0x23) {
|
736
|
+
this.skip(1);
|
737
|
+
sqlState = this.readBuffer(5).toString();
|
738
|
+
}
|
739
|
+
const message = this.readString(undefined, encoding);
|
740
|
+
const err = new Error(message);
|
741
|
+
err.code = ErrorCodeToName[errorCode];
|
742
|
+
err.errno = errorCode;
|
743
|
+
err.sqlState = sqlState;
|
744
|
+
err.sqlMessage = message;
|
745
|
+
return err;
|
746
|
+
}
|
747
|
+
|
748
|
+
writeInt32(n) {
|
749
|
+
this.buffer.writeUInt32LE(n, this.offset);
|
750
|
+
this.offset += 4;
|
751
|
+
}
|
752
|
+
|
753
|
+
writeInt24(n) {
|
754
|
+
this.writeInt8(n & 0xff);
|
755
|
+
this.writeInt16(n >> 8);
|
756
|
+
}
|
757
|
+
|
758
|
+
writeInt16(n) {
|
759
|
+
this.buffer.writeUInt16LE(n, this.offset);
|
760
|
+
this.offset += 2;
|
761
|
+
}
|
762
|
+
|
763
|
+
writeInt8(n) {
|
764
|
+
this.buffer.writeUInt8(n, this.offset);
|
765
|
+
this.offset++;
|
766
|
+
}
|
767
|
+
|
768
|
+
writeDouble(n) {
|
769
|
+
this.buffer.writeDoubleLE(n, this.offset);
|
770
|
+
this.offset += 8;
|
771
|
+
}
|
772
|
+
|
773
|
+
writeBuffer(b) {
|
774
|
+
b.copy(this.buffer, this.offset);
|
775
|
+
this.offset += b.length;
|
776
|
+
}
|
777
|
+
|
778
|
+
writeNull() {
|
779
|
+
this.buffer[this.offset] = 0xfb;
|
780
|
+
this.offset++;
|
781
|
+
}
|
782
|
+
|
783
|
+
// TODO: refactor following three?
|
784
|
+
writeNullTerminatedString(s, encoding) {
|
785
|
+
const buf = StringParser.encode(s, encoding);
|
786
|
+
this.buffer.length && buf.copy(this.buffer, this.offset);
|
787
|
+
this.offset += buf.length;
|
788
|
+
this.writeInt8(0);
|
789
|
+
}
|
790
|
+
|
791
|
+
writeString(s, encoding) {
|
792
|
+
if (s === null) {
|
793
|
+
this.writeInt8(0xfb);
|
794
|
+
return;
|
795
|
+
}
|
796
|
+
if (s.length === 0) {
|
797
|
+
return;
|
798
|
+
}
|
799
|
+
// const bytes = Buffer.byteLength(s, 'utf8');
|
800
|
+
// this.buffer.write(s, this.offset, bytes, 'utf8');
|
801
|
+
// this.offset += bytes;
|
802
|
+
const buf = StringParser.encode(s, encoding);
|
803
|
+
this.buffer.length && buf.copy(this.buffer, this.offset);
|
804
|
+
this.offset += buf.length;
|
805
|
+
}
|
806
|
+
|
807
|
+
writeLengthCodedString(s, encoding) {
|
808
|
+
const buf = StringParser.encode(s, encoding);
|
809
|
+
this.writeLengthCodedNumber(buf.length);
|
810
|
+
this.buffer.length && buf.copy(this.buffer, this.offset);
|
811
|
+
this.offset += buf.length;
|
812
|
+
}
|
813
|
+
|
814
|
+
writeLengthCodedBuffer(b) {
|
815
|
+
this.writeLengthCodedNumber(b.length);
|
816
|
+
b.copy(this.buffer, this.offset);
|
817
|
+
this.offset += b.length;
|
818
|
+
}
|
819
|
+
|
820
|
+
writeLengthCodedNumber(n) {
|
821
|
+
if (n < 0xfb) {
|
822
|
+
return this.writeInt8(n);
|
823
|
+
}
|
824
|
+
if (n < 0xffff) {
|
825
|
+
this.writeInt8(0xfc);
|
826
|
+
return this.writeInt16(n);
|
827
|
+
}
|
828
|
+
if (n < 0xffffff) {
|
829
|
+
this.writeInt8(0xfd);
|
830
|
+
return this.writeInt24(n);
|
831
|
+
}
|
832
|
+
if (n === null) {
|
833
|
+
return this.writeInt8(0xfb);
|
834
|
+
}
|
835
|
+
// TODO: check that n is out of int precision
|
836
|
+
this.writeInt8(0xfe);
|
837
|
+
this.buffer.writeUInt32LE(n, this.offset);
|
838
|
+
this.offset += 4;
|
839
|
+
this.buffer.writeUInt32LE(n >> 32, this.offset);
|
840
|
+
this.offset += 4;
|
841
|
+
return this.offset;
|
842
|
+
}
|
843
|
+
|
844
|
+
writeDate(d, timezone) {
|
845
|
+
this.buffer.writeUInt8(11, this.offset);
|
846
|
+
if (!timezone || timezone === 'local') {
|
847
|
+
this.buffer.writeUInt16LE(d.getFullYear(), this.offset + 1);
|
848
|
+
this.buffer.writeUInt8(d.getMonth() + 1, this.offset + 3);
|
849
|
+
this.buffer.writeUInt8(d.getDate(), this.offset + 4);
|
850
|
+
this.buffer.writeUInt8(d.getHours(), this.offset + 5);
|
851
|
+
this.buffer.writeUInt8(d.getMinutes(), this.offset + 6);
|
852
|
+
this.buffer.writeUInt8(d.getSeconds(), this.offset + 7);
|
853
|
+
this.buffer.writeUInt32LE(d.getMilliseconds() * 1000, this.offset + 8);
|
854
|
+
} else {
|
855
|
+
if (timezone !== 'Z') {
|
856
|
+
const offset =
|
857
|
+
(timezone[0] === '-' ? -1 : 1) *
|
858
|
+
(parseInt(timezone.substring(1, 3), 10) * 60 +
|
859
|
+
parseInt(timezone.substring(4), 10));
|
860
|
+
if (offset !== 0) {
|
861
|
+
d = new Date(d.getTime() + 60000 * offset);
|
862
|
+
}
|
863
|
+
}
|
864
|
+
this.buffer.writeUInt16LE(d.getUTCFullYear(), this.offset + 1);
|
865
|
+
this.buffer.writeUInt8(d.getUTCMonth() + 1, this.offset + 3);
|
866
|
+
this.buffer.writeUInt8(d.getUTCDate(), this.offset + 4);
|
867
|
+
this.buffer.writeUInt8(d.getUTCHours(), this.offset + 5);
|
868
|
+
this.buffer.writeUInt8(d.getUTCMinutes(), this.offset + 6);
|
869
|
+
this.buffer.writeUInt8(d.getUTCSeconds(), this.offset + 7);
|
870
|
+
this.buffer.writeUInt32LE(d.getUTCMilliseconds() * 1000, this.offset + 8);
|
871
|
+
}
|
872
|
+
this.offset += 12;
|
873
|
+
}
|
874
|
+
|
875
|
+
writeHeader(sequenceId) {
|
876
|
+
const offset = this.offset;
|
877
|
+
this.offset = 0;
|
878
|
+
this.writeInt24(this.buffer.length - 4);
|
879
|
+
this.writeInt8(sequenceId);
|
880
|
+
this.offset = offset;
|
881
|
+
}
|
882
|
+
|
883
|
+
clone() {
|
884
|
+
return new Packet(this.sequenceId, this.buffer, this.start, this.end);
|
885
|
+
}
|
886
|
+
|
887
|
+
type() {
|
888
|
+
if (this.isEOF()) {
|
889
|
+
return 'EOF';
|
890
|
+
}
|
891
|
+
if (this.isError()) {
|
892
|
+
return 'Error';
|
893
|
+
}
|
894
|
+
if (this.buffer[this.offset] === 0) {
|
895
|
+
return 'maybeOK'; // could be other packet types as well
|
896
|
+
}
|
897
|
+
return '';
|
898
|
+
}
|
899
|
+
|
900
|
+
static lengthCodedNumberLength(n) {
|
901
|
+
if (n < 0xfb) {
|
902
|
+
return 1;
|
903
|
+
}
|
904
|
+
if (n < 0xffff) {
|
905
|
+
return 3;
|
906
|
+
}
|
907
|
+
if (n < 0xffffff) {
|
908
|
+
return 5;
|
909
|
+
}
|
910
|
+
return 9;
|
911
|
+
}
|
912
|
+
|
913
|
+
static lengthCodedStringLength(str, encoding) {
|
914
|
+
const buf = StringParser.encode(str, encoding);
|
915
|
+
const slen = buf.length;
|
916
|
+
return Packet.lengthCodedNumberLength(slen) + slen;
|
917
|
+
}
|
918
|
+
|
919
|
+
static MockBuffer() {
|
920
|
+
const noop = function () {};
|
921
|
+
const res = Buffer.alloc(0);
|
922
|
+
for (const op in NativeBuffer.prototype) {
|
923
|
+
if (typeof res[op] === 'function') {
|
924
|
+
res[op] = noop;
|
925
|
+
}
|
926
|
+
}
|
927
|
+
return res;
|
928
|
+
}
|
929
|
+
}
|
930
|
+
|
931
|
+
module.exports = Packet;
|