1- import type {
2- Params ,
3- AnyObject ,
4- Resource ,
5- AnyResource ,
6- } from 'pinejs-client-core' ;
1+ import type { AnyObject , Resource , AnyResource } from 'pinejs-client-core' ;
72import { PinejsClientCore } from 'pinejs-client-core' ;
83export type { PinejsClientCore } from 'pinejs-client-core' ;
94
10- interface BackendParams {
11- /** The browser fetch API implementation or a compatible one */
12- fetch ?: typeof fetch ;
13- }
14-
155export class RequestError extends Error {
166 public code = 'PineClientFetchRequestError' ;
177
@@ -31,21 +21,6 @@ export default class PineFetch<
3121 [ key in string ] : AnyResource ;
3222 } ,
3323> extends PinejsClientCore < Model > {
34- constructor (
35- params : Params ,
36- public backendParams : BackendParams ,
37- ) {
38- super ( params ) ;
39- if (
40- typeof backendParams ?. fetch !== 'function' &&
41- typeof fetch !== 'function'
42- ) {
43- throw new Error (
44- 'No fetch implementation provided and native one not available' ,
45- ) ;
46- }
47- }
48-
4924 async _request ( {
5025 url,
5126 body,
@@ -61,10 +36,7 @@ export default class PineFetch<
6136 ? JSON . stringify ( body )
6237 : body ;
6338
64- // Assign to a variable first, otherwise browser fetch errors in case the context is different.
65- const fetchImplementation = this . backendParams ?. fetch ?? fetch ;
66-
67- const response = await fetchImplementation ( url , {
39+ const response = await fetch ( url , {
6840 ...options ,
6941 body : normalizedBody ,
7042 } ) ;
@@ -78,6 +50,6 @@ export default class PineFetch<
7850 }
7951 throw new RequestError ( responseBody , response . status , response . headers ) ;
8052 }
81- return response . json ( ) ;
53+ return await response . json ( ) ;
8254 }
8355}
0 commit comments