11import processBody from './body'
22
3+ /*
4+ Methods that can be callbacks, ex:
5+ headers: ${partialHeaders => }
6+ */
7+ const callbackMethods = {
8+ headers : ( { value, partial } ) => value ( partial ) ,
9+ url : ( { value, partial } ) => value ( partial . url )
10+ }
11+
312/*
413 Take in raw query string and
514 return a fetch api compatible object
615*/
7-
816const buildObjectFromTag = ( strings , vars , partial ) => {
917 const namespace = 'legible-request-var-'
1018 return strings
@@ -31,14 +39,15 @@ const buildObjectFromTag = (strings, vars, partial) => {
3139 if ( ! value . startsWith ( namespace ) ) return [ key , value ]
3240 // Get the index at the end of the namespaced string
3341 const index = parseInt ( value . replace ( namespace , '' ) , 10 )
34- // Return an array of the object key and replaced value from `vars`
35- if ( partial . url && key === 'url' && typeof vars [ index ] === 'function' ) {
36- return [ key , vars [ index ] ( partial . url ) ]
37- }
3842
39- if ( key === 'headers' && typeof vars [ index ] === 'function' ) {
40- return [ key , vars [ index ] ( partial ) ]
43+ // run through any callback methods
44+ if ( callbackMethods [ key ] && typeof vars [ index ] === 'function' ) {
45+ return [ key , callbackMethods [ key ] ( {
46+ value : vars [ index ] ,
47+ partial
48+ } ) ]
4149 }
50+
4251 return [ key , vars [ index ] ]
4352 } )
4453 // Convert to object
0 commit comments