1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

Merge branch 'master' of github.com:budibase/budibase into print-line-debugging-baby-hell-yeah

This commit is contained in:
Sam Rose 2024-07-24 15:12:34 +01:00
commit ac8b759262
No known key found for this signature in database
11 changed files with 98 additions and 46 deletions

View file

@ -164,7 +164,7 @@ jobs:
- name: Pull testcontainers images - name: Pull testcontainers images
run: | run: |
docker pull mcr.microsoft.com/mssql/server:2022-latest & docker pull mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04 &
docker pull mysql:8.3 & docker pull mysql:8.3 &
docker pull postgres:16.1-bullseye & docker pull postgres:16.1-bullseye &
docker pull mongo:7.0-jammy & docker pull mongo:7.0-jammy &

13
nx.json
View file

@ -10,7 +10,18 @@
}, },
"targetDefaults": { "targetDefaults": {
"build": { "build": {
"inputs": ["{workspaceRoot}/scripts/*", "{workspaceRoot}/lerna.json"] "inputs": [
"{workspaceRoot}/scripts/*",
"{workspaceRoot}/lerna.json",
"{workspaceRoot}/.github/workflows/*"
]
},
"test": {
"inputs": [
"{workspaceRoot}/scripts/*",
"{workspaceRoot}/lerna.json",
"{workspaceRoot}/.github/workflows/*"
]
} }
}, },
"namedInputs": { "namedInputs": {

View file

@ -92,25 +92,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
} }
} }
export async function find(ctx: UserCtx): Promise<Row> {
const id = ctx.params.rowId
const tableId = utils.getTableId(ctx)
const row = await sdk.rows.external.getRow(tableId, id, {
relationships: true,
})
if (!row) {
ctx.throw(404)
}
const table = await sdk.tables.getTable(tableId)
// Preserving links, as the outputProcessing does not support external rows yet and we don't need it in this use case
return await outputProcessing(table, row, {
squash: true,
preserveLinks: true,
})
}
export async function destroy(ctx: UserCtx) { export async function destroy(ctx: UserCtx) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
const _id = ctx.request.body._id const _id = ctx.request.body._id

View file

@ -117,7 +117,9 @@ export async function fetch(ctx: any) {
export async function find(ctx: UserCtx<void, GetRowResponse>) { export async function find(ctx: UserCtx<void, GetRowResponse>) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
ctx.body = await pickApi(tableId).find(ctx) const rowId = ctx.params.rowId
ctx.body = await sdk.rows.find(tableId, rowId)
} }
function isDeleteRows(input: any): input is DeleteRows { function isDeleteRows(input: any): input is DeleteRows {
@ -278,7 +280,8 @@ export async function downloadAttachment(ctx: UserCtx) {
const { columnName } = ctx.params const { columnName } = ctx.params
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
const row = await pickApi(tableId).find(ctx) const rowId = ctx.params.rowId
const row = await sdk.rows.find(tableId, rowId)
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)
const columnSchema = table.schema[columnName] const columnSchema = table.schema[columnName]

View file

@ -32,7 +32,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
try { try {
oldRow = await outputProcessing( oldRow = await outputProcessing(
dbTable, dbTable,
await utils.findRow(ctx, tableId, inputs._id!) await utils.findRow(tableId, inputs._id!)
) )
} catch (err) { } catch (err) {
if (isUserTable) { if (isUserTable) {
@ -96,15 +96,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
return { ...result, oldRow } return { ...result, oldRow }
} }
export async function find(ctx: UserCtx): Promise<Row> {
const tableId = utils.getTableId(ctx),
rowId = ctx.params.rowId
const table = await sdk.tables.getTable(tableId)
let row = await utils.findRow(ctx, tableId, rowId)
row = await outputProcessing(table, row)
return row
}
export async function destroy(ctx: UserCtx) { export async function destroy(ctx: UserCtx) {
const db = context.getAppDB() const db = context.getAppDB()
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
@ -195,7 +186,7 @@ export async function fetchEnrichedRow(ctx: UserCtx) {
sdk.tables.getTable(tableId), sdk.tables.getTable(tableId),
linkRows.getLinkDocuments({ tableId, rowId, fieldName }), linkRows.getLinkDocuments({ tableId, rowId, fieldName }),
]) ])
let row = await utils.findRow(ctx, tableId, rowId) let row = await utils.findRow(tableId, rowId)
row = await outputProcessing(table, row) row = await outputProcessing(table, row)
const linkVals = links as LinkDocumentValue[] const linkVals = links as LinkDocumentValue[]

View file

@ -1,5 +1,5 @@
import { InternalTables } from "../../../../db/utils" import { InternalTables } from "../../../../db/utils"
import * as userController from "../../user"
import { context } from "@budibase/backend-core" import { context } from "@budibase/backend-core"
import { import {
Ctx, Ctx,
@ -8,7 +8,6 @@ import {
RelationshipsJson, RelationshipsJson,
Row, Row,
Table, Table,
UserCtx,
} from "@budibase/types" } from "@budibase/types"
import { import {
processDates, processDates,
@ -24,6 +23,7 @@ import {
import sdk from "../../../../sdk" import sdk from "../../../../sdk"
import { processStringSync } from "@budibase/string-templates" import { processStringSync } from "@budibase/string-templates"
import validateJs from "validate.js" import validateJs from "validate.js"
import { getFullUser } from "../../../../utilities/users"
validateJs.extend(validateJs.validators.datetime, { validateJs.extend(validateJs.validators.datetime, {
parse: function (value: string) { parse: function (value: string) {
@ -63,16 +63,12 @@ export async function processRelationshipFields(
return row return row
} }
export async function findRow(ctx: UserCtx, tableId: string, rowId: string) { export async function findRow(tableId: string, rowId: string) {
const db = context.getAppDB() const db = context.getAppDB()
let row: Row let row: Row
// TODO remove special user case in future // TODO remove special user case in future
if (tableId === InternalTables.USER_METADATA) { if (tableId === InternalTables.USER_METADATA) {
ctx.params = { row = await getFullUser(rowId)
id: rowId,
}
await userController.findMetadata(ctx)
row = ctx.body
} else { } else {
row = await db.get(rowId) row = await db.get(rowId)
} }

View file

@ -36,6 +36,7 @@ import { generator, mocks } from "@budibase/backend-core/tests"
import _, { merge } from "lodash" import _, { merge } from "lodash"
import * as uuid from "uuid" import * as uuid from "uuid"
import { Knex } from "knex" import { Knex } from "knex"
import { InternalTables } from "../../../db/utils"
const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString() const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString()
tk.freeze(timestamp) tk.freeze(timestamp)
@ -804,6 +805,23 @@ describe.each([
status: 404, status: 404,
}) })
}) })
isInternal &&
it("can search row from user table", async () => {
const res = await config.api.row.get(
InternalTables.USER_METADATA,
config.userMetadataId!
)
expect(res).toEqual({
...config.getUser(),
_id: config.userMetadataId!,
_rev: expect.any(String),
roles: undefined,
roleId: "ADMIN",
tableId: InternalTables.USER_METADATA,
})
})
}) })
describe("fetch", () => { describe("fetch", () => {

View file

@ -9,7 +9,9 @@ let ports: Promise<testContainerUtils.Port[]>
export async function getDatasource(): Promise<Datasource> { export async function getDatasource(): Promise<Datasource> {
if (!ports) { if (!ports) {
ports = startContainer( ports = startContainer(
new GenericContainer("mcr.microsoft.com/mssql/server:2022-latest") new GenericContainer(
"mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04"
)
.withExposedPorts(1433) .withExposedPorts(1433)
.withEnvironment({ .withEnvironment({
ACCEPT_EULA: "Y", ACCEPT_EULA: "Y",

View file

@ -1,4 +1,5 @@
import { IncludeRelationship, Operation, Row } from "@budibase/types" import { IncludeRelationship, Operation, Row } from "@budibase/types"
import { HTTPError } from "@budibase/backend-core"
import { handleRequest } from "../../../api/controllers/row/external" import { handleRequest } from "../../../api/controllers/row/external"
import { breakRowIdField } from "../../../integrations/utils" import { breakRowIdField } from "../../../integrations/utils"
import sdk from "../../../sdk" import sdk from "../../../sdk"
@ -53,7 +54,7 @@ export async function save(
const rowId = response.row._id const rowId = response.row._id
if (rowId) { if (rowId) {
const row = await sdk.rows.external.getRow(tableId, rowId, { const row = await getRow(tableId, rowId, {
relationships: true, relationships: true,
}) })
return { return {
@ -67,3 +68,20 @@ export async function save(
return response return response
} }
} }
export async function find(tableId: string, rowId: string): Promise<Row> {
const row = await getRow(tableId, rowId, {
relationships: true,
})
if (!row) {
throw new HTTPError("Row not found", 404)
}
const table = await sdk.tables.getTable(tableId)
// Preserving links, as the outputProcessing does not support external rows yet and we don't need it in this use case
return await outputProcessing(table, row, {
squash: true,
preserveLinks: true,
})
}

View file

@ -1,10 +1,15 @@
import { db } from "@budibase/backend-core" import { context, db } from "@budibase/backend-core"
import { Row } from "@budibase/types" import { Row } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import cloneDeep from "lodash/fp/cloneDeep" import cloneDeep from "lodash/fp/cloneDeep"
import { finaliseRow } from "../../../api/controllers/row/staticFormula" import { finaliseRow } from "../../../api/controllers/row/staticFormula"
import { inputProcessing } from "../../../utilities/rowProcessor" import {
inputProcessing,
outputProcessing,
} from "../../../utilities/rowProcessor"
import * as linkRows from "../../../db/linkedRows" import * as linkRows from "../../../db/linkedRows"
import { InternalTables } from "../../../db/utils"
import { getFullUser } from "../../../utilities/users"
export async function save( export async function save(
tableId: string, tableId: string,
@ -47,3 +52,26 @@ export async function save(
updateFormula: true, updateFormula: true,
}) })
} }
export async function find(tableId: string, rowId: string): Promise<Row> {
const table = await sdk.tables.getTable(tableId)
let row = await findRow(tableId, rowId)
row = await outputProcessing(table, row)
return row
}
async function findRow(tableId: string, rowId: string) {
const db = context.getAppDB()
let row: Row
// TODO remove special user case in future
if (tableId === InternalTables.USER_METADATA) {
row = await getFullUser(rowId)
} else {
row = await db.get(rowId)
}
if (row.tableId !== tableId) {
throw "Supplied tableId does not match the rows tableId"
}
return row
}

View file

@ -34,3 +34,7 @@ export async function save(
) { ) {
return pickApi(tableId).save(tableId, row, userId) return pickApi(tableId).save(tableId, row, userId)
} }
export async function find(tableId: string, rowId: string) {
return pickApi(tableId).find(tableId, rowId)
}