Browse Source

fix: add proper type definition for xcCondition

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

38
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;
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
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]:
| XcXonditionObj
| XcXonditionObj[]
| XcConditionObjVal
| XcConditionObjVal[];
[key: string]: ConditionVal | Condition | Condition[];
}
declare module 'knex' {
@ -527,7 +531,7 @@ declare module 'knex' {
): Knex.QueryBuilder<TRecord, TResult>;
condition<TRecord, TResult>(
conditionObj: XcXonditionObj,
conditionObj: Condition,
columnAliases?: {
[columnAlias: string]: string;
},
@ -542,7 +546,7 @@ declare module 'knex' {
): Knex.QueryBuilder<TRecord, TResult>;
conditionGraph<TRecord, TResult>(condition: {
condition: XcXonditionObj;
condition: Condition;
models: { [key: string]: BaseModelSql };
}): 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 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<void> {
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<any> {
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<number> {
@ -590,7 +593,7 @@ export class MetaService {
target: string,
data: any,
idOrCondition?: string | { [p: string]: any },
xcCondition?,
xcCondition?: Condition,
): Promise<any> {
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<void> {
NcError.notImplemented('metaDeleteAll');
// await this.knexConnection..dropTableIfExists('nc_roles').;
// await this.knexConnection.schema.dropTableIfExists('nc_store').;
// await this.knexConnection.schema.dropTableIfExists('nc_hooks').;

Loading…
Cancel
Save