@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.
Files changed (117) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/README.md +34 -0
  3. package/README.zh-CN.md +34 -0
  4. package/client.d.ts +1 -0
  5. package/client.js +1 -0
  6. package/dist/client/AppManager.d.ts +2 -0
  7. package/dist/client/AppNameInput.d.ts +2 -0
  8. package/dist/client/MultiAppBlockInitializer.d.ts +2 -0
  9. package/dist/client/MultiAppManagerProvider.d.ts +2 -0
  10. package/dist/client/MultiAppManagerProvider.style.d.ts +5 -0
  11. package/dist/client/Settings.d.ts +2 -0
  12. package/dist/client/index.d.ts +6 -0
  13. package/dist/client/index.js +1 -0
  14. package/dist/client/settings/schemas/applications.d.ts +13 -0
  15. package/dist/client/utils.d.ts +4 -0
  16. package/dist/constants.d.ts +1 -0
  17. package/dist/constants.js +27 -0
  18. package/dist/externalVersion.js +16 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +39 -0
  21. package/dist/locale/en-US.json +27 -0
  22. package/dist/locale/es-ES.json +9 -0
  23. package/dist/locale/ko_KR.json +11 -0
  24. package/dist/locale/pt-BR.json +9 -0
  25. package/dist/locale/zh-CN.json +27 -0
  26. package/dist/node_modules/mariadb/LICENSE +502 -0
  27. package/dist/node_modules/mariadb/callback.js +41 -0
  28. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +278 -0
  29. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +372 -0
  30. package/dist/node_modules/mariadb/lib/cmd/change-user.js +149 -0
  31. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +17 -0
  32. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +102 -0
  33. package/dist/node_modules/mariadb/lib/cmd/command.js +168 -0
  34. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +327 -0
  35. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +427 -0
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +168 -0
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +23 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +761 -0
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +55 -0
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +58 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +19 -0
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +142 -0
  43. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +74 -0
  44. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +126 -0
  45. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +292 -0
  46. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +74 -0
  47. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +29 -0
  48. package/dist/node_modules/mariadb/lib/cmd/ping.js +52 -0
  49. package/dist/node_modules/mariadb/lib/cmd/query.js +255 -0
  50. package/dist/node_modules/mariadb/lib/cmd/quit.js +28 -0
  51. package/dist/node_modules/mariadb/lib/cmd/reset.js +54 -0
  52. package/dist/node_modules/mariadb/lib/cmd/resultset.js +607 -0
  53. package/dist/node_modules/mariadb/lib/cmd/stream.js +45 -0
  54. package/dist/node_modules/mariadb/lib/config/connection-options.js +258 -0
  55. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +19 -0
  56. package/dist/node_modules/mariadb/lib/config/pool-options.js +47 -0
  57. package/dist/node_modules/mariadb/lib/connection-callback.js +160 -0
  58. package/dist/node_modules/mariadb/lib/connection.js +1460 -0
  59. package/dist/node_modules/mariadb/lib/const/capabilities.js +64 -0
  60. package/dist/node_modules/mariadb/lib/const/collations.js +473 -0
  61. package/dist/node_modules/mariadb/lib/const/connection_status.js +13 -0
  62. package/dist/node_modules/mariadb/lib/const/error-code.js +1282 -0
  63. package/dist/node_modules/mariadb/lib/const/field-detail.js +35 -0
  64. package/dist/node_modules/mariadb/lib/const/field-type.js +71 -0
  65. package/dist/node_modules/mariadb/lib/const/server-status.js +30 -0
  66. package/dist/node_modules/mariadb/lib/const/state-change.js +12 -0
  67. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +81 -0
  68. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +590 -0
  69. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +141 -0
  70. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +171 -0
  71. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +193 -0
  72. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +36 -0
  73. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +37 -0
  74. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +502 -0
  75. package/dist/node_modules/mariadb/lib/io/packet.js +515 -0
  76. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +481 -0
  77. package/dist/node_modules/mariadb/lib/misc/connection-information.js +96 -0
  78. package/dist/node_modules/mariadb/lib/misc/errors.js +123 -0
  79. package/dist/node_modules/mariadb/lib/misc/parse.js +1033 -0
  80. package/dist/node_modules/mariadb/lib/misc/utils.js +298 -0
  81. package/dist/node_modules/mariadb/lib/pool-base.js +611 -0
  82. package/dist/node_modules/mariadb/lib/pool-callback.js +202 -0
  83. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +66 -0
  84. package/dist/node_modules/mariadb/lib/pool-cluster.js +407 -0
  85. package/dist/node_modules/mariadb/lib/pool-promise.js +108 -0
  86. package/dist/node_modules/mariadb/package.json +1 -0
  87. package/dist/node_modules/mariadb/promise.js +34 -0
  88. package/dist/node_modules/mariadb/types/index.d.ts +870 -0
  89. package/dist/server/actions/apps.d.ts +5 -0
  90. package/dist/server/actions/apps.js +117 -0
  91. package/dist/server/app-lifecycle.d.ts +8 -0
  92. package/dist/server/app-lifecycle.js +99 -0
  93. package/dist/server/app-start-env.d.ts +2 -0
  94. package/dist/server/app-start-env.js +105 -0
  95. package/dist/server/collections/applications.d.ts +2 -0
  96. package/dist/server/collections/applications.js +82 -0
  97. package/dist/server/index.d.ts +4 -0
  98. package/dist/server/index.js +29 -0
  99. package/dist/server/middlewares/app-selector.d.ts +1 -0
  100. package/dist/server/middlewares/app-selector.js +47 -0
  101. package/dist/server/middlewares/index.d.ts +2 -0
  102. package/dist/server/middlewares/index.js +23 -0
  103. package/dist/server/middlewares/inject-app-list.d.ts +1 -0
  104. package/dist/server/middlewares/inject-app-list.js +48 -0
  105. package/dist/server/migrations/20240820153000-add-apps-tmpl.d.ts +6 -0
  106. package/dist/server/migrations/20240820153000-add-apps-tmpl.js +47 -0
  107. package/dist/server/migrations/20241126124904-add-createdBy.d.ts +6 -0
  108. package/dist/server/migrations/20241126124904-add-createdBy.js +41 -0
  109. package/dist/server/models/application.d.ts +10 -0
  110. package/dist/server/models/application.js +57 -0
  111. package/dist/server/server.d.ts +19 -0
  112. package/dist/server/server.js +246 -0
  113. package/dist/swagger/index.d.ts +197 -0
  114. package/dist/swagger/index.js +227 -0
  115. package/package.json +38 -0
  116. package/server.d.ts +2 -0
  117. package/server.js +1 -0
