Skip to content

Commit

Permalink
Rename remoteTarget to remoteOrigin
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Dec 9, 2023
1 parent b919cfc commit 585be3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
21 changes: 10 additions & 11 deletions packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export class DwnApi {
// Remove target from inherited properties since target is being explicitly defined in method parameters.
delete inheritedProperties.target;


// If `data` is being updated then `dataCid` and `dataSize` must not be present.
if (request.data !== undefined) {
delete inheritedProperties.dataCid;
Expand Down Expand Up @@ -379,12 +378,12 @@ export class DwnApi {
*/
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.
* If the record was returned by a query of a remote DWN, set the `remoteOrigin` to
* the DID of the DWN that returned the record. The `remoteOrigin` property 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,
remoteOrigin : request.from,
...entry as RecordsWriteMessage
};
const record = new Record(this.agent, recordOptions);
Expand Down Expand Up @@ -439,12 +438,12 @@ export class DwnApi {
*/
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.
* If the record was returned by reading from a remote DWN, set the `remoteOrigin` to
* the DID of the DWN that returned the record. The `remoteOrigin` property will be used
* to determine which DWN to send subsequent read requests to in the event the data
* payload must be read again (e.g., if the data stream is consumed).
*/
remoteTarget : request.from,
remoteOrigin : request.from,
...responseRecord,
};

Expand Down
28 changes: 14 additions & 14 deletions packages/api/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type RecordOptions = RecordsWriteMessage & {
target: string;
encodedData?: string | Blob;
data?: Readable | ReadableStream;
remoteTarget?: string;
remoteOrigin?: string;
};

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ export class Record implements RecordModel {
private _encryption?: RecordsWriteMessage['encryption'];
private _readableStream?: Readable;
private _recordId: string;
private _remoteTarget?: string;
private _remoteOrigin?: string;

// Immutable DWN Record properties.

Expand Down Expand Up @@ -155,10 +155,11 @@ export class Record implements RecordModel {
this.author = options.author;
this.target = options.target;

/** If the record was queried from a remote DWN, the `remoteTarget` DID will be defined. This
* value is used to send subsequent read requests to the same remote DWN in the event the
* record's data payload was too large to be returned in query results. */
this._remoteTarget = options.remoteTarget;
/** If the record was queried or read from a remote DWN, the `remoteOrigin` DID will be
* defined. This value is used to send subsequent read requests to the same remote DWN in the
* event the record's data payload was too large to be returned in query results. or must be
* read again (e.g., if the data stream is consumed). */
this._remoteOrigin = options.remoteOrigin;

// RecordsWriteMessage properties.
this._attestation = options.attestation;
Expand Down Expand Up @@ -264,13 +265,12 @@ export class Record implements RecordModel {
self._readableStream = NodeStream.fromWebReadable({ readableStream: self._encodedData.stream() });

} else if (!NodeStream.isReadable({ readable: self._readableStream })) {
/** If `encodedData` is not set, then the Record was instantiated by `dwn.records.read()`
* or was too large to be returned in `dwn.records.query()` results. In either case, the
* data is not available in-memory and must be fetched from either: */
self._readableStream = self._remoteTarget ?
// 1. ...a remote DWN if the record was queried from a remote DWN.
await self.readRecordData({ target: self._remoteTarget, isRemote: true }) :
// 2. ...a local DWN if the record was queried from the local DWN.
/** If the data stream for this `Record` instance has already been partially or fully
* consumed, then the data must be fetched again from either: */
self._readableStream = self._remoteOrigin ?
// A. ...a remote DWN if the record was originally queried from a remote DWN.
await self.readRecordData({ target: self._remoteOrigin, isRemote: true }) :
// B. ...a local DWN if the record was originally queried from the local DWN.
await self.readRecordData({ target: self.target, isRemote: false });
}

Expand Down Expand Up @@ -440,7 +440,7 @@ export class Record implements RecordModel {
}

/**
* Fetches the record's data from the source DWN.
* Fetches the record's data from the specified DWN.
*
* This private method is called when the record data is not available in-memory
* and needs to be fetched from either a local or a remote DWN.
Expand Down

0 comments on commit 585be3f

Please sign in to comment.