mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
Functions page on self-hosted differs from Platform Adds the possibility to see function details page in Self-Host version. ## Summary by CodeRabbit * **New Features** * Edge function detail lookup added for self‑hosted deployments (new retrieval endpoint & store method). * Consistent navigation to function pages from the functions list. * **Improvements** * UI tabs, download, and test controls adapt to deployment type. * Region, JWT verification, local development, and delete controls shown only on the platform. * Edit/save/delete controls enable/disable correctly based on deployment and permissions. * Function details load reliably across deployments.
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import type { Dirent } from 'node:fs'
|
|
import { readdir, stat } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
import { FunctionArtifact } from './types'
|
|
|
|
export class FileSystemFunctionsArtifactStore {
|
|
constructor(private folderPath: string) {}
|
|
|
|
async getFunctions(): Promise<FunctionArtifact[]> {
|
|
const dirEntries = await readdir(this.folderPath, { withFileTypes: true })
|
|
|
|
const functionsFolders = dirEntries.filter((dir) => dir.isDirectory() && dir.name !== 'main')
|
|
const functionsArtifacts = await Promise.all(
|
|
functionsFolders.map(parseFolderToFunctionArtifact)
|
|
)
|
|
|
|
return functionsArtifacts.filter((f) => f !== undefined)
|
|
}
|
|
|
|
async getFunctionBySlug(slug: string): Promise<FunctionArtifact | undefined> {
|
|
const dirEntries = await readdir(this.folderPath, { withFileTypes: true })
|
|
|
|
const functionFolder = dirEntries.find(
|
|
(dir) => dir.isDirectory() && dir.name !== 'main' && dir.name === slug
|
|
)
|
|
if (!functionFolder) return
|
|
|
|
return parseFolderToFunctionArtifact(functionFolder)
|
|
}
|
|
}
|
|
|
|
async function parseFolderToFunctionArtifact(
|
|
folder: Dirent
|
|
): Promise<FunctionArtifact | undefined> {
|
|
const folderPath = path.join(folder.parentPath, folder.name)
|
|
const files = await readdir(folderPath, { withFileTypes: true })
|
|
const entrypoint = files.find((file) => file.isFile() && file.name.startsWith('index'))
|
|
|
|
if (!entrypoint) return
|
|
|
|
const entrypointPath = path.join(folderPath, entrypoint.name)
|
|
const entrypointStat = await stat(entrypointPath)
|
|
|
|
return {
|
|
slug: folder.name,
|
|
entrypoint_path: pathToFileURL(entrypointPath).href,
|
|
created_at: entrypointStat.birthtimeMs,
|
|
updated_at: entrypointStat.mtimeMs,
|
|
}
|
|
}
|