@budibase/server 1.0.49-alpha.9 → 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.ad5370ae.js → index.2c37968e.js} +246 -249
- 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 +2827 -3117
- 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 +141 -48
- package/coverage/lcov-report/api/controllers/row/index.html +40 -55
- 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 +24 -39
- 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 +4431 -5013
- 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 +67 -90
- package/dist/api/controllers/row/external.js +22 -14
- 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 +14 -56
- 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 +11 -15
- 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/integrations/postgres/init.sql +6 -11
- 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 +43 -67
- package/src/api/controllers/row/external.js +58 -27
- 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 +21 -69
- 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 +12 -17
- 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/tsconfig.json +1 -2
- 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 -29
- 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 -18
- 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/module.d.ts +0 -3
- 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
|
@@ -22,21 +22,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
const datasource_1 = require("../../../definitions/datasource");
|
|
24
24
|
const utils_1 = require("../../../integrations/utils");
|
|
25
|
-
const utils_2 = require("./utils");
|
|
26
|
-
const constants_1 = require("../../../constants");
|
|
27
|
-
const utils_3 = require("../../../integrations/utils");
|
|
28
|
-
const string_templates_1 = require("@budibase/string-templates");
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
const fp_1 = require("lodash/fp");
|
|
31
|
-
const utils_4 = require("../../../utilities/rowProcessor/utils");
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
const context_1 = require("@budibase/backend-core/context");
|
|
34
25
|
var External;
|
|
35
26
|
(function (External) {
|
|
27
|
+
const { getDatasourceAndQuery } = require("./utils");
|
|
28
|
+
const { DataSourceOperation, FieldTypes, RelationshipTypes, } = require("../../../constants");
|
|
29
|
+
const { breakExternalTableId, isSQL } = require("../../../integrations/utils");
|
|
30
|
+
const { processObjectSync } = require("@budibase/string-templates");
|
|
31
|
+
const { cloneDeep } = require("lodash/fp");
|
|
32
|
+
const CouchDB = require("../../../db");
|
|
33
|
+
const { processFormulas } = require("../../../utilities/rowProcessor/utils");
|
|
36
34
|
function buildFilters(id, filters, table) {
|
|
37
35
|
const primary = table.primary;
|
|
38
36
|
// if passed in array need to copy for shifting etc
|
|
39
|
-
let idCopy =
|
|
37
|
+
let idCopy = cloneDeep(id);
|
|
40
38
|
if (filters) {
|
|
41
39
|
// need to map over the filters and make sure the _id field isn't present
|
|
42
40
|
for (let filter of Object.values(filters)) {
|
|
@@ -79,10 +77,10 @@ var External;
|
|
|
79
77
|
*/
|
|
80
78
|
function cleanupConfig(config, table) {
|
|
81
79
|
const primaryOptions = [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
FieldTypes.STRING,
|
|
81
|
+
FieldTypes.LONGFORM,
|
|
82
|
+
FieldTypes.OPTIONS,
|
|
83
|
+
FieldTypes.NUMBER,
|
|
86
84
|
];
|
|
87
85
|
// filter out fields which cannot be keys
|
|
88
86
|
const fieldNames = Object.entries(table.schema)
|
|
@@ -135,7 +133,7 @@ var External;
|
|
|
135
133
|
if (!tableId) {
|
|
136
134
|
return {};
|
|
137
135
|
}
|
|
138
|
-
const { datasourceId, tableName } =
|
|
136
|
+
const { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
139
137
|
return {
|
|
140
138
|
datasourceId,
|
|
141
139
|
entityId: tableName,
|
|
@@ -155,11 +153,11 @@ var External;
|
|
|
155
153
|
thisRow._id = generateIdForRow(row, table);
|
|
156
154
|
thisRow.tableId = table._id;
|
|
157
155
|
thisRow._rev = "rev";
|
|
158
|
-
return
|
|
156
|
+
return thisRow;
|
|
159
157
|
}
|
|
160
158
|
function fixArrayTypes(row, table) {
|
|
161
159
|
for (let [fieldName, schema] of Object.entries(table.schema)) {
|
|
162
|
-
if (schema.type ===
|
|
160
|
+
if (schema.type === FieldTypes.ARRAY &&
|
|
163
161
|
typeof row[fieldName] === "string") {
|
|
164
162
|
try {
|
|
165
163
|
row[fieldName] = JSON.parse(row[fieldName]);
|
|
@@ -176,8 +174,9 @@ var External;
|
|
|
176
174
|
return (field.relationshipType && field.relationshipType.split("-")[0] === "one");
|
|
177
175
|
}
|
|
178
176
|
class ExternalRequest {
|
|
179
|
-
constructor(operation, tableId, datasource) {
|
|
177
|
+
constructor(appId, operation, tableId, datasource) {
|
|
180
178
|
this.tables = {};
|
|
179
|
+
this.appId = appId;
|
|
181
180
|
this.operation = operation;
|
|
182
181
|
this.tableId = tableId;
|
|
183
182
|
this.datasource = datasource;
|
|
@@ -189,10 +188,8 @@ var External;
|
|
|
189
188
|
if (!tableId) {
|
|
190
189
|
throw "Table ID is unknown, cannot find table";
|
|
191
190
|
}
|
|
192
|
-
const { tableName } =
|
|
193
|
-
|
|
194
|
-
return this.tables[tableName];
|
|
195
|
-
}
|
|
191
|
+
const { tableName } = breakExternalTableId(tableId);
|
|
192
|
+
return this.tables[tableName];
|
|
196
193
|
}
|
|
197
194
|
inputProcessing(row, table) {
|
|
198
195
|
if (!row) {
|
|
@@ -207,7 +204,7 @@ var External;
|
|
|
207
204
|
if (row[key] == null ||
|
|
208
205
|
newRow[key] ||
|
|
209
206
|
field.autocolumn ||
|
|
210
|
-
field.type ===
|
|
207
|
+
field.type === FieldTypes.FORMULA) {
|
|
211
208
|
continue;
|
|
212
209
|
}
|
|
213
210
|
// if its an empty string then it means return the column to null (if possible)
|
|
@@ -216,17 +213,17 @@ var External;
|
|
|
216
213
|
continue;
|
|
217
214
|
}
|
|
218
215
|
// parse floats/numbers
|
|
219
|
-
if (field.type ===
|
|
216
|
+
if (field.type === FieldTypes.NUMBER && !isNaN(parseFloat(row[key]))) {
|
|
220
217
|
newRow[key] = parseFloat(row[key]);
|
|
221
218
|
}
|
|
222
219
|
// if its not a link then just copy it over
|
|
223
|
-
if (field.type !==
|
|
220
|
+
if (field.type !== FieldTypes.LINK) {
|
|
224
221
|
newRow[key] = row[key];
|
|
225
222
|
continue;
|
|
226
223
|
}
|
|
227
|
-
const { tableName: linkTableName } =
|
|
224
|
+
const { tableName: linkTableName } = breakExternalTableId(field.tableId);
|
|
228
225
|
// table has to exist for many to many
|
|
229
|
-
if (!
|
|
226
|
+
if (!this.tables[linkTableName]) {
|
|
230
227
|
continue;
|
|
231
228
|
}
|
|
232
229
|
const linkTable = this.tables[linkTableName];
|
|
@@ -278,24 +275,14 @@ var External;
|
|
|
278
275
|
* This iterates through the returned rows and works out what elements of the rows
|
|
279
276
|
* actually match up to another row (based on primary keys) - this is pretty specific
|
|
280
277
|
* to SQL and the way that SQL relationships are returned based on joins.
|
|
281
|
-
* This is complicated, but the idea is that when a SQL query returns all the relations
|
|
282
|
-
* will be separate rows, with all of the data in each row. We have to decipher what comes
|
|
283
|
-
* from where (which tables) and how to convert that into budibase columns.
|
|
284
278
|
*/
|
|
285
|
-
updateRelationshipColumns(
|
|
279
|
+
updateRelationshipColumns(row, rows, relationships) {
|
|
286
280
|
const columns = {};
|
|
287
281
|
for (let relationship of relationships) {
|
|
288
282
|
const linkedTable = this.tables[relationship.tableName];
|
|
289
283
|
if (!linkedTable) {
|
|
290
284
|
continue;
|
|
291
285
|
}
|
|
292
|
-
const fromColumn = `${table.name}.${relationship.from}`;
|
|
293
|
-
const toColumn = `${linkedTable.name}.${relationship.to}`;
|
|
294
|
-
// this is important when working with multiple relationships
|
|
295
|
-
// between the same tables, don't want to overlap/multiply the relations
|
|
296
|
-
if (!relationship.through && row[fromColumn] !== row[toColumn]) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
286
|
let linked = basicProcessing(row, linkedTable);
|
|
300
287
|
if (!linked._id) {
|
|
301
288
|
continue;
|
|
@@ -333,7 +320,7 @@ var External;
|
|
|
333
320
|
row._id = rowId;
|
|
334
321
|
// this is a relationship of some sort
|
|
335
322
|
if (finalRows[rowId]) {
|
|
336
|
-
finalRows = this.updateRelationshipColumns(
|
|
323
|
+
finalRows = this.updateRelationshipColumns(row, finalRows, relationships);
|
|
337
324
|
continue;
|
|
338
325
|
}
|
|
339
326
|
const thisRow = fixArrayTypes(basicProcessing(row, table), table);
|
|
@@ -342,9 +329,9 @@ var External;
|
|
|
342
329
|
}
|
|
343
330
|
finalRows[thisRow._id] = thisRow;
|
|
344
331
|
// do this at end once its been added to the final rows
|
|
345
|
-
finalRows = this.updateRelationshipColumns(
|
|
332
|
+
finalRows = this.updateRelationshipColumns(row, finalRows, relationships);
|
|
346
333
|
}
|
|
347
|
-
return
|
|
334
|
+
return processFormulas(table, Object.values(finalRows));
|
|
348
335
|
}
|
|
349
336
|
/**
|
|
350
337
|
* Gets the list of relationship JSON structures based on the columns in the table,
|
|
@@ -354,12 +341,12 @@ var External;
|
|
|
354
341
|
buildRelationships(table) {
|
|
355
342
|
const relationships = [];
|
|
356
343
|
for (let [fieldName, field] of Object.entries(table.schema)) {
|
|
357
|
-
if (field.type !==
|
|
344
|
+
if (field.type !== FieldTypes.LINK) {
|
|
358
345
|
continue;
|
|
359
346
|
}
|
|
360
|
-
const { tableName: linkTableName } =
|
|
347
|
+
const { tableName: linkTableName } = breakExternalTableId(field.tableId);
|
|
361
348
|
// no table to link to, this is not a valid relationships
|
|
362
|
-
if (!
|
|
349
|
+
if (!this.tables[linkTableName]) {
|
|
363
350
|
continue;
|
|
364
351
|
}
|
|
365
352
|
const linkTable = this.tables[linkTableName];
|
|
@@ -375,7 +362,7 @@ var External;
|
|
|
375
362
|
column: fieldName,
|
|
376
363
|
};
|
|
377
364
|
if (field.through) {
|
|
378
|
-
const { tableName: throughTableName } =
|
|
365
|
+
const { tableName: throughTableName } = breakExternalTableId(field.through);
|
|
379
366
|
definition.through = throughTableName;
|
|
380
367
|
// don't support composite keys for relationships
|
|
381
368
|
definition.from = field.throughTo || table.primary[0];
|
|
@@ -394,24 +381,21 @@ var External;
|
|
|
394
381
|
lookupRelations(tableId, row) {
|
|
395
382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
383
|
const related = {};
|
|
397
|
-
const { tableName } =
|
|
398
|
-
if (!tableName) {
|
|
399
|
-
return related;
|
|
400
|
-
}
|
|
384
|
+
const { tableName } = breakExternalTableId(tableId);
|
|
401
385
|
const table = this.tables[tableName];
|
|
402
386
|
// @ts-ignore
|
|
403
387
|
const primaryKey = table.primary[0];
|
|
404
388
|
// make a new request to get the row with all its relationships
|
|
405
389
|
// we need this to work out if any relationships need removed
|
|
406
390
|
for (let field of Object.values(table.schema)) {
|
|
407
|
-
if (field.type !==
|
|
391
|
+
if (field.type !== FieldTypes.LINK ||
|
|
408
392
|
!field.fieldName ||
|
|
409
393
|
isOneSide(field)) {
|
|
410
394
|
continue;
|
|
411
395
|
}
|
|
412
|
-
const isMany = field.relationshipType ===
|
|
396
|
+
const isMany = field.relationshipType === RelationshipTypes.MANY_TO_MANY;
|
|
413
397
|
const tableId = isMany ? field.through : field.tableId;
|
|
414
|
-
const { tableName: relatedTableName } =
|
|
398
|
+
const { tableName: relatedTableName } = breakExternalTableId(tableId);
|
|
415
399
|
// @ts-ignore
|
|
416
400
|
const linkPrimaryKey = this.tables[relatedTableName].primary[0];
|
|
417
401
|
const manyKey = field.throughTo || primaryKey;
|
|
@@ -420,8 +404,8 @@ var External;
|
|
|
420
404
|
if (!lookupField || !row[lookupField]) {
|
|
421
405
|
continue;
|
|
422
406
|
}
|
|
423
|
-
const response = yield
|
|
424
|
-
endpoint: getEndpoint(tableId,
|
|
407
|
+
const response = yield getDatasourceAndQuery(this.appId, {
|
|
408
|
+
endpoint: getEndpoint(tableId, DataSourceOperation.READ),
|
|
425
409
|
filters: {
|
|
426
410
|
equal: {
|
|
427
411
|
[fieldName]: row[lookupField],
|
|
@@ -447,27 +431,26 @@ var External;
|
|
|
447
431
|
* all and then re-create, as theres no chance of losing data (e.g. delete succeed, but write fail).
|
|
448
432
|
*/
|
|
449
433
|
handleManyRelationships(mainTableId, row, relationships) {
|
|
434
|
+
var _a;
|
|
450
435
|
return __awaiter(this, void 0, void 0, function* () {
|
|
436
|
+
const { appId } = this;
|
|
451
437
|
// if we're creating (in a through table) need to wipe the existing ones first
|
|
452
438
|
const promises = [];
|
|
453
439
|
const related = yield this.lookupRelations(mainTableId, row);
|
|
454
440
|
for (let relationship of relationships) {
|
|
455
441
|
const { key, tableId, isUpdate, id } = relationship, rest = __rest(relationship, ["key", "tableId", "isUpdate", "id"]);
|
|
456
|
-
const body =
|
|
442
|
+
const body = processObjectSync(rest, row);
|
|
457
443
|
const linkTable = this.getTable(tableId);
|
|
458
444
|
// @ts-ignore
|
|
459
|
-
const linkPrimary = linkTable
|
|
460
|
-
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
const rows = related[key].rows || [];
|
|
445
|
+
const linkPrimary = linkTable.primary[0];
|
|
446
|
+
const rows = ((_a = related[key]) === null || _a === void 0 ? void 0 : _a.rows) || [];
|
|
464
447
|
const found = rows.find((row) => row[linkPrimary] === relationship.id ||
|
|
465
|
-
row[linkPrimary] ===
|
|
448
|
+
row[linkPrimary] === body[linkPrimary]);
|
|
466
449
|
const operation = isUpdate
|
|
467
|
-
?
|
|
468
|
-
:
|
|
450
|
+
? DataSourceOperation.UPDATE
|
|
451
|
+
: DataSourceOperation.CREATE;
|
|
469
452
|
if (!found) {
|
|
470
|
-
promises.push(
|
|
453
|
+
promises.push(getDatasourceAndQuery(appId, {
|
|
471
454
|
endpoint: getEndpoint(tableId, operation),
|
|
472
455
|
// if we're doing many relationships then we're writing, only one response
|
|
473
456
|
body,
|
|
@@ -483,8 +466,7 @@ var External;
|
|
|
483
466
|
for (let [colName, { isMany, rows, tableId }] of Object.entries(related)) {
|
|
484
467
|
const table = this.getTable(tableId);
|
|
485
468
|
// if its not the foreign key skip it, nothing to do
|
|
486
|
-
if (
|
|
487
|
-
(table.primary && table.primary.indexOf(colName) !== -1)) {
|
|
469
|
+
if (table.primary && table.primary.indexOf(colName) !== -1) {
|
|
488
470
|
continue;
|
|
489
471
|
}
|
|
490
472
|
for (let row of rows) {
|
|
@@ -492,10 +474,10 @@ var External;
|
|
|
492
474
|
// safety check, if there are no filters on deletion bad things happen
|
|
493
475
|
if (Object.keys(filters).length !== 0) {
|
|
494
476
|
const op = isMany
|
|
495
|
-
?
|
|
496
|
-
:
|
|
477
|
+
? DataSourceOperation.DELETE
|
|
478
|
+
: DataSourceOperation.UPDATE;
|
|
497
479
|
const body = isMany ? null : { [colName]: null };
|
|
498
|
-
promises.push(
|
|
480
|
+
promises.push(getDatasourceAndQuery(this.appId, {
|
|
499
481
|
endpoint: getEndpoint(tableId, op),
|
|
500
482
|
body,
|
|
501
483
|
filters,
|
|
@@ -516,36 +498,31 @@ var External;
|
|
|
516
498
|
buildFields(table, includeRelations = datasource_1.IncludeRelationships.INCLUDE) {
|
|
517
499
|
function extractRealFields(table, existing = []) {
|
|
518
500
|
return Object.entries(table.schema)
|
|
519
|
-
.filter(column => column[1].type !==
|
|
520
|
-
column[1].type !==
|
|
501
|
+
.filter(column => column[1].type !== FieldTypes.LINK &&
|
|
502
|
+
column[1].type !== FieldTypes.FORMULA &&
|
|
521
503
|
!existing.find((field) => field === column[0]))
|
|
522
504
|
.map(column => `${table.name}.${column[0]}`);
|
|
523
505
|
}
|
|
524
506
|
let fields = extractRealFields(table);
|
|
525
507
|
for (let field of Object.values(table.schema)) {
|
|
526
|
-
if (field.type !==
|
|
508
|
+
if (field.type !== FieldTypes.LINK || !includeRelations) {
|
|
527
509
|
continue;
|
|
528
510
|
}
|
|
529
|
-
const { tableName: linkTableName } =
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
fields = fields.concat(linkedFields);
|
|
535
|
-
}
|
|
511
|
+
const { tableName: linkTableName } = breakExternalTableId(field.tableId);
|
|
512
|
+
const linkTable = this.tables[linkTableName];
|
|
513
|
+
if (linkTable) {
|
|
514
|
+
const linkedFields = extractRealFields(linkTable, fields);
|
|
515
|
+
fields = fields.concat(linkedFields);
|
|
536
516
|
}
|
|
537
517
|
}
|
|
538
518
|
return fields;
|
|
539
519
|
}
|
|
540
520
|
run(config) {
|
|
541
521
|
return __awaiter(this, void 0, void 0, function* () {
|
|
542
|
-
const { operation, tableId } = this;
|
|
543
|
-
let { datasourceId, tableName } =
|
|
544
|
-
if (!tableName) {
|
|
545
|
-
throw "Unable to run without a table name";
|
|
546
|
-
}
|
|
522
|
+
const { appId, operation, tableId } = this;
|
|
523
|
+
let { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
547
524
|
if (!this.datasource) {
|
|
548
|
-
const db =
|
|
525
|
+
const db = new CouchDB(appId);
|
|
549
526
|
this.datasource = yield db.get(datasourceId);
|
|
550
527
|
if (!this.datasource || !this.datasource.entities) {
|
|
551
528
|
throw "No tables found, fetch tables before query.";
|
|
@@ -553,7 +530,7 @@ var External;
|
|
|
553
530
|
this.tables = this.datasource.entities;
|
|
554
531
|
}
|
|
555
532
|
const table = this.tables[tableName];
|
|
556
|
-
let isSql =
|
|
533
|
+
let isSql = isSQL(this.datasource);
|
|
557
534
|
if (!table) {
|
|
558
535
|
throw `Unable to process query, table "${tableName}" not defined.`;
|
|
559
536
|
}
|
|
@@ -564,7 +541,7 @@ var External;
|
|
|
564
541
|
// clean up row on ingress using schema
|
|
565
542
|
const processed = this.inputProcessing(row, table);
|
|
566
543
|
row = processed.row;
|
|
567
|
-
if (operation ===
|
|
544
|
+
if (operation === DataSourceOperation.DELETE &&
|
|
568
545
|
(filters == null || Object.keys(filters).length === 0)) {
|
|
569
546
|
throw "Deletion must be filtered";
|
|
570
547
|
}
|
|
@@ -592,15 +569,15 @@ var External;
|
|
|
592
569
|
},
|
|
593
570
|
};
|
|
594
571
|
// can't really use response right now
|
|
595
|
-
const response = yield
|
|
572
|
+
const response = yield getDatasourceAndQuery(appId, json);
|
|
596
573
|
// handle many to many relationships now if we know the ID (could be auto increment)
|
|
597
|
-
if (operation !==
|
|
574
|
+
if (operation !== DataSourceOperation.READ &&
|
|
598
575
|
processed.manyRelationships) {
|
|
599
576
|
yield this.handleManyRelationships(table._id || "", response[0], processed.manyRelationships);
|
|
600
577
|
}
|
|
601
578
|
const output = this.outputProcessing(response, table, relationships);
|
|
602
579
|
// if reading it'll just be an array of rows, return whole thing
|
|
603
|
-
return operation ===
|
|
580
|
+
return operation === DataSourceOperation.READ && Array.isArray(response)
|
|
604
581
|
? output
|
|
605
582
|
: { row: output[0], table };
|
|
606
583
|
});
|
|
@@ -22,8 +22,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
const { DataSourceOperation, SortDirection, FieldTypes, NoEmptyFilterStrings, } = require("../../../constants");
|
|
23
23
|
const { breakExternalTableId, breakRowIdField, } = require("../../../integrations/utils");
|
|
24
24
|
const ExternalRequest = require("./ExternalRequest");
|
|
25
|
-
const
|
|
26
|
-
function handleRequest(operation, tableId, opts = {}) {
|
|
25
|
+
const CouchDB = require("../../../db");
|
|
26
|
+
function handleRequest(appId, operation, tableId, opts = {}) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
|
|
29
29
|
if (opts && opts.filters) {
|
|
@@ -38,25 +38,27 @@ function handleRequest(operation, tableId, opts = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
return new ExternalRequest(operation, tableId, opts.datasource).run(opts);
|
|
41
|
+
return new ExternalRequest(appId, operation, tableId, opts.datasource).run(opts);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
exports.handleRequest = handleRequest;
|
|
45
45
|
exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const appId = ctx.appId;
|
|
46
47
|
const inputs = ctx.request.body;
|
|
47
48
|
const tableId = ctx.params.tableId;
|
|
48
49
|
const id = breakRowIdField(inputs._id);
|
|
49
50
|
// don't save the ID to db
|
|
50
51
|
delete inputs._id;
|
|
51
|
-
return handleRequest(DataSourceOperation.UPDATE, tableId, {
|
|
52
|
+
return handleRequest(appId, DataSourceOperation.UPDATE, tableId, {
|
|
52
53
|
id,
|
|
53
54
|
row: inputs,
|
|
54
55
|
});
|
|
55
56
|
});
|
|
56
57
|
exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const appId = ctx.appId;
|
|
57
59
|
const inputs = ctx.request.body;
|
|
58
60
|
const tableId = ctx.params.tableId;
|
|
59
|
-
return handleRequest(DataSourceOperation.CREATE, tableId, {
|
|
61
|
+
return handleRequest(appId, DataSourceOperation.CREATE, tableId, {
|
|
60
62
|
row: inputs,
|
|
61
63
|
});
|
|
62
64
|
});
|
|
@@ -68,31 +70,35 @@ exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
68
70
|
return exports.fetch(ctx);
|
|
69
71
|
});
|
|
70
72
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const appId = ctx.appId;
|
|
71
74
|
const tableId = ctx.params.tableId;
|
|
72
|
-
return handleRequest(DataSourceOperation.READ, tableId);
|
|
75
|
+
return handleRequest(appId, DataSourceOperation.READ, tableId);
|
|
73
76
|
});
|
|
74
77
|
exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const appId = ctx.appId;
|
|
75
79
|
const id = ctx.params.rowId;
|
|
76
80
|
const tableId = ctx.params.tableId;
|
|
77
|
-
const response = yield handleRequest(DataSourceOperation.READ, tableId, {
|
|
81
|
+
const response = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
|
|
78
82
|
id,
|
|
79
83
|
});
|
|
80
84
|
return response ? response[0] : response;
|
|
81
85
|
});
|
|
82
86
|
exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const appId = ctx.appId;
|
|
83
88
|
const tableId = ctx.params.tableId;
|
|
84
89
|
const id = ctx.request.body._id;
|
|
85
|
-
const { row } = yield handleRequest(DataSourceOperation.DELETE, tableId, {
|
|
90
|
+
const { row } = yield handleRequest(appId, DataSourceOperation.DELETE, tableId, {
|
|
86
91
|
id,
|
|
87
92
|
});
|
|
88
93
|
return { response: { ok: true }, row };
|
|
89
94
|
});
|
|
90
95
|
exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
const appId = ctx.appId;
|
|
91
97
|
const { rows } = ctx.request.body;
|
|
92
98
|
const tableId = ctx.params.tableId;
|
|
93
99
|
let promises = [];
|
|
94
100
|
for (let row of rows) {
|
|
95
|
-
promises.push(handleRequest(DataSourceOperation.DELETE, tableId, {
|
|
101
|
+
promises.push(handleRequest(appId, DataSourceOperation.DELETE, tableId, {
|
|
96
102
|
id: breakRowIdField(row._id),
|
|
97
103
|
}));
|
|
98
104
|
}
|
|
@@ -100,6 +106,7 @@ exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
100
106
|
return { response: { ok: true }, rows: responses.map(resp => resp.row) };
|
|
101
107
|
});
|
|
102
108
|
exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const appId = ctx.appId;
|
|
103
110
|
const tableId = ctx.params.tableId;
|
|
104
111
|
const _a = ctx.request.body, { paginate, query } = _a, params = __rest(_a, ["paginate", "query"]);
|
|
105
112
|
let { bookmark, limit } = params;
|
|
@@ -128,14 +135,14 @@ exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
128
135
|
[params.sort]: direction,
|
|
129
136
|
};
|
|
130
137
|
}
|
|
131
|
-
const rows = yield handleRequest(DataSourceOperation.READ, tableId, {
|
|
138
|
+
const rows = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
|
|
132
139
|
filters: query,
|
|
133
140
|
sort,
|
|
134
141
|
paginate: paginateObj,
|
|
135
142
|
});
|
|
136
143
|
let hasNextPage = false;
|
|
137
144
|
if (paginate && rows.length === limit) {
|
|
138
|
-
const nextRows = yield handleRequest(DataSourceOperation.READ, tableId, {
|
|
145
|
+
const nextRows = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
|
|
139
146
|
filters: query,
|
|
140
147
|
sort,
|
|
141
148
|
paginate: {
|
|
@@ -153,16 +160,17 @@ exports.validate = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
153
160
|
return { valid: true };
|
|
154
161
|
});
|
|
155
162
|
exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
const appId = ctx.appId;
|
|
156
164
|
const id = ctx.params.rowId;
|
|
157
165
|
const tableId = ctx.params.tableId;
|
|
158
166
|
const { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
159
|
-
const db =
|
|
167
|
+
const db = new CouchDB(appId);
|
|
160
168
|
const datasource = yield db.get(datasourceId);
|
|
161
169
|
if (!datasource || !datasource.entities) {
|
|
162
170
|
ctx.throw(400, "Datasource has not been configured for plus API.");
|
|
163
171
|
}
|
|
164
172
|
const tables = datasource.entities;
|
|
165
|
-
const response = yield handleRequest(DataSourceOperation.READ, tableId, {
|
|
173
|
+
const response = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
|
|
166
174
|
id,
|
|
167
175
|
datasource,
|
|
168
176
|
});
|
|
@@ -181,7 +189,7 @@ exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function*
|
|
|
181
189
|
const linkedTable = tables[breakExternalTableId(linkedTableId).tableName];
|
|
182
190
|
// don't support composite keys right now
|
|
183
191
|
const linkedIds = links.map(link => breakRowIdField(link._id)[0]);
|
|
184
|
-
row[fieldName] = yield handleRequest(DataSourceOperation.READ, linkedTableId, {
|
|
192
|
+
row[fieldName] = yield handleRequest(appId, DataSourceOperation.READ, linkedTableId, {
|
|
185
193
|
tables,
|
|
186
194
|
filters: {
|
|
187
195
|
oneOf: {
|