@sisense/sdk-pivot-query-client 2.17.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.
Files changed (189) hide show
  1. package/LICENSE.md +35 -0
  2. package/README.md +2 -0
  3. package/dist/__test-helpers__/testUtils.d.ts +30 -0
  4. package/dist/__test-helpers__/testUtils.js +89 -0
  5. package/dist/builders/index.d.ts +2 -0
  6. package/dist/builders/index.js +2 -0
  7. package/dist/builders/pivot-data-builder.d.ts +34 -0
  8. package/dist/builders/pivot-data-builder.js +182 -0
  9. package/dist/builders/socket-builder.d.ts +18 -0
  10. package/dist/builders/socket-builder.js +72 -0
  11. package/dist/cjs/__test-helpers__/testUtils.d.ts +30 -0
  12. package/dist/cjs/__test-helpers__/testUtils.js +104 -0
  13. package/dist/cjs/builders/index.d.ts +2 -0
  14. package/dist/cjs/builders/index.js +7 -0
  15. package/dist/cjs/builders/pivot-data-builder.d.ts +34 -0
  16. package/dist/cjs/builders/pivot-data-builder.js +186 -0
  17. package/dist/cjs/builders/socket-builder.d.ts +18 -0
  18. package/dist/cjs/builders/socket-builder.js +79 -0
  19. package/dist/cjs/data-handling/DataService.d.ts +672 -0
  20. package/dist/cjs/data-handling/DataService.js +1364 -0
  21. package/dist/cjs/data-handling/DivergenceComparator.d.ts +7 -0
  22. package/dist/cjs/data-handling/DivergenceComparator.js +20 -0
  23. package/dist/cjs/data-handling/constants.d.ts +44 -0
  24. package/dist/cjs/data-handling/constants.js +43 -0
  25. package/dist/cjs/data-handling/index.d.ts +3 -0
  26. package/dist/cjs/data-handling/index.js +23 -0
  27. package/dist/cjs/data-handling/types.d.ts +104 -0
  28. package/dist/cjs/data-handling/types.js +2 -0
  29. package/dist/cjs/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  30. package/dist/cjs/data-handling/utils/createPivotTreeNode.js +21 -0
  31. package/dist/cjs/data-handling/utils/index.d.ts +4 -0
  32. package/dist/cjs/data-handling/utils/index.js +14 -0
  33. package/dist/cjs/data-handling/utils/jaqlProcessor.d.ts +122 -0
  34. package/dist/cjs/data-handling/utils/jaqlProcessor.js +661 -0
  35. package/dist/cjs/data-handling/utils/pivotTransforms.d.ts +74 -0
  36. package/dist/cjs/data-handling/utils/pivotTransforms.js +373 -0
  37. package/dist/cjs/data-handling/utils/plugins/PluginService.d.ts +135 -0
  38. package/dist/cjs/data-handling/utils/plugins/PluginService.js +383 -0
  39. package/dist/cjs/data-handling/utils/plugins/getters.d.ts +23 -0
  40. package/dist/cjs/data-handling/utils/plugins/getters.js +70 -0
  41. package/dist/cjs/data-handling/utils/plugins/types.d.ts +75 -0
  42. package/dist/cjs/data-handling/utils/plugins/types.js +2 -0
  43. package/dist/cjs/data-handling/utils/plugins/validator.d.ts +13 -0
  44. package/dist/cjs/data-handling/utils/plugins/validator.js +169 -0
  45. package/dist/cjs/data-load/AbstractDataLoadService.d.ts +256 -0
  46. package/dist/cjs/data-load/AbstractDataLoadService.js +473 -0
  47. package/dist/cjs/data-load/DataLoadService.d.ts +63 -0
  48. package/dist/cjs/data-load/DataLoadService.js +152 -0
  49. package/dist/cjs/data-load/SisenseDataLoadService.d.ts +44 -0
  50. package/dist/cjs/data-load/SisenseDataLoadService.js +87 -0
  51. package/dist/cjs/data-load/TestDataLoadService.d.ts +27 -0
  52. package/dist/cjs/data-load/TestDataLoadService.js +76 -0
  53. package/dist/cjs/data-load/constants.d.ts +13 -0
  54. package/dist/cjs/data-load/constants.js +28 -0
  55. package/dist/cjs/data-load/index.d.ts +6 -0
  56. package/dist/cjs/data-load/index.js +14 -0
  57. package/dist/cjs/data-load/sockets/SisenseSocket.d.ts +81 -0
  58. package/dist/cjs/data-load/sockets/SisenseSocket.js +162 -0
  59. package/dist/cjs/data-load/sockets/TestSocket.d.ts +61 -0
  60. package/dist/cjs/data-load/sockets/TestSocket.js +90 -0
  61. package/dist/cjs/data-load/sockets/helpers.d.ts +4 -0
  62. package/dist/cjs/data-load/sockets/helpers.js +27 -0
  63. package/dist/cjs/data-load/sockets/index.d.ts +2 -0
  64. package/dist/cjs/data-load/sockets/index.js +8 -0
  65. package/dist/cjs/data-load/types.d.ts +90 -0
  66. package/dist/cjs/data-load/types.js +2 -0
  67. package/dist/cjs/errors/LoadingCanceledError.d.ts +7 -0
  68. package/dist/cjs/errors/LoadingCanceledError.js +24 -0
  69. package/dist/cjs/errors/index.d.ts +1 -0
  70. package/dist/cjs/errors/index.js +6 -0
  71. package/dist/cjs/index.d.ts +17 -0
  72. package/dist/cjs/index.js +32 -0
  73. package/dist/cjs/package.json +12 -0
  74. package/dist/cjs/pivot-query-client.d.ts +13 -0
  75. package/dist/cjs/pivot-query-client.js +26 -0
  76. package/dist/cjs/tree-structure/AbstractTreeService.d.ts +308 -0
  77. package/dist/cjs/tree-structure/AbstractTreeService.js +716 -0
  78. package/dist/cjs/tree-structure/HeaderTreeService.d.ts +180 -0
  79. package/dist/cjs/tree-structure/HeaderTreeService.js +280 -0
  80. package/dist/cjs/tree-structure/TreeCellMap.d.ts +104 -0
  81. package/dist/cjs/tree-structure/TreeCellMap.js +145 -0
  82. package/dist/cjs/tree-structure/TreeService.d.ts +8 -0
  83. package/dist/cjs/tree-structure/TreeService.js +12 -0
  84. package/dist/cjs/tree-structure/constants.d.ts +6 -0
  85. package/dist/cjs/tree-structure/constants.js +10 -0
  86. package/dist/cjs/tree-structure/index.d.ts +5 -0
  87. package/dist/cjs/tree-structure/index.js +10 -0
  88. package/dist/cjs/tree-structure/types.d.ts +93 -0
  89. package/dist/cjs/tree-structure/types.js +2 -0
  90. package/dist/cjs/tree-structure/utils/index.d.ts +1 -0
  91. package/dist/cjs/tree-structure/utils/index.js +9 -0
  92. package/dist/cjs/tree-structure/utils/treeNode.d.ts +147 -0
  93. package/dist/cjs/tree-structure/utils/treeNode.js +534 -0
  94. package/dist/cjs/utils/array.d.ts +13 -0
  95. package/dist/cjs/utils/array.js +25 -0
  96. package/dist/cjs/utils/cloneObject.d.ts +30 -0
  97. package/dist/cjs/utils/cloneObject.js +225 -0
  98. package/dist/cjs/utils/index.d.ts +3 -0
  99. package/dist/cjs/utils/index.js +9 -0
  100. package/dist/cjs/utils/throttle.d.ts +12 -0
  101. package/dist/cjs/utils/throttle.js +39 -0
  102. package/dist/cjs/utils/types.d.ts +12 -0
  103. package/dist/cjs/utils/types.js +2 -0
  104. package/dist/data-handling/DataService.d.ts +672 -0
  105. package/dist/data-handling/DataService.js +1357 -0
  106. package/dist/data-handling/DivergenceComparator.d.ts +7 -0
  107. package/dist/data-handling/DivergenceComparator.js +16 -0
  108. package/dist/data-handling/constants.d.ts +44 -0
  109. package/dist/data-handling/constants.js +40 -0
  110. package/dist/data-handling/index.d.ts +3 -0
  111. package/dist/data-handling/index.js +4 -0
  112. package/dist/data-handling/types.d.ts +104 -0
  113. package/dist/data-handling/types.js +1 -0
  114. package/dist/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  115. package/dist/data-handling/utils/createPivotTreeNode.js +17 -0
  116. package/dist/data-handling/utils/index.d.ts +4 -0
  117. package/dist/data-handling/utils/index.js +4 -0
  118. package/dist/data-handling/utils/jaqlProcessor.d.ts +122 -0
  119. package/dist/data-handling/utils/jaqlProcessor.js +621 -0
  120. package/dist/data-handling/utils/pivotTransforms.d.ts +74 -0
  121. package/dist/data-handling/utils/pivotTransforms.js +335 -0
  122. package/dist/data-handling/utils/plugins/PluginService.d.ts +135 -0
  123. package/dist/data-handling/utils/plugins/PluginService.js +379 -0
  124. package/dist/data-handling/utils/plugins/getters.d.ts +23 -0
  125. package/dist/data-handling/utils/plugins/getters.js +65 -0
  126. package/dist/data-handling/utils/plugins/types.d.ts +75 -0
  127. package/dist/data-handling/utils/plugins/types.js +1 -0
  128. package/dist/data-handling/utils/plugins/validator.d.ts +13 -0
  129. package/dist/data-handling/utils/plugins/validator.js +165 -0
  130. package/dist/data-load/AbstractDataLoadService.d.ts +256 -0
  131. package/dist/data-load/AbstractDataLoadService.js +466 -0
  132. package/dist/data-load/DataLoadService.d.ts +63 -0
  133. package/dist/data-load/DataLoadService.js +148 -0
  134. package/dist/data-load/SisenseDataLoadService.d.ts +44 -0
  135. package/dist/data-load/SisenseDataLoadService.js +83 -0
  136. package/dist/data-load/TestDataLoadService.d.ts +27 -0
  137. package/dist/data-load/TestDataLoadService.js +69 -0
  138. package/dist/data-load/constants.d.ts +13 -0
  139. package/dist/data-load/constants.js +25 -0
  140. package/dist/data-load/index.d.ts +6 -0
  141. package/dist/data-load/index.js +6 -0
  142. package/dist/data-load/sockets/SisenseSocket.d.ts +81 -0
  143. package/dist/data-load/sockets/SisenseSocket.js +155 -0
  144. package/dist/data-load/sockets/TestSocket.d.ts +61 -0
  145. package/dist/data-load/sockets/TestSocket.js +83 -0
  146. package/dist/data-load/sockets/helpers.d.ts +4 -0
  147. package/dist/data-load/sockets/helpers.js +23 -0
  148. package/dist/data-load/sockets/index.d.ts +2 -0
  149. package/dist/data-load/sockets/index.js +3 -0
  150. package/dist/data-load/types.d.ts +90 -0
  151. package/dist/data-load/types.js +1 -0
  152. package/dist/errors/LoadingCanceledError.d.ts +7 -0
  153. package/dist/errors/LoadingCanceledError.js +20 -0
  154. package/dist/errors/index.d.ts +1 -0
  155. package/dist/errors/index.js +2 -0
  156. package/dist/index.d.ts +17 -0
  157. package/dist/index.js +9 -0
  158. package/dist/pivot-query-client.d.ts +13 -0
  159. package/dist/pivot-query-client.js +22 -0
  160. package/dist/tree-structure/AbstractTreeService.d.ts +308 -0
  161. package/dist/tree-structure/AbstractTreeService.js +712 -0
  162. package/dist/tree-structure/HeaderTreeService.d.ts +180 -0
  163. package/dist/tree-structure/HeaderTreeService.js +276 -0
  164. package/dist/tree-structure/TreeCellMap.d.ts +104 -0
  165. package/dist/tree-structure/TreeCellMap.js +141 -0
  166. package/dist/tree-structure/TreeService.d.ts +8 -0
  167. package/dist/tree-structure/TreeService.js +8 -0
  168. package/dist/tree-structure/constants.d.ts +6 -0
  169. package/dist/tree-structure/constants.js +7 -0
  170. package/dist/tree-structure/index.d.ts +5 -0
  171. package/dist/tree-structure/index.js +4 -0
  172. package/dist/tree-structure/types.d.ts +93 -0
  173. package/dist/tree-structure/types.js +1 -0
  174. package/dist/tree-structure/utils/index.d.ts +1 -0
  175. package/dist/tree-structure/utils/index.js +1 -0
  176. package/dist/tree-structure/utils/treeNode.d.ts +147 -0
  177. package/dist/tree-structure/utils/treeNode.js +515 -0
  178. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  179. package/dist/utils/array.d.ts +13 -0
  180. package/dist/utils/array.js +21 -0
  181. package/dist/utils/cloneObject.d.ts +30 -0
  182. package/dist/utils/cloneObject.js +221 -0
  183. package/dist/utils/index.d.ts +3 -0
  184. package/dist/utils/index.js +3 -0
  185. package/dist/utils/throttle.d.ts +12 -0
  186. package/dist/utils/throttle.js +35 -0
  187. package/dist/utils/types.d.ts +12 -0
  188. package/dist/utils/types.js +1 -0
  189. package/package.json +61 -0
