@@ -30,7 +30,7 @@ const DGRAPHCLOUD_API_KEY_HEADER = "X-Auth-Token";
30
30
export class DgraphClientStub {
31
31
private readonly addr : string ;
32
32
private readonly options : Options ;
33
- // tslint: disable-next-line no-any
33
+ /* eslint- disable-next-line @typescript-eslint/ no-explicit- any */
34
34
private readonly jsonParser : ( text : string ) => any ;
35
35
private legacyApi : boolean ;
36
36
private accessToken : string ;
@@ -42,13 +42,12 @@ export class DgraphClientStub {
42
42
addr ?: string ,
43
43
stubConfig : {
44
44
legacyApi ?: boolean ;
45
- // tslint: disable-next-line no -any
45
+ // eslint- disable-next-line @typescript-eslint/no-explicit -any
46
46
jsonParser ?( text : string ) : any ;
47
47
} = { } ,
48
48
options : Options = { } ,
49
49
) {
50
50
if ( addr === undefined ) {
51
- // tslint:disable-next-line no-http-string
52
51
this . addr = "http://localhost:8080" ;
53
52
} else {
54
53
this . addr = addr ;
@@ -60,13 +59,13 @@ export class DgraphClientStub {
60
59
this . jsonParser =
61
60
stubConfig . jsonParser !== undefined
62
61
? stubConfig . jsonParser
63
- : // tslint: disable-next-line no-unsafe-any
64
- JSON . parse . bind ( JSON ) ;
62
+ : // eslint- disable-next-line @typescript-eslint/tslint/config
63
+ JSON . parse . bind ( JSON ) ;
65
64
}
66
65
67
66
public async detectApiVersion ( ) : Promise < string > {
68
67
const health = await this . getHealth ( ) ;
69
- // tslint: disable-next-line no-unsafe-any no-string-literal
68
+ // eslint- disable-next-line @typescript-eslint/tslint/config, @typescript-eslint/dot-notation
70
69
let version : string = health [ "version" ] || health [ 0 ] . version ;
71
70
if ( version === undefined ) {
72
71
version = "1.0.x" ;
@@ -205,19 +204,19 @@ export class DgraphClientStub {
205
204
) {
206
205
body = `{
207
206
${
208
- mu . setNquads === undefined
209
- ? ""
210
- : `set {
207
+ mu . setNquads === undefined
208
+ ? ""
209
+ : `set {
211
210
${ mu . setNquads }
212
211
}`
213
- }
212
+ }
214
213
${
215
- mu . deleteNquads === undefined
216
- ? ""
217
- : `delete {
214
+ mu . deleteNquads === undefined
215
+ ? ""
216
+ : `delete {
218
217
${ mu . deleteNquads }
219
218
}`
220
- }
219
+ }
221
220
}` ;
222
221
} else if ( mu . mutation !== undefined ) {
223
222
body = mu . mutation ;
@@ -250,7 +249,7 @@ export class DgraphClientStub {
250
249
let nextDelim = "?" ;
251
250
if ( mu . startTs > 0 ) {
252
251
url +=
253
- ( ! this . legacyApi ? ` ?startTs=` : `/` ) + mu . startTs . toString ( ) ;
252
+ ( ! this . legacyApi ? " ?startTs=" : "/" ) + mu . startTs . toString ( ) ;
254
253
nextDelim = "&" ;
255
254
}
256
255
@@ -428,15 +427,15 @@ export class DgraphClientStub {
428
427
return this . callAPI ( "state" , this . options ) ;
429
428
}
430
429
431
- public setAutoRefresh ( val : boolean ) {
430
+ public setAutoRefresh ( val : boolean ) : void {
432
431
if ( ! val ) {
433
432
this . cancelRefreshTimer ( ) ;
434
433
}
435
434
this . autoRefresh = val ;
436
435
this . maybeStartRefreshTimer ( this . accessToken ) ;
437
436
}
438
437
439
- public setAlphaAuthToken ( authToken : string ) {
438
+ public setAlphaAuthToken ( authToken : string ) : void {
440
439
if ( this . options . headers === undefined ) {
441
440
this . options . headers = { } ;
442
441
}
@@ -445,51 +444,46 @@ export class DgraphClientStub {
445
444
446
445
/**
447
446
* @deprecated since v21.3 and will be removed in v21.07 release.
448
- * Please use {@link setCloudApiKey} instead.
447
+ * Please use {@link setCloudApiKey} instead.
449
448
*/
450
-
451
- public setSlashApiKey ( apiKey : string ) {
449
+ public setSlashApiKey ( apiKey : string ) : void {
452
450
this . setCloudApiKey ( apiKey ) ;
453
451
}
454
452
455
- public setCloudApiKey ( apiKey : string ) {
453
+ public setCloudApiKey ( apiKey : string ) : void {
456
454
if ( this . options . headers === undefined ) {
457
455
this . options . headers = { } ;
458
456
}
459
457
this . options . headers [ DGRAPHCLOUD_API_KEY_HEADER ] = apiKey ;
460
458
}
461
459
462
- private cancelRefreshTimer ( ) {
460
+ private cancelRefreshTimer ( ) : void {
463
461
if ( this . autoRefreshTimer !== undefined ) {
464
- // tslint: disable-next-line
465
- clearTimeout ( < any > this . autoRefreshTimer ) ;
462
+ // eslint- disable-next-line @typescript-eslint/no-explicit-any
463
+ clearTimeout ( ( this . autoRefreshTimer as any ) ) ;
466
464
this . autoRefreshTimer = undefined ;
467
465
}
468
466
}
469
467
470
- private maybeStartRefreshTimer ( accessToken ?: string ) {
468
+ private maybeStartRefreshTimer ( accessToken ?: string ) : void {
471
469
if ( accessToken === undefined || ! this . autoRefresh ) {
472
470
return ;
473
471
}
474
472
this . cancelRefreshTimer ( ) ;
475
473
476
474
const timeToWait = Math . max (
477
475
2000 ,
478
- // tslint: disable-next-line no-unsafe-any
479
- ( < { exp : number } > jwt . decode ( accessToken ) ) . exp * 1000 -
476
+ // eslint- disable-next-line @typescript-eslint/tslint/config
477
+ ( jwt . decode ( accessToken ) as { exp : number } ) . exp * 1000 -
480
478
Date . now ( ) -
481
479
AUTO_REFRESH_PREFETCH_TIME ,
482
480
) ;
483
481
484
- // tslint:disable-next-line no-unsafe-any no-any
485
- this . autoRefreshTimer = < number > (
486
- ( < unknown > (
487
- setTimeout (
488
- ( ) => ( this . refreshToken !== undefined ? this . login ( ) : 0 ) ,
489
- timeToWait ,
490
- )
491
- ) )
492
- ) ;
482
+ // eslint-disable-next-line @typescript-eslint/tslint/config
483
+ this . autoRefreshTimer = ( setTimeout (
484
+ ( ) => ( this . refreshToken !== undefined ? this . login ( ) : 0 ) ,
485
+ timeToWait ,
486
+ ) as unknown ) as number ;
493
487
}
494
488
495
489
private async callAPI < T > ( path : string , config : Config ) : Promise < T > {
@@ -499,40 +493,38 @@ export class DgraphClientStub {
499
493
config . headers [ ACL_TOKEN_HEADER ] = this . accessToken ;
500
494
}
501
495
502
- // tslint: disable-next-line no-unsafe-any
496
+ // eslint- disable-next-line @typescript-eslint/tslint/config
503
497
const response = await fetch ( url , config ) ;
504
498
505
- // tslint: disable-next-line no-unsafe-any
499
+ // eslint- disable-next-line @typescript-eslint/tslint/config
506
500
if ( response . status >= 300 || response . status < 200 ) {
507
- // tslint: disable-next-line no-unsafe-any
501
+ // eslint- disable-next-line @typescript-eslint/tslint/config
508
502
throw new HTTPError ( response ) ;
509
503
}
510
504
511
505
let json ;
512
- // tslint: disable-next-line no-unsafe-any
506
+ // eslint- disable-next-line @typescript-eslint/tslint/config
513
507
const responseText : string = await response . text ( ) ;
514
508
515
509
try {
516
- // tslint: disable-next-line no-unsafe -any
510
+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
517
511
json = this . jsonParser ( responseText ) ;
518
512
} catch ( e ) {
519
513
if ( config . acceptRawText ) {
520
- return < T > ( < unknown > responseText ) ;
514
+ return ( responseText as unknown ) as T ;
521
515
}
522
- const err : ErrorNonJson = < ErrorNonJson > (
523
- new Error ( "Response is not JSON" )
524
- ) ;
516
+ const err : ErrorNonJson = new Error ( "Response is not JSON" ) as ErrorNonJson ;
525
517
err . responseText = responseText ;
526
518
throw err ;
527
519
}
528
- // tslint: disable-next-line no-unsafe -any
529
- const errors = ( < { errors : APIResultError [ ] } > json ) . errors ;
520
+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
521
+ const errors = ( json as { errors : APIResultError [ ] } ) . errors ;
530
522
531
523
if ( errors !== undefined ) {
532
524
throw new APIError ( url , errors ) ;
533
525
}
534
526
535
- return < T > json ;
527
+ return json as T ;
536
528
}
537
529
538
530
private getURL ( path : string ) : string {
0 commit comments