migrateSituation

API / @publicodes/tools / migration / migrateSituation

function migrateSituation(situation, instructions): Partial<Record<string, 
  | PublicodesExpression
  | ASTNode<
  | "arrondi"
  | "barème"
  | "condition"
  | "constant"
  | "contexte"
  | "durée"
  | "est non applicable"
  | "est non défini"
  | "grille"
  | "inversion"
  | "operation"
  | "reference"
  | "replacementRule"
  | "résoudre référence circulaire"
  | "rule"
  | "simplifier unité"
  | "taux progressif"
  | "texte"
  | "une possibilité"
  | "unité"
  | "variable manquante"
  | "variations"
| "logarithme">>>

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

ParameterTypeDescription
situationPartial<Record<string, | PublicodesExpression | ASTNode< | "arrondi" | "barème" | "condition" | "constant" | "contexte" | "durée" | "est non applicable" | "est non défini" | "grille" | "inversion" | "operation" | "reference" | "replacementRule" | "résoudre référence circulaire" | "rule" | "simplifier unité" | "taux progressif" | "texte" | "une possibilité" | "unité" | "variable manquante" | "variations" | "logarithme">>>The situation object containing all answers for a given simulation.
instructionsMigrationThe migration instructions object.

Returns

Partial<Record<string, | PublicodesExpression | ASTNode< | "arrondi" | "barème" | "condition" | "constant" | "contexte" | "durée" | "est non applicable" | "est non défini" | "grille" | "inversion" | "operation" | "reference" | "replacementRule" | "résoudre référence circulaire" | "rule" | "simplifier unité" | "taux progressif" | "texte" | "une possibilité" | "unité" | "variable manquante" | "variations" | "logarithme">>>

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.