MCPcopy
hub / github.com/coder/mux / sanitizeMetaFile

Function sanitizeMetaFile

src/node/services/memoryMeta.ts:101–119  ·  view source on GitHub ↗

Self-healing parse: anything malformed degrades to "no metadata".

(raw: unknown)

Source from the content-addressed store, hash-verified

99
100/** Self-healing parse: anything malformed degrades to "no metadata". */
101function sanitizeMetaFile(raw: unknown): MemoryMetaFile {
102 if (typeof raw !== "object" || raw === null) return { entries: {} };
103 const entriesRaw = (raw as Record<string, unknown>).entries;
104 if (typeof entriesRaw !== "object" || entriesRaw === null) return { entries: {} };
105 const entries: Record<string, MemoryMetaEntry> = {};
106 for (const [key, value] of Object.entries(entriesRaw)) {
107 if (typeof value !== "object" || value === null) continue;
108 const record = value as Record<string, unknown>;
109 const entry: MemoryMetaEntry = {
110 pinned: record.pinned === true,
111 accessCount: sanitizeCount(record.accessCount),
112 lastAccessedAt: sanitizeTimestamp(record.lastAccessedAt),
113 lastWriteAt: sanitizeTimestamp(record.lastWriteAt),
114 };
115 if (isEmptyEntry(entry)) continue;
116 entries[key] = entry;
117 }
118 return { entries };
119}
120
121export class MemoryMetaService {
122 private readonly metaPath: string;

Callers 1

loadMethod · 0.85

Calls 3

sanitizeCountFunction · 0.85
sanitizeTimestampFunction · 0.85
isEmptyEntryFunction · 0.85

Tested by

no test coverage detected