1
1
"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
- } ;
13
2
var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
14
3
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
15
4
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
@@ -62,14 +51,15 @@ var DgraphClientStub = (function () {
62
51
}
63
52
DgraphClientStub . prototype . detectApiVersion = function ( ) {
64
53
return __awaiter ( this , void 0 , void 0 , function ( ) {
65
- var health ;
54
+ var health , version ;
66
55
return __generator ( this , function ( _a ) {
67
56
switch ( _a . label ) {
68
- case 0 : return [ 4 , this . health ( ) ] ;
57
+ case 0 : return [ 4 , this . getHealth ( ) ] ;
69
58
case 1 :
70
59
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 ] ;
73
63
}
74
64
} ) ;
75
65
} ) ;
@@ -248,33 +238,6 @@ var DgraphClientStub = (function () {
248
238
: "/abort/" + ctx . start_ts ;
249
239
return this . callAPI ( url , { method : "POST" } ) ;
250
240
} ;
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
- } ;
278
241
DgraphClientStub . prototype . login = function ( userid , password , refreshToken ) {
279
242
return __awaiter ( this , void 0 , void 0 , function ( ) {
280
243
var body , res ;
@@ -329,28 +292,15 @@ var DgraphClientStub = (function () {
329
292
DgraphClientStub . prototype . getHealth = function ( all ) {
330
293
if ( all === void 0 ) { all = false ; }
331
294
return __awaiter ( this , void 0 , void 0 , function ( ) {
332
- var url ;
333
295
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" : "" ) , { } ) ] ;
342
297
} ) ;
343
298
} ) ;
344
299
} ;
345
300
DgraphClientStub . prototype . getState = function ( ) {
346
301
return __awaiter ( this , void 0 , void 0 , function ( ) {
347
302
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" , { } ) ] ;
354
304
} ) ;
355
305
} ) ;
356
306
} ;
@@ -375,7 +325,7 @@ var DgraphClientStub = (function () {
375
325
this . cancelRefreshTimer ( ) ;
376
326
var timeToWait = Math . max ( 2000 , jwt . decode ( accessToken ) . exp * 1000 - Date . now ( )
377
327
- 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 ) ;
379
329
} ;
380
330
DgraphClientStub . prototype . callAPI = function ( path , config ) {
381
331
return __awaiter ( this , void 0 , void 0 , function ( ) {
0 commit comments