diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index d7afe38605..ade20bfd3f 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -11,15 +11,6 @@ import { validateFormulaAndExtractTreeWithType, } from 'nocodb-sdk' import type { ColumnType, FormulaType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk' -import { - UITypes, - isLinksOrLTAR, - isNumericCol, - isSystemColumn, - jsepCurlyHook, - substituteColumnIdWithAliasInFormula, - validateFormulaAndExtractTreeWithType -} from 'nocodb-sdk' import { MetaInj, NcAutocompleteTree, @@ -87,12 +78,12 @@ const refTables = computed(() => { const validators = { formula_raw: [ { - validator: (_: any, formula: any) => { - return new Promise((resolve, reject) => { + validator: (_: any, formula: any) => { + return new Promise(async (resolve, reject) => { if (!formula?.trim()) return reject(new Error('Required')) try { - validateFormulaAndExtractTreeWithType({ formula, columns: supportedColumns.value, clientOrSqlUi: sqlUi.value }) + await validateFormulaAndExtractTreeWithType({ formula, columns: supportedColumns.value, clientOrSqlUi: sqlUi.value }) } catch (e: any) { if (e instanceof FormulaError && e.extra?.key) { return reject(new Error(t(e.extra.key, e.extra))) diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts index f0fcb1f697..3fd462ffae 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts @@ -6,7 +6,7 @@ import UITypes from './UITypes'; describe('Formula parsing and type validation', () => { it('Simple formula', async () => { - const result = validateFormulaAndExtractTreeWithType({ + const result = await validateFormulaAndExtractTreeWithType({ formula: '1 + 2', columns: [], clientOrSqlUi: 'mysql2', @@ -16,7 +16,7 @@ describe('Formula parsing and type validation', () => { }); it('Formula with IF condition', async () => { - const result = validateFormulaAndExtractTreeWithType({ + const result = await validateFormulaAndExtractTreeWithType({ formula: 'IF({column}, "Found", BLANK())', columns: [ { @@ -31,7 +31,7 @@ describe('Formula parsing and type validation', () => { expect(result.dataType).toEqual(FormulaDataTypes.STRING); }); it('Complex formula', async () => { - const result = validateFormulaAndExtractTreeWithType({ + const result = await validateFormulaAndExtractTreeWithType({ formula: 'SWITCH({column2},"value1",IF({column1}, "Found", BLANK()),"value2", 2)', columns: [ @@ -51,7 +51,7 @@ describe('Formula parsing and type validation', () => { expect(result.dataType).toEqual(FormulaDataTypes.STRING); - const result1 = validateFormulaAndExtractTreeWithType({ + const result1 = await validateFormulaAndExtractTreeWithType({ formula: 'SWITCH({column2},"value1",IF({column1}, 1, 2),"value2", 2)', columns: [ { diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 8b512a9b4e..9f81c15e3b 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -6,12 +6,10 @@ import dayjs from 'dayjs'; import { MssqlUi, MysqlUi, - OracleUi, PgUi, SnowflakeUi, SqlUiFactory, } from './sqlUi'; -import { RollupColumn } from '../../../nocodb/src/models'; // todo: move to date utils and export, remove duplicate from gui @@ -1260,11 +1258,10 @@ async function extractColumnIdentifierType({ | 'mariadb' | 'sqlite' | 'snowflake' - | MysqlUi - | MssqlUi - | SnowflakeUi - | PgUi - | OracleUi; + | typeof MysqlUi + | typeof MssqlUi + | typeof SnowflakeUi + | typeof PgUi }) { const res: { dataType?: FormulaDataTypes; @@ -1422,8 +1419,7 @@ export async function validateFormulaAndExtractTreeWithType({ | typeof MysqlUi | typeof MssqlUi | typeof SnowflakeUi - | typeof PgUi - | typeof OracleUi; + | typeof PgUi; getMeta?: (tableId: string) => Promise; }) { const colAliasToColMap = {}; diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index e6764da560..b75c59b8d2 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -77,7 +77,7 @@ async function _formulaQueryBuilder( // formula may include double curly brackets in previous version // convert to single curly bracket here for compatibility // const _tree1 = jsep(_tree.replaceAll('{{', '{').replaceAll('}}', '}')); - tree = validateFormulaAndExtractTreeWithType({ + tree = await validateFormulaAndExtractTreeWithType({ formula: _tree.replaceAll('{{', '{').replaceAll('}}', '}'), columns, clientOrSqlUi: baseModelSqlv2.clientType as diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 3e3f0c4073..4ecff4f71d 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -210,7 +210,7 @@ export class ColumnsService { colBody.formula_raw || colBody.formula, table.columns, ); - colBody.parsed_tree = validateFormulaAndExtractTreeWithType({ + colBody.parsed_tree = await validateFormulaAndExtractTreeWithType({ formula: colBody.formula_raw || colBody.formula, columns: table.columns, clientOrSqlUi: source.type, @@ -939,7 +939,7 @@ export class ColumnsService { ]); await FormulaColumn.update(c.id, { formula_raw: new_formula_raw, - parsed_tree: validateFormulaAndExtractTreeWithType({ + parsed_tree: await validateFormulaAndExtractTreeWithType({ formula: new_formula_raw, columns: table.columns, clientOrSqlUi: source.type, @@ -1005,7 +1005,7 @@ export class ColumnsService { ]); await FormulaColumn.update(c.id, { formula_raw: new_formula_raw, - parsed_tree: validateFormulaAndExtractTreeWithType({ + parsed_tree: await validateFormulaAndExtractTreeWithType({ formula: new_formula_raw, columns: table.columns, clientOrSqlUi: source.type, @@ -1215,7 +1215,7 @@ export class ColumnsService { colBody.formula_raw || colBody.formula, table.columns, ); - colBody.parsed_tree = validateFormulaAndExtractTreeWithType({ + colBody.parsed_tree = await validateFormulaAndExtractTreeWithType({ // formula may include double curly brackets in previous version // convert to single curly bracket here for compatibility formula: