@genesislcap/grid-pro 14.199.3-alpha-40ecfcd.0 → 14.200.0-FUI-2127.3

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.
Files changed (44) hide show
  1. package/README.md +111 -117
  2. package/dist/custom-elements.json +841 -2743
  3. package/dist/dts/datasource/base.datasource.d.ts +6 -22
  4. package/dist/dts/datasource/base.datasource.d.ts.map +1 -1
  5. package/dist/dts/datasource/server-side.datasource.d.ts +83 -27
  6. package/dist/dts/datasource/server-side.datasource.d.ts.map +1 -1
  7. package/dist/dts/datasource/server-side.grid-definitions.d.ts.map +1 -1
  8. package/dist/dts/grid-pro-genesis-datasource/grid-pro-genesis-datasource.d.ts +13 -13
  9. package/dist/dts/grid-pro-genesis-datasource/grid-pro-genesis-datasource.d.ts.map +1 -1
  10. package/dist/dts/grid-pro.d.ts +2 -16
  11. package/dist/dts/grid-pro.d.ts.map +1 -1
  12. package/dist/esm/datasource/base.datasource.js +9 -79
  13. package/dist/esm/datasource/client-side.grid-definitions.js +1 -1
  14. package/dist/esm/datasource/server-side.datasource.js +396 -220
  15. package/dist/esm/datasource/server-side.grid-definitions.js +7 -42
  16. package/dist/esm/grid-pro-genesis-datasource/grid-pro-genesis-datasource.js +61 -55
  17. package/dist/esm/grid-pro.js +4 -7
  18. package/dist/grid-pro.api.json +142 -21
  19. package/dist/grid-pro.d.ts +112 -77
  20. package/docs/api/grid-pro.gridpro.addeventlistener.md +2 -2
  21. package/docs/api/grid-pro.gridpro.md +1 -1
  22. package/docs/api/{grid-pro.gridprogenesisdatasource.destroy.md → grid-pro.gridprogenesisdatasource.auth.md} +3 -9
  23. package/docs/api/grid-pro.gridprogenesisdatasource.datasource.md +11 -0
  24. package/docs/api/grid-pro.gridprogenesisdatasource.deinit.md +0 -5
  25. package/docs/api/grid-pro.gridprogenesisdatasource.disablepolling.md +11 -0
  26. package/docs/api/grid-pro.gridprogenesisdatasource.handleerrors.md +2 -2
  27. package/docs/api/grid-pro.gridprogenesisdatasource.md +6 -2
  28. package/docs/api/grid-pro.gridprogenesisdatasource.pollinginterval.md +11 -0
  29. package/docs/api/grid-pro.gridprogenesisdatasource.request.md +11 -0
  30. package/docs/api/grid-pro.gridprogenesisdatasource.reset.md +1 -1
  31. package/docs/api-report.md +68 -19
  32. package/package.json +13 -13
  33. package/dist/dts/datasource/base.types.d.ts +0 -22
  34. package/dist/dts/datasource/base.types.d.ts.map +0 -1
  35. package/dist/dts/datasource/server-side.resource-base.d.ts +0 -55
  36. package/dist/dts/datasource/server-side.resource-base.d.ts.map +0 -1
  37. package/dist/dts/datasource/server-side.resource-dataserver.d.ts +0 -20
  38. package/dist/dts/datasource/server-side.resource-dataserver.d.ts.map +0 -1
  39. package/dist/dts/datasource/server-side.resource-reqrep.d.ts +0 -17
  40. package/dist/dts/datasource/server-side.resource-reqrep.d.ts.map +0 -1
  41. package/dist/esm/datasource/base.types.js +0 -1
  42. package/dist/esm/datasource/server-side.resource-base.js +0 -285
  43. package/dist/esm/datasource/server-side.resource-dataserver.js +0 -132
  44. package/dist/esm/datasource/server-side.resource-reqrep.js +0 -131
@@ -1,17 +1,286 @@
1
1
  import { __awaiter, __decorate } from "tslib";
2
- import { Events, } from '@ag-grid-community/core';
3
- import { dataServerResultFilter, MessageType, normaliseCriteria, toFieldMetadata, } from '@genesislcap/foundation-comms';
2
+ import { Auth, Connect, dataServerResultFilter, extractFieldDefinitions, MessageType, normaliseCriteria, toFieldMetadata, } from '@genesislcap/foundation-comms';
4
3
  import { LifecycleMixin } from '@genesislcap/foundation-utils';
5
- import { attr, customElement, DOM, observable } from '@microsoft/fast-element';
6
- import { gridProGenesisDatasourceEventNames } from '../grid-pro-genesis-datasource';
7
- import { logger } from '../utils';
8
- import { GridProBaseDatasource } from './base.datasource';
4
+ import { attr, customElement, DOM } from '@microsoft/fast-element';
5
+ import { getAvailableIndexes, getAvailableIndexFields, logger } from '../utils';
6
+ import { GridProBaseDatasource, StreamBaseDatasource } from './base.datasource';
9
7
  import { getServerSideFilterParamsByFieldType } from './server-side.grid-definitions';
10
- import { DataserverServerSideDatasource } from './server-side.resource-dataserver';
11
- import { ReqRepServerSideDatasource } from './server-side.resource-reqrep';
8
+ /**
9
+ * The IServerSideDatasource implementation, used for SSRM (Server-Side Row Model) in the grid.
10
+ * @alpha
11
+ */
12
+ export class StreamDatasource extends StreamBaseDatasource {
13
+ constructor(options) {
14
+ super();
15
+ /**
16
+ * The number of rows in the grid. THIS DO NOT CONSIDER CRITERIA_MATCH scenarios.
17
+ * @internal
18
+ */
19
+ this.server_ROWS_COUNT = 0;
20
+ /**
21
+ * The number of rows in the grid. THIS IS A LOCAL COUNT CONSIDERING CONSIDER CRITERIA_MATCH scenarios.
22
+ * @internal
23
+ */
24
+ this.client_ROWS_COUNT = 0;
25
+ this.moreRows = false;
26
+ this.calculatedRowsCount = 0;
27
+ this.lastSequenceId = 0;
28
+ this.createDataserverStreamFunc = options.createDataserverStreamFunc;
29
+ this.resourceName = options.resourceName;
30
+ this.resourceParams = options.resourceParams;
31
+ this.originalCriteriaMatch = options.resourceParams.CRITERIA_MATCH;
32
+ this.resourceIndexes = options.resourceIndexes;
33
+ this.resourceColDefs = options.resourceColDefs;
34
+ this.maxRows = options.maxRows;
35
+ this.maxView = options.maxView;
36
+ this.rowId = options.rowId;
37
+ this.pagination = options.pagination;
38
+ }
39
+ getRows(params) {
40
+ var _a;
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const filterModelBeingApplied = params.request.filterModel;
43
+ const filtersAreBeingApplied = Object.keys(filterModelBeingApplied).length > 0;
44
+ const filtersAreGettingCleaned = Object.keys(filterModelBeingApplied).length === 0;
45
+ const filterModelBeingAppliedDiffersFromCurrent = JSON.stringify(filterModelBeingApplied) !== JSON.stringify(this.currentFilterModel);
46
+ if (filterModelBeingAppliedDiffersFromCurrent || filtersAreBeingApplied) {
47
+ if (filtersAreGettingCleaned && this.currentFilterModel) {
48
+ this.currentFilterModel = null;
49
+ this.resourceParams.CRITERIA_MATCH = this.originalCriteriaMatch;
50
+ yield this.refreshDatasource(params);
51
+ return;
52
+ }
53
+ else if (filterModelBeingAppliedDiffersFromCurrent && filtersAreBeingApplied) {
54
+ this.currentFilterModel = filterModelBeingApplied;
55
+ this.resourceParams.CRITERIA_MATCH = this.buildCriteriaMatchFromFilters();
56
+ yield this.refreshDatasource(params);
57
+ return;
58
+ }
59
+ }
60
+ const toBeAppliedSortModel = params.request.sortModel;
61
+ if (((_a = this.currentSortModel) === null || _a === void 0 ? void 0 : _a.length) !== toBeAppliedSortModel.length ||
62
+ toBeAppliedSortModel.length > 0) {
63
+ if (toBeAppliedSortModel.length === 0 && this.currentSortModel) {
64
+ this.calculatedRowsCount = 0;
65
+ this.currentSortModel = null;
66
+ this.resourceParams.ORDER_BY = null;
67
+ this.resourceParams.REVERSE = null;
68
+ yield this.refreshDatasource(params);
69
+ return;
70
+ }
71
+ else if (toBeAppliedSortModel.length > 0) {
72
+ this.currentSortModel = toBeAppliedSortModel;
73
+ const coldIdBeingSorted = toBeAppliedSortModel[0].colId; // Not allowing multiple sorts by user
74
+ const sortTypeBeingApplied = toBeAppliedSortModel[0].sort;
75
+ const orderByAndToBeSortedColIds = this.getOrderByAndToBeSortedColIds(this.resourceIndexes, coldIdBeingSorted);
76
+ if (!orderByAndToBeSortedColIds) {
77
+ this.calculatedRowsCount = 0;
78
+ const availableIndexes = getAvailableIndexes(this.resourceIndexes);
79
+ const availableIndexFields = getAvailableIndexFields(this.resourceIndexes);
80
+ logger.warn('The FIELD/column (${coldIdBeingSorted}) being sorted is not part of an INDEX, required for the [orderBy] operation. See https://learn.genesis.global/docs/database/data-types/index-entities/');
81
+ logger.debug('Available indexes:', availableIndexes);
82
+ logger.debug('Columns that can be sorted with the available indexes:', availableIndexFields);
83
+ params.fail();
84
+ return;
85
+ }
86
+ else if (JSON.stringify(toBeAppliedSortModel) !== JSON.stringify(this.currentSortModel)) {
87
+ this.resourceParams.ORDER_BY = orderByAndToBeSortedColIds.orderBy;
88
+ this.resourceParams.REVERSE = sortTypeBeingApplied === 'desc' ? true : false;
89
+ yield this.refreshDatasource(params);
90
+ return;
91
+ }
92
+ }
93
+ }
94
+ if (this.moreRows && params.request.startRow >= Number(this.maxRows)) {
95
+ this.connect.getMoreRows(this.streamSourceRef);
96
+ }
97
+ if (!this.dataserverStream) {
98
+ this.dataserverStream = yield this.createDataserverStreamFunc(this.resourceParams);
99
+ }
100
+ let applyResult = true;
101
+ this.dataserverStreamSubscription = this.dataserverStream.subscribe((dataserverResult) => {
102
+ if (applyResult) {
103
+ this.applyServerSideData(params, dataserverResult);
104
+ applyResult = false;
105
+ }
106
+ });
107
+ });
108
+ }
109
+ applyServerSideData(params, result) {
110
+ var _a;
111
+ const messageType = result.MESSAGE_TYPE;
112
+ if (messageType &&
113
+ (messageType === MessageType.LOGOFF_ACK || messageType === MessageType.MSG_NACK)) {
114
+ params.fail();
115
+ return;
116
+ }
117
+ this.moreRows = result.MORE_ROWS;
118
+ if (result.ROW) {
119
+ const nextMessage = dataServerResultFilter(result);
120
+ this.handleCurrentStreamLoad(nextMessage);
121
+ }
122
+ else {
123
+ this.rowData = new Map();
124
+ const successRowData = { rowData: [] };
125
+ successRowData.rowCount = 0;
126
+ params.success(successRowData);
127
+ return;
128
+ }
129
+ this.lastSequenceId = result.SEQUENCE_ID;
130
+ if (this.lastSequenceId === 1) {
131
+ this.streamSourceRef = result.SOURCE_REF;
132
+ this.server_ROWS_COUNT = (_a = result.ROWS_COUNT) !== null && _a !== void 0 ? _a : this.rowData.size;
133
+ }
134
+ const successRowData = {
135
+ rowData: Array.from(this.sortMapByNumericKey(this.rowData).values()),
136
+ rowCount: this.pagination && !this.resourceParams.CRITERIA_MATCH
137
+ ? Math.min(this.server_ROWS_COUNT, this.maxView)
138
+ : undefined,
139
+ };
140
+ this.calculatedRowsCount = this.client_ROWS_COUNT;
141
+ if (this.calculatedRowsCount === 0) {
142
+ this.calculatedRowsCount = params.request.endRow;
143
+ }
144
+ if (params.request.endRow > this.maxView || params.request.endRow > this.calculatedRowsCount) {
145
+ successRowData.rowCount = this.calculatedRowsCount;
146
+ }
147
+ else if (params.request.endRow === this.server_ROWS_COUNT) {
148
+ successRowData.rowCount = this.server_ROWS_COUNT;
149
+ }
150
+ else if (!this.moreRows && this.server_ROWS_COUNT > this.calculatedRowsCount) {
151
+ successRowData.rowCount = this.calculatedRowsCount;
152
+ }
153
+ params.success(successRowData);
154
+ }
155
+ sortMapByNumericKey(inputMap) {
156
+ // Convert Map to array of key-value pairs
157
+ const sortedArray = Array.from(inputMap.entries()).sort(([key1], [key2]) => +key2 - +key1);
158
+ // Create a new Map from the sorted array
159
+ const sortedMap = new Map(sortedArray);
160
+ return sortedMap;
161
+ }
162
+ deinit() {
163
+ var _a;
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ this.rowData = new Map();
166
+ this.client_ROWS_COUNT = 0;
167
+ this.calculatedRowsCount = 0;
168
+ this.server_ROWS_COUNT = 0;
169
+ this.dataserverStream = undefined;
170
+ (_a = this.dataserverStreamSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
171
+ this.dataserverStreamSubscription = undefined;
172
+ this.streamSourceRef = undefined;
173
+ });
174
+ }
175
+ refreshDatasource(params) {
176
+ var _a;
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ yield this.deinit();
179
+ (_a = params.api) === null || _a === void 0 ? void 0 : _a.refreshServerSide({ purge: true });
180
+ params.fail();
181
+ });
182
+ }
183
+ getOrderByAndToBeSortedColIds(map, searchValue) {
184
+ for (const [key, value] of map.entries()) {
185
+ const searchIndex = value.findIndex((x) => x === searchValue);
186
+ if (searchIndex !== -1) {
187
+ const copy = [...value];
188
+ const toBeSorted = copy.splice(searchIndex, 1);
189
+ return { orderBy: key, toBeSorted };
190
+ }
191
+ }
192
+ }
193
+ handleCurrentStreamLoad(result) {
194
+ var _a;
195
+ if (!result)
196
+ return;
197
+ const rows = new Map();
198
+ (_a = result.inserts) === null || _a === void 0 ? void 0 : _a.forEach((insertData) => {
199
+ rows.set(insertData[this.rowId], insertData);
200
+ });
201
+ this.rowData = rows;
202
+ }
203
+ buildCriteriaMatchFromFilters() {
204
+ this.resourceParams.CRITERIA_MATCH = this.originalCriteriaMatch;
205
+ if (this.resourceParams.CRITERIA_MATCH &&
206
+ typeof this.resourceParams.CRITERIA_MATCH === 'string') {
207
+ this.resourceParams.CRITERIA_MATCH = this.resourceParams.CRITERIA_MATCH.split(';');
208
+ }
209
+ if (!this.resourceParams.CRITERIA_MATCH) {
210
+ this.resourceParams.CRITERIA_MATCH = [];
211
+ }
212
+ const criteria = this.resourceParams.CRITERIA_MATCH.concat(this.criteriaFromFilters());
213
+ return criteria.join(' && ');
214
+ }
215
+ // TODO: update this following https://learn.genesis.global/docs/server/data-server/advanced/#common-expressions
216
+ criteriaFromFilters() {
217
+ const filters = [];
218
+ this.getFiltersByType('text').forEach((k) => {
219
+ // TODO: no official "boolean" filter type, it's a "text"
220
+ if (!this.currentFilterModel[k].filter &&
221
+ (this.currentFilterModel[k].type === 'false' || this.currentFilterModel[k].type === 'true')) {
222
+ filters.push(`${k} == ${this.currentFilterModel[k].type}`);
223
+ }
224
+ else {
225
+ switch (this.currentFilterModel[k].type) {
226
+ case 'equals':
227
+ filters.push(`${k} == '${this.currentFilterModel[k].filter}'`);
228
+ break;
229
+ case 'contains':
230
+ filters.push(`Expr.containsIgnoreCase(${k}, '${this.currentFilterModel[k].filter}')`);
231
+ break;
232
+ }
233
+ }
234
+ });
235
+ this.getFiltersByType('number').forEach((k) => {
236
+ const value = this.currentFilterModel[k].filter;
237
+ switch (this.currentFilterModel[k].type) {
238
+ case 'equals':
239
+ !isNaN(value) && filters.push(`${k} == ${value}`);
240
+ break;
241
+ case 'lessThan':
242
+ !isNaN(value) && filters.push(`${k} < ${value}`);
243
+ break;
244
+ case 'greaterThan':
245
+ !isNaN(value) && filters.push(`${k} > ${value}`);
246
+ break;
247
+ }
248
+ });
249
+ this.getFiltersByType('date').forEach((k) => {
250
+ const dateFrom = this.currentFilterModel[k].dateFrom
251
+ .replace(/-/g, '')
252
+ .replace('T', '-')
253
+ .split(' ')[0];
254
+ switch (this.currentFilterModel[k].type) {
255
+ case 'equals':
256
+ filters.push(`Expr.dateIsEqual(${k}, '${dateFrom}')`);
257
+ break;
258
+ case 'lessThan':
259
+ filters.push(`Expr.dateIsBefore(${k}, '${dateFrom}')`);
260
+ break;
261
+ case 'greaterThan':
262
+ filters.push(`Expr.dateIsAfter(${k}, '${dateFrom}')`);
263
+ break;
264
+ default:
265
+ break;
266
+ }
267
+ });
268
+ return filters;
269
+ }
270
+ getFiltersByType(filterType) {
271
+ return Object.keys(this.currentFilterModel)
272
+ .filter((k) => this.resourceColDefs.findIndex((o) => o.NAME === k) !== -1)
273
+ .filter((k) => this.currentFilterModel[k].filterType === filterType);
274
+ }
275
+ }
276
+ __decorate([
277
+ Auth
278
+ ], StreamDatasource.prototype, "auth", void 0);
279
+ __decorate([
280
+ Connect
281
+ ], StreamDatasource.prototype, "connect", void 0);
12
282
  const criteriaDelimiter = ';';
