MCPcopy
hub / github.com/toeverything/AFFiNE / extractRootDocPagesMeta

Function extractRootDocPagesMeta

tools/doc-diff/src/rootdoc.ts:12–65  ·  view source on GitHub ↗
(rootDoc: Doc)

Source from the content-addressed store, hash-verified

10};
11
12export function extractRootDocPagesMeta(rootDoc: Doc): RootDocMetaExtract {
13 const recordsById = new Map<string, KeyedRecord>();
14 const duplicateIds: string[] = [];
15
16 const meta = rootDoc.getMap('meta');
17 const pages = meta.get('pages');
18 const entries =
19 pages instanceof YArray
20 ? pages.toArray()
21 : Array.isArray(pages)
22 ? pages
23 : null;
24 if (!entries) {
25 return { recordsById, duplicateIds };
26 }
27
28 for (const entry of entries) {
29 let id: string | null = null;
30 if (entry instanceof YMap) {
31 const idRaw = entry.get('id');
32 id =
33 typeof idRaw === 'string'
34 ? idRaw
35 : typeof idRaw?.toString === 'function'
36 ? idRaw.toString()
37 : null;
38 } else if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
39 const record = entry as Record<string, unknown>;
40 id =
41 typeof record.id === 'string'
42 ? record.id
43 : (record.id?.toString?.() ?? null);
44 }
45
46 if (!id) {
47 continue;
48 }
49
50 if (recordsById.has(id)) {
51 duplicateIds.push(id);
52 }
53
54 const metaPlain = toPlain(entry) as unknown;
55 if (
56 metaPlain &&
57 typeof metaPlain === 'object' &&
58 !Array.isArray(metaPlain)
59 ) {
60 recordsById.set(id, metaPlain as KeyedRecord);
61 }
62 }
63
64 return { recordsById, duplicateIds };
65}
66
67function docLabel(id: string, meta: KeyedRecord) {
68 const title = meta.title;

Callers

nothing calls this directly

Calls 7

toPlainFunction · 0.90
getMethod · 0.65
toStringMethod · 0.65
pushMethod · 0.65
setMethod · 0.65
toArrayMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected