mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 10:19:50 -04:00
180ce515f6
* **Chores** * Updated internal module import paths across hook files to use standardized path aliases for improved code consistency and maintainability.
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import { useMemo } from 'react'
|
|
|
|
import {
|
|
parseDbSchemaString,
|
|
useProjectPostgrestConfigQuery,
|
|
} from '@/data/config/project-postgrest-config-query'
|
|
|
|
type UseIsSchemaExposedParams = {
|
|
projectRef?: string
|
|
schemaName?: string
|
|
}
|
|
|
|
type UseIsSchemaExposedOptions = {
|
|
enabled?: boolean
|
|
}
|
|
|
|
export type UseIsSchemaExposedReturn =
|
|
| {
|
|
status: 'pending'
|
|
data: undefined
|
|
isPending: true
|
|
isError: false
|
|
isSuccess: false
|
|
}
|
|
| {
|
|
status: 'error'
|
|
data: undefined
|
|
isPending: false
|
|
isError: true
|
|
isSuccess: false
|
|
}
|
|
| {
|
|
status: 'success'
|
|
data: boolean
|
|
isPending: false
|
|
isError: false
|
|
isSuccess: true
|
|
}
|
|
|
|
export const useIsSchemaExposed = (
|
|
{ projectRef, schemaName }: UseIsSchemaExposedParams,
|
|
{ enabled = true }: UseIsSchemaExposedOptions = {}
|
|
): UseIsSchemaExposedReturn => {
|
|
const shouldQueryConfig = enabled && !!projectRef && !!schemaName
|
|
const {
|
|
data: dbSchemaString,
|
|
isPending: isConfigPending,
|
|
isError: isConfigError,
|
|
} = useProjectPostgrestConfigQuery(
|
|
{ projectRef },
|
|
{ enabled: shouldQueryConfig, select: ({ db_schema }) => db_schema }
|
|
)
|
|
|
|
const exposedSchemas = useMemo(() => {
|
|
if (!dbSchemaString) return []
|
|
return parseDbSchemaString(dbSchemaString)
|
|
}, [dbSchemaString])
|
|
|
|
if (!shouldQueryConfig || isConfigPending) {
|
|
return { status: 'pending', data: undefined, isPending: true, isError: false, isSuccess: false }
|
|
}
|
|
|
|
if (isConfigError) {
|
|
return { status: 'error', data: undefined, isPending: false, isError: true, isSuccess: false }
|
|
}
|
|
|
|
return {
|
|
status: 'success',
|
|
data: exposedSchemas.includes(schemaName),
|
|
isPending: false,
|
|
isError: false,
|
|
isSuccess: true,
|
|
}
|
|
}
|