@@ -635,14 +635,19 @@ function getResourceObjects(queryObject, result_array) {
635
635
* @param {string } [lastDataVersion] the last data version tracking id.
636
636
* @param {boolean } [getDataVersion] If true the function will return object having result
637
637
* and dataVersion.
638
+ * @param {Array<NamedResourceData> } [resources] csv resources supplied as strings
638
639
* @returns {Promise } A promise that returns the call response object or object having *result*
639
640
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
640
641
* @example
641
642
* const result = await client.query(WOQL.star())
642
643
*/
643
- WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false ) {
644
+ WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false , resources = [ ] ) {
644
645
allWitnesses = allWitnesses || false ;
645
646
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
+
646
651
if ( woql && woql . json && ( ! woql . containsUpdate ( ) || commitMsg ) ) {
647
652
const doql = woql . containsUpdate ( ) ? this . generateCommitInfo ( commitMsg ) : { } ;
648
653
doql . query = woql . json ( ) ;
@@ -655,9 +660,17 @@ WOQLClient.prototype.query = function (woql, commitMsg, allWitnesses, lastDataVe
655
660
const formData = new FormData ( ) ;
656
661
657
662
resourceObjects . forEach ( ( resourceObject ) => {
663
+ const providedResourceInsteadOfFile = typeof resourceObject . source . post === 'string'
664
+ ? providedResourcesLookupMap ?. [ resourceObject . source . post . split ( '/' ) . pop ( ) ]
665
+ : undefined ;
666
+
658
667
const fileName = resourceObject . source . post . split ( '/' ) . pop ( ) ;
659
668
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
+ }
661
674
resourceObject . source . post = fileName ;
662
675
} ) ;
663
676
0 commit comments