dbgate-datalib 4.6.0 → 4.7.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.
package/lib/ChangeSet.js CHANGED
@@ -251,6 +251,16 @@ function revertChangeSetRowChanges(changeSet, definition) {
251
251
  return changeSet;
252
252
  }
253
253
  exports.revertChangeSetRowChanges = revertChangeSetRowChanges;
254
+ function consolidateInsertIndexes(changeSet, name) {
255
+ const indexes = changeSet.inserts
256
+ .filter(x => x.pureName == name.pureName && x.schemaName == name.schemaName)
257
+ .map(x => x.insertedRowIndex);
258
+ indexes.sort((a, b) => a - b);
259
+ if (indexes[indexes.length - 1] != indexes.length - 1) {
260
+ return Object.assign(Object.assign({}, changeSet), { inserts: changeSet.inserts.map(x => (Object.assign(Object.assign({}, x), { insertedRowIndex: indexes.indexOf(x.insertedRowIndex) }))) });
261
+ }
262
+ return changeSet;
263
+ }
254
264
  function deleteChangeSetRows(changeSet, definition) {
255
265
  let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
256
266
  if (fieldName == 'updates') {
@@ -258,7 +268,7 @@ function deleteChangeSetRows(changeSet, definition) {
258
268
  [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
259
269
  }
260
270
  if (fieldName == 'inserts') {
261
- return revertChangeSetRowChanges(changeSet, definition);
271
+ return consolidateInsertIndexes(revertChangeSetRowChanges(changeSet, definition), definition);
262
272
  }
263
273
  else {
264
274
  if (existingItem && fieldName == 'deletes')
@@ -25,6 +25,9 @@ export declare class FreeTableGridDisplay extends GridDisplay {
25
25
  isSparse?: boolean;
26
26
  defaultValue?: string;
27
27
  defaultConstraint?: string;
28
+ columnComment?: string;
29
+ isUnsigned?: boolean;
30
+ isZerofill?: boolean;
28
31
  }[];
29
32
  getDisplayColumn(col: ColumnInfo): {
30
33
  pureName: string;
@@ -45,5 +48,8 @@ export declare class FreeTableGridDisplay extends GridDisplay {
45
48
  isSparse?: boolean;
46
49
  defaultValue?: string;
47
50
  defaultConstraint?: string;
51
+ columnComment?: string;
52
+ isUnsigned?: boolean;
53
+ isZerofill?: boolean;
48
54
  };
49
55
  }
@@ -13,6 +13,7 @@ export interface DisplayColumn {
13
13
  autoIncrement?: boolean;
14
14
  isPrimaryKey?: boolean;
15
15
  foreignKey?: ForeignKeyInfo;
16
+ isForeignKeyUnique?: boolean;
16
17
  isExpandable?: boolean;
17
18
  isChecked?: boolean;
18
19
  hintColumnNames?: string[];
@@ -53,6 +54,7 @@ export declare abstract class GridDisplay {
53
54
  isLoadedCorrectly: boolean;
54
55
  supportsReload: boolean;
55
56
  isDynamicStructure: boolean;
57
+ filterTypeOverride: any;
56
58
  setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
57
59
  addDynamicColumn(name: string): void;
58
60
  focusColumns(uniqueNames: string[]): void;
@@ -27,6 +27,7 @@ class GridDisplay {
27
27
  this.isLoadedCorrectly = true;
28
28
  this.supportsReload = false;
29
29
  this.isDynamicStructure = false;
30
+ this.filterTypeOverride = null;
30
31
  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
32
  }
32
33
  get baseTableOrSimilar() {
@@ -462,22 +463,23 @@ class GridDisplay {
462
463
  return sql;
463
464
  }
464
465
  compileFilters() {
466
+ var _a;
465
467
  const filters = this.config && this.config.filters;
466
468
  if (!filters)
467
469
  return null;
468
470
  const conditions = [];
469
471
  for (const name in filters) {
470
- const column = this.columns.find(x => (x.columnName = name));
471
- if (!column)
472
+ const column = this.isDynamicStructure ? null : this.columns.find(x => x.columnName == name);
473
+ if (!this.isDynamicStructure && !column)
472
474
  continue;
473
- const filterType = (0, dbgate_filterparser_1.getFilterType)(column.dataType);
475
+ const filterType = this.isDynamicStructure ? (_a = this.filterTypeOverride) !== null && _a !== void 0 ? _a : 'mongo' : (0, dbgate_filterparser_1.getFilterType)(column.dataType);
474
476
  try {
475
477
  const condition = (0, dbgate_filterparser_1.parseFilter)(filters[name], filterType);
476
478
  const replaced = lodash_1.default.cloneDeepWith(condition, (expr) => {
477
479
  if (expr.exprType == 'placeholder')
478
480
  return {
479
481
  exprType: 'column',
480
- columnName: column.columnName,
482
+ columnName: this.isDynamicStructure ? name : column.columnName,
481
483
  };
482
484
  });
483
485
  conditions.push(replaced);
@@ -1,5 +1,5 @@
1
1
  import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
2
2
  import { GridConfig, GridCache } from './GridConfig';
3
3
  export declare class JslGridDisplay extends GridDisplay {
4
- constructor(jslid: any, structure: any, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, rows: any);
4
+ constructor(jslid: any, structure: any, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, rows: any, isDynamicStructure: boolean, supportsReload: boolean);
5
5
  }
@@ -8,11 +8,15 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const GridDisplay_1 = require("./GridDisplay");
9
9
  const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
10
10
  class JslGridDisplay extends GridDisplay_1.GridDisplay {
11
- constructor(jslid, structure, config, setConfig, cache, setCache, rows) {
11
+ constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload) {
12
12
  var _a;
13
13
  super(config, setConfig, cache, setCache, null);
14
14
  this.filterable = true;
15
- if (structure.columns) {
15
+ this.supportsReload = supportsReload;
16
+ this.isDynamicStructure = isDynamicStructure;
17
+ if (isDynamicStructure)
18
+ this.filterTypeOverride = 'string';
19
+ if (structure === null || structure === void 0 ? void 0 : structure.columns) {
16
20
  this.columns = lodash_1.default.uniqBy((_a = structure.columns
17
21
  .map(col => ({
18
22
  columnName: col.columnName,
@@ -25,7 +29,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
25
29
  schemaName: null,
26
30
  }))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) }))), col => col.uniqueName);
27
31
  }
28
- if (structure.__isDynamicStructure) {
32
+ if (structure === null || structure === void 0 ? void 0 : structure.__isDynamicStructure) {
29
33
  this.columns = (0, CollectionGridDisplay_1.analyseCollectionDisplayColumns)(rows, this);
30
34
  }
31
35
  if (!this.columns)
@@ -32,6 +32,7 @@ export declare class TableGridDisplay extends GridDisplay {
32
32
  uniquePath: string[];
33
33
  isPrimaryKey: boolean;
34
34
  foreignKey: ForeignKeyInfo;
35
+ isForeignKeyUnique: boolean;
35
36
  pairingId?: string;
36
37
  columnName: string;
37
38
  notNull: boolean;
@@ -45,6 +46,9 @@ export declare class TableGridDisplay extends GridDisplay {
45
46
  isSparse?: boolean;
46
47
  defaultValue?: string;
47
48
  defaultConstraint?: string;
49
+ columnComment?: string;
50
+ isUnsigned?: boolean;
51
+ isZerofill?: boolean;
48
52
  }[];
49
53
  addJoinsFromExpandedColumns(select: Select, columns: DisplayColumn[], parentAlias: string, columnSources: any): void;
50
54
  addReferenceToSelect(select: Select, parentAlias: string, column: DisplayColumn): void;
@@ -64,6 +68,7 @@ export declare class TableGridDisplay extends GridDisplay {
64
68
  uniquePath: string[];
65
69
  isPrimaryKey: boolean;
66
70
  foreignKey: ForeignKeyInfo;
71
+ isForeignKeyUnique: boolean;
67
72
  pairingId?: string;
68
73
  columnName: string;
69
74
  notNull: boolean;
@@ -77,6 +82,9 @@ export declare class TableGridDisplay extends GridDisplay {
77
82
  isSparse?: boolean;
78
83
  defaultValue?: string;
79
84
  defaultConstraint?: string;
85
+ columnComment?: string;
86
+ isUnsigned?: boolean;
87
+ isZerofill?: boolean;
80
88
  };
81
89
  addAddedColumnsToSelect(select: Select, columns: DisplayColumn[], parentAlias: string, displayedColumnInfo: DisplayedColumnInfo): void;
82
90
  get hasReferences(): boolean;
@@ -41,7 +41,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
41
41
  var _a, _b;
42
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
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 }));
44
+ return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === 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.isForeignKeyUnique ? col.foreignKey : null)) === null || _c === void 0 ? void 0 : _c.delimiter, isExpandable: !!col.foreignKey }));
45
45
  })) || []);
46
46
  }
47
47
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
@@ -148,7 +148,9 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
148
148
  return [];
149
149
  }
150
150
  getFkTarget(column) {
151
- const { uniqueName, foreignKey } = column;
151
+ const { uniqueName, foreignKey, isForeignKeyUnique } = column;
152
+ if (!isForeignKeyUnique)
153
+ return null;
152
154
  const pureName = foreignKey.refTableName;
153
155
  const schemaName = foreignKey.refSchemaName;
154
156
  return this.findTable({ schemaName, pureName });
@@ -172,9 +174,16 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
172
174
  const uniquePath = [...parentPath, col.columnName];
173
175
  const uniqueName = uniquePath.join('.');
174
176
  // console.log('this.config.addedColumns', this.config.addedColumns, uniquePath);
175
- return Object.assign(Object.assign({}, col), { pureName: table.pureName, schemaName: table.schemaName, headerText: uniquePath.length == 1 ? col.columnName : `${table.pureName}.${col.columnName}`, uniqueName,
177
+ const res = Object.assign(Object.assign({}, col), { pureName: table.pureName, schemaName: table.schemaName, headerText: uniquePath.length == 1 ? col.columnName : `${table.pureName}.${col.columnName}`, uniqueName,
176
178
  uniquePath, isPrimaryKey: table.primaryKey && !!table.primaryKey.columns.find(x => x.columnName == col.columnName), foreignKey: table.foreignKeys &&
177
- table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName) });
179
+ table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName), isForeignKeyUnique: false });
180
+ if (res.foreignKey) {
181
+ const refTableInfo = this.dbinfo.tables.find(x => x.schemaName == res.foreignKey.refSchemaName && x.pureName == res.foreignKey.refTableName);
182
+ if (refTableInfo && (0, dbgate_tools_1.isTableColumnUnique)(refTableInfo, res.foreignKey.columns[0].refColumnName)) {
183
+ res.isForeignKeyUnique = true;
184
+ }
185
+ }
186
+ return res;
178
187
  }
179
188
  addAddedColumnsToSelect(select, columns, parentAlias, displayedColumnInfo) {
180
189
  for (const column of columns) {
@@ -24,6 +24,9 @@ export declare class ViewGridDisplay extends GridDisplay {
24
24
  isSparse?: boolean;
25
25
  defaultValue?: string;
26
26
  defaultConstraint?: string;
27
+ columnComment?: string;
28
+ isUnsigned?: boolean;
29
+ isZerofill?: boolean;
27
30
  }[];
28
31
  getDisplayColumn(view: ViewInfo, col: ColumnInfo): {
29
32
  pureName: string;
@@ -44,6 +47,9 @@ export declare class ViewGridDisplay extends GridDisplay {
44
47
  isSparse?: boolean;
45
48
  defaultValue?: string;
46
49
  defaultConstraint?: string;
50
+ columnComment?: string;
51
+ isUnsigned?: boolean;
52
+ isZerofill?: boolean;
47
53
  };
48
54
  createSelect(options?: {}): import("dbgate-sqltree").Select;
49
55
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.6.0",
2
+ "version": "4.7.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.6.0",
15
- "dbgate-filterparser": "^4.6.0"
14
+ "dbgate-sqltree": "^4.7.0",
15
+ "dbgate-filterparser": "^4.7.0"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.6.0",
18
+ "dbgate-types": "^4.7.0",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }