From d4ec07fa8a2100345b5684c6f16fa2d403bf7b94 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Nov 2024 15:30:10 +0000 Subject: [PATCH 1/4] Removing the datasource query API for datasource plus, this isn't used and has no real purpose (internal tables aren't supported) removing it as it exposes very internal types to the API, making it harder to adjust these types. --- .../server/src/api/controllers/datasource.ts | 10 ----- packages/server/src/api/routes/datasource.ts | 9 ---- .../routes/tests/queries/generic-sql.spec.ts | 43 ------------------- .../src/tests/utilities/api/datasource.ts | 10 ----- 4 files changed, 72 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index 794e2dfddd..97cf8db299 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -296,16 +296,6 @@ export async function find(ctx: UserCtx) { ctx.body = await sdk.datasources.removeSecretSingle(datasource) } -// dynamic query functionality -export async function query(ctx: UserCtx) { - const queryJson = ctx.request.body - try { - ctx.body = await sdk.rows.utils.getDatasourceAndQuery(queryJson) - } catch (err: any) { - ctx.throw(400, err) - } -} - export async function getExternalSchema(ctx: UserCtx) { const datasource = await sdk.datasources.get(ctx.params.datasourceId) const enrichedDatasource = await sdk.datasources.getAndMergeDatasource( diff --git a/packages/server/src/api/routes/datasource.ts b/packages/server/src/api/routes/datasource.ts index 755088c56c..22f9a77cc9 100644 --- a/packages/server/src/api/routes/datasource.ts +++ b/packages/server/src/api/routes/datasource.ts @@ -41,15 +41,6 @@ router ), datasourceController.update ) - .post( - "/api/datasources/query", - authorized( - permissions.PermissionType.TABLE, - permissions.PermissionLevel.READ - ), - datasourceQueryValidator(), - datasourceController.query - ) .post( "/api/datasources/:datasourceId/schema", authorized(permissions.BUILDER), diff --git a/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts b/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts index 44b21e0350..001f4890fd 100644 --- a/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts +++ b/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts @@ -817,49 +817,6 @@ if (descriptions.length) { }) describe("query through datasource", () => { - it("should be able to query the datasource", async () => { - const datasource = await config.api.datasource.create(rawDatasource) - - const entityId = tableName - await config.api.datasource.update({ - ...datasource, - entities: { - [entityId]: { - name: entityId, - schema: {}, - type: "table", - primary: ["id"], - sourceId: datasource._id!, - sourceType: TableSourceType.EXTERNAL, - }, - }, - }) - - const res = await config.api.datasource.query({ - endpoint: { - datasourceId: datasource._id!, - operation: Operation.READ, - entityId, - }, - resource: { - fields: ["id", "name"], - }, - filters: { - string: { - name: "two", - }, - }, - }) - expect(res).toHaveLength(1) - expect(res[0]).toEqual({ - id: 2, - name: "two", - // the use of table.* introduces the possibility of nulls being returned - birthday: null, - number: null, - }) - }) - // this parameter really only impacts SQL queries describe("confirm nullDefaultSupport", () => { let queryParams: Partial diff --git a/packages/server/src/tests/utilities/api/datasource.ts b/packages/server/src/tests/utilities/api/datasource.ts index 67484a688a..9be7be998d 100644 --- a/packages/server/src/tests/utilities/api/datasource.ts +++ b/packages/server/src/tests/utilities/api/datasource.ts @@ -66,16 +66,6 @@ export class DatasourceAPI extends TestAPI { return await this._get(`/api/datasources`, { expectations }) } - query = async ( - query: Omit & Partial>, - expectations?: Expectations - ) => { - return await this._post(`/api/datasources/query`, { - body: query, - expectations, - }) - } - fetchSchema = async ( { datasourceId, From a162d8d9f584ff5d255e2799c8e62bd95f947bd2 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Nov 2024 16:43:21 +0000 Subject: [PATCH 2/4] Linting. --- packages/server/src/api/routes/datasource.ts | 5 +---- .../src/api/routes/tests/queries/generic-sql.spec.ts | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/server/src/api/routes/datasource.ts b/packages/server/src/api/routes/datasource.ts index 22f9a77cc9..9ec792632a 100644 --- a/packages/server/src/api/routes/datasource.ts +++ b/packages/server/src/api/routes/datasource.ts @@ -2,10 +2,7 @@ import Router from "@koa/router" import * as datasourceController from "../controllers/datasource" import authorized from "../../middleware/authorized" import { permissions } from "@budibase/backend-core" -import { - datasourceValidator, - datasourceQueryValidator, -} from "./utils/validators" +import { datasourceValidator } from "./utils/validators" const router: Router = new Router() diff --git a/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts b/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts index 001f4890fd..e7ddc0df22 100644 --- a/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts +++ b/packages/server/src/api/routes/tests/queries/generic-sql.spec.ts @@ -1,10 +1,4 @@ -import { - Datasource, - Operation, - Query, - QueryPreview, - TableSourceType, -} from "@budibase/types" +import { Datasource, Query, QueryPreview } from "@budibase/types" import { DatabaseName, datasourceDescribe, From 69106306c4f50de1aece5fc74383f4b9716d40c6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Nov 2024 16:43:47 +0000 Subject: [PATCH 3/4] Removing unused validator. --- .../server/src/api/routes/utils/validators.ts | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/packages/server/src/api/routes/utils/validators.ts b/packages/server/src/api/routes/utils/validators.ts index 3bee4f88ce..30862cfc68 100644 --- a/packages/server/src/api/routes/utils/validators.ts +++ b/packages/server/src/api/routes/utils/validators.ts @@ -231,30 +231,6 @@ export function externalSearchValidator() { ) } -export function datasourceQueryValidator() { - return auth.joiValidator.body( - Joi.object({ - endpoint: Joi.object({ - datasourceId: Joi.string().required(), - operation: Joi.string() - .required() - .valid(...Object.values(DataSourceOperation)), - entityId: Joi.string().required(), - }).required(), - resource: Joi.object({ - fields: Joi.array().items(Joi.string()).optional(), - }).optional(), - body: Joi.object().optional(), - sort: Joi.object().optional(), - filters: filterObject().optional(), - paginate: Joi.object({ - page: Joi.string().alphanum().optional(), - limit: Joi.number().optional(), - }).optional(), - }) - ) -} - export function webhookValidator() { return auth.joiValidator.body( Joi.object({ From 13918c5789fa6e1195cda7376e2c6bfda885fe45 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Nov 2024 16:49:35 +0000 Subject: [PATCH 4/4] More linting. --- packages/server/src/api/routes/utils/validators.ts | 1 - packages/server/src/constants/index.ts | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/packages/server/src/api/routes/utils/validators.ts b/packages/server/src/api/routes/utils/validators.ts index 30862cfc68..a8fa12ec3d 100644 --- a/packages/server/src/api/routes/utils/validators.ts +++ b/packages/server/src/api/routes/utils/validators.ts @@ -1,5 +1,4 @@ import { auth, permissions } from "@budibase/backend-core" -import { DataSourceOperation } from "../../../constants" import { AutomationActionStepId, AutomationStep, diff --git a/packages/server/src/constants/index.ts b/packages/server/src/constants/index.ts index bac838b53e..604a81cd9f 100644 --- a/packages/server/src/constants/index.ts +++ b/packages/server/src/constants/index.ts @@ -45,17 +45,6 @@ export enum AuthTypes { EXTERNAL = "external", } -export enum DataSourceOperation { - CREATE = "CREATE", - READ = "READ", - UPDATE = "UPDATE", - DELETE = "DELETE", - BULK_CREATE = "BULK_CREATE", - CREATE_TABLE = "CREATE_TABLE", - UPDATE_TABLE = "UPDATE_TABLE", - DELETE_TABLE = "DELETE_TABLE", -} - export enum DatasourceAuthTypes { GOOGLE = "google", }