Home / Function/ getRegistryItem() — ui Function Reference

getRegistryItem() — ui Function Reference

Architecture documentation for the getRegistryItem() function in registry.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  e7d34ace_4c02_90be_4798_c4bf467583f2["getRegistryItem()"]
  a2cd9f1d_8dbe_d488_4209_1dbd8f522cc1["registry.ts"]
  e7d34ace_4c02_90be_4798_c4bf467583f2 -->|defined in| a2cd9f1d_8dbe_d488_4209_1dbd8f522cc1
  dae1e5ee_7a0a_29a4_4a13_43731ce7b108["getRegistryItems()"]
  dae1e5ee_7a0a_29a4_4a13_43731ce7b108 -->|calls| e7d34ace_4c02_90be_4798_c4bf467583f2
  c5a597ec_26fe_0d08_07fb_4f7ec5884da8["getIndexForStyle()"]
  e7d34ace_4c02_90be_4798_c4bf467583f2 -->|calls| c5a597ec_26fe_0d08_07fb_4f7ec5884da8
  c743b8aa_a35c_4c96_c711_c91af6b33fba["getFileContent()"]
  e7d34ace_4c02_90be_4798_c4bf467583f2 -->|calls| c743b8aa_a35c_4c96_c711_c91af6b33fba
  2f1c60f1_9430_e7e1_db29_3cff5bbb6a4e["fixFilePaths()"]
  e7d34ace_4c02_90be_4798_c4bf467583f2 -->|calls| 2f1c60f1_9430_e7e1_db29_3cff5bbb6a4e
  style e7d34ace_4c02_90be_4798_c4bf467583f2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/lib/registry.ts lines 108–169

export async function getRegistryItem(name: string, styleName: string) {
  const cacheKey = `${styleName}:${name}`

  // Check cache first.
  if (registryCache.has(cacheKey)) {
    return registryCache.get(cacheKey)
  }

  const { index, key } = getIndexForStyle(styleName)
  const item = index[key]?.[name]

  if (!item) {
    registryCache.set(cacheKey, null)
    return null
  }

  // Convert all file paths to object.
  // TODO: remove when we migrate to new registry.
  item.files = item.files.map((file: unknown) =>
    typeof file === "string" ? { path: file } : file
  )

  // Fail early before doing expensive file operations.
  const result = registryItemSchema.safeParse(item)
  if (!result.success) {
    registryCache.set(cacheKey, null)
    return null
  }

  // Read all files in parallel.
  let files: typeof result.data.files = await Promise.all(
    item.files.map(async (file: z.infer<typeof registryItemFileSchema>) => {
      const content = await getFileContent(file)
      const relativePath = path.relative(process.cwd(), file.path)

      return {
        ...file,
        path: relativePath,
        content,
      }
    })
  )

  // Fix file paths.
  files = fixFilePaths(files)

  const parsed = registryItemSchema.safeParse({
    ...result.data,
    files,
  })

  if (!parsed.success) {
    console.error(parsed.error.message)
    registryCache.set(cacheKey, null)
    return null
  }

  // Cache the result.
  registryCache.set(cacheKey, parsed.data)

  return parsed.data
}

Subdomains

Called By

Frequently Asked Questions

What does getRegistryItem() do?
getRegistryItem() is a function in the ui codebase, defined in apps/v4/lib/registry.ts.
Where is getRegistryItem() defined?
getRegistryItem() is defined in apps/v4/lib/registry.ts at line 108.
What does getRegistryItem() call?
getRegistryItem() calls 3 function(s): fixFilePaths, getFileContent, getIndexForStyle.
What calls getRegistryItem()?
getRegistryItem() is called by 1 function(s): getRegistryItems.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free