(value: unknown)
| 25 | export const viewPreferencesKey = (project: string): string => `cbm-view-preferences-v1:${encodeURIComponent(project)}`; |
| 26 | |
| 27 | function validated(value: unknown): Readonly<ViewPreferences> { |
| 28 | const row = typeof value === 'object' && value !== null ? value as Record<string, unknown> : {}; |
| 29 | const oneOf = <T extends string | number>(candidate: unknown, choices: readonly T[], fallback: T): T => |
| 30 | choices.includes(candidate as T) ? candidate as T : fallback; |
| 31 | return Object.freeze({ |
| 32 | galaxyNodes: oneOf(row.galaxyNodes, GALAXY_NODE_LIMITS, DEFAULT_VIEW_PREFERENCES.galaxyNodes), |
| 33 | galaxyEdges: oneOf(row.galaxyEdges, GALAXY_EDGE_LIMITS, DEFAULT_VIEW_PREFERENCES.galaxyEdges), |
| 34 | coverageShadow: typeof row.coverageShadow === 'boolean' ? row.coverageShadow : DEFAULT_VIEW_PREFERENCES.coverageShadow, |
| 35 | brickHeight: oneOf(row.brickHeight, ['lines', 'uniform'] as const, DEFAULT_VIEW_PREFERENCES.brickHeight), |
| 36 | brickColor: oneOf(row.brickColor, ['language', 'kind'] as const, DEFAULT_VIEW_PREFERENCES.brickColor), |
| 37 | hotspotGravity: typeof row.hotspotGravity === 'boolean' ? row.hotspotGravity : DEFAULT_VIEW_PREFERENCES.hotspotGravity, |
| 38 | fileVisibility: oneOf(row.fileVisibility, ['all', 'connected', 'unconnected'] as const, DEFAULT_VIEW_PREFERENCES.fileVisibility), |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | function decode(raw: string | null): Readonly<ViewPreferences> { |
| 43 | try { |
no test coverage detected