dbgate-datalib 4.4.0-alpha.2 → 4.4.3

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;
@@ -2,11 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FreeTableGridDisplay = void 0;
4
4
  const GridDisplay_1 = require("./GridDisplay");
5
+ const _1 = require(".");
5
6
  class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
6
7
  constructor(model, config, setConfig, cache, setCache) {
8
+ var _a;
7
9
  super(config, setConfig, cache, setCache);
8
10
  this.model = model;
9
- this.columns = this.getDisplayColumns(model);
11
+ this.columns = ((_a = model === null || model === void 0 ? void 0 : model.structure) === null || _a === void 0 ? void 0 : _a.__isDynamicStructure)
12
+ ? (0, _1.analyseCollectionDisplayColumns)(model === null || model === void 0 ? void 0 : model.rows, this)
13
+ : this.getDisplayColumns(model);
10
14
  this.filterable = false;
11
15
  this.sortable = false;
12
16
  }
@@ -15,7 +15,7 @@ export interface DisplayColumn {
15
15
  foreignKey?: ForeignKeyInfo;
16
16
  isExpandable?: boolean;
17
17
  isChecked?: boolean;
18
- hintColumnName?: string;
18
+ hintColumnNames?: string[];
19
19
  dataType?: string;
20
20
  filterType?: boolean;
21
21
  isStructured?: boolean;
@@ -51,6 +51,7 @@ export declare abstract class GridDisplay {
51
51
  supportsReload: boolean;
52
52
  isDynamicStructure: boolean;
53
53
  setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
54
+ addDynamicColumn(name: string): void;
54
55
  focusColumn(uniqueName: string): void;
55
56
  get hasReferences(): boolean;
56
57
  get focusedColumn(): string;
@@ -43,6 +43,9 @@ class GridDisplay {
43
43
  this.reload();
44
44
  }
45
45
  }
46
+ addDynamicColumn(name) {
47
+ this.includeInColumnSet('addedColumns', name, true);
48
+ }
46
49
  focusColumn(uniqueName) {
47
50
  this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumn: uniqueName })));
48
51
  }
@@ -81,7 +84,7 @@ class GridDisplay {
81
84
  this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { hiddenColumns: this.columns.map(x => x.uniqueName) })));
82
85
  }
83
86
  get hiddenColumnIndexes() {
84
- return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.columns, y => y.uniqueName == x));
87
+ return (this.config.hiddenColumns || []).map(x => lodash_1.default.findIndex(this.allColumns, y => y.uniqueName == x));
85
88
  }
