a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(repo): improve mst key splitting

Mary 9ccc7ef6 569bc9ab

+17 -2
+5
.changeset/five-cameras-scream.md
··· 1 + --- 2 + '@atcute/repo': patch 3 + --- 4 + 5 + improve mst key splitting
+2 -1
packages/utilities/repo/lib/reader.ts
··· 8 8 9 9 import { isCommit, RepoEntry } from './types.ts'; 10 10 import { assert } from './utils.ts'; 11 + import { parseMstKey } from './utils/mst.ts'; 11 12 12 13 /** @internal */ 13 14 type EntryMap = Map<string, CarEntry>; ··· 35 36 const commit = readEntry(map, roots[0], isCommit); 36 37 37 38 for (const { key, cid } of walkMstEntries(map, commit.data)) { 38 - const [collection, rkey] = key.split('/'); 39 + const { collection, rkey } = parseMstKey(key); 39 40 40 41 const carEntry = map.get(cid.$link); 41 42 assert(carEntry != null, `cid not found in blockmap; cid=${cid}`);
+2 -1
packages/utilities/repo/lib/streamed-reader.ts
··· 7 7 8 8 import { isCommit, RepoEntry } from './types.ts'; 9 9 import { assert } from './utils.ts'; 10 + import { parseMstKey } from './utils/mst.ts'; 10 11 import Queue from './utils/queue.ts'; 11 12 12 13 type EntryMeta = { t: 0 } | { t: 1 } | { t: 2; k: string }; ··· 178 179 break; 179 180 } 180 181 case 2: { 181 - const [collection, rkey] = meta.k.split('/'); 182 + const { collection, rkey } = parseMstKey(meta.k); 182 183 183 184 yield new RepoEntry(collection, rkey, CID.toCidLink(entry.cid), entry); 184 185 break;
+8
packages/utilities/repo/lib/utils/mst.ts
··· 1 + import { assert } from '../utils.ts'; 2 + 3 + export const parseMstKey = (key: string): { collection: string; rkey: string } => { 4 + const slash = key.indexOf('/'); 5 + assert(slash !== -1, `invalid mst key; key=${key}`); 6 + 7 + return { collection: key.slice(0, slash), rkey: key.slice(slash + 1) }; 8 + };