@webex/plugin-meetings 3.8.1-web-workers-keepalive.1 → 3.9.0-webinar5k.1
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/dist/breakouts/breakout.js +1 -1
- package/dist/breakouts/index.js +1 -1
- package/dist/constants.js +8 -2
- package/dist/constants.js.map +1 -1
- package/dist/hashTree/constants.js +23 -0
- package/dist/hashTree/constants.js.map +1 -0
- package/dist/hashTree/hashTree.js +516 -0
- package/dist/hashTree/hashTree.js.map +1 -0
- package/dist/hashTree/hashTreeParser.js +521 -0
- package/dist/hashTree/hashTreeParser.js.map +1 -0
- package/dist/interpretation/index.js +1 -1
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/locus-info/index.js +301 -59
- package/dist/locus-info/index.js.map +1 -1
- package/dist/meeting/brbState.js +14 -12
- package/dist/meeting/brbState.js.map +1 -1
- package/dist/meeting/index.js +110 -12
- package/dist/meeting/index.js.map +1 -1
- package/dist/meeting/muteState.js +2 -5
- package/dist/meeting/muteState.js.map +1 -1
- package/dist/meeting/request.js +19 -0
- package/dist/meeting/request.js.map +1 -1
- package/dist/meeting/request.type.js.map +1 -1
- package/dist/meeting/util.js +8 -11
- package/dist/meeting/util.js.map +1 -1
- package/dist/meetings/index.js +6 -2
- package/dist/meetings/index.js.map +1 -1
- package/dist/member/index.js.map +1 -1
- package/dist/member/types.js.map +1 -1
- package/dist/members/collection.js +13 -0
- package/dist/members/collection.js.map +1 -1
- package/dist/members/index.js +44 -23
- package/dist/members/index.js.map +1 -1
- package/dist/members/request.js +3 -3
- package/dist/members/request.js.map +1 -1
- package/dist/members/util.js +18 -6
- package/dist/members/util.js.map +1 -1
- package/dist/multistream/sendSlotManager.js +32 -2
- package/dist/multistream/sendSlotManager.js.map +1 -1
- package/dist/types/constants.d.ts +6 -0
- package/dist/types/hashTree/constants.d.ts +8 -0
- package/dist/types/hashTree/hashTree.d.ts +128 -0
- package/dist/types/hashTree/hashTreeParser.d.ts +152 -0
- package/dist/types/locus-info/index.d.ts +93 -3
- package/dist/types/meeting/brbState.d.ts +0 -1
- package/dist/types/meeting/index.d.ts +29 -3
- package/dist/types/meeting/request.d.ts +9 -1
- package/dist/types/meeting/request.type.d.ts +74 -0
- package/dist/types/meeting/util.d.ts +3 -3
- package/dist/types/member/types.d.ts +1 -0
- package/dist/types/members/collection.d.ts +6 -0
- package/dist/types/members/index.d.ts +15 -3
- package/dist/types/members/request.d.ts +1 -1
- package/dist/types/members/util.d.ts +5 -2
- package/dist/types/multistream/sendSlotManager.d.ts +16 -0
- package/dist/webinar/index.js +1 -1
- package/package.json +24 -23
- package/src/constants.ts +7 -0
- package/src/hashTree/constants.ts +12 -0
- package/src/hashTree/hashTree.ts +460 -0
- package/src/hashTree/hashTreeParser.ts +556 -0
- package/src/locus-info/index.ts +393 -58
- package/src/meeting/brbState.ts +9 -7
- package/src/meeting/index.ts +104 -6
- package/src/meeting/muteState.ts +2 -6
- package/src/meeting/request.ts +16 -0
- package/src/meeting/request.type.ts +64 -0
- package/src/meeting/util.ts +17 -20
- package/src/meetings/index.ts +17 -3
- package/src/member/index.ts +1 -0
- package/src/member/types.ts +1 -0
- package/src/members/collection.ts +11 -0
- package/src/members/index.ts +33 -7
- package/src/members/request.ts +2 -2
- package/src/members/util.ts +14 -3
- package/src/multistream/sendSlotManager.ts +34 -2
- package/test/unit/spec/hashTree/hashTree.ts +394 -0
- package/test/unit/spec/hashTree/hashTreeParser.ts +156 -0
- package/test/unit/spec/locus-info/index.js +506 -55
- package/test/unit/spec/meeting/brbState.ts +9 -9
- package/test/unit/spec/meeting/index.js +475 -42
- package/test/unit/spec/meeting/request.js +71 -0
- package/test/unit/spec/members/index.js +33 -10
- package/test/unit/spec/members/request.js +2 -2
- package/test/unit/spec/members/utils.js +27 -7
- package/test/unit/spec/multistream/sendSlotManager.ts +59 -0
- package/test/unit/spec/reachability/index.ts +3 -1
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.EMPTY_HASH = exports.DataSetNames = void 0;
|
8
|
+
// TODO: Consider moving these to the main meetings constants file at some point
|
9
|
+
// Only worth doing so if they are used outside of the hash tree
|
10
|
+
|
11
|
+
var EMPTY_HASH = exports.EMPTY_HASH = '99aa06d3014798d86001c324468d497f';
|
12
|
+
var DataSetNames = exports.DataSetNames = {
|
13
|
+
MAIN: 'main',
|
14
|
+
// sent to web client, contains also panelists, over LLM
|
15
|
+
ATTENDEES: 'attendees',
|
16
|
+
// NOT SENT to web client, all the attendees in the locus
|
17
|
+
ATD_ACTIVE: 'atd-active',
|
18
|
+
// only sent to panelists, over LLM; the attendees that have their hands raised or are allowed to unmute themselves
|
19
|
+
ATD_UNMUTED: 'atd-unmuted',
|
20
|
+
// sent to web client, over LLM, not sent to panelists; the attendees that are unmuted
|
21
|
+
SELF: 'self' // sent to web client, over Mercury
|
22
|
+
};
|
23
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EMPTY_HASH","exports","DataSetNames","MAIN","ATTENDEES","ATD_ACTIVE","ATD_UNMUTED","SELF"],"sources":["constants.ts"],"sourcesContent":["// TODO: Consider moving these to the main meetings constants file at some point\n// Only worth doing so if they are used outside of the hash tree\n\nexport const EMPTY_HASH = '99aa06d3014798d86001c324468d497f';\n\nexport const DataSetNames = {\n MAIN: 'main', // sent to web client, contains also panelists, over LLM\n ATTENDEES: 'attendees', // NOT SENT to web client, all the attendees in the locus\n ATD_ACTIVE: 'atd-active', // only sent to panelists, over LLM; the attendees that have their hands raised or are allowed to unmute themselves\n ATD_UNMUTED: 'atd-unmuted', // sent to web client, over LLM, not sent to panelists; the attendees that are unmuted\n SELF: 'self', // sent to web client, over Mercury\n};\n"],"mappings":";;;;;;;AAAA;AACA;;AAEO,IAAMA,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,kCAAkC;AAErD,IAAME,YAAY,GAAAD,OAAA,CAAAC,YAAA,GAAG;EAC1BC,IAAI,EAAE,MAAM;EAAE;EACdC,SAAS,EAAE,WAAW;EAAE;EACxBC,UAAU,EAAE,YAAY;EAAE;EAC1BC,WAAW,EAAE,aAAa;EAAE;EAC5BC,IAAI,EAAE,MAAM,CAAE;AAChB,CAAC"}
|
@@ -0,0 +1,516 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Array$from = require("@babel/runtime-corejs2/core-js/array/from");
|
4
|
+
var _Symbol = require("@babel/runtime-corejs2/core-js/symbol");
|
5
|
+
var _Symbol$iterator = require("@babel/runtime-corejs2/core-js/symbol/iterator");
|
6
|
+
var _Array$isArray = require("@babel/runtime-corejs2/core-js/array/is-array");
|
7
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
8
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
9
|
+
_Object$defineProperty(exports, "__esModule", {
|
10
|
+
value: true
|
11
|
+
});
|
12
|
+
exports.default = void 0;
|
13
|
+
var _set = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/set"));
|
14
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
15
|
+
var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
|
17
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
20
|
+
var _xxh3Ts = require("xxh3-ts");
|
21
|
+
var _constants = require("./constants");
|
22
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && o[_Symbol$iterator] || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
23
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
24
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
25
|
+
/**
|
26
|
+
* HashTree is a data structure that organizes items into leaves based on their IDs,
|
27
|
+
*/
|
28
|
+
var HashTree = /*#__PURE__*/function () {
|
29
|
+
/**
|
30
|
+
* Constructs a new HashTree.
|
31
|
+
* @param {LeafDataItem[]} leafData Initial data to populate the tree.
|
32
|
+
* @param {number} numLeaves The number of leaf nodes in the tree. Must be 0 or a power of 2.
|
33
|
+
* @throws {Error} If numLeaves is not 0 or a power of 2.
|
34
|
+
*/
|
35
|
+
function HashTree(leafData, numLeaves) {
|
36
|
+
(0, _classCallCheck2.default)(this, HashTree);
|
37
|
+
(0, _defineProperty2.default)(this, "leaves", void 0);
|
38
|
+
(0, _defineProperty2.default)(this, "leafHashes", void 0);
|
39
|
+
(0, _defineProperty2.default)(this, "numLeaves", void 0);
|
40
|
+
// eslint-disable-next-line no-bitwise
|
41
|
+
if ((numLeaves & numLeaves - 1) !== 0) {
|
42
|
+
throw new Error("Number of leaves must be a power of 2, saw ".concat(numLeaves));
|
43
|
+
}
|
44
|
+
this.numLeaves = numLeaves;
|
45
|
+
this.leafHashes = new Array(numLeaves).fill(_constants.EMPTY_HASH);
|
46
|
+
this.leaves = new Array(numLeaves).fill(null).map(function () {
|
47
|
+
return {};
|
48
|
+
});
|
49
|
+
if (leafData) {
|
50
|
+
this.putItems(leafData);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Internal logic for adding or updating an item, without computing the leaf hash.
|
56
|
+
* @param {LeafDataItem} item The item to add or update.
|
57
|
+
* @returns {{put: boolean, index: (number|null)}} Object indicating if put and the leaf index.
|
58
|
+
* @private
|
59
|
+
*/
|
60
|
+
(0, _createClass2.default)(HashTree, [{
|
61
|
+
key: "_putItemInternal",
|
62
|
+
value: function _putItemInternal(item) {
|
63
|
+
if (this.numLeaves === 0) {
|
64
|
+
return {
|
65
|
+
put: false,
|
66
|
+
index: null
|
67
|
+
}; // Cannot add to a tree with 0 leaves
|
68
|
+
}
|
69
|
+
|
70
|
+
var index = item.id % this.numLeaves;
|
71
|
+
if (!this.leaves[index][item.type]) {
|
72
|
+
this.leaves[index][item.type] = {};
|
73
|
+
}
|
74
|
+
var existingItem = this.leaves[index][item.type][item.id];
|
75
|
+
if (!existingItem || existingItem.version < item.version) {
|
76
|
+
this.leaves[index][item.type][item.id] = item;
|
77
|
+
return {
|
78
|
+
put: true,
|
79
|
+
index: index
|
80
|
+
};
|
81
|
+
}
|
82
|
+
return {
|
83
|
+
put: false,
|
84
|
+
index: null
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Adds or updates a single item in the hash tree.
|
90
|
+
* @param {LeafDataItem} item The item to add or update.
|
91
|
+
* @returns {boolean} True if the item was added or updated, false otherwise (e.g., older version or tree has 0 leaves).
|
92
|
+
*/
|
93
|
+
}, {
|
94
|
+
key: "putItem",
|
95
|
+
value: function putItem(item) {
|
96
|
+
var _this$_putItemInterna = this._putItemInternal(item),
|
97
|
+
put = _this$_putItemInterna.put,
|
98
|
+
index = _this$_putItemInterna.index;
|
99
|
+
if (put && index !== null) {
|
100
|
+
this.computeLeafHash(index);
|
101
|
+
}
|
102
|
+
return put;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Adds or updates multiple items in the hash tree.
|
107
|
+
* @param {LeafDataItem[]} items The array of items to add or update.
|
108
|
+
* @returns {boolean[]} An array of booleans indicating success for each item.
|
109
|
+
*/
|
110
|
+
}, {
|
111
|
+
key: "putItems",
|
112
|
+
value: function putItems(items) {
|
113
|
+
var _this = this;
|
114
|
+
if (this.numLeaves === 0 && items.length > 0) {
|
115
|
+
// Cannot add items to a tree with 0 leaves.
|
116
|
+
return items.map(function () {
|
117
|
+
return false;
|
118
|
+
});
|
119
|
+
}
|
120
|
+
var results = [];
|
121
|
+
var changedLeafIndexes = new _set.default();
|
122
|
+
items.forEach(function (item) {
|
123
|
+
var _this$_putItemInterna2 = _this._putItemInternal(item),
|
124
|
+
put = _this$_putItemInterna2.put,
|
125
|
+
index = _this$_putItemInterna2.index;
|
126
|
+
results.push(put);
|
127
|
+
if (put && index !== null) {
|
128
|
+
changedLeafIndexes.add(index);
|
129
|
+
}
|
130
|
+
});
|
131
|
+
changedLeafIndexes.forEach(function (index) {
|
132
|
+
_this.computeLeafHash(index);
|
133
|
+
});
|
134
|
+
return results;
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Internal logic for removing an item, without computing the leaf hash.
|
139
|
+
* @param {LeafDataItem} item The item to remove.
|
140
|
+
* @returns {{removed: boolean, index: (number|null)}} Object indicating if removed and the leaf index.
|
141
|
+
* @private
|
142
|
+
*/
|
143
|
+
}, {
|
144
|
+
key: "_removeItemInternal",
|
145
|
+
value: function _removeItemInternal(item) {
|
146
|
+
if (this.numLeaves === 0) {
|
147
|
+
return {
|
148
|
+
removed: false,
|
149
|
+
index: null
|
150
|
+
};
|
151
|
+
}
|
152
|
+
var index = item.id % this.numLeaves;
|
153
|
+
if (this.leaves[index] && this.leaves[index][item.type] && this.leaves[index][item.type][item.id]) {
|
154
|
+
var existingItem = this.leaves[index][item.type][item.id];
|
155
|
+
if (existingItem.id === item.id && existingItem.type === item.type && existingItem.version <= item.version) {
|
156
|
+
delete this.leaves[index][item.type][item.id];
|
157
|
+
if ((0, _keys.default)(this.leaves[index][item.type]).length === 0) {
|
158
|
+
delete this.leaves[index][item.type];
|
159
|
+
}
|
160
|
+
return {
|
161
|
+
removed: true,
|
162
|
+
index: index
|
163
|
+
};
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return {
|
167
|
+
removed: false,
|
168
|
+
index: null
|
169
|
+
};
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Removes a single item from the hash tree.
|
174
|
+
* The removal is based on matching type, id, and the provided item's version
|
175
|
+
* being greater than or equal to the existing item's version.
|
176
|
+
* @param {LeafDataItem} item The item to remove.
|
177
|
+
* @returns {boolean} True if the item was removed, false otherwise.
|
178
|
+
*/
|
179
|
+
}, {
|
180
|
+
key: "removeItem",
|
181
|
+
value: function removeItem(item) {
|
182
|
+
var _this$_removeItemInte = this._removeItemInternal(item),
|
183
|
+
removed = _this$_removeItemInte.removed,
|
184
|
+
index = _this$_removeItemInte.index;
|
185
|
+
if (removed && index !== null) {
|
186
|
+
this.computeLeafHash(index);
|
187
|
+
}
|
188
|
+
return removed;
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Removes multiple items from the hash tree.
|
193
|
+
* @param {LeafDataItem[]} items The array of items to remove.
|
194
|
+
* @returns {boolean[]} An array of booleans indicating success for each item.
|
195
|
+
*/
|
196
|
+
}, {
|
197
|
+
key: "removeItems",
|
198
|
+
value: function removeItems(items) {
|
199
|
+
var _this2 = this;
|
200
|
+
if (this.numLeaves === 0 && items.length > 0) {
|
201
|
+
return items.map(function () {
|
202
|
+
return false;
|
203
|
+
});
|
204
|
+
}
|
205
|
+
var results = [];
|
206
|
+
var changedLeafIndexes = new _set.default();
|
207
|
+
items.forEach(function (item) {
|
208
|
+
var _this2$_removeItemInt = _this2._removeItemInternal(item),
|
209
|
+
removed = _this2$_removeItemInt.removed,
|
210
|
+
index = _this2$_removeItemInt.index;
|
211
|
+
results.push(removed);
|
212
|
+
if (removed && index !== null) {
|
213
|
+
changedLeafIndexes.add(index);
|
214
|
+
}
|
215
|
+
});
|
216
|
+
changedLeafIndexes.forEach(function (index) {
|
217
|
+
_this2.computeLeafHash(index);
|
218
|
+
});
|
219
|
+
return results;
|
220
|
+
}
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Updates multiple items in the hash tree.
|
224
|
+
* This method can handle both adding and removing items based on the `operation` flag.
|
225
|
+
*
|
226
|
+
* @param {object[]} itemUpdates An array of objects containing `operation` flag and the `item` to update.
|
227
|
+
* @returns {boolean[]} An array of booleans indicating success for each operation.
|
228
|
+
*/
|
229
|
+
}, {
|
230
|
+
key: "updateItems",
|
231
|
+
value: function updateItems(itemUpdates) {
|
232
|
+
var _this3 = this;
|
233
|
+
if (this.numLeaves === 0 && itemUpdates.length > 0) {
|
234
|
+
return itemUpdates.map(function () {
|
235
|
+
return false;
|
236
|
+
});
|
237
|
+
}
|
238
|
+
var results = [];
|
239
|
+
var changedLeafIndexes = new _set.default();
|
240
|
+
itemUpdates.forEach(function (_ref) {
|
241
|
+
var operation = _ref.operation,
|
242
|
+
item = _ref.item;
|
243
|
+
if (operation === 'remove') {
|
244
|
+
var _this3$_removeItemInt = _this3._removeItemInternal(item),
|
245
|
+
removed = _this3$_removeItemInt.removed,
|
246
|
+
index = _this3$_removeItemInt.index;
|
247
|
+
results.push(removed);
|
248
|
+
if (removed && index !== null) {
|
249
|
+
changedLeafIndexes.add(index);
|
250
|
+
}
|
251
|
+
} else {
|
252
|
+
var _this3$_putItemIntern = _this3._putItemInternal(item),
|
253
|
+
put = _this3$_putItemIntern.put,
|
254
|
+
_index = _this3$_putItemIntern.index;
|
255
|
+
results.push(put);
|
256
|
+
if (put && _index !== null) {
|
257
|
+
changedLeafIndexes.add(_index);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
});
|
261
|
+
changedLeafIndexes.forEach(function (index) {
|
262
|
+
_this3.computeLeafHash(index);
|
263
|
+
});
|
264
|
+
return results;
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Computes the hash for a specific leaf.
|
269
|
+
* The hash is based on the sorted items within the leaf.
|
270
|
+
* @param {number} index The index of the leaf to compute the hash for.
|
271
|
+
* @returns {void}
|
272
|
+
*/
|
273
|
+
}, {
|
274
|
+
key: "computeLeafHash",
|
275
|
+
value: function computeLeafHash(index) {
|
276
|
+
var leafContent = this.leaves[index];
|
277
|
+
var totalItemsCount = (0, _keys.default)(leafContent).reduce(function (count, type) {
|
278
|
+
return count + (0, _keys.default)(leafContent[type]).length;
|
279
|
+
}, 0);
|
280
|
+
var buffer = Buffer.alloc(totalItemsCount * 16);
|
281
|
+
var offset = 0;
|
282
|
+
|
283
|
+
// iterate through the item types lexicographically
|
284
|
+
var itemTypes = (0, _keys.default)(leafContent).sort();
|
285
|
+
itemTypes.forEach(function (type) {
|
286
|
+
// iterate through the items of this type in ascending order of ID
|
287
|
+
var items = (0, _values.default)(leafContent[type]).sort(function (a, b) {
|
288
|
+
return a.id - b.id;
|
289
|
+
});
|
290
|
+
|
291
|
+
// add all the items id and version to the hasher
|
292
|
+
items.forEach(function (item) {
|
293
|
+
buffer.writeBigInt64LE(BigInt(item.id), offset);
|
294
|
+
buffer.writeBigInt64LE(BigInt(item.version), offset + 8);
|
295
|
+
offset += 16;
|
296
|
+
});
|
297
|
+
});
|
298
|
+
this.leafHashes[index] = (0, _xxh3Ts.XXH3_128)(buffer, BigInt(0)).toString(16);
|
299
|
+
}
|
300
|
+
|
301
|
+
/**
|
302
|
+
* Computes all internal and leaf node hashes of the tree.
|
303
|
+
* Internal node hashes are computed bottom-up from the leaf hashes.
|
304
|
+
* @returns {string[]} An array of hash strings, with internal node hashes first, followed by leaf hashes.
|
305
|
+
* Returns `[EMPTY_HASH]` if the tree has 0 leaves.
|
306
|
+
*/
|
307
|
+
}, {
|
308
|
+
key: "computeTreeHashes",
|
309
|
+
value: function computeTreeHashes() {
|
310
|
+
if (this.numLeaves === 0) {
|
311
|
+
return [_constants.EMPTY_HASH];
|
312
|
+
}
|
313
|
+
var currentLevelHashes = (0, _toConsumableArray2.default)(this.leafHashes);
|
314
|
+
var allHashes = [];
|
315
|
+
while (currentLevelHashes.length > 1) {
|
316
|
+
var nextLevelHashes = [];
|
317
|
+
for (var i = 0; i < currentLevelHashes.length; i += 2) {
|
318
|
+
var leftHash = currentLevelHashes[i];
|
319
|
+
var rightHash = i + 1 < currentLevelHashes.length ? currentLevelHashes[i + 1] : leftHash;
|
320
|
+
var input = Buffer.concat([Buffer.from(leftHash, 'hex').subarray(0, 8).reverse(), Buffer.from(leftHash, 'hex').subarray(8, 16).reverse(), Buffer.from(rightHash, 'hex').subarray(0, 8).reverse(), Buffer.from(rightHash, 'hex').subarray(8, 16).reverse()]);
|
321
|
+
nextLevelHashes.push((0, _xxh3Ts.XXH3_128)(input, BigInt(0)).toString(16));
|
322
|
+
}
|
323
|
+
currentLevelHashes = nextLevelHashes;
|
324
|
+
allHashes.unshift.apply(allHashes, (0, _toConsumableArray2.default)(currentLevelHashes));
|
325
|
+
}
|
326
|
+
return [].concat(allHashes, (0, _toConsumableArray2.default)(this.leafHashes));
|
327
|
+
}
|
328
|
+
|
329
|
+
/**
|
330
|
+
* Returns all hashes in the tree (internal nodes then leaf nodes).
|
331
|
+
* @returns {string[]} An array of hash strings.
|
332
|
+
*/
|
333
|
+
}, {
|
334
|
+
key: "getHashes",
|
335
|
+
value: function getHashes() {
|
336
|
+
return this.computeTreeHashes();
|
337
|
+
}
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Computes and returns the hash value of the root node.
|
341
|
+
* @returns {string} The root hash of the entire tree. Returns `EMPTY_HASH` if the tree has 0 leaves.
|
342
|
+
*/
|
343
|
+
}, {
|
344
|
+
key: "getRootHash",
|
345
|
+
value: function getRootHash() {
|
346
|
+
if (this.numLeaves === 0) {
|
347
|
+
return _constants.EMPTY_HASH;
|
348
|
+
}
|
349
|
+
return this.computeTreeHashes()[0];
|
350
|
+
}
|
351
|
+
|
352
|
+
/**
|
353
|
+
* Gets the number of leaves in the tree.
|
354
|
+
* @returns {number} The number of leaves.
|
355
|
+
*/
|
356
|
+
}, {
|
357
|
+
key: "getLeafCount",
|
358
|
+
value: function getLeafCount() {
|
359
|
+
return this.numLeaves;
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Calculates the total number of items stored in the tree.
|
364
|
+
* @returns {number} The total number of items.
|
365
|
+
*/
|
366
|
+
}, {
|
367
|
+
key: "getTotalItemCount",
|
368
|
+
value: function getTotalItemCount() {
|
369
|
+
var count = 0;
|
370
|
+
var _iterator = _createForOfIteratorHelper(this.leaves),
|
371
|
+
_step;
|
372
|
+
try {
|
373
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
374
|
+
var leaf = _step.value;
|
375
|
+
for (var _i = 0, _Object$keys2 = (0, _keys.default)(leaf); _i < _Object$keys2.length; _i++) {
|
376
|
+
var type = _Object$keys2[_i];
|
377
|
+
count += (0, _keys.default)(leaf[type]).length;
|
378
|
+
}
|
379
|
+
}
|
380
|
+
} catch (err) {
|
381
|
+
_iterator.e(err);
|
382
|
+
} finally {
|
383
|
+
_iterator.f();
|
384
|
+
}
|
385
|
+
return count;
|
386
|
+
}
|
387
|
+
|
388
|
+
/**
|
389
|
+
* Retrieves all data items from a specific leaf.
|
390
|
+
* @param {number} leafIndex The index of the leaf.
|
391
|
+
* @returns {LeafDataItem[]} An array of LeafDataItem in the specified leaf, sorted by ID,
|
392
|
+
* or an empty array if the index is invalid or leaf is empty.
|
393
|
+
*/
|
394
|
+
}, {
|
395
|
+
key: "getLeafData",
|
396
|
+
value: function getLeafData(leafIndex) {
|
397
|
+
if (leafIndex < 0 || leafIndex >= this.numLeaves) {
|
398
|
+
return [];
|
399
|
+
}
|
400
|
+
var leafContent = this.leaves[leafIndex];
|
401
|
+
var items = [];
|
402
|
+
for (var _i2 = 0, _Object$keys3 = (0, _keys.default)(leafContent); _i2 < _Object$keys3.length; _i2++) {
|
403
|
+
var type = _Object$keys3[_i2];
|
404
|
+
items.push.apply(items, (0, _toConsumableArray2.default)((0, _values.default)(leafContent[type])));
|
405
|
+
}
|
406
|
+
// Optionally sort them if a specific order is required, e.g., by ID
|
407
|
+
items.sort(function (a, b) {
|
408
|
+
return a.id - b.id;
|
409
|
+
});
|
410
|
+
return items;
|
411
|
+
}
|
412
|
+
|
413
|
+
/**
|
414
|
+
* Resizes the HashTree to have a new number of leaf nodes, redistributing all existing items.
|
415
|
+
* @param {number} newNumLeaves The new number of leaf nodes (must be 0 or a power of 2).
|
416
|
+
* @returns {boolean} true if the tree was resized, false if the size didn't change.
|
417
|
+
* @throws {Error} if newNumLeaves is not 0 or a power of 2.
|
418
|
+
*/
|
419
|
+
}, {
|
420
|
+
key: "resize",
|
421
|
+
value: function resize(newNumLeaves) {
|
422
|
+
// eslint-disable-next-line no-bitwise
|
423
|
+
if (newNumLeaves < 0 || newNumLeaves !== 0 && (newNumLeaves & newNumLeaves - 1) !== 0) {
|
424
|
+
throw new Error('New number of leaves must be 0 or a power of 2');
|
425
|
+
}
|
426
|
+
if (newNumLeaves === this.numLeaves) {
|
427
|
+
return false;
|
428
|
+
}
|
429
|
+
var allItems = [];
|
430
|
+
var _iterator2 = _createForOfIteratorHelper(this.leaves),
|
431
|
+
_step2;
|
432
|
+
try {
|
433
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
434
|
+
var leaf = _step2.value;
|
435
|
+
for (var _i3 = 0, _Object$keys4 = (0, _keys.default)(leaf); _i3 < _Object$keys4.length; _i3++) {
|
436
|
+
var type = _Object$keys4[_i3];
|
437
|
+
allItems.push.apply(allItems, (0, _toConsumableArray2.default)((0, _values.default)(leaf[type])));
|
438
|
+
}
|
439
|
+
}
|
440
|
+
|
441
|
+
// Re-initialize
|
442
|
+
// eslint-disable-next-line no-extra-semi
|
443
|
+
} catch (err) {
|
444
|
+
_iterator2.e(err);
|
445
|
+
} finally {
|
446
|
+
_iterator2.f();
|
447
|
+
}
|
448
|
+
this.numLeaves = newNumLeaves; // Type assertion to update readonly property
|
449
|
+
this.leafHashes = new Array(newNumLeaves).fill(_constants.EMPTY_HASH);
|
450
|
+
this.leaves = new Array(newNumLeaves).fill(null).map(function () {
|
451
|
+
return {};
|
452
|
+
});
|
453
|
+
if (newNumLeaves > 0) {
|
454
|
+
this.putItems(allItems); // Re-add items which will be re-assigned to leaves and re-hashed
|
455
|
+
}
|
456
|
+
|
457
|
+
return true;
|
458
|
+
}
|
459
|
+
|
460
|
+
/**
|
461
|
+
* Compares the tree's leaf hashes with an external set of hashes and returns the indices of differing leaf nodes.
|
462
|
+
* The externalHashes array is expected to contain all node hashes (internal followed by leaves),
|
463
|
+
* similar to the output of getHashes().
|
464
|
+
* @param {string[]} externalHashes An array of hash strings (internal node hashes then leaf hashes).
|
465
|
+
* @returns {number[]} An array of indices of the leaf nodes that have different hashes.
|
466
|
+
*/
|
467
|
+
}, {
|
468
|
+
key: "diffHashes",
|
469
|
+
value: function diffHashes(externalHashes) {
|
470
|
+
if (this.numLeaves === 0) {
|
471
|
+
// If this tree is empty, its hash is EMPTY_HASH.
|
472
|
+
// It differs if externalHashes is not a single EMPTY_HASH.
|
473
|
+
if (externalHashes && externalHashes.length === 1 && externalHashes[0] === _constants.EMPTY_HASH) {
|
474
|
+
return []; // No differences
|
475
|
+
}
|
476
|
+
// An empty tree has no leaves to differ, so return an empty array
|
477
|
+
// as no specific leaf indexes are different.
|
478
|
+
|
479
|
+
return [];
|
480
|
+
}
|
481
|
+
|
482
|
+
// todo: why is this not taking advantage of the tree structure and comparing from the root down?
|
483
|
+
|
484
|
+
// We are interested in comparing the leaf hashes part.
|
485
|
+
// The externalHashes array should also have its leaf hashes at the end.
|
486
|
+
var differingLeafIndexes = [];
|
487
|
+
// Calculate where the leaf hashes would start in the externalHashes array,
|
488
|
+
// assuming it has the same number of leaves as this tree.
|
489
|
+
var externalLeafHashesStart = externalHashes.length - this.numLeaves;
|
490
|
+
if (externalLeafHashesStart < 0) {
|
491
|
+
// externalHashes is too short to contain a complete set of leaf hashes
|
492
|
+
// corresponding to this tree's numLeaves.
|
493
|
+
// In this case, consider all of this tree's leaves as "different".
|
494
|
+
for (var i = 0; i < this.numLeaves; i += 1) {
|
495
|
+
differingLeafIndexes.push(i);
|
496
|
+
}
|
497
|
+
return differingLeafIndexes;
|
498
|
+
}
|
499
|
+
|
500
|
+
// Compare each leaf hash
|
501
|
+
for (var _i4 = 0; _i4 < this.numLeaves; _i4 += 1) {
|
502
|
+
var ownLeafHash = this.leafHashes[_i4];
|
503
|
+
// externalLeafHash might be undefined if externalHashes is shorter than expected
|
504
|
+
// but externalLeafHashesStart was non-negative, implying a structural mismatch.
|
505
|
+
var externalLeafHash = externalHashes[externalLeafHashesStart + _i4];
|
506
|
+
if (ownLeafHash !== externalLeafHash) {
|
507
|
+
differingLeafIndexes.push(_i4);
|
508
|
+
}
|
509
|
+
}
|
510
|
+
return differingLeafIndexes;
|
511
|
+
}
|
512
|
+
}]);
|
513
|
+
return HashTree;
|
514
|
+
}();
|
515
|
+
var _default = exports.default = HashTree;
|
516
|
+
//# sourceMappingURL=hashTree.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_xxh3Ts","require","_constants","_createForOfIteratorHelper","o","allowArrayLike","it","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","_Array$from","test","arr","len","arr2","Array","HashTree","leafData","numLeaves","_classCallCheck2","default","_defineProperty2","Error","concat","leafHashes","fill","EMPTY_HASH","leaves","map","putItems","_createClass2","key","_putItemInternal","item","put","index","id","type","existingItem","version","putItem","_this$_putItemInterna","computeLeafHash","items","_this","results","changedLeafIndexes","_set","forEach","_this$_putItemInterna2","push","add","_removeItemInternal","removed","_keys","removeItem","_this$_removeItemInte","removeItems","_this2","_this2$_removeItemInt","updateItems","itemUpdates","_this3","_ref","operation","_this3$_removeItemInt","_this3$_putItemIntern","leafContent","totalItemsCount","reduce","count","buffer","Buffer","alloc","offset","itemTypes","sort","_values","a","b","writeBigInt64LE","BigInt","XXH3_128","computeTreeHashes","currentLevelHashes","_toConsumableArray2","allHashes","nextLevelHashes","leftHash","rightHash","input","from","subarray","reverse","unshift","apply","getHashes","getRootHash","getLeafCount","getTotalItemCount","_iterator","_step","leaf","_i","_Object$keys2","getLeafData","leafIndex","_i2","_Object$keys3","resize","newNumLeaves","allItems","_iterator2","_step2","_i3","_Object$keys4","diffHashes","externalHashes","differingLeafIndexes","externalLeafHashesStart","ownLeafHash","externalLeafHash","_default","exports"],"sources":["hashTree.ts"],"sourcesContent":["import {XXH3_128} from 'xxh3-ts';\nimport {EMPTY_HASH} from './constants';\n\nexport type LeafDataItem = {\n type: string;\n id: number;\n version: number;\n};\n\n/**\n * HashTree is a data structure that organizes items into leaves based on their IDs,\n */\nclass HashTree {\n leaves: Array<Record<string, Record<number, LeafDataItem>>>;\n\n leafHashes: Array<string>;\n readonly numLeaves: number;\n\n /**\n * Constructs a new HashTree.\n * @param {LeafDataItem[]} leafData Initial data to populate the tree.\n * @param {number} numLeaves The number of leaf nodes in the tree. Must be 0 or a power of 2.\n * @throws {Error} If numLeaves is not 0 or a power of 2.\n */\n constructor(leafData: LeafDataItem[], numLeaves: number) {\n // eslint-disable-next-line no-bitwise\n if ((numLeaves & (numLeaves - 1)) !== 0) {\n throw new Error(`Number of leaves must be a power of 2, saw ${numLeaves}`);\n }\n\n this.numLeaves = numLeaves;\n this.leafHashes = new Array(numLeaves).fill(EMPTY_HASH);\n\n this.leaves = new Array(numLeaves).fill(null).map(() => {\n return {};\n });\n\n if (leafData) {\n this.putItems(leafData);\n }\n }\n\n /**\n * Internal logic for adding or updating an item, without computing the leaf hash.\n * @param {LeafDataItem} item The item to add or update.\n * @returns {{put: boolean, index: (number|null)}} Object indicating if put and the leaf index.\n * @private\n */\n private _putItemInternal(item: LeafDataItem): {put: boolean; index: number | null} {\n if (this.numLeaves === 0) {\n return {put: false, index: null}; // Cannot add to a tree with 0 leaves\n }\n\n const index = item.id % this.numLeaves;\n\n if (!this.leaves[index][item.type]) {\n this.leaves[index][item.type] = {};\n }\n\n const existingItem = this.leaves[index][item.type][item.id];\n\n if (!existingItem || existingItem.version < item.version) {\n this.leaves[index][item.type][item.id] = item;\n\n return {put: true, index};\n }\n\n return {put: false, index: null};\n }\n\n /**\n * Adds or updates a single item in the hash tree.\n * @param {LeafDataItem} item The item to add or update.\n * @returns {boolean} True if the item was added or updated, false otherwise (e.g., older version or tree has 0 leaves).\n */\n putItem(item: LeafDataItem): boolean {\n const {put, index} = this._putItemInternal(item);\n\n if (put && index !== null) {\n this.computeLeafHash(index);\n }\n\n return put;\n }\n\n /**\n * Adds or updates multiple items in the hash tree.\n * @param {LeafDataItem[]} items The array of items to add or update.\n * @returns {boolean[]} An array of booleans indicating success for each item.\n */\n putItems(items: LeafDataItem[]): boolean[] {\n if (this.numLeaves === 0 && items.length > 0) {\n // Cannot add items to a tree with 0 leaves.\n return items.map(() => false);\n }\n const results: boolean[] = [];\n const changedLeafIndexes = new Set<number>();\n\n items.forEach((item) => {\n const {put, index} = this._putItemInternal(item);\n results.push(put);\n if (put && index !== null) {\n changedLeafIndexes.add(index);\n }\n });\n\n changedLeafIndexes.forEach((index) => {\n this.computeLeafHash(index);\n });\n\n return results;\n }\n\n /**\n * Internal logic for removing an item, without computing the leaf hash.\n * @param {LeafDataItem} item The item to remove.\n * @returns {{removed: boolean, index: (number|null)}} Object indicating if removed and the leaf index.\n * @private\n */\n private _removeItemInternal(item: LeafDataItem): {removed: boolean; index: number | null} {\n if (this.numLeaves === 0) {\n return {removed: false, index: null};\n }\n\n const index = item.id % this.numLeaves;\n\n if (\n this.leaves[index] &&\n this.leaves[index][item.type] &&\n this.leaves[index][item.type][item.id]\n ) {\n const existingItem = this.leaves[index][item.type][item.id];\n if (\n existingItem.id === item.id &&\n existingItem.type === item.type &&\n existingItem.version <= item.version\n ) {\n delete this.leaves[index][item.type][item.id];\n if (Object.keys(this.leaves[index][item.type]).length === 0) {\n delete this.leaves[index][item.type];\n }\n\n return {removed: true, index};\n }\n }\n\n return {removed: false, index: null};\n }\n\n /**\n * Removes a single item from the hash tree.\n * The removal is based on matching type, id, and the provided item's version\n * being greater than or equal to the existing item's version.\n * @param {LeafDataItem} item The item to remove.\n * @returns {boolean} True if the item was removed, false otherwise.\n */\n removeItem(item: LeafDataItem): boolean {\n const {removed, index} = this._removeItemInternal(item);\n\n if (removed && index !== null) {\n this.computeLeafHash(index);\n }\n\n return removed;\n }\n\n /**\n * Removes multiple items from the hash tree.\n * @param {LeafDataItem[]} items The array of items to remove.\n * @returns {boolean[]} An array of booleans indicating success for each item.\n */\n removeItems(items: LeafDataItem[]): boolean[] {\n if (this.numLeaves === 0 && items.length > 0) {\n return items.map(() => false);\n }\n\n const results: boolean[] = [];\n const changedLeafIndexes = new Set<number>();\n\n items.forEach((item) => {\n const {removed, index} = this._removeItemInternal(item);\n results.push(removed);\n if (removed && index !== null) {\n changedLeafIndexes.add(index);\n }\n });\n\n changedLeafIndexes.forEach((index) => {\n this.computeLeafHash(index);\n });\n\n return results;\n }\n\n /**\n * Updates multiple items in the hash tree.\n * This method can handle both adding and removing items based on the `operation` flag.\n *\n * @param {object[]} itemUpdates An array of objects containing `operation` flag and the `item` to update.\n * @returns {boolean[]} An array of booleans indicating success for each operation.\n */\n updateItems(itemUpdates: {operation: 'update' | 'remove'; item: LeafDataItem}[]): boolean[] {\n if (this.numLeaves === 0 && itemUpdates.length > 0) {\n return itemUpdates.map(() => false);\n }\n\n const results: boolean[] = [];\n const changedLeafIndexes = new Set<number>();\n\n itemUpdates.forEach(({operation, item}) => {\n if (operation === 'remove') {\n const {removed, index} = this._removeItemInternal(item);\n results.push(removed);\n if (removed && index !== null) {\n changedLeafIndexes.add(index);\n }\n } else {\n const {put, index} = this._putItemInternal(item);\n results.push(put);\n if (put && index !== null) {\n changedLeafIndexes.add(index);\n }\n }\n });\n\n changedLeafIndexes.forEach((index) => {\n this.computeLeafHash(index);\n });\n\n return results;\n }\n\n /**\n * Computes the hash for a specific leaf.\n * The hash is based on the sorted items within the leaf.\n * @param {number} index The index of the leaf to compute the hash for.\n * @returns {void}\n */\n computeLeafHash(index: number) {\n const leafContent = this.leaves[index];\n\n const totalItemsCount = Object.keys(leafContent).reduce((count, type) => {\n return count + Object.keys(leafContent[type]).length;\n }, 0);\n const buffer = Buffer.alloc(totalItemsCount * 16);\n\n let offset = 0;\n\n // iterate through the item types lexicographically\n const itemTypes = Object.keys(leafContent).sort();\n itemTypes.forEach((type) => {\n // iterate through the items of this type in ascending order of ID\n const items = Object.values(leafContent[type]).sort(\n (a: LeafDataItem, b: LeafDataItem) => a.id - b.id\n );\n\n // add all the items id and version to the hasher\n items.forEach((item: LeafDataItem) => {\n buffer.writeBigInt64LE(BigInt(item.id), offset);\n buffer.writeBigInt64LE(BigInt(item.version), offset + 8);\n\n offset += 16;\n });\n });\n\n this.leafHashes[index] = XXH3_128(buffer, BigInt(0)).toString(16);\n }\n\n /**\n * Computes all internal and leaf node hashes of the tree.\n * Internal node hashes are computed bottom-up from the leaf hashes.\n * @returns {string[]} An array of hash strings, with internal node hashes first, followed by leaf hashes.\n * Returns `[EMPTY_HASH]` if the tree has 0 leaves.\n */\n computeTreeHashes(): string[] {\n if (this.numLeaves === 0) {\n return [EMPTY_HASH];\n }\n\n let currentLevelHashes = [...this.leafHashes];\n const allHashes = [];\n\n while (currentLevelHashes.length > 1) {\n const nextLevelHashes: string[] = [];\n for (let i = 0; i < currentLevelHashes.length; i += 2) {\n const leftHash = currentLevelHashes[i];\n const rightHash = i + 1 < currentLevelHashes.length ? currentLevelHashes[i + 1] : leftHash;\n\n const input = Buffer.concat([\n Buffer.from(leftHash, 'hex').subarray(0, 8).reverse(),\n Buffer.from(leftHash, 'hex').subarray(8, 16).reverse(),\n Buffer.from(rightHash, 'hex').subarray(0, 8).reverse(),\n Buffer.from(rightHash, 'hex').subarray(8, 16).reverse(),\n ]);\n\n nextLevelHashes.push(XXH3_128(input, BigInt(0)).toString(16));\n }\n currentLevelHashes = nextLevelHashes;\n allHashes.unshift(...currentLevelHashes);\n }\n\n return [...allHashes, ...this.leafHashes];\n }\n\n /**\n * Returns all hashes in the tree (internal nodes then leaf nodes).\n * @returns {string[]} An array of hash strings.\n */\n getHashes(): string[] {\n return this.computeTreeHashes();\n }\n\n /**\n * Computes and returns the hash value of the root node.\n * @returns {string} The root hash of the entire tree. Returns `EMPTY_HASH` if the tree has 0 leaves.\n */\n getRootHash(): string {\n if (this.numLeaves === 0) {\n return EMPTY_HASH;\n }\n\n return this.computeTreeHashes()[0];\n }\n\n /**\n * Gets the number of leaves in the tree.\n * @returns {number} The number of leaves.\n */\n getLeafCount(): number {\n return this.numLeaves;\n }\n\n /**\n * Calculates the total number of items stored in the tree.\n * @returns {number} The total number of items.\n */\n getTotalItemCount(): number {\n let count = 0;\n for (const leaf of this.leaves) {\n for (const type of Object.keys(leaf)) {\n count += Object.keys(leaf[type]).length;\n }\n }\n\n return count;\n }\n\n /**\n * Retrieves all data items from a specific leaf.\n * @param {number} leafIndex The index of the leaf.\n * @returns {LeafDataItem[]} An array of LeafDataItem in the specified leaf, sorted by ID,\n * or an empty array if the index is invalid or leaf is empty.\n */\n getLeafData(leafIndex: number): LeafDataItem[] {\n if (leafIndex < 0 || leafIndex >= this.numLeaves) {\n return [];\n }\n const leafContent = this.leaves[leafIndex];\n const items: LeafDataItem[] = [];\n for (const type of Object.keys(leafContent)) {\n items.push(...Object.values(leafContent[type]));\n }\n // Optionally sort them if a specific order is required, e.g., by ID\n items.sort((a, b) => a.id - b.id);\n\n return items;\n }\n\n /**\n * Resizes the HashTree to have a new number of leaf nodes, redistributing all existing items.\n * @param {number} newNumLeaves The new number of leaf nodes (must be 0 or a power of 2).\n * @returns {boolean} true if the tree was resized, false if the size didn't change.\n * @throws {Error} if newNumLeaves is not 0 or a power of 2.\n */\n resize(newNumLeaves: number): boolean {\n // eslint-disable-next-line no-bitwise\n if (newNumLeaves < 0 || (newNumLeaves !== 0 && (newNumLeaves & (newNumLeaves - 1)) !== 0)) {\n throw new Error('New number of leaves must be 0 or a power of 2');\n }\n\n if (newNumLeaves === this.numLeaves) {\n return false;\n }\n\n const allItems: LeafDataItem[] = [];\n for (const leaf of this.leaves) {\n for (const type of Object.keys(leaf)) {\n allItems.push(...Object.values(leaf[type]));\n }\n }\n\n // Re-initialize\n // eslint-disable-next-line no-extra-semi\n (this as any).numLeaves = newNumLeaves; // Type assertion to update readonly property\n this.leafHashes = new Array(newNumLeaves).fill(EMPTY_HASH);\n this.leaves = new Array(newNumLeaves).fill(null).map(() => ({}));\n\n if (newNumLeaves > 0) {\n this.putItems(allItems); // Re-add items which will be re-assigned to leaves and re-hashed\n }\n\n return true;\n }\n\n /**\n * Compares the tree's leaf hashes with an external set of hashes and returns the indices of differing leaf nodes.\n * The externalHashes array is expected to contain all node hashes (internal followed by leaves),\n * similar to the output of getHashes().\n * @param {string[]} externalHashes An array of hash strings (internal node hashes then leaf hashes).\n * @returns {number[]} An array of indices of the leaf nodes that have different hashes.\n */\n diffHashes(externalHashes: string[]): number[] {\n if (this.numLeaves === 0) {\n // If this tree is empty, its hash is EMPTY_HASH.\n // It differs if externalHashes is not a single EMPTY_HASH.\n if (externalHashes && externalHashes.length === 1 && externalHashes[0] === EMPTY_HASH) {\n return []; // No differences\n }\n // An empty tree has no leaves to differ, so return an empty array\n // as no specific leaf indexes are different.\n\n return [];\n }\n\n // todo: why is this not taking advantage of the tree structure and comparing from the root down?\n\n // We are interested in comparing the leaf hashes part.\n // The externalHashes array should also have its leaf hashes at the end.\n const differingLeafIndexes: number[] = [];\n // Calculate where the leaf hashes would start in the externalHashes array,\n // assuming it has the same number of leaves as this tree.\n const externalLeafHashesStart = externalHashes.length - this.numLeaves;\n\n if (externalLeafHashesStart < 0) {\n // externalHashes is too short to contain a complete set of leaf hashes\n // corresponding to this tree's numLeaves.\n // In this case, consider all of this tree's leaves as \"different\".\n for (let i = 0; i < this.numLeaves; i += 1) {\n differingLeafIndexes.push(i);\n }\n\n return differingLeafIndexes;\n }\n\n // Compare each leaf hash\n for (let i = 0; i < this.numLeaves; i += 1) {\n const ownLeafHash = this.leafHashes[i];\n // externalLeafHash might be undefined if externalHashes is shorter than expected\n // but externalLeafHashesStart was non-negative, implying a structural mismatch.\n const externalLeafHash = externalHashes[externalLeafHashesStart + i];\n if (ownLeafHash !== externalLeafHash) {\n differingLeafIndexes.push(i);\n }\n }\n\n return differingLeafIndexes;\n }\n}\n\nexport default HashTree;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAAuC,SAAAE,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,OAAA,oBAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,EAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAO,MAAA,qBAAAL,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAM,CAAA,UAAAC,CAAA,YAAAA,EAAA,e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