@@ -31,29 +31,26 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
31
31
/**
32
32
* Avoid repeating this validations code
33
33
*/
34
- function validateEvaluationParams ( maybeKey : SplitIO . SplitKey , maybeFeatureFlagNameOrNames : string | string [ ] | undefined , maybeAttributes : SplitIO . Attributes | undefined , methodName : string , maybeFlagSetNameOrNames ?: string [ ] ) {
35
- const multi = startsWith ( methodName , GET_TREATMENTS ) ;
34
+ function validateEvaluationParams ( maybeKey : SplitIO . SplitKey , maybeNameOrNames : string | string [ ] , maybeAttributes : SplitIO . Attributes | undefined , methodName : string ) {
36
35
const key = validateKey ( log , maybeKey , methodName ) ;
37
- let splitOrSplits : string | string [ ] | false = false ;
38
- let flagSetOrFlagSets : string [ ] = [ ] ;
39
- if ( maybeFeatureFlagNameOrNames ) {
40
- splitOrSplits = multi ? validateSplits ( log , maybeFeatureFlagNameOrNames , methodName ) : validateSplit ( log , maybeFeatureFlagNameOrNames , methodName ) ;
41
- }
36
+
37
+ const nameOrNames = methodName . indexOf ( 'ByFlagSet' ) > - 1 ?
38
+ validateFlagSets ( log , methodName , maybeNameOrNames as string [ ] , settings . sync . __splitFiltersValidation . groupedFilters . bySet ) :
39
+ startsWith ( methodName , GET_TREATMENTS ) ?
40
+ validateSplits ( log , maybeNameOrNames , methodName ) :
41
+ validateSplit ( log , maybeNameOrNames , methodName ) ;
42
+
42
43
const attributes = validateAttributes ( log , maybeAttributes , methodName ) ;
43
44
const isNotDestroyed = validateIfNotDestroyed ( log , readinessManager , methodName ) ;
44
- if ( maybeFlagSetNameOrNames ) {
45
- flagSetOrFlagSets = validateFlagSets ( log , methodName , maybeFlagSetNameOrNames , settings . sync . __splitFiltersValidation . groupedFilters . bySet ) ;
46
- }
47
45
48
- validateIfOperational ( log , readinessManager , methodName , splitOrSplits ) ;
46
+ validateIfOperational ( log , readinessManager , methodName , nameOrNames ) ;
49
47
50
- const valid = isNotDestroyed && key && ( splitOrSplits || flagSetOrFlagSets . length > 0 ) && attributes !== false ;
48
+ const valid = isNotDestroyed && key && nameOrNames && attributes !== false ;
51
49
52
50
return {
53
51
valid,
54
52
key,
55
- splitOrSplits,
56
- flagSetOrFlagSets,
53
+ nameOrNames,
57
54
attributes
58
55
} ;
59
56
}
@@ -66,7 +63,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
66
63
const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT ) ;
67
64
68
65
if ( params . valid ) {
69
- return client . getTreatment ( params . key as SplitIO . SplitKey , params . splitOrSplits as string , params . attributes as SplitIO . Attributes | undefined ) ;
66
+ return client . getTreatment ( params . key as SplitIO . SplitKey , params . nameOrNames as string , params . attributes as SplitIO . Attributes | undefined ) ;
70
67
} else {
71
68
return wrapResult ( CONTROL ) ;
72
69
}
@@ -76,7 +73,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
76
73
const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT_WITH_CONFIG ) ;
77
74
78
75
if ( params . valid ) {
79
- return client . getTreatmentWithConfig ( params . key as SplitIO . SplitKey , params . splitOrSplits as string , params . attributes as SplitIO . Attributes | undefined ) ;
76
+ return client . getTreatmentWithConfig ( params . key as SplitIO . SplitKey , params . nameOrNames as string , params . attributes as SplitIO . Attributes | undefined ) ;
80
77
} else {
81
78
return wrapResult ( objectAssign ( { } , CONTROL_WITH_CONFIG ) ) ;
82
79
}
@@ -86,10 +83,10 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
86
83
const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS ) ;
87
84
88
85
if ( params . valid ) {
89
- return client . getTreatments ( params . key as SplitIO . SplitKey , params . splitOrSplits as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
86
+ return client . getTreatments ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
90
87
} else {
91
88
const res : SplitIO . Treatments = { } ;
92
- if ( params . splitOrSplits ) ( params . splitOrSplits as string [ ] ) . forEach ( ( split : string ) => res [ split ] = CONTROL ) ;
89
+ if ( params . nameOrNames ) ( params . nameOrNames as string [ ] ) . forEach ( ( split : string ) => res [ split ] = CONTROL ) ;
93
90
94
91
return wrapResult ( res ) ;
95
92
}
@@ -99,50 +96,50 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
99
96
const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS_WITH_CONFIG ) ;
100
97
101
98
if ( params . valid ) {
102
- return client . getTreatmentsWithConfig ( params . key as SplitIO . SplitKey , params . splitOrSplits as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
99
+ return client . getTreatmentsWithConfig ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
103
100
} else {
104
101
const res : SplitIO . TreatmentsWithConfig = { } ;
105
- if ( params . splitOrSplits ) ( params . splitOrSplits as string [ ] ) . forEach ( split => res [ split ] = objectAssign ( { } , CONTROL_WITH_CONFIG ) ) ;
102
+ if ( params . nameOrNames ) ( params . nameOrNames as string [ ] ) . forEach ( split => res [ split ] = objectAssign ( { } , CONTROL_WITH_CONFIG ) ) ;
106
103
107
104
return wrapResult ( res ) ;
108
105
}
109
106
}
110
107
111
108
function getTreatmentsByFlagSets ( maybeKey : SplitIO . SplitKey , maybeFlagSets : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
112
- const params = validateEvaluationParams ( maybeKey , undefined , maybeAttributes , GET_TREATMENTS_BY_FLAG_SETS , maybeFlagSets ) ;
109
+ const params = validateEvaluationParams ( maybeKey , maybeFlagSets , maybeAttributes , GET_TREATMENTS_BY_FLAG_SETS ) ;
113
110
114
111
if ( params . valid ) {
115
- return client . getTreatmentsByFlagSets ( params . key as SplitIO . SplitKey , params . flagSetOrFlagSets as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
112
+ return client . getTreatmentsByFlagSets ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
116
113
} else {
117
114
return wrapResult ( { } ) ;
118
115
}
119
116
}
120
117
121
118
function getTreatmentsWithConfigByFlagSets ( maybeKey : SplitIO . SplitKey , maybeFlagSets : string [ ] , maybeAttributes ?: SplitIO . Attributes ) {
122
- const params = validateEvaluationParams ( maybeKey , undefined , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS , maybeFlagSets ) ;
119
+ const params = validateEvaluationParams ( maybeKey , maybeFlagSets , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS ) ;
123
120
124
121
if ( params . valid ) {
125
- return client . getTreatmentsWithConfigByFlagSets ( params . key as SplitIO . SplitKey , params . flagSetOrFlagSets as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
122
+ return client . getTreatmentsWithConfigByFlagSets ( params . key as SplitIO . SplitKey , params . nameOrNames as string [ ] , params . attributes as SplitIO . Attributes | undefined ) ;
126
123
} else {
127
124
return wrapResult ( { } ) ;
128
125
}
129
126
}
130
127
131
128
function getTreatmentsByFlagSet ( maybeKey : SplitIO . SplitKey , maybeFlagSet : string , maybeAttributes ?: SplitIO . Attributes ) {
132
- const params = validateEvaluationParams ( maybeKey , undefined , maybeAttributes , GET_TREATMENTS_BY_FLAG_SET , [ maybeFlagSet ] ) ;
129
+ const params = validateEvaluationParams ( maybeKey , [ maybeFlagSet ] , maybeAttributes , GET_TREATMENTS_BY_FLAG_SET ) ;
133
130
134
131
if ( params . valid ) {
135
- return client . getTreatmentsByFlagSet ( params . key as SplitIO . SplitKey , params . flagSetOrFlagSets [ 0 ] as string , params . attributes as SplitIO . Attributes | undefined ) ;
132
+ return client . getTreatmentsByFlagSet ( params . key as SplitIO . SplitKey , ( params . nameOrNames as string [ ] ) [ 0 ] , params . attributes as SplitIO . Attributes | undefined ) ;
136
133
} else {
137
134
return wrapResult ( { } ) ;
138
135
}
139
136
}
140
137
141
138
function getTreatmentsWithConfigByFlagSet ( maybeKey : SplitIO . SplitKey , maybeFlagSet : string , maybeAttributes ?: SplitIO . Attributes ) {
142
- const params = validateEvaluationParams ( maybeKey , undefined , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET , [ maybeFlagSet ] ) ;
139
+ const params = validateEvaluationParams ( maybeKey , [ maybeFlagSet ] , maybeAttributes , GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET ) ;
143
140
144
141
if ( params . valid ) {
145
- return client . getTreatmentsWithConfigByFlagSet ( params . key as SplitIO . SplitKey , params . flagSetOrFlagSets [ 0 ] as string , params . attributes as SplitIO . Attributes | undefined ) ;
142
+ return client . getTreatmentsWithConfigByFlagSet ( params . key as SplitIO . SplitKey , ( params . nameOrNames as string [ ] ) [ 0 ] , params . attributes as SplitIO . Attributes | undefined ) ;
146
143
} else {
147
144
return wrapResult ( { } ) ;
148
145
}
0 commit comments