Skip to content

Commit

Permalink
pkg: upgrade publicodes
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Jun 3, 2024
1 parent 6c73142 commit 71c7830
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"license": "MIT",
"dependencies": {
"@types/node": "^18.11.18",
"publicodes": "^1.1.1"
"publicodes": "^1.3.0"
},
"devDependencies": {
"@types/jest": "^29.2.5",
Expand Down
17 changes: 6 additions & 11 deletions src/migration/migrateSituation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Evaluation } from 'publicodes'
import { Evaluation, Situation } from 'publicodes'
import { getValueWithoutQuotes, RuleName } from '../commons'

/**
* A situation object containing all answers for a given simulation.
*/
export type Situation = Record<RuleName, Evaluation>

/**
* Associate a old value to a new value.
*/
Expand Down Expand Up @@ -59,9 +54,9 @@ export type Migration = {
* @note An example of instructions can be found {@link https://github.com/incubateur-ademe/nosgestesclimat/blob/preprod/migration/migration.yaml | here}.
*/
export function migrateSituation(
situation: Situation,
situation: Situation<RuleName>,
instructions: Migration,
): Situation {
): Situation<RuleName> {
let newSituation = { ...situation }
const currentRules = Object.keys(situation)
const valueKeysToMigrate = Object.keys(instructions.valuesToMigrate)
Expand Down Expand Up @@ -99,7 +94,7 @@ export function migrateSituation(
function handleSpecialCases(
rule: RuleName,
oldValue: Evaluation,
situation: Situation,
situation: Situation<RuleName>,
): void {
// Special case, number store as a string, we have to convert it to a number
if (
Expand Down Expand Up @@ -133,7 +128,7 @@ function handleSpecialCases(
function updateKey(
rule: RuleName,
oldValue: Evaluation,
situation: Situation,
situation: Situation<RuleName>,
ruleToMigrate: RuleName | undefined,
): void {
if (ruleToMigrate === undefined) {
Expand All @@ -151,7 +146,7 @@ function updateKey(
function updateValue(
rule: RuleName,
value: string,
situation: Situation,
situation: Situation<RuleName>,
): void {
// The value is not a value to migrate and the key has to be deleted
if (value === '') {
Expand Down
4 changes: 2 additions & 2 deletions test/optims/constantFolding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Constant folding [meta]', () => {
}
const engine = new Engine(rawRules, {
logger: disabledLogger,
allowOrphanRules: true,
strict: { noOrphanRule: false },
})
const baseParsedRules = engine.getParsedRules()
const serializedBaseParsedRules = serializeParsedRules(baseParsedRules)
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Constant folding [meta]', () => {
}
const engine = new Engine(rawRules, {
logger: disabledLogger,
allowOrphanRules: true,
strict: { noOrphanRule: false },
})
const foldedRules = serializeParsedRules(
constantFolding(engine, {
Expand Down
2 changes: 1 addition & 1 deletion test/serializeParsedRules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ describe('More complexe cases', () => {
},
}
const parsedRules = new Engine(rules, {
allowOrphanRules: true,
strict: { noOrphanRule: false },
}).getParsedRules()

expect(serializeParsedRules(parsedRules)).toStrictEqual(
Expand Down
2 changes: 1 addition & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ParsedRules } from 'publicodes'
export function callWithEngine<R>(fn: (engine: Engine) => R, rawRules: any): R {
const engine = new Engine(rawRules, {
logger: disabledLogger,
allowOrphanRules: true,
strict: { noOrphanRule: false },
})
return fn(engine)
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2498,10 +2498,10 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

publicodes@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/publicodes/-/publicodes-1.2.0.tgz#2856891da07633315eff419402bb61109045504d"
integrity sha512-qit3KsTqwZct5Xt6uyJ83yXNXxxScKuSRvemUgCRWEczP/mPAX/tiDQUgwwOC2fDoiCuQuZ9EiQwU5HfzHFIJQ==
publicodes@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/publicodes/-/publicodes-1.3.0.tgz#5530e029ef6aaea2373c56a846d78732c56abc66"
integrity sha512-VBicg3+/SZUe49LzM77CpxWEjPra7sWDnbJyGVShDd2Tuo/p3Krb7ebe/kNM5Z1WDwuqCYLT+X75Co7fi/tMAA==

punycode@^2.1.0:
version "2.3.1"
Expand Down

0 comments on commit 71c7830

Please sign in to comment.