Merge branch 'master' of github.com:budibase/budibase into use-right-docker-socket

This commit is contained in:
Sam Rose 2024-11-28 17:23:23 +00:00
commit f504ef404f
No known key found for this signature in database
8 changed files with 3 additions and 124 deletions

@ -1 +1 @@
Subproject commit 6f38253253ee364aea636add990083ca5cda3bde
Subproject commit e2252498ddfade3c2592b1ec78f7bee4e3cf0d2f

View File

@ -23,13 +23,11 @@ import {
Table,
RowValue,
DynamicVariable,
QueryJsonRequest,
} from "@budibase/types"
import sdk from "../../sdk"
import { builderSocket } from "../../websockets"
import { isEqual } from "lodash"
import { processTable } from "../../sdk/app/tables/getters"
import { makeExternalQuery } from "../../integrations/base/query"
export async function fetch(ctx: UserCtx) {
ctx.body = await sdk.datasources.fetch()
@ -298,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<QueryJsonRequest>) {
const queryJson = ctx.request.body
try {
ctx.body = await makeExternalQuery(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(

View File

@ -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()
@ -41,15 +38,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),

View File

@ -1,10 +1,4 @@
import {
Datasource,
Operation,
Query,
QueryPreview,
TableSourceType,
} from "@budibase/types"
import { Datasource, Query, QueryPreview } from "@budibase/types"
import {
DatabaseName,
datasourceDescribe,
@ -817,49 +811,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<Query>

View File

@ -1,5 +1,4 @@
import { auth, permissions } from "@budibase/backend-core"
import { DataSourceOperation } from "../../../constants"
import {
AutomationActionStepId,
AutomationStep,
@ -231,30 +230,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({

View File

@ -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",
}

View File

@ -4,7 +4,6 @@ import {
Datasource,
FetchDatasourceInfoResponse,
FieldType,
QueryJsonRequest,
RelationshipType,
UpdateDatasourceRequest,
UpdateDatasourceResponse,
@ -69,13 +68,6 @@ export class DatasourceAPI extends TestAPI {
return await this._get<Datasource[]>(`/api/datasources`, { expectations })
}
query = async (query: QueryJsonRequest, expectations?: Expectations) => {
return await this._post<any>(`/api/datasources/query`, {
body: query,
expectations,
})
}
fetchSchema = async (
{
datasourceId,

View File

@ -190,10 +190,6 @@ export interface EnrichedQueryJson extends QueryJson {
datasource?: Datasource
}
export interface QueryJsonRequest extends Omit<QueryJson, "endpoint"> {
endpoint: QueryJson["endpoint"] & { datasourceId: string; entityId: string }
}
export interface QueryOptions {
disableReturning?: boolean
disableBindings?: boolean