@tachybase/module-multi-app 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/README.md +34 -0
- package/README.zh-CN.md +34 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/dist/client/AppManager.d.ts +2 -0
- package/dist/client/AppNameInput.d.ts +2 -0
- package/dist/client/MultiAppBlockInitializer.d.ts +2 -0
- package/dist/client/MultiAppManagerProvider.d.ts +2 -0
- package/dist/client/MultiAppManagerProvider.style.d.ts +5 -0
- package/dist/client/Settings.d.ts +2 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +1 -0
- package/dist/client/settings/schemas/applications.d.ts +13 -0
- package/dist/client/utils.d.ts +4 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +27 -0
- package/dist/externalVersion.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +27 -0
- package/dist/locale/es-ES.json +9 -0
- package/dist/locale/ko_KR.json +11 -0
- package/dist/locale/pt-BR.json +9 -0
- package/dist/locale/zh-CN.json +27 -0
- package/dist/node_modules/mariadb/LICENSE +502 -0
- package/dist/node_modules/mariadb/callback.js +41 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +278 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +372 -0
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +149 -0
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +17 -0
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +102 -0
- package/dist/node_modules/mariadb/lib/cmd/command.js +168 -0
- package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +327 -0
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +427 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +168 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +23 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +761 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +55 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +58 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +19 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +142 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +74 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +126 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +292 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +74 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +29 -0
- package/dist/node_modules/mariadb/lib/cmd/ping.js +52 -0
- package/dist/node_modules/mariadb/lib/cmd/query.js +255 -0
- package/dist/node_modules/mariadb/lib/cmd/quit.js +28 -0
- package/dist/node_modules/mariadb/lib/cmd/reset.js +54 -0
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +607 -0
- package/dist/node_modules/mariadb/lib/cmd/stream.js +45 -0
- package/dist/node_modules/mariadb/lib/config/connection-options.js +258 -0
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +19 -0
- package/dist/node_modules/mariadb/lib/config/pool-options.js +47 -0
- package/dist/node_modules/mariadb/lib/connection-callback.js +160 -0
- package/dist/node_modules/mariadb/lib/connection.js +1460 -0
- package/dist/node_modules/mariadb/lib/const/capabilities.js +64 -0
- package/dist/node_modules/mariadb/lib/const/collations.js +473 -0
- package/dist/node_modules/mariadb/lib/const/connection_status.js +13 -0
- package/dist/node_modules/mariadb/lib/const/error-code.js +1282 -0
- package/dist/node_modules/mariadb/lib/const/field-detail.js +35 -0
- package/dist/node_modules/mariadb/lib/const/field-type.js +71 -0
- package/dist/node_modules/mariadb/lib/const/server-status.js +30 -0
- package/dist/node_modules/mariadb/lib/const/state-change.js +12 -0
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +81 -0
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +590 -0
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +141 -0
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +171 -0
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +193 -0
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +36 -0
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +37 -0
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +502 -0
- package/dist/node_modules/mariadb/lib/io/packet.js +515 -0
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +481 -0
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +96 -0
- package/dist/node_modules/mariadb/lib/misc/errors.js +123 -0
- package/dist/node_modules/mariadb/lib/misc/parse.js +1033 -0
- package/dist/node_modules/mariadb/lib/misc/utils.js +298 -0
- package/dist/node_modules/mariadb/lib/pool-base.js +611 -0
- package/dist/node_modules/mariadb/lib/pool-callback.js +202 -0
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +66 -0
- package/dist/node_modules/mariadb/lib/pool-cluster.js +407 -0
- package/dist/node_modules/mariadb/lib/pool-promise.js +108 -0
- package/dist/node_modules/mariadb/package.json +1 -0
- package/dist/node_modules/mariadb/promise.js +34 -0
- package/dist/node_modules/mariadb/types/index.d.ts +870 -0
- package/dist/server/actions/apps.d.ts +5 -0
- package/dist/server/actions/apps.js +117 -0
- package/dist/server/app-lifecycle.d.ts +8 -0
- package/dist/server/app-lifecycle.js +99 -0
- package/dist/server/app-start-env.d.ts +2 -0
- package/dist/server/app-start-env.js +105 -0
- package/dist/server/collections/applications.d.ts +2 -0
- package/dist/server/collections/applications.js +82 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +29 -0
- package/dist/server/middlewares/app-selector.d.ts +1 -0
- package/dist/server/middlewares/app-selector.js +47 -0
- package/dist/server/middlewares/index.d.ts +2 -0
- package/dist/server/middlewares/index.js +23 -0
- package/dist/server/middlewares/inject-app-list.d.ts +1 -0
- package/dist/server/middlewares/inject-app-list.js +48 -0
- package/dist/server/migrations/20240820153000-add-apps-tmpl.d.ts +6 -0
- package/dist/server/migrations/20240820153000-add-apps-tmpl.js +47 -0
- package/dist/server/migrations/20241126124904-add-createdBy.d.ts +6 -0
- package/dist/server/migrations/20241126124904-add-createdBy.js +41 -0
- package/dist/server/models/application.d.ts +10 -0
- package/dist/server/models/application.js +57 -0
- package/dist/server/server.d.ts +19 -0
- package/dist/server/server.js +246 -0
- package/dist/swagger/index.d.ts +197 -0
- package/dist/swagger/index.js +227 -0
- package/package.json +38 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Iconv = require('iconv-lite');
|
|
4
|
+
const Capabilities = require('../const/capabilities');
|
|
5
|
+
const Ed25519PasswordAuth = require('./handshake/auth/ed25519-password-auth');
|
|
6
|
+
const NativePasswordAuth = require('./handshake/auth/native-password-auth');
|
|
7
|
+
const Collations = require('../const/collations');
|
|
8
|
+
const Handshake = require('./handshake/handshake');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* send a COM_CHANGE_USER: resets the connection and re-authenticates with the given credentials
|
|
12
|
+
* see https://mariadb.com/kb/en/library/com_change_user/
|
|
13
|
+
*/
|
|
14
|
+
class ChangeUser extends Handshake {
|
|
15
|
+
constructor(options, resolve, reject, addCommand) {
|
|
16
|
+
super(resolve, reject, () => {}, addCommand);
|
|
17
|
+
this.opts = options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
start(out, opts, info) {
|
|
21
|
+
this.configAssign(opts, this.opts);
|
|
22
|
+
let authToken;
|
|
23
|
+
const pwd = Array.isArray(this.opts.password) ? this.opts.password[0] : this.opts.password;
|
|
24
|
+
switch (info.defaultPluginName) {
|
|
25
|
+
case 'mysql_native_password':
|
|
26
|
+
case '':
|
|
27
|
+
authToken = NativePasswordAuth.encryptPassword(pwd, info.seed, 'sha1');
|
|
28
|
+
break;
|
|
29
|
+
case 'client_ed25519':
|
|
30
|
+
authToken = Ed25519PasswordAuth.encryptPassword(pwd, info.seed);
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
authToken = Buffer.alloc(0);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
out.startPacket(this);
|
|
38
|
+
out.writeInt8(0x11);
|
|
39
|
+
out.writeString(this.opts.user || '');
|
|
40
|
+
out.writeInt8(0);
|
|
41
|
+
|
|
42
|
+
if (info.serverCapabilities & Capabilities.SECURE_CONNECTION) {
|
|
43
|
+
out.writeInt8(authToken.length);
|
|
44
|
+
out.writeBuffer(authToken, 0, authToken.length);
|
|
45
|
+
} else {
|
|
46
|
+
out.writeBuffer(authToken, 0, authToken.length);
|
|
47
|
+
out.writeInt8(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (info.clientCapabilities & Capabilities.CONNECT_WITH_DB) {
|
|
51
|
+
out.writeString(this.opts.database);
|
|
52
|
+
out.writeInt8(0);
|
|
53
|
+
info.database = this.opts.database;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
out.writeInt16(this.opts.collation.index);
|
|
57
|
+
|
|
58
|
+
if (info.clientCapabilities & Capabilities.PLUGIN_AUTH) {
|
|
59
|
+
out.writeString(info.defaultPluginName);
|
|
60
|
+
out.writeInt8(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (info.clientCapabilities & Capabilities.CONNECT_ATTRS) {
|
|
64
|
+
out.writeInt8(0xfc);
|
|
65
|
+
let initPos = out.pos; //save position, assuming connection attributes length will be less than 2 bytes length
|
|
66
|
+
out.writeInt16(0);
|
|
67
|
+
|
|
68
|
+
const encoding = this.opts.collation.charset;
|
|
69
|
+
|
|
70
|
+
writeParam(out, '_client_name', encoding);
|
|
71
|
+
writeParam(out, 'MariaDB connector/Node', encoding);
|
|
72
|
+
|
|
73
|
+
let packageJson = require('../../package.json');
|
|
74
|
+
writeParam(out, '_client_version', encoding);
|
|
75
|
+
writeParam(out, packageJson.version, encoding);
|
|
76
|
+
|
|
77
|
+
writeParam(out, '_node_version', encoding);
|
|
78
|
+
writeParam(out, process.versions.node, encoding);
|
|
79
|
+
|
|
80
|
+
if (opts.connectAttributes !== true) {
|
|
81
|
+
let attrNames = Object.keys(this.opts.connectAttributes);
|
|
82
|
+
for (let k = 0; k < attrNames.length; ++k) {
|
|
83
|
+
writeParam(out, attrNames[k], encoding);
|
|
84
|
+
writeParam(out, this.opts.connectAttributes[attrNames[k]], encoding);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//write end size
|
|
89
|
+
out.writeInt16AtPos(initPos);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
out.flushBuffer(true);
|
|
93
|
+
this.onPacketReceive = this.handshakeResult;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Assign global configuration option used by result-set to current query option.
|
|
98
|
+
* a little faster than Object.assign() since doest copy all information
|
|
99
|
+
*
|
|
100
|
+
* @param connOpts connection global configuration
|
|
101
|
+
* @param opt current options
|
|
102
|
+
*/
|
|
103
|
+
configAssign(connOpts, opt) {
|
|
104
|
+
if (!opt) {
|
|
105
|
+
this.opts = connOpts;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.opts.database = opt.database ? opt.database : connOpts.database;
|
|
109
|
+
this.opts.connectAttributes = opt.connectAttributes
|
|
110
|
+
? opt.connectAttributes
|
|
111
|
+
: connOpts.connectAttributes;
|
|
112
|
+
|
|
113
|
+
if (opt.charset && typeof opt.charset === 'string') {
|
|
114
|
+
this.opts.collation = Collations.fromCharset(opt.charset.toLowerCase());
|
|
115
|
+
if (this.opts.collation === undefined) {
|
|
116
|
+
this.opts.collation = Collations.fromName(opt.charset.toUpperCase());
|
|
117
|
+
if (this.opts.collation !== undefined) {
|
|
118
|
+
console.log(
|
|
119
|
+
"warning: please use option 'collation' " +
|
|
120
|
+
"in replacement of 'charset' when using a collation name ('" +
|
|
121
|
+
opt.charset +
|
|
122
|
+
"')\n" +
|
|
123
|
+
"(collation looks like 'UTF8MB4_UNICODE_CI', charset like 'utf8')."
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (this.opts.collation === undefined)
|
|
128
|
+
throw new RangeError("Unknown charset '" + opt.charset + "'");
|
|
129
|
+
} else if (opt.collation && typeof opt.collation === 'string') {
|
|
130
|
+
const initial = opt.collation;
|
|
131
|
+
this.opts.collation = Collations.fromName(initial.toUpperCase());
|
|
132
|
+
if (this.opts.collation === undefined)
|
|
133
|
+
throw new RangeError("Unknown collation '" + initial + "'");
|
|
134
|
+
} else {
|
|
135
|
+
this.opts.collation = Collations.fromIndex(opt.charsetNumber) || connOpts.collation;
|
|
136
|
+
}
|
|
137
|
+
connOpts.password = opt.password;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function writeParam(out, val, encoding) {
|
|
142
|
+
let param = Buffer.isEncoding(encoding)
|
|
143
|
+
? Buffer.from(val, encoding)
|
|
144
|
+
: Iconv.encode(val, encoding);
|
|
145
|
+
out.writeLengthCoded(param.length);
|
|
146
|
+
out.writeBuffer(param, 0, param.length);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = ChangeUser;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Command = require('../command');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ok_Packet
|
|
7
|
+
* see https://mariadb.com/kb/en/ok_packet/
|
|
8
|
+
*/
|
|
9
|
+
class OkPacket {
|
|
10
|
+
constructor(affectedRows, insertId, warningStatus) {
|
|
11
|
+
this.affectedRows = affectedRows;
|
|
12
|
+
this.insertId = insertId;
|
|
13
|
+
this.warningStatus = warningStatus;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = OkPacket;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Collations = require('../const/collations.js');
|
|
4
|
+
const FieldType = require('../const/field-type');
|
|
5
|
+
const Capabilities = require('../const/capabilities');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Column definition
|
|
9
|
+
* see https://mariadb.com/kb/en/library/resultset/#column-definition-packet
|
|
10
|
+
*/
|
|
11
|
+
class ColumnDef {
|
|
12
|
+
constructor(packet, info) {
|
|
13
|
+
this._parse = new StringParser(packet);
|
|
14
|
+
if (info.serverCapabilities & Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO) {
|
|
15
|
+
const subPacket = packet.subPacketLengthEncoded();
|
|
16
|
+
while (subPacket.remaining()) {
|
|
17
|
+
switch (subPacket.readUInt8()) {
|
|
18
|
+
case 0:
|
|
19
|
+
this.dataTypeName = subPacket.readAsciiStringLengthEncoded();
|
|
20
|
+
break;
|
|
21
|
+
|
|
22
|
+
case 1:
|
|
23
|
+
this.dataTypeFormat = subPacket.readAsciiStringLengthEncoded();
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
default:
|
|
27
|
+
// skip data
|
|
28
|
+
const len = subPacket.readUnsignedLength();
|
|
29
|
+
if (len) {
|
|
30
|
+
subPacket.skip(len);
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
packet.skip(1); // length of fixed fields
|
|
38
|
+
this.collation = Collations.fromIndex(packet.readUInt16());
|
|
39
|
+
this.columnLength = packet.readUInt32();
|
|
40
|
+
this.columnType = packet.readUInt8();
|
|
41
|
+
this.flags = packet.readUInt16();
|
|
42
|
+
this.scale = packet.readUInt8();
|
|
43
|
+
this.type = FieldType.TYPES[this.columnType];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
db() {
|
|
47
|
+
return this._parse.packet.readString(this._parse.dbOffset, this._parse.dbLength);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
schema() {
|
|
51
|
+
return this._parse.packet.readString(this._parse.dbOffset, this._parse.dbLength);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
table() {
|
|
55
|
+
return this._parse.packet.readString(this._parse.tableOffset, this._parse.tableLength);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
orgTable() {
|
|
59
|
+
return this._parse.packet.readString(this._parse.orgTableOffset, this._parse.orgTableLength);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
name() {
|
|
63
|
+
return this._parse.packet.readString(this._parse.nameOffset, this._parse.nameLength);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
orgName() {
|
|
67
|
+
return this._parse.packet.readString(this._parse.orgNameOffset, this._parse.orgNameLength);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* String parser.
|
|
73
|
+
* This object permits to avoid listing all private information to metadata object.
|
|
74
|
+
*/
|
|
75
|
+
class StringParser {
|
|
76
|
+
constructor(packet) {
|
|
77
|
+
packet.skip(4); // skip 'def'
|
|
78
|
+
|
|
79
|
+
this.dbLength = packet.readUnsignedLength();
|
|
80
|
+
this.dbOffset = packet.pos;
|
|
81
|
+
packet.skip(this.dbLength);
|
|
82
|
+
|
|
83
|
+
this.tableLength = packet.readUnsignedLength();
|
|
84
|
+
this.tableOffset = packet.pos;
|
|
85
|
+
packet.skip(this.tableLength);
|
|
86
|
+
|
|
87
|
+
this.orgTableLength = packet.readUnsignedLength();
|
|
88
|
+
this.orgTableOffset = packet.pos;
|
|
89
|
+
packet.skip(this.orgTableLength);
|
|
90
|
+
|
|
91
|
+
this.nameLength = packet.readUnsignedLength();
|
|
92
|
+
this.nameOffset = packet.pos;
|
|
93
|
+
packet.skip(this.nameLength);
|
|
94
|
+
|
|
95
|
+
this.orgNameLength = packet.readUnsignedLength();
|
|
96
|
+
this.orgNameOffset = packet.pos;
|
|
97
|
+
packet.skip(this.orgNameLength);
|
|
98
|
+
this.packet = packet;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = ColumnDef;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EventEmitter = require('events');
|
|
4
|
+
const Errors = require('../misc/errors');
|
|
5
|
+
const ServerStatus = require('../const/server-status');
|
|
6
|
+
const StateChange = require('../const/state-change');
|
|
7
|
+
const Collations = require('../const/collations');
|
|
8
|
+
const OkPacket = require('./class/ok-packet');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default command interface.
|
|
12
|
+
*/
|
|
13
|
+
class Command extends EventEmitter {
|
|
14
|
+
constructor(resolve, reject) {
|
|
15
|
+
super();
|
|
16
|
+
this.sequenceNo = -1;
|
|
17
|
+
this.compressSequenceNo = -1;
|
|
18
|
+
this.resolve = resolve;
|
|
19
|
+
this.reject = reject;
|
|
20
|
+
this.sending = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
displaySql() {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Throw an an unexpected error.
|
|
29
|
+
* server exchange will still be read to keep connection in a good state, but promise will be rejected.
|
|
30
|
+
*
|
|
31
|
+
* @param msg message
|
|
32
|
+
* @param fatal is error fatal for connection
|
|
33
|
+
* @param info current server state information
|
|
34
|
+
* @param sqlState error sqlState
|
|
35
|
+
* @param errno error number
|
|
36
|
+
*/
|
|
37
|
+
throwUnexpectedError(msg, fatal, info, sqlState, errno) {
|
|
38
|
+
if (this.reject) {
|
|
39
|
+
process.nextTick(
|
|
40
|
+
this.reject,
|
|
41
|
+
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
|
|
42
|
+
);
|
|
43
|
+
this.resolve = null;
|
|
44
|
+
this.reject = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create and throw new Error from error information
|
|
50
|
+
* only first called throwing an error or successfully end will be executed.
|
|
51
|
+
*
|
|
52
|
+
* @param msg message
|
|
53
|
+
* @param fatal is error fatal for connection
|
|
54
|
+
* @param info current server state information
|
|
55
|
+
* @param sqlState error sqlState
|
|
56
|
+
* @param errno error number
|
|
57
|
+
*/
|
|
58
|
+
throwNewError(msg, fatal, info, sqlState, errno) {
|
|
59
|
+
this.onPacketReceive = null;
|
|
60
|
+
if (this.reject) {
|
|
61
|
+
process.nextTick(
|
|
62
|
+
this.reject,
|
|
63
|
+
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
|
|
64
|
+
);
|
|
65
|
+
this.resolve = null;
|
|
66
|
+
this.reject = null;
|
|
67
|
+
}
|
|
68
|
+
this.emit('end');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Throw Error
|
|
73
|
+
* only first called throwing an error or successfully end will be executed.
|
|
74
|
+
*
|
|
75
|
+
* @param err error to be thrown
|
|
76
|
+
* @param info current server state information
|
|
77
|
+
*/
|
|
78
|
+
throwError(err, info) {
|
|
79
|
+
this.onPacketReceive = null;
|
|
80
|
+
if (this.reject) {
|
|
81
|
+
if (this.stack) {
|
|
82
|
+
err = Errors.createError(
|
|
83
|
+
err.message,
|
|
84
|
+
err.sql,
|
|
85
|
+
err.fatal,
|
|
86
|
+
info,
|
|
87
|
+
err.sqlState,
|
|
88
|
+
err.errno,
|
|
89
|
+
this.stack,
|
|
90
|
+
false
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
this.resolve = null;
|
|
94
|
+
process.nextTick(this.reject, err);
|
|
95
|
+
this.reject = null;
|
|
96
|
+
}
|
|
97
|
+
this.emit('end', err);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Successfully end command.
|
|
102
|
+
* only first called throwing an error or successfully end will be executed.
|
|
103
|
+
*
|
|
104
|
+
* @param val return value.
|
|
105
|
+
*/
|
|
106
|
+
successEnd(val) {
|
|
107
|
+
this.onPacketReceive = null;
|
|
108
|
+
if (this.resolve) {
|
|
109
|
+
this.reject = null;
|
|
110
|
+
process.nextTick(this.resolve, val);
|
|
111
|
+
this.resolve = null;
|
|
112
|
+
}
|
|
113
|
+
this.emit('end');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
parseOkPacket(packet, out, opts, info) {
|
|
117
|
+
packet.skip(1); //skip header
|
|
118
|
+
|
|
119
|
+
const affectedRows = packet.readUnsignedLength();
|
|
120
|
+
const insertId = opts.supportBigInt
|
|
121
|
+
? packet.readSignedLengthBigInt()
|
|
122
|
+
: packet.readSignedLength();
|
|
123
|
+
|
|
124
|
+
info.status = packet.readUInt16();
|
|
125
|
+
|
|
126
|
+
const okPacket = new OkPacket(affectedRows, insertId, packet.readUInt16());
|
|
127
|
+
|
|
128
|
+
if (info.status & ServerStatus.SESSION_STATE_CHANGED) {
|
|
129
|
+
packet.skipLengthCodedNumber();
|
|
130
|
+
while (packet.remaining()) {
|
|
131
|
+
const subPacket = packet.subPacketLengthEncoded();
|
|
132
|
+
while (subPacket.remaining()) {
|
|
133
|
+
const type = subPacket.readUInt8();
|
|
134
|
+
switch (type) {
|
|
135
|
+
case StateChange.SESSION_TRACK_SYSTEM_VARIABLES:
|
|
136
|
+
const subSubPacket = subPacket.subPacketLengthEncoded();
|
|
137
|
+
const variable = subSubPacket.readStringLength();
|
|
138
|
+
const value = subSubPacket.readStringLength();
|
|
139
|
+
|
|
140
|
+
switch (variable) {
|
|
141
|
+
case 'character_set_client':
|
|
142
|
+
opts.collation = Collations.fromCharset(value);
|
|
143
|
+
if (opts.collation === undefined) {
|
|
144
|
+
this.throwError(new Error("unknown charset : '" + value + "'"), info);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
opts.emit('collation', opts.collation);
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
default:
|
|
151
|
+
//variable not used by driver
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case StateChange.SESSION_TRACK_SCHEMA:
|
|
156
|
+
const subSubPacket2 = subPacket.subPacketLengthEncoded();
|
|
157
|
+
info.database = subSubPacket2.readStringLength();
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return okPacket;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = Command;
|