ravendb
Version:
RavenDB client for Node.js
51 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeSeriesPolicy = void 0;
const TimeValue_js_1 = require("../../../Primitives/TimeValue.js");
const StringUtil_js_1 = require("../../../Utility/StringUtil.js");
const index_js_1 = require("../../../Exceptions/index.js");
const RawTimeSeriesTypes_js_1 = require("./RawTimeSeriesTypes.js");
class TimeSeriesPolicy {
/**
* Name of the time series policy, must be unique.
*/
name;
/**
* How long the data of this policy will be retained
*/
retentionTime;
/**
* Define the aggregation of this policy
*/
aggregationTime;
getTimeSeriesName(rawName) {
return rawName + RawTimeSeriesTypes_js_1.TIME_SERIES_ROLLUP_SEPARATOR + this.name;
}
constructor(name, aggregationTime, retentionTime) {
retentionTime = retentionTime || TimeValue_js_1.TimeValue.MAX_VALUE;
if (StringUtil_js_1.StringUtil.isNullOrEmpty(name)) {
(0, index_js_1.throwError)("InvalidArgumentException", "Name cannot be null or empty");
}
if (aggregationTime.compareTo(TimeValue_js_1.TimeValue.ZERO) <= 0) {
(0, index_js_1.throwError)("InvalidArgumentException", "Aggregation time must be greater than zero");
}
if (retentionTime.compareTo(TimeValue_js_1.TimeValue.ZERO) <= 0) {
(0, index_js_1.throwError)("InvalidArgumentException", "Retention time must be greater than zero");
}
this.retentionTime = retentionTime;
this.aggregationTime = aggregationTime;
this.name = name;
}
serialize() {
return {
Name: this.name,
RetentionTime: this.retentionTime ? this.retentionTime.serialize() : null,
AggregationTime: this.aggregationTime ? this.aggregationTime.serialize() : null
};
}
static parse(policy) {
return new TimeSeriesPolicy(policy.Name, TimeValue_js_1.TimeValue.parse(policy.AggregationTime), TimeValue_js_1.TimeValue.parse(policy.RetentionTime));
}
}
exports.TimeSeriesPolicy = TimeSeriesPolicy;
//# sourceMappingURL=TimeSeriesPolicy.js.map