@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,427 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ResultSet = require('./resultset');
|
|
4
|
+
const FieldDetail = require('../const/field-detail');
|
|
5
|
+
const FieldType = require('../const/field-type');
|
|
6
|
+
const Long = require('long');
|
|
7
|
+
const moment = require('moment-timezone');
|
|
8
|
+
const QUOTE = 0x27;
|
|
9
|
+
|
|
10
|
+
class CommonText extends ResultSet {
|
|
11
|
+
constructor(resolve, reject, cmdOpts, connOpts, sql, values) {
|
|
12
|
+
super(resolve, reject);
|
|
13
|
+
this.configAssign(connOpts, cmdOpts);
|
|
14
|
+
this.sql = sql;
|
|
15
|
+
this.initialValues = values;
|
|
16
|
+
this.getDateQuote = this.opts.tz
|
|
17
|
+
? this.opts.tz === 'Etc/UTC'
|
|
18
|
+
? CommonText.getUtcDate
|
|
19
|
+
: CommonText.getTimezoneDate
|
|
20
|
+
: CommonText.getLocalDate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Write (and escape) current parameter value to output writer
|
|
25
|
+
*
|
|
26
|
+
* @param out output writer
|
|
27
|
+
* @param value current parameter
|
|
28
|
+
* @param opts connection options
|
|
29
|
+
* @param info connection information
|
|
30
|
+
*/
|
|
31
|
+
writeParam(out, value, opts, info) {
|
|
32
|
+
switch (typeof value) {
|
|
33
|
+
case 'boolean':
|
|
34
|
+
out.writeStringAscii(value ? 'true' : 'false');
|
|
35
|
+
break;
|
|
36
|
+
case 'bigint':
|
|
37
|
+
case 'number':
|
|
38
|
+
out.writeStringAscii('' + value);
|
|
39
|
+
break;
|
|
40
|
+
case 'object':
|
|
41
|
+
if (value === null) {
|
|
42
|
+
out.writeStringAscii('NULL');
|
|
43
|
+
} else if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
44
|
+
out.writeStringAscii(this.getDateQuote(value, opts));
|
|
45
|
+
} else if (Buffer.isBuffer(value)) {
|
|
46
|
+
out.writeStringAscii("_BINARY '");
|
|
47
|
+
out.writeBufferEscape(value);
|
|
48
|
+
out.writeInt8(QUOTE);
|
|
49
|
+
} else if (typeof value.toSqlString === 'function') {
|
|
50
|
+
out.writeStringEscapeQuote(String(value.toSqlString()));
|
|
51
|
+
} else if (Long.isLong(value)) {
|
|
52
|
+
out.writeStringAscii(value.toString());
|
|
53
|
+
} else if (Array.isArray(value)) {
|
|
54
|
+
if (opts.arrayParenthesis) {
|
|
55
|
+
out.writeStringAscii('(');
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < value.length; i++) {
|
|
58
|
+
if (i !== 0) out.writeStringAscii(',');
|
|
59
|
+
this.writeParam(out, value[i], opts, info);
|
|
60
|
+
}
|
|
61
|
+
if (opts.arrayParenthesis) {
|
|
62
|
+
out.writeStringAscii(')');
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (
|
|
66
|
+
value.type != null &&
|
|
67
|
+
[
|
|
68
|
+
'Point',
|
|
69
|
+
'LineString',
|
|
70
|
+
'Polygon',
|
|
71
|
+
'MultiPoint',
|
|
72
|
+
'MultiLineString',
|
|
73
|
+
'MultiPolygon',
|
|
74
|
+
'GeometryCollection'
|
|
75
|
+
].includes(value.type)
|
|
76
|
+
) {
|
|
77
|
+
//GeoJSON format.
|
|
78
|
+
let prefix =
|
|
79
|
+
(info.isMariaDB() && info.hasMinVersion(10, 1, 4)) ||
|
|
80
|
+
(!info.isMariaDB() && info.hasMinVersion(5, 7, 6))
|
|
81
|
+
? 'ST_'
|
|
82
|
+
: '';
|
|
83
|
+
switch (value.type) {
|
|
84
|
+
case 'Point':
|
|
85
|
+
out.writeStringAscii(
|
|
86
|
+
prefix +
|
|
87
|
+
"PointFromText('POINT(" +
|
|
88
|
+
CommonText.geoPointToString(value.coordinates) +
|
|
89
|
+
")')"
|
|
90
|
+
);
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 'LineString':
|
|
94
|
+
out.writeStringAscii(
|
|
95
|
+
prefix +
|
|
96
|
+
"LineFromText('LINESTRING(" +
|
|
97
|
+
CommonText.geoArrayPointToString(value.coordinates) +
|
|
98
|
+
")')"
|
|
99
|
+
);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case 'Polygon':
|
|
103
|
+
out.writeStringAscii(
|
|
104
|
+
prefix +
|
|
105
|
+
"PolygonFromText('POLYGON(" +
|
|
106
|
+
CommonText.geoMultiArrayPointToString(value.coordinates) +
|
|
107
|
+
")')"
|
|
108
|
+
);
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'MultiPoint':
|
|
112
|
+
out.writeStringAscii(
|
|
113
|
+
prefix +
|
|
114
|
+
"MULTIPOINTFROMTEXT('MULTIPOINT(" +
|
|
115
|
+
CommonText.geoArrayPointToString(value.coordinates) +
|
|
116
|
+
")')"
|
|
117
|
+
);
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case 'MultiLineString':
|
|
121
|
+
out.writeStringAscii(
|
|
122
|
+
prefix +
|
|
123
|
+
"MLineFromText('MULTILINESTRING(" +
|
|
124
|
+
CommonText.geoMultiArrayPointToString(value.coordinates) +
|
|
125
|
+
")')"
|
|
126
|
+
);
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
case 'MultiPolygon':
|
|
130
|
+
out.writeStringAscii(
|
|
131
|
+
prefix +
|
|
132
|
+
"MPolyFromText('MULTIPOLYGON(" +
|
|
133
|
+
CommonText.geoMultiPolygonToString(value.coordinates) +
|
|
134
|
+
")')"
|
|
135
|
+
);
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'GeometryCollection':
|
|
139
|
+
out.writeStringAscii(
|
|
140
|
+
prefix +
|
|
141
|
+
"GeomCollFromText('GEOMETRYCOLLECTION(" +
|
|
142
|
+
CommonText.geometricCollectionToString(value.geometries) +
|
|
143
|
+
")')"
|
|
144
|
+
);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
if (opts.permitSetMultiParamEntries) {
|
|
149
|
+
let first = true;
|
|
150
|
+
for (let key in value) {
|
|
151
|
+
const val = value[key];
|
|
152
|
+
if (typeof val === 'function') continue;
|
|
153
|
+
if (first) {
|
|
154
|
+
first = false;
|
|
155
|
+
} else {
|
|
156
|
+
out.writeStringAscii(',');
|
|
157
|
+
}
|
|
158
|
+
out.writeString('`' + key + '`');
|
|
159
|
+
out.writeStringAscii('=');
|
|
160
|
+
this.writeParam(out, val, opts, info);
|
|
161
|
+
}
|
|
162
|
+
if (first) out.writeStringEscapeQuote(JSON.stringify(value));
|
|
163
|
+
} else {
|
|
164
|
+
out.writeStringEscapeQuote(JSON.stringify(value));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
out.writeStringEscapeQuote(value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static geometricCollectionToString(geo) {
|
|
175
|
+
if (!geo) return '';
|
|
176
|
+
let st = '';
|
|
177
|
+
for (let i = 0; i < geo.length; i++) {
|
|
178
|
+
//GeoJSON format.
|
|
179
|
+
st += i !== 0 ? ',' : '';
|
|
180
|
+
switch (geo[i].type) {
|
|
181
|
+
case 'Point':
|
|
182
|
+
st += 'POINT(' + CommonText.geoPointToString(geo[i].coordinates) + ')';
|
|
183
|
+
break;
|
|
184
|
+
|
|
185
|
+
case 'LineString':
|
|
186
|
+
st += 'LINESTRING(' + CommonText.geoArrayPointToString(geo[i].coordinates) + ')';
|
|
187
|
+
break;
|
|
188
|
+
|
|
189
|
+
case 'Polygon':
|
|
190
|
+
st += 'POLYGON(' + CommonText.geoMultiArrayPointToString(geo[i].coordinates) + ')';
|
|
191
|
+
break;
|
|
192
|
+
|
|
193
|
+
case 'MultiPoint':
|
|
194
|
+
st += 'MULTIPOINT(' + CommonText.geoArrayPointToString(geo[i].coordinates) + ')';
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
case 'MultiLineString':
|
|
198
|
+
st +=
|
|
199
|
+
'MULTILINESTRING(' + CommonText.geoMultiArrayPointToString(geo[i].coordinates) + ')';
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
case 'MultiPolygon':
|
|
203
|
+
st += 'MULTIPOLYGON(' + CommonText.geoMultiPolygonToString(geo[i].coordinates) + ')';
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return st;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static geoMultiPolygonToString(coords) {
|
|
211
|
+
if (!coords) return '';
|
|
212
|
+
let st = '';
|
|
213
|
+
for (let i = 0; i < coords.length; i++) {
|
|
214
|
+
st += (i !== 0 ? ',(' : '(') + CommonText.geoMultiArrayPointToString(coords[i]) + ')';
|
|
215
|
+
}
|
|
216
|
+
return st;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static geoMultiArrayPointToString(coords) {
|
|
220
|
+
if (!coords) return '';
|
|
221
|
+
let st = '';
|
|
222
|
+
for (let i = 0; i < coords.length; i++) {
|
|
223
|
+
st += (i !== 0 ? ',(' : '(') + CommonText.geoArrayPointToString(coords[i]) + ')';
|
|
224
|
+
}
|
|
225
|
+
return st;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static geoArrayPointToString(coords) {
|
|
229
|
+
if (!coords) return '';
|
|
230
|
+
let st = '';
|
|
231
|
+
for (let i = 0; i < coords.length; i++) {
|
|
232
|
+
st += (i !== 0 ? ',' : '') + CommonText.geoPointToString(coords[i]);
|
|
233
|
+
}
|
|
234
|
+
return st;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static geoPointToString(coords) {
|
|
238
|
+
if (!coords) return '';
|
|
239
|
+
return (isNaN(coords[0]) ? '' : coords[0]) + ' ' + (isNaN(coords[1]) ? '' : coords[1]);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
parseRowAsArray(columns, packet, connOpts) {
|
|
243
|
+
const row = new Array(this._columnCount);
|
|
244
|
+
for (let i = 0; i < this._columnCount; i++) {
|
|
245
|
+
row[i] = this._getValue(i, columns[i], this.opts, connOpts, packet);
|
|
246
|
+
}
|
|
247
|
+
return row;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
parseRowNested(columns, packet, connOpts) {
|
|
251
|
+
const row = {};
|
|
252
|
+
for (let i = 0; i < this._columnCount; i++) {
|
|
253
|
+
if (!row[this.tableHeader[i][0]]) row[this.tableHeader[i][0]] = {};
|
|
254
|
+
row[this.tableHeader[i][0]][this.tableHeader[i][1]] = this._getValue(
|
|
255
|
+
i,
|
|
256
|
+
columns[i],
|
|
257
|
+
this.opts,
|
|
258
|
+
connOpts,
|
|
259
|
+
packet
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return row;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
parseRowStd(columns, packet, connOpts) {
|
|
266
|
+
const row = {};
|
|
267
|
+
for (let i = 0; i < this._columnCount; i++) {
|
|
268
|
+
row[this.tableHeader[i]] = this._getValue(i, columns[i], this.opts, connOpts, packet);
|
|
269
|
+
}
|
|
270
|
+
return row;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
castTextWrapper(column, opts, connOpts, packet) {
|
|
274
|
+
column.string = () => packet.readStringLength();
|
|
275
|
+
column.buffer = () => packet.readBufferLengthEncoded();
|
|
276
|
+
column.float = () => packet.readFloatLengthCoded();
|
|
277
|
+
column.int = () => packet.readIntLengthEncoded();
|
|
278
|
+
column.long = () =>
|
|
279
|
+
packet.readLongLengthEncoded(
|
|
280
|
+
opts.supportBigInt,
|
|
281
|
+
opts.supportBigNumbers,
|
|
282
|
+
opts.bigNumberStrings,
|
|
283
|
+
(column.flags & FieldDetail.UNSIGNED) > 0
|
|
284
|
+
);
|
|
285
|
+
column.decimal = () => packet.readDecimalLengthEncoded(opts.bigNumberStrings);
|
|
286
|
+
column.date = () => packet.readDateTime(opts);
|
|
287
|
+
column.geometry = () => {
|
|
288
|
+
return column.readGeometry();
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
readCastValue(index, column, opts, connOpts, packet) {
|
|
293
|
+
this.castTextWrapper(column, opts, connOpts, packet);
|
|
294
|
+
return opts.typeCast(
|
|
295
|
+
column,
|
|
296
|
+
this.readRowData.bind(this, index, column, opts, connOpts, packet)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Read row data.
|
|
302
|
+
*
|
|
303
|
+
* @param index current data index in row
|
|
304
|
+
* @param column associate metadata
|
|
305
|
+
* @param opts query options
|
|
306
|
+
* @param connOpts connection options
|
|
307
|
+
* @param packet row packet
|
|
308
|
+
* @returns {*} data
|
|
309
|
+
*/
|
|
310
|
+
readRowData(index, column, opts, connOpts, packet) {
|
|
311
|
+
switch (column.columnType) {
|
|
312
|
+
case FieldType.TINY:
|
|
313
|
+
case FieldType.SHORT:
|
|
314
|
+
case FieldType.LONG:
|
|
315
|
+
case FieldType.INT24:
|
|
316
|
+
case FieldType.YEAR:
|
|
317
|
+
return packet.readIntLengthEncoded();
|
|
318
|
+
case FieldType.FLOAT:
|
|
319
|
+
case FieldType.DOUBLE:
|
|
320
|
+
return packet.readFloatLengthCoded();
|
|
321
|
+
case FieldType.LONGLONG:
|
|
322
|
+
return packet.readLongLengthEncoded(
|
|
323
|
+
opts.supportBigInt,
|
|
324
|
+
opts.supportBigNumbers,
|
|
325
|
+
opts.bigNumberStrings,
|
|
326
|
+
(column.flags & FieldDetail.UNSIGNED) > 0
|
|
327
|
+
);
|
|
328
|
+
case FieldType.DECIMAL:
|
|
329
|
+
case FieldType.NEWDECIMAL:
|
|
330
|
+
return packet.readDecimalLengthEncoded(opts.bigNumberStrings);
|
|
331
|
+
case FieldType.DATE:
|
|
332
|
+
if (opts.dateStrings) {
|
|
333
|
+
return packet.readAsciiStringLengthEncoded();
|
|
334
|
+
}
|
|
335
|
+
return packet.readDate();
|
|
336
|
+
case FieldType.DATETIME:
|
|
337
|
+
case FieldType.TIMESTAMP:
|
|
338
|
+
if (opts.dateStrings) {
|
|
339
|
+
return packet.readAsciiStringLengthEncoded();
|
|
340
|
+
}
|
|
341
|
+
return packet.readDateTime(opts);
|
|
342
|
+
case FieldType.TIME:
|
|
343
|
+
return packet.readAsciiStringLengthEncoded();
|
|
344
|
+
case FieldType.GEOMETRY:
|
|
345
|
+
return packet.readGeometry(column.dataTypeName);
|
|
346
|
+
case FieldType.JSON:
|
|
347
|
+
//for mysql only => parse string as JSON object
|
|
348
|
+
return JSON.parse(packet.readStringLengthEncoded('utf8'));
|
|
349
|
+
|
|
350
|
+
default:
|
|
351
|
+
if (column.dataTypeFormat && column.dataTypeFormat === 'json' && opts.autoJsonMap) {
|
|
352
|
+
return JSON.parse(packet.readStringLengthEncoded('utf8'));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (column.collation.index === 63) {
|
|
356
|
+
return packet.readBufferLengthEncoded();
|
|
357
|
+
}
|
|
358
|
+
const string = packet.readStringLength();
|
|
359
|
+
if (column.flags & 2048) {
|
|
360
|
+
//SET
|
|
361
|
+
return string == null ? null : string === '' ? [] : string.split(',');
|
|
362
|
+
}
|
|
363
|
+
return string;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function getDatePartQuote(year, mon, day, hour, min, sec, ms) {
|
|
369
|
+
//return 'YYYY-MM-DD HH:MM:SS' datetime format
|
|
370
|
+
//see https://mariadb.com/kb/en/library/datetime/
|
|
371
|
+
return (
|
|
372
|
+
"'" +
|
|
373
|
+
(year > 999 ? year : year > 99 ? '0' + year : year > 9 ? '00' + year : '000' + year) +
|
|
374
|
+
'-' +
|
|
375
|
+
(mon < 10 ? '0' : '') +
|
|
376
|
+
mon +
|
|
377
|
+
'-' +
|
|
378
|
+
(day < 10 ? '0' : '') +
|
|
379
|
+
day +
|
|
380
|
+
' ' +
|
|
381
|
+
(hour < 10 ? '0' : '') +
|
|
382
|
+
hour +
|
|
383
|
+
':' +
|
|
384
|
+
(min < 10 ? '0' : '') +
|
|
385
|
+
min +
|
|
386
|
+
':' +
|
|
387
|
+
(sec < 10 ? '0' : '') +
|
|
388
|
+
sec +
|
|
389
|
+
'.' +
|
|
390
|
+
(ms > 99 ? ms : ms > 9 ? '0' + ms : '00' + ms) +
|
|
391
|
+
"'"
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function getLocalDate(date, opts) {
|
|
396
|
+
const year = date.getFullYear();
|
|
397
|
+
const mon = date.getMonth() + 1;
|
|
398
|
+
const day = date.getDate();
|
|
399
|
+
const hour = date.getHours();
|
|
400
|
+
const min = date.getMinutes();
|
|
401
|
+
const sec = date.getSeconds();
|
|
402
|
+
const ms = date.getMilliseconds();
|
|
403
|
+
return getDatePartQuote(year, mon, day, hour, min, sec, ms);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function getUtcDate(date, opts) {
|
|
407
|
+
const year = date.getUTCFullYear();
|
|
408
|
+
const mon = date.getUTCMonth() + 1;
|
|
409
|
+
const day = date.getUTCDate();
|
|
410
|
+
const hour = date.getUTCHours();
|
|
411
|
+
const min = date.getUTCMinutes();
|
|
412
|
+
const sec = date.getUTCSeconds();
|
|
413
|
+
const ms = date.getUTCMilliseconds();
|
|
414
|
+
return getDatePartQuote(year, mon, day, hour, min, sec, ms);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function getTimezoneDate(date, opts) {
|
|
418
|
+
if (date.getMilliseconds() != 0) {
|
|
419
|
+
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss.SSS'");
|
|
420
|
+
}
|
|
421
|
+
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss'");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
module.exports = CommonText;
|
|
425
|
+
module.exports.getTimezoneDate = getTimezoneDate;
|
|
426
|
+
module.exports.getUtcDate = getUtcDate;
|
|
427
|
+
module.exports.getLocalDate = getLocalDate;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const PluginAuth = require('./plugin-auth');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const Errors = require('../../../misc/errors');
|
|
5
|
+
const NativePasswordAuth = require('./native-password-auth');
|
|
6
|
+
const Sha256PasswordAuth = require('./sha256-password-auth');
|
|
7
|
+
|
|
8
|
+
const State = {
|
|
9
|
+
INIT: 'INIT',
|
|
10
|
+
FAST_AUTH_RESULT: 'FAST_AUTH_RESULT',
|
|
11
|
+
REQUEST_SERVER_KEY: 'REQUEST_SERVER_KEY',
|
|
12
|
+
SEND_AUTH: 'SEND_AUTH'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Use caching Sha2 password authentication
|
|
17
|
+
*/
|
|
18
|
+
class CachingSha2PasswordAuth extends PluginAuth {
|
|
19
|
+
constructor(packSeq, compressPackSeq, pluginData, resolve, reject, multiAuthResolver) {
|
|
20
|
+
super(resolve, reject, multiAuthResolver);
|
|
21
|
+
this.pluginData = pluginData;
|
|
22
|
+
this.sequenceNo = packSeq;
|
|
23
|
+
this.counter = 0;
|
|
24
|
+
this.state = State.INIT;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
start(out, opts, info) {
|
|
28
|
+
this.exchange(this.pluginData, out, opts, info);
|
|
29
|
+
this.onPacketReceive = this.response;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exchange(buffer, out, opts, info) {
|
|
33
|
+
switch (this.state) {
|
|
34
|
+
case State.INIT:
|
|
35
|
+
const truncatedSeed = this.pluginData.slice(0, this.pluginData.length - 1);
|
|
36
|
+
const encPwd = NativePasswordAuth.encryptPassword(opts.password, truncatedSeed, 'sha256');
|
|
37
|
+
out.startPacket(this);
|
|
38
|
+
if (encPwd.length > 0) {
|
|
39
|
+
out.writeBuffer(encPwd, 0, encPwd.length);
|
|
40
|
+
out.flushBuffer(true);
|
|
41
|
+
} else {
|
|
42
|
+
out.writeEmptyPacket(true);
|
|
43
|
+
}
|
|
44
|
+
this.state = State.FAST_AUTH_RESULT;
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
case State.FAST_AUTH_RESULT:
|
|
48
|
+
// length encoded numeric : 0x01 0x03/0x04
|
|
49
|
+
const fastAuthResult = buffer[1];
|
|
50
|
+
switch (fastAuthResult) {
|
|
51
|
+
case 0x03:
|
|
52
|
+
// success authentication
|
|
53
|
+
this.emit('send_end');
|
|
54
|
+
return this.successSend(packet, out, opts, info);
|
|
55
|
+
|
|
56
|
+
case 0x04:
|
|
57
|
+
if (opts.ssl) {
|
|
58
|
+
// using SSL, so sending password in clear
|
|
59
|
+
out.startPacket(this);
|
|
60
|
+
out.writeString(opts.password);
|
|
61
|
+
out.writeInt8(0);
|
|
62
|
+
out.flushBuffer(true);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// retrieve public key from configuration or from server
|
|
67
|
+
if (opts.cachingRsaPublicKey) {
|
|
68
|
+
try {
|
|
69
|
+
let key = opts.cachingRsaPublicKey;
|
|
70
|
+
if (!key.includes('-----BEGIN')) {
|
|
71
|
+
// rsaPublicKey contain path
|
|
72
|
+
key = fs.readFileSync(key, 'utf8');
|
|
73
|
+
}
|
|
74
|
+
this.publicKey = Sha256PasswordAuth.retreivePublicKey(key);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return this.throwError(err, info);
|
|
77
|
+
}
|
|
78
|
+
// send Sha256Password Packet
|
|
79
|
+
Sha256PasswordAuth.sendSha256PwdPacket(
|
|
80
|
+
this,
|
|
81
|
+
this.pluginData,
|
|
82
|
+
this.publicKey,
|
|
83
|
+
opts.password,
|
|
84
|
+
out
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
if (!opts.allowPublicKeyRetrieval) {
|
|
88
|
+
return this.throwError(
|
|
89
|
+
Errors.createError(
|
|
90
|
+
'RSA public key is not available client side. Either set option `cachingRsaPublicKey` to indicate' +
|
|
91
|
+
' public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`',
|
|
92
|
+
null,
|
|
93
|
+
true,
|
|
94
|
+
info,
|
|
95
|
+
'08S01',
|
|
96
|
+
Errors.ER_CANNOT_RETRIEVE_RSA_KEY
|
|
97
|
+
),
|
|
98
|
+
info
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
this.state = State.REQUEST_SERVER_KEY;
|
|
102
|
+
// ask caching public Key Retrieval
|
|
103
|
+
out.startPacket(this);
|
|
104
|
+
out.writeInt8(0x02);
|
|
105
|
+
out.flushBuffer(true);
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
case State.REQUEST_SERVER_KEY:
|
|
111
|
+
this.publicKey = Sha256PasswordAuth.retreivePublicKey(buffer.toString('utf8', 1));
|
|
112
|
+
this.state = State.SEND_AUTH;
|
|
113
|
+
Sha256PasswordAuth.sendSha256PwdPacket(
|
|
114
|
+
this,
|
|
115
|
+
this.pluginData,
|
|
116
|
+
this.publicKey,
|
|
117
|
+
opts.password,
|
|
118
|
+
out
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static retreivePublicKey(key) {
|
|
124
|
+
return key.replace('(-+BEGIN PUBLIC KEY-+\\r?\\n|\\n?-+END PUBLIC KEY-+\\r?\\n?)', '');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static sendSha256PwdPacket(cmd, pluginData, publicKey, password, out) {
|
|
128
|
+
const truncatedSeed = pluginData.slice(0, pluginData.length - 1);
|
|
129
|
+
out.startPacket(cmd);
|
|
130
|
+
const enc = Sha256PasswordAuth.encrypt(truncatedSeed, password, publicKey);
|
|
131
|
+
out.writeBuffer(enc, 0, enc.length);
|
|
132
|
+
out.flushBuffer(cmd);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// encrypt password with public key
|
|
136
|
+
static encrypt(seed, password, publicKey) {
|
|
137
|
+
const nullFinishedPwd = Buffer.from(password + '\0');
|
|
138
|
+
const xorBytes = Buffer.allocUnsafe(nullFinishedPwd.length);
|
|
139
|
+
const seedLength = seed.length;
|
|
140
|
+
for (let i = 0; i < xorBytes.length; i++) {
|
|
141
|
+
xorBytes[i] = nullFinishedPwd[i] ^ seed[i % seedLength];
|
|
142
|
+
}
|
|
143
|
+
return crypto.publicEncrypt(
|
|
144
|
+
{ key: publicKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING },
|
|
145
|
+
xorBytes
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
response(packet, out, opts, info) {
|
|
150
|
+
const marker = packet.peek();
|
|
151
|
+
switch (marker) {
|
|
152
|
+
//*********************************************************************************************************
|
|
153
|
+
//* OK_Packet and Err_Packet ending packet
|
|
154
|
+
//*********************************************************************************************************
|
|
155
|
+
case 0x00:
|
|
156
|
+
case 0xff:
|
|
157
|
+
this.emit('send_end');
|
|
158
|
+
return this.successSend(packet, out, opts, info);
|
|
159
|
+
|
|
160
|
+
default:
|
|
161
|
+
let promptData = packet.readBufferRemaining();
|
|
162
|
+
this.exchange(promptData, out, opts, info);
|
|
163
|
+
this.onPacketReceive = this.response;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = CachingSha2PasswordAuth;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const PluginAuth = require('./plugin-auth');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Send password in clear.
|
|
5
|
+
* (used only when SSL is active)
|
|
6
|
+
*/
|
|
7
|
+
class ClearPasswordAuth extends PluginAuth {
|
|
8
|
+
constructor(packSeq, compressPackSeq, pluginData, resolve, reject, multiAuthResolver) {
|
|
9
|
+
super(resolve, reject, multiAuthResolver);
|
|
10
|
+
this.sequenceNo = packSeq;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
start(out, opts, info) {
|
|
14
|
+
out.startPacket(this);
|
|
15
|
+
if (opts.password) out.writeString(opts.password);
|
|
16
|
+
out.writeInt8(0);
|
|
17
|
+
out.flushBuffer(true);
|
|
18
|
+
this.emit('send_end');
|
|
19
|
+
this.onPacketReceive = this.successSend;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = ClearPasswordAuth;
|