@stream-io/feeds-client 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index-react-bindings.browser.cjs +36 -19
  3. package/dist/index-react-bindings.browser.cjs.map +1 -1
  4. package/dist/index-react-bindings.browser.js +36 -19
  5. package/dist/index-react-bindings.browser.js.map +1 -1
  6. package/dist/index-react-bindings.node.cjs +36 -19
  7. package/dist/index-react-bindings.node.cjs.map +1 -1
  8. package/dist/index-react-bindings.node.js +36 -19
  9. package/dist/index-react-bindings.node.js.map +1 -1
  10. package/dist/index.browser.cjs +35 -20
  11. package/dist/index.browser.cjs.map +1 -1
  12. package/dist/index.browser.js +35 -20
  13. package/dist/index.browser.js.map +1 -1
  14. package/dist/index.node.cjs +35 -20
  15. package/dist/index.node.cjs.map +1 -1
  16. package/dist/index.node.js +35 -20
  17. package/dist/index.node.js.map +1 -1
  18. package/dist/src/common/real-time/StableWSConnection.d.ts +3 -3
  19. package/dist/src/common/real-time/event-models.d.ts +14 -0
  20. package/dist/src/common/search/FeedSearchSource.d.ts +2 -2
  21. package/dist/src/feed/event-handlers/feed/handle-feed-updated.d.ts +2 -2
  22. package/dist/src/feeds-client/feeds-client.d.ts +3 -2
  23. package/dist/src/gen/models/index.d.ts +18 -8
  24. package/dist/src/types.d.ts +2 -2
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/common/real-time/event-models.ts +16 -0
  28. package/src/common/search/BaseSearchSource.ts +1 -1
  29. package/src/common/search/FeedSearchSource.ts +3 -2
  30. package/src/feed/event-handlers/feed/handle-feed-updated.ts +2 -2
  31. package/src/feeds-client/feeds-client.ts +51 -20
  32. package/src/gen/models/index.ts +26 -8
  33. package/src/types.ts +5 -2
@@ -5717,6 +5717,11 @@ function handleUserUpdated(event) {
5717
5717
  });
5718
5718
  }
5719
5719
 
5720
+ var UnhandledErrorType;
5721
+ (function (UnhandledErrorType) {
5722
+ UnhandledErrorType["ReconnectionReconciliation"] = "reconnection-reconciliation";
5723
+ })(UnhandledErrorType || (UnhandledErrorType = {}));
5724
+
5720
5725
  class FeedsClient extends FeedsApi {
5721
5726
  constructor(apiKey, options) {
5722
5727
  const tokenManager = new TokenManager();
@@ -5726,6 +5731,22 @@ class FeedsClient extends FeedsApi {
5726
5731
  this.eventDispatcher = new EventDispatcher();
5727
5732
  this.activeFeeds = {};
5728
5733
  this.healthyConnectionChangedEventCount = 0;
5734
+ this.recoverOnReconnect = async () => {
5735
+ this.healthyConnectionChangedEventCount++;
5736
+ // we skip the first event as we could potentially be querying twice
5737
+ if (this.healthyConnectionChangedEventCount > 1) {
5738
+ const entries = Object.entries(this.activeFeeds);
5739
+ const results = await Promise.allSettled(entries.map(([, feed]) => feed.synchronize()));
5740
+ const failures = results.flatMap((result, index) => result.status === 'rejected'
5741
+ ? [{ feed: entries[index][0], reason: result.reason }]
5742
+ : []);
5743
+ this.eventDispatcher.dispatch({
5744
+ type: 'errors.unhandled',
5745
+ error_type: UnhandledErrorType.ReconnectionReconciliation,
5746
+ failures,
5747
+ });
5748
+ }
5749
+ };
5729
5750
  this.pollFromState = (id) => this.polls_by_id.get(id);
5730
5751
  this.connectUser = async (user, tokenProvider) => {
5731
5752
  if (this.state.getLatestValue().connected_user !== undefined ||
@@ -5821,18 +5842,18 @@ class FeedsClient extends FeedsApi {
5821
5842
  };
5822
5843
  this.getOrCreateActiveFeed = (group, id, data, watch) => {
5823
5844
  const fid = `${group}:${id}`;
5824
- if (this.activeFeeds[fid]) {
5825
- const feed = this.activeFeeds[fid];
5826
- if (watch && !feed.currentState.watch) {
5827
- handleWatchStarted.bind(feed)();
5828
- }
5829
- return feed;
5845
+ if (!this.activeFeeds[fid]) {
5846
+ this.activeFeeds[fid] = new Feed(this, group, id, data, watch);
5830
5847
  }
5831
- else {
5832
- const feed = new Feed(this, group, id, data, watch);
5833
- this.activeFeeds[fid] = feed;
5834
- return feed;
5848
+ const feed = this.activeFeeds[fid];
5849
+ if (!feed.currentState.watch) {
5850
+ // feed isn't watched and may be stale, update it
5851
+ if (data)
5852
+ handleFeedUpdated.call(feed, { feed: data });
5853
+ if (watch)
5854
+ handleWatchStarted.call(feed);
5835
5855
  }
5856
+ return feed;
5836
5857
  };
5837
5858
  this.state = new StateStore({
5838
5859
  connected_user: undefined,
@@ -5850,13 +5871,7 @@ class FeedsClient extends FeedsApi {
5850
5871
  const { online } = event;
5851
5872
  this.state.partialNext({ is_ws_connection_healthy: online });
5852
5873
  if (online) {
5853
- this.healthyConnectionChangedEventCount++;
5854
- // we skip the first event as we could potentially be querying twice
5855
- if (this.healthyConnectionChangedEventCount > 1) {
5856
- for (const activeFeed of Object.values(this.activeFeeds)) {
5857
- activeFeed.synchronize();
5858
- }
5859
- }
5874
+ this.recoverOnReconnect();
5860
5875
  }
5861
5876
  else {
5862
5877
  for (const activeFeed of Object.values(this.activeFeeds)) {
@@ -5970,7 +5985,7 @@ class FeedsClient extends FeedsApi {
5970
5985
  }
5971
5986
  async queryFeeds(request) {
5972
5987
  const response = await this._queryFeeds(request);
5973
- const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
5988
+ const feeds = response.feeds.map((feedResponse) => this.getOrCreateActiveFeed(feedResponse.group_id, feedResponse.id, feedResponse, request?.watch));
5974
5989
  return {
5975
5990
  feeds,
5976
5991
  next: response.next,
@@ -6422,7 +6437,9 @@ const useSearchResult = (sourceFromProps) => {
6422
6437
  const source = sourceFromProps ?? sourceFromContext;
6423
6438
  const { items, error, isLoading, hasNext } = useStateStore(source?.state, selector$2) ?? {};
6424
6439
  const loadMore = useStableCallback(async () => {
6425
- source?.search();
6440
+ if (hasNext) {
6441
+ source?.search();
6442
+ }
6426
6443
  });
6427
6444
  return react.useMemo(() => ({ items, error, isLoading, hasNext, loadMore }), [error, hasNext, isLoading, items, loadMore]);
6428
6445
  };