13
283
  const withoutColumnDefs = null;
14
- const timeoutInMs = 500;
15
284
  /**
16
285
  * A Genesis Datasource element, for server-side | SSRM-compatible data fetching and used exclusively by the GridPro element.
17
286
  * @remarks Only supports Server-Side Row Model. Requires `@ag-grid-enterprise/server-side-row-model` setup and valid AG Grid Enterprise license.
@@ -23,33 +292,34 @@ let GridProServerSideDatasource = class GridProServerSideDatasource extends Life
23
292
  this.applyFuncName = 'applyServerSideTransaction';
24
293
  this.applyAsyncFuncName = 'applyServerSideTransactionAsync';
25
294
  this.pagination = false;
26
- /**
27
- * The starting VIEW_NUMBER of the data to be fetched.
28
- * @remarks The VIEW_NUMBER isincremented by the grid as the user scrolls or changes pages.
29
- */
30
- this.zeroBasedViewNumber = false;
31
- /**
32
- * Enable live updates for the grid.
33
- * @remarks Only works with DATASERVER resources (StreamDatasource) right now.
34
- */
35
- this.liveUpdates = false;
36
- this.request = {};
37
- }
38
- resourceNameChanged(oldValue, newValue) {
39
- if (!oldValue || oldValue === newValue)
40
- return;
41
- DOM.queueUpdate(() => __awaiter(this, void 0, void 0, function* () {
42
- yield this.restart();
43
- }));
44
295
  }
