@tachybase/module-multi-app 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +34 -34
  2. package/README.zh-CN.md +34 -34
  3. package/client.d.ts +1 -1
  4. package/client.js +1 -1
  5. package/dist/externalVersion.js +5 -5
  6. package/dist/locale/en-US.json +48 -48
  7. package/dist/locale/es-ES.json +9 -9
  8. package/dist/locale/ko_KR.json +11 -11
  9. package/dist/locale/pt-BR.json +9 -9
  10. package/dist/locale/zh-CN.json +58 -58
  11. package/dist/node_modules/mariadb/callback.js +43 -8
  12. package/dist/node_modules/mariadb/check-node.js +30 -0
  13. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  14. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  15. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  16. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  17. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  18. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  19. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  20. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  21. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  22. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  23. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  24. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  25. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  26. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  27. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  28. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  29. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  34. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  35. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  43. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  44. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  45. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  46. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  47. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  48. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  49. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  50. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  51. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  52. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  53. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  54. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  55. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  56. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  57. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  58. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  59. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  60. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  61. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  62. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  63. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  64. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  65. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  66. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  67. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  68. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  69. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  70. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  71. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  72. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  73. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  74. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  75. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  76. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  77. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  78. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  79. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  80. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  81. package/dist/node_modules/mariadb/package.json +1 -1
  82. package/dist/node_modules/mariadb/promise.js +1 -34
  83. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  84. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  85. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  86. package/dist/node_modules/qs/package.json +1 -1
  87. package/dist/server/actions/apps.js +2 -2
  88. package/dist/server/app-lifecycle.d.ts +1 -1
  89. package/dist/server/app-lifecycle.js +4 -4
  90. package/dist/server/models/application.d.ts +1 -1
  91. package/package.json +7 -7
  92. package/server.d.ts +2 -2
  93. package/server.js +1 -1
  94. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  95. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  96. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  97. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  98. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  99. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  100. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  101. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  102. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  103. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -0,0 +1,282 @@
