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

    Class Event<T>

    An Event represents a notification or message that doesn't expect a response.

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

    // Create a status update event
    const eventId = ARID.new();
    const timestamp = new Date("2024-08-15T13:45:30Z");

    const statusEvent = Event.from("System online", eventId)
    .withNote("Regular status update")
    .withDate(timestamp);

    // Convert to an envelope for transmission
    const envelope = statusEvent.toEnvelope();

    Type Parameters

    Implements

    Index
    • get id(): ARID

      Returns the unique identifier (ARID) of the event.

      Returns ARID

    • get note(): string

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

      Returns string

    • get date(): Date | undefined

      The date attached to the event 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 event, if any: the stored CborDate, exact as decoded or given.

      Returns CborDate | undefined

    • Returns a human-readable summary of the event.

      Returns string

    • Adds a date to the event: 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 Event<T>

    • Converts the event to an envelope.

      The envelope's subject is the event's ID tagged with TAG_EVENT, and assertions include the event's content, note (if not empty), and date (if present).

      Returns Envelope

    • Reads an event from an envelope (the reference's Event::try_from(envelope)): the 'content' object through contentExtractor, the subject as TAG_EVENT(ARID), the 'note' and 'date' objects by subject extraction.

      Type Parameters

      Parameters

      Returns Event<T>

      EnvelopeError NonexistentPredicate when there is no content; General (Failed to parse content) when the extractor fails; NotLeaf / Cbor when the subject is not TAG_EVENT(ARID); Cbor / InvalidFormat when a 'note' is not text or a 'date' is not a tag-1 date

    • Returns a string representation of the event.

      Returns string

    • Checks equality with another event: the content (as envelopes), the id, the note and the exact date must all be equal (the reference's derived PartialEq).

      Parameters

      Returns boolean