diff --git a/package.json b/package.json index 8f2aaf6..648c94f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "zod": "^4.3.6" }, "devDependencies": { + "@atproto/lex-json": "^0.0.16", "@types/bun": "^1.3.12", "@typescript/native-preview": "^7.0.0-dev.20260420.1", "oxfmt": "^0.46.0", diff --git a/src/index.ts b/src/index.ts index fad56d5..ed1af43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,13 @@ import type { Loader, LiveLoader, LoaderContext } from "astro/loaders"; -import type { - Client, - Infer, - ListOptions, - GetOptions, - AtIdentifierString, - RecordSchema, - Validator, +import { + type Client, + type Infer, + type ListOptions, + type GetOptions, + type AtIdentifierString, + type RecordSchema, + type Validator, + lexToJson, } from "@atproto/lex"; import { custom, ZodMiniCustom } from "zod/mini"; @@ -110,7 +111,7 @@ export function atLiveLoader( if (!cid) return { error: new ATLoaderError(`No CID found for record: ${uri}`) }; return { id: cid, - data: value, + data: lexToJson(value) as Infer, }; }, loadCollection: async ({ filter }) => { @@ -119,7 +120,7 @@ export function atLiveLoader( if (invalid.length > 0) return { error: new ATLoaderError(`Invalid records: ${JSON.stringify(invalid)}`) }; return { - entries: records.map((r) => ({ data: r.value as Infer, id: r.cid })), + entries: records.map((r) => ({ data: lexToJson(r.value) as Infer, id: r.cid })), } }, }; @@ -181,7 +182,7 @@ export function atLoader( for (const record of records) { const data = await parseData>({ id: record.cid, - data: record.value, + data: lexToJson(record.value) as Infer, }); store.set({ id: record.cid,