dbgate-datalib 4.4.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
  }
@@ -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);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.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.2",
15
- "dbgate-filterparser": "^4.4.2"
14
+ "dbgate-sqltree": "^4.4.3",
15
+ "dbgate-filterparser": "^4.4.3"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.4.2",
18
+ "dbgate-types": "^4.4.3",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }