[SDK] Remove @atproto/api (#11386)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:22 +03:00
committed by GitHub
parent 54da80dfb0
commit 9fe0084874
391 changed files with 3130 additions and 3589 deletions
+11 -8
View File
@@ -1,7 +1,7 @@
import {AppBskyFeedDefs} from '@atproto/api'
import {type Client, type XrpcRequestParams} from '@atproto/lex'
import {app} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {type FeedAPI, type FeedAPIResponse} from './types'
type GetAuthorFeedParams = XrpcRequestParams<
@@ -29,7 +29,7 @@ export class AuthorFeedAPI implements FeedAPI {
return params
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const data = await this.client.call(app.bsky.feed.getAuthorFeed, {
...this.params,
limit: 1,
@@ -61,12 +61,15 @@ export class AuthorFeedAPI implements FeedAPI {
}
}
_filter(feed: AppBskyFeedDefs.FeedViewPost[]) {
_filter(feed: app.bsky.feed.defs.FeedViewPost[]) {
if (this.params.filter === 'posts_and_author_threads') {
return feed.filter(post => {
const isReply = post.reply
const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason)
const isPin = AppBskyFeedDefs.isReasonPin(post.reason)
const isRepost = bsky.isType(
app.bsky.feed.defs.reasonRepost,
post.reason,
)
const isPin = bsky.isType(app.bsky.feed.defs.reasonPin, post.reason)
if (!isReply) return true
if (isRepost || isPin) return true
return isReply && isAuthorReplyChain(this.params.actor, post, feed)
@@ -79,15 +82,15 @@ export class AuthorFeedAPI implements FeedAPI {
function isAuthorReplyChain(
actor: string,
post: AppBskyFeedDefs.FeedViewPost,
posts: AppBskyFeedDefs.FeedViewPost[],
post: app.bsky.feed.defs.FeedViewPost,
posts: app.bsky.feed.defs.FeedViewPost[],
): boolean {
// current post is by a different user (shouldn't happen)
if (post.post.author.did !== actor) return false
const replyParent = post.reply?.parent
if (AppBskyFeedDefs.isPostView(replyParent)) {
if (bsky.isType(app.bsky.feed.defs.postView, replyParent)) {
// reply parent is by a different user
if (replyParent.author.did !== actor) return false
+4 -5
View File
@@ -1,5 +1,4 @@
import {type AppBskyFeedDefs, jsonStringToLex} from '@atproto/api'
import {Client, type XrpcRequestParams} from '@atproto/lex'
import {Client, lexParse, type XrpcRequestParams} from '@atproto/lex'
import {
getAppLanguageAsContentLanguage,
@@ -30,7 +29,7 @@ export class CustomFeedAPI implements FeedAPI {
this.userInterests = userInterests
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const contentLangs = getContentLanguages().join(',')
const data = await this.client.call(
app.bsky.feed.getFeed,
@@ -140,7 +139,7 @@ async function loggedOutFetch({
* is asserted here just as the old-world one was.
*/
let data = res.ok
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
: null
if (data?.feed?.length) {
return data
@@ -154,7 +153,7 @@ async function loggedOutFetch({
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
)
data = res.ok
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
: null
if (data?.feed?.length) {
return data
+2 -2
View File
@@ -1,7 +1,7 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {DEMO_FEED} from '#/lib/demo'
import {type app} from '#/lexicons'
import {type FeedAPI, type FeedAPIResponse} from './types'
export class DemoFeedAPI implements FeedAPI {
@@ -11,7 +11,7 @@ export class DemoFeedAPI implements FeedAPI {
this.client = client
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
return DEMO_FEED.feed[0]
}
+1 -2
View File
@@ -1,4 +1,3 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {app} from '#/lexicons'
@@ -11,7 +10,7 @@ export class FollowingFeedAPI implements FeedAPI {
this.client = client
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const data = await this.client.call(app.bsky.feed.getTimeline, {
limit: 1,
})
+10 -5
View File
@@ -1,8 +1,8 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {type AtUriString} from '@atproto/syntax'
import {PROD_DEFAULT_FEED} from '#/lib/constants'
import {type app} from '#/lexicons'
import {CustomFeedAPI} from './custom'
import {FollowingFeedAPI} from './following'
import {type FeedAPI, type FeedAPIResponse} from './types'
@@ -15,7 +15,12 @@ import {type FeedAPI, type FeedAPIResponse} from './types'
// we use this fallback marker post to drive this instead. see Feed.tsx
// for the usage.
// -prf
export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
/*
* A synthetic marker, not a real view: its `uri`/`did`/`indexedAt` are
* deliberately not well-formed, so the literal is asserted rather than branded.
* Only `post.uri` is ever read (see Feed.tsx).
*/
export const FALLBACK_MARKER_POST = {
post: {
uri: 'fallback-marker-post',
cid: 'fake',
@@ -26,7 +31,7 @@ export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
},
indexedAt: new Date().toISOString(),
},
}
} as unknown as app.bsky.feed.defs.FeedViewPost
export class HomeFeedAPI implements FeedAPI {
client: Client
@@ -63,7 +68,7 @@ export class HomeFeedAPI implements FeedAPI {
this.itemCursor = 0
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
if (this.usingDiscover) {
return this.discover.peekLatest()
}
@@ -82,7 +87,7 @@ export class HomeFeedAPI implements FeedAPI {
}
let returnCursor
let posts: AppBskyFeedDefs.FeedViewPost[] = []
let posts: app.bsky.feed.defs.FeedViewPost[] = []
if (!this.usingDiscover) {
const res = await this.following.fetch({cursor, limit})
+1 -2
View File
@@ -1,4 +1,3 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client, type XrpcRequestParams} from '@atproto/lex'
import {app} from '#/lexicons'
@@ -23,7 +22,7 @@ export class LikesFeedAPI implements FeedAPI {
this.params = feedParams
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const data = await this.client.call(app.bsky.feed.getActorLikes, {
...this.params,
limit: 1,
+1 -2
View File
@@ -1,4 +1,3 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client, type XrpcRequestParams} from '@atproto/lex'
import {app} from '#/lexicons'
@@ -23,7 +22,7 @@ export class ListFeedAPI implements FeedAPI {
this.params = feedParams
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const data = await this.client.call(app.bsky.feed.getListFeed, {
...this.params,
limit: 1,
+6 -7
View File
@@ -1,4 +1,3 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {type AtUriString} from '@atproto/syntax'
import shuffle from 'lodash.shuffle'
@@ -28,7 +27,7 @@ const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
*/
type MergeFeedPage = {
cursor?: string
feed: AppBskyFeedDefs.FeedViewPost[]
feed: app.bsky.feed.defs.FeedViewPost[]
} | null
export class MergeFeedAPI implements FeedAPI {
@@ -89,7 +88,7 @@ export class MergeFeedAPI implements FeedAPI {
}
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
const data = await this.client.call(app.bsky.feed.getTimeline, {
limit: 1,
})
@@ -136,7 +135,7 @@ export class MergeFeedAPI implements FeedAPI {
await Promise.all(promises)
// assemble a response by sampling from feeds with content
const posts: AppBskyFeedDefs.FeedViewPost[] = []
const posts: app.bsky.feed.defs.FeedViewPost[] = []
while (posts.length < limit) {
let slice = this.sampleItem()
if (slice[0]) {
@@ -188,7 +187,7 @@ class MergeFeedSource {
feedTuners: FeedTunerFn[]
sourceInfo: ReasonFeedSource | undefined
cursor: string | undefined = undefined
queue: AppBskyFeedDefs.FeedViewPost[] = []
queue: app.bsky.feed.defs.FeedViewPost[] = []
hasMore = true
constructor({
@@ -210,7 +209,7 @@ class MergeFeedSource {
return this.hasMore && this.queue.length === 0
}
take(n: number): AppBskyFeedDefs.FeedViewPost[] {
take(n: number): app.bsky.feed.defs.FeedViewPost[] {
return this.queue.splice(0, n)
}
@@ -327,7 +326,7 @@ class MergeFeedSource_Custom extends MergeFeedSource {
// some custom feeds fail to enforce the pagination limit
// so we manually truncate here
// -prf
let feed: AppBskyFeedDefs.FeedViewPost[] =
let feed: app.bsky.feed.defs.FeedViewPost[] =
limit && data.feed.length > limit
? data.feed.slice(0, limit)
: data.feed
+2 -3
View File
@@ -1,4 +1,3 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type Client, type XrpcRequestParams} from '@atproto/lex'
import {logger} from '#/logger'
@@ -10,7 +9,7 @@ type GetPostsParams = XrpcRequestParams<typeof app.bsky.feed.getPosts.main>
export class PostListFeedAPI implements FeedAPI {
client: Client
params: GetPostsParams
peek: AppBskyFeedDefs.FeedViewPost | null = null
peek: app.bsky.feed.defs.FeedViewPost | null = null
constructor({
client,
@@ -30,7 +29,7 @@ export class PostListFeedAPI implements FeedAPI {
}
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
if (this.peek) return this.peek
throw new Error('Has not fetched yet')
}
+3 -3
View File
@@ -1,12 +1,12 @@
import {type AppBskyFeedDefs} from '@atproto/api'
import {type app} from '#/lexicons'
export interface FeedAPIResponse {
cursor?: string
feed: AppBskyFeedDefs.FeedViewPost[]
feed: app.bsky.feed.defs.FeedViewPost[]
}
export interface FeedAPI {
peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost>
peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost>
fetch({
cursor,
limit,
+1 -1
View File
@@ -1,4 +1,4 @@
import {AtUri} from '@atproto/api'
import {AtUri} from '@atproto/syntax'
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
import {type UsePreferencesQueryResponse} from '#/state/queries/preferences'