1
+ // SPDX-License-Identifier: LGPL-2.1-or-later
2
+ // Copyright (c) 2015-2024 MariaDB Corporation Ab
3
+
4
+ 'use strict';
5
+
6
+ const FieldType = require('../../const/field-type');
7
+ const Errors = require('../../misc/errors');
8
+
9
+ module.exports.newRow = function (packet, columns) {
10
+ packet.skip(1); // skip 0x00 header.
11
+ const len = ~~((columns.length + 9) / 8);
12
+ const nullBitMap = new Array(len);
13
+ for (let i = 0; i < len; i++) nullBitMap[i] = packet.readUInt8();
14
+ return nullBitMap;
15
+ };
16
+ module.exports.castWrapper = function (column, packet, opts, nullBitmap, index) {
17
+ column.string = () => (isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded());
18
+ column.buffer = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded());
19
+ column.float = () => (isNullBitmap(index, nullBitmap) ? null : packet.readFloat());
20
+ column.tiny = () =>
21
+ isNullBitmap(index, nullBitmap) ? null : column.signed() ? packet.readInt8() : packet.readUInt8();
22
+ column.short = () =>
23
+ isNullBitmap(index, nullBitmap) ? null : column.signed() ? packet.readInt16() : packet.readUInt16();
24
+ column.int = () => (isNullBitmap(index, nullBitmap) ? null : packet.readInt32());
25
+ column.long = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBigInt64());
26
+ column.decimal = () => (isNullBitmap(index, nullBitmap) ? null : packet.readDecimalLengthEncoded());
27
+ column.date = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDate(opts));
28
+ column.datetime = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDateTime());
29
+
30
+ column.geometry = () => {
31
+ let defaultVal = null;
32
+ if (column.dataTypeName) {
33
+ switch (column.dataTypeName) {
34
+ case 'point':
35
+ defaultVal = { type: 'Point' };
36
+ break;
37
+ case 'linestring':
38
+ defaultVal = { type: 'LineString' };
39
+ break;
40
+ case 'polygon':
41
+ defaultVal = { type: 'Polygon' };
42
+ break;
43
+ case 'multipoint':
44
+ defaultVal = { type: 'MultiPoint' };
45
+ break;
46
+ case 'multilinestring':
47
+ defaultVal = { type: 'MultiLineString' };
48
+ break;
49
+ case 'multipolygon':
50
+ defaultVal = { type: 'MultiPolygon' };
51
+ break;
52
+ default:
53
+ defaultVal = { type: column.dataTypeName };
54
+ break;
55
+ }
56
+ }
57
+
58
+ if (isNullBitmap(index, nullBitmap)) {
59
+ return defaultVal;
60
+ }
61
+ return packet.readGeometry(defaultVal);
62
+ };
63
+ };
64
+ module.exports.parser = function (col, opts) {
65
+ // set reader function read(col, packet, index, nullBitmap, opts, throwUnexpectedError)
66
+ // this permit for multi-row result-set to avoid resolving type parsing each data.
67
+
68
+ // return constant parser (function not depending on column info other than type)
69
+ const defaultParser = col.signed()
70
+ ? DEFAULT_SIGNED_PARSER_TYPE[col.columnType]
71
+ : DEFAULT_UNSIGNED_PARSER_TYPE[col.columnType];
72
+ if (defaultParser) return defaultParser;
73
+
74
+ // parser depending on column info
75
+ switch (col.columnType) {
76
+ case FieldType.BIGINT:
77
+ if (col.signed()) {
78
+ return opts.bigIntAsNumber || opts.supportBigNumbers ? readBigintAsIntBinarySigned : readBigintBinarySigned;
79
+ }
80
+ return opts.bigIntAsNumber || opts.supportBigNumbers ? readBigintAsIntBinaryUnsigned : readBigintBinaryUnsigned;
81
+
82
+ case FieldType.DATETIME:
83
+ case FieldType.TIMESTAMP:
84
+ return opts.dateStrings ? readTimestampStringBinary.bind(null, col.scale) : readTimestampBinary;
85
+
86
+ case FieldType.DECIMAL:
87
+ case FieldType.NEWDECIMAL:
88
+ return col.scale === 0 ? readDecimalAsIntBinary : readDecimalBinary;
89
+
90
+ case FieldType.GEOMETRY:
91
+ let defaultVal = col.__getDefaultGeomVal();
92
+ return readGeometryBinary.bind(null, defaultVal);
93
+
94
+ case FieldType.BIT:
95
+ if (col.columnLength === 1 && opts.bitOneIsBoolean) {
96
+ return readBitBinaryBoolean;
97
+ }
98
+ return readBinaryBuffer;
99
+ case FieldType.JSON:
100
+ return opts.jsonStrings ? readStringBinary : readJsonBinary;
101
+
102
+ default:
103
+ if (col.dataTypeFormat && col.dataTypeFormat === 'json' && opts.autoJsonMap) {
104
+ return readJsonBinary;
105
+ }
106
+ if (col.collation.index === 63) {
107
+ return readBinaryBuffer;
108
+ }
109
+ if (col.isSet()) {
110
+ return readBinarySet;
111
+ }
112
+ return readStringBinary;
113
+ }
114
+ };
115
+
116
+ const isNullBitmap = (index, nullBitmap) => {
117
+ return (nullBitmap[~~((index + 2) / 8)] & (1 << (index + 2) % 8)) > 0;
118
+ };
119
+
120
+ const readTinyBinarySigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
121
+ isNullBitmap(index, nullBitmap) ? null : packet.readInt8();
122
+ const readTinyBinaryUnsigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
123
+ isNullBitmap(index, nullBitmap) ? null : packet.readUInt8();
124
+ const readShortBinarySigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
125
+ isNullBitmap(index, nullBitmap) ? null : packet.readInt16();
126
+ const readShortBinaryUnsigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
127
+ isNullBitmap(index, nullBitmap) ? null : packet.readUInt16();
128
+ const readMediumBinarySigned = (packet, opts, throwUnexpectedError, nullBitmap, index) => {
129
+ if (isNullBitmap(index, nullBitmap)) {
130
+ return null;
131
+ }
132
+ const result = packet.readInt24();
133
+ packet.skip(1); // MEDIUMINT is encoded on 4 bytes in exchanges !
134
+ return result;
135
+ };
136
+ const readMediumBinaryUnsigned = (packet, opts, throwUnexpectedError, nullBitmap, index) => {
137
+ if (isNullBitmap(index, nullBitmap)) {
138
+ return null;
139
+ }
140
+ const result = packet.readUInt24();
141
+ packet.skip(1); // MEDIUMINT is encoded on 4 bytes in exchanges !
142
+ return result;
143
+ };
144
+ const readIntBinarySigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
145
+ isNullBitmap(index, nullBitmap) ? null : packet.readInt32();
146
+ const readIntBinaryUnsigned = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
147
+ isNullBitmap(index, nullBitmap) ? null : packet.readUInt32();
148
+ const readFloatBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
149
+ isNullBitmap(index, nullBitmap) ? null : packet.readFloat();
150
+ const readDoubleBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
151
+ isNullBitmap(index, nullBitmap) ? null : packet.readDouble();
152
+ const readBigintBinaryUnsigned = function (packet, opts, throwUnexpectedError, nullBitmap, index) {
153
+ if (isNullBitmap(index, nullBitmap)) return null;
154
+ return packet.readBigUInt64();
155
+ };
156
+ const readBigintBinarySigned = function (packet, opts, throwUnexpectedError, nullBitmap, index) {
157
+ if (isNullBitmap(index, nullBitmap)) return null;
158
+ return packet.readBigInt64();
159
+ };
160
+
161
+ const readBigintAsIntBinaryUnsigned = function (packet, opts, throwUnexpectedError, nullBitmap, index) {
162
+ if (isNullBitmap(index, nullBitmap)) return null;
163
+ const val = packet.readBigUInt64();
164
+ if (opts.bigIntAsNumber && opts.checkNumberRange && !Number.isSafeInteger(Number(val))) {
165
+ return throwUnexpectedError(
166
+ `value ${val} can't safely be converted to number`,
167
+ false,
168
+ null,
169
+ '42000',
170
+ Errors.ER_PARSING_PRECISION
171
+ );
172
+ }
173
+ if (opts.supportBigNumbers && (opts.bigNumberStrings || !Number.isSafeInteger(Number(val)))) {
174
+ return val.toString();
175
+ }
176
+ return Number(val);
177
+ };
178
+
179
+ const readBigintAsIntBinarySigned = function (packet, opts, throwUnexpectedError, nullBitmap, index) {
180
+ if (isNullBitmap(index, nullBitmap)) return null;
181
+ const val = packet.readBigInt64();
182
+ if (opts.bigIntAsNumber && opts.checkNumberRange && !Number.isSafeInteger(Number(val))) {
183
+ return throwUnexpectedError(
184
+ `value ${val} can't safely be converted to number`,
185
+ false,
186
+ null,
187
+ '42000',
188
+ Errors.ER_PARSING_PRECISION
189
+ );
190
+ }
191
+ if (opts.supportBigNumbers && (opts.bigNumberStrings || !Number.isSafeInteger(Number(val)))) {
192
+ return val.toString();
193
+ }
194
+ return Number(val);
195
+ };
196
+
197
+ const readGeometryBinary = (defaultVal, packet, opts, throwUnexpectedError, nullBitmap, index) => {
198
+ if (isNullBitmap(index, nullBitmap)) {
199
+ return defaultVal;
200
+ }
201
+ return packet.readGeometry(defaultVal);
202
+ };
203
+ const readDateBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
204
+ isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDate(opts);
205
+ const readTimestampBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
206
+ isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDateTime();
207
+ const readTimestampStringBinary = (scale, packet, opts, throwUnexpectedError, nullBitmap, index) =>
208
+ isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDateTimeAsString(scale);
209
+ const readTimeBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
210
+ isNullBitmap(index, nullBitmap) ? null : packet.readBinaryTime();
211
+ const readDecimalAsIntBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) => {
212
+ //checkNumberRange additional check is only done when
213
+ // resulting value is an integer
214
+ if (isNullBitmap(index, nullBitmap)) return null;
215
+ const valDec = packet.readDecimalLengthEncoded();
216
+ if (valDec != null && (opts.decimalAsNumber || opts.supportBigNumbers)) {
217
+ if (opts.decimalAsNumber && opts.checkNumberRange && !Number.isSafeInteger(Number(valDec))) {
218
+ return throwUnexpectedError(
219
+ `value ${valDec} can't safely be converted to number`,
220
+ false,
221
+ null,
222
+ '42000',
223
+ Errors.ER_PARSING_PRECISION
224
+ );
225
+ }
226
+ if (opts.supportBigNumbers && (opts.bigNumberStrings || !Number.isSafeInteger(Number(valDec)))) {
227
+ return valDec;
228
+ }
229
+ return Number(valDec);
230
+ }
231
+ return valDec;
232
+ };
233
+ const readDecimalBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) => {
234
+ if (isNullBitmap(index, nullBitmap)) return null;
235
+ const valDec = packet.readDecimalLengthEncoded();
236
+ if (valDec != null && (opts.decimalAsNumber || opts.supportBigNumbers)) {
237
+ const numberValue = Number(valDec);
238
+ if (
239
+ opts.supportBigNumbers &&
240
+ (opts.bigNumberStrings || (Number.isInteger(numberValue) && !Number.isSafeInteger(numberValue)))
241
+ ) {
242
+ return valDec;
243
+ }
244
+ return numberValue;
245
+ }
246
+ return valDec;
247
+ };
248
+ const readJsonBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
249
+ isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLengthEncoded());
250
+ const readBitBinaryBoolean = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
251
+ isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded()[0] === 1;
252
+ const readBinaryBuffer = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
253
+ isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded();
254
+ const readBinarySet = (packet, opts, throwUnexpectedError, nullBitmap, index) => {
255
+ if (isNullBitmap(index, nullBitmap)) return null;
256
+ const string = packet.readStringLengthEncoded();
257
+ return string == null ? null : string === '' ? [] : string.split(',');
258
+ };
259
+ const readStringBinary = (packet, opts, throwUnexpectedError, nullBitmap, index) =>
260
+ isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded();
261
+
262
+ const DEFAULT_SIGNED_PARSER_TYPE = Array(256);
263
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.TINY] = readTinyBinarySigned;
264
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.YEAR] = readShortBinarySigned;
265
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.SHORT] = readShortBinarySigned;
266
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.INT24] = readMediumBinarySigned;
267
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.INT] = readIntBinarySigned;
268
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.FLOAT] = readFloatBinary;
269
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.DOUBLE] = readDoubleBinary;
270
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.DATE] = readDateBinary;
271
+ DEFAULT_SIGNED_PARSER_TYPE[FieldType.TIME] = readTimeBinary;
272
+
273
+ const DEFAULT_UNSIGNED_PARSER_TYPE = Array(256);
274
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.TINY] = readTinyBinaryUnsigned;
275
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.YEAR] = readShortBinaryUnsigned;
276
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.SHORT] = readShortBinaryUnsigned;
277
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.INT24] = readMediumBinaryUnsigned;
278
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.INT] = readIntBinaryUnsigned;
279
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.FLOAT] = readFloatBinary;
280
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.DOUBLE] = readDoubleBinary;
281
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.DATE] = readDateBinary;
282
+ DEFAULT_UNSIGNED_PARSER_TYPE[FieldType.TIME] = readTimeBinary;
@@ -0,0 +1,210 @@
1
+ // SPDX-License-Identifier: LGPL-2.1-or-later
2
+ // Copyright (c) 2015-2024 MariaDB Corporation Ab
3
+
4
+ 'use strict';
5
+
6
+ const FieldType = require('../../const/field-type');
7
+ const Errors = require('../../misc/errors');
8
+
9
+ module.exports.parser = function (col, opts) {
10
+ // Fast path: For most types, we can directly return the default parser
11
+ // This avoids the cost of the switch statement for common types
12
+ const defaultParser = DEFAULT_PARSER_TYPE[col.columnType];
13
+ if (defaultParser) return defaultParser;
14
+
15
+ // Parser depending on column info
16
+ switch (col.columnType) {
17
+ case FieldType.DECIMAL:
18
+ case FieldType.NEWDECIMAL:
19
+ return col.scale === 0 ? readDecimalAsIntLengthCoded : readDecimalLengthCoded;
20
+
21
+ case FieldType.BIGINT:
22
+ if (opts.bigIntAsNumber || opts.supportBigNumbers) return readBigIntAsNumberLengthCoded;
23
+ return readBigIntLengthCoded;
24
+
25
+ case FieldType.GEOMETRY:
26
+ const defaultVal = col.__getDefaultGeomVal();
27
+ return function (packet, opts, throwUnexpectedError) {
28
+ return packet.readGeometry(defaultVal);
29
+ };
30
+
31
+ case FieldType.BIT:
32
+ if (col.columnLength === 1 && opts.bitOneIsBoolean) {
33
+ return readBitAsBoolean;
34
+ }
35
+ return readBufferLengthEncoded;
36
+
37
+ case FieldType.JSON:
38
+ return opts.jsonStrings ? readStringLengthEncoded : readJson;
39
+
40
+ default:
41
+ if (col.dataTypeFormat === 'json' && opts.autoJsonMap) {
42
+ return readJson;
43
+ }
44
+ if (col.collation.index === 63) {
45
+ return readBufferLengthEncoded;
46
+ }
47
+ if (col.isSet()) {
48
+ return readSet;
49
+ }
50
+ return readStringLengthEncoded;
51
+ }
52
+ };
53
+
54
+ module.exports.castWrapper = function (column, packet, opts, nullBitmap, index) {
55
+ const p = packet;
56
+
57
+ column.string = () => p.readStringLengthEncoded();
58
+ column.buffer = () => p.readBufferLengthEncoded();
59
+ column.float = () => p.readFloatLengthCoded();
60
+ column.tiny = column.short = column.int = () => p.readIntLengthEncoded();
61
+ column.long = () => p.readBigIntLengthEncoded();
62
+ column.decimal = () => p.readDecimalLengthEncoded();
63
+ column.date = () => p.readDate(opts);
64
+ column.datetime = () => p.readDateTime();
65
+
66
+ // Only define geometry method if needed (likely less common)
67
+ // Inline the geometry switch case for better performance
68
+ column.geometry = () => {
69
+ let defaultVal = null;
70
+
71
+ if (column.dataTypeName) {
72
+ // Use object lookup instead of switch for better performance
73
+ const geoTypes = {
74
+ point: { type: 'Point' },
75
+ linestring: { type: 'LineString' },
76
+ polygon: { type: 'Polygon' },
77
+ multipoint: { type: 'MultiPoint' },
78
+ multilinestring: { type: 'MultiLineString' },
79
+ multipolygon: { type: 'MultiPolygon' }
80
+ };
81
+
82
+ defaultVal = geoTypes[column.dataTypeName] || { type: column.dataTypeName };
83
+ }
84
+
85
+ return p.readGeometry(defaultVal);
86
+ };
87
+ };
88
+
89
+ const readIntLengthEncoded = (packet, opts, throwUnexpectedError) => packet.readIntLengthEncoded();
90
+ const readStringLengthEncoded = (packet, opts, throwUnexpectedError) => packet.readStringLengthEncoded();
91
+ const readFloatLengthCoded = (packet, opts, throwUnexpectedError) => packet.readFloatLengthCoded();
92
+ const readBigIntLengthCoded = (packet, opts, throwUnexpectedError) => packet.readBigIntLengthEncoded();
93
+ const readAsciiStringLengthEncoded = (packet, opts, throwUnexpectedError) => packet.readAsciiStringLengthEncoded();
94
+ const readBitAsBoolean = (packet, opts, throwUnexpectedError) => {
95
+ const val = packet.readBufferLengthEncoded();
96
+ return val == null ? null : val[0] === 1;
97
+ };
98
+ const readBufferLengthEncoded = (packet, opts, throwUnexpectedError) => packet.readBufferLengthEncoded();
99
+
100
+ const readJson = (packet, opts, throwUnexpectedError) => {
101
+ const jsonStr = packet.readStringLengthEncoded();
102
+ return jsonStr === null ? null : JSON.parse(jsonStr);
103
+ };
104
+
105
+ const readSet = (packet, opts, throwUnexpectedError) => {
106
+ const string = packet.readStringLengthEncoded();
107
+ return string == null ? null : string === '' ? [] : string.split(',');
108
+ };
109
+
110
+ const readDate = (packet, opts, throwUnexpectedError) =>
111
+ opts.dateStrings ? packet.readAsciiStringLengthEncoded() : packet.readDate();
112
+
113
+ const readTimestamp = (packet, opts, throwUnexpectedError) =>
114
+ opts.dateStrings ? packet.readAsciiStringLengthEncoded() : packet.readDateTime();
115
+
116
+ // Initialize the DEFAULT_PARSER_TYPE array with frequently used types
117
+ // Use a typed array for performance when accessing elements
118
+ const DEFAULT_PARSER_TYPE = new Array(256);
119
+ DEFAULT_PARSER_TYPE[FieldType.TINY] = readIntLengthEncoded;
120
+ DEFAULT_PARSER_TYPE[FieldType.SHORT] = readIntLengthEncoded;
121
+ DEFAULT_PARSER_TYPE[FieldType.INT] = readIntLengthEncoded;
122
+ DEFAULT_PARSER_TYPE[FieldType.INT24] = readIntLengthEncoded;
123
+ DEFAULT_PARSER_TYPE[FieldType.YEAR] = readIntLengthEncoded;
124
+ DEFAULT_PARSER_TYPE[FieldType.FLOAT] = readFloatLengthCoded;
125
+ DEFAULT_PARSER_TYPE[FieldType.DOUBLE] = readFloatLengthCoded;
126
+ DEFAULT_PARSER_TYPE[FieldType.DATE] = readDate;
127
+ DEFAULT_PARSER_TYPE[FieldType.DATETIME] = readTimestamp;
128
+ DEFAULT_PARSER_TYPE[FieldType.TIMESTAMP] = readTimestamp;
129
+ DEFAULT_PARSER_TYPE[FieldType.TIME] = readAsciiStringLengthEncoded;
130
+
131
+ const readBigIntAsNumberLengthCoded = (packet, opts, throwUnexpectedError) => {
132
+ const len = packet.readUnsignedLength();
133
+ if (len === null) return null;
134
+
135
+ // Fast path for small integers
136
+ if (len < 16) {
137
+ const val = packet._atoi(len);
138
+ // We know we're here because either bigIntAsNumber or supportBigNumbers is true
139
+ if (opts.supportBigNumbers && opts.bigNumberStrings) {
140
+ return `${val}`;
141
+ }
142
+ return val;
143
+ }
144
+
145
+ const val = packet.readBigIntFromLen(len);
146
+ if (opts.bigIntAsNumber && opts.checkNumberRange && !Number.isSafeInteger(Number(val))) {
147
+ return throwUnexpectedError(
148
+ `value ${val} can't safely be converted to number`,
149
+ false,
150
+ null,
151
+ '42000',
152
+ Errors.ER_PARSING_PRECISION
153
+ );
154
+ }
155
+ const numVal = Number(val);
156
+ if (opts.supportBigNumbers && (opts.bigNumberStrings || !Number.isSafeInteger(numVal))) {
157
+ return val.toString();
158
+ }
159
+
160
+ return numVal;
161
+ };
162
+
163
+ const readDecimalAsIntLengthCoded = (packet, opts, throwUnexpectedError) => {
164
+ const valDec = packet.readDecimalLengthEncoded();
165
+ if (valDec === null) return null;
166
+
167
+ // Only perform conversions if needed based on options
168
+ if (!(opts.decimalAsNumber || opts.supportBigNumbers)) return valDec;
169
+
170
+ // Convert once
171
+ const numValue = Number(valDec);
172
+
173
+ // Check number range if required
174
+ if (opts.decimalAsNumber && opts.checkNumberRange && !Number.isSafeInteger(numValue)) {
175
+ return throwUnexpectedError(
176
+ `value ${valDec} can't safely be converted to number`,
177
+ false,
178
+ null,
179
+ '42000',
180
+ Errors.ER_PARSING_PRECISION
181
+ );
182
+ }
183
+
184
+ // Return string representation for big numbers if needed
185
+ if (opts.supportBigNumbers && (opts.bigNumberStrings || !Number.isSafeInteger(numValue))) {
186
+ return valDec;
187
+ }
188
+
189
+ return numValue;
190
+ };
191
+
192
+ const readDecimalLengthCoded = (packet, opts, throwUnexpectedError) => {
193
+ const valDec = packet.readDecimalLengthEncoded();
194
+ if (valDec === null) return null;
195
+
196
+ // Only perform conversions if needed based on options
197
+ if (!(opts.decimalAsNumber || opts.supportBigNumbers)) return valDec;
198
+
199
+ const numberValue = Number(valDec);
200
+
201
+ // Handle big numbers specifically
202
+ if (
203
+ opts.supportBigNumbers &&
204
+ (opts.bigNumberStrings || (Number.isInteger(numberValue) && !Number.isSafeInteger(numberValue)))
205
+ ) {
206
+ return valDec;
207
+ }
208
+
209
+ return numberValue;
210
+ };
@@ -1,15 +1,9 @@
1
- 'use strict';
2
-
3
- const ResultSet = require('./resultset');
1
+ // SPDX-License-Identifier: LGPL-2.1-or-later
2
+ // Copyright (c) 2015-2024 MariaDB Corporation Ab
4
3
 
