Skip to content

Commit

Permalink
Updated dwn-sdk-js dependency to v0.5.1 (#950)
Browse files Browse the repository at this point in the history
* Updated dwn-sdk-js dependency to v0.5.1
* Updated dwn-server docker image
* Updated dwn-server dependency
  • Loading branch information
thehenrytsai authored Oct 10, 2024
1 parent bfa0417 commit aaf4b4a
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 51 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@changesets/cli": "^2.27.5",
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@web5/dwn-server": "0.4.10",
"@web5/dwn-server": "0.6.0",
"audit-ci": "^7.0.1",
"eslint-plugin-mocha": "10.4.3",
"globals": "^13.24.0",
Expand Down Expand Up @@ -60,4 +60,4 @@
"rollup@>=4.0.0 <4.22.4": ">=4.22.4"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"dependencies": {
"@noble/ciphers": "0.5.3",
"@scure/bip39": "1.2.2",
"@tbd54566975/dwn-sdk-js": "0.4.7",
"@tbd54566975/dwn-sdk-js": "0.5.1",
"@web5/common": "workspace:*",
"@web5/crypto": "workspace:*",
"@web5/dids": "workspace:*",
Expand Down Expand Up @@ -110,4 +110,4 @@
"sinon": "18.0.0",
"typescript": "5.1.6"
}
}
}
4 changes: 2 additions & 2 deletions packages/agent/src/store-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ export class DwnDataStore<TStoreObject extends Record<string, any> = Jwk> implem
messageParams : { filter: { recordId } }
});

