@amityco/ts-sdk 6.4.2 → 6.4.3-70fa0bc.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/cache/api/ingestInCache.d.ts +2 -1
- package/dist/cache/api/ingestInCache.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/index.cjs.js +39 -41
- package/dist/index.esm.js +39 -41
- package/dist/index.umd.js +1 -1
- package/dist/postRepository/events/onPostReactionAdded.d.ts.map +1 -1
- package/dist/postRepository/events/onPostReactionRemoved.d.ts.map +1 -1
- package/dist/reactionRepository/utils/index.d.ts +1 -1
- package/dist/reactionRepository/utils/index.d.ts.map +1 -1
- package/dist/reactionRepository/utils/prepareReactionPayloadFormEvent.d.ts +3 -0
- package/dist/reactionRepository/utils/prepareReactionPayloadFormEvent.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cache/api/ingestInCache.ts +4 -1
- package/src/channelRepsitory/channelMembership/observers/tests/getMembers.test.ts +7 -1
- package/src/channelRepsitory/channelMembership/observers/tests/searchMembers.test.ts +7 -1
- package/src/commentRepository/events/onCommentReactionAdded.ts +3 -4
- package/src/commentRepository/events/onCommentReactionRemoved.ts +3 -4
- package/src/postRepository/events/onPostReactionAdded.ts +3 -4
- package/src/postRepository/events/onPostReactionRemoved.ts +3 -4
- package/src/postRepository/events/tests/onPostReactionAdded.test.ts +1 -1
- package/src/reactionRepository/utils/index.ts +1 -1
- package/src/reactionRepository/utils/prepareReactionPayloadFormEvent.ts +62 -0
- package/src/utils/tests/dummy/post.ts +1 -0
- package/dist/reactionRepository/utils/preparePayloadForCache.d.ts +0 -3
- package/dist/reactionRepository/utils/preparePayloadForCache.d.ts.map +0 -1
- package/src/reactionRepository/utils/preparePayloadForCache.ts +0 -53
|
@@ -4,9 +4,10 @@ import { PAYLOAD2MODEL } from '~/core/model';
|
|
|
4
4
|
*
|
|
5
5
|
* @param payload a "backend v3" payload object
|
|
6
6
|
* @param options caching options like cachedAt or offline
|
|
7
|
+
* @param replace If TRUE it will overwrite the current cache with payload, if FALSE it will merge the payload into cache.
|
|
7
8
|
*
|
|
8
9
|
* @category Cache
|
|
9
10
|
* @hidden
|
|
10
11
|
*/
|
|
11
|
-
export declare const ingestInCache: (payload?: Record<keyof typeof PAYLOAD2MODEL, Amity.Model[]>, options?: Amity.CacheOptions) => void;
|
|
12
|
+
export declare const ingestInCache: (payload?: Record<keyof typeof PAYLOAD2MODEL, Amity.Model[]>, options?: Amity.CacheOptions, replace?: boolean) => void;
|
|
12
13
|
//# sourceMappingURL=ingestInCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingestInCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/ingestInCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ingestInCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/ingestInCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AAK1D;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,aACf,OAAO,MAAM,oBAAoB,EAAE,MAAM,KAAK,EAAE,CAAC,YAChD,MAAM,YAAY,4BAc7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onCommentReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionAdded.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,aACvB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,
|
|
1
|
+
{"version":3,"file":"onCommentReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionAdded.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,aACvB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,YAuBR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onCommentReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionRemoved.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,aACzB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,
|
|
1
|
+
{"version":3,"file":"onCommentReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionRemoved.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,aACzB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,YAuBR,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -20717,11 +20717,12 @@ const setClientToken = async (params) => {
|
|
|
20717
20717
|
*
|
|
20718
20718
|
* @param payload a "backend v3" payload object
|
|
20719
20719
|
* @param options caching options like cachedAt or offline
|
|
20720
|
+
* @param replace If TRUE it will overwrite the current cache with payload, if FALSE it will merge the payload into cache.
|
|
20720
20721
|
*
|
|
20721
20722
|
* @category Cache
|
|
20722
20723
|
* @hidden
|
|
20723
20724
|
*/
|
|
20724
|
-
const ingestInCache = (payload = {}, options) => {
|
|
20725
|
+
const ingestInCache = (payload = {}, options, replace = true) => {
|
|
20725
20726
|
Object.entries(payload).forEach(([key, models]) => {
|
|
20726
20727
|
const type = PAYLOAD2MODEL[key];
|
|
20727
20728
|
if (!type)
|
|
@@ -20730,7 +20731,7 @@ const ingestInCache = (payload = {}, options) => {
|
|
|
20730
20731
|
if (!resolver)
|
|
20731
20732
|
return;
|
|
20732
20733
|
models.forEach(model => {
|
|
20733
|
-
upsertInCache([type, 'get', resolver(model)], model, options);
|
|
20734
|
+
(replace ? pushToCache : upsertInCache)([type, 'get', resolver(model)], model, options);
|
|
20734
20735
|
});
|
|
20735
20736
|
});
|
|
20736
20737
|
};
|
|
@@ -26885,42 +26886,43 @@ getComment$1.locally = (commentId) => {
|
|
|
26885
26886
|
};
|
|
26886
26887
|
};
|
|
26887
26888
|
|
|
26888
|
-
|
|
26889
|
-
const preparePayloadForCache = (event, payload) => {
|
|
26889
|
+
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
26890
26890
|
var _a, _b;
|
|
26891
|
-
|
|
26892
|
-
if (
|
|
26893
|
-
|
|
26891
|
+
let id;
|
|
26892
|
+
if (eventPrefix === 'post') {
|
|
26893
|
+
id = payload.posts[0].postId;
|
|
26894
26894
|
}
|
|
26895
|
-
|
|
26896
|
-
|
|
26897
|
-
if (event === 'post.addReaction' || event === 'post.removeReaction') {
|
|
26898
|
-
const post = payload.posts[0];
|
|
26899
|
-
cached = (_a = pullFromCache(['post', 'get', post.postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26900
|
-
model = post;
|
|
26895
|
+
else if (eventPrefix === 'comment') {
|
|
26896
|
+
id = payload.comments[0].commentId;
|
|
26901
26897
|
}
|
|
26902
26898
|
else {
|
|
26903
|
-
|
|
26904
|
-
cached = (_b = pullFromCache(['comment', 'get', comment.commentId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26905
|
-
model = comment;
|
|
26899
|
+
throw new Error(`Unknown event type`);
|
|
26906
26900
|
}
|
|
26907
|
-
|
|
26908
|
-
|
|
26901
|
+
return ((_b = (_a = pullFromCache(['comment', 'get', id])) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.myReactions) || [];
|
|
26902
|
+
};
|
|
26903
|
+
const rebuildPayload = (payload, payloadKey, myReactions) => {
|
|
26904
|
+
const [model] = payload[payloadKey];
|
|
26905
|
+
return Object.assign(Object.assign({}, payload), { [payloadKey]: [Object.assign(Object.assign({}, model), { myReactions })] });
|
|
26906
|
+
};
|
|
26907
|
+
/** @hidden */
|
|
26908
|
+
const prepareReactionPayloadFormEvent = (event, payload) => {
|
|
26909
|
+
if (getActiveClient().userId !== payload.reactor.userId) {
|
|
26910
|
+
return payload;
|
|
26909
26911
|
}
|
|
26910
|
-
|
|
26911
|
-
|
|
26912
|
-
|
|
26913
|
-
|
|
26914
|
-
|
|
26912
|
+
const eventPrefix = event.split('.')[0]; // 'post' | 'comment'
|
|
26913
|
+
const eventSuffix = event.split('.')[1]; // 'addReaction' | 'removeReaction'
|
|
26914
|
+
let myReactions;
|
|
26915
|
+
const cachedMyReactions = getMyReactionsInCache(payload, eventPrefix);
|
|
26916
|
+
if (eventSuffix === 'addReaction') {
|
|
26917
|
+
myReactions = [...cachedMyReactions, payload.reactor.reactionName];
|
|
26918
|
+
}
|
|
26919
|
+
else if (eventSuffix === 'removeReaction') {
|
|
26920
|
+
myReactions = cachedMyReactions.filter(reaction => reaction !== payload.reactor.reactionName);
|
|
26915
26921
|
}
|
|
26916
26922
|
else {
|
|
26917
|
-
|
|
26918
|
-
return;
|
|
26919
|
-
}
|
|
26920
|
-
Object.assign(model, {
|
|
26921
|
-
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
26922
|
-
});
|
|
26923
|
+
throw new Error(`Unknown event type`);
|
|
26923
26924
|
}
|
|
26925
|
+
return rebuildPayload(payload, `${eventPrefix}s`, myReactions);
|
|
26924
26926
|
};
|
|
26925
26927
|
|
|
26926
26928
|
/* begin_public_function
|
|
@@ -27270,9 +27272,8 @@ const onPostReactionAdded = (callback) => {
|
|
|
27270
27272
|
callback(payload.posts[0]);
|
|
27271
27273
|
}
|
|
27272
27274
|
else {
|
|
27273
|
-
|
|
27274
|
-
|
|
27275
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27275
|
+
const processed = prepareReactionPayloadFormEvent('post.addReaction', payload);
|
|
27276
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27276
27277
|
ingestInCache(postPayload);
|
|
27277
27278
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27278
27279
|
callback(post.data);
|
|
@@ -27303,9 +27304,8 @@ const onPostReactionRemoved = (callback) => {
|
|
|
27303
27304
|
callback(payload.posts[0]);
|
|
27304
27305
|
}
|
|
27305
27306
|
else {
|
|
27306
|
-
|
|
27307
|
-
|
|
27308
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27307
|
+
const processed = prepareReactionPayloadFormEvent('post.removeReaction', payload);
|
|
27308
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27309
27309
|
ingestInCache(postPayload);
|
|
27310
27310
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27311
27311
|
callback(post.data);
|
|
@@ -27446,9 +27446,8 @@ const onCommentReactionAdded = (callback) => {
|
|
|
27446
27446
|
callback(payload.comments[0]);
|
|
27447
27447
|
}
|
|
27448
27448
|
else {
|
|
27449
|
-
|
|
27450
|
-
|
|
27451
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27449
|
+
const processed = prepareReactionPayloadFormEvent('comment.addReaction', payload);
|
|
27450
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27452
27451
|
ingestInCache(commentPayload);
|
|
27453
27452
|
const comment = pullFromCache([
|
|
27454
27453
|
'comment',
|
|
@@ -27483,9 +27482,8 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
27483
27482
|
callback(payload.comments[0]);
|
|
27484
27483
|
}
|
|
27485
27484
|
else {
|
|
27486
|
-
|
|
27487
|
-
|
|
27488
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27485
|
+
const processed = prepareReactionPayloadFormEvent('comment.removeReaction', payload);
|
|
27486
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27489
27487
|
ingestInCache(commentPayload);
|
|
27490
27488
|
const comment = pullFromCache([
|
|
27491
27489
|
'comment',
|
package/dist/index.esm.js
CHANGED
|
@@ -20703,11 +20703,12 @@ const setClientToken = async (params) => {
|
|
|
20703
20703
|
*
|
|
20704
20704
|
* @param payload a "backend v3" payload object
|
|
20705
20705
|
* @param options caching options like cachedAt or offline
|
|
20706
|
+
* @param replace If TRUE it will overwrite the current cache with payload, if FALSE it will merge the payload into cache.
|
|
20706
20707
|
*
|
|
20707
20708
|
* @category Cache
|
|
20708
20709
|
* @hidden
|
|
20709
20710
|
*/
|
|
20710
|
-
const ingestInCache = (payload = {}, options) => {
|
|
20711
|
+
const ingestInCache = (payload = {}, options, replace = true) => {
|
|
20711
20712
|
Object.entries(payload).forEach(([key, models]) => {
|
|
20712
20713
|
const type = PAYLOAD2MODEL[key];
|
|
20713
20714
|
if (!type)
|
|
@@ -20716,7 +20717,7 @@ const ingestInCache = (payload = {}, options) => {
|
|
|
20716
20717
|
if (!resolver)
|
|
20717
20718
|
return;
|
|
20718
20719
|
models.forEach(model => {
|
|
20719
|
-
upsertInCache([type, 'get', resolver(model)], model, options);
|
|
20720
|
+
(replace ? pushToCache : upsertInCache)([type, 'get', resolver(model)], model, options);
|
|
20720
20721
|
});
|
|
20721
20722
|
});
|
|
20722
20723
|
};
|
|
@@ -26871,42 +26872,43 @@ getComment$1.locally = (commentId) => {
|
|
|
26871
26872
|
};
|
|
26872
26873
|
};
|
|
26873
26874
|
|
|
26874
|
-
|
|
26875
|
-
const preparePayloadForCache = (event, payload) => {
|
|
26875
|
+
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
26876
26876
|
var _a, _b;
|
|
26877
|
-
|
|
26878
|
-
if (
|
|
26879
|
-
|
|
26877
|
+
let id;
|
|
26878
|
+
if (eventPrefix === 'post') {
|
|
26879
|
+
id = payload.posts[0].postId;
|
|
26880
26880
|
}
|
|
26881
|
-
|
|
26882
|
-
|
|
26883
|
-
if (event === 'post.addReaction' || event === 'post.removeReaction') {
|
|
26884
|
-
const post = payload.posts[0];
|
|
26885
|
-
cached = (_a = pullFromCache(['post', 'get', post.postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26886
|
-
model = post;
|
|
26881
|
+
else if (eventPrefix === 'comment') {
|
|
26882
|
+
id = payload.comments[0].commentId;
|
|
26887
26883
|
}
|
|
26888
26884
|
else {
|
|
26889
|
-
|
|
26890
|
-
cached = (_b = pullFromCache(['comment', 'get', comment.commentId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26891
|
-
model = comment;
|
|
26885
|
+
throw new Error(`Unknown event type`);
|
|
26892
26886
|
}
|
|
26893
|
-
|
|
26894
|
-
|
|
26887
|
+
return ((_b = (_a = pullFromCache(['comment', 'get', id])) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.myReactions) || [];
|
|
26888
|
+
};
|
|
26889
|
+
const rebuildPayload = (payload, payloadKey, myReactions) => {
|
|
26890
|
+
const [model] = payload[payloadKey];
|
|
26891
|
+
return Object.assign(Object.assign({}, payload), { [payloadKey]: [Object.assign(Object.assign({}, model), { myReactions })] });
|
|
26892
|
+
};
|
|
26893
|
+
/** @hidden */
|
|
26894
|
+
const prepareReactionPayloadFormEvent = (event, payload) => {
|
|
26895
|
+
if (getActiveClient().userId !== payload.reactor.userId) {
|
|
26896
|
+
return payload;
|
|
26895
26897
|
}
|
|
26896
|
-
|
|
26897
|
-
|
|
26898
|
-
|
|
26899
|
-
|
|
26900
|
-
|
|
26898
|
+
const eventPrefix = event.split('.')[0]; // 'post' | 'comment'
|
|
26899
|
+
const eventSuffix = event.split('.')[1]; // 'addReaction' | 'removeReaction'
|
|
26900
|
+
let myReactions;
|
|
26901
|
+
const cachedMyReactions = getMyReactionsInCache(payload, eventPrefix);
|
|
26902
|
+
if (eventSuffix === 'addReaction') {
|
|
26903
|
+
myReactions = [...cachedMyReactions, payload.reactor.reactionName];
|
|
26904
|
+
}
|
|
26905
|
+
else if (eventSuffix === 'removeReaction') {
|
|
26906
|
+
myReactions = cachedMyReactions.filter(reaction => reaction !== payload.reactor.reactionName);
|
|
26901
26907
|
}
|
|
26902
26908
|
else {
|
|
26903
|
-
|
|
26904
|
-
return;
|
|
26905
|
-
}
|
|
26906
|
-
Object.assign(model, {
|
|
26907
|
-
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
26908
|
-
});
|
|
26909
|
+
throw new Error(`Unknown event type`);
|
|
26909
26910
|
}
|
|
26911
|
+
return rebuildPayload(payload, `${eventPrefix}s`, myReactions);
|
|
26910
26912
|
};
|
|
26911
26913
|
|
|
26912
26914
|
/* begin_public_function
|
|
@@ -27256,9 +27258,8 @@ const onPostReactionAdded = (callback) => {
|
|
|
27256
27258
|
callback(payload.posts[0]);
|
|
27257
27259
|
}
|
|
27258
27260
|
else {
|
|
27259
|
-
|
|
27260
|
-
|
|
27261
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27261
|
+
const processed = prepareReactionPayloadFormEvent('post.addReaction', payload);
|
|
27262
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27262
27263
|
ingestInCache(postPayload);
|
|
27263
27264
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27264
27265
|
callback(post.data);
|
|
@@ -27289,9 +27290,8 @@ const onPostReactionRemoved = (callback) => {
|
|
|
27289
27290
|
callback(payload.posts[0]);
|
|
27290
27291
|
}
|
|
27291
27292
|
else {
|
|
27292
|
-
|
|
27293
|
-
|
|
27294
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27293
|
+
const processed = prepareReactionPayloadFormEvent('post.removeReaction', payload);
|
|
27294
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27295
27295
|
ingestInCache(postPayload);
|
|
27296
27296
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27297
27297
|
callback(post.data);
|
|
@@ -27432,9 +27432,8 @@ const onCommentReactionAdded = (callback) => {
|
|
|
27432
27432
|
callback(payload.comments[0]);
|
|
27433
27433
|
}
|
|
27434
27434
|
else {
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27435
|
+
const processed = prepareReactionPayloadFormEvent('comment.addReaction', payload);
|
|
27436
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27438
27437
|
ingestInCache(commentPayload);
|
|
27439
27438
|
const comment = pullFromCache([
|
|
27440
27439
|
'comment',
|
|
@@ -27469,9 +27468,8 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
27469
27468
|
callback(payload.comments[0]);
|
|
27470
27469
|
}
|
|
27471
27470
|
else {
|
|
27472
|
-
|
|
27473
|
-
|
|
27474
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27471
|
+
const processed = prepareReactionPayloadFormEvent('comment.removeReaction', payload);
|
|
27472
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27475
27473
|
ingestInCache(commentPayload);
|
|
27476
27474
|
const comment = pullFromCache([
|
|
27477
27475
|
'comment',
|