Skip to content

Commit

Permalink
Add debug to lookup specific records
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Nov 12, 2024
1 parent fb24fdc commit 82a0123
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/src/app/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ export class IdentityService {
console.log('Connecting to Web5...');

// const result = await Web5.connect({ agent: customAgent, connectedDid, password, sync: this.syncInterval });
const result = await Web5.connect({ connectedDid, password, sync: this.syncInterval });
const result = await Web5.connect({
didCreateOptions: { dwnEndpoints: [] },
connectedDid,
password,
sync: this.syncInterval,
});

// Populate the accounts array with the connected accounts.
this.accounts[connectedDid] = result.web5;
Expand Down Expand Up @@ -435,6 +440,7 @@ export class IdentityService {
// }

const { web5 } = await Web5.connect({
didCreateOptions: { dwnEndpoints: [] },
// agent: this.agent,
connectedDid: uri,
password,
Expand Down Expand Up @@ -506,7 +512,12 @@ export class IdentityService {
did: userDid,
web5,
recoveryPhrase,
} = await Web5.connect({ connectedDid: did, sync: this.syncInterval, password });
} = await Web5.connect({
didCreateOptions: { dwnEndpoints: [] },
connectedDid: did,
sync: this.syncInterval,
password,
});

if (recoveryPhrase) {
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/app/settings/debug/debug.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ <h1>Debug Tool</h1>
<mat-card-title>DWN Tool</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Target DID</mat-label>
<input matInput [(ngModel)]="targetDid" placeholder="Enter DID" />
</mat-form-field>

<mat-form-field appearance="outline" class="full-width">
<mat-label>Record ID</mat-label>
<input matInput [(ngModel)]="recordId" placeholder="Enter Record ID" />
</mat-form-field>

<mat-form-field appearance="outline" subscriptSizing="dynamic" class="full-width">
<textarea rows="6" matInput #body placeholder="Query (JSON)" [(ngModel)]="query"></textarea>
</mat-form-field>
Expand All @@ -19,6 +29,7 @@ <h1>Debug Tool</h1>
<button mat-button (click)="dwnWrite()">Write</button>
<button mat-button (click)="dwnQuery()">Query</button>
<button mat-button (click)="dwnRead()">Read</button>
<button mat-button (click)="lookupRecord()" [disabled]="!targetDid || !recordId">Lookup Record</button>
</mat-card-actions>
</mat-card>

Expand Down
6 changes: 6 additions & 0 deletions app/src/app/settings/debug/debug.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
word-wrap: break-word;
font-family: monospace;
}

// In debug.component.scss
.full-width {
width: 100%;
margin-bottom: 1rem;
}
36 changes: 36 additions & 0 deletions app/src/app/settings/debug/debug.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export class DebugComponent {

syncInterval = '15s';

targetDid: string = '';
recordId: string = '';

async createInstance(num: number) {
const password = 'password' + num;

Expand Down Expand Up @@ -227,4 +230,37 @@ export class DebugComponent {
this.status = `${status.code}: ${status.detail}`;
this.result = JSON.stringify(record, null, 2);
}

async lookupRecord() {
if (!this.targetDid || !this.recordId) {
this.status = 'Error: Both DID and Record ID are required';
return;
}

try {
const { record, status } = await this.identity.web5.dwn.records.read({
// from: this.targetDid,
message: {
filter: {
recordId: this.recordId,
},
},
});

// const { record, status } = await this.identity.web5.dwn.records.read({
// from: this.targetDid,
// message: {
// filter: {
// recordId: this.recordId,
// },
// },
// });

this.status = `${status.code}: ${status.detail}`;
this.result = JSON.stringify(record, null, 2);
} catch (error) {
this.status = `Error: ${error}`;
this.result = '';
}
}
}

0 comments on commit 82a0123

Please sign in to comment.