dbgate-tools 7.1.4 → 7.1.5
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/lib/stringTools.d.ts +2 -0
- package/lib/stringTools.js +67 -1
- package/package.json +3 -3
package/lib/stringTools.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export type EditorDataType = 'null' | 'objectid' | 'string' | 'number' | 'object
|
|
|
4
4
|
export declare function arrayToHexString(byteArray: any): any;
|
|
5
5
|
export declare function hexStringToArray(inputString: any): any[];
|
|
6
6
|
export declare function base64ToHex(base64String: any): string;
|
|
7
|
+
export declare function base64ToUuid(base64String: any): string | null;
|
|
7
8
|
export declare function hexToBase64(hexString: any): string;
|
|
9
|
+
export declare function uuidToBase64(uuid: string): string | null;
|
|
8
10
|
export declare function parseCellValue(value: any, editorTypes?: DataEditorTypesBehaviour): any;
|
|
9
11
|
export declare function stringifyCellValue(value: any, intent: 'gridCellIntent' | 'inlineEditorIntent' | 'multilineEditorIntent' | 'stringConversionIntent' | 'exportIntent' | 'clipboardIntent', editorTypes?: DataEditorTypesBehaviour, gridFormattingOptions?: {
|
|
10
12
|
thousandsSeparator?: string;
|
package/lib/stringTools.js
CHANGED
|
@@ -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.hexToBase64 = 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_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"));
|
|
@@ -37,6 +37,27 @@ function base64ToHex(base64String) {
|
|
|
37
37
|
return '0x' + hexString.toUpperCase();
|
|
38
38
|
}
|
|
39
39
|
exports.base64ToHex = base64ToHex;
|
|
40
|
+
function base64ToUuid(base64String) {
|
|
41
|
+
let binaryString;
|
|
42
|
+
try {
|
|
43
|
+
binaryString = atob(base64String);
|
|
44
|
+
}
|
|
45
|
+
catch (_a) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (binaryString.length !== 16) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const hex = Array.from(binaryString, c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('');
|
|
52
|
+
return [
|
|
53
|
+
hex.slice(0, 8),
|
|
54
|
+
hex.slice(8, 12),
|
|
55
|
+
hex.slice(12, 16),
|
|
56
|
+
hex.slice(16, 20),
|
|
57
|
+
hex.slice(20, 32),
|
|
58
|
+
].join('-');
|
|
59
|
+
}
|
|
60
|
+
exports.base64ToUuid = base64ToUuid;
|
|
40
61
|
function hexToBase64(hexString) {
|
|
41
62
|
const binaryString = hexString
|
|
42
63
|
.match(/.{1,2}/g)
|
|
@@ -45,6 +66,22 @@ function hexToBase64(hexString) {
|
|
|
45
66
|
return btoa(binaryString);
|
|
46
67
|
}
|
|
47
68
|
exports.hexToBase64 = hexToBase64;
|
|
69
|
+
const uuidPattern = '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}';
|
|
70
|
+
const uuidRegex = new RegExp(`^${uuidPattern}$`);
|
|
71
|
+
const uuid3WrapperRegex = new RegExp(`^UUID3\\("(${uuidPattern})"\\)$`);
|
|
72
|
+
const uuid4WrapperRegex = new RegExp(`^UUID\\("(${uuidPattern})"\\)$`);
|
|
73
|
+
function uuidToBase64(uuid) {
|
|
74
|
+
if (!uuid || !uuidRegex.test(uuid)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const hex = uuid.replace(/-/g, '');
|
|
78
|
+
const binaryString = hex
|
|
79
|
+
.match(/.{1,2}/g)
|
|
80
|
+
.map(byte => String.fromCharCode(parseInt(byte, 16)))
|
|
81
|
+
.join('');
|
|
82
|
+
return btoa(binaryString);
|
|
83
|
+
}
|
|
84
|
+
exports.uuidToBase64 = uuidToBase64;
|
|
48
85
|
function parseCellValue(value, editorTypes) {
|
|
49
86
|
if (!(0, isString_1.default)(value))
|
|
50
87
|
return value;
|
|
@@ -53,6 +90,23 @@ function parseCellValue(value, editorTypes) {
|
|
|
53
90
|
return null;
|
|
54
91
|
}
|
|
55
92
|
if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseHexAsBuffer) {
|
|
93
|
+
const mUuid3 = value.match(uuid3WrapperRegex);
|
|
94
|
+
if (mUuid3) {
|
|
95
|
+
const base64Uuid3 = uuidToBase64(mUuid3[1]);
|
|
96
|
+
if (base64Uuid3 != null)
|
|
97
|
+
return { $binary: { base64: base64Uuid3, subType: '03' } };
|
|
98
|
+
}
|
|
99
|
+
const mUuid4 = value.match(uuid4WrapperRegex);
|
|
100
|
+
if (mUuid4) {
|
|
101
|
+
const base64Uuid4 = uuidToBase64(mUuid4[1]);
|
|
102
|
+
if (base64Uuid4 != null)
|
|
103
|
+
return { $binary: { base64: base64Uuid4, subType: '04' } };
|
|
104
|
+
}
|
|
105
|
+
if (uuidRegex.test(value)) {
|
|
106
|
+
const base64UuidPlain = uuidToBase64(value);
|
|
107
|
+
if (base64UuidPlain != null)
|
|
108
|
+
return { $binary: { base64: base64UuidPlain, subType: '04' } };
|
|
109
|
+
}
|
|
56
110
|
const mHex = value.match(/^0x([0-9a-fA-F][0-9a-fA-F])+$/);
|
|
57
111
|
if (mHex) {
|
|
58
112
|
return {
|
|
@@ -238,6 +292,18 @@ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, j
|
|
|
238
292
|
if (value === false)
|
|
239
293
|
return { value: 'false', gridStyle: 'valueCellStyle' };
|
|
240
294
|
if ((_a = value === null || value === void 0 ? void 0 : value.$binary) === null || _a === void 0 ? void 0 : _a.base64) {
|
|
295
|
+
const subType = value.$binary.subType;
|
|
296
|
+
if (subType === '03' || subType === '04') {
|
|
297
|
+
const uuidStr = base64ToUuid(value.$binary.base64);
|
|
298
|
+
if (uuidStr != null) {
|
|
299
|
+
if (intent === 'gridCellIntent' || intent === 'exportIntent' || intent === 'clipboardIntent' || intent === 'stringConversionIntent') {
|
|
300
|
+
return { value: uuidStr, gridStyle: 'valueCellStyle' };
|
|
301
|
+
}
|
|
302
|
+
// For editing intents: tag with subType so parseCellValue can round-trip it
|
|
303
|
+
const tag = subType === '03' ? 'UUID3' : 'UUID';
|
|
304
|
+
return { value: `${tag}("${uuidStr}")`, gridStyle: 'valueCellStyle' };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
241
307
|
return {
|
|
242
308
|
value: base64ToHex(value.$binary.base64),
|
|
243
309
|
gridStyle: 'valueCellStyle',
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "7.1.
|
|
2
|
+
"version": "7.1.5",
|
|
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.
|
|
29
|
+
"dbgate-types": "7.1.5",
|
|
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.
|
|
37
|
+
"dbgate-sqltree": "7.1.5",
|
|
38
38
|
"debug": "^4.3.4",
|
|
39
39
|
"json-stable-stringify": "^1.0.1",
|
|
40
40
|
"lodash": "^4.17.21",
|