Skip to content

Commit dad9c81

Browse files
committed
chore: fixed the lint issues in web3-adapter.
1 parent bfc0c61 commit dad9c81

File tree

4 files changed

+83
-77
lines changed

4 files changed

+83
-77
lines changed

infrastructure/web3-adapter/src/db/mapping.db.ts

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { join } from "node:path";
2+
import { promisify } from "node:util";
13
import sqlite3 from "sqlite3";
2-
import { join } from "path";
3-
import { promisify } from "util";
44

55
export class MappingDatabase {
66
private db: sqlite3.Database;
7-
private runAsync: (sql: string, params?: any) => Promise<void>;
8-
private getAsync: (sql: string, params?: any) => Promise<any>;
9-
private allAsync: (sql: string, params?: any) => Promise<any[]>;
7+
private runAsync: (sql: string, params?: string[]) => Promise<void>;
8+
private getAsync: (
9+
sql: string,
10+
params?: string[]
11+
// biome-ignore lint/suspicious/noExplicitAny: can't explicitly state that this would return an array of strings
12+
) => Promise<Record<string, string | any>>;
13+
private allAsync: (
14+
sql: string,
15+
params?: string[]
16+
// biome-ignore lint/suspicious/noExplicitAny: can't explicitly state that this would return an array of strings
17+
) => Promise<Record<string, string | any>[]>;
1018

1119
constructor(dbPath: string) {
1220
// Ensure the directory exists
@@ -47,7 +55,7 @@ export class MappingDatabase {
4755
// Validate inputs
4856
if (!params.localId || !params.globalId) {
4957
throw new Error(
50-
"Invalid mapping parameters: all fields are required",
58+
"Invalid mapping parameters: all fields are required"
5159
);
5260
}
5361

@@ -60,26 +68,18 @@ export class MappingDatabase {
6068
return;
6169
}
6270

63-
try {
64-
await this.runAsync(
65-
`INSERT INTO id_mappings (local_id, global_id)
71+
await this.runAsync(
72+
`INSERT INTO id_mappings (local_id, global_id)
6673
VALUES (?, ?)`,
67-
[params.localId, params.globalId],
68-
);
74+
[params.localId, params.globalId]
75+
);
6976

70-
const storedMapping = await this.getGlobalId(params.localId);
71-
72-
if (storedMapping !== params.globalId) {
73-
console.log(
74-
"storedMappingError",
75-
storedMapping,
76-
params.globalId,
77-
);
78-
console.error("Failed to store mapping");
79-
return;
80-
}
81-
} catch (error) {
82-
throw error;
77+
const storedMapping = await this.getGlobalId(params.localId);
78+
79+
if (storedMapping !== params.globalId) {
80+
console.log("storedMappingError", storedMapping, params.globalId);
81+
console.error("Failed to store mapping");
82+
return;
8383
}
8484
}
8585

@@ -96,7 +96,7 @@ export class MappingDatabase {
9696
`SELECT global_id
9797
FROM id_mappings
9898
WHERE local_id = ?`,
99-
[localId],
99+
[localId]
100100
);
101101
return result?.global_id ?? null;
102102
} catch (error) {
@@ -118,7 +118,7 @@ export class MappingDatabase {
118118
`SELECT local_id
119119
FROM id_mappings
120120
WHERE global_id = ?`,
121-
[globalId],
121+
[globalId]
122122
);
123123
return result?.local_id ?? null;
124124
} catch (error) {
@@ -134,15 +134,11 @@ export class MappingDatabase {
134134
return;
135135
}
136136

137-
try {
138-
await this.runAsync(
139-
`DELETE FROM id_mappings
137+
await this.runAsync(
138+
`DELETE FROM id_mappings
140139
WHERE local_id = ?`,
141-
[localId],
142-
);
143-
} catch (error) {
144-
throw error;
145-
}
140+
[localId]
141+
);
146142
}
147143

148144
/**
@@ -157,7 +153,7 @@ export class MappingDatabase {
157153
try {
158154
const results = await this.allAsync(
159155
`SELECT local_id, global_id
160-
FROM id_mappings`,
156+
FROM id_mappings`
161157
);
162158

163159
return results.map(({ local_id, global_id }) => ({

infrastructure/web3-adapter/src/evault/evault.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { GraphQLClient } from "graphql-request";
1+
import { Agent } from "node:http";
22
import axios, { type AxiosInstance } from "axios";
3+
import { GraphQLClient } from "graphql-request";
34
import { v4 } from "uuid";
45

56
export interface MetaEnvelope {
67
id?: string | null;
78
schemaId: string;
9+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
810
data: Record<string, any>;
911
w3id: string;
1012
}
@@ -71,14 +73,17 @@ interface StoreMetaEnvelopeResponse {
7173
envelopes: Array<{
7274
id: string;
7375
ontology: string;
76+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
7477
value: any;
7578
valueType: string;
7679
}>;
80+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
7781
parsed: any;
7882
};
7983
envelopes: Array<{
8084
id: string;
8185
ontology: string;
86+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
8287
value: any;
8388
valueType: string;
8489
}>;
@@ -90,14 +95,17 @@ interface StoreMetaEnvelopeResponse {
9095
envelopes: Array<{
9196
id: string;
9297
ontology: string;
98+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
9399
value: any;
94100
valueType: string;
95101
}>;
102+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
96103
parsed: any;
97104
};
98105
envelopes: Array<{
99106
id: string;
100107
ontology: string;
108+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
101109
value: any;
102110
valueType: string;
103111
}>;
@@ -122,21 +130,18 @@ export class EVaultClient {
122130
private httpClient: AxiosInstance;
123131
private isDisposed = false;
124132

125-
constructor(
126-
private registryUrl: string,
127-
private platform: string,
128-
) {
133+
constructor(private registryUrl: string, private platform: string) {
129134
// Configure axios with connection pooling and timeouts
130135
this.httpClient = axios.create({
131136
timeout: CONFIG.REQUEST_TIMEOUT,
132137
maxRedirects: 3,
133138
// Connection pooling configuration
134-
httpAgent: new (require("http").Agent)({
139+
httpAgent: new Agent({
135140
keepAlive: true,
136141
maxSockets: CONFIG.CONNECTION_POOL_SIZE,
137142
timeout: CONFIG.CONNECTION_TIMEOUT,
138143
}),
139-
httpsAgent: new (require("https").Agent)({
144+
httpsAgent: new Agent({
140145
keepAlive: true,
141146
maxSockets: CONFIG.CONNECTION_POOL_SIZE,
142147
timeout: CONFIG.CONNECTION_TIMEOUT,
@@ -169,7 +174,7 @@ export class EVaultClient {
169174
*/
170175
private async withRetry<T>(
171176
operation: () => Promise<T>,
172-
maxRetries: number = CONFIG.MAX_RETRIES,
177+
maxRetries: number = CONFIG.MAX_RETRIES
173178
): Promise<T> {
174179
let lastError: Error;
175180

@@ -194,11 +199,12 @@ export class EVaultClient {
194199
}
195200

196201
// Exponential backoff
197-
const delay = CONFIG.RETRY_DELAY * Math.pow(2, attempt);
202+
const delay = CONFIG.RETRY_DELAY * 2 ** attempt;
198203
await new Promise((resolve) => setTimeout(resolve, delay));
199204
}
200205
}
201206

207+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
202208
throw lastError!;
203209
}
204210

