dbgate-tools 6.4.0 → 6.4.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.
package/lib/SqlDumper.js CHANGED
@@ -65,6 +65,8 @@ class SqlDumper {
65
65
  this.putStringValue(new Date(value).toISOString());
66
66
  else if ((value === null || value === void 0 ? void 0 : value.type) == 'Buffer' && (0, isArray_1.default)(value === null || value === void 0 ? void 0 : value.data))
67
67
  this.putByteArrayValue(value === null || value === void 0 ? void 0 : value.data);
68
+ else if (value === null || value === void 0 ? void 0 : value.$bigint)
69
+ this.putRaw(value === null || value === void 0 ? void 0 : value.$bigint);
68
70
  else if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value))
69
71
  this.putStringValue(JSON.stringify(value));
70
72
  else
@@ -1,35 +1,60 @@
1
+ export declare const DB_KEYS_SHOW_INCREMENT = 100;
1
2
  export interface DbKeysNodeModelBase {
2
3
  text?: string;
4
+ sortKey: string;
5
+ key: string;
3
6
  count?: number;
4
7
  level: number;
8
+ keyPath: string[];
9
+ parentKey: string;
5
10
  }
6
11
  export interface DbKeysLeafNodeModel extends DbKeysNodeModelBase {
7
- key: string;
8
12
  type: 'string' | 'hash' | 'set' | 'list' | 'zset' | 'stream' | 'binary' | 'ReJSON-RL';
9
13
  }
10
14
  export interface DbKeysFolderNodeModel extends DbKeysNodeModelBase {
11
- root: string;
12
15
  type: 'dir';
13
- maxShowCount?: number;
16
+ }
17
+ export interface DbKeysFolderStateMode {
18
+ key: string;
19
+ visibleCount?: number;
14
20
  isExpanded?: boolean;
15
- shouldLoadNext?: boolean;
16
- hasNext?: boolean;
17
21
  }
18
22
  export interface DbKeysTreeModel {
23
+ treeKeySeparator: string;
19
24
  root: DbKeysFolderNodeModel;
20
25
  dirsByKey: {
21
26
  [key: string]: DbKeysFolderNodeModel;
22
27
  };
28
+ dirStateByKey: {
29
+ [key: string]: DbKeysFolderStateMode;
30
+ };
23
31
  childrenByKey: {
24
32
  [key: string]: DbKeysNodeModel[];
25
33
  };
26
- refreshAll?: boolean;
34
+ keyObjectsByKey: {
35
+ [key: string]: DbKeysNodeModel;
36
+ };
37
+ scannedKeys: number;
38
+ loadCount: number;
39
+ dbsize: number;
40
+ cursor: string;
41
+ loadedAll: boolean;
27
42
  }
28
43
  export type DbKeysNodeModel = DbKeysLeafNodeModel | DbKeysFolderNodeModel;
29
- export type DbKeysLoadFunction = (root: string, limit: number) => Promise<DbKeysNodeModel[]>;
30
- export type DbKeysChangeModelFunction = (func: (model: DbKeysTreeModel) => DbKeysTreeModel) => void;
31
- export declare function dbKeys_loadMissing(tree: DbKeysTreeModel, loader: DbKeysLoadFunction): Promise<DbKeysTreeModel>;
44
+ export interface DbKeyLoadedModel {
45
+ key: string;
46
+ type: 'string' | 'hash' | 'set' | 'list' | 'zset' | 'stream' | 'binary' | 'ReJSON-RL';
47
+ count?: number;
48
+ }
49
+ export interface DbKeysLoadResult {
50
+ nextCursor: string;
51
+ keys: DbKeyLoadedModel[];
52
+ dbsize: number;
53
+ }
54
+ export type DbKeysChangeModelFunction = (func: (model: DbKeysTreeModel) => DbKeysTreeModel, loadNextPage: boolean) => void;
55
+ export declare function dbKeys_mergeNextPage(tree: DbKeysTreeModel, nextPage: DbKeysLoadResult): DbKeysTreeModel;
32
56
  export declare function dbKeys_markNodeExpanded(tree: DbKeysTreeModel, root: string, isExpanded: boolean): DbKeysTreeModel;
33
- export declare function dbKeys_refreshAll(tree?: DbKeysTreeModel): DbKeysTreeModel;
34
- export declare function dbKeys_reloadFolder(tree: DbKeysTreeModel, root: string): DbKeysTreeModel;
57
+ export declare function dbKeys_showNextItems(tree: DbKeysTreeModel, root: string): DbKeysTreeModel;
58
+ export declare function dbKeys_createNewModel(treeKeySeparator: string): DbKeysTreeModel;
59
+ export declare function dbKeys_clearLoadedData(tree: DbKeysTreeModel): DbKeysTreeModel;
35
60
  export declare function dbKeys_getFlatList(tree: DbKeysTreeModel): DbKeysNodeModel[];
@@ -1,20 +1,11 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.dbKeys_getFlatList = exports.dbKeys_reloadFolder = exports.dbKeys_refreshAll = exports.dbKeys_markNodeExpanded = exports.dbKeys_loadMissing = void 0;
16
- const omit_1 = __importDefault(require("lodash/omit"));
17
- const SHOW_INCREMENT = 100;
6
+ exports.dbKeys_getFlatList = exports.dbKeys_clearLoadedData = exports.dbKeys_createNewModel = exports.dbKeys_showNextItems = exports.dbKeys_markNodeExpanded = exports.dbKeys_mergeNextPage = exports.DB_KEYS_SHOW_INCREMENT = void 0;
7
+ const sortBy_1 = __importDefault(require("lodash/sortBy"));
8
+ exports.DB_KEYS_SHOW_INCREMENT = 100;
18
9
  // function dbKeys_findFolderNode(node: DbKeysNodeModel, root: string) {
19
10
  // if (node.type != 'dir') {
20
11
  // return null;
@@ -49,78 +40,181 @@ const SHOW_INCREMENT = 100;
49
40
  // },
50
41
  // };
51
42
  // }
52
- function dbKeys_loadMissing(tree, loader) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const childrenByKey = Object.assign({}, tree.childrenByKey);
55
- const dirsByKey = Object.assign({}, tree.dirsByKey);
56
- for (const root in tree.dirsByKey) {
57
- const dir = tree.dirsByKey[root];
58
- if (dir.isExpanded && dir.shouldLoadNext) {
59
- if (!tree.childrenByKey[root] || dir.hasNext) {
60
- const loadCount = dir.maxShowCount && dir.shouldLoadNext ? dir.maxShowCount + SHOW_INCREMENT : SHOW_INCREMENT;
61
- const items = yield loader(root, loadCount + 1);
62
- childrenByKey[root] = items.slice(0, loadCount);
63
- dirsByKey[root] = Object.assign(Object.assign({}, dir), { shouldLoadNext: false, maxShowCount: loadCount, hasNext: items.length > loadCount });
64
- for (const child of items.slice(0, loadCount)) {
65
- if (child.type == 'dir' && !dirsByKey[child.root]) {
66
- dirsByKey[child.root] = {
67
- shouldLoadNext: false,
68
- maxShowCount: null,
69
- hasNext: false,
70
- isExpanded: false,
71
- type: 'dir',
72
- level: dir.level + 1,
73
- root: child.root,
74
- text: child.text,
75
- };
76
- }
77
- }
78
- }
79
- else {
80
- dirsByKey[root] = Object.assign(Object.assign({}, dir), { shouldLoadNext: false });
81
- }
43
+ // export async function dbKeys_loadMissing(tree: DbKeysTreeModel, loader: DbKeysLoadFunction): Promise<DbKeysTreeModel> {
44
+ // const childrenByKey = { ...tree.childrenByKey };
45
+ // const dirsByKey = { ...tree.dirsByKey };
46
+ // for (const root in tree.dirsByKey) {
47
+ // const dir = tree.dirsByKey[root];
48
+ // if (dir.isExpanded && dir.shouldLoadNext) {
49
+ // if (!tree.childrenByKey[root] || dir.hasNext) {
50
+ // const loadCount = dir.maxShowCount && dir.shouldLoadNext ? dir.maxShowCount + SHOW_INCREMENT : SHOW_INCREMENT;
51
+ // const items = await loader(root, loadCount + 1);
52
+ // childrenByKey[root] = items.slice(0, loadCount);
53
+ // dirsByKey[root] = {
54
+ // ...dir,
55
+ // shouldLoadNext: false,
56
+ // maxShowCount: loadCount,
57
+ // hasNext: items.length > loadCount,
58
+ // };
59
+ // for (const child of items.slice(0, loadCount)) {
60
+ // if (child.type == 'dir' && !dirsByKey[child.root]) {
61
+ // dirsByKey[child.root] = {
62
+ // shouldLoadNext: false,
63
+ // maxShowCount: null,
64
+ // hasNext: false,
65
+ // isExpanded: false,
66
+ // type: 'dir',
67
+ // level: dir.level + 1,
68
+ // root: child.root,
69
+ // text: child.text,
70
+ // };
71
+ // }
72
+ // }
73
+ // } else {
74
+ // dirsByKey[root] = {
75
+ // ...dir,
76
+ // shouldLoadNext: false,
77
+ // };
78
+ // }
79
+ // }
80
+ // }
81
+ // return {
82
+ // ...tree,
83
+ // dirsByKey,
84
+ // childrenByKey,
85
+ // refreshAll: false,
86
+ // };
87
+ // }
88
+ function dbKeys_mergeNextPage(tree, nextPage) {
89
+ const keyObjectsByKey = Object.assign({}, tree.keyObjectsByKey);
90
+ for (const keyObj of nextPage.keys) {
91
+ const keyPath = keyObj.key.split(tree.treeKeySeparator);
92
+ keyObjectsByKey[keyObj.key] = Object.assign(Object.assign({}, keyObj), { level: keyPath.length, text: keyPath[keyPath.length - 1], sortKey: keyPath[keyPath.length - 1], keyPath, parentKey: keyPath.slice(0, -1).join(tree.treeKeySeparator) });
93
+ }
94
+ const dirsByKey = {};
95
+ const childrenByKey = {};
96
+ dirsByKey[''] = tree.root;
97
+ for (const keyObj of Object.values(keyObjectsByKey)) {
98
+ const dirPath = keyObj.keyPath.slice(0, -1);
99
+ const dirKey = dirPath.join(tree.treeKeySeparator);
100
+ let dirDepth = keyObj.keyPath.length - 1;
101
+ while (dirDepth > 0) {
102
+ const newDirPath = keyObj.keyPath.slice(0, dirDepth);
103
+ const newDirKey = newDirPath.join(tree.treeKeySeparator);
104
+ if (!dirsByKey[newDirKey]) {
105
+ dirsByKey[newDirKey] = {
106
+ level: keyObj.level - 1,
107
+ keyPath: newDirPath,
108
+ parentKey: newDirPath.slice(0, -1).join(tree.treeKeySeparator),
109
+ type: 'dir',
110
+ key: newDirKey,
111
+ text: `${newDirPath[newDirPath.length - 1]}${tree.treeKeySeparator}*`,
112
+ sortKey: newDirPath[newDirPath.length - 1],
113
+ };
82
114
  }
115
+ dirDepth -= 1;
116
+ }
117
+ if (!childrenByKey[dirKey]) {
118
+ childrenByKey[dirKey] = [];
119
+ }
120
+ childrenByKey[dirKey].push(keyObj);
121
+ }
122
+ for (const dirObj of Object.values(dirsByKey)) {
123
+ if (dirObj.key == '') {
124
+ continue;
125
+ }
126
+ if (!childrenByKey[dirObj.parentKey]) {
127
+ childrenByKey[dirObj.parentKey] = [];
83
128
  }
84
- return Object.assign(Object.assign({}, tree), { dirsByKey,
85
- childrenByKey, refreshAll: false });
86
- });
129
+ childrenByKey[dirObj.parentKey].push(dirObj);
130
+ // set key count
131
+ dirsByKey[dirObj.key].count = childrenByKey[dirObj.key].length;
132
+ }
133
+ for (const key in childrenByKey) {
134
+ childrenByKey[key] = (0, sortBy_1.default)(childrenByKey[key], 'sortKey');
135
+ }
136
+ return Object.assign(Object.assign({}, tree), { cursor: nextPage.nextCursor, dirsByKey,
137
+ childrenByKey,
138
+ keyObjectsByKey, scannedKeys: tree.scannedKeys + tree.loadCount, loadedAll: nextPage.nextCursor == '0', dbsize: nextPage.dbsize });
87
139
  }
