@budibase/server 1.0.48 → 1.0.49-alpha.11
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 +4 -5
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +2 -1
- package/__mocks__/pg.ts +3 -5
- package/builder/assets/index.83c0944f.css +1 -0
- package/builder/assets/{index.e083dcaf.js → index.ae50a4cf.js} +249 -246
- package/builder/assets/{vendor.f9faf6ab.js → vendor.d526bfe8.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +3062 -2777
- package/coverage/coverage-final.json +106 -101
- 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 +257 -152
- package/coverage/lcov-report/api/controllers/auth.js.html +22 -13
- package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
- package/coverage/lcov-report/api/controllers/component.js.html +13 -16
- package/coverage/lcov-report/api/controllers/datasource.js.html +81 -51
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- 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 +6 -21
- package/coverage/lcov-report/api/controllers/migrations.js.html +119 -0
- 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 +38 -35
- 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 +7 -10
- package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
- package/coverage/lcov-report/api/controllers/row/index.html +55 -40
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +118 -226
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
- package/coverage/lcov-report/api/controllers/row/utils.js.html +47 -62
- package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +599 -0
- package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
- package/coverage/lcov-report/api/controllers/table/index.html +58 -43
- package/coverage/lcov-report/api/controllers/table/index.js.html +58 -82
- package/coverage/lcov-report/api/controllers/table/internal.js.html +81 -66
- package/coverage/lcov-report/api/controllers/table/utils.js.html +218 -110
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +47 -50
- 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 +27 -33
- package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
- 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/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/{hosting.js.html → migrations.js.html} +17 -14
- 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 +17 -2
- 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 +7 -10
- 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 +13 -22
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
- 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 +61 -55
- package/coverage/lcov-report/automations/utils.js.html +54 -42
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +53 -26
- 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 +25 -37
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +51 -96
- 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 +135 -120
- 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 +173 -65
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +95 -83
- 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 +281 -53
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +30 -24
- 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 +36 -42
- 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 +58 -49
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +43 -73
- 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 +97 -103
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
- 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 +141 -0
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +305 -0
- package/coverage/lcov-report/{api/controllers/hosting.js.html → utilities/usageQuota/usageQuoteReset.js.html} +36 -48
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +43 -112
- package/coverage/lcov.info +4982 -4409
- package/dist/api/controllers/application.js +90 -60
- package/dist/api/controllers/auth.js +8 -5
- package/dist/api/controllers/automation.js +14 -19
- package/dist/api/controllers/cloud.js +2 -3
- package/dist/api/controllers/component.js +3 -4
- package/dist/api/controllers/datasource.js +20 -10
- package/dist/api/controllers/deploy/Deployment.js +3 -6
- package/dist/api/controllers/deploy/index.js +12 -13
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/migrations.js +21 -0
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +4 -6
- package/dist/api/controllers/query/index.js +11 -10
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +5 -6
- package/dist/api/controllers/row/ExternalRequest.js +90 -67
- package/dist/api/controllers/row/external.js +14 -22
- package/dist/api/controllers/row/internal.js +55 -93
- package/dist/api/controllers/row/internalSearch.js +23 -17
- package/dist/api/controllers/row/staticFormula.js +147 -0
- package/dist/api/controllers/row/utils.js +13 -14
- package/dist/api/controllers/screen.js +5 -7
- package/dist/api/controllers/static/index.js +61 -12
- package/dist/api/controllers/table/bulkFormula.js +159 -0
- package/dist/api/controllers/table/external.js +7 -10
- package/dist/api/controllers/table/index.js +16 -13
- package/dist/api/controllers/table/internal.js +22 -16
- package/dist/api/controllers/table/utils.js +62 -35
- package/dist/api/controllers/user.js +18 -20
- package/dist/api/controllers/view/index.js +8 -10
- package/dist/api/controllers/view/utils.js +9 -4
- package/dist/api/controllers/webhook.js +10 -8
- package/dist/api/routes/index.js +2 -2
- package/dist/api/routes/migrations.js +9 -0
- package/dist/api/routes/static.js +2 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
- package/dist/app.js +35 -5
- package/dist/automations/automationUtils.js +2 -3
- package/dist/automations/steps/createRow.js +3 -5
- package/dist/automations/steps/deleteRow.js +1 -4
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +27 -25
- package/dist/automations/utils.js +10 -5
- package/dist/constants/index.js +7 -0
- package/dist/db/linkedRows/LinkController.js +3 -7
- package/dist/db/linkedRows/index.js +16 -27
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +9 -10
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +4 -1
- package/dist/integrations/base/sql.js +56 -14
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +60 -9
- package/dist/middleware/authorized.js +57 -30
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +41 -37
- package/dist/middleware/usageQuota.js +82 -15
- package/dist/migrations/functions/appUrls.js +46 -0
- package/dist/migrations/functions/quotas1.js +50 -0
- package/dist/migrations/functions/usageQuotas/index.js +20 -0
- package/dist/migrations/functions/usageQuotas/syncApps.js +29 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +33 -0
- package/dist/migrations/functions/userEmailViewCasing.js +24 -0
- package/dist/migrations/index.js +62 -0
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +80 -50
- package/dist/threads/automation.js +13 -11
- package/dist/threads/query.js +17 -19
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +4 -3
- package/dist/utilities/global.js +15 -12
- package/dist/utilities/index.js +7 -17
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +23 -17
- package/dist/utilities/rowProcessor/utils.js +14 -4
- package/dist/utilities/{usageQuota.js → usageQuota/index.js} +45 -31
- package/dist/utilities/usageQuota/rows.js +78 -0
- package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +4 -24
- package/nodemon.json +1 -1
- package/package.json +9 -6
- package/scripts/integrations/postgres/init.sql +11 -6
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +85 -50
- package/src/api/controllers/auth.js +8 -5
- package/src/api/controllers/automation.js +13 -23
- package/src/api/controllers/cloud.js +2 -3
- package/src/api/controllers/component.js +3 -4
- package/src/api/controllers/datasource.js +21 -11
- package/src/api/controllers/deploy/Deployment.js +3 -7
- package/src/api/controllers/deploy/index.js +20 -13
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +4 -9
- package/src/api/controllers/migrations.js +13 -0
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +4 -6
- package/src/api/controllers/query/import/tests/index.spec.js +2 -1
- package/src/api/controllers/query/index.js +11 -10
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +5 -6
- package/src/api/controllers/row/ExternalRequest.ts +67 -43
- package/src/api/controllers/row/external.js +27 -58
- package/src/api/controllers/row/internal.js +54 -90
- package/src/api/controllers/row/internalSearch.js +23 -17
- package/src/api/controllers/row/staticFormula.js +156 -0
- package/src/api/controllers/row/utils.js +13 -18
- package/src/api/controllers/screen.js +5 -7
- package/src/api/controllers/static/index.js +65 -12
- package/src/api/controllers/table/bulkFormula.js +173 -0
- package/src/api/controllers/table/external.js +7 -10
- package/src/api/controllers/table/index.js +20 -28
- package/src/api/controllers/table/internal.js +24 -19
- package/src/api/controllers/table/utils.js +78 -42
- package/src/api/controllers/user.js +19 -20
- package/src/api/controllers/view/index.js +8 -10
- package/src/api/controllers/view/utils.js +9 -4
- package/src/api/controllers/webhook.js +10 -8
- package/src/api/routes/index.js +2 -2
- package/src/api/routes/migrations.js +14 -0
- package/src/api/routes/static.js +5 -0
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/api/routes/tests/automation.spec.js +1 -0
- package/src/api/routes/tests/misc.spec.js +0 -1
- package/src/api/routes/tests/routing.spec.js +21 -12
- package/src/api/routes/tests/row.spec.js +7 -4
- package/src/api/routes/tests/static.spec.js +98 -0
- package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
- package/src/app.ts +18 -5
- package/src/automations/automationUtils.js +2 -3
- package/src/automations/steps/createRow.js +2 -5
- package/src/automations/steps/deleteRow.js +1 -4
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +33 -31
- package/src/automations/utils.js +9 -5
- package/src/constants/index.js +9 -0
- package/src/db/linkedRows/LinkController.js +3 -7
- package/src/db/linkedRows/index.js +16 -31
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +0 -1
- package/src/db/tests/linkTests.spec.js +5 -6
- package/src/db/views/staticViews.js +8 -10
- package/src/definitions/common.ts +3 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/environment.js +4 -1
- package/src/integrations/base/sql.ts +69 -21
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/tests/sql.spec.js +16 -0
- package/src/integrations/utils.ts +75 -12
- package/src/middleware/authorized.js +66 -30
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +50 -46
- package/src/middleware/tests/authorized.spec.js +13 -6
- package/src/middleware/tests/currentapp.spec.js +6 -0
- package/src/middleware/tests/usageQuota.spec.js +18 -24
- package/src/middleware/usageQuota.js +93 -17
- package/src/migrations/functions/appUrls.ts +34 -0
- package/src/migrations/functions/quotas1.ts +20 -0
- package/src/migrations/functions/tests/appUrls.spec.js +29 -0
- package/src/migrations/functions/tests/quotas1.spec.js +27 -0
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
- package/src/migrations/functions/usageQuotas/index.ts +8 -0
- package/src/migrations/functions/usageQuotas/syncApps.ts +18 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +37 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +43 -0
- package/src/migrations/functions/userEmailViewCasing.ts +13 -0
- package/src/migrations/index.ts +56 -0
- package/src/module.d.ts +3 -0
- package/src/tests/utilities/TestConfiguration.js +82 -55
- package/src/threads/automation.js +17 -15
- package/src/threads/query.js +19 -21
- package/src/utilities/fileSystem/index.js +4 -3
- package/src/utilities/global.js +15 -12
- package/src/utilities/index.js +7 -17
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +25 -27
- package/src/utilities/rowProcessor/utils.js +23 -7
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +93 -0
- package/src/utilities/usageQuota/rows.js +75 -0
- package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +4 -27
- package/tsconfig.json +2 -1
- package/builder/assets/index.39e01193.css +0 -1
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- package/src/api/routes/tests/hosting.spec.js +0 -36
- package/src/utilities/usageQuota.js +0 -73
|
@@ -9,12 +9,12 @@ const {
|
|
|
9
9
|
getLinkedTable,
|
|
10
10
|
} = require("./linkUtils")
|
|
11
11
|
const { flatten } = require("lodash")
|
|
12
|
-
const CouchDB = require("../../db")
|
|
13
12
|
const { FieldTypes } = require("../../constants")
|
|
14
13
|
const { getMultiIDParams, USER_METDATA_PREFIX } = require("../../db/utils")
|
|
15
14
|
const { partition } = require("lodash")
|
|
16
15
|
const { getGlobalUsersFromMetadata } = require("../../utilities/global")
|
|
17
16
|
const { processFormulas } = require("../../utilities/rowProcessor/utils")
|
|
17
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* This functionality makes sure that when rows with links are created, updated or deleted they are processed
|
|
@@ -48,14 +48,13 @@ function clearRelationshipFields(table, rows) {
|
|
|
48
48
|
return rows
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async function getLinksForRows(
|
|
51
|
+
async function getLinksForRows(rows) {
|
|
52
52
|
const tableIds = [...new Set(rows.map(el => el.tableId))]
|
|
53
53
|
// start by getting all the link values for performance reasons
|
|
54
54
|
const responses = flatten(
|
|
55
55
|
await Promise.all(
|
|
56
56
|
tableIds.map(tableId =>
|
|
57
57
|
getLinkDocuments({
|
|
58
|
-
appId,
|
|
59
58
|
tableId: tableId,
|
|
60
59
|
includeDocs: IncludeDocs.EXCLUDE,
|
|
61
60
|
})
|
|
@@ -72,9 +71,9 @@ async function getLinksForRows(appId, rows) {
|
|
|
72
71
|
)
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
async function getFullLinkedDocs(
|
|
74
|
+
async function getFullLinkedDocs(links) {
|
|
76
75
|
// create DBs
|
|
77
|
-
const db =
|
|
76
|
+
const db = getAppDB()
|
|
78
77
|
const linkedRowIds = links.map(link => link.id)
|
|
79
78
|
const uniqueRowIds = [...new Set(linkedRowIds)]
|
|
80
79
|
let dbRows = (await db.allDocs(getMultiIDParams(uniqueRowIds))).rows.map(
|
|
@@ -88,7 +87,7 @@ async function getFullLinkedDocs(ctx, appId, links) {
|
|
|
88
87
|
let [users, other] = partition(linked, linkRow =>
|
|
89
88
|
linkRow._id.startsWith(USER_METDATA_PREFIX)
|
|
90
89
|
)
|
|
91
|
-
users = await getGlobalUsersFromMetadata(
|
|
90
|
+
users = await getGlobalUsersFromMetadata(users)
|
|
92
91
|
return [...other, ...users]
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -96,20 +95,16 @@ async function getFullLinkedDocs(ctx, appId, links) {
|
|
|
96
95
|
* Update link documents for a row or table - this is to be called by the API controller when a change is occurring.
|
|
97
96
|
* @param {string} args.eventType states what type of change which is occurring, means this can be expanded upon in the
|
|
98
97
|
* future quite easily (all updates go through one function).
|
|
99
|
-
* @param {string} args.appId The ID of the instance in which the change is occurring.
|
|
100
98
|
* @param {string} args.tableId The ID of the of the table which is being changed.
|
|
101
|
-
* @param {object|
|
|
102
|
-
* @param {object|
|
|
103
|
-
* @param {object|
|
|
99
|
+
* @param {object|undefined} args.row The row which is changing, e.g. created, updated or deleted.
|
|
100
|
+
* @param {object|undefined} args.table If the table has already been retrieved this can be used to reduce database gets.
|
|
101
|
+
* @param {object|undefined} args.oldTable If the table is being updated then the old table can be provided for differencing.
|
|
104
102
|
* @returns {Promise<object>} When the update is complete this will respond successfully. Returns the row for
|
|
105
103
|
* row operations and the table for table operations.
|
|
106
104
|
*/
|
|
107
105
|
exports.updateLinks = async function (args) {
|
|
108
|
-
const { eventType,
|
|
106
|
+
const { eventType, row, tableId, table, oldTable } = args
|
|
109
107
|
const baseReturnObj = row == null ? table : row
|
|
110
|
-
if (appId == null) {
|
|
111
|
-
throw "Cannot operate without an instance ID."
|
|
112
|
-
}
|
|
113
108
|
// make sure table ID is set
|
|
114
109
|
if (tableId == null && table != null) {
|
|
115
110
|
args.tableId = table._id
|
|
@@ -146,27 +141,23 @@ exports.updateLinks = async function (args) {
|
|
|
146
141
|
/**
|
|
147
142
|
* Given a table and a list of rows this will retrieve all of the attached docs and enrich them into the row.
|
|
148
143
|
* This is required for formula fields, this may only be utilised internally (for now).
|
|
149
|
-
* @param {object} ctx The request which is looking for rows.
|
|
150
144
|
* @param {object} table The table from which the rows originated.
|
|
151
145
|
* @param {array<object>} rows The rows which are to be enriched.
|
|
152
146
|
* @return {Promise<*>} returns the rows with all of the enriched relationships on it.
|
|
153
147
|
*/
|
|
154
|
-
exports.attachFullLinkedDocs = async (
|
|
155
|
-
const appId = ctx.appId
|
|
148
|
+
exports.attachFullLinkedDocs = async (table, rows) => {
|
|
156
149
|
const linkedTableIds = getLinkedTableIDs(table)
|
|
157
150
|
if (linkedTableIds.length === 0) {
|
|
158
151
|
return rows
|
|
159
152
|
}
|
|
160
|
-
// create DBs
|
|
161
|
-
const db = new CouchDB(appId)
|
|
162
153
|
// get all the links
|
|
163
|
-
const links = (await getLinksForRows(
|
|
154
|
+
const links = (await getLinksForRows(rows)).filter(link =>
|
|
164
155
|
rows.some(row => row._id === link.thisId)
|
|
165
156
|
)
|
|
166
157
|
// clear any existing links that could be dupe'd
|
|
167
158
|
rows = clearRelationshipFields(table, rows)
|
|
168
159
|
// now get the docs and combine into the rows
|
|
169
|
-
let linked = await getFullLinkedDocs(
|
|
160
|
+
let linked = await getFullLinkedDocs(links)
|
|
170
161
|
const linkedTables = []
|
|
171
162
|
for (let row of rows) {
|
|
172
163
|
for (let link of links.filter(link => link.thisId === row._id)) {
|
|
@@ -177,11 +168,7 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
|
|
|
177
168
|
if (linkedRow) {
|
|
178
169
|
const linkedTableId =
|
|
179
170
|
linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
|
|
180
|
-
const linkedTable = await getLinkedTable(
|
|
181
|
-
db,
|
|
182
|
-
linkedTableId,
|
|
183
|
-
linkedTables
|
|
184
|
-
)
|
|
171
|
+
const linkedTable = await getLinkedTable(linkedTableId, linkedTables)
|
|
185
172
|
if (linkedTable) {
|
|
186
173
|
row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
|
|
187
174
|
}
|
|
@@ -193,18 +180,16 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
|
|
|
193
180
|
|
|
194
181
|
/**
|
|
195
182
|
* This function will take the given enriched rows and squash the links to only contain the primary display field.
|
|
196
|
-
* @param {string} appId The app in which the tables/rows/links exist.
|
|
197
183
|
* @param {object} table The table from which the rows originated.
|
|
198
184
|
* @param {array<object>} enriched The pre-enriched rows (full docs) which are to be squashed.
|
|
199
185
|
* @returns {Promise<Array>} The rows after having their links squashed to only contain the ID and primary display.
|
|
200
186
|
*/
|
|
201
|
-
exports.squashLinksToPrimaryDisplay = async (
|
|
202
|
-
const db = new CouchDB(appId)
|
|
187
|
+
exports.squashLinksToPrimaryDisplay = async (table, enriched) => {
|
|
203
188
|
// will populate this as we find them
|
|
204
189
|
const linkedTables = [table]
|
|
205
190
|
for (let row of enriched) {
|
|
206
191
|
// this only fetches the table if its not already in array
|
|
207
|
-
const rowTable = await getLinkedTable(
|
|
192
|
+
const rowTable = await getLinkedTable(row.tableId, linkedTables)
|
|
208
193
|
for (let [column, schema] of Object.entries(rowTable.schema)) {
|
|
209
194
|
if (schema.type !== FieldTypes.LINK || !Array.isArray(row[column])) {
|
|
210
195
|
continue
|
|
@@ -212,7 +197,7 @@ exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => {
|
|
|
212
197
|
const newLinks = []
|
|
213
198
|
for (let link of row[column]) {
|
|
214
199
|
const linkTblId = link.tableId || getRelatedTableForField(table, column)
|
|
215
|
-
const linkedTable = await getLinkedTable(
|
|
200
|
+
const linkedTable = await getLinkedTable(linkTblId, linkedTables)
|
|
216
201
|
const obj = { _id: link._id }
|
|
217
202
|
if (link[linkedTable.primaryDisplay]) {
|
|
218
203
|
obj.primaryDisplay = link[linkedTable.primaryDisplay]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const CouchDB = require("../index")
|
|
2
1
|
const Sentry = require("@sentry/node")
|
|
3
2
|
const { ViewNames, getQueryIndex } = require("../utils")
|
|
4
3
|
const { FieldTypes } = require("../../constants")
|
|
5
4
|
const { createLinkView } = require("../views/staticViews")
|
|
5
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Only needed so that boolean parameters are being used for includeDocs
|
|
@@ -17,7 +17,6 @@ exports.createLinkView = createLinkView
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Gets the linking documents, not the linked documents themselves.
|
|
20
|
-
* @param {string} args.appId The instance in which we are searching for linked rows.
|
|
21
20
|
* @param {string} args.tableId The table which we are searching for linked rows against.
|
|
22
21
|
* @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
|
|
23
22
|
* linking documents that are related to it. If this is not specified then the table level will be assumed.
|
|
@@ -30,8 +29,8 @@ exports.createLinkView = createLinkView
|
|
|
30
29
|
* (if any).
|
|
31
30
|
*/
|
|
32
31
|
exports.getLinkDocuments = async function (args) {
|
|
33
|
-
const {
|
|
34
|
-
const db =
|
|
32
|
+
const { tableId, rowId, includeDocs } = args
|
|
33
|
+
const db = getAppDB()
|
|
35
34
|
let params
|
|
36
35
|
if (rowId != null) {
|
|
37
36
|
params = { key: [tableId, rowId] }
|
|
@@ -68,7 +67,7 @@ exports.getLinkDocuments = async function (args) {
|
|
|
68
67
|
} catch (err) {
|
|
69
68
|
// check if the view doesn't exist, it should for all new instances
|
|
70
69
|
if (err != null && err.name === "not_found") {
|
|
71
|
-
await exports.createLinkView(
|
|
70
|
+
await exports.createLinkView()
|
|
72
71
|
return exports.getLinkDocuments(arguments[0])
|
|
73
72
|
} else {
|
|
74
73
|
/* istanbul ignore next */
|
|
@@ -89,7 +88,8 @@ exports.getLinkedTableIDs = table => {
|
|
|
89
88
|
.map(column => column.tableId)
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
exports.getLinkedTable = async (
|
|
91
|
+
exports.getLinkedTable = async (id, tables) => {
|
|
92
|
+
const db = getAppDB()
|
|
93
93
|
let linkedTable = tables.find(table => table._id === id)
|
|
94
94
|
if (linkedTable) {
|
|
95
95
|
return linkedTable
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const TestConfig = require("../../tests/utilities/TestConfiguration")
|
|
2
|
-
const { basicTable
|
|
2
|
+
const { basicTable } = require("../../tests/utilities/structures")
|
|
3
3
|
const linkUtils = require("../linkedRows/linkUtils")
|
|
4
|
-
const links = require("../linkedRows")
|
|
5
4
|
const CouchDB = require("../index")
|
|
5
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
6
6
|
|
|
7
7
|
describe("test link functionality", () => {
|
|
8
8
|
const config = new TestConfig(false)
|
|
@@ -11,18 +11,18 @@ describe("test link functionality", () => {
|
|
|
11
11
|
let db, table
|
|
12
12
|
beforeEach(async () => {
|
|
13
13
|
await config.init()
|
|
14
|
-
db =
|
|
14
|
+
db = getAppDB()
|
|
15
15
|
table = await config.createTable()
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
it("should be able to retrieve a linked table from a list", async () => {
|
|
19
|
-
const retrieved = await linkUtils.getLinkedTable(
|
|
19
|
+
const retrieved = await linkUtils.getLinkedTable(table._id, [table])
|
|
20
20
|
expect(retrieved._id).toBe(table._id)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
it("should be able to retrieve a table from DB and update list", async () => {
|
|
24
24
|
const tables = []
|
|
25
|
-
const retrieved = await linkUtils.getLinkedTable(
|
|
25
|
+
const retrieved = await linkUtils.getLinkedTable(table._id, tables)
|
|
26
26
|
expect(retrieved._id).toBe(table._id)
|
|
27
27
|
expect(tables[0]).toBeDefined()
|
|
28
28
|
})
|
|
@@ -51,7 +51,6 @@ describe("test link functionality", () => {
|
|
|
51
51
|
const db = new CouchDB("test")
|
|
52
52
|
await db.put({ _id: "_design/database", views: {} })
|
|
53
53
|
const output = await linkUtils.getLinkDocuments({
|
|
54
|
-
appId: "test",
|
|
55
54
|
tableId: "test",
|
|
56
55
|
rowId: "test",
|
|
57
56
|
includeDocs: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
2
2
|
const {
|
|
3
3
|
DocumentTypes,
|
|
4
4
|
SEPARATOR,
|
|
@@ -21,12 +21,11 @@ const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates the link view for the instance, this will overwrite the existing one, but this should only
|
|
23
23
|
* be called if it is found that the view does not exist.
|
|
24
|
-
* @param {string} appId The instance to which the view should be added.
|
|
25
24
|
* @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
|
|
26
25
|
* so it may be slow.
|
|
27
26
|
*/
|
|
28
|
-
exports.createLinkView = async
|
|
29
|
-
const db =
|
|
27
|
+
exports.createLinkView = async () => {
|
|
28
|
+
const db = getAppDB()
|
|
30
29
|
const designDoc = await db.get("_design/database")
|
|
31
30
|
const view = {
|
|
32
31
|
map: function (doc) {
|
|
@@ -57,8 +56,8 @@ exports.createLinkView = async appId => {
|
|
|
57
56
|
await db.put(designDoc)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
exports.createRoutingView = async
|
|
61
|
-
const db =
|
|
59
|
+
exports.createRoutingView = async () => {
|
|
60
|
+
const db = getAppDB()
|
|
62
61
|
const designDoc = await db.get("_design/database")
|
|
63
62
|
const view = {
|
|
64
63
|
// if using variables in a map function need to inject them before use
|
|
@@ -78,8 +77,8 @@ exports.createRoutingView = async appId => {
|
|
|
78
77
|
await db.put(designDoc)
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
async function searchIndex(
|
|
82
|
-
const db =
|
|
80
|
+
async function searchIndex(indexName, fnString) {
|
|
81
|
+
const db = getAppDB()
|
|
83
82
|
const designDoc = await db.get("_design/database")
|
|
84
83
|
designDoc.indexes = {
|
|
85
84
|
[indexName]: {
|
|
@@ -90,9 +89,8 @@ async function searchIndex(appId, indexName, fnString) {
|
|
|
90
89
|
await db.put(designDoc)
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
exports.createAllSearchIndex = async
|
|
92
|
+
exports.createAllSearchIndex = async () => {
|
|
94
93
|
await searchIndex(
|
|
95
|
-
appId,
|
|
96
94
|
SearchIndexes.ROWS,
|
|
97
95
|
function (doc) {
|
|
98
96
|
function idx(input, prev) {
|
|
@@ -17,6 +17,8 @@ export interface FieldSchema {
|
|
|
17
17
|
autocolumn?: boolean
|
|
18
18
|
throughFrom?: string
|
|
19
19
|
throughTo?: string
|
|
20
|
+
formula?: string
|
|
21
|
+
formulaType?: string
|
|
20
22
|
main?: boolean
|
|
21
23
|
meta?: {
|
|
22
24
|
toTable: string
|
|
@@ -46,6 +48,7 @@ export interface Table extends Base {
|
|
|
46
48
|
schema: TableSchema
|
|
47
49
|
primaryDisplay?: string
|
|
48
50
|
sourceId?: string
|
|
51
|
+
relatedFormula?: string[]
|
|
49
52
|
constrained?: string[]
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -47,6 +47,7 @@ export enum SourceNames {
|
|
|
47
47
|
ARANGODB = "ARANGODB",
|
|
48
48
|
REST = "REST",
|
|
49
49
|
ORACLE = "ORACLE",
|
|
50
|
+
GOOGLE_SHEETS = "GOOGLE_SHEETS",
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export enum IncludeRelationships {
|
|
@@ -86,6 +87,8 @@ export interface ExtraQueryConfig {
|
|
|
86
87
|
export interface Integration {
|
|
87
88
|
docs: string
|
|
88
89
|
plus?: boolean
|
|
90
|
+
auth?: { type: string }
|
|
91
|
+
relationships?: boolean
|
|
89
92
|
description: string
|
|
90
93
|
friendlyName: string
|
|
91
94
|
datasource: {}
|
package/src/environment.js
CHANGED
|
@@ -2,7 +2,8 @@ function isTest() {
|
|
|
2
2
|
return (
|
|
3
3
|
process.env.NODE_ENV === "jest" ||
|
|
4
4
|
process.env.NODE_ENV === "cypress" ||
|
|
5
|
-
process.env.JEST_WORKER_ID != null
|
|
5
|
+
(process.env.JEST_WORKER_ID != null &&
|
|
6
|
+
process.env.JEST_WORKER_ID !== "null")
|
|
6
7
|
)
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -38,10 +39,12 @@ module.exports = {
|
|
|
38
39
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
39
40
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
|
40
41
|
USE_QUOTAS: process.env.USE_QUOTAS,
|
|
42
|
+
EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
|
|
41
43
|
REDIS_URL: process.env.REDIS_URL,
|
|
42
44
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
43
45
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
|
44
46
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
47
|
+
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
|
45
48
|
// environment
|
|
46
49
|
NODE_ENV: process.env.NODE_ENV,
|
|
47
50
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
|
@@ -72,16 +72,22 @@ class InternalBuilder {
|
|
|
72
72
|
|
|
73
73
|
// right now we only do filters on the specific table being queried
|
|
74
74
|
addFilters(
|
|
75
|
-
tableName: string,
|
|
76
75
|
query: KnexQuery,
|
|
77
|
-
filters: SearchFilters | undefined
|
|
76
|
+
filters: SearchFilters | undefined,
|
|
77
|
+
opts: { relationship?: boolean; tableName?: string }
|
|
78
78
|
): KnexQuery {
|
|
79
79
|
function iterate(
|
|
80
80
|
structure: { [key: string]: any },
|
|
81
81
|
fn: (key: string, value: any) => void
|
|
82
82
|
) {
|
|
83
83
|
for (let [key, value] of Object.entries(structure)) {
|
|
84
|
-
|
|
84
|
+
const isRelationshipField = key.includes(".")
|
|
85
|
+
if (!opts.relationship && !isRelationshipField) {
|
|
86
|
+
fn(`${opts.tableName}.${key}`, value)
|
|
87
|
+
}
|
|
88
|
+
if (opts.relationship && isRelationshipField) {
|
|
89
|
+
fn(key, value)
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
if (!filters) {
|
|
@@ -185,29 +191,70 @@ class InternalBuilder {
|
|
|
185
191
|
if (!relationships) {
|
|
186
192
|
return query
|
|
187
193
|
}
|
|
194
|
+
const tableSets: Record<string, [any]> = {}
|
|
195
|
+
// aggregate into table sets (all the same to tables)
|
|
188
196
|
for (let relationship of relationships) {
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
const keyObj: { toTable: string; throughTable: string | undefined } = {
|
|
198
|
+
toTable: relationship.tableName,
|
|
199
|
+
throughTable: undefined,
|
|
200
|
+
}
|
|
201
|
+
if (relationship.through) {
|
|
202
|
+
keyObj.throughTable = relationship.through
|
|
203
|
+
}
|
|
204
|
+
const key = JSON.stringify(keyObj)
|
|
205
|
+
if (tableSets[key]) {
|
|
206
|
+
tableSets[key].push(relationship)
|
|
207
|
+
} else {
|
|
208
|
+
tableSets[key] = [relationship]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (let [key, relationships] of Object.entries(tableSets)) {
|
|
212
|
+
const { toTable, throughTable } = JSON.parse(key)
|
|
213
|
+
if (!throughTable) {
|
|
193
214
|
// @ts-ignore
|
|
194
|
-
query = query.
|
|
215
|
+
query = query.join(
|
|
195
216
|
toTable,
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
function () {
|
|
218
|
+
for (let relationship of relationships) {
|
|
219
|
+
const from = relationship.from,
|
|
220
|
+
to = relationship.to
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"left"
|
|
198
226
|
)
|
|
199
227
|
} else {
|
|
200
|
-
const throughTable = relationship.through
|
|
201
|
-
const fromPrimary = relationship.fromPrimary
|
|
202
|
-
const toPrimary = relationship.toPrimary
|
|
203
228
|
query = query
|
|
204
229
|
// @ts-ignore
|
|
205
|
-
.
|
|
230
|
+
.join(
|
|
206
231
|
throughTable,
|
|
207
|
-
|
|
208
|
-
|
|
232
|
+
function () {
|
|
233
|
+
for (let relationship of relationships) {
|
|
234
|
+
const fromPrimary = relationship.fromPrimary
|
|
235
|
+
const from = relationship.from
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
this.orOn(
|
|
238
|
+
`${fromTable}.${fromPrimary}`,
|
|
239
|
+
"=",
|
|
240
|
+
`${throughTable}.${from}`
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"left"
|
|
245
|
+
)
|
|
246
|
+
.join(
|
|
247
|
+
toTable,
|
|
248
|
+
function () {
|
|
249
|
+
for (let relationship of relationships) {
|
|
250
|
+
const toPrimary = relationship.toPrimary
|
|
251
|
+
const to = relationship.to
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
this.orOn(`${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
"left"
|
|
209
257
|
)
|
|
210
|
-
.leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
|
211
258
|
}
|
|
212
259
|
}
|
|
213
260
|
return query.limit(BASE_LIMIT)
|
|
@@ -272,7 +319,7 @@ class InternalBuilder {
|
|
|
272
319
|
if (foundOffset) {
|
|
273
320
|
query = query.offset(foundOffset)
|
|
274
321
|
}
|
|
275
|
-
query = this.addFilters(
|
|
322
|
+
query = this.addFilters(query, filters, { tableName })
|
|
276
323
|
// add sorting to pre-query
|
|
277
324
|
query = this.addSorting(query, json)
|
|
278
325
|
// @ts-ignore
|
|
@@ -285,20 +332,21 @@ class InternalBuilder {
|
|
|
285
332
|
preQuery = this.addSorting(preQuery, json)
|
|
286
333
|
}
|
|
287
334
|
// handle joins
|
|
288
|
-
|
|
335
|
+
query = this.addRelationships(
|
|
289
336
|
knex,
|
|
290
337
|
preQuery,
|
|
291
338
|
selectStatement,
|
|
292
339
|
tableName,
|
|
293
340
|
relationships
|
|
294
341
|
)
|
|
342
|
+
return this.addFilters(query, filters, { relationship: true })
|
|
295
343
|
}
|
|
296
344
|
|
|
297
345
|
update(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
298
346
|
const { endpoint, body, filters } = json
|
|
299
347
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
300
348
|
const parsedBody = parseBody(body)
|
|
301
|
-
query = this.addFilters(endpoint.entityId
|
|
349
|
+
query = this.addFilters(query, filters, { tableName: endpoint.entityId })
|
|
302
350
|
// mysql can't use returning
|
|
303
351
|
if (opts.disableReturning) {
|
|
304
352
|
return query.update(parsedBody)
|
|
@@ -310,7 +358,7 @@ class InternalBuilder {
|
|
|
310
358
|
delete(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
311
359
|
const { endpoint, filters } = json
|
|
312
360
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
313
|
-
query = this.addFilters(endpoint.entityId
|
|
361
|
+
query = this.addFilters(query, filters, { tableName: endpoint.entityId })
|
|
314
362
|
// mysql can't use returning
|
|
315
363
|
if (opts.disableReturning) {
|
|
316
364
|
return query.delete()
|