mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## Problem Studio still called the legacy `/workers` Management API routes and used the old `project_worker` response contract, so Compute instances could not be listed or retrieved after the API rename. The production API type check also detected drift in the v1 and platform declarations. ## Fix - Regenerate the v1, v2, and platform API declarations from the deployed schemas. - Update Studio list and detail queries to `/compute`. - Align typed fixtures with the Compute response schemas and `project_compute_instance` resource type. - Update platform response type references to the generated `_Output` schema names. ## How to test - Run `pnpm api:verify-types`. - Run `pnpm --filter api-types test`. - Run `pnpm --filter studio test data/compute/compute.utils.test.ts "tests/pages/project/[ref]/compute/index.test.tsx"`. - Run `pnpm --filter studio typecheck`. - Run `pnpm --filter common typecheck`. - Run `pnpm --filter studio lint:ratchet`. Expected result: production API declarations are synchronized, and Studio requests the `/compute` list and detail endpoints and renders `project_compute_instance` responses successfully. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Updated API response handling across profiles, backups, notifications, integrations, warehouses, access tokens, payments, and other Studio workflows for more accurate serialized data. * Compute instance pages and queries now use the compute-specific API endpoints and response data. * Improved feature-flag type handling when disabled feature data is unavailable. * **Tests** * Updated automated coverage and fixtures to reflect current compute and API response formats. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import type { components } from '@/data/api'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type BackupRestoreVariables = {
|
|
ref: string
|
|
backup: Backup
|
|
}
|
|
|
|
// [Joshen] Shift to backups RQ query once created
|
|
export type Backup = components['schemas']['BackupsResponse_Output']['backups'][number]
|
|
|
|
export async function restoreFromBackup({ ref, backup }: BackupRestoreVariables) {
|
|
if (backup.isPhysicalBackup) {
|
|
const { data, error } = await post('/platform/database/{ref}/backups/restore-physical', {
|
|
params: { path: { ref } },
|
|
body: { id: backup.id },
|
|
})
|
|
if (error) throw error
|
|
return data
|
|
}
|
|
|
|
const { data, error } = await post('/platform/database/{ref}/backups/restore', {
|
|
params: { path: { ref } },
|
|
body: { id: backup.id },
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type BackupRestoreData = Awaited<ReturnType<typeof restoreFromBackup>>
|
|
|
|
export const useBackupRestoreMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<BackupRestoreData, ResponseError, BackupRestoreVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<BackupRestoreData, ResponseError, BackupRestoreVariables>({
|
|
mutationFn: (vars) => restoreFromBackup(vars),
|
|
async onSuccess(data, variables, context) {
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to restore from backup: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|