@@ -81,7 +81,6 @@ export interface KuboCASOptions {
8181 maxRetries ?: number ;
8282 initialDelay ?: number ; // seconds
8383 backoffFactor ?: number ; // >= 1.0
84- fetchImpl ?: typeof fetch ; // custom fetch if desired
8584}
8685
8786export class KuboCAS extends ContentAddressedStore {
@@ -98,7 +97,6 @@ export class KuboCAS extends ContentAddressedStore {
9897 private readonly maxRetries : number ;
9998 private readonly initialDelay : number ;
10099 private readonly backoffFactor : number ;
101- private readonly fetchImpl : typeof fetch ;
102100
103101 constructor ( opts : KuboCASOptions = { } ) {
104102 super ( ) ;
@@ -115,7 +113,6 @@ export class KuboCAS extends ContentAddressedStore {
115113 maxRetries = 3 ,
116114 initialDelay = 1.0 ,
117115 backoffFactor = 2.0 ,
118- fetchImpl = ( globalThis as any ) . fetch ,
119116 } = opts ;
120117
121118 // Validate chunker like Python
@@ -127,12 +124,6 @@ export class KuboCAS extends ContentAddressedStore {
127124 if ( initialDelay <= 0 ) throw new Error ( "initial_delay must be positive" ) ;
128125 if ( backoffFactor < 1.0 ) throw new Error ( "backoff_factor must be >= 1.0" ) ;
129126
130- const fallbackFetch = ( globalThis as any ) ?. fetch ;
131- const candidateFetch = fetchImpl ?? fallbackFetch ;
132- if ( typeof candidateFetch !== "function" ) {
133- throw new Error ( "fetch is not available" ) ;
134- }
135- this . fetchImpl = candidateFetch . bind ( globalThis ) as typeof fetch ;
136127 this . hasher = hasher ;
137128
138129 let gateway = gatewayBaseUrl || KuboCAS . KUBO_DEFAULT_LOCAL_GATEWAY_BASE_URL ;
@@ -198,7 +189,7 @@ export class KuboCAS extends ContentAddressedStore {
198189 // Blob is widely supported; for Node 18+, global Blob exists
199190 form . append ( "file" , new Blob ( [ data ] ) ) ;
200191
201- const res = await this . fetchImpl ( this . rpcUrl , {
192+ const res = await fetch ( this . rpcUrl , {
202193 method : "POST" ,
203194 headers : this . buildHeaders ( ) ,
204195 body : form ,
@@ -244,7 +235,7 @@ export class KuboCAS extends ContentAddressedStore {
244235
245236 return this . sem . withPermit ( async ( ) => {
246237 return this . retrying ( async ( ) => {
247- const res = await this . fetchImpl ( url , {
238+ const res = await fetch ( url , {
248239 method : "GET" ,
249240 headers : this . buildHeaders ( headers ) ,
250241 } ) ;
@@ -262,15 +253,15 @@ export class KuboCAS extends ContentAddressedStore {
262253 async pin_cid ( cid : CID , targetRpc = KuboCAS . KUBO_DEFAULT_LOCAL_RPC_BASE_URL ) : Promise < void > {
263254 const url = `${ targetRpc . replace ( / \/ + $ / , "" ) } /api/v0/pin/add?recursive=true&arg=${ encodeURIComponent ( String ( cid ) ) } ` ;
264255 await this . sem . withPermit ( async ( ) => {
265- const res = await this . fetchImpl ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
256+ const res = await fetch ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
266257 if ( ! res . ok ) throw new Error ( `pin/add failed: ${ res . status } ${ res . statusText } ` ) ;
267258 } ) ;
268259 }
269260
270261 async unpin_cid ( cid : CID , targetRpc = KuboCAS . KUBO_DEFAULT_LOCAL_RPC_BASE_URL ) : Promise < void > {
271262 const url = `${ targetRpc . replace ( / \/ + $ / , "" ) } /api/v0/pin/rm?recursive=true&arg=${ encodeURIComponent ( String ( cid ) ) } ` ;
272263 await this . sem . withPermit ( async ( ) => {
273- const res = await this . fetchImpl ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
264+ const res = await fetch ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
274265 if ( ! res . ok ) throw new Error ( `pin/rm failed: ${ res . status } ${ res . statusText } ` ) ;
275266 } ) ;
276267 }
@@ -281,7 +272,7 @@ export class KuboCAS extends ContentAddressedStore {
281272 params . append ( "arg" , String ( oldId ) ) ;
282273 params . append ( "arg" , String ( newId ) ) ;
283274 await this . sem . withPermit ( async ( ) => {
284- const res = await this . fetchImpl ( `${ url } ?${ params . toString ( ) } ` , {
275+ const res = await fetch ( `${ url } ?${ params . toString ( ) } ` , {
285276 method : "POST" ,
286277 headers : this . buildHeaders ( ) ,
287278 } ) ;
@@ -292,7 +283,7 @@ export class KuboCAS extends ContentAddressedStore {
292283 async pin_ls ( targetRpc = KuboCAS . KUBO_DEFAULT_LOCAL_RPC_BASE_URL ) : Promise < Array < Record < string , unknown > > > {
293284 const url = `${ targetRpc . replace ( / \/ + $ / , "" ) } /api/v0/pin/ls` ;
294285 return this . sem . withPermit ( async ( ) => {
295- const res = await this . fetchImpl ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
286+ const res = await fetch ( url , { method : "POST" , headers : this . buildHeaders ( ) } ) ;
296287 if ( ! res . ok ) throw new Error ( `pin/ls failed: ${ res . status } ${ res . statusText } ` ) ;
297288 const json = await res . json ( ) as { Keys ?: Record < string , { Type : string } > } ;
298289 // Kubo returns { Keys: { "<cid>": { Type: "recursive" } , ... } }
0 commit comments