MCPcopy Index your code
hub / github.com/massCodeIO/massCode / createUniqueFolder

Function createUniqueFolder

src/main/http/import/persist.ts:34–58  ·  view source on GitHub ↗
(
  storage: HttpStorageProvider,
  name: string,
  parentId: number | null,
)

Source from the content-addressed store, hash-verified

32}
33
34function createUniqueFolder(
35 storage: HttpStorageProvider,
36 name: string,
37 parentId: number | null,
38): { id: number, name: string } {
39 const baseName = normalizeImportName(name, 'Imported')
40
41 for (let suffix = 0; suffix <= 10_000; suffix += 1) {
42 const candidate = withSuffix(baseName, suffix)
43 try {
44 const { id } = storage.folders.createFolder({
45 name: candidate,
46 parentId,
47 })
48 return { id, name: candidate }
49 }
50 catch (error) {
51 if (parseStorageError(error)?.code !== 'NAME_CONFLICT') {
52 throw error
53 }
54 }
55 }
56
57 throw new Error('NAME_CONFLICT:Cannot generate unique folder name')
58}
59
60function createUniqueRequest(
61 storage: HttpStorageProvider,

Callers 1

persistHttpImportResultFunction · 0.85

Calls 3

normalizeImportNameFunction · 0.90
withSuffixFunction · 0.85
parseStorageErrorFunction · 0.70

Tested by

no test coverage detected