Skip to content

Commit a3a096e

Browse files
chore(core): pgrade dependencies (#81)
* upgade dependencies * upgrade ts-jest version * remove unwanted rules
1 parent d780a8b commit a3a096e

15 files changed

+6596
-2032
lines changed

.eslintrc.js

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

package-lock.json

Lines changed: 5931 additions & 1858 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.5",
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: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ 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;
@@ -42,13 +42,12 @@ export class DgraphClientStub {
4242
addr?: string,
4343
stubConfig: {
4444
legacyApi?: boolean;
45-
// tslint:disable-next-line no-any
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4646
jsonParser?(text: string): any;
4747
} = {},
4848
options: Options = {},
4949
) {
5050
if (addr === undefined) {
51-
// tslint:disable-next-line no-http-string
5251
this.addr = "http://localhost:8080";
5352
} else {
5453
this.addr = addr;
@@ -60,13 +59,13 @@ export class DgraphClientStub {
6059
this.jsonParser =
6160
stubConfig.jsonParser !== undefined
6261
? 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);
6564
}
6665

6766
public async detectApiVersion(): Promise<string> {
6867
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
7069
let version: string = health["version"] || health[0].version;
7170
if (version === undefined) {
7271
version = "1.0.x";
@@ -205,19 +204,19 @@ export class DgraphClientStub {
205204
) {
206205
body = `{
207206
${
208-
mu.setNquads === undefined
209-
? ""
210-
: `set {
207+
mu.setNquads === undefined
208+
? ""
209+
: `set {
211210
${mu.setNquads}
212211
}`
213-
}
212+
}
214213
${
215-
mu.deleteNquads === undefined
216-
? ""
217-
: `delete {
214+
mu.deleteNquads === undefined
215+
? ""
216+
: `delete {
218217
${mu.deleteNquads}
219218
}`
220-
}
219+
}
221220
}`;
222221
} else if (mu.mutation !== undefined) {
223222
body = mu.mutation;
@@ -250,7 +249,7 @@ export class DgraphClientStub {
250249
let nextDelim = "?";
251250
if (mu.startTs > 0) {
252251
url +=
253-
(!this.legacyApi ? `?startTs=` : `/`) + mu.startTs.toString();
252+
(!this.legacyApi ? "?startTs=" : "/") + mu.startTs.toString();
254253
nextDelim = "&";
255254
}
256255

@@ -428,15 +427,15 @@ export class DgraphClientStub {
428427
return this.callAPI("state", this.options);
429428
}
430429

431-
public setAutoRefresh(val: boolean) {
430+
public setAutoRefresh(val: boolean): void {
432431
if (!val) {
433432
this.cancelRefreshTimer();
434433
}
435434
this.autoRefresh = val;
436435
this.maybeStartRefreshTimer(this.accessToken);
437436
}
438437

439-
public setAlphaAuthToken(authToken: string) {
438+
public setAlphaAuthToken(authToken: string): void{
440439
if (this.options.headers === undefined) {
441440
this.options.headers = {};
442441
}
@@ -445,51 +444,46 @@ export class DgraphClientStub {
445444

446445
/**
447446
* @deprecated since v21.3 and will be removed in v21.07 release.
448-
* Please use {@link setCloudApiKey} instead.
447+
* Please use {@link setCloudApiKey} instead.
449448
*/
450-
451-
public setSlashApiKey(apiKey: string) {
449+
public setSlashApiKey(apiKey: string): void {
452450
this.setCloudApiKey(apiKey);
453451
}
454452

455-
public setCloudApiKey(apiKey: string) {
453+
public setCloudApiKey(apiKey: string): void {
456454
if (this.options.headers === undefined) {
457455
this.options.headers = {};
458456
}
459457
this.options.headers[DGRAPHCLOUD_API_KEY_HEADER] = apiKey;
460458
}
461459

462-
private cancelRefreshTimer() {
460+
private cancelRefreshTimer(): void {
463461
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));
466464
this.autoRefreshTimer = undefined;
467465
}
468466
}
469467

470-
private maybeStartRefreshTimer(accessToken?: string) {
468+
private maybeStartRefreshTimer(accessToken?: string): void {
471469
if (accessToken === undefined || !this.autoRefresh) {
472470
return;
473471
}
474472
this.cancelRefreshTimer();
475473

476474
const timeToWait = Math.max(
477475
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 -
480478
Date.now() -
481479
AUTO_REFRESH_PREFETCH_TIME,
482480
);
483481

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;
493487
}
494488

495489
private async callAPI<T>(path: string, config: Config): Promise<T> {
@@ -499,40 +493,38 @@ export class DgraphClientStub {
499493
config.headers[ACL_TOKEN_HEADER] = this.accessToken;
500494
}
501495

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

505-
// tslint:disable-next-line no-unsafe-any
499+
// eslint-disable-next-line @typescript-eslint/tslint/config
506500
if (response.status >= 300 || response.status < 200) {
507-
// tslint:disable-next-line no-unsafe-any
501+
// eslint-disable-next-line @typescript-eslint/tslint/config
508502
throw new HTTPError(response);
509503
}
510504

511505
let json;
512-
// tslint:disable-next-line no-unsafe-any
506+
// eslint-disable-next-line @typescript-eslint/tslint/config
513507
const responseText: string = await response.text();
514508

515509
try {
516-
// tslint:disable-next-line no-unsafe-any
510+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
517511
json = this.jsonParser(responseText);
518512
} catch (e) {
519513
if (config.acceptRawText) {
520-
return <T>(<unknown>responseText);
514+
return (responseText as unknown) as T;
521515
}
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;
525517
err.responseText = responseText;
526518
throw err;
527519
}
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;
530522

531523
if (errors !== undefined) {
532524
throw new APIError(url, errors);
533525
}
534526

535-
return <T>json;
527+
return json as T;
536528
}
537529

538530
private getURL(path: string): string {

src/errors.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,32 @@ export const ERR_BEST_EFFORT_REQUIRED_READ_ONLY = new Error(
1717
export class CustomError extends Error {
1818
public readonly name: string;
1919

20-
constructor(message?: string) {
20+
public constructor(message?: string) {
2121
super(message);
2222

23-
// tslint:disable no-any no-unsafe-any
2423
this.name = new.target.name;
2524

2625
// fix the extended error prototype chain because typescript __extends implementation can't
27-
const setPrototypeOf: Function = (<any>Object).setPrototypeOf;
26+
/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/tslint/config,
27+
@typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */
28+
const setPrototypeOf: (o: any, proto: object | null) => any = (Object as any).setPrototypeOf;
2829
setPrototypeOf !== undefined
2930
? setPrototypeOf(this, new.target.prototype)
30-
: ((<any>this).__proto__ = new.target.prototype);
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-proto
32+
: ((this as any).__proto__ = new.target.prototype);
3133

32-
// try to remove contructor from stack trace
33-
const captureStackTrace: Function = (<any>Error).captureStackTrace;
34+
// try to remove constructor from stack trace
35+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
36+
const captureStackTrace: (targetObject: any, constructorOpt?: any) => void = (Error as any).captureStackTrace;
3437
if (captureStackTrace !== undefined) {
3538
captureStackTrace(this, this.constructor);
3639
}
37-
// tslint:enable no-any no-unsafe-any
40+
/* eslint-enable @typescript-eslint/ban-types, @typescript-eslint/tslint/config,
41+
@typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */
3842
}
3943
}
4044

45+
4146
export interface APIResultError {
4247
code: string;
4348
message: string;
@@ -50,7 +55,7 @@ export class APIError extends CustomError {
5055
public readonly url: string;
5156
public readonly errors: APIResultError[];
5257

53-
constructor(url: string, errors: APIResultError[]) {
58+
public constructor(url: string, errors: APIResultError[]) {
5459
super(errors.length > 0 ? errors[0].message : "API returned errors");
5560
this.url = url;
5661
this.errors = errors;
@@ -63,7 +68,7 @@ export class APIError extends CustomError {
6368
export class HTTPError extends CustomError {
6469
public readonly errorResponse: Response;
6570

66-
constructor(response: Response) {
71+
public constructor(response: Response) {
6772
super(`Invalid status code = ${response.status}`);
6873
this.errorResponse = response;
6974
}

0 commit comments

Comments
 (0)