@budibase/server 2.0.39 → 2.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/mongodb.ts +1 -1
- package/__mocks__/node-fetch.ts +12 -2
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.e0ddd30b.css → index.442de33f.css} +2 -2
- package/builder/assets/{index.b20dee52.js → index.72aa3989.js} +340 -332
- package/builder/index.html +2 -2
- package/coverage/clover.xml +1125 -1250
- package/coverage/coverage-final.json +73 -77
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +79 -67
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +21 -21
- package/coverage/lcov-report/api/controllers/index.html +17 -47
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +13 -13
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -8
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +30 -30
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +5 -35
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +24 -84
- package/coverage/lcov-report/automations/index.html +21 -21
- package/coverage/lcov-report/automations/index.js.html +9 -9
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +15 -15
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +49 -49
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +10 -28
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +28 -28
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +37 -316
- 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 +3 -3
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +88 -88
- 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 +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +19 -19
- package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +15 -12
- package/coverage/lcov-report/utilities/global.js.html +31 -31
- package/coverage/lcov-report/utilities/index.html +28 -28
- package/coverage/lcov-report/utilities/index.js.html +8 -8
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +72 -57
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
- package/coverage/lcov.info +1691 -1899
- package/dist/api/controllers/application.js +4 -7
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +7 -2
- package/dist/api/controllers/row/index.js +40 -66
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +3 -2
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/static/templates/preview.hbs +10 -0
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +10 -3
- package/dist/api/controllers/table/utils.js +7 -49
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -68
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +12 -35
- package/dist/automations/index.js +4 -4
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/triggers.js +6 -6
- package/dist/automations/utils.js +23 -49
- package/dist/constants/index.js +4 -8
- package/dist/db/utils.js +10 -75
- package/dist/index.js +1 -0
- package/dist/integrations/arangodb.js +2 -0
- package/dist/integrations/base/sqlTable.js +1 -0
- package/dist/integrations/mongodb.js +300 -11
- package/dist/integrations/rest.js +38 -5
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
- package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
- package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
- package/dist/migrations/index.js +10 -38
- package/dist/package.json +14 -14
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +190 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +17 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +12 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +1 -0
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/rowProcessor/index.js +5 -0
- package/dist/utilities/usageQuota/rows.js +6 -4
- package/package.json +15 -15
- package/specs/openapi.json +3 -0
- package/specs/openapi.yaml +3 -0
- package/src/api/controllers/application.ts +5 -12
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -8
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +8 -2
- package/src/api/controllers/row/index.ts +50 -65
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +4 -2
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/static/templates/preview.hbs +10 -0
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +8 -9
- package/src/api/controllers/table/utils.ts +4 -53
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/api/routes/tests/row.spec.js +22 -27
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -91
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +14 -34
- package/src/automations/index.js +4 -4
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +1 -6
- package/src/automations/triggers.js +6 -6
- package/src/automations/utils.ts +30 -32
- package/src/constants/index.js +4 -10
- package/src/db/utils.js +17 -110
- package/src/definitions/automations.ts +1 -18
- package/src/definitions/datasource.ts +1 -0
- package/src/index.ts +1 -0
- package/src/integrations/arangodb.ts +2 -0
- package/src/integrations/base/sqlTable.ts +1 -0
- package/src/integrations/mongodb.ts +290 -27
- package/src/integrations/rest.ts +17 -5
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +38 -22
- package/src/migrations/functions/backfill/app/tables.ts +7 -13
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
- package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
- package/src/migrations/index.ts +21 -45
- package/src/migrations/tests/index.spec.ts +0 -1
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +206 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +78 -0
- package/src/sdk/app/tables/index.ts +61 -0
- package/src/sdk/index.ts +15 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +12 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/csvParser.js +1 -0
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/rowProcessor/index.js +5 -0
- package/src/utilities/usageQuota/rows.js +7 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
- package/src/migrations/functions/pluginCount.ts +0 -12
|
@@ -38,6 +38,7 @@ const backend_core_2 = require("@budibase/backend-core");
|
|
|
38
38
|
const types_1 = require("@budibase/types");
|
|
39
39
|
const layouts_1 = require("../../constants/layouts");
|
|
40
40
|
const plugins_1 = require("../../utilities/plugins");
|
|
41
|
+
const sdk_1 = __importDefault(require("../../sdk"));
|
|
41
42
|
const URL_REGEX_SLASH = /\/|\\/g;
|
|
42
43
|
// utility function, need to do away with this
|
|
43
44
|
function getLayouts() {
|
|
@@ -125,11 +126,7 @@ function createInstance(template) {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
else if (template && template.useTemplate === "true") {
|
|
128
|
-
|
|
129
|
-
const { ok } = yield db.load(yield (0, fileSystem_1.getTemplateStream)(template));
|
|
130
|
-
if (!ok) {
|
|
131
|
-
throw "Error loading database dump from template.";
|
|
132
|
-
}
|
|
129
|
+
yield sdk_1.default.backups.importApp(appId, db, template);
|
|
133
130
|
}
|
|
134
131
|
else {
|
|
135
132
|
// create the users table
|
|
@@ -315,7 +312,7 @@ const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function*
|
|
|
315
312
|
yield creationEvents(ctx.request, app);
|
|
316
313
|
// app import & template creation
|
|
317
314
|
if (ctx.request.body.useTemplate === "true") {
|
|
318
|
-
const rows = yield (0, rows_1.getUniqueRows)([app.appId]);
|
|
315
|
+
const { rows } = yield (0, rows_1.getUniqueRows)([app.appId]);
|
|
319
316
|
const rowCount = rows ? rows.length : 0;
|
|
320
317
|
if (rowCount) {
|
|
321
318
|
try {
|
|
@@ -440,7 +437,7 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
440
437
|
return result;
|
|
441
438
|
});
|
|
442
439
|
const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
443
|
-
const rows = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
|
|
440
|
+
const { rows } = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
|
|
444
441
|
ctx.rowCount = rows.length;
|
|
445
442
|
});
|
|
446
443
|
const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -8,22 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.exportAppDump =
|
|
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.exportAppDump = void 0;
|
|
16
|
+
const sdk_1 = __importDefault(require("../../sdk"));
|
|
17
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
18
|
+
const utils_1 = require("../../db/utils");
|
|
19
|
+
const utilities_1 = require("../../utilities");
|
|
20
|
+
function exportAppDump(ctx) {
|
|
16
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
22
|
let { appId, excludeRows } = ctx.query;
|
|
18
23
|
const appName = decodeURI(ctx.query.appname);
|
|
19
|
-
excludeRows = isQsTrue(excludeRows);
|
|
20
|
-
const backupIdentifier = `${appName}-export-${new Date().getTime()}.
|
|
24
|
+
excludeRows = (0, utilities_1.isQsTrue)(excludeRows);
|
|
25
|
+
const backupIdentifier = `${appName}-export-${new Date().getTime()}.tar.gz`;
|
|
21
26
|
ctx.attachment(backupIdentifier);
|
|
22
|
-
ctx.body = yield
|
|
23
|
-
yield context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const appDb = context.getAppDB();
|
|
25
|
-
const app = yield appDb.get(DocumentType.APP_METADATA);
|
|
26
|
-
yield events.app.exported(app);
|
|
27
|
+
ctx.body = yield sdk_1.default.backups.streamExportApp(appId, excludeRows);
|
|
28
|
+
yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const appDb = backend_core_1.context.getAppDB();
|
|
30
|
+
const app = yield appDb.get(utils_1.DocumentType.APP_METADATA);
|
|
31
|
+
yield backend_core_1.events.app.exported(app);
|
|
27
32
|
}));
|
|
28
33
|
});
|
|
29
|
-
}
|
|
34
|
+
}
|
|
35
|
+
exports.exportAppDump = exportAppDump;
|
|
@@ -10,55 +10,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const env = require("../../environment");
|
|
12
12
|
const { getAllApps, getGlobalDBName } = require("@budibase/backend-core/db");
|
|
13
|
-
const { exportDB, sendTempFile, readFileSync, } = require("../../utilities/fileSystem");
|
|
14
|
-
const { stringToReadStream } = require("../../utilities");
|
|
15
13
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
16
|
-
const {
|
|
14
|
+
const { streamFile } = require("../../utilities/fileSystem");
|
|
15
|
+
const { stringToReadStream } = require("../../utilities");
|
|
17
16
|
const { getDocParams, DocumentType, isDevAppID } = require("../../db/utils");
|
|
18
|
-
|
|
17
|
+
const { create } = require("./application");
|
|
18
|
+
const { join } = require("path");
|
|
19
|
+
const sdk = require("../../sdk");
|
|
20
|
+
function createApp(appName, appDirectory) {
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
22
|
const ctx = {
|
|
21
23
|
request: {
|
|
22
24
|
body: {
|
|
23
|
-
|
|
25
|
+
useTemplate: true,
|
|
24
26
|
name: appName,
|
|
25
27
|
},
|
|
28
|
+
files: {
|
|
29
|
+
templateFile: {
|
|
30
|
+
path: appDirectory,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
26
33
|
},
|
|
27
34
|
};
|
|
28
35
|
return create(ctx);
|
|
29
36
|
});
|
|
30
37
|
}
|
|
38
|
+
function getAllDocType(db, docType) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const response = yield db.allDocs(getDocParams(docType, null, {
|
|
41
|
+
include_docs: true,
|
|
42
|
+
}));
|
|
43
|
+
return response.rows.map(row => row.doc);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
31
46
|
exports.exportApps = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
47
|
if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
|
|
33
48
|
ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.");
|
|
34
49
|
}
|
|
35
50
|
const apps = yield getAllApps({ all: true });
|
|
36
|
-
const globalDBString = yield exportDB(getGlobalDBName(), {
|
|
51
|
+
const globalDBString = yield sdk.backups.exportDB(getGlobalDBName(), {
|
|
37
52
|
filter: doc => !doc._id.startsWith(DocumentType.USER),
|
|
38
53
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (isDevAppID(appId)) {
|
|
47
|
-
allDBs[app.name] = yield exportDB(appId);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const filename = `cloud-export-${new Date().getTime()}.txt`;
|
|
54
|
+
// only export the dev apps as they will be the latest, the user can republish the apps
|
|
55
|
+
// in their self-hosted environment
|
|
56
|
+
let appMetadata = apps
|
|
57
|
+
.filter(app => isDevAppID(app.appId || app._id))
|
|
58
|
+
.map(app => ({ appId: app.appId || app._id, name: app.name }));
|
|
59
|
+
const tmpPath = yield sdk.backups.exportMultipleApps(appMetadata, globalDBString);
|
|
60
|
+
const filename = `cloud-export-${new Date().getTime()}.tar.gz`;
|
|
51
61
|
ctx.attachment(filename);
|
|
52
|
-
ctx.body =
|
|
62
|
+
ctx.body = streamFile(tmpPath);
|
|
53
63
|
});
|
|
54
|
-
function getAllDocType(db, docType) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const response = yield db.allDocs(getDocParams(docType, null, {
|
|
57
|
-
include_docs: true,
|
|
58
|
-
}));
|
|
59
|
-
return response.rows.map(row => row.doc);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
64
|
function hasBeenImported() {
|
|
63
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
66
|
if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
|
|
@@ -81,17 +83,18 @@ exports.importApps = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
81
83
|
if (beenImported || !ctx.request.files || !ctx.request.files.importFile) {
|
|
82
84
|
ctx.throw(400, "Import file is required and environment must be fresh to import apps.");
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if (ctx.request.files.importFile.type !== "application/gzip") {
|
|
87
|
+
ctx.throw(400, "Import file must be a gzipped tarball.");
|
|
88
|
+
}
|
|
89
|
+
// initially get all the app databases out of the tarball
|
|
90
|
+
const tmpPath = sdk.backups.untarFile(ctx.request.files.importFile);
|
|
91
|
+
const globalDbImport = sdk.backups.getGlobalDBFile(tmpPath);
|
|
92
|
+
const appNames = sdk.backups.getListOfAppsInMulti(tmpPath);
|
|
90
93
|
const globalDb = getGlobalDB();
|
|
91
94
|
// load the global db first
|
|
92
95
|
yield globalDb.load(stringToReadStream(globalDbImport));
|
|
93
|
-
for (let
|
|
94
|
-
yield createApp(appName,
|
|
96
|
+
for (let appName of appNames) {
|
|
97
|
+
yield createApp(appName, join(tmpPath, appName));
|
|
95
98
|
}
|
|
96
99
|
// if there are any users make sure to remove them
|
|
97
100
|
let users = yield getAllDocType(globalDb, DocumentType.USER);
|
|
@@ -20,6 +20,8 @@ const utils_2 = require("../../../automations/utils");
|
|
|
20
20
|
const cache_1 = require("@budibase/backend-core/cache");
|
|
21
21
|
const context_1 = require("@budibase/backend-core/context");
|
|
22
22
|
const backend_core_1 = require("@budibase/backend-core");
|
|
23
|
+
const pro_1 = require("@budibase/pro");
|
|
24
|
+
const types_1 = require("@budibase/types");
|
|
23
25
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
24
26
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
25
27
|
const DeploymentStatus = {
|
|
@@ -87,13 +89,20 @@ function initDeployedApp(prodAppId) {
|
|
|
87
89
|
console.log("Enabled cron triggers for deployed app..");
|
|
88
90
|
});
|
|
89
91
|
}
|
|
90
|
-
function deployApp(deployment) {
|
|
92
|
+
function deployApp(deployment, userId) {
|
|
91
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
94
|
let replication;
|
|
93
95
|
try {
|
|
94
96
|
const appId = (0, context_1.getAppId)();
|
|
95
97
|
const devAppId = (0, db_1.getDevelopmentAppID)(appId);
|
|
96
98
|
const productionAppId = (0, db_1.getProdAppID)(appId);
|
|
99
|
+
// don't try this if feature isn't allowed, will error
|
|
100
|
+
if (yield pro_1.backups.isEnabled()) {
|
|
101
|
+
// trigger backup initially
|
|
102
|
+
yield pro_1.backups.triggerAppBackup(productionAppId, types_1.AppBackupTrigger.PUBLISH, {
|
|
103
|
+
createdBy: userId,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
97
106
|
const config = {
|
|
98
107
|
source: devAppId,
|
|
99
108
|
target: productionAppId,
|
|
@@ -195,7 +204,7 @@ const _deployApp = function (ctx) {
|
|
|
195
204
|
deployment = yield storeDeploymentHistory(deployment);
|
|
196
205
|
console.log("Stored deployment history");
|
|
197
206
|
console.log("Deploying app...");
|
|
198
|
-
let app = yield deployApp(deployment);
|
|
207
|
+
let app = yield deployApp(deployment, ctx.user._id);
|
|
199
208
|
yield backend_core_1.events.app.published(app);
|
|
200
209
|
ctx.body = deployment;
|
|
201
210
|
});
|
|
@@ -61,6 +61,7 @@ const _import = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
61
61
|
config: {
|
|
62
62
|
url: info.url,
|
|
63
63
|
defaultHeaders: [],
|
|
64
|
+
rejectUnauthorized: true,
|
|
64
65
|
},
|
|
65
66
|
name: info.name,
|
|
66
67
|
};
|
|
@@ -149,7 +150,9 @@ function preview(ctx) {
|
|
|
149
150
|
auth: Object.assign({}, authConfigCtx),
|
|
150
151
|
},
|
|
151
152
|
});
|
|
152
|
-
const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn
|
|
153
|
+
const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn, {
|
|
154
|
+
datasourceId: datasource._id,
|
|
155
|
+
});
|
|
153
156
|
const schemaFields = {};
|
|
154
157
|
if ((rows === null || rows === void 0 ? void 0 : rows.length) > 0) {
|
|
155
158
|
for (let key of [...new Set(keys)]) {
|
|
@@ -226,7 +229,9 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
|
|
|
226
229
|
auth: Object.assign({}, authConfigCtx),
|
|
227
230
|
},
|
|
228
231
|
});
|
|
229
|
-
const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn
|
|
232
|
+
const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn, {
|
|
233
|
+
datasourceId: datasource._id,
|
|
234
|
+
});
|
|
230
235
|
// remove the raw from execution incase transformer being used to hide data
|
|
231
236
|
if (extra === null || extra === void 0 ? void 0 : extra.raw) {
|
|
232
237
|
delete extra.raw;
|
|
@@ -43,17 +43,13 @@ function patch(ctx) {
|
|
|
43
43
|
if (body && !body._id) {
|
|
44
44
|
return (0, exports.save)(ctx);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
ctx.throw(400, err);
|
|
56
|
-
}
|
|
46
|
+
const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx), {
|
|
47
|
+
datasourceId: tableId,
|
|
48
|
+
});
|
|
49
|
+
ctx.status = 200;
|
|
50
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
|
|
51
|
+
ctx.message = `${table.name} updated successfully.`;
|
|
52
|
+
ctx.body = row;
|
|
57
53
|
});
|
|
58
54
|
}
|
|
59
55
|
exports.patch = patch;
|
|
@@ -65,51 +61,39 @@ const save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
65
61
|
if (body && body._id) {
|
|
66
62
|
return patch(ctx);
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
catch (err) {
|
|
76
|
-
ctx.throw(400, err);
|
|
77
|
-
}
|
|
64
|
+
const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx), {
|
|
65
|
+
datasourceId: tableId,
|
|
66
|
+
}));
|
|
67
|
+
ctx.status = 200;
|
|
68
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
|
|
69
|
+
ctx.message = `${table.name} saved successfully`;
|
|
70
|
+
ctx.body = row;
|
|
78
71
|
});
|
|
79
72
|
exports.save = save;
|
|
80
73
|
function fetchView(ctx) {
|
|
81
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
75
|
const tableId = getTableId(ctx);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
ctx.throw(400, err);
|
|
88
|
-
}
|
|
76
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
|
|
77
|
+
datasourceId: tableId,
|
|
78
|
+
});
|
|
89
79
|
});
|
|
90
80
|
}
|
|
91
81
|
exports.fetchView = fetchView;
|
|
92
82
|
function fetch(ctx) {
|
|
93
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
84
|
const tableId = getTableId(ctx);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
ctx.throw(400, err);
|
|
100
|
-
}
|
|
85
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
|
|
86
|
+
datasourceId: tableId,
|
|
87
|
+
});
|
|
101
88
|
});
|
|
102
89
|
}
|
|
103
90
|
exports.fetch = fetch;
|
|
104
91
|
function find(ctx) {
|
|
105
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
93
|
const tableId = getTableId(ctx);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
ctx.throw(400, err);
|
|
112
|
-
}
|
|
94
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx), {
|
|
95
|
+
datasourceId: tableId,
|
|
96
|
+
});
|
|
113
97
|
});
|
|
114
98
|
}
|
|
115
99
|
exports.find = find;
|
|
@@ -120,7 +104,9 @@ function destroy(ctx) {
|
|
|
120
104
|
const tableId = getTableId(ctx);
|
|
121
105
|
let response, row;
|
|
122
106
|
if (inputs.rows) {
|
|
123
|
-
let { rows } = yield pro_1.quotas.addQuery(() => pickApi(tableId).bulkDestroy(ctx)
|
|
107
|
+
let { rows } = yield pro_1.quotas.addQuery(() => pickApi(tableId).bulkDestroy(ctx), {
|
|
108
|
+
datasourceId: tableId,
|
|
109
|
+
});
|
|
124
110
|
yield pro_1.quotas.removeRows(rows.length);
|
|
125
111
|
response = rows;
|
|
126
112
|
for (let row of rows) {
|
|
@@ -128,7 +114,9 @@ function destroy(ctx) {
|
|
|
128
114
|
}
|
|
129
115
|
}
|
|
130
116
|
else {
|
|
131
|
-
let resp = yield pro_1.quotas.addQuery(() => pickApi(tableId).destroy(ctx)
|
|
117
|
+
let resp = yield pro_1.quotas.addQuery(() => pickApi(tableId).destroy(ctx), {
|
|
118
|
+
datasourceId: tableId,
|
|
119
|
+
});
|
|
132
120
|
yield pro_1.quotas.removeRow();
|
|
133
121
|
response = resp.response;
|
|
134
122
|
row = resp.row;
|
|
@@ -144,47 +132,33 @@ exports.destroy = destroy;
|
|
|
144
132
|
function search(ctx) {
|
|
145
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
134
|
const tableId = getTableId(ctx);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
ctx.throw(400, err);
|
|
153
|
-
}
|
|
135
|
+
ctx.status = 200;
|
|
136
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx), {
|
|
137
|
+
datasourceId: tableId,
|
|
138
|
+
});
|
|
154
139
|
});
|
|
155
140
|
}
|
|
156
141
|
exports.search = search;
|
|
157
142
|
function validate(ctx) {
|
|
158
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
144
|
const tableId = getTableId(ctx);
|
|
160
|
-
|
|
161
|
-
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
ctx.throw(400, err);
|
|
165
|
-
}
|
|
145
|
+
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
166
146
|
});
|
|
167
147
|
}
|
|
168
148
|
exports.validate = validate;
|
|
169
149
|
function fetchEnrichedRow(ctx) {
|
|
170
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
151
|
const tableId = getTableId(ctx);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
catch (err) {
|
|
176
|
-
ctx.throw(400, err);
|
|
177
|
-
}
|
|
152
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx), {
|
|
153
|
+
datasourceId: tableId,
|
|
154
|
+
});
|
|
178
155
|
});
|
|
179
156
|
}
|
|
180
157
|
exports.fetchEnrichedRow = fetchEnrichedRow;
|
|
181
158
|
const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
159
|
const tableId = getTableId(ctx);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
catch (err) {
|
|
187
|
-
ctx.throw(400, err);
|
|
188
|
-
}
|
|
160
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
|
|
161
|
+
datasourceId: tableId,
|
|
162
|
+
});
|
|
189
163
|
});
|
|
190
164
|
exports.exportRows = exportRows;
|
|
@@ -122,7 +122,7 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
122
122
|
table,
|
|
123
123
|
});
|
|
124
124
|
if (!validateResult.valid) {
|
|
125
|
-
throw { validation: validateResult.errors };
|
|
125
|
+
ctx.throw(400, { validation: validateResult.errors });
|
|
126
126
|
}
|
|
127
127
|
// returned row is cleaned and prepared for writing to DB
|
|
128
128
|
row = yield linkRows.updateLinks({
|
|
@@ -15,7 +15,7 @@ require("svelte/register");
|
|
|
15
15
|
const send = require("koa-send");
|
|
16
16
|
const { resolve, join } = require("../../../utilities/centralPath");
|
|
17
17
|
const uuid = require("uuid");
|
|
18
|
-
const { ObjectStoreBuckets } = require("../../../constants");
|
|
18
|
+
const { ObjectStoreBuckets, ATTACHMENT_DIR } = require("../../../constants");
|
|
19
19
|
const { processString } = require("@budibase/string-templates");
|
|
20
20
|
const { loadHandlebarsFile, NODE_MODULES_PATH, TOP_LEVEL_PATH, } = require("../../../utilities/fileSystem");
|
|
21
21
|
const env = require("../../../environment");
|
|
@@ -88,7 +88,7 @@ const uploadFile = function (ctx) {
|
|
|
88
88
|
const processedFileName = `${uuid.v4()}.${fileExtension}`;
|
|
89
89
|
return prepareUpload({
|
|
90
90
|
file,
|
|
91
|
-
s3Key: `${ctx.appId}
|
|
91
|
+
s3Key: `${ctx.appId}/${ATTACHMENT_DIR}/${processedFileName}`,
|
|
92
92
|
bucket: ObjectStoreBuckets.APPS,
|
|
93
93
|
});
|
|
94
94
|
}));
|
|
@@ -111,6 +111,7 @@ const serveApp = function (ctx) {
|
|
|
111
111
|
const App = require("./templates/BudibaseApp.svelte").default;
|
|
112
112
|
const plugins = (0, plugins_1.enrichPluginURLs)(appInfo.usedPlugins);
|
|
113
113
|
const { head, html, css } = App.render({
|
|
114
|
+
metaImage: "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
|
|
114
115
|
title: appInfo.name,
|
|
115
116
|
production: env.isProd(),
|
|
116
117
|
appId,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
export let title = ""
|
|
3
3
|
export let favicon = ""
|
|
4
|
+
export let metaImage = ""
|
|
5
|
+
export let url = ""
|
|
4
6
|
|
|
5
7
|
export let clientLibPath
|
|
6
8
|
export let usedPlugins
|
|
@@ -12,6 +14,15 @@
|
|
|
12
14
|
name="viewport"
|
|
13
15
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
|
14
16
|
/>
|
|
17
|
+
<!-- Opengraph Meta Tags -->
|
|
18
|
+
<meta name="twitter:card" content="summary_large_image" />
|
|
19
|
+
<meta name="twitter:site" content="@budibase" />
|
|
20
|
+
<meta name="twitter:image" content={metaImage} />
|
|
21
|
+
<meta name="twitter:title" content="{title} - built with Budibase" />
|
|
22
|
+
<meta property="og:site_name" content="Budibase" />
|
|
23
|
+
<meta property="og:title" content="{title} - built with Budibase" />
|
|
24
|
+
<meta property="og:type" content="website" />
|
|
25
|
+
<meta property="og:image" content={metaImage} />
|
|
15
26
|
|
|
16
27
|
<title>{title}</title>
|
|
17
28
|
<link rel="icon" type="image/png" href={favicon} />
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// If this is a custom event, try and handle it
|
|
60
|
+
if (parsed.runtimeEvent) {
|
|
61
|
+
const { name, payload } = parsed
|
|
62
|
+
if (window.handleBuilderRuntimeEvent) {
|
|
63
|
+
window.handleBuilderRuntimeEvent(name, payload)
|
|
64
|
+
}
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Otherwise this is a full reload message
|
|
59
69
|
// Extract data from message
|
|
60
70
|
const {
|
|
61
71
|
selectedComponentId,
|
|
@@ -9,12 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { FieldTypes, FormulaTypes } = require("../../../constants");
|
|
12
|
-
const {
|
|
12
|
+
const { clearColumns } = require("./utils");
|
|
13
13
|
const { doesContainStrings } = require("@budibase/string-templates");
|
|
14
14
|
const { cloneDeep } = require("lodash/fp");
|
|
15
15
|
const { isEqual, uniq } = require("lodash");
|
|
16
16
|
const { updateAllFormulasInTable } = require("../row/staticFormula");
|
|
17
17
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
18
|
+
const sdk = require("../../../sdk");
|
|
18
19
|
function isStaticFormula(column) {
|
|
19
20
|
return (column.type === FieldTypes.FORMULA &&
|
|
20
21
|
column.formulaType === FormulaTypes.STATIC);
|
|
@@ -46,7 +47,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
46
47
|
function checkIfFormulaNeedsCleared(table, { oldTable, deletion }) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
49
|
// start by retrieving all tables, remove the current table from the list
|
|
49
|
-
const tables = (yield getAllInternalTables()).filter(tbl => tbl._id !== table._id);
|
|
50
|
+
const tables = (yield sdk.tables.getAllInternalTables()).filter(tbl => tbl._id !== table._id);
|
|
50
51
|
const schemaToUse = oldTable ? oldTable.schema : table.schema;
|
|
51
52
|
let removedColumns = Object.values(schemaToUse).filter(column => deletion || !table.schema[column.name]);
|
|
52
53
|
// remove any formula columns that used related columns
|
|
@@ -96,7 +97,7 @@ function updateRelatedFormulaLinksOnTables(table, { deletion } = { deletion: fal
|
|
|
96
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
98
|
const db = getAppDB();
|
|
98
99
|
// start by retrieving all tables, remove the current table from the list
|
|
99
|
-
const tables = (yield getAllInternalTables()).filter(tbl => tbl._id !== table._id);
|
|
100
|
+
const tables = (yield sdk.tables.getAllInternalTables()).filter(tbl => tbl._id !== table._id);
|
|
100
101
|
// clone the tables, so we can compare at end
|
|
101
102
|
const initialTables = cloneDeep(tables);
|
|
102
103
|
// first find the related column names
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { buildExternalTableId, breakExternalTableId, } = require("../../../integrations/utils");
|
|
12
|
-
const {
|
|
12
|
+
const { generateForeignKey, generateJunctionTableName, foreignKeyStructure, hasTypeChanged, } = require("./utils");
|
|
13
13
|
const { DataSourceOperation, FieldTypes, RelationshipTypes, } = require("../../../constants");
|
|
14
14
|
const { makeExternalQuery } = require("../../../integrations/base/query");
|
|
15
15
|
const { cloneDeep } = require("lodash/fp");
|
|
@@ -17,6 +17,7 @@ const csvParser = require("../../../utilities/csvParser");
|
|
|
17
17
|
const { handleRequest } = require("../row/external");
|
|
18
18
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
19
19
|
const { events } = require("@budibase/backend-core");
|
|
20
|
+
const sdk = require("../../../sdk");
|
|
20
21
|
function makeTableRequest(datasource, operation, table, tables, oldTable = null, renamed = null) {
|
|
21
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
23
|
const json = {
|
|
@@ -150,7 +151,7 @@ exports.save = function (ctx) {
|
|
|
150
151
|
let tableToSave = Object.assign({ type: "table", _id: buildExternalTableId(datasourceId, table.name) }, table);
|
|
151
152
|
let oldTable;
|
|
152
153
|
if (ctx.request.body && ctx.request.body._id) {
|
|
153
|
-
oldTable = yield getTable(ctx.request.body._id);
|
|
154
|
+
oldTable = yield sdk.tables.getTable(ctx.request.body._id);
|
|
154
155
|
}
|
|
155
156
|
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
156
157
|
ctx.throw(400, "A column type has changed.");
|
|
@@ -221,7 +222,7 @@ exports.save = function (ctx) {
|
|
|
221
222
|
};
|
|
222
223
|
exports.destroy = function (ctx) {
|
|
223
224
|
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
-
const tableToDelete = yield getTable(ctx.params.tableId);
|
|
225
|
+
const tableToDelete = yield sdk.tables.getTable(ctx.params.tableId);
|
|
225
226
|
if (!tableToDelete || !tableToDelete.created) {
|
|
226
227
|
ctx.throw(400, "Cannot delete tables which weren't created in Budibase.");
|
|
227
228
|
}
|
|
@@ -239,7 +240,7 @@ exports.destroy = function (ctx) {
|
|
|
239
240
|
};
|
|
240
241
|
exports.bulkImport = function (ctx) {
|
|
241
242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
const table = yield getTable(ctx.params.tableId);
|
|
243
|
+
const table = yield sdk.tables.getTable(ctx.params.tableId);
|
|
243
244
|
const { dataImport } = ctx.request.body;
|
|
244
245
|
if (!dataImport || !dataImport.schema || !dataImport.csvString) {
|
|
245
246
|
ctx.throw(400, "Provided data import information is invalid.");
|
|
@@ -14,8 +14,8 @@ const csvParser = require("../../../utilities/csvParser");
|
|
|
14
14
|
const { isExternalTable, isSQL } = require("../../../integrations/utils");
|
|
15
15
|
const { getDatasourceParams } = require("../../../db/utils");
|
|
16
16
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
17
|
-
const { getTable, getAllInternalTables } = require("./utils");
|
|
18
17
|
const { events } = require("@budibase/backend-core");
|
|
18
|
+
const sdk = require("../../../sdk");
|
|
19
19
|
function pickApi({ tableId, table }) {
|
|
20
20
|
if (table && !tableId) {
|
|
21
21
|
tableId = table._id;
|
|
@@ -32,7 +32,7 @@ function pickApi({ tableId, table }) {
|
|
|
32
32
|
exports.fetch = function (ctx) {
|
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
const db = getAppDB();
|
|
35
|
-
const internal = yield getAllInternalTables();
|
|
35
|
+
const internal = yield sdk.tables.getAllInternalTables();
|
|
36
36
|
const externalTables = yield db.allDocs(getDatasourceParams("plus", {
|
|
37
37
|
include_docs: true,
|
|
38
38
|
}));
|
|
@@ -51,7 +51,7 @@ exports.fetch = function (ctx) {
|
|
|
51
51
|
exports.find = function (ctx) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
53
|
const tableId = ctx.params.tableId;
|
|
54
|
-
ctx.body = yield getTable(tableId);
|
|
54
|
+
ctx.body = yield sdk.tables.getTable(tableId);
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
57
|
exports.save = function (ctx) {
|
|
@@ -106,7 +106,7 @@ exports.validateCSVSchema = function (ctx) {
|
|
|
106
106
|
const { csvString, schema = {}, tableId } = ctx.request.body;
|
|
107
107
|
let existingTable;
|
|
108
108
|
if (tableId) {
|
|
109
|
-
existingTable = yield getTable(tableId);
|
|
109
|
+
existingTable = yield sdk.tables.getTable(tableId);
|
|
110
110
|
}
|
|
111
111
|
let result = yield csvParser.parse(csvString, schema);
|
|
112
112
|
if (existingTable) {
|