@@ -35,7 +35,7 @@ class OpenEO {
35
35
}
36
36
37
37
version ( ) {
38
- return "0.3.0 " ;
38
+ return "0.3.2 " ;
39
39
}
40
40
}
41
41
@@ -94,6 +94,21 @@ class Connection {
94
94
. then ( response => response . data ) ;
95
95
}
96
96
97
+ buildProcessGraph ( ) {
98
+ return this . listProcesses ( )
99
+ . then ( data => {
100
+ var builder = { } ;
101
+ for ( let i in data . processes ) {
102
+ let process = data . processes [ i ] ;
103
+ builder [ process . name ] = ( options ) => {
104
+ options . process_id = process . name ;
105
+ return options ;
106
+ }
107
+ }
108
+ return builder ;
109
+ } ) ;
110
+ }
111
+
97
112
authenticateOIDC ( options = null ) {
98
113
return Promise . reject ( new Error ( "Not implemented yet." ) ) ;
99
114
}
@@ -204,7 +219,7 @@ class Connection {
204
219
}
205
220
206
221
createJob ( processGraph , outputFormat = null , outputParameters = { } , title = null , description = null , plan = null , budget = null , additional = { } ) {
207
- var jobObject = Object . assign ( additional , {
222
+ var jobObject = Object . assign ( { } , additional , {
208
223
title : title ,
209
224
description : description ,
210
225
process_graph : processGraph ,
@@ -328,7 +343,48 @@ class Connection {
328
343
break ;
329
344
}
330
345
331
- return axios ( options ) ;
346
+ return axios ( options ) . catch ( error => {
347
+ return new Promise ( ( resolve , reject ) => {
348
+ if ( error . response !== null && typeof error . response === 'object' && error . response . data !== null && typeof error . response . data === 'object' && typeof error . response . data . type === 'string' && error . response . data . type . indexOf ( '/json' ) !== - 1 ) {
349
+ // JSON error responses are Blobs and streams if responseType is set as such, so convert to JSON if required.
350
+ // See: https://github.com/axios/axios/issues/815
351
+ try {
352
+ switch ( options . responseType ) {
353
+ case 'blob' :
354
+ const fileReader = new FileReader ( ) ;
355
+ fileReader . onerror = ( ) => {
356
+ fileReader . abort ( ) ;
357
+ reject ( error ) ;
358
+ } ;
359
+ fileReader . onload = ( ) => {
360
+ reject ( JSON . parse ( fileReader . result ) ) ;
361
+ } ;
362
+ fileReader . readAsText ( error . response . data ) ;
363
+ break ;
364
+ case 'stream' :
365
+ const chunks = "" ;
366
+ error . response . data . on ( "data" , chunk => {
367
+ chunks . push ( chunk ) ;
368
+ } ) ;
369
+ readStream . on ( "error" , ( ) => {
370
+ reject ( error ) ;
371
+ } ) ;
372
+ readStream . on ( "end" , ( ) => {
373
+ reject ( JSON . parse ( Buffer . concat ( chunks ) . toString ( ) ) ) ;
374
+ } ) ;
375
+ break ;
376
+ default :
377
+ reject ( error ) ;
378
+ }
379
+ } catch ( exception ) {
380
+ reject ( error ) ;
381
+ }
382
+ }
383
+ else {
384
+ reject ( error ) ;
385
+ }
386
+ } ) ;
387
+ } ) ;
332
388
}
333
389
334
390
_resetAuth ( ) {
@@ -498,7 +554,7 @@ class Subscriptions {
498
554
499
555
_flushQueue ( ) {
500
556
if ( this . socket . readyState === this . socket . OPEN ) {
501
- for ( var i in this . messageQueue ) {
557
+ for ( let i in this . messageQueue ) {
502
558
this . socket . send ( JSON . stringify ( this . messageQueue [ i ] ) ) ;
503
559
}
504
560
@@ -538,7 +594,7 @@ class Subscriptions {
538
594
parameters = { } ;
539
595
}
540
596
541
- var payloadParameters = Object . assign ( parameters , { topic : topic } ) ;
597
+ var payloadParameters = Object . assign ( { } , parameters , { topic : topic } ) ;
542
598
543
599
this . _sendMessage ( action , {
544
600
topics : [ payloadParameters ]
@@ -553,15 +609,19 @@ class Capabilities {
553
609
if ( ! data || ! data . version || ! data . endpoints ) {
554
610
throw new Error ( "Data is not a valid Capabilities response" ) ;
555
611
}
556
- this . _data = data ;
612
+ this . data = data ;
613
+ }
614
+
615
+ toPlainObject ( ) {
616
+ return this . data ;
557
617
}
558
618
559
619
version ( ) {
560
- return this . _data . version ;
620
+ return this . data . version ;
561
621
}
562
622
563
623
listFeatures ( ) {
564
- return this . _data . endpoints ;
624
+ return this . data . endpoints ;
565
625
}
566
626
567
627
hasFeature ( methodName ) {
@@ -606,14 +666,14 @@ class Capabilities {
606
666
} ;
607
667
608
668
// regex-ify to allow custom parameter names
609
- for ( var key in clientMethodNameToAPIRequestMap ) {
669
+ for ( let key in clientMethodNameToAPIRequestMap ) {
610
670
clientMethodNameToAPIRequestMap [ key ] = clientMethodNameToAPIRequestMap [ key ] . replace ( / { [ ^ } ] + } / , '{[^}]+}' ) ;
611
671
}
612
672
613
673
if ( methodName === 'createFile' ) {
614
674
return this . hasFeature ( 'uploadFile' ) ; // createFile is always available, map it to uploadFile as it is more meaningful.
615
675
} else {
616
- return this . _data . endpoints
676
+ return this . data . endpoints
617
677
. map ( ( e ) => e . methods . map ( ( method ) => method + ' ' + e . path ) )
618
678
// .flat(1) // does exactly what we want, but (as of Sept. 2018) not yet part of the standard...
619
679
. reduce ( ( a , b ) => a . concat ( b ) , [ ] ) // ES6-proof version of flat(1)
@@ -622,11 +682,11 @@ class Capabilities {
622
682
}
623
683
624
684
currency ( ) {
625
- return ( this . _data . billing ? this . _data . billing . currency : null ) ;
685
+ return ( this . data . billing ? this . data . billing . currency : null ) ;
626
686
}
627
687
628
688
listPlans ( ) {
629
- return ( this . _data . billing ? this . _data . billing . plans : null ) ;
689
+ return ( this . data . billing ? this . data . billing . plans : null ) ;
630
690
}
631
691
}
632
692
@@ -637,8 +697,8 @@ class BaseEntity {
637
697
this . connection = connection ;
638
698
this . clientNames = { } ;
639
699
this . extra = { } ;
640
- for ( var i in properties ) {
641
- var backend , client ;
700
+ for ( let i in properties ) {
701
+ let backend , client ;
642
702
if ( Array . isArray ( properties [ i ] ) ) {
643
703
backend = properties [ i ] [ 0 ] ;
644
704
client = properties [ i ] [ 1 ] ;
@@ -655,7 +715,7 @@ class BaseEntity {
655
715
}
656
716
657
717
setAll ( metadata ) {
658
- for ( var name in metadata ) {
718
+ for ( let name in metadata ) {
659
719
if ( typeof this . clientNames [ name ] === 'undefined' ) {
660
720
this . extra [ name ] = metadata [ name ] ;
661
721
}
@@ -668,8 +728,8 @@ class BaseEntity {
668
728
669
729
getAll ( ) {
670
730
var obj = { } ;
671
- for ( var backend in this . clientNames ) {
672
- var client = this . clientNames [ backend ] ;
731
+ for ( let backend in this . clientNames ) {
732
+ let client = this . clientNames [ backend ] ;
673
733
obj [ client ] = this [ client ] ;
674
734
}
675
735
return Object . assign ( obj , this . extra ) ;
@@ -736,7 +796,7 @@ class File extends BaseEntity {
736
796
}
737
797
} ;
738
798
if ( typeof statusCallback === 'function' ) {
739
- options . onUploadProgress = function ( progressEvent ) {
799
+ options . onUploadProgress = ( progressEvent ) => {
740
800
var percentCompleted = Math . round ( ( progressEvent . loaded * 100 ) / progressEvent . total ) ;
741
801
statusCallback ( percentCompleted ) ;
742
802
} ;
@@ -836,11 +896,11 @@ class Job extends BaseEntity {
836
896
837
897
var promises = [ ] ;
838
898
var files = [ ] ;
839
- for ( var i in list . links ) {
840
- var link = list . links [ i ] . href ;
841
- var parsedUrl = url . parse ( link ) ;
842
- var targetPath = path . join ( targetFolder , path . basename ( parsedUrl . pathname ) ) ;
843
- var p = this . connection . download ( link , false )
899
+ for ( let i in list . links ) {
900
+ let link = list . links [ i ] . href ;
901
+ let parsedUrl = url . parse ( link ) ;
902
+ let targetPath = path . join ( targetFolder , path . basename ( parsedUrl . pathname ) ) ;
903
+ let p = this . connection . download ( link , false )
844
904
. then ( response => this . connection . _saveToFileNode ( response . data , targetPath ) )
845
905
. then ( ( ) => files . push ( targetPath ) ) ;
846
906
promises . push ( p ) ;
@@ -926,13 +986,14 @@ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
926
986
module . exports = toExport ;
927
987
}
928
988
else {
989
+ /* istanbul ignore next */
929
990
if ( typeof define === 'function' && define . amd ) {
930
991
define ( [ ] , function ( ) {
931
992
return toExport ;
932
993
} ) ;
933
994
}
934
995
else {
935
- for ( let exportObjName in toExport ) {
996
+ for ( let exportObjName in toExport ) {
936
997
window [ exportObjName ] = toExport [ exportObjName ] ;
937
998
}
938
999
}
0 commit comments