-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathKeyBuilderCS.ts
More file actions
75 lines (58 loc) · 2.06 KB
/
KeyBuilderCS.ts
File metadata and controls
75 lines (58 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { startsWith } from '../utils/lang';
import { KeyBuilder } from './KeyBuilder';
export interface MySegmentsKeyBuilder {
buildSegmentNameKey(segmentName: string): string;
extractSegmentName(builtSegmentKeyName: string): string | undefined;
buildTillKey(): string;
}
export class KeyBuilderCS extends KeyBuilder implements MySegmentsKeyBuilder {
protected readonly regexSplitsCacheKey: RegExp;
protected readonly matchingKey: string;
constructor(prefix: string, matchingKey: string) {
super(prefix);
this.matchingKey = matchingKey;
this.regexSplitsCacheKey = new RegExp(`^${prefix}\\.(splits?|trafficType|flagSet|rbsegment)\\.`);
}
/**
* @override
*/
buildSegmentNameKey(segmentName: string) {
return `${this.prefix}.${this.matchingKey}.segment.${segmentName}`;
}
extractSegmentName(builtSegmentKeyName: string) {
const prefix = `${this.prefix}.${this.matchingKey}.segment.`;
if (startsWith(builtSegmentKeyName, prefix)) return builtSegmentKeyName.slice(prefix.length);
}
buildLastUpdatedKey() {
return `${this.prefix}.splits.lastUpdated`;
}
isSplitsCacheKey(key: string) {
return this.regexSplitsCacheKey.test(key);
}
buildTillKey() {
return `${this.prefix}.${this.matchingKey}.segments.till`;
}
isSplitKey(key: string) {
return startsWith(key, `${this.prefix}.split.`);
}
isRBSegmentKey(key: string) {
return startsWith(key, `${this.prefix}.rbsegment.`);
}
buildSplitsWithSegmentCountKey() {
return `${this.prefix}.splits.usingSegments`;
}
}
export function myLargeSegmentsKeyBuilder(prefix: string, matchingKey: string): MySegmentsKeyBuilder {
return {
buildSegmentNameKey(segmentName: string) {
return `${prefix}.${matchingKey}.largeSegment.${segmentName}`;
},
extractSegmentName(builtSegmentKeyName: string) {
const p = `${prefix}.${matchingKey}.largeSegment.`;
if (startsWith(builtSegmentKeyName, p)) return builtSegmentKeyName.slice(p.length);
},
buildTillKey() {
return `${prefix}.${matchingKey}.largeSegments.till`;
}
};
}