@budibase/server 2.0.24-alpha.2 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/{index.6263131a.js → index.6e94f86b.js} +274 -274
- package/builder/assets/{index.e56da48a.css → index.dfa4073c.css} +2 -2
- package/builder/index.html +2 -2
- package/coverage/clover.xml +341 -344
- package/coverage/coverage-final.json +24 -24
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +1 -1
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +12 -12
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +5 -5
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +5 -5
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +22 -22
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +3 -3
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +16 -10
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +2 -2
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +11 -11
- package/coverage/lcov-report/middleware/currentapp.js.html +34 -34
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +13 -13
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +38 -38
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +11 -23
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +614 -619
- package/dist/api/controllers/application.js +9 -10
- package/dist/api/controllers/query/index.js +2 -6
- package/dist/api/controllers/row/index.js +10 -30
- package/dist/api/controllers/static/templates/preview.hbs +0 -10
- package/dist/api/controllers/table/internal.js +1 -3
- package/dist/api/controllers/table/utils.js +1 -3
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/utils.js +3 -5
- package/dist/db/utils.js +1 -1
- package/dist/migrations/functions/{usageQuotas/syncPlugins.js → pluginCount.js} +3 -1
- package/dist/migrations/functions/{syncQuotas.js → quotas1.js} +7 -3
- package/dist/migrations/functions/usageQuotas/syncApps.js +1 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +5 -9
- package/dist/migrations/index.js +9 -3
- package/dist/package.json +7 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/redis.js +2 -6
- package/dist/utilities/usageQuota/rows.js +4 -6
- package/package.json +8 -8
- package/src/api/controllers/application.ts +10 -11
- package/src/api/controllers/query/index.ts +2 -7
- package/src/api/controllers/row/index.ts +13 -36
- package/src/api/controllers/static/templates/preview.hbs +0 -10
- package/src/api/controllers/table/internal.ts +1 -3
- package/src/api/controllers/table/utils.ts +1 -3
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/row.spec.js +27 -22
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +6 -1
- package/src/automations/utils.ts +4 -6
- package/src/db/utils.js +2 -0
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/pluginCount.ts +12 -0
- package/src/migrations/functions/{syncQuotas.ts → quotas1.ts} +8 -3
- package/src/migrations/functions/tests/{syncQuotas.spec.js → quotas1.spec.js} +2 -5
- package/src/migrations/functions/usageQuotas/syncApps.ts +1 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +6 -15
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +1 -9
- package/src/migrations/index.ts +15 -3
- package/src/migrations/tests/index.spec.ts +1 -0
- package/src/utilities/redis.js +2 -6
- package/src/utilities/usageQuota/rows.js +3 -7
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +0 -10
package/dist/utilities/redis.js
CHANGED
|
@@ -42,12 +42,8 @@ exports.doesUserHaveLock = (devAppId, user) => __awaiter(void 0, void 0, void 0,
|
|
|
42
42
|
const userId = getGlobalIDFromUserMetadataID(user._id);
|
|
43
43
|
return expected === userId;
|
|
44
44
|
});
|
|
45
|
-
exports.
|
|
46
|
-
|
|
47
|
-
return locks.map(lock => ({
|
|
48
|
-
appId: lock.key,
|
|
49
|
-
user: lock.value,
|
|
50
|
-
}));
|
|
45
|
+
exports.getLocksById = (appIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
return yield devAppClient.bulkGet(appIds);
|
|
51
47
|
});
|
|
52
48
|
exports.updateLock = (devAppId, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
49
|
// make sure always global user ID
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
12
|
-
const { isDevAppID, getDevelopmentAppID,
|
|
12
|
+
const { isDevAppID, getDevelopmentAppID, doWithDB, } = require("@budibase/backend-core/db");
|
|
13
13
|
const ROW_EXCLUSIONS = [USER_METDATA_PREFIX];
|
|
14
14
|
const getAppPairs = appIds => {
|
|
15
15
|
// collect the app ids into dev / prod pairs
|
|
@@ -53,7 +53,7 @@ const getAppRows = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
53
53
|
* Rows duplicates may exist across apps due to data import so they are not filtered out.
|
|
54
54
|
*/
|
|
55
55
|
exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
let uniqueRows = []
|
|
56
|
+
let uniqueRows = [];
|
|
57
57
|
const pairs = getAppPairs(appIds);
|
|
58
58
|
for (let pair of Object.values(pairs)) {
|
|
59
59
|
let appRows = [];
|
|
@@ -73,9 +73,7 @@ exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function*
|
|
|
73
73
|
// this can't be done on all rows because app import results in
|
|
74
74
|
// duplicate row ids across apps
|
|
75
75
|
// the array pre-concat is important to avoid stack overflow
|
|
76
|
-
|
|
77
|
-
rowsByApp[prodId] = [...new Set(appRows)];
|
|
78
|
-
uniqueRows = uniqueRows.concat(rowsByApp[prodId]);
|
|
76
|
+
uniqueRows = uniqueRows.concat([...new Set(appRows)]);
|
|
79
77
|
}
|
|
80
|
-
return
|
|
78
|
+
return uniqueRows;
|
|
81
79
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.24
|
|
4
|
+
"version": "2.0.24",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "2.0.24
|
|
81
|
-
"@budibase/client": "2.0.24
|
|
82
|
-
"@budibase/pro": "2.0.
|
|
83
|
-
"@budibase/string-templates": "2.0.24
|
|
84
|
-
"@budibase/types": "2.0.24
|
|
80
|
+
"@budibase/backend-core": "^2.0.24",
|
|
81
|
+
"@budibase/client": "^2.0.24",
|
|
82
|
+
"@budibase/pro": "2.0.23",
|
|
83
|
+
"@budibase/string-templates": "^2.0.24",
|
|
84
|
+
"@budibase/types": "^2.0.24",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"to-json-schema": "0.2.5",
|
|
147
147
|
"uuid": "3.3.2",
|
|
148
148
|
"validate.js": "0.13.1",
|
|
149
|
-
"vm2": "3.9.
|
|
149
|
+
"vm2": "3.9.6",
|
|
150
150
|
"worker-farm": "1.7.0",
|
|
151
151
|
"xml2js": "0.4.23",
|
|
152
152
|
"yargs": "13.2.4",
|
|
@@ -199,5 +199,5 @@
|
|
|
199
199
|
"optionalDependencies": {
|
|
200
200
|
"oracledb": "5.3.0"
|
|
201
201
|
},
|
|
202
|
-
"gitHead": "
|
|
202
|
+
"gitHead": "e1180dfac0d033b751c902aee375137d04aaa7ca"
|
|
203
203
|
}
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
import { USERS_TABLE_SCHEMA } from "../../constants"
|
|
33
33
|
import { removeAppFromUserRoles } from "../../utilities/workerRequests"
|
|
34
34
|
import { clientLibraryPath, stringToReadStream } from "../../utilities"
|
|
35
|
-
import {
|
|
35
|
+
import { getLocksById } from "../../utilities/redis"
|
|
36
36
|
import {
|
|
37
37
|
updateClientLibrary,
|
|
38
38
|
backupClientLibrary,
|
|
@@ -45,11 +45,10 @@ import { cleanupAutomations } from "../../automations/utils"
|
|
|
45
45
|
import { context } from "@budibase/backend-core"
|
|
46
46
|
import { checkAppMetadata } from "../../automations/logging"
|
|
47
47
|
import { getUniqueRows } from "../../utilities/usageQuota/rows"
|
|
48
|
-
import { quotas } from "@budibase/pro"
|
|
48
|
+
import { quotas, groups } from "@budibase/pro"
|
|
49
49
|
import { errors, events, migrations } from "@budibase/backend-core"
|
|
50
50
|
import { App, Layout, Screen, MigrationType } from "@budibase/types"
|
|
51
51
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
|
52
|
-
import { groups } from "@budibase/pro"
|
|
53
52
|
import { enrichPluginURLs } from "../../utilities/plugins"
|
|
54
53
|
|
|
55
54
|
const URL_REGEX_SLASH = /\/|\\/g
|
|
@@ -172,16 +171,16 @@ export const fetch = async (ctx: any) => {
|
|
|
172
171
|
const all = ctx.query && ctx.query.status === AppStatus.ALL
|
|
173
172
|
const apps = await getAllApps({ dev, all })
|
|
174
173
|
|
|
174
|
+
const appIds = apps
|
|
175
|
+
.filter((app: any) => app.status === "development")
|
|
176
|
+
.map((app: any) => app.appId)
|
|
175
177
|
// get the locks for all the dev apps
|
|
176
178
|
if (dev || all) {
|
|
177
|
-
const locks = await
|
|
179
|
+
const locks = await getLocksById(appIds)
|
|
178
180
|
for (let app of apps) {
|
|
179
|
-
|
|
180
|
-
continue
|
|
181
|
-
}
|
|
182
|
-
const lock = locks.find((lock: any) => lock.appId === app.appId)
|
|
181
|
+
const lock = locks[app.appId]
|
|
183
182
|
if (lock) {
|
|
184
|
-
app.lockedBy = lock
|
|
183
|
+
app.lockedBy = lock
|
|
185
184
|
} else {
|
|
186
185
|
// make sure its definitely not present
|
|
187
186
|
delete app.lockedBy
|
|
@@ -360,7 +359,7 @@ const appPostCreate = async (ctx: any, app: App) => {
|
|
|
360
359
|
await creationEvents(ctx.request, app)
|
|
361
360
|
// app import & template creation
|
|
362
361
|
if (ctx.request.body.useTemplate === "true") {
|
|
363
|
-
const
|
|
362
|
+
const rows = await getUniqueRows([app.appId])
|
|
364
363
|
const rowCount = rows ? rows.length : 0
|
|
365
364
|
if (rowCount) {
|
|
366
365
|
try {
|
|
@@ -494,7 +493,7 @@ const destroyApp = async (ctx: any) => {
|
|
|
494
493
|
}
|
|
495
494
|
|
|
496
495
|
const preDestroyApp = async (ctx: any) => {
|
|
497
|
-
const
|
|
496
|
+
const rows = await getUniqueRows([ctx.params.appId])
|
|
498
497
|
ctx.rowCount = rows.length
|
|
499
498
|
}
|
|
500
499
|
|
|
@@ -153,10 +153,7 @@ export async function preview(ctx: any) {
|
|
|
153
153
|
auth: { ...authConfigCtx },
|
|
154
154
|
},
|
|
155
155
|
})
|
|
156
|
-
|
|
157
|
-
const { rows, keys, info, extra } = await quotas.addQuery(runFn, {
|
|
158
|
-
datasourceId: datasource._id,
|
|
159
|
-
})
|
|
156
|
+
const { rows, keys, info, extra } = await quotas.addQuery(runFn)
|
|
160
157
|
const schemaFields: any = {}
|
|
161
158
|
if (rows?.length > 0) {
|
|
162
159
|
for (let key of [...new Set(keys)] as string[]) {
|
|
@@ -237,9 +234,7 @@ async function execute(
|
|
|
237
234
|
},
|
|
238
235
|
})
|
|
239
236
|
|
|
240
|
-
const { rows, pagination, extra } = await quotas.addQuery(runFn
|
|
241
|
-
datasourceId: datasource._id,
|
|
242
|
-
})
|
|
237
|
+
const { rows, pagination, extra } = await quotas.addQuery(runFn)
|
|
243
238
|
// remove the raw from execution incase transformer being used to hide data
|
|
244
239
|
if (extra?.raw) {
|
|
245
240
|
delete extra.raw
|
|
@@ -31,11 +31,8 @@ export async function patch(ctx: any): Promise<any> {
|
|
|
31
31
|
return save(ctx)
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
const { row, table } = await quotas.addQuery(
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
datasourceId: tableId,
|
|
38
|
-
}
|
|
34
|
+
const { row, table } = await quotas.addQuery(() =>
|
|
35
|
+
pickApi(tableId).patch(ctx)
|
|
39
36
|
)
|
|
40
37
|
ctx.status = 200
|
|
41
38
|
ctx.eventEmitter &&
|
|
@@ -57,9 +54,7 @@ export const save = async (ctx: any) => {
|
|
|
57
54
|
}
|
|
58
55
|
try {
|
|
59
56
|
const { row, table } = await quotas.addRow(() =>
|
|
60
|
-
quotas.addQuery(() => pickApi(tableId).save(ctx)
|
|
61
|
-
datasourceId: tableId,
|
|
62
|
-
})
|
|
57
|
+
quotas.addQuery(() => pickApi(tableId).save(ctx))
|
|
63
58
|
)
|
|
64
59
|
ctx.status = 200
|
|
65
60
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
|
|
@@ -73,9 +68,7 @@ export const save = async (ctx: any) => {
|
|
|
73
68
|
export async function fetchView(ctx: any) {
|
|
74
69
|
const tableId = getTableId(ctx)
|
|
75
70
|
try {
|
|
76
|
-
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx)
|
|
77
|
-
datasourceId: tableId,
|
|
78
|
-
})
|
|
71
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx))
|
|
79
72
|
} catch (err) {
|
|
80
73
|
ctx.throw(400, err)
|
|
81
74
|
}
|
|
@@ -84,9 +77,7 @@ export async function fetchView(ctx: any) {
|
|
|
84
77
|
export async function fetch(ctx: any) {
|
|
85
78
|
const tableId = getTableId(ctx)
|
|
86
79
|
try {
|
|
87
|
-
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx)
|
|
88
|
-
datasourceId: tableId,
|
|
89
|
-
})
|
|
80
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx))
|
|
90
81
|
} catch (err) {
|
|
91
82
|
ctx.throw(400, err)
|
|
92
83
|
}
|
|
@@ -95,9 +86,7 @@ export async function fetch(ctx: any) {
|
|
|
95
86
|
export async function find(ctx: any) {
|
|
96
87
|
const tableId = getTableId(ctx)
|
|
97
88
|
try {
|
|
98
|
-
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx)
|
|
99
|
-
datasourceId: tableId,
|
|
100
|
-
})
|
|
89
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx))
|
|
101
90
|
} catch (err) {
|
|
102
91
|
ctx.throw(400, err)
|
|
103
92
|
}
|
|
@@ -109,11 +98,8 @@ export async function destroy(ctx: any) {
|
|
|
109
98
|
const tableId = getTableId(ctx)
|
|
110
99
|
let response, row
|
|
111
100
|
if (inputs.rows) {
|
|
112
|
-
let { rows } = await quotas.addQuery(
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
datasourceId: tableId,
|
|
116
|
-
}
|
|
101
|
+
let { rows } = await quotas.addQuery(() =>
|
|
102
|
+
pickApi(tableId).bulkDestroy(ctx)
|
|
117
103
|
)
|
|
118
104
|
await quotas.removeRows(rows.length)
|
|
119
105
|
response = rows
|
|
@@ -121,9 +107,7 @@ export async function destroy(ctx: any) {
|
|
|
121
107
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
|
122
108
|
}
|
|
123
109
|
} else {
|
|
124
|
-
let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx)
|
|
125
|
-
datasourceId: tableId,
|
|
126
|
-
})
|
|
110
|
+
let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx))
|
|
127
111
|
await quotas.removeRow()
|
|
128
112
|
response = resp.response
|
|
129
113
|
row = resp.row
|
|
@@ -139,9 +123,7 @@ export async function search(ctx: any) {
|
|
|
139
123
|
const tableId = getTableId(ctx)
|
|
140
124
|
try {
|
|
141
125
|
ctx.status = 200
|
|
142
|
-
ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx)
|
|
143
|
-
datasourceId: tableId,
|
|
144
|
-
})
|
|
126
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx))
|
|
145
127
|
} catch (err) {
|
|
146
128
|
ctx.throw(400, err)
|
|
147
129
|
}
|
|
@@ -159,11 +141,8 @@ export async function validate(ctx: any) {
|
|
|
159
141
|
export async function fetchEnrichedRow(ctx: any) {
|
|
160
142
|
const tableId = getTableId(ctx)
|
|
161
143
|
try {
|
|
162
|
-
ctx.body = await quotas.addQuery(
|
|
163
|
-
|
|
164
|
-
{
|
|
165
|
-
datasourceId: tableId,
|
|
166
|
-
}
|
|
144
|
+
ctx.body = await quotas.addQuery(() =>
|
|
145
|
+
pickApi(tableId).fetchEnrichedRow(ctx)
|
|
167
146
|
)
|
|
168
147
|
} catch (err) {
|
|
169
148
|
ctx.throw(400, err)
|
|
@@ -173,9 +152,7 @@ export async function fetchEnrichedRow(ctx: any) {
|
|
|
173
152
|
export const exportRows = async (ctx: any) => {
|
|
174
153
|
const tableId = getTableId(ctx)
|
|
175
154
|
try {
|
|
176
|
-
ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx)
|
|
177
|
-
datasourceId: tableId,
|
|
178
|
-
})
|
|
155
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx))
|
|
179
156
|
} catch (err) {
|
|
180
157
|
ctx.throw(400, err)
|
|
181
158
|
}
|
|
@@ -56,16 +56,6 @@
|
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// If this is a custom event, try and handle it
|
|
60
|
-
if (parsed.runtimeEvent) {
|
|
61
|
-
const { name, payload } = parsed
|
|
62
|
-
if (window.handleBuilderRuntimeEvent) {
|
|
63
|
-
window.handleBuilderRuntimeEvent(name, payload)
|
|
64
|
-
}
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Otherwise this is a full reload message
|
|
69
59
|
// Extract data from message
|
|
70
60
|
const {
|
|
71
61
|
selectedComponentId,
|
|
@@ -153,9 +153,7 @@ export async function destroy(ctx: any) {
|
|
|
153
153
|
await db.bulkDocs(
|
|
154
154
|
rows.rows.map((row: any) => ({ ...row.doc, _deleted: true }))
|
|
155
155
|
)
|
|
156
|
-
await quotas.removeRows(rows.rows.length
|
|
157
|
-
tableId: ctx.params.tableId,
|
|
158
|
-
})
|
|
156
|
+
await quotas.removeRows(rows.rows.length)
|
|
159
157
|
|
|
160
158
|
// update linked rows
|
|
161
159
|
await updateLinks({
|
|
@@ -148,9 +148,7 @@ export async function handleDataImport(user: any, table: any, dataImport: any) {
|
|
|
148
148
|
finalData.push(row)
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
await quotas.addRows(finalData.length, () => db.bulkDocs(finalData)
|
|
152
|
-
tableId: table._id,
|
|
153
|
-
})
|
|
151
|
+
await quotas.addRows(finalData.length, () => db.bulkDocs(finalData))
|
|
154
152
|
await events.rows.imported(table, "csv", finalData.length)
|
|
155
153
|
return table
|
|
156
154
|
}
|
|
@@ -34,13 +34,18 @@ describe("/rows", () => {
|
|
|
34
34
|
.expect(status)
|
|
35
35
|
|
|
36
36
|
const getRowUsage = async () => {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
return config.doInContext(null, () =>
|
|
38
|
+
quotas.getCurrentUsageValue(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
|
|
39
|
+
)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const getQueryUsage = async () => {
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
return config.doInContext(null, () =>
|
|
44
|
+
quotas.getCurrentUsageValue(
|
|
45
|
+
QuotaUsageType.MONTHLY,
|
|
46
|
+
MonthlyQuotaName.QUERIES
|
|
47
|
+
)
|
|
48
|
+
)
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
const assertRowUsage = async expected => {
|
|
@@ -55,26 +60,26 @@ describe("/rows", () => {
|
|
|
55
60
|
|
|
56
61
|
describe("save, load, update", () => {
|
|
57
62
|
it("returns a success message when the row is created", async () => {
|
|
58
|
-
const rowUsage = await getRowUsage()
|
|
59
|
-
const queryUsage = await getQueryUsage()
|
|
60
|
-
|
|
61
|
-
const res = await request
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(res.res.statusMessage).toEqual(`${table.name} saved successfully`)
|
|
68
|
-
expect(res.body.name).toEqual("Test Contact")
|
|
69
|
-
expect(res.body._rev).toBeDefined()
|
|
70
|
-
await assertRowUsage(rowUsage + 1)
|
|
71
|
-
await assertQueryUsage(queryUsage + 1)
|
|
63
|
+
// const rowUsage = await getRowUsage()
|
|
64
|
+
// const queryUsage = await getQueryUsage()
|
|
65
|
+
//
|
|
66
|
+
// const res = await request
|
|
67
|
+
// .post(`/api/${row.tableId}/rows`)
|
|
68
|
+
// .send(row)
|
|
69
|
+
// .set(config.defaultHeaders())
|
|
70
|
+
// .expect('Content-Type', /json/)
|
|
71
|
+
// .expect(200)
|
|
72
|
+
// expect(res.res.statusMessage).toEqual(`${table.name} saved successfully`)
|
|
73
|
+
// expect(res.body.name).toEqual("Test Contact")
|
|
74
|
+
// expect(res.body._rev).toBeDefined()
|
|
75
|
+
// await assertRowUsage(rowUsage + 1)
|
|
76
|
+
// await assertQueryUsage(queryUsage + 1)
|
|
72
77
|
})
|
|
73
78
|
|
|
74
79
|
it("updates a row successfully", async () => {
|
|
75
80
|
const existing = await config.createRow()
|
|
76
|
-
const rowUsage = await getRowUsage()
|
|
77
|
-
const queryUsage = await getQueryUsage()
|
|
81
|
+
// const rowUsage = await getRowUsage()
|
|
82
|
+
// const queryUsage = await getQueryUsage()
|
|
78
83
|
|
|
79
84
|
const res = await request
|
|
80
85
|
.post(`/api/${table._id}/rows`)
|
|
@@ -92,8 +97,8 @@ describe("/rows", () => {
|
|
|
92
97
|
`${table.name} updated successfully.`
|
|
93
98
|
)
|
|
94
99
|
expect(res.body.name).toEqual("Updated Name")
|
|
95
|
-
await assertRowUsage(rowUsage)
|
|
96
|
-
await assertQueryUsage(queryUsage + 1)
|
|
100
|
+
// await assertRowUsage(rowUsage)
|
|
101
|
+
// await assertQueryUsage(queryUsage + 1)
|
|
97
102
|
})
|
|
98
103
|
|
|
99
104
|
it("should load a row", async () => {
|
|
@@ -66,9 +66,9 @@ exports.run = async function ({ inputs, appId, emitter }) {
|
|
|
66
66
|
}
|
|
67
67
|
const tableId = inputs.row.tableId
|
|
68
68
|
|
|
69
|
-
// clear any
|
|
69
|
+
// clear any falsy properties so that they aren't updated
|
|
70
70
|
for (let propKey of Object.keys(inputs.row)) {
|
|
71
|
-
if (inputs.row[propKey]
|
|
71
|
+
if (!inputs.row[propKey] || inputs.row[propKey] === "") {
|
|
72
72
|
delete inputs.row[propKey]
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -29,11 +29,16 @@ describe("Run through some parts of the automations system", () => {
|
|
|
29
29
|
afterAll(setup.afterAll)
|
|
30
30
|
|
|
31
31
|
it("should be able to init in builder", async () => {
|
|
32
|
-
await triggers.externalTrigger(basicAutomation(), { a: 1
|
|
32
|
+
await triggers.externalTrigger(basicAutomation(), { a: 1 })
|
|
33
33
|
await wait(100)
|
|
34
34
|
expect(thread.execute).toHaveBeenCalled()
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
+
it("should be able to init in prod", async () => {
|
|
38
|
+
await triggers.externalTrigger(basicAutomation(), { a: 1 })
|
|
39
|
+
await wait(100)
|
|
40
|
+
})
|
|
41
|
+
|
|
37
42
|
it("should check coercion", async () => {
|
|
38
43
|
const table = await config.createTable()
|
|
39
44
|
const automation = basicAutomation()
|
package/src/automations/utils.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
getAppId,
|
|
14
14
|
getProdAppDB,
|
|
15
15
|
} from "@budibase/backend-core/context"
|
|
16
|
-
import {
|
|
16
|
+
import { tenancy } from "@budibase/backend-core"
|
|
17
17
|
import { quotas } from "@budibase/pro"
|
|
18
18
|
import { Automation } from "@budibase/types"
|
|
19
19
|
|
|
@@ -28,14 +28,12 @@ const jobMessage = (job: any, message: string) => {
|
|
|
28
28
|
|
|
29
29
|
export async function processEvent(job: any) {
|
|
30
30
|
try {
|
|
31
|
-
const automationId = job.data.automation._id
|
|
32
31
|
console.log(jobMessage(job, "running"))
|
|
33
32
|
// need to actually await these so that an error can be captured properly
|
|
34
|
-
|
|
33
|
+
const tenantId = tenancy.getTenantIDFromAppID(job.data.event.appId)
|
|
34
|
+
return await tenancy.doInTenant(tenantId, async () => {
|
|
35
35
|
const runFn = () => Runner.run(job)
|
|
36
|
-
return quotas.addAutomation(runFn
|
|
37
|
-
automationId,
|
|
38
|
-
})
|
|
36
|
+
return quotas.addAutomation(runFn)
|
|
39
37
|
})
|
|
40
38
|
} catch (err) {
|
|
41
39
|
const errJson = JSON.stringify(err)
|
package/src/db/utils.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { tenancy, logging } from "@budibase/backend-core"
|
|
2
|
+
import { plugins } from "@budibase/pro"
|
|
3
|
+
|
|
4
|
+
export const run = async () => {
|
|
5
|
+
try {
|
|
6
|
+
await tenancy.doInTenant(tenancy.DEFAULT_TENANT_ID, async () => {
|
|
7
|
+
await plugins.checkPluginQuotas()
|
|
8
|
+
})
|
|
9
|
+
} catch (err) {
|
|
10
|
+
logging.logAlert("Failed to update plugin quotas", err)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { runQuotaMigration } from "./usageQuotas"
|
|
2
2
|
import * as syncApps from "./usageQuotas/syncApps"
|
|
3
3
|
import * as syncRows from "./usageQuotas/syncRows"
|
|
4
|
-
import * as syncPlugins from "./usageQuotas/syncPlugins"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* Date:
|
|
7
|
+
* January 2022
|
|
8
|
+
*
|
|
9
|
+
* Description:
|
|
10
|
+
* Synchronise the app and row quotas to the state of the db after it was
|
|
11
|
+
* discovered that the quota resets were still in place and the row quotas
|
|
12
|
+
* weren't being decremented correctly.
|
|
8
13
|
*/
|
|
14
|
+
|
|
9
15
|
export const run = async () => {
|
|
10
16
|
await runQuotaMigration(async () => {
|
|
11
17
|
await syncApps.run()
|
|
12
18
|
await syncRows.run()
|
|
13
|
-
await syncPlugins.run()
|
|
14
19
|
})
|
|
15
20
|
}
|
|
@@ -2,13 +2,11 @@ const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
|
2
2
|
|
|
3
3
|
const syncApps = jest.fn()
|
|
4
4
|
const syncRows = jest.fn()
|
|
5
|
-
const syncPlugins = jest.fn()
|
|
6
5
|
|
|
7
6
|
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
|
|
8
7
|
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
|
|
9
|
-
jest.mock("../usageQuotas/syncPlugins", () => ({ run: syncPlugins }) )
|
|
10
8
|
|
|
11
|
-
const migration = require("../
|
|
9
|
+
const migration = require("../quotas1")
|
|
12
10
|
|
|
13
11
|
describe("run", () => {
|
|
14
12
|
let config = new TestConfig(false)
|
|
@@ -19,10 +17,9 @@ describe("run", () => {
|
|
|
19
17
|
|
|
20
18
|
afterAll(config.end)
|
|
21
19
|
|
|
22
|
-
it("
|
|
20
|
+
it("runs ", async () => {
|
|
23
21
|
await migration.run()
|
|
24
22
|
expect(syncApps).toHaveBeenCalledTimes(1)
|
|
25
23
|
expect(syncRows).toHaveBeenCalledTimes(1)
|
|
26
|
-
expect(syncPlugins).toHaveBeenCalledTimes(1)
|
|
27
24
|
})
|
|
28
25
|
})
|
|
@@ -2,28 +2,19 @@ import { getTenantId } from "@budibase/backend-core/tenancy"
|
|
|
2
2
|
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
3
|
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
|
|
4
4
|
import { quotas } from "@budibase/pro"
|
|
5
|
-
import {
|
|
5
|
+
import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
|
|
6
6
|
|
|
7
7
|
export const run = async () => {
|
|
8
8
|
// get all rows in all apps
|
|
9
|
+
// @ts-ignore
|
|
9
10
|
const allApps = await getAllApps({ all: true })
|
|
11
|
+
// @ts-ignore
|
|
10
12
|
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
// get the counts per app
|
|
14
|
-
const counts: { [key: string]: number } = {}
|
|
15
|
-
let rowCount = 0
|
|
16
|
-
Object.entries(appRows).forEach(([appId, rows]) => {
|
|
17
|
-
counts[appId] = rows.length
|
|
18
|
-
rowCount += rows.length
|
|
19
|
-
})
|
|
13
|
+
const rows = await getUniqueRows(appIds)
|
|
14
|
+
const rowCount = rows ? rows.length : 0
|
|
20
15
|
|
|
21
16
|
// sync row count
|
|
22
17
|
const tenantId = getTenantId()
|
|
23
18
|
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
|
|
24
|
-
await quotas.
|
|
25
|
-
counts,
|
|
26
|
-
StaticQuotaName.ROWS,
|
|
27
|
-
QuotaUsageType.STATIC
|
|
28
|
-
)
|
|
19
|
+
await quotas.setUsage(rowCount, StaticQuotaName.ROWS, QuotaUsageType.STATIC)
|
|
29
20
|
}
|
|
@@ -2,7 +2,6 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration"
|
|
|
2
2
|
import * as syncRows from "../syncRows"
|
|
3
3
|
import { quotas } from "@budibase/pro"
|
|
4
4
|
import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
|
|
5
|
-
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
6
5
|
|
|
7
6
|
describe("syncRows", () => {
|
|
8
7
|
let config = new TestConfig(false)
|
|
@@ -23,11 +22,10 @@ describe("syncRows", () => {
|
|
|
23
22
|
expect(usageDoc.usageQuota.rows).toEqual(300)
|
|
24
23
|
|
|
25
24
|
// app 1
|
|
26
|
-
const app1 = config.app
|
|
27
25
|
await config.createTable()
|
|
28
26
|
await config.createRow()
|
|
29
27
|
// app 2
|
|
30
|
-
|
|
28
|
+
await config.createApp("second-app")
|
|
31
29
|
await config.createTable()
|
|
32
30
|
await config.createRow()
|
|
33
31
|
await config.createRow()
|
|
@@ -38,12 +36,6 @@ describe("syncRows", () => {
|
|
|
38
36
|
// assert the migration worked
|
|
39
37
|
usageDoc = await quotas.getQuotaUsage()
|
|
40
38
|
expect(usageDoc.usageQuota.rows).toEqual(3)
|
|
41
|
-
expect(usageDoc.apps?.[getProdAppID(app1.appId)].usageQuota.rows).toEqual(
|
|
42
|
-
1
|
|
43
|
-
)
|
|
44
|
-
expect(usageDoc.apps?.[getProdAppID(app2.appId)].usageQuota.rows).toEqual(
|
|
45
|
-
2
|
|
46
|
-
)
|
|
47
39
|
})
|
|
48
40
|
})
|
|
49
41
|
})
|