@budibase/server 1.0.123-alpha.0 → 1.0.123
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/builder/assets/index.68a7f4e3.css +6 -0
- package/builder/assets/index.8d4a5b33.js +1291 -0
- package/builder/assets/{vendor.5240f480.js → vendor.8e34a169.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1763 -758
- package/coverage/coverage-final.json +43 -28
- package/coverage/lcov-report/api/controllers/analytics.js.html +3 -8
- package/coverage/lcov-report/api/controllers/apikeys.js.html +4 -9
- package/coverage/lcov-report/api/controllers/application.js.html +1436 -0
- package/coverage/lcov-report/api/controllers/auth.js.html +3 -8
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -8
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -8
- package/coverage/lcov-report/api/controllers/cloud.js.html +3 -8
- package/coverage/lcov-report/api/controllers/component.js.html +3 -8
- package/coverage/lcov-report/api/controllers/datasource.js.html +6 -11
- package/coverage/lcov-report/api/controllers/dev.js.html +3 -8
- package/coverage/lcov-report/api/controllers/index.html +26 -16
- package/coverage/lcov-report/api/controllers/integration.js.html +3 -8
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -8
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -8
- package/coverage/lcov-report/api/controllers/migrations.js.html +3 -8
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -8
- package/coverage/lcov-report/api/controllers/query/index.html +26 -16
- package/coverage/lcov-report/api/controllers/query/index.js.html +713 -0
- package/coverage/lcov-report/api/controllers/query/validation.js.html +3 -8
- package/coverage/lcov-report/api/controllers/role.js.html +5 -10
- package/coverage/lcov-report/api/controllers/routing.js.html +4 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +3 -8
- package/coverage/lcov-report/api/controllers/row/index.html +35 -25
- package/coverage/lcov-report/api/controllers/row/index.js.html +524 -0
- package/coverage/lcov-report/api/controllers/row/internal.js.html +24 -32
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +16 -21
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +19 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +19 -33
- package/coverage/lcov-report/api/controllers/screen.js.html +4 -9
- package/coverage/lcov-report/api/controllers/script.js.html +3 -8
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +50 -55
- package/coverage/lcov-report/api/controllers/table/external.js.html +3 -8
- package/coverage/lcov-report/api/controllers/table/index.html +44 -19
- package/coverage/lcov-report/api/controllers/table/index.js.html +15 -20
- package/coverage/lcov-report/api/controllers/table/internal.js.html +620 -0
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1331 -0
- package/coverage/lcov-report/api/controllers/templates.js.html +3 -8
- package/coverage/lcov-report/api/controllers/user.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/index.html +3 -8
- package/coverage/lcov-report/api/controllers/view/index.js.html +5 -10
- package/coverage/lcov-report/api/controllers/view/utils.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -8
- package/coverage/lcov-report/api/controllers/webhook.js.html +5 -10
- package/coverage/lcov-report/api/index.html +13 -18
- package/coverage/lcov-report/api/index.js.html +8 -28
- package/coverage/lcov-report/api/routes/analytics.js.html +3 -8
- package/coverage/lcov-report/api/routes/apikeys.js.html +3 -8
- package/coverage/lcov-report/api/routes/application.js.html +179 -0
- package/coverage/lcov-report/api/routes/auth.js.html +3 -8
- package/coverage/lcov-report/api/routes/automation.js.html +3 -8
- package/coverage/lcov-report/api/routes/backup.js.html +3 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +3 -8
- package/coverage/lcov-report/api/routes/component.js.html +3 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +3 -8
- package/coverage/lcov-report/api/routes/deploy.js.html +3 -8
- package/coverage/lcov-report/api/routes/dev.js.html +4 -9
- package/coverage/lcov-report/api/routes/index.html +68 -13
- package/coverage/lcov-report/api/routes/index.js.html +266 -0
- package/coverage/lcov-report/api/routes/integration.js.html +3 -8
- package/coverage/lcov-report/api/routes/layout.js.html +3 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +3 -8
- package/coverage/lcov-report/api/routes/migrations.js.html +3 -8
- package/coverage/lcov-report/api/routes/permission.js.html +3 -8
- package/coverage/lcov-report/api/routes/query.js.html +3 -8
- package/coverage/lcov-report/api/routes/role.js.html +3 -8
- package/coverage/lcov-report/api/routes/routing.js.html +3 -8
- package/coverage/lcov-report/api/routes/row.js.html +908 -0
- package/coverage/lcov-report/api/routes/screen.js.html +3 -8
- package/coverage/lcov-report/api/routes/script.js.html +3 -8
- package/coverage/lcov-report/{automations/steps/loop.js.html → api/routes/static.js.html} +80 -70
- package/coverage/lcov-report/api/routes/table.js.html +3 -8
- package/coverage/lcov-report/api/routes/templates.js.html +3 -8
- package/coverage/lcov-report/api/routes/user.js.html +3 -8
- package/coverage/lcov-report/api/routes/utils/index.html +3 -8
- package/coverage/lcov-report/api/routes/utils/validators.js.html +3 -8
- package/coverage/lcov-report/api/routes/view.js.html +3 -8
- package/coverage/lcov-report/api/routes/webhook.js.html +3 -8
- package/coverage/lcov-report/automations/actions.js.html +7 -21
- package/coverage/lcov-report/automations/automationUtils.js.html +23 -64
- package/coverage/lcov-report/automations/bullboard.js.html +3 -8
- package/coverage/lcov-report/automations/index.html +37 -27
- package/coverage/lcov-report/automations/index.js.html +3 -8
- package/coverage/lcov-report/automations/steps/bash.js.html +3 -8
- package/coverage/lcov-report/automations/steps/createRow.js.html +380 -0
- package/coverage/lcov-report/automations/steps/delay.js.html +3 -8
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +347 -0
- package/coverage/lcov-report/automations/steps/discord.js.html +3 -8
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +3 -8
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -8
- package/coverage/lcov-report/automations/steps/filter.js.html +3 -8
- package/coverage/lcov-report/automations/steps/index.html +41 -31
- package/coverage/lcov-report/automations/steps/integromat.js.html +3 -8
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +4 -9
- package/coverage/lcov-report/automations/steps/queryRows.js.html +4 -9
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +3 -8
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -8
- package/coverage/lcov-report/automations/steps/slack.js.html +3 -8
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -8
- package/coverage/lcov-report/automations/steps/utils.js.html +9 -14
- package/coverage/lcov-report/automations/steps/zapier.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/index.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +3 -8
- package/coverage/lcov-report/automations/triggers.js.html +11 -16
- package/coverage/lcov-report/automations/utils.js.html +665 -0
- package/coverage/lcov-report/block-navigation.js +0 -8
- package/coverage/lcov-report/constants/index.html +3 -8
- package/coverage/lcov-report/constants/index.js.html +42 -41
- package/coverage/lcov-report/constants/layouts.js.html +3 -8
- package/coverage/lcov-report/constants/screens.js.html +3 -8
- package/coverage/lcov-report/db/inMemoryView.js.html +3 -8
- package/coverage/lcov-report/db/index.html +3 -8
- package/coverage/lcov-report/db/index.js.html +4 -9
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +23 -25
- package/coverage/lcov-report/db/linkedRows/index.html +12 -17
- package/coverage/lcov-report/db/linkedRows/index.js.html +17 -22
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +7 -12
- package/coverage/lcov-report/db/newid.js.html +6 -11
- package/coverage/lcov-report/db/utils.js.html +79 -84
- package/coverage/lcov-report/events/AutomationEmitter.js.html +9 -14
- package/coverage/lcov-report/events/index.html +3 -8
- package/coverage/lcov-report/events/index.js.html +4 -9
- package/coverage/lcov-report/events/utils.js.html +13 -18
- package/coverage/lcov-report/index.html +132 -137
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +3 -8
- package/coverage/lcov-report/integrations/tests/index.html +3 -8
- package/coverage/lcov-report/middleware/appInfo.js.html +3 -8
- package/coverage/lcov-report/middleware/authorized.js.html +458 -0
- package/coverage/lcov-report/middleware/builder.js.html +3 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +15 -65
- package/coverage/lcov-report/middleware/index.html +50 -25
- package/coverage/lcov-report/middleware/joi-validator.js.html +4 -9
- package/coverage/lcov-report/middleware/publicApi.js.html +3 -8
- package/coverage/lcov-report/middleware/resourceId.js.html +3 -8
- package/coverage/lcov-report/middleware/selfhost.js.html +4 -9
- package/coverage/lcov-report/middleware/usageQuota.js.html +572 -0
- package/coverage/lcov-report/middleware/utils.js.html +3 -8
- package/coverage/lcov-report/sorter.js +0 -26
- package/coverage/lcov-report/threads/automation.js.html +90 -581
- package/coverage/lcov-report/threads/index.html +40 -30
- package/coverage/lcov-report/threads/index.js.html +296 -0
- package/coverage/lcov-report/threads/query.js.html +4 -9
- package/coverage/lcov-report/threads/utils.js.html +9 -17
- package/coverage/lcov-report/utilities/bcrypt.js.html +3 -8
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -8
- package/coverage/lcov-report/utilities/centralPath.js.html +3 -8
- package/coverage/lcov-report/utilities/csvParser.js.html +5 -10
- package/coverage/lcov-report/utilities/global.js.html +4 -9
- package/coverage/lcov-report/utilities/index.html +3 -8
- package/coverage/lcov-report/utilities/index.js.html +6 -11
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -32
- package/coverage/lcov-report/utilities/queue/index.html +7 -12
- package/coverage/lcov-report/utilities/routing/index.html +3 -8
- package/coverage/lcov-report/utilities/routing/index.js.html +3 -8
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -32
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +71 -67
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +106 -27
- package/coverage/lcov-report/utilities/scriptRunner.js.html +3 -8
- package/coverage/lcov-report/utilities/security.js.html +4 -9
- package/coverage/lcov-report/utilities/statusCodes.js.html +3 -8
- package/coverage/lcov-report/utilities/usageQuota/index.html +34 -24
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +39 -44
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +3 -8
- package/coverage/lcov-report/utilities/users.js.html +3 -8
- package/coverage/lcov-report/utilities/workerRequests.js.html +4 -9
- package/coverage/lcov.info +3061 -1290
- package/dist/api/controllers/application.js +73 -145
- package/dist/api/controllers/deploy/index.js +36 -68
- package/dist/api/controllers/public/applications.js +9 -29
- package/dist/api/controllers/public/queries.js +7 -27
- package/dist/api/controllers/public/rows.js +12 -32
- package/dist/api/controllers/public/tables.js +2 -2
- package/dist/api/controllers/public/users.js +8 -8
- package/dist/api/controllers/public/utils.js +1 -1
- package/dist/api/controllers/query/import/index.js +3 -3
- package/dist/api/controllers/query/index.js +44 -57
- package/dist/api/controllers/row/ExternalRequest.js +27 -27
- package/dist/api/controllers/row/index.js +60 -83
- package/dist/api/controllers/row/internal.js +1 -2
- package/dist/api/controllers/row/utils.js +1 -2
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -3
- package/dist/api/controllers/table/bulkFormula.js +1 -2
- package/dist/api/controllers/table/internal.js +55 -40
- package/dist/api/controllers/table/utils.js +229 -271
- package/dist/api/index.js +0 -5
- package/dist/api/routes/application.js +13 -39
- package/dist/api/routes/index.js +56 -61
- package/dist/api/routes/public/index.js +9 -6
- package/dist/api/routes/public/queries.js +1 -1
- package/dist/api/routes/public/rows.js +1 -1
- package/dist/api/routes/public/tables.js +3 -3
- package/dist/api/routes/public/users.js +1 -1
- package/dist/api/routes/row.js +17 -43
- package/dist/api/routes/static.js +13 -40
- package/dist/api/routes/tests/utilities/TestFunctions.js +33 -75
- package/dist/app.js +4 -8
- package/dist/automations/actions.js +0 -3
- package/dist/automations/automationUtils.js +0 -10
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +16 -13
- package/dist/automations/tests/utilities/index.js +11 -13
- package/dist/automations/utils.js +133 -187
- package/dist/constants/index.js +7 -5
- package/dist/db/linkedRows/LinkController.js +1 -0
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +3 -2
- package/dist/index.js +0 -4
- package/dist/integrations/base/sql.js +2 -2
- package/dist/integrations/base/sqlTable.js +2 -2
- package/dist/integrations/googlesheets.js +1 -1
- package/dist/integrations/index.js +0 -4
- package/dist/integrations/microsoftSqlServer.js +8 -8
- package/dist/integrations/mysql.js +9 -9
- package/dist/integrations/oracle.js +7 -7
- package/dist/integrations/postgres.js +7 -7
- package/dist/integrations/queries/sql.js +2 -2
- package/dist/integrations/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- package/dist/middleware/currentapp.js +1 -15
- package/dist/middleware/usageQuota.js +154 -0
- package/dist/migrations/functions/appUrls.js +1 -1
- package/dist/migrations/functions/quotas1.js +2 -6
- package/dist/migrations/functions/usageQuotas/index.js +4 -0
- package/dist/migrations/functions/usageQuotas/syncApps.js +7 -4
- package/dist/migrations/functions/usageQuotas/syncRows.js +8 -5
- package/dist/migrations/index.js +1 -17
- package/dist/package.json +4 -10
- package/dist/threads/automation.js +27 -149
- package/dist/threads/index.js +10 -36
- package/dist/threads/utils.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +1 -6
- package/dist/utilities/rowProcessor/index.js +11 -6
- package/dist/utilities/rowProcessor/utils.js +27 -1
- package/dist/utilities/usageQuota/index.js +86 -0
- package/nodemon.json +1 -1
- package/package.json +9 -15
- package/scripts/dev/manage.js +0 -2
- package/src/api/controllers/{application.ts → application.js} +51 -118
- package/src/api/controllers/deploy/{index.ts → index.js} +29 -53
- package/src/api/controllers/public/applications.ts +2 -2
- package/src/api/controllers/public/queries.ts +1 -1
- package/src/api/controllers/public/rows.ts +1 -1
- package/src/api/controllers/query/{index.ts → index.js} +48 -51
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/{index.ts → index.js} +17 -24
- package/src/api/controllers/row/internal.js +1 -2
- package/src/api/controllers/row/utils.js +1 -4
- package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -3
- package/src/api/controllers/table/bulkFormula.js +1 -1
- package/src/api/controllers/table/{internal.ts → internal.js} +48 -27
- package/src/api/controllers/table/{utils.ts → utils.js} +69 -86
- package/src/api/index.js +0 -5
- package/src/api/routes/{application.ts → application.js} +14 -8
- package/src/api/routes/index.js +62 -0
- package/src/api/routes/public/index.ts +4 -1
- package/src/api/routes/{row.ts → row.js} +15 -7
- package/src/api/routes/{static.ts → static.js} +11 -11
- package/src/api/routes/tests/misc.spec.js +37 -39
- package/src/api/routes/tests/routing.spec.js +0 -1
- package/src/api/routes/tests/utilities/{TestFunctions.ts → TestFunctions.js} +33 -57
- package/src/app.ts +2 -1
- package/src/automations/actions.js +0 -3
- package/src/automations/automationUtils.js +0 -12
- package/src/automations/steps/{createRow.ts → createRow.js} +15 -9
- package/src/automations/steps/{deleteRow.ts → deleteRow.js} +16 -10
- package/src/automations/tests/automation.spec.js +1 -0
- package/src/automations/tests/{createRow.spec.ts → createRow.spec.js} +15 -4
- package/src/automations/tests/{deleteRow.spec.ts → deleteRow.spec.js} +5 -3
- package/src/automations/tests/utilities/index.js +10 -12
- package/src/automations/{utils.ts → utils.js} +28 -39
- package/src/constants/index.js +8 -6
- package/src/db/linkedRows/LinkController.js +1 -0
- package/src/definitions/datasource.ts +0 -1
- package/src/environment.js +3 -2
- package/src/index.ts +0 -3
- package/src/integrations/index.ts +0 -4
- package/src/middleware/{authorized.ts → authorized.js} +14 -20
- package/src/middleware/currentapp.js +1 -16
- package/src/middleware/tests/usageQuota.spec.js +120 -0
- package/src/middleware/usageQuota.js +164 -0
- package/src/migrations/functions/tests/quotas1.spec.js +2 -0
- package/src/migrations/functions/usageQuotas/index.ts +5 -0
- package/src/migrations/functions/usageQuotas/syncApps.ts +6 -3
- package/src/migrations/functions/usageQuotas/syncRows.ts +6 -3
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +41 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +45 -0
- package/src/migrations/index.ts +1 -13
- package/src/threads/automation.js +34 -196
- package/src/threads/{index.ts → index.js} +14 -18
- package/src/threads/utils.js +0 -1
- package/src/utilities/queue/inMemoryQueue.js +1 -7
- package/src/utilities/rowProcessor/index.js +12 -9
- package/src/utilities/rowProcessor/utils.js +29 -1
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +93 -0
- package/tsconfig.json +2 -2
- package/builder/assets/index.89795487.css +0 -6
- package/builder/assets/index.be9a1b80.js +0 -1299
- package/dist/automations/steps/loop.js +0 -51
- package/dist/integrations/redis.js +0 -158
- package/dist/migrations/functions/developerQuota.js +0 -49
- package/dist/migrations/functions/publishedAppsQuota.js +0 -47
- package/dist/migrations/functions/usageQuotas/syncDevelopers.js +0 -24
- package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +0 -26
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/src/api/routes/index.ts +0 -60
- package/src/automations/steps/loop.js +0 -50
- package/src/integrations/redis.ts +0 -152
- package/src/integrations/tests/redis.spec.js +0 -60
- package/src/migrations/functions/developerQuota.ts +0 -15
- package/src/migrations/functions/publishedAppsQuota.ts +0 -13
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +0 -34
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +0 -40
- package/tsconfig.build.json +0 -10
|
@@ -36,12 +36,12 @@ var External;
|
|
|
36
36
|
function buildFilters(id, filters, table) {
|
|
37
37
|
const primary = table.primary;
|
|
38
38
|
// if passed in array need to copy for shifting etc
|
|
39
|
-
let idCopy =
|
|
39
|
+
let idCopy = fp_1.cloneDeep(id);
|
|
40
40
|
if (filters) {
|
|
41
41
|
// need to map over the filters and make sure the _id field isn't present
|
|
42
42
|
for (let filter of Object.values(filters)) {
|
|
43
43
|
if (filter._id && primary) {
|
|
44
|
-
const parts =
|
|
44
|
+
const parts = utils_1.breakRowIdField(filter._id);
|
|
45
45
|
for (let field of primary) {
|
|
46
46
|
filter[field] = parts.shift();
|
|
47
47
|
}
|
|
@@ -56,7 +56,7 @@ var External;
|
|
|
56
56
|
}
|
|
57
57
|
// if used as URL parameter it will have been joined
|
|
58
58
|
if (!Array.isArray(idCopy)) {
|
|
59
|
-
idCopy =
|
|
59
|
+
idCopy = utils_1.breakRowIdField(idCopy);
|
|
60
60
|
}
|
|
61
61
|
const equal = {};
|
|
62
62
|
if (primary && idCopy) {
|
|
@@ -90,8 +90,8 @@ var External;
|
|
|
90
90
|
.map(([fieldName]) => fieldName);
|
|
91
91
|
const iterateObject = (obj) => {
|
|
92
92
|
for (let [field, value] of Object.entries(obj)) {
|
|
93
|
-
if (fieldNames.find(name => name === field) &&
|
|
94
|
-
obj[field] =
|
|
93
|
+
if (fieldNames.find(name => name === field) && utils_1.isRowId(value)) {
|
|
94
|
+
obj[field] = utils_1.convertRowId(value);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
};
|
|
@@ -129,13 +129,13 @@ var External;
|
|
|
129
129
|
if (idParts.length === 0) {
|
|
130
130
|
return "";
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return utils_1.generateRowIdField(idParts);
|
|
133
133
|
}
|
|
134
134
|
function getEndpoint(tableId, operation) {
|
|
135
135
|
if (!tableId) {
|
|
136
136
|
return {};
|
|
137
137
|
}
|
|
138
|
-
const { datasourceId, tableName } =
|
|
138
|
+
const { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
|
|
139
139
|
return {
|
|
140
140
|
datasourceId,
|
|
141
141
|
entityId: tableName,
|
|
@@ -155,7 +155,7 @@ var External;
|
|
|
155
155
|
thisRow._id = generateIdForRow(row, table);
|
|
156
156
|
thisRow.tableId = table._id;
|
|
157
157
|
thisRow._rev = "rev";
|
|
158
|
-
return
|
|
158
|
+
return utils_4.processFormulas(table, thisRow);
|
|
159
159
|
}
|
|
160
160
|
function fixArrayTypes(row, table) {
|
|
161
161
|
for (let [fieldName, schema] of Object.entries(table.schema)) {
|
|
@@ -189,7 +189,7 @@ var External;
|
|
|
189
189
|
if (!tableId) {
|
|
190
190
|
throw "Table ID is unknown, cannot find table";
|
|
191
191
|
}
|
|
192
|
-
const { tableName } =
|
|
192
|
+
const { tableName } = utils_3.breakExternalTableId(tableId);
|
|
193
193
|
if (tableName) {
|
|
194
194
|
return this.tables[tableName];
|
|
195
195
|
}
|
|
@@ -224,7 +224,7 @@ var External;
|
|
|
224
224
|
newRow[key] = row[key];
|
|
225
225
|
continue;
|
|
226
226
|
}
|
|
227
|
-
const { tableName: linkTableName } =
|
|
227
|
+
const { tableName: linkTableName } = utils_3.breakExternalTableId(field === null || field === void 0 ? void 0 : field.tableId);
|
|
228
228
|
// table has to exist for many to many
|
|
229
229
|
if (!linkTableName || !this.tables[linkTableName]) {
|
|
230
230
|
continue;
|
|
@@ -234,7 +234,7 @@ var External;
|
|
|
234
234
|
const linkTablePrimary = linkTable.primary[0];
|
|
235
235
|
// one to many
|
|
236
236
|
if (isOneSide(field)) {
|
|
237
|
-
newRow[field.foreignKey || linkTablePrimary] =
|
|
237
|
+
newRow[field.foreignKey || linkTablePrimary] = utils_1.breakRowIdField(row[key][0])[0];
|
|
238
238
|
}
|
|
239
239
|
// many to many
|
|
240
240
|
else if (field.through) {
|
|
@@ -246,7 +246,7 @@ var External;
|
|
|
246
246
|
tableId: field.through || field.tableId,
|
|
247
247
|
isUpdate: false,
|
|
248
248
|
key: otherKey,
|
|
249
|
-
[otherKey]:
|
|
249
|
+
[otherKey]: utils_1.breakRowIdField(relationship)[0],
|
|
250
250
|
// leave the ID for enrichment later
|
|
251
251
|
[thisKey]: `{{ literal ${tablePrimary} }}`,
|
|
252
252
|
});
|
|
@@ -262,7 +262,7 @@ var External;
|
|
|
262
262
|
tableId: field.tableId,
|
|
263
263
|
isUpdate: true,
|
|
264
264
|
key: otherKey,
|
|
265
|
-
[thisKey]:
|
|
265
|
+
[thisKey]: utils_1.breakRowIdField(relationship)[0],
|
|
266
266
|
// leave the ID for enrichment later
|
|
267
267
|
[otherKey]: `{{ literal ${tablePrimary} }}`,
|
|
268
268
|
});
|
|
@@ -355,7 +355,7 @@ var External;
|
|
|
355
355
|
// do this at end once its been added to the final rows
|
|
356
356
|
finalRows = this.updateRelationshipColumns(table, row, finalRows, relationships);
|
|
357
357
|
}
|
|
358
|
-
return
|
|
358
|
+
return utils_4.processFormulas(table, Object.values(finalRows)).map((row) => this.squashRelationshipColumns(table, row, relationships));
|
|
359
359
|
}
|
|
360
360
|
/**
|
|
361
361
|
* Gets the list of relationship JSON structures based on the columns in the table,
|
|
@@ -368,7 +368,7 @@ var External;
|
|
|
368
368
|
if (field.type !== constants_1.FieldTypes.LINK) {
|
|
369
369
|
continue;
|
|
370
370
|
}
|
|
371
|
-
const { tableName: linkTableName } =
|
|
371
|
+
const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
|
|
372
372
|
// no table to link to, this is not a valid relationships
|
|
373
373
|
if (!linkTableName || !this.tables[linkTableName]) {
|
|
374
374
|
continue;
|
|
@@ -386,7 +386,7 @@ var External;
|
|
|
386
386
|
column: fieldName,
|
|
387
387
|
};
|
|
388
388
|
if (field.through) {
|
|
389
|
-
const { tableName: throughTableName } =
|
|
389
|
+
const { tableName: throughTableName } = utils_3.breakExternalTableId(field.through);
|
|
390
390
|
definition.through = throughTableName;
|
|
391
391
|
// don't support composite keys for relationships
|
|
392
392
|
definition.from = field.throughTo || table.primary[0];
|
|
@@ -405,7 +405,7 @@ var External;
|
|
|
405
405
|
lookupRelations(tableId, row) {
|
|
406
406
|
return __awaiter(this, void 0, void 0, function* () {
|
|
407
407
|
const related = {};
|
|
408
|
-
const { tableName } =
|
|
408
|
+
const { tableName } = utils_3.breakExternalTableId(tableId);
|
|
409
409
|
if (!tableName) {
|
|
410
410
|
return related;
|
|
411
411
|
}
|
|
@@ -422,7 +422,7 @@ var External;
|
|
|
422
422
|
}
|
|
423
423
|
const isMany = field.relationshipType === constants_1.RelationshipTypes.MANY_TO_MANY;
|
|
424
424
|
const tableId = isMany ? field.through : field.tableId;
|
|
425
|
-
const { tableName: relatedTableName } =
|
|
425
|
+
const { tableName: relatedTableName } = utils_3.breakExternalTableId(tableId);
|
|
426
426
|
// @ts-ignore
|
|
427
427
|
const linkPrimaryKey = this.tables[relatedTableName].primary[0];
|
|
428
428
|
const manyKey = field.throughTo || primaryKey;
|
|
@@ -431,7 +431,7 @@ var External;
|
|
|
431
431
|
if (!lookupField || !row[lookupField]) {
|
|
432
432
|
continue;
|
|
433
433
|
}
|
|
434
|
-
const response = yield
|
|
434
|
+
const response = yield utils_2.getDatasourceAndQuery({
|
|
435
435
|
endpoint: getEndpoint(tableId, constants_1.DataSourceOperation.READ),
|
|
436
436
|
filters: {
|
|
437
437
|
equal: {
|
|
@@ -465,7 +465,7 @@ var External;
|
|
|
465
465
|
const related = yield this.lookupRelations(mainTableId, row);
|
|
466
466
|
for (let relationship of relationships) {
|
|
467
467
|
const { key, tableId, isUpdate, id } = relationship, rest = __rest(relationship, ["key", "tableId", "isUpdate", "id"]);
|
|
468
|
-
const body =
|
|
468
|
+
const body = string_templates_1.processObjectSync(rest, row, {});
|
|
469
469
|
const linkTable = this.getTable(tableId);
|
|
470
470
|
// @ts-ignore
|
|
471
471
|
const linkPrimary = linkTable === null || linkTable === void 0 ? void 0 : linkTable.primary[0];
|
|
@@ -479,7 +479,7 @@ var External;
|
|
|
479
479
|
? constants_1.DataSourceOperation.UPDATE
|
|
480
480
|
: constants_1.DataSourceOperation.CREATE;
|
|
481
481
|
if (!found) {
|
|
482
|
-
promises.push(
|
|
482
|
+
promises.push(utils_2.getDatasourceAndQuery({
|
|
483
483
|
endpoint: getEndpoint(tableId, operation),
|
|
484
484
|
// if we're doing many relationships then we're writing, only one response
|
|
485
485
|
body,
|
|
@@ -507,7 +507,7 @@ var External;
|
|
|
507
507
|
? constants_1.DataSourceOperation.DELETE
|
|
508
508
|
: constants_1.DataSourceOperation.UPDATE;
|
|
509
509
|
const body = isMany ? null : { [colName]: null };
|
|
510
|
-
promises.push(
|
|
510
|
+
promises.push(utils_2.getDatasourceAndQuery({
|
|
511
511
|
endpoint: getEndpoint(tableId, op),
|
|
512
512
|
body,
|
|
513
513
|
filters,
|
|
@@ -538,7 +538,7 @@ var External;
|
|
|
538
538
|
if (field.type !== constants_1.FieldTypes.LINK || !includeRelations) {
|
|
539
539
|
continue;
|
|
540
540
|
}
|
|
541
|
-
const { tableName: linkTableName } =
|
|
541
|
+
const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
|
|
542
542
|
if (linkTableName) {
|
|
543
543
|
const linkTable = this.tables[linkTableName];
|
|
544
544
|
if (linkTable) {
|
|
@@ -552,12 +552,12 @@ var External;
|
|
|
552
552
|
run(config) {
|
|
553
553
|
return __awaiter(this, void 0, void 0, function* () {
|
|
554
554
|
const { operation, tableId } = this;
|
|
555
|
-
let { datasourceId, tableName } =
|
|
555
|
+
let { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
|
|
556
556
|
if (!tableName) {
|
|
557
557
|
throw "Unable to run without a table name";
|
|
558
558
|
}
|
|
559
559
|
if (!this.datasource) {
|
|
560
|
-
const db =
|
|
560
|
+
const db = context_1.getAppDB();
|
|
561
561
|
this.datasource = yield db.get(datasourceId);
|
|
562
562
|
if (!this.datasource || !this.datasource.entities) {
|
|
563
563
|
throw "No tables found, fetch tables before query.";
|
|
@@ -565,7 +565,7 @@ var External;
|
|
|
565
565
|
this.tables = this.datasource.entities;
|
|
566
566
|
}
|
|
567
567
|
const table = this.tables[tableName];
|
|
568
|
-
let isSql =
|
|
568
|
+
let isSql = utils_3.isSQL(this.datasource);
|
|
569
569
|
if (!table) {
|
|
570
570
|
throw `Unable to process query, table "${tableName}" not defined.`;
|
|
571
571
|
}
|
|
@@ -604,7 +604,7 @@ var External;
|
|
|
604
604
|
},
|
|
605
605
|
};
|
|
606
606
|
// can't really use response right now
|
|
607
|
-
const response = yield
|
|
607
|
+
const response = yield utils_2.getDatasourceAndQuery(json);
|
|
608
608
|
// handle many to many relationships now if we know the ID (could be auto increment)
|
|
609
609
|
if (operation !== constants_1.DataSourceOperation.READ &&
|
|
610
610
|
processed.manyRelationships) {
|
|
@@ -8,20 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.exportRows = exports.fetchEnrichedRow = exports.validate = exports.search = exports.destroy = exports.find = exports.fetch = exports.fetchView = exports.save = exports.patch = void 0;
|
|
16
|
-
const pro_1 = require("@budibase/pro");
|
|
17
|
-
const internal_1 = __importDefault(require("./internal"));
|
|
18
|
-
const external_1 = __importDefault(require("./external"));
|
|
19
|
-
const utils_1 = require("../../../integrations/utils");
|
|
11
|
+
const internal = require("./internal");
|
|
12
|
+
const external = require("./external");
|
|
13
|
+
const { isExternalTable } = require("../../../integrations/utils");
|
|
20
14
|
function pickApi(tableId) {
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
15
|
+
if (isExternalTable(tableId)) {
|
|
16
|
+
return external;
|
|
23
17
|
}
|
|
24
|
-
return
|
|
18
|
+
return internal;
|
|
25
19
|
}
|
|
26
20
|
function getTableId(ctx) {
|
|
27
21
|
if (ctx.request.body && ctx.request.body.tableId) {
|
|
@@ -34,55 +28,48 @@ function getTableId(ctx) {
|
|
|
34
28
|
return ctx.params.viewName;
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const appId = ctx.appId;
|
|
40
|
-
const tableId = getTableId(ctx);
|
|
41
|
-
const body = ctx.request.body;
|
|
42
|
-
// if it doesn't have an _id then its save
|
|
43
|
-
if (body && !body._id) {
|
|
44
|
-
return save(ctx);
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const { row, table } = yield pickApi(tableId).patch(ctx);
|
|
48
|
-
ctx.status = 200;
|
|
49
|
-
ctx.eventEmitter &&
|
|
50
|
-
ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
|
|
51
|
-
ctx.message = `${table.name} updated successfully.`;
|
|
52
|
-
ctx.body = row;
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
ctx.throw(400, err);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
exports.patch = patch;
|
|
60
|
-
const saveRow = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
32
|
const appId = ctx.appId;
|
|
62
33
|
const tableId = getTableId(ctx);
|
|
63
34
|
const body = ctx.request.body;
|
|
64
|
-
// if it
|
|
65
|
-
if (body && body._id) {
|
|
66
|
-
return
|
|
35
|
+
// if it doesn't have an _id then its save
|
|
36
|
+
if (body && !body._id) {
|
|
37
|
+
return exports.save(ctx);
|
|
67
38
|
}
|
|
68
39
|
try {
|
|
69
|
-
const { row, table } = yield pickApi(tableId).
|
|
40
|
+
const { row, table } = yield pickApi(tableId).patch(ctx);
|
|
70
41
|
ctx.status = 200;
|
|
71
|
-
ctx.eventEmitter &&
|
|
72
|
-
|
|
42
|
+
ctx.eventEmitter &&
|
|
43
|
+
ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
|
|
44
|
+
ctx.message = `${table.name} updated successfully.`;
|
|
73
45
|
ctx.body = row;
|
|
74
46
|
}
|
|
75
47
|
catch (err) {
|
|
76
48
|
ctx.throw(400, err);
|
|
77
49
|
}
|
|
78
50
|
});
|
|
79
|
-
function
|
|
51
|
+
exports.save = function (ctx) {
|
|
80
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
|
|
53
|
+
const appId = ctx.appId;
|
|
54
|
+
const tableId = getTableId(ctx);
|
|
55
|
+
const body = ctx.request.body;
|
|
56
|
+
// if it has an ID already then its a patch
|
|
57
|
+
if (body && body._id) {
|
|
58
|
+
return exports.patch(ctx);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const { row, table } = yield pickApi(tableId).save(ctx);
|
|
62
|
+
ctx.status = 200;
|
|
63
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
|
|
64
|
+
ctx.message = `${table.name} saved successfully`;
|
|
65
|
+
ctx.body = row;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
ctx.throw(400, err);
|
|
69
|
+
}
|
|
82
70
|
});
|
|
83
|
-
}
|
|
84
|
-
exports.
|
|
85
|
-
function fetchView(ctx) {
|
|
71
|
+
};
|
|
72
|
+
exports.fetchView = function (ctx) {
|
|
86
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
74
|
const tableId = getTableId(ctx);
|
|
88
75
|
try {
|
|
@@ -92,9 +79,8 @@ function fetchView(ctx) {
|
|
|
92
79
|
ctx.throw(400, err);
|
|
93
80
|
}
|
|
94
81
|
});
|
|
95
|
-
}
|
|
96
|
-
exports.
|
|
97
|
-
function fetch(ctx) {
|
|
82
|
+
};
|
|
83
|
+
exports.fetch = function (ctx) {
|
|
98
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
85
|
const tableId = getTableId(ctx);
|
|
100
86
|
try {
|
|
@@ -104,9 +90,8 @@ function fetch(ctx) {
|
|
|
104
90
|
ctx.throw(400, err);
|
|
105
91
|
}
|
|
106
92
|
});
|
|
107
|
-
}
|
|
108
|
-
exports.
|
|
109
|
-
function find(ctx) {
|
|
93
|
+
};
|
|
94
|
+
exports.find = function (ctx) {
|
|
110
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
96
|
const tableId = getTableId(ctx);
|
|
112
97
|
try {
|
|
@@ -116,9 +101,8 @@ function find(ctx) {
|
|
|
116
101
|
ctx.throw(400, err);
|
|
117
102
|
}
|
|
118
103
|
});
|
|
119
|
-
}
|
|
120
|
-
exports.
|
|
121
|
-
function destroy(ctx) {
|
|
104
|
+
};
|
|
105
|
+
exports.destroy = function (ctx) {
|
|
122
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
107
|
const appId = ctx.appId;
|
|
124
108
|
const inputs = ctx.request.body;
|
|
@@ -126,7 +110,6 @@ function destroy(ctx) {
|
|
|
126
110
|
let response, row;
|
|
127
111
|
if (inputs.rows) {
|
|
128
112
|
let { rows } = yield pickApi(tableId).bulkDestroy(ctx);
|
|
129
|
-
yield pro_1.quotas.removeRows(rows.length);
|
|
130
113
|
response = rows;
|
|
131
114
|
for (let row of rows) {
|
|
132
115
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
|
|
@@ -134,7 +117,6 @@ function destroy(ctx) {
|
|
|
134
117
|
}
|
|
135
118
|
else {
|
|
136
119
|
let resp = yield pickApi(tableId).destroy(ctx);
|
|
137
|
-
yield pro_1.quotas.removeRow();
|
|
138
120
|
response = resp.response;
|
|
139
121
|
row = resp.row;
|
|
140
122
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
|
|
@@ -144,52 +126,47 @@ function destroy(ctx) {
|
|
|
144
126
|
ctx.row = row || {};
|
|
145
127
|
ctx.body = response;
|
|
146
128
|
});
|
|
147
|
-
}
|
|
148
|
-
exports.
|
|
149
|
-
|
|
129
|
+
};
|
|
130
|
+
exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const tableId = getTableId(ctx);
|
|
132
|
+
try {
|
|
133
|
+
ctx.status = 200;
|
|
134
|
+
ctx.body = yield pickApi(tableId).search(ctx);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
ctx.throw(400, err);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
exports.validate = function (ctx) {
|
|
150
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
142
|
const tableId = getTableId(ctx);
|
|
152
143
|
try {
|
|
153
|
-
ctx.
|
|
154
|
-
ctx.body = yield pickApi(tableId).search(ctx);
|
|
144
|
+
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
155
145
|
}
|
|
156
146
|
catch (err) {
|
|
157
147
|
ctx.throw(400, err);
|
|
158
148
|
}
|
|
159
149
|
});
|
|
160
|
-
}
|
|
161
|
-
exports.
|
|
162
|
-
function validate(ctx) {
|
|
150
|
+
};
|
|
151
|
+
exports.fetchEnrichedRow = function (ctx) {
|
|
163
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
153
|
const tableId = getTableId(ctx);
|
|
165
154
|
try {
|
|
166
|
-
ctx.body = yield pickApi(tableId).
|
|
155
|
+
ctx.body = yield pickApi(tableId).fetchEnrichedRow(ctx);
|
|
167
156
|
}
|
|
168
157
|
catch (err) {
|
|
169
158
|
ctx.throw(400, err);
|
|
170
159
|
}
|
|
171
160
|
});
|
|
172
|
-
}
|
|
173
|
-
exports.
|
|
174
|
-
function fetchEnrichedRow(ctx) {
|
|
161
|
+
};
|
|
162
|
+
exports.export = function (ctx) {
|
|
175
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
164
|
const tableId = getTableId(ctx);
|
|
177
165
|
try {
|
|
178
|
-
ctx.body = yield pickApi(tableId).
|
|
166
|
+
ctx.body = yield pickApi(tableId).exportRows(ctx);
|
|
179
167
|
}
|
|
180
168
|
catch (err) {
|
|
181
169
|
ctx.throw(400, err);
|
|
182
170
|
}
|
|
183
171
|
});
|
|
184
|
-
}
|
|
185
|
-
exports.fetchEnrichedRow = fetchEnrichedRow;
|
|
186
|
-
const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
-
const tableId = getTableId(ctx);
|
|
188
|
-
try {
|
|
189
|
-
ctx.body = yield pickApi(tableId).exportRows(ctx);
|
|
190
|
-
}
|
|
191
|
-
catch (err) {
|
|
192
|
-
ctx.throw(400, err);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
exports.exportRows = exportRows;
|
|
172
|
+
};
|
|
@@ -243,9 +243,8 @@ exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
243
243
|
exports.destroy = function (ctx) {
|
|
244
244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
245
245
|
const db = getAppDB();
|
|
246
|
-
const { _id } = ctx.request.body;
|
|
246
|
+
const { _id, _rev } = ctx.request.body;
|
|
247
247
|
let row = yield db.get(_id);
|
|
248
|
-
let _rev = ctx.request.body._rev || row._rev;
|
|
249
248
|
if (row.tableId !== ctx.params.tableId) {
|
|
250
249
|
throw "Supplied tableId doesn't match the row's tableId";
|
|
251
250
|
}
|
|
@@ -71,8 +71,7 @@ exports.validate = ({ tableId, row, table }) => __awaiter(void 0, void 0, void 0
|
|
|
71
71
|
if (type === FieldTypes.ARRAY && row[fieldName]) {
|
|
72
72
|
if (row[fieldName].length) {
|
|
73
73
|
row[fieldName].map(val => {
|
|
74
|
-
if (!constraints.inclusion.includes(val)
|
|
75
|
-
constraints.inclusion.length !== 0) {
|
|
74
|
+
if (!constraints.inclusion.includes(val)) {
|
|
76
75
|
errors[fieldName] = "Field not in list";
|
|
77
76
|
}
|
|
78
77
|
});
|
|
@@ -24,7 +24,6 @@ function isStaticFormula(column) {
|
|
|
24
24
|
* in the formula.
|
|
25
25
|
*/
|
|
26
26
|
function getFormulaThatUseColumn(table, columnNames) {
|
|
27
|
-
var _a;
|
|
28
27
|
let formula = [];
|
|
29
28
|
columnNames = Array.isArray(columnNames) ? columnNames : [columnNames];
|
|
30
29
|
for (let column of Object.values(table.schema)) {
|
|
@@ -32,7 +31,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
32
31
|
if (!isStaticFormula(column)) {
|
|
33
32
|
continue;
|
|
34
33
|
}
|
|
35
|
-
if (!doesContainStrings(
|
|
34
|
+
if (!doesContainStrings(column.formula, columnNames)) {
|
|
36
35
|
continue;
|
|
37
36
|
}
|
|
38
37
|
formula.push(column.name);
|
|
@@ -19,33 +19,52 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const utils_2 = require("./utils");
|
|
22
|
+
const linkRows = require("../../../db/linkedRows");
|
|
23
|
+
const { getRowParams, generateTableID } = require("../../../db/utils");
|
|
24
|
+
const { FieldTypes } = require("../../../constants");
|
|
25
|
+
const { TableSaveFunctions, hasTypeChanged, getTable, handleDataImport, } = require("./utils");
|
|
26
|
+
const usageQuota = require("../../../utilities/usageQuota");
|
|
28
27
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const env = require("../../../environment");
|
|
29
|
+
const { cleanupAttachments, fixAutoColumnSubType, } = require("../../../utilities/rowProcessor");
|
|
30
|
+
const { runStaticFormulaChecks } = require("./bulkFormula");
|
|
31
|
+
function checkAutoColumns(table, oldTable) {
|
|
32
|
+
if (!table.schema) {
|
|
33
|
+
return table;
|
|
34
|
+
}
|
|
35
|
+
for (let [key, schema] of Object.entries(table.schema)) {
|
|
36
|
+
if (!schema.autocolumn || schema.subtype) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const oldSchema = oldTable && oldTable.schema[key];
|
|
40
|
+
if (oldSchema && oldSchema.subtype) {
|
|
41
|
+
table.schema[key].subtype = oldSchema.subtype;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
table.schema[key] = fixAutoColumnSubType(schema);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return table;
|
|
48
|
+
}
|
|
49
|
+
exports.save = function (ctx) {
|
|
34
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
51
|
const db = getAppDB();
|
|
36
52
|
const _a = ctx.request.body, { dataImport } = _a, rest = __rest(_a, ["dataImport"]);
|
|
37
|
-
let tableToSave = Object.assign({ type: "table", _id:
|
|
53
|
+
let tableToSave = Object.assign({ type: "table", _id: generateTableID(), views: {} }, rest);
|
|
38
54
|
// if the table obj had an _id then it will have been retrieved
|
|
39
55
|
let oldTable;
|
|
40
56
|
if (ctx.request.body && ctx.request.body._id) {
|
|
41
57
|
oldTable = yield db.get(ctx.request.body._id);
|
|
42
58
|
}
|
|
43
|
-
|
|
59
|
+
// check all types are correct
|
|
60
|
+
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
44
61
|
ctx.throw(400, "A column type has changed.");
|
|
45
62
|
}
|
|
63
|
+
// check that subtypes have been maintained
|
|
64
|
+
tableToSave = checkAutoColumns(tableToSave, oldTable);
|
|
46
65
|
// saving a table is a complex operation, involving many different steps, this
|
|
47
66
|
// has been broken out into a utility to make it more obvious/easier to manipulate
|
|
48
|
-
const tableSaveFunctions = new
|
|
67
|
+
const tableSaveFunctions = new TableSaveFunctions({
|
|
49
68
|
user: ctx.user,
|
|
50
69
|
oldTable,
|
|
51
70
|
dataImport,
|
|
@@ -70,7 +89,7 @@ function save(ctx) {
|
|
|
70
89
|
}
|
|
71
90
|
// rename row fields when table column is renamed
|
|
72
91
|
/* istanbul ignore next */
|
|
73
|
-
if (_rename && tableToSave.schema[_rename.updated].type ===
|
|
92
|
+
if (_rename && tableToSave.schema[_rename.updated].type === FieldTypes.LINK) {
|
|
74
93
|
ctx.throw(400, "Cannot rename a linked column.");
|
|
75
94
|
}
|
|
76
95
|
tableToSave = yield tableSaveFunctions.mid(tableToSave);
|
|
@@ -85,8 +104,10 @@ function save(ctx) {
|
|
|
85
104
|
}
|
|
86
105
|
// update linked rows
|
|
87
106
|
try {
|
|
88
|
-
const linkResp = yield
|
|
89
|
-
eventType: oldTable
|
|
107
|
+
const linkResp = yield linkRows.updateLinks({
|
|
108
|
+
eventType: oldTable
|
|
109
|
+
? linkRows.EventType.TABLE_UPDATED
|
|
110
|
+
: linkRows.EventType.TABLE_SAVE,
|
|
90
111
|
table: tableToSave,
|
|
91
112
|
oldTable: oldTable,
|
|
92
113
|
});
|
|
@@ -107,52 +128,46 @@ function save(ctx) {
|
|
|
107
128
|
tableToSave._rev = result.rev;
|
|
108
129
|
tableToSave = yield tableSaveFunctions.after(tableToSave);
|
|
109
130
|
// has to run after, make sure it has _id
|
|
110
|
-
yield
|
|
131
|
+
yield runStaticFormulaChecks(tableToSave, { oldTable });
|
|
111
132
|
return tableToSave;
|
|
112
133
|
});
|
|
113
|
-
}
|
|
114
|
-
exports.
|
|
115
|
-
function destroy(ctx) {
|
|
134
|
+
};
|
|
135
|
+
exports.destroy = function (ctx) {
|
|
116
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
137
|
const db = getAppDB();
|
|
118
138
|
const tableToDelete = yield db.get(ctx.params.tableId);
|
|
119
139
|
// Delete all rows for that table
|
|
120
|
-
const rows = yield db.allDocs(
|
|
140
|
+
const rows = yield db.allDocs(getRowParams(ctx.params.tableId, null, {
|
|
121
141
|
include_docs: true,
|
|
122
142
|
}));
|
|
123
|
-
yield db.bulkDocs(rows.rows.map(
|
|
124
|
-
yield
|
|
143
|
+
yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
144
|
+
yield usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length);
|
|
125
145
|
// update linked rows
|
|
126
|
-
yield
|
|
127
|
-
eventType:
|
|
146
|
+
yield linkRows.updateLinks({
|
|
147
|
+
eventType: linkRows.EventType.TABLE_DELETE,
|
|
128
148
|
table: tableToDelete,
|
|
129
149
|
});
|
|
130
150
|
// don't remove the table itself until very end
|
|
131
151
|
yield db.remove(tableToDelete);
|
|
132
152
|
// remove table search index
|
|
133
|
-
if (!
|
|
153
|
+
if (!env.isTest()) {
|
|
134
154
|
const currentIndexes = yield db.getIndexes();
|
|
135
|
-
const existingIndex = currentIndexes.indexes.find(
|
|
155
|
+
const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
|
|
136
156
|
if (existingIndex) {
|
|
137
157
|
yield db.deleteIndex(existingIndex);
|
|
138
158
|
}
|
|
139
159
|
}
|
|
140
160
|
// has to run after, make sure it has _id
|
|
141
|
-
yield
|
|
142
|
-
|
|
143
|
-
deletion: true,
|
|
144
|
-
});
|
|
145
|
-
yield (0, rowProcessor_1.cleanupAttachments)(tableToDelete, { rows });
|
|
161
|
+
yield runStaticFormulaChecks(tableToDelete, { deletion: true });
|
|
162
|
+
yield cleanupAttachments(tableToDelete, { rows });
|
|
146
163
|
return tableToDelete;
|
|
147
164
|
});
|
|
148
|
-
}
|
|
149
|
-
exports.
|
|
150
|
-
function bulkImport(ctx) {
|
|
165
|
+
};
|
|
166
|
+
exports.bulkImport = function (ctx) {
|
|
151
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
const table = yield
|
|
168
|
+
const table = yield getTable(ctx.params.tableId);
|
|
153
169
|
const { dataImport } = ctx.request.body;
|
|
154
|
-
yield
|
|
170
|
+
yield handleDataImport(ctx.user, table, dataImport);
|
|
155
171
|
return table;
|
|
156
172
|
});
|
|
157
|
-
}
|
|
158
|
-
exports.bulkImport = bulkImport;
|
|
173
|
+
};
|