@amityco/ts-sdk 0.0.1-beta.43 → 0.0.1-beta.44.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/category/api/queryCategories.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/observers/liveCommunities.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +21 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/index.cjs.js +116 -62
- package/dist/index.esm.js +115 -63
- package/dist/index.umd.js +4 -4
- package/dist/message/api/queryMessages.d.ts +1 -17
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/subChannel/api/querySubChannels.d.ts.map +1 -1
- package/dist/utils/inferIsDeleted.d.ts +2 -0
- package/dist/utils/inferIsDeleted.d.ts.map +1 -0
- package/dist/utils/tests/inferIsDeleted.test.d.ts +2 -0
- package/dist/utils/tests/inferIsDeleted.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/category/api/queryCategories.ts +3 -1
- package/src/category/observers/liveCategories.ts +1 -1
- package/src/category/observers/tests/liveCategories.test.ts +7 -5
- package/src/channel/api/tests/removeChannelMembers.test.ts +3 -4
- package/src/channel/observers/tests/liveChannels.test.ts +6 -6
- package/src/client/api/connectClient.ts +1 -1
- package/src/comment/api/queryComments.ts +3 -1
- package/src/comment/observers/liveComments.ts +1 -1
- package/src/community/api/queryCommunities.ts +2 -1
- package/src/community/api/test/queryCommunity.test.ts +2 -2
- package/src/community/observers/liveCommunities.ts +5 -8
- package/src/community/observers/tests/liveCommunities.test.ts +7 -94
- package/src/community/observers/tests/liveCommunity.test.ts +4 -4
- package/src/core/query/filtering.ts +79 -0
- package/src/core/query/query.ts +4 -4
- package/src/message/api/queryMessages.ts +7 -44
- package/src/message/api/tests/queryMessages.test.ts +2 -37
- package/src/message/observers/liveMessages.ts +2 -2
- package/src/message/tests/observers/liveMessage.test.ts +1 -1
- package/src/message/tests/observers/liveMessages.test.ts +1 -1
- package/src/message/utils/prepareMessagePayload.ts +3 -1
- package/src/post/api/queryPosts.ts +3 -1
- package/src/post/observers/livePosts.ts +7 -2
- package/src/post/observers/tests/livePosts.test.ts +10 -4
- package/src/subChannel/api/querySubChannels.ts +3 -1
- package/src/subChannel/observers/liveSubChannels.ts +1 -1
- package/src/utils/inferIsDeleted.ts +16 -0
- package/src/utils/tests/inferIsDeleted.test.ts +15 -0
|
@@ -106,48 +106,13 @@ describe('queryMessages', () => {
|
|
|
106
106
|
expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
test('it should set isDeleted to
|
|
109
|
+
test('it should set isDeleted to false if includeDeleted is undefined', async () => {
|
|
110
110
|
const mockFn = jest.fn();
|
|
111
111
|
client.http.get = mockFn.mockResolvedValue(getResolvedMessageValue());
|
|
112
112
|
|
|
113
113
|
await queryMessages(queryCriteriaWithoutPage);
|
|
114
114
|
|
|
115
115
|
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
116
|
-
expect(mockFn.mock.lastCall[1].params.isDeleted).
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('queryMessages.locally', () => {
|
|
121
|
-
beforeEach(() => enableCache());
|
|
122
|
-
afterEach(() => disableCache());
|
|
123
|
-
|
|
124
|
-
test('should return cached messages', () => {
|
|
125
|
-
messagesToQuery.forEach(message => pushToCache(['message', 'get', message.messageId], message));
|
|
126
|
-
|
|
127
|
-
pushToCache(['message', 'query', convertQueryParams(queryCriteria)], {
|
|
128
|
-
messages: messageIds,
|
|
129
|
-
paging,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
expect(queryMessages.locally(queryCriteria)).toEqual(
|
|
133
|
-
expect.objectContaining({
|
|
134
|
-
data: messagesToQuery,
|
|
135
|
-
prevPage: undefined,
|
|
136
|
-
nextPage,
|
|
137
|
-
}),
|
|
138
|
-
);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test(`shouldn't return if individual message cache not exist`, () => {
|
|
142
|
-
pushToCache(['message', 'query', convertQueryParams(queryCriteria)], {
|
|
143
|
-
messages: messageIds,
|
|
144
|
-
paging,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(queryMessages.locally(queryCriteria)).toBeUndefined();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('it should return undefined if message not in cache', () => {
|
|
151
|
-
expect(queryMessages.locally({ subChannelId: 'non-existent' })).toBeUndefined();
|
|
116
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
|
|
152
117
|
});
|
|
153
118
|
});
|
|
@@ -76,7 +76,7 @@ export const liveMessages = (
|
|
|
76
76
|
* for cases when message is deleted via RTE, this flag is used to get
|
|
77
77
|
* items from cache that are !deleted
|
|
78
78
|
*/
|
|
79
|
-
if (params.includeDeleted
|
|
79
|
+
if (!params.includeDeleted) {
|
|
80
80
|
messages = filterByPropEquality(messages, 'isDeleted', false);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -97,6 +97,7 @@ 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));
|
|
100
101
|
|
|
101
102
|
responder(collection);
|
|
102
103
|
};
|
|
@@ -152,6 +153,5 @@ export const liveMessages = (
|
|
|
152
153
|
return () => {
|
|
153
154
|
log(`liveMessages(tmpid: ${timestamp}) > dispose`);
|
|
154
155
|
disposers.forEach(fn => fn());
|
|
155
|
-
dropFromCache(cacheKey);
|
|
156
156
|
};
|
|
157
157
|
};
|
|
@@ -4,6 +4,8 @@ import { toToken } from '~/core/query';
|
|
|
4
4
|
import { getMessageMarkers } from '~/marker/api';
|
|
5
5
|
import { prepareMessagePayloadForCache } from '~/reaction/utils/prepareMessagePayloadForCache';
|
|
6
6
|
|
|
7
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
8
|
+
|
|
7
9
|
const getCachedMarker = (message: Amity.Message | Amity.RawMessage) => {
|
|
8
10
|
const key = {
|
|
9
11
|
creatorId: message.creatorId,
|
|
@@ -166,7 +168,7 @@ export function convertQueryParams({
|
|
|
166
168
|
const out: RawQueryMessages = {
|
|
167
169
|
...rest,
|
|
168
170
|
messageFeedId: subChannelId,
|
|
169
|
-
isDeleted: includeDeleted
|
|
171
|
+
isDeleted: inferIsDeleted(includeDeleted),
|
|
170
172
|
options: { token: toToken(page || { limit: 10 }, 'afterbeforeraw')! },
|
|
171
173
|
};
|
|
172
174
|
|
|
@@ -5,7 +5,9 @@ import { toToken, toPageRaw } from '~/core/query';
|
|
|
5
5
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
6
6
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
7
7
|
import { getResolver } from '~/core/model';
|
|
8
|
+
|
|
8
9
|
import { prepareMembershipPayload } from '~/group/utils';
|
|
10
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
9
11
|
|
|
10
12
|
/* begin_public_function
|
|
11
13
|
id: post.query, feed.query.community_feed, feed.query.user_feed
|
|
@@ -39,7 +41,7 @@ export const queryPosts = async (
|
|
|
39
41
|
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/v4/posts`, {
|
|
40
42
|
params: {
|
|
41
43
|
...params,
|
|
42
|
-
isDeleted: includeDeleted
|
|
44
|
+
isDeleted: inferIsDeleted(includeDeleted),
|
|
43
45
|
/*
|
|
44
46
|
* when creating post like image, file, video BE will create 2 posts
|
|
45
47
|
* 1. parent post to store text with dataType=text
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createQuery,
|
|
8
8
|
filterByFeedType,
|
|
9
9
|
filterByPropEquality,
|
|
10
|
+
filterByPostDataTypes,
|
|
10
11
|
queryOptions,
|
|
11
12
|
runQuery,
|
|
12
13
|
sortByFirstCreated,
|
|
@@ -89,7 +90,7 @@ export const livePosts = (
|
|
|
89
90
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
90
91
|
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
91
92
|
|
|
92
|
-
if (params.includeDeleted
|
|
93
|
+
if (!params.includeDeleted) {
|
|
93
94
|
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -101,6 +102,10 @@ export const livePosts = (
|
|
|
101
102
|
posts = filterByFeedType(posts, params.feedType);
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
if (params.dataTypes?.length) {
|
|
106
|
+
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
107
|
+
}
|
|
108
|
+
|
|
104
109
|
callback({
|
|
105
110
|
onNextPage: onFetch,
|
|
106
111
|
data: posts,
|
|
@@ -127,6 +132,7 @@ export const livePosts = (
|
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
pushToCache(cacheKey, collection);
|
|
135
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
130
136
|
|
|
131
137
|
responder(collection);
|
|
132
138
|
};
|
|
@@ -183,6 +189,5 @@ export const livePosts = (
|
|
|
183
189
|
return () => {
|
|
184
190
|
log(`livePosts(tmpid: ${timestamp}) > dispose`);
|
|
185
191
|
disposers.forEach(fn => fn());
|
|
186
|
-
dropFromCache(cacheKey);
|
|
187
192
|
};
|
|
188
193
|
};
|
|
@@ -66,7 +66,7 @@ describe('livePosts', () => {
|
|
|
66
66
|
|
|
67
67
|
const filters: [string, Amity.PostLiveCollection, number?][] = [
|
|
68
68
|
['not deleted', { ...params, includeDeleted: false }],
|
|
69
|
-
['tags', { ...params, tags: ['test_tag'] }, 1],
|
|
69
|
+
['tags', { ...params, tags: ['test_tag'], includeDeleted: true }, 1],
|
|
70
70
|
];
|
|
71
71
|
|
|
72
72
|
test.each(filters)(
|
|
@@ -104,7 +104,7 @@ describe('livePosts', () => {
|
|
|
104
104
|
.mockResolvedValue(postQueryResponse)
|
|
105
105
|
.mockResolvedValueOnce(postQueryResponsePage2);
|
|
106
106
|
|
|
107
|
-
livePosts(params, callback);
|
|
107
|
+
livePosts({ ...params, includeDeleted: true }, callback);
|
|
108
108
|
|
|
109
109
|
expect(callback).toHaveBeenCalled();
|
|
110
110
|
|
|
@@ -292,7 +292,10 @@ describe('livePosts', () => {
|
|
|
292
292
|
const callback = jest.fn();
|
|
293
293
|
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
294
294
|
|
|
295
|
-
livePosts(
|
|
295
|
+
livePosts(
|
|
296
|
+
{ ...params, targetType: 'community', feedType: 'reviewing', includeDeleted: true },
|
|
297
|
+
callback,
|
|
298
|
+
);
|
|
296
299
|
|
|
297
300
|
await pause();
|
|
298
301
|
const payload = postQueryResponsePage2.data.posts;
|
|
@@ -335,7 +338,10 @@ describe('livePosts', () => {
|
|
|
335
338
|
const callback = jest.fn();
|
|
336
339
|
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
337
340
|
|
|
338
|
-
livePosts(
|
|
341
|
+
livePosts(
|
|
342
|
+
{ ...params, targetType: 'community', feedType: 'published', includeDeleted: true },
|
|
343
|
+
callback,
|
|
344
|
+
);
|
|
339
345
|
|
|
340
346
|
await pause();
|
|
341
347
|
const payload = postQueryResponsePage2.data.posts;
|
|
@@ -4,6 +4,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
4
4
|
import { getResolver } from '~/core/model';
|
|
5
5
|
import { toPage, toToken } from '~/core/query';
|
|
6
6
|
import { fireEvent } from '~/core/events';
|
|
7
|
+
|
|
8
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
7
9
|
import { convertQueryParams, prepareSubChannelPayload } from '../utils';
|
|
8
10
|
|
|
9
11
|
/* begin_public_function
|
|
@@ -36,7 +38,7 @@ export const querySubChannels = async (
|
|
|
36
38
|
{
|
|
37
39
|
params: {
|
|
38
40
|
...params,
|
|
39
|
-
isDeleted: includeDeleted
|
|
41
|
+
isDeleted: inferIsDeleted(includeDeleted),
|
|
40
42
|
options: {
|
|
41
43
|
token: toToken(page, 'skiplimit'),
|
|
42
44
|
},
|
|
@@ -59,7 +59,7 @@ export const liveSubChannels = (
|
|
|
59
59
|
const responder = (data: Amity.SubChannelLiveCollectionCache) => {
|
|
60
60
|
let subChannels: Amity.SubChannel[] = data.data;
|
|
61
61
|
|
|
62
|
-
if (params.includeDeleted
|
|
62
|
+
if (!params.includeDeleted) {
|
|
63
63
|
subChannels = filterByPropEquality(subChannels, 'isDeleted', false);
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
3
|
+
* value of includeDeleted
|
|
4
|
+
*
|
|
5
|
+
* There are two important things to note here:
|
|
6
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
7
|
+
* the server
|
|
8
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
9
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
10
|
+
* for deleted entities
|
|
11
|
+
*
|
|
12
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
13
|
+
* DRY
|
|
14
|
+
*/
|
|
15
|
+
export const inferIsDeleted = (includeDeleted?: boolean): boolean | undefined =>
|
|
16
|
+
includeDeleted === true ? undefined : false;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { inferIsDeleted } from '../inferIsDeleted';
|
|
2
|
+
|
|
3
|
+
describe('utils > inferIsDeleted', () => {
|
|
4
|
+
test('it should return false if includeDeleted false', () => {
|
|
5
|
+
expect(inferIsDeleted(false)).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('it should return false if includeDeleted undefined', () => {
|
|
9
|
+
expect(inferIsDeleted(undefined)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('it should return undefined if includeDeleted true', () => {
|
|
13
|
+
expect(inferIsDeleted(true)).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
});
|