dbgate-datalib 4.4.0 → 4.4.4
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/ChangeSet.d.ts +1 -0
- package/lib/ChangeSet.js +11 -3
- package/lib/CollectionGridDisplay.d.ts +1 -1
- package/lib/CollectionGridDisplay.js +11 -2
- package/lib/FreeTableGridDisplay.js +10 -2
- package/lib/GridDisplay.d.ts +5 -1
- package/lib/GridDisplay.js +19 -9
- package/lib/JslGridDisplay.js +6 -2
- package/lib/ViewGridDisplay.js +2 -1
- package/package.json +4 -4
package/lib/ChangeSet.d.ts
CHANGED
|
@@ -40,4 +40,5 @@ export declare function revertChangeSetRowChanges(changeSet: ChangeSet, definiti
|
|
|
40
40
|
export declare function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
|
|
41
41
|
export declare function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo): any[];
|
|
42
42
|
export declare function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet;
|
|
43
|
+
export declare function changeSetInsertDocuments(changeSet: ChangeSet, documents: any[], name?: NamedObjectInfo): ChangeSet;
|
|
43
44
|
export declare function changeSetContainsChanges(changeSet: ChangeSet): boolean;
|
package/lib/ChangeSet.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.changeSetContainsChanges = exports.changeSetInsertNewRow = exports.getChangeSetInsertedRows = exports.deleteChangeSetRows = exports.revertChangeSetRowChanges = exports.changeSetToSql = exports.extractChangeSetCondition = exports.batchUpdateChangeSet = exports.setChangeSetRowData = exports.setChangeSetValue = exports.findExistingChangeSetItem = exports.createChangeSet = void 0;
|
|
6
|
+
exports.changeSetContainsChanges = exports.changeSetInsertDocuments = exports.changeSetInsertNewRow = exports.getChangeSetInsertedRows = exports.deleteChangeSetRows = exports.revertChangeSetRowChanges = exports.changeSetToSql = exports.extractChangeSetCondition = exports.batchUpdateChangeSet = exports.setChangeSetRowData = exports.setChangeSetValue = exports.findExistingChangeSetItem = exports.createChangeSet = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
function createChangeSet() {
|
|
9
9
|
return {
|
|
@@ -150,7 +150,7 @@ function changeSetInsertToSql(item, dbinfo = null) {
|
|
|
150
150
|
const table = dbinfo.tables.find(x => x.schemaName == item.schemaName && x.pureName == item.pureName);
|
|
151
151
|
if (table) {
|
|
152
152
|
const autoIncCol = table.columns.find(x => x.autoIncrement);
|
|
153
|
-
console.log('autoIncCol', autoIncCol);
|
|
153
|
+
// console.log('autoIncCol', autoIncCol);
|
|
154
154
|
if (autoIncCol && fields.find(x => x.targetColumn == autoIncCol.columnName)) {
|
|
155
155
|
autoInc = true;
|
|
156
156
|
}
|
|
@@ -292,7 +292,7 @@ function getChangeSetInsertedRows(changeSet, name) {
|
|
|
292
292
|
}
|
|
293
293
|
exports.getChangeSetInsertedRows = getChangeSetInsertedRows;
|
|
294
294
|
function changeSetInsertNewRow(changeSet, name) {
|
|
295
|
-
console.log('INSERT', name);
|
|
295
|
+
// console.log('INSERT', name);
|
|
296
296
|
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
|
297
297
|
return Object.assign(Object.assign({}, changeSet), { inserts: [
|
|
298
298
|
...changeSet.inserts,
|
|
@@ -300,6 +300,14 @@ function changeSetInsertNewRow(changeSet, name) {
|
|
|
300
300
|
] });
|
|
301
301
|
}
|
|
302
302
|
exports.changeSetInsertNewRow = changeSetInsertNewRow;
|
|
303
|
+
function changeSetInsertDocuments(changeSet, documents, name) {
|
|
304
|
+
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
|
305
|
+
return Object.assign(Object.assign({}, changeSet), { inserts: [
|
|
306
|
+
...changeSet.inserts,
|
|
307
|
+
...documents.map((doc, index) => (Object.assign(Object.assign({}, name), { insertedRowIndex: insertedRows.length + index, fields: doc }))),
|
|
308
|
+
] });
|
|
309
|
+
}
|
|
310
|
+
exports.changeSetInsertDocuments = changeSetInsertDocuments;
|
|
303
311
|
function changeSetContainsChanges(changeSet) {
|
|
304
312
|
if (!changeSet)
|
|
305
313
|
return false;
|
|
@@ -4,5 +4,5 @@ import { GridConfig, GridCache } from './GridConfig';
|
|
|
4
4
|
export declare function analyseCollectionDisplayColumns(rows: any, display: any): any[];
|
|
5
5
|
export declare class CollectionGridDisplay extends GridDisplay {
|
|
6
6
|
collection: CollectionInfo;
|
|
7
|
-
constructor(collection: CollectionInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, loadedRows: any);
|
|
7
|
+
constructor(collection: CollectionInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, loadedRows: any, changeSet: any);
|
|
8
8
|
}
|
|
@@ -74,18 +74,27 @@ function getDisplayColumn(basePath, columnName, display) {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
function analyseCollectionDisplayColumns(rows, display) {
|
|
77
|
+
var _a;
|
|
77
78
|
const res = [];
|
|
79
|
+
const addedColumns = (_a = display === null || display === void 0 ? void 0 : display.config) === null || _a === void 0 ? void 0 : _a.addedColumns;
|
|
78
80
|
for (const row of rows || []) {
|
|
79
81
|
getColumnsForObject([], row, res, display);
|
|
80
82
|
}
|
|
83
|
+
for (const added of addedColumns || []) {
|
|
84
|
+
if (res.find(x => x.uniqueName == added))
|
|
85
|
+
continue;
|
|
86
|
+
res.push(getDisplayColumn([], added, display));
|
|
87
|
+
}
|
|
81
88
|
return (res.map(col => (Object.assign(Object.assign({}, col), { isChecked: display.isColumnChecked(col) }))) || []);
|
|
82
89
|
}
|
|
83
90
|
exports.analyseCollectionDisplayColumns = analyseCollectionDisplayColumns;
|
|
84
91
|
class CollectionGridDisplay extends GridDisplay_1.GridDisplay {
|
|
85
|
-
constructor(collection, driver, config, setConfig, cache, setCache, loadedRows) {
|
|
92
|
+
constructor(collection, driver, config, setConfig, cache, setCache, loadedRows, changeSet) {
|
|
86
93
|
super(config, setConfig, cache, setCache, driver);
|
|
87
94
|
this.collection = collection;
|
|
88
|
-
|
|
95
|
+
const changedDocs = lodash_1.default.compact(changeSet.updates.map(chs => chs.document));
|
|
96
|
+
const insertedDocs = lodash_1.default.compact(changeSet.inserts.map(chs => chs.fields));
|
|
97
|
+
this.columns = analyseCollectionDisplayColumns([...(loadedRows || []), ...changedDocs, ...insertedDocs], this);
|
|
89
98
|
this.filterable = true;
|
|
90
99
|
this.sortable = true;
|
|
91
100
|
this.editable = true;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.FreeTableGridDisplay = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
4
8
|
const GridDisplay_1 = require("./GridDisplay");
|
|
9
|
+
const _1 = require(".");
|
|
5
10
|
class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
6
11
|
constructor(model, config, setConfig, cache, setCache) {
|
|
12
|
+
var _a;
|
|
7
13
|
super(config, setConfig, cache, setCache);
|
|
8
14
|
this.model = model;
|
|
9
|
-
this.columns =
|
|
15
|
+
this.columns = ((_a = model === null || model === void 0 ? void 0 : model.structure) === null || _a === void 0 ? void 0 : _a.__isDynamicStructure)
|
|
16
|
+
? (0, _1.analyseCollectionDisplayColumns)(model === null || model === void 0 ? void 0 : model.rows, this)
|
|
17
|
+
: this.getDisplayColumns(model);
|
|
10
18
|
this.filterable = false;
|
|
11
19
|
this.sortable = false;
|
|
12
20
|
}
|
|
13
21
|
getDisplayColumns(model) {
|
|
14
22
|
var _a, _b, _c;
|
|
15
|
-
return (((_c = (_b = (_a = model === null || model === void 0 ? void 0 : model.structure) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => this.getDisplayColumn(col))) === null || _c === void 0 ? void 0 : _c.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
|
|
23
|
+
return lodash_1.default.uniqBy(((_c = (_b = (_a = model === null || model === void 0 ? void 0 : model.structure) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => this.getDisplayColumn(col))) === null || _c === void 0 ? void 0 : _c.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || [], col => col.uniqueName);
|
|
16
24
|
}
|
|
17
25
|
getDisplayColumn(col) {
|
|
18
26
|
const uniquePath = [col.columnName];
|
package/lib/GridDisplay.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GridConfig, GridCache, GridConfigColumns, GroupFunc } from './GridConfig';
|
|
2
|
-
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo, CollectionInfo, SqlDialect } from 'dbgate-types';
|
|
2
|
+
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo, CollectionInfo, SqlDialect, ViewInfo } from 'dbgate-types';
|
|
3
3
|
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
|
4
4
|
import { Select, Condition } from 'dbgate-sqltree';
|
|
5
5
|
export interface DisplayColumn {
|
|
@@ -40,8 +40,11 @@ export declare abstract class GridDisplay {
|
|
|
40
40
|
dialect: SqlDialect;
|
|
41
41
|
columns: DisplayColumn[];
|
|
42
42
|
baseTable?: TableInfo;
|
|
43
|
+
baseView?: ViewInfo;
|
|
43
44
|
baseCollection?: CollectionInfo;
|
|
45
|
+
get baseTableOrSimilar(): NamedObjectInfo;
|
|
44
46
|
get baseTableOrCollection(): NamedObjectInfo;
|
|
47
|
+
get baseTableOrView(): TableInfo | ViewInfo;
|
|
45
48
|
changeSetKeyFields: string[];
|
|
46
49
|
sortable: boolean;
|
|
47
50
|
groupable: boolean;
|
|
@@ -51,6 +54,7 @@ export declare abstract class GridDisplay {
|
|
|
51
54
|
supportsReload: boolean;
|
|
52
55
|
isDynamicStructure: boolean;
|
|
53
56
|
setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
|
|
57
|
+
addDynamicColumn(name: string): void;
|
|
54
58
|
focusColumn(uniqueName: string): void;
|
|
55
59
|
get hasReferences(): boolean;
|
|
56
60
|
get focusedColumn(): string;
|
package/lib/GridDisplay.js
CHANGED
|
@@ -29,9 +29,15 @@ class GridDisplay {
|
|
|
29
29
|
this.isDynamicStructure = false;
|
|
30
30
|
this.dialect = ((driver === null || driver === void 0 ? void 0 : driver.dialectByVersion) && (driver === null || driver === void 0 ? void 0 : driver.dialectByVersion(serverVersion))) || (driver === null || driver === void 0 ? void 0 : driver.dialect);
|
|
31
31
|
}
|
|
32
|
+
get baseTableOrSimilar() {
|
|
33
|
+
return this.baseTable || this.baseCollection || this.baseView;
|
|
34
|
+
}
|
|
32
35
|
get baseTableOrCollection() {
|
|
33
36
|
return this.baseTable || this.baseCollection;
|
|
34
37
|
}
|
|
38
|
+
get baseTableOrView() {
|
|
39
|
+
return this.baseTable || this.baseView;
|
|
40
|
+
}
|
|
35
41
|
setColumnVisibility(uniquePath, isVisible) {
|
|
36
42
|
const uniqueName = uniquePath.join('.');
|
|
37
43
|
if (uniquePath.length == 1) {
|
|
@@ -43,6 +49,9 @@ class GridDisplay {
|
|
|
43
49
|
this.reload();
|
|
44
50
|
}
|
|
45
51
|
}
|
|
52
|
+
addDynamicColumn(name) {
|
|
53
|
+
this.includeInColumnSet('addedColumns', name, true);
|
|
54
|
+
}
|
|
46
55
|
focusColumn(uniqueName) {
|
|
47
56
|
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumn: uniqueName })));
|
|
48
57
|
}
|
|
@@ -81,7 +90,7 @@ class GridDisplay {
|
|
|
81
90
|
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { hiddenColumns: this.columns.map(x => x.uniqueName) })));
|
|
82
91
|
}
|
|
83
92
|
get hiddenColumnIndexes() {
|
|
84
|
-
return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.
|
|
93
|
+
return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.allColumns, y => y.uniqueName == x));
|
|
85
94
|
}
|
|
86
95
|
isColumnChecked(column) {
|
|
87
96
|
// console.log('isColumnChecked', column, this.config.hiddenColumns);
|
|
@@ -249,10 +258,11 @@ class GridDisplay {
|
|
|
249
258
|
this.reload();
|
|
250
259
|
}
|
|
251
260
|
getGrouping(uniqueName) {
|
|
261
|
+
var _a, _b;
|
|
252
262
|
if (this.isGrouped) {
|
|
253
263
|
if (this.config.grouping[uniqueName])
|
|
254
264
|
return this.config.grouping[uniqueName];
|
|
255
|
-
const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
|
|
265
|
+
const column = (_b = (_a = (this.baseTable || this.baseView)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.find(x => x.columnName == uniqueName);
|
|
256
266
|
if ((0, dbgate_tools_2.isTypeLogical)(column === null || column === void 0 ? void 0 : column.dataType))
|
|
257
267
|
return 'COUNT DISTINCT';
|
|
258
268
|
if (column === null || column === void 0 ? void 0 : column.autoIncrement)
|
|
@@ -285,21 +295,21 @@ class GridDisplay {
|
|
|
285
295
|
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
|
286
296
|
if (!col)
|
|
287
297
|
return null;
|
|
288
|
-
const
|
|
289
|
-
if (!
|
|
298
|
+
const baseObj = this.baseTableOrSimilar;
|
|
299
|
+
if (!baseObj)
|
|
290
300
|
return null;
|
|
291
|
-
if (
|
|
301
|
+
if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
|
|
292
302
|
return null;
|
|
293
303
|
}
|
|
294
304
|
return Object.assign(Object.assign({}, this.getChangeSetRow(row, insertedRowIndex)), { uniqueName: uniqueName, columnName: col.columnName });
|
|
295
305
|
}
|
|
296
306
|
getChangeSetRow(row, insertedRowIndex) {
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
307
|
+
const baseObj = this.baseTableOrSimilar;
|
|
308
|
+
if (!baseObj)
|
|
299
309
|
return null;
|
|
300
310
|
return {
|
|
301
|
-
pureName:
|
|
302
|
-
schemaName:
|
|
311
|
+
pureName: baseObj.pureName,
|
|
312
|
+
schemaName: baseObj.schemaName,
|
|
303
313
|
insertedRowIndex,
|
|
304
314
|
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
|
305
315
|
};
|
package/lib/JslGridDisplay.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.JslGridDisplay = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
4
8
|
const GridDisplay_1 = require("./GridDisplay");
|
|
5
9
|
const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
|
|
6
10
|
class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
@@ -9,7 +13,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
9
13
|
super(config, setConfig, cache, setCache, null);
|
|
10
14
|
this.filterable = true;
|
|
11
15
|
if (structure.columns) {
|
|
12
|
-
this.columns = (_a = structure.columns
|
|
16
|
+
this.columns = lodash_1.default.uniqBy((_a = structure.columns
|
|
13
17
|
.map(col => ({
|
|
14
18
|
columnName: col.columnName,
|
|
15
19
|
headerText: col.columnName,
|
|
@@ -19,7 +23,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
19
23
|
autoIncrement: col.autoIncrement,
|
|
20
24
|
pureName: null,
|
|
21
25
|
schemaName: null,
|
|
22
|
-
}))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })));
|
|
26
|
+
}))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) }))), col => col.uniqueName);
|
|
23
27
|
}
|
|
24
28
|
if (structure.__isDynamicStructure) {
|
|
25
29
|
this.columns = (0, CollectionGridDisplay_1.analyseCollectionDisplayColumns)(rows, this);
|
package/lib/ViewGridDisplay.js
CHANGED
|
@@ -9,9 +9,10 @@ class ViewGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
9
9
|
this.columns = this.getDisplayColumns(view);
|
|
10
10
|
this.filterable = true;
|
|
11
11
|
this.sortable = true;
|
|
12
|
-
this.groupable =
|
|
12
|
+
this.groupable = false;
|
|
13
13
|
this.editable = false;
|
|
14
14
|
this.supportsReload = true;
|
|
15
|
+
this.baseView = view;
|
|
15
16
|
}
|
|
16
17
|
getDisplayColumns(view) {
|
|
17
18
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.4.
|
|
2
|
+
"version": "4.4.4",
|
|
3
3
|
"name": "dbgate-datalib",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"lib"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"dbgate-sqltree": "^4.4.
|
|
15
|
-
"dbgate-filterparser": "^4.4.
|
|
14
|
+
"dbgate-sqltree": "^4.4.4",
|
|
15
|
+
"dbgate-filterparser": "^4.4.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"dbgate-types": "^4.4.
|
|
18
|
+
"dbgate-types": "^4.4.4",
|
|
19
19
|
"@types/node": "^13.7.0",
|
|
20
20
|
"typescript": "^4.4.3"
|
|
21
21
|
}
|