dbgate-datalib 5.1.6 → 5.1.7-alpha.13

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.
@@ -9,6 +9,7 @@ const zip_1 = __importDefault(require("lodash/zip"));
9
9
  const difference_1 = __importDefault(require("lodash/difference"));
10
10
  const debug_1 = __importDefault(require("debug"));
11
11
  const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
12
+ const perspectiveTools_1 = require("./perspectiveTools");
12
13
  const dbg = (0, debug_1.default)('dbgate:PerspectiveCache');
13
14
  class PerspectiveBindingGroup {
14
15
  constructor(table) {
@@ -16,7 +17,7 @@ class PerspectiveBindingGroup {
16
17
  this.loadedRows = [];
17
18
  }
18
19
  matchRow(row) {
19
- return this.table.bindingColumns.every((column, index) => row[column] == this.bindingValues[index]);
20
+ return this.table.bindingColumns.every((column, index) => (0, perspectiveTools_1.perspectiveValueMatcher)(row[column], this.bindingValues[index]));
20
21
  }
21
22
  }
22
23
  exports.PerspectiveBindingGroup = PerspectiveBindingGroup;
@@ -57,7 +58,9 @@ class PerspectiveCacheTable {
57
58
  return uncached;
58
59
  }
59
60
  storeGroupSize(props, bindingValues, count) {
60
- const originalBindingValue = props.bindingValues.find(v => (0, zip_1.default)(v, bindingValues).every(([x, y]) => x == y));
61
+ const originalBindingValue = props.bindingValues.find(v => (0, zip_1.default)(v, bindingValues).every(([x, y]) => (0, perspectiveTools_1.perspectiveValueMatcher)(x, y)));
62
+ // console.log('storeGroupSize NEW', bindingValues);
63
+ // console.log('storeGroupSize ORIGINAL', originalBindingValue);
61
64
  if (originalBindingValue) {
62
65
  const key = (0, json_stable_stringify_1.default)(originalBindingValue);
63
66
  // console.log('SET SIZE', originalBindingValue, bindingValues, key, count);
@@ -41,7 +41,7 @@ function addObjectToColumns(columns, row) {
41
41
  if (!column.types.includes(type)) {
42
42
  column.types.push(type);
43
43
  }
44
- if ((0, isPlainObject_1.default)(value)) {
44
+ if ((0, isPlainObject_1.default)(value) && type != 'oid') {
45
45
  addObjectToColumns(column.columns, value);
46
46
  }
47
47
  if ((0, isArray_1.default)(value)) {
@@ -48,10 +48,11 @@ class PerspectiveDataProvider {
48
48
  loadDataNested(props) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
50
  const tableCache = this.cache.getTableCache(props);
51
+ // console.log('loadDataNested', props);
51
52
  const uncached = tableCache.getUncachedBindingGroups(props);
52
53
  if (uncached.length > 0) {
53
54
  const counts = yield this.loader.loadGrouping(Object.assign(Object.assign({}, props), { bindingValues: uncached }));
54
- // console.log('COUNTS', counts);
55
+ // console.log('loadDataNested COUNTS', counts);
55
56
  for (const resetItem of uncached) {
56
57
  tableCache.storeGroupSize(props, resetItem, 0);
57
58
  }
@@ -170,6 +171,13 @@ class PerspectiveDataProvider {
170
171
  offset: tableCache.loadedCount,
171
172
  limit: props.topCount - tableCache.loadedCount,
172
173
  } }));
174
+ if (!nextRows) {
175
+ // return tableCache.getRowsResult(props);
176
+ return {
177
+ rows: [],
178
+ incomplete: false,
179
+ };
180
+ }
173
181
  if (nextRows.errorMessage) {
174
182
  throw new Error(nextRows.errorMessage);
175
183
  }
@@ -39,6 +39,9 @@ export declare abstract class PerspectiveTreeNode {
39
39
  get isSortable(): boolean;
40
40
  get generatesHiearchicGridColumn(): boolean;
41
41
  get generatesDataGridColumn(): boolean;
42
+ get validParentDesignerId(): any;
43
+ get preloadedLevelData(): boolean;
44
+ get findByDesignerIdWithoutDesignerId(): boolean;
42
45
  matchChildRow(parentRow: any, childRow: any): boolean;
43
46
  hasTableCode(code: string): any;
44
47
  get level(): any;
@@ -135,6 +138,7 @@ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
135
138
  refTable: TableInfo;
136
139
  constructor(table: TableInfo | ViewInfo | CollectionInfo, column: PerspectiveDataPatternColumn, tableColumn: ColumnInfo, dbs: MultipleDatabaseInfo, config: PerspectiveConfig, setConfig: ChangePerspectiveConfigFunc, dataProvider: PerspectiveDataProvider, databaseConfig: PerspectiveDatabaseConfig, parentNode: PerspectiveTreeNode, designerId: string);
137
140
  get isChildColumn(): boolean;
141
+ get findByDesignerIdWithoutDesignerId(): boolean;
138
142
  getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
139
143
  get generatesHiearchicGridColumn(): boolean;
140
144
  get icon(): "img column" | "img json";
@@ -145,6 +149,9 @@ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
145
149
  get isExpandable(): boolean;
146
150
  get isSortable(): boolean;
147
151
  get filterType(): FilterType;
152
+ get preloadedLevelData(): boolean;
153
+ generatePatternChildNodes(): PerspectivePatternColumnNode[];
154
+ hasCheckedJoinChild(): boolean;
148
155
  generateChildNodes(): PerspectiveTreeNode[];
149
156
  get filterInfo(): PerspectiveFilterColumnInfo;
150
157
  parseFilterCondition(source?: any): {};
@@ -18,6 +18,7 @@ const json_stable_stringify_1 = __importDefault(require("json-stable-stringify")
18
18
  const dbgate_filterparser_1 = require("dbgate-filterparser");
19
19
  // import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
20
20
  const v1_1 = __importDefault(require("uuid/v1"));
21
+ const perspectiveTools_1 = require("./perspectiveTools");
21
22
  // export function groupPerspectiveLoadProps(
22
23
  // ...list: PerspectiveDataLoadPropsWithNode[]
23
24
  // ): PerspectiveDataLoadPropsWithNode[] {
@@ -102,6 +103,18 @@ class PerspectiveTreeNode {
102
103
  get generatesDataGridColumn() {
103
104
  return this.isCheckedColumn;
104
105
  }
106
+ get validParentDesignerId() {
107
+ var _a;
108
+ if (this.designerId)
109
+ return this.designerId;
110
+ return (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.validParentDesignerId;
111
+ }
112
+ get preloadedLevelData() {
113
+ return false;
114
+ }
115
+ get findByDesignerIdWithoutDesignerId() {
116
+ return false;
117
+ }
105
118
  matchChildRow(parentRow, childRow) {
106
119
  return true;
107
120
  }
@@ -178,7 +191,7 @@ class PerspectiveTreeNode {
178
191
  get hasUncheckedNodeInPath() {
179
192
  if (!this.parentNode)
180
193
  return false;
181
- if (!this.isCheckedNode)
194
+ if (this.designerId && !this.isCheckedNode)
182
195
  return true;
183
196
  return this.parentNode.hasUncheckedNodeInPath;
184
197
  }
@@ -334,7 +347,7 @@ class PerspectiveTreeNode {
334
347
  // return this.findChildNodeByUniquePath(uniquePath.slice(1));
335
348
  // }
336
349
  findNodeByDesignerId(designerId) {
337
- if (!this.designerId) {
350
+ if (!this.designerId && !this.findByDesignerIdWithoutDesignerId) {
338
351
  return null;
339
352
  }
340
353
  if (!designerId) {
@@ -631,13 +644,19 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
631
644
  this.column = column;
632
645
  this.tableColumn = tableColumn;
633
646
  this.parentNodeConfig = (_a = this.tableNodeOrParent) === null || _a === void 0 ? void 0 : _a.nodeConfig;
647
+ // console.log('PATTERN COLUMN', column);
634
648
  }
635
649
  get isChildColumn() {
636
650
  return this.parentNode instanceof PerspectivePatternColumnNode;
637
651
  }
652
+ get findByDesignerIdWithoutDesignerId() {
653
+ return this.isExpandable;
654
+ }
638
655
  // 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];
656
+ // console.log('MATCH PATTENR ROW', parentRow, childRow);
657
+ // return false;
658
+ // // if (!this.foreignKey) return false;
659
+ // // return parentRow[this.foreignKey.columns[0].columnName] == childRow[this.foreignKey.columns[0].refColumnName];
641
660
  // }
642
661
  // getChildMatchColumns() {
643
662
  // if (!this.foreignKey) return [];
@@ -674,12 +693,18 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
674
693
  // }));
675
694
  // }
676
695
  getNodeLoadProps(parentRows) {
696
+ // console.log('GETTING PATTERN', parentRows);
677
697
  return null;
678
698
  }
679
699
  get generatesHiearchicGridColumn() {
680
700
  var _a, _b, _c;
701
+ // return true;
681
702
  // 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 + '::')));
703
+ if ((_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 + '::'))) {
704
+ return true;
705
+ }
706
+ // return false;
707
+ return this.hasCheckedJoinChild();
683
708
  }
684
709
  // get generatesHiearchicGridColumn() {
685
710
  // // return this.config &&;
@@ -716,9 +741,81 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
716
741
  return (0, dbgate_filterparser_1.getFilterType)(this.tableColumn.dataType);
717
742
  return 'mongo';
718
743
  }
719
- generateChildNodes() {
744
+ get preloadedLevelData() {
745
+ return true;
746
+ }
747
+ generatePatternChildNodes() {
720
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));
721
- return [];
749
+ }
750
+ hasCheckedJoinChild() {
751
+ for (const node of this.childNodes) {
752
+ if (node instanceof PerspectivePatternColumnNode) {
753
+ if (node.hasCheckedJoinChild())
754
+ return true;
755
+ }
756
+ if (node.isCheckedNode)
757
+ return true;
758
+ }
759
+ return false;
760
+ }
761
+ generateChildNodes() {
762
+ var _a, _b, _c, _d, _e;
763
+ const patternChildren = this.generatePatternChildNodes();
764
+ const customs = [];
765
+ // console.log('GETTING CHILDREN', this.config.nodes, this.config.references);
766
+ for (const node of this.config.nodes) {
767
+ for (const ref of this.config.references) {
768
+ const validDesignerId = this.validParentDesignerId;
769
+ if ((ref.sourceId == validDesignerId && ref.targetId == node.designerId) ||
770
+ (ref.targetId == validDesignerId && ref.sourceId == node.designerId)) {
771
+ // console.log('TESTING REF', ref, this.codeName);
772
+ if (ref.columns.length != 1)
773
+ continue;
774
+ // console.log('CP1');
775
+ if (ref.sourceId == validDesignerId &&
776
+ this.codeName == (0, perspectiveTools_1.getPerspectiveParentColumnName)(ref.columns[0].source)) {
777
+ if (ref.columns[0].target.includes('::'))
778
+ continue;
779
+ }
780
+ else if (ref.targetId == validDesignerId &&
781
+ this.codeName == (0, perspectiveTools_1.getPerspectiveParentColumnName)(ref.columns[0].target)) {
782
+ if (ref.columns[0].source.includes('::'))
783
+ continue;
784
+ }
785
+ else {
786
+ continue;
787
+ }
788
+ // console.log('CP2');
789
+ const newConfig = Object.assign({}, this.databaseConfig);
790
+ if (node.conid)
791
+ newConfig.conid = node.conid;
792
+ if (node.database)
793
+ newConfig.database = node.database;
794
+ const db = (_b = (_a = this.dbs) === null || _a === void 0 ? void 0 : _a[newConfig.conid]) === null || _b === void 0 ? void 0 : _b[newConfig.database];
795
+ 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);
796
+ 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);
797
+ const collection = (_e = db === null || db === void 0 ? void 0 : db.collections) === null || _e === void 0 ? void 0 : _e.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
798
+ const join = {
799
+ refNodeDesignerId: node.designerId,
800
+ referenceDesignerId: ref.designerId,
801
+ baseDesignerId: validDesignerId,
802
+ joinName: node.alias,
803
+ refTableName: node.pureName,
804
+ refSchemaName: node.schemaName,
805
+ conid: node.conid,
806
+ database: node.database,
807
+ columns: ref.sourceId == validDesignerId
808
+ ? ref.columns.map(col => ({ baseColumnName: col.source, refColumnName: col.target }))
809
+ : ref.columns.map(col => ({ baseColumnName: col.target, refColumnName: col.source })),
810
+ };
811
+ 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));
813
+ }
814
+ }
815
+ }
816
+ }
817
+ return [...patternChildren, ...customs];
818
+ // return [];
722
819
  // if (!this.foreignKey) return [];
723
820
  // const tbl = this?.db?.tables?.find(
724
821
  // x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
@@ -919,8 +1016,9 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
919
1016
  this.dataProvider = dataProvider;
920
1017
  }
921
1018
  matchChildRow(parentRow, childRow) {
1019
+ // console.log('MATCH ROW', parentRow, childRow);
922
1020
  for (const column of this.customJoin.columns) {
923
- if (parentRow[column.baseColumnName] != childRow[column.refColumnName]) {
1021
+ if (!(0, perspectiveTools_1.perspectiveValueMatcher)(parentRow[(0, perspectiveTools_1.getPerspectiveMostNestedChildColumnName)(column.baseColumnName)], childRow[column.refColumnName])) {
924
1022
  return false;
925
1023
  }
926
1024
  }
@@ -934,13 +1032,55 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
934
1032
  }
935
1033
  getNodeLoadProps(parentRows) {
936
1034
  // console.log('CUSTOM JOIN', this.customJoin);
1035
+ // console.log('PARENT ROWS', parentRows);
937
1036
  // console.log('this.getDataLoadColumns()', this.getDataLoadColumns());
938
1037
  const isMongo = (0, dbgate_tools_1.isCollectionInfo)(this.table);
1038
+ // const bindingValues = [];
1039
+ // for (const row of parentRows) {
1040
+ // const rowBindingValueArrays = [];
1041
+ // for (const col of this.customJoin.columns) {
1042
+ // const path = col.baseColumnName.split('::');
1043
+ // const values = [];
1044
+ // function processSubpath(parent, subpath) {
1045
+ // if (subpath.length == 0) {
1046
+ // values.push(parent);
1047
+ // return;
1048
+ // }
1049
+ // if (parent == null) {
1050
+ // return;
1051
+ // }
1052
+ // const obj = parent[subpath[0]];
1053
+ // if (_isArray(obj)) {
1054
+ // for (const elem of obj) {
1055
+ // processSubpath(elem, subpath.slice(1));
1056
+ // }
1057
+ // } else {
1058
+ // processSubpath(obj, subpath.slice(1));
1059
+ // }
1060
+ // }
1061
+ // processSubpath(row, path);
1062
+ // rowBindingValueArrays.push(values);
1063
+ // }
1064
+ // const valueCount = Math.max(...rowBindingValueArrays.map(x => x.length));
1065
+ // for (let i = 0; i < valueCount; i += 1) {
1066
+ // const value = Array(this.customJoin.columns.length);
1067
+ // for (let col = 0; col < this.customJoin.columns.length; col++) {
1068
+ // value[col] = rowBindingValueArrays[col][i % rowBindingValueArrays[col].length];
1069
+ // }
1070
+ // bindingValues.push(value);
1071
+ // }
1072
+ // }
1073
+ const bindingValues = parentRows.map(row => this.customJoin.columns.map(x => row[(0, perspectiveTools_1.getPerspectiveMostNestedChildColumnName)(x.baseColumnName)]));
1074
+ // console.log('bindingValues', bindingValues);
1075
+ // console.log(
1076
+ // 'bindingValues UNIQ',
1077
+ // _uniqBy(bindingValues, x => JSON.stringify(x))
1078
+ // );
939
1079
  return {
940
1080
  schemaName: this.table.schemaName,
941
1081
  pureName: this.table.pureName,
942
1082
  bindingColumns: this.getParentMatchColumns(),
943
- bindingValues: (0, uniqBy_1.default)(parentRows.map(row => this.customJoin.columns.map(x => row[x.baseColumnName])), json_stable_stringify_1.default),
1083
+ bindingValues: (0, uniqBy_1.default)(bindingValues, x => JSON.stringify(x)),
944
1084
  dataColumns: this.getDataLoadColumns(),
945
1085
  allColumns: isMongo,
946
1086
  databaseConfig: this.databaseConfig,
@@ -1059,6 +1199,9 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
1059
1199
  for (const ref of config.references) {
1060
1200
  if ((ref.sourceId == parentNode.designerId && ref.targetId == node.designerId) ||
1061
1201
  (ref.targetId == parentNode.designerId && ref.sourceId == node.designerId)) {
1202
+ if (ref.columns.find(x => x.source.includes('::') || x.target.includes('::'))) {
1203
+ continue;
1204
+ }
1062
1205
  const newConfig = Object.assign({}, databaseConfig);
1063
1206
  if (node.conid)
1064
1207
  newConfig.conid = node.conid;
package/lib/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from './PerspectiveConfig';
21
21
  export * from './processPerspectiveDefaultColunns';
22
22
  export * from './PerspectiveDataPattern';
23
23
  export * from './PerspectiveDataLoader';
24
+ export * from './perspectiveTools';
package/lib/index.js CHANGED
@@ -37,3 +37,4 @@ __exportStar(require("./PerspectiveConfig"), exports);
37
37
  __exportStar(require("./processPerspectiveDefaultColunns"), exports);
38
38
  __exportStar(require("./PerspectiveDataPattern"), exports);
39
39
  __exportStar(require("./PerspectiveDataLoader"), exports);
40
+ __exportStar(require("./perspectiveTools"), exports);
@@ -0,0 +1,3 @@
1
+ export declare function getPerspectiveParentColumnName(columnName: string): string;
2
+ export declare function getPerspectiveMostNestedChildColumnName(columnName: string): string;
3
+ export declare function perspectiveValueMatcher(value1: any, value2: any): boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.perspectiveValueMatcher = exports.getPerspectiveMostNestedChildColumnName = exports.getPerspectiveParentColumnName = void 0;
4
+ function getPerspectiveParentColumnName(columnName) {
5
+ const path = columnName.split('::');
6
+ if (path.length >= 2)
7
+ return path.slice(0, -1).join('::');
8
+ return null;
9
+ }
10
+ exports.getPerspectiveParentColumnName = getPerspectiveParentColumnName;
11
+ function getPerspectiveMostNestedChildColumnName(columnName) {
12
+ const path = columnName.split('::');
13
+ return path[path.length - 1];
14
+ }
15
+ exports.getPerspectiveMostNestedChildColumnName = getPerspectiveMostNestedChildColumnName;
16
+ // export function perspectiveValueMatcher(value1, value2): boolean {
17
+ // if (value1?.$oid && value2?.$oid) return value1.$oid == value2.$oid;
18
+ // if (Array.isArray(value1)) return !!value1.find(x => perspectiveValueMatcher(x, value2));
19
+ // if (Array.isArray(value2)) return !!value2.find(x => perspectiveValueMatcher(value1, x));
20
+ // return value1 == value2;
21
+ // }
22
+ function perspectiveValueMatcher(value1, value2) {
23
+ if ((value1 === null || value1 === void 0 ? void 0 : value1.$oid) && (value2 === null || value2 === void 0 ? void 0 : value2.$oid))
24
+ return value1.$oid == value2.$oid;
25
+ return value1 == value2;
26
+ }
27
+ exports.perspectiveValueMatcher = perspectiveValueMatcher;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.1.6",
2
+ "version": "5.1.7-alpha.13",
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.1.6",
17
- "dbgate-tools": "^5.1.6",
18
- "dbgate-filterparser": "^5.1.6"
16
+ "dbgate-sqltree": "^5.1.7-alpha.13",
17
+ "dbgate-tools": "^5.1.7-alpha.13",
18
+ "dbgate-filterparser": "^5.1.7-alpha.13"
19
19
  },
20
20
  "devDependencies": {
21
- "dbgate-types": "^5.1.6",
21
+ "dbgate-types": "^5.1.7-alpha.13",
22
22
  "@types/node": "^13.7.0",
23
23
  "jest": "^28.1.3",
24
24
  "ts-jest": "^28.0.7",