Skip to content

Commit

Permalink
feat: expose migration function into a submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog committed May 15, 2024
1 parent 6365081 commit 2b664d4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ by the nosgestesclimat.fr team.</i> :warning:
- 🏗️ Compiles your set of Publicodes files into a standalone JSON file - [[doc](https://publicodes.github.io/tools/modules/compilation.html#md:compile-a-model-from-a-source)]
- 📦 Resolves import from external Publicodes models, from source and from published [NPM packages](https://www.npmjs.com/package/futureco-data) - [[doc](https://publicodes.github.io/tools/modules/compilation.html#md:import-rules-from-a-npm-package)]
- 🪶 Pre-computes your model at compile time and reduces [the number of rules by ~65%](https://github.com/incubateur-ademe/nosgestesclimat/pull/1697) - [[doc](https://publicodes.github.io/tools/modules/optims.html)]
- ➡️ Use a migration function for user situation to deal with breaking changes in your models - [[doc](https://publicodes.github.io/tools/modules/migration.html)]

## Installation

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"import": "./dist/compilation/index.js",
"require": "./dist/compilation/index.cjs",
"types": "./dist/compilation/index.d.ts"
},
"./migration": {
"import": "./dist/migration/index.js",
"require": "./dist/migration/index.cjs",
"types": "./dist/migration/index.d.ts"
}
},
"files": [
Expand Down Expand Up @@ -70,7 +75,8 @@
"entry": [
"source/index.ts",
"source/optims/index.ts",
"source/compilation/index.ts"
"source/compilation/index.ts",
"source/migration/index.ts"
],
"format": [
"cjs",
Expand Down
1 change: 0 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './commons'
export * from './serializeParsedRules'
export * from './migrations'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ type Props = {
migrationInstructions: MigrationType
}

/**
* Migrate rules and answers from a situation which used to work with an old version of a model to a new version according to the migration instructions.
*
* @param situation - The `situation` as Publicodes object containing all answers for a given simulation.
* @param foldedSteps - In case of form app, an array containing answered questions.
* @param migrationInstructions - An object containing keys and values to migrate formatted as follows:
* @example
* {
keysToMigrate: {
oldKey: newKey
}
valuesToMigrate: {
key: {
oldValue: newValue
}
}
* An example can be found in [nosgestesclimat repository](https://github.com/incubateur-ademe/nosgestesclimat/blob/preprod/migration/migration.yaml).
* @returns The migrated situation (and foldedSteps if specified)
*/
export function migrateSituation({
situation,
foldedSteps = [],
Expand Down
7 changes: 6 additions & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"$schema": "https://typedoc.org/schema.json",
"name": "@publicodes/tools API",
"entryPoints": ["./source", "./source/optims/", "./source/compilation/"],
"entryPoints": [
"./source",
"./source/optims/",
"./source/compilation/",
"./source/migration"
],
"navigationLinks": {
"GitHub": "https://github.com/publicodes/tools"
},
Expand Down

0 comments on commit 2b664d4

Please sign in to comment.