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 return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
154 function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
@@ -62,14 +51,15 @@ var DgraphClientStub = (function () {
6251 }
6352 DgraphClientStub . prototype . detectApiVersion = function ( ) {
6453 return __awaiter ( this , void 0 , void 0 , function ( ) {
65- var health ;
54+ var health , version ;
6655 return __generator ( this , function ( _a ) {
6756 switch ( _a . label ) {
68- case 0 : return [ 4 , this . health ( ) ] ;
57+ case 0 : return [ 4 , this . getHealth ( ) ] ;
6958 case 1 :
7059 health = _a . sent ( ) ;
71- this . legacyApi = health . version . startsWith ( "1.0." ) ;
72- return [ 2 , health . version ] ;
60+ version = health [ "version" ] || health [ 0 ] . version ;
61+ this . legacyApi = version . startsWith ( "1.0." ) ;
62+ return [ 2 , version ] ;
7363 }
7464 } ) ;
7565 } ) ;
@@ -248,33 +238,6 @@ var DgraphClientStub = (function () {
248238 : "/abort/" + ctx . start_ts ;
249239 return this . callAPI ( url , { method : "POST" } ) ;
250240 } ;
251- DgraphClientStub . prototype . health = function ( ) {
252- return __awaiter ( this , void 0 , void 0 , function ( ) {
253- var response , text ;
254- return __generator ( this , function ( _a ) {
255- switch ( _a . label ) {
256- case 0 : return [ 4 , fetch ( this . getURL ( "health" ) , {
257- method : "GET" ,
258- } ) ] ;
259- case 1 :
260- response = _a . sent ( ) ;
261- if ( response . status >= 300 || response . status < 200 ) {
262- throw new Error ( "Invalid status code = " + response . status ) ;
263- }
264- return [ 4 , response . text ( ) ] ;
265- case 2 :
266- text = _a . sent ( ) ;
267- if ( text === "OK" ) {
268- return [ 2 , {
269- health : text ,
270- version : "1.0.x" ,
271- } ] ;
272- }
273- return [ 2 , __assign ( { } , JSON . parse ( text ) , { health : "OK" } ) ] ;
274- }
275- } ) ;
276- } ) ;
277- } ;
278241 DgraphClientStub . prototype . login = function ( userid , password , refreshToken ) {
279242 return __awaiter ( this , void 0 , void 0 , function ( ) {
280243 var body , res ;
@@ -329,28 +292,15 @@ var DgraphClientStub = (function () {
329292 DgraphClientStub . prototype . getHealth = function ( all ) {
330293 if ( all === void 0 ) { all = false ; }
331294 return __awaiter ( this , void 0 , void 0 , function ( ) {
332- var url ;
333295 return __generator ( this , function ( _a ) {
334- switch ( _a . label ) {
335- case 0 :
336- url = "health" + ( all ? "?all" : "" ) ;
337- return [ 4 , this . callAPI ( url , {
338- method : "GET" ,
339- } ) ] ;
340- case 1 : return [ 2 , _a . sent ( ) ] ;
341- }
296+ return [ 2 , this . callAPI ( "health" + ( all ? "?all" : "" ) , { } ) ] ;
342297 } ) ;
343298 } ) ;
344299 } ;
345300 DgraphClientStub . prototype . getState = function ( ) {
346301 return __awaiter ( this , void 0 , void 0 , function ( ) {
347302 return __generator ( this , function ( _a ) {
348- switch ( _a . label ) {
349- case 0 : return [ 4 , this . callAPI ( "state" , {
350- method : "GET" ,
351- } ) ] ;
352- case 1 : return [ 2 , _a . sent ( ) ] ;
353- }
303+ return [ 2 , this . callAPI ( "state" , { } ) ] ;
354304 } ) ;
355305 } ) ;
356306 } ;
@@ -375,7 +325,7 @@ var DgraphClientStub = (function () {
375325 this . cancelRefreshTimer ( ) ;
376326 var timeToWait = Math . max ( 2000 , jwt . decode ( accessToken ) . exp * 1000 - Date . now ( )
377327 - AUTO_REFRESH_PREFETCH_TIME ) ;
378- this . autoRefreshTimer = setTimeout ( function ( ) { return _this . refreshToken && _this . login ( ) ; } , timeToWait ) ;
328+ this . autoRefreshTimer = setTimeout ( function ( ) { return _this . refreshToken !== undefined ? _this . login ( ) : 0 ; } , timeToWait ) ;
379329 } ;
380330 DgraphClientStub . prototype . callAPI = function ( path , config ) {
381331 return __awaiter ( this , void 0 , void 0 , function ( ) {
0 commit comments