Skip to content

Commit 2cfe5b5

Browse files
upgade dependencies
1 parent d780a8b commit 2cfe5b5

15 files changed

+6012
-1675
lines changed

.eslintrc.js

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 5329 additions & 1501 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,40 @@
2020
"clean": "rimraf coverage",
2121
"build": "tsc -p tsconfig.release.json",
2222
"build:watch": "tsc -w -p tsconfig.release.json",
23-
"lint": "tslint -t stylish --project \"tsconfig.json\"",
24-
"lint:fix": "tslint --fix -t stylish --project \"tsconfig.json\"",
23+
"lint": "eslint -c .eslintrc.js --ext .ts .",
24+
"lint:fix": "eslint . --ext .ts --fix",
2525
"pretest": "npm run lint",
2626
"test": "npm run test-only",
2727
"test-only": "jest --coverage --runInBand",
2828
"test:watch": "jest --watch",
2929
"coveralls": "cat ./coverage/lcov.info | coveralls"
3030
},
3131
"devDependencies": {
32-
"@types/jest": "^29.4.0",
33-
"@types/node": "^18.11.18",
34-
"coveralls": "^3.1.0",
35-
"jest": "^29.4.3",
36-
"rimraf": "^3.0.2",
37-
"ts-jest": "^29.0.5",
38-
"tslint": "^6.1.3",
39-
"tslint-microsoft-contrib": "^6.2.0",
40-
"typescript": "^4.9.5"
32+
"@types/jest": "^29.5.12",
33+
"@types/node": "^20.14.2",
34+
"@typescript-eslint/eslint-plugin": "^7.13.0",
35+
"@typescript-eslint/eslint-plugin-tslint": "^7.0.2",
36+
"@typescript-eslint/parser": "^7.13.0",
37+
"coveralls": "^3.1.1",
38+
"eslint": "^8.57.0",
39+
"eslint-plugin-import": "^2.29.1",
40+
"eslint-plugin-jest": "^28.6.0",
41+
"eslint-plugin-jsdoc": "^48.2.9",
42+
"eslint-plugin-jsx-a11y": "^6.8.0",
43+
"eslint-plugin-no-null": "^1.0.2",
44+
"eslint-plugin-prefer-arrow": "^1.2.3",
45+
"eslint-plugin-react": "^7.34.2",
46+
"eslint-plugin-security": "^3.0.0",
47+
"eslint-plugin-unicorn": "^53.0.0",
48+
"jest": "^29.7.0",
49+
"rimraf": "^5.0.7",
50+
"ts-jest": "^29.1.4",
51+
"typescript": "^5.4.5"
4152
},
4253
"dependencies": {
54+
"eslint-plugin-lodash": "^7.4.0",
4355
"isomorphic-fetch": "^3.0.0",
44-
"jsonwebtoken": "^9.0.0"
56+
"jsonwebtoken": "^9.0.2"
4557
},
4658
"prettier": {
4759
"arrowParens": "avoid",

src/client.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class DgraphClient {
1818
* The client can be backed by multiple connections (to the same server, or
1919
* multiple servers in a cluster).
2020
*/
21-
constructor(...clients: DgraphClientStub[]) {
21+
public constructor(...clients: DgraphClientStub[]) {
2222
if (clients.length === 0) {
2323
throw ERR_NO_CLIENTS;
2424
}
@@ -53,28 +53,26 @@ export class DgraphClient {
5353
return c.alter(op);
5454
}
5555

56-
public setAlphaAuthToken(authToken: string) {
56+
public setAlphaAuthToken(authToken: string): void {
5757
this.clients.forEach((c: DgraphClientStub) =>
5858
c.setAlphaAuthToken(authToken),
5959
);
6060
}
6161

6262
/**
6363
* @deprecated since v21.3 and will be removed in v21.07 release.
64-
* Please use {@link setCloudApiKey} instead.
64+
* Please use {@link setCloudApiKey} instead.
6565
*/
66-
67-
public setSlashApiKey(apiKey: string) {
66+
public setSlashApiKey(apiKey: string): void {
6867
this.setCloudApiKey(apiKey);
6968
}
7069

71-
public setCloudApiKey(apiKey: string) {
72-
this.clients.forEach((c: DgraphClientStub) => c.setCloudApiKey(apiKey));
70+
public setCloudApiKey(apiKey: string): void {
71+
this.clients.forEach((c: DgraphClientStub) =>
72+
c.setCloudApiKey(apiKey),
73+
);
7374
}
7475

75-
/**
76-
* login obtains access tokens from Dgraph Server
77-
*/
7876
public async login(userid: string, password: string): Promise<boolean> {
7977
this.debug(`Login request:\nuserid: ${userid}`);
8078

@@ -85,15 +83,11 @@ export class DgraphClient {
8583
/**
8684
* loginIntoNamespace obtains access tokens from Dgraph Server for the particular userid & namespace
8785
*/
88-
public async loginIntoNamespace(
89-
userid: string,
90-
password: string,
91-
namespace?: number,
92-
): Promise<boolean> {
86+
public async loginIntoNamespace(userid: string, password: string, namespace?: number): Promise<boolean> {
9387
this.debug(`Login request:\nuserid: ${userid}`);
9488

9589
const c = this.anyClient();
96-
return c.loginIntoNamespace(userid, password, namespace); // tslint:disable-line no-unsafe-any
90+
return c.loginIntoNamespace(userid, password, namespace); // eslint:disable-line no-unsafe-any
9791
}
9892

9993
/**
@@ -142,7 +136,8 @@ export class DgraphClient {
142136
*/
143137
public debug(msg: string): void {
144138
if (this.debugMode) {
145-
console.log(msg); // tslint:disable-line no-console
139+
// eslint-disable-next-line no-console
140+
console.log(msg);
146141
}
147142
}
148143

src/clientStub.ts

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ const DGRAPHCLOUD_API_KEY_HEADER = "X-Auth-Token";
3030
export class DgraphClientStub {
3131
private readonly addr: string;
3232
private readonly options: Options;
33-
// tslint:disable-next-line no-any
33+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
3434
private readonly jsonParser: (text: string) => any;
3535
private legacyApi: boolean;
3636
private accessToken: string;
3737
private refreshToken: string;
3838
private autoRefresh: boolean;
3939
private autoRefreshTimer?: number;
4040

41+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
4142
constructor(
4243
addr?: string,
4344
stubConfig: {
4445
legacyApi?: boolean;
45-
// tslint:disable-next-line no-any
46+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4647
jsonParser?(text: string): any;
4748
} = {},
4849
options: Options = {},
4950
) {
5051
if (addr === undefined) {
51-
// tslint:disable-next-line no-http-string
5252
this.addr = "http://localhost:8080";
5353
} else {
5454
this.addr = addr;
@@ -60,13 +60,13 @@ export class DgraphClientStub {
6060
this.jsonParser =
6161
stubConfig.jsonParser !== undefined
6262
? 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);
6565
}
6666

6767
public async detectApiVersion(): Promise<string> {
6868
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
7070
let version: string = health["version"] || health[0].version;
7171
if (version === undefined) {
7272
version = "1.0.x";
@@ -205,19 +205,19 @@ export class DgraphClientStub {
205205
) {
206206
body = `{
207207
${
208-
mu.setNquads === undefined
209-
? ""
210-
: `set {
208+
mu.setNquads === undefined
209+
? ""
210+
: `set {
211211
${mu.setNquads}
212212
}`
213-
}
213+
}
214214
${
215-
mu.deleteNquads === undefined
216-
? ""
217-
: `delete {
215+
mu.deleteNquads === undefined
216+
? ""
217+
: `delete {
218218
${mu.deleteNquads}
219219
}`
220-
}
220+
}
221221
}`;
222222
} else if (mu.mutation !== undefined) {
223223
body = mu.mutation;
@@ -250,7 +250,7 @@ export class DgraphClientStub {
250250
let nextDelim = "?";
251251
if (mu.startTs > 0) {
252252
url +=
253-
(!this.legacyApi ? `?startTs=` : `/`) + mu.startTs.toString();
253+
(!this.legacyApi ? "?startTs=" : "/") + mu.startTs.toString();
254254
nextDelim = "&";
255255
}
256256

@@ -428,15 +428,15 @@ export class DgraphClientStub {
428428
return this.callAPI("state", this.options);
429429
}
430430

431-
public setAutoRefresh(val: boolean) {
431+
public setAutoRefresh(val: boolean): void {
432432
if (!val) {
433433
this.cancelRefreshTimer();
434434
}
435435
this.autoRefresh = val;
436436
this.maybeStartRefreshTimer(this.accessToken);
437437
}
438438

439-
public setAlphaAuthToken(authToken: string) {
439+
public setAlphaAuthToken(authToken: string): void{
440440
if (this.options.headers === undefined) {
441441
this.options.headers = {};
442442
}
@@ -445,51 +445,46 @@ export class DgraphClientStub {
445445

446446
/**
447447
* @deprecated since v21.3 and will be removed in v21.07 release.
448-
* Please use {@link setCloudApiKey} instead.
448+
* Please use {@link setCloudApiKey} instead.
449449
*/
450-
451-
public setSlashApiKey(apiKey: string) {
450+
public setSlashApiKey(apiKey: string): void {
452451
this.setCloudApiKey(apiKey);
453452
}
454453

455-
public setCloudApiKey(apiKey: string) {
454+
public setCloudApiKey(apiKey: string): void {
456455
if (this.options.headers === undefined) {
457456
this.options.headers = {};
458457
}
459458
this.options.headers[DGRAPHCLOUD_API_KEY_HEADER] = apiKey;
460459
}
461460

462-
private cancelRefreshTimer() {
461+
private cancelRefreshTimer(): void {
463462
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));
466465
this.autoRefreshTimer = undefined;
467466
}
468467
}
469468

470-
private maybeStartRefreshTimer(accessToken?: string) {
469+
private maybeStartRefreshTimer(accessToken?: string): void {
471470
if (accessToken === undefined || !this.autoRefresh) {
472471
return;
473472
}
474473
this.cancelRefreshTimer();
475474

476475
const timeToWait = Math.max(
477476
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 -
480479
Date.now() -
481480
AUTO_REFRESH_PREFETCH_TIME,
482481
);
483482

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;
493488
}
494489

495490
private async callAPI<T>(path: string, config: Config): Promise<T> {
@@ -499,40 +494,38 @@ export class DgraphClientStub {
499494
config.headers[ACL_TOKEN_HEADER] = this.accessToken;
500495
}
501496

502-
// tslint:disable-next-line no-unsafe-any
497+
// eslint-disable-next-line @typescript-eslint/tslint/config
503498
const response = await fetch(url, config);
504499

505-
// tslint:disable-next-line no-unsafe-any
500+
// eslint-disable-next-line @typescript-eslint/tslint/config
506501
if (response.status >= 300 || response.status < 200) {
507-
// tslint:disable-next-line no-unsafe-any
502+
// eslint-disable-next-line @typescript-eslint/tslint/config
508503
throw new HTTPError(response);
509504
}
510505

511506
let json;
512-
// tslint:disable-next-line no-unsafe-any
507+
// eslint-disable-next-line @typescript-eslint/tslint/config
513508
const responseText: string = await response.text();
514509

515510
try {
516-
// tslint:disable-next-line no-unsafe-any
511+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
517512
json = this.jsonParser(responseText);
518513
} catch (e) {
519514
if (config.acceptRawText) {
520-
return <T>(<unknown>responseText);
515+
return (responseText as unknown) as T;
521516
}
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;
525518
err.responseText = responseText;
526519
throw err;
527520
}
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;
530523

531524
if (errors !== undefined) {
532525
throw new APIError(url, errors);
533526
}
534527

535-
return <T>json;
528+
return json as T;
536529
}
537530

538531
private getURL(path: string): string {

0 commit comments

Comments
 (0)