From 6edffb0d5e7001c17ed57e736878a327108bf17b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 24 Oct 2022 10:04:14 +0100 Subject: [PATCH] Addressing majority of PR comments. --- packages/backend-core/package.json | 2 +- .../src/events/publishers/backup.ts | 4 ++-- packages/backend-core/src/queue/listeners.ts | 12 +++++----- packages/backend-core/src/queue/queue.ts | 4 ++-- packages/backend-core/yarn.lock | 23 ++++--------------- packages/server/package.json | 2 +- packages/server/src/api/controllers/cloud.js | 6 ++--- packages/server/src/sdk/index.ts | 6 ++--- packages/server/yarn.lock | 16 +------------ packages/types/src/core/index.ts | 1 - packages/types/src/{core => sdk}/db.ts | 0 packages/types/src/sdk/events/backup.ts | 2 +- packages/types/src/sdk/index.ts | 1 + packages/worker/src/sdk/users/users.ts | 3 --- 14 files changed, 26 insertions(+), 56 deletions(-) delete mode 100644 packages/types/src/core/index.ts rename packages/types/src/{core => sdk}/db.ts (100%) diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index e9c9261f62..3ca2281bd2 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -64,7 +64,7 @@ }, "devDependencies": { "@types/chance": "1.1.3", - "@types/ioredis": "4.28.10", + "@types/ioredis": "4.28.0", "@types/jest": "27.5.1", "@types/koa": "2.0.52", "@types/lodash": "4.14.180", diff --git a/packages/backend-core/src/events/publishers/backup.ts b/packages/backend-core/src/events/publishers/backup.ts index bd346cad64..0fc81da259 100644 --- a/packages/backend-core/src/events/publishers/backup.ts +++ b/packages/backend-core/src/events/publishers/backup.ts @@ -1,8 +1,8 @@ -import { AppBackup, AppBackupRevertEvent, Event } from "@budibase/types" +import { AppBackup, AppBackupRestoreEvent, Event } from "@budibase/types" import { publishEvent } from "../events" export async function appBackupRestored(backup: AppBackup) { - const properties: AppBackupRevertEvent = { + const properties: AppBackupRestoreEvent = { appId: backup.appId, backupName: backup.name!, backupCreatedAt: backup.timestamp, diff --git a/packages/backend-core/src/queue/listeners.ts b/packages/backend-core/src/queue/listeners.ts index f264c3a84c..e1975b5d06 100644 --- a/packages/backend-core/src/queue/listeners.ts +++ b/packages/backend-core/src/queue/listeners.ts @@ -6,18 +6,18 @@ export type StalledFn = (job: Job) => Promise export function addListeners( queue: Queue, jobQueue: JobQueue, - removeStalled?: StalledFn + removeStalledCb?: StalledFn ) { logging(queue, jobQueue) - if (removeStalled) { - handleStalled(queue, removeStalled) + if (removeStalledCb) { + handleStalled(queue, removeStalledCb) } } -function handleStalled(queue: Queue, removeStalled?: StalledFn) { +function handleStalled(queue: Queue, removeStalledCb?: StalledFn) { queue.on("stalled", async (job: Job) => { - if (removeStalled) { - await removeStalled(job) + if (removeStalledCb) { + await removeStalledCb(job) } else if (job.opts.repeat) { const jobId = job.id const repeatJobs = await queue.getRepeatableJobs() diff --git a/packages/backend-core/src/queue/queue.ts b/packages/backend-core/src/queue/queue.ts index 7eaafe38a8..e2f9ea9d94 100644 --- a/packages/backend-core/src/queue/queue.ts +++ b/packages/backend-core/src/queue/queue.ts @@ -18,7 +18,7 @@ async function cleanup() { export function createQueue( jobQueue: JobQueue, - removeStalled?: StalledFn + opts: { removeStalledCb?: StalledFn } ): BullQueue.Queue { const queueConfig: any = redisProtocolUrl || { redis: opts } let queue: any @@ -27,7 +27,7 @@ export function createQueue( } else { queue = new InMemoryQueue(jobQueue, queueConfig) } - addListeners(queue, jobQueue, removeStalled) + addListeners(queue, jobQueue, opts?.removeStalledCb) QUEUES.push(queue) if (!cleanupInterval) { cleanupInterval = setInterval(cleanup, CLEANUP_PERIOD_MS) diff --git a/packages/backend-core/yarn.lock b/packages/backend-core/yarn.lock index d2831ca8fe..d301526ba1 100644 --- a/packages/backend-core/yarn.lock +++ b/packages/backend-core/yarn.lock @@ -291,11 +291,6 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/types@2.0.30-alpha.3": - version "2.0.30-alpha.3" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.3.tgz#cb55bcced75b711cc8a675284fbacaa8ebf1c0f2" - integrity sha512-rHeFVuNbSSE4fMnX6uyrM2r47m+neqFXlVNOkhHU9i7KoIcIZbEYInU8CjUFR2da3ruST9ajXjJ5UenX2+MnTg== - "@hapi/hoek@^9.0.0": version "9.3.0" resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb" @@ -698,14 +693,6 @@ "@types/connect" "*" "@types/node" "*" -"@types/bull@^3.15.9": - version "3.15.9" - resolved "https://registry.yarnpkg.com/@types/bull/-/bull-3.15.9.tgz#e10e0901ec3762bff85716b3c580277960751c93" - integrity sha512-MPUcyPPQauAmynoO3ezHAmCOhbB0pWmYyijr/5ctaCqhbKWsjW0YCod38ZcLzUBprosfZ9dPqfYIcfdKjk7RNQ== - dependencies: - "@types/ioredis" "*" - "@types/redis" "^2.8.0" - "@types/chance@1.1.3": version "1.1.3" resolved "https://registry.yarnpkg.com/@types/chance/-/chance-1.1.3.tgz#d19fe9391288d60fdccd87632bfc9ab2b4523fea" @@ -776,10 +763,10 @@ resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-1.8.2.tgz#7315b4c4c54f82d13fa61c228ec5c2ea5cc9e0e1" integrity sha512-EqX+YQxINb+MeXaIqYDASb6U6FCHbWjkj4a1CKDBks3d/QiB2+PqBLyO72vLDgAO1wUI4O+9gweRcQK11bTL/w== -"@types/ioredis@*", "@types/ioredis@^4.28.10": - version "4.28.10" - resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.28.10.tgz#40ceb157a4141088d1394bb87c98ed09a75a06ff" - integrity sha512-69LyhUgrXdgcNDv7ogs1qXZomnfOEnSmrmMFqKgt1XMJxmoOSG/u3wYy13yACIfKuMJ8IhKgHafDO3sx19zVQQ== +"@types/ioredis@4.28.0": + version "4.28.0" + resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.28.0.tgz#609b2ea0d91231df2dd7f67dd77436bc72584911" + integrity sha512-HSA/JQivJgV0e+353gvgu6WVoWvGRe0HyHOnAN2AvbVIhUlJBhNnnkP8gEEokrDWrxywrBkwo8NuDZ6TVPL9XA== dependencies: "@types/node" "*" @@ -1547,7 +1534,7 @@ buffer@^5.5.0, buffer@^5.6.0: base64-js "^1.3.1" ieee754 "^1.1.13" -bull@^4.10.1: +bull@4.10.1: version "4.10.1" resolved "https://registry.yarnpkg.com/bull/-/bull-4.10.1.tgz#f14974b6089358b62b495a2cbf838aadc098e43f" integrity sha512-Fp21tRPb2EaZPVfmM+ONZKVz2RA+to+zGgaTLyCKt3JMSU8OOBqK8143OQrnGuGpsyE5G+9FevFAGhdZZfQP2g== diff --git a/packages/server/package.json b/packages/server/package.json index 80d72723fb..88ee16dab3 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -163,7 +163,7 @@ "@types/google-spreadsheet": "3.1.5", "@types/ioredis": "4.28.10", "@types/jest": "27.5.1", - "@types/koa": "2.13.5", + "@types/koa": "2.13.4", "@types/koa__router": "8.0.11", "@types/lodash": "4.14.180", "@types/node": "14.18.20", diff --git a/packages/server/src/api/controllers/cloud.js b/packages/server/src/api/controllers/cloud.js index 27b576f181..0a111eae83 100644 --- a/packages/server/src/api/controllers/cloud.js +++ b/packages/server/src/api/controllers/cloud.js @@ -35,9 +35,9 @@ async function getAllDocType(db, docType) { } exports.exportApps = async ctx => { - // if (env.SELF_HOSTED || !env.MULTI_TENANCY) { - // ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.") - // } + if (env.SELF_HOSTED || !env.MULTI_TENANCY) { + ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.") + } const apps = await getAllApps({ all: true }) const globalDBString = await sdk.backups.exportDB(getGlobalDBName(), { filter: doc => !doc._id.startsWith(DocumentType.USER), diff --git a/packages/server/src/sdk/index.ts b/packages/server/src/sdk/index.ts index 85c01cdb44..8bdc4f8e77 100644 --- a/packages/server/src/sdk/index.ts +++ b/packages/server/src/sdk/index.ts @@ -1,13 +1,13 @@ import { default as backups } from "./app/backups" import { default as tables } from "./app/tables" -const toExport = { +const sdk = { backups, tables, } // default export for TS -export default toExport +export default sdk // default export for JS -module.exports = toExport +module.exports = sdk diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 4d07fc6450..5fa18745e7 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -2831,7 +2831,7 @@ dependencies: "@types/koa" "*" -"@types/koa@*": +"@types/koa@*", "@types/koa@2.13.4": version "2.13.4" resolved "https://registry.yarnpkg.com/@types/koa/-/koa-2.13.4.tgz#10620b3f24a8027ef5cbae88b393d1b31205726b" integrity sha512-dfHYMfU+z/vKtQB7NUrthdAEiSvnLebvBjwHtfFmpZmB7em2N3WVQdHgnFq+xvyVgxW5jKDmjWfLD3lw4g4uTw== @@ -2845,20 +2845,6 @@ "@types/koa-compose" "*" "@types/node" "*" -"@types/koa@2.13.5": - version "2.13.5" - resolved "https://registry.yarnpkg.com/@types/koa/-/koa-2.13.5.tgz#64b3ca4d54e08c0062e89ec666c9f45443b21a61" - integrity sha512-HSUOdzKz3by4fnqagwthW/1w/yJspTgppyyalPVbgZf8jQWvdIXcVW5h2DGtw4zYntOaeRGx49r1hxoPWrD4aA== - dependencies: - "@types/accepts" "*" - "@types/content-disposition" "*" - "@types/cookies" "*" - "@types/http-assert" "*" - "@types/http-errors" "*" - "@types/keygrip" "*" - "@types/koa-compose" "*" - "@types/node" "*" - "@types/koa__router@8.0.11": version "8.0.11" resolved "https://registry.yarnpkg.com/@types/koa__router/-/koa__router-8.0.11.tgz#d7b37e6db934fc072ea1baa2ab92bc8ac4564f3e" diff --git a/packages/types/src/core/index.ts b/packages/types/src/core/index.ts deleted file mode 100644 index 9071393365..0000000000 --- a/packages/types/src/core/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./db" diff --git a/packages/types/src/core/db.ts b/packages/types/src/sdk/db.ts similarity index 100% rename from packages/types/src/core/db.ts rename to packages/types/src/sdk/db.ts diff --git a/packages/types/src/sdk/events/backup.ts b/packages/types/src/sdk/events/backup.ts index f3ddafcafc..8d3e2b1afa 100644 --- a/packages/types/src/sdk/events/backup.ts +++ b/packages/types/src/sdk/events/backup.ts @@ -1,6 +1,6 @@ import { BaseEvent } from "./event" -export interface AppBackupRevertEvent extends BaseEvent { +export interface AppBackupRestoreEvent extends BaseEvent { appId: string backupName: string backupCreatedAt: string diff --git a/packages/types/src/sdk/index.ts b/packages/types/src/sdk/index.ts index 0c374dd105..724b152303 100644 --- a/packages/types/src/sdk/index.ts +++ b/packages/types/src/sdk/index.ts @@ -8,3 +8,4 @@ export * from "./search" export * from "./koa" export * from "./auth" export * from "./locks" +export * from "./db" diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index ce03a12587..b0290507fc 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -79,9 +79,6 @@ export const paginatedUsers = async ({ } else if (email) { userList = await usersCore.searchGlobalUsersByEmail(email, opts) property = "email" - } - if (userIds) { - // TODO: search users by userIds } else { // no search, query allDocs const response = await db.allDocs(dbUtils.getGlobalUserParams(null, opts))