···
3
+
atUriAuthoritySchema,
···
} from "@atcute/identity-resolver";
21
+
import z from "zod";
export const getRecordFromAtUri = async ({
···
return { ok: false, error: err };
121
+
export const atUriRegexp =
122
+
/^at:\/\/([a-zA-Z0-9._:%-]+)(?:\/([a-zA-Z0-9-.]+)(?:\/([a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(?:#(\/[a-zA-Z0-9._~:@!$&%')(*+,;=\-[\]/\\]*))?$/;
124
+
export const stringToAtUri = (str: string): Result<AtUri, unknown> => {
125
+
const isValidAtUri = atUriRegexp.test(str);
129
+
error: { message: "Input string was not a valid at:// URI" },
132
+
const fragments = str.split("/");
133
+
if (fragments.length <= 2)
136
+
error: { message: "Input string was not a valid at:// URI." },
140
+
success: authorityParseSuccess,
141
+
error: authorityParseError,
142
+
data: authorityParsed,
143
+
} = atUriAuthoritySchema.safeParse(fragments[1]);
144
+
if (!authorityParseSuccess)
149
+
"Input at:// URI was a valid shape, but somehow could not parse the first fragment as a valid authority.",
150
+
details: z.treeifyError(authorityParseError),
155
+
success: nsidParseSuccess,
156
+
error: nsidParseError,
158
+
} = nsidSchema.safeParse(fragments[2]);
159
+
if (fragments[2] && !nsidParseSuccess)
164
+
"Input at:// URI was a valid shape and had a second fragment, but was somehow not a valid NSID.",
165
+
details: z.treeifyError(nsidParseError),
172
+
authority: authorityParsed,
173
+
collection: nsidParsed,
174
+
rKey: fragments[3],