@@ -211,15 +217,15 @@ export class EVaultClient {
211217
const response = await this.httpClient.post<PlatformTokenResponse>(
212218
new URL(
213219
"/platforms/certification",
214-
this.registryUrl,
220+
this.registryUrl
215221
).toString(),
216222
{ platform: this.platform },
217223
{
218224
headers: {
219225
"Content-Type": "application/json",
220226
},
221227
timeout: CONFIG.REQUEST_TIMEOUT,
222-
},
228+
}
223229
);
224230

225231
const now = Date.now();
@@ -265,7 +271,7 @@ export class EVaultClient {
265271
new URL(`/resolve?w3id=${w3id}`, this.registryUrl).toString(),
266272
{
267273
timeout: CONFIG.REQUEST_TIMEOUT,
268-
},
274+
}
269275
);
270276
return new URL("/graphql", response.data.uri).toString();
271277
} catch (error) {
@@ -351,7 +357,7 @@ export class EVaultClient {
351357
{
352358
id,
353359
w3id,
354-
},
360+
}
355361
);
356362
return response.metaEnvelope;
357363
} catch (error) {
@@ -363,12 +369,12 @@ export class EVaultClient {
363369

364370
async updateMetaEnvelopeById(
365371
id: string,
366-
envelope: MetaEnvelope,
372+
envelope: MetaEnvelope
367373
): Promise<void> {
368374
return this.withRetry(async () => {
369375
console.log("sending to eVault", envelope.w3id);
370376
const client = await this.ensureClient(envelope.w3id).catch(
371-
() => null,
377+
() => null
372378
);
373379
if (!client)
374380
throw new Error("Failed to establish client connection");
@@ -386,7 +392,7 @@ export class EVaultClient {
386392
const response =
387393
await client.request<StoreMetaEnvelopeResponse>(
388394
UPDATE_META_ENVELOPE,
389-
variables,
395+
variables
390396
);
391397
} catch (error) {
392398
console.error("Error updating meta envelope:", error);

infrastructure/web3-adapter/src/index.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import * as fs from "fs/promises";
2-
import path from "path";
3-
import type { IMapping } from "./mapper/mapper.types";
4-
import { fromGlobal, toGlobal } from "./mapper/mapper";
1+
import * as fs from "node:fs/promises";
2+
import path from "node:path";
53
import { MappingDatabase } from "./db";
64
import { EVaultClient } from "./evault/evault";
7-
import { v4 as uuidv4 } from "uuid";
5+
import { fromGlobal, toGlobal } from "./mapper/mapper";
6+
import type { IMapping } from "./mapper/mapper.types";
87

98
export class Web3Adapter {
109
mapping: Record<string, IMapping> = {};
@@ -19,29 +18,29 @@ export class Web3Adapter {
1918
dbPath: string;
2019
registryUrl: string;
2120
platform: string;
22-
},
21+
}
2322
) {
2423
this.readPaths();
2524
this.mappingDb = new MappingDatabase(config.dbPath);
2625
this.evaultClient = new EVaultClient(
2726
config.registryUrl,
28-
config.platform,
27+
config.platform
2928
);
3029
this.platform = config.platform;
3130
}
3231

3332
async readPaths() {
3433
const allRawFiles = await fs.readdir(this.config.schemasPath);
3534
const mappingFiles = allRawFiles.filter((p: string) =>
36-
p.endsWith(".json"),
35+
p.endsWith(".json")
3736
);
3837

3938
for (const mappingFile of mappingFiles) {
4039
const mappingFileContent = await fs.readFile(
41-
path.join(this.config.schemasPath, mappingFile),
40+
path.join(this.config.schemasPath, mappingFile)
4241
);
4342
const mappingParsed = JSON.parse(
44-
mappingFileContent.toString(),
43+
mappingFileContent.toString()
4544
) as IMapping;
4645
this.mapping[mappingParsed.tableName] = mappingParsed;
4746
}
@@ -63,7 +62,7 @@ export class Web3Adapter {
6362
const { data, tableName, participants } = props;
6463

6564
const existingGlobalId = await this.mappingDb.getGlobalId(
66-
data.id as string,
65+
data.id as string
6766
);
6867

6968
console.log(this.mapping, tableName, this.mapping[tableName]);
@@ -122,12 +121,12 @@ export class Web3Adapter {
122121

123122
// Handle references for other participants
124123
const otherEvaults = (participants ?? []).filter(
125-
(i: string) => i !== global.ownerEvault,
124+
(i: string) => i !== global.ownerEvault
126125
);
127126
for (const evault of otherEvaults) {
128127
await this.evaultClient.storeReference(
129128
`${global.ownerEvault}/${globalId}`,
130-
evault,
129+
evault
131130
);
132131
}
133132

0 commit comments

Comments
 (0)