2024-03-18 13:58:05 +01:00
|
|
|
import type {
|
2022-08-12 14:49:26 +02:00
|
|
|
IFeatureStrategyParameters,
|
|
|
|
IStrategy,
|
|
|
|
IFeatureStrategy,
|
|
|
|
} from 'interfaces/strategy';
|
|
|
|
|
|
|
|
// Sort the keys in a parameters payload object by the
|
|
|
|
// order of the parameters in the strategy definition.
|
|
|
|
export const sortStrategyParameters = (
|
|
|
|
parameters: IFeatureStrategyParameters,
|
2023-10-02 14:25:46 +02:00
|
|
|
strategyDefinition: IStrategy,
|
2022-08-12 14:49:26 +02:00
|
|
|
): Partial<IFeatureStrategy> => {
|
|
|
|
const sortedParameterNames = strategyDefinition.parameters.map(
|
2023-10-02 14:25:46 +02:00
|
|
|
(parameter) => parameter.name,
|
2022-08-12 14:49:26 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
Object.entries(parameters).sort(
|
|
|
|
(a, b) =>
|
|
|
|
sortedParameterNames.indexOf(a[0]) -
|
2023-10-02 14:25:46 +02:00
|
|
|
sortedParameterNames.indexOf(b[0]),
|
|
|
|
),
|
2022-08-12 14:49:26 +02:00
|
|
|
);
|
|
|
|
};
|