MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / normalizePersistedConfig

Function normalizePersistedConfig

apps/desktop/src/main/vault.ts:332–433  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

330}
331
332function normalizePersistedConfig(value: unknown): PersistedConfig {
333 if (!value || typeof value !== 'object') return { ...DEFAULT_CONFIG }
334 const candidate = value as Partial<PersistedConfig>
335 const zoomFactor =
336 typeof candidate.zoomFactor === 'number' && Number.isFinite(candidate.zoomFactor)
337 ? Math.min(3, Math.max(0.5, Math.round(candidate.zoomFactor * 100) / 100))
338 : DEFAULT_CONFIG.zoomFactor
339 const normalizeProfile = (candidate: unknown): PersistedRemoteWorkspaceProfile | null => {
340 if (!candidate || typeof candidate !== 'object') return null
341 const value = candidate as Record<string, unknown>
342 const baseUrl = typeof value.baseUrl === 'string' ? value.baseUrl.trim() : ''
343 const name = typeof value.name === 'string' ? value.name.trim() : ''
344 if (!baseUrl || !name) return null
345 return {
346 id: typeof value.id === 'string' && value.id.trim() ? value.id : randomUUID(),
347 name,
348 baseUrl,
349 authToken: typeof value.authToken === 'string' ? value.authToken : null,
350 vaultPath: typeof value.vaultPath === 'string' && value.vaultPath.trim() ? value.vaultPath : null,
351 lastConnectedAt:
352 typeof value.lastConnectedAt === 'number' && Number.isFinite(value.lastConnectedAt)
353 ? value.lastConnectedAt
354 : null
355 }
356 }
357 const normalizeLocalVault = (candidate: unknown): PersistedLocalVault | null => {
358 if (!candidate || typeof candidate !== 'object') return null
359 const value = candidate as Record<string, unknown>
360 const rawRoot = typeof value.root === 'string' ? value.root.trim() : ''
361 if (!rawRoot) return null
362 const root = path.resolve(rawRoot)
363 const name =
364 typeof value.name === 'string' && value.name.trim()
365 ? value.name.trim()
366 : path.basename(root)
367 const lastOpenedAt =
368 typeof value.lastOpenedAt === 'number' && Number.isFinite(value.lastOpenedAt)
369 ? value.lastOpenedAt
370 : 0
371 return { root, name, lastOpenedAt }
372 }
373 const legacyRemoteWorkspace =
374 candidate.remoteWorkspace &&
375 typeof candidate.remoteWorkspace === 'object' &&
376 typeof candidate.remoteWorkspace.baseUrl === 'string'
377 ? {
378 baseUrl: candidate.remoteWorkspace.baseUrl,
379 authToken:
380 typeof candidate.remoteWorkspace.authToken === 'string'
381 ? candidate.remoteWorkspace.authToken
382 : null
383 }
384 : null
385 const remoteWorkspaceProfiles = Array.isArray(candidate.remoteWorkspaceProfiles)
386 ? candidate.remoteWorkspaceProfiles
387 .map((entry) => normalizeProfile(entry))
388 .filter((entry): entry is PersistedRemoteWorkspaceProfile => !!entry)
389 : []

Callers 3

readConfigFileFunction · 0.85
sanitizeForPersistFunction · 0.85
updateConfigFunction · 0.85

Calls 3

normalizeProfileFunction · 0.85
normalizeLocalVaultFunction · 0.85
normalizeWindowStateFunction · 0.85

Tested by

no test coverage detected