Merge branch 'master' into feature/deprecate-table-component
This commit is contained in:
commit
41b3243ace
|
@ -36,12 +36,14 @@
|
||||||
"files": ["**/*.ts"],
|
"files": ["**/*.ts"],
|
||||||
"excludedFiles": ["qa-core/**"],
|
"excludedFiles": ["qa-core/**"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"plugins": ["@typescript-eslint"],
|
||||||
"extends": ["eslint:recommended"],
|
"extends": ["eslint:recommended"],
|
||||||
"globals": {
|
"globals": {
|
||||||
"NodeJS": true
|
"NodeJS": true
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
"local-rules/no-budibase-imports": "error"
|
"local-rules/no-budibase-imports": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -49,7 +51,7 @@
|
||||||
"files": ["**/*.spec.ts"],
|
"files": ["**/*.spec.ts"],
|
||||||
"excludedFiles": ["qa-core/**"],
|
"excludedFiles": ["qa-core/**"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"plugins": ["jest"],
|
"plugins": ["jest", "@typescript-eslint"],
|
||||||
"extends": ["eslint:recommended", "plugin:jest/recommended"],
|
"extends": ["eslint:recommended", "plugin:jest/recommended"],
|
||||||
"env": {
|
"env": {
|
||||||
"jest/globals": true
|
"jest/globals": true
|
||||||
|
@ -59,6 +61,7 @@
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
"local-rules/no-test-com": "error",
|
"local-rules/no-test-com": "error",
|
||||||
"local-rules/email-domain-example-com": "error",
|
"local-rules/email-domain-example-com": "error",
|
||||||
"no-console": "warn",
|
"no-console": "warn",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "2.22.5",
|
"version": "2.22.7",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*",
|
"packages/*",
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
"svelte": "^4.2.10",
|
"svelte": "^4.2.10",
|
||||||
"svelte-eslint-parser": "^0.33.1",
|
"svelte-eslint-parser": "^0.33.1",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
|
"typescript-eslint": "^7.3.1",
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6465dc9c2a38e1380b32204cad4ae0c1f33e065a
|
Subproject commit f5b467b6b1c55c48847545db41be7b1c035e167a
|
|
@ -129,7 +129,7 @@ export default class BaseCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async bustCache(key: string, opts = { client: null }) {
|
async bustCache(key: string) {
|
||||||
const client = await this.getClient()
|
const client = await this.getClient()
|
||||||
try {
|
try {
|
||||||
await client.delete(generateTenantKey(key))
|
await client.delete(generateTenantKey(key))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as utils from "../utils"
|
import * as utils from "../utils"
|
||||||
import { Duration, DurationType } from "../utils"
|
import { Duration } from "../utils"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { getTenantId } from "../context"
|
import { getTenantId } from "../context"
|
||||||
import * as redis from "../redis/init"
|
import * as redis from "../redis/init"
|
||||||
|
|
|
@ -8,7 +8,7 @@ const DEFAULT_WRITE_RATE_MS = 10000
|
||||||
let CACHE: BaseCache | null = null
|
let CACHE: BaseCache | null = null
|
||||||
|
|
||||||
interface CacheItem<T extends Document> {
|
interface CacheItem<T extends Document> {
|
||||||
doc: any
|
doc: T
|
||||||
lastWrite: number
|
lastWrite: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,6 @@ interface SearchResponse<T> {
|
||||||
totalRows: number
|
totalRows: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PaginatedSearchResponse<T> extends SearchResponse<T> {
|
|
||||||
hasNextPage: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SearchParams<T> = {
|
export type SearchParams<T> = {
|
||||||
tableId?: string
|
tableId?: string
|
||||||
sort?: string
|
sort?: string
|
||||||
|
|
|
@ -17,13 +17,8 @@ export function init(processors: ProcessorMap) {
|
||||||
// if not processing in this instance, kick it off
|
// if not processing in this instance, kick it off
|
||||||
if (!processingPromise) {
|
if (!processingPromise) {
|
||||||
processingPromise = asyncEventQueue.process(async job => {
|
processingPromise = asyncEventQueue.process(async job => {
|
||||||
const { event, identity, properties, timestamp } = job.data
|
const { event, identity, properties } = job.data
|
||||||
await documentProcessor.processEvent(
|
await documentProcessor.processEvent(event, identity, properties)
|
||||||
event,
|
|
||||||
identity,
|
|
||||||
properties,
|
|
||||||
timestamp
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
Event,
|
Event,
|
||||||
Identity,
|
Identity,
|
||||||
Group,
|
|
||||||
IdentityType,
|
IdentityType,
|
||||||
AuditLogQueueEvent,
|
AuditLogQueueEvent,
|
||||||
AuditLogFn,
|
AuditLogFn,
|
||||||
|
@ -79,11 +78,11 @@ export default class AuditLogsProcessor implements EventProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async identify(identity: Identity, timestamp?: string | number) {
|
async identify() {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
async identifyGroup(group: Group, timestamp?: string | number) {
|
async identifyGroup() {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@ export default class LoggingProcessor implements EventProcessor {
|
||||||
async processEvent(
|
async processEvent(
|
||||||
event: Event,
|
event: Event,
|
||||||
identity: Identity,
|
identity: Identity,
|
||||||
properties: any,
|
properties: any
|
||||||
timestamp?: string
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (skipLogging) {
|
if (skipLogging) {
|
||||||
return
|
return
|
||||||
|
@ -17,14 +16,14 @@ export default class LoggingProcessor implements EventProcessor {
|
||||||
console.log(`[audit] [identityType=${identity.type}] ${event}`, properties)
|
console.log(`[audit] [identityType=${identity.type}] ${event}`, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
async identify(identity: Identity, timestamp?: string | number) {
|
async identify(identity: Identity) {
|
||||||
if (skipLogging) {
|
if (skipLogging) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(`[audit] identified`, identity)
|
console.log(`[audit] identified`, identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
async identifyGroup(group: Group, timestamp?: string | number) {
|
async identifyGroup(group: Group) {
|
||||||
if (skipLogging) {
|
if (skipLogging) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,7 @@ export default class DocumentUpdateProcessor implements EventProcessor {
|
||||||
this.processors = processors
|
this.processors = processors
|
||||||
}
|
}
|
||||||
|
|
||||||
async processEvent(
|
async processEvent(event: Event, identity: Identity, properties: any) {
|
||||||
event: Event,
|
|
||||||
identity: Identity,
|
|
||||||
properties: any,
|
|
||||||
timestamp?: string | number
|
|
||||||
) {
|
|
||||||
const tenantId = identity.realTenantId
|
const tenantId = identity.realTenantId
|
||||||
const docId = getDocumentId(event, properties)
|
const docId = getDocumentId(event, properties)
|
||||||
if (!tenantId || !docId) {
|
if (!tenantId || !docId) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ export const buildMatcherRegex = (
|
||||||
}
|
}
|
||||||
|
|
||||||
export const matches = (ctx: BBContext, options: RegexMatcher[]) => {
|
export const matches = (ctx: BBContext, options: RegexMatcher[]) => {
|
||||||
return options.find(({ regex, method, route }) => {
|
return options.find(({ regex, method }) => {
|
||||||
const urlMatch = regex.test(ctx.request.url)
|
const urlMatch = regex.test(ctx.request.url)
|
||||||
const methodMatch =
|
const methodMatch =
|
||||||
method === "ALL"
|
method === "ALL"
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Cookie } from "../../../constants"
|
||||||
import * as configs from "../../../configs"
|
import * as configs from "../../../configs"
|
||||||
import * as cache from "../../../cache"
|
import * as cache from "../../../cache"
|
||||||
import * as utils from "../../../utils"
|
import * as utils from "../../../utils"
|
||||||
import { UserCtx, SSOProfile, DatasourceAuthCookie } from "@budibase/types"
|
import { UserCtx, SSOProfile } from "@budibase/types"
|
||||||
import { ssoSaveUserNoOp } from "../sso/sso"
|
import { ssoSaveUserNoOp } from "../sso/sso"
|
||||||
|
|
||||||
const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy
|
const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as context from "../../../context"
|
||||||
import fetch from "node-fetch"
|
import fetch from "node-fetch"
|
||||||
import {
|
import {
|
||||||
SaveSSOUserFunction,
|
SaveSSOUserFunction,
|
||||||
SaveUserOpts,
|
|
||||||
SSOAuthDetails,
|
SSOAuthDetails,
|
||||||
SSOUser,
|
SSOUser,
|
||||||
User,
|
User,
|
||||||
|
@ -14,10 +13,8 @@ import {
|
||||||
// no-op function for user save
|
// no-op function for user save
|
||||||
// - this allows datasource auth and access token refresh to work correctly
|
// - this allows datasource auth and access token refresh to work correctly
|
||||||
// - prefer no-op over an optional argument to ensure function is provided to login flows
|
// - prefer no-op over an optional argument to ensure function is provided to login flows
|
||||||
export const ssoSaveUserNoOp: SaveSSOUserFunction = (
|
export const ssoSaveUserNoOp: SaveSSOUserFunction = (user: SSOUser) =>
|
||||||
user: SSOUser,
|
Promise.resolve(user)
|
||||||
opts: SaveUserOpts
|
|
||||||
) => Promise.resolve(user)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common authentication logic for third parties. e.g. OAuth, OIDC.
|
* Common authentication logic for third parties. e.g. OAuth, OIDC.
|
||||||
|
|
|
@ -45,10 +45,6 @@ export const runMigration = async (
|
||||||
options: MigrationOptions = {}
|
options: MigrationOptions = {}
|
||||||
) => {
|
) => {
|
||||||
const migrationType = migration.type
|
const migrationType = migration.type
|
||||||
let tenantId: string | undefined
|
|
||||||
if (migrationType !== MigrationType.INSTALLATION) {
|
|
||||||
tenantId = context.getTenantId()
|
|
||||||
}
|
|
||||||
const migrationName = migration.name
|
const migrationName = migration.name
|
||||||
const silent = migration.silent
|
const silent = migration.silent
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ describe("app", () => {
|
||||||
|
|
||||||
it("gets url with embedded minio", async () => {
|
it("gets url with embedded minio", async () => {
|
||||||
testEnv.withMinio()
|
testEnv.withMinio()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(() => {
|
||||||
const url = getAppFileUrl()
|
const url = getAppFileUrl()
|
||||||
expect(url).toBe(
|
expect(url).toBe(
|
||||||
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
|
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
|
||||||
|
@ -136,7 +136,7 @@ describe("app", () => {
|
||||||
|
|
||||||
it("gets url with custom S3", async () => {
|
it("gets url with custom S3", async () => {
|
||||||
testEnv.withS3()
|
testEnv.withS3()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(() => {
|
||||||
const url = getAppFileUrl()
|
const url = getAppFileUrl()
|
||||||
expect(url).toBe(
|
expect(url).toBe(
|
||||||
"http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg"
|
"http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg"
|
||||||
|
@ -146,7 +146,7 @@ describe("app", () => {
|
||||||
|
|
||||||
it("gets url with cloudfront + s3", async () => {
|
it("gets url with cloudfront + s3", async () => {
|
||||||
testEnv.withCloudfront()
|
testEnv.withCloudfront()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(() => {
|
||||||
const url = getAppFileUrl()
|
const url = getAppFileUrl()
|
||||||
// omit rest of signed params
|
// omit rest of signed params
|
||||||
expect(
|
expect(
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { DBTestConfiguration } from "../../../tests/extra"
|
||||||
import * as tenants from "../tenants"
|
import * as tenants from "../tenants"
|
||||||
|
|
||||||
describe("tenants", () => {
|
describe("tenants", () => {
|
||||||
const config = new DBTestConfiguration()
|
new DBTestConfiguration()
|
||||||
|
|
||||||
describe("addTenant", () => {
|
describe("addTenant", () => {
|
||||||
it("concurrently adds multiple tenants safely", async () => {
|
it("concurrently adds multiple tenants safely", async () => {
|
||||||
|
|
|
@ -166,7 +166,7 @@ class InMemoryQueue implements Partial<Queue> {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async removeJobs(pattern: string) {
|
async removeJobs(pattern: string) {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ function logging(queue: Queue, jobQueue: JobQueue) {
|
||||||
// A Job is waiting to be processed as soon as a worker is idling.
|
// A Job is waiting to be processed as soon as a worker is idling.
|
||||||
console.info(...getLogParams(eventType, BullEvent.WAITING, { jobId }))
|
console.info(...getLogParams(eventType, BullEvent.WAITING, { jobId }))
|
||||||
})
|
})
|
||||||
.on(BullEvent.ACTIVE, async (job: Job, jobPromise: any) => {
|
.on(BullEvent.ACTIVE, async (job: Job) => {
|
||||||
// A job has started. You can use `jobPromise.cancel()`` to abort it.
|
// A job has started. You can use `jobPromise.cancel()`` to abort it.
|
||||||
await doInJobContext(job, () => {
|
await doInJobContext(job, () => {
|
||||||
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))
|
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))
|
||||||
|
|
|
@ -40,6 +40,7 @@ export async function shutdown() {
|
||||||
if (inviteClient) await inviteClient.finish()
|
if (inviteClient) await inviteClient.finish()
|
||||||
if (passwordResetClient) await passwordResetClient.finish()
|
if (passwordResetClient) await passwordResetClient.finish()
|
||||||
if (socketClient) await socketClient.finish()
|
if (socketClient) await socketClient.finish()
|
||||||
|
if (docWritethroughClient) await docWritethroughClient.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on("exit", async () => {
|
process.on("exit", async () => {
|
||||||
|
|
|
@ -120,7 +120,7 @@ describe("redis", () => {
|
||||||
|
|
||||||
await redis.bulkStore(data, ttl)
|
await redis.bulkStore(data, ttl)
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const key of Object.keys(data)) {
|
||||||
expect(await redis.get(key)).toBe(null)
|
expect(await redis.get(key)).toBe(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe("Users", () => {
|
||||||
...{ _id: groupId, roles: { app1: "ADMIN" } },
|
...{ _id: groupId, roles: { app1: "ADMIN" } },
|
||||||
}
|
}
|
||||||
const users: User[] = []
|
const users: User[] = []
|
||||||
for (const _ of Array.from({ length: usersInGroup })) {
|
for (let i = 0; i < usersInGroup; i++) {
|
||||||
const userId = `us_${generator.guid()}`
|
const userId = `us_${generator.guid()}`
|
||||||
const user: User = structures.users.user({
|
const user: User = structures.users.user({
|
||||||
_id: userId,
|
_id: userId,
|
||||||
|
|
|
@ -39,19 +39,23 @@ const handleClick = event => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handler.allowedType && event.type !== handler.allowedType) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
handler.callback?.(event)
|
handler.callback?.(event)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
document.documentElement.addEventListener("click", handleClick, true)
|
document.documentElement.addEventListener("click", handleClick, true)
|
||||||
document.documentElement.addEventListener("contextmenu", handleClick, true)
|
document.documentElement.addEventListener("mousedown", handleClick, true)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or updates a click handler
|
* Adds or updates a click handler
|
||||||
*/
|
*/
|
||||||
const updateHandler = (id, element, anchor, callback) => {
|
const updateHandler = (id, element, anchor, callback, allowedType) => {
|
||||||
let existingHandler = clickHandlers.find(x => x.id === id)
|
let existingHandler = clickHandlers.find(x => x.id === id)
|
||||||
if (!existingHandler) {
|
if (!existingHandler) {
|
||||||
clickHandlers.push({ id, element, anchor, callback })
|
clickHandlers.push({ id, element, anchor, callback, allowedType })
|
||||||
} else {
|
} else {
|
||||||
existingHandler.callback = callback
|
existingHandler.callback = callback
|
||||||
}
|
}
|
||||||
|
@ -77,7 +81,8 @@ export default (element, opts) => {
|
||||||
const update = newOpts => {
|
const update = newOpts => {
|
||||||
const callback = newOpts?.callback || newOpts
|
const callback = newOpts?.callback || newOpts
|
||||||
const anchor = newOpts?.anchor || element
|
const anchor = newOpts?.anchor || element
|
||||||
updateHandler(id, element, anchor, callback)
|
const allowedType = newOpts?.allowedType || "click"
|
||||||
|
updateHandler(id, element, anchor, callback, allowedType)
|
||||||
}
|
}
|
||||||
update(opts)
|
update(opts)
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
let deleteTableName
|
let deleteTableName
|
||||||
|
|
||||||
$: externalTable = table?.sourceType === DB_TYPE_EXTERNAL
|
$: externalTable = table?.sourceType === DB_TYPE_EXTERNAL
|
||||||
$: allowDeletion = !externalTable || table?.created
|
|
||||||
|
|
||||||
function showDeleteModal() {
|
function showDeleteModal() {
|
||||||
templateScreens = $screenStore.screens.filter(
|
templateScreens = $screenStore.screens.filter(
|
||||||
|
@ -56,7 +55,7 @@
|
||||||
$goto(`./datasource/${table.datasourceId}`)
|
$goto(`./datasource/${table.datasourceId}`)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error("Error deleting table")
|
notifications.error(`Error deleting table - ${error.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,17 +85,15 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if allowDeletion}
|
<ActionMenu>
|
||||||
<ActionMenu>
|
<div slot="control" class="icon">
|
||||||
<div slot="control" class="icon">
|
<Icon s hoverable name="MoreSmallList" />
|
||||||
<Icon s hoverable name="MoreSmallList" />
|
</div>
|
||||||
</div>
|
{#if !externalTable}
|
||||||
{#if !externalTable}
|
<MenuItem icon="Edit" on:click={editorModal.show}>Edit</MenuItem>
|
||||||
<MenuItem icon="Edit" on:click={editorModal.show}>Edit</MenuItem>
|
{/if}
|
||||||
{/if}
|
<MenuItem icon="Delete" on:click={showDeleteModal}>Delete</MenuItem>
|
||||||
<MenuItem icon="Delete" on:click={showDeleteModal}>Delete</MenuItem>
|
</ActionMenu>
|
||||||
</ActionMenu>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<Modal bind:this={editorModal} on:show={initForm}>
|
<Modal bind:this={editorModal} on:show={initForm}>
|
||||||
<ModalContent
|
<ModalContent
|
||||||
|
|
|
@ -129,10 +129,7 @@
|
||||||
filteredUsers = $usersFetch.rows
|
filteredUsers = $usersFetch.rows
|
||||||
.filter(user => user.email !== $auth.user.email)
|
.filter(user => user.email !== $auth.user.email)
|
||||||
.map(user => {
|
.map(user => {
|
||||||
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(
|
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(user)
|
||||||
user,
|
|
||||||
prodAppId
|
|
||||||
)
|
|
||||||
const isAppBuilder = user.builder?.apps?.includes(prodAppId)
|
const isAppBuilder = user.builder?.apps?.includes(prodAppId)
|
||||||
let role
|
let role
|
||||||
if (isAdminOrGlobalBuilder) {
|
if (isAdminOrGlobalBuilder) {
|
||||||
|
|
|
@ -291,7 +291,10 @@
|
||||||
<div
|
<div
|
||||||
id="side-panel-container"
|
id="side-panel-container"
|
||||||
class:open={$sidePanelStore.open}
|
class:open={$sidePanelStore.open}
|
||||||
use:clickOutside={autoCloseSidePanel ? sidePanelStore.actions.close : null}
|
use:clickOutside={{
|
||||||
|
callback: autoCloseSidePanel ? sidePanelStore.actions.close : null,
|
||||||
|
allowedType: "mousedown",
|
||||||
|
}}
|
||||||
class:builder={$builderStore.inBuilder}
|
class:builder={$builderStore.inBuilder}
|
||||||
>
|
>
|
||||||
<div class="side-panel-header">
|
<div class="side-panel-header">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import { get } from "svelte/store"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
import Block from "components/Block.svelte"
|
import Block from "components/Block.svelte"
|
||||||
import BlockComponent from "components/BlockComponent.svelte"
|
import BlockComponent from "components/BlockComponent.svelte"
|
||||||
|
@ -33,8 +34,9 @@
|
||||||
export let sidePanelDeleteLabel
|
export let sidePanelDeleteLabel
|
||||||
export let notificationOverride
|
export let notificationOverride
|
||||||
|
|
||||||
const { fetchDatasourceSchema, API } = getContext("sdk")
|
const { fetchDatasourceSchema, API, generateGoldenSample } = getContext("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
const context = getContext("context")
|
||||||
const stateKey = `ID_${generate()}`
|
const stateKey = `ID_${generate()}`
|
||||||
|
|
||||||
let formId
|
let formId
|
||||||
|
@ -48,20 +50,6 @@
|
||||||
let schemaLoaded = false
|
let schemaLoaded = false
|
||||||
|
|
||||||
$: deleteLabel = setDeleteLabel(sidePanelDeleteLabel, sidePanelShowDelete)
|
$: deleteLabel = setDeleteLabel(sidePanelDeleteLabel, sidePanelShowDelete)
|
||||||
|
|
||||||
const setDeleteLabel = sidePanelDeleteLabel => {
|
|
||||||
// Accommodate old config to ensure delete button does not reappear
|
|
||||||
let labelText = sidePanelShowDelete === false ? "" : sidePanelDeleteLabel
|
|
||||||
|
|
||||||
// Empty text is considered hidden.
|
|
||||||
if (labelText?.trim() === "") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to "Delete" if the value is unset
|
|
||||||
return labelText || "Delete"
|
|
||||||
}
|
|
||||||
|
|
||||||
$: isDSPlus = dataSource?.type === "table" || dataSource?.type === "viewV2"
|
$: isDSPlus = dataSource?.type === "table" || dataSource?.type === "viewV2"
|
||||||
$: fetchSchema(dataSource)
|
$: fetchSchema(dataSource)
|
||||||
$: enrichSearchColumns(searchColumns, schema).then(
|
$: enrichSearchColumns(searchColumns, schema).then(
|
||||||
|
@ -105,6 +93,30 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Provide additional data context for live binding eval
|
||||||
|
export const getAdditionalDataContext = () => {
|
||||||
|
const rows = get(context)[dataProviderId]?.rows
|
||||||
|
const goldenRow = generateGoldenSample(rows)
|
||||||
|
return {
|
||||||
|
eventContext: {
|
||||||
|
row: goldenRow,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const setDeleteLabel = sidePanelDeleteLabel => {
|
||||||
|
// Accommodate old config to ensure delete button does not reappear
|
||||||
|
let labelText = sidePanelShowDelete === false ? "" : sidePanelDeleteLabel
|
||||||
|
|
||||||
|
// Empty text is considered hidden.
|
||||||
|
if (labelText?.trim() === "") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to "Delete" if the value is unset
|
||||||
|
return labelText || "Delete"
|
||||||
|
}
|
||||||
|
|
||||||
// Load the datasource schema so we can determine column types
|
// Load the datasource schema so we can determine column types
|
||||||
const fetchSchema = async dataSource => {
|
const fetchSchema = async dataSource => {
|
||||||
if (dataSource?.type === "table") {
|
if (dataSource?.type === "table") {
|
||||||
|
|
|
@ -40,16 +40,18 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle certain key presses regardless of selection state
|
||||||
|
if (e.key === "Enter" && (e.ctrlKey || e.metaKey) && $config.canAddRows) {
|
||||||
|
e.preventDefault()
|
||||||
|
dispatch("add-row-inline")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// If nothing selected avoid processing further key presses
|
// If nothing selected avoid processing further key presses
|
||||||
if (!$focusedCellId) {
|
if (!$focusedCellId) {
|
||||||
if (e.key === "Tab" || e.key?.startsWith("Arrow")) {
|
if (e.key === "Tab" || e.key?.startsWith("Arrow")) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
focusFirstCell()
|
focusFirstCell()
|
||||||
} else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
||||||
if ($config.canAddRows) {
|
|
||||||
e.preventDefault()
|
|
||||||
dispatch("add-row-inline")
|
|
||||||
}
|
|
||||||
} else if (e.key === "Delete" || e.key === "Backspace") {
|
} else if (e.key === "Delete" || e.key === "Backspace") {
|
||||||
if (Object.keys($selectedRows).length && $config.canDeleteRows) {
|
if (Object.keys($selectedRows).length && $config.canDeleteRows) {
|
||||||
dispatch("request-bulk-delete")
|
dispatch("request-bulk-delete")
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8baf8586ec078951230c8466d5f13f9b6d5ed055
|
Subproject commit dd748e045ffdbc6662c5d2b76075f01d65a96a2f
|
|
@ -1,3 +1,4 @@
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
module FirebaseMock {
|
module FirebaseMock {
|
||||||
const firebase: any = {}
|
const firebase: any = {}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
module SendgridMock {
|
module SendgridMock {
|
||||||
class Email {
|
class Email {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
module ArangoMock {
|
module ArangoMock {
|
||||||
const arangodb: any = {}
|
const arangodb: any = {}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
module MongoMock {
|
module MongoMock {
|
||||||
const mongodb: any = {}
|
const mongodb: any = {}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
ConnectionPool: jest.fn(() => ({
|
|
||||||
connect: jest.fn(() => ({
|
|
||||||
request: jest.fn(() => ({
|
|
||||||
query: jest.fn(sql => ({ recordset: [sql] })),
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
query: jest.fn(() => ({
|
|
||||||
recordset: [
|
|
||||||
{
|
|
||||||
a: "string",
|
|
||||||
b: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})),
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
const client = {
|
|
||||||
connect: jest.fn(),
|
|
||||||
query: jest.fn((query, bindings, fn) => {
|
|
||||||
fn(null, [])
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
createConnection: jest.fn(() => client),
|
|
||||||
client,
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
module MySQLMock {
|
|
||||||
const mysql: any = {}
|
|
||||||
|
|
||||||
const client = {
|
|
||||||
connect: jest.fn(),
|
|
||||||
end: jest.fn(),
|
|
||||||
query: jest.fn(async () => {
|
|
||||||
return [[]]
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql.createConnection = jest.fn(async () => {
|
|
||||||
return client
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = mysql
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
module FetchMock {
|
module FetchMock {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const fetch = jest.requireActual("node-fetch")
|
const fetch = jest.requireActual("node-fetch")
|
||||||
|
|
|
@ -26,7 +26,6 @@ import {
|
||||||
env as envCore,
|
env as envCore,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
events,
|
events,
|
||||||
HTTPError,
|
|
||||||
migrations,
|
migrations,
|
||||||
objectStore,
|
objectStore,
|
||||||
roles,
|
roles,
|
||||||
|
|
|
@ -116,7 +116,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
||||||
target: prodDb.name,
|
target: prodDb.name,
|
||||||
})
|
})
|
||||||
await replication.replicate({
|
await replication.replicate({
|
||||||
filter: (doc: any, params: any) => {
|
filter: (doc: any) => {
|
||||||
return doc._id && doc._id.startsWith("role_")
|
return doc._id && doc._id.startsWith("role_")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,13 +7,11 @@ import {
|
||||||
FilterType,
|
FilterType,
|
||||||
IncludeRelationship,
|
IncludeRelationship,
|
||||||
ManyToManyRelationshipFieldMetadata,
|
ManyToManyRelationshipFieldMetadata,
|
||||||
ManyToOneRelationshipFieldMetadata,
|
|
||||||
OneToManyRelationshipFieldMetadata,
|
OneToManyRelationshipFieldMetadata,
|
||||||
Operation,
|
Operation,
|
||||||
PaginationJson,
|
PaginationJson,
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
RelationshipsJson,
|
RelationshipsJson,
|
||||||
RelationshipType,
|
|
||||||
Row,
|
Row,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
SortJson,
|
SortJson,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { quotas } from "@budibase/pro"
|
|
||||||
import {
|
import {
|
||||||
UserCtx,
|
UserCtx,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
|
|
|
@ -61,9 +61,6 @@ export async function destroy(ctx: UserCtx) {
|
||||||
const tableToDelete: TableRequest = await sdk.tables.getTable(
|
const tableToDelete: TableRequest = await sdk.tables.getTable(
|
||||||
ctx.params.tableId
|
ctx.params.tableId
|
||||||
)
|
)
|
||||||
if (!tableToDelete || !tableToDelete.created) {
|
|
||||||
ctx.throw(400, "Cannot delete tables which weren't created in Budibase.")
|
|
||||||
}
|
|
||||||
const datasourceId = getDatasourceId(tableToDelete)
|
const datasourceId = getDatasourceId(tableToDelete)
|
||||||
try {
|
try {
|
||||||
const { datasource, table } = await sdk.tables.external.destroy(
|
const { datasource, table } = await sdk.tables.external.destroy(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { generateUserFlagID, InternalTables } from "../../db/utils"
|
import { generateUserFlagID, InternalTables } from "../../db/utils"
|
||||||
import { getFullUser } from "../../utilities/users"
|
import { getFullUser } from "../../utilities/users"
|
||||||
import { cache, context } from "@budibase/backend-core"
|
import { context } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
ContextUserMetadata,
|
ContextUserMetadata,
|
||||||
Ctx,
|
Ctx,
|
||||||
|
|
|
@ -24,7 +24,7 @@ async function parseSchema(view: CreateViewRequest) {
|
||||||
icon: schemaValue.icon,
|
icon: schemaValue.icon,
|
||||||
}
|
}
|
||||||
Object.entries(fieldSchema)
|
Object.entries(fieldSchema)
|
||||||
.filter(([_, val]) => val === undefined)
|
.filter(([, val]) => val === undefined)
|
||||||
.forEach(([key]) => {
|
.forEach(([key]) => {
|
||||||
delete fieldSchema[key as keyof UIFieldMetadata]
|
delete fieldSchema[key as keyof UIFieldMetadata]
|
||||||
})
|
})
|
||||||
|
|
|
@ -33,7 +33,6 @@ export { default as staticRoutes } from "./static"
|
||||||
export { default as publicRoutes } from "./public"
|
export { default as publicRoutes } from "./public"
|
||||||
|
|
||||||
const appBackupRoutes = pro.appBackups
|
const appBackupRoutes = pro.appBackups
|
||||||
const scheduleRoutes = pro.schedules
|
|
||||||
const environmentVariableRoutes = pro.environmentVariables
|
const environmentVariableRoutes = pro.environmentVariables
|
||||||
|
|
||||||
export const mainRoutes: Router[] = [
|
export const mainRoutes: Router[] = [
|
||||||
|
@ -65,7 +64,6 @@ export const mainRoutes: Router[] = [
|
||||||
pluginRoutes,
|
pluginRoutes,
|
||||||
opsRoutes,
|
opsRoutes,
|
||||||
debugRoutes,
|
debugRoutes,
|
||||||
scheduleRoutes,
|
|
||||||
environmentVariableRoutes,
|
environmentVariableRoutes,
|
||||||
// these need to be handled last as they still use /api/:tableId
|
// these need to be handled last as they still use /api/:tableId
|
||||||
// this could be breaking as koa may recognise other routes as this
|
// this could be breaking as koa may recognise other routes as this
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe("/applications/:appId/import", () => {
|
||||||
|
|
||||||
it("should be able to perform import", async () => {
|
it("should be able to perform import", async () => {
|
||||||
const appId = config.getAppId()
|
const appId = config.getAppId()
|
||||||
const res = await request
|
await request
|
||||||
.post(`/api/applications/${appId}/import`)
|
.post(`/api/applications/${appId}/import`)
|
||||||
.field("encryptionPassword", PASSWORD)
|
.field("encryptionPassword", PASSWORD)
|
||||||
.attach("appExport", path.join(__dirname, "assets", "export.tar.gz"))
|
.attach("appExport", path.join(__dirname, "assets", "export.tar.gz"))
|
||||||
|
|
|
@ -2,7 +2,6 @@ import * as setup from "./utilities"
|
||||||
import { roles, db as dbCore } from "@budibase/backend-core"
|
import { roles, db as dbCore } from "@budibase/backend-core"
|
||||||
|
|
||||||
describe("/api/applications/:appId/sync", () => {
|
describe("/api/applications/:appId/sync", () => {
|
||||||
let request = setup.getRequest()
|
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let app
|
let app
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ describe("/applications", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should reject with a known name", async () => {
|
it("should reject with a known name", async () => {
|
||||||
const resp = await config.api.application.duplicateApp(
|
await config.api.application.duplicateApp(
|
||||||
app.appId,
|
app.appId,
|
||||||
{
|
{
|
||||||
name: app.name,
|
name: app.name,
|
||||||
|
@ -381,7 +381,7 @@ describe("/applications", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should reject with a known url", async () => {
|
it("should reject with a known url", async () => {
|
||||||
const resp = await config.api.application.duplicateApp(
|
await config.api.application.duplicateApp(
|
||||||
app.appId,
|
app.appId,
|
||||||
{
|
{
|
||||||
name: "this is fine",
|
name: "this is fine",
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
import * as setup from "./utilities"
|
||||||
const setup = require("./utilities")
|
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
||||||
|
|
||||||
import os from "os"
|
|
||||||
|
|
||||||
jest.mock("process", () => ({
|
|
||||||
arch: "arm64",
|
|
||||||
version: "v14.20.1",
|
|
||||||
platform: "darwin",
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe("/component", () => {
|
describe("/component", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
|
@ -17,21 +9,6 @@ describe("/component", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
os.cpus = () => [
|
|
||||||
{
|
|
||||||
model: "test",
|
|
||||||
speed: 12323,
|
|
||||||
times: {
|
|
||||||
user: 0,
|
|
||||||
nice: 0,
|
|
||||||
sys: 0,
|
|
||||||
idle: 0,
|
|
||||||
irq: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
os.uptime = () => 123123123123
|
|
||||||
os.totalmem = () => 10000000000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("/api/debug", () => {
|
describe("/api/debug", () => {
|
||||||
|
@ -43,14 +20,16 @@ describe("/component", () => {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body).toEqual({
|
expect(res.body).toEqual({
|
||||||
budibaseVersion: "0.0.0+jest",
|
budibaseVersion: "0.0.0+jest",
|
||||||
cpuArch: "arm64",
|
cpuArch: expect.any(String),
|
||||||
cpuCores: 1,
|
cpuCores: expect.any(Number),
|
||||||
cpuInfo: "test",
|
cpuInfo: expect.any(String),
|
||||||
hosting: "docker-compose",
|
hosting: "docker-compose",
|
||||||
nodeVersion: "v14.20.1",
|
nodeVersion: expect.stringMatching(/^v\d+\.\d+\.\d+$/),
|
||||||
platform: "darwin",
|
platform: expect.any(String),
|
||||||
totalMemory: "9.313225746154785GB",
|
totalMemory: expect.stringMatching(/^[0-9\\.]+GB$/),
|
||||||
uptime: "1425036 day(s), 3 hour(s), 32 minute(s)",
|
uptime: expect.stringMatching(
|
||||||
|
/^\d+ day\(s\), \d+ hour\(s\), \d+ minute\(s\)$/
|
||||||
|
),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ describe("/permission", () => {
|
||||||
level: PermissionLevel.READ,
|
level: PermissionLevel.READ,
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await config.api.permission.revoke(
|
await config.api.permission.revoke(
|
||||||
{
|
{
|
||||||
roleId: STD_ROLE_ID,
|
roleId: STD_ROLE_ID,
|
||||||
resourceId: table._id,
|
resourceId: table._id,
|
||||||
|
|
|
@ -0,0 +1,401 @@
|
||||||
|
import { Datasource, Query, SourceName } from "@budibase/types"
|
||||||
|
import * as setup from "../utilities"
|
||||||
|
import { databaseTestProviders } from "../../../../integrations/tests/utils"
|
||||||
|
import pg from "pg"
|
||||||
|
import mysql from "mysql2/promise"
|
||||||
|
import mssql from "mssql"
|
||||||
|
|
||||||
|
jest.unmock("pg")
|
||||||
|
|
||||||
|
const createTableSQL: Record<string, string> = {
|
||||||
|
[SourceName.POSTGRES]: `
|
||||||
|
CREATE TABLE test_table (
|
||||||
|
id serial PRIMARY KEY,
|
||||||
|
name VARCHAR ( 50 ) NOT NULL,
|
||||||
|
birthday TIMESTAMP
|
||||||
|
);`,
|
||||||
|
[SourceName.MYSQL]: `
|
||||||
|
CREATE TABLE test_table (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(50) NOT NULL,
|
||||||
|
birthday TIMESTAMP
|
||||||
|
);`,
|
||||||
|
[SourceName.SQL_SERVER]: `
|
||||||
|
CREATE TABLE test_table (
|
||||||
|
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||||
|
name NVARCHAR(50) NOT NULL,
|
||||||
|
birthday DATETIME
|
||||||
|
);`,
|
||||||
|
}
|
||||||
|
|
||||||
|
const insertSQL = `INSERT INTO test_table (name) VALUES ('one'), ('two'), ('three'), ('four'), ('five')`
|
||||||
|
const dropTableSQL = `DROP TABLE test_table;`
|
||||||
|
|
||||||
|
describe.each([
|
||||||
|
["postgres", databaseTestProviders.postgres],
|
||||||
|
["mysql", databaseTestProviders.mysql],
|
||||||
|
["mssql", databaseTestProviders.mssql],
|
||||||
|
["mariadb", databaseTestProviders.mariadb],
|
||||||
|
])("queries (%s)", (__, dsProvider) => {
|
||||||
|
const config = setup.getConfig()
|
||||||
|
let datasource: Datasource
|
||||||
|
|
||||||
|
async function createQuery(query: Partial<Query>): Promise<Query> {
|
||||||
|
const defaultQuery: Query = {
|
||||||
|
datasourceId: datasource._id!,
|
||||||
|
name: "New Query",
|
||||||
|
parameters: [],
|
||||||
|
fields: {},
|
||||||
|
schema: {},
|
||||||
|
queryVerb: "read",
|
||||||
|
transformer: "return data",
|
||||||
|
readable: true,
|
||||||
|
}
|
||||||
|
return await config.api.query.create({ ...defaultQuery, ...query })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function rawQuery(sql: string): Promise<any> {
|
||||||
|
// We re-fetch the datasource here because the one returned by
|
||||||
|
// config.api.datasource.create has the password field blanked out, and we
|
||||||
|
// need the password to connect to the database.
|
||||||
|
const ds = await dsProvider.datasource()
|
||||||
|
switch (ds.source) {
|
||||||
|
case SourceName.POSTGRES: {
|
||||||
|
const client = new pg.Client(ds.config!)
|
||||||
|
await client.connect()
|
||||||
|
try {
|
||||||
|
const { rows } = await client.query(sql)
|
||||||
|
return rows
|
||||||
|
} finally {
|
||||||
|
await client.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case SourceName.MYSQL: {
|
||||||
|
const con = await mysql.createConnection(ds.config!)
|
||||||
|
try {
|
||||||
|
const [rows] = await con.query(sql)
|
||||||
|
return rows
|
||||||
|
} finally {
|
||||||
|
con.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case SourceName.SQL_SERVER: {
|
||||||
|
const pool = new mssql.ConnectionPool(ds.config! as mssql.config)
|
||||||
|
const client = await pool.connect()
|
||||||
|
try {
|
||||||
|
const { recordset } = await client.query(sql)
|
||||||
|
return recordset
|
||||||
|
} finally {
|
||||||
|
await pool.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
datasource = await config.api.datasource.create(
|
||||||
|
await dsProvider.datasource()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await rawQuery(createTableSQL[datasource.source])
|
||||||
|
await rawQuery(insertSQL)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await rawQuery(dropTableSQL)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await dsProvider.stop()
|
||||||
|
setup.afterAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("create", () => {
|
||||||
|
it("should be able to insert with bindings", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "INSERT INTO test_table (name) VALUES ({{ foo }})",
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "foo",
|
||||||
|
default: "bar",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
queryVerb: "create",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: {
|
||||||
|
foo: "baz",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
created: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const rows = await rawQuery("SELECT * FROM test_table WHERE name = 'baz'")
|
||||||
|
expect(rows).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it.each(["2021-02-05T12:01:00.000Z", "2021-02-05"])(
|
||||||
|
"should coerce %s into a date",
|
||||||
|
async datetimeStr => {
|
||||||
|
const date = new Date(datetimeStr)
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: `INSERT INTO test_table (name, birthday) VALUES ('foo', {{ birthday }})`,
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "birthday",
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
queryVerb: "create",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: { birthday: datetimeStr },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([{ created: true }])
|
||||||
|
|
||||||
|
const rows = await rawQuery(
|
||||||
|
`SELECT * FROM test_table WHERE birthday = '${date.toISOString()}'`
|
||||||
|
)
|
||||||
|
expect(rows).toHaveLength(1)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
it.each(["2021,02,05", "202205-1500"])(
|
||||||
|
"should not coerce %s as a date",
|
||||||
|
async notDateStr => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "INSERT INTO test_table (name) VALUES ({{ name }})",
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
queryVerb: "create",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: {
|
||||||
|
name: notDateStr,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([{ created: true }])
|
||||||
|
|
||||||
|
const rows = await rawQuery(
|
||||||
|
`SELECT * FROM test_table WHERE name = '${notDateStr}'`
|
||||||
|
)
|
||||||
|
expect(rows).toHaveLength(1)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("read", () => {
|
||||||
|
it("should execute a query", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "SELECT * FROM test_table ORDER BY id",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!)
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "one",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "two",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
name: "three",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: "four",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
name: "five",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to transform a query", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "SELECT * FROM test_table WHERE id = 1",
|
||||||
|
},
|
||||||
|
transformer: `
|
||||||
|
data[0].id = data[0].id + 1;
|
||||||
|
return data;
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!)
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "one",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should coerce numeric bindings", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "SELECT * FROM test_table WHERE id = {{ id }}",
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "id",
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: {
|
||||||
|
id: "1",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "one",
|
||||||
|
birthday: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
it("should be able to update rows", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "UPDATE test_table SET name = {{ name }} WHERE id = {{ id }}",
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "id",
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
default: "updated",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
queryVerb: "update",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: {
|
||||||
|
id: "1",
|
||||||
|
name: "foo",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
updated: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const rows = await rawQuery("SELECT * FROM test_table WHERE id = 1")
|
||||||
|
expect(rows).toEqual([{ id: 1, name: "foo", birthday: null }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to execute an update that updates no rows", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "UPDATE test_table SET name = 'updated' WHERE id = 100",
|
||||||
|
},
|
||||||
|
queryVerb: "update",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!)
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
updated: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to execute a delete that deletes no rows", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "DELETE FROM test_table WHERE id = 100",
|
||||||
|
},
|
||||||
|
queryVerb: "delete",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!)
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("delete", () => {
|
||||||
|
it("should be able to delete rows", async () => {
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
sql: "DELETE FROM test_table WHERE id = {{ id }}",
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "id",
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
queryVerb: "delete",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!, {
|
||||||
|
parameters: {
|
||||||
|
id: "1",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const rows = await rawQuery("SELECT * FROM test_table WHERE id = 1")
|
||||||
|
expect(rows).toHaveLength(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -1,239 +0,0 @@
|
||||||
import { Datasource, Query } from "@budibase/types"
|
|
||||||
import * as setup from "../utilities"
|
|
||||||
import { databaseTestProviders } from "../../../../integrations/tests/utils"
|
|
||||||
import mysql from "mysql2/promise"
|
|
||||||
|
|
||||||
jest.unmock("mysql2")
|
|
||||||
jest.unmock("mysql2/promise")
|
|
||||||
|
|
||||||
const createTableSQL = `
|
|
||||||
CREATE TABLE test_table (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
name VARCHAR(50) NOT NULL
|
|
||||||
)
|
|
||||||
`
|
|
||||||
|
|
||||||
const insertSQL = `
|
|
||||||
INSERT INTO test_table (name) VALUES ('one'), ('two'), ('three'), ('four'), ('five')
|
|
||||||
`
|
|
||||||
|
|
||||||
const dropTableSQL = `
|
|
||||||
DROP TABLE test_table
|
|
||||||
`
|
|
||||||
|
|
||||||
describe("/queries", () => {
|
|
||||||
let config = setup.getConfig()
|
|
||||||
let datasource: Datasource
|
|
||||||
|
|
||||||
async function createQuery(query: Partial<Query>): Promise<Query> {
|
|
||||||
const defaultQuery: Query = {
|
|
||||||
datasourceId: datasource._id!,
|
|
||||||
name: "New Query",
|
|
||||||
parameters: [],
|
|
||||||
fields: {},
|
|
||||||
schema: {},
|
|
||||||
queryVerb: "read",
|
|
||||||
transformer: "return data",
|
|
||||||
readable: true,
|
|
||||||
}
|
|
||||||
return await config.api.query.create({ ...defaultQuery, ...query })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withConnection(
|
|
||||||
callback: (client: mysql.Connection) => Promise<void>
|
|
||||||
): Promise<void> {
|
|
||||||
const ds = await databaseTestProviders.mysql.datasource()
|
|
||||||
const con = await mysql.createConnection(ds.config!)
|
|
||||||
try {
|
|
||||||
await callback(con)
|
|
||||||
} finally {
|
|
||||||
con.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await databaseTestProviders.mysql.stop()
|
|
||||||
setup.afterAll()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await config.init()
|
|
||||||
datasource = await config.api.datasource.create(
|
|
||||||
await databaseTestProviders.mysql.datasource()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await withConnection(async connection => {
|
|
||||||
const resp = await connection.query(createTableSQL)
|
|
||||||
await connection.query(insertSQL)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await withConnection(async connection => {
|
|
||||||
await connection.query(dropTableSQL)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should execute a query", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "SELECT * FROM test_table ORDER BY id",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!)
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "one",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "two",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: "three",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
name: "four",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
name: "five",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to transform a query", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "SELECT * FROM test_table WHERE id = 1",
|
|
||||||
},
|
|
||||||
transformer: `
|
|
||||||
data[0].id = data[0].id + 1;
|
|
||||||
return data;
|
|
||||||
`,
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!)
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "one",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to insert with bindings", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "INSERT INTO test_table (name) VALUES ({{ foo }})",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "foo",
|
|
||||||
default: "bar",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "create",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
foo: "baz",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
created: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withConnection(async connection => {
|
|
||||||
const [rows] = await connection.query(
|
|
||||||
"SELECT * FROM test_table WHERE name = 'baz'"
|
|
||||||
)
|
|
||||||
expect(rows).toHaveLength(1)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to update rows", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "UPDATE test_table SET name = {{ name }} WHERE id = {{ id }}",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "id",
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "name",
|
|
||||||
default: "updated",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "update",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
id: "1",
|
|
||||||
name: "foo",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
updated: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withConnection(async connection => {
|
|
||||||
const [rows] = await connection.query(
|
|
||||||
"SELECT * FROM test_table WHERE id = 1"
|
|
||||||
)
|
|
||||||
expect(rows).toEqual([{ id: 1, name: "foo" }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to delete rows", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "DELETE FROM test_table WHERE id = {{ id }}",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "id",
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "delete",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
id: "1",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withConnection(async connection => {
|
|
||||||
const [rows] = await connection.query(
|
|
||||||
"SELECT * FROM test_table WHERE id = 1"
|
|
||||||
)
|
|
||||||
expect(rows).toHaveLength(0)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -1,243 +0,0 @@
|
||||||
import { Datasource, Query } from "@budibase/types"
|
|
||||||
import * as setup from "../utilities"
|
|
||||||
import { databaseTestProviders } from "../../../../integrations/tests/utils"
|
|
||||||
import { Client } from "pg"
|
|
||||||
|
|
||||||
jest.unmock("pg")
|
|
||||||
|
|
||||||
const createTableSQL = `
|
|
||||||
CREATE TABLE test_table (
|
|
||||||
id serial PRIMARY KEY,
|
|
||||||
name VARCHAR ( 50 ) NOT NULL
|
|
||||||
);
|
|
||||||
`
|
|
||||||
|
|
||||||
const insertSQL = `
|
|
||||||
INSERT INTO test_table (name) VALUES ('one');
|
|
||||||
INSERT INTO test_table (name) VALUES ('two');
|
|
||||||
INSERT INTO test_table (name) VALUES ('three');
|
|
||||||
INSERT INTO test_table (name) VALUES ('four');
|
|
||||||
INSERT INTO test_table (name) VALUES ('five');
|
|
||||||
`
|
|
||||||
|
|
||||||
const dropTableSQL = `
|
|
||||||
DROP TABLE test_table;
|
|
||||||
`
|
|
||||||
|
|
||||||
describe("/queries", () => {
|
|
||||||
let config = setup.getConfig()
|
|
||||||
let datasource: Datasource
|
|
||||||
|
|
||||||
async function createQuery(query: Partial<Query>): Promise<Query> {
|
|
||||||
const defaultQuery: Query = {
|
|
||||||
datasourceId: datasource._id!,
|
|
||||||
name: "New Query",
|
|
||||||
parameters: [],
|
|
||||||
fields: {},
|
|
||||||
schema: {},
|
|
||||||
queryVerb: "read",
|
|
||||||
transformer: "return data",
|
|
||||||
readable: true,
|
|
||||||
}
|
|
||||||
return await config.api.query.create({ ...defaultQuery, ...query })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withClient(
|
|
||||||
callback: (client: Client) => Promise<void>
|
|
||||||
): Promise<void> {
|
|
||||||
const ds = await databaseTestProviders.postgres.datasource()
|
|
||||||
const client = new Client(ds.config!)
|
|
||||||
await client.connect()
|
|
||||||
try {
|
|
||||||
await callback(client)
|
|
||||||
} finally {
|
|
||||||
await client.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await databaseTestProviders.postgres.stop()
|
|
||||||
setup.afterAll()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await config.init()
|
|
||||||
datasource = await config.api.datasource.create(
|
|
||||||
await databaseTestProviders.postgres.datasource()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await withClient(async client => {
|
|
||||||
await client.query(createTableSQL)
|
|
||||||
await client.query(insertSQL)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await withClient(async client => {
|
|
||||||
await client.query(dropTableSQL)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should execute a query", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "SELECT * FROM test_table ORDER BY id",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!)
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "one",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "two",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: "three",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
name: "four",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
name: "five",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to transform a query", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "SELECT * FROM test_table WHERE id = 1",
|
|
||||||
},
|
|
||||||
transformer: `
|
|
||||||
data[0].id = data[0].id + 1;
|
|
||||||
return data;
|
|
||||||
`,
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!)
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "one",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to insert with bindings", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "INSERT INTO test_table (name) VALUES ({{ foo }})",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "foo",
|
|
||||||
default: "bar",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "create",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
foo: "baz",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
created: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withClient(async client => {
|
|
||||||
const { rows } = await client.query(
|
|
||||||
"SELECT * FROM test_table WHERE name = 'baz'"
|
|
||||||
)
|
|
||||||
expect(rows).toHaveLength(1)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to update rows", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "UPDATE test_table SET name = {{ name }} WHERE id = {{ id }}",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "id",
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "name",
|
|
||||||
default: "updated",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "update",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
id: "1",
|
|
||||||
name: "foo",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
updated: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withClient(async client => {
|
|
||||||
const { rows } = await client.query(
|
|
||||||
"SELECT * FROM test_table WHERE id = 1"
|
|
||||||
)
|
|
||||||
expect(rows).toEqual([{ id: 1, name: "foo" }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to delete rows", async () => {
|
|
||||||
const query = await createQuery({
|
|
||||||
fields: {
|
|
||||||
sql: "DELETE FROM test_table WHERE id = {{ id }}",
|
|
||||||
},
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
name: "id",
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryVerb: "delete",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await config.api.query.execute(query._id!, {
|
|
||||||
parameters: {
|
|
||||||
id: "1",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.data).toEqual([
|
|
||||||
{
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await withClient(async client => {
|
|
||||||
const { rows } = await client.query(
|
|
||||||
"SELECT * FROM test_table WHERE id = 1"
|
|
||||||
)
|
|
||||||
expect(rows).toHaveLength(0)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -3,7 +3,7 @@ import { databaseTestProviders } from "../../../integrations/tests/utils"
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
import { outputProcessing } from "../../../utilities/rowProcessor"
|
import { outputProcessing } from "../../../utilities/rowProcessor"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { context, InternalTable, roles, tenancy } from "@budibase/backend-core"
|
import { context, InternalTable, tenancy } from "@budibase/backend-core"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
|
@ -14,33 +14,21 @@ import {
|
||||||
FieldTypeSubtypes,
|
FieldTypeSubtypes,
|
||||||
FormulaType,
|
FormulaType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
PermissionLevel,
|
|
||||||
QuotaUsageType,
|
QuotaUsageType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
Row,
|
Row,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SearchQueryOperators,
|
|
||||||
SortOrder,
|
|
||||||
SortType,
|
|
||||||
StaticQuotaName,
|
StaticQuotaName,
|
||||||
Table,
|
Table,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
ViewV2,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
expectAnyExternalColsAttributes,
|
|
||||||
expectAnyInternalColsAttributes,
|
|
||||||
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"
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
jest.unmock("mysql2")
|
|
||||||
jest.unmock("mysql2/promise")
|
|
||||||
jest.unmock("mssql")
|
jest.unmock("mssql")
|
||||||
jest.unmock("pg")
|
jest.unmock("pg")
|
||||||
|
|
||||||
|
@ -392,6 +380,23 @@ describe.each([
|
||||||
expect(row.arrayFieldArrayStrKnown).toEqual(["One"])
|
expect(row.arrayFieldArrayStrKnown).toEqual(["One"])
|
||||||
expect(row.optsFieldStrKnown).toEqual("Alpha")
|
expect(row.optsFieldStrKnown).toEqual("Alpha")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
isInternal &&
|
||||||
|
it("doesn't allow creating in user table", async () => {
|
||||||
|
const userTableId = InternalTable.USER_METADATA
|
||||||
|
const response = await config.api.row.save(
|
||||||
|
userTableId,
|
||||||
|
{
|
||||||
|
tableId: userTableId,
|
||||||
|
firstName: "Joe",
|
||||||
|
lastName: "Joe",
|
||||||
|
email: "joe@joe.com",
|
||||||
|
roles: {},
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
expect(response.message).toBe("Cannot create new user entry.")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("get", () => {
|
describe("get", () => {
|
||||||
|
@ -890,642 +895,6 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("view 2.0", () => {
|
|
||||||
async function userTable(): Promise<Table> {
|
|
||||||
return saveTableRequest({
|
|
||||||
name: `users_${uuid.v4()}`,
|
|
||||||
type: "table",
|
|
||||||
schema: {
|
|
||||||
name: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "name",
|
|
||||||
},
|
|
||||||
surname: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "surname",
|
|
||||||
},
|
|
||||||
age: {
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
name: "age",
|
|
||||||
},
|
|
||||||
address: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "address",
|
|
||||||
},
|
|
||||||
jobTitle: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "jobTitle",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const randomRowData = () => ({
|
|
||||||
name: generator.first(),
|
|
||||||
surname: generator.last(),
|
|
||||||
age: generator.age(),
|
|
||||||
address: generator.address(),
|
|
||||||
jobTitle: generator.word(),
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("create", () => {
|
|
||||||
it("should persist a new row with only the provided view fields", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: {
|
|
||||||
name: { visible: true },
|
|
||||||
surname: { visible: true },
|
|
||||||
address: { visible: true },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = randomRowData()
|
|
||||||
const newRow = await config.api.row.save(view.id, {
|
|
||||||
tableId: table!._id,
|
|
||||||
_viewId: view.id,
|
|
||||||
...data,
|
|
||||||
})
|
|
||||||
|
|
||||||
const row = await config.api.row.get(table._id!, newRow._id!)
|
|
||||||
expect(row).toEqual({
|
|
||||||
name: data.name,
|
|
||||||
surname: data.surname,
|
|
||||||
address: data.address,
|
|
||||||
tableId: table!._id,
|
|
||||||
_id: newRow._id,
|
|
||||||
_rev: newRow._rev,
|
|
||||||
id: newRow.id,
|
|
||||||
...defaultRowFields,
|
|
||||||
})
|
|
||||||
expect(row._viewId).toBeUndefined()
|
|
||||||
expect(row.age).toBeUndefined()
|
|
||||||
expect(row.jobTitle).toBeUndefined()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("patch", () => {
|
|
||||||
it("should update only the view fields for a row", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const tableId = table._id!
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: tableId,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: {
|
|
||||||
name: { visible: true },
|
|
||||||
address: { visible: true },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const newRow = await config.api.row.save(view.id, {
|
|
||||||
tableId,
|
|
||||||
_viewId: view.id,
|
|
||||||
...randomRowData(),
|
|
||||||
})
|
|
||||||
const newData = randomRowData()
|
|
||||||
await config.api.row.patch(view.id, {
|
|
||||||
tableId,
|
|
||||||
_viewId: view.id,
|
|
||||||
_id: newRow._id!,
|
|
||||||
_rev: newRow._rev!,
|
|
||||||
...newData,
|
|
||||||
})
|
|
||||||
|
|
||||||
const row = await config.api.row.get(tableId, newRow._id!)
|
|
||||||
expect(row).toEqual({
|
|
||||||
...newRow,
|
|
||||||
name: newData.name,
|
|
||||||
address: newData.address,
|
|
||||||
_id: newRow._id,
|
|
||||||
_rev: expect.any(String),
|
|
||||||
id: newRow.id,
|
|
||||||
...defaultRowFields,
|
|
||||||
})
|
|
||||||
expect(row._viewId).toBeUndefined()
|
|
||||||
expect(row.age).toBeUndefined()
|
|
||||||
expect(row.jobTitle).toBeUndefined()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("destroy", () => {
|
|
||||||
it("should be able to delete a row", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const tableId = table._id!
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: tableId,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: {
|
|
||||||
name: { visible: true },
|
|
||||||
address: { visible: true },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const createdRow = await config.api.row.save(table._id!, {})
|
|
||||||
const rowUsage = await getRowUsage()
|
|
||||||
|
|
||||||
await config.api.row.bulkDelete(view.id, { rows: [createdRow] })
|
|
||||||
|
|
||||||
await assertRowUsage(rowUsage - 1)
|
|
||||||
|
|
||||||
await config.api.row.get(tableId, createdRow._id!, {
|
|
||||||
status: 404,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should be able to delete multiple rows", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const tableId = table._id!
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: tableId,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: {
|
|
||||||
name: { visible: true },
|
|
||||||
address: { visible: true },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const rows = await Promise.all([
|
|
||||||
config.api.row.save(table._id!, {}),
|
|
||||||
config.api.row.save(table._id!, {}),
|
|
||||||
config.api.row.save(table._id!, {}),
|
|
||||||
])
|
|
||||||
const rowUsage = await getRowUsage()
|
|
||||||
|
|
||||||
await config.api.row.bulkDelete(view.id, { rows: [rows[0], rows[2]] })
|
|
||||||
|
|
||||||
await assertRowUsage(rowUsage - 2)
|
|
||||||
|
|
||||||
await config.api.row.get(tableId, rows[0]._id!, {
|
|
||||||
status: 404,
|
|
||||||
})
|
|
||||||
await config.api.row.get(tableId, rows[2]._id!, {
|
|
||||||
status: 404,
|
|
||||||
})
|
|
||||||
await config.api.row.get(tableId, rows[1]._id!, { status: 200 })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("view search", () => {
|
|
||||||
let table: Table
|
|
||||||
const viewSchema = { age: { visible: true }, name: { visible: true } }
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
table = await config.api.table.save(
|
|
||||||
saveTableRequest({
|
|
||||||
name: `users_${uuid.v4()}`,
|
|
||||||
schema: {
|
|
||||||
name: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "name",
|
|
||||||
constraints: { type: "string" },
|
|
||||||
},
|
|
||||||
age: {
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
name: "age",
|
|
||||||
constraints: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns empty rows from view when no schema is passed", async () => {
|
|
||||||
const rows = await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () =>
|
|
||||||
config.api.row.save(table._id!, { tableId: table._id })
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
})
|
|
||||||
const response = await config.api.viewV2.search(createViewResponse.id)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(10)
|
|
||||||
expect(response).toEqual({
|
|
||||||
rows: expect.arrayContaining(
|
|
||||||
rows.map(r => ({
|
|
||||||
_viewId: createViewResponse.id,
|
|
||||||
tableId: table._id,
|
|
||||||
_id: r._id,
|
|
||||||
_rev: r._rev,
|
|
||||||
...defaultRowFields,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
...(isInternal
|
|
||||||
? {}
|
|
||||||
: {
|
|
||||||
hasNextPage: false,
|
|
||||||
bookmark: null,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("searching respects the view filters", async () => {
|
|
||||||
await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () =>
|
|
||||||
config.api.row.save(table._id!, {
|
|
||||||
tableId: table._id,
|
|
||||||
name: generator.name(),
|
|
||||||
age: generator.integer({ min: 10, max: 30 }),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
const expectedRows = await Promise.all(
|
|
||||||
Array.from({ length: 5 }, () =>
|
|
||||||
config.api.row.save(table._id!, {
|
|
||||||
tableId: table._id,
|
|
||||||
name: generator.name(),
|
|
||||||
age: 40,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
query: [
|
|
||||||
{ operator: SearchQueryOperators.EQUAL, field: "age", value: 40 },
|
|
||||||
],
|
|
||||||
schema: viewSchema,
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await config.api.viewV2.search(createViewResponse.id)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(5)
|
|
||||||
expect(response).toEqual({
|
|
||||||
rows: expect.arrayContaining(
|
|
||||||
expectedRows.map(r => ({
|
|
||||||
_viewId: createViewResponse.id,
|
|
||||||
tableId: table._id,
|
|
||||||
name: r.name,
|
|
||||||
age: r.age,
|
|
||||||
_id: r._id,
|
|
||||||
_rev: r._rev,
|
|
||||||
...defaultRowFields,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
...(isInternal
|
|
||||||
? {}
|
|
||||||
: {
|
|
||||||
hasNextPage: false,
|
|
||||||
bookmark: null,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const sortTestOptions: [
|
|
||||||
{
|
|
||||||
field: string
|
|
||||||
order?: SortOrder
|
|
||||||
type?: SortType
|
|
||||||
},
|
|
||||||
string[]
|
|
||||||
][] = [
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "name",
|
|
||||||
order: SortOrder.ASCENDING,
|
|
||||||
type: SortType.STRING,
|
|
||||||
},
|
|
||||||
["Alice", "Bob", "Charly", "Danny"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "name",
|
|
||||||
},
|
|
||||||
["Alice", "Bob", "Charly", "Danny"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "name",
|
|
||||||
order: SortOrder.DESCENDING,
|
|
||||||
},
|
|
||||||
["Danny", "Charly", "Bob", "Alice"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "name",
|
|
||||||
order: SortOrder.DESCENDING,
|
|
||||||
type: SortType.STRING,
|
|
||||||
},
|
|
||||||
["Danny", "Charly", "Bob", "Alice"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "age",
|
|
||||||
order: SortOrder.ASCENDING,
|
|
||||||
type: SortType.number,
|
|
||||||
},
|
|
||||||
["Danny", "Alice", "Charly", "Bob"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "age",
|
|
||||||
order: SortOrder.ASCENDING,
|
|
||||||
},
|
|
||||||
["Danny", "Alice", "Charly", "Bob"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "age",
|
|
||||||
order: SortOrder.DESCENDING,
|
|
||||||
},
|
|
||||||
["Bob", "Charly", "Alice", "Danny"],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
field: "age",
|
|
||||||
order: SortOrder.DESCENDING,
|
|
||||||
type: SortType.number,
|
|
||||||
},
|
|
||||||
["Bob", "Charly", "Alice", "Danny"],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
describe("sorting", () => {
|
|
||||||
let table: Table
|
|
||||||
beforeAll(async () => {
|
|
||||||
table = await config.api.table.save(await userTable())
|
|
||||||
const users = [
|
|
||||||
{ name: "Alice", age: 25 },
|
|
||||||
{ name: "Bob", age: 30 },
|
|
||||||
{ name: "Charly", age: 27 },
|
|
||||||
{ name: "Danny", age: 15 },
|
|
||||||
]
|
|
||||||
await Promise.all(
|
|
||||||
users.map(u =>
|
|
||||||
config.api.row.save(table._id!, {
|
|
||||||
tableId: table._id,
|
|
||||||
...u,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it.each(sortTestOptions)(
|
|
||||||
"allow sorting (%s)",
|
|
||||||
async (sortParams, expected) => {
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
sort: sortParams,
|
|
||||||
schema: viewSchema,
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await config.api.viewV2.search(
|
|
||||||
createViewResponse.id
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(4)
|
|
||||||
expect(response.rows).toEqual(
|
|
||||||
expected.map(name => expect.objectContaining({ name }))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
it.each(sortTestOptions)(
|
|
||||||
"allow override the default view sorting (%s)",
|
|
||||||
async (sortParams, expected) => {
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
sort: {
|
|
||||||
field: "name",
|
|
||||||
order: SortOrder.ASCENDING,
|
|
||||||
type: SortType.STRING,
|
|
||||||
},
|
|
||||||
schema: viewSchema,
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await config.api.viewV2.search(
|
|
||||||
createViewResponse.id,
|
|
||||||
{
|
|
||||||
sort: sortParams.field,
|
|
||||||
sortOrder: sortParams.order,
|
|
||||||
sortType: sortParams.type,
|
|
||||||
query: {},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(4)
|
|
||||||
expect(response.rows).toEqual(
|
|
||||||
expected.map(name => expect.objectContaining({ name }))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("when schema is defined, defined columns and row attributes are returned", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const rows = await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () =>
|
|
||||||
config.api.row.save(table._id!, {
|
|
||||||
tableId: table._id,
|
|
||||||
name: generator.name(),
|
|
||||||
age: generator.age(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: { name: { visible: true } },
|
|
||||||
})
|
|
||||||
const response = await config.api.viewV2.search(view.id)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(10)
|
|
||||||
expect(response.rows).toEqual(
|
|
||||||
expect.arrayContaining(
|
|
||||||
rows.map(r => ({
|
|
||||||
...(isInternal
|
|
||||||
? expectAnyInternalColsAttributes
|
|
||||||
: expectAnyExternalColsAttributes),
|
|
||||||
_viewId: view.id,
|
|
||||||
name: r.name,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("views without data can be returned", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
})
|
|
||||||
const response = await config.api.viewV2.search(createViewResponse.id)
|
|
||||||
expect(response.rows).toHaveLength(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("respects the limit parameter", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
|
||||||
)
|
|
||||||
|
|
||||||
const limit = generator.integer({ min: 1, max: 8 })
|
|
||||||
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
})
|
|
||||||
const response = await config.api.viewV2.search(createViewResponse.id, {
|
|
||||||
limit,
|
|
||||||
query: {},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(limit)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("can handle pagination", async () => {
|
|
||||||
const table = await config.api.table.save(await userTable())
|
|
||||||
await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
|
||||||
)
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
})
|
|
||||||
const rows = (await config.api.viewV2.search(view.id)).rows
|
|
||||||
|
|
||||||
const page1 = await config.api.viewV2.search(view.id, {
|
|
||||||
paginate: true,
|
|
||||||
limit: 4,
|
|
||||||
query: {},
|
|
||||||
})
|
|
||||||
expect(page1).toEqual({
|
|
||||||
rows: expect.arrayContaining(rows.slice(0, 4)),
|
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: true,
|
|
||||||
bookmark: expect.anything(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const page2 = await config.api.viewV2.search(view.id, {
|
|
||||||
paginate: true,
|
|
||||||
limit: 4,
|
|
||||||
bookmark: page1.bookmark,
|
|
||||||
|
|
||||||
query: {},
|
|
||||||
})
|
|
||||||
expect(page2).toEqual({
|
|
||||||
rows: expect.arrayContaining(rows.slice(4, 8)),
|
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: true,
|
|
||||||
bookmark: expect.anything(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const page3 = await config.api.viewV2.search(view.id, {
|
|
||||||
paginate: true,
|
|
||||||
limit: 4,
|
|
||||||
bookmark: page2.bookmark,
|
|
||||||
query: {},
|
|
||||||
})
|
|
||||||
expect(page3).toEqual({
|
|
||||||
rows: expect.arrayContaining(rows.slice(8)),
|
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: false,
|
|
||||||
bookmark: expect.anything(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
isInternal &&
|
|
||||||
it("doesn't allow creating in user table", async () => {
|
|
||||||
const userTableId = InternalTable.USER_METADATA
|
|
||||||
const response = await config.api.row.save(
|
|
||||||
userTableId,
|
|
||||||
{
|
|
||||||
tableId: userTableId,
|
|
||||||
firstName: "Joe",
|
|
||||||
lastName: "Joe",
|
|
||||||
email: "joe@joe.com",
|
|
||||||
roles: {},
|
|
||||||
},
|
|
||||||
{ status: 400 }
|
|
||||||
)
|
|
||||||
expect(response.message).toBe("Cannot create new user entry.")
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("permissions", () => {
|
|
||||||
let table: Table
|
|
||||||
let view: ViewV2
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
table = await config.api.table.save(await userTable())
|
|
||||||
await Promise.all(
|
|
||||||
Array.from({ length: 10 }, () =>
|
|
||||||
config.api.row.save(table._id!, {})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
view = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
mocks.licenses.useViewPermissions()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("does not allow public users to fetch by default", async () => {
|
|
||||||
await config.publish()
|
|
||||||
await config.api.viewV2.publicSearch(view.id, undefined, {
|
|
||||||
status: 403,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("allow public users to fetch when permissions are explicit", async () => {
|
|
||||||
await config.api.permission.add({
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
|
||||||
level: PermissionLevel.READ,
|
|
||||||
resourceId: view.id,
|
|
||||||
})
|
|
||||||
await config.publish()
|
|
||||||
|
|
||||||
const response = await config.api.viewV2.publicSearch(view.id)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(10)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("allow public users to fetch when permissions are inherited", async () => {
|
|
||||||
await config.api.permission.add({
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
|
||||||
level: PermissionLevel.READ,
|
|
||||||
resourceId: table._id!,
|
|
||||||
})
|
|
||||||
await config.publish()
|
|
||||||
|
|
||||||
const response = await config.api.viewV2.publicSearch(view.id)
|
|
||||||
|
|
||||||
expect(response.rows).toHaveLength(10)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("respects inherited permissions, not allowing not public views from public tables", async () => {
|
|
||||||
await config.api.permission.add({
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
|
||||||
level: PermissionLevel.READ,
|
|
||||||
resourceId: table._id!,
|
|
||||||
})
|
|
||||||
await config.api.permission.add({
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.POWER,
|
|
||||||
level: PermissionLevel.READ,
|
|
||||||
resourceId: view.id,
|
|
||||||
})
|
|
||||||
await config.publish()
|
|
||||||
|
|
||||||
await config.api.viewV2.publicSearch(view.id, undefined, {
|
|
||||||
status: 403,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
let o2mTable: Table
|
let o2mTable: Table
|
||||||
let m2mTable: Table
|
let m2mTable: Table
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe("/views", () => {
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("returns a success message when the view is successfully created", async () => {
|
it("returns a success message when the view is successfully created", async () => {
|
||||||
const res = await saveView()
|
await saveView()
|
||||||
expect(events.view.created).toHaveBeenCalledTimes(1)
|
expect(events.view.created).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -5,23 +5,26 @@ import {
|
||||||
FieldSchema,
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
PermissionLevel,
|
||||||
|
QuotaUsageType,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SearchQueryOperators,
|
SearchQueryOperators,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
SortType,
|
SortType,
|
||||||
|
StaticQuotaName,
|
||||||
Table,
|
Table,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
UIFieldMetadata,
|
UIFieldMetadata,
|
||||||
UpdateViewRequest,
|
UpdateViewRequest,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import * as uuid from "uuid"
|
import * as uuid from "uuid"
|
||||||
import { databaseTestProviders } from "../../../integrations/tests/utils"
|
import { databaseTestProviders } from "../../../integrations/tests/utils"
|
||||||
import merge from "lodash/merge"
|
import merge from "lodash/merge"
|
||||||
|
import { quotas } from "@budibase/pro"
|
||||||
|
import { roles } from "@budibase/backend-core"
|
||||||
|
|
||||||
jest.unmock("mysql2")
|
|
||||||
jest.unmock("mysql2/promise")
|
|
||||||
jest.unmock("mssql")
|
jest.unmock("mssql")
|
||||||
jest.unmock("pg")
|
jest.unmock("pg")
|
||||||
|
|
||||||
|
@ -33,6 +36,7 @@ describe.each([
|
||||||
["mariadb", databaseTestProviders.mariadb],
|
["mariadb", databaseTestProviders.mariadb],
|
||||||
])("/v2/views (%s)", (_, dsProvider) => {
|
])("/v2/views (%s)", (_, dsProvider) => {
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
|
const isInternal = !dsProvider
|
||||||
|
|
||||||
let table: Table
|
let table: Table
|
||||||
let datasource: Datasource
|
let datasource: Datasource
|
||||||
|
@ -99,6 +103,18 @@ describe.each([
|
||||||
setup.afterAll()
|
setup.afterAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getRowUsage = async () => {
|
||||||
|
const { total } = await config.doInContext(undefined, () =>
|
||||||
|
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
|
||||||
|
)
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
const assertRowUsage = async (expected: number) => {
|
||||||
|
const usage = await getRowUsage()
|
||||||
|
expect(usage).toBe(expected)
|
||||||
|
}
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("persist the view when the view is successfully created", async () => {
|
it("persist the view when the view is successfully created", async () => {
|
||||||
const newView: CreateViewRequest = {
|
const newView: CreateViewRequest = {
|
||||||
|
@ -525,4 +541,468 @@ describe.each([
|
||||||
expect(row.Country).toEqual("Aussy")
|
expect(row.Country).toEqual("Aussy")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("row operations", () => {
|
||||||
|
let table: Table, view: ViewV2
|
||||||
|
beforeEach(async () => {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
one: { type: FieldType.STRING, name: "one" },
|
||||||
|
two: { type: FieldType.STRING, name: "two" },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
view = await config.api.viewV2.create({
|
||||||
|
tableId: table._id!,
|
||||||
|
name: generator.guid(),
|
||||||
|
schema: {
|
||||||
|
two: { visible: true },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("create", () => {
|
||||||
|
it("should persist a new row with only the provided view fields", async () => {
|
||||||
|
const newRow = await config.api.row.save(view.id, {
|
||||||
|
tableId: table!._id,
|
||||||
|
_viewId: view.id,
|
||||||
|
one: "foo",
|
||||||
|
two: "bar",
|
||||||
|
})
|
||||||
|
|
||||||
|
const row = await config.api.row.get(table._id!, newRow._id!)
|
||||||
|
expect(row.one).toBeUndefined()
|
||||||
|
expect(row.two).toEqual("bar")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("patch", () => {
|
||||||
|
it("should update only the view fields for a row", async () => {
|
||||||
|
const newRow = await config.api.row.save(table._id!, {
|
||||||
|
one: "foo",
|
||||||
|
two: "bar",
|
||||||
|
})
|
||||||
|
await config.api.row.patch(view.id, {
|
||||||
|
tableId: table._id!,
|
||||||
|
_id: newRow._id!,
|
||||||
|
_rev: newRow._rev!,
|
||||||
|
one: "newFoo",
|
||||||
|
two: "newBar",
|
||||||
|
})
|
||||||
|
|
||||||
|
const row = await config.api.row.get(table._id!, newRow._id!)
|
||||||
|
expect(row.one).toEqual("foo")
|
||||||
|
expect(row.two).toEqual("newBar")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("destroy", () => {
|
||||||
|
it("should be able to delete a row", async () => {
|
||||||
|
const createdRow = await config.api.row.save(table._id!, {})
|
||||||
|
const rowUsage = await getRowUsage()
|
||||||
|
await config.api.row.bulkDelete(view.id, { rows: [createdRow] })
|
||||||
|
await assertRowUsage(rowUsage - 1)
|
||||||
|
await config.api.row.get(table._id!, createdRow._id!, {
|
||||||
|
status: 404,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to delete multiple rows", async () => {
|
||||||
|
const rows = await Promise.all([
|
||||||
|
config.api.row.save(table._id!, {}),
|
||||||
|
config.api.row.save(table._id!, {}),
|
||||||
|
config.api.row.save(table._id!, {}),
|
||||||
|
])
|
||||||
|
const rowUsage = await getRowUsage()
|
||||||
|
|
||||||
|
await config.api.row.bulkDelete(view.id, { rows: [rows[0], rows[2]] })
|
||||||
|
|
||||||
|
await assertRowUsage(rowUsage - 2)
|
||||||
|
|
||||||
|
await config.api.row.get(table._id!, rows[0]._id!, {
|
||||||
|
status: 404,
|
||||||
|
})
|
||||||
|
await config.api.row.get(table._id!, rows[2]._id!, {
|
||||||
|
status: 404,
|
||||||
|
})
|
||||||
|
await config.api.row.get(table._id!, rows[1]._id!, { status: 200 })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("search", () => {
|
||||||
|
it("returns empty rows from view when no schema is passed", async () => {
|
||||||
|
const rows = await Promise.all(
|
||||||
|
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
||||||
|
)
|
||||||
|
const response = await config.api.viewV2.search(view.id)
|
||||||
|
expect(response.rows).toHaveLength(10)
|
||||||
|
expect(response).toEqual({
|
||||||
|
rows: expect.arrayContaining(
|
||||||
|
rows.map(r => ({
|
||||||
|
_viewId: view.id,
|
||||||
|
tableId: table._id,
|
||||||
|
_id: r._id,
|
||||||
|
_rev: r._rev,
|
||||||
|
...(isInternal
|
||||||
|
? {
|
||||||
|
type: "row",
|
||||||
|
updatedAt: expect.any(String),
|
||||||
|
createdAt: expect.any(String),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
...(isInternal
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
hasNextPage: false,
|
||||||
|
bookmark: null,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("searching respects the view filters", async () => {
|
||||||
|
await config.api.row.save(table._id!, {
|
||||||
|
one: "foo",
|
||||||
|
two: "bar",
|
||||||
|
})
|
||||||
|
const two = await config.api.row.save(table._id!, {
|
||||||
|
one: "foo2",
|
||||||
|
two: "bar2",
|
||||||
|
})
|
||||||
|
|
||||||
|
const view = await config.api.viewV2.create({
|
||||||
|
tableId: table._id!,
|
||||||
|
name: generator.guid(),
|
||||||
|
query: [
|
||||||
|
{
|
||||||
|
operator: SearchQueryOperators.EQUAL,
|
||||||
|
field: "two",
|
||||||
|
value: "bar2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
schema: {
|
||||||
|
two: { visible: true },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await config.api.viewV2.search(view.id)
|
||||||
|
expect(response.rows).toHaveLength(1)
|
||||||
|
expect(response).toEqual({
|
||||||
|
rows: expect.arrayContaining([
|
||||||
|
{
|
||||||
|
_viewId: view.id,
|
||||||
|
tableId: table._id,
|
||||||
|
two: two.two,
|
||||||
|
_id: two._id,
|
||||||
|
_rev: two._rev,
|
||||||
|
...(isInternal
|
||||||
|
? {
|
||||||
|
type: "row",
|
||||||
|
createdAt: expect.any(String),
|
||||||
|
updatedAt: expect.any(String),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
...(isInternal
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
hasNextPage: false,
|
||||||
|
bookmark: null,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("views without data can be returned", async () => {
|
||||||
|
const response = await config.api.viewV2.search(view.id)
|
||||||
|
expect(response.rows).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("respects the limit parameter", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
||||||
|
)
|
||||||
|
const limit = generator.integer({ min: 1, max: 8 })
|
||||||
|
const response = await config.api.viewV2.search(view.id, {
|
||||||
|
limit,
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
expect(response.rows).toHaveLength(limit)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can handle pagination", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
||||||
|
)
|
||||||
|
const rows = (await config.api.viewV2.search(view.id)).rows
|
||||||
|
|
||||||
|
const page1 = await config.api.viewV2.search(view.id, {
|
||||||
|
paginate: true,
|
||||||
|
limit: 4,
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
expect(page1).toEqual({
|
||||||
|
rows: expect.arrayContaining(rows.slice(0, 4)),
|
||||||
|
totalRows: isInternal ? 10 : undefined,
|
||||||
|
hasNextPage: true,
|
||||||
|
bookmark: expect.anything(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const page2 = await config.api.viewV2.search(view.id, {
|
||||||
|
paginate: true,
|
||||||
|
limit: 4,
|
||||||
|
bookmark: page1.bookmark,
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
expect(page2).toEqual({
|
||||||
|
rows: expect.arrayContaining(rows.slice(4, 8)),
|
||||||
|
totalRows: isInternal ? 10 : undefined,
|
||||||
|
hasNextPage: true,
|
||||||
|
bookmark: expect.anything(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const page3 = await config.api.viewV2.search(view.id, {
|
||||||
|
paginate: true,
|
||||||
|
limit: 4,
|
||||||
|
bookmark: page2.bookmark,
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
expect(page3).toEqual({
|
||||||
|
rows: expect.arrayContaining(rows.slice(8)),
|
||||||
|
totalRows: isInternal ? 10 : undefined,
|
||||||
|
hasNextPage: false,
|
||||||
|
bookmark: expect.anything(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const sortTestOptions: [
|
||||||
|
{
|
||||||
|
field: string
|
||||||
|
order?: SortOrder
|
||||||
|
type?: SortType
|
||||||
|
},
|
||||||
|
string[]
|
||||||
|
][] = [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "name",
|
||||||
|
order: SortOrder.ASCENDING,
|
||||||
|
type: SortType.STRING,
|
||||||
|
},
|
||||||
|
["Alice", "Bob", "Charly", "Danny"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "name",
|
||||||
|
},
|
||||||
|
["Alice", "Bob", "Charly", "Danny"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "name",
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
},
|
||||||
|
["Danny", "Charly", "Bob", "Alice"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "name",
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
type: SortType.STRING,
|
||||||
|
},
|
||||||
|
["Danny", "Charly", "Bob", "Alice"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "age",
|
||||||
|
order: SortOrder.ASCENDING,
|
||||||
|
type: SortType.number,
|
||||||
|
},
|
||||||
|
["Danny", "Alice", "Charly", "Bob"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "age",
|
||||||
|
order: SortOrder.ASCENDING,
|
||||||
|
},
|
||||||
|
["Danny", "Alice", "Charly", "Bob"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "age",
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
},
|
||||||
|
["Bob", "Charly", "Alice", "Danny"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
field: "age",
|
||||||
|
order: SortOrder.DESCENDING,
|
||||||
|
type: SortType.number,
|
||||||
|
},
|
||||||
|
["Bob", "Charly", "Alice", "Danny"],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
describe("sorting", () => {
|
||||||
|
let table: Table
|
||||||
|
const viewSchema = { age: { visible: true }, name: { visible: true } }
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
name: `users_${uuid.v4()}`,
|
||||||
|
type: "table",
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "name",
|
||||||
|
},
|
||||||
|
surname: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "surname",
|
||||||
|
},
|
||||||
|
age: {
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
name: "age",
|
||||||
|
},
|
||||||
|
address: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "address",
|
||||||
|
},
|
||||||
|
jobTitle: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "jobTitle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const users = [
|
||||||
|
{ name: "Alice", age: 25 },
|
||||||
|
{ name: "Bob", age: 30 },
|
||||||
|
{ name: "Charly", age: 27 },
|
||||||
|
{ name: "Danny", age: 15 },
|
||||||
|
]
|
||||||
|
await Promise.all(
|
||||||
|
users.map(u =>
|
||||||
|
config.api.row.save(table._id!, {
|
||||||
|
tableId: table._id,
|
||||||
|
...u,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it.each(sortTestOptions)(
|
||||||
|
"allow sorting (%s)",
|
||||||
|
async (sortParams, expected) => {
|
||||||
|
const view = await config.api.viewV2.create({
|
||||||
|
tableId: table._id!,
|
||||||
|
name: generator.guid(),
|
||||||
|
sort: sortParams,
|
||||||
|
schema: viewSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await config.api.viewV2.search(view.id)
|
||||||
|
|
||||||
|
expect(response.rows).toHaveLength(4)
|
||||||
|
expect(response.rows).toEqual(
|
||||||
|
expected.map(name => expect.objectContaining({ name }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
it.each(sortTestOptions)(
|
||||||
|
"allow override the default view sorting (%s)",
|
||||||
|
async (sortParams, expected) => {
|
||||||
|
const view = await config.api.viewV2.create({
|
||||||
|
tableId: table._id!,
|
||||||
|
name: generator.guid(),
|
||||||
|
sort: {
|
||||||
|
field: "name",
|
||||||
|
order: SortOrder.ASCENDING,
|
||||||
|
type: SortType.STRING,
|
||||||
|
},
|
||||||
|
schema: viewSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await config.api.viewV2.search(view.id, {
|
||||||
|
sort: sortParams.field,
|
||||||
|
sortOrder: sortParams.order,
|
||||||
|
sortType: sortParams.type,
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.rows).toHaveLength(4)
|
||||||
|
expect(response.rows).toEqual(
|
||||||
|
expected.map(name => expect.objectContaining({ name }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("permissions", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
mocks.licenses.useViewPermissions()
|
||||||
|
await Promise.all(
|
||||||
|
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does not allow public users to fetch by default", async () => {
|
||||||
|
await config.publish()
|
||||||
|
await config.api.viewV2.publicSearch(view.id, undefined, {
|
||||||
|
status: 403,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("allow public users to fetch when permissions are explicit", async () => {
|
||||||
|
await config.api.permission.add({
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
resourceId: view.id,
|
||||||
|
})
|
||||||
|
await config.publish()
|
||||||
|
|
||||||
|
const response = await config.api.viewV2.publicSearch(view.id)
|
||||||
|
|
||||||
|
expect(response.rows).toHaveLength(10)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("allow public users to fetch when permissions are inherited", async () => {
|
||||||
|
await config.api.permission.add({
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
resourceId: table._id!,
|
||||||
|
})
|
||||||
|
await config.publish()
|
||||||
|
|
||||||
|
const response = await config.api.viewV2.publicSearch(view.id)
|
||||||
|
|
||||||
|
expect(response.rows).toHaveLength(10)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("respects inherited permissions, not allowing not public views from public tables", async () => {
|
||||||
|
await config.api.permission.add({
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.PUBLIC,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
resourceId: table._id!,
|
||||||
|
})
|
||||||
|
await config.api.permission.add({
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.POWER,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
resourceId: view.id,
|
||||||
|
})
|
||||||
|
await config.publish()
|
||||||
|
|
||||||
|
await config.api.viewV2.publicSearch(view.id, undefined, {
|
||||||
|
status: 403,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
import sdk from "../sdk"
|
import sdk from "../sdk"
|
||||||
import { Row } from "@budibase/types"
|
import { Row } from "@budibase/types"
|
||||||
import { LoopInput, LoopStep, LoopStepType } from "../definitions/automations"
|
import { LoopInput, LoopStepType } from "../definitions/automations"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When values are input to the system generally they will be of type string as this is required for template strings.
|
* When values are input to the system generally they will be of type string as this is required for template strings.
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
AutomationStepInput,
|
AutomationStepInput,
|
||||||
AutomationStepType,
|
AutomationStepType,
|
||||||
AutomationIOType,
|
AutomationIOType,
|
||||||
AutomationFeature,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
export const definition: AutomationStepSchema = {
|
export const definition: AutomationStepSchema = {
|
||||||
|
|
|
@ -10,8 +10,6 @@ import {
|
||||||
AutomationStepSchema,
|
AutomationStepSchema,
|
||||||
AutomationStepType,
|
AutomationStepType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { utils } from "@budibase/backend-core"
|
|
||||||
import env from "../../environment"
|
|
||||||
|
|
||||||
export const definition: AutomationStepSchema = {
|
export const definition: AutomationStepSchema = {
|
||||||
name: "External Data Connector",
|
name: "External Data Connector",
|
||||||
|
|
|
@ -58,7 +58,7 @@ export const definition: AutomationStepSchema = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run({ inputs, context }: AutomationStepInput) {
|
export async function run({ inputs }: AutomationStepInput) {
|
||||||
if (!environment.OPENAI_API_KEY) {
|
if (!environment.OPENAI_API_KEY) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|
|
@ -62,6 +62,7 @@ export const definition: AutomationStepSchema = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run({ inputs }: AutomationStepInput) {
|
export async function run({ inputs }: AutomationStepInput) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { automationId, ...fieldParams } = inputs.automation
|
const { automationId, ...fieldParams } = inputs.automation
|
||||||
|
|
||||||
if (await features.isTriggerAutomationRunEnabled()) {
|
if (await features.isTriggerAutomationRunEnabled()) {
|
||||||
|
|
|
@ -3,19 +3,18 @@ import * as triggers from "../triggers"
|
||||||
import { loopAutomation } from "../../tests/utilities/structures"
|
import { loopAutomation } from "../../tests/utilities/structures"
|
||||||
import { context } from "@budibase/backend-core"
|
import { context } from "@budibase/backend-core"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { Row, Table } from "@budibase/types"
|
import { Table } from "@budibase/types"
|
||||||
import { LoopInput, LoopStepType } from "../../definitions/automations"
|
import { LoopInput, LoopStepType } from "../../definitions/automations"
|
||||||
|
|
||||||
describe("Attempt to run a basic loop automation", () => {
|
describe("Attempt to run a basic loop automation", () => {
|
||||||
let config = setup.getConfig(),
|
let config = setup.getConfig(),
|
||||||
table: Table,
|
table: Table
|
||||||
row: Row
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await automation.init()
|
await automation.init()
|
||||||
await config.init()
|
await config.init()
|
||||||
table = await config.createTable()
|
table = await config.createTable()
|
||||||
row = await config.createRow()
|
await config.createRow()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { LoopStep, LoopStepType } from "../../definitions/automations"
|
import { LoopStepType } from "../../definitions/automations"
|
||||||
import {
|
import {
|
||||||
typecastForLooping,
|
typecastForLooping,
|
||||||
cleanInputValues,
|
cleanInputValues,
|
||||||
|
|
|
@ -6,6 +6,10 @@ import {
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
|
import env from "../environment"
|
||||||
|
|
||||||
|
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
||||||
|
|
||||||
export enum FilterTypes {
|
export enum FilterTypes {
|
||||||
STRING = "string",
|
STRING = "string",
|
||||||
FUZZY = "fuzzy",
|
FUZZY = "fuzzy",
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
import merge from "lodash/merge"
|
|
||||||
import env from "../environment"
|
|
||||||
|
|
||||||
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
|
||||||
|
|
||||||
const TableInfo = {
|
|
||||||
API_KEYS: {
|
|
||||||
name: "beta-api-key-table",
|
|
||||||
primary: "pk",
|
|
||||||
},
|
|
||||||
USERS: {
|
|
||||||
name: "prod-budi-table",
|
|
||||||
primary: "pk",
|
|
||||||
sort: "sk",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
let docClient: any = null
|
|
||||||
|
|
||||||
type GetOpts = {
|
|
||||||
primary: string
|
|
||||||
sort?: string
|
|
||||||
otherProps?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateOpts = {
|
|
||||||
primary: string
|
|
||||||
sort?: string
|
|
||||||
expression?: string
|
|
||||||
condition?: string
|
|
||||||
names?: string[]
|
|
||||||
values?: any[]
|
|
||||||
exists?: boolean
|
|
||||||
otherProps?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
type PutOpts = {
|
|
||||||
item: any
|
|
||||||
otherProps?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
class Table {
|
|
||||||
_name: string
|
|
||||||
_primary: string
|
|
||||||
_sort?: string
|
|
||||||
|
|
||||||
constructor(tableInfo: { name: string; primary: string; sort?: string }) {
|
|
||||||
if (!tableInfo.name || !tableInfo.primary) {
|
|
||||||
throw "Table info must specify a name and a primary key"
|
|
||||||
}
|
|
||||||
this._name = tableInfo.name
|
|
||||||
this._primary = tableInfo.primary
|
|
||||||
this._sort = tableInfo.sort
|
|
||||||
}
|
|
||||||
|
|
||||||
async get({ primary, sort, otherProps }: GetOpts) {
|
|
||||||
let params = {
|
|
||||||
TableName: this._name,
|
|
||||||
Key: {
|
|
||||||
[this._primary]: primary,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if (this._sort && sort) {
|
|
||||||
params.Key[this._sort] = sort
|
|
||||||
}
|
|
||||||
if (otherProps) {
|
|
||||||
params = merge(params, otherProps)
|
|
||||||
}
|
|
||||||
let response = await docClient.get(params).promise()
|
|
||||||
return response.Item
|
|
||||||
}
|
|
||||||
|
|
||||||
async update({
|
|
||||||
primary,
|
|
||||||
sort,
|
|
||||||
expression,
|
|
||||||
condition,
|
|
||||||
names,
|
|
||||||
values,
|
|
||||||
exists,
|
|
||||||
otherProps,
|
|
||||||
}: UpdateOpts) {
|
|
||||||
let params: any = {
|
|
||||||
TableName: this._name,
|
|
||||||
Key: {
|
|
||||||
[this._primary]: primary,
|
|
||||||
},
|
|
||||||
ExpressionAttributeNames: names,
|
|
||||||
ExpressionAttributeValues: values,
|
|
||||||
UpdateExpression: expression,
|
|
||||||
}
|
|
||||||
if (condition) {
|
|
||||||
params.ConditionExpression = condition
|
|
||||||
}
|
|
||||||
if (this._sort && sort) {
|
|
||||||
params.Key[this._sort] = sort
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
params.ExpressionAttributeNames["#PRIMARY"] = this._primary
|
|
||||||
if (params.ConditionExpression) {
|
|
||||||
params.ConditionExpression += " AND "
|
|
||||||
}
|
|
||||||
params.ConditionExpression += "attribute_exists(#PRIMARY)"
|
|
||||||
}
|
|
||||||
if (otherProps) {
|
|
||||||
params = merge(params, otherProps)
|
|
||||||
}
|
|
||||||
return docClient.update(params).promise()
|
|
||||||
}
|
|
||||||
|
|
||||||
async put({ item, otherProps }: PutOpts) {
|
|
||||||
if (
|
|
||||||
item[this._primary] == null ||
|
|
||||||
(this._sort && item[this._sort] == null)
|
|
||||||
) {
|
|
||||||
throw "Cannot put item without primary and sort key (if required)"
|
|
||||||
}
|
|
||||||
let params = {
|
|
||||||
TableName: this._name,
|
|
||||||
Item: item,
|
|
||||||
}
|
|
||||||
if (otherProps) {
|
|
||||||
params = merge(params, otherProps)
|
|
||||||
}
|
|
||||||
return docClient.put(params).promise()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function init(endpoint: string) {
|
|
||||||
let AWS = require("aws-sdk")
|
|
||||||
let docClientParams: any = {
|
|
||||||
correctClockSkew: true,
|
|
||||||
region: AWS_REGION,
|
|
||||||
}
|
|
||||||
if (endpoint) {
|
|
||||||
docClientParams.endpoint = endpoint
|
|
||||||
} else if (env.DYNAMO_ENDPOINT) {
|
|
||||||
docClientParams.endpoint = env.DYNAMO_ENDPOINT
|
|
||||||
}
|
|
||||||
docClient = new AWS.DynamoDB.DocumentClient(docClientParams)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!env.isProd() && !env.isJest()) {
|
|
||||||
env._set("AWS_ACCESS_KEY_ID", "KEY_ID")
|
|
||||||
env._set("AWS_SECRET_ACCESS_KEY", "SECRET_KEY")
|
|
||||||
init("http://localhost:8333")
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ import {
|
||||||
Row,
|
Row,
|
||||||
LinkDocumentValue,
|
LinkDocumentValue,
|
||||||
FieldType,
|
FieldType,
|
||||||
LinkDocument,
|
|
||||||
ContextUser,
|
ContextUser,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { features } from "@budibase/backend-core"
|
import { features } from "@budibase/backend-core"
|
||||||
import env from "./environment"
|
import env from "./environment"
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
enum AppFeature {
|
enum AppFeature {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
API = "api",
|
API = "api",
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
AUTOMATIONS = "automations",
|
AUTOMATIONS = "automations",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
TableRequest,
|
TableRequest,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import _ from "lodash"
|
|
||||||
import { databaseTestProviders } from "../integrations/tests/utils"
|
import { databaseTestProviders } from "../integrations/tests/utils"
|
||||||
import mysql from "mysql2/promise"
|
import mysql from "mysql2/promise"
|
||||||
import { builderSocket } from "../websockets"
|
import { builderSocket } from "../websockets"
|
||||||
|
@ -21,7 +20,6 @@ fetch.mockSearch()
|
||||||
|
|
||||||
const config = setup.getConfig()!
|
const config = setup.getConfig()!
|
||||||
|
|
||||||
jest.unmock("mysql2/promise")
|
|
||||||
jest.mock("../websockets", () => ({
|
jest.mock("../websockets", () => ({
|
||||||
clientAppSocket: jest.fn(),
|
clientAppSocket: jest.fn(),
|
||||||
gridAppSocket: jest.fn(),
|
gridAppSocket: jest.fn(),
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import AWS from "aws-sdk"
|
import AWS from "aws-sdk"
|
||||||
import { AWS_REGION } from "../db/dynamoClient"
|
import { AWS_REGION } from "../constants"
|
||||||
import { DocumentClient } from "aws-sdk/clients/dynamodb"
|
import { DocumentClient } from "aws-sdk/clients/dynamodb"
|
||||||
|
|
||||||
interface DynamoDBConfig {
|
interface DynamoDBConfig {
|
||||||
|
|
|
@ -168,6 +168,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
getStringConcat(parts: string[]) {
|
getStringConcat(parts: string[]) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ import {
|
||||||
Schema,
|
Schema,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
DatasourcePlusQueryResponse,
|
DatasourcePlusQueryResponse,
|
||||||
FieldType,
|
|
||||||
FieldSubtype,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
|
|
@ -13,8 +13,6 @@ import {
|
||||||
Schema,
|
Schema,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
DatasourcePlusQueryResponse,
|
DatasourcePlusQueryResponse,
|
||||||
FieldType,
|
|
||||||
FieldSubtype,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
|
|
@ -28,7 +28,7 @@ describe("Airtable Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
it("calls the create method with the correct params", async () => {
|
||||||
const response = await config.integration.create({
|
await config.integration.create({
|
||||||
table: "test",
|
table: "test",
|
||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
|
@ -40,7 +40,7 @@ describe("Airtable Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
it("calls the read method with the correct params", async () => {
|
||||||
const response = await config.integration.read({
|
await config.integration.read({
|
||||||
table: "test",
|
table: "test",
|
||||||
view: "Grid view",
|
view: "Grid view",
|
||||||
})
|
})
|
||||||
|
@ -51,7 +51,7 @@ describe("Airtable Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
it("calls the update method with the correct params", async () => {
|
||||||
const response = await config.integration.update({
|
await config.integration.update({
|
||||||
table: "table",
|
table: "table",
|
||||||
id: "123",
|
id: "123",
|
||||||
json: {
|
json: {
|
||||||
|
@ -68,7 +68,7 @@ describe("Airtable Integration", () => {
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
it("calls the delete method with the correct params", async () => {
|
||||||
const ids = [1, 2, 3, 4]
|
const ids = [1, 2, 3, 4]
|
||||||
const response = await config.integration.delete({
|
await config.integration.delete({
|
||||||
ids,
|
ids,
|
||||||
})
|
})
|
||||||
expect(config.client.destroy).toHaveBeenCalledWith(ids)
|
expect(config.client.destroy).toHaveBeenCalledWith(ids)
|
||||||
|
|
|
@ -12,7 +12,6 @@ class TestConfiguration {
|
||||||
|
|
||||||
describe("ArangoDB Integration", () => {
|
describe("ArangoDB Integration", () => {
|
||||||
let config: any
|
let config: any
|
||||||
let indexName = "Users"
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = new TestConfiguration()
|
config = new TestConfiguration()
|
||||||
|
@ -23,7 +22,7 @@ describe("ArangoDB Integration", () => {
|
||||||
json: "Hello",
|
json: "Hello",
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await config.integration.create(body)
|
await config.integration.create(body)
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(
|
expect(config.integration.client.query).toHaveBeenCalledWith(
|
||||||
`INSERT Hello INTO collection RETURN NEW`
|
`INSERT Hello INTO collection RETURN NEW`
|
||||||
)
|
)
|
||||||
|
@ -33,7 +32,7 @@ describe("ArangoDB Integration", () => {
|
||||||
const query = {
|
const query = {
|
||||||
sql: `test`,
|
sql: `test`,
|
||||||
}
|
}
|
||||||
const response = await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
|
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -79,7 +79,7 @@ describe("CouchDB Integration", () => {
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
it("calls the delete method with the correct params", async () => {
|
||||||
const id = "1234"
|
const id = "1234"
|
||||||
const response = await config.integration.delete({ id })
|
await config.integration.delete({ id })
|
||||||
expect(config.integration.client.get).toHaveBeenCalledWith(id)
|
expect(config.integration.client.get).toHaveBeenCalledWith(id)
|
||||||
expect(config.integration.client.remove).toHaveBeenCalled()
|
expect(config.integration.client.remove).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe("DynamoDB Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
it("calls the create method with the correct params", async () => {
|
||||||
const response = await config.integration.create({
|
await config.integration.create({
|
||||||
table: tableName,
|
table: tableName,
|
||||||
json: {
|
json: {
|
||||||
Name: "John",
|
Name: "John",
|
||||||
|
@ -66,7 +66,7 @@ describe("DynamoDB Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the get method with the correct params", async () => {
|
it("calls the get method with the correct params", async () => {
|
||||||
const response = await config.integration.get({
|
await config.integration.get({
|
||||||
table: tableName,
|
table: tableName,
|
||||||
json: {
|
json: {
|
||||||
Id: 123,
|
Id: 123,
|
||||||
|
@ -80,7 +80,7 @@ describe("DynamoDB Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
it("calls the update method with the correct params", async () => {
|
||||||
const response = await config.integration.update({
|
await config.integration.update({
|
||||||
table: tableName,
|
table: tableName,
|
||||||
json: {
|
json: {
|
||||||
Name: "John",
|
Name: "John",
|
||||||
|
@ -93,7 +93,7 @@ describe("DynamoDB Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
it("calls the delete method with the correct params", async () => {
|
||||||
const response = await config.integration.delete({
|
await config.integration.delete({
|
||||||
table: tableName,
|
table: tableName,
|
||||||
json: {
|
json: {
|
||||||
Name: "John",
|
Name: "John",
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe("Elasticsearch Integration", () => {
|
||||||
const body = {
|
const body = {
|
||||||
name: "Hello",
|
name: "Hello",
|
||||||
}
|
}
|
||||||
const response = await config.integration.create({
|
await config.integration.create({
|
||||||
index: indexName,
|
index: indexName,
|
||||||
json: body,
|
json: body,
|
||||||
})
|
})
|
||||||
|
|
|
@ -81,7 +81,7 @@ describe("Firebase Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
it("calls the delete method with the correct params", async () => {
|
||||||
const response = await config.integration.delete({
|
await config.integration.delete({
|
||||||
table: tableName,
|
table: tableName,
|
||||||
json: {
|
json: {
|
||||||
id: "test",
|
id: "test",
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
import { default as MSSQLIntegration } from "../microsoftSqlServer"
|
|
||||||
|
|
||||||
jest.mock("mssql")
|
|
||||||
|
|
||||||
class TestConfiguration {
|
|
||||||
integration: any
|
|
||||||
|
|
||||||
constructor(config: any = {}) {
|
|
||||||
this.integration = new MSSQLIntegration.integration(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("MS SQL Server Integration", () => {
|
|
||||||
let config: any
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
config = new TestConfiguration()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("check sql used", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await config.integration.connect()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
const response = await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.request).toHaveBeenCalledWith()
|
|
||||||
expect(response[0]).toEqual(sql)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
const response = await config.integration.read({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.request).toHaveBeenCalledWith()
|
|
||||||
expect(response[0]).toEqual(sql)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("no rows returned", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await config.integration.connect()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the create response has no rows", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
const response = await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response[0]).toEqual(sql)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -1,152 +0,0 @@
|
||||||
import { default as MySQLIntegration, bindingTypeCoerce } from "../mysql"
|
|
||||||
|
|
||||||
jest.mock("mysql2")
|
|
||||||
|
|
||||||
class TestConfiguration {
|
|
||||||
integration: any
|
|
||||||
|
|
||||||
constructor(config: any = { ssl: {} }) {
|
|
||||||
this.integration = new MySQLIntegration.integration(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("MySQL Integration", () => {
|
|
||||||
let config: any
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
config = new TestConfiguration()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
|
||||||
const sql = "update table users set name = 'test';"
|
|
||||||
await config.integration.update({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
|
||||||
const sql = "delete from users where name = 'todelete';"
|
|
||||||
await config.integration.delete({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("no rows returned", () => {
|
|
||||||
it("returns the correct response when the create response has no rows", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
const response = await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ created: true }])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the update response has no rows", async () => {
|
|
||||||
const sql = "update table users set name = 'test';"
|
|
||||||
const response = await config.integration.update({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ updated: true }])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the delete response has no rows", async () => {
|
|
||||||
const sql = "delete from users where name = 'todelete';"
|
|
||||||
const response = await config.integration.delete({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ deleted: true }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("binding type coerce", () => {
|
|
||||||
it("ignores non-string types", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
const date = new Date()
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
bindings: [11, date, ["a", "b", "c"], { id: 1 }],
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [
|
|
||||||
11,
|
|
||||||
date,
|
|
||||||
["a", "b", "c"],
|
|
||||||
{ id: 1 },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("parses strings matching a number regex", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
bindings: ["101", "3.14"],
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(
|
|
||||||
sql,
|
|
||||||
[101, 3.14]
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("parses strings matching a valid date format", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
bindings: [
|
|
||||||
"2001-10-30",
|
|
||||||
"2010-09-01T13:30:59.123Z",
|
|
||||||
"2021-02-05 12:01 PM",
|
|
||||||
],
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [
|
|
||||||
new Date("2001-10-30T00:00:00.000Z"),
|
|
||||||
new Date("2010-09-01T13:30:59.123Z"),
|
|
||||||
new Date("2021-02-05T12:01:00.000Z"),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("does not parse string matching a valid array of numbers as date", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
bindings: ["1,2,2017"],
|
|
||||||
})
|
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, [
|
|
||||||
"1,2,2017",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("bindingTypeCoercion", () => {
|
|
||||||
it("shouldn't coerce something that looks like a date", () => {
|
|
||||||
const response = bindingTypeCoerce(["202205-1500"])
|
|
||||||
expect(response[0]).toBe("202205-1500")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should coerce an actual date", () => {
|
|
||||||
const date = new Date("2023-06-13T14:24:22.620Z")
|
|
||||||
const response = bindingTypeCoerce(["2023-06-13T14:24:22.620Z"])
|
|
||||||
expect(response[0]).toEqual(date)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should coerce numbers", () => {
|
|
||||||
const response = bindingTypeCoerce(["0"])
|
|
||||||
expect(response[0]).toEqual(0)
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -44,7 +44,7 @@ describe("Oracle Integration", () => {
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
it("calls the update method with the correct params", async () => {
|
||||||
const sql = "update table users set name = 'test';"
|
const sql = "update table users set name = 'test';"
|
||||||
const response = await config.integration.update({
|
await config.integration.update({
|
||||||
sql,
|
sql,
|
||||||
})
|
})
|
||||||
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
|
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
const pg = require("pg")
|
|
||||||
|
|
||||||
import { default as PostgresIntegration } from "../postgres"
|
|
||||||
|
|
||||||
jest.mock("pg")
|
|
||||||
|
|
||||||
class TestConfiguration {
|
|
||||||
integration: any
|
|
||||||
|
|
||||||
constructor(config: any = {}) {
|
|
||||||
this.integration = new PostgresIntegration.integration(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Postgres Integration", () => {
|
|
||||||
let config: any
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
config = new TestConfiguration()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
|
||||||
const sql = "select * from users;"
|
|
||||||
await config.integration.read({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
|
||||||
const sql = "update table users set name = 'test';"
|
|
||||||
const response = await config.integration.update({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
|
||||||
const sql = "delete from users where name = 'todelete';"
|
|
||||||
await config.integration.delete({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("no rows returned", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
pg.queryMock.mockImplementation(() => ({ rows: [] }))
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the create response has no rows", async () => {
|
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
|
||||||
const response = await config.integration.create({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ created: true }])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the update response has no rows", async () => {
|
|
||||||
const sql = "update table users set name = 'test';"
|
|
||||||
const response = await config.integration.update({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ updated: true }])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the correct response when the delete response has no rows", async () => {
|
|
||||||
const sql = "delete from users where name = 'todelete';"
|
|
||||||
const response = await config.integration.delete({
|
|
||||||
sql,
|
|
||||||
})
|
|
||||||
expect(response).toEqual([{ deleted: true }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -70,7 +70,7 @@ describe("REST Integration", () => {
|
||||||
Accept: "text/html",
|
Accept: "text/html",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const response = await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "text/html",
|
Accept: "text/html",
|
||||||
|
@ -91,7 +91,7 @@ describe("REST Integration", () => {
|
||||||
name: "test",
|
name: "test",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
const response = await config.integration.update(query)
|
await config.integration.update(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: '{"name":"test"}',
|
body: '{"name":"test"}',
|
||||||
|
@ -111,7 +111,7 @@ describe("REST Integration", () => {
|
||||||
name: "test",
|
name: "test",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
const response = await config.integration.delete(query)
|
await config.integration.delete(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: HEADERS,
|
headers: HEADERS,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const AWS = require("aws-sdk")
|
|
||||||
|
|
||||||
import { default as S3Integration } from "../s3"
|
import { default as S3Integration } from "../s3"
|
||||||
|
|
||||||
jest.mock("aws-sdk")
|
jest.mock("aws-sdk")
|
||||||
|
|
|
@ -41,6 +41,9 @@ export async function datasource(): Promise<Datasource> {
|
||||||
port,
|
port,
|
||||||
user: "sa",
|
user: "sa",
|
||||||
password: "Password_123",
|
password: "Password_123",
|
||||||
|
options: {
|
||||||
|
encrypt: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { utils } from "@budibase/shared-core"
|
|
||||||
import environment from "../../environment"
|
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
|
|
||||||
export const enum BundleType {
|
export const enum BundleType {
|
||||||
|
|
|
@ -8,11 +8,10 @@ import {
|
||||||
import { context, logging } from "@budibase/backend-core"
|
import { context, logging } from "@budibase/backend-core"
|
||||||
import tracer from "dd-trace"
|
import tracer from "dd-trace"
|
||||||
import { IsolatedVM } from "./vm"
|
import { IsolatedVM } from "./vm"
|
||||||
import type { VM } from "@budibase/types"
|
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
setJSRunner((js: string, ctx: Record<string, any>) => {
|
setJSRunner((js: string, ctx: Record<string, any>) => {
|
||||||
return tracer.trace("runJS", {}, span => {
|
return tracer.trace("runJS", {}, () => {
|
||||||
try {
|
try {
|
||||||
// Reuse an existing isolate from context, or make a new one
|
// Reuse an existing isolate from context, or make a new one
|
||||||
const bbCtx = context.getCurrentContext()
|
const bbCtx = context.getCurrentContext()
|
||||||
|
@ -36,6 +35,7 @@ export function init() {
|
||||||
// Because we can't pass functions into an Isolate, we remove them from
|
// Because we can't pass functions into an Isolate, we remove them from
|
||||||
// the passed context and rely on the withHelpers() method to add them
|
// the passed context and rely on the withHelpers() method to add them
|
||||||
// back in.
|
// back in.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { helpers, snippets, ...rest } = ctx
|
const { helpers, snippets, ...rest } = ctx
|
||||||
return vm.withContext(rest, () => vm.execute(js))
|
return vm.withContext(rest, () => vm.execute(js))
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default async (ctx: Ctx, next: any) => {
|
||||||
let errors = []
|
let errors = []
|
||||||
for (let fn of current.cleanup) {
|
for (let fn of current.cleanup) {
|
||||||
try {
|
try {
|
||||||
await tracer.trace("cleanup", async span => {
|
await tracer.trace("cleanup", async () => {
|
||||||
await fn()
|
await fn()
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {
|
||||||
|
|
||||||
import authorizedMiddleware from "../authorized"
|
import authorizedMiddleware from "../authorized"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import { generateTableID, generateViewID } from "../../db/utils"
|
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import { initProMocks } from "../../tests/utilities/mocks/pro"
|
import { initProMocks } from "../../tests/utilities/mocks/pro"
|
||||||
import { getResourcePerms } from "../../sdk/app/permissions"
|
import { getResourcePerms } from "../../sdk/app/permissions"
|
||||||
|
|
|
@ -32,10 +32,7 @@ export default async (ctx: Ctx<Row>, next: Next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// have to mutate the koa context, can't return
|
// have to mutate the koa context, can't return
|
||||||
export async function trimViewFields<T extends Row>(
|
export async function trimViewFields(body: Row, viewId: string): Promise<void> {
|
||||||
body: Row,
|
|
||||||
viewId: string
|
|
||||||
): Promise<void> {
|
|
||||||
const view = await sdk.views.get(viewId)
|
const view = await sdk.views.get(viewId)
|
||||||
const allowedKeys = sdk.views.allowedFields(view)
|
const allowedKeys = sdk.views.allowedFields(view)
|
||||||
// have to mutate the context, can't update reference
|
// have to mutate the context, can't update reference
|
||||||
|
|
|
@ -43,7 +43,7 @@ export const backfill = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.roles) {
|
if (user.roles) {
|
||||||
for (const [appId, role] of Object.entries(user.roles)) {
|
for (const [, role] of Object.entries(user.roles)) {
|
||||||
await events.role.assigned(user, role, timestamp)
|
await events.role.assigned(user, role, timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import env from "../environment"
|
||||||
// migration functions
|
// migration functions
|
||||||
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
||||||
import * as syncQuotas from "./functions/syncQuotas"
|
import * as syncQuotas from "./functions/syncQuotas"
|
||||||
import * as syncUsers from "./functions/usageQuotas/syncUsers"
|
|
||||||
import * as appUrls from "./functions/appUrls"
|
import * as appUrls from "./functions/appUrls"
|
||||||
import * as tableSettings from "./functions/tableSettings"
|
import * as tableSettings from "./functions/tableSettings"
|
||||||
import * as backfill from "./functions/backfill"
|
import * as backfill from "./functions/backfill"
|
||||||
|
|
|
@ -3,11 +3,7 @@ import { db as dbCore, context, logging, roles } from "@budibase/backend-core"
|
||||||
import { User, ContextUser, UserGroup } from "@budibase/types"
|
import { User, ContextUser, UserGroup } from "@budibase/types"
|
||||||
import { sdk as proSdk } from "@budibase/pro"
|
import { sdk as proSdk } from "@budibase/pro"
|
||||||
import sdk from "../../"
|
import sdk from "../../"
|
||||||
import {
|
import { getRawGlobalUsers, processUser } from "../../../utilities/global"
|
||||||
getGlobalUsers,
|
|
||||||
getRawGlobalUsers,
|
|
||||||
processUser,
|
|
||||||
} from "../../../utilities/global"
|
|
||||||
import { generateUserMetadataID, InternalTables } from "../../../db/utils"
|
import { generateUserMetadataID, InternalTables } from "../../../db/utils"
|
||||||
|
|
||||||
type DeletedUser = { _id: string; deleted: boolean }
|
type DeletedUser = { _id: string; deleted: boolean }
|
||||||
|
|
|
@ -6,7 +6,7 @@ import EventEmitter from "events"
|
||||||
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
|
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
|
||||||
|
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
let app, group: UserGroup, groupUser: User
|
let group: UserGroup, groupUser: User
|
||||||
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
|
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
|
||||||
|
|
||||||
const emitter = new EventEmitter()
|
const emitter = new EventEmitter()
|
||||||
|
@ -36,7 +36,7 @@ function waitForUpdate(opts: { group?: boolean }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = await config.init("syncApp")
|
await config.init("syncApp")
|
||||||
})
|
})
|
||||||
|
|
||||||
async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { db, env, roles } from "@budibase/backend-core"
|
import { db, roles } from "@budibase/backend-core"
|
||||||
import { features } from "@budibase/pro"
|
import { features } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
DocumentType,
|
DocumentType,
|
||||||
|
@ -133,7 +133,7 @@ export async function getDependantResources(
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissions = await getResourcePerms(view.id)
|
const permissions = await getResourcePerms(view.id)
|
||||||
for (const [level, roleInfo] of Object.entries(permissions)) {
|
for (const [, roleInfo] of Object.entries(permissions)) {
|
||||||
if (roleInfo.type === PermissionSource.INHERITED) {
|
if (roleInfo.type === PermissionSource.INHERITED) {
|
||||||
dependants[VirtualDocumentType.VIEW] ??= new Set()
|
dependants[VirtualDocumentType.VIEW] ??= new Set()
|
||||||
dependants[VirtualDocumentType.VIEW].add(view.id)
|
dependants[VirtualDocumentType.VIEW].add(view.id)
|
||||||
|
|
|
@ -17,8 +17,6 @@ import {
|
||||||
generator,
|
generator,
|
||||||
} from "@budibase/backend-core/tests"
|
} from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
jest.unmock("mysql2/promise")
|
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
describe("external search", () => {
|
describe("external search", () => {
|
||||||
|
|
|
@ -351,6 +351,7 @@ describe("table sdk", () => {
|
||||||
const view: ViewV2 = {
|
const view: ViewV2 = {
|
||||||
...basicView,
|
...basicView,
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { name, description, ...newTableSchema } = basicTable.schema
|
const { name, description, ...newTableSchema } = basicTable.schema
|
||||||
|
|
||||||
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
|
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
|
||||||
|
@ -364,6 +365,7 @@ describe("table sdk", () => {
|
||||||
const view: ViewV2 = {
|
const view: ViewV2 = {
|
||||||
...basicView,
|
...basicView,
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { description, ...newTableSchema } = {
|
const { description, ...newTableSchema } = {
|
||||||
...basicTable.schema,
|
...basicTable.schema,
|
||||||
updatedDescription: {
|
updatedDescription: {
|
||||||
|
@ -448,6 +450,7 @@ describe("table sdk", () => {
|
||||||
hiddenField: { visible: false },
|
hiddenField: { visible: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { name, description, ...newTableSchema } = basicTable.schema
|
const { name, description, ...newTableSchema } = basicTable.schema
|
||||||
|
|
||||||
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
|
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
|
||||||
|
@ -471,6 +474,7 @@ describe("table sdk", () => {
|
||||||
hiddenField: { visible: false },
|
hiddenField: { visible: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { name, description, ...newTableSchema } = {
|
const { name, description, ...newTableSchema } = {
|
||||||
...basicTable.schema,
|
...basicTable.schema,
|
||||||
newField1: {
|
newField1: {
|
||||||
|
@ -502,6 +506,7 @@ describe("table sdk", () => {
|
||||||
hiddenField: { visible: false },
|
hiddenField: { visible: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { description, ...newTableSchema } = {
|
const { description, ...newTableSchema } = {
|
||||||
...basicTable.schema,
|
...basicTable.schema,
|
||||||
updatedDescription: {
|
updatedDescription: {
|
||||||
|
|
|
@ -49,7 +49,6 @@ import {
|
||||||
AuthToken,
|
AuthToken,
|
||||||
Automation,
|
Automation,
|
||||||
CreateViewRequest,
|
CreateViewRequest,
|
||||||
Ctx,
|
|
||||||
Datasource,
|
Datasource,
|
||||||
FieldType,
|
FieldType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
PaginatedSearchRowResponse,
|
PaginatedSearchRowResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { Expectations, TestAPI } from "./base"
|
import { Expectations, TestAPI } from "./base"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
|
|
||||||
export class ViewV2API extends TestAPI {
|
export class ViewV2API extends TestAPI {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue