···63636464 return json as LinkResponse<K>;
6565};
6666+6767+// due to the way Bluesky has designed its embeds, quotes can be in two
6868+// different paths, `.embed.record.uri` and `.embed.record.record.uri`.
6969+// Since Constellation can only support one path at a time, here's a function
7070+// that will make this happen really nicely
7171+const MP_CURSOR_RE = /^mp:(\d+)(?::(.+))?$/;
7272+7373+export const getLinksMultiPath = async <K extends keyof Records>({
7474+ uri,
7575+ collection,
7676+ paths,
7777+ limit = 10,
7878+ cursor = null,
7979+}: {
8080+ uri: string;
8181+ collection: K;
8282+ paths: [string, string, ...string[]];
8383+ limit?: number;
8484+ cursor?: string | null;
8585+}): Promise<LinkResponse<K>> => {
8686+ let index = 0;
8787+ let curs: string | null = null;
8888+8989+ const result: LinkResponse<K> = {
9090+ // this will never be anything other than 0 unfortunately,
9191+ // can't make it work across different paths
9292+ total: 0,
9393+ cursor: null,
9494+ linking_records: [],
9595+ };
9696+9797+ if (cursor !== null) {
9898+ const match = MP_CURSOR_RE.exec(cursor);
9999+ if (match === null) {
100100+ return result;
101101+ }
102102+103103+ index = parseInt(match[1], 10);
104104+ curs = match[2] ?? null;
105105+106106+ if (index >= paths.length) {
107107+ return result;
108108+ }
109109+ }
110110+111111+ while (index < paths.length) {
112112+ const data = await getLinks({
113113+ uri: uri,
114114+ collection: collection,
115115+ path: paths[index],
116116+ limit: limit - result.linking_records.length,
117117+ cursor: curs,
118118+ });
119119+120120+ result.linking_records = [...result.linking_records, ...data.linking_records];
121121+122122+ // response returned a cursor, so we're breaking early
123123+ if (data.cursor !== null) {
124124+ result.cursor = `mp:${index}:${data.cursor}`;
125125+ break;
126126+ }
127127+128128+ // we've reached the limit
129129+ if (result.linking_records.length >= limit) {
130130+ break;
131131+ }
132132+133133+ // move to the next path
134134+ index++;
135135+ curs = null;
136136+ result.cursor = index < paths.length ? `mp:${index}` : null;
137137+ }
138138+139139+ return result;
140140+};