@@ -635,14 +635,19 @@ function getResourceObjects(queryObject, result_array) {
635635 * @param {string } [lastDataVersion] the last data version tracking id.
636636 * @param {boolean } [getDataVersion] If true the function will return object having result
637637 * and dataVersion.
638+ * @param {Array<NamedResourceData> } [resources] csv resources supplied as strings
638639 * @returns {Promise } A promise that returns the call response object or object having *result*
639640 * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
640641 * @example
641642 * const result = await client.query(WOQL.star())
642643 */
643- WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false ) {
644+ WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false , resources = [ ] ) {
644645 allWitnesses = allWitnesses || false ;
645646 commitMsg = commitMsg || 'Commit generated with javascript client without message' ;
647+
648+ const providedResourcesLookupMap = ( resources ?? [ ] )
649+ . reduce ( ( map , res ) => ( { ...map , [ ( res . filename ) . split ( '/' ) . pop ( ) ] : res . data } ) , { } ) ;
650+
646651 if ( woql && woql . json && ( ! woql . containsUpdate ( ) || commitMsg ) ) {
647652 const doql = woql . containsUpdate ( ) ? this . generateCommitInfo ( commitMsg ) : { } ;
648653 doql . query = woql . json ( ) ;
@@ -655,9 +660,17 @@ WOQLClient.prototype.query = function (woql, commitMsg, allWitnesses, lastDataVe
655660 const formData = new FormData ( ) ;
656661
657662 resourceObjects . forEach ( ( resourceObject ) => {
663+ const providedResourceInsteadOfFile = typeof resourceObject . source . post === 'string'
664+ ? providedResourcesLookupMap ?. [ resourceObject . source . post . split ( '/' ) . pop ( ) ]
665+ : undefined ;
666+
658667 const fileName = resourceObject . source . post . split ( '/' ) . pop ( ) ;
659668
660- formData . append ( 'file' , fs . createReadStream ( resourceObject . source . post ) ) ;
669+ if ( providedResourceInsteadOfFile ) {
670+ formData . append ( 'file' , providedResourceInsteadOfFile , { filename : fileName , contentType : 'application/csv' } ) ;
671+ } else {
672+ formData . append ( 'file' , fs . createReadStream ( resourceObject . source . post ) ) ;
673+ }
661674 resourceObject . source . post = fileName ;
662675 } ) ;
663676
0 commit comments