1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Merge branch 'master' into tableblock-event-context

This commit is contained in:
Martin McKeaveney 2024-03-21 08:52:20 +00:00 committed by GitHub
commit ec11d4f4b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
156 changed files with 594 additions and 705 deletions

View file

@ -36,14 +36,14 @@
"files": ["**/*.ts"],
"excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended"],
"globals": {
"NodeJS": true
},
"rules": {
"no-unused-vars": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off",
"no-useless-escape": "off",
"no-undef": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-unused-vars": "error",
"local-rules/no-budibase-imports": "error"
}
},
@ -51,18 +51,17 @@
"files": ["**/*.spec.ts"],
"excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser",
"plugins": ["jest"],
"plugins": ["jest", "@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:jest/recommended"],
"env": {
"jest/globals": true
},
"globals": {
"NodeJS": true
},
"rules": {
"no-unused-vars": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off",
"no-useless-escape": "off",
"no-undef": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-unused-vars": "error",
"local-rules/no-test-com": "error",
"local-rules/email-domain-example-com": "error",
"no-console": "warn",

View file

@ -1,5 +1,5 @@
{
"version": "2.22.3",
"version": "2.22.7",
"npmClient": "yarn",
"packages": [
"packages/*",

View file

@ -26,6 +26,7 @@
"svelte": "^4.2.10",
"svelte-eslint-parser": "^0.33.1",
"typescript": "5.2.2",
"typescript-eslint": "^7.3.1",
"yargs": "^17.7.2"
},
"scripts": {

@ -1 +1 @@
Subproject commit 6465dc9c2a38e1380b32204cad4ae0c1f33e065a
Subproject commit f5b467b6b1c55c48847545db41be7b1c035e167a

View file

@ -133,7 +133,7 @@ export async function refreshOAuthToken(
configId?: string
): Promise<RefreshResponse> {
switch (providerType) {
case SSOProviderType.OIDC:
case SSOProviderType.OIDC: {
if (!configId) {
return { err: { data: "OIDC config id not provided" } }
}
@ -142,12 +142,14 @@ export async function refreshOAuthToken(
return { err: { data: "OIDC configuration not found" } }
}
return refreshOIDCAccessToken(oidcConfig, refreshToken)
case SSOProviderType.GOOGLE:
}
case SSOProviderType.GOOGLE: {
let googleConfig = await configs.getGoogleConfig()
if (!googleConfig) {
return { err: { data: "Google configuration not found" } }
}
return refreshGoogleAccessToken(googleConfig, refreshToken)
}
}
}

View file

@ -129,7 +129,7 @@ export default class BaseCache {
}
}
async bustCache(key: string, opts = { client: null }) {
async bustCache(key: string) {
const client = await this.getClient()
try {
await client.delete(generateTenantKey(key))

View file

@ -1,5 +1,5 @@
import * as utils from "../utils"
import { Duration, DurationType } from "../utils"
import { Duration } from "../utils"
import env from "../environment"
import { getTenantId } from "../context"
import * as redis from "../redis/init"

View file

@ -8,7 +8,7 @@ const DEFAULT_WRITE_RATE_MS = 10000
let CACHE: BaseCache | null = null
interface CacheItem<T extends Document> {
doc: any
doc: T
lastWrite: number
}

View file

@ -10,10 +10,6 @@ interface SearchResponse<T> {
totalRows: number
}
interface PaginatedSearchResponse<T> extends SearchResponse<T> {
hasNextPage: boolean
}
export type SearchParams<T> = {
tableId?: string
sort?: string
@ -247,7 +243,7 @@ export class QueryBuilder<T> {
}
// Escape characters
if (!this.#noEscaping && escape && originalType === "string") {
value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&")
value = `${value}`.replace(/[ /#+\-&|!(){}\]^"~*?:\\]/g, "\\$&")
}
// Wrap in quotes

View file

@ -34,12 +34,12 @@ export async function createUserIndex() {
}
let idxKey = prev != null ? `${prev}.${key}` : key
if (typeof input[key] === "string") {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index(idxKey, input[key].toLowerCase(), { facet: true })
} else if (typeof input[key] !== "object") {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index(idxKey, input[key], { facet: true })
} else {
idx(input[key], idxKey)

View file

@ -17,13 +17,8 @@ export function init(processors: ProcessorMap) {
// if not processing in this instance, kick it off
if (!processingPromise) {
processingPromise = asyncEventQueue.process(async job => {
const { event, identity, properties, timestamp } = job.data
await documentProcessor.processEvent(
event,
identity,
properties,
timestamp
)
const { event, identity, properties } = job.data
await documentProcessor.processEvent(event, identity, properties)
})
}
}

View file

@ -1,7 +1,6 @@
import {
Event,
Identity,
Group,
IdentityType,
AuditLogQueueEvent,
AuditLogFn,
@ -79,11 +78,11 @@ export default class AuditLogsProcessor implements EventProcessor {
}
}
async identify(identity: Identity, timestamp?: string | number) {
async identify() {
// no-op
}
async identifyGroup(group: Group, timestamp?: string | number) {
async identifyGroup() {
// no-op
}

View file

@ -8,8 +8,7 @@ export default class LoggingProcessor implements EventProcessor {
async processEvent(
event: Event,
identity: Identity,
properties: any,
timestamp?: string
properties: any
): Promise<void> {
if (skipLogging) {
return
@ -17,14 +16,14 @@ export default class LoggingProcessor implements EventProcessor {
console.log(`[audit] [identityType=${identity.type}] ${event}`, properties)
}
async identify(identity: Identity, timestamp?: string | number) {
async identify(identity: Identity) {
if (skipLogging) {
return
}
console.log(`[audit] identified`, identity)
}
async identifyGroup(group: Group, timestamp?: string | number) {
async identifyGroup(group: Group) {
if (skipLogging) {
return
}

View file

@ -14,12 +14,7 @@ export default class DocumentUpdateProcessor implements EventProcessor {
this.processors = processors
}
async processEvent(
event: Event,
identity: Identity,
properties: any,
timestamp?: string | number
) {
async processEvent(event: Event, identity: Identity, properties: any) {
const tenantId = identity.realTenantId
const docId = getDocumentId(event, properties)
if (!tenantId || !docId) {

View file

@ -10,6 +10,18 @@ import { formats } from "dd-trace/ext"
import { localFileDestination } from "../system"
function isPlainObject(obj: any) {
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
}
function isError(obj: any) {
return obj instanceof Error
}
function isMessage(obj: any) {
return typeof obj === "string"
}
// LOGGER
let pinoInstance: pino.Logger | undefined
@ -71,23 +83,11 @@ if (!env.DISABLE_PINO_LOGGER) {
err?: Error
}
function isPlainObject(obj: any) {
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
}
function isError(obj: any) {
return obj instanceof Error
}
function isMessage(obj: any) {
return typeof obj === "string"
}
/**
* Backwards compatibility between console logging statements
* and pino logging requirements.
*/
function getLogParams(args: any[]): [MergingObject, string] {
const getLogParams = (args: any[]): [MergingObject, string] => {
let error = undefined
let objects: any[] = []
let message = ""

View file

@ -28,7 +28,7 @@ export const buildMatcherRegex = (
}
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 methodMatch =
method === "ALL"

View file

@ -3,7 +3,7 @@ import { Cookie } from "../../../constants"
import * as configs from "../../../configs"
import * as cache from "../../../cache"
import * as utils from "../../../utils"
import { UserCtx, SSOProfile, DatasourceAuthCookie } from "@budibase/types"
import { UserCtx, SSOProfile } from "@budibase/types"
import { ssoSaveUserNoOp } from "../sso/sso"
const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy

View file

@ -5,7 +5,6 @@ import * as context from "../../../context"
import fetch from "node-fetch"
import {
SaveSSOUserFunction,
SaveUserOpts,
SSOAuthDetails,
SSOUser,
User,
@ -14,10 +13,8 @@ import {
// no-op function for user save
// - 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
export const ssoSaveUserNoOp: SaveSSOUserFunction = (
user: SSOUser,
opts: SaveUserOpts
) => Promise.resolve(user)
export const ssoSaveUserNoOp: SaveSSOUserFunction = (user: SSOUser) =>
Promise.resolve(user)
/**
* Common authentication logic for third parties. e.g. OAuth, OIDC.

View file

@ -45,10 +45,6 @@ export const runMigration = async (
options: MigrationOptions = {}
) => {
const migrationType = migration.type
let tenantId: string | undefined
if (migrationType !== MigrationType.INSTALLATION) {
tenantId = context.getTenantId()
}
const migrationName = migration.name
const silent = migration.silent

View file

@ -126,7 +126,7 @@ describe("app", () => {
it("gets url with embedded minio", async () => {
testEnv.withMinio()
await testEnv.withTenant(tenantId => {
await testEnv.withTenant(() => {
const url = getAppFileUrl()
expect(url).toBe(
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
@ -136,7 +136,7 @@ describe("app", () => {
it("gets url with custom S3", async () => {
testEnv.withS3()
await testEnv.withTenant(tenantId => {
await testEnv.withTenant(() => {
const url = getAppFileUrl()
expect(url).toBe(
"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 () => {
testEnv.withCloudfront()
await testEnv.withTenant(tenantId => {
await testEnv.withTenant(() => {
const url = getAppFileUrl()
// omit rest of signed params
expect(

View file

@ -3,7 +3,7 @@ import { DBTestConfiguration } from "../../../tests/extra"
import * as tenants from "../tenants"
describe("tenants", () => {
const config = new DBTestConfiguration()
new DBTestConfiguration()
describe("addTenant", () => {
it("concurrently adds multiple tenants safely", async () => {

View file

@ -39,7 +39,7 @@ class InMemoryQueue implements Partial<Queue> {
_opts?: QueueOptions
_messages: JobMessage[]
_queuedJobIds: Set<string>
_emitter: EventEmitter
_emitter: NodeJS.EventEmitter
_runCount: number
_addCount: number
@ -166,7 +166,7 @@ class InMemoryQueue implements Partial<Queue> {
return []
}
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async removeJobs(pattern: string) {
// no-op
}

View file

@ -132,7 +132,7 @@ function logging(queue: Queue, jobQueue: JobQueue) {
// A Job is waiting to be processed as soon as a worker is idling.
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.
await doInJobContext(job, () => {
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))

View file

@ -40,6 +40,7 @@ export async function shutdown() {
if (inviteClient) await inviteClient.finish()
if (passwordResetClient) await passwordResetClient.finish()
if (socketClient) await socketClient.finish()
if (docWritethroughClient) await docWritethroughClient.finish()
}
process.on("exit", async () => {

View file

@ -120,7 +120,7 @@ describe("redis", () => {
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)
}

View file

@ -97,7 +97,7 @@ describe("redlockImpl", () => {
executionTimeMs: lockTtl * 2,
})
).rejects.toThrow(
`Unable to fully release the lock on resource \"lock:${config.tenantId}_persist_writethrough\".`
`Unable to fully release the lock on resource "lock:${config.tenantId}_persist_writethrough".`
)
}
)

View file

@ -45,7 +45,7 @@ describe("Users", () => {
...{ _id: groupId, roles: { app1: "ADMIN" } },
}
const users: User[] = []
for (const _ of Array.from({ length: usersInGroup })) {
for (let i = 0; i < usersInGroup; i++) {
const userId = `us_${generator.guid()}`
const user: User = structures.users.user({
_id: userId,

View file

@ -39,19 +39,23 @@ const handleClick = event => {
return
}
if (handler.allowedType && event.type !== handler.allowedType) {
return
}
handler.callback?.(event)
})
}
document.documentElement.addEventListener("click", handleClick, true)
document.documentElement.addEventListener("contextmenu", handleClick, true)
document.documentElement.addEventListener("mousedown", handleClick, true)
/**
* 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)
if (!existingHandler) {
clickHandlers.push({ id, element, anchor, callback })
clickHandlers.push({ id, element, anchor, callback, allowedType })
} else {
existingHandler.callback = callback
}
@ -77,7 +81,8 @@ export default (element, opts) => {
const update = newOpts => {
const callback = newOpts?.callback || newOpts
const anchor = newOpts?.anchor || element
updateHandler(id, element, anchor, callback)
const allowedType = newOpts?.allowedType || "click"
updateHandler(id, element, anchor, callback, allowedType)
}
update(opts)
return {

View file

@ -28,7 +28,6 @@
let deleteTableName
$: externalTable = table?.sourceType === DB_TYPE_EXTERNAL
$: allowDeletion = !externalTable || table?.created
function showDeleteModal() {
templateScreens = $screenStore.screens.filter(
@ -56,7 +55,7 @@
$goto(`./datasource/${table.datasourceId}`)
}
} catch (error) {
notifications.error("Error deleting table")
notifications.error(`Error deleting table - ${error.message}`)
}
}
@ -86,17 +85,15 @@
}
</script>
{#if allowDeletion}
<ActionMenu>
<div slot="control" class="icon">
<Icon s hoverable name="MoreSmallList" />
</div>
{#if !externalTable}
<MenuItem icon="Edit" on:click={editorModal.show}>Edit</MenuItem>
{/if}
<MenuItem icon="Delete" on:click={showDeleteModal}>Delete</MenuItem>
</ActionMenu>
{/if}
<ActionMenu>
<div slot="control" class="icon">
<Icon s hoverable name="MoreSmallList" />
</div>
{#if !externalTable}
<MenuItem icon="Edit" on:click={editorModal.show}>Edit</MenuItem>
{/if}
<MenuItem icon="Delete" on:click={showDeleteModal}>Delete</MenuItem>
</ActionMenu>
<Modal bind:this={editorModal} on:show={initForm}>
<ModalContent

View file

@ -129,10 +129,7 @@
filteredUsers = $usersFetch.rows
.filter(user => user.email !== $auth.user.email)
.map(user => {
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(
user,
prodAppId
)
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(user)
const isAppBuilder = user.builder?.apps?.includes(prodAppId)
let role
if (isAdminOrGlobalBuilder) {

View file

@ -24,6 +24,13 @@
navigationStore,
} from "stores/builder"
import { DefaultAppTheme } from "constants"
import BarButtonList from "/src/components/design/settings/controls/BarButtonList.svelte"
$: alignmentOptions = [
{ value: "Left", barIcon: "TextAlignLeft" },
{ value: "Center", barIcon: "TextAlignCenter" },
{ value: "Right", barIcon: "TextAlignRight" },
]
$: screenRouteOptions = $screenStore.screens
.map(screen => screen.routing?.route)
@ -46,6 +53,10 @@
notifications.error("Error updating navigation settings")
}
}
const updateTextAlign = textAlignValue => {
navigationStore.syncAppNavigation({ textAlign: textAlignValue })
}
</script>
<Panel
@ -133,6 +144,15 @@
on:change={e => update("title", e.detail)}
updateOnChange={false}
/>
<div class="label">
<Label size="M">Text align</Label>
</div>
<BarButtonList
options={alignmentOptions}
value={$navigationStore.textAlign}
onChange={updateTextAlign}
/>
{/if}
<div class="label">
<Label>Background</Label>

View file

@ -11,6 +11,7 @@ export const INITIAL_NAVIGATION_STATE = {
hideLogo: null,
logoUrl: null,
hideTitle: null,
textAlign: "Left",
navBackground: null,
navWidth: null,
navTextColor: null,

View file

@ -36,6 +36,7 @@
export let pageWidth
export let logoLinkUrl
export let openLogoLinkInNewTab
export let textAlign
export let embedded = false
@ -226,7 +227,7 @@
{/if}
{/if}
{#if !hideTitle && title}
<Heading size="S">{title}</Heading>
<Heading size="S" {textAlign}>{title}</Heading>
{/if}
</div>
{#if !embedded}
@ -290,7 +291,10 @@
<div
id="side-panel-container"
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}
>
<div class="side-panel-header">

@ -1 +1 @@
Subproject commit 7d1b3eaf33e560d19d591813e5bba91d75ef3953
Subproject commit dd748e045ffdbc6662c5d2b76075f01d65a96a2f

View file

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module FirebaseMock {
const firebase: any = {}

View file

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module SendgridMock {
class Email {
constructor() {

View file

@ -1,8 +1,5 @@
module AirtableMock {
function Airtable() {
// @ts-ignore
this.base = jest.fn()
}
module.exports = Airtable
class Airtable {
base = jest.fn()
}
module.exports = Airtable

View file

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module ArangoMock {
const arangodb: any = {}

View file

@ -1,102 +1,81 @@
import fs from "fs"
import { join } from "path"
module AwsMock {
const aws: any = {}
const response = (body: any, extra?: any) => () => ({
promise: () => body,
...extra,
})
const response = (body: any, extra?: any) => () => ({
promise: () => body,
...extra,
})
function DocumentClient() {
// @ts-ignore
this.put = jest.fn(response({}))
// @ts-ignore
this.query = jest.fn(
response({
Items: [],
})
)
// @ts-ignore
this.scan = jest.fn(
response({
Items: [
{
Name: "test",
},
],
})
)
// @ts-ignore
this.get = jest.fn(response({}))
// @ts-ignore
this.update = jest.fn(response({}))
// @ts-ignore
this.delete = jest.fn(response({}))
}
function S3() {
// @ts-ignore
this.listObjects = jest.fn(
response({
Contents: [],
})
)
// @ts-ignore
this.createBucket = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.deleteObjects = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.getSignedUrl = (operation, params) => {
return `http://example.com/${params.Bucket}/${params.Key}`
}
// @ts-ignore
this.headBucket = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.upload = jest.fn(
response({
Contents: {},
})
)
// @ts-ignore
this.getObject = jest.fn(
response(
class DocumentClient {
put = jest.fn(response({}))
query = jest.fn(
response({
Items: [],
})
)
scan = jest.fn(
response({
Items: [
{
Body: "",
Name: "test",
},
{
createReadStream: jest
.fn()
.mockReturnValue(
fs.createReadStream(join(__dirname, "aws-sdk.ts"))
),
}
)
)
}
aws.DynamoDB = { DocumentClient }
aws.S3 = S3
aws.config = { update: jest.fn() }
module.exports = aws
],
})
)
get = jest.fn(response({}))
update = jest.fn(response({}))
delete = jest.fn(response({}))
}
class S3 {
listObjects = jest.fn(
response({
Contents: [],
})
)
createBucket = jest.fn(
response({
Contents: {},
})
)
deleteObjects = jest.fn(
response({
Contents: {},
})
)
getSignedUrl = jest.fn((operation, params) => {
return `http://example.com/${params.Bucket}/${params.Key}`
})
headBucket = jest.fn(
response({
Contents: {},
})
)
upload = jest.fn(
response({
Contents: {},
})
)
getObject = jest.fn(
response(
{
Body: "",
},
{
createReadStream: jest
.fn()
.mockReturnValue(fs.createReadStream(join(__dirname, "aws-sdk.ts"))),
}
)
)
}
module.exports = {
DynamoDB: {
DocumentClient,
},
S3,
config: {
update: jest.fn(),
},
}

View file

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module MongoMock {
const mongodb: any = {}

View file

@ -1,24 +1,17 @@
module MsSqlMock {
const mssql: any = {}
mssql.query = jest.fn(() => ({
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,
},
],
}))
// mssql.connect = jest.fn(() => ({ recordset: [] }))
mssql.ConnectionPool = jest.fn(() => ({
connect: jest.fn(() => ({
request: jest.fn(() => ({
query: jest.fn(sql => ({ recordset: [sql] })),
})),
})),
}))
module.exports = mssql
})),
}

View file

@ -1,14 +1,11 @@
module MySQLMock {
const mysql: any = {}
const client = {
connect: jest.fn(),
query: jest.fn((query, bindings, fn) => {
fn(null, [])
}),
}
mysql.createConnection = jest.fn(() => client)
module.exports = mysql
const client = {
connect: jest.fn(),
query: jest.fn((query, bindings, fn) => {
fn(null, [])
}),
}
module.exports = {
createConnection: jest.fn(() => client),
client,
}

View file

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module MySQLMock {
const mysql: any = {}

View file

@ -1,6 +1,7 @@
// @ts-ignore
import fs from "fs"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module FetchMock {
// @ts-ignore
const fetch = jest.requireActual("node-fetch")

View file

@ -1,31 +1,21 @@
module OracleDbMock {
// mock execute
const execute = jest.fn(() => ({
rows: [
{
a: "string",
b: 1,
},
],
}))
const executeMock = jest.fn(() => ({
rows: [
{
a: "string",
b: 1,
},
],
}))
const close = jest.fn()
const closeMock = jest.fn()
// mock connection
function Connection() {}
Connection.prototype.execute = execute
Connection.prototype.close = close
// mock oracledb
const oracleDb: any = {}
oracleDb.getConnection = jest.fn(() => {
// @ts-ignore
return new Connection()
})
// expose mocks
oracleDb.executeMock = execute
oracleDb.closeMock = close
module.exports = oracleDb
class Connection {
execute = executeMock
close = closeMock
}
module.exports = {
getConnection: jest.fn(() => new Connection()),
executeMock,
closeMock,
}

View file

@ -1,30 +1,25 @@
module PgMock {
const pg: any = {}
const query = jest.fn(() => ({
rows: [
{
a: "string",
b: 1,
},
],
}))
const query = jest.fn(() => ({
rows: [
{
a: "string",
b: 1,
},
],
}))
// constructor
function Client() {}
Client.prototype.query = query
Client.prototype.end = jest.fn(cb => {
class Client {
query = query
end = jest.fn(cb => {
if (cb) cb()
})
Client.prototype.connect = jest.fn()
Client.prototype.release = jest.fn()
const on = jest.fn()
pg.Client = Client
pg.queryMock = query
pg.on = on
module.exports = pg
connect = jest.fn()
release = jest.fn()
}
const on = jest.fn()
module.exports = {
Client,
queryMock: query,
on,
}

View file

@ -26,7 +26,6 @@ import {
env as envCore,
ErrorCode,
events,
HTTPError,
migrations,
objectStore,
roles,

View file

@ -39,25 +39,28 @@ export async function create(ctx: any) {
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
switch (source) {
case PluginSource.NPM:
case PluginSource.NPM: {
const { metadata: metadataNpm, directory: directoryNpm } =
await npmUpload(url, name)
metadata = metadataNpm
directory = directoryNpm
break
case PluginSource.GITHUB:
}
case PluginSource.GITHUB: {
const { metadata: metadataGithub, directory: directoryGithub } =
await githubUpload(url, name, githubToken)
metadata = metadataGithub
directory = directoryGithub
break
case PluginSource.URL:
}
case PluginSource.URL: {
const headersObj = headers || {}
const { metadata: metadataUrl, directory: directoryUrl } =
await urlUpload(url, name, headersObj)
metadata = metadataUrl
directory = directoryUrl
break
}
}
pluginCore.validate(metadata?.schema)

View file

@ -109,13 +109,14 @@ export class OpenAPI2 extends OpenAPISource {
for (let param of allParams) {
if (parameterNotRef(param)) {
switch (param.in) {
case "query":
case "query": {
let prefix = ""
if (queryString) {
prefix = "&"
}
queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`
break
}
case "header":
headers[param.name] = `{{${param.name}}}`
break
@ -125,7 +126,7 @@ export class OpenAPI2 extends OpenAPISource {
case "formData":
// future enhancement
break
case "body":
case "body": {
// set the request body to the example provided
// future enhancement: generate an example from the schema
let bodyParam: OpenAPIV2.InBodyParameterObject =
@ -135,6 +136,7 @@ export class OpenAPI2 extends OpenAPISource {
requestBody = schema.example
}
break
}
}
// add the parameter if it can be bound in our config

View file

@ -161,13 +161,14 @@ export class OpenAPI3 extends OpenAPISource {
for (let param of allParams) {
if (parameterNotRef(param)) {
switch (param.in) {
case "query":
case "query": {
let prefix = ""
if (queryString) {
prefix = "&"
}
queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`
break
}
case "header":
headers[param.name] = `{{${param.name}}}`
break

View file

@ -116,7 +116,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
target: prodDb.name,
})
await replication.replicate({
filter: (doc: any, params: any) => {
filter: (doc: any) => {
return doc._id && doc._id.startsWith("role_")
},
})

View file

@ -7,13 +7,11 @@ import {
FilterType,
IncludeRelationship,
ManyToManyRelationshipFieldMetadata,
ManyToOneRelationshipFieldMetadata,
OneToManyRelationshipFieldMetadata,
Operation,
PaginationJson,
RelationshipFieldMetadata,
RelationshipsJson,
RelationshipType,
Row,
SearchFilters,
SortJson,
@ -717,7 +715,7 @@ export class ExternalRequest<T extends Operation> {
const rows = related[key]?.rows || []
function relationshipMatchPredicate({
const relationshipMatchPredicate = ({
row,
linkPrimary,
linkSecondary,
@ -725,7 +723,7 @@ export class ExternalRequest<T extends Operation> {
row: Row
linkPrimary: string
linkSecondary?: string
}) {
}) => {
const matchesPrimaryLink =
row[linkPrimary] === relationship.id ||
row[linkPrimary] === body?.[linkPrimary]

View file

@ -23,6 +23,12 @@ const DISABLED_WRITE_CLIENTS: SqlClient[] = [
SqlClient.ORACLE,
]
const DISABLED_OPERATIONS: Operation[] = [
Operation.CREATE_TABLE,
Operation.UPDATE_TABLE,
Operation.DELETE_TABLE,
]
class CharSequence {
static alphabet = "abcdefghijklmnopqrstuvwxyz"
counters: number[]
@ -59,13 +65,18 @@ export default class AliasTables {
}
isAliasingEnabled(json: QueryJson, datasource: Datasource) {
const operation = json.endpoint.operation
const fieldLength = json.resource?.fields?.length
if (!fieldLength || fieldLength <= 0) {
if (
!fieldLength ||
fieldLength <= 0 ||
DISABLED_OPERATIONS.includes(operation)
) {
return false
}
try {
const sqlClient = getSQLClient(datasource)
const isWrite = WRITE_OPERATIONS.includes(json.endpoint.operation)
const isWrite = WRITE_OPERATIONS.includes(operation)
const isDisabledClient = DISABLED_WRITE_CLIENTS.includes(sqlClient)
if (isWrite && isDisabledClient) {
return false

View file

@ -1,4 +1,3 @@
import { quotas } from "@budibase/pro"
import {
UserCtx,
ViewV2,

View file

@ -61,9 +61,6 @@ export async function destroy(ctx: UserCtx) {
const tableToDelete: TableRequest = await sdk.tables.getTable(
ctx.params.tableId
)
if (!tableToDelete || !tableToDelete.created) {
ctx.throw(400, "Cannot delete tables which weren't created in Budibase.")
}
const datasourceId = getDatasourceId(tableToDelete)
try {
const { datasource, table } = await sdk.tables.external.destroy(

View file

@ -1,6 +1,6 @@
import { generateUserFlagID, InternalTables } from "../../db/utils"
import { getFullUser } from "../../utilities/users"
import { cache, context } from "@budibase/backend-core"
import { context } from "@budibase/backend-core"
import {
ContextUserMetadata,
Ctx,

View file

@ -24,7 +24,7 @@ async function parseSchema(view: CreateViewRequest) {
icon: schemaValue.icon,
}
Object.entries(fieldSchema)
.filter(([_, val]) => val === undefined)
.filter(([, val]) => val === undefined)
.forEach(([key]) => {
delete fieldSchema[key as keyof UIFieldMetadata]
})

View file

@ -33,7 +33,6 @@ export { default as staticRoutes } from "./static"
export { default as publicRoutes } from "./public"
const appBackupRoutes = pro.appBackups
const scheduleRoutes = pro.schedules
const environmentVariableRoutes = pro.environmentVariables
export const mainRoutes: Router[] = [
@ -65,7 +64,6 @@ export const mainRoutes: Router[] = [
pluginRoutes,
opsRoutes,
debugRoutes,
scheduleRoutes,
environmentVariableRoutes,
// these need to be handled last as they still use /api/:tableId
// this could be breaking as koa may recognise other routes as this

View file

@ -81,6 +81,7 @@ exports[`/datasources fetch returns all the datasources from the server 1`] = `
{
"config": {},
"createdAt": "2020-01-01T00:00:00.000Z",
"isSQL": true,
"name": "Test",
"source": "POSTGRES",
"type": "datasource",

View file

@ -16,7 +16,7 @@ describe("/applications/:appId/import", () => {
it("should be able to perform import", async () => {
const appId = config.getAppId()
const res = await request
await request
.post(`/api/applications/${appId}/import`)
.field("encryptionPassword", PASSWORD)
.attach("appExport", path.join(__dirname, "assets", "export.tar.gz"))

View file

@ -2,7 +2,6 @@ import * as setup from "./utilities"
import { roles, db as dbCore } from "@budibase/backend-core"
describe("/api/applications/:appId/sync", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let app

View file

@ -19,6 +19,7 @@ import env from "../../../environment"
import { type App } from "@budibase/types"
import tk from "timekeeper"
import * as uuid from "uuid"
import { structures } from "@budibase/backend-core/tests"
describe("/applications", () => {
let config = setup.getConfig()
@ -356,7 +357,7 @@ describe("/applications", () => {
it("should reject an unknown app id with a 404", async () => {
await config.api.application.duplicateApp(
app.appId.slice(0, -1) + "a",
structures.db.id(),
{
name: "to-dupe 123",
url: "/to-dupe-123",
@ -368,7 +369,7 @@ describe("/applications", () => {
})
it("should reject with a known name", async () => {
const resp = await config.api.application.duplicateApp(
await config.api.application.duplicateApp(
app.appId,
{
name: app.name,
@ -380,7 +381,7 @@ describe("/applications", () => {
})
it("should reject with a known url", async () => {
const resp = await config.api.application.duplicateApp(
await config.api.application.duplicateApp(
app.appId,
{
name: "this is fine",

View file

@ -156,7 +156,7 @@ describe("/permission", () => {
level: PermissionLevel.READ,
})
const response = await config.api.permission.revoke(
await config.api.permission.revoke(
{
roleId: STD_ROLE_ID,
resourceId: table._id,

View file

@ -65,7 +65,7 @@ describe("/queries", () => {
beforeEach(async () => {
await withConnection(async connection => {
const resp = await connection.query(createTableSQL)
await connection.query(createTableSQL)
await connection.query(insertSQL)
})
})

View file

@ -330,6 +330,7 @@ describe("/queries", () => {
],
},
]
pg.queryMock.mockImplementation(() => ({
rows,
}))

View file

@ -74,7 +74,7 @@ describe("/views", () => {
describe("create", () => {
it("returns a success message when the view is successfully created", async () => {
const res = await saveView()
await saveView()
expect(events.view.created).toHaveBeenCalledTimes(1)
})

View file

@ -5,7 +5,7 @@ import {
} from "@budibase/string-templates"
import sdk from "../sdk"
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.

View file

@ -4,7 +4,6 @@ import {
AutomationStepInput,
AutomationStepType,
AutomationIOType,
AutomationFeature,
} from "@budibase/types"
export const definition: AutomationStepSchema = {

View file

@ -10,8 +10,6 @@ import {
AutomationStepSchema,
AutomationStepType,
} from "@budibase/types"
import { utils } from "@budibase/backend-core"
import env from "../../environment"
export const definition: AutomationStepSchema = {
name: "External Data Connector",

View file

@ -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) {
return {
success: false,

View file

@ -62,6 +62,7 @@ export const definition: AutomationStepSchema = {
}
export async function run({ inputs }: AutomationStepInput) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { automationId, ...fieldParams } = inputs.automation
if (await features.isTriggerAutomationRunEnabled()) {

View file

@ -3,19 +3,18 @@ import * as triggers from "../triggers"
import { loopAutomation } from "../../tests/utilities/structures"
import { context } from "@budibase/backend-core"
import * as setup from "./utilities"
import { Row, Table } from "@budibase/types"
import { Table } from "@budibase/types"
import { LoopInput, LoopStepType } from "../../definitions/automations"
describe("Attempt to run a basic loop automation", () => {
let config = setup.getConfig(),
table: Table,
row: Row
table: Table
beforeEach(async () => {
await automation.init()
await config.init()
table = await config.createTable()
row = await config.createRow()
await config.createRow()
})
afterAll(setup.afterAll)

View file

@ -1,4 +1,4 @@
import { LoopStep, LoopStepType } from "../../definitions/automations"
import { LoopStepType } from "../../definitions/automations"
import {
typecastForLooping,
cleanInputValues,

View file

@ -6,6 +6,10 @@ import {
TableSourceType,
} from "@budibase/types"
import env from "../environment"
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
export enum FilterTypes {
STRING = "string",
FUZZY = "fuzzy",

View file

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

View file

@ -18,7 +18,6 @@ import {
Row,
LinkDocumentValue,
FieldType,
LinkDocument,
ContextUser,
} from "@budibase/types"
import sdk from "../../sdk"

View file

@ -30,8 +30,8 @@ export async function createLinkView() {
if (doc.type === "link") {
let doc1 = doc.doc1
let doc2 = doc.doc2
// @ts-expect-error emit is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
emit([doc1.tableId, doc1.rowId], {
id: doc2.rowId,
thisId: doc1.rowId,
@ -39,8 +39,8 @@ export async function createLinkView() {
})
// if linking to same table can't emit twice
if (doc1.tableId !== doc2.tableId) {
// @ts-expect-error emit is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
emit([doc2.tableId, doc2.rowId], {
id: doc1.rowId,
thisId: doc2.rowId,
@ -101,8 +101,8 @@ export async function createAllSearchIndex() {
if (Array.isArray(input[key])) {
for (let val of input[key]) {
if (typeof val !== "object") {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index(idxKey, val, { store: true })
}
}
@ -110,12 +110,12 @@ export async function createAllSearchIndex() {
continue
}
if (typeof input[key] === "string") {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index(idxKey, input[key].toLowerCase(), { store: true })
} else if (typeof input[key] !== "object") {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index(idxKey, input[key], { store: true })
} else {
idx(input[key], idxKey)
@ -123,8 +123,8 @@ export async function createAllSearchIndex() {
}
}
if (doc._id!.startsWith("ro_")) {
// @ts-expect-error index is available in a CouchDB map function
// eslint-disable-next-line no-undef
// @ts-ignore
index("default", doc._id)
idx(doc)
}

View file

@ -1,8 +1,11 @@
import { features } from "@budibase/backend-core"
import env from "./environment"
// eslint-disable-next-line no-unused-vars
enum AppFeature {
// eslint-disable-next-line no-unused-vars
API = "api",
// eslint-disable-next-line no-unused-vars
AUTOMATIONS = "automations",
}

View file

@ -12,7 +12,6 @@ import {
TableRequest,
TableSourceType,
} from "@budibase/types"
import _ from "lodash"
import { databaseTestProviders } from "../integrations/tests/utils"
import mysql from "mysql2/promise"
import { builderSocket } from "../websockets"
@ -106,6 +105,7 @@ describe("mysql integrations", () => {
plus: true,
source: "MYSQL",
type: "datasource_plus",
isSQL: true,
_id: expect.any(String),
_rev: expect.any(String),
createdAt: expect.any(String),

View file

@ -319,6 +319,7 @@ describe("postgres integrations", () => {
},
plus: true,
source: "POSTGRES",
isSQL: true,
type: "datasource_plus",
_id: expect.any(String),
_rev: expect.any(String),

View file

@ -699,13 +699,15 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
convertJsonStringColumns(
table: Table,
results: Record<string, any>[]
results: Record<string, any>[],
aliases?: Record<string, string>
): Record<string, any>[] {
for (const [name, field] of Object.entries(table.schema)) {
if (!this._isJsonColumn(field)) {
continue
}
const fullName = `${table.name}.${name}`
const tableName = aliases?.[table.name] || table.name
const fullName = `${tableName}.${name}`
for (let row of results) {
if (typeof row[fullName] === "string") {
row[fullName] = JSON.parse(row[fullName])

View file

@ -59,7 +59,7 @@ function generateSchema(
case FieldType.BARCODEQR:
schema.text(key)
break
case FieldType.BB_REFERENCE:
case FieldType.BB_REFERENCE: {
const subtype = column.subtype as FieldSubtype
switch (subtype) {
case FieldSubtype.USER:
@ -72,6 +72,7 @@ function generateSchema(
throw utils.unreachable(subtype)
}
break
}
case FieldType.NUMBER:
// if meta is specified then this is a junction table entry
if (column.meta && column.meta.toKey && column.meta.toTable) {

View file

@ -8,7 +8,7 @@ import {
} from "@budibase/types"
import AWS from "aws-sdk"
import { AWS_REGION } from "../db/dynamoClient"
import { AWS_REGION } from "../constants"
import { DocumentClient } from "aws-sdk/clients/dynamodb"
interface DynamoDBConfig {

View file

@ -168,6 +168,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
return ""
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getStringConcat(parts: string[]) {
return ""
}

View file

@ -14,8 +14,6 @@ import {
Schema,
TableSourceType,
DatasourcePlusQueryResponse,
FieldType,
FieldSubtype,
} from "@budibase/types"
import {
getSqlQuery,
@ -254,7 +252,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
}
switch (this.config.authType) {
case MSSQLConfigAuthType.AZURE_ACTIVE_DIRECTORY:
case MSSQLConfigAuthType.AZURE_ACTIVE_DIRECTORY: {
const { clientId, tenantId, clientSecret } =
this.config.adConfig || {}
const clientApp = new ConfidentialClientApplication({
@ -276,7 +274,8 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
},
}
break
case MSSQLConfigAuthType.NTLM:
}
case MSSQLConfigAuthType.NTLM: {
const { domain, trustServerCertificate } =
this.config.ntlmConfig || {}
clientCfg.authentication = {
@ -288,6 +287,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
clientCfg.options ??= {}
clientCfg.options.trustServerCertificate = !!trustServerCertificate
break
}
case null:
case undefined:
break
@ -506,7 +506,11 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
const queryFn = (query: any, op: string) => this.internalQuery(query, op)
const processFn = (result: any) => {
if (json?.meta?.table && result.recordset) {
return this.convertJsonStringColumns(json.meta.table, result.recordset)
return this.convertJsonStringColumns(
json.meta.table,
result.recordset,
json.tableAliases
)
} else if (result.recordset) {
return result.recordset
}

View file

@ -13,8 +13,6 @@ import {
Schema,
TableSourceType,
DatasourcePlusQueryResponse,
FieldType,
FieldSubtype,
} from "@budibase/types"
import {
getSqlQuery,
@ -390,7 +388,11 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
this.internalQuery(query, { connect: false, disableCoercion: true })
const processFn = (result: any) => {
if (json?.meta?.table && Array.isArray(result)) {
return this.convertJsonStringColumns(json.meta.table, result)
return this.convertJsonStringColumns(
json.meta.table,
result,
json.tableAliases
)
}
return result
}

View file

@ -455,7 +455,7 @@ class OracleIntegration extends Sql implements DatasourcePlus {
operation !== Operation.DELETE
) {
const lastRow = await this.internalQuery({
sql: `SELECT * FROM \"${json.endpoint.entityId}\" WHERE ROWID = '${response.lastRowid}'`,
sql: `SELECT * FROM "${json.endpoint.entityId}" WHERE ROWID = '${response.lastRowid}'`,
})
return lastRow.rows as Row[]
} else {

View file

@ -283,7 +283,7 @@ class RestIntegration implements IntegrationBase {
// content type defaults to plaintext
input.body = string
break
case BodyTypes.ENCODED:
case BodyTypes.ENCODED: {
const params = new URLSearchParams()
for (let [key, value] of Object.entries(object)) {
params.append(key, value as string)
@ -293,7 +293,8 @@ class RestIntegration implements IntegrationBase {
})
input.body = params
break
case BodyTypes.FORM_DATA:
}
case BodyTypes.FORM_DATA: {
const form = new FormData()
for (let [key, value] of Object.entries(object)) {
form.append(key, value)
@ -303,6 +304,7 @@ class RestIntegration implements IntegrationBase {
})
input.body = form
break
}
case BodyTypes.XML:
if (object != null && Object.keys(object).length) {
string = new XmlBuilder().buildObject(object)

View file

@ -28,7 +28,7 @@ describe("Airtable Integration", () => {
})
it("calls the create method with the correct params", async () => {
const response = await config.integration.create({
await config.integration.create({
table: "test",
json: {},
})
@ -40,7 +40,7 @@ describe("Airtable Integration", () => {
})
it("calls the read method with the correct params", async () => {
const response = await config.integration.read({
await config.integration.read({
table: "test",
view: "Grid view",
})
@ -51,7 +51,7 @@ describe("Airtable Integration", () => {
})
it("calls the update method with the correct params", async () => {
const response = await config.integration.update({
await config.integration.update({
table: "table",
id: "123",
json: {
@ -68,7 +68,7 @@ describe("Airtable Integration", () => {
it("calls the delete method with the correct params", async () => {
const ids = [1, 2, 3, 4]
const response = await config.integration.delete({
await config.integration.delete({
ids,
})
expect(config.client.destroy).toHaveBeenCalledWith(ids)

View file

@ -12,7 +12,6 @@ class TestConfiguration {
describe("ArangoDB Integration", () => {
let config: any
let indexName = "Users"
beforeEach(() => {
config = new TestConfiguration()
@ -23,7 +22,7 @@ describe("ArangoDB Integration", () => {
json: "Hello",
}
const response = await config.integration.create(body)
await config.integration.create(body)
expect(config.integration.client.query).toHaveBeenCalledWith(
`INSERT Hello INTO collection RETURN NEW`
)
@ -33,7 +32,7 @@ describe("ArangoDB Integration", () => {
const query = {
sql: `test`,
}
const response = await config.integration.read(query)
await config.integration.read(query)
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
})
})

View file

@ -79,7 +79,7 @@ describe("CouchDB Integration", () => {
it("calls the delete method with the correct params", async () => {
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.remove).toHaveBeenCalled()
})

View file

@ -19,7 +19,7 @@ describe("DynamoDB Integration", () => {
})
it("calls the create method with the correct params", async () => {
const response = await config.integration.create({
await config.integration.create({
table: tableName,
json: {
Name: "John",
@ -66,7 +66,7 @@ describe("DynamoDB Integration", () => {
})
it("calls the get method with the correct params", async () => {
const response = await config.integration.get({
await config.integration.get({
table: tableName,
json: {
Id: 123,
@ -80,7 +80,7 @@ describe("DynamoDB Integration", () => {
})
it("calls the update method with the correct params", async () => {
const response = await config.integration.update({
await config.integration.update({
table: tableName,
json: {
Name: "John",
@ -93,7 +93,7 @@ describe("DynamoDB Integration", () => {
})
it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({
await config.integration.delete({
table: tableName,
json: {
Name: "John",

View file

@ -22,7 +22,7 @@ describe("Elasticsearch Integration", () => {
const body = {
name: "Hello",
}
const response = await config.integration.create({
await config.integration.create({
index: indexName,
json: body,
})

View file

@ -81,7 +81,7 @@ describe("Firebase Integration", () => {
})
it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({
await config.integration.delete({
table: tableName,
json: {
id: "test",

View file

@ -44,7 +44,7 @@ describe("Oracle Integration", () => {
it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';"
const response = await config.integration.update({
await config.integration.update({
sql,
})
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)

View file

@ -37,7 +37,7 @@ describe("Postgres Integration", () => {
it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';"
const response = await config.integration.update({
await config.integration.update({
sql,
})
expect(pg.queryMock).toHaveBeenCalledWith(sql, [])

View file

@ -70,7 +70,7 @@ describe("REST Integration", () => {
Accept: "text/html",
},
}
const response = await config.integration.read(query)
await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
headers: {
Accept: "text/html",
@ -91,7 +91,7 @@ describe("REST Integration", () => {
name: "test",
}),
}
const response = await config.integration.update(query)
await config.integration.update(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "PUT",
body: '{"name":"test"}',
@ -111,7 +111,7 @@ describe("REST Integration", () => {
name: "test",
}),
}
const response = await config.integration.delete(query)
await config.integration.delete(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "DELETE",
headers: HEADERS,

View file

@ -1,5 +1,3 @@
const AWS = require("aws-sdk")
import { default as S3Integration } from "../s3"
jest.mock("aws-sdk")

View file

@ -389,7 +389,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`,
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age"::jsonb @> '[20]' and "${TABLE_NAME}"."name"::jsonb @> '["John"]' limit $1) as "${TABLE_NAME}"`,
})
})
@ -440,7 +440,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`,
sql: `select * from (select * from "${TABLE_NAME}" where NOT "${TABLE_NAME}"."age"::jsonb @> '[20]' and NOT "${TABLE_NAME}"."name"::jsonb @> '["John"]' limit $1) as "${TABLE_NAME}"`,
})
})
@ -491,7 +491,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb ?| array [20,25] and \"${TABLE_NAME}\".\"name\"::jsonb ?| array ['John','Mary'] limit $1) as \"${TABLE_NAME}\"`,
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age"::jsonb ?| array [20,25] and "${TABLE_NAME}"."name"::jsonb ?| array ['John','Mary'] limit $1) as "${TABLE_NAME}"`,
})
})
@ -572,7 +572,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: ["2000-01-01 00:00:00", 500],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" > $1 limit $2) as \"${TABLE_NAME}\"`,
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."dob" > $1 limit $2) as "${TABLE_NAME}"`,
})
})
@ -591,7 +591,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: ["2010-01-01 00:00:00", 500],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" < $1 limit $2) as \"${TABLE_NAME}\"`,
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."dob" < $1 limit $2) as "${TABLE_NAME}"`,
})
})
@ -607,7 +607,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: ["john%", limit],
sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`,
sql: `select * from (select * from (select * from "test" where LOWER("test"."name") LIKE :1) where rownum <= :2) "test"`,
})
query = new Sql(SqlClient.ORACLE, limit)._query(
@ -622,7 +622,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: ["%20%", "%25%", `%"john"%`, `%"mary"%`, limit],
sql: `select * from (select * from (select * from \"test\" where (LOWER(\"test\".\"age\") LIKE :1 AND LOWER(\"test\".\"age\") LIKE :2) and (LOWER(\"test\".\"name\") LIKE :3 AND LOWER(\"test\".\"name\") LIKE :4)) where rownum <= :5) \"test\"`,
sql: `select * from (select * from (select * from "test" where (LOWER("test"."age") LIKE :1 AND LOWER("test"."age") LIKE :2) and (LOWER("test"."name") LIKE :3 AND LOWER("test"."name") LIKE :4)) where rownum <= :5) "test"`,
})
query = new Sql(SqlClient.ORACLE, limit)._query(
@ -636,7 +636,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: [`%jo%`, limit],
sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`,
sql: `select * from (select * from (select * from "test" where LOWER("test"."name") LIKE :1) where rownum <= :2) "test"`,
})
})
@ -663,7 +663,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: ['{ "created_at":"2023-09-09T03:21:06.024Z" }'],
sql: `insert into \"test\" (\"name\") values ($1) returning *`,
sql: `insert into "test" ("name") values ($1) returning *`,
})
})
@ -676,7 +676,7 @@ describe("SQL query builder", () => {
)
expect(query).toEqual({
bindings: [dateObj],
sql: `insert into \"test\" (\"name\") values ($1) returning *`,
sql: `insert into "test" ("name") values ($1) returning *`,
})
})

View file

@ -330,7 +330,7 @@ function copyExistingPropsOver(
const existingTableSchema = entities[tableName].schema
for (let key in existingTableSchema) {
if (!existingTableSchema.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(existingTableSchema, key)) {
continue
}
const column = existingTableSchema[key]

Some files were not shown because too many files have changed in this diff Show more