13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import { find , objectEntries , objectValues , sprintf , assign , keyBy } from '../utils/fns' ;
16
+ import { find , objectEntries , objectValues , sprintf , keyBy } from '../utils/fns' ;
17
17
18
18
import { ERROR_MESSAGES , LOG_LEVEL , LOG_MESSAGES , FEATURE_VARIABLE_TYPES } from '../utils/enums' ;
19
19
import configValidator from '../utils/config_validator' ;
@@ -36,6 +36,7 @@ import {
36
36
} from '../shared_types' ;
37
37
import { OdpConfig , OdpIntegrationConfig } from '../odp/odp_config' ;
38
38
import { Transformer } from '../utils/type' ;
39
+ import exp from 'constants' ;
39
40
40
41
interface TryCreatingProjectConfigConfig {
41
42
// TODO[OASIS-6649]: Don't use object type
@@ -99,27 +100,27 @@ const MODULE_NAME = 'PROJECT_CONFIG';
99
100
100
101
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101
102
function createMutationSafeDatafileCopy ( datafile : any ) : ProjectConfig {
102
- const datafileCopy = assign ( { } , datafile ) ;
103
+ const datafileCopy = { ... datafile } ;
103
104
datafileCopy . audiences = ( datafile . audiences || [ ] ) . map ( ( audience : Audience ) => {
104
- return assign ( { } , audience ) ;
105
+ return { ... audience } ;
105
106
} ) ;
106
107
datafileCopy . experiments = ( datafile . experiments || [ ] ) . map ( ( experiment : Experiment ) => {
107
- return assign ( { } , experiment ) ;
108
+ return { ... experiment } ;
108
109
} ) ;
109
110
datafileCopy . featureFlags = ( datafile . featureFlags || [ ] ) . map ( ( featureFlag : FeatureFlag ) => {
110
- return assign ( { } , featureFlag ) ;
111
+ return { ... featureFlag } ;
111
112
} ) ;
112
113
datafileCopy . groups = ( datafile . groups || [ ] ) . map ( ( group : Group ) => {
113
- const groupCopy = assign ( { } , group ) ;
114
+ const groupCopy = { ... group } ;
114
115
groupCopy . experiments = ( group . experiments || [ ] ) . map ( experiment => {
115
- return assign ( { } , experiment ) ;
116
+ return { ... experiment } ;
116
117
} ) ;
117
118
return groupCopy ;
118
119
} ) ;
119
120
datafileCopy . rollouts = ( datafile . rollouts || [ ] ) . map ( ( rollout : Rollout ) => {
120
- const rolloutCopy = assign ( { } , rollout ) ;
121
+ const rolloutCopy = { ... rollout } ;
121
122
rolloutCopy . experiments = ( rollout . experiments || [ ] ) . map ( experiment => {
122
- return assign ( { } , experiment ) ;
123
+ return { ... experiment } ;
123
124
} ) ;
124
125
return rolloutCopy ;
125
126
} ) ;
@@ -148,8 +149,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
148
149
( projectConfig . audiences || [ ] ) . forEach ( audience => {
149
150
audience . conditions = JSON . parse ( audience . conditions as string ) ;
150
151
} ) ;
151
- projectConfig . audiencesById = keyBy ( projectConfig . audiences , 'id' ) ;
152
- assign ( projectConfig . audiencesById , keyBy ( projectConfig . typedAudiences , 'id' ) ) ;
152
+
153
+ projectConfig . audiencesById = {
154
+ ...keyBy ( projectConfig . audiences , 'id' ) ,
155
+ ...keyBy ( projectConfig . typedAudiences , 'id' ) ,
156
+ }
153
157
154
158
projectConfig . attributeKeyMap = keyBy ( projectConfig . attributes , 'key' ) ;
155
159
projectConfig . eventKeyMap = keyBy ( projectConfig . events , 'key' ) ;
@@ -159,7 +163,8 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
159
163
Object . keys ( projectConfig . groupIdMap || { } ) . forEach ( Id => {
160
164
experiments = projectConfig . groupIdMap [ Id ] . experiments ;
161
165
( experiments || [ ] ) . forEach ( experiment => {
162
- projectConfig . experiments . push ( assign ( experiment , { groupId : Id } ) ) ;
166
+ experiment . groupId = Id ;
167
+ projectConfig . experiments . push ( experiment ) ;
163
168
} ) ;
164
169
} ) ;
165
170
@@ -226,7 +231,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
226
231
experiment . variationKeyMap = keyBy ( experiment . variations , 'key' ) ;
227
232
228
233
// Creates { <variationId>: { key: <variationKey>, id: <variationId> } } mapping for quick lookup
229
- assign ( projectConfig . variationIdMap , keyBy ( experiment . variations , 'id' ) ) ;
234
+ projectConfig . variationIdMap = {
235
+ ...projectConfig . variationIdMap ,
236
+ ...keyBy ( experiment . variations , 'id' )
237
+ } ;
238
+
230
239
objectValues ( experiment . variationKeyMap || { } ) . forEach ( variation => {
231
240
if ( variation . variables ) {
232
241
projectConfig . variationVariableUsageMap [ variation . id ] = keyBy ( variation . variables , 'id' ) ;
0 commit comments