88
- exports.dbKeys_loadMissing = dbKeys_loadMissing;
140
+ exports.dbKeys_mergeNextPage = dbKeys_mergeNextPage;
89
141
  function dbKeys_markNodeExpanded(tree, root, isExpanded) {
90
- const node = tree.dirsByKey[root];
91
- if (!node) {
92
- return tree;
93
- }
94
- return Object.assign(Object.assign({}, tree), { dirsByKey: Object.assign(Object.assign({}, tree.dirsByKey), { [root]: Object.assign(Object.assign({}, node), { isExpanded, shouldLoadNext: isExpanded }) }) });
142
+ const node = tree.dirStateByKey[root];
143
+ return Object.assign(Object.assign({}, tree), { dirStateByKey: Object.assign(Object.assign({}, tree.dirStateByKey), { [root]: Object.assign(Object.assign({}, node), { isExpanded }) }) });
95
144
  }
96
145
  exports.dbKeys_markNodeExpanded = dbKeys_markNodeExpanded;
97
- function dbKeys_refreshAll(tree) {
146
+ function dbKeys_showNextItems(tree, root) {
147
+ var _a;
148
+ const node = tree.dirStateByKey[root];
149
+ return Object.assign(Object.assign({}, tree), { dirStateByKey: Object.assign(Object.assign({}, tree.dirStateByKey), { [root]: Object.assign(Object.assign({}, node), { visibleCount: ((_a = node === null || node === void 0 ? void 0 : node.visibleCount) !== null && _a !== void 0 ? _a : exports.DB_KEYS_SHOW_INCREMENT) + exports.DB_KEYS_SHOW_INCREMENT }) }) });
150
+ }
151
+ exports.dbKeys_showNextItems = dbKeys_showNextItems;
152
+ function dbKeys_createNewModel(treeKeySeparator) {
98
153
  const root = {
99
- isExpanded: true,
100
154
  level: 0,
101
- root: '',
102
155
  type: 'dir',
103
- shouldLoadNext: true,
156
+ keyPath: [],
157
+ parentKey: '',
158
+ key: '',
159
+ sortKey: '',
104
160
  };
105
- return Object.assign(Object.assign({}, tree), { childrenByKey: {}, dirsByKey: {
161
+ return {
162
+ treeKeySeparator,
163
+ childrenByKey: {},
164
+ keyObjectsByKey: {},
165
+ dirsByKey: {
106
166
  '': root,
107
- }, refreshAll: true, root });
167
+ },
168
+ dirStateByKey: {
169
+ '': {
170
+ key: '',
171
+ visibleCount: exports.DB_KEYS_SHOW_INCREMENT,
172
+ isExpanded: true,
173
+ },
174
+ },
175
+ scannedKeys: 0,
176
+ dbsize: 0,
177
+ loadCount: 2000,
178
+ cursor: '0',
179
+ root,
180
+ loadedAll: false,
181
+ };
108
182
  }
109
- exports.dbKeys_refreshAll = dbKeys_refreshAll;
110
- function dbKeys_reloadFolder(tree, root) {
111
- return Object.assign(Object.assign({}, tree), { childrenByKey: (0, omit_1.default)(tree.childrenByKey, root), dirsByKey: Object.assign(Object.assign({}, tree.dirsByKey), { [root]: Object.assign(Object.assign({}, tree.dirsByKey[root]), { shouldLoadNext: true, hasNext: undefined }) }) });
183
+ exports.dbKeys_createNewModel = dbKeys_createNewModel;
184
+ function dbKeys_clearLoadedData(tree) {
185
+ return Object.assign(Object.assign({}, tree), { childrenByKey: {}, keyObjectsByKey: {}, dirsByKey: {
186
+ '': tree.root,
187
+ }, scannedKeys: 0, dbsize: 0, cursor: '0', loadedAll: false });
112
188
  }
113
- exports.dbKeys_reloadFolder = dbKeys_reloadFolder;
114
- function addFlatItems(tree, root, res) {
115
- const item = tree.dirsByKey[root];
116
- if (!item.isExpanded) {
189
+ exports.dbKeys_clearLoadedData = dbKeys_clearLoadedData;
190
+ // export function dbKeys_reloadFolder(tree: DbKeysTreeModel, root: string): DbKeysTreeModel {
191
+ // return {
192
+ // ...tree,
193
+ // childrenByKey: _omit(tree.childrenByKey, root),
194
+ // dirsByKey: {
195
+ // ...tree.dirsByKey,
196
+ // [root]: {
197
+ // ...tree.dirsByKey[root],
198
+ // shouldLoadNext: true,
199
+ // hasNext: undefined,
200
+ // },
201
+ // },
202
+ // };
203
+ // }
204
+ function addFlatItems(tree, root, res, visitedRoots = []) {
205
+ const item = tree.dirStateByKey[root];
206
+ if (!(item === null || item === void 0 ? void 0 : item.isExpanded)) {
117
207
  return false;
118
208
  }
119
209
  const children = tree.childrenByKey[root] || [];
120
210
  for (const child of children) {
121
211
  res.push(child);
122
212
  if (child.type == 'dir') {
123
- addFlatItems(tree, child.root, res);
213
+ if (visitedRoots.includes(child.key)) {
214
+ console.warn('Redis: preventing infinite loop for root', child.key);
215
+ return false;
216
+ }
217
+ addFlatItems(tree, child.key, res, [...visitedRoots, root]);
124
218
  }
125
219
  }
126
220
  }
@@ -37,3 +37,8 @@ export declare function getLimitedQuery(sql: string): string;
37
37
  export declare function pinoLogRecordToMessageRecord(logRecord: any, defaultSeverity?: string): any;
38
38
  export declare function jsonLinesStringify(jsonArray: any[]): string;
39
39
  export declare function jsonLinesParse(jsonLines: string): any[];
40
+ export declare function serializeJsTypesForJsonStringify(obj: any, replacer?: any): any;
41
+ export declare function deserializeJsTypesFromJsonParse(obj: any): any;
42
+ export declare function serializeJsTypesReplacer(key: any, value: any): any;
43
+ export declare function deserializeJsTypesReviver(key: any, value: any): any;
44
+ export declare function parseNumberSafe(value: any): number | bigint;
@@ -14,13 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- 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.hexStringToArray = exports.arrayToHexString = void 0;
17
+ 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.hexStringToArray = exports.arrayToHexString = void 0;
18
18
  const isString_1 = __importDefault(require("lodash/isString"));
19
19
  const isArray_1 = __importDefault(require("lodash/isArray"));
20
20
  const isDate_1 = __importDefault(require("lodash/isDate"));
21
21
  const isNumber_1 = __importDefault(require("lodash/isNumber"));
22
22
  const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
23
23
  const pad_1 = __importDefault(require("lodash/pad"));
24
+ const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
24
25
  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]))$/;
25
26
  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]))$/;
