UNPKG

@configurator/ravendb

Version:
87 lines 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IncrementOperation = exports.DeleteOperation = exports.AppendOperation = exports.TimeSeriesOperation = void 0; const DateUtil_1 = require("../../../Utility/DateUtil"); class TimeSeriesOperation { constructor(name) { this.name = name; } serialize(conventions) { const sortedAppends = this._appends ? Array.from(this._appends.values()) .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) .map(x => x.serialize(conventions)) : null; return { Name: this.name, Appends: sortedAppends, Deletes: this._deletes ? this._deletes.map(x => x.serialize(conventions)) : null, Increments: this._increments ? Array.from(this._increments.values()).map(x => x.serialize(conventions)) : null }; } increment(incrementOperation) { if (!this._increments) { this._increments = new Map(); } const time = incrementOperation.timestamp.getTime(); if (this._increments.has(time)) { this._increments.delete(time); } this._increments.set(time, incrementOperation); } append(appendOperation) { if (!this._appends) { this._appends = new Map(); } const time = appendOperation.timestamp.getTime(); if (this._appends.has(time)) { this._appends.delete(time); } this._appends.set(time, appendOperation); } delete(deleteOperation) { if (!this._deletes) { this._deletes = []; } this._deletes.push(deleteOperation); } } exports.TimeSeriesOperation = TimeSeriesOperation; class AppendOperation { constructor(timestamp, values, tag) { this.timestamp = timestamp; this.values = values; this.tag = tag; } serialize(conventions) { return { Timestamp: DateUtil_1.DateUtil.utc.stringify(this.timestamp), Values: this.values, Tag: this.tag || undefined }; } } exports.AppendOperation = AppendOperation; class DeleteOperation { constructor(from, to) { this.from = from; this.to = to; } serialize(conventions) { return { From: this.from ? DateUtil_1.DateUtil.utc.stringify(this.from) : null, To: this.to ? DateUtil_1.DateUtil.utc.stringify(this.to) : null }; } } exports.DeleteOperation = DeleteOperation; class IncrementOperation { serialize(conventions) { return { Timestamp: this.timestamp ? DateUtil_1.DateUtil.utc.stringify(this.timestamp) : null, Values: this.values }; } } exports.IncrementOperation = IncrementOperation; //# sourceMappingURL=TimeSeriesOperation.js.map