mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES/NO ## What kind of change does this PR introduce? Bug fix, feature, docs update, ... ## What is the current behavior? Please link any relevant issues here. ## What is the new behavior? Feel free to include screenshots if it includes visual changes. ## Additional context Add any other context or screenshots.
35 lines
941 B
TypeScript
35 lines
941 B
TypeScript
import rawPages from '@/_go'
|
|
import { goPageSchema, type GoPage } from '@/types/go'
|
|
|
|
export function getAllGoPages(): GoPage[] {
|
|
const pages: GoPage[] = []
|
|
const seenSlugs = new Set<string>()
|
|
|
|
for (const raw of rawPages) {
|
|
const result = goPageSchema.safeParse(raw)
|
|
|
|
if (!result.success) {
|
|
throw new Error(
|
|
`Invalid go page definition (slug: "${(raw as any).slug ?? 'unknown'}"):\n${result.error.issues.map((i) => ` - ${i.path.join('.')}: ${i.message}`).join('\n')}`
|
|
)
|
|
}
|
|
|
|
if (seenSlugs.has(result.data.slug)) {
|
|
throw new Error(`Duplicate slug "${result.data.slug}" in _go registry`)
|
|
}
|
|
|
|
seenSlugs.add(result.data.slug)
|
|
pages.push(result.data)
|
|
}
|
|
|
|
return pages
|
|
}
|
|
|
|
export function getAllGoSlugs(): string[] {
|
|
return getAllGoPages().map((p) => p.slug)
|
|
}
|
|
|
|
export function getGoPageBySlug(slug: string): GoPage | undefined {
|
|
return getAllGoPages().find((p) => p.slug === slug)
|
|
}
|