26
27
  function arrayToHexString(byteArray) {
@@ -78,7 +79,7 @@ function parseCellValue(value, editorTypes) {
78
79
  }
79
80
  if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseNumber) {
80
81
  if (/^-?[0-9]+(?:\.[0-9]+)?$/.test(value)) {
81
- return parseFloat(value);
82
+ return parseNumberSafe(value);
82
83
  }
83
84
  }
84
85
  if ((editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonArray) || (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonObject)) {
@@ -189,6 +190,18 @@ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, j
189
190
  }
190
191
  }
191
192
  }
193
+ if (value === null || value === void 0 ? void 0 : value.$bigint) {
194
+ return {
195
+ value: value.$bigint,
196
+ gridStyle: 'valueCellStyle',
197
+ };
198
+ }
199
+ if (typeof value === 'bigint') {
200
+ return {
201
+ value: value.toString(),
202
+ gridStyle: 'valueCellStyle',
203
+ };
204
+ }
192
205
  if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseDateAsDollar) {
193
206
  if (value === null || value === void 0 ? void 0 : value.$date) {
194
207
  const dateString = (0, isDate_1.default)(value.$date) ? value.$date.toISOString() : value.$date.toString();
@@ -320,6 +333,9 @@ function shouldOpenMultilineDialog(value) {
320
333
  if (value === null || value === void 0 ? void 0 : value.$date) {
321
334
  return false;
322
335
  }
336
+ if (value === null || value === void 0 ? void 0 : value.$bigint) {
337
+ return false;
338
+ }
323
339
  if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value)) {
324
340
  return true;
325
341
  }
@@ -553,3 +569,47 @@ function jsonLinesParse(jsonLines) {
553
569
  .filter(x => x);
554
570
  }
555
571
  exports.jsonLinesParse = jsonLinesParse;
572
+ function serializeJsTypesForJsonStringify(obj, replacer = null) {
573
+ return (0, cloneDeepWith_1.default)(obj, value => {
574
+ if (typeof value === 'bigint') {
575
+ return { $bigint: value.toString() };
576
+ }
577
+ if (replacer) {
578
+ return replacer(value);
579
+ }
580
+ });
581
+ }
582
+ exports.serializeJsTypesForJsonStringify = serializeJsTypesForJsonStringify;
583
+ function deserializeJsTypesFromJsonParse(obj) {
584
+ return (0, cloneDeepWith_1.default)(obj, value => {
585
+ if (value === null || value === void 0 ? void 0 : value.$bigint) {
586
+ return BigInt(value.$bigint);
587
+ }
588
+ });
589
+ }
590
+ exports.deserializeJsTypesFromJsonParse = deserializeJsTypesFromJsonParse;
591
+ function serializeJsTypesReplacer(key, value) {
592
+ if (typeof value === 'bigint') {
593
+ return { $bigint: value.toString() };
594
+ }
595
+ return value;
596
+ }
597
+ exports.serializeJsTypesReplacer = serializeJsTypesReplacer;
598
+ function deserializeJsTypesReviver(key, value) {
599
+ if (value === null || value === void 0 ? void 0 : value.$bigint) {
600
+ return BigInt(value.$bigint);
601
+ }
602
+ return value;
603
+ }
604
+ exports.deserializeJsTypesReviver = deserializeJsTypesReviver;
605
+ function parseNumberSafe(value) {
606
+ if (/^-?[0-9]+$/.test(value)) {
607
+ const parsed = parseInt(value);
608
+ if (Number.isSafeInteger(parsed)) {
609
+ return parsed;
610
+ }
611
+ return BigInt(value);
612
+ }
613
+ return parseFloat(value);
614
+ }
615
+ exports.parseNumberSafe = parseNumberSafe;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.4.0",
2
+ "version": "6.4.2",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -26,14 +26,14 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@types/node": "^13.7.0",
29
- "dbgate-types": "^6.4.0",
29
+ "dbgate-types": "^6.4.2",
30
30
  "jest": "^28.1.3",
31
31
  "ts-jest": "^28.0.7",
32
32
  "typescript": "^4.4.3"
33
33
  },
34
34
  "dependencies": {
35
- "dbgate-query-splitter": "^4.11.4",
36
- "dbgate-sqltree": "^6.4.0",
35
+ "dbgate-query-splitter": "^4.11.5",
36
+ "dbgate-sqltree": "^6.4.2",
37
37
  "debug": "^4.3.4",
38
38
  "json-stable-stringify": "^1.0.1",
39
39
  "lodash": "^4.17.21",