dbgate-tools 7.1.6 → 7.1.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.
@@ -1,5 +1,6 @@
1
1
  import { DataEditorTypesBehaviour } from 'dbgate-types';
2
2
  export declare const MAX_GRID_TEXT_LENGTH = 1000;
3
+ export declare const MAX_GRID_BINARY_SIZE = 10000;
3
4
  export type EditorDataType = 'null' | 'objectid' | 'string' | 'number' | 'object' | 'date' | 'array' | 'boolean' | 'unknown';
4
5
  export declare function arrayToHexString(byteArray: any): any;
5
6
  export declare function hexStringToArray(inputString: any): any[];
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.shortenIdentifier = exports.setSqlFrontMatter = exports.removeSqlFrontMatter = exports.getSqlFrontMatter = exports.parseNumberSafe = exports.deserializeJsTypesReviver = exports.serializeJsTypesReplacer = exports.deserializeJsTypesFromJsonParse = exports.serializeJsTypesForJsonStringify = exports.jsonLinesParse = exports.jsonLinesStringify = exports.pinoLogRecordToMessageRecord = exports.getLimitedQuery = exports.safeFormatDate = exports.extractErrorLogData = exports.extractErrorStackTrace = exports.extractErrorMessage = exports.getConvertValueMenu = exports.detectTypeIcon = exports.detectCellDataType = exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.shouldOpenMultilineDialog = exports.safeCompileRegExp = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.uuidToBase64 = exports.hexToBase64 = exports.base64ToUuid = exports.base64ToHex = exports.hexStringToArray = exports.arrayToHexString = exports.MAX_GRID_TEXT_LENGTH = void 0;
6
+ exports.shortenIdentifier = exports.setSqlFrontMatter = exports.removeSqlFrontMatter = exports.getSqlFrontMatter = exports.parseNumberSafe = exports.deserializeJsTypesReviver = exports.serializeJsTypesReplacer = exports.deserializeJsTypesFromJsonParse = exports.serializeJsTypesForJsonStringify = exports.jsonLinesParse = exports.jsonLinesStringify = exports.pinoLogRecordToMessageRecord = exports.getLimitedQuery = exports.safeFormatDate = exports.extractErrorLogData = exports.extractErrorStackTrace = exports.extractErrorMessage = exports.getConvertValueMenu = exports.detectTypeIcon = exports.detectCellDataType = exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.shouldOpenMultilineDialog = exports.safeCompileRegExp = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.uuidToBase64 = exports.hexToBase64 = exports.base64ToUuid = exports.base64ToHex = exports.hexStringToArray = exports.arrayToHexString = exports.MAX_GRID_BINARY_SIZE = exports.MAX_GRID_TEXT_LENGTH = void 0;
7
7
  const isString_1 = __importDefault(require("lodash/isString"));
8
8
  const isArray_1 = __importDefault(require("lodash/isArray"));
9
9
  const isDate_1 = __importDefault(require("lodash/isDate"));
@@ -16,6 +16,14 @@ const omitBy_1 = __importDefault(require("lodash/omitBy"));
16
16
  const isPlainObject_2 = __importDefault(require("lodash/isPlainObject"));
17
17
  const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
18
18
  exports.MAX_GRID_TEXT_LENGTH = 1000; // maximum length of text in grid cell, longer text is truncated
19
+ exports.MAX_GRID_BINARY_SIZE = 10000; // maximum binary size (base64 chars or byte count) before showing 'too large' in grid cell
20
+ function formatByteSize(bytes) {
21
+ if (bytes >= 1024 * 1024)
22
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
23
+ if (bytes >= 1024)
24
+ return `${(bytes / 1024).toFixed(1)} KB`;
25
+ return `${bytes} B`;
26
+ }
19
27
  const dateTimeStorageRegex = /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
20
28
  const dateTimeParseRegex = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
21
29
  function arrayToHexString(byteArray) {
@@ -304,6 +312,9 @@ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, j
304
312
  return { value: `${tag}("${uuidStr}")`, gridStyle: 'valueCellStyle' };
305
313
  }
306
314
  }
315
+ if (intent === 'gridCellIntent' && value.$binary.base64.length > exports.MAX_GRID_BINARY_SIZE) {
316
+ return { value: `(Field too large, ${formatByteSize(Math.round(value.$binary.base64.length * 3 / 4))})`, gridStyle: 'nullCellStyle' };
317
+ }
307
318
  return {
308
319
  value: base64ToHex(value.$binary.base64),
309
320
  gridStyle: 'valueCellStyle',
@@ -385,6 +396,13 @@ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, j
385
396
  };
386
397
  }
387
398
  }
399
+ if ((value === null || value === void 0 ? void 0 : value.type) === 'Buffer' && (0, isArray_1.default)(value.data)) {
400
+ if (intent === 'gridCellIntent') {
401
+ return value.data.length > exports.MAX_GRID_BINARY_SIZE
402
+ ? { value: `(Field too large, ${formatByteSize(value.data.length)})`, gridStyle: 'nullCellStyle' }
403
+ : { value: '0x' + arrayToHexString(value.data), gridStyle: 'valueCellStyle' };
404
+ }
405
+ }
388
406
  if ((0, isArray_1.default)(value)) {
389
407
  switch (intent) {
390
408
  case 'gridCellIntent':
@@ -510,7 +528,7 @@ function shouldOpenMultilineDialog(value) {
510
528
  }
511
529
  exports.shouldOpenMultilineDialog = shouldOpenMultilineDialog;
512
530
  function isJsonLikeLongString(value) {
513
- return (0, isString_1.default)(value) && value.length > 100 && value.match(/^\s*\{.*\}\s*$|^\s*\[.*\]\s*$/m);
531
+ return (0, isString_1.default)(value) && value.length > 100 && value.length <= exports.MAX_GRID_BINARY_SIZE && value.match(/^\s*\{.*\}\s*$|^\s*\[.*\]\s*$/m);
514
532
  }
515
533
  exports.isJsonLikeLongString = isJsonLikeLongString;
516
534
  function getIconForRedisType(type) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.1.6",
2
+ "version": "7.1.8",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@types/node": "^13.7.0",
29
- "dbgate-types": "7.1.6",
29
+ "dbgate-types": "7.1.8",
30
30
  "jest": "^28.1.3",
31
31
  "ts-jest": "^28.0.7",
32
32
  "typescript": "^4.4.3"
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "blueimp-md5": "^2.19.0",
36
36
  "dbgate-query-splitter": "^4.12.0",
37
- "dbgate-sqltree": "7.1.6",
37
+ "dbgate-sqltree": "7.1.8",
38
38
  "debug": "^4.3.4",
39
39
  "json-stable-stringify": "^1.0.1",
40
40
  "lodash": "^4.17.21",