@amityco/ts-sdk 0.0.1-beta.32 → 0.0.1-beta.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.
Files changed (50) hide show
  1. package/dist/cache/api/ingestInCache.d.ts +1 -1
  2. package/dist/cache/api/tests/ingestInCache.test.d.ts +2 -0
  3. package/dist/cache/api/tests/ingestInCache.test.d.ts.map +1 -0
  4. package/dist/core/model/idResolvers.d.ts.map +1 -1
  5. package/dist/index.cjs.js +26 -6
  6. package/dist/index.esm.js +26 -6
  7. package/dist/index.umd.js +1 -1
  8. package/dist/reaction/api/addReaction.d.ts.map +1 -1
  9. package/dist/reaction/api/removeReaction.d.ts.map +1 -1
  10. package/dist/utils/tests/dummy/channel.d.ts +6 -0
  11. package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
  12. package/dist/utils/tests/dummy/community.d.ts +4 -0
  13. package/dist/utils/tests/dummy/community.d.ts.map +1 -0
  14. package/dist/utils/tests/dummy/file.d.ts +2 -0
  15. package/dist/utils/tests/dummy/file.d.ts.map +1 -0
  16. package/dist/utils/tests/dummy/follow.d.ts +1 -0
  17. package/dist/utils/tests/dummy/follow.d.ts.map +1 -1
  18. package/dist/utils/tests/dummy/index.d.ts +5 -0
  19. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  20. package/dist/utils/tests/dummy/message.d.ts +5 -0
  21. package/dist/utils/tests/dummy/message.d.ts.map +1 -1
  22. package/dist/utils/tests/dummy/poll.d.ts +3 -0
  23. package/dist/utils/tests/dummy/poll.d.ts.map +1 -0
  24. package/dist/utils/tests/dummy/post.d.ts +3 -0
  25. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  26. package/dist/utils/tests/dummy/reaction.d.ts +4 -0
  27. package/dist/utils/tests/dummy/reaction.d.ts.map +1 -0
  28. package/dist/utils/tests/dummy/role.d.ts +4 -0
  29. package/dist/utils/tests/dummy/role.d.ts.map +1 -0
  30. package/dist/utils/tests/dummy/user.d.ts +1 -0
  31. package/dist/utils/tests/dummy/user.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/cache/api/ingestInCache.ts +2 -2
  34. package/src/cache/api/tests/ingestInCache.test.ts +87 -0
  35. package/src/core/model/idResolvers.ts +1 -1
  36. package/src/reaction/api/addReaction.ts +17 -3
  37. package/src/reaction/api/removeReaction.ts +17 -3
  38. package/src/reaction/api/tests/addReaction.test.ts +42 -6
  39. package/src/reaction/api/tests/removeReaction.test.ts +49 -13
  40. package/src/utils/tests/dummy/channel.ts +9 -1
  41. package/src/utils/tests/dummy/community.ts +44 -0
  42. package/src/utils/tests/dummy/file.ts +20 -0
  43. package/src/utils/tests/dummy/follow.ts +6 -0
  44. package/src/utils/tests/dummy/index.ts +9 -0
  45. package/src/utils/tests/dummy/message.ts +8 -1
  46. package/src/utils/tests/dummy/poll.ts +43 -0
  47. package/src/utils/tests/dummy/post.ts +39 -1
  48. package/src/utils/tests/dummy/reaction.ts +22 -0
  49. package/src/utils/tests/dummy/role.ts +21 -0
  50. package/src/utils/tests/dummy/user.ts +6 -0
@@ -2,7 +2,7 @@
2
2
  * Ingest a payload (v3) into the cache
3
3
  *
4
4
  * @param payload a "backend v3" payload object
5
- * @param order the order of the keys to process (in case of need)
5
+ * @param options caching options like cachedAt or offline
6
6
  *
7
7
  * @category Cache
