Merge branch 'develop' of github.com:Budibase/budibase into lab-day/refactor-app-db

This commit is contained in:
mike12345567 2022-02-01 14:33:02 +00:00
commit 53aabb4d05
30 changed files with 1941 additions and 2435 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -36,10 +36,10 @@
"dev:server": "lerna run --parallel dev:builder --concurrency 1 --scope @budibase/worker --scope @budibase/server", "dev:server": "lerna run --parallel dev:builder --concurrency 1 --scope @budibase/worker --scope @budibase/server",
"test": "lerna run test", "test": "lerna run test",
"lint:eslint": "eslint packages", "lint:eslint": "eslint packages",
"lint:prettier": "prettier --check \"packages/**/*.{js,svelte}\"", "lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
"lint": "yarn run lint:eslint && yarn run lint:prettier", "lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:fix:eslint": "eslint --fix packages", "lint:fix:eslint": "eslint --fix packages",
"lint:fix:prettier": "prettier --write \"packages/**/*.{js,svelte}\"", "lint:fix:prettier": "prettier --write \"packages/**/*.{js,ts,svelte}\"",
"lint:fix:ts": "lerna run lint:fix", "lint:fix:ts": "lerna run lint:fix",
"lint:fix": "yarn run lint:fix:ts && yarn run lint:fix:prettier && yarn run lint:fix:eslint", "lint:fix": "yarn run lint:fix:ts && yarn run lint:fix:prettier && yarn run lint:fix:eslint",
"test:e2e": "lerna run cy:test", "test:e2e": "lerna run cy:test",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/backend-core", "name": "@budibase/backend-core",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"description": "Budibase backend core libraries used in server and worker", "description": "Budibase backend core libraries used in server and worker",
"main": "src/index.js", "main": "src/index.js",
"author": "Budibase", "author": "Budibase",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/bbui", "name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.", "description": "A UI solution used in the different Budibase projects.",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"module": "dist/bbui.es.js", "module": "dist/bbui.es.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"license": "GPL-3.0", "license": "GPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -66,10 +66,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.0.49-alpha.2", "@budibase/bbui": "^1.0.49-alpha.5",
"@budibase/client": "^1.0.49-alpha.2", "@budibase/client": "^1.0.49-alpha.5",
"@budibase/colorpicker": "1.1.2", "@budibase/colorpicker": "1.1.2",
"@budibase/string-templates": "^1.0.49-alpha.2", "@budibase/string-templates": "^1.0.49-alpha.5",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1", "@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1", "@spectrum-css/vars": "^3.0.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/cli", "name": "@budibase/cli",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"description": "Budibase CLI, for developers, self hosting and migrations.", "description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js", "main": "src/index.js",
"bin": { "bin": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"license": "MPL-2.0", "license": "MPL-2.0",
"module": "dist/budibase-client.js", "module": "dist/budibase-client.js",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
@ -19,9 +19,9 @@
"dev:builder": "rollup -cw" "dev:builder": "rollup -cw"
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.0.49-alpha.2", "@budibase/bbui": "^1.0.49-alpha.5",
"@budibase/standard-components": "^0.9.139", "@budibase/standard-components": "^0.9.139",
"@budibase/string-templates": "^1.0.49-alpha.2", "@budibase/string-templates": "^1.0.49-alpha.5",
"regexparam": "^1.3.0", "regexparam": "^1.3.0",
"rollup-plugin-polyfill-node": "^0.8.0", "rollup-plugin-polyfill-node": "^0.8.0",
"shortid": "^2.2.15", "shortid": "^2.2.15",

View File

@ -16,7 +16,12 @@ export default class QueryFetch extends DataFetch {
if (!datasource?._id) { if (!datasource?._id) {
return null return null
} }
return await fetchQueryDefinition(datasource._id) const definition = await fetchQueryDefinition(datasource._id)
// After getting the definition of query, it loses "fields" attribute because of security reason from the server. However, this attribute needs to be inside of defintion for pagination.
if (!definition.fields) {
definition.fields = datasource.fields
}
return definition
} }
async getData() { async getData() {

View File

@ -9,7 +9,7 @@ module ArangoMock {
this.close = jest.fn() this.close = jest.fn()
} }
// @ts-ignore // @ts-ignore
arangodb.aql = (strings, ...args) => { arangodb.aql = (strings, ...args) => {
let str = strings.join("{}") let str = strings.join("{}")

View File

@ -1,7 +1,7 @@
module AwsMock { module AwsMock {
const aws: any = {} const aws: any = {}
const response = (body: any) => () => ({promise: () => body}) const response = (body: any) => () => ({ promise: () => body })
function DocumentClient() { function DocumentClient() {
// @ts-ignore // @ts-ignore
@ -39,9 +39,9 @@ module AwsMock {
) )
} }
aws.DynamoDB = {DocumentClient} aws.DynamoDB = { DocumentClient }
aws.S3 = S3 aws.S3 = S3
aws.config = {update: jest.fn()} aws.config = { update: jest.fn() }
module.exports = aws module.exports = aws
} }

View File

@ -5,15 +5,14 @@ module MongoMock {
this.connect = jest.fn() this.connect = jest.fn()
this.close = jest.fn() this.close = jest.fn()
this.insertOne = jest.fn() this.insertOne = jest.fn()
this.insertMany = jest.fn(() => ({toArray: () => []})) this.insertMany = jest.fn(() => ({ toArray: () => [] }))
this.find = jest.fn(() => ({toArray: () => []})) this.find = jest.fn(() => ({ toArray: () => [] }))
this.findOne = jest.fn() this.findOne = jest.fn()
this.count = jest.fn() this.count = jest.fn()
this.deleteOne = jest.fn() this.deleteOne = jest.fn()
this.deleteMany = jest.fn(() => ({toArray: () => []})) this.deleteMany = jest.fn(() => ({ toArray: () => [] }))
this.updateOne = jest.fn() this.updateOne = jest.fn()
this.updateMany = jest.fn(() => ({toArray: () => []})) this.updateMany = jest.fn(() => ({ toArray: () => [] }))
this.collection = jest.fn(() => ({ this.collection = jest.fn(() => ({
insertOne: this.insertOne, insertOne: this.insertOne,

View File

@ -10,12 +10,12 @@ module MsSqlMock {
], ],
})) }))
// mssql.connect = jest.fn(() => ({ recordset: [] })) // mssql.connect = jest.fn(() => ({ recordset: [] }))
mssql.ConnectionPool = jest.fn(() => ({ mssql.ConnectionPool = jest.fn(() => ({
connect: jest.fn(() => ({ connect: jest.fn(() => ({
request: jest.fn(() => ({ request: jest.fn(() => ({
query: jest.fn(sql => ({ recordset: [ sql ] })), query: jest.fn(sql => ({ recordset: [sql] })),
})), })),
})), })),
})) }))

View File

@ -62,7 +62,8 @@ module FetchMock {
return json({ return json({
url, url,
opts, opts,
value: "<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" lang=\"en-GB\"></html>", value:
'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"></html>',
}) })
} else if (url.includes("failonce.com")) { } else if (url.includes("failonce.com")) {
failCount++ failCount++

View File

@ -10,16 +10,14 @@ module PgMock {
], ],
})) }))
// constructor // constructor
function Client() { function Client() {}
}
Client.prototype.query = query Client.prototype.query = query
Client.prototype.connect = jest.fn() Client.prototype.connect = jest.fn()
Client.prototype.release = jest.fn() Client.prototype.release = jest.fn()
function Pool() { function Pool() {}
}
const on = jest.fn() const on = jest.fn()
Pool.prototype.query = query Pool.prototype.query = query

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -70,9 +70,9 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@apidevtools/swagger-parser": "^10.0.3", "@apidevtools/swagger-parser": "^10.0.3",
"@budibase/backend-core": "^1.0.49-alpha.2", "@budibase/backend-core": "^1.0.49-alpha.5",
"@budibase/client": "^1.0.49-alpha.2", "@budibase/client": "^1.0.49-alpha.5",
"@budibase/string-templates": "^1.0.49-alpha.2", "@budibase/string-templates": "^1.0.49-alpha.5",
"@bull-board/api": "^3.7.0", "@bull-board/api": "^3.7.0",
"@bull-board/koa": "^3.7.0", "@bull-board/koa": "^3.7.0",
"@elastic/elasticsearch": "7.10.0", "@elastic/elasticsearch": "7.10.0",

View File

@ -9,7 +9,16 @@ import { getAppUrl } from "../../api/controllers/application"
* Add the url to the app metadata if it doesn't exist * Add the url to the app metadata if it doesn't exist
*/ */
export const run = async (appDb: any) => { export const run = async (appDb: any) => {
const metadata = await appDb.get(DocumentTypes.APP_METADATA) let metadata
try {
metadata = await appDb.get(DocumentTypes.APP_METADATA)
} catch (e) {
// sometimes the metadata document doesn't exist
// exit early instead of failing the migration
console.error("Error retrieving app metadata. Skipping", e)
return
}
if (!metadata.url) { if (!metadata.url) {
const context = { const context = {
request: { request: {
@ -20,6 +29,6 @@ export const run = async (appDb: any) => {
} }
metadata.url = getAppUrl(context) metadata.url = getAppUrl(context)
console.log(`Adding url to app: ${metadata.url}`) console.log(`Adding url to app: ${metadata.url}`)
await appDb.put(metadata)
} }
await appDb.put(metadata)
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/string-templates", "name": "@budibase/string-templates",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"description": "Handlebars wrapper for Budibase templating.", "description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs", "main": "src/index.cjs",
"module": "dist/bundle.mjs", "module": "dist/bundle.mjs",

View File

@ -3,6 +3,7 @@
"emit": true, "emit": true,
"key": true "key": true
}, },
"parser": "@typescript-eslint/parser",
"env": { "env": {
"node": true "node": true
}, },

View File

@ -1,3 +1,4 @@
node_modules/ node_modules/
.env .env
watchtower-hook.json watchtower-hook.json
dist/

View File

@ -1,3 +1,6 @@
{ {
"watch": ["src", "../backend-core"] "watch": ["src", "../backend-core"],
"ext": "js,ts,json",
"ignore": ["src/**/*.spec.ts", "src/**/*.spec.js"],
"exec": "ts-node src/index.ts"
} }

View File

@ -1,9 +1,9 @@
{ {
"name": "@budibase/worker", "name": "@budibase/worker",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "1.0.49-alpha.2", "version": "1.0.49-alpha.5",
"description": "Budibase background service", "description": "Budibase background service",
"main": "src/index.js", "main": "src/index.ts",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/Budibase/budibase.git" "url": "https://github.com/Budibase/budibase.git"
@ -12,10 +12,15 @@
"budibase" "budibase"
], ],
"scripts": { "scripts": {
"run:docker": "node src/index.js", "build": "rimraf dist/ && tsc",
"postbuild": "copyfiles -u 1 src/**/*.hbs dist/",
"run:docker": "node dist/index.js",
"build:docker": "docker build . -t worker-service --label version=$BUDIBASE_RELEASE_VERSION", "build:docker": "docker build . -t worker-service --label version=$BUDIBASE_RELEASE_VERSION",
"dev:stack:init": "node ./scripts/dev/manage.js init", "dev:stack:init": "node ./scripts/dev/manage.js init",
"dev:builder": "npm run dev:stack:init && nodemon", "dev:builder": "npm run dev:stack:init && nodemon",
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
"lint": "eslint --fix src/",
"lint:fix": "yarn run format && yarn run lint",
"test": "jest --runInBand", "test": "jest --runInBand",
"env:multi:enable": "node scripts/multiTenancy.js enable", "env:multi:enable": "node scripts/multiTenancy.js enable",
"env:multi:disable": "node scripts/multiTenancy.js disable", "env:multi:disable": "node scripts/multiTenancy.js disable",
@ -29,8 +34,8 @@
"author": "Budibase", "author": "Budibase",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@budibase/backend-core": "^1.0.49-alpha.2", "@budibase/backend-core": "^1.0.49-alpha.5",
"@budibase/string-templates": "^1.0.49-alpha.2", "@budibase/string-templates": "^1.0.49-alpha.5",
"@koa/router": "^8.0.0", "@koa/router": "^8.0.0",
"@sentry/node": "^6.0.0", "@sentry/node": "^6.0.0",
"@techpass/passport-openidconnect": "^0.3.0", "@techpass/passport-openidconnect": "^0.3.0",
@ -58,13 +63,26 @@
"server-destroy": "^1.0.1" "server-destroy": "^1.0.1"
}, },
"devDependencies": { "devDependencies": {
"jest": "^26.6.3", "@types/jest": "^26.0.23",
"@types/koa": "^2.13.3",
"@types/koa-router": "^7.4.2",
"@types/node": "^15.12.4",
"@typescript-eslint/parser": "4.28.0",
"copyfiles": "^2.4.1",
"eslint": "^6.8.0",
"jest": "^27.0.5",
"nodemon": "^2.0.7", "nodemon": "^2.0.7",
"pouchdb-adapter-memory": "^7.2.2", "pouchdb-adapter-memory": "^7.2.2",
"prettier": "2.3.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3", "supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"typescript": "4.3.5",
"update-dotenv": "^1.1.1" "update-dotenv": "^1.1.1"
}, },
"jest": { "jest": {
"preset": "ts-jest",
"testEnvironment": "node", "testEnvironment": "node",
"setupFiles": [ "setupFiles": [
"./scripts/jestSetup.js" "./scripts/jestSetup.js"

View File

@ -1,10 +1,9 @@
jest.mock("nodemailer")
const setup = require("./utilities") const setup = require("./utilities")
const sendMailMock = setup.emailMock()
const TENANT_ID = "default" const TENANT_ID = "default"
jest.mock("nodemailer")
const sendMailMock = setup.emailMock()
describe("/api/global/auth", () => { describe("/api/global/auth", () => {
let request = setup.getRequest() let request = setup.getRequest()
let config = setup.getConfig() let config = setup.getConfig()

View File

@ -1,11 +1,7 @@
const setup = require("./utilities")
// mock the email system // mock the email system
jest.mock("nodemailer") jest.mock("nodemailer")
const nodemailer = require("nodemailer") const setup = require("./utilities")
nodemailer.createTransport.mockReturnValue({ setup.emailMock()
verify: jest.fn(),
})
describe("/api/global/configs/checklist", () => { describe("/api/global/configs/checklist", () => {
let request = setup.getRequest() let request = setup.getRequest()

View File

@ -1,16 +1,10 @@
jest.mock("nodemailer")
const setup = require("./utilities") const setup = require("./utilities")
const sendMailMock = setup.emailMock()
const { EmailTemplatePurpose } = require("../../../constants") const { EmailTemplatePurpose } = require("../../../constants")
const { TENANT_ID } = require("./utilities/structures") const { TENANT_ID } = require("./utilities/structures")
// mock the email system
const sendMailMock = jest.fn()
jest.mock("nodemailer")
const nodemailer = require("nodemailer")
nodemailer.createTransport.mockReturnValue({
sendMail: sendMailMock,
verify: jest.fn(),
})
describe("/api/global/email", () => { describe("/api/global/email", () => {
let request = setup.getRequest() let request = setup.getRequest()
let config = setup.getConfig() let config = setup.getConfig()

View File

@ -1,7 +1,5 @@
const setup = require("./utilities")
const { TENANT_ID } = require("./utilities/structures")
jest.mock("nodemailer") jest.mock("nodemailer")
const setup = require("./utilities")
const sendMailMock = setup.emailMock() const sendMailMock = setup.emailMock()
describe("/api/global/users", () => { describe("/api/global/users", () => {

View File

@ -1,4 +1,8 @@
// need to load environment first // need to load environment first
import { Scope } from "@sentry/node"
import { Event } from "@sentry/types/dist/event"
import Application from "koa"
const env = require("./environment") const env = require("./environment")
const CouchDB = require("./db") const CouchDB = require("./db")
require("@budibase/backend-core").init(CouchDB) require("@budibase/backend-core").init(CouchDB)
@ -13,7 +17,7 @@ const api = require("./api")
const redis = require("./utilities/redis") const redis = require("./utilities/redis")
const Sentry = require("@sentry/node") const Sentry = require("@sentry/node")
const app = new Koa() const app: Application = new Koa()
app.keys = ["secret", "key"] app.keys = ["secret", "key"]
@ -42,8 +46,8 @@ if (env.isProd()) {
Sentry.init() Sentry.init()
app.on("error", (err, ctx) => { app.on("error", (err, ctx) => {
Sentry.withScope(function (scope) { Sentry.withScope(function (scope: Scope) {
scope.addEventProcessor(function (event) { scope.addEventProcessor(function (event: Event) {
return Sentry.Handlers.parseRequest(event, ctx.request) return Sentry.Handlers.parseRequest(event, ctx.request)
}) })
Sentry.captureException(err) Sentry.captureException(err)

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["es2019"],
"allowJs": true,
"outDir": "dist",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"incremental": true
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules",
"**/*.json",
"**/*.spec.ts",
"**/*.spec.js"
]
}

File diff suppressed because it is too large Load Diff