UNPKG

@splitsoftware/splitio-commons

Version:
62 lines (61 loc) 2.5 kB
import { __extends } from "tslib"; import { startsWith } from '../utils/lang'; import { KeyBuilder } from './KeyBuilder'; var KeyBuilderCS = /** @class */ (function (_super) { __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 (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 startsWith(key, this.prefix + ".split."); }; KeyBuilderCS.prototype.isRBSegmentKey = function (key) { return 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)); export { KeyBuilderCS }; export function myLargeSegmentsKeyBuilder(prefix, matchingKey) { return { buildSegmentNameKey: function (segmentName) { return prefix + "." + matchingKey + ".largeSegment." + segmentName; }, extractSegmentName: function (builtSegmentKeyName) { var p = prefix + "." + matchingKey + ".largeSegment."; if (startsWith(builtSegmentKeyName, p)) return builtSegmentKeyName.slice(p.length); }, buildTillKey: function () { return prefix + "." + matchingKey + ".largeSegments.till"; } }; }