Merge branch 'master' into fix/automation-adjacent-bugs
This commit is contained in:
commit
f3c5a2b973
|
@ -9,8 +9,5 @@ packages/server/client
|
|||
packages/server/coverage
|
||||
packages/builder/.routify
|
||||
packages/sdk/sdk
|
||||
packages/account-portal/packages/server/build
|
||||
packages/account-portal/packages/ui/.routify
|
||||
packages/account-portal/packages/ui/build
|
||||
**/*.ivm.bundle.js
|
||||
packages/server/build/oldClientVersions/**/**
|
||||
|
|
|
@ -64,18 +64,15 @@ jobs:
|
|||
- run: yarn --frozen-lockfile
|
||||
|
||||
# Run build all the projects
|
||||
- name: Build OSS
|
||||
run: yarn build:oss
|
||||
- name: Build account portal
|
||||
run: yarn build:account-portal
|
||||
if: ${{ env.IS_OSS_CONTRIBUTOR == 'false' }}
|
||||
- name: Build
|
||||
run: yarn build
|
||||
# Check the types of the projects built via esbuild
|
||||
- name: Check types
|
||||
run: |
|
||||
if ${{ env.ONLY_AFFECTED_TASKS }}; then
|
||||
yarn check:types --since=${{ env.NX_BASE_BRANCH }} --ignore @budibase/account-portal-server
|
||||
yarn check:types --since=${{ env.NX_BASE_BRANCH }}
|
||||
else
|
||||
yarn check:types --ignore @budibase/account-portal-server
|
||||
yarn check:types
|
||||
fi
|
||||
|
||||
helm-lint:
|
||||
|
@ -117,9 +114,11 @@ jobs:
|
|||
- name: Test
|
||||
run: |
|
||||
if ${{ env.ONLY_AFFECTED_TASKS }}; then
|
||||
yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }}
|
||||
yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --ignore=@budibase/builder --no-prefix --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions
|
||||
yarn test -- --scope=@budibase/builder --since=${{ env.NX_BASE_BRANCH }}
|
||||
else
|
||||
yarn test --ignore=@budibase/worker --ignore=@budibase/server
|
||||
yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --ignore=@budibase/builder --no-prefix -- --verbose --reporters=default --reporters=github-actions
|
||||
yarn test -- --scope=@budibase/builder --no-prefix
|
||||
fi
|
||||
|
||||
test-worker:
|
||||
|
@ -141,16 +140,22 @@ jobs:
|
|||
- name: Test worker
|
||||
run: |
|
||||
if ${{ env.ONLY_AFFECTED_TASKS }}; then
|
||||
node scripts/run-affected.js --task=test --scope=@budibase/worker --since=${{ env.NX_BASE_BRANCH }}
|
||||
else
|
||||
yarn test --scope=@budibase/worker
|
||||
AFFECTED=$(yarn --silent nx show projects --affected -t test --base=${{ env.NX_BASE_BRANCH }} -p @budibase/worker)
|
||||
if [ -z "$AFFECTED" ]; then
|
||||
echo "No affected tests to run"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
cd packages/worker
|
||||
yarn test --verbose --reporters=default --reporters=github-actions
|
||||
|
||||
test-server:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
datasource: [mssql, mysql, postgres, mongodb, mariadb, oracle, none]
|
||||
datasource:
|
||||
[mssql, mysql, postgres, mongodb, mariadb, oracle, sqs, none]
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
@ -213,7 +218,7 @@ jobs:
|
|||
fi
|
||||
|
||||
cd packages/server
|
||||
yarn test --filter $FILTER --passWithNoTests
|
||||
yarn test --filter $FILTER --verbose --reporters=default --reporters=github-actions
|
||||
|
||||
check-pro-submodule:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -274,64 +279,6 @@ jobs:
|
|||
echo 'All good, the submodule had been merged and setup correctly!'
|
||||
fi
|
||||
|
||||
check-accountportal-submodule:
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: dorny/paths-filter@v3
|
||||
id: changes
|
||||
with:
|
||||
filters: |
|
||||
src:
|
||||
- packages/account-portal/**
|
||||
|
||||
- if: steps.changes.outputs.src == 'true'
|
||||
name: Check account portal commit
|
||||
id: get_accountportal_commits
|
||||
run: |
|
||||
cd packages/account-portal
|
||||
accountportal_commit=$(git rev-parse HEAD)
|
||||
|
||||
branch="${{ github.base_ref || github.ref_name }}"
|
||||
echo "Running on branch '$branch' (base_ref=${{ github.base_ref }}, ref_name=${{ github.head_ref }})"
|
||||
|
||||
base_commit=$(git rev-parse origin/master)
|
||||
|
||||
if [[ ! -z $base_commit ]]; then
|
||||
echo "target_branch=$branch"
|
||||
echo "target_branch=$branch" >> "$GITHUB_OUTPUT"
|
||||
echo "accountportal_commit=$accountportal_commit"
|
||||
echo "accountportal_commit=$accountportal_commit" >> "$GITHUB_OUTPUT"
|
||||
echo "base_commit=$base_commit"
|
||||
echo "base_commit=$base_commit" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Nothing to do - branch to branch merge."
|
||||
fi
|
||||
|
||||
- name: Check submodule merged to base branch
|
||||
if: ${{ steps.get_accountportal_commits.outputs.base_commit != '' }}
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const submoduleCommit = '${{ steps.get_accountportal_commits.outputs.accountportal_commit }}';
|
||||
const baseCommit = '${{ steps.get_accountportal_commits.outputs.base_commit }}';
|
||||
|
||||
if (submoduleCommit !== baseCommit) {
|
||||
console.error('Submodule commit does not match the latest commit on the "${{ steps.get_accountportal_commits.outputs.target_branch }}" branch.');
|
||||
console.error('Refer to the account portal repo to merge your changes: https://github.com/Budibase/account-portal/blob/master/docs/index.md')
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('All good, the submodule had been merged and setup correctly!')
|
||||
}
|
||||
|
||||
check-lockfile:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
@ -8,6 +8,7 @@ packages/server/build/oldClientVersions/**/*
|
|||
packages/builder/src/components/deploy/clientVersions.json
|
||||
packages/server/src/integrations/tests/utils/*.lock
|
||||
packages/builder/vite.config.mjs.timestamp*
|
||||
packages/account-portal
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
@ -110,4 +111,4 @@ budibase-component
|
|||
budibase-datasource
|
||||
|
||||
*.iml
|
||||
.nx
|
||||
.nx
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
[submodule "packages/pro"]
|
||||
path = packages/pro
|
||||
url = git@github.com:Budibase/budibase-pro.git
|
||||
[submodule "packages/account-portal"]
|
||||
path = packages/account-portal
|
||||
url = git@github.com:Budibase/account-portal.git
|
||||
|
|
|
@ -9,8 +9,4 @@ packages/backend-core/coverage
|
|||
packages/builder/.routify
|
||||
packages/sdk/sdk
|
||||
packages/pro/coverage
|
||||
packages/account-portal/packages/ui/build
|
||||
packages/account-portal/packages/ui/.routify
|
||||
packages/account-portal/packages/server/build
|
||||
packages/account-portal/packages/server/coverage
|
||||
**/*.ivm.bundle.js
|
|
@ -20,16 +20,6 @@
|
|||
"args": ["${workspaceFolder}/packages/worker/src/index.ts"],
|
||||
"cwd": "${workspaceFolder}/packages/worker"
|
||||
},
|
||||
{
|
||||
"name": "Camunda Worker",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
||||
"args": [
|
||||
"${workspaceFolder}/packages/account-portal/packages/server/src/v2/run.ts"
|
||||
],
|
||||
"cwd": "${workspaceFolder}/packages/account-portal/packages/server"
|
||||
},
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
|
|
|
@ -423,9 +423,9 @@ core-js-pure@^3.20.2:
|
|||
integrity sha512-12VZfFIu+wyVbBebyHmRTuEE/tZrB4tJToWcwAMcsp3h4+sHR+fMJWbKpYiCRWlhFBq+KNyO8rIV9rTkeVmznQ==
|
||||
|
||||
cross-spawn@^7.0.2:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
|
||||
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
|
||||
version "7.0.6"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
|
||||
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
|
||||
dependencies:
|
||||
path-key "^3.1.0"
|
||||
shebang-command "^2.0.0"
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"version": "3.2.5",
|
||||
"version": "3.2.12",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*",
|
||||
"!packages/account-portal",
|
||||
"packages/account-portal/packages/*"
|
||||
],
|
||||
"concurrency": 20,
|
||||
"command": {
|
||||
"publish": {
|
||||
|
|
1
nx.json
1
nx.json
|
@ -2,7 +2,6 @@
|
|||
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
||||
"tasksRunnerOptions": {
|
||||
"default": {
|
||||
"runner": "nx-cloud",
|
||||
"options": {
|
||||
"cacheableOperations": ["build", "test", "check:types"]
|
||||
}
|
||||
|
|
29
package.json
29
package.json
|
@ -9,6 +9,7 @@
|
|||
"@types/node": "20.10.0",
|
||||
"@types/proper-lockfile": "^4.1.4",
|
||||
"@typescript-eslint/parser": "6.9.0",
|
||||
"depcheck": "^1.4.7",
|
||||
"esbuild": "^0.18.17",
|
||||
"esbuild-node-externals": "^1.14.0",
|
||||
"eslint": "^8.52.0",
|
||||
|
@ -24,22 +25,22 @@
|
|||
"prettier": "2.8.8",
|
||||
"prettier-plugin-svelte": "^2.3.0",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"svelte": "^4.2.10",
|
||||
"svelte": "4.2.19",
|
||||
"svelte-eslint-parser": "^0.33.1",
|
||||
"typescript": "5.5.2",
|
||||
"typescript-eslint": "^7.3.1",
|
||||
"yargs": "^17.7.2"
|
||||
"yargs": "^17.7.2",
|
||||
"cross-spawn": "7.0.6"
|
||||
},
|
||||
"scripts": {
|
||||
"get-past-client-version": "node scripts/getPastClientVersion.js",
|
||||
"setup": "git config submodule.recurse true && git submodule update && node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev",
|
||||
"build": "DISABLE_V8_COMPILE_CACHE=1 NODE_OPTIONS=--max-old-space-size=1500 lerna run build --stream",
|
||||
"build:apps": "DISABLE_V8_COMPILE_CACHE=1 yarn build --scope @budibase/server --scope @budibase/worker",
|
||||
"build:oss": "DISABLE_V8_COMPILE_CACHE=1 NODE_OPTIONS=--max-old-space-size=1500 lerna run build --stream --ignore @budibase/account-portal-server --ignore @budibase/account-portal-ui",
|
||||
"build:cli": "yarn build --scope @budibase/cli",
|
||||
"build:account-portal": "NODE_OPTIONS=--max-old-space-size=1500 lerna run build --stream --scope @budibase/account-portal-server --scope @budibase/account-portal-ui",
|
||||
"build:dev": "lerna run --stream prebuild && yarn nx run-many --target=build --output-style=dynamic --watch --preserveWatchOutput",
|
||||
"check:types": "lerna run --concurrency 2 check:types --ignore @budibase/account-portal-server",
|
||||
"check:types": "yarn check:dependencies && lerna run --concurrency 2 check:types",
|
||||
"check:dependencies": "lerna run --concurrency 2 check:dependencies",
|
||||
"build:sdk": "lerna run --stream build:sdk",
|
||||
"deps:circular": "madge packages/server/dist/index.js packages/worker/src/index.ts packages/backend-core/dist/src/index.js packages/cli/src/index.js --circular",
|
||||
"release": "lerna publish from-package --yes --force-publish --no-git-tag-version --no-push --no-git-reset",
|
||||
|
@ -52,15 +53,12 @@
|
|||
"kill-server": "kill-port 4001 4002",
|
||||
"kill-accountportal": "kill-port 3001 4003",
|
||||
"kill-all": "yarn run kill-builder && yarn run kill-server && yarn kill-accountportal",
|
||||
"dev": "yarn run kill-all && lerna run --parallel prebuild && lerna run --stream dev --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server",
|
||||
"dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up --ignore @budibase/account-portal-server && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server",
|
||||
"dev": "yarn run kill-all && lerna run --parallel prebuild && lerna run --stream dev",
|
||||
"dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker",
|
||||
"dev:server": "yarn run kill-server && lerna run --stream dev --scope @budibase/worker --scope @budibase/server",
|
||||
"dev:accountportal": "yarn kill-accountportal && lerna run dev --stream --scope @budibase/account-portal-ui --scope @budibase/account-portal-server",
|
||||
"dev:camunda": "./scripts/deploy-camunda.sh",
|
||||
"dev:all": "yarn run kill-all && lerna run --stream dev",
|
||||
"dev:built": "yarn run kill-all && cd packages/server && yarn dev:stack:up && cd ../../ && lerna run --stream dev:built",
|
||||
"dev:docker": "./scripts/devDocker.sh",
|
||||
"test": "lerna run --concurrency 1 --stream test --stream",
|
||||
"test": "lerna run --concurrency 1 --stream test",
|
||||
"test:containers:kill": "./scripts/killTestcontainers.sh",
|
||||
"lint:eslint": "eslint packages --max-warnings=0",
|
||||
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\" && prettier --write \"examples/**/*.{js,ts,svelte}\"",
|
||||
|
@ -98,9 +96,7 @@
|
|||
},
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"packages/*",
|
||||
"!packages/account-portal",
|
||||
"packages/account-portal/packages/*"
|
||||
"packages/*"
|
||||
]
|
||||
},
|
||||
"resolutions": {
|
||||
|
@ -114,7 +110,7 @@
|
|||
"semver": "7.5.3",
|
||||
"http-cache-semantics": "4.1.1",
|
||||
"msgpackr": "1.10.1",
|
||||
"axios": "1.6.3",
|
||||
"axios": "1.7.7",
|
||||
"xml2js": "0.6.2",
|
||||
"unset-value": "2.0.1",
|
||||
"passport": "0.6.0",
|
||||
|
@ -124,6 +120,5 @@
|
|||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0 <21.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 9bef5d1656b4f3c991447ded6d65b0eba393a140
|
|
@ -1,6 +1,4 @@
|
|||
*
|
||||
!dist/**/*
|
||||
dist/tsconfig.build.tsbuildinfo
|
||||
!package.json
|
||||
!src/**
|
||||
!tests/**
|
||||
!package.json
|
|
@ -9,6 +9,13 @@
|
|||
"./tests": "./dist/tests/index.js",
|
||||
"./*": "./dist/*.js"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"tests": [
|
||||
"dist/tests/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"author": "Budibase",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
|
@ -17,6 +24,7 @@
|
|||
"build": "tsc -p tsconfig.build.json --paths null && node ./scripts/build.js",
|
||||
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
||||
"check:types": "tsc -p tsconfig.json --noEmit --paths null --target es2020",
|
||||
"check:dependencies": "node ../../scripts/depcheck.js",
|
||||
"test": "bash scripts/test.sh",
|
||||
"test:watch": "jest --watchAll"
|
||||
},
|
||||
|
@ -25,17 +33,21 @@
|
|||
"@budibase/pouchdb-replication-stream": "1.2.11",
|
||||
"@budibase/shared-core": "0.0.0",
|
||||
"@budibase/types": "0.0.0",
|
||||
"@techpass/passport-openidconnect": "0.3.3",
|
||||
"aws-cloudfront-sign": "3.0.2",
|
||||
"aws-sdk": "2.1030.0",
|
||||
"aws-sdk": "2.1692.0",
|
||||
"bcrypt": "5.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bull": "4.10.1",
|
||||
"correlation-id": "4.0.0",
|
||||
"dd-trace": "5.2.0",
|
||||
"dd-trace": "5.26.0",
|
||||
"dotenv": "16.0.1",
|
||||
"google-auth-library": "^8.0.1",
|
||||
"google-spreadsheet": "npm:@budibase/google-spreadsheet@4.1.5",
|
||||
"ioredis": "5.3.2",
|
||||
"joi": "17.6.0",
|
||||
"jsonwebtoken": "9.0.2",
|
||||
"knex": "2.4.2",
|
||||
"koa-passport": "^6.0.0",
|
||||
"koa-pino-logger": "4.0.0",
|
||||
"lodash": "4.17.21",
|
||||
|
@ -46,17 +58,17 @@
|
|||
"pino": "8.11.0",
|
||||
"pino-http": "8.3.3",
|
||||
"posthog-node": "4.0.1",
|
||||
"pouchdb": "7.3.0",
|
||||
"pouchdb-find": "7.2.2",
|
||||
"pouchdb": "9.0.0",
|
||||
"pouchdb-find": "9.0.0",
|
||||
"redlock": "4.2.0",
|
||||
"rotating-file-stream": "3.1.0",
|
||||
"sanitize-s3-objectkey": "0.0.1",
|
||||
"semver": "^7.5.4",
|
||||
"tar-fs": "2.1.1",
|
||||
"uuid": "^8.3.2",
|
||||
"knex": "2.4.2"
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/types": "^29.6.3",
|
||||
"@shopify/jest-koa-mocks": "5.1.1",
|
||||
"@swc/core": "1.3.71",
|
||||
"@swc/jest": "0.2.27",
|
||||
|
@ -64,8 +76,9 @@
|
|||
"@types/cookies": "0.7.8",
|
||||
"@types/jest": "29.5.5",
|
||||
"@types/lodash": "4.14.200",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/node-fetch": "2.6.4",
|
||||
"@types/pouchdb": "6.4.0",
|
||||
"@types/pouchdb": "6.4.2",
|
||||
"@types/redlock": "4.0.7",
|
||||
"@types/semver": "7.3.7",
|
||||
"@types/tar-fs": "2.0.1",
|
||||
|
@ -74,6 +87,7 @@
|
|||
"ioredis-mock": "8.9.0",
|
||||
"jest": "29.7.0",
|
||||
"jest-serial-runner": "1.2.1",
|
||||
"nock": "^13.5.6",
|
||||
"pino-pretty": "10.0.0",
|
||||
"pouchdb-adapter-memory": "7.2.2",
|
||||
"testcontainers": "^10.7.2",
|
||||
|
|
|
@ -190,7 +190,7 @@ export class DatabaseImpl implements Database {
|
|||
}
|
||||
}
|
||||
|
||||
private async performCall<T>(call: DBCallback<T>): Promise<any> {
|
||||
private async performCall<T>(call: DBCallback<T>): Promise<T> {
|
||||
const db = this.getDb()
|
||||
const fnc = await call(db)
|
||||
try {
|
||||
|
@ -467,7 +467,7 @@ export class DatabaseImpl implements Database {
|
|||
} catch (err: any) {
|
||||
// didn't exist, don't worry
|
||||
if (err.statusCode === 404) {
|
||||
return
|
||||
return { ok: true }
|
||||
} else {
|
||||
throw new CouchDBError(err.message, err)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export class DDInstrumentedDatabase implements Database {
|
|||
|
||||
exists(docId?: string): Promise<boolean> {
|
||||
return tracer.trace("db.exists", span => {
|
||||
span?.addTags({ db_name: this.name, doc_id: docId })
|
||||
span.addTags({ db_name: this.name, doc_id: docId })
|
||||
if (docId) {
|
||||
return this.db.exists(docId)
|
||||
}
|
||||
|
@ -37,15 +37,17 @@ export class DDInstrumentedDatabase implements Database {
|
|||
|
||||
get<T extends Document>(id?: string | undefined): Promise<T> {
|
||||
return tracer.trace("db.get", span => {
|
||||
span?.addTags({ db_name: this.name, doc_id: id })
|
||||
span.addTags({ db_name: this.name, doc_id: id })
|
||||
return this.db.get(id)
|
||||
})
|
||||
}
|
||||
|
||||
tryGet<T extends Document>(id?: string | undefined): Promise<T | undefined> {
|
||||
return tracer.trace("db.tryGet", span => {
|
||||
span?.addTags({ db_name: this.name, doc_id: id })
|
||||
return this.db.tryGet(id)
|
||||
return tracer.trace("db.tryGet", async span => {
|
||||
span.addTags({ db_name: this.name, doc_id: id })
|
||||
const doc = await this.db.tryGet<T>(id)
|
||||
span.addTags({ doc_found: doc !== undefined })
|
||||
return doc
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -53,13 +55,15 @@ export class DDInstrumentedDatabase implements Database {
|
|||
ids: string[],
|
||||
opts?: { allowMissing?: boolean | undefined } | undefined
|
||||
): Promise<T[]> {
|
||||
return tracer.trace("db.getMultiple", span => {
|
||||
span?.addTags({
|
||||
return tracer.trace("db.getMultiple", async span => {
|
||||
span.addTags({
|
||||
db_name: this.name,
|
||||
num_docs: ids.length,
|
||||
allow_missing: opts?.allowMissing,
|
||||
})
|
||||
return this.db.getMultiple(ids, opts)
|
||||
const docs = await this.db.getMultiple<T>(ids, opts)
|
||||
span.addTags({ num_docs_found: docs.length })
|
||||
return docs
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -69,12 +73,14 @@ export class DDInstrumentedDatabase implements Database {
|
|||
idOrDoc: string | Document,
|
||||
rev?: string
|
||||
): Promise<DocumentDestroyResponse> {
|
||||
return tracer.trace("db.remove", span => {
|
||||
span?.addTags({ db_name: this.name, doc_id: idOrDoc })
|
||||
return tracer.trace("db.remove", async span => {
|
||||
span.addTags({ db_name: this.name, doc_id: idOrDoc, rev })
|
||||
const isDocument = typeof idOrDoc === "object"
|
||||
const id = isDocument ? idOrDoc._id! : idOrDoc
|
||||
rev = isDocument ? idOrDoc._rev : rev
|
||||
return this.db.remove(id, rev)
|
||||
const resp = await this.db.remove(id, rev)
|
||||
span.addTags({ ok: resp.ok })
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -83,7 +89,11 @@ export class DDInstrumentedDatabase implements Database {
|
|||
opts?: { silenceErrors?: boolean }
|
||||
): Promise<void> {
|
||||
return tracer.trace("db.bulkRemove", span => {
|
||||
span?.addTags({ db_name: this.name, num_docs: documents.length })
|
||||
span.addTags({
|
||||
db_name: this.name,
|
||||
num_docs: documents.length,
|
||||
silence_errors: opts?.silenceErrors,
|
||||
})
|
||||
return this.db.bulkRemove(documents, opts)
|
||||
})
|
||||
}
|
||||
|
@ -92,15 +102,21 @@ export class DDInstrumentedDatabase implements Database {
|
|||
document: AnyDocument,
|
||||
opts?: DatabasePutOpts | undefined
|
||||
): Promise<DocumentInsertResponse> {
|
||||
return tracer.trace("db.put", span => {
|
||||
span?.addTags({ db_name: this.name, doc_id: document._id })
|
||||
return this.db.put(document, opts)
|
||||
return tracer.trace("db.put", async span => {
|
||||
span.addTags({
|
||||
db_name: this.name,
|
||||
doc_id: document._id,
|
||||
force: opts?.force,
|
||||
})
|
||||
const resp = await this.db.put(document, opts)
|
||||
span.addTags({ ok: resp.ok })
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
bulkDocs(documents: AnyDocument[]): Promise<DocumentBulkResponse[]> {
|
||||
return tracer.trace("db.bulkDocs", span => {
|
||||
span?.addTags({ db_name: this.name, num_docs: documents.length })
|
||||
span.addTags({ db_name: this.name, num_docs: documents.length })
|
||||
return this.db.bulkDocs(documents)
|
||||
})
|
||||
}
|
||||
|
@ -108,9 +124,15 @@ export class DDInstrumentedDatabase implements Database {
|
|||
allDocs<T extends Document | RowValue>(
|
||||
params: DatabaseQueryOpts
|
||||
): Promise<AllDocsResponse<T>> {
|
||||
return tracer.trace("db.allDocs", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
return this.db.allDocs(params)
|
||||
return tracer.trace("db.allDocs", async span => {
|
||||
span.addTags({ db_name: this.name, ...params })
|
||||
const resp = await this.db.allDocs<T>(params)
|
||||
span.addTags({
|
||||
total_rows: resp.total_rows,
|
||||
rows_length: resp.rows.length,
|
||||
offset: resp.offset,
|
||||
})
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -118,57 +140,75 @@ export class DDInstrumentedDatabase implements Database {
|
|||
viewName: string,
|
||||
params: DatabaseQueryOpts
|
||||
): Promise<AllDocsResponse<T>> {
|
||||
return tracer.trace("db.query", span => {
|
||||
span?.addTags({ db_name: this.name, view_name: viewName })
|
||||
return this.db.query(viewName, params)
|
||||
return tracer.trace("db.query", async span => {
|
||||
span.addTags({ db_name: this.name, view_name: viewName, ...params })
|
||||
const resp = await this.db.query<T>(viewName, params)
|
||||
span.addTags({
|
||||
total_rows: resp.total_rows,
|
||||
rows_length: resp.rows.length,
|
||||
offset: resp.offset,
|
||||
})
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
destroy(): Promise<void | OkResponse> {
|
||||
return tracer.trace("db.destroy", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
return this.db.destroy()
|
||||
destroy(): Promise<OkResponse> {
|
||||
return tracer.trace("db.destroy", async span => {
|
||||
span.addTags({ db_name: this.name })
|
||||
const resp = await this.db.destroy()
|
||||
span.addTags({ ok: resp.ok })
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
compact(): Promise<void | OkResponse> {
|
||||
return tracer.trace("db.compact", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
return this.db.compact()
|
||||
compact(): Promise<OkResponse> {
|
||||
return tracer.trace("db.compact", async span => {
|
||||
span.addTags({ db_name: this.name })
|
||||
const resp = await this.db.compact()
|
||||
span.addTags({ ok: resp.ok })
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
dump(stream: Writable, opts?: DatabaseDumpOpts | undefined): Promise<any> {
|
||||
return tracer.trace("db.dump", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({
|
||||
db_name: this.name,
|
||||
batch_limit: opts?.batch_limit,
|
||||
batch_size: opts?.batch_size,
|
||||
style: opts?.style,
|
||||
timeout: opts?.timeout,
|
||||
num_doc_ids: opts?.doc_ids?.length,
|
||||
view: opts?.view,
|
||||
})
|
||||
return this.db.dump(stream, opts)
|
||||
})
|
||||
}
|
||||
|
||||
load(...args: any[]): Promise<any> {
|
||||
return tracer.trace("db.load", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({ db_name: this.name, num_args: args.length })
|
||||
return this.db.load(...args)
|
||||
})
|
||||
}
|
||||
|
||||
createIndex(...args: any[]): Promise<any> {
|
||||
return tracer.trace("db.createIndex", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({ db_name: this.name, num_args: args.length })
|
||||
return this.db.createIndex(...args)
|
||||
})
|
||||
}
|
||||
|
||||
deleteIndex(...args: any[]): Promise<any> {
|
||||
return tracer.trace("db.deleteIndex", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({ db_name: this.name, num_args: args.length })
|
||||
return this.db.deleteIndex(...args)
|
||||
})
|
||||
}
|
||||
|
||||
getIndexes(...args: any[]): Promise<any> {
|
||||
return tracer.trace("db.getIndexes", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({ db_name: this.name, num_args: args.length })
|
||||
return this.db.getIndexes(...args)
|
||||
})
|
||||
}
|
||||
|
@ -177,22 +217,27 @@ export class DDInstrumentedDatabase implements Database {
|
|||
sql: string,
|
||||
parameters?: SqlQueryBinding
|
||||
): Promise<T[]> {
|
||||
return tracer.trace("db.sql", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
return this.db.sql(sql, parameters)
|
||||
return tracer.trace("db.sql", async span => {
|
||||
span.addTags({ db_name: this.name, num_bindings: parameters?.length })
|
||||
const resp = await this.db.sql<T>(sql, parameters)
|
||||
span.addTags({ num_rows: resp.length })
|
||||
return resp
|
||||
})
|
||||
}
|
||||
|
||||
sqlPurgeDocument(docIds: string[] | string): Promise<void> {
|
||||
return tracer.trace("db.sqlPurgeDocument", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({
|
||||
db_name: this.name,
|
||||
num_docs: Array.isArray(docIds) ? docIds.length : 1,
|
||||
})
|
||||
return this.db.sqlPurgeDocument(docIds)
|
||||
})
|
||||
}
|
||||
|
||||
sqlDiskCleanup(): Promise<void> {
|
||||
return tracer.trace("db.sqlDiskCleanup", span => {
|
||||
span?.addTags({ db_name: this.name })
|
||||
span.addTags({ db_name: this.name })
|
||||
return this.db.sqlDiskCleanup()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -19,6 +19,12 @@ function isDev() {
|
|||
return process.env.NODE_ENV !== "production"
|
||||
}
|
||||
|
||||
function parseIntSafe(number?: string) {
|
||||
if (number) {
|
||||
return parseInt(number)
|
||||
}
|
||||
}
|
||||
|
||||
let LOADED = false
|
||||
if (!LOADED && isDev() && !isTest()) {
|
||||
require("dotenv").config()
|
||||
|
@ -231,6 +237,7 @@ const environment = {
|
|||
MIN_VERSION_WITHOUT_POWER_ROLE:
|
||||
process.env.MIN_VERSION_WITHOUT_POWER_ROLE || "3.0.0",
|
||||
DISABLE_CONTENT_SECURITY_POLICY: process.env.DISABLE_CONTENT_SECURITY_POLICY,
|
||||
BSON_BUFFER_SIZE: parseIntSafe(process.env.BSON_BUFFER_SIZE),
|
||||
}
|
||||
|
||||
export function setEnv(newEnvVars: Partial<typeof environment>): () => void {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { makePropSafe as safe } from "@budibase/string-templates"
|
||||
import { API } from "../api/index.js"
|
||||
import { UILogicalOperator } from "@budibase/types"
|
||||
import { OnEmptyFilter } from "@budibase/frontend-core/src/constants.js"
|
||||
|
||||
// Map of data types to component types for search fields inside blocks
|
||||
const schemaComponentMap = {
|
||||
|
@ -60,7 +62,11 @@ export const enrichSearchColumns = async (searchColumns, schema) => {
|
|||
* @param formId the ID of the form containing the search fields
|
||||
*/
|
||||
export const enrichFilter = (filter, columns, formId) => {
|
||||
let enrichedFilter = [...(filter || [])]
|
||||
if (!columns?.length) {
|
||||
return filter
|
||||
}
|
||||
|
||||
let newFilters = []
|
||||
columns?.forEach(column => {
|
||||
const safePath = column.name.split(".").map(safe).join(".")
|
||||
const stringType = column.type === "string" || column.type === "formula"
|
||||
|
@ -69,7 +75,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
|||
|
||||
// For dates, use a range of the entire day selected
|
||||
if (dateType) {
|
||||
enrichedFilter.push({
|
||||
newFilters.push({
|
||||
field: column.name,
|
||||
type: column.type,
|
||||
operator: "rangeLow",
|
||||
|
@ -79,7 +85,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
|||
const format = "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
||||
let hbs = `{{ date (add (date ${binding} "x") 86399999) "${format}" }}`
|
||||
hbs = `{{#if ${binding} }}${hbs}{{/if}}`
|
||||
enrichedFilter.push({
|
||||
newFilters.push({
|
||||
field: column.name,
|
||||
type: column.type,
|
||||
operator: "rangeHigh",
|
||||
|
@ -90,7 +96,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
|||
|
||||
// For other fields, do an exact match
|
||||
else {
|
||||
enrichedFilter.push({
|
||||
newFilters.push({
|
||||
field: column.name,
|
||||
type: column.type,
|
||||
operator: stringType ? "string" : "equal",
|
||||
|
@ -99,5 +105,16 @@ export const enrichFilter = (filter, columns, formId) => {
|
|||
})
|
||||
}
|
||||
})
|
||||
return enrichedFilter
|
||||
|
||||
return {
|
||||
logicalOperator: UILogicalOperator.ALL,
|
||||
onEmptyFilter: OnEmptyFilter.RETURN_ALL,
|
||||
groups: [
|
||||
...(filter?.groups || []),
|
||||
{
|
||||
logicalOperator: UILogicalOperator.ALL,
|
||||
filters: newFilters,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bfeece324a03a3a5f25137bf3f8c66d5ed6103d8
|
||||
Subproject commit 25dd40ee12b048307b558ebcedb36548d6e042cd
|
|
@ -13,6 +13,7 @@
|
|||
"build": "node ./scripts/build.js",
|
||||
"postbuild": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client && copyfiles -f ../../yarn.lock ./dist/",
|
||||
"check:types": "tsc -p tsconfig.json --noEmit --paths null --target es2020",
|
||||
"check:dependencies": "node ../../scripts/depcheck.js",
|
||||
"build:isolated-vm-lib:snippets": "esbuild --minify --bundle src/jsRunner/bundles/snippets.ts --outfile=src/jsRunner/bundles/snippets.ivm.bundle.js --platform=node --format=iife --global-name=snippets",
|
||||
"build:isolated-vm-lib:string-templates": "esbuild --minify --bundle src/jsRunner/bundles/index-helpers.ts --outfile=src/jsRunner/bundles/index-helpers.ivm.bundle.js --platform=node --format=iife --external:handlebars --global-name=helpers",
|
||||
"build:isolated-vm-lib:bson": "esbuild --minify --bundle src/jsRunner/bundles/bsonPackage.ts --outfile=src/jsRunner/bundles/bson.ivm.bundle.js --platform=node --format=iife --global-name=bson",
|
||||
|
@ -49,9 +50,11 @@
|
|||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@apidevtools/swagger-parser": "10.0.3",
|
||||
"@azure/msal-node": "^2.5.1",
|
||||
"@budibase/backend-core": "0.0.0",
|
||||
"@budibase/client": "0.0.0",
|
||||
"@budibase/frontend-core": "0.0.0",
|
||||
"@budibase/nano": "10.1.5",
|
||||
"@budibase/pro": "0.0.0",
|
||||
"@budibase/shared-core": "0.0.0",
|
||||
"@budibase/string-templates": "0.0.0",
|
||||
|
@ -60,15 +63,17 @@
|
|||
"@bull-board/koa": "5.10.2",
|
||||
"@elastic/elasticsearch": "7.10.0",
|
||||
"@google-cloud/firestore": "7.8.0",
|
||||
"@koa/router": "8.0.8",
|
||||
"@koa/cors": "5.0.0",
|
||||
"@koa/router": "13.1.0",
|
||||
"@socket.io/redis-adapter": "^8.2.1",
|
||||
"@types/xml2js": "^0.4.14",
|
||||
"airtable": "0.12.2",
|
||||
"arangojs": "7.2.0",
|
||||
"archiver": "7.0.1",
|
||||
"aws-sdk": "2.1030.0",
|
||||
"aws-sdk": "2.1692.0",
|
||||
"bcrypt": "5.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bson": "^6.9.0",
|
||||
"buffer": "6.0.3",
|
||||
"bull": "4.10.1",
|
||||
"chokidar": "3.5.3",
|
||||
|
@ -76,17 +81,20 @@
|
|||
"cookies": "0.8.0",
|
||||
"csvtojson": "2.0.10",
|
||||
"curlconverter": "3.21.0",
|
||||
"dd-trace": "5.2.0",
|
||||
"dayjs": "^1.10.8",
|
||||
"dd-trace": "5.26.0",
|
||||
"dotenv": "8.2.0",
|
||||
"form-data": "4.0.0",
|
||||
"global-agent": "3.0.0",
|
||||
"google-auth-library": "^8.0.1",
|
||||
"google-spreadsheet": "npm:@budibase/google-spreadsheet@4.1.5",
|
||||
"ioredis": "5.3.2",
|
||||
"isolated-vm": "^4.7.2",
|
||||
"jimp": "0.22.12",
|
||||
"jimp": "1.1.4",
|
||||
"joi": "17.6.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"jsonschema": "1.4.0",
|
||||
"jsonwebtoken": "9.0.2",
|
||||
"knex": "2.4.2",
|
||||
"koa": "2.13.4",
|
||||
"koa-body": "4.2.0",
|
||||
|
@ -97,7 +105,7 @@
|
|||
"lodash": "4.17.21",
|
||||
"memorystream": "0.3.1",
|
||||
"mongodb": "6.7.0",
|
||||
"mssql": "10.0.1",
|
||||
"mssql": "11.0.1",
|
||||
"mysql2": "3.9.8",
|
||||
"node-fetch": "2.6.7",
|
||||
"object-sizeof": "2.6.1",
|
||||
|
@ -105,24 +113,28 @@
|
|||
"openapi-types": "9.3.1",
|
||||
"oracledb": "6.5.1",
|
||||
"pg": "8.10.0",
|
||||
"pouchdb": "7.3.0",
|
||||
"pouchdb": "9.0.0",
|
||||
"pouchdb-all-dbs": "1.1.1",
|
||||
"pouchdb-find": "7.2.2",
|
||||
"pouchdb-find": "9.0.0",
|
||||
"redis": "4",
|
||||
"semver": "^7.5.4",
|
||||
"serialize-error": "^7.0.1",
|
||||
"server-destroy": "1.0.1",
|
||||
"snowflake-promise": "^4.5.0",
|
||||
"socket.io": "4.7.5",
|
||||
"snowflake-sdk": "^1.15.0",
|
||||
"socket.io": "4.8.1",
|
||||
"svelte": "^4.2.10",
|
||||
"tar": "6.2.1",
|
||||
"tmp": "0.2.3",
|
||||
"to-json-schema": "0.2.5",
|
||||
"uuid": "^8.3.2",
|
||||
"validate.js": "0.13.1",
|
||||
"worker-farm": "1.7.0",
|
||||
"xml2js": "0.5.0"
|
||||
"xml2js": "0.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.22.5",
|
||||
"@babel/preset-env": "7.16.11",
|
||||
"@jest/types": "^29.6.3",
|
||||
"@swc/core": "1.3.71",
|
||||
"@swc/jest": "0.2.27",
|
||||
"@types/archiver": "6.0.2",
|
||||
|
@ -130,19 +142,24 @@
|
|||
"@types/jest": "29.5.5",
|
||||
"@types/koa": "2.13.4",
|
||||
"@types/koa-send": "^4.1.6",
|
||||
"@types/koa__router": "8.0.8",
|
||||
"@types/koa__cors": "5.0.0",
|
||||
"@types/koa__router": "12.0.4",
|
||||
"@types/lodash": "4.14.200",
|
||||
"@types/mssql": "9.1.4",
|
||||
"@types/mssql": "9.1.5",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/node-fetch": "2.6.4",
|
||||
"@types/oracledb": "6.5.1",
|
||||
"@types/pg": "8.6.6",
|
||||
"@types/pouchdb": "6.4.2",
|
||||
"@types/server-destroy": "1.0.1",
|
||||
"@types/supertest": "2.0.14",
|
||||
"@types/tar": "6.1.5",
|
||||
"@types/tmp": "0.2.6",
|
||||
"@types/uuid": "8.3.4",
|
||||
"chance": "^1.1.12",
|
||||
"copyfiles": "2.4.1",
|
||||
"docker-compose": "0.23.17",
|
||||
"ioredis-mock": "8.9.0",
|
||||
"jest": "29.7.0",
|
||||
"jest-extended": "^4.0.2",
|
||||
"jest-openapi": "0.14.2",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,6 +23,13 @@ components:
|
|||
description: The ID of the table which this request is targeting.
|
||||
schema:
|
||||
type: string
|
||||
viewId:
|
||||
in: path
|
||||
name: viewId
|
||||
required: true
|
||||
description: The ID of the view which this request is targeting.
|
||||
schema:
|
||||
type: string
|
||||
rowId:
|
||||
in: path
|
||||
name: rowId
|
||||
|
@ -36,7 +43,7 @@ components:
|
|||
required: true
|
||||
description: The ID of the app which this request is targeting.
|
||||
schema:
|
||||
default: "{{ appId }}"
|
||||
default: "{{appId}}"
|
||||
type: string
|
||||
appIdUrl:
|
||||
in: path
|
||||
|
@ -44,7 +51,7 @@ components:
|
|||
required: true
|
||||
description: The ID of the app which this request is targeting.
|
||||
schema:
|
||||
default: "{{ appId }}"
|
||||
default: "{{appId}}"
|
||||
type: string
|
||||
queryId:
|
||||
in: path
|
||||
|
@ -442,6 +449,74 @@ components:
|
|||
# TYPE budibase_quota_limit_automations gauge
|
||||
|
||||
budibase_quota_limit_automations 9007199254740991
|
||||
view:
|
||||
value:
|
||||
data:
|
||||
name: peopleView
|
||||
tableId: ta_896a325f7e8147d2a2cda93c5d236511
|
||||
schema:
|
||||
name:
|
||||
visible: true
|
||||
readonly: false
|
||||
order: 1
|
||||
width: 300
|
||||
age:
|
||||
visible: true
|
||||
readonly: true
|
||||
order: 2
|
||||
width: 200
|
||||
salary:
|
||||
visible: false
|
||||
readonly: false
|
||||
query:
|
||||
logicalOperator: all
|
||||
onEmptyFilter: none
|
||||
groups:
|
||||
- logicalOperator: any
|
||||
filters:
|
||||
- operator: string
|
||||
field: name
|
||||
value: John
|
||||
- operator: range
|
||||
field: age
|
||||
value:
|
||||
low: 18
|
||||
high: 100
|
||||
primaryDisplay: name
|
||||
views:
|
||||
value:
|
||||
data:
|
||||
- name: peopleView
|
||||
tableId: ta_896a325f7e8147d2a2cda93c5d236511
|
||||
schema:
|
||||
name:
|
||||
visible: true
|
||||
readonly: false
|
||||
order: 1
|
||||
width: 300
|
||||
age:
|
||||
visible: true
|
||||
readonly: true
|
||||
order: 2
|
||||
width: 200
|
||||
salary:
|
||||
visible: false
|
||||
readonly: false
|
||||
query:
|
||||
logicalOperator: all
|
||||
onEmptyFilter: none
|
||||
groups:
|
||||
- logicalOperator: any
|
||||
filters:
|
||||
- operator: string
|
||||
field: name
|
||||
value: John
|
||||
- operator: range
|
||||
field: age
|
||||
value:
|
||||
low: 18
|
||||
high: 100
|
||||
primaryDisplay: name
|
||||
securitySchemes:
|
||||
ApiKeyAuth:
|
||||
type: apiKey
|
||||
|
@ -761,7 +836,6 @@ components:
|
|||
enum:
|
||||
- static
|
||||
- dynamic
|
||||
- ai
|
||||
description: Defines whether this is a static or dynamic formula.
|
||||
- type: object
|
||||
properties:
|
||||
|
@ -931,7 +1005,6 @@ components:
|
|||
enum:
|
||||
- static
|
||||
- dynamic
|
||||
- ai
|
||||
description: Defines whether this is a static or dynamic formula.
|
||||
- type: object
|
||||
properties:
|
||||
|
@ -1108,7 +1181,6 @@ components:
|
|||
enum:
|
||||
- static
|
||||
- dynamic
|
||||
- ai
|
||||
description: Defines whether this is a static or dynamic formula.
|
||||
- type: object
|
||||
properties:
|
||||
|
@ -1704,6 +1776,644 @@ components:
|
|||
- userIds
|
||||
required:
|
||||
- data
|
||||
view:
|
||||
description: The view to be created/updated.
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- schema
|
||||
- tableId
|
||||
properties:
|
||||
name:
|
||||
description: The name of the view.
|
||||
type: string
|
||||
tableId:
|
||||
description: The ID of the table this view is based on.
|
||||
type: string
|
||||
type:
|
||||
description: The type of view - standard (empty value) or calculation.
|
||||
type: string
|
||||
enum:
|
||||
- calculation
|
||||
primaryDisplay:
|
||||
type: string
|
||||
description: A column used to display rows from this view - usually used when
|
||||
rendered in tables.
|
||||
query:
|
||||
description: Search parameters for view
|
||||
type: object
|
||||
required: []
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
onEmptyFilter:
|
||||
description: If no filters match, should the view return all rows, or no rows.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- none
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
sort:
|
||||
type: object
|
||||
required:
|
||||
- field
|
||||
properties:
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table/view schema to sort on.
|
||||
order:
|
||||
type: string
|
||||
description: The order in which to sort.
|
||||
enum:
|
||||
- ascending
|
||||
- descending
|
||||
type:
|
||||
type: string
|
||||
description: The type of sort to perform (by number, or by alphabetically).
|
||||
enum:
|
||||
- string
|
||||
- number
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- type: object
|
||||
properties:
|
||||
visible:
|
||||
type: boolean
|
||||
description: Defines whether the column is visible or not - rows
|
||||
retrieved/updated through this view will not be able to
|
||||
access it.
|
||||
readonly:
|
||||
type: boolean
|
||||
description: "When used in combination with 'visible: true' the column will be
|
||||
visible in row responses but cannot be updated."
|
||||
order:
|
||||
type: integer
|
||||
description: A number defining where the column shows up in tables, lowest being
|
||||
first.
|
||||
width:
|
||||
type: integer
|
||||
description: A width for the column, defined in pixels - this affects rendering
|
||||
in tables.
|
||||
column:
|
||||
type: array
|
||||
description: If this is a relationship column, we can set the columns we wish to
|
||||
include
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
readonly:
|
||||
type: boolean
|
||||
- type: object
|
||||
properties:
|
||||
calculationType:
|
||||
type: string
|
||||
description: This column should be built from a calculation, specifying a type
|
||||
and field. It is important to note when a calculation is
|
||||
configured all non-calculation columns will be used for
|
||||
grouping.
|
||||
enum:
|
||||
- sum
|
||||
- avg
|
||||
- count
|
||||
- min
|
||||
- max
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table to perform the calculation on.
|
||||
distinct:
|
||||
type: boolean
|
||||
description: Can be used in tandem with the count calculation type, to count
|
||||
unique entries.
|
||||
viewOutput:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
description: The view to be created/updated.
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- schema
|
||||
- tableId
|
||||
- id
|
||||
properties:
|
||||
name:
|
||||
description: The name of the view.
|
||||
type: string
|
||||
tableId:
|
||||
description: The ID of the table this view is based on.
|
||||
type: string
|
||||
type:
|
||||
description: The type of view - standard (empty value) or calculation.
|
||||
type: string
|
||||
enum:
|
||||
- calculation
|
||||
primaryDisplay:
|
||||
type: string
|
||||
description: A column used to display rows from this view - usually used when
|
||||
rendered in tables.
|
||||
query:
|
||||
description: Search parameters for view
|
||||
type: object
|
||||
required: []
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
onEmptyFilter:
|
||||
description: If no filters match, should the view return all rows, or no rows.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- none
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
sort:
|
||||
type: object
|
||||
required:
|
||||
- field
|
||||
properties:
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table/view schema to sort on.
|
||||
order:
|
||||
type: string
|
||||
description: The order in which to sort.
|
||||
enum:
|
||||
- ascending
|
||||
- descending
|
||||
type:
|
||||
type: string
|
||||
description: The type of sort to perform (by number, or by alphabetically).
|
||||
enum:
|
||||
- string
|
||||
- number
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- type: object
|
||||
properties:
|
||||
visible:
|
||||
type: boolean
|
||||
description: Defines whether the column is visible or not - rows
|
||||
retrieved/updated through this view will not be able
|
||||
to access it.
|
||||
readonly:
|
||||
type: boolean
|
||||
description: "When used in combination with 'visible: true' the column will be
|
||||
visible in row responses but cannot be updated."
|
||||
order:
|
||||
type: integer
|
||||
description: A number defining where the column shows up in tables, lowest being
|
||||
first.
|
||||
width:
|
||||
type: integer
|
||||
description: A width for the column, defined in pixels - this affects rendering
|
||||
in tables.
|
||||
column:
|
||||
type: array
|
||||
description: If this is a relationship column, we can set the columns we wish to
|
||||
include
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
readonly:
|
||||
type: boolean
|
||||
- type: object
|
||||
properties:
|
||||
calculationType:
|
||||
type: string
|
||||
description: This column should be built from a calculation, specifying a type
|
||||
and field. It is important to note when a calculation
|
||||
is configured all non-calculation columns will be used
|
||||
for grouping.
|
||||
enum:
|
||||
- sum
|
||||
- avg
|
||||
- count
|
||||
- min
|
||||
- max
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table to perform the calculation on.
|
||||
distinct:
|
||||
type: boolean
|
||||
description: Can be used in tandem with the count calculation type, to count
|
||||
unique entries.
|
||||
id:
|
||||
description: The ID of the view.
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
viewSearch:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
description: The view to be created/updated.
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- schema
|
||||
- tableId
|
||||
- id
|
||||
properties:
|
||||
name:
|
||||
description: The name of the view.
|
||||
type: string
|
||||
tableId:
|
||||
description: The ID of the table this view is based on.
|
||||
type: string
|
||||
type:
|
||||
description: The type of view - standard (empty value) or calculation.
|
||||
type: string
|
||||
enum:
|
||||
- calculation
|
||||
primaryDisplay:
|
||||
type: string
|
||||
description: A column used to display rows from this view - usually used when
|
||||
rendered in tables.
|
||||
query:
|
||||
description: Search parameters for view
|
||||
type: object
|
||||
required: []
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
onEmptyFilter:
|
||||
description: If no filters match, should the view return all rows, or no rows.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- none
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
groups:
|
||||
description: A grouping of filters to be applied.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
logicalOperator:
|
||||
description: When using groups this defines whether all of the filters must
|
||||
match, or only one of them.
|
||||
type: string
|
||||
enum:
|
||||
- all
|
||||
- any
|
||||
filters:
|
||||
description: A list of filters to apply
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
operator:
|
||||
type: string
|
||||
description: The type of search operation which is being performed.
|
||||
enum:
|
||||
- equal
|
||||
- notEqual
|
||||
- empty
|
||||
- notEmpty
|
||||
- fuzzy
|
||||
- string
|
||||
- contains
|
||||
- notContains
|
||||
- containsAny
|
||||
- oneOf
|
||||
- range
|
||||
field:
|
||||
type: string
|
||||
description: The field in the view to perform the search on.
|
||||
value:
|
||||
description: The value to search for - the type will depend on the operator in
|
||||
use.
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
sort:
|
||||
type: object
|
||||
required:
|
||||
- field
|
||||
properties:
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table/view schema to sort on.
|
||||
order:
|
||||
type: string
|
||||
description: The order in which to sort.
|
||||
enum:
|
||||
- ascending
|
||||
- descending
|
||||
type:
|
||||
type: string
|
||||
description: The type of sort to perform (by number, or by alphabetically).
|
||||
enum:
|
||||
- string
|
||||
- number
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- type: object
|
||||
properties:
|
||||
visible:
|
||||
type: boolean
|
||||
description: Defines whether the column is visible or not - rows
|
||||
retrieved/updated through this view will not be able
|
||||
to access it.
|
||||
readonly:
|
||||
type: boolean
|
||||
description: "When used in combination with 'visible: true' the column will be
|
||||
visible in row responses but cannot be updated."
|
||||
order:
|
||||
type: integer
|
||||
description: A number defining where the column shows up in tables, lowest being
|
||||
first.
|
||||
width:
|
||||
type: integer
|
||||
description: A width for the column, defined in pixels - this affects rendering
|
||||
in tables.
|
||||
column:
|
||||
type: array
|
||||
description: If this is a relationship column, we can set the columns we wish to
|
||||
include
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
readonly:
|
||||
type: boolean
|
||||
- type: object
|
||||
properties:
|
||||
calculationType:
|
||||
type: string
|
||||
description: This column should be built from a calculation, specifying a type
|
||||
and field. It is important to note when a
|
||||
calculation is configured all non-calculation
|
||||
columns will be used for grouping.
|
||||
enum:
|
||||
- sum
|
||||
- avg
|
||||
- count
|
||||
- min
|
||||
- max
|
||||
field:
|
||||
type: string
|
||||
description: The field from the table to perform the calculation on.
|
||||
distinct:
|
||||
type: boolean
|
||||
description: Can be used in tandem with the count calculation type, to count
|
||||
unique entries.
|
||||
id:
|
||||
description: The ID of the view.
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
paths:
|
||||
|
@ -2136,6 +2846,32 @@ paths:
|
|||
examples:
|
||||
search:
|
||||
$ref: "#/components/examples/rows"
|
||||
"/views/{viewId}/rows/search":
|
||||
post:
|
||||
operationId: rowViewSearch
|
||||
summary: Search for rows in a view
|
||||
tags:
|
||||
- rows
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/viewId"
|
||||
- $ref: "#/components/parameters/appId"
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/rowSearch"
|
||||
responses:
|
||||
"200":
|
||||
description: The response will contain an array of rows that match the search
|
||||
parameters.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/searchOutput"
|
||||
examples:
|
||||
search:
|
||||
$ref: "#/components/examples/rows"
|
||||
/tables:
|
||||
post:
|
||||
operationId: tableCreate
|
||||
|
@ -2359,4 +3095,123 @@ paths:
|
|||
examples:
|
||||
users:
|
||||
$ref: "#/components/examples/users"
|
||||
/views:
|
||||
post:
|
||||
operationId: viewCreate
|
||||
summary: Create a view
|
||||
description: Create a view, this can be against an internal or external table.
|
||||
tags:
|
||||
- views
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/appId"
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/view"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
responses:
|
||||
"200":
|
||||
description: Returns the created view, including the ID which has been generated
|
||||
for it.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/viewOutput"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
"/views/{viewId}":
|
||||
put:
|
||||
operationId: viewUpdate
|
||||
summary: Update a view
|
||||
description: Update a view, this can be against an internal or external table.
|
||||
tags:
|
||||
- views
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/viewId"
|
||||
- $ref: "#/components/parameters/appId"
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/view"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
responses:
|
||||
"200":
|
||||
description: Returns the updated view.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/viewOutput"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
delete:
|
||||
operationId: viewDestroy
|
||||
summary: Delete a view
|
||||
description: Delete a view, this can be against an internal or external table.
|
||||
tags:
|
||||
- views
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/viewId"
|
||||
- $ref: "#/components/parameters/appId"
|
||||
responses:
|
||||
"200":
|
||||
description: Returns the deleted view.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/viewOutput"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
get:
|
||||
operationId: viewGetById
|
||||
summary: Retrieve a view
|
||||
description: Lookup a view, this could be internal or external.
|
||||
tags:
|
||||
- views
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/viewId"
|
||||
- $ref: "#/components/parameters/appId"
|
||||
responses:
|
||||
"200":
|
||||
description: Returns the retrieved view.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/viewOutput"
|
||||
examples:
|
||||
view:
|
||||
$ref: "#/components/examples/view"
|
||||
/views/search:
|
||||
post:
|
||||
operationId: viewSearch
|
||||
summary: Search for views
|
||||
description: Based on view properties (currently only name) search for views.
|
||||
tags:
|
||||
- views
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/appId"
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/nameSearch"
|
||||
responses:
|
||||
"200":
|
||||
description: Returns the found views, based on the search parameters.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/viewSearch"
|
||||
examples:
|
||||
views:
|
||||
$ref: "#/components/examples/views"
|
||||
tags: []
|
||||
|
|
|
@ -8,6 +8,16 @@ export const tableId = {
|
|||
},
|
||||
}
|
||||
|
||||
export const viewId = {
|
||||
in: "path",
|
||||
name: "viewId",
|
||||
required: true,
|
||||
description: "The ID of the view which this request is targeting.",
|
||||
schema: {
|
||||
type: "string",
|
||||
},
|
||||
}
|
||||
|
||||
export const rowId = {
|
||||
in: "path",
|
||||
name: "rowId",
|
||||
|
|
|
@ -6,6 +6,7 @@ import user from "./user"
|
|||
import metrics from "./metrics"
|
||||
import misc from "./misc"
|
||||
import roles from "./roles"
|
||||
import view from "./view"
|
||||
|
||||
export const examples = {
|
||||
...application.getExamples(),
|
||||
|
@ -16,6 +17,7 @@ export const examples = {
|
|||
...misc.getExamples(),
|
||||
...metrics.getExamples(),
|
||||
...roles.getExamples(),
|
||||
...view.getExamples(),
|
||||
}
|
||||
|
||||
export const schemas = {
|
||||
|
@ -26,4 +28,5 @@ export const schemas = {
|
|||
...user.getSchemas(),
|
||||
...misc.getSchemas(),
|
||||
...roles.getSchemas(),
|
||||
...view.getSchemas(),
|
||||
}
|
||||
|
|
|
@ -1,99 +1,101 @@
|
|||
import { object } from "./utils"
|
||||
import Resource from "./utils/Resource"
|
||||
|
||||
export const searchSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
allOr: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used.",
|
||||
},
|
||||
string: {
|
||||
type: "object",
|
||||
example: {
|
||||
columnName1: "value",
|
||||
columnName2: "value",
|
||||
},
|
||||
description:
|
||||
"A map of field name to the string to search for, this will look for rows that have a value starting with the string value.",
|
||||
additionalProperties: {
|
||||
type: "string",
|
||||
description: "The value to search for in the column.",
|
||||
},
|
||||
},
|
||||
fuzzy: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for a sub-string within a string column, e.g. searching for 'dib' will match 'Budibase'.",
|
||||
},
|
||||
range: {
|
||||
type: "object",
|
||||
description:
|
||||
'Searches within a range, the format of this must be in the format of an object with a "low" and "high" property.',
|
||||
example: {
|
||||
columnName1: {
|
||||
low: 10,
|
||||
high: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
equal: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows that have a column value that is exactly the value set.",
|
||||
},
|
||||
notEqual: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for any row which does not contain the specified column value.",
|
||||
},
|
||||
empty: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.",
|
||||
example: {
|
||||
columnName1: "",
|
||||
},
|
||||
},
|
||||
notEmpty: {
|
||||
type: "object",
|
||||
description: "Searches for rows which have the specified column.",
|
||||
},
|
||||
oneOf: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2].",
|
||||
},
|
||||
contains: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for a value, or set of values in array column types (such as a multi-select). If an array of search options is provided then it must match all.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
notContains: {
|
||||
type: "object",
|
||||
description:
|
||||
"The logical inverse of contains. Only works on array column types. If an array of values is passed, the row must not match any of them to be returned in the response.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
containsAny: {
|
||||
type: "object",
|
||||
description:
|
||||
"As with the contains search, only works on array column types and searches for any of the provided values when given an array.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default new Resource().setSchemas({
|
||||
rowSearch: object(
|
||||
{
|
||||
query: {
|
||||
type: "object",
|
||||
properties: {
|
||||
allOr: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used.",
|
||||
},
|
||||
string: {
|
||||
type: "object",
|
||||
example: {
|
||||
columnName1: "value",
|
||||
columnName2: "value",
|
||||
},
|
||||
description:
|
||||
"A map of field name to the string to search for, this will look for rows that have a value starting with the string value.",
|
||||
additionalProperties: {
|
||||
type: "string",
|
||||
description: "The value to search for in the column.",
|
||||
},
|
||||
},
|
||||
fuzzy: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for a sub-string within a string column, e.g. searching for 'dib' will match 'Budibase'.",
|
||||
},
|
||||
range: {
|
||||
type: "object",
|
||||
description:
|
||||
'Searches within a range, the format of this must be in the format of an object with a "low" and "high" property.',
|
||||
example: {
|
||||
columnName1: {
|
||||
low: 10,
|
||||
high: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
equal: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows that have a column value that is exactly the value set.",
|
||||
},
|
||||
notEqual: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for any row which does not contain the specified column value.",
|
||||
},
|
||||
empty: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.",
|
||||
example: {
|
||||
columnName1: "",
|
||||
},
|
||||
},
|
||||
notEmpty: {
|
||||
type: "object",
|
||||
description: "Searches for rows which have the specified column.",
|
||||
},
|
||||
oneOf: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2].",
|
||||
},
|
||||
contains: {
|
||||
type: "object",
|
||||
description:
|
||||
"Searches for a value, or set of values in array column types (such as a multi-select). If an array of search options is provided then it must match all.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
notContains: {
|
||||
type: "object",
|
||||
description:
|
||||
"The logical inverse of contains. Only works on array column types. If an array of values is passed, the row must not match any of them to be returned in the response.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
containsAny: {
|
||||
type: "object",
|
||||
description:
|
||||
"As with the contains search, only works on array column types and searches for any of the provided values when given an array.",
|
||||
example: {
|
||||
arrayColumn: ["a", "b"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
query: searchSchema,
|
||||
paginate: {
|
||||
type: "boolean",
|
||||
description: "Enables pagination, by default this is disabled.",
|
||||
|
|
|
@ -0,0 +1,274 @@
|
|||
import { object } from "./utils"
|
||||
import Resource from "./utils/Resource"
|
||||
import {
|
||||
ArrayOperator,
|
||||
BasicOperator,
|
||||
CalculationType,
|
||||
RangeOperator,
|
||||
SortOrder,
|
||||
SortType,
|
||||
} from "@budibase/types"
|
||||
import { cloneDeep } from "lodash"
|
||||
|
||||
const view = {
|
||||
name: "peopleView",
|
||||
tableId: "ta_896a325f7e8147d2a2cda93c5d236511",
|
||||
schema: {
|
||||
name: {
|
||||
visible: true,
|
||||
readonly: false,
|
||||
order: 1,
|
||||
width: 300,
|
||||
},
|
||||
age: {
|
||||
visible: true,
|
||||
readonly: true,
|
||||
order: 2,
|
||||
width: 200,
|
||||
},
|
||||
salary: {
|
||||
visible: false,
|
||||
readonly: false,
|
||||
},
|
||||
},
|
||||
query: {
|
||||
logicalOperator: "all",
|
||||
onEmptyFilter: "none",
|
||||
groups: [
|
||||
{
|
||||
logicalOperator: "any",
|
||||
filters: [
|
||||
{ operator: "string", field: "name", value: "John" },
|
||||
{ operator: "range", field: "age", value: { low: 18, high: 100 } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
primaryDisplay: "name",
|
||||
}
|
||||
|
||||
const baseColumnDef = {
|
||||
visible: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Defines whether the column is visible or not - rows retrieved/updated through this view will not be able to access it.",
|
||||
},
|
||||
readonly: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"When used in combination with 'visible: true' the column will be visible in row responses but cannot be updated.",
|
||||
},
|
||||
order: {
|
||||
type: "integer",
|
||||
description:
|
||||
"A number defining where the column shows up in tables, lowest being first.",
|
||||
},
|
||||
width: {
|
||||
type: "integer",
|
||||
description:
|
||||
"A width for the column, defined in pixels - this affects rendering in tables.",
|
||||
},
|
||||
column: {
|
||||
type: "array",
|
||||
description:
|
||||
"If this is a relationship column, we can set the columns we wish to include",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
readonly: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const logicalOperator = {
|
||||
description:
|
||||
"When using groups this defines whether all of the filters must match, or only one of them.",
|
||||
type: "string",
|
||||
enum: ["all", "any"],
|
||||
}
|
||||
|
||||
const filterGroup = {
|
||||
description: "A grouping of filters to be applied.",
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
logicalOperator,
|
||||
filters: {
|
||||
description: "A list of filters to apply",
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
operator: {
|
||||
type: "string",
|
||||
description:
|
||||
"The type of search operation which is being performed.",
|
||||
enum: [
|
||||
...Object.values(BasicOperator),
|
||||
...Object.values(ArrayOperator),
|
||||
...Object.values(RangeOperator),
|
||||
],
|
||||
},
|
||||
field: {
|
||||
type: "string",
|
||||
description: "The field in the view to perform the search on.",
|
||||
},
|
||||
value: {
|
||||
description:
|
||||
"The value to search for - the type will depend on the operator in use.",
|
||||
oneOf: [
|
||||
{ type: "string" },
|
||||
{ type: "number" },
|
||||
{ type: "boolean" },
|
||||
{ type: "object" },
|
||||
{ type: "array" },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// have to clone to avoid constantly recursive structure - we can't represent this easily
|
||||
const layeredFilterGroup: any = cloneDeep(filterGroup)
|
||||
layeredFilterGroup.items.properties.groups = filterGroup
|
||||
|
||||
const viewQuerySchema = {
|
||||
description: "Search parameters for view",
|
||||
type: "object",
|
||||
required: [],
|
||||
properties: {
|
||||
logicalOperator,
|
||||
onEmptyFilter: {
|
||||
description:
|
||||
"If no filters match, should the view return all rows, or no rows.",
|
||||
type: "string",
|
||||
enum: ["all", "none"],
|
||||
},
|
||||
groups: layeredFilterGroup,
|
||||
},
|
||||
}
|
||||
|
||||
const viewSchema = {
|
||||
description: "The view to be created/updated.",
|
||||
type: "object",
|
||||
required: ["name", "schema", "tableId"],
|
||||
properties: {
|
||||
name: {
|
||||
description: "The name of the view.",
|
||||
type: "string",
|
||||
},
|
||||
tableId: {
|
||||
description: "The ID of the table this view is based on.",
|
||||
type: "string",
|
||||
},
|
||||
type: {
|
||||
description: "The type of view - standard (empty value) or calculation.",
|
||||
type: "string",
|
||||
enum: ["calculation"],
|
||||
},
|
||||
primaryDisplay: {
|
||||
type: "string",
|
||||
description:
|
||||
"A column used to display rows from this view - usually used when rendered in tables.",
|
||||
},
|
||||
query: viewQuerySchema,
|
||||
sort: {
|
||||
type: "object",
|
||||
required: ["field"],
|
||||
properties: {
|
||||
field: {
|
||||
type: "string",
|
||||
description: "The field from the table/view schema to sort on.",
|
||||
},
|
||||
order: {
|
||||
type: "string",
|
||||
description: "The order in which to sort.",
|
||||
enum: Object.values(SortOrder),
|
||||
},
|
||||
type: {
|
||||
type: "string",
|
||||
description:
|
||||
"The type of sort to perform (by number, or by alphabetically).",
|
||||
enum: Object.values(SortType),
|
||||
},
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
type: "object",
|
||||
additionalProperties: {
|
||||
oneOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: baseColumnDef,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
calculationType: {
|
||||
type: "string",
|
||||
description:
|
||||
"This column should be built from a calculation, specifying a type and field. It is important to note when a calculation is configured all non-calculation columns will be used for grouping.",
|
||||
enum: Object.values(CalculationType),
|
||||
},
|
||||
field: {
|
||||
type: "string",
|
||||
description:
|
||||
"The field from the table to perform the calculation on.",
|
||||
},
|
||||
distinct: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Can be used in tandem with the count calculation type, to count unique entries.",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const viewOutputSchema = {
|
||||
...viewSchema,
|
||||
properties: {
|
||||
...viewSchema.properties,
|
||||
id: {
|
||||
description: "The ID of the view.",
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
required: [...viewSchema.required, "id"],
|
||||
}
|
||||
|
||||
export default new Resource()
|
||||
.setExamples({
|
||||
view: {
|
||||
value: {
|
||||
data: view,
|
||||
},
|
||||
},
|
||||
views: {
|
||||
value: {
|
||||
data: [view],
|
||||
},
|
||||
},
|
||||
})
|
||||
.setSchemas({
|
||||
view: viewSchema,
|
||||
viewOutput: object({
|
||||
data: viewOutputSchema,
|
||||
}),
|
||||
viewSearch: object({
|
||||
data: {
|
||||
type: "array",
|
||||
items: viewOutputSchema,
|
||||
},
|
||||
}),
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
import { Application } from "./types"
|
||||
import { RequiredKeys } from "@budibase/types"
|
||||
|
||||
function application(body: any): Application {
|
||||
function application(body: any): RequiredKeys<Application> {
|
||||
let app = body?.application ? body.application : body
|
||||
return {
|
||||
_id: app.appId,
|
||||
|
|
|
@ -3,6 +3,7 @@ import applications from "./applications"
|
|||
import users from "./users"
|
||||
import rows from "./rows"
|
||||
import queries from "./queries"
|
||||
import views from "./views"
|
||||
|
||||
export default {
|
||||
...tables,
|
||||
|
@ -10,4 +11,5 @@ export default {
|
|||
...users,
|
||||
...rows,
|
||||
...queries,
|
||||
...views,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Query, ExecuteQuery } from "./types"
|
||||
import { RequiredKeys } from "@budibase/types"
|
||||
|
||||
function query(body: any): Query {
|
||||
function query(body: any): RequiredKeys<Query> {
|
||||
return {
|
||||
_id: body._id,
|
||||
datasourceId: body.datasourceId,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Row, RowSearch } from "./types"
|
||||
import { RequiredKeys } from "@budibase/types"
|
||||
|
||||
function row(body: any): Row {
|
||||
function row(body: any): RequiredKeys<Row> {
|
||||
delete body._rev
|
||||
// have to input everything, since structure unknown
|
||||
return {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Table } from "./types"
|
||||
import { RequiredKeys } from "@budibase/types"
|
||||
|
||||
function table(body: any): Table {
|
||||
function table(body: any): RequiredKeys<Table> {
|
||||
return {
|
||||
_id: body._id,
|
||||
name: body.name,
|
||||
|
|
|
@ -9,6 +9,9 @@ export type CreateApplicationParams = components["schemas"]["application"]
|
|||
export type Table = components["schemas"]["tableOutput"]["data"]
|
||||
export type CreateTableParams = components["schemas"]["table"]
|
||||
|
||||
export type View = components["schemas"]["viewOutput"]["data"]
|
||||
export type CreateViewParams = components["schemas"]["view"]
|
||||
|
||||
export type Row = components["schemas"]["rowOutput"]["data"]
|
||||
export type RowSearch = components["schemas"]["searchOutput"]
|
||||
export type CreateRowParams = components["schemas"]["row"]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { User } from "./types"
|
||||
import { RequiredKeys } from "@budibase/types"
|
||||
|
||||
function user(body: any): User {
|
||||
function user(body: any): RequiredKeys<User> {
|
||||
return {
|
||||
_id: body._id,
|
||||
email: body.email,
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import { View } from "./types"
|
||||
import { ViewV2, Ctx, RequiredKeys } from "@budibase/types"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
|
||||
function view(body: ViewV2): RequiredKeys<View> {
|
||||
return {
|
||||
id: body.id,
|
||||
tableId: body.tableId,
|
||||
type: body.type,
|
||||
name: body.name,
|
||||
schema: body.schema!,
|
||||
primaryDisplay: body.primaryDisplay,
|
||||
query: dataFilters.buildQuery(body.query),
|
||||
sort: body.sort,
|
||||
}
|
||||
}
|
||||
|
||||
function mapView(ctx: Ctx<{ data: ViewV2 }>): { data: View } {
|
||||
return {
|
||||
data: view(ctx.body.data),
|
||||
}
|
||||
}
|
||||
|
||||
function mapViews(ctx: Ctx<{ data: ViewV2[] }>): { data: View[] } {
|
||||
const views = ctx.body.data.map((body: ViewV2) => view(body))
|
||||
return { data: views }
|
||||
}
|
||||
|
||||
export default {
|
||||
mapView,
|
||||
mapViews,
|
||||
}
|
|
@ -22,13 +22,13 @@ export function fixRow(row: Row, params: any) {
|
|||
return row
|
||||
}
|
||||
|
||||
export async function search(ctx: UserCtx, next: Next) {
|
||||
function buildSearchRequestBody(ctx: UserCtx) {
|
||||
let { sort, paginate, bookmark, limit, query } = ctx.request.body
|
||||
// update the body to the correct format of the internal search
|
||||
if (!sort) {
|
||||
sort = {}
|
||||
}
|
||||
ctx.request.body = {
|
||||
return {
|
||||
sort: sort.column,
|
||||
sortType: sort.type,
|
||||
sortOrder: sort.order,
|
||||
|
@ -37,10 +37,23 @@ export async function search(ctx: UserCtx, next: Next) {
|
|||
limit,
|
||||
query,
|
||||
}
|
||||
}
|
||||
|
||||
export async function search(ctx: UserCtx, next: Next) {
|
||||
ctx.request.body = buildSearchRequestBody(ctx)
|
||||
await rowController.search(ctx)
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function viewSearch(ctx: UserCtx, next: Next) {
|
||||
ctx.request.body = buildSearchRequestBody(ctx)
|
||||
ctx.params = {
|
||||
viewId: ctx.params.viewId,
|
||||
}
|
||||
await rowController.views.searchView(ctx)
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function create(ctx: UserCtx, next: Next) {
|
||||
ctx.request.body = fixRow(ctx.request.body, ctx.params)
|
||||
await rowController.save(ctx)
|
||||
|
@ -79,4 +92,5 @@ export default {
|
|||
update,
|
||||
destroy,
|
||||
search,
|
||||
viewSearch,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
import { search as stringSearch } from "./utils"
|
||||
import * as controller from "../view"
|
||||
import { ViewV2, UserCtx, UISearchFilter, PublicAPIView } from "@budibase/types"
|
||||
import { Next } from "koa"
|
||||
import { merge } from "lodash"
|
||||
|
||||
function viewRequest(view: PublicAPIView, params?: { viewId: string }) {
|
||||
const viewV2: ViewV2 = view
|
||||
if (!viewV2) {
|
||||
return viewV2
|
||||
}
|
||||
if (params?.viewId) {
|
||||
viewV2.id = params.viewId
|
||||
}
|
||||
if (!view.query) {
|
||||
viewV2.query = {}
|
||||
} else {
|
||||
// public API only has one form of query
|
||||
viewV2.queryUI = viewV2.query as UISearchFilter
|
||||
}
|
||||
viewV2.version = 2
|
||||
return viewV2
|
||||
}
|
||||
|
||||
function viewResponse(view: ViewV2): PublicAPIView {
|
||||
// remove our internal structure - always un-necessary
|
||||
delete view.query
|
||||
return {
|
||||
...view,
|
||||
query: view.queryUI,
|
||||
}
|
||||
}
|
||||
|
||||
function viewsResponse(views: ViewV2[]): PublicAPIView[] {
|
||||
return views.map(viewResponse)
|
||||
}
|
||||
|
||||
export async function search(ctx: UserCtx, next: Next) {
|
||||
const { name } = ctx.request.body
|
||||
await controller.v2.fetch(ctx)
|
||||
ctx.body.data = viewsResponse(stringSearch(ctx.body.data, name))
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function create(ctx: UserCtx, next: Next) {
|
||||
ctx = merge(ctx, {
|
||||
request: {
|
||||
body: viewRequest(ctx.request.body),
|
||||
},
|
||||
})
|
||||
await controller.v2.create(ctx)
|
||||
ctx.body.data = viewResponse(ctx.body.data)
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function read(ctx: UserCtx, next: Next) {
|
||||
ctx = merge(ctx, {
|
||||
params: {
|
||||
viewId: ctx.params.viewId,
|
||||
},
|
||||
})
|
||||
await controller.v2.get(ctx)
|
||||
ctx.body.data = viewResponse(ctx.body.data)
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function update(ctx: UserCtx, next: Next) {
|
||||
const viewId = ctx.params.viewId
|
||||
ctx = merge(ctx, {
|
||||
request: {
|
||||
body: {
|
||||
data: viewRequest(ctx.request.body, { viewId }),
|
||||
},
|
||||
},
|
||||
params: {
|
||||
viewId,
|
||||
},
|
||||
})
|
||||
await controller.v2.update(ctx)
|
||||
ctx.body.data = viewResponse(ctx.body.data)
|
||||
await next()
|
||||
}
|
||||
|
||||
export async function destroy(ctx: UserCtx, next: Next) {
|
||||
await controller.v2.remove(ctx)
|
||||
await next()
|
||||
}
|
||||
|
||||
export default {
|
||||
create,
|
||||
read,
|
||||
update,
|
||||
destroy,
|
||||
search,
|
||||
}
|
|
@ -4,7 +4,7 @@ import { URL } from "url"
|
|||
|
||||
const curlconverter = require("curlconverter")
|
||||
|
||||
const parseCurl = (data: string): any => {
|
||||
const parseCurl = (data: string): Promise<any> => {
|
||||
const curlJson = curlconverter.toJsonString(data)
|
||||
return JSON.parse(curlJson)
|
||||
}
|
||||
|
@ -53,8 +53,7 @@ export class Curl extends ImportSource {
|
|||
|
||||
isSupported = async (data: string): Promise<boolean> => {
|
||||
try {
|
||||
const curl = parseCurl(data)
|
||||
this.curl = curl
|
||||
this.curl = parseCurl(data)
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
} from "@budibase/types"
|
||||
import { ValidQueryNameRegex, utils as JsonUtils } from "@budibase/shared-core"
|
||||
import { findHBSBlocks } from "@budibase/string-templates"
|
||||
import { ObjectId } from "mongodb"
|
||||
|
||||
const Runner = new Thread(ThreadType.QUERY, {
|
||||
timeoutMs: env.QUERY_THREAD_TIMEOUT,
|
||||
|
@ -223,6 +224,8 @@ export async function preview(
|
|||
} else {
|
||||
fieldMetadata = makeQuerySchema(FieldType.ARRAY, key)
|
||||
}
|
||||
} else if (field instanceof ObjectId) {
|
||||
fieldMetadata = makeQuerySchema(FieldType.STRING, key)
|
||||
} else {
|
||||
fieldMetadata = makeQuerySchema(FieldType.JSON, key)
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ export async function searchView(
|
|||
result.rows.forEach(r => (r._viewId = view.id))
|
||||
ctx.body = result
|
||||
}
|
||||
|
||||
function getSortOptions(request: SearchViewRowRequest, view: ViewV2) {
|
||||
if (request.sort) {
|
||||
return {
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
RelationSchemaField,
|
||||
ViewFieldMetadata,
|
||||
CalculationType,
|
||||
ViewFetchResponseEnriched,
|
||||
CountDistinctCalculationFieldMetadata,
|
||||
CountCalculationFieldMetadata,
|
||||
} from "@budibase/types"
|
||||
|
@ -125,6 +126,12 @@ export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {
|
||||
ctx.body = {
|
||||
data: await sdk.views.getAllEnriched(),
|
||||
}
|
||||
}
|
||||
|
||||
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||
const view = ctx.request.body
|
||||
const { tableId } = view
|
||||
|
|
|
@ -4,19 +4,21 @@ import queryEndpoints from "./queries"
|
|||
import tableEndpoints from "./tables"
|
||||
import rowEndpoints from "./rows"
|
||||
import userEndpoints from "./users"
|
||||
import viewEndpoints from "./views"
|
||||
import roleEndpoints from "./roles"
|
||||
import authorized from "../../../middleware/authorized"
|
||||
import publicApi from "../../../middleware/publicApi"
|
||||
import { paramResource, paramSubResource } from "../../../middleware/resourceId"
|
||||
import { PermissionType, PermissionLevel } from "@budibase/types"
|
||||
import { PermissionLevel, PermissionType } from "@budibase/types"
|
||||
import { CtxFn } from "./utils/Endpoint"
|
||||
import mapperMiddleware from "./middleware/mapper"
|
||||
import env from "../../../environment"
|
||||
import { middleware, redis } from "@budibase/backend-core"
|
||||
import { SelectableDatabase } from "@budibase/backend-core/src/redis/utils"
|
||||
import cors from "@koa/cors"
|
||||
// below imports don't have declaration files
|
||||
const Router = require("@koa/router")
|
||||
const { RateLimit, Stores } = require("koa2-ratelimit")
|
||||
import { middleware, redis } from "@budibase/backend-core"
|
||||
import { SelectableDatabase } from "@budibase/backend-core/src/redis/utils"
|
||||
|
||||
interface KoaRateLimitOptions {
|
||||
socket: {
|
||||
|
@ -81,6 +83,7 @@ const publicRouter = new Router({
|
|||
if (limiter && !env.isDev()) {
|
||||
publicRouter.use(limiter)
|
||||
}
|
||||
publicRouter.use(cors())
|
||||
|
||||
function addMiddleware(
|
||||
endpoints: any,
|
||||
|
@ -149,6 +152,7 @@ applyAdminRoutes(metricEndpoints)
|
|||
applyAdminRoutes(roleEndpoints)
|
||||
applyRoutes(appEndpoints, PermissionType.APP, "appId")
|
||||
applyRoutes(tableEndpoints, PermissionType.TABLE, "tableId")
|
||||
applyRoutes(viewEndpoints, PermissionType.VIEW, "viewId")
|
||||
applyRoutes(userEndpoints, PermissionType.USER, "userId")
|
||||
applyRoutes(queryEndpoints, PermissionType.QUERY, "queryId")
|
||||
// needs to be applied last for routing purposes, don't override other endpoints
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { Ctx } from "@budibase/types"
|
||||
import mapping from "../../../controllers/public/mapping"
|
||||
|
||||
enum Resources {
|
||||
enum Resource {
|
||||
APPLICATION = "applications",
|
||||
TABLES = "tables",
|
||||
VIEWS = "views",
|
||||
ROWS = "rows",
|
||||
USERS = "users",
|
||||
QUERIES = "queries",
|
||||
|
@ -15,7 +16,7 @@ function isAttachment(ctx: Ctx) {
|
|||
}
|
||||
|
||||
function isArrayResponse(ctx: Ctx) {
|
||||
return ctx.url.endsWith(Resources.SEARCH) || Array.isArray(ctx.body)
|
||||
return ctx.url.endsWith(Resource.SEARCH) || Array.isArray(ctx.body)
|
||||
}
|
||||
|
||||
function noResponse(ctx: Ctx) {
|
||||
|
@ -38,6 +39,14 @@ function processTables(ctx: Ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
function processViews(ctx: Ctx) {
|
||||
if (isArrayResponse(ctx)) {
|
||||
return mapping.mapViews(ctx)
|
||||
} else {
|
||||
return mapping.mapView(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
function processRows(ctx: Ctx) {
|
||||
if (isArrayResponse(ctx)) {
|
||||
return mapping.mapRowSearch(ctx)
|
||||
|
@ -71,20 +80,27 @@ export default async (ctx: Ctx, next: any) => {
|
|||
let body = {}
|
||||
|
||||
switch (urlParts[0]) {
|
||||
case Resources.APPLICATION:
|
||||
case Resource.APPLICATION:
|
||||
body = processApplications(ctx)
|
||||
break
|
||||
case Resources.TABLES:
|
||||
if (urlParts[2] === Resources.ROWS) {
|
||||
case Resource.TABLES:
|
||||
if (urlParts[2] === Resource.ROWS) {
|
||||
body = processRows(ctx)
|
||||
} else {
|
||||
body = processTables(ctx)
|
||||
}
|
||||
break
|
||||
case Resources.USERS:
|
||||
case Resource.VIEWS:
|
||||
if (urlParts[2] === Resource.ROWS) {
|
||||
body = processRows(ctx)
|
||||
} else {
|
||||
body = processViews(ctx)
|
||||
}
|
||||
break
|
||||
case Resource.USERS:
|
||||
body = processUsers(ctx)
|
||||
break
|
||||
case Resources.QUERIES:
|
||||
case Resource.QUERIES:
|
||||
body = processQueries(ctx)
|
||||
break
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import controller from "../../controllers/public/rows"
|
||||
import controller, { viewSearch } from "../../controllers/public/rows"
|
||||
import Endpoint from "./utils/Endpoint"
|
||||
import { externalSearchValidator } from "../utils/validators"
|
||||
|
||||
|
@ -168,4 +168,40 @@ read.push(
|
|||
).addMiddleware(externalSearchValidator())
|
||||
)
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views/{viewId}/rows/search:
|
||||
* post:
|
||||
* operationId: rowViewSearch
|
||||
* summary: Search for rows in a view
|
||||
* tags:
|
||||
* - rows
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/viewId'
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/rowSearch'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: The response will contain an array of rows that match the search parameters.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/searchOutput'
|
||||
* examples:
|
||||
* search:
|
||||
* $ref: '#/components/examples/rows'
|
||||
*/
|
||||
read.push(
|
||||
new Endpoint(
|
||||
"post",
|
||||
"/views/:viewId/rows/search",
|
||||
controller.viewSearch
|
||||
).addMiddleware(externalSearchValidator())
|
||||
)
|
||||
|
||||
export default { read, write }
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
import { User, Table, SearchFilters, Row } from "@budibase/types"
|
||||
import {
|
||||
User,
|
||||
Table,
|
||||
SearchFilters,
|
||||
Row,
|
||||
ViewV2Schema,
|
||||
ViewV2,
|
||||
ViewV2Type,
|
||||
PublicAPIView,
|
||||
} from "@budibase/types"
|
||||
import { HttpMethod, MakeRequestResponse, generateMakeRequest } from "./utils"
|
||||
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
||||
import { Expectations } from "../../../../tests/utilities/api/base"
|
||||
|
||||
type RequestOpts = { internal?: boolean; appId?: string }
|
||||
|
||||
type Response<T> = { data: T }
|
||||
|
||||
export interface PublicAPIExpectations {
|
||||
status?: number
|
||||
body?: Record<string, any>
|
||||
headers?: Record<string, string>
|
||||
}
|
||||
|
||||
export class PublicAPIRequest {
|
||||
|
@ -15,6 +26,7 @@ export class PublicAPIRequest {
|
|||
private appId: string | undefined
|
||||
|
||||
tables: PublicTableAPI
|
||||
views: PublicViewAPI
|
||||
rows: PublicRowAPI
|
||||
apiKey: string
|
||||
|
||||
|
@ -28,6 +40,7 @@ export class PublicAPIRequest {
|
|||
this.appId = appId
|
||||
this.tables = new PublicTableAPI(this)
|
||||
this.rows = new PublicRowAPI(this)
|
||||
this.views = new PublicViewAPI(this)
|
||||
}
|
||||
|
||||
static async init(config: TestConfiguration, user: User, opts?: RequestOpts) {
|
||||
|
@ -59,6 +72,12 @@ export class PublicAPIRequest {
|
|||
if (expectations?.body) {
|
||||
expect(res.body).toEqual(expectations?.body)
|
||||
}
|
||||
if (expectations?.headers) {
|
||||
for (let [header, value] of Object.entries(expectations.headers)) {
|
||||
const found = res.headers[header]
|
||||
expect(found?.toLowerCase()).toEqual(value)
|
||||
}
|
||||
}
|
||||
return res.body
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +92,16 @@ export class PublicTableAPI {
|
|||
async create(
|
||||
table: Table,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<{ data: Table }> {
|
||||
): Promise<Response<Table>> {
|
||||
return this.request.send("post", "/tables", table, expectations)
|
||||
}
|
||||
|
||||
async search(
|
||||
name: string,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<Table[]>> {
|
||||
return this.request.send("post", "/tables/search", { name }, expectations)
|
||||
}
|
||||
}
|
||||
|
||||
export class PublicRowAPI {
|
||||
|
@ -85,11 +111,24 @@ export class PublicRowAPI {
|
|||
this.request = request
|
||||
}
|
||||
|
||||
async create(
|
||||
tableId: string,
|
||||
row: Row,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<Row>> {
|
||||
return this.request.send(
|
||||
"post",
|
||||
`/tables/${tableId}/rows`,
|
||||
row,
|
||||
expectations
|
||||
)
|
||||
}
|
||||
|
||||
async search(
|
||||
tableId: string,
|
||||
query: SearchFilters,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<{ data: Row[] }> {
|
||||
): Promise<Response<Row[]>> {
|
||||
return this.request.send(
|
||||
"post",
|
||||
`/tables/${tableId}/rows/search`,
|
||||
|
@ -99,4 +138,75 @@ export class PublicRowAPI {
|
|||
expectations
|
||||
)
|
||||
}
|
||||
|
||||
async viewSearch(
|
||||
viewId: string,
|
||||
query: SearchFilters,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<Row[]>> {
|
||||
return this.request.send(
|
||||
"post",
|
||||
`/views/${viewId}/rows/search`,
|
||||
{
|
||||
query,
|
||||
},
|
||||
expectations
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export class PublicViewAPI {
|
||||
request: PublicAPIRequest
|
||||
|
||||
constructor(request: PublicAPIRequest) {
|
||||
this.request = request
|
||||
}
|
||||
|
||||
async create(
|
||||
view: Omit<PublicAPIView, "id" | "version">,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<PublicAPIView>> {
|
||||
return this.request.send("post", "/views", view, expectations)
|
||||
}
|
||||
|
||||
async update(
|
||||
viewId: string,
|
||||
view: Omit<PublicAPIView, "id" | "version">,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<PublicAPIView>> {
|
||||
return this.request.send("put", `/views/${viewId}`, view, expectations)
|
||||
}
|
||||
|
||||
async destroy(
|
||||
viewId: string,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<void> {
|
||||
return this.request.send(
|
||||
"delete",
|
||||
`/views/${viewId}`,
|
||||
undefined,
|
||||
expectations
|
||||
)
|
||||
}
|
||||
|
||||
async find(
|
||||
viewId: string,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<PublicAPIView>> {
|
||||
return this.request.send("get", `/views/${viewId}`, undefined, expectations)
|
||||
}
|
||||
|
||||
async search(
|
||||
viewName: string,
|
||||
expectations?: PublicAPIExpectations
|
||||
): Promise<Response<PublicAPIView[]>> {
|
||||
return this.request.send(
|
||||
"post",
|
||||
"/views/search",
|
||||
{
|
||||
name: viewName,
|
||||
},
|
||||
expectations
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import * as setup from "../../tests/utilities"
|
||||
import { PublicAPIRequest } from "./Request"
|
||||
|
||||
describe("check public API security", () => {
|
||||
const config = setup.getConfig()
|
||||
let request: PublicAPIRequest
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.init()
|
||||
request = await PublicAPIRequest.init(config, await config.globalUser())
|
||||
})
|
||||
|
||||
it("should have Access-Control-Allow-Origin set to *", async () => {
|
||||
await request.tables.search("", {
|
||||
status: 200,
|
||||
headers: {
|
||||
"access-control-allow-origin": "*",
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,95 @@
|
|||
import * as setup from "../../tests/utilities"
|
||||
import { basicTable } from "../../../../tests/utilities/structures"
|
||||
import { BasicOperator, Table, UILogicalOperator } from "@budibase/types"
|
||||
import { PublicAPIRequest } from "./Request"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
||||
describe("check public API security", () => {
|
||||
const config = setup.getConfig()
|
||||
let request: PublicAPIRequest, table: Table
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.init()
|
||||
request = await PublicAPIRequest.init(config, await config.globalUser())
|
||||
table = (await request.tables.create(basicTable())).data
|
||||
})
|
||||
|
||||
function baseView() {
|
||||
return {
|
||||
name: generator.word(),
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
schema: {
|
||||
name: {
|
||||
readonly: true,
|
||||
visible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
it("should be able to create a view", async () => {
|
||||
await request.views.create(baseView(), { status: 201 })
|
||||
})
|
||||
|
||||
it("should be able to update a view", async () => {
|
||||
const view = await request.views.create(baseView(), { status: 201 })
|
||||
const response = await request.views.update(view.data.id, {
|
||||
...view.data,
|
||||
name: "new name",
|
||||
})
|
||||
})
|
||||
|
||||
it("should be able to search views", async () => {
|
||||
const viewName = "view to search for"
|
||||
const view = await request.views.create(
|
||||
{
|
||||
...baseView(),
|
||||
name: viewName,
|
||||
},
|
||||
{ status: 201 }
|
||||
)
|
||||
const results = await request.views.search(viewName, {
|
||||
status: 200,
|
||||
})
|
||||
expect(results.data.length).toEqual(1)
|
||||
expect(results.data[0].id).toEqual(view.data.id)
|
||||
})
|
||||
|
||||
it("should be able to delete a view", async () => {
|
||||
const view = await request.views.create(baseView(), { status: 201 })
|
||||
const result = await request.views.destroy(view.data.id, { status: 204 })
|
||||
expect(result).toBeDefined()
|
||||
})
|
||||
|
||||
it("should be able to search rows through a view", async () => {
|
||||
const row1 = await request.rows.create(
|
||||
table._id!,
|
||||
{ name: "hello world" },
|
||||
{ status: 200 }
|
||||
)
|
||||
await request.rows.create(table._id!, { name: "foo bar" }, { status: 200 })
|
||||
const response = await request.views.create(
|
||||
{
|
||||
...baseView(),
|
||||
query: {
|
||||
logicalOperator: UILogicalOperator.ANY,
|
||||
groups: [
|
||||
{
|
||||
filters: [
|
||||
{
|
||||
operator: BasicOperator.STRING,
|
||||
field: "name",
|
||||
value: "hello",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{ status: 201 }
|
||||
)
|
||||
const results = await request.rows.viewSearch(response.data.id, {})
|
||||
expect(results.data.length).toEqual(1)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,165 @@
|
|||
import controller from "../../controllers/public/views"
|
||||
import Endpoint from "./utils/Endpoint"
|
||||
import { viewValidator, nameValidator } from "../utils/validators"
|
||||
|
||||
const read = [],
|
||||
write = []
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views:
|
||||
* post:
|
||||
* operationId: viewCreate
|
||||
* summary: Create a view
|
||||
* description: Create a view, this can be against an internal or external table.
|
||||
* tags:
|
||||
* - views
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* requestBody:
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/view'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns the created view, including the ID which has been generated for it.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/viewOutput'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
*/
|
||||
write.push(
|
||||
new Endpoint("post", "/views", controller.create).addMiddleware(
|
||||
viewValidator()
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views/{viewId}:
|
||||
* put:
|
||||
* operationId: viewUpdate
|
||||
* summary: Update a view
|
||||
* description: Update a view, this can be against an internal or external table.
|
||||
* tags:
|
||||
* - views
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/viewId'
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* requestBody:
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/view'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns the updated view.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/viewOutput'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
*/
|
||||
write.push(
|
||||
new Endpoint("put", "/views/:viewId", controller.update).addMiddleware(
|
||||
viewValidator()
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views/{viewId}:
|
||||
* delete:
|
||||
* operationId: viewDestroy
|
||||
* summary: Delete a view
|
||||
* description: Delete a view, this can be against an internal or external table.
|
||||
* tags:
|
||||
* - views
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/viewId'
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns the deleted view.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/viewOutput'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
*/
|
||||
write.push(new Endpoint("delete", "/views/:viewId", controller.destroy))
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views/{viewId}:
|
||||
* get:
|
||||
* operationId: viewGetById
|
||||
* summary: Retrieve a view
|
||||
* description: Lookup a view, this could be internal or external.
|
||||
* tags:
|
||||
* - views
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/viewId'
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns the retrieved view.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/viewOutput'
|
||||
* examples:
|
||||
* view:
|
||||
* $ref: '#/components/examples/view'
|
||||
*/
|
||||
read.push(new Endpoint("get", "/views/:viewId", controller.read))
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /views/search:
|
||||
* post:
|
||||
* operationId: viewSearch
|
||||
* summary: Search for views
|
||||
* description: Based on view properties (currently only name) search for views.
|
||||
* tags:
|
||||
* - views
|
||||
* parameters:
|
||||
* - $ref: '#/components/parameters/appId'
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/nameSearch'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns the found views, based on the search parameters.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/viewSearch'
|
||||
* examples:
|
||||
* views:
|
||||
* $ref: '#/components/examples/views'
|
||||
*/
|
||||
read.push(
|
||||
new Endpoint("post", "/views/search", controller.search).addMiddleware(
|
||||
nameValidator()
|
||||
)
|
||||
)
|
||||
|
||||
export default { read, write }
|
|
@ -164,9 +164,12 @@ describe("/datasources", () => {
|
|||
})
|
||||
})
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "%s", exclude: [DatabaseName.MONGODB, DatabaseName.SQS] },
|
||||
({ config, dsProvider }) => {
|
||||
const descriptions = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
})
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)("$dbName", ({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let rawDatasource: Datasource
|
||||
let client: Knex
|
||||
|
@ -492,5 +495,5 @@ datasourceDescribe(
|
|||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -977,63 +977,69 @@ describe("/rowsActions", () => {
|
|||
})
|
||||
})
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "row actions (%s)", only: [DatabaseName.SQS, DatabaseName.POSTGRES] },
|
||||
({ config, dsProvider, isInternal }) => {
|
||||
let datasource: Datasource | undefined
|
||||
const descriptions = datasourceDescribe({
|
||||
only: [DatabaseName.SQS, DatabaseName.POSTGRES],
|
||||
})
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"row actions ($dbName)",
|
||||
({ config, dsProvider, isInternal }) => {
|
||||
let datasource: Datasource | undefined
|
||||
|
||||
async function getTable(): Promise<Table> {
|
||||
if (isInternal) {
|
||||
await config.api.application.addSampleData(config.getAppId())
|
||||
const tables = await config.api.table.fetch()
|
||||
return tables.find(t => t.sourceId === DEFAULT_BB_DATASOURCE_ID)!
|
||||
} else {
|
||||
const table = await config.api.table.save(
|
||||
setup.structures.tableForDatasource(datasource!)
|
||||
)
|
||||
return table
|
||||
}
|
||||
}
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
|
||||
it("should delete all the row actions (and automations) for its tables when a datasource is deleted", async () => {
|
||||
async function getRowActionsFromDb(tableId: string) {
|
||||
return await context.doInAppContext(config.getAppId(), async () => {
|
||||
const db = context.getAppDB()
|
||||
const tableDoc = await db.tryGet<TableRowActions>(
|
||||
generateRowActionsID(tableId)
|
||||
async function getTable(): Promise<Table> {
|
||||
if (isInternal) {
|
||||
await config.api.application.addSampleData(config.getAppId())
|
||||
const tables = await config.api.table.fetch()
|
||||
return tables.find(t => t.sourceId === DEFAULT_BB_DATASOURCE_ID)!
|
||||
} else {
|
||||
const table = await config.api.table.save(
|
||||
setup.structures.tableForDatasource(datasource!)
|
||||
)
|
||||
return tableDoc
|
||||
})
|
||||
return table
|
||||
}
|
||||
}
|
||||
|
||||
const table = await getTable()
|
||||
const tableId = table._id!
|
||||
it("should delete all the row actions (and automations) for its tables when a datasource is deleted", async () => {
|
||||
async function getRowActionsFromDb(tableId: string) {
|
||||
return await context.doInAppContext(config.getAppId(), async () => {
|
||||
const db = context.getAppDB()
|
||||
const tableDoc = await db.tryGet<TableRowActions>(
|
||||
generateRowActionsID(tableId)
|
||||
)
|
||||
return tableDoc
|
||||
})
|
||||
}
|
||||
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
const table = await getTable()
|
||||
const tableId = table._id!
|
||||
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
|
||||
const { actions } = (await getRowActionsFromDb(tableId))!
|
||||
expect(Object.entries(actions)).toHaveLength(2)
|
||||
|
||||
const { automations } = await config.api.automation.fetch()
|
||||
expect(automations).toHaveLength(2)
|
||||
|
||||
const datasource = await config.api.datasource.get(table.sourceId)
|
||||
await config.api.datasource.delete(datasource)
|
||||
|
||||
const automationsResp = await config.api.automation.fetch()
|
||||
expect(automationsResp.automations).toHaveLength(0)
|
||||
|
||||
expect(await getRowActionsFromDb(tableId)).toBeUndefined()
|
||||
})
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
|
||||
const { actions } = (await getRowActionsFromDb(tableId))!
|
||||
expect(Object.entries(actions)).toHaveLength(2)
|
||||
|
||||
const { automations } = await config.api.automation.fetch()
|
||||
expect(automations).toHaveLength(2)
|
||||
|
||||
const datasource = await config.api.datasource.get(table.sourceId)
|
||||
await config.api.datasource.delete(datasource)
|
||||
|
||||
const automationsResp = await config.api.automation.fetch()
|
||||
expect(automationsResp.automations).toHaveLength(0)
|
||||
|
||||
expect(await getRowActionsFromDb(tableId)).toBeUndefined()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,13 @@ import {
|
|||
Table,
|
||||
WebhookActionType,
|
||||
BuiltinPermissionID,
|
||||
ViewV2Type,
|
||||
SortOrder,
|
||||
SortType,
|
||||
UILogicalOperator,
|
||||
BasicOperator,
|
||||
ArrayOperator,
|
||||
RangeOperator,
|
||||
} from "@budibase/types"
|
||||
import Joi, { CustomValidator } from "joi"
|
||||
import { ValidSnippetNameRegex, helpers } from "@budibase/shared-core"
|
||||
|
@ -66,6 +73,66 @@ export function tableValidator() {
|
|||
)
|
||||
}
|
||||
|
||||
function searchUIFilterValidator() {
|
||||
const logicalOperator = Joi.string().valid(
|
||||
...Object.values(UILogicalOperator)
|
||||
)
|
||||
const operators = [
|
||||
...Object.values(BasicOperator),
|
||||
...Object.values(ArrayOperator),
|
||||
...Object.values(RangeOperator),
|
||||
]
|
||||
const filters = Joi.array().items(
|
||||
Joi.object({
|
||||
operator: Joi.string()
|
||||
.valid(...operators)
|
||||
.required(),
|
||||
field: Joi.string().required(),
|
||||
// could do with better validation of value based on operator
|
||||
value: Joi.any().required(),
|
||||
})
|
||||
)
|
||||
return Joi.object({
|
||||
logicalOperator,
|
||||
onEmptyFilter: Joi.string().valid(...Object.values(EmptyFilterOption)),
|
||||
groups: Joi.array().items(
|
||||
Joi.object({
|
||||
logicalOperator,
|
||||
filters,
|
||||
groups: Joi.array().items(
|
||||
Joi.object({
|
||||
filters,
|
||||
logicalOperator,
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
export function viewValidator() {
|
||||
return auth.joiValidator.body(
|
||||
Joi.object({
|
||||
id: OPTIONAL_STRING,
|
||||
tableId: Joi.string().required(),
|
||||
name: Joi.string().required(),
|
||||
type: Joi.string().optional().valid(null, ViewV2Type.CALCULATION),
|
||||
primaryDisplay: OPTIONAL_STRING,
|
||||
schema: Joi.object().required(),
|
||||
query: searchUIFilterValidator().optional(),
|
||||
sort: Joi.object({
|
||||
field: Joi.string().required(),
|
||||
order: Joi.string()
|
||||
.optional()
|
||||
.valid(...Object.values(SortOrder)),
|
||||
type: Joi.string()
|
||||
.optional()
|
||||
.valid(...Object.values(SortType)),
|
||||
}).optional(),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export function nameValidator() {
|
||||
return auth.joiValidator.body(
|
||||
Joi.object({
|
||||
|
@ -91,8 +158,7 @@ export function datasourceValidator() {
|
|||
)
|
||||
}
|
||||
|
||||
function filterObject(opts?: { unknown: boolean }) {
|
||||
const { unknown = true } = opts || {}
|
||||
function searchFiltersValidator() {
|
||||
const conditionalFilteringObject = () =>
|
||||
Joi.object({
|
||||
conditions: Joi.array().items(Joi.link("#schema")).required(),
|
||||
|
@ -119,7 +185,14 @@ function filterObject(opts?: { unknown: boolean }) {
|
|||
fuzzyOr: Joi.forbidden(),
|
||||
documentType: Joi.forbidden(),
|
||||
}
|
||||
return Joi.object(filtersValidators).unknown(unknown).id("schema")
|
||||
|
||||
return Joi.object(filtersValidators)
|
||||
}
|
||||
|
||||
function filterObject(opts?: { unknown: boolean }) {
|
||||
const { unknown = true } = opts || {}
|
||||
|
||||
return searchFiltersValidator().unknown(unknown).id("schema")
|
||||
}
|
||||
|
||||
export function internalSearchValidator() {
|
||||
|
|
|
@ -8,6 +8,11 @@ import { permissions } from "@budibase/backend-core"
|
|||
const router: Router = new Router()
|
||||
|
||||
router
|
||||
.get(
|
||||
"/api/v2/views",
|
||||
authorized(permissions.BUILDER),
|
||||
viewController.v2.fetch
|
||||
)
|
||||
.get(
|
||||
"/api/v2/views/:viewId",
|
||||
authorizedResource(
|
||||
|
|
|
@ -7,71 +7,74 @@ import {
|
|||
import { Knex } from "knex"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
||||
datasourceDescribe(
|
||||
{
|
||||
name: "execute query action",
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
},
|
||||
({ config, dsProvider }) => {
|
||||
let tableName: string
|
||||
let client: Knex
|
||||
let datasource: Datasource
|
||||
let query: Query
|
||||
const descriptions = datasourceDescribe({
|
||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||
})
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"execute query action ($dbName)",
|
||||
({ config, dsProvider }) => {
|
||||
let tableName: string
|
||||
let client: Knex
|
||||
let datasource: Datasource
|
||||
let query: Query
|
||||
|
||||
beforeEach(async () => {
|
||||
tableName = generator.guid()
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.string("a")
|
||||
table.integer("b")
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
await client(tableName).insert({ a: "string", b: 1 })
|
||||
query = await setup.saveTestQuery(config, client, tableName, datasource)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTable(tableName)
|
||||
})
|
||||
beforeEach(async () => {
|
||||
tableName = generator.guid()
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.string("a")
|
||||
table.integer("b")
|
||||
})
|
||||
await client(tableName).insert({ a: "string", b: 1 })
|
||||
query = await setup.saveTestQuery(config, client, tableName, datasource)
|
||||
})
|
||||
|
||||
it("should be able to execute a query", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: { queryId: query._id },
|
||||
}
|
||||
)
|
||||
expect(res.response).toEqual([{ a: "string", b: 1 }])
|
||||
expect(res.success).toEqual(true)
|
||||
})
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTable(tableName)
|
||||
})
|
||||
|
||||
it("should handle a null query value", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: null,
|
||||
}
|
||||
)
|
||||
expect(res.response.message).toEqual("Invalid inputs")
|
||||
expect(res.success).toEqual(false)
|
||||
})
|
||||
it("should be able to execute a query", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: { queryId: query._id },
|
||||
}
|
||||
)
|
||||
expect(res.response).toEqual([{ a: "string", b: 1 }])
|
||||
expect(res.success).toEqual(true)
|
||||
})
|
||||
|
||||
it("should handle an error executing a query", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: { queryId: "wrong_id" },
|
||||
}
|
||||
)
|
||||
expect(res.response).toBeDefined()
|
||||
expect(res.success).toEqual(false)
|
||||
})
|
||||
}
|
||||
)
|
||||
it("should handle a null query value", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: null,
|
||||
}
|
||||
)
|
||||
expect(res.response.message).toEqual("Invalid inputs")
|
||||
expect(res.success).toEqual(false)
|
||||
})
|
||||
|
||||
it("should handle an error executing a query", async () => {
|
||||
let res = await setup.runStep(
|
||||
config,
|
||||
setup.actions.EXECUTE_QUERY.stepId,
|
||||
{
|
||||
query: { queryId: "wrong_id" },
|
||||
}
|
||||
)
|
||||
expect(res.response).toBeDefined()
|
||||
expect(res.success).toEqual(false)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -433,9 +433,10 @@ describe("Automation Scenarios", () => {
|
|||
})
|
||||
})
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "", only: [DatabaseName.MYSQL] },
|
||||
({ config, dsProvider }) => {
|
||||
const descriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
|
||||
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)("/rows ($dbName)", ({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
|
||||
|
@ -531,5 +532,5 @@ datasourceDescribe(
|
|||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ export interface paths {
|
|||
"/tables/{tableId}/rows/search": {
|
||||
post: operations["rowSearch"];
|
||||
};
|
||||
"/views/{viewId}/rows/search": {
|
||||
post: operations["rowViewSearch"];
|
||||
};
|
||||
"/tables": {
|
||||
/** Create a table, this could be internal or external. */
|
||||
post: operations["tableCreate"];
|
||||
|
@ -93,6 +96,22 @@ export interface paths {
|
|||
/** Based on user properties (currently only name) search for users. */
|
||||
post: operations["userSearch"];
|
||||
};
|
||||
"/views": {
|
||||
/** Create a view, this can be against an internal or external table. */
|
||||
post: operations["viewCreate"];
|
||||
};
|
||||
"/views/{viewId}": {
|
||||
/** Lookup a view, this could be internal or external. */
|
||||
get: operations["viewGetById"];
|
||||
/** Update a view, this can be against an internal or external table. */
|
||||
put: operations["viewUpdate"];
|
||||
/** Delete a view, this can be against an internal or external table. */
|
||||
delete: operations["viewDestroy"];
|
||||
};
|
||||
"/views/search": {
|
||||
/** Based on view properties (currently only name) search for views. */
|
||||
post: operations["viewSearch"];
|
||||
};
|
||||
}
|
||||
|
||||
export interface components {
|
||||
|
@ -813,10 +832,442 @@ export interface components {
|
|||
userIds: string[];
|
||||
};
|
||||
};
|
||||
/** @description The view to be created/updated. */
|
||||
view: {
|
||||
/** @description The name of the view. */
|
||||
name: string;
|
||||
/** @description The ID of the table this view is based on. */
|
||||
tableId: string;
|
||||
/**
|
||||
* @description The type of view - standard (empty value) or calculation.
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "calculation";
|
||||
/** @description A column used to display rows from this view - usually used when rendered in tables. */
|
||||
primaryDisplay?: string;
|
||||
/** @description Search parameters for view */
|
||||
query?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/**
|
||||
* @description If no filters match, should the view return all rows, or no rows.
|
||||
* @enum {string}
|
||||
*/
|
||||
onEmptyFilter?: "all" | "none";
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
sort?: {
|
||||
/** @description The field from the table/view schema to sort on. */
|
||||
field: string;
|
||||
/**
|
||||
* @description The order in which to sort.
|
||||
* @enum {string}
|
||||
*/
|
||||
order?: "ascending" | "descending";
|
||||
/**
|
||||
* @description The type of sort to perform (by number, or by alphabetically).
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "string" | "number";
|
||||
};
|
||||
schema: {
|
||||
[key: string]:
|
||||
| {
|
||||
/** @description Defines whether the column is visible or not - rows retrieved/updated through this view will not be able to access it. */
|
||||
visible?: boolean;
|
||||
/** @description When used in combination with 'visible: true' the column will be visible in row responses but cannot be updated. */
|
||||
readonly?: boolean;
|
||||
/** @description A number defining where the column shows up in tables, lowest being first. */
|
||||
order?: number;
|
||||
/** @description A width for the column, defined in pixels - this affects rendering in tables. */
|
||||
width?: number;
|
||||
/** @description If this is a relationship column, we can set the columns we wish to include */
|
||||
column?: {
|
||||
readonly?: boolean;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* @description This column should be built from a calculation, specifying a type and field. It is important to note when a calculation is configured all non-calculation columns will be used for grouping.
|
||||
* @enum {string}
|
||||
*/
|
||||
calculationType?: "sum" | "avg" | "count" | "min" | "max";
|
||||
/** @description The field from the table to perform the calculation on. */
|
||||
field?: string;
|
||||
/** @description Can be used in tandem with the count calculation type, to count unique entries. */
|
||||
distinct?: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
viewOutput: {
|
||||
/** @description The view to be created/updated. */
|
||||
data: {
|
||||
/** @description The name of the view. */
|
||||
name: string;
|
||||
/** @description The ID of the table this view is based on. */
|
||||
tableId: string;
|
||||
/**
|
||||
* @description The type of view - standard (empty value) or calculation.
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "calculation";
|
||||
/** @description A column used to display rows from this view - usually used when rendered in tables. */
|
||||
primaryDisplay?: string;
|
||||
/** @description Search parameters for view */
|
||||
query?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/**
|
||||
* @description If no filters match, should the view return all rows, or no rows.
|
||||
* @enum {string}
|
||||
*/
|
||||
onEmptyFilter?: "all" | "none";
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
sort?: {
|
||||
/** @description The field from the table/view schema to sort on. */
|
||||
field: string;
|
||||
/**
|
||||
* @description The order in which to sort.
|
||||
* @enum {string}
|
||||
*/
|
||||
order?: "ascending" | "descending";
|
||||
/**
|
||||
* @description The type of sort to perform (by number, or by alphabetically).
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "string" | "number";
|
||||
};
|
||||
schema: {
|
||||
[key: string]:
|
||||
| {
|
||||
/** @description Defines whether the column is visible or not - rows retrieved/updated through this view will not be able to access it. */
|
||||
visible?: boolean;
|
||||
/** @description When used in combination with 'visible: true' the column will be visible in row responses but cannot be updated. */
|
||||
readonly?: boolean;
|
||||
/** @description A number defining where the column shows up in tables, lowest being first. */
|
||||
order?: number;
|
||||
/** @description A width for the column, defined in pixels - this affects rendering in tables. */
|
||||
width?: number;
|
||||
/** @description If this is a relationship column, we can set the columns we wish to include */
|
||||
column?: {
|
||||
readonly?: boolean;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* @description This column should be built from a calculation, specifying a type and field. It is important to note when a calculation is configured all non-calculation columns will be used for grouping.
|
||||
* @enum {string}
|
||||
*/
|
||||
calculationType?: "sum" | "avg" | "count" | "min" | "max";
|
||||
/** @description The field from the table to perform the calculation on. */
|
||||
field?: string;
|
||||
/** @description Can be used in tandem with the count calculation type, to count unique entries. */
|
||||
distinct?: boolean;
|
||||
};
|
||||
};
|
||||
/** @description The ID of the view. */
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
viewSearch: {
|
||||
data: {
|
||||
/** @description The name of the view. */
|
||||
name: string;
|
||||
/** @description The ID of the table this view is based on. */
|
||||
tableId: string;
|
||||
/**
|
||||
* @description The type of view - standard (empty value) or calculation.
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "calculation";
|
||||
/** @description A column used to display rows from this view - usually used when rendered in tables. */
|
||||
primaryDisplay?: string;
|
||||
/** @description Search parameters for view */
|
||||
query?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/**
|
||||
* @description If no filters match, should the view return all rows, or no rows.
|
||||
* @enum {string}
|
||||
*/
|
||||
onEmptyFilter?: "all" | "none";
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
/** @description A grouping of filters to be applied. */
|
||||
groups?: {
|
||||
/**
|
||||
* @description When using groups this defines whether all of the filters must match, or only one of them.
|
||||
* @enum {string}
|
||||
*/
|
||||
logicalOperator?: "all" | "any";
|
||||
/** @description A list of filters to apply */
|
||||
filters?: {
|
||||
/**
|
||||
* @description The type of search operation which is being performed.
|
||||
* @enum {string}
|
||||
*/
|
||||
operator?:
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "empty"
|
||||
| "notEmpty"
|
||||
| "fuzzy"
|
||||
| "string"
|
||||
| "contains"
|
||||
| "notContains"
|
||||
| "containsAny"
|
||||
| "oneOf"
|
||||
| "range";
|
||||
/** @description The field in the view to perform the search on. */
|
||||
field?: string;
|
||||
/** @description The value to search for - the type will depend on the operator in use. */
|
||||
value?:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| { [key: string]: unknown }
|
||||
| unknown[];
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
sort?: {
|
||||
/** @description The field from the table/view schema to sort on. */
|
||||
field: string;
|
||||
/**
|
||||
* @description The order in which to sort.
|
||||
* @enum {string}
|
||||
*/
|
||||
order?: "ascending" | "descending";
|
||||
/**
|
||||
* @description The type of sort to perform (by number, or by alphabetically).
|
||||
* @enum {string}
|
||||
*/
|
||||
type?: "string" | "number";
|
||||
};
|
||||
schema: {
|
||||
[key: string]:
|
||||
| {
|
||||
/** @description Defines whether the column is visible or not - rows retrieved/updated through this view will not be able to access it. */
|
||||
visible?: boolean;
|
||||
/** @description When used in combination with 'visible: true' the column will be visible in row responses but cannot be updated. */
|
||||
readonly?: boolean;
|
||||
/** @description A number defining where the column shows up in tables, lowest being first. */
|
||||
order?: number;
|
||||
/** @description A width for the column, defined in pixels - this affects rendering in tables. */
|
||||
width?: number;
|
||||
/** @description If this is a relationship column, we can set the columns we wish to include */
|
||||
column?: {
|
||||
readonly?: boolean;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* @description This column should be built from a calculation, specifying a type and field. It is important to note when a calculation is configured all non-calculation columns will be used for grouping.
|
||||
* @enum {string}
|
||||
*/
|
||||
calculationType?: "sum" | "avg" | "count" | "min" | "max";
|
||||
/** @description The field from the table to perform the calculation on. */
|
||||
field?: string;
|
||||
/** @description Can be used in tandem with the count calculation type, to count unique entries. */
|
||||
distinct?: boolean;
|
||||
};
|
||||
};
|
||||
/** @description The ID of the view. */
|
||||
id: string;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
parameters: {
|
||||
/** @description The ID of the table which this request is targeting. */
|
||||
tableId: string;
|
||||
/** @description The ID of the view which this request is targeting. */
|
||||
viewId: string;
|
||||
/** @description The ID of the row which this request is targeting. */
|
||||
rowId: string;
|
||||
/** @description The ID of the app which this request is targeting. */
|
||||
|
@ -1213,6 +1664,31 @@ export interface operations {
|
|||
};
|
||||
};
|
||||
};
|
||||
rowViewSearch: {
|
||||
parameters: {
|
||||
path: {
|
||||
/** The ID of the view which this request is targeting. */
|
||||
viewId: components["parameters"]["viewId"];
|
||||
};
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** The response will contain an array of rows that match the search parameters. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["searchOutput"];
|
||||
};
|
||||
};
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["rowSearch"];
|
||||
};
|
||||
};
|
||||
};
|
||||
/** Create a table, this could be internal or external. */
|
||||
tableCreate: {
|
||||
parameters: {
|
||||
|
@ -1409,6 +1885,118 @@ export interface operations {
|
|||
};
|
||||
};
|
||||
};
|
||||
/** Create a view, this can be against an internal or external table. */
|
||||
viewCreate: {
|
||||
parameters: {
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** Returns the created view, including the ID which has been generated for it. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["viewOutput"];
|
||||
};
|
||||
};
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["view"];
|
||||
};
|
||||
};
|
||||
};
|
||||
/** Lookup a view, this could be internal or external. */
|
||||
viewGetById: {
|
||||
parameters: {
|
||||
path: {
|
||||
/** The ID of the view which this request is targeting. */
|
||||
viewId: components["parameters"]["viewId"];
|
||||
};
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** Returns the retrieved view. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["viewOutput"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** Update a view, this can be against an internal or external table. */
|
||||
viewUpdate: {
|
||||
parameters: {
|
||||
path: {
|
||||
/** The ID of the view which this request is targeting. */
|
||||
viewId: components["parameters"]["viewId"];
|
||||
};
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** Returns the updated view. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["viewOutput"];
|
||||
};
|
||||
};
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["view"];
|
||||
};
|
||||
};
|
||||
};
|
||||
/** Delete a view, this can be against an internal or external table. */
|
||||
viewDestroy: {
|
||||
parameters: {
|
||||
path: {
|
||||
/** The ID of the view which this request is targeting. */
|
||||
viewId: components["parameters"]["viewId"];
|
||||
};
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** Returns the deleted view. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["viewOutput"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** Based on view properties (currently only name) search for views. */
|
||||
viewSearch: {
|
||||
parameters: {
|
||||
header: {
|
||||
/** The ID of the app which this request is targeting. */
|
||||
"x-budibase-app-id": components["parameters"]["appId"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** Returns the found views, based on the search parameters. */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["viewSearch"];
|
||||
};
|
||||
};
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["nameSearch"];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface external {}
|
||||
|
|
|
@ -10,119 +10,123 @@ function uniqueTableName(length?: number): string {
|
|||
.substring(0, length || 10)
|
||||
}
|
||||
|
||||
datasourceDescribe(
|
||||
{
|
||||
name: "Integration compatibility with mysql search_path",
|
||||
only: [DatabaseName.MYSQL],
|
||||
},
|
||||
({ config, dsProvider }) => {
|
||||
let rawDatasource: Datasource
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
const mainDescriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
|
||||
|
||||
const database = generator.guid()
|
||||
const database2 = generator.guid()
|
||||
if (mainDescriptions.length) {
|
||||
describe.each(mainDescriptions)(
|
||||
"/Integration compatibility with mysql search_path ($dbName)",
|
||||
({ config, dsProvider }) => {
|
||||
let rawDatasource: Datasource
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
rawDatasource = ds.rawDatasource!
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
const database = generator.guid()
|
||||
const database2 = generator.guid()
|
||||
|
||||
await client.raw(`CREATE DATABASE \`${database}\`;`)
|
||||
await client.raw(`CREATE DATABASE \`${database2}\`;`)
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
rawDatasource = ds.rawDatasource!
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
|
||||
rawDatasource.config!.database = database
|
||||
datasource = await config.api.datasource.create(rawDatasource)
|
||||
})
|
||||
await client.raw(`CREATE DATABASE \`${database}\`;`)
|
||||
await client.raw(`CREATE DATABASE \`${database2}\`;`)
|
||||
|
||||
afterAll(async () => {
|
||||
await client.raw(`DROP DATABASE \`${database}\`;`)
|
||||
await client.raw(`DROP DATABASE \`${database2}\`;`)
|
||||
})
|
||||
|
||||
it("discovers tables from any schema in search path", async () => {
|
||||
await client.schema.createTable(`${database}.table1`, table => {
|
||||
table.increments("id1").primary()
|
||||
rawDatasource.config!.database = database
|
||||
datasource = await config.api.datasource.create(rawDatasource)
|
||||
})
|
||||
const res = await config.api.datasource.info(datasource)
|
||||
expect(res.tableNames).toBeDefined()
|
||||
expect(res.tableNames).toEqual(expect.arrayContaining(["table1"]))
|
||||
})
|
||||
|
||||
it("does not mix columns from different tables", async () => {
|
||||
const repeated_table_name = "table_same_name"
|
||||
await client.schema.createTable(
|
||||
`${database}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id").primary()
|
||||
table.string("val1")
|
||||
}
|
||||
)
|
||||
await client.schema.createTable(
|
||||
`${database2}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id2").primary()
|
||||
table.string("val2")
|
||||
}
|
||||
)
|
||||
|
||||
const res = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
tablesFilter: [repeated_table_name],
|
||||
afterAll(async () => {
|
||||
await client.raw(`DROP DATABASE \`${database}\`;`)
|
||||
await client.raw(`DROP DATABASE \`${database2}\`;`)
|
||||
})
|
||||
expect(res.datasource.entities![repeated_table_name].schema).toBeDefined()
|
||||
const schema = res.datasource.entities![repeated_table_name].schema
|
||||
expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
datasourceDescribe(
|
||||
{
|
||||
name: "POST /api/datasources/:datasourceId/schema",
|
||||
only: [DatabaseName.MYSQL],
|
||||
},
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
it("discovers tables from any schema in search path", async () => {
|
||||
await client.schema.createTable(`${database}.table1`, table => {
|
||||
table.increments("id1").primary()
|
||||
})
|
||||
const res = await config.api.datasource.info(datasource)
|
||||
expect(res.tableNames).toBeDefined()
|
||||
expect(res.tableNames).toEqual(expect.arrayContaining(["table1"]))
|
||||
})
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
|
||||
let tableName: string
|
||||
beforeEach(async () => {
|
||||
tableName = uniqueTableName()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTableIfExists(tableName)
|
||||
})
|
||||
|
||||
it("recognises enum columns as options", async () => {
|
||||
const enumColumnName = "status"
|
||||
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("order_id").primary()
|
||||
table.string("customer_name", 100).notNullable()
|
||||
table.enum(
|
||||
enumColumnName,
|
||||
["pending", "processing", "shipped", "delivered", "cancelled"],
|
||||
{ useNative: true, enumName: `${tableName}_${enumColumnName}` }
|
||||
it("does not mix columns from different tables", async () => {
|
||||
const repeated_table_name = "table_same_name"
|
||||
await client.schema.createTable(
|
||||
`${database}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id").primary()
|
||||
table.string("val1")
|
||||
}
|
||||
)
|
||||
await client.schema.createTable(
|
||||
`${database2}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id2").primary()
|
||||
table.string("val2")
|
||||
}
|
||||
)
|
||||
|
||||
const res = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
tablesFilter: [repeated_table_name],
|
||||
})
|
||||
expect(
|
||||
res.datasource.entities![repeated_table_name].schema
|
||||
).toBeDefined()
|
||||
const schema = res.datasource.entities![repeated_table_name].schema
|
||||
expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
const res = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const descriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
|
||||
|
||||
const table = res.datasource.entities![tableName]
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"POST /api/datasources/:datasourceId/schema ($dbName)",
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
|
||||
expect(table).toBeDefined()
|
||||
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
||||
})
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
|
||||
let tableName: string
|
||||
beforeEach(async () => {
|
||||
tableName = uniqueTableName()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTableIfExists(tableName)
|
||||
})
|
||||
|
||||
it("recognises enum columns as options", async () => {
|
||||
const enumColumnName = "status"
|
||||
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("order_id").primary()
|
||||
table.string("customer_name", 100).notNullable()
|
||||
table.enum(
|
||||
enumColumnName,
|
||||
["pending", "processing", "shipped", "delivered", "cancelled"],
|
||||
{ useNative: true, enumName: `${tableName}_${enumColumnName}` }
|
||||
)
|
||||
})
|
||||
|
||||
const res = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
const table = res.datasource.entities![tableName]
|
||||
|
||||
expect(table).toBeDefined()
|
||||
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,283 +8,292 @@ import {
|
|||
} from "../integrations/tests/utils"
|
||||
import { Knex } from "knex"
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "postgres integrations", only: [DatabaseName.POSTGRES] },
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
const mainDescriptions = datasourceDescribe({ only: [DatabaseName.POSTGRES] })
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
if (mainDescriptions.length) {
|
||||
describe.each(mainDescriptions)(
|
||||
"/postgres integrations",
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
|
||||
afterAll(config.end)
|
||||
|
||||
describe("POST /api/datasources/:datasourceId/schema", () => {
|
||||
let tableName: string
|
||||
|
||||
beforeEach(async () => {
|
||||
tableName = generator.guid().replaceAll("-", "").substring(0, 10)
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTableIfExists(tableName)
|
||||
})
|
||||
afterAll(config.end)
|
||||
|
||||
it("recognises when a table has no primary key", async () => {
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("id", { primaryKey: false })
|
||||
describe("POST /api/datasources/:datasourceId/schema", () => {
|
||||
let tableName: string
|
||||
|
||||
beforeEach(async () => {
|
||||
tableName = generator.guid().replaceAll("-", "").substring(0, 10)
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
afterEach(async () => {
|
||||
await client.schema.dropTableIfExists(tableName)
|
||||
})
|
||||
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table must have a primary key.",
|
||||
})
|
||||
})
|
||||
it("recognises when a table has no primary key", async () => {
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("id", { primaryKey: false })
|
||||
})
|
||||
|
||||
it("recognises when a table is using a reserved column name", async () => {
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("_id").primary()
|
||||
})
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table contains invalid columns.",
|
||||
})
|
||||
})
|
||||
|
||||
it("recognises enum columns as options", async () => {
|
||||
const tableName = `orders_${generator
|
||||
.guid()
|
||||
.replaceAll("-", "")
|
||||
.substring(0, 6)}`
|
||||
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("order_id").primary()
|
||||
table.string("customer_name").notNullable()
|
||||
table.enum("status", ["pending", "processing", "shipped"], {
|
||||
useNative: true,
|
||||
enumName: `${tableName}_status`,
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table must have a primary key.",
|
||||
})
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
it("recognises when a table is using a reserved column name", async () => {
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("_id").primary()
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table contains invalid columns.",
|
||||
})
|
||||
})
|
||||
|
||||
const table = response.datasource.entities?.[tableName]
|
||||
it("recognises enum columns as options", async () => {
|
||||
const tableName = `orders_${generator
|
||||
.guid()
|
||||
.replaceAll("-", "")
|
||||
.substring(0, 6)}`
|
||||
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema["status"].type).toEqual(FieldType.OPTIONS)
|
||||
})
|
||||
})
|
||||
await client.schema.createTable(tableName, table => {
|
||||
table.increments("order_id").primary()
|
||||
table.string("customer_name").notNullable()
|
||||
table.enum("status", ["pending", "processing", "shipped"], {
|
||||
useNative: true,
|
||||
enumName: `${tableName}_status`,
|
||||
})
|
||||
})
|
||||
|
||||
describe("check custom column types", () => {
|
||||
beforeAll(async () => {
|
||||
await client.schema.createTable("binaryTable", table => {
|
||||
table.binary("id").primary()
|
||||
table.string("column1")
|
||||
table.integer("column2")
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
const table = response.datasource.entities?.[tableName]
|
||||
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema["status"].type).toEqual(FieldType.OPTIONS)
|
||||
})
|
||||
})
|
||||
|
||||
it("should handle binary columns", async () => {
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
describe("check custom column types", () => {
|
||||
beforeAll(async () => {
|
||||
await client.schema.createTable("binaryTable", table => {
|
||||
table.binary("id").primary()
|
||||
table.string("column1")
|
||||
table.integer("column2")
|
||||
})
|
||||
})
|
||||
expect(response.datasource.entities).toBeDefined()
|
||||
const table = response.datasource.entities?.["binaryTable"]
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema.id.externalType).toBe("bytea")
|
||||
const row = await config.api.row.save(table?._id!, {
|
||||
id: "1111",
|
||||
column1: "hello",
|
||||
column2: 222,
|
||||
})
|
||||
expect(row._id).toBeDefined()
|
||||
const decoded = decodeURIComponent(row._id!).replace(/'/g, '"')
|
||||
expect(JSON.parse(decoded)[0]).toBe("1111")
|
||||
})
|
||||
})
|
||||
|
||||
describe("check fetching null/not null table", () => {
|
||||
beforeAll(async () => {
|
||||
await client.schema.createTable("nullableTable", table => {
|
||||
table.increments("order_id").primary()
|
||||
table.integer("order_number").notNullable()
|
||||
it("should handle binary columns", async () => {
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
expect(response.datasource.entities).toBeDefined()
|
||||
const table = response.datasource.entities?.["binaryTable"]
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema.id.externalType).toBe("bytea")
|
||||
const row = await config.api.row.save(table?._id!, {
|
||||
id: "1111",
|
||||
column1: "hello",
|
||||
column2: 222,
|
||||
})
|
||||
expect(row._id).toBeDefined()
|
||||
const decoded = decodeURIComponent(row._id!).replace(/'/g, '"')
|
||||
expect(JSON.parse(decoded)[0]).toBe("1111")
|
||||
})
|
||||
})
|
||||
|
||||
it("should be able to change the table to allow nullable and refetch this", async () => {
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const entities = response.datasource.entities
|
||||
expect(entities).toBeDefined()
|
||||
const nullableTable = entities?.["nullableTable"]
|
||||
expect(nullableTable).toBeDefined()
|
||||
expect(
|
||||
nullableTable?.schema["order_number"].constraints?.presence
|
||||
).toEqual(true)
|
||||
|
||||
// need to perform these calls raw to the DB so that the external state of the DB differs to what Budibase
|
||||
// is aware of - therefore we can try to fetch and make sure BB updates correctly
|
||||
await client.schema.alterTable("nullableTable", table => {
|
||||
table.setNullable("order_number")
|
||||
describe("check fetching null/not null table", () => {
|
||||
beforeAll(async () => {
|
||||
await client.schema.createTable("nullableTable", table => {
|
||||
table.increments("order_id").primary()
|
||||
table.integer("order_number").notNullable()
|
||||
})
|
||||
})
|
||||
|
||||
const responseAfter = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
it("should be able to change the table to allow nullable and refetch this", async () => {
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const entities = response.datasource.entities
|
||||
expect(entities).toBeDefined()
|
||||
const nullableTable = entities?.["nullableTable"]
|
||||
expect(nullableTable).toBeDefined()
|
||||
expect(
|
||||
nullableTable?.schema["order_number"].constraints?.presence
|
||||
).toEqual(true)
|
||||
|
||||
// need to perform these calls raw to the DB so that the external state of the DB differs to what Budibase
|
||||
// is aware of - therefore we can try to fetch and make sure BB updates correctly
|
||||
await client.schema.alterTable("nullableTable", table => {
|
||||
table.setNullable("order_number")
|
||||
})
|
||||
|
||||
const responseAfter = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const entitiesAfter = responseAfter.datasource.entities
|
||||
expect(entitiesAfter).toBeDefined()
|
||||
const nullableTableAfter = entitiesAfter?.["nullableTable"]
|
||||
expect(nullableTableAfter).toBeDefined()
|
||||
expect(
|
||||
nullableTableAfter?.schema["order_number"].constraints?.presence
|
||||
).toBeUndefined()
|
||||
})
|
||||
const entitiesAfter = responseAfter.datasource.entities
|
||||
expect(entitiesAfter).toBeDefined()
|
||||
const nullableTableAfter = entitiesAfter?.["nullableTable"]
|
||||
expect(nullableTableAfter).toBeDefined()
|
||||
expect(
|
||||
nullableTableAfter?.schema["order_number"].constraints?.presence
|
||||
).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("money field 💰", () => {
|
||||
const tableName = "moneytable"
|
||||
let table: Table
|
||||
describe("money field 💰", () => {
|
||||
const tableName = "moneytable"
|
||||
let table: Table
|
||||
|
||||
beforeAll(async () => {
|
||||
await client.raw(`
|
||||
beforeAll(async () => {
|
||||
await client.raw(`
|
||||
CREATE TABLE ${tableName} (
|
||||
id serial PRIMARY KEY,
|
||||
price money
|
||||
)
|
||||
`)
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
table = response.datasource.entities![tableName]
|
||||
})
|
||||
|
||||
it("should be able to import a money field", async () => {
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema.price.type).toBe(FieldType.NUMBER)
|
||||
})
|
||||
|
||||
it("should be able to search a money field", async () => {
|
||||
await config.api.row.bulkImport(table._id!, {
|
||||
rows: [{ price: 200 }, { price: 300 }],
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
table = response.datasource.entities![tableName]
|
||||
})
|
||||
|
||||
const { rows } = await config.api.row.search(table._id!, {
|
||||
query: {
|
||||
equal: {
|
||||
price: 200,
|
||||
it("should be able to import a money field", async () => {
|
||||
expect(table).toBeDefined()
|
||||
expect(table?.schema.price.type).toBe(FieldType.NUMBER)
|
||||
})
|
||||
|
||||
it("should be able to search a money field", async () => {
|
||||
await config.api.row.bulkImport(table._id!, {
|
||||
rows: [{ price: 200 }, { price: 300 }],
|
||||
})
|
||||
|
||||
const { rows } = await config.api.row.search(table._id!, {
|
||||
query: {
|
||||
equal: {
|
||||
price: 200,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(rows).toHaveLength(1)
|
||||
expect(rows[0].price).toBe("200.00")
|
||||
})
|
||||
|
||||
it("should be able to update a money field", async () => {
|
||||
let row = await config.api.row.save(table._id!, { price: 200 })
|
||||
expect(row.price).toBe("200.00")
|
||||
|
||||
row = await config.api.row.save(table._id!, { ...row, price: 300 })
|
||||
expect(row.price).toBe("300.00")
|
||||
|
||||
row = await config.api.row.save(table._id!, {
|
||||
...row,
|
||||
price: "400.00",
|
||||
})
|
||||
expect(row.price).toBe("400.00")
|
||||
})
|
||||
expect(rows).toHaveLength(1)
|
||||
expect(rows[0].price).toBe("200.00")
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it("should be able to update a money field", async () => {
|
||||
let row = await config.api.row.save(table._id!, { price: 200 })
|
||||
expect(row.price).toBe("200.00")
|
||||
const descriptions = datasourceDescribe({ only: [DatabaseName.POSTGRES] })
|
||||
|
||||
row = await config.api.row.save(table._id!, { ...row, price: 300 })
|
||||
expect(row.price).toBe("300.00")
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"Integration compatibility with postgres search_path",
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
let schema1: string
|
||||
let schema2: string
|
||||
|
||||
row = await config.api.row.save(table._id!, { ...row, price: "400.00" })
|
||||
expect(row.price).toBe("400.00")
|
||||
})
|
||||
})
|
||||
beforeEach(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
const rawDatasource = ds.rawDatasource!
|
||||
|
||||
schema1 = generator.guid().replaceAll("-", "")
|
||||
schema2 = generator.guid().replaceAll("-", "")
|
||||
|
||||
client = await knexClient(rawDatasource)
|
||||
|
||||
await client.schema.createSchema(schema1)
|
||||
await client.schema.createSchema(schema2)
|
||||
|
||||
rawDatasource.config!.schema = `${schema1}, ${schema2}`
|
||||
|
||||
client = await knexClient(rawDatasource)
|
||||
datasource = await config.api.datasource.create(rawDatasource)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropSchema(schema1, true)
|
||||
await client.schema.dropSchema(schema2, true)
|
||||
})
|
||||
|
||||
it("discovers tables from any schema in search path", async () => {
|
||||
await client.schema.createTable(`${schema1}.table1`, table => {
|
||||
table.increments("id1").primary()
|
||||
})
|
||||
|
||||
await client.schema.createTable(`${schema2}.table2`, table => {
|
||||
table.increments("id2").primary()
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.info(datasource)
|
||||
expect(response.tableNames).toBeDefined()
|
||||
expect(response.tableNames).toEqual(
|
||||
expect.arrayContaining(["table1", "table2"])
|
||||
)
|
||||
})
|
||||
|
||||
it("does not mix columns from different tables", async () => {
|
||||
const repeated_table_name = "table_same_name"
|
||||
|
||||
await client.schema.createTable(
|
||||
`${schema1}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id").primary()
|
||||
table.string("val1")
|
||||
}
|
||||
)
|
||||
|
||||
await client.schema.createTable(
|
||||
`${schema2}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id2").primary()
|
||||
table.string("val2")
|
||||
}
|
||||
)
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
tablesFilter: [repeated_table_name],
|
||||
})
|
||||
expect(
|
||||
response.datasource.entities?.[repeated_table_name].schema
|
||||
).toBeDefined()
|
||||
const schema =
|
||||
response.datasource.entities?.[repeated_table_name].schema
|
||||
expect(Object.keys(schema || {}).sort()).toEqual(["id", "val1"])
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
datasourceDescribe(
|
||||
{
|
||||
name: "Integration compatibility with postgres search_path",
|
||||
only: [DatabaseName.POSTGRES],
|
||||
},
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let client: Knex
|
||||
let schema1: string
|
||||
let schema2: string
|
||||
|
||||
beforeEach(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
const rawDatasource = ds.rawDatasource!
|
||||
|
||||
schema1 = generator.guid().replaceAll("-", "")
|
||||
schema2 = generator.guid().replaceAll("-", "")
|
||||
|
||||
client = await knexClient(rawDatasource)
|
||||
|
||||
await client.schema.createSchema(schema1)
|
||||
await client.schema.createSchema(schema2)
|
||||
|
||||
rawDatasource.config!.schema = `${schema1}, ${schema2}`
|
||||
|
||||
client = await knexClient(rawDatasource)
|
||||
datasource = await config.api.datasource.create(rawDatasource)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await client.schema.dropSchema(schema1, true)
|
||||
await client.schema.dropSchema(schema2, true)
|
||||
})
|
||||
|
||||
it("discovers tables from any schema in search path", async () => {
|
||||
await client.schema.createTable(`${schema1}.table1`, table => {
|
||||
table.increments("id1").primary()
|
||||
})
|
||||
|
||||
await client.schema.createTable(`${schema2}.table2`, table => {
|
||||
table.increments("id2").primary()
|
||||
})
|
||||
|
||||
const response = await config.api.datasource.info(datasource)
|
||||
expect(response.tableNames).toBeDefined()
|
||||
expect(response.tableNames).toEqual(
|
||||
expect.arrayContaining(["table1", "table2"])
|
||||
)
|
||||
})
|
||||
|
||||
it("does not mix columns from different tables", async () => {
|
||||
const repeated_table_name = "table_same_name"
|
||||
|
||||
await client.schema.createTable(
|
||||
`${schema1}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id").primary()
|
||||
table.string("val1")
|
||||
}
|
||||
)
|
||||
|
||||
await client.schema.createTable(
|
||||
`${schema2}.${repeated_table_name}`,
|
||||
table => {
|
||||
table.increments("id2").primary()
|
||||
table.string("val2")
|
||||
}
|
||||
)
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
tablesFilter: [repeated_table_name],
|
||||
})
|
||||
expect(
|
||||
response.datasource.entities?.[repeated_table_name].schema
|
||||
).toBeDefined()
|
||||
const schema = response.datasource.entities?.[repeated_table_name].schema
|
||||
expect(Object.keys(schema || {}).sort()).toEqual(["id", "val1"])
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -281,8 +281,14 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
|||
case MSSQLConfigAuthType.NTLM: {
|
||||
const { domain, trustServerCertificate } =
|
||||
this.config.ntlmConfig || {}
|
||||
|
||||
if (!domain) {
|
||||
throw Error("Domain must be provided for NTLM config")
|
||||
}
|
||||
|
||||
clientCfg.authentication = {
|
||||
type: "ntlm",
|
||||
// @ts-expect-error - username and password not required for NTLM
|
||||
options: {
|
||||
domain,
|
||||
},
|
||||
|
|
|
@ -6,7 +6,8 @@ import {
|
|||
QueryType,
|
||||
SqlQuery,
|
||||
} from "@budibase/types"
|
||||
import { Snowflake } from "snowflake-promise"
|
||||
import snowflakeSdk, { SnowflakeError } from "snowflake-sdk"
|
||||
import { promisify } from "util"
|
||||
|
||||
interface SnowflakeConfig {
|
||||
account: string
|
||||
|
@ -71,11 +72,52 @@ const SCHEMA: Integration = {
|
|||
},
|
||||
}
|
||||
|
||||
class SnowflakeIntegration {
|
||||
private client: Snowflake
|
||||
class SnowflakePromise {
|
||||
config: SnowflakeConfig
|
||||
client?: snowflakeSdk.Connection
|
||||
|
||||
constructor(config: SnowflakeConfig) {
|
||||
this.client = new Snowflake(config)
|
||||
this.config = config
|
||||
}
|
||||
|
||||
async connect() {
|
||||
if (this.client?.isUp()) return
|
||||
|
||||
this.client = snowflakeSdk.createConnection(this.config)
|
||||
const connectAsync = promisify(this.client.connect.bind(this.client))
|
||||
return connectAsync()
|
||||
}
|
||||
|
||||
async execute(sql: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.client) {
|
||||
throw Error(
|
||||
"No snowflake client present to execute query. Run connect() first to initialise."
|
||||
)
|
||||
}
|
||||
|
||||
this.client.execute({
|
||||
sqlText: sql,
|
||||
complete: function (
|
||||
err: SnowflakeError | undefined,
|
||||
statementExecuted: any,
|
||||
rows: any
|
||||
) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
resolve(rows)
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class SnowflakeIntegration {
|
||||
private client: SnowflakePromise
|
||||
|
||||
constructor(config: SnowflakeConfig) {
|
||||
this.client = new SnowflakePromise(config)
|
||||
}
|
||||
|
||||
async testConnection(): Promise<ConnectionInfo> {
|
||||
|
|
|
@ -35,7 +35,6 @@ const providers: Record<DatabaseName, DatasourceProvider> = {
|
|||
}
|
||||
|
||||
export interface DatasourceDescribeOpts {
|
||||
name: string
|
||||
only?: DatabaseName[]
|
||||
exclude?: DatabaseName[]
|
||||
}
|
||||
|
@ -102,16 +101,12 @@ function createDummyTest() {
|
|||
})
|
||||
}
|
||||
|
||||
export function datasourceDescribe(
|
||||
opts: DatasourceDescribeOpts,
|
||||
cb: (args: DatasourceDescribeReturn) => void
|
||||
) {
|
||||
export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
||||
if (process.env.DATASOURCE === "none") {
|
||||
createDummyTest()
|
||||
return
|
||||
}
|
||||
|
||||
const { name, only, exclude } = opts
|
||||
const { only, exclude } = opts
|
||||
|
||||
if (only && exclude) {
|
||||
throw new Error("you can only supply one of 'only' or 'exclude'")
|
||||
|
@ -130,36 +125,28 @@ export function datasourceDescribe(
|
|||
|
||||
if (databases.length === 0) {
|
||||
createDummyTest()
|
||||
return
|
||||
}
|
||||
|
||||
describe.each(databases)(name, name => {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
afterAll(() => {
|
||||
config.end()
|
||||
})
|
||||
|
||||
cb({
|
||||
name,
|
||||
config,
|
||||
dsProvider: () => createDatasources(config, name),
|
||||
isInternal: name === DatabaseName.SQS,
|
||||
isExternal: name !== DatabaseName.SQS,
|
||||
isSql: [
|
||||
DatabaseName.MARIADB,
|
||||
DatabaseName.MYSQL,
|
||||
DatabaseName.POSTGRES,
|
||||
DatabaseName.SQL_SERVER,
|
||||
DatabaseName.ORACLE,
|
||||
].includes(name),
|
||||
isMySQL: name === DatabaseName.MYSQL,
|
||||
isPostgres: name === DatabaseName.POSTGRES,
|
||||
isMongodb: name === DatabaseName.MONGODB,
|
||||
isMSSQL: name === DatabaseName.SQL_SERVER,
|
||||
isOracle: name === DatabaseName.ORACLE,
|
||||
})
|
||||
})
|
||||
const config = new TestConfiguration()
|
||||
return databases.map(dbName => ({
|
||||
dbName,
|
||||
config,
|
||||
dsProvider: () => createDatasources(config, dbName),
|
||||
isInternal: dbName === DatabaseName.SQS,
|
||||
isExternal: dbName !== DatabaseName.SQS,
|
||||
isSql: [
|
||||
DatabaseName.MARIADB,
|
||||
DatabaseName.MYSQL,
|
||||
DatabaseName.POSTGRES,
|
||||
DatabaseName.SQL_SERVER,
|
||||
DatabaseName.ORACLE,
|
||||
].includes(dbName),
|
||||
isMySQL: dbName === DatabaseName.MYSQL,
|
||||
isPostgres: dbName === DatabaseName.POSTGRES,
|
||||
isMongodb: dbName === DatabaseName.MONGODB,
|
||||
isMSSQL: dbName === DatabaseName.SQL_SERVER,
|
||||
isOracle: dbName === DatabaseName.ORACLE,
|
||||
}))
|
||||
}
|
||||
|
||||
function getDatasource(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { constants, utils } from "@budibase/backend-core"
|
||||
import { BBContext } from "@budibase/types"
|
||||
import { Ctx } from "@budibase/types"
|
||||
|
||||
export default function ({ requiresAppId }: { requiresAppId?: boolean } = {}) {
|
||||
return async (ctx: BBContext, next: any) => {
|
||||
return async (ctx: Ctx, next: any) => {
|
||||
const appId = await utils.getAppIdFromCtx(ctx)
|
||||
if (requiresAppId && !appId) {
|
||||
ctx.throw(
|
||||
|
|
|
@ -19,202 +19,206 @@ 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.
|
||||
datasourceDescribe(
|
||||
{ name: "search sdk (%s)", exclude: [DatabaseName.MONGODB] },
|
||||
({ config, dsProvider, isInternal }) => {
|
||||
let datasource: Datasource | undefined
|
||||
let table: Table
|
||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
if (descriptions.length) {
|
||||
describe.each(descriptions)(
|
||||
"search sdk ($dbName)",
|
||||
({ config, dsProvider, isInternal }) => {
|
||||
let datasource: Datasource | undefined
|
||||
let table: Table
|
||||
|
||||
beforeEach(async () => {
|
||||
const idFieldSchema: NumberFieldMetadata | AutoColumnFieldMetadata =
|
||||
isInternal
|
||||
? {
|
||||
name: "id",
|
||||
type: FieldType.AUTO,
|
||||
subtype: AutoFieldSubType.AUTO_ID,
|
||||
autocolumn: true,
|
||||
}
|
||||
: {
|
||||
name: "id",
|
||||
type: FieldType.NUMBER,
|
||||
autocolumn: true,
|
||||
}
|
||||
|
||||
table = await config.api.table.save(
|
||||
tableForDatasource(datasource, {
|
||||
primary: ["id"],
|
||||
schema: {
|
||||
id: idFieldSchema,
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
surname: {
|
||||
name: "surname",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
age: {
|
||||
name: "age",
|
||||
type: FieldType.NUMBER,
|
||||
},
|
||||
address: {
|
||||
name: "address",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await config.api.row.save(table._id!, {
|
||||
name: generator.first(),
|
||||
surname: generator.last(),
|
||||
age: generator.age(),
|
||||
address: generator.address(),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
config.end()
|
||||
})
|
||||
|
||||
it("querying by fields will always return data attribute columns", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const { rows } = await search({
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
fields: ["name", "age"],
|
||||
})
|
||||
|
||||
expect(rows).toHaveLength(10)
|
||||
for (const row of rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).toContain("age")
|
||||
expect(keys).not.toContain("surname")
|
||||
expect(keys).not.toContain("address")
|
||||
}
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
})
|
||||
|
||||
!isInternal &&
|
||||
it("will decode _id in oneOf query", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {
|
||||
oneOf: {
|
||||
_id: ["%5B1%5D", "%5B4%5D", "%5B8%5D"],
|
||||
beforeEach(async () => {
|
||||
const idFieldSchema: NumberFieldMetadata | AutoColumnFieldMetadata =
|
||||
isInternal
|
||||
? {
|
||||
name: "id",
|
||||
type: FieldType.AUTO,
|
||||
subtype: AutoFieldSubType.AUTO_ID,
|
||||
autocolumn: true,
|
||||
}
|
||||
: {
|
||||
name: "id",
|
||||
type: FieldType.NUMBER,
|
||||
autocolumn: true,
|
||||
}
|
||||
|
||||
table = await config.api.table.save(
|
||||
tableForDatasource(datasource, {
|
||||
primary: ["id"],
|
||||
schema: {
|
||||
id: idFieldSchema,
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
surname: {
|
||||
name: "surname",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
age: {
|
||||
name: "age",
|
||||
type: FieldType.NUMBER,
|
||||
},
|
||||
address: {
|
||||
name: "address",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.rows).toHaveLength(3)
|
||||
expect(result.rows.map(row => row.id)).toEqual(
|
||||
expect.arrayContaining([1, 4, 8])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("does not allow accessing hidden fields", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await config.api.table.save({
|
||||
...table,
|
||||
schema: {
|
||||
...table.schema,
|
||||
name: {
|
||||
...table.schema.name,
|
||||
visible: true,
|
||||
},
|
||||
age: {
|
||||
...table.schema.age,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
})
|
||||
expect(result.rows).toHaveLength(10)
|
||||
for (const row of result.rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).toContain("surname")
|
||||
expect(keys).toContain("address")
|
||||
expect(keys).not.toContain("age")
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await config.api.row.save(table._id!, {
|
||||
name: generator.first(),
|
||||
surname: generator.last(),
|
||||
age: generator.age(),
|
||||
address: generator.address(),
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("does not allow accessing hidden fields even if requested", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await config.api.table.save({
|
||||
...table,
|
||||
schema: {
|
||||
...table.schema,
|
||||
name: {
|
||||
...table.schema.name,
|
||||
visible: true,
|
||||
},
|
||||
age: {
|
||||
...table.schema.age,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
fields: ["name", "age"],
|
||||
})
|
||||
expect(result.rows).toHaveLength(10)
|
||||
for (const row of result.rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).not.toContain("age")
|
||||
expect(keys).not.toContain("surname")
|
||||
expect(keys).not.toContain("address")
|
||||
}
|
||||
afterAll(async () => {
|
||||
config.end()
|
||||
})
|
||||
})
|
||||
|
||||
it.each([
|
||||
[["id", "name", "age"], 3],
|
||||
[["name", "age"], 10],
|
||||
])(
|
||||
"cannot query by non search fields (fields: %s)",
|
||||
async (queryFields, expectedRows) => {
|
||||
it("querying by fields will always return data attribute columns", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const { rows } = await search({
|
||||
tableId: table._id!,
|
||||
query: {
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
$and: {
|
||||
conditions: [
|
||||
{ range: { id: { low: 2, high: 4 } } },
|
||||
{ range: { id: { low: 3, high: 5 } } },
|
||||
],
|
||||
},
|
||||
},
|
||||
{ equal: { id: 7 } },
|
||||
],
|
||||
},
|
||||
},
|
||||
fields: queryFields,
|
||||
query: {},
|
||||
fields: ["name", "age"],
|
||||
})
|
||||
|
||||
expect(rows).toHaveLength(expectedRows)
|
||||
expect(rows).toHaveLength(10)
|
||||
for (const row of rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).toContain("age")
|
||||
expect(keys).not.toContain("surname")
|
||||
expect(keys).not.toContain("address")
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
!isInternal &&
|
||||
it("will decode _id in oneOf query", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {
|
||||
oneOf: {
|
||||
_id: ["%5B1%5D", "%5B4%5D", "%5B8%5D"],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.rows).toHaveLength(3)
|
||||
expect(result.rows.map(row => row.id)).toEqual(
|
||||
expect.arrayContaining([1, 4, 8])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("does not allow accessing hidden fields", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await config.api.table.save({
|
||||
...table,
|
||||
schema: {
|
||||
...table.schema,
|
||||
name: {
|
||||
...table.schema.name,
|
||||
visible: true,
|
||||
},
|
||||
age: {
|
||||
...table.schema.age,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
})
|
||||
expect(result.rows).toHaveLength(10)
|
||||
for (const row of result.rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).toContain("surname")
|
||||
expect(keys).toContain("address")
|
||||
expect(keys).not.toContain("age")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("does not allow accessing hidden fields even if requested", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await config.api.table.save({
|
||||
...table,
|
||||
schema: {
|
||||
...table.schema,
|
||||
name: {
|
||||
...table.schema.name,
|
||||
visible: true,
|
||||
},
|
||||
age: {
|
||||
...table.schema.age,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
const result = await search({
|
||||
tableId: table._id!,
|
||||
query: {},
|
||||
fields: ["name", "age"],
|
||||
})
|
||||
expect(result.rows).toHaveLength(10)
|
||||
for (const row of result.rows) {
|
||||
const keys = Object.keys(row)
|
||||
expect(keys).toContain("name")
|
||||
expect(keys).not.toContain("age")
|
||||
expect(keys).not.toContain("surname")
|
||||
expect(keys).not.toContain("address")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it.each([
|
||||
[["id", "name", "age"], 3],
|
||||
[["name", "age"], 10],
|
||||
])(
|
||||
"cannot query by non search fields (fields: %s)",
|
||||
async (queryFields, expectedRows) => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const { rows } = await search({
|
||||
tableId: table._id!,
|
||||
query: {
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
$and: {
|
||||
conditions: [
|
||||
{ range: { id: { low: 2, high: 4 } } },
|
||||
{ range: { id: { low: 3, high: 5 } } },
|
||||
],
|
||||
},
|
||||
},
|
||||
{ equal: { id: 7 } },
|
||||
],
|
||||
},
|
||||
},
|
||||
fields: queryFields,
|
||||
})
|
||||
|
||||
expect(rows).toHaveLength(expectedRows)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -78,8 +78,11 @@ export async function getAllInternalTables(db?: Database): Promise<Table[]> {
|
|||
}
|
||||
|
||||
async function getAllExternalTables(): Promise<Table[]> {
|
||||
// this is all datasources, we'll need to filter out internal
|
||||
const datasources = await sdk.datasources.fetch({ enriched: true })
|
||||
const allEntities = datasources.map(datasource => datasource.entities)
|
||||
const allEntities = datasources
|
||||
.filter(datasource => datasource._id !== INTERNAL_TABLE_SOURCE_ID)
|
||||
.map(datasource => datasource.entities)
|
||||
let final: Table[] = []
|
||||
for (let entities of allEntities) {
|
||||
if (entities) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import { isExternalTableID } from "../../../integrations/utils"
|
|||
import * as internal from "./internal"
|
||||
import * as external from "./external"
|
||||
import sdk from "../../../sdk"
|
||||
import { ensureQueryUISet } from "./utils"
|
||||
|
||||
function pickApi(tableId: any) {
|
||||
if (isExternalTableID(tableId)) {
|
||||
|
@ -44,6 +45,24 @@ export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
|
|||
return pickApi(tableId).getEnriched(viewId)
|
||||
}
|
||||
|
||||
export async function getAllEnriched(): Promise<ViewV2Enriched[]> {
|
||||
const tables = await sdk.tables.getAllTables()
|
||||
let views: ViewV2Enriched[] = []
|
||||
for (let table of tables) {
|
||||
if (!table.views || Object.keys(table.views).length === 0) {
|
||||
continue
|
||||
}
|
||||
const v2Views = Object.values(table.views).filter(isV2)
|
||||
const enrichedViews = await Promise.all(
|
||||
v2Views.map(view =>
|
||||
enrichSchema(ensureQueryUISet(view), table.schema, tables)
|
||||
)
|
||||
)
|
||||
views = views.concat(enrichedViews)
|
||||
}
|
||||
return views
|
||||
}
|
||||
|
||||
export async function getTable(view: string | ViewV2): Promise<Table> {
|
||||
const viewId = typeof view === "string" ? view : view.id
|
||||
const cached = context.getTableForView(viewId)
|
||||
|
@ -333,13 +352,19 @@ export function allowedFields(
|
|||
|
||||
export async function enrichSchema(
|
||||
view: ViewV2,
|
||||
tableSchema: TableSchema
|
||||
tableSchema: TableSchema,
|
||||
tables?: Table[]
|
||||
): Promise<ViewV2Enriched> {
|
||||
async function populateRelTableSchema(
|
||||
tableId: string,
|
||||
viewFields: Record<string, RelationSchemaField>
|
||||
) {
|
||||
const relTable = await sdk.tables.getTable(tableId)
|
||||
let relTable = tables
|
||||
? tables?.find(t => t._id === tableId)
|
||||
: await sdk.tables.getTable(tableId)
|
||||
if (!relTable) {
|
||||
throw new Error("Cannot enrich relationship, table not found")
|
||||
}
|
||||
const result: Record<string, ViewV2ColumnEnriched> = {}
|
||||
for (const relTableFieldName of Object.keys(relTable.schema)) {
|
||||
const relTableField = relTable.schema[relTableFieldName]
|
||||
|
|
|
@ -28,6 +28,7 @@ import Koa from "koa"
|
|||
import { Server } from "http"
|
||||
import { AddressInfo } from "net"
|
||||
import fs from "fs"
|
||||
import bson from "bson"
|
||||
|
||||
let STARTUP_RAN = false
|
||||
|
||||
|
@ -193,6 +194,10 @@ export async function startup(
|
|||
})
|
||||
}
|
||||
|
||||
if (coreEnv.BSON_BUFFER_SIZE) {
|
||||
bson.setInternalBufferSize(coreEnv.BSON_BUFFER_SIZE)
|
||||
}
|
||||
|
||||
console.log("Initialising JS runner")
|
||||
jsRunner.init()
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
SearchViewRowRequest,
|
||||
PaginatedSearchRowResponse,
|
||||
ViewResponseEnriched,
|
||||
ViewFetchResponseEnriched,
|
||||
} from "@budibase/types"
|
||||
import { Expectations, TestAPI } from "./base"
|
||||
|
||||
|
@ -49,6 +50,12 @@ export class ViewV2API extends TestAPI {
|
|||
.data
|
||||
}
|
||||
|
||||
fetch = async (expectations?: Expectations) => {
|
||||
return await this._get<ViewFetchResponseEnriched>(`/api/v2/views`, {
|
||||
expectations,
|
||||
})
|
||||
}
|
||||
|
||||
search = async (
|
||||
viewId: string,
|
||||
params?: SearchViewRowRequest,
|
||||
|
|
|
@ -136,21 +136,23 @@ class QueryRunner {
|
|||
pagination = output.pagination
|
||||
}
|
||||
|
||||
// transform as required
|
||||
if (transformer) {
|
||||
// We avoid invoking the transformer if it's trivial because there is a cost
|
||||
// to passing data in and out of the isolate, especially for MongoDB where
|
||||
// we have to bson serialise/deserialise the data.
|
||||
const hasTransformer =
|
||||
transformer != null &&
|
||||
transformer.length > 0 &&
|
||||
transformer.trim() !== "return data" &&
|
||||
transformer.trim() !== "return data;"
|
||||
|
||||
if (transformer && hasTransformer) {
|
||||
transformer = iifeWrapper(transformer)
|
||||
let vm = new IsolatedVM()
|
||||
if (datasource.source === SourceName.MONGODB) {
|
||||
vm = vm.withParsingBson(rows)
|
||||
}
|
||||
|
||||
const ctx = {
|
||||
data: rows,
|
||||
params: enrichedParameters,
|
||||
}
|
||||
if (transformer != null) {
|
||||
rows = vm.withContext(ctx, () => vm.execute(transformer!))
|
||||
}
|
||||
const ctx = { data: rows, params: enrichedParameters }
|
||||
rows = vm.withContext(ctx, () => vm.execute(transformer!))
|
||||
}
|
||||
|
||||
// if the request fails we retry once, invalidating the cached value
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import jimp from "jimp"
|
||||
import { Jimp } from "jimp"
|
||||
|
||||
const FORMATS = {
|
||||
IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
|
||||
|
@ -6,8 +6,8 @@ const FORMATS = {
|
|||
|
||||
function processImage(file: { path: string }) {
|
||||
// this will overwrite the temp file
|
||||
return jimp.read(file.path).then(img => {
|
||||
return img.resize(300, jimp.AUTO).write(file.path)
|
||||
return Jimp.read(file.path).then(img => {
|
||||
return img.resize({ w: 256 }).write(file.path as `${string}.${string}`)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"extends": "./tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["es2020", "dom"],
|
||||
"composite": true,
|
||||
"baseUrl": "."
|
||||
},
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
*
|
||||
!dist/**/*
|
||||
dist/tsconfig.build.tsbuildinfo
|
||||
!package.json
|
|
@ -4,7 +4,7 @@
|
|||
"description": "Handlebars wrapper for Budibase templating.",
|
||||
"main": "dist/bundle.cjs",
|
||||
"module": "dist/bundle.mjs",
|
||||
"types": "src/index.ts",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MPL-2.0",
|
||||
"exports": {
|
||||
".": {
|
||||
|
@ -12,12 +12,8 @@
|
|||
"import": "./dist/bundle.mjs"
|
||||
},
|
||||
"./package.json": "./package.json",
|
||||
"./iife": "./src/iife.js"
|
||||
"./iife": "./dist/iife.mjs"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc --emitDeclarationOnly && rollup -c",
|
||||
"dev": "rollup -cw",
|
||||
|
|
|
@ -10,8 +10,8 @@ import inject from "@rollup/plugin-inject"
|
|||
|
||||
const production = !process.env.ROLLUP_WATCH
|
||||
|
||||
const config = (format, outputFile) => ({
|
||||
input: "src/index.ts",
|
||||
const config = (input, outputFile, format) => ({
|
||||
input,
|
||||
output: {
|
||||
sourcemap: !production,
|
||||
format,
|
||||
|
@ -42,6 +42,7 @@ const config = (format, outputFile) => ({
|
|||
})
|
||||
|
||||
export default [
|
||||
config("cjs", "./dist/bundle.cjs"),
|
||||
config("esm", "./dist/bundle.mjs"),
|
||||
config("src/index.ts", "./dist/bundle.cjs", "cjs"),
|
||||
config("src/index.ts", "./dist/bundle.mjs", "esm"),
|
||||
config("src/iife.ts", "./dist/iife.mjs", "esm"),
|
||||
]
|
||||
|
|
|
@ -9,6 +9,10 @@ export interface ViewResponseEnriched {
|
|||
data: ViewV2Enriched
|
||||
}
|
||||
|
||||
export interface ViewFetchResponseEnriched {
|
||||
data: ViewV2Enriched[]
|
||||
}
|
||||
|
||||
export interface CreateViewRequest extends Omit<ViewV2, "version" | "id"> {}
|
||||
|
||||
export interface UpdateViewRequest extends ViewV2 {}
|
||||
|
|
|
@ -101,6 +101,10 @@ export interface ViewV2 {
|
|||
schema?: ViewV2Schema
|
||||
}
|
||||
|
||||
export interface PublicAPIView extends Omit<ViewV2, "query" | "queryUI"> {
|
||||
query?: UISearchFilter
|
||||
}
|
||||
|
||||
export type ViewV2Schema = Record<string, ViewFieldMetadata>
|
||||
|
||||
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
|
||||
|
|
|
@ -8,7 +8,7 @@ export interface RowValue {
|
|||
export interface RowResponse<T extends Document | RowValue> {
|
||||
id: string
|
||||
key: string
|
||||
error: string
|
||||
error?: string
|
||||
value: T
|
||||
doc?: T
|
||||
}
|
||||
|
|
|
@ -163,8 +163,8 @@ export interface Database {
|
|||
viewName: string,
|
||||
params: DatabaseQueryOpts
|
||||
): Promise<AllDocsResponse<T>>
|
||||
destroy(): Promise<Nano.OkResponse | void>
|
||||
compact(): Promise<Nano.OkResponse | void>
|
||||
destroy(): Promise<Nano.OkResponse>
|
||||
compact(): Promise<Nano.OkResponse>
|
||||
// these are all PouchDB related functions that are rarely used - in future
|
||||
// should be replaced by better typed/non-pouch implemented methods
|
||||
dump(stream: Writable, opts?: DatabaseDumpOpts): Promise<any>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"build": "node ../../scripts/build.js",
|
||||
"postbuild": "copyfiles -f ../../yarn.lock ./dist/",
|
||||
"check:types": "tsc -p tsconfig.json --noEmit --paths null --target es2020",
|
||||
"check:dependencies": "node ../../scripts/depcheck.js",
|
||||
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
||||
"run:docker": "node dist/index.js",
|
||||
"debug": "yarn build && node --expose-gc --inspect=9223 dist/index.js",
|
||||
|
@ -39,20 +40,24 @@
|
|||
"dependencies": {
|
||||
"@budibase/backend-core": "0.0.0",
|
||||
"@budibase/pro": "0.0.0",
|
||||
"@budibase/shared-core": "0.0.0",
|
||||
"@budibase/string-templates": "0.0.0",
|
||||
"@budibase/types": "0.0.0",
|
||||
"@koa/router": "8.0.8",
|
||||
"@koa/router": "13.1.0",
|
||||
"@techpass/passport-openidconnect": "0.3.3",
|
||||
"@types/global-agent": "2.1.1",
|
||||
"aws-sdk": "2.1030.0",
|
||||
"aws-sdk": "2.1692.0",
|
||||
"bcrypt": "5.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bull": "4.10.1",
|
||||
"dd-trace": "5.2.0",
|
||||
"dd-trace": "5.26.0",
|
||||
"dotenv": "8.6.0",
|
||||
"email-validator": "^2.0.4",
|
||||
"global-agent": "3.0.0",
|
||||
"ical-generator": "4.1.0",
|
||||
"joi": "17.6.0",
|
||||
"jsonwebtoken": "9.0.2",
|
||||
"knex": "2.4.2",
|
||||
"koa": "2.13.4",
|
||||
"koa-body": "4.2.0",
|
||||
"koa-compress": "4.0.1",
|
||||
|
@ -69,16 +74,18 @@
|
|||
"pouchdb": "7.3.0",
|
||||
"pouchdb-all-dbs": "1.1.1",
|
||||
"server-destroy": "1.0.1",
|
||||
"knex": "2.4.2"
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/types": "^29.6.3",
|
||||
"@swc/core": "1.3.71",
|
||||
"@swc/jest": "0.2.27",
|
||||
"@types/jest": "29.5.5",
|
||||
"@types/jsonwebtoken": "9.0.3",
|
||||
"@types/koa": "2.13.4",
|
||||
"@types/koa__router": "8.0.8",
|
||||
"@types/koa__router": "12.0.4",
|
||||
"@types/lodash": "4.14.200",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/node-fetch": "2.6.4",
|
||||
"@types/server-destroy": "1.0.1",
|
||||
"@types/supertest": "2.0.14",
|
||||
|
@ -87,6 +94,7 @@
|
|||
"nock": "^13.5.4",
|
||||
"nodemon": "2.0.15",
|
||||
"rimraf": "3.0.2",
|
||||
"superagent": "^10.1.1",
|
||||
"supertest": "6.3.3",
|
||||
"timekeeper": "2.2.0",
|
||||
"typescript": "5.5.2",
|
||||
|
|
|
@ -40,6 +40,8 @@ import {
|
|||
import { checkAnyUserExists } from "../../../utilities/users"
|
||||
import { isEmailConfigured } from "../../../utilities/email"
|
||||
import { BpmStatusKey, BpmStatusValue, utils } from "@budibase/shared-core"
|
||||
import emailValidator from "email-validator"
|
||||
import crypto from "crypto"
|
||||
|
||||
const MAX_USERS_UPLOAD_LIMIT = 1000
|
||||
|
||||
|
@ -299,6 +301,10 @@ export const find = async (ctx: any) => {
|
|||
|
||||
export const tenantUserLookup = async (ctx: any) => {
|
||||
const id = ctx.params.id
|
||||
// is email, check its valid
|
||||
if (id.includes("@") && !emailValidator.validate(id)) {
|
||||
ctx.throw(400, `${id} is not a valid email address to lookup.`)
|
||||
}
|
||||
const user = await userSdk.core.getFirstPlatformUser(id)
|
||||
if (user) {
|
||||
ctx.body = user
|
||||
|
|
|
@ -99,6 +99,7 @@ export default server.listen(parseInt(env.PORT || "4002"), async () => {
|
|||
startupLog = `${startupLog} - environment: "${env.BUDIBASE_ENVIRONMENT}"`
|
||||
}
|
||||
console.log(startupLog)
|
||||
|
||||
await initPro()
|
||||
await redis.clients.init()
|
||||
features.init()
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/node
|
||||
|
||||
const depcheck = require("depcheck")
|
||||
|
||||
function filterResults(missing) {
|
||||
if (missing.src) {
|
||||
delete missing.src
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
function printMissing(missing) {
|
||||
for (let [key, value] of Object.entries(filterResults(missing))) {
|
||||
console.log(`Package ${key} missing in: ${value.join(", ")}`)
|
||||
}
|
||||
}
|
||||
|
||||
depcheck(process.cwd(), {
|
||||
ignorePatterns: ["dist"],
|
||||
skipMissing: false,
|
||||
}).then(results => {
|
||||
if (Object.values(filterResults(results.missing)).length > 0) {
|
||||
printMissing(results.missing)
|
||||
console.error("Missing packages found - stopping.")
|
||||
process.exit(-1)
|
||||
} else {
|
||||
console.log("No missing dependencies.")
|
||||
}
|
||||
})
|
|
@ -1,32 +0,0 @@
|
|||
#!/bin/bash
|
||||
yarn global add zbctl
|
||||
export ZEEBE_ADDRESS='localhost:26500'
|
||||
|
||||
cd ../budibase-bpm
|
||||
|
||||
is_camunda_ready() {
|
||||
if (zbctl --insecure status 2>/dev/null) | grep -q 'Healthy'; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
docker-compose up -d
|
||||
echo "waiting for Camunda to be ready..."
|
||||
|
||||
while is_camunda_ready -eq 0; do sleep 1; done
|
||||
|
||||
echo "deploy processes..."
|
||||
for file in src/main/resources/models/*; do
|
||||
zbctl deploy resource $file --insecure
|
||||
done
|
||||
|
||||
cd ../budibase/packages/pro
|
||||
yarn && yarn build
|
||||
|
||||
cd ../account-portal/packages/server
|
||||
yarn worker:run & cd ../../../.. && yarn dev:accountportal
|
||||
|
||||
|
||||
|
|
@ -5,12 +5,12 @@ domain=$2
|
|||
|
||||
if [ "$enable" = "enable" ]; then
|
||||
lerna run env:localdomain:enable -- "$domain"
|
||||
cd packages/account-portal
|
||||
cd ../account-portal
|
||||
yarn env:localdomain:enable "$domain"
|
||||
cd -
|
||||
else
|
||||
lerna run env:localdomain:disable
|
||||
cd packages/account-portal
|
||||
cd ../account-portal
|
||||
yarn env:localdomain:disable
|
||||
cd -
|
||||
fi
|
|
@ -1,34 +0,0 @@
|
|||
/***
|
||||
* Running lerna with since and scope is not working as expected.
|
||||
* For example, running the command `yarn test --scope=@budibase/worker --since=master`, with changes only on `@budibase/backend-core` will not work as expected, as it does not analyse the dependencies properly. The actual `@budibase/worker` task will not be triggered.
|
||||
*
|
||||
* This script is using `lerna ls` to detect all the affected projects from a given commit, and if the scoped package is affected, the actual command will be executed.
|
||||
*
|
||||
* The current version of the script only supports a single project in the scope.
|
||||
*/
|
||||
|
||||
const { execSync } = require("child_process")
|
||||
|
||||
const argv = require("yargs").demandOption(["task", "since", "scope"]).argv
|
||||
|
||||
const { task, since, scope } = argv
|
||||
|
||||
const affectedPackages = execSync(
|
||||
`yarn --silent nx show projects --affected -t ${task} --base=${since} --json`,
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const packages = JSON.parse(affectedPackages)
|
||||
|
||||
const isAffected = packages.includes(scope)
|
||||
|
||||
if (isAffected) {
|
||||
console.log(`${scope} is affected. Running task "${task}"`)
|
||||
execSync(`yarn ${task} --scope=${scope}`, {
|
||||
stdio: "inherit",
|
||||
})
|
||||
} else {
|
||||
console.log(`${scope} is not affected. Skipping task "${task}"`)
|
||||
}
|
Loading…
Reference in New Issue