if (!readReply.record?.data) {
if (!readReply.entry?.data) {
throw new Error(`${this.name}: Failed to read data from DWN for: ${recordId}`);
}

// If the record was found, convert back to store object format.
const storeObject = await NodeStream.consumeToJson({ readable: readReply.record.data }) as TStoreObject;
const storeObject = await NodeStream.consumeToJson({ readable: readReply.entry.data }) as TStoreObject;

// If caching is enabled, add the store object to the cache.
if (useCache) {
Expand Down
20 changes: 10 additions & 10 deletions packages/agent/tests/dwn-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,12 @@ describe('AgentDwnApi', () => {
const readReply = readResponse.reply;
expect(readReply).to.have.property('status');
expect(readReply.status.code).to.equal(200);
expect(readReply).to.have.property('record');
expect(readReply.record).to.have.property('data');
expect(readReply.record).to.have.property('descriptor');
expect(readReply.record).to.have.property('recordId', writeMessage.recordId);
expect(readReply).to.have.property('entry');
expect(readReply.entry).to.have.property('data');
expect(readReply.entry!.recordsWrite).to.have.property('descriptor');
expect(readReply.entry!.recordsWrite).to.have.property('recordId', writeMessage.recordId);

const readDataBytes = await NodeStream.consumeToBytes({ readable: readReply.record!.data });
const readDataBytes = await NodeStream.consumeToBytes({ readable: readReply.entry!.data! });
expect(readDataBytes).to.deep.equal(dataBytes);
});

Expand Down Expand Up @@ -1529,12 +1529,12 @@ describe('AgentDwnApi', () => {
const readReply = readResponse.reply;
expect(readReply).to.have.property('status');
expect(readReply.status.code).to.equal(200);
expect(readReply).to.have.property('record');
expect(readReply.record).to.have.property('data');
expect(readReply.record).to.have.property('descriptor');
expect(readReply.record).to.have.property('recordId', writeMessage.recordId);
expect(readReply).to.have.property('entry');
expect(readReply.entry).to.have.property('data');
expect(readReply.entry?.recordsWrite).to.have.property('descriptor');
expect(readReply.entry?.recordsWrite).to.have.property('recordId', writeMessage.recordId);

const dataStream: ReadableStream | Readable = readReply.record!.data;
const dataStream: ReadableStream | Readable = readReply.entry!.data!;
// If the data stream is a web ReadableStream, convert it to a Node.js Readable.
const nodeReadable = Stream.isReadableStream(dataStream) ?
NodeStream.fromWebReadable({ readableStream: dataStream }) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ describe('HttpDwnRpcClient', () => {

// should return success, and the record we inserted
expect(readResponse.status.code).to.equal(200);
expect(readResponse.record).to.exist;
expect(readResponse.record?.recordId).to.equal(writeMessage.recordId);
expect(readResponse.entry).to.exist;
expect(readResponse.entry?.recordsWrite?.recordId).to.equal(writeMessage.recordId);
});

it('throws error if invalid response exists in the header', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ describe('WebSocketDwnRpcClient', () => {

// should return success, and the record we inserted
expect(readResponse.status.code).to.equal(200);
expect(readResponse.record).to.exist;
expect(readResponse.record?.recordId).to.equal(writeMessage.recordId);
expect(readResponse.entry).to.exist;
expect(readResponse.entry?.recordsWrite?.recordId).to.equal(writeMessage.recordId);
});

it('subscribes to updates to a record', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/agent/tests/sync-engine-level.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,9 @@ describe('SyncEngineLevel', () => {
messageParams : { filter: { recordId: writeResponse.message!.recordId } }
});
expect(readResponse.reply.status.code).to.equal(200);
expect(readResponse.reply.record).to.exist;
expect(readResponse.reply.record!.data).to.exist;
expect(readResponse.reply.record!.descriptor.dataSize).to.equal(LARGE_DATA_SIZE);
expect(readResponse.reply.entry).to.exist;
expect(readResponse.reply.entry!.data).to.exist;
expect(readResponse.reply.entry!.recordsWrite!.descriptor.dataSize).to.equal(LARGE_DATA_SIZE);
}).slow(1200); // Yellow at 600ms, Red at 1200ms.

it('synchronizes records for multiple identities from remote DWN to local DWN', async () => {
Expand Down Expand Up @@ -1776,8 +1776,8 @@ describe('SyncEngineLevel', () => {
});
const reply = readRecord.reply;
expect(reply.status.code).to.equal(200);
expect(reply.record).to.not.be.undefined;
expect(reply.record!.data).to.not.be.undefined;
expect(reply.entry).to.exist;
expect(reply.entry!.data).to.exist;
}).slow(1200); // Yellow at 600ms, Red at 1200ms.

it('synchronizes records for multiple identities from local DWN to remote DWN', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
},
"devDependencies": {
"@playwright/test": "1.45.3",
"@tbd54566975/dwn-sdk-js": "0.4.7",
"@tbd54566975/dwn-sdk-js": "0.5.1",
"@types/chai": "4.3.6",
"@types/eslint": "8.56.10",
"@types/mocha": "10.0.1",
Expand All @@ -109,4 +109,4 @@
"source-map-loader": "4.0.2",
"typescript": "5.1.6"
}
}
}
8 changes: 5 additions & 3 deletions packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ export class DwnApi {
agentResponse = await this.agent.processDwnRequest(agentRequest);
}

const { reply: { record: responseRecord, status } } = agentResponse;
const { reply: { entry, status } } = agentResponse;

let record: Record;
if (200 <= status.code && status.code <= 299) {
Expand All @@ -773,7 +773,7 @@ export class DwnApi {
* Extract the `author` DID from the record since records may be signed by the
* tenant owner or any other entity.
*/
author : getRecordAuthor(responseRecord),
author : getRecordAuthor(entry.recordsWrite),
/**
* Set the `connectedDid` to currently connected DID so that subsequent calls to
* {@link Record} instance methods, such as `record.update()` are executed on the
Expand All @@ -788,7 +788,9 @@ export class DwnApi {
*/
remoteOrigin : request.from,
delegateDid : this.delegateDid,
...responseRecord,
data : entry.data,
initialWrite : entry.initialWrite,
...entry.recordsWrite,
};

record = new Record(this.agent, recordOptions, this.permissionsApi);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,12 +1062,12 @@ export class Record implements RecordModel {
this._agent.processDwnRequest(readRequest);

try {
const { reply: { status, record }} = await agentResponsePromise;
const { reply: { status, entry }} = await agentResponsePromise;
if (status.code !== 200) {
throw new Error(`${status.code}: ${status.detail}`);
}

const dataStream: ReadableStream | Readable = record.data;
const dataStream: ReadableStream | Readable = entry.data;
// If the data stream is a web ReadableStream, convert it to a Node.js Readable.
const nodeReadable = Stream.isReadableStream(dataStream) ?
NodeStream.fromWebReadable({ readableStream: dataStream }) :
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:0.4.10
image: ghcr.io/tbd54566975/dwn-server:0.6.0
ports:
- "3000:3000"
49 changes: 31 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaf4b4a

Please sign in to comment.