1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/packages/unleash-api/lib/helper/legacy-feature-mapper.js
Ivar 096c86d58b Add support for aggregate_strategies in the API.
This commit changes the features-tables:
- drop columns 'strategy' and 'parameters'
- add column 'strategies' of type json.
- migrates existing strategy-mappings in to the new format.

The idea is that the 'strategies' column should contain a json-array
of strategy-configuration for the toggle:

```
[{
 "name" : "strategy1",
 "parameters": { "name": "vale" }
}]

```

To make sure to not break exiting clients the api is extended with a
mapping layer (adding old fields to the json-respons, and mapping
to the new format on create/update a feature toggle.

this commit is first step in solving #102
2016-09-06 21:31:28 +02:00

32 lines
846 B
JavaScript

'use strict';
function addOldFields (feature) {
let modifiedFeature = Object.assign({}, feature);
modifiedFeature.strategy = feature.strategies[0].name;
modifiedFeature.parameters = Object.assign({}, feature.strategies[0].parameters);
return modifiedFeature;
}
function isOldFomrat (feature) {
return feature.strategy && !feature.strategies;
}
function toNewFormat (feature) {
if (isOldFomrat(feature)) {
return {
name: feature.name,
description: feature.description,
enabled: feature.enabled,
strategies: [
{
name: feature.strategy,
parameters: Object.assign({}, feature.parameters),
},
],
};
}
return feature;
}
module.exports = { addOldFields, toNewFormat };