@stream-io/feeds-client 0.1.8 → 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/hooks/util/index.ts +1 -0
- package/@react-bindings/index.ts +5 -0
- package/CHANGELOG.md +22 -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/hooks/util/index.d.ts +1 -0
- package/dist/@react-bindings/hooks/util/useBookmarkActions.d.ts +13 -0
- package/dist/@react-bindings/hooks/util/useReactionActions.d.ts +1 -1
- 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 +431 -156
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +422 -157
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +431 -156
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +422 -157
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +346 -264
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +346 -265
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +346 -264
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +346 -265
- package/dist/index.node.js.map +1 -1
- package/dist/src/Feed.d.ts +40 -9
- package/dist/src/FeedsClient.d.ts +8 -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/src/gen-imports.d.ts +1 -1
- package/dist/src/state-updates/follow-utils.d.ts +19 -0
- package/dist/src/state-updates/state-update-queue.d.ts +15 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Feed.ts +226 -192
- package/src/FeedsClient.ts +75 -3
- 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/src/gen-imports.ts +1 -1
- package/src/state-updates/activity-reaction-utils.test.ts +1 -0
- package/src/state-updates/activity-utils.test.ts +1 -0
- package/src/state-updates/follow-utils.test.ts +552 -0
- package/src/state-updates/follow-utils.ts +126 -0
- package/src/state-updates/state-update-queue.test.ts +53 -0
- package/src/state-updates/state-update-queue.ts +35 -0
- package/src/utils.test.ts +175 -0
- package/src/utils.ts +20 -0
package/dist/src/Feed.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActivityRequest, FeedResponse, GetOrCreateFeedRequest, GetOrCreateFeedResponse, QueryFollowsRequest, WSEvent, ActivityResponse, CommentResponse, SingleFollowRequest, QueryFeedMembersRequest, SortParamRequest } from './gen/models';
|
|
1
|
+
import { ActivityRequest, FeedResponse, GetOrCreateFeedRequest, GetOrCreateFeedResponse, QueryFollowsRequest, WSEvent, ActivityResponse, CommentResponse, SingleFollowRequest, QueryFeedMembersRequest, SortParamRequest, FollowResponse } from './gen/models';
|
|
2
2
|
import { StateStore } from './common/StateStore';
|
|
3
3
|
import { EventDispatcher } from './common/EventDispatcher';
|
|
4
4
|
import { FeedApi } from './gen/feeds/FeedApi';
|
|
@@ -41,17 +41,17 @@ export type FeedState = Omit<Partial<GetOrCreateFeedResponse & FeedResponse>, 'f
|
|
|
41
41
|
* comments_by_entity_id: {
|
|
42
42
|
* 'activity-1': {
|
|
43
43
|
* comments: [comment1],
|
|
44
|
-
*
|
|
44
|
+
* entity_parent_id: undefined,
|
|
45
45
|
* },
|
|
46
46
|
* 'comment-1': {
|
|
47
47
|
* comments: [comment2],
|
|
48
|
-
*
|
|
48
|
+
* entity_parent_id: 'activity-1', // parent store where "comment-1" is located in "comments" array
|
|
49
49
|
* }
|
|
50
50
|
* }
|
|
51
51
|
* }
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
entity_parent_id?: ActivityIdOrCommentId;
|
|
55
55
|
comments?: CommentResponse[];
|
|
56
56
|
} | undefined>;
|
|
57
57
|
followers_pagination?: LoadingStates & {
|
|
@@ -64,19 +64,47 @@ export type FeedState = Omit<Partial<GetOrCreateFeedResponse & FeedResponse>, 'f
|
|
|
64
64
|
sort?: SortParamRequest[];
|
|
65
65
|
};
|
|
66
66
|
last_get_or_create_request_config?: GetOrCreateFeedRequest;
|
|
67
|
+
/**
|
|
68
|
+
* `true` if the feed is receiving real-time updates via WebSocket
|
|
69
|
+
*/
|
|
70
|
+
watch: boolean;
|
|
67
71
|
};
|
|
68
72
|
export declare class Feed extends FeedApi {
|
|
69
73
|
readonly state: StateStore<FeedState>;
|
|
70
74
|
private static readonly noop;
|
|
75
|
+
private readonly stateUpdateQueue;
|
|
71
76
|
private readonly eventHandlers;
|
|
72
77
|
protected eventDispatcher: EventDispatcher<WSEvent['type'], WSEvent>;
|
|
73
|
-
constructor(client: FeedsClient, groupId: 'user' | 'timeline' | (string & {}), id: string, data?: FeedResponse);
|
|
78
|
+
constructor(client: FeedsClient, groupId: 'user' | 'timeline' | (string & {}), id: string, data?: FeedResponse, watch?: boolean);
|
|
74
79
|
private readonly client;
|
|
75
80
|
get fid(): string;
|
|
76
81
|
get currentState(): FeedState;
|
|
77
82
|
private handleCommentReactionEvent;
|
|
78
83
|
synchronize(): Promise<void>;
|
|
79
84
|
getOrCreate(request?: GetOrCreateFeedRequest): Promise<StreamResponse<GetOrCreateFeedResponse>>;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
handleFollowCreated(follow: FollowResponse): void;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
handleFollowDeleted(follow: FollowResponse | {
|
|
93
|
+
source_feed: {
|
|
94
|
+
fid: string;
|
|
95
|
+
};
|
|
96
|
+
target_feed: {
|
|
97
|
+
fid: string;
|
|
98
|
+
};
|
|
99
|
+
}): void;
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
handleWatchStopped(): void;
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
handleWatchStarted(): void;
|
|
80
108
|
private handleBookmarkAdded;
|
|
81
109
|
private handleBookmarkDeleted;
|
|
82
110
|
private handleBookmarkUpdated;
|
|
@@ -84,14 +112,17 @@ export declare class Feed extends FeedApi {
|
|
|
84
112
|
* Returns index of the provided comment object.
|
|
85
113
|
*/
|
|
86
114
|
private getCommentIndex;
|
|
87
|
-
|
|
88
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Load child comments of entity (activity or comment) into the state, if the target entity is comment,
|
|
117
|
+
* `entityParentId` should be provided (`CommentResponse.parent_id ?? CommentResponse.object_id`).
|
|
118
|
+
*/
|
|
119
|
+
private loadCommentsIntoState;
|
|
89
120
|
private loadNextPageComments;
|
|
90
121
|
loadNextPageActivityComments(activity: ActivityResponse, request?: Partial<Omit<GetCommentsRequest, 'object_id' | 'object_type' | 'next'>>): Promise<void>;
|
|
91
122
|
loadNextPageCommentReplies(comment: CommentResponse, request?: Partial<Omit<GetCommentsRepliesRequest, 'comment_id' | 'next'>>): Promise<void>;
|
|
92
123
|
private loadNextPageFollows;
|
|
93
|
-
loadNextPageFollowers(request: Pick<QueryFollowsRequest, 'limit'>): Promise<void>;
|
|
94
|
-
loadNextPageFollowing(request: Pick<QueryFollowsRequest, 'limit'>): Promise<void>;
|
|
124
|
+
loadNextPageFollowers(request: Pick<QueryFollowsRequest, 'limit' | 'sort'>): Promise<void>;
|
|
125
|
+
loadNextPageFollowing(request: Pick<QueryFollowsRequest, 'limit' | 'sort'>): Promise<void>;
|
|
95
126
|
loadNextPageMembers(request: Omit<QueryFeedMembersRequest, 'next' | 'prev'>): Promise<void>;
|
|
96
127
|
/**
|
|
97
128
|
* Method which queries followers of this feed (feeds which target this feed).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FeedsApi } from './gen/feeds/FeedsApi';
|
|
2
|
-
import { ActivityResponse, FileUploadRequest, ImageUploadRequest, OwnUser, PollResponse, PollVotesResponse, QueryFeedsRequest, QueryPollVotesRequest, UserRequest } from './gen/models';
|
|
2
|
+
import { ActivityResponse, FileUploadRequest, FollowBatchRequest, ImageUploadRequest, OwnUser, PollResponse, PollVotesResponse, QueryFeedsRequest, QueryPollVotesRequest, SingleFollowRequest, UserRequest } from './gen/models';
|
|
3
3
|
import { FeedsEvent, StreamFile, TokenOrProvider } from './types';
|
|
4
4
|
import { StateStore } from './common/StateStore';
|
|
5
5
|
import { Feed } from './Feed';
|
|
@@ -63,6 +63,13 @@ export declare class FeedsClient extends FeedsApi {
|
|
|
63
63
|
updateNetworkConnectionStatus: (event: {
|
|
64
64
|
type: "online" | "offline";
|
|
65
65
|
} | Event) => void;
|
|
66
|
+
follow(request: SingleFollowRequest): Promise<StreamResponse<import("./gen/models").SingleFollowResponse>>;
|
|
67
|
+
followBatch(request: FollowBatchRequest): Promise<StreamResponse<import("./gen/models").FollowBatchResponse>>;
|
|
68
|
+
unfollow(request: SingleFollowRequest): Promise<StreamResponse<import("./gen/models").UnfollowResponse>>;
|
|
69
|
+
stopWatchingFeed(request: {
|
|
70
|
+
feed_group_id: string;
|
|
71
|
+
feed_id: string;
|
|
72
|
+
}): Promise<StreamResponse<import("./gen/models").Response>>;
|
|
66
73
|
private readonly getOrCreateActiveFeed;
|
|
67
74
|
private findActiveFeedByActivityId;
|
|
68
75
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateStore } from './StateStore';
|
|
2
2
|
import { type DebouncedFunc } from './utils';
|
|
3
|
-
export type SearchSourceType = '
|
|
3
|
+
export type SearchSourceType = 'activity' | 'user' | 'feed' | (string & {});
|
|
4
4
|
export type QueryReturnValue<T> = {
|
|
5
5
|
items: T[];
|
|
6
6
|
next?: string | null;
|
|
@@ -44,10 +44,12 @@ export type SearchSourceOptions = {
|
|
|
44
44
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
45
45
|
debounceMs?: number;
|
|
46
46
|
pageSize?: number;
|
|
47
|
+
allowEmptySearchString?: boolean;
|
|
47
48
|
};
|
|
48
49
|
export declare abstract class BaseSearchSource<T> implements SearchSource<T> {
|
|
49
50
|
state: StateStore<SearchSourceState<T>>;
|
|
50
51
|
protected pageSize: number;
|
|
52
|
+
protected allowEmptySearchString: boolean;
|
|
51
53
|
abstract readonly type: SearchSourceType;
|
|
52
54
|
protected searchDebounced: DebouncedExecQueryFunction;
|
|
53
55
|
protected constructor(options?: SearchSourceOptions);
|
|
@@ -2,10 +2,14 @@ import { BaseSearchSource } from './BaseSearchSource';
|
|
|
2
2
|
import type { SearchSourceOptions } from './BaseSearchSource';
|
|
3
3
|
import { FeedsClient } from '../FeedsClient';
|
|
4
4
|
import { Feed } from '../Feed';
|
|
5
|
+
export type FeedSearchSourceOptions = SearchSourceOptions & {
|
|
6
|
+
groupId?: string;
|
|
7
|
+
};
|
|
5
8
|
export declare class FeedSearchSource extends BaseSearchSource<Feed> {
|
|
6
9
|
readonly type: "feed";
|
|
7
10
|
private readonly client;
|
|
8
|
-
|
|
11
|
+
private readonly feedGroupId?;
|
|
12
|
+
constructor(client: FeedsClient, options?: FeedSearchSourceOptions);
|
|
9
13
|
protected query(searchQuery: string): Promise<{
|
|
10
14
|
items: never[];
|
|
11
15
|
next?: undefined;
|
|
@@ -17,6 +17,8 @@ export declare class SearchController {
|
|
|
17
17
|
/**
|
|
18
18
|
* Not intended for direct use by integrators, might be removed without notice resulting in
|
|
19
19
|
* broken integrations.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
20
22
|
*/
|
|
21
23
|
_internalState: StateStore<InternalSearchControllerState>;
|
|
22
24
|
state: StateStore<SearchControllerState>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FeedState } from '../Feed';
|
|
2
|
+
import { FollowResponse } from '../gen/models';
|
|
3
|
+
import { UpdateStateResult } from '../types-internal';
|
|
4
|
+
export declare const handleFollowCreated: (follow: FollowResponse, currentState: FeedState, currentFeedId: string, connectedUserId?: string) => UpdateStateResult<{
|
|
5
|
+
data: FeedState;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const handleFollowDeleted: (follow: FollowResponse | {
|
|
8
|
+
source_feed: {
|
|
9
|
+
fid: string;
|
|
10
|
+
};
|
|
11
|
+
target_feed: {
|
|
12
|
+
fid: string;
|
|
13
|
+
};
|
|
14
|
+
}, currentState: FeedState, currentFeedId: string, connectedUserId?: string) => UpdateStateResult<{
|
|
15
|
+
data: FeedState;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const handleFollowUpdated: (currentState: FeedState) => UpdateStateResult<{
|
|
18
|
+
data: FeedState;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FollowResponse } from '../gen/models';
|
|
2
|
+
export declare const shouldUpdateState: ({ stateUpdateId, stateUpdateQueue, watch, }: {
|
|
3
|
+
stateUpdateId: string;
|
|
4
|
+
stateUpdateQueue: Set<string>;
|
|
5
|
+
watch: boolean;
|
|
6
|
+
}) => boolean;
|
|
7
|
+
export declare const getStateUpdateQueueIdForFollow: (follow: FollowResponse) => string;
|
|
8
|
+
export declare const getStateUpdateQueueIdForUnfollow: (follow: FollowResponse | {
|
|
9
|
+
source_feed: {
|
|
10
|
+
fid: string;
|
|
11
|
+
};
|
|
12
|
+
target_feed: {
|
|
13
|
+
fid: string;
|
|
14
|
+
};
|
|
15
|
+
}) => string;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const isCommentResponse: (entity: CommentParent) => entity is Com
|
|
|
7
7
|
export declare const Constants: {
|
|
8
8
|
readonly DEFAULT_COMMENT_PAGINATION: "first";
|
|
9
9
|
};
|
|
10
|
+
export declare const uniqueArrayMerge: <T>(existingArray: T[], arrayToMerge: T[], getKey: (v: T) => string) => T[];
|