polfan-server-js-client 0.1.993 → 0.1.995
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/build/index.js +61 -69
- package/build/index.js.map +1 -1
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +19 -4
- package/build/types/types/src/schemes/commands/GetTopics.d.ts +1 -1
- package/package.json +1 -1
- package/src/state-tracker/RoomsManager.ts +6 -4
- package/src/state-tracker/TopicHistoryWindow.ts +39 -19
- package/src/types/src/schemes/commands/GetTopics.ts +1 -1
- package/tests/history-window.test.ts +34 -10
package/build/index.js
CHANGED
|
@@ -650,9 +650,10 @@ function TopicHistoryWindow_toPrimitive(input, hint) { if (TopicHistoryWindow_ty
|
|
|
650
650
|
|
|
651
651
|
var WindowState;
|
|
652
652
|
(function (WindowState) {
|
|
653
|
-
WindowState[WindowState["
|
|
654
|
-
WindowState[WindowState["
|
|
655
|
-
WindowState[WindowState["
|
|
653
|
+
WindowState[WindowState["EMPTY"] = 0] = "EMPTY";
|
|
654
|
+
WindowState[WindowState["LATEST_LIVE"] = 1] = "LATEST_LIVE";
|
|
655
|
+
WindowState[WindowState["LATEST_FETCHED"] = 2] = "LATEST_FETCHED";
|
|
656
|
+
WindowState[WindowState["PAST_FETCHED"] = 3] = "PAST_FETCHED";
|
|
656
657
|
})(WindowState || (WindowState = {}));
|
|
657
658
|
var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj) {
|
|
658
659
|
TopicHistoryWindow_inherits(TraversableRemoteCollection, _ObservableIndexedObj);
|
|
@@ -665,7 +666,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
665
666
|
}
|
|
666
667
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
667
668
|
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "limit", 50);
|
|
668
|
-
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.
|
|
669
|
+
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.EMPTY);
|
|
669
670
|
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "fetchingState", undefined);
|
|
670
671
|
return _this;
|
|
671
672
|
}
|
|
@@ -693,13 +694,13 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
693
694
|
switch (_context.prev = _context.next) {
|
|
694
695
|
case 0:
|
|
695
696
|
this.throwIfFetchingInProgress();
|
|
696
|
-
if (!(this.currentState === WindowState.
|
|
697
|
+
if (!(this.currentState === WindowState.LATEST_FETCHED)) {
|
|
697
698
|
_context.next = 3;
|
|
698
699
|
break;
|
|
699
700
|
}
|
|
700
701
|
return _context.abrupt("return");
|
|
701
702
|
case 3:
|
|
702
|
-
this.fetchingState = WindowState.
|
|
703
|
+
this.fetchingState = WindowState.LATEST_FETCHED;
|
|
703
704
|
_context.prev = 4;
|
|
704
705
|
_context.next = 7;
|
|
705
706
|
return this.fetchLatestItems();
|
|
@@ -712,7 +713,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
712
713
|
case 11:
|
|
713
714
|
this.deleteAll();
|
|
714
715
|
this.addItems(result, 'tail');
|
|
715
|
-
this.currentState = WindowState.
|
|
716
|
+
this.currentState = WindowState.LATEST_FETCHED;
|
|
716
717
|
case 14:
|
|
717
718
|
case "end":
|
|
718
719
|
return _context.stop();
|
|
@@ -735,7 +736,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
735
736
|
switch (_context2.prev = _context2.next) {
|
|
736
737
|
case 0:
|
|
737
738
|
this.throwIfFetchingInProgress();
|
|
738
|
-
this.fetchingState = WindowState.
|
|
739
|
+
this.fetchingState = WindowState.PAST_FETCHED;
|
|
739
740
|
_context2.prev = 2;
|
|
740
741
|
_context2.next = 5;
|
|
741
742
|
return this.fetchItemsBefore();
|
|
@@ -753,25 +754,13 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
753
754
|
return _context2.abrupt("return", this.resetToLatest());
|
|
754
755
|
case 11:
|
|
755
756
|
if (!result.length) {
|
|
756
|
-
_context2.next =
|
|
757
|
+
_context2.next = 15;
|
|
757
758
|
break;
|
|
758
759
|
}
|
|
759
760
|
this.addItems(result, 'head');
|
|
760
761
|
_context2.next = 15;
|
|
761
|
-
return this.
|
|
762
|
+
return this.refreshFetchedState();
|
|
762
763
|
case 15:
|
|
763
|
-
if (!_context2.sent) {
|
|
764
|
-
_context2.next = 19;
|
|
765
|
-
break;
|
|
766
|
-
}
|
|
767
|
-
_context2.t0 = WindowState.LATEST;
|
|
768
|
-
_context2.next = 20;
|
|
769
|
-
break;
|
|
770
|
-
case 19:
|
|
771
|
-
_context2.t0 = WindowState.PAST;
|
|
772
|
-
case 20:
|
|
773
|
-
this.currentState = _context2.t0;
|
|
774
|
-
case 21:
|
|
775
764
|
case "end":
|
|
776
765
|
return _context2.stop();
|
|
777
766
|
}
|
|
@@ -818,7 +807,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
818
807
|
}
|
|
819
808
|
this.addItems(result, 'tail');
|
|
820
809
|
_context3.next = 16;
|
|
821
|
-
return this.
|
|
810
|
+
return this.refreshFetchedState();
|
|
822
811
|
case 16:
|
|
823
812
|
case "end":
|
|
824
813
|
return _context3.stop();
|
|
@@ -832,9 +821,9 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
832
821
|
return fetchNext;
|
|
833
822
|
}()
|
|
834
823
|
}, {
|
|
835
|
-
key: "
|
|
824
|
+
key: "refreshFetchedState",
|
|
836
825
|
value: function () {
|
|
837
|
-
var
|
|
826
|
+
var _refreshFetchedState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
838
827
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
839
828
|
while (1) {
|
|
840
829
|
switch (_context4.prev = _context4.next) {
|
|
@@ -846,11 +835,11 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
846
835
|
_context4.next = 6;
|
|
847
836
|
break;
|
|
848
837
|
}
|
|
849
|
-
_context4.t0 = WindowState.
|
|
838
|
+
_context4.t0 = WindowState.LATEST_FETCHED;
|
|
850
839
|
_context4.next = 7;
|
|
851
840
|
break;
|
|
852
841
|
case 6:
|
|
853
|
-
_context4.t0 = WindowState.
|
|
842
|
+
_context4.t0 = WindowState.PAST_FETCHED;
|
|
854
843
|
case 7:
|
|
855
844
|
this.currentState = _context4.t0;
|
|
856
845
|
case 8:
|
|
@@ -860,11 +849,18 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
860
849
|
}
|
|
861
850
|
}, _callee4, this);
|
|
862
851
|
}));
|
|
863
|
-
function
|
|
864
|
-
return
|
|
852
|
+
function refreshFetchedState() {
|
|
853
|
+
return _refreshFetchedState.apply(this, arguments);
|
|
865
854
|
}
|
|
866
|
-
return
|
|
855
|
+
return refreshFetchedState;
|
|
867
856
|
}()
|
|
857
|
+
}, {
|
|
858
|
+
key: "refreshLiveState",
|
|
859
|
+
value: function refreshLiveState() {
|
|
860
|
+
if (this.currentState === WindowState.EMPTY && this.length) {
|
|
861
|
+
this.currentState = WindowState.LATEST_LIVE;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
868
864
|
}, {
|
|
869
865
|
key: "throwIfFetchingInProgress",
|
|
870
866
|
value: function throwIfFetchingInProgress() {
|
|
@@ -952,18 +948,11 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
|
|
|
952
948
|
while (1) {
|
|
953
949
|
switch (_context5.prev = _context5.next) {
|
|
954
950
|
case 0:
|
|
955
|
-
if (
|
|
956
|
-
|
|
957
|
-
|
|
951
|
+
if ([WindowState.LATEST_FETCHED, WindowState.LATEST_LIVE, WindowState.EMPTY].includes(this.state) && ev.location.roomId === this.roomId && ev.location.topicId === this.topicId) {
|
|
952
|
+
this.set(ev.message);
|
|
953
|
+
this.refreshLiveState();
|
|
958
954
|
}
|
|
959
|
-
|
|
960
|
-
if (!(this.state === WindowState.UNINITIALIZED)) {
|
|
961
|
-
_context5.next = 5;
|
|
962
|
-
break;
|
|
963
|
-
}
|
|
964
|
-
_context5.next = 5;
|
|
965
|
-
return this.refreshMode();
|
|
966
|
-
case 5:
|
|
955
|
+
case 1:
|
|
967
956
|
case "end":
|
|
968
957
|
return _context5.stop();
|
|
969
958
|
}
|
|
@@ -1189,7 +1178,7 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
|
|
|
1189
1178
|
return this.getLatestMessageId();
|
|
1190
1179
|
case 2:
|
|
1191
1180
|
lastMessageId = _context11.sent;
|
|
1192
|
-
return _context11.abrupt("return", lastMessageId ? this.has(lastMessageId) :
|
|
1181
|
+
return _context11.abrupt("return", lastMessageId ? this.has(lastMessageId) : true);
|
|
1193
1182
|
case 4:
|
|
1194
1183
|
case "end":
|
|
1195
1184
|
return _context11.stop();
|
|
@@ -2046,7 +2035,7 @@ var RoomsManager = /*#__PURE__*/function () {
|
|
|
2046
2035
|
value: function () {
|
|
2047
2036
|
var _getTopics = RoomsManager_asyncToGenerator( /*#__PURE__*/RoomsManager_regeneratorRuntime().mark(function _callee5(roomId, tryToFetchTopicIds) {
|
|
2048
2037
|
var _this3 = this;
|
|
2049
|
-
var
|
|
2038
|
+
var canFetch, idsToFetch, promise, _iterator, _step, topicId;
|
|
2050
2039
|
return RoomsManager_regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
2051
2040
|
while (1) {
|
|
2052
2041
|
switch (_context5.prev = _context5.next) {
|
|
@@ -2055,57 +2044,60 @@ var RoomsManager = /*#__PURE__*/function () {
|
|
|
2055
2044
|
return this.deferredSession.promise;
|
|
2056
2045
|
case 2:
|
|
2057
2046
|
if (!(tryToFetchTopicIds !== null && tryToFetchTopicIds !== void 0 && tryToFetchTopicIds.length)) {
|
|
2058
|
-
_context5.next =
|
|
2047
|
+
_context5.next = 23;
|
|
2059
2048
|
break;
|
|
2060
2049
|
}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2050
|
+
// Topic can be fetched if it isn't already cached and fetch is not already in progress
|
|
2051
|
+
canFetch = function canFetch(topicId) {
|
|
2052
|
+
var _this3$topics$get;
|
|
2053
|
+
return !((_this3$topics$get = _this3.topics.get(roomId)) !== null && _this3$topics$get !== void 0 && _this3$topics$get.has(topicId)) && !_this3.topicsPromises.has(roomId + topicId);
|
|
2054
|
+
};
|
|
2055
|
+
idsToFetch = tryToFetchTopicIds.filter(canFetch);
|
|
2056
|
+
if (idsToFetch.length) {
|
|
2065
2057
|
promise = this.tracker.client.send('GetTopics', {
|
|
2066
2058
|
roomId: roomId,
|
|
2067
|
-
|
|
2059
|
+
topicIds: idsToFetch
|
|
2068
2060
|
}).then(function (result) {
|
|
2069
|
-
var _this3$topics$
|
|
2070
|
-
return (_this3$topics$
|
|
2061
|
+
var _this3$topics$get2;
|
|
2062
|
+
return (_this3$topics$get2 = _this3.topics.get(result.data.location.roomId)) === null || _this3$topics$get2 === void 0 ? void 0 : _this3$topics$get2.set.apply(_this3$topics$get2, RoomsManager_toConsumableArray(result.data.topics));
|
|
2071
2063
|
});
|
|
2072
|
-
|
|
2064
|
+
idsToFetch.forEach(function (topicId) {
|
|
2073
2065
|
return _this3.topicsPromises.register(promise, roomId + topicId);
|
|
2074
2066
|
});
|
|
2075
2067
|
}
|
|
2076
2068
|
_iterator = RoomsManager_createForOfIteratorHelper(tryToFetchTopicIds);
|
|
2077
|
-
_context5.prev =
|
|
2069
|
+
_context5.prev = 7;
|
|
2078
2070
|
_iterator.s();
|
|
2079
|
-
case
|
|
2071
|
+
case 9:
|
|
2080
2072
|
if ((_step = _iterator.n()).done) {
|
|
2081
|
-
_context5.next =
|
|
2073
|
+
_context5.next = 15;
|
|
2082
2074
|
break;
|
|
2083
2075
|
}
|
|
2084
2076
|
topicId = _step.value;
|
|
2085
|
-
_context5.next =
|
|
2077
|
+
_context5.next = 13;
|
|
2086
2078
|
return this.topicsPromises.get(roomId + topicId);
|
|
2087
|
-
case
|
|
2088
|
-
_context5.next =
|
|
2079
|
+
case 13:
|
|
2080
|
+
_context5.next = 9;
|
|
2089
2081
|
break;
|
|
2090
|
-
case
|
|
2091
|
-
_context5.next =
|
|
2082
|
+
case 15:
|
|
2083
|
+
_context5.next = 20;
|
|
2092
2084
|
break;
|
|
2093
|
-
case
|
|
2094
|
-
_context5.prev =
|
|
2095
|
-
_context5.t0 = _context5["catch"](
|
|
2085
|
+
case 17:
|
|
2086
|
+
_context5.prev = 17;
|
|
2087
|
+
_context5.t0 = _context5["catch"](7);
|
|
2096
2088
|
_iterator.e(_context5.t0);
|
|
2097
|
-
case
|
|
2098
|
-
_context5.prev =
|
|
2089
|
+
case 20:
|
|
2090
|
+
_context5.prev = 20;
|
|
2099
2091
|
_iterator.f();
|
|
2100
|
-
return _context5.finish(
|
|
2101
|
-
case 22:
|
|
2102
|
-
return _context5.abrupt("return", this.topics.get(roomId));
|
|
2092
|
+
return _context5.finish(20);
|
|
2103
2093
|
case 23:
|
|
2094
|
+
return _context5.abrupt("return", this.topics.get(roomId));
|
|
2095
|
+
case 24:
|
|
2104
2096
|
case "end":
|
|
2105
2097
|
return _context5.stop();
|
|
2106
2098
|
}
|
|
2107
2099
|
}
|
|
2108
|
-
}, _callee5, this, [[
|
|
2100
|
+
}, _callee5, this, [[7, 17, 20, 23]]);
|
|
2109
2101
|
}));
|
|
2110
2102
|
function getTopics(_x3, _x4) {
|
|
2111
2103
|
return _getTopics.apply(this, arguments);
|