Home / Function/ formatFunctionBodyToFiles() — supabase Function Reference

formatFunctionBodyToFiles() — supabase Function Reference

Architecture documentation for the formatFunctionBodyToFiles() function in EdgeFunctions.utils.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  c5700ff2_66d2_9ed0_fc8b_024d4cc74563["formatFunctionBodyToFiles()"]
  6d7786a7_ce8f_60c1_ea38_9688d45a0a97["getBasePath()"]
  c5700ff2_66d2_9ed0_fc8b_024d4cc74563 -->|calls| 6d7786a7_ce8f_60c1_ea38_9688d45a0a97
  style c5700ff2_66d2_9ed0_fc8b_024d4cc74563 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/EdgeFunctions/EdgeFunctions.utils.ts lines 59–106

export const formatFunctionBodyToFiles = ({
  functionBody,
  entrypointPath,
}: {
  functionBody: EdgeFunctionBodyData
  entrypointPath?: string
}) => {
  const entrypoint_path = functionBody.metadata?.deno2_entrypoint_path ?? entrypointPath

  // Set files from API response when available
  if (entrypoint_path) {
    const base_path = getBasePath(
      entrypoint_path,
      functionBody.files.map((file) => file.name)
    )
    const filesWithRelPath = functionBody.files
      // set file paths relative to entrypoint
      .map((file: { name: string; content: string }) => {
        try {
          // if the current file and base path doesn't share a common path,
          // return unmodified file
          const common_path = common([base_path, file.name])
          if (common_path === '' || common_path === '/tmp/') {
            return file
          }

          // prepend "/" to turn relative paths to absolute
          file.name = relative('/' + base_path, '/' + file.name)
          return file
        } catch (e) {
          console.error(e)
          // return unmodified file
          return file
        }
      })

    return filesWithRelPath.map((file: { name: string; content: string }, index: number) => {
      return {
        id: index + 1,
        name: file.name,
        content: file.content,
        state: 'unchanged',
      } as FileData
    })
  }

  return []
}

Subdomains

Frequently Asked Questions

What does formatFunctionBodyToFiles() do?
formatFunctionBodyToFiles() is a function in the supabase codebase.
What does formatFunctionBodyToFiles() call?
formatFunctionBodyToFiles() calls 1 function(s): getBasePath.

Analyze Your Own Codebase

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

Try Supermodel Free