|
|
@ -976,17 +976,19 @@ enum FormulaErrorType { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class FormulaError extends Error { |
|
|
|
class FormulaError extends Error { |
|
|
|
public name: string; |
|
|
|
|
|
|
|
public type: FormulaErrorType; |
|
|
|
public type: FormulaErrorType; |
|
|
|
|
|
|
|
public extra: Record<string, any>; |
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
type: FormulaErrorType, |
|
|
|
type: FormulaErrorType, |
|
|
|
name: string, |
|
|
|
extra: { |
|
|
|
|
|
|
|
[key: string]: any; |
|
|
|
|
|
|
|
}, |
|
|
|
message: string = 'Formula Error' |
|
|
|
message: string = 'Formula Error' |
|
|
|
) { |
|
|
|
) { |
|
|
|
super(message); |
|
|
|
super(message); |
|
|
|
this.name = name; |
|
|
|
|
|
|
|
this.type = type; |
|
|
|
this.type = type; |
|
|
|
|
|
|
|
this.extra = extra; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1029,48 +1031,39 @@ export function validateFormulaAndExtractTreeWithType( |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new FormulaError( |
|
|
|
throw new FormulaError( |
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: 'msg.formula.requiredArgumentsFormula', |
|
|
|
|
|
|
|
requiredArguments: validation.args.rqd, |
|
|
|
calleeName, |
|
|
|
calleeName, |
|
|
|
|
|
|
|
}, |
|
|
|
'Required arguments missing' |
|
|
|
'Required arguments missing' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// errors.add(
|
|
|
|
|
|
|
|
// t('msg.formula.requiredArgumentsFormula', {
|
|
|
|
|
|
|
|
// requiredArguments: validation.args.rqd,
|
|
|
|
|
|
|
|
// calleeName,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
validation.args.min !== undefined && |
|
|
|
validation.args.min !== undefined && |
|
|
|
validation.args.min > parsedTree.arguments.length |
|
|
|
validation.args.min > parsedTree.arguments.length |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new FormulaError( |
|
|
|
throw new FormulaError( |
|
|
|
FormulaErrorType.MIN_ARG, |
|
|
|
FormulaErrorType.MIN_ARG, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: 'msg.formula.minRequiredArgumentsFormula', |
|
|
|
|
|
|
|
minRequiredArguments: validation.args.min, |
|
|
|
calleeName, |
|
|
|
calleeName, |
|
|
|
|
|
|
|
}, |
|
|
|
'Minimum arguments required' |
|
|
|
'Minimum arguments required' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// errors.add(
|
|
|
|
|
|
|
|
// t('msg.formula.minRequiredArgumentsFormula', {
|
|
|
|
|
|
|
|
// minRequiredArguments: validation.args.min,
|
|
|
|
|
|
|
|
// calleeName,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
validation.args.max !== undefined && |
|
|
|
validation.args.max !== undefined && |
|
|
|
validation.args.max < parsedTree.arguments.length |
|
|
|
validation.args.max < parsedTree.arguments.length |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new FormulaError( |
|
|
|
throw new FormulaError( |
|
|
|
FormulaErrorType.MAX_ARG, |
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: 'msg.formula.maxRequiredArgumentsFormula', |
|
|
|
|
|
|
|
maxRequiredArguments: validation.args.max, |
|
|
|
calleeName, |
|
|
|
calleeName, |
|
|
|
'Maximum arguments required' |
|
|
|
}, |
|
|
|
|
|
|
|
'Maximum arguments missing' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// errors.add(
|
|
|
|
|
|
|
|
// t('msg.formula.maxRequiredArgumentsFormula', {
|
|
|
|
|
|
|
|
// maxRequiredArguments: validation.args.max,
|
|
|
|
|
|
|
|
// calleeName,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// get args type and validate
|
|
|
|
// get args type and validate
|
|
|
@ -1098,7 +1091,9 @@ export function validateFormulaAndExtractTreeWithType( |
|
|
|
// check for circular reference
|
|
|
|
// check for circular reference
|
|
|
|
checkForCircularFormulaRef(col, parsedTree, columns); |
|
|
|
checkForCircularFormulaRef(col, parsedTree, columns); |
|
|
|
|
|
|
|
|
|
|
|
const formulaRes = col.colOptions?.parsed_tree || validateFormulaAndExtractTreeWithType( |
|
|
|
const formulaRes = |
|
|
|
|
|
|
|
col.colOptions?.parsed_tree || |
|
|
|
|
|
|
|
validateFormulaAndExtractTreeWithType( |
|
|
|
// formula may include double curly brackets in previous version
|
|
|
|
// formula may include double curly brackets in previous version
|
|
|
|
// convert to single curly bracket here for compatibility
|
|
|
|
// convert to single curly bracket here for compatibility
|
|
|
|
col.colOptions.formula.replaceAll('{{', '{').replaceAll('}}', '}'), |
|
|
|
col.colOptions.formula.replaceAll('{{', '{').replaceAll('}}', '}'), |
|
|
@ -1268,9 +1263,13 @@ function checkForCircularFormulaRef(formulaCol, parsedTree, columns) { |
|
|
|
} |
|
|
|
} |
|
|
|
// vertices not same as visited = cycle found
|
|
|
|
// vertices not same as visited = cycle found
|
|
|
|
if (vertices !== visited) { |
|
|
|
if (vertices !== visited) { |
|
|
|
// errors.add(t('msg.formula.cantSaveCircularReference'))
|
|
|
|
throw new FormulaError( |
|
|
|
throw new FormulaError(FormulaErrorType.CIRCULAR_REFERENCE, ''); |
|
|
|
FormulaErrorType.CIRCULAR_REFERENCE, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: 'msg.formula.cantSaveCircularReference', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'Circular reference detected' |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|