[SDK] Remove @atproto/api (#11386)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type AtUriString} from '@atproto/syntax'
|
||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
@@ -13,7 +12,7 @@ import {useAppviewClient} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
|
||||
type MutationArgs =
|
||||
| {action: 'create'; post: AppBskyFeedDefs.PostView}
|
||||
| {action: 'create'; post: app.bsky.feed.defs.PostView}
|
||||
| {
|
||||
action: 'delete'
|
||||
/**
|
||||
@@ -32,7 +31,7 @@ export function useBookmarkMutation() {
|
||||
if (args.action === 'create') {
|
||||
updatePostShadow(qc, args.post.uri, {bookmarked: true})
|
||||
await client.call(app.bsky.bookmark.createBookmark, {
|
||||
uri: args.post.uri as AtUriString,
|
||||
uri: args.post.uri,
|
||||
cid: args.post.cid,
|
||||
})
|
||||
} else if (args.action === 'delete') {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {type $Typed, AppBskyFeedDefs, AtUri} from '@atproto/api'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {
|
||||
type InfiniteData,
|
||||
type QueryClient,
|
||||
@@ -57,7 +58,7 @@ export async function truncateAndInvalidate(qc: QueryClient) {
|
||||
|
||||
export async function optimisticallySaveBookmark(
|
||||
qc: QueryClient,
|
||||
post: AppBskyFeedDefs.PostView,
|
||||
post: app.bsky.feed.defs.PostView,
|
||||
) {
|
||||
qc.setQueriesData<InfiniteData<app.bsky.bookmark.getBookmarks.$OutputBody>>(
|
||||
{
|
||||
@@ -71,9 +72,9 @@ export async function optimisticallySaveBookmark(
|
||||
if (index === 0) {
|
||||
post.$type = 'app.bsky.feed.defs#postView'
|
||||
/*
|
||||
* The optimistic entry is synthesized from an `@atproto/api`
|
||||
* `PostView`, whose string fields are unbranded, so it is asserted
|
||||
* to the vendored view type the query data is now keyed on.
|
||||
* The optimistic entry is synthesized with unbranded string
|
||||
* fields, so it is asserted to the generated view type the query
|
||||
* data is keyed on.
|
||||
*/
|
||||
const bookmark = {
|
||||
createdAt: new Date().toISOString(),
|
||||
@@ -81,7 +82,7 @@ export async function optimisticallySaveBookmark(
|
||||
uri: post.uri,
|
||||
cid: post.cid,
|
||||
},
|
||||
item: post as $Typed<AppBskyFeedDefs.PostView>,
|
||||
item: post as $Typed<app.bsky.feed.defs.PostView>,
|
||||
} as unknown as app.bsky.bookmark.defs.BookmarkView
|
||||
return {
|
||||
...page,
|
||||
@@ -121,7 +122,7 @@ export async function optimisticallyDeleteBookmark(
|
||||
export function* findAllPostsInQueryData(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
): Generator<AppBskyFeedDefs.PostView, undefined> {
|
||||
): Generator<app.bsky.feed.defs.PostView, undefined> {
|
||||
const queryDatas = queryClient.getQueriesData<
|
||||
InfiniteData<app.bsky.bookmark.getBookmarks.$OutputBody>
|
||||
>({
|
||||
@@ -135,13 +136,7 @@ export function* findAllPostsInQueryData(
|
||||
}
|
||||
for (const page of queryData?.pages) {
|
||||
for (const bookmark of page.bookmarks) {
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyFeedDefs.PostView>(
|
||||
bookmark.item,
|
||||
AppBskyFeedDefs.isPostView,
|
||||
)
|
||||
)
|
||||
continue
|
||||
if (!bsky.isType(app.bsky.feed.defs.postView, bookmark.item)) continue
|
||||
|
||||
if (didOrHandleUriMatches(atUri, bookmark.item)) {
|
||||
yield bookmark.item
|
||||
|
||||
Reference in New Issue
Block a user