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
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
15
4
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
@@ -63,14 +52,25 @@ var DgraphClientStub = (function () {
63
52
}
64
53
DgraphClientStub . prototype . detectApiVersion = function ( ) {
65
54
return __awaiter ( this , void 0 , void 0 , function ( ) {
66
- var health ;
55
+ var response , err_1 ;
67
56
return __generator ( this , function ( _a ) {
68
57
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 ( ) ] ;
70
61
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 ] ;
74
74
}
75
75
} ) ;
76
76
} ) ;
@@ -249,33 +249,6 @@ var DgraphClientStub = (function () {
249
249
: "/abort/" + ctx . start_ts ;
250
250
return this . callAPI ( url , { method : "POST" } ) ;
251
251
} ;
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
- } ;
279
252
DgraphClientStub . prototype . login = function ( userid , password , refreshToken ) {
280
253
return __awaiter ( this , void 0 , void 0 , function ( ) {
281
254
var body , res ;
@@ -329,30 +302,14 @@ var DgraphClientStub = (function () {
329
302
} ;
330
303
DgraphClientStub . prototype . getHealth = function ( all ) {
331
304
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" ,
344
308
} ) ;
345
309
} ;
346
310
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" ,
356
313
} ) ;
357
314
} ;
358
315
DgraphClientStub . prototype . setAutoRefresh = function ( val ) {
@@ -380,7 +337,7 @@ var DgraphClientStub = (function () {
380
337
} ;
381
338
DgraphClientStub . prototype . callAPI = function ( path , config ) {
382
339
return __awaiter ( this , void 0 , void 0 , function ( ) {
383
- var url , response , json , errors ;
340
+ var url , response , json , err_2 , errors ;
384
341
return __generator ( this , function ( _a ) {
385
342
switch ( _a . label ) {
386
343
case 0 :
@@ -395,9 +352,18 @@ var DgraphClientStub = (function () {
395
352
if ( response . status >= 300 || response . status < 200 ) {
396
353
throw new Error ( "Invalid status code = " + response . status ) ;
397
354
}
398
- return [ 4 , response . json ( ) ] ;
355
+ _a . label = 2 ;
399
356
case 2 :
357
+ _a . trys . push ( [ 2 , 4 , , 5 ] ) ;
358
+ return [ 4 , response . json ( ) ] ;
359
+ case 3 :
400
360
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 :
401
367
errors = json . errors ;
402
368
if ( errors !== undefined ) {
403
369
throw new errors_1 . APIError ( url , errors ) ;
0 commit comments