bigint support #1087

This commit is contained in:
SPRINX0\prochazka
2025-05-05 16:04:21 +02:00
parent 23db345756
commit 110d87e512
11 changed files with 93 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import _isDate from 'lodash/isDate';
import _isNumber from 'lodash/isNumber';
import _isPlainObject from 'lodash/isPlainObject';
import _pad from 'lodash/pad';
import _cloneDeepWith from 'lodash/cloneDeepWith';
import { DataEditorTypesBehaviour } from 'dbgate-types';
export type EditorDataType =
@@ -208,6 +209,12 @@ export function stringifyCellValue(
}
}
}
if (value?.$bigint) {
return {
value: value.$bigint,
gridStyle: 'valueCellStyle',
};
}
if (editorTypes?.parseDateAsDollar) {
if (value?.$date) {
@@ -343,6 +350,9 @@ export function shouldOpenMultilineDialog(value) {
if (value?.$date) {
return false;
}
if (value?.$bigint) {
return false;
}
if (_isPlainObject(value) || _isArray(value)) {
return true;
}
@@ -573,3 +583,44 @@ export function jsonLinesParse(jsonLines: string): any[] {
})
.filter(x => x);
}
export function serializeJsTypesForJsonStringify(obj) {
return _cloneDeepWith(obj, value => {
if (typeof value === 'bigint') {
return { $bigint: value.toString() };
}
});
}
export function deserializeJsTypesFromJsonParse(obj) {
return _cloneDeepWith(obj, value => {
if (value?.$bigint) {
return BigInt(value.$bigint);
}
});
}
export function serializeJsTypesReplacer(key, value) {
if (typeof value === 'bigint') {
return { $bigint: value.toString() };
}
return value;
}
export function deserializeJsTypesReviver(key, value) {
if (value?.$bigint) {
return BigInt(value.$bigint);
}
return value;
}
export function parseNumberSafe(value) {
if (/^-?[0-9]+$/.test(value)) {
const parsed = parseInt(value);
if (Number.isSafeInteger(parsed)) {
return parsed;
}
return BigInt(value);
}
return parseFloat(value);
}