mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 14:19:11 +03:00
* Migrate the CreateBucketModal to use RHF. * Minor fixes for the create bucket modal. * Use the bucket type from the API everywhere. * Improve the types on some functions. Add "skip" mode to FDWCreateMutation. * Expand the CreateBucketModal to explain what will happen when creating an iceberg bucket. * Add a page for iceberg buckets. * Add error states to the iceberg explorer. * Fix the names for the FDWs. * Add a dialog for setting up namespace. * Restructure the new files. * Add a download env button. * Add warning to install the wrappers extension when creating an iceberg bucket. * Add failover details when the FDW is not setup. * Fix a lint error. * Fix a type error. * Minor fixes. * Fix the server name. * Add an icon for iceberg buckets. * Fix the import foreign schema dialog. * Make the setup wrapper button functional. * Fix a bad useMemo dependency. * Small changes to the iceberg bucket page. * Minor fix for the edit wrapper sheet. * Rename the files from kebab-case to PascalCase. * Rename the files again to include Analytic instead of Iceberg. * Rename Iceberg type to Analytic. * Add a switch for creating namespace in the import foreign schema dialog. * Fix the CreateBucketModal. * Fix the delete modal feature. * Fix the S3 keys in the FDW. * Only create a namespace if the switch is true. * Regenerate and fix the types. * Fix the FDW create mutation to handle numbers in the FDW names. * Make the icon smaller. * Check whether the namespace exists, if it doesn't create it. * Hide action from the analytic bucket which don't work. * Invalidate namespaces when creating them. * Add small explanation for the creation of namespaces. * Minor fixes. * Tons of changes to make the namespace feature work. * Fix type errors. * Fix bad import. * Minor copy fixes. * Replace the multiple cards with a table of namespaces. * update copy icon * tiny copy update * Fix the empty state for foreign tables. * Hide the analytics bucket option for self-hosted. * Minor copy fixes. * Expand the CTA on no namespaces state. * More minor fixes. * More small fixes. --------- Co-authored-by: Alaister Young <a@alaisteryoung.com>
134 lines
4.2 KiB
TypeScript
134 lines
4.2 KiB
TypeScript
import { FDW, FDWTable } from 'data/fdw/fdws-query'
|
|
import { WRAPPERS, WRAPPER_HANDLERS } from './Wrappers.constants'
|
|
import type { WrapperMeta } from './Wrappers.types'
|
|
|
|
export const makeValidateRequired = (options: { name: string; required: boolean }[]) => {
|
|
const requiredOptionsSet = new Set(
|
|
options.filter((option) => option.required).map((option) => option.name)
|
|
)
|
|
|
|
const requiredArrayOptionsSet = new Set(
|
|
Array.from(requiredOptionsSet).filter((option) => option.includes('.'))
|
|
)
|
|
const requiredArrayOptions = Array.from(requiredArrayOptionsSet)
|
|
|
|
return (values: any) => {
|
|
const errors = Object.fromEntries(
|
|
Object.entries(values)
|
|
.flatMap(([key, value]) =>
|
|
Array.isArray(value)
|
|
? [[key, value], ...value.map((v, i) => [`${key}.${i}`, v])]
|
|
: [[key, value]]
|
|
)
|
|
.filter(([_key, value]) => {
|
|
const [key, idx] = _key.split('.')
|
|
|
|
if (
|
|
idx !== undefined &&
|
|
requiredOptionsSet.has(key) &&
|
|
Object.keys(value).some((subKey) => requiredArrayOptionsSet.has(`${key}.${subKey}`))
|
|
) {
|
|
const arrayOption = requiredArrayOptions.find((option) => option.startsWith(`${key}.`))
|
|
if (arrayOption) {
|
|
const subKey = arrayOption.split('.')[1]
|
|
return !value[subKey]
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
return requiredOptionsSet.has(key) && (Array.isArray(value) ? value.length < 1 : !value)
|
|
})
|
|
.map(([key]) => {
|
|
if (key === 'table_name') return [key, 'Please provide a name for your table']
|
|
else if (key === 'columns') return [key, 'Please select at least one column']
|
|
else return [key, 'This field is required']
|
|
})
|
|
)
|
|
|
|
return errors
|
|
}
|
|
}
|
|
|
|
export interface FormattedWrapperTable {
|
|
index: number
|
|
columns: { name: string }[]
|
|
is_new_schema: boolean
|
|
schema: string
|
|
schema_name: string
|
|
table_name: string
|
|
object?: string // From options object for Firebase/Stripe
|
|
[key: string]: any // For other dynamic options from table.options
|
|
}
|
|
|
|
export const formatWrapperTables = (
|
|
wrapper: { handler: string; tables?: FDWTable[] },
|
|
wrapperMeta?: WrapperMeta
|
|
): FormattedWrapperTable[] => {
|
|
const tables = wrapper?.tables ?? []
|
|
|
|
return tables.map((table) => {
|
|
let index: number = 0
|
|
const options = Object.fromEntries(table.options.map((option: string) => option.split('=')))
|
|
|
|
switch (wrapper.handler) {
|
|
case WRAPPER_HANDLERS.STRIPE:
|
|
index =
|
|
wrapperMeta?.tables.findIndex(
|
|
(x) => x.options.find((x) => x.name === 'object')?.defaultValue === options.object
|
|
) ?? 0
|
|
break
|
|
case WRAPPER_HANDLERS.FIREBASE:
|
|
if (options.object === 'auth/users') {
|
|
index =
|
|
wrapperMeta?.tables.findIndex((x) =>
|
|
x.options.find((x) => x.defaultValue === 'auth/users')
|
|
) ?? 0
|
|
} else {
|
|
index = wrapperMeta?.tables.findIndex((x) => x.label === 'Firestore Collection') ?? 0
|
|
}
|
|
break
|
|
case WRAPPER_HANDLERS.S3:
|
|
case WRAPPER_HANDLERS.AIRTABLE:
|
|
case WRAPPER_HANDLERS.LOGFLARE:
|
|
case WRAPPER_HANDLERS.BIG_QUERY:
|
|
case WRAPPER_HANDLERS.CLICK_HOUSE:
|
|
break
|
|
}
|
|
|
|
return {
|
|
...options,
|
|
index,
|
|
id: table.id,
|
|
columns: table.columns,
|
|
is_new_schema: false,
|
|
schema: table.schema,
|
|
schema_name: table.schema,
|
|
table_name: table.name,
|
|
}
|
|
})
|
|
}
|
|
|
|
export const convertKVStringArrayToJson = (values: string[]): Record<string, string> => {
|
|
return Object.fromEntries(values.map((value) => value.split('=')))
|
|
}
|
|
|
|
export function wrapperMetaComparator(
|
|
wrapperMeta: Pick<WrapperMeta, 'handlerName' | 'server'>,
|
|
wrapper: FDW | undefined
|
|
) {
|
|
if (wrapperMeta.handlerName === 'wasm_fdw_handler') {
|
|
const serverOptions = convertKVStringArrayToJson(wrapper?.server_options ?? [])
|
|
return (
|
|
wrapperMeta.server.options.find((option) => option.name === 'fdw_package_name')
|
|
?.defaultValue === serverOptions['fdw_package_name']
|
|
)
|
|
}
|
|
|
|
return wrapperMeta.handlerName === wrapper?.handler
|
|
}
|
|
|
|
export function getWrapperMetaForWrapper(wrapper: FDW | undefined) {
|
|
return WRAPPERS.find((w) => wrapperMetaComparator(w, wrapper))
|
|
}
|