@webex/plugin-meetings 3.12.0-task-refactor.1 → 3.12.0-webex-services-ready.2
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/AGENTS.md +9 -0
- package/dist/aiEnableRequest/index.js +197 -0
- package/dist/aiEnableRequest/index.js.map +1 -0
- package/dist/aiEnableRequest/utils.js +36 -0
- package/dist/aiEnableRequest/utils.js.map +1 -0
- package/dist/annotation/index.js +14 -5
- package/dist/annotation/index.js.map +1 -1
- package/dist/breakouts/breakout.js +8 -3
- package/dist/breakouts/breakout.js.map +1 -1
- package/dist/breakouts/index.js +26 -2
- package/dist/breakouts/index.js.map +1 -1
- package/dist/common/errors/webex-errors.js +49 -5
- package/dist/common/errors/webex-errors.js.map +1 -1
- package/dist/config.js +9 -3
- package/dist/config.js.map +1 -1
- package/dist/constants.js +59 -10
- package/dist/constants.js.map +1 -1
- package/dist/controls-options-manager/constants.js +11 -1
- package/dist/controls-options-manager/constants.js.map +1 -1
- package/dist/controls-options-manager/index.js +67 -29
- package/dist/controls-options-manager/index.js.map +1 -1
- package/dist/controls-options-manager/util.js +91 -0
- package/dist/controls-options-manager/util.js.map +1 -1
- package/dist/hashTree/constants.js +34 -0
- package/dist/hashTree/constants.js.map +1 -0
- package/dist/hashTree/hashTree.js +533 -0
- package/dist/hashTree/hashTree.js.map +1 -0
- package/dist/hashTree/hashTreeParser.js +2068 -36
- package/dist/hashTree/hashTreeParser.js.map +1 -1
- package/dist/hashTree/types.js +13 -3
- package/dist/hashTree/types.js.map +1 -1
- package/dist/hashTree/utils.js +111 -0
- package/dist/hashTree/utils.js.map +1 -0
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/interceptors/constant.js +12 -0
- package/dist/interceptors/constant.js.map +1 -0
- package/dist/interceptors/dataChannelAuthToken.js +350 -0
- package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
- package/dist/interceptors/index.js +7 -0
- package/dist/interceptors/index.js.map +1 -1
- package/dist/interceptors/locusRetry.js +23 -8
- package/dist/interceptors/locusRetry.js.map +1 -1
- package/dist/interceptors/locusRouteToken.js +27 -5
- package/dist/interceptors/locusRouteToken.js.map +1 -1
- package/dist/interceptors/utils.js +27 -0
- package/dist/interceptors/utils.js.map +1 -0
- package/dist/interpretation/index.js +11 -2
- package/dist/interpretation/index.js.map +1 -1
- package/dist/interpretation/interpretation.types.js +7 -0
- package/dist/interpretation/interpretation.types.js.map +1 -0
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/locus-info/controlsUtils.js +11 -4
- package/dist/locus-info/controlsUtils.js.map +1 -1
- package/dist/locus-info/index.js +896 -277
- package/dist/locus-info/index.js.map +1 -1
- package/dist/locus-info/infoUtils.js +36 -5
- package/dist/locus-info/infoUtils.js.map +1 -1
- package/dist/locus-info/selfUtils.js +1 -0
- package/dist/locus-info/selfUtils.js.map +1 -1
- package/dist/locus-info/types.js +19 -0
- package/dist/locus-info/types.js.map +1 -1
- package/dist/media/MediaConnectionAwaiter.js +72 -3
- package/dist/media/MediaConnectionAwaiter.js.map +1 -1
- package/dist/media/index.js +8 -2
- package/dist/media/index.js.map +1 -1
- package/dist/media/properties.js +5 -2
- package/dist/media/properties.js.map +1 -1
- package/dist/meeting/in-meeting-actions.js +11 -1
- package/dist/meeting/in-meeting-actions.js.map +1 -1
- package/dist/meeting/index.js +2075 -1096
- package/dist/meeting/index.js.map +1 -1
- package/dist/meeting/locusMediaRequest.js +229 -82
- package/dist/meeting/locusMediaRequest.js.map +1 -1
- package/dist/meeting/muteState.js +10 -1
- package/dist/meeting/muteState.js.map +1 -1
- package/dist/meeting/request.js +55 -2
- package/dist/meeting/request.js.map +1 -1
- package/dist/meeting/request.type.js.map +1 -1
- package/dist/meeting/util.js +168 -5
- package/dist/meeting/util.js.map +1 -1
- package/dist/meeting-info/meeting-info-v2.js +2 -2
- package/dist/meeting-info/meeting-info-v2.js.map +1 -1
- package/dist/meetings/index.js +369 -173
- package/dist/meetings/index.js.map +1 -1
- package/dist/meetings/meetings.types.js +6 -1
- package/dist/meetings/meetings.types.js.map +1 -1
- package/dist/meetings/request.js +39 -0
- package/dist/meetings/request.js.map +1 -1
- package/dist/meetings/util.js +127 -25
- package/dist/meetings/util.js.map +1 -1
- package/dist/member/index.js +20 -0
- package/dist/member/index.js.map +1 -1
- package/dist/member/types.js.map +1 -1
- package/dist/member/util.js +40 -0
- package/dist/member/util.js.map +1 -1
- package/dist/members/index.js +101 -43
- package/dist/members/index.js.map +1 -1
- package/dist/members/util.js +8 -1
- package/dist/members/util.js.map +1 -1
- package/dist/metrics/constants.js +11 -1
- package/dist/metrics/constants.js.map +1 -1
- package/dist/multistream/codec/constants.js +63 -0
- package/dist/multistream/codec/constants.js.map +1 -0
- package/dist/multistream/mediaRequestManager.js +64 -68
- package/dist/multistream/mediaRequestManager.js.map +1 -1
- package/dist/multistream/receiveSlot.js +9 -0
- package/dist/multistream/receiveSlot.js.map +1 -1
- package/dist/multistream/remoteMediaManager.js +11 -0
- package/dist/multistream/remoteMediaManager.js.map +1 -1
- package/dist/multistream/sendSlotManager.js +116 -2
- package/dist/multistream/sendSlotManager.js.map +1 -1
- package/dist/reachability/clusterReachability.js +171 -18
- package/dist/reachability/clusterReachability.js.map +1 -1
- package/dist/reachability/index.js +142 -94
- package/dist/reachability/index.js.map +1 -1
- package/dist/reachability/reachability.types.js +2 -0
- package/dist/reachability/reachability.types.js.map +1 -1
- package/dist/reachability/reachabilityPeerConnection.js +1 -1
- package/dist/reachability/reachabilityPeerConnection.js.map +1 -1
- package/dist/reachability/util.js +45 -0
- package/dist/reachability/util.js.map +1 -1
- package/dist/reactions/reactions.type.js.map +1 -1
- package/dist/reconnection-manager/index.js +0 -1
- package/dist/reconnection-manager/index.js.map +1 -1
- package/dist/recording-controller/index.js +1 -3
- package/dist/recording-controller/index.js.map +1 -1
- package/dist/types/aiEnableRequest/index.d.ts +5 -0
- package/dist/types/aiEnableRequest/utils.d.ts +2 -0
- package/dist/types/common/browser-detection.d.ts +1 -0
- package/dist/types/common/errors/webex-errors.d.ts +32 -2
- package/dist/types/common/events/events-scope.d.ts +1 -0
- package/dist/types/common/events/events.d.ts +1 -0
- package/dist/types/config.d.ts +7 -2
- package/dist/types/constants.d.ts +35 -1
- package/dist/types/controls-options-manager/constants.d.ts +6 -1
- package/dist/types/controls-options-manager/index.d.ts +16 -0
- package/dist/types/hashTree/constants.d.ts +11 -0
- package/dist/types/hashTree/hashTree.d.ts +136 -0
- package/dist/types/hashTree/hashTreeParser.d.ts +392 -14
- package/dist/types/hashTree/types.d.ts +20 -0
- package/dist/types/hashTree/utils.d.ts +40 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interceptors/constant.d.ts +5 -0
- package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
- package/dist/types/interceptors/index.d.ts +2 -1
- package/dist/types/interceptors/locusRetry.d.ts +4 -4
- package/dist/types/interceptors/locusRouteToken.d.ts +2 -0
- package/dist/types/interceptors/utils.d.ts +1 -0
- package/dist/types/interpretation/interpretation.types.d.ts +10 -0
- package/dist/types/locus-info/index.d.ts +116 -51
- package/dist/types/locus-info/infoUtils.d.ts +8 -0
- package/dist/types/locus-info/types.d.ts +48 -12
- package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
- package/dist/types/media/properties.d.ts +3 -1
- package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
- package/dist/types/meeting/index.d.ts +196 -15
- package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
- package/dist/types/meeting/request.d.ts +17 -1
- package/dist/types/meeting/request.type.d.ts +5 -0
- package/dist/types/meeting/util.d.ts +40 -0
- package/dist/types/meeting-info/util.d.ts +1 -0
- package/dist/types/meeting-info/utilv2.d.ts +1 -0
- package/dist/types/meetings/index.d.ts +34 -20
- package/dist/types/meetings/meetings.types.d.ts +15 -0
- package/dist/types/meetings/request.d.ts +14 -0
- package/dist/types/member/index.d.ts +2 -0
- package/dist/types/member/types.d.ts +5 -4
- package/dist/types/member/util.d.ts +14 -0
- package/dist/types/members/index.d.ts +15 -2
- package/dist/types/members/util.d.ts +1 -5
- package/dist/types/metrics/constants.d.ts +10 -0
- package/dist/types/multistream/codec/constants.d.ts +7 -0
- package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
- package/dist/types/multistream/sendSlotManager.d.ts +23 -1
- package/dist/types/reachability/clusterReachability.d.ts +33 -6
- package/dist/types/reachability/index.d.ts +10 -3
- package/dist/types/reachability/reachability.types.d.ts +7 -0
- package/dist/types/reachability/util.d.ts +17 -0
- package/dist/types/reactions/reactions.type.d.ts +4 -0
- package/dist/types/recording-controller/util.d.ts +5 -5
- package/dist/types/roap/index.d.ts +1 -1
- package/dist/types/webinar/utils.d.ts +6 -0
- package/dist/webinar/index.js +585 -164
- package/dist/webinar/index.js.map +1 -1
- package/dist/webinar/utils.js +25 -0
- package/dist/webinar/utils.js.map +1 -0
- package/package.json +26 -24
- package/src/aiEnableRequest/README.md +84 -0
- package/src/aiEnableRequest/index.ts +186 -0
- package/src/aiEnableRequest/utils.ts +25 -0
- package/src/annotation/index.ts +27 -7
- package/src/breakouts/breakout.ts +3 -1
- package/src/breakouts/index.ts +31 -0
- package/src/common/errors/webex-errors.ts +50 -3
- package/src/config.ts +7 -2
- package/src/constants.ts +49 -3
- package/src/controls-options-manager/constants.ts +14 -1
- package/src/controls-options-manager/index.ts +87 -28
- package/src/controls-options-manager/util.ts +81 -1
- package/src/hashTree/constants.ts +26 -0
- package/src/hashTree/hashTree.ts +480 -0
- package/src/hashTree/hashTreeParser.ts +1911 -29
- package/src/hashTree/types.ts +24 -1
- package/src/hashTree/utils.ts +98 -0
- package/src/index.ts +14 -1
- package/src/interceptors/constant.ts +6 -0
- package/src/interceptors/dataChannelAuthToken.ts +246 -0
- package/src/interceptors/index.ts +2 -1
- package/src/interceptors/locusRetry.ts +25 -4
- package/src/interceptors/locusRouteToken.ts +22 -5
- package/src/interceptors/utils.ts +16 -0
- package/src/interpretation/index.ts +29 -11
- package/src/interpretation/interpretation.types.ts +11 -0
- package/src/locus-info/controlsUtils.ts +20 -1
- package/src/locus-info/index.ts +958 -250
- package/src/locus-info/infoUtils.ts +41 -6
- package/src/locus-info/selfUtils.ts +1 -0
- package/src/locus-info/types.ts +51 -12
- package/src/media/MediaConnectionAwaiter.ts +62 -5
- package/src/media/index.ts +10 -1
- package/src/media/properties.ts +4 -1
- package/src/meeting/in-meeting-actions.ts +20 -0
- package/src/meeting/index.ts +1025 -146
- package/src/meeting/locusMediaRequest.ts +106 -6
- package/src/meeting/muteState.ts +10 -1
- package/src/meeting/request.ts +53 -0
- package/src/meeting/request.type.ts +6 -0
- package/src/meeting/util.ts +207 -7
- package/src/meeting-info/meeting-info-v2.ts +4 -2
- package/src/meetings/index.ts +307 -132
- package/src/meetings/meetings.types.ts +19 -0
- package/src/meetings/request.ts +43 -0
- package/src/meetings/util.ts +127 -13
- package/src/member/index.ts +20 -0
- package/src/member/types.ts +1 -0
- package/src/member/util.ts +41 -0
- package/src/members/index.ts +70 -7
- package/src/members/util.ts +12 -4
- package/src/metrics/constants.ts +11 -0
- package/src/multistream/codec/constants.ts +58 -0
- package/src/multistream/mediaRequestManager.ts +117 -76
- package/src/multistream/receiveSlot.ts +18 -0
- package/src/multistream/remoteMediaManager.ts +13 -0
- package/src/multistream/sendSlotManager.ts +97 -3
- package/src/reachability/clusterReachability.ts +156 -29
- package/src/reachability/index.ts +62 -17
- package/src/reachability/reachability.types.ts +11 -0
- package/src/reachability/reachabilityPeerConnection.ts +3 -1
- package/src/reachability/util.ts +36 -0
- package/src/reactions/reactions.type.ts +4 -0
- package/src/reconnection-manager/index.ts +0 -1
- package/src/recording-controller/index.ts +1 -2
- package/src/webinar/index.ts +448 -11
- package/src/webinar/utils.ts +16 -0
- package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
- package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
- package/test/unit/spec/annotation/index.ts +69 -7
- package/test/unit/spec/breakouts/breakout.ts +9 -3
- package/test/unit/spec/breakouts/index.ts +49 -0
- package/test/unit/spec/common/errors/webex-errors.ts +78 -0
- package/test/unit/spec/controls-options-manager/index.js +244 -29
- package/test/unit/spec/controls-options-manager/util.js +165 -0
- package/test/unit/spec/hashTree/hashTree.ts +721 -0
- package/test/unit/spec/hashTree/hashTreeParser.ts +5328 -0
- package/test/unit/spec/hashTree/utils.ts +264 -0
- package/test/unit/spec/interceptors/dataChannelAuthToken.ts +406 -0
- package/test/unit/spec/interceptors/locusRetry.ts +205 -4
- package/test/unit/spec/interceptors/locusRouteToken.ts +44 -0
- package/test/unit/spec/interceptors/utils.ts +75 -0
- package/test/unit/spec/interpretation/index.ts +26 -4
- package/test/unit/spec/locus-info/controlsUtils.js +222 -52
- package/test/unit/spec/locus-info/index.js +2000 -171
- package/test/unit/spec/locus-info/infoUtils.js +184 -1
- package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
- package/test/unit/spec/media/index.ts +92 -0
- package/test/unit/spec/media/properties.ts +12 -3
- package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
- package/test/unit/spec/meeting/index.js +2925 -209
- package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
- package/test/unit/spec/meeting/muteState.js +81 -0
- package/test/unit/spec/meeting/request.js +82 -0
- package/test/unit/spec/meeting/utils.js +595 -27
- package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
- package/test/unit/spec/meetings/index.js +1214 -75
- package/test/unit/spec/meetings/request.js +141 -0
- package/test/unit/spec/meetings/utils.js +453 -52
- package/test/unit/spec/member/index.js +35 -4
- package/test/unit/spec/member/util.js +154 -27
- package/test/unit/spec/members/index.js +216 -0
- package/test/unit/spec/members/request.js +37 -1
- package/test/unit/spec/members/utils.js +63 -0
- package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
- package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
- package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
- package/test/unit/spec/reachability/clusterReachability.ts +125 -1
- package/test/unit/spec/reachability/index.ts +154 -49
- package/test/unit/spec/reachability/util.ts +31 -0
- package/test/unit/spec/reconnection-manager/index.js +4 -8
- package/test/unit/spec/recording-controller/index.js +9 -8
- package/test/unit/spec/webinar/index.ts +837 -39
- package/test/unit/spec/webinar/utils.ts +39 -0
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
+
var _Array$from = require("@babel/runtime-corejs2/core-js/array/from");
|
|
5
|
+
var _Symbol = require("@babel/runtime-corejs2/core-js/symbol");
|
|
6
|
+
var _Symbol$iterator = require("@babel/runtime-corejs2/core-js/symbol/iterator");
|
|
7
|
+
var _Array$isArray2 = require("@babel/runtime-corejs2/core-js/array/is-array");
|
|
8
|
+
var _Object$keys4 = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
9
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
10
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
12
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
4
13
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
5
14
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
15
|
_Object$defineProperty(exports, "__esModule", {
|
|
7
16
|
value: true
|
|
8
17
|
});
|
|
9
|
-
exports.default = exports.LocusInfoUpdateType = void 0;
|
|
10
|
-
exports.isSelf = isSelf;
|
|
18
|
+
exports.default = exports.SyncAllBackoffType = exports.MeetingEndedError = exports.LocusNotFoundError = exports.LocusInfoUpdateType = void 0;
|
|
11
19
|
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
|
20
|
+
var _set = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/set"));
|
|
21
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
22
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
23
|
+
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
|
|
24
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
|
25
|
+
var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
|
|
26
|
+
var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/parse-int"));
|
|
27
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
|
|
28
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
|
|
29
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/typeof"));
|
|
12
30
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
|
13
31
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
14
32
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
@@ -17,18 +35,39 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
17
35
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
18
36
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
19
37
|
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/wrapNativeSuper"));
|
|
38
|
+
var _lodash = require("lodash");
|
|
39
|
+
var _hashTree = _interopRequireDefault(require("./hashTree"));
|
|
40
|
+
var _loggerProxy = _interopRequireDefault(require("../common/logs/logger-proxy"));
|
|
41
|
+
var _metrics = _interopRequireDefault(require("../metrics"));
|
|
42
|
+
var _constants = _interopRequireDefault(require("../metrics/constants"));
|
|
43
|
+
var _constants2 = require("../constants");
|
|
44
|
+
var _constants3 = require("./constants");
|
|
20
45
|
var _types = require("./types");
|
|
46
|
+
var _types2 = require("../locus-info/types");
|
|
47
|
+
var _utils = require("./utils");
|
|
48
|
+
function ownKeys(e, r) { var t = _Object$keys4(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
49
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
50
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof _Symbol && r[_Symbol$iterator] || r["@@iterator"]; if (!t) { if (_Array$isArray2(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
51
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? _Array$from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
52
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
21
53
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
22
54
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
55
|
+
var SyncAllBackoffType = exports.SyncAllBackoffType = /*#__PURE__*/function (SyncAllBackoffType) {
|
|
56
|
+
SyncAllBackoffType["NONE"] = "none";
|
|
57
|
+
SyncAllBackoffType["ONLY_LLM"] = "onlyLLM";
|
|
58
|
+
SyncAllBackoffType["ALL"] = "all";
|
|
59
|
+
return SyncAllBackoffType;
|
|
60
|
+
}({});
|
|
23
61
|
var LocusInfoUpdateType = exports.LocusInfoUpdateType = {
|
|
24
62
|
OBJECTS_UPDATED: 'OBJECTS_UPDATED',
|
|
25
|
-
MEETING_ENDED: 'MEETING_ENDED'
|
|
63
|
+
MEETING_ENDED: 'MEETING_ENDED',
|
|
64
|
+
LOCUS_NOT_FOUND: 'LOCUS_NOT_FOUND'
|
|
26
65
|
};
|
|
27
66
|
/**
|
|
28
67
|
* This error is thrown if we receive information that the meeting has ended while we're processing some hash messages.
|
|
29
68
|
* It's handled internally by HashTreeParser and results in MEETING_ENDED being sent up.
|
|
30
69
|
*/
|
|
31
|
-
var MeetingEndedError = /*#__PURE__*/function (_Error) {
|
|
70
|
+
var MeetingEndedError = exports.MeetingEndedError = /*#__PURE__*/function (_Error) {
|
|
32
71
|
function MeetingEndedError() {
|
|
33
72
|
(0, _classCallCheck2.default)(this, MeetingEndedError);
|
|
34
73
|
return _callSuper(this, MeetingEndedError, arguments);
|
|
@@ -37,13 +76,23 @@ var MeetingEndedError = /*#__PURE__*/function (_Error) {
|
|
|
37
76
|
return (0, _createClass2.default)(MeetingEndedError);
|
|
38
77
|
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
39
78
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
79
|
+
* This error is thrown when a 404 is received from Locus hash tree endpoints, indicating that the locus URL
|
|
80
|
+
* is no longer valid (e.g. participant moved to a breakout room, or meeting ended).
|
|
81
|
+
* It's handled internally by HashTreeParser and results in LOCUS_NOT_FOUND being sent up.
|
|
43
82
|
*/
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
83
|
+
var LocusNotFoundError = exports.LocusNotFoundError = /*#__PURE__*/function (_Error2) {
|
|
84
|
+
function LocusNotFoundError() {
|
|
85
|
+
(0, _classCallCheck2.default)(this, LocusNotFoundError);
|
|
86
|
+
return _callSuper(this, LocusNotFoundError, arguments);
|
|
87
|
+
}
|
|
88
|
+
(0, _inherits2.default)(LocusNotFoundError, _Error2);
|
|
89
|
+
return (0, _createClass2.default)(LocusNotFoundError);
|
|
90
|
+
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
91
|
+
/* Currently Locus always sends Metadata objects only in the "self" dataset.
|
|
92
|
+
* If this ever changes, update all the code that relies on this constant.
|
|
93
|
+
*/
|
|
94
|
+
var MetadataDataSetName = _constants3.DataSetNames.SELF;
|
|
95
|
+
var PossibleSentinelMessageDataSetNames = [_constants3.DataSetNames.MAIN, _constants3.DataSetNames.SELF, _constants3.DataSetNames.UNJOINED];
|
|
47
96
|
|
|
48
97
|
/**
|
|
49
98
|
* Parses hash tree eventing locus data
|
|
@@ -55,7 +104,7 @@ var HashTreeParser = /*#__PURE__*/function () {
|
|
|
55
104
|
* @param {Object} options.initialLocus The initial locus data containing the hash tree information
|
|
56
105
|
*/
|
|
57
106
|
function HashTreeParser(options) {
|
|
58
|
-
var _locus$
|
|
107
|
+
var _locus$links, _locus$links$resource, _locus$links$resource2, _options$metadata, _options$metadata2, _options$metadata2$vi;
|
|
59
108
|
(0, _classCallCheck2.default)(this, HashTreeParser);
|
|
60
109
|
(0, _defineProperty2.default)(this, "dataSets", {});
|
|
61
110
|
(0, _defineProperty2.default)(this, "visibleDataSetsUrl", void 0);
|
|
@@ -64,32 +113,229 @@ var HashTreeParser = /*#__PURE__*/function () {
|
|
|
64
113
|
(0, _defineProperty2.default)(this, "locusInfoUpdateCallback", void 0);
|
|
65
114
|
(0, _defineProperty2.default)(this, "visibleDataSets", void 0);
|
|
66
115
|
(0, _defineProperty2.default)(this, "debugId", void 0);
|
|
67
|
-
|
|
116
|
+
(0, _defineProperty2.default)(this, "excludedDataSets", void 0);
|
|
117
|
+
(0, _defineProperty2.default)(this, "state", void 0);
|
|
118
|
+
(0, _defineProperty2.default)(this, "syncQueue", []);
|
|
119
|
+
(0, _defineProperty2.default)(this, "isSyncInProgress", false);
|
|
120
|
+
// tracks whether syncAllDatasets is currently in its backoff delay phase and with what scope
|
|
121
|
+
(0, _defineProperty2.default)(this, "syncAllBackoffType", SyncAllBackoffType.NONE);
|
|
122
|
+
// datasets that received messages during the syncAllDatasets backoff sleep and should be skipped
|
|
123
|
+
(0, _defineProperty2.default)(this, "dataSetsSyncedDuringBackoff", new _set.default());
|
|
124
|
+
(0, _defineProperty2.default)(this, "syncQueueProcessingPromise", _promise.default.resolve());
|
|
125
|
+
// top-level heartbeat interval from the most recent message, used as fallback when dataset-level value is missing
|
|
126
|
+
(0, _defineProperty2.default)(this, "topLevelHeartbeatIntervalMs", void 0);
|
|
127
|
+
var _options$initialLocus = options.initialLocus,
|
|
128
|
+
dataSets = _options$initialLocus.dataSets,
|
|
129
|
+
locus = _options$initialLocus.locus; // extract dataSets from initialLocus
|
|
130
|
+
|
|
68
131
|
this.debugId = options.debugId;
|
|
69
132
|
this.webexRequest = options.webexRequest;
|
|
70
133
|
this.locusInfoUpdateCallback = options.locusInfoUpdateCallback;
|
|
71
|
-
this.
|
|
134
|
+
this.excludedDataSets = options.excludedDataSets || [];
|
|
135
|
+
this.visibleDataSetsUrl = locus === null || locus === void 0 ? void 0 : (_locus$links = locus.links) === null || _locus$links === void 0 ? void 0 : (_locus$links$resource = _locus$links.resources) === null || _locus$links$resource === void 0 ? void 0 : (_locus$links$resource2 = _locus$links$resource.visibleDataSets) === null || _locus$links$resource2 === void 0 ? void 0 : _locus$links$resource2.url;
|
|
136
|
+
this.setVisibleDataSets(((_options$metadata = options.metadata) === null || _options$metadata === void 0 ? void 0 : _options$metadata.visibleDataSets) || [], dataSets);
|
|
137
|
+
this.state = 'active';
|
|
138
|
+
if (((_options$metadata2 = options.metadata) === null || _options$metadata2 === void 0 ? void 0 : (_options$metadata2$vi = _options$metadata2.visibleDataSets) === null || _options$metadata2$vi === void 0 ? void 0 : _options$metadata2$vi.length) === 0) {
|
|
139
|
+
_loggerProxy.default.logger.warn("HashTreeParser#constructor --> ".concat(this.debugId, " No visibleDataSets found in Metadata"));
|
|
140
|
+
}
|
|
141
|
+
// object mapping dataset names to arrays of leaf data
|
|
142
|
+
var leafData = this.analyzeLocusHtMeta(locus);
|
|
143
|
+
if (options.metadata) {
|
|
144
|
+
// add also the metadata that's outside of locus object itself
|
|
145
|
+
this.analyzeMetadata(leafData, options.metadata);
|
|
146
|
+
}
|
|
147
|
+
_loggerProxy.default.logger.info("HashTreeParser#constructor --> ".concat(this.debugId, " creating HashTreeParser for datasets: ").concat((0, _stringify.default)(dataSets.map(function (ds) {
|
|
148
|
+
return ds.name;
|
|
149
|
+
})), " with visible datasets: ").concat((0, _stringify.default)(this.visibleDataSets.map(function (vds) {
|
|
150
|
+
return vds.name;
|
|
151
|
+
}))));
|
|
152
|
+
var _iterator = _createForOfIteratorHelper(dataSets),
|
|
153
|
+
_step;
|
|
154
|
+
try {
|
|
155
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
156
|
+
var dataSet = _step.value;
|
|
157
|
+
var name = dataSet.name,
|
|
158
|
+
leafCount = dataSet.leafCount;
|
|
159
|
+
this.dataSets[name] = _objectSpread(_objectSpread({}, dataSet), {}, {
|
|
160
|
+
hashTree: this.isVisibleDataSet(name) ? new _hashTree.default(leafData[name] || [], leafCount) : undefined
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
} catch (err) {
|
|
164
|
+
_iterator.e(err);
|
|
165
|
+
} finally {
|
|
166
|
+
_iterator.f();
|
|
167
|
+
}
|
|
72
168
|
}
|
|
73
169
|
|
|
74
170
|
/**
|
|
75
|
-
*
|
|
171
|
+
* Sets the visible data sets list for the HashTreeParser. This method should be called only at the start, to initialize
|
|
172
|
+
* the visible data sets, before any message processsing, so for example from the constructor or when resuming the parser.
|
|
76
173
|
*
|
|
77
|
-
* @param {
|
|
78
|
-
* @
|
|
174
|
+
* @param {Array<VisibleDataSetInfo>} visibleDataSets - The visible data sets to set
|
|
175
|
+
* @param {Array<DataSet>} dataSets - The "dataSets" list from Locus (yes, Locus sends visibleDataSets and dataSets as separate lists and they can differ)
|
|
176
|
+
* @returns {void}
|
|
79
177
|
*/
|
|
80
178
|
return (0, _createClass2.default)(HashTreeParser, [{
|
|
81
|
-
key: "
|
|
179
|
+
key: "setVisibleDataSets",
|
|
180
|
+
value: function setVisibleDataSets(visibleDataSets, dataSets) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
this.visibleDataSets = (0, _lodash.cloneDeep)(visibleDataSets).filter(function (vds) {
|
|
183
|
+
return (
|
|
184
|
+
// exclude data sets we will never care about
|
|
185
|
+
!_this.isExcludedDataSet(vds.name) &&
|
|
186
|
+
// and make sure that visibleDataSets list is consistent with dataSets list
|
|
187
|
+
dataSets.some(function (ds) {
|
|
188
|
+
return ds.name === vds.name;
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Checks if the given data set name is in the list of visible data sets
|
|
196
|
+
* @param {string} dataSetName data set name to check
|
|
197
|
+
* @returns {Boolean} True if the data set is visible, false otherwise
|
|
198
|
+
*/
|
|
199
|
+
}, {
|
|
200
|
+
key: "isVisibleDataSet",
|
|
201
|
+
value: function isVisibleDataSet(dataSetName) {
|
|
202
|
+
return this.visibleDataSets.some(function (vds) {
|
|
203
|
+
return vds.name === dataSetName;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Checks if the given data set name is in the excluded list
|
|
209
|
+
* @param {string} dataSetName data set name to check
|
|
210
|
+
* @returns {boolean} True if the data set is excluded, false otherwise
|
|
211
|
+
*/
|
|
212
|
+
}, {
|
|
213
|
+
key: "isExcludedDataSet",
|
|
214
|
+
value: function isExcludedDataSet(dataSetName) {
|
|
215
|
+
return this.excludedDataSets.some(function (name) {
|
|
216
|
+
return name === dataSetName;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Adds a data set to the visible data sets list, unless it is in the excluded list.
|
|
222
|
+
* @param {VisibleDataSetInfo} dataSetInfo data set info to add
|
|
223
|
+
* @returns {boolean} True if the data set was added, false if it was excluded
|
|
224
|
+
*/
|
|
225
|
+
}, {
|
|
226
|
+
key: "addToVisibleDataSetsList",
|
|
227
|
+
value: function addToVisibleDataSetsList(dataSetInfo) {
|
|
228
|
+
if (this.isExcludedDataSet(dataSetInfo.name)) {
|
|
229
|
+
_loggerProxy.default.logger.info("HashTreeParser#addToVisibleDataSetsList --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" is in the excluded list, ignoring"));
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
this.visibleDataSets.push(dataSetInfo);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Initializes a new visible data set by creating a hash tree for it, adding it to all the internal structures,
|
|
238
|
+
* and sending an initial sync request to Locus with empty leaf data - that will trigger Locus to gives us all the data
|
|
239
|
+
* from that dataset (in the response or via messages).
|
|
240
|
+
*
|
|
241
|
+
* @param {VisibleDataSetInfo} visibleDataSetInfo Information about the new visible data set
|
|
242
|
+
* @param {DataSet} dataSetInfo The new data set to be added
|
|
243
|
+
* @returns {Promise}
|
|
244
|
+
*/
|
|
245
|
+
}, {
|
|
246
|
+
key: "initializeNewVisibleDataSet",
|
|
82
247
|
value: (function () {
|
|
83
|
-
var
|
|
248
|
+
var _initializeNewVisibleDataSet = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(visibleDataSetInfo, dataSetInfo) {
|
|
249
|
+
var hashTree;
|
|
84
250
|
return _regenerator.default.wrap(function (_context) {
|
|
85
251
|
while (1) switch (_context.prev = _context.next) {
|
|
86
252
|
case 0:
|
|
253
|
+
if (!this.isVisibleDataSet(dataSetInfo.name)) {
|
|
254
|
+
_context.next = 1;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" already exists, skipping init"));
|
|
258
|
+
return _context.abrupt("return");
|
|
259
|
+
case 1:
|
|
260
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Adding visible data set \"").concat(dataSetInfo.name, "\""));
|
|
261
|
+
if (this.addToVisibleDataSetsList(visibleDataSetInfo)) {
|
|
262
|
+
_context.next = 2;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
return _context.abrupt("return");
|
|
266
|
+
case 2:
|
|
267
|
+
hashTree = new _hashTree.default([], dataSetInfo.leafCount);
|
|
268
|
+
this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
|
|
269
|
+
hashTree: hashTree
|
|
270
|
+
});
|
|
271
|
+
this.enqueueSyncForDataset(dataSetInfo.name, 'new visible data set initialization', true);
|
|
272
|
+
_context.next = 3;
|
|
273
|
+
return this.syncQueueProcessingPromise;
|
|
274
|
+
case 3:
|
|
87
275
|
case "end":
|
|
88
276
|
return _context.stop();
|
|
89
277
|
}
|
|
90
|
-
}, _callee);
|
|
278
|
+
}, _callee, this);
|
|
91
279
|
}));
|
|
92
|
-
function
|
|
280
|
+
function initializeNewVisibleDataSet(_x, _x2) {
|
|
281
|
+
return _initializeNewVisibleDataSet.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
return initializeNewVisibleDataSet;
|
|
284
|
+
}()
|
|
285
|
+
/**
|
|
286
|
+
* Queries Locus for all up-to-date information about all visible data sets
|
|
287
|
+
*
|
|
288
|
+
* @returns {Promise}
|
|
289
|
+
*/
|
|
290
|
+
)
|
|
291
|
+
}, {
|
|
292
|
+
key: "getAllVisibleDataSetsFromLocus",
|
|
293
|
+
value: function getAllVisibleDataSetsFromLocus() {
|
|
294
|
+
var _this2 = this;
|
|
295
|
+
if (!this.visibleDataSetsUrl) {
|
|
296
|
+
_loggerProxy.default.logger.warn("HashTreeParser#getAllVisibleDataSetsFromLocus --> ".concat(this.debugId, " No visibleDataSetsUrl, cannot get data sets information"));
|
|
297
|
+
return _promise.default.resolve([]);
|
|
298
|
+
}
|
|
299
|
+
return this.webexRequest({
|
|
300
|
+
method: _constants2.HTTP_VERBS.GET,
|
|
301
|
+
uri: this.visibleDataSetsUrl
|
|
302
|
+
}).then(function (response) {
|
|
303
|
+
return response.body.dataSets;
|
|
304
|
+
}).catch(function (error) {
|
|
305
|
+
_this2.checkForSentinelHttpResponse(error);
|
|
306
|
+
throw error;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Initializes the hash tree parser from a message received from Locus.
|
|
312
|
+
*
|
|
313
|
+
* @param {HashTreeMessage} message - initial hash tree message received from Locus
|
|
314
|
+
* @returns {Promise}
|
|
315
|
+
*/
|
|
316
|
+
}, {
|
|
317
|
+
key: "initializeFromMessage",
|
|
318
|
+
value: (function () {
|
|
319
|
+
var _initializeFromMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(message) {
|
|
320
|
+
var visibleDataSets;
|
|
321
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
322
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
323
|
+
case 0:
|
|
324
|
+
this.visibleDataSetsUrl = message.visibleDataSetsUrl;
|
|
325
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeFromMessage --> ".concat(this.debugId, " visibleDataSetsUrl=").concat(this.visibleDataSetsUrl));
|
|
326
|
+
_context2.next = 1;
|
|
327
|
+
return this.getAllVisibleDataSetsFromLocus();
|
|
328
|
+
case 1:
|
|
329
|
+
visibleDataSets = _context2.sent;
|
|
330
|
+
_context2.next = 2;
|
|
331
|
+
return this.initializeDataSets(visibleDataSets, 'initialization from message');
|
|
332
|
+
case 2:
|
|
333
|
+
case "end":
|
|
334
|
+
return _context2.stop();
|
|
335
|
+
}
|
|
336
|
+
}, _callee2, this);
|
|
337
|
+
}));
|
|
338
|
+
function initializeFromMessage(_x3) {
|
|
93
339
|
return _initializeFromMessage.apply(this, arguments);
|
|
94
340
|
}
|
|
95
341
|
return initializeFromMessage;
|
|
@@ -107,20 +353,386 @@ var HashTreeParser = /*#__PURE__*/function () {
|
|
|
107
353
|
}, {
|
|
108
354
|
key: "initializeFromGetLociResponse",
|
|
109
355
|
value: (function () {
|
|
110
|
-
var _initializeFromGetLociResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
111
|
-
|
|
112
|
-
|
|
356
|
+
var _initializeFromGetLociResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(locus) {
|
|
357
|
+
var _locus$links2, _locus$links2$resourc, _locus$links2$resourc2;
|
|
358
|
+
var visibleDataSets;
|
|
359
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
360
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
113
361
|
case 0:
|
|
362
|
+
if (locus !== null && locus !== void 0 && (_locus$links2 = locus.links) !== null && _locus$links2 !== void 0 && (_locus$links2$resourc = _locus$links2.resources) !== null && _locus$links2$resourc !== void 0 && (_locus$links2$resourc2 = _locus$links2$resourc.visibleDataSets) !== null && _locus$links2$resourc2 !== void 0 && _locus$links2$resourc2.url) {
|
|
363
|
+
_context3.next = 1;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
_loggerProxy.default.logger.warn("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " missing visibleDataSets url in GET Loci response, cannot initialize hash trees"));
|
|
367
|
+
return _context3.abrupt("return");
|
|
368
|
+
case 1:
|
|
369
|
+
this.visibleDataSetsUrl = locus.links.resources.visibleDataSets.url;
|
|
370
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " visibleDataSets url: ").concat(this.visibleDataSetsUrl));
|
|
371
|
+
_context3.next = 2;
|
|
372
|
+
return this.getAllVisibleDataSetsFromLocus();
|
|
373
|
+
case 2:
|
|
374
|
+
visibleDataSets = _context3.sent;
|
|
375
|
+
_context3.next = 3;
|
|
376
|
+
return this.initializeDataSets(visibleDataSets, 'initialization from GET /loci response');
|
|
377
|
+
case 3:
|
|
114
378
|
case "end":
|
|
115
|
-
return
|
|
379
|
+
return _context3.stop();
|
|
116
380
|
}
|
|
117
|
-
},
|
|
381
|
+
}, _callee3, this);
|
|
118
382
|
}));
|
|
119
|
-
function initializeFromGetLociResponse(
|
|
383
|
+
function initializeFromGetLociResponse(_x4) {
|
|
120
384
|
return _initializeFromGetLociResponse.apply(this, arguments);
|
|
121
385
|
}
|
|
122
386
|
return initializeFromGetLociResponse;
|
|
123
387
|
}()
|
|
388
|
+
/**
|
|
389
|
+
* Initializes data sets by doing an initialization sync on each visible data set that doesn't have a hash tree yet.
|
|
390
|
+
*
|
|
391
|
+
* @param {DataSet[]} visibleDataSets Array of visible DataSet objects to initialize
|
|
392
|
+
* @param {string} debugText Text to include in logs for debugging purposes
|
|
393
|
+
* @returns {Promise}
|
|
394
|
+
*/
|
|
395
|
+
)
|
|
396
|
+
}, {
|
|
397
|
+
key: "initializeDataSets",
|
|
398
|
+
value: (function () {
|
|
399
|
+
var _initializeDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(visibleDataSets, debugText) {
|
|
400
|
+
var _iterator2, _step2, dataSet, name, leafCount, url, _t;
|
|
401
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
402
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
403
|
+
case 0:
|
|
404
|
+
if (!(this.state === 'stopped')) {
|
|
405
|
+
_context4.next = 1;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
return _context4.abrupt("return");
|
|
409
|
+
case 1:
|
|
410
|
+
_iterator2 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(visibleDataSets, _constants3.DATA_SET_INIT_PRIORITY));
|
|
411
|
+
_context4.prev = 2;
|
|
412
|
+
_iterator2.s();
|
|
413
|
+
case 3:
|
|
414
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
415
|
+
_context4.next = 6;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
dataSet = _step2.value;
|
|
419
|
+
name = dataSet.name, leafCount = dataSet.leafCount, url = dataSet.url;
|
|
420
|
+
if (!this.dataSets[name]) {
|
|
421
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " initializing dataset \"").concat(name, "\" (").concat(debugText, ")"));
|
|
422
|
+
this.dataSets[name] = _objectSpread({}, dataSet);
|
|
423
|
+
} else {
|
|
424
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " dataset \"").concat(name, "\" already exists (").concat(debugText, ")"));
|
|
425
|
+
}
|
|
426
|
+
if (this.isVisibleDataSet(name)) {
|
|
427
|
+
_context4.next = 4;
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
if (this.addToVisibleDataSetsList({
|
|
431
|
+
name: name,
|
|
432
|
+
url: url
|
|
433
|
+
})) {
|
|
434
|
+
_context4.next = 4;
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
return _context4.abrupt("continue", 5);
|
|
438
|
+
case 4:
|
|
439
|
+
if (!this.dataSets[name].hashTree) {
|
|
440
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " creating hash tree for visible dataset \"").concat(name, "\" (").concat(debugText, ")"));
|
|
441
|
+
this.dataSets[name].hashTree = new _hashTree.default([], leafCount);
|
|
442
|
+
this.enqueueSyncForDataset(name, "initialization sync for ".concat(debugText), true);
|
|
443
|
+
}
|
|
444
|
+
case 5:
|
|
445
|
+
_context4.next = 3;
|
|
446
|
+
break;
|
|
447
|
+
case 6:
|
|
448
|
+
_context4.next = 8;
|
|
449
|
+
break;
|
|
450
|
+
case 7:
|
|
451
|
+
_context4.prev = 7;
|
|
452
|
+
_t = _context4["catch"](2);
|
|
453
|
+
_iterator2.e(_t);
|
|
454
|
+
case 8:
|
|
455
|
+
_context4.prev = 8;
|
|
456
|
+
_iterator2.f();
|
|
457
|
+
return _context4.finish(8);
|
|
458
|
+
case 9:
|
|
459
|
+
_context4.next = 10;
|
|
460
|
+
return this.syncQueueProcessingPromise;
|
|
461
|
+
case 10:
|
|
462
|
+
case "end":
|
|
463
|
+
return _context4.stop();
|
|
464
|
+
}
|
|
465
|
+
}, _callee4, this, [[2, 7, 8, 9]]);
|
|
466
|
+
}));
|
|
467
|
+
function initializeDataSets(_x5, _x6) {
|
|
468
|
+
return _initializeDataSets.apply(this, arguments);
|
|
469
|
+
}
|
|
470
|
+
return initializeDataSets;
|
|
471
|
+
}()
|
|
472
|
+
/**
|
|
473
|
+
* Each dataset exists at a different place in the dto
|
|
474
|
+
* iterate recursively over the locus and if it has a htMeta key,
|
|
475
|
+
* create an object with the type, id and version and add it to the appropriate leafData array
|
|
476
|
+
*
|
|
477
|
+
* @param {any} locus - The current part of the locus being processed
|
|
478
|
+
* @param {Object} [options]
|
|
479
|
+
* @param {boolean} [options.copyData=false] - Whether to copy the data for each leaf into returned result
|
|
480
|
+
* @returns {any} - An object mapping dataset names to arrays of leaf data
|
|
481
|
+
*/
|
|
482
|
+
)
|
|
483
|
+
}, {
|
|
484
|
+
key: "analyzeLocusHtMeta",
|
|
485
|
+
value: function analyzeLocusHtMeta(locus, options) {
|
|
486
|
+
var _ref = options || {},
|
|
487
|
+
_ref$copyData = _ref.copyData,
|
|
488
|
+
copyData = _ref$copyData === void 0 ? false : _ref$copyData;
|
|
489
|
+
// object mapping dataset names to arrays of leaf data
|
|
490
|
+
var leafInfo = {};
|
|
491
|
+
var _findAndStoreMetaData = function findAndStoreMetaData(currentLocusPart, currentLocusPartName) {
|
|
492
|
+
if ((0, _typeof2.default)(currentLocusPart) !== 'object' || currentLocusPart === null) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (currentLocusPart.htMeta && currentLocusPart.htMeta.dataSetNames) {
|
|
496
|
+
var _currentLocusPart$htM = currentLocusPart.htMeta.elementId,
|
|
497
|
+
type = _currentLocusPart$htM.type,
|
|
498
|
+
id = _currentLocusPart$htM.id,
|
|
499
|
+
version = _currentLocusPart$htM.version;
|
|
500
|
+
var dataSetNames = currentLocusPart.htMeta.dataSetNames;
|
|
501
|
+
var newLeafInfo = {
|
|
502
|
+
type: type,
|
|
503
|
+
id: id,
|
|
504
|
+
version: version
|
|
505
|
+
};
|
|
506
|
+
if (copyData) {
|
|
507
|
+
if (type.toLowerCase() === _types.ObjectType.control) {
|
|
508
|
+
// control entries require special handling, because they are signalled by Locus
|
|
509
|
+
// differently when coming in messages vs API responses
|
|
510
|
+
newLeafInfo.data = (0, _defineProperty2.default)({}, currentLocusPartName, (0, _lodash.cloneDeep)(currentLocusPart));
|
|
511
|
+
} else {
|
|
512
|
+
newLeafInfo.data = (0, _lodash.cloneDeep)(currentLocusPart);
|
|
513
|
+
|
|
514
|
+
// remove any nested other objects that have their own htMeta
|
|
515
|
+
(0, _utils.deleteNestedObjectsWithHtMeta)(newLeafInfo.data);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
var _iterator3 = _createForOfIteratorHelper(dataSetNames),
|
|
519
|
+
_step3;
|
|
520
|
+
try {
|
|
521
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
522
|
+
var dataSetName = _step3.value;
|
|
523
|
+
if (!leafInfo[dataSetName]) {
|
|
524
|
+
leafInfo[dataSetName] = [];
|
|
525
|
+
}
|
|
526
|
+
leafInfo[dataSetName].push(newLeafInfo);
|
|
527
|
+
}
|
|
528
|
+
} catch (err) {
|
|
529
|
+
_iterator3.e(err);
|
|
530
|
+
} finally {
|
|
531
|
+
_iterator3.f();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if ((0, _isArray.default)(currentLocusPart)) {
|
|
535
|
+
var _iterator4 = _createForOfIteratorHelper(currentLocusPart.entries()),
|
|
536
|
+
_step4;
|
|
537
|
+
try {
|
|
538
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
539
|
+
var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
|
|
540
|
+
index = _step4$value[0],
|
|
541
|
+
item = _step4$value[1];
|
|
542
|
+
_findAndStoreMetaData(item, index.toString());
|
|
543
|
+
}
|
|
544
|
+
} catch (err) {
|
|
545
|
+
_iterator4.e(err);
|
|
546
|
+
} finally {
|
|
547
|
+
_iterator4.f();
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
for (var _i = 0, _Object$keys = (0, _keys.default)(currentLocusPart); _i < _Object$keys.length; _i++) {
|
|
551
|
+
var key = _Object$keys[_i];
|
|
552
|
+
if (Object.prototype.hasOwnProperty.call(currentLocusPart, key)) {
|
|
553
|
+
_findAndStoreMetaData(currentLocusPart[key], key);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
_findAndStoreMetaData(locus, 'locus');
|
|
559
|
+
return leafInfo;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Analyzes the Metadata object that is sent outside of Locus object, and appends its data to passed in leafInfo
|
|
564
|
+
* structure.
|
|
565
|
+
*
|
|
566
|
+
* @param {Record<string, LeafInfo[]>} leafInfo the structure to which the Metadata info will be appended
|
|
567
|
+
* @param {Metadata} metadata Metadata object
|
|
568
|
+
* @returns {void}
|
|
569
|
+
*/
|
|
570
|
+
}, {
|
|
571
|
+
key: "analyzeMetadata",
|
|
572
|
+
value: function analyzeMetadata(leafInfo, metadata) {
|
|
573
|
+
var _htMeta$dataSetNames;
|
|
574
|
+
var htMeta = metadata.htMeta;
|
|
575
|
+
if ((htMeta === null || htMeta === void 0 ? void 0 : (_htMeta$dataSetNames = htMeta.dataSetNames) === null || _htMeta$dataSetNames === void 0 ? void 0 : _htMeta$dataSetNames.length) === 1 && htMeta.dataSetNames[0].toLowerCase() === MetadataDataSetName) {
|
|
576
|
+
var _metadata$htMeta$elem = metadata.htMeta.elementId,
|
|
577
|
+
type = _metadata$htMeta$elem.type,
|
|
578
|
+
id = _metadata$htMeta$elem.id,
|
|
579
|
+
version = _metadata$htMeta$elem.version;
|
|
580
|
+
var dataSetName = htMeta.dataSetNames[0];
|
|
581
|
+
if (!leafInfo[dataSetName]) {
|
|
582
|
+
leafInfo[dataSetName] = [];
|
|
583
|
+
}
|
|
584
|
+
leafInfo[dataSetName].push({
|
|
585
|
+
type: type,
|
|
586
|
+
id: id,
|
|
587
|
+
version: version
|
|
588
|
+
});
|
|
589
|
+
} else {
|
|
590
|
+
throw new Error("".concat(this.debugId, " Metadata htMeta has unexpected dataSetNames: ").concat(htMeta && htMeta.dataSetNames.join(',')));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Checks if the provided hash tree message indicates the end of the meeting and that there won't be any more updates.
|
|
596
|
+
*
|
|
597
|
+
* @param {HashTreeMessage} message - The hash tree message to check
|
|
598
|
+
* @returns {boolean} - Returns true if the message indicates the end of the meeting, false otherwise
|
|
599
|
+
*/
|
|
600
|
+
}, {
|
|
601
|
+
key: "isEndMessage",
|
|
602
|
+
value: function isEndMessage(message) {
|
|
603
|
+
var _this3 = this;
|
|
604
|
+
return message.dataSets.some(function (dataSet) {
|
|
605
|
+
if (dataSet.leafCount === 1 && dataSet.root === _constants3.EMPTY_HASH && (!_this3.dataSets[dataSet.name] || _this3.dataSets[dataSet.name].version < dataSet.version) && PossibleSentinelMessageDataSetNames.includes(dataSet.name.toLowerCase())) {
|
|
606
|
+
// this is a special way for Locus to indicate that this meeting has ended
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
return false;
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Handles the root hash heartbeat message
|
|
615
|
+
*
|
|
616
|
+
* @param {RootHashMessage} message - The root hash heartbeat message
|
|
617
|
+
* @returns {void}
|
|
618
|
+
*/
|
|
619
|
+
}, {
|
|
620
|
+
key: "handleRootHashHeartBeatMessage",
|
|
621
|
+
value: function handleRootHashHeartBeatMessage(message) {
|
|
622
|
+
var _this4 = this;
|
|
623
|
+
var dataSets = message.dataSets;
|
|
624
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleRootHashMessage --> ".concat(this.debugId, " Received heartbeat root hash message with data sets: ").concat((0, _stringify.default)(dataSets.map(function (_ref2) {
|
|
625
|
+
var name = _ref2.name,
|
|
626
|
+
root = _ref2.root,
|
|
627
|
+
leafCount = _ref2.leafCount,
|
|
628
|
+
version = _ref2.version;
|
|
629
|
+
return {
|
|
630
|
+
name: name,
|
|
631
|
+
root: root,
|
|
632
|
+
leafCount: leafCount,
|
|
633
|
+
version: version
|
|
634
|
+
};
|
|
635
|
+
}))));
|
|
636
|
+
this.cancelPendingSyncsForDataSets(dataSets.map(function (ds) {
|
|
637
|
+
return ds.name;
|
|
638
|
+
}));
|
|
639
|
+
dataSets.forEach(function (dataSet) {
|
|
640
|
+
_this4.updateDataSetInfo(dataSet);
|
|
641
|
+
_this4.runSyncAlgorithm(dataSet);
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Handles known errors that can happen during syncs
|
|
647
|
+
*
|
|
648
|
+
* @param {any} error - The error to handle
|
|
649
|
+
* @returns {boolean} true if the error was recognized and handled, false otherwise
|
|
650
|
+
*/
|
|
651
|
+
}, {
|
|
652
|
+
key: "handleSyncErrors",
|
|
653
|
+
value: function handleSyncErrors(error) {
|
|
654
|
+
if (error instanceof MeetingEndedError) {
|
|
655
|
+
this.callLocusInfoUpdateCallback({
|
|
656
|
+
updateType: LocusInfoUpdateType.MEETING_ENDED
|
|
657
|
+
});
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
if (error instanceof LocusNotFoundError) {
|
|
661
|
+
this.callLocusInfoUpdateCallback({
|
|
662
|
+
updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND
|
|
663
|
+
});
|
|
664
|
+
this.stop();
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Asynchronously initializes new visible data sets
|
|
672
|
+
*
|
|
673
|
+
* @param {VisibleDataSetInfo[]} dataSetsRequiringInitialization list of datasets to initialize
|
|
674
|
+
* @returns {void}
|
|
675
|
+
*/
|
|
676
|
+
}, {
|
|
677
|
+
key: "queueInitForNewVisibleDataSets",
|
|
678
|
+
value: function queueInitForNewVisibleDataSets(dataSetsRequiringInitialization) {
|
|
679
|
+
var _this5 = this;
|
|
680
|
+
_loggerProxy.default.logger.info("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(this.debugId, " queuing initialization of new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
|
|
681
|
+
return ds.name;
|
|
682
|
+
}).join(', ')));
|
|
683
|
+
queueMicrotask(function () {
|
|
684
|
+
_this5.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch(function (error) {
|
|
685
|
+
if (!_this5.handleSyncErrors(error)) {
|
|
686
|
+
_loggerProxy.default.logger.warn("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(_this5.debugId, " error while initializing new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
|
|
687
|
+
return ds.name;
|
|
688
|
+
}).join(', '), ": "), error);
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Handles updates to Metadata object that we receive from Locus via other means than messages. Right now
|
|
696
|
+
* that means only in the API response alongside locus object.
|
|
697
|
+
*
|
|
698
|
+
* @param {Metadata} metadata received in Locus update other than a message (for example in an API response)
|
|
699
|
+
* @param {HashTreeObject[]} updatedObjects a list of updated hash tree objects to which any updates resulting from new Metadata will be added
|
|
700
|
+
* @returns {void}
|
|
701
|
+
*/
|
|
702
|
+
}, {
|
|
703
|
+
key: "handleMetadataUpdate",
|
|
704
|
+
value: function handleMetadataUpdate(metadata, updatedObjects) {
|
|
705
|
+
var _this$dataSets$Metada;
|
|
706
|
+
var dataSetsRequiringInitialization = [];
|
|
707
|
+
|
|
708
|
+
// current assumption based on Locus docs is that Metadata object lives always in "self" data set
|
|
709
|
+
var hashTree = (_this$dataSets$Metada = this.dataSets[MetadataDataSetName]) === null || _this$dataSets$Metada === void 0 ? void 0 : _this$dataSets$Metada.hashTree;
|
|
710
|
+
if (!hashTree) {
|
|
711
|
+
_loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received Metadata object but no hash tree for \"").concat(MetadataDataSetName, "\" data set exists"));
|
|
712
|
+
} else {
|
|
713
|
+
var metadataUpdated = hashTree.putItem(metadata.htMeta.elementId);
|
|
714
|
+
if (metadataUpdated) {
|
|
715
|
+
// metadata in Locus API response is in a slightly different format than the objects in messages, so need to adapt it
|
|
716
|
+
var metadataObject = {
|
|
717
|
+
htMeta: metadata.htMeta,
|
|
718
|
+
data: metadata
|
|
719
|
+
};
|
|
720
|
+
updatedObjects.push(metadataObject);
|
|
721
|
+
var _this$checkForVisible = this.checkForVisibleDataSetChanges([metadataObject]),
|
|
722
|
+
changeDetected = _this$checkForVisible.changeDetected,
|
|
723
|
+
removedDataSets = _this$checkForVisible.removedDataSets,
|
|
724
|
+
addedDataSets = _this$checkForVisible.addedDataSets;
|
|
725
|
+
if (changeDetected) {
|
|
726
|
+
dataSetsRequiringInitialization = this.processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects);
|
|
727
|
+
}
|
|
728
|
+
if (dataSetsRequiringInitialization.length > 0) {
|
|
729
|
+
// there are some data sets that we need to initialize asynchronously
|
|
730
|
+
this.queueInitForNewVisibleDataSets(dataSetsRequiringInitialization);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
124
736
|
/**
|
|
125
737
|
* This method should be called when we receive a partial locus DTO that contains dataSets and htMeta information
|
|
126
738
|
* It updates the hash trees with the new leaf data based on the received Locus
|
|
@@ -128,11 +740,509 @@ var HashTreeParser = /*#__PURE__*/function () {
|
|
|
128
740
|
* @param {Object} update - The locus update containing data sets and locus information
|
|
129
741
|
* @returns {void}
|
|
130
742
|
*/
|
|
131
|
-
)
|
|
132
743
|
}, {
|
|
133
744
|
key: "handleLocusUpdate",
|
|
134
745
|
value: function handleLocusUpdate(update) {
|
|
135
|
-
|
|
746
|
+
var _this6 = this;
|
|
747
|
+
if (this.state === 'stopped') {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
var dataSets = update.dataSets,
|
|
751
|
+
locus = update.locus,
|
|
752
|
+
metadata = update.metadata;
|
|
753
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received update with dataSets=").concat(dataSets === null || dataSets === void 0 ? void 0 : dataSets.map(function (ds) {
|
|
754
|
+
return ds.name;
|
|
755
|
+
}).join(','), " metadata=").concat(metadata ? 'yes' : 'no'));
|
|
756
|
+
if (!dataSets) {
|
|
757
|
+
// this happens for example when we handle GET /loci response
|
|
758
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received hash tree update without dataSets"));
|
|
759
|
+
} else {
|
|
760
|
+
var _iterator5 = _createForOfIteratorHelper(dataSets),
|
|
761
|
+
_step5;
|
|
762
|
+
try {
|
|
763
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
764
|
+
var dataSet = _step5.value;
|
|
765
|
+
this.updateDataSetInfo(dataSet);
|
|
766
|
+
}
|
|
767
|
+
} catch (err) {
|
|
768
|
+
_iterator5.e(err);
|
|
769
|
+
} finally {
|
|
770
|
+
_iterator5.f();
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
var updatedObjects = [];
|
|
774
|
+
|
|
775
|
+
// first, analyze the locus object to extract the hash tree objects' htMeta and data from it
|
|
776
|
+
var leafInfo = this.analyzeLocusHtMeta(locus, {
|
|
777
|
+
copyData: true
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
// if we got metadata, process it (currently that means only potential visible data set list changes)
|
|
781
|
+
if (metadata) {
|
|
782
|
+
this.handleMetadataUpdate(metadata, updatedObjects);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// then process the data in hash trees, if it is a new version, then add it to updatedObjects
|
|
786
|
+
(0, _keys.default)(leafInfo).forEach(function (dataSetName) {
|
|
787
|
+
if (_this6.dataSets[dataSetName]) {
|
|
788
|
+
if (_this6.dataSets[dataSetName].hashTree) {
|
|
789
|
+
var appliedChangesList = _this6.dataSets[dataSetName].hashTree.putItems(leafInfo[dataSetName].map(function (leaf) {
|
|
790
|
+
return {
|
|
791
|
+
id: leaf.id,
|
|
792
|
+
type: leaf.type,
|
|
793
|
+
version: leaf.version
|
|
794
|
+
};
|
|
795
|
+
}));
|
|
796
|
+
(0, _lodash.zip)(appliedChangesList, leafInfo[dataSetName]).forEach(function (_ref3) {
|
|
797
|
+
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
798
|
+
changeApplied = _ref4[0],
|
|
799
|
+
leaf = _ref4[1];
|
|
800
|
+
if (changeApplied) {
|
|
801
|
+
updatedObjects.push({
|
|
802
|
+
htMeta: {
|
|
803
|
+
elementId: {
|
|
804
|
+
type: leaf.type,
|
|
805
|
+
id: leaf.id,
|
|
806
|
+
version: leaf.version
|
|
807
|
+
},
|
|
808
|
+
dataSetNames: [dataSetName]
|
|
809
|
+
},
|
|
810
|
+
data: leaf.data
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
} else {
|
|
815
|
+
// no hash tree means that the data set is not visible
|
|
816
|
+
_loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this6.debugId, " received leaf data for data set \"").concat(dataSetName, "\" that has no hash tree created, ignoring"));
|
|
817
|
+
}
|
|
818
|
+
} else {
|
|
819
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(_this6.debugId, " received leaf data for unknown data set \"").concat(dataSetName, "\", ignoring"));
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
if (updatedObjects.length === 0) {
|
|
823
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " No objects updated as a result of received API response"));
|
|
824
|
+
} else {
|
|
825
|
+
this.callLocusInfoUpdateCallback({
|
|
826
|
+
updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
|
|
827
|
+
updatedObjects: updatedObjects
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Updates the internal data set information based on the received data set from Locus.
|
|
834
|
+
*
|
|
835
|
+
* @param {DataSet} receivedDataSet - The latest data set information received from Locus to update the internal state.
|
|
836
|
+
* @returns {void}
|
|
837
|
+
*/
|
|
838
|
+
}, {
|
|
839
|
+
key: "updateDataSetInfo",
|
|
840
|
+
value: function updateDataSetInfo(receivedDataSet) {
|
|
841
|
+
if (!this.dataSets[receivedDataSet.name]) {
|
|
842
|
+
this.dataSets[receivedDataSet.name] = _objectSpread({}, receivedDataSet);
|
|
843
|
+
_loggerProxy.default.logger.info("HashTreeParser#updateDataSetInfo --> ".concat(this.debugId, " created entry for \"").concat(receivedDataSet.name, "\" dataset: version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
// update our version of the dataSet
|
|
847
|
+
if (this.dataSets[receivedDataSet.name].version < receivedDataSet.version) {
|
|
848
|
+
this.dataSets[receivedDataSet.name].version = receivedDataSet.version;
|
|
849
|
+
this.dataSets[receivedDataSet.name].root = receivedDataSet.root;
|
|
850
|
+
this.dataSets[receivedDataSet.name].idleMs = receivedDataSet.idleMs;
|
|
851
|
+
this.dataSets[receivedDataSet.name].backoff = {
|
|
852
|
+
maxMs: receivedDataSet.backoff.maxMs,
|
|
853
|
+
exponent: receivedDataSet.backoff.exponent
|
|
854
|
+
};
|
|
855
|
+
this.dataSets[receivedDataSet.name].heartbeatIntervalMs = receivedDataSet.heartbeatIntervalMs;
|
|
856
|
+
_loggerProxy.default.logger.info("HashTreeParser#updateDataSetInfo --> ".concat(this.debugId, " updated \"").concat(receivedDataSet.name, "\" dataset to version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Updates the leaf count for a data set, resizing its hash tree accordingly.
|
|
862
|
+
*
|
|
863
|
+
* @param {InternalDataSet} dataSet - The data set to update
|
|
864
|
+
* @param {number} newLeafCount - The new leaf count
|
|
865
|
+
* @returns {void}
|
|
866
|
+
*/
|
|
867
|
+
}, {
|
|
868
|
+
key: "updateDataSetLeafCount",
|
|
869
|
+
value: function updateDataSetLeafCount(dataSet, newLeafCount) {
|
|
870
|
+
var _dataSet$hashTree;
|
|
871
|
+
(_dataSet$hashTree = dataSet.hashTree) === null || _dataSet$hashTree === void 0 ? void 0 : _dataSet$hashTree.resize(newLeafCount);
|
|
872
|
+
dataSet.leafCount = newLeafCount;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Checks for changes in the visible data sets based on the updated objects.
|
|
877
|
+
* @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects.
|
|
878
|
+
* @returns {Object} An object containing the removed and added visible data sets.
|
|
879
|
+
*/
|
|
880
|
+
}, {
|
|
881
|
+
key: "checkForVisibleDataSetChanges",
|
|
882
|
+
value: function checkForVisibleDataSetChanges(updatedObjects) {
|
|
883
|
+
var _this7 = this;
|
|
884
|
+
var removedDataSets = [];
|
|
885
|
+
var addedDataSets = [];
|
|
886
|
+
|
|
887
|
+
// visibleDataSets can only be changed by Metadata object updates
|
|
888
|
+
updatedObjects.forEach(function (object) {
|
|
889
|
+
var _object$data;
|
|
890
|
+
if ((0, _utils.isMetadata)(object) && (_object$data = object.data) !== null && _object$data !== void 0 && _object$data.visibleDataSets) {
|
|
891
|
+
var newVisibleDataSets = object.data.visibleDataSets.filter(function (vds) {
|
|
892
|
+
return !_this7.isExcludedDataSet(vds.name);
|
|
893
|
+
});
|
|
894
|
+
removedDataSets = _this7.visibleDataSets.filter(function (ds) {
|
|
895
|
+
return !newVisibleDataSets.some(function (nvs) {
|
|
896
|
+
return nvs.name === ds.name;
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
addedDataSets = newVisibleDataSets.filter(function (nvs) {
|
|
900
|
+
return _this7.visibleDataSets.every(function (ds) {
|
|
901
|
+
return ds.name !== nvs.name;
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
if (removedDataSets.length > 0 || addedDataSets.length > 0) {
|
|
905
|
+
_loggerProxy.default.logger.info("HashTreeParser#checkForVisibleDataSetChanges --> ".concat(_this7.debugId, " visible data sets change: removed: ").concat(removedDataSets.map(function (ds) {
|
|
906
|
+
return ds.name;
|
|
907
|
+
}).join(', '), ", added: ").concat(addedDataSets.map(function (ds) {
|
|
908
|
+
return ds.name;
|
|
909
|
+
}).join(', ')));
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
return {
|
|
914
|
+
changeDetected: removedDataSets.length > 0 || addedDataSets.length > 0,
|
|
915
|
+
removedDataSets: removedDataSets,
|
|
916
|
+
addedDataSets: addedDataSets
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Deletes the hash tree for the specified data set.
|
|
922
|
+
*
|
|
923
|
+
* @param {string} dataSetName name of the data set to delete
|
|
924
|
+
* @returns {void}
|
|
925
|
+
*/
|
|
926
|
+
}, {
|
|
927
|
+
key: "deleteHashTree",
|
|
928
|
+
value: function deleteHashTree(dataSetName) {
|
|
929
|
+
var _this$dataSets$dataSe;
|
|
930
|
+
this.dataSets[dataSetName].hashTree = undefined;
|
|
931
|
+
(_this$dataSets$dataSe = this.dataSets[dataSetName].syncAbortController) === null || _this$dataSets$dataSe === void 0 ? void 0 : _this$dataSets$dataSe.abort();
|
|
932
|
+
this.dataSets[dataSetName].syncAbortController = undefined;
|
|
933
|
+
|
|
934
|
+
// we also need to stop the timers as there is no hash tree anymore to sync
|
|
935
|
+
if (this.dataSets[dataSetName].timer) {
|
|
936
|
+
clearTimeout(this.dataSets[dataSetName].timer);
|
|
937
|
+
this.dataSets[dataSetName].timer = undefined;
|
|
938
|
+
}
|
|
939
|
+
if (this.dataSets[dataSetName].heartbeatWatchdogTimer) {
|
|
940
|
+
clearTimeout(this.dataSets[dataSetName].heartbeatWatchdogTimer);
|
|
941
|
+
this.dataSets[dataSetName].heartbeatWatchdogTimer = undefined;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Adds entries to the passed in updateObjects array
|
|
947
|
+
* for the changes that result from removing visible data sets and creates hash
|
|
948
|
+
* trees for the new visible data sets, but without populating the hash trees.
|
|
949
|
+
*
|
|
950
|
+
* This function is synchronous. If we are missing information about some new
|
|
951
|
+
* visible data sets and they require async initialization, the names of these data sets
|
|
952
|
+
* are returned in an array.
|
|
953
|
+
*
|
|
954
|
+
* @param {VisibleDataSetInfo[]} removedDataSets - The list of removed data sets.
|
|
955
|
+
* @param {VisibleDataSetInfo[]} addedDataSets - The list of added data sets.
|
|
956
|
+
* @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects to which changes will be added.
|
|
957
|
+
* @returns {VisibleDataSetInfo[]} list of data sets that couldn't be initialized synchronously
|
|
958
|
+
*/
|
|
959
|
+
}, {
|
|
960
|
+
key: "processVisibleDataSetChanges",
|
|
961
|
+
value: function processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects) {
|
|
962
|
+
var _this8 = this;
|
|
963
|
+
var dataSetsRequiringInitialization = [];
|
|
964
|
+
|
|
965
|
+
// if a visible data set was removed, we need to tell our client that all objects from it are removed
|
|
966
|
+
var removedObjects = [];
|
|
967
|
+
removedDataSets.forEach(function (ds) {
|
|
968
|
+
var _this8$dataSets$ds$na;
|
|
969
|
+
if ((_this8$dataSets$ds$na = _this8.dataSets[ds.name]) !== null && _this8$dataSets$ds$na !== void 0 && _this8$dataSets$ds$na.hashTree) {
|
|
970
|
+
for (var i = 0; i < _this8.dataSets[ds.name].hashTree.numLeaves; i += 1) {
|
|
971
|
+
removedObjects.push.apply(removedObjects, (0, _toConsumableArray2.default)(_this8.dataSets[ds.name].hashTree.getLeafData(i).map(function (elementId) {
|
|
972
|
+
return {
|
|
973
|
+
htMeta: {
|
|
974
|
+
elementId: elementId,
|
|
975
|
+
dataSetNames: [ds.name]
|
|
976
|
+
},
|
|
977
|
+
data: null
|
|
978
|
+
};
|
|
979
|
+
})));
|
|
980
|
+
}
|
|
981
|
+
_this8.deleteHashTree(ds.name);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
this.visibleDataSets = this.visibleDataSets.filter(function (vds) {
|
|
985
|
+
return !removedDataSets.some(function (rds) {
|
|
986
|
+
return rds.name === vds.name;
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
updatedObjects.push.apply(updatedObjects, removedObjects);
|
|
990
|
+
|
|
991
|
+
// now setup the new visible data sets
|
|
992
|
+
var _iterator6 = _createForOfIteratorHelper(addedDataSets),
|
|
993
|
+
_step6;
|
|
994
|
+
try {
|
|
995
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
996
|
+
var ds = _step6.value;
|
|
997
|
+
var dataSetInfo = this.dataSets[ds.name];
|
|
998
|
+
if (dataSetInfo) {
|
|
999
|
+
if (this.isVisibleDataSet(dataSetInfo.name)) {
|
|
1000
|
+
_loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Data set \"").concat(ds.name, "\" is already visible, skipping"));
|
|
1001
|
+
|
|
1002
|
+
// eslint-disable-next-line no-continue
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
_loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Adding visible data set \"").concat(ds.name, "\""));
|
|
1006
|
+
if (!this.addToVisibleDataSetsList(ds)) {
|
|
1007
|
+
// eslint-disable-next-line no-continue
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
var hashTree = new _hashTree.default([], dataSetInfo.leafCount);
|
|
1011
|
+
this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
|
|
1012
|
+
hashTree: hashTree
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
// this call is needed here for the edge case where we receive a message with new visible data sets
|
|
1016
|
+
// and there are no objects belonging to these data sets in the message but we already have the info about them in this.dataSets
|
|
1017
|
+
this.runSyncAlgorithm(this.dataSets[dataSetInfo.name]);
|
|
1018
|
+
} else {
|
|
1019
|
+
_loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " visible data set \"").concat(ds.name, "\" added but no info about it in our dataSets structures"));
|
|
1020
|
+
// todo: add a metric here
|
|
1021
|
+
dataSetsRequiringInitialization.push(ds);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
} catch (err) {
|
|
1025
|
+
_iterator6.e(err);
|
|
1026
|
+
} finally {
|
|
1027
|
+
_iterator6.f();
|
|
1028
|
+
}
|
|
1029
|
+
return dataSetsRequiringInitialization;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Adds entries to the passed in updateObjects array
|
|
1034
|
+
* for the changes that result from adding and removing visible data sets.
|
|
1035
|
+
*
|
|
1036
|
+
* @param {VisibleDataSetInfo[]} addedDataSets - The list of added data sets.
|
|
1037
|
+
* @returns {Promise<void>}
|
|
1038
|
+
*/
|
|
1039
|
+
}, {
|
|
1040
|
+
key: "initializeNewVisibleDataSets",
|
|
1041
|
+
value: (function () {
|
|
1042
|
+
var _initializeNewVisibleDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(addedDataSets) {
|
|
1043
|
+
var _this9 = this;
|
|
1044
|
+
var allDataSets, _iterator7, _step7, _loop, _t2;
|
|
1045
|
+
return _regenerator.default.wrap(function (_context6) {
|
|
1046
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
1047
|
+
case 0:
|
|
1048
|
+
if (!(this.state === 'stopped')) {
|
|
1049
|
+
_context6.next = 1;
|
|
1050
|
+
break;
|
|
1051
|
+
}
|
|
1052
|
+
return _context6.abrupt("return");
|
|
1053
|
+
case 1:
|
|
1054
|
+
_context6.next = 2;
|
|
1055
|
+
return this.getAllVisibleDataSetsFromLocus();
|
|
1056
|
+
case 2:
|
|
1057
|
+
allDataSets = _context6.sent;
|
|
1058
|
+
_iterator7 = _createForOfIteratorHelper((0, _utils.sortByInitPriority)(addedDataSets, _constants3.DATA_SET_INIT_PRIORITY));
|
|
1059
|
+
_context6.prev = 3;
|
|
1060
|
+
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
1061
|
+
var ds, dataSetInfo;
|
|
1062
|
+
return _regenerator.default.wrap(function (_context5) {
|
|
1063
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
1064
|
+
case 0:
|
|
1065
|
+
ds = _step7.value;
|
|
1066
|
+
dataSetInfo = allDataSets.find(function (d) {
|
|
1067
|
+
return d.name === ds.name;
|
|
1068
|
+
});
|
|
1069
|
+
_loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this9.debugId, " initializing data set \"").concat(ds.name, "\""));
|
|
1070
|
+
if (dataSetInfo) {
|
|
1071
|
+
_context5.next = 1;
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
_loggerProxy.default.logger.warn("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this9.debugId, " missing info about data set \"").concat(ds.name, "\" in Locus response from visibleDataSetsUrl"));
|
|
1075
|
+
_context5.next = 2;
|
|
1076
|
+
break;
|
|
1077
|
+
case 1:
|
|
1078
|
+
_context5.next = 2;
|
|
1079
|
+
return _this9.initializeNewVisibleDataSet(ds, dataSetInfo);
|
|
1080
|
+
case 2:
|
|
1081
|
+
case "end":
|
|
1082
|
+
return _context5.stop();
|
|
1083
|
+
}
|
|
1084
|
+
}, _loop);
|
|
1085
|
+
});
|
|
1086
|
+
_iterator7.s();
|
|
1087
|
+
case 4:
|
|
1088
|
+
if ((_step7 = _iterator7.n()).done) {
|
|
1089
|
+
_context6.next = 6;
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
return _context6.delegateYield(_loop(), "t0", 5);
|
|
1093
|
+
case 5:
|
|
1094
|
+
_context6.next = 4;
|
|
1095
|
+
break;
|
|
1096
|
+
case 6:
|
|
1097
|
+
_context6.next = 8;
|
|
1098
|
+
break;
|
|
1099
|
+
case 7:
|
|
1100
|
+
_context6.prev = 7;
|
|
1101
|
+
_t2 = _context6["catch"](3);
|
|
1102
|
+
_iterator7.e(_t2);
|
|
1103
|
+
case 8:
|
|
1104
|
+
_context6.prev = 8;
|
|
1105
|
+
_iterator7.f();
|
|
1106
|
+
return _context6.finish(8);
|
|
1107
|
+
case 9:
|
|
1108
|
+
case "end":
|
|
1109
|
+
return _context6.stop();
|
|
1110
|
+
}
|
|
1111
|
+
}, _callee5, this, [[3, 7, 8, 9]]);
|
|
1112
|
+
}));
|
|
1113
|
+
function initializeNewVisibleDataSets(_x7) {
|
|
1114
|
+
return _initializeNewVisibleDataSets.apply(this, arguments);
|
|
1115
|
+
}
|
|
1116
|
+
return initializeNewVisibleDataSets;
|
|
1117
|
+
}()
|
|
1118
|
+
/**
|
|
1119
|
+
* Parses incoming hash tree messages, updates the hash trees and returns information about the changes
|
|
1120
|
+
*
|
|
1121
|
+
* @param {HashTreeMessage} message - The hash tree message containing data sets and objects to be processed
|
|
1122
|
+
* @param {string} [debugText] - Optional debug text to include in logs
|
|
1123
|
+
* @returns {HashTreeObject[]} list of hash tree objects that were updated as a result of processing the message
|
|
1124
|
+
*/
|
|
1125
|
+
)
|
|
1126
|
+
}, {
|
|
1127
|
+
key: "parseMessage",
|
|
1128
|
+
value: function parseMessage(message, debugText) {
|
|
1129
|
+
var _message$dataSets,
|
|
1130
|
+
_message$locusStateEl,
|
|
1131
|
+
_message$locusStateEl2,
|
|
1132
|
+
_this0 = this;
|
|
1133
|
+
if (this.state === 'stopped') {
|
|
1134
|
+
return [];
|
|
1135
|
+
}
|
|
1136
|
+
var dataSets = message.dataSets,
|
|
1137
|
+
visibleDataSetsUrl = message.visibleDataSetsUrl;
|
|
1138
|
+
_loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " ").concat(debugText || '', " dataSets: ").concat((_message$dataSets = message.dataSets) === null || _message$dataSets === void 0 ? void 0 : _message$dataSets.map(function (_ref5) {
|
|
1139
|
+
var name = _ref5.name,
|
|
1140
|
+
version = _ref5.version;
|
|
1141
|
+
return "".concat(name, ":").concat(version);
|
|
1142
|
+
}).join(','), ", elements: ").concat((_message$locusStateEl = message.locusStateElements) === null || _message$locusStateEl === void 0 ? void 0 : _message$locusStateEl.map(function (el) {
|
|
1143
|
+
return "".concat(el.htMeta.elementId.type, ":").concat(el.htMeta.elementId.id, ":").concat(el.htMeta.elementId.version).concat(el.data ? '+' : '-');
|
|
1144
|
+
}).join(',')));
|
|
1145
|
+
if (((_message$locusStateEl2 = message.locusStateElements) === null || _message$locusStateEl2 === void 0 ? void 0 : _message$locusStateEl2.length) === 0) {
|
|
1146
|
+
_loggerProxy.default.logger.warn("HashTreeParser#parseMessage --> ".concat(this.debugId, " got empty locusStateElements!!!"));
|
|
1147
|
+
_metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS, {
|
|
1148
|
+
debugId: this.debugId
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// first, update our metadata about the datasets with info from the message
|
|
1153
|
+
this.visibleDataSetsUrl = visibleDataSetsUrl;
|
|
1154
|
+
dataSets.forEach(function (dataSet) {
|
|
1155
|
+
return _this0.updateDataSetInfo(dataSet);
|
|
1156
|
+
});
|
|
1157
|
+
this.cancelPendingSyncsForDataSets(dataSets.map(function (ds) {
|
|
1158
|
+
return ds.name;
|
|
1159
|
+
}));
|
|
1160
|
+
var updatedObjects = [];
|
|
1161
|
+
|
|
1162
|
+
// when we detect new visible datasets, it may be that the metadata about them is not
|
|
1163
|
+
// available in the message, they will require separate async initialization
|
|
1164
|
+
var dataSetsRequiringInitialization = [];
|
|
1165
|
+
|
|
1166
|
+
// first find out if there are any visible data set changes - they're signalled in Metadata object updates
|
|
1167
|
+
var metadataUpdates = (message.locusStateElements || []).filter(function (object) {
|
|
1168
|
+
return (0, _utils.isMetadata)(object);
|
|
1169
|
+
});
|
|
1170
|
+
if (metadataUpdates.length > 0) {
|
|
1171
|
+
var updatedMetadataObjects = [];
|
|
1172
|
+
metadataUpdates.forEach(function (object) {
|
|
1173
|
+
// todo: once Locus supports it, we will use the "view" field here instead of dataSetNames
|
|
1174
|
+
var _iterator8 = _createForOfIteratorHelper(object.htMeta.dataSetNames),
|
|
1175
|
+
_step8;
|
|
1176
|
+
try {
|
|
1177
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1178
|
+
var _this0$dataSets$dataS;
|
|
1179
|
+
var dataSetName = _step8.value;
|
|
1180
|
+
var hashTree = (_this0$dataSets$dataS = _this0.dataSets[dataSetName]) === null || _this0$dataSets$dataS === void 0 ? void 0 : _this0$dataSets$dataS.hashTree;
|
|
1181
|
+
if (hashTree && object.data) {
|
|
1182
|
+
if (hashTree.putItem(object.htMeta.elementId)) {
|
|
1183
|
+
updatedMetadataObjects.push(object);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
} catch (err) {
|
|
1188
|
+
_iterator8.e(err);
|
|
1189
|
+
} finally {
|
|
1190
|
+
_iterator8.f();
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
updatedObjects.push.apply(updatedObjects, updatedMetadataObjects);
|
|
1194
|
+
var _this$checkForVisible2 = this.checkForVisibleDataSetChanges(updatedMetadataObjects),
|
|
1195
|
+
changeDetected = _this$checkForVisible2.changeDetected,
|
|
1196
|
+
removedDataSets = _this$checkForVisible2.removedDataSets,
|
|
1197
|
+
addedDataSets = _this$checkForVisible2.addedDataSets;
|
|
1198
|
+
if (changeDetected) {
|
|
1199
|
+
dataSetsRequiringInitialization = this.processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (message.locusStateElements && message.locusStateElements.length > 0) {
|
|
1203
|
+
// by this point we now have this.dataSets setup for data sets from this message
|
|
1204
|
+
// and hash trees created for the new visible data sets,
|
|
1205
|
+
// so we can now process all the updates from the message
|
|
1206
|
+
dataSets.forEach(function (dataSet) {
|
|
1207
|
+
if (_this0.dataSets[dataSet.name]) {
|
|
1208
|
+
var hashTree = _this0.dataSets[dataSet.name].hashTree;
|
|
1209
|
+
if (hashTree) {
|
|
1210
|
+
var locusStateElementsForThisSet = message.locusStateElements.filter(function (object) {
|
|
1211
|
+
return object.htMeta.dataSetNames.includes(dataSet.name);
|
|
1212
|
+
});
|
|
1213
|
+
var appliedChangesList = hashTree.updateItems(locusStateElementsForThisSet.map(function (object) {
|
|
1214
|
+
return object.data ? {
|
|
1215
|
+
operation: 'update',
|
|
1216
|
+
item: object.htMeta.elementId
|
|
1217
|
+
} : {
|
|
1218
|
+
operation: 'remove',
|
|
1219
|
+
item: object.htMeta.elementId
|
|
1220
|
+
};
|
|
1221
|
+
}));
|
|
1222
|
+
(0, _lodash.zip)(appliedChangesList, locusStateElementsForThisSet).forEach(function (_ref6) {
|
|
1223
|
+
var _ref7 = (0, _slicedToArray2.default)(_ref6, 2),
|
|
1224
|
+
changeApplied = _ref7[0],
|
|
1225
|
+
object = _ref7[1];
|
|
1226
|
+
if (changeApplied) {
|
|
1227
|
+
// add to updatedObjects so that our locus DTO will get updated with the new object
|
|
1228
|
+
updatedObjects.push(object);
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
} else {
|
|
1232
|
+
_loggerProxy.default.logger.info("Locus-info:index#parseMessage --> ".concat(_this0.debugId, " unexpected (not visible) dataSet ").concat(dataSet.name, " received in hash tree message"));
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
_this0.runSyncAlgorithm(dataSet);
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
if (dataSetsRequiringInitialization.length > 0) {
|
|
1239
|
+
// there are some data sets that we need to initialize asynchronously
|
|
1240
|
+
this.queueInitForNewVisibleDataSets(dataSetsRequiringInitialization);
|
|
1241
|
+
}
|
|
1242
|
+
if (updatedObjects.length === 0) {
|
|
1243
|
+
_loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " No objects updated as a result of received message"));
|
|
1244
|
+
}
|
|
1245
|
+
return updatedObjects;
|
|
136
1246
|
}
|
|
137
1247
|
|
|
138
1248
|
/**
|
|
@@ -144,21 +1254,943 @@ var HashTreeParser = /*#__PURE__*/function () {
|
|
|
144
1254
|
*/
|
|
145
1255
|
}, {
|
|
146
1256
|
key: "handleMessage",
|
|
1257
|
+
value: function handleMessage(message, debugText) {
|
|
1258
|
+
if (this.state === 'stopped') {
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (message.heartbeatIntervalMs !== undefined) {
|
|
1262
|
+
this.topLevelHeartbeatIntervalMs = message.heartbeatIntervalMs;
|
|
1263
|
+
}
|
|
1264
|
+
if (this.isEndMessage(message)) {
|
|
1265
|
+
_loggerProxy.default.logger.info("HashTreeParser#handleMessage --> ".concat(this.debugId, " received sentinel END MEETING message"));
|
|
1266
|
+
this.stopAllTimers();
|
|
1267
|
+
this.callLocusInfoUpdateCallback({
|
|
1268
|
+
updateType: LocusInfoUpdateType.MEETING_ENDED
|
|
1269
|
+
});
|
|
1270
|
+
} else if (message.locusStateElements === undefined) {
|
|
1271
|
+
this.handleRootHashHeartBeatMessage(message);
|
|
1272
|
+
this.resetHeartbeatWatchdogs(message.dataSets);
|
|
1273
|
+
} else {
|
|
1274
|
+
var updatedObjects = this.parseMessage(message, debugText);
|
|
1275
|
+
this.resetHeartbeatWatchdogs(message.dataSets);
|
|
1276
|
+
this.callLocusInfoUpdateCallback({
|
|
1277
|
+
updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
|
|
1278
|
+
updatedObjects: updatedObjects
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Calls the updateInfo callback if there are any updates to report
|
|
1285
|
+
*
|
|
1286
|
+
* @param {Object} updates parsed from a Locus message
|
|
1287
|
+
* @returns {void}
|
|
1288
|
+
*/
|
|
1289
|
+
}, {
|
|
1290
|
+
key: "callLocusInfoUpdateCallback",
|
|
1291
|
+
value: function callLocusInfoUpdateCallback(updates) {
|
|
1292
|
+
var _updates$updatedObjec,
|
|
1293
|
+
_this1 = this;
|
|
1294
|
+
if (this.state === 'stopped') {
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
var updateType = updates.updateType;
|
|
1298
|
+
if (updateType === LocusInfoUpdateType.OBJECTS_UPDATED && ((_updates$updatedObjec = updates.updatedObjects) === null || _updates$updatedObjec === void 0 ? void 0 : _updates$updatedObjec.length) > 0) {
|
|
1299
|
+
// Filter out updates for objects that already have a higher version in their datasets,
|
|
1300
|
+
// or removals for objects that still exist in any of their datasets
|
|
1301
|
+
var filteredUpdates = updates.updatedObjects.filter(function (object) {
|
|
1302
|
+
var elementId = object.htMeta.elementId;
|
|
1303
|
+
var type = elementId.type,
|
|
1304
|
+
id = elementId.id,
|
|
1305
|
+
version = elementId.version;
|
|
1306
|
+
|
|
1307
|
+
// Check all datasets
|
|
1308
|
+
for (var _i2 = 0, _Object$keys3 = (0, _keys.default)(_this1.dataSets); _i2 < _Object$keys3.length; _i2++) {
|
|
1309
|
+
var dataSetName = _Object$keys3[_i2];
|
|
1310
|
+
var dataSet = _this1.dataSets[dataSetName];
|
|
1311
|
+
|
|
1312
|
+
// only visible datasets have hash trees set
|
|
1313
|
+
if (dataSet !== null && dataSet !== void 0 && dataSet.hashTree) {
|
|
1314
|
+
var existingVersion = dataSet.hashTree.getItemVersion(id, type);
|
|
1315
|
+
if (existingVersion !== undefined) {
|
|
1316
|
+
if (object.data) {
|
|
1317
|
+
// For updates: filter out if any dataset has a higher version
|
|
1318
|
+
if (existingVersion > version) {
|
|
1319
|
+
_loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this1.debugId, " Filtering out update for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" has v").concat(existingVersion));
|
|
1320
|
+
return false;
|
|
1321
|
+
}
|
|
1322
|
+
} else if (existingVersion >= version) {
|
|
1323
|
+
// For removals: filter out if the object still exists in any dataset
|
|
1324
|
+
_loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this1.debugId, " Filtering out removal for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" still has v").concat(existingVersion));
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return true;
|
|
1331
|
+
});
|
|
1332
|
+
if (filteredUpdates.length > 0) {
|
|
1333
|
+
this.locusInfoUpdateCallback({
|
|
1334
|
+
updateType: updateType,
|
|
1335
|
+
updatedObjects: filteredUpdates
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
} else if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED) {
|
|
1339
|
+
this.locusInfoUpdateCallback({
|
|
1340
|
+
updateType: updateType
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Calculates a weighted backoff time that should be used for syncs
|
|
1347
|
+
*
|
|
1348
|
+
* @param {Object} backoff - The backoff configuration containing maxMs and exponent
|
|
1349
|
+
* @returns {number} - A weighted backoff time based on the provided configuration, using algorithm supplied by Locus team
|
|
1350
|
+
*/
|
|
1351
|
+
}, {
|
|
1352
|
+
key: "getWeightedBackoffTime",
|
|
1353
|
+
value: function getWeightedBackoffTime(backoff) {
|
|
1354
|
+
var maxMs = backoff.maxMs,
|
|
1355
|
+
exponent = backoff.exponent;
|
|
1356
|
+
var randomValue = Math.random();
|
|
1357
|
+
return Math.round(Math.pow(randomValue, exponent) * maxMs);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Performs a sync for the given data set.
|
|
1362
|
+
*
|
|
1363
|
+
* @param {InternalDataSet} dataSet - The data set to sync
|
|
1364
|
+
* @param {string} reason - The reason for the sync (used for logging)
|
|
1365
|
+
* @param {boolean} [isInitialization] - Whether this is an initialization sync (sends empty leaves data instead of comparing hashes)
|
|
1366
|
+
* @returns {Promise<void>}
|
|
1367
|
+
*/
|
|
1368
|
+
}, {
|
|
1369
|
+
key: "performSync",
|
|
147
1370
|
value: (function () {
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
1371
|
+
var _performSync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(dataSet, reason, isInitialization) {
|
|
1372
|
+
var _dataSet$syncAbortCon;
|
|
1373
|
+
var abortController, hashTree, rootHash, leavesData, receivedHashes, hashesResult, mismatchedLeaveIndexes, syncResponse, _t3, _t4;
|
|
1374
|
+
return _regenerator.default.wrap(function (_context7) {
|
|
1375
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
151
1376
|
case 0:
|
|
1377
|
+
if (dataSet.hashTree) {
|
|
1378
|
+
_context7.next = 1;
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1381
|
+
return _context7.abrupt("return");
|
|
1382
|
+
case 1:
|
|
1383
|
+
abortController = (_dataSet$syncAbortCon = dataSet.syncAbortController) !== null && _dataSet$syncAbortCon !== void 0 ? _dataSet$syncAbortCon : new AbortController();
|
|
1384
|
+
dataSet.syncAbortController = abortController;
|
|
1385
|
+
hashTree = dataSet.hashTree;
|
|
1386
|
+
rootHash = hashTree.getRootHash();
|
|
1387
|
+
_context7.prev = 2;
|
|
1388
|
+
_loggerProxy.default.logger.info("HashTreeParser#performSync --> ".concat(this.debugId, " ").concat(reason, ", syncing data set \"").concat(dataSet.name, "\""));
|
|
1389
|
+
leavesData = {};
|
|
1390
|
+
if (isInitialization) {
|
|
1391
|
+
_context7.next = 10;
|
|
1392
|
+
break;
|
|
1393
|
+
}
|
|
1394
|
+
if (!(dataSet.leafCount !== 1)) {
|
|
1395
|
+
_context7.next = 9;
|
|
1396
|
+
break;
|
|
1397
|
+
}
|
|
1398
|
+
_context7.prev = 3;
|
|
1399
|
+
_context7.next = 4;
|
|
1400
|
+
return this.getHashesFromLocus(dataSet.name, rootHash);
|
|
1401
|
+
case 4:
|
|
1402
|
+
hashesResult = _context7.sent;
|
|
1403
|
+
if (hashesResult) {
|
|
1404
|
+
_context7.next = 5;
|
|
1405
|
+
break;
|
|
1406
|
+
}
|
|
1407
|
+
return _context7.abrupt("return");
|
|
1408
|
+
case 5:
|
|
1409
|
+
receivedHashes = hashesResult.hashes;
|
|
1410
|
+
this.updateDataSetLeafCount(dataSet, hashesResult.dataSet.leafCount);
|
|
1411
|
+
_context7.next = 8;
|
|
1412
|
+
break;
|
|
1413
|
+
case 6:
|
|
1414
|
+
_context7.prev = 6;
|
|
1415
|
+
_t3 = _context7["catch"](3);
|
|
1416
|
+
if (!((_t3 === null || _t3 === void 0 ? void 0 : _t3.statusCode) === 409)) {
|
|
1417
|
+
_context7.next = 7;
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
// this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
|
|
1421
|
+
_loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Got 409 when fetching hashes for data set \"").concat(dataSet.name, "\": ").concat(_t3.message));
|
|
1422
|
+
return _context7.abrupt("return");
|
|
1423
|
+
case 7:
|
|
1424
|
+
throw _t3;
|
|
1425
|
+
case 8:
|
|
1426
|
+
// identify mismatched leaves
|
|
1427
|
+
mismatchedLeaveIndexes = hashTree.diffHashes(receivedHashes);
|
|
1428
|
+
mismatchedLeaveIndexes.forEach(function (index) {
|
|
1429
|
+
leavesData[index] = hashTree.getLeafData(index);
|
|
1430
|
+
});
|
|
1431
|
+
_context7.next = 10;
|
|
1432
|
+
break;
|
|
1433
|
+
case 9:
|
|
1434
|
+
leavesData = {
|
|
1435
|
+
0: hashTree.getLeafData(0)
|
|
1436
|
+
};
|
|
1437
|
+
case 10:
|
|
1438
|
+
if (!abortController.signal.aborted) {
|
|
1439
|
+
_context7.next = 11;
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1442
|
+
_loggerProxy.default.logger.info("HashTreeParser#performSync --> ".concat(this.debugId, " abandoning sync for \"").concat(dataSet.name, "\" before /sync - message received during sync"));
|
|
1443
|
+
return _context7.abrupt("return");
|
|
1444
|
+
case 11:
|
|
1445
|
+
// request sync for mismatched leaves
|
|
1446
|
+
syncResponse = null;
|
|
1447
|
+
if (!isInitialization) {
|
|
1448
|
+
_context7.next = 13;
|
|
1449
|
+
break;
|
|
1450
|
+
}
|
|
1451
|
+
_context7.next = 12;
|
|
1452
|
+
return this.sendSyncRequestToLocus(dataSet, {
|
|
1453
|
+
isInitialization: true
|
|
1454
|
+
});
|
|
1455
|
+
case 12:
|
|
1456
|
+
syncResponse = _context7.sent;
|
|
1457
|
+
_context7.next = 15;
|
|
1458
|
+
break;
|
|
1459
|
+
case 13:
|
|
1460
|
+
if (!((0, _keys.default)(leavesData).length > 0)) {
|
|
1461
|
+
_context7.next = 15;
|
|
1462
|
+
break;
|
|
1463
|
+
}
|
|
1464
|
+
_context7.next = 14;
|
|
1465
|
+
return this.sendSyncRequestToLocus(dataSet, {
|
|
1466
|
+
mismatchedLeavesData: leavesData
|
|
1467
|
+
});
|
|
1468
|
+
case 14:
|
|
1469
|
+
syncResponse = _context7.sent;
|
|
1470
|
+
case 15:
|
|
1471
|
+
// sync API may return nothing (in that case data will arrive via messages)
|
|
1472
|
+
// or it may return a response in the same format as messages
|
|
1473
|
+
// We still need to restart the sync timer as a safety net in case the messages don't arrive.
|
|
1474
|
+
this.runSyncAlgorithm(dataSet);
|
|
1475
|
+
if (syncResponse) {
|
|
1476
|
+
// clear the abort controller before processing the response so that
|
|
1477
|
+
// parseMessage() -> cancelPendingSyncsForDataSets() doesn't log a
|
|
1478
|
+
// misleading "aborting sync" message for this already-completed sync
|
|
1479
|
+
dataSet.syncAbortController = undefined;
|
|
1480
|
+
|
|
1481
|
+
// the format of sync response is the same as messages, so we can reuse the same handler
|
|
1482
|
+
this.handleMessage(syncResponse, "via sync API (".concat(isInitialization ? 'init' : "".concat((0, _keys.default)(leavesData).length, " mismatched leaves"), ")"));
|
|
1483
|
+
}
|
|
1484
|
+
_context7.next = 17;
|
|
1485
|
+
break;
|
|
1486
|
+
case 16:
|
|
1487
|
+
_context7.prev = 16;
|
|
1488
|
+
_t4 = _context7["catch"](2);
|
|
1489
|
+
if (!this.handleSyncErrors(_t4)) {
|
|
1490
|
+
_loggerProxy.default.logger.warn("HashTreeParser#performSync --> ".concat(this.debugId, " error during sync for data set \"").concat(dataSet.name, "\":"), _t4);
|
|
1491
|
+
}
|
|
1492
|
+
case 17:
|
|
1493
|
+
_context7.prev = 17;
|
|
1494
|
+
dataSet.syncAbortController = undefined;
|
|
1495
|
+
return _context7.finish(17);
|
|
1496
|
+
case 18:
|
|
152
1497
|
case "end":
|
|
153
|
-
return
|
|
1498
|
+
return _context7.stop();
|
|
1499
|
+
}
|
|
1500
|
+
}, _callee6, this, [[2, 16, 17, 18], [3, 6]]);
|
|
1501
|
+
}));
|
|
1502
|
+
function performSync(_x8, _x9, _x0) {
|
|
1503
|
+
return _performSync.apply(this, arguments);
|
|
1504
|
+
}
|
|
1505
|
+
return performSync;
|
|
1506
|
+
}()
|
|
1507
|
+
/**
|
|
1508
|
+
* Cancels any pending or in-flight syncs for the specified data sets.
|
|
1509
|
+
* This removes matching entries from the sync queue and aborts any in-flight sync HTTP requests.
|
|
1510
|
+
*
|
|
1511
|
+
* @param {string[]} dataSetNames - The names of the data sets to cancel syncs for
|
|
1512
|
+
* @returns {void}
|
|
1513
|
+
*/
|
|
1514
|
+
)
|
|
1515
|
+
}, {
|
|
1516
|
+
key: "cancelPendingSyncsForDataSets",
|
|
1517
|
+
value: function cancelPendingSyncsForDataSets(dataSetNames) {
|
|
1518
|
+
var previousLength = this.syncQueue.length;
|
|
1519
|
+
this.syncQueue = this.syncQueue.filter(function (entry) {
|
|
1520
|
+
return !dataSetNames.includes(entry.dataSetName);
|
|
1521
|
+
});
|
|
1522
|
+
if (previousLength !== this.syncQueue.length) {
|
|
1523
|
+
_loggerProxy.default.logger.info("HashTreeParser#cancelPendingSyncsForDataSets --> ".concat(this.debugId, " removed ").concat(previousLength - this.syncQueue.length, " entries from sync queue for data sets: ").concat(dataSetNames.join(', ')));
|
|
1524
|
+
}
|
|
1525
|
+
this.markDataSetsForSyncAllBackoffSkip(dataSetNames);
|
|
1526
|
+
this.abortInFlightSyncs(dataSetNames);
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* If a syncAllDatasets backoff sleep is in progress, marks the given data sets to be skipped
|
|
1531
|
+
* after the sleep completes.
|
|
1532
|
+
*
|
|
1533
|
+
* @param {string[]} dataSetNames - The names of the data sets to mark
|
|
1534
|
+
* @returns {void}
|
|
1535
|
+
*/
|
|
1536
|
+
}, {
|
|
1537
|
+
key: "markDataSetsForSyncAllBackoffSkip",
|
|
1538
|
+
value: function markDataSetsForSyncAllBackoffSkip(dataSetNames) {
|
|
1539
|
+
if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
|
|
1540
|
+
var _iterator9 = _createForOfIteratorHelper(dataSetNames),
|
|
1541
|
+
_step9;
|
|
1542
|
+
try {
|
|
1543
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1544
|
+
var name = _step9.value;
|
|
1545
|
+
this.dataSetsSyncedDuringBackoff.add(name);
|
|
1546
|
+
}
|
|
1547
|
+
} catch (err) {
|
|
1548
|
+
_iterator9.e(err);
|
|
1549
|
+
} finally {
|
|
1550
|
+
_iterator9.f();
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Aborts any in-flight sync HTTP requests for the specified data sets.
|
|
1557
|
+
*
|
|
1558
|
+
* @param {string[]} dataSetNames - The names of the data sets whose syncs should be aborted
|
|
1559
|
+
* @returns {void}
|
|
1560
|
+
*/
|
|
1561
|
+
}, {
|
|
1562
|
+
key: "abortInFlightSyncs",
|
|
1563
|
+
value: function abortInFlightSyncs(dataSetNames) {
|
|
1564
|
+
var _iterator0 = _createForOfIteratorHelper(dataSetNames),
|
|
1565
|
+
_step0;
|
|
1566
|
+
try {
|
|
1567
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
1568
|
+
var _this$dataSets$name;
|
|
1569
|
+
var name = _step0.value;
|
|
1570
|
+
if ((_this$dataSets$name = this.dataSets[name]) !== null && _this$dataSets$name !== void 0 && _this$dataSets$name.syncAbortController) {
|
|
1571
|
+
_loggerProxy.default.logger.info("HashTreeParser#cancelPendingSyncsForDataSets --> ".concat(this.debugId, " aborting in-flight sync for data set \"").concat(name, "\""));
|
|
1572
|
+
this.dataSets[name].syncAbortController.abort();
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
} catch (err) {
|
|
1576
|
+
_iterator0.e(err);
|
|
1577
|
+
} finally {
|
|
1578
|
+
_iterator0.f();
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Enqueues a sync for the given data set. If the data set is already in the queue, the request is ignored.
|
|
1584
|
+
* This ensures that all syncs are executed sequentially and no more than 1 sync runs at a time.
|
|
1585
|
+
*
|
|
1586
|
+
* @param {string} dataSetName - The name of the data set to sync
|
|
1587
|
+
* @param {string} reason - The reason for the sync (used for logging)
|
|
1588
|
+
* @param {boolean} [isInitialization=false] - Whether this is an initialization sync (uses empty leaves data instead of hash comparison)
|
|
1589
|
+
* @returns {void}
|
|
1590
|
+
*/
|
|
1591
|
+
}, {
|
|
1592
|
+
key: "enqueueSyncForDataset",
|
|
1593
|
+
value: function enqueueSyncForDataset(dataSetName, reason) {
|
|
1594
|
+
var isInitialization = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1595
|
+
if (this.state === 'stopped') return;
|
|
1596
|
+
var existingEntry = this.syncQueue.find(function (entry) {
|
|
1597
|
+
return entry.dataSetName === dataSetName;
|
|
1598
|
+
});
|
|
1599
|
+
if (existingEntry) {
|
|
1600
|
+
if (isInitialization) {
|
|
1601
|
+
existingEntry.isInitialization = true;
|
|
1602
|
+
}
|
|
1603
|
+
_loggerProxy.default.logger.info("HashTreeParser#enqueueSyncForDataset --> ".concat(this.debugId, " data set \"").concat(dataSetName, "\" already in sync queue, skipping"));
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
this.syncQueue.push({
|
|
1607
|
+
dataSetName: dataSetName,
|
|
1608
|
+
reason: reason,
|
|
1609
|
+
isInitialization: isInitialization
|
|
1610
|
+
});
|
|
1611
|
+
if (!this.isSyncInProgress) {
|
|
1612
|
+
this.syncQueueProcessingPromise = this.processSyncQueue();
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* Processes the sync queue sequentially. Only one instance of this method runs at a time.
|
|
1618
|
+
*
|
|
1619
|
+
* @returns {Promise<void>}
|
|
1620
|
+
*/
|
|
1621
|
+
}, {
|
|
1622
|
+
key: "processSyncQueue",
|
|
1623
|
+
value: (function () {
|
|
1624
|
+
var _processSyncQueue = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
1625
|
+
var _ref8, dataSetName, reason, isInitialization, dataSet;
|
|
1626
|
+
return _regenerator.default.wrap(function (_context8) {
|
|
1627
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1628
|
+
case 0:
|
|
1629
|
+
if (!this.isSyncInProgress) {
|
|
1630
|
+
_context8.next = 1;
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
return _context8.abrupt("return");
|
|
1634
|
+
case 1:
|
|
1635
|
+
this.isSyncInProgress = true;
|
|
1636
|
+
_context8.prev = 2;
|
|
1637
|
+
case 3:
|
|
1638
|
+
if (!(this.syncQueue.length > 0 && this.state !== 'stopped')) {
|
|
1639
|
+
_context8.next = 6;
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1643
|
+
_ref8 = this.syncQueue.shift(), dataSetName = _ref8.dataSetName, reason = _ref8.reason, isInitialization = _ref8.isInitialization;
|
|
1644
|
+
dataSet = this.dataSets[dataSetName];
|
|
1645
|
+
if (dataSet !== null && dataSet !== void 0 && dataSet.hashTree) {
|
|
1646
|
+
_context8.next = 4;
|
|
1647
|
+
break;
|
|
1648
|
+
}
|
|
1649
|
+
return _context8.abrupt("continue", 3);
|
|
1650
|
+
case 4:
|
|
1651
|
+
_context8.next = 5;
|
|
1652
|
+
return this.performSync(dataSet, reason, isInitialization);
|
|
1653
|
+
case 5:
|
|
1654
|
+
_context8.next = 3;
|
|
1655
|
+
break;
|
|
1656
|
+
case 6:
|
|
1657
|
+
_context8.prev = 6;
|
|
1658
|
+
this.isSyncInProgress = false;
|
|
1659
|
+
return _context8.finish(6);
|
|
1660
|
+
case 7:
|
|
1661
|
+
case "end":
|
|
1662
|
+
return _context8.stop();
|
|
1663
|
+
}
|
|
1664
|
+
}, _callee7, this, [[2,, 6, 7]]);
|
|
1665
|
+
}));
|
|
1666
|
+
function processSyncQueue() {
|
|
1667
|
+
return _processSyncQueue.apply(this, arguments);
|
|
1668
|
+
}
|
|
1669
|
+
return processSyncQueue;
|
|
1670
|
+
}()
|
|
1671
|
+
/**
|
|
1672
|
+
* sets the backoff type for syncAllDatasets calls, which determines the scope of datasets that will be synced after the backoff delay.
|
|
1673
|
+
*
|
|
1674
|
+
* @param {boolean} onlyLLM - Whether the backoff is for a syncAllDatasets call that is syncing only LLM datasets
|
|
1675
|
+
* @returns {void}
|
|
1676
|
+
*/
|
|
1677
|
+
)
|
|
1678
|
+
}, {
|
|
1679
|
+
key: "setSyncAllBackoffType",
|
|
1680
|
+
value: function setSyncAllBackoffType(onlyLLM) {
|
|
1681
|
+
this.syncAllBackoffType = onlyLLM ? SyncAllBackoffType.ONLY_LLM : SyncAllBackoffType.ALL;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
* Checks if a syncAll backoff is already in progress. If so, upgrades the scope from
|
|
1686
|
+
* onlyLLM to all datasets when the new call has a broader scope.
|
|
1687
|
+
*
|
|
1688
|
+
* @param {boolean} onlyLLM - Whether the current call is for LLM datasets only
|
|
1689
|
+
* @returns {boolean} true if a backoff is already pending (caller should return early)
|
|
1690
|
+
*/
|
|
1691
|
+
}, {
|
|
1692
|
+
key: "tryUpgradePendingBackoff",
|
|
1693
|
+
value: function tryUpgradePendingBackoff(onlyLLM) {
|
|
1694
|
+
if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
|
|
1695
|
+
if (!onlyLLM && this.syncAllBackoffType === SyncAllBackoffType.ONLY_LLM) {
|
|
1696
|
+
this.setSyncAllBackoffType(false);
|
|
1697
|
+
_loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " upgraded pending syncAll from onlyLLM to all datasets"));
|
|
1698
|
+
}
|
|
1699
|
+
return true;
|
|
1700
|
+
}
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
/**
|
|
1705
|
+
* Syncs all data sets that have hash trees, one by one in sequence, using the priority order
|
|
1706
|
+
* provided by sortByInitPriority().
|
|
1707
|
+
*
|
|
1708
|
+
* If a call is already waiting in the backoff delay phase, a new call with a broader scope
|
|
1709
|
+
* (onlyLLM=false) will upgrade the pending scope, and the dataset list will be computed after
|
|
1710
|
+
* the backoff using the upgraded scope. After the backoff, the sync queue handles deduplication
|
|
1711
|
+
* so no guard is needed.
|
|
1712
|
+
*
|
|
1713
|
+
* @param {Object} [options={}] - Options for syncing
|
|
1714
|
+
* @param {boolean} [options.onlyLLM=false] - Whether to sync only LLM based data sets
|
|
1715
|
+
* @returns {Promise<void>}
|
|
1716
|
+
*/
|
|
1717
|
+
}, {
|
|
1718
|
+
key: "syncAllDatasets",
|
|
1719
|
+
value: (function () {
|
|
1720
|
+
var _syncAllDatasets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
1721
|
+
var options,
|
|
1722
|
+
_options$onlyLLM,
|
|
1723
|
+
onlyLLM,
|
|
1724
|
+
dataSetsToSync,
|
|
1725
|
+
delay,
|
|
1726
|
+
effectiveBackoffType,
|
|
1727
|
+
skippedDataSets,
|
|
1728
|
+
effectiveDataSetsToSync,
|
|
1729
|
+
_iterator1,
|
|
1730
|
+
_step1,
|
|
1731
|
+
ds,
|
|
1732
|
+
_args9 = arguments;
|
|
1733
|
+
return _regenerator.default.wrap(function (_context9) {
|
|
1734
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1735
|
+
case 0:
|
|
1736
|
+
options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
|
|
1737
|
+
_options$onlyLLM = options.onlyLLM, onlyLLM = _options$onlyLLM === void 0 ? false : _options$onlyLLM;
|
|
1738
|
+
if (!(this.state === 'stopped')) {
|
|
1739
|
+
_context9.next = 1;
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
return _context9.abrupt("return");
|
|
1743
|
+
case 1:
|
|
1744
|
+
if (!this.tryUpgradePendingBackoff(onlyLLM)) {
|
|
1745
|
+
_context9.next = 2;
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
return _context9.abrupt("return");
|
|
1749
|
+
case 2:
|
|
1750
|
+
dataSetsToSync = this.getSortedDataSetsWithHashTrees(onlyLLM);
|
|
1751
|
+
if (!(dataSetsToSync.length === 0)) {
|
|
1752
|
+
_context9.next = 3;
|
|
1753
|
+
break;
|
|
1754
|
+
}
|
|
1755
|
+
return _context9.abrupt("return");
|
|
1756
|
+
case 3:
|
|
1757
|
+
this.setSyncAllBackoffType(onlyLLM);
|
|
1758
|
+
delay = this.getWeightedBackoffTime(dataSetsToSync[0].backoff);
|
|
1759
|
+
_loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " starting backoff delay of ").concat(delay, "ms (onlyLLM=").concat(onlyLLM, ")"));
|
|
1760
|
+
|
|
1761
|
+
// delay the start of the syncs - this is a Locus requirement to avoid thundering herd issues
|
|
1762
|
+
_context9.next = 4;
|
|
1763
|
+
return (0, _utils.sleep)(delay);
|
|
1764
|
+
case 4:
|
|
1765
|
+
// read the (possibly upgraded) scope and clear the backoff flag
|
|
1766
|
+
effectiveBackoffType = this.syncAllBackoffType;
|
|
1767
|
+
skippedDataSets = this.dataSetsSyncedDuringBackoff;
|
|
1768
|
+
this.syncAllBackoffType = SyncAllBackoffType.NONE;
|
|
1769
|
+
this.dataSetsSyncedDuringBackoff = new _set.default();
|
|
1770
|
+
if (!(this.state === 'stopped')) {
|
|
1771
|
+
_context9.next = 5;
|
|
1772
|
+
break;
|
|
1773
|
+
}
|
|
1774
|
+
return _context9.abrupt("return");
|
|
1775
|
+
case 5:
|
|
1776
|
+
// re-evaluate the dataset list after the sleep, since the scope may have been upgraded
|
|
1777
|
+
// and exclude datasets that received messages during the backoff sleep
|
|
1778
|
+
effectiveDataSetsToSync = this.getSortedDataSetsWithHashTrees(effectiveBackoffType === SyncAllBackoffType.ONLY_LLM).filter(function (ds) {
|
|
1779
|
+
return !skippedDataSets.has(ds.name);
|
|
1780
|
+
});
|
|
1781
|
+
if (skippedDataSets.size > 0) {
|
|
1782
|
+
_loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " skipping datasets that received messages during backoff: ").concat((0, _toConsumableArray2.default)(skippedDataSets).join(', ')));
|
|
1783
|
+
}
|
|
1784
|
+
_loggerProxy.default.logger.info("HashTreeParser#syncAllDatasets --> ".concat(this.debugId, " syncing ").concat(effectiveBackoffType === SyncAllBackoffType.ONLY_LLM ? 'only LLM' : 'all', " datasets: ").concat(effectiveDataSetsToSync.map(function (ds) {
|
|
1785
|
+
return ds.name;
|
|
1786
|
+
}).join(', ')));
|
|
1787
|
+
_iterator1 = _createForOfIteratorHelper(effectiveDataSetsToSync);
|
|
1788
|
+
try {
|
|
1789
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
1790
|
+
ds = _step1.value;
|
|
1791
|
+
this.enqueueSyncForDataset(ds.name, 'syncAllDatasets');
|
|
1792
|
+
}
|
|
1793
|
+
} catch (err) {
|
|
1794
|
+
_iterator1.e(err);
|
|
1795
|
+
} finally {
|
|
1796
|
+
_iterator1.f();
|
|
1797
|
+
}
|
|
1798
|
+
_context9.next = 6;
|
|
1799
|
+
return this.syncQueueProcessingPromise;
|
|
1800
|
+
case 6:
|
|
1801
|
+
case "end":
|
|
1802
|
+
return _context9.stop();
|
|
1803
|
+
}
|
|
1804
|
+
}, _callee8, this);
|
|
1805
|
+
}));
|
|
1806
|
+
function syncAllDatasets() {
|
|
1807
|
+
return _syncAllDatasets.apply(this, arguments);
|
|
1808
|
+
}
|
|
1809
|
+
return syncAllDatasets;
|
|
1810
|
+
}()
|
|
1811
|
+
/**
|
|
1812
|
+
* Returns the list of data sets that have hash trees, sorted by the priority order provided by sortByInitPriority().
|
|
1813
|
+
*
|
|
1814
|
+
* @param {boolean} onlyLLM - Whether to include only LLM based data sets
|
|
1815
|
+
* @returns {Array<{name: string, backoff: {maxMs: number, exponent: number}}>} The sorted list of data sets with their backoff configurations
|
|
1816
|
+
*/
|
|
1817
|
+
)
|
|
1818
|
+
}, {
|
|
1819
|
+
key: "getSortedDataSetsWithHashTrees",
|
|
1820
|
+
value: function getSortedDataSetsWithHashTrees(onlyLLM) {
|
|
1821
|
+
var dataSets = (0, _values.default)(this.dataSets).filter(function (dataSet) {
|
|
1822
|
+
return dataSet === null || dataSet === void 0 ? void 0 : dataSet.hashTree;
|
|
1823
|
+
}).map(function (dataSet) {
|
|
1824
|
+
return {
|
|
1825
|
+
name: dataSet.name,
|
|
1826
|
+
backoff: dataSet.backoff
|
|
1827
|
+
};
|
|
1828
|
+
});
|
|
1829
|
+
if (onlyLLM) {
|
|
1830
|
+
dataSets = dataSets.filter(function (ds) {
|
|
1831
|
+
return _constants3.LLM_DATASET_NAMES.includes(ds.name);
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
return (0, _utils.sortByInitPriority)(dataSets, _constants3.DATA_SET_INIT_PRIORITY);
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
/**
|
|
1838
|
+
* Runs the sync algorithm for the given data set.
|
|
1839
|
+
*
|
|
1840
|
+
* @param {DataSet} receivedDataSet - The data set to run the sync algorithm for.
|
|
1841
|
+
* @returns {void}
|
|
1842
|
+
*/
|
|
1843
|
+
}, {
|
|
1844
|
+
key: "runSyncAlgorithm",
|
|
1845
|
+
value: function runSyncAlgorithm(receivedDataSet) {
|
|
1846
|
+
var _this10 = this;
|
|
1847
|
+
var dataSet = this.dataSets[receivedDataSet.name];
|
|
1848
|
+
if (!dataSet) {
|
|
1849
|
+
_loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No data set found for ").concat(receivedDataSet.name, ", skipping sync algorithm"));
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (!dataSet.hashTree) {
|
|
1853
|
+
// no hash tree, so no need to do any syncing
|
|
1854
|
+
// we fall into this branch often, because Locus sends dataSets in messages that are not visible to us
|
|
1855
|
+
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
dataSet.hashTree.resize(receivedDataSet.leafCount);
|
|
1859
|
+
var delay = dataSet.idleMs + this.getWeightedBackoffTime(dataSet.backoff);
|
|
1860
|
+
if (delay > 0) {
|
|
1861
|
+
if (dataSet.timer) {
|
|
1862
|
+
clearTimeout(dataSet.timer);
|
|
1863
|
+
}
|
|
1864
|
+
dataSet.timer = setTimeout(function () {
|
|
1865
|
+
dataSet.timer = undefined;
|
|
1866
|
+
if (!dataSet.hashTree) {
|
|
1867
|
+
_loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(_this10.debugId, " Data set \"").concat(dataSet.name, "\" no longer has a hash tree, cannot run sync algorithm"));
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
var rootHash = dataSet.hashTree.getRootHash();
|
|
1871
|
+
if (dataSet.root !== rootHash) {
|
|
1872
|
+
_this10.enqueueSyncForDataset(dataSet.name, "Root hash mismatch: received=".concat(dataSet.root, ", ours=").concat(rootHash));
|
|
1873
|
+
}
|
|
1874
|
+
}, delay);
|
|
1875
|
+
} else {
|
|
1876
|
+
_loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No delay for \"").concat(dataSet.name, "\" data set, skipping sync timer reset/setup"));
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* Resets the heartbeat watchdog timers for the specified data sets. Each data set has its own
|
|
1882
|
+
* watchdog timer that monitors whether heartbeats are being received within the expected interval.
|
|
1883
|
+
* If a heartbeat is not received for a specific data set within heartbeatIntervalMs plus
|
|
1884
|
+
* a backoff-calculated time, the sync algorithm is initiated for that data set
|
|
1885
|
+
*
|
|
1886
|
+
* @param {Array<DataSet>} receivedDataSets - The data sets from the received message for which watchdog timers should be reset
|
|
1887
|
+
* @returns {void}
|
|
1888
|
+
*/
|
|
1889
|
+
}, {
|
|
1890
|
+
key: "resetHeartbeatWatchdogs",
|
|
1891
|
+
value: function resetHeartbeatWatchdogs(receivedDataSets) {
|
|
1892
|
+
var _this11 = this;
|
|
1893
|
+
var _iterator10 = _createForOfIteratorHelper(receivedDataSets),
|
|
1894
|
+
_step10;
|
|
1895
|
+
try {
|
|
1896
|
+
var _loop2 = function _loop2() {
|
|
1897
|
+
var _dataSet$heartbeatInt;
|
|
1898
|
+
var receivedDataSet = _step10.value;
|
|
1899
|
+
var dataSet = _this11.dataSets[receivedDataSet.name];
|
|
1900
|
+
if (dataSet.heartbeatWatchdogTimer) {
|
|
1901
|
+
clearTimeout(dataSet.heartbeatWatchdogTimer);
|
|
1902
|
+
dataSet.heartbeatWatchdogTimer = undefined;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// dataset-level heartbeatIntervalMs takes priority; fall back to top-level common value
|
|
1906
|
+
var heartbeatIntervalMs = (_dataSet$heartbeatInt = dataSet === null || dataSet === void 0 ? void 0 : dataSet.heartbeatIntervalMs) !== null && _dataSet$heartbeatInt !== void 0 ? _dataSet$heartbeatInt : _this11.topLevelHeartbeatIntervalMs;
|
|
1907
|
+
if (!(dataSet !== null && dataSet !== void 0 && dataSet.hashTree) || !heartbeatIntervalMs) {
|
|
1908
|
+
// eslint-disable-next-line no-continue
|
|
1909
|
+
return 1; // continue
|
|
1910
|
+
}
|
|
1911
|
+
var backoffTime = _this11.getWeightedBackoffTime(dataSet.backoff);
|
|
1912
|
+
var delay = heartbeatIntervalMs + backoffTime;
|
|
1913
|
+
dataSet.heartbeatWatchdogTimer = setTimeout(function () {
|
|
1914
|
+
dataSet.heartbeatWatchdogTimer = undefined;
|
|
1915
|
+
_loggerProxy.default.logger.warn("HashTreeParser#resetHeartbeatWatchdogs --> ".concat(_this11.debugId, " Heartbeat watchdog fired for data set \"").concat(dataSet.name, "\" - no heartbeat received within expected interval, initiating sync"));
|
|
1916
|
+
_metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
|
|
1917
|
+
debugId: _this11.debugId,
|
|
1918
|
+
dataSetName: dataSet.name
|
|
1919
|
+
});
|
|
1920
|
+
_this11.enqueueSyncForDataset(dataSet.name, "heartbeat watchdog expired");
|
|
1921
|
+
_this11.resetHeartbeatWatchdogs([dataSet]);
|
|
1922
|
+
}, delay);
|
|
1923
|
+
};
|
|
1924
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1925
|
+
if (_loop2()) continue;
|
|
1926
|
+
}
|
|
1927
|
+
} catch (err) {
|
|
1928
|
+
_iterator10.e(err);
|
|
1929
|
+
} finally {
|
|
1930
|
+
_iterator10.f();
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
/**
|
|
1935
|
+
* Stops all timers for the data sets to prevent any further sync attempts.
|
|
1936
|
+
* @returns {void}
|
|
1937
|
+
*/
|
|
1938
|
+
}, {
|
|
1939
|
+
key: "stopAllTimers",
|
|
1940
|
+
value: function stopAllTimers() {
|
|
1941
|
+
(0, _values.default)(this.dataSets).forEach(function (dataSet) {
|
|
1942
|
+
if (dataSet.timer) {
|
|
1943
|
+
clearTimeout(dataSet.timer);
|
|
1944
|
+
dataSet.timer = undefined;
|
|
1945
|
+
}
|
|
1946
|
+
if (dataSet.heartbeatWatchdogTimer) {
|
|
1947
|
+
clearTimeout(dataSet.heartbeatWatchdogTimer);
|
|
1948
|
+
dataSet.heartbeatWatchdogTimer = undefined;
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* Stops the HashTreeParser, preventing it from processing any further messages and clearing all timers.
|
|
1955
|
+
* It also clears all the hash trees, so if the parser is resumed later, it will need to do a sync
|
|
1956
|
+
* to be up-to-date.
|
|
1957
|
+
* @returns {void}
|
|
1958
|
+
*/
|
|
1959
|
+
}, {
|
|
1960
|
+
key: "stop",
|
|
1961
|
+
value: function stop() {
|
|
1962
|
+
_loggerProxy.default.logger.info("HashTreeParser#stop --> ".concat(this.debugId, " Stopping HashTreeParser, clearing timers and hash trees"));
|
|
1963
|
+
this.stopAllTimers();
|
|
1964
|
+
this.syncQueue = [];
|
|
1965
|
+
this.topLevelHeartbeatIntervalMs = undefined;
|
|
1966
|
+
this.syncAllBackoffType = SyncAllBackoffType.NONE;
|
|
1967
|
+
this.dataSetsSyncedDuringBackoff = new _set.default();
|
|
1968
|
+
(0, _values.default)(this.dataSets).forEach(function (dataSet) {
|
|
1969
|
+
var _dataSet$syncAbortCon2;
|
|
1970
|
+
(_dataSet$syncAbortCon2 = dataSet.syncAbortController) === null || _dataSet$syncAbortCon2 === void 0 ? void 0 : _dataSet$syncAbortCon2.abort();
|
|
1971
|
+
dataSet.syncAbortController = undefined;
|
|
1972
|
+
dataSet.hashTree = undefined;
|
|
1973
|
+
});
|
|
1974
|
+
this.visibleDataSets = [];
|
|
1975
|
+
this.state = 'stopped';
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* Cleans up the HashTreeParser, stopping all timers and clearing all internal state.
|
|
1980
|
+
* After calling this, the parser should not be used anymore.
|
|
1981
|
+
* @returns {void}
|
|
1982
|
+
*/
|
|
1983
|
+
}, {
|
|
1984
|
+
key: "cleanUp",
|
|
1985
|
+
value: function cleanUp() {
|
|
1986
|
+
this.stop();
|
|
1987
|
+
this.dataSets = {};
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* Resumes the HashTreeParser that was previously stopped, using a hash tree message.
|
|
1992
|
+
* @param {HashTreeMessage} message - The message to resume with, it must contain metadata with visible data sets info
|
|
1993
|
+
* @returns {void}
|
|
1994
|
+
*/
|
|
1995
|
+
}, {
|
|
1996
|
+
key: "resumeFromMessage",
|
|
1997
|
+
value: function resumeFromMessage(message) {
|
|
1998
|
+
var _message$locusStateEl3, _metadataObject$data;
|
|
1999
|
+
// check that message contains metadata with visible data sets - this is essential to be able to resume
|
|
2000
|
+
var metadataObject = (_message$locusStateEl3 = message.locusStateElements) === null || _message$locusStateEl3 === void 0 ? void 0 : _message$locusStateEl3.find(function (el) {
|
|
2001
|
+
return (0, _utils.isMetadata)(el);
|
|
2002
|
+
});
|
|
2003
|
+
if (!(metadataObject !== null && metadataObject !== void 0 && (_metadataObject$data = metadataObject.data) !== null && _metadataObject$data !== void 0 && _metadataObject$data.visibleDataSets)) {
|
|
2004
|
+
_loggerProxy.default.logger.warn("HashTreeParser#resumeFromMessage --> ".concat(this.debugId, " Cannot resume HashTreeParser because the message is missing metadata with visible data sets info"));
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
this.setVisibleDataSets(metadataObject.data.visibleDataSets, message.dataSets);
|
|
2008
|
+
this.dataSets = {};
|
|
2009
|
+
var _iterator11 = _createForOfIteratorHelper(message.dataSets),
|
|
2010
|
+
_step11;
|
|
2011
|
+
try {
|
|
2012
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
2013
|
+
var dataSet = _step11.value;
|
|
2014
|
+
var name = dataSet.name,
|
|
2015
|
+
leafCount = dataSet.leafCount;
|
|
2016
|
+
this.dataSets[name] = _objectSpread(_objectSpread({}, dataSet), {}, {
|
|
2017
|
+
hashTree: this.isVisibleDataSet(name) ? new _hashTree.default([], leafCount) : undefined
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
_iterator11.e(err);
|
|
2022
|
+
} finally {
|
|
2023
|
+
_iterator11.f();
|
|
2024
|
+
}
|
|
2025
|
+
_loggerProxy.default.logger.info("HashTreeParser#resumeFromMessage --> ".concat(this.debugId, " Resuming HashTreeParser with data sets: ").concat((0, _keys.default)(this.dataSets).join(', '), ", visible data sets: ").concat(this.visibleDataSets.map(function (ds) {
|
|
2026
|
+
return ds.name;
|
|
2027
|
+
}).join(', ')));
|
|
2028
|
+
this.state = 'active';
|
|
2029
|
+
this.handleMessage(message, 'on resume');
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Resumes the HashTreeParser that was previously stopped, using a Locus API response.
|
|
2034
|
+
* Unlike resumeFromMessage(), this does not require metadata/dataSets in the input,
|
|
2035
|
+
* as it fetches all necessary information from Locus via initializeFromGetLociResponse.
|
|
2036
|
+
* @param {LocusDTO} locus - locus object from an API response
|
|
2037
|
+
* @returns {Promise}
|
|
2038
|
+
*/
|
|
2039
|
+
}, {
|
|
2040
|
+
key: "resumeFromApiResponse",
|
|
2041
|
+
value: (function () {
|
|
2042
|
+
var _resumeFromApiResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9(locus) {
|
|
2043
|
+
return _regenerator.default.wrap(function (_context0) {
|
|
2044
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
2045
|
+
case 0:
|
|
2046
|
+
this.state = 'active';
|
|
2047
|
+
this.dataSets = {};
|
|
2048
|
+
_loggerProxy.default.logger.info("HashTreeParser#resumeFromApiResponse --> ".concat(this.debugId, " Resuming HashTreeParser from API response"));
|
|
2049
|
+
_context0.next = 1;
|
|
2050
|
+
return this.initializeFromGetLociResponse(locus);
|
|
2051
|
+
case 1:
|
|
2052
|
+
case "end":
|
|
2053
|
+
return _context0.stop();
|
|
154
2054
|
}
|
|
155
|
-
},
|
|
2055
|
+
}, _callee9, this);
|
|
156
2056
|
}));
|
|
157
|
-
function
|
|
158
|
-
return
|
|
2057
|
+
function resumeFromApiResponse(_x1) {
|
|
2058
|
+
return _resumeFromApiResponse.apply(this, arguments);
|
|
159
2059
|
}
|
|
160
|
-
return
|
|
2060
|
+
return resumeFromApiResponse;
|
|
161
2061
|
}())
|
|
2062
|
+
}, {
|
|
2063
|
+
key: "checkForSentinelHttpResponse",
|
|
2064
|
+
value: function checkForSentinelHttpResponse(error, dataSetName) {
|
|
2065
|
+
var _error$body;
|
|
2066
|
+
// 404 for any dataset means the locus is no longer available at this URL - could be replaced or ended
|
|
2067
|
+
// if a dataset is just not visible, we would get a 400
|
|
2068
|
+
if (error.statusCode === 404) {
|
|
2069
|
+
_loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received 404 for data set \"").concat(dataSetName, "\", locus not found"));
|
|
2070
|
+
this.stopAllTimers();
|
|
2071
|
+
throw new LocusNotFoundError();
|
|
2072
|
+
}
|
|
2073
|
+
var isValidDataSetForSentinel = dataSetName === undefined || PossibleSentinelMessageDataSetNames.includes(dataSetName.toLowerCase());
|
|
2074
|
+
if (error.statusCode === 409 && ((_error$body = error.body) === null || _error$body === void 0 ? void 0 : _error$body.errorCode) === _types2.LocusErrorCodes.LOCUS_INACTIVE && isValidDataSetForSentinel) {
|
|
2075
|
+
var _error$body2;
|
|
2076
|
+
_loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received ").concat(error.statusCode, "/").concat((_error$body2 = error.body) === null || _error$body2 === void 0 ? void 0 : _error$body2.errorCode, " for data set \"").concat(dataSetName, "\", indicating that the meeting has ended"));
|
|
2077
|
+
this.stopAllTimers();
|
|
2078
|
+
throw new MeetingEndedError();
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Gets the current hashes from the locus for a specific data set.
|
|
2084
|
+
* @param {string} dataSetName
|
|
2085
|
+
* @param {string} currentRootHash
|
|
2086
|
+
* @returns {Object|null} An object containing the hashes and leaf count, or null if the hashes match and no sync is needed
|
|
2087
|
+
*/
|
|
2088
|
+
}, {
|
|
2089
|
+
key: "getHashesFromLocus",
|
|
2090
|
+
value: function getHashesFromLocus(dataSetName, currentRootHash) {
|
|
2091
|
+
var _this12 = this;
|
|
2092
|
+
_loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Requesting hashes for data set \"").concat(dataSetName, "\""));
|
|
2093
|
+
var dataSet = this.dataSets[dataSetName];
|
|
2094
|
+
var url = "".concat(dataSet.url, "/hashtree");
|
|
2095
|
+
return this.webexRequest({
|
|
2096
|
+
method: _constants2.HTTP_VERBS.GET,
|
|
2097
|
+
uri: url,
|
|
2098
|
+
qs: {
|
|
2099
|
+
rootHash: currentRootHash
|
|
2100
|
+
}
|
|
2101
|
+
}).then(function (response) {
|
|
2102
|
+
var _response$body, _response$body2;
|
|
2103
|
+
if (!response.body || (0, _lodash.isEmpty)(response.body)) {
|
|
2104
|
+
// 204 with empty body means our hashes match Locus, no sync needed
|
|
2105
|
+
_loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Got ").concat(response.statusCode, " with empty body for data set \"").concat(dataSetName, "\", hashes match - no sync needed"));
|
|
2106
|
+
return null;
|
|
2107
|
+
}
|
|
2108
|
+
var hashes = (_response$body = response.body) === null || _response$body === void 0 ? void 0 : _response$body.hashes;
|
|
2109
|
+
var dataSetFromResponse = (_response$body2 = response.body) === null || _response$body2 === void 0 ? void 0 : _response$body2.dataSet;
|
|
2110
|
+
if (!hashes || !(0, _isArray.default)(hashes)) {
|
|
2111
|
+
_loggerProxy.default.logger.warn("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Locus returned invalid hashes, response body="), response.body);
|
|
2112
|
+
throw new Error("Locus returned invalid hashes: ".concat(hashes));
|
|
2113
|
+
}
|
|
2114
|
+
_loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Received hashes for data set \"").concat(dataSetName, "\": ").concat((0, _stringify.default)(hashes)));
|
|
2115
|
+
return {
|
|
2116
|
+
hashes: hashes,
|
|
2117
|
+
dataSet: dataSetFromResponse
|
|
2118
|
+
};
|
|
2119
|
+
}).catch(function (error) {
|
|
2120
|
+
_loggerProxy.default.logger.error("HashTreeParser#getHashesFromLocus --> ".concat(_this12.debugId, " Error ").concat(error.statusCode, " fetching hashes for data set \"").concat(dataSetName, "\":"), error);
|
|
2121
|
+
_this12.checkForSentinelHttpResponse(error, dataSet.name);
|
|
2122
|
+
_metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_SYNC_FAILURE, {
|
|
2123
|
+
debugId: _this12.debugId,
|
|
2124
|
+
dataSetName: dataSetName,
|
|
2125
|
+
request: 'GET /hashtree',
|
|
2126
|
+
statusCode: error.statusCode,
|
|
2127
|
+
reason: error.message
|
|
2128
|
+
});
|
|
2129
|
+
throw error;
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* Sends a sync request to Locus for the specified data set.
|
|
2135
|
+
*
|
|
2136
|
+
* @param {InternalDataSet} dataSet The data set to sync.
|
|
2137
|
+
* @param {Object} options Either `{ isInitialization: true }` for init syncs (uses leafCount=1 with empty leaf data) or `{ mismatchedLeavesData }` for normal syncs.
|
|
2138
|
+
* @returns {Promise<HashTreeMessage|null>}
|
|
2139
|
+
*/
|
|
2140
|
+
}, {
|
|
2141
|
+
key: "sendSyncRequestToLocus",
|
|
2142
|
+
value: function sendSyncRequestToLocus(dataSet, options) {
|
|
2143
|
+
var _this13 = this;
|
|
2144
|
+
_loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(this.debugId, " Sending sync request for data set \"").concat(dataSet.name, "\""));
|
|
2145
|
+
var isInitialization = 'isInitialization' in options;
|
|
2146
|
+
var url = "".concat(dataSet.url, "/sync");
|
|
2147
|
+
var body = {
|
|
2148
|
+
leafCount: isInitialization ? 1 : dataSet.leafCount,
|
|
2149
|
+
leafDataEntries: []
|
|
2150
|
+
};
|
|
2151
|
+
if (isInitialization) {
|
|
2152
|
+
// initialization sync: Locus requires leafCount=1 with a single empty leaf
|
|
2153
|
+
body.leafDataEntries.push({
|
|
2154
|
+
leafIndex: 0,
|
|
2155
|
+
elementIds: []
|
|
2156
|
+
});
|
|
2157
|
+
} else {
|
|
2158
|
+
var mismatchedLeavesData = options.mismatchedLeavesData;
|
|
2159
|
+
(0, _keys.default)(mismatchedLeavesData).forEach(function (index) {
|
|
2160
|
+
var leafIndex = (0, _parseInt2.default)(index, 10);
|
|
2161
|
+
body.leafDataEntries.push({
|
|
2162
|
+
leafIndex: leafIndex,
|
|
2163
|
+
elementIds: mismatchedLeavesData[leafIndex]
|
|
2164
|
+
});
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
var ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : _constants3.EMPTY_HASH;
|
|
2168
|
+
return this.webexRequest({
|
|
2169
|
+
method: _constants2.HTTP_VERBS.POST,
|
|
2170
|
+
uri: url,
|
|
2171
|
+
qs: {
|
|
2172
|
+
rootHash: ourCurrentRootHash
|
|
2173
|
+
},
|
|
2174
|
+
body: body
|
|
2175
|
+
}).then(function (resp) {
|
|
2176
|
+
if (!resp.body || (0, _lodash.isEmpty)(resp.body)) {
|
|
2177
|
+
_loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this13.debugId, " Got ").concat(resp.statusCode, " with empty body for sync request for data set \"").concat(dataSet.name, "\", data should arrive via messages"));
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
return resp.body;
|
|
2181
|
+
}).catch(function (error) {
|
|
2182
|
+
_loggerProxy.default.logger.error("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this13.debugId, " Error ").concat(error.statusCode, " sending sync request for data set \"").concat(dataSet.name, "\":"), error);
|
|
2183
|
+
_this13.checkForSentinelHttpResponse(error, dataSet.name);
|
|
2184
|
+
_metrics.default.sendBehavioralMetric(_constants.default.HASH_TREE_SYNC_FAILURE, {
|
|
2185
|
+
debugId: _this13.debugId,
|
|
2186
|
+
dataSetName: dataSet.name,
|
|
2187
|
+
request: 'POST /sync',
|
|
2188
|
+
statusCode: error.statusCode,
|
|
2189
|
+
reason: error.message
|
|
2190
|
+
});
|
|
2191
|
+
throw error;
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
162
2194
|
}]);
|
|
163
2195
|
}();
|
|
164
2196
|
var _default = exports.default = HashTreeParser;
|