redis-time-series-ts
Version:
Javascript RedisTimeSeries client
34 lines (33 loc) • 970 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Count = void 0;
const commandKeyword_1 = require("../enum/commandKeyword");
/**
* A `count` object representing the maximum number of results to return
*/
class Count {
/**
* Creates a count object. Limits the number of items returned in a series
*
* @param count maximum number of results to return
* ```
* // Example
* const count = new Count(5000)
* count.flatten() // ['COUNT', 5000]
* ```
*/
constructor(count) {
this.count = this.validate(count);
}
flatten() {
return [commandKeyword_1.CommandKeyword.COUNT, this.count];
}
validate(count) {
const truncatedCount = Math.trunc(count);
if (truncatedCount < 0) {
throw new Error(`count must be positive, provided ${truncatedCount}`);
}
return truncatedCount;
}
}
exports.Count = Count;