UNPKG

@splitsoftware/splitio-commons

Version:
66 lines (65 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.myLargeSegmentsKeyBuilder = exports.KeyBuilderCS = void 0; var tslib_1 = require("tslib"); var lang_1 = require("../utils/lang"); var KeyBuilder_1 = require("./KeyBuilder"); var KeyBuilderCS = /** @class */ (function (_super) { (0, tslib_1.__extends)(KeyBuilderCS, _super); function KeyBuilderCS(prefix, matchingKey) { var _this = _super.call(this, prefix) || this; _this.matchingKey = matchingKey; _this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet)\\."); return _this; } /** * @override */ KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) { return this.prefix + "." + this.matchingKey + ".segment." + segmentName; }; KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) { var prefix = this.prefix + "." + this.matchingKey + ".segment."; if ((0, lang_1.startsWith)(builtSegmentKeyName, prefix)) return builtSegmentKeyName.slice(prefix.length); }; KeyBuilderCS.prototype.buildLastUpdatedKey = function () { return this.prefix + ".splits.lastUpdated"; }; KeyBuilderCS.prototype.isSplitsCacheKey = function (key) { return this.regexSplitsCacheKey.test(key); }; KeyBuilderCS.prototype.buildTillKey = function () { return this.prefix + "." + this.matchingKey + ".segments.till"; }; KeyBuilderCS.prototype.isSplitKey = function (key) { return (0, lang_1.startsWith)(key, this.prefix + ".split."); }; KeyBuilderCS.prototype.isRBSegmentKey = function (key) { return (0, lang_1.startsWith)(key, this.prefix + ".rbsegment."); }; KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () { return this.prefix + ".splits.usingSegments"; }; KeyBuilderCS.prototype.buildLastClear = function () { return this.prefix + ".lastClear"; }; return KeyBuilderCS; }(KeyBuilder_1.KeyBuilder)); exports.KeyBuilderCS = KeyBuilderCS; function myLargeSegmentsKeyBuilder(prefix, matchingKey) { return { buildSegmentNameKey: function (segmentName) { return prefix + "." + matchingKey + ".largeSegment." + segmentName; }, extractSegmentName: function (builtSegmentKeyName) { var p = prefix + "." + matchingKey + ".largeSegment."; if ((0, lang_1.startsWith)(builtSegmentKeyName, p)) return builtSegmentKeyName.slice(p.length); }, buildTillKey: function () { return prefix + "." + matchingKey + ".largeSegments.till"; } }; } exports.myLargeSegmentsKeyBuilder = myLargeSegmentsKeyBuilder;