Merge branch 'master' into BUDI-9068/move-snippets-to-sidepanel
This commit is contained in:
commit
e19f713182
|
@ -0,0 +1 @@
|
|||
scripts/resources/minio filter=lfs diff=lfs merge=lfs -text
|
|
@ -30,7 +30,7 @@ env:
|
|||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -47,7 +47,7 @@ jobs:
|
|||
- run: yarn lint
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -76,7 +76,7 @@ jobs:
|
|||
fi
|
||||
|
||||
helm-lint:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -88,7 +88,7 @@ jobs:
|
|||
- run: cd charts/budibase && helm lint .
|
||||
|
||||
test-libraries:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -122,7 +122,7 @@ jobs:
|
|||
fi
|
||||
|
||||
test-worker:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -151,11 +151,22 @@ jobs:
|
|||
yarn test --verbose --reporters=default --reporters=github-actions
|
||||
|
||||
test-server:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
datasource:
|
||||
[mssql, mysql, postgres, postgres_legacy, mongodb, mariadb, oracle, sqs, none]
|
||||
[
|
||||
mssql,
|
||||
mysql,
|
||||
postgres,
|
||||
postgres_legacy,
|
||||
mongodb,
|
||||
mariadb,
|
||||
oracle,
|
||||
sqs,
|
||||
elasticsearch,
|
||||
none,
|
||||
]
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -192,6 +203,8 @@ jobs:
|
|||
docker pull budibase/oracle-database:23.2-slim-faststart
|
||||
elif [ "${{ matrix.datasource }}" == "postgres_legacy" ]; then
|
||||
docker pull postgres:9.5.25
|
||||
elif [ "${{ matrix.datasource }}" == "elasticsearch" ]; then
|
||||
docker pull elasticsearch@${{ steps.dotenv.outputs.ELASTICSEARCH_SHA }}
|
||||
fi
|
||||
docker pull minio/minio &
|
||||
docker pull redis &
|
||||
|
@ -240,7 +253,7 @@ jobs:
|
|||
yarn test --filter $FILTER --verbose --reporters=default --reporters=github-actions
|
||||
|
||||
check-pro-submodule:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
if: inputs.run_as_oss != true && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'Budibase/budibase')
|
||||
steps:
|
||||
- name: Checkout repo and submodules
|
||||
|
@ -299,7 +312,7 @@ jobs:
|
|||
fi
|
||||
|
||||
check-lockfile:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
if: inputs.run_as_oss != true && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'Budibase/budibase')
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
|
|
|
@ -20,7 +20,7 @@ jobs:
|
|||
- run: yarn --frozen-lockfile
|
||||
|
||||
- name: Install OpenAPI pkg
|
||||
run: yarn global add openapi
|
||||
run: yarn global add rdme@8.6.6
|
||||
|
||||
- name: update specs
|
||||
run: cd packages/server && yarn specs && openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841
|
||||
run: cd packages/server && yarn specs && rdme openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=67c16880add6da002352069a
|
||||
|
|
|
@ -108,7 +108,7 @@ You can install them following any of the steps described below:
|
|||
- Installation steps: https://asdf-vm.com/guide/getting-started.html
|
||||
- asdf plugin add nodejs
|
||||
- asdf plugin add python
|
||||
- npm install -g yarn
|
||||
- asdf plugin add yarn
|
||||
|
||||
### Using NVM and pyenv
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
ARG BASEIMG=budibase/couchdb:v3.3.3-sqs-v2.1.1
|
||||
FROM node:20-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
|
||||
|
@ -34,13 +34,13 @@ COPY packages/worker/dist packages/worker/dist
|
|||
COPY packages/worker/pm2.config.js packages/worker/pm2.config.js
|
||||
|
||||
|
||||
FROM $BASEIMG as runner
|
||||
FROM $BASEIMG AS runner
|
||||
ARG TARGETARCH
|
||||
ENV TARGETARCH $TARGETARCH
|
||||
ENV TARGETARCH=$TARGETARCH
|
||||
#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
|
||||
ENV TARGETBUILD $TARGETBUILD
|
||||
ENV TARGETBUILD=$TARGETBUILD
|
||||
|
||||
# install base dependencies
|
||||
RUN apt-get update && \
|
||||
|
@ -67,6 +67,12 @@ RUN mkdir -p /var/log/nginx && \
|
|||
|
||||
# setup minio
|
||||
WORKDIR /minio
|
||||
|
||||
# a 2022 version of minio that supports gateway mode
|
||||
COPY scripts/resources/minio /minio
|
||||
RUN chmod +x minio
|
||||
|
||||
# handles the installation of minio in non-aas environments
|
||||
COPY scripts/install-minio.sh ./install.sh
|
||||
RUN chmod +x install.sh && ./install.sh
|
||||
|
||||
|
@ -86,7 +92,7 @@ COPY hosting/single/ssh/sshd_config /etc/
|
|||
COPY hosting/single/ssh/ssh_setup.sh /tmp
|
||||
|
||||
# setup letsencrypt certificate
|
||||
RUN apt-get install -y certbot python3-certbot-nginx
|
||||
RUN apt-get update && apt-get install -y certbot python3-certbot-nginx
|
||||
COPY hosting/letsencrypt /app/letsencrypt
|
||||
RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh
|
||||
|
||||
|
|
|
@ -1,53 +1,61 @@
|
|||
#!/bin/bash
|
||||
declare -a ENV_VARS=("COUCHDB_USER" "COUCHDB_PASSWORD" "DATA_DIR" "MINIO_ACCESS_KEY" "MINIO_SECRET_KEY" "INTERNAL_API_KEY" "JWT_SECRET" "REDIS_PASSWORD")
|
||||
declare -a DOCKER_VARS=("APP_PORT" "APPS_URL" "ARCHITECTURE" "BUDIBASE_ENVIRONMENT" "CLUSTER_PORT" "DEPLOYMENT_ENVIRONMENT" "MINIO_URL" "NODE_ENV" "POSTHOG_TOKEN" "REDIS_URL" "SELF_HOSTED" "WORKER_PORT" "WORKER_URL" "TENANT_FEATURE_FLAGS" "ACCOUNT_PORTAL_URL")
|
||||
# Check the env vars set in Dockerfile have come through, AAS seems to drop them
|
||||
[[ -z "${APP_PORT}" ]] && export APP_PORT=4001
|
||||
[[ -z "${ARCHITECTURE}" ]] && export ARCHITECTURE=amd
|
||||
[[ -z "${BUDIBASE_ENVIRONMENT}" ]] && export BUDIBASE_ENVIRONMENT=PRODUCTION
|
||||
[[ -z "${CLUSTER_PORT}" ]] && export CLUSTER_PORT=80
|
||||
[[ -z "${DEPLOYMENT_ENVIRONMENT}" ]] && export DEPLOYMENT_ENVIRONMENT=docker
|
||||
[[ -z "${MINIO_URL}" ]] && [[ -z "${USE_S3}" ]] && export MINIO_URL=http://127.0.0.1:9000
|
||||
[[ -z "${NODE_ENV}" ]] && export NODE_ENV=production
|
||||
[[ -z "${POSTHOG_TOKEN}" ]] && export POSTHOG_TOKEN=phc_bIjZL7oh2GEUd2vqvTBH8WvrX0fWTFQMs6H5KQxiUxU
|
||||
[[ -z "${ACCOUNT_PORTAL_URL}" ]] && export ACCOUNT_PORTAL_URL=https://account.budibase.app
|
||||
[[ -z "${REDIS_URL}" ]] && export REDIS_URL=127.0.0.1:6379
|
||||
[[ -z "${SELF_HOSTED}" ]] && export SELF_HOSTED=1
|
||||
[[ -z "${WORKER_PORT}" ]] && export WORKER_PORT=4002
|
||||
[[ -z "${WORKER_URL}" ]] && export WORKER_URL=http://127.0.0.1:4002
|
||||
[[ -z "${APPS_URL}" ]] && export APPS_URL=http://127.0.0.1:4001
|
||||
[[ -z "${SERVER_TOP_LEVEL_PATH}" ]] && export SERVER_TOP_LEVEL_PATH=/app
|
||||
# export CUSTOM_DOMAIN=budi001.custom.com
|
||||
|
||||
# Azure App Service customisations
|
||||
if [[ "${TARGETBUILD}" = "aas" ]]; then
|
||||
export DATA_DIR="${DATA_DIR:-/home}"
|
||||
WEBSITES_ENABLE_APP_SERVICE_STORAGE=true
|
||||
/etc/init.d/ssh start
|
||||
else
|
||||
export DATA_DIR=${DATA_DIR:-/data}
|
||||
echo "Starting runner.sh..."
|
||||
|
||||
# set defaults for Docker-related variables
|
||||
export APP_PORT="${APP_PORT:-4001}"
|
||||
export ARCHITECTURE="${ARCHITECTURE:-amd}"
|
||||
export BUDIBASE_ENVIRONMENT="${BUDIBASE_ENVIRONMENT:-PRODUCTION}"
|
||||
export CLUSTER_PORT="${CLUSTER_PORT:-80}"
|
||||
export DEPLOYMENT_ENVIRONMENT="${DEPLOYMENT_ENVIRONMENT:-docker}"
|
||||
|
||||
# only set MINIO_URL if neither MINIO_URL nor USE_S3 is set
|
||||
if [[ -z "${MINIO_URL}" && -z "${USE_S3}" ]]; then
|
||||
export MINIO_URL="http://127.0.0.1:9000"
|
||||
fi
|
||||
mkdir -p ${DATA_DIR}
|
||||
# Mount NFS or GCP Filestore if env vars exist for it
|
||||
if [[ ! -z ${FILESHARE_IP} && ! -z ${FILESHARE_NAME} ]]; then
|
||||
|
||||
export NODE_ENV="${NODE_ENV:-production}"
|
||||
export POSTHOG_TOKEN="${POSTHOG_TOKEN:-phc_bIjZL7oh2GEUd2vqvTBH8WvrX0fWTFQMs6H5KQxiUxU}"
|
||||
export ACCOUNT_PORTAL_URL="${ACCOUNT_PORTAL_URL:-https://account.budibase.app}"
|
||||
export REDIS_URL="${REDIS_URL:-127.0.0.1:6379}"
|
||||
export SELF_HOSTED="${SELF_HOSTED:-1}"
|
||||
export WORKER_PORT="${WORKER_PORT:-4002}"
|
||||
export WORKER_URL="${WORKER_URL:-http://127.0.0.1:4002}"
|
||||
export APPS_URL="${APPS_URL:-http://127.0.0.1:4001}"
|
||||
export SERVER_TOP_LEVEL_PATH="${SERVER_TOP_LEVEL_PATH:-/app}"
|
||||
|
||||
# set DATA_DIR and ensure the directory exists
|
||||
if [[ ${TARGETBUILD} == "aas" ]]; then
|
||||
export DATA_DIR="/home"
|
||||
else
|
||||
export DATA_DIR="${DATA_DIR:-/data}"
|
||||
fi
|
||||
mkdir -p "${DATA_DIR}"
|
||||
|
||||
# mount NFS or GCP Filestore if FILESHARE_IP and FILESHARE_NAME are set
|
||||
if [[ -n "${FILESHARE_IP}" && -n "${FILESHARE_NAME}" ]]; then
|
||||
echo "Mounting NFS share"
|
||||
apt update && apt install -y nfs-common nfs-kernel-server
|
||||
echo "Mount file share ${FILESHARE_IP}:/${FILESHARE_NAME} to ${DATA_DIR}"
|
||||
mount -o nolock ${FILESHARE_IP}:/${FILESHARE_NAME} ${DATA_DIR}
|
||||
mount -o nolock "${FILESHARE_IP}:/${FILESHARE_NAME}" "${DATA_DIR}"
|
||||
echo "Mounting result: $?"
|
||||
fi
|
||||
|
||||
if [ -f "${DATA_DIR}/.env" ]; then
|
||||
# Read in the .env file and export the variables
|
||||
for LINE in $(cat ${DATA_DIR}/.env); do export $LINE; done
|
||||
# source environment variables from a .env file if it exists in DATA_DIR
|
||||
if [[ -f "${DATA_DIR}/.env" ]]; then
|
||||
set -a # Automatically export all variables loaded from .env
|
||||
source "${DATA_DIR}/.env"
|
||||
set +a
|
||||
fi
|
||||
# randomise any unset environment variables
|
||||
for ENV_VAR in "${ENV_VARS[@]}"
|
||||
do
|
||||
if [[ -z "${!ENV_VAR}" ]]; then
|
||||
eval "export $ENV_VAR=$(uuidgen | sed -e 's/-//g')"
|
||||
|
||||
# randomize any unset sensitive environment variables using uuidgen
|
||||
env_vars=(COUCHDB_USER COUCHDB_PASSWORD MINIO_ACCESS_KEY MINIO_SECRET_KEY INTERNAL_API_KEY JWT_SECRET REDIS_PASSWORD)
|
||||
for var in "${env_vars[@]}"; do
|
||||
if [[ -z "${!var}" ]]; then
|
||||
export "$var"="$(uuidgen | tr -d '-')"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${COUCH_DB_URL}" ]]; then
|
||||
export COUCH_DB_URL=http://$COUCHDB_USER:$COUCHDB_PASSWORD@127.0.0.1:5984
|
||||
fi
|
||||
|
@ -58,17 +66,15 @@ fi
|
|||
|
||||
if [ ! -f "${DATA_DIR}/.env" ]; then
|
||||
touch ${DATA_DIR}/.env
|
||||
for ENV_VAR in "${ENV_VARS[@]}"
|
||||
do
|
||||
for ENV_VAR in "${ENV_VARS[@]}"; do
|
||||
temp=$(eval "echo \$$ENV_VAR")
|
||||
echo "$ENV_VAR=$temp" >> ${DATA_DIR}/.env
|
||||
echo "$ENV_VAR=$temp" >>${DATA_DIR}/.env
|
||||
done
|
||||
for ENV_VAR in "${DOCKER_VARS[@]}"
|
||||
do
|
||||
for ENV_VAR in "${DOCKER_VARS[@]}"; do
|
||||
temp=$(eval "echo \$$ENV_VAR")
|
||||
echo "$ENV_VAR=$temp" >> ${DATA_DIR}/.env
|
||||
echo "$ENV_VAR=$temp" >>${DATA_DIR}/.env
|
||||
done
|
||||
echo "COUCH_DB_URL=${COUCH_DB_URL}" >> ${DATA_DIR}/.env
|
||||
echo "COUCH_DB_URL=${COUCH_DB_URL}" >>${DATA_DIR}/.env
|
||||
fi
|
||||
|
||||
# Read in the .env file and export the variables
|
||||
|
@ -79,6 +85,7 @@ ln -s ${DATA_DIR}/.env /worker/.env
|
|||
# make these directories in runner, incase of mount
|
||||
mkdir -p ${DATA_DIR}/minio
|
||||
mkdir -p ${DATA_DIR}/redis
|
||||
mkdir -p ${DATA_DIR}/couch
|
||||
chown -R couchdb:couchdb ${DATA_DIR}/couch
|
||||
|
||||
REDIS_CONFIG="/etc/redis/redis.conf"
|
||||
|
@ -89,21 +96,33 @@ if [[ -n "${USE_DEFAULT_REDIS_CONFIG}" ]]; then
|
|||
fi
|
||||
|
||||
if [[ -n "${REDIS_PASSWORD}" ]]; then
|
||||
redis-server "${REDIS_CONFIG}" --requirepass $REDIS_PASSWORD > /dev/stdout 2>&1 &
|
||||
redis-server "${REDIS_CONFIG}" --requirepass $REDIS_PASSWORD >/dev/stdout 2>&1 &
|
||||
else
|
||||
redis-server "${REDIS_CONFIG}" > /dev/stdout 2>&1 &
|
||||
redis-server "${REDIS_CONFIG}" >/dev/stdout 2>&1 &
|
||||
fi
|
||||
/bbcouch-runner.sh &
|
||||
|
||||
echo "Starting callback CouchDB runner..."
|
||||
./bbcouch-runner.sh &
|
||||
|
||||
# only start minio if use s3 isn't passed
|
||||
if [[ -z "${USE_S3}" ]]; then
|
||||
/minio/minio server --console-address ":9001" ${DATA_DIR}/minio > /dev/stdout 2>&1 &
|
||||
if [[ ${TARGETBUILD} == aas ]]; then
|
||||
echo "Starting MinIO in Azure Gateway mode"
|
||||
if [[ -z "${AZURE_STORAGE_ACCOUNT}" || -z "${AZURE_STORAGE_KEY}" || -z "${MINIO_ACCESS_KEY}" || -z "${MINIO_SECRET_KEY}" ]]; then
|
||||
echo "The following environment variables must be set: AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY, MINIO_ACCESS_KEY, MINIO_SECRET_KEY"
|
||||
exit 1
|
||||
fi
|
||||
/minio/minio gateway azure --console-address ":9001" >/dev/stdout 2>&1 &
|
||||
else
|
||||
echo "Starting MinIO in standalone mode"
|
||||
/minio/minio server --console-address ":9001" ${DATA_DIR}/minio >/dev/stdout 2>&1 &
|
||||
fi
|
||||
fi
|
||||
|
||||
/etc/init.d/nginx restart
|
||||
if [[ ! -z "${CUSTOM_DOMAIN}" ]]; then
|
||||
# Add monthly cron job to renew certbot certificate
|
||||
echo -n "* * 2 * * root exec /app/letsencrypt/certificate-renew.sh ${CUSTOM_DOMAIN}" >> /etc/cron.d/certificate-renew
|
||||
echo -n "* * 2 * * root exec /app/letsencrypt/certificate-renew.sh ${CUSTOM_DOMAIN}" >>/etc/cron.d/certificate-renew
|
||||
chmod +x /etc/cron.d/certificate-renew
|
||||
# Request the certbot certificate
|
||||
/app/letsencrypt/certificate-request.sh ${CUSTOM_DOMAIN}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"version": "3.4.13",
|
||||
"version": "3.4.22",
|
||||
"npmClient": "yarn",
|
||||
"concurrency": 20,
|
||||
"command": {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
export let active = false
|
||||
export let inactive = false
|
||||
export let hoverable = false
|
||||
export let outlineColor = null
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
|
@ -29,6 +30,7 @@
|
|||
class:spectrum-Label--seafoam={seafoam}
|
||||
class:spectrum-Label--active={active}
|
||||
class:spectrum-Label--inactive={inactive}
|
||||
style={outlineColor ? `border: 2px solid ${outlineColor}` : ""}
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
export let small = false
|
||||
export let disabled
|
||||
<script lang="ts">
|
||||
export let small: boolean = false
|
||||
export let disabled: boolean = false
|
||||
</script>
|
||||
|
||||
<button
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Field from "./Field.svelte"
|
||||
import Checkbox from "./Core/Checkbox.svelte"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
|
||||
export let value = null
|
||||
export let label = null
|
||||
export let labelPosition = "above"
|
||||
export let text = null
|
||||
export let disabled = false
|
||||
export let error = null
|
||||
export let size = "M"
|
||||
export let helpText = null
|
||||
export let value: boolean | undefined = undefined
|
||||
export let label: string | undefined = undefined
|
||||
export let labelPosition: "above" | "below" = "above"
|
||||
export let text: string | undefined = undefined
|
||||
export let disabled: boolean = false
|
||||
export let error: string | undefined = undefined
|
||||
export let size: "S" | "M" | "L" | "XL" = "M"
|
||||
export let helpText: string | undefined = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const onChange = e => {
|
||||
const onChange = (e: CustomEvent<boolean>) => {
|
||||
value = e.detail
|
||||
dispatch("change", e.detail)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Field {helpText} {label} {labelPosition} {error}>
|
||||
<Checkbox {error} {disabled} {text} {value} {size} on:change={onChange} />
|
||||
<Checkbox {disabled} {text} {value} {size} on:change={onChange} />
|
||||
</Field>
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<svg
|
||||
on:contextmenu
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseleave
|
||||
on:focus
|
||||
class:hoverable
|
||||
class:disabled
|
||||
class="spectrum-Icon spectrum-Icon--size{size}"
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
overflow-x: hidden;
|
||||
}
|
||||
.main {
|
||||
overflow-y: scroll;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.content {
|
||||
display: flex;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
export let secondary: boolean = false
|
||||
export let overBackground: boolean = false
|
||||
export let target: string | undefined = undefined
|
||||
export let download: boolean | undefined = undefined
|
||||
export let download: string | undefined = undefined
|
||||
export let disabled: boolean = false
|
||||
export let tooltip: string | null = null
|
||||
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
<script>
|
||||
import { getContext } from "svelte"
|
||||
|
||||
const multilevel = getContext("sidenav-type")
|
||||
import Badge from "../Badge/Badge.svelte"
|
||||
|
||||
export let href = ""
|
||||
export let external = false
|
||||
export let heading = ""
|
||||
export let icon = ""
|
||||
export let selected = false
|
||||
export let disabled = false
|
||||
export let badge = ""
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||
<li
|
||||
class="spectrum-SideNav-item"
|
||||
class:is-selected={selected}
|
||||
class:is-disabled={disabled}
|
||||
on:click
|
||||
>
|
||||
{#if heading}
|
||||
<h2 class="spectrum-SideNav-heading" id="nav-heading-{heading}">
|
||||
{heading}
|
||||
</h2>
|
||||
{/if}
|
||||
<a
|
||||
target={external ? "_blank" : ""}
|
||||
{href}
|
||||
class="spectrum-SideNav-itemLink"
|
||||
aria-current="page"
|
||||
>
|
||||
{#if icon}
|
||||
<svg
|
||||
class="spectrum-Icon spectrum-Icon--sizeM spectrum-SideNav-itemIcon"
|
||||
focusable="false"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<use xlink:href="#spectrum-icon-18-{icon}" />
|
||||
</svg>
|
||||
{/if}
|
||||
<slot />
|
||||
{#if badge}
|
||||
<div class="badge">
|
||||
<Badge active size="S">{badge}</Badge>
|
||||
</div>
|
||||
{/if}
|
||||
</a>
|
||||
|
||||
{#if multilevel && $$slots.subnav}
|
||||
<ul class="spectrum-SideNav">
|
||||
<slot name="subnav" />
|
||||
</ul>
|
||||
{/if}
|
||||
</li>
|
||||
|
||||
<style>
|
||||
.badge {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
|
@ -1,13 +0,0 @@
|
|||
<script>
|
||||
import { setContext } from "svelte"
|
||||
import "@spectrum-css/sidenav/dist/index-vars.css"
|
||||
|
||||
export let multilevel = false
|
||||
setContext("sidenav-type", multilevel)
|
||||
</script>
|
||||
|
||||
<nav>
|
||||
<ul class="spectrum-SideNav" class:spectrum-SideNav--multiLevel={multilevel}>
|
||||
<slot />
|
||||
</ul>
|
||||
</nav>
|
|
@ -7,17 +7,26 @@ export const BANNER_TYPES = {
|
|||
WARNING: "warning",
|
||||
}
|
||||
|
||||
interface BannerConfig {
|
||||
message?: string
|
||||
type?: string
|
||||
extraButtonText?: string
|
||||
extraButtonAction?: () => void
|
||||
onChange?: () => void
|
||||
}
|
||||
|
||||
interface DefaultConfig {
|
||||
messages: BannerConfig[]
|
||||
}
|
||||
|
||||
export function createBannerStore() {
|
||||
const DEFAULT_CONFIG = {
|
||||
const DEFAULT_CONFIG: DefaultConfig = {
|
||||
messages: [],
|
||||
}
|
||||
|
||||
const banner = writable(DEFAULT_CONFIG)
|
||||
const banner = writable<DefaultConfig>(DEFAULT_CONFIG)
|
||||
|
||||
const show = async (
|
||||
// eslint-disable-next-line
|
||||
config = { message, type, extraButtonText, extraButtonAction, onChange }
|
||||
) => {
|
||||
const show = async (config: BannerConfig = {}) => {
|
||||
banner.update(store => {
|
||||
return {
|
||||
...store,
|
||||
|
@ -27,7 +36,7 @@ export function createBannerStore() {
|
|||
}
|
||||
|
||||
const showStatus = async () => {
|
||||
const config = {
|
||||
const config: BannerConfig = {
|
||||
message: "Some systems are experiencing issues",
|
||||
type: BANNER_TYPES.NEGATIVE,
|
||||
extraButtonText: "View Status",
|
||||
|
@ -37,18 +46,24 @@ export function createBannerStore() {
|
|||
await queue([config])
|
||||
}
|
||||
|
||||
const queue = async entries => {
|
||||
const priority = {
|
||||
const queue = async (entries: Array<BannerConfig>) => {
|
||||
const priority: Record<string, number> = {
|
||||
[BANNER_TYPES.NEGATIVE]: 0,
|
||||
[BANNER_TYPES.WARNING]: 1,
|
||||
[BANNER_TYPES.INFO]: 2,
|
||||
}
|
||||
banner.update(store => {
|
||||
const sorted = [...store.messages, ...entries].sort((a, b) => {
|
||||
if (priority[a.type] == priority[b.type]) {
|
||||
if (
|
||||
priority[a.type as keyof typeof priority] ===
|
||||
priority[b.type as keyof typeof priority]
|
||||
) {
|
||||
return 0
|
||||
}
|
||||
return priority[a.type] < priority[b.type] ? -1 : 1
|
||||
return priority[a.type as keyof typeof priority] <
|
||||
priority[b.type as keyof typeof priority]
|
||||
? -1
|
||||
: 1
|
||||
})
|
||||
return {
|
||||
...store,
|
|
@ -2,9 +2,21 @@ import { writable } from "svelte/store"
|
|||
|
||||
const NOTIFICATION_TIMEOUT = 3000
|
||||
|
||||
interface Notification {
|
||||
id: string
|
||||
type: string
|
||||
message: string
|
||||
icon: string
|
||||
dismissable: boolean
|
||||
action: (() => void) | null
|
||||
actionMessage: string | null
|
||||
wide: boolean
|
||||
dismissTimeout: number
|
||||
}
|
||||
|
||||
export const createNotificationStore = () => {
|
||||
const timeoutIds = new Set()
|
||||
const _notifications = writable([], () => {
|
||||
const timeoutIds = new Set<ReturnType<typeof setTimeout>>()
|
||||
const _notifications = writable<Notification[]>([], () => {
|
||||
return () => {
|
||||
// clear all the timers
|
||||
timeoutIds.forEach(timeoutId => {
|
||||
|
@ -21,7 +33,7 @@ export const createNotificationStore = () => {
|
|||
}
|
||||
|
||||
const send = (
|
||||
message,
|
||||
message: string,
|
||||
{
|
||||
type = "default",
|
||||
icon = "",
|
||||
|
@ -30,7 +42,15 @@ export const createNotificationStore = () => {
|
|||
actionMessage = null,
|
||||
wide = false,
|
||||
dismissTimeout = NOTIFICATION_TIMEOUT,
|
||||
}
|
||||
}: {
|
||||
type?: string
|
||||
icon?: string
|
||||
autoDismiss?: boolean
|
||||
action?: (() => void) | null
|
||||
actionMessage?: string | null
|
||||
wide?: boolean
|
||||
dismissTimeout?: number
|
||||
} = {}
|
||||
) => {
|
||||
if (block) {
|
||||
return
|
||||
|
@ -60,7 +80,7 @@ export const createNotificationStore = () => {
|
|||
}
|
||||
}
|
||||
|
||||
const dismissNotification = id => {
|
||||
const dismissNotification = (id: string) => {
|
||||
_notifications.update(state => {
|
||||
return state.filter(n => n.id !== id)
|
||||
})
|
||||
|
@ -71,17 +91,18 @@ export const createNotificationStore = () => {
|
|||
return {
|
||||
subscribe,
|
||||
send,
|
||||
info: msg => send(msg, { type: "info", icon: "Info" }),
|
||||
error: msg =>
|
||||
info: (msg: string) => send(msg, { type: "info", icon: "Info" }),
|
||||
error: (msg: string) =>
|
||||
send(msg, { type: "error", icon: "Alert", autoDismiss: false }),
|
||||
warning: msg => send(msg, { type: "warning", icon: "Alert" }),
|
||||
success: msg => send(msg, { type: "success", icon: "CheckmarkCircle" }),
|
||||
warning: (msg: string) => send(msg, { type: "warning", icon: "Alert" }),
|
||||
success: (msg: string) =>
|
||||
send(msg, { type: "success", icon: "CheckmarkCircle" }),
|
||||
blockNotifications,
|
||||
dismiss: dismissNotification,
|
||||
}
|
||||
}
|
||||
|
||||
function id() {
|
||||
function id(): string {
|
||||
return "_" + Math.random().toString(36).slice(2, 9)
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/label/dist/index-vars.css"
|
||||
import Badge from "../Badge/Badge.svelte"
|
||||
|
||||
export let value
|
||||
export let value: string | string[]
|
||||
|
||||
const displayLimit = 5
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Link from "../Link/Link.svelte"
|
||||
|
||||
export let value
|
||||
export let value: { name: string; url: string; extension: string }[]
|
||||
|
||||
const displayLimit = 5
|
||||
$: attachments = value?.slice(0, displayLimit) ?? []
|
||||
$: leftover = (value?.length ?? 0) - attachments.length
|
||||
|
||||
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
|
||||
const isImage = extension => {
|
||||
return imageExtensions.includes(extension?.toLowerCase())
|
||||
const imageExtensions: string[] = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
|
||||
const isImage = (extension: string | undefined): boolean => {
|
||||
return imageExtensions.includes(extension?.toLowerCase() ?? "")
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
export let value
|
||||
<script lang="ts">
|
||||
export let value: string
|
||||
</script>
|
||||
|
||||
<div class="bold">{value}</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/checkbox/dist/index-vars.css"
|
||||
|
||||
export let value
|
||||
export let value: boolean
|
||||
</script>
|
||||
|
||||
<label
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import StringRenderer from "./StringRenderer.svelte"
|
||||
import BooleanRenderer from "./BooleanRenderer.svelte"
|
||||
import DateTimeRenderer from "./DateTimeRenderer.svelte"
|
||||
|
@ -8,14 +8,14 @@
|
|||
import InternalRenderer from "./InternalRenderer.svelte"
|
||||
import { processStringSync } from "@budibase/string-templates"
|
||||
|
||||
export let row
|
||||
export let schema
|
||||
export let value
|
||||
export let customRenderers = []
|
||||
export let snippets
|
||||
export let row: Record<string, any>
|
||||
export let schema: Record<string, any>
|
||||
export let value: Record<string, any>
|
||||
export let customRenderers: { column: string; component: any }[] = []
|
||||
export let snippets: any
|
||||
|
||||
let renderer
|
||||
const typeMap = {
|
||||
let renderer: any
|
||||
const typeMap: Record<string, any> = {
|
||||
boolean: BooleanRenderer,
|
||||
datetime: DateTimeRenderer,
|
||||
link: RelationshipRenderer,
|
||||
|
@ -33,7 +33,7 @@
|
|||
$: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
|
||||
$: cellValue = getCellValue(value, schema.template)
|
||||
|
||||
const getType = schema => {
|
||||
const getType = (schema: any): string => {
|
||||
// Use a string renderer for dates if we use a custom template
|
||||
if (schema?.type === "datetime" && schema?.template) {
|
||||
return "string"
|
||||
|
@ -41,7 +41,7 @@
|
|||
return schema?.type || "string"
|
||||
}
|
||||
|
||||
const getCellValue = (value, template) => {
|
||||
const getCellValue = (value: any, template: string | undefined): any => {
|
||||
if (!template) {
|
||||
return value
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
export let value
|
||||
<script lang="ts">
|
||||
export let value: string
|
||||
</script>
|
||||
|
||||
<code>{value}</code>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import dayjs from "dayjs"
|
||||
|
||||
export let value
|
||||
export let schema
|
||||
export let value: string | Date
|
||||
export let schema: { timeOnly?: boolean; dateOnly?: boolean }
|
||||
|
||||
// adding the 0- will turn a string like 00:00:00 into a valid ISO
|
||||
// date, but will make actual ISO dates invalid
|
||||
$: time = new Date(`0-${value}`)
|
||||
$: isTimeOnly = !isNaN(time) || schema?.timeOnly
|
||||
$: isTimeOnly = !isNaN(time as any) || schema?.timeOnly
|
||||
$: isDateOnly = schema?.dateOnly
|
||||
$: format = isTimeOnly
|
||||
? "HH:mm:ss"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Icon from "../Icon/Icon.svelte"
|
||||
import { copyToClipboard } from "../helpers"
|
||||
import { notifications } from "../Stores/notifications"
|
||||
|
||||
export let value
|
||||
export let value: string
|
||||
|
||||
const onClick = async e => {
|
||||
const onClick = async (e: MouseEvent): Promise<void> => {
|
||||
e.stopPropagation()
|
||||
try {
|
||||
await copyToClipboard(value)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/label/dist/index-vars.css"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
import Badge from "../Badge/Badge.svelte"
|
||||
|
||||
export let row
|
||||
export let value
|
||||
export let schema
|
||||
export let row: { tableId: string; _id: string }
|
||||
export let value: { primaryDisplay?: string }[] | undefined
|
||||
export let schema: { name?: string }
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const displayLimit = 5
|
||||
|
@ -13,7 +13,7 @@
|
|||
$: relationships = value?.slice(0, displayLimit) ?? []
|
||||
$: leftover = (value?.length ?? 0) - relationships.length
|
||||
|
||||
const onClick = e => {
|
||||
const onClick = (e: MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
dispatch("clickrelationship", {
|
||||
tableId: row.tableId,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Checkbox from "../Form/Checkbox.svelte"
|
||||
import ActionButton from "../ActionButton/ActionButton.svelte"
|
||||
|
||||
export let selected
|
||||
export let onEdit
|
||||
export let allowSelectRows = false
|
||||
export let allowEditRows = false
|
||||
export let data
|
||||
export let selected: boolean | undefined
|
||||
export let onEdit: (_e: Event) => void
|
||||
export let allowSelectRows: boolean = false
|
||||
export let allowEditRows: boolean = false
|
||||
export let data: Record<string, any>
|
||||
</script>
|
||||
|
||||
<div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
export let value
|
||||
export let schema
|
||||
<script lang="ts">
|
||||
export let value: string | object
|
||||
export let schema: { capitalise?: boolean }
|
||||
</script>
|
||||
|
||||
<div class:capitalise={schema?.capitalise}>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from "svelte"
|
||||
import "@spectrum-css/table/dist/index-vars.css"
|
||||
import CellRenderer from "./CellRenderer.svelte"
|
||||
|
@ -7,6 +7,7 @@
|
|||
import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
|
||||
import Checkbox from "../Form/Checkbox.svelte"
|
||||
|
||||
/**
|
||||
/**
|
||||
* The expected schema is our normal couch schemas for our tables.
|
||||
* Each field schema can be enriched with a few extra properties to customise
|
||||
|
@ -24,42 +25,42 @@
|
|||
* borderLeft: show a left border
|
||||
* borderRight: show a right border
|
||||
*/
|
||||
export let data = []
|
||||
export let schema = {}
|
||||
export let showAutoColumns = false
|
||||
export let rowCount = 0
|
||||
export let quiet = false
|
||||
export let loading = false
|
||||
export let allowSelectRows
|
||||
export let allowEditRows = true
|
||||
export let allowEditColumns = true
|
||||
export let allowClickRows = true
|
||||
export let selectedRows = []
|
||||
export let customRenderers = []
|
||||
export let disableSorting = false
|
||||
export let autoSortColumns = true
|
||||
export let compact = false
|
||||
export let customPlaceholder = false
|
||||
export let showHeaderBorder = true
|
||||
export let placeholderText = "No rows found"
|
||||
export let snippets = []
|
||||
export let defaultSortColumn = undefined
|
||||
export let defaultSortOrder = "Ascending"
|
||||
export let data: any[] = []
|
||||
export let schema: Record<string, any> = {}
|
||||
export let showAutoColumns: boolean = false
|
||||
export let rowCount: number = 0
|
||||
export let quiet: boolean = false
|
||||
export let loading: boolean = false
|
||||
export let allowSelectRows: boolean = false
|
||||
export let allowEditRows: boolean = true
|
||||
export let allowEditColumns: boolean = true
|
||||
export let allowClickRows: boolean = true
|
||||
export let selectedRows: any[] = []
|
||||
export let customRenderers: any[] = []
|
||||
export let disableSorting: boolean = false
|
||||
export let autoSortColumns: boolean = true
|
||||
export let compact: boolean = false
|
||||
export let customPlaceholder: boolean = false
|
||||
export let showHeaderBorder: boolean = true
|
||||
export let placeholderText: string = "No rows found"
|
||||
export let snippets: any[] = []
|
||||
export let defaultSortColumn: string | undefined = undefined
|
||||
export let defaultSortOrder: "Ascending" | "Descending" = "Ascending"
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
// Config
|
||||
const headerHeight = 36
|
||||
const headerHeight: number = 36
|
||||
$: rowHeight = compact ? 46 : 55
|
||||
|
||||
// Sorting state
|
||||
let sortColumn
|
||||
let sortOrder
|
||||
let sortColumn: string | undefined
|
||||
let sortOrder: "Ascending" | "Descending" | undefined
|
||||
|
||||
// Table state
|
||||
let height = 0
|
||||
let loaded = false
|
||||
let checkboxStatus = false
|
||||
let height: number = 0
|
||||
let loaded: boolean = false
|
||||
let checkboxStatus: boolean = false
|
||||
|
||||
$: schema = fixSchema(schema)
|
||||
$: if (!loading) loaded = true
|
||||
|
@ -95,8 +96,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
const fixSchema = schema => {
|
||||
let fixedSchema = {}
|
||||
const fixSchema = (schema: Record<string, any>): Record<string, any> => {
|
||||
let fixedSchema: Record<string, any> = {}
|
||||
Object.entries(schema || {}).forEach(([fieldName, fieldSchema]) => {
|
||||
if (typeof fieldSchema === "string") {
|
||||
fixedSchema[fieldName] = {
|
||||
|
@ -120,7 +121,13 @@
|
|||
return fixedSchema
|
||||
}
|
||||
|
||||
const getVisibleRowCount = (loaded, height, allRows, rowCount, rowHeight) => {
|
||||
const getVisibleRowCount = (
|
||||
loaded: boolean,
|
||||
height: number,
|
||||
allRows: number,
|
||||
rowCount: number,
|
||||
rowHeight: number
|
||||
): number => {
|
||||
if (!loaded) {
|
||||
return rowCount || 0
|
||||
}
|
||||
|
@ -131,12 +138,12 @@
|
|||
}
|
||||
|
||||
const getHeightStyle = (
|
||||
visibleRowCount,
|
||||
rowCount,
|
||||
totalRowCount,
|
||||
rowHeight,
|
||||
loading
|
||||
) => {
|
||||
visibleRowCount: number,
|
||||
rowCount: number,
|
||||
totalRowCount: number,
|
||||
rowHeight: number,
|
||||
loading: boolean
|
||||
): string => {
|
||||
if (loading) {
|
||||
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
||||
}
|
||||
|
@ -146,7 +153,11 @@
|
|||
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
||||
}
|
||||
|
||||
const getGridStyle = (fields, schema, showEditColumn) => {
|
||||
const getGridStyle = (
|
||||
fields: string[],
|
||||
schema: Record<string, any>,
|
||||
showEditColumn: boolean
|
||||
): string => {
|
||||
let style = "grid-template-columns:"
|
||||
if (showEditColumn) {
|
||||
style += " auto"
|
||||
|
@ -163,7 +174,11 @@
|
|||
return style
|
||||
}
|
||||
|
||||
const sortRows = (rows, sortColumn, sortOrder) => {
|
||||
const sortRows = (
|
||||
rows: any[],
|
||||
sortColumn: string | undefined,
|
||||
sortOrder: string | undefined
|
||||
): any[] => {
|
||||
sortColumn = sortColumn ?? defaultSortColumn
|
||||
sortOrder = sortOrder ?? defaultSortOrder
|
||||
if (!sortColumn || !sortOrder || disableSorting) {
|
||||
|
@ -180,7 +195,7 @@
|
|||
})
|
||||
}
|
||||
|
||||
const sortBy = fieldSchema => {
|
||||
const sortBy = (fieldSchema: Record<string, any>): void => {
|
||||
if (fieldSchema.sortable === false) {
|
||||
return
|
||||
}
|
||||
|
@ -193,7 +208,7 @@
|
|||
dispatch("sort", { column: sortColumn, order: sortOrder })
|
||||
}
|
||||
|
||||
const getDisplayName = schema => {
|
||||
const getDisplayName = (schema: Record<string, any>): string => {
|
||||
let name = schema?.displayName
|
||||
if (schema && name === undefined) {
|
||||
name = schema.name
|
||||
|
@ -201,9 +216,13 @@
|
|||
return name || ""
|
||||
}
|
||||
|
||||
const getFields = (schema, showAutoColumns, autoSortColumns) => {
|
||||
let columns = []
|
||||
let autoColumns = []
|
||||
const getFields = (
|
||||
schema: Record<string, any>,
|
||||
showAutoColumns: boolean,
|
||||
autoSortColumns: boolean
|
||||
): string[] => {
|
||||
let columns: any[] = []
|
||||
let autoColumns: any[] = []
|
||||
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
|
||||
if (!field || !fieldSchema) {
|
||||
return
|
||||
|
@ -235,17 +254,17 @@
|
|||
.map(column => column.name)
|
||||
}
|
||||
|
||||
const editColumn = (e, field) => {
|
||||
const editColumn = (e: Event, field: any): void => {
|
||||
e.stopPropagation()
|
||||
dispatch("editcolumn", field)
|
||||
}
|
||||
|
||||
const editRow = (e, row) => {
|
||||
const editRow = (e: Event, row: any): void => {
|
||||
e.stopPropagation()
|
||||
dispatch("editrow", cloneDeep(row))
|
||||
}
|
||||
|
||||
const toggleSelectRow = row => {
|
||||
const toggleSelectRow = (row: any): void => {
|
||||
if (!allowSelectRows) {
|
||||
return
|
||||
}
|
||||
|
@ -258,7 +277,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
const toggleSelectAll = e => {
|
||||
const toggleSelectAll = (e: CustomEvent): void => {
|
||||
const select = !!e.detail
|
||||
if (select) {
|
||||
// Add any rows which are not already in selected rows
|
||||
|
@ -278,8 +297,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
const computeCellStyles = schema => {
|
||||
let styles = {}
|
||||
const computeCellStyles = (
|
||||
schema: Record<string, any>
|
||||
): Record<string, string> => {
|
||||
let styles: Record<string, string> = {}
|
||||
Object.keys(schema || {}).forEach(field => {
|
||||
styles[field] = ""
|
||||
if (schema[field].color) {
|
||||
|
|
|
@ -1,28 +1,48 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/tabs/dist/index-vars.css"
|
||||
import { writable } from "svelte/store"
|
||||
import { onMount, setContext, createEventDispatcher } from "svelte"
|
||||
|
||||
export let selected
|
||||
export let vertical = false
|
||||
export let noPadding = false
|
||||
// added as a separate option as noPadding is used for vertical padding
|
||||
export let noHorizPadding = false
|
||||
export let quiet = false
|
||||
export let emphasized = false
|
||||
export let onTop = false
|
||||
export let size = "M"
|
||||
export let beforeSwitch = null
|
||||
interface TabInfo {
|
||||
width?: number
|
||||
height?: number
|
||||
left?: number
|
||||
top?: number
|
||||
}
|
||||
|
||||
let thisSelected = undefined
|
||||
interface TabState {
|
||||
title: string
|
||||
id: string
|
||||
emphasized: boolean
|
||||
info?: TabInfo
|
||||
}
|
||||
|
||||
export let selected: string
|
||||
export let vertical: boolean = false
|
||||
export let noPadding: boolean = false
|
||||
// added as a separate option as noPadding is used for vertical padding
|
||||
export let noHorizPadding: boolean = false
|
||||
export let quiet: boolean = false
|
||||
export let emphasized: boolean = false
|
||||
export let onTop: boolean = false
|
||||
export let size: "S" | "M" | "L" = "M"
|
||||
export let beforeSwitch: ((_title: string) => boolean) | null = null
|
||||
|
||||
let thisSelected: string | undefined = undefined
|
||||
let container: HTMLElement | undefined
|
||||
|
||||
let _id = id()
|
||||
const tab = writable({ title: selected, id: _id, emphasized })
|
||||
const tab = writable<TabState>({ title: selected, id: _id, emphasized })
|
||||
setContext("tab", tab)
|
||||
|
||||
let container
|
||||
let top: string | undefined
|
||||
let left: string | undefined
|
||||
let width: string | undefined
|
||||
let height: string | undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const dispatch = createEventDispatcher<{
|
||||
select: string
|
||||
}>()
|
||||
|
||||
$: {
|
||||
if (thisSelected !== selected) {
|
||||
|
@ -44,29 +64,34 @@
|
|||
}
|
||||
if ($tab.title !== thisSelected) {
|
||||
tab.update(state => {
|
||||
state.title = thisSelected
|
||||
state.title = thisSelected as string
|
||||
return state
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let top, left, width, height
|
||||
$: calculateIndicatorLength($tab)
|
||||
$: calculateIndicatorOffset($tab)
|
||||
$: $tab && calculateIndicatorLength()
|
||||
$: $tab && calculateIndicatorOffset()
|
||||
|
||||
function calculateIndicatorLength() {
|
||||
if (!vertical) {
|
||||
width = $tab.info?.width + "px"
|
||||
width = ($tab.info?.width ?? 0) + "px"
|
||||
} else {
|
||||
height = $tab.info?.height + 4 + "px"
|
||||
height = ($tab.info?.height ?? 0) + 4 + "px"
|
||||
}
|
||||
}
|
||||
|
||||
function calculateIndicatorOffset() {
|
||||
if (!vertical) {
|
||||
left = $tab.info?.left - container?.getBoundingClientRect().left + "px"
|
||||
left =
|
||||
($tab.info?.left ?? 0) -
|
||||
(container?.getBoundingClientRect().left ?? 0) +
|
||||
"px"
|
||||
} else {
|
||||
top = $tab.info?.top - container?.getBoundingClientRect().top + "px"
|
||||
top =
|
||||
($tab.info?.top ?? 0) -
|
||||
(container?.getBoundingClientRect().top ?? 0) +
|
||||
"px"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +100,7 @@
|
|||
calculateIndicatorOffset()
|
||||
})
|
||||
|
||||
function id() {
|
||||
function id(): string {
|
||||
return "_" + Math.random().toString(36).slice(2, 9)
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/tags/dist/index-vars.css"
|
||||
import Avatar from "../Avatar/Avatar.svelte"
|
||||
import ClearButton from "../ClearButton/ClearButton.svelte"
|
||||
|
||||
export let icon = ""
|
||||
export let avatar = ""
|
||||
export let invalid = false
|
||||
export let disabled = false
|
||||
export let closable = false
|
||||
export let icon: string = ""
|
||||
export let avatar: string = ""
|
||||
export let invalid: boolean = false
|
||||
export let disabled: boolean = false
|
||||
export let closable: boolean = false
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/tags/dist/index-vars.css"
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Icon from "../Icon/Icon.svelte"
|
||||
import AbsTooltip from "./AbsTooltip.svelte"
|
||||
|
||||
export let tooltip = ""
|
||||
export let size = "M"
|
||||
export let disabled = true
|
||||
export let tooltip: string = ""
|
||||
export let size: "S" | "M" = "M"
|
||||
export let disabled: boolean = true
|
||||
</script>
|
||||
|
||||
<div class:container={!!tooltip}>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<script>
|
||||
export let selected = false
|
||||
export let open = false
|
||||
export let href = false
|
||||
export let title
|
||||
export let icon
|
||||
<script lang="ts">
|
||||
export let selected: boolean = false
|
||||
export let open: boolean = false
|
||||
export let href: string | null = null
|
||||
export let title: string
|
||||
export let icon: string | undefined
|
||||
</script>
|
||||
|
||||
<li
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/treeview/dist/index-vars.css"
|
||||
|
||||
export let quiet = false
|
||||
export let standalone = true
|
||||
export let width = "250px"
|
||||
export let quiet: boolean = false
|
||||
export let standalone: boolean = true
|
||||
export let width: string = "250px"
|
||||
</script>
|
||||
|
||||
<ul
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/typography/dist/index-vars.css"
|
||||
|
||||
// Sizes
|
||||
export let size = "M"
|
||||
export let size: "S" | "M" | "L" = "M"
|
||||
</script>
|
||||
|
||||
<code class="spectrum-Code spectrum-Code--size{size}">
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/typography/dist/index-vars.css"
|
||||
|
||||
export let size = "M"
|
||||
export let serif = false
|
||||
export let weight = 600
|
||||
export let size: "S" | "M" | "L" = "M"
|
||||
export let serif: boolean = false
|
||||
export let weight: number | null = null
|
||||
</script>
|
||||
|
||||
<p
|
||||
|
|
|
@ -65,8 +65,6 @@ export { default as Modal } from "./Modal/Modal.svelte"
|
|||
export { default as ModalContent, keepOpen } from "./Modal/ModalContent.svelte"
|
||||
export { default as NotificationDisplay } from "./Notification/NotificationDisplay.svelte"
|
||||
export { default as Notification } from "./Notification/Notification.svelte"
|
||||
export { default as SideNavigation } from "./SideNavigation/Navigation.svelte"
|
||||
export { default as SideNavigationItem } from "./SideNavigation/Item.svelte"
|
||||
export { default as Context } from "./context"
|
||||
export { default as Table } from "./Table/Table.svelte"
|
||||
export { default as Tabs } from "./Tabs/Tabs.svelte"
|
||||
|
|
|
@ -2,6 +2,7 @@ import { FieldType } from "@budibase/types"
|
|||
import { FIELDS } from "@/constants/backend"
|
||||
import { tables } from "@/stores/builder"
|
||||
import { get as svelteGet } from "svelte/store"
|
||||
import { makeReadableKeyPropSafe } from "@/dataBinding"
|
||||
|
||||
// currently supported level of relationship depth (server side)
|
||||
const MAX_DEPTH = 1
|
||||
|
@ -26,7 +27,7 @@ export function getBindings({
|
|||
if (!table) {
|
||||
return bindings
|
||||
}
|
||||
for (let [column, schema] of Object.entries(table.schema)) {
|
||||
for (const [column, schema] of Object.entries(table.schema)) {
|
||||
const isRelationship = schema.type === FieldType.LINK
|
||||
// skip relationships after a certain depth and types which
|
||||
// can't bind to
|
||||
|
@ -62,6 +63,10 @@ export function getBindings({
|
|||
|
||||
const label = path == null ? column : `${path}.0.${column}`
|
||||
const binding = path == null ? `[${column}]` : `[${path}].0.[${column}]`
|
||||
const readableBinding = (path == null ? [column] : [path, "0", column])
|
||||
.map(makeReadableKeyPropSafe)
|
||||
.join(".")
|
||||
|
||||
// only supply a description for relationship paths
|
||||
const description =
|
||||
path == null
|
||||
|
@ -75,7 +80,7 @@ export function getBindings({
|
|||
description,
|
||||
// don't include path, it messes things up, relationship path
|
||||
// will be replaced by the main array binding
|
||||
readableBinding: label,
|
||||
readableBinding,
|
||||
runtimeBinding: binding,
|
||||
display: {
|
||||
name: label,
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
import type { EditorMode } from "@budibase/types"
|
||||
import type { BindingCompletion, CodeValidator } from "@/types"
|
||||
import { validateHbsTemplate } from "./validator/hbs"
|
||||
import { validateJsTemplate } from "./validator/js"
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let completions: BindingCompletion[] = []
|
||||
|
@ -356,6 +357,9 @@
|
|||
if (mode === EditorModes.Handlebars) {
|
||||
const diagnostics = validateHbsTemplate(value, validations)
|
||||
editor.dispatch(setDiagnostics(editor.state, diagnostics))
|
||||
} else if (mode === EditorModes.JS) {
|
||||
const diagnostics = validateJsTemplate(value, validations)
|
||||
editor.dispatch(setDiagnostics(editor.state, diagnostics))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,10 @@ export function validateHbsTemplate(
|
|||
) {
|
||||
const ignoreMissing = options?.ignoreMissing || false
|
||||
nodes.forEach(node => {
|
||||
if (isMustacheStatement(node) && isPathExpression(node.path)) {
|
||||
if (
|
||||
(isMustacheStatement(node) || isBlockStatement(node)) &&
|
||||
isPathExpression(node.path)
|
||||
) {
|
||||
const helperName = node.path.original
|
||||
|
||||
const from =
|
||||
|
@ -75,21 +78,64 @@ export function validateHbsTemplate(
|
|||
message: `Helper "${helperName}" requires a body:\n{{#${helperName} ...}} [body] {{/${helperName}}}`,
|
||||
})
|
||||
return
|
||||
} else if (!requiresBlock && isBlockStatement(node)) {
|
||||
diagnostics.push({
|
||||
from,
|
||||
to,
|
||||
severity: "error",
|
||||
message: `Helper "${helperName}" should not contain a body.`,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const providedParams = node.params
|
||||
let providedParamsCount = node.params.length
|
||||
if (isBlockStatement(node)) {
|
||||
// Block body counts as a parameter
|
||||
providedParamsCount++
|
||||
}
|
||||
|
||||
if (providedParams.length !== expectedArguments.length) {
|
||||
const optionalArgMatcher = new RegExp(/^\[(.+)\]$/)
|
||||
const optionalArgs = expectedArguments.filter(a =>
|
||||
optionalArgMatcher.test(a)
|
||||
)
|
||||
|
||||
if (
|
||||
!optionalArgs.length &&
|
||||
providedParamsCount !== expectedArguments.length
|
||||
) {
|
||||
diagnostics.push({
|
||||
from,
|
||||
to,
|
||||
severity: "error",
|
||||
message: `Helper "${helperName}" expects ${
|
||||
expectedArguments.length
|
||||
} parameters (${expectedArguments.join(", ")}), but got ${
|
||||
providedParams.length
|
||||
}.`,
|
||||
} parameters (${expectedArguments.join(
|
||||
", "
|
||||
)}), but got ${providedParamsCount}.`,
|
||||
})
|
||||
} else if (optionalArgs.length) {
|
||||
const maxArgs = expectedArguments.length
|
||||
const minArgs = maxArgs - optionalArgs.length
|
||||
if (
|
||||
minArgs > providedParamsCount ||
|
||||
maxArgs < providedParamsCount
|
||||
) {
|
||||
const parameters = expectedArguments
|
||||
.map(a => {
|
||||
const test = optionalArgMatcher.exec(a)
|
||||
if (!test?.[1]) {
|
||||
return a
|
||||
}
|
||||
return `${test[1]} (optional)`
|
||||
})
|
||||
.join(", ")
|
||||
diagnostics.push({
|
||||
from,
|
||||
to,
|
||||
severity: "error",
|
||||
message: `Helper "${helperName}" expects between ${minArgs} to ${expectedArguments.length} parameters (${parameters}), but got ${providedParamsCount}.`,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
import { Parser } from "acorn"
|
||||
import * as walk from "acorn-walk"
|
||||
|
||||
import type { Diagnostic } from "@codemirror/lint"
|
||||
import { CodeValidator } from "@/types"
|
||||
|
||||
export function validateJsTemplate(
|
||||
code: string,
|
||||
validations: CodeValidator
|
||||
): Diagnostic[] {
|
||||
const diagnostics: Diagnostic[] = []
|
||||
|
||||
try {
|
||||
const ast = Parser.parse(code, {
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
allowReturnOutsideFunction: true,
|
||||
})
|
||||
|
||||
const lineOffsets: number[] = []
|
||||
let offset = 0
|
||||
for (const line of code.split("\n")) {
|
||||
lineOffsets.push(offset)
|
||||
offset += line.length + 1 // +1 for newline character
|
||||
}
|
||||
|
||||
let hasReturnStatement = false
|
||||
walk.ancestor(ast, {
|
||||
ReturnStatement(node, _state, ancestors) {
|
||||
if (
|
||||
// it returns a value
|
||||
node.argument &&
|
||||
// and it is top level
|
||||
ancestors.length === 2 &&
|
||||
ancestors[0].type === "Program" &&
|
||||
ancestors[1].type === "ReturnStatement"
|
||||
) {
|
||||
hasReturnStatement = true
|
||||
}
|
||||
},
|
||||
CallExpression(node) {
|
||||
const callee: any = node.callee
|
||||
if (
|
||||
node.type === "CallExpression" &&
|
||||
callee.object?.name === "helpers" &&
|
||||
node.loc
|
||||
) {
|
||||
const functionName = callee.property.name
|
||||
const from =
|
||||
lineOffsets[node.loc.start.line - 1] + node.loc.start.column
|
||||
const to = lineOffsets[node.loc.end.line - 1] + node.loc.end.column
|
||||
|
||||
if (!(functionName in validations)) {
|
||||
diagnostics.push({
|
||||
from,
|
||||
to,
|
||||
severity: "warning",
|
||||
message: `"${functionName}" function does not exist.`,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const { arguments: expectedArguments } = validations[functionName]
|
||||
if (
|
||||
expectedArguments &&
|
||||
node.arguments.length !== expectedArguments.length
|
||||
) {
|
||||
diagnostics.push({
|
||||
from,
|
||||
to,
|
||||
severity: "error",
|
||||
message: `Function "${functionName}" expects ${
|
||||
expectedArguments.length
|
||||
} parameters (${expectedArguments.join(", ")}), but got ${
|
||||
node.arguments.length
|
||||
}.`,
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (!hasReturnStatement) {
|
||||
diagnostics.push({
|
||||
from: 0,
|
||||
to: code.length,
|
||||
severity: "error",
|
||||
message: "Your code must return a value.",
|
||||
})
|
||||
}
|
||||
} catch (e: any) {
|
||||
diagnostics.push({
|
||||
from: 0,
|
||||
to: code.length,
|
||||
severity: "error",
|
||||
message: `Syntax error: ${e.message}`,
|
||||
})
|
||||
}
|
||||
|
||||
return diagnostics
|
||||
}
|
|
@ -2,7 +2,7 @@ import { validateHbsTemplate } from "../hbs"
|
|||
import { CodeValidator } from "@/types"
|
||||
|
||||
describe("hbs validator", () => {
|
||||
it("validate empty strings", () => {
|
||||
it("validates empty strings", () => {
|
||||
const text = ""
|
||||
const validators = {}
|
||||
|
||||
|
@ -10,7 +10,7 @@ describe("hbs validator", () => {
|
|||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("validate strings without hbs expressions", () => {
|
||||
it("validates strings without hbs expressions", () => {
|
||||
const text = "first line\nand another one"
|
||||
const validators = {}
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe("hbs validator", () => {
|
|||
fieldName: {},
|
||||
}
|
||||
|
||||
it("validate valid expressions", () => {
|
||||
it("validates valid expressions", () => {
|
||||
const text = "{{ fieldName }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
|
@ -98,13 +98,14 @@ describe("hbs validator", () => {
|
|||
})
|
||||
|
||||
describe("expressions with parameters", () => {
|
||||
describe("basic expression", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "c"],
|
||||
},
|
||||
}
|
||||
|
||||
it("validate valid params", () => {
|
||||
it("validates valid params", () => {
|
||||
const text = "{{ helperFunction 1 99 'a' }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
|
@ -139,4 +140,151 @@ describe("hbs validator", () => {
|
|||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("body expressions", () => {
|
||||
const validators: CodeValidator = {
|
||||
bodyFunction: {
|
||||
arguments: ["a", "b", "c"],
|
||||
requiresBlock: true,
|
||||
},
|
||||
nonBodyFunction: {
|
||||
arguments: ["a", "b"],
|
||||
},
|
||||
}
|
||||
|
||||
it("validates valid params", () => {
|
||||
const text = "{{#bodyFunction 1 99 }}body{{/bodyFunction}}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("validates empty bodies", () => {
|
||||
const text = "{{#bodyFunction 1 99 }}{{/bodyFunction}}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("validates too little parameters", () => {
|
||||
const text = "{{#bodyFunction 1 }}{{/bodyFunction}}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `Helper "bodyFunction" expects 3 parameters (a, b, c), but got 2.`,
|
||||
severity: "error",
|
||||
to: 37,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates too many parameters", () => {
|
||||
const text = "{{#bodyFunction 1 99 'a' 0 }}{{/bodyFunction}}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `Helper "bodyFunction" expects 3 parameters (a, b, c), but got 5.`,
|
||||
severity: "error",
|
||||
to: 46,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates non-supported body usages", () => {
|
||||
const text = "{{#nonBodyFunction 1 99}}{{/nonBodyFunction}}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `Helper "nonBodyFunction" should not contain a body.`,
|
||||
severity: "error",
|
||||
to: 45,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("optional parameters", () => {
|
||||
it("supports empty parameters", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "[c]"],
|
||||
},
|
||||
}
|
||||
const text = "{{ helperFunction 1 99 }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("supports valid parameters", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "[c]"],
|
||||
},
|
||||
}
|
||||
const text = "{{ helperFunction 1 99 'a' }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("returns a valid message on missing parameters", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "[c]"],
|
||||
},
|
||||
}
|
||||
const text = "{{ helperFunction 1 }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `Helper "helperFunction" expects between 2 to 3 parameters (a, b, c (optional)), but got 1.`,
|
||||
severity: "error",
|
||||
to: 22,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a valid message on too many parameters", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "[c]"],
|
||||
},
|
||||
}
|
||||
const text = "{{ helperFunction 1 2 3 4 }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `Helper "helperFunction" expects between 2 to 3 parameters (a, b, c (optional)), but got 4.`,
|
||||
severity: "error",
|
||||
to: 28,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("validates wrong hbs code", () => {
|
||||
const text = "{{#fieldName}}{{/wrong}}"
|
||||
|
||||
const result = validateHbsTemplate(text, {})
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `The handlebars code is not valid:\nfieldName doesn't match wrong - 1:3`,
|
||||
severity: "error",
|
||||
to: text.length,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
import { validateJsTemplate } from "../js"
|
||||
import { CodeValidator } from "@/types"
|
||||
|
||||
describe("js validator", () => {
|
||||
it("validates valid code", () => {
|
||||
const text = "return 7"
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("does not validate runtime errors", () => {
|
||||
const text = "return a"
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("validates multiline code", () => {
|
||||
const text = "const foo='bar'\nreturn 123"
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("allows return not being on the last line", () => {
|
||||
const text = "const foo='bar'\nreturn 123\nconsole.log(foo)"
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("throws on missing return", () => {
|
||||
const text = "const foo='bar'\nbar='foo'"
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: "Your code must return a value.",
|
||||
severity: "error",
|
||||
to: 25,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("checks that returns are at top level", () => {
|
||||
const text = `
|
||||
function call(){
|
||||
return 1
|
||||
}`
|
||||
const validators = {}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: "Your code must return a value.",
|
||||
severity: "error",
|
||||
to: text.length,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
describe("helpers", () => {
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "c"],
|
||||
},
|
||||
}
|
||||
|
||||
it("validates helpers with valid params", () => {
|
||||
const text = "return helpers.helperFunction(1, 99, 'a')"
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("throws on too few params", () => {
|
||||
const text = "return helpers.helperFunction(100)"
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 7,
|
||||
message: `Function "helperFunction" expects 3 parameters (a, b, c), but got 1.`,
|
||||
severity: "error",
|
||||
to: 34,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("throws on too many params", () => {
|
||||
const text = "return helpers.helperFunction( 1, 99, 'a', 100)"
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 7,
|
||||
message: `Function "helperFunction" expects 3 parameters (a, b, c), but got 4.`,
|
||||
severity: "error",
|
||||
to: 47,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates helpers on inner functions", () => {
|
||||
const text = `function call(){
|
||||
return helpers.helperFunction(1, 99)
|
||||
}
|
||||
return call()`
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 46,
|
||||
message: `Function "helperFunction" expects 3 parameters (a, b, c), but got 2.`,
|
||||
severity: "error",
|
||||
to: 75,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("validates multiple helpers", () => {
|
||||
const text =
|
||||
"return helpers.helperFunction(1, 99, 'a') + helpers.helperFunction(1) + helpers.another(1) + helpers.another()"
|
||||
const validators: CodeValidator = {
|
||||
helperFunction: {
|
||||
arguments: ["a", "b", "c"],
|
||||
},
|
||||
another: { arguments: [] },
|
||||
}
|
||||
|
||||
const result = validateJsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 44,
|
||||
message: `Function "helperFunction" expects 3 parameters (a, b, c), but got 1.`,
|
||||
severity: "error",
|
||||
to: 69,
|
||||
},
|
||||
{
|
||||
from: 72,
|
||||
message: `Function "another" expects 0 parameters (), but got 1.`,
|
||||
severity: "error",
|
||||
to: 90,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -90,7 +90,7 @@
|
|||
$: requestEval(runtimeExpression, context, snippets)
|
||||
$: bindingHelpers = new BindingHelpers(getCaretPosition, insertAtPos)
|
||||
|
||||
$: bindingOptions = bindingsToCompletions(bindings, editorMode)
|
||||
$: bindingOptions = bindingsToCompletions(enrichedBindings, editorMode)
|
||||
$: helperOptions = allowHelpers ? getHelperCompletions(editorMode) : []
|
||||
$: snippetsOptions =
|
||||
usingJS && allowSnippets && !$licensing.isFreePlan && snippets?.length
|
||||
|
@ -372,6 +372,7 @@
|
|||
value={jsValue ? decodeJSBinding(jsValue) : jsValue}
|
||||
on:change={onChangeJSValue}
|
||||
{completions}
|
||||
{validations}
|
||||
mode={EditorModes.JS}
|
||||
bind:getCaretPosition
|
||||
bind:insertAtPos
|
||||
|
|
|
@ -373,6 +373,18 @@ const getContextBindings = (asset, componentId) => {
|
|||
.flat()
|
||||
}
|
||||
|
||||
export const makeReadableKeyPropSafe = key => {
|
||||
if (!key.includes(" ")) {
|
||||
return key
|
||||
}
|
||||
|
||||
if (new RegExp(/^\[(.+)\]$/).test(key.test)) {
|
||||
return key
|
||||
}
|
||||
|
||||
return `[${key}]`
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of bindings for a given component context
|
||||
*/
|
||||
|
@ -457,11 +469,11 @@ const generateComponentContextBindings = (asset, componentContext) => {
|
|||
const runtimeBinding = `${safeComponentId}.${safeKey}`
|
||||
|
||||
// Optionally use a prefix with readable bindings
|
||||
let readableBinding = component._instanceName
|
||||
let readableBinding = makeReadableKeyPropSafe(component._instanceName)
|
||||
if (readablePrefix) {
|
||||
readableBinding += `.${readablePrefix}`
|
||||
}
|
||||
readableBinding += `.${fieldSchema.name || key}`
|
||||
readableBinding += `.${makeReadableKeyPropSafe(fieldSchema.name || key)}`
|
||||
|
||||
// Determine which category this binding belongs in
|
||||
const bindingCategory = getComponentBindingCategory(
|
||||
|
@ -473,7 +485,7 @@ const generateComponentContextBindings = (asset, componentContext) => {
|
|||
bindings.push({
|
||||
type: "context",
|
||||
runtimeBinding,
|
||||
readableBinding: `${readableBinding}`,
|
||||
readableBinding,
|
||||
// Field schema and provider are required to construct relationship
|
||||
// datasource options, based on bindable properties
|
||||
fieldSchema,
|
||||
|
@ -1354,13 +1366,14 @@ const bindingReplacement = (
|
|||
}
|
||||
// work from longest to shortest
|
||||
const convertFromProps = bindableProperties
|
||||
// TODO check whitespaces
|
||||
.map(el => el[convertFrom])
|
||||
.sort((a, b) => {
|
||||
return b.length - a.length
|
||||
})
|
||||
const boundValues = textWithBindings.match(regex) || []
|
||||
let result = textWithBindings
|
||||
for (let boundValue of boundValues) {
|
||||
for (const boundValue of boundValues) {
|
||||
let newBoundValue = boundValue
|
||||
// we use a search string, where any time we replace something we blank it out
|
||||
// in the search, working from longest to shortest so always use best match first
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<script>
|
||||
import { Icon } from "@budibase/bbui"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
|
||||
export let groups = []
|
||||
function tooltip(groups) {
|
||||
const sortedNames = groups
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map(group => group.name)
|
||||
return `Member of ${helpers.lists.punctuateList(sortedNames)}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="icon">
|
||||
<Icon
|
||||
name="Info"
|
||||
size="XS"
|
||||
color="grey"
|
||||
hoverable
|
||||
tooltip={tooltip(groups)}
|
||||
tooltipPosition="top"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.icon {
|
||||
height: auto;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
|
@ -37,6 +37,7 @@
|
|||
import { emailValidator } from "@/helpers/validation"
|
||||
import { fly } from "svelte/transition"
|
||||
import InfoDisplay from "../design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte"
|
||||
import BuilderGroupPopover from "./BuilderGroupPopover.svelte"
|
||||
|
||||
let query = null
|
||||
let loaded = false
|
||||
|
@ -197,12 +198,19 @@
|
|||
return
|
||||
}
|
||||
const update = await users.get(user._id)
|
||||
await users.save({
|
||||
...update,
|
||||
roles: {
|
||||
const newRoles = {
|
||||
...update.roles,
|
||||
[prodAppId]: role,
|
||||
},
|
||||
}
|
||||
// make sure no undefined/null roles (during removal)
|
||||
for (let [appId, role] of Object.entries(newRoles)) {
|
||||
if (!role) {
|
||||
delete newRoles[appId]
|
||||
}
|
||||
}
|
||||
await users.save({
|
||||
...update,
|
||||
roles: newRoles,
|
||||
})
|
||||
await searchUsers(query, $builderStore.builderSidePanel, loaded)
|
||||
}
|
||||
|
@ -539,6 +547,10 @@
|
|||
creationAccessType = Constants.Roles.CREATOR
|
||||
}
|
||||
}
|
||||
|
||||
const itemCountText = (word, count) => {
|
||||
return `${count} ${word}${count !== 1 ? "s" : ""}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeyDown} />
|
||||
|
@ -701,13 +713,11 @@
|
|||
>
|
||||
<div class="details">
|
||||
<GroupIcon {group} size="S" />
|
||||
<div>
|
||||
<div class="group-name">
|
||||
{group.name}
|
||||
</div>
|
||||
<div class="auth-entity-meta">
|
||||
{`${group.users?.length} user${
|
||||
group.users?.length != 1 ? "s" : ""
|
||||
}`}
|
||||
{itemCountText("user", group.users?.length)}
|
||||
</div>
|
||||
</div>
|
||||
<div class="auth-entity-access">
|
||||
|
@ -741,16 +751,33 @@
|
|||
<div class="auth-entity-access-title">Access</div>
|
||||
</div>
|
||||
{#each allUsers as user}
|
||||
{@const userGroups = sdk.users.getUserAppGroups(
|
||||
$appStore.appId,
|
||||
user,
|
||||
$groups
|
||||
)}
|
||||
<div class="auth-entity">
|
||||
<div class="details">
|
||||
<div class="user-groups">
|
||||
<div class="user-email" title={user.email}>
|
||||
{user.email}
|
||||
</div>
|
||||
{#if userGroups.length}
|
||||
<div class="group-info">
|
||||
<div class="auth-entity-meta">
|
||||
{itemCountText("group", userGroups.length)}
|
||||
</div>
|
||||
<BuilderGroupPopover groups={userGroups} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="auth-entity-access" class:muted={user.group}>
|
||||
<RoleSelect
|
||||
footer={getRoleFooter(user)}
|
||||
placeholder={false}
|
||||
placeholder={userGroups?.length
|
||||
? "Controlled by group"
|
||||
: false}
|
||||
value={parseRole(user)}
|
||||
allowRemove={user.role && !user.group}
|
||||
allowPublic={false}
|
||||
|
@ -915,6 +942,7 @@
|
|||
color: var(--spectrum-global-color-gray-600);
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
.auth-entity-access {
|
||||
|
@ -931,7 +959,7 @@
|
|||
|
||||
.auth-entity,
|
||||
.auth-entity-header {
|
||||
padding: 0px var(--spacing-xl);
|
||||
padding: 0 var(--spacing-xl);
|
||||
}
|
||||
|
||||
.auth-entity,
|
||||
|
@ -946,15 +974,17 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-m);
|
||||
color: var(--spectrum-global-color-gray-900);
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.auth-entity .user-email {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
.auth-entity .user-email,
|
||||
.group-name {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: var(--spectrum-global-color-gray-900);
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
#builder-side-panel-container {
|
||||
|
@ -1048,4 +1078,23 @@
|
|||
.alert {
|
||||
padding: 0 var(--spacing-xl);
|
||||
}
|
||||
|
||||
.user-groups {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: var(--spacing-m);
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: var(--spacing-xs);
|
||||
justify-content: end;
|
||||
width: 60px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -98,7 +98,9 @@
|
|||
$: privileged = sdk.users.isAdminOrGlobalBuilder(user)
|
||||
$: nameLabel = getNameLabel(user)
|
||||
$: filteredGroups = getFilteredGroups(internalGroups, searchTerm)
|
||||
$: availableApps = getAvailableApps($appsStore.apps, privileged, user?.roles)
|
||||
$: availableApps = user
|
||||
? getApps(user, sdk.users.userAppAccessList(user, $groups || []))
|
||||
: []
|
||||
$: userGroups = $groups.filter(x => {
|
||||
return x.users?.find(y => {
|
||||
return y._id === userId
|
||||
|
@ -107,23 +109,19 @@
|
|||
$: globalRole = users.getUserRole(user)
|
||||
$: isTenantOwner = tenantOwner?.email && tenantOwner.email === user?.email
|
||||
|
||||
const getAvailableApps = (appList, privileged, roles) => {
|
||||
let availableApps = appList.slice()
|
||||
if (!privileged) {
|
||||
availableApps = availableApps.filter(x => {
|
||||
let roleKeys = Object.keys(roles || {})
|
||||
return roleKeys.concat(user?.builder?.apps).find(y => {
|
||||
return x.appId === appsStore.extractAppId(y)
|
||||
})
|
||||
})
|
||||
}
|
||||
const getApps = (user, appIds) => {
|
||||
let availableApps = $appsStore.apps
|
||||
.slice()
|
||||
.filter(app =>
|
||||
appIds.find(id => id === appsStore.getProdAppID(app.devId))
|
||||
)
|
||||
return availableApps.map(app => {
|
||||
const prodAppId = appsStore.getProdAppID(app.devId)
|
||||
return {
|
||||
name: app.name,
|
||||
devId: app.devId,
|
||||
icon: app.icon,
|
||||
role: getRole(prodAppId, roles),
|
||||
role: getRole(prodAppId, user),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -136,7 +134,7 @@
|
|||
return groups.filter(group => group.name?.toLowerCase().includes(search))
|
||||
}
|
||||
|
||||
const getRole = (prodAppId, roles) => {
|
||||
const getRole = (prodAppId, user) => {
|
||||
if (privileged) {
|
||||
return Constants.Roles.ADMIN
|
||||
}
|
||||
|
@ -145,7 +143,21 @@
|
|||
return Constants.Roles.CREATOR
|
||||
}
|
||||
|
||||
return roles[prodAppId]
|
||||
if (user?.roles[prodAppId]) {
|
||||
return user.roles[prodAppId]
|
||||
}
|
||||
|
||||
// check if access via group for creator
|
||||
const foundGroup = $groups?.find(
|
||||
group => group.roles[prodAppId] || group.builder?.apps[prodAppId]
|
||||
)
|
||||
if (foundGroup.builder?.apps[prodAppId]) {
|
||||
return Constants.Roles.CREATOR
|
||||
}
|
||||
// can't tell how groups will control role
|
||||
if (foundGroup.roles[prodAppId]) {
|
||||
return Constants.Roles.GROUP
|
||||
}
|
||||
}
|
||||
|
||||
const getNameLabel = user => {
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
{#if value === Constants.Roles.CREATOR}
|
||||
{#if value === Constants.Roles.GROUP}
|
||||
Controlled by group
|
||||
{:else if value === Constants.Roles.CREATOR}
|
||||
Can edit
|
||||
{:else}
|
||||
<StatusLight
|
||||
|
|
|
@ -128,7 +128,7 @@
|
|||
$auth.user?.email === user.email
|
||||
? false
|
||||
: true,
|
||||
apps: [...new Set(Object.keys(user.roles))],
|
||||
apps: sdk.users.userAppAccessList(user, $groups),
|
||||
access: role.sortOrder,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -484,7 +484,7 @@ const automationActions = (store: AutomationStore) => ({
|
|||
branches.forEach((branch, bIdx) => {
|
||||
children[branch.id].forEach(
|
||||
(bBlock: AutomationStep, sIdx: number, array: AutomationStep[]) => {
|
||||
const ended = array.length - 1 === sIdx && !branches.length
|
||||
const ended = array.length - 1 === sIdx
|
||||
treeTraverse(bBlock, pathToCurrentNode, sIdx, bIdx, ended)
|
||||
}
|
||||
)
|
||||
|
@ -505,7 +505,6 @@ const automationActions = (store: AutomationStore) => ({
|
|||
blocks.forEach((block, idx, array) => {
|
||||
treeTraverse(block, null, idx, null, array.length - 1 === idx)
|
||||
})
|
||||
|
||||
return blockRefs
|
||||
},
|
||||
|
||||
|
|
|
@ -81,11 +81,11 @@ export const screenComponentErrorList = derived(
|
|||
const errors: UIComponentError[] = []
|
||||
|
||||
function checkComponentErrors(component: Component, ancestors: string[]) {
|
||||
errors.push(...getMissingAncestors(component, definitions, ancestors))
|
||||
errors.push(
|
||||
...getInvalidDatasources(screen, component, datasources, definitions)
|
||||
)
|
||||
errors.push(...getMissingRequiredSettings(component, definitions))
|
||||
errors.push(...getMissingAncestors(component, definitions, ancestors))
|
||||
|
||||
for (const child of component._children || []) {
|
||||
checkComponentErrors(child, [...ancestors, component._component])
|
||||
|
@ -239,7 +239,10 @@ function getMissingAncestors(
|
|||
ancestors: string[]
|
||||
): UIComponentError[] {
|
||||
const definition = definitions[component._component]
|
||||
|
||||
if (ancestors.some(a => !a.startsWith(BudibasePrefix))) {
|
||||
// We don't have a way to know what components are used within a plugin component
|
||||
return []
|
||||
}
|
||||
if (!definition?.requiredAncestors?.length) {
|
||||
return []
|
||||
}
|
||||
|
|
|
@ -4492,6 +4492,12 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"label": "Zoom level",
|
||||
"key": "defaultZoom",
|
||||
"defaultValue": "1"
|
||||
},
|
||||
{
|
||||
"type": "event",
|
||||
"label": "On change",
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"apexcharts": "^3.48.0",
|
||||
"dayjs": "^1.10.8",
|
||||
"downloadjs": "1.4.7",
|
||||
"html5-qrcode": "^2.2.1",
|
||||
"html5-qrcode": "^2.3.8",
|
||||
"leaflet": "^1.7.1",
|
||||
"sanitize-html": "^2.13.0",
|
||||
"screenfull": "^6.0.1",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
export let beepFrequency = 2637
|
||||
export let customFrequency = 1046
|
||||
export let preferredCamera = "environment"
|
||||
export let defaultZoom = 1
|
||||
export let validator
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
@ -58,6 +59,14 @@
|
|||
html5QrCode
|
||||
.start(cameraSetting, cameraConfig, onScanSuccess)
|
||||
.then(() => {
|
||||
if (defaultZoom > 1) {
|
||||
const cameraOptions =
|
||||
html5QrCode.getRunningTrackCameraCapabilities()
|
||||
const zoom = cameraOptions.zoomFeature()
|
||||
if (zoom.isSupported()) {
|
||||
zoom.apply(defaultZoom)
|
||||
}
|
||||
}
|
||||
resolve({ initialised: true })
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
export let beepFrequency
|
||||
export let customFrequency
|
||||
export let preferredCamera
|
||||
export let defaultZoom
|
||||
export let helpText = null
|
||||
|
||||
let fieldState
|
||||
|
@ -56,6 +57,7 @@
|
|||
{beepFrequency}
|
||||
{customFrequency}
|
||||
{preferredCamera}
|
||||
{defaultZoom}
|
||||
validator={fieldState.validator}
|
||||
/>
|
||||
{/if}
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
import ClientApp from "./components/ClientApp.svelte"
|
||||
import UpdatingApp from "./components/UpdatingApp.svelte"
|
||||
import {
|
||||
builderStore,
|
||||
appStore,
|
||||
blockStore,
|
||||
componentStore,
|
||||
environmentStore,
|
||||
dndStore,
|
||||
eventStore,
|
||||
hoverStore,
|
||||
stateStore,
|
||||
routeStore,
|
||||
} from "./stores"
|
||||
import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-vite.js"
|
||||
import { get } from "svelte/store"
|
||||
import { initWebsocket } from "./websocket.js"
|
||||
|
||||
// Provide svelte and svelte/internal as globals for custom components
|
||||
import * as svelte from "svelte"
|
||||
import * as internal from "svelte/internal"
|
||||
|
||||
window.svelte_internal = internal
|
||||
window.svelte = svelte
|
||||
|
||||
// Initialise spectrum icons
|
||||
loadSpectrumIcons()
|
||||
|
||||
let app
|
||||
|
||||
const loadBudibase = async () => {
|
||||
// Update builder store with any builder flags
|
||||
builderStore.set({
|
||||
...get(builderStore),
|
||||
inBuilder: !!window["##BUDIBASE_IN_BUILDER##"],
|
||||
layout: window["##BUDIBASE_PREVIEW_LAYOUT##"],
|
||||
screen: window["##BUDIBASE_PREVIEW_SCREEN##"],
|
||||
selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"],
|
||||
previewId: window["##BUDIBASE_PREVIEW_ID##"],
|
||||
theme: window["##BUDIBASE_PREVIEW_THEME##"],
|
||||
customTheme: window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"],
|
||||
previewDevice: window["##BUDIBASE_PREVIEW_DEVICE##"],
|
||||
navigation: window["##BUDIBASE_PREVIEW_NAVIGATION##"],
|
||||
hiddenComponentIds: window["##BUDIBASE_HIDDEN_COMPONENT_IDS##"],
|
||||
usedPlugins: window["##BUDIBASE_USED_PLUGINS##"],
|
||||
location: window["##BUDIBASE_LOCATION##"],
|
||||
snippets: window["##BUDIBASE_SNIPPETS##"],
|
||||
componentErrors: window["##BUDIBASE_COMPONENT_ERRORS##"],
|
||||
})
|
||||
|
||||
// Set app ID - this window flag is set by both the preview and the real
|
||||
// server rendered app HTML
|
||||
appStore.actions.setAppId(window["##BUDIBASE_APP_ID##"])
|
||||
|
||||
// Set the flag used to determine if the app is being loaded via an iframe
|
||||
appStore.actions.setAppEmbedded(
|
||||
window["##BUDIBASE_APP_EMBEDDED##"] === "true"
|
||||
)
|
||||
|
||||
if (window.MIGRATING_APP) {
|
||||
new UpdatingApp({
|
||||
target: window.document.body,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch environment info
|
||||
if (!get(environmentStore)?.loaded) {
|
||||
await environmentStore.actions.fetchEnvironment()
|
||||
}
|
||||
|
||||
// Register handler for runtime events from the builder
|
||||
window.handleBuilderRuntimeEvent = (type, data) => {
|
||||
if (!window["##BUDIBASE_IN_BUILDER##"]) {
|
||||
return
|
||||
}
|
||||
if (type === "event-completed") {
|
||||
eventStore.actions.resolveEvent(data)
|
||||
} else if (type === "eject-block") {
|
||||
const block = blockStore.actions.getBlock(data)
|
||||
block?.eject()
|
||||
} else if (type === "dragging-new-component") {
|
||||
const { dragging, component } = data
|
||||
if (dragging) {
|
||||
const definition =
|
||||
componentStore.actions.getComponentDefinition(component)
|
||||
dndStore.actions.startDraggingNewComponent({ component, definition })
|
||||
} else {
|
||||
dndStore.actions.reset()
|
||||
}
|
||||
} else if (type === "request-context") {
|
||||
const { selectedComponentInstance, screenslotInstance } =
|
||||
get(componentStore)
|
||||
const instance = selectedComponentInstance || screenslotInstance
|
||||
const context = instance?.getDataContext()
|
||||
let stringifiedContext = null
|
||||
try {
|
||||
stringifiedContext = JSON.stringify(context)
|
||||
} catch (error) {
|
||||
// Ignore - invalid context
|
||||
}
|
||||
eventStore.actions.dispatchEvent("provide-context", {
|
||||
context: stringifiedContext,
|
||||
})
|
||||
} else if (type === "hover-component") {
|
||||
hoverStore.actions.hoverComponent(data, false)
|
||||
} else if (type === "builder-meta") {
|
||||
builderStore.actions.setMetadata(data)
|
||||
} else if (type === "builder-state") {
|
||||
const [[key, value]] = Object.entries(data)
|
||||
stateStore.actions.setValue(key, value)
|
||||
} else if (type === "builder-url-test-data") {
|
||||
const { route, testValue } = data
|
||||
routeStore.actions.setTestUrlParams(route, testValue)
|
||||
}
|
||||
}
|
||||
|
||||
// Register any custom components
|
||||
if (window["##BUDIBASE_CUSTOM_COMPONENTS##"]) {
|
||||
window["##BUDIBASE_CUSTOM_COMPONENTS##"].forEach(component => {
|
||||
componentStore.actions.registerCustomComponent(component)
|
||||
})
|
||||
}
|
||||
|
||||
// Make a callback available for custom component bundles to register
|
||||
// themselves at runtime
|
||||
window.registerCustomComponent =
|
||||
componentStore.actions.registerCustomComponent
|
||||
|
||||
// Initialise websocket
|
||||
initWebsocket()
|
||||
|
||||
// Create app if one hasn't been created yet
|
||||
if (!app) {
|
||||
app = new ClientApp({
|
||||
target: window.document.body,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Attach to window so the HTML template can call this when it loads
|
||||
window.loadBudibase = loadBudibase
|
|
@ -106,6 +106,7 @@ export const Roles = {
|
|||
PUBLIC: "PUBLIC",
|
||||
BUILDER: "BUILDER",
|
||||
CREATOR: "CREATOR",
|
||||
GROUP: "GROUP",
|
||||
}
|
||||
|
||||
export const EventPublishType = {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 45f5673d5e5ab3c22deb6663cea2e31a628aa133
|
||||
Subproject commit b28dbd549284cf450be7f25ad85aadf614d08f0b
|
|
@ -1,24 +0,0 @@
|
|||
const elastic: any = {}
|
||||
|
||||
elastic.Client = function () {
|
||||
this.index = jest.fn().mockResolvedValue({ body: [] })
|
||||
this.search = jest.fn().mockResolvedValue({
|
||||
body: {
|
||||
hits: {
|
||||
hits: [
|
||||
{
|
||||
_source: {
|
||||
name: "test",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
this.update = jest.fn().mockResolvedValue({ body: [] })
|
||||
this.delete = jest.fn().mockResolvedValue({ body: [] })
|
||||
|
||||
this.close = jest.fn()
|
||||
}
|
||||
|
||||
module.exports = elastic
|
|
@ -1,5 +1,6 @@
|
|||
MSSQL_SHA=sha256:3b913841850a4d57fcfcb798be06acc88ea0f2acc5418bc0c140a43e91c4a545
|
||||
MSSQL_SHA=sha256:d252932ef839c24c61c1139cc98f69c85ca774fa7c6bfaaa0015b7eb02b9dc87
|
||||
MYSQL_SHA=sha256:9de9d54fecee6253130e65154b930978b1fcc336bcc86dfd06e89b72a2588ebe
|
||||
POSTGRES_SHA=sha256:bd0d8e485d1aca439d39e5ea99b931160bd28d862e74c786f7508e9d0053090e
|
||||
MONGODB_SHA=sha256:afa36bca12295b5f9dae68a493c706113922bdab520e901bd5d6c9d7247a1d8d
|
||||
MARIADB_SHA=sha256:e59ba8783bf7bc02a4779f103bb0d8751ac0e10f9471089709608377eded7aa8
|
||||
ELASTICSEARCH_SHA=sha256:9a6443f55243f6acbfeb4a112d15eb3b9aac74bf25e0e39fa19b3ddd3a6879d0
|
|
@ -11,6 +11,7 @@ import {
|
|||
UploadPluginResponse,
|
||||
FetchPluginResponse,
|
||||
DeletePluginResponse,
|
||||
PluginMetadata,
|
||||
} from "@budibase/types"
|
||||
import env from "../../../environment"
|
||||
import { clientAppSocket } from "../../../websockets"
|
||||
|
@ -53,10 +54,11 @@ export async function create(
|
|||
const { source, url, headers, githubToken } = ctx.request.body
|
||||
|
||||
try {
|
||||
let metadata
|
||||
let directory
|
||||
let metadata: PluginMetadata
|
||||
let directory: string
|
||||
|
||||
// Generating random name as a backup and needed for url
|
||||
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
|
||||
const name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
|
||||
|
||||
switch (source) {
|
||||
case PluginSource.NPM: {
|
||||
|
@ -81,12 +83,14 @@ export async function create(
|
|||
directory = directoryUrl
|
||||
break
|
||||
}
|
||||
default:
|
||||
ctx.throw(400, "Invalid source")
|
||||
}
|
||||
|
||||
pluginCore.validate(metadata?.schema)
|
||||
pluginCore.validate(metadata.schema)
|
||||
|
||||
// Only allow components in cloud
|
||||
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {
|
||||
if (!env.SELF_HOSTED && metadata.schema?.type !== PluginType.COMPONENT) {
|
||||
throw new Error(
|
||||
"Only component plugins are supported outside of self-host"
|
||||
)
|
||||
|
|
|
@ -1,45 +1,49 @@
|
|||
import {
|
||||
AIOperationEnum,
|
||||
CalculationType,
|
||||
Datasource,
|
||||
FieldType,
|
||||
RelationshipType,
|
||||
SourceName,
|
||||
Table,
|
||||
ViewV2,
|
||||
ViewV2Type,
|
||||
} from "@budibase/types"
|
||||
import { buildSqlFieldList } from "../sqlUtils"
|
||||
import { structures } from "../../../../routes/tests/utilities"
|
||||
import { sql } from "@budibase/backend-core"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import { generateViewID } from "../../../../../db/utils"
|
||||
|
||||
import sdk from "../../../../../sdk"
|
||||
import { cloneDeep } from "lodash"
|
||||
import { utils } from "@budibase/shared-core"
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../../../integrations/tests/utils"
|
||||
import { context } from "@budibase/backend-core"
|
||||
|
||||
jest.mock("../../../../../sdk/app/views", () => ({
|
||||
...jest.requireActual("../../../../../sdk/app/views"),
|
||||
getTable: jest.fn(),
|
||||
}))
|
||||
const getTableMock = sdk.views.getTable as jest.MockedFunction<
|
||||
typeof sdk.views.getTable
|
||||
>
|
||||
const descriptions = datasourceDescribe({
|
||||
only: [DatabaseName.POSTGRES],
|
||||
})
|
||||
|
||||
describe("buildSqlFieldList", () => {
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"buildSqlFieldList ($dbName)",
|
||||
({ config, dsProvider }) => {
|
||||
let allTables: Record<string, Table>
|
||||
let datasource: Datasource
|
||||
|
||||
beforeEach(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
allTables = {}
|
||||
})
|
||||
|
||||
class TableConfig {
|
||||
private _table: Table & { _id: string }
|
||||
private _table: Table
|
||||
|
||||
constructor(name: string) {
|
||||
this._table = {
|
||||
...structures.tableForDatasource({
|
||||
type: "datasource",
|
||||
source: SourceName.POSTGRES,
|
||||
}),
|
||||
...structures.tableForDatasource(datasource),
|
||||
name,
|
||||
_id: sql.utils.buildExternalTableId("ds_id", name),
|
||||
schema: {
|
||||
name: {
|
||||
name: "name",
|
||||
|
@ -55,8 +59,6 @@ describe("buildSqlFieldList", () => {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
allTables[name] = this._table
|
||||
}
|
||||
|
||||
withHiddenField(field: string) {
|
||||
|
@ -110,6 +112,7 @@ describe("buildSqlFieldList", () => {
|
|||
type: FieldType.LINK,
|
||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||
fieldName: "link",
|
||||
foreignKey: "link",
|
||||
tableId: toTableId,
|
||||
}
|
||||
return this
|
||||
|
@ -125,17 +128,17 @@ describe("buildSqlFieldList", () => {
|
|||
return this
|
||||
}
|
||||
|
||||
create() {
|
||||
return cloneDeep(this._table)
|
||||
async create() {
|
||||
const table = await config.api.table.save(this._table)
|
||||
allTables[table.name] = table
|
||||
return table
|
||||
}
|
||||
}
|
||||
|
||||
class ViewConfig {
|
||||
private _table: Table
|
||||
private _view: ViewV2
|
||||
|
||||
constructor(table: Table) {
|
||||
this._table = table
|
||||
this._view = {
|
||||
version: 2,
|
||||
id: generateViewID(table._id!),
|
||||
|
@ -183,197 +186,208 @@ describe("buildSqlFieldList", () => {
|
|||
return this
|
||||
}
|
||||
|
||||
create() {
|
||||
getTableMock.mockResolvedValueOnce(this._table)
|
||||
return cloneDeep(this._view)
|
||||
async create() {
|
||||
return await config.api.viewV2.create(this._view)
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
allTables = {}
|
||||
})
|
||||
const buildSqlFieldListInApp: typeof buildSqlFieldList = async (
|
||||
table,
|
||||
allTables,
|
||||
opts
|
||||
) => {
|
||||
return context.doInAppContext(config.getAppId(), () =>
|
||||
buildSqlFieldList(table, allTables, opts)
|
||||
)
|
||||
}
|
||||
|
||||
describe("table", () => {
|
||||
it("extracts fields from table schema", async () => {
|
||||
const table = new TableConfig("table").create()
|
||||
const result = await buildSqlFieldList(table, {})
|
||||
const table = await new TableConfig("table").create()
|
||||
const result = await buildSqlFieldListInApp(table, {})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
])
|
||||
})
|
||||
|
||||
it("excludes hidden fields", async () => {
|
||||
const table = new TableConfig("table")
|
||||
const table = await new TableConfig("table")
|
||||
.withHiddenField("description")
|
||||
.create()
|
||||
const result = await buildSqlFieldList(table, {})
|
||||
expect(result).toEqual(["table.name", "table.amount"])
|
||||
const result = await buildSqlFieldListInApp(table, {})
|
||||
expect(result).toEqual(["table.name", "table.amount", "table.id"])
|
||||
})
|
||||
|
||||
it("excludes non-sql fields fields", async () => {
|
||||
const table = new TableConfig("table")
|
||||
const table = await new TableConfig("table")
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.withField("ai", FieldType.AI)
|
||||
.withRelation("link", "otherTableId")
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(table, {})
|
||||
const result = await buildSqlFieldListInApp(table, {})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
])
|
||||
})
|
||||
|
||||
it("includes hidden fields if there is a formula column", async () => {
|
||||
const table = new TableConfig("table")
|
||||
const table = await new TableConfig("table")
|
||||
.withHiddenField("description")
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(table, {})
|
||||
const result = await buildSqlFieldListInApp(table, {})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
])
|
||||
})
|
||||
|
||||
it("includes relationships fields when flagged", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
.withPrimary("id")
|
||||
.withDisplay("name")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(table, allTables, {
|
||||
const result = await buildSqlFieldListInApp(table, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
"linkedTable.id",
|
||||
"linkedTable.name",
|
||||
])
|
||||
})
|
||||
|
||||
it("includes all relationship fields if there is a formula column", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("hidden", FieldType.STRING, { visible: false })
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(table, allTables, {
|
||||
const result = await buildSqlFieldListInApp(table, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
"linkedTable.name",
|
||||
"linkedTable.description",
|
||||
"linkedTable.amount",
|
||||
"linkedTable.hidden",
|
||||
"linkedTable.id",
|
||||
])
|
||||
})
|
||||
|
||||
it("never includes non-sql columns from relationships", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("hidden", FieldType.STRING, { visible: false })
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.withField("ai", FieldType.AI)
|
||||
.withRelation("link", "otherTableId")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(table, allTables, {
|
||||
const result = await buildSqlFieldListInApp(table, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
"linkedTable.name",
|
||||
"linkedTable.description",
|
||||
"linkedTable.amount",
|
||||
"linkedTable.id",
|
||||
"linkedTable.hidden",
|
||||
"linkedTable.id",
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("view", () => {
|
||||
it("extracts fields from table schema", async () => {
|
||||
const view = new ViewConfig(new TableConfig("table").create())
|
||||
const view = await new ViewConfig(
|
||||
await new TableConfig("table").create()
|
||||
)
|
||||
.withVisible("amount")
|
||||
.withHidden("name")
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, {})
|
||||
expect(result).toEqual(["table.amount"])
|
||||
const result = await buildSqlFieldListInApp(view, {})
|
||||
expect(result).toEqual(["table.amount", "table.id"])
|
||||
})
|
||||
|
||||
it("includes all fields if there is a formula column", async () => {
|
||||
const table = new TableConfig("table")
|
||||
const table = await new TableConfig("table")
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withHidden("name")
|
||||
.withVisible("amount")
|
||||
.withVisible("formula")
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, {})
|
||||
const result = await buildSqlFieldListInApp(view, {})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
])
|
||||
})
|
||||
|
||||
it("does not includes all fields if the formula column is not included", async () => {
|
||||
const table = new TableConfig("table")
|
||||
const table = await new TableConfig("table")
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withHidden("name")
|
||||
.withVisible("amount")
|
||||
.withHidden("formula")
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, {})
|
||||
expect(result).toEqual(["table.amount"])
|
||||
const result = await buildSqlFieldListInApp(view, {})
|
||||
expect(result).toEqual(["table.amount", "table.id"])
|
||||
})
|
||||
|
||||
it("includes relationships columns", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.withPrimary("id")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.create()
|
||||
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withVisible("name")
|
||||
.withVisible("link")
|
||||
.withRelationshipColumns("link", {
|
||||
|
@ -383,51 +397,52 @@ describe("buildSqlFieldList", () => {
|
|||
})
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, allTables, {
|
||||
const result = await buildSqlFieldListInApp(view, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.id",
|
||||
"linkedTable.id",
|
||||
"linkedTable.amount",
|
||||
])
|
||||
})
|
||||
|
||||
it("excludes relationships fields when view is not included in the view", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
.withPrimary("id")
|
||||
.withDisplay("name")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withVisible("name")
|
||||
.withHidden("amount")
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, allTables, {
|
||||
const result = await buildSqlFieldListInApp(view, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual(["table.name"])
|
||||
expect(result).toEqual(["table.name", "table.id"])
|
||||
})
|
||||
|
||||
it("does not include relationships columns for hidden links", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.withPrimary("id")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.create()
|
||||
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withVisible("name")
|
||||
.withHidden("link")
|
||||
.withRelationshipColumns("link", {
|
||||
|
@ -437,28 +452,27 @@ describe("buildSqlFieldList", () => {
|
|||
})
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, allTables, {
|
||||
const result = await buildSqlFieldListInApp(view, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual(["table.name"])
|
||||
expect(result).toEqual(["table.name", "table.id"])
|
||||
})
|
||||
|
||||
it("includes all relationship fields if there is a formula column", async () => {
|
||||
const otherTable = new TableConfig("linkedTable")
|
||||
const otherTable = await new TableConfig("linkedTable")
|
||||
.withField("id", FieldType.NUMBER)
|
||||
.withField("hidden", FieldType.STRING, { visible: false })
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.withField("ai", FieldType.AI)
|
||||
.withRelation("link", "otherTableId")
|
||||
.withPrimary("id")
|
||||
.create()
|
||||
|
||||
const table = new TableConfig("table")
|
||||
.withRelation("link", otherTable._id)
|
||||
const table = await new TableConfig("table")
|
||||
.withRelation("link", otherTable._id!)
|
||||
.withField("formula", FieldType.FORMULA)
|
||||
.create()
|
||||
|
||||
const view = new ViewConfig(table)
|
||||
const view = await new ViewConfig(table)
|
||||
.withVisible("name")
|
||||
.withVisible("formula")
|
||||
.withHidden("link")
|
||||
|
@ -469,13 +483,14 @@ describe("buildSqlFieldList", () => {
|
|||
})
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, allTables, {
|
||||
const result = await buildSqlFieldListInApp(view, allTables, {
|
||||
relationships: true,
|
||||
})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
"table.id",
|
||||
"linkedTable.name",
|
||||
"linkedTable.description",
|
||||
"linkedTable.amount",
|
||||
|
@ -487,25 +502,31 @@ describe("buildSqlFieldList", () => {
|
|||
|
||||
describe("calculation view", () => {
|
||||
it("does not include calculation fields", async () => {
|
||||
const view = new ViewConfig(new TableConfig("table").create())
|
||||
const view = await new ViewConfig(
|
||||
await new TableConfig("table").create()
|
||||
)
|
||||
.withCalculation("average", "amount", CalculationType.AVG)
|
||||
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, {})
|
||||
const result = await buildSqlFieldListInApp(view, {})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
it("includes visible fields calculation fields", async () => {
|
||||
const view = new ViewConfig(new TableConfig("table").create())
|
||||
const view = await new ViewConfig(
|
||||
await new TableConfig("table").create()
|
||||
)
|
||||
.withCalculation("average", "amount", CalculationType.AVG)
|
||||
.withHidden("name")
|
||||
.withVisible("amount")
|
||||
|
||||
.create()
|
||||
|
||||
const result = await buildSqlFieldList(view, {})
|
||||
const result = await buildSqlFieldListInApp(view, {})
|
||||
expect(result).toEqual(["table.amount"])
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -165,7 +165,8 @@ describe("/datasources", () => {
|
|||
})
|
||||
|
||||
const descriptions = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
plus: true,
|
||||
exclude: [DatabaseName.SQS],
|
||||
})
|
||||
|
||||
if (descriptions.length) {
|
||||
|
@ -590,7 +591,8 @@ if (descriptions.length) {
|
|||
}
|
||||
|
||||
const datasources = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS, DatabaseName.ORACLE],
|
||||
plus: true,
|
||||
exclude: [DatabaseName.SQS, DatabaseName.ORACLE],
|
||||
})
|
||||
|
||||
if (datasources.length) {
|
||||
|
|
|
@ -9,7 +9,8 @@ import { Knex } from "knex"
|
|||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
||||
const descriptions = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
plus: true,
|
||||
exclude: [DatabaseName.SQS],
|
||||
})
|
||||
|
||||
if (descriptions.length) {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import * as setup from "./utilities"
|
||||
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||
|
||||
import tk from "timekeeper"
|
||||
import emitter from "../../../../src/events"
|
||||
|
@ -80,7 +77,7 @@ function encodeJS(binding: string) {
|
|||
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
||||
}
|
||||
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
const descriptions = datasourceDescribe({ plus: true })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||
import {
|
||||
context,
|
||||
db as dbCore,
|
||||
|
@ -60,7 +57,7 @@ jest.mock("@budibase/pro", () => ({
|
|||
},
|
||||
}))
|
||||
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
const descriptions = datasourceDescribe({ plus: true })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
|
@ -3553,6 +3550,31 @@ if (descriptions.length) {
|
|||
limit: 1,
|
||||
}).toContainExactly([row])
|
||||
})
|
||||
|
||||
isInternal &&
|
||||
describe("search by _id for relations", () => {
|
||||
it("can filter by the related _id", async () => {
|
||||
await expectSearch({
|
||||
query: {
|
||||
equal: { "rel._id": row.rel[0]._id },
|
||||
},
|
||||
}).toContainExactly([row])
|
||||
|
||||
await expectSearch({
|
||||
query: {
|
||||
equal: { "rel._id": row.rel[1]._id },
|
||||
},
|
||||
}).toContainExactly([row])
|
||||
})
|
||||
|
||||
it("can filter by the related _id and find nothing", async () => {
|
||||
await expectSearch({
|
||||
query: {
|
||||
equal: { "rel._id": "rel_none" },
|
||||
},
|
||||
}).toFindNothing()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
!isInternal &&
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
// Directly mock the AWS SDK
|
||||
jest.mock("@aws-sdk/s3-request-presigner", () => ({
|
||||
getSignedUrl: jest.fn(() => {
|
||||
return `http://example.com`
|
||||
}),
|
||||
}))
|
||||
jest.mock("@aws-sdk/client-s3")
|
||||
|
||||
import { Datasource, SourceName } from "@budibase/types"
|
||||
import { setEnv } from "../../../environment"
|
||||
import { getRequest, getConfig, afterAll as _afterAll } from "./utilities"
|
||||
|
@ -92,7 +84,17 @@ describe("/static", () => {
|
|||
.set(config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body.signedUrl).toEqual("http://example.com")
|
||||
|
||||
expect(res.body.signedUrl).toStartWith(
|
||||
"https://foo.s3.eu-west-1.amazonaws.com/bar?"
|
||||
)
|
||||
expect(res.body.signedUrl).toContain("X-Amz-Algorithm=AWS4-HMAC-SHA256")
|
||||
expect(res.body.signedUrl).toContain("X-Amz-Credential=bb")
|
||||
expect(res.body.signedUrl).toContain("X-Amz-Date=")
|
||||
expect(res.body.signedUrl).toContain("X-Amz-Signature=")
|
||||
expect(res.body.signedUrl).toContain("X-Amz-Expires=900")
|
||||
expect(res.body.signedUrl).toContain("X-Amz-SignedHeaders=host")
|
||||
|
||||
expect(res.body.publicUrl).toEqual(
|
||||
`https://${bucket}.s3.eu-west-1.amazonaws.com/${key}`
|
||||
)
|
||||
|
|
|
@ -28,17 +28,14 @@ import * as setup from "./utilities"
|
|||
import * as uuid from "uuid"
|
||||
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||
import timekeeper from "timekeeper"
|
||||
|
||||
const { basicTable } = setup.structures
|
||||
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
|
||||
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
const descriptions = datasourceDescribe({ plus: true })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
|
|
|
@ -37,17 +37,14 @@ import {
|
|||
ViewV2Type,
|
||||
} from "@budibase/types"
|
||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||
import merge from "lodash/merge"
|
||||
import { quotas } from "@budibase/pro"
|
||||
import { context, db, events, roles, setEnv } from "@budibase/backend-core"
|
||||
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/openai"
|
||||
import nock from "nock"
|
||||
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
const descriptions = datasourceDescribe({ plus: true })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as automation from "../index"
|
||||
import { Table, AutomationStatus } from "@budibase/types"
|
||||
import { Table, AutomationStatus, EmptyFilterOption } from "@budibase/types"
|
||||
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
|
||||
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
||||
|
||||
|
@ -280,4 +280,23 @@ describe("Branching automations", () => {
|
|||
|
||||
expect(results.steps[2].outputs.message).toContain("Special user")
|
||||
})
|
||||
|
||||
it("should not fail with empty conditions", async () => {
|
||||
const results = await createAutomationBuilder(config)
|
||||
.onAppAction()
|
||||
.branch({
|
||||
specialBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Hello!" }),
|
||||
condition: {
|
||||
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
|
||||
},
|
||||
},
|
||||
})
|
||||
.test({ fields: { test_trigger: true } })
|
||||
|
||||
expect(results.steps[0].outputs.success).toEqual(false)
|
||||
expect(results.steps[0].outputs.status).toEqual(
|
||||
AutomationStatus.NO_CONDITION_MET
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -9,7 +9,8 @@ import { generator } from "@budibase/backend-core/tests"
|
|||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||
|
||||
const descriptions = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
plus: true,
|
||||
exclude: [DatabaseName.SQS],
|
||||
})
|
||||
|
||||
if (descriptions.length) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
CreateRowStepOutputs,
|
||||
FieldType,
|
||||
FilterCondition,
|
||||
AutomationStepStatus,
|
||||
} from "@budibase/types"
|
||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
|
@ -560,5 +561,25 @@ describe("Attempt to run a basic loop automation", () => {
|
|||
status: "stopped",
|
||||
})
|
||||
})
|
||||
|
||||
it("should not fail if queryRows returns nothing", async () => {
|
||||
const table = await config.api.table.save(basicTable())
|
||||
const results = await createAutomationBuilder(config)
|
||||
.onAppAction()
|
||||
.queryRows({
|
||||
tableId: table._id!,
|
||||
})
|
||||
.loop({
|
||||
option: LoopStepType.ARRAY,
|
||||
binding: "{{ steps.1.rows }}",
|
||||
})
|
||||
.serverLog({ text: "Message {{loop.currentItem}}" })
|
||||
.test({ fields: {} })
|
||||
|
||||
expect(results.steps[1].outputs.success).toBe(true)
|
||||
expect(results.steps[1].outputs.status).toBe(
|
||||
AutomationStepStatus.NO_ITERATIONS
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { SendEmailResponse } from "@budibase/types"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
import * as workerRequests from "../../../utilities/workerRequests"
|
||||
|
||||
|
@ -5,17 +6,18 @@ jest.mock("../../../utilities/workerRequests", () => ({
|
|||
sendSmtpEmail: jest.fn(),
|
||||
}))
|
||||
|
||||
function generateResponse(to: string, from: string) {
|
||||
function generateResponse(to: string, from: string): SendEmailResponse {
|
||||
return {
|
||||
success: true,
|
||||
response: {
|
||||
message: `Email sent to ${to}.`,
|
||||
accepted: [to],
|
||||
envelope: {
|
||||
from: from,
|
||||
to: [to],
|
||||
},
|
||||
message: `Email sent to ${to}.`,
|
||||
},
|
||||
messageId: "messageId",
|
||||
pending: [],
|
||||
rejected: [],
|
||||
response: "response",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
import { Client, ClientOptions } from "@elastic/elasticsearch"
|
||||
import { HOST_ADDRESS } from "./utils"
|
||||
|
||||
interface ElasticsearchConfig {
|
||||
export interface ElasticsearchConfig {
|
||||
url: string
|
||||
ssl?: boolean
|
||||
ca?: string
|
||||
|
@ -99,9 +99,9 @@ const SCHEMA: Integration = {
|
|||
},
|
||||
}
|
||||
|
||||
class ElasticSearchIntegration implements IntegrationBase {
|
||||
export class ElasticSearchIntegration implements IntegrationBase {
|
||||
private config: ElasticsearchConfig
|
||||
private client
|
||||
private client: Client
|
||||
|
||||
constructor(config: ElasticsearchConfig) {
|
||||
this.config = config
|
||||
|
@ -132,20 +132,23 @@ class ElasticSearchIntegration implements IntegrationBase {
|
|||
}
|
||||
}
|
||||
|
||||
async create(query: { index: string; json: object }) {
|
||||
const { index, json } = query
|
||||
async create(query: {
|
||||
index: string
|
||||
json: object
|
||||
extra?: Record<string, string>
|
||||
}) {
|
||||
const { index, json, extra } = query
|
||||
|
||||
try {
|
||||
const result = await this.client.index({
|
||||
index,
|
||||
body: json,
|
||||
...extra,
|
||||
})
|
||||
return result.body
|
||||
} catch (err) {
|
||||
console.error("Error writing to elasticsearch", err)
|
||||
throw err
|
||||
} finally {
|
||||
await this.client.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,41 +163,46 @@ class ElasticSearchIntegration implements IntegrationBase {
|
|||
} catch (err) {
|
||||
console.error("Error querying elasticsearch", err)
|
||||
throw err
|
||||
} finally {
|
||||
await this.client.close()
|
||||
}
|
||||
}
|
||||
|
||||
async update(query: { id: string; index: string; json: object }) {
|
||||
const { id, index, json } = query
|
||||
async update(query: {
|
||||
id: string
|
||||
index: string
|
||||
json: object
|
||||
extra?: Record<string, string>
|
||||
}) {
|
||||
const { id, index, json, extra } = query
|
||||
try {
|
||||
const result = await this.client.update({
|
||||
id,
|
||||
index,
|
||||
body: json,
|
||||
...extra,
|
||||
})
|
||||
return result.body
|
||||
} catch (err) {
|
||||
console.error("Error querying elasticsearch", err)
|
||||
throw err
|
||||
} finally {
|
||||
await this.client.close()
|
||||
}
|
||||
}
|
||||
|
||||
async delete(query: { id: string; index: string }) {
|
||||
const { id, index } = query
|
||||
async delete(query: {
|
||||
id: string
|
||||
index: string
|
||||
extra?: Record<string, string>
|
||||
}) {
|
||||
const { id, index, extra } = query
|
||||
try {
|
||||
const result = await this.client.delete({
|
||||
id,
|
||||
index,
|
||||
...extra,
|
||||
})
|
||||
return result.body
|
||||
} catch (err) {
|
||||
console.error("Error deleting from elasticsearch", err)
|
||||
throw err
|
||||
} finally {
|
||||
await this.client.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,83 +1,81 @@
|
|||
import { default as ElasticSearchIntegration } from "../elasticsearch"
|
||||
import { Datasource } from "@budibase/types"
|
||||
import { ElasticsearchConfig, ElasticSearchIntegration } from "../elasticsearch"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import { DatabaseName, datasourceDescribe } from "./utils"
|
||||
|
||||
jest.mock("@elastic/elasticsearch")
|
||||
const describes = datasourceDescribe({ only: [DatabaseName.ELASTICSEARCH] })
|
||||
|
||||
class TestConfiguration {
|
||||
integration: any
|
||||
if (describes.length) {
|
||||
describe.each(describes)("Elasticsearch Integration", ({ dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let integration: ElasticSearchIntegration
|
||||
|
||||
constructor(config: any = {}) {
|
||||
this.integration = new ElasticSearchIntegration.integration(config)
|
||||
}
|
||||
}
|
||||
let index: string
|
||||
|
||||
describe("Elasticsearch Integration", () => {
|
||||
let config: any
|
||||
let indexName = "Users"
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
config = new TestConfiguration()
|
||||
index = generator.guid()
|
||||
integration = new ElasticSearchIntegration(
|
||||
datasource.config! as ElasticsearchConfig
|
||||
)
|
||||
})
|
||||
|
||||
it("calls the create method with the correct params", async () => {
|
||||
const body = {
|
||||
name: "Hello",
|
||||
}
|
||||
await config.integration.create({
|
||||
index: indexName,
|
||||
json: body,
|
||||
it("can create a record", async () => {
|
||||
await integration.create({
|
||||
index,
|
||||
json: { name: "Hello" },
|
||||
extra: { refresh: "true" },
|
||||
})
|
||||
expect(config.integration.client.index).toHaveBeenCalledWith({
|
||||
index: indexName,
|
||||
body,
|
||||
const records = await integration.read({
|
||||
index,
|
||||
json: { query: { match_all: {} } },
|
||||
})
|
||||
expect(records).toEqual([{ name: "Hello" }])
|
||||
})
|
||||
|
||||
it("calls the read method with the correct params", async () => {
|
||||
const body = {
|
||||
query: {
|
||||
term: {
|
||||
name: "kimchy",
|
||||
},
|
||||
},
|
||||
}
|
||||
const response = await config.integration.read({
|
||||
index: indexName,
|
||||
json: body,
|
||||
})
|
||||
expect(config.integration.client.search).toHaveBeenCalledWith({
|
||||
index: indexName,
|
||||
body,
|
||||
})
|
||||
expect(response).toEqual(expect.any(Array))
|
||||
it("can update a record", async () => {
|
||||
const create = await integration.create({
|
||||
index,
|
||||
json: { name: "Hello" },
|
||||
extra: { refresh: "true" },
|
||||
})
|
||||
|
||||
it("calls the update method with the correct params", async () => {
|
||||
const body = {
|
||||
name: "updated",
|
||||
}
|
||||
|
||||
const response = await config.integration.update({
|
||||
id: "1234",
|
||||
index: indexName,
|
||||
json: body,
|
||||
await integration.update({
|
||||
id: create._id,
|
||||
index,
|
||||
json: { doc: { name: "World" } },
|
||||
extra: { refresh: "true" },
|
||||
})
|
||||
|
||||
expect(config.integration.client.update).toHaveBeenCalledWith({
|
||||
id: "1234",
|
||||
index: indexName,
|
||||
body,
|
||||
const records = await integration.read({
|
||||
index,
|
||||
json: { query: { match_all: {} } },
|
||||
})
|
||||
expect(response).toEqual(expect.any(Array))
|
||||
expect(records).toEqual([{ name: "World" }])
|
||||
})
|
||||
|
||||
it("calls the delete method with the correct params", async () => {
|
||||
const body = {
|
||||
id: "1234",
|
||||
}
|
||||
|
||||
const response = await config.integration.delete(body)
|
||||
|
||||
expect(config.integration.client.delete).toHaveBeenCalledWith(body)
|
||||
expect(response).toEqual(expect.any(Array))
|
||||
it("can delete a record", async () => {
|
||||
const create = await integration.create({
|
||||
index,
|
||||
json: { name: "Hello" },
|
||||
extra: { refresh: "true" },
|
||||
})
|
||||
})
|
||||
|
||||
await integration.delete({
|
||||
id: create._id,
|
||||
index,
|
||||
extra: { refresh: "true" },
|
||||
})
|
||||
|
||||
const records = await integration.read({
|
||||
index,
|
||||
json: { query: { match_all: {} } },
|
||||
})
|
||||
expect(records).toEqual([])
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
import { Datasource, SourceName } from "@budibase/types"
|
||||
import { GenericContainer, Wait } from "testcontainers"
|
||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||
import { startContainer } from "."
|
||||
import { ELASTICSEARCH_IMAGE } from "./images"
|
||||
import { ElasticsearchConfig } from "../../elasticsearch"
|
||||
|
||||
let ports: Promise<testContainerUtils.Port[]>
|
||||
|
||||
export async function getDatasource(): Promise<Datasource> {
|
||||
if (!ports) {
|
||||
ports = startContainer(
|
||||
new GenericContainer(ELASTICSEARCH_IMAGE)
|
||||
.withExposedPorts(9200)
|
||||
.withEnvironment({
|
||||
// We need to set the discovery type to single-node to avoid the
|
||||
// cluster waiting for other nodes to join before starting up.
|
||||
"discovery.type": "single-node",
|
||||
// We disable security to avoid having to do any auth against the
|
||||
// container, and to disable SSL. With SSL enabled it uses a self
|
||||
// signed certificate that we'd have to ignore anyway.
|
||||
"xpack.security.enabled": "false",
|
||||
})
|
||||
.withWaitStrategy(
|
||||
Wait.forHttp(
|
||||
// Single node clusters never reach status green, so we wait for
|
||||
// yellow instead.
|
||||
"/_cluster/health?wait_for_status=yellow&timeout=10s",
|
||||
9200
|
||||
).withStartupTimeout(60000)
|
||||
)
|
||||
// We gave the container a tmpfs data directory. Without this, I found
|
||||
// that the default data directory was very small and the container
|
||||
// easily filled it up. This caused the cluster to go into a red status
|
||||
// and stop responding to requests.
|
||||
.withTmpFs({ "/usr/share/elasticsearch/data": "rw" })
|
||||
)
|
||||
}
|
||||
|
||||
const port = (await ports).find(x => x.container === 9200)?.host
|
||||
if (!port) {
|
||||
throw new Error("Elasticsearch port not found")
|
||||
}
|
||||
|
||||
const config: ElasticsearchConfig = {
|
||||
url: `http://127.0.0.1:${port}`,
|
||||
}
|
||||
|
||||
return {
|
||||
type: "datasource",
|
||||
source: SourceName.ELASTICSEARCH,
|
||||
config,
|
||||
}
|
||||
}
|
|
@ -12,3 +12,4 @@ export const POSTGRES_IMAGE = `postgres@${process.env.POSTGRES_SHA}`
|
|||
export const POSTGRES_LEGACY_IMAGE = `postgres:9.5.25`
|
||||
export const MONGODB_IMAGE = `mongo@${process.env.MONGODB_SHA}`
|
||||
export const MARIADB_IMAGE = `mariadb@${process.env.MARIADB_SHA}`
|
||||
export const ELASTICSEARCH_IMAGE = `elasticsearch@${process.env.ELASTICSEARCH_SHA}`
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as mysql from "./mysql"
|
|||
import * as mssql from "./mssql"
|
||||
import * as mariadb from "./mariadb"
|
||||
import * as oracle from "./oracle"
|
||||
import * as elasticsearch from "./elasticsearch"
|
||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||
import { Knex } from "knex"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
|
@ -23,22 +24,32 @@ export enum DatabaseName {
|
|||
MARIADB = "mariadb",
|
||||
ORACLE = "oracle",
|
||||
SQS = "sqs",
|
||||
ELASTICSEARCH = "elasticsearch",
|
||||
}
|
||||
|
||||
const DATASOURCE_PLUS = [
|
||||
DatabaseName.POSTGRES,
|
||||
DatabaseName.POSTGRES_LEGACY,
|
||||
DatabaseName.MYSQL,
|
||||
DatabaseName.SQL_SERVER,
|
||||
DatabaseName.MARIADB,
|
||||
DatabaseName.ORACLE,
|
||||
DatabaseName.SQS,
|
||||
]
|
||||
|
||||
const providers: Record<DatabaseName, DatasourceProvider> = {
|
||||
// datasource_plus entries
|
||||
[DatabaseName.POSTGRES]: postgres.getDatasource,
|
||||
[DatabaseName.POSTGRES_LEGACY]: postgres.getLegacyDatasource,
|
||||
[DatabaseName.MONGODB]: mongodb.getDatasource,
|
||||
[DatabaseName.MYSQL]: mysql.getDatasource,
|
||||
[DatabaseName.SQL_SERVER]: mssql.getDatasource,
|
||||
[DatabaseName.MARIADB]: mariadb.getDatasource,
|
||||
[DatabaseName.ORACLE]: oracle.getDatasource,
|
||||
[DatabaseName.SQS]: async () => undefined,
|
||||
}
|
||||
|
||||
export interface DatasourceDescribeOpts {
|
||||
only?: DatabaseName[]
|
||||
exclude?: DatabaseName[]
|
||||
// rest
|
||||
[DatabaseName.ELASTICSEARCH]: elasticsearch.getDatasource,
|
||||
[DatabaseName.MONGODB]: mongodb.getDatasource,
|
||||
}
|
||||
|
||||
export interface DatasourceDescribeReturnPromise {
|
||||
|
@ -103,6 +114,20 @@ function createDummyTest() {
|
|||
})
|
||||
}
|
||||
|
||||
interface OnlyOpts {
|
||||
only: DatabaseName[]
|
||||
}
|
||||
|
||||
interface PlusOpts {
|
||||
plus: true
|
||||
exclude?: DatabaseName[]
|
||||
}
|
||||
|
||||
export type DatasourceDescribeOpts = OnlyOpts | PlusOpts
|
||||
|
||||
// If you ever want to rename this function, be mindful that you will also need
|
||||
// to modify src/tests/filters/index.js to make sure that we're correctly
|
||||
// filtering datasource/non-datasource tests in CI.
|
||||
export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
||||
// tests that call this need a lot longer timeouts
|
||||
jest.setTimeout(120000)
|
||||
|
@ -111,17 +136,15 @@ export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
|||
createDummyTest()
|
||||
}
|
||||
|
||||
const { only, exclude } = opts
|
||||
|
||||
if (only && exclude) {
|
||||
throw new Error("you can only supply one of 'only' or 'exclude'")
|
||||
}
|
||||
|
||||
let databases = Object.values(DatabaseName)
|
||||
if (only) {
|
||||
databases = only
|
||||
} else if (exclude) {
|
||||
databases = databases.filter(db => !exclude.includes(db))
|
||||
let databases: DatabaseName[] = []
|
||||
if ("only" in opts) {
|
||||
databases = opts.only
|
||||
} else if ("plus" in opts) {
|
||||
databases = Object.values(DatabaseName)
|
||||
.filter(db => DATASOURCE_PLUS.includes(db))
|
||||
.filter(db => !opts.exclude?.includes(db))
|
||||
} else {
|
||||
throw new Error("invalid options")
|
||||
}
|
||||
|
||||
if (process.env.DATASOURCE) {
|
||||
|
@ -156,6 +179,7 @@ export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
|||
isMSSQL: dbName === DatabaseName.SQL_SERVER,
|
||||
isOracle: dbName === DatabaseName.ORACLE,
|
||||
isMariaDB: dbName === DatabaseName.MARIADB,
|
||||
isElasticsearch: dbName === DatabaseName.ELASTICSEARCH,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function getDatasource(): Promise<Datasource> {
|
|||
})
|
||||
.withWaitStrategy(
|
||||
Wait.forSuccessfulCommand(
|
||||
"/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password_123 -q 'SELECT 1'"
|
||||
"/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P Password_123 -q 'SELECT 1'"
|
||||
).withStartupTimeout(20000)
|
||||
)
|
||||
)
|
||||
|
@ -44,7 +44,8 @@ export async function getDatasource(): Promise<Datasource> {
|
|||
user: "sa",
|
||||
password: "Password_123",
|
||||
options: {
|
||||
encrypt: false,
|
||||
encrypt: true,
|
||||
trustServerCertificate: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
} from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import sdk from "../../../sdk"
|
||||
import { isInternal } from "../tables/utils"
|
||||
|
||||
export const removeInvalidFilters = (
|
||||
filters: SearchFilters,
|
||||
|
@ -70,6 +71,10 @@ export const getQueryableFields = async (
|
|||
opts?: { noRelationships?: boolean }
|
||||
): Promise<string[]> => {
|
||||
const result = []
|
||||
if (isInternal({ table })) {
|
||||
result.push("_id")
|
||||
}
|
||||
|
||||
for (const field of Object.keys(table.schema).filter(
|
||||
f => allowedFields.includes(f) && table.schema[f].visible !== false
|
||||
)) {
|
||||
|
@ -113,14 +118,13 @@ export const getQueryableFields = async (
|
|||
return result
|
||||
}
|
||||
|
||||
const result = [
|
||||
"_id", // Querying by _id is always allowed, even if it's never part of the schema
|
||||
]
|
||||
// Querying by _id is always allowed, even if it's never part of the schema
|
||||
const result = ["_id"]
|
||||
|
||||
if (fields == null) {
|
||||
fields = Object.keys(table.schema)
|
||||
}
|
||||
result.push(...(await extractTableFields(table, fields, [table._id!])))
|
||||
|
||||
return result
|
||||
return Array.from(new Set(result))
|
||||
}
|
||||
|
|
|
@ -10,16 +10,13 @@ import {
|
|||
import { search } from "../../../../../sdk/app/rows/search"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../../../integrations/tests/utils"
|
||||
import { datasourceDescribe } from "../../../../../integrations/tests/utils"
|
||||
import { tableForDatasource } from "../../../../../tests/utilities/structures"
|
||||
|
||||
// These test cases are only for things that cannot be tested through the API
|
||||
// (e.g. limiting searches to returning specific fields). If it's possible to
|
||||
// test through the API, it should be done there instead.
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
const descriptions = datasourceDescribe({ plus: true })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
|
|
|
@ -250,6 +250,8 @@ describe("query utils", () => {
|
|||
expect(result).toEqual([
|
||||
"_id",
|
||||
"name",
|
||||
"aux._id",
|
||||
"auxTable._id",
|
||||
"aux.title",
|
||||
"auxTable.title",
|
||||
"aux.name",
|
||||
|
@ -284,7 +286,14 @@ describe("query utils", () => {
|
|||
const result = await config.doInContext(config.appId, () => {
|
||||
return getQueryableFields(table)
|
||||
})
|
||||
expect(result).toEqual(["_id", "name", "aux.name", "auxTable.name"])
|
||||
expect(result).toEqual([
|
||||
"_id",
|
||||
"name",
|
||||
"aux._id",
|
||||
"auxTable._id",
|
||||
"aux.name",
|
||||
"auxTable.name",
|
||||
])
|
||||
})
|
||||
|
||||
it("excludes all relationship fields if hidden", async () => {
|
||||
|
@ -387,10 +396,14 @@ describe("query utils", () => {
|
|||
"_id",
|
||||
"name",
|
||||
// aux1 primitive props
|
||||
"aux1._id",
|
||||
"aux1Table._id",
|
||||
"aux1.name",
|
||||
"aux1Table.name",
|
||||
|
||||
// aux2 primitive props
|
||||
"aux2._id",
|
||||
"aux2Table._id",
|
||||
"aux2.title",
|
||||
"aux2Table.title",
|
||||
])
|
||||
|
@ -405,14 +418,18 @@ describe("query utils", () => {
|
|||
"name",
|
||||
|
||||
// aux2_1 primitive props
|
||||
"aux2_1._id",
|
||||
"aux2Table._id",
|
||||
"aux2_1.title",
|
||||
"aux2Table.title",
|
||||
|
||||
// aux2_2 primitive props
|
||||
"aux2_2._id",
|
||||
"aux2_2.title",
|
||||
"aux2Table.title",
|
||||
|
||||
// table primitive props
|
||||
"table._id",
|
||||
"TestTable._id",
|
||||
"table.name",
|
||||
"TestTable.name",
|
||||
])
|
||||
|
@ -427,14 +444,18 @@ describe("query utils", () => {
|
|||
"title",
|
||||
|
||||
// aux1_1 primitive props
|
||||
"aux1_1._id",
|
||||
"aux1Table._id",
|
||||
"aux1_1.name",
|
||||
"aux1Table.name",
|
||||
|
||||
// aux1_2 primitive props
|
||||
"aux1_2._id",
|
||||
"aux1_2.name",
|
||||
"aux1Table.name",
|
||||
|
||||
// table primitive props
|
||||
"table._id",
|
||||
"TestTable._id",
|
||||
"table.name",
|
||||
"TestTable.name",
|
||||
])
|
||||
|
@ -481,6 +502,8 @@ describe("query utils", () => {
|
|||
"name",
|
||||
|
||||
// deep 1 aux primitive props
|
||||
"aux._id",
|
||||
"auxTable._id",
|
||||
"aux.title",
|
||||
"auxTable.title",
|
||||
])
|
||||
|
@ -495,6 +518,8 @@ describe("query utils", () => {
|
|||
"title",
|
||||
|
||||
// deep 1 dependency primitive props
|
||||
"table._id",
|
||||
"TestTable._id",
|
||||
"table.name",
|
||||
"TestTable.name",
|
||||
])
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
import {
|
||||
FieldType,
|
||||
INTERNAL_TABLE_SOURCE_ID,
|
||||
Table,
|
||||
TableSourceType,
|
||||
ViewV2,
|
||||
} from "@budibase/types"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import sdk from "../../.."
|
||||
|
||||
jest.mock("../../views", () => ({
|
||||
...jest.requireActual("../../views"),
|
||||
enrichSchema: jest.fn().mockImplementation(v => ({ ...v, mocked: true })),
|
||||
}))
|
||||
|
||||
describe("table sdk", () => {
|
||||
describe("enrichViewSchemas", () => {
|
||||
const basicTable: Table = {
|
||||
_id: generator.guid(),
|
||||
name: "TestTable",
|
||||
type: "table",
|
||||
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||
sourceType: TableSourceType.INTERNAL,
|
||||
schema: {
|
||||
name: {
|
||||
type: FieldType.STRING,
|
||||
name: "name",
|
||||
visible: true,
|
||||
width: 80,
|
||||
order: 2,
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: FieldType.STRING,
|
||||
name: "description",
|
||||
visible: true,
|
||||
width: 200,
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
id: {
|
||||
type: FieldType.NUMBER,
|
||||
name: "id",
|
||||
visible: true,
|
||||
order: 1,
|
||||
constraints: {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
hiddenField: {
|
||||
type: FieldType.STRING,
|
||||
name: "hiddenField",
|
||||
visible: false,
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
it("should fetch the default schema if not overriden", async () => {
|
||||
const tableId = basicTable._id!
|
||||
function getTable() {
|
||||
const view: ViewV2 = {
|
||||
version: 2,
|
||||
id: generator.guid(),
|
||||
name: generator.guid(),
|
||||
tableId,
|
||||
}
|
||||
return view
|
||||
}
|
||||
const view1 = getTable()
|
||||
const view2 = getTable()
|
||||
const view3 = getTable()
|
||||
const res = await sdk.tables.enrichViewSchemas({
|
||||
...basicTable,
|
||||
views: {
|
||||
[view1.name]: view1,
|
||||
[view2.name]: view2,
|
||||
[view3.name]: view3,
|
||||
},
|
||||
})
|
||||
|
||||
expect(sdk.views.enrichSchema).toHaveBeenCalledTimes(3)
|
||||
|
||||
expect(res).toEqual({
|
||||
...basicTable,
|
||||
views: {
|
||||
[view1.name]: {
|
||||
...view1,
|
||||
mocked: true,
|
||||
},
|
||||
[view2.name]: {
|
||||
...view2,
|
||||
mocked: true,
|
||||
},
|
||||
[view3.name]: {
|
||||
...view3,
|
||||
mocked: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
|
@ -7,7 +7,7 @@ import { default as queries } from "./app/queries"
|
|||
import { default as rows } from "./app/rows"
|
||||
import { default as links } from "./app/links"
|
||||
import { default as users } from "./users"
|
||||
import { default as plugins } from "./plugins"
|
||||
import * as plugins from "./plugins"
|
||||
import * as views from "./app/views"
|
||||
import * as permissions from "./app/permissions"
|
||||
import * as rowActions from "./app/rowActions"
|
||||
|
|
|
@ -1,5 +1,41 @@
|
|||
import * as plugins from "./plugins"
|
||||
import { KoaFile, Plugin, PluginSource, PluginType } from "@budibase/types"
|
||||
import {
|
||||
db as dbCore,
|
||||
objectStore,
|
||||
plugins as pluginCore,
|
||||
tenancy,
|
||||
} from "@budibase/backend-core"
|
||||
import { fileUpload } from "../../api/controllers/plugin/file"
|
||||
import env from "../../environment"
|
||||
import { clientAppSocket } from "../../websockets"
|
||||
import { sdk as pro } from "@budibase/pro"
|
||||
|
||||
export default {
|
||||
...plugins,
|
||||
export async function fetch(type?: PluginType): Promise<Plugin[]> {
|
||||
const db = tenancy.getGlobalDB()
|
||||
const response = await db.allDocs(
|
||||
dbCore.getPluginParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
||||
plugins = await objectStore.enrichPluginURLs(plugins)
|
||||
if (type) {
|
||||
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
||||
} else {
|
||||
return plugins
|
||||
}
|
||||
}
|
||||
|
||||
export async function processUploaded(plugin: KoaFile, source: PluginSource) {
|
||||
const { metadata, directory } = await fileUpload(plugin)
|
||||
pluginCore.validate(metadata.schema)
|
||||
|
||||
// Only allow components in cloud
|
||||
if (!env.SELF_HOSTED && metadata.schema?.type !== PluginType.COMPONENT) {
|
||||
throw new Error("Only component plugins are supported outside of self-host")
|
||||
}
|
||||
|
||||
const doc = await pro.plugins.storePlugin(metadata, directory, source)
|
||||
clientAppSocket?.emit("plugin-update", { name: doc.name, hash: doc.hash })
|
||||
return doc
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
import { KoaFile, Plugin, PluginSource, PluginType } from "@budibase/types"
|
||||
import {
|
||||
db as dbCore,
|
||||
objectStore,
|
||||
plugins as pluginCore,
|
||||
tenancy,
|
||||
} from "@budibase/backend-core"
|
||||
import { fileUpload } from "../../api/controllers/plugin/file"
|
||||
import env from "../../environment"
|
||||
import { clientAppSocket } from "../../websockets"
|
||||
import { sdk as pro } from "@budibase/pro"
|
||||
|
||||
export async function fetch(type?: PluginType): Promise<Plugin[]> {
|
||||
const db = tenancy.getGlobalDB()
|
||||
const response = await db.allDocs(
|
||||
dbCore.getPluginParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
||||
plugins = await objectStore.enrichPluginURLs(plugins)
|
||||
if (type) {
|
||||
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
||||
} else {
|
||||
return plugins
|
||||
}
|
||||
}
|
||||
|
||||
export async function processUploaded(plugin: KoaFile, source?: PluginSource) {
|
||||
const { metadata, directory } = await fileUpload(plugin)
|
||||
pluginCore.validate(metadata?.schema)
|
||||
|
||||
// Only allow components in cloud
|
||||
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {
|
||||
throw new Error("Only component plugins are supported outside of self-host")
|
||||
}
|
||||
|
||||
const doc = await pro.plugins.storePlugin(metadata, directory, source)
|
||||
clientAppSocket?.emit("plugin-update", { name: doc.name, hash: doc.hash })
|
||||
return doc
|
||||
}
|
|
@ -68,8 +68,12 @@ function getLoopIterable(step: LoopStep): any[] {
|
|||
let input = step.inputs.binding
|
||||
|
||||
if (option === LoopStepType.ARRAY && typeof input === "string") {
|
||||
if (input === "") {
|
||||
input = []
|
||||
} else {
|
||||
input = JSON.parse(input)
|
||||
}
|
||||
}
|
||||
|
||||
if (option === LoopStepType.STRING && Array.isArray(input)) {
|
||||
input = input.join(",")
|
||||
|
@ -363,6 +367,8 @@ class Orchestrator {
|
|||
if (e.errno === "ETIME") {
|
||||
span?.addTags({ timedOut: true })
|
||||
console.warn(`Automation execution timed out after ${timeout}ms`)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,7 +498,7 @@ class Orchestrator {
|
|||
}
|
||||
|
||||
const status =
|
||||
iterations === 0 ? AutomationStatus.NO_CONDITION_MET : undefined
|
||||
iterations === 0 ? AutomationStepStatus.NO_ITERATIONS : undefined
|
||||
return stepSuccess(stepToLoop, { status, iterations, items })
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Plugin } from "@budibase/types"
|
||||
import { Plugin, PluginUpload } from "@budibase/types"
|
||||
import { budibaseTempDir } from "../budibaseDir"
|
||||
import fs from "fs"
|
||||
import { join } from "path"
|
||||
|
@ -8,31 +8,31 @@ import stream from "stream"
|
|||
const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
|
||||
const AUTOMATION_PATH = join(budibaseTempDir(), "automation")
|
||||
|
||||
export const getPluginMetadata = async (path: string) => {
|
||||
let metadata: any = {}
|
||||
export const getPluginMetadata = async (
|
||||
path: string
|
||||
): Promise<PluginUpload> => {
|
||||
let pkg: any
|
||||
let schema: any
|
||||
try {
|
||||
const pkg = fs.readFileSync(join(path, "package.json"), "utf8")
|
||||
const schema = fs.readFileSync(join(path, "schema.json"), "utf8")
|
||||
|
||||
metadata.schema = JSON.parse(schema)
|
||||
metadata.package = JSON.parse(pkg)
|
||||
|
||||
if (
|
||||
!metadata.package.name ||
|
||||
!metadata.package.version ||
|
||||
!metadata.package.description
|
||||
) {
|
||||
throw new Error(
|
||||
"package.json is missing one of 'name', 'version' or 'description'."
|
||||
)
|
||||
pkg = JSON.parse(fs.readFileSync(join(path, "package.json"), "utf8"))
|
||||
schema = JSON.parse(fs.readFileSync(join(path, "schema.json"), "utf8"))
|
||||
if (!pkg.name) {
|
||||
throw new Error("package.json is missing 'name'.")
|
||||
}
|
||||
if (!pkg.version) {
|
||||
throw new Error("package.json is missing 'version'.")
|
||||
}
|
||||
if (!pkg.description) {
|
||||
throw new Error("package.json is missing 'description'.")
|
||||
}
|
||||
} catch (err: any) {
|
||||
throw new Error(
|
||||
`Unable to process schema.json/package.json in plugin. ${err.message}`
|
||||
`Unable to process schema.json/package.json in plugin. ${err.message}`,
|
||||
{ cause: err }
|
||||
)
|
||||
}
|
||||
|
||||
return { metadata, directory: path }
|
||||
return { metadata: { package: pkg, schema }, directory: path }
|
||||
}
|
||||
|
||||
async function getPluginImpl(path: string, plugin: Plugin) {
|
||||
|
|
|
@ -8,7 +8,15 @@ import {
|
|||
logging,
|
||||
env as coreEnv,
|
||||
} from "@budibase/backend-core"
|
||||
import { Ctx, User, EmailInvite, EmailAttachment } from "@budibase/types"
|
||||
import {
|
||||
Ctx,
|
||||
User,
|
||||
EmailInvite,
|
||||
EmailAttachment,
|
||||
SendEmailResponse,
|
||||
SendEmailRequest,
|
||||
EmailTemplatePurpose,
|
||||
} from "@budibase/types"
|
||||
|
||||
interface Request {
|
||||
ctx?: Ctx
|
||||
|
@ -110,25 +118,23 @@ export async function sendSmtpEmail({
|
|||
invite?: EmailInvite
|
||||
}) {
|
||||
// tenant ID will be set in header
|
||||
const response = await fetch(
|
||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`),
|
||||
createRequest({
|
||||
method: "POST",
|
||||
body: {
|
||||
const request: SendEmailRequest = {
|
||||
email: to,
|
||||
from,
|
||||
contents,
|
||||
subject,
|
||||
cc,
|
||||
bcc,
|
||||
purpose: "custom",
|
||||
purpose: EmailTemplatePurpose.CUSTOM,
|
||||
automation,
|
||||
invite,
|
||||
attachments,
|
||||
},
|
||||
})
|
||||
}
|
||||
const response = await fetch(
|
||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`),
|
||||
createRequest({ method: "POST", body: request })
|
||||
)
|
||||
return checkResponse(response, "send email")
|
||||
return (await checkResponse(response, "send email")) as SendEmailResponse
|
||||
}
|
||||
|
||||
export async function removeAppFromUserRoles(ctx: Ctx, appId: string) {
|
||||
|
|
|
@ -3,7 +3,8 @@ import env from "./environment"
|
|||
import chokidar from "chokidar"
|
||||
import fs from "fs"
|
||||
import { constants, tenancy } from "@budibase/backend-core"
|
||||
import pluginsSdk from "./sdk/plugins"
|
||||
import { processUploaded } from "./sdk/plugins"
|
||||
import { PluginSource } from "@budibase/types"
|
||||
|
||||
export function watch() {
|
||||
const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz")
|
||||
|
@ -27,7 +28,7 @@ export function watch() {
|
|||
const split = path.split("/")
|
||||
const name = split[split.length - 1]
|
||||
console.log("Importing plugin:", path)
|
||||
await pluginsSdk.processUploaded({ name, path })
|
||||
await processUploaded({ name, path }, PluginSource.FILE)
|
||||
} catch (err: any) {
|
||||
const message = err?.message ? err?.message : err
|
||||
console.error("Failed to import plugin:", message)
|
||||
|
|
|
@ -6,3 +6,4 @@ export * as cron from "./cron"
|
|||
export * as schema from "./schema"
|
||||
export * as views from "./views"
|
||||
export * as roles from "./roles"
|
||||
export * as lists from "./lists"
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
export function punctuateList(list: string[]) {
|
||||
if (list.length === 0) return ""
|
||||
if (list.length === 1) return list[0]
|
||||
if (list.length === 2) return list.join(" and ")
|
||||
return list.slice(0, -1).join(", ") + " and " + list[list.length - 1]
|
||||
}
|
|
@ -4,6 +4,7 @@ import {
|
|||
SEPARATOR,
|
||||
User,
|
||||
InternalTable,
|
||||
UserGroup,
|
||||
} from "@budibase/types"
|
||||
import { getProdAppID } from "./applications"
|
||||
import * as _ from "lodash/fp"
|
||||
|
@ -129,3 +130,30 @@ export function containsUserID(value: string | undefined): boolean {
|
|||
}
|
||||
return value.includes(`${DocumentType.USER}${SEPARATOR}`)
|
||||
}
|
||||
|
||||
export function getUserGroups(user: User, groups?: UserGroup[]) {
|
||||
return (
|
||||
groups?.filter(group => group.users?.find(u => u._id === user._id)) || []
|
||||
)
|
||||
}
|
||||
|
||||
export function getUserAppGroups(
|
||||
appId: string,
|
||||
user: User,
|
||||
groups?: UserGroup[]
|
||||
) {
|
||||
const prodAppId = getProdAppID(appId)
|
||||
const userGroups = getUserGroups(user, groups)
|
||||
return userGroups.filter(group =>
|
||||
Object.keys(group.roles || {}).find(app => app === prodAppId)
|
||||
)
|
||||
}
|
||||
|
||||
export function userAppAccessList(user: User, groups?: UserGroup[]) {
|
||||
const userGroups = getUserGroups(user, groups)
|
||||
const userGroupApps = userGroups.flatMap(userGroup =>
|
||||
Object.keys(userGroup.roles || {})
|
||||
)
|
||||
const fullList = [...Object.keys(user.roles), ...userGroupApps]
|
||||
return [...new Set(fullList)]
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ type BudibaseAnnotation = Annotation & {
|
|||
|
||||
type Helper = {
|
||||
args: string[]
|
||||
numArgs: number
|
||||
example?: string
|
||||
description: string
|
||||
requiresBlock?: boolean
|
||||
|
@ -34,15 +33,13 @@ const outputJSON: Manifest = {}
|
|||
const ADDED_HELPERS = {
|
||||
date: {
|
||||
date: {
|
||||
args: ["datetime", "format"],
|
||||
numArgs: 2,
|
||||
args: ["[datetime]", "[format]", "[options]"],
|
||||
example: '{{date now "DD-MM-YYYY" "America/New_York" }} -> 21-01-2021',
|
||||
description:
|
||||
"Format a date using moment.js date formatting - the timezone is optional and uses the tz database.",
|
||||
},
|
||||
duration: {
|
||||
args: ["time", "durationType"],
|
||||
numArgs: 2,
|
||||
example: '{{duration 8 "seconds"}} -> a few seconds',
|
||||
description:
|
||||
"Produce a humanized duration left/until given an amount of time and the type of time measurement.",
|
||||
|
@ -53,7 +50,6 @@ const ADDED_HELPERS = {
|
|||
function fixSpecialCases(name: string, obj: Helper) {
|
||||
if (name === "ifNth") {
|
||||
obj.args = ["a", "b", "options"]
|
||||
obj.numArgs = 3
|
||||
}
|
||||
if (name === "eachIndex") {
|
||||
obj.description = "Iterates the array, listing an item and the index of it."
|
||||
|
@ -163,7 +159,6 @@ function run() {
|
|||
.map(tag => tag.description!.replace(/`/g, "").split(" ")[0].trim())
|
||||
collectionInfo[name] = fixSpecialCases(name, {
|
||||
args,
|
||||
numArgs: args.length,
|
||||
example: jsDocInfo.example || undefined,
|
||||
description: jsDocInfo.description,
|
||||
requiresBlock: jsDocInfo.acceptsBlock && !jsDocInfo.acceptsInline,
|
||||
|
|
|
@ -71,7 +71,7 @@ function getContext(thisArg: any, locals: any, options: any) {
|
|||
function initialConfig(str: any, pattern: any, options?: any) {
|
||||
if (isOptions(pattern)) {
|
||||
options = pattern
|
||||
pattern = null
|
||||
pattern = DEFAULT_FORMAT
|
||||
}
|
||||
|
||||
if (isOptions(str)) {
|
||||
|
@ -93,13 +93,15 @@ function setLocale(this: any, str: any, pattern: any, options?: any) {
|
|||
dayjs.locale(opts.lang || opts.language)
|
||||
}
|
||||
|
||||
const DEFAULT_FORMAT = "MMMM DD, YYYY"
|
||||
|
||||
export const date = (str: any, pattern: any, options: any) => {
|
||||
const config = initialConfig(str, pattern, options)
|
||||
|
||||
// if no args are passed, return a formatted date
|
||||
if (config.str == null && config.pattern == null) {
|
||||
dayjs.locale("en")
|
||||
return dayjs().format("MMMM DD, YYYY")
|
||||
return dayjs().format(DEFAULT_FORMAT)
|
||||
}
|
||||
|
||||
setLocale(config.str, config.pattern, config.options)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"args": [
|
||||
"a"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ abs 12012.1000 }} -> 12012.1",
|
||||
"description": "<p>Return the magnitude of <code>a</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -14,7 +13,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ add 1 2 }} -> 3",
|
||||
"description": "<p>Return the sum of <code>a</code> plus <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -23,7 +21,6 @@
|
|||
"args": [
|
||||
"array"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ avg 1 2 3 4 5 }} -> 3",
|
||||
"description": "<p>Returns the average of all numbers in the given array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -32,7 +29,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ ceil 1.2 }} -> 2",
|
||||
"description": "<p>Get the <code>Math.ceil()</code> of the given value.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -42,7 +38,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ divide 10 5 }} -> 2",
|
||||
"description": "<p>Divide <code>a</code> by <code>b</code></p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -51,7 +46,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ floor 1.2 }} -> 1",
|
||||
"description": "<p>Get the <code>Math.floor()</code> of the given value.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -61,7 +55,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ subtract 10 5 }} -> 5",
|
||||
"description": "<p>Return the product of <code>a</code> minus <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -71,7 +64,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ modulo 10 5 }} -> 0",
|
||||
"description": "<p>Get the remainder of a division operation.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -81,7 +73,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ multiply 10 5 }} -> 50",
|
||||
"description": "<p>Multiply number <code>a</code> by number <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -91,7 +82,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ plus 10 5 }} -> 15",
|
||||
"description": "<p>Add <code>a</code> by <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -101,7 +91,6 @@
|
|||
"min",
|
||||
"max"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ random 0 20 }} -> 10",
|
||||
"description": "<p>Generate a random number between two values</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -111,7 +100,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ remainder 10 6 }} -> 4",
|
||||
"description": "<p>Get the remainder when <code>a</code> is divided by <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -120,7 +108,6 @@
|
|||
"args": [
|
||||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ round 10.3 }} -> 10",
|
||||
"description": "<p>Round the given number.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -130,7 +117,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ subtract 10 5 }} -> 5",
|
||||
"description": "<p>Return the product of <code>a</code> minus <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -139,7 +125,6 @@
|
|||
"args": [
|
||||
"array"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ sum [1, 2, 3] }} -> 6",
|
||||
"description": "<p>Returns the sum of all numbers in the given array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -151,7 +136,6 @@
|
|||
"array",
|
||||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd']",
|
||||
"description": "<p>Returns all of the items in an array after the specified index. Opposite of <a href=\"#before\">before</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -160,7 +144,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ arrayify 'foo' }} -> ['foo']",
|
||||
"description": "<p>Cast the given <code>value</code> to an array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -170,7 +153,6 @@
|
|||
"array",
|
||||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b']",
|
||||
"description": "<p>Return all of the items in the collection before the specified count. Opposite of <a href=\"#after\">after</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -180,7 +162,6 @@
|
|||
"array",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '",
|
||||
"description": "<p>Iterates the array, listing an item and the index of it.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -191,7 +172,6 @@
|
|||
"value",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found",
|
||||
"description": "<p>Block helper that filters the given array and renders the block for values that evaluate to <code>true</code>, otherwise the inverse block is returned.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -201,7 +181,6 @@
|
|||
"array",
|
||||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{first [1, 2, 3, 4] 2}} -> 1,2",
|
||||
"description": "<p>Returns the first item, or first <code>n</code> items of an array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -211,7 +190,6 @@
|
|||
"array",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John '",
|
||||
"description": "<p>Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - <code>index</code> - <code>total</code> - <code>isFirst</code> - <code>isLast</code> Also, <code>@index</code> is exposed as a private variable, and additional private variables may be defined as hash arguments.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -222,7 +200,6 @@
|
|||
"value",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists '",
|
||||
"description": "<p>Block helper that renders the block if an array has the given <code>value</code>. Optionally specify an inverse block to render when the array does not have the given value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -231,7 +208,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{isArray [1, 2]}} -> true",
|
||||
"description": "<p>Returns true if <code>value</code> is an es5 array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -241,7 +217,6 @@
|
|||
"array",
|
||||
"idx"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{itemAt [1, 2, 3] 1}} -> 2",
|
||||
"description": "<p>Returns the item from <code>array</code> at index <code>idx</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -251,7 +226,6 @@
|
|||
"array",
|
||||
"separator"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{join [1, 2, 3]}} -> 1, 2, 3",
|
||||
"description": "<p>Join all elements of array into a string, optionally using a given separator.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -261,7 +235,6 @@
|
|||
"value",
|
||||
"length"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{equalsLength [1, 2, 3] 3}} -> true",
|
||||
"description": "<p>Returns true if the the length of the given <code>value</code> is equal to the given <code>length</code>. Can be used as a block or inline helper.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -271,7 +244,6 @@
|
|||
"value",
|
||||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{last [1, 2, 3]}} -> 3",
|
||||
"description": "<p>Returns the last item, or last <code>n</code> items of an array or string. Opposite of <a href=\"#first\">first</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -280,7 +252,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{length [1, 2, 3]}} -> 3",
|
||||
"description": "<p>Returns the length of the given string or array.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -290,7 +261,6 @@
|
|||
"value",
|
||||
"length"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{equalsLength [1, 2, 3] 3}} -> true",
|
||||
"description": "<p>Returns true if the the length of the given <code>value</code> is equal to the given <code>length</code>. Can be used as a block or inline helper.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -300,7 +270,6 @@
|
|||
"array",
|
||||
"fn"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{map [1, 2, 3] double}} -> [2, 4, 6]",
|
||||
"description": "<p>Returns a new array, created by calling <code>function</code> on each element of the given <code>array</code>. For example,</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -310,7 +279,6 @@
|
|||
"collection",
|
||||
"prop"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{pluck [{ 'name': 'Bob' }] 'name' }} -> ['Bob']",
|
||||
"description": "<p>Map over the given object or array or objects and create an array of values from the given <code>prop</code>. Dot-notation may be used (as a string) to get nested properties.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -319,7 +287,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{reverse [1, 2, 3]}} -> [3, 2, 1]",
|
||||
"description": "<p>Reverse the elements in an array, or the characters in a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -330,7 +297,6 @@
|
|||
"iter",
|
||||
"provided"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#some [1, \"b\", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found '",
|
||||
"description": "<p>Block helper that returns the block if the callback returns true for some value in the given array.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -340,7 +306,6 @@
|
|||
"array",
|
||||
"key"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']",
|
||||
"description": "<p>Sort the given <code>array</code>. If an array of objects is passed, you may optionally pass a <code>key</code> to sort on as the second argument. You may alternatively pass a sorting function as the second argument.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -350,7 +315,6 @@
|
|||
"array",
|
||||
"props"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}]",
|
||||
"description": "<p>Sort an <code>array</code>. If an array of objects is passed, you may optionally pass a <code>key</code> to sort on as the second argument. You may alternatively pass a sorting function as the second argument.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -361,7 +325,6 @@
|
|||
"idx",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 '",
|
||||
"description": "<p>Use the items in the array <em>after</em> the specified index as context inside a block. Opposite of <a href=\"#withBefore\">withBefore</a>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -372,7 +335,6 @@
|
|||
"idx",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '",
|
||||
"description": "<p>Use the items in the array <em>before</em> the specified index as context inside a block. Opposite of <a href=\"#withAfter\">withAfter</a>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -383,7 +345,6 @@
|
|||
"idx",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1",
|
||||
"description": "<p>Use the first item in a collection inside a handlebars block expression. Opposite of <a href=\"#withLast\">withLast</a>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -394,7 +355,6 @@
|
|||
"size",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}<br>{{/withGroup}} -> 12<br>34<br>",
|
||||
"description": "<p>Block helper that groups array elements by given group <code>size</code>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -405,7 +365,6 @@
|
|||
"idx",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4",
|
||||
"description": "<p>Use the last item or <code>n</code> items in an array as context inside a block. Opposite of <a href=\"#withFirst\">withFirst</a>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -416,7 +375,6 @@
|
|||
"prop",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc",
|
||||
"description": "<p>Block helper that sorts a collection and exposes the sorted collection as context inside the block.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -426,7 +384,6 @@
|
|||
"array",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe",
|
||||
"description": "<p>Block helper that return an array with all duplicate values removed. Best used along with a <a href=\"#each\">each</a> helper.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -437,7 +394,6 @@
|
|||
"args": [
|
||||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ bytes 1386 1 }} -> 1.4 kB",
|
||||
"description": "<p>Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. <strong>Examples:</strong> - <code>'foo' => 3 B</code> - <code>13661855 => 13.66 MB</code> - <code>825399 => 825.39 kB</code> - <code>1396 => 1.4 kB</code></p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -446,7 +402,6 @@
|
|||
"args": [
|
||||
"num"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ addCommas 1000000 }} -> 1,000,000",
|
||||
"description": "<p>Add commas to numbers</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -455,7 +410,6 @@
|
|||
"args": [
|
||||
"num"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212",
|
||||
"description": "<p>Convert a string or number to a formatted phone number.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -465,7 +419,6 @@
|
|||
"number",
|
||||
"precision"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toAbbr 10123 2 }} -> 10.12k",
|
||||
"description": "<p>Abbreviate numbers to the given number of <code>precision</code>. This for general numbers, not size in bytes.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -475,7 +428,6 @@
|
|||
"number",
|
||||
"fractionDigits"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toExponential 10123 2 }} -> 1.01e+4",
|
||||
"description": "<p>Returns a string representing the given number in exponential notation.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -485,7 +437,6 @@
|
|||
"number",
|
||||
"digits"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toFixed 1.1234 2 }} -> 1.12",
|
||||
"description": "<p>Formats the given number using fixed-point notation.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -494,7 +445,6 @@
|
|||
"args": [
|
||||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Convert input to a float.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -502,7 +452,6 @@
|
|||
"args": [
|
||||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Convert input to an integer.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -511,7 +460,6 @@
|
|||
"number",
|
||||
"precision"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{toPrecision '1.1234' 2}} -> 1.1",
|
||||
"description": "<p>Returns a string representing the <code>Number</code> object to the specified precision.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -522,7 +470,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There",
|
||||
"description": "<p>Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -531,7 +478,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere",
|
||||
"description": "<p>Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -540,7 +486,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There",
|
||||
"description": "<p>Decode a Uniform Resource Identifier (URI) component.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -550,7 +495,6 @@
|
|||
"base",
|
||||
"href"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test",
|
||||
"description": "<p>Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -559,7 +503,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ urlParse 'https://myurl/api/test' }}",
|
||||
"description": "<p>Parses a <code>url</code> string into an object.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -568,7 +511,6 @@
|
|||
"args": [
|
||||
"url"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test'",
|
||||
"description": "<p>Strip the query string from the given <code>url</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -577,7 +519,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test'",
|
||||
"description": "<p>Strip protocol from a <code>url</code>. Useful for displaying media that may have an 'http' protocol on secure connections.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -589,7 +530,6 @@
|
|||
"str",
|
||||
"suffix"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{append 'index' '.html'}} -> index.html",
|
||||
"description": "<p>Append the specified <code>suffix</code> to the given string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -598,7 +538,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{camelcase 'foo bar baz'}} -> fooBarBaz",
|
||||
"description": "<p>camelCase the characters in the given <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -607,7 +546,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{capitalize 'foo bar baz'}} -> Foo bar baz",
|
||||
"description": "<p>Capitalize the first word in a sentence.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -616,7 +554,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz",
|
||||
"description": "<p>Capitalize all words in a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -626,7 +563,6 @@
|
|||
"str",
|
||||
"spaces"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ center 'test' 1}} -> ' test '",
|
||||
"description": "<p>Center a string using non-breaking spaces</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -635,7 +571,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ chop ' ABC '}} -> ABC",
|
||||
"description": "<p>Like trim, but removes both extraneous whitespace <strong>and non-word characters</strong> from the beginning and end of a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -644,7 +579,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{dashcase 'a-b-c d_e'}} -> a-b-c-d-e",
|
||||
"description": "<p>dash-case the characters in <code>string</code>. Replaces non-word characters and periods with hyphens.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -653,7 +587,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{dotcase 'a-b-c d_e'}} -> a.b.c.d.e",
|
||||
"description": "<p>dot.case the characters in <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -662,7 +595,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{downcase 'aBcDeF'}} -> abcdef",
|
||||
"description": "<p>Lowercase all of the characters in the given string. Alias for <a href=\"#lowercase\">lowercase</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -672,7 +604,6 @@
|
|||
"str",
|
||||
"length"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ellipsis 'foo bar baz' 7}} -> foo bar…",
|
||||
"description": "<p>Truncates a string to the specified <code>length</code>, and appends it with an elipsis, <code>…</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -681,7 +612,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{hyphenate 'foo bar baz qux'}} -> foo-bar-baz-qux",
|
||||
"description": "<p>Replace spaces in a string with hyphens.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -690,7 +620,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{isString 'foo'}} -> true",
|
||||
"description": "<p>Return true if <code>value</code> is a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -699,7 +628,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{lowercase 'Foo BAR baZ'}} -> foo bar baz",
|
||||
"description": "<p>Lowercase all characters in the given string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -709,7 +637,6 @@
|
|||
"str",
|
||||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{occurrences 'foo bar foo bar baz' 'foo'}} -> 2",
|
||||
"description": "<p>Return the number of occurrences of <code>substring</code> within the given <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -718,7 +645,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{pascalcase 'foo bar baz'}} -> FooBarBaz",
|
||||
"description": "<p>PascalCase the characters in <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -727,7 +653,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{pathcase 'a-b-c d_e'}} -> a/b/c/d/e",
|
||||
"description": "<p>path/case the characters in <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -736,7 +661,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{plusify 'foo bar baz'}} -> foo+bar+baz",
|
||||
"description": "<p>Replace spaces in the given string with pluses.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -746,7 +670,6 @@
|
|||
"str",
|
||||
"prefix"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{prepend 'bar' 'foo-'}} -> foo-bar",
|
||||
"description": "<p>Prepends the given <code>string</code> with the specified <code>prefix</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -756,7 +679,6 @@
|
|||
"str",
|
||||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{remove 'a b a b a b' 'a '}} -> b b b",
|
||||
"description": "<p>Remove all occurrences of <code>substring</code> from the given <code>str</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -766,7 +688,6 @@
|
|||
"str",
|
||||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b'",
|
||||
"description": "<p>Remove the first occurrence of <code>substring</code> from the given <code>str</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -777,7 +698,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b",
|
||||
"description": "<p>Replace all occurrences of substring <code>a</code> with substring <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -788,7 +708,6 @@
|
|||
"a",
|
||||
"b"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b",
|
||||
"description": "<p>Replace the first occurrence of substring <code>a</code> with substring <code>b</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -797,7 +716,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world.",
|
||||
"description": "<p>Sentence case the given string</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -806,7 +724,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{snakecase 'a-b-c d_e'}} -> a_b_c_d_e",
|
||||
"description": "<p>snake_case the characters in the given <code>string</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -815,7 +732,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{split 'a,b,c'}} -> ['a', 'b', 'c']",
|
||||
"description": "<p>Split <code>string</code> by the given <code>character</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -826,7 +742,6 @@
|
|||
"testString",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope",
|
||||
"description": "<p>Tests whether a string begins with the given prefix.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -835,7 +750,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{titleize 'this is title case' }} -> This Is Title Case",
|
||||
"description": "<p>Title case the given string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -844,7 +758,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trim ' ABC ' }} -> ABC",
|
||||
"description": "<p>Removes extraneous whitespace from the beginning and end of a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -853,7 +766,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trimLeft ' ABC ' }} -> 'ABC '",
|
||||
"description": "<p>Removes extraneous whitespace from the beginning of a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -862,7 +774,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trimRight ' ABC ' }} -> ' ABC'",
|
||||
"description": "<p>Removes extraneous whitespace from the end of a string.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -873,7 +784,6 @@
|
|||
"limit",
|
||||
"suffix"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{truncate 'foo bar baz' 7 }} -> foo bar",
|
||||
"description": "<p>Truncate a string to the specified <code>length</code>. Also see <a href=\"#ellipsis\">ellipsis</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -884,7 +794,6 @@
|
|||
"limit",
|
||||
"suffix"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{truncateWords 'foo bar baz' 1 }} -> foo…",
|
||||
"description": "<p>Truncate a string to have the specified number of words. Also see <a href=\"#truncate\">truncate</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -893,7 +802,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{upcase 'aBcDef'}} -> ABCDEF",
|
||||
"description": "<p>Uppercase all of the characters in the given string. Alias for <a href=\"#uppercase\">uppercase</a>.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -903,7 +811,6 @@
|
|||
"str",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{uppercase 'aBcDef'}} -> ABCDEF",
|
||||
"description": "<p>Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -912,7 +819,6 @@
|
|||
"args": [
|
||||
"num"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{lorem 11}} -> Lorem ipsum",
|
||||
"description": "<p>Takes a number and returns that many charaters of Lorem Ipsum</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -925,7 +831,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no",
|
||||
"description": "<p>Helper that renders the block if <strong>both</strong> of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -937,7 +842,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 4,
|
||||
"example": "{{compare 10 '<' 5 }} -> false",
|
||||
"description": "<p>Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -949,7 +853,6 @@
|
|||
"[startIndex=0]",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 4,
|
||||
"example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '",
|
||||
"description": "<p>Block helper that renders the block if <code>collection</code> has the given <code>value</code>, using strict equality (<code>===</code>) for comparison, otherwise the inverse block is rendered (if specified). If a <code>startIndex</code> is specified and is negative, it is used as the offset from the end of the collection.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -959,7 +862,6 @@
|
|||
"value",
|
||||
"defaultValue"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{default null null 'default'}} -> default",
|
||||
"description": "<p>Returns the first value that is not undefined, otherwise the 'default' value is returned.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -970,7 +872,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=''</code> hash argument for the second value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -981,7 +882,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than'",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>greater than</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=''</code> hash argument for the second value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -992,7 +892,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal'",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>greater than or equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=''</code> hash argument for the second value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1003,7 +902,6 @@
|
|||
"pattern",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it",
|
||||
"description": "<p>Block helper that renders a block if <code>value</code> has <code>pattern</code>. If an inverse block is specified it will be rendered when falsy.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1013,7 +911,6 @@
|
|||
"val",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{isFalsey '' }} -> true",
|
||||
"description": "<p>Returns true if the given <code>value</code> is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -1023,7 +920,6 @@
|
|||
"val",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{isTruthy '12' }} -> true",
|
||||
"description": "<p>Returns true if the given <code>value</code> is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -1033,7 +929,6 @@
|
|||
"number",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even '",
|
||||
"description": "<p>Return true if the given value is an even number.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1044,7 +939,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder",
|
||||
"description": "<p>Conditionally renders a block if the remainder is zero when <code>b</code> operand is divided by <code>a</code>. If an inverse block is specified it will be rendered when the remainder is <strong>not zero</strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1054,7 +948,6 @@
|
|||
"value",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd",
|
||||
"description": "<p>Block helper that renders a block if <code>value</code> is <strong>an odd number</strong>. If an inverse block is specified it will be rendered when falsy.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1065,7 +958,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#is 3 3}} is {{else}} is not {{/is}} -> ' is '",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. Similar to <a href=\"#eq\">eq</a> but does not do strict equality.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1076,7 +968,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is '",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>not equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. Similar to <a href=\"#unlesseq\">unlessEq</a> but does not use strict equality for comparisons.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1086,7 +977,6 @@
|
|||
"context",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than '",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>less than</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=''</code> hash argument for the second value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1097,7 +987,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal '",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>less than or equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=''</code> hash argument for the second value.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1108,7 +997,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey",
|
||||
"description": "<p>Block helper that renders a block if <strong>neither of</strong> the given values are truthy. If an inverse block is specified it will be rendered when falsy.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1118,7 +1006,6 @@
|
|||
"val",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey",
|
||||
"description": "<p>Returns true if <code>val</code> is falsey. Works as a block or inline helper.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1128,7 +1015,6 @@
|
|||
"arguments",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy '",
|
||||
"description": "<p>Block helper that renders a block if <strong>any of</strong> the given values is truthy. If an inverse block is specified it will be rendered when falsy.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1139,7 +1025,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal '",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is equal to <code>b</code></strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1150,7 +1035,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than '",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is greater than <code>b</code></strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1161,7 +1045,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is less than <code>b</code></strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1172,7 +1055,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is greater than or equal to <code>b</code></strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1183,7 +1065,6 @@
|
|||
"b",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than '",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is less than or equal to <code>b</code></strong>.</p>\n",
|
||||
"requiresBlock": true
|
||||
|
@ -1194,7 +1075,6 @@
|
|||
"args": [
|
||||
"objects"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1203,7 +1083,6 @@
|
|||
"context",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"description": "<p>Block helper that iterates over the properties of an object, exposing each key and value on the context.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1212,7 +1091,6 @@
|
|||
"obj",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"description": "<p>Block helper that iterates over the <strong>own</strong> properties of an object, exposing each key and value on the context.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1220,7 +1098,6 @@
|
|||
"args": [
|
||||
"prop"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Take arguments and, if they are string or number, convert them to a dot-delineated object property path.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1230,7 +1107,6 @@
|
|||
"context",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"description": "<p>Use property paths (<code>a.b.c</code>) to get a value or nested value from the context. Works as a regular helper or block helper.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1239,7 +1115,6 @@
|
|||
"prop",
|
||||
"context"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"description": "<p>Use property paths (<code>a.b.c</code>) to get an object from the context. Differs from the <code>get</code> helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1248,7 +1123,6 @@
|
|||
"key",
|
||||
"context"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"description": "<p>Return true if <code>key</code> is an own, enumerable property of the given <code>context</code> object.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1256,7 +1130,6 @@
|
|||
"args": [
|
||||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Return true if <code>value</code> is an object.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1264,7 +1137,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Parses the given string using <code>JSON.parse</code>.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1272,7 +1144,6 @@
|
|||
"args": [
|
||||
"obj"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1281,7 +1152,6 @@
|
|||
"object",
|
||||
"objects"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"description": "<p>Deeply merge the properties of the given <code>objects</code> with the context object.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
|
@ -1289,7 +1159,6 @@
|
|||
"args": [
|
||||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Parses the given string using <code>JSON.parse</code>.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1299,7 +1168,6 @@
|
|||
"context",
|
||||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"description": "<p>Pick properties from the context object.</p>\n",
|
||||
"requiresBlock": true
|
||||
},
|
||||
|
@ -1307,7 +1175,6 @@
|
|||
"args": [
|
||||
"obj"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n",
|
||||
"requiresBlock": false
|
||||
}
|
||||
|
@ -1317,7 +1184,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{toRegex 'foo'}} -> /foo/",
|
||||
"description": "<p>Convert the given string to a regular expression.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -1326,7 +1192,6 @@
|
|||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{test 'foobar' (toRegex 'foo')}} -> true",
|
||||
"description": "<p>Returns true if the given <code>str</code> matches the given regex. A regex can be passed on the context, or using the <a href=\"#toregex\">toRegex</a> helper as a subexpression.</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -1335,7 +1200,6 @@
|
|||
"uuid": {
|
||||
"uuid": {
|
||||
"args": [],
|
||||
"numArgs": 0,
|
||||
"example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc",
|
||||
"description": "<p>Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).</p>\n",
|
||||
"requiresBlock": false
|
||||
|
@ -1344,10 +1208,10 @@
|
|||
"date": {
|
||||
"date": {
|
||||
"args": [
|
||||
"datetime",
|
||||
"format"
|
||||
"[datetime]",
|
||||
"[format]",
|
||||
"[options]"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{date now \"DD-MM-YYYY\" \"America/New_York\" }} -> 21-01-2021",
|
||||
"description": "<p>Format a date using moment.js date formatting - the timezone is optional and uses the tz database.</p>\n"
|
||||
},
|
||||
|
@ -1356,7 +1220,6 @@
|
|||
"time",
|
||||
"durationType"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{duration 8 \"seconds\"}} -> a few seconds",
|
||||
"description": "<p>Produce a humanized duration left/until given an amount of time and the type of time measurement.</p>\n"
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"@budibase/nano": "10.1.5",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/koa": "2.13.4",
|
||||
"@types/nodemailer": "^6.4.17",
|
||||
"@types/redlock": "4.0.7",
|
||||
"koa-useragent": "^4.1.0",
|
||||
"rimraf": "3.0.2",
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue