Skip to content

Commit 56bd67b

Browse files
committed
chore: formatted web3-adapters.
1 parent dad9c81 commit 56bd67b

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export class MappingDatabase {
77
private runAsync: (sql: string, params?: string[]) => Promise<void>;
88
private getAsync: (
99
sql: string,
10-
params?: string[]
10+
params?: string[],
1111
// biome-ignore lint/suspicious/noExplicitAny: can't explicitly state that this would return an array of strings
1212
) => Promise<Record<string, string | any>>;
1313
private allAsync: (
1414
sql: string,
15-
params?: string[]
15+
params?: string[],
1616
// biome-ignore lint/suspicious/noExplicitAny: can't explicitly state that this would return an array of strings
1717
) => Promise<Record<string, string | any>[]>;
1818

@@ -55,7 +55,7 @@ export class MappingDatabase {
5555
// Validate inputs
5656
if (!params.localId || !params.globalId) {
5757
throw new Error(
58-
"Invalid mapping parameters: all fields are required"
58+
"Invalid mapping parameters: all fields are required",
5959
);
6060
}
6161

@@ -71,7 +71,7 @@ export class MappingDatabase {
7171
await this.runAsync(
7272
`INSERT INTO id_mappings (local_id, global_id)
7373
VALUES (?, ?)`,
74-
[params.localId, params.globalId]
74+
[params.localId, params.globalId],
7575
);
7676

7777
const storedMapping = await this.getGlobalId(params.localId);
@@ -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) {
@@ -137,7 +137,7 @@ export class MappingDatabase {
137137
await this.runAsync(
138138
`DELETE FROM id_mappings
139139
WHERE local_id = ?`,
140-
[localId]
140+
[localId],
141141
);
142142
}
143143

@@ -153,7 +153,7 @@ export class MappingDatabase {
153153
try {
154154
const results = await this.allAsync(
155155
`SELECT local_id, global_id
156-
FROM id_mappings`
156+
FROM id_mappings`,
157157
);
158158

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

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export class EVaultClient {
130130
private httpClient: AxiosInstance;
131131
private isDisposed = false;
132132

133-
constructor(private registryUrl: string, private platform: string) {
133+
constructor(
134+
private registryUrl: string,
135+
private platform: string,
136+
) {
134137
// Configure axios with connection pooling and timeouts
135138
this.httpClient = axios.create({
136139
timeout: CONFIG.REQUEST_TIMEOUT,
@@ -174,7 +177,7 @@ export class EVaultClient {
174177
*/
175178
private async withRetry<T>(
176179
operation: () => Promise<T>,
177-
maxRetries: number = CONFIG.MAX_RETRIES
180+
maxRetries: number = CONFIG.MAX_RETRIES,
178181
): Promise<T> {
179182
let lastError: Error;
180183

@@ -217,15 +220,15 @@ export class EVaultClient {
217220
const response = await this.httpClient.post<PlatformTokenResponse>(
218221
new URL(
219222
"/platforms/certification",
220-
this.registryUrl
223+
this.registryUrl,
221224
).toString(),
222225
{ platform: this.platform },
223226
{
224227
headers: {
225228
"Content-Type": "application/json",
226229
},
227230
timeout: CONFIG.REQUEST_TIMEOUT,
228-
}
231+
},
229232
);
230233

231234
const now = Date.now();
@@ -271,7 +274,7 @@ export class EVaultClient {
271274
new URL(`/resolve?w3id=${w3id}`, this.registryUrl).toString(),
272275
{
273276
timeout: CONFIG.REQUEST_TIMEOUT,
274-
}
277+
},
275278
);
276279
return new URL("/graphql", response.data.uri).toString();
277280
} catch (error) {
@@ -357,7 +360,7 @@ export class EVaultClient {
357360
{
358361
id,
359362
w3id,
360-
}
363+
},
361364
);
362365
return response.metaEnvelope;
363366
} catch (error) {
@@ -369,12 +372,12 @@ export class EVaultClient {
369372

370373
async updateMetaEnvelopeById(
371374
id: string,
372-
envelope: MetaEnvelope
375+
envelope: MetaEnvelope,
373376
): Promise<void> {
374377
return this.withRetry(async () => {
375378
console.log("sending to eVault", envelope.w3id);
376379
const client = await this.ensureClient(envelope.w3id).catch(
377-
() => null
380+
() => null,
378381
);
379382
if (!client)
380383
throw new Error("Failed to establish client connection");
@@ -392,7 +395,7 @@ export class EVaultClient {
392395
const response =
393396
await client.request<StoreMetaEnvelopeResponse>(
394397
UPDATE_META_ENVELOPE,
395-
variables
398+
variables,
396399
);
397400
} catch (error) {
398401
console.error("Error updating meta envelope:", error);

infrastructure/web3-adapter/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ export class Web3Adapter {
1818
dbPath: string;
1919
registryUrl: string;
2020
platform: string;
21-
}
21+
},
2222
) {
2323
this.readPaths();
2424
this.mappingDb = new MappingDatabase(config.dbPath);
2525
this.evaultClient = new EVaultClient(
2626
config.registryUrl,
27-
config.platform
27+
config.platform,
2828
);
2929
this.platform = config.platform;
3030
}
3131

3232
async readPaths() {
3333
const allRawFiles = await fs.readdir(this.config.schemasPath);
3434
const mappingFiles = allRawFiles.filter((p: string) =>
35-
p.endsWith(".json")
35+
p.endsWith(".json"),
3636
);
3737

3838
for (const mappingFile of mappingFiles) {
3939
const mappingFileContent = await fs.readFile(
40-
path.join(this.config.schemasPath, mappingFile)
40+
path.join(this.config.schemasPath, mappingFile),
4141
);
4242
const mappingParsed = JSON.parse(
43-
mappingFileContent.toString()
43+
mappingFileContent.toString(),
4444
) as IMapping;
4545
this.mapping[mappingParsed.tableName] = mappingParsed;
4646
}
@@ -62,7 +62,7 @@ export class Web3Adapter {
6262
const { data, tableName, participants } = props;
6363

6464
const existingGlobalId = await this.mappingDb.getGlobalId(
65-
data.id as string
65+
data.id as string,
6666
);
6767

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

122122
// Handle references for other participants
123123
const otherEvaults = (participants ?? []).filter(
124-
(i: string) => i !== global.ownerEvault
124+
(i: string) => i !== global.ownerEvault,
125125
);
126126
for (const evault of otherEvaults) {
127127
await this.evaultClient.storeReference(
128128
`${global.ownerEvault}/${globalId}`,
129-
evault
129+
evault,
130130
);
131131
}
132132

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function getValueByPath(obj: Record<string, any>, path: string): any {
1717
// If there's a field path after [], map through the array
1818
if (fieldPath) {
1919
return array.map((item) =>
20-
getValueByPath(item, fieldPath.slice(1))
20+
getValueByPath(item, fieldPath.slice(1)),
2121
); // Remove the leading dot
2222
}
2323

@@ -35,7 +35,7 @@ export function getValueByPath(obj: Record<string, any>, path: string): any {
3535

3636
async function extractOwnerEvault(
3737
data: Record<string, unknown>,
38-
ownerEnamePath: string
38+
ownerEnamePath: string,
3939
): Promise<string | null> {
4040
if (!ownerEnamePath || ownerEnamePath === "null") {
4141
return null;
@@ -63,7 +63,7 @@ export async function fromGlobal({
6363
const result: Record<string, unknown> = {};
6464

6565
for (const [localKey, globalPathRaw] of Object.entries(
66-
mapping.localToUniversalMap
66+
mapping.localToUniversalMap,
6767
)) {
6868
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
6969
let value: any;
@@ -79,7 +79,7 @@ export async function fromGlobal({
7979
if (calcMatch) {
8080
const calcResult = evaluateCalcExpression(
8181
calcMatch[1],
82-
data
82+
data,
8383
);
8484
value =
8585
calcResult !== undefined
@@ -120,7 +120,7 @@ export async function fromGlobal({
120120
const localId = await mappingStore.getLocalId(v);
121121

122122
return localId ? `${tableRef}(${localId})` : null;
123-
})
123+
}),
124124
);
125125
} else {
126126
value = await mappingStore.getLocalId(value);
@@ -139,7 +139,7 @@ export async function fromGlobal({
139139
function evaluateCalcExpression(
140140
expr: string,
141141
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
142-
context: Record<string, any>
142+
context: Record<string, any>,
143143
): number | undefined {
144144
const tokens = expr
145145
.split(/[^\w.]+/)
@@ -152,7 +152,7 @@ function evaluateCalcExpression(
152152
if (typeof value !== "undefined") {
153153
resolvedExpr = resolvedExpr.replace(
154154
new RegExp(`\\b${token.replace(".", "\\.")}\\b`, "g"),
155-
value
155+
value,
156156
);
157157
}
158158
}
@@ -172,7 +172,7 @@ export async function toGlobal({
172172
const result: Record<string, unknown> = {};
173173

174174
for (const [localKey, globalPathRaw] of Object.entries(
175-
mapping.localToUniversalMap
175+
mapping.localToUniversalMap,
176176
)) {
177177
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
178178
let value: any;
@@ -205,7 +205,7 @@ export async function toGlobal({
205205
if (calcMatch) {
206206
const calcResult = evaluateCalcExpression(
207207
calcMatch[1],
208-
data
208+
data,
209209
);
210210
value =
211211
calcResult !== undefined
@@ -263,8 +263,8 @@ export async function toGlobal({
263263
value = await Promise.all(
264264
value.map(
265265
async (v) =>
266-
(await mappingStore.getGlobalId(v)) ?? undefined
267-
)
266+
(await mappingStore.getGlobalId(v)) ?? undefined,
267+
),
268268
);
269269
} else {
270270
value = (await mappingStore.getGlobalId(value)) ?? undefined;

0 commit comments

Comments
 (0)