···
} from "@/lib/types/atproto";
-
import { atprotoHandleSchema } from "@/lib/types/atproto";
import { comAtprotoRepoGetRecordResponseSchema } from "@/lib/types/lexicon/com.atproto.repo.getRecord";
import type { Result } from "@/lib/utils/result";
import type { DidDocumentResolver } from "@atcute/identity-resolver";
···
} from "@atcute/identity-resolver";
export const getRecordFromAtUri = async ({
···
result += rKey ? `/${rKey}` : "";
···
} from "@/lib/types/atproto";
+
} from "@/lib/types/atproto";
import { comAtprotoRepoGetRecordResponseSchema } from "@/lib/types/lexicon/com.atproto.repo.getRecord";
import type { Result } from "@/lib/utils/result";
import type { DidDocumentResolver } from "@atcute/identity-resolver";
···
} from "@atcute/identity-resolver";
+
import { z } from "zod";
export const getRecordFromAtUri = async ({
···
result += rKey ? `/${rKey}` : "";
+
export const stringToAtUri = (str: string): Result<AtUri, unknown> => {
+
const isValidAtUri = atUriRegexp.test(str);
+
error: { message: "Input string was not a valid at:// URI" },
+
const fragments = str.split("/");
+
if (fragments.length <= 2)
+
error: { message: "Input string was not a valid at:// URI." },
+
success: authorityParseSuccess,
+
error: authorityParseError,
+
} = atUriAuthoritySchema.safeParse(fragments[1]);
+
if (!authorityParseSuccess)
+
"Input at:// URI was a valid shape, but somehow could not parse the first fragment as a valid authority.",
+
details: z.treeifyError(authorityParseError),
+
success: nsidParseSuccess,
+
} = nsidSchema.safeParse(fragments[2]);
+
if (fragments[2] && !nsidParseSuccess)
+
"Input at:// URI was a valid shape and had a second fragment, but was somehow not a valid NSID.",
+
details: z.treeifyError(nsidParseError),
+
authority: authorityParsed,
+
collection: nsidParsed,