Skip to content

Commit a050eae

Browse files
ascorbicclaude
andauthored
chore(pds): extract invalidRecordError helper in repo.ts (#17)
* feat(pds): load official Bluesky lexicon schemas for validation Replaces empty validator with actual schema validation using official Bluesky lexicon JSON files vendored from the atproto repository. Changes: - Added update-lexicons.sh script to fetch official schemas from GitHub - Vendored 16 lexicon schemas (core, feed, actor, graph, richtext, embed) - Updated validation.ts to load all schemas with proper dependencies - Added 11 Bluesky-specific validation tests (all passing) - Tree-shakeable: only JSON files imported, no large dependencies Schemas loaded: - Core: com.atproto.repo.strongRef, com.atproto.label.defs - Feed: app.bsky.feed.{post, like, repost, threadgate} - Actor: app.bsky.actor.profile - Graph: app.bsky.graph.{follow, block, list, listitem} - Richtext: app.bsky.richtext.facet - Embed: app.bsky.embed.{images, external, record, recordWithMedia} All 19 tests passing (8 validation tests + 11 Bluesky tests). * chore(pds): typing improvements and dependency cleanup - Use LexiconDoc type instead of any in validation.ts - Add vite/client types to tsconfig for import.meta.glob - Format firehose test and add proper sequencer typing - Remove unused echo from update-lexicons script - Remove unused dependencies from lockfile 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(pds): extract invalidRecordError helper in repo.ts Reduces duplication for InvalidRecord error responses across createRecord, putRecord, and applyWrites endpoints. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1e271f0 commit a050eae

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

packages/pds/src/xrpc/repo.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { AtUri, ensureValidDid } from "@atproto/syntax";
33
import { AccountDurableObject } from "../account-do";
44
import { validator } from "../validation";
55

6+
function invalidRecordError(
7+
c: Context<{ Bindings: Env }>,
8+
err: unknown,
9+
prefix?: string,
10+
): Response {
11+
const message = err instanceof Error ? err.message : String(err);
12+
return c.json(
13+
{
14+
error: "InvalidRecord",
15+
message: prefix ? `${prefix}: ${message}` : message,
16+
},
17+
400,
18+
);
19+
}
20+
621
export async function describeRepo(
722
c: Context<{ Bindings: Env }>,
823
accountDO: DurableObjectStub<AccountDurableObject>,
@@ -211,13 +226,7 @@ export async function createRecord(
211226
try {
212227
validator.validateRecord(collection, record);
213228
} catch (err) {
214-
return c.json(
215-
{
216-
error: "InvalidRecord",
217-
message: err instanceof Error ? err.message : String(err),
218-
},
219-
400,
220-
);
229+
return invalidRecordError(c, err);
221230
}
222231

223232
const result = await accountDO.rpcCreateRecord(collection, rkey, record);
@@ -298,13 +307,7 @@ export async function putRecord(
298307
try {
299308
validator.validateRecord(collection, record);
300309
} catch (err) {
301-
return c.json(
302-
{
303-
error: "InvalidRecord",
304-
message: err instanceof Error ? err.message : String(err),
305-
},
306-
400,
307-
);
310+
return invalidRecordError(c, err);
308311
}
309312

310313
try {
@@ -368,16 +371,9 @@ export async function applyWrites(
368371
try {
369372
validator.validateRecord(write.collection, write.value);
370373
} catch (err) {
371-
return c.json(
372-
{
373-
error: "InvalidRecord",
374-
message: `Write ${i}: ${err instanceof Error ? err.message : String(err)}`,
375-
},
376-
400,
377-
);
374+
return invalidRecordError(c, err, `Write ${i}`);
378375
}
379376
}
380-
// Delete operations don't need validation
381377
}
382378

383379
try {

0 commit comments

Comments
 (0)