@@ -51,6 +51,7 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
51
51
private _include : IncludeScopeHash = { }
52
52
private _stats : StatsScope = { }
53
53
private _extraParams : any = { }
54
+ private _extraFetchOptions : RequestInit = { }
54
55
55
56
constructor ( model : Constructor < T > | typeof SpraypaintBase ) {
56
57
this . model = ( model as any ) as typeof SpraypaintBase
@@ -212,6 +213,18 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
212
213
return copy
213
214
}
214
215
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
+
215
228
// The `Model` class has a `scope()` method to return the scope for it.
216
229
// This method makes it possible for methods to expect either a model or
217
230
// a scope and reliably cast them to a scope for use via `scope()`
@@ -247,6 +260,13 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
247
260
}
248
261
}
249
262
263
+ fetchOptions ( ) : RequestInit {
264
+ return {
265
+ ...this . model . fetchOptions ( ) ,
266
+ ...this . _extraFetchOptions
267
+ }
268
+ }
269
+
250
270
copy ( ) : Scope < T > {
251
271
const newScope = cloneDeep ( this )
252
272
@@ -317,9 +337,7 @@ export class Scope<T extends SpraypaintBase = SpraypaintBase> {
317
337
url = `${ url } ?${ qp } `
318
338
}
319
339
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 ( ) )
323
341
refreshJWT ( this . model , response )
324
342
return response . jsonPayload
325
343
}
0 commit comments