dbgate-datalib 5.2.2 → 5.2.4-alpha.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.
@@ -14,9 +14,9 @@ export declare abstract class PerspectiveTreeNode {
14
14
  setConfig: ChangePerspectiveConfigFunc;
15
15
  parentNode: PerspectiveTreeNode;
16
16
  dataProvider: PerspectiveDataProvider;
17
- databaseConfig: PerspectiveDatabaseConfig;
17
+ defaultDatabaseConfig: PerspectiveDatabaseConfig;
18
18
  designerId: string;
19
- constructor(dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, parentNode: PerspectiveTreeNode, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, designerId: string);
19
+ constructor(dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, parentNode: PerspectiveTreeNode, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, designerId: string);
20
20
  readonly nodeConfig: PerspectiveNodeConfig;
21
21
  parentNodeConfig: PerspectiveNodeConfig;
22
22
  abstract get title(): any;
@@ -33,6 +33,7 @@ export declare abstract class PerspectiveTreeNode {
33
33
  get namedObject(): NamedObjectInfo;
34
34
  get tableNodeOrParent(): PerspectiveTableNode;
35
35
  get engineType(): PerspectiveDatabaseEngineType;
36
+ get databaseConfig(): PerspectiveDatabaseConfig;
36
37
  abstract getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
37
38
  get isRoot(): boolean;
38
39
  get rootNode(): PerspectiveTreeNode;
@@ -72,11 +73,13 @@ export declare abstract class PerspectiveTreeNode {
72
73
  includeInNodeSet(field: 'expandedColumns' | 'uncheckedColumns' | 'checkedColumns', isIncluded: boolean): void;
73
74
  getFilter(): string;
74
75
  getDataLoadColumns(): any[];
76
+ getMutliColumnSqlCondition(source: any): Condition;
77
+ getMutliColumnMongoCondition(): {};
75
78
  getChildrenSqlCondition(source?: any): Condition;
76
79
  getChildrenMongoCondition(source?: any): {};
77
80
  getOrderBy(table: TableInfo | ViewInfo | CollectionInfo): PerspectiveDataLoadProps['orderBy'];
78
81
  getBaseTables(): any[];
79
- getBaseTableFromThis(): any;
82
+ getBaseTableFromThis(): TableInfo | ViewInfo | CollectionInfo;
80
83
  get filterInfo(): PerspectiveFilterColumnInfo;
81
84
  findChildNodeByUniquePath(uniquePath: string[]): any;
82
85
  findNodeByDesignerId(designerId: string): PerspectiveTreeNode;
@@ -94,7 +97,7 @@ export declare class PerspectiveTableColumnNode extends PerspectiveTreeNode {
94
97
  refTable: TableInfo;
95
98
  isView: boolean;
96
99
  isTable: boolean;
97
- constructor(column: ColumnInfo, table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
100
+ constructor(column: ColumnInfo, table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
98
101
  get engineType(): PerspectiveDatabaseEngineType;
99
102
  matchChildRow(parentRow: any, childRow: any): boolean;
100
103
  getChildMatchColumns(): string[];
@@ -136,7 +139,7 @@ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
136
139
  tableColumn: ColumnInfo;
137
140
  foreignKey: ForeignKeyInfo;
138
141
  refTable: TableInfo;
139
- constructor(table: TableInfo | ViewInfo | CollectionInfo, column: PerspectiveDataPatternColumn, tableColumn: ColumnInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
142
+ constructor(table: TableInfo | ViewInfo | CollectionInfo, column: PerspectiveDataPatternColumn, tableColumn: ColumnInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
140
143
  get isChildColumn(): boolean;
141
144
  get findByDesignerIdWithoutDesignerId(): boolean;
142
145
  getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
@@ -159,7 +162,7 @@ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
159
162
  export declare class PerspectiveTableNode extends PerspectiveTreeNode {
160
163
  table: TableInfo | ViewInfo | CollectionInfo;
161
164
  dataProvider: PerspectiveDataProvider;
162
- constructor(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
165
+ constructor(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
163
166
  get engineType(): PerspectiveDatabaseEngineType;
164
167
  getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
165
168
  get codeName(): string;
@@ -182,7 +185,7 @@ export declare class PerspectiveTableReferenceNode extends PerspectiveTableNode
182
185
  foreignKey: ForeignKeyInfo;
183
186
  dataProvider: PerspectiveDataProvider;
184
187
  isMultiple: boolean;
185
- constructor(foreignKey: ForeignKeyInfo, table: TableInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, isMultiple: boolean, parentNode: PerspectiveTreeNode, designerId: string);
188
+ constructor(foreignKey: ForeignKeyInfo, table: TableInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, isMultiple: boolean, parentNode: PerspectiveTreeNode, designerId: string);
186
189
  matchChildRow(parentRow: any, childRow: any): boolean;
187
190
  getChildMatchColumns(): string[];
188
191
  getParentMatchColumns(): string[];
@@ -198,7 +201,7 @@ export declare class PerspectiveTableReferenceNode extends PerspectiveTableNode
198
201
  export declare class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
199
202
  customJoin: PerspectiveCustomJoinConfig;
200
203
  dataProvider: PerspectiveDataProvider;
201
- constructor(customJoin: PerspectiveCustomJoinConfig, table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
204
+ constructor(customJoin: PerspectiveCustomJoinConfig, table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
202
205
  matchChildRow(parentRow: any, childRow: any): boolean;
203
206
  getChildMatchColumns(): string[];
204
207
  getParentMatchColumns(): string[];
@@ -210,4 +213,4 @@ export declare class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode
210
213
  toggleChecked(value?: boolean): void;
211
214
  getParentJoinCondition(alias: string, parentAlias: string): Condition[];
212
215
  }
213
- export declare function getTableChildPerspectiveNodes(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode): any[];
216
+ export declare function getTableChildPerspectiveNodes(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, defaultDatabaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode): any[];
@@ -40,13 +40,13 @@ const perspectiveTools_1 = require("./perspectiveTools");
40
40
  // return res;
41
41
  // }
42
42
  class PerspectiveTreeNode {
43
- constructor(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId) {
43
+ constructor(dbs, config, setConfig, parentNode, dataProvider, defaultDatabaseConfig, designerId) {
44
44
  this.dbs = dbs;
45
45
  this.config = config;
46
46
  this.setConfig = setConfig;
47
47
  this.parentNode = parentNode;
48
48
  this.dataProvider = dataProvider;
49
- this.databaseConfig = databaseConfig;
49
+ this.defaultDatabaseConfig = defaultDatabaseConfig;
50
50
  this.designerId = designerId;
51
51
  this.childNodesCache = null;
52
52
  this.nodeConfig = config.nodes.find(x => x.designerId == designerId);
@@ -85,6 +85,15 @@ class PerspectiveTreeNode {
85
85
  get engineType() {
86
86
  return null;
87
87
  }
88
+ get databaseConfig() {
89
+ var _a, _b, _c, _d;
90
+ const res = Object.assign({}, this.defaultDatabaseConfig);
91
+ if ((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.conid)
92
+ res.conid = (_b = this.nodeConfig) === null || _b === void 0 ? void 0 : _b.conid;
93
+ if ((_c = this.nodeConfig) === null || _c === void 0 ? void 0 : _c.database)
94
+ res.database = (_d = this.nodeConfig) === null || _d === void 0 ? void 0 : _d.database;
95
+ return res;
96
+ }
88
97
  get isRoot() {
89
98
  return this.parentNode == null;
90
99
  }
@@ -264,10 +273,69 @@ class PerspectiveTreeNode {
264
273
  .map(x => x.columnName),
265
274
  ]));
266
275
  }
276
+ getMutliColumnSqlCondition(source) {
277
+ var _a, _b;
278
+ if (!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.multiColumnFilter))
279
+ return null;
280
+ const base = this.getBaseTableFromThis();
281
+ if (!base)
282
+ return null;
283
+ try {
284
+ const condition = (0, dbgate_filterparser_1.parseFilter)((_b = this.nodeConfig) === null || _b === void 0 ? void 0 : _b.multiColumnFilter, 'string');
285
+ if (condition) {
286
+ const orCondition = {
287
+ conditionType: 'or',
288
+ conditions: [],
289
+ };
290
+ for (const column of base.columns || []) {
291
+ orCondition.conditions.push((0, cloneDeepWith_1.default)(condition, (expr) => {
292
+ if (expr.exprType == 'placeholder') {
293
+ return {
294
+ exprType: 'column',
295
+ alias: source,
296
+ columnName: column.columnName,
297
+ };
298
+ }
299
+ }));
300
+ }
301
+ if (orCondition.conditions.length > 0) {
302
+ return orCondition;
303
+ }
304
+ }
305
+ }
306
+ catch (err) {
307
+ console.warn(err.message);
308
+ }
309
+ return null;
310
+ }
311
+ getMutliColumnMongoCondition() {
312
+ var _a, _b, _c, _d;
313
+ if (!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.multiColumnFilter))
314
+ return null;
315
+ const pattern = (_c = (_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.dataPatterns) === null || _c === void 0 ? void 0 : _c[this.designerId];
316
+ if (!pattern)
317
+ return null;
318
+ const condition = (0, dbgate_filterparser_1.parseFilter)((_d = this.nodeConfig) === null || _d === void 0 ? void 0 : _d.multiColumnFilter, 'mongo');
319
+ if (!condition)
320
+ return null;
321
+ const res = pattern.columns.map(col => {
322
+ return (0, cloneDeepWith_1.default)(condition, expr => {
323
+ if (expr.__placeholder__) {
324
+ return {
325
+ [col.name]: expr.__placeholder__,
326
+ };
327
+ }
328
+ });
329
+ });
330
+ return {
331
+ $or: res,
332
+ };
333
+ }
267
334
  getChildrenSqlCondition(source = null) {
268
335
  const conditions = (0, compact_1.default)([
269
336
  ...this.childNodes.map(x => x.parseFilterCondition(source)),
270
337
  ...this.buildParentFilterConditions(),
338
+ this.getMutliColumnSqlCondition(source),
271
339
  ]);
272
340
  if (conditions.length == 0) {
273
341
  return null;
@@ -281,7 +349,10 @@ class PerspectiveTreeNode {
281
349
  };
282
350
  }
283
351
  getChildrenMongoCondition(source = null) {
284
- const conditions = (0, compact_1.default)([...this.childNodes.map(x => x.parseFilterCondition(source))]);
352
+ const conditions = (0, compact_1.default)([
353
+ ...this.childNodes.map(x => x.parseFilterCondition(source)),
354
+ this.getMutliColumnMongoCondition(),
355
+ ]);
285
356
  if (conditions.length == 0) {
286
357
  return null;
287
358
  }
@@ -443,9 +514,9 @@ class PerspectiveTreeNode {
443
514
  }
444
515
  exports.PerspectiveTreeNode = PerspectiveTreeNode;
445
516
  class PerspectiveTableColumnNode extends PerspectiveTreeNode {
446
- constructor(column, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
517
+ constructor(column, table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId) {
447
518
  var _a, _b, _c, _d, _e;
448
- super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
519
+ super(dbs, config, setConfig, parentNode, dataProvider, defaultDatabaseConfig, designerId);
449
520
  this.column = column;
450
521
  this.table = table;
451
522
  this.isTable = !!((_b = (_a = this.db) === null || _a === void 0 ? void 0 : _a.tables) === null || _b === void 0 ? void 0 : _b.find(x => x.schemaName == table.schemaName && x.pureName == table.pureName));
@@ -576,7 +647,7 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
576
647
  if (!this.foreignKey)
577
648
  return [];
578
649
  const tbl = (_b = (_a = this === null || this === void 0 ? void 0 : this.db) === null || _a === void 0 ? void 0 : _a.tables) === null || _b === void 0 ? void 0 : _b.find(x => { var _a, _b; return x.pureName == ((_a = this.foreignKey) === null || _a === void 0 ? void 0 : _a.refTableName) && x.schemaName == ((_b = this.foreignKey) === null || _b === void 0 ? void 0 : _b.refSchemaName); });
579
- return getTableChildPerspectiveNodes(tbl, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this);
650
+ return getTableChildPerspectiveNodes(tbl, this.dbs, this.config, this.setConfig, this.dataProvider, this.defaultDatabaseConfig, this);
580
651
  }
581
652
  getBaseTableFromThis() {
582
653
  return this.refTable;
@@ -637,9 +708,9 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
637
708
  }
638
709
  exports.PerspectiveTableColumnNode = PerspectiveTableColumnNode;
639
710
  class PerspectivePatternColumnNode extends PerspectiveTreeNode {
640
- constructor(table, column, tableColumn, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
711
+ constructor(table, column, tableColumn, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId) {
641
712
  var _a;
642
- super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
713
+ super(dbs, config, setConfig, parentNode, dataProvider, defaultDatabaseConfig, designerId);
643
714
  this.table = table;
644
715
  this.column = column;
645
716
  this.tableColumn = tableColumn;
@@ -745,7 +816,7 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
745
816
  return true;
746
817
  }
747
818
  generatePatternChildNodes() {
748
- return this.column.columns.map(column => new PerspectivePatternColumnNode(this.table, column, this.tableColumn, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this, null));
819
+ return this.column.columns.map(column => new PerspectivePatternColumnNode(this.table, column, this.tableColumn, this.dbs, this.config, this.setConfig, this.dataProvider, this.defaultDatabaseConfig, this, null));
749
820
  }
750
821
  hasCheckedJoinChild() {
751
822
  for (const node of this.childNodes) {
@@ -786,7 +857,7 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
786
857
  continue;
787
858
  }
788
859
  // console.log('CP2');
789
- const newConfig = Object.assign({}, this.databaseConfig);
860
+ const newConfig = Object.assign({}, this.defaultDatabaseConfig);
790
861
  if (node.conid)
791
862
  newConfig.conid = node.conid;
792
863
  if (node.database)
@@ -809,7 +880,7 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
809
880
  : ref.columns.map(col => ({ baseColumnName: col.target, refColumnName: col.source })),
810
881
  };
811
882
  if (table || view || collection) {
812
- customs.push(new PerspectiveCustomJoinTreeNode(join, table || view || collection, this.dbs, this.config, this.setConfig, this.dataProvider, newConfig, this, node.designerId));
883
+ customs.push(new PerspectiveCustomJoinTreeNode(join, table || view || collection, this.dbs, this.config, this.setConfig, this.dataProvider, this.defaultDatabaseConfig, this, node.designerId));
813
884
  }
814
885
  }
815
886
  }
@@ -860,8 +931,8 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
860
931
  }
861
932
  exports.PerspectivePatternColumnNode = PerspectivePatternColumnNode;
862
933
  class PerspectiveTableNode extends PerspectiveTreeNode {
863
- constructor(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
864
- super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
934
+ constructor(table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId) {
935
+ super(dbs, config, setConfig, parentNode, dataProvider, defaultDatabaseConfig, designerId);
865
936
  this.table = table;
866
937
  this.dataProvider = dataProvider;
867
938
  }
@@ -893,7 +964,7 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
893
964
  return true;
894
965
  }
895
966
  generateChildNodes() {
896
- return getTableChildPerspectiveNodes(this.table, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this);
967
+ return getTableChildPerspectiveNodes(this.table, this.dbs, this.config, this.setConfig, this.dataProvider, this.defaultDatabaseConfig, this);
897
968
  }
898
969
  get icon() {
899
970
  return 'img table';
@@ -922,8 +993,8 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
922
993
  }
923
994
  exports.PerspectiveTableNode = PerspectiveTableNode;
924
995
  class PerspectiveTableReferenceNode extends PerspectiveTableNode {
925
- constructor(foreignKey, table, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode, designerId) {
926
- super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
996
+ constructor(foreignKey, table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, isMultiple, parentNode, designerId) {
997
+ super(table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId);
927
998
  this.foreignKey = foreignKey;
928
999
  this.dataProvider = dataProvider;
929
1000
  this.isMultiple = isMultiple;
@@ -1010,8 +1081,8 @@ class PerspectiveTableReferenceNode extends PerspectiveTableNode {
1010
1081
  }
1011
1082
  exports.PerspectiveTableReferenceNode = PerspectiveTableReferenceNode;
1012
1083
  class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
1013
- constructor(customJoin, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
1014
- super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
1084
+ constructor(customJoin, table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId) {
1085
+ super(table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId);
1015
1086
  this.customJoin = customJoin;
1016
1087
  this.dataProvider = dataProvider;
1017
1088
  }
@@ -1153,7 +1224,7 @@ function findDesignerIdForNode(config, parentNode, nodeCreateFunc) {
1153
1224
  }
1154
1225
  return node;
1155
1226
  }
1156
- function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
1227
+ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode) {
1157
1228
  var _a, _b, _c, _d, _e, _f, _g, _h;
1158
1229
  if (!table)
1159
1230
  return [];
@@ -1163,10 +1234,10 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
1163
1234
  const columnNodes = ((_b = tableOrView === null || tableOrView === void 0 ? void 0 : tableOrView.columns) === null || _b === void 0 ? void 0 : _b.map(col => findDesignerIdForNode(config, parentNode, designerId => {
1164
1235
  var _a, _b, _c;
1165
1236
  return ((_b = (_a = pattern === null || pattern === void 0 ? void 0 : pattern.columns) === null || _a === void 0 ? void 0 : _a.find(x => x.name == col.columnName)) === null || _b === void 0 ? void 0 : _b.types.includes('json'))
1166
- ? new PerspectivePatternColumnNode(table, (_c = pattern === null || pattern === void 0 ? void 0 : pattern.columns) === null || _c === void 0 ? void 0 : _c.find(x => x.name == col.columnName), col, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId)
1167
- : new PerspectiveTableColumnNode(col, tableOrView, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
1237
+ ? new PerspectivePatternColumnNode(table, (_c = pattern === null || pattern === void 0 ? void 0 : pattern.columns) === null || _c === void 0 ? void 0 : _c.find(x => x.name == col.columnName), col, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId)
1238
+ : new PerspectiveTableColumnNode(col, tableOrView, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId);
1168
1239
  }))) ||
1169
- ((_c = pattern === null || pattern === void 0 ? void 0 : pattern.columns) === null || _c === void 0 ? void 0 : _c.map(col => findDesignerIdForNode(config, parentNode, designerId => new PerspectivePatternColumnNode(table, col, null, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId)))) ||
1240
+ ((_c = pattern === null || pattern === void 0 ? void 0 : pattern.columns) === null || _c === void 0 ? void 0 : _c.map(col => findDesignerIdForNode(config, parentNode, designerId => new PerspectivePatternColumnNode(table, col, null, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, designerId)))) ||
1170
1241
  [];
1171
1242
  // if (!columnNodes.find(x => x.isChecked)) {
1172
1243
  // const circularColumns = columnNodes.filter(x => x.isCircular).map(x => x.columnName);
@@ -1185,7 +1256,7 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
1185
1256
  const tbl = db.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
1186
1257
  if (tbl) {
1187
1258
  const isMultiple = (table === null || table === void 0 ? void 0 : table.dependencies.filter(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName).length) >= 2;
1188
- dependencies.push(findDesignerIdForNode(config, parentNode, designerId => new PerspectiveTableReferenceNode(fk, tbl, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode, designerId)));
1259
+ dependencies.push(findDesignerIdForNode(config, parentNode, designerId => new PerspectiveTableReferenceNode(fk, tbl, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, isMultiple, parentNode, designerId)));
1189
1260
  }
1190
1261
  }
1191
1262
  }
@@ -1202,7 +1273,7 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
1202
1273
  if (ref.columns.find(x => x.source.includes('::') || x.target.includes('::'))) {
1203
1274
  continue;
1204
1275
  }
1205
- const newConfig = Object.assign({}, databaseConfig);
1276
+ const newConfig = Object.assign({}, defaultDatabaseConfig);
1206
1277
  if (node.conid)
1207
1278
  newConfig.conid = node.conid;
1208
1279
  if (node.database)
@@ -1225,7 +1296,7 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
1225
1296
  : ref.columns.map(col => ({ baseColumnName: col.target, refColumnName: col.source })),
1226
1297
  };
1227
1298
  if (table || view || collection) {
1228
- customs.push(new PerspectiveCustomJoinTreeNode(join, table || view || collection, dbs, config, setConfig, dataProvider, newConfig, parentNode, node.designerId));
1299
+ customs.push(new PerspectiveCustomJoinTreeNode(join, table || view || collection, dbs, config, setConfig, dataProvider, defaultDatabaseConfig, parentNode, node.designerId));
1229
1300
  }
1230
1301
  }
1231
1302
  }
@@ -39,7 +39,7 @@ function processDependencies(changeSet, result, allForeignKeys, fkPath, table, b
39
39
  schemaName: fk.schemaName,
40
40
  },
41
41
  alias: 't0',
42
- relations: subFkPath.map((fkItem, fkIndex) => ({
42
+ relations: [...subFkPath].reverse().map((fkItem, fkIndex) => ({
43
43
  joinType: 'INNER JOIN',
44
44
  alias: `t${fkIndex + 1}`,
45
45
  name: {
@@ -106,7 +106,17 @@ function getDeleteCascades(changeSet, dbinfo) {
106
106
  const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
107
107
  if (!table.primaryKey)
108
108
  continue;
109
- processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo, [table.pureName]);
109
+ const itemResult = [];
110
+ processDependencies(changeSet, itemResult, allForeignKeys, [], table, baseCmd, dbinfo, [table.pureName]);
111
+ for (const item of itemResult) {
112
+ const existing = result.find(x => x.title == item.title);
113
+ if (existing) {
114
+ existing.commands.push(...item.commands);
115
+ }
116
+ else {
117
+ result.push(item);
118
+ }
119
+ }
110
120
  // let resItem = result.find(x => x.title == baseCmd.pureName);
111
121
  // if (!resItem) {
112
122
  // resItem = {
package/lib/index.d.ts CHANGED
@@ -6,8 +6,6 @@ export * from './TableGridDisplay';
6
6
  export * from './ViewGridDisplay';
7
7
  export * from './JslGridDisplay';
8
8
  export * from './ChangeSet';
9
- export * from './FreeTableGridDisplay';
10
- export * from './FreeTableModel';
11
9
  export * from './MacroDefinition';
12
10
  export * from './runMacro';
13
11
  export * from './CollectionGridDisplay';
@@ -20,3 +18,4 @@ export * from './processPerspectiveDefaultColunns';
20
18
  export * from './PerspectiveDataPattern';
21
19
  export * from './PerspectiveDataLoader';
22
20
  export * from './perspectiveTools';
21
+ export * from './DataDuplicator';
package/lib/index.js CHANGED
@@ -22,12 +22,8 @@ __exportStar(require("./TableGridDisplay"), exports);
22
22
  __exportStar(require("./ViewGridDisplay"), exports);
23
23
  __exportStar(require("./JslGridDisplay"), exports);
24
24
  __exportStar(require("./ChangeSet"), exports);
25
- __exportStar(require("./FreeTableGridDisplay"), exports);
26
- __exportStar(require("./FreeTableModel"), exports);
27
25
  __exportStar(require("./MacroDefinition"), exports);
28
26
  __exportStar(require("./runMacro"), exports);
29
- // export * from './FormViewDisplay';
30
- // export * from './TableFormViewDisplay';
31
27
  __exportStar(require("./CollectionGridDisplay"), exports);
32
28
  __exportStar(require("./deleteCascade"), exports);
33
29
  __exportStar(require("./PerspectiveDisplay"), exports);
@@ -38,3 +34,4 @@ __exportStar(require("./processPerspectiveDefaultColunns"), exports);
38
34
  __exportStar(require("./PerspectiveDataPattern"), exports);
39
35
  __exportStar(require("./PerspectiveDataLoader"), exports);
40
36
  __exportStar(require("./perspectiveTools"), exports);
37
+ __exportStar(require("./DataDuplicator"), exports);
package/lib/runMacro.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { FreeTableModel } from './FreeTableModel';
2
1
  import { MacroDefinition, MacroSelectedCell } from './MacroDefinition';
3
2
  import { ChangeSet } from './ChangeSet';
4
3
  import { GridDisplay } from './GridDisplay';
5
- export declare function runMacro(macro: MacroDefinition, macroArgs: {}, data: FreeTableModel, preview: boolean, selectedCells: MacroSelectedCell[], errors?: string[]): FreeTableModel;
6
4
  export declare function compileMacroFunction(macro: MacroDefinition, errors?: any[]): any;
7
- export declare function runMacroOnValue(compiledFunc: any, macroArgs: any, value: any, rowIndex: any, row: any, column: any, errors?: any[]): any;
8
- export declare function runMacroOnChangeSet(macro: MacroDefinition, macroArgs: {}, selectedCells: MacroSelectedCell[], changeSet: ChangeSet, display: GridDisplay): ChangeSet;
5
+ export declare function runMacroOnValue(compiledFunc: any, macroArgs: any, value: any, rowIndex: number, row: any, column: string, errors?: any[]): any;
6
+ export declare function runMacroOnRow(compiledFunc: any, macroArgs: any, rowIndex: number, row: any, columns: string[], errors?: any[]): any;
7
+ export declare function runMacroOnChangeSet(macro: MacroDefinition, macroArgs: {}, selectedCells: MacroSelectedCell[], changeSet: ChangeSet, display: GridDisplay, useRowIndexInsteaOfCondition: boolean): ChangeSet;
package/lib/runMacro.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.runMacroOnChangeSet = exports.runMacroOnValue = exports.compileMacroFunction = exports.runMacro = void 0;
6
+ exports.runMacroOnChangeSet = exports.runMacroOnRow = exports.runMacroOnValue = exports.compileMacroFunction = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const v1_1 = __importDefault(require("uuid/v1"));
9
9
  const v4_1 = __importDefault(require("uuid/v4"));
@@ -15,13 +15,8 @@ const getMacroFunction = {
15
15
  ${code}
16
16
  }
17
17
  `,
18
- transformRows: code => `
19
- (rows, args, modules, selectedCells, cols, columns) => {
20
- ${code}
21
- }
22
- `,
23
- transformData: code => `
24
- (rows, args, modules, selectedCells, cols, columns) => {
18
+ transformRow: code => `
19
+ (row, args, modules, rowIndex, columns) => {
25
20
  ${code}
26
21
  }
27
22
  `,
@@ -32,116 +27,6 @@ const modules = {
32
27
  uuidv4: v4_1.default,
33
28
  moment: moment_1.default,
34
29
  };
35
- function runTramsformValue(func, macroArgs, data, preview, selectedCells, errors = []) {
36
- const selectedRows = lodash_1.default.groupBy(selectedCells, 'row');
37
- const rows = data.rows.map((row, rowIndex) => {
38
- const selectedRow = selectedRows[rowIndex];
39
- if (selectedRow) {
40
- const modifiedFields = [];
41
- let res = null;
42
- for (const cell of selectedRow) {
43
- const { column } = cell;
44
- const oldValue = row[column];
45
- let newValue = oldValue;
46
- try {
47
- newValue = func(oldValue, macroArgs, modules, rowIndex, row, column);
48
- }
49
- catch (err) {
50
- errors.push(`Error processing column ${column} on row ${rowIndex}: ${err.message}`);
51
- }
52
- if (newValue != oldValue) {
53
- if (res == null) {
54
- res = Object.assign({}, row);
55
- }
56
- res[column] = newValue;
57
- if (preview)
58
- modifiedFields.push(column);
59
- }
60
- }
61
- if (res) {
62
- if (modifiedFields.length > 0) {
63
- return Object.assign(Object.assign({}, res), { __modifiedFields: new Set(modifiedFields) });
64
- }
65
- return res;
66
- }
67
- return row;
68
- }
69
- else {
70
- return row;
71
- }
72
- });
73
- return {
74
- structure: data.structure,
75
- rows,
76
- };
77
- }
78
- function removePreviewRowFlags(rows) {
79
- rows = rows.filter(row => row.__rowStatus != 'deleted');
80
- rows = rows.map(row => {
81
- if (row.__rowStatus || row.__modifiedFields || row.__insertedFields || row.__deletedFields)
82
- return lodash_1.default.omit(row, ['__rowStatus', '__modifiedFields', '__insertedFields', '__deletedFields']);
83
- return row;
84
- });
85
- return rows;
86
- }
87
- function runTramsformRows(func, macroArgs, data, preview, selectedCells, errors = []) {
88
- let rows = data.rows;
89
- try {
90
- rows = func(data.rows, macroArgs, modules, selectedCells, data.structure.columns.map(x => x.columnName), data.structure.columns);
91
- if (!preview) {
92
- rows = removePreviewRowFlags(rows);
93
- }
94
- }
95
- catch (err) {
96
- errors.push(`Error processing rows: ${err.message}`);
97
- }
98
- return {
99
- structure: data.structure,
100
- rows,
101
- };
102
- }
103
- function runTramsformData(func, macroArgs, data, preview, selectedCells, errors = []) {
104
- try {
105
- let { rows, columns, cols } = func(data.rows, macroArgs, modules, selectedCells, data.structure.columns.map(x => x.columnName), data.structure.columns);
106
- if (cols && !columns) {
107
- columns = cols.map(columnName => ({ columnName }));
108
- }
109
- columns = lodash_1.default.uniqBy(columns, 'columnName');
110
- if (!preview) {
111
- rows = removePreviewRowFlags(rows);
112
- }
113
- return {
114
- structure: { columns },
115
- rows,
116
- };
117
- }
118
- catch (err) {
119
- errors.push(`Error processing data: ${err.message}`);
120
- }
121
- return data;
122
- }
123
- function runMacro(macro, macroArgs, data, preview, selectedCells, errors = []) {
124
- let func;
125
- try {
126
- func = eval(getMacroFunction[macro.type](macro.code));
127
- }
128
- catch (err) {
129
- errors.push(`Error compiling macro ${macro.name}: ${err.message}`);
130
- return data;
131
- }
132
- if (macro.type == 'transformValue') {
133
- return runTramsformValue(func, macroArgs, data, preview, selectedCells, errors);
134
- }
135
- if (macro.type == 'transformRows') {
136
- return runTramsformRows(func, macroArgs, data, preview, selectedCells, errors);
137
- }
138
- if (macro.type == 'transformData') {
139
- // @ts-ignore
140
- return runTramsformData(func, macroArgs, data, preview, selectedCells, errors);
141
- }
142
- return data;
143
- }
144
- exports.runMacro = runMacro;
145
30
  function compileMacroFunction(macro, errors = []) {
146
31
  if (!macro)
147
32
  return null;
@@ -169,17 +54,45 @@ function runMacroOnValue(compiledFunc, macroArgs, value, rowIndex, row, column,
169
54
  }
170
55
  }
171
56
  exports.runMacroOnValue = runMacroOnValue;
172
- function runMacroOnChangeSet(macro, macroArgs, selectedCells, changeSet, display) {
57
+ function runMacroOnRow(compiledFunc, macroArgs, rowIndex, row, columns, errors = []) {
58
+ if (!compiledFunc)
59
+ return row;
60
+ try {
61
+ const res = compiledFunc(row, macroArgs, modules, rowIndex, columns);
62
+ return res;
63
+ }
64
+ catch (err) {
65
+ errors.push(`Error processing row ${rowIndex}: ${err.message}`);
66
+ return row;
67
+ }
68
+ }
69
+ exports.runMacroOnRow = runMacroOnRow;
70
+ function runMacroOnChangeSet(macro, macroArgs, selectedCells, changeSet, display, useRowIndexInsteaOfCondition) {
71
+ var _a;
173
72
  const errors = [];
174
73
  const compiledMacroFunc = compileMacroFunction(macro, errors);
175
74
  if (!compiledMacroFunc)
176
75
  return null;
177
- let res = changeSet;
178
- for (const cell of selectedCells) {
179
- const definition = display.getChangeSetField(cell.rowData, cell.column, undefined);
180
- const macroResult = runMacroOnValue(compiledMacroFunc, macroArgs, cell.value, cell.row, cell.rowData, cell.column, errors);
181
- res = (0, ChangeSet_1.setChangeSetValue)(res, definition, macroResult);
76
+ if (macro.type == 'transformValue') {
77
+ let res = changeSet;
78
+ for (const cell of selectedCells) {
79
+ const definition = display.getChangeSetField(cell.rowData, cell.column, undefined, useRowIndexInsteaOfCondition ? cell.row : undefined, useRowIndexInsteaOfCondition);
80
+ const macroResult = runMacroOnValue(compiledMacroFunc, macroArgs, cell.value, cell.row, cell.rowData, cell.column, errors);
81
+ res = (0, ChangeSet_1.setChangeSetValue)(res, definition, macroResult);
82
+ }
83
+ return res;
84
+ }
85
+ if (macro.type == 'transformRow') {
86
+ let res = changeSet;
87
+ const rowIndexes = lodash_1.default.uniq(selectedCells.map(x => x.row));
88
+ for (const index of rowIndexes) {
89
+ const rowData = (_a = selectedCells.find(x => x.row == index)) === null || _a === void 0 ? void 0 : _a.rowData;
90
+ const columns = lodash_1.default.uniq(selectedCells.map(x => x.column));
91
+ const definition = display.getChangeSetRow(rowData, null, index, true);
92
+ const newRow = runMacroOnRow(compiledMacroFunc, macroArgs, index, rowData, columns);
93
+ res = (0, ChangeSet_1.setChangeSetRowData)(res, definition, newRow);
94
+ }
95
+ return res;
182
96
  }
183
- return res;
184
97
  }
185
98
  exports.runMacroOnChangeSet = runMacroOnChangeSet;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.2.2",
2
+ "version": "5.2.4-alpha.1",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -13,12 +13,12 @@
13
13
  "lib"
14
14
  ],
15
15
  "dependencies": {
16
- "dbgate-sqltree": "^5.2.2",
17
- "dbgate-tools": "^5.2.2",
18
- "dbgate-filterparser": "^5.2.2"
16
+ "dbgate-sqltree": "^5.2.4-alpha.1",
17
+ "dbgate-tools": "^5.2.4-alpha.1",
18
+ "dbgate-filterparser": "^5.2.4-alpha.1"
19
19
  },
20
20
  "devDependencies": {
21
- "dbgate-types": "^5.2.2",
21
+ "dbgate-types": "^5.2.4-alpha.1",
22
22
  "@types/node": "^13.7.0",
23
23
  "jest": "^28.1.3",
24
24
  "ts-jest": "^28.0.7",