@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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const setup = require("./utilities")
|
|
2
|
-
const { events } = require("@budibase/backend-core")
|
|
3
2
|
|
|
4
3
|
function priceTable() {
|
|
5
4
|
return {
|
|
@@ -30,70 +29,27 @@ describe("/views", () => {
|
|
|
30
29
|
|
|
31
30
|
beforeEach(async () => {
|
|
32
31
|
await config.init()
|
|
33
|
-
table = await config.createTable(priceTable())
|
|
34
32
|
})
|
|
35
33
|
|
|
36
|
-
const saveView = async (view) => {
|
|
37
|
-
const viewToSave = {
|
|
38
|
-
name: "TestView",
|
|
39
|
-
field: "Price",
|
|
40
|
-
calculation: "stats",
|
|
41
|
-
tableId: table._id,
|
|
42
|
-
...view
|
|
43
|
-
}
|
|
44
|
-
return request
|
|
45
|
-
.post(`/api/views`)
|
|
46
|
-
.send(viewToSave)
|
|
47
|
-
.set(config.defaultHeaders())
|
|
48
|
-
.expect("Content-Type", /json/)
|
|
49
|
-
.expect(200)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
34
|
describe("create", () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const res = await saveView()
|
|
56
|
-
expect(res.body.tableId).toBe(table._id)
|
|
57
|
-
expect(events.view.created).toBeCalledTimes(1)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it("creates a view with a calculation", async () => {
|
|
61
|
-
jest.clearAllMocks()
|
|
62
|
-
|
|
63
|
-
const res = await saveView({ calculation: "count" })
|
|
64
|
-
|
|
65
|
-
expect(res.body.tableId).toBe(table._id)
|
|
66
|
-
expect(events.view.created).toBeCalledTimes(1)
|
|
67
|
-
expect(events.view.updated).not.toBeCalled()
|
|
68
|
-
expect(events.view.calculationCreated).toBeCalledTimes(1)
|
|
69
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
70
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
71
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
72
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
73
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
table = await config.createTable(priceTable())
|
|
74
37
|
})
|
|
75
38
|
|
|
76
|
-
it("
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
39
|
+
it("returns a success message when the view is successfully created", async () => {
|
|
40
|
+
const res = await request
|
|
41
|
+
.post(`/api/views`)
|
|
42
|
+
.send({
|
|
43
|
+
name: "TestView",
|
|
44
|
+
field: "Price",
|
|
45
|
+
calculation: "stats",
|
|
46
|
+
tableId: table._id,
|
|
47
|
+
})
|
|
48
|
+
.set(config.defaultHeaders())
|
|
49
|
+
.expect("Content-Type", /json/)
|
|
50
|
+
.expect(200)
|
|
87
51
|
|
|
88
52
|
expect(res.body.tableId).toBe(table._id)
|
|
89
|
-
expect(events.view.created).toBeCalledTimes(1)
|
|
90
|
-
expect(events.view.updated).not.toBeCalled()
|
|
91
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
92
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
93
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
94
|
-
expect(events.view.filterCreated).toBeCalledTimes(1)
|
|
95
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
96
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
97
53
|
})
|
|
98
54
|
|
|
99
55
|
it("updates the table row with the new view metadata", async () => {
|
|
@@ -145,100 +101,6 @@ describe("/views", () => {
|
|
|
145
101
|
})
|
|
146
102
|
})
|
|
147
103
|
|
|
148
|
-
describe("update", () => {
|
|
149
|
-
it("updates a view with no calculation or filter changed", async () => {
|
|
150
|
-
await saveView()
|
|
151
|
-
jest.clearAllMocks()
|
|
152
|
-
|
|
153
|
-
await saveView()
|
|
154
|
-
|
|
155
|
-
expect(events.view.created).not.toBeCalled()
|
|
156
|
-
expect(events.view.updated).toBeCalledTimes(1)
|
|
157
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
158
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
159
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
160
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
161
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
162
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it("updates a view calculation", async () => {
|
|
166
|
-
await saveView({ calculation: "sum" })
|
|
167
|
-
jest.clearAllMocks()
|
|
168
|
-
|
|
169
|
-
await saveView({ calculation: "count" })
|
|
170
|
-
|
|
171
|
-
expect(events.view.created).not.toBeCalled()
|
|
172
|
-
expect(events.view.updated).toBeCalledTimes(1)
|
|
173
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
174
|
-
expect(events.view.calculationUpdated).toBeCalledTimes(1)
|
|
175
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
176
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
177
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
178
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it("deletes a view calculation", async () => {
|
|
182
|
-
await saveView({ calculation: "sum" })
|
|
183
|
-
jest.clearAllMocks()
|
|
184
|
-
|
|
185
|
-
await saveView({ calculation: null })
|
|
186
|
-
|
|
187
|
-
expect(events.view.created).not.toBeCalled()
|
|
188
|
-
expect(events.view.updated).toBeCalledTimes(1)
|
|
189
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
190
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
191
|
-
expect(events.view.calculationDeleted).toBeCalledTimes(1)
|
|
192
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
193
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
194
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
it("updates a view filter", async () => {
|
|
198
|
-
await saveView({ filters: [{
|
|
199
|
-
value: "1",
|
|
200
|
-
condition: "EQUALS",
|
|
201
|
-
key: "price"
|
|
202
|
-
}] })
|
|
203
|
-
jest.clearAllMocks()
|
|
204
|
-
|
|
205
|
-
await saveView({ filters: [{
|
|
206
|
-
value: "2",
|
|
207
|
-
condition: "EQUALS",
|
|
208
|
-
key: "price"
|
|
209
|
-
}] })
|
|
210
|
-
|
|
211
|
-
expect(events.view.created).not.toBeCalled()
|
|
212
|
-
expect(events.view.updated).toBeCalledTimes(1)
|
|
213
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
214
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
215
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
216
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
217
|
-
expect(events.view.filterUpdated).toBeCalledTimes(1)
|
|
218
|
-
expect(events.view.filterDeleted).not.toBeCalled()
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it("deletes a view filter", async () => {
|
|
222
|
-
await saveView({ filters: [{
|
|
223
|
-
value: "1",
|
|
224
|
-
condition: "EQUALS",
|
|
225
|
-
key: "price"
|
|
226
|
-
}] })
|
|
227
|
-
jest.clearAllMocks()
|
|
228
|
-
|
|
229
|
-
await saveView({ filters: [] })
|
|
230
|
-
|
|
231
|
-
expect(events.view.created).not.toBeCalled()
|
|
232
|
-
expect(events.view.updated).toBeCalledTimes(1)
|
|
233
|
-
expect(events.view.calculationCreated).not.toBeCalled()
|
|
234
|
-
expect(events.view.calculationUpdated).not.toBeCalled()
|
|
235
|
-
expect(events.view.calculationDeleted).not.toBeCalled()
|
|
236
|
-
expect(events.view.filterCreated).not.toBeCalled()
|
|
237
|
-
expect(events.view.filterUpdated).not.toBeCalled()
|
|
238
|
-
expect(events.view.filterDeleted).toBeCalledTimes(1)
|
|
239
|
-
})
|
|
240
|
-
})
|
|
241
|
-
|
|
242
104
|
describe("fetch", () => {
|
|
243
105
|
beforeEach(async () => {
|
|
244
106
|
table = await config.createTable(priceTable())
|
|
@@ -262,6 +124,10 @@ describe("/views", () => {
|
|
|
262
124
|
})
|
|
263
125
|
|
|
264
126
|
describe("query", () => {
|
|
127
|
+
beforeEach(async () => {
|
|
128
|
+
table = await config.createTable(priceTable())
|
|
129
|
+
})
|
|
130
|
+
|
|
265
131
|
it("returns data for the created view", async () => {
|
|
266
132
|
await config.createView({
|
|
267
133
|
name: "TestView",
|
|
@@ -335,82 +201,37 @@ describe("/views", () => {
|
|
|
335
201
|
.expect(200)
|
|
336
202
|
expect(res.body.map).toBeDefined()
|
|
337
203
|
expect(res.body.meta.tableId).toEqual(table._id)
|
|
338
|
-
expect(events.view.deleted).toBeCalledTimes(1)
|
|
339
204
|
})
|
|
340
205
|
})
|
|
341
206
|
|
|
342
207
|
describe("exportView", () => {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const table = await config.createTable()
|
|
350
|
-
await config.createRow({ name: "test-name", description: "test-desc" })
|
|
351
|
-
return table
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const exportView = async (viewName, format) => {
|
|
355
|
-
return request
|
|
356
|
-
.get(`/api/views/export?view=${viewName}&format=${format}`)
|
|
208
|
+
it("should be able to export a view", async () => {
|
|
209
|
+
await config.createTable(priceTable())
|
|
210
|
+
await config.createRow()
|
|
211
|
+
const view = await config.createView()
|
|
212
|
+
let res = await request
|
|
213
|
+
.get(`/api/views/export?view=${view.name}&format=json`)
|
|
357
214
|
.set(config.defaultHeaders())
|
|
358
215
|
.expect(200)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
expect(events.table.exported).toBeCalledTimes(1)
|
|
379
|
-
expect(events.table.exported).toBeCalledWith(table, "json")
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
it("should be able to export a table as CSV", async () => {
|
|
383
|
-
const table = await setupExport()
|
|
384
|
-
|
|
385
|
-
const res = await exportView(table._id, "csv")
|
|
386
|
-
|
|
387
|
-
assertCSVExport(res)
|
|
388
|
-
expect(events.table.exported).toBeCalledTimes(1)
|
|
389
|
-
expect(events.table.exported).toBeCalledWith(table, "csv")
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
it("should be able to export a view as JSON", async () => {
|
|
393
|
-
let table = await setupExport()
|
|
394
|
-
const view = await config.createView()
|
|
395
|
-
table = await config.getTable(table._id)
|
|
396
|
-
|
|
397
|
-
let res = await exportView(view.name, "json")
|
|
398
|
-
|
|
399
|
-
assertJsonExport(res)
|
|
400
|
-
expect(events.view.exported).toBeCalledTimes(1)
|
|
401
|
-
expect(events.view.exported).toBeCalledWith(table, "json")
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
it("should be able to export a view as CSV", async () => {
|
|
405
|
-
let table = await setupExport()
|
|
406
|
-
const view = await config.createView()
|
|
407
|
-
table = await config.getTable(table._id)
|
|
408
|
-
|
|
409
|
-
let res = await exportView(view.name, "csv")
|
|
410
|
-
|
|
411
|
-
assertCSVExport(res)
|
|
412
|
-
expect(events.view.exported).toBeCalledTimes(1)
|
|
413
|
-
expect(events.view.exported).toBeCalledWith(table, "csv")
|
|
216
|
+
let error
|
|
217
|
+
try {
|
|
218
|
+
const obj = JSON.parse(res.text)
|
|
219
|
+
expect(obj.length).toBe(1)
|
|
220
|
+
} catch (err) {
|
|
221
|
+
error = err
|
|
222
|
+
}
|
|
223
|
+
expect(error).toBeUndefined()
|
|
224
|
+
res = await request
|
|
225
|
+
.get(`/api/views/export?view=${view.name}&format=csv`)
|
|
226
|
+
.set(config.defaultHeaders())
|
|
227
|
+
.expect(200)
|
|
228
|
+
// this shouldn't be JSON
|
|
229
|
+
try {
|
|
230
|
+
JSON.parse(res.text)
|
|
231
|
+
} catch (err) {
|
|
232
|
+
error = err
|
|
233
|
+
}
|
|
234
|
+
expect(error).toBeDefined()
|
|
414
235
|
})
|
|
415
236
|
})
|
|
416
237
|
})
|
package/src/app.ts
CHANGED
|
@@ -18,7 +18,6 @@ const { logAlert } = require("@budibase/backend-core/logging")
|
|
|
18
18
|
const { Thread } = require("./threads")
|
|
19
19
|
import redis from "./utilities/redis"
|
|
20
20
|
import * as migrations from "./migrations"
|
|
21
|
-
import { events, installation } from "@budibase/backend-core"
|
|
22
21
|
|
|
23
22
|
const app = new Koa()
|
|
24
23
|
|
|
@@ -84,7 +83,6 @@ server.on("close", async () => {
|
|
|
84
83
|
}
|
|
85
84
|
await automations.shutdown()
|
|
86
85
|
await redis.shutdown()
|
|
87
|
-
await events.shutdown()
|
|
88
86
|
await Thread.shutdown()
|
|
89
87
|
api.shutdown()
|
|
90
88
|
if (!env.isTest()) {
|
|
@@ -98,22 +96,6 @@ module.exports = server.listen(env.PORT || 0, async () => {
|
|
|
98
96
|
eventEmitter.emitPort(env.PORT)
|
|
99
97
|
fileSystem.init()
|
|
100
98
|
await redis.init()
|
|
101
|
-
|
|
102
|
-
// run migrations on startup if not done via http
|
|
103
|
-
// not recommended in a clustered environment
|
|
104
|
-
if (!env.HTTP_MIGRATIONS && !env.isTest()) {
|
|
105
|
-
try {
|
|
106
|
-
await migrations.migrate()
|
|
107
|
-
} catch (e) {
|
|
108
|
-
logAlert("Error performing migrations. Exiting.", e)
|
|
109
|
-
shutdown()
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// check for version updates
|
|
114
|
-
await installation.checkInstallVersion()
|
|
115
|
-
|
|
116
|
-
// done last - this will never complete
|
|
117
99
|
await automations.init()
|
|
118
100
|
})
|
|
119
101
|
|
|
@@ -136,3 +118,12 @@ process.on("uncaughtException", err => {
|
|
|
136
118
|
process.on("SIGTERM", () => {
|
|
137
119
|
shutdown()
|
|
138
120
|
})
|
|
121
|
+
|
|
122
|
+
// run migrations on startup if not done via http
|
|
123
|
+
// not recommended in a clustered environment
|
|
124
|
+
if (!env.HTTP_MIGRATIONS) {
|
|
125
|
+
migrations.migrate().catch(err => {
|
|
126
|
+
logAlert("Error performing migrations. Exiting.", err)
|
|
127
|
+
shutdown()
|
|
128
|
+
})
|
|
129
|
+
}
|
package/src/automations/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
const { processEvent } = require("./utils")
|
|
2
2
|
const { queue, shutdown } = require("./bullboard")
|
|
3
|
-
const { TRIGGER_DEFINITIONS } = require("./triggers")
|
|
4
|
-
const { ACTION_DEFINITIONS } = require("./actions")
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* This module is built purely to kick off the worker farm and manage the inputs/outputs
|
|
@@ -22,5 +20,3 @@ exports.shutdown = () => {
|
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
exports.queue = queue
|
|
25
|
-
exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
|
|
26
|
-
exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS
|
package/src/environment.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
const { join } = require("path")
|
|
2
2
|
|
|
3
3
|
function isTest() {
|
|
4
|
-
return isCypress() || isJest()
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function isJest() {
|
|
8
4
|
return (
|
|
9
5
|
process.env.NODE_ENV === "jest" ||
|
|
6
|
+
process.env.NODE_ENV === "cypress" ||
|
|
10
7
|
(process.env.JEST_WORKER_ID != null &&
|
|
11
8
|
process.env.JEST_WORKER_ID !== "null")
|
|
12
9
|
)
|
|
@@ -70,6 +67,7 @@ module.exports = {
|
|
|
70
67
|
AUTOMATION_MAX_ITERATIONS: process.env.AUTOMATION_MAX_ITERATIONS,
|
|
71
68
|
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
|
72
69
|
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
|
|
70
|
+
POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
|
|
73
71
|
QUERY_THREAD_TIMEOUT: parseIntSafe(process.env.QUERY_THREAD_TIMEOUT),
|
|
74
72
|
SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
|
|
75
73
|
// flags
|
|
@@ -86,7 +84,6 @@ module.exports = {
|
|
|
86
84
|
module.exports[key] = value
|
|
87
85
|
},
|
|
88
86
|
isTest,
|
|
89
|
-
isJest,
|
|
90
87
|
isCypress,
|
|
91
88
|
isDev,
|
|
92
89
|
isProd: () => {
|
package/src/migrations/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const {
|
|
2
|
+
MIGRATION_TYPES,
|
|
3
|
+
runMigrations,
|
|
4
|
+
} = require("@budibase/backend-core/migrations")
|
|
4
5
|
|
|
5
6
|
// migration functions
|
|
6
7
|
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
|
@@ -8,129 +9,59 @@ import * as quota1 from "./functions/quotas1"
|
|
|
8
9
|
import * as appUrls from "./functions/appUrls"
|
|
9
10
|
import * as developerQuota from "./functions/developerQuota"
|
|
10
11
|
import * as publishedAppsQuota from "./functions/publishedAppsQuota"
|
|
11
|
-
|
|
12
|
+
|
|
13
|
+
export interface Migration {
|
|
14
|
+
type: string
|
|
15
|
+
name: string
|
|
16
|
+
opts?: object
|
|
17
|
+
fn: Function
|
|
18
|
+
}
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
21
|
+
* e.g.
|
|
22
|
+
* {
|
|
23
|
+
* tenantIds: ['bb'],
|
|
24
|
+
* force: {
|
|
25
|
+
* global: ['quota_1']
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
16
28
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (const definition of definitions) {
|
|
22
|
-
switch (definition.name) {
|
|
23
|
-
case MigrationName.USER_EMAIL_VIEW_CASING: {
|
|
24
|
-
serverMigrations.push({
|
|
25
|
-
...definition,
|
|
26
|
-
fn: userEmailViewCasing.run,
|
|
27
|
-
})
|
|
28
|
-
break
|
|
29
|
-
}
|
|
30
|
-
case MigrationName.QUOTAS_1: {
|
|
31
|
-
serverMigrations.push({
|
|
32
|
-
...definition,
|
|
33
|
-
fn: quota1.run,
|
|
34
|
-
})
|
|
35
|
-
break
|
|
36
|
-
}
|
|
37
|
-
case MigrationName.APP_URLS: {
|
|
38
|
-
serverMigrations.push({
|
|
39
|
-
...definition,
|
|
40
|
-
appOpts: { all: true },
|
|
41
|
-
fn: appUrls.run,
|
|
42
|
-
})
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
case MigrationName.DEVELOPER_QUOTA: {
|
|
46
|
-
serverMigrations.push({
|
|
47
|
-
...definition,
|
|
48
|
-
fn: developerQuota.run,
|
|
49
|
-
})
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
case MigrationName.PUBLISHED_APP_QUOTA: {
|
|
53
|
-
serverMigrations.push({
|
|
54
|
-
...definition,
|
|
55
|
-
fn: publishedAppsQuota.run,
|
|
56
|
-
})
|
|
57
|
-
break
|
|
58
|
-
}
|
|
59
|
-
case MigrationName.EVENT_APP_BACKFILL: {
|
|
60
|
-
serverMigrations.push({
|
|
61
|
-
...definition,
|
|
62
|
-
appOpts: { all: true },
|
|
63
|
-
fn: backfill.app.run,
|
|
64
|
-
silent: !!env.SELF_HOSTED, // reduce noisy logging
|
|
65
|
-
preventRetry: !!env.SELF_HOSTED, // only ever run once
|
|
66
|
-
})
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
case MigrationName.EVENT_GLOBAL_BACKFILL: {
|
|
70
|
-
serverMigrations.push({
|
|
71
|
-
...definition,
|
|
72
|
-
fn: backfill.global.run,
|
|
73
|
-
silent: !!env.SELF_HOSTED, // reduce noisy logging
|
|
74
|
-
preventRetry: !!env.SELF_HOSTED, // only ever run once
|
|
75
|
-
})
|
|
76
|
-
break
|
|
77
|
-
}
|
|
78
|
-
case MigrationName.EVENT_INSTALLATION_BACKFILL: {
|
|
79
|
-
serverMigrations.push({
|
|
80
|
-
...definition,
|
|
81
|
-
fn: backfill.installation.run,
|
|
82
|
-
silent: !!env.SELF_HOSTED, // reduce noisy logging
|
|
83
|
-
preventRetry: !!env.SELF_HOSTED, // only ever run once
|
|
84
|
-
})
|
|
85
|
-
break
|
|
86
|
-
}
|
|
87
|
-
}
|
|
29
|
+
export interface MigrationOptions {
|
|
30
|
+
tenantIds?: string[]
|
|
31
|
+
force?: {
|
|
32
|
+
[type: string]: string[]
|
|
88
33
|
}
|
|
89
|
-
|
|
90
|
-
return serverMigrations
|
|
91
34
|
}
|
|
92
35
|
|
|
93
|
-
export const MIGRATIONS =
|
|
36
|
+
export const MIGRATIONS: Migration[] = [
|
|
37
|
+
{
|
|
38
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
39
|
+
name: "user_email_view_casing",
|
|
40
|
+
fn: userEmailViewCasing.run,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
44
|
+
name: "quotas_1",
|
|
45
|
+
fn: quota1.run,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: MIGRATION_TYPES.APP,
|
|
49
|
+
name: "app_urls",
|
|
50
|
+
opts: { all: true },
|
|
51
|
+
fn: appUrls.run,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
55
|
+
name: "developer_quota",
|
|
56
|
+
fn: developerQuota.run,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
60
|
+
name: "published_apps_quota",
|
|
61
|
+
fn: publishedAppsQuota.run,
|
|
62
|
+
},
|
|
63
|
+
]
|
|
94
64
|
|
|
95
65
|
export const migrate = async (options?: MigrationOptions) => {
|
|
96
|
-
|
|
97
|
-
// self host runs migrations on startup
|
|
98
|
-
// make sure only a single instance runs them
|
|
99
|
-
await migrateWithLock(options)
|
|
100
|
-
} else {
|
|
101
|
-
await migrations.runMigrations(MIGRATIONS, options)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const migrateWithLock = async (options?: MigrationOptions) => {
|
|
106
|
-
// get a new lock client
|
|
107
|
-
|
|
108
|
-
const redlock = await redis.clients.getMigrationsRedlock()
|
|
109
|
-
// lock for 15 minutes
|
|
110
|
-
const ttl = 1000 * 60 * 15
|
|
111
|
-
|
|
112
|
-
let migrationLock
|
|
113
|
-
|
|
114
|
-
// acquire lock
|
|
115
|
-
try {
|
|
116
|
-
migrationLock = await redlock.lock("migrations", ttl)
|
|
117
|
-
} catch (e: any) {
|
|
118
|
-
if (e.name === "LockError") {
|
|
119
|
-
return
|
|
120
|
-
} else {
|
|
121
|
-
throw e
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// run migrations
|
|
126
|
-
try {
|
|
127
|
-
await migrations.runMigrations(MIGRATIONS, options)
|
|
128
|
-
} finally {
|
|
129
|
-
// release lock
|
|
130
|
-
try {
|
|
131
|
-
await migrationLock.unlock()
|
|
132
|
-
} catch (e) {
|
|
133
|
-
console.error("unable to release migration lock")
|
|
134
|
-
}
|
|
135
|
-
}
|
|
66
|
+
await runMigrations(MIGRATIONS, options)
|
|
136
67
|
}
|
package/src/module.d.ts
CHANGED