dbgate-datalib 4.3.0 → 4.3.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,4 +1,4 @@
1
- import { Command } from 'dbgate-sqltree';
1
+ import { Command, Condition } from 'dbgate-sqltree';
2
2
  import { NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
3
3
  export interface ChangeSetItem {
4
4
  pureName: string;
@@ -34,6 +34,7 @@ export declare function findExistingChangeSetItem(changeSet: ChangeSet, definiti
34
34
  export declare function setChangeSetValue(changeSet: ChangeSet, definition: ChangeSetFieldDefinition, value: string): ChangeSet;
35
35
  export declare function setChangeSetRowData(changeSet: ChangeSet, definition: ChangeSetRowDefinition, document: any): ChangeSet;
36
36
  export declare function batchUpdateChangeSet(changeSet: ChangeSet, rowDefinitions: ChangeSetRowDefinition[], dataRows: []): ChangeSet;
37
+ export declare function extractChangeSetCondition(item: ChangeSetItem, alias?: string): Condition;
37
38
  export declare function changeSetToSql(changeSet: ChangeSet, dbinfo: DatabaseInfo): Command[];
38
39
  export declare function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
39
40
  export declare function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
package/lib/ChangeSet.js CHANGED
@@ -3,6 +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
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  function createChangeSet() {
8
9
  return {
@@ -140,7 +141,7 @@ function extractFields(item, allowNulls = true) {
140
141
  value: item.fields[targetColumn],
141
142
  }));
142
143
  }
143
- function insertToSql(item, dbinfo = null) {
144
+ function changeSetInsertToSql(item, dbinfo = null) {
144
145
  const fields = extractFields(item, false);
145
146
  if (fields.length == 0)
146
147
  return null;
@@ -181,7 +182,7 @@ function insertToSql(item, dbinfo = null) {
181
182
  : null,
182
183
  ];
183
184
  }
184
- function extractCondition(item) {
185
+ function extractChangeSetCondition(item, alias) {
185
186
  return {
186
187
  conditionType: 'and',
187
188
  conditions: lodash_1.default.keys(item.condition).map(columnName => ({
@@ -195,6 +196,7 @@ function extractCondition(item) {
195
196
  pureName: item.pureName,
196
197
  schemaName: item.schemaName,
197
198
  },
199
+ alias,
198
200
  },
199
201
  },
200
202
  right: {
@@ -204,7 +206,8 @@ function extractCondition(item) {
204
206
  })),
205
207
  };
206
208
  }
207
- function updateToSql(item) {
209
+ exports.extractChangeSetCondition = extractChangeSetCondition;
210
+ function changeSetUpdateToSql(item) {
208
211
  return {
209
212
  from: {
210
213
  name: {
@@ -214,10 +217,10 @@ function updateToSql(item) {
214
217
  },
215
218
  commandType: 'update',
216
219
  fields: extractFields(item),
217
- where: extractCondition(item),
220
+ where: extractChangeSetCondition(item),
218
221
  };
219
222
  }
220
- function deleteToSql(item) {
223
+ function changeSetDeleteToSql(item) {
221
224
  return {
222
225
  from: {
223
226
  name: {
@@ -226,14 +229,14 @@ function deleteToSql(item) {
226
229
  },
227
230
  },
228
231
  commandType: 'delete',
229
- where: extractCondition(item),
232
+ where: extractChangeSetCondition(item),
230
233
  };
231
234
  }
232
235
  function changeSetToSql(changeSet, dbinfo) {
233
236
  return lodash_1.default.compact(lodash_1.default.flatten([
234
- ...changeSet.inserts.map(item => insertToSql(item, dbinfo)),
235
- ...changeSet.updates.map(updateToSql),
236
- ...changeSet.deletes.map(deleteToSql),
237
+ ...changeSet.inserts.map(item => changeSetInsertToSql(item, dbinfo)),
238
+ ...changeSet.updates.map(changeSetUpdateToSql),
239
+ ...changeSet.deletes.map(changeSetDeleteToSql),
237
240
  ]));
238
241
  }
239
242
  exports.changeSetToSql = changeSetToSql;
@@ -3,6 +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.CollectionGridDisplay = exports.analyseCollectionDisplayColumns = void 0;
6
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  const GridDisplay_1 = require("./GridDisplay");
8
9
  function getObjectKeys(obj) {
@@ -3,12 +3,12 @@ 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.FormViewDisplay = void 0;
6
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  const GridConfig_1 = require("./GridConfig");
8
9
  const dbgate_filterparser_1 = require("dbgate-filterparser");
9
10
  class FormViewDisplay {
10
11
  constructor(config, setConfig, cache, setCache, driver, dbinfo = null, serverVersion = null) {
11
- var _a, _b, _c;
12
12
  this.config = config;
13
13
  this.setConfig = setConfig;
14
14
  this.cache = cache;
@@ -17,7 +17,7 @@ class FormViewDisplay {
17
17
  this.dbinfo = dbinfo;
18
18
  this.serverVersion = serverVersion;
19
19
  this.isLoadedCorrectly = true;
20
- this.dialect = (((_a = driver) === null || _a === void 0 ? void 0 : _a.dialectByVersion) && ((_b = driver) === null || _b === void 0 ? void 0 : _b.dialectByVersion(serverVersion))) || ((_c = driver) === null || _c === void 0 ? void 0 : _c.dialect);
20
+ 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);
21
21
  }
22
22
  addFilterColumn(column) {
23
23
  if (!column)
@@ -28,7 +28,7 @@ class FormViewDisplay {
28
28
  if (!column || !rowData)
29
29
  return;
30
30
  const value = rowData[column.uniqueName];
31
- const expr = dbgate_filterparser_1.getFilterValueExpression(value, column.dataType);
31
+ const expr = (0, dbgate_filterparser_1.getFilterValueExpression)(value, column.dataType);
32
32
  if (expr) {
33
33
  this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { filters: Object.assign(Object.assign({}, cfg.filters), { [column.uniqueName]: expr }), addedColumns: cfg.addedColumns.includes(column.uniqueName)
34
34
  ? cfg.addedColumns
@@ -47,7 +47,7 @@ class FormViewDisplay {
47
47
  this.reload();
48
48
  }
49
49
  reload() {
50
- this.setCache(cache => (Object.assign(Object.assign({}, GridConfig_1.createGridCache()), { refreshTime: new Date().getTime() })));
50
+ this.setCache(cache => (Object.assign(Object.assign({}, (0, GridConfig_1.createGridCache)()), { refreshTime: new Date().getTime() })));
51
51
  }
52
52
  getKeyValue(columnName) {
53
53
  const { formViewKey, formViewKeyRequested } = this.config;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FreeTableGridDisplay = void 0;
3
4
  const GridDisplay_1 = require("./GridDisplay");
4
5
  class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
5
6
  constructor(model, config, setConfig, cache, setCache) {
@@ -10,8 +11,8 @@ class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
10
11
  this.sortable = false;
11
12
  }
12
13
  getDisplayColumns(model) {
13
- var _a, _b, _c, _d;
14
- return (((_d = (_c = (_b = (_a = model) === null || _a === void 0 ? void 0 : _a.structure) === null || _b === void 0 ? void 0 : _b.columns) === null || _c === void 0 ? void 0 : _c.map(col => this.getDisplayColumn(col))) === null || _d === void 0 ? void 0 : _d.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
14
+ 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) })))) || []);
15
16
  }
16
17
  getDisplayColumn(col) {
17
18
  const uniquePath = [col.columnName];
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFreeTableModel = void 0;
3
4
  function createFreeTableModel() {
4
5
  return {
5
6
  structure: {
package/lib/GridConfig.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createGridCache = exports.createGridConfig = void 0;
3
4
  function createGridConfig() {
4
5
  return {
5
6
  hiddenColumns: [],
@@ -3,6 +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.reloadDataCacheFunc = exports.GridDisplay = void 0;
6
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  const GridConfig_1 = require("./GridConfig");
8
9
  const dbgate_filterparser_1 = require("dbgate-filterparser");
@@ -11,7 +12,6 @@ const dbgate_sqltree_1 = require("dbgate-sqltree");
11
12
  const dbgate_tools_2 = require("dbgate-tools");
12
13
  class GridDisplay {
13
14
  constructor(config, setConfig, cache, setCache, driver, dbinfo = null, serverVersion = null) {
14
- var _a, _b, _c;
15
15
  this.config = config;
16
16
  this.setConfig = setConfig;
17
17
  this.cache = cache;
@@ -27,7 +27,7 @@ class GridDisplay {
27
27
  this.isLoadedCorrectly = true;
28
28
  this.supportsReload = false;
29
29
  this.isDynamicStructure = false;
30
- this.dialect = (((_a = driver) === null || _a === void 0 ? void 0 : _a.dialectByVersion) && ((_b = driver) === null || _b === void 0 ? void 0 : _b.dialectByVersion(serverVersion))) || ((_c = driver) === null || _c === void 0 ? void 0 : _c.dialect);
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
32
  get baseTableOrCollection() {
33
33
  return this.baseTable || this.baseCollection;
@@ -96,7 +96,7 @@ class GridDisplay {
96
96
  if (!column)
97
97
  continue;
98
98
  try {
99
- const condition = dbgate_filterparser_1.parseFilter(filter, dbgate_filterparser_1.getFilterType(column.dataType));
99
+ const condition = (0, dbgate_filterparser_1.parseFilter)(filter, (0, dbgate_filterparser_1.getFilterType)(column.dataType));
100
100
  if (condition) {
101
101
  conditions.push(lodash_1.default.cloneDeepWith(condition, (expr) => {
102
102
  if (expr.exprType == 'placeholder')
@@ -203,7 +203,7 @@ class GridDisplay {
203
203
  }
204
204
  }
205
205
  getColumns(columnFilter) {
206
- return this.columns.filter(col => dbgate_tools_1.filterName(columnFilter, col.columnName));
206
+ return this.columns.filter(col => (0, dbgate_tools_1.filterName)(columnFilter, col.columnName));
207
207
  }
208
208
  getGridColumns() {
209
209
  return this.getColumns(null).filter(x => this.isColumnChecked(x));
@@ -246,14 +246,13 @@ class GridDisplay {
246
246
  this.reload();
247
247
  }
248
248
  getGrouping(uniqueName) {
249
- var _a, _b;
250
249
  if (this.isGrouped) {
251
250
  if (this.config.grouping[uniqueName])
252
251
  return this.config.grouping[uniqueName];
253
252
  const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
254
- if (dbgate_tools_2.isTypeLogical((_a = column) === null || _a === void 0 ? void 0 : _a.dataType))
253
+ if ((0, dbgate_tools_2.isTypeLogical)(column === null || column === void 0 ? void 0 : column.dataType))
255
254
  return 'COUNT DISTINCT';
256
- if ((_b = column) === null || _b === void 0 ? void 0 : _b.autoIncrement)
255
+ if (column === null || column === void 0 ? void 0 : column.autoIncrement)
257
256
  return 'COUNT';
258
257
  return 'MAX';
259
258
  }
@@ -391,7 +390,7 @@ class GridDisplay {
391
390
  select = this.getRowNumberOverSelect(select, offset, count);
392
391
  else if (this.dialect.limitSelect)
393
392
  select.topRecords = count;
394
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
393
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
395
394
  return sql;
396
395
  }
397
396
  getExportQuery(postprocessSelect = null) {
@@ -400,7 +399,7 @@ class GridDisplay {
400
399
  return null;
401
400
  if (postprocessSelect)
402
401
  postprocessSelect(select);
403
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
402
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
404
403
  return sql;
405
404
  }
406
405
  resizeColumn(uniqueName, computedSize, diff) {
@@ -443,7 +442,7 @@ class GridDisplay {
443
442
  },
444
443
  ];
445
444
  }
446
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
445
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
447
446
  return sql;
448
447
  }
449
448
  compileFilters() {
@@ -455,9 +454,9 @@ class GridDisplay {
455
454
  const column = this.columns.find(x => (x.columnName = name));
456
455
  if (!column)
457
456
  continue;
458
- const filterType = dbgate_filterparser_1.getFilterType(column.dataType);
457
+ const filterType = (0, dbgate_filterparser_1.getFilterType)(column.dataType);
459
458
  try {
460
- const condition = dbgate_filterparser_1.parseFilter(filters[name], filterType);
459
+ const condition = (0, dbgate_filterparser_1.parseFilter)(filters[name], filterType);
461
460
  const replaced = lodash_1.default.cloneDeepWith(condition, (expr) => {
462
461
  if (expr.exprType == 'placeholder')
463
462
  return {
@@ -495,6 +494,6 @@ class GridDisplay {
495
494
  }
496
495
  exports.GridDisplay = GridDisplay;
497
496
  function reloadDataCacheFunc(cache) {
498
- return Object.assign(Object.assign({}, GridConfig_1.createGridCache()), { refreshTime: new Date().getTime() });
497
+ return Object.assign(Object.assign({}, (0, GridConfig_1.createGridCache)()), { refreshTime: new Date().getTime() });
499
498
  }
500
499
  exports.reloadDataCacheFunc = reloadDataCacheFunc;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JslGridDisplay = void 0;
3
4
  const GridDisplay_1 = require("./GridDisplay");
4
5
  const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
5
6
  class JslGridDisplay extends GridDisplay_1.GridDisplay {
@@ -21,7 +22,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
21
22
  }))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })));
22
23
  }
23
24
  if (structure.__isDynamicStructure) {
24
- this.columns = CollectionGridDisplay_1.analyseCollectionDisplayColumns(rows, this);
25
+ this.columns = (0, CollectionGridDisplay_1.analyseCollectionDisplayColumns)(rows, this);
25
26
  }
26
27
  if (!this.columns)
27
28
  this.columns = [];
@@ -3,6 +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.TableFormViewDisplay = void 0;
6
7
  const FormViewDisplay_1 = require("./FormViewDisplay");
7
8
  const dbgate_sqltree_1 = require("dbgate-sqltree");
8
9
  const TableGridDisplay_1 = require("./TableGridDisplay");
@@ -123,8 +124,8 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
123
124
  const select = this.getSelect();
124
125
  if (!select)
125
126
  return null;
126
- select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyEqualCondition());
127
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
127
+ select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyEqualCondition());
128
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
128
129
  return sql;
129
130
  }
130
131
  getCountSelect() {
@@ -148,7 +149,7 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
148
149
  const select = this.getCountSelect();
149
150
  if (!select)
150
151
  return null;
151
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
152
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
152
153
  return sql;
153
154
  }
154
155
  getBeforeCountQuery() {
@@ -157,8 +158,8 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
157
158
  const select = this.getCountSelect();
158
159
  if (!select)
159
160
  return null;
160
- select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
161
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
161
+ select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('<'));
162
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
162
163
  return sql;
163
164
  }
164
165
  navigate(row) {
@@ -169,7 +170,7 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
169
170
  if (!row)
170
171
  return false;
171
172
  const formViewKey = this.extractKey(row);
172
- return json_stable_stringify_1.default(formViewKey) == json_stable_stringify_1.default(this.config.formViewKey);
173
+ return (0, json_stable_stringify_1.default)(formViewKey) == (0, json_stable_stringify_1.default)(this.config.formViewKey);
173
174
  }
174
175
  navigateRowQuery(commmand) {
175
176
  if (!this.driver)
@@ -195,14 +196,14 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
195
196
  break;
196
197
  case 'previous':
197
198
  select.orderBy = getOrderBy('DESC');
198
- select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
199
+ select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('<'));
199
200
  break;
200
201
  case 'next':
201
202
  select.orderBy = getOrderBy('ASC');
202
- select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('>'));
203
+ select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('>'));
203
204
  break;
204
205
  }
205
- const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
206
+ const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
206
207
  return sql;
207
208
  }
208
209
  getChangeSetRow(row) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableGridDisplay = void 0;
3
4
  const dbgate_tools_1 = require("dbgate-tools");
4
5
  const GridDisplay_1 = require("./GridDisplay");
5
6
  class TableGridDisplay extends GridDisplay_1.GridDisplay {
@@ -36,8 +37,8 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
36
37
  this.dbinfo.tables.find(x => x.pureName == pureName && x.schemaName == schemaName));
37
38
  }
38
39
  getDisplayColumns(table, parentPath) {
39
- var _a, _b, _c;
40
- return (((_c = (_b = (_a = table) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => this.getDisplayColumn(table, col, parentPath))) === null || _c === void 0 ? void 0 : _c.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnName: col.foreignKey ? `hint_${col.uniqueName}` : null, isExpandable: !!col.foreignKey })))) || []);
40
+ 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 })))) || []);
41
42
  }
42
43
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
43
44
  for (const column of columns) {
@@ -95,7 +96,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
95
96
  }
96
97
  const table = this.getFkTarget(column);
97
98
  if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
98
- const hintColumn = table.columns.find(x => { var _a, _b, _c; return (_c = (_b = (_a = x) === null || _a === void 0 ? void 0 : _a.dataType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === null || _c === void 0 ? void 0 : _c.includes('char'); });
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'); });
99
100
  if (hintColumn) {
100
101
  const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
101
102
  this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
@@ -148,7 +149,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
148
149
  return select;
149
150
  }
150
151
  getColumns(columnFilter) {
151
- return this.enrichExpandedColumns(this.columns.filter(col => dbgate_tools_1.filterName(columnFilter, col.columnName)));
152
+ return this.enrichExpandedColumns(this.columns.filter(col => (0, dbgate_tools_1.filterName)(columnFilter, col.columnName)));
152
153
  }
153
154
  getDisplayColumn(table, col, parentPath) {
154
155
  const uniquePath = [...parentPath, col.columnName];
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewGridDisplay = void 0;
3
4
  const GridDisplay_1 = require("./GridDisplay");
4
5
  class ViewGridDisplay extends GridDisplay_1.GridDisplay {
5
6
  constructor(view, driver, config, setConfig, cache, setCache, serverVersion) {
@@ -13,8 +14,8 @@ class ViewGridDisplay extends GridDisplay_1.GridDisplay {
13
14
  this.supportsReload = true;
14
15
  }
15
16
  getDisplayColumns(view) {
16
- var _a, _b, _c;
17
- return (((_c = (_b = (_a = view) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => this.getDisplayColumn(view, col))) === null || _c === void 0 ? void 0 : _c.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
17
+ var _a, _b;
18
+ return (((_b = (_a = view === null || view === void 0 ? void 0 : view.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(view, col))) === null || _b === void 0 ? void 0 : _b.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
18
19
  }
19
20
  getDisplayColumn(view, col) {
20
21
  const uniquePath = [col.columnName];
@@ -0,0 +1,8 @@
1
+ import { Command } from 'dbgate-sqltree';
2
+ import { DatabaseInfo } from 'dbgate-types';
3
+ import { ChangeSet } from './ChangeSet';
4
+ export interface ChangeSetDeleteCascade {
5
+ title: string;
6
+ commands: Command[];
7
+ }
8
+ export declare function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): ChangeSetDeleteCascade[];
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDeleteCascades = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const ChangeSet_1 = require("./ChangeSet");
9
+ // function getDeleteScript()
10
+ function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo) {
11
+ if (result.find(x => x.title == table.pureName))
12
+ return;
13
+ const dependencies = allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName);
14
+ for (const fk of dependencies) {
15
+ const depTable = dbinfo.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
16
+ const subFkPath = [...fkPath, fk];
17
+ if (depTable && depTable.pureName != baseCmd.pureName) {
18
+ processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo);
19
+ }
20
+ const refCmd = {
21
+ commandType: 'delete',
22
+ from: {
23
+ name: {
24
+ pureName: fk.pureName,
25
+ schemaName: fk.schemaName,
26
+ },
27
+ },
28
+ where: {
29
+ conditionType: 'exists',
30
+ subQuery: {
31
+ commandType: 'select',
32
+ selectAll: true,
33
+ from: {
34
+ name: {
35
+ pureName: fk.pureName,
36
+ schemaName: fk.schemaName,
37
+ },
38
+ alias: 't0',
39
+ relations: subFkPath.map((fkItem, fkIndex) => ({
40
+ joinType: 'INNER JOIN',
41
+ alias: `t${fkIndex + 1}`,
42
+ name: {
43
+ pureName: fkItem.refTableName,
44
+ schemaName: fkItem.refSchemaName,
45
+ },
46
+ conditions: fkItem.columns.map(column => ({
47
+ conditionType: 'binary',
48
+ operator: '=',
49
+ left: {
50
+ exprType: 'column',
51
+ columnName: column.columnName,
52
+ source: { alias: `t${fkIndex}` },
53
+ },
54
+ right: {
55
+ exprType: 'column',
56
+ columnName: column.refColumnName,
57
+ source: { alias: `t${fkIndex + 1}` },
58
+ },
59
+ })),
60
+ })),
61
+ },
62
+ where: {
63
+ conditionType: 'and',
64
+ conditions: [
65
+ (0, ChangeSet_1.extractChangeSetCondition)(baseCmd, `t${subFkPath.length}`),
66
+ // @ts-ignore
67
+ ...table.primaryKey.columns.map(column => ({
68
+ conditionType: 'binary',
69
+ operator: '=',
70
+ left: {
71
+ exprType: 'column',
72
+ columnName: column.columnName,
73
+ source: { alias: 't0' },
74
+ },
75
+ right: {
76
+ exprType: 'column',
77
+ columnName: column.columnName,
78
+ source: {
79
+ name: fk,
80
+ },
81
+ },
82
+ })),
83
+ ],
84
+ },
85
+ },
86
+ },
87
+ };
88
+ let resItem = result.find(x => x.title == fk.pureName);
89
+ if (!resItem) {
90
+ resItem = {
91
+ title: fk.pureName,
92
+ commands: [],
93
+ };
94
+ result.push(resItem);
95
+ }
96
+ resItem.commands.push(refCmd);
97
+ }
98
+ }
99
+ function getDeleteCascades(changeSet, dbinfo) {
100
+ const result = [];
101
+ const allForeignKeys = lodash_1.default.flatten(dbinfo.tables.map(x => x.foreignKeys));
102
+ for (const baseCmd of changeSet.deletes) {
103
+ const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
104
+ if (!table.primaryKey)
105
+ continue;
106
+ processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo);
107
+ // let resItem = result.find(x => x.title == baseCmd.pureName);
108
+ // if (!resItem) {
109
+ // resItem = {
110
+ // title: baseCmd.pureName,
111
+ // commands: [],
112
+ // };
113
+ // result.push(resItem);
114
+ // }
115
+ // resItem.commands.push(changeSetDeleteToSql(baseCmd));
116
+ }
117
+ return result;
118
+ }
119
+ exports.getDeleteCascades = getDeleteCascades;
package/lib/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export * from './runMacro';
11
11
  export * from './FormViewDisplay';
12
12
  export * from './TableFormViewDisplay';
13
13
  export * from './CollectionGridDisplay';
14
+ export * from './deleteCascade';
package/lib/index.js CHANGED
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
5
12
  Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./GridDisplay"));
7
- __export(require("./GridConfig"));
8
- __export(require("./TableGridDisplay"));
9
- __export(require("./ViewGridDisplay"));
10
- __export(require("./JslGridDisplay"));
11
- __export(require("./ChangeSet"));
12
- __export(require("./FreeTableGridDisplay"));
13
- __export(require("./FreeTableModel"));
14
- __export(require("./runMacro"));
15
- __export(require("./FormViewDisplay"));
16
- __export(require("./TableFormViewDisplay"));
17
- __export(require("./CollectionGridDisplay"));
13
+ __exportStar(require("./GridDisplay"), exports);
14
+ __exportStar(require("./GridConfig"), exports);
15
+ __exportStar(require("./TableGridDisplay"), exports);
16
+ __exportStar(require("./ViewGridDisplay"), exports);
17
+ __exportStar(require("./JslGridDisplay"), exports);
18
+ __exportStar(require("./ChangeSet"), exports);
19
+ __exportStar(require("./FreeTableGridDisplay"), exports);
20
+ __exportStar(require("./FreeTableModel"), exports);
21
+ __exportStar(require("./MacroDefinition"), exports);
22
+ __exportStar(require("./runMacro"), exports);
23
+ __exportStar(require("./FormViewDisplay"), exports);
24
+ __exportStar(require("./TableFormViewDisplay"), exports);
25
+ __exportStar(require("./CollectionGridDisplay"), exports);
26
+ __exportStar(require("./deleteCascade"), exports);
package/lib/runMacro.js CHANGED
@@ -3,6 +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.runMacroOnChangeSet = exports.runMacroOnValue = exports.compileMacroFunction = exports.runMacro = void 0;
6
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  const v1_1 = __importDefault(require("uuid/v1"));
8
9
  const v4_1 = __importDefault(require("uuid/v4"));
@@ -177,7 +178,7 @@ function runMacroOnChangeSet(macro, macroArgs, selectedCells, changeSet, display
177
178
  for (const cell of selectedCells) {
178
179
  const definition = display.getChangeSetField(cell.rowData, cell.column, undefined);
179
180
  const macroResult = runMacroOnValue(compiledMacroFunc, macroArgs, cell.value, cell.row, cell.rowData, cell.column, errors);
180
- res = ChangeSet_1.setChangeSetValue(res, definition, macroResult);
181
+ res = (0, ChangeSet_1.setChangeSetValue)(res, definition, macroResult);
181
182
  }
182
183
  return res;
183
184
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.3.0",
2
+ "version": "4.3.1",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -11,12 +11,12 @@
11
11
  "lib"
12
12
  ],
13
13
  "dependencies": {
14
- "dbgate-sqltree": "^4.3.0",
15
- "dbgate-filterparser": "^4.3.0"
14
+ "dbgate-sqltree": "^4.3.1",
15
+ "dbgate-filterparser": "^4.3.1"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.3.0",
18
+ "dbgate-types": "^4.3.1",
19
19
  "@types/node": "^13.7.0",
20
- "typescript": "^3.7.5"
20
+ "typescript": "^4.4.3"
21
21
  }
22
22
  }