| 36 | } |
| 37 | |
| 38 | export function patchFile(raw: unknown): ApplyPatchFile | undefined { |
| 39 | if (!raw || typeof raw !== "object") return |
| 40 | |
| 41 | const value = raw as Raw |
| 42 | const type = kind(value.type) |
| 43 | const filePath = typeof value.filePath === "string" ? value.filePath : undefined |
| 44 | const relativePath = typeof value.relativePath === "string" ? value.relativePath : filePath |
| 45 | const patch = typeof value.patch === "string" ? value.patch : typeof value.diff === "string" ? value.diff : undefined |
| 46 | const before = typeof value.before === "string" ? value.before : undefined |
| 47 | const after = typeof value.after === "string" ? value.after : undefined |
| 48 | |
| 49 | if (!type || !filePath || !relativePath) return |
| 50 | if (!patch && before === undefined && after === undefined) return |
| 51 | |
| 52 | const additions = typeof value.additions === "number" ? value.additions : 0 |
| 53 | const deletions = typeof value.deletions === "number" ? value.deletions : 0 |
| 54 | const movePath = typeof value.movePath === "string" ? value.movePath : undefined |
| 55 | |
| 56 | return { |
| 57 | filePath, |
| 58 | relativePath, |
| 59 | type, |
| 60 | additions, |
| 61 | deletions, |
| 62 | movePath, |
| 63 | view: normalize({ |
| 64 | file: relativePath, |
| 65 | patch, |
| 66 | before, |
| 67 | after, |
| 68 | additions, |
| 69 | deletions, |
| 70 | status: status(type), |
| 71 | }), |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | export function patchFiles(raw: unknown) { |
| 76 | if (!Array.isArray(raw)) return [] |