From e008f0eed2f6edb0793713efcbc25ab114447af8 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 27 May 2024 15:24:46 +0000 Subject: [PATCH] fix: add proper type definition for xcCondition --- packages/nocodb/src/db/CustomKnex.ts | 40 +++++++++++++----------- packages/nocodb/src/meta/meta.service.ts | 18 ++++++----- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/packages/nocodb/src/db/CustomKnex.ts b/packages/nocodb/src/db/CustomKnex.ts index cda64ad395..0c277239cd 100644 --- a/packages/nocodb/src/db/CustomKnex.ts +++ b/packages/nocodb/src/db/CustomKnex.ts @@ -492,23 +492,27 @@ const appendWhereCondition = function ( return knexRef; }; -type XcConditionObjVal = { - [key in 'eq' | 'neq' | 'lt' | 'gt' | 'ge' | 'le' | 'like' | 'nlike']: - | string - | number - | any; -}; - -interface XcXonditionObj { - _or: XcXonditionObj[]; - _and: XcXonditionObj[]; - _not: XcXonditionObj; - [key: string]: - | XcXonditionObj - | XcXonditionObj[] - | XcConditionObjVal - | XcConditionObjVal[]; +type AtLeastOne }> = Partial & + U[keyof U]; + +export type ConditionVal = AtLeastOne<{ + eq: string | number | any; + neq: string | number | any; + lt: string | number | any; + gt: string | number | any; + ge: string | number | any; + le: string | number | any; + like: string | number | any; + nlike: string | number | any; +}>; + +export interface Condition { + _or?: Condition[]; + _and?: Condition[]; + _not?: Condition; + + [key: string]: ConditionVal | Condition | Condition[]; } declare module 'knex' { @@ -527,7 +531,7 @@ declare module 'knex' { ): Knex.QueryBuilder; condition( - conditionObj: XcXonditionObj, + conditionObj: Condition, columnAliases?: { [columnAlias: string]: string; }, @@ -542,7 +546,7 @@ declare module 'knex' { ): Knex.QueryBuilder; conditionGraph(condition: { - condition: XcXonditionObj; + condition: Condition; models: { [key: string]: BaseModelSql }; }): Knex.QueryBuilder; diff --git a/packages/nocodb/src/meta/meta.service.ts b/packages/nocodb/src/meta/meta.service.ts index 758c4a7934..0d04879d71 100644 --- a/packages/nocodb/src/meta/meta.service.ts +++ b/packages/nocodb/src/meta/meta.service.ts @@ -6,11 +6,13 @@ import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; import type * as knex from 'knex'; import type { Knex } from 'knex'; +import type { Condition } from '~/db/CustomKnex'; import XcMigrationSource from '~/meta/migrations/XcMigrationSource'; import XcMigrationSourcev2 from '~/meta/migrations/XcMigrationSourcev2'; import { XKnex } from '~/db/CustomKnex'; import { NcConfig } from '~/utils/nc-config'; import { MetaTable } from '~/utils/globals'; +import { NcError } from '~/helpers/catchError'; dayjs.extend(utc); dayjs.extend(timezone); @@ -119,6 +121,7 @@ export class MetaService { }); return insertObj; } + public async bulkMetaInsert( base_id: string, source_id: string, @@ -278,7 +281,7 @@ export class MetaService { condition?: { [key: string]: any }; limit?: number; offset?: number; - xcCondition?; + xcCondition?: Condition; fields?: string[]; sort?: { field: string; desc?: boolean }; }, @@ -370,7 +373,7 @@ export class MetaService { dbAlias: string, target: string, idOrCondition: string | { [p: string]: any }, - xcCondition?, + xcCondition?: Condition, ): Promise { const query = this.knexConnection(target); @@ -400,7 +403,7 @@ export class MetaService { target: string, idOrCondition: string | { [p: string]: any }, fields?: string[], - xcCondition?, + xcCondition?: Condition, ): Promise { const query = this.knexConnection(target); @@ -466,7 +469,7 @@ export class MetaService { condition?: { [p: string]: any }; limit?: number; offset?: number; - xcCondition?; + xcCondition?: Condition; fields?: string[]; orderBy?: { [key: string]: 'asc' | 'desc' }; }, @@ -513,7 +516,7 @@ export class MetaService { condition?: { [p: string]: any }; limit?: number; offset?: number; - xcCondition?; + xcCondition?: Condition; fields?: string[]; orderBy?: { [key: string]: 'asc' | 'desc' }; }, @@ -558,7 +561,7 @@ export class MetaService { target: string, args?: { condition?: { [p: string]: any }; - xcCondition?; + xcCondition?: Condition; aggField?: string; }, ): Promise { @@ -590,7 +593,7 @@ export class MetaService { target: string, data: any, idOrCondition?: string | { [p: string]: any }, - xcCondition?, + xcCondition?: Condition, ): Promise { const query = this.knexConnection(target); if (base_id !== null && base_id !== undefined) { @@ -619,6 +622,7 @@ export class MetaService { _project_id: string, _dbAlias: string, ): Promise { + NcError.notImplemented('metaDeleteAll'); // await this.knexConnection..dropTableIfExists('nc_roles').; // await this.knexConnection.schema.dropTableIfExists('nc_store').; // await this.knexConnection.schema.dropTableIfExists('nc_hooks').;