@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.
- package/LICENSE.md +35 -0
- package/README.md +2 -0
- package/dist/__test-helpers__/testUtils.d.ts +30 -0
- package/dist/__test-helpers__/testUtils.js +89 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +2 -0
- package/dist/builders/pivot-data-builder.d.ts +34 -0
- package/dist/builders/pivot-data-builder.js +182 -0
- package/dist/builders/socket-builder.d.ts +18 -0
- package/dist/builders/socket-builder.js +72 -0
- package/dist/cjs/__test-helpers__/testUtils.d.ts +30 -0
- package/dist/cjs/__test-helpers__/testUtils.js +104 -0
- package/dist/cjs/builders/index.d.ts +2 -0
- package/dist/cjs/builders/index.js +7 -0
- package/dist/cjs/builders/pivot-data-builder.d.ts +34 -0
- package/dist/cjs/builders/pivot-data-builder.js +186 -0
- package/dist/cjs/builders/socket-builder.d.ts +18 -0
- package/dist/cjs/builders/socket-builder.js +79 -0
- package/dist/cjs/data-handling/DataService.d.ts +672 -0
- package/dist/cjs/data-handling/DataService.js +1364 -0
- package/dist/cjs/data-handling/DivergenceComparator.d.ts +7 -0
- package/dist/cjs/data-handling/DivergenceComparator.js +20 -0
- package/dist/cjs/data-handling/constants.d.ts +44 -0
- package/dist/cjs/data-handling/constants.js +43 -0
- package/dist/cjs/data-handling/index.d.ts +3 -0
- package/dist/cjs/data-handling/index.js +23 -0
- package/dist/cjs/data-handling/types.d.ts +104 -0
- package/dist/cjs/data-handling/types.js +2 -0
- package/dist/cjs/data-handling/utils/createPivotTreeNode.d.ts +13 -0
- package/dist/cjs/data-handling/utils/createPivotTreeNode.js +21 -0
- package/dist/cjs/data-handling/utils/index.d.ts +4 -0
- package/dist/cjs/data-handling/utils/index.js +14 -0
- package/dist/cjs/data-handling/utils/jaqlProcessor.d.ts +122 -0
- package/dist/cjs/data-handling/utils/jaqlProcessor.js +661 -0
- package/dist/cjs/data-handling/utils/pivotTransforms.d.ts +74 -0
- package/dist/cjs/data-handling/utils/pivotTransforms.js +373 -0
- package/dist/cjs/data-handling/utils/plugins/PluginService.d.ts +135 -0
- package/dist/cjs/data-handling/utils/plugins/PluginService.js +383 -0
- package/dist/cjs/data-handling/utils/plugins/getters.d.ts +23 -0
- package/dist/cjs/data-handling/utils/plugins/getters.js +70 -0
- package/dist/cjs/data-handling/utils/plugins/types.d.ts +75 -0
- package/dist/cjs/data-handling/utils/plugins/types.js +2 -0
- package/dist/cjs/data-handling/utils/plugins/validator.d.ts +13 -0
- package/dist/cjs/data-handling/utils/plugins/validator.js +169 -0
- package/dist/cjs/data-load/AbstractDataLoadService.d.ts +256 -0
- package/dist/cjs/data-load/AbstractDataLoadService.js +473 -0
- package/dist/cjs/data-load/DataLoadService.d.ts +63 -0
- package/dist/cjs/data-load/DataLoadService.js +152 -0
- package/dist/cjs/data-load/SisenseDataLoadService.d.ts +44 -0
- package/dist/cjs/data-load/SisenseDataLoadService.js +87 -0
- package/dist/cjs/data-load/TestDataLoadService.d.ts +27 -0
- package/dist/cjs/data-load/TestDataLoadService.js +76 -0
- package/dist/cjs/data-load/constants.d.ts +13 -0
- package/dist/cjs/data-load/constants.js +28 -0
- package/dist/cjs/data-load/index.d.ts +6 -0
- package/dist/cjs/data-load/index.js +14 -0
- package/dist/cjs/data-load/sockets/SisenseSocket.d.ts +81 -0
- package/dist/cjs/data-load/sockets/SisenseSocket.js +162 -0
- package/dist/cjs/data-load/sockets/TestSocket.d.ts +61 -0
- package/dist/cjs/data-load/sockets/TestSocket.js +90 -0
- package/dist/cjs/data-load/sockets/helpers.d.ts +4 -0
- package/dist/cjs/data-load/sockets/helpers.js +27 -0
- package/dist/cjs/data-load/sockets/index.d.ts +2 -0
- package/dist/cjs/data-load/sockets/index.js +8 -0
- package/dist/cjs/data-load/types.d.ts +90 -0
- package/dist/cjs/data-load/types.js +2 -0
- package/dist/cjs/errors/LoadingCanceledError.d.ts +7 -0
- package/dist/cjs/errors/LoadingCanceledError.js +24 -0
- package/dist/cjs/errors/index.d.ts +1 -0
- package/dist/cjs/errors/index.js +6 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/package.json +12 -0
- package/dist/cjs/pivot-query-client.d.ts +13 -0
- package/dist/cjs/pivot-query-client.js +26 -0
- package/dist/cjs/tree-structure/AbstractTreeService.d.ts +308 -0
- package/dist/cjs/tree-structure/AbstractTreeService.js +716 -0
- package/dist/cjs/tree-structure/HeaderTreeService.d.ts +180 -0
- package/dist/cjs/tree-structure/HeaderTreeService.js +280 -0
- package/dist/cjs/tree-structure/TreeCellMap.d.ts +104 -0
- package/dist/cjs/tree-structure/TreeCellMap.js +145 -0
- package/dist/cjs/tree-structure/TreeService.d.ts +8 -0
- package/dist/cjs/tree-structure/TreeService.js +12 -0
- package/dist/cjs/tree-structure/constants.d.ts +6 -0
- package/dist/cjs/tree-structure/constants.js +10 -0
- package/dist/cjs/tree-structure/index.d.ts +5 -0
- package/dist/cjs/tree-structure/index.js +10 -0
- package/dist/cjs/tree-structure/types.d.ts +93 -0
- package/dist/cjs/tree-structure/types.js +2 -0
- package/dist/cjs/tree-structure/utils/index.d.ts +1 -0
- package/dist/cjs/tree-structure/utils/index.js +9 -0
- package/dist/cjs/tree-structure/utils/treeNode.d.ts +147 -0
- package/dist/cjs/tree-structure/utils/treeNode.js +534 -0
- package/dist/cjs/utils/array.d.ts +13 -0
- package/dist/cjs/utils/array.js +25 -0
- package/dist/cjs/utils/cloneObject.d.ts +30 -0
- package/dist/cjs/utils/cloneObject.js +225 -0
- package/dist/cjs/utils/index.d.ts +3 -0
- package/dist/cjs/utils/index.js +9 -0
- package/dist/cjs/utils/throttle.d.ts +12 -0
- package/dist/cjs/utils/throttle.js +39 -0
- package/dist/cjs/utils/types.d.ts +12 -0
- package/dist/cjs/utils/types.js +2 -0
- package/dist/data-handling/DataService.d.ts +672 -0
- package/dist/data-handling/DataService.js +1357 -0
- package/dist/data-handling/DivergenceComparator.d.ts +7 -0
- package/dist/data-handling/DivergenceComparator.js +16 -0
- package/dist/data-handling/constants.d.ts +44 -0
- package/dist/data-handling/constants.js +40 -0
- package/dist/data-handling/index.d.ts +3 -0
- package/dist/data-handling/index.js +4 -0
- package/dist/data-handling/types.d.ts +104 -0
- package/dist/data-handling/types.js +1 -0
- package/dist/data-handling/utils/createPivotTreeNode.d.ts +13 -0
- package/dist/data-handling/utils/createPivotTreeNode.js +17 -0
- package/dist/data-handling/utils/index.d.ts +4 -0
- package/dist/data-handling/utils/index.js +4 -0
- package/dist/data-handling/utils/jaqlProcessor.d.ts +122 -0
- package/dist/data-handling/utils/jaqlProcessor.js +621 -0
- package/dist/data-handling/utils/pivotTransforms.d.ts +74 -0
- package/dist/data-handling/utils/pivotTransforms.js +335 -0
- package/dist/data-handling/utils/plugins/PluginService.d.ts +135 -0
- package/dist/data-handling/utils/plugins/PluginService.js +379 -0
- package/dist/data-handling/utils/plugins/getters.d.ts +23 -0
- package/dist/data-handling/utils/plugins/getters.js +65 -0
- package/dist/data-handling/utils/plugins/types.d.ts +75 -0
- package/dist/data-handling/utils/plugins/types.js +1 -0
- package/dist/data-handling/utils/plugins/validator.d.ts +13 -0
- package/dist/data-handling/utils/plugins/validator.js +165 -0
- package/dist/data-load/AbstractDataLoadService.d.ts +256 -0
- package/dist/data-load/AbstractDataLoadService.js +466 -0
- package/dist/data-load/DataLoadService.d.ts +63 -0
- package/dist/data-load/DataLoadService.js +148 -0
- package/dist/data-load/SisenseDataLoadService.d.ts +44 -0
- package/dist/data-load/SisenseDataLoadService.js +83 -0
- package/dist/data-load/TestDataLoadService.d.ts +27 -0
- package/dist/data-load/TestDataLoadService.js +69 -0
- package/dist/data-load/constants.d.ts +13 -0
- package/dist/data-load/constants.js +25 -0
- package/dist/data-load/index.d.ts +6 -0
- package/dist/data-load/index.js +6 -0
- package/dist/data-load/sockets/SisenseSocket.d.ts +81 -0
- package/dist/data-load/sockets/SisenseSocket.js +155 -0
- package/dist/data-load/sockets/TestSocket.d.ts +61 -0
- package/dist/data-load/sockets/TestSocket.js +83 -0
- package/dist/data-load/sockets/helpers.d.ts +4 -0
- package/dist/data-load/sockets/helpers.js +23 -0
- package/dist/data-load/sockets/index.d.ts +2 -0
- package/dist/data-load/sockets/index.js +3 -0
- package/dist/data-load/types.d.ts +90 -0
- package/dist/data-load/types.js +1 -0
- package/dist/errors/LoadingCanceledError.d.ts +7 -0
- package/dist/errors/LoadingCanceledError.js +20 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +9 -0
- package/dist/pivot-query-client.d.ts +13 -0
- package/dist/pivot-query-client.js +22 -0
- package/dist/tree-structure/AbstractTreeService.d.ts +308 -0
- package/dist/tree-structure/AbstractTreeService.js +712 -0
- package/dist/tree-structure/HeaderTreeService.d.ts +180 -0
- package/dist/tree-structure/HeaderTreeService.js +276 -0
- package/dist/tree-structure/TreeCellMap.d.ts +104 -0
- package/dist/tree-structure/TreeCellMap.js +141 -0
- package/dist/tree-structure/TreeService.d.ts +8 -0
- package/dist/tree-structure/TreeService.js +8 -0
- package/dist/tree-structure/constants.d.ts +6 -0
- package/dist/tree-structure/constants.js +7 -0
- package/dist/tree-structure/index.d.ts +5 -0
- package/dist/tree-structure/index.js +4 -0
- package/dist/tree-structure/types.d.ts +93 -0
- package/dist/tree-structure/types.js +1 -0
- package/dist/tree-structure/utils/index.d.ts +1 -0
- package/dist/tree-structure/utils/index.js +1 -0
- package/dist/tree-structure/utils/treeNode.d.ts +147 -0
- package/dist/tree-structure/utils/treeNode.js +515 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/utils/array.d.ts +13 -0
- package/dist/utils/array.js +21 -0
- package/dist/utils/cloneObject.d.ts +30 -0
- package/dist/utils/cloneObject.js +221 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/throttle.d.ts +12 -0
- package/dist/utils/throttle.js +35 -0
- package/dist/utils/types.d.ts +12 -0
- package/dist/utils/types.js +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCutNodesByChildCount = exports.clearNodeCache = exports.getNodesByChildCount = exports.getDeepLength = exports.getChildLength = exports.getLastLevelNodes = exports.iterateThroughTree = exports.deepMerge = exports.merge = exports.wrapInRootNode = exports.getLevel = exports.setLevel = exports.setChildren = exports.getChildren = exports.hasChildren = exports.create = exports.ROOT = void 0;
|
|
4
|
+
const index_js_1 = require("../../utils/index.js");
|
|
5
|
+
class ChunksList extends Array {
|
|
6
|
+
constructor(items) {
|
|
7
|
+
super(...items);
|
|
8
|
+
Object.setPrototypeOf(this, Object.create(ChunksList.prototype));
|
|
9
|
+
this.isHandled = false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ROOT = '$*$root$*$';
|
|
13
|
+
function create(value, children, data, index) {
|
|
14
|
+
const res = { value };
|
|
15
|
+
if (children) {
|
|
16
|
+
res.children = children;
|
|
17
|
+
}
|
|
18
|
+
if (data) {
|
|
19
|
+
res.data = data;
|
|
20
|
+
}
|
|
21
|
+
if (typeof index !== 'undefined') {
|
|
22
|
+
res.index = index;
|
|
23
|
+
}
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
exports.create = create;
|
|
27
|
+
/**
|
|
28
|
+
* Defines if node has child nodes or not
|
|
29
|
+
*
|
|
30
|
+
* @param {TreeNode} node - tree node object
|
|
31
|
+
* @returns {boolean} - true - has children, false - last child
|
|
32
|
+
*/
|
|
33
|
+
function hasChildren(node) {
|
|
34
|
+
return !!(node && node.children && node.children.length);
|
|
35
|
+
}
|
|
36
|
+
exports.hasChildren = hasChildren;
|
|
37
|
+
/**
|
|
38
|
+
* Returns list of child nodes
|
|
39
|
+
*
|
|
40
|
+
* @param {TreeNode} node - tree node object
|
|
41
|
+
* @returns {Array<TreeNode>|Array} - list of child nodes or empty array
|
|
42
|
+
*/
|
|
43
|
+
function getChildren(node) {
|
|
44
|
+
return (node && node.children) || [];
|
|
45
|
+
}
|
|
46
|
+
exports.getChildren = getChildren;
|
|
47
|
+
/**
|
|
48
|
+
* Set new list of child nodes
|
|
49
|
+
*
|
|
50
|
+
* @param {TreeNode} node - tree node object
|
|
51
|
+
* @param {Array<TreeNode>} list - new list of child nodes
|
|
52
|
+
* @returns {void}
|
|
53
|
+
*/
|
|
54
|
+
function setChildren(node, list) {
|
|
55
|
+
if (node && list && Array.isArray(list)) {
|
|
56
|
+
node.children = list;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.setChildren = setChildren;
|
|
60
|
+
/**
|
|
61
|
+
* Set node deep level in tree hierarchy
|
|
62
|
+
*
|
|
63
|
+
* @param {TreeNode} node - tree node object
|
|
64
|
+
* @param {number} level - hierarchy level
|
|
65
|
+
* @returns {void}
|
|
66
|
+
*/
|
|
67
|
+
function setLevel(node, level) {
|
|
68
|
+
if (node) {
|
|
69
|
+
node.level = level;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.setLevel = setLevel;
|
|
73
|
+
/**
|
|
74
|
+
* Returns node deep level in tree hierarchy
|
|
75
|
+
*
|
|
76
|
+
* @param {TreeNode} node - tree node object
|
|
77
|
+
* @returns {number} hierarchy level
|
|
78
|
+
*/
|
|
79
|
+
function getLevel(node) {
|
|
80
|
+
if (node && typeof node.level !== 'undefined') {
|
|
81
|
+
return node.level || 0;
|
|
82
|
+
}
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
exports.getLevel = getLevel;
|
|
86
|
+
function wrapInRootNode(data) {
|
|
87
|
+
if (!data) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (data && !Array.isArray(data) && data.value === exports.ROOT) {
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
const node = { value: exports.ROOT, children: [] };
|
|
94
|
+
if (Array.isArray(data)) {
|
|
95
|
+
node.children = data;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
(node.children || [])[0] = data;
|
|
99
|
+
}
|
|
100
|
+
return node;
|
|
101
|
+
}
|
|
102
|
+
exports.wrapInRootNode = wrapInRootNode;
|
|
103
|
+
function findNode(rootNode, checkCb, level = 0) {
|
|
104
|
+
let res;
|
|
105
|
+
if (!rootNode || !checkCb) {
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
if (checkCb(rootNode, level)) {
|
|
109
|
+
res = rootNode;
|
|
110
|
+
}
|
|
111
|
+
if (hasChildren(rootNode)) {
|
|
112
|
+
const children = getChildren(rootNode);
|
|
113
|
+
const childCount = children.length;
|
|
114
|
+
for (let i = 0; i < childCount; i += 1) {
|
|
115
|
+
const childRes = findNode(children[i], checkCb, level + 1);
|
|
116
|
+
if (childRes) {
|
|
117
|
+
res = childRes;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return res;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Merge two root trees into one
|
|
126
|
+
*
|
|
127
|
+
* @param {TreeNode} [firstNode] - first tree
|
|
128
|
+
* @param {TreeNode} [secondNode] - second tree
|
|
129
|
+
* @returns {TreeNode} - merged tree
|
|
130
|
+
*/
|
|
131
|
+
function merge(firstNode, secondNode) {
|
|
132
|
+
if (!firstNode && !secondNode) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
if (!firstNode && secondNode) {
|
|
136
|
+
return wrapInRootNode(secondNode);
|
|
137
|
+
}
|
|
138
|
+
if (firstNode && !secondNode) {
|
|
139
|
+
return wrapInRootNode(firstNode);
|
|
140
|
+
}
|
|
141
|
+
const firstRootNode = wrapInRootNode(firstNode);
|
|
142
|
+
const secondRootNode = wrapInRootNode(secondNode);
|
|
143
|
+
const firstChildrens = (firstRootNode && firstRootNode.children) || [];
|
|
144
|
+
const secondChildrens = (secondRootNode && secondRootNode.children) || [];
|
|
145
|
+
const children = firstChildrens.concat(secondChildrens);
|
|
146
|
+
return wrapInRootNode(children);
|
|
147
|
+
}
|
|
148
|
+
exports.merge = merge;
|
|
149
|
+
const findLastCut = (node, level = 0) => {
|
|
150
|
+
if (!node || !node.isPart) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
node.level = level;
|
|
154
|
+
const childs = getChildren(node);
|
|
155
|
+
const lastChild = childs[childs.length - 1];
|
|
156
|
+
if (!lastChild) {
|
|
157
|
+
return node;
|
|
158
|
+
}
|
|
159
|
+
const childCut = findLastCut(lastChild, level + 1);
|
|
160
|
+
return childCut || node;
|
|
161
|
+
};
|
|
162
|
+
const findFirstCut = (node, lastCut, level = 0) => {
|
|
163
|
+
if (!node || !node.isPart) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
node.level = level;
|
|
167
|
+
if (node && lastCut && node.value === lastCut.value && node.level === lastCut.level) {
|
|
168
|
+
return node;
|
|
169
|
+
}
|
|
170
|
+
const childs = getChildren(node);
|
|
171
|
+
const firstChild = childs[0];
|
|
172
|
+
if (!firstChild) {
|
|
173
|
+
return node;
|
|
174
|
+
}
|
|
175
|
+
const childCut = findFirstCut(firstChild, lastCut, level + 1);
|
|
176
|
+
return childCut || node;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Merging two partial pivot trees into one (mutate first argument).
|
|
180
|
+
*
|
|
181
|
+
* @param {TreeNode} targetTree - main part of pivot table model (looks like 'tree' data structure)
|
|
182
|
+
* @param {TreeNode} sourceTree - part of pivot table model (looks like 'tree' data structure) which
|
|
183
|
+
* we want merge in main part
|
|
184
|
+
* @returns {TreeNode} - merged tree
|
|
185
|
+
*/
|
|
186
|
+
function deepMerge(targetTree, sourceTree) {
|
|
187
|
+
/**
|
|
188
|
+
* The node to which we plan to add children
|
|
189
|
+
*
|
|
190
|
+
* @type {?TreeNode}
|
|
191
|
+
*/
|
|
192
|
+
let targetNode = findLastCut(targetTree);
|
|
193
|
+
/**
|
|
194
|
+
* The node from where we plan to copy the children
|
|
195
|
+
*
|
|
196
|
+
* @type {?TreeNode}
|
|
197
|
+
*/
|
|
198
|
+
let sourceNode = findFirstCut(sourceTree, targetNode);
|
|
199
|
+
// This long logical expression
|
|
200
|
+
// needed for the flow type checker
|
|
201
|
+
// to infer non nullable type
|
|
202
|
+
// of a nested `.children` property
|
|
203
|
+
// and I can't move it out to a function
|
|
204
|
+
if (targetNode &&
|
|
205
|
+
targetNode.children &&
|
|
206
|
+
Array.isArray(targetNode.children) &&
|
|
207
|
+
sourceNode &&
|
|
208
|
+
sourceNode.children &&
|
|
209
|
+
Array.isArray(sourceNode.children) &&
|
|
210
|
+
sourceNode.children.length > 0) {
|
|
211
|
+
targetNode.children = targetNode.children.concat(sourceNode.children);
|
|
212
|
+
sourceNode.isHandled = true;
|
|
213
|
+
}
|
|
214
|
+
let hasReachedFirstCutNode = false;
|
|
215
|
+
targetNode = targetTree;
|
|
216
|
+
sourceNode = sourceTree;
|
|
217
|
+
// This long logical expression
|
|
218
|
+
// needed for the flow type checker
|
|
219
|
+
// to infer non nullable type
|
|
220
|
+
// of a nested `.children` property
|
|
221
|
+
// and I can't move it out to a function
|
|
222
|
+
while (targetNode &&
|
|
223
|
+
targetNode.children &&
|
|
224
|
+
Array.isArray(targetNode.children) &&
|
|
225
|
+
sourceNode &&
|
|
226
|
+
sourceNode.children &&
|
|
227
|
+
Array.isArray(sourceNode.children) &&
|
|
228
|
+
!sourceNode.isHandled) {
|
|
229
|
+
const preservedTargetChildren = targetNode.children;
|
|
230
|
+
targetNode = targetNode.children[targetNode.children.length - 1];
|
|
231
|
+
let i = 0;
|
|
232
|
+
if (sourceNode.children[0] && !hasReachedFirstCutNode) {
|
|
233
|
+
hasReachedFirstCutNode = !getChildren(sourceNode.children[0]).some((obj) => obj.isPart);
|
|
234
|
+
i = 1;
|
|
235
|
+
}
|
|
236
|
+
while (i < sourceNode.children.length) {
|
|
237
|
+
preservedTargetChildren.push(sourceNode.children[i]);
|
|
238
|
+
i += 1;
|
|
239
|
+
}
|
|
240
|
+
// eslint-disable-next-line prefer-destructuring
|
|
241
|
+
sourceNode = sourceNode.children[0];
|
|
242
|
+
}
|
|
243
|
+
return targetTree;
|
|
244
|
+
}
|
|
245
|
+
exports.deepMerge = deepMerge;
|
|
246
|
+
function iterateThroughTree(nodes, callback, parent) {
|
|
247
|
+
if (!nodes || !callback) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
nodes.forEach((node) => {
|
|
251
|
+
callback(node, parent);
|
|
252
|
+
if (hasChildren(node)) {
|
|
253
|
+
iterateThroughTree(getChildren(node), callback, node);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
exports.iterateThroughTree = iterateThroughTree;
|
|
258
|
+
function getLastLevelNodes(nodes, lastLevelNodes = [], level = 0, options = { maxLevel: 0 }) {
|
|
259
|
+
nodes.forEach((item) => {
|
|
260
|
+
if (options.maxLevel < level) {
|
|
261
|
+
options.maxLevel = level;
|
|
262
|
+
}
|
|
263
|
+
if (hasChildren(item)) {
|
|
264
|
+
getLastLevelNodes(getChildren(item), lastLevelNodes, level + 1, options);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
lastLevelNodes.push(item);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return lastLevelNodes;
|
|
271
|
+
}
|
|
272
|
+
exports.getLastLevelNodes = getLastLevelNodes;
|
|
273
|
+
/**
|
|
274
|
+
* Returns number of last children for the tree
|
|
275
|
+
*
|
|
276
|
+
* @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
|
|
277
|
+
* @param {object} options - additional options
|
|
278
|
+
* @param {number} options.callCount - inner state for recursive calls count
|
|
279
|
+
* @param {boolean} options.clearCache - define if use cached value or recalculate new one
|
|
280
|
+
* @returns {number} - count of last children
|
|
281
|
+
*/
|
|
282
|
+
function getChildLength(item, options = {}) {
|
|
283
|
+
if (!options) {
|
|
284
|
+
// eslint-disable-next-line no-param-reassign
|
|
285
|
+
options = {};
|
|
286
|
+
}
|
|
287
|
+
if (typeof options.callCount !== 'number') {
|
|
288
|
+
options.callCount = 1;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
options.callCount += 1;
|
|
292
|
+
}
|
|
293
|
+
if (!item) {
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
let clearCache = options.clearCache || false;
|
|
297
|
+
if (!Array.isArray(item) && item.value === exports.ROOT) {
|
|
298
|
+
// do not use cache from 'root' node
|
|
299
|
+
clearCache = true;
|
|
300
|
+
}
|
|
301
|
+
let count = 1;
|
|
302
|
+
let children = [];
|
|
303
|
+
if (Array.isArray(item)) {
|
|
304
|
+
count = 0;
|
|
305
|
+
children = item;
|
|
306
|
+
}
|
|
307
|
+
else if (item.children) {
|
|
308
|
+
children = getChildren(item);
|
|
309
|
+
}
|
|
310
|
+
if (children && children.length) {
|
|
311
|
+
if (!clearCache && !Array.isArray(item) && typeof item.childCount === 'number') {
|
|
312
|
+
// get cached value
|
|
313
|
+
count = item.childCount;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
count = 0;
|
|
317
|
+
// recalculate new value
|
|
318
|
+
children.forEach((child) => {
|
|
319
|
+
count += getChildLength(child, options);
|
|
320
|
+
});
|
|
321
|
+
if (!Array.isArray(item)) {
|
|
322
|
+
// cache value
|
|
323
|
+
item.childCount = count;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return count;
|
|
328
|
+
}
|
|
329
|
+
exports.getChildLength = getChildLength;
|
|
330
|
+
/**
|
|
331
|
+
* Returns deep level of the tree
|
|
332
|
+
*
|
|
333
|
+
* @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
|
|
334
|
+
* @param {object} options - additional options
|
|
335
|
+
* @param {number} options.callCount - inner state for recursive calls count
|
|
336
|
+
* @param {boolean} options.clearCache - define if use cached value or recalculate new one
|
|
337
|
+
* @returns {number} - count of last children
|
|
338
|
+
*/
|
|
339
|
+
function getDeepLength(item, options = {}) {
|
|
340
|
+
if (!options) {
|
|
341
|
+
// eslint-disable-next-line no-param-reassign
|
|
342
|
+
options = {};
|
|
343
|
+
}
|
|
344
|
+
if (typeof options.callCount !== 'number') {
|
|
345
|
+
options.callCount = 1;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
options.callCount += 1;
|
|
349
|
+
}
|
|
350
|
+
if (!item) {
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
let clearCache = options.clearCache || false;
|
|
354
|
+
if (!Array.isArray(item) && item.value === exports.ROOT) {
|
|
355
|
+
// do not use cache from 'root' node
|
|
356
|
+
clearCache = true;
|
|
357
|
+
}
|
|
358
|
+
let count = 0;
|
|
359
|
+
let children = [];
|
|
360
|
+
if (item && !Array.isArray(item) && typeof item.value !== 'undefined') {
|
|
361
|
+
count = 1;
|
|
362
|
+
}
|
|
363
|
+
if (Array.isArray(item)) {
|
|
364
|
+
count = 0;
|
|
365
|
+
children = item;
|
|
366
|
+
}
|
|
367
|
+
else if (item.children) {
|
|
368
|
+
children = getChildren(item);
|
|
369
|
+
}
|
|
370
|
+
if (children && children.length) {
|
|
371
|
+
if (!clearCache && !Array.isArray(item) && typeof item.childDeep === 'number') {
|
|
372
|
+
// get cached value
|
|
373
|
+
count += item.childDeep;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
let maxCount = 0;
|
|
377
|
+
children.forEach((child) => {
|
|
378
|
+
const childCount = getDeepLength(child, options);
|
|
379
|
+
if (childCount > maxCount) {
|
|
380
|
+
maxCount = childCount;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
count += maxCount;
|
|
384
|
+
if (!Array.isArray(item)) {
|
|
385
|
+
// cache value
|
|
386
|
+
item.childDeep = maxCount;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return count;
|
|
391
|
+
}
|
|
392
|
+
exports.getDeepLength = getDeepLength;
|
|
393
|
+
/**
|
|
394
|
+
* Returns part of tree nodes list according to children indexes "from" - "to"
|
|
395
|
+
* return result is not strict, and start/stop in returns object show returned node position
|
|
396
|
+
*
|
|
397
|
+
* @param {Array<TreeNode>} rootNodes - list of nodes
|
|
398
|
+
* @param {number} [from=0] - start index to for partial tree
|
|
399
|
+
* @param {number} [to] - end index for partial tree
|
|
400
|
+
* @returns {{nodes: Array<TreeNode>, start: number, stop: number}} - partial tree nodes and
|
|
401
|
+
* start/stop indexes of it in scope of initial list
|
|
402
|
+
*/
|
|
403
|
+
function getNodesByChildCount(rootNodes = [], from = 0, to) {
|
|
404
|
+
const nodes = [];
|
|
405
|
+
let index = 0;
|
|
406
|
+
let startIndex = -1;
|
|
407
|
+
let stopIndex = -1;
|
|
408
|
+
const count = rootNodes.length;
|
|
409
|
+
if (typeof from === 'number' && typeof to === 'number' && from > to) {
|
|
410
|
+
throw new Error('Wrong "getNodesByChildCount" diapason');
|
|
411
|
+
}
|
|
412
|
+
if (typeof from === 'number' && from < 0) {
|
|
413
|
+
throw new Error('Wrong "from" index for "getNodesByChildCount"');
|
|
414
|
+
}
|
|
415
|
+
for (let i = 0; i < count; i += 1) {
|
|
416
|
+
const rootNode = rootNodes[i];
|
|
417
|
+
const childCount = getChildLength(rootNode);
|
|
418
|
+
// start index
|
|
419
|
+
if (index + childCount > from) {
|
|
420
|
+
if (startIndex < 0) {
|
|
421
|
+
startIndex = index;
|
|
422
|
+
}
|
|
423
|
+
nodes.push(rootNode);
|
|
424
|
+
// stop index
|
|
425
|
+
if (typeof to === 'number' && index + childCount >= to) {
|
|
426
|
+
stopIndex = index + childCount;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
stopIndex = index + childCount;
|
|
431
|
+
index += childCount;
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
nodes,
|
|
435
|
+
start: startIndex,
|
|
436
|
+
stop: stopIndex,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
exports.getNodesByChildCount = getNodesByChildCount;
|
|
440
|
+
/**
|
|
441
|
+
* Clear tree node internal cache
|
|
442
|
+
*
|
|
443
|
+
* @param {TreeNode} node - node to clear
|
|
444
|
+
* @returns {void}
|
|
445
|
+
*/
|
|
446
|
+
function clearNodeCache(node) {
|
|
447
|
+
if (node.isMapped !== undefined) {
|
|
448
|
+
node.isMapped = undefined;
|
|
449
|
+
}
|
|
450
|
+
if (node.minLevel !== undefined) {
|
|
451
|
+
node.minLevel = undefined;
|
|
452
|
+
}
|
|
453
|
+
if (node.childCount !== undefined) {
|
|
454
|
+
node.childCount = undefined;
|
|
455
|
+
}
|
|
456
|
+
if (node.childDeep !== undefined) {
|
|
457
|
+
node.childDeep = undefined;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
exports.clearNodeCache = clearNodeCache;
|
|
461
|
+
/**
|
|
462
|
+
* Returns cut cloned part of tree nodes list according to children indexes "from" - "to"
|
|
463
|
+
*
|
|
464
|
+
* @param {Array<TreeNode>} rootNodes - list of nodes
|
|
465
|
+
* @param {number} [from=0] - start index to for cut tree
|
|
466
|
+
* @param {number} [to] - end index for cut tree
|
|
467
|
+
* @param {object} [options] - additional options
|
|
468
|
+
* @param {Array<string>} [options.cloneIncludeKeys] - clone node include keys
|
|
469
|
+
* @param {Array<string>} [options.cloneExcludeKeys] - clone node exclude keys
|
|
470
|
+
* @returns {Array<TreeNode>} - cut cloned list of nodes
|
|
471
|
+
*/
|
|
472
|
+
function getCutNodesByChildCount(rootNodes = [], from = 0, to, options) {
|
|
473
|
+
const { cloneFn = index_js_1.cloneObject } = options || {};
|
|
474
|
+
const result = [];
|
|
475
|
+
const { nodes, start, stop } = getNodesByChildCount(rootNodes, from, to);
|
|
476
|
+
const count = nodes.length;
|
|
477
|
+
let firstItem;
|
|
478
|
+
let lastItem;
|
|
479
|
+
let handleLast = true;
|
|
480
|
+
if (start < from) {
|
|
481
|
+
const firstOriginalItem = nodes[0] || {};
|
|
482
|
+
const newFrom = from - start;
|
|
483
|
+
let newTo;
|
|
484
|
+
if (count === 1 && typeof to === 'number') {
|
|
485
|
+
newTo = to - start;
|
|
486
|
+
handleLast = false;
|
|
487
|
+
}
|
|
488
|
+
firstItem = cloneFn(firstOriginalItem, true);
|
|
489
|
+
const firstItemChilds = getCutNodesByChildCount(getChildren(firstOriginalItem), newFrom, newTo, options);
|
|
490
|
+
setChildren(firstItem, firstItemChilds);
|
|
491
|
+
}
|
|
492
|
+
if (typeof to === 'number' && stop > to && handleLast) {
|
|
493
|
+
const lastOriginalItem = nodes[count - 1] || {};
|
|
494
|
+
const newFrom = 0;
|
|
495
|
+
const newTo = getChildLength(lastOriginalItem) - (stop - to);
|
|
496
|
+
lastItem = cloneFn(lastOriginalItem, true);
|
|
497
|
+
const lastItemChilds = getCutNodesByChildCount(getChildren(lastOriginalItem), newFrom, newTo, options);
|
|
498
|
+
setChildren(lastItem, lastItemChilds);
|
|
499
|
+
}
|
|
500
|
+
nodes.forEach((node, index) => {
|
|
501
|
+
if (firstItem && index === 0) {
|
|
502
|
+
result.push(firstItem);
|
|
503
|
+
}
|
|
504
|
+
else if (lastItem && index === count - 1) {
|
|
505
|
+
result.push(lastItem);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
const clonedNode = cloneFn(node);
|
|
509
|
+
result.push(clonedNode);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
return result;
|
|
513
|
+
}
|
|
514
|
+
exports.getCutNodesByChildCount = getCutNodesByChildCount;
|
|
515
|
+
exports.default = {
|
|
516
|
+
ROOT: exports.ROOT,
|
|
517
|
+
create,
|
|
518
|
+
hasChildren,
|
|
519
|
+
getChildren,
|
|
520
|
+
setChildren,
|
|
521
|
+
setLevel,
|
|
522
|
+
getLevel,
|
|
523
|
+
getLastLevelNodes,
|
|
524
|
+
iterateThroughTree,
|
|
525
|
+
wrapInRootNode,
|
|
526
|
+
findNode,
|
|
527
|
+
merge,
|
|
528
|
+
deepMerge,
|
|
529
|
+
getChildLength,
|
|
530
|
+
getDeepLength,
|
|
531
|
+
getNodesByChildCount,
|
|
532
|
+
getCutNodesByChildCount,
|
|
533
|
+
clearNodeCache,
|
|
534
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for finding first element index from array that meets check condition
|
|
3
|
+
*
|
|
4
|
+
* @param {Array<any>} arr - target array
|
|
5
|
+
* @param {Function} check - check function
|
|
6
|
+
* @param {number} [startFrom=0] - index from which to start search
|
|
7
|
+
* @returns {number} - found element index
|
|
8
|
+
*/
|
|
9
|
+
export declare function findIndex(arr: Array<any>, check: Function, startFrom?: number): number;
|
|
10
|
+
declare const _default: {
|
|
11
|
+
findIndex: typeof findIndex;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findIndex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helper for finding first element index from array that meets check condition
|
|
6
|
+
*
|
|
7
|
+
* @param {Array<any>} arr - target array
|
|
8
|
+
* @param {Function} check - check function
|
|
9
|
+
* @param {number} [startFrom=0] - index from which to start search
|
|
10
|
+
* @returns {number} - found element index
|
|
11
|
+
*/
|
|
12
|
+
function findIndex(arr, check, startFrom = 0) {
|
|
13
|
+
for (let i = startFrom; i < arr.length; i += 1) {
|
|
14
|
+
const value = arr[i];
|
|
15
|
+
const isFound = !!check(value, i, arr);
|
|
16
|
+
if (isFound) {
|
|
17
|
+
return i;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return -1;
|
|
21
|
+
}
|
|
22
|
+
exports.findIndex = findIndex;
|
|
23
|
+
exports.default = {
|
|
24
|
+
findIndex,
|
|
25
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes deep clone of the object with ability exclude some properties or include only specific ones
|
|
3
|
+
* (includeKeys && excludeKeys) - simple key name comparison
|
|
4
|
+
* (include && exclude) - with parent hierarchy support, example:
|
|
5
|
+
* 'property1.deep_property2.deep_property3'
|
|
6
|
+
* or for array:
|
|
7
|
+
* 'arrayProperty.0' and 'arrayProperty.$.deep_property'
|
|
8
|
+
*
|
|
9
|
+
* @param {any} obj - object to clone
|
|
10
|
+
* @param {object} [options] - additional behaviour options
|
|
11
|
+
* @param {Array<string>} [options.include] - list of include properties keys
|
|
12
|
+
* @param {Array<string>} [options.includeKeys] - list of include properties keys
|
|
13
|
+
* @param {Array<string>} [options.exclude] - list of exclude properties keys
|
|
14
|
+
* @param {Array<string>} [options.excludeKeys] - list of exclude properties keys
|
|
15
|
+
* @param {boolean} [options.excludeEmpty] - defines if empty objects should be copied or not
|
|
16
|
+
* @param {Array<any>} [options.referenceClone] - defines types which clone by reference
|
|
17
|
+
* @returns {any} - cloned object
|
|
18
|
+
*/
|
|
19
|
+
export declare function cloneObject(obj: any, options?: {
|
|
20
|
+
include?: Array<string> | undefined;
|
|
21
|
+
includeKeys?: Array<string> | undefined;
|
|
22
|
+
exclude?: Array<string> | undefined;
|
|
23
|
+
excludeKeys?: Array<string> | undefined;
|
|
24
|
+
excludeEmpty?: boolean;
|
|
25
|
+
referenceClone?: Array<any>;
|
|
26
|
+
}): any;
|
|
27
|
+
export declare namespace cloneObject {
|
|
28
|
+
var REFERENCE_CLONE_TYPES: (ErrorConstructor | DateConstructor | RegExpConstructor | PromiseConstructor)[];
|
|
29
|
+
}
|
|
30
|
+
export default cloneObject;
|