86
89
  isColumnChecked(column) {
87
90
  // console.log('isColumnChecked', column, this.config.hiddenColumns);
@@ -4,10 +4,11 @@ import { EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
4
4
  import { GridConfig, GridCache } from './GridConfig';
5
5
  import { Select, Condition } from 'dbgate-sqltree';
6
6
  import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
7
+ import { DictionaryDescriptionFunc } from '.';
7
8
  export declare class TableFormViewDisplay extends FormViewDisplay {
8
9
  tableName: NamedObjectInfo;
9
10
  private gridDisplay;
10
- constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any);
11
+ constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any, getDictionaryDescription?: DictionaryDescriptionFunc);
11
12
  addDisplayColumns(columns: DisplayColumn[]): void;
12
13
  getPrimaryKeyEqualCondition(row?: any): Condition;
13
14
  getPrimaryKeyOperatorCondition(operator: any): Condition;
@@ -9,10 +9,10 @@ const dbgate_sqltree_1 = require("dbgate-sqltree");
9
9
  const TableGridDisplay_1 = require("./TableGridDisplay");
10
10
  const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
11
11
  class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
12
- constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion) {
12
+ constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription = null) {
13
13
  super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
14
14
  this.tableName = tableName;
15
- this.gridDisplay = new TableGridDisplay_1.TableGridDisplay(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion);
15
+ this.gridDisplay = new TableGridDisplay_1.TableGridDisplay(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription);
16
16
  this.gridDisplay.addAllExpandedColumnsToSelected = true;
17
17
  this.isLoadedCorrectly = this.gridDisplay.isLoadedCorrectly && !!this.driver;
18
18
  this.columns = [];
@@ -1,21 +1,29 @@
1
1
  import { GridDisplay, ChangeCacheFunc, DisplayColumn, DisplayedColumnInfo, ChangeConfigFunc } from './GridDisplay';
2
- import { TableInfo, EngineDriver, ColumnInfo, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
2
+ import { TableInfo, EngineDriver, ColumnInfo, NamedObjectInfo, DatabaseInfo, ForeignKeyInfo } from 'dbgate-types';
3
3
  import { GridConfig, GridCache } from './GridConfig';
4
4
  import { Select } from 'dbgate-sqltree';
5
+ export interface DictionaryDescription {
6
+ expression: string;
7
+ columns: string[];
8
+ delimiter: string;
9
+ }
10
+ export declare type DictionaryDescriptionFunc = (table: TableInfo) => DictionaryDescription;
5
11
  export declare class TableGridDisplay extends GridDisplay {
6
12
  tableName: NamedObjectInfo;
7
13
  displayOptions: any;
14
+ getDictionaryDescription: DictionaryDescriptionFunc;
8
15
  table: TableInfo;
9
16
  addAllExpandedColumnsToSelected: boolean;
10
17
  hintBaseColumns: DisplayColumn[];
11
- constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any);
18
+ constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any, getDictionaryDescription?: DictionaryDescriptionFunc);
12
19
  findTable({ schemaName, pureName }: {
13
20
  schemaName?: any;
14
21
  pureName: any;
15
22
  }): TableInfo;
16
23
  getDisplayColumns(table: TableInfo, parentPath: string[]): {
17
24
  isChecked: boolean;
18
- hintColumnName: string;
25
+ hintColumnNames: string[];
26
+ hintColumnDelimiter: string;
19
27
  isExpandable: boolean;
20
28
  pureName: string;
21
29
  schemaName: string;
@@ -23,7 +31,7 @@ export declare class TableGridDisplay extends GridDisplay {
23
31
  uniqueName: string;
24
32
  uniquePath: string[];
25
33
  isPrimaryKey: boolean;
26
- foreignKey: import("dbgate-types").ForeignKeyInfo;
34
+ foreignKey: ForeignKeyInfo;
27
35
  pairingId?: string;
28
36
  columnName: string;
29
37
  notNull: boolean;
@@ -40,6 +48,7 @@ export declare class TableGridDisplay extends GridDisplay {
40
48
  }[];
41
49
  addJoinsFromExpandedColumns(select: Select, columns: DisplayColumn[], parentAlias: string, columnSources: any): void;
42
50
  addReferenceToSelect(select: Select, parentAlias: string, column: DisplayColumn): void;
51
+ getFkDictionaryDescription(foreignKey: ForeignKeyInfo): DictionaryDescription;
43
52
  addHintsToSelect(select: Select): boolean;
44
53
  enrichExpandedColumns(list: DisplayColumn[]): DisplayColumn[];
45
54
  getExpandedColumns(column: DisplayColumn): DisplayColumn[];
@@ -54,7 +63,7 @@ export declare class TableGridDisplay extends GridDisplay {
54
63
  uniqueName: string;
55
64
  uniquePath: string[];
56
65
  isPrimaryKey: boolean;
57
- foreignKey: import("dbgate-types").ForeignKeyInfo;
66
+ foreignKey: ForeignKeyInfo;
58
67
  pairingId?: string;
59
68
  columnName: string;
60
69
  notNull: boolean;
@@ -4,10 +4,11 @@ exports.TableGridDisplay = void 0;
4
4
  const dbgate_tools_1 = require("dbgate-tools");
5
5
  const GridDisplay_1 = require("./GridDisplay");
6
6
  class TableGridDisplay extends GridDisplay_1.GridDisplay {
7
- constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion) {
7
+ constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription = null) {
8
8
  super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
9
9
  this.tableName = tableName;
10
10
  this.displayOptions = displayOptions;
11
+ this.getDictionaryDescription = getDictionaryDescription;
11
12
  this.addAllExpandedColumnsToSelected = false;
12
13
  this.table = this.findTable(tableName);
13
14
  if (!this.table) {
@@ -38,7 +39,10 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
38
39
  }
39
40
  getDisplayColumns(table, parentPath) {
40
41
  var _a, _b;
41
- return (((_b = (_a = table === null || table === void 0 ? void 0 : table.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(table, col, parentPath))) === null || _b === void 0 ? void 0 : _b.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnName: col.foreignKey ? `hint_${col.uniqueName}` : null, isExpandable: !!col.foreignKey })))) || []);
42
+ return (((_b = (_a = table === null || table === void 0 ? void 0 : table.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(table, col, parentPath))) === null || _b === void 0 ? void 0 : _b.map(col => {
43
+ var _a, _b, _c;
44
+ return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.foreignKey)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(columnName => `hint_${col.uniqueName}_${columnName}`)) || null, hintColumnDelimiter: (_c = this.getFkDictionaryDescription(col.foreignKey)) === null || _c === void 0 ? void 0 : _c.delimiter, isExpandable: !!col.foreignKey }));
45
+ })) || []);
42
46
  }
43
47
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
44
48
  for (const column of columns) {
@@ -86,6 +90,18 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
86
90
  ];
87
91
  }
88
92
  }
93
+ getFkDictionaryDescription(foreignKey) {
94
+ if (!foreignKey)
95
+ return null;
96
+ const pureName = foreignKey.refTableName;
97
+ const schemaName = foreignKey.refSchemaName;
98
+ const table = this.findTable({ schemaName, pureName });
99
+ if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
100
+ const hintDescription = this.getDictionaryDescription(table);
101
+ return hintDescription;
102
+ }
103
+ return null;
104
+ }
89
105
  addHintsToSelect(select) {
90
106
  let res = false;
91
107
  const groupColumns = this.groupColumns;
@@ -96,17 +112,18 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
96
112
  }
97
113
  const table = this.getFkTarget(column);
98
114
  if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
99
- const hintColumn = table.columns.find(x => { var _a, _b; return (_b = (_a = x === null || x === void 0 ? void 0 : x.dataType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes('char'); });
100
- if (hintColumn) {
115
+ // const hintColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
116
+ const hintDescription = this.getDictionaryDescription(table);
117
+ if (hintDescription) {
101
118
  const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
102
119
  this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
103
120
  const childAlias = `${column.uniqueName}_ref`;
104
- select.columns.push({
121
+ select.columns.push(...hintDescription.columns.map(columnName => ({
105
122
  exprType: 'column',
106
- columnName: hintColumn.columnName,
107
- alias: `hint_${column.uniqueName}`,
123
+ columnName,
124
+ alias: `hint_${column.uniqueName}_${columnName}`,
108
125
  source: { alias: childAlias },
109
- });
126
+ })));
110
127
  res = true;
111
128
  }
112
129
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.0-alpha.2",
2
+ "version": "4.4.3",
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.0-alpha.2",
15
- "dbgate-filterparser": "^4.4.0-alpha.2"
14
+ "dbgate-sqltree": "^4.4.3",
15
+ "dbgate-filterparser": "^4.4.3"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.4.0-alpha.2",
18
+ "dbgate-types": "^4.4.3",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }