dbgate-datalib 5.0.7 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,8 +14,8 @@ export declare class FreeTableGridDisplay extends GridDisplay {
14
14
  uniquePath: string[];
15
15
  pairingId?: string;
16
16
  columnName: string;
17
- notNull: boolean;
18
- autoIncrement: boolean;
17
+ notNull?: boolean;
18
+ autoIncrement?: boolean;
19
19
  dataType: string;
20
20
  precision?: number;
21
21
  scale?: number;
@@ -28,6 +28,8 @@ export declare class FreeTableGridDisplay extends GridDisplay {
28
28
  columnComment?: string;
29
29
  isUnsigned?: boolean;
30
30
  isZerofill?: boolean;
31
+ contentHash?: string;
32
+ engine?: string;
31
33
  }[];
32
34
  getDisplayColumn(col: ColumnInfo): {
33
35
  pureName: string;
@@ -37,8 +39,8 @@ export declare class FreeTableGridDisplay extends GridDisplay {
37
39
  uniquePath: string[];
38
40
  pairingId?: string;
39
41
  columnName: string;
40
- notNull: boolean;
41
- autoIncrement: boolean;
42
+ notNull?: boolean;
43
+ autoIncrement?: boolean;
42
44
  dataType: string;
43
45
  precision?: number;
44
46
  scale?: number;
@@ -51,5 +53,7 @@ export declare class FreeTableGridDisplay extends GridDisplay {
51
53
  columnComment?: string;
52
54
  isUnsigned?: boolean;
53
55
  isZerofill?: boolean;
56
+ contentHash?: string;
57
+ engine?: string;
54
58
  };
55
59
  }
@@ -9,7 +9,7 @@ export interface DisplayColumn {
9
9
  headerText: string;
10
10
  uniqueName: string;
11
11
  uniquePath: string[];
12
- notNull: boolean;
12
+ notNull?: boolean;
13
13
  autoIncrement?: boolean;
14
14
  isPrimaryKey?: boolean;
15
15
  foreignKey?: ForeignKeyInfo;
@@ -0,0 +1,39 @@
1
+ import { PerspectiveDataLoadProps } from './PerspectiveDataProvider';
2
+ export declare class PerspectiveBindingGroup {
3
+ table: PerspectiveCacheTable;
4
+ constructor(table: PerspectiveCacheTable);
5
+ groupSize?: number;
6
+ loadedAll: boolean;
7
+ loadedRows: any[];
8
+ bindingValues: any[];
9
+ matchRow(row: any): boolean;
10
+ }
11
+ export declare class PerspectiveCacheTable {
12
+ cache: PerspectiveCache;
13
+ constructor(props: PerspectiveDataLoadProps, cache: PerspectiveCache);
14
+ schemaName: string;
15
+ pureName: string;
16
+ bindingColumns?: string[];
17
+ dataColumns: string[];
18
+ loadedAll: boolean;
19
+ loadedRows: any[];
20
+ bindingGroups: {
21
+ [bindingKey: string]: PerspectiveBindingGroup;
22
+ };
23
+ get loadedCount(): number;
24
+ getRowsResult(props: PerspectiveDataLoadProps): {
25
+ rows: any[];
26
+ incomplete: boolean;
27
+ };
28
+ getBindingGroup(groupValues: any[]): PerspectiveBindingGroup;
29
+ getUncachedBindingGroups(props: PerspectiveDataLoadProps): any[][];
30
+ storeGroupSize(props: PerspectiveDataLoadProps, bindingValues: any[], count: number): void;
31
+ }
32
+ export declare class PerspectiveCache {
33
+ constructor();
34
+ tables: {
35
+ [tableKey: string]: PerspectiveCacheTable;
36
+ };
37
+ getTableCache(props: PerspectiveDataLoadProps): PerspectiveCacheTable;
38
+ clear(): void;
39
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PerspectiveCache = exports.PerspectiveCacheTable = exports.PerspectiveBindingGroup = void 0;
7
+ const pick_1 = __importDefault(require("lodash/pick"));
8
+ const zip_1 = __importDefault(require("lodash/zip"));
9
+ const difference_1 = __importDefault(require("lodash/difference"));
10
+ const debug_1 = __importDefault(require("debug"));
11
+ const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
12
+ const dbg = (0, debug_1.default)('dbgate:PerspectiveCache');
13
+ class PerspectiveBindingGroup {
14
+ constructor(table) {
15
+ this.table = table;
16
+ this.loadedRows = [];
17
+ }
18
+ matchRow(row) {
19
+ return this.table.bindingColumns.every((column, index) => row[column] == this.bindingValues[index]);
20
+ }
21
+ }
22
+ exports.PerspectiveBindingGroup = PerspectiveBindingGroup;
23
+ class PerspectiveCacheTable {
24
+ constructor(props, cache) {
25
+ this.cache = cache;
26
+ this.loadedRows = [];
27
+ this.bindingGroups = {};
28
+ this.schemaName = props.schemaName;
29
+ this.pureName = props.pureName;
30
+ this.bindingColumns = props.bindingColumns;
31
+ this.dataColumns = props.dataColumns;
32
+ this.loadedAll = false;
33
+ }
34
+ get loadedCount() {
35
+ return this.loadedRows.length;
36
+ }
37
+ getRowsResult(props) {
38
+ return {
39
+ rows: this.loadedRows.slice(0, props.topCount),
40
+ incomplete: props.topCount < this.loadedCount || !this.loadedAll,
41
+ };
42
+ }
43
+ getBindingGroup(groupValues) {
44
+ const key = (0, json_stable_stringify_1.default)(groupValues);
45
+ return this.bindingGroups[key];
46
+ }
47
+ getUncachedBindingGroups(props) {
48
+ const uncached = [];
49
+ for (const group of props.bindingValues) {
50
+ const key = (0, json_stable_stringify_1.default)(group);
51
+ const item = this.bindingGroups[key];
52
+ if (!item) {
53
+ uncached.push(group);
54
+ }
55
+ }
56
+ return uncached;
57
+ }
58
+ storeGroupSize(props, bindingValues, count) {
59
+ const originalBindingValue = props.bindingValues.find(v => (0, zip_1.default)(v, bindingValues).every(([x, y]) => x == y));
60
+ if (originalBindingValue) {
61
+ const key = (0, json_stable_stringify_1.default)(originalBindingValue);
62
+ // console.log('SET SIZE', originalBindingValue, bindingValues, key, count);
63
+ const group = new PerspectiveBindingGroup(this);
64
+ group.bindingValues = bindingValues;
65
+ group.groupSize = count;
66
+ this.bindingGroups[key] = group;
67
+ }
68
+ else {
69
+ dbg('Group not found', bindingValues);
70
+ }
71
+ }
72
+ }
73
+ exports.PerspectiveCacheTable = PerspectiveCacheTable;
74
+ class PerspectiveCache {
75
+ constructor() {
76
+ this.tables = {};
77
+ }
78
+ getTableCache(props) {
79
+ const tableKey = (0, json_stable_stringify_1.default)((0, pick_1.default)(props, ['schemaName', 'pureName', 'bindingColumns', 'databaseConfig', 'orderBy', 'condition']));
80
+ let res = this.tables[tableKey];
81
+ if (res && (0, difference_1.default)(props.dataColumns, res.dataColumns).length > 0) {
82
+ dbg('Delete cache because incomplete columns', props.pureName, res.dataColumns);
83
+ // we have incomplete cache
84
+ delete this.tables[tableKey];
85
+ res = null;
86
+ }
87
+ if (!res) {
88
+ res = new PerspectiveCacheTable(props, this);
89
+ this.tables[tableKey] = res;
90
+ return res;
91
+ }
92
+ // cache could be used
93
+ return res;
94
+ }
95
+ clear() {
96
+ this.tables = {};
97
+ }
98
+ }
99
+ exports.PerspectiveCache = PerspectiveCache;
@@ -0,0 +1,63 @@
1
+ import { DatabaseInfo, ForeignKeyInfo } from 'dbgate-types';
2
+ export interface PerspectiveConfigColumns {
3
+ expandedColumns: string[];
4
+ checkedColumns: string[];
5
+ uncheckedColumns: string[];
6
+ }
7
+ export interface PerspectiveCustomJoinConfig {
8
+ joinid: string;
9
+ joinName: string;
10
+ baseUniqueName: string;
11
+ conid?: string;
12
+ database?: string;
13
+ refSchemaName?: string;
14
+ refTableName: string;
15
+ columns: {
16
+ baseColumnName: string;
17
+ refColumnName: string;
18
+ }[];
19
+ }
20
+ export interface PerspectiveFilterColumnInfo {
21
+ columnName: string;
22
+ filterType: string;
23
+ pureName: string;
24
+ schemaName: string;
25
+ foreignKey: ForeignKeyInfo;
26
+ }
27
+ export interface PerspectiveParentFilterConfig {
28
+ uniqueName: string;
29
+ }
30
+ export interface PerspectiveConfig extends PerspectiveConfigColumns {
31
+ rootObject: {
32
+ schemaName?: string;
33
+ pureName: string;
34
+ };
35
+ filters: {
36
+ [uniqueName: string]: string;
37
+ };
38
+ sort: {
39
+ [parentUniqueName: string]: {
40
+ uniqueName: string;
41
+ order: 'ASC' | 'DESC';
42
+ }[];
43
+ };
44
+ customJoins: PerspectiveCustomJoinConfig[];
45
+ parentFilters: PerspectiveParentFilterConfig[];
46
+ }
47
+ export declare function createPerspectiveConfig(rootObject: {
48
+ schemaName?: string;
49
+ pureName: string;
50
+ }): PerspectiveConfig;
51
+ export declare type ChangePerspectiveConfigFunc = (changeFunc: (config: PerspectiveConfig) => PerspectiveConfig, reload?: boolean) => void;
52
+ export declare function extractPerspectiveDatabases({ conid, database }: {
53
+ conid: any;
54
+ database: any;
55
+ }, cfg: PerspectiveConfig): {
56
+ conid: string;
57
+ database: string;
58
+ }[];
59
+ export interface MultipleDatabaseInfo {
60
+ [conid: string]: {
61
+ [database: string]: DatabaseInfo;
62
+ };
63
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractPerspectiveDatabases = exports.createPerspectiveConfig = void 0;
4
+ function createPerspectiveConfig(rootObject) {
5
+ return {
6
+ expandedColumns: [],
7
+ checkedColumns: [],
8
+ uncheckedColumns: [],
9
+ customJoins: [],
10
+ filters: {},
11
+ sort: {},
12
+ rootObject,
13
+ parentFilters: [],
14
+ };
15
+ }
16
+ exports.createPerspectiveConfig = createPerspectiveConfig;
17
+ function extractPerspectiveDatabases({ conid, database }, cfg) {
18
+ const res = [];
19
+ res.push({ conid, database });
20
+ function add(conid, database) {
21
+ if (res.find(x => x.conid == conid && x.database == database))
22
+ return;
23
+ res.push({ conid, database });
24
+ }
25
+ for (const custom of cfg.customJoins) {
26
+ add(custom.conid || conid, custom.database || database);
27
+ }
28
+ return res;
29
+ }
30
+ exports.extractPerspectiveDatabases = extractPerspectiveDatabases;
@@ -0,0 +1,9 @@
1
+ import { Condition } from 'dbgate-sqltree';
2
+ import { PerspectiveDataLoadProps } from './PerspectiveDataProvider';
3
+ export declare class PerspectiveDataLoader {
4
+ apiCall: any;
5
+ constructor(apiCall: any);
6
+ buildCondition(props: PerspectiveDataLoadProps): Condition;
7
+ loadGrouping(props: PerspectiveDataLoadProps): Promise<any>;
8
+ loadData(props: PerspectiveDataLoadProps): Promise<any>;
9
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PerspectiveDataLoader = void 0;
16
+ const debug_1 = __importDefault(require("debug"));
17
+ const dbg = (0, debug_1.default)('dbgate:PerspectiveDataLoader');
18
+ class PerspectiveDataLoader {
19
+ constructor(apiCall) {
20
+ this.apiCall = apiCall;
21
+ }
22
+ buildCondition(props) {
23
+ const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props;
24
+ const conditions = [];
25
+ if (condition) {
26
+ conditions.push(condition);
27
+ }
28
+ if ((bindingColumns === null || bindingColumns === void 0 ? void 0 : bindingColumns.length) == 1) {
29
+ conditions.push({
30
+ conditionType: 'in',
31
+ expr: {
32
+ exprType: 'column',
33
+ columnName: bindingColumns[0],
34
+ source: {
35
+ name: { schemaName, pureName },
36
+ },
37
+ },
38
+ values: bindingValues.map(x => x[0]),
39
+ });
40
+ }
41
+ return conditions.length > 0
42
+ ? {
43
+ conditionType: 'and',
44
+ conditions,
45
+ }
46
+ : null;
47
+ }
48
+ loadGrouping(props) {
49
+ var _a;
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const { schemaName, pureName, bindingColumns, bindingValues, dataColumns } = props;
52
+ const bindingColumnExpressions = bindingColumns.map(columnName => ({
53
+ exprType: 'column',
54
+ columnName,
55
+ source: {
56
+ name: { schemaName, pureName },
57
+ },
58
+ }));
59
+ const select = {
60
+ commandType: 'select',
61
+ from: {
62
+ name: { schemaName, pureName },
63
+ },
64
+ columns: [
65
+ {
66
+ exprType: 'call',
67
+ func: 'COUNT',
68
+ args: [
69
+ {
70
+ exprType: 'raw',
71
+ sql: '*',
72
+ },
73
+ ],
74
+ alias: '_perspective_group_size_',
75
+ },
76
+ ...bindingColumnExpressions,
77
+ ],
78
+ where: this.buildCondition(props),
79
+ };
80
+ select.groupBy = bindingColumnExpressions;
81
+ if (dbg === null || dbg === void 0 ? void 0 : dbg.enabled) {
82
+ dbg(`LOAD COUNTS, table=${props.pureName}, columns=${(_a = props.dataColumns) === null || _a === void 0 ? void 0 : _a.join(',')}`);
83
+ }
84
+ const response = yield this.apiCall('database-connections/sql-select', {
85
+ conid: props.databaseConfig.conid,
86
+ database: props.databaseConfig.database,
87
+ select,
88
+ });
89
+ if (response.errorMessage)
90
+ return response;
91
+ return response.rows.map(row => (Object.assign(Object.assign({}, row), { _perspective_group_size_: parseInt(row._perspective_group_size_) })));
92
+ });
93
+ }
94
+ loadData(props) {
95
+ var _a, _b, _c;
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props;
98
+ const select = {
99
+ commandType: 'select',
100
+ from: {
101
+ name: { schemaName, pureName },
102
+ },
103
+ columns: dataColumns === null || dataColumns === void 0 ? void 0 : dataColumns.map(columnName => ({
104
+ exprType: 'column',
105
+ columnName,
106
+ source: {
107
+ name: { schemaName, pureName },
108
+ },
109
+ })),
110
+ selectAll: !dataColumns,
111
+ orderBy: orderBy === null || orderBy === void 0 ? void 0 : orderBy.map(({ columnName, order }) => ({
112
+ exprType: 'column',
113
+ columnName,
114
+ direction: order,
115
+ source: {
116
+ name: { schemaName, pureName },
117
+ },
118
+ })),
119
+ range: props.range,
120
+ where: this.buildCondition(props),
121
+ };
122
+ if (dbg === null || dbg === void 0 ? void 0 : dbg.enabled) {
123
+ dbg(`LOAD DATA, table=${props.pureName}, columns=${(_a = props.dataColumns) === null || _a === void 0 ? void 0 : _a.join(',')}, range=${(_b = props.range) === null || _b === void 0 ? void 0 : _b.offset},${(_c = props.range) === null || _c === void 0 ? void 0 : _c.limit}`);
124
+ }
125
+ const response = yield this.apiCall('database-connections/sql-select', {
126
+ conid: props.databaseConfig.conid,
127
+ database: props.databaseConfig.database,
128
+ select,
129
+ });
130
+ if (response.errorMessage)
131
+ return response;
132
+ return response.rows;
133
+ });
134
+ }
135
+ }
136
+ exports.PerspectiveDataLoader = PerspectiveDataLoader;
@@ -0,0 +1,42 @@
1
+ import { Condition } from 'dbgate-sqltree';
2
+ import { RangeDefinition } from 'dbgate-types';
3
+ import { PerspectiveCache } from './PerspectiveCache';
4
+ import { PerspectiveDataLoader } from './PerspectiveDataLoader';
5
+ export declare const PERSPECTIVE_PAGE_SIZE = 100;
6
+ export interface PerspectiveDatabaseConfig {
7
+ conid: string;
8
+ database: string;
9
+ }
10
+ export interface PerspectiveDataLoadProps {
11
+ databaseConfig: PerspectiveDatabaseConfig;
12
+ schemaName: string;
13
+ pureName: string;
14
+ dataColumns: string[];
15
+ orderBy: {
16
+ columnName: string;
17
+ order: 'ASC' | 'DESC';
18
+ }[];
19
+ bindingColumns?: string[];
20
+ bindingValues?: any[][];
21
+ range?: RangeDefinition;
22
+ topCount?: number;
23
+ condition?: Condition;
24
+ }
25
+ export declare class PerspectiveDataProvider {
26
+ cache: PerspectiveCache;
27
+ loader: PerspectiveDataLoader;
28
+ constructor(cache: PerspectiveCache, loader: PerspectiveDataLoader);
29
+ loadData(props: PerspectiveDataLoadProps): Promise<{
30
+ rows: any[];
31
+ incomplete: boolean;
32
+ }>;
33
+ loadDataNested(props: PerspectiveDataLoadProps): Promise<{
34
+ rows: any[];
35
+ incomplete: boolean;
36
+ }>;
37
+ loadNextGroup(props: PerspectiveDataLoadProps, groupIndex: number): Promise<void>;
38
+ loadDataFlat(props: PerspectiveDataLoadProps): Promise<{
39
+ rows: any[];
40
+ incomplete: boolean;
41
+ }>;
42
+ }
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.PerspectiveDataProvider = exports.PERSPECTIVE_PAGE_SIZE = void 0;
27
+ const debug_1 = __importDefault(require("debug"));
28
+ exports.PERSPECTIVE_PAGE_SIZE = 100;
29
+ const dbg = (0, debug_1.default)('dbgate:PerspectiveDataProvider');
30
+ class PerspectiveDataProvider {
31
+ constructor(cache, loader) {
32
+ this.cache = cache;
33
+ this.loader = loader;
34
+ }
35
+ loadData(props) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ dbg('load data', props);
38
+ // console.log('LOAD DATA', props);
39
+ if (props.bindingColumns) {
40
+ return this.loadDataNested(props);
41
+ }
42
+ else {
43
+ return this.loadDataFlat(props);
44
+ }
45
+ });
46
+ }
47
+ loadDataNested(props) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const tableCache = this.cache.getTableCache(props);
50
+ const uncached = tableCache.getUncachedBindingGroups(props);
51
+ if (uncached.length > 0) {
52
+ const counts = yield this.loader.loadGrouping(Object.assign(Object.assign({}, props), { bindingValues: uncached }));
53
+ // console.log('COUNTS', counts);
54
+ for (const resetItem of uncached) {
55
+ tableCache.storeGroupSize(props, resetItem, 0);
56
+ }
57
+ for (const countItem of counts) {
58
+ const { _perspective_group_size_ } = countItem, fields = __rest(countItem, ["_perspective_group_size_"]);
59
+ tableCache.storeGroupSize(props, props.bindingColumns.map(col => fields[col]), _perspective_group_size_);
60
+ }
61
+ }
62
+ const rows = [];
63
+ // console.log('CACHE', tableCache.bindingGroups);
64
+ let groupIndex = 0;
65
+ let loadCalled = false;
66
+ let shouldReturn = false;
67
+ for (; groupIndex < props.bindingValues.length; groupIndex++) {
68
+ const groupValues = props.bindingValues[groupIndex];
69
+ const group = tableCache.getBindingGroup(groupValues);
70
+ if (!group.loadedAll) {
71
+ if (loadCalled) {
72
+ shouldReturn = true;
73
+ }
74
+ else {
75
+ // we need to load next data
76
+ yield this.loadNextGroup(props, groupIndex);
77
+ loadCalled = true;
78
+ }
79
+ }
80
+ // console.log('GRP', groupValues, group);
81
+ rows.push(...group.loadedRows);
82
+ if (rows.length >= props.topCount || shouldReturn) {
83
+ return {
84
+ rows: rows.slice(0, props.topCount),
85
+ incomplete: props.topCount < rows.length || !group.loadedAll || groupIndex < props.bindingValues.length - 1,
86
+ };
87
+ }
88
+ }
89
+ if (groupIndex >= props.bindingValues.length) {
90
+ // all groups are fully loaded
91
+ return { rows, incomplete: false };
92
+ }
93
+ });
94
+ }
95
+ loadNextGroup(props, groupIndex) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const tableCache = this.cache.getTableCache(props);
98
+ const planLoadingGroupIndexes = [];
99
+ const planLoadingGroups = [];
100
+ let planLoadRowCount = 0;
101
+ const loadPlanned = () => __awaiter(this, void 0, void 0, function* () {
102
+ // console.log(
103
+ // 'LOAD PLANNED',
104
+ // planLoadingGroupIndexes,
105
+ // planLoadingGroupIndexes.map(idx => props.bindingValues[idx])
106
+ // );
107
+ const rows = yield this.loader.loadData(Object.assign(Object.assign({}, props), { bindingValues: planLoadingGroupIndexes.map(idx => props.bindingValues[idx]) }));
108
+ // console.log('LOADED PLANNED', rows);
109
+ // distribute rows into groups
110
+ for (const row of rows) {
111
+ const group = planLoadingGroups.find(x => x.matchRow(row));
112
+ if (group) {
113
+ group.loadedRows.push(row);
114
+ }
115
+ }
116
+ for (const group of planLoadingGroups) {
117
+ group.loadedAll = true;
118
+ }
119
+ });
120
+ for (; groupIndex < props.bindingValues.length; groupIndex++) {
121
+ const groupValues = props.bindingValues[groupIndex];
122
+ const group = tableCache.getBindingGroup(groupValues);
123
+ if (group.loadedAll)
124
+ continue;
125
+ if (group.groupSize == 0) {
126
+ group.loadedAll = true;
127
+ continue;
128
+ }
129
+ if (group.groupSize >= exports.PERSPECTIVE_PAGE_SIZE) {
130
+ if (planLoadingGroupIndexes.length > 0) {
131
+ yield loadPlanned();
132
+ return;
133
+ }
134
+ const nextRows = yield this.loader.loadData(Object.assign(Object.assign({}, props), { topCount: null, range: {
135
+ offset: group.loadedRows.length,
136
+ limit: exports.PERSPECTIVE_PAGE_SIZE,
137
+ }, bindingValues: [group.bindingValues] }));
138
+ group.loadedRows = [...group.loadedRows, ...nextRows];
139
+ group.loadedAll = nextRows.length < exports.PERSPECTIVE_PAGE_SIZE;
140
+ return;
141
+ }
142
+ else {
143
+ if (planLoadRowCount + group.groupSize > exports.PERSPECTIVE_PAGE_SIZE) {
144
+ yield loadPlanned();
145
+ return;
146
+ }
147
+ planLoadingGroupIndexes.push(groupIndex);
148
+ planLoadingGroups.push(group);
149
+ planLoadRowCount += group.groupSize;
150
+ }
151
+ }
152
+ if (planLoadingGroupIndexes.length > 0) {
153
+ yield loadPlanned();
154
+ }
155
+ });
156
+ }
157
+ loadDataFlat(props) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ const tableCache = this.cache.getTableCache(props);
160
+ if (props.topCount <= tableCache.loadedCount) {
161
+ return tableCache.getRowsResult(props);
162
+ }
163
+ // load missing rows
164
+ tableCache.dataColumns = props.dataColumns;
165
+ const nextRows = yield this.loader.loadData(Object.assign(Object.assign({}, props), { topCount: null, range: {
166
+ offset: tableCache.loadedCount,
167
+ limit: props.topCount - tableCache.loadedCount,
168
+ } }));
169
+ if (nextRows.errorMessage) {
170
+ throw new Error(nextRows.errorMessage);
171
+ }
172
+ tableCache.loadedRows = [...tableCache.loadedRows, ...nextRows];
173
+ tableCache.loadedAll = nextRows.length < props.topCount - tableCache.loadedCount;
174
+ // const rows=tableCache.getRows(props);
175
+ return tableCache.getRowsResult(props);
176
+ });
177
+ }
178
+ }
179
+ exports.PerspectiveDataProvider = PerspectiveDataProvider;