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

Function renameDatabase

apps/web/src/bridge/http-bridge.ts:881–899  ·  view source on GitHub ↗
(csvPath: string, newTitle: string)

Source from the content-addressed store, hash-verified

879}
880
881async function renameDatabase(csvPath: string, newTitle: string): Promise<string> {
882 const oldFormDir = formDirFromCsvPath(dbToPosix(csvPath))
883 if (!oldFormDir) throw new Error(`Not a database folder: ${csvPath}`)
884 const parentRel = oldFormDir.includes('/') ? oldFormDir.slice(0, oldFormDir.lastIndexOf('/')) : ''
885 const safeName = (newTitle.trim() || 'Untitled Database').replace(DB_TITLE_BAD, '-')
886 const makeFormDir = (name: string): string =>
887 parentRel ? `${parentRel}/${name}${FORM_DIR_SUFFIX}` : `${name}${FORM_DIR_SUFFIX}`
888 let targetFormDir = makeFormDir(safeName)
889 if (targetFormDir === oldFormDir) return csvPath
890 let n = 2
891 while ((await readFileTextOrNull(csvPathForFormDir(targetFormDir))) !== null) {
892 targetFormDir = makeFormDir(`${safeName} ${n++}`)
893 }
894 const atRoot = await primaryNotesAtRoot()
895 const { folder, subpath: oldSub } = splitVaultPath(oldFormDir, atRoot)
896 const { subpath: newSub } = splitVaultPath(targetFormDir, atRoot)
897 await renameFolder(folder, oldSub, newSub)
898 return csvPathForFormDir(targetFormDir)
899}
900
901async function listDatabases(): Promise<DatabaseSummary[]> {
902 const [folders, atRoot] = await Promise.all([listFolders(), primaryNotesAtRoot()])

Callers

nothing calls this directly

Calls 8

formDirFromCsvPathFunction · 0.90
csvPathForFormDirFunction · 0.90
dbToPosixFunction · 0.85
readFileTextOrNullFunction · 0.85
primaryNotesAtRootFunction · 0.85
splitVaultPathFunction · 0.85
makeFormDirFunction · 0.70
renameFolderFunction · 0.70

Tested by

no test coverage detected