Skip to content

Commit

Permalink
Update @web5/agent to consume dwn-sdk-js v0.3.5 (#644)
Browse files Browse the repository at this point in the history
* upgrade agents

* upgrade `@web5/api` to latest `@web5/agent` `v0.3.7`

* add test for record pruning

* add tests for RecordsWriteMessage
  • Loading branch information
LiranCohen authored May 28, 2024
1 parent c43b71f commit 8b8de7a
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 138 deletions.
10 changes: 10 additions & 0 deletions .changeset/fresh-mayflies-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@web5/api": patch
---

Update `@web5/api` to the latest `@web5/agent` `v0.3.7`

Includes upgrade to `dwn-sdk-js`@`v0.3.5`

Features:
- Ability to apply the `prune` property to a `RecordsWriteDelete`
8 changes: 8 additions & 0 deletions .changeset/tough-numbers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@web5/identity-agent": patch
"@web5/proxy-agent": patch
"@web5/user-agent": patch
"@web5/agent": patch
---

Upgrade `dwn-sdk-js` to `v0.3.5`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@changesets/cli": "^2.27.1",
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@web5/dwn-server": "0.2.2",
"@web5/dwn-server": "0.2.3",
"eslint-plugin-mocha": "10.4.3",
"npkill": "0.11.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
"dependencies": {
"@noble/ciphers": "0.4.1",
"@scure/bip39": "1.2.2",
"@tbd54566975/dwn-sdk-js": "0.3.2",
"@tbd54566975/dwn-sdk-js": "0.3.5",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.1",
"@web5/dids": "1.1.0",
"abstract-level": "1.0.4",
"ed25519-keygen": "0.4.11",
"isomorphic-ws": "^5.0.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/agent/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { DidUrlDereferencer } from '@web5/dids';
import type { PaginationCursor, RecordsWriteMessage } from '@tbd54566975/dwn-sdk-js';
import type { PaginationCursor, RecordsDeleteMessage, RecordsWriteMessage } from '@tbd54566975/dwn-sdk-js';

import { DateSort } from '@tbd54566975/dwn-sdk-js';
import { Readable } from '@web5/common';
import { utils as didUtils } from '@web5/dids';
import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
import { DwnInterfaceName, DwnMethodName, Message, RecordsWrite } from '@tbd54566975/dwn-sdk-js';
import { DateSort, DwnInterfaceName, DwnMethodName, Message, Records, RecordsWrite } from '@tbd54566975/dwn-sdk-js';

export function blobToIsomorphicNodeReadable(blob: Blob): Readable {
return webReadableToIsomorphicNodeReadable(blob.stream() as ReadableStream<any>);
Expand Down Expand Up @@ -39,8 +38,8 @@ export async function getDwnServiceEndpointUrls(didUri: string, dereferencer: Di
return [];
}

export function getRecordAuthor(record: RecordsWriteMessage): string | undefined {
return RecordsWrite.getAuthor(record);
export function getRecordAuthor(record: RecordsWriteMessage | RecordsDeleteMessage): string | undefined {
return Records.getAuthor(record);
}

export function isRecordsWrite(obj: unknown): obj is RecordsWrite {
Expand Down
17 changes: 12 additions & 5 deletions packages/agent/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ describe('Utils', () => {

describe('getRecordAuthor', () => {
it('should get the author of a RecordsWriteMessage', async () => {
// create a RecordWriteMessage object
const { message, author } = await TestDataGenerator.generateRecordsWrite();
// create a RecordsWriteMessage object
const { message: recordsWriteMessage, author: recordsWriteAuthor } = await TestDataGenerator.generateRecordsWrite();

const writeAuthorFromFunction = getRecordAuthor(recordsWriteMessage);
expect(writeAuthorFromFunction).to.not.be.undefined;
expect(writeAuthorFromFunction!).to.equal(recordsWriteAuthor.did);

// create a RecordsDeleteMessage
const { message: recordsDeleteMessage, author: recordsDeleteAuthor } = await TestDataGenerator.generateRecordsDelete();

const authorFromFunction = getRecordAuthor(message);
expect(authorFromFunction).to.not.be.undefined;
expect(authorFromFunction!).to.equal(author.did);
const deleteAuthorFromFunction = getRecordAuthor(recordsDeleteMessage);
expect(deleteAuthorFromFunction).to.not.be.undefined;
expect(deleteAuthorFromFunction!).to.equal(recordsDeleteAuthor.did);
});
});
});
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
"node": ">=18.0.0"
},
"dependencies": {
"@web5/agent": "0.3.6",
"@web5/agent": "0.3.7",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.1",
"@web5/user-agent": "0.3.6"
"@web5/dids": "1.1.0",
"@web5/user-agent": "0.3.7"
},
"devDependencies": {
"@playwright/test": "1.40.1",
"@tbd54566975/dwn-sdk-js": "0.3.2",
"@tbd54566975/dwn-sdk-js": "0.3.5",
"@types/chai": "4.3.6",
"@types/eslint": "8.56.10",
"@types/mocha": "10.0.1",
Expand Down
89 changes: 89 additions & 0 deletions packages/api/tests/dwn-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,95 @@ describe('DwnApi', () => {
expect(deleteResult.status.code).to.equal(202);
});

it('deletes a record and prunes its children', async () => {
// Install a protocol that supports parent-child relationships.
const { status: protocolStatus, protocol } = await dwnAlice.protocols.configure({
message: {
definition: {
protocol : 'http://example.com/parent-child',
published : true,
types : {
foo: {
schema: 'http://example.com/foo',
},
bar: {
schema: 'http://example.com/bar'
}
},
structure: {
foo: {
bar: {}
}
}
}
}
});
expect(protocolStatus.code).to.equal(202);

// Write a parent record.
const { status: parentWriteStatus, record: parentRecord } = await dwnAlice.records.write({
data : 'Hello, world!',
message : {
protocol : protocol.definition.protocol,
protocolPath : 'foo',
schema : 'http://example.com/foo',
dataFormat : 'text/plain'
}
});
expect(parentWriteStatus.code).to.equal(202);
expect(parentRecord).to.exist;

// Write a child record.
const { status: childWriteStatus, record: childRecord } = await dwnAlice.records.write({
data : 'Hello, world!',
message : {
protocol : protocol.definition.protocol,
protocolPath : 'foo/bar',
schema : 'http://example.com/bar',
dataFormat : 'text/plain',
parentContextId : parentRecord.contextId
}
});
expect(childWriteStatus.code).to.equal(202);
expect(childRecord).to.exist;

// query for child records to confirm it exists
const { status: childrenStatus, records: childrenRecords } = await dwnAlice.records.query({
message: {
filter: {
protocol : protocol.definition.protocol,
protocolPath : 'foo/bar'
}
}
});
expect(childrenStatus.code).to.equal(200);
expect(childrenRecords).to.exist;
expect(childrenRecords).to.have.lengthOf(1);
expect(childrenRecords![0].id).to.equal(childRecord.id);

// Delete the parent record and its children.
const { status: deleteStatus } = await dwnAlice.records.delete({
message: {
recordId : parentRecord.id,
prune : true
}
});
expect(deleteStatus.code).to.equal(202);

// query for child records to confirm it was deleted
const { status: childrenStatusAfterDelete, records: childrenRecordsAfterDelete } = await dwnAlice.records.query({
message: {
filter: {
protocol : protocol.definition.protocol,
protocolPath : 'foo/bar'
}
}
});
expect(childrenStatusAfterDelete.code).to.equal(200);
expect(childrenRecordsAfterDelete).to.exist;
expect(childrenRecordsAfterDelete).to.have.lengthOf(0);
});

it('returns a 404 when the specified record does not exist', async () => {
let deleteResult = await dwnAlice.records.delete({
message: {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/tests/record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ describe('Record', () => {
// fails because record has not been stored in the local dwn yet
let updateResult = await record!.update({ data: 'bye' });
expect(updateResult.status.code).to.equal(400);
expect(updateResult.status.detail).to.equal('RecordsWriteGetInitialWriteNotFound: initial write is not found');
expect(updateResult.status.detail).to.equal('RecordsWriteGetInitialWriteNotFound: Initial write is not found.');

const { status: recordStoreStatus }= await record.store();
expect(recordStoreStatus.code).to.equal(202);
Expand Down Expand Up @@ -2235,7 +2235,7 @@ describe('Record', () => {
const [ queriedRecord ] = queryResult.records;
let updateResult = await queriedRecord!.update({ data: 'bye' });
expect(updateResult.status.code).to.equal(400);
expect(updateResult.status.detail).to.equal('RecordsWriteGetInitialWriteNotFound: initial write is not found');
expect(updateResult.status.detail).to.equal('RecordsWriteGetInitialWriteNotFound: Initial write is not found.');

// store the queried record
const { status: queriedStoreStatus } = await queriedRecord.store();
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-env/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ version: "3.98"
services:
dwn-server:
container_name: dwn-server
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.3.2
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.3.5
ports:
- "3000:3000"
2 changes: 1 addition & 1 deletion packages/identity-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@web5/agent": "0.3.7",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.1"
"@web5/dids": "1.1.0"
},
"devDependencies": {
"@playwright/test": "1.40.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@web5/agent": "0.3.7",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.1"
"@web5/dids": "1.1.0"
},
"devDependencies": {
"@playwright/test": "1.40.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/user-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@web5/agent": "0.3.7",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.0.1"
"@web5/dids": "1.1.0"
},
"devDependencies": {
"@playwright/test": "1.40.1",
Expand Down
Loading

0 comments on commit 8b8de7a

Please sign in to comment.