stream-chat 9.45.6 → 9.46.0

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.
@@ -0,0 +1,24 @@
1
+ import { BaseSearchSource } from './BaseSearchSource';
2
+ import { FilterBuilder, type FilterBuilderOptions } from '../pagination';
3
+ import type { Channel } from '../channel';
4
+ import type { ChannelMemberResponse, MemberFilters, MemberSort, QueryMembersOptions } from '../types';
5
+ import type { SearchSourceOptions } from './types';
6
+ type CustomContext = Record<string, unknown>;
7
+ export type ChannelMemberSearchSourceFilterBuilderContext<C extends CustomContext = CustomContext> = {
8
+ searchQuery?: string;
9
+ } & C;
10
+ export declare class ChannelMemberSearchSource<TFilterContext extends CustomContext = CustomContext> extends BaseSearchSource<ChannelMemberResponse> {
11
+ readonly type = "members";
12
+ channel: Channel;
13
+ filters: MemberFilters | undefined;
14
+ sort: MemberSort | undefined;
15
+ searchOptions: Omit<QueryMembersOptions, 'limit' | 'offset'> | undefined;
16
+ filterBuilder: FilterBuilder<MemberFilters, ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>>;
17
+ constructor(channel: Channel, options?: SearchSourceOptions, filterBuilderOptions?: FilterBuilderOptions<MemberFilters, ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>>);
18
+ canExecuteQuery: (newSearchString?: string) => boolean;
19
+ protected query(searchQuery: string): Promise<{
20
+ items: ChannelMemberResponse[];
21
+ }>;
22
+ protected filterQueryResults(items: ChannelMemberResponse[]): ChannelMemberResponse[];
23
+ }
24
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from './BaseSearchSource';
2
+ export * from './ChannelMemberSearchSource';
2
3
  export * from './SearchController';
3
4
  export * from './UserSearchSource';
4
5
  export * from './ChannelSearchSource';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat",
3
- "version": "9.45.6",
3
+ "version": "9.46.0",
4
4
  "description": "JS SDK for the Stream Chat API",
5
5
  "homepage": "https://getstream.io/chat/",
6
6
  "author": {
@@ -0,0 +1,85 @@
1
+ import { BaseSearchSource } from './BaseSearchSource';
2
+ import { FilterBuilder, type FilterBuilderOptions } from '../pagination';
3
+ import type { Channel } from '../channel';
4
+ import type {
5
+ ChannelMemberResponse,
6
+ MemberFilters,
7
+ MemberSort,
8
+ QueryMembersOptions,
9
+ } from '../types';
10
+ import type { SearchSourceOptions } from './types';
11
+
12
+ type CustomContext = Record<string, unknown>;
13
+
14
+ export type ChannelMemberSearchSourceFilterBuilderContext<
15
+ C extends CustomContext = CustomContext,
16
+ > = { searchQuery?: string } & C;
17
+
18
+ export class ChannelMemberSearchSource<
19
+ TFilterContext extends CustomContext = CustomContext,
20
+ > extends BaseSearchSource<ChannelMemberResponse> {
21
+ readonly type = 'members';
22
+ channel: Channel;
23
+ filters: MemberFilters | undefined;
24
+ sort: MemberSort | undefined;
25
+ searchOptions: Omit<QueryMembersOptions, 'limit' | 'offset'> | undefined;
26
+ filterBuilder: FilterBuilder<
27
+ MemberFilters,
28
+ ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
29
+ >;
30
+
31
+ constructor(
32
+ channel: Channel,
33
+ options?: SearchSourceOptions,
34
+ filterBuilderOptions: FilterBuilderOptions<
35
+ MemberFilters,
36
+ ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
37
+ > = {},
38
+ ) {
39
+ super(options);
40
+ this.channel = channel;
41
+ this.filterBuilder = new FilterBuilder<
42
+ MemberFilters,
43
+ ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
44
+ >({
45
+ initialFilterConfig: {
46
+ default: {
47
+ enabled: true,
48
+ generate: ({ searchQuery }) =>
49
+ searchQuery
50
+ ? {
51
+ $or: [
52
+ { name: { $autocomplete: searchQuery } },
53
+ { id: { $eq: searchQuery } },
54
+ ],
55
+ }
56
+ : null,
57
+ },
58
+ },
59
+ ...filterBuilderOptions,
60
+ });
61
+ }
62
+
63
+ canExecuteQuery = (newSearchString?: string) => {
64
+ const hasNewSearchQuery = typeof newSearchString !== 'undefined';
65
+
66
+ return this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery);
67
+ };
68
+
69
+ protected async query(searchQuery: string) {
70
+ const filters = this.filterBuilder.buildFilters({
71
+ baseFilters: this.filters,
72
+ context: {
73
+ searchQuery,
74
+ } as ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>,
75
+ });
76
+ const sort = this.sort ?? [];
77
+ const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
78
+ const { members } = await this.channel.queryMembers(filters ?? {}, sort, options);
79
+ return { items: members };
80
+ }
81
+
82
+ protected filterQueryResults(items: ChannelMemberResponse[]) {
83
+ return items;
84
+ }
85
+ }
@@ -130,7 +130,7 @@ export class MessageSearchSource<
130
130
  }
131
131
 
132
132
  protected async query(searchQuery: string) {
133
- if (!this.client.userID || !searchQuery || this.next === null) return { items: [] };
133
+ if (!this.client.userID || this.next === null) return { items: [] };
134
134
 
135
135
  const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
136
136
  baseFilters: {
@@ -1,4 +1,5 @@
1
1
  export * from './BaseSearchSource';
2
+ export * from './ChannelMemberSearchSource';
2
3
  export * from './SearchController';
3
4
  export * from './UserSearchSource';
4
5
  export * from './ChannelSearchSource';