(raw: unknown)
| 54 | } |
| 55 | |
| 56 | export function normalizeMemory(raw: unknown): Memory | null { |
| 57 | if (!isRecord(raw)) return null; |
| 58 | const m = raw as RawMemory; |
| 59 | |
| 60 | const id = typeof m.id === 'string' ? m.id : undefined; |
| 61 | const type = typeof m.type === 'string' ? (m.type as MemoryType) : 'decision'; |
| 62 | const category = typeof m.category === 'string' ? (m.category as MemoryCategory) : undefined; |
| 63 | const memory = |
| 64 | typeof m.memory === 'string' |
| 65 | ? m.memory |
| 66 | : typeof m.decision === 'string' |
| 67 | ? m.decision |
| 68 | : undefined; |
| 69 | const reason = typeof m.reason === 'string' ? m.reason : undefined; |
| 70 | const date = typeof m.date === 'string' ? m.date : undefined; |
| 71 | |
| 72 | if (!id || !category || !memory || !reason || !date) return null; |
| 73 | |
| 74 | const source = m.source === 'git' ? ('git' as const) : undefined; |
| 75 | const scope = normalizeMemoryScope(m.scope); |
| 76 | return { |
| 77 | id, |
| 78 | type, |
| 79 | category, |
| 80 | memory, |
| 81 | reason, |
| 82 | date, |
| 83 | ...(source && { source }), |
| 84 | ...(scope && { scope }) |
| 85 | }; |
| 86 | } |
| 87 | |
| 88 | export function normalizeMemories(raw: unknown): Memory[] { |
| 89 | if (!Array.isArray(raw)) return []; |
no test coverage detected