Merge branch 'master' into BUDI-7656/add-migration

This commit is contained in:
Michael Drury 2024-01-08 13:20:33 +00:00 committed by GitHub
commit 5a18944a4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
126 changed files with 2793 additions and 2214 deletions

View File

@ -38,10 +38,10 @@ jobs:
submodules: ${{ env.IS_OSS_CONTRIBUTOR == 'false' }}
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- run: yarn lint
@ -56,10 +56,10 @@ jobs:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
@ -84,7 +84,7 @@ jobs:
with:
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: azure/setup-helm@v3
- run: cd charts/budibase && helm lint .
@ -98,10 +98,10 @@ jobs:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- name: Test
@ -122,10 +122,10 @@ jobs:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- name: Test worker
@ -146,10 +146,10 @@ jobs:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- name: Test server
@ -171,10 +171,10 @@ jobs:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
fetch-depth: 0
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- name: Test
@ -194,10 +194,10 @@ jobs:
submodules: ${{ env.IS_OSS_CONTRIBUTOR == 'false' }}
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn --frozen-lockfile
- name: Build packages

View File

@ -16,8 +16,8 @@ jobs:
days-before-pr-stale: 7
stale-issue-label: stale
exempt-pr-labels: pinned,security,roadmap
days-before-pr-close: 7
days-before-issue-close: 30
- uses: actions/stale@v8
with:
@ -26,6 +26,7 @@ jobs:
days-before-stale: 30
only-issue-labels: bug,High priority
stale-issue-label: warn
days-before-close: 30
- uses: actions/stale@v8
with:
@ -34,6 +35,7 @@ jobs:
days-before-stale: 90
only-issue-labels: bug,Medium priority
stale-issue-label: warn
days-before-close: 30
- uses: actions/stale@v8
with:
@ -43,5 +45,4 @@ jobs:
stale-issue-label: stale
only-issue-labels: bug
stale-issue-message: "This issue has been automatically marked as stale because it has not had any activity for six months."
days-before-close: 30

2
.nvmrc
View File

@ -1 +1 @@
v18.17.0
v20.10.0

View File

@ -1,3 +1,3 @@
nodejs 18.17.0
nodejs 20.10.0
python 3.10.0
yarn 1.22.19

View File

@ -252,4 +252,10 @@ spec:
{{ end }}
restartPolicy: Always
serviceAccountName: ""
{{ if .Values.services.apps.ndots }}
dnsConfig:
options:
- name: ndots
value: {{ .Values.services.apps.ndots | quote }}
{{ end }}
status: {}

View File

@ -227,6 +227,7 @@ spec:
resources:
{{- toYaml . | nindent 10 }}
{{ end }}
{{ if .Values.services.automationWorkers.command }}
command:
{{- toYaml .Values.services.automationWorkers.command | nindent 10 }}
{{ end }}
@ -251,6 +252,11 @@ spec:
{{ end }}
restartPolicy: Always
serviceAccountName: ""
{{ if .Values.services.automationWorkers.command }}}
{{ if .Values.services.automationWorkers.ndots }}
dnsConfig:
options:
- name: ndots
value: {{ .Values.services.automationWorkers.ndots | quote }}
{{ end }}
status: {}
{{- end }}

View File

@ -109,4 +109,10 @@ spec:
{{- toYaml .Values.services.proxy.args | nindent 8 }}
{{ end }}
volumes:
{{ if .Values.services.proxy.ndots }}
dnsConfig:
options:
- name: ndots
value: {{ .Values.services.proxy.ndots | quote }}
{{ end }}
status: {}

View File

@ -238,4 +238,10 @@ spec:
{{ end }}
restartPolicy: Always
serviceAccountName: ""
{{ if .Values.services.worker.ndots }}
dnsConfig:
options:
- name: ndots
value: {{ .Values.services.worker.ndots | quote }}
{{ end }}
status: {}

View File

@ -90,7 +90,7 @@ Component libraries are collections of components as well as the definition of t
#### 1. Prerequisites
- NodeJS version `18.x.x`
- NodeJS version `20.x.x`
- Python version `3.x`
### Using asdf (recommended)

View File

@ -76,6 +76,6 @@ done
# CouchDB needs the `_users` and `_replicator` databases to exist before it will
# function correctly, so we create them here.
curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984/_users
curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984/_replicator
curl -X PUT -u "${COUCHDB_USER}:${COUCHDB_PASSWORD}" http://localhost:5984/_users
curl -X PUT -u "${COUCHDB_USER}:${COUCHDB_PASSWORD}" http://localhost:5984/_replicator
sleep infinity

View File

@ -26,7 +26,7 @@ services:
BB_ADMIN_USER_EMAIL: ${BB_ADMIN_USER_EMAIL}
BB_ADMIN_USER_PASSWORD: ${BB_ADMIN_USER_PASSWORD}
PLUGINS_DIR: ${PLUGINS_DIR}
OFFLINE_MODE: ${OFFLINE_MODE}
OFFLINE_MODE: ${OFFLINE_MODE:-}
depends_on:
- worker-service
- redis-service
@ -53,7 +53,7 @@ services:
INTERNAL_API_KEY: ${INTERNAL_API_KEY}
REDIS_URL: redis-service:6379
REDIS_PASSWORD: ${REDIS_PASSWORD}
OFFLINE_MODE: ${OFFLINE_MODE}
OFFLINE_MODE: ${OFFLINE_MODE:-}
depends_on:
- redis-service
- minio-service
@ -109,7 +109,7 @@ services:
redis-service:
restart: unless-stopped
image: redis
command: redis-server --requirepass ${REDIS_PASSWORD}
command: redis-server --requirepass "${REDIS_PASSWORD}"
volumes:
- redis_data:/data

View File

@ -1,4 +1,4 @@
FROM node:18-slim as build
FROM node:20-slim as build
# install node-gyp dependencies
RUN apt-get update && apt-get install -y --no-install-recommends g++ make python3 jq
@ -42,7 +42,7 @@ COPY packages/string-templates packages/string-templates
FROM budibase/couchdb as runner
ARG TARGETARCH
ENV TARGETARCH $TARGETARCH
ENV NODE_MAJOR 18
ENV NODE_MAJOR 20
#TARGETBUILD can be set to single (for single docker image) or aas (for azure app service)
# e.g. docker build --build-arg TARGETBUILD=aas ....
ARG TARGETBUILD=single

View File

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

View File

@ -6,6 +6,7 @@
"@babel/eslint-parser": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
"@types/node": "20.10.0",
"@typescript-eslint/parser": "6.9.0",
"esbuild": "^0.18.17",
"esbuild-node-externals": "^1.8.0",
@ -99,7 +100,7 @@
"@budibase/types": "0.0.0"
},
"engines": {
"node": ">=18.0.0 <19.0.0"
"node": ">=20.0.0 <21.0.0"
},
"dependencies": {}
}

@ -1 +1 @@
Subproject commit e46a352a6326a838faa00f912de069aee95d7300
Subproject commit 8ee2734e77709438cbcaaabc024f677c7b24c883

View File

@ -65,7 +65,6 @@
"@types/cookies": "0.7.8",
"@types/jest": "29.5.5",
"@types/lodash": "4.14.200",
"@types/node": "18.17.0",
"@types/node-fetch": "2.6.4",
"@types/pouchdb": "6.4.0",
"@types/redlock": "4.0.3",

View File

@ -18,14 +18,15 @@ export enum TTL {
ONE_DAY = 86400,
}
function performExport(funcName: string) {
// @ts-ignore
return (...args: any) => GENERIC[funcName](...args)
}
export const keys = performExport("keys")
export const get = performExport("get")
export const store = performExport("store")
export const destroy = performExport("delete")
export const withCache = performExport("withCache")
export const bustCache = performExport("bustCache")
export const keys = (...args: Parameters<typeof GENERIC.keys>) =>
GENERIC.keys(...args)
export const get = (...args: Parameters<typeof GENERIC.get>) =>
GENERIC.get(...args)
export const store = (...args: Parameters<typeof GENERIC.store>) =>
GENERIC.store(...args)
export const destroy = (...args: Parameters<typeof GENERIC.delete>) =>
GENERIC.delete(...args)
export const withCache = (...args: Parameters<typeof GENERIC.withCache>) =>
GENERIC.withCache(...args)
export const bustCache = (...args: Parameters<typeof GENERIC.bustCache>) =>
GENERIC.bustCache(...args)

View File

@ -1,6 +1,6 @@
import * as redis from "../redis/init"
import * as utils from "../utils"
import { Duration, DurationType } from "../utils"
import { Duration } from "../utils"
const TTL_SECONDS = Duration.fromHours(1).toSeconds()
@ -32,7 +32,18 @@ export async function getCode(code: string): Promise<PasswordReset> {
const client = await redis.getPasswordResetClient()
const value = (await client.get(code)) as PasswordReset | undefined
if (!value) {
throw "Provided information is not valid, cannot reset password - please try again."
throw new Error(
"Provided information is not valid, cannot reset password - please try again."
)
}
return value
}
/**
* Given a reset code this will invalidate it.
* @param code The code provided via the email link.
*/
export async function invalidateCode(code: string): Promise<void> {
const client = await redis.getPasswordResetClient()
await client.delete(code)
}

View File