45
296
  criteriaChanged(oldCriteria, newCriteria) {
46
297
  const criteriaIsNotDuplicate = oldCriteria !== normaliseCriteria(newCriteria, criteriaDelimiter);
47
298
  if (this.ssrmDatasource && criteriaIsNotDuplicate) {
48
- DOM.queueUpdate(() => __awaiter(this, void 0, void 0, function* () {
49
- yield this.reloadResourceData();
50
- }));
299
+ this.reloadResourceData();
51
300
  }
52
301
  }
302
+ /**
303
+ * Resets the grid data while keeping columnDefs and sends a DATA_LOGOFF message if it's a stream.
304
+ * @remarks This is used when the grid is already initialized and we want to reload the data due to a criteria/filter change.
305
+ * @internal
306
+ */
307
+ reloadResourceData() {
308
+ var _a, _b, _c;
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ this.clearRowData(withoutColumnDefs);
311
+ this.ssrmDatasource.streamSourceRef = undefined;
312
+ this.ssrmDatasource = undefined;
313
+ (_a = this.agGrid.gridApi) === null || _a === void 0 ? void 0 : _a.refreshServerSide({ purge: true });
314
+ (_c = (_b = this.agGrid) === null || _b === void 0 ? void 0 : _b.gridApi) === null || _c === void 0 ? void 0 : _c.showLoadingOverlay();
315
+ this.init();
316
+ });
317
+ }
318
+ resourceNameChanged(oldValue, newValue) {
319
+ if (!oldValue || oldValue === newValue)
320
+ return;
321
+ this.restart();
322
+ }
53
323
  connectedCallback() {
54
324
  super.connectedCallback();
55
325
  const shouldRunConnect = this.shouldRunConnect;
@@ -62,11 +332,11 @@ let GridProServerSideDatasource = class GridProServerSideDatasource extends Life
62
332
  disconnectedCallback() {
63
333
  super.disconnectedCallback();
64
334
  const shouldRunDisconnect = this.shouldRunDisconnect;
65
- DOM.queueUpdate(() => __awaiter(this, void 0, void 0, function* () {
335
+ DOM.queueUpdate(() => {
66
336
  if (!shouldRunDisconnect)
67
337
  return;
68
- yield this.destroy();
69
- }));
338
+ this.deinit();
339
+ });
70
340
  }
71
341
  deepClone() {
72
342
  const copy = super.deepClone();
@@ -74,134 +344,68 @@ let GridProServerSideDatasource = class GridProServerSideDatasource extends Life
74
344
  copy.deferredColumnStates = structuredClone(this.deferredColumnStates);
75
345
  return copy;
76
346
  }
77
- /**
78
- * Resets the grid data while keeping columnDefs and sends a DATA_LOGOFF message if it's a stream.
79
- * @remarks This is used when the grid is already initialized and we want to reload the data due to a criteria/filter change.
80
- * @internal
81
- */
82
- reloadResourceData(params) {
83
- var _a, _b, _c, _d, _e, _f;
84
- return __awaiter(this, void 0, void 0, function* () {
85
- this.datasource.destroy();
86
- (_a = this.liveUpdatesStream) === null || _a === void 0 ? void 0 : _a.unsubscribe();
87
- this.liveUpdatesStream = undefined;
88
- this.clearRowData(withoutColumnDefs);
89
- if (params) {
90
- // this.datasource.stream = undefined;
91
- const options = Object.assign(Object.assign({}, this.datasourceOptions()), params);
92
- const initOK = yield this.datasource.init(options, true, false);
93
- // this.$emit(gridProGenesisDatasourceEventNames.dataInit);
94
- if (!initOK) {
95
- (_b = this.agGrid.gridApi) === null || _b === void 0 ? void 0 : _b.setServerSideDatasource(null);
96
- logger.error('Genesis Datasource re-init failed on filtering/sorting.');
97
- }
98
- }
99
- else {
100
- if (this.ssrmDatasource) {
101
- yield this.ssrmDatasource.destroy();
102
- this.ssrmDatasource = undefined;
103
- }
104
- (_c = this.agGrid.gridApi) === null || _c === void 0 ? void 0 : _c.setServerSideDatasource(null);
105
- (_d = this.agGrid.gridApi) === null || _d === void 0 ? void 0 : _d.refreshServerSide({ purge: true });
106
- (_f = (_e = this.agGrid) === null || _e === void 0 ? void 0 : _e.gridApi) === null || _f === void 0 ? void 0 : _f.showLoadingOverlay();
107
- yield this.init();
108
- }
109
- });
347
+ deinit() {
348
+ var _a;
349
+ this.clearRowData();
350
+ this.ssrmDatasource.deinit();
351
+ this.ssrmDatasource = undefined;
352
+ this.originalFieldDef = undefined;
353
+ (_a = this.agGrid.gridApi) === null || _a === void 0 ? void 0 : _a.refreshServerSide({ purge: true });
110
354
  }
111
355
  init() {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- if (this.agGrid) {
114
- this.agGrid.gridOptions = Object.assign(Object.assign({ getRowId: (params) => {
115
- if (!params.data) {
116
- return null;
117
- }
118
- return params.data[this.rowId];
119
- }, getRowStyle(params) {
120
- var _a, _b;
121
- if ((_b = (_a = params.data) === null || _a === void 0 ? void 0 : _a.ROW_REF) === null || _b === void 0 ? void 0 : _b.includes('_deleted')) {
122
- return { color: 'grey' };
123
- }
124
- }, cacheBlockSize: this.maxRows, defaultColDef: {
125
- filter: true,
126
- resizable: true,
127
- sortable: false,
128
- }, pagination: this.pagination, paginationPageSize: this.maxRows, rowBuffer: 0, rowModelType: 'serverSide', suppressServerSideInfiniteScroll: false, suppressMultiSort: true, onFilterChanged: (params) => { }, onSortChanged: (params) => { }, onPaginationChanged: (event) => this.onPaginationChanged(event) }, this.agGrid['agGridOptions']), this.deferredGridOptions);
129
- this.agGrid['initGrid']();
130
- this.agGrid.addEventListener(Events.EVENT_GRID_READY, () => __awaiter(this, void 0, void 0, function* () {
131
- const initOK = yield this.datasource.init(this.datasourceOptions(), true, false);
132
- if (!initOK) {
133
- logger.debug(`Genesis Datasource init failed for ${this.resourceName}`);
134
- this.clearRowData();
135
- return;
136
- }
137
- this.$emit(gridProGenesisDatasourceEventNames.dataInit);
138
- this.indexes = this.getResourceIndexes(this.datasource.availableIndexes);
139
- const fieldMetadata = toFieldMetadata(this.datasource.originalFieldDef);
140
- const agColumnDefs = yield this.getAgColumnDefs(fieldMetadata);
141
- this.agGrid.gridApi.setColumnDefs(agColumnDefs);
142
- if (this.isRequestServer) {
143
- this.ssrmDatasource = new ReqRepServerSideDatasource({
144
- createReqRepRequestFunc: this.createReqRepRequest.bind(this),
145
- reloadResourceDataFunc: this.reloadResourceData.bind(this),
146
- resourceName: this.resourceName,
147
- resourceParams: this.params,
148
- resourceIndexes: this.indexes,
149
- resourceColDefs: this.datasource.originalFieldDef,
150
- maxRows: +this.maxRows,
151
- maxView: +this.maxView,
152
- rowId: this.rowId,
153
- pagination: this.pagination,
154
- zeroBasedViewNumber: this.zeroBasedViewNumber,
155
- });
356
+ if (this.agGrid && this.resourceName && this.connect.isConnected) {
357
+ this.agGrid.gridOptions = Object.assign(Object.assign({ getRowId: (params) => {
358
+ if (!params.data) {
359
+ return null;
156
360
  }
157
- else {
158
- this.ssrmDatasource = new DataserverServerSideDatasource({
159
- createDataserverStreamFunc: this.createDataserverStream.bind(this),
160
- reloadResourceDataFunc: this.reloadResourceData.bind(this),
161
- resourceName: this.resourceName,
162
- resourceParams: this.params,
163
- resourceIndexes: this.indexes,
164
- resourceColDefs: this.datasource.originalFieldDef,
165
- maxRows: +this.maxRows,
166
- maxView: +this.maxView,
167
- rowId: this.rowId,
168
- pagination: this.pagination,
169
- zeroBasedViewNumber: this.zeroBasedViewNumber,
170
- });
361
+ return params.data[this.rowId];
362
+ }, getRowStyle(params) {
363
+ var _a, _b;
364
+ if ((_b = (_a = params.data) === null || _a === void 0 ? void 0 : _a.ROW_REF) === null || _b === void 0 ? void 0 : _b.includes('_deleted')) {
365
+ return { color: 'grey' };
171
366
  }
172
- this.agGrid.gridApi.setServerSideDatasource(this.ssrmDatasource);
173
- }), { once: true });
174
- return;
175
- }
176
- logger.warn(`Application not connected, falling back to local columnDefs/rowData`);
177
- });
178
- }
179
- onPaginationChanged(event) {
180
- var _a;
181
- if (this.agGrid.gridApi && this.ssrmDatasource) {
182
- this.ssrmDatasource.isNewPageSize = (_a = event.newPage) !== null && _a !== void 0 ? _a : false;
367
+ }, cacheBlockSize: this.maxRows, defaultColDef: {
368
+ filter: true,
369
+ resizable: true,
370
+ sortable: false,
371
+ }, pagination: this.pagination, paginationPageSize: this.maxRows, rowBuffer: 0, rowModelType: 'serverSide', suppressServerSideInfiniteScroll: false, suppressMultiSort: true, onFilterChanged: (params) => { }, onSortChanged: (params) => { } }, this.agGrid['agGridOptions']), this.deferredGridOptions);
372
+ this.agGrid['initGrid']();
373
+ this.agGrid.addEventListener('onGridReady', () => __awaiter(this, void 0, void 0, function* () {
374
+ /**
375
+ * We should have all the metadata via Datasource, ie.
376
+ * Datasource.availableIndexes, Datasource.originalFieldDef etc.
377
+ * Could this not leverage that?
378
+ */
379
+ const meta = yield this.connect
380
+ .getMetadata(this.resourceName)
381
+ .catch((e) => logger.error(e));
382
+ if (!meta)
383
+ return false;
384
+ this.indexes = this.getResourceIndexes(meta.INDEXES);
385
+ this.originalFieldDef = extractFieldDefinitions(meta);
386
+ const fieldMetadata = toFieldMetadata(this.originalFieldDef);
387
+ const agColumnDefs = yield this.getAgColumnDefs(fieldMetadata);
388
+ this.agGrid.gridApi.setColumnDefs(agColumnDefs);
389
+ this.ssrmDatasource = new StreamDatasource({
390
+ createDataserverStreamFunc: this.createDataserverStream.bind(this),
391
+ resourceName: this.resourceName,
392
+ resourceParams: this.params,
393
+ resourceIndexes: this.indexes,
394
+ resourceColDefs: this.originalFieldDef,
395
+ maxRows: +this.maxRows,
396
+ maxView: +this.maxView,
397
+ rowId: this.rowId,
398
+ pagination: this.pagination,
399
+ });
400
+ this.agGrid.gridApi.setServerSideDatasource(this.ssrmDatasource);
401
+ }), { once: true });
402
+ return;
183
403
  }
184
- }
185
- destroy() {
186
- var _a, _b, _c;
187
- return __awaiter(this, void 0, void 0, function* () {
188
- this.datasource.destroy();
189
- (_a = this.liveUpdatesStream) === null || _a === void 0 ? void 0 : _a.unsubscribe();
190
- this.liveUpdatesStream = undefined;
191
- this.clearRowData();
192
- if (this.ssrmDatasource) {
193
- yield this.ssrmDatasource.destroy();
194
- this.ssrmDatasource = undefined;
195
- }
196
- (_b = this.agGrid.gridApi) === null || _b === void 0 ? void 0 : _b.setServerSideDatasource(null);
197
- (_c = this.agGrid.gridApi) === null || _c === void 0 ? void 0 : _c.refreshServerSide({ purge: true });
198
- });
404
+ logger.warn(`Application not connected, falling back to local columnDefs/rowData`);
199
405
  }
200
406
  restart() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- yield this.destroy();
203
- this.init();
204
- });
407
+ this.deinit();
408
+ this.init();
205
409
  }
