UNPKG

redis-time-series-ts

Version:
34 lines (33 loc) 970 B
"use strict"; 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;