@amityco/ts-sdk 0.0.1-be4fc2f.0 → 0.0.1-beta.10
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/README.md +2 -2
- package/dist/@types/core/cache.d.ts +49 -9
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +22 -12
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +1 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/paging.d.ts +59 -0
- package/dist/@types/core/paging.d.ts.map +1 -0
- package/dist/@types/core/permissions.d.ts +1 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +13 -43
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +3 -2
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +1 -1
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +2 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +1 -2
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +1 -1
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +3 -3
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +1 -1
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +2 -1
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cache/api/backupCache.d.ts +24 -0
- package/dist/cache/api/backupCache.d.ts.map +1 -0
- package/dist/cache/api/disableCache.d.ts +13 -0
- package/dist/cache/api/disableCache.d.ts.map +1 -0
- package/dist/cache/api/dropFromCache.d.ts +17 -0
- package/dist/cache/api/dropFromCache.d.ts.map +1 -0
- package/dist/cache/api/enableCache.d.ts +18 -0
- package/dist/cache/api/enableCache.d.ts.map +1 -0
- package/dist/cache/api/index.d.ts +12 -0
- package/dist/cache/api/index.d.ts.map +1 -0
- package/dist/cache/api/ingestInCache.d.ts +11 -0
- package/dist/cache/api/ingestInCache.d.ts.map +1 -0
- package/dist/cache/api/mergeInCache.d.ts +20 -0
- package/dist/cache/api/mergeInCache.d.ts.map +1 -0
- package/dist/cache/api/pullFromCache.d.ts +17 -0
- package/dist/cache/api/pullFromCache.d.ts.map +1 -0
- package/dist/cache/api/pushToCache.d.ts +17 -0
- package/dist/cache/api/pushToCache.d.ts.map +1 -0
- package/dist/cache/api/queryCache.d.ts +17 -0
- package/dist/cache/api/queryCache.d.ts.map +1 -0
- package/dist/cache/api/restoreCache.d.ts +22 -0
- package/dist/cache/api/restoreCache.d.ts.map +1 -0
- package/dist/cache/api/snipeIdFromCollection.d.ts +18 -0
- package/dist/cache/api/snipeIdFromCollection.d.ts.map +1 -0
- package/dist/cache/api/upsertInCache.d.ts +19 -0
- package/dist/cache/api/upsertInCache.d.ts.map +1 -0
- package/dist/cache/api/wipeCache.d.ts +21 -0
- package/dist/cache/api/wipeCache.d.ts.map +1 -0
- package/dist/cache/utils/index.d.ts +41 -0
- package/dist/cache/utils/index.d.ts.map +1 -0
- package/dist/category/api/getCategory.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +5 -4
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/createChannel.d.ts +1 -1
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/deleteChannel.d.ts +1 -1
- package/dist/channel/api/deleteChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts +2 -2
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts +2 -2
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +1 -5
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +1 -5
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/events/onMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onMemberRemoved.d.ts.map +1 -1
- package/dist/channel/observers/observeChannel.d.ts +1 -3
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/disconnectClient.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts +3 -1
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +0 -2
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/comment/api/createComment.d.ts +1 -1
- package/dist/comment/api/createComment.d.ts.map +1 -1
- package/dist/comment/api/deleteComment.d.ts +1 -37
- package/dist/comment/api/deleteComment.d.ts.map +1 -1
- package/dist/comment/api/getComment.d.ts +2 -2
- package/dist/comment/api/getComment.d.ts.map +1 -1
- package/dist/comment/api/getComments.d.ts +2 -2
- package/dist/comment/api/getComments.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts +4 -18
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/comment/api/updateComment.d.ts +1 -1
- package/dist/comment/api/updateComment.d.ts.map +1 -1
- package/dist/comment/events/onCommentCreated.d.ts +2 -2
- package/dist/comment/events/onCommentCreated.d.ts.map +1 -1
- package/dist/comment/events/onCommentDeleted.d.ts +2 -2
- package/dist/comment/events/onCommentDeleted.d.ts.map +1 -1
- package/dist/comment/events/onCommentFlagged.d.ts +2 -2
- package/dist/comment/events/onCommentFlagged.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionAdded.d.ts +2 -2
- package/dist/comment/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionRemoved.d.ts +2 -2
- package/dist/comment/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/comment/events/onCommentUnflagged.d.ts +2 -2
- package/dist/comment/events/onCommentUnflagged.d.ts.map +1 -1
- package/dist/comment/events/onCommentUpdated.d.ts +2 -2
- package/dist/comment/events/onCommentUpdated.d.ts.map +1 -1
- package/dist/comment/events/utils.d.ts +1 -1
- package/dist/comment/events/utils.d.ts.map +1 -1
- package/dist/comment/observers/observeComment.d.ts +1 -3
- package/dist/comment/observers/observeComment.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembersRole.d.ts.map +1 -1
- package/dist/community/api/createCommunity.d.ts +1 -1
- package/dist/community/api/createCommunity.d.ts.map +1 -1
- package/dist/community/api/deleteCommunity.d.ts.map +1 -1
- package/dist/community/api/getCommunities.d.ts +2 -2
- package/dist/community/api/getCommunities.d.ts.map +1 -1
- package/dist/community/api/getCommunity.d.ts +2 -2
- package/dist/community/api/getCommunity.d.ts.map +1 -1
- package/dist/community/api/joinCommunity.d.ts.map +1 -1
- package/dist/community/api/leaveCommunity.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts +1 -5
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunityMembers.d.ts +1 -5
- package/dist/community/api/queryCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembersRole.d.ts.map +1 -1
- package/dist/community/api/updateCommunity.d.ts +1 -1
- package/dist/community/api/updateCommunity.d.ts.map +1 -1
- package/dist/community/events/onCommunityCreated.d.ts +1 -1
- package/dist/community/events/onCommunityDeleted.d.ts +1 -1
- package/dist/community/events/onCommunityJoined.d.ts +3 -3
- package/dist/community/events/onCommunityJoined.d.ts.map +1 -1
- package/dist/community/events/onCommunityLeft.d.ts +3 -3
- package/dist/community/events/onCommunityLeft.d.ts.map +1 -1
- package/dist/community/events/onCommunityUpdated.d.ts +1 -1
- package/dist/community/events/onCommunityUserAdded.d.ts +3 -3
- package/dist/community/events/onCommunityUserAdded.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserBanned.d.ts +3 -3
- package/dist/community/events/onCommunityUserBanned.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserRemoved.d.ts +3 -3
- package/dist/community/events/onCommunityUserRemoved.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserUnbanned.d.ts +3 -3
- package/dist/community/events/onCommunityUserUnbanned.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts +1 -0
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/observers/observeCommunity.d.ts +1 -3
- package/dist/community/observers/observeCommunity.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts +9 -11
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +6 -2
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/index.d.ts +0 -1
- package/dist/core/query/index.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +21 -3
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +9 -21
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +13 -2
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/core/transports/mqtt.d.ts +2 -1
- package/dist/core/transports/mqtt.d.ts.map +1 -1
- package/dist/core/transports/ws.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +1 -5
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/file/api/createFile.d.ts +1 -1
- package/dist/file/api/createFile.d.ts.map +1 -1
- package/dist/file/api/deleteFile.d.ts.map +1 -1
- package/dist/file/api/getFile.d.ts +2 -2
- package/dist/file/api/getFile.d.ts.map +1 -1
- package/dist/file/observers/observeFile.d.ts +1 -3
- package/dist/file/observers/observeFile.d.ts.map +1 -1
- package/dist/index.cjs.js +17428 -2854
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +17411 -2840
- package/dist/index.umd.js +6 -4
- package/dist/message/api/createMessage.d.ts +2 -2
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/deleteMessage.d.ts +2 -2
- package/dist/message/api/deleteMessage.d.ts.map +1 -1
- package/dist/message/api/getMessage.d.ts +2 -2
- package/dist/message/api/getMessage.d.ts.map +1 -1
- package/dist/message/api/getMessages.d.ts +2 -2
- package/dist/message/api/getMessages.d.ts.map +1 -1
- package/dist/message/api/queryMessages.d.ts +2 -16
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/api/updateMessage.d.ts +2 -2
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/message/events/onMessageCreated.d.ts.map +1 -1
- package/dist/message/events/onMessageDeleted.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/message/observers/observeMessage.d.ts +1 -3
- package/dist/message/observers/observeMessage.d.ts.map +1 -1
- package/dist/message/observers/observeMessages.d.ts +1 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/post/api/createPost.d.ts +1 -1
- package/dist/post/api/createPost.d.ts.map +1 -1
- package/dist/post/api/deletePost.d.ts +1 -40
- package/dist/post/api/deletePost.d.ts.map +1 -1
- package/dist/post/api/getPost.d.ts +5 -5
- package/dist/post/api/getPost.d.ts.map +1 -1
- package/dist/post/api/getPosts.d.ts +4 -4
- package/dist/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts +4 -8
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/api/updatePost.d.ts +1 -1
- package/dist/post/api/updatePost.d.ts.map +1 -1
- package/dist/post/events/onPostApproved.d.ts +1 -1
- package/dist/post/events/onPostCreated.d.ts +1 -1
- package/dist/post/events/onPostDeclined.d.ts +1 -1
- package/dist/post/events/onPostDeleted.d.ts +1 -1
- package/dist/post/events/onPostDeleted.d.ts.map +1 -1
- package/dist/post/events/onPostFlagged.d.ts +1 -1
- package/dist/post/events/onPostReactionAdded.d.ts +1 -1
- package/dist/post/events/onPostReactionAdded.d.ts.map +1 -1
- package/dist/post/events/onPostReactionRemoved.d.ts +1 -1
- package/dist/post/events/onPostReactionRemoved.d.ts.map +1 -1
- package/dist/post/events/onPostUnflagged.d.ts +1 -1
- package/dist/post/events/onPostUpdated.d.ts +1 -1
- package/dist/post/events/utils.d.ts.map +1 -1
- package/dist/post/observers/observePost.d.ts +1 -3
- package/dist/post/observers/observePost.d.ts.map +1 -1
- package/dist/reaction/api/addReaction.d.ts +1 -1
- package/dist/reaction/api/addReaction.d.ts.map +1 -1
- package/dist/reaction/api/removeReaction.d.ts +1 -1
- package/dist/reaction/api/removeReaction.d.ts.map +1 -1
- package/dist/reaction/events/onReactionAdded.d.ts +4 -2
- package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
- package/dist/reaction/events/onReactionRemoved.d.ts +4 -2
- package/dist/reaction/events/onReactionRemoved.d.ts.map +1 -1
- package/dist/reaction/utils/fetchReference.d.ts +1 -1
- package/dist/reaction/utils/fetchReference.d.ts.map +1 -1
- package/dist/reaction/utils/index.d.ts +1 -0
- package/dist/reaction/utils/index.d.ts.map +1 -1
- package/dist/reaction/utils/preparePayloadForCache.d.ts +3 -0
- package/dist/reaction/utils/preparePayloadForCache.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/role/api/getRole.d.ts +2 -2
- package/dist/role/api/getRole.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +1 -5
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/stream/api/createStream.d.ts +1 -1
- package/dist/stream/api/createStream.d.ts.map +1 -1
- package/dist/stream/api/deleteStream.d.ts.map +1 -1
- package/dist/stream/api/disposeStream.d.ts +1 -1
- package/dist/stream/api/disposeStream.d.ts.map +1 -1
- package/dist/stream/api/getStream.d.ts +2 -2
- package/dist/stream/api/getStream.d.ts.map +1 -1
- package/dist/stream/api/queryStreams.d.ts +1 -5
- package/dist/stream/api/queryStreams.d.ts.map +1 -1
- package/dist/stream/api/updateStream.d.ts +1 -1
- package/dist/stream/api/updateStream.d.ts.map +1 -1
- package/dist/stream/events/onStreamRecorded.d.ts.map +1 -1
- package/dist/stream/events/onStreamStarted.d.ts.map +1 -1
- package/dist/stream/events/onStreamStopped.d.ts.map +1 -1
- package/dist/user/api/getUser.d.ts +4 -4
- package/dist/user/api/getUser.d.ts.map +1 -1
- package/dist/user/api/getUsers.d.ts +4 -4
- package/dist/user/api/getUsers.d.ts.map +1 -1
- package/dist/user/api/queryUsers.d.ts +7 -11
- package/dist/user/api/queryUsers.d.ts.map +1 -1
- package/dist/user/api/updateUser.d.ts +1 -1
- package/dist/user/api/updateUser.d.ts.map +1 -1
- package/dist/user/events/onUserFlagCleared.d.ts +1 -1
- package/dist/user/events/onUserFlagged.d.ts +1 -1
- package/dist/user/events/onUserUnflagged.d.ts +1 -1
- package/dist/user/events/onUserUpdated.d.ts +1 -1
- package/dist/user/events/utils.d.ts.map +1 -1
- package/dist/user/observers/observeUser.d.ts +1 -3
- package/dist/user/observers/observeUser.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/@types/core/cache.ts +56 -9
- package/src/@types/core/events.ts +14 -11
- package/src/@types/core/model.ts +2 -0
- package/src/@types/core/paging.ts +75 -0
- package/src/@types/core/permissions.ts +0 -1
- package/src/@types/core/query.ts +14 -55
- package/src/@types/core/transport.ts +4 -2
- package/src/@types/domains/category.ts +0 -1
- package/src/@types/domains/channel.ts +0 -1
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/comment.ts +0 -1
- package/src/@types/domains/community.ts +0 -1
- package/src/@types/domains/content.ts +17 -15
- package/src/@types/domains/file.ts +0 -1
- package/src/@types/domains/group.ts +2 -3
- package/src/@types/domains/message.ts +0 -1
- package/src/@types/domains/post.ts +8 -8
- package/src/@types/domains/stream.ts +0 -1
- package/src/@types/domains/user.ts +1 -1
- package/src/@types/index.ts +1 -1
- package/src/@types/mqtt.d.ts +3 -0
- package/src/cache/api/backupCache.ts +53 -0
- package/src/cache/api/disableCache.ts +23 -0
- package/src/cache/api/dropFromCache.ts +44 -0
- package/src/cache/api/enableCache.ts +29 -0
- package/src/cache/api/index.ts +23 -0
- package/src/cache/api/ingestInCache.ts +33 -0
- package/src/cache/api/mergeInCache.ts +45 -0
- package/src/cache/api/pullFromCache.ts +33 -0
- package/src/cache/api/pushToCache.ts +40 -0
- package/src/cache/api/queryCache.ts +35 -0
- package/src/cache/api/restoreCache.ts +43 -0
- package/src/cache/api/snipeIdFromCollection.ts +53 -0
- package/src/cache/api/upsertInCache.ts +39 -0
- package/src/cache/api/wipeCache.ts +36 -0
- package/src/cache/utils/index.ts +84 -0
- package/src/category/api/getCategory.ts +3 -4
- package/src/category/api/queryCategories.ts +5 -6
- package/src/channel/api/addChannelMembers.ts +4 -5
- package/src/channel/api/addChannelMembersRole.ts +3 -5
- package/src/channel/api/createChannel.ts +16 -11
- package/src/channel/api/deleteChannel.ts +2 -2
- package/src/channel/api/getChannel.ts +22 -9
- package/src/channel/api/getChannels.ts +25 -12
- package/src/channel/api/joinChannel.ts +5 -6
- package/src/channel/api/leaveChannel.ts +5 -6
- package/src/channel/api/queryChannelMembers.ts +9 -11
- package/src/channel/api/queryChannels.ts +19 -12
- package/src/channel/api/removeChannelMembers.ts +4 -5
- package/src/channel/api/removeChannelMembersRole.ts +3 -5
- package/src/channel/api/updateChannel.ts +9 -7
- package/src/channel/events/onChannelDeleted.ts +1 -3
- package/src/channel/events/onChannelJoined.ts +1 -3
- package/src/channel/events/onChannelLeft.ts +1 -3
- package/src/channel/events/onChannelUpdated.ts +1 -3
- package/src/channel/events/onMemberAdded.ts +1 -3
- package/src/channel/events/onMemberRemoved.ts +1 -3
- package/src/channel/observers/observeChannel.ts +20 -14
- package/src/client/api/connectClient.ts +7 -7
- package/src/client/api/disconnectClient.ts +3 -0
- package/src/client/api/getToken.ts +3 -2
- package/src/client/api/index.ts +3 -2
- package/src/comment/api/createComment.ts +10 -7
- package/src/comment/api/deleteComment.ts +9 -8
- package/src/comment/api/getComment.ts +22 -10
- package/src/comment/api/getComments.ts +25 -12
- package/src/comment/api/queryComments.ts +35 -89
- package/src/comment/api/updateComment.ts +9 -6
- package/src/comment/events/onCommentCreated.ts +3 -3
- package/src/comment/events/onCommentDeleted.ts +3 -3
- package/src/comment/events/onCommentFlagged.ts +3 -3
- package/src/comment/events/onCommentReactionAdded.ts +40 -6
- package/src/comment/events/onCommentReactionRemoved.ts +40 -6
- package/src/comment/events/onCommentUnflagged.ts +3 -3
- package/src/comment/events/onCommentUpdated.ts +3 -3
- package/src/comment/events/utils.ts +30 -8
- package/src/comment/observers/observeComment.ts +20 -25
- package/src/community/api/addCommunityMembers.ts +5 -6
- package/src/community/api/addCommunityMembersRole.ts +3 -5
- package/src/community/api/createCommunity.ts +9 -6
- package/src/community/api/deleteCommunity.ts +3 -3
- package/src/community/api/getCommunities.ts +25 -12
- package/src/community/api/getCommunity.ts +23 -9
- package/src/community/api/joinCommunity.ts +7 -5
- package/src/community/api/leaveCommunity.ts +7 -5
- package/src/community/api/queryCommunities.ts +18 -12
- package/src/community/api/queryCommunityMembers.ts +10 -11
- package/src/community/api/removeCommunityMembers.ts +4 -5
- package/src/community/api/removeCommunityMembersRole.ts +3 -5
- package/src/community/api/updateCommunity.ts +10 -7
- package/src/community/events/onCommunityCreated.ts +1 -1
- package/src/community/events/onCommunityDeleted.ts +1 -1
- package/src/community/events/onCommunityJoined.ts +5 -5
- package/src/community/events/onCommunityLeft.ts +5 -5
- package/src/community/events/onCommunityUpdated.ts +1 -1
- package/src/community/events/onCommunityUserAdded.ts +5 -5
- package/src/community/events/onCommunityUserBanned.ts +5 -5
- package/src/community/events/onCommunityUserRemoved.ts +5 -5
- package/src/community/events/onCommunityUserUnbanned.ts +5 -5
- package/src/community/events/utils.ts +94 -4
- package/src/community/observers/observeCommunity.ts +21 -22
- package/src/core/model/idResolvers.ts +10 -40
- package/src/core/model/identifyModel.ts +37 -16
- package/src/core/model/index.ts +22 -2
- package/src/core/query/index.ts +0 -1
- package/src/core/query/paging.ts +43 -3
- package/src/core/query/query.ts +63 -115
- package/src/core/subscription.ts +66 -17
- package/src/core/transports/mqtt.ts +86 -20
- package/src/core/transports/ws.ts +1 -0
- package/src/feed/api/queryGlobalFeed.ts +7 -10
- package/src/file/api/createFile.ts +8 -6
- package/src/file/api/deleteFile.ts +5 -6
- package/src/file/api/getFile.ts +21 -9
- package/src/file/observers/observeFile.ts +5 -7
- package/src/index.ts +6 -6
- package/src/message/api/createMessage.ts +21 -17
- package/src/message/api/deleteMessage.ts +12 -11
- package/src/message/api/getMessage.ts +22 -10
- package/src/message/api/getMessages.ts +25 -12
- package/src/message/api/queryMessages.ts +34 -68
- package/src/message/api/updateMessage.ts +22 -12
- package/src/message/events/onMessageCreated.ts +1 -3
- package/src/message/events/onMessageDeleted.ts +1 -3
- package/src/message/events/onMessageUpdated.ts +1 -3
- package/src/message/observers/observeMessage.ts +8 -10
- package/src/message/observers/observeMessages.ts +6 -6
- package/src/post/api/createPost.ts +9 -6
- package/src/post/api/deletePost.ts +11 -9
- package/src/post/api/getPost.ts +26 -14
- package/src/post/api/getPosts.ts +27 -14
- package/src/post/api/queryPosts.ts +46 -19
- package/src/post/api/updatePost.ts +10 -6
- package/src/post/events/onPostApproved.ts +1 -1
- package/src/post/events/onPostCreated.ts +1 -1
- package/src/post/events/onPostDeclined.ts +1 -1
- package/src/post/events/onPostDeleted.ts +2 -2
- package/src/post/events/onPostFlagged.ts +1 -1
- package/src/post/events/onPostReactionAdded.ts +38 -4
- package/src/post/events/onPostReactionRemoved.ts +38 -4
- package/src/post/events/onPostUnflagged.ts +1 -1
- package/src/post/events/onPostUpdated.ts +1 -1
- package/src/post/events/utils.ts +39 -6
- package/src/post/observers/observePost.ts +22 -27
- package/src/reaction/api/addReaction.ts +30 -20
- package/src/reaction/api/removeReaction.ts +30 -20
- package/src/reaction/events/onReactionAdded.ts +37 -18
- package/src/reaction/events/onReactionRemoved.ts +38 -15
- package/src/reaction/utils/fetchReference.ts +1 -1
- package/src/reaction/utils/index.ts +1 -0
- package/src/reaction/utils/preparePayloadForCache.ts +45 -0
- package/src/report/api/createReport.ts +4 -5
- package/src/report/api/deleteReport.ts +4 -5
- package/src/role/api/getRole.ts +25 -9
- package/src/role/api/queryRoles.ts +10 -12
- package/src/stream/api/createStream.ts +9 -6
- package/src/stream/api/deleteStream.ts +10 -1
- package/src/stream/api/disposeStream.ts +10 -6
- package/src/stream/api/getStream.ts +23 -10
- package/src/stream/api/queryStreams.ts +10 -11
- package/src/stream/api/updateStream.ts +9 -6
- package/src/stream/events/onStreamRecorded.ts +1 -3
- package/src/stream/events/onStreamStarted.ts +1 -3
- package/src/stream/events/onStreamStopped.ts +1 -3
- package/src/user/api/getUser.ts +14 -11
- package/src/user/api/getUsers.ts +30 -14
- package/src/user/api/queryUsers.ts +40 -17
- package/src/user/api/updateUser.ts +10 -7
- package/src/user/events/onUserFlagCleared.ts +1 -1
- package/src/user/events/onUserFlagged.ts +1 -1
- package/src/user/events/onUserUnflagged.ts +1 -1
- package/src/user/events/onUserUpdated.ts +1 -1
- package/src/user/events/utils.ts +6 -4
- package/src/user/observers/observeUser.ts +9 -11
- package/dist/@types/core/store.d.ts +0 -46
- package/dist/@types/core/store.d.ts.map +0 -1
- package/dist/client/api/clearCache.d.ts +0 -15
- package/dist/client/api/clearCache.d.ts.map +0 -1
- package/dist/client/api/enableCache.d.ts +0 -15
- package/dist/client/api/enableCache.d.ts.map +0 -1
- package/dist/core/cache/drop.d.ts +0 -11
- package/dist/core/cache/drop.d.ts.map +0 -1
- package/dist/core/cache/index.d.ts +0 -19
- package/dist/core/cache/index.d.ts.map +0 -1
- package/dist/core/cache/ingest.d.ts +0 -10
- package/dist/core/cache/ingest.d.ts.map +0 -1
- package/dist/core/cache/merge.d.ts +0 -10
- package/dist/core/cache/merge.d.ts.map +0 -1
- package/dist/core/cache/mutate.d.ts +0 -10
- package/dist/core/cache/mutate.d.ts.map +0 -1
- package/dist/core/cache/pull.d.ts +0 -11
- package/dist/core/cache/pull.d.ts.map +0 -1
- package/dist/core/cache/push.d.ts +0 -10
- package/dist/core/cache/push.d.ts.map +0 -1
- package/dist/core/cache/sync.d.ts +0 -10
- package/dist/core/cache/sync.d.ts.map +0 -1
- package/dist/core/model/toRecord.d.ts +0 -10
- package/dist/core/model/toRecord.d.ts.map +0 -1
- package/dist/core/query/decorate.d.ts +0 -23
- package/dist/core/query/decorate.d.ts.map +0 -1
- package/dist/core/stores/index.d.ts +0 -3
- package/dist/core/stores/index.d.ts.map +0 -1
- package/dist/core/stores/memory.d.ts +0 -30
- package/dist/core/stores/memory.d.ts.map +0 -1
- package/dist/core/stores/persistent.d.ts +0 -13
- package/dist/core/stores/persistent.d.ts.map +0 -1
- package/src/@types/core/store.ts +0 -52
- package/src/client/api/clearCache.ts +0 -23
- package/src/client/api/enableCache.ts +0 -36
- package/src/core/cache/drop.ts +0 -24
- package/src/core/cache/index.ts +0 -24
- package/src/core/cache/ingest.ts +0 -24
- package/src/core/cache/merge.ts +0 -19
- package/src/core/cache/mutate.ts +0 -25
- package/src/core/cache/pull.ts +0 -31
- package/src/core/cache/push.ts +0 -41
- package/src/core/cache/sync.ts +0 -41
- package/src/core/model/toRecord.ts +0 -11
- package/src/core/query/decorate.ts +0 -64
- package/src/core/stores/index.ts +0 -2
- package/src/core/stores/memory.ts +0 -59
- package/src/core/stores/persistent.ts +0 -63
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { encodeKey } from '../utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { pullFromCache } from '@amityco/ts-sdk'
|
|
8
|
+
* const user = pullFromCache<Amity.User>(["user", "foobar"])
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Retrieves a {@link Amity.CacheEntry} object matching a given
|
|
12
|
+
* {@link Amity.CacheKey}. The cache entry is not typed, so the
|
|
13
|
+
* expected returned type must be passed manually.
|
|
14
|
+
*
|
|
15
|
+
* @param key the key matching the object to retrieve from cache
|
|
16
|
+
* @returns the matching cache entry, or undefined.
|
|
17
|
+
*
|
|
18
|
+
* @category Cache API
|
|
19
|
+
*/
|
|
20
|
+
export const pullFromCache = <T extends unknown>(
|
|
21
|
+
key: Amity.CacheKey
|
|
22
|
+
): Amity.CacheEntry<T> | undefined => {
|
|
23
|
+
const { log, cache } = getActiveClient()
|
|
24
|
+
|
|
25
|
+
if (!cache) return
|
|
26
|
+
log('cache/api/pullFromCache', key)
|
|
27
|
+
|
|
28
|
+
const str = encodeKey(key)
|
|
29
|
+
|
|
30
|
+
return !!cache.data[str]
|
|
31
|
+
? cache.data[str] as Amity.CacheEntry<T>
|
|
32
|
+
: undefined
|
|
33
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { encodeKey } from '../utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { pushToCache } from '@amityco/ts-sdk'
|
|
8
|
+
* pushToCache<Amity.User>(["user", "foobar"], user)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Saves any provided value as {@link Amity.CacheEntry} for the matching {@link Amity.CacheKey}
|
|
12
|
+
*
|
|
13
|
+
* @param key the key to save the object to
|
|
14
|
+
* @param data the object to save
|
|
15
|
+
* @param options customisation object around cache behavior (default gives a 2mn lifespan)
|
|
16
|
+
* @returns a success boolean if the object was saved in cache
|
|
17
|
+
*
|
|
18
|
+
* @category Cache API
|
|
19
|
+
*/
|
|
20
|
+
export const pushToCache = (
|
|
21
|
+
key: Amity.CacheKey,
|
|
22
|
+
data: unknown,
|
|
23
|
+
options: Amity.CacheOptions = { cachedAt: Date.now() },
|
|
24
|
+
): boolean => {
|
|
25
|
+
const { log, cache } = getActiveClient()
|
|
26
|
+
|
|
27
|
+
if (!cache) return false
|
|
28
|
+
log('cache/api/pushToCache', { key, data, options })
|
|
29
|
+
|
|
30
|
+
// if consumer did not pass offline but a offline policy is
|
|
31
|
+
// defined, use the fn to determine if the object needs to
|
|
32
|
+
// be saved in persistent storage or not.
|
|
33
|
+
if (!options?.hasOwnProperty('offline') && cache.persistIf)
|
|
34
|
+
options.offline = cache.persistIf(key, data)
|
|
35
|
+
|
|
36
|
+
const encodedKey = encodeKey(key)
|
|
37
|
+
cache.data[encodedKey] = { key, data, ...options }
|
|
38
|
+
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { decodeKey, partialMatch } from '../utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { queryCache } from '@amityco/ts-sdk'
|
|
8
|
+
* const entries = queryCache(["user"])
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Retrieves a list of {@link Amity.CacheEntry} objects matching a
|
|
12
|
+
* partial {@link Amity.CacheKey}. The cache entries can't be typed,
|
|
13
|
+
* but the expected returned type can be passed manually.
|
|
14
|
+
*
|
|
15
|
+
* @param partialKey the partial key matching the objects to retrieve from cache
|
|
16
|
+
* @returns the matching cache entries, or empty array.
|
|
17
|
+
*
|
|
18
|
+
* @category Cache API
|
|
19
|
+
*/
|
|
20
|
+
export const queryCache = <T extends unknown>(
|
|
21
|
+
key: Amity.CacheKey
|
|
22
|
+
): Amity.CacheEntry<T>[] | undefined => {
|
|
23
|
+
const { log, cache } = getActiveClient()
|
|
24
|
+
|
|
25
|
+
if (!cache) return
|
|
26
|
+
log('cache/api/queryCache', { key })
|
|
27
|
+
|
|
28
|
+
return Object
|
|
29
|
+
.keys(cache.data)
|
|
30
|
+
.filter(stringKey => {
|
|
31
|
+
const decodedKey = decodeKey(stringKey)
|
|
32
|
+
return partialMatch(key, decodedKey)
|
|
33
|
+
})
|
|
34
|
+
.map(stringKey => cache.data[stringKey]) as Amity.CacheEntry<T>[]
|
|
35
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { restoreCache } from '@amityco/ts-sdk'
|
|
8
|
+
* const success = await restoreCache()
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Reads a previously saved {@link Amity.Cache} from a persistent storage,
|
|
12
|
+
* and inserts it into the current {@link Amity.Cache} instance.
|
|
13
|
+
*
|
|
14
|
+
* The strategy for persistent storage will depend on the runtime,
|
|
15
|
+
* which is supported by @react-native-async-storage/async-storage.
|
|
16
|
+
*
|
|
17
|
+
* The current userId will be appended to the given storageKey to ensures
|
|
18
|
+
* the cached data concerns only the current user.
|
|
19
|
+
*
|
|
20
|
+
* @param storageKey the name of the persistent storage
|
|
21
|
+
* @returns a success boolean if the cache was dumped to persistent storage
|
|
22
|
+
*
|
|
23
|
+
* @category Cache API
|
|
24
|
+
*/
|
|
25
|
+
export const restoreCache = async (
|
|
26
|
+
storageKey: string = 'amitySdk'
|
|
27
|
+
) => {
|
|
28
|
+
const client = getActiveClient()
|
|
29
|
+
|
|
30
|
+
if (!client.cache) return false
|
|
31
|
+
client.log('cache/api/restoreCache', { storageKey })
|
|
32
|
+
|
|
33
|
+
const serializedData = (await AsyncStorage.getItem(`${storageKey}#${client.userId}`)) ?? '{}'
|
|
34
|
+
|
|
35
|
+
let cache: Amity.Cache['data'] = {}
|
|
36
|
+
|
|
37
|
+
try { cache = JSON.parse(serializedData) }
|
|
38
|
+
catch (err) {}
|
|
39
|
+
|
|
40
|
+
// current cache should override. in case there's something fresher.
|
|
41
|
+
client.cache.data = { ...cache, ...client.cache.data }
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { queryCache, mergeInCache, dropFromCache } from '.';
|
|
4
|
+
|
|
5
|
+
import { decodeKey, partialMatch } from '../utils'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ```js
|
|
9
|
+
* import { snipeFromCollection } from '@amityco/ts-sdk'
|
|
10
|
+
* const user = snipeFromCollection("user", "foobar")
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Removes a {@link Amity.Model} object from matching a given
|
|
14
|
+
* {@link Amity.CacheKey}. The cache entry is not typed, so the
|
|
15
|
+
* expected returned type must be passed manually.
|
|
16
|
+
*
|
|
17
|
+
* @param domain the key matching the object to retrieve from cache
|
|
18
|
+
* @param id the key matching the object to retrieve from cache
|
|
19
|
+
* @returns a success boolean if the id was removed from all matching collections
|
|
20
|
+
*
|
|
21
|
+
* @category Cache API
|
|
22
|
+
*/
|
|
23
|
+
export const snipeIdFromCollections = (
|
|
24
|
+
domain: Amity.Domain,
|
|
25
|
+
id: string,
|
|
26
|
+
) => {
|
|
27
|
+
const { log, cache } = getActiveClient()
|
|
28
|
+
|
|
29
|
+
if (!cache) return false
|
|
30
|
+
log('cache/api/snipeFromCollections', { domain, id })
|
|
31
|
+
|
|
32
|
+
const entries = (queryCache<unknown[]>([domain, 'query']) ?? [])
|
|
33
|
+
.filter(entry => entry?.data.includes(id))
|
|
34
|
+
|
|
35
|
+
if (!entries.length)
|
|
36
|
+
return false
|
|
37
|
+
|
|
38
|
+
const toBeDeleted: Amity.CacheKey[] = []
|
|
39
|
+
|
|
40
|
+
entries.forEach(({ key }) => {
|
|
41
|
+
mergeInCache<unknown[]>(key, (oldVal) => {
|
|
42
|
+
const newVal = oldVal.filter(itemId => itemId !== id)
|
|
43
|
+
|
|
44
|
+
if (!newVal.length)
|
|
45
|
+
toBeDeleted.push(key)
|
|
46
|
+
|
|
47
|
+
return newVal
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
toBeDeleted.forEach(key => dropFromCache(key, true))
|
|
52
|
+
return true
|
|
53
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { pullFromCache } from './pullFromCache'
|
|
4
|
+
import { pushToCache } from './pushToCache'
|
|
5
|
+
import { mergeInCache } from './mergeInCache'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ```js
|
|
9
|
+
* import { upsertInCache } from '@amityco/ts-sdk'
|
|
10
|
+
* upsertInCache<Amity.User>(["user", "foobar"], user)
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Insert or update any provided value as {@link Amity.CacheEntry} for
|
|
14
|
+
* the matching {@link Amity.CacheKey}
|
|
15
|
+
*
|
|
16
|
+
* @param key the key to save the object to
|
|
17
|
+
* @param data the object to save
|
|
18
|
+
* @param options customisation object around cache behavior (default gives a 2mn lifespan)
|
|
19
|
+
* @returns a success boolean if the object was saved in cache
|
|
20
|
+
*
|
|
21
|
+
* @category Cache API
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
export const upsertInCache = <T extends {}>(
|
|
25
|
+
key: Amity.CacheKey,
|
|
26
|
+
data: T,
|
|
27
|
+
options: Amity.CacheOptions = { cachedAt: Date.now() },
|
|
28
|
+
): boolean => {
|
|
29
|
+
const { log, cache } = getActiveClient()
|
|
30
|
+
|
|
31
|
+
if (!cache) return false
|
|
32
|
+
log('cache/api/upsertInCache', { key, data, options })
|
|
33
|
+
|
|
34
|
+
const cached = pullFromCache<T>(key)
|
|
35
|
+
|
|
36
|
+
return cached
|
|
37
|
+
? mergeInCache<T>(key, data, options)
|
|
38
|
+
: pushToCache(key, data, options)
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { wipeCache } from '@amityco/ts-sdk'
|
|
8
|
+
* const success = await wipeCache()
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Wipes a persistent storage for the current {@link Amity.Cache} instance.
|
|
12
|
+
*
|
|
13
|
+
* The strategy for persistent storage will depend on the runtime,
|
|
14
|
+
* which is supported by @react-native-async-storage/async-storage.
|
|
15
|
+
*
|
|
16
|
+
* The current userId will be appended to the given storageKey to avoid
|
|
17
|
+
* collision between multiple client instances over time.
|
|
18
|
+
*
|
|
19
|
+
* @param storageKey the name of the persistent storage
|
|
20
|
+
* @returns a success boolean if the persistent cache was wiped.
|
|
21
|
+
*
|
|
22
|
+
* @category Cache API
|
|
23
|
+
*/
|
|
24
|
+
export const wipeCache = async (
|
|
25
|
+
storageKey: string = 'amitySdk'
|
|
26
|
+
) => {
|
|
27
|
+
const { log, cache, userId } = getActiveClient()
|
|
28
|
+
|
|
29
|
+
if (!cache) return false
|
|
30
|
+
log('cache/api/wipeCache', { storageKey })
|
|
31
|
+
|
|
32
|
+
cache.data = {}
|
|
33
|
+
await AsyncStorage.setItem(`${storageKey}#${userId}`, '{}')
|
|
34
|
+
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallow-clones an object and sort its keys
|
|
3
|
+
*
|
|
4
|
+
* @param source a plain object to clone
|
|
5
|
+
* @returns a clone of source, with keys sorted with default javascript sorting
|
|
6
|
+
*
|
|
7
|
+
* @category Cache
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
const normalize = (
|
|
11
|
+
source: Record<string, Amity.Serializable>
|
|
12
|
+
): Record<string, Amity.Serializable> => (
|
|
13
|
+
Object.keys(source)
|
|
14
|
+
.sort()
|
|
15
|
+
.reduce((acc, key) => ({ ...acc, [key]: source[key] }), {})
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
20
|
+
*
|
|
21
|
+
* @param key the key to encode
|
|
22
|
+
* @returns an encoded string
|
|
23
|
+
*
|
|
24
|
+
* @category Cache
|
|
25
|
+
* @hidden
|
|
26
|
+
*/
|
|
27
|
+
export const encodeKey = (key: Amity.CacheKey): string => (
|
|
28
|
+
JSON.stringify(key, (_, val) =>
|
|
29
|
+
typeof val === "object" ? normalize(val) : val
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Decodes a string back into a {@link Amity.CacheKey}
|
|
35
|
+
|
|
36
|
+
*
|
|
37
|
+
* @param key the string key to decode
|
|
38
|
+
* @returns a plain Amity.CacheKey object.
|
|
39
|
+
*
|
|
40
|
+
* @category Cache
|
|
41
|
+
* @hidden
|
|
42
|
+
*/
|
|
43
|
+
export const decodeKey = (key: string): Amity.CacheKey => JSON.parse(key);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Performs a recursive partial deep equal check on two objects.
|
|
48
|
+
*
|
|
49
|
+
* @param predicate the reference object containing the partial information
|
|
50
|
+
* @param candidate the object to check against
|
|
51
|
+
* @returns true if the candidate contains all the values of the predicate
|
|
52
|
+
*
|
|
53
|
+
* @category Cache
|
|
54
|
+
*/
|
|
55
|
+
export const partialMatch = (predicate: any, candidate: any): boolean => {
|
|
56
|
+
if (predicate === candidate) return true;
|
|
57
|
+
|
|
58
|
+
// if one or the other is nullish, there can't be equality
|
|
59
|
+
else if (!predicate || !candidate) return false;
|
|
60
|
+
|
|
61
|
+
// we only perform recursive check on objects
|
|
62
|
+
else if (typeof predicate !== "object") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// recursively call for partial match based on the predicate
|
|
67
|
+
return Object.keys(predicate).every((key) =>
|
|
68
|
+
partialMatch(predicate[key], candidate[key])
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Type guard to check and cast that a given predicate matched {@link Amity.Cached} shape
|
|
74
|
+
*
|
|
75
|
+
* @param obj any {@link Amity.Cached}-like object
|
|
76
|
+
* @returns success boolean if the given object is of {@link Amity.Cached} shape
|
|
77
|
+
*
|
|
78
|
+
* @category Cache
|
|
79
|
+
*/
|
|
80
|
+
export const isCached = <T extends unknown>(
|
|
81
|
+
obj?: any
|
|
82
|
+
): obj is Amity.Cached<T> => (
|
|
83
|
+
['data', 'cachedAt'].every(prop => obj?.hasOwnProperty(prop))
|
|
84
|
+
)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache } from '~/core/cache'
|
|
3
|
+
// import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* ```js
|
|
@@ -27,8 +26,8 @@ export const getCategory = async (
|
|
|
27
26
|
`/api/v3/community-categories/${categoryId}`
|
|
28
27
|
)
|
|
29
28
|
|
|
30
|
-
decoratePayload(data)
|
|
31
|
-
ingestInCache(data)
|
|
29
|
+
// decoratePayload(data)
|
|
30
|
+
// ingestInCache(data)
|
|
32
31
|
|
|
33
32
|
const { categories } = data
|
|
34
33
|
return categories[0]
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache } from '~/
|
|
5
|
-
import { toRecord } from '~/core/model'
|
|
3
|
+
import { toPage, toToken } from '~/core/query'
|
|
4
|
+
// import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* ```js
|
|
@@ -38,12 +37,12 @@ export const queryCategories = async (query?: {
|
|
|
38
37
|
|
|
39
38
|
const { paging, ...response } = data
|
|
40
39
|
|
|
41
|
-
decoratePayload(response as unknown as Record<string, any[]>)
|
|
42
|
-
ingestInCache(response as unknown as Record<string, any[]>)
|
|
40
|
+
// decoratePayload(response as unknown as Record<string, any[]>)
|
|
41
|
+
// ingestInCache(response as unknown as Record<string, any[]>)
|
|
43
42
|
|
|
44
43
|
const prevPage = toPage(paging?.previous)
|
|
45
44
|
const nextPage = toPage(paging?.next)
|
|
46
45
|
|
|
47
46
|
const { categories } = response
|
|
48
|
-
return
|
|
47
|
+
return { data: categories, prevPage, nextPage }
|
|
49
48
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache } from '~/core/cache'
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
4
|
import { fireEvent } from '~/core/events'
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -22,7 +21,7 @@ import { fireEvent } from '~/core/events'
|
|
|
22
21
|
export const addChannelMembers = async (
|
|
23
22
|
channelId: Amity.Channel['channelId'],
|
|
24
23
|
userIds: Amity.User['userId'][]
|
|
25
|
-
) => {
|
|
24
|
+
): Promise<boolean> => {
|
|
26
25
|
const client = getActiveClient()
|
|
27
26
|
client.log('channel/addChannelMembers', channelId, userIds)
|
|
28
27
|
|
|
@@ -31,8 +30,8 @@ export const addChannelMembers = async (
|
|
|
31
30
|
{ channelId, userIds }
|
|
32
31
|
)
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (client.cache) ingestInCache(data)
|
|
34
|
+
|
|
36
35
|
fireEvent('v3.channel.didAddUsers', {
|
|
37
36
|
channels: data.channels!,
|
|
38
37
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache } from '~/core/cache'
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* ```js
|
|
@@ -23,7 +22,7 @@ export const addChannelMembersRole = async (
|
|
|
23
22
|
channelId: Amity.Channel['channelId'],
|
|
24
23
|
roleId: Amity.Role['roleId'],
|
|
25
24
|
userIds: Amity.User['userId'][]
|
|
26
|
-
) => {
|
|
25
|
+
): Promise<boolean> => {
|
|
27
26
|
const client = getActiveClient()
|
|
28
27
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds)
|
|
29
28
|
|
|
@@ -32,8 +31,7 @@ export const addChannelMembersRole = async (
|
|
|
32
31
|
{ channelId, role: roleId, userIds }
|
|
33
32
|
)
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
ingestInCache(data)
|
|
34
|
+
if (client.cache) ingestInCache(data)
|
|
37
35
|
|
|
38
36
|
const { channelUsers } = data
|
|
39
37
|
return !!channelUsers.find(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache } from '~/core/cache'
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* ```js
|
|
@@ -20,18 +19,24 @@ import { ingestInCache } from '~/core/cache'
|
|
|
20
19
|
export const createChannel = async <T extends Amity.ChannelType>(
|
|
21
20
|
bundle: { type: T, userIds?: Amity.User['userId'] }
|
|
22
21
|
& Pick<Amity.Channel<T>, 'displayName' | 'avatarFileId' | 'tags' | 'metadata'>
|
|
23
|
-
) => {
|
|
22
|
+
): Promise<Amity.Cached<Amity.Channel>> => {
|
|
24
23
|
const client = getActiveClient()
|
|
25
24
|
client.log('user/createChannel', bundle)
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
'/api/v3/channels', bundle,
|
|
29
|
-
)
|
|
26
|
+
let payload;
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (bundle?.type === 'conversation') {
|
|
29
|
+
payload = await client.http.post<Amity.ChannelPayload>('/api/v3/channels/conversation', {...bundle, isDistinct: true })
|
|
30
|
+
} else {
|
|
31
|
+
payload = await client.http.post<Amity.ChannelPayload>('/api/v3/channels', bundle)
|
|
32
|
+
}
|
|
34
33
|
|
|
35
|
-
const
|
|
36
|
-
|
|
34
|
+
const cachedAt = client.cache && Date.now()
|
|
35
|
+
if (client.cache) ingestInCache(payload.data, { cachedAt })
|
|
36
|
+
|
|
37
|
+
const { channels } = payload.data
|
|
38
|
+
return {
|
|
39
|
+
data: channels[0],
|
|
40
|
+
cachedAt,
|
|
41
|
+
}
|
|
37
42
|
}
|
|
@@ -18,7 +18,7 @@ import { getChannel } from './getChannel'
|
|
|
18
18
|
*/
|
|
19
19
|
export const deleteChannel = async (
|
|
20
20
|
channelId: Amity.Channel['channelId'],
|
|
21
|
-
) => {
|
|
21
|
+
): Promise<Amity.Channel> => {
|
|
22
22
|
const client = getActiveClient()
|
|
23
23
|
client.log('channel/deleteChannel', channelId)
|
|
24
24
|
|
|
@@ -30,5 +30,5 @@ export const deleteChannel = async (
|
|
|
30
30
|
const deleted = await getChannel(channelId)
|
|
31
31
|
// no need for event, fired by server
|
|
32
32
|
|
|
33
|
-
return deleted
|
|
33
|
+
return deleted.data
|
|
34
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { pullFromCache } from '~/cache/api'
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* ```js
|
|
@@ -19,7 +19,7 @@ import { decoratePayload } from '~/core/query'
|
|
|
19
19
|
*/
|
|
20
20
|
export const getChannel = async (
|
|
21
21
|
channelId: Amity.Channel['channelId'],
|
|
22
|
-
) => {
|
|
22
|
+
): Promise<Amity.Cached<Amity.Channel>> => {
|
|
23
23
|
const client = getActiveClient()
|
|
24
24
|
client.log('channel/getChannel', channelId)
|
|
25
25
|
|
|
@@ -28,11 +28,15 @@ export const getChannel = async (
|
|
|
28
28
|
`/api/v3/channels/${channelId}`,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
ingestInCache(data)
|
|
31
|
+
const cachedAt = client.cache && Date.now()
|
|
32
|
+
if (client.cache) ingestInCache(data, { cachedAt })
|
|
33
33
|
|
|
34
34
|
const { channels } = data
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
data: channels.find(channel => channel.channelId === channelId)!,
|
|
38
|
+
cachedAt,
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/**
|
|
@@ -50,10 +54,19 @@ export const getChannel = async (
|
|
|
50
54
|
*/
|
|
51
55
|
getChannel.locally = (
|
|
52
56
|
channelId: Amity.Channel['channelId'],
|
|
53
|
-
) => {
|
|
57
|
+
): Amity.Cached<Amity.Channel> | undefined => {
|
|
54
58
|
const client = getActiveClient()
|
|
55
59
|
client.log('channel/getChannel.locally', channelId)
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
if (!client.cache) return
|
|
62
|
+
|
|
63
|
+
const cached = pullFromCache<Amity.Channel>(['channel', 'get', channelId])
|
|
64
|
+
|
|
65
|
+
if (!cached)
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
data: cached.data,
|
|
70
|
+
cachedAt: cached.cachedAt,
|
|
71
|
+
}
|
|
59
72
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { ingestInCache
|
|
5
|
-
import { toRecord } from '~/core/model'
|
|
3
|
+
import { pullFromCache } from '~/cache/api'
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* ```js
|
|
@@ -20,7 +19,7 @@ import { toRecord } from '~/core/model'
|
|
|
20
19
|
*/
|
|
21
20
|
export const getChannels = async (
|
|
22
21
|
channelIds: Amity.Channel['channelId'][],
|
|
23
|
-
) => {
|
|
22
|
+
): Promise<Amity.Cached<Amity.Channel[]>> => {
|
|
24
23
|
const client = getActiveClient()
|
|
25
24
|
client.log('channel/getChannels', channelIds)
|
|
26
25
|
|
|
@@ -30,11 +29,13 @@ export const getChannels = async (
|
|
|
30
29
|
{ params: { channelIds } },
|
|
31
30
|
)
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
ingestInCache(data)
|
|
32
|
+
const cachedAt = client.cache && Date.now()
|
|
33
|
+
if (client.cache) ingestInCache(data, { cachedAt })
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return {
|
|
36
|
+
data: data.channels,
|
|
37
|
+
cachedAt
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -52,12 +53,24 @@ export const getChannels = async (
|
|
|
52
53
|
*/
|
|
53
54
|
getChannels.locally = (
|
|
54
55
|
channelIds: Amity.Channel['channelId'][],
|
|
55
|
-
) => {
|
|
56
|
+
): Amity.Cached<Amity.Channel[]> | undefined => {
|
|
56
57
|
const client = getActiveClient()
|
|
57
58
|
client.log('channel/getChannels.locally', channelIds)
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
if (!client.cache) return
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const cached = channelIds
|
|
63
|
+
.map(channelId => pullFromCache<Amity.Channel>(['channel', 'get', channelId])!)
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
|
|
66
|
+
const channels = cached.map(({ data }) => data)
|
|
67
|
+
const oldest = cached.sort((a, b) => a.cachedAt! < b.cachedAt! ? -1 : 1)?.[0]
|
|
68
|
+
|
|
69
|
+
if (cached?.length < channelIds.length)
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
data: channels,
|
|
74
|
+
cachedAt: oldest.cachedAt,
|
|
75
|
+
}
|
|
63
76
|
}
|