@ -134,7 +134,7 @@ export async function doInContext(appId: string, task: any): Promise<any> {
}
export async function doInTenant<T>(
tenantId: string | null,
tenantId: string | undefined,
task: () => T
): Promise<T> {
// make sure default always selected in single tenancy

View File

@ -17,6 +17,7 @@ import { directCouchUrlCall } from "./utils"
import { getPouchDB } from "./pouchDB"
import { WriteStream, ReadStream } from "fs"
import { newid } from "../../docIds/newid"
import { DDInstrumentedDatabase } from "../instrumentation"
function buildNano(couchInfo: { url: string; cookie: string }) {
return Nano({
@ -35,7 +36,8 @@ export function DatabaseWithConnection(
connection: string,
opts?: DatabaseOpts
) {
return new DatabaseImpl(dbName, opts, connection)
const db = new DatabaseImpl(dbName, opts, connection)
return new DDInstrumentedDatabase(db)
}
export class DatabaseImpl implements Database {

View File

@ -1,8 +1,9 @@
import { directCouchQuery, DatabaseImpl } from "./couch"
import { CouchFindOptions, Database, DatabaseOpts } from "@budibase/types"
import { DDInstrumentedDatabase } from "./instrumentation"
export function getDB(dbName: string, opts?: DatabaseOpts): Database {
return new DatabaseImpl(dbName, opts)
return new DDInstrumentedDatabase(new DatabaseImpl(dbName, opts))
}
// we have to use a callback for this so that we can close

View File

@ -0,0 +1,156 @@
import {
DocumentScope,
DocumentDestroyResponse,
DocumentInsertResponse,
DocumentBulkResponse,
OkResponse,
} from "@budibase/nano"
import {
AllDocsResponse,
AnyDocument,
Database,
DatabaseDumpOpts,
DatabasePutOpts,
DatabaseQueryOpts,
Document,
} from "@budibase/types"
import tracer from "dd-trace"
import { Writable } from "stream"
export class DDInstrumentedDatabase implements Database {
constructor(private readonly db: Database) {}
get name(): string {
return this.db.name
}
exists(): Promise<boolean> {
return tracer.trace("db.exists", span => {
span?.addTags({ db_name: this.name })
return this.db.exists()
})
}
checkSetup(): Promise<DocumentScope<any>> {
return tracer.trace("db.checkSetup", span => {
span?.addTags({ db_name: this.name })
return this.db.checkSetup()
})
}
get<T extends Document>(id?: string | undefined): Promise<T> {
return tracer.trace("db.get", span => {
span?.addTags({ db_name: this.name, doc_id: id })
return this.db.get(id)
})
}
getMultiple<T extends Document>(
ids: string[],
opts?: { allowMissing?: boolean | undefined } | undefined
): Promise<T[]> {
return tracer.trace("db.getMultiple", span => {
span?.addTags({
db_name: this.name,
num_docs: ids.length,
allow_missing: opts?.allowMissing,
})
return this.db.getMultiple(ids, opts)
})
}
remove(
id: string | Document,
rev?: string | undefined
): Promise<DocumentDestroyResponse> {
return tracer.trace("db.remove", span => {
span?.addTags({ db_name: this.name, doc_id: id })
return this.db.remove(id, rev)
})
}
put(
document: AnyDocument,
opts?: DatabasePutOpts | undefined
): Promise<DocumentInsertResponse> {
return tracer.trace("db.put", span => {
span?.addTags({ db_name: this.name, doc_id: document._id })
return this.db.put(document, opts)
})
}
bulkDocs(documents: AnyDocument[]): Promise<DocumentBulkResponse[]> {
return tracer.trace("db.bulkDocs", span => {
span?.addTags({ db_name: this.name, num_docs: documents.length })
return this.db.bulkDocs(documents)
})
}
allDocs<T extends Document>(
params: DatabaseQueryOpts
): Promise<AllDocsResponse<T>> {
return tracer.trace("db.allDocs", span => {
span?.addTags({ db_name: this.name })
return this.db.allDocs(params)
})
}
query<T extends Document>(
viewName: string,
params: DatabaseQueryOpts
): Promise<AllDocsResponse<T>> {
return tracer.trace("db.query", span => {
span?.addTags({ db_name: this.name, view_name: viewName })
return this.db.query(viewName, params)
})
}
destroy(): Promise<void | OkResponse> {
return tracer.trace("db.destroy", span => {
span?.addTags({ db_name: this.name })
return this.db.destroy()
})
}
compact(): Promise<void | OkResponse> {
return tracer.trace("db.compact", span => {
span?.addTags({ db_name: this.name })
return this.db.compact()
})
}
dump(stream: Writable, opts?: DatabaseDumpOpts | undefined): Promise<any> {
return tracer.trace("db.dump", span => {
span?.addTags({ db_name: this.name })
return this.db.dump(stream, opts)
})
}
load(...args: any[]): Promise<any> {
return tracer.trace("db.load", span => {
span?.addTags({ db_name: this.name })
return this.db.load(...args)
})
}
createIndex(...args: any[]): Promise<any> {
return tracer.trace("db.createIndex", span => {
span?.addTags({ db_name: this.name })
return this.db.createIndex(...args)
})
}
deleteIndex(...args: any[]): Promise<any> {
return tracer.trace("db.deleteIndex", span => {
span?.addTags({ db_name: this.name })
return this.db.deleteIndex(...args)
})
}
getIndexes(...args: any[]): Promise<any> {
return tracer.trace("db.getIndexes", span => {
span?.addTags({ db_name: this.name })
return this.db.getIndexes(...args)
})
}
}

View File

@ -166,6 +166,8 @@ const environment = {
DISABLE_JWT_WARNING: process.env.DISABLE_JWT_WARNING,
BLACKLIST_IPS: process.env.BLACKLIST_IPS,
SERVICE_TYPE: "unknown",
PASSWORD_MIN_LENGTH: process.env.PASSWORD_MIN_LENGTH,
PASSWORD_MAX_LENGTH: process.env.PASSWORD_MAX_LENGTH,
/**
* Enable to allow an admin user to login using a password.
* This can be useful to prevent lockout when configuring SSO.

View File

@ -33,6 +33,7 @@ export * as docUpdates from "./docUpdates"
export * from "./utils/Duration"
export { SearchParams } from "./db"
export * as docIds from "./docIds"
export * as security from "./security"
// Add context to tenancy for backwards compatibility
// only do this for external usages to prevent internal
// circular dependencies

View File

@ -5,6 +5,7 @@ import { IdentityType } from "@budibase/types"
import env from "../../environment"
import * as context from "../../context"
import * as correlation from "../correlation"
import tracer from "dd-trace"
import { formats } from "dd-trace/ext"
import { localFileDestination } from "../system"
@ -116,6 +117,11 @@ if (!env.DISABLE_PINO_LOGGER) {
correlationId: correlation.getId(),
}
const span = tracer.scope().active()
if (span) {
tracer.inject(span.context(), formats.LOG, contextObject)
}
const mergingObject: any = {
err: error,
pid: process.pid,

View File

@ -15,6 +15,7 @@ import * as identity from "../context/identity"
import env from "../environment"
import { Ctx, EndpointMatcher, SessionCookie } from "@budibase/types"
import { InvalidAPIKeyError, ErrorCode } from "../errors"
import tracer from "dd-trace"
const ONE_MINUTE = env.SESSION_UPDATE_PERIOD
? parseInt(env.SESSION_UPDATE_PERIOD)
@ -166,6 +167,16 @@ export default function (
if (!authenticated) {
authenticated = false
}
if (user) {
tracer.setUser({
id: user?._id,
tenantId: user?.tenantId,
budibaseAccess: user?.budibaseAccess,
status: user?.status,
})
}
// isAuthenticated is a function, so use a variable to be able to check authed state
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })

View File

@ -47,7 +47,7 @@ export function createQueue<T>(
cleanupInterval = timers.set(cleanup, CLEANUP_PERIOD_MS)
// fire off an initial cleanup
cleanup().catch(err => {
console.error(`Unable to cleanup automation queue initially - ${err}`)
console.error(`Unable to cleanup ${jobQueue} initially - ${err}`)
})
}
return queue

View File

@ -18,6 +18,7 @@ import {
SelectableDatabase,
getRedisConnectionDetails,
} from "./utils"
import { logAlert } from "../logging"
import * as timers from "../timers"
const RETRY_PERIOD_MS = 2000
@ -39,21 +40,16 @@ function pickClient(selectDb: number): any {
return CLIENTS[selectDb]
}
function connectionError(
selectDb: number,
timeout: NodeJS.Timeout,
err: Error | string
) {
function connectionError(timeout: NodeJS.Timeout, err: Error | string) {
// manually shut down, ignore errors
if (CLOSED) {
return
}
pickClient(selectDb).disconnect()
CLOSED = true
// always clear this on error
clearTimeout(timeout)
CONNECTED = false
console.error("Redis connection failed - " + err)
logAlert("Redis connection failed", err)
setTimeout(() => {
init()
}, RETRY_PERIOD_MS)
@ -79,11 +75,7 @@ function init(selectDb = DEFAULT_SELECT_DB) {
// start the timer - only allowed 5 seconds to connect
timeout = setTimeout(() => {
if (!CONNECTED) {
connectionError(
selectDb,
timeout,
"Did not successfully connect in timeout"
)
connectionError(timeout, "Did not successfully connect in timeout")
}
}, STARTUP_TIMEOUT_MS)
@ -106,12 +98,13 @@ function init(selectDb = DEFAULT_SELECT_DB) {
// allow the process to exit
return
}
connectionError(selectDb, timeout, err)
connectionError(timeout, err)
})
client.on("error", (err: Error) => {
connectionError(selectDb, timeout, err)
connectionError(timeout, err)
})
client.on("connect", () => {
console.log(`Connected to Redis DB: ${selectDb}`)
clearTimeout(timeout)
CONNECTED = true
})

View File

@ -2,7 +2,6 @@ import Redlock from "redlock"
import { getLockClient } from "./init"
import { LockOptions, LockType } from "@budibase/types"
import * as context from "../context"
import { logWarn } from "../logging"
import { utils } from "@budibase/shared-core"
import { Duration } from "../utils"

View File

@ -0,0 +1,24 @@
import env from "../environment"
export const PASSWORD_MIN_LENGTH = +(env.PASSWORD_MIN_LENGTH || 8)
export const PASSWORD_MAX_LENGTH = +(env.PASSWORD_MAX_LENGTH || 512)
export function validatePassword(
password: string
): { valid: true } | { valid: false; error: string } {
if (!password || password.length < PASSWORD_MIN_LENGTH) {
return {
valid: false,
error: `Password invalid. Minimum ${PASSWORD_MIN_LENGTH} characters.`,
}
}
if (password.length > PASSWORD_MAX_LENGTH) {
return {
valid: false,
error: `Password invalid. Maximum ${PASSWORD_MAX_LENGTH} characters.`,
}
}
return { valid: true }
}

View File

@ -0,0 +1 @@
export * from "./auth"

View File

@ -0,0 +1,45 @@
import { generator } from "../../../tests"
import { PASSWORD_MAX_LENGTH, validatePassword } from "../auth"
describe("auth", () => {
describe("validatePassword", () => {
it("a valid password returns successful", () => {
expect(validatePassword("password")).toEqual({ valid: true })
})
it.each([
["undefined", undefined],
["null", null],
["empty", ""],
])("%s returns unsuccessful", (_, password) => {
expect(validatePassword(password as string)).toEqual({
valid: false,
error: "Password invalid. Minimum 8 characters.",
})
})
it.each([
generator.word({ length: PASSWORD_MAX_LENGTH }),
generator.paragraph().substring(0, PASSWORD_MAX_LENGTH),
])(`can use passwords up to 512 characters in length`, password => {
expect(validatePassword(password)).toEqual({
valid: true,
})
})
it.each([
generator.word({ length: PASSWORD_MAX_LENGTH + 1 }),
generator
.paragraph({ sentences: 50 })
.substring(0, PASSWORD_MAX_LENGTH + 1),
])(
`passwords cannot have more than ${PASSWORD_MAX_LENGTH} characters`,
password => {
expect(validatePassword(password)).toEqual({
valid: false,
error: "Password invalid. Maximum 512 characters.",
})
}
)
})
})

View File

@ -39,7 +39,7 @@ const ALL_STRATEGIES = Object.values(TenantResolutionStrategy)
export const getTenantIDFromCtx = (
ctx: BBContext,
opts: GetTenantIdOptions
): string | null => {
): string | undefined => {
// exit early if not multi-tenant
if (!isMultiTenant()) {
return DEFAULT_TENANT_ID
@ -144,5 +144,5 @@ export const getTenantIDFromCtx = (
ctx.throw(403, "Tenant id not set")
}
return null
return undefined
}

View File

@ -157,12 +157,12 @@ describe("getTenantIDFromCtx", () => {
TenantResolutionStrategy.PATH,
],
}
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeNull()
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeUndefined()
expect(ctx.throw).toBeCalledTimes(1)
expect(ctx.throw).toBeCalledWith(403, "Tenant id not set")
})
it("returns null if allowNoTenant is true", () => {
it("returns undefined if allowNoTenant is true", () => {
const ctx = createCtx({})
mockOpts = {
allowNoTenant: true,
@ -172,7 +172,7 @@ describe("getTenantIDFromCtx", () => {
TenantResolutionStrategy.PATH,
],
}
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeNull()
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeUndefined()
})
})

View File

@ -50,7 +50,7 @@ export class ExecutionTimeTracker {
return this.totalTimeMs
}
private checkLimit() {
checkLimit() {
if (this.totalTimeMs > this.limitMs) {
throw new ExecutionTimeoutError(
`Execution time limit of ${this.limitMs}ms exceeded: ${this.totalTimeMs}ms`

View File

@ -27,6 +27,7 @@ import {
} from "./utils"
import { searchExistingEmails } from "./lookup"
import { hash } from "../utils"
import { validatePassword } from "../security"
type QuotaUpdateFn = (
change: number,
@ -43,6 +44,12 @@ type GroupFns = {
getBulk: GroupGetFn
getGroupBuilderAppIds: GroupBuildersFn
}
type CreateAdminUserOpts = {
ssoId?: string
hashPassword?: boolean
requirePassword?: boolean
skipPasswordValidation?: boolean
}
type FeatureFns = { isSSOEnforced: FeatureFn; isAppBuildersEnabled: FeatureFn }
const bulkDeleteProcessing = async (dbUser: User) => {
@ -110,6 +117,14 @@ export class UserDB {
if (await UserDB.isPreventPasswordActions(user, account)) {
throw new HTTPError("Password change is disabled for this user", 400)
}
if (!opts.skipPasswordValidation) {
const passwordValidation = validatePassword(password)
if (!passwordValidation.valid) {
throw new HTTPError(passwordValidation.error, 400)
}
}
hashedPassword = opts.hashPassword ? await hash(password) : password
} else if (dbUser) {
hashedPassword = dbUser.password
@ -482,7 +497,7 @@ export class UserDB {
email: string,
password: string,
tenantId: string,
opts?: { ssoId?: string; hashPassword?: boolean; requirePassword?: boolean }
opts?: CreateAdminUserOpts
) {
const user: User = {
email: email,
@ -506,6 +521,7 @@ export class UserDB {
return await UserDB.save(user, {
hashPassword: opts?.hashPassword,
requirePassword: opts?.requirePassword,
skipPasswordValidation: opts?.skipPasswordValidation,
})
}

View File

@ -31,8 +31,8 @@ export async function resolveAppUrl(ctx: Ctx) {
const appUrl = ctx.path.split("/")[2]
let possibleAppUrl = `/${appUrl.toLowerCase()}`
let tenantId: string | null = context.getTenantId()
if (env.MULTI_TENANCY) {
let tenantId: string | undefined = context.getTenantId()
if (!env.isDev() && env.MULTI_TENANCY) {
// always use the tenant id from the subdomain in multi tenancy
// this ensures the logged-in user tenant id doesn't overwrite
// e.g. in the case of viewing a public app while already logged-in to another tenant
@ -41,7 +41,7 @@ export async function resolveAppUrl(ctx: Ctx) {
})
}
// search prod apps for a url that matches
// search prod apps for an url that matches
const apps: App[] = await context.doInTenant(
tenantId,
() => getAllApps({ dev: false }) as Promise<App[]>

View File

@ -21,7 +21,7 @@ export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
_id: userId,
userId,
email: newEmail(),
password: "test",
password: "password",
roles: { app_test: "admin" },
firstName: generator.first(),
lastName: generator.last(),

View File

@ -130,5 +130,6 @@
max-width: 150px;
transform: translateX(-50%);
text-align: center;
z-index: 1;
}
</style>

View File

@ -78,7 +78,7 @@
var(--spacing-xl);
}
.property-panel.no-title {
padding: var(--spacing-xl);
padding-top: var(--spacing-xl);
}
.show {

View File

@ -51,15 +51,13 @@
margin-top: var(--spectrum-global-dimension-size-75);
align-items: center;
}
.helpText :global(svg) {
width: 14px;
color: var(--grey-5);
width: 13px;
color: var(--spectrum-global-color-gray-600);
margin-right: 6px;
}
.helpText span {
color: var(--grey-7);
color: var(--spectrum-global-color-gray-800);
font-size: var(--spectrum-global-dimension-font-size-75);
}
</style>

View File

@ -19,7 +19,7 @@
// Ensure the value is updated if the value prop changes outside the editor's
// control
$: checkValue(value)
$: mde?.codemirror.on("change", debouncedUpdate)
$: mde?.codemirror.on("blur", update)
$: if (readonly || disabled) {
mde?.togglePreview()
}
@ -30,21 +30,10 @@
}
}
const debounce = (fn, interval) => {
let timeout
return () => {
clearTimeout(timeout)
timeout = setTimeout(fn, interval)
}
}
const update = () => {
latestValue = mde.value()
dispatch("change", latestValue)
}
// Debounce the update function to avoid spamming it constantly
const debouncedUpdate = debounce(update, 250)
</script>
{#key height}

View File

@ -465,8 +465,8 @@ const filterCategoryByContext = (component, context) => {
const { _component } = component
if (_component.endsWith("formblock")) {
if (
(component.actionType == "Create" && context.type === "schema") ||
(component.actionType == "View" && context.type === "form")
(component.actionType === "Create" && context.type === "schema") ||
(component.actionType === "View" && context.type === "form")
) {
return false
}
@ -474,20 +474,21 @@ const filterCategoryByContext = (component, context) => {
return true
}
// Enrich binding category information for certain components
const getComponentBindingCategory = (component, context, def) => {
let icon = def.icon
let category = component._instanceName
if (component._component.endsWith("formblock")) {
let contextCategorySuffix = {
form: "Fields",
schema: "Row",
if (context.type === "form") {
category = `${component._instanceName} - Fields`
icon = "Form"
} else if (context.type === "schema") {
category = `${component._instanceName} - Row`
icon = "Data"
}
category = `${component._instanceName} - ${
contextCategorySuffix[context.type]
}`
icon = context.type === "form" ? "Form" : "Data"
}
return {
icon,
category,

View File

@ -610,12 +610,12 @@ export const getFrontendStore = () => {
// Use default config if the 'buttons' prop has never been initialised
if (!("buttons" in enrichedComponent)) {
enrichedComponent["buttons"] =
Utils.buildDynamicButtonConfig(enrichedComponent)
Utils.buildFormBlockButtonConfig(enrichedComponent)
migrated = true
} else if (enrichedComponent["buttons"] == null) {
// Ignore legacy config if 'buttons' has been reset by 'resetOn'
const { _id, actionType, dataSource } = enrichedComponent
enrichedComponent["buttons"] = Utils.buildDynamicButtonConfig({
enrichedComponent["buttons"] = Utils.buildFormBlockButtonConfig({
_id,
actionType,
dataSource,
@ -1289,15 +1289,14 @@ export const getFrontendStore = () => {
const settings = getComponentSettings(component._component)
const updatedSetting = settings.find(setting => setting.key === name)
// Can be a single string or array of strings
const resetFields = settings.filter(setting => {
return (
// Reset dependent fields
settings.forEach(setting => {
const needsReset =
name === setting.resetOn ||
(Array.isArray(setting.resetOn) && setting.resetOn.includes(name))
)
})
resetFields?.forEach(setting => {
component[setting.key] = null
if (needsReset) {
component[setting.key] = setting.defaultValue || null
}
})
if (

View File

@ -1,4 +1,4 @@
import { string, number } from "yup"
import { string, number, object } from "yup"
const propertyValidator = type => {
if (type === "number") {
@ -9,6 +9,10 @@ const propertyValidator = type => {
return string().email().nullable()
}
if (type === "object") {
return object().nullable()
}
return string().nullable()
}

View File

@ -53,6 +53,7 @@
export let value = ""
export let placeholder = null
export let autocompleteEnabled = true
export let autofocus = false
// Export a function to expose caret position
export const getCaretPosition = () => {
@ -241,6 +242,12 @@
})
}
$: {
if (autofocus && isEditorInitialised) {
editor.focus()
}
}
$: editorHeight = typeof height === "number" ? `${height}px` : height
// Init when all elements are ready

View File

@ -45,6 +45,7 @@
export let valid
export let allowJS = false
export let allowHelpers = true
export let autofocusEditor = false
const drawerActions = getContext("drawer-actions")
const bindingDrawerActions = getContext("binding-drawer-actions")
@ -199,6 +200,7 @@
]}
placeholder=""
height="100%"
autofocus={autofocusEditor}
/>
</div>
<div class="binding-footer">
@ -301,6 +303,7 @@
bind:getCaretPosition
bind:insertAtPos
height="100%"
autofocus={autofocusEditor}
/>
</div>
<div class="binding-footer">

View File

@ -6,6 +6,7 @@
export let value = ""
export let allowJS = false
export let allowHelpers = true
export let autofocusEditor = false
$: enrichedBindings = enrichBindings(bindings)
@ -27,5 +28,6 @@
{value}
{allowJS}
{allowHelpers}
{autofocusEditor}
on:change
/>

View File

@ -44,7 +44,11 @@
})
const onChange = value => {
if (type === "link" && value && hasValidLinks(value)) {
if (
(type === "link" || type === "bb_reference") &&
value &&
hasValidLinks(value)
) {
currentVal = value.split(",")
} else if (type === "array" && value && hasValidOptions(value)) {
currentVal = value.split(",")
@ -95,6 +99,7 @@
date: isValidDate,
datetime: isValidDate,
link: hasValidLinks,
bb_reference: hasValidLinks,
array: hasValidOptions,
longform: value => !isJSBinding(value),
json: value => !isJSBinding(value),

View File

@ -25,6 +25,8 @@ import BarButtonList from "./controls/BarButtonList.svelte"
import FieldConfiguration from "./controls/FieldConfiguration/FieldConfiguration.svelte"
import ButtonConfiguration from "./controls/ButtonConfiguration/ButtonConfiguration.svelte"
import RelationshipFilterEditor from "./controls/RelationshipFilterEditor.svelte"
import FormStepConfiguration from "./controls/FormStepConfiguration.svelte"
import FormStepControls from "components/design/settings/controls/FormStepControls.svelte"
const componentMap = {
text: DrawerBindableInput,
@ -51,6 +53,8 @@ const componentMap = {
url: URLSelect,
fieldConfiguration: FieldConfiguration,
buttonConfiguration: ButtonConfiguration,
stepConfiguration: FormStepConfiguration,
formStepControls: FormStepControls,
columns: ColumnEditor,
"columns/basic": BasicColumnEditor,
"columns/grid": GridColumnEditor,

View File

@ -34,6 +34,9 @@
$: canAddButtons = max == null || buttonList.length < max
const sanitizeValue = val => {
if (!Array.isArray(val)) {
return null
}
return val?.map(button => {
return button._component ? button : buildPseudoInstance(button)
})

View File

@ -13,6 +13,8 @@
export let draggable = true
export let focus
let zoneType = generate()
let store = writable({
selected: null,
actions: {
@ -46,6 +48,7 @@
return {
id: listItemKey ? item[listItemKey] : generate(),
item,
type: zoneType,
}
})
.filter(item => item.id)
@ -83,6 +86,8 @@
items: draggableItems,
dropTargetStyle: { outline: "none" },
dragDisabled: !draggable || inactive,
type: zoneType,
dropFromOthersDisabled: true,
}}
on:finalize={handleFinalize}
on:consider={updateRowOrder}

View File

@ -14,6 +14,7 @@
import { convertOldFieldFormat, getComponentForField } from "./utils"
export let componentInstance
export let bindings
export let value
const dispatch = createEventDispatcher()
@ -28,7 +29,9 @@
let selectAll = true
$: bindings = getBindableProperties($selectedScreen, componentInstance._id)
$: resolvedBindings =
bindings || getBindableProperties($selectedScreen, componentInstance._id)
$: actionType = componentInstance.actionType
let componentBindings = []
@ -39,7 +42,10 @@
)
}
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: datasource =
componentInstance.dataSource ||
getDatasourceForProvider($currentAsset, componentInstance)
$: resourceId = datasource?.resourceId || datasource?.tableId
$: if (!isEqual(value, cachedValue)) {
@ -179,7 +185,7 @@
listType={FieldSetting}
listTypeProps={{
componentBindings,
bindings,
bindings: resolvedBindings,
}}
/>
{/if}

View File

@ -41,7 +41,7 @@
<div class="filter-editor">
<ActionButton on:click={drawer.show}>{text}</ActionButton>
</div>
<Drawer bind:this={drawer} title="Filtering">
<Drawer bind:this={drawer} title="Filtering" on:drawerHide on:drawerShow>
<Button cta slot="buttons" on:click={saveFilter}>Save</Button>
<FilterDrawer
slot="body"

View File

@ -0,0 +1,171 @@
<script>
import { createEventDispatcher, setContext } from "svelte"
import ComponentSettingsSection from "../../../../pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte"
import { getDatasourceForProvider } from "builderStore/dataBinding"
import { currentAsset, store } from "builderStore"
import { Helpers } from "@budibase/bbui"
import { derived, writable } from "svelte/store"
import { Utils } from "@budibase/frontend-core"
import { cloneDeep } from "lodash"
export let componentInstance
export let componentBindings
export let value
export let bindings
const dispatch = createEventDispatcher()
const multiStepStore = writable({
stepCount: value?.length ?? 0,
currentStep: 0,
})
const currentStep = derived(multiStepStore, state => state.currentStep)
const componentType = "@budibase/standard-components/multistepformblockstep"
setContext("multi-step-form-block", multiStepStore)
$: stepCount = value?.length || 0
$: updateStore(stepCount)
$: dataSource = getDatasourceForProvider($currentAsset, componentInstance)
$: emitCurrentStep($currentStep)
$: stepLabel = getStepLabel($multiStepStore)
$: stepDef = getDefinition(stepLabel)
$: stepSettings = value?.[$currentStep] || {}
$: defaults = Utils.buildMultiStepFormBlockDefaultProps({
_id: componentInstance._id,
stepCount: $multiStepStore.stepCount,
currentStep: $multiStepStore.currentStep,
actionType: componentInstance.actionType,
dataSource: componentInstance.dataSource,
})
$: stepInstance = {
_id: Helpers.uuid(),
_component: componentType,
_instanceName: `Step ${currentStep + 1}`,
title: stepSettings.title ?? defaults.title,
buttons: stepSettings.buttons || defaults.buttons,
fields: stepSettings.fields,
desc: stepSettings.desc,
// Needed for field configuration
dataSource,
}
const getDefinition = stepLabel => {
let def = cloneDeep(store.actions.components.getDefinition(componentType))
def.settings.find(x => x.key === "steps").label = stepLabel
return def
}
const updateStore = stepCount => {
multiStepStore.update(state => {
state.stepCount = stepCount
if (state.currentStep >= stepCount) {
state.currentStep = 0
}
return { ...state }
})
}
const getStepLabel = ({ stepCount, currentStep }) => {
if (stepCount <= 1) {
return "Steps"
}
return `Steps (${currentStep + 1}/${stepCount})`
}
const emitCurrentStep = step => {
store.actions.preview.sendEvent("builder-meta", {
componentId: componentInstance._id,
step: step,
})
}
const addStep = () => {
value = value.toSpliced($currentStep + 1, 0, {})
dispatch("change", value)
multiStepStore.update(state => ({
...state,
currentStep: $currentStep + 1,
}))
}
const removeStep = () => {
value = value.toSpliced($currentStep, 1)
dispatch("change", value)
multiStepStore.update(state => ({
...state,
currentStep: Math.min($currentStep, stepCount - 2),
}))
}
const previousStep = () => {
multiStepStore.update(state => ({
...state,
currentStep: Math.max($currentStep - 1, 0),
}))
}
const nextStep = () => {
multiStepStore.update(state => ({
...state,
currentStep: Math.min($currentStep + 1, value.length - 1),
}))
}
const updateStep = (field, val) => {
const newStep = {
...value[$currentStep],
[field.key]: val,
}
value = value.toSpliced($currentStep, 1, newStep)
dispatch("change", value)
}
const handleStepAction = action => {
switch (action) {
case "addStep":
addStep()
break
case "removeStep":
removeStep()
break
case "nextStep":
nextStep()
break
case "previousStep":
previousStep()
}
}
const processUpdate = (field, val) => {
if (field.key === "steps") {
handleStepAction(val.action)
} else {
updateStep(field, val)
}
}
</script>
<div class="nested-section">
<ComponentSettingsSection
includeHidden
componentInstance={stepInstance}
componentDefinition={stepDef}
onUpdateSetting={processUpdate}
showSectionTitle={false}
isScreen={false}
nested={true}
{bindings}
{componentBindings}
/>
</div>
<style>
.nested-section {
margin: 0 calc(-1 * var(--spacing-xl)) calc(-1 * var(--spacing-xl))
calc(-1 * var(--spacing-xl));
}
.nested-section :global(.property-panel) {
padding-top: 0;
}
</style>

View File

@ -0,0 +1,84 @@
<script>
import { createEventDispatcher, getContext } from "svelte"
import { ActionButton } from "@budibase/bbui"
const multiStepStore = getContext("multi-step-form-block")
const dispatch = createEventDispatcher()
$: ({ stepCount, currentStep } = $multiStepStore)
const stepAction = action => {
dispatch("change", {
action,
})
}
</script>
{#if stepCount === 1}
<div class="stretch">
<ActionButton
icon="MultipleAdd"
secondary
on:click={() => {
stepAction("addStep")
}}
>
Add Step
</ActionButton>
</div>
{:else}
<div class="step-actions">
<ActionButton
size="S"
secondary
icon="ChevronLeft"
disabled={currentStep === 0}
on:click={() => {
stepAction("previousStep")
}}
tooltip={"Previous step"}
/>
<ActionButton
size="S"
secondary
disabled={currentStep === stepCount - 1}
icon="ChevronRight"
on:click={() => {
stepAction("nextStep")
}}
tooltip={"Next step"}
/>
<ActionButton
size="S"
secondary
icon="Close"
disabled={stepCount === 1}
on:click={() => {
stepAction("removeStep")
}}
tooltip={"Remove step"}
/>
<ActionButton
size="S"
secondary
icon="MultipleAdd"
on:click={() => {
stepAction("addStep")
}}
tooltip={"Add step"}
/>
</div>
{/if}
<style>
.stretch :global(.spectrum-ActionButton) {
width: 100%;
}
.step-actions {
display: flex;
gap: var(--spacing-s);
}
.step-actions :global(.spectrum-ActionButton) {
height: 32px;
}
</style>

View File

@ -114,7 +114,7 @@ const getColumns = ({
primary,
sortable,
updateSortable: newDraggableList => {
onChange(toGridFormat(newDraggableList.concat(primary)))
onChange(toGridFormat(newDraggableList.concat(primary || [])))
},
update: newEntry => {
const newDraggableList = draggableList.map(entry => {

View File

@ -25,7 +25,6 @@
</script>
<div class="options-wrap">
<div />
<div><ActionButton on:click={drawer.show}>Define Options</ActionButton></div>
</div>
<Drawer bind:this={drawer} title="Options" on:drawerHide on:drawerShow>

View File

@ -24,6 +24,7 @@
export let propertyFocus = false
export let info = null
export let disableBindings = false
export let wide
$: nullishValue = value == null || value === ""
$: allBindings = getAllBindings(bindings, componentBindings, nested)
@ -78,7 +79,7 @@
<div
class="property-control"
class:wide={!label || labelHidden}
class:wide={!label || labelHidden || wide === true}
class:highlighted={highlighted && nullishValue}
class:property-focus={propertyFocus}
>
@ -104,6 +105,7 @@
{...props}
on:drawerHide
on:drawerShow
on:meta
/>
</div>
{#if info}
@ -146,15 +148,28 @@
.control {
position: relative;
}
.property-control.wide .control {
grid-column: 1 / -1;
}
.text {
font-size: var(--spectrum-global-dimension-font-size-75);
color: var(--grey-6);
grid-column: 2 / 2;
}
.property-control.wide .control {
flex: 1;
}
.property-control.wide {
grid-template-columns: unset;
display: flex;
flex-direction: column;
width: 100%;
}
.property-control.wide > * {
width: 100%;
}
.property-control.wide .text {
grid-column: 1 / -1;
}
.property-control.wide .label {
margin-bottom: -8px;
}
</style>

View File

@ -32,4 +32,4 @@
$: schema = linkedTable?.schema
</script>
<FilterEditor on:change {...$$props} {schema} />
<FilterEditor on:change {...$$props} {schema} on:drawerHide on:drawerShow />

View File

@ -12,7 +12,10 @@
} from "@budibase/bbui"
import { currentAsset, selectedComponent } from "builderStore"
import { findClosestMatchingComponent } from "builderStore/componentUtils"
import { getSchemaForDatasource } from "builderStore/dataBinding"
import {
getSchemaForDatasource,
getDatasourceForProvider,
} from "builderStore/dataBinding"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
import { generate } from "shortid"
@ -124,6 +127,12 @@
],
}
const resolveDatasource = (currentAsset, componentInstance, parent) => {
return (
getDatasourceForProvider(currentAsset, parent || componentInstance) || {}
)
}
$: dataSourceSchema = getDataSourceSchema($currentAsset, $selectedComponent)
$: field = fieldName || $selectedComponent?.field
$: schemaRules = parseRulesFromSchema(field, dataSourceSchema || {})
@ -146,8 +155,8 @@
component._component.endsWith("/formblock") ||
component._component.endsWith("/tableblock")
)
return getSchemaForDatasource(asset, formParent?.dataSource)
const dataSource = resolveDatasource(asset, component, formParent)
return getSchemaForDatasource(asset, dataSource)
}
const parseRulesFromSchema = (field, dataSourceSchema) => {

View File

@ -38,7 +38,7 @@
$goto("../portal")
} catch (error) {
submitted = false
notifications.error("Failed to create admin user")
notifications.error(error.message || "Failed to create admin user")
}
}
</script>

View File

@ -32,21 +32,19 @@
const generalSettings = settings.filter(
setting => !setting.section && setting.tag === tag
)
const customSections = settings.filter(
setting => setting.section && setting.tag === tag
)
let sections = [
...(generalSettings?.length
? [
{
name: "General",
settings: generalSettings,
},
]
: []),
...(customSections || []),
]
let sections = []
if (generalSettings.length) {
sections.push({
name: "General",
settings: generalSettings,
})
}
if (customSections.length) {
sections = sections.concat(customSections)
}
// Filter out settings which shouldn't be rendered
sections.forEach(section => {
@ -153,6 +151,7 @@
<DetailSummary
name={showSectionTitle ? section.name : ""}
initiallyShow={section.collapsed !== true}
collapsible={section.name !== "General"}
>
{#if section.info}
<div class="section-info">
@ -172,6 +171,7 @@
control={getComponentForSetting(setting)}
label={setting.label}
labelHidden={setting.labelHidden}
wide={setting.wide}
key={setting.key}
value={componentInstance[setting.key]}
defaultValue={setting.defaultValue}
@ -208,7 +208,7 @@
</DetailSummary>
{/if}
{/each}
{#if componentDefinition?.block && !tag}
{#if componentDefinition?.block && !tag && componentDefinition.ejectable !== false}
<DetailSummary name="Eject" collapsible={false}>
<EjectBlockButton />
</DetailSummary>

View File

@ -64,6 +64,7 @@
on:change={event => (tempValue = event.detail)}
allowJS
{bindings}
autofocusEditor={true}
/>
</Drawer>
{/key}

View File

@ -8,6 +8,7 @@
"cardsblock",
"repeaterblock",
"formblock",
"multistepformblock",
"chartblock",
"rowexplorer"
]

View File

@ -45,7 +45,7 @@
}
} catch (err) {
submitted = false
notifications.error("Unable to reset password")
notifications.error(err.message || "Unable to reset password")
}
}

View File

@ -5,7 +5,6 @@ build/
docker-error.log
envoy.yaml
*.tar.gz
prebuilds/
dist/
budibase-automation/
budibase-component/

View File

@ -9,26 +9,11 @@
"author": "Budibase",
"license": "GPL-3.0",
"scripts": {
"prebuild": "rm -rf prebuilds 2> /dev/null && cp -r ../../node_modules/leveldown/prebuilds prebuilds",
"rename": "renamer --find .node --replace .fake 'prebuilds/**'",
"tsc": "node ../../scripts/build.js",
"pkg": "pkg . --out-path build --no-bytecode --public --public-packages \"*\" -C GZip",
"build": "yarn prebuild && yarn rename && yarn tsc && yarn pkg && yarn postbuild",
"build": "yarn tsc",
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
"postbuild": "rm -rf prebuilds 2> /dev/null",
"start": "ts-node ./src/index.ts"
},
"pkg": {
"targets": [
"node18-linux",
"node18-win",
"node18-macos"
],
"assets": [
"prebuilds/**/*"
],
"outputPath": "build"
},
"dependencies": {
"@budibase/backend-core": "0.0.0",
"@budibase/string-templates": "0.0.0",
@ -43,7 +28,6 @@
"inquirer": "8.0.0",
"lookpath": "1.1.0",
"node-fetch": "2.6.7",
"pkg": "5.8.0",
"posthog-node": "1.3.0",
"pouchdb": "7.3.0",
"pouchdb-replication-stream": "1.2.9",
@ -55,7 +39,6 @@
"@types/jest": "29.5.5",
"@types/node-fetch": "2.6.4",
"@types/pouchdb": "^6.4.0",
"renamer": "^4.0.0",
"ts-node": "10.8.1",
"typescript": "5.2.2"
}

View File

@ -1,10 +1,9 @@
#!/usr/bin/env node
process.env.DISABLE_PINO_LOGGER = "1"
import "./prebuilds"
import "./environment"
import { getCommands } from "./options"
import { Command } from "commander"
import { getHelpDescription } from "./utils"
import { getHelpDescription, error } from "./utils"
import { version } from "../package.json"
// add hosting config
@ -21,6 +20,23 @@ async function init() {
await program.parseAsync(process.argv)
}
const events = ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException"]
events.forEach(event => {
process.on(event, (evt?: number) => {
if (evt && !isNaN(evt)) {
return
}
if (evt) {
console.error(
error(
"Failed to run CLI command - please report with the following message:"
)
)
console.error(error(evt))
}
})
})
init().catch(err => {
console.error(`Unexpected error - `, err)
})

View File

@ -1,57 +0,0 @@
import os from "os"
import { join } from "path"
import fs from "fs"
import { error } from "./utils"
const PREBUILDS = "prebuilds"
const ARCH = `${os.platform()}-${os.arch()}`
const PREBUILD_DIR = join(process.execPath, "..", "cli", PREBUILDS, ARCH)
// running as built CLI pkg bundle
if (!process.argv[0].includes("node")) {
checkForBinaries()
}
function localPrebuildPath() {
return join(process.execPath, "..", PREBUILDS)
}
function checkForBinaries() {
const readDir = join(__filename, "..", "..", "..", "cli", PREBUILDS, ARCH)
if (fs.existsSync(PREBUILD_DIR) || !fs.existsSync(readDir)) {
return
}
const natives = fs.readdirSync(readDir)
if (fs.existsSync(readDir)) {
const writePath = join(localPrebuildPath(), ARCH)
fs.mkdirSync(writePath, { recursive: true })
for (let native of natives) {
const filename = `${native.split(".fake")[0]}.node`
fs.cpSync(join(readDir, native), join(writePath, filename))
}
}
}
function cleanup(evt?: number) {
// cleanup prebuilds first
const path = localPrebuildPath()
if (fs.existsSync(path)) {
fs.rmSync(path, { recursive: true })
}
if (evt && !isNaN(evt)) {
return
}
if (evt) {
console.error(
error(
"Failed to run CLI command - please report with the following message:"
)
)
console.error(error(evt))
}
}
const events = ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException"]
events.forEach(event => {
process.on(event, cleanup)
})

View File

@ -3295,6 +3295,7 @@
},
{
"type": "options",
"label": "Custom options",
"key": "customOptions",
"dependsOn": {
"setting": "optionsSource",
@ -3502,6 +3503,7 @@
},
{
"type": "options",
"label": "Custom options",
"key": "customOptions",
"dependsOn": {
"setting": "optionsSource",
@ -4877,7 +4879,7 @@
},
"chartblock": {
"block": true,
"name": "Chart block",
"name": "Chart Block",
"icon": "GraphPie",
"hasChildren": false,
"settings": [
@ -5367,7 +5369,7 @@
},
"tableblock": {
"block": true,
"name": "Table block",
"name": "Table Block",
"icon": "Table",
"styles": ["size"],
"size": {
@ -5613,7 +5615,7 @@
},
"cardsblock": {
"block": true,
"name": "Cards block",
"name": "Cards Block",
"icon": "PersonalizationField",
"styles": ["size"],
"size": {
@ -5793,7 +5795,7 @@
},
"repeaterblock": {
"block": true,
"name": "Repeater block",
"name": "Repeater Block",
"icon": "ViewList",
"illegalChildren": ["section"],
"hasChildren": true,
@ -6033,6 +6035,164 @@
}
]
},
"multistepformblock": {
"name": "Multi-step Form Block",
"icon": "AssetsAdded",
"block": true,
"hasChildren": false,
"ejectable": false,
"size": {
"width": 400,
"height": 400
},
"styles": ["size"],
"settings": [
{
"type": "table",
"label": "Data",
"key": "dataSource"
},
{
"type": "radio",
"label": "Type",
"key": "actionType",
"options": ["Create", "Update", "View"],
"defaultValue": "Create"
},
{
"section": true,
"dependsOn": {
"setting": "actionType",
"value": "Create",
"invert": true
},
"name": "Row ID",
"info": "<a href='https://docs.budibase.com/docs/form-block' target='_blank'>How to pass a row ID using bindings</a>",
"settings": [
{
"type": "text",
"label": "Row ID",
"key": "rowId",
"nested": true
},
{
"type": "text",
"label": "No rows found",
"key": "noRowsMessage",
"defaultValue": "We couldn't find a row to display",
"nested": true
}
]
},
{
"section": true,
"name": "Details",
"settings": [
{
"type": "stepConfiguration",
"key": "steps",
"nested": true,
"labelHidden": true,
"resetOn": [
"dataSource",
"actionType"
],
"defaultValue": [
{}
]
}
]
}
],
"actions": [
{
"type": "ValidateForm",
"suffix": "form"
},
{
"type": "ClearForm",
"suffix": "form"
},
{
"type": "UpdateFieldValue",
"suffix": "form"
},
{
"type": "ScrollTo",
"suffix": "form"
},
{
"type": "ChangeFormStep",
"suffix": "form"
}
],
"context": [
{
"type": "form",
"suffix": "form"
},
{
"type": "static",
"suffix": "form",
"values": [
{
"label": "Value",
"key": "__value",
"type": "object"
},
{
"label": "Valid",
"key": "__valid",
"type": "boolean"
},
{
"label": "Current Step",
"key": "__currentStep",
"type": "number"
},
{
"label": "Current Step Valid",
"key": "__currentStepValid",
"type": "boolean"
}
]
}
]
},
"multistepformblockstep": {
"name": "Multi-step Form Block Step",
"settings": [
{
"type": "formStepControls",
"label": "Steps",
"key": "steps"
},
{
"type": "text",
"label": "Title",
"key": "title",
"nested": true
},
{
"type": "text",
"label": "Description",
"key": "desc",
"nested": true
},
{
"type": "fieldConfiguration",
"key": "fields",
"nested": true
},
{
"type": "buttonConfiguration",
"label": "Buttons",
"key": "buttons",
"wide": true,
"nested": true
}
]
},
"formblock": {
"name": "Form Block",
"icon": "Form",
@ -6288,7 +6448,7 @@
}
},
"gridblock": {
"name": "Grid block",
"name": "Grid Block",
"icon": "Table",
"styles": ["size"],
"size": {

View File

@ -0,0 +1,204 @@
<script>
import BlockComponent from "components/BlockComponent.svelte"
import { getContext, setContext } from "svelte"
import { builderStore } from "stores"
import { Utils } from "@budibase/frontend-core"
import FormBlockWrapper from "./form/FormBlockWrapper.svelte"
import { writable } from "svelte/store"
export let actionType
export let rowId
export let noRowsMessage
export let steps
export let dataSource
const { fetchDatasourceSchema } = getContext("sdk")
const component = getContext("component")
const context = getContext("context")
// Set current step context to force child form to use it
const currentStep = writable(1)
setContext("current-step", currentStep)
const FieldTypeToComponentMap = {
string: "stringfield",
number: "numberfield",
bigint: "bigintfield",
options: "optionsfield",
array: "multifieldselect",
boolean: "booleanfield",
longform: "longformfield",
datetime: "datetimefield",
attachment: "attachmentfield",
link: "relationshipfield",
json: "jsonfield",
barcodeqr: "codescanner",
bb_reference: "bbreferencefield",
}
let schema
$: fetchSchema(dataSource)
$: enrichedSteps = enrichSteps(steps, schema, $component.id)
$: updateCurrentStep(enrichedSteps, $builderStore, $component)
const updateCurrentStep = (steps, builderStore, component) => {
const { componentId, step } = builderStore.metadata || {}
// If we aren't in the builder or aren't selected then don't update the step
// context at all, allowing the normal form to take control.
if (
!component.selected ||
!builderStore.inBuilder ||
componentId !== component.id
) {
return
}
// Ensure we have a valid step selected
let newStep = Math.min(step || 0, steps.length - 1)
// Sanity check
newStep = Math.max(newStep, 0)
// Add 1 because the form component expects 1 indexed rather than 0 indexed
currentStep.set(newStep + 1)
}
const getPropsForField = field => {
if (field._component) {
return field
}
return {
field: field.name,
label: field.name,
placeholder: field.name,
_instanceName: field.name,
}
}
const getComponentForField = field => {
const fieldSchemaName = field.field || field.name
if (!fieldSchemaName || !schema?.[fieldSchemaName]) {
return null
}
const type = schema[fieldSchemaName].type
return FieldTypeToComponentMap[type]
}
const fetchSchema = async () => {
schema = (await fetchDatasourceSchema(dataSource)) || {}
}
const getDefaultFields = (fields, schema) => {
if (fields?.length) {
return fields.filter(field => field.active)
}
return Object.values(schema || {})
.filter(field => !field.autocolumn)
.map(field => ({
name: field.name,
}))
}
const enrichSteps = (steps, schema, id) => {
const safeSteps = steps?.length ? steps : [{}]
return safeSteps.map((step, idx) => {
const { title, desc, fields, buttons } = step
const defaultProps = Utils.buildMultiStepFormBlockDefaultProps({
_id: id,
stepCount: safeSteps.length,
currentStep: idx,
actionType,
dataSource,
})
return {
fields: getDefaultFields(fields || [], schema),
title: title ?? defaultProps.title,
desc,
buttons: buttons || defaultProps.buttons,
}
})
}
</script>
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
<BlockComponent
type="form"
context="form"
props={{
dataSource,
actionType: actionType === "Create" ? "Create" : "Update",
readonly: actionType === "View",
}}
styles={{
normal: {
width: "600px",
"margin-left": "auto",
"margin-right": "auto",
},
}}
>
{#each enrichedSteps as step, stepIdx}
<BlockComponent
type="formstep"
props={{ step: stepIdx + 1, _instanceName: `Step ${stepIdx + 1}` }}
>
<BlockComponent
type="container"
props={{
gap: "M",
direction: "column",
hAlign: "stretch",
vAlign: "top",
size: "shrink",
}}
>
<BlockComponent type="container" order={0}>
<BlockComponent type="heading" props={{ text: step.title }} />
</BlockComponent>
<BlockComponent type="text" props={{ text: step.desc }} order={1} />
<BlockComponent type="container" order={2}>
<div
class="form-block fields"
class:mobile={$context.device.mobile}
>
{#each step.fields as field, fieldIdx (`${field.field || field.name}_${stepIdx}_${fieldIdx}`)}
{#if getComponentForField(field)}
<BlockComponent
type={getComponentForField(field)}
props={getPropsForField(field)}
order={fieldIdx}
interactive
name={field.field}
/>
{/if}
{/each}
</div>
</BlockComponent>
<BlockComponent
type="buttongroup"
props={{ buttons: step.buttons }}
styles={{
normal: {
"margin-top": "16px",
},
}}
order={3}
/>
</BlockComponent>
</BlockComponent>
{/each}
</BlockComponent>
</FormBlockWrapper>
<style>
.fields {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 8px 16px;
}
.fields.mobile :global(.spectrum-Form-item) {
grid-column: span 6 !important;
}
</style>

View File

@ -265,7 +265,7 @@
props={{
dataSource,
buttonPosition: "top",
buttons: Utils.buildDynamicButtonConfig({
buttons: Utils.buildFormBlockButtonConfig({
_id: $component.id + "-form-edit",
showDeleteButton: deleteLabel !== "",
showSaveButton: true,
@ -299,7 +299,7 @@
props={{
dataSource,
buttonPosition: "top",
buttons: Utils.buildDynamicButtonConfig({
buttons: Utils.buildFormBlockButtonConfig({
_id: $component.id + "-form-new",
showDeleteButton: false,
showSaveButton: true,

View File

@ -1,10 +1,8 @@
<script>
import { getContext } from "svelte"
import BlockComponent from "components/BlockComponent.svelte"
import Block from "components/Block.svelte"
import { makePropSafe as safe } from "@budibase/string-templates"
import InnerFormBlock from "./InnerFormBlock.svelte"
import { Utils } from "@budibase/frontend-core"
import FormBlockWrapper from "./FormBlockWrapper.svelte"
export let actionType
export let dataSource
@ -71,22 +69,10 @@
}
let schema
let providerId
let repeaterId
$: formattedFields = convertOldFieldFormat(fields)
$: fieldsOrDefault = getDefaultFields(formattedFields, schema)
$: fetchSchema(dataSource)
$: dataProvider = `{{ literal ${safe(providerId)} }}`
$: filter = [
{
field: "_id",
operator: "equal",
type: "string",
value: !rowId ? `{{ ${safe("url")}.${safe("id")} }}` : rowId,
valueType: "Binding",
},
]
// We could simply spread $$props into the inner form and append our
// additions, but that would create svelte warnings about unused props and
// make maintenance in future more confusing as we typically always have a
@ -102,11 +88,10 @@
title,
description,
schema,
repeaterId,
notificationOverride,
buttons:
buttons ||
Utils.buildDynamicButtonConfig({
Utils.buildFormBlockButtonConfig({
_id: $component.id,
showDeleteButton,
showSaveButton,
@ -124,43 +109,6 @@
}
</script>
<Block>
{#if actionType === "Create"}
<BlockComponent
type="container"
props={{
direction: "column",
hAlign: "left",
vAlign: "stretch",
}}
>
<InnerFormBlock {...innerProps} />
</BlockComponent>
{:else}
<BlockComponent
type="dataprovider"
context="provider"
bind:id={providerId}
props={{
dataSource,
filter,
limit: 1,
paginate: false,
}}
>
<BlockComponent
type="repeater"
context="repeater"
bind:id={repeaterId}
props={{
dataProvider,
noRowsMessage: noRowsMessage || "We couldn't find a row to display",
direction: "column",
hAlign: "center",
}}
>
<InnerFormBlock {...innerProps} />
</BlockComponent>
</BlockComponent>
{/if}
</Block>
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
<InnerFormBlock {...innerProps} />
</FormBlockWrapper>

View File

@ -0,0 +1,64 @@
<script>
import BlockComponent from "components/BlockComponent.svelte"
import Block from "components/Block.svelte"
import { makePropSafe as safe } from "@budibase/string-templates"
import { getContext } from "svelte"
export let actionType
export let dataSource
export let rowId
export let noRowsMessage
const component = getContext("component")
$: providerId = `${$component.id}-provider`
$: dataProvider = `{{ literal ${safe(providerId)} }}`
$: filter = [
{
field: "_id",
operator: "equal",
type: "string",
value: !rowId ? `{{ ${safe("url")}.${safe("id")} }}` : rowId,
valueType: "Binding",
},
]
</script>
<Block>
{#if actionType === "Create"}
<BlockComponent
type="container"
props={{
direction: "column",
hAlign: "left",
vAlign: "stretch",
}}
>
<slot />
</BlockComponent>
{:else}
<BlockComponent
type="dataprovider"
context="provider"
props={{
dataSource,
filter,
limit: 1,
paginate: false,
}}
>
<BlockComponent
type="repeater"
context="repeater"
props={{
dataProvider,
noRowsMessage: noRowsMessage || "We couldn't find a row to display",
direction: "column",
hAlign: "center",
}}
>
<slot />
</BlockComponent>
</BlockComponent>
{/if}
</Block>

View File

@ -4,3 +4,4 @@ export { default as repeaterblock } from "./RepeaterBlock.svelte"
export { default as formblock } from "./form/FormBlock.svelte"
export { default as chartblock } from "./ChartBlock.svelte"
export { default as rowexplorer } from "./RowExplorer.svelte"
export { default as multistepformblock } from "./MultiStepFormblock.svelte"

View File

@ -137,21 +137,23 @@
width: 100%;
}
.error :global(svg),
.helpText :global(svg) {
width: 13px;
margin-right: 6px;
}
.error {
display: flex;
margin-top: var(--spectrum-global-dimension-size-75);
align-items: center;
}
.error :global(svg) {
width: 14px;
color: var(
--spectrum-semantic-negative-color-default,
var(--spectrum-global-color-red-500)
);
margin-right: 4px;
}
.error span {
color: var(
--spectrum-semantic-negative-color-default,
@ -165,17 +167,14 @@
margin-top: var(--spectrum-global-dimension-size-75);
align-items: center;
}
.helpText :global(svg) {
width: 14px;
color: var(--grey-7);
margin-right: 6px;
color: var(--spectrum-global-color-gray-600);
}
.helpText span {
color: var(--grey-5);
color: var(--spectrum-global-color-gray-800);
font-size: var(--spectrum-global-dimension-font-size-75);
}
.spectrum-FieldLabel--right,
.spectrum-FieldLabel--left {
padding-right: var(--spectrum-global-dimension-size-200);

View File

@ -34,7 +34,7 @@
let loaded = false
let schema
let table
let currentStep = writable(getInitialFormStep())
let currentStep = getContext("current-step") || writable(getInitialFormStep())
$: fetchSchema(dataSource)
$: schemaKey = generateSchemaKey(schema)

View File

@ -423,10 +423,14 @@
}
const fieldId = field.fieldState.fieldId
const fieldElement = document.getElementById(fieldId)
fieldElement.focus({ preventScroll: true })
if (fieldElement) {
fieldElement.focus({ preventScroll: true })
}
const label = document.querySelector(`label[for="${fieldId}"]`)
label.style.scrollMargin = "100px"
label.scrollIntoView({ behavior: "smooth", block: "nearest" })
if (label) {
label.style.scrollMargin = "100px"
label.scrollIntoView({ behavior: "smooth", block: "nearest" })
}
}
// Action context to pass to children

View File

@ -76,6 +76,8 @@ const loadBudibase = async () => {
} else {
dndStore.actions.reset()
}
} else if (type === "builder-meta") {
builderStore.actions.setMetadata(data)
}
}

View File

@ -18,6 +18,7 @@ const createBuilderStore = () => {
hiddenComponentIds: [],
usedPlugins: null,
eventResolvers: {},
metadata: null,
// Legacy - allow the builder to specify a layout
layout: null,
@ -123,6 +124,12 @@ const createBuilderStore = () => {
parentType,
})
},
setMetadata: metadata => {
store.update(state => ({
...state,
metadata,
}))
},
}
return {
...store,

View File

@ -116,7 +116,7 @@ export const domDebounce = callback => {
*
* @param {any} props
* */
export const buildDynamicButtonConfig = props => {
export const buildFormBlockButtonConfig = props => {
const {
_id,
actionType,
@ -130,7 +130,6 @@ export const buildDynamicButtonConfig = props => {
} = props || {}
if (!_id) {
console.log("MISSING ID")
return
}
const formId = `${_id}-form`
@ -228,7 +227,7 @@ export const buildDynamicButtonConfig = props => {
})
}
if (actionType == "Update" && showDeleteButton !== false) {
if (actionType === "Update" && showDeleteButton !== false) {
defaultButtons.push({
text: deleteText || "Delete",
_id: Helpers.uuid(),
@ -241,3 +240,108 @@ export const buildDynamicButtonConfig = props => {
return defaultButtons
}
export const buildMultiStepFormBlockDefaultProps = props => {
const { _id, stepCount, currentStep, actionType, dataSource } = props || {}
// Sanity check
if (!_id || !stepCount) {
return
}
const title = `Step {{ [${_id}-form].[__currentStep] }}`
const resourceId = dataSource?.resourceId
const formId = `${_id}-form`
let buttons = []
// Add previous step button if we aren't the first step
if (currentStep !== 0) {
buttons.push({
_id: Helpers.uuid(),
_component: "@budibase/standard-components/button",
_instanceName: Helpers.uuid(),
text: "Back",
type: "secondary",
size: "M",
onClick: [
{
parameters: {
type: "prev",
componentId: formId,
},
"##eventHandlerType": "Change Form Step",
},
],
})
}
// Add a next button if we aren't the last step
if (currentStep !== stepCount - 1) {
buttons.push({
_id: Helpers.uuid(),
_component: "@budibase/standard-components/button",
_instanceName: Helpers.uuid(),
text: "Next",
type: "cta",
size: "M",
onClick: [
{
"##eventHandlerType": "Validate Form",
parameters: {
componentId: formId,
},
},
{
parameters: {
type: "next",
componentId: formId,
},
"##eventHandlerType": "Change Form Step",
},
],
})
}
// Add save button if we are the last step
if (actionType !== "View" && currentStep === stepCount - 1) {
buttons.push({
_id: Helpers.uuid(),
_component: "@budibase/standard-components/button",
_instanceName: Helpers.uuid(),
text: "Save",
type: "cta",
size: "M",
onClick: [
{
"##eventHandlerType": "Validate Form",
parameters: {
componentId: formId,
},
},
{
"##eventHandlerType": "Save Row",
parameters: {
tableId: resourceId,
providerId: formId,
},
},
// Clear a create form once submitted
...(actionType !== "Create"
? []
: [
{
"##eventHandlerType": "Clear Form",
parameters: {
componentId: formId,
},
},
]),
],
})
}
return {
buttons,
title,
}
}

@ -1 +1 @@
Subproject commit 992486c10044a7495496b97bdf5f454d4020bfba
Subproject commit b1c10c2daf808d103724c324256cbff67f33fb46

View File

@ -1,4 +1,4 @@
FROM node:18-slim
FROM node:20-slim
LABEL com.centurylinklabs.watchtower.lifecycle.pre-check="scripts/watchtower-hooks/pre-check.sh"
LABEL com.centurylinklabs.watchtower.lifecycle.pre-update="scripts/watchtower-hooks/pre-update.sh"

View File

@ -86,7 +86,7 @@
"lodash": "4.17.21",
"memorystream": "0.3.1",
"mongodb": "5.7",
"mssql": "9.1.1",
"mssql": "10.0.1",
"mysql2": "3.5.2",
"node-fetch": "2.6.7",
"object-sizeof": "2.6.1",
@ -121,8 +121,7 @@
"@types/koa": "2.13.4",
"@types/koa__router": "8.0.8",
"@types/lodash": "4.14.200",
"@types/mssql": "8.1.2",
"@types/node": "18.17.0",
"@types/mssql": "9.1.4",
"@types/node-fetch": "2.6.4",
"@types/oracledb": "5.2.2",
"@types/pg": "8.6.6",

View File

@ -48,6 +48,7 @@ async function init() {
HTTP_MIGRATIONS: "0",
HTTP_LOGGING: "0",
VERSION: "0.0.0+local",
PASSWORD_MIN_LENGTH: "1",
}
config = { ...config, ...existingConfig }

View File

@ -0,0 +1,196 @@
#!/bin/node
const {
createApp,
getTable,
createRow,
createTable,
getApp,
getRows,
} = require("./utils")
const Chance = require("chance")
const generator = new Chance()
const STUDENT_COUNT = 500
const SUBJECT_COUNT = 10
let { apiKey, appId } = require("yargs")
.demandOption(["apiKey"])
.option("appId").argv
const start = Date.now()
async function batchCreate(apiKey, appId, table, items, batchSize = 100) {
let i = 0
let errors = 0
async function createSingleRow(item) {
try {
const row = await createRow(apiKey, appId, table, item)
console.log(
`${table.name} - ${++i} of ${items.length} created (${
(Date.now() - start) / 1000
}s)`
)
return row
} catch {
errors++
}
}
const rows = []
const maxConcurrency = Math.min(batchSize, items.length)
const inFlight = {}
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const item = items[itemIndex]
const promise = createSingleRow(item)
.then(result => {
rows.push(result)
})
.finally(() => {
delete inFlight[itemIndex]
})
inFlight[itemIndex] = promise
if (Object.keys(inFlight).length >= maxConcurrency) {
await Promise.race(Object.values(inFlight))
}
}
await Promise.all(Object.values(inFlight))
if (errors) {
console.error(
`${table.name} - ${errors} creation errored (${
(Date.now() - start) / 1000
}s)`
)
}
return rows
}
const useExistingApp = !!appId
async function upsertTable(appId, tableName, tableData) {
if (useExistingApp) {
return await getTable(apiKey, appId, tableName)
}
const table = await createTable(apiKey, appId, {
...tableData,
name: tableName,
})
return table
}
async function run() {
if (!appId) {
const app = appId ? await getApp(apiKey, appId) : await createApp(apiKey)
appId = app._id
console.log(`App created. Url: http://localhost:10000/builder/app/${appId}`)
} else {
console.log(
`App retrieved. Url: http://localhost:10000/builder/app/${appId}`
)
}
const studentsTable = await getTable(apiKey, appId, "Students")
let studentNumber = studentsTable.schema["Auto ID"].lastID
const students = await batchCreate(
apiKey,
appId,
studentsTable,
Array.from({ length: STUDENT_COUNT }).map(() => ({
"Student Number": (++studentNumber).toString(),
"First Name": generator.first(),
"Last Name": generator.last(),
Gender: generator.pickone(["M", "F"]),
Grade: generator.pickone(["8", "9", "10", "11"]),
"Tardiness (Days)": generator.integer({ min: 1, max: 100 }),
"Home Number": generator.phone(),
"Attendance_(%)": generator.integer({ min: 0, max: 100 }),
}))
)
const subjectTable = await upsertTable(appId, "Subjects", {
schema: {
Name: {
name: "Name",
type: "string",
},
},
primaryDisplay: "Name",
})
const subjects = useExistingApp
? await getRows(apiKey, appId, subjectTable._id)
: await batchCreate(
apiKey,
appId,
subjectTable,
Array.from({ length: SUBJECT_COUNT }).map(() => ({
Name: generator.profession(),
}))
)
const gradesTable = await upsertTable(appId, "Grades", {
schema: {
Score: {
name: "Score",
type: "number",
},
Student: {
name: "Student",
tableId: studentsTable._id,
constraints: {
presence: true,
type: "array",
},
fieldName: "Grades",
relationshipType: "one-to-many",
type: "link",
},
Subject: {
name: "Subject",
tableId: subjectTable._id,
constraints: {
presence: true,
type: "array",
},
fieldName: "Grades",
relationshipType: "one-to-many",
type: "link",
},
},
})
await batchCreate(
apiKey,
appId,
gradesTable,
students.flatMap(student =>
subjects.map(subject => ({
Score: generator.integer({ min: 0, max: 100 }),
Student: [student],
Subject: [subject],
}))
)
)
console.log(
`Access the app here: http://localhost:10000/builder/app/${appId}`
)
}
run()
.then(() => {
console.log(`Done in ${(Date.now() - start) / 1000} seconds`)
})
.catch(err => {
console.error(err)
})

View File

@ -0,0 +1,29 @@
#!/bin/node
const { searchApps, deleteApp } = require("./utils")
if (!process.argv[2]) {
console.error("Please specify an API key as script argument.")
process.exit(-1)
}
async function run() {
const apiKey = process.argv[2]
const apps = await searchApps(apiKey)
console.log(`Deleting ${apps.length} apps`)
let deletedApps = 0
await Promise.all(
apps.map(async app => {
await deleteApp(apiKey, app._id)
console.log(`App ${++deletedApps} of ${apps.length} deleted`)
})
)
}
run()
.then(() => {
console.log("Done!")
})
.catch(err => {
console.error(err)
})

View File

@ -2,7 +2,8 @@ const fetch = require("node-fetch")
const uuid = require("uuid/v4")
const URL_APP = "http://localhost:10000/api/public/v1/applications"
const URL_TABLE = "http://localhost:10000/api/public/v1/tables/search"
const URL_TABLE = "http://localhost:10000/api/public/v1/tables"
const URL_SEARCH_TABLE = "http://localhost:10000/api/public/v1/tables/search"
async function request(apiKey, url, method, body, appId = undefined) {
const headers = {
@ -37,30 +38,64 @@ exports.createApp = async apiKey => {
return json.data
}
exports.getTable = async (apiKey, appId) => {
const res = await request(apiKey, URL_TABLE, "POST", {}, appId)
exports.getApp = async (apiKey, appId) => {
const res = await request(apiKey, `${URL_APP}/${appId}`, "GET")
const json = await res.json()
return json.data[0]
return json.data
}
exports.searchApps = async apiKey => {
const res = await request(apiKey, `${URL_APP}/search`, "POST", {})
const json = await res.json()
return json.data
}
exports.createRow = async (apiKey, appId, table) => {
const body = {}
for (let [key, schema] of Object.entries(table.schema)) {
let fake
switch (schema.type) {
default:
case "string":
fake = schema.constraints.inclusion
? schema.constraints.inclusion[0]
: "a"
break
case "number":
fake = 1
break
exports.deleteApp = async (apiKey, appId) => {
const res = await request(apiKey, `${URL_APP}/${appId}`, "DELETE")
return res
}
exports.getTable = async (apiKey, appId, tableName) => {
const res = await request(apiKey, URL_SEARCH_TABLE, "POST", {}, appId)
const json = await res.json()
const table = json.data.find(t => t.name === tableName)
if (!table) {
throw `Table '${tableName} not found`
}
return table
}
exports.createRow = async (apiKey, appId, table, body) => {
if (!body) {
body = {}
for (let [key, schema] of Object.entries(table.schema)) {
let fake
switch (schema.type) {
default:
case "string":
fake = schema.constraints?.inclusion
? schema.constraints.inclusion[0]
: "a"
break
case "number":
fake = 1
break
}
body[key] = fake
}
body[key] = fake
}
const url = `http://localhost:10000/api/public/v1/tables/${table._id}/rows`
const res = await request(apiKey, url, "POST", body, appId)
return (await res.json()).data
}
exports.getRows = async (apiKey, appId, tableId) => {
const url = `${URL_TABLE}/${tableId}/rows/search`
const res = await request(apiKey, url, "POST", {}, appId)
return (await res.json()).data
}
exports.createTable = async (apiKey, appId, config) => {
const res = await request(apiKey, URL_TABLE, "POST", config, appId)
const json = await res.json()
return json.data
}

View File

@ -161,11 +161,8 @@ export async function preview(ctx: UserCtx) {
auth: { ...authConfigCtx },
},
}
const runFn = () => Runner.run(inputs)
const { rows, keys, info, extra } = await quotas.addQuery<any>(runFn, {
datasourceId: datasource._id,
})
const { rows, keys, info, extra } = (await Runner.run(inputs)) as any
const schemaFields: any = {}
if (rows?.length > 0) {
for (let key of [...new Set(keys)] as string[]) {
@ -259,14 +256,8 @@ async function execute(
},
schema: query.schema,
}
const runFn = () => Runner.run(inputs)
const { rows, pagination, extra, info } = await quotas.addQuery<any>(
runFn,
{
datasourceId: datasource._id,
}
)
const { rows, pagination, extra, info } = (await Runner.run(inputs)) as any
// remove the raw from execution incase transformer being used to hide data
if (extra?.raw) {
delete extra.raw

View File

@ -26,7 +26,7 @@ import {
inputProcessing,
outputProcessing,
} from "../../../utilities/rowProcessor"
import { cloneDeep, isEqual } from "lodash"
import { cloneDeep } from "lodash"
export async function handleRequest<T extends Operation>(
operation: T,
@ -86,50 +86,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
}
}
export async function save(ctx: UserCtx) {
const inputs = ctx.request.body
const tableId = utils.getTableId(ctx)
const table = await sdk.tables.getTable(tableId)
const { table: updatedTable, row } = await inputProcessing(
ctx.user?._id,
cloneDeep(table),
inputs
)
const validateResult = await sdk.rows.utils.validate({
row,
tableId,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
const response = await handleRequest(Operation.CREATE, tableId, {
row,
})
if (!isEqual(table, updatedTable)) {
await sdk.tables.saveTable(updatedTable)
}
const rowId = response.row._id
if (rowId) {
const row = await sdk.rows.external.getRow(tableId, rowId, {
relationships: true,
})
return {
...response,
row: await outputProcessing(table, row, {
preserveLinks: true,
squash: true,
}),
}
} else {
return response
}
}
export async function find(ctx: UserCtx): Promise<Row> {
const id = ctx.params.rowId
const tableId = utils.getTableId(ctx)

View File

@ -4,20 +4,20 @@ import * as external from "./external"
import { isExternalTableID } from "../../../integrations/utils"
import {
Ctx,
UserCtx,
DeleteRowRequest,
DeleteRow,
DeleteRowRequest,
DeleteRows,
Row,
PatchRowRequest,
PatchRowResponse,
SearchRowResponse,
SearchRowRequest,
SearchParams,
GetRowResponse,
ValidateResponse,
ExportRowsRequest,
ExportRowsResponse,
GetRowResponse,
PatchRowRequest,
PatchRowResponse,
Row,
SearchParams,
SearchRowRequest,
SearchRowResponse,
UserCtx,
ValidateResponse,
} from "@budibase/types"
import * as utils from "./utils"
import { gridSocket } from "../../../websockets"
@ -25,12 +25,12 @@ import { addRev } from "../public/utils"
import { fixRow } from "../public/rows"
import sdk from "../../../sdk"
import * as exporters from "../view/exporters"
import { apiFileReturn } from "../../../utilities/fileSystem"
import { Format } from "../view/exporters"
import { apiFileReturn } from "../../../utilities/fileSystem"
export * as views from "./views"
function pickApi(tableId: any) {
function pickApi(tableId: string) {
if (isExternalTableID(tableId)) {
return external
}
@ -49,12 +49,7 @@ export async function patch(
return save(ctx)
}
try {
const { row, table } = await quotas.addQuery(
() => pickApi(tableId).patch(ctx),
{
datasourceId: tableId,
}
)
const { row, table } = await pickApi(tableId).patch(ctx)
if (!row) {
ctx.throw(404, "Row not found")
}
@ -84,9 +79,7 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
return patch(ctx as UserCtx<PatchRowRequest, PatchRowResponse>)
}
const { row, table, squashed } = await quotas.addRow(() =>
quotas.addQuery(() => pickApi(tableId).save(ctx), {
datasourceId: tableId,
})
sdk.rows.save(tableId, ctx.request.body, ctx.user?._id)
)
ctx.status = 200
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
@ -102,31 +95,21 @@ export async function fetchView(ctx: any) {
const { calculation, group, field } = ctx.query
ctx.body = await quotas.addQuery(
() =>
sdk.rows.fetchView(tableId, viewName, {
calculation,
group: calculation ? group : null,
field,
}),
{
datasourceId: tableId,
}
)
ctx.body = await sdk.rows.fetchView(tableId, viewName, {
calculation,
group: calculation ? group : null,
field,
})
}
export async function fetch(ctx: any) {
const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId), {
datasourceId: tableId,
})
ctx.body = await sdk.rows.fetch(tableId)
}
export async function find(ctx: UserCtx<void, GetRowResponse>) {
const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx), {
datasourceId: tableId,
})
ctx.body = await pickApi(tableId).find(ctx)
}
function isDeleteRows(input: any): input is DeleteRows {
@ -157,15 +140,9 @@ async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {
let deleteRequest = ctx.request.body as DeleteRows
const rowDeletes: Row[] = await processDeleteRowsRequest(ctx)
deleteRequest.rows = rowDeletes
deleteRequest.rows = await processDeleteRowsRequest(ctx)
const { rows } = await quotas.addQuery(
() => pickApi(tableId).bulkDestroy(ctx),
{
datasourceId: tableId,
}
)
const { rows } = await pickApi(tableId).bulkDestroy(ctx)
await quotas.removeRows(rows.length)
for (let row of rows) {
@ -180,9 +157,7 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
const appId = ctx.appId
const tableId = utils.getTableId(ctx)
const resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx), {
datasourceId: tableId,
})
const resp = await pickApi(tableId).destroy(ctx)
await quotas.removeRow()
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, resp.row)
@ -220,9 +195,7 @@ export async function search(ctx: Ctx<SearchRowRequest, SearchRowResponse>) {
}
ctx.status = 200
ctx.body = await quotas.addQuery(() => sdk.rows.search(searchParams), {
datasourceId: tableId,
})
ctx.body = await sdk.rows.search(searchParams)
}
export async function validate(ctx: Ctx<Row, ValidateResponse>) {
@ -240,12 +213,7 @@ export async function validate(ctx: Ctx<Row, ValidateResponse>) {
export async function fetchEnrichedRow(ctx: any) {
const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(
() => pickApi(tableId).fetchEnrichedRow(ctx),
{
datasourceId: tableId,
}
)
ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
}
export const exportRows = async (
@ -265,22 +233,15 @@ export const exportRows = async (
)
}
ctx.body = await quotas.addQuery(
async () => {
const { fileName, content } = await sdk.rows.exportRows({
tableId,
format: format as Format,
rowIds: rows,
columns,
query,
sort,
sortOrder,
})
ctx.attachment(fileName)
return apiFileReturn(content)
},
{
datasourceId: tableId,
}
)
const { fileName, content } = await sdk.rows.exportRows({
tableId,
format: format as Format,
rowIds: rows,
columns,
query,
sort,
sortOrder,
})
ctx.attachment(fileName)
ctx.body = apiFileReturn(content)
}

View File

@ -1,5 +1,5 @@
import * as linkRows from "../../../db/linkedRows"
import { generateRowID, InternalTables } from "../../../db/utils"
import { InternalTables } from "../../../db/utils"
import * as userController from "../user"
import {
AttachmentCleanup,
@ -94,45 +94,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
})
}
export async function save(ctx: UserCtx) {
let inputs = ctx.request.body
inputs.tableId = utils.getTableId(ctx)
if (!inputs._rev && !inputs._id) {
inputs._id = generateRowID(inputs.tableId)
}
// this returns the table and row incase they have been updated
const dbTable = await sdk.tables.getTable(inputs.tableId)
// need to copy the table so it can be differenced on way out
const tableClone = cloneDeep(dbTable)
let { table, row } = await inputProcessing(ctx.user?._id, tableClone, inputs)
const validateResult = await sdk.rows.utils.validate({
row,
table,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
// make sure link rows are up-to-date
row = (await linkRows.updateLinks({
eventType: linkRows.EventType.ROW_SAVE,
row,
tableId: row.tableId,
table,
})) as Row
return finaliseRow(table, row, {
oldTable: dbTable,
updateFormula: true,
})
}
export async function find(ctx: UserCtx): Promise<Row> {
const tableId = utils.getTableId(ctx),
rowId = ctx.params.rowId

View File

@ -5,8 +5,8 @@ import {
processFormulas,
} from "../../../utilities/rowProcessor"
import { FieldTypes, FormulaTypes } from "../../../constants"
import { context } from "@budibase/backend-core"
import { Table, Row } from "@budibase/types"
import { context, locks } from "@budibase/backend-core"
import { Table, Row, LockType, LockName } from "@budibase/types"
import * as linkRows from "../../../db/linkedRows"
import sdk from "../../../sdk"
import isEqual from "lodash/isEqual"
@ -149,12 +149,22 @@ export async function finaliseRow(
await db.put(table)
} catch (err: any) {
if (err.status === 409) {
const updatedTable = await sdk.tables.getTable(table._id!)
let response = processAutoColumn(null, updatedTable, row, {
reprocessing: true,
})
await db.put(response.table)
row = response.row
// Some conflicts with the autocolumns occurred, we need to refetch the table and recalculate
await locks.doWithLock(
{
type: LockType.AUTO_EXTEND,
name: LockName.PROCESS_AUTO_COLUMNS,
resource: table._id,
},
async () => {
const latestTable = await sdk.tables.getTable(table._id!)
let response = processAutoColumn(null, latestTable, row, {
reprocessing: true,
})
await db.put(response.table)
row = response.row
}
)
} else {
throw err
}

View File

@ -68,10 +68,7 @@ export async function searchView(
paginate: body.paginate,
}
const result = await quotas.addQuery(() => sdk.rows.search(searchOptions), {
datasourceId: view.tableId,
})
const result = await sdk.rows.search(searchOptions)
result.rows.forEach(r => (r._viewId = view.id))
ctx.body = result
}

View File

@ -77,7 +77,7 @@ const publicRouter = new Router({
prefix: PREFIX,
})
if (limiter) {
if (limiter && !env.isDev()) {
publicRouter.use(limiter)
}

View File

@ -132,11 +132,6 @@ describe.each([
expect(usage).toBe(expected)
}
const assertQueryUsage = async (expected: number) => {
const usage = await getQueryUsage()
expect(usage).toBe(expected)
}
const defaultRowFields = isInternal
? {
type: "row",
@ -181,7 +176,6 @@ describe.each([
expect(res.body.name).toEqual("Test Contact")
expect(res.body._rev).toBeDefined()
await assertRowUsage(rowUsage + 1)
await assertQueryUsage(queryUsage + 1)
})
it("Increment row autoId per create row request", async () => {
@ -232,7 +226,6 @@ describe.each([
}
await assertRowUsage(rowUsage + ids.length)
await assertQueryUsage(queryUsage + ids.length)
})
it("updates a row successfully", async () => {
@ -249,7 +242,6 @@ describe.each([
expect(res.name).toEqual("Updated Name")
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
})
it("should load a row", async () => {
@ -262,7 +254,6 @@ describe.each([
...existing,
...defaultRowFields,
})
await assertQueryUsage(queryUsage + 1)
})
it("should list all rows for given tableId", async () => {
@ -284,7 +275,6 @@ describe.each([
expect(res.length).toBe(2)
expect(res.find((r: Row) => r.name === newRow.name)).toBeDefined()
expect(res.find((r: Row) => r.name === firstRow.name)).toBeDefined()
await assertQueryUsage(queryUsage + 1)
})
it("load should return 404 when row does not exist", async () => {
@ -294,7 +284,6 @@ describe.each([
await config.api.row.get(tableId, "1234567", {
expectStatus: 404,
})
await assertQueryUsage(queryUsage) // no change
})
isInternal &&
@ -558,7 +547,6 @@ describe.each([
expect(savedRow.body.description).toEqual(existing.description)
expect(savedRow.body.name).toEqual("Updated Name")
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 2) // account for the second load
})
it("should throw an error when given improper types", async () => {
@ -578,7 +566,6 @@ describe.each([
)
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
})
it("should not overwrite links if those links are not set", async () => {
@ -668,7 +655,6 @@ describe.each([
const res = await config.api.row.delete(table._id!, [createdRow])
expect(res.body[0]._id).toEqual(createdRow._id)
await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
})
})
@ -687,7 +673,6 @@ describe.each([
expect(res.valid).toBe(true)
expect(Object.keys(res.errors)).toEqual([])
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
})
it("should errors on invalid row", async () => {
@ -705,7 +690,6 @@ describe.each([
expect(Object.keys(res.errors)).toEqual([])
}
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
})
})
@ -726,7 +710,6 @@ describe.each([
expect(res.body.length).toEqual(2)
await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 2)
await assertQueryUsage(queryUsage + 1)
})
it("should be able to delete a variety of row set types", async () => {
@ -747,7 +730,6 @@ describe.each([
expect(res.body.length).toEqual(3)
await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 3)
await assertQueryUsage(queryUsage + 1)
})
it("should accept a valid row object and delete the row", async () => {
@ -760,7 +742,6 @@ describe.each([
expect(res.body.id).toEqual(row1._id)
await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
})
it("Should ignore malformed/invalid delete requests", async () => {
@ -787,7 +768,6 @@ describe.each([
expect(res3.body.message).toEqual("Invalid delete rows request")
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
})
})
@ -808,7 +788,6 @@ describe.each([
expect(res.body.length).toEqual(1)
expect(res.body[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
})
it("should throw an error if view doesn't exist", async () => {
@ -818,7 +797,6 @@ describe.each([
await config.api.legacyView.get("derp", { expectStatus: 404 })
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
})
it("should be able to run on a view", async () => {
@ -837,7 +815,6 @@ describe.each([
expect(res.body[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
})
})
@ -910,7 +887,6 @@ describe.each([
expect(resEnriched.body.link[0].name).toBe("Test Contact")
expect(resEnriched.body.link[0].description).toBe("original description")
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 2)
})
})
@ -1129,7 +1105,6 @@ describe.each([
await config.api.row.delete(view.id, [createdRow])
await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
await config.api.row.get(tableId, createdRow._id!, {
expectStatus: 404,
@ -1157,7 +1132,6 @@ describe.each([
await config.api.row.delete(view.id, [rows[0], rows[2]])
await assertRowUsage(rowUsage - 2)
await assertQueryUsage(queryUsage + 1)
await config.api.row.get(tableId, rows[0]._id!, {
expectStatus: 404,

View File

@ -16,6 +16,7 @@ import {
} from "@budibase/types"
import sdk from "../sdk"
import { automationsEnabled } from "../features"
import tracer from "dd-trace"
const REBOOT_CRON = "@reboot"
const WH_STEP_ID = definitions.WEBHOOK.stepId
@ -39,27 +40,62 @@ function loggingArgs(job: AutomationJob) {
}
export async function processEvent(job: AutomationJob) {
const appId = job.data.event.appId!
const automationId = job.data.automation._id!
return tracer.trace(
"processEvent",
{ resource: "automation" },
async span => {
const appId = job.data.event.appId!
const automationId = job.data.automation._id!
const task = async () => {
try {
// need to actually await these so that an error can be captured properly
console.log("automation running", ...loggingArgs(job))
const runFn = () => Runner.run(job)
const result = await quotas.addAutomation(runFn, {
span?.addTags({
appId,
automationId,
job: {
id: job.id,
name: job.name,
attemptsMade: job.attemptsMade,
opts: {
attempts: job.opts.attempts,
priority: job.opts.priority,
delay: job.opts.delay,
repeat: job.opts.repeat,
backoff: job.opts.backoff,
lifo: job.opts.lifo,
timeout: job.opts.timeout,
jobId: job.opts.jobId,
removeOnComplete: job.opts.removeOnComplete,
removeOnFail: job.opts.removeOnFail,
stackTraceLimit: job.opts.stackTraceLimit,
preventParsingData: job.opts.preventParsingData,
},
},
})
console.log("automation completed", ...loggingArgs(job))
return result
} catch (err) {
console.error(`automation was unable to run`, err, ...loggingArgs(job))
return { err }
}
}
return await context.doInAutomationContext({ appId, automationId, task })
const task = async () => {
try {
// need to actually await these so that an error can be captured properly
console.log("automation running", ...loggingArgs(job))
const runFn = () => Runner.run(job)
const result = await quotas.addAutomation(runFn, {
automationId,
})
console.log("automation completed", ...loggingArgs(job))
return result
} catch (err) {
span?.addTags({ error: true })
console.error(
`automation was unable to run`,
err,
...loggingArgs(job)
)
return { err }
}
}
return await context.doInAutomationContext({ appId, automationId, task })
}
)
}
export async function updateTestHistory(

View File

@ -3,5 +3,9 @@ import apm from "dd-trace"
// enable APM if configured
if (process.env.DD_APM_ENABLED) {
console.log("Starting dd-trace")
apm.init()
apm.init({
// @ts-ignore for some reason dd-trace types don't include this options,
// even though it's spoken about in the docs.
debug: process.env.DD_ENV === "qa",
})
}

View File

@ -305,8 +305,8 @@ export function shouldCopySpecialColumn(
}
/**
* Looks for columns which need to be copied over into the new table definitions, like relationships
* and options types.
* Looks for columns which need to be copied over into the new table definitions, like relationships,
* options types and views.
* @param tableName The name of the table which is being checked.
* @param table The specific table which is being checked.
* @param entities All the tables that existed before - the old table definitions.
@ -325,6 +325,9 @@ function copyExistingPropsOver(
if (entities[tableName]?.created) {
table.created = entities[tableName]?.created
}
table.views = entities[tableName].views
const existingTableSchema = entities[tableName].schema
for (let key in existingTableSchema) {
if (!existingTableSchema.hasOwnProperty(key)) {

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