8
8
  * @hidden
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ingestInCache.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingestInCache.test.d.ts","sourceRoot":"","sources":["../../../../src/cache/api/tests/ingestInCache.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"idResolvers.d.ts","sourceRoot":"","sources":["../../../src/core/model/idResolvers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,aAAK,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI;KACzD,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM;CACtD,CAAC;AA0BF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+EAAyD,CAAC"}
1
+ {"version":3,"file":"idResolvers.d.ts","sourceRoot":"","sources":["../../../src/core/model/idResolvers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,aAAK,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI;KACzD,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM;CACtD,CAAC;AA0BF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+EAAuE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -20410,7 +20410,7 @@ const getDeviceInfo = () => {
20410
20410
  * Ingest a payload (v3) into the cache
20411
20411
  *
20412
20412
  * @param payload a "backend v3" payload object
20413
- * @param order the order of the keys to process (in case of need)
20413
+ * @param options caching options like cachedAt or offline
20414
20414
  *
20415
20415
  * @category Cache
20416
20416
  * @hidden
@@ -20422,9 +20422,7 @@ const ingestInCache = (payload = {}, options) => {
20422
20422
  return;
20423
20423
  const resolver = getResolver(type);
20424
20424
  models.forEach(model => {
20425
- upsertInCache(
20426
- // eslint-disable @typescript-eslint no-explicit-any
20427
- [type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20425
+ upsertInCache([type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20428
20426
  model, options);
20429
20427
  });
20430
20428
  });
@@ -23367,6 +23365,15 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
23367
23365
  referenceType,
23368
23366
  reactionName,
23369
23367
  });
23368
+ if (client.cache) {
23369
+ const model = pullFromCache([
23370
+ referenceType,
23371
+ 'get',
23372
+ referenceId,
23373
+ ]);
23374
+ (model === null || model === void 0 ? void 0 : model.data) &&
23375
+ pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
23376
+ }
23370
23377
  return true;
23371
23378
  };
23372
23379
  /**
@@ -23402,7 +23409,9 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
23402
23409
  if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
23403
23410
  return;
23404
23411
  const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
23405
- upsertInCache([referenceType, 'get', referenceId], reaction, { cachedAt: -1 });
23412
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
23413
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
23414
+ });
23406
23415
  dispatchReactable(referenceType, reaction);
23407
23416
  return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
23408
23417
  };
@@ -23433,6 +23442,15 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
23433
23442
  await client.http.delete(`/api/v2/reactions`, {
23434
23443
  data: { referenceId, referenceType, reactionName },
23435
23444
  });
23445
+ if (client.cache) {
23446
+ const model = pullFromCache([
23447
+ referenceType,
23448
+ 'get',
23449
+ referenceId,
23450
+ ]);
23451
+ (model === null || model === void 0 ? void 0 : model.data) &&
23452
+ pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
23453
+ }
23436
23454
  return true;
23437
23455
  };
23438
23456
  /**
@@ -23468,7 +23486,9 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
23468
23486
  if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
23469
23487
  return;
23470
23488
  const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
23471
- upsertInCache([referenceType, 'get', referenceId], reaction, { cachedAt: -1 });
23489
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
23490
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
23491
+ });
23472
23492
  dispatchReactable(referenceType, reaction);
23473
23493
  return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
23474
23494
  };
package/dist/index.esm.js CHANGED
@@ -20395,7 +20395,7 @@ const getDeviceInfo = () => {
20395
20395
  * Ingest a payload (v3) into the cache
20396
20396
  *
20397
20397
  * @param payload a "backend v3" payload object
20398
- * @param order the order of the keys to process (in case of need)
20398
+ * @param options caching options like cachedAt or offline
20399
20399
  *
20400
20400
  * @category Cache
20401
20401
  * @hidden
@@ -20407,9 +20407,7 @@ const ingestInCache = (payload = {}, options) => {
20407
20407
  return;
20408
20408
  const resolver = getResolver(type);
20409
20409
  models.forEach(model => {
20410
- upsertInCache(
20411
- // eslint-disable @typescript-eslint no-explicit-any
20412
- [type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20410
+ upsertInCache([type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20413
20411
  model, options);
20414
20412
  });
20415
20413
  });
@@ -23352,6 +23350,15 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
23352
23350
  referenceType,
23353
23351
  reactionName,
23354
23352
  });
23353
+ if (client.cache) {
23354
+ const model = pullFromCache([
23355
+ referenceType,
23356
+ 'get',
23357
+ referenceId,
23358
+ ]);
23359
+ (model === null || model === void 0 ? void 0 : model.data) &&
23360
+ pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
23361
+ }
23355
23362
  return true;
23356
23363
  };
23357
23364
  /**
@@ -23387,7 +23394,9 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
23387
23394
  if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
23388
23395
  return;
23389
23396
  const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
23390
- upsertInCache([referenceType, 'get', referenceId], reaction, { cachedAt: -1 });
23397
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
23398
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
23399
+ });
23391
23400
  dispatchReactable(referenceType, reaction);
23392
23401
  return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
23393
23402
  };
@@ -23418,6 +23427,15 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
23418
23427
  await client.http.delete(`/api/v2/reactions`, {
23419
23428
  data: { referenceId, referenceType, reactionName },
23420
23429
  });
23430
+ if (client.cache) {
23431
+ const model = pullFromCache([
23432
+ referenceType,
23433
+ 'get',
23434
+ referenceId,
23435
+ ]);
23436
+ (model === null || model === void 0 ? void 0 : model.data) &&
23437
+ pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
23438
+ }
23421
23439
  return true;
23422
23440
  };
23423
23441
  /**
@@ -23453,7 +23471,9 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
23453
23471
  if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
23454
23472
  return;
23455
23473
  const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
23456
- upsertInCache([referenceType, 'get', referenceId], reaction, { cachedAt: -1 });
23474
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
23475
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
23476
+ });
23457
23477
  dispatchReactable(referenceType, reaction);
23458
23478
  return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
23459
23479
  };