206
410
  clearRowData(withColumnDefs = true) {
207
411
  var _a, _b, _c, _d;
@@ -248,69 +452,50 @@ let GridProServerSideDatasource = class GridProServerSideDatasource extends Life
248
452
  get rowModel() {
249
453
  return this.agGrid.gridApi.getModel();
250
454
  }
251
- createReqRepRequest(existingParams = null) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- const reqRep = yield this.datasource.snapshot(existingParams);
254
- return reqRep;
255
- });
256
- }
257
455
  createDataserverStream(existingParams = null) {
258
456
  return __awaiter(this, void 0, void 0, function* () {
259
- if (this.liveUpdates) {
260
- const streamOnMessage = (message) => __awaiter(this, void 0, void 0, function* () {
261
- var _a, _b;
262
- const messageType = message.MESSAGE_TYPE;
263
- if (messageType === MessageType.QUERY_UPDATE && message.ROW) {
264
- if (!this.ssrmDatasource) {
265
- return;
266
- }
267
- const nextMessage = dataServerResultFilter(message);
268
- this.agTransaction = { add: [], remove: [], update: [] };
269
- this.handleStreamInserts(nextMessage.inserts);
270
- this.handleStreamUpdates(nextMessage.updates);
271
- this.handleStreamDeletes(nextMessage.deletes);
272
- if (message.SEQUENCE_ID > 1) {
273
- this.ssrmDatasource.clientRowsCount += (_a = nextMessage.inserts.length) !== null && _a !== void 0 ? _a : 0;
274
- this.ssrmDatasource.serverRowsCount += (_b = nextMessage.inserts.length) !== null && _b !== void 0 ? _b : 0;
275
- }
276
- // this.handleStreamDeletes(nextMessage.deletes);
277
- // this.ssrmDatasource.client_ROWS_COUNT -= nextMessage.deletes.length ?? 0;
278
- // this.ssrmDatasource.server_ROWS_COUNT -= nextMessage.deletes.length ?? 0;
279
- if (this.pagination) {
280
- this.applyAllAgTransactions();
281
- }
282
- else {
283
- // TODO: Double-check this bit / DOM.queueUpdate do not work here
284
- setTimeout(() => {
285
- this.applyAllAgTransactions();
286
- }, timeoutInMs);
287
- }
457
+ const streamOnMessage = (message) => __awaiter(this, void 0, void 0, function* () {
458
+ var _a;
459
+ const messageType = message.MESSAGE_TYPE;
460
+ if (messageType === MessageType.QUERY_UPDATE && message.ROW) {
461
+ if (!this.ssrmDatasource) {
462
+ return;
288
463
  }
289
- });
290
- const onError = (error) => logger.error(error);
291
- this.liveUpdatesStream = this.connect
292
- .stream(this.resourceName, () => { }, onError, existingParams !== null && existingParams !== void 0 ? existingParams : this.params)
293
- .subscribe((message) => streamOnMessage(message));
294
- // return this.connect.stream(
295
- // this.resourceName,
296
- // (message) => streamOnMessage(message),
297
- // onError,
298
- // existingParams ?? this.params,
299
- // );
464
+ const nextMessage = dataServerResultFilter(message);
465
+ this.agTransaction = { add: [], remove: [], update: [] };
466
+ this.handleStreamInserts(nextMessage.inserts);
467
+ // TODO: deletion flow not being handled yet.
468
+ // this.handleStreamDeletes(nextMessage.deletes);
469
+ this.handleStreamDeletesTemp(nextMessage.deletes);
470
+ this.handleStreamUpdates(nextMessage.updates);
471
+ this.ssrmDatasource.client_ROWS_COUNT += (_a = nextMessage.inserts.length) !== null && _a !== void 0 ? _a : 0;
472
+ if (message.SEQUENCE_ID > 1) {
473
+ const updatedInfo = yield this.connect.snapshot(this.resourceName, {
474
+ MAX_ROWS: 1,
475
+ MAX_VIEW: 1,
476
+ CRITERIA_MATCH: this.criteria,
477
+ });
478
+ this.ssrmDatasource.server_ROWS_COUNT = updatedInfo.ROWS_COUNT;
479
+ }
480
+ this.applyAllAgTransactions();
481
+ }
482
+ });
483
+ const onError = (error) => logger.error(error);
484
+ return this.connect.stream(this.resourceName, (message) => {
485
+ streamOnMessage(message);
486
+ }, onError, existingParams !== null && existingParams !== void 0 ? existingParams : this.params);
487
+ });
488
+ }
489
+ handleStreamDeletesTemp(deletes) {
490
+ if (!deletes)
491
+ return;
492
+ deletes.forEach((deleteData) => {
493
+ const rowNode = this.agGrid.gridApi.getRowNode(deleteData.ROW_REF);
494
+ if (rowNode) {
495
+ rowNode.setData(Object.assign(Object.assign({}, rowNode.data), { ROW_REF: deleteData.ROW_REF + '_deleted' }));
300
496
  }
301
- yield this.datasource.startStream();
302
- return this.datasource.stream;
303
497
  });
304
498
  }
305
- // private handleStreamDeletesTemp(deletes: RowData[]) {
306
- // if (!deletes) return;
307
- // deletes.forEach((deleteData) => {
308
- // const rowNode = this.agGrid.gridApi.getRowNode(deleteData.ROW_REF);
309
- // if (rowNode) {
310
- // rowNode.setData({ ...rowNode.data, ROW_REF: deleteData.ROW_REF + '_deleted' });
311
- // }
312
- // });
313
- // }
314
499
  getAgColumnDefs(fieldsMetadata) {
315
500
  return __awaiter(this, void 0, void 0, function* () {
316
501
  const colDefsFromGenesisData = this.generateColumnDefsFromMetadata(fieldsMetadata, getServerSideFilterParamsByFieldType);
@@ -333,15 +518,6 @@ let GridProServerSideDatasource = class GridProServerSideDatasource extends Life
333
518
  __decorate([
334
519
  attr({ mode: 'boolean' })
335
520
  ], GridProServerSideDatasource.prototype, "pagination", void 0);
336
- __decorate([
337
- attr({ mode: 'boolean', attribute: 'zero-based-view-number' })
338
- ], GridProServerSideDatasource.prototype, "zeroBasedViewNumber", void 0);
339
- __decorate([
340
- attr({ mode: 'boolean', attribute: 'live-updates' })
341
- ], GridProServerSideDatasource.prototype, "liveUpdates", void 0);
342
- __decorate([
343
- observable
344
- ], GridProServerSideDatasource.prototype, "request", void 0);
345
521
  GridProServerSideDatasource = __decorate([
346
522
  customElement({
347
523
  name: 'grid-pro-server-side-datasource',