Skip to content

Commit 698e999

Browse files
Update signal parameter to be an object instead
1 parent 496db81 commit 698e999

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/lib/storage/StorageFileApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get, post, remove } from './fetch'
1+
import { FetchParameters, get, post, remove } from './fetch'
22
import { isBrowser } from './helpers'
33
import { FileObject, FileOptions, SearchOptions } from './types'
44

@@ -227,15 +227,15 @@ export class StorageFileApi {
227227
async list(
228228
path?: string,
229229
options?: SearchOptions,
230-
signal?: AbortSignal
230+
parameters?: FetchParameters
231231
): Promise<{ data: FileObject[] | null; error: Error | null }> {
232232
try {
233233
const body = { ...DEFAULT_SEARCH_OPTIONS, ...options, prefix: path || '' }
234234
const data = await post(
235235
`${this.url}/object/list/${this.bucketId}`,
236236
body,
237237
{ headers: this.headers },
238-
signal
238+
parameters
239239
)
240240
return { data, error: null }
241241
} catch (error) {

src/lib/storage/fetch.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export interface FetchOptions {
77
noResolveJson?: boolean
88
}
99

10+
export interface FetchParameters {
11+
signal?: AbortSignal
12+
}
13+
1014
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE'
1115

1216
const _getErrorMessage = (err: any): string =>
@@ -27,7 +31,7 @@ const handleError = (error: any, reject: any) => {
2731
const _getRequestParams = (
2832
method: RequestMethodType,
2933
options?: FetchOptions,
30-
signal?: AbortSignal,
34+
parameters?: FetchParameters,
3135
body?: object
3236
) => {
3337
const params: { [k: string]: any } = { method, headers: options?.headers || {} }
@@ -39,22 +43,18 @@ const _getRequestParams = (
3943
params.headers = { 'Content-Type': 'application/json', ...options?.headers }
4044
params.body = JSON.stringify(body)
4145

42-
if (signal) {
43-
params.signal = signal
44-
}
45-
46-
return params
46+
return { ...params, ...parameters }
4747
}
4848

4949
async function _handleRequest(
5050
method: RequestMethodType,
5151
url: string,
5252
options?: FetchOptions,
53-
signal?: AbortSignal,
53+
parameters?: FetchParameters,
5454
body?: object
5555
): Promise<any> {
5656
return new Promise((resolve, reject) => {
57-
fetch(url, _getRequestParams(method, options, signal, body))
57+
fetch(url, _getRequestParams(method, options, parameters, body))
5858
.then((result) => {
5959
if (!result.ok) throw result
6060
if (options?.noResolveJson) return resolve(result)
@@ -65,33 +65,37 @@ async function _handleRequest(
6565
})
6666
}
6767

68-
export async function get(url: string, options?: FetchOptions, signal?: AbortSignal): Promise<any> {
69-
return _handleRequest('GET', url, options, signal)
68+
export async function get(
69+
url: string,
70+
options?: FetchOptions,
71+
parameters?: FetchParameters
72+
): Promise<any> {
73+
return _handleRequest('GET', url, options, parameters)
7074
}
7175

7276
export async function post(
7377
url: string,
7478
body: object,
7579
options?: FetchOptions,
76-
signal?: AbortSignal
80+
parameters?: FetchParameters
7781
): Promise<any> {
78-
return _handleRequest('POST', url, options, signal, body)
82+
return _handleRequest('POST', url, options, parameters, body)
7983
}
8084

8185
export async function put(
8286
url: string,
8387
body: object,
8488
options?: FetchOptions,
85-
signal?: AbortSignal
89+
parameters?: FetchParameters
8690
): Promise<any> {
87-
return _handleRequest('PUT', url, options, signal, body)
91+
return _handleRequest('PUT', url, options, parameters, body)
8892
}
8993

9094
export async function remove(
9195
url: string,
9296
body: object,
9397
options?: FetchOptions,
94-
signal?: AbortSignal
98+
parameters?: FetchParameters
9599
): Promise<any> {
96-
return _handleRequest('DELETE', url, options, signal, body)
100+
return _handleRequest('DELETE', url, options, parameters, body)
97101
}

0 commit comments

Comments
 (0)