UNPKG

diffusion

Version:

Diffusion JavaScript client

68 lines (67 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventImpl = void 0; /** * Implementation of a time series event */ var EventImpl = /** @class */ (function () { /** * Create a new EventImpl instance * * @param metadata the metadata of the event * @param originalEvent the original event * @param value the value of the event */ function EventImpl(metadata, originalEvent, value) { this.metadata = metadata; this.originalEvent = originalEvent; this.value = value; this.sequence = metadata.sequence; this.timestamp = metadata.timestamp; this.author = metadata.author; this.isEditEvent = !metadata.equals(originalEvent); this.isOriginalEvent = !this.isEditEvent; } /** * Static factory to create a new EventImpl instance * * @param metadata the metadata of the event * @param originalEvent the original event * @param value the value of the event * @return a new EventImpl instance */ EventImpl.create = function (metadata, originalEvent, value) { return new EventImpl(metadata, originalEvent, value); }; /** * Createa copy of this EventImpl with a different value * * @param newValue the new value * @return a new EventImpl instance */ EventImpl.prototype.withValue = function (newValue) { return new EventImpl(this.metadata, this.originalEvent, newValue); }; /** * @inheritdoc */ EventImpl.prototype.equals = function (other) { if (other && other instanceof EventImpl) { return this.metadata.equals(other.metadata) && this.originalEvent.equals(other.originalEvent) && this.value === other.value; } return false; }; /** * Convert the time series event into a string * * @return a string representation of the event */ EventImpl.prototype.toString = function () { var s = this.isEditEvent ? "Edit of [" + this.originalEvent + "]" : ''; return s + "[" + this.metadata + "] " + this.value; }; return EventImpl; }()); exports.EventImpl = EventImpl;