migrateSituation
API / @publicodes/tools / migration / migrateSituation
function migrateSituation(situation, instructions): Situation<RuleName>; Defined in: migration/migrateSituation.ts:56
Migrate a situation from an old version of a model to a new version according to the provided migration instructions.
Parameters
| Parameter | Type | Description |
|---|---|---|
situation | Situation<RuleName> | The situation object containing all answers for a given simulation. |
instructions | Migration | The migration instructions object. |
Returns
Situation<RuleName>
The migrated situation (and foldedSteps if specified).
Example
import { migrateSituation } from '@publicodes/tools/migration'
const situation = {
"age": 25
"job": "developer",
"city": "Paris"
}
const instructions = {
keysToMigrate: {
// The rule `age` will be renamed to `âge`.
age: 'âge',
// The rule `city` will be removed.
city: ''
},
valuesToMigrate: {
job: {
// The value `developer` will be translated to `développeur`.
developer: 'développeur'
}
}
}
migrateSituation(situation, instructions) // { "âge": 25, "job": "'développeur'" } Note
An example of instructions can be found here.