@amityco/ts-sdk 0.0.1-beta.24 → 0.0.1-beta.25

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 (47) hide show
  1. package/dist/@types/core/events.d.ts +5 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/core/events.d.ts +3 -3
  4. package/dist/core/events.d.ts.map +1 -1
  5. package/dist/index.cjs.js +181 -3
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.esm.js +177 -4
  9. package/dist/index.umd.js +5 -5
  10. package/dist/poll/api/closePoll.d.ts.map +1 -1
  11. package/dist/poll/api/deletePoll.d.ts.map +1 -1
  12. package/dist/poll/api/votePoll.d.ts.map +1 -1
  13. package/dist/poll/events/index.d.ts +3 -0
  14. package/dist/poll/events/index.d.ts.map +1 -0
  15. package/dist/poll/events/onPollDeleted.d.ts +17 -0
  16. package/dist/poll/events/onPollDeleted.d.ts.map +1 -0
  17. package/dist/poll/events/onPollUpdated.d.ts +17 -0
  18. package/dist/poll/events/onPollUpdated.d.ts.map +1 -0
  19. package/dist/poll/observers/index.d.ts +2 -0
  20. package/dist/poll/observers/index.d.ts.map +1 -0
  21. package/dist/poll/observers/observePoll.d.ts +18 -0
  22. package/dist/poll/observers/observePoll.d.ts.map +1 -0
  23. package/dist/post/api/approvePost.d.ts +17 -0
  24. package/dist/post/api/approvePost.d.ts.map +1 -0
  25. package/dist/post/api/declinePost.d.ts +17 -0
  26. package/dist/post/api/declinePost.d.ts.map +1 -0
  27. package/dist/post/api/index.d.ts +2 -0
  28. package/dist/post/api/index.d.ts.map +1 -1
  29. package/dist/report/api/createReport.d.ts.map +1 -1
  30. package/dist/report/api/deleteReport.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/@types/core/events.ts +6 -1
  33. package/src/core/query/query.ts +1 -1
  34. package/src/index.ts +2 -0
  35. package/src/poll/api/closePoll.ts +3 -0
  36. package/src/poll/api/deletePoll.ts +3 -0
  37. package/src/poll/api/votePoll.ts +3 -0
  38. package/src/poll/events/index.ts +2 -0
  39. package/src/poll/events/onPollDeleted.ts +31 -0
  40. package/src/poll/events/onPollUpdated.ts +31 -0
  41. package/src/poll/observers/index.ts +1 -0
  42. package/src/poll/observers/observePoll.ts +67 -0
  43. package/src/post/api/approvePost.ts +48 -0
  44. package/src/post/api/declinePost.ts +48 -0
  45. package/src/post/api/index.ts +3 -0
  46. package/src/report/api/createReport.ts +7 -1
  47. package/src/report/api/deleteReport.ts +7 -1
@@ -100,7 +100,11 @@ declare global {
100
100
  'follow.followerDeleted': Amity.FollowStatus;
101
101
  };
102
102
  type MqttMessageEvents = MqttCommunityMessageEvents & MqttPostMessageEvents & MqttCommentMessageEvents & MqttUserMessageEvents & MqttFollowMessageEvents;
103
- type Events = WsEvents & MqttEvents & MqttMessageEvents;
103
+ type LocalEvents = {
104
+ 'poll.updated': Amity.PollPayload;
105
+ 'poll.deleted': Amity.PollPayload;
106
+ };
107
+ type Events = WsEvents & MqttEvents & MqttMessageEvents & LocalEvents;
104
108
  }
105
109
  }
106
110
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/@types/core/events.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;QAE7C,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,IACrC,QAAQ,CAAC,CAAC,CAAC,GACX,CAAC;YACC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE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27
- export declare const createEventSubscriber: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted">(client: Amity.Client, namespace: string, event: T, fn: Amity.Listener<Amity.Events[T]>) => Amity.Unsubscriber;
28
- export declare const createMqttMessageSubscriber: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted">(client: Amity.Client, namespace: string, event: string, fn: (params: Record<string, unknown>) => void) => Amity.Unsubscriber;
27
+ export declare const createEventSubscriber: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted" | "poll.updated" | "poll.deleted">(client: Amity.Client, namespace: string, event: T, fn: Amity.Listener<Amity.Events[T]>) => Amity.Unsubscriber;
28
+ export declare const createMqttMessageSubscriber: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted" | "poll.updated" | "poll.deleted">(client: Amity.Client, namespace: string, event: string, fn: (params: Record<string, unknown>) => void) => Amity.Unsubscriber;
29
29
  /**
30
30
  * Wrapper around dispatch event
31
31
  *
32
32
  * @hidden
33
33
  */
