decentralised message store

feat: more constellation helpers

serenity 63f9f158 03bdc8b1

Changed files
+26 -2
src
+1 -1
src/lib/utils/atproto.ts
···
WellKnownHandleResolver,
} from "@atcute/identity-resolver";
-
export const resolveRecordFromAtUri = async ({
+
export const getRecordFromAtUri = async ({
authority,
collection,
rKey,
+25 -1
src/lib/utils/constellation.ts
···
import { CONSTELLATION_URL } from "@/lib/env";
-
import type { ConstellationBacklinkResponse } from "@/lib/types/constellation";
+
import type { AtUri } from "@/lib/types/atproto";
+
import type {
+
ConstellationBacklink,
+
ConstellationBacklinkResponse,
+
} from "@/lib/types/constellation";
import { constellationBacklinkResponseSchema } from "@/lib/types/constellation";
+
import { getRecordFromAtUri } from "@/lib/utils/atproto";
import type { Result } from "@/lib/utils/result";
import type { ZodError } from "zod";
···
return { ok: false, error };
} else return { ok: true, data: constellationResponse };
};
+
+
export const getPdsRecordFromBacklink = async (
+
backlink: ConstellationBacklink,
+
): Promise<Result<unknown, unknown>> => {
+
const atUri = createAtUriFromBacklink(backlink);
+
const atUriRecordResult = await getRecordFromAtUri(atUri);
+
if (!atUriRecordResult.ok)
+
return { ok: false, error: atUriRecordResult.error };
+
return { ok: true, data: atUriRecordResult.data };
+
};
+
+
export const createAtUriFromBacklink = (
+
backlink: ConstellationBacklink,
+
): Required<AtUri> => {
+
const { did: authority, collection, rkey: rKey } = backlink;
+
+
// @ts-expect-error tempalte literal issues
+
return { authority, collection, rKey };
+
};