|
|
|
@ -267,7 +267,9 @@ interface FormulaMeta {
|
|
|
|
|
max?: number; |
|
|
|
|
rqd?: number; |
|
|
|
|
|
|
|
|
|
type?: FormulaDataTypes; |
|
|
|
|
// array of allowed types when args types are not same
|
|
|
|
|
// types should be in order of args
|
|
|
|
|
type?: FormulaDataTypes | FormulaDataTypes[]; |
|
|
|
|
}; |
|
|
|
|
custom?: (args: FormulaDataTypes[], parseTree: any) => void; |
|
|
|
|
}; |
|
|
|
@ -956,38 +958,11 @@ export const formulas: Record<string, FormulaMeta> = {
|
|
|
|
|
args: { |
|
|
|
|
min: 2, |
|
|
|
|
max: 3, |
|
|
|
|
}, |
|
|
|
|
custom(argTypes: FormulaDataTypes[], parsedTree) { |
|
|
|
|
if (argTypes[0] !== FormulaDataTypes.STRING) { |
|
|
|
|
throw new FormulaError( |
|
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
|
{ |
|
|
|
|
key: 'msg.formula.stringTypeIsExpected', |
|
|
|
|
calleeName: parsedTree.callee?.name?.toUpperCase(), |
|
|
|
|
}, |
|
|
|
|
'String type is expected' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (argTypes[1] !== FormulaDataTypes.NUMERIC) { |
|
|
|
|
throw new FormulaError( |
|
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
|
{ |
|
|
|
|
key: 'msg.formula.numericTypeIsExpected', |
|
|
|
|
calleeName: parsedTree.callee?.name?.toUpperCase(), |
|
|
|
|
}, |
|
|
|
|
'Numeric type is expected' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (argTypes[2] && argTypes[2] !== FormulaDataTypes.NUMERIC) { |
|
|
|
|
throw new FormulaError( |
|
|
|
|
FormulaErrorType.INVALID_ARG, |
|
|
|
|
{ |
|
|
|
|
key: 'msg.formula.numericTypeIsExpected', |
|
|
|
|
calleeName: parsedTree.callee?.name?.toUpperCase(), |
|
|
|
|
}, |
|
|
|
|
'Numeric type is expected' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
type: [ |
|
|
|
|
FormulaDataTypes.STRING, |
|
|
|
|
FormulaDataTypes.NUMERIC, |
|
|
|
|
FormulaDataTypes.NUMERIC, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
description: |
|
|
|
@ -1007,6 +982,11 @@ export const formulas: Record<string, FormulaMeta> = {
|
|
|
|
|
validation: { |
|
|
|
|
args: { |
|
|
|
|
rqd: 3, |
|
|
|
|
type: [ |
|
|
|
|
FormulaDataTypes.STRING, |
|
|
|
|
FormulaDataTypes.NUMERIC, |
|
|
|
|
FormulaDataTypes.NUMERIC, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
custom(argTypes: FormulaDataTypes[], parsedTree) { |
|
|
|
|
if (argTypes[0] !== FormulaDataTypes.STRING) { |
|
|
|
@ -1758,9 +1738,16 @@ export async function validateFormulaAndExtractTreeWithType({
|
|
|
|
|
} |
|
|
|
|
// validate against expected arg types if present
|
|
|
|
|
else if (formulas[calleeName].validation?.args?.type) { |
|
|
|
|
const expectedArgType = formulas[calleeName].validation.args.type; |
|
|
|
|
for (let i = 0; i < validateResult.length; i++) { |
|
|
|
|
const argPt = validateResult[i]; |
|
|
|
|
|
|
|
|
|
// if type
|
|
|
|
|
const expectedArgType = Array.isArray( |
|
|
|
|
formulas[calleeName].validation.args.type |
|
|
|
|
) |
|
|
|
|
? formulas[calleeName].validation.args.type[i] |
|
|
|
|
: formulas[calleeName].validation.args.type; |
|
|
|
|
|
|
|
|
|
for (const argPt of validateResult) { |
|
|
|
|
if ( |
|
|
|
|
argPt.dataType !== expectedArgType && |
|
|
|
|
argPt.dataType !== FormulaDataTypes.NULL && |
|
|
|
@ -1786,7 +1773,6 @@ export async function validateFormulaAndExtractTreeWithType({
|
|
|
|
|
} else { |
|
|
|
|
let key = '', |
|
|
|
|
message = 'Invalid argument type'; |
|
|
|
|
|
|
|
|
|
if (expectedArgType === FormulaDataTypes.NUMERIC) { |
|
|
|
|
key = 'msg.formula.numericTypeIsExpected'; |
|
|
|
|
message = 'Numeric type is expected'; |
|
|
|
|