@budibase/server 1.0.123 → 1.0.125
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.3d890df7.js +1299 -0
- package/builder/assets/index.89795487.css +6 -0
- package/builder/assets/{vendor.8e34a169.js → vendor.5240f480.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +695 -1678
- package/coverage/coverage-final.json +28 -43
- package/coverage/lcov-report/api/controllers/analytics.js.html +8 -3
- package/coverage/lcov-report/api/controllers/apikeys.js.html +9 -4
- package/coverage/lcov-report/api/controllers/auth.js.html +8 -3
- package/coverage/lcov-report/api/controllers/automation.js.html +8 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +8 -3
- package/coverage/lcov-report/api/controllers/cloud.js.html +8 -3
- package/coverage/lcov-report/api/controllers/component.js.html +8 -3
- package/coverage/lcov-report/api/controllers/datasource.js.html +11 -6
- package/coverage/lcov-report/api/controllers/dev.js.html +8 -3
- package/coverage/lcov-report/api/controllers/index.html +16 -26
- package/coverage/lcov-report/api/controllers/integration.js.html +8 -3
- package/coverage/lcov-report/api/controllers/layout.js.html +8 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +8 -3
- package/coverage/lcov-report/api/controllers/migrations.js.html +8 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +8 -3
- package/coverage/lcov-report/api/controllers/query/index.html +16 -26
- package/coverage/lcov-report/api/controllers/query/validation.js.html +8 -3
- package/coverage/lcov-report/api/controllers/role.js.html +10 -5
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -4
- package/coverage/lcov-report/api/controllers/row/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/row/index.html +25 -35
- package/coverage/lcov-report/api/controllers/row/internal.js.html +32 -24
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +21 -16
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -19
- package/coverage/lcov-report/api/controllers/row/utils.js.html +33 -19
- package/coverage/lcov-report/api/controllers/screen.js.html +9 -4
- package/coverage/lcov-report/api/controllers/script.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +55 -50
- package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/index.html +19 -44
- package/coverage/lcov-report/api/controllers/table/index.js.html +20 -15
- package/coverage/lcov-report/api/controllers/templates.js.html +8 -3
- package/coverage/lcov-report/api/controllers/user.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/index.html +8 -3
- package/coverage/lcov-report/api/controllers/view/index.js.html +10 -5
- package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +10 -5
- package/coverage/lcov-report/api/index.html +18 -13
- package/coverage/lcov-report/api/index.js.html +28 -8
- package/coverage/lcov-report/api/routes/analytics.js.html +8 -3
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -3
- package/coverage/lcov-report/api/routes/auth.js.html +8 -3
- package/coverage/lcov-report/api/routes/automation.js.html +8 -3
- package/coverage/lcov-report/api/routes/backup.js.html +8 -3
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -3
- package/coverage/lcov-report/api/routes/component.js.html +8 -3
- package/coverage/lcov-report/api/routes/datasource.js.html +8 -3
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -3
- package/coverage/lcov-report/api/routes/dev.js.html +9 -4
- package/coverage/lcov-report/api/routes/index.html +13 -68
- package/coverage/lcov-report/api/routes/integration.js.html +8 -3
- package/coverage/lcov-report/api/routes/layout.js.html +8 -3
- package/coverage/lcov-report/api/routes/metadata.js.html +8 -3
- package/coverage/lcov-report/api/routes/migrations.js.html +8 -3
- package/coverage/lcov-report/api/routes/permission.js.html +8 -3
- package/coverage/lcov-report/api/routes/query.js.html +8 -3
- package/coverage/lcov-report/api/routes/role.js.html +8 -3
- package/coverage/lcov-report/api/routes/routing.js.html +8 -3
- package/coverage/lcov-report/api/routes/screen.js.html +8 -3
- package/coverage/lcov-report/api/routes/script.js.html +8 -3
- package/coverage/lcov-report/api/routes/table.js.html +8 -3
- package/coverage/lcov-report/api/routes/templates.js.html +8 -3
- package/coverage/lcov-report/api/routes/user.js.html +8 -3
- package/coverage/lcov-report/api/routes/utils/index.html +8 -3
- package/coverage/lcov-report/api/routes/utils/validators.js.html +8 -3
- package/coverage/lcov-report/api/routes/view.js.html +8 -3
- package/coverage/lcov-report/api/routes/webhook.js.html +8 -3
- package/coverage/lcov-report/automations/actions.js.html +21 -7
- package/coverage/lcov-report/automations/automationUtils.js.html +64 -23
- package/coverage/lcov-report/automations/bullboard.js.html +8 -3
- package/coverage/lcov-report/automations/index.html +27 -37
- package/coverage/lcov-report/automations/index.js.html +8 -3
- package/coverage/lcov-report/automations/steps/bash.js.html +8 -3
- package/coverage/lcov-report/automations/steps/delay.js.html +8 -3
- package/coverage/lcov-report/automations/steps/discord.js.html +8 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +8 -3
- package/coverage/lcov-report/automations/steps/executeScript.js.html +8 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +8 -3
- package/coverage/lcov-report/automations/steps/index.html +31 -41
- package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
- package/coverage/lcov-report/{api/routes/static.js.html → automations/steps/loop.js.html} +70 -80
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +9 -4
- package/coverage/lcov-report/automations/steps/queryRows.js.html +9 -4
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +8 -3
- package/coverage/lcov-report/automations/steps/serverLog.js.html +8 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +8 -3
- package/coverage/lcov-report/automations/steps/updateRow.js.html +8 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +14 -9
- package/coverage/lcov-report/automations/steps/zapier.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/index.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +8 -3
- package/coverage/lcov-report/automations/triggers.js.html +16 -11
- package/coverage/lcov-report/block-navigation.js +8 -0
- package/coverage/lcov-report/constants/index.html +12 -7
- package/coverage/lcov-report/constants/index.js.html +55 -32
- package/coverage/lcov-report/constants/layouts.js.html +8 -3
- package/coverage/lcov-report/constants/screens.js.html +8 -3
- package/coverage/lcov-report/db/inMemoryView.js.html +8 -3
- package/coverage/lcov-report/db/index.html +8 -3
- package/coverage/lcov-report/db/index.js.html +9 -4
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +20 -15
- package/coverage/lcov-report/db/linkedRows/index.html +8 -3
- package/coverage/lcov-report/db/linkedRows/index.js.html +22 -17
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +12 -7
- package/coverage/lcov-report/db/newid.js.html +11 -6
- package/coverage/lcov-report/db/utils.js.html +84 -79
- package/coverage/lcov-report/events/AutomationEmitter.js.html +14 -9
- package/coverage/lcov-report/events/index.html +8 -3
- package/coverage/lcov-report/events/index.js.html +9 -4
- package/coverage/lcov-report/events/utils.js.html +18 -13
- package/coverage/lcov-report/index.html +125 -120
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +8 -3
- package/coverage/lcov-report/integrations/tests/index.html +8 -3
- package/coverage/lcov-report/middleware/appInfo.js.html +8 -3
- package/coverage/lcov-report/middleware/builder.js.html +8 -3
- package/coverage/lcov-report/middleware/currentapp.js.html +65 -15
- package/coverage/lcov-report/middleware/index.html +25 -50
- package/coverage/lcov-report/middleware/joi-validator.js.html +9 -4
- package/coverage/lcov-report/middleware/publicApi.js.html +8 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +8 -3
- package/coverage/lcov-report/middleware/selfhost.js.html +9 -4
- package/coverage/lcov-report/middleware/utils.js.html +8 -3
- package/coverage/lcov-report/sorter.js +26 -0
- package/coverage/lcov-report/threads/automation.js.html +581 -90
- package/coverage/lcov-report/threads/index.html +30 -40
- package/coverage/lcov-report/threads/query.js.html +9 -4
- package/coverage/lcov-report/threads/utils.js.html +17 -9
- package/coverage/lcov-report/utilities/bcrypt.js.html +8 -3
- package/coverage/lcov-report/utilities/budibaseDir.js.html +8 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +8 -3
- package/coverage/lcov-report/utilities/csvParser.js.html +10 -5
- package/coverage/lcov-report/utilities/global.js.html +9 -4
- package/coverage/lcov-report/utilities/index.html +8 -3
- package/coverage/lcov-report/utilities/index.js.html +11 -6
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +32 -9
- package/coverage/lcov-report/utilities/queue/index.html +12 -7
- package/coverage/lcov-report/utilities/routing/index.html +8 -3
- package/coverage/lcov-report/utilities/routing/index.js.html +8 -3
- package/coverage/lcov-report/utilities/rowProcessor/index.html +8 -3
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +48 -43
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +18 -13
- package/coverage/lcov-report/utilities/scriptRunner.js.html +8 -3
- package/coverage/lcov-report/utilities/security.js.html +9 -4
- package/coverage/lcov-report/utilities/statusCodes.js.html +8 -3
- package/coverage/lcov-report/utilities/usageQuota/index.html +24 -34
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +44 -39
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +8 -3
- package/coverage/lcov-report/utilities/users.js.html +8 -3
- package/coverage/lcov-report/utilities/workerRequests.js.html +9 -4
- package/coverage/lcov.info +1144 -2875
- package/dist/api/controllers/application.js +145 -73
- package/dist/api/controllers/deploy/index.js +68 -36
- package/dist/api/controllers/public/applications.js +29 -9
- package/dist/api/controllers/public/queries.js +27 -7
- package/dist/api/controllers/public/rows.js +32 -12
- package/dist/api/controllers/public/tables.js +2 -2
- package/dist/api/controllers/public/users.js +8 -8
- package/dist/api/controllers/public/utils.js +1 -1
- package/dist/api/controllers/query/import/index.js +3 -3
- package/dist/api/controllers/query/index.js +57 -44
- package/dist/api/controllers/row/ExternalRequest.js +27 -27
- package/dist/api/controllers/row/index.js +83 -60
- package/dist/api/controllers/row/internal.js +2 -1
- package/dist/api/controllers/row/utils.js +2 -1
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +3 -0
- package/dist/api/controllers/table/bulkFormula.js +2 -1
- package/dist/api/controllers/table/internal.js +41 -35
- package/dist/api/controllers/table/utils.js +271 -229
- package/dist/api/index.js +5 -0
- package/dist/api/routes/application.js +39 -13
- package/dist/api/routes/index.js +61 -56
- package/dist/api/routes/public/index.js +6 -9
- package/dist/api/routes/public/queries.js +1 -1
- package/dist/api/routes/public/rows.js +1 -1
- package/dist/api/routes/public/tables.js +3 -3
- package/dist/api/routes/public/users.js +1 -1
- package/dist/api/routes/row.js +43 -17
- package/dist/api/routes/static.js +40 -13
- package/dist/api/routes/tests/utilities/TestFunctions.js +75 -33
- package/dist/app.js +8 -4
- package/dist/automations/actions.js +3 -0
- package/dist/automations/automationUtils.js +10 -0
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +13 -16
- package/dist/automations/steps/loop.js +51 -0
- package/dist/automations/tests/utilities/index.js +13 -11
- package/dist/automations/utils.js +187 -133
- package/dist/constants/index.js +5 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +2 -3
- package/dist/index.js +4 -0
- package/dist/integrations/base/sql.js +2 -2
- package/dist/integrations/base/sqlTable.js +2 -2
- package/dist/integrations/googlesheets.js +1 -1
- package/dist/integrations/index.js +4 -0
- package/dist/integrations/microsoftSqlServer.js +8 -8
- package/dist/integrations/mysql.js +9 -9
- package/dist/integrations/oracle.js +7 -7
- package/dist/integrations/postgres.js +7 -7
- package/dist/integrations/queries/sql.js +2 -2
- package/dist/integrations/redis.js +158 -0
- package/dist/integrations/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- package/dist/middleware/currentapp.js +15 -1
- package/dist/migrations/functions/appUrls.js +1 -1
- package/dist/migrations/functions/developerQuota.js +49 -0
- package/dist/migrations/functions/publishedAppsQuota.js +47 -0
- package/dist/migrations/functions/quotas1.js +6 -2
- package/dist/migrations/functions/usageQuotas/index.js +0 -4
- package/dist/migrations/functions/usageQuotas/syncApps.js +4 -7
- package/dist/migrations/functions/usageQuotas/syncDevelopers.js +24 -0
- package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +26 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +5 -8
- package/dist/migrations/index.js +17 -1
- package/dist/package.json +14 -8
- package/dist/threads/automation.js +149 -27
- package/dist/threads/index.js +36 -10
- package/dist/threads/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +6 -1
- package/nodemon.json +1 -1
- package/package.json +15 -9
- package/scripts/dev/manage.js +2 -0
- package/src/api/controllers/{application.js → application.ts} +118 -51
- package/src/api/controllers/deploy/{index.js → index.ts} +53 -29
- package/src/api/controllers/public/applications.ts +2 -2
- package/src/api/controllers/public/queries.ts +1 -1
- package/src/api/controllers/public/rows.ts +1 -1
- package/src/api/controllers/query/{index.js → index.ts} +51 -48
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/{index.js → index.ts} +24 -17
- package/src/api/controllers/row/internal.js +2 -1
- package/src/api/controllers/row/utils.js +4 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +3 -0
- package/src/api/controllers/table/bulkFormula.js +1 -1
- package/src/api/controllers/table/{internal.js → internal.ts} +30 -26
- package/src/api/controllers/table/{utils.js → utils.ts} +86 -69
- package/src/api/index.js +5 -0
- package/src/api/routes/{application.js → application.ts} +8 -14
- package/src/api/routes/index.ts +60 -0
- package/src/api/routes/public/index.ts +1 -4
- package/src/api/routes/{row.js → row.ts} +7 -15
- package/src/api/routes/{static.js → static.ts} +11 -11
- package/src/api/routes/tests/misc.spec.js +39 -37
- package/src/api/routes/tests/utilities/{TestFunctions.js → TestFunctions.ts} +57 -33
- package/src/app.ts +1 -2
- package/src/automations/actions.js +3 -0
- package/src/automations/automationUtils.js +12 -0
- package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
- package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
- package/src/automations/steps/loop.js +50 -0
- package/src/automations/tests/automation.spec.js +0 -1
- package/src/automations/tests/{createRow.spec.js → createRow.spec.ts} +4 -15
- package/src/automations/tests/{deleteRow.spec.js → deleteRow.spec.ts} +3 -5
- package/src/automations/tests/utilities/index.js +12 -10
- package/src/automations/{utils.js → utils.ts} +39 -28
- package/src/constants/index.js +6 -0
- package/src/definitions/common.ts +1 -0
- package/src/definitions/datasource.ts +1 -0
- package/src/environment.js +2 -3
- package/src/index.ts +3 -0
- package/src/integrations/index.ts +4 -0
- package/src/integrations/redis.ts +152 -0
- package/src/integrations/tests/redis.spec.js +60 -0
- package/src/middleware/{authorized.js → authorized.ts} +20 -14
- package/src/middleware/currentapp.js +16 -1
- package/src/middleware/tests/currentapp.spec.js +8 -4
- package/src/migrations/functions/developerQuota.ts +15 -0
- package/src/migrations/functions/publishedAppsQuota.ts +13 -0
- package/src/migrations/functions/tests/quotas1.spec.js +0 -2
- package/src/migrations/functions/usageQuotas/index.ts +0 -5
- package/src/migrations/functions/usageQuotas/syncApps.ts +3 -6
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +3 -6
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +34 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +40 -0
- package/src/migrations/index.ts +13 -1
- package/src/threads/automation.js +196 -34
- package/src/threads/{index.js → index.ts} +18 -14
- package/src/threads/utils.js +1 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -1
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +2 -2
- package/builder/assets/index.68a7f4e3.css +0 -6
- package/builder/assets/index.8d4a5b33.js +0 -1291
- package/coverage/lcov-report/api/controllers/application.js.html +0 -1436
- package/coverage/lcov-report/api/controllers/query/index.js.html +0 -713
- package/coverage/lcov-report/api/controllers/row/index.js.html +0 -524
- package/coverage/lcov-report/api/controllers/table/internal.js.html +0 -620
- package/coverage/lcov-report/api/controllers/table/utils.js.html +0 -1331
- package/coverage/lcov-report/api/routes/application.js.html +0 -179
- package/coverage/lcov-report/api/routes/index.js.html +0 -266
- package/coverage/lcov-report/api/routes/row.js.html +0 -908
- package/coverage/lcov-report/automations/steps/createRow.js.html +0 -380
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +0 -347
- package/coverage/lcov-report/automations/utils.js.html +0 -665
- package/coverage/lcov-report/middleware/authorized.js.html +0 -458
- package/coverage/lcov-report/middleware/usageQuota.js.html +0 -572
- package/coverage/lcov-report/threads/index.js.html +0 -296
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
- package/dist/middleware/usageQuota.js +0 -154
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/utilities/usageQuota/index.js +0 -86
- package/src/api/routes/index.js +0 -62
- package/src/middleware/tests/usageQuota.spec.js +0 -120
- package/src/middleware/usageQuota.js +0 -164
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -41
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -45
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -93
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { invalidateDynamicVariables } = require("../../../threads/utils")
|
|
11
|
-
const environment = require("../../../environment")
|
|
12
|
-
const { getAppDB } = require("@budibase/backend-core/context")
|
|
1
|
+
import { generateQueryID, getQueryParams, isProdAppID } from "../../../db/utils"
|
|
2
|
+
import { BaseQueryVerbs } from "../../../constants"
|
|
3
|
+
import { Thread, ThreadType } from "../../../threads"
|
|
4
|
+
import { save as saveDatasource } from "../datasource"
|
|
5
|
+
import { RestImporter } from "./import"
|
|
6
|
+
import { invalidateDynamicVariables } from "../../../threads/utils"
|
|
7
|
+
import { QUERY_THREAD_TIMEOUT } from "../../../environment"
|
|
8
|
+
import { getAppDB } from "@budibase/backend-core/context"
|
|
9
|
+
import { quotas } from "@budibase/pro"
|
|
13
10
|
|
|
14
11
|
const Runner = new Thread(ThreadType.QUERY, {
|
|
15
|
-
timeoutMs:
|
|
12
|
+
timeoutMs: QUERY_THREAD_TIMEOUT || 10000,
|
|
16
13
|
})
|
|
17
14
|
|
|
18
15
|
// simple function to append "readable" to all read queries
|
|
19
|
-
function enrichQueries(input) {
|
|
16
|
+
function enrichQueries(input: any) {
|
|
20
17
|
const wasArray = Array.isArray(input)
|
|
21
18
|
const queries = wasArray ? input : [input]
|
|
22
19
|
for (let query of queries) {
|
|
@@ -27,7 +24,7 @@ function enrichQueries(input) {
|
|
|
27
24
|
return wasArray ? queries : queries[0]
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
|
|
27
|
+
export async function fetch(ctx: any) {
|
|
31
28
|
const db = getAppDB()
|
|
32
29
|
|
|
33
30
|
const body = await db.allDocs(
|
|
@@ -36,10 +33,10 @@ exports.fetch = async function (ctx) {
|
|
|
36
33
|
})
|
|
37
34
|
)
|
|
38
35
|
|
|
39
|
-
ctx.body = enrichQueries(body.rows.map(row => row.doc))
|
|
36
|
+
ctx.body = enrichQueries(body.rows.map((row: any) => row.doc))
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
const _import = async (ctx: any) => {
|
|
43
40
|
const body = ctx.request.body
|
|
44
41
|
const data = body.data
|
|
45
42
|
|
|
@@ -49,7 +46,7 @@ exports.import = async ctx => {
|
|
|
49
46
|
let datasourceId
|
|
50
47
|
if (!body.datasourceId) {
|
|
51
48
|
// construct new datasource
|
|
52
|
-
const info = await importer.getInfo()
|
|
49
|
+
const info: any = await importer.getInfo()
|
|
53
50
|
let datasource = {
|
|
54
51
|
type: "datasource",
|
|
55
52
|
source: "REST",
|
|
@@ -77,8 +74,9 @@ exports.import = async ctx => {
|
|
|
77
74
|
}
|
|
78
75
|
ctx.status = 200
|
|
79
76
|
}
|
|
77
|
+
export { _import as import }
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
export async function save(ctx: any) {
|
|
82
80
|
const db = getAppDB()
|
|
83
81
|
const query = ctx.request.body
|
|
84
82
|
|
|
@@ -93,7 +91,7 @@ exports.save = async function (ctx) {
|
|
|
93
91
|
ctx.message = `Query ${query.name} saved successfully.`
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
export async function find(ctx: any) {
|
|
97
95
|
const db = getAppDB()
|
|
98
96
|
const query = enrichQueries(await db.get(ctx.params.queryId))
|
|
99
97
|
// remove properties that could be dangerous in real app
|
|
@@ -104,7 +102,7 @@ exports.find = async function (ctx) {
|
|
|
104
102
|
ctx.body = query
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
|
|
105
|
+
export async function preview(ctx: any) {
|
|
108
106
|
const db = getAppDB()
|
|
109
107
|
|
|
110
108
|
const datasource = await db.get(ctx.request.body.datasourceId)
|
|
@@ -114,16 +112,18 @@ exports.preview = async function (ctx) {
|
|
|
114
112
|
ctx.request.body
|
|
115
113
|
|
|
116
114
|
try {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
const runFn = () =>
|
|
116
|
+
Runner.run({
|
|
117
|
+
appId: ctx.appId,
|
|
118
|
+
datasource,
|
|
119
|
+
queryVerb,
|
|
120
|
+
fields,
|
|
121
|
+
parameters,
|
|
122
|
+
transformer,
|
|
123
|
+
queryId,
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
const { rows, keys, info, extra } = await quotas.addQuery(runFn)
|
|
127
127
|
ctx.body = {
|
|
128
128
|
rows,
|
|
129
129
|
schemaFields: [...new Set(keys)],
|
|
@@ -135,7 +135,7 @@ exports.preview = async function (ctx) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
async function execute(ctx, opts = { rowsOnly: false }) {
|
|
138
|
+
async function execute(ctx: any, opts = { rowsOnly: false }) {
|
|
139
139
|
const db = getAppDB()
|
|
140
140
|
|
|
141
141
|
const query = await db.get(ctx.params.queryId)
|
|
@@ -153,16 +153,19 @@ async function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
153
153
|
|
|
154
154
|
// call the relevant CRUD method on the integration class
|
|
155
155
|
try {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
156
|
+
const runFn = () =>
|
|
157
|
+
Runner.run({
|
|
158
|
+
appId: ctx.appId,
|
|
159
|
+
datasource,
|
|
160
|
+
queryVerb: query.queryVerb,
|
|
161
|
+
fields: query.fields,
|
|
162
|
+
pagination: ctx.request.body.pagination,
|
|
163
|
+
parameters: enrichedParameters,
|
|
164
|
+
transformer: query.transformer,
|
|
165
|
+
queryId: ctx.params.queryId,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const { rows, pagination, extra } = await quotas.addQuery(runFn)
|
|
166
169
|
if (opts && opts.rowsOnly) {
|
|
167
170
|
ctx.body = rows
|
|
168
171
|
} else {
|
|
@@ -173,15 +176,15 @@ async function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
|
|
179
|
+
export async function executeV1(ctx: any) {
|
|
177
180
|
return execute(ctx, { rowsOnly: true })
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
|
|
183
|
+
export async function executeV2(ctx: any) {
|
|
181
184
|
return execute(ctx, { rowsOnly: false })
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
const removeDynamicVariables = async queryId => {
|
|
187
|
+
const removeDynamicVariables = async (queryId: any) => {
|
|
185
188
|
const db = getAppDB()
|
|
186
189
|
const query = await db.get(queryId)
|
|
187
190
|
const datasource = await db.get(query.datasourceId)
|
|
@@ -190,19 +193,19 @@ const removeDynamicVariables = async queryId => {
|
|
|
190
193
|
if (dynamicVariables) {
|
|
191
194
|
// delete dynamic variables from the datasource
|
|
192
195
|
datasource.config.dynamicVariables = dynamicVariables.filter(
|
|
193
|
-
dv => dv.queryId !== queryId
|
|
196
|
+
(dv: any) => dv.queryId !== queryId
|
|
194
197
|
)
|
|
195
198
|
await db.put(datasource)
|
|
196
199
|
|
|
197
200
|
// invalidate the deleted variables
|
|
198
201
|
const variablesToDelete = dynamicVariables.filter(
|
|
199
|
-
dv => dv.queryId === queryId
|
|
202
|
+
(dv: any) => dv.queryId === queryId
|
|
200
203
|
)
|
|
201
204
|
await invalidateDynamicVariables(variablesToDelete)
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
|
|
205
|
-
|
|
208
|
+
export async function destroy(ctx: any) {
|
|
206
209
|
const db = getAppDB()
|
|
207
210
|
await removeDynamicVariables(ctx.params.queryId)
|
|
208
211
|
await db.remove(ctx.params.queryId, ctx.params.revId)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { quotas } from "@budibase/pro"
|
|
2
|
+
import internal from "./internal"
|
|
3
|
+
import external from "./external"
|
|
4
|
+
import { isExternalTable } from "../../../integrations/utils"
|
|
4
5
|
|
|
5
|
-
function pickApi(tableId) {
|
|
6
|
+
function pickApi(tableId: any) {
|
|
6
7
|
if (isExternalTable(tableId)) {
|
|
7
8
|
return external
|
|
8
9
|
}
|
|
9
10
|
return internal
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
function getTableId(ctx) {
|
|
13
|
+
function getTableId(ctx: any) {
|
|
13
14
|
if (ctx.request.body && ctx.request.body.tableId) {
|
|
14
15
|
return ctx.request.body.tableId
|
|
15
16
|
}
|
|
@@ -21,13 +22,13 @@ function getTableId(ctx) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
export async function patch(ctx: any): Promise<any> {
|
|
25
26
|
const appId = ctx.appId
|
|
26
27
|
const tableId = getTableId(ctx)
|
|
27
28
|
const body = ctx.request.body
|
|
28
29
|
// if it doesn't have an _id then its save
|
|
29
30
|
if (body && !body._id) {
|
|
30
|
-
return
|
|
31
|
+
return save(ctx)
|
|
31
32
|
}
|
|
32
33
|
try {
|
|
33
34
|
const { row, table } = await pickApi(tableId).patch(ctx)
|
|
@@ -41,13 +42,13 @@ exports.patch = async ctx => {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
const saveRow = async (ctx: any) => {
|
|
45
46
|
const appId = ctx.appId
|
|
46
47
|
const tableId = getTableId(ctx)
|
|
47
48
|
const body = ctx.request.body
|
|
48
49
|
// if it has an ID already then its a patch
|
|
49
50
|
if (body && body._id) {
|
|
50
|
-
return
|
|
51
|
+
return patch(ctx)
|
|
51
52
|
}
|
|
52
53
|
try {
|
|
53
54
|
const { row, table } = await pickApi(tableId).save(ctx)
|
|
@@ -60,7 +61,11 @@ exports.save = async function (ctx) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
export async function save(ctx: any) {
|
|
65
|
+
await quotas.addRow(() => saveRow(ctx))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function fetchView(ctx: any) {
|
|
64
69
|
const tableId = getTableId(ctx)
|
|
65
70
|
try {
|
|
66
71
|
ctx.body = await pickApi(tableId).fetchView(ctx)
|
|
@@ -69,7 +74,7 @@ exports.fetchView = async function (ctx) {
|
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
export async function fetch(ctx: any) {
|
|
73
78
|
const tableId = getTableId(ctx)
|
|
74
79
|
try {
|
|
75
80
|
ctx.body = await pickApi(tableId).fetch(ctx)
|
|
@@ -78,7 +83,7 @@ exports.fetch = async function (ctx) {
|
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
export async function find(ctx: any) {
|
|
82
87
|
const tableId = getTableId(ctx)
|
|
83
88
|
try {
|
|
84
89
|
ctx.body = await pickApi(tableId).find(ctx)
|
|
@@ -87,19 +92,21 @@ exports.find = async function (ctx) {
|
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
export async function destroy(ctx: any) {
|
|
91
96
|
const appId = ctx.appId
|
|
92
97
|
const inputs = ctx.request.body
|
|
93
98
|
const tableId = getTableId(ctx)
|
|
94
99
|
let response, row
|
|
95
100
|
if (inputs.rows) {
|
|
96
101
|
let { rows } = await pickApi(tableId).bulkDestroy(ctx)
|
|
102
|
+
await quotas.removeRows(rows.length)
|
|
97
103
|
response = rows
|
|
98
104
|
for (let row of rows) {
|
|
99
105
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
|
100
106
|
}
|
|
101
107
|
} else {
|
|
102
108
|
let resp = await pickApi(tableId).destroy(ctx)
|
|
109
|
+
await quotas.removeRow()
|
|
103
110
|
response = resp.response
|
|
104
111
|
row = resp.row
|
|
105
112
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
|
@@ -110,7 +117,7 @@ exports.destroy = async function (ctx) {
|
|
|
110
117
|
ctx.body = response
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
export async function search(ctx: any) {
|
|
114
121
|
const tableId = getTableId(ctx)
|
|
115
122
|
try {
|
|
116
123
|
ctx.status = 200
|
|
@@ -120,7 +127,7 @@ exports.search = async ctx => {
|
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|
|
123
|
-
|
|
130
|
+
export async function validate(ctx: any) {
|
|
124
131
|
const tableId = getTableId(ctx)
|
|
125
132
|
try {
|
|
126
133
|
ctx.body = await pickApi(tableId).validate(ctx)
|
|
@@ -129,7 +136,7 @@ exports.validate = async function (ctx) {
|
|
|
129
136
|
}
|
|
130
137
|
}
|
|
131
138
|
|
|
132
|
-
|
|
139
|
+
export async function fetchEnrichedRow(ctx: any) {
|
|
133
140
|
const tableId = getTableId(ctx)
|
|
134
141
|
try {
|
|
135
142
|
ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
|
|
@@ -138,7 +145,7 @@ exports.fetchEnrichedRow = async function (ctx) {
|
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
export const exportRows = async (ctx: any) => {
|
|
142
149
|
const tableId = getTableId(ctx)
|
|
143
150
|
try {
|
|
144
151
|
ctx.body = await pickApi(tableId).exportRows(ctx)
|
|
@@ -260,8 +260,9 @@ exports.find = async ctx => {
|
|
|
260
260
|
|
|
261
261
|
exports.destroy = async function (ctx) {
|
|
262
262
|
const db = getAppDB()
|
|
263
|
-
const { _id
|
|
263
|
+
const { _id } = ctx.request.body
|
|
264
264
|
let row = await db.get(_id)
|
|
265
|
+
let _rev = ctx.request.body._rev || row._rev
|
|
265
266
|
|
|
266
267
|
if (row.tableId !== ctx.params.tableId) {
|
|
267
268
|
throw "Supplied tableId doesn't match the row's tableId"
|
|
@@ -65,7 +65,10 @@ exports.validate = async ({ tableId, row, table }) => {
|
|
|
65
65
|
if (type === FieldTypes.ARRAY && row[fieldName]) {
|
|
66
66
|
if (row[fieldName].length) {
|
|
67
67
|
row[fieldName].map(val => {
|
|
68
|
-
if (
|
|
68
|
+
if (
|
|
69
|
+
!constraints.inclusion.includes(val) &&
|
|
70
|
+
constraints.inclusion.length !== 0
|
|
71
|
+
) {
|
|
69
72
|
errors[fieldName] = "Field not in list"
|
|
70
73
|
}
|
|
71
74
|
})
|
|
@@ -25,7 +25,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
25
25
|
if (!isStaticFormula(column)) {
|
|
26
26
|
continue
|
|
27
27
|
}
|
|
28
|
-
if (!doesContainStrings(column
|
|
28
|
+
if (!doesContainStrings(column?.formula ?? "", columnNames)) {
|
|
29
29
|
continue
|
|
30
30
|
}
|
|
31
31
|
formula.push(column.name)
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { updateLinks, EventType } from "../../../db/linkedRows"
|
|
2
|
+
import { getRowParams, generateTableID } from "../../../db/utils"
|
|
3
|
+
import { FieldTypes } from "../../../constants"
|
|
4
|
+
import {
|
|
5
5
|
TableSaveFunctions,
|
|
6
6
|
hasTypeChanged,
|
|
7
7
|
getTable,
|
|
8
8
|
handleDataImport,
|
|
9
|
-
}
|
|
10
|
-
const usageQuota = require("../../../utilities/usageQuota")
|
|
9
|
+
} from "./utils"
|
|
11
10
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import { isTest } from "../../../environment"
|
|
12
|
+
import {
|
|
14
13
|
cleanupAttachments,
|
|
15
14
|
fixAutoColumnSubType,
|
|
16
|
-
}
|
|
17
|
-
|
|
15
|
+
} from "../../../utilities/rowProcessor"
|
|
16
|
+
import { runStaticFormulaChecks } from "./bulkFormula"
|
|
17
|
+
import { Table } from "../../../definitions/common"
|
|
18
|
+
import { quotas } from "@budibase/pro"
|
|
18
19
|
|
|
19
|
-
function checkAutoColumns(table, oldTable) {
|
|
20
|
+
function checkAutoColumns(table: Table, oldTable: Table) {
|
|
20
21
|
if (!table.schema) {
|
|
21
22
|
return table
|
|
22
23
|
}
|
|
@@ -34,7 +35,7 @@ function checkAutoColumns(table, oldTable) {
|
|
|
34
35
|
return table
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
export async function save(ctx: any) {
|
|
38
39
|
const db = getAppDB()
|
|
39
40
|
const { dataImport, ...rest } = ctx.request.body
|
|
40
41
|
let tableToSave = {
|
|
@@ -104,10 +105,8 @@ exports.save = async function (ctx) {
|
|
|
104
105
|
|
|
105
106
|
// update linked rows
|
|
106
107
|
try {
|
|
107
|
-
const linkResp = await
|
|
108
|
-
eventType: oldTable
|
|
109
|
-
? linkRows.EventType.TABLE_UPDATED
|
|
110
|
-
: linkRows.EventType.TABLE_SAVE,
|
|
108
|
+
const linkResp: any = await updateLinks({
|
|
109
|
+
eventType: oldTable ? EventType.TABLE_UPDATED : EventType.TABLE_SAVE,
|
|
111
110
|
table: tableToSave,
|
|
112
111
|
oldTable: oldTable,
|
|
113
112
|
})
|
|
@@ -129,11 +128,11 @@ exports.save = async function (ctx) {
|
|
|
129
128
|
|
|
130
129
|
tableToSave = await tableSaveFunctions.after(tableToSave)
|
|
131
130
|
// has to run after, make sure it has _id
|
|
132
|
-
await runStaticFormulaChecks(tableToSave, { oldTable })
|
|
131
|
+
await runStaticFormulaChecks(tableToSave, { oldTable, deletion: null })
|
|
133
132
|
return tableToSave
|
|
134
133
|
}
|
|
135
134
|
|
|
136
|
-
|
|
135
|
+
export async function destroy(ctx: any) {
|
|
137
136
|
const db = getAppDB()
|
|
138
137
|
const tableToDelete = await db.get(ctx.params.tableId)
|
|
139
138
|
|
|
@@ -143,12 +142,14 @@ exports.destroy = async function (ctx) {
|
|
|
143
142
|
include_docs: true,
|
|
144
143
|
})
|
|
145
144
|
)
|
|
146
|
-
await db.bulkDocs(
|
|
147
|
-
|
|
145
|
+
await db.bulkDocs(
|
|
146
|
+
rows.rows.map((row: any) => ({ ...row.doc, _deleted: true }))
|
|
147
|
+
)
|
|
148
|
+
await quotas.removeRows(rows.rows.length)
|
|
148
149
|
|
|
149
150
|
// update linked rows
|
|
150
|
-
await
|
|
151
|
-
eventType:
|
|
151
|
+
await updateLinks({
|
|
152
|
+
eventType: EventType.TABLE_DELETE,
|
|
152
153
|
table: tableToDelete,
|
|
153
154
|
})
|
|
154
155
|
|
|
@@ -156,10 +157,10 @@ exports.destroy = async function (ctx) {
|
|
|
156
157
|
await db.remove(tableToDelete)
|
|
157
158
|
|
|
158
159
|
// remove table search index
|
|
159
|
-
if (!
|
|
160
|
+
if (!isTest()) {
|
|
160
161
|
const currentIndexes = await db.getIndexes()
|
|
161
162
|
const existingIndex = currentIndexes.indexes.find(
|
|
162
|
-
existing => existing.name === `search:${ctx.params.tableId}`
|
|
163
|
+
(existing: any) => existing.name === `search:${ctx.params.tableId}`
|
|
163
164
|
)
|
|
164
165
|
if (existingIndex) {
|
|
165
166
|
await db.deleteIndex(existingIndex)
|
|
@@ -167,12 +168,15 @@ exports.destroy = async function (ctx) {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
// has to run after, make sure it has _id
|
|
170
|
-
await runStaticFormulaChecks(tableToDelete, {
|
|
171
|
+
await runStaticFormulaChecks(tableToDelete, {
|
|
172
|
+
oldTable: null,
|
|
173
|
+
deletion: true,
|
|
174
|
+
})
|
|
171
175
|
await cleanupAttachments(tableToDelete, { rows })
|
|
172
176
|
return tableToDelete
|
|
173
177
|
}
|
|
174
178
|
|
|
175
|
-
|
|
179
|
+
export async function bulkImport(ctx: any) {
|
|
176
180
|
const table = await getTable(ctx.params.tableId)
|
|
177
181
|
const { dataImport } = ctx.request.body
|
|
178
182
|
await handleDataImport(ctx.user, table, dataImport)
|