@amityco/ts-sdk 0.0.1-beta.44.0 → 0.0.1-beta.45.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.
- package/dist/index.cjs.js +57 -57
- package/dist/index.esm.js +57 -57
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
- package/src/category/observers/liveCategories.ts +4 -4
- package/src/channel/observers/liveChannelMembers.ts +4 -4
- package/src/channel/observers/liveChannels.ts +4 -4
- package/src/channel/observers/tests/liveChannels.test.ts +3 -9
- package/src/comment/observers/liveComments.ts +4 -4
- package/src/community/observers/liveCommunities.ts +4 -4
- package/src/community/observers/liveCommunityMembers.ts +4 -4
- package/src/follow/observers/liveFollowers.ts +4 -4
- package/src/follow/observers/liveFollowings.ts +4 -4
- package/src/message/observers/liveMessages.ts +6 -6
- package/src/post/observers/livePosts.ts +4 -4
- package/src/reaction/observers/liveReactions.ts +4 -4
- package/src/user/observers/liveUsers.ts +4 -4
- package/src/user/observers/tests/liveUsers.test.ts +3 -9
package/package.json
CHANGED
|
@@ -96,16 +96,16 @@ export const liveCategories = (
|
|
|
96
96
|
*};
|
|
97
97
|
*/
|
|
98
98
|
|
|
99
|
-
const onFetch = () => {
|
|
99
|
+
const onFetch = (initial = false) => {
|
|
100
100
|
const collection = pullFromCache<Amity.CategoryLiveCollectionCache>(cacheKey)?.data;
|
|
101
101
|
|
|
102
102
|
const categories = collection?.data ?? [];
|
|
103
103
|
|
|
104
|
-
if (categories.length > 0 && !collection?.params.page) return;
|
|
104
|
+
if (!initial && categories.length > 0 && !collection?.params.page) return;
|
|
105
105
|
|
|
106
106
|
const query = createQuery(queryCategories, {
|
|
107
107
|
...queryParams,
|
|
108
|
-
page: collection?.params.page ?? { limit },
|
|
108
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
runQuery(
|
|
@@ -134,7 +134,7 @@ export const liveCategories = (
|
|
|
134
134
|
// @TODO -> update once observers added
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
onFetch();
|
|
137
|
+
onFetch(true);
|
|
138
138
|
|
|
139
139
|
return () => {
|
|
140
140
|
log(`liveCategories(tmpid: ${timestamp}) > dispose`);
|
|
@@ -137,16 +137,16 @@ export const liveChannelMembers = (
|
|
|
137
137
|
responder(collection);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const onFetch = () => {
|
|
140
|
+
const onFetch = (initial = false) => {
|
|
141
141
|
const collection = pullFromCache<Amity.ChannelMembersLiveCollectionCache>(cacheKey)?.data;
|
|
142
142
|
|
|
143
143
|
const channelMembers = collection?.data ?? [];
|
|
144
144
|
|
|
145
|
-
if (channelMembers.length > 0 && !collection?.params.page) return;
|
|
145
|
+
if (!initial && channelMembers.length > 0 && !collection?.params.page) return;
|
|
146
146
|
|
|
147
147
|
const query = createQuery(queryChannelMembers, {
|
|
148
148
|
...queryParams,
|
|
149
|
-
page: collection?.params.page ?? { limit },
|
|
149
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
runQuery(
|
|
@@ -180,7 +180,7 @@ export const liveChannelMembers = (
|
|
|
180
180
|
onChannelMemberUnbanned(realtimeRouter('onChannelMemberUnbanned')),
|
|
181
181
|
);
|
|
182
182
|
|
|
183
|
-
onFetch();
|
|
183
|
+
onFetch(true);
|
|
184
184
|
|
|
185
185
|
return () => {
|
|
186
186
|
log(`liveChannelMembers(tmpid: ${timestamp}) > dispose`);
|
|
@@ -146,16 +146,16 @@ export const liveChannels = (
|
|
|
146
146
|
responder(collection);
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const onFetch = () => {
|
|
149
|
+
const onFetch = (initial = false) => {
|
|
150
150
|
const collection = pullFromCache<Amity.ChannelLiveCollectionCache>(cacheKey)?.data;
|
|
151
151
|
|
|
152
152
|
const channels = collection?.data ?? [];
|
|
153
153
|
|
|
154
|
-
if (channels.length > 0 && !collection?.params.page) return;
|
|
154
|
+
if (!initial && channels.length > 0 && !collection?.params.page) return;
|
|
155
155
|
|
|
156
156
|
const query = createQuery(queryChannels, {
|
|
157
157
|
...queryParams,
|
|
158
|
-
page: collection?.params.page ?? { limit },
|
|
158
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
runQuery(
|
|
@@ -192,7 +192,7 @@ export const liveChannels = (
|
|
|
192
192
|
onMessageCreated(() => null), // watch unread count
|
|
193
193
|
);
|
|
194
194
|
|
|
195
|
-
onFetch();
|
|
195
|
+
onFetch(true);
|
|
196
196
|
|
|
197
197
|
return () => {
|
|
198
198
|
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
@@ -75,17 +75,11 @@ describe('liveChannels', () => {
|
|
|
75
75
|
liveChannels({}, callback);
|
|
76
76
|
await pause();
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
// The second `getChannels` call fetches data from the cache,
|
|
79
|
+
// so there is no loading state and the callback only fires once.
|
|
80
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
79
81
|
expect(callback).toHaveBeenNthCalledWith(
|
|
80
82
|
1,
|
|
81
|
-
expect.objectContaining(
|
|
82
|
-
getSnapshot({
|
|
83
|
-
data: convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
84
|
-
}),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
expect(callback).toHaveBeenNthCalledWith(
|
|
88
|
-
2,
|
|
89
83
|
expect.objectContaining(
|
|
90
84
|
getSnapshot({
|
|
91
85
|
data: convertRawChannelPayload(channelQueryResponse.data).channels,
|
|
@@ -120,16 +120,16 @@ export const liveComments = (
|
|
|
120
120
|
responder(collection);
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
const onFetch = () => {
|
|
123
|
+
const onFetch = (initial = false) => {
|
|
124
124
|
const collection = pullFromCache<Amity.CommentLiveCollectionCache>(cacheKey)?.data;
|
|
125
125
|
|
|
126
126
|
const comments = collection?.data ?? [];
|
|
127
127
|
|
|
128
|
-
if (comments.length > 0 && !collection?.params?.page) return;
|
|
128
|
+
if (!initial && comments.length > 0 && !collection?.params?.page) return;
|
|
129
129
|
|
|
130
130
|
const query = createQuery(queryComments, {
|
|
131
131
|
...queryParams,
|
|
132
|
-
page: collection?.params
|
|
132
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
runQuery(
|
|
@@ -167,7 +167,7 @@ export const liveComments = (
|
|
|
167
167
|
onCommentReactionRemoved(realtimeRouter('onReactionRemoved')),
|
|
168
168
|
);
|
|
169
169
|
|
|
170
|
-
onFetch();
|
|
170
|
+
onFetch(true);
|
|
171
171
|
|
|
172
172
|
return () => {
|
|
173
173
|
log(`liveComments(tmpid: ${timestamp}) > dispose`);
|
|
@@ -138,16 +138,16 @@ export const liveCommunities = (
|
|
|
138
138
|
responder(collection);
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
const onFetch = () => {
|
|
141
|
+
const onFetch = (initial = false) => {
|
|
142
142
|
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
|
|
143
143
|
|
|
144
144
|
const communities = collection?.data ?? [];
|
|
145
145
|
|
|
146
|
-
if (communities.length > 0 && !collection?.params.page) return;
|
|
146
|
+
if (!initial && communities.length > 0 && !collection?.params.page) return;
|
|
147
147
|
|
|
148
148
|
const query = createQuery(queryCommunities, {
|
|
149
149
|
...queryParams,
|
|
150
|
-
page: collection?.params.page ?? { limit },
|
|
150
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
runQuery(
|
|
@@ -181,7 +181,7 @@ export const liveCommunities = (
|
|
|
181
181
|
onCommunityUserChanged(realtimeRouter('onMemberCountChanged')),
|
|
182
182
|
);
|
|
183
183
|
|
|
184
|
-
onFetch();
|
|
184
|
+
onFetch(true);
|
|
185
185
|
|
|
186
186
|
return () => {
|
|
187
187
|
log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
|
|
@@ -132,16 +132,16 @@ export const liveCommunityMembers = (
|
|
|
132
132
|
responder(collection);
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
const onFetch = () => {
|
|
135
|
+
const onFetch = (initial = false) => {
|
|
136
136
|
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(cacheKey)?.data;
|
|
137
137
|
|
|
138
138
|
const communityMembers = collection?.data ?? [];
|
|
139
139
|
|
|
140
|
-
if (communityMembers.length > 0 && !collection?.params.page) return;
|
|
140
|
+
if (!initial && communityMembers.length > 0 && !collection?.params.page) return;
|
|
141
141
|
|
|
142
142
|
const query = createQuery(queryCommunityMembers, {
|
|
143
143
|
...queryParams,
|
|
144
|
-
page: collection?.params.page ?? { limit },
|
|
144
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
runQuery(
|
|
@@ -178,7 +178,7 @@ export const liveCommunityMembers = (
|
|
|
178
178
|
onCommunityUserRoleRemoved(realtimeRouter('onMemberCountChanged')),
|
|
179
179
|
);
|
|
180
180
|
|
|
181
|
-
onFetch();
|
|
181
|
+
onFetch(true);
|
|
182
182
|
|
|
183
183
|
return () => {
|
|
184
184
|
log(`liveCommunityMembers(tmpid: ${timestamp}) > dispose`);
|
|
@@ -96,16 +96,16 @@ export const liveFollowers = (
|
|
|
96
96
|
responder(collection);
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
const onFetch = () => {
|
|
99
|
+
const onFetch = (initial = false) => {
|
|
100
100
|
const collection = pullFromCache<Amity.FollowerLiveCollectionCache>(cacheKey)?.data;
|
|
101
101
|
|
|
102
102
|
const followers = collection?.data ?? [];
|
|
103
103
|
|
|
104
|
-
if (followers.length > 0 && !collection?.params?.page) return;
|
|
104
|
+
if (!initial && followers.length > 0 && !collection?.params?.page) return;
|
|
105
105
|
|
|
106
106
|
const query = createQuery(queryFollowers, {
|
|
107
107
|
...queryParams,
|
|
108
|
-
page: collection?.params
|
|
108
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
runQuery(
|
|
@@ -140,7 +140,7 @@ export const liveFollowers = (
|
|
|
140
140
|
onFollowerDeleted(realtimeRouter('onDeleted')),
|
|
141
141
|
);
|
|
142
142
|
|
|
143
|
-
onFetch();
|
|
143
|
+
onFetch(true);
|
|
144
144
|
|
|
145
145
|
return () => {
|
|
146
146
|
log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
|
|
@@ -96,16 +96,16 @@ export const liveFollowings = (
|
|
|
96
96
|
responder(collection);
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
const onFetch = () => {
|
|
99
|
+
const onFetch = (initial = false) => {
|
|
100
100
|
const collection = pullFromCache<Amity.FollowingLiveCollectionCache>(cacheKey)?.data;
|
|
101
101
|
|
|
102
102
|
const followings = collection?.data ?? [];
|
|
103
103
|
|
|
104
|
-
if (followings.length > 0 && !collection?.params?.page) return;
|
|
104
|
+
if (!initial && followings.length > 0 && !collection?.params?.page) return;
|
|
105
105
|
|
|
106
106
|
const query = createQuery(queryFollowings, {
|
|
107
107
|
...queryParams,
|
|
108
|
-
page: collection?.params
|
|
108
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
runQuery(
|
|
@@ -140,7 +140,7 @@ export const liveFollowings = (
|
|
|
140
140
|
onFollowerDeleted(realtimeRouter('onDeleted')),
|
|
141
141
|
);
|
|
142
142
|
|
|
143
|
-
onFetch();
|
|
143
|
+
onFetch(true);
|
|
144
144
|
|
|
145
145
|
return () => {
|
|
146
146
|
log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
onMessageUpdated,
|
|
23
23
|
} from '../events';
|
|
24
24
|
import { onMessageFetched } from '../events/onMessageFetched';
|
|
25
|
-
import { queryMessages } from '../api';
|
|
25
|
+
import { queryMessages } from '../api/queryMessages';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* ```js
|
|
@@ -97,21 +97,20 @@ export const liveMessages = (
|
|
|
97
97
|
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
98
98
|
|
|
99
99
|
pushToCache(cacheKey, collection);
|
|
100
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
101
100
|
|
|
102
101
|
responder(collection);
|
|
103
102
|
};
|
|
104
103
|
|
|
105
|
-
const onFetch = () => {
|
|
104
|
+
const onFetch = (initial = false) => {
|
|
106
105
|
const collection = pullFromCache<Amity.MessageLiveCollectionCache>(cacheKey)?.data;
|
|
107
106
|
|
|
108
107
|
const messages = collection?.data ?? [];
|
|
109
108
|
|
|
110
|
-
if (messages.length > 0 && !collection?.params?.page) return;
|
|
109
|
+
if (!initial && messages.length > 0 && !collection?.params?.page) return;
|
|
111
110
|
|
|
112
111
|
const query = createQuery(queryMessages, {
|
|
113
112
|
...queryParams,
|
|
114
|
-
page: collection?.params
|
|
113
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
115
114
|
});
|
|
116
115
|
|
|
117
116
|
runQuery(
|
|
@@ -148,7 +147,8 @@ export const liveMessages = (
|
|
|
148
147
|
onMessageReactionRemoved(realtimeRouter('onReactionRemoved')),
|
|
149
148
|
);
|
|
150
149
|
|
|
151
|
-
onFetch();
|
|
150
|
+
onFetch(true);
|
|
151
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
152
152
|
|
|
153
153
|
return () => {
|
|
154
154
|
log(`liveMessages(tmpid: ${timestamp}) > dispose`);
|
|
@@ -137,16 +137,16 @@ export const livePosts = (
|
|
|
137
137
|
responder(collection);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const onFetch = () => {
|
|
140
|
+
const onFetch = (initial = false) => {
|
|
141
141
|
const collection = pullFromCache<Amity.PostLiveCollectionCache>(cacheKey)?.data;
|
|
142
142
|
|
|
143
143
|
const posts = collection?.data ?? [];
|
|
144
144
|
|
|
145
|
-
if (posts.length > 0 && !collection?.params?.page) return;
|
|
145
|
+
if (!initial && posts.length > 0 && !collection?.params?.page) return;
|
|
146
146
|
|
|
147
147
|
const query = createQuery(queryPosts, {
|
|
148
148
|
...queryParams,
|
|
149
|
-
page: collection?.params
|
|
149
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
runQuery(
|
|
@@ -184,7 +184,7 @@ export const livePosts = (
|
|
|
184
184
|
onPostReactionRemoved(realtimeRouter('onReactionRemoved')),
|
|
185
185
|
);
|
|
186
186
|
|
|
187
|
-
onFetch();
|
|
187
|
+
onFetch(true);
|
|
188
188
|
|
|
189
189
|
return () => {
|
|
190
190
|
log(`livePosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -88,16 +88,16 @@ export const liveReactions = (
|
|
|
88
88
|
responder(collection);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const onFetch = () => {
|
|
91
|
+
const onFetch = (initial = false) => {
|
|
92
92
|
const collection = pullFromCache<Amity.ReactionLiveCollectionCache>(cacheKey)?.data;
|
|
93
93
|
|
|
94
94
|
const reactions = collection?.data ?? [];
|
|
95
95
|
|
|
96
|
-
if (reactions.length > 0 && !collection?.params?.page) return;
|
|
96
|
+
if (!initial && reactions.length > 0 && !collection?.params?.page) return;
|
|
97
97
|
|
|
98
98
|
const query = createQuery(queryReactions, {
|
|
99
99
|
...queryParams,
|
|
100
|
-
page: collection?.params
|
|
100
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
runQuery(
|
|
@@ -133,7 +133,7 @@ export const liveReactions = (
|
|
|
133
133
|
),
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
onFetch();
|
|
136
|
+
onFetch(true);
|
|
137
137
|
|
|
138
138
|
return () => {
|
|
139
139
|
log(`liveReactions(tmpid: ${timestamp}) > dispose`);
|
|
@@ -111,16 +111,16 @@ export const liveUsers = (
|
|
|
111
111
|
responder(collection);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const onFetch = () => {
|
|
114
|
+
const onFetch = (initial = false) => {
|
|
115
115
|
const collection = pullFromCache<Amity.UserLiveCollectionCache>(cacheKey)?.data;
|
|
116
116
|
|
|
117
117
|
const users = collection?.data ?? [];
|
|
118
118
|
|
|
119
|
-
if (users.length > 0 && !collection?.params.page) return;
|
|
119
|
+
if (!initial && users.length > 0 && !collection?.params.page) return;
|
|
120
120
|
|
|
121
121
|
const query = createQuery(queryUsers, {
|
|
122
122
|
...queryParams,
|
|
123
|
-
page: collection?.params.page ?? { limit },
|
|
123
|
+
page: (!initial ? collection?.params.page : undefined) ?? { limit },
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
runQuery(
|
|
@@ -153,7 +153,7 @@ export const liveUsers = (
|
|
|
153
153
|
onUserFlagCleared(realtimeRouter('onFlagCleared')),
|
|
154
154
|
);
|
|
155
155
|
|
|
156
|
-
onFetch();
|
|
156
|
+
onFetch(true);
|
|
157
157
|
|
|
158
158
|
return () => {
|
|
159
159
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
@@ -65,17 +65,11 @@ describe('liveUsers', () => {
|
|
|
65
65
|
liveUsers(params, callback);
|
|
66
66
|
await pause();
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
// The second `getUsers` call fetches data from the cache,
|
|
69
|
+
// so there is no loading state and the callback only fires once.
|
|
70
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
69
71
|
expect(callback).toHaveBeenNthCalledWith(
|
|
70
72
|
1,
|
|
71
|
-
expect.objectContaining(
|
|
72
|
-
getSnapshot({
|
|
73
|
-
data: payload.users,
|
|
74
|
-
}),
|
|
75
|
-
),
|
|
76
|
-
);
|
|
77
|
-
expect(callback).toHaveBeenNthCalledWith(
|
|
78
|
-
2,
|
|
79
73
|
expect.objectContaining(
|
|
80
74
|
getSnapshot({
|
|
81
75
|
data: payload.users,
|