[SDK] Remove @atproto/api (#11386)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+16
-18
@@ -1,7 +1,6 @@
|
||||
import {useCallback} from 'react'
|
||||
import {type AppBskyActorDefs, type AppBskyFeedDefs, AtUri} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex'
|
||||
import {type AtUriString, type HandleString} from '@atproto/syntax'
|
||||
import {AtUri, type AtUriString, type HandleString} from '@atproto/syntax'
|
||||
import {deleteLike, deletePost, deleteRepost, like, repost} from '@bsky.app/sdk'
|
||||
import {
|
||||
type QueryClient,
|
||||
@@ -26,7 +25,7 @@ export const RQKEY = (postUri: string) => [RQKEY_ROOT, postUri]
|
||||
|
||||
export function usePostQuery(uri: string | undefined) {
|
||||
const client = useAppviewClient()
|
||||
return useQuery<AppBskyFeedDefs.PostView>({
|
||||
return useQuery<app.bsky.feed.defs.PostView>({
|
||||
queryKey: RQKEY(uri || ''),
|
||||
queryFn: async () => {
|
||||
if (!uri) throw new Error('[unreachable] No URI provided')
|
||||
@@ -46,14 +45,13 @@ export function usePostQuery(uri: string | undefined) {
|
||||
* Read one post by AT-URI, resolving a handle authority first when the URI
|
||||
* carries one.
|
||||
*
|
||||
* The appview still answers with `@atproto/api`-shaped views for the callers of
|
||||
* these hooks, so the generated view is asserted across at this single
|
||||
* The appview response is asserted to the generated view at this single
|
||||
* boundary rather than at every consumer.
|
||||
*/
|
||||
async function fetchPost(
|
||||
client: Client,
|
||||
uri: string,
|
||||
): Promise<AppBskyFeedDefs.PostView | undefined> {
|
||||
): Promise<app.bsky.feed.defs.PostView | undefined> {
|
||||
const urip = new AtUri(uri)
|
||||
|
||||
if (!urip.host.startsWith('did:')) {
|
||||
@@ -72,7 +70,7 @@ async function fetchPost(
|
||||
export function precachePost(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
post: AppBskyFeedDefs.PostView,
|
||||
post: app.bsky.feed.defs.PostView,
|
||||
) {
|
||||
queryClient.setQueryData(RQKEY(uri), post)
|
||||
}
|
||||
@@ -110,7 +108,7 @@ export function useGetPosts() {
|
||||
uris: uris as AtUriString[],
|
||||
})
|
||||
// See the note on `fetchPost` about the view shapes.
|
||||
return data.posts as AppBskyFeedDefs.PostView[]
|
||||
return data.posts
|
||||
},
|
||||
})
|
||||
},
|
||||
@@ -119,7 +117,7 @@ export function useGetPosts() {
|
||||
}
|
||||
|
||||
export function usePostLikeMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
viaRepost: {uri: string; cid: string} | undefined,
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:like']['logContext'],
|
||||
@@ -183,7 +181,7 @@ export function usePostLikeMutationQueue(
|
||||
function usePostLikeMutation(
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:like']['logContext'],
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
) {
|
||||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -191,12 +189,12 @@ function usePostLikeMutation(
|
||||
const pdsClient = usePdsClient()
|
||||
const ax = useAnalytics()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the like
|
||||
{uri: AtUriString}, // responds with the uri of the like
|
||||
Error,
|
||||
{uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present
|
||||
>({
|
||||
mutationFn: ({uri, cid, via}) => {
|
||||
let ownProfile: AppBskyActorDefs.ProfileViewDetailed | undefined
|
||||
let ownProfile: app.bsky.actor.defs.ProfileViewDetailed | undefined
|
||||
if (currentAccount) {
|
||||
ownProfile = findProfileQueryData(queryClient, currentAccount.did)
|
||||
}
|
||||
@@ -231,7 +229,7 @@ function usePostLikeMutation(
|
||||
function usePostUnlikeMutation(
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:unlike']['logContext'],
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
) {
|
||||
const pdsClient = usePdsClient()
|
||||
const ax = useAnalytics()
|
||||
@@ -249,7 +247,7 @@ function usePostUnlikeMutation(
|
||||
}
|
||||
|
||||
export function usePostRepostMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
viaRepost: {uri: string; cid: string} | undefined,
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:repost']['logContext'],
|
||||
@@ -315,12 +313,12 @@ export function usePostRepostMutationQueue(
|
||||
function usePostRepostMutation(
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:repost']['logContext'],
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
) {
|
||||
const pdsClient = usePdsClient()
|
||||
const ax = useAnalytics()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the repost
|
||||
{uri: AtUriString}, // responds with the uri of the repost
|
||||
Error,
|
||||
{uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present
|
||||
>({
|
||||
@@ -343,7 +341,7 @@ function usePostRepostMutation(
|
||||
function usePostUnrepostMutation(
|
||||
feedDescriptor: string | undefined,
|
||||
logContext: Metrics['post:unrepost']['logContext'],
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
) {
|
||||
const pdsClient = usePdsClient()
|
||||
const ax = useAnalytics()
|
||||
@@ -374,7 +372,7 @@ export function usePostDeleteMutation() {
|
||||
}
|
||||
|
||||
export function useThreadMuteMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
post: Shadow<app.bsky.feed.defs.PostView>,
|
||||
rootUri: string,
|
||||
) {
|
||||
const threadMuteMutation = useThreadMuteMutation()
|
||||
|
||||
Reference in New Issue
Block a user