@stream-io/feeds-client 0.1.9 → 0.1.10

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 (38) hide show
  1. package/@react-bindings/hooks/search-state-hooks/index.ts +3 -0
  2. package/@react-bindings/index.ts +5 -0
  3. package/CHANGELOG.md +7 -0
  4. package/dist/@react-bindings/contexts/StreamSearchContext.d.ts +12 -0
  5. package/dist/@react-bindings/contexts/StreamSearchResultsContext.d.ts +12 -0
  6. package/dist/@react-bindings/hooks/search-state-hooks/index.d.ts +3 -0
  7. package/dist/@react-bindings/hooks/search-state-hooks/useSearchQuery.d.ts +4 -0
  8. package/dist/@react-bindings/hooks/search-state-hooks/useSearchResult.d.ts +8 -0
  9. package/dist/@react-bindings/hooks/search-state-hooks/useSearchSources.d.ts +4 -0
  10. package/dist/@react-bindings/index.d.ts +5 -0
  11. package/dist/@react-bindings/wrappers/StreamSearch.d.ts +12 -0
  12. package/dist/@react-bindings/wrappers/StreamSearchResults.d.ts +12 -0
  13. package/dist/index-react-bindings.browser.cjs +85 -16
  14. package/dist/index-react-bindings.browser.cjs.map +1 -1
  15. package/dist/index-react-bindings.browser.js +77 -17
  16. package/dist/index-react-bindings.browser.js.map +1 -1
  17. package/dist/index-react-bindings.node.cjs +85 -16
  18. package/dist/index-react-bindings.node.cjs.map +1 -1
  19. package/dist/index-react-bindings.node.js +77 -17
  20. package/dist/index-react-bindings.node.js.map +1 -1
  21. package/dist/index.browser.cjs +26 -125
  22. package/dist/index.browser.cjs.map +1 -1
  23. package/dist/index.browser.js +26 -125
  24. package/dist/index.browser.js.map +1 -1
  25. package/dist/index.node.cjs +26 -125
  26. package/dist/index.node.cjs.map +1 -1
  27. package/dist/index.node.js +26 -125
  28. package/dist/index.node.js.map +1 -1
  29. package/dist/src/common/BaseSearchSource.d.ts +3 -1
  30. package/dist/src/common/FeedSearchSource.d.ts +5 -1
  31. package/dist/src/common/SearchController.d.ts +2 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +1 -1
  34. package/src/common/ActivitySearchSource.ts +5 -15
  35. package/src/common/BaseSearchSource.ts +9 -9
  36. package/src/common/FeedSearchSource.ts +20 -65
  37. package/src/common/SearchController.ts +2 -0
  38. package/src/common/UserSearchSource.ts +9 -61
