11"use strict" ;
2- var __assign = ( this && this . __assign ) || function ( ) {
3- __assign = Object . assign || function ( t ) {
4- for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
5- s = arguments [ i ] ;
6- for ( var p in s ) if ( Object . prototype . hasOwnProperty . call ( s , p ) )
7- t [ p ] = s [ p ] ;
8- }
9- return t ;
10- } ;
11- return __assign . apply ( this , arguments ) ;
12- } ;
132var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
143 function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
154 return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
@@ -63,14 +52,25 @@ var DgraphClientStub = (function () {
6352 }
6453 DgraphClientStub . prototype . detectApiVersion = function ( ) {
6554 return __awaiter ( this , void 0 , void 0 , function ( ) {
66- var health ;
55+ var response , err_1 ;
6756 return __generator ( this , function ( _a ) {
6857 switch ( _a . label ) {
69- case 0 : return [ 4 , this . health ( ) ] ;
58+ case 0 :
59+ _a . trys . push ( [ 0 , 2 , , 3 ] ) ;
60+ return [ 4 , this . getHealth ( ) ] ;
7061 case 1 :
71- health = _a . sent ( ) ;
72- this . legacyApi = health . version . startsWith ( "1.0." ) ;
73- return [ 2 , health . version ] ;
62+ response = _a . sent ( ) ;
63+ return [ 2 , response . data [ "version" ] ] ;
64+ case 2 :
65+ err_1 = _a . sent ( ) ;
66+ if ( err_1 . name === "FetchError" ) {
67+ if ( err_1 . response . status === 200 ) {
68+ this . legacyApi = true ;
69+ return [ 2 , "1.0.x" ] ;
70+ }
71+ }
72+ throw new Error ( "Failed to obtain alpha health." ) ;
73+ case 3 : return [ 2 ] ;
7474 }
7575 } ) ;
7676 } ) ;
@@ -249,33 +249,6 @@ var DgraphClientStub = (function () {
249249 : "/abort/" + ctx . start_ts ;
250250 return this . callAPI ( url , { method : "POST" } ) ;
251251 } ;
252- DgraphClientStub . prototype . health = function ( ) {
253- return __awaiter ( this , void 0 , void 0 , function ( ) {
254- var response , text ;
255- return __generator ( this , function ( _a ) {
256- switch ( _a . label ) {
257- case 0 : return [ 4 , fetch ( this . getURL ( "health" ) , {
258- method : "GET" ,
259- } ) ] ;
260- case 1 :
261- response = _a . sent ( ) ;
262- if ( response . status >= 300 || response . status < 200 ) {
263- throw new Error ( "Invalid status code = " + response . status ) ;
264- }
265- return [ 4 , response . text ( ) ] ;
266- case 2 :
267- text = _a . sent ( ) ;
268- if ( text === "OK" ) {
269- return [ 2 , {
270- health : text ,
271- version : "1.0.x" ,
272- } ] ;
273- }
274- return [ 2 , __assign ( __assign ( { } , JSON . parse ( text ) ) , { health : "OK" } ) ] ;
275- }
276- } ) ;
277- } ) ;
278- } ;
279252 DgraphClientStub . prototype . login = function ( userid , password , refreshToken ) {
280253 return __awaiter ( this , void 0 , void 0 , function ( ) {
281254 var body , res ;
@@ -329,30 +302,14 @@ var DgraphClientStub = (function () {
329302 } ;
330303 DgraphClientStub . prototype . getHealth = function ( all ) {
331304 if ( all === void 0 ) { all = false ; }
332- return __awaiter ( this , void 0 , void 0 , function ( ) {
333- var url ;
334- return __generator ( this , function ( _a ) {
335- switch ( _a . label ) {
336- case 0 :
337- url = "health" + ( all ? "?all" : "" ) ;
338- return [ 4 , this . callAPI ( url , {
339- method : "GET" ,
340- } ) ] ;
341- case 1 : return [ 2 , _a . sent ( ) ] ;
342- }
343- } ) ;
305+ var url = "health" + ( all ? "?all" : "" ) ;
306+ return this . callAPI ( url , {
307+ method : "GET" ,
344308 } ) ;
345309 } ;
346310 DgraphClientStub . prototype . getState = function ( ) {
347- return __awaiter ( this , void 0 , void 0 , function ( ) {
348- return __generator ( this , function ( _a ) {
349- switch ( _a . label ) {
350- case 0 : return [ 4 , this . callAPI ( "state" , {
351- method : "GET" ,
352- } ) ] ;
353- case 1 : return [ 2 , _a . sent ( ) ] ;
354- }
355- } ) ;
311+ return this . callAPI ( "state" , {
312+ method : "GET" ,
356313 } ) ;
357314 } ;
358315 DgraphClientStub . prototype . setAutoRefresh = function ( val ) {
@@ -380,7 +337,7 @@ var DgraphClientStub = (function () {
380337 } ;
381338 DgraphClientStub . prototype . callAPI = function ( path , config ) {
382339 return __awaiter ( this , void 0 , void 0 , function ( ) {
383- var url , response , json , errors ;
340+ var url , response , json , err_2 , errors ;
384341 return __generator ( this , function ( _a ) {
385342 switch ( _a . label ) {
386343 case 0 :
@@ -395,9 +352,18 @@ var DgraphClientStub = (function () {
395352 if ( response . status >= 300 || response . status < 200 ) {
396353 throw new Error ( "Invalid status code = " + response . status ) ;
397354 }
398- return [ 4 , response . json ( ) ] ;
355+ _a . label = 2 ;
399356 case 2 :
357+ _a . trys . push ( [ 2 , 4 , , 5 ] ) ;
358+ return [ 4 , response . json ( ) ] ;
359+ case 3 :
400360 json = _a . sent ( ) ;
361+ return [ 3 , 5 ] ;
362+ case 4 :
363+ err_2 = _a . sent ( ) ;
364+ err_2 . response = response ;
365+ throw err_2 ;
366+ case 5 :
401367 errors = json . errors ;
402368 if ( errors !== undefined ) {
403369 throw new errors_1 . APIError ( url , errors ) ;
0 commit comments