@budibase/server 1.0.49-alpha.6 → 1.0.49
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/__mocks__/arangojs.ts +1 -1
- package/__mocks__/aws-sdk.ts +4 -4
- package/__mocks__/mongodb.ts +5 -4
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +1 -2
- package/__mocks__/pg.ts +5 -3
- package/builder/assets/{index.1b905242.js → index.2c37968e.js} +231 -234
- package/builder/assets/index.39e01193.css +1 -0
- package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2816 -3119
- package/coverage/coverage-final.json +101 -106
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +152 -257
- package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
- package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
- package/coverage/lcov-report/api/controllers/component.js.html +16 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
- package/coverage/lcov-report/api/controllers/index.html +76 -76
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
- package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
- package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/index.html +10 -10
- package/coverage/lcov-report/api/controllers/query/index.js.html +35 -38
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +16 -16
- package/coverage/lcov-report/api/controllers/routing.js.html +10 -7
- package/coverage/lcov-report/api/controllers/row/external.js.html +27 -21
- package/coverage/lcov-report/api/controllers/row/index.html +34 -49
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
- package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
- package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
- package/coverage/lcov-report/api/controllers/table/index.html +43 -58
- package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
- package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
- package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +50 -47
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +16 -16
- package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
- package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +8 -8
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
- package/coverage/lcov-report/api/routes/index.html +18 -18
- package/coverage/lcov-report/api/routes/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -17
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- 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 +13 -13
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- 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 +7 -7
- 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 +55 -61
- package/coverage/lcov-report/automations/utils.js.html +42 -54
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +26 -53
- 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/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +37 -25
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +87 -87
- 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 +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +120 -135
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +65 -173
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
- package/coverage/lcov-report/middleware/index.html +38 -38
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +24 -30
- package/coverage/lcov-report/threads/index.html +26 -26
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +26 -62
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +49 -58
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +73 -43
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
- 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/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
- package/coverage/lcov.info +4423 -5022
- package/dist/api/controllers/application.js +60 -90
- package/dist/api/controllers/auth.js +5 -8
- package/dist/api/controllers/automation.js +19 -14
- package/dist/api/controllers/cloud.js +3 -2
- package/dist/api/controllers/component.js +4 -3
- package/dist/api/controllers/datasource.js +10 -20
- package/dist/api/controllers/deploy/Deployment.js +6 -3
- package/dist/api/controllers/deploy/index.js +13 -12
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/hosting.js +30 -0
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +6 -4
- package/dist/api/controllers/query/index.js +10 -11
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +6 -5
- package/dist/api/controllers/row/ExternalRequest.js +63 -76
- package/dist/api/controllers/row/external.js +4 -4
- package/dist/api/controllers/row/internal.js +93 -55
- package/dist/api/controllers/row/internalSearch.js +17 -23
- package/dist/api/controllers/row/utils.js +14 -13
- package/dist/api/controllers/screen.js +7 -5
- package/dist/api/controllers/static/index.js +12 -61
- package/dist/api/controllers/table/external.js +10 -7
- package/dist/api/controllers/table/index.js +13 -16
- package/dist/api/controllers/table/internal.js +16 -22
- package/dist/api/controllers/table/utils.js +35 -62
- package/dist/api/controllers/user.js +20 -18
- package/dist/api/controllers/view/index.js +10 -8
- package/dist/api/controllers/view/utils.js +4 -9
- package/dist/api/controllers/webhook.js +8 -10
- package/dist/api/routes/hosting.js +11 -0
- package/dist/api/routes/index.js +2 -2
- package/dist/api/routes/static.js +1 -2
- package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
- package/dist/app.js +5 -35
- package/dist/automations/automationUtils.js +3 -2
- package/dist/automations/steps/createRow.js +5 -3
- package/dist/automations/steps/deleteRow.js +4 -1
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +25 -27
- package/dist/automations/utils.js +5 -10
- package/dist/constants/index.js +0 -7
- package/dist/db/linkedRows/LinkController.js +7 -3
- package/dist/db/linkedRows/index.js +27 -16
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +10 -9
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +1 -4
- package/dist/integrations/base/sql.js +6 -13
- package/dist/integrations/index.js +0 -3
- package/dist/integrations/utils.js +9 -60
- package/dist/middleware/authorized.js +30 -57
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +37 -41
- package/dist/middleware/usageQuota.js +15 -82
- package/dist/package.json +5 -8
- package/dist/tests/utilities/TestConfiguration.js +50 -80
- package/dist/threads/automation.js +11 -13
- package/dist/threads/query.js +13 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +3 -4
- package/dist/utilities/global.js +12 -15
- package/dist/utilities/index.js +17 -7
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +17 -23
- package/dist/utilities/rowProcessor/utils.js +4 -14
- package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +24 -4
- package/nodemon.json +1 -1
- package/package.json +6 -9
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +50 -85
- package/src/api/controllers/auth.js +5 -8
- package/src/api/controllers/automation.js +23 -13
- package/src/api/controllers/cloud.js +3 -2
- package/src/api/controllers/component.js +4 -3
- package/src/api/controllers/datasource.js +11 -21
- package/src/api/controllers/deploy/Deployment.js +7 -3
- package/src/api/controllers/deploy/index.js +13 -20
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/hosting.js +22 -0
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +9 -4
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +6 -4
- package/src/api/controllers/query/import/tests/index.spec.js +1 -2
- package/src/api/controllers/query/index.js +10 -11
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +6 -5
- package/src/api/controllers/row/ExternalRequest.ts +42 -53
- package/src/api/controllers/row/external.js +6 -4
- package/src/api/controllers/row/internal.js +90 -54
- package/src/api/controllers/row/internalSearch.js +17 -23
- package/src/api/controllers/row/utils.js +18 -13
- package/src/api/controllers/screen.js +7 -5
- package/src/api/controllers/static/index.js +12 -65
- package/src/api/controllers/table/external.js +10 -7
- package/src/api/controllers/table/index.js +28 -20
- package/src/api/controllers/table/internal.js +19 -24
- package/src/api/controllers/table/utils.js +42 -78
- package/src/api/controllers/user.js +20 -19
- package/src/api/controllers/view/index.js +10 -8
- package/src/api/controllers/view/utils.js +4 -9
- package/src/api/controllers/webhook.js +8 -10
- package/src/api/routes/hosting.js +13 -0
- package/src/api/routes/index.js +2 -2
- package/src/api/routes/static.js +0 -5
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +2 -1
- package/src/api/routes/tests/automation.spec.js +0 -1
- package/src/api/routes/tests/hosting.spec.js +36 -0
- package/src/api/routes/tests/misc.spec.js +1 -0
- package/src/api/routes/tests/routing.spec.js +12 -21
- package/src/api/routes/tests/row.spec.js +4 -7
- package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
- package/src/app.ts +5 -18
- package/src/automations/automationUtils.js +3 -2
- package/src/automations/steps/createRow.js +5 -2
- package/src/automations/steps/deleteRow.js +4 -1
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +31 -33
- package/src/automations/utils.js +5 -9
- package/src/constants/index.js +0 -9
- package/src/db/linkedRows/LinkController.js +7 -3
- package/src/db/linkedRows/index.js +31 -16
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +1 -0
- package/src/db/tests/linkTests.spec.js +6 -5
- package/src/db/views/staticViews.js +10 -8
- package/src/definitions/common.ts +0 -3
- package/src/definitions/datasource.ts +0 -3
- package/src/environment.js +1 -4
- package/src/integrations/base/sql.ts +7 -14
- package/src/integrations/index.ts +0 -3
- package/src/integrations/tests/sql.spec.js +0 -16
- package/src/integrations/utils.ts +12 -75
- package/src/middleware/authorized.js +30 -66
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +46 -50
- package/src/middleware/tests/authorized.spec.js +6 -13
- package/src/middleware/tests/currentapp.spec.js +0 -6
- package/src/middleware/tests/usageQuota.spec.js +24 -18
- package/src/middleware/usageQuota.js +17 -93
- package/src/tests/utilities/TestConfiguration.js +55 -82
- package/src/threads/automation.js +15 -17
- package/src/threads/query.js +14 -26
- package/src/utilities/fileSystem/index.js +3 -4
- package/src/utilities/global.js +12 -15
- package/src/utilities/index.js +17 -7
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +27 -25
- package/src/utilities/rowProcessor/utils.js +7 -23
- package/src/utilities/usageQuota.js +73 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +27 -4
- package/builder/assets/index.83c0944f.css +0 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
- package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
- package/dist/api/controllers/migrations.js +0 -21
- package/dist/api/controllers/row/staticFormula.js +0 -147
- package/dist/api/controllers/table/bulkFormula.js +0 -159
- package/dist/api/routes/migrations.js +0 -9
- package/dist/integrations/googlesheets.js +0 -340
- package/dist/migrations/functions/appUrls.js +0 -46
- package/dist/migrations/functions/quotas1.js +0 -50
- package/dist/migrations/functions/usageQuotas/index.js +0 -20
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -30
- package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
- package/dist/migrations/functions/userEmailViewCasing.js +0 -24
- package/dist/migrations/index.js +0 -62
- package/dist/utilities/usageQuota/rows.js +0 -78
- package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
- package/src/api/controllers/migrations.js +0 -13
- package/src/api/controllers/row/staticFormula.js +0 -156
- package/src/api/controllers/table/bulkFormula.js +0 -173
- package/src/api/routes/migrations.js +0 -14
- package/src/api/routes/tests/static.spec.js +0 -98
- package/src/integrations/googlesheets.ts +0 -353
- package/src/migrations/functions/appUrls.ts +0 -34
- package/src/migrations/functions/quotas1.ts +0 -20
- package/src/migrations/functions/tests/appUrls.spec.js +0 -29
- package/src/migrations/functions/tests/quotas1.spec.js +0 -27
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
- package/src/migrations/functions/usageQuotas/index.ts +0 -8
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
- package/src/migrations/functions/userEmailViewCasing.ts +0 -13
- package/src/migrations/index.ts +0 -56
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -93
- package/src/utilities/usageQuota/rows.js +0 -75
- package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
12
|
-
const CouchDB = require("../../db");
|
|
13
|
-
const { isDevAppID, getDevelopmentAppID } = require("@budibase/backend-core/db");
|
|
14
|
-
const ROW_EXCLUSIONS = [USER_METDATA_PREFIX];
|
|
15
|
-
const getAppPairs = appIds => {
|
|
16
|
-
// collect the app ids into dev / prod pairs
|
|
17
|
-
// keyed by the dev app id
|
|
18
|
-
const pairs = {};
|
|
19
|
-
for (let appId of appIds) {
|
|
20
|
-
const devId = getDevelopmentAppID(appId);
|
|
21
|
-
if (!pairs[devId]) {
|
|
22
|
-
pairs[devId] = {};
|
|
23
|
-
}
|
|
24
|
-
if (isDevAppID(appId)) {
|
|
25
|
-
pairs[devId].devId = appId;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
pairs[devId].prodId = appId;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return pairs;
|
|
32
|
-
};
|
|
33
|
-
const getAppRows = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
// need to specify the app ID, as this is used for different apps in one call
|
|
35
|
-
const appDb = new CouchDB(appId);
|
|
36
|
-
const response = yield appDb.allDocs(getRowParams(null, null, {
|
|
37
|
-
include_docs: false,
|
|
38
|
-
}));
|
|
39
|
-
return response.rows
|
|
40
|
-
.map(r => r.id)
|
|
41
|
-
.filter(id => {
|
|
42
|
-
for (let exclusion of ROW_EXCLUSIONS) {
|
|
43
|
-
if (id.startsWith(exclusion)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* Return a set of all rows in the given app ids.
|
|
52
|
-
* The returned rows will be unique on a per dev/prod app basis.
|
|
53
|
-
* Rows duplicates may exist across apps due to data import so they are not filtered out.
|
|
54
|
-
*/
|
|
55
|
-
exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
let uniqueRows = [];
|
|
57
|
-
const pairs = getAppPairs(appIds);
|
|
58
|
-
for (let pair of Object.values(pairs)) {
|
|
59
|
-
let appRows = [];
|
|
60
|
-
for (let appId of [pair.devId, pair.prodId]) {
|
|
61
|
-
if (!appId) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
appRows.push(yield getAppRows(appId));
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
console.error(e);
|
|
69
|
-
// don't error out if we can't count the app rows, just continue
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// ensure uniqueness on a per app pair basis
|
|
73
|
-
// this can't be done on all rows because app import results in
|
|
74
|
-
// duplicate row ids across apps
|
|
75
|
-
uniqueRows = uniqueRows.concat(...new Set(appRows));
|
|
76
|
-
}
|
|
77
|
-
return uniqueRows;
|
|
78
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// UNUSED CODE
|
|
3
|
-
// Preserved for future use
|
|
4
|
-
/* eslint-disable no-unused-vars */
|
|
5
|
-
function getNewQuotaReset() {
|
|
6
|
-
return Date.now() + 2592000000;
|
|
7
|
-
}
|
|
8
|
-
function resetQuotasIfRequired(quota) {
|
|
9
|
-
// Check if the quota needs reset
|
|
10
|
-
if (Date.now() >= quota.quotaReset) {
|
|
11
|
-
quota.quotaReset = getNewQuotaReset();
|
|
12
|
-
for (let prop of Object.keys(quota.usageQuota)) {
|
|
13
|
-
quota.usageQuota[prop] = 0;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const { migrate, MIGRATIONS } = require("../../migrations")
|
|
2
|
-
|
|
3
|
-
exports.migrate = async ctx => {
|
|
4
|
-
const options = ctx.request.body
|
|
5
|
-
// don't await as can take a while, just return
|
|
6
|
-
migrate(options)
|
|
7
|
-
ctx.status = 200
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
exports.fetchDefinitions = async ctx => {
|
|
11
|
-
ctx.body = MIGRATIONS
|
|
12
|
-
ctx.status = 200
|
|
13
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
const { getRowParams } = require("../../../db/utils")
|
|
2
|
-
const {
|
|
3
|
-
outputProcessing,
|
|
4
|
-
processAutoColumn,
|
|
5
|
-
processFormulas,
|
|
6
|
-
} = require("../../../utilities/rowProcessor")
|
|
7
|
-
const { FieldTypes, FormulaTypes } = require("../../../constants")
|
|
8
|
-
const { isEqual } = require("lodash")
|
|
9
|
-
const { cloneDeep } = require("lodash/fp")
|
|
10
|
-
const { getAppDB } = require("@budibase/backend-core/context")
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This function runs through a list of enriched rows, looks at the rows which
|
|
14
|
-
* are related and then checks if they need the state of their formulas
|
|
15
|
-
* updated.
|
|
16
|
-
* NOTE: this will only for affect static formulas.
|
|
17
|
-
*/
|
|
18
|
-
exports.updateRelatedFormula = async (table, enrichedRows) => {
|
|
19
|
-
const db = getAppDB()
|
|
20
|
-
// no formula to update, we're done
|
|
21
|
-
if (!table.relatedFormula) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
let promises = []
|
|
25
|
-
for (let enrichedRow of Array.isArray(enrichedRows)
|
|
26
|
-
? enrichedRows
|
|
27
|
-
: [enrichedRows]) {
|
|
28
|
-
// the related rows by tableId
|
|
29
|
-
let relatedRows = {}
|
|
30
|
-
for (let [key, field] of Object.entries(enrichedRow)) {
|
|
31
|
-
const columnDefinition = table.schema[key]
|
|
32
|
-
if (columnDefinition && columnDefinition.type === FieldTypes.LINK) {
|
|
33
|
-
const relatedTableId = columnDefinition.tableId
|
|
34
|
-
if (!relatedRows[relatedTableId]) {
|
|
35
|
-
relatedRows[relatedTableId] = []
|
|
36
|
-
}
|
|
37
|
-
relatedRows[relatedTableId] = relatedRows[relatedTableId].concat(field)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
for (let tableId of table.relatedFormula) {
|
|
41
|
-
let relatedTable
|
|
42
|
-
try {
|
|
43
|
-
// no rows to update, skip
|
|
44
|
-
if (!relatedRows[tableId] || relatedRows[tableId].length === 0) {
|
|
45
|
-
continue
|
|
46
|
-
}
|
|
47
|
-
relatedTable = await db.get(tableId)
|
|
48
|
-
} catch (err) {
|
|
49
|
-
// no error scenario, table doesn't seem to exist anymore, ignore
|
|
50
|
-
}
|
|
51
|
-
for (let column of Object.values(relatedTable.schema)) {
|
|
52
|
-
// needs updated in related rows
|
|
53
|
-
if (
|
|
54
|
-
column.type === FieldTypes.FORMULA &&
|
|
55
|
-
column.formulaType === FormulaTypes.STATIC
|
|
56
|
-
) {
|
|
57
|
-
// re-enrich rows for all the related, don't update the related formula for them
|
|
58
|
-
promises = promises.concat(
|
|
59
|
-
relatedRows[tableId].map(related =>
|
|
60
|
-
exports.finaliseRow(relatedTable, related, {
|
|
61
|
-
updateFormula: false,
|
|
62
|
-
})
|
|
63
|
-
)
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
await Promise.all(promises)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
exports.updateAllFormulasInTable = async table => {
|
|
73
|
-
const db = getAppDB()
|
|
74
|
-
// start by getting the raw rows (which will be written back to DB after update)
|
|
75
|
-
let rows = (
|
|
76
|
-
await db.allDocs(
|
|
77
|
-
getRowParams(table._id, null, {
|
|
78
|
-
include_docs: true,
|
|
79
|
-
})
|
|
80
|
-
)
|
|
81
|
-
).rows.map(row => row.doc)
|
|
82
|
-
// now enrich the rows, note the clone so that we have the base state of the
|
|
83
|
-
// rows so that we don't write any of the enriched information back
|
|
84
|
-
let enrichedRows = await outputProcessing(table, cloneDeep(rows), {
|
|
85
|
-
squash: false,
|
|
86
|
-
})
|
|
87
|
-
const updatedRows = []
|
|
88
|
-
for (let row of rows) {
|
|
89
|
-
// find the enriched row, if found process the formulas
|
|
90
|
-
const enrichedRow = enrichedRows.find(enriched => enriched._id === row._id)
|
|
91
|
-
if (enrichedRow) {
|
|
92
|
-
const processed = processFormulas(table, cloneDeep(row), {
|
|
93
|
-
dynamic: false,
|
|
94
|
-
contextRows: enrichedRow,
|
|
95
|
-
})
|
|
96
|
-
// values have changed, need to add to bulk docs to update
|
|
97
|
-
if (!isEqual(processed, row)) {
|
|
98
|
-
updatedRows.push(processed)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
await db.bulkDocs(updatedRows)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* This function runs at the end of the save/patch functions of the row controller, all this
|
|
107
|
-
* really does is enrich the row, handle any static formula processing, then return the enriched
|
|
108
|
-
* row. The reason we need to return the enriched row is that the automation row created trigger
|
|
109
|
-
* expects the row to be totally enriched/contain all relationships.
|
|
110
|
-
*/
|
|
111
|
-
exports.finaliseRow = async (
|
|
112
|
-
table,
|
|
113
|
-
row,
|
|
114
|
-
{ oldTable, updateFormula } = { updateFormula: true }
|
|
115
|
-
) => {
|
|
116
|
-
const db = getAppDB()
|
|
117
|
-
row.type = "row"
|
|
118
|
-
// process the row before return, to include relationships
|
|
119
|
-
let enrichedRow = await outputProcessing(table, cloneDeep(row), {
|
|
120
|
-
squash: false,
|
|
121
|
-
})
|
|
122
|
-
// use enriched row to generate formulas for saving, specifically only use as context
|
|
123
|
-
row = processFormulas(table, row, {
|
|
124
|
-
dynamic: false,
|
|
125
|
-
contextRows: enrichedRow,
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
// don't worry about rev, tables handle rev/lastID updates
|
|
129
|
-
// if another row has been written since processing this will
|
|
130
|
-
// handle the auto ID clash
|
|
131
|
-
if (oldTable && !isEqual(oldTable, table)) {
|
|
132
|
-
try {
|
|
133
|
-
await db.put(table)
|
|
134
|
-
} catch (err) {
|
|
135
|
-
if (err.status === 409) {
|
|
136
|
-
const updatedTable = await db.get(table._id)
|
|
137
|
-
let response = processAutoColumn(null, updatedTable, row, {
|
|
138
|
-
reprocessing: true,
|
|
139
|
-
})
|
|
140
|
-
await db.put(response.table)
|
|
141
|
-
row = response.row
|
|
142
|
-
} else {
|
|
143
|
-
throw err
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const response = await db.put(row)
|
|
148
|
-
// for response, calculate the formulas for the enriched row
|
|
149
|
-
enrichedRow._rev = response.rev
|
|
150
|
-
enrichedRow = await processFormulas(table, enrichedRow, { dynamic: false })
|
|
151
|
-
// this updates the related formulas in other rows based on the relations to this row
|
|
152
|
-
if (updateFormula) {
|
|
153
|
-
await exports.updateRelatedFormula(table, enrichedRow)
|
|
154
|
-
}
|
|
155
|
-
return { row: enrichedRow, table }
|
|
156
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
const { FieldTypes, FormulaTypes } = require("../../../constants")
|
|
2
|
-
const { getAllInternalTables, clearColumns } = require("./utils")
|
|
3
|
-
const { doesContainStrings } = require("@budibase/string-templates")
|
|
4
|
-
const { cloneDeep } = require("lodash/fp")
|
|
5
|
-
const { isEqual, uniq } = require("lodash")
|
|
6
|
-
const { updateAllFormulasInTable } = require("../row/staticFormula")
|
|
7
|
-
const { getAppDB } = require("@budibase/backend-core/context")
|
|
8
|
-
|
|
9
|
-
function isStaticFormula(column) {
|
|
10
|
-
return (
|
|
11
|
-
column.type === FieldTypes.FORMULA &&
|
|
12
|
-
column.formulaType === FormulaTypes.STATIC
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* This retrieves the formula columns from a table schema that use a specified column name
|
|
18
|
-
* in the formula.
|
|
19
|
-
*/
|
|
20
|
-
function getFormulaThatUseColumn(table, columnNames) {
|
|
21
|
-
let formula = []
|
|
22
|
-
columnNames = Array.isArray(columnNames) ? columnNames : [columnNames]
|
|
23
|
-
for (let column of Object.values(table.schema)) {
|
|
24
|
-
// not a static formula, or doesn't contain a relationship
|
|
25
|
-
if (!isStaticFormula(column)) {
|
|
26
|
-
continue
|
|
27
|
-
}
|
|
28
|
-
if (!doesContainStrings(column.formula, columnNames)) {
|
|
29
|
-
continue
|
|
30
|
-
}
|
|
31
|
-
formula.push(column.name)
|
|
32
|
-
}
|
|
33
|
-
return formula
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* This functions checks for when a related table, column or related column is deleted, if any
|
|
38
|
-
* tables need to have the formula column removed.
|
|
39
|
-
*/
|
|
40
|
-
async function checkIfFormulaNeedsCleared(table, { oldTable, deletion }) {
|
|
41
|
-
// start by retrieving all tables, remove the current table from the list
|
|
42
|
-
const tables = (await getAllInternalTables()).filter(
|
|
43
|
-
tbl => tbl._id !== table._id
|
|
44
|
-
)
|
|
45
|
-
const schemaToUse = oldTable ? oldTable.schema : table.schema
|
|
46
|
-
let removedColumns = Object.values(schemaToUse).filter(
|
|
47
|
-
column => deletion || !table.schema[column.name]
|
|
48
|
-
)
|
|
49
|
-
// remove any formula columns that used related columns
|
|
50
|
-
for (let removed of removedColumns) {
|
|
51
|
-
let tableToUse = table
|
|
52
|
-
// if relationship, get the related table
|
|
53
|
-
if (removed.type === FieldTypes.LINK) {
|
|
54
|
-
tableToUse = tables.find(table => table._id === removed.tableId)
|
|
55
|
-
}
|
|
56
|
-
const columnsToDelete = getFormulaThatUseColumn(tableToUse, removed.name)
|
|
57
|
-
if (columnsToDelete.length > 0) {
|
|
58
|
-
await clearColumns(table, columnsToDelete)
|
|
59
|
-
}
|
|
60
|
-
// need a special case, where a column has been removed from this table, but was used
|
|
61
|
-
// in a different, related tables formula
|
|
62
|
-
if (!table.relatedFormula) {
|
|
63
|
-
continue
|
|
64
|
-
}
|
|
65
|
-
for (let relatedTableId of table.relatedFormula) {
|
|
66
|
-
const relatedColumns = Object.values(table.schema).filter(
|
|
67
|
-
column => column.tableId === relatedTableId
|
|
68
|
-
)
|
|
69
|
-
const relatedTable = tables.find(table => table._id === relatedTableId)
|
|
70
|
-
// look to see if the column was used in a relationship formula,
|
|
71
|
-
// relationships won't be used for this
|
|
72
|
-
if (relatedTable && relatedColumns && removed.type !== FieldTypes.LINK) {
|
|
73
|
-
let relatedFormulaToRemove = []
|
|
74
|
-
for (let column of relatedColumns) {
|
|
75
|
-
relatedFormulaToRemove = relatedFormulaToRemove.concat(
|
|
76
|
-
getFormulaThatUseColumn(relatedTable, [
|
|
77
|
-
column.fieldName,
|
|
78
|
-
removed.name,
|
|
79
|
-
])
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
if (relatedFormulaToRemove.length > 0) {
|
|
83
|
-
await clearColumns(relatedTable, uniq(relatedFormulaToRemove))
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* This function adds a note to related tables that they are
|
|
92
|
-
* used in a static formula - so that the link controller
|
|
93
|
-
* can manage hydrating related rows formula fields. This is
|
|
94
|
-
* specifically only for static formula.
|
|
95
|
-
*/
|
|
96
|
-
async function updateRelatedFormulaLinksOnTables(
|
|
97
|
-
table,
|
|
98
|
-
{ deletion } = { deletion: false }
|
|
99
|
-
) {
|
|
100
|
-
const db = getAppDB()
|
|
101
|
-
// start by retrieving all tables, remove the current table from the list
|
|
102
|
-
const tables = (await getAllInternalTables()).filter(
|
|
103
|
-
tbl => tbl._id !== table._id
|
|
104
|
-
)
|
|
105
|
-
// clone the tables, so we can compare at end
|
|
106
|
-
const initialTables = cloneDeep(tables)
|
|
107
|
-
// first find the related column names
|
|
108
|
-
const relatedColumns = Object.values(table.schema).filter(
|
|
109
|
-
col => col.type === FieldTypes.LINK
|
|
110
|
-
)
|
|
111
|
-
// we start by removing the formula field from all tables
|
|
112
|
-
for (let otherTable of tables) {
|
|
113
|
-
if (!otherTable.relatedFormula) {
|
|
114
|
-
continue
|
|
115
|
-
}
|
|
116
|
-
const index = otherTable.relatedFormula.indexOf(table._id)
|
|
117
|
-
if (index !== -1) {
|
|
118
|
-
otherTable.relatedFormula.splice(index, 1)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// if deleting, just remove the table IDs, don't try add
|
|
122
|
-
if (!deletion) {
|
|
123
|
-
for (let relatedCol of relatedColumns) {
|
|
124
|
-
let columns = getFormulaThatUseColumn(table, relatedCol.name)
|
|
125
|
-
if (!columns || columns.length === 0) {
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
const relatedTable = tables.find(
|
|
129
|
-
related => related._id === relatedCol.tableId
|
|
130
|
-
)
|
|
131
|
-
// check if the table is already in the list of related formula, if it isn't, then add it
|
|
132
|
-
if (
|
|
133
|
-
relatedTable &&
|
|
134
|
-
(!relatedTable.relatedFormula ||
|
|
135
|
-
!relatedTable.relatedFormula.includes(table._id))
|
|
136
|
-
) {
|
|
137
|
-
relatedTable.relatedFormula = relatedTable.relatedFormula
|
|
138
|
-
? [...relatedTable.relatedFormula, table._id]
|
|
139
|
-
: [table._id]
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// now we just need to compare all the tables and see if any need saved
|
|
144
|
-
for (let initial of initialTables) {
|
|
145
|
-
const found = tables.find(tbl => initial._id === tbl._id)
|
|
146
|
-
if (found && !isEqual(initial, found)) {
|
|
147
|
-
await db.put(found)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async function checkIfFormulaUpdated(table, { oldTable }) {
|
|
153
|
-
// look to see if any formula values have changed
|
|
154
|
-
const shouldUpdate = Object.values(table.schema).find(
|
|
155
|
-
column =>
|
|
156
|
-
isStaticFormula(column) &&
|
|
157
|
-
(!oldTable ||
|
|
158
|
-
!oldTable.schema[column.name] ||
|
|
159
|
-
!isEqual(oldTable.schema[column.name], column))
|
|
160
|
-
)
|
|
161
|
-
// if a static formula column has updated, then need to run the update
|
|
162
|
-
if (shouldUpdate != null) {
|
|
163
|
-
await updateAllFormulasInTable(table)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
exports.runStaticFormulaChecks = async (table, { oldTable, deletion }) => {
|
|
168
|
-
await updateRelatedFormulaLinksOnTables(table, { deletion })
|
|
169
|
-
await checkIfFormulaNeedsCleared(table, { oldTable, deletion })
|
|
170
|
-
if (!deletion) {
|
|
171
|
-
await checkIfFormulaUpdated(table, { oldTable })
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const Router = require("@koa/router")
|
|
2
|
-
const migrationsController = require("../controllers/migrations")
|
|
3
|
-
const router = Router()
|
|
4
|
-
const { internalApi } = require("@budibase/backend-core/auth")
|
|
5
|
-
|
|
6
|
-
router
|
|
7
|
-
.post("/api/migrations/run", internalApi, migrationsController.migrate)
|
|
8
|
-
.get(
|
|
9
|
-
"/api/migrations/definitions",
|
|
10
|
-
internalApi,
|
|
11
|
-
migrationsController.fetchDefinitions
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
module.exports = router
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
jest.mock("node-fetch")
|
|
2
|
-
jest.mock("aws-sdk", () => ({
|
|
3
|
-
config: {
|
|
4
|
-
update: jest.fn(),
|
|
5
|
-
},
|
|
6
|
-
DynamoDB: {
|
|
7
|
-
DocumentClient: jest.fn(),
|
|
8
|
-
},
|
|
9
|
-
S3: jest.fn(() => ({
|
|
10
|
-
getSignedUrl: jest.fn(() => {
|
|
11
|
-
return "my-url"
|
|
12
|
-
}),
|
|
13
|
-
})),
|
|
14
|
-
}))
|
|
15
|
-
|
|
16
|
-
const setup = require("./utilities")
|
|
17
|
-
|
|
18
|
-
describe("/attachments", () => {
|
|
19
|
-
let request = setup.getRequest()
|
|
20
|
-
let config = setup.getConfig()
|
|
21
|
-
let app
|
|
22
|
-
|
|
23
|
-
afterAll(setup.afterAll)
|
|
24
|
-
|
|
25
|
-
beforeEach(async () => {
|
|
26
|
-
app = await config.init()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe("generateSignedUrls", () => {
|
|
30
|
-
let datasource
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
datasource = await config.createDatasource({
|
|
34
|
-
datasource: {
|
|
35
|
-
type: "datasource",
|
|
36
|
-
name: "Test",
|
|
37
|
-
source: "S3",
|
|
38
|
-
config: {},
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it("should be able to generate a signed upload URL", async () => {
|
|
44
|
-
const bucket = "foo"
|
|
45
|
-
const key = "bar"
|
|
46
|
-
const res = await request
|
|
47
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
48
|
-
.send({ bucket, key })
|
|
49
|
-
.set(config.defaultHeaders())
|
|
50
|
-
.expect("Content-Type", /json/)
|
|
51
|
-
.expect(200)
|
|
52
|
-
expect(res.body.signedUrl).toEqual("my-url")
|
|
53
|
-
expect(res.body.publicUrl).toEqual(
|
|
54
|
-
`https://${bucket}.s3.eu-west-1.amazonaws.com/${key}`
|
|
55
|
-
)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it("should handle an invalid datasource ID", async () => {
|
|
59
|
-
const res = await request
|
|
60
|
-
.post(`/api/attachments/foo/url`)
|
|
61
|
-
.send({
|
|
62
|
-
bucket: "foo",
|
|
63
|
-
key: "bar",
|
|
64
|
-
})
|
|
65
|
-
.set(config.defaultHeaders())
|
|
66
|
-
.expect("Content-Type", /json/)
|
|
67
|
-
.expect(400)
|
|
68
|
-
expect(res.body.message).toEqual(
|
|
69
|
-
"The specified datasource could not be found"
|
|
70
|
-
)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it("should require a bucket parameter", async () => {
|
|
74
|
-
const res = await request
|
|
75
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
76
|
-
.send({
|
|
77
|
-
bucket: undefined,
|
|
78
|
-
key: "bar",
|
|
79
|
-
})
|
|
80
|
-
.set(config.defaultHeaders())
|
|
81
|
-
.expect("Content-Type", /json/)
|
|
82
|
-
.expect(400)
|
|
83
|
-
expect(res.body.message).toEqual("bucket and key values are required")
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it("should require a key parameter", async () => {
|
|
87
|
-
const res = await request
|
|
88
|
-
.post(`/api/attachments/${datasource._id}/url`)
|
|
89
|
-
.send({
|
|
90
|
-
bucket: "foo",
|
|
91
|
-
})
|
|
92
|
-
.set(config.defaultHeaders())
|
|
93
|
-
.expect("Content-Type", /json/)
|
|
94
|
-
.expect(400)
|
|
95
|
-
expect(res.body.message).toEqual("bucket and key values are required")
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
})
|