@budibase/server 1.0.46 → 1.0.49-alpha.1
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.ba78c49d.css +1 -0
- package/builder/assets/{index.e9bff1c6.js → index.ed1cf508.js} +237 -234
- package/builder/assets/{vendor.f9faf6ab.js → vendor.d526bfe8.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2368 -2016
- package/coverage/coverage-final.json +101 -95
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +210 -126
- package/coverage/lcov-report/api/controllers/auth.js.html +18 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +72 -36
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +38 -53
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
- package/coverage/lcov-report/api/controllers/row/index.html +48 -33
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +95 -158
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +41 -17
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +551 -0
- package/coverage/lcov-report/api/controllers/row/utils.js.html +39 -57
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +629 -0
- package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
- package/coverage/lcov-report/api/controllers/table/index.html +49 -34
- package/coverage/lcov-report/api/controllers/table/index.js.html +53 -77
- package/coverage/lcov-report/api/controllers/table/internal.js.html +59 -35
- package/coverage/lcov-report/api/controllers/table/utils.js.html +283 -76
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +30 -24
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +10 -10
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +7 -22
- package/coverage/lcov-report/api/routes/index.js.html +4 -10
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +17 -2
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +13 -19
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +13 -13
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +18 -18
- package/coverage/lcov-report/automations/utils.js.html +32 -32
- package/coverage/lcov-report/constants/index.html +11 -11
- package/coverage/lcov-report/constants/index.js.html +68 -32
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +18 -18
- package/coverage/lcov-report/db/linkedRows/index.html +10 -10
- package/coverage/lcov-report/db/linkedRows/index.js.html +38 -41
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +86 -86
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +131 -101
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +166 -64
- package/coverage/lcov-report/middleware/builder.js.html +8 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +29 -29
- package/coverage/lcov-report/middleware/index.html +30 -30
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +275 -41
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/migrations/usageQuotas/index.html +141 -0
- package/coverage/lcov-report/migrations/usageQuotas/index.js.html +152 -0
- package/coverage/lcov-report/{api/routes/hosting.js.html → migrations/usageQuotas/syncApps.js.html} +42 -27
- package/coverage/lcov-report/{api/controllers/hosting.js.html → migrations/usageQuotas/syncRows.js.html} +41 -44
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +15 -15
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +23 -8
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +26 -26
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +25 -25
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +115 -79
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +141 -0
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +356 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +302 -0
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +134 -0
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +39 -108
- package/coverage/lcov.info +3719 -3046
- package/dist/api/controllers/application.js +49 -20
- package/dist/api/controllers/auth.js +4 -0
- package/dist/api/controllers/datasource.js +11 -0
- package/dist/api/controllers/row/ExternalRequest.js +2 -1
- package/dist/api/controllers/row/internal.js +30 -53
- package/dist/api/controllers/row/internalSearch.js +12 -4
- package/dist/api/controllers/row/staticFormula.js +147 -0
- package/dist/api/controllers/row/utils.js +6 -8
- package/dist/api/controllers/static/index.js +59 -10
- package/dist/api/controllers/table/bulkFormula.js +160 -0
- package/dist/api/controllers/table/index.js +12 -9
- package/dist/api/controllers/table/internal.js +9 -0
- package/dist/api/controllers/table/utils.js +56 -14
- package/dist/api/controllers/user.js +2 -0
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/static.js +2 -1
- package/dist/automations/steps/createRow.js +2 -4
- package/dist/automations/steps/deleteRow.js +1 -4
- package/dist/constants/index.js +12 -5
- package/dist/db/linkedRows/index.js +4 -5
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/base/sql.js +13 -6
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +57 -8
- package/dist/middleware/authorized.js +55 -30
- package/dist/middleware/usageQuota.js +82 -13
- package/dist/migrations/usageQuotas/index.js +24 -0
- package/dist/migrations/usageQuotas/syncApps.js +26 -0
- package/dist/migrations/usageQuotas/syncRows.js +29 -0
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +10 -6
- package/dist/threads/query.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/rowProcessor/index.js +18 -11
- package/dist/utilities/rowProcessor/utils.js +14 -4
- package/dist/utilities/{usageQuota.js → usageQuota/index.js} +44 -31
- package/dist/utilities/usageQuota/rows.js +77 -0
- package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
- package/dist/utilities/workerRequests.js +0 -20
- package/nodemon.json +1 -1
- package/package.json +9 -6
- package/src/api/controllers/application.js +52 -24
- package/src/api/controllers/auth.js +4 -0
- package/src/api/controllers/datasource.js +12 -0
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/internal.js +29 -50
- package/src/api/controllers/row/internalSearch.js +12 -4
- package/src/api/controllers/row/staticFormula.js +157 -0
- package/src/api/controllers/row/utils.js +6 -12
- package/src/api/controllers/static/index.js +63 -10
- package/src/api/controllers/table/bulkFormula.js +183 -0
- package/src/api/controllers/table/index.js +16 -24
- package/src/api/controllers/table/internal.js +9 -1
- package/src/api/controllers/table/utils.js +80 -11
- package/src/api/controllers/user.js +2 -0
- package/src/api/routes/index.js +0 -2
- package/src/api/routes/static.js +5 -0
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/api/routes/tests/static.spec.js +98 -0
- package/src/automations/steps/createRow.js +2 -4
- package/src/automations/steps/deleteRow.js +1 -4
- package/src/constants/index.js +17 -5
- package/src/db/linkedRows/index.js +4 -5
- package/src/definitions/common.ts +3 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/environment.js +1 -0
- package/src/integrations/base/sql.ts +14 -7
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/tests/sql.spec.js +16 -0
- package/src/integrations/utils.ts +71 -10
- package/src/middleware/authorized.js +64 -30
- package/src/middleware/tests/authorized.spec.js +6 -4
- package/src/middleware/tests/usageQuota.spec.js +18 -24
- package/src/middleware/usageQuota.js +93 -15
- package/src/migrations/tests/usageQuotas/index.spec.js +27 -0
- package/src/migrations/tests/usageQuotas/syncApps.spec.js +37 -0
- package/src/migrations/tests/usageQuotas/syncRows.spec.js +43 -0
- package/src/migrations/usageQuotas/index.js +24 -0
- package/src/migrations/usageQuotas/syncApps.js +18 -0
- package/src/migrations/usageQuotas/syncRows.js +21 -0
- package/src/tests/utilities/TestConfiguration.js +10 -6
- package/src/threads/query.js +5 -0
- package/src/utilities/rowProcessor/index.js +24 -12
- package/src/utilities/rowProcessor/utils.js +23 -7
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +92 -0
- package/src/utilities/usageQuota/rows.js +74 -0
- package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
- package/src/utilities/workerRequests.js +0 -23
- package/builder/assets/index.39e01193.css +0 -1
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- package/src/api/routes/tests/hosting.spec.js +0 -36
- package/src/utilities/usageQuota.js +0 -73
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const CouchDB = require("../../../db");
|
|
12
|
+
const { FieldTypes, FormulaTypes } = require("../../../constants");
|
|
13
|
+
const { getAllInternalTables, clearColumns } = require("./utils");
|
|
14
|
+
const { doesContainStrings } = require("@budibase/string-templates");
|
|
15
|
+
const { cloneDeep } = require("lodash/fp");
|
|
16
|
+
const { isEqual, uniq } = require("lodash");
|
|
17
|
+
const { updateAllFormulasInTable } = require("../row/staticFormula");
|
|
18
|
+
function isStaticFormula(column) {
|
|
19
|
+
return (column.type === FieldTypes.FORMULA &&
|
|
20
|
+
column.formulaType === FormulaTypes.STATIC);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This retrieves the formula columns from a table schema that use a specified column name
|
|
24
|
+
* in the formula.
|
|
25
|
+
*/
|
|
26
|
+
function getFormulaThatUseColumn(table, columnNames) {
|
|
27
|
+
let formula = [];
|
|
28
|
+
columnNames = Array.isArray(columnNames) ? columnNames : [columnNames];
|
|
29
|
+
for (let column of Object.values(table.schema)) {
|
|
30
|
+
// not a static formula, or doesn't contain a relationship
|
|
31
|
+
if (!isStaticFormula(column)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (!doesContainStrings(column.formula, columnNames)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
formula.push(column.name);
|
|
38
|
+
}
|
|
39
|
+
return formula;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This functions checks for when a related table, column or related column is deleted, if any
|
|
43
|
+
* tables need to have the formula column removed.
|
|
44
|
+
*/
|
|
45
|
+
function checkIfFormulaNeedsCleared(appId, table, { oldTable, deletion }) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const db = new CouchDB(appId);
|
|
48
|
+
// start by retrieving all tables, remove the current table from the list
|
|
49
|
+
const tables = (yield getAllInternalTables(appId)).filter(tbl => tbl._id !== table._id);
|
|
50
|
+
const schemaToUse = oldTable ? oldTable.schema : table.schema;
|
|
51
|
+
let removedColumns = Object.values(schemaToUse).filter(column => deletion || !table.schema[column.name]);
|
|
52
|
+
// remove any formula columns that used related columns
|
|
53
|
+
for (let removed of removedColumns) {
|
|
54
|
+
let tableToUse = table;
|
|
55
|
+
// if relationship, get the related table
|
|
56
|
+
if (removed.type === FieldTypes.LINK) {
|
|
57
|
+
tableToUse = tables.find(table => table._id === removed.tableId);
|
|
58
|
+
}
|
|
59
|
+
const columnsToDelete = getFormulaThatUseColumn(tableToUse, removed.name);
|
|
60
|
+
if (columnsToDelete.length > 0) {
|
|
61
|
+
yield clearColumns(db, table, columnsToDelete);
|
|
62
|
+
}
|
|
63
|
+
// need a special case, where a column has been removed from this table, but was used
|
|
64
|
+
// in a different, related tables formula
|
|
65
|
+
if (!table.relatedFormula) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (let relatedTableId of table.relatedFormula) {
|
|
69
|
+
const relatedColumns = Object.values(table.schema).filter(column => column.tableId === relatedTableId);
|
|
70
|
+
const relatedTable = tables.find(table => table._id === relatedTableId);
|
|
71
|
+
// look to see if the column was used in a relationship formula,
|
|
72
|
+
// relationships won't be used for this
|
|
73
|
+
if (relatedTable && relatedColumns && removed.type !== FieldTypes.LINK) {
|
|
74
|
+
let relatedFormulaToRemove = [];
|
|
75
|
+
for (let column of relatedColumns) {
|
|
76
|
+
relatedFormulaToRemove = relatedFormulaToRemove.concat(getFormulaThatUseColumn(relatedTable, [
|
|
77
|
+
column.fieldName,
|
|
78
|
+
removed.name,
|
|
79
|
+
]));
|
|
80
|
+
}
|
|
81
|
+
if (relatedFormulaToRemove.length > 0) {
|
|
82
|
+
yield clearColumns(db, relatedTable, uniq(relatedFormulaToRemove));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* This function adds a note to related tables that they are
|
|
91
|
+
* used in a static formula - so that the link controller
|
|
92
|
+
* can manage hydrating related rows formula fields. This is
|
|
93
|
+
* specifically only for static formula.
|
|
94
|
+
*/
|
|
95
|
+
function updateRelatedFormulaLinksOnTables(appId, table, { deletion } = { deletion: false }) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const db = new CouchDB(appId);
|
|
98
|
+
// start by retrieving all tables, remove the current table from the list
|
|
99
|
+
const tables = (yield getAllInternalTables(appId)).filter(tbl => tbl._id !== table._id);
|
|
100
|
+
// clone the tables, so we can compare at end
|
|
101
|
+
const initialTables = cloneDeep(tables);
|
|
102
|
+
// first find the related column names
|
|
103
|
+
const relatedColumns = Object.values(table.schema).filter(col => col.type === FieldTypes.LINK);
|
|
104
|
+
// we start by removing the formula field from all tables
|
|
105
|
+
for (let otherTable of tables) {
|
|
106
|
+
if (!otherTable.relatedFormula) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const index = otherTable.relatedFormula.indexOf(table._id);
|
|
110
|
+
if (index !== -1) {
|
|
111
|
+
otherTable.relatedFormula.splice(index, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// if deleting, just remove the table IDs, don't try add
|
|
115
|
+
if (!deletion) {
|
|
116
|
+
for (let relatedCol of relatedColumns) {
|
|
117
|
+
let columns = getFormulaThatUseColumn(table, relatedCol.name);
|
|
118
|
+
if (!columns || columns.length === 0) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const relatedTable = tables.find(related => related._id === relatedCol.tableId);
|
|
122
|
+
// check if the table is already in the list of related formula, if it isn't, then add it
|
|
123
|
+
if (relatedTable &&
|
|
124
|
+
(!relatedTable.relatedFormula ||
|
|
125
|
+
!relatedTable.relatedFormula.includes(table._id))) {
|
|
126
|
+
relatedTable.relatedFormula = relatedTable.relatedFormula
|
|
127
|
+
? [...relatedTable.relatedFormula, table._id]
|
|
128
|
+
: [table._id];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// now we just need to compare all the tables and see if any need saved
|
|
133
|
+
for (let initial of initialTables) {
|
|
134
|
+
const found = tables.find(tbl => initial._id === tbl._id);
|
|
135
|
+
if (found && !isEqual(initial, found)) {
|
|
136
|
+
yield db.put(found);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function checkIfFormulaUpdated(appId, table, { oldTable }) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
// look to see if any formula values have changed
|
|
144
|
+
const shouldUpdate = Object.values(table.schema).find(column => isStaticFormula(column) &&
|
|
145
|
+
(!oldTable ||
|
|
146
|
+
!oldTable.schema[column.name] ||
|
|
147
|
+
!isEqual(oldTable.schema[column.name], column)));
|
|
148
|
+
// if a static formula column has updated, then need to run the update
|
|
149
|
+
if (shouldUpdate != null) {
|
|
150
|
+
yield updateAllFormulasInTable(appId, table);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
exports.runStaticFormulaChecks = (appId, table, { oldTable, deletion }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
yield updateRelatedFormulaLinksOnTables(appId, table, { deletion });
|
|
156
|
+
yield checkIfFormulaNeedsCleared(appId, table, { oldTable, deletion });
|
|
157
|
+
if (!deletion) {
|
|
158
|
+
yield checkIfFormulaUpdated(appId, table, { oldTable });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
@@ -12,9 +12,9 @@ const CouchDB = require("../../../db");
|
|
|
12
12
|
const internal = require("./internal");
|
|
13
13
|
const external = require("./external");
|
|
14
14
|
const csvParser = require("../../../utilities/csvParser");
|
|
15
|
-
const { isExternalTable } = require("../../../integrations/utils");
|
|
16
|
-
const {
|
|
17
|
-
const { getTable } = require("./utils");
|
|
15
|
+
const { isExternalTable, isSQL } = require("../../../integrations/utils");
|
|
16
|
+
const { getDatasourceParams } = require("../../../db/utils");
|
|
17
|
+
const { getTable, getAllInternalTables } = require("./utils");
|
|
18
18
|
function pickApi({ tableId, table }) {
|
|
19
19
|
if (table && !tableId) {
|
|
20
20
|
tableId = table._id;
|
|
@@ -31,15 +31,18 @@ function pickApi({ tableId, table }) {
|
|
|
31
31
|
exports.fetch = function (ctx) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
33
|
const db = new CouchDB(ctx.appId);
|
|
34
|
-
const
|
|
35
|
-
include_docs: true,
|
|
36
|
-
}));
|
|
37
|
-
const internal = internalTables.rows.map(row => (Object.assign(Object.assign({}, row.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
|
|
34
|
+
const internal = yield getAllInternalTables(ctx.appId);
|
|
38
35
|
const externalTables = yield db.allDocs(getDatasourceParams("plus", {
|
|
39
36
|
include_docs: true,
|
|
40
37
|
}));
|
|
41
|
-
const external = externalTables.rows.flatMap(
|
|
42
|
-
|
|
38
|
+
const external = externalTables.rows.flatMap(tableDoc => {
|
|
39
|
+
let entities = tableDoc.doc.entities;
|
|
40
|
+
if (entities) {
|
|
41
|
+
return Object.values(entities).map(entity => (Object.assign(Object.assign({}, entity), { type: "external", sourceId: tableDoc.doc._id, sql: isSQL(tableDoc.doc) })));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
43
46
|
});
|
|
44
47
|
ctx.body = [...internal, ...external];
|
|
45
48
|
});
|
|
@@ -24,6 +24,9 @@ const linkRows = require("../../../db/linkedRows");
|
|
|
24
24
|
const { getRowParams, generateTableID } = require("../../../db/utils");
|
|
25
25
|
const { FieldTypes } = require("../../../constants");
|
|
26
26
|
const { TableSaveFunctions, hasTypeChanged, getTable, handleDataImport, } = require("./utils");
|
|
27
|
+
const usageQuota = require("../../../utilities/usageQuota");
|
|
28
|
+
const { cleanupAttachments } = require("../../../utilities/rowProcessor");
|
|
29
|
+
const { runStaticFormulaChecks } = require("./bulkFormula");
|
|
27
30
|
exports.save = function (ctx) {
|
|
28
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
32
|
const appId = ctx.appId;
|
|
@@ -105,6 +108,8 @@ exports.save = function (ctx) {
|
|
|
105
108
|
const result = yield db.put(tableToSave);
|
|
106
109
|
tableToSave._rev = result.rev;
|
|
107
110
|
tableToSave = yield tableSaveFunctions.after(tableToSave);
|
|
111
|
+
// has to run after, make sure it has _id
|
|
112
|
+
yield runStaticFormulaChecks(appId, tableToSave, { oldTable });
|
|
108
113
|
return tableToSave;
|
|
109
114
|
});
|
|
110
115
|
};
|
|
@@ -118,6 +123,7 @@ exports.destroy = function (ctx) {
|
|
|
118
123
|
include_docs: true,
|
|
119
124
|
}));
|
|
120
125
|
yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
126
|
+
yield usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length);
|
|
121
127
|
// update linked rows
|
|
122
128
|
yield linkRows.updateLinks({
|
|
123
129
|
appId,
|
|
@@ -132,6 +138,9 @@ exports.destroy = function (ctx) {
|
|
|
132
138
|
if (existingIndex) {
|
|
133
139
|
yield db.deleteIndex(existingIndex);
|
|
134
140
|
}
|
|
141
|
+
// has to run after, make sure it has _id
|
|
142
|
+
yield runStaticFormulaChecks(appId, tableToDelete, { deletion: true });
|
|
143
|
+
yield cleanupAttachments(appId, tableToDelete, { rows });
|
|
135
144
|
return tableToDelete;
|
|
136
145
|
});
|
|
137
146
|
};
|
|
@@ -10,15 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../../db");
|
|
12
12
|
const csvParser = require("../../../utilities/csvParser");
|
|
13
|
-
const { getRowParams, generateRowID, InternalTables, } = require("../../../db/utils");
|
|
14
|
-
const { isEqual } = require("lodash
|
|
13
|
+
const { getRowParams, generateRowID, InternalTables, getTableParams, BudibaseInternalDB, } = require("../../../db/utils");
|
|
14
|
+
const { isEqual } = require("lodash");
|
|
15
15
|
const { AutoFieldSubTypes, FieldTypes } = require("../../../constants");
|
|
16
|
-
const { inputProcessing } = require("../../../utilities/rowProcessor");
|
|
17
|
-
const { USERS_TABLE_SCHEMA, SwitchableTypes } = require("../../../constants");
|
|
18
|
-
const { isExternalTable, breakExternalTableId, } = require("../../../integrations/utils");
|
|
16
|
+
const { inputProcessing, cleanupAttachments, } = require("../../../utilities/rowProcessor");
|
|
17
|
+
const { USERS_TABLE_SCHEMA, SwitchableTypes, CanSwitchTypes, } = require("../../../constants");
|
|
18
|
+
const { isExternalTable, breakExternalTableId, isSQL, } = require("../../../integrations/utils");
|
|
19
19
|
const { getViews, saveView } = require("../view/utils");
|
|
20
20
|
const viewTemplate = require("../view/viewBuilder");
|
|
21
|
-
|
|
21
|
+
const usageQuota = require("../../../utilities/usageQuota");
|
|
22
|
+
const { cloneDeep } = require("lodash/fp");
|
|
23
|
+
exports.clearColumns = (appId, table, columnNames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const db = new CouchDB(appId);
|
|
25
|
+
const rows = yield db.allDocs(getRowParams(table._id, null, {
|
|
26
|
+
include_docs: true,
|
|
27
|
+
}));
|
|
28
|
+
return db.bulkDocs(rows.rows.map(({ doc }) => {
|
|
29
|
+
columnNames.forEach(colName => delete doc[colName]);
|
|
30
|
+
return doc;
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
exports.checkForColumnUpdates = (appId, db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
34
|
let updatedRows = [];
|
|
23
35
|
const rename = updatedTable._rename;
|
|
24
36
|
let deletedColumns = [];
|
|
@@ -31,16 +43,20 @@ exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0
|
|
|
31
43
|
const rows = yield db.allDocs(getRowParams(updatedTable._id, null, {
|
|
32
44
|
include_docs: true,
|
|
33
45
|
}));
|
|
34
|
-
|
|
46
|
+
const rawRows = rows.rows.map(({ doc }) => doc);
|
|
47
|
+
updatedRows = rawRows.map(row => {
|
|
48
|
+
row = cloneDeep(row);
|
|
35
49
|
if (rename) {
|
|
36
|
-
|
|
37
|
-
delete
|
|
50
|
+
row[rename.updated] = row[rename.old];
|
|
51
|
+
delete row[rename.old];
|
|
38
52
|
}
|
|
39
53
|
else if (deletedColumns.length !== 0) {
|
|
40
|
-
deletedColumns.forEach(colName => delete
|
|
54
|
+
deletedColumns.forEach(colName => delete row[colName]);
|
|
41
55
|
}
|
|
42
|
-
return
|
|
56
|
+
return row;
|
|
43
57
|
});
|
|
58
|
+
// cleanup any attachments from object storage for deleted attachment columns
|
|
59
|
+
yield cleanupAttachments(appId, updatedTable, { oldTable, rows: rawRows });
|
|
44
60
|
// Update views
|
|
45
61
|
yield exports.checkForViewUpdates(db, updatedTable, rename, deletedColumns);
|
|
46
62
|
delete updatedTable._rename;
|
|
@@ -95,7 +111,11 @@ exports.handleDataImport = (appId, user, table, dataImport) => __awaiter(void 0,
|
|
|
95
111
|
}
|
|
96
112
|
finalData.push(row);
|
|
97
113
|
}
|
|
114
|
+
yield usageQuota.update(usageQuota.Properties.ROW, finalData.length, {
|
|
115
|
+
dryRun: true,
|
|
116
|
+
});
|
|
98
117
|
yield db.bulkDocs(finalData);
|
|
118
|
+
yield usageQuota.update(usageQuota.Properties.ROW, finalData.length);
|
|
99
119
|
let response = yield db.put(table);
|
|
100
120
|
table._rev = response._rev;
|
|
101
121
|
return table;
|
|
@@ -174,7 +194,7 @@ class TableSaveFunctions {
|
|
|
174
194
|
// when confirmed valid
|
|
175
195
|
mid(table) {
|
|
176
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
let response = yield exports.checkForColumnUpdates(this.db, this.oldTable, table);
|
|
197
|
+
let response = yield exports.checkForColumnUpdates(this.appId, this.db, this.oldTable, table);
|
|
178
198
|
this.rows = this.rows.concat(response.rows);
|
|
179
199
|
return table;
|
|
180
200
|
});
|
|
@@ -191,6 +211,13 @@ class TableSaveFunctions {
|
|
|
191
211
|
return this.rows;
|
|
192
212
|
}
|
|
193
213
|
}
|
|
214
|
+
exports.getAllInternalTables = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
|
+
const db = new CouchDB(appId);
|
|
216
|
+
const internalTables = yield db.allDocs(getTableParams(null, {
|
|
217
|
+
include_docs: true,
|
|
218
|
+
}));
|
|
219
|
+
return internalTables.rows.map(tableDoc => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
|
|
220
|
+
});
|
|
194
221
|
exports.getAllExternalTables = (appId, datasourceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
222
|
const db = new CouchDB(appId);
|
|
196
223
|
const datasource = yield db.get(datasourceId);
|
|
@@ -207,7 +234,9 @@ exports.getTable = (appId, tableId) => __awaiter(void 0, void 0, void 0, functio
|
|
|
207
234
|
const db = new CouchDB(appId);
|
|
208
235
|
if (isExternalTable(tableId)) {
|
|
209
236
|
let { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
210
|
-
|
|
237
|
+
const datasource = yield db.get(datasourceId);
|
|
238
|
+
const table = yield exports.getExternalTable(appId, datasourceId, tableName);
|
|
239
|
+
return Object.assign(Object.assign({}, table), { sql: isSQL(datasource) });
|
|
211
240
|
}
|
|
212
241
|
else {
|
|
213
242
|
return db.get(tableId);
|
|
@@ -295,6 +324,19 @@ exports.foreignKeyStructure = (keyName, meta = null) => {
|
|
|
295
324
|
}
|
|
296
325
|
return structure;
|
|
297
326
|
};
|
|
327
|
+
exports.areSwitchableTypes = (type1, type2) => {
|
|
328
|
+
if (SwitchableTypes.indexOf(type1) === -1 &&
|
|
329
|
+
SwitchableTypes.indexOf(type2) === -1) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
for (let option of CanSwitchTypes) {
|
|
333
|
+
const index1 = option.indexOf(type1), index2 = option.indexOf(type2);
|
|
334
|
+
if (index1 !== -1 && index2 !== -1 && index1 !== index2) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
};
|
|
298
340
|
exports.hasTypeChanged = (table, oldTable) => {
|
|
299
341
|
if (!oldTable) {
|
|
300
342
|
return false;
|
|
@@ -305,7 +347,7 @@ exports.hasTypeChanged = (table, oldTable) => {
|
|
|
305
347
|
continue;
|
|
306
348
|
}
|
|
307
349
|
const newType = table.schema[key].type;
|
|
308
|
-
if (oldType !== newType &&
|
|
350
|
+
if (oldType !== newType && !exports.areSwitchableTypes(oldType, newType)) {
|
|
309
351
|
return true;
|
|
310
352
|
}
|
|
311
353
|
}
|
|
@@ -155,6 +155,8 @@ exports.updateSelfMetadata = function (ctx) {
|
|
|
155
155
|
ctx.request.body._id = ctx.user._id;
|
|
156
156
|
// make sure no stale rev
|
|
157
157
|
delete ctx.request.body._rev;
|
|
158
|
+
// make sure no csrf token
|
|
159
|
+
delete ctx.request.body.csrfToken;
|
|
158
160
|
yield exports.updateMetadata(ctx);
|
|
159
161
|
});
|
|
160
162
|
};
|
package/dist/api/routes/index.js
CHANGED
|
@@ -21,7 +21,6 @@ const integrationRoutes = require("./integration");
|
|
|
21
21
|
const permissionRoutes = require("./permission");
|
|
22
22
|
const datasourceRoutes = require("./datasource");
|
|
23
23
|
const queryRoutes = require("./query");
|
|
24
|
-
const hostingRoutes = require("./hosting");
|
|
25
24
|
const backupRoutes = require("./backup");
|
|
26
25
|
const metadataRoutes = require("./metadata");
|
|
27
26
|
const devRoutes = require("./dev");
|
|
@@ -46,7 +45,6 @@ exports.mainRoutes = [
|
|
|
46
45
|
permissionRoutes,
|
|
47
46
|
datasourceRoutes,
|
|
48
47
|
queryRoutes,
|
|
49
|
-
hostingRoutes,
|
|
50
48
|
backupRoutes,
|
|
51
49
|
metadataRoutes,
|
|
52
50
|
devRoutes,
|
|
@@ -43,5 +43,6 @@ router
|
|
|
43
43
|
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
|
44
44
|
.post("/api/attachments/:tableId/upload", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), controller.uploadFile)
|
|
45
45
|
// TODO: this likely needs to be secured in some way
|
|
46
|
-
.get("/:appId/:path*", controller.serveApp)
|
|
46
|
+
.get("/:appId/:path*", controller.serveApp)
|
|
47
|
+
.post("/api/attachments/:datasourceId/url", authorized(PermissionTypes.TABLE, PermissionLevels.READ), controller.getSignedUploadURL);
|
|
47
48
|
module.exports = router;
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const rowController = require("../../api/controllers/row");
|
|
12
12
|
const automationUtils = require("../automationUtils");
|
|
13
|
-
const env = require("../../environment");
|
|
14
13
|
const usage = require("../../utilities/usageQuota");
|
|
15
14
|
const { buildCtx } = require("./utils");
|
|
16
15
|
exports.definition = {
|
|
@@ -87,10 +86,9 @@ exports.run = function ({ inputs, appId, emitter }) {
|
|
|
87
86
|
});
|
|
88
87
|
try {
|
|
89
88
|
inputs.row = yield automationUtils.cleanUpRow(appId, inputs.row.tableId, inputs.row);
|
|
90
|
-
|
|
91
|
-
yield usage.update(usage.Properties.ROW, 1);
|
|
92
|
-
}
|
|
89
|
+
yield usage.update(usage.Properties.ROW, 1, { dryRun: true });
|
|
93
90
|
yield rowController.save(ctx);
|
|
91
|
+
yield usage.update(usage.Properties.ROW, 1);
|
|
94
92
|
return {
|
|
95
93
|
row: inputs.row,
|
|
96
94
|
response: ctx.body,
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const rowController = require("../../api/controllers/row");
|
|
12
|
-
const env = require("../../environment");
|
|
13
12
|
const usage = require("../../utilities/usageQuota");
|
|
14
13
|
const { buildCtx } = require("./utils");
|
|
15
14
|
const automationUtils = require("../automationUtils");
|
|
@@ -81,9 +80,7 @@ exports.run = function ({ inputs, appId, emitter }) {
|
|
|
81
80
|
},
|
|
82
81
|
});
|
|
83
82
|
try {
|
|
84
|
-
|
|
85
|
-
yield usage.update(usage.Properties.ROW, -1);
|
|
86
|
-
}
|
|
83
|
+
yield usage.update(usage.Properties.ROW, -1);
|
|
87
84
|
yield rowController.destroy(ctx);
|
|
88
85
|
return {
|
|
89
86
|
response: ctx.body,
|
package/dist/constants/index.js
CHANGED
|
@@ -41,17 +41,21 @@ exports.FieldTypes = {
|
|
|
41
41
|
JSON: "json",
|
|
42
42
|
INTERNAL: "internal",
|
|
43
43
|
};
|
|
44
|
-
exports.
|
|
45
|
-
exports.FieldTypes.
|
|
46
|
-
exports.FieldTypes.OPTIONS,
|
|
47
|
-
exports.FieldTypes.NUMBER,
|
|
48
|
-
exports.FieldTypes.BOOLEAN,
|
|
44
|
+
exports.CanSwitchTypes = [
|
|
45
|
+
[exports.FieldTypes.JSON, exports.FieldTypes.ARRAY],
|
|
46
|
+
[exports.FieldTypes.STRING, exports.FieldTypes.OPTIONS],
|
|
47
|
+
[exports.FieldTypes.BOOLEAN, exports.FieldTypes.NUMBER],
|
|
49
48
|
];
|
|
49
|
+
exports.SwitchableTypes = exports.CanSwitchTypes.reduce((prev, current) => prev ? prev.concat(current) : current);
|
|
50
50
|
exports.RelationshipTypes = {
|
|
51
51
|
ONE_TO_MANY: "one-to-many",
|
|
52
52
|
MANY_TO_ONE: "many-to-one",
|
|
53
53
|
MANY_TO_MANY: "many-to-many",
|
|
54
54
|
};
|
|
55
|
+
exports.FormulaTypes = {
|
|
56
|
+
STATIC: "static",
|
|
57
|
+
DYNAMIC: "dynamic",
|
|
58
|
+
};
|
|
55
59
|
exports.AuthTypes = {
|
|
56
60
|
APP: "app",
|
|
57
61
|
BUILDER: "builder",
|
|
@@ -67,6 +71,9 @@ exports.DataSourceOperation = {
|
|
|
67
71
|
UPDATE_TABLE: "UPDATE_TABLE",
|
|
68
72
|
DELETE_TABLE: "DELETE_TABLE",
|
|
69
73
|
};
|
|
74
|
+
exports.DatasourceAuthTypes = {
|
|
75
|
+
GOOGLE: "google",
|
|
76
|
+
};
|
|
70
77
|
exports.SortDirection = {
|
|
71
78
|
ASCENDING: "ASCENDING",
|
|
72
79
|
DESCENDING: "DESCENDING",
|
|
@@ -61,7 +61,7 @@ function getLinksForRows(appId, rows) {
|
|
|
61
61
|
.map(el => (Object.assign(Object.assign({}, el), { unique: el.id + el.thisId + el.fieldName }))), "unique");
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
function getFullLinkedDocs(
|
|
64
|
+
function getFullLinkedDocs(appId, links) {
|
|
65
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
66
|
// create DBs
|
|
67
67
|
const db = new CouchDB(appId);
|
|
@@ -132,13 +132,12 @@ exports.updateLinks = function (args) {
|
|
|
132
132
|
/**
|
|
133
133
|
* Given a table and a list of rows this will retrieve all of the attached docs and enrich them into the row.
|
|
134
134
|
* This is required for formula fields, this may only be utilised internally (for now).
|
|
135
|
-
* @param {
|
|
135
|
+
* @param {string} appId The ID of the app which this request is in the context of.
|
|
136
136
|
* @param {object} table The table from which the rows originated.
|
|
137
137
|
* @param {array<object>} rows The rows which are to be enriched.
|
|
138
138
|
* @return {Promise<*>} returns the rows with all of the enriched relationships on it.
|
|
139
139
|
*/
|
|
140
|
-
exports.attachFullLinkedDocs = (
|
|
141
|
-
const appId = ctx.appId;
|
|
140
|
+
exports.attachFullLinkedDocs = (appId, table, rows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
141
|
const linkedTableIds = getLinkedTableIDs(table);
|
|
143
142
|
if (linkedTableIds.length === 0) {
|
|
144
143
|
return rows;
|
|
@@ -150,7 +149,7 @@ exports.attachFullLinkedDocs = (ctx, table, rows) => __awaiter(void 0, void 0, v
|
|
|
150
149
|
// clear any existing links that could be dupe'd
|
|
151
150
|
rows = clearRelationshipFields(table, rows);
|
|
152
151
|
// now get the docs and combine into the rows
|
|
153
|
-
let linked = yield getFullLinkedDocs(
|
|
152
|
+
let linked = yield getFullLinkedDocs(appId, links);
|
|
154
153
|
const linkedTables = [];
|
|
155
154
|
for (let row of rows) {
|
|
156
155
|
for (let link of links.filter(link => link.thisId === row._id)) {
|
|
@@ -49,6 +49,7 @@ var SourceNames;
|
|
|
49
49
|
SourceNames["ARANGODB"] = "ARANGODB";
|
|
50
50
|
SourceNames["REST"] = "REST";
|
|
51
51
|
SourceNames["ORACLE"] = "ORACLE";
|
|
52
|
+
SourceNames["GOOGLE_SHEETS"] = "GOOGLE_SHEETS";
|
|
52
53
|
})(SourceNames = exports.SourceNames || (exports.SourceNames = {}));
|
|
53
54
|
var IncludeRelationships;
|
|
54
55
|
(function (IncludeRelationships) {
|
package/dist/environment.js
CHANGED
|
@@ -30,6 +30,7 @@ module.exports = {
|
|
|
30
30
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
31
31
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
|
32
32
|
USE_QUOTAS: process.env.USE_QUOTAS,
|
|
33
|
+
EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
|
|
33
34
|
REDIS_URL: process.env.REDIS_URL,
|
|
34
35
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
35
36
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
|
@@ -69,10 +69,16 @@ class InternalBuilder {
|
|
|
69
69
|
this.client = client;
|
|
70
70
|
}
|
|
71
71
|
// right now we only do filters on the specific table being queried
|
|
72
|
-
addFilters(
|
|
72
|
+
addFilters(query, filters, opts) {
|
|
73
73
|
function iterate(structure, fn) {
|
|
74
74
|
for (let [key, value] of Object.entries(structure)) {
|
|
75
|
-
|
|
75
|
+
const isRelationshipField = key.includes(".");
|
|
76
|
+
if (!opts.relationship && !isRelationshipField) {
|
|
77
|
+
fn(`${opts.tableName}.${key}`, value);
|
|
78
|
+
}
|
|
79
|
+
if (opts.relationship && isRelationshipField) {
|
|
80
|
+
fn(key, value);
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
if (!filters) {
|
|
@@ -248,7 +254,7 @@ class InternalBuilder {
|
|
|
248
254
|
if (foundOffset) {
|
|
249
255
|
query = query.offset(foundOffset);
|
|
250
256
|
}
|
|
251
|
-
query = this.addFilters(
|
|
257
|
+
query = this.addFilters(query, filters, { tableName });
|
|
252
258
|
// add sorting to pre-query
|
|
253
259
|
query = this.addSorting(query, json);
|
|
254
260
|
// @ts-ignore
|
|
@@ -261,13 +267,14 @@ class InternalBuilder {
|
|
|
261
267
|
preQuery = this.addSorting(preQuery, json);
|
|
262
268
|
}
|
|
263
269
|
// handle joins
|
|
264
|
-
|
|
270
|
+
query = this.addRelationships(knex, preQuery, selectStatement, tableName, relationships);
|
|
271
|
+
return this.addFilters(query, filters, { relationship: true });
|
|
265
272
|
}
|
|
266
273
|
update(knex, json, opts) {
|
|
267
274
|
const { endpoint, body, filters } = json;
|
|
268
275
|
let query = knex(endpoint.entityId);
|
|
269
276
|
const parsedBody = parseBody(body);
|
|
270
|
-
query = this.addFilters(endpoint.entityId
|
|
277
|
+
query = this.addFilters(query, filters, { tableName: endpoint.entityId });
|
|
271
278
|
// mysql can't use returning
|
|
272
279
|
if (opts.disableReturning) {
|
|
273
280
|
return query.update(parsedBody);
|
|
@@ -279,7 +286,7 @@ class InternalBuilder {
|
|
|
279
286
|
delete(knex, json, opts) {
|
|
280
287
|
const { endpoint, filters } = json;
|
|
281
288
|
let query = knex(endpoint.entityId);
|
|
282
|
-
query = this.addFilters(endpoint.entityId
|
|
289
|
+
query = this.addFilters(query, filters, { tableName: endpoint.entityId });
|
|
283
290
|
// mysql can't use returning
|
|
284
291
|
if (opts.disableReturning) {
|
|
285
292
|
return query.delete();
|