@blockchaincommons/envelope - v1.0.0-beta.4
    Preparing search index...

    Class Request

    A Request represents a message requesting execution of a function with parameters.

    import { Request, ARID } from '@blockchaincommons/envelope';

    // Create a random request ID
    const requestId = ARID.new();

    // Create a request to execute a function with parameters
    const request = Request.from("getBalance", requestId)
    .withParameter("account", "alice")
    .withParameter("currency", "USD")
    .withNote("Monthly balance check");

    // Convert to an envelope
    const envelope = request.toEnvelope();

    Implements

    Index
    • get note(): string

      Returns the note attached to the request, or an empty string if none exists.

      Returns string

    • get date(): Date | undefined

      The date attached to the request as a JavaScript Date (millisecond precision), if any; cborDate is the exact value.

      Returns Date | undefined

    • get cborDate(): CborDate | undefined

      The date attached to the request, if any: the stored CborDate, exact as decoded or given.

      Returns CborDate | undefined

    • Returns a human-readable summary of the request.

      Returns string

    • Adds a date to the request: a CborDate is kept as it is (the reference's Date, exact to the nanosecond); a JavaScript Date converts through CborDate.fromDate.

      Parameters

      • date: Date | CborDate

      Returns Request

    • Converts the request to an envelope.

      The envelope's subject is the request's ID tagged with TAG_REQUEST, and assertions include the request's body, note (if not empty), and date (if present).

      Returns Envelope

    • Reads a request from an envelope (the reference's Request::try_from((envelope, expected_function))): the 'body' object as an expression, the subject as TAG_REQUEST(ARID), the 'note' and 'date' objects by subject extraction.

      Parameters

      Returns Request

      EnvelopeError NonexistentPredicate / AmbiguousPredicate when the body is not exactly one; Cbor (dcbor error: <reason>) when the body is not an expression or is not expectedFunction; NotLeaf / Cbor when the subject is not TAG_REQUEST(ARID); Cbor / InvalidFormat when a 'note' is not text or a 'date' is not a tag-1 date

    • Checks equality with another request: the id, the note, the exact date and the body envelope must all be equal (the reference's derived PartialEq).

      Parameters

      Returns boolean