|
|
@ -10,7 +10,7 @@ import { |
|
|
|
isSystemColumn, |
|
|
|
isSystemColumn, |
|
|
|
jsepCurlyHook, |
|
|
|
jsepCurlyHook, |
|
|
|
substituteColumnIdWithAliasInFormula, |
|
|
|
substituteColumnIdWithAliasInFormula, |
|
|
|
validateDateWithUnknownFormat, |
|
|
|
validateFormulaAndExtractTreeWithType |
|
|
|
} from 'nocodb-sdk' |
|
|
|
} from 'nocodb-sdk' |
|
|
|
import { |
|
|
|
import { |
|
|
|
MetaInj, |
|
|
|
MetaInj, |
|
|
@ -99,10 +99,15 @@ const validators = { |
|
|
|
validator: (_: any, formula: any) => { |
|
|
|
validator: (_: any, formula: any) => { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
if (!formula?.trim()) return reject(new Error('Required')) |
|
|
|
if (!formula?.trim()) return reject(new Error('Required')) |
|
|
|
const res = parseAndValidateFormula(formula) |
|
|
|
|
|
|
|
if (res !== true) { |
|
|
|
try { |
|
|
|
return reject(new Error(res)) |
|
|
|
validateFormulaAndExtractTreeWithType(formula, supportedColumns.value) |
|
|
|
|
|
|
|
} catch (e: any) { |
|
|
|
|
|
|
|
return reject(new Error(e.message)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// if (res !== true) { |
|
|
|
|
|
|
|
// return reject(new Error(res)) |
|
|
|
|
|
|
|
// } |
|
|
|
resolve() |
|
|
|
resolve() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
@ -226,7 +231,7 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n |
|
|
|
return validateAgainstMeta(arg, errors, typeErrors) |
|
|
|
return validateAgainstMeta(arg, errors, typeErrors) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const argsTypes = validateResult.map((v: any) => v.returnType); |
|
|
|
const argsTypes = validateResult.map((v: any) => v.returnType) |
|
|
|
|
|
|
|
|
|
|
|
if (typeof validateResult[0].returnType === 'function') { |
|
|
|
if (typeof validateResult[0].returnType === 'function') { |
|
|
|
returnType = formulas[calleeName].returnType(argsTypes) |
|
|
|
returnType = formulas[calleeName].returnType(argsTypes) |
|
|
@ -266,7 +271,9 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n |
|
|
|
typeErrors, |
|
|
|
typeErrors, |
|
|
|
) |
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
parsedTree.arguments.map((arg: Record<string, any>) => validateAgainstType(arg, expectedType, null, typeErrors, argsTypes)) |
|
|
|
parsedTree.arguments.map((arg: Record<string, any>) => |
|
|
|
|
|
|
|
validateAgainstType(arg, expectedType, null, typeErrors, argsTypes), |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (expectedType === formulaTypes.DATE) { |
|
|
|
} else if (expectedType === formulaTypes.DATE) { |
|
|
|
if (calleeName === 'DATEADD') { |
|
|
|
if (calleeName === 'DATEADD') { |
|
|
@ -488,7 +495,13 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n |
|
|
|
return { errors, returnType } |
|
|
|
return { errors, returnType } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function validateAgainstType(parsedTree: any, expectedType: string, func: any, typeErrors = new Set(), argTypes: formulaTypes = []) { |
|
|
|
function validateAgainstType( |
|
|
|
|
|
|
|
parsedTree: any, |
|
|
|
|
|
|
|
expectedType: string, |
|
|
|
|
|
|
|
func: any, |
|
|
|
|
|
|
|
typeErrors = new Set(), |
|
|
|
|
|
|
|
argTypes: formulaTypes = [], |
|
|
|
|
|
|
|
) { |
|
|
|
let type |
|
|
|
let type |
|
|
|
if (parsedTree === false || typeof parsedTree === 'undefined') { |
|
|
|
if (parsedTree === false || typeof parsedTree === 'undefined') { |
|
|
|
return typeErrors |
|
|
|
return typeErrors |
|
|
|