@budibase/server 1.0.105-alpha.21 → 1.0.105-alpha.24
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.8d922c8c.js → index.06b1c616.js} +150 -147
- package/builder/assets/{index.b7e0672d.css → index.e3fb1cb4.css} +2 -2
- package/builder/index.html +2 -2
- package/coverage/clover.xml +517 -1564
- package/coverage/coverage-final.json +27 -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 +23 -33
- 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 +20 -15
- 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 +52 -47
- package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/index.html +17 -42
- 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 +9 -4
- package/coverage/lcov-report/automations/automationUtils.js.html +20 -15
- package/coverage/lcov-report/automations/bullboard.js.html +8 -3
- package/coverage/lcov-report/automations/index.html +16 -26
- 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 +16 -41
- package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
- package/coverage/lcov-report/automations/steps/loop.js.html +8 -3
- 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 +8 -3
- package/coverage/lcov-report/constants/index.js.html +35 -30
- 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/client.js.html +26 -21
- 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 +10 -5
- 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 +83 -78
- 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 +122 -117
- 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 +11 -6
- package/coverage/lcov-report/middleware/index.html +16 -41
- 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 +55 -50
- package/coverage/lcov-report/threads/index.html +16 -26
- package/coverage/lcov-report/threads/query.js.html +10 -5
- package/coverage/lcov-report/threads/utils.js.html +11 -6
- 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 +46 -41
- 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 +45 -40
- 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 +759 -2599
- package/dist/api/controllers/application.js +138 -70
- package/dist/api/controllers/deploy/index.js +64 -35
- 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/table/internal.js +40 -34
- 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 +62 -26
- package/dist/app.js +11 -4
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +13 -16
- package/dist/automations/tests/utilities/index.js +0 -2
- package/dist/automations/utils.js +187 -132
- package/dist/environment.js +0 -2
- 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/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/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- 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 +10 -8
- package/dist/threads/index.js +35 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +6 -1
- package/nodemon.json +1 -1
- package/package.json +11 -9
- package/scripts/dev/manage.js +2 -0
- package/src/api/controllers/{application.js → application.ts} +103 -44
- package/src/api/controllers/deploy/{index.js → index.ts} +45 -28
- 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/table/{internal.js → internal.ts} +27 -24
- 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/utilities/{TestFunctions.js → TestFunctions.ts} +42 -25
- package/src/app.ts +1 -2
- package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
- package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
- 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 +0 -2
- package/src/automations/{utils.js → utils.ts} +39 -27
- package/src/environment.js +0 -2
- package/src/middleware/{authorized.js → authorized.ts} +20 -14
- 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 +32 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +38 -0
- package/src/migrations/index.ts +13 -1
- package/src/module.d.ts +4 -0
- package/src/threads/{index.js → index.ts} +14 -12
- package/src/utilities/queue/inMemoryQueue.js +7 -1
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +0 -1430
- 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 -548
- 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/api/routes/static.js.html +0 -245
- 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 -662
- 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 -278
- 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 -134
- package/src/middleware/usageQuota.js +0 -164
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
- 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
|
});
|
|
@@ -344,7 +344,7 @@ var External;
|
|
|
344
344
|
// do this at end once its been added to the final rows
|
|
345
345
|
finalRows = this.updateRelationshipColumns(table, row, finalRows, relationships);
|
|
346
346
|
}
|
|
347
|
-
return utils_4.processFormulas(table, Object.values(finalRows));
|
|
347
|
+
return (0, utils_4.processFormulas)(table, Object.values(finalRows));
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
350
|
* Gets the list of relationship JSON structures based on the columns in the table,
|
|
@@ -357,7 +357,7 @@ var External;
|
|
|
357
357
|
if (field.type !== constants_1.FieldTypes.LINK) {
|
|
358
358
|
continue;
|
|
359
359
|
}
|
|
360
|
-
const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
|
|
360
|
+
const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
|
|
361
361
|
// no table to link to, this is not a valid relationships
|
|
362
362
|
if (!linkTableName || !this.tables[linkTableName]) {
|
|
363
363
|
continue;
|
|
@@ -375,7 +375,7 @@ var External;
|
|
|
375
375
|
column: fieldName,
|
|
376
376
|
};
|
|
377
377
|
if (field.through) {
|
|
378
|
-
const { tableName: throughTableName } = utils_3.breakExternalTableId(field.through);
|
|
378
|
+
const { tableName: throughTableName } = (0, utils_3.breakExternalTableId)(field.through);
|
|
379
379
|
definition.through = throughTableName;
|
|
380
380
|
// don't support composite keys for relationships
|
|
381
381
|
definition.from = field.throughTo || table.primary[0];
|
|
@@ -394,7 +394,7 @@ var External;
|
|
|
394
394
|
lookupRelations(tableId, row) {
|
|
395
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
396
|
const related = {};
|
|
397
|
-
const { tableName } = utils_3.breakExternalTableId(tableId);
|
|
397
|
+
const { tableName } = (0, utils_3.breakExternalTableId)(tableId);
|
|
398
398
|
if (!tableName) {
|
|
399
399
|
return related;
|
|
400
400
|
}
|
|
@@ -411,7 +411,7 @@ var External;
|
|
|
411
411
|
}
|
|
412
412
|
const isMany = field.relationshipType === constants_1.RelationshipTypes.MANY_TO_MANY;
|
|
413
413
|
const tableId = isMany ? field.through : field.tableId;
|
|
414
|
-
const { tableName: relatedTableName } = utils_3.breakExternalTableId(tableId);
|
|
414
|
+
const { tableName: relatedTableName } = (0, utils_3.breakExternalTableId)(tableId);
|
|
415
415
|
// @ts-ignore
|
|
416
416
|
const linkPrimaryKey = this.tables[relatedTableName].primary[0];
|
|
417
417
|
const manyKey = field.throughTo || primaryKey;
|
|
@@ -420,7 +420,7 @@ var External;
|
|
|
420
420
|
if (!lookupField || !row[lookupField]) {
|
|
421
421
|
continue;
|
|
422
422
|
}
|
|
423
|
-
const response = yield utils_2.getDatasourceAndQuery({
|
|
423
|
+
const response = yield (0, utils_2.getDatasourceAndQuery)({
|
|
424
424
|
endpoint: getEndpoint(tableId, constants_1.DataSourceOperation.READ),
|
|
425
425
|
filters: {
|
|
426
426
|
equal: {
|
|
@@ -454,7 +454,7 @@ var External;
|
|
|
454
454
|
const related = yield this.lookupRelations(mainTableId, row);
|
|
455
455
|
for (let relationship of relationships) {
|
|
456
456
|
const { key, tableId, isUpdate, id } = relationship, rest = __rest(relationship, ["key", "tableId", "isUpdate", "id"]);
|
|
457
|
-
const body = string_templates_1.processObjectSync(rest, row, {});
|
|
457
|
+
const body = (0, string_templates_1.processObjectSync)(rest, row, {});
|
|
458
458
|
const linkTable = this.getTable(tableId);
|
|
459
459
|
// @ts-ignore
|
|
460
460
|
const linkPrimary = linkTable === null || linkTable === void 0 ? void 0 : linkTable.primary[0];
|
|
@@ -468,7 +468,7 @@ var External;
|
|
|
468
468
|
? constants_1.DataSourceOperation.UPDATE
|
|
469
469
|
: constants_1.DataSourceOperation.CREATE;
|
|
470
470
|
if (!found) {
|
|
471
|
-
promises.push(utils_2.getDatasourceAndQuery({
|
|
471
|
+
promises.push((0, utils_2.getDatasourceAndQuery)({
|
|
472
472
|
endpoint: getEndpoint(tableId, operation),
|
|
473
473
|
// if we're doing many relationships then we're writing, only one response
|
|
474
474
|
body,
|
|
@@ -496,7 +496,7 @@ var External;
|
|
|
496
496
|
? constants_1.DataSourceOperation.DELETE
|
|
497
497
|
: constants_1.DataSourceOperation.UPDATE;
|
|
498
498
|
const body = isMany ? null : { [colName]: null };
|
|
499
|
-
promises.push(utils_2.getDatasourceAndQuery({
|
|
499
|
+
promises.push((0, utils_2.getDatasourceAndQuery)({
|
|
500
500
|
endpoint: getEndpoint(tableId, op),
|
|
501
501
|
body,
|
|
502
502
|
filters,
|
|
@@ -527,7 +527,7 @@ var External;
|
|
|
527
527
|
if (field.type !== constants_1.FieldTypes.LINK || !includeRelations) {
|
|
528
528
|
continue;
|
|
529
529
|
}
|
|
530
|
-
const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
|
|
530
|
+
const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
|
|
531
531
|
if (linkTableName) {
|
|
532
532
|
const linkTable = this.tables[linkTableName];
|
|
533
533
|
if (linkTable) {
|
|
@@ -541,12 +541,12 @@ var External;
|
|
|
541
541
|
run(config) {
|
|
542
542
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
543
|
const { operation, tableId } = this;
|
|
544
|
-
let { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
|
|
544
|
+
let { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
|
|
545
545
|
if (!tableName) {
|
|
546
546
|
throw "Unable to run without a table name";
|
|
547
547
|
}
|
|
548
548
|
if (!this.datasource) {
|
|
549
|
-
const db = context_1.getAppDB();
|
|
549
|
+
const db = (0, context_1.getAppDB)();
|
|
550
550
|
this.datasource = yield db.get(datasourceId);
|
|
551
551
|
if (!this.datasource || !this.datasource.entities) {
|
|
552
552
|
throw "No tables found, fetch tables before query.";
|
|
@@ -554,7 +554,7 @@ var External;
|
|
|
554
554
|
this.tables = this.datasource.entities;
|
|
555
555
|
}
|
|
556
556
|
const table = this.tables[tableName];
|
|
557
|
-
let isSql = utils_3.isSQL(this.datasource);
|
|
557
|
+
let isSql = (0, utils_3.isSQL)(this.datasource);
|
|
558
558
|
if (!table) {
|
|
559
559
|
throw `Unable to process query, table "${tableName}" not defined.`;
|
|
560
560
|
}
|
|
@@ -593,7 +593,7 @@ var External;
|
|
|
593
593
|
},
|
|
594
594
|
};
|
|
595
595
|
// can't really use response right now
|
|
596
|
-
const response = yield utils_2.getDatasourceAndQuery(json);
|
|
596
|
+
const response = yield (0, utils_2.getDatasourceAndQuery)(json);
|
|
597
597
|
// handle many to many relationships now if we know the ID (could be auto increment)
|
|
598
598
|
if (operation !== constants_1.DataSourceOperation.READ &&
|
|
599
599
|
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;
|
|
@@ -242,8 +242,9 @@ exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
242
242
|
exports.destroy = function (ctx) {
|
|
243
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
244
244
|
const db = getAppDB();
|
|
245
|
-
const { _id
|
|
245
|
+
const { _id } = ctx.request.body;
|
|
246
246
|
let row = yield db.get(_id);
|
|
247
|
+
let _rev = ctx.request.body._rev || row._rev;
|
|
247
248
|
if (row.tableId !== ctx.params.tableId) {
|
|
248
249
|
throw "Supplied tableId doesn't match the row's tableId";
|
|
249
250
|
}
|
|
@@ -19,31 +19,33 @@ 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
|
|
31
|
-
|
|
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");
|
|
33
|
+
function save(ctx) {
|
|
32
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
35
|
const db = getAppDB();
|
|
34
36
|
const _a = ctx.request.body, { dataImport } = _a, rest = __rest(_a, ["dataImport"]);
|
|
35
|
-
let tableToSave = Object.assign({ type: "table", _id: generateTableID(), views: {} }, rest);
|
|
37
|
+
let tableToSave = Object.assign({ type: "table", _id: (0, utils_1.generateTableID)(), views: {} }, rest);
|
|
36
38
|
// if the table obj had an _id then it will have been retrieved
|
|
37
39
|
let oldTable;
|
|
38
40
|
if (ctx.request.body && ctx.request.body._id) {
|
|
39
41
|
oldTable = yield db.get(ctx.request.body._id);
|
|
40
42
|
}
|
|
41
|
-
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
43
|
+
if ((0, utils_2.hasTypeChanged)(tableToSave, oldTable)) {
|
|
42
44
|
ctx.throw(400, "A column type has changed.");
|
|
43
45
|
}
|
|
44
46
|
// saving a table is a complex operation, involving many different steps, this
|
|
45
47
|
// has been broken out into a utility to make it more obvious/easier to manipulate
|
|
46
|
-
const tableSaveFunctions = new TableSaveFunctions({
|
|
48
|
+
const tableSaveFunctions = new utils_2.TableSaveFunctions({
|
|
47
49
|
user: ctx.user,
|
|
48
50
|
oldTable,
|
|
49
51
|
dataImport,
|
|
@@ -68,7 +70,7 @@ exports.save = function (ctx) {
|
|
|
68
70
|
}
|
|
69
71
|
// rename row fields when table column is renamed
|
|
70
72
|
/* istanbul ignore next */
|
|
71
|
-
if (_rename && tableToSave.schema[_rename.updated].type === FieldTypes.LINK) {
|
|
73
|
+
if (_rename && tableToSave.schema[_rename.updated].type === constants_1.FieldTypes.LINK) {
|
|
72
74
|
ctx.throw(400, "Cannot rename a linked column.");
|
|
73
75
|
}
|
|
74
76
|
tableToSave = yield tableSaveFunctions.mid(tableToSave);
|
|
@@ -83,10 +85,8 @@ exports.save = function (ctx) {
|
|
|
83
85
|
}
|
|
84
86
|
// update linked rows
|
|
85
87
|
try {
|
|
86
|
-
const linkResp = yield
|
|
87
|
-
eventType: oldTable
|
|
88
|
-
? linkRows.EventType.TABLE_UPDATED
|
|
89
|
-
: linkRows.EventType.TABLE_SAVE,
|
|
88
|
+
const linkResp = yield (0, linkedRows_1.updateLinks)({
|
|
89
|
+
eventType: oldTable ? linkedRows_1.EventType.TABLE_UPDATED : linkedRows_1.EventType.TABLE_SAVE,
|
|
90
90
|
table: tableToSave,
|
|
91
91
|
oldTable: oldTable,
|
|
92
92
|
});
|
|
@@ -107,46 +107,52 @@ exports.save = function (ctx) {
|
|
|
107
107
|
tableToSave._rev = result.rev;
|
|
108
108
|
tableToSave = yield tableSaveFunctions.after(tableToSave);
|
|
109
109
|
// has to run after, make sure it has _id
|
|
110
|
-
yield runStaticFormulaChecks(tableToSave, { oldTable });
|
|
110
|
+
yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToSave, { oldTable, deletion: null });
|
|
111
111
|
return tableToSave;
|
|
112
112
|
});
|
|
113
|
-
}
|
|
114
|
-
exports.
|
|
113
|
+
}
|
|
114
|
+
exports.save = save;
|
|
115
|
+
function destroy(ctx) {
|
|
115
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
117
|
const db = getAppDB();
|
|
117
118
|
const tableToDelete = yield db.get(ctx.params.tableId);
|
|
118
119
|
// Delete all rows for that table
|
|
119
|
-
const rows = yield db.allDocs(getRowParams(ctx.params.tableId, null, {
|
|
120
|
+
const rows = yield db.allDocs((0, utils_1.getRowParams)(ctx.params.tableId, null, {
|
|
120
121
|
include_docs: true,
|
|
121
122
|
}));
|
|
122
|
-
yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
123
|
-
yield
|
|
123
|
+
yield db.bulkDocs(rows.rows.map((row) => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
124
|
+
yield pro_1.quotas.removeRows(rows.rows.length);
|
|
124
125
|
// update linked rows
|
|
125
|
-
yield
|
|
126
|
-
eventType:
|
|
126
|
+
yield (0, linkedRows_1.updateLinks)({
|
|
127
|
+
eventType: linkedRows_1.EventType.TABLE_DELETE,
|
|
127
128
|
table: tableToDelete,
|
|
128
129
|
});
|
|
129
130
|
// don't remove the table itself until very end
|
|
130
131
|
yield db.remove(tableToDelete);
|
|
131
132
|
// remove table search index
|
|
132
|
-
if (!
|
|
133
|
+
if (!(0, environment_1.isTest)()) {
|
|
133
134
|
const currentIndexes = yield db.getIndexes();
|
|
134
|
-
const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
|
|
135
|
+
const existingIndex = currentIndexes.indexes.find((existing) => existing.name === `search:${ctx.params.tableId}`);
|
|
135
136
|
if (existingIndex) {
|
|
136
137
|
yield db.deleteIndex(existingIndex);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
// has to run after, make sure it has _id
|
|
140
|
-
yield runStaticFormulaChecks(tableToDelete, {
|
|
141
|
-
|
|
141
|
+
yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToDelete, {
|
|
142
|
+
oldTable: null,
|
|
143
|
+
deletion: true,
|
|
144
|
+
});
|
|
145
|
+
yield (0, rowProcessor_1.cleanupAttachments)(tableToDelete, { rows });
|
|
142
146
|
return tableToDelete;
|
|
143
147
|
});
|
|
144
|
-
}
|
|
145
|
-
exports.
|
|
148
|
+
}
|
|
149
|
+
exports.destroy = destroy;
|
|
150
|
+
function bulkImport(ctx) {
|
|
146
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const table = yield getTable(ctx.params.tableId);
|
|
152
|
+
const table = yield (0, utils_2.getTable)(ctx.params.tableId);
|
|
148
153
|
const { dataImport } = ctx.request.body;
|
|
149
|
-
yield handleDataImport(ctx.user, table, dataImport);
|
|
154
|
+
yield (0, utils_2.handleDataImport)(ctx.user, table, dataImport);
|
|
150
155
|
return table;
|
|
151
156
|
});
|
|
152
|
-
}
|
|
157
|
+
}
|
|
158
|
+
exports.bulkImport = bulkImport;
|