dbgate-datalib 4.4.3 → 4.5.1

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.
@@ -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.FreeTableGridDisplay = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
4
8
  const GridDisplay_1 = require("./GridDisplay");
5
9
  const _1 = require(".");
6
10
  class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
@@ -16,7 +20,7 @@ class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
16
20
  }
17
21
  getDisplayColumns(model) {
18
22
  var _a, _b, _c;
19
- 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);
20
24
  }
21
25
  getDisplayColumn(col) {
22
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;
@@ -52,11 +55,12 @@ export declare abstract class GridDisplay {
52
55
  isDynamicStructure: boolean;
53
56
  setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
54
57
  addDynamicColumn(name: string): void;
55
- focusColumn(uniqueName: string): void;
58
+ focusColumns(uniqueNames: string[]): void;
56
59
  get hasReferences(): boolean;
57
- get focusedColumn(): string;
60
+ get focusedColumns(): string[];
58
61
  get engine(): string;
59
62
  get allColumns(): DisplayColumn[];
63
+ findColumn(uniqueName: string): DisplayColumn;
60
64
  getFkTarget(column: DisplayColumn): TableInfo;
61
65
  reload(): void;
62
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) {
@@ -46,14 +52,14 @@ class GridDisplay {
46
52
  addDynamicColumn(name) {
47
53
  this.includeInColumnSet('addedColumns', name, true);
48
54
  }
49
- focusColumn(uniqueName) {
50
- this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumn: uniqueName })));
55
+ focusColumns(uniqueNames) {
56
+ this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumns: uniqueNames })));
51
57
  }
52
58
  get hasReferences() {
53
59
  return false;
54
60
  }
55
- get focusedColumn() {
56
- return this.config.focusedColumn;
61
+ get focusedColumns() {
62
+ return this.config.focusedColumns;
57
63
  }
58
64
  get engine() {
59
65
  var _a;
@@ -62,6 +68,9 @@ class GridDisplay {
62
68
  get allColumns() {
63
69
  return this.getColumns(null).filter(col => col.isChecked || col.uniquePath.length == 1);
64
70
  }
71
+ findColumn(uniqueName) {
72
+ return this.getColumns(null).find(x => x.uniqueName == uniqueName);
73
+ }
65
74
  getFkTarget(column) {
66
75
  return null;
67
76
  }
@@ -252,10 +261,11 @@ class GridDisplay {
252
261
  this.reload();
253
262
  }
254
263
  getGrouping(uniqueName) {
264
+ var _a, _b;
255
265
  if (this.isGrouped) {
256
266
  if (this.config.grouping[uniqueName])
257
267
  return this.config.grouping[uniqueName];
258
- 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);
259
269
  if ((0, dbgate_tools_2.isTypeLogical)(column === null || column === void 0 ? void 0 : column.dataType))
260
270
  return 'COUNT DISTINCT';
261
271
  if (column === null || column === void 0 ? void 0 : column.autoIncrement)
@@ -288,21 +298,21 @@ class GridDisplay {
288
298
  const col = this.columns.find(x => x.uniqueName == uniqueName);
289
299
  if (!col)
290
300
  return null;
291
- const baseTableOrCollection = this.baseTableOrCollection;
292
- if (!baseTableOrCollection)
301
+ const baseObj = this.baseTableOrSimilar;
302
+ if (!baseObj)
293
303
  return null;
294
- if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) {
304
+ if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
295
305
  return null;
296
306
  }
297
307
  return Object.assign(Object.assign({}, this.getChangeSetRow(row, insertedRowIndex)), { uniqueName: uniqueName, columnName: col.columnName });
298
308
  }
299
309
  getChangeSetRow(row, insertedRowIndex) {
300
- const baseTableOrCollection = this.baseTableOrCollection;
301
- if (!baseTableOrCollection)
310
+ const baseObj = this.baseTableOrSimilar;
311
+ if (!baseObj)
302
312
  return null;
303
313
  return {
304
- pureName: baseTableOrCollection.pureName,
305
- schemaName: baseTableOrCollection.schemaName,
314
+ pureName: baseObj.pureName,
315
+ schemaName: baseObj.schemaName,
306
316
  insertedRowIndex,
307
317
  condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
308
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.3",
2
+ "version": "4.5.1",
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.3",
15
- "dbgate-filterparser": "^4.4.3"
14
+ "dbgate-sqltree": "^4.5.1",
15
+ "dbgate-filterparser": "^4.5.1"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.4.3",
18
+ "dbgate-types": "^4.5.1",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }