2121*/
2222
2323import {
24+ collateFetchArgumentsFn ,
2425 matchObjectPropertiesFn ,
2526 parsePropertiesToMatchFn ,
2627} from './utils.js' ;
@@ -569,18 +570,8 @@ function jsonEditFetchResponseFn(trusted, jsonq = '') {
569570 const args = context . callArgs ;
570571 const fetchPromise = context . reflect ( ) ;
571572 if ( propNeedles . size !== 0 ) {
572- const objs = [ args [ 0 ] instanceof Object ? args [ 0 ] : { url : args [ 0 ] } ] ;
573- if ( objs [ 0 ] instanceof Request ) {
574- try {
575- objs [ 0 ] = safe . Request_clone . call ( objs [ 0 ] ) ;
576- } catch ( ex ) {
577- safe . uboErr ( logPrefix , 'Error:' , ex ) ;
578- }
579- }
580- if ( args [ 1 ] instanceof Object ) {
581- objs . push ( args [ 1 ] ) ;
582- }
583- const matched = matchObjectPropertiesFn ( propNeedles , ...objs ) ;
573+ const props = collateFetchArgumentsFn ( ...args ) ;
574+ const matched = matchObjectPropertiesFn ( propNeedles , props ) ;
584575 if ( matched === undefined ) { return fetchPromise ; }
585576 if ( safe . logLevel > 1 ) {
586577 safe . uboLog ( logPrefix , `Matched "propsToMatch":\n\t${ matched . join ( '\n\t' ) } ` ) ;
@@ -618,6 +609,7 @@ function jsonEditFetchResponseFn(trusted, jsonq = '') {
618609registerScriptlet ( jsonEditFetchResponseFn , {
619610 name : 'json-edit-fetch-response.fn' ,
620611 dependencies : [
612+ collateFetchArgumentsFn ,
621613 JSONPath ,
622614 matchObjectPropertiesFn ,
623615 parsePropertiesToMatchFn ,
@@ -716,17 +708,8 @@ function jsonEditFetchRequestFn(trusted, jsonq = '') {
716708 return context . reflect ( ) ;
717709 }
718710 if ( propNeedles . size !== 0 ) {
719- const objs = [
720- resource instanceof Object ? resource : { url : `${ resource } ` }
721- ] ;
722- if ( objs [ 0 ] instanceof Request ) {
723- try {
724- objs [ 0 ] = safe . Request_clone . call ( objs [ 0 ] ) ;
725- } catch ( ex ) {
726- safe . uboErr ( logPrefix , 'Error:' , ex ) ;
727- }
728- }
729- const matched = matchObjectPropertiesFn ( propNeedles , ...objs ) ;
711+ const props = collateFetchArgumentsFn ( resource , options ) ;
712+ const matched = matchObjectPropertiesFn ( propNeedles , props ) ;
730713 if ( matched === undefined ) { return context . reflect ( ) ; }
731714 if ( safe . logLevel > 1 ) {
732715 safe . uboLog ( logPrefix , `Matched "propsToMatch":\n\t${ matched . join ( '\n\t' ) } ` ) ;
@@ -745,6 +728,7 @@ function jsonEditFetchRequestFn(trusted, jsonq = '') {
745728registerScriptlet ( jsonEditFetchRequestFn , {
746729 name : 'json-edit-fetch-request.fn' ,
747730 dependencies : [
731+ collateFetchArgumentsFn ,
748732 JSONPath ,
749733 matchObjectPropertiesFn ,
750734 parsePropertiesToMatchFn ,
@@ -986,18 +970,8 @@ function jsonlEditFetchResponseFn(trusted, jsonq = '') {
986970 const args = context . callArgs ;
987971 const fetchPromise = context . reflect ( ) ;
988972 if ( propNeedles . size !== 0 ) {
989- const objs = [ args [ 0 ] instanceof Object ? args [ 0 ] : { url : args [ 0 ] } ] ;
990- if ( objs [ 0 ] instanceof Request ) {
991- try {
992- objs [ 0 ] = safe . Request_clone . call ( objs [ 0 ] ) ;
993- } catch ( ex ) {
994- safe . uboErr ( logPrefix , 'Error:' , ex ) ;
995- }
996- }
997- if ( args [ 1 ] instanceof Object ) {
998- objs . push ( args [ 1 ] ) ;
999- }
1000- const matched = matchObjectPropertiesFn ( propNeedles , ...objs ) ;
973+ const props = collateFetchArgumentsFn ( ...args ) ;
974+ const matched = matchObjectPropertiesFn ( propNeedles , props ) ;
1001975 if ( matched === undefined ) { return fetchPromise ; }
1002976 if ( safe . logLevel > 1 ) {
1003977 safe . uboLog ( logPrefix , `Matched "propsToMatch":\n\t${ matched . join ( '\n\t' ) } ` ) ;
@@ -1039,6 +1013,7 @@ function jsonlEditFetchResponseFn(trusted, jsonq = '') {
10391013registerScriptlet ( jsonlEditFetchResponseFn , {
10401014 name : 'jsonl-edit-fetch-response.fn' ,
10411015 dependencies : [
1016+ collateFetchArgumentsFn ,
10421017 JSONPath ,
10431018 jsonlEditFn ,
10441019 matchObjectPropertiesFn ,
0 commit comments