[SDK] Migrate the gate records to raw repo calls on the pds client (#11378)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:19 +03:00
committed by GitHub
parent 3568cdc42d
commit ca226f589d
11 changed files with 234 additions and 180 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ import {
} from '@atproto/api'
import {TID} from '@atproto/common-web'
import {type Client} from '@atproto/lex'
import {toDatetimeString} from '@atproto/syntax'
import {RichText} from '@bsky.app/sdk/richtext'
import {t} from '@lingui/core/macro'
import {type QueryClient} from '@tanstack/react-query'
@@ -145,7 +146,7 @@ export async function post(
collection: 'app.bsky.feed.threadgate',
rkey: rkey,
value: createThreadgateRecord({
createdAt: now.toISOString(),
createdAt: toDatetimeString(now),
post: uri,
allow: threadgateAllowUISettingToAllowRecordValue(thread.threadgate),
}),
+20
View File
@@ -7,6 +7,8 @@ import {
XrpcResponseError,
} from '@atproto/lex'
import {com} from '#/lexicons'
/**
* Same nsid means `e` was thrown for this method schema, so `e` can be
* treated as an `XrpcResponseError<M>` - which is what lets the SDK's
@@ -57,3 +59,21 @@ export function matchXrpcError<M extends Procedure | Query>(
}
return undefined
}
/**
* Whether `e` is a `com.atproto.repo.getRecord` failure meaning the record is
* absent, so the caller can treat the read as "no record" instead of an error.
*
* `getRecord` declares `RecordNotFound` and both the PDS and the appview throw
* it by that name, so the declared code is the primary check. The message
* substring is kept as a fallback because that is what the pre-SDK call sites
* matched on, and an older PDS in the network may still answer with an
* unnamed error whose message carries the text. Dropping it would silently
* turn a previously-handled absence into a thrown error.
*/
export function isRecordNotFoundError(e: unknown): boolean {
if (matchXrpcError(e, com.atproto.repo.getRecord) === 'RecordNotFound') {
return true
}
return e instanceof Error && e.message.includes('Could not locate record:')
}