@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.
- package/@react-bindings/hooks/search-state-hooks/index.ts +3 -0
- package/@react-bindings/index.ts +5 -0
- package/CHANGELOG.md +7 -0
- package/dist/@react-bindings/contexts/StreamSearchContext.d.ts +12 -0
- package/dist/@react-bindings/contexts/StreamSearchResultsContext.d.ts +12 -0
- package/dist/@react-bindings/hooks/search-state-hooks/index.d.ts +3 -0
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchQuery.d.ts +4 -0
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchResult.d.ts +8 -0
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchSources.d.ts +4 -0
- package/dist/@react-bindings/index.d.ts +5 -0
- package/dist/@react-bindings/wrappers/StreamSearch.d.ts +12 -0
- package/dist/@react-bindings/wrappers/StreamSearchResults.d.ts +12 -0
- package/dist/index-react-bindings.browser.cjs +85 -16
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +77 -17
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +85 -16
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +77 -17
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +26 -125
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +26 -125
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +26 -125
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +26 -125
- package/dist/index.node.js.map +1 -1
- package/dist/src/common/BaseSearchSource.d.ts +3 -1
- package/dist/src/common/FeedSearchSource.d.ts +5 -1
- package/dist/src/common/SearchController.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/ActivitySearchSource.ts +5 -15
- package/src/common/BaseSearchSource.ts +9 -9
- package/src/common/FeedSearchSource.ts +20 -65
- package/src/common/SearchController.ts +2 -0
- package/src/common/UserSearchSource.ts +9 -61
package/package.json
CHANGED
|
@@ -7,12 +7,6 @@ import { ActivityResponse } from '../gen/models';
|
|
|
7
7
|
export class ActivitySearchSource extends BaseSearchSource<ActivityResponse> {
|
|
8
8
|
readonly type = 'activity' as const;
|
|
9
9
|
private readonly client: FeedsClient;
|
|
10
|
-
// messageSearchChannelFilters: ChannelFilters | undefined;
|
|
11
|
-
// messageSearchFilters: MessageFilters | undefined;
|
|
12
|
-
// messageSearchSort: SearchMessageSort | undefined;
|
|
13
|
-
// channelQueryFilters: ChannelFilters | undefined;
|
|
14
|
-
// channelQuerySort: ChannelSort | undefined;
|
|
15
|
-
// channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
|
|
16
10
|
|
|
17
11
|
constructor(client: FeedsClient, options?: SearchSourceOptions) {
|
|
18
12
|
super(options);
|
|
@@ -20,12 +14,15 @@ export class ActivitySearchSource extends BaseSearchSource<ActivityResponse> {
|
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
protected async query(searchQuery: string) {
|
|
23
|
-
const { connected_user: connectedUser } =
|
|
17
|
+
const { connected_user: connectedUser } =
|
|
18
|
+
this.client.state.getLatestValue();
|
|
24
19
|
if (!connectedUser) return { items: [] };
|
|
25
20
|
|
|
26
21
|
const { activities: items, next } = await this.client.queryActivities({
|
|
27
22
|
sort: [{ direction: -1, field: 'created_at' }],
|
|
28
|
-
|
|
23
|
+
...(!this.allowEmptySearchString || searchQuery.length > 0
|
|
24
|
+
? { filter: { text: { $autocomplete: searchQuery } } }
|
|
25
|
+
: {}),
|
|
29
26
|
limit: 10,
|
|
30
27
|
next: this.next ?? undefined,
|
|
31
28
|
});
|
|
@@ -37,10 +34,3 @@ export class ActivitySearchSource extends BaseSearchSource<ActivityResponse> {
|
|
|
37
34
|
return items;
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// filter: {
|
|
43
|
-
// 'feed.name': { $autocomplete: searchQuery }
|
|
44
|
-
// 'feed.description': { $autocomplete: searchQuery }
|
|
45
|
-
// 'created_by.name': { $autocomplete: searchQuery }
|
|
46
|
-
// },
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { StateStore } from './StateStore';
|
|
2
2
|
import { debounce, type DebouncedFunc } from './utils';
|
|
3
3
|
|
|
4
|
-
export type SearchSourceType =
|
|
5
|
-
|
|
6
|
-
| 'users'
|
|
7
|
-
| 'messages'
|
|
8
|
-
| (string & {});
|
|
4
|
+
export type SearchSourceType = 'activity' | 'user' | 'feed' | (string & {});
|
|
5
|
+
|
|
9
6
|
export type QueryReturnValue<T> = { items: T[]; next?: string | null };
|
|
7
|
+
|
|
10
8
|
export type DebounceOptions = {
|
|
11
9
|
debounceMs: number;
|
|
12
10
|
};
|
|
@@ -14,7 +12,6 @@ type DebouncedExecQueryFunction = DebouncedFunc<
|
|
|
14
12
|
(searchString?: string) => Promise<void>
|
|
15
13
|
>;
|
|
16
14
|
|
|
17
|
-
|
|
18
15
|
export interface SearchSource<T = any> {
|
|
19
16
|
activate(): void;
|
|
20
17
|
|
|
@@ -46,7 +43,6 @@ export interface SearchSource<T = any> {
|
|
|
46
43
|
readonly type: SearchSourceType;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
50
46
|
export type SearchSourceState<T = any> = {
|
|
51
47
|
hasNext: boolean;
|
|
52
48
|
isActive: boolean;
|
|
@@ -61,24 +57,28 @@ export type SearchSourceOptions = {
|
|
|
61
57
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
62
58
|
debounceMs?: number;
|
|
63
59
|
pageSize?: number;
|
|
60
|
+
allowEmptySearchString?: boolean;
|
|
64
61
|
};
|
|
65
62
|
const DEFAULT_SEARCH_SOURCE_OPTIONS: Required<SearchSourceOptions> = {
|
|
66
63
|
debounceMs: 300,
|
|
67
64
|
pageSize: 10,
|
|
65
|
+
allowEmptySearchString: false,
|
|
68
66
|
} as const;
|
|
69
67
|
|
|
70
68
|
export abstract class BaseSearchSource<T> implements SearchSource<T> {
|
|
71
69
|
state: StateStore<SearchSourceState<T>>;
|
|
72
70
|
protected pageSize: number;
|
|
71
|
+
protected allowEmptySearchString: boolean;
|
|
73
72
|
abstract readonly type: SearchSourceType;
|
|
74
73
|
protected searchDebounced!: DebouncedExecQueryFunction;
|
|
75
74
|
|
|
76
75
|
protected constructor(options?: SearchSourceOptions) {
|
|
77
|
-
const { debounceMs, pageSize } = {
|
|
76
|
+
const { debounceMs, pageSize, allowEmptySearchString } = {
|
|
78
77
|
...DEFAULT_SEARCH_SOURCE_OPTIONS,
|
|
79
78
|
...options,
|
|
80
79
|
};
|
|
81
80
|
this.pageSize = pageSize;
|
|
81
|
+
this.allowEmptySearchString = allowEmptySearchString;
|
|
82
82
|
this.state = new StateStore<SearchSourceState<T>>(this.initialState);
|
|
83
83
|
this.setDebounceOptions({ debounceMs });
|
|
84
84
|
}
|
|
@@ -157,7 +157,7 @@ export abstract class BaseSearchSource<T> implements SearchSource<T> {
|
|
|
157
157
|
this.isActive &&
|
|
158
158
|
!this.isLoading &&
|
|
159
159
|
(this.hasNext || hasNewSearchQuery) &&
|
|
160
|
-
searchString
|
|
160
|
+
(this.allowEmptySearchString || searchString)
|
|
161
161
|
);
|
|
162
162
|
};
|
|
163
163
|
|
|
@@ -4,85 +4,40 @@ import type { SearchSourceOptions } from './BaseSearchSource';
|
|
|
4
4
|
import { FeedsClient } from '../FeedsClient';
|
|
5
5
|
import { Feed } from '../Feed';
|
|
6
6
|
|
|
7
|
+
export type FeedSearchSourceOptions = SearchSourceOptions & {
|
|
8
|
+
groupId?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
7
11
|
export class FeedSearchSource extends BaseSearchSource<Feed> {
|
|
8
12
|
readonly type = 'feed' as const;
|
|
9
13
|
private readonly client: FeedsClient;
|
|
10
|
-
|
|
11
|
-
// messageSearchFilters: MessageFilters | undefined;
|
|
12
|
-
// messageSearchSort: SearchMessageSort | undefined;
|
|
13
|
-
// channelQueryFilters: ChannelFilters | undefined;
|
|
14
|
-
// channelQuerySort: ChannelSort | undefined;
|
|
15
|
-
// channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
|
|
14
|
+
private readonly feedGroupId?: string | undefined;
|
|
16
15
|
|
|
17
|
-
constructor(client: FeedsClient, options?:
|
|
16
|
+
constructor(client: FeedsClient, options?: FeedSearchSourceOptions) {
|
|
18
17
|
super(options);
|
|
19
18
|
this.client = client;
|
|
19
|
+
this.feedGroupId = options?.groupId;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
protected async query(searchQuery: string) {
|
|
23
|
-
const { connected_user: connectedUser } =
|
|
23
|
+
const { connected_user: connectedUser } =
|
|
24
|
+
this.client.state.getLatestValue();
|
|
24
25
|
if (!connectedUser) return { items: [] };
|
|
25
26
|
|
|
26
|
-
// const channelFilters: ChannelFilters = {
|
|
27
|
-
// members: { $in: [this.client.userID] },
|
|
28
|
-
// ...this.messageSearchChannelFilters,
|
|
29
|
-
// } as ChannelFilters;
|
|
30
|
-
|
|
31
|
-
// const messageFilters: MessageFilters = {
|
|
32
|
-
// text: searchQuery,
|
|
33
|
-
// type: 'regular', // FIXME: type: 'reply' resp. do not filter by type and allow to jump to a message in a thread - missing support
|
|
34
|
-
// ...this.messageSearchFilters,
|
|
35
|
-
// } as MessageFilters;
|
|
36
|
-
|
|
37
|
-
// const sort: SearchMessageSort = {
|
|
38
|
-
// created_at: -1,
|
|
39
|
-
// ...this.messageSearchSort,
|
|
40
|
-
// };
|
|
41
|
-
|
|
42
|
-
// const options = {
|
|
43
|
-
// limit: this.pageSize,
|
|
44
|
-
// next: this.next,
|
|
45
|
-
// sort,
|
|
46
|
-
// } as SearchOptions;
|
|
47
|
-
|
|
48
|
-
// const { next, results } = await this.client.search(
|
|
49
|
-
// channelFilters,
|
|
50
|
-
// messageFilters,
|
|
51
|
-
// options,
|
|
52
|
-
// );
|
|
53
|
-
// const items = results.map(({ message }) => message);
|
|
54
|
-
|
|
55
|
-
// const cids = Array.from(
|
|
56
|
-
// items.reduce((acc, message) => {
|
|
57
|
-
// if (message.cid && !this.client.activeChannels[message.cid])
|
|
58
|
-
// acc.add(message.cid);
|
|
59
|
-
// return acc;
|
|
60
|
-
// }, new Set<string>()), // keep the cids unique
|
|
61
|
-
// );
|
|
62
|
-
// const allChannelsLoadedLocally = cids.length === 0;
|
|
63
|
-
// if (!allChannelsLoadedLocally) {
|
|
64
|
-
// await this.client.queryChannels(
|
|
65
|
-
// {
|
|
66
|
-
// cid: { $in: cids },
|
|
67
|
-
// ...this.channelQueryFilters,
|
|
68
|
-
// } as ChannelFilters,
|
|
69
|
-
// {
|
|
70
|
-
// last_message_at: -1,
|
|
71
|
-
// ...this.channelQuerySort,
|
|
72
|
-
// },
|
|
73
|
-
// this.channelQueryOptions,
|
|
74
|
-
// );
|
|
75
|
-
// }
|
|
76
|
-
|
|
77
27
|
const { feeds: items, next } = await this.client.queryFeeds({
|
|
78
28
|
filter: {
|
|
79
|
-
group_id:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
29
|
+
...(this.feedGroupId ? { group_id: this.feedGroupId } : {}),
|
|
30
|
+
...(!this.allowEmptySearchString || searchQuery.length > 0
|
|
31
|
+
? {
|
|
32
|
+
$or: [
|
|
33
|
+
{ name: { $autocomplete: searchQuery } },
|
|
34
|
+
{ description: { $autocomplete: searchQuery } },
|
|
35
|
+
{ 'created_by.name': { $autocomplete: searchQuery } },
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
: {}),
|
|
85
39
|
},
|
|
40
|
+
next: this.next ?? undefined,
|
|
86
41
|
});
|
|
87
42
|
|
|
88
43
|
return { items, next };
|
|
@@ -23,6 +23,8 @@ export class SearchController {
|
|
|
23
23
|
/**
|
|
24
24
|
* Not intended for direct use by integrators, might be removed without notice resulting in
|
|
25
25
|
* broken integrations.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
26
28
|
*/
|
|
27
29
|
_internalState: StateStore<InternalSearchControllerState>;
|
|
28
30
|
state: StateStore<SearchControllerState>;
|
|
@@ -7,12 +7,6 @@ import { UserResponse } from '../gen/models';
|
|
|
7
7
|
export class UserSearchSource extends BaseSearchSource<UserResponse> {
|
|
8
8
|
readonly type = 'user' as const;
|
|
9
9
|
private readonly client: FeedsClient;
|
|
10
|
-
// messageSearchChannelFilters: ChannelFilters | undefined;
|
|
11
|
-
// messageSearchFilters: MessageFilters | undefined;
|
|
12
|
-
// messageSearchSort: SearchMessageSort | undefined;
|
|
13
|
-
// channelQueryFilters: ChannelFilters | undefined;
|
|
14
|
-
// channelQuerySort: ChannelSort | undefined;
|
|
15
|
-
// channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
|
|
16
10
|
|
|
17
11
|
constructor(client: FeedsClient, options?: SearchSourceOptions) {
|
|
18
12
|
super(options);
|
|
@@ -20,66 +14,20 @@ export class UserSearchSource extends BaseSearchSource<UserResponse> {
|
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
protected async query(searchQuery: string) {
|
|
23
|
-
const { connected_user: connectedUser } =
|
|
17
|
+
const { connected_user: connectedUser } =
|
|
18
|
+
this.client.state.getLatestValue();
|
|
24
19
|
if (!connectedUser) return { items: [] };
|
|
25
20
|
|
|
26
|
-
// const channelFilters: ChannelFilters = {
|
|
27
|
-
// members: { $in: [this.client.userID] },
|
|
28
|
-
// ...this.messageSearchChannelFilters,
|
|
29
|
-
// } as ChannelFilters;
|
|
30
|
-
|
|
31
|
-
// const messageFilters: MessageFilters = {
|
|
32
|
-
// text: searchQuery,
|
|
33
|
-
// type: 'regular', // FIXME: type: 'reply' resp. do not filter by type and allow to jump to a message in a thread - missing support
|
|
34
|
-
// ...this.messageSearchFilters,
|
|
35
|
-
// } as MessageFilters;
|
|
36
|
-
|
|
37
|
-
// const sort: SearchMessageSort = {
|
|
38
|
-
// created_at: -1,
|
|
39
|
-
// ...this.messageSearchSort,
|
|
40
|
-
// };
|
|
41
|
-
|
|
42
|
-
// const options = {
|
|
43
|
-
// limit: this.pageSize,
|
|
44
|
-
// next: this.next,
|
|
45
|
-
// sort,
|
|
46
|
-
// } as SearchOptions;
|
|
47
|
-
|
|
48
|
-
// const { next, results } = await this.client.search(
|
|
49
|
-
// channelFilters,
|
|
50
|
-
// messageFilters,
|
|
51
|
-
// options,
|
|
52
|
-
// );
|
|
53
|
-
// const items = results.map(({ message }) => message);
|
|
54
|
-
|
|
55
|
-
// const cids = Array.from(
|
|
56
|
-
// items.reduce((acc, message) => {
|
|
57
|
-
// if (message.cid && !this.client.activeChannels[message.cid])
|
|
58
|
-
// acc.add(message.cid);
|
|
59
|
-
// return acc;
|
|
60
|
-
// }, new Set<string>()), // keep the cids unique
|
|
61
|
-
// );
|
|
62
|
-
// const allChannelsLoadedLocally = cids.length === 0;
|
|
63
|
-
// if (!allChannelsLoadedLocally) {
|
|
64
|
-
// await this.client.queryChannels(
|
|
65
|
-
// {
|
|
66
|
-
// cid: { $in: cids },
|
|
67
|
-
// ...this.channelQueryFilters,
|
|
68
|
-
// } as ChannelFilters,
|
|
69
|
-
// {
|
|
70
|
-
// last_message_at: -1,
|
|
71
|
-
// ...this.channelQuerySort,
|
|
72
|
-
// },
|
|
73
|
-
// this.channelQueryOptions,
|
|
74
|
-
// );
|
|
75
|
-
// }
|
|
76
|
-
|
|
77
21
|
const { users: items } = await this.client.queryUsers({
|
|
78
22
|
payload: {
|
|
79
23
|
filter_conditions: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
24
|
+
...(!this.allowEmptySearchString || searchQuery.length > 0
|
|
25
|
+
? {
|
|
26
|
+
name: {
|
|
27
|
+
$autocomplete: searchQuery,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
: {}),
|
|
83
31
|
},
|
|
84
32
|
},
|
|
85
33
|
});
|