UNPKG

@near-lake/primitives

Version:

Near Protocol primitive datatypes utilized by near-lake-framework and QueryAPI

62 lines (61 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RawEvent = exports.Event = void 0; /** * This structure is an ephemeral entity to provide access to the [Events Standard](https://github.com/near/NEPs/blob/master/neps/nep-0297.md) structure and keep data about the related `Receipt` for convenience. * * #### Interface for Capturing Data About an Event in `handleStreamerMessage()` * * The interface to capture data about an event has the following arguments: * - `standard`: name of standard, e.g. nep171 * - `version`: e.g. 1.0.0 * - `event`: type of the event, e.g. `nft_mint` * - `data`: associate event data. Strictly typed for each set {standard, version, event} inside corresponding NEP */ class Event { constructor(receiptId, rawEvent) { this.receiptId = receiptId; this.rawEvent = rawEvent; } get event() { return this.rawEvent.event; } get standard() { return this.rawEvent.standard; } get version() { return this.rawEvent.version; } get data() { return this.rawEvent.data; } get relatedReceiptId() { console.warn("relatedReceiptId is deprecated, use receiptId instead"); return this.receiptId; } } exports.Event = Event; Event.fromLog = (log, receiptId = "") => { const rawEvent = RawEvent.fromLog(log); return new Event(receiptId, rawEvent); }; /** * This structure is a copy of the [JSON Events](https://github.com/near/NEPs/blob/master/neps/nep-0297.md) structure representation. */ class RawEvent { constructor(event, standard, version, data) { this.event = event; this.standard = standard; this.version = version; this.data = data; } } exports.RawEvent = RawEvent; RawEvent.isEvent = (log) => { return log.startsWith("EVENT_JSON:"); }; RawEvent.fromLog = (log) => { const { event, standard, version, data } = JSON.parse(log.replace("EVENT_JSON:", "")); return new RawEvent(event, standard, version, data); }; ;