finish phase 3: type-only codemod and zero non-bridge @atproto/api imports
Task 8: codemod repointed 150 namespace-type files to #/lexicons (AppBskyFeedDefs.PostView -> app.bsky.feed.defs.PostView, .Record -> .Main) plus ~105 hand-fixed consumers (composer/video state, DebugMod, Profile, onboarding, dialogs). DM_SERVICE_HEADERS deleted; last chat call sites on the chat client. RichText.tsx flipped to SDK-only. Remaining @atproto/api importers: the three session bridge files, the deliberate dual-world matcher in lib/xrpc-error.ts, and test fixtures. toLex boundary casts are TODO(phase4)-tagged for bridge removal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,37 +1,34 @@
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyGraphFollow,
|
||||
type AppBskyGraphGetFollows,
|
||||
type ComAtprotoRepoApplyWrites,
|
||||
type ComAtprotoRepoStrongRef,
|
||||
} from '@atproto/api'
|
||||
import {TID} from '@atproto/common-web'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
import {
|
||||
type AtIdentifierString,
|
||||
type DidString,
|
||||
toDatetimeString,
|
||||
} from '@atproto/syntax'
|
||||
import chunk from 'lodash.chunk'
|
||||
|
||||
import {until} from '#/lib/async/until'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app, com} from '#/lexicons'
|
||||
|
||||
export async function bulkWriteFollows(
|
||||
agent: SessionAgent,
|
||||
pdsClient: Client,
|
||||
appviewClient: Client,
|
||||
dids: string[],
|
||||
via?: ComAtprotoRepoStrongRef.Main,
|
||||
via?: com.atproto.repo.strongRef.Main,
|
||||
) {
|
||||
const session = agent.session
|
||||
const did = pdsClient.assertDid
|
||||
|
||||
if (!session) {
|
||||
throw new Error(`bulkWriteFollows failed: no session`)
|
||||
}
|
||||
|
||||
const followRecords: $Typed<AppBskyGraphFollow.Record>[] = dids.map(did => {
|
||||
const followRecords: $Typed<app.bsky.graph.follow.Main>[] = dids.map(did => {
|
||||
return {
|
||||
$type: 'app.bsky.graph.follow',
|
||||
subject: did,
|
||||
createdAt: new Date().toISOString(),
|
||||
subject: did as DidString,
|
||||
createdAt: toDatetimeString(new Date()),
|
||||
via,
|
||||
}
|
||||
})
|
||||
|
||||
const followWrites: $Typed<ComAtprotoRepoApplyWrites.Create>[] =
|
||||
const followWrites: $Typed<com.atproto.repo.applyWrites.Create>[] =
|
||||
followRecords.map(r => ({
|
||||
$type: 'com.atproto.repo.applyWrites#create',
|
||||
collection: 'app.bsky.graph.follow',
|
||||
@@ -41,35 +38,35 @@ export async function bulkWriteFollows(
|
||||
|
||||
const chunks = chunk(followWrites, 50)
|
||||
for (const chunk of chunks) {
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: session.did,
|
||||
await pdsClient.call(com.atproto.repo.applyWrites, {
|
||||
repo: did,
|
||||
writes: chunk,
|
||||
})
|
||||
}
|
||||
await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length)
|
||||
await whenFollowsIndexed(appviewClient, did, res => !!res.follows.length)
|
||||
|
||||
const followUris = new Map<string, string>()
|
||||
for (const r of followWrites) {
|
||||
followUris.set(
|
||||
r.value.subject as string,
|
||||
`at://${session.did}/app.bsky.graph.follow/${r.rkey}`,
|
||||
`at://${did}/app.bsky.graph.follow/${r.rkey}`,
|
||||
)
|
||||
}
|
||||
return followUris
|
||||
}
|
||||
|
||||
async function whenFollowsIndexed(
|
||||
agent: SessionAgent,
|
||||
appviewClient: Client,
|
||||
actor: string,
|
||||
fn: (res: AppBskyGraphGetFollows.Response) => boolean,
|
||||
fn: (res: app.bsky.graph.getFollows.$OutputBody) => boolean,
|
||||
) {
|
||||
await until(
|
||||
5, // 5 tries
|
||||
1e3, // 1s delay between tries
|
||||
fn,
|
||||
() =>
|
||||
agent.app.bsky.graph.getFollows({
|
||||
actor,
|
||||
appviewClient.call(app.bsky.graph.getFollows, {
|
||||
actor: actor as AtIdentifierString,
|
||||
limit: 1,
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user