From b314b05f065c3ed91ee586a1e8a8b4c3254d4f80 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Wed, 12 Feb 2025 17:14:50 +0800 Subject: [PATCH] Remove unused files from lib/common/fetch --- apps/studio/lib/common/fetch/base.ts | 16 -------- apps/studio/lib/common/fetch/delete.ts | 30 -------------- apps/studio/lib/common/fetch/head.ts | 56 -------------------------- apps/studio/lib/common/fetch/index.ts | 5 --- apps/studio/lib/common/fetch/patch.ts | 30 -------------- apps/studio/lib/common/fetch/put.ts | 31 -------------- 6 files changed, 168 deletions(-) delete mode 100644 apps/studio/lib/common/fetch/delete.ts delete mode 100644 apps/studio/lib/common/fetch/head.ts delete mode 100644 apps/studio/lib/common/fetch/patch.ts delete mode 100644 apps/studio/lib/common/fetch/put.ts diff --git a/apps/studio/lib/common/fetch/base.ts b/apps/studio/lib/common/fetch/base.ts index f9bf3c87aa7..b9c84be30da 100644 --- a/apps/studio/lib/common/fetch/base.ts +++ b/apps/studio/lib/common/fetch/base.ts @@ -30,22 +30,6 @@ export async function handleResponse( } } -export async function handleHeadResponse( - response: Response, - requestId: string, - headers: string[] -): Promise> { - 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 - } -} - export async function handleResponseError( response: Response, requestId: string diff --git a/apps/studio/lib/common/fetch/delete.ts b/apps/studio/lib/common/fetch/delete.ts deleted file mode 100644 index b8da5a117dc..00000000000 --- a/apps/studio/lib/common/fetch/delete.ts +++ /dev/null @@ -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_( - url: string, - data?: { [prop: string]: any }, - options?: { [prop: string]: any } -): Promise> { - 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) - } -} diff --git a/apps/studio/lib/common/fetch/head.ts b/apps/studio/lib/common/fetch/head.ts deleted file mode 100644 index 97d3e514c62..00000000000 --- a/apps/studio/lib/common/fetch/head.ts +++ /dev/null @@ -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( - url: string, - headersToRetrieve: string[], - options?: { [prop: string]: any } -): Promise> { - 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( - url: string, - headersToRetrieve: string[], - options?: { [prop: string]: any } -): Promise> { - 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) - } -} diff --git a/apps/studio/lib/common/fetch/index.ts b/apps/studio/lib/common/fetch/index.ts index e374cad9dc1..372891ff036 100644 --- a/apps/studio/lib/common/fetch/index.ts +++ b/apps/studio/lib/common/fetch/index.ts @@ -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' diff --git a/apps/studio/lib/common/fetch/patch.ts b/apps/studio/lib/common/fetch/patch.ts deleted file mode 100644 index f8b3bb47d4a..00000000000 --- a/apps/studio/lib/common/fetch/patch.ts +++ /dev/null @@ -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( - url: string, - data: { [prop: string]: any }, - options?: { [prop: string]: any } -): Promise> { - 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) - } -} diff --git a/apps/studio/lib/common/fetch/put.ts b/apps/studio/lib/common/fetch/put.ts deleted file mode 100644 index a2439e23d87..00000000000 --- a/apps/studio/lib/common/fetch/put.ts +++ /dev/null @@ -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( - url: string, - data: { [prop: string]: any }, - options?: { [prop: string]: any } -): Promise> { - 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) - } -}