@@ -31,29 +31,26 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
3131 /**
3232 * Avoid repeating this validations code
3333 */
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 ) {
3635 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+
4243 const attributes = validateAttributes ( log , maybeAttributes , methodName ) ;
4344 const isNotDestroyed = validateIfNotDestroyed ( log , readinessManager , methodName ) ;
44- if ( maybeFlagSetNameOrNames ) {
45- flagSetOrFlagSets = validateFlagSets ( log , methodName , maybeFlagSetNameOrNames , settings . sync . __splitFiltersValidation . groupedFilters . bySet ) ;
46- }
4745
48- validateIfOperational ( log , readinessManager , methodName , splitOrSplits ) ;
46+ validateIfOperational ( log , readinessManager , methodName , nameOrNames ) ;
4947
50- const valid = isNotDestroyed && key && ( splitOrSplits || flagSetOrFlagSets . length > 0 ) && attributes !== false ;
48+ const valid = isNotDestroyed && key && nameOrNames && attributes !== false ;
5149
5250 return {
5351 valid,
5452 key,
55- splitOrSplits,
56- flagSetOrFlagSets,
53+ nameOrNames,
5754 attributes
5855 } ;
5956 }
@@ -66,7 +63,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
6663 const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT ) ;
6764
6865 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 ) ;
7067 } else {
7168 return wrapResult ( CONTROL ) ;
7269 }
@@ -76,7 +73,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
7673 const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagName , maybeAttributes , GET_TREATMENT_WITH_CONFIG ) ;
7774
7875 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 ) ;
8077 } else {
8178 return wrapResult ( objectAssign ( { } , CONTROL_WITH_CONFIG ) ) ;
8279 }
@@ -86,10 +83,10 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
8683 const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS ) ;
8784
8885 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 ) ;
9087 } else {
9188 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 ) ;
9390
9491 return wrapResult ( res ) ;
9592 }
@@ -99,50 +96,50 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
9996 const params = validateEvaluationParams ( maybeKey , maybeFeatureFlagNames , maybeAttributes , GET_TREATMENTS_WITH_CONFIG ) ;
10097
10198 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 ) ;
103100 } else {
104101 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 ) ) ;
106103
107104 return wrapResult ( res ) ;
108105 }
109106 }
110107
111108 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 ) ;
113110
114111 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 ) ;
116113 } else {
117114 return wrapResult ( { } ) ;
118115 }
119116 }
120117
121118 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 ) ;
123120
124121 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 ) ;
126123 } else {
127124 return wrapResult ( { } ) ;
128125 }
129126 }
130127
131128 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 ) ;
133130
134131 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 ) ;
136133 } else {
137134 return wrapResult ( { } ) ;
138135 }
139136 }
140137
141138 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 ) ;
143140
144141 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 ) ;
146143 } else {
147144 return wrapResult ( { } ) ;
148145 }
0 commit comments