@budibase/server 1.0.200-alpha.3 → 1.0.200
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/Dockerfile +0 -2
- package/builder/assets/index.f83b3433.js +1315 -0
- package/builder/index.html +1 -1
- package/coverage/clover.xml +1998 -2086
- package/coverage/coverage-final.json +122 -121
- package/coverage/lcov-report/api/controllers/analytics.js.html +202 -0
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +72 -174
- package/coverage/lcov-report/api/controllers/backup.js.html +6 -30
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +41 -53
- package/coverage/lcov-report/api/controllers/dev.js.html +70 -94
- package/coverage/lcov-report/api/controllers/index.html +72 -57
- package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
- package/coverage/lcov-report/api/controllers/layout.js.html +19 -28
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
- package/coverage/lcov-report/api/controllers/role.js.html +48 -78
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
- package/coverage/lcov-report/api/controllers/screen.js.html +20 -56
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
- package/coverage/lcov-report/api/controllers/table/external.js.html +17 -23
- package/coverage/lcov-report/api/controllers/table/index.html +26 -26
- package/coverage/lcov-report/api/controllers/table/index.js.html +49 -85
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/index.html +21 -21
- package/coverage/lcov-report/api/controllers/view/index.js.html +65 -275
- package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
- package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
- package/coverage/lcov-report/api/index.html +15 -15
- package/coverage/lcov-report/api/index.js.html +45 -39
- package/coverage/lcov-report/api/routes/analytics.js.html +13 -7
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
- package/coverage/lcov-report/automations/actions.js.html +25 -25
- package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
- package/coverage/lcov-report/automations/bullboard.js.html +35 -35
- package/coverage/lcov-report/automations/index.html +29 -29
- package/coverage/lcov-report/automations/index.js.html +17 -29
- package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +18 -18
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +30 -30
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +9 -9
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +81 -81
- 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 +7 -7
- package/coverage/lcov-report/events/utils.js.html +10 -10
- package/coverage/lcov-report/index.html +74 -74
- 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 +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +20 -20
- package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +1 -1
- package/coverage/lcov-report/threads/utils.js.html +13 -13
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
- package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
- package/coverage/lcov-report/utilities/global.js.html +28 -28
- package/coverage/lcov-report/utilities/index.html +25 -25
- package/coverage/lcov-report/utilities/index.js.html +41 -41
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
- package/coverage/lcov-report/utilities/queue/index.html +15 -15
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +7 -7
- package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
- package/coverage/lcov.info +2762 -2903
- package/dist/api/controllers/analytics.js +30 -7
- package/dist/api/controllers/application.js +16 -56
- package/dist/api/controllers/automation.js +2 -31
- package/dist/api/controllers/backup.js +0 -7
- package/dist/api/controllers/datasource.js +2 -8
- package/dist/api/controllers/deploy/index.js +2 -6
- package/dist/api/controllers/dev.js +2 -9
- package/dist/api/controllers/layout.js +0 -3
- package/dist/api/controllers/query/import/index.js +2 -12
- package/dist/api/controllers/query/import/sources/curl.js +0 -3
- package/dist/api/controllers/query/import/sources/openapi2.js +0 -3
- package/dist/api/controllers/query/import/sources/openapi3.js +0 -3
- package/dist/api/controllers/query/index.js +2 -16
- package/dist/api/controllers/role.js +0 -11
- package/dist/api/controllers/screen.js +1 -10
- package/dist/api/controllers/static/index.js +15 -29
- package/dist/api/controllers/table/external.js +0 -2
- package/dist/api/controllers/table/index.js +0 -12
- package/dist/api/controllers/table/utils.js +3 -3
- package/dist/api/controllers/view/index.js +6 -62
- package/dist/api/index.js +4 -2
- package/dist/api/routes/analytics.js +3 -1
- package/dist/app.js +8 -16
- package/dist/automations/index.js +0 -4
- package/dist/automations/steps/executeQuery.js +1 -1
- package/dist/environment.js +2 -4
- package/dist/integrations/firebase.js +0 -1
- package/dist/migrations/index.js +31 -95
- package/dist/package.json +69 -79
- package/dist/tests/utilities/TestConfiguration.js +93 -121
- package/dist/tests/utilities/structures.js +0 -45
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/nodemon.json +1 -1
- package/package.json +70 -80
- package/scripts/dev/manage.js +0 -2
- package/scripts/jestSetup.js +0 -7
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/analytics.js +39 -0
- package/src/api/controllers/application.ts +18 -60
- package/src/api/controllers/automation.js +2 -36
- package/src/api/controllers/backup.js +0 -8
- package/src/api/controllers/datasource.js +4 -8
- package/src/api/controllers/deploy/index.ts +2 -6
- package/src/api/controllers/dev.js +2 -10
- package/src/api/controllers/layout.js +0 -3
- package/src/api/controllers/query/import/index.ts +3 -16
- package/src/api/controllers/query/import/sources/base/index.ts +1 -2
- package/src/api/controllers/query/import/sources/curl.ts +0 -4
- package/src/api/controllers/query/import/sources/openapi2.ts +0 -4
- package/src/api/controllers/query/import/sources/openapi3.ts +0 -4
- package/src/api/controllers/query/import/tests/index.spec.js +7 -20
- package/src/api/controllers/query/index.ts +3 -16
- package/src/api/controllers/role.js +0 -10
- package/src/api/controllers/screen.js +1 -13
- package/src/api/controllers/static/index.js +15 -28
- package/src/api/controllers/table/external.js +0 -2
- package/src/api/controllers/table/index.js +0 -12
- package/src/api/controllers/table/utils.ts +4 -4
- package/src/api/controllers/view/index.js +6 -76
- package/src/api/index.js +4 -2
- package/src/api/routes/analytics.js +3 -1
- package/src/api/routes/public/utils/Endpoint.ts +1 -1
- package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +1 -5
- package/src/api/routes/tests/application.spec.js +4 -64
- package/src/api/routes/tests/automation.spec.js +60 -168
- package/src/api/routes/tests/backup.spec.js +0 -2
- package/src/api/routes/tests/datasource.spec.js +0 -5
- package/src/api/routes/tests/layout.spec.js +0 -4
- package/src/api/routes/tests/query.spec.js +13 -56
- package/src/api/routes/tests/role.spec.js +7 -40
- package/src/api/routes/tests/row.spec.js +3 -2
- package/src/api/routes/tests/screen.spec.js +4 -30
- package/src/api/routes/tests/static.spec.js +54 -120
- package/src/api/routes/tests/table.spec.js +38 -102
- package/src/api/routes/tests/view.spec.js +43 -222
- package/src/app.ts +9 -18
- package/src/automations/index.js +0 -4
- package/src/automations/steps/executeQuery.js +1 -1
- package/src/automations/tests/delay.spec.js +0 -4
- package/src/environment.js +2 -5
- package/src/integrations/firebase.ts +0 -1
- package/src/migrations/index.ts +51 -120
- package/src/module.d.ts +1 -0
- package/src/tests/utilities/TestConfiguration.js +90 -138
- package/src/tests/utilities/structures.js +0 -71
- package/tsconfig.build.json +5 -20
- package/tsconfig.json +17 -22
- package/builder/assets/index.05491b9d.js +0 -1315
- package/dist/migrations/functions/backfill/app/automations.js +0 -31
- package/dist/migrations/functions/backfill/app/datasources.js +0 -28
- package/dist/migrations/functions/backfill/app/layouts.js +0 -33
- package/dist/migrations/functions/backfill/app/queries.js +0 -32
- package/dist/migrations/functions/backfill/app/roles.js +0 -28
- package/dist/migrations/functions/backfill/app/screens.js +0 -28
- package/dist/migrations/functions/backfill/app/tables.js +0 -40
- package/dist/migrations/functions/backfill/app.js +0 -175
- package/dist/migrations/functions/backfill/global/configs.js +0 -61
- package/dist/migrations/functions/backfill/global/quotas.js +0 -60
- package/dist/migrations/functions/backfill/global/users.js +0 -50
- package/dist/migrations/functions/backfill/global.js +0 -189
- package/dist/migrations/functions/backfill/index.js +0 -32
- package/dist/migrations/functions/backfill/installation.js +0 -80
- package/dist/migrations/tests/helpers.js +0 -72
- package/dist/migrations/tests/structures.js +0 -37
- package/src/api/controllers/analytics.ts +0 -8
- package/src/api/routes/tests/data/export.txt +0 -1
- package/src/api/routes/tests/deployment.spec.js +0 -25
- package/src/api/routes/tests/dev.spec.js +0 -40
- package/src/migrations/functions/backfill/app/automations.ts +0 -26
- package/src/migrations/functions/backfill/app/datasources.ts +0 -22
- package/src/migrations/functions/backfill/app/layouts.ts +0 -29
- package/src/migrations/functions/backfill/app/queries.ts +0 -33
- package/src/migrations/functions/backfill/app/roles.ts +0 -22
- package/src/migrations/functions/backfill/app/screens.ts +0 -22
- package/src/migrations/functions/backfill/app/tables.ts +0 -36
- package/src/migrations/functions/backfill/app.ts +0 -148
- package/src/migrations/functions/backfill/global/configs.ts +0 -66
- package/src/migrations/functions/backfill/global/quotas.ts +0 -60
- package/src/migrations/functions/backfill/global/users.ts +0 -49
- package/src/migrations/functions/backfill/global.ts +0 -194
- package/src/migrations/functions/backfill/index.ts +0 -7
- package/src/migrations/functions/backfill/installation.ts +0 -50
- package/src/migrations/tests/helpers.ts +0 -40
- package/src/migrations/tests/index.spec.ts +0 -132
- package/src/migrations/tests/structures.ts +0 -66
|
@@ -7,7 +7,6 @@ const { Replication, getProdAppID } = require("@budibase/backend-core/db")
|
|
|
7
7
|
const { DocumentTypes } = require("../../db/utils")
|
|
8
8
|
const { app: appCache } = require("@budibase/backend-core/cache")
|
|
9
9
|
const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context")
|
|
10
|
-
const { events } = require("@budibase/backend-core")
|
|
11
10
|
|
|
12
11
|
async function redirect(ctx, method, path = "global") {
|
|
13
12
|
const { devPath } = ctx.params
|
|
@@ -103,11 +102,7 @@ exports.revert = async ctx => {
|
|
|
103
102
|
target: appId,
|
|
104
103
|
})
|
|
105
104
|
try {
|
|
106
|
-
|
|
107
|
-
// in-memory db stalls on rollback
|
|
108
|
-
await replication.rollback()
|
|
109
|
-
}
|
|
110
|
-
|
|
105
|
+
await replication.rollback()
|
|
111
106
|
// update appID in reverted app to be dev version again
|
|
112
107
|
const db = getAppDB()
|
|
113
108
|
const appDoc = await db.get(DocumentTypes.APP_METADATA)
|
|
@@ -118,7 +113,6 @@ exports.revert = async ctx => {
|
|
|
118
113
|
ctx.body = {
|
|
119
114
|
message: "Reverted changes successfully.",
|
|
120
115
|
}
|
|
121
|
-
await events.app.reverted(appDoc)
|
|
122
116
|
} catch (err) {
|
|
123
117
|
ctx.throw(400, `Unable to revert. ${err}`)
|
|
124
118
|
} finally {
|
|
@@ -127,9 +121,7 @@ exports.revert = async ctx => {
|
|
|
127
121
|
}
|
|
128
122
|
|
|
129
123
|
exports.getBudibaseVersion = async ctx => {
|
|
130
|
-
const version = require("../../../package.json").version
|
|
131
124
|
ctx.body = {
|
|
132
|
-
version,
|
|
125
|
+
version: require("../../../package.json").version,
|
|
133
126
|
}
|
|
134
|
-
await events.version.checked(version)
|
|
135
127
|
}
|
|
@@ -4,7 +4,6 @@ const {
|
|
|
4
4
|
} = require("../../constants/layouts")
|
|
5
5
|
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
|
6
6
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
7
|
-
const { events } = require("@budibase/backend-core")
|
|
8
7
|
|
|
9
8
|
exports.save = async function (ctx) {
|
|
10
9
|
const db = getAppDB()
|
|
@@ -20,7 +19,6 @@ exports.save = async function (ctx) {
|
|
|
20
19
|
|
|
21
20
|
layout._id = layout._id || generateLayoutID()
|
|
22
21
|
const response = await db.put(layout)
|
|
23
|
-
await events.layout.created(layout)
|
|
24
22
|
layout._rev = response.rev
|
|
25
23
|
|
|
26
24
|
ctx.body = layout
|
|
@@ -48,7 +46,6 @@ exports.destroy = async function (ctx) {
|
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
await db.remove(layoutId, layoutRev)
|
|
51
|
-
await events.layout.deleted(layoutId)
|
|
52
49
|
ctx.body = { message: "Layout deleted successfully" }
|
|
53
50
|
ctx.status = 200
|
|
54
51
|
}
|
|
@@ -3,12 +3,10 @@ import { generateQueryID } from "../../../../db/utils"
|
|
|
3
3
|
import { ImportInfo, ImportSource } from "./sources/base"
|
|
4
4
|
import { OpenAPI2 } from "./sources/openapi2"
|
|
5
5
|
import { OpenAPI3 } from "./sources/openapi3"
|
|
6
|
+
import { Query } from "./../../../../definitions/common"
|
|
6
7
|
import { Curl } from "./sources/curl"
|
|
7
8
|
// @ts-ignore
|
|
8
9
|
import { getAppDB } from "@budibase/backend-core/context"
|
|
9
|
-
import { events } from "@budibase/backend-core"
|
|
10
|
-
import { Datasource, Query } from "@budibase/types"
|
|
11
|
-
|
|
12
10
|
interface ImportResult {
|
|
13
11
|
errorQueries: Query[]
|
|
14
12
|
queries: Query[]
|
|
@@ -38,7 +36,7 @@ export class RestImporter {
|
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
importQueries = async (datasourceId: string): Promise<ImportResult> => {
|
|
41
|
-
//
|
|
39
|
+
// constuct the queries
|
|
42
40
|
let queries = await this.source.getQueries(datasourceId)
|
|
43
41
|
|
|
44
42
|
// validate queries
|
|
@@ -78,20 +76,9 @@ export class RestImporter {
|
|
|
78
76
|
}
|
|
79
77
|
})
|
|
80
78
|
|
|
81
|
-
const successQueries = Object.values(queryIndex)
|
|
82
|
-
|
|
83
|
-
// events
|
|
84
|
-
const count = successQueries.length
|
|
85
|
-
const importSource = this.source.getImportSource()
|
|
86
|
-
const datasource: Datasource = await db.get(datasourceId)
|
|
87
|
-
await events.query.imported(datasource, importSource, count)
|
|
88
|
-
for (let query of successQueries) {
|
|
89
|
-
await events.query.created(datasource, query)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
79
|
return {
|
|
93
80
|
errorQueries,
|
|
94
|
-
queries:
|
|
81
|
+
queries: Object.values(queryIndex),
|
|
95
82
|
}
|
|
96
83
|
}
|
|
97
84
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Query, QueryParameter } from "
|
|
1
|
+
import { Query, QueryParameter } from "../../../../../../definitions/datasource"
|
|
2
2
|
import { URL } from "url"
|
|
3
3
|
|
|
4
4
|
export interface ImportInfo {
|
|
@@ -17,7 +17,6 @@ export abstract class ImportSource {
|
|
|
17
17
|
abstract isSupported(data: string): Promise<boolean>
|
|
18
18
|
abstract getInfo(): Promise<ImportInfo>
|
|
19
19
|
abstract getQueries(datasourceId: string): Promise<Query[]>
|
|
20
|
-
abstract getImportSource(): string
|
|
21
20
|
|
|
22
21
|
constructQuery = (
|
|
23
22
|
datasourceId: string,
|
|
@@ -106,10 +106,6 @@ export class OpenAPI3 extends OpenAPISource {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
getImportSource(): string {
|
|
110
|
-
return "openapi3.0"
|
|
111
|
-
}
|
|
112
|
-
|
|
113
109
|
getQueries = async (datasourceId: string): Promise<Query[]> => {
|
|
114
110
|
let url: string | URL | undefined
|
|
115
111
|
if (this.document.servers?.length) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const TestConfig = require("../../../../../tests/utilities/TestConfiguration")
|
|
2
|
+
|
|
2
3
|
const { RestImporter } = require("../index")
|
|
4
|
+
|
|
3
5
|
const fs = require("fs")
|
|
4
6
|
const path = require('path')
|
|
5
|
-
const { events} = require("@budibase/backend-core")
|
|
6
7
|
|
|
7
8
|
const getData = (file) => {
|
|
8
9
|
return fs.readFileSync(path.join(__dirname, `../sources/tests/${file}`), "utf8")
|
|
@@ -53,11 +54,9 @@ describe("Rest Importer", () => {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const runTest = async (test, assertions) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
})
|
|
57
|
+
for (let [key, data] of Object.entries(datasets)) {
|
|
58
|
+
await test(key, data, assertions)
|
|
59
|
+
}
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
const testGetInfo = async (key, data, assertions) => {
|
|
@@ -104,12 +103,9 @@ describe("Rest Importer", () => {
|
|
|
104
103
|
|
|
105
104
|
const testImportQueries = async (key, data, assertions) => {
|
|
106
105
|
await init(data)
|
|
107
|
-
const
|
|
108
|
-
const importResult = await restImporter.importQueries(datasource._id)
|
|
106
|
+
const importResult = await restImporter.importQueries("datasourceId")
|
|
109
107
|
expect(importResult.errorQueries.length).toBe(0)
|
|
110
108
|
expect(importResult.queries.length).toBe(assertions[key].count)
|
|
111
|
-
expect(events.query.imported).toBeCalledTimes(1)
|
|
112
|
-
expect(events.query.imported).toBeCalledWith(datasource, assertions[key].source, assertions[key].count)
|
|
113
109
|
jest.clearAllMocks()
|
|
114
110
|
}
|
|
115
111
|
|
|
@@ -120,41 +116,32 @@ describe("Rest Importer", () => {
|
|
|
120
116
|
// openapi2 (swagger)
|
|
121
117
|
"oapi2CrudJson" : {
|
|
122
118
|
count: 6,
|
|
123
|
-
source: "openapi2.0",
|
|
124
119
|
},
|
|
125
120
|
"oapi2CrudYaml" :{
|
|
126
121
|
count: 6,
|
|
127
|
-
source: "openapi2.0"
|
|
128
122
|
},
|
|
129
123
|
"oapi2PetstoreJson" : {
|
|
130
124
|
count: 20,
|
|
131
|
-
source: "openapi2.0"
|
|
132
125
|
},
|
|
133
126
|
"oapi2PetstoreYaml" :{
|
|
134
127
|
count: 20,
|
|
135
|
-
source: "openapi2.0"
|
|
136
128
|
},
|
|
137
129
|
// openapi3
|
|
138
130
|
"oapi3CrudJson" : {
|
|
139
131
|
count: 6,
|
|
140
|
-
source: "openapi3.0"
|
|
141
132
|
},
|
|
142
133
|
"oapi3CrudYaml" :{
|
|
143
134
|
count: 6,
|
|
144
|
-
source: "openapi3.0"
|
|
145
135
|
},
|
|
146
136
|
"oapi3PetstoreJson" : {
|
|
147
137
|
count: 19,
|
|
148
|
-
source: "openapi3.0"
|
|
149
138
|
},
|
|
150
139
|
"oapi3PetstoreYaml" :{
|
|
151
140
|
count: 19,
|
|
152
|
-
source: "openapi3.0"
|
|
153
141
|
},
|
|
154
142
|
// curl
|
|
155
143
|
"curl": {
|
|
156
|
-
count: 1
|
|
157
|
-
source: "curl"
|
|
144
|
+
count: 1
|
|
158
145
|
}
|
|
159
146
|
}
|
|
160
147
|
await runTest(testImportQueries, assertions)
|
|
@@ -7,7 +7,6 @@ import { invalidateDynamicVariables } from "../../../threads/utils"
|
|
|
7
7
|
import { QUERY_THREAD_TIMEOUT } from "../../../environment"
|
|
8
8
|
import { getAppDB } from "@budibase/backend-core/context"
|
|
9
9
|
import { quotas } from "@budibase/pro"
|
|
10
|
-
import { events } from "@budibase/backend-core"
|
|
11
10
|
|
|
12
11
|
const Runner = new Thread(ThreadType.QUERY, {
|
|
13
12
|
timeoutMs: QUERY_THREAD_TIMEOUT || 10000,
|
|
@@ -81,18 +80,11 @@ export async function save(ctx: any) {
|
|
|
81
80
|
const db = getAppDB()
|
|
82
81
|
const query = ctx.request.body
|
|
83
82
|
|
|
84
|
-
const datasource = await db.get(query.datasourceId)
|
|
85
|
-
|
|
86
|
-
let eventFn
|
|
87
83
|
if (!query._id) {
|
|
88
84
|
query._id = generateQueryID(query.datasourceId)
|
|
89
|
-
eventFn = () => events.query.created(datasource, query)
|
|
90
|
-
} else {
|
|
91
|
-
eventFn = () => events.query.updated(datasource, query)
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
const response = await db.put(query)
|
|
95
|
-
await eventFn()
|
|
96
88
|
query._rev = response.rev
|
|
97
89
|
|
|
98
90
|
ctx.body = query
|
|
@@ -114,10 +106,10 @@ export async function preview(ctx: any) {
|
|
|
114
106
|
const db = getAppDB()
|
|
115
107
|
|
|
116
108
|
const datasource = await db.get(ctx.request.body.datasourceId)
|
|
117
|
-
const query = ctx.request.body
|
|
118
109
|
// preview may not have a queryId as it hasn't been saved, but if it does
|
|
119
110
|
// this stops dynamic variables from calling the same query
|
|
120
|
-
const { fields, parameters, queryVerb, transformer, queryId } =
|
|
111
|
+
const { fields, parameters, queryVerb, transformer, queryId } =
|
|
112
|
+
ctx.request.body
|
|
121
113
|
|
|
122
114
|
try {
|
|
123
115
|
const runFn = () =>
|
|
@@ -132,7 +124,6 @@ export async function preview(ctx: any) {
|
|
|
132
124
|
})
|
|
133
125
|
|
|
134
126
|
const { rows, keys, info, extra } = await quotas.addQuery(runFn)
|
|
135
|
-
await events.query.previewed(datasource, query)
|
|
136
127
|
ctx.body = {
|
|
137
128
|
rows,
|
|
138
129
|
schemaFields: [...new Set(keys)],
|
|
@@ -216,12 +207,8 @@ const removeDynamicVariables = async (queryId: any) => {
|
|
|
216
207
|
|
|
217
208
|
export async function destroy(ctx: any) {
|
|
218
209
|
const db = getAppDB()
|
|
219
|
-
|
|
220
|
-
await removeDynamicVariables(queryId)
|
|
221
|
-
const query = await db.get(queryId)
|
|
222
|
-
const datasource = await db.get(query.datasourceId)
|
|
210
|
+
await removeDynamicVariables(ctx.params.queryId)
|
|
223
211
|
await db.remove(ctx.params.queryId, ctx.params.revId)
|
|
224
212
|
ctx.message = `Query deleted.`
|
|
225
213
|
ctx.status = 200
|
|
226
|
-
await events.query.deleted(datasource, query)
|
|
227
214
|
}
|
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
InternalTables,
|
|
11
11
|
} = require("../../db/utils")
|
|
12
12
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
13
|
-
const { events } = require("@budibase/backend-core")
|
|
14
13
|
|
|
15
14
|
const UpdateRolesOptions = {
|
|
16
15
|
CREATED: "created",
|
|
@@ -51,10 +50,8 @@ exports.find = async function (ctx) {
|
|
|
51
50
|
exports.save = async function (ctx) {
|
|
52
51
|
const db = getAppDB()
|
|
53
52
|
let { _id, name, inherits, permissionId } = ctx.request.body
|
|
54
|
-
let isCreate = false
|
|
55
53
|
if (!_id) {
|
|
56
54
|
_id = generateRoleID()
|
|
57
|
-
isCreate = true
|
|
58
55
|
} else if (isBuiltin(_id)) {
|
|
59
56
|
ctx.throw(400, "Cannot update builtin roles.")
|
|
60
57
|
}
|
|
@@ -65,11 +62,6 @@ exports.save = async function (ctx) {
|
|
|
65
62
|
role._rev = ctx.request.body._rev
|
|
66
63
|
}
|
|
67
64
|
const result = await db.put(role)
|
|
68
|
-
if (isCreate) {
|
|
69
|
-
await events.role.created(role)
|
|
70
|
-
} else {
|
|
71
|
-
await events.role.updated(role)
|
|
72
|
-
}
|
|
73
65
|
await updateRolesOnUserTable(db, _id, UpdateRolesOptions.CREATED)
|
|
74
66
|
role._rev = result.rev
|
|
75
67
|
ctx.body = role
|
|
@@ -79,7 +71,6 @@ exports.save = async function (ctx) {
|
|
|
79
71
|
exports.destroy = async function (ctx) {
|
|
80
72
|
const db = getAppDB()
|
|
81
73
|
const roleId = ctx.params.roleId
|
|
82
|
-
const role = await db.get(roleId)
|
|
83
74
|
if (isBuiltin(roleId)) {
|
|
84
75
|
ctx.throw(400, "Cannot delete builtin role.")
|
|
85
76
|
}
|
|
@@ -97,7 +88,6 @@ exports.destroy = async function (ctx) {
|
|
|
97
88
|
}
|
|
98
89
|
|
|
99
90
|
await db.remove(roleId, ctx.params.rev)
|
|
100
|
-
await events.role.deleted(role)
|
|
101
91
|
await updateRolesOnUserTable(
|
|
102
92
|
db,
|
|
103
93
|
ctx.params.roleId,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { getScreenParams, generateScreenID } = require("../../db/utils")
|
|
2
2
|
const { AccessController } = require("@budibase/backend-core/roles")
|
|
3
3
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
4
|
-
const { events } = require("@budibase/backend-core")
|
|
5
4
|
|
|
6
5
|
exports.fetch = async ctx => {
|
|
7
6
|
const db = getAppDB()
|
|
@@ -24,17 +23,11 @@ exports.save = async ctx => {
|
|
|
24
23
|
const db = getAppDB()
|
|
25
24
|
let screen = ctx.request.body
|
|
26
25
|
|
|
27
|
-
let eventFn
|
|
28
26
|
if (!screen._id) {
|
|
29
27
|
screen._id = generateScreenID()
|
|
30
|
-
eventFn = events.screen.created
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
const response = await db.put(screen)
|
|
34
30
|
|
|
35
|
-
if (eventFn) {
|
|
36
|
-
await eventFn(screen)
|
|
37
|
-
}
|
|
38
31
|
ctx.message = `Screen ${screen.name} saved.`
|
|
39
32
|
ctx.body = {
|
|
40
33
|
...screen,
|
|
@@ -45,12 +38,7 @@ exports.save = async ctx => {
|
|
|
45
38
|
|
|
46
39
|
exports.destroy = async ctx => {
|
|
47
40
|
const db = getAppDB()
|
|
48
|
-
|
|
49
|
-
const screen = await db.get(id)
|
|
50
|
-
|
|
51
|
-
await db.remove(id, ctx.params.screenRev)
|
|
52
|
-
|
|
53
|
-
await events.screen.deleted(screen)
|
|
41
|
+
await db.remove(ctx.params.screenId, ctx.params.screenRev)
|
|
54
42
|
ctx.body = {
|
|
55
43
|
message: "Screen deleted successfully",
|
|
56
44
|
}
|
|
@@ -14,11 +14,10 @@ const env = require("../../../environment")
|
|
|
14
14
|
const { clientLibraryPath } = require("../../../utilities")
|
|
15
15
|
const { upload } = require("../../../utilities/fileSystem")
|
|
16
16
|
const { attachmentsRelativeURL } = require("../../../utilities")
|
|
17
|
-
const { DocumentTypes
|
|
17
|
+
const { DocumentTypes } = require("../../../db/utils")
|
|
18
18
|
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
|
19
19
|
const AWS = require("aws-sdk")
|
|
20
20
|
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
|
21
|
-
const { events } = require("@budibase/backend-core")
|
|
22
21
|
|
|
23
22
|
async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
|
24
23
|
const response = await upload({
|
|
@@ -42,7 +41,6 @@ async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
|
|
42
41
|
exports.serveBuilder = async function (ctx) {
|
|
43
42
|
let builderPath = resolve(TOP_LEVEL_PATH, "builder")
|
|
44
43
|
await send(ctx, ctx.file, { root: builderPath })
|
|
45
|
-
await events.serve.servedBuilder()
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
exports.uploadFile = async function (ctx) {
|
|
@@ -67,36 +65,25 @@ exports.uploadFile = async function (ctx) {
|
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
exports.serveApp = async function (ctx) {
|
|
68
|
+
const App = require("./templates/BudibaseApp.svelte").default
|
|
70
69
|
const db = getAppDB({ skip_setup: true })
|
|
71
70
|
const appInfo = await db.get(DocumentTypes.APP_METADATA)
|
|
72
71
|
let appId = getAppId()
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
clientLibPath: clientLibraryPath(appId, appInfo.version),
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`)
|
|
84
|
-
ctx.body = await processString(appHbs, {
|
|
85
|
-
head,
|
|
86
|
-
body: html,
|
|
87
|
-
style: css.code,
|
|
88
|
-
appId,
|
|
89
|
-
})
|
|
90
|
-
} else {
|
|
91
|
-
// just return the app info for jest to assert on
|
|
92
|
-
ctx.body = appInfo
|
|
93
|
-
}
|
|
73
|
+
const { head, html, css } = App.render({
|
|
74
|
+
title: appInfo.name,
|
|
75
|
+
production: env.isProd(),
|
|
76
|
+
appId,
|
|
77
|
+
clientLibPath: clientLibraryPath(appId, appInfo.version),
|
|
78
|
+
})
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`)
|
|
81
|
+
ctx.body = await processString(appHbs, {
|
|
82
|
+
head,
|
|
83
|
+
body: html,
|
|
84
|
+
style: css.code,
|
|
85
|
+
appId,
|
|
86
|
+
})
|
|
100
87
|
}
|
|
101
88
|
|
|
102
89
|
exports.serveClientLibrary = async function (ctx) {
|
|
@@ -19,7 +19,6 @@ const { cloneDeep } = require("lodash/fp")
|
|
|
19
19
|
const csvParser = require("../../../utilities/csvParser")
|
|
20
20
|
const { handleRequest } = require("../row/external")
|
|
21
21
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
22
|
-
const { events } = require("@budibase/backend-core")
|
|
23
22
|
|
|
24
23
|
async function makeTableRequest(
|
|
25
24
|
datasource,
|
|
@@ -315,6 +314,5 @@ exports.bulkImport = async function (ctx) {
|
|
|
315
314
|
await handleRequest(DataSourceOperation.BULK_CREATE, table._id, {
|
|
316
315
|
rows,
|
|
317
316
|
})
|
|
318
|
-
await events.rows.imported(table, "csv", rows.length)
|
|
319
317
|
return table
|
|
320
318
|
}
|
|
@@ -5,7 +5,6 @@ const { isExternalTable, isSQL } = require("../../../integrations/utils")
|
|
|
5
5
|
const { getDatasourceParams } = require("../../../db/utils")
|
|
6
6
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
7
7
|
const { getTable, getAllInternalTables } = require("./utils")
|
|
8
|
-
const { events } = require("@budibase/backend-core")
|
|
9
8
|
|
|
10
9
|
function pickApi({ tableId, table }) {
|
|
11
10
|
if (table && !tableId) {
|
|
@@ -56,17 +55,7 @@ exports.find = async function (ctx) {
|
|
|
56
55
|
exports.save = async function (ctx) {
|
|
57
56
|
const appId = ctx.appId
|
|
58
57
|
const table = ctx.request.body
|
|
59
|
-
const importFormat =
|
|
60
|
-
table.dataImport && table.dataImport.csvString ? "csv" : undefined
|
|
61
58
|
const savedTable = await pickApi({ table }).save(ctx)
|
|
62
|
-
if (!table._id) {
|
|
63
|
-
await events.table.created(savedTable)
|
|
64
|
-
} else {
|
|
65
|
-
await events.table.updated(savedTable)
|
|
66
|
-
}
|
|
67
|
-
if (importFormat) {
|
|
68
|
-
await events.table.imported(savedTable, importFormat)
|
|
69
|
-
}
|
|
70
59
|
ctx.status = 200
|
|
71
60
|
ctx.message = `Table ${table.name} saved successfully.`
|
|
72
61
|
ctx.eventEmitter &&
|
|
@@ -78,7 +67,6 @@ exports.destroy = async function (ctx) {
|
|
|
78
67
|
const appId = ctx.appId
|
|
79
68
|
const tableId = ctx.params.tableId
|
|
80
69
|
const deletedTable = await pickApi({ tableId }).destroy(ctx)
|
|
81
|
-
await events.table.deleted(deletedTable)
|
|
82
70
|
ctx.eventEmitter &&
|
|
83
71
|
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
|
|
84
72
|
ctx.status = 200
|
|
@@ -26,8 +26,7 @@ import { getViews, saveView } from "../view/utils"
|
|
|
26
26
|
import viewTemplate from "../view/viewBuilder"
|
|
27
27
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
28
28
|
import { cloneDeep } from "lodash/fp"
|
|
29
|
-
import { quotas } from "@budibase/pro"
|
|
30
|
-
import { events } from "@budibase/backend-core"
|
|
29
|
+
import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro"
|
|
31
30
|
|
|
32
31
|
export async function clearColumns(table: any, columnNames: any) {
|
|
33
32
|
const db = getAppDB()
|
|
@@ -149,7 +148,8 @@ export async function handleDataImport(user: any, table: any, dataImport: any) {
|
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
await quotas.addRows(finalData.length, () => db.bulkDocs(finalData))
|
|
152
|
-
await
|
|
151
|
+
let response = await db.put(table)
|
|
152
|
+
table._rev = response._rev
|
|
153
153
|
return table
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -245,7 +245,7 @@ class TableSaveFunctions {
|
|
|
245
245
|
// after saving
|
|
246
246
|
async after(table: any) {
|
|
247
247
|
table = await handleSearchIndexes(table)
|
|
248
|
-
await handleDataImport(this.user, table, this.dataImport)
|
|
248
|
+
table = await handleDataImport(this.user, table, this.dataImport)
|
|
249
249
|
return table
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -6,9 +6,6 @@ const { fetchView } = require("../row")
|
|
|
6
6
|
const { getTable } = require("../table/utils")
|
|
7
7
|
const { FieldTypes } = require("../../../constants")
|
|
8
8
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
9
|
-
const { events } = require("@budibase/backend-core")
|
|
10
|
-
const { DocumentTypes } = require("../../../db/utils")
|
|
11
|
-
const { cloneDeep, isEqual } = require("lodash")
|
|
12
9
|
|
|
13
10
|
exports.fetch = async ctx => {
|
|
14
11
|
ctx.body = await getViews()
|
|
@@ -18,28 +15,24 @@ exports.save = async ctx => {
|
|
|
18
15
|
const db = getAppDB()
|
|
19
16
|
const { originalName, ...viewToSave } = ctx.request.body
|
|
20
17
|
const view = viewTemplate(viewToSave)
|
|
21
|
-
const viewName = viewToSave.name
|
|
22
18
|
|
|
23
|
-
if (!
|
|
19
|
+
if (!viewToSave.name) {
|
|
24
20
|
ctx.throw(400, "Cannot create view without a name")
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
await saveView(originalName,
|
|
23
|
+
await saveView(originalName, viewToSave.name, view)
|
|
28
24
|
|
|
29
25
|
// add views to table document
|
|
30
|
-
const
|
|
31
|
-
const table = cloneDeep(existingTable)
|
|
26
|
+
const table = await db.get(ctx.request.body.tableId)
|
|
32
27
|
if (!table.views) table.views = {}
|
|
33
28
|
if (!view.meta.schema) {
|
|
34
29
|
view.meta.schema = table.schema
|
|
35
30
|
}
|
|
36
|
-
table.views[
|
|
31
|
+
table.views[viewToSave.name] = view.meta
|
|
37
32
|
if (originalName) {
|
|
38
33
|
delete table.views[originalName]
|
|
39
|
-
existingTable.views[viewName] = existingTable.views[originalName]
|
|
40
34
|
}
|
|
41
35
|
await db.put(table)
|
|
42
|
-
await handleViewEvents(existingTable.views[viewName], table.views[viewName])
|
|
43
36
|
|
|
44
37
|
ctx.body = {
|
|
45
38
|
...table.views[viewToSave.name],
|
|
@@ -47,62 +40,6 @@ exports.save = async ctx => {
|
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
const calculationEvents = async (existingView, newView) => {
|
|
51
|
-
const existingCalculation = existingView && existingView.calculation
|
|
52
|
-
const newCalculation = newView && newView.calculation
|
|
53
|
-
|
|
54
|
-
if (existingCalculation && !newCalculation) {
|
|
55
|
-
await events.view.calculationDeleted(existingView)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!existingCalculation && newCalculation) {
|
|
59
|
-
await events.view.calculationCreated(newView)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
existingCalculation &&
|
|
64
|
-
newCalculation &&
|
|
65
|
-
existingCalculation !== newCalculation
|
|
66
|
-
) {
|
|
67
|
-
await events.view.calculationUpdated(newView)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const filterEvents = async (existingView, newView) => {
|
|
72
|
-
const hasExistingFilters = !!(
|
|
73
|
-
existingView &&
|
|
74
|
-
existingView.filters &&
|
|
75
|
-
existingView.filters.length
|
|
76
|
-
)
|
|
77
|
-
const hasNewFilters = !!(newView && newView.filters && newView.filters.length)
|
|
78
|
-
|
|
79
|
-
if (hasExistingFilters && !hasNewFilters) {
|
|
80
|
-
await events.view.filterDeleted(newView)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!hasExistingFilters && hasNewFilters) {
|
|
84
|
-
await events.view.filterCreated(newView)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
hasExistingFilters &&
|
|
89
|
-
hasNewFilters &&
|
|
90
|
-
!isEqual(existingView.filters, newView.filters)
|
|
91
|
-
) {
|
|
92
|
-
await events.view.filterUpdated(newView)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const handleViewEvents = async (existingView, newView) => {
|
|
97
|
-
if (!existingView) {
|
|
98
|
-
await events.view.created(newView)
|
|
99
|
-
} else {
|
|
100
|
-
await events.view.updated(newView)
|
|
101
|
-
}
|
|
102
|
-
await calculationEvents(existingView, newView)
|
|
103
|
-
await filterEvents(existingView, newView)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
43
|
exports.destroy = async ctx => {
|
|
107
44
|
const db = getAppDB()
|
|
108
45
|
const viewName = decodeURI(ctx.params.viewName)
|
|
@@ -110,7 +47,6 @@ exports.destroy = async ctx => {
|
|
|
110
47
|
const table = await db.get(view.meta.tableId)
|
|
111
48
|
delete table.views[viewName]
|
|
112
49
|
await db.put(table)
|
|
113
|
-
await events.view.deleted(view)
|
|
114
50
|
|
|
115
51
|
ctx.body = view
|
|
116
52
|
}
|
|
@@ -143,9 +79,9 @@ exports.exportView = async ctx => {
|
|
|
143
79
|
let rows = ctx.body
|
|
144
80
|
|
|
145
81
|
let schema = view && view.meta && view.meta.schema
|
|
146
|
-
const tableId = ctx.params.tableId || view.meta.tableId
|
|
147
|
-
const table = await getTable(tableId)
|
|
148
82
|
if (!schema) {
|
|
83
|
+
const tableId = ctx.params.tableId || view.meta.tableId
|
|
84
|
+
const table = await getTable(tableId)
|
|
149
85
|
schema = table.schema
|
|
150
86
|
}
|
|
151
87
|
|
|
@@ -180,10 +116,4 @@ exports.exportView = async ctx => {
|
|
|
180
116
|
// send down the file
|
|
181
117
|
ctx.attachment(filename)
|
|
182
118
|
ctx.body = apiFileReturn(exporter(headers, rows))
|
|
183
|
-
|
|
184
|
-
if (viewName.startsWith(DocumentTypes.TABLE)) {
|
|
185
|
-
await events.table.exported(table, format)
|
|
186
|
-
} else {
|
|
187
|
-
await events.view.exported(table, format)
|
|
188
|
-
}
|
|
189
119
|
}
|