@@ -5761,6 +5761,7 @@ const FeedOwnCapability = {
5761
5761
  const DEFAULT_SEARCH_SOURCE_OPTIONS = {
5762
5762
  debounceMs: 300,
5763
5763
  pageSize: 10,
5764
+ allowEmptySearchString: false,
5764
5765
  };
5765
5766
  class BaseSearchSource {
5766
5767
  constructor(options) {
@@ -5783,14 +5784,15 @@ class BaseSearchSource {
5783
5784
  return !!(this.isActive &&
5784
5785
  !this.isLoading &&
5785
5786
  (this.hasNext || hasNewSearchQuery) &&
5786
- searchString);
5787
+ (this.allowEmptySearchString || searchString));
5787
5788
  };
5788
5789
  this.search = (searchQuery) => this.searchDebounced(searchQuery);
5789
- const { debounceMs, pageSize } = {
5790
+ const { debounceMs, pageSize, allowEmptySearchString } = {
5790
5791
  ...DEFAULT_SEARCH_SOURCE_OPTIONS,
5791
5792
  ...options,
5792
5793
  };
5793
5794
  this.pageSize = pageSize;
5795
+ this.allowEmptySearchString = allowEmptySearchString;
5794
5796
  this.state = new StateStore(this.initialState);
5795
5797
  this.setDebounceOptions({ debounceMs });
5796
5798
  }
@@ -6006,12 +6008,6 @@ class SearchController {
6006
6008
  }
6007
6009
 
6008
6010
  class ActivitySearchSource extends BaseSearchSource {
6009
- // messageSearchChannelFilters: ChannelFilters | undefined;
6010
- // messageSearchFilters: MessageFilters | undefined;
6011
- // messageSearchSort: SearchMessageSort | undefined;
6012
- // channelQueryFilters: ChannelFilters | undefined;
6013
- // channelQuerySort: ChannelSort | undefined;
6014
- // channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
6015
6011
  constructor(client, options) {
6016
6012
  super(options);
6017
6013
  this.type = 'activity';
@@ -6023,7 +6019,9 @@ class ActivitySearchSource extends BaseSearchSource {
6023
6019
  return { items: [] };
6024
6020
  const { activities: items, next } = await this.client.queryActivities({
6025
6021
  sort: [{ direction: -1, field: 'created_at' }],
6026
- filter: { text: { $autocomplete: searchQuery } },
6022
+ ...(!this.allowEmptySearchString || searchQuery.length > 0
6023
+ ? { filter: { text: { $autocomplete: searchQuery } } }
6024
+ : {}),
6027
6025
  limit: 10,
6028
6026
  next: this.next ?? undefined,
6029
6027
  });
@@ -6033,19 +6031,8 @@ class ActivitySearchSource extends BaseSearchSource {
6033
6031
  return items;
6034
6032
  }
6035
6033
  }
6036
- // filter: {
6037
- // 'feed.name': { $autocomplete: searchQuery }
6038
- // 'feed.description': { $autocomplete: searchQuery }
6039
- // 'created_by.name': { $autocomplete: searchQuery }
6040
- // },
6041
6034
 
6042
6035
  class UserSearchSource extends BaseSearchSource {
6043
- // messageSearchChannelFilters: ChannelFilters | undefined;
6044
- // messageSearchFilters: MessageFilters | undefined;
6045
- // messageSearchSort: SearchMessageSort | undefined;
6046
- // channelQueryFilters: ChannelFilters | undefined;
6047
- // channelQuerySort: ChannelSort | undefined;
6048
- // channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
6049
6036
  constructor(client, options) {
6050
6037
  super(options);
6051
6038
  this.type = 'user';
@@ -6055,57 +6042,16 @@ class UserSearchSource extends BaseSearchSource {
6055
6042
  const { connected_user: connectedUser } = this.client.state.getLatestValue();
6056
6043
  if (!connectedUser)
6057
6044
  return { items: [] };
6058
- // const channelFilters: ChannelFilters = {
6059
- // members: { $in: [this.client.userID] },
6060
- // ...this.messageSearchChannelFilters,
6061
- // } as ChannelFilters;
6062
- // const messageFilters: MessageFilters = {
6063
- // text: searchQuery,
6064
- // type: 'regular', // FIXME: type: 'reply' resp. do not filter by type and allow to jump to a message in a thread - missing support
6065
- // ...this.messageSearchFilters,
6066
- // } as MessageFilters;
6067
- // const sort: SearchMessageSort = {
6068
- // created_at: -1,
6069
- // ...this.messageSearchSort,
6070
- // };
6071
- // const options = {
6072
- // limit: this.pageSize,
6073
- // next: this.next,
6074
- // sort,
6075
- // } as SearchOptions;
6076
- // const { next, results } = await this.client.search(
6077
- // channelFilters,
6078
- // messageFilters,
6079
- // options,
6080
- // );
6081
- // const items = results.map(({ message }) => message);
6082
- // const cids = Array.from(
6083
- // items.reduce((acc, message) => {
6084
- // if (message.cid && !this.client.activeChannels[message.cid])
6085
- // acc.add(message.cid);
6086
- // return acc;
6087
- // }, new Set<string>()), // keep the cids unique
6088
- // );
6089
- // const allChannelsLoadedLocally = cids.length === 0;
6090
- // if (!allChannelsLoadedLocally) {
6091
- // await this.client.queryChannels(
6092
- // {
6093
- // cid: { $in: cids },
6094
- // ...this.channelQueryFilters,
6095
- // } as ChannelFilters,
6096
- // {
6097
- // last_message_at: -1,
6098
- // ...this.channelQuerySort,
6099
- // },
6100
- // this.channelQueryOptions,
6101
- // );
6102
- // }
6103
6045
  const { users: items } = await this.client.queryUsers({
6104
6046
  payload: {
6105
6047
  filter_conditions: {
6106
- name: {
6107
- $autocomplete: searchQuery,
6108
- },
6048
+ ...(!this.allowEmptySearchString || searchQuery.length > 0
6049
+ ? {
6050
+ name: {
6051
+ $autocomplete: searchQuery,
6052
+ },
6053
+ }
6054
+ : {}),
6109
6055
  },
6110
6056
  },
6111
6057
  });
@@ -6117,75 +6063,30 @@ class UserSearchSource extends BaseSearchSource {
6117
6063
  }
6118
6064
 
6119
6065
  class FeedSearchSource extends BaseSearchSource {
6120
- // messageSearchChannelFilters: ChannelFilters | undefined;
6121
- // messageSearchFilters: MessageFilters | undefined;
6122
- // messageSearchSort: SearchMessageSort | undefined;
6123
- // channelQueryFilters: ChannelFilters | undefined;
6124
- // channelQuerySort: ChannelSort | undefined;
6125
- // channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
6126
6066
  constructor(client, options) {
6127
6067
  super(options);
6128
6068
  this.type = 'feed';
6129
6069
  this.client = client;
6070
+ this.feedGroupId = options?.groupId;
6130
6071
  }
6131
6072
  async query(searchQuery) {
6132
6073
  const { connected_user: connectedUser } = this.client.state.getLatestValue();
6133
6074
  if (!connectedUser)
6134
6075
  return { items: [] };
6135
- // const channelFilters: ChannelFilters = {
6136
- // members: { $in: [this.client.userID] },
6137
- // ...this.messageSearchChannelFilters,
6138
- // } as ChannelFilters;
6139
- // const messageFilters: MessageFilters = {
6140
- // text: searchQuery,
6141
- // type: 'regular', // FIXME: type: 'reply' resp. do not filter by type and allow to jump to a message in a thread - missing support
6142
- // ...this.messageSearchFilters,
6143
- // } as MessageFilters;
6144
- // const sort: SearchMessageSort = {
6145
- // created_at: -1,
6146
- // ...this.messageSearchSort,
6147
- // };
6148
- // const options = {
6149
- // limit: this.pageSize,
6150
- // next: this.next,
6151
- // sort,
6152
- // } as SearchOptions;
6153
- // const { next, results } = await this.client.search(
6154
- // channelFilters,
6155
- // messageFilters,
6156
- // options,
6157
- // );
6158
- // const items = results.map(({ message }) => message);
6159
- // const cids = Array.from(
6160
- // items.reduce((acc, message) => {
6161
- // if (message.cid && !this.client.activeChannels[message.cid])
6162
- // acc.add(message.cid);
6163
- // return acc;
6164
- // }, new Set<string>()), // keep the cids unique
6165
- // );
6166
- // const allChannelsLoadedLocally = cids.length === 0;
6167
- // if (!allChannelsLoadedLocally) {
6168
- // await this.client.queryChannels(
6169
- // {
6170
- // cid: { $in: cids },
6171
- // ...this.channelQueryFilters,
6172
- // } as ChannelFilters,
6173
- // {
6174
- // last_message_at: -1,
6175
- // ...this.channelQuerySort,
6176
- // },
6177
- // this.channelQueryOptions,
6178
- // );
6179
- // }
6180
6076
  const { feeds: items, next } = await this.client.queryFeeds({
6181
6077
  filter: {
6182
- group_id: 'user',
6183
- $or: [
6184
- { name: { $autocomplete: searchQuery } },
6185
- { description: { $autocomplete: searchQuery } },
6186
- { 'created_by.name': { $autocomplete: searchQuery } },
6187
- ],
6078
+ ...(this.feedGroupId ? { group_id: this.feedGroupId } : {}),
6079
+ ...(!this.allowEmptySearchString || searchQuery.length > 0
6080
+ ? {
6081
+ $or: [
6082
+ { name: { $autocomplete: searchQuery } },
6083
+ { description: { $autocomplete: searchQuery } },
6084
+ { 'created_by.name': { $autocomplete: searchQuery } },
6085
+ ],
6086
+ }
6087
+ : {}),
6188
6088
  },
6089
+ next: this.next ?? undefined,
6189
6090
  });
6190
6091
  return { items, next };
6191
6092
  }