@budibase/server 1.0.123 → 1.0.125
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.3d890df7.js +1299 -0
- package/builder/assets/index.89795487.css +6 -0
- package/builder/assets/{vendor.8e34a169.js → vendor.5240f480.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +695 -1678
- package/coverage/coverage-final.json +28 -43
- package/coverage/lcov-report/api/controllers/analytics.js.html +8 -3
- package/coverage/lcov-report/api/controllers/apikeys.js.html +9 -4
- package/coverage/lcov-report/api/controllers/auth.js.html +8 -3
- package/coverage/lcov-report/api/controllers/automation.js.html +8 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +8 -3
- package/coverage/lcov-report/api/controllers/cloud.js.html +8 -3
- package/coverage/lcov-report/api/controllers/component.js.html +8 -3
- package/coverage/lcov-report/api/controllers/datasource.js.html +11 -6
- package/coverage/lcov-report/api/controllers/dev.js.html +8 -3
- package/coverage/lcov-report/api/controllers/index.html +16 -26
- package/coverage/lcov-report/api/controllers/integration.js.html +8 -3
- package/coverage/lcov-report/api/controllers/layout.js.html +8 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +8 -3
- package/coverage/lcov-report/api/controllers/migrations.js.html +8 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +8 -3
- package/coverage/lcov-report/api/controllers/query/index.html +16 -26
- package/coverage/lcov-report/api/controllers/query/validation.js.html +8 -3
- package/coverage/lcov-report/api/controllers/role.js.html +10 -5
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -4
- package/coverage/lcov-report/api/controllers/row/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/row/index.html +25 -35
- package/coverage/lcov-report/api/controllers/row/internal.js.html +32 -24
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +21 -16
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -19
- package/coverage/lcov-report/api/controllers/row/utils.js.html +33 -19
- package/coverage/lcov-report/api/controllers/screen.js.html +9 -4
- package/coverage/lcov-report/api/controllers/script.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +55 -50
- package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/index.html +19 -44
- package/coverage/lcov-report/api/controllers/table/index.js.html +20 -15
- package/coverage/lcov-report/api/controllers/templates.js.html +8 -3
- package/coverage/lcov-report/api/controllers/user.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/index.html +8 -3
- package/coverage/lcov-report/api/controllers/view/index.js.html +10 -5
- package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -3
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +10 -5
- package/coverage/lcov-report/api/index.html +18 -13
- package/coverage/lcov-report/api/index.js.html +28 -8
- package/coverage/lcov-report/api/routes/analytics.js.html +8 -3
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -3
- package/coverage/lcov-report/api/routes/auth.js.html +8 -3
- package/coverage/lcov-report/api/routes/automation.js.html +8 -3
- package/coverage/lcov-report/api/routes/backup.js.html +8 -3
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -3
- package/coverage/lcov-report/api/routes/component.js.html +8 -3
- package/coverage/lcov-report/api/routes/datasource.js.html +8 -3
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -3
- package/coverage/lcov-report/api/routes/dev.js.html +9 -4
- package/coverage/lcov-report/api/routes/index.html +13 -68
- package/coverage/lcov-report/api/routes/integration.js.html +8 -3
- package/coverage/lcov-report/api/routes/layout.js.html +8 -3
- package/coverage/lcov-report/api/routes/metadata.js.html +8 -3
- package/coverage/lcov-report/api/routes/migrations.js.html +8 -3
- package/coverage/lcov-report/api/routes/permission.js.html +8 -3
- package/coverage/lcov-report/api/routes/query.js.html +8 -3
- package/coverage/lcov-report/api/routes/role.js.html +8 -3
- package/coverage/lcov-report/api/routes/routing.js.html +8 -3
- package/coverage/lcov-report/api/routes/screen.js.html +8 -3
- package/coverage/lcov-report/api/routes/script.js.html +8 -3
- package/coverage/lcov-report/api/routes/table.js.html +8 -3
- package/coverage/lcov-report/api/routes/templates.js.html +8 -3
- package/coverage/lcov-report/api/routes/user.js.html +8 -3
- package/coverage/lcov-report/api/routes/utils/index.html +8 -3
- package/coverage/lcov-report/api/routes/utils/validators.js.html +8 -3
- package/coverage/lcov-report/api/routes/view.js.html +8 -3
- package/coverage/lcov-report/api/routes/webhook.js.html +8 -3
- package/coverage/lcov-report/automations/actions.js.html +21 -7
- package/coverage/lcov-report/automations/automationUtils.js.html +64 -23
- package/coverage/lcov-report/automations/bullboard.js.html +8 -3
- package/coverage/lcov-report/automations/index.html +27 -37
- package/coverage/lcov-report/automations/index.js.html +8 -3
- package/coverage/lcov-report/automations/steps/bash.js.html +8 -3
- package/coverage/lcov-report/automations/steps/delay.js.html +8 -3
- package/coverage/lcov-report/automations/steps/discord.js.html +8 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +8 -3
- package/coverage/lcov-report/automations/steps/executeScript.js.html +8 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +8 -3
- package/coverage/lcov-report/automations/steps/index.html +31 -41
- package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
- package/coverage/lcov-report/{api/routes/static.js.html → automations/steps/loop.js.html} +70 -80
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +9 -4
- package/coverage/lcov-report/automations/steps/queryRows.js.html +9 -4
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +8 -3
- package/coverage/lcov-report/automations/steps/serverLog.js.html +8 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +8 -3
- package/coverage/lcov-report/automations/steps/updateRow.js.html +8 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +14 -9
- package/coverage/lcov-report/automations/steps/zapier.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/index.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +8 -3
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +8 -3
- package/coverage/lcov-report/automations/triggers.js.html +16 -11
- package/coverage/lcov-report/block-navigation.js +8 -0
- package/coverage/lcov-report/constants/index.html +12 -7
- package/coverage/lcov-report/constants/index.js.html +55 -32
- package/coverage/lcov-report/constants/layouts.js.html +8 -3
- package/coverage/lcov-report/constants/screens.js.html +8 -3
- package/coverage/lcov-report/db/inMemoryView.js.html +8 -3
- package/coverage/lcov-report/db/index.html +8 -3
- package/coverage/lcov-report/db/index.js.html +9 -4
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +20 -15
- package/coverage/lcov-report/db/linkedRows/index.html +8 -3
- package/coverage/lcov-report/db/linkedRows/index.js.html +22 -17
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +12 -7
- package/coverage/lcov-report/db/newid.js.html +11 -6
- package/coverage/lcov-report/db/utils.js.html +84 -79
- package/coverage/lcov-report/events/AutomationEmitter.js.html +14 -9
- package/coverage/lcov-report/events/index.html +8 -3
- package/coverage/lcov-report/events/index.js.html +9 -4
- package/coverage/lcov-report/events/utils.js.html +18 -13
- package/coverage/lcov-report/index.html +125 -120
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +8 -3
- package/coverage/lcov-report/integrations/tests/index.html +8 -3
- package/coverage/lcov-report/middleware/appInfo.js.html +8 -3
- package/coverage/lcov-report/middleware/builder.js.html +8 -3
- package/coverage/lcov-report/middleware/currentapp.js.html +65 -15
- package/coverage/lcov-report/middleware/index.html +25 -50
- package/coverage/lcov-report/middleware/joi-validator.js.html +9 -4
- package/coverage/lcov-report/middleware/publicApi.js.html +8 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +8 -3
- package/coverage/lcov-report/middleware/selfhost.js.html +9 -4
- package/coverage/lcov-report/middleware/utils.js.html +8 -3
- package/coverage/lcov-report/sorter.js +26 -0
- package/coverage/lcov-report/threads/automation.js.html +581 -90
- package/coverage/lcov-report/threads/index.html +30 -40
- package/coverage/lcov-report/threads/query.js.html +9 -4
- package/coverage/lcov-report/threads/utils.js.html +17 -9
- package/coverage/lcov-report/utilities/bcrypt.js.html +8 -3
- package/coverage/lcov-report/utilities/budibaseDir.js.html +8 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +8 -3
- package/coverage/lcov-report/utilities/csvParser.js.html +10 -5
- package/coverage/lcov-report/utilities/global.js.html +9 -4
- package/coverage/lcov-report/utilities/index.html +8 -3
- package/coverage/lcov-report/utilities/index.js.html +11 -6
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +32 -9
- package/coverage/lcov-report/utilities/queue/index.html +12 -7
- package/coverage/lcov-report/utilities/routing/index.html +8 -3
- package/coverage/lcov-report/utilities/routing/index.js.html +8 -3
- package/coverage/lcov-report/utilities/rowProcessor/index.html +8 -3
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +48 -43
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +18 -13
- package/coverage/lcov-report/utilities/scriptRunner.js.html +8 -3
- package/coverage/lcov-report/utilities/security.js.html +9 -4
- package/coverage/lcov-report/utilities/statusCodes.js.html +8 -3
- package/coverage/lcov-report/utilities/usageQuota/index.html +24 -34
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +44 -39
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +8 -3
- package/coverage/lcov-report/utilities/users.js.html +8 -3
- package/coverage/lcov-report/utilities/workerRequests.js.html +9 -4
- package/coverage/lcov.info +1144 -2875
- package/dist/api/controllers/application.js +145 -73
- package/dist/api/controllers/deploy/index.js +68 -36
- package/dist/api/controllers/public/applications.js +29 -9
- package/dist/api/controllers/public/queries.js +27 -7
- package/dist/api/controllers/public/rows.js +32 -12
- 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 +57 -44
- package/dist/api/controllers/row/ExternalRequest.js +27 -27
- package/dist/api/controllers/row/index.js +83 -60
- package/dist/api/controllers/row/internal.js +2 -1
- package/dist/api/controllers/row/utils.js +2 -1
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +3 -0
- package/dist/api/controllers/table/bulkFormula.js +2 -1
- package/dist/api/controllers/table/internal.js +41 -35
- package/dist/api/controllers/table/utils.js +271 -229
- package/dist/api/index.js +5 -0
- package/dist/api/routes/application.js +39 -13
- package/dist/api/routes/index.js +61 -56
- package/dist/api/routes/public/index.js +6 -9
- 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 +43 -17
- package/dist/api/routes/static.js +40 -13
- package/dist/api/routes/tests/utilities/TestFunctions.js +75 -33
- package/dist/app.js +8 -4
- package/dist/automations/actions.js +3 -0
- package/dist/automations/automationUtils.js +10 -0
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +13 -16
- package/dist/automations/steps/loop.js +51 -0
- package/dist/automations/tests/utilities/index.js +13 -11
- package/dist/automations/utils.js +187 -133
- package/dist/constants/index.js +5 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +2 -3
- package/dist/index.js +4 -0
- 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 +4 -0
- 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/redis.js +158 -0
- package/dist/integrations/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- package/dist/middleware/currentapp.js +15 -1
- package/dist/migrations/functions/appUrls.js +1 -1
- package/dist/migrations/functions/developerQuota.js +49 -0
- package/dist/migrations/functions/publishedAppsQuota.js +47 -0
- package/dist/migrations/functions/quotas1.js +6 -2
- package/dist/migrations/functions/usageQuotas/index.js +0 -4
- package/dist/migrations/functions/usageQuotas/syncApps.js +4 -7
- package/dist/migrations/functions/usageQuotas/syncDevelopers.js +24 -0
- package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +26 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +5 -8
- package/dist/migrations/index.js +17 -1
- package/dist/package.json +14 -8
- package/dist/threads/automation.js +149 -27
- package/dist/threads/index.js +36 -10
- package/dist/threads/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +6 -1
- package/nodemon.json +1 -1
- package/package.json +15 -9
- package/scripts/dev/manage.js +2 -0
- package/src/api/controllers/{application.js → application.ts} +118 -51
- package/src/api/controllers/deploy/{index.js → index.ts} +53 -29
- 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.js → index.ts} +51 -48
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/{index.js → index.ts} +24 -17
- package/src/api/controllers/row/internal.js +2 -1
- package/src/api/controllers/row/utils.js +4 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +3 -0
- package/src/api/controllers/table/bulkFormula.js +1 -1
- package/src/api/controllers/table/{internal.js → internal.ts} +30 -26
- package/src/api/controllers/table/{utils.js → utils.ts} +86 -69
- package/src/api/index.js +5 -0
- package/src/api/routes/{application.js → application.ts} +8 -14
- package/src/api/routes/index.ts +60 -0
- package/src/api/routes/public/index.ts +1 -4
- package/src/api/routes/{row.js → row.ts} +7 -15
- package/src/api/routes/{static.js → static.ts} +11 -11
- package/src/api/routes/tests/misc.spec.js +39 -37
- package/src/api/routes/tests/utilities/{TestFunctions.js → TestFunctions.ts} +57 -33
- package/src/app.ts +1 -2
- package/src/automations/actions.js +3 -0
- package/src/automations/automationUtils.js +12 -0
- package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
- package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
- package/src/automations/steps/loop.js +50 -0
- package/src/automations/tests/automation.spec.js +0 -1
- package/src/automations/tests/{createRow.spec.js → createRow.spec.ts} +4 -15
- package/src/automations/tests/{deleteRow.spec.js → deleteRow.spec.ts} +3 -5
- package/src/automations/tests/utilities/index.js +12 -10
- package/src/automations/{utils.js → utils.ts} +39 -28
- package/src/constants/index.js +6 -0
- package/src/definitions/common.ts +1 -0
- package/src/definitions/datasource.ts +1 -0
- package/src/environment.js +2 -3
- package/src/index.ts +3 -0
- package/src/integrations/index.ts +4 -0
- package/src/integrations/redis.ts +152 -0
- package/src/integrations/tests/redis.spec.js +60 -0
- package/src/middleware/{authorized.js → authorized.ts} +20 -14
- package/src/middleware/currentapp.js +16 -1
- package/src/middleware/tests/currentapp.spec.js +8 -4
- package/src/migrations/functions/developerQuota.ts +15 -0
- package/src/migrations/functions/publishedAppsQuota.ts +13 -0
- package/src/migrations/functions/tests/quotas1.spec.js +0 -2
- package/src/migrations/functions/usageQuotas/index.ts +0 -5
- package/src/migrations/functions/usageQuotas/syncApps.ts +3 -6
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +3 -6
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +34 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +40 -0
- package/src/migrations/index.ts +13 -1
- package/src/threads/automation.js +196 -34
- package/src/threads/{index.js → index.ts} +18 -14
- package/src/threads/utils.js +1 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -1
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +2 -2
- package/builder/assets/index.68a7f4e3.css +0 -6
- package/builder/assets/index.8d4a5b33.js +0 -1291
- package/coverage/lcov-report/api/controllers/application.js.html +0 -1436
- package/coverage/lcov-report/api/controllers/query/index.js.html +0 -713
- package/coverage/lcov-report/api/controllers/row/index.js.html +0 -524
- package/coverage/lcov-report/api/controllers/table/internal.js.html +0 -620
- package/coverage/lcov-report/api/controllers/table/utils.js.html +0 -1331
- package/coverage/lcov-report/api/routes/application.js.html +0 -179
- package/coverage/lcov-report/api/routes/index.js.html +0 -266
- package/coverage/lcov-report/api/routes/row.js.html +0 -908
- package/coverage/lcov-report/automations/steps/createRow.js.html +0 -380
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +0 -347
- package/coverage/lcov-report/automations/utils.js.html +0 -665
- package/coverage/lcov-report/middleware/authorized.js.html +0 -458
- package/coverage/lcov-report/middleware/usageQuota.js.html +0 -572
- package/coverage/lcov-report/threads/index.js.html +0 -296
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
- package/dist/middleware/usageQuota.js +0 -154
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/utilities/usageQuota/index.js +0 -86
- package/src/api/routes/index.js +0 -62
- package/src/middleware/tests/usageQuota.spec.js +0 -120
- package/src/middleware/usageQuota.js +0 -164
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -41
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -45
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -93
|
@@ -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 = fp_1.cloneDeep(id);
|
|
39
|
+
let idCopy = (0, 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 = utils_1.breakRowIdField(filter._id);
|
|
44
|
+
const parts = (0, 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 = utils_1.breakRowIdField(idCopy);
|
|
59
|
+
idCopy = (0, 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) && utils_1.isRowId(value)) {
|
|
94
|
-
obj[field] = utils_1.convertRowId(value);
|
|
93
|
+
if (fieldNames.find(name => name === field) && (0, utils_1.isRowId)(value)) {
|
|
94
|
+
obj[field] = (0, 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 utils_1.generateRowIdField(idParts);
|
|
132
|
+
return (0, 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 } = utils_3.breakExternalTableId(tableId);
|
|
138
|
+
const { datasourceId, tableName } = (0, 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 utils_4.processFormulas(table, thisRow);
|
|
158
|
+
return (0, 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 } = utils_3.breakExternalTableId(tableId);
|
|
192
|
+
const { tableName } = (0, 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 } = utils_3.breakExternalTableId(field === null || field === void 0 ? void 0 : field.tableId);
|
|
227
|
+
const { tableName: linkTableName } = (0, 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] = utils_1.breakRowIdField(row[key][0])[0];
|
|
237
|
+
newRow[field.foreignKey || linkTablePrimary] = (0, 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]: utils_1.breakRowIdField(relationship)[0],
|
|
249
|
+
[otherKey]: (0, 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]: utils_1.breakRowIdField(relationship)[0],
|
|
265
|
+
[thisKey]: (0, 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 utils_4.processFormulas(table, Object.values(finalRows)).map((row) => this.squashRelationshipColumns(table, row, relationships));
|
|
358
|
+
return (0, 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 } = utils_3.breakExternalTableId(field.tableId);
|
|
371
|
+
const { tableName: linkTableName } = (0, 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 } = utils_3.breakExternalTableId(field.through);
|
|
389
|
+
const { tableName: throughTableName } = (0, 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 } = utils_3.breakExternalTableId(tableId);
|
|
408
|
+
const { tableName } = (0, 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 } = utils_3.breakExternalTableId(tableId);
|
|
425
|
+
const { tableName: relatedTableName } = (0, 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 utils_2.getDatasourceAndQuery({
|
|
434
|
+
const response = yield (0, 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 = string_templates_1.processObjectSync(rest, row, {});
|
|
468
|
+
const body = (0, 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(utils_2.getDatasourceAndQuery({
|
|
482
|
+
promises.push((0, 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(utils_2.getDatasourceAndQuery({
|
|
510
|
+
promises.push((0, 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 } = utils_3.breakExternalTableId(field.tableId);
|
|
541
|
+
const { tableName: linkTableName } = (0, 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 } = utils_3.breakExternalTableId(tableId);
|
|
555
|
+
let { datasourceId, tableName } = (0, 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 = context_1.getAppDB();
|
|
560
|
+
const db = (0, 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 = utils_3.isSQL(this.datasource);
|
|
568
|
+
let isSql = (0, 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 utils_2.getDatasourceAndQuery(json);
|
|
607
|
+
const response = yield (0, 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,14 +8,20 @@ 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
|
-
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
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");
|
|
14
20
|
function pickApi(tableId) {
|
|
15
|
-
if (isExternalTable(tableId)) {
|
|
16
|
-
return
|
|
21
|
+
if ((0, utils_1.isExternalTable)(tableId)) {
|
|
22
|
+
return external_1.default;
|
|
17
23
|
}
|
|
18
|
-
return
|
|
24
|
+
return internal_1.default;
|
|
19
25
|
}
|
|
20
26
|
function getTableId(ctx) {
|
|
21
27
|
if (ctx.request.body && ctx.request.body.tableId) {
|
|
@@ -28,48 +34,55 @@ function getTableId(ctx) {
|
|
|
28
34
|
return ctx.params.viewName;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
function patch(ctx) {
|
|
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* () {
|
|
32
61
|
const appId = ctx.appId;
|
|
33
62
|
const tableId = getTableId(ctx);
|
|
34
63
|
const body = ctx.request.body;
|
|
35
|
-
// if it
|
|
36
|
-
if (body &&
|
|
37
|
-
return
|
|
64
|
+
// if it has an ID already then its a patch
|
|
65
|
+
if (body && body._id) {
|
|
66
|
+
return patch(ctx);
|
|
38
67
|
}
|
|
39
68
|
try {
|
|
40
|
-
const { row, table } = yield pickApi(tableId).
|
|
69
|
+
const { row, table } = yield pickApi(tableId).save(ctx);
|
|
41
70
|
ctx.status = 200;
|
|
42
|
-
ctx.eventEmitter &&
|
|
43
|
-
|
|
44
|
-
ctx.message = `${table.name} updated successfully.`;
|
|
71
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
|
|
72
|
+
ctx.message = `${table.name} saved successfully`;
|
|
45
73
|
ctx.body = row;
|
|
46
74
|
}
|
|
47
75
|
catch (err) {
|
|
48
76
|
ctx.throw(400, err);
|
|
49
77
|
}
|
|
50
78
|
});
|
|
51
|
-
|
|
79
|
+
function save(ctx) {
|
|
52
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
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
|
-
}
|
|
81
|
+
yield pro_1.quotas.addRow(() => saveRow(ctx));
|
|
70
82
|
});
|
|
71
|
-
}
|
|
72
|
-
exports.
|
|
83
|
+
}
|
|
84
|
+
exports.save = save;
|
|
85
|
+
function fetchView(ctx) {
|
|
73
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
87
|
const tableId = getTableId(ctx);
|
|
75
88
|
try {
|
|
@@ -79,8 +92,9 @@ exports.fetchView = function (ctx) {
|
|
|
79
92
|
ctx.throw(400, err);
|
|
80
93
|
}
|
|
81
94
|
});
|
|
82
|
-
}
|
|
83
|
-
exports.
|
|
95
|
+
}
|
|
96
|
+
exports.fetchView = fetchView;
|
|
97
|
+
function fetch(ctx) {
|
|
84
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
99
|
const tableId = getTableId(ctx);
|
|
86
100
|
try {
|
|
@@ -90,8 +104,9 @@ exports.fetch = function (ctx) {
|
|
|
90
104
|
ctx.throw(400, err);
|
|
91
105
|
}
|
|
92
106
|
});
|
|
93
|
-
}
|
|
94
|
-
exports.
|
|
107
|
+
}
|
|
108
|
+
exports.fetch = fetch;
|
|
109
|
+
function find(ctx) {
|
|
95
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
111
|
const tableId = getTableId(ctx);
|
|
97
112
|
try {
|
|
@@ -101,8 +116,9 @@ exports.find = function (ctx) {
|
|
|
101
116
|
ctx.throw(400, err);
|
|
102
117
|
}
|
|
103
118
|
});
|
|
104
|
-
}
|
|
105
|
-
exports.
|
|
119
|
+
}
|
|
120
|
+
exports.find = find;
|
|
121
|
+
function destroy(ctx) {
|
|
106
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
123
|
const appId = ctx.appId;
|
|
108
124
|
const inputs = ctx.request.body;
|
|
@@ -110,6 +126,7 @@ exports.destroy = function (ctx) {
|
|
|
110
126
|
let response, row;
|
|
111
127
|
if (inputs.rows) {
|
|
112
128
|
let { rows } = yield pickApi(tableId).bulkDestroy(ctx);
|
|
129
|
+
yield pro_1.quotas.removeRows(rows.length);
|
|
113
130
|
response = rows;
|
|
114
131
|
for (let row of rows) {
|
|
115
132
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
|
|
@@ -117,6 +134,7 @@ exports.destroy = function (ctx) {
|
|
|
117
134
|
}
|
|
118
135
|
else {
|
|
119
136
|
let resp = yield pickApi(tableId).destroy(ctx);
|
|
137
|
+
yield pro_1.quotas.removeRow();
|
|
120
138
|
response = resp.response;
|
|
121
139
|
row = resp.row;
|
|
122
140
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
|
|
@@ -126,47 +144,52 @@ exports.destroy = function (ctx) {
|
|
|
126
144
|
ctx.row = row || {};
|
|
127
145
|
ctx.body = response;
|
|
128
146
|
});
|
|
129
|
-
}
|
|
130
|
-
exports.
|
|
131
|
-
|
|
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) {
|
|
147
|
+
}
|
|
148
|
+
exports.destroy = destroy;
|
|
149
|
+
function search(ctx) {
|
|
141
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
151
|
const tableId = getTableId(ctx);
|
|
143
152
|
try {
|
|
144
|
-
ctx.
|
|
153
|
+
ctx.status = 200;
|
|
154
|
+
ctx.body = yield pickApi(tableId).search(ctx);
|
|
145
155
|
}
|
|
146
156
|
catch (err) {
|
|
147
157
|
ctx.throw(400, err);
|
|
148
158
|
}
|
|
149
159
|
});
|
|
150
|
-
}
|
|
151
|
-
exports.
|
|
160
|
+
}
|
|
161
|
+
exports.search = search;
|
|
162
|
+
function validate(ctx) {
|
|
152
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
164
|
const tableId = getTableId(ctx);
|
|
154
165
|
try {
|
|
155
|
-
ctx.body = yield pickApi(tableId).
|
|
166
|
+
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
156
167
|
}
|
|
157
168
|
catch (err) {
|
|
158
169
|
ctx.throw(400, err);
|
|
159
170
|
}
|
|
160
171
|
});
|
|
161
|
-
}
|
|
162
|
-
exports.
|
|
172
|
+
}
|
|
173
|
+
exports.validate = validate;
|
|
174
|
+
function fetchEnrichedRow(ctx) {
|
|
163
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
176
|
const tableId = getTableId(ctx);
|
|
165
177
|
try {
|
|
166
|
-
ctx.body = yield pickApi(tableId).
|
|
178
|
+
ctx.body = yield pickApi(tableId).fetchEnrichedRow(ctx);
|
|
167
179
|
}
|
|
168
180
|
catch (err) {
|
|
169
181
|
ctx.throw(400, err);
|
|
170
182
|
}
|
|
171
183
|
});
|
|
172
|
-
}
|
|
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;
|
|
@@ -243,8 +243,9 @@ 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
|
|
246
|
+
const { _id } = ctx.request.body;
|
|
247
247
|
let row = yield db.get(_id);
|
|
248
|
+
let _rev = ctx.request.body._rev || row._rev;
|
|
248
249
|
if (row.tableId !== ctx.params.tableId) {
|
|
249
250
|
throw "Supplied tableId doesn't match the row's tableId";
|
|
250
251
|
}
|
|
@@ -71,7 +71,8 @@ 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)
|
|
74
|
+
if (!constraints.inclusion.includes(val) &&
|
|
75
|
+
constraints.inclusion.length !== 0) {
|
|
75
76
|
errors[fieldName] = "Field not in list";
|
|
76
77
|
}
|
|
77
78
|
});
|
|
@@ -24,6 +24,7 @@ function isStaticFormula(column) {
|
|
|
24
24
|
* in the formula.
|
|
25
25
|
*/
|
|
26
26
|
function getFormulaThatUseColumn(table, columnNames) {
|
|
27
|
+
var _a;
|
|
27
28
|
let formula = [];
|
|
28
29
|
columnNames = Array.isArray(columnNames) ? columnNames : [columnNames];
|
|
29
30
|
for (let column of Object.values(table.schema)) {
|
|
@@ -31,7 +32,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
31
32
|
if (!isStaticFormula(column)) {
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
34
|
-
if (!doesContainStrings(column.formula, columnNames)) {
|
|
35
|
+
if (!doesContainStrings((_a = column === null || column === void 0 ? void 0 : column.formula) !== null && _a !== void 0 ? _a : "", columnNames)) {
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
37
38
|
formula.push(column.name);
|
|
@@ -19,15 +19,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.bulkImport = exports.destroy = exports.save = void 0;
|
|
24
|
+
const linkedRows_1 = require("../../../db/linkedRows");
|
|
25
|
+
const utils_1 = require("../../../db/utils");
|
|
26
|
+
const constants_1 = require("../../../constants");
|
|
27
|
+
const utils_2 = require("./utils");
|
|
27
28
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
29
|
+
const environment_1 = require("../../../environment");
|
|
30
|
+
const rowProcessor_1 = require("../../../utilities/rowProcessor");
|
|
31
|
+
const bulkFormula_1 = require("./bulkFormula");
|
|
32
|
+
const pro_1 = require("@budibase/pro");
|
|
31
33
|
function checkAutoColumns(table, oldTable) {
|
|
32
34
|
if (!table.schema) {
|
|
33
35
|
return table;
|
|
@@ -41,30 +43,30 @@ function checkAutoColumns(table, oldTable) {
|
|
|
41
43
|
table.schema[key].subtype = oldSchema.subtype;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
|
-
table.schema[key] = fixAutoColumnSubType(schema);
|
|
46
|
+
table.schema[key] = (0, rowProcessor_1.fixAutoColumnSubType)(schema);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
return table;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
function save(ctx) {
|
|
50
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
53
|
const db = getAppDB();
|
|
52
54
|
const _a = ctx.request.body, { dataImport } = _a, rest = __rest(_a, ["dataImport"]);
|
|
53
|
-
let tableToSave = Object.assign({ type: "table", _id: generateTableID(), views: {} }, rest);
|
|
55
|
+
let tableToSave = Object.assign({ type: "table", _id: (0, utils_1.generateTableID)(), views: {} }, rest);
|
|
54
56
|
// if the table obj had an _id then it will have been retrieved
|
|
55
57
|
let oldTable;
|
|
56
58
|
if (ctx.request.body && ctx.request.body._id) {
|
|
57
59
|
oldTable = yield db.get(ctx.request.body._id);
|
|
58
60
|
}
|
|
59
61
|
// check all types are correct
|
|
60
|
-
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
62
|
+
if ((0, utils_2.hasTypeChanged)(tableToSave, oldTable)) {
|
|
61
63
|
ctx.throw(400, "A column type has changed.");
|
|
62
64
|
}
|
|
63
65
|
// check that subtypes have been maintained
|
|
64
66
|
tableToSave = checkAutoColumns(tableToSave, oldTable);
|
|
65
67
|
// saving a table is a complex operation, involving many different steps, this
|
|
66
68
|
// has been broken out into a utility to make it more obvious/easier to manipulate
|
|
67
|
-
const tableSaveFunctions = new TableSaveFunctions({
|
|
69
|
+
const tableSaveFunctions = new utils_2.TableSaveFunctions({
|
|
68
70
|
user: ctx.user,
|
|
69
71
|
oldTable,
|
|
70
72
|
dataImport,
|
|
@@ -89,7 +91,7 @@ exports.save = function (ctx) {
|
|
|
89
91
|
}
|
|
90
92
|
// rename row fields when table column is renamed
|
|
91
93
|
/* istanbul ignore next */
|
|
92
|
-
if (_rename && tableToSave.schema[_rename.updated].type === FieldTypes.LINK) {
|
|
94
|
+
if (_rename && tableToSave.schema[_rename.updated].type === constants_1.FieldTypes.LINK) {
|
|
93
95
|
ctx.throw(400, "Cannot rename a linked column.");
|
|
94
96
|
}
|
|
95
97
|
tableToSave = yield tableSaveFunctions.mid(tableToSave);
|
|
@@ -104,10 +106,8 @@ exports.save = function (ctx) {
|
|
|
104
106
|
}
|
|
105
107
|
// update linked rows
|
|
106
108
|
try {
|
|
107
|
-
const linkResp = yield
|
|
108
|
-
eventType: oldTable
|
|
109
|
-
? linkRows.EventType.TABLE_UPDATED
|
|
110
|
-
: linkRows.EventType.TABLE_SAVE,
|
|
109
|
+
const linkResp = yield (0, linkedRows_1.updateLinks)({
|
|
110
|
+
eventType: oldTable ? linkedRows_1.EventType.TABLE_UPDATED : linkedRows_1.EventType.TABLE_SAVE,
|
|
111
111
|
table: tableToSave,
|
|
112
112
|
oldTable: oldTable,
|
|
113
113
|
});
|
|
@@ -128,46 +128,52 @@ exports.save = function (ctx) {
|
|
|
128
128
|
tableToSave._rev = result.rev;
|
|
129
129
|
tableToSave = yield tableSaveFunctions.after(tableToSave);
|
|
130
130
|
// has to run after, make sure it has _id
|
|
131
|
-
yield runStaticFormulaChecks(tableToSave, { oldTable });
|
|
131
|
+
yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToSave, { oldTable, deletion: null });
|
|
132
132
|
return tableToSave;
|
|
133
133
|
});
|
|
134
|
-
}
|
|
135
|
-
exports.
|
|
134
|
+
}
|
|
135
|
+
exports.save = save;
|
|
136
|
+
function destroy(ctx) {
|
|
136
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
138
|
const db = getAppDB();
|
|
138
139
|
const tableToDelete = yield db.get(ctx.params.tableId);
|
|
139
140
|
// Delete all rows for that table
|
|
140
|
-
const rows = yield db.allDocs(getRowParams(ctx.params.tableId, null, {
|
|
141
|
+
const rows = yield db.allDocs((0, utils_1.getRowParams)(ctx.params.tableId, null, {
|
|
141
142
|
include_docs: true,
|
|
142
143
|
}));
|
|
143
|
-
yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
144
|
-
yield
|
|
144
|
+
yield db.bulkDocs(rows.rows.map((row) => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
145
|
+
yield pro_1.quotas.removeRows(rows.rows.length);
|
|
145
146
|
// update linked rows
|
|
146
|
-
yield
|
|
147
|
-
eventType:
|
|
147
|
+
yield (0, linkedRows_1.updateLinks)({
|
|
148
|
+
eventType: linkedRows_1.EventType.TABLE_DELETE,
|
|
148
149
|
table: tableToDelete,
|
|
149
150
|
});
|
|
150
151
|
// don't remove the table itself until very end
|
|
151
152
|
yield db.remove(tableToDelete);
|
|
152
153
|
// remove table search index
|
|
153
|
-
if (!
|
|
154
|
+
if (!(0, environment_1.isTest)()) {
|
|
154
155
|
const currentIndexes = yield db.getIndexes();
|
|
155
|
-
const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
|
|
156
|
+
const existingIndex = currentIndexes.indexes.find((existing) => existing.name === `search:${ctx.params.tableId}`);
|
|
156
157
|
if (existingIndex) {
|
|
157
158
|
yield db.deleteIndex(existingIndex);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
// has to run after, make sure it has _id
|
|
161
|
-
yield runStaticFormulaChecks(tableToDelete, {
|
|
162
|
-
|
|
162
|
+
yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToDelete, {
|
|
163
|
+
oldTable: null,
|
|
164
|
+
deletion: true,
|
|
165
|
+
});
|
|
166
|
+
yield (0, rowProcessor_1.cleanupAttachments)(tableToDelete, { rows });
|
|
163
167
|
return tableToDelete;
|
|
164
168
|
});
|
|
165
|
-
}
|
|
166
|
-
exports.
|
|
169
|
+
}
|
|
170
|
+
exports.destroy = destroy;
|
|
171
|
+
function bulkImport(ctx) {
|
|
167
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
const table = yield getTable(ctx.params.tableId);
|
|
173
|
+
const table = yield (0, utils_2.getTable)(ctx.params.tableId);
|
|
169
174
|
const { dataImport } = ctx.request.body;
|
|
170
|
-
yield handleDataImport(ctx.user, table, dataImport);
|
|
175
|
+
yield (0, utils_2.handleDataImport)(ctx.user, table, dataImport);
|
|
171
176
|
return table;
|
|
172
177
|
});
|
|
173
|
-
}
|
|
178
|
+
}
|
|
179
|
+
exports.bulkImport = bulkImport;
|