UNPKG

redis-time-series-ts

Version:
135 lines (134 loc) 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestParamsBuilder = void 0; const commandKeyword_1 = require("../enum/commandKeyword"); const list_1 = require("../iterator/list"); const count_1 = require("../entity/count"); class RequestParamsBuilder { constructor() { this.reset(); } addKey(key) { this.params.push(key); return this; } addKeys(sourceKey, destKey) { if (sourceKey === destKey) { throw new Error(`source and destination key cannot be equals: ${sourceKey} != ${destKey}`); } this.params.push(sourceKey, destKey); return this; } addRetention(retention) { if (retention != null) { if (retention < 0) { throw new Error(`retention must be positive integer, found: ${retention}`); } this.params.push(commandKeyword_1.CommandKeyword.RETENTION, retention); } return this; } addLabels(labels) { if (labels != null && labels.length !== 0) { const flatLabels = new list_1.List(labels).flatten(); this.params.push(commandKeyword_1.CommandKeyword.LABELS, ...flatLabels); } return this; } addChunkSize(chunkSize) { if (chunkSize != null) { if (chunkSize < 0) { throw new Error(`chunkSize must be positive integer, found: ${chunkSize}`); } this.params.push(commandKeyword_1.CommandKeyword.CHUNK_SIZE, chunkSize); } return this; } addDuplicatePolicy(policy) { if (policy != null) { if (![`BLOCK`, `FIRST`, `LAST`, `MIN`, `MAX`, `SUM`].includes(policy)) { throw new Error(`duplicate policy must be either BLOCK, FIRST, LAST, MIN, MAX or SUM, found: ${policy}`); } this.params.push(commandKeyword_1.CommandKeyword.DUPLICATE_POLICY, policy); } return this; } addOnDuplicate(policy) { if (policy != null) { if (![`BLOCK`, `FIRST`, `LAST`, `MIN`, `MAX`, `SUM`].includes(policy)) { throw new Error(`duplicate policy must be either BLOCK, FIRST, LAST, MIN, MAX or SUM, found: ${policy}`); } this.params.push(commandKeyword_1.CommandKeyword.ON_DUPLICATE, policy); } return this; } removeLabels() { this.params.push(commandKeyword_1.CommandKeyword.LABELS); return this; } addSamples(samples) { if (samples.length !== 0) { const flatSamples = new list_1.List(samples).flatten(); this.params.push(...flatSamples); } return this; } addSample(sample) { this.params.push(...sample.flatten()); return this; } addSampleWithOptionalTimeStamp(sample) { this.params.push(sample.getKey(), sample.getValue(), commandKeyword_1.CommandKeyword.TIMESTAMP, sample.getTimestamp()); return this; } addCount(count) { if (count != null) { this.params.push(...new count_1.Count(count).flatten()); } return this; } addAggregation(aggregation) { if (aggregation != null) { this.params.push(...aggregation.flatten()); } return this; } addRange(range) { if (range != null) { this.params.push(...range.flatten()); } return this; } addFilters(filters) { const flatFilters = new list_1.List(filters.get()).flatten(); this.params.push(...flatFilters); return this; } addFiltersWithKeyword(filters) { const flatFilters = new list_1.List(filters.get()).flatten(); this.params.push(commandKeyword_1.CommandKeyword.FILTER, ...flatFilters); return this; } addWithLabels(withLabels) { if (withLabels != null && withLabels) { this.params.push(commandKeyword_1.CommandKeyword.WITHLABELS); } return this; } addUncompressed(uncompressed) { if (uncompressed != null && uncompressed) { this.params.push(commandKeyword_1.CommandKeyword.UNCOMPRESSED); } return this; } reset() { this.params = []; return this; } get() { const params = this.params; this.reset(); return params; } } exports.RequestParamsBuilder = RequestParamsBuilder;