5
- class CommonBinary extends ResultSet {
6
- constructor(resolve, reject, cmdOpts, connOpts, sql, values) {
7
- super(resolve, reject);
8
- this.configAssign(connOpts, cmdOpts);
9
- this.sql = sql;
10
- this.initialValues = values;
11
- }
4
+ 'use strict';
12
5
 
6
+ class BinaryEncoder {
13
7
  /**
14
8
  * Write (and escape) current parameter value to output writer
15
9
  *
@@ -18,65 +12,49 @@ class CommonBinary extends ResultSet {
18
12
  * @param opts connection options
19
13
  * @param info connection information
20
14
  */
21
- writeParam(out, value, opts, info) {
22
- let flushed = false;
15
+ static writeParam(out, value, opts, info) {
16
+ // GEOJSON are not checked, because change to null/Buffer on parameter validation
23
17
  switch (typeof value) {
24
18
  case 'boolean':
25
- flushed = out.writeInt8(0x00);
26
- flushed = out.writeInt8(value ? 0x01 : 0x00) || flushed;
19
+ out.writeInt8(value ? 0x01 : 0x00);
27
20
  break;
28
21
  case 'bigint':
22
+ if (value >= 2n ** 63n) {
23
+ out.writeLengthEncodedString(value.toString());
24
+ } else {
25
+ out.writeBigInt(value);
26
+ }
27
+ break;
28
+
29
29
  case 'number':
30
- flushed = out.writeInt8(0x00);
31
- flushed = out.writeLengthStringAscii('' + value) || flushed;
30
+ // additional verification, to permit query without type,
31
+ // like 'SELECT ?' returning same type of value
32
+ if (Number.isInteger(value) && value >= -2147483648 && value < 2147483647) {
33
+ out.writeInt32(value);
34
+ break;
35
+ }
36
+ out.writeDouble(value);
37
+ break;
38
+ case 'string':
39
+ out.writeLengthEncodedString(value);
32
40
  break;
33
41
  case 'object':
34
42
  if (Object.prototype.toString.call(value) === '[object Date]') {
35
- flushed = out.writeInt8(0x00);
36
- flushed = out.writeBinaryDate(value, opts) || flushed;
43
+ out.writeBinaryDate(value);
37
44
  } else if (Buffer.isBuffer(value)) {
38
- flushed = out.writeInt8(0x00);
39
- flushed = out.writeLengthEncodedBuffer(value) || flushed;
45
+ out.writeLengthEncodedBuffer(value);
40
46
  } else if (typeof value.toSqlString === 'function') {
41
- flushed = out.writeInt8(0x00);
42
- flushed = out.writeLengthEncodedString(String(value.toSqlString())) || flushed;
47
+ out.writeLengthEncodedString(String(value.toSqlString()));
43
48
  } else {
44
- if (
45
- value.type != null &&
46
- [
47
- 'Point',
48
- 'LineString',
49
- 'Polygon',
50
- 'MultiPoint',
51
- 'MultiLineString',
52
- 'MultiPolygon',
53
- 'GeometryCollection'
54
- ].includes(value.type)
55
- ) {
56
- const geoBuff = this.getBufferFromGeometryValue(value);
57
- if (geoBuff) {
58
- flushed = out.writeInt8(0x00); //Value follow
59
- flushed =
60
- out.writeLengthEncodedBuffer(Buffer.concat([Buffer.from([0, 0, 0, 0]), geoBuff])) ||
61
- flushed;
62
- } else {
63
- flushed = out.writeInt8(0x01); //NULL
64
- }
65
- } else {
66
- //TODO check if permitSetMultiParamEntries is needed !?
67
- flushed = out.writeInt8(0x00);
68
- flushed = out.writeLengthEncodedString(JSON.stringify(value)) || flushed;
69
- }
49
+ out.writeLengthEncodedString(JSON.stringify(value));
70
50
  }
71
51
  break;
72
52
  default:
73
- flushed = out.writeInt8(0x00);
74
- flushed = out.writeLengthEncodedString(value) || flushed;
53
+ out.writeLengthEncodedBuffer(value);
75
54
  }
76
- return flushed;
77
55
  }
78
56
 
79
- getBufferFromGeometryValue(value, headerType) {
57
+ static getBufferFromGeometryValue(value, headerType) {
80
58
  let geoBuff;
81
59
  let pos;
82
60
  let type;
@@ -196,7 +174,7 @@ class CommonBinary extends ResultSet {
196
174
  const subArrays = [geoBuff];
197
175
  for (let i = 0; i < coordinateLength; i++) {
198
176
  const tmpBuf = this.getBufferFromGeometryValue(value.geometries[i]);
199
- if (tmpBuf == null) break;
177
+ if (tmpBuf === null) break;
200
178
  subArrays.push(tmpBuf);
201
179
  }
202
180
  geoBuff.writeInt32LE(subArrays.length - 1, 5);
@@ -213,7 +191,7 @@ class CommonBinary extends ResultSet {
213
191
  const subArrays = [geoBuff];
214
192
  for (let i = 0; i < coordinateLength; i++) {
215
193
  const tmpBuf = this.getBufferFromGeometryValue(value.coordinates[i], type);
216
- if (tmpBuf == null) break;
194
+ if (tmpBuf === null) break;
217
195
  subArrays.push(tmpBuf);
218
196
  }
219
197
  geoBuff.writeInt32LE(subArrays.length - 1, 5);
@@ -225,13 +203,7 @@ class CommonBinary extends ResultSet {
225
203
  } else {
226
204
  switch (headerType) {
227
205
  case 'MultiPoint':
228
- if (
229
- value &&
230
- Array.isArray(value) &&
231
- value.length >= 2 &&
232
- !isNaN(value[0]) &&
233
- !isNaN(value[1])
234
- ) {
206
+ if (value && Array.isArray(value) && value.length >= 2 && !isNaN(value[0]) && !isNaN(value[1])) {
235
207
  geoBuff = Buffer.allocUnsafe(21);
236
208
  geoBuff.writeInt8(0x01, 0); //LITTLE ENDIAN
237
209
  geoBuff.writeInt32LE(1, 1); //wkbPoint
@@ -307,21 +279,6 @@ class CommonBinary extends ResultSet {
307
279
  return null;
308
280
  }
309
281
  }
310
-
311
- /**
312
- * Read text result-set row
313
- *
314
- * see: https://mariadb.com/kb/en/library/resultset-row/#text-resultset-row
315
- * data are created according to their type.
316
- *
317
- * @param columns columns metadata
318
- * @param packet current row packet
319
- * @param connOpts connection options
320
- * @returns {*} row data
321
- */
322
- parseRow(columns, packet, connOpts) {
323
- throw new Error('not implemented');
324
- }
325
282
  }
326
283
 
327
- module.exports = CommonBinary;
284
+ module.exports = BinaryEncoder;