mirror of
https://github.com/supabase/supabase.git
synced 2026-05-24 20:58:45 +08:00
31 lines
960 B
TypeScript
31 lines
960 B
TypeScript
import { constructHeaders, handleError, handleResponse, handleResponseError } from './base'
|
|
import { uuidv4 } from '../../helpers'
|
|
import type { SupaResponse } from 'types/base'
|
|
|
|
/**
|
|
* @deprecated please use patch method from data/fetchers instead
|
|
*/
|
|
export async function patch<T = any>(
|
|
url: string,
|
|
data: { [prop: string]: any },
|
|
options?: { [prop: string]: any }
|
|
): Promise<SupaResponse<T>> {
|
|
const requestId = uuidv4()
|
|
try {
|
|
const { headers: optionHeaders, ...otherOptions } = options ?? {}
|
|
const headers = await constructHeaders(requestId, optionHeaders)
|
|
const response = await fetch(url, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(data),
|
|
referrerPolicy: 'no-referrer-when-downgrade',
|
|
headers,
|
|
...otherOptions,
|
|
})
|
|
|
|
if (!response.ok) return handleResponseError(response, requestId)
|
|
return handleResponse(response, requestId)
|
|
} catch (error) {
|
|
return handleError(error, requestId)
|
|
}
|
|
}
|