Change pour suivre les conventions de nommage
parent
87de1210ee
commit
8d3d6560af
|
@ -72,7 +72,7 @@ export function cyclesInDependenciesGraph(rawRules: RawRules): GraphCycles {
|
|||
* Tarjan method, which is **not necessarily the smallest cycle**. However, the
|
||||
* smallest cycle would be the most legibe one…
|
||||
*/
|
||||
export function cyclicDependencies<Names extends string>(
|
||||
export function cyclicDependencies(
|
||||
rawRules: RawRules
|
||||
): GraphCyclesWithDependencies {
|
||||
const parsedRules = parsePublicodes(rawRules)
|
||||
|
|
|
@ -21,7 +21,7 @@ type TransformASTFunction = (n: ASTNode) => ASTNode
|
|||
by using the function passed as second argument. The returned value will be the
|
||||
transformed version of the node.
|
||||
*/
|
||||
export function updateAST(
|
||||
export function transformAST(
|
||||
fn: (
|
||||
node: ASTNode,
|
||||
updateFn: TransformASTFunction
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
reduce,
|
||||
} from 'ramda'
|
||||
import React from 'react'
|
||||
import Engine, { evaluationFunction } from '.'
|
||||
import Engine, { EvaluationFunction } from '.'
|
||||
import {
|
||||
ASTNode,
|
||||
ConstantNode,
|
||||
|
@ -77,7 +77,7 @@ function convertNodesToSameUnit(nodes, contextRule, mecanismName) {
|
|||
export const evaluateArray: <NodeName extends NodeKind>(
|
||||
reducer: Parameters<typeof reduce>[0],
|
||||
start: Parameters<typeof reduce>[1]
|
||||
) => evaluationFunction<NodeName> = (reducer, start) =>
|
||||
) => EvaluationFunction<NodeName> = (reducer, start) =>
|
||||
function (node: any) {
|
||||
const evaluate = this.evaluateNode.bind(this)
|
||||
const evaluatedNodes = convertNodesToSameUnit(
|
||||
|
@ -207,5 +207,5 @@ export function evaluateObject<NodeName extends NodeKind>(
|
|||
temporalValue,
|
||||
temporalExplanation,
|
||||
}
|
||||
} as evaluationFunction<NodeName>
|
||||
} as EvaluationFunction<NodeName>
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '.'
|
||||
import { EvaluationFunction } from '.'
|
||||
import { ASTNode } from './AST/types'
|
||||
|
||||
export let evaluationFunctions = {
|
||||
|
@ -7,7 +7,7 @@ export let evaluationFunctions = {
|
|||
|
||||
export function registerEvaluationFunction<
|
||||
NodeName extends ASTNode['nodeKind']
|
||||
>(nodeKind: NodeName, evaluationFunction: evaluationFunction<NodeName>) {
|
||||
>(nodeKind: NodeName, evaluationFunction: EvaluationFunction<NodeName>) {
|
||||
evaluationFunctions ??= {}
|
||||
if (evaluationFunctions[nodeKind]) {
|
||||
throw Error(
|
||||
|
|
|
@ -47,7 +47,7 @@ export { parsePublicodes }
|
|||
export { utils }
|
||||
export { Rule }
|
||||
|
||||
export type evaluationFunction<Kind extends NodeKind = NodeKind> = (
|
||||
export type EvaluationFunction<Kind extends NodeKind = NodeKind> = (
|
||||
this: Engine,
|
||||
node: ASTNode & { nodeKind: Kind }
|
||||
) => ASTNode & { nodeKind: Kind } & EvaluatedNode
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import parse from '../parse'
|
||||
import { InfixMecanism, Mecanism } from '../components/mecanisms/common'
|
||||
import { bonus, makeJsx, mergeMissing } from '../evaluation'
|
||||
|
@ -26,7 +26,7 @@ function MecanismApplicable({ explanation }) {
|
|||
)
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'applicable si'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'applicable si'> = function (node) {
|
||||
const explanation = { ...node.explanation }
|
||||
const condition = this.evaluateNode(explanation.condition)
|
||||
let valeur = explanation.valeur
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { InfixMecanism } from '../components/mecanisms/common'
|
||||
import { makeJsx, mergeAllMissing } from '../evaluation'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
|
@ -30,7 +30,7 @@ function roundWithPrecision(n: number, fractionDigits: number) {
|
|||
return +n.toFixed(fractionDigits)
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'arrondi'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'arrondi'> = function (node) {
|
||||
const valeur = this.evaluateNode(node.explanation.valeur)
|
||||
const nodeValue = valeur.nodeValue
|
||||
let arrondi = node.explanation.arrondi
|
||||
|
@ -56,7 +56,7 @@ const evaluate: evaluationFunction<'arrondi'> = function (node) {
|
|||
}
|
||||
}
|
||||
|
||||
export default function Arrondi(v, context) {
|
||||
export default function parseArrondi(v, context) {
|
||||
const explanation = {
|
||||
valeur: parse(v.valeur, context),
|
||||
arrondi: parse(v.arrondi, context),
|
||||
|
@ -64,10 +64,10 @@ export default function Arrondi(v, context) {
|
|||
return {
|
||||
jsx: MecanismArrondi,
|
||||
explanation,
|
||||
nodeKind: Arrondi.nom,
|
||||
nodeKind: parseArrondi.nom,
|
||||
}
|
||||
}
|
||||
|
||||
Arrondi.nom = 'arrondi' as const
|
||||
parseArrondi.nom = 'arrondi' as const
|
||||
|
||||
registerEvaluationFunction(Arrondi.nom, evaluate)
|
||||
registerEvaluationFunction(parseArrondi.nom, evaluate)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import Barème from '../components/mecanisms/Barème'
|
||||
import { evaluationError } from '../error'
|
||||
import parse from '../parse'
|
||||
|
@ -84,7 +84,7 @@ function evaluateBarème(tranches, assiette, evaluate, cache) {
|
|||
}
|
||||
})
|
||||
}
|
||||
const evaluate: evaluationFunction<'barème'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'barème'> = function (node) {
|
||||
const evaluateNode = this.evaluateNode.bind(this)
|
||||
const assiette = this.evaluateNode(node.explanation.assiette)
|
||||
const multiplicateur = this.evaluateNode(node.explanation.multiplicateur)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { is, map } from 'ramda'
|
||||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { Mecanism } from '../components/mecanisms/common'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { makeJsx, mergeAllMissing } from '../evaluation'
|
||||
|
@ -13,7 +13,7 @@ export type TouteCesConditionsNode = {
|
|||
jsx: any
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'toutes ces conditions'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'toutes ces conditions'> = function (node) {
|
||||
const [nodeValue, explanation] = node.explanation.reduce<
|
||||
[boolean | null, Array<ASTNode>]
|
||||
>(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { is, isEmpty, map, max, mergeWith, reduce } from 'ramda'
|
||||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { Mecanism } from '../components/mecanisms/common'
|
||||
import { ASTNode, EvaluatedNode, Evaluation } from '../AST/types'
|
||||
import {
|
||||
|
@ -19,7 +19,7 @@ export type UneDeCesConditionsNode = {
|
|||
jsx: any
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'une de ces conditions'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'une de ces conditions'> = function (node) {
|
||||
type Calculations = {
|
||||
explanation: Array<ASTNode | EvaluatedNode>
|
||||
nodeValue: Evaluation<boolean>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { ASTNode, Unit } from '../AST/types'
|
||||
import { Mecanism } from '../components/mecanisms/common'
|
||||
import { convertToDate, convertToString } from '../date'
|
||||
|
@ -43,7 +43,7 @@ const objectShape = {
|
|||
depuis: defaultNode(todayString),
|
||||
"jusqu'à": defaultNode(todayString),
|
||||
}
|
||||
const evaluate: evaluationFunction<'durée'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'durée'> = function (node) {
|
||||
const from = this.evaluateNode(node.explanation.depuis)
|
||||
const to = this.evaluateNode(node.explanation["jusqu'à"])
|
||||
let nodeValue
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { lensPath, over } from 'ramda'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import grille from '../components/mecanisms/Grille'
|
||||
import { defaultNode, mergeAllMissing } from '../evaluation'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
|
@ -57,7 +57,7 @@ const evaluateGrille = (tranches, evaluate) =>
|
|||
}
|
||||
})
|
||||
|
||||
const evaluate: evaluationFunction<'grille'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'grille'> = function (node) {
|
||||
const evaluate = this.evaluateNode.bind(this)
|
||||
const assiette = this.evaluateNode(node.explanation.assiette)
|
||||
const multiplicateur = this.evaluateNode(node.explanation.multiplicateur)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import parse from '../parse'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { ASTNode, ConstantNode, Unit } from '../AST/types'
|
||||
import InversionNumérique from '../components/mecanisms/InversionNumérique'
|
||||
import { mergeMissing } from '../evaluation'
|
||||
|
@ -31,7 +31,7 @@ export type InversionNode = {
|
|||
// equal to its situation value, mathematically we search for the zero of the
|
||||
// function x → f(x) - goal. The iteration logic between each test is
|
||||
// implemented in the `uniroot` file.
|
||||
export const evaluateInversion: evaluationFunction<'inversion'> = function (
|
||||
export const evaluateInversion: EvaluationFunction<'inversion'> = function (
|
||||
node
|
||||
) {
|
||||
const inversionGoal = node.explanation.inversionCandidates.find(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { InfixMecanism, Mecanism } from '../components/mecanisms/common'
|
||||
import { ASTNode, EvaluatedNode } from '../AST/types'
|
||||
import { bonus, makeJsx, mergeMissing } from '../evaluation'
|
||||
|
@ -27,7 +27,7 @@ function MecanismNonApplicable({ explanation }) {
|
|||
)
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'non applicable si'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'non applicable si'> = function (node) {
|
||||
const condition = this.evaluateNode(node.explanation.condition)
|
||||
let valeur = node.explanation.valeur
|
||||
if (condition.nodeValue === false || condition.nodeValue === null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { equals, fromPairs, map } from 'ramda'
|
||||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { Operation } from '../components/mecanisms/common'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { convertToDate } from '../date'
|
||||
|
@ -55,7 +55,7 @@ const parseOperation = (k, symbol) => (v, context) => {
|
|||
} as OperationNode
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'operation'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'operation'> = function (node) {
|
||||
const explanation = node.explanation.map((node) =>
|
||||
this.evaluateNode(node)
|
||||
) as [EvaluatedNode, EvaluatedNode]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { InfixMecanism } from '../components/mecanisms/common'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { bonus, makeJsx, mergeMissing } from '../evaluation'
|
||||
|
@ -29,7 +29,7 @@ function ParDéfautComponent({ explanation }) {
|
|||
)
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'par défaut'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'par défaut'> = function (node) {
|
||||
const explanation: {
|
||||
parDéfaut: EvaluatedNode | ASTNode
|
||||
valeur: EvaluatedNode | ASTNode
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { InfixMecanism } from '../components/mecanisms/common'
|
||||
import { typeWarning } from '../error'
|
||||
import parse from '../parse'
|
||||
|
||||
import { makeJsx, mergeAllMissing } from '../evaluation'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
import { convertNodeToUnit } from '../nodeUnits'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { EvaluatedNode } from '../AST/types'
|
||||
import parse from '../parse'
|
||||
|
||||
function MecanismPlafond({ explanation }) {
|
||||
return (
|
||||
|
@ -34,7 +32,7 @@ export type PlafondNode = {
|
|||
jsx: any
|
||||
nodeKind: 'plafond'
|
||||
}
|
||||
const evaluate: evaluationFunction<'plafond'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'plafond'> = function (node) {
|
||||
const valeur = this.evaluateNode(node.explanation.valeur)
|
||||
|
||||
let nodeValue = valeur.nodeValue
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { InfixMecanism } from '../components/mecanisms/common'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { typeWarning } from '../error'
|
||||
|
@ -33,7 +33,7 @@ export type PlancherNode = {
|
|||
jsx: any
|
||||
nodeKind: 'plancher'
|
||||
}
|
||||
const evaluate: evaluationFunction<'plancher'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'plancher'> = function (node) {
|
||||
const valeur = this.evaluateNode(node.explanation.valeur)
|
||||
let nodeValue = valeur.nodeValue
|
||||
let plancher = node.explanation.plancher
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import Product from '../components/mecanisms/Product'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { typeWarning } from '../error'
|
||||
|
@ -35,7 +35,7 @@ export const mecanismProduct = (v, context) => {
|
|||
} as ProductNode
|
||||
}
|
||||
|
||||
const productEffect: evaluationFunction = function ({
|
||||
const productEffect: EvaluationFunction = function ({
|
||||
assiette,
|
||||
taux,
|
||||
facteur,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import Recalcul from '../components/mecanisms/Recalcul'
|
||||
import { defaultNode } from '../evaluation'
|
||||
|
@ -18,7 +18,7 @@ export type RecalculNode = {
|
|||
nodeKind: 'recalcul'
|
||||
}
|
||||
|
||||
const evaluateRecalcul: evaluationFunction<'recalcul'> = function (node) {
|
||||
const evaluateRecalcul: EvaluationFunction<'recalcul'> = function (node) {
|
||||
if (this.cache._meta.inRecalcul) {
|
||||
return (defaultNode(false) as any) as RecalculNode & EvaluatedNode
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { path } from 'ramda'
|
||||
import React from 'react'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { RuleLinkWithContext } from '../components/RuleLink'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
|
@ -15,7 +15,7 @@ export type SynchronisationNode = {
|
|||
nodeKind: 'synchronisation'
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'synchronisation'> = function (node: any) {
|
||||
const evaluate: EvaluationFunction<'synchronisation'> = function (node: any) {
|
||||
const data = this.evaluateNode(node.explanation.data)
|
||||
const valuePath = node.explanation.chemin.split(' . ')
|
||||
const nodeValue =
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import tauxProgressif from '../components/mecanisms/TauxProgressif'
|
||||
import { defaultNode, mergeAllMissing } from '../evaluation'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
|
@ -36,7 +36,7 @@ export default function parseTauxProgressif(v, context): TauxProgressifNode {
|
|||
}
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'taux progressif'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'taux progressif'> = function (node) {
|
||||
const evaluate = this.evaluateNode.bind(this)
|
||||
const assiette = this.evaluateNode(node.explanation.assiette)
|
||||
const multiplicateur = this.evaluateNode(node.explanation.multiplicateur)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import { ASTNode } from '../AST/types'
|
||||
import { registerEvaluationFunction } from '../evaluationFunctions'
|
||||
import parse from '../parse'
|
||||
|
@ -22,7 +22,7 @@ export type VariableTemporelleNode = {
|
|||
nodeKind: 'variable temporelle'
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'variable temporelle'> = function (
|
||||
const evaluate: EvaluationFunction<'variable temporelle'> = function (
|
||||
node: any
|
||||
) {
|
||||
const start =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { or } from 'ramda'
|
||||
import { evaluationFunction } from '..'
|
||||
import { EvaluationFunction } from '..'
|
||||
import Variations from '../components/mecanisms/Variations'
|
||||
import { ASTNode, EvaluatedNode, Unit } from '../AST/types'
|
||||
import { typeWarning } from '../error'
|
||||
|
@ -66,7 +66,7 @@ export default function parseVariations(v, context): VariationNode {
|
|||
}
|
||||
}
|
||||
|
||||
const evaluate: evaluationFunction<'variations'> = function (node) {
|
||||
const evaluate: EvaluationFunction<'variations'> = function (node) {
|
||||
const [temporalValue, explanation, unit] = node.explanation.reduce<
|
||||
[
|
||||
Temporal<any>,
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
import yaml from 'yaml'
|
||||
import { ParsedRules } from '.'
|
||||
import { traverseParsedRules, updateAST } from './AST'
|
||||
import { transformAST, traverseParsedRules } from './AST'
|
||||
import parse from './parse'
|
||||
import {
|
||||
getReplacements,
|
||||
inlineReplacements,
|
||||
ReplacementNode,
|
||||
} from './replacement'
|
||||
import { getReplacements, inlineReplacements } from './replacement'
|
||||
import { Rule, RuleNode } from './rule'
|
||||
import { disambiguateRuleReference } from './ruleUtils'
|
||||
|
||||
|
@ -104,7 +100,7 @@ function transpileRef(object: Record<string, any> | string | Array<any>) {
|
|||
}
|
||||
|
||||
export const disambiguateReference = (parsedRules: Record<string, RuleNode>) =>
|
||||
updateAST((node) => {
|
||||
transformAST((node) => {
|
||||
if (node.nodeKind === 'reference') {
|
||||
const dottedName = disambiguateRuleReference(
|
||||
parsedRules,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { groupBy } from 'ramda'
|
||||
import { updateAST } from './AST'
|
||||
import { transformAST } from './AST'
|
||||
import { ASTNode } from './AST/types'
|
||||
import { InternalError, warning } from './error'
|
||||
import { defaultNode, makeJsx } from './evaluation'
|
||||
|
@ -99,7 +99,7 @@ export function getReplacements(
|
|||
export function inlineReplacements(
|
||||
replacements: Record<string, Array<ReplacementNode>>
|
||||
): (n: ASTNode) => ASTNode {
|
||||
return updateAST((n, fn) => {
|
||||
return transformAST((n, fn) => {
|
||||
if (
|
||||
n.nodeKind === 'replacement' ||
|
||||
n.nodeKind === 'inversion' ||
|
||||
|
|
Loading…
Reference in New Issue