Skip to content

Commit cec23c8

Browse files
make IRBSegment conditions and excluded properties optional
1 parent ea66074 commit cec23c8

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/dtos/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ export interface IRBSegment {
203203
name: string,
204204
changeNumber: number,
205205
status: 'ACTIVE' | 'ARCHIVED',
206-
conditions: ISplitCondition[],
207-
excluded: {
208-
keys: string[],
209-
segments: string[]
206+
conditions?: ISplitCondition[],
207+
excluded?: {
208+
keys?: string[],
209+
segments?: string[]
210210
}
211211
}
212212

src/evaluator/matchers/rbsegment.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
1212
return function ruleBasedSegmentMatcher({ key, attributes }: IDependencyMatcherValue, splitEvaluator: ISplitEvaluator): MaybeThenable<boolean> {
1313

1414
function matchConditions(rbsegment: IRBSegment) {
15-
const conditions = rbsegment.conditions;
15+
const conditions = rbsegment.conditions || [];
1616
const evaluator = parser(log, conditions, storage);
1717

1818
const evaluation = evaluator(
@@ -31,10 +31,11 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
3131

3232
function isExcluded(rbSegment: IRBSegment) {
3333
const matchingKey = getMatching(key);
34+
const excluded = rbSegment.excluded || {};
3435

35-
if (rbSegment.excluded.keys.indexOf(matchingKey) !== -1) return true;
36+
if (excluded.keys && excluded.keys.indexOf(matchingKey) !== -1) return true;
3637

37-
const isInSegment = rbSegment.excluded.segments.map(segmentName => {
38+
const isInSegment = (excluded.segments || []).map(segmentName => {
3839
return storage.segments.isInSegment(segmentName, matchingKey);
3940
});
4041

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function checkAllSegmentsExist(segments: ISegmentsCacheBase): Promise<boolean> {
3030
* Exported for testing purposes.
3131
*/
3232
export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: typeof IN_SEGMENT | typeof IN_RULE_BASED_SEGMENT = IN_SEGMENT): Set<string> {
33-
const { conditions, excluded } = ruleEntity as IRBSegment;
33+
const { conditions = [], excluded } = ruleEntity as IRBSegment;
3434
const segments = new Set<string>(excluded && excluded.segments);
3535

3636
for (let i = 0; i < conditions.length; i++) {

0 commit comments

Comments
 (0)