mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 06:09:08 +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.7 KiB
TypeScript
65 lines
1.7 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 ExistsNamespaceVariables = {
|
|
catalogUri: string
|
|
warehouse: string
|
|
token: string
|
|
namespace: string
|
|
}
|
|
|
|
async function checkNamespaceExists({
|
|
catalogUri,
|
|
warehouse,
|
|
token,
|
|
namespace,
|
|
}: ExistsNamespaceVariables) {
|
|
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/${namespace}`.replaceAll(/(?<!:)\/\//g, '/')
|
|
|
|
try {
|
|
const response = await fetchHandler(url, {
|
|
headers,
|
|
method: 'HEAD',
|
|
})
|
|
|
|
return response.status === 204
|
|
} catch (error) {
|
|
handleError(error)
|
|
}
|
|
}
|
|
|
|
type IcebergNamespaceExistsData = Awaited<ReturnType<typeof checkNamespaceExists>>
|
|
|
|
export type IcebergNamespaceExistsError = ResponseError
|
|
|
|
export const useIcebergNamespaceExistsQuery = <TData = IcebergNamespaceExistsData>(
|
|
params: ExistsNamespaceVariables,
|
|
{
|
|
...options
|
|
}: UseQueryOptions<IcebergNamespaceExistsData, IcebergNamespaceExistsError, TData> = {}
|
|
) => {
|
|
return useQuery<IcebergNamespaceExistsData, IcebergNamespaceExistsError, TData>(
|
|
storageKeys.icebergNamespace(params.catalogUri, params.warehouse, params.namespace),
|
|
() => checkNamespaceExists(params),
|
|
{ ...options }
|
|
)
|
|
}
|