@@ -51,6 +51,7 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
5151 private _include : IncludeScopeHash = { }
5252 private _stats : StatsScope = { }
5353 private _extraParams : any = { }
54+ private _extraFetchOptions : RequestInit = { }
5455
5556 constructor ( model : Constructor < T > | typeof SpraypaintBase ) {
5657 this . model = ( model as any ) as typeof SpraypaintBase
@@ -212,6 +213,18 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
212213 return copy
213214 }
214215
216+ extraFetchOptions ( options : RequestInit ) : Scope < T > {
217+ const copy = this . copy ( )
218+
219+ for ( const key in options ) {
220+ if ( options . hasOwnProperty ( key ) ) {
221+ copy . _extraFetchOptions [ key ] = options [ key ]
222+ }
223+ }
224+
225+ return copy
226+ }
227+
215228 // The `Model` class has a `scope()` method to return the scope for it.
216229 // This method makes it possible for methods to expect either a model or
217230 // a scope and reliably cast them to a scope for use via `scope()`
@@ -247,6 +260,13 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
247260 }
248261 }
249262
263+ fetchOptions ( ) : RequestInit {
264+ return {
265+ ...this . model . fetchOptions ( ) ,
266+ ...this . _extraFetchOptions
267+ }
268+ }
269+
250270 copy ( ) : Scope < T > {
251271 const newScope = cloneDeep ( this )
252272
@@ -317,9 +337,7 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
317337 url = `${ url } ?${ qp } `
318338 }
319339 const request = new Request ( this . model . middlewareStack , this . model . logger )
320- const fetchOpts = this . model . fetchOptions ( )
321-
322- const response = await request . get ( url , fetchOpts )
340+ const response = await request . get ( url , this . fetchOptions ( ) )
323341 refreshJWT ( this . model , response )
324342 return response . jsonPayload
325343 }
0 commit comments