ravendb
Version:
RavenDB client for Node.js
47 lines • 1.83 kB
JavaScript
import { TimeValue } from "../../../Primitives/TimeValue.js";
import { StringUtil } from "../../../Utility/StringUtil.js";
import { throwError } from "../../../Exceptions/index.js";
import { TIME_SERIES_ROLLUP_SEPARATOR } from "./RawTimeSeriesTypes.js";
export 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 + TIME_SERIES_ROLLUP_SEPARATOR + this.name;
}
constructor(name, aggregationTime, retentionTime) {
retentionTime = retentionTime || TimeValue.MAX_VALUE;
if (StringUtil.isNullOrEmpty(name)) {
throwError("InvalidArgumentException", "Name cannot be null or empty");
}
if (aggregationTime.compareTo(TimeValue.ZERO) <= 0) {
throwError("InvalidArgumentException", "Aggregation time must be greater than zero");
}
if (retentionTime.compareTo(TimeValue.ZERO) <= 0) {
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.parse(policy.AggregationTime), TimeValue.parse(policy.RetentionTime));
}
}
//# sourceMappingURL=TimeSeriesPolicy.js.map