Skip to content

Commit c64b57a

Browse files
Simplify configsFetcher
1 parent 3aed036 commit c64b57a

1 file changed

Lines changed: 22 additions & 28 deletions

File tree

src/sync/polling/fetchers/configsFetcher.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,48 @@ export function configsFetcherFactory(fetchConfigs: IFetchSplitChanges): ISplitC
2222

2323
return configsPromise
2424
.then((resp: IResponse) => resp.json())
25-
.then((configs: IConfigsResponse) => {
26-
return convertConfigsToSplits(configs);
27-
});
25+
.then(convertConfigsResponseToSplitChangesResponse);
2826
};
2927

3028
}
3129

3230
function defaultCondition(treatment: string): ISplitCondition {
3331
return {
34-
conditionType: 'ROLLOUT' as const,
32+
conditionType: 'ROLLOUT',
3533
matcherGroup: {
36-
combiner: 'AND' as const,
34+
combiner: 'AND',
3735
matchers: [{
38-
keySelector: { trafficType: 'user', attribute: null },
36+
keySelector: null,
3937
matcherType: 'ALL_KEYS',
40-
negate: false,
41-
userDefinedSegmentMatcherData: null,
42-
whitelistMatcherData: null,
43-
unaryNumericMatcherData: null,
44-
betweenMatcherData: null,
45-
booleanMatcherData: null,
46-
dependencyMatcherData: null,
47-
stringMatcherData: null,
38+
negate: false
4839
}],
4940
},
5041
partitions: [{ treatment, size: 100 }],
5142
label: 'default rule',
5243
};
5344
}
5445

55-
function convertConfigsToSplits(configs: IConfigsResponse): ISplitChangesResponse {
46+
function convertConfigToDefinitionDTO(config: IConfig) {
47+
const defaultTreatment = config.defaultTreatment || 'default';
48+
49+
return {
50+
...config,
51+
defaultTreatment,
52+
trafficTypeName: config.trafficTypeName || 'user',
53+
conditions: config.conditions && config.conditions.length > 0 ? config.conditions : [defaultCondition(defaultTreatment)],
54+
killed: config.killed || false,
55+
seed: config.seed || 0,
56+
trafficAllocation: config.trafficAllocation || 100,
57+
trafficAllocationSeed: config.trafficAllocationSeed || 0,
58+
};
59+
}
60+
61+
function convertConfigsResponseToSplitChangesResponse(configs: IConfigsResponse): ISplitChangesResponse {
5662
return {
5763
...configs,
5864
ff: configs.configs ? {
5965
...configs.configs,
60-
d: configs.configs.d?.map((config: IConfig) => {
61-
const dt = config.defaultTreatment || 'default';
62-
return {
63-
...config,
64-
defaultTreatment: dt,
65-
conditions: config.conditions && config.conditions.length > 0 ? config.conditions : [defaultCondition(dt)],
66-
killed: config.killed || false,
67-
trafficTypeName: config.trafficTypeName || 'user',
68-
seed: config.seed || 0,
69-
trafficAllocation: config.trafficAllocation || 100,
70-
trafficAllocationSeed: config.trafficAllocationSeed || 0,
71-
};
72-
})
66+
d: configs.configs.d?.map(convertConfigToDefinitionDTO)
7367
} : undefined,
7468
rbs: configs.rbs
7569
};

0 commit comments

Comments
 (0)