@@ -0,0 +1,515 @@
1
+ 'use strict';
2
+
3
+ const Errors = require('../misc/errors');
4
+ const Iconv = require('iconv-lite');
5
+ const Long = require('long');
6
+ const moment = require('moment-timezone');
7
+
8
+ /**
9
+ * Object to easily parse buffer.
10
+ *
11
+ */
12
+ class Packet {
13
+ constructor(buf, pos, end) {
14
+ this.buf = buf;
15
+ this.pos = pos;
16
+ this.end = end;
17
+ }
18
+
19
+ skip(n) {
20
+ this.pos += n;
21
+ }
22
+
23
+ readGeometry(dataTypeName) {
24
+ const geoBuf = this.readBufferLengthEncoded();
25
+ if (geoBuf === null || geoBuf.length === 0) {
26
+ if (dataTypeName) {
27
+ switch (dataTypeName) {
28
+ case 'point':
29
+ return { type: 'Point' };
30
+ case 'linestring':
31
+ return { type: 'LineString' };
32
+ case 'polygon':
33
+ return { type: 'Polygon' };
34
+ case 'multipoint':
35
+ return { type: 'MultiPoint' };
36
+ case 'multilinestring':
37
+ return { type: 'MultiLineString' };
38
+ case 'multipolygon':
39
+ return { type: 'MultiPolygon' };
40
+ default:
41
+ return { type: dataTypeName };
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+ let geoPos = 4;
47
+ return readGeometryObject(false);
48
+
49
+ function parseCoordinates(byteOrder) {
50
+ geoPos += 16;
51
+ const x = byteOrder ? geoBuf.readDoubleLE(geoPos - 16) : geoBuf.readDoubleBE(geoPos - 16);
52
+ const y = byteOrder ? geoBuf.readDoubleLE(geoPos - 8) : geoBuf.readDoubleBE(geoPos - 8);
53
+ return [x, y];
54
+ }
55
+
56
+ function readGeometryObject(inner) {
57
+ const byteOrder = geoBuf[geoPos++];
58
+ const wkbType = byteOrder ? geoBuf.readInt32LE(geoPos) : geoBuf.readInt32BE(geoPos);
59
+ geoPos += 4;
60
+ switch (wkbType) {
61
+ case 1: //wkbPoint
62
+ const coords = parseCoordinates(byteOrder);
63
+
64
+ if (inner) return coords;
65
+ return {
66
+ type: 'Point',
67
+ coordinates: coords
68
+ };
69
+
70
+ case 2: //wkbLineString
71
+ const pointNumber = byteOrder ? geoBuf.readInt32LE(geoPos) : geoBuf.readInt32BE(geoPos);
72
+ geoPos += 4;
73
+ let coordinates = [];
74
+ for (let i = 0; i < pointNumber; i++) {
75
+ coordinates.push(parseCoordinates(byteOrder));
76
+ }
77
+ if (inner) return coordinates;
78
+ return {
79
+ type: 'LineString',
80
+ coordinates: coordinates
81
+ };
82
+
83
+ case 3: //wkbPolygon
84
+ let polygonCoordinates = [];
85
+ const numRings = byteOrder ? geoBuf.readInt32LE(geoPos) : geoBuf.readInt32BE(geoPos);
86
+ geoPos += 4;
87
+ for (let ring = 0; ring < numRings; ring++) {
88
+ const pointNumber = byteOrder ? geoBuf.readInt32LE(geoPos) : geoBuf.readInt32BE(geoPos);
89
+ geoPos += 4;
90
+ let linesCoordinates = [];
91
+ for (let i = 0; i < pointNumber; i++) {
92
+ linesCoordinates.push(parseCoordinates(byteOrder));
93
+ }
94
+ polygonCoordinates.push(linesCoordinates);
95
+ }
96
+
97
+ if (inner) return polygonCoordinates;
98
+ return {
99
+ type: 'Polygon',
100
+ coordinates: polygonCoordinates
101
+ };
102
+
103
+ case 4: //wkbMultiPoint
104
+ return {
105
+ type: 'MultiPoint',
106
+ coordinates: parseGeomArray(byteOrder, true)
107
+ };
108
+
109
+ case 5: //wkbMultiLineString
110
+ return {
111
+ type: 'MultiLineString',
112
+ coordinates: parseGeomArray(byteOrder, true)
113
+ };
114
+ case 6: //wkbMultiPolygon
115
+ return {
116
+ type: 'MultiPolygon',
117
+ coordinates: parseGeomArray(byteOrder, true)
118
+ };
119
+ case 7: //wkbGeometryCollection
120
+ return {
121
+ type: 'GeometryCollection',
122
+ geometries: parseGeomArray(byteOrder, false)
123
+ };
124
+ }
125
+ return null;
126
+ }
127
+
128
+ function parseGeomArray(byteOrder, inner) {
129
+ let coordinates = [];
130
+ const number = byteOrder ? geoBuf.readInt32LE(geoPos) : geoBuf.readInt32BE(geoPos);
131
+ geoPos += 4;
132
+ for (let i = 0; i < number; i++) {
133
+ coordinates.push(readGeometryObject(inner));
134
+ }
135
+ return coordinates;
136
+ }
137
+ }
138
+
139
+ peek() {
140
+ return this.buf[this.pos];
141
+ }
142
+
143
+ remaining() {
144
+ return this.end - this.pos > 0;
145
+ }
146
+
147
+ readUInt8() {
148
+ return this.buf[this.pos++];
149
+ }
150
+
151
+ readUInt16() {
152
+ return this.buf[this.pos++] + (this.buf[this.pos++] << 8);
153
+ }
154
+
155
+ readUInt24() {
156
+ return this.buf[this.pos++] + (this.buf[this.pos++] << 8) + (this.buf[this.pos++] << 16);
157
+ }
158
+
159
+ readUInt32() {
160
+ return (
161
+ this.buf[this.pos++] +
162
+ (this.buf[this.pos++] << 8) +
163
+ (this.buf[this.pos++] << 16) +
164
+ this.buf[this.pos++] * 0x1000000
165
+ );
166
+ }
167
+
168
+ readInt32() {
169
+ return (
170
+ this.buf[this.pos++] +
171
+ (this.buf[this.pos++] << 8) +
172
+ (this.buf[this.pos++] << 16) +
173
+ (this.buf[this.pos++] << 24)
174
+ );
175
+ }
176
+
177
+ readInt32LE() {
178
+ return (
179
+ (this.buf[this.pos++] << 24) +
180
+ (this.buf[this.pos++] << 16) +
181
+ (this.buf[this.pos++] << 8) +
182
+ this.buf[this.pos++]
183
+ );
184
+ }
185
+
186
+ readInt64() {
187
+ // could use readBigInt64LE when support would be 10.20+
188
+ const val =
189
+ this.buf[this.pos + 4] +
190
+ this.buf[this.pos + 5] * 2 ** 8 +
191
+ this.buf[this.pos + 6] * 2 ** 16 +
192
+ (this.buf[this.pos + 7] << 24);
193
+ const vv =
194
+ (BigInt(val) << BigInt(32)) +
195
+ BigInt(
196
+ this.buf[this.pos] +
197
+ this.buf[this.pos + 1] * 2 ** 8 +
198
+ this.buf[this.pos + 2] * 2 ** 16 +
199
+ this.buf[this.pos + 3] * 2 ** 24
200
+ );
201
+ this.pos += 8;
202
+ return vv;
203
+ }
204
+
205
+ readUnsignedLength() {
206
+ const type = this.buf[this.pos++] & 0xff;
207
+ switch (type) {
208
+ case 0xfb:
209
+ return null;
210
+ case 0xfc:
211
+ return this.readUInt16();
212
+ case 0xfd:
213
+ return this.readUInt24();
214
+ case 0xfe:
215
+ // limitation to BigInt signed value
216
+ return Number(this.readInt64());
217
+ default:
218
+ return type;
219
+ }
220
+ }
221
+
222
+ readBuffer(len) {
223
+ this.pos += len;
224
+ return this.buf.slice(this.pos - len, this.pos);
225
+ }
226
+
227
+ readBufferRemaining() {
228
+ let b = this.buf.slice(this.pos, this.end);
229
+ this.pos = this.end;
230
+ return b;
231
+ }
232
+
233
+ readBufferLengthEncoded() {
234
+ const len = this.readUnsignedLength();
235
+ if (len === null) return null;
236
+ this.pos += len;
237
+ return this.buf.slice(this.pos - len, this.pos);
238
+ }
239
+
240
+ readStringNullEnded() {
241
+ let initialPosition = this.pos;
242
+ let cnt = 0;
243
+ while (this.remaining() > 0 && this.buf[this.pos++] !== 0) {
244
+ cnt++;
245
+ }
246
+ return this.buf.toString('utf8', initialPosition, initialPosition + cnt);
247
+ }
248
+
249
+ readSignedLength() {
250
+ const type = this.buf[this.pos++];
251
+ switch (type) {
252
+ case 0xfb:
253
+ return null;
254
+ case 0xfc:
255
+ return this.readUInt16();
256
+ case 0xfd:
257
+ return this.readUInt24();
258
+ case 0xfe:
259
+ return Number(this.readInt64());
260
+ default:
261
+ return type;
262
+ }
263
+ }
264
+
265
+ readSignedLengthBigInt() {
266
+ const type = this.buf[this.pos++];
267
+ switch (type) {
268
+ case 0xfb:
269
+ return null;
270
+ case 0xfc:
271
+ return BigInt(this.readUInt16());
272
+ case 0xfd:
273
+ return BigInt(this.readUInt24());
274
+ case 0xfe:
275
+ return this.readInt64();
276
+ default:
277
+ return BigInt(type);
278
+ }
279
+ }
280
+
281
+ readAsciiStringLengthEncoded() {
282
+ const len = this.readUnsignedLength();
283
+ if (len === null) return null;
284
+ this.pos += len;
285
+ return this.buf.toString('ascii', this.pos - len, this.pos);
286
+ }
287
+
288
+ readStringLength() {
289
+ throw new Error(
290
+ 'code is normally superseded by Node encoder or Iconv depending on charset used'
291
+ );
292
+ }
293
+
294
+ readStringLengthEncoded(encoding) {
295
+ const len = this.readUnsignedLength();
296
+ if (len === null) return null;
297
+
298
+ this.pos += len;
299
+ if (Buffer.isEncoding(encoding)) {
300
+ return this.buf.toString(encoding, this.pos - len, this.pos);
301
+ }
302
+ return Iconv.decode(this.buf.slice(this.pos - len, this.pos), encoding);
303
+ }
304
+
305
+ readLongLengthEncoded(supportBigInt, supportBigNumbers, bigNumberStrings, unsigned) {
306
+ const len = this.readUnsignedLength();
307
+ if (len === null) return null;
308
+
309
+ if (supportBigInt) {
310
+ const str = this.buf.toString('ascii', this.pos, this.pos + len);
311
+ this.pos += len;
312
+ return BigInt(str);
313
+ }
314
+
315
+ let result = 0;
316
+ let negate = false;
317
+ let begin = this.pos;
318
+
319
+ //minus sign
320
+ if (len > 0 && this.buf[begin] === 45) {
321
+ negate = true;
322
+ begin++;
323
+ }
324
+ for (; begin < this.pos + len; begin++) {
325
+ result = result * 10 + (this.buf[begin] - 48);
326
+ }
327
+
328
+ let val = negate ? -1 * result : result;
329
+ this.pos += len;
330
+
331
+ if (!Number.isSafeInteger(val)) {
332
+ const str = this.buf.toString('ascii', this.pos - len, this.pos);
333
+ if (bigNumberStrings) return str;
334
+ if (supportBigNumbers) {
335
+ return Long.fromString(str, unsigned, 10);
336
+ }
337
+ }
338
+ return val;
339
+ }
340
+
341
+ readDecimalLengthEncoded(bigNumberStrings) {
342
+ const len = this.readUnsignedLength();
343
+ if (len === null) return null;
344
+
345
+ this.pos += len;
346
+ let str = this.buf.toString('ascii', this.pos - len, this.pos);
347
+ return bigNumberStrings ? str : +str;
348
+ }
349
+
350
+ readDate() {
351
+ const len = this.readUnsignedLength();
352
+ if (len === null) return null;
353
+
354
+ let res = [];
355
+ let value = 0;
356
+ let initPos = this.pos;
357
+ this.pos += len;
358
+ while (initPos < this.pos) {
359
+ const char = this.buf[initPos++];
360
+ if (char === 45) {
361
+ //minus separator
362
+ res.push(value);
363
+ value = 0;
364
+ } else {
365
+ value = value * 10 + char - 48;
366
+ }
367
+ }
368
+ res.push(value);
369
+
370
+ //handle zero-date as null
371
+ if (res[0] === 0 && res[1] === 0 && res[2] === 0) return null;
372
+
373
+ return new Date(res[0], res[1] - 1, res[2]);
374
+ }
375
+
376
+ readDateTime(opts) {
377
+ const len = this.readUnsignedLength();
378
+ if (len === null) return null;
379
+ this.pos += len;
380
+ const str = this.buf.toString('ascii', this.pos - len, this.pos);
381
+ if (str.startsWith('0000-00-00 00:00:00')) return null;
382
+
383
+ if (opts.tz) {
384
+ return new Date(
385
+ moment.tz(str, opts.tz).clone().tz(opts._localTz).format('YYYY-MM-DD HH:mm:ss.SSSSSS')
386
+ );
387
+ }
388
+ return new Date(str);
389
+ }
390
+
391
+ readIntLengthEncoded() {
392
+ const len = this.readUnsignedLength();
393
+ if (len === null) return null;
394
+
395
+ let result = 0;
396
+ let negate = false;
397
+ let begin = this.pos;
398
+
399
+ if (len > 0 && this.buf[begin] === 45) {
400
+ //minus sign
401
+ negate = true;
402
+ begin++;
403
+ }
404
+ for (; begin < this.pos + len; begin++) {
405
+ result = result * 10 + (this.buf[begin] - 48);
406
+ }
407
+ this.pos += len;
408
+ return negate ? -1 * result : result;
409
+ }
410
+
411
+ readFloatLengthCoded() {
412
+ const len = this.readUnsignedLength();
413
+ if (len === null) return null;
414
+ this.pos += len;
415
+ return +this.buf.toString('ascii', this.pos - len, this.pos);
416
+ }
417
+
418
+ skipLengthCodedNumber() {
419
+ const type = this.buf[this.pos++] & 0xff;
420
+ switch (type) {
421
+ case 251:
422
+ return;
423
+ case 252:
424
+ this.pos +=
425
+ 2 + (0xffff & ((this.buf[this.pos] & 0xff) + ((this.buf[this.pos + 1] & 0xff) << 8)));
426
+ return;
427
+ case 253:
428
+ this.pos +=
429
+ 3 +
430
+ (0xffffff &
431
+ ((this.buf[this.pos] & 0xff) +
432
+ ((this.buf[this.pos + 1] & 0xff) << 8) +
433
+ ((this.buf[this.pos + 2] & 0xff) << 16)));
434
+ return;
435
+ case 254:
436
+ this.pos +=
437
+ 8 +
438
+ ((this.buf[this.pos] & 0xff) +
439
+ ((this.buf[this.pos + 1] & 0xff) << 8) +
440
+ ((this.buf[this.pos + 2] & 0xff) << 16) +
441
+ ((this.buf[this.pos + 3] & 0xff) << 24) +
442
+ ((this.buf[this.pos + 4] & 0xff) << 32) +
443
+ ((this.buf[this.pos + 5] & 0xff) << 40) +
444
+ ((this.buf[this.pos + 6] & 0xff) << 48) +
445
+ ((this.buf[this.pos + 7] & 0xff) << 56));
446
+ return;
447
+ default:
448
+ this.pos += type;
449
+ return;
450
+ }
451
+ }
452
+
453
+ positionFromEnd(num) {
454
+ this.pos = this.end - num;
455
+ }
456
+
457
+ /**
458
+ * For testing purpose only
459
+ */
460
+ _toBuf() {
461
+ return this.buf.slice(this.pos, this.end);
462
+ }
463
+
464
+ forceOffset(off) {
465
+ this.pos = off;
466
+ }
467
+
468
+ length() {
469
+ return this.end - this.pos;
470
+ }
471
+
472
+ subPacketLengthEncoded() {
473
+ const len = this.readUnsignedLength();
474
+ this.skip(len);
475
+ return new Packet(this.buf, this.pos - len, this.pos);
476
+ }
477
+
478
+ /**
479
+ * Parse ERR_Packet : https://mariadb.com/kb/en/library/err_packet/
480
+ *
481
+ * @param info current connection info
482
+ * @param sql command sql
483
+ * @param stack additional stack trace
484
+ * @returns {Error}
485
+ */
486
+ readError(info, sql, stack) {
487
+ this.skip(1);
488
+ let errorCode = this.readUInt16();
489
+ let sqlState = '';
490
+
491
+ if (this.peek() === 0x23) {
492
+ this.skip(6);
493
+ sqlState = this.buf.toString('utf8', this.pos - 5, this.pos);
494
+ }
495
+
496
+ let msg = this.buf.toString('utf8', this.pos, this.end);
497
+ let fatal = sqlState.startsWith('08') || sqlState === '70100';
498
+ if (fatal) {
499
+ const packetMsgs = info.getLastPackets();
500
+ if (packetMsgs !== '')
501
+ return Errors.createError(
502
+ msg + '\nlast received packets:\n' + packetMsgs,
503
+ sql,
504
+ fatal,
505
+ info,
506
+ sqlState,
507
+ errorCode,
508
+ stack
509
+ );
510
+ }
511
+ return Errors.createError(msg, sql, fatal, info, sqlState, errorCode, stack);
512
+ }
513
+ }
514
+
515
+ module.exports = Packet;