@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,75 @@
|
|
|
1
|
+
export {}
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Amity {
|
|
5
|
+
type SkipLimitPagination = {
|
|
6
|
+
skip?: number
|
|
7
|
+
limit?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
WARNING:
|
|
12
|
+
in traditional "before/after" pagination, 'before' and 'after'
|
|
13
|
+
normally should be strings representing the unique id of the
|
|
14
|
+
resource. for some reason, our backend uses a number instead,
|
|
15
|
+
bound to "channelSegment" (for message) and "segmentNumber" (
|
|
16
|
+
for comments). so we have to cast this as number.
|
|
17
|
+
*/
|
|
18
|
+
type AfterBeforePagination = {
|
|
19
|
+
before?: number
|
|
20
|
+
after?: number
|
|
21
|
+
first?: number
|
|
22
|
+
last?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type PrevPage = {
|
|
26
|
+
after?: never
|
|
27
|
+
before?: number
|
|
28
|
+
limit: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type NextPage = {
|
|
32
|
+
after?: number
|
|
33
|
+
before?: never
|
|
34
|
+
limit: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Page = (PrevPage | NextPage)
|
|
38
|
+
|
|
39
|
+
type Pages = {
|
|
40
|
+
nextPage?: Page | null
|
|
41
|
+
prevPage?: Page | null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type Paged<T> = { data: T[] } & Pages
|
|
45
|
+
|
|
46
|
+
type AfterBeforeRawPagination = {
|
|
47
|
+
before?: string
|
|
48
|
+
after?: string
|
|
49
|
+
updatedAt?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type PrevPageRaw = {
|
|
53
|
+
after?: never
|
|
54
|
+
before?: string
|
|
55
|
+
limit: number
|
|
56
|
+
updatedAt?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type NextPageRaw = {
|
|
60
|
+
after?: string
|
|
61
|
+
before?: never
|
|
62
|
+
limit: number
|
|
63
|
+
updatedAt?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type PageRaw = (PrevPageRaw | NextPageRaw)
|
|
67
|
+
|
|
68
|
+
type PagesRaw = {
|
|
69
|
+
nextPage?: PageRaw | null
|
|
70
|
+
prevPage?: PageRaw | null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type PagedRaw<T> = { data: T[] } & PagesRaw
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/@types/core/query.ts
CHANGED
|
@@ -2,14 +2,12 @@ export {}
|
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
syncedAt: number
|
|
5
|
+
type Cachable = {
|
|
6
|
+
cachedAt: number
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
type Local = {
|
|
11
|
-
|
|
12
|
-
syncedAt: -1
|
|
10
|
+
cachedAt: -1
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
type AsyncFunc<Args extends any[], Returned extends any> = {
|
|
@@ -18,12 +16,12 @@ declare global {
|
|
|
18
16
|
|
|
19
17
|
type FetcherFunc<Args extends any[], Returned extends any> = {
|
|
20
18
|
(...args: Args): Promise<Returned>
|
|
21
|
-
locally: (...args: Args) => Returned
|
|
19
|
+
locally: (...args: Args) => Returned | undefined
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
type MutatorFunc<Args extends any[], Returned extends any> = {
|
|
25
23
|
(...args: Args): Promise<Returned>
|
|
26
|
-
optimistically: (...args: Args) => Returned
|
|
24
|
+
optimistically: (...args: Args) => Returned | undefined
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
type OfflineFunc<Args extends any[], Returned extends any> = (
|
|
@@ -41,55 +39,16 @@ declare global {
|
|
|
41
39
|
lifeSpan: number
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
type
|
|
45
|
-
origin
|
|
46
|
-
loading
|
|
47
|
-
error?:
|
|
42
|
+
type SnapshotOptions = {
|
|
43
|
+
origin: 'local' | 'server' | 'event'
|
|
44
|
+
loading: boolean
|
|
45
|
+
error?: any
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
type
|
|
51
|
-
? { data
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
skip?: number
|
|
56
|
-
limit?: number
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
WARNING:
|
|
61
|
-
in traditional "before/after" pagination, 'before' and 'after'
|
|
62
|
-
normally should be strings representing the unique id of the
|
|
63
|
-
resource. for some reason, our backend uses a number instead,
|
|
64
|
-
bound to "channelSegment" (for message) and "segmentNumber" (
|
|
65
|
-
for comments). so we have to cast this as number.
|
|
66
|
-
*/
|
|
67
|
-
type AfterBeforePagination = {
|
|
68
|
-
before?: number
|
|
69
|
-
after?: number
|
|
70
|
-
first?: number
|
|
71
|
-
last?: number
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
type PrevPage = {
|
|
75
|
-
after?: never
|
|
76
|
-
before?: number
|
|
77
|
-
limit: number
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
type NextPage = {
|
|
81
|
-
after?: number
|
|
82
|
-
before?: never
|
|
83
|
-
limit: number
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
type Page = (PrevPage | NextPage)
|
|
87
|
-
|
|
88
|
-
type Pages = {
|
|
89
|
-
nextPage: Page | null
|
|
90
|
-
prevPage: Page | null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
type Paged<T> = { data: T } & Pages
|
|
48
|
+
type Snapshot<T> = (
|
|
49
|
+
T extends Amity.Cached<infer K> ? { data: K } :
|
|
50
|
+
T extends (Amity.PagedRaw<any> | Amity.Paged<any>) ? T :
|
|
51
|
+
{ data: T }
|
|
52
|
+
) & SnapshotOptions
|
|
94
53
|
}
|
|
95
54
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ASCError } from '~/core/errors'
|
|
2
|
+
|
|
1
3
|
export {}
|
|
2
4
|
|
|
3
5
|
declare global {
|
|
@@ -37,8 +39,8 @@ declare global {
|
|
|
37
39
|
once: <T extends keyof Amity.MqttEvents>(event: T, handler: (payload: Amity.MqttEvents[T]) => void) => void
|
|
38
40
|
off: <T extends keyof Amity.MqttEvents>(event: T, handler?: (payload: Amity.MqttEvents[T]) => void) => void
|
|
39
41
|
removeAllListeners: () => void
|
|
40
|
-
subscribe: (topic: string,
|
|
41
|
-
unsubscribe: (topic: string
|
|
42
|
+
subscribe: (topic: string, callback?: Amity.Listener<ASCError | void>) => Amity.Unsubscriber
|
|
43
|
+
unsubscribe: (topic: string) => void
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -4,30 +4,32 @@ declare global {
|
|
|
4
4
|
namespace Amity {
|
|
5
5
|
type ContentType = ('text' | 'image' | 'file' | 'video' | 'json' | string)
|
|
6
6
|
|
|
7
|
-
type ContentDataText = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type ContentDataText = {
|
|
8
|
+
text: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ContentDataFile = {
|
|
12
|
+
fileId: Amity.File<'file'>['fileId']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ContentDataImage = {
|
|
16
|
+
imageId: Amity.File<'image'>['fileId']
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ContentDataVideo = {
|
|
20
|
+
videoId: Amity.File<'file'>['fileId']
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
type ContentData<T extends ContentType> = (
|
|
13
24
|
T extends 'text' ? ContentDataText :
|
|
14
25
|
T extends 'file' ? ContentDataFile :
|
|
15
26
|
T extends 'image' ? ContentDataImage :
|
|
16
27
|
T extends 'video' ? ContentDataVideo :
|
|
17
|
-
T extends 'json' ?
|
|
18
|
-
T extends string ?
|
|
28
|
+
T extends 'json' ? Record<string, unknown> :
|
|
29
|
+
T extends string ? string | Record<string, unknown> : // custom type
|
|
19
30
|
never
|
|
20
31
|
)
|
|
21
32
|
|
|
22
|
-
type ContentTypeFor<T> = (
|
|
23
|
-
T extends ContentDataText ? 'text' :
|
|
24
|
-
T extends ContentDataFile ? 'file' :
|
|
25
|
-
T extends ContentDataImage ? 'image' :
|
|
26
|
-
T extends ContentDataVideo ? 'video' :
|
|
27
|
-
T extends object ? 'json' :
|
|
28
|
-
'custom'
|
|
29
|
-
)
|
|
30
|
-
|
|
31
33
|
type Content<T extends ContentType, K extends 'type' | 'dataType' = 'dataType'> = (
|
|
32
34
|
{ [S in K]?: T } & { data: ContentData<T> }
|
|
33
35
|
)
|
|
@@ -13,12 +13,12 @@ declare global {
|
|
|
13
13
|
} & (
|
|
14
14
|
T extends 'channel' ? {
|
|
15
15
|
channelId: Amity.Channel['channelId']
|
|
16
|
-
membership: 'member' | '
|
|
16
|
+
membership: 'member' | 'none' | 'banned'
|
|
17
17
|
readToSegment: number
|
|
18
18
|
} :
|
|
19
19
|
T extends 'community' ? {
|
|
20
20
|
communityId: Amity.Community['communityId']
|
|
21
|
-
communityMembership: 'member' | '
|
|
21
|
+
communityMembership: 'member' | 'none' | 'banned'
|
|
22
22
|
} :
|
|
23
23
|
never
|
|
24
24
|
)
|
|
@@ -33,6 +33,5 @@ declare global {
|
|
|
33
33
|
}
|
|
34
34
|
& Member<T>
|
|
35
35
|
& Amity.Accredited
|
|
36
|
-
& Amity.Syncable
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -20,13 +20,13 @@ declare global {
|
|
|
20
20
|
hasFlaggedChildren: false
|
|
21
21
|
hasFlaggedComment: false
|
|
22
22
|
editedAt: timestamp,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
}
|
|
24
|
+
& Amity.Content<T, 'dataType'>
|
|
25
|
+
& Amity.Metadata
|
|
26
|
+
& Amity.Flaggable
|
|
27
|
+
& Amity.Reactable
|
|
28
|
+
& Amity.Timestamps
|
|
29
|
+
& Amity.SoftDelete
|
|
30
|
+
& Amity.Subscribable
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -3,6 +3,7 @@ export {}
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
5
|
type User = {
|
|
6
|
+
_id: string
|
|
6
7
|
userId: string
|
|
7
8
|
displayName?: string
|
|
8
9
|
avatarFileId?: Amity.File<'image'>['fileId']
|
|
@@ -13,7 +14,6 @@ declare global {
|
|
|
13
14
|
& Amity.Flaggable
|
|
14
15
|
& Amity.Accredited
|
|
15
16
|
& Amity.Timestamps
|
|
16
|
-
& Amity.Syncable
|
|
17
17
|
& Amity.Subscribable
|
|
18
18
|
}
|
|
19
19
|
}
|
package/src/@types/index.ts
CHANGED
|
@@ -5,8 +5,8 @@ import './core/permissions' // permissions enum
|
|
|
5
5
|
|
|
6
6
|
import './core/payload' // backend payload definition
|
|
7
7
|
import './core/events' // sdk events definitions
|
|
8
|
+
import './core/paging' // createQuery, runQuery
|
|
8
9
|
import './core/query' // createQuery, runQuery
|
|
9
|
-
import './core/store' // store definition
|
|
10
10
|
import './core/cache' // cache.pull('user', ...)
|
|
11
11
|
|
|
12
12
|
// domains
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { backupCache } from '@amityco/ts-sdk'
|
|
8
|
+
* const success = await backupCache()
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Writes the {@link Amity.Cache} to a persistent storage.
|
|
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
|
+
* @param persistIf a custom function to define the persistence policy. Default
|
|
21
|
+
* will check the value of {@link Amity.CacheEntry["offline"]}, which can be
|
|
22
|
+
* defined globally when customizing {@link Amity.Cache["persistIf"]}
|
|
23
|
+
* @returns a success boolean if the cache was dumped to persistent storage
|
|
24
|
+
*
|
|
25
|
+
* @category Cache API
|
|
26
|
+
*/
|
|
27
|
+
export const backupCache = async (
|
|
28
|
+
storageKey: string = 'amitySdk',
|
|
29
|
+
persistIf = (entry: Amity.CacheEntry) => entry.offline,
|
|
30
|
+
) => {
|
|
31
|
+
const { log, cache, userId } = getActiveClient()
|
|
32
|
+
|
|
33
|
+
if (!cache) return false
|
|
34
|
+
log('cache/api/backupCache', { storageKey })
|
|
35
|
+
|
|
36
|
+
// prepare a subset of the cache where only
|
|
37
|
+
// objects to backup are there
|
|
38
|
+
const offlineEntries = Object.fromEntries(
|
|
39
|
+
Object.entries(cache.data)
|
|
40
|
+
.filter(([_, entry]) => persistIf(entry))
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
// nothing to backup, abort
|
|
44
|
+
if (!Object.keys(offlineEntries).length)
|
|
45
|
+
return false
|
|
46
|
+
|
|
47
|
+
await AsyncStorage.setItem(
|
|
48
|
+
`${storageKey}#${userId}`,
|
|
49
|
+
JSON.stringify(offlineEntries),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { disableCache } from '@amityco/ts-sdk'
|
|
6
|
+
* disableCache()
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Wipes the existing {@link Amity.Cache} object attached to
|
|
10
|
+
* an {@link Amity.Client} instance
|
|
11
|
+
*
|
|
12
|
+
* @category Cache API
|
|
13
|
+
*/
|
|
14
|
+
export const disableCache = () => {
|
|
15
|
+
const client = getActiveClient()
|
|
16
|
+
|
|
17
|
+
if (!client.cache) return
|
|
18
|
+
client.log('cache/api/disableCache')
|
|
19
|
+
|
|
20
|
+
// we do this so that testing if cache is enabled
|
|
21
|
+
// is only `if (client.cache)
|
|
22
|
+
delete client.cache
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
import { decodeKey, encodeKey, partialMatch } from '../utils'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ```js
|
|
6
|
+
* import { dropFromCache } from '@amityco/ts-sdk'
|
|
7
|
+
* const success = dropFromCache(['user', 'foobar'])
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Removes an existing {@link Amity.CacheEntry} from the {@link Amity.Client}'s
|
|
11
|
+
* {@link Amity.Cache} from a given {@link Amity.CacheKey}
|
|
12
|
+
*
|
|
13
|
+
* @param key The key of the object to delete
|
|
14
|
+
* @param exact If false, the function will delete all keys satisfying the given key
|
|
15
|
+
* @returns A success boolean if the object was deleted
|
|
16
|
+
*
|
|
17
|
+
* @category Cache API
|
|
18
|
+
*/
|
|
19
|
+
export const dropFromCache = (
|
|
20
|
+
key: Amity.CacheKey,
|
|
21
|
+
exact: boolean = false,
|
|
22
|
+
): boolean => {
|
|
23
|
+
const { log, cache } = getActiveClient()
|
|
24
|
+
|
|
25
|
+
if (!cache) return false
|
|
26
|
+
log('cache/api/dropFromCache', { key, exact })
|
|
27
|
+
|
|
28
|
+
if (!exact) {
|
|
29
|
+
return (Object.keys(cache.data))
|
|
30
|
+
.map(stringKey => decodeKey(stringKey))
|
|
31
|
+
.filter(candidate => partialMatch(key, candidate))
|
|
32
|
+
.map<boolean>(filteredKey => dropFromCache(filteredKey, true))
|
|
33
|
+
.every(returned => returned)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const encodedKey = encodeKey(key)
|
|
37
|
+
|
|
38
|
+
if (encodedKey in cache.data) {
|
|
39
|
+
delete cache.data[encodedKey]
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { enableCache } from '@amityco/ts-sdk'
|
|
6
|
+
* enableCache()
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Adds a new {@link Amity.Cache} object to
|
|
10
|
+
* an {@link Amity.Client} instance
|
|
11
|
+
*
|
|
12
|
+
* @param prevState a previous state of cache instance (useful for SSR)
|
|
13
|
+
* @param persistIf a function to determine if an entry inserted in cache
|
|
14
|
+
* is destined to be also saved in the persistent storage when
|
|
15
|
+
* calling {@link backupCache}
|
|
16
|
+
*
|
|
17
|
+
* @category Cache API
|
|
18
|
+
*/
|
|
19
|
+
export const enableCache = (
|
|
20
|
+
prevState: Amity.Cache['data'] = {},
|
|
21
|
+
persistIf?: Amity.Cache['persistIf'],
|
|
22
|
+
) => {
|
|
23
|
+
const client = getActiveClient()
|
|
24
|
+
|
|
25
|
+
if (client.cache) return
|
|
26
|
+
client.log('cache/api/enableCache')
|
|
27
|
+
|
|
28
|
+
client.cache = { data: prevState, persistIf }
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// on/off
|
|
2
|
+
export * from './enableCache'
|
|
3
|
+
export * from './disableCache'
|
|
4
|
+
|
|
5
|
+
// persistency
|
|
6
|
+
export * from './restoreCache'
|
|
7
|
+
export * from './backupCache'
|
|
8
|
+
export * from './wipeCache'
|
|
9
|
+
|
|
10
|
+
// fetch
|
|
11
|
+
export * from './queryCache'
|
|
12
|
+
export * from './pullFromCache'
|
|
13
|
+
|
|
14
|
+
// mutate
|
|
15
|
+
export * from './pushToCache'
|
|
16
|
+
export * from './mergeInCache'
|
|
17
|
+
export * from './upsertInCache'
|
|
18
|
+
export * from './dropFromCache'
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* ingestInCache and syncInCache are not exported ;
|
|
22
|
+
* we don't want it as part of the sdk's public api.
|
|
23
|
+
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PAYLOAD2MODEL, getResolver } from '~/core/model'
|
|
2
|
+
|
|
3
|
+
import { upsertInCache } from './upsertInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ingest a payload (v3) into the cache
|
|
7
|
+
*
|
|
8
|
+
* @param payload a "backend v3" payload object
|
|
9
|
+
* @param order the order of the keys to process (in case of need)
|
|
10
|
+
*
|
|
11
|
+
* @category Cache
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
export const ingestInCache = (
|
|
15
|
+
payload: Record<string, Record<string, unknown>[]> = {},
|
|
16
|
+
options?: Amity.CacheOptions,
|
|
17
|
+
) => {
|
|
18
|
+
Object.entries(payload)
|
|
19
|
+
.forEach(([key, models]) => {
|
|
20
|
+
const type = PAYLOAD2MODEL[key];
|
|
21
|
+
if (!type) return
|
|
22
|
+
|
|
23
|
+
const resolver = getResolver(type);
|
|
24
|
+
models.forEach(model => {
|
|
25
|
+
upsertInCache(
|
|
26
|
+
// eslint-disable @typescript-eslint no-explicit-any
|
|
27
|
+
[type, 'get', resolver(model as any)], // this 'any' cannot be avoided, sorry.
|
|
28
|
+
model,
|
|
29
|
+
options,
|
|
30
|
+
);
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient'
|
|
2
|
+
|
|
3
|
+
import { pullFromCache } from './pullFromCache'
|
|
4
|
+
import { pushToCache } from './pushToCache'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { mergeInCache } from '@amityco/ts-sdk'
|
|
9
|
+
*
|
|
10
|
+
* mergeInCache(
|
|
11
|
+
* ["foo", "bar"],
|
|
12
|
+
* (oldVal) => ({ ...oldVal, ...newVal }).
|
|
13
|
+
* )
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Merges a new {@link Amity.Cache} object to an {@link Amity.Client} instance
|
|
17
|
+
*
|
|
18
|
+
* @param key the key matching the object to retrieve from cache
|
|
19
|
+
* @param mutation either a plain object to shallow merge, or a function.
|
|
20
|
+
* @returns a success boolean if the object was updated
|
|
21
|
+
*
|
|
22
|
+
* @category Cache API
|
|
23
|
+
*/
|
|
24
|
+
export const mergeInCache = <T extends {}>(
|
|
25
|
+
key: Amity.CacheKey,
|
|
26
|
+
mutation: Partial<T> | ((oldVal: T) => T),
|
|
27
|
+
options?: Amity.CacheOptions,
|
|
28
|
+
): boolean => {
|
|
29
|
+
const { log, cache } = getActiveClient()
|
|
30
|
+
|
|
31
|
+
if (!cache) return false
|
|
32
|
+
log('cache/api/mergeInCache', { key, mutation })
|
|
33
|
+
|
|
34
|
+
const oldVal = pullFromCache<T>(key);
|
|
35
|
+
|
|
36
|
+
if (!oldVal)
|
|
37
|
+
return false;
|
|
38
|
+
|
|
39
|
+
const newVal = typeof mutation === 'function'
|
|
40
|
+
? mutation(oldVal.data)
|
|
41
|
+
: { ...oldVal.data, ...mutation };
|
|
42
|
+
|
|
43
|
+
pushToCache(key, newVal, options);
|
|
44
|
+
return true;
|
|
45
|
+
};
|