Browse Source

fix: add proper type definition for xcCondition

pull/8571/head
Pranav C 4 months ago
parent
commit
e008f0eed2
  1. 40
      packages/nocodb/src/db/CustomKnex.ts
  2. 18
      packages/nocodb/src/meta/meta.service.ts

40
packages/nocodb/src/db/CustomKnex.ts

@ -492,23 +492,27 @@ const appendWhereCondition = function (
return knexRef; 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]: type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
| XcXonditionObj U[keyof U];
| XcXonditionObj[]
| XcConditionObjVal export type ConditionVal = AtLeastOne<{
| XcConditionObjVal[]; 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' { declare module 'knex' {
@ -527,7 +531,7 @@ declare module 'knex' {
): Knex.QueryBuilder<TRecord, TResult>; ): Knex.QueryBuilder<TRecord, TResult>;
condition<TRecord, TResult>( condition<TRecord, TResult>(
conditionObj: XcXonditionObj, conditionObj: Condition,
columnAliases?: { columnAliases?: {
[columnAlias: string]: string; [columnAlias: string]: string;
}, },
@ -542,7 +546,7 @@ declare module 'knex' {
): Knex.QueryBuilder<TRecord, TResult>; ): Knex.QueryBuilder<TRecord, TResult>;
conditionGraph<TRecord, TResult>(condition: { conditionGraph<TRecord, TResult>(condition: {
condition: XcXonditionObj; condition: Condition;
models: { [key: string]: BaseModelSql }; models: { [key: string]: BaseModelSql };
}): Knex.QueryBuilder<TRecord, TResult>; }): Knex.QueryBuilder<TRecord, TResult>;

18
packages/nocodb/src/meta/meta.service.ts

@ -6,11 +6,13 @@ import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone'; import timezone from 'dayjs/plugin/timezone';
import type * as knex from 'knex'; import type * as knex from 'knex';
import type { Knex } from 'knex'; import type { Knex } from 'knex';
import type { Condition } from '~/db/CustomKnex';
import XcMigrationSource from '~/meta/migrations/XcMigrationSource'; import XcMigrationSource from '~/meta/migrations/XcMigrationSource';
import XcMigrationSourcev2 from '~/meta/migrations/XcMigrationSourcev2'; import XcMigrationSourcev2 from '~/meta/migrations/XcMigrationSourcev2';
import { XKnex } from '~/db/CustomKnex'; import { XKnex } from '~/db/CustomKnex';
import { NcConfig } from '~/utils/nc-config'; import { NcConfig } from '~/utils/nc-config';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import { NcError } from '~/helpers/catchError';
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(timezone); dayjs.extend(timezone);
@ -119,6 +121,7 @@ export class MetaService {
}); });
return insertObj; return insertObj;
} }
public async bulkMetaInsert( public async bulkMetaInsert(
base_id: string, base_id: string,
source_id: string, source_id: string,
@ -278,7 +281,7 @@ export class MetaService {
condition?: { [key: string]: any }; condition?: { [key: string]: any };
limit?: number; limit?: number;
offset?: number; offset?: number;
xcCondition?; xcCondition?: Condition;
fields?: string[]; fields?: string[];
sort?: { field: string; desc?: boolean }; sort?: { field: string; desc?: boolean };
}, },
@ -370,7 +373,7 @@ export class MetaService {
dbAlias: string, dbAlias: string,
target: string, target: string,
idOrCondition: string | { [p: string]: any }, idOrCondition: string | { [p: string]: any },
xcCondition?, xcCondition?: Condition,
): Promise<void> { ): Promise<void> {
const query = this.knexConnection(target); const query = this.knexConnection(target);
@ -400,7 +403,7 @@ export class MetaService {
target: string, target: string,
idOrCondition: string | { [p: string]: any }, idOrCondition: string | { [p: string]: any },
fields?: string[], fields?: string[],
xcCondition?, xcCondition?: Condition,
): Promise<any> { ): Promise<any> {
const query = this.knexConnection(target); const query = this.knexConnection(target);
@ -466,7 +469,7 @@ export class MetaService {
condition?: { [p: string]: any }; condition?: { [p: string]: any };
limit?: number; limit?: number;
offset?: number; offset?: number;
xcCondition?; xcCondition?: Condition;
fields?: string[]; fields?: string[];
orderBy?: { [key: string]: 'asc' | 'desc' }; orderBy?: { [key: string]: 'asc' | 'desc' };
}, },
@ -513,7 +516,7 @@ export class MetaService {
condition?: { [p: string]: any }; condition?: { [p: string]: any };
limit?: number; limit?: number;
offset?: number; offset?: number;
xcCondition?; xcCondition?: Condition;
fields?: string[]; fields?: string[];
orderBy?: { [key: string]: 'asc' | 'desc' }; orderBy?: { [key: string]: 'asc' | 'desc' };
}, },
@ -558,7 +561,7 @@ export class MetaService {
target: string, target: string,
args?: { args?: {
condition?: { [p: string]: any }; condition?: { [p: string]: any };
xcCondition?; xcCondition?: Condition;
aggField?: string; aggField?: string;
}, },
): Promise<number> { ): Promise<number> {
@ -590,7 +593,7 @@ export class MetaService {
target: string, target: string,
data: any, data: any,
idOrCondition?: string | { [p: string]: any }, idOrCondition?: string | { [p: string]: any },
xcCondition?, xcCondition?: Condition,
): Promise<any> { ): Promise<any> {
const query = this.knexConnection(target); const query = this.knexConnection(target);
if (base_id !== null && base_id !== undefined) { if (base_id !== null && base_id !== undefined) {
@ -619,6 +622,7 @@ export class MetaService {
_project_id: string, _project_id: string,
_dbAlias: string, _dbAlias: string,
): Promise<void> { ): Promise<void> {
NcError.notImplemented('metaDeleteAll');
// await this.knexConnection..dropTableIfExists('nc_roles').; // await this.knexConnection..dropTableIfExists('nc_roles').;
// await this.knexConnection.schema.dropTableIfExists('nc_store').; // await this.knexConnection.schema.dropTableIfExists('nc_store').;
// await this.knexConnection.schema.dropTableIfExists('nc_hooks').; // await this.knexConnection.schema.dropTableIfExists('nc_hooks').;

Loading…
Cancel
Save