@stream-io/feeds-client 0.3.31 → 0.3.33
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/CHANGELOG.md +15 -0
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +39 -33
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +4 -3
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +39 -33
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/{feeds-client-DYnxEI2D.mjs → feeds-client-C-6NrDBy.mjs} +196 -182
- package/dist/feeds-client-C-6NrDBy.mjs.map +1 -0
- package/dist/{feeds-client-BUsd5D-y.js → feeds-client-CyaHg6lu.js} +196 -182
- package/dist/feeds-client-CyaHg6lu.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts +1 -0
- package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts +8 -0
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts.map +1 -0
- package/dist/types/common/types.d.ts +1 -1
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +2 -1
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +7 -9
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/gen/models/index.d.ts +4 -0
- package/dist/types/gen/models/index.d.ts.map +1 -1
- package/dist/types/utils/check-own-fields-equality.d.ts +2 -0
- package/dist/types/utils/check-own-fields-equality.d.ts.map +1 -1
- package/dist/types/utils/throttling/index.d.ts +1 -1
- package/dist/types/utils/throttling/index.d.ts.map +1 -1
- package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts +14 -0
- package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/activity-with-state-updates/activity-with-state-updates.ts +7 -2
- package/src/bindings/react/hooks/feed-state-hooks/index.ts +1 -0
- package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +14 -23
- package/src/bindings/react/hooks/feed-state-hooks/useOwnFollowings.ts +18 -0
- package/src/common/types.ts +1 -1
- package/src/feed/event-handlers/activity/handle-activity-added.ts +0 -6
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +0 -4
- package/src/feed/feed.ts +51 -39
- package/src/feeds-client/feeds-client.ts +88 -91
- package/src/gen/models/index.ts +8 -0
- package/src/utils/check-own-fields-equality.ts +37 -10
- package/src/utils/throttling/index.ts +1 -1
- package/src/utils/throttling/{throttled-get-batched-own-capabilities.ts → throttled-get-batched-own-fields.ts} +10 -10
- package/dist/feeds-client-BUsd5D-y.js.map +0 -1
- package/dist/feeds-client-DYnxEI2D.mjs.map +0 -1
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts +0 -14
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts.map +0 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { FeedState } from '../feed';
|
|
2
|
-
import type { FeedResponse } from '../gen/models';
|
|
2
|
+
import type { FeedResponse, FollowResponse } from '../gen/models';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
) => {
|
|
4
|
+
const areFollowArraysEqual = (
|
|
5
|
+
currentFollows: FollowResponse[] | undefined,
|
|
6
|
+
newFollows: FollowResponse[] | undefined,
|
|
7
|
+
): boolean => {
|
|
8
8
|
const existingFollows = new Set(
|
|
9
|
-
|
|
9
|
+
currentFollows?.map(
|
|
10
10
|
(f) =>
|
|
11
11
|
`${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`,
|
|
12
12
|
),
|
|
13
13
|
);
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const newFollowsSet = new Set(
|
|
15
|
+
newFollows?.map(
|
|
16
16
|
(f) =>
|
|
17
17
|
`${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`,
|
|
18
18
|
),
|
|
19
19
|
);
|
|
20
|
-
if (existingFollows.size ===
|
|
20
|
+
if (existingFollows.size === newFollowsSet.size) {
|
|
21
21
|
const areEqual = Array.from(existingFollows).every((f) =>
|
|
22
|
-
|
|
22
|
+
newFollowsSet.has(f),
|
|
23
23
|
);
|
|
24
24
|
if (areEqual) {
|
|
25
25
|
return true;
|
|
@@ -29,6 +29,13 @@ export const isOwnFollowsEqual = (
|
|
|
29
29
|
return false;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
export const isOwnFollowsEqual = (
|
|
33
|
+
currentState: FeedState,
|
|
34
|
+
newState: FeedResponse,
|
|
35
|
+
) => {
|
|
36
|
+
return areFollowArraysEqual(currentState.own_follows, newState.own_follows);
|
|
37
|
+
};
|
|
38
|
+
|
|
32
39
|
export const isOwnMembershipEqual = (
|
|
33
40
|
currentState: FeedState,
|
|
34
41
|
newState: FeedResponse,
|
|
@@ -38,3 +45,23 @@ export const isOwnMembershipEqual = (
|
|
|
38
45
|
(newState.own_membership?.updated_at.getTime() ?? 0)
|
|
39
46
|
);
|
|
40
47
|
};
|
|
48
|
+
|
|
49
|
+
export const isOwnCapabilitiesEqual = (
|
|
50
|
+
currentState: FeedState,
|
|
51
|
+
newState: FeedResponse,
|
|
52
|
+
) => {
|
|
53
|
+
return (
|
|
54
|
+
[...(currentState.own_capabilities ?? [])].sort().join(',') ===
|
|
55
|
+
[...(newState.own_capabilities ?? [])].sort().join(',')
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const isOwnFollowingsEqual = (
|
|
60
|
+
currentState: FeedState,
|
|
61
|
+
newState: FeedResponse,
|
|
62
|
+
) => {
|
|
63
|
+
return areFollowArraysEqual(
|
|
64
|
+
currentState.own_followings,
|
|
65
|
+
newState.own_followings,
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './throttle';
|
|
2
|
-
export * from './throttled-get-batched-own-
|
|
2
|
+
export * from './throttled-get-batched-own-fields';
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import type { FeedsClient } from '../../feeds-client';
|
|
2
2
|
import type { ThrottledFunction } from './throttle';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const BATCH_OWN_FIELDS_API_LIMIT = 100;
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type GetBatchedOwnFields = {
|
|
7
7
|
feeds: string[];
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type GetBatchedOwnFieldsThrottledCallback = [
|
|
11
11
|
feeds: string[],
|
|
12
12
|
callback: (feedsToClear: string[]) => void | Promise<void>,
|
|
13
13
|
];
|
|
14
14
|
|
|
15
|
-
export type
|
|
16
|
-
ThrottledFunction<
|
|
15
|
+
export type ThrottledGetBatchedOwnFields =
|
|
16
|
+
ThrottledFunction<GetBatchedOwnFieldsThrottledCallback>;
|
|
17
17
|
|
|
18
|
-
export const
|
|
18
|
+
export const DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL = 2000;
|
|
19
19
|
|
|
20
20
|
const queuedFeeds: Set<string> = new Set();
|
|
21
21
|
|
|
22
|
-
export function
|
|
22
|
+
export function queueBatchedOwnFields(
|
|
23
23
|
this: FeedsClient,
|
|
24
|
-
{ feeds }:
|
|
24
|
+
{ feeds }: GetBatchedOwnFields,
|
|
25
25
|
) {
|
|
26
26
|
for (const feed of feeds) {
|
|
27
27
|
queuedFeeds.add(feed);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (queuedFeeds.size > 0) {
|
|
31
|
-
this.
|
|
32
|
-
[...queuedFeeds].slice(0,
|
|
31
|
+
this.throttledGetBatchOwnFields(
|
|
32
|
+
[...queuedFeeds].slice(0, BATCH_OWN_FIELDS_API_LIMIT),
|
|
33
33
|
(feedsToClear: string[]) => {
|
|
34
34
|
for (const feed of feedsToClear) {
|
|
35
35
|
queuedFeeds.delete(feed);
|