dbgate-datalib 4.4.2 → 4.5.0

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.
@@ -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
- this.columns = analyseCollectionDisplayColumns(loadedRows, this);
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 = this.getDisplayColumns(model);
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];
@@ -16,7 +16,7 @@ export interface GridConfig extends GridConfigColumns {
16
16
  filters: {
17
17
  [uniqueName: string]: string;
18
18
  };
19
- focusedColumn?: string;
19
+ focusedColumns?: string[];
20
20
  columnWidths: {
21
21
  [uniqueName: string]: number;
22
22
  };
package/lib/GridConfig.js CHANGED
@@ -9,7 +9,7 @@ function createGridConfig() {
9
9
  filters: {},
10
10
  columnWidths: {},
11
11
  sort: [],
12
- focusedColumn: null,
12
+ focusedColumns: null,
13
13
  grouping: {},
14
14
  formFilterColumns: [],
15
15
  };
@@ -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,11 +54,13 @@ export declare abstract class GridDisplay {
51
54
  supportsReload: boolean;
52
55
  isDynamicStructure: boolean;
53
56
  setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
54
- focusColumn(uniqueName: string): void;
57
+ addDynamicColumn(name: string): void;
58
+ focusColumns(uniqueNames: string[]): void;
55
59
  get hasReferences(): boolean;
56
- get focusedColumn(): string;
60
+ get focusedColumns(): string[];
57
61
  get engine(): string;
58
62
  get allColumns(): DisplayColumn[];
63
+ findColumn(uniqueName: string): DisplayColumn;
59
64
  getFkTarget(column: DisplayColumn): TableInfo;
60
65
  reload(): void;
61
66
  includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean): void;
@@ -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,14 +49,17 @@ class GridDisplay {
43
49
  this.reload();
44
50
  }
45
51
  }
46
- focusColumn(uniqueName) {
47
- this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumn: uniqueName })));
52
+ addDynamicColumn(name) {
53
+ this.includeInColumnSet('addedColumns', name, true);
54
+ }
55
+ focusColumns(uniqueNames) {
56
+ this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumns: uniqueNames })));
48
57
  }
49
58
  get hasReferences() {
50
59
  return false;
51
60
  }
52
- get focusedColumn() {
53
- return this.config.focusedColumn;
61
+ get focusedColumns() {
62
+ return this.config.focusedColumns;
54
63
  }
55
64
  get engine() {
56
65
  var _a;
@@ -59,6 +68,9 @@ class GridDisplay {
59
68
  get allColumns() {
60
69
  return this.getColumns(null).filter(col => col.isChecked || col.uniquePath.length == 1);
61
70
  }
71
+ findColumn(uniqueName) {
72
+ return this.getColumns(null).find(x => x.uniqueName == uniqueName);
73
+ }
62
74
  getFkTarget(column) {
63
75
  return null;
64
76
  }
@@ -81,7 +93,7 @@ class GridDisplay {
81
93
  this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { hiddenColumns: this.columns.map(x => x.uniqueName) })));
82
94
  }
83
95
  get hiddenColumnIndexes() {
84
- return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.columns, y => y.uniqueName == x));
96
+ return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.allColumns, y => y.uniqueName == x));
85
97
  }
86
98
  isColumnChecked(column) {
87
99
  // console.log('isColumnChecked', column, this.config.hiddenColumns);
@@ -249,10 +261,11 @@ class GridDisplay {
249
261
  this.reload();
250
262
  }
251
263
  getGrouping(uniqueName) {
264
+ var _a, _b;
252
265
  if (this.isGrouped) {
253
266
  if (this.config.grouping[uniqueName])
254
267
  return this.config.grouping[uniqueName];
255
- const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
268
+ 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
269
  if ((0, dbgate_tools_2.isTypeLogical)(column === null || column === void 0 ? void 0 : column.dataType))
257
270
  return 'COUNT DISTINCT';
258
271
  if (column === null || column === void 0 ? void 0 : column.autoIncrement)
@@ -285,21 +298,21 @@ class GridDisplay {
285
298
  const col = this.columns.find(x => x.uniqueName == uniqueName);
286
299
  if (!col)
287
300
  return null;
288
- const baseTableOrCollection = this.baseTableOrCollection;
289
- if (!baseTableOrCollection)
301
+ const baseObj = this.baseTableOrSimilar;
302
+ if (!baseObj)
290
303
  return null;
291
- if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) {
304
+ if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
292
305
  return null;
293
306
  }
294
307
  return Object.assign(Object.assign({}, this.getChangeSetRow(row, insertedRowIndex)), { uniqueName: uniqueName, columnName: col.columnName });
295
308
  }
296
309
  getChangeSetRow(row, insertedRowIndex) {
297
- const baseTableOrCollection = this.baseTableOrCollection;
298
- if (!baseTableOrCollection)
310
+ const baseObj = this.baseTableOrSimilar;
311
+ if (!baseObj)
299
312
  return null;
300
313
  return {
301
- pureName: baseTableOrCollection.pureName,
302
- schemaName: baseTableOrCollection.schemaName,
314
+ pureName: baseObj.pureName,
315
+ schemaName: baseObj.schemaName,
303
316
  insertedRowIndex,
304
317
  condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
305
318
  };
@@ -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);
@@ -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 = true;
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;
@@ -7,15 +7,18 @@ exports.getDeleteCascades = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const ChangeSet_1 = require("./ChangeSet");
9
9
  // function getDeleteScript()
10
- function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo) {
10
+ function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo, usedTables) {
11
11
  if (result.find(x => x.title == table.pureName))
12
12
  return;
13
13
  const dependencies = allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName);
14
14
  for (const fk of dependencies) {
15
15
  const depTable = dbinfo.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
16
16
  const subFkPath = [...fkPath, fk];
17
- if (depTable && depTable.pureName != baseCmd.pureName) {
18
- processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo);
17
+ if (depTable && !usedTables.includes(depTable.pureName)) {
18
+ processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo, [
19
+ ...usedTables,
20
+ depTable.pureName,
21
+ ]);
19
22
  }
20
23
  const refCmd = {
21
24
  commandType: 'delete',
@@ -103,7 +106,7 @@ function getDeleteCascades(changeSet, dbinfo) {
103
106
  const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
104
107
  if (!table.primaryKey)
105
108
  continue;
106
- processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo);
109
+ processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo, [table.pureName]);
107
110
  // let resItem = result.find(x => x.title == baseCmd.pureName);
108
111
  // if (!resItem) {
109
112
  // resItem = {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.2",
2
+ "version": "4.5.0",
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.2",
15
- "dbgate-filterparser": "^4.4.2"
14
+ "dbgate-sqltree": "^4.5.0",
15
+ "dbgate-filterparser": "^4.5.0"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.4.2",
18
+ "dbgate-types": "^4.5.0",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }