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