mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Drops the remaining Next-era shims and aliases that only existed for the dual runtime (FE-3106). Part 14 of the stack. **Depends on:** #53222 **Changed:** - ~45 files – import Sentry from `@sentry/react` directly instead of the aliased `@sentry/nextjs` - `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the TanStack `useBlocker` implementation (previously swapped in by a Vite alias) - `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router` → `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`) for the exempt-route and last-visited checks - `hooks/misc/withAuth.tsx` – no `getLayout` forwarding - `TemplateEditor.test.tsx` – renders inside a router for the unsaved-changes blocker **Removed:** - `compat/sentry-nextjs.ts` and its Vite alias, the `usePreventNavigationOnUnsavedChanges` alias and Next hook, `types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency The `compat/next/*` shims for `link`, `router`, `head`, `image`, `navigation`, `dynamic` and `script` stay: about 300 components outside `routes/**` still import them. Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Trigger an error (e.g. a failing query) – it reaches Sentry as before - Edit an email template or edge function and navigate away – the unsaved-changes prompt appears - Open an org you don't belong to – toast and redirect home; open a SQL snippet, leave and come back – last snippet is restored --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import * as Sentry from '@sentry/react'
|
|
|
|
import { constructHeaders } from '../apiHelpers'
|
|
import { databaseErrorSchema, PgMetaDatabaseError, WrappedResult } from './types'
|
|
import { assertSelfHosted, encryptString, getConnectionString } from './util'
|
|
import { PG_META_URL } from '@/lib/constants/index'
|
|
|
|
export type QueryOptions = {
|
|
query: string
|
|
parameters?: unknown[]
|
|
readOnly?: boolean
|
|
headers?: HeadersInit
|
|
}
|
|
|
|
/**
|
|
* Executes a SQL query against the self-hosted Postgres instance via pg-meta service.
|
|
*
|
|
* _Only call this from server-side self-hosted code._
|
|
*/
|
|
export async function executeQuery<T = unknown>({
|
|
query,
|
|
parameters,
|
|
readOnly = false,
|
|
headers,
|
|
}: QueryOptions): Promise<WrappedResult<T[]>> {
|
|
assertSelfHosted()
|
|
|
|
const connectionString = getConnectionString({ readOnly })
|
|
const connectionStringEncrypted = encryptString(connectionString)
|
|
|
|
const requestBody: { query: string; parameters?: unknown[] } = { query }
|
|
if (parameters !== undefined) {
|
|
requestBody.parameters = parameters
|
|
}
|
|
|
|
return await Sentry.startSpan({ name: 'pg-meta.query', op: 'db.query' }, async (span) => {
|
|
const response = await fetch(`${PG_META_URL}/query`, {
|
|
method: 'POST',
|
|
headers: constructHeaders({
|
|
...headers,
|
|
'Content-Type': 'application/json',
|
|
'x-connection-encrypted': connectionStringEncrypted,
|
|
}),
|
|
body: JSON.stringify(requestBody),
|
|
})
|
|
|
|
try {
|
|
const result = await response.json()
|
|
|
|
if (!response.ok) {
|
|
const { message, code, formattedError } = databaseErrorSchema.parse(result)
|
|
span.setAttribute('db.error', 1)
|
|
span.setAttribute('db.status_code', response.status)
|
|
const error = new PgMetaDatabaseError(message, code, response.status, formattedError)
|
|
return { data: undefined, error }
|
|
}
|
|
|
|
span.setAttribute('db.status_code', response.status)
|
|
return { data: result, error: undefined }
|
|
} catch (error) {
|
|
span.setAttribute('db.error', 1)
|
|
if (error instanceof Error) {
|
|
return { data: undefined, error }
|
|
}
|
|
throw error
|
|
}
|
|
})
|
|
}
|