Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bugs with Reading Remote Records and Repeated Record Data Access #327

Merged
merged 14 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ Each `Record` instance has the following instance properties: `id`, `attestation
Each `Record` instance has the following instance methods:

- **`data`** - _`object`_: an object with the following convenience methods that read out the data of the record entry in the following formats:
- **`text`** - _`function`_: produces a textual representation of the data.
- **`json`** - _`function`_: if the value is JSON data, this method will return a parsed JSON object.
- **`stream`** - _`function`_: returns the raw stream of bytes for the data.
- **`blob`** - _`function`_: returns the data as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
- **`bytes`** - _`function`_: returns the data as a raw byte array in `Uint8Array` format.
- **`json`** - _`function`_: returns a parsed JSON object.
- **`stream`** - _`function`_: returns the data as a raw stream of bytes.
- **`text`** - _`function`_: returns the data as a string.
- **`send`** - _`function`_: sends the record the instance represents to the DWeb Node endpoints of a provided DID.
- **`update`** - _`function`_: takes in a new request object matching the expected method signature of a `write` and overwrites the record. This is a convenience method that allows you to easily overwrite records with less verbosity.
- **`delete`** - _`function`_: generates a `delete` entry tombstone for the record. This is a convenience method that allows you to easily delete records with less verbosity.

### **`web5.dwn.records.query(request)`**

Expand Down
2,576 changes: 1,875 additions & 701 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ Each `Record` instance has the following instance properties: `id`, `attestation
Each `Record` instance has the following instance methods:

- **`data`** - _`object`_: an object with the following convenience methods that read out the data of the record entry in the following formats:
- **`text`** - _`function`_: produces a textual representation of the data.
- **`json`** - _`function`_: if the value is JSON data, this method will return a parsed JSON object.
- **`stream`** - _`function`_: returns the raw stream of bytes for the data.
- **`blob`** - _`function`_: returns the data as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
- **`bytes`** - _`function`_: returns the data as a raw byte array in `Uint8Array` format.
- **`json`** - _`function`_: returns a parsed JSON object.
- **`stream`** - _`function`_: returns the data as a raw stream of bytes.
- **`text`** - _`function`_: returns the data as a string.
- **`send`** - _`function`_: sends the record the instance represents to the DWeb Node endpoints of a provided DID.
- **`update`** - _`function`_: takes in a new request object matching the expected method signature of a `write` and overwrites the record. This is a convenience method that allows you to easily overwrite records with less verbosity.
- **`delete`** - _`function`_: generates a `delete` entry tombstone for the record. This is a convenience method that allows you to easily delete records with less verbosity.

### **`web5.dwn.records.query(request)`**

Expand Down
22 changes: 18 additions & 4 deletions packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,20 @@ export class DwnApi {
* Extract the `author` DID from the record entry since records may be signed by the
* tenant owner or any other entity.
*/
author : RecordsWrite.getAuthor(entry),
author : RecordsWrite.getAuthor(entry),
/**
* Set the `target` DID to currently connected DID so that subsequent calls to
* {@link Record} instance methods, such as `record.update()` are executed on the
* local DWN even if the record was returned by a query of a remote DWN.
*/
target : this.connectedDid,
target : this.connectedDid,
/**
* If the record was returned by a query of a remote DWN, set the `remoteTarget` to
* the DID of the DWN that returned the record. The `remoteTarget` will be used to
* determine which DWN to send subsequent read requests to in the event the data payload
* exceeds the threshold for being returned with queries.
*/
remoteTarget : request.from,
...entry as RecordsWriteMessage
};
const record = new Record(this.agent, recordOptions);
Expand Down Expand Up @@ -424,13 +431,20 @@ export class DwnApi {
* Extract the `author` DID from the record since records may be signed by the
* tenant owner or any other entity.
*/
author : RecordsWrite.getAuthor(responseRecord),
author : RecordsWrite.getAuthor(responseRecord),
/**
* Set the `target` DID to currently connected DID so that subsequent calls to
* {@link Record} instance methods, such as `record.update()` are executed on the
* local DWN even if the record was read from a remote DWN.
*/
target : this.connectedDid,
target : this.connectedDid,
/**
* If the record was returned by a query of a remote DWN, set the `remoteTarget` to
* the DID of the DWN that returned the record. The `remoteTarget` will be used to
* determine which DWN to send subsequent read requests to in the event the data payload
* exceeds the threshold for being returned with queries.
*/
remoteTarget : request.from,
...responseRecord,
};

Expand Down
Loading