@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
62 lines (61 loc) • 2.68 kB
JavaScript
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.regexDefinitionsCacheKey = new RegExp("^".concat(prefix, "\\.(splits?|trafficType|flagSet)\\."));
return _this;
}
/**
* @override
*/
KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) {
return "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.").concat(segmentName);
};
KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
var prefix = "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.");
if (startsWith(builtSegmentKeyName, prefix))
return builtSegmentKeyName.slice(prefix.length);
};
KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
return "".concat(this.prefix, ".splits.lastUpdated");
};
KeyBuilderCS.prototype.isDefinitionsCacheKey = function (key) {
return this.regexDefinitionsCacheKey.test(key);
};
KeyBuilderCS.prototype.buildTillKey = function () {
return "".concat(this.prefix, ".").concat(this.matchingKey, ".segments.till");
};
KeyBuilderCS.prototype.isDefinitionKey = function (key) {
return startsWith(key, "".concat(this.prefix, ".split."));
};
KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
return startsWith(key, "".concat(this.prefix, ".rbsegment."));
};
KeyBuilderCS.prototype.buildDefinitionsWithSegmentCountKey = function () {
return "".concat(this.prefix, ".splits.usingSegments");
};
KeyBuilderCS.prototype.buildLastClear = function () {
return "".concat(this.prefix, ".lastClear");
};
return KeyBuilderCS;
}(KeyBuilder));
export { KeyBuilderCS };
export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
return {
buildSegmentNameKey: function (segmentName) {
return "".concat(prefix, ".").concat(matchingKey, ".largeSegment.").concat(segmentName);
},
extractSegmentName: function (builtSegmentKeyName) {
var p = "".concat(prefix, ".").concat(matchingKey, ".largeSegment.");
if (startsWith(builtSegmentKeyName, p))
return builtSegmentKeyName.slice(p.length);
},
buildTillKey: function () {
return "".concat(prefix, ".").concat(matchingKey, ".largeSegments.till");
}
};
}