Remove unused files from lib/common/fetch

This commit is contained in:
Joshen Lim committed 2025-02-12 17:14:50 +08:00
1 parent 22dd096928
commit b314b05f06
6 files changed
-168

No files matched your search

-16
View File
@@ -30,22 +30,6 @@ export async function handleResponse<T>(
}
}
export async function handleHeadResponse<T>(
response: Response,
requestId: string,
headers: string[]
): Promise<SupaResponse<T>> {
try {
const res = {} as any
headers.forEach((header: string) => {
res[header] = response.headers.get(header)
})
return res
} catch (e) {
return handleError(response, requestId) as SupaResponse<T>
}
}
export async function handleResponseError<T = unknown>(
response: Response,
requestId: string
-30
View File
@@ -1,30 +0,0 @@
import { handleError, handleResponse, handleResponseError, constructHeaders } from './base'
import { uuidv4 } from '../../helpers'
import type { SupaResponse } from 'types/base'
/**
* @deprecated please use del method from data/fetchers instead
*/
export async function delete_<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: 'DELETE',
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)
}
}
-56
View File
@@ -1,56 +0,0 @@
import { handleError, handleHeadResponse, handleResponseError, constructHeaders } from './base'
import { uuidv4 } from '../../helpers'
import type { SupaResponse } from 'types/base'
/**
* @deprecated please use head method from data/fetchers instead
*/
export async function head<T = any>(
url: string,
headersToRetrieve: string[],
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: 'HEAD',
referrerPolicy: 'no-referrer-when-downgrade',
headers,
...otherOptions,
})
if (!response.ok) return handleResponseError(response, requestId)
return handleHeadResponse(response, requestId, headersToRetrieve)
} catch (error) {
return handleError(error, requestId)
}
}
export async function headWithTimeout<T = any>(
url: string,
headersToRetrieve: string[],
options?: { [prop: string]: any }
): Promise<SupaResponse<T>> {
const requestId = uuidv4()
try {
const timeout = options?.timeout ?? 60000
const controller = new AbortController()
const id = setTimeout(() => controller.abort(), timeout)
const { headers: optionHeaders, ...otherOptions } = options ?? {}
const headers = await constructHeaders(requestId, optionHeaders)
const response = await fetch(url, {
method: 'HEAD',
referrerPolicy: 'no-referrer-when-downgrade',
headers,
...otherOptions,
signal: controller.signal,
})
clearTimeout(id)
if (!response.ok) return handleResponseError(response, requestId)
return handleHeadResponse(response, requestId, headersToRetrieve)
} catch (error) {
return handleError(error, requestId)
}
}
-5
View File
@@ -3,14 +3,9 @@
export {
constructHeaders,
handleError,
handleHeadResponse,
handleResponse,
handleResponseError,
isResponseOk,
} from './base'
export { delete_ } from './delete'
export { get, getWithTimeout } from './get'
export { head, headWithTimeout } from './head'
export { patch } from './patch'
export { post } from './post'
export { put } from './put'
-30
View File
@@ -1,30 +0,0 @@
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)
}
}
-31
View File
@@ -1,31 +0,0 @@
import { constructHeaders, handleError, handleResponse, handleResponseError } from './base'
import { uuidv4 } from '../../helpers'
import type { SupaResponse } from 'types/base'
/**
* @deprecated please use post method from data/fetchers instead
*/
export async function put<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: 'PUT',
body: JSON.stringify(data),
credentials: 'include',
referrerPolicy: 'no-referrer-when-downgrade',
headers,
...otherOptions,
})
if (!response.ok) return handleResponseError(response, requestId)
return handleResponse(response, requestId)
} catch (error) {
return handleError(error, requestId)
}
}