The Record class encapsulates a single record's data and metadata, providing a more developer-friendly interface for working with Decentralized Web Node (DWN) records.

Methods are provided to read, update, and manage the record's lifecycle, including writing to remote DWNs.

Implements

Constructors

Properties

_agent: Web5Agent

The Web5Agent instance that handles DWNs requests.

_attestation?: GeneralJws

Attestation JWS signature.

_author: string

The DID of the entity that authored the record.

_authorization?: AuthorizationModel

Authorization signature(s).

_connectedDid: string

The DID of the DWN tenant under which operations are being performed.

_contextId?: string

Context ID associated with the record.

_descriptor: RecordsWriteDescriptor

Descriptor detailing the record's schema, format, and other metadata.

_encodedData?: Blob

Encoded data of the record, if available.

_encryption?: EncryptionProperty

Encryption details for the record, if the data is encrypted.

_initialWrite: RecordsWriteMessage

Initial state of the record before any updates.

_initialWriteSigned: boolean

Flag indicating if the initial write has been signed by the owner.

_initialWriteStored: boolean

Flag indicating if the initial write has been stored, to prevent duplicates.

_protocolRole: string

Role under which the record is written.

_readableStream?: Readable

Stream of the record's data.

_recordId: string

Unique identifier of the record.

_remoteOrigin?: string

The origin DID if the record was fetched from a remote DWN.

_sendCache: typeof SendCache = SendCache

Cache to minimize the amount of redundant two-phase commits we do in store() and send() Retains awareness of the last 100 records stored/sent for up to 100 target DIDs each.

Accessors

  • get attestation(): GeneralJws
  • Record's signatures attestation

    Returns GeneralJws

  • get author(): string
  • DID that signed the record.

    Returns string

  • get authorization(): AuthorizationModel
  • Record's signatures attestation

    Returns AuthorizationModel

  • get contextId(): string
  • Record's context ID

    Returns string

  • get data(): {
        blob(): Promise<Blob>;
        bytes(): Promise<Uint8Array>;
        catch(onRejected?): any;
        json(): Promise<any>;
        stream(): Promise<Readable>;
        text(): Promise<string>;
        then(onFulfilled?, onRejected?): any;
    }
  • Beta

    Returns the data of the current record. If the record data is not available, it attempts to fetch the data from the DWN.

    Returns {
        blob(): Promise<Blob>;
        bytes(): Promise<Uint8Array>;
        catch(onRejected?): any;
        json(): Promise<any>;
        stream(): Promise<Readable>;
        text(): Promise<string>;
        then(onFulfilled?, onRejected?): any;
    }

    a data stream with convenience methods such as blob(), json(), text(), and stream(), similar to the fetch API response

    • blob:function
      • Beta

        Returns the data of the current record as a Blob.

        Returns Promise<Blob>

        A promise that resolves to a Blob containing the record's data.

        Throws

        If the record data is not available or cannot be converted to a Blob.

    • bytes:function
      • Beta

        Returns the data of the current record as a Uint8Array.

        Returns Promise<Uint8Array>

        A Promise that resolves to a Uint8Array containing the record's data bytes.

        Throws

        If the record data is not available or cannot be converted to a byte array.

    • catch:function
      • Attaches a rejection handler callback to the Promise returned by the stream() method. This method is a shorthand for .then(undefined, onRejected), specifically designed for handling rejection cases in the promise chain initiated by accessing the record's data. It ensures that errors during data retrieval or processing can be caught and handled appropriately.

        Parameters

        • Optional onRejected: ((reason) => PromiseLike<never>)

          A function to asynchronously execute when the stream() promise becomes rejected.

            • (reason): PromiseLike<never>
            • Parameters

              • reason: any

              Returns PromiseLike<never>

        Returns any

        A Promise that resolves to the value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.

    • json:function
      • Beta

        Parses the data of the current record as JSON and returns it as a JavaScript object.

        Returns Promise<any>

        A Promise that resolves to a JavaScript object parsed from the record's JSON data.

        Throws

        If the record data is not available, not in JSON format, or cannot be parsed.

    • stream:function
      • Beta

        Provides a Readable stream containing the record's data.

        Returns Promise<Readable>

        A promise that resolves to a Node.js Readable stream of the record's data.

        Throws

        If the record data is not available in-memory and cannot be fetched.

    • text:function
      • Beta

        Returns the data of the current record as a string.

        Returns Promise<string>

        A promise that resolves to a string containing the record's text data.

        Throws

        If the record data is not available or cannot be converted to text.

    • then:function
      • Attaches callbacks for the resolution and/or rejection of the Promise returned by stream().

        This method is a proxy to the then method of the Promise returned by stream(), allowing for a seamless integration with promise-based workflows.

        Parameters

        • Optional onFulfilled: ((value) => Readable | PromiseLike<Readable>)

          A function to asynchronously execute when the stream() promise becomes fulfilled.

            • (value): Readable | PromiseLike<Readable>
            • Parameters

              • value: Readable

              Returns Readable | PromiseLike<Readable>

        • Optional onRejected: ((reason) => PromiseLike<never>)

          A function to asynchronously execute when the stream() promise becomes rejected.

            • (reason): PromiseLike<never>
            • Parameters

              • reason: any

              Returns PromiseLike<never>

        Returns any

        A Promise for the completion of which ever callback is executed.

    Throws

    Error if the record has already been deleted.

  • get dataCid(): string
  • Record's CID

    Returns string

  • get dataFormat(): string
  • Record's data format

    Returns string

  • get dataSize(): number
  • Record's data size

    Returns number

  • get dateCreated(): string
  • Record's creation date

    Returns string

  • get dateModified(): string
  • Record's modified date

    Returns string

  • get datePublished(): string
  • Record's published date

    Returns string

  • get encryption(): EncryptionProperty
  • Record's encryption

    Returns EncryptionProperty

  • get id(): string
  • Record's ID

    Returns string

  • get initialWrite(): RecordsWriteMessage
  • Record's initial write if the record has been updated

    Returns RecordsWriteMessage

  • get interface(): Records
  • Interface is always Records

    Returns Records

  • get messageTimestamp(): string
  • Record's published status

    Returns string

  • get method(): Write
  • Method is always Write

    Returns Write

  • get parentId(): string
  • Record's parent ID

    Returns string

  • get protocol(): string
  • Record's protocol

    Returns string

  • get protocolPath(): string
  • Record's protocol path

    Returns string

  • get protocolRole(): string
  • Role under which the author is writing the record

    Returns string

  • get published(): boolean
  • Record's published status (true/false)

    Returns boolean

  • get rawMessage(): RecordsWriteMessage
  • Returns a copy of the raw RecordsWriteMessage that was used to create the current Record instance.

    Returns RecordsWriteMessage

  • get recipient(): string
  • Record's recipient

    Returns string

  • get schema(): string
  • Record's schema

    Returns string

  • get tags(): RecordsWriteTags
  • Returns RecordsWriteTags

Methods

  • Beta

    Signs the current record state as well as any initial write and optionally stores it to the owner's DWN. This is useful when importing a record that was signed by someone else into your own DWN.

    Parameters

    • store: boolean = true

      if true, the record will be stored to the owner's DWN after signing. Defaults to true.

    Returns Promise<DwnResponseStatus>

    the status of the import request

  • Handles the various conditions around there being an initial write, whether to store initial/current state, and whether to add an owner signature to the initial write to enable storage when protocol rules require it.

    Parameters

    • __namedParameters: {
          signAsOwner: boolean;
          store: boolean;
      }
      • signAsOwner: boolean
      • store: boolean

    Returns Promise<DwnResponseStatus>

  • Beta

    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. It makes a read request to the specified DWN and processes the response to provide a Node.js Readable stream of the record's data.

    Parameters

    • params: {
          isRemote: boolean;
          target: string;
      }

      Parameters for fetching the record's data.

      • isRemote: boolean

        Indicates whether the target DWN is a remote node.

      • target: string

        The DID of the DWN to fetch the data from.

    Returns Promise<Readable>

    A Promise that resolves to a Node.js Readable stream of the record's data.

    Throws

    If there is an error while fetching or processing the data from the DWN.

  • Beta

    Send the current record to a remote DWN by specifying their DID If no DID is specified, the target is assumed to be the owner (connectedDID). If an initial write is present and the Record class send cache has no awareness of it, the initial write is sent first (vs waiting for the regular DWN sync)

    Parameters

    • Optional target: string

      the optional DID to send the record to, if none is set it is sent to the connectedDid

    Returns Promise<DwnResponseStatus>

    the status of the send record request

    Throws

    Error if the record has already been deleted.

  • Beta

    Stores the current record state as well as any initial write to the owner's DWN.

    Parameters

    • importRecord: boolean = false

      if true, the record will signed by the owner before storing it to the owner's DWN. Defaults to false.

    Returns Promise<DwnResponseStatus>

    the status of the store request

  • Returns a JSON representation of the Record instance. It's called by JSON.stringify(...) automatically.

    Returns RecordModel

  • Convenience method to return the string representation of the Record instance. Called automatically in string concatenation, String() type conversion, and template literals.

    Returns string

  • Beta

    Update the current record on the DWN.

    Parameters

    Returns Promise<DwnResponseStatus>

    the status of the update request

    Throws

    Error if the record has already been deleted.

  • Beta

    Verifies if the properties to be mutated are mutable.

    This private method is used to ensure that only mutable properties of the Record instance are being changed. It checks whether the properties specified for mutation are among the set of properties that are allowed to be modified. If any of the properties to be mutated are not in the set of mutable properties, the method throws an error.

    Parameters

    • propertiesToMutate: Iterable<string>

      An iterable of property names that are intended to be mutated.

    • mutableDescriptorProperties: Set<string>

      A set of property names that are allowed to be mutated.

    Returns void

    Throws

    If any of the properties in propertiesToMutate are not in mutableDescriptorProperties.

Generated using TypeDoc