34
- export declare const fireEvent: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted">(event: T, payload: Amity.Events[T]) => void;
34
+ export declare const fireEvent: <T extends "disconnected" | "error" | "connect_error" | "reconnect_error" | "reconnect_failed" | "v3.channel.didUpdate" | "v3.channel.didJoin" | "v3.channel.didLeave" | "v3.channel.didAddUsers" | "v3.channel.didRemoveUsers" | "v3.channel.didBan" | "v3.channel.didUnban" | "v3.message.didCreate" | "v3.message.didUpdate" | "v3.message.didDelete" | "connect" | "message" | "disconnect" | "close" | "end" | "reconnect" | "v3.channel.didCreate" | "v3.channel.didDelete" | "video-streaming.didRecord" | "video-streaming.didStart" | "video-streaming.didStop" | "community.created" | "community.updated" | "community.deleted" | "community.joined" | "community.left" | "community.userAdded" | "community.userRemoved" | "community.userBanned" | "community.userUnbanned" | "post.created" | "post.updated" | "post.deleted" | "post.approved" | "post.declined" | "post.flagged" | "post.unflagged" | "post.addReaction" | "post.removeReaction" | "comment.created" | "comment.updated" | "comment.deleted" | "comment.flagged" | "comment.unflagged" | "comment.addReaction" | "comment.removeReaction" | "user.updated" | "user.deleted" | "user.flagged" | "user.unflagged" | "user.flagCleared" | "follow.created" | "follow.requested" | "follow.accepted" | "follow.unfollowed" | "follow.requestCanceled" | "follow.requestDeclined" | "follow.followerDeleted" | "poll.updated" | "poll.deleted">(event: T, payload: Amity.Events[T]) => void;
35
35
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/core/events.ts"],"names":[],"mappings":"AAuC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O,MAAM,SAAS,w4CAKrB,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -454,7 +454,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
454
454
  // @ts-ignore
455
455
  const modelKey = local && local.data && identifyModelKey(local.data);
456
456
  // @ts-ignore
457
- optimisticArgs = modelKey ? [Object.assign(Object.assign({}, args[0]), { [modelKey]: local.data[modelKey] })] : args;
457
+ optimisticArgs = modelKey ? [...args, { [modelKey]: local.data[modelKey] }] : args;
458
458
  }
459
459
  func(...optimisticArgs)
460
460
  .then(fresh => {
@@ -22506,6 +22506,78 @@ const deletePost = async (postId, permanent = false) => {
22506
22506
  return deleted;
22507
22507
  };
22508
22508
 
22509
+ /**
22510
+ * ```js
22511
+ * import { approvePost } from '@amityco/ts-sdk'
22512
+ *
22513
+ * const { data: post } = await approvePost('postId')
22514
+ * ```
22515
+ *
22516
+ * Approves a {@link Amity.Post}
22517
+ *
22518
+ * @param postId The {@link Amity.Post} ID to be approved
22519
+ * @return A {@link Amity.Post} that was approved
22520
+ *
22521
+ * @category Post API
22522
+ * @async
22523
+ */
22524
+ const approvePost = async (postId) => {
22525
+ var _a;
22526
+ const client = getActiveClient();
22527
+ client.log('post/approvePost', postId);
22528
+ const { data: approved } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
22529
+ const cachedAt = client.cache && Date.now();
22530
+ if (client.cache)
22531
+ ingestInCache(approved, { cachedAt });
22532
+ // fire virtual event for community update
22533
+ if (approved.posts[0].targetType === 'community') {
22534
+ const community = (_a = approved.communities) === null || _a === void 0 ? void 0 : _a[0];
22535
+ // @ts-ignore as communities is optional currently in PostPayload
22536
+ fireEvent('community.updated', { communities: [community] });
22537
+ }
22538
+ fireEvent('post.approved', { posts: [approved.posts[0]] });
22539
+ return {
22540
+ data: approved.posts.find(post => post.postId === postId),
22541
+ cachedAt,
22542
+ };
22543
+ };
22544
+
22545
+ /**
22546
+ * ```js
22547
+ * import { declinePost } from '@amityco/ts-sdk'
22548
+ *
22549
+ * const {data: post} = await declinePost('postId')
22550
+ * ```
22551
+ *
22552
+ * Declines a {@link Amity.Post}
22553
+ *
22554
+ * @param postId The {@link Amity.Post} ID to be declined
22555
+ * @return A {@link Amity.Post} that was declined
22556
+ *
22557
+ * @category Post API
22558
+ * @async
22559
+ */
22560
+ const declinePost = async (postId) => {
22561
+ var _a;
22562
+ const client = getActiveClient();
22563
+ client.log('post/declinePost', postId);
22564
+ const { data: declined } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
22565
+ const cachedAt = client.cache && Date.now();
22566
+ if (client.cache)
22567
+ ingestInCache(declined, { cachedAt });
22568
+ // fire virtual event
22569
+ if (declined.posts[0].targetType === 'community') {
22570
+ const community = (_a = declined.communities) === null || _a === void 0 ? void 0 : _a[0];
22571
+ // @ts-ignore as communities is optional currently in PostPayload
22572
+ fireEvent('community.updated', { communities: [community] });
22573
+ }
22574
+ fireEvent('post.declined', { posts: [declined.posts[0]] });
22575
+ return {
22576
+ data: declined.posts.find(post => post.postId === postId),
22577
+ cachedAt,
22578
+ };
22579
+ };
22580
+
22509
22581
  /**
22510
22582
  * ```js
22511
22583
  * import { queryComments } from '@amityco/ts-sdk'
@@ -23558,7 +23630,9 @@ const createReport = async (referenceType, referenceId) => {
23558
23630
  const client = getActiveClient();
23559
23631
  client.log('report/createReport', { referenceType, referenceId });
23560
23632
  const { domainName } = REFERENCE_TYPES[referenceType];
23561
- const { data } = await client.http.post(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`);
23633
+ const { data } = await client.http.post(`/api/${referenceType === 'user'
23634
+ ? `v4/me/flags/${encodeURIComponent(referenceId)}`
23635
+ : `v3/${domainName}/${encodeURIComponent(referenceId)}/flag`}`);
23562
23636
  if (client.cache)
23563
23637
  ingestInCache(data);
23564
23638
  const event = referenceType === 'message'
@@ -23585,7 +23659,9 @@ const deleteReport = async (referenceType, referenceId) => {
23585
23659
  const client = getActiveClient();
23586
23660
  client.log('report/deleteReport', { referenceType, referenceId });
23587
23661
  const { domainName } = REFERENCE_TYPES[referenceType];
23588
- const { data } = await client.http.delete(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`);
23662
+ const { data } = await client.http.delete(`/api/${referenceType === 'user'
23663
+ ? `v4/me/flags/${encodeURIComponent(referenceId)}`
23664
+ : `v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`}`);
23589
23665
  if (client.cache)
23590
23666
  ingestInCache(data);
23591
23667
  const event = referenceType === 'message'
@@ -25764,6 +25840,7 @@ const closePoll = async (pollId) => {
25764
25840
  const cachedAt = client.cache && Date.now();
25765
25841
  if (client.cache)
25766
25842
  ingestInCache(data, { cachedAt });
25843
+ fireEvent('poll.updated', data);
25767
25844
  const { polls } = data;
25768
25845
  return {
25769
25846
  data: polls.find(poll => poll.pollId === pollId),
@@ -25794,6 +25871,7 @@ const deletePoll = async (pollId) => {
25794
25871
  const { success } = data; // unwrapPayload(data)
25795
25872
  const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
25796
25873
  upsertInCache(['poll', 'get', pollId], deleted);
25874
+ fireEvent('poll.deleted', { polls: [deleted], users: [] });
25797
25875
  return success;
25798
25876
  };
25799
25877
 
@@ -25820,12 +25898,107 @@ const votePoll = async (pollId, answerIds) => {
25820
25898
  if (client.cache)
25821
25899
  ingestInCache(data, { cachedAt });
25822
25900
  const { polls } = data;
25901
+ fireEvent('poll.updated', data);
25823
25902
  return {
25824
25903
  data: polls.find(poll => poll.pollId === pollId),
25825
25904
  cachedAt,
25826
25905
  };
25827
25906
  };
25828
25907
 
25908
+ /**
25909
+ * ```js
25910
+ * import { onPollUpdated } from '@amityco/ts-sdk'
25911
+ * const dispose = onPollUpdated(poll => {
25912
+ * // ...
25913
+ * })
25914
+ * ```
25915
+ *
25916
+ * Fired when an {@link Amity.Poll} has been updated
25917
+ *
25918
+ * @param callback The function to call when the event was fired
25919
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25920
+ *
25921
+ * @category Poll Events
25922
+ */
25923
+ const onPollUpdated = (callback) => {
25924
+ const client = getActiveClient();
25925
+ const filter = (payload) => {
25926
+ if (client.cache)
25927
+ ingestInCache(payload);
25928
+ callback(payload.polls[0]);
25929
+ };
25930
+ return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
25931
+ };
25932
+
25933
+ /**
25934
+ * ```js
25935
+ * import { onPollDeleted } from '@amityco/ts-sdk'
25936
+ * const dispose = onPollDeleted(poll => {
25937
+ * // ...
25938
+ * })
25939
+ * ```
25940
+ *
25941
+ * Fired when an {@link Amity.Poll} has been deleted
25942
+ *
25943
+ * @param callback The function to call when the event was fired
25944
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25945
+ *
25946
+ * @category Poll Events
25947
+ */
25948
+ const onPollDeleted = (callback) => {
25949
+ const client = getActiveClient();
25950
+ const filter = (payload) => {
25951
+ if (client.cache)
25952
+ ingestInCache(payload);
25953
+ callback(payload.polls[0]);
25954
+ };
25955
+ return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
25956
+ };
25957
+
25958
+ /**
25959
+ * ```js
25960
+ * import { observePoll } from '@amityco/ts-sdk'
25961
+ *
25962
+ * let poll = {}
25963
+ * const dispose = observePoll(pollId, updated => poll = updated)
25964
+ * ```
25965
+ *
25966
+ * Observe all mutation on a given {@link Amity.Poll}
25967
+ *
25968
+ * @param pollId the ID of the poll to observe
25969
+ * @param callback the function to call when new data are available
25970
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
25971
+ *
25972
+ * @category Poll Observer
25973
+ */
25974
+ const observePoll = (pollId, callback, policy = 'cache_then_server') => {
25975
+ const { log } = getActiveClient();
25976
+ const timestamp = Date.now();
25977
+ log(`observePoll(tmpid: ${timestamp}) > listen`);
25978
+ // wrapper function to make sure
25979
+ const router = (result, action) => {
25980
+ var _a, _b;
25981
+ if (callback instanceof Function)
25982
+ return callback(result);
25983
+ if (action !== 'onFetch')
25984
+ (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
25985
+ (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
25986
+ };
25987
+ const realtimeRouter = (result, action) => {
25988
+ var _a;
25989
+ if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
25990
+ return;
25991
+ router(result, action);
25992
+ };
25993
+ const disposers = [];
25994
+ disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
25995
+ runQuery(createQuery(getPoll, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
25996
+ return () => {
25997
+ log(`observePoll(tmpid: ${timestamp}) > dispose`);
25998
+ disposers.forEach(fn => fn());
25999
+ };
26000
+ };
26001
+
25829
26002
  /**
25830
26003
  * ```js
25831
26004
  * import { getStream } from '@amityco/ts-sdk'
@@ -26149,6 +26322,7 @@ exports.addChannelMembersRole = addChannelMembersRole;
26149
26322
  exports.addCommunityMembers = addCommunityMembers;
26150
26323
  exports.addCommunityMembersRoles = addCommunityMembersRoles;
26151
26324
  exports.addReaction = addReaction;
26325
+ exports.approvePost = approvePost;
26152
26326
  exports.backupCache = backupCache;
26153
26327
  exports.closePoll = closePoll;
26154
26328
  exports.connectClient = connectClient;
@@ -26167,6 +26341,7 @@ exports.createStream = createStream;
26167
26341
  exports.createUserToken = createUserToken;
26168
26342
  exports.createVideo = createVideo;
26169
26343
  exports.declineFollower = declineFollower;
26344
+ exports.declinePost = declinePost;
26170
26345
  exports.deleteChannel = deleteChannel;
26171
26346
  exports.deleteComment = deleteComment;
26172
26347
  exports.deleteCommunity = deleteCommunity;
@@ -26239,6 +26414,7 @@ exports.observeFollowers = observeFollowers;
26239
26414
  exports.observeFollowings = observeFollowings;
26240
26415
  exports.observeMessage = observeMessage;
26241
26416
  exports.observeMessages = observeMessages;
26417
+ exports.observePoll = observePoll;
26242
26418
  exports.observePost = observePost;
26243
26419
  exports.observePosts = observePosts;
26244
26420
  exports.observeUser = observeUser;
@@ -26276,6 +26452,8 @@ exports.onFollowerRequested = onFollowerRequested;
26276
26452
  exports.onMessageCreated = onMessageCreated;
26277
26453
  exports.onMessageDeleted = onMessageDeleted;
26278
26454
  exports.onMessageUpdated = onMessageUpdated;
26455
+ exports.onPollDeleted = onPollDeleted;
26456
+ exports.onPollUpdated = onPollUpdated;
26279
26457
  exports.onPostApproved = onPostApproved;
26280
26458
  exports.onPostCreated = onPostCreated;
26281
26459
  exports.onPostDeclined = onPostDeclined;
package/dist/index.d.ts CHANGED
@@ -36,6 +36,8 @@ export * from './comment/api';
36
36
  export * from './comment/events';
37
37
  export * from './comment/observers';
38
38
  export * from './poll/api';
39
+ export * from './poll/events';
40
+ export * from './poll/observers';
39
41
  export * from './stream/api';
40
42
  export * from './stream/events';
41
43
  export * from './external/api';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAG3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAG7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBA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AChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,gBAAgB,CAAC"}
package/dist/index.esm.js CHANGED
@@ -440,7 +440,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
440
440
  // @ts-ignore
441
441
  const modelKey = local && local.data && identifyModelKey(local.data);
442
442
  // @ts-ignore
443
- optimisticArgs = modelKey ? [Object.assign(Object.assign({}, args[0]), { [modelKey]: local.data[modelKey] })] : args;
443
+ optimisticArgs = modelKey ? [...args, { [modelKey]: local.data[modelKey] }] : args;
444
444
  }
445
445
  func(...optimisticArgs)
446
446
  .then(fresh => {
@@ -22492,6 +22492,78 @@ const deletePost = async (postId, permanent = false) => {
22492
22492
  return deleted;
22493
22493
  };
22494
22494
 
22495
+ /**
22496
+ * ```js
22497
+ * import { approvePost } from '@amityco/ts-sdk'
22498
+ *
22499
+ * const { data: post } = await approvePost('postId')
22500
+ * ```
22501
+ *
22502
+ * Approves a {@link Amity.Post}
22503
+ *
22504
+ * @param postId The {@link Amity.Post} ID to be approved
22505
+ * @return A {@link Amity.Post} that was approved
22506
+ *
22507
+ * @category Post API
22508
+ * @async
22509
+ */
22510
+ const approvePost = async (postId) => {
22511
+ var _a;
22512
+ const client = getActiveClient();
22513
+ client.log('post/approvePost', postId);
22514
+ const { data: approved } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
22515
+ const cachedAt = client.cache && Date.now();
22516
+ if (client.cache)
22517
+ ingestInCache(approved, { cachedAt });
22518
+ // fire virtual event for community update
22519
+ if (approved.posts[0].targetType === 'community') {
22520
+ const community = (_a = approved.communities) === null || _a === void 0 ? void 0 : _a[0];
22521
+ // @ts-ignore as communities is optional currently in PostPayload
22522
+ fireEvent('community.updated', { communities: [community] });
22523
+ }
22524
+ fireEvent('post.approved', { posts: [approved.posts[0]] });
22525
+ return {
22526
+ data: approved.posts.find(post => post.postId === postId),
22527
+ cachedAt,
22528
+ };
22529
+ };
22530
+
22531
+ /**
22532
+ * ```js
22533
+ * import { declinePost } from '@amityco/ts-sdk'
22534
+ *
22535
+ * const {data: post} = await declinePost('postId')
22536
+ * ```
22537
+ *
22538
+ * Declines a {@link Amity.Post}
22539
+ *
22540
+ * @param postId The {@link Amity.Post} ID to be declined
22541
+ * @return A {@link Amity.Post} that was declined
22542
+ *
22543
+ * @category Post API
22544
+ * @async
22545
+ */
22546
+ const declinePost = async (postId) => {
22547
+ var _a;
22548
+ const client = getActiveClient();
22549
+ client.log('post/declinePost', postId);
22550
+ const { data: declined } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
22551
+ const cachedAt = client.cache && Date.now();
22552
+ if (client.cache)
22553
+ ingestInCache(declined, { cachedAt });
22554
+ // fire virtual event
22555
+ if (declined.posts[0].targetType === 'community') {
22556
+ const community = (_a = declined.communities) === null || _a === void 0 ? void 0 : _a[0];
22557
+ // @ts-ignore as communities is optional currently in PostPayload
22558
+ fireEvent('community.updated', { communities: [community] });
22559
+ }
22560
+ fireEvent('post.declined', { posts: [declined.posts[0]] });
22561
+ return {
22562
+ data: declined.posts.find(post => post.postId === postId),
22563
+ cachedAt,
22564
+ };
22565
+ };
22566
+
22495
22567
  /**
22496
22568
  * ```js
22497
22569
  * import { queryComments } from '@amityco/ts-sdk'
@@ -23544,7 +23616,9 @@ const createReport = async (referenceType, referenceId) => {
23544
23616
  const client = getActiveClient();
23545
23617
  client.log('report/createReport', { referenceType, referenceId });
23546
23618
  const { domainName } = REFERENCE_TYPES[referenceType];
23547
- const { data } = await client.http.post(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`);
23619
+ const { data } = await client.http.post(`/api/${referenceType === 'user'
23620
+ ? `v4/me/flags/${encodeURIComponent(referenceId)}`
23621
+ : `v3/${domainName}/${encodeURIComponent(referenceId)}/flag`}`);
23548
23622
  if (client.cache)
23549
23623
  ingestInCache(data);
23550
23624
  const event = referenceType === 'message'
@@ -23571,7 +23645,9 @@ const deleteReport = async (referenceType, referenceId) => {
23571
23645
  const client = getActiveClient();
23572
23646
  client.log('report/deleteReport', { referenceType, referenceId });
23573
23647
  const { domainName } = REFERENCE_TYPES[referenceType];
23574
- const { data } = await client.http.delete(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`);
23648
+ const { data } = await client.http.delete(`/api/${referenceType === 'user'
23649
+ ? `v4/me/flags/${encodeURIComponent(referenceId)}`
23650
+ : `v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`}`);
23575
23651
  if (client.cache)
23576
23652
  ingestInCache(data);
23577
23653
  const event = referenceType === 'message'
@@ -25750,6 +25826,7 @@ const closePoll = async (pollId) => {
25750
25826
  const cachedAt = client.cache && Date.now();
25751
25827
  if (client.cache)
25752
25828
  ingestInCache(data, { cachedAt });
25829
+ fireEvent('poll.updated', data);
25753
25830
  const { polls } = data;
25754
25831
  return {
25755
25832
  data: polls.find(poll => poll.pollId === pollId),
@@ -25780,6 +25857,7 @@ const deletePoll = async (pollId) => {
25780
25857
  const { success } = data; // unwrapPayload(data)
25781
25858
  const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
25782
25859
  upsertInCache(['poll', 'get', pollId], deleted);
25860
+ fireEvent('poll.deleted', { polls: [deleted], users: [] });
25783
25861
  return success;
25784
25862
  };
25785
25863
 
@@ -25806,12 +25884,107 @@ const votePoll = async (pollId, answerIds) => {
25806
25884
  if (client.cache)
25807
25885
  ingestInCache(data, { cachedAt });
25808
25886
  const { polls } = data;
25887
+ fireEvent('poll.updated', data);
25809
25888
  return {
25810
25889
  data: polls.find(poll => poll.pollId === pollId),
25811
25890
  cachedAt,
25812
25891
  };
25813
25892
  };
25814
25893
 
25894
+ /**
25895
+ * ```js
25896
+ * import { onPollUpdated } from '@amityco/ts-sdk'
25897
+ * const dispose = onPollUpdated(poll => {
25898
+ * // ...
25899
+ * })
25900
+ * ```
25901
+ *
25902
+ * Fired when an {@link Amity.Poll} has been updated
25903
+ *
25904
+ * @param callback The function to call when the event was fired
25905
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25906
+ *
25907
+ * @category Poll Events
25908
+ */
25909
+ const onPollUpdated = (callback) => {
25910
+ const client = getActiveClient();
25911
+ const filter = (payload) => {
25912
+ if (client.cache)
25913
+ ingestInCache(payload);
25914
+ callback(payload.polls[0]);
25915
+ };
25916
+ return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
25917
+ };
25918
+
25919
+ /**
25920
+ * ```js
25921
+ * import { onPollDeleted } from '@amityco/ts-sdk'
25922
+ * const dispose = onPollDeleted(poll => {
25923
+ * // ...
25924
+ * })
25925
+ * ```
25926
+ *
25927
+ * Fired when an {@link Amity.Poll} has been deleted
25928
+ *
25929
+ * @param callback The function to call when the event was fired
25930
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25931
+ *
25932
+ * @category Poll Events
25933
+ */
25934
+ const onPollDeleted = (callback) => {
25935
+ const client = getActiveClient();
25936
+ const filter = (payload) => {
25937
+ if (client.cache)
25938
+ ingestInCache(payload);
25939
+ callback(payload.polls[0]);
25940
+ };
25941
+ return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
25942
+ };
25943
+
25944
+ /**
25945
+ * ```js
25946
+ * import { observePoll } from '@amityco/ts-sdk'
25947
+ *
25948
+ * let poll = {}
25949
+ * const dispose = observePoll(pollId, updated => poll = updated)
25950
+ * ```
25951
+ *
25952
+ * Observe all mutation on a given {@link Amity.Poll}
25953
+ *
25954
+ * @param pollId the ID of the poll to observe
25955
+ * @param callback the function to call when new data are available
25956
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
25957
+ *
25958
+ * @category Poll Observer
25959
+ */
25960
+ const observePoll = (pollId, callback, policy = 'cache_then_server') => {
25961
+ const { log } = getActiveClient();
25962
+ const timestamp = Date.now();
25963
+ log(`observePoll(tmpid: ${timestamp}) > listen`);
25964
+ // wrapper function to make sure
25965
+ const router = (result, action) => {
25966
+ var _a, _b;
25967
+ if (callback instanceof Function)
25968
+ return callback(result);
25969
+ if (action !== 'onFetch')
25970
+ (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
25971
+ (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
25972
+ };
25973
+ const realtimeRouter = (result, action) => {
25974
+ var _a;
25975
+ if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
25976
+ return;
25977
+ router(result, action);
25978
+ };
25979
+ const disposers = [];
25980
+ disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
25981
+ runQuery(createQuery(getPoll, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
25982
+ return () => {
25983
+ log(`observePoll(tmpid: ${timestamp}) > dispose`);
25984
+ disposers.forEach(fn => fn());
25985
+ };
25986
+ };
25987
+
25815
25988
  /**
25816
25989
  * ```js
25817
25990
  * import { getStream } from '@amityco/ts-sdk'
@@ -26127,4 +26300,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
26127
26300
  return { accessToken: data.accessToken };
26128
26301
  };
26129
26302
 
26130
- export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
26303
+ export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };