Skip to content

Commit b94e693

Browse files
committed
chore: fix mapper sync
1 parent 3dbefa3 commit b94e693

File tree

6 files changed

+115
-202
lines changed

6 files changed

+115
-202
lines changed

\

Lines changed: 0 additions & 165 deletions
This file was deleted.

infrastructure/web3-adapter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"graphql-request": "^6.1.0",
2121
"sqlite3": "^5.1.7",
2222
"test": "^3.3.0",
23+
"uuid": "^11.1.0",
2324
"vitest": "^3.1.2"
2425
},
2526
"devDependencies": {

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GraphQLClient } from "graphql-request";
22
import axios from "axios";
3+
import { v4 } from "uuid";
34

45
export interface MetaEnvelope {
56
id?: string | null;
@@ -102,7 +103,7 @@ export class EVaultClient {
102103
private async resolveEndpoint(w3id: string): Promise<string> {
103104
try {
104105
const response = await axios.get(
105-
new URL(`/resolve?w3id=${w3id}`, this.registryUrl).toString()
106+
new URL(`/resolve?w3id=${w3id}`, this.registryUrl).toString(),
106107
);
107108
return new URL("/graphql", response.data.uri).toString();
108109
} catch (error) {
@@ -113,14 +114,18 @@ export class EVaultClient {
113114

114115
private async ensureClient(w3id: string): Promise<GraphQLClient> {
115116
if (!this.endpoint || !this.client) {
116-
this.endpoint = await this.resolveEndpoint(w3id);
117+
this.endpoint = await this.resolveEndpoint(w3id).catch(() => null);
118+
if (!this.endpoint) throw new Error();
117119
this.client = new GraphQLClient(this.endpoint);
118120
}
119121
return this.client;
120122
}
121123

122124
async storeMetaEnvelope(envelope: MetaEnvelope): Promise<string> {
123-
const client = await this.ensureClient(envelope.w3id);
125+
const client = await this.ensureClient(envelope.w3id).catch(() => {
126+
return null;
127+
});
128+
if (!client) return v4();
124129

125130
try {
126131
const response = await client.request<StoreMetaEnvelopeResponse>(
@@ -131,7 +136,7 @@ export class EVaultClient {
131136
payload: envelope.data,
132137
acl: ["*"],
133138
},
134-
}
139+
},
135140
);
136141
return response.storeMetaEnvelope.metaEnvelope.id;
137142
} catch (error) {
@@ -154,7 +159,7 @@ export class EVaultClient {
154159
},
155160
acl: ["*"],
156161
},
157-
}
162+
},
158163
);
159164

160165
response.storeMetaEnvelope.metaEnvelope.id;
@@ -174,7 +179,7 @@ export class EVaultClient {
174179
{
175180
id,
176181
w3id,
177-
}
182+
},
178183
);
179184
return response.metaEnvelope;
180185
} catch (error) {
@@ -185,9 +190,10 @@ export class EVaultClient {
185190

186191
async updateMetaEnvelopeById(
187192
id: string,
188-
envelope: MetaEnvelope
193+
envelope: MetaEnvelope,
189194
): Promise<StoreMetaEnvelopeResponse["storeMetaEnvelope"]> {
190-
const client = await this.ensureClient(envelope.w3id);
195+
const client = await this.ensureClient(envelope.w3id).catch(() => null);
196+
if (!client) throw new Error();
191197

192198
try {
193199
const variables = {
@@ -201,7 +207,7 @@ export class EVaultClient {
201207

202208
const response = await client.request<StoreMetaEnvelopeResponse>(
203209
UPDATE_META_ENVELOPE,
204-
variables
210+
variables,
205211
);
206212
return response.updateMetaEnvelopeById;
207213
} catch (error) {

infrastructure/web3-adapter/src/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Web3Adapter {
1717
schemasPath: string;
1818
dbPath: string;
1919
registryUrl: string;
20-
}
20+
},
2121
) {
2222
this.readPaths();
2323
this.mappingDb = new MappingDatabase(config.dbPath);
@@ -27,15 +27,15 @@ export class Web3Adapter {
2727
async readPaths() {
2828
const allRawFiles = await fs.readdir(this.config.schemasPath);
2929
const mappingFiles = allRawFiles.filter((p: string) =>
30-
p.endsWith(".json")
30+
p.endsWith(".json"),
3131
);
3232

3333
for (const mappingFile of mappingFiles) {
3434
const mappingFileContent = await fs.readFile(
35-
path.join(this.config.schemasPath, mappingFile)
35+
path.join(this.config.schemasPath, mappingFile),
3636
);
3737
const mappingParsed = JSON.parse(
38-
mappingFileContent.toString()
38+
mappingFileContent.toString(),
3939
) as IMapping;
4040
this.mapping[mappingParsed.tableName] = mappingParsed;
4141
}
@@ -69,13 +69,14 @@ export class Web3Adapter {
6969
mappingStore: this.mappingDb,
7070
});
7171

72-
// Update the existing global entity
73-
// await this.evaultClient.updateMetaEnvelopeById(existingGlobalId, {
74-
// id: existingGlobalId,
75-
// w3id: global.ownerEvault as string,
76-
// data: global.data,
77-
// schemaId: this.mapping[tableName].schemaId,
78-
// });
72+
this.evaultClient
73+
.updateMetaEnvelopeById(existingGlobalId, {
74+
id: existingGlobalId,
75+
w3id: global.ownerEvault as string,
76+
data: global.data,
77+
schemaId: this.mapping[tableName].schemaId,
78+
})
79+
.catch(() => console.error("failed to sync update"));
7980

8081
return {
8182
id: existingGlobalId,
@@ -113,12 +114,12 @@ export class Web3Adapter {
113114

114115
// Handle references for other participants
115116
const otherEvaults = (participants ?? []).filter(
116-
(i: string) => i !== global.ownerEvault
117+
(i: string) => i !== global.ownerEvault,
117118
);
118119
for (const evault of otherEvaults) {
119120
await this.evaultClient.storeReference(
120121
`${global.ownerEvault}/${globalId}`,
121-
evault
122+
evault,
122123
);
123124
}
124125

platforms/blabsy/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dev URL
22
NEXT_PUBLIC_URL=http://localhost
3-
NEXT_PUBLIC_BASE_URL=http://192.168.29.208:4444
3+
NEXT_PUBLIC_BASE_URL=http://192.168.0.226:4444
44

55
# Emulator
66
NEXT_PUBLIC_USE_EMULATOR=false

0 commit comments

Comments
 (0)