(raw: unknown)
| 7 | * before processing and return `null` for anything unexpected. |
| 8 | */ |
| 9 | export function parseWebviewToExtensionMessage(raw: unknown): WebviewToExtensionMessage | null { |
| 10 | if (!raw || typeof raw !== "object" || Array.isArray(raw)) { |
| 11 | return null; |
| 12 | } |
| 13 | |
| 14 | const record = raw as Record<string, unknown>; |
| 15 | const type = record.type; |
| 16 | if (typeof type !== "string") { |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | switch (type) { |
| 21 | case "ready": |
| 22 | case "refreshWorkspaces": |
| 23 | case "configureConnection": |
| 24 | return { type }; |
| 25 | |
| 26 | case "selectWorkspace": { |
| 27 | const workspaceId = record.workspaceId; |
| 28 | if (typeof workspaceId !== "string" && workspaceId !== null) { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | return { type, workspaceId }; |
| 33 | } |
| 34 | |
| 35 | case "openWorkspace": { |
| 36 | if (typeof record.workspaceId !== "string") { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | return { type, workspaceId: record.workspaceId }; |
| 41 | } |
| 42 | |
| 43 | case "debugLog": { |
| 44 | if (typeof record.message !== "string") { |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | return { type, message: record.message, data: record.data }; |
| 49 | } |
| 50 | |
| 51 | case "copyDebugLog": { |
| 52 | if (typeof record.text !== "string") { |
| 53 | return null; |
| 54 | } |
| 55 | |
| 56 | return { type, text: record.text }; |
| 57 | } |
| 58 | |
| 59 | case "orpcCall": { |
| 60 | if (typeof record.requestId !== "string") { |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | const path = record.path; |
| 65 | if (!Array.isArray(path) || !path.every((segment) => typeof segment === "string")) { |
| 66 | return null; |
no outgoing calls
no test coverage detected