@amityco/ts-sdk 0.0.1-02f0fa3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +390 -0
- package/README.md +137 -0
- package/dist/@types/core/cache.d.ts +21 -0
- package/dist/@types/core/cache.d.ts.map +1 -0
- package/dist/@types/core/errors.d.ts +32 -0
- package/dist/@types/core/errors.d.ts.map +1 -0
- package/dist/@types/core/events.d.ts +46 -0
- package/dist/@types/core/events.d.ts.map +1 -0
- package/dist/@types/core/model.d.ts +41 -0
- package/dist/@types/core/model.d.ts.map +1 -0
- package/dist/@types/core/payload.d.ts +88 -0
- package/dist/@types/core/payload.d.ts.map +1 -0
- package/dist/@types/core/permissions.d.ts +71 -0
- package/dist/@types/core/permissions.d.ts.map +1 -0
- package/dist/@types/core/query.d.ts +72 -0
- package/dist/@types/core/query.d.ts.map +1 -0
- package/dist/@types/core/store.d.ts +46 -0
- package/dist/@types/core/store.d.ts.map +1 -0
- package/dist/@types/core/transport.d.ts +27 -0
- package/dist/@types/core/transport.d.ts.map +1 -0
- package/dist/@types/domains/category.d.ts +11 -0
- package/dist/@types/domains/category.d.ts.map +1 -0
- package/dist/@types/domains/channel.d.ts +26 -0
- package/dist/@types/domains/channel.d.ts.map +1 -0
- package/dist/@types/domains/client.d.ts +31 -0
- package/dist/@types/domains/client.d.ts.map +1 -0
- package/dist/@types/domains/comment.d.ts +17 -0
- package/dist/@types/domains/comment.d.ts.map +1 -0
- package/dist/@types/domains/community.d.ts +24 -0
- package/dist/@types/domains/community.d.ts.map +1 -0
- package/dist/@types/domains/content.d.ts +26 -0
- package/dist/@types/domains/content.d.ts.map +1 -0
- package/dist/@types/domains/feed.d.ts +14 -0
- package/dist/@types/domains/feed.d.ts.map +1 -0
- package/dist/@types/domains/file.d.ts +29 -0
- package/dist/@types/domains/file.d.ts.map +1 -0
- package/dist/@types/domains/group.d.ts +26 -0
- package/dist/@types/domains/group.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +16 -0
- package/dist/@types/domains/message.d.ts.map +1 -0
- package/dist/@types/domains/partials.d.ts +42 -0
- package/dist/@types/domains/partials.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +22 -0
- package/dist/@types/domains/post.d.ts.map +1 -0
- package/dist/@types/domains/reaction.d.ts +24 -0
- package/dist/@types/domains/reaction.d.ts.map +1 -0
- package/dist/@types/domains/stream.d.ts +47 -0
- package/dist/@types/domains/stream.d.ts.map +1 -0
- package/dist/@types/domains/user.d.ts +12 -0
- package/dist/@types/domains/user.d.ts.map +1 -0
- package/dist/@types/global.d.ts +13 -0
- package/dist/@types/global.d.ts.map +1 -0
- package/dist/@types/index.d.ts +23 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/category/api/getCategory.d.ts +16 -0
- package/dist/category/api/getCategory.d.ts.map +1 -0
- package/dist/category/api/index.d.ts +3 -0
- package/dist/category/api/index.d.ts.map +1 -0
- package/dist/category/api/queryCategories.d.ts +23 -0
- package/dist/category/api/queryCategories.d.ts.map +1 -0
- package/dist/channel/api/addChannelMembers.d.ts +17 -0
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/addChannelMembersRole.d.ts +18 -0
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -0
- package/dist/channel/api/createChannel.d.ts +19 -0
- package/dist/channel/api/createChannel.d.ts.map +1 -0
- package/dist/channel/api/deleteChannel.d.ts +16 -0
- package/dist/channel/api/deleteChannel.d.ts.map +1 -0
- package/dist/channel/api/getChannel.d.ts +32 -0
- package/dist/channel/api/getChannel.d.ts.map +1 -0
- package/dist/channel/api/getChannels.d.ts +32 -0
- package/dist/channel/api/getChannels.d.ts.map +1 -0
- package/dist/channel/api/index.d.ts +14 -0
- package/dist/channel/api/index.d.ts.map +1 -0
- package/dist/channel/api/joinChannel.d.ts +16 -0
- package/dist/channel/api/joinChannel.d.ts.map +1 -0
- package/dist/channel/api/leaveChannel.d.ts +16 -0
- package/dist/channel/api/leaveChannel.d.ts.map +1 -0
- package/dist/channel/api/queryChannelMembers.d.ts +42 -0
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/queryChannels.d.ts +43 -0
- package/dist/channel/api/queryChannels.d.ts.map +1 -0
- package/dist/channel/api/removeChannelMembers.d.ts +17 -0
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/removeChannelMembersRole.d.ts +18 -0
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -0
- package/dist/channel/api/updateChannel.d.ts +17 -0
- package/dist/channel/api/updateChannel.d.ts.map +1 -0
- package/dist/channel/events/index.d.ts +7 -0
- package/dist/channel/events/index.d.ts.map +1 -0
- package/dist/channel/events/onChannelCreated.d.ts +17 -0
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -0
- package/dist/channel/events/onChannelDeleted.d.ts +17 -0
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -0
- package/dist/channel/events/onChannelJoined.d.ts +17 -0
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -0
- package/dist/channel/events/onChannelLeft.d.ts +17 -0
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -0
- package/dist/channel/events/onChannelUpdated.d.ts +17 -0
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -0
- package/dist/channel/events/onMemberAdded.d.ts +17 -0
- package/dist/channel/events/onMemberAdded.d.ts.map +1 -0
- package/dist/channel/events/onMemberRemoved.d.ts +17 -0
- package/dist/channel/events/onMemberRemoved.d.ts.map +1 -0
- package/dist/channel/observers/index.d.ts +2 -0
- package/dist/channel/observers/index.d.ts.map +1 -0
- package/dist/channel/observers/observeChannel.d.ts +20 -0
- package/dist/channel/observers/observeChannel.d.ts.map +1 -0
- package/dist/client/api/activeClient.d.ts +17 -0
- package/dist/client/api/activeClient.d.ts.map +1 -0
- package/dist/client/api/clearCache.d.ts +15 -0
- package/dist/client/api/clearCache.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +26 -0
- package/dist/client/api/connectClient.d.ts.map +1 -0
- package/dist/client/api/createClient.d.ts +17 -0
- package/dist/client/api/createClient.d.ts.map +1 -0
- package/dist/client/api/disconnectClient.d.ts +16 -0
- package/dist/client/api/disconnectClient.d.ts.map +1 -0
- package/dist/client/api/enableCache.d.ts +15 -0
- package/dist/client/api/enableCache.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +19 -0
- package/dist/client/api/getToken.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +8 -0
- package/dist/client/api/index.d.ts.map +1 -0
- package/dist/client/api/isConnected.d.ts +14 -0
- package/dist/client/api/isConnected.d.ts.map +1 -0
- package/dist/client/events/index.d.ts +2 -0
- package/dist/client/events/index.d.ts.map +1 -0
- package/dist/client/events/onClientDisconnected.d.ts +17 -0
- package/dist/client/events/onClientDisconnected.d.ts.map +1 -0
- package/dist/comment/api/createComment.d.ts +16 -0
- package/dist/comment/api/createComment.d.ts.map +1 -0
- package/dist/comment/api/deleteComment.d.ts +16 -0
- package/dist/comment/api/deleteComment.d.ts.map +1 -0
- package/dist/comment/api/getComment.d.ts +32 -0
- package/dist/comment/api/getComment.d.ts.map +1 -0
- package/dist/comment/api/getComments.d.ts +32 -0
- package/dist/comment/api/getComments.d.ts.map +1 -0
- package/dist/comment/api/index.d.ts +7 -0
- package/dist/comment/api/index.d.ts.map +1 -0
- package/dist/comment/api/queryComments.d.ts +53 -0
- package/dist/comment/api/queryComments.d.ts.map +1 -0
- package/dist/comment/api/updateComment.d.ts +19 -0
- package/dist/comment/api/updateComment.d.ts.map +1 -0
- package/dist/comment/events/index.d.ts +4 -0
- package/dist/comment/events/index.d.ts.map +1 -0
- package/dist/comment/events/onCommentCreated.d.ts +17 -0
- package/dist/comment/events/onCommentCreated.d.ts.map +1 -0
- package/dist/comment/events/onCommentDeleted.d.ts +17 -0
- package/dist/comment/events/onCommentDeleted.d.ts.map +1 -0
- package/dist/comment/events/onCommentUpdated.d.ts +17 -0
- package/dist/comment/events/onCommentUpdated.d.ts.map +1 -0
- package/dist/comment/observers/index.d.ts +3 -0
- package/dist/comment/observers/index.d.ts.map +1 -0
- package/dist/comment/observers/observeComment.d.ts +20 -0
- package/dist/comment/observers/observeComment.d.ts.map +1 -0
- package/dist/comment/observers/observeComments.d.ts +22 -0
- package/dist/comment/observers/observeComments.d.ts.map +1 -0
- package/dist/community/api/addCommunityMembers.d.ts +17 -0
- package/dist/community/api/addCommunityMembers.d.ts.map +1 -0
- package/dist/community/api/addCommunityMembersRole.d.ts +18 -0
- package/dist/community/api/addCommunityMembersRole.d.ts.map +1 -0
- package/dist/community/api/createCommunity.d.ts +20 -0
- package/dist/community/api/createCommunity.d.ts.map +1 -0
- package/dist/community/api/deleteCommunity.d.ts +16 -0
- package/dist/community/api/deleteCommunity.d.ts.map +1 -0
- package/dist/community/api/getCommunities.d.ts +32 -0
- package/dist/community/api/getCommunities.d.ts.map +1 -0
- package/dist/community/api/getCommunity.d.ts +32 -0
- package/dist/community/api/getCommunity.d.ts.map +1 -0
- package/dist/community/api/index.d.ts +14 -0
- package/dist/community/api/index.d.ts.map +1 -0
- package/dist/community/api/joinCommunity.d.ts +16 -0
- package/dist/community/api/joinCommunity.d.ts.map +1 -0
- package/dist/community/api/leaveCommunity.d.ts +16 -0
- package/dist/community/api/leaveCommunity.d.ts.map +1 -0
- package/dist/community/api/queryCommunities.d.ts +46 -0
- package/dist/community/api/queryCommunities.d.ts.map +1 -0
- package/dist/community/api/queryCommunityMembers.d.ts +42 -0
- package/dist/community/api/queryCommunityMembers.d.ts.map +1 -0
- package/dist/community/api/removeCommunityMembers.d.ts +17 -0
- package/dist/community/api/removeCommunityMembers.d.ts.map +1 -0
- package/dist/community/api/removeCommunityMembersRole.d.ts +18 -0
- package/dist/community/api/removeCommunityMembersRole.d.ts.map +1 -0
- package/dist/community/api/updateCommunity.d.ts +17 -0
- package/dist/community/api/updateCommunity.d.ts.map +1 -0
- package/dist/community/events/index.d.ts +6 -0
- package/dist/community/events/index.d.ts.map +1 -0
- package/dist/community/events/onCommunityCreated.d.ts +17 -0
- package/dist/community/events/onCommunityCreated.d.ts.map +1 -0
- package/dist/community/events/onCommunityDeleted.d.ts +17 -0
- package/dist/community/events/onCommunityDeleted.d.ts.map +1 -0
- package/dist/community/events/onCommunityJoined.d.ts +17 -0
- package/dist/community/events/onCommunityJoined.d.ts.map +1 -0
- package/dist/community/events/onCommunityLeft.d.ts +17 -0
- package/dist/community/events/onCommunityLeft.d.ts.map +1 -0
- package/dist/community/events/onCommunityUpdated.d.ts +17 -0
- package/dist/community/events/onCommunityUpdated.d.ts.map +1 -0
- package/dist/community/observers/index.d.ts +2 -0
- package/dist/community/observers/index.d.ts.map +1 -0
- package/dist/community/observers/observeCommunity.d.ts +20 -0
- package/dist/community/observers/observeCommunity.d.ts.map +1 -0
- package/dist/core/cache/drop.d.ts +11 -0
- package/dist/core/cache/drop.d.ts.map +1 -0
- package/dist/core/cache/index.d.ts +19 -0
- package/dist/core/cache/index.d.ts.map +1 -0
- package/dist/core/cache/ingest.d.ts +10 -0
- package/dist/core/cache/ingest.d.ts.map +1 -0
- package/dist/core/cache/merge.d.ts +10 -0
- package/dist/core/cache/merge.d.ts.map +1 -0
- package/dist/core/cache/mutate.d.ts +10 -0
- package/dist/core/cache/mutate.d.ts.map +1 -0
- package/dist/core/cache/pull.d.ts +11 -0
- package/dist/core/cache/pull.d.ts.map +1 -0
- package/dist/core/cache/push.d.ts +10 -0
- package/dist/core/cache/push.d.ts.map +1 -0
- package/dist/core/cache/sync.d.ts +10 -0
- package/dist/core/cache/sync.d.ts.map +1 -0
- package/dist/core/debug.d.ts +15 -0
- package/dist/core/debug.d.ts.map +1 -0
- package/dist/core/device.d.ts +7 -0
- package/dist/core/device.d.ts.map +1 -0
- package/dist/core/errors.d.ts +59 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/events.d.ts +33 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/model/idResolvers.d.ts +20 -0
- package/dist/core/model/idResolvers.d.ts.map +1 -0
- package/dist/core/model/identifyModel.d.ts +8 -0
- package/dist/core/model/identifyModel.d.ts.map +1 -0
- package/dist/core/model/index.d.ts +4 -0
- package/dist/core/model/index.d.ts.map +1 -0
- package/dist/core/model/toRecord.d.ts +10 -0
- package/dist/core/model/toRecord.d.ts.map +1 -0
- package/dist/core/query/decorate.d.ts +23 -0
- package/dist/core/query/decorate.d.ts.map +1 -0
- package/dist/core/query/filtering.d.ts +12 -0
- package/dist/core/query/filtering.d.ts.map +1 -0
- package/dist/core/query/index.d.ts +6 -0
- package/dist/core/query/index.d.ts.map +1 -0
- package/dist/core/query/paging.d.ts +58 -0
- package/dist/core/query/paging.d.ts.map +1 -0
- package/dist/core/query/query.d.ts +121 -0
- package/dist/core/query/query.d.ts.map +1 -0
- package/dist/core/query/sorting.d.ts +39 -0
- package/dist/core/query/sorting.d.ts.map +1 -0
- package/dist/core/stores/index.d.ts +3 -0
- package/dist/core/stores/index.d.ts.map +1 -0
- package/dist/core/stores/memory.d.ts +30 -0
- package/dist/core/stores/memory.d.ts.map +1 -0
- package/dist/core/stores/persistent.d.ts +13 -0
- package/dist/core/stores/persistent.d.ts.map +1 -0
- package/dist/core/transports.d.ts +49 -0
- package/dist/core/transports.d.ts.map +1 -0
- package/dist/core/uuid.d.ts +2 -0
- package/dist/core/uuid.d.ts.map +1 -0
- package/dist/feed/api/index.d.ts +2 -0
- package/dist/feed/api/index.d.ts.map +1 -0
- package/dist/feed/api/queryGlobalFeed.d.ts +23 -0
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -0
- package/dist/file/api/createFile.d.ts +16 -0
- package/dist/file/api/createFile.d.ts.map +1 -0
- package/dist/file/api/deleteFile.d.ts +16 -0
- package/dist/file/api/deleteFile.d.ts.map +1 -0
- package/dist/file/api/fileUrlWithSize.d.ts +9 -0
- package/dist/file/api/fileUrlWithSize.d.ts.map +1 -0
- package/dist/file/api/getFile.d.ts +32 -0
- package/dist/file/api/getFile.d.ts.map +1 -0
- package/dist/file/api/index.d.ts +5 -0
- package/dist/file/api/index.d.ts.map +1 -0
- package/dist/file/observers/index.d.ts +2 -0
- package/dist/file/observers/index.d.ts.map +1 -0
- package/dist/file/observers/observeFile.d.ts +20 -0
- package/dist/file/observers/observeFile.d.ts.map +1 -0
- package/dist/index.cjs.js +4884 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +4734 -0
- package/dist/index.umd.js +4880 -0
- package/dist/message/api/createMessage.d.ts +38 -0
- package/dist/message/api/createMessage.d.ts.map +1 -0
- package/dist/message/api/deleteMessage.d.ts +32 -0
- package/dist/message/api/deleteMessage.d.ts.map +1 -0
- package/dist/message/api/getMessage.d.ts +32 -0
- package/dist/message/api/getMessage.d.ts.map +1 -0
- package/dist/message/api/getMessages.d.ts +32 -0
- package/dist/message/api/getMessages.d.ts.map +1 -0
- package/dist/message/api/index.d.ts +7 -0
- package/dist/message/api/index.d.ts.map +1 -0
- package/dist/message/api/queryMessages.d.ts +55 -0
- package/dist/message/api/queryMessages.d.ts.map +1 -0
- package/dist/message/api/updateMessage.d.ts +38 -0
- package/dist/message/api/updateMessage.d.ts.map +1 -0
- package/dist/message/events/index.d.ts +4 -0
- package/dist/message/events/index.d.ts.map +1 -0
- package/dist/message/events/onMessageCreated.d.ts +17 -0
- package/dist/message/events/onMessageCreated.d.ts.map +1 -0
- package/dist/message/events/onMessageDeleted.d.ts +17 -0
- package/dist/message/events/onMessageDeleted.d.ts.map +1 -0
- package/dist/message/events/onMessageUpdated.d.ts +17 -0
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -0
- package/dist/message/observers/index.d.ts +3 -0
- package/dist/message/observers/index.d.ts.map +1 -0
- package/dist/message/observers/observeMessage.d.ts +22 -0
- package/dist/message/observers/observeMessage.d.ts.map +1 -0
- package/dist/message/observers/observeMessages.d.ts +19 -0
- package/dist/message/observers/observeMessages.d.ts.map +1 -0
- package/dist/post/api/createPost.d.ts +21 -0
- package/dist/post/api/createPost.d.ts.map +1 -0
- package/dist/post/api/deletePost.d.ts +16 -0
- package/dist/post/api/deletePost.d.ts.map +1 -0
- package/dist/post/api/getPost.d.ts +32 -0
- package/dist/post/api/getPost.d.ts.map +1 -0
- package/dist/post/api/getPosts.d.ts +32 -0
- package/dist/post/api/getPosts.d.ts.map +1 -0
- package/dist/post/api/index.d.ts +7 -0
- package/dist/post/api/index.d.ts.map +1 -0
- package/dist/post/api/queryPosts.d.ts +45 -0
- package/dist/post/api/queryPosts.d.ts.map +1 -0
- package/dist/post/api/updatePost.d.ts +19 -0
- package/dist/post/api/updatePost.d.ts.map +1 -0
- package/dist/post/events/index.d.ts +4 -0
- package/dist/post/events/index.d.ts.map +1 -0
- package/dist/post/events/onPostCreated.d.ts +17 -0
- package/dist/post/events/onPostCreated.d.ts.map +1 -0
- package/dist/post/events/onPostDeleted.d.ts +17 -0
- package/dist/post/events/onPostDeleted.d.ts.map +1 -0
- package/dist/post/events/onPostUpdated.d.ts +17 -0
- package/dist/post/events/onPostUpdated.d.ts.map +1 -0
- package/dist/post/observers/index.d.ts +3 -0
- package/dist/post/observers/index.d.ts.map +1 -0
- package/dist/post/observers/observePost.d.ts +20 -0
- package/dist/post/observers/observePost.d.ts.map +1 -0
- package/dist/post/observers/observePosts.d.ts +25 -0
- package/dist/post/observers/observePosts.d.ts.map +1 -0
- package/dist/reaction/api/addReaction.d.ts +36 -0
- package/dist/reaction/api/addReaction.d.ts.map +1 -0
- package/dist/reaction/api/index.d.ts +3 -0
- package/dist/reaction/api/index.d.ts.map +1 -0
- package/dist/reaction/api/removeReaction.d.ts +36 -0
- package/dist/reaction/api/removeReaction.d.ts.map +1 -0
- package/dist/reaction/events/index.d.ts +2 -0
- package/dist/reaction/events/index.d.ts.map +1 -0
- package/dist/reaction/events/onReactionAdded.d.ts +17 -0
- package/dist/reaction/events/onReactionAdded.d.ts.map +1 -0
- package/dist/reaction/events/onReactionRemoved.d.ts +17 -0
- package/dist/reaction/events/onReactionRemoved.d.ts.map +1 -0
- package/dist/reaction/utils/dispatchReactable.d.ts +3 -0
- package/dist/reaction/utils/dispatchReactable.d.ts.map +1 -0
- package/dist/reaction/utils/fetchReference.d.ts +3 -0
- package/dist/reaction/utils/fetchReference.d.ts.map +1 -0
- package/dist/reaction/utils/index.d.ts +3 -0
- package/dist/reaction/utils/index.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts +16 -0
- package/dist/report/api/createReport.d.ts.map +1 -0
- package/dist/report/api/deleteReport.d.ts +16 -0
- package/dist/report/api/deleteReport.d.ts.map +1 -0
- package/dist/report/api/index.d.ts +4 -0
- package/dist/report/api/index.d.ts.map +1 -0
- package/dist/report/api/isReportedByMe.d.ts +16 -0
- package/dist/report/api/isReportedByMe.d.ts.map +1 -0
- package/dist/report/constants/referenceTypes.d.ts +24 -0
- package/dist/report/constants/referenceTypes.d.ts.map +1 -0
- package/dist/role/api/getRole.d.ts +32 -0
- package/dist/role/api/getRole.d.ts.map +1 -0
- package/dist/role/api/index.d.ts +3 -0
- package/dist/role/api/index.d.ts.map +1 -0
- package/dist/role/api/queryRoles.d.ts +42 -0
- package/dist/role/api/queryRoles.d.ts.map +1 -0
- package/dist/stream/api/createStream.d.ts +18 -0
- package/dist/stream/api/createStream.d.ts.map +1 -0
- package/dist/stream/api/deleteStream.d.ts +16 -0
- package/dist/stream/api/deleteStream.d.ts.map +1 -0
- package/dist/stream/api/getStream.d.ts +12 -0
- package/dist/stream/api/getStream.d.ts.map +1 -0
- package/dist/stream/api/index.d.ts +6 -0
- package/dist/stream/api/index.d.ts.map +1 -0
- package/dist/stream/api/queryStreams.d.ts +23 -0
- package/dist/stream/api/queryStreams.d.ts.map +1 -0
- package/dist/stream/api/updateStream.d.ts +17 -0
- package/dist/stream/api/updateStream.d.ts.map +1 -0
- package/dist/stream/events/index.d.ts +4 -0
- package/dist/stream/events/index.d.ts.map +1 -0
- package/dist/stream/events/onStreamRecorded.d.ts +17 -0
- package/dist/stream/events/onStreamRecorded.d.ts.map +1 -0
- package/dist/stream/events/onStreamStarted.d.ts +17 -0
- package/dist/stream/events/onStreamStarted.d.ts.map +1 -0
- package/dist/stream/events/onStreamStopped.d.ts +17 -0
- package/dist/stream/events/onStreamStopped.d.ts.map +1 -0
- package/dist/user/api/getUser.d.ts +32 -0
- package/dist/user/api/getUser.d.ts.map +1 -0
- package/dist/user/api/getUsers.d.ts +32 -0
- package/dist/user/api/getUsers.d.ts.map +1 -0
- package/dist/user/api/index.d.ts +5 -0
- package/dist/user/api/index.d.ts.map +1 -0
- package/dist/user/api/queryUsers.d.ts +43 -0
- package/dist/user/api/queryUsers.d.ts.map +1 -0
- package/dist/user/api/updateUser.d.ts +17 -0
- package/dist/user/api/updateUser.d.ts.map +1 -0
- package/dist/user/events/index.d.ts +2 -0
- package/dist/user/events/index.d.ts.map +1 -0
- package/dist/user/events/onUserUpdated.d.ts +17 -0
- package/dist/user/events/onUserUpdated.d.ts.map +1 -0
- package/dist/user/observers/index.d.ts +2 -0
- package/dist/user/observers/index.d.ts.map +1 -0
- package/dist/user/observers/observeUser.d.ts +19 -0
- package/dist/user/observers/observeUser.d.ts.map +1 -0
- package/package.json +59 -0
- package/rollup.config.js +41 -0
- package/src/@types/core/cache.ts +22 -0
- package/src/@types/core/errors.ts +34 -0
- package/src/@types/core/events.ts +60 -0
- package/src/@types/core/model.ts +51 -0
- package/src/@types/core/payload.ts +102 -0
- package/src/@types/core/permissions.ts +76 -0
- package/src/@types/core/query.ts +95 -0
- package/src/@types/core/store.ts +52 -0
- package/src/@types/core/transport.ts +32 -0
- package/src/@types/domains/category.ts +15 -0
- package/src/@types/domains/channel.ts +38 -0
- package/src/@types/domains/client.ts +36 -0
- package/src/@types/domains/comment.ts +26 -0
- package/src/@types/domains/community.ts +35 -0
- package/src/@types/domains/content.ts +35 -0
- package/src/@types/domains/feed.ts +16 -0
- package/src/@types/domains/file.ts +41 -0
- package/src/@types/domains/group.ts +38 -0
- package/src/@types/domains/message.ts +27 -0
- package/src/@types/domains/partials.ts +52 -0
- package/src/@types/domains/post.ts +31 -0
- package/src/@types/domains/reaction.ts +30 -0
- package/src/@types/domains/stream.ts +57 -0
- package/src/@types/domains/user.ts +18 -0
- package/src/@types/global.ts +25 -0
- package/src/@types/index.ts +31 -0
- package/src/category/api/getCategory.ts +35 -0
- package/src/category/api/index.ts +2 -0
- package/src/category/api/queryCategories.ts +49 -0
- package/src/channel/api/addChannelMembers.ts +45 -0
- package/src/channel/api/addChannelMembersRole.ts +43 -0
- package/src/channel/api/createChannel.ts +37 -0
- package/src/channel/api/deleteChannel.ts +34 -0
- package/src/channel/api/getChannel.ts +59 -0
- package/src/channel/api/getChannels.ts +63 -0
- package/src/channel/api/index.ts +18 -0
- package/src/channel/api/joinChannel.ts +38 -0
- package/src/channel/api/leaveChannel.ts +38 -0
- package/src/channel/api/queryChannelMembers.ts +79 -0
- package/src/channel/api/queryChannels.ts +89 -0
- package/src/channel/api/removeChannelMembers.ts +45 -0
- package/src/channel/api/removeChannelMembersRole.ts +43 -0
- package/src/channel/api/updateChannel.ts +38 -0
- package/src/channel/events/index.ts +6 -0
- package/src/channel/events/onChannelCreated.ts +37 -0
- package/src/channel/events/onChannelDeleted.ts +37 -0
- package/src/channel/events/onChannelJoined.ts +37 -0
- package/src/channel/events/onChannelLeft.ts +37 -0
- package/src/channel/events/onChannelUpdated.ts +37 -0
- package/src/channel/events/onMemberAdded.ts +37 -0
- package/src/channel/events/onMemberRemoved.ts +37 -0
- package/src/channel/observers/index.ts +1 -0
- package/src/channel/observers/observeChannel.ts +80 -0
- package/src/client/api/activeClient.ts +33 -0
- package/src/client/api/clearCache.ts +23 -0
- package/src/client/api/connectClient.ts +63 -0
- package/src/client/api/createClient.ts +56 -0
- package/src/client/api/disconnectClient.ts +31 -0
- package/src/client/api/enableCache.ts +35 -0
- package/src/client/api/getToken.ts +35 -0
- package/src/client/api/index.ts +7 -0
- package/src/client/api/isConnected.ts +24 -0
- package/src/client/events/index.ts +1 -0
- package/src/client/events/onClientDisconnected.ts +29 -0
- package/src/comment/api/createComment.ts +43 -0
- package/src/comment/api/deleteComment.ts +40 -0
- package/src/comment/api/getComment.ts +59 -0
- package/src/comment/api/getComments.ts +63 -0
- package/src/comment/api/index.ts +7 -0
- package/src/comment/api/queryComments.ts +169 -0
- package/src/comment/api/updateComment.ts +41 -0
- package/src/comment/events/index.ts +3 -0
- package/src/comment/events/onCommentCreated.ts +39 -0
- package/src/comment/events/onCommentDeleted.ts +39 -0
- package/src/comment/events/onCommentUpdated.ts +39 -0
- package/src/comment/observers/index.ts +2 -0
- package/src/comment/observers/observeComment.ts +73 -0
- package/src/comment/observers/observeComments.ts +61 -0
- package/src/community/api/addCommunityMembers.ts +46 -0
- package/src/community/api/addCommunityMembersRole.ts +43 -0
- package/src/community/api/createCommunity.ts +43 -0
- package/src/community/api/deleteCommunity.ts +35 -0
- package/src/community/api/getCommunities.ts +63 -0
- package/src/community/api/getCommunity.ts +58 -0
- package/src/community/api/index.ts +17 -0
- package/src/community/api/joinCommunity.ts +41 -0
- package/src/community/api/leaveCommunity.ts +41 -0
- package/src/community/api/queryCommunities.ts +92 -0
- package/src/community/api/queryCommunityMembers.ts +78 -0
- package/src/community/api/removeCommunityMembers.ts +46 -0
- package/src/community/api/removeCommunityMembersRole.ts +43 -0
- package/src/community/api/updateCommunity.ts +40 -0
- package/src/community/events/index.ts +6 -0
- package/src/community/events/onCommunityCreated.ts +37 -0
- package/src/community/events/onCommunityDeleted.ts +37 -0
- package/src/community/events/onCommunityJoined.ts +37 -0
- package/src/community/events/onCommunityLeft.ts +37 -0
- package/src/community/events/onCommunityUpdated.ts +37 -0
- package/src/community/observers/index.ts +1 -0
- package/src/community/observers/observeCommunity.ts +74 -0
- package/src/core/cache/drop.ts +24 -0
- package/src/core/cache/index.ts +24 -0
- package/src/core/cache/ingest.ts +24 -0
- package/src/core/cache/merge.ts +19 -0
- package/src/core/cache/mutate.ts +25 -0
- package/src/core/cache/pull.ts +31 -0
- package/src/core/cache/push.ts +41 -0
- package/src/core/cache/sync.ts +41 -0
- package/src/core/debug.ts +26 -0
- package/src/core/device.ts +38 -0
- package/src/core/errors.ts +85 -0
- package/src/core/events.ts +93 -0
- package/src/core/model/idResolvers.ts +66 -0
- package/src/core/model/identifyModel.ts +32 -0
- package/src/core/model/index.ts +3 -0
- package/src/core/model/toRecord.ts +11 -0
- package/src/core/query/decorate.ts +64 -0
- package/src/core/query/filtering.ts +17 -0
- package/src/core/query/index.ts +5 -0
- package/src/core/query/paging.ts +166 -0
- package/src/core/query/query.ts +300 -0
- package/src/core/query/sorting.ts +50 -0
- package/src/core/stores/index.ts +2 -0
- package/src/core/stores/memory.ts +59 -0
- package/src/core/stores/persistent.ts +63 -0
- package/src/core/transports.ts +157 -0
- package/src/core/uuid.ts +2 -0
- package/src/feed/api/index.ts +1 -0
- package/src/feed/api/queryGlobalFeed.ts +50 -0
- package/src/file/api/createFile.ts +51 -0
- package/src/file/api/deleteFile.ts +35 -0
- package/src/file/api/fileUrlWithSize.ts +13 -0
- package/src/file/api/getFile.ts +60 -0
- package/src/file/api/index.ts +4 -0
- package/src/file/observers/index.ts +1 -0
- package/src/file/observers/observeFile.ts +57 -0
- package/src/index.ts +55 -0
- package/src/message/api/createMessage.ts +90 -0
- package/src/message/api/deleteMessage.ts +75 -0
- package/src/message/api/getMessage.ts +60 -0
- package/src/message/api/getMessages.ts +63 -0
- package/src/message/api/index.ts +6 -0
- package/src/message/api/queryMessages.ts +145 -0
- package/src/message/api/updateMessage.ts +79 -0
- package/src/message/events/index.ts +3 -0
- package/src/message/events/onMessageCreated.ts +39 -0
- package/src/message/events/onMessageDeleted.ts +39 -0
- package/src/message/events/onMessageUpdated.ts +39 -0
- package/src/message/observers/index.ts +2 -0
- package/src/message/observers/observeMessage.ts +76 -0
- package/src/message/observers/observeMessages.ts +60 -0
- package/src/post/api/createPost.ts +45 -0
- package/src/post/api/deletePost.ts +43 -0
- package/src/post/api/getPost.ts +60 -0
- package/src/post/api/getPosts.ts +63 -0
- package/src/post/api/index.ts +7 -0
- package/src/post/api/queryPosts.ts +86 -0
- package/src/post/api/updatePost.ts +42 -0
- package/src/post/events/index.ts +3 -0
- package/src/post/events/onPostCreated.ts +39 -0
- package/src/post/events/onPostDeleted.ts +39 -0
- package/src/post/events/onPostUpdated.ts +39 -0
- package/src/post/observers/index.ts +2 -0
- package/src/post/observers/observePost.ts +72 -0
- package/src/post/observers/observePosts.ts +66 -0
- package/src/reaction/api/addReaction.ts +84 -0
- package/src/reaction/api/index.ts +2 -0
- package/src/reaction/api/removeReaction.ts +84 -0
- package/src/reaction/events/index.ts +1 -0
- package/src/reaction/events/onReactionAdded.ts +43 -0
- package/src/reaction/events/onReactionRemoved.ts +41 -0
- package/src/reaction/utils/dispatchReactable.ts +19 -0
- package/src/reaction/utils/fetchReference.ts +18 -0
- package/src/reaction/utils/index.ts +2 -0
- package/src/report/api/createReport.ts +40 -0
- package/src/report/api/deleteReport.ts +40 -0
- package/src/report/api/index.ts +4 -0
- package/src/report/api/isReportedByMe.ts +37 -0
- package/src/report/constants/referenceTypes.ts +22 -0
- package/src/role/api/getRole.ts +53 -0
- package/src/role/api/index.ts +2 -0
- package/src/role/api/queryRoles.ts +79 -0
- package/src/stream/api/createStream.ts +33 -0
- package/src/stream/api/deleteStream.ts +38 -0
- package/src/stream/api/getStream.ts +29 -0
- package/src/stream/api/index.ts +7 -0
- package/src/stream/api/queryStreams.ts +44 -0
- package/src/stream/api/updateStream.ts +36 -0
- package/src/stream/events/index.ts +3 -0
- package/src/stream/events/onStreamRecorded.ts +39 -0
- package/src/stream/events/onStreamStarted.ts +39 -0
- package/src/stream/events/onStreamStopped.ts +39 -0
- package/src/user/api/getUser.ts +59 -0
- package/src/user/api/getUsers.ts +60 -0
- package/src/user/api/index.ts +5 -0
- package/src/user/api/queryUsers.ts +88 -0
- package/src/user/api/updateUser.ts +44 -0
- package/src/user/events/index.ts +1 -0
- package/src/user/events/onUserUpdated.ts +39 -0
- package/src/user/observers/index.ts +1 -0
- package/src/user/observers/observeUser.ts +64 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { encode, decode } from 'js-base64'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
|
|
6
|
+
*
|
|
7
|
+
* @param json any json object as extracted from the backend
|
|
8
|
+
* @returns success boolean if the token has either "skip" or "limit" props
|
|
9
|
+
*
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
export const isSkipLimit = (json: Object): json is Amity.SkipLimitPagination => (
|
|
13
|
+
['skip', 'limit'].some(prop => prop in json)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to find if the a given decoded backend token uses "after/before" pagination style
|
|
18
|
+
*
|
|
19
|
+
* @param json any json object as extracted from the backend
|
|
20
|
+
* @returns success boolean if the token has either "after" or "before" props
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
export const isAfterBefore = (json: Object): json is Amity.AfterBeforePagination => (
|
|
25
|
+
['after', 'before', 'first', 'last'].some(prop => prop in json)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
30
|
+
*
|
|
31
|
+
* @param payload any object as passed from query functions
|
|
32
|
+
* @returns success boolean if the object is an array shaped as [Record<string, Amity.Syncable>, Amity.Pages]
|
|
33
|
+
*
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
export const isPaged = (payload: any): payload is Amity.Paged<any> => {
|
|
37
|
+
return (
|
|
38
|
+
payload?.hasOwnProperty('data')
|
|
39
|
+
&& payload?.hasOwnProperty('nextPage')
|
|
40
|
+
&& payload?.hasOwnProperty('prevPage')
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Converts a paging object into a b64 string token
|
|
46
|
+
*
|
|
47
|
+
* @param paging the sdk-friendly paging object
|
|
48
|
+
* @param style the style of token to produce
|
|
49
|
+
* @returns a backend's b64 encoded token
|
|
50
|
+
*
|
|
51
|
+
* @hidden
|
|
52
|
+
*/
|
|
53
|
+
export const toToken = (
|
|
54
|
+
paging: Amity.Page | undefined,
|
|
55
|
+
style: 'skiplimit' | 'afterbefore',
|
|
56
|
+
|
|
57
|
+
): Amity.Token | undefined => {
|
|
58
|
+
if (!paging || !Object.keys(paging).length)
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
let payload = {}
|
|
62
|
+
|
|
63
|
+
// TODO: refactor this clean
|
|
64
|
+
if (style === 'skiplimit') {
|
|
65
|
+
payload = {
|
|
66
|
+
skip: paging.after ?? 0,
|
|
67
|
+
limit: paging.limit,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (style === 'afterbefore') {
|
|
71
|
+
/*
|
|
72
|
+
Caution: this testing style is only valid because
|
|
73
|
+
our backend expects nothing else than a number as
|
|
74
|
+
"before" or "after" value. if that would change,
|
|
75
|
+
we'd need to move toward a more simple: `!paging.before`
|
|
76
|
+
*/
|
|
77
|
+
if (!isNaN(paging?.before!)) {
|
|
78
|
+
payload = {
|
|
79
|
+
before: paging.before,
|
|
80
|
+
last: paging.limit,
|
|
81
|
+
}
|
|
82
|
+
} else if (!isNaN(paging?.after!)) {
|
|
83
|
+
payload = {
|
|
84
|
+
after: paging.after,
|
|
85
|
+
first: paging.limit,
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// avoid sending {} as it seems backend flips when we do
|
|
91
|
+
if (!Object.keys(payload).length)
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
// don't try catch, let it throw
|
|
95
|
+
return encode(JSON.stringify(payload))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Converts a b64 string token into a paging object
|
|
100
|
+
*
|
|
101
|
+
* @param token the backend's b64 encoded token
|
|
102
|
+
* @returns a sdk-friendly paging object
|
|
103
|
+
*
|
|
104
|
+
* @hidden
|
|
105
|
+
*/
|
|
106
|
+
export const toPage = (token?: Amity.Token): Amity.Page | null => {
|
|
107
|
+
if (!token) return null
|
|
108
|
+
|
|
109
|
+
// don't try catch, let it throw
|
|
110
|
+
const json = JSON.parse(decode(token))
|
|
111
|
+
|
|
112
|
+
if (isSkipLimit(json)) {
|
|
113
|
+
return {
|
|
114
|
+
after: json.skip,
|
|
115
|
+
limit: json.limit!,
|
|
116
|
+
} as Amity.NextPage
|
|
117
|
+
} else if (isAfterBefore(json)) {
|
|
118
|
+
if ('before' in json) {
|
|
119
|
+
return {
|
|
120
|
+
before: json.before,
|
|
121
|
+
limit: json.last,
|
|
122
|
+
} as Amity.PrevPage
|
|
123
|
+
} else if ('after' in json) {
|
|
124
|
+
return {
|
|
125
|
+
after: json.after,
|
|
126
|
+
limit: json.first,
|
|
127
|
+
} as Amity.NextPage
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Slices a collection according to its paging
|
|
136
|
+
*
|
|
137
|
+
* @param type the type of collection (for unique id identification with after/before)
|
|
138
|
+
* @param collection the collection to slice
|
|
139
|
+
* @param paging the paging object
|
|
140
|
+
* @returns the sliced collection according to the paging definition
|
|
141
|
+
*
|
|
142
|
+
* @hidden
|
|
143
|
+
*/
|
|
144
|
+
export const sliceByPaging = <K extends Amity.Domain, T extends Amity.Model[K]>(
|
|
145
|
+
type: K, collection: T[], page?: Amity.Page
|
|
146
|
+
) => {
|
|
147
|
+
console.log('slice by paging', page)
|
|
148
|
+
if (!page) return collection.slice()
|
|
149
|
+
|
|
150
|
+
let start: number | undefined = 0
|
|
151
|
+
let end: number | undefined = undefined
|
|
152
|
+
|
|
153
|
+
// next page behavior
|
|
154
|
+
if (page.after) {
|
|
155
|
+
start = page.after
|
|
156
|
+
end = start + page.limit
|
|
157
|
+
// prev page behavior
|
|
158
|
+
} else if (page.before) {
|
|
159
|
+
end = page.before + 1
|
|
160
|
+
start = end > page.limit ? end - page.limit : 0
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const paged = collection.slice(start, end)
|
|
164
|
+
|
|
165
|
+
return paged.length === page.limit ? paged : undefined
|
|
166
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { syncInCache } from '../cache'
|
|
2
|
+
|
|
3
|
+
import { isPaged } from './paging'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
7
|
+
*
|
|
8
|
+
* @param func any SDK APi function
|
|
9
|
+
* @returns success boolean if the function has a 'locally' twin
|
|
10
|
+
*
|
|
11
|
+
* @hidden
|
|
12
|
+
*/
|
|
13
|
+
export const isFetcher = <Args extends any[], Returned extends any>(
|
|
14
|
+
func: Amity.AsyncFunc<Args, Returned>
|
|
15
|
+
): func is Amity.FetcherFunc<Args, Returned> => (
|
|
16
|
+
'locally' in func
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Type guard to check and cast that a given async function is has the ".optimistically" property
|
|
21
|
+
*
|
|
22
|
+
* @param func any SDK APi function
|
|
23
|
+
* @returns success boolean if the function has an 'optimistically' twin
|
|
24
|
+
*
|
|
25
|
+
* @hidden
|
|
26
|
+
*/
|
|
27
|
+
export const isMutator = <Args extends any[], Returned extends any>(
|
|
28
|
+
func: Amity.AsyncFunc<Args, Returned>
|
|
29
|
+
): func is Amity.MutatorFunc<Args, Returned> => (
|
|
30
|
+
'optimistically' in func
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Type guard to check and cast that a given async function is has
|
|
35
|
+
* the ".locally" or ".optimistically" property
|
|
36
|
+
*
|
|
37
|
+
* @param func any SDK APi function
|
|
38
|
+
* @returns success boolean if the function has an offline twin
|
|
39
|
+
*
|
|
40
|
+
* @hidden
|
|
41
|
+
*/
|
|
42
|
+
export const isOffline = <Args extends any[], Returned extends any>(
|
|
43
|
+
func: Amity.AsyncFunc<Args, Returned>
|
|
44
|
+
): func is Amity.OfflineFunc<Args, Returned> => isFetcher(func) || isMutator(func)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Type guard to check and cast that a given object has the "syncedAt" property
|
|
48
|
+
*
|
|
49
|
+
* @param model any object to check on
|
|
50
|
+
* @returns success boolean if the object has property "syncedAt"
|
|
51
|
+
*
|
|
52
|
+
* @hidden
|
|
53
|
+
*/
|
|
54
|
+
export const isSyncable = (model: any): model is Amity.Syncable => (
|
|
55
|
+
model?.hasOwnProperty('syncedAt')
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a model is considered local (syncedAt === -1)
|
|
60
|
+
*
|
|
61
|
+
* @param model any syncable object to check
|
|
62
|
+
* @returns success boolean if the object is marked as local
|
|
63
|
+
*
|
|
64
|
+
* @hidden
|
|
65
|
+
*/
|
|
66
|
+
export const isLocal = (model?: any): model is Amity.Syncable => {
|
|
67
|
+
return isSyncable(model) && model?.syncedAt === -1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a model is considered fresh
|
|
72
|
+
*
|
|
73
|
+
* @param model any syncable object to check
|
|
74
|
+
* @param lifeSpan the supposedly duration for which the object is considered synced
|
|
75
|
+
* @returns success boolean if the object is below the given lifespan
|
|
76
|
+
*
|
|
77
|
+
* @hidden
|
|
78
|
+
*/
|
|
79
|
+
export const isFresh = (model?: Amity.Syncable, lifeSpan: number = 0) => {
|
|
80
|
+
return Date.now() - (model?.syncedAt ?? 0) <= lifeSpan
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a model is considered synced
|
|
85
|
+
*
|
|
86
|
+
* @param model any syncable object to check
|
|
87
|
+
* @param lifeSpan the supposedly duration for which the object is considered synced
|
|
88
|
+
* @returns success boolean if the object is local or below the given lifespan
|
|
89
|
+
*
|
|
90
|
+
* @hidden
|
|
91
|
+
*/
|
|
92
|
+
export const isSynced = (model?: any, lifeSpan: number = 0) => {
|
|
93
|
+
return isLocal(model) || isFresh(model, lifeSpan)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* ```js
|
|
98
|
+
* import { createQuery, getUser } from '@amityco/ts-sdk'
|
|
99
|
+
* const query = createQuery(getUser, 'foobar')
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* Creates a wrapper for the API call you wish to call.
|
|
103
|
+
* This wrapper is necessary to create for optimistically calls
|
|
104
|
+
*
|
|
105
|
+
*
|
|
106
|
+
* @param fn A compatible API function from the ts sdk
|
|
107
|
+
* @param args The arguments to pass to the function passed as `fn`
|
|
108
|
+
* @returns A wrapper containing both the function and its future arguments
|
|
109
|
+
*
|
|
110
|
+
* @category Query
|
|
111
|
+
*/
|
|
112
|
+
export const createQuery = <Args extends any[], Returned extends any>(
|
|
113
|
+
func: Amity.AsyncFunc<Args, Returned> | Amity.OfflineFunc<Args, Returned>,
|
|
114
|
+
...args: Args
|
|
115
|
+
) => ({ func, args })
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* ```js
|
|
120
|
+
* import { queryOptions } from '@amityco/ts-sdk'
|
|
121
|
+
* const options = queryOptions('no_fetch', lifeSpan)
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* Creates a query options object based on the query policy passed
|
|
125
|
+
*
|
|
126
|
+
* @param policy The policy to apply to a query
|
|
127
|
+
* @returns A properly set query options object
|
|
128
|
+
*
|
|
129
|
+
* @category Query
|
|
130
|
+
*/
|
|
131
|
+
export const queryOptions = (
|
|
132
|
+
policy: Amity.QueryPolicy, lifeSpan: number = 2 * 60 * 1000, // 2mn
|
|
133
|
+
): Amity.QueryOptions => {
|
|
134
|
+
if (policy === 'cache_only')
|
|
135
|
+
return { lifeSpan: Infinity }
|
|
136
|
+
else if (policy === 'server_only')
|
|
137
|
+
return { lifeSpan: 0 }
|
|
138
|
+
|
|
139
|
+
return { lifeSpan }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Checks if an unknown shaped payload is considered empty or not.
|
|
144
|
+
* Since the payload can be wrapped around [] or {} (query or get many),
|
|
145
|
+
* we need a smarter definition of what's considered "empty".
|
|
146
|
+
*
|
|
147
|
+
* @param local the unknown object to check for emptiness
|
|
148
|
+
* @returns true if the mixed-shape "local" content is considered empty
|
|
149
|
+
*
|
|
150
|
+
* @hidden
|
|
151
|
+
*/
|
|
152
|
+
const isEmpty = (local: any) => {
|
|
153
|
+
// if it's supposed to be a single object, it'd be undefined
|
|
154
|
+
if (!local)
|
|
155
|
+
return true
|
|
156
|
+
|
|
157
|
+
// it's a paged query, the 1st cell of the array would be empty
|
|
158
|
+
else if (isPaged(local) && isEmpty(local.data)) {
|
|
159
|
+
return true
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// if it's a item collection, it'd have no keys
|
|
163
|
+
else if (!Object.keys(local).length)
|
|
164
|
+
return true
|
|
165
|
+
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Checks if an unknown shaped payload is considered synced or not.
|
|
171
|
+
* The object will first be identified by 3 types of shapes:
|
|
172
|
+
*
|
|
173
|
+
* 1. Amity.Paged<Amity.Syncable>
|
|
174
|
+
* 2. Amity.Syncable
|
|
175
|
+
* 3. Record<string, Amity.Syncable>
|
|
176
|
+
*
|
|
177
|
+
* then the "Syncable" component will be extracted and evaluated against
|
|
178
|
+
* the query options' lifeSpan value.
|
|
179
|
+
*
|
|
180
|
+
* @param local the unknown object to check for freshness
|
|
181
|
+
* @param options query options (for lifeSpan checking)
|
|
182
|
+
* @returns true if the mixed-shape "local" content is considered fresh
|
|
183
|
+
*
|
|
184
|
+
* @hidden
|
|
185
|
+
*/
|
|
186
|
+
const shouldAbort = (local: any, options: Amity.QueryOptions) => {
|
|
187
|
+
// it's a paged query
|
|
188
|
+
if (isPaged(local) && shouldAbort(local.data, options)) {
|
|
189
|
+
return true
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// if it's object let's try to see if it's Amity.Syncable first
|
|
193
|
+
else if (isSynced(local, options.lifeSpan)) {
|
|
194
|
+
return true
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// otherwise consider as Record<string, Amity.Syncable>
|
|
198
|
+
else if (
|
|
199
|
+
Object.values(local).length > 0 &&
|
|
200
|
+
Object.values(local).every(item => isSynced(item, options.lifeSpan))
|
|
201
|
+
) {
|
|
202
|
+
return true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return false
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* ```js
|
|
210
|
+
* import { createQuery, getUser, runQuery } from '@amityco/ts-sdk'
|
|
211
|
+
* const query = createQuery(getUser, client, 'foobar')
|
|
212
|
+
* runQuery(query, user => console.log(user))
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* Calls an API function wrapped around a Amity.Query, and executes the callback whenever
|
|
216
|
+
* a value is available. The value can be picked either from the local cache and/or
|
|
217
|
+
* from the server afterwards depending on the query options passed
|
|
218
|
+
*
|
|
219
|
+
* @param query A query object wrapping the call to be made
|
|
220
|
+
* @param callback A function to execute when a value is available
|
|
221
|
+
* @param options the query options
|
|
222
|
+
*
|
|
223
|
+
* @category Query
|
|
224
|
+
*/
|
|
225
|
+
export const runQuery = <Args extends any[], Returned extends any>(
|
|
226
|
+
{ func, args }: Amity.Query<Args, Returned>,
|
|
227
|
+
callback?: (args: Amity.QueryResult<Returned | undefined>) => void,
|
|
228
|
+
options: Amity.QueryOptions = queryOptions('cache_then_server')
|
|
229
|
+
) => {
|
|
230
|
+
if (!isOffline(func) || options.lifeSpan === 0) {
|
|
231
|
+
callback?.(wrap(undefined, {
|
|
232
|
+
origin: 'server',
|
|
233
|
+
loading: true
|
|
234
|
+
}))
|
|
235
|
+
|
|
236
|
+
func(...args)
|
|
237
|
+
.then(fresh => {
|
|
238
|
+
callback?.(wrap(fresh, {
|
|
239
|
+
origin: 'server',
|
|
240
|
+
loading: false,
|
|
241
|
+
}))
|
|
242
|
+
})
|
|
243
|
+
.catch(error => {
|
|
244
|
+
callback?.(wrap(undefined, {
|
|
245
|
+
error,
|
|
246
|
+
loading: false,
|
|
247
|
+
}))
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const local = isMutator(func)
|
|
254
|
+
? func.optimistically(...args)
|
|
255
|
+
: func.locally(...args)
|
|
256
|
+
|
|
257
|
+
if (!isEmpty(local)) {
|
|
258
|
+
callback?.(wrap(local, { origin: 'local' }))
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (local && isFetcher(func) && shouldAbort(local, options)) return
|
|
262
|
+
|
|
263
|
+
callback?.(wrap(local, {
|
|
264
|
+
origin: 'local',
|
|
265
|
+
loading: true,
|
|
266
|
+
}))
|
|
267
|
+
|
|
268
|
+
func(...args)
|
|
269
|
+
.then(fresh => {
|
|
270
|
+
// @ts-ignore i know.
|
|
271
|
+
isLocal(local) && syncInCache(local, fresh)
|
|
272
|
+
|
|
273
|
+
callback?.(wrap(fresh, {
|
|
274
|
+
origin: 'server',
|
|
275
|
+
loading: false
|
|
276
|
+
}))
|
|
277
|
+
})
|
|
278
|
+
.catch(error => {
|
|
279
|
+
callback?.(wrap(local, {
|
|
280
|
+
error,
|
|
281
|
+
loading: false,
|
|
282
|
+
}))
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
*
|
|
288
|
+
* @param data
|
|
289
|
+
* @param meta
|
|
290
|
+
* @returns
|
|
291
|
+
*/
|
|
292
|
+
const wrap = <T extends any>(data: T, meta: Amity.QueryMetadata = {}) => {
|
|
293
|
+
if (isPaged(data))
|
|
294
|
+
return {
|
|
295
|
+
...meta,
|
|
296
|
+
...data as Amity.Paged<T>,
|
|
297
|
+
} as Amity.QueryResult<T>
|
|
298
|
+
|
|
299
|
+
return { ...meta, data } as Amity.QueryResult<T>
|
|
300
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Note:
|
|
2
|
+
// this file should contain a suite of sorting utilities to help the
|
|
3
|
+
// local version of the query functions.
|
|
4
|
+
|
|
5
|
+
type SortingFunc<T = Object> = (a: T, b: T) => number
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Alphabetic sorting of objects having a displayName
|
|
9
|
+
*/
|
|
10
|
+
export const sortByDisplayName: SortingFunc<{ displayName: string }> = (
|
|
11
|
+
{ displayName: a }, { displayName: b }
|
|
12
|
+
) => {
|
|
13
|
+
if (a === b) return 0
|
|
14
|
+
return a < b ? -1 : 1
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sorting a collection by their apparition order (oldest first)
|
|
19
|
+
*/
|
|
20
|
+
export const sortByChannelSegment: SortingFunc<{ channelSegment: number }> = (
|
|
21
|
+
{ channelSegment: a }, { channelSegment: b }
|
|
22
|
+
) => a - b
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Sorting a collection by their apparition order (oldest first)
|
|
26
|
+
*/
|
|
27
|
+
export const sortBySegmentNumber: SortingFunc<{ segmentNumber: number }> = (
|
|
28
|
+
{ segmentNumber: a }, { segmentNumber: b }
|
|
29
|
+
) => a - b
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sorting a collection by its oldest items
|
|
33
|
+
*/
|
|
34
|
+
export const sortByFirstCreated: SortingFunc<{ createdAt: Date | number | string }> = (
|
|
35
|
+
{ createdAt: a }, { createdAt: b }
|
|
36
|
+
) => new Date(a).valueOf() - new Date(b).valueOf()
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sorting a collection by its newest items
|
|
40
|
+
*/
|
|
41
|
+
export const sortByLastCreated: SortingFunc<{ createdAt: Date | number | string }> = (
|
|
42
|
+
{ createdAt: a }, { createdAt: b }
|
|
43
|
+
) => new Date(b).valueOf() - new Date(a).valueOf()
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sorting a collection by the items with most recent activity
|
|
47
|
+
*/
|
|
48
|
+
export const sortByLastActivity: SortingFunc<{ lastActivity: Date | number | string }> = (
|
|
49
|
+
{ lastActivity: a }, { lastActivity: b }
|
|
50
|
+
) => new Date(b).valueOf() - new Date(a).valueOf()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal store implementation.
|
|
3
|
+
*
|
|
4
|
+
* Beware, the state is mutable! it is your responsibility
|
|
5
|
+
* handle the state's mutations correctly. We do so in
|
|
6
|
+
* order for users with mutable/observable stacks to be able
|
|
7
|
+
* to decorate the state with their favorite libraries.
|
|
8
|
+
*
|
|
9
|
+
* @param defaultValue the hydration state value of the store
|
|
10
|
+
* @returns A store instance with an "in memory" storage strategy
|
|
11
|
+
*
|
|
12
|
+
* @category Storage
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
export const memoryStore = <T extends {}>(
|
|
16
|
+
defaultValue: Record<string, T> = {},
|
|
17
|
+
) => {
|
|
18
|
+
const state: Record<string, T> = defaultValue
|
|
19
|
+
|
|
20
|
+
/* default read operation is just to return the state */
|
|
21
|
+
const read: Amity.StateReader<T> = () => state
|
|
22
|
+
|
|
23
|
+
/* default write operation is just to mutate the state */
|
|
24
|
+
const write: Amity.StateWriter<T> = (payload) => {
|
|
25
|
+
Object.assign(state, payload)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* default write operation is just to mutate the state */
|
|
29
|
+
const erase: Amity.StateEraser = (...keys) => {
|
|
30
|
+
if (!keys.length)
|
|
31
|
+
keys = Object.keys(state)
|
|
32
|
+
|
|
33
|
+
keys.forEach(key => delete state[key])
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { read, write, erase } as Amity.Store<T>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* ```js
|
|
41
|
+
* import { memoryStores } from '@amityco/core/cache/store/volatile'
|
|
42
|
+
* const stores = imemoryStores('user', 'file')
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Builds a collection of in memory stores based on the available store names
|
|
46
|
+
*
|
|
47
|
+
* @param names collection of store names
|
|
48
|
+
* @returns a dictionary of { storeName: storeInstance } according to the given names
|
|
49
|
+
*
|
|
50
|
+
* @category Storage
|
|
51
|
+
*/
|
|
52
|
+
export const memoryStores = <
|
|
53
|
+
T extends Amity.Domain[], // https://github.com/microsoft/TypeScript/issues/44155
|
|
54
|
+
>(...names: T) => {
|
|
55
|
+
return names.reduce((acc, name) => {
|
|
56
|
+
const store = memoryStore<Amity.Model[typeof name]>()
|
|
57
|
+
return { ...acc, [name]: store }
|
|
58
|
+
}, {} as Amity.StoreCollection<T>)
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
|
|
3
|
+
import { memoryStore } from './memory'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_DEBOUNCE_TIME = 250
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Persistent store implementation.
|
|
9
|
+
*
|
|
10
|
+
* @param persistentKey the name of the store in persistent storage
|
|
11
|
+
* @param defaultValue the hydration state value of the store
|
|
12
|
+
* @param debounceTime a delay to avoid spamming the persistent storage while writing,
|
|
13
|
+
* @returns A store instance with an "persistent" storage strategy
|
|
14
|
+
*
|
|
15
|
+
* @category Storage
|
|
16
|
+
* @hidden
|
|
17
|
+
*/
|
|
18
|
+
export const persistentStore = async <T extends {}>(
|
|
19
|
+
persistentKey: string,
|
|
20
|
+
defaultValue: Record<string, T> = {},
|
|
21
|
+
debounceTime = DEFAULT_DEBOUNCE_TIME,
|
|
22
|
+
) => {
|
|
23
|
+
let initialValue = defaultValue
|
|
24
|
+
|
|
25
|
+
const serializedBackup = await AsyncStorage.getItem(persistentKey)
|
|
26
|
+
|
|
27
|
+
if (serializedBackup) {
|
|
28
|
+
try { initialValue = JSON.parse(serializedBackup) }
|
|
29
|
+
catch (err) {}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// create a store
|
|
33
|
+
const store = memoryStore<T>(initialValue)
|
|
34
|
+
|
|
35
|
+
let timer: number
|
|
36
|
+
let job: Promise<any> | null = null
|
|
37
|
+
|
|
38
|
+
const backup = () => {
|
|
39
|
+
if (job) {
|
|
40
|
+
job.then(() => backup())
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
clearTimeout(timer)
|
|
45
|
+
setTimeout(async () => {
|
|
46
|
+
job = Promise.resolve()
|
|
47
|
+
.then(() => AsyncStorage.setItem(persistentKey, JSON.stringify(store.read())))
|
|
48
|
+
.then(() => job = null)
|
|
49
|
+
}, debounceTime)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const write: typeof store.write = (payload) => {
|
|
53
|
+
store.write(payload)
|
|
54
|
+
backup()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const erase: typeof store.erase = (...keys) => {
|
|
58
|
+
store.erase(...keys)
|
|
59
|
+
backup()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { read: store.read, write, erase } as Amity.Store<T>
|
|
63
|
+
}
|