UNPKG

ravendb

Version:
91 lines 2.67 kB
import { DateUtil } from "../../../Utility/DateUtil.js"; export class TimeSeriesOperation { _appends; // using map in node - for performance _deletes; _increments; name; 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); } } export class AppendOperation { timestamp; values; tag; constructor(timestamp, values, tag) { this.timestamp = timestamp; this.values = values; this.tag = tag; } serialize(conventions) { return { Timestamp: DateUtil.utc.stringify(this.timestamp), Values: this.values, Tag: this.tag || undefined }; } } export class DeleteOperation { from; to; constructor(from, to) { this.from = from; this.to = to; } serialize(conventions) { return { From: this.from ? DateUtil.utc.stringify(this.from) : null, To: this.to ? DateUtil.utc.stringify(this.to) : null }; } } export class IncrementOperation { timestamp; values; serialize(conventions) { return { Timestamp: this.timestamp ? DateUtil.utc.stringify(this.timestamp) : null, Values: this.values }; } } //# sourceMappingURL=TimeSeriesOperation.js.map