@@ -0,0 +1,1364 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DataService = exports.THROTTLE_TIME_MS = exports.NODES_CHUNK_SIZE_MAX = exports.EVENT_TOTAL_COLUMNS_COUNT = exports.EVENT_TOTAL_ROWS_COUNT = exports.EVENT_DATA_CELL_FORMAT = exports.EVENT_HEADER_CELL_FORMAT = exports.EVENT_PROGRESS_ERROR = exports.EVENT_FINISH_CHUNK_LOADED = exports.EVENT_DATA_FINISH_CHUNK_LOADED = exports.EVENT_GRAND_CHUNK_LOADED = exports.EVENT_RANGEMINMAX_CHUNK_LOADED = exports.EVENT_DATABAR_CHUNK_LOADED = exports.EVENT_DATA_CHUNK_LOADED = exports.EVENT_DATA_LOAD = exports.DEFAULT_PAGE_SIZE = void 0;
18
+ /* eslint-disable @typescript-eslint/ban-types */
19
+ const events_1 = __importDefault(require("events"));
20
+ const constants_js_1 = require("../data-load/constants.js");
21
+ const index_js_1 = require("../errors/index.js");
22
+ const index_js_2 = require("../tree-structure/index.js");
23
+ const index_js_3 = require("../tree-structure/utils/index.js");
24
+ const index_js_4 = require("../utils/index.js");
25
+ const constants_js_2 = require("./constants.js");
26
+ const DivergenceComparator_js_1 = require("./DivergenceComparator.js");
27
+ const index_js_5 = require("./utils/index.js");
28
+ const getJaqlComposition = (jaql, rawMetadata) => {
29
+ const processedJaql = jaql || { metadata: [], grandTotals: null };
30
+ let { metadata } = processedJaql;
31
+ metadata = metadata.map((panel) => {
32
+ const field = panel.field || {};
33
+ // find format to compose from rawMetadata by field.index
34
+ const samePanel = rawMetadata.find(({ field: rawField }) => rawField && rawField.index === field.index);
35
+ const format = samePanel ? samePanel.format : null;
36
+ return format ? Object.assign(Object.assign({}, panel), { format }) : panel;
37
+ });
38
+ return Object.assign(Object.assign({}, processedJaql), { metadata });
39
+ };
40
+ exports.DEFAULT_PAGE_SIZE = 100;
41
+ exports.EVENT_DATA_LOAD = 'dataLoad';
42
+ exports.EVENT_DATA_CHUNK_LOADED = 'dataChunkLoaded';
43
+ exports.EVENT_DATABAR_CHUNK_LOADED = 'dataBarChunkLoaded';
44
+ exports.EVENT_RANGEMINMAX_CHUNK_LOADED = 'rangeMinMaxChunkLoaded';
45
+ exports.EVENT_GRAND_CHUNK_LOADED = 'grandChunkLoaded';
46
+ exports.EVENT_DATA_FINISH_CHUNK_LOADED = 'dataFinishChunkLoaded';
47
+ exports.EVENT_FINISH_CHUNK_LOADED = 'finishChunkLoaded';
48
+ exports.EVENT_PROGRESS_ERROR = 'progressError';
49
+ exports.EVENT_HEADER_CELL_FORMAT = 'headerCellFormat';
50
+ exports.EVENT_DATA_CELL_FORMAT = 'dataCellFormat';
51
+ exports.EVENT_TOTAL_ROWS_COUNT = 'totalRowsCountLoaded';
52
+ exports.EVENT_TOTAL_COLUMNS_COUNT = 'totalColumnsCountLoaded';
53
+ exports.NODES_CHUNK_SIZE_MAX = 1000;
54
+ // TODO Review if throttling is needed
55
+ exports.THROTTLE_TIME_MS = 0;
56
+ const defaultOptions = {
57
+ throttle: index_js_4.throttle,
58
+ throttleTime: exports.THROTTLE_TIME_MS,
59
+ PluginService: index_js_5.PluginService,
60
+ skipInternalColorFormatting: false,
61
+ subtotalsForSingleRow: false,
62
+ };
63
+ class DataService {
64
+ // eslint-disable-next-line max-lines-per-function
65
+ constructor(loadService, events, options) {
66
+ /**
67
+ *
68
+ *
69
+ * @private
70
+ *
71
+ * loaded data chunks group
72
+ */
73
+ this.tempDataChunks = [];
74
+ /**
75
+ *
76
+ * @private
77
+ *
78
+ * last not handled data chunks group index
79
+ */
80
+ this.lastNotHandledChunkIndex = 0;
81
+ /**
82
+ *
83
+ * @private
84
+ *
85
+ * last ready but not handled data chunks group index
86
+ */
87
+ this.lastReadyNotHandledChunkIndex = 0;
88
+ /**
89
+ *
90
+ * @private
91
+ *
92
+ * Current rows nodes
93
+ */
94
+ this.rowsGrand = undefined;
95
+ /**
96
+ *
97
+ @private */
98
+ this.rowsTreeService = undefined;
99
+ /**
100
+ *
101
+ @private */
102
+ this.columnsTreeService = undefined;
103
+ /**
104
+ *
105
+ @private */
106
+ this.cornerTreeService = undefined;
107
+ /**
108
+ @private */
109
+ this.pageSize = exports.DEFAULT_PAGE_SIZE;
110
+ /**
111
+ *
112
+ @private */
113
+ this.isPaginated = false;
114
+ /**
115
+ *
116
+ * @private
117
+ *
118
+ * number of loaded pages
119
+ */
120
+ this.loadedPagesCount = 0;
121
+ /**
122
+ *
123
+ * @private
124
+ *
125
+ * state for "loadData" method
126
+ */
127
+ this.isLoadInProgress = false;
128
+ /**
129
+ *
130
+ @private */
131
+ this.loadAllPromise = undefined;
132
+ /**
133
+ *
134
+ @private */
135
+ this.loadAllPromiseResolve = undefined;
136
+ /**
137
+ *
138
+ @private */
139
+ this.loadAllPromiseReject = undefined;
140
+ /**
141
+ *
142
+ * @private
143
+ *
144
+ * defines if all data is loaded
145
+ */
146
+ this.isWholeDataLoaded = false;
147
+ /**
148
+ *
149
+ * @private
150
+ *
151
+ * defines that data finish event is happened
152
+ */
153
+ this.hasDataFinishEvent = false;
154
+ /**
155
+ *
156
+ * @private
157
+ *
158
+ * defines that data handler in progress
159
+ */
160
+ this.isDataHandlerThrottled = false;
161
+ /**
162
+ *
163
+ * @private
164
+ *
165
+ * jaql request pure metadata
166
+ */
167
+ this.metadata = [];
168
+ /**
169
+ *
170
+ * @private
171
+ *
172
+ * service for items indexation divergence
173
+ */
174
+ this.divergenceComparator = new DivergenceComparator_js_1.DivergenceComparator();
175
+ /**
176
+ *
177
+ @private */
178
+ this.rawJaql = undefined;
179
+ /**
180
+ *
181
+ * @private
182
+ *
183
+ * triggered events data storage
184
+ */
185
+ this.triggeredEventsData = {};
186
+ /**
187
+ *
188
+ * @private
189
+ *
190
+ * plugins handlers
191
+ */
192
+ this.callPlugins = [];
193
+ /**
194
+ * Handler for pivot metadata received event
195
+ *
196
+ * @returns {void}
197
+ */
198
+ this.onMetadataHandler = () => {
199
+ const jaql = { metadata: this.getMetadata() };
200
+ const isSingleRowTree = this.isSingleRowTree();
201
+ if (isSingleRowTree) {
202
+ index_js_5.jaqlProcessor.normalizeSingleBranchTreeSortDetails(jaql);
203
+ }
204
+ };
205
+ this.onHeadersHandler = (data) => {
206
+ // bind methods for injecting them into tree service builders
207
+ const getJaql = this.getJaql.bind(this);
208
+ const getRawJaql = this.getRawJaql.bind(this);
209
+ const applyIndexDivergence = this.applyIndexDivergence.bind(this);
210
+ const emitHeaderCellFormatEvent = (item, panel, jaql) => this.emit(exports.EVENT_HEADER_CELL_FORMAT, item, panel, jaql, this.options);
211
+ // build columns tree service
212
+ const buildColumnsTreeService = DataService.createColumnsTreeServiceBuilder({
213
+ getJaql,
214
+ getRawJaql,
215
+ pluginService: this.pluginService,
216
+ applyIndexDivergence,
217
+ }, {
218
+ emitHeaderCellFormatEvent,
219
+ });
220
+ const columnsTreeServiceBuildResult = buildColumnsTreeService(data);
221
+ this.columnsTreeService = columnsTreeServiceBuildResult.columnsTreeService;
222
+ this.columnsCount = columnsTreeServiceBuildResult.columnsCount;
223
+ this.totalColumnsCount = columnsTreeServiceBuildResult.totalColumnsCount;
224
+ this.emit(exports.EVENT_TOTAL_COLUMNS_COUNT, {
225
+ columnsCount: this.columnsCount || 0,
226
+ totalColumnsCount: this.totalColumnsCount || 0,
227
+ });
228
+ // build corner tree service
229
+ const buildCornerTreeService = DataService.createCornerTreeServiceBuilder({
230
+ getJaql,
231
+ getRawJaql,
232
+ pluginService: this.pluginService,
233
+ columnsTreeService: this.columnsTreeService,
234
+ }, {
235
+ emitHeaderCellFormatEvent,
236
+ });
237
+ const { cornerTreeService } = buildCornerTreeService();
238
+ this.cornerTreeService = cornerTreeService;
239
+ };
240
+ this.onDataHandler = (data) => {
241
+ // store the data chunk into temporary storage
242
+ // this step is NOT throttled because we want to make
243
+ // ALL data chunks coming (regardless of the rate) is captured
244
+ this.tempDataChunks = this.tempDataChunks || [];
245
+ if (Array.isArray(data)) {
246
+ (data || []).forEach((item) => {
247
+ DataService.fillDataChunks(this.tempDataChunks, item, this.pageSize);
248
+ });
249
+ }
250
+ else {
251
+ DataService.fillDataChunks(this.tempDataChunks, data, this.pageSize);
252
+ }
253
+ // the data processing step CAN be throttled
254
+ // However, method onDataHandlerThrottle needs logic
255
+ // to maintain the LAST processed chunk
256
+ if (this.tempDataChunks.length) {
257
+ this.isDataHandlerThrottled = true;
258
+ // @ts-ignore
259
+ this.onDataHandlerThrottle();
260
+ }
261
+ };
262
+ this.onGrandHandler = (data) => {
263
+ const rows = this.preProcessTree([data], constants_js_2.PanelType.ROWS);
264
+ const mainNode = rows[0];
265
+ const name = 'Rows grand total';
266
+ const grandData = mainNode ? mainNode.data : [];
267
+ const node = index_js_3.treeNode.create(name, undefined, grandData);
268
+ const grandTotalNode = (0, index_js_5.createPivotTreeNode)(node, constants_js_2.PanelType.ROWS);
269
+ grandTotalNode.userType = constants_js_2.UserType.GRAND_TOTAL;
270
+ this.postProcessTree([grandTotalNode]);
271
+ this.postProcessData([grandTotalNode]);
272
+ this.rowsGrand = grandTotalNode;
273
+ this.emit(exports.EVENT_GRAND_CHUNK_LOADED, index_js_3.treeNode.wrapInRootNode(this.rowsGrand));
274
+ };
275
+ this.onFinishHandler = () => {
276
+ this.emit(exports.EVENT_FINISH_CHUNK_LOADED, {
277
+ totalRows: typeof this.totalRowsCount === 'number' ? this.totalRowsCount : this.getTotalItemsCount(),
278
+ totalColumns: typeof this.totalColumnsCount === 'number'
279
+ ? this.totalColumnsCount
280
+ : this.getLoadedColumnsCount(), // backward compatibility
281
+ });
282
+ };
283
+ this.onTotalRowsHandler = (data) => {
284
+ const { rowsCount, queryRowsCount, limitReached } = data || {};
285
+ this.totalRowsCount = rowsCount;
286
+ this.totalRecordsCount = queryRowsCount;
287
+ this.limitReached = limitReached;
288
+ this.emit(exports.EVENT_TOTAL_ROWS_COUNT, data);
289
+ };
290
+ this.onDataBarsHandler = (chunk) => {
291
+ const { data = [] } = chunk;
292
+ let offset = 0;
293
+ if (this.cornerTreeService) {
294
+ offset = this.cornerTreeService.getTreeChildLength();
295
+ }
296
+ this.dataBars = [...Array(offset), ...data];
297
+ this.emit(exports.EVENT_DATABAR_CHUNK_LOADED, this.dataBars);
298
+ };
299
+ this.onRangeMinMaxHandler = (chunk) => {
300
+ const { data = [] } = chunk;
301
+ const jaql = this.getJaql();
302
+ const measuresTree = index_js_5.jaqlProcessor.getMetadataTree(jaql, constants_js_2.PanelType.MEASURES);
303
+ const measures = index_js_3.treeNode.getChildren(measuresTree);
304
+ const rangeMinMax = [];
305
+ measures.forEach((measure, index) => {
306
+ // align indexes in case disabled measures
307
+ rangeMinMax[measure.measureJaqlIndex || 0] = data[index];
308
+ });
309
+ this.rangeMinMax = rangeMinMax;
310
+ this.emit(exports.EVENT_RANGEMINMAX_CHUNK_LOADED, this.rangeMinMax);
311
+ };
312
+ this.onDataFinishHandler = ({ rowsCount } = {}) => {
313
+ this.finishRequest();
314
+ this.rowsCount = rowsCount;
315
+ if (this.tempDataChunks.length) {
316
+ const chunkLast = this.tempDataChunks[this.tempDataChunks.length - 1];
317
+ chunkLast.ready = true;
318
+ }
319
+ // @ts-ignore
320
+ this.onDataHandlerThrottle();
321
+ this.checkLoadPromise();
322
+ this.emit(exports.EVENT_DATA_FINISH_CHUNK_LOADED, {
323
+ limitedRows: this.rowsCount,
324
+ limitedColumns: this.columnsCount,
325
+ });
326
+ };
327
+ this.onErrorHandler = (data) => {
328
+ if (process.env.NODE_ENV !== 'production') {
329
+ // eslint-disable-next-line no-console
330
+ console.warn(`DataService data loading error "${JSON.stringify(data)}"`);
331
+ }
332
+ if (!this.isLoadInProgress &&
333
+ !this.isWholeDataLoaded &&
334
+ !(data instanceof index_js_1.LoadingCanceledError)) {
335
+ // post load error
336
+ this.emit(exports.EVENT_PROGRESS_ERROR, data);
337
+ }
338
+ };
339
+ this.loadService = loadService;
340
+ this.events = events || new events_1.default();
341
+ this.options = Object.assign(Object.assign({}, defaultOptions), options);
342
+ this.attachEvent();
343
+ this.onDataHandlerThrottle = this.options.throttle(() => {
344
+ const chunkIndex = (0, index_js_4.findIndex)(this.tempDataChunks, (item) => item.ready && !item.handled, this.lastReadyNotHandledChunkIndex);
345
+ if (chunkIndex === -1) {
346
+ return;
347
+ }
348
+ this.lastReadyNotHandledChunkIndex = chunkIndex;
349
+ const chunk = this.tempDataChunks[chunkIndex];
350
+ const rows = this.preProcessTree(chunk.list, constants_js_2.PanelType.ROWS);
351
+ const modifiedRows = this.modifyTree(rows, constants_js_2.PanelType.ROWS);
352
+ this.postProcessTree(modifiedRows, { skipFormatEvent: true });
353
+ this.postProcessData(modifiedRows, { skipFormatEvent: true });
354
+ const wrappedModifiedRows = index_js_3.treeNode.wrapInRootNode(modifiedRows);
355
+ if (this.rowsTreeService) {
356
+ this.rowsTreeService.extend(wrappedModifiedRows);
357
+ }
358
+ else {
359
+ this.rowsTreeService = new index_js_2.TreeService(wrappedModifiedRows, true);
360
+ }
361
+ this.emit(exports.EVENT_DATA_CHUNK_LOADED, this.getLoadedElementsCount());
362
+ chunk.handled = true;
363
+ const nextChunkIndex = (0, index_js_4.findIndex)(this.tempDataChunks, (item) => !item.handled, this.lastNotHandledChunkIndex);
364
+ if (nextChunkIndex !== -1) {
365
+ this.lastNotHandledChunkIndex = nextChunkIndex;
366
+ // Note: removed `setImmediate` as not support
367
+ this.onDataHandlerThrottle();
368
+ }
369
+ else {
370
+ this.isDataHandlerThrottled = false;
371
+ }
372
+ if (this.hasDataFinishEvent && this.tempDataChunks.length) {
373
+ const chunkLast = this.tempDataChunks[this.tempDataChunks.length - 1];
374
+ chunkLast.ready = true;
375
+ }
376
+ if (this.hasDataFinishEvent && nextChunkIndex === -1) {
377
+ this.finishRequest();
378
+ this.checkLoadPromise();
379
+ }
380
+ else {
381
+ this.checkLoadPromise();
382
+ }
383
+ }, this.options.throttleTime);
384
+ }
385
+ destroy() {
386
+ this.detachEvent();
387
+ this.rowsGrand = undefined;
388
+ this.rowsTreeService = undefined;
389
+ this.columnsTreeService = undefined;
390
+ this.cornerTreeService = undefined;
391
+ this.tempDataChunks = [];
392
+ this.lastNotHandledChunkIndex = 0;
393
+ this.lastReadyNotHandledChunkIndex = 0;
394
+ this.events.removeAllListeners();
395
+ }
396
+ /**
397
+ * Subscribe to event notification
398
+ *
399
+ * @param {string} eventName - event name to subscribe
400
+ * @param {Function} callback - event handler
401
+ * @returns {void}
402
+ */
403
+ on(eventName, callback) {
404
+ this.events.on(eventName, callback);
405
+ if (this.triggeredEventsData[eventName]) {
406
+ this.triggeredEventsData[eventName].forEach((payload) => {
407
+ // Note: removed `setImmediate` as not supported
408
+ this.events.emit(eventName, ...payload);
409
+ });
410
+ delete this.triggeredEventsData[eventName];
411
+ }
412
+ }
413
+ /**
414
+ * Emits event with payload
415
+ *
416
+ * @param {string} eventName - event name to emit
417
+ * @param {Array<any>} payload - event payload
418
+ * @returns {void}
419
+ */
420
+ emit(eventName, ...payload) {
421
+ const eventListeners = this.events.listeners(eventName);
422
+ if (eventListeners.length === 0) {
423
+ this.triggeredEventsData[eventName] = this.triggeredEventsData[eventName] || [];
424
+ this.triggeredEventsData[eventName].push(payload);
425
+ }
426
+ else {
427
+ this.events.emit(eventName, ...payload);
428
+ }
429
+ }
430
+ /**
431
+ * Unsubscribe from event notification
432
+ *
433
+ * @param {string} eventName - event name to unsubscribe from
434
+ * @param {Function} callback - event handler
435
+ * @returns {void}
436
+ */
437
+ off(eventName, callback) {
438
+ this.events.removeListener(eventName, callback);
439
+ if (this.triggeredEventsData[eventName]) {
440
+ delete this.triggeredEventsData[eventName];
441
+ }
442
+ }
443
+ /**
444
+ * Initialize start data loading
445
+ *
446
+ * @param {JaqlRequest} [jaql] - JAQL request object
447
+ * @param {object} [options] - additional options
448
+ * @param {number} [options.pageSize=100] - page size to wait
449
+ * @param {boolean} [options.isPaginated=false] - defines which type of treeService to return,
450
+ * partial or paginated
451
+ * @param {Array<JaqlPanel>} [options.metadata] - jaql's metadata
452
+ * @param {boolean} [options.cacheResult=false] - cache result for next call or not
453
+ * @returns {Promise<any>} - promise with initial data to render
454
+ */
455
+ // eslint-disable-next-line max-lines-per-function,sonarjs/cognitive-complexity
456
+ loadData(jaql, options) {
457
+ // console.log('loadData', jaql, options);
458
+ const { pageSize = exports.DEFAULT_PAGE_SIZE, isPaginated = false, cacheResult = false, metadata, } = options || {};
459
+ const pageSizeIsNotChanged = this.pageSize === pageSize;
460
+ this.clearLoadAllPromise();
461
+ if (jaql) {
462
+ this.clearCache();
463
+ // TODO review this
464
+ // this.onDataHandlerThrottle.cancel();
465
+ }
466
+ this.pageSize = pageSize;
467
+ this.isPaginated = isPaginated;
468
+ this.emit(exports.EVENT_DATA_LOAD);
469
+ if (this.loadPromiseCache && pageSizeIsNotChanged) {
470
+ const loadPromise = Promise.resolve(this.loadPromiseCache);
471
+ this.loadPromiseCache = undefined;
472
+ return loadPromise;
473
+ }
474
+ this.isLoadInProgress = true;
475
+ if (jaql) {
476
+ this.metadata = metadata || [];
477
+ this.rawJaql = getJaqlComposition(jaql, this.metadata);
478
+ // console.log('getJaqlComposition', jaql, this.metadata, this.rawJaql);
479
+ this.initPluginService(this.rawJaql);
480
+ this.loadService
481
+ .load(jaql)
482
+ .then((data) => {
483
+ if (data === null || data === undefined) {
484
+ return;
485
+ }
486
+ const isDataNotExist = !('data' in data);
487
+ const isDataTransferFinished = data.dataFinish[0];
488
+ if (isDataTransferFinished && isDataNotExist) {
489
+ // eslint-disable-next-line no-throw-literal
490
+ throw {
491
+ error: {
492
+ error: true,
493
+ details: 'metadata undefined.',
494
+ },
495
+ };
496
+ }
497
+ })
498
+ .catch((data) => {
499
+ if (this.loadPromiseReject) {
500
+ this.loadPromiseReject(data.error);
501
+ }
502
+ });
503
+ }
504
+ const loadPromise = new Promise((resolve, reject) => {
505
+ this.loadPromiseResolve = resolve;
506
+ this.loadPromiseReject = reject;
507
+ })
508
+ .then((loadedCount) => this.sendInitPage(loadedCount))
509
+ .then((data) => {
510
+ if (cacheResult) {
511
+ this.loadPromiseCache = data;
512
+ }
513
+ this.loadedPagesCount = 1;
514
+ return data;
515
+ })
516
+ .catch((err) => {
517
+ if (err instanceof index_js_1.LoadingCanceledError) {
518
+ this.clearLoadPromise();
519
+ }
520
+ throw err;
521
+ });
522
+ this.checkLoadPromise();
523
+ return loadPromise;
524
+ }
525
+ /**
526
+ * Sets Promise that resolves after all data loaded
527
+ *
528
+ * @returns {Promise<{ loadedRowsCount: number, totalItemsCount: number }>} - promise with
529
+ * loaded items count
530
+ */
531
+ loadAllData() {
532
+ if (this.isWholeDataLoaded) {
533
+ const allDataInfo = {
534
+ loadedRowsCount: this.getLoadedElementsCount(),
535
+ totalItemsCount: typeof this.totalRowsCount === 'number' ? this.totalRowsCount : this.getTotalItemsCount(),
536
+ totalRecordsCount: this.totalRecordsCount,
537
+ limitReached: this.limitReached,
538
+ dataBars: this.dataBars,
539
+ rangeMinMax: this.rangeMinMax,
540
+ };
541
+ if (this.columnsCount !== 0 && this.totalColumnsCount !== 0) {
542
+ allDataInfo.columnsCount = this.columnsCount;
543
+ allDataInfo.totalColumnsCount = this.totalColumnsCount;
544
+ }
545
+ return Promise.resolve(allDataInfo);
546
+ }
547
+ if (!this.loadAllPromise) {
548
+ this.loadAllPromise = new Promise((resolve, reject) => {
549
+ this.loadAllPromiseResolve = resolve;
550
+ this.loadAllPromiseReject = reject;
551
+ })
552
+ .then(() => ({
553
+ loadedRowsCount: this.getLoadedElementsCount(),
554
+ totalItemsCount: typeof this.totalRowsCount === 'number'
555
+ ? this.totalRowsCount
556
+ : this.getTotalItemsCount(),
557
+ totalRecordsCount: this.totalRecordsCount,
558
+ limitReached: this.limitReached,
559
+ dataBars: this.dataBars,
560
+ rangeMinMax: this.rangeMinMax,
561
+ }))
562
+ .catch((err) => {
563
+ if (err instanceof index_js_1.LoadingCanceledError) {
564
+ this.clearLoadAllPromise();
565
+ }
566
+ throw err;
567
+ });
568
+ }
569
+ return this.loadAllPromise;
570
+ }
571
+ /**
572
+ * public method for selecting page and setting new page size
573
+ *
574
+ * @param {number} selected - page number
575
+ * @param {number} pageSize - set page size (optional)
576
+ * @returns {Promise<{rowsTreeService, columnsTreeService, cornerTreeService, isLastPage}>}
577
+ * - returns private method's call with panel's treeServices
578
+ */
579
+ getSelectedPageData(selected, pageSize) {
580
+ return Promise.resolve(this.sendPaginatedPage(selected, pageSize));
581
+ }
582
+ /**
583
+ * public method for selecting page by indexes
584
+ *
585
+ * @param {number} from - first row's index
586
+ * @param {number} to - last row's index
587
+ * @param {boolean} lastPage - append grandTotals
588
+ * @returns {Promise<{rowsTreeService, columnsTreeService, cornerTreeService, isLastPage}>}
589
+ * - returns private method's call with panel's treeServices
590
+ */
591
+ getIndexedPageData(from, to, lastPage = false) {
592
+ return Promise.resolve(this.sendPartialPage(from, to, lastPage));
593
+ }
594
+ /**
595
+ * Returns current jaql request object
596
+ *
597
+ * @returns {JaqlRequest} - jaql request object
598
+ */
599
+ getJaql() {
600
+ return (this.loadService.getJaql() || {
601
+ metadata: [],
602
+ grandTotals: null,
603
+ });
604
+ }
605
+ /**
606
+ * Defines data structure
607
+ *
608
+ * @returns {boolean} - true - single branch tree
609
+ */
610
+ isSingleRowTree() {
611
+ return this.loadService.isSingleRowTree();
612
+ }
613
+ /**
614
+ * Set cell process handlers
615
+ *
616
+ * @param {Array<PluginConfig>} handlers - object with target and handler
617
+ * @returns {void}
618
+ */
619
+ setPluginHandlers(handlers) {
620
+ this.callPlugins = handlers;
621
+ }
622
+ /**
623
+ * Set global styles for all cells
624
+ *
625
+ * @param {GlobalStyles} [styles] - object with target and handler
626
+ * @returns {void}
627
+ */
628
+ setGlobalStyles(styles) {
629
+ this.globalStyles = styles;
630
+ }
631
+ /**
632
+ * Returns current raw jaql request object
633
+ *
634
+ * @returns {JaqlRequest} - composition of required jaql fields
635
+ * @private
636
+ */
637
+ getRawJaql() {
638
+ return this.rawJaql || this.getJaql();
639
+ }
640
+ /**
641
+ * Returns current jaql request metadata array
642
+ *
643
+ * @returns {Array<JaqlPanel>} - jaql request metadata
644
+ * @private
645
+ */
646
+ getMetadata() {
647
+ return this.metadata.length > 0 ? this.metadata : this.getJaql().metadata;
648
+ }
649
+ /**
650
+ * Pre-process initial tree structure
651
+ *
652
+ * @param {Array<TreeNode>} items - items to normalize
653
+ * @param {string} type - items types to normalize
654
+ * @param {object} options - additional options
655
+ * @param {number} [options.level=0] - tree level, for internal use only
656
+ * @param {object} [options.measurePath={}] - items types to normalize
657
+ * @returns {Array<PivotTreeNode>} - normalized list of items
658
+ */
659
+ preProcessTree(items, type, options) {
660
+ return index_js_5.pivotTransforms.preProcessTree(items, type, this.getJaql(), options);
661
+ }
662
+ /**
663
+ * Post-process final tree structure with formatting event
664
+ *
665
+ * @param {PivotTreeNode} items - list of PivotTreeNode items
666
+ * @param {object} [options] - additional options
667
+ * @param {boolean} [options.skipFormatEvent] - process tree but skip format event trigger
668
+ * @param {boolean} [options.onlyFormatEvents] - process tree with format event trigger only
669
+ * @param {Function} [options.iterateFn] - iterate function to call for each tree node
670
+ * @returns {void}
671
+ */
672
+ postProcessTree(items, options) {
673
+ const emitFn = (item, panel, jaql) => this.emit(exports.EVENT_HEADER_CELL_FORMAT, item, panel, jaql, this.options);
674
+ const extendedOptions = Object.assign(Object.assign({}, (options || {})), { emitFn });
675
+ return index_js_5.pivotTransforms.postProcessTree(items, this.getRawJaql(), extendedOptions);
676
+ }
677
+ /**
678
+ * Post-process data list with formatting event
679
+ *
680
+ * @param {PivotTreeNode} items - list of PivotTreeNode rows items
681
+ * @param {object} [options] - additional options
682
+ * @param {boolean} [options.skipFormatEvent] - process data list but skip format event trigger
683
+ * @param {boolean} [options.onlyFormatEvents] - process data list with format event
684
+ * trigger only
685
+ * @returns {void}
686
+ */
687
+ // eslint-disable-next-line sonarjs/cognitive-complexity
688
+ postProcessData(items, options) {
689
+ const { skipFormatEvent = false, onlyFormatEvents = false } = options || {};
690
+ const columns = this.columnsTreeService ? this.columnsTreeService.getLastLevelNodes() : [];
691
+ const rows = index_js_3.treeNode.getLastLevelNodes(items);
692
+ const jaql = this.getRawJaql();
693
+ if (skipFormatEvent) {
694
+ return;
695
+ }
696
+ rows.forEach((rowTreeNode) => {
697
+ const rowItem = (0, index_js_5.createPivotTreeNode)(rowTreeNode);
698
+ columns.forEach((columnTreeNode) => {
699
+ const columnItem = (0, index_js_5.createPivotTreeNode)(columnTreeNode);
700
+ const measurePanel = index_js_5.jaqlProcessor.getMetadataPanelByIndex(jaql, columnItem.measureJaqlIndex, constants_js_2.PanelType.MEASURES);
701
+ if (typeof rowItem.data !== 'undefined' && typeof columnItem.index !== 'undefined') {
702
+ const { data = [] } = rowItem;
703
+ const { index } = columnItem;
704
+ const value = data[index];
705
+ const item = typeof value === 'object' && value !== null && value !== undefined ? value : { value };
706
+ data[index] = item;
707
+ if (onlyFormatEvents || !skipFormatEvent) {
708
+ const { skipInternalColorFormatting = false } = this.options;
709
+ if (!skipInternalColorFormatting) {
710
+ index_js_5.pivotTransforms.applyColorFormatting(item, rowItem, columnItem, measurePanel);
711
+ }
712
+ this.emit(exports.EVENT_DATA_CELL_FORMAT, item, rowItem, columnItem, measurePanel, jaql, this.options);
713
+ }
714
+ }
715
+ });
716
+ });
717
+ }
718
+ /**
719
+ * Modify tree structure for subtotals and grand totals and some customization
720
+ *
721
+ * @param {Array<PivotTreeNode>} items - base items to modify
722
+ * @param {string} type - items types to normalize
723
+ * @param {TreeNode} originalData - initial data object
724
+ * @returns {PivotTreeNode | Array<PivotTreeNode>} - normalized list of items
725
+ */
726
+ modifyTree(items, type, originalData) {
727
+ const jaql = this.getJaql();
728
+ return index_js_5.pivotTransforms.modifyTree(items, type, jaql, {
729
+ originalData,
730
+ applyIndexDivergence: this.applyIndexDivergence.bind(this),
731
+ subtotalsForSingleRow: this.options.subtotalsForSingleRow,
732
+ });
733
+ }
734
+ /**
735
+ * method calculates divergence by prev indexes
736
+ *
737
+ * @param {Array<PivotTreeNode>} items - data to modify divergence and apply
738
+ * @returns {void}
739
+ * @private
740
+ */
741
+ applyIndexDivergence(items) {
742
+ this.divergenceComparator = new DivergenceComparator_js_1.DivergenceComparator(items, this.divergenceComparator);
743
+ }
744
+ /**
745
+ * method creates plugin service instance for pivot
746
+ *
747
+ * @param {JaqlRequest} jaql - data to modify divergence and apply
748
+ * @returns {void}
749
+ * @private
750
+ */
751
+ initPluginService(jaql) {
752
+ this.pluginService = new this.options.PluginService(this.callPlugins, jaql, this.globalStyles);
753
+ }
754
+ /**
755
+ * Cancel current loading process
756
+ *
757
+ * @returns {void}
758
+ */
759
+ cancelLoading() {
760
+ const loadingCanceledError = new index_js_1.LoadingCanceledError();
761
+ if (this.loadPromiseReject && typeof this.loadPromiseReject === 'function') {
762
+ this.loadPromiseReject(loadingCanceledError);
763
+ }
764
+ if (this.loadAllPromiseReject && typeof this.loadAllPromiseReject === 'function') {
765
+ this.loadAllPromiseReject(loadingCanceledError);
766
+ }
767
+ this.detachEvent();
768
+ }
769
+ /**
770
+ * Returns final page size, excluding grand totals rows for example
771
+ *
772
+ * @returns {number} - page size
773
+ * @private
774
+ */
775
+ getPageSize() {
776
+ return this.pageSize;
777
+ }
778
+ /**
779
+ *
780
+ * Send result for "loadData" function after promise resolve
781
+ *
782
+ * @param {number} loadedCount - count of already loaded rows
783
+ * @returns {{
784
+ * rowsTreeService: TreeServiceI,
785
+ * columnsTreeService: TreeServiceI,
786
+ * corner: TreeNode,
787
+ * values: TreeNode,
788
+ * cellsMetadata: Map<string, Metadata>
789
+ * }} - object with initial data
790
+ * @private
791
+ */
792
+ sendInitPage(loadedCount) {
793
+ if (this.loadService.hasError() || !this.loadService.hasData()) {
794
+ return DataService.getEmptyPage();
795
+ }
796
+ let partialRowsService;
797
+ let cellsMetadata;
798
+ const pageSize = this.getPageSize();
799
+ if (this.rowsTreeService) {
800
+ const from = 0;
801
+ const to = pageSize > loadedCount ? loadedCount : pageSize;
802
+ const cloneFn = DataService.cloneTreeNode;
803
+ const partialTree = this.rowsTreeService.getPartialTree(from, to, { cloneFn });
804
+ if (this.rowsGrand) {
805
+ partialTree.push((0, index_js_4.cloneObject)(this.rowsGrand));
806
+ }
807
+ this.postProcessTree(partialTree, {
808
+ onlyFormatEvents: true,
809
+ iterateFn: index_js_3.treeNode.clearNodeCache,
810
+ });
811
+ this.postProcessData(partialTree, { onlyFormatEvents: true });
812
+ const deepLength = this.rowsTreeService ? this.rowsTreeService.getTreeDeepsLength() : 0;
813
+ const wrappedModifiedRows = index_js_3.treeNode.wrapInRootNode(partialTree);
814
+ if (this.pluginService && wrappedModifiedRows && wrappedModifiedRows.children) {
815
+ this.pluginService.applyToRows(wrappedModifiedRows.children);
816
+ cellsMetadata = this.pluginService.metadataCache;
817
+ }
818
+ partialRowsService = new index_js_2.TreeService(wrappedModifiedRows, true, deepLength);
819
+ partialRowsService.hasGrandTotals = !!this.rowsGrand;
820
+ }
821
+ const isLastPage = this.isWholeDataLoaded && pageSize >= loadedCount;
822
+ return {
823
+ rowsTreeService: partialRowsService,
824
+ columnsTreeService: this.columnsTreeService,
825
+ cornerTreeService: this.cornerTreeService,
826
+ isLastPage,
827
+ cellsMetadata,
828
+ };
829
+ }
830
+ /**
831
+ * Sets Page Size and returns Tree Services
832
+ *
833
+ * @param {number} selected - page number -- STARTING FROM 0
834
+ * @param {number} [newPageSize] - set new pageSize
835
+ * @returns {{
836
+ * rowsTreeService: null,
837
+ * columnsTreeService: TreeServiceI,
838
+ * cornerTreeService: TreeServiceI,
839
+ * isLastPage: boolean
840
+ * }} - returns panel's treeServices
841
+ * @private
842
+ */
843
+ // eslint-disable-next-line sonarjs/cognitive-complexity
844
+ sendPaginatedPage(selected, newPageSize) {
845
+ if (this.loadService.hasError() || !this.loadService.hasData()) {
846
+ return DataService.getEmptyPage();
847
+ }
848
+ if (newPageSize) {
849
+ this.pageSize = newPageSize;
850
+ }
851
+ const pageSize = this.getPageSize();
852
+ const loadedCount = this.getLoadedElementsCount();
853
+ if (selected * pageSize >= loadedCount) {
854
+ throw new Error('Selected page is out of elements range!');
855
+ }
856
+ if (selected < 0) {
857
+ throw new Error('Selected page must be >= 0');
858
+ }
859
+ let partialRowsService;
860
+ let cellsMetadata;
861
+ if (this.rowsTreeService) {
862
+ const from = selected >= 0 ? selected * pageSize : 0;
863
+ const to = (selected + 1) * pageSize > loadedCount ? loadedCount : (selected + 1) * pageSize;
864
+ const cloneFn = DataService.cloneTreeNode;
865
+ const partialTree = this.rowsTreeService.getPartialTree(from, to, { cloneFn });
866
+ if (this.rowsGrand) {
867
+ partialTree.push((0, index_js_4.cloneObject)(this.rowsGrand));
868
+ }
869
+ this.postProcessTree(partialTree, {
870
+ onlyFormatEvents: true,
871
+ iterateFn: index_js_3.treeNode.clearNodeCache,
872
+ });
873
+ this.postProcessData(partialTree, { onlyFormatEvents: true });
874
+ const deepLength = this.rowsTreeService ? this.rowsTreeService.getTreeDeepsLength() : 0;
875
+ const wrappedModifiedRows = index_js_3.treeNode.wrapInRootNode(partialTree);
876
+ if (this.pluginService && wrappedModifiedRows && wrappedModifiedRows.children) {
877
+ this.pluginService.applyToRows(wrappedModifiedRows.children);
878
+ cellsMetadata = this.pluginService.metadataCache;
879
+ }
880
+ partialRowsService = new index_js_2.TreeService(wrappedModifiedRows, true, deepLength);
881
+ partialRowsService.hasGrandTotals = !!this.rowsGrand;
882
+ }
883
+ return {
884
+ rowsTreeService: partialRowsService,
885
+ columnsTreeService: this.columnsTreeService,
886
+ cornerTreeService: this.cornerTreeService,
887
+ isLastPage: true,
888
+ cellsMetadata,
889
+ };
890
+ }
891
+ /**
892
+ * Returns partial tree by indexes
893
+ *
894
+ * @param {number} paramFrom - start index
895
+ * @param {number} paramTo - stop index
896
+ * @param {boolean} lastPage - append grandTotals
897
+ * @returns {{
898
+ * rowsTreeService: TreeServiceI,
899
+ * columnsTreeService: TreeServiceI,
900
+ * cornerTreeService: TreeServiceI,
901
+ * isLastPage: boolean
902
+ * }} - returns panel's treeServices
903
+ * @private
904
+ */
905
+ sendPartialPage(paramFrom, paramTo, lastPage) {
906
+ if (this.loadService.hasError() || !this.loadService.hasData()) {
907
+ return DataService.getEmptyPage();
908
+ }
909
+ const loadedCount = this.getLoadedElementsCount();
910
+ let [from, to] = [Math.min(paramFrom, paramTo), Math.max(paramFrom, paramTo)];
911
+ from = from >= 0 ? from : 0;
912
+ to = to >= 0 ? to : 0;
913
+ to = to < loadedCount ? to : loadedCount;
914
+ let rowsTreeService;
915
+ let cellsMetadata;
916
+ if (from > loadedCount) {
917
+ rowsTreeService = undefined;
918
+ }
919
+ else {
920
+ let partialTree;
921
+ if (this.rowsTreeService) {
922
+ const cloneFn = DataService.cloneTreeNode;
923
+ partialTree = this.rowsTreeService.getPartialTree(from, to, { cloneFn });
924
+ if (lastPage && this.rowsGrand) {
925
+ partialTree.push((0, index_js_4.cloneObject)(this.rowsGrand));
926
+ }
927
+ this.postProcessTree(partialTree, {
928
+ onlyFormatEvents: true,
929
+ iterateFn: index_js_3.treeNode.clearNodeCache,
930
+ });
931
+ this.postProcessData(partialTree, { onlyFormatEvents: true });
932
+ }
933
+ const deepLength = this.rowsTreeService ? this.rowsTreeService.getTreeDeepsLength() : 0;
934
+ const wrappedModifiedRows = index_js_3.treeNode.wrapInRootNode(partialTree);
935
+ if (this.pluginService && wrappedModifiedRows && wrappedModifiedRows.children) {
936
+ this.pluginService.applyToRows(wrappedModifiedRows.children);
937
+ cellsMetadata = this.pluginService.metadataCache;
938
+ }
939
+ rowsTreeService = new index_js_2.TreeService(wrappedModifiedRows, true, deepLength);
940
+ rowsTreeService.hasGrandTotals = !!(lastPage && this.rowsGrand);
941
+ }
942
+ return {
943
+ rowsTreeService,
944
+ columnsTreeService: this.columnsTreeService,
945
+ cornerTreeService: this.cornerTreeService,
946
+ isLastPage: true,
947
+ cellsMetadata,
948
+ };
949
+ }
950
+ /**
951
+ *
952
+ * Get current state of tree (not recommended to use before 'loadData')
953
+ *
954
+ * @returns {number} loadedCount - current loaded count of children
955
+ * @private
956
+ */
957
+ getLoadedElementsCount() {
958
+ return this.rowsTreeService ? this.rowsTreeService.getTreeChildLength() : 0;
959
+ }
960
+ /**
961
+ * Returns total amount items count handled on back-end side
962
+ *
963
+ * @deprecated
964
+ * @returns {number} - items count
965
+ * @private
966
+ */
967
+ getTotalItemsCount() {
968
+ return this.loadService.getTotalItemsCount();
969
+ }
970
+ /**
971
+ * Getter for pivot table loaded columns number
972
+ *
973
+ * @deprecated
974
+ * @returns {number} loadedCount - current loaded pivot table columns count
975
+ * @private
976
+ */
977
+ getLoadedColumnsCount() {
978
+ return this.columnsTreeService ? this.columnsTreeService.getTreeChildLength() : 0;
979
+ }
980
+ /**
981
+ * Attach events to load service
982
+ * This is a key function implementing the Observer pattern
983
+ * DataService acts as Observer and subscribes its handlers to various
984
+ * data loading events emitted by the load service.
985
+ *
986
+ *
987
+ * @returns {void}
988
+ * @private
989
+ */
990
+ attachEvent() {
991
+ if (this.loadService.listenerCount(constants_js_1.MessageType.HEADERS)) {
992
+ this.loadService.offAll(constants_js_1.MessageType.HEADERS);
993
+ }
994
+ this.loadService.on(constants_js_1.MessageType.HEADERS, this.onHeadersHandler);
995
+ this.loadService.on(constants_js_1.MessageType.METADATA, this.onMetadataHandler);
996
+ this.loadService.on(constants_js_1.MessageType.DATA, this.onDataHandler);
997
+ this.loadService.on(constants_js_1.MessageType.GRAND, this.onGrandHandler);
998
+ this.loadService.on(constants_js_1.MessageType.DATA_FINISH, this.onDataFinishHandler);
999
+ this.loadService.on(constants_js_1.MessageType.TOTAL_ROWS, this.onTotalRowsHandler);
1000
+ this.loadService.on(constants_js_1.MessageType.DATABARS, this.onDataBarsHandler);
1001
+ this.loadService.on(constants_js_1.MessageType.RANGE_MIN_MAX, this.onRangeMinMaxHandler);
1002
+ this.loadService.on(constants_js_1.MessageType.FINISH, this.onFinishHandler);
1003
+ this.loadService.on(constants_js_1.MessageType.ERROR, this.onErrorHandler);
1004
+ }
1005
+ /**
1006
+ * Dettach events from load service
1007
+ *
1008
+ * @returns {void}
1009
+ * @private
1010
+ */
1011
+ detachEvent() {
1012
+ this.loadService.off(constants_js_1.MessageType.HEADERS, this.onHeadersHandler);
1013
+ this.loadService.off(constants_js_1.MessageType.METADATA, this.onMetadataHandler);
1014
+ this.loadService.off(constants_js_1.MessageType.DATA, this.onDataHandler);
1015
+ this.loadService.off(constants_js_1.MessageType.GRAND, this.onGrandHandler);
1016
+ this.loadService.off(constants_js_1.MessageType.DATA_FINISH, this.onDataFinishHandler);
1017
+ this.loadService.off(constants_js_1.MessageType.TOTAL_ROWS, this.onTotalRowsHandler);
1018
+ this.loadService.off(constants_js_1.MessageType.DATABARS, this.onDataBarsHandler);
1019
+ this.loadService.off(constants_js_1.MessageType.RANGE_MIN_MAX, this.onRangeMinMaxHandler);
1020
+ this.loadService.off(constants_js_1.MessageType.FINISH, this.onFinishHandler);
1021
+ this.loadService.off(constants_js_1.MessageType.ERROR, this.onErrorHandler);
1022
+ }
1023
+ /**
1024
+ * Check for enough data loaded and resolve promise of "loadData" function
1025
+ *
1026
+ * @returns {void}
1027
+ * @private
1028
+ */
1029
+ checkLoadPromise() {
1030
+ if (!this.isLoadInProgress) {
1031
+ return;
1032
+ }
1033
+ const loadedCount = this.getLoadedElementsCount();
1034
+ if (loadedCount >= this.getPageSize() || this.isWholeDataLoaded) {
1035
+ this.isLoadInProgress = false;
1036
+ if (typeof this.loadPromiseResolve === 'function') {
1037
+ this.loadPromiseResolve(loadedCount);
1038
+ this.clearLoadPromise();
1039
+ }
1040
+ }
1041
+ }
1042
+ /**
1043
+ * @returns {void}
1044
+ * @private
1045
+ */
1046
+ clearLoadAllPromise() {
1047
+ this.loadAllPromise = undefined;
1048
+ this.loadAllPromiseReject = undefined;
1049
+ this.loadAllPromiseResolve = undefined;
1050
+ }
1051
+ /**
1052
+ * @returns {void}
1053
+ * @private
1054
+ */
1055
+ clearLoadPromise() {
1056
+ this.loadPromiseReject = undefined;
1057
+ this.loadPromiseResolve = undefined;
1058
+ }
1059
+ /**
1060
+ * Mark finish request
1061
+ *
1062
+ * @returns {void}
1063
+ * @private
1064
+ */
1065
+ finishRequest() {
1066
+ this.hasDataFinishEvent = true;
1067
+ // even if the finish request arrives but the data handling is still being throttled
1068
+ // we cannot resolve the loadAllPromiseResolve because there are still data chunks
1069
+ // in temp storage to be processed
1070
+ if (this.isDataHandlerThrottled) {
1071
+ return;
1072
+ }
1073
+ this.isWholeDataLoaded = true;
1074
+ if (this.loadAllPromiseResolve && typeof this.loadAllPromiseResolve === 'function') {
1075
+ this.loadAllPromiseResolve();
1076
+ this.clearLoadAllPromise();
1077
+ }
1078
+ }
1079
+ /**
1080
+ * Clear internal cache in case new JAQL request send
1081
+ *
1082
+ * @returns {void}
1083
+ * @private
1084
+ */
1085
+ clearCache() {
1086
+ this.rowsGrand = undefined;
1087
+ this.rowsTreeService = undefined;
1088
+ this.columnsTreeService = undefined;
1089
+ this.loadedPagesCount = 0;
1090
+ this.hasDataFinishEvent = false;
1091
+ this.isWholeDataLoaded = false;
1092
+ this.isLoadInProgress = false;
1093
+ this.tempDataChunks = [];
1094
+ this.lastNotHandledChunkIndex = 0;
1095
+ this.lastReadyNotHandledChunkIndex = 0;
1096
+ this.isDataHandlerThrottled = false;
1097
+ }
1098
+ static getEmptyPage() {
1099
+ return {
1100
+ isLastPage: true,
1101
+ };
1102
+ }
1103
+ static fillDataChunks(list, node, firstMaxSize = exports.NODES_CHUNK_SIZE_MAX, maxSize = exports.NODES_CHUNK_SIZE_MAX) {
1104
+ const isFirstChunk = list.length < 2;
1105
+ const maxChunkSize = isFirstChunk ? firstMaxSize : maxSize;
1106
+ let lastChunk = list[Math.max(0, list.length - 1)];
1107
+ let lastChunkNode;
1108
+ let createNewChunk = !lastChunk;
1109
+ if (!node ||
1110
+ (typeof node.children === 'undefined' &&
1111
+ typeof node.value === 'undefined' &&
1112
+ node.data &&
1113
+ !node.data.length)) {
1114
+ if (lastChunk) {
1115
+ lastChunk.ready = true;
1116
+ }
1117
+ return;
1118
+ }
1119
+ if (lastChunk) {
1120
+ const lastChunkNodeIndex = Math.max(0, lastChunk.list.length - 1);
1121
+ lastChunkNode = lastChunk.list[lastChunkNodeIndex];
1122
+ const lastChunkSizeStr = lastChunk.size ? `${lastChunk.size}` : '0';
1123
+ const lastChunkSize = parseInt(lastChunkSizeStr, 10);
1124
+ const afterLastChunkSize = lastChunkSize + (node.size || 1);
1125
+ if (lastChunk.handled ||
1126
+ (afterLastChunkSize > maxChunkSize &&
1127
+ !(lastChunkNode.isPart && lastChunkNode.value === node.value))) {
1128
+ createNewChunk = true;
1129
+ }
1130
+ }
1131
+ if (node &&
1132
+ node.isPart &&
1133
+ lastChunkNode &&
1134
+ (!lastChunkNode.isPart || lastChunkNode.value !== node.value)) {
1135
+ createNewChunk = true;
1136
+ if (lastChunkNode.value !== node.value) {
1137
+ lastChunkNode = undefined;
1138
+ }
1139
+ }
1140
+ if (createNewChunk) {
1141
+ if (lastChunk) {
1142
+ lastChunk.ready = true;
1143
+ }
1144
+ lastChunk = {
1145
+ list: [],
1146
+ size: 0,
1147
+ ready: false,
1148
+ handled: false,
1149
+ };
1150
+ list.push(lastChunk);
1151
+ }
1152
+ if (lastChunk) {
1153
+ if (lastChunkNode && lastChunkNode.isPart && node && node.isPart) {
1154
+ index_js_3.treeNode.deepMerge(lastChunkNode, node);
1155
+ lastChunk.size += node.size || 1;
1156
+ }
1157
+ else {
1158
+ lastChunk.list.push(node);
1159
+ lastChunk.size += node.size || 1;
1160
+ }
1161
+ }
1162
+ }
1163
+ static cloneTreeNode(obj, skipChildren) {
1164
+ // return cloneObject(obj);
1165
+ const node = obj;
1166
+ const { children, isMapped, // eslint-disable-line no-unused-vars
1167
+ minLevel, // eslint-disable-line no-unused-vars
1168
+ childCount, // eslint-disable-line no-unused-vars
1169
+ childDeep, // eslint-disable-line no-unused-vars
1170
+ // @ts-ignore
1171
+ parent,
1172
+ // @ts-ignore
1173
+ master,
1174
+ // @ts-ignore
1175
+ data,
1176
+ // @ts-ignore
1177
+ state,
1178
+ // @ts-ignore
1179
+ style,
1180
+ // @ts-ignore
1181
+ store } = node, restNode = __rest(node, ["children", "isMapped", "minLevel", "childCount", "childDeep", "parent", "master", "data", "state", "style", "store"]);
1182
+ const clone = (0, index_js_4.cloneObject)(restNode);
1183
+ if (parent) {
1184
+ clone.parent = parent;
1185
+ }
1186
+ if (master) {
1187
+ clone.master = master;
1188
+ }
1189
+ if (data) {
1190
+ clone.data = (0, index_js_4.cloneObject)(data);
1191
+ }
1192
+ if (state) {
1193
+ clone.state = (0, index_js_4.cloneObject)(state);
1194
+ }
1195
+ if (style) {
1196
+ clone.style = (0, index_js_4.cloneObject)(style);
1197
+ }
1198
+ if (store) {
1199
+ clone.store = (0, index_js_4.cloneObject)(store);
1200
+ }
1201
+ if (!skipChildren && children) {
1202
+ clone.children = children.map((ch) => {
1203
+ const clonedChild = DataService.cloneTreeNode(ch);
1204
+ // @ts-ignore
1205
+ clonedChild.parent = clone;
1206
+ return clonedChild;
1207
+ });
1208
+ }
1209
+ return clone;
1210
+ }
1211
+ /**
1212
+ * @typedef {Function} buildColumnsTreeService
1213
+ * @param {HeaderTreeNode} originalColumnsTree
1214
+ * @returns {BuildColumnsTreeServiceResult}
1215
+ */
1216
+ /**
1217
+ * @typedef {object} BuildColumnsTreeServiceResult
1218
+ * @property {TreeNode|undefined} columnsTree
1219
+ * @property {TreeService|undefined} columnsTreeService
1220
+ * @property {number} columnsCount
1221
+ * @property {number} totalColumnsCount
1222
+ */
1223
+ /**
1224
+ * Creates builder function for building columns tree service
1225
+ *
1226
+ * @param {object} handlers - build handlers
1227
+ * @param {Function} handlers.getJaql - jaql getter
1228
+ * @param {Function} [handlers.getRawJaql] - raw jaql getter
1229
+ * @param {PluginService} [handlers.pluginService] - plugin service
1230
+ * @param {Function} [handlers.applyIndexDivergence] - helper for calculation indexes divergence
1231
+ * @param {object} [events] - build event emitters
1232
+ * @param {Function} events.emitHeaderCellFormatEvent - emits EVENT_HEADER_CELL_FORMAT event
1233
+ * @returns {buildColumnsTreeService} - build function
1234
+ */
1235
+ static createColumnsTreeServiceBuilder(handlers, events) {
1236
+ return (originalColumnsTree) => {
1237
+ const jaql = handlers.getJaql();
1238
+ const rawJaql = handlers.getRawJaql
1239
+ ? handlers.getRawJaql()
1240
+ : getJaqlComposition(jaql, jaql.metadata || []);
1241
+ const valuesTree = index_js_5.jaqlProcessor.getMetadataTree(jaql, constants_js_2.PanelType.MEASURES);
1242
+ const valuesTreeChildren = index_js_3.treeNode.getChildren(valuesTree);
1243
+ const { preProcessTree, modifyTree, postProcessTree } = index_js_5.pivotTransforms;
1244
+ let columnsTree;
1245
+ let columnsTreeService;
1246
+ let columnsCount = 0;
1247
+ let totalColumnsCount = 0;
1248
+ if (index_js_3.treeNode.hasChildren(originalColumnsTree)) {
1249
+ if (originalColumnsTree.columnsCount && originalColumnsTree.totalColumnsCount) {
1250
+ columnsCount = originalColumnsTree.columnsCount;
1251
+ totalColumnsCount = originalColumnsTree.totalColumnsCount;
1252
+ }
1253
+ const columns = preProcessTree(originalColumnsTree, constants_js_2.PanelType.COLUMNS, jaql);
1254
+ const modifiedColumns = modifyTree(columns, constants_js_2.PanelType.COLUMNS, jaql, {
1255
+ originalData: originalColumnsTree,
1256
+ applyIndexDivergence: handlers.applyIndexDivergence,
1257
+ });
1258
+ postProcessTree(modifiedColumns, rawJaql, {
1259
+ emitFn: events && events.emitHeaderCellFormatEvent,
1260
+ });
1261
+ const wrappedModifiedColumns = index_js_3.treeNode.wrapInRootNode(modifiedColumns);
1262
+ if (handlers.pluginService && wrappedModifiedColumns && wrappedModifiedColumns.children) {
1263
+ handlers.pluginService.applyToColumns(wrappedModifiedColumns.children);
1264
+ }
1265
+ columnsTree = wrappedModifiedColumns;
1266
+ columnsTreeService = new index_js_2.TreeService(wrappedModifiedColumns);
1267
+ if (valuesTreeChildren.length === 1) {
1268
+ columnsTreeService.setValueNode(valuesTreeChildren[0]);
1269
+ }
1270
+ }
1271
+ else if (index_js_3.treeNode.hasChildren(valuesTree)) {
1272
+ if (originalColumnsTree.columnsCount && originalColumnsTree.totalColumnsCount) {
1273
+ columnsCount = originalColumnsTree.columnsCount;
1274
+ totalColumnsCount = originalColumnsTree.totalColumnsCount;
1275
+ }
1276
+ // columns limit
1277
+ if (typeof originalColumnsTree.maxChilds === 'number') {
1278
+ columnsCount = originalColumnsTree.maxChilds;
1279
+ valuesTree.children = index_js_3.treeNode
1280
+ .getChildren(valuesTree)
1281
+ .filter((item, index) => index < originalColumnsTree.maxChilds);
1282
+ }
1283
+ if (handlers.pluginService && valuesTree.children) {
1284
+ handlers.pluginService.applyToColumns(valuesTree.children);
1285
+ }
1286
+ postProcessTree(index_js_3.treeNode.getChildren(valuesTree), rawJaql, {
1287
+ emitFn: events && events.emitHeaderCellFormatEvent,
1288
+ });
1289
+ columnsTree = valuesTree;
1290
+ columnsTreeService = new index_js_2.TreeService(valuesTree);
1291
+ }
1292
+ else {
1293
+ if (handlers.pluginService) {
1294
+ handlers.pluginService.resetRowStartFrom();
1295
+ }
1296
+ columnsTree = undefined;
1297
+ columnsTreeService = undefined;
1298
+ columnsCount = 0;
1299
+ totalColumnsCount = 0;
1300
+ }
1301
+ return {
1302
+ columnsTree,
1303
+ columnsTreeService,
1304
+ columnsCount,
1305
+ totalColumnsCount,
1306
+ };
1307
+ };
1308
+ }
1309
+ /**
1310
+ * @typedef {Function} buildCornerTreeService
1311
+ * @param {HeaderTreeNode} originalColumnsTree
1312
+ * @returns {BuildCornerTreeServiceResult}
1313
+ */
1314
+ /**
1315
+ * @typedef {object} BuildCornerTreeServiceResult
1316
+ * @property {TreeNode|undefined} columnsTree
1317
+ * @property {TreeService|undefined} columnsTreeService
1318
+ * @property {number} columnsCount
1319
+ * @property {number} totalColumnsCount
1320
+ */
1321
+ /**
1322
+ * Creates builder function for building corners tree service
1323
+ *
1324
+ * @param {object} handlers - build handlers
1325
+ * @param {Function} handlers.getJaql - jaql getter
1326
+ * @param {Function} [handlers.getRawJaql] - raw jaql getter
1327
+ * @param {PluginService} [handlers.pluginService] - plugin service
1328
+ * @param {TreeServiceI} [handlers.columnsTreeService] - column tree service
1329
+ * @param {object} [events] - build event emitters
1330
+ * @param {Function} events.emitHeaderCellFormatEvent - emits EVENT_HEADER_CELL_FORMAT event
1331
+ * @returns {buildCornerTreeService} - build function
1332
+ */
1333
+ static createCornerTreeServiceBuilder(handlers, events) {
1334
+ return () => {
1335
+ const jaql = handlers.getJaql();
1336
+ const rawJaql = handlers.getRawJaql
1337
+ ? handlers.getRawJaql()
1338
+ : getJaqlComposition(jaql, jaql.metadata || []);
1339
+ const cornerTree = index_js_5.jaqlProcessor.getMetadataTree(jaql, constants_js_2.PanelType.ROWS);
1340
+ let cornerTreeService;
1341
+ if (index_js_3.treeNode.hasChildren(cornerTree)) {
1342
+ // add user type to tree node
1343
+ index_js_3.treeNode.iterateThroughTree(index_js_3.treeNode.getChildren(cornerTree), (item) => {
1344
+ item.userType = constants_js_2.UserType.CORNER;
1345
+ const panel = index_js_5.jaqlProcessor.getMetadataPanelByIndex(rawJaql, item.jaqlIndex, item.metadataType || '');
1346
+ if (events && events.emitHeaderCellFormatEvent) {
1347
+ events.emitHeaderCellFormatEvent(item, panel, rawJaql);
1348
+ }
1349
+ });
1350
+ let cornerDeep;
1351
+ if (handlers.columnsTreeService) {
1352
+ cornerDeep = handlers.columnsTreeService.getTreeDeepsLength();
1353
+ }
1354
+ if (handlers.pluginService) {
1355
+ handlers.pluginService.applyToHeaders(cornerTree);
1356
+ }
1357
+ cornerTreeService = new index_js_2.TreeService(cornerTree, false, cornerDeep);
1358
+ }
1359
+ return { cornerTree, cornerTreeService };
1360
+ };
1361
+ }
1362
+ }
1363
+ exports.DataService = DataService;
1364
+ exports.default = DataService;