dbgate-datalib 5.1.4 → 5.1.5

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,8 +1,9 @@
1
- import { ColumnInfo, DatabaseInfo, ForeignKeyInfo, NamedObjectInfo, TableInfo, ViewInfo } from 'dbgate-types';
2
- import { ChangePerspectiveConfigFunc, MultipleDatabaseInfo, PerspectiveConfig, PerspectiveCustomJoinConfig, PerspectiveFilterColumnInfo, PerspectiveNodeConfig, PerspectiveReferenceConfig } from './PerspectiveConfig';
3
- import { PerspectiveDatabaseConfig, PerspectiveDataLoadProps, PerspectiveDataProvider } from './PerspectiveDataProvider';
1
+ import { CollectionInfo, ColumnInfo, DatabaseInfo, ForeignKeyInfo, NamedObjectInfo, TableInfo, ViewInfo } from 'dbgate-types';
2
+ import { ChangePerspectiveConfigFunc, MultipleDatabaseInfo, PerspectiveConfig, PerspectiveCustomJoinConfig, PerspectiveDatabaseConfig, PerspectiveDatabaseEngineType, PerspectiveFilterColumnInfo, PerspectiveNodeConfig, PerspectiveReferenceConfig } from './PerspectiveConfig';
3
+ import { PerspectiveDataLoadProps, PerspectiveDataProvider } from './PerspectiveDataProvider';
4
4
  import { FilterType } from 'dbgate-filterparser/lib/types';
5
5
  import { Condition } from 'dbgate-sqltree';
6
+ import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern';
6
7
  export interface PerspectiveDataLoadPropsWithNode {
7
8
  props: PerspectiveDataLoadProps;
8
9
  node: PerspectiveTreeNode;
@@ -17,7 +18,7 @@ export declare abstract class PerspectiveTreeNode {
17
18
  designerId: string;
18
19
  constructor(dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, parentNode: PerspectiveTreeNode, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, designerId: string);
19
20
  readonly nodeConfig: PerspectiveNodeConfig;
20
- readonly parentNodeConfig: PerspectiveNodeConfig;
21
+ parentNodeConfig: PerspectiveNodeConfig;
21
22
  abstract get title(): any;
22
23
  abstract get codeName(): any;
23
24
  abstract get isExpandable(): any;
@@ -30,10 +31,14 @@ export declare abstract class PerspectiveTreeNode {
30
31
  get dataField(): any;
31
32
  get tableCode(): any;
32
33
  get namedObject(): NamedObjectInfo;
34
+ get tableNodeOrParent(): PerspectiveTableNode;
35
+ get engineType(): PerspectiveDatabaseEngineType;
33
36
  abstract getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
34
37
  get isRoot(): boolean;
35
38
  get rootNode(): PerspectiveTreeNode;
36
39
  get isSortable(): boolean;
40
+ get generatesHiearchicGridColumn(): boolean;
41
+ get generatesDataGridColumn(): boolean;
37
42
  matchChildRow(parentRow: any, childRow: any): boolean;
38
43
  hasTableCode(code: string): any;
39
44
  get level(): any;
@@ -64,8 +69,9 @@ export declare abstract class PerspectiveTreeNode {
64
69
  includeInNodeSet(field: 'expandedColumns' | 'uncheckedColumns' | 'checkedColumns', isIncluded: boolean): void;
65
70
  getFilter(): string;
66
71
  getDataLoadColumns(): any[];
67
- getChildrenCondition(source?: any): Condition;
68
- getOrderBy(table: TableInfo | ViewInfo): PerspectiveDataLoadProps['orderBy'];
72
+ getChildrenSqlCondition(source?: any): Condition;
73
+ getChildrenMongoCondition(source?: any): {};
74
+ getOrderBy(table: TableInfo | ViewInfo | CollectionInfo): PerspectiveDataLoadProps['orderBy'];
69
75
  getBaseTables(): any[];
70
76
  getBaseTableFromThis(): any;
71
77
  get filterInfo(): PerspectiveFilterColumnInfo;
@@ -86,6 +92,7 @@ export declare class PerspectiveTableColumnNode extends PerspectiveTreeNode {
86
92
  isView: boolean;
87
93
  isTable: boolean;
88
94
  constructor(column: ColumnInfo, table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
95
+ get engineType(): PerspectiveDatabaseEngineType;
89
96
  matchChildRow(parentRow: any, childRow: any): boolean;
90
97
  getChildMatchColumns(): string[];
91
98
  getParentMatchColumns(): string[];
@@ -115,26 +122,51 @@ export declare class PerspectiveTableColumnNode extends PerspectiveTreeNode {
115
122
  pureName: string;
116
123
  conid: string;
117
124
  database: string;
125
+ objectTypeField: string;
118
126
  };
119
127
  get tableCode(): string;
120
128
  get namedObject(): NamedObjectInfo;
121
129
  }
130
+ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
131
+ table: TableInfo | ViewInfo | CollectionInfo;
132
+ column: PerspectiveDataPatternColumn;
133
+ tableColumn: ColumnInfo;
134
+ foreignKey: ForeignKeyInfo;
135
+ refTable: TableInfo;
136
+ constructor(table: TableInfo | ViewInfo | CollectionInfo, column: PerspectiveDataPatternColumn, tableColumn: ColumnInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
137
+ get isChildColumn(): boolean;
138
+ getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
139
+ get generatesHiearchicGridColumn(): boolean;
140
+ get icon(): "img column" | "img json";
141
+ get codeName(): string;
142
+ get columnName(): string;
143
+ get fieldName(): string;
144
+ get title(): string;
145
+ get isExpandable(): boolean;
146
+ get isSortable(): boolean;
147
+ get filterType(): FilterType;
148
+ generateChildNodes(): PerspectiveTreeNode[];
149
+ get filterInfo(): PerspectiveFilterColumnInfo;
150
+ parseFilterCondition(source?: any): {};
151
+ }
122
152
  export declare class PerspectiveTableNode extends PerspectiveTreeNode {
123
- table: TableInfo | ViewInfo;
153
+ table: TableInfo | ViewInfo | CollectionInfo;
124
154
  dataProvider: PerspectiveDataProvider;
125
- constructor(table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
155
+ constructor(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
156
+ get engineType(): PerspectiveDatabaseEngineType;
126
157
  getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
127
158
  get codeName(): string;
128
159
  get title(): string;
129
160
  get isExpandable(): boolean;
130
161
  generateChildNodes(): PerspectiveTreeNode[];
131
162
  get icon(): string;
132
- getBaseTableFromThis(): TableInfo | ViewInfo;
163
+ getBaseTableFromThis(): TableInfo | ViewInfo | CollectionInfo;
133
164
  get headerTableAttributes(): {
134
165
  schemaName: string;
135
166
  pureName: string;
136
167
  conid: string;
137
168
  database: string;
169
+ objectTypeField: string;
138
170
  };
139
171
  get tableCode(): string;
140
172
  get namedObject(): NamedObjectInfo;
@@ -159,7 +191,7 @@ export declare class PerspectiveTableReferenceNode extends PerspectiveTableNode
159
191
  export declare class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
160
192
  customJoin: PerspectiveCustomJoinConfig;
161
193
  dataProvider: PerspectiveDataProvider;
162
- constructor(customJoin: PerspectiveCustomJoinConfig, table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
194
+ constructor(customJoin: PerspectiveCustomJoinConfig, table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
163
195
  matchChildRow(parentRow: any, childRow: any): boolean;
164
196
  getChildMatchColumns(): string[];
165
197
  getParentMatchColumns(): string[];
@@ -171,4 +203,4 @@ export declare class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode
171
203
  toggleChecked(value?: boolean): void;
172
204
  getParentJoinCondition(alias: string, parentAlias: string): Condition[];
173
205
  }
174
- export declare function getTableChildPerspectiveNodes(table: TableInfo | ViewInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode): any[];
206
+ export declare function getTableChildPerspectiveNodes(table: TableInfo | ViewInfo | CollectionInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode): any[];
@@ -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.getTableChildPerspectiveNodes = exports.PerspectiveCustomJoinTreeNode = exports.PerspectiveTableReferenceNode = exports.PerspectiveTableNode = exports.PerspectiveTableColumnNode = exports.PerspectiveTreeNode = void 0;
6
+ exports.getTableChildPerspectiveNodes = exports.PerspectiveCustomJoinTreeNode = exports.PerspectiveTableReferenceNode = exports.PerspectiveTableNode = exports.PerspectivePatternColumnNode = exports.PerspectiveTableColumnNode = exports.PerspectiveTreeNode = void 0;
7
7
  const dbgate_tools_1 = require("dbgate-tools");
8
8
  const PerspectiveConfig_1 = require("./PerspectiveConfig");
9
9
  const isEqual_1 = __importDefault(require("lodash/isEqual"));
@@ -72,6 +72,18 @@ class PerspectiveTreeNode {
72
72
  get namedObject() {
73
73
  return null;
74
74
  }
75
+ get tableNodeOrParent() {
76
+ if (this instanceof PerspectiveTableNode) {
77
+ return this;
78
+ }
79
+ if (this.parentNode == null) {
80
+ return null;
81
+ }
82
+ return this.parentNode.tableNodeOrParent;
83
+ }
84
+ get engineType() {
85
+ return null;
86
+ }
75
87
  get isRoot() {
76
88
  return this.parentNode == null;
77
89
  }
@@ -84,6 +96,12 @@ class PerspectiveTreeNode {
84
96
  get isSortable() {
85
97
  return false;
86
98
  }
99
+ get generatesHiearchicGridColumn() {
100
+ return this.isExpandable && this.isCheckedNode;
101
+ }
102
+ get generatesDataGridColumn() {
103
+ return this.isCheckedColumn;
104
+ }
87
105
  matchChildRow(parentRow, childRow) {
88
106
  return true;
89
107
  }
@@ -211,10 +229,11 @@ class PerspectiveTreeNode {
211
229
  }
212
230
  includeInNodeSet(field, isIncluded) {
213
231
  this.setConfig(cfg => {
214
- var _a;
232
+ var _a, _b;
215
233
  const changedFields = n => (Object.assign(Object.assign({}, n), { [field]: isIncluded ? [...(n[field] || []), this.codeName] : (n[field] || []).filter(x => x != this.codeName) }));
216
- const [cfgChanged, nodeCfg] = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.ensureNodeConfig(cfg);
217
- return Object.assign(Object.assign({}, cfgChanged), { nodes: cfgChanged.nodes.map(n => { var _a; return n.designerId == (((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.designerId) || (nodeCfg === null || nodeCfg === void 0 ? void 0 : nodeCfg.designerId)) ? changedFields(n) : n; }) });
234
+ const [cfgChanged, nodeCfg] = (_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.tableNodeOrParent) === null || _b === void 0 ? void 0 : _b.ensureNodeConfig(cfg);
235
+ const res = Object.assign(Object.assign({}, cfgChanged), { nodes: cfgChanged.nodes.map(n => { var _a, _b; return n.designerId == (((_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.tableNodeOrParent) === null || _b === void 0 ? void 0 : _b.designerId) || (nodeCfg === null || nodeCfg === void 0 ? void 0 : nodeCfg.designerId)) ? changedFields(n) : n; }) });
236
+ return res;
218
237
  });
219
238
  }
220
239
  getFilter() {
@@ -226,9 +245,13 @@ class PerspectiveTreeNode {
226
245
  ...this.childNodes.map(x => x.childDataColumn),
227
246
  ...(0, flatten_1.default)(this.childNodes.filter(x => x.isExpandable && x.isChecked).map(x => x.getChildMatchColumns())),
228
247
  ...this.getParentMatchColumns(),
248
+ ...this.childNodes
249
+ .filter(x => x instanceof PerspectivePatternColumnNode)
250
+ .filter(x => { var _a, _b; return (_b = (_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.checkedColumns) === null || _b === void 0 ? void 0 : _b.find(y => y.startsWith(x.codeName + '::')); })
251
+ .map(x => x.columnName),
229
252
  ]));
230
253
  }
231
- getChildrenCondition(source = null) {
254
+ getChildrenSqlCondition(source = null) {
232
255
  const conditions = (0, compact_1.default)([
233
256
  ...this.childNodes.map(x => x.parseFilterCondition(source)),
234
257
  ...this.buildParentFilterConditions(),
@@ -244,6 +267,16 @@ class PerspectiveTreeNode {
244
267
  conditions,
245
268
  };
246
269
  }
270
+ getChildrenMongoCondition(source = null) {
271
+ const conditions = (0, compact_1.default)([...this.childNodes.map(x => x.parseFilterCondition(source))]);
272
+ if (conditions.length == 0) {
273
+ return null;
274
+ }
275
+ if (conditions.length == 1) {
276
+ return conditions[0];
277
+ }
278
+ return { $and: conditions };
279
+ }
247
280
  getOrderBy(table) {
248
281
  var _a;
249
282
  const res = (0, compact_1.default)(this.childNodes.map(node => {
@@ -256,11 +289,18 @@ class PerspectiveTreeNode {
256
289
  };
257
290
  }
258
291
  }));
259
- return res.length > 0
260
- ? res
261
- : ((_a = table === null || table === void 0 ? void 0 : table.primaryKey) === null || _a === void 0 ? void 0 : _a.columns.map(x => ({ columnName: x.columnName, order: 'ASC' }))) || [
262
- { columnName: table === null || table === void 0 ? void 0 : table.columns[0].columnName, order: 'ASC' },
263
- ];
292
+ if (res.length > 0)
293
+ return res;
294
+ const pkColumns = (_a = table === null || table === void 0 ? void 0 : table.primaryKey) === null || _a === void 0 ? void 0 : _a.columns.map(x => ({
295
+ columnName: x.columnName,
296
+ order: 'ASC',
297
+ }));
298
+ if (pkColumns)
299
+ return pkColumns;
300
+ const columns = table === null || table === void 0 ? void 0 : table.columns;
301
+ if (columns)
302
+ return [{ columnName: columns[0].columnName, order: 'ASC' }];
303
+ return [{ columnName: '_id', order: 'ASC' }];
264
304
  }
265
305
  getBaseTables() {
266
306
  const res = [];
@@ -312,10 +352,12 @@ class PerspectiveTreeNode {
312
352
  return null;
313
353
  }
314
354
  get supportsParentFilter() {
315
- var _a, _b, _c, _d, _e, _f, _g, _h;
355
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
316
356
  return ((((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.isRoot) || ((_b = this.parentNode) === null || _b === void 0 ? void 0 : _b.supportsParentFilter)) &&
317
357
  ((_d = (_c = this.parentNode) === null || _c === void 0 ? void 0 : _c.databaseConfig) === null || _d === void 0 ? void 0 : _d.conid) == ((_e = this.databaseConfig) === null || _e === void 0 ? void 0 : _e.conid) &&
318
- ((_g = (_f = this.parentNode) === null || _f === void 0 ? void 0 : _f.databaseConfig) === null || _g === void 0 ? void 0 : _g.database) == ((_h = this.databaseConfig) === null || _h === void 0 ? void 0 : _h.database));
358
+ ((_g = (_f = this.parentNode) === null || _f === void 0 ? void 0 : _f.databaseConfig) === null || _g === void 0 ? void 0 : _g.database) == ((_h = this.databaseConfig) === null || _h === void 0 ? void 0 : _h.database) &&
359
+ this.engineType == 'sqldb' &&
360
+ ((_j = this.parentNode) === null || _j === void 0 ? void 0 : _j.engineType) == 'sqldb');
319
361
  }
320
362
  get isParentFilter() {
321
363
  var _a;
@@ -362,7 +404,7 @@ class PerspectiveTreeNode {
362
404
  conditionType: 'and',
363
405
  conditions: (0, compact_1.default)([
364
406
  ...lastNode.getParentJoinCondition(lastAlias, this.namedObject.pureName),
365
- leafNode.getChildrenCondition({ alias: 'pert_0' }),
407
+ leafNode.getChildrenSqlCondition({ alias: 'pert_0' }),
366
408
  ]),
367
409
  };
368
410
  return {
@@ -398,6 +440,9 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
398
440
  this.foreignKey = (_e = table === null || table === void 0 ? void 0 : table.foreignKeys) === null || _e === void 0 ? void 0 : _e.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName);
399
441
  this.refTable = this.db.tables.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); });
400
442
  }
443
+ get engineType() {
444
+ return this.parentNode.engineType;
445
+ }
401
446
  matchChildRow(parentRow, childRow) {
402
447
  if (!this.foreignKey)
403
448
  return false;
@@ -452,7 +497,8 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
452
497
  dataColumns: this.getDataLoadColumns(),
453
498
  databaseConfig: this.databaseConfig,
454
499
  orderBy: this.getOrderBy(this.refTable),
455
- condition: this.getChildrenCondition(),
500
+ sqlCondition: this.getChildrenSqlCondition(),
501
+ engineType: 'sqldb',
456
502
  };
457
503
  }
458
504
  get icon() {
@@ -472,6 +518,7 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
472
518
  }
473
519
  get fieldName() {
474
520
  return this.codeName + 'Ref';
521
+ // return this.codeName ;
475
522
  }
476
523
  get title() {
477
524
  return this.column.columnName;
@@ -554,6 +601,7 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
554
601
  pureName: this.foreignKey.refTableName,
555
602
  conid: this.databaseConfig.conid,
556
603
  database: this.databaseConfig.database,
604
+ objectTypeField: this.table.objectTypeField,
557
605
  };
558
606
  }
559
607
  return null;
@@ -575,20 +623,166 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
575
623
  }
576
624
  }
577
625
  exports.PerspectiveTableColumnNode = PerspectiveTableColumnNode;
626
+ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
627
+ constructor(table, column, tableColumn, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
628
+ var _a;
629
+ super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
630
+ this.table = table;
631
+ this.column = column;
632
+ this.tableColumn = tableColumn;
633
+ this.parentNodeConfig = (_a = this.tableNodeOrParent) === null || _a === void 0 ? void 0 : _a.nodeConfig;
634
+ }
635
+ get isChildColumn() {
636
+ return this.parentNode instanceof PerspectivePatternColumnNode;
637
+ }
638
+ // matchChildRow(parentRow: any, childRow: any): boolean {
639
+ // if (!this.foreignKey) return false;
640
+ // return parentRow[this.foreignKey.columns[0].columnName] == childRow[this.foreignKey.columns[0].refColumnName];
641
+ // }
642
+ // getChildMatchColumns() {
643
+ // if (!this.foreignKey) return [];
644
+ // return [this.foreignKey.columns[0].columnName];
645
+ // }
646
+ // getParentMatchColumns() {
647
+ // if (!this.foreignKey) return [];
648
+ // return [this.foreignKey.columns[0].refColumnName];
649
+ // }
650
+ // getParentJoinCondition(alias: string, parentAlias: string): Condition[] {
651
+ // if (!this.foreignKey) return [];
652
+ // return this.foreignKey.columns.map(column => {
653
+ // const res: Condition = {
654
+ // conditionType: 'binary',
655
+ // operator: '=',
656
+ // left: {
657
+ // exprType: 'column',
658
+ // columnName: column.columnName,
659
+ // source: { alias: parentAlias },
660
+ // },
661
+ // right: {
662
+ // exprType: 'column',
663
+ // columnName: column.refColumnName,
664
+ // source: { alias },
665
+ // },
666
+ // };
667
+ // return res;
668
+ // });
669
+ // }
670
+ // createReferenceConfigColumns(): PerspectiveReferenceConfig['columns'] {
671
+ // return this.foreignKey?.columns?.map(col => ({
672
+ // source: col.columnName,
673
+ // target: col.refColumnName,
674
+ // }));
675
+ // }
676
+ getNodeLoadProps(parentRows) {
677
+ return null;
678
+ }
679
+ get generatesHiearchicGridColumn() {
680
+ var _a, _b, _c;
681
+ // console.log('generatesHiearchicGridColumn', this.parentTableNode?.nodeConfig?.checkedColumns, this.codeName + '::');
682
+ return !!((_c = (_b = (_a = this.tableNodeOrParent) === null || _a === void 0 ? void 0 : _a.nodeConfig) === null || _b === void 0 ? void 0 : _b.checkedColumns) === null || _c === void 0 ? void 0 : _c.find(x => x.startsWith(this.codeName + '::')));
683
+ }
684
+ // get generatesHiearchicGridColumn() {
685
+ // // return this.config &&;
686
+ // }
687
+ get icon() {
688
+ if (this.column.types.includes('json')) {
689
+ return 'img json';
690
+ }
691
+ return 'img column';
692
+ }
693
+ get codeName() {
694
+ if (this.parentNode instanceof PerspectivePatternColumnNode) {
695
+ return `${this.parentNode.codeName}::${this.column.name}`;
696
+ }
697
+ return this.column.name;
698
+ }
699
+ get columnName() {
700
+ return this.column.name;
701
+ }
702
+ get fieldName() {
703
+ return this.column.name;
704
+ }
705
+ get title() {
706
+ return this.column.name;
707
+ }
708
+ get isExpandable() {
709
+ return this.column.columns.length > 0;
710
+ }
711
+ get isSortable() {
712
+ return !this.isChildColumn;
713
+ }
714
+ get filterType() {
715
+ if (this.tableColumn)
716
+ return (0, dbgate_filterparser_1.getFilterType)(this.tableColumn.dataType);
717
+ return 'mongo';
718
+ }
719
+ generateChildNodes() {
720
+ 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));
721
+ return [];
722
+ // if (!this.foreignKey) return [];
723
+ // const tbl = this?.db?.tables?.find(
724
+ // x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
725
+ // );
726
+ // return getTableChildPerspectiveNodes(
727
+ // tbl,
728
+ // this.dbs,
729
+ // this.config,
730
+ // this.setConfig,
731
+ // this.dataProvider,
732
+ // this.databaseConfig,
733
+ // this
734
+ // );
735
+ }
736
+ get filterInfo() {
737
+ if (this.isChildColumn) {
738
+ return null;
739
+ }
740
+ return {
741
+ columnName: this.columnName,
742
+ filterType: this.filterType,
743
+ pureName: this.table.pureName,
744
+ schemaName: this.table.schemaName,
745
+ foreignKey: this.foreignKey,
746
+ };
747
+ }
748
+ parseFilterCondition(source = null) {
749
+ const filter = this.getFilter();
750
+ if (!filter)
751
+ return null;
752
+ const condition = (0, dbgate_filterparser_1.parseFilter)(filter, 'mongo');
753
+ if (!condition)
754
+ return null;
755
+ return (0, cloneDeepWith_1.default)(condition, expr => {
756
+ if (expr.__placeholder__) {
757
+ return {
758
+ [this.columnName]: expr.__placeholder__,
759
+ };
760
+ }
761
+ });
762
+ }
763
+ }
764
+ exports.PerspectivePatternColumnNode = PerspectivePatternColumnNode;
578
765
  class PerspectiveTableNode extends PerspectiveTreeNode {
579
766
  constructor(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
580
767
  super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
581
768
  this.table = table;
582
769
  this.dataProvider = dataProvider;
583
770
  }
771
+ get engineType() {
772
+ return (0, dbgate_tools_1.isCollectionInfo)(this.table) ? 'docdb' : 'sqldb';
773
+ }
584
774
  getNodeLoadProps(parentRows) {
775
+ const isMongo = (0, dbgate_tools_1.isCollectionInfo)(this.table);
585
776
  return {
586
777
  schemaName: this.table.schemaName,
587
778
  pureName: this.table.pureName,
588
779
  dataColumns: this.getDataLoadColumns(),
780
+ allColumns: isMongo,
589
781
  databaseConfig: this.databaseConfig,
590
782
  orderBy: this.getOrderBy(this.table),
591
- condition: this.getChildrenCondition(),
783
+ sqlCondition: isMongo ? null : this.getChildrenSqlCondition(),
784
+ mongoCondition: isMongo ? this.getChildrenMongoCondition() : null,
785
+ engineType: isMongo ? 'docdb' : 'sqldb',
592
786
  };
593
787
  }
594
788
  get codeName() {
@@ -616,6 +810,7 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
616
810
  pureName: this.table.pureName,
617
811
  conid: this.databaseConfig.conid,
618
812
  database: this.databaseConfig.database,
813
+ objectTypeField: this.table.objectTypeField,
619
814
  };
620
815
  }
621
816
  get tableCode() {
@@ -629,55 +824,6 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
629
824
  }
630
825
  }
631
826
  exports.PerspectiveTableNode = PerspectiveTableNode;
632
- // export class PerspectiveViewNode extends PerspectiveTreeNode {
633
- // constructor(
634
- // public view: ViewInfo,
635
- // dbs: MultipleDatabaseInfo,
636
- // config: PerspectiveConfig,
637
- // setConfig: ChangePerspectiveConfigFunc,
638
- // public dataProvider: PerspectiveDataProvider,
639
- // databaseConfig: PerspectiveDatabaseConfig,
640
- // parentNode: PerspectiveTreeNode
641
- // ) {
642
- // super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
643
- // }
644
- // getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps {
645
- // return {
646
- // schemaName: this.view.schemaName,
647
- // pureName: this.view.pureName,
648
- // dataColumns: this.getDataLoadColumns(),
649
- // databaseConfig: this.databaseConfig,
650
- // orderBy: this.getOrderBy(this.view),
651
- // condition: this.getChildrenCondition(),
652
- // };
653
- // }
654
- // get codeName() {
655
- // return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName;
656
- // }
657
- // get title() {
658
- // return this.view.pureName;
659
- // }
660
- // get isExpandable() {
661
- // return true;
662
- // }
663
- // get childNodes(): PerspectiveTreeNode[] {
664
- // return getTableChildPerspectiveNodes(
665
- // this.view,
666
- // this.dbs,
667
- // this.config,
668
- // this.setConfig,
669
- // this.dataProvider,
670
- // this.databaseConfig,
671
- // this
672
- // );
673
- // }
674
- // get icon() {
675
- // return 'img table';
676
- // }
677
- // getBaseTableFromThis() {
678
- // return this.view;
679
- // }
680
- // }
681
827
  class PerspectiveTableReferenceNode extends PerspectiveTableNode {
682
828
  constructor(foreignKey, table, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode, designerId) {
683
829
  super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
@@ -711,7 +857,8 @@ class PerspectiveTableReferenceNode extends PerspectiveTableNode {
711
857
  dataColumns: this.getDataLoadColumns(),
712
858
  databaseConfig: this.databaseConfig,
713
859
  orderBy: this.getOrderBy(this.table),
714
- condition: this.getChildrenCondition(),
860
+ sqlCondition: this.getChildrenSqlCondition(),
861
+ engineType: 'sqldb',
715
862
  };
716
863
  }
717
864
  createReferenceConfigColumns() {
@@ -788,15 +935,19 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
788
935
  getNodeLoadProps(parentRows) {
789
936
  // console.log('CUSTOM JOIN', this.customJoin);
790
937
  // console.log('this.getDataLoadColumns()', this.getDataLoadColumns());
938
+ const isMongo = (0, dbgate_tools_1.isCollectionInfo)(this.table);
791
939
  return {
792
940
  schemaName: this.table.schemaName,
793
941
  pureName: this.table.pureName,
794
942
  bindingColumns: this.getParentMatchColumns(),
795
943
  bindingValues: (0, uniqBy_1.default)(parentRows.map(row => this.customJoin.columns.map(x => row[x.baseColumnName])), json_stable_stringify_1.default),
796
944
  dataColumns: this.getDataLoadColumns(),
945
+ allColumns: isMongo,
797
946
  databaseConfig: this.databaseConfig,
798
947
  orderBy: this.getOrderBy(this.table),
799
- condition: this.getChildrenCondition(),
948
+ sqlCondition: isMongo ? null : this.getChildrenSqlCondition(),
949
+ mongoCondition: isMongo ? this.getChildrenMongoCondition() : null,
950
+ engineType: isMongo ? 'docdb' : 'sqldb',
800
951
  };
801
952
  }
802
953
  // get title() {
@@ -863,11 +1014,20 @@ function findDesignerIdForNode(config, parentNode, nodeCreateFunc) {
863
1014
  return node;
864
1015
  }
865
1016
  function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
866
- var _a, _b, _c, _d;
1017
+ var _a, _b, _c, _d, _e, _f, _g, _h;
867
1018
  if (!table)
868
1019
  return [];
869
1020
  const db = parentNode.db;
870
- const columnNodes = table.columns.map(col => findDesignerIdForNode(config, parentNode, designerId => new PerspectiveTableColumnNode(col, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId)));
1021
+ const pattern = (_a = dataProvider === null || dataProvider === void 0 ? void 0 : dataProvider.dataPatterns) === null || _a === void 0 ? void 0 : _a[parentNode.designerId];
1022
+ const tableOrView = (0, dbgate_tools_1.isTableInfo)(table) || (0, dbgate_tools_1.isViewInfo)(table) ? table : null;
1023
+ 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 => {
1024
+ var _a, _b, _c;
1025
+ 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'))
1026
+ ? 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)
1027
+ : new PerspectiveTableColumnNode(col, tableOrView, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
1028
+ }))) ||
1029
+ ((_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)))) ||
1030
+ [];
871
1031
  // if (!columnNodes.find(x => x.isChecked)) {
872
1032
  // const circularColumns = columnNodes.filter(x => x.isCircular).map(x => x.columnName);
873
1033
  // const defaultColumns = getPerspectiveDefaultColumns(table, db, circularColumns);
@@ -892,7 +1052,7 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
892
1052
  res.push(...(0, sortBy_1.default)(dependencies, 'title'));
893
1053
  const customs = [];
894
1054
  for (const node of config.nodes) {
895
- if (node.designerId == ((_a = parentNode.parentNode) === null || _a === void 0 ? void 0 : _a.designerId) || res.find(x => x.designerId == node.designerId)) {
1055
+ if (node.designerId == ((_d = parentNode.parentNode) === null || _d === void 0 ? void 0 : _d.designerId) || res.find(x => x.designerId == node.designerId)) {
896
1056
  // already used as FK
897
1057
  continue;
898
1058
  }
@@ -904,9 +1064,10 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
904
1064
  newConfig.conid = node.conid;
905
1065
  if (node.database)
906
1066
  newConfig.database = node.database;
907
- const db = (_b = dbs === null || dbs === void 0 ? void 0 : dbs[newConfig.conid]) === null || _b === void 0 ? void 0 : _b[newConfig.database];
908
- const table = (_c = db === null || db === void 0 ? void 0 : db.tables) === null || _c === void 0 ? void 0 : _c.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
909
- const view = (_d = db === null || db === void 0 ? void 0 : db.views) === null || _d === void 0 ? void 0 : _d.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
1067
+ const db = (_e = dbs === null || dbs === void 0 ? void 0 : dbs[newConfig.conid]) === null || _e === void 0 ? void 0 : _e[newConfig.database];
1068
+ const table = (_f = db === null || db === void 0 ? void 0 : db.tables) === null || _f === void 0 ? void 0 : _f.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
1069
+ const view = (_g = db === null || db === void 0 ? void 0 : db.views) === null || _g === void 0 ? void 0 : _g.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
1070
+ const collection = (_h = db === null || db === void 0 ? void 0 : db.collections) === null || _h === void 0 ? void 0 : _h.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
910
1071
  const join = {
911
1072
  refNodeDesignerId: node.designerId,
912
1073
  referenceDesignerId: ref.designerId,
@@ -920,40 +1081,13 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
920
1081
  ? ref.columns.map(col => ({ baseColumnName: col.source, refColumnName: col.target }))
921
1082
  : ref.columns.map(col => ({ baseColumnName: col.target, refColumnName: col.source })),
922
1083
  };
923
- if (table || view) {
924
- customs.push(new PerspectiveCustomJoinTreeNode(join, table || view, dbs, config, setConfig, dataProvider, newConfig, parentNode, node.designerId));
1084
+ if (table || view || collection) {
1085
+ customs.push(new PerspectiveCustomJoinTreeNode(join, table || view || collection, dbs, config, setConfig, dataProvider, newConfig, parentNode, node.designerId));
925
1086
  }
926
1087
  }
927
1088
  }
928
1089
  }
929
1090
  res.push(...(0, sortBy_1.default)(customs, 'title'));
930
- // const customs = [];
931
- // for (const join of config.customJoins || []) {
932
- // if (join.baseUniqueName == parentColumn.uniqueName) {
933
- // const newConfig = { ...databaseConfig };
934
- // if (join.conid) newConfig.conid = join.conid;
935
- // if (join.database) newConfig.database = join.database;
936
- // const db = dbs?.[newConfig.conid]?.[newConfig.database];
937
- // const table = db?.tables?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
938
- // const view = db?.views?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
939
- // if (table || view) {
940
- // customs.push(
941
- // new PerspectiveCustomJoinTreeNode(
942
- // join,
943
- // table || view,
944
- // dbs,
945
- // config,
946
- // setConfig,
947
- // dataProvider,
948
- // newConfig,
949
- // parentColumn,
950
- // null
951
- // )
952
- // );
953
- // }
954
- // }
955
- // }
956
- // res.push(..._sortBy(customs, 'title'));
957
1091
  return res;
958
1092
  }
959
1093
  exports.getTableChildPerspectiveNodes = getTableChildPerspectiveNodes;
package/lib/index.d.ts CHANGED
@@ -19,3 +19,4 @@ export * from './PerspectiveDataProvider';
19
19
  export * from './PerspectiveCache';
20
20
  export * from './PerspectiveConfig';
21
21
  export * from './processPerspectiveDefaultColunns';
22
+ export * from './PerspectiveDataPattern';
package/lib/index.js CHANGED
@@ -35,3 +35,4 @@ __exportStar(require("./PerspectiveDataProvider"), exports);
35
35
  __exportStar(require("./PerspectiveCache"), exports);
36
36
  __exportStar(require("./PerspectiveConfig"), exports);
37
37
  __exportStar(require("./processPerspectiveDefaultColunns"), exports);
38
+ __exportStar(require("./PerspectiveDataPattern"), exports);