mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
* Change the import foreign schema to always create a schema. * Fix the Iceberg wrapper. * Refactor the create wrapper to always create a new schema. * Remove unneeded props. * Smol fixes * Prevent double error toasts * Smol fix * Fix the wrapper creation to include the correct api key. * Fix a bug with the new api keys. * Handle both types of keys when fetching the iceberg namespaces. * Add a field to all wrappers to hold the schema name which can import foreign schema. * sq * When importing a foreign schema, save the schema in a special field. * Fix a type error. * Fix importing foreign schema overriding wrapper server options with unencrypted values * Add comment * Handle duplicate and empty schemas when importing a foreign schema. * Update the copy in the foreign schema wrappers. * Remove unnecessary code. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { UseQueryOptions, useQuery } from '@tanstack/react-query'
|
|
|
|
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { storageKeys } from './keys'
|
|
|
|
type GetNamespacesVariables = {
|
|
catalogUri: string
|
|
warehouse: string
|
|
token: string
|
|
}
|
|
|
|
async function getNamespaces({ catalogUri, warehouse, token }: GetNamespacesVariables) {
|
|
let headers = new Headers()
|
|
// handle both secret key and service role key
|
|
if (token.startsWith('sb_secret_')) {
|
|
headers = await constructHeaders({
|
|
'Content-Type': 'application/json',
|
|
apikey: `${token}`,
|
|
})
|
|
headers.delete('Authorization')
|
|
} else {
|
|
headers = await constructHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${token}`,
|
|
})
|
|
}
|
|
|
|
const url = `${catalogUri}/v1/${warehouse}/namespaces`.replaceAll(/(?<!:)\/\//g, '/')
|
|
|
|
try {
|
|
const response = await fetchHandler(url, {
|
|
headers,
|
|
method: 'GET',
|
|
})
|
|
|
|
const result = await response.json()
|
|
if (result.error) {
|
|
if (result.error.message) {
|
|
throw new Error(result.error.message)
|
|
}
|
|
throw new Error('Failed to get iceberg namespaces')
|
|
}
|
|
const r = result as { namespaces: string[][] }
|
|
return r.namespaces.flat()
|
|
} catch (error) {
|
|
handleError(error)
|
|
}
|
|
}
|
|
|
|
type IcebergNamespacesData = Awaited<ReturnType<typeof getNamespaces>>
|
|
|
|
export type IcebergNamespacesError = ResponseError
|
|
|
|
export const useIcebergNamespacesQuery = <TData = IcebergNamespacesData>(
|
|
params: GetNamespacesVariables,
|
|
{ ...options }: UseQueryOptions<IcebergNamespacesData, IcebergNamespacesError, TData> = {}
|
|
) => {
|
|
return useQuery<IcebergNamespacesData, IcebergNamespacesError, TData>(
|
|
storageKeys.icebergNamespaces(params.catalogUri, params.warehouse),
|
|
() => getNamespaces(params),
|
|
{ ...options